From 0928eb94510a92dbe68e738e2db9953ea75d9f27 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 6 Oct 2022 16:53:25 +0100 Subject: [PATCH 1/3] Fix field name of returned stripped state events We now support both the new and old field name. --- synapse/federation/federation_client.py | 2 +- synapse/federation/federation_server.py | 10 +++++++++- synapse/handlers/federation.py | 21 +++++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py index 4dca711cd28d..b220ab43fc05 100644 --- a/synapse/federation/federation_client.py +++ b/synapse/federation/federation_client.py @@ -1294,7 +1294,7 @@ async def _do_send_leave(self, destination: str, pdu: EventBase) -> JsonDict: return resp[1] async def send_knock(self, destinations: List[str], pdu: EventBase) -> JsonDict: - """Attempts to send a knock event to given a list of servers. Iterates + """Attempts to send a knock event to a given list of servers. Iterates through the list until one attempt succeeds. Doing so will cause the remote server to add the event to the graph, diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py index 907940e19eb0..2543a4b30f83 100644 --- a/synapse/federation/federation_server.py +++ b/synapse/federation/federation_server.py @@ -824,7 +824,15 @@ async def on_send_knock_request( context, self._room_prejoin_state_types ) ) - return {"knock_state_events": stripped_room_state} + return { + "knock_room_state": stripped_room_state, + # Since v1.37, Synapse incorrectly used "knock_state_events" for this field. + # Thus, we also populate a 'knock_state_events' with the same content to + # support old instances. + # See https://github.com/matrix-org/synapse/issues/14088. + # TODO: Remove when enough of the ecosystem have upgraded to Synapse v1.xx+. + "knock_state_events": stripped_room_state, + } async def _on_send_membership_event( self, origin: str, content: JsonDict, membership_type: str, room_id: str diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 986ffed3d592..58a2adaaaf3d 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -781,15 +781,28 @@ async def do_knock( # Send the signed event back to the room, and potentially receive some # further information about the room in the form of partial state events - stripped_room_state = await self.federation_client.send_knock( - target_hosts, event - ) + knock_response = await self.federation_client.send_knock(target_hosts, event) # Store any stripped room state events in the "unsigned" key of the event. # This is a bit of a hack and is cribbing off of invites. Basically we # store the room state here and retrieve it again when this event appears # in the invitee's sync stream. It is stripped out for all other local users. - event.unsigned["knock_room_state"] = stripped_room_state["knock_state_events"] + stripped_room_state = ( + knock_response.get("knock_room_state") + # Since v1.37, Synapse incorrectly used "knock_state_events" for this field. + # Thus, we also check for a 'knock_state_events' to support old instances. + # See https://github.com/matrix-org/synapse/issues/14088. + # TODO: Remove when enough of the ecosystem have upgraded to Synapse v1.xx+. + or knock_response.get("knock_state_events") + ) + + if stripped_room_state is None: + raise KeyError( + "Missing 'knock_room_state' (or legacy 'knock_state_events') field in " + "send_knock response" + ) + + event.unsigned["knock_room_state"] = stripped_room_state context = EventContext.for_outlier(self._storage_controllers) stream_id = await self._federation_event_handler.persist_events_and_notify( From 3483e31afda080a794f5a06a2169a01eefadcc18 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 7 Oct 2022 11:41:01 +0100 Subject: [PATCH 2/3] changelog --- changelog.d/14102.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/14102.bugfix diff --git a/changelog.d/14102.bugfix b/changelog.d/14102.bugfix new file mode 100644 index 000000000000..d71e108f7c1d --- /dev/null +++ b/changelog.d/14102.bugfix @@ -0,0 +1 @@ +Fix a bug introduced in Synapse v1.37.0 in which an incorrect key name was used for sending and receiving room metadata when knocking on a room. \ No newline at end of file From df29a1295d8f812d262dc990431b33e59eeef1ce Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 12 Oct 2022 11:28:08 +0100 Subject: [PATCH 3/3] Replace TODOs with an issue (#14151) --- synapse/federation/federation_server.py | 1 - synapse/handlers/federation.py | 1 - 2 files changed, 2 deletions(-) diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py index 2543a4b30f83..28097664b4d6 100644 --- a/synapse/federation/federation_server.py +++ b/synapse/federation/federation_server.py @@ -830,7 +830,6 @@ async def on_send_knock_request( # Thus, we also populate a 'knock_state_events' with the same content to # support old instances. # See https://github.com/matrix-org/synapse/issues/14088. - # TODO: Remove when enough of the ecosystem have upgraded to Synapse v1.xx+. "knock_state_events": stripped_room_state, } diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 58a2adaaaf3d..44e70c6c3c30 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -792,7 +792,6 @@ async def do_knock( # Since v1.37, Synapse incorrectly used "knock_state_events" for this field. # Thus, we also check for a 'knock_state_events' to support old instances. # See https://github.com/matrix-org/synapse/issues/14088. - # TODO: Remove when enough of the ecosystem have upgraded to Synapse v1.xx+. or knock_response.get("knock_state_events") )