diff options
author | Patrick Cloke <patrickc@matrix.org> | 2023-07-26 15:48:42 -0400 |
---|---|---|
committer | Patrick Cloke <patrickc@matrix.org> | 2023-07-26 15:48:42 -0400 |
commit | 7c70e00393da4ba69053d11a768e9cf56d46eb45 (patch) | |
tree | 5a7ab4a7350b1ad09778bb15be9cf3e8a7ae9e2e | |
parent | Actually fetch if a server is linearized. (diff) | |
download | synapse-github/clokep/lm.tar.xz |
Only return LPDUs to linearized matrix servers. github/clokep/lm clokep/lm
-rw-r--r-- | synapse/events/__init__.py | 5 | ||||
-rw-r--r-- | synapse/federation/federation_server.py | 42 |
2 files changed, 42 insertions, 5 deletions
diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py index eaf6fcf2f9..da4b326f95 100644 --- a/synapse/events/__init__.py +++ b/synapse/events/__init__.py @@ -406,6 +406,9 @@ class EventBase(metaclass=abc.ABCMeta): return template_json + def get_templated_linearized_pdu_json(self) -> JsonDict: + raise NotImplementedError() + def __getitem__(self, field: str) -> Optional[Any]: return self._dict[field] @@ -644,7 +647,7 @@ class FrozenLinearizedEvent(FrozenEventV3): pdu.pop("prev_events") return pdu - def get_templated_pdu_json(self) -> JsonDict: + def get_templated_linearized_pdu_json(self) -> JsonDict: """ Return a JSON object suitable for a templated event, as used in the make_{join,leave,knock} workflow. diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py index 24f726a4dd..5713fb44c2 100644 --- a/synapse/federation/federation_server.py +++ b/synapse/federation/federation_server.py @@ -696,7 +696,18 @@ class FederationServer(FederationBase): pdu = await self.handler.on_make_join_request( origin, room_id, KNOWN_ROOM_VERSIONS[room_version_id], user_id ) - return {"event": pdu.get_templated_pdu_json(), "room_version": room_version_id} + + # For a linearized matrix server return a templated LPDU, otherwise a templated PDU. + # TODO(LM) Is it an error for a LM server to not be on a LM room version? + if ( + pdu.room_version.linearized_matrix + and await self.keyring.is_server_linearized(origin) + ): + event_json = pdu.get_templated_linearized_pdu_json() + else: + event_json = pdu.get_templated_pdu_json() + + return {"event": event_json, "room_version": room_version_id} async def on_invite_request( self, origin: str, content: JsonDict, room_version_id: str @@ -805,7 +816,17 @@ class FederationServer(FederationBase): room_version = await self.store.get_room_version_id(room_id) - return {"event": pdu.get_templated_pdu_json(), "room_version": room_version} + # For a linearized matrix server return a templated LPDU, otherwise a templated PDU. + # TODO(LM) Is it an error for a LM server to not be on a LM room version? + if ( + pdu.room_version.linearized_matrix + and await self.keyring.is_server_linearized(origin) + ): + event_json = pdu.get_templated_linearized_pdu_json() + else: + event_json = pdu.get_templated_pdu_json() + + return {"event": event_json, "room_version": room_version} async def on_send_leave_request( self, origin: str, content: JsonDict, expected_room_id: Optional[str] = None @@ -865,8 +886,19 @@ class FederationServer(FederationBase): ) pdu = await self.handler.on_make_knock_request(origin, room_id, user_id) + + # For a linearized matrix server return a templated LPDU, otherwise a templated PDU. + # TODO(LM) Is it an error for a LM server to not be on a LM room version? + if ( + pdu.room_version.linearized_matrix + and await self.keyring.is_server_linearized(origin) + ): + event_json = pdu.get_templated_linearized_pdu_json() + else: + event_json = pdu.get_templated_pdu_json() + return { - "event": pdu.get_templated_pdu_json(), + "event": event_json, "room_version": room_version.identifier, } @@ -974,7 +1006,9 @@ class FederationServer(FederationBase): # Linearized Matrix requires building the event (i.e. adding auth/prev # events). The input content is an LPDU. - if room_version.linearized_matrix: + if room_version.linearized_matrix and await self.keyring.is_server_linearized( + origin + ): event = await self._on_lpdu_event(content, room_version) else: event = event_from_pdu_json(content, room_version) |