diff --git a/synapse/http/proxyagent.py b/synapse/http/proxyagent.py index 8de1088e10c3..f0c6756bb713 100644 --- a/synapse/http/proxyagent.py +++ b/synapse/http/proxyagent.py @@ -24,7 +24,11 @@ from zope.interface import implementer from twisted.internet import defer -from twisted.internet.endpoints import HostnameEndpoint, wrapClientTLS +from twisted.internet.endpoints import ( + HostnameEndpoint, + UNIXClientEndpoint, + wrapClientTLS, +) from twisted.internet.interfaces import ( IProtocol, IProtocolFactory, @@ -42,7 +46,11 @@ from twisted.web.http_headers import Headers from twisted.web.iweb import IAgent, IBodyProducer, IPolicyForHTTPS, IResponse -from synapse.config.workers import InstanceLocationConfig +from synapse.config.workers import ( + InstanceLocationConfig, + InstanceTcpLocationConfig, + InstanceUnixLocationConfig, +) from synapse.http import redact_uri from synapse.http.connectproxyclient import HTTPConnectProxyEndpoint, ProxyCredentials from synapse.logging.context import run_in_background @@ -142,20 +150,34 @@ def __init__( self._federation_proxy_endpoint: Optional[IStreamClientEndpoint] = None if federation_proxies: - endpoints = [] + endpoints: List[IStreamClientEndpoint] = [] for federation_proxy in federation_proxies: - endpoint = HostnameEndpoint( - self.proxy_reactor, - federation_proxy.host, - federation_proxy.port, - ) - - if federation_proxy.tls: - tls_connection_creator = self._policy_for_https.creatorForNetloc( - federation_proxy.host.encode("utf-8"), + endpoint: IStreamClientEndpoint + if isinstance(federation_proxy, InstanceTcpLocationConfig): + endpoint = HostnameEndpoint( + self.proxy_reactor, + federation_proxy.host, federation_proxy.port, ) - endpoint = wrapClientTLS(tls_connection_creator, endpoint) + if federation_proxy.tls: + tls_connection_creator = ( + self._policy_for_https.creatorForNetloc( + federation_proxy.host, + federation_proxy.port, + ) + ) + endpoint = wrapClientTLS(tls_connection_creator, endpoint) + + elif isinstance(federation_proxy, InstanceUnixLocationConfig): + endpoint = UNIXClientEndpoint( + self.proxy_reactor, federation_proxy.path + ) + + else: + # It is supremely unlikely we ever hit this + raise SchemeNotSupported( + f"Unknown type of Endpoint requested, check {federation_proxy}" + ) endpoints.append(endpoint)