mirror of
https://github.com/element-hq/synapse
synced 2024-08-19 01:00:54 +00:00
factor out _update_context_for_auth_events
This is duplicated, so let's factor it out before fixing it
This commit is contained in:
parent
f5cf3638e9
commit
1ca4288135
1 changed files with 42 additions and 20 deletions
|
@ -1706,6 +1706,17 @@ class FederationHandler(BaseHandler):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def do_auth(self, origin, event, context, auth_events):
|
def do_auth(self, origin, event, context, auth_events):
|
||||||
|
"""
|
||||||
|
|
||||||
|
Args:
|
||||||
|
origin (str):
|
||||||
|
event (synapse.events.FrozenEvent):
|
||||||
|
context (synapse.events.snapshot.EventContext):
|
||||||
|
auth_events (dict[(str, str)->str]):
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
defer.Deferred[None]
|
||||||
|
"""
|
||||||
# Check if we have all the auth events.
|
# Check if we have all the auth events.
|
||||||
current_state = set(e.event_id for e in auth_events.values())
|
current_state = set(e.event_id for e in auth_events.values())
|
||||||
event_auth_events = set(e_id for e_id, _ in event.auth_events)
|
event_auth_events = set(e_id for e_id, _ in event.auth_events)
|
||||||
|
@ -1817,16 +1828,9 @@ class FederationHandler(BaseHandler):
|
||||||
current_state = set(e.event_id for e in auth_events.values())
|
current_state = set(e.event_id for e in auth_events.values())
|
||||||
different_auth = event_auth_events - current_state
|
different_auth = event_auth_events - current_state
|
||||||
|
|
||||||
context.current_state_ids = dict(context.current_state_ids)
|
self._update_context_for_auth_events(
|
||||||
context.current_state_ids.update({
|
context, auth_events, event_key,
|
||||||
k: a.event_id for k, a in auth_events.items()
|
)
|
||||||
if k != event_key
|
|
||||||
})
|
|
||||||
context.prev_state_ids = dict(context.prev_state_ids)
|
|
||||||
context.prev_state_ids.update({
|
|
||||||
k: a.event_id for k, a in auth_events.items()
|
|
||||||
})
|
|
||||||
context.state_group = self.store.get_next_state_group()
|
|
||||||
|
|
||||||
if different_auth and not event.internal_metadata.is_outlier():
|
if different_auth and not event.internal_metadata.is_outlier():
|
||||||
logger.info("Different auth after resolution: %s", different_auth)
|
logger.info("Different auth after resolution: %s", different_auth)
|
||||||
|
@ -1906,16 +1910,9 @@ class FederationHandler(BaseHandler):
|
||||||
# 4. Look at rejects and their proofs.
|
# 4. Look at rejects and their proofs.
|
||||||
# TODO.
|
# TODO.
|
||||||
|
|
||||||
context.current_state_ids = dict(context.current_state_ids)
|
self._update_context_for_auth_events(
|
||||||
context.current_state_ids.update({
|
context, auth_events, event_key,
|
||||||
k: a.event_id for k, a in auth_events.items()
|
)
|
||||||
if k != event_key
|
|
||||||
})
|
|
||||||
context.prev_state_ids = dict(context.prev_state_ids)
|
|
||||||
context.prev_state_ids.update({
|
|
||||||
k: a.event_id for k, a in auth_events.items()
|
|
||||||
})
|
|
||||||
context.state_group = self.store.get_next_state_group()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.auth.check(event, auth_events=auth_events)
|
self.auth.check(event, auth_events=auth_events)
|
||||||
|
@ -1923,6 +1920,31 @@ class FederationHandler(BaseHandler):
|
||||||
logger.warn("Failed auth resolution for %r because %s", event, e)
|
logger.warn("Failed auth resolution for %r because %s", event, e)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
def _update_context_for_auth_events(self, context, auth_events,
|
||||||
|
event_key):
|
||||||
|
"""Update the state_ids in an event context after auth event resolution
|
||||||
|
|
||||||
|
Args:
|
||||||
|
context (synapse.events.snapshot.EventContext): event context
|
||||||
|
to be updated
|
||||||
|
|
||||||
|
auth_events (dict[(str, str)->str]): Events to update in the event
|
||||||
|
context.
|
||||||
|
|
||||||
|
event_key ((str, str)): (type, state_key) for the current event.
|
||||||
|
this will not be included in the current_state in the context.
|
||||||
|
"""
|
||||||
|
context.current_state_ids = dict(context.current_state_ids)
|
||||||
|
context.current_state_ids.update({
|
||||||
|
k: a.event_id for k, a in auth_events.items()
|
||||||
|
if k != event_key
|
||||||
|
})
|
||||||
|
context.prev_state_ids = dict(context.prev_state_ids)
|
||||||
|
context.prev_state_ids.update({
|
||||||
|
k: a.event_id for k, a in auth_events.items()
|
||||||
|
})
|
||||||
|
context.state_group = self.store.get_next_state_group()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def construct_auth_difference(self, local_auth, remote_auth):
|
def construct_auth_difference(self, local_auth, remote_auth):
|
||||||
""" Given a local and remote auth chain, find the differences. This
|
""" Given a local and remote auth chain, find the differences. This
|
||||||
|
|
Loading…
Reference in a new issue