Add type hints to the federation server transport. (#10080)

This commit is contained in:
Patrick Cloke 2021-06-08 11:19:25 -04:00 committed by GitHub
parent e0ddd82f2c
commit c7f3fb2745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 194 additions and 75 deletions

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

@ -0,0 +1 @@
Add type hints to the federation servlets.

View File

@ -129,7 +129,7 @@ class FederationServer(FederationBase):
# come in waves. # come in waves.
self._state_resp_cache = ResponseCache( self._state_resp_cache = ResponseCache(
hs.get_clock(), "state_resp", timeout_ms=30000 hs.get_clock(), "state_resp", timeout_ms=30000
) # type: ResponseCache[Tuple[str, str]] ) # type: ResponseCache[Tuple[str, Optional[str]]]
self._state_ids_resp_cache = ResponseCache( self._state_ids_resp_cache = ResponseCache(
hs.get_clock(), "state_ids_resp", timeout_ms=30000 hs.get_clock(), "state_ids_resp", timeout_ms=30000
) # type: ResponseCache[Tuple[str, str]] ) # type: ResponseCache[Tuple[str, str]]
@ -406,7 +406,7 @@ class FederationServer(FederationBase):
) )
async def on_room_state_request( async def on_room_state_request(
self, origin: str, room_id: str, event_id: str self, origin: str, room_id: str, event_id: Optional[str]
) -> Tuple[int, Dict[str, Any]]: ) -> Tuple[int, Dict[str, Any]]:
origin_host, _ = parse_server_name(origin) origin_host, _ = parse_server_name(origin)
await self.check_server_matches_acl(origin_host, room_id) await self.check_server_matches_acl(origin_host, room_id)
@ -463,7 +463,7 @@ class FederationServer(FederationBase):
return {"pdu_ids": state_ids, "auth_chain_ids": auth_chain_ids} return {"pdu_ids": state_ids, "auth_chain_ids": auth_chain_ids}
async def _on_context_state_request_compute( async def _on_context_state_request_compute(
self, room_id: str, event_id: str self, room_id: str, event_id: Optional[str]
) -> Dict[str, list]: ) -> Dict[str, list]:
if event_id: if event_id:
pdus = await self.handler.get_state_for_pdu( pdus = await self.handler.get_state_for_pdu(

View File

@ -28,6 +28,7 @@ from synapse.api.urls import (
FEDERATION_V1_PREFIX, FEDERATION_V1_PREFIX,
FEDERATION_V2_PREFIX, FEDERATION_V2_PREFIX,
) )
from synapse.handlers.groups_local import GroupsLocalHandler
from synapse.http.server import HttpServer, JsonResource from synapse.http.server import HttpServer, JsonResource
from synapse.http.servlet import ( from synapse.http.servlet import (
parse_boolean_from_args, parse_boolean_from_args,
@ -275,10 +276,17 @@ class BaseFederationServlet:
RATELIMIT = True # Whether to rate limit requests or not RATELIMIT = True # Whether to rate limit requests or not
def __init__(self, handler, authenticator, ratelimiter, server_name): def __init__(
self.handler = handler self,
hs: HomeServer,
authenticator: Authenticator,
ratelimiter: FederationRateLimiter,
server_name: str,
):
self.hs = hs
self.authenticator = authenticator self.authenticator = authenticator
self.ratelimiter = ratelimiter self.ratelimiter = ratelimiter
self.server_name = server_name
def _wrap(self, func): def _wrap(self, func):
authenticator = self.authenticator authenticator = self.authenticator
@ -375,17 +383,30 @@ class BaseFederationServlet:
) )
class FederationSendServlet(BaseFederationServlet): class BaseFederationServerServlet(BaseFederationServlet):
"""Abstract base class for federation servlet classes which provides a federation server handler.
See BaseFederationServlet for more information.
"""
def __init__(
self,
hs: HomeServer,
authenticator: Authenticator,
ratelimiter: FederationRateLimiter,
server_name: str,
):
super().__init__(hs, authenticator, ratelimiter, server_name)
self.handler = hs.get_federation_server()
class FederationSendServlet(BaseFederationServerServlet):
PATH = "/send/(?P<transaction_id>[^/]*)/?" PATH = "/send/(?P<transaction_id>[^/]*)/?"
# We ratelimit manually in the handler as we queue up the requests and we # We ratelimit manually in the handler as we queue up the requests and we
# don't want to fill up the ratelimiter with blocked requests. # don't want to fill up the ratelimiter with blocked requests.
RATELIMIT = False RATELIMIT = False
def __init__(self, handler, server_name, **kwargs):
super().__init__(handler, server_name=server_name, **kwargs)
self.server_name = server_name
# This is when someone is trying to send us a bunch of data. # This is when someone is trying to send us a bunch of data.
async def on_PUT(self, origin, content, query, transaction_id): async def on_PUT(self, origin, content, query, transaction_id):
"""Called on PUT /send/<transaction_id>/ """Called on PUT /send/<transaction_id>/
@ -434,7 +455,7 @@ class FederationSendServlet(BaseFederationServlet):
return code, response return code, response
class FederationEventServlet(BaseFederationServlet): class FederationEventServlet(BaseFederationServerServlet):
PATH = "/event/(?P<event_id>[^/]*)/?" PATH = "/event/(?P<event_id>[^/]*)/?"
# This is when someone asks for a data item for a given server data_id pair. # This is when someone asks for a data item for a given server data_id pair.
@ -442,7 +463,7 @@ class FederationEventServlet(BaseFederationServlet):
return await self.handler.on_pdu_request(origin, event_id) return await self.handler.on_pdu_request(origin, event_id)
class FederationStateV1Servlet(BaseFederationServlet): class FederationStateV1Servlet(BaseFederationServerServlet):
PATH = "/state/(?P<room_id>[^/]*)/?" PATH = "/state/(?P<room_id>[^/]*)/?"
# This is when someone asks for all data for a given room. # This is when someone asks for all data for a given room.
@ -454,7 +475,7 @@ class FederationStateV1Servlet(BaseFederationServlet):
) )
class FederationStateIdsServlet(BaseFederationServlet): class FederationStateIdsServlet(BaseFederationServerServlet):
PATH = "/state_ids/(?P<room_id>[^/]*)/?" PATH = "/state_ids/(?P<room_id>[^/]*)/?"
async def on_GET(self, origin, content, query, room_id): async def on_GET(self, origin, content, query, room_id):
@ -465,7 +486,7 @@ class FederationStateIdsServlet(BaseFederationServlet):
) )
class FederationBackfillServlet(BaseFederationServlet): class FederationBackfillServlet(BaseFederationServerServlet):
PATH = "/backfill/(?P<room_id>[^/]*)/?" PATH = "/backfill/(?P<room_id>[^/]*)/?"
async def on_GET(self, origin, content, query, room_id): async def on_GET(self, origin, content, query, room_id):
@ -478,7 +499,7 @@ class FederationBackfillServlet(BaseFederationServlet):
return await self.handler.on_backfill_request(origin, room_id, versions, limit) return await self.handler.on_backfill_request(origin, room_id, versions, limit)
class FederationQueryServlet(BaseFederationServlet): class FederationQueryServlet(BaseFederationServerServlet):
PATH = "/query/(?P<query_type>[^/]*)" PATH = "/query/(?P<query_type>[^/]*)"
# This is when we receive a server-server Query # This is when we receive a server-server Query
@ -488,7 +509,7 @@ class FederationQueryServlet(BaseFederationServlet):
return await self.handler.on_query_request(query_type, args) return await self.handler.on_query_request(query_type, args)
class FederationMakeJoinServlet(BaseFederationServlet): class FederationMakeJoinServlet(BaseFederationServerServlet):
PATH = "/make_join/(?P<room_id>[^/]*)/(?P<user_id>[^/]*)" PATH = "/make_join/(?P<room_id>[^/]*)/(?P<user_id>[^/]*)"
async def on_GET(self, origin, _content, query, room_id, user_id): async def on_GET(self, origin, _content, query, room_id, user_id):
@ -518,7 +539,7 @@ class FederationMakeJoinServlet(BaseFederationServlet):
return 200, content return 200, content
class FederationMakeLeaveServlet(BaseFederationServlet): class FederationMakeLeaveServlet(BaseFederationServerServlet):
PATH = "/make_leave/(?P<room_id>[^/]*)/(?P<user_id>[^/]*)" PATH = "/make_leave/(?P<room_id>[^/]*)/(?P<user_id>[^/]*)"
async def on_GET(self, origin, content, query, room_id, user_id): async def on_GET(self, origin, content, query, room_id, user_id):
@ -526,7 +547,7 @@ class FederationMakeLeaveServlet(BaseFederationServlet):
return 200, content return 200, content
class FederationV1SendLeaveServlet(BaseFederationServlet): class FederationV1SendLeaveServlet(BaseFederationServerServlet):
PATH = "/send_leave/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)" PATH = "/send_leave/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)"
async def on_PUT(self, origin, content, query, room_id, event_id): async def on_PUT(self, origin, content, query, room_id, event_id):
@ -534,7 +555,7 @@ class FederationV1SendLeaveServlet(BaseFederationServlet):
return 200, (200, content) return 200, (200, content)
class FederationV2SendLeaveServlet(BaseFederationServlet): class FederationV2SendLeaveServlet(BaseFederationServerServlet):
PATH = "/send_leave/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)" PATH = "/send_leave/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)"
PREFIX = FEDERATION_V2_PREFIX PREFIX = FEDERATION_V2_PREFIX
@ -544,14 +565,14 @@ class FederationV2SendLeaveServlet(BaseFederationServlet):
return 200, content return 200, content
class FederationEventAuthServlet(BaseFederationServlet): class FederationEventAuthServlet(BaseFederationServerServlet):
PATH = "/event_auth/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)" PATH = "/event_auth/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)"
async def on_GET(self, origin, content, query, room_id, event_id): async def on_GET(self, origin, content, query, room_id, event_id):
return await self.handler.on_event_auth(origin, room_id, event_id) return await self.handler.on_event_auth(origin, room_id, event_id)
class FederationV1SendJoinServlet(BaseFederationServlet): class FederationV1SendJoinServlet(BaseFederationServerServlet):
PATH = "/send_join/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)" PATH = "/send_join/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)"
async def on_PUT(self, origin, content, query, room_id, event_id): async def on_PUT(self, origin, content, query, room_id, event_id):
@ -561,7 +582,7 @@ class FederationV1SendJoinServlet(BaseFederationServlet):
return 200, (200, content) return 200, (200, content)
class FederationV2SendJoinServlet(BaseFederationServlet): class FederationV2SendJoinServlet(BaseFederationServerServlet):
PATH = "/send_join/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)" PATH = "/send_join/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)"
PREFIX = FEDERATION_V2_PREFIX PREFIX = FEDERATION_V2_PREFIX
@ -573,7 +594,7 @@ class FederationV2SendJoinServlet(BaseFederationServlet):
return 200, content return 200, content
class FederationV1InviteServlet(BaseFederationServlet): class FederationV1InviteServlet(BaseFederationServerServlet):
PATH = "/invite/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)" PATH = "/invite/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)"
async def on_PUT(self, origin, content, query, room_id, event_id): async def on_PUT(self, origin, content, query, room_id, event_id):
@ -590,7 +611,7 @@ class FederationV1InviteServlet(BaseFederationServlet):
return 200, (200, content) return 200, (200, content)
class FederationV2InviteServlet(BaseFederationServlet): class FederationV2InviteServlet(BaseFederationServerServlet):
PATH = "/invite/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)" PATH = "/invite/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)"
PREFIX = FEDERATION_V2_PREFIX PREFIX = FEDERATION_V2_PREFIX
@ -614,7 +635,7 @@ class FederationV2InviteServlet(BaseFederationServlet):
return 200, content return 200, content
class FederationThirdPartyInviteExchangeServlet(BaseFederationServlet): class FederationThirdPartyInviteExchangeServlet(BaseFederationServerServlet):
PATH = "/exchange_third_party_invite/(?P<room_id>[^/]*)" PATH = "/exchange_third_party_invite/(?P<room_id>[^/]*)"
async def on_PUT(self, origin, content, query, room_id): async def on_PUT(self, origin, content, query, room_id):
@ -622,21 +643,21 @@ class FederationThirdPartyInviteExchangeServlet(BaseFederationServlet):
return 200, {} return 200, {}
class FederationClientKeysQueryServlet(BaseFederationServlet): class FederationClientKeysQueryServlet(BaseFederationServerServlet):
PATH = "/user/keys/query" PATH = "/user/keys/query"
async def on_POST(self, origin, content, query): async def on_POST(self, origin, content, query):
return await self.handler.on_query_client_keys(origin, content) return await self.handler.on_query_client_keys(origin, content)
class FederationUserDevicesQueryServlet(BaseFederationServlet): class FederationUserDevicesQueryServlet(BaseFederationServerServlet):
PATH = "/user/devices/(?P<user_id>[^/]*)" PATH = "/user/devices/(?P<user_id>[^/]*)"
async def on_GET(self, origin, content, query, user_id): async def on_GET(self, origin, content, query, user_id):
return await self.handler.on_query_user_devices(origin, user_id) return await self.handler.on_query_user_devices(origin, user_id)
class FederationClientKeysClaimServlet(BaseFederationServlet): class FederationClientKeysClaimServlet(BaseFederationServerServlet):
PATH = "/user/keys/claim" PATH = "/user/keys/claim"
async def on_POST(self, origin, content, query): async def on_POST(self, origin, content, query):
@ -644,7 +665,7 @@ class FederationClientKeysClaimServlet(BaseFederationServlet):
return 200, response return 200, response
class FederationGetMissingEventsServlet(BaseFederationServlet): class FederationGetMissingEventsServlet(BaseFederationServerServlet):
# TODO(paul): Why does this path alone end with "/?" optional? # TODO(paul): Why does this path alone end with "/?" optional?
PATH = "/get_missing_events/(?P<room_id>[^/]*)/?" PATH = "/get_missing_events/(?P<room_id>[^/]*)/?"
@ -664,7 +685,7 @@ class FederationGetMissingEventsServlet(BaseFederationServlet):
return 200, content return 200, content
class On3pidBindServlet(BaseFederationServlet): class On3pidBindServlet(BaseFederationServerServlet):
PATH = "/3pid/onbind" PATH = "/3pid/onbind"
REQUIRE_AUTH = False REQUIRE_AUTH = False
@ -694,7 +715,7 @@ class On3pidBindServlet(BaseFederationServlet):
return 200, {} return 200, {}
class OpenIdUserInfo(BaseFederationServlet): class OpenIdUserInfo(BaseFederationServerServlet):
""" """
Exchange a bearer token for information about a user. Exchange a bearer token for information about a user.
@ -770,8 +791,16 @@ class PublicRoomList(BaseFederationServlet):
PATH = "/publicRooms" PATH = "/publicRooms"
def __init__(self, handler, authenticator, ratelimiter, server_name, allow_access): def __init__(
super().__init__(handler, authenticator, ratelimiter, server_name) self,
hs: HomeServer,
authenticator: Authenticator,
ratelimiter: FederationRateLimiter,
server_name: str,
allow_access: bool,
):
super().__init__(hs, authenticator, ratelimiter, server_name)
self.handler = hs.get_room_list_handler()
self.allow_access = allow_access self.allow_access = allow_access
async def on_GET(self, origin, content, query): async def on_GET(self, origin, content, query):
@ -856,7 +885,24 @@ class FederationVersionServlet(BaseFederationServlet):
) )
class FederationGroupsProfileServlet(BaseFederationServlet): class BaseGroupsServerServlet(BaseFederationServlet):
"""Abstract base class for federation servlet classes which provides a groups server handler.
See BaseFederationServlet for more information.
"""
def __init__(
self,
hs: HomeServer,
authenticator: Authenticator,
ratelimiter: FederationRateLimiter,
server_name: str,
):
super().__init__(hs, authenticator, ratelimiter, server_name)
self.handler = hs.get_groups_server_handler()
class FederationGroupsProfileServlet(BaseGroupsServerServlet):
"""Get/set the basic profile of a group on behalf of a user""" """Get/set the basic profile of a group on behalf of a user"""
PATH = "/groups/(?P<group_id>[^/]*)/profile" PATH = "/groups/(?P<group_id>[^/]*)/profile"
@ -882,7 +928,7 @@ class FederationGroupsProfileServlet(BaseFederationServlet):
return 200, new_content return 200, new_content
class FederationGroupsSummaryServlet(BaseFederationServlet): class FederationGroupsSummaryServlet(BaseGroupsServerServlet):
PATH = "/groups/(?P<group_id>[^/]*)/summary" PATH = "/groups/(?P<group_id>[^/]*)/summary"
async def on_GET(self, origin, content, query, group_id): async def on_GET(self, origin, content, query, group_id):
@ -895,7 +941,7 @@ class FederationGroupsSummaryServlet(BaseFederationServlet):
return 200, new_content return 200, new_content
class FederationGroupsRoomsServlet(BaseFederationServlet): class FederationGroupsRoomsServlet(BaseGroupsServerServlet):
"""Get the rooms in a group on behalf of a user""" """Get the rooms in a group on behalf of a user"""
PATH = "/groups/(?P<group_id>[^/]*)/rooms" PATH = "/groups/(?P<group_id>[^/]*)/rooms"
@ -910,7 +956,7 @@ class FederationGroupsRoomsServlet(BaseFederationServlet):
return 200, new_content return 200, new_content
class FederationGroupsAddRoomsServlet(BaseFederationServlet): class FederationGroupsAddRoomsServlet(BaseGroupsServerServlet):
"""Add/remove room from group""" """Add/remove room from group"""
PATH = "/groups/(?P<group_id>[^/]*)/room/(?P<room_id>[^/]*)" PATH = "/groups/(?P<group_id>[^/]*)/room/(?P<room_id>[^/]*)"
@ -938,7 +984,7 @@ class FederationGroupsAddRoomsServlet(BaseFederationServlet):
return 200, new_content return 200, new_content
class FederationGroupsAddRoomsConfigServlet(BaseFederationServlet): class FederationGroupsAddRoomsConfigServlet(BaseGroupsServerServlet):
"""Update room config in group""" """Update room config in group"""
PATH = ( PATH = (
@ -958,7 +1004,7 @@ class FederationGroupsAddRoomsConfigServlet(BaseFederationServlet):
return 200, result return 200, result
class FederationGroupsUsersServlet(BaseFederationServlet): class FederationGroupsUsersServlet(BaseGroupsServerServlet):
"""Get the users in a group on behalf of a user""" """Get the users in a group on behalf of a user"""
PATH = "/groups/(?P<group_id>[^/]*)/users" PATH = "/groups/(?P<group_id>[^/]*)/users"
@ -973,7 +1019,7 @@ class FederationGroupsUsersServlet(BaseFederationServlet):
return 200, new_content return 200, new_content
class FederationGroupsInvitedUsersServlet(BaseFederationServlet): class FederationGroupsInvitedUsersServlet(BaseGroupsServerServlet):
"""Get the users that have been invited to a group""" """Get the users that have been invited to a group"""
PATH = "/groups/(?P<group_id>[^/]*)/invited_users" PATH = "/groups/(?P<group_id>[^/]*)/invited_users"
@ -990,7 +1036,7 @@ class FederationGroupsInvitedUsersServlet(BaseFederationServlet):
return 200, new_content return 200, new_content
class FederationGroupsInviteServlet(BaseFederationServlet): class FederationGroupsInviteServlet(BaseGroupsServerServlet):
"""Ask a group server to invite someone to the group""" """Ask a group server to invite someone to the group"""
PATH = "/groups/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/invite" PATH = "/groups/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/invite"
@ -1007,7 +1053,7 @@ class FederationGroupsInviteServlet(BaseFederationServlet):
return 200, new_content return 200, new_content
class FederationGroupsAcceptInviteServlet(BaseFederationServlet): class FederationGroupsAcceptInviteServlet(BaseGroupsServerServlet):
"""Accept an invitation from the group server""" """Accept an invitation from the group server"""
PATH = "/groups/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/accept_invite" PATH = "/groups/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/accept_invite"
@ -1021,7 +1067,7 @@ class FederationGroupsAcceptInviteServlet(BaseFederationServlet):
return 200, new_content return 200, new_content
class FederationGroupsJoinServlet(BaseFederationServlet): class FederationGroupsJoinServlet(BaseGroupsServerServlet):
"""Attempt to join a group""" """Attempt to join a group"""
PATH = "/groups/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/join" PATH = "/groups/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/join"
@ -1035,7 +1081,7 @@ class FederationGroupsJoinServlet(BaseFederationServlet):
return 200, new_content return 200, new_content
class FederationGroupsRemoveUserServlet(BaseFederationServlet): class FederationGroupsRemoveUserServlet(BaseGroupsServerServlet):
"""Leave or kick a user from the group""" """Leave or kick a user from the group"""
PATH = "/groups/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/remove" PATH = "/groups/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/remove"
@ -1052,7 +1098,24 @@ class FederationGroupsRemoveUserServlet(BaseFederationServlet):
return 200, new_content return 200, new_content
class FederationGroupsLocalInviteServlet(BaseFederationServlet): class BaseGroupsLocalServlet(BaseFederationServlet):
"""Abstract base class for federation servlet classes which provides a groups local handler.
See BaseFederationServlet for more information.
"""
def __init__(
self,
hs: HomeServer,
authenticator: Authenticator,
ratelimiter: FederationRateLimiter,
server_name: str,
):
super().__init__(hs, authenticator, ratelimiter, server_name)
self.handler = hs.get_groups_local_handler()
class FederationGroupsLocalInviteServlet(BaseGroupsLocalServlet):
"""A group server has invited a local user""" """A group server has invited a local user"""
PATH = "/groups/local/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/invite" PATH = "/groups/local/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/invite"
@ -1061,12 +1124,16 @@ class FederationGroupsLocalInviteServlet(BaseFederationServlet):
if get_domain_from_id(group_id) != origin: if get_domain_from_id(group_id) != origin:
raise SynapseError(403, "group_id doesn't match origin") raise SynapseError(403, "group_id doesn't match origin")
assert isinstance(
self.handler, GroupsLocalHandler
), "Workers cannot handle group invites."
new_content = await self.handler.on_invite(group_id, user_id, content) new_content = await self.handler.on_invite(group_id, user_id, content)
return 200, new_content return 200, new_content
class FederationGroupsRemoveLocalUserServlet(BaseFederationServlet): class FederationGroupsRemoveLocalUserServlet(BaseGroupsLocalServlet):
"""A group server has removed a local user""" """A group server has removed a local user"""
PATH = "/groups/local/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/remove" PATH = "/groups/local/(?P<group_id>[^/]*)/users/(?P<user_id>[^/]*)/remove"
@ -1075,6 +1142,10 @@ class FederationGroupsRemoveLocalUserServlet(BaseFederationServlet):
if get_domain_from_id(group_id) != origin: if get_domain_from_id(group_id) != origin:
raise SynapseError(403, "user_id doesn't match origin") raise SynapseError(403, "user_id doesn't match origin")
assert isinstance(
self.handler, GroupsLocalHandler
), "Workers cannot handle group removals."
new_content = await self.handler.user_removed_from_group( new_content = await self.handler.user_removed_from_group(
group_id, user_id, content group_id, user_id, content
) )
@ -1087,6 +1158,16 @@ class FederationGroupsRenewAttestaionServlet(BaseFederationServlet):
PATH = "/groups/(?P<group_id>[^/]*)/renew_attestation/(?P<user_id>[^/]*)" PATH = "/groups/(?P<group_id>[^/]*)/renew_attestation/(?P<user_id>[^/]*)"
def __init__(
self,
hs: HomeServer,
authenticator: Authenticator,
ratelimiter: FederationRateLimiter,
server_name: str,
):
super().__init__(hs, authenticator, ratelimiter, server_name)
self.handler = hs.get_groups_attestation_renewer()
async def on_POST(self, origin, content, query, group_id, user_id): async def on_POST(self, origin, content, query, group_id, user_id):
# We don't need to check auth here as we check the attestation signatures # We don't need to check auth here as we check the attestation signatures
@ -1097,7 +1178,7 @@ class FederationGroupsRenewAttestaionServlet(BaseFederationServlet):
return 200, new_content return 200, new_content
class FederationGroupsSummaryRoomsServlet(BaseFederationServlet): class FederationGroupsSummaryRoomsServlet(BaseGroupsServerServlet):
"""Add/remove a room from the group summary, with optional category. """Add/remove a room from the group summary, with optional category.
Matches both: Matches both:
@ -1154,7 +1235,7 @@ class FederationGroupsSummaryRoomsServlet(BaseFederationServlet):
return 200, resp return 200, resp
class FederationGroupsCategoriesServlet(BaseFederationServlet): class FederationGroupsCategoriesServlet(BaseGroupsServerServlet):
"""Get all categories for a group""" """Get all categories for a group"""
PATH = "/groups/(?P<group_id>[^/]*)/categories/?" PATH = "/groups/(?P<group_id>[^/]*)/categories/?"
@ -1169,7 +1250,7 @@ class FederationGroupsCategoriesServlet(BaseFederationServlet):
return 200, resp return 200, resp
class FederationGroupsCategoryServlet(BaseFederationServlet): class FederationGroupsCategoryServlet(BaseGroupsServerServlet):
"""Add/remove/get a category in a group""" """Add/remove/get a category in a group"""
PATH = "/groups/(?P<group_id>[^/]*)/categories/(?P<category_id>[^/]+)" PATH = "/groups/(?P<group_id>[^/]*)/categories/(?P<category_id>[^/]+)"
@ -1222,7 +1303,7 @@ class FederationGroupsCategoryServlet(BaseFederationServlet):
return 200, resp return 200, resp
class FederationGroupsRolesServlet(BaseFederationServlet): class FederationGroupsRolesServlet(BaseGroupsServerServlet):
"""Get roles in a group""" """Get roles in a group"""
PATH = "/groups/(?P<group_id>[^/]*)/roles/?" PATH = "/groups/(?P<group_id>[^/]*)/roles/?"
@ -1237,7 +1318,7 @@ class FederationGroupsRolesServlet(BaseFederationServlet):
return 200, resp return 200, resp
class FederationGroupsRoleServlet(BaseFederationServlet): class FederationGroupsRoleServlet(BaseGroupsServerServlet):
"""Add/remove/get a role in a group""" """Add/remove/get a role in a group"""
PATH = "/groups/(?P<group_id>[^/]*)/roles/(?P<role_id>[^/]+)" PATH = "/groups/(?P<group_id>[^/]*)/roles/(?P<role_id>[^/]+)"
@ -1290,7 +1371,7 @@ class FederationGroupsRoleServlet(BaseFederationServlet):
return 200, resp return 200, resp
class FederationGroupsSummaryUsersServlet(BaseFederationServlet): class FederationGroupsSummaryUsersServlet(BaseGroupsServerServlet):
"""Add/remove a user from the group summary, with optional role. """Add/remove a user from the group summary, with optional role.
Matches both: Matches both:
@ -1345,7 +1426,7 @@ class FederationGroupsSummaryUsersServlet(BaseFederationServlet):
return 200, resp return 200, resp
class FederationGroupsBulkPublicisedServlet(BaseFederationServlet): class FederationGroupsBulkPublicisedServlet(BaseGroupsLocalServlet):
"""Get roles in a group""" """Get roles in a group"""
PATH = "/get_groups_publicised" PATH = "/get_groups_publicised"
@ -1358,7 +1439,7 @@ class FederationGroupsBulkPublicisedServlet(BaseFederationServlet):
return 200, resp return 200, resp
class FederationGroupsSettingJoinPolicyServlet(BaseFederationServlet): class FederationGroupsSettingJoinPolicyServlet(BaseGroupsServerServlet):
"""Sets whether a group is joinable without an invite or knock""" """Sets whether a group is joinable without an invite or knock"""
PATH = "/groups/(?P<group_id>[^/]*)/settings/m.join_policy" PATH = "/groups/(?P<group_id>[^/]*)/settings/m.join_policy"
@ -1379,6 +1460,16 @@ class FederationSpaceSummaryServlet(BaseFederationServlet):
PREFIX = FEDERATION_UNSTABLE_PREFIX + "/org.matrix.msc2946" PREFIX = FEDERATION_UNSTABLE_PREFIX + "/org.matrix.msc2946"
PATH = "/spaces/(?P<room_id>[^/]*)" PATH = "/spaces/(?P<room_id>[^/]*)"
def __init__(
self,
hs: HomeServer,
authenticator: Authenticator,
ratelimiter: FederationRateLimiter,
server_name: str,
):
super().__init__(hs, authenticator, ratelimiter, server_name)
self.handler = hs.get_space_summary_handler()
async def on_GET( async def on_GET(
self, self,
origin: str, origin: str,
@ -1444,16 +1535,25 @@ class RoomComplexityServlet(BaseFederationServlet):
PATH = "/rooms/(?P<room_id>[^/]*)/complexity" PATH = "/rooms/(?P<room_id>[^/]*)/complexity"
PREFIX = FEDERATION_UNSTABLE_PREFIX PREFIX = FEDERATION_UNSTABLE_PREFIX
def __init__(
self,
hs: HomeServer,
authenticator: Authenticator,
ratelimiter: FederationRateLimiter,
server_name: str,
):
super().__init__(hs, authenticator, ratelimiter, server_name)
self._store = self.hs.get_datastore()
async def on_GET(self, origin, content, query, room_id): async def on_GET(self, origin, content, query, room_id):
is_public = await self._store.is_room_world_readable_or_publicly_joinable(
store = self.handler.hs.get_datastore() room_id
)
is_public = await store.is_room_world_readable_or_publicly_joinable(room_id)
if not is_public: if not is_public:
raise SynapseError(404, "Room not found", errcode=Codes.INVALID_PARAM) raise SynapseError(404, "Room not found", errcode=Codes.INVALID_PARAM)
complexity = await store.get_room_complexity(room_id) complexity = await self._store.get_room_complexity(room_id)
return 200, complexity return 200, complexity
@ -1482,6 +1582,7 @@ FEDERATION_SERVLET_CLASSES = (
On3pidBindServlet, On3pidBindServlet,
FederationVersionServlet, FederationVersionServlet,
RoomComplexityServlet, RoomComplexityServlet,
FederationSpaceSummaryServlet,
) # type: Tuple[Type[BaseFederationServlet], ...] ) # type: Tuple[Type[BaseFederationServlet], ...]
OPENID_SERVLET_CLASSES = ( OPENID_SERVLET_CLASSES = (
@ -1559,14 +1660,7 @@ def register_servlets(
if "federation" in servlet_groups: if "federation" in servlet_groups:
for servletclass in FEDERATION_SERVLET_CLASSES: for servletclass in FEDERATION_SERVLET_CLASSES:
servletclass( servletclass(
handler=hs.get_federation_server(), hs=hs,
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)
FederationSpaceSummaryServlet(
handler=hs.get_space_summary_handler(),
authenticator=authenticator, authenticator=authenticator,
ratelimiter=ratelimiter, ratelimiter=ratelimiter,
server_name=hs.hostname, server_name=hs.hostname,
@ -1575,7 +1669,7 @@ def register_servlets(
if "openid" in servlet_groups: if "openid" in servlet_groups:
for servletclass in OPENID_SERVLET_CLASSES: for servletclass in OPENID_SERVLET_CLASSES:
servletclass( servletclass(
handler=hs.get_federation_server(), hs=hs,
authenticator=authenticator, authenticator=authenticator,
ratelimiter=ratelimiter, ratelimiter=ratelimiter,
server_name=hs.hostname, server_name=hs.hostname,
@ -1584,7 +1678,7 @@ def register_servlets(
if "room_list" in servlet_groups: if "room_list" in servlet_groups:
for servletclass in ROOM_LIST_CLASSES: for servletclass in ROOM_LIST_CLASSES:
servletclass( servletclass(
handler=hs.get_room_list_handler(), hs=hs,
authenticator=authenticator, authenticator=authenticator,
ratelimiter=ratelimiter, ratelimiter=ratelimiter,
server_name=hs.hostname, server_name=hs.hostname,
@ -1594,7 +1688,7 @@ def register_servlets(
if "group_server" in servlet_groups: if "group_server" in servlet_groups:
for servletclass in GROUP_SERVER_SERVLET_CLASSES: for servletclass in GROUP_SERVER_SERVLET_CLASSES:
servletclass( servletclass(
handler=hs.get_groups_server_handler(), hs=hs,
authenticator=authenticator, authenticator=authenticator,
ratelimiter=ratelimiter, ratelimiter=ratelimiter,
server_name=hs.hostname, server_name=hs.hostname,
@ -1603,7 +1697,7 @@ def register_servlets(
if "group_local" in servlet_groups: if "group_local" in servlet_groups:
for servletclass in GROUP_LOCAL_SERVLET_CLASSES: for servletclass in GROUP_LOCAL_SERVLET_CLASSES:
servletclass( servletclass(
handler=hs.get_groups_local_handler(), hs=hs,
authenticator=authenticator, authenticator=authenticator,
ratelimiter=ratelimiter, ratelimiter=ratelimiter,
server_name=hs.hostname, server_name=hs.hostname,
@ -1612,7 +1706,7 @@ def register_servlets(
if "group_attestation" in servlet_groups: if "group_attestation" in servlet_groups:
for servletclass in GROUP_ATTESTATION_SERVLET_CLASSES: for servletclass in GROUP_ATTESTATION_SERVLET_CLASSES:
servletclass( servletclass(
handler=hs.get_groups_attestation_renewer(), hs=hs,
authenticator=authenticator, authenticator=authenticator,
ratelimiter=ratelimiter, ratelimiter=ratelimiter,
server_name=hs.hostname, server_name=hs.hostname,

View File

@ -44,7 +44,7 @@ class RoomListHandler(BaseHandler):
self.enable_room_list_search = hs.config.enable_room_list_search self.enable_room_list_search = hs.config.enable_room_list_search
self.response_cache = ResponseCache( self.response_cache = ResponseCache(
hs.get_clock(), "room_list" hs.get_clock(), "room_list"
) # type: ResponseCache[Tuple[Optional[int], Optional[str], ThirdPartyInstanceID]] ) # type: ResponseCache[Tuple[Optional[int], Optional[str], Optional[ThirdPartyInstanceID]]]
self.remote_response_cache = ResponseCache( self.remote_response_cache = ResponseCache(
hs.get_clock(), "remote_room_list", timeout_ms=30 * 1000 hs.get_clock(), "remote_room_list", timeout_ms=30 * 1000
) # type: ResponseCache[Tuple[str, Optional[int], Optional[str], bool, Optional[str]]] ) # type: ResponseCache[Tuple[str, Optional[int], Optional[str], bool, Optional[str]]]
@ -54,7 +54,7 @@ class RoomListHandler(BaseHandler):
limit: Optional[int] = None, limit: Optional[int] = None,
since_token: Optional[str] = None, since_token: Optional[str] = None,
search_filter: Optional[dict] = None, search_filter: Optional[dict] = None,
network_tuple: ThirdPartyInstanceID = EMPTY_THIRD_PARTY_ID, network_tuple: Optional[ThirdPartyInstanceID] = EMPTY_THIRD_PARTY_ID,
from_federation: bool = False, from_federation: bool = False,
) -> JsonDict: ) -> JsonDict:
"""Generate a local public room list. """Generate a local public room list.
@ -111,7 +111,7 @@ class RoomListHandler(BaseHandler):
limit: Optional[int] = None, limit: Optional[int] = None,
since_token: Optional[str] = None, since_token: Optional[str] = None,
search_filter: Optional[dict] = None, search_filter: Optional[dict] = None,
network_tuple: ThirdPartyInstanceID = EMPTY_THIRD_PARTY_ID, network_tuple: Optional[ThirdPartyInstanceID] = EMPTY_THIRD_PARTY_ID,
from_federation: bool = False, from_federation: bool = False,
) -> JsonDict: ) -> JsonDict:
"""Generate a public room list. """Generate a public room list.

View File

@ -295,6 +295,30 @@ def parse_strings_from_args(
return default return default
@overload
def parse_string_from_args(
args: Dict[bytes, List[bytes]],
name: str,
default: Optional[str] = None,
required: Literal[True] = True,
allowed_values: Optional[Iterable[str]] = None,
encoding: str = "ascii",
) -> str:
...
@overload
def parse_string_from_args(
args: Dict[bytes, List[bytes]],
name: str,
default: Optional[str] = None,
required: bool = False,
allowed_values: Optional[Iterable[str]] = None,
encoding: str = "ascii",
) -> Optional[str]:
...
def parse_string_from_args( def parse_string_from_args(
args: Dict[bytes, List[bytes]], args: Dict[bytes, List[bytes]],
name: str, name: str,