Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 4103f0e

Browse files
committed
Collect the sent_to_us_directly code together
We can now properly separate the two arms of the `if sent_to_us_directly` condition.
1 parent 8eca8c9 commit 4103f0e

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

changelog.d/10615.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clean up some of the federation event authentication code for clarity.

synapse/handlers/federation.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,32 @@ async def on_receive_pdu(
326326
if not missing_prevs:
327327
logger.info("Found all missing prev_events")
328328

329-
if missing_prevs:
330-
# We've still not been able to get all of the prev_events for this event.
329+
if missing_prevs:
330+
# since this event was pushed to us, it is possible for it to
331+
# become the only forward-extremity in the room, and we would then
332+
# trust its state to be the state for the whole room. This is very
333+
# bad. Further, if the event was pushed to us, there is no excuse
334+
# for us not to have all the prev_events. (XXX: apart from
335+
# min_depth?)
336+
#
337+
# We therefore reject any such events.
338+
logger.warning(
339+
"Rejecting: failed to fetch %d prev events: %s",
340+
len(missing_prevs),
341+
shortstr(missing_prevs),
342+
)
343+
raise FederationError(
344+
"ERROR",
345+
403,
346+
(
347+
"Your server isn't divulging details about prev_events "
348+
"referenced in this event."
349+
),
350+
affected=pdu.event_id,
351+
)
352+
353+
else:
354+
# We don't have all of the prev_events for this event.
331355
#
332356
# In this case, we need to fall back to asking another server in the
333357
# federation for the state at this event. That's ok provided we then
@@ -336,37 +360,15 @@ async def on_receive_pdu(
336360
# withholding its prev_events, and declaring yourself to be an admin in
337361
# the subsequent state request).
338362
#
339-
# Now, if we're pulling this event as a missing prev_event, then clearly
363+
# Since we're pulling this event as a missing prev_event, then clearly
340364
# this event is not going to become the only forward-extremity and we are
341365
# guaranteed to resolve its state against our existing forward
342366
# extremities, so that should be fine.
343367
#
344-
# On the other hand, if this event was pushed to us, it is possible for
345-
# it to become the only forward-extremity in the room, and we would then
346-
# trust its state to be the state for the whole room. This is very bad.
347-
# Further, if the event was pushed to us, there is no excuse for us not to
348-
# have all the prev_events. We therefore reject any such events.
349-
#
350368
# XXX this really feels like it could/should be merged with the above,
351369
# but there is an interaction with min_depth that I'm not really
352370
# following.
353371

354-
if sent_to_us_directly:
355-
logger.warning(
356-
"Rejecting: failed to fetch %d prev events: %s",
357-
len(missing_prevs),
358-
shortstr(missing_prevs),
359-
)
360-
raise FederationError(
361-
"ERROR",
362-
403,
363-
(
364-
"Your server isn't divulging details about prev_events "
365-
"referenced in this event."
366-
),
367-
affected=pdu.event_id,
368-
)
369-
370372
logger.info(
371373
"Event %s is missing prev_events %s: calculating state for a "
372374
"backwards extremity",

0 commit comments

Comments
 (0)