diff options
author | Richard van der Hoff <richard@matrix.org> | 2019-01-26 21:48:50 +0000 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2019-01-28 10:34:30 +0000 |
commit | 0fd5b3b53e312a48d98afec27ff3686d8ffce199 (patch) | |
tree | b19d1f3f3060d3ec106a84bedcd9618fc01476e7 /synapse/http/federation/matrix_federation_agent.py | |
parent | MatrixFederationAgent: factor out routing logic (diff) | |
download | synapse-0fd5b3b53e312a48d98afec27ff3686d8ffce199.tar.xz |
Handle IP literals explicitly
We don't want to be doing .well-known lookups on these guys.
Diffstat (limited to 'synapse/http/federation/matrix_federation_agent.py')
-rw-r--r-- | synapse/http/federation/matrix_federation_agent.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/synapse/http/federation/matrix_federation_agent.py b/synapse/http/federation/matrix_federation_agent.py index 2a8bceed9a..4d674cdb93 100644 --- a/synapse/http/federation/matrix_federation_agent.py +++ b/synapse/http/federation/matrix_federation_agent.py @@ -15,6 +15,7 @@ import logging import attr +from netaddr import IPAddress from zope.interface import implementer from twisted.internet import defer @@ -137,6 +138,24 @@ class MatrixFederationAgent(object): Returns: Deferred[_RoutingResult] """ + # check for an IP literal + try: + ip_address = IPAddress(parsed_uri.host.decode("ascii")) + except Exception: + # not an IP address + ip_address = None + + if ip_address: + port = parsed_uri.port + if port == -1: + port = 8448 + defer.returnValue(_RoutingResult( + host_header=parsed_uri.netloc, + tls_server_name=parsed_uri.host, + target_host=parsed_uri.host, + target_port=port, + )) + if parsed_uri.port != -1: # there is an explicit port defer.returnValue(_RoutingResult( |