Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add Unix socket support to the proxyagent
Browse files Browse the repository at this point in the history
Originally from #15708
  • Loading branch information
realtyem authored and MadLittleMods committed Jul 11, 2023
1 parent 1ac93f3 commit e127596
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions synapse/http/proxyagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e127596

Please sign in to comment.