From 963256638d5b3c3edee14bfbd7c00944b45d04c0 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 12 Feb 2015 18:17:11 +0000 Subject: [PATCH] Correctly handle all the places that can throw exceptions --- scripts/federation_client.py | 7 +++++-- synapse/federation/federation_base.py | 22 +++++++++++++--------- synapse/federation/federation_server.py | 9 ++++++--- synapse/handlers/federation.py | 12 ++++++++++++ 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/scripts/federation_client.py b/scripts/federation_client.py index 3139c6176..ea62dceb3 100644 --- a/scripts/federation_client.py +++ b/scripts/federation_client.py @@ -97,8 +97,11 @@ def lookup(destination, path): if ":" in destination: return "https://%s%s" % (destination, path) else: - srv = srvlookup.lookup("matrix", "tcp", destination)[0] - return "https://%s:%d%s" % (srv.host, srv.port, path) + try: + srv = srvlookup.lookup("matrix", "tcp", destination)[0] + return "https://%s:%d%s" % (srv.host, srv.port, path) + except: + return "https://%s:%d%s" % (destination, 8448, path) def get_json(origin_name, origin_key, destination, path): request_json = { diff --git a/synapse/federation/federation_base.py b/synapse/federation/federation_base.py index a990aec4f..30f3f5c8a 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, - ) + 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 + 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 b23f72c7f..9f5c98694 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 77c81fe2d..5a7593cc3 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):