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

Commit

Permalink
Add support for knocking to workers. (#15133)
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel authored Mar 2, 2023
1 parent c8665dd commit ecbe0dd
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 16 deletions.
1 change: 1 addition & 0 deletions changelog.d/15133.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for knocking to workers.
1 change: 1 addition & 0 deletions docker/configure_workers_and_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,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",
],
Expand Down
1 change: 1 addition & 0 deletions docs/workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,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
Expand Down
4 changes: 3 additions & 1 deletion synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1073,7 +1074,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(
Expand Down Expand Up @@ -1984,6 +1985,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,
Expand Down
4 changes: 3 additions & 1 deletion synapse/handlers/room_member_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -123,9 +124,10 @@ 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=user,
user_id=user.to_string(),
content=content,
)
return ret["event_id"], ret["stream_id"]
Expand Down
15 changes: 4 additions & 11 deletions synapse/replication/http/membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -363,3 +354,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)
2 changes: 1 addition & 1 deletion synapse/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,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:
Expand Down
1 change: 0 additions & 1 deletion synapse/rest/client/knock.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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
)
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<room_id>[^/]*)/"
"(?P<membership_action>join|invite|leave|ban|unban|kick)"
Expand Down

0 comments on commit ecbe0dd

Please sign in to comment.