mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Neaten the handling of state and auth_chain up a bit
This commit is contained in:
parent
9bace3a367
commit
7dd1c5c542
@ -30,6 +30,7 @@ from synapse.types import UserID
|
|||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
@ -112,14 +113,6 @@ class FederationHandler(BaseHandler):
|
|||||||
|
|
||||||
logger.debug("Event: %s", event)
|
logger.debug("Event: %s", event)
|
||||||
|
|
||||||
event_ids = set()
|
|
||||||
if state:
|
|
||||||
event_ids |= {e.event_id for e in state}
|
|
||||||
if auth_chain:
|
|
||||||
event_ids |= {e.event_id for e in auth_chain}
|
|
||||||
|
|
||||||
seen_ids = (yield self.store.have_events(event_ids)).keys()
|
|
||||||
|
|
||||||
# FIXME (erikj): Awful hack to make the case where we are not currently
|
# FIXME (erikj): Awful hack to make the case where we are not currently
|
||||||
# in the room work
|
# in the room work
|
||||||
current_state = None
|
current_state = None
|
||||||
@ -131,27 +124,37 @@ class FederationHandler(BaseHandler):
|
|||||||
logger.debug("Got event for room we're not in.")
|
logger.debug("Got event for room we're not in.")
|
||||||
current_state = state
|
current_state = state
|
||||||
|
|
||||||
if state and auth_chain is not None:
|
event_ids = set()
|
||||||
for list_of_pdus in [auth_chain, state]:
|
if state:
|
||||||
for e in list_of_pdus:
|
event_ids |= {e.event_id for e in state}
|
||||||
if e.event_id in seen_ids:
|
if auth_chain:
|
||||||
continue
|
event_ids |= {e.event_id for e in auth_chain}
|
||||||
|
|
||||||
e.internal_metadata.outlier = True
|
seen_ids = (yield self.store.have_events(event_ids)).keys()
|
||||||
try:
|
|
||||||
auth_ids = [e_id for e_id, _ in e.auth_events]
|
if state and auth_chain is not None:
|
||||||
auth = {
|
# If we have any state or auth_chain given to us by the replication
|
||||||
(e.type, e.state_key): e for e in auth_chain
|
# layer, then we should handle them (if we haven't before.)
|
||||||
if e.event_id in auth_ids
|
for e in itertools.chain(auth_chain, state):
|
||||||
}
|
if e.event_id in seen_ids:
|
||||||
yield self._handle_new_event(
|
continue
|
||||||
origin, e, auth_events=auth
|
|
||||||
)
|
e.internal_metadata.outlier = True
|
||||||
except:
|
try:
|
||||||
logger.exception(
|
auth_ids = [e_id for e_id, _ in e.auth_events]
|
||||||
"Failed to handle state event %s",
|
auth = {
|
||||||
e.event_id,
|
(e.type, e.state_key): e for e in auth_chain
|
||||||
)
|
if e.event_id in auth_ids
|
||||||
|
}
|
||||||
|
yield self._handle_new_event(
|
||||||
|
origin, e, auth_events=auth
|
||||||
|
)
|
||||||
|
seen_ids.add(e.event_id)
|
||||||
|
except:
|
||||||
|
logger.exception(
|
||||||
|
"Failed to handle state event %s",
|
||||||
|
e.event_id,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield self._handle_new_event(
|
yield self._handle_new_event(
|
||||||
|
Loading…
Reference in New Issue
Block a user