Compare commits

...

8 Commits

Author SHA1 Message Date
Richard van der Hoff
45ad44b076 Fix typo
Co-Authored-By: anoadragon453 <1342360+anoadragon453@users.noreply.github.com>
2019-01-21 16:05:29 +00:00
Andrew Morgan
8b0a9b3ad7 Set default config value for tests 2019-01-17 13:23:16 +00:00
Andrew Morgan
53f8936b40 Simplify code slightly 2019-01-17 12:09:31 +00:00
Andrew Morgan
439d71a8d1 Fix missing hs property 2019-01-17 12:03:48 +00:00
Andrew Morgan
a82b682b07 linting 2019-01-17 10:52:04 +00:00
Andrew Morgan
1128d9b9b2 Clarify this is not for use with a SOCKS proxy 2019-01-16 17:36:20 +00:00
Andrew Morgan
2c9ce72071 Add changelog file 2019-01-16 17:23:08 +00:00
Andrew Morgan
6a83652dee Allow for Synapse to run through a http proxy
Signed-off-by: Andrew Morgan <andrew@amorgan.xyz>
2019-01-16 17:17:50 +00:00
4 changed files with 42 additions and 4 deletions

1
changelog.d/4406.feature Normal file
View File

@@ -0,0 +1 @@
Add a simple HTTP proxy option for Synapse to send federation traffic through before reaching other servers.

View File

@@ -107,12 +107,23 @@ class ServerConfig(Config):
federation_domain_whitelist = config.get(
"federation_domain_whitelist", None
)
# turn the whitelist into a hash for speed of lookup
if federation_domain_whitelist is not None:
self.federation_domain_whitelist = {}
for domain in federation_domain_whitelist:
self.federation_domain_whitelist[domain] = True
# Optional proxy address for federation traffic
self.federation_request_gateway_addr = config.get(
"federation_request_gateway_addr", None
)
if self.federation_request_gateway_addr is not None:
# Ensure proxy address is correctly formatted
if len(self.federation_request_gateway_addr.split(':')) != 2:
self.federation_request_gateway_addr = None
if self.public_baseurl is not None:
if self.public_baseurl[-1] != '/':
self.public_baseurl += '/'
@@ -289,6 +300,11 @@ class ServerConfig(Config):
# - nyc.example.com
# - syd.example.com
# Send outbound federation requests through a seperate traffic gateway.
# Not intended to be used with a SOCKS proxy, but rather a relay for
# HTTP traffic.
# federation_request_gateway_addr: localhost:1234
# List of ports that Synapse should listen on, their purpose and their
# configuration.
listeners:

View File

@@ -56,7 +56,6 @@ outgoing_requests_counter = Counter("synapse_http_matrixfederationclient_request
incoming_responses_counter = Counter("synapse_http_matrixfederationclient_responses",
"", ["method", "code"])
MAX_LONG_RETRIES = 10
MAX_SHORT_RETRIES = 3
@@ -66,6 +65,19 @@ else:
MAXINT = sys.maxint
class ProxyMatrixFederationEndpointFactory(object):
def __init__(self, hs):
self.reactor = hs.get_reactor()
self.tls_client_options_factory = hs.tls_client_options_factory
self.gateway_addr = hs.config.federation_request_gateway_addr
def endpointForURI(self, uri):
return matrix_federation_endpoint(
self.reactor, self.gateway_addr, timeout=10,
tls_client_options_factory=None
)
class MatrixFederationEndpointFactory(object):
def __init__(self, hs):
self.reactor = hs.get_reactor()
@@ -186,14 +198,22 @@ class MatrixFederationHttpClient(object):
self.hs = hs
self.signing_key = hs.config.signing_key[0]
self.server_name = hs.hostname
self.gateway_addr = hs.config.federation_request_gateway_addr
reactor = hs.get_reactor()
pool = HTTPConnectionPool(reactor)
pool.retryAutomatically = False
pool.maxPersistentPerHost = 5
pool.cachedConnectionTimeout = 2 * 60
self.agent = Agent.usingEndpointFactory(
reactor, MatrixFederationEndpointFactory(hs), pool=pool
)
if self.gateway_addr:
self.agent = Agent.usingEndpointFactory(
reactor, ProxyMatrixFederationEndpointFactory(hs), pool=pool
)
else:
self.agent = Agent.usingEndpointFactory(
reactor, MatrixFederationEndpointFactory(hs), pool=pool
)
self.clock = hs.get_clock()
self._store = hs.get_datastore()
self.version_string_bytes = hs.version_string.encode('ascii')

View File

@@ -115,6 +115,7 @@ def default_config(name):
config.email_enable_notifs = False
config.block_non_admin_invites = False
config.federation_domain_whitelist = None
config.federation_request_gateway_addr = None
config.federation_rc_reject_limit = 10
config.federation_rc_sleep_limit = 10
config.federation_rc_sleep_delay = 100