Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Remove some DNS lookups to support IPv6 #1934

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions synapse/http/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,26 +280,14 @@ def resolve_service(service_name, dns_client=client, cache=SERVER_CACHE, clock=t
continue

payload = answer.payload
host = str(payload.target)
srv_ttl = answer.ttl

try:
answers, _, _ = yield dns_client.lookupAddress(host)
except DNSNameError:
continue

for answer in answers:
if answer.type == dns.A and answer.payload:
ip = answer.payload.dottedQuad()
host_ttl = min(srv_ttl, answer.ttl)

servers.append(_Server(
host=ip,
port=int(payload.port),
priority=int(payload.priority),
weight=int(payload.weight),
expires=int(clock.time()) + host_ttl,
))
servers.append(_Server(
host=str(payload.target),
port=int(payload.port),
priority=int(payload.priority),
weight=int(payload.weight),
expires=int(clock.time()) + answer.ttl,
))

servers.sort()
cache[service_name] = list(servers)
Expand Down
12 changes: 1 addition & 11 deletions tests/test_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def test_resolve(self):

service_name = "test_service.examle.com"
host_name = "example.com"
ip_address = "127.0.0.1"

answer_srv = dns.RRHeader(
type=dns.SRV,
Expand All @@ -41,15 +40,7 @@ def test_resolve(self):
)
)

answer_a = dns.RRHeader(
type=dns.A,
payload=dns.Record_A(
address=ip_address,
)
)

dns_client_mock.lookupService.return_value = ([answer_srv], None, None)
dns_client_mock.lookupAddress.return_value = ([answer_a], None, None)

cache = {}

Expand All @@ -58,11 +49,10 @@ def test_resolve(self):
)

dns_client_mock.lookupService.assert_called_once_with(service_name)
dns_client_mock.lookupAddress.assert_called_once_with(host_name)

self.assertEquals(len(servers), 1)
self.assertEquals(servers, cache[service_name])
self.assertEquals(servers[0].host, ip_address)
self.assertEquals(servers[0].host, host_name)

@defer.inlineCallbacks
def test_from_cache_expired_and_dns_fail(self):
Expand Down