From e68c32d5ff77ebe2b9e39759be5481e9825641d0 Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Tue, 22 Nov 2022 11:56:33 +0100 Subject: [PATCH 1/3] Faster joins: use servers list approximation in assert_host_in_room Signed-off-by: Mathieu Velten --- changelog.d/14515.misc | 1 + synapse/handlers/event_auth.py | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 changelog.d/14515.misc diff --git a/changelog.d/14515.misc b/changelog.d/14515.misc new file mode 100644 index 000000000000..a0effb4dbeea --- /dev/null +++ b/changelog.d/14515.misc @@ -0,0 +1 @@ +Faster joins: use servers list approximation received during `send_join` (potentially updated with received membership events) in `assert_host_in_room`. \ No newline at end of file diff --git a/synapse/handlers/event_auth.py b/synapse/handlers/event_auth.py index 3bbad0271bcc..f74837326fc4 100644 --- a/synapse/handlers/event_auth.py +++ b/synapse/handlers/event_auth.py @@ -45,6 +45,7 @@ class EventAuthHandler: def __init__(self, hs: "HomeServer"): self._clock = hs.get_clock() self._store = hs.get_datastores().main + self._state_storage_controller = hs.get_storage_controllers().state self._server_name = hs.hostname async def check_auth_rules_from_context( @@ -179,14 +180,19 @@ async def assert_host_in_room( this function may return an incorrect result as we are not able to fully track server membership in a room without full state. """ - if not allow_partial_state_rooms and await self._store.is_partial_state_room( - room_id - ): - raise AuthError( - 403, - "Unable to authorise you right now; room is partial-stated here.", - errcode=Codes.UNABLE_DUE_TO_PARTIAL_STATE, - ) + if self._store.is_partial_state_room(room_id): + if allow_partial_state_rooms: + current_hosts = await self._state_storage_controller.get_current_hosts_in_room_or_partial_state_approximation( + room_id + ) + if host not in current_hosts: + raise AuthError(403, "Host not in room (partial-state approx).") + else: + raise AuthError( + 403, + "Unable to authorise you right now; room is partial-stated here.", + errcode=Codes.UNABLE_DUE_TO_PARTIAL_STATE, + ) if not await self.is_host_in_room(room_id, host): raise AuthError(403, "Host not in room.") From 00eda085d0133da56311c691e9ac29027f020402 Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Tue, 22 Nov 2022 12:54:59 +0100 Subject: [PATCH 2/3] Missing await --- synapse/handlers/event_auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/event_auth.py b/synapse/handlers/event_auth.py index f74837326fc4..6d8df4a448d6 100644 --- a/synapse/handlers/event_auth.py +++ b/synapse/handlers/event_auth.py @@ -180,7 +180,7 @@ async def assert_host_in_room( this function may return an incorrect result as we are not able to fully track server membership in a room without full state. """ - if self._store.is_partial_state_room(room_id): + if await self._store.is_partial_state_room(room_id): if allow_partial_state_rooms: current_hosts = await self._state_storage_controller.get_current_hosts_in_room_or_partial_state_approximation( room_id From f57f9406418f614001b832a612077a4cd984af30 Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Tue, 22 Nov 2022 18:15:14 +0100 Subject: [PATCH 3/3] Missing else --- synapse/handlers/event_auth.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/synapse/handlers/event_auth.py b/synapse/handlers/event_auth.py index 6d8df4a448d6..f91dbbecb79c 100644 --- a/synapse/handlers/event_auth.py +++ b/synapse/handlers/event_auth.py @@ -193,9 +193,9 @@ async def assert_host_in_room( "Unable to authorise you right now; room is partial-stated here.", errcode=Codes.UNABLE_DUE_TO_PARTIAL_STATE, ) - - if not await self.is_host_in_room(room_id, host): - raise AuthError(403, "Host not in room.") + else: + if not await self.is_host_in_room(room_id, host): + raise AuthError(403, "Host not in room.") async def check_restricted_join_rules( self,