summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-11-26 12:08:58 +0000
committerBrendan Abolivier <babolivier@matrix.org>2019-02-13 15:16:02 +0000
commite8be4ca1add6afec884f8b7ea5bdf36d5edf2167 (patch)
tree7cbfc6625549cdca06bad6b12f4de56ae86c69b3
parentFILES (diff)
downloadsynapse-e8be4ca1add6afec884f8b7ea5bdf36d5edf2167.tar.xz
Join via closest server
-rw-r--r--synapse/federation/federation_client.py16
-rw-r--r--synapse/handlers/directory.py13
-rw-r--r--synapse/handlers/federation.py1
3 files changed, 24 insertions, 6 deletions
diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py
index d05ed91d64..db2c050b3c 100644
--- a/synapse/federation/federation_client.py
+++ b/synapse/federation/federation_client.py
@@ -486,6 +486,22 @@ class FederationClient(FederationBase):
 
             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:
             if destination == self.server_name:
                 continue
diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py
index 0699731c13..78dbc2bdae 100644
--- a/synapse/handlers/directory.py
+++ b/synapse/handlers/directory.py
@@ -265,9 +265,8 @@ class DirectoryHandler(BaseHandler):
                 Codes.NOT_FOUND
             )
 
-        users = yield self.state.get_current_user_in_room(room_id)
-        extra_servers = set(get_domain_from_id(u) for u in users)
-        servers = set(extra_servers) | set(servers)
+        hosts = yield self.state.get_current_hosts_in_room(room_id)
+        servers = set(hosts) | set(servers)
 
         # If this server is in the list of servers, return it first.
         if self.server_name in servers:
@@ -278,6 +277,8 @@ class DirectoryHandler(BaseHandler):
         else:
             servers = list(servers)
 
+        logger.info("Returning servers %s", servers)
+
         defer.returnValue({
             "room_id": room_id,
             "servers": servers,
@@ -292,14 +293,14 @@ class DirectoryHandler(BaseHandler):
                 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
         )
 
         if result is not None:
             defer.returnValue({
-                "room_id": result.room_id,
-                "servers": result.servers,
+                "room_id": result["room_id"],
+                "servers": result["servers"],
             })
         else:
             raise SynapseError(
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index bbca24f23c..651d640bf9 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -1155,6 +1155,7 @@ class FederationHandler(BaseHandler):
         have finished processing the join.
         """
         logger.debug("Joining %s to %s", joinee, room_id)
+        logger.info("Target hosts %s", target_hosts)
 
         origin, event = yield self._make_and_verify_event(
             target_hosts,