This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Faster joins: filter out non local events when a room doesn't have it…
…s full state (#14404) Signed-off-by: Mathieu Velten <[email protected]>
- Loading branch information
Mathieu Velten
authored
Nov 21, 2022
1 parent
640cb3c
commit 1526ff3
Showing
5 changed files
with
43 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Faster joins: filter out non local events when a room doesn't have its full state. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -563,7 +563,8 @@ def get_effective_room_visibility_from_state(state: StateMap[EventBase]) -> str: | |
|
||
async def filter_events_for_server( | ||
storage: StorageControllers, | ||
server_name: str, | ||
target_server_name: str, | ||
local_server_name: str, | ||
events: List[EventBase], | ||
redact: bool = True, | ||
check_history_visibility_only: bool = False, | ||
|
@@ -603,7 +604,7 @@ def check_event_is_visible( | |
# if the server is either in the room or has been invited | ||
# into the room. | ||
for ev in memberships.values(): | ||
assert get_domain_from_id(ev.state_key) == server_name | ||
assert get_domain_from_id(ev.state_key) == target_server_name | ||
|
||
memtype = ev.membership | ||
if memtype == Membership.JOIN: | ||
|
@@ -622,6 +623,24 @@ def check_event_is_visible( | |
# to no users having been erased. | ||
erased_senders = {} | ||
|
||
# Filter out non-local events when we are in the middle of a partial join, since our servers | ||
# list can be out of date and we could leak events to servers not in the room anymore. | ||
# This can also be true for local events but we consider it to be an acceptable risk. | ||
|
||
# We do this check as a first step and before retrieving membership events because | ||
# otherwise a room could be fully joined after we retrieve those, which would then bypass | ||
# this check but would base the filtering on an outdated view of the membership events. | ||
|
||
partial_state_invisible_events = set() | ||
if not check_history_visibility_only: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
MatMaul
Contributor
|
||
for e in events: | ||
sender_domain = get_domain_from_id(e.sender) | ||
if ( | ||
sender_domain != local_server_name | ||
and await storage.main.is_partial_state_room(e.room_id) | ||
): | ||
partial_state_invisible_events.add(e) | ||
|
||
# Let's check to see if all the events have a history visibility | ||
# of "shared" or "world_readable". If that's the case then we don't | ||
# need to check membership (as we know the server is in the room). | ||
|
@@ -636,7 +655,7 @@ def check_event_is_visible( | |
if event_to_history_vis[e.event_id] | ||
not in (HistoryVisibility.SHARED, HistoryVisibility.WORLD_READABLE) | ||
], | ||
server_name, | ||
target_server_name, | ||
) | ||
|
||
to_return = [] | ||
|
@@ -645,6 +664,10 @@ def check_event_is_visible( | |
visible = check_event_is_visible( | ||
event_to_history_vis[e.event_id], event_to_memberships.get(e.event_id, {}) | ||
) | ||
|
||
if e in partial_state_invisible_events: | ||
visible = False | ||
|
||
if visible and not erased: | ||
to_return.append(e) | ||
elif redact: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm very confused here. Why do we only ignore partial state events if we're not checking history visibility?