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

Commit 095ec68

Browse files
committed
Use the name of the worker to abstract connection details away from ReplicationEndpoint and into ReplicationEndpointFactory
1 parent 5a5eb88 commit 095ec68

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

synapse/http/replicationagent.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,16 @@ def endpointForURI(self, uri: URI) -> IStreamClientEndpoint:
6060
6161
Returns: The correct client endpoint object
6262
"""
63+
# The place to connect to now comes in as the name of the worker, similar to
64+
# a hostname in placement. Use the instance_map data to get the actual
65+
# connection information.
66+
netloc = self.instance_map[uri.netloc.decode("utf-8")].netloc()
6367
if uri.scheme in (b"http", b"https"):
64-
endpoint = HostnameEndpoint(self.reactor, uri.host, uri.port)
68+
host, port = netloc.split(":", maxsplit=1)
69+
endpoint = HostnameEndpoint(self.reactor, host, port)
6570
if uri.scheme == b"https":
6671
endpoint = wrapClientTLS(
67-
self.context_factory.creatorForNetloc(uri.host, uri.port), endpoint
72+
self.context_factory.creatorForNetloc(host, int(port)), endpoint
6873
)
6974
return endpoint
7075
else:
@@ -107,6 +112,7 @@ def __init__(
107112
_AgentBase.__init__(self, reactor, pool)
108113
endpoint_factory = ReplicationEndpointFactory(
109114
reactor, instance_map, contextFactory
115+
)
110116
self._endpointFactory = endpoint_factory
111117

112118
def request(

synapse/replication/http/_base.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,7 @@ async def send_request(
219219
with outgoing_gauge.track_inprogress():
220220
if instance_name == local_instance_name:
221221
raise Exception("Trying to send HTTP request to self")
222-
if instance_name in instance_map:
223-
host = instance_map[instance_name].host
224-
port = instance_map[instance_name].port
225-
tls = instance_map[instance_name].tls
226-
else:
222+
if instance_name not in instance_map:
227223
raise Exception(
228224
"Instance %r not in 'instance_map' config" % (instance_name,)
229225
)
@@ -271,13 +267,11 @@ async def send_request(
271267
"Unknown METHOD on %s replication endpoint" % (cls.NAME,)
272268
)
273269

274-
# Here the protocol is hard coded to be http by default or https in case the replication
275-
# port is set to have tls true.
276-
scheme = "https" if tls else "http"
277-
uri = "%s://%s:%s/_synapse/replication/%s/%s" % (
278-
scheme,
279-
host,
280-
port,
270+
# Use the instance_map data to retrieve the correct scheme and use the
271+
# instance_name to abstract the connection details into the Agent
272+
uri = "%s://%s/_synapse/replication/%s/%s" % (
273+
instance_map[instance_name].scheme(),
274+
instance_name,
281275
cls.NAME,
282276
"/".join(url_args),
283277
)

0 commit comments

Comments
 (0)