forked from MirrorHub/synapse
better logging for federation connections
This commit is contained in:
parent
d428b46346
commit
24d59c7568
1 changed files with 16 additions and 5 deletions
|
@ -23,6 +23,7 @@ from zope.interface import implementer
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.internet.endpoints import HostnameEndpoint, wrapClientTLS
|
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.client import URI, Agent, HTTPConnectionPool, RedirectAgent, readBody
|
||||||
from twisted.web.http import stringToDatetime
|
from twisted.web.http import stringToDatetime
|
||||||
from twisted.web.http_headers import Headers
|
from twisted.web.http_headers import Headers
|
||||||
|
@ -152,12 +153,9 @@ class MatrixFederationAgent(object):
|
||||||
class EndpointFactory(object):
|
class EndpointFactory(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def endpointForURI(_uri):
|
def endpointForURI(_uri):
|
||||||
logger.info(
|
ep = LoggingHostnameEndpoint(
|
||||||
"Connecting to %s:%i",
|
self._reactor, res.target_host, res.target_port,
|
||||||
res.target_host.decode("ascii"),
|
|
||||||
res.target_port,
|
|
||||||
)
|
)
|
||||||
ep = HostnameEndpoint(self._reactor, res.target_host, res.target_port)
|
|
||||||
if tls_options is not None:
|
if tls_options is not None:
|
||||||
ep = wrapClientTLS(tls_options, ep)
|
ep = wrapClientTLS(tls_options, ep)
|
||||||
return ep
|
return ep
|
||||||
|
@ -342,6 +340,19 @@ class MatrixFederationAgent(object):
|
||||||
defer.returnValue(result)
|
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):
|
def _cache_period_from_headers(headers, time_now=time.time):
|
||||||
cache_controls = _parse_cache_control(headers)
|
cache_controls = _parse_cache_control(headers)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue