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

Commit

Permalink
Use the name of the worker to abstract connection details away from R…
Browse files Browse the repository at this point in the history
…eplicationEndpoint and into ReplicationEndpointFactory
  • Loading branch information
realtyem committed May 11, 2023
1 parent 5a5eb88 commit 095ec68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 8 additions & 2 deletions synapse/http/replicationagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ def endpointForURI(self, uri: URI) -> IStreamClientEndpoint:
Returns: The correct client endpoint object
"""
# The place to connect to now comes in as the name of the worker, similar to
# a hostname in placement. Use the instance_map data to get the actual
# connection information.
netloc = self.instance_map[uri.netloc.decode("utf-8")].netloc()
if uri.scheme in (b"http", b"https"):
endpoint = HostnameEndpoint(self.reactor, uri.host, uri.port)
host, port = netloc.split(":", maxsplit=1)
endpoint = HostnameEndpoint(self.reactor, host, port)
if uri.scheme == b"https":
endpoint = wrapClientTLS(
self.context_factory.creatorForNetloc(uri.host, uri.port), endpoint
self.context_factory.creatorForNetloc(host, int(port)), endpoint
)
return endpoint
else:
Expand Down Expand Up @@ -107,6 +112,7 @@ def __init__(
_AgentBase.__init__(self, reactor, pool)
endpoint_factory = ReplicationEndpointFactory(
reactor, instance_map, contextFactory
)
self._endpointFactory = endpoint_factory

def request(
Expand Down
18 changes: 6 additions & 12 deletions synapse/replication/http/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,7 @@ async def send_request(
with outgoing_gauge.track_inprogress():
if instance_name == local_instance_name:
raise Exception("Trying to send HTTP request to self")
if instance_name in instance_map:
host = instance_map[instance_name].host
port = instance_map[instance_name].port
tls = instance_map[instance_name].tls
else:
if instance_name not in instance_map:
raise Exception(
"Instance %r not in 'instance_map' config" % (instance_name,)
)
Expand Down Expand Up @@ -271,13 +267,11 @@ async def send_request(
"Unknown METHOD on %s replication endpoint" % (cls.NAME,)
)

# Here the protocol is hard coded to be http by default or https in case the replication
# port is set to have tls true.
scheme = "https" if tls else "http"
uri = "%s://%s:%s/_synapse/replication/%s/%s" % (
scheme,
host,
port,
# Use the instance_map data to retrieve the correct scheme and use the
# instance_name to abstract the connection details into the Agent
uri = "%s://%s/_synapse/replication/%s/%s" % (
instance_map[instance_name].scheme(),
instance_name,
cls.NAME,
"/".join(url_args),
)
Expand Down

0 comments on commit 095ec68

Please sign in to comment.