From e8b1721290b196f9190f72517e8136d6af8cad58 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 9 Mar 2017 13:15:27 +0000 Subject: Move sig check out of _handle_new_pdu When we receive PDUs via `get_missing_events`, we have already checked their sigs, so there is no need to do it again. --- synapse/federation/federation_server.py | 48 ++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'synapse/federation') diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py index 3ef700f7fc..d8df6555d1 100644 --- a/synapse/federation/federation_server.py +++ b/synapse/federation/federation_server.py @@ -165,7 +165,7 @@ class FederationServer(FederationBase): ) try: - yield self._handle_new_pdu(transaction.origin, pdu) + yield self._handle_received_pdu(transaction.origin, pdu) results.append({}) except FederationError as e: self.send_failure(e, transaction.origin) @@ -496,9 +496,44 @@ class FederationServer(FederationBase): destination=None, ) + @defer.inlineCallbacks + def _handle_received_pdu(self, origin, pdu): + """ Process a PDU received in a federation /send/ transaction. + + Args: + origin (str): server which sent the pdu + pdu (FrozenEvent): received pdu + + Returns (Deferred): completes with None + Raises: FederationError if the signatures / hash do not match + """ + # Check signature. + try: + pdu = yield self._check_sigs_and_hash(pdu) + except SynapseError as e: + raise FederationError( + "ERROR", + e.code, + e.msg, + affected=pdu.event_id, + ) + + yield self._handle_new_pdu(origin, pdu, get_missing=True) + @defer.inlineCallbacks @log_function def _handle_new_pdu(self, origin, pdu, get_missing=True): + """ Process a PDU received via a federation /send/ transaction, or + via backfill of missing prev_events + + Args: + origin (str): server which initiated the /send/ transaction. Will + be used to fetch missing events or state. + pdu (FrozenEvent): received PDU + get_missing (bool): True if we should fetch missing prev_events + + Returns (Deferred): completes with None + """ # We reprocess pdus when we have seen them only as outliers existing = yield self._get_persisted_pdu( @@ -518,17 +553,6 @@ class FederationServer(FederationBase): logger.debug("Already seen pdu %s", pdu.event_id) return - # Check signature. - try: - pdu = yield self._check_sigs_and_hash(pdu) - except SynapseError as e: - raise FederationError( - "ERROR", - e.code, - e.msg, - affected=pdu.event_id, - ) - state = None auth_chain = [] -- cgit 1.4.1