From 5d2b478c41c609cf6ae49a3b89f30cba80bc80dc Mon Sep 17 00:00:00 2001 From: Silke Hofstra Date: Wed, 22 Feb 2017 13:13:40 +0100 Subject: [PATCH 1/2] Remove some DNS lookups to support IPv6 The current implementation only does a lookup for an A record. This is troublesome for IPv6-enabled or IPv6-only servers. Removing the lookup lets Twisted do the resolving. Signed-off-by: Silke Hofstra --- synapse/http/endpoint.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/synapse/http/endpoint.py b/synapse/http/endpoint.py index d8923c9abb4e..a3a68c8ecfd4 100644 --- a/synapse/http/endpoint.py +++ b/synapse/http/endpoint.py @@ -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) From 1efb5ba767be48729637fff24379bdf75e5add61 Mon Sep 17 00:00:00 2001 From: Silke Hofstra Date: Wed, 22 Feb 2017 14:56:38 +0100 Subject: [PATCH 2/2] Remove the lookup from the tests. Signed-off-by: Silke Hofstra --- tests/test_dns.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/tests/test_dns.py b/tests/test_dns.py index c394c57ee7dc..52c6882afc2f 100644 --- a/tests/test_dns.py +++ b/tests/test_dns.py @@ -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, @@ -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 = {} @@ -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):