mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-21 03:42:55 +03:00
Make using proxy optional
This commit is contained in:
parent
c11388b1ce
commit
28c3a43a7e
1 changed files with 25 additions and 5 deletions
|
@ -18,6 +18,7 @@ import logging
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
import os
|
||||||
|
|
||||||
import opentracing
|
import opentracing
|
||||||
from opentracing.ext import tags
|
from opentracing.ext import tags
|
||||||
|
@ -58,6 +59,7 @@ outgoing_requests_counter = Counter("synapse_http_matrixfederationclient_request
|
||||||
incoming_responses_counter = Counter("synapse_http_matrixfederationclient_responses",
|
incoming_responses_counter = Counter("synapse_http_matrixfederationclient_responses",
|
||||||
"", ["method", "code"])
|
"", ["method", "code"])
|
||||||
|
|
||||||
|
USE_PROXY = "SYNAPSE_USE_PROXY" in os.environ
|
||||||
|
|
||||||
MAX_LONG_RETRIES = 10
|
MAX_LONG_RETRIES = 10
|
||||||
MAX_SHORT_RETRIES = 3
|
MAX_SHORT_RETRIES = 3
|
||||||
|
@ -68,6 +70,18 @@ else:
|
||||||
MAXINT = sys.maxint
|
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
|
||||||
|
|
||||||
|
def endpointForURI(self, uri):
|
||||||
|
return matrix_federation_endpoint(
|
||||||
|
self.reactor, "localhost:8888", timeout=10,
|
||||||
|
tls_client_options_factory=None
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MatrixFederationEndpointFactory(object):
|
class MatrixFederationEndpointFactory(object):
|
||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
self.reactor = hs.get_reactor()
|
self.reactor = hs.get_reactor()
|
||||||
|
@ -77,8 +91,8 @@ class MatrixFederationEndpointFactory(object):
|
||||||
destination = uri.netloc.decode('ascii')
|
destination = uri.netloc.decode('ascii')
|
||||||
|
|
||||||
return matrix_federation_endpoint(
|
return matrix_federation_endpoint(
|
||||||
self.reactor, "localhost:8888", timeout=10,
|
self.reactor, destination, timeout=10,
|
||||||
tls_client_options_factory=None
|
tls_client_options_factory=self.tls_client_options_factory
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,9 +207,15 @@ class MatrixFederationHttpClient(object):
|
||||||
pool.retryAutomatically = False
|
pool.retryAutomatically = False
|
||||||
pool.maxPersistentPerHost = 5
|
pool.maxPersistentPerHost = 5
|
||||||
pool.cachedConnectionTimeout = 2 * 60
|
pool.cachedConnectionTimeout = 2 * 60
|
||||||
self.agent = Agent.usingEndpointFactory(
|
|
||||||
reactor, MatrixFederationEndpointFactory(hs), pool=pool
|
if USE_PROXY:
|
||||||
)
|
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.clock = hs.get_clock()
|
||||||
self._store = hs.get_datastore()
|
self._store = hs.get_datastore()
|
||||||
self.version_string_bytes = hs.version_string.encode('ascii')
|
self.version_string_bytes = hs.version_string.encode('ascii')
|
||||||
|
|
Loading…
Reference in a new issue