diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2021-11-29 14:32:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-29 14:32:20 -0500 |
commit | a4521ce0a8d252e77ca8bd261ecf40ba67511a31 (patch) | |
tree | 44c545e9105a04929c01c8ad9cf8ce4a3c198d11 /synapse/federation/federation_client.py | |
parent | Make background updates controllable via a plugin (#11306) (diff) | |
download | synapse-a4521ce0a8d252e77ca8bd261ecf40ba67511a31.tar.xz |
Support the stable /hierarchy endpoint from MSC2946 (#11329)
This also makes additional updates where the implementation had drifted from the approved MSC. Unstable endpoints will be removed at a later data.
Diffstat (limited to 'synapse/federation/federation_client.py')
-rw-r--r-- | synapse/federation/federation_client.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py index 3b85b135e0..bc3f96c1fc 100644 --- a/synapse/federation/federation_client.py +++ b/synapse/federation/federation_client.py @@ -1395,11 +1395,28 @@ class FederationClient(FederationBase): async def send_request( destination: str, ) -> Tuple[JsonDict, Sequence[JsonDict], Sequence[str]]: - res = await self.transport_layer.get_room_hierarchy( - destination=destination, - room_id=room_id, - suggested_only=suggested_only, - ) + try: + res = await self.transport_layer.get_room_hierarchy( + destination=destination, + room_id=room_id, + suggested_only=suggested_only, + ) + except HttpResponseException as e: + # If an error is received that is due to an unrecognised endpoint, + # fallback to the unstable endpoint. Otherwise consider it a + # legitmate error and raise. + if not self._is_unknown_endpoint(e): + raise + + logger.debug( + "Couldn't fetch room hierarchy with the v1 API, falling back to the unstable API" + ) + + res = await self.transport_layer.get_room_hierarchy_unstable( + destination=destination, + room_id=room_id, + suggested_only=suggested_only, + ) room = res.get("room") if not isinstance(room, dict): @@ -1449,6 +1466,10 @@ class FederationClient(FederationBase): if e.code != 502: raise + logger.debug( + "Couldn't fetch room hierarchy, falling back to the spaces API" + ) + # Fallback to the old federation API and translate the results if # no servers implement the new API. # |