0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-16 16:53:51 +01:00
This commit is contained in:
Amber Brown 2018-06-27 11:36:03 +01:00
parent 35cc3e8b14
commit a7ecf34b70

View file

@ -240,35 +240,37 @@ class FederationHandler(BaseHandler):
affected=pdu.event_id, affected=pdu.event_id,
) )
elif prevs - seen: elif prevs - seen:
# If we're walking back up the chain to fetch it, then # Calculate the state of the previous events, and
# try and find the states. If we can't get the states, # de-conflict them to find the current state.
# discard it.
state_groups = [] state_groups = []
auth_chains = set() auth_chains = set()
try: try:
# Get the ones we know about # Get the state of the events we know about
ours = yield self.store.get_state_groups(pdu.room_id, list(seen)) ours = yield self.store.get_state_groups(pdu.room_id, list(seen))
state_groups.append(ours) state_groups.append(ours)
# Ask the remote server for the states we don't
# know about
for p in prevs - seen: for p in prevs - seen:
state, auth_chain = yield self.replication_layer.get_state_for_room( state, got_auth_chain = yield self.replication_layer.get_state_for_room(
origin, pdu.room_id, p origin, pdu.room_id, p
) )
auth_chains.update(auth_chain) auth_chains.update(got_auth_chain)
state_group = { state_group = {(x.type, x.state_key): x.event_id for x in state}
(x.type, x.state_key): x.event_id for x in state
}
state_groups.append(state_group) state_groups.append(state_group)
# Resolve any conflicting state
def fetch(ev_ids): def fetch(ev_ids):
return self.store.get_events( return self.store.get_events(
ev_ids, get_prev_content=False, check_redacted=False, ev_ids, get_prev_content=False, check_redacted=False
) )
state = yield resolve_events_with_factory(state_groups, {pdu.event_id: pdu}, fetch) state_map = yield resolve_events_with_factory(
state_groups, {pdu.event_id: pdu}, fetch
)
state = yield self.store.get_events(state.values()) state = (yield self.store.get_events(state_map.values())).values()
state = state.values() auth_chain = list(auth_chains)
except Exception: except Exception:
raise FederationError( raise FederationError(
"ERROR", "ERROR",