Stop using BaseHandler in FederationEventHandler (#10745)

It's now only used in a couple of places, so we can drop it altogether.
This commit is contained in:
Richard van der Hoff 2021-09-06 14:49:33 +01:00 committed by GitHub
parent 40a1fddd1b
commit b298de780a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View File

@ -1 +1 @@
Move `kick_guest_users` into `RoomMemberHandler`. Clean up some of the federation event authentication code for clarity.

1
changelog.d/10745.misc Normal file
View File

@ -0,0 +1 @@
Clean up some of the federation event authentication code for clarity.

View File

@ -54,7 +54,6 @@ from synapse.event_auth import auth_types_for_event
from synapse.events import EventBase from synapse.events import EventBase
from synapse.events.snapshot import EventContext from synapse.events.snapshot import EventContext
from synapse.federation.federation_client import InvalidResponseError from synapse.federation.federation_client import InvalidResponseError
from synapse.handlers._base import BaseHandler
from synapse.logging.context import ( from synapse.logging.context import (
make_deferred_yieldable, make_deferred_yieldable,
nested_logging_context, nested_logging_context,
@ -117,7 +116,7 @@ class _NewEventInfo:
claimed_auth_event_map: StateMap[EventBase] claimed_auth_event_map: StateMap[EventBase]
class FederationEventHandler(BaseHandler): class FederationEventHandler:
"""Handles events that originated from federation. """Handles events that originated from federation.
Responsible for handing incoming events and passing them on to the rest Responsible for handing incoming events and passing them on to the rest
@ -125,8 +124,6 @@ class FederationEventHandler(BaseHandler):
""" """
def __init__(self, hs: "HomeServer"): def __init__(self, hs: "HomeServer"):
super().__init__(hs)
self.store = hs.get_datastore() self.store = hs.get_datastore()
self.storage = hs.get_storage() self.storage = hs.get_storage()
self.state_store = self.storage.state self.state_store = self.storage.state
@ -137,11 +134,15 @@ class FederationEventHandler(BaseHandler):
self._message_handler = hs.get_message_handler() self._message_handler = hs.get_message_handler()
self.action_generator = hs.get_action_generator() self.action_generator = hs.get_action_generator()
self._state_resolution_handler = hs.get_state_resolution_handler() 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.federation_client = hs.get_federation_client()
self.third_party_event_rules = hs.get_third_party_event_rules() 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.is_mine_id = hs.is_mine_id
self._server_name = hs.hostname
self._instance_name = hs.get_instance_name() self._instance_name = hs.get_instance_name()
self.config = hs.config self.config = hs.config
@ -222,7 +223,7 @@ class FederationEventHandler(BaseHandler):
# Note that if we were never in the room then we would have already # 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. # dropped the event, since we wouldn't know the room version.
is_in_room = await self._event_auth_handler.check_host_in_room( 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: if not is_in_room:
logger.info( logger.info(
@ -435,7 +436,7 @@ class FederationEventHandler(BaseHandler):
server from invalid events (there is probably no point in trying to server from invalid events (there is probably no point in trying to
re-fetch invalid events from every other HS in the room.) 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.") raise SynapseError(400, "Can't backfill from self.")
events = await self.federation_client.backfill( events = await self.federation_client.backfill(
@ -1030,7 +1031,7 @@ class FederationEventHandler(BaseHandler):
room_creator = create_event.content.get(EventContentFields.ROOM_CREATOR) room_creator = create_event.content.get(EventContentFields.ROOM_CREATOR)
if ( if (
not room_version.msc2716_historical not room_version.msc2716_historical
or not self.hs.config.experimental.msc2716_enabled or not self.config.experimental.msc2716_enabled
or marker_event.sender != room_creator or marker_event.sender != room_creator
): ):
return return
@ -1349,7 +1350,7 @@ class FederationEventHandler(BaseHandler):
current_state_map = await self.state_handler.get_current_state(event.room_id) current_state_map = await self.state_handler.get_current_state(event.room_id)
current_state = list(current_state_map.values()) 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( async def _check_for_soft_fail(
self, self,
@ -1804,7 +1805,7 @@ class FederationEventHandler(BaseHandler):
event_pos = PersistedEventPosition( event_pos = PersistedEventPosition(
self._instance_name, event.internal_metadata.stream_ordering 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 event, event_pos, max_stream_token, extra_users=extra_users
) )