Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c89bd0e

Browse files
author
Mathieu Velten
committedNov 22, 2022
Faster joins: use servers list approximation in assert_host_in_room
1 parent 1526ff3 commit c89bd0e

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
 

‎changelog.d/14515.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Faster joins: use servers list approximation received during `send_join` (potentially updated with received membership events) in `assert_host_in_room`.

‎synapse/handlers/event_auth.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class EventAuthHandler:
4545
def __init__(self, hs: "HomeServer"):
4646
self._clock = hs.get_clock()
4747
self._store = hs.get_datastores().main
48+
self._state_storage_controller = hs.get_storage_controllers().state
4849
self._server_name = hs.hostname
4950

5051
async def check_auth_rules_from_context(
@@ -179,14 +180,19 @@ async def assert_host_in_room(
179180
this function may return an incorrect result as we are not able to fully
180181
track server membership in a room without full state.
181182
"""
182-
if not allow_partial_state_rooms and await self._store.is_partial_state_room(
183-
room_id
184-
):
185-
raise AuthError(
186-
403,
187-
"Unable to authorise you right now; room is partial-stated here.",
188-
errcode=Codes.UNABLE_DUE_TO_PARTIAL_STATE,
189-
)
183+
if self._store.is_partial_state_room(room_id):
184+
if allow_partial_state_rooms:
185+
current_hosts = await self._state_storage_controller.get_current_hosts_in_room_or_partial_state_approximation(
186+
room_id
187+
)
188+
if host not in current_hosts:
189+
raise AuthError(403, "Host not in room (partial-state approx).")
190+
else:
191+
raise AuthError(
192+
403,
193+
"Unable to authorise you right now; room is partial-stated here.",
194+
errcode=Codes.UNABLE_DUE_TO_PARTIAL_STATE,
195+
)
190196

191197
if not await self.is_host_in_room(room_id, host):
192198
raise AuthError(403, "Host not in room.")

0 commit comments

Comments
 (0)
This repository has been archived.