From 963256638d5b3c3edee14bfbd7c00944b45d04c0 Mon Sep 17 00:00:00 2001
From: Erik Johnston <erik@matrix.org>
Date: Thu, 12 Feb 2015 18:17:11 +0000
Subject: Correctly handle all the places that can throw exceptions

---
 synapse/federation/federation_base.py   | 24 ++++++++++++++----------
 synapse/federation/federation_server.py |  9 ++++++---
 synapse/handlers/federation.py          | 12 ++++++++++++
 3 files changed, 32 insertions(+), 13 deletions(-)

(limited to 'synapse')

diff --git a/synapse/federation/federation_base.py b/synapse/federation/federation_base.py
index a990aec4fd..30f3f5c8a4 100644
--- a/synapse/federation/federation_base.py
+++ b/synapse/federation/federation_base.py
@@ -61,7 +61,8 @@ class FederationBase(object):
                 # Check local db.
                 new_pdu = yield self.store.get_event(
                     pdu.event_id,
-                    allow_rejected=True
+                    allow_rejected=True,
+                    allow_none=True,
                 )
                 if new_pdu:
                     signed_pdus.append(new_pdu)
@@ -69,15 +70,18 @@ class FederationBase(object):
 
                 # Check pdu.origin
                 if pdu.origin != origin:
-                    new_pdu = yield self.get_pdu(
-                        destinations=[pdu.origin],
-                        event_id=pdu.event_id,
-                        outlier=outlier,
-                    )
-
-                    if new_pdu:
-                        signed_pdus.append(new_pdu)
-                        continue
+                    try:
+                        new_pdu = yield self.get_pdu(
+                            destinations=[pdu.origin],
+                            event_id=pdu.event_id,
+                            outlier=outlier,
+                        )
+
+                        if new_pdu:
+                            signed_pdus.append(new_pdu)
+                            continue
+                    except:
+                        pass
 
                 logger.warn("Failed to find copy of %s with valid signature")
 
diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py
index b23f72c7fa..9f5c98694c 100644
--- a/synapse/federation/federation_server.py
+++ b/synapse/federation/federation_server.py
@@ -411,9 +411,12 @@ class FederationServer(FederationBase):
                 "_handle_new_pdu getting state for %s",
                 pdu.room_id
             )
-            state, auth_chain = yield self.get_state_for_room(
-                origin, pdu.room_id, pdu.event_id,
-            )
+            try:
+                state, auth_chain = yield self.get_state_for_room(
+                    origin, pdu.room_id, pdu.event_id,
+                )
+            except:
+                logger.warn("Failed to get state for event: %s", pdu.event_id)
 
         ret = yield self.handler.on_receive_pdu(
             origin,
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index 77c81fe2da..5a7593cc3b 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -788,6 +788,18 @@ class FederationHandler(BaseHandler):
 
         defer.returnValue(ret)
 
+    @defer.inlineCallbacks
+    def trigger_query_auth(self, destination, event_id):
+        local_auth_chain = yield self.store.get_auth_chain([event_id])
+
+        result = yield self.replication_layer.query_auth(
+            destination,
+            event.room_id,
+            event.event_id,
+            local_auth_chain,
+        )
+
+
     @defer.inlineCallbacks
     @log_function
     def do_auth(self, origin, event, context, auth_events):
-- 
cgit 1.5.1


From 58d848adc0ee9ab8e44a780a19be1e46e0d5cec3 Mon Sep 17 00:00:00 2001
From: Erik Johnston <erik@matrix.org>
Date: Thu, 12 Feb 2015 18:35:36 +0000
Subject: Parrellize fetching of events

---
 synapse/federation/federation_base.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

(limited to 'synapse')

diff --git a/synapse/federation/federation_base.py b/synapse/federation/federation_base.py
index 30f3f5c8a4..966f4d2c5c 100644
--- a/synapse/federation/federation_base.py
+++ b/synapse/federation/federation_base.py
@@ -50,8 +50,11 @@ class FederationBase(object):
         Returns:
             Deferred : A list of PDUs that have valid signatures and hashes.
         """
+
         signed_pdus = []
-        for pdu in pdus:
+
+        @defer.inlineCallbacks
+        def do(pdu):
             try:
                 new_pdu = yield self._check_sigs_and_hash(pdu)
                 signed_pdus.append(new_pdu)
@@ -66,7 +69,7 @@ class FederationBase(object):
                 )
                 if new_pdu:
                     signed_pdus.append(new_pdu)
-                    continue
+                    return
 
                 # Check pdu.origin
                 if pdu.origin != origin:
@@ -79,12 +82,17 @@ class FederationBase(object):
 
                         if new_pdu:
                             signed_pdus.append(new_pdu)
-                            continue
+                            return
                     except:
                         pass
 
                 logger.warn("Failed to find copy of %s with valid signature")
 
+        yield defer.gatherResults(
+            [do(pdu) for pdu in pdus],
+            consumeErrors=True
+        )
+
         defer.returnValue(signed_pdus)
 
     @defer.inlineCallbacks
-- 
cgit 1.5.1


From 38df10b99eaa7f8165c9e541142e96bf023ad744 Mon Sep 17 00:00:00 2001
From: Erik Johnston <erik@matrix.org>
Date: Thu, 12 Feb 2015 19:29:32 +0000
Subject: Remove unused function

---
 synapse/handlers/federation.py | 12 ------------
 1 file changed, 12 deletions(-)

(limited to 'synapse')

diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index 5a7593cc3b..77c81fe2da 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -788,18 +788,6 @@ class FederationHandler(BaseHandler):
 
         defer.returnValue(ret)
 
-    @defer.inlineCallbacks
-    def trigger_query_auth(self, destination, event_id):
-        local_auth_chain = yield self.store.get_auth_chain([event_id])
-
-        result = yield self.replication_layer.query_auth(
-            destination,
-            event.room_id,
-            event.event_id,
-            local_auth_chain,
-        )
-
-
     @defer.inlineCallbacks
     @log_function
     def do_auth(self, origin, event, context, auth_events):
-- 
cgit 1.5.1


From 789251afa7d97a08318f92ffe96f5f7ce16d6157 Mon Sep 17 00:00:00 2001
From: Erik Johnston <erik@matrix.org>
Date: Thu, 12 Feb 2015 19:29:43 +0000
Subject: Fix logging

---
 synapse/federation/federation_base.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

(limited to 'synapse')

diff --git a/synapse/federation/federation_base.py b/synapse/federation/federation_base.py
index 966f4d2c5c..21a763214b 100644
--- a/synapse/federation/federation_base.py
+++ b/synapse/federation/federation_base.py
@@ -86,7 +86,10 @@ class FederationBase(object):
                     except:
                         pass
 
-                logger.warn("Failed to find copy of %s with valid signature")
+                logger.warn(
+                    "Failed to find copy of %s with valid signature",
+                    pdu.event_id,
+                )
 
         yield defer.gatherResults(
             [do(pdu) for pdu in pdus],
-- 
cgit 1.5.1


From f22646efcc3d3c5c7fc0d7797de2675e1a794dd0 Mon Sep 17 00:00:00 2001
From: "Paul \"LeoNerd\" Evans" <paul@matrix.org>
Date: Thu, 12 Feb 2015 19:11:52 +0000
Subject: Only attempt to fetch presence state of JOINed members in room
 initialSync (SYN-202)

---
 synapse/handlers/message.py | 1 +
 1 file changed, 1 insertion(+)

(limited to 'synapse')

diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index 3355adefcf..c6d6188d9d 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -372,6 +372,7 @@ class MessageHandler(BaseHandler):
         room_members = [
             m for m in current_state.values()
             if m.type == EventTypes.Member
+                and m.content["membership"] == Membership.JOIN
         ]
 
         presence_handler = self.hs.get_handlers().presence_handler
-- 
cgit 1.5.1


From 55e0916ffc0a4e2c7bff533c561e99889650c61d Mon Sep 17 00:00:00 2001
From: "Paul \"LeoNerd\" Evans" <paul@matrix.org>
Date: Thu, 12 Feb 2015 19:19:37 +0000
Subject: Reindent code to be less human-readable to keep pep8 from complaining

---
 synapse/handlers/message.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'synapse')

diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index c6d6188d9d..b00380387d 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -372,7 +372,7 @@ class MessageHandler(BaseHandler):
         room_members = [
             m for m in current_state.values()
             if m.type == EventTypes.Member
-                and m.content["membership"] == Membership.JOIN
+            and m.content["membership"] == Membership.JOIN
         ]
 
         presence_handler = self.hs.get_handlers().presence_handler
-- 
cgit 1.5.1