diff options
author | Richard van der Hoff <richard@matrix.org> | 2017-03-09 13:15:27 +0000 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2017-03-09 15:50:44 +0000 |
commit | e8b1721290b196f9190f72517e8136d6af8cad58 (patch) | |
tree | 5b72f2d99ffa9a5bc137474cbe0f2a95f0a896bb | |
parent | Factor _get_missing_events_for_pdu out of _handle_new_pdu (diff) | |
download | synapse-e8b1721290b196f9190f72517e8136d6af8cad58.tar.xz |
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.
Diffstat (limited to '')
-rw-r--r-- | synapse/federation/federation_server.py | 48 |
1 files changed, 36 insertions, 12 deletions
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) @@ -497,8 +497,43 @@ class FederationServer(FederationBase): ) @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 = [] |