diff options
author | Richard van der Hoff <richard@matrix.org> | 2019-01-31 23:18:20 +0000 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2019-01-31 23:18:20 +0000 |
commit | 24d59c756884f3b4a05dfb9414998443873f418d (patch) | |
tree | e2763a54229059925db687c324a707ab2c8355bf /synapse/http/federation | |
parent | Update federation routing logic to check .well-known before SRV (diff) | |
download | synapse-24d59c756884f3b4a05dfb9414998443873f418d.tar.xz |
better logging for federation connections
Diffstat (limited to 'synapse/http/federation')
-rw-r--r-- | synapse/http/federation/matrix_federation_agent.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/synapse/http/federation/matrix_federation_agent.py b/synapse/http/federation/matrix_federation_agent.py index 57dcab4727..3a0525e365 100644 --- a/synapse/http/federation/matrix_federation_agent.py +++ b/synapse/http/federation/matrix_federation_agent.py @@ -23,6 +23,7 @@ from zope.interface import implementer from twisted.internet import defer from twisted.internet.endpoints import HostnameEndpoint, wrapClientTLS +from twisted.internet.interfaces import IStreamClientEndpoint from twisted.web.client import URI, Agent, HTTPConnectionPool, RedirectAgent, readBody from twisted.web.http import stringToDatetime from twisted.web.http_headers import Headers @@ -152,12 +153,9 @@ class MatrixFederationAgent(object): class EndpointFactory(object): @staticmethod def endpointForURI(_uri): - logger.info( - "Connecting to %s:%i", - res.target_host.decode("ascii"), - res.target_port, + ep = LoggingHostnameEndpoint( + self._reactor, res.target_host, res.target_port, ) - ep = HostnameEndpoint(self._reactor, res.target_host, res.target_port) if tls_options is not None: ep = wrapClientTLS(tls_options, ep) return ep @@ -342,6 +340,19 @@ class MatrixFederationAgent(object): defer.returnValue(result) +@implementer(IStreamClientEndpoint) +class LoggingHostnameEndpoint(object): + """A wrapper for HostnameEndpint which logs when it connects""" + def __init__(self, reactor, host, port, *args, **kwargs): + self.host = host + self.port = port + self.ep = HostnameEndpoint(reactor, host, port, *args, **kwargs) + + def connect(self, protocol_factory): + logger.info("Connecting to %s:%i", self.host, self.port) + return self.ep.connect(protocol_factory) + + def _cache_period_from_headers(headers, time_now=time.time): cache_controls = _parse_cache_control(headers) |