From cd1579b58a229a72c68bcd42c6912e1cc8464f43 Mon Sep 17 00:00:00 2001 From: Jason Little Date: Thu, 6 Jul 2023 17:14:19 -0500 Subject: [PATCH] Add Unix socket support to the proxyagent --- synapse/http/proxyagent.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/synapse/http/proxyagent.py b/synapse/http/proxyagent.py index 348fecde5894..7431e9e1da68 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, InstanceTcpLocationConfig +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,8 +150,9 @@ def __init__( self._federation_proxy_endpoint: Optional[IStreamClientEndpoint] = None if federation_proxies: - endpoints = [] + endpoints: List[IStreamClientEndpoint] = [] for federation_proxy in federation_proxies: + endpoint: IStreamClientEndpoint if isinstance(federation_proxy, InstanceTcpLocationConfig): endpoint = HostnameEndpoint( self.proxy_reactor, @@ -160,7 +169,18 @@ def __init__( ) endpoint = wrapClientTLS(tls_connection_creator, endpoint) - endpoints.append(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) self._federation_proxy_endpoint = _ProxyEndpoints(endpoints)