From 6e754dff750e30e5587e46cafde8fd931dac4661 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Wed, 22 Feb 2023 09:29:06 +0100 Subject: [PATCH 1/7] Add support for knocking to workers --- docker/configure_workers_and_start.py | 1 + docs/workers.md | 1 + synapse/rest/__init__.py | 2 +- synapse/rest/client/room.py | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docker/configure_workers_and_start.py b/docker/configure_workers_and_start.py index 58c62f2231f3..de8b0f506b70 100755 --- a/docker/configure_workers_and_start.py +++ b/docker/configure_workers_and_start.py @@ -204,6 +204,7 @@ "^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/send", "^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$", "^/_matrix/client/(api/v1|r0|v3|unstable)/join/", + "^/_matrix/client/(api/v1|r0|v3|unstable)/knock/", "^/_matrix/client/(api/v1|r0|v3|unstable)/profile/", "^/_matrix/client/(v1|unstable/org.matrix.msc2716)/rooms/.*/batch_send", ], diff --git a/docs/workers.md b/docs/workers.md index 2eb970ffa6a0..dcbfecb51f67 100644 --- a/docs/workers.md +++ b/docs/workers.md @@ -251,6 +251,7 @@ information. ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/state/ ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$ ^/_matrix/client/(api/v1|r0|v3|unstable)/join/ + ^/_matrix/client/(api/v1|r0|v3|unstable)/knock/ ^/_matrix/client/(api/v1|r0|v3|unstable)/profile/ # Account data requests diff --git a/synapse/rest/__init__.py b/synapse/rest/__init__.py index 14c4e6ebbbee..1ce6fc8ac7ac 100644 --- a/synapse/rest/__init__.py +++ b/synapse/rest/__init__.py @@ -140,7 +140,7 @@ def register_servlets(client_resource: HttpServer, hs: "HomeServer") -> None: relations.register_servlets(hs, client_resource) if is_main_process: password_policy.register_servlets(hs, client_resource) - knock.register_servlets(hs, client_resource) + knock.register_servlets(hs, client_resource) # moving to /_synapse/admin if is_main_process: diff --git a/synapse/rest/client/room.py b/synapse/rest/client/room.py index d0db85cca77f..3a9dc5f8da46 100644 --- a/synapse/rest/client/room.py +++ b/synapse/rest/client/room.py @@ -926,7 +926,7 @@ def __init__(self, hs: "HomeServer"): self.auth = hs.get_auth() def register(self, http_server: HttpServer) -> None: - # /rooms/$roomid/[invite|join|leave] + # /rooms/$roomid/[join|invite|leave|ban|unban|kick] PATTERNS = ( "/rooms/(?P[^/]*)/" "(?Pjoin|invite|leave|ban|unban|kick)" From 501f0c2f574a78bc527befd6b846bc6398cf8513 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Wed, 22 Feb 2023 11:57:48 +0100 Subject: [PATCH 2/7] newsfile --- changelog.d/15133.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/15133.feature diff --git a/changelog.d/15133.feature b/changelog.d/15133.feature new file mode 100644 index 000000000000..e0af0d455440 --- /dev/null +++ b/changelog.d/15133.feature @@ -0,0 +1 @@ +Add support for knocking to workers. \ No newline at end of file From dcf9f4ecce2e15b0da6ad7a94cf07f0fe15743e6 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Fri, 24 Feb 2023 12:56:14 +0100 Subject: [PATCH 3/7] user -> user_id for `_remote_knock_client` --- synapse/handlers/room_member_worker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/room_member_worker.py b/synapse/handlers/room_member_worker.py index ba261702d4bc..5401de4a55eb 100644 --- a/synapse/handlers/room_member_worker.py +++ b/synapse/handlers/room_member_worker.py @@ -125,7 +125,7 @@ async def remote_knock( ret = await self._remote_knock_client( remote_room_hosts=remote_room_hosts, room_id=room_id, - user=user, + user_id=user.to_string, content=content, ) return ret["event_id"], ret["stream_id"] From e699453af822c3714df7f9eacbf5f10379d82b88 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Fri, 24 Feb 2023 13:45:59 +0100 Subject: [PATCH 4/7] add `requester` --- synapse/handlers/room_member.py | 4 +++- synapse/handlers/room_member_worker.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py index a965c7ec7698..3a1684463d32 100644 --- a/synapse/handlers/room_member.py +++ b/synapse/handlers/room_member.py @@ -207,6 +207,7 @@ async def _remote_join( @abc.abstractmethod async def remote_knock( self, + requester: Requester, remote_room_hosts: List[str], room_id: str, user: UserID, @@ -1070,7 +1071,7 @@ async def update_membership_locked( ) return await self.remote_knock( - remote_room_hosts, room_id, target, content + requester, remote_room_hosts, room_id, target, content ) return await self._local_membership_update( @@ -1977,6 +1978,7 @@ async def _generate_local_out_of_band_leave( async def remote_knock( self, + requester: Requester, remote_room_hosts: List[str], room_id: str, user: UserID, diff --git a/synapse/handlers/room_member_worker.py b/synapse/handlers/room_member_worker.py index 5401de4a55eb..37b392856c30 100644 --- a/synapse/handlers/room_member_worker.py +++ b/synapse/handlers/room_member_worker.py @@ -113,6 +113,7 @@ async def remote_rescind_knock( async def remote_knock( self, + requester: Requester, remote_room_hosts: List[str], room_id: str, user: UserID, @@ -123,6 +124,7 @@ async def remote_knock( Implements RoomMemberHandler.remote_knock """ ret = await self._remote_knock_client( + requester=requester, remote_room_hosts=remote_room_hosts, room_id=room_id, user_id=user.to_string, From ec192a6a883f80f8b4e99ef45072aa7d402f07e2 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Mon, 27 Feb 2023 10:08:50 +0100 Subject: [PATCH 5/7] add missing brackets --- synapse/handlers/room_member_worker.py | 2 +- synapse/rest/client/knock.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/synapse/handlers/room_member_worker.py b/synapse/handlers/room_member_worker.py index 37b392856c30..76e36b8a6d53 100644 --- a/synapse/handlers/room_member_worker.py +++ b/synapse/handlers/room_member_worker.py @@ -127,7 +127,7 @@ async def remote_knock( requester=requester, remote_room_hosts=remote_room_hosts, room_id=room_id, - user_id=user.to_string, + user_id=user.to_string(), content=content, ) return ret["event_id"], ret["stream_id"] diff --git a/synapse/rest/client/knock.py b/synapse/rest/client/knock.py index ad025c8a4529..c3bdc1cfcd15 100644 --- a/synapse/rest/client/knock.py +++ b/synapse/rest/client/knock.py @@ -67,7 +67,6 @@ async def on_POST( # twisted.web.server.Request.args is incorrectly defined as Optional[Any] args: Dict[bytes, List[bytes]] = request.args # type: ignore - remote_room_hosts = parse_strings_from_args( args, "server_name", required=False ) From 3677ae67b0570762da8c1ce6ab31ea44fa972eb8 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Mon, 27 Feb 2023 13:56:16 +0100 Subject: [PATCH 6/7] load rest servlets --- synapse/replication/http/membership.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/synapse/replication/http/membership.py b/synapse/replication/http/membership.py index 9fa1060d48f6..0acbc1e01327 100644 --- a/synapse/replication/http/membership.py +++ b/synapse/replication/http/membership.py @@ -363,3 +363,5 @@ def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: ReplicationRemoteJoinRestServlet(hs).register(http_server) ReplicationRemoteRejectInviteRestServlet(hs).register(http_server) ReplicationUserJoinedLeftRoomRestServlet(hs).register(http_server) + ReplicationRemoteKnockRestServlet(hs).register(http_server) + ReplicationRemoteRescindKnockRestServlet(hs).register(http_server) From 40a2ddbf27def5afd15e7ad1343aeb301ba73007 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Mon, 27 Feb 2023 14:36:17 +0100 Subject: [PATCH 7/7] codestyle --- synapse/replication/http/membership.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/synapse/replication/http/membership.py b/synapse/replication/http/membership.py index 0acbc1e01327..67b01db67e7f 100644 --- a/synapse/replication/http/membership.py +++ b/synapse/replication/http/membership.py @@ -142,17 +142,12 @@ async def _serialize_payload( # type: ignore[override] } async def _handle_request( # type: ignore[override] - self, - request: SynapseRequest, - content: JsonDict, - room_id: str, - user_id: str, + self, request: SynapseRequest, content: JsonDict, room_id: str, user_id: str ) -> Tuple[int, JsonDict]: remote_room_hosts = content["remote_room_hosts"] event_content = content["content"] requester = Requester.deserialize(self.store, content["requester"]) - request.requester = requester logger.debug("remote_knock: %s on room: %s", user_id, room_id) @@ -277,16 +272,12 @@ async def _serialize_payload( # type: ignore[override] } async def _handle_request( # type: ignore[override] - self, - request: SynapseRequest, - content: JsonDict, - knock_event_id: str, + self, request: SynapseRequest, content: JsonDict, knock_event_id: str ) -> Tuple[int, JsonDict]: txn_id = content["txn_id"] event_content = content["content"] requester = Requester.deserialize(self.store, content["requester"]) - request.requester = requester # hopefully we're now on the master, so this won't recurse!