mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2025-01-11 05:39:30 -05:00
make FederationHandler._update_auth_events_and_context_for_auth async
This commit is contained in:
parent
bc9b75c6f0
commit
a25ddf26a3
@ -2200,10 +2200,13 @@ class FederationHandler(BaseHandler):
|
|||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def _update_auth_events_and_context_for_auth(
|
||||||
def _update_auth_events_and_context_for_auth(
|
self,
|
||||||
self, origin, event, context, auth_events
|
origin: str,
|
||||||
):
|
event: EventBase,
|
||||||
|
context: EventContext,
|
||||||
|
auth_events: StateMap[EventBase],
|
||||||
|
) -> EventContext:
|
||||||
"""Helper for do_auth. See there for docs.
|
"""Helper for do_auth. See there for docs.
|
||||||
|
|
||||||
Checks whether a given event has the expected auth events. If it
|
Checks whether a given event has the expected auth events. If it
|
||||||
@ -2211,16 +2214,16 @@ class FederationHandler(BaseHandler):
|
|||||||
we can come to a consensus (e.g. if one server missed some valid
|
we can come to a consensus (e.g. if one server missed some valid
|
||||||
state).
|
state).
|
||||||
|
|
||||||
This attempts to resovle any potential divergence of state between
|
This attempts to resolve any potential divergence of state between
|
||||||
servers, but is not essential and so failures should not block further
|
servers, but is not essential and so failures should not block further
|
||||||
processing of the event.
|
processing of the event.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
origin (str):
|
origin:
|
||||||
event (synapse.events.EventBase):
|
event:
|
||||||
context (synapse.events.snapshot.EventContext):
|
context:
|
||||||
|
|
||||||
auth_events (dict[(str, str)->synapse.events.EventBase]):
|
auth_events:
|
||||||
Map from (event_type, state_key) to event
|
Map from (event_type, state_key) to event
|
||||||
|
|
||||||
Normally, our calculated auth_events based on the state of the room
|
Normally, our calculated auth_events based on the state of the room
|
||||||
@ -2231,7 +2234,7 @@ class FederationHandler(BaseHandler):
|
|||||||
Also NB that this function adds entries to it.
|
Also NB that this function adds entries to it.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
defer.Deferred[EventContext]: updated context
|
updated context
|
||||||
"""
|
"""
|
||||||
event_auth_events = set(event.auth_event_ids())
|
event_auth_events = set(event.auth_event_ids())
|
||||||
|
|
||||||
@ -2245,7 +2248,7 @@ class FederationHandler(BaseHandler):
|
|||||||
#
|
#
|
||||||
# we start by checking if they are in the store, and then try calling /event_auth/.
|
# we start by checking if they are in the store, and then try calling /event_auth/.
|
||||||
if missing_auth:
|
if missing_auth:
|
||||||
have_events = yield self.store.have_seen_events(missing_auth)
|
have_events = await self.store.have_seen_events(missing_auth)
|
||||||
logger.debug("Events %s are in the store", have_events)
|
logger.debug("Events %s are in the store", have_events)
|
||||||
missing_auth.difference_update(have_events)
|
missing_auth.difference_update(have_events)
|
||||||
|
|
||||||
@ -2254,7 +2257,7 @@ class FederationHandler(BaseHandler):
|
|||||||
logger.info("auth_events contains unknown events: %s", missing_auth)
|
logger.info("auth_events contains unknown events: %s", missing_auth)
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
remote_auth_chain = yield self.federation_client.get_event_auth(
|
remote_auth_chain = await self.federation_client.get_event_auth(
|
||||||
origin, event.room_id, event.event_id
|
origin, event.room_id, event.event_id
|
||||||
)
|
)
|
||||||
except RequestSendFailed as e:
|
except RequestSendFailed as e:
|
||||||
@ -2263,7 +2266,7 @@ class FederationHandler(BaseHandler):
|
|||||||
logger.info("Failed to get event auth from remote: %s", e)
|
logger.info("Failed to get event auth from remote: %s", e)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
seen_remotes = yield self.store.have_seen_events(
|
seen_remotes = await self.store.have_seen_events(
|
||||||
[e.event_id for e in remote_auth_chain]
|
[e.event_id for e in remote_auth_chain]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -2286,9 +2289,7 @@ class FederationHandler(BaseHandler):
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
"do_auth %s missing_auth: %s", event.event_id, e.event_id
|
"do_auth %s missing_auth: %s", event.event_id, e.event_id
|
||||||
)
|
)
|
||||||
yield defer.ensureDeferred(
|
await self._handle_new_event(origin, e, auth_events=auth)
|
||||||
self._handle_new_event(origin, e, auth_events=auth)
|
|
||||||
)
|
|
||||||
|
|
||||||
if e.event_id in event_auth_events:
|
if e.event_id in event_auth_events:
|
||||||
auth_events[(e.type, e.state_key)] = e
|
auth_events[(e.type, e.state_key)] = e
|
||||||
@ -2322,7 +2323,7 @@ class FederationHandler(BaseHandler):
|
|||||||
|
|
||||||
# XXX: currently this checks for redactions but I'm not convinced that is
|
# XXX: currently this checks for redactions but I'm not convinced that is
|
||||||
# necessary?
|
# necessary?
|
||||||
different_events = yield self.store.get_events_as_list(different_auth)
|
different_events = await self.store.get_events_as_list(different_auth)
|
||||||
|
|
||||||
for d in different_events:
|
for d in different_events:
|
||||||
if d.room_id != event.room_id:
|
if d.room_id != event.room_id:
|
||||||
@ -2348,8 +2349,8 @@ class FederationHandler(BaseHandler):
|
|||||||
remote_auth_events.update({(d.type, d.state_key): d for d in different_events})
|
remote_auth_events.update({(d.type, d.state_key): d for d in different_events})
|
||||||
remote_state = remote_auth_events.values()
|
remote_state = remote_auth_events.values()
|
||||||
|
|
||||||
room_version = yield self.store.get_room_version_id(event.room_id)
|
room_version = await self.store.get_room_version_id(event.room_id)
|
||||||
new_state = yield self.state_handler.resolve_events(
|
new_state = await self.state_handler.resolve_events(
|
||||||
room_version, (local_state, remote_state), event
|
room_version, (local_state, remote_state), event
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -2364,7 +2365,7 @@ class FederationHandler(BaseHandler):
|
|||||||
|
|
||||||
auth_events.update(new_state)
|
auth_events.update(new_state)
|
||||||
|
|
||||||
context = yield self._update_context_for_auth_events(
|
context = await self._update_context_for_auth_events(
|
||||||
event, context, auth_events
|
event, context, auth_events
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user