summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2023-03-03 14:58:21 +0000
committerDavid Robertson <davidr@element.io>2023-03-03 14:58:21 +0000
commite9eca6d8f4c4a73d1756025ecbd201ad677a50c8 (patch)
treebc3e58a825d68ffacd8c19d3326bb486de4fbaa7
parentTesting: (diff)
downloadsynapse-github/dmr/restrict_outbound_federation.tar.xz
-rw-r--r--synapse/app/_base.py4
-rw-r--r--synapse/http/outbound_federation_proxy.py22
2 files changed, 24 insertions, 2 deletions
diff --git a/synapse/app/_base.py b/synapse/app/_base.py

index 07188976c7..ff321bea9d 100644 --- a/synapse/app/_base.py +++ b/synapse/app/_base.py
@@ -64,6 +64,7 @@ from synapse.events.presence_router import load_legacy_presence_router from synapse.events.spamcheck import load_legacy_spam_checkers from synapse.events.third_party_rules import load_legacy_third_party_event_rules from synapse.handlers.auth import load_legacy_password_auth_providers +from synapse.http.outbound_federation_proxy import OutboundFederationProxyFactory from synapse.http.site import SynapseSite from synapse.logging.context import PreserveLoggingContext from synapse.logging.opentracing import init_tracer @@ -387,8 +388,7 @@ def listen_outbound_fed_proxy( context_factory: Optional[IOpenSSLContextFactory], reactor: ISynapseReactor = reactor, ) -> None: - factory = HTTPFactory.forProtocol(Proxy) - listen_http(listener_config, factory, context_factory, reactor) + listen_http(listener_config, OutboundFederationProxyFactory, context_factory, reactor) def listen_http( diff --git a/synapse/http/outbound_federation_proxy.py b/synapse/http/outbound_federation_proxy.py new file mode 100644
index 0000000000..1f3ed0c884 --- /dev/null +++ b/synapse/http/outbound_federation_proxy.py
@@ -0,0 +1,22 @@ +from twisted.web.http import HTTPFactory +from twisted.web.proxy import Proxy, ProxyClient, ProxyClientFactory, ProxyRequest + + +class FederationOutboundProxyClient(ProxyClient): + ... + + +class FederationOutboundProxyClientFactory(ProxyClientFactory): + protocol = FederationOutboundProxyClient + + +class FederationOutboundProxyRequest(ProxyRequest): + protocols = {b"matrix": FederationOutboundProxyClientFactory} + ports = {b"matrix": 80} + + +class FederationOutboundProxy(Proxy): + requestFactory = FederationOutboundProxyRequest + + +OutboundFederationProxyFactory = HTTPFactory.forProtocol(FederationOutboundProxy)