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

Commit

Permalink
Stop using BaseHandler in FederationEventHandler
Browse files Browse the repository at this point in the history
It's now only used in a couple of places, so we can drop it altogether.
  • Loading branch information
richvdh committed Sep 6, 2021
1 parent 56e2a30 commit 6dd3287
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion changelog.d/10744.misc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Move `kick_guest_users` into `RoomMemberHandler`.
Clean up some of the federation event authentication code for clarity.
1 change: 1 addition & 0 deletions changelog.d/10745.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean up some of the federation event authentication code for clarity.
17 changes: 9 additions & 8 deletions synapse/handlers/federation_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
from synapse.events import EventBase
from synapse.events.snapshot import EventContext
from synapse.federation.federation_client import InvalidResponseError
from synapse.handlers._base import BaseHandler
from synapse.logging.context import (
make_deferred_yieldable,
nested_logging_context,
Expand Down Expand Up @@ -117,16 +116,14 @@ class _NewEventInfo:
claimed_auth_event_map: StateMap[EventBase]


class FederationEventHandler(BaseHandler):
class FederationEventHandler:
"""Handles events that originated from federation.
Responsible for handing incoming events and passing them on to the rest
of the homeserver (including auth and state conflict resolutions)
"""

def __init__(self, hs: "HomeServer"):
super().__init__(hs)

self.store = hs.get_datastore()
self.storage = hs.get_storage()
self.state_store = self.storage.state
Expand All @@ -137,11 +134,15 @@ def __init__(self, hs: "HomeServer"):
self._message_handler = hs.get_message_handler()
self.action_generator = hs.get_action_generator()
self._state_resolution_handler = hs.get_state_resolution_handler()
# avoid a circular dependency by deferring execution here
self._get_room_member_handler = hs.get_room_member_handler

self.federation_client = hs.get_federation_client()
self.third_party_event_rules = hs.get_third_party_event_rules()
self._notifier = hs.get_notifier()

self.is_mine_id = hs.is_mine_id
self._server_name = hs.hostname
self._instance_name = hs.get_instance_name()

self.config = hs.config
Expand Down Expand Up @@ -222,7 +223,7 @@ async def on_receive_pdu(self, origin: str, pdu: EventBase) -> None:
# Note that if we were never in the room then we would have already
# dropped the event, since we wouldn't know the room version.
is_in_room = await self._event_auth_handler.check_host_in_room(
room_id, self.server_name
room_id, self._server_name
)
if not is_in_room:
logger.info(
Expand Down Expand Up @@ -435,7 +436,7 @@ async def backfill(
server from invalid events (there is probably no point in trying to
re-fetch invalid events from every other HS in the room.)
"""
if dest == self.server_name:
if dest == self._server_name:
raise SynapseError(400, "Can't backfill from self.")

events = await self.federation_client.backfill(
Expand Down Expand Up @@ -1349,7 +1350,7 @@ async def _maybe_kick_guest_users(self, event: EventBase) -> None:

current_state_map = await self.state_handler.get_current_state(event.room_id)
current_state = list(current_state_map.values())
await self.hs.get_room_member_handler().kick_guest_users(current_state)
await self._get_room_member_handler().kick_guest_users(current_state)

async def _check_for_soft_fail(
self,
Expand Down Expand Up @@ -1804,7 +1805,7 @@ async def _notify_persisted_event(
event_pos = PersistedEventPosition(
self._instance_name, event.internal_metadata.stream_ordering
)
self.notifier.on_new_room_event(
self._notifier.on_new_room_event(
event, event_pos, max_stream_token, extra_users=extra_users
)

Expand Down

0 comments on commit 6dd3287

Please sign in to comment.