Join via closest server

This commit is contained in:
Erik Johnston 2018-11-26 12:08:58 +00:00 committed by Brendan Abolivier
parent 781bd4fb96
commit e8be4ca1ad
3 changed files with 24 additions and 6 deletions

View file

@ -486,6 +486,22 @@ class FederationClient(FederationBase):
RuntimeError if no servers were reachable. RuntimeError if no servers were reachable.
""" """
healths = yield self.store.get_destination_healths(destinations)
with_healths = []
without_healths = []
for d in destinations:
if healths.get(d):
with_healths.append(d)
else:
without_healths.append(d)
with_healths.sort(key=lambda d: healths[d])
destinations = with_healths + without_healths
logger.info("Trying destinations: %r", destinations)
for destination in destinations: for destination in destinations:
if destination == self.server_name: if destination == self.server_name:
continue continue

View file

@ -265,9 +265,8 @@ class DirectoryHandler(BaseHandler):
Codes.NOT_FOUND Codes.NOT_FOUND
) )
users = yield self.state.get_current_user_in_room(room_id) hosts = yield self.state.get_current_hosts_in_room(room_id)
extra_servers = set(get_domain_from_id(u) for u in users) servers = set(hosts) | set(servers)
servers = set(extra_servers) | set(servers)
# If this server is in the list of servers, return it first. # If this server is in the list of servers, return it first.
if self.server_name in servers: if self.server_name in servers:
@ -278,6 +277,8 @@ class DirectoryHandler(BaseHandler):
else: else:
servers = list(servers) servers = list(servers)
logger.info("Returning servers %s", servers)
defer.returnValue({ defer.returnValue({
"room_id": room_id, "room_id": room_id,
"servers": servers, "servers": servers,
@ -292,14 +293,14 @@ class DirectoryHandler(BaseHandler):
400, "Room Alias is not hosted on this Home Server" 400, "Room Alias is not hosted on this Home Server"
) )
result = yield self.get_association_from_room_alias( result = yield self.get_association(
room_alias room_alias
) )
if result is not None: if result is not None:
defer.returnValue({ defer.returnValue({
"room_id": result.room_id, "room_id": result["room_id"],
"servers": result.servers, "servers": result["servers"],
}) })
else: else:
raise SynapseError( raise SynapseError(

View file

@ -1155,6 +1155,7 @@ class FederationHandler(BaseHandler):
have finished processing the join. have finished processing the join.
""" """
logger.debug("Joining %s to %s", joinee, room_id) logger.debug("Joining %s to %s", joinee, room_id)
logger.info("Target hosts %s", target_hosts)
origin, event = yield self._make_and_verify_event( origin, event = yield self._make_and_verify_event(
target_hosts, target_hosts,