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

Commit db23830

Browse files
committed
Support the stable endpoint for Server-Server requests.
1 parent b4ad0bf commit db23830

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

docs/workers.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ expressions:
210210
^/_matrix/federation/v1/get_groups_publicised$
211211
^/_matrix/key/v2/query
212212
^/_matrix/federation/unstable/org.matrix.msc2946/spaces/
213-
^/_matrix/federation/unstable/org.matrix.msc2946/hierarchy/
213+
^/_matrix/federation/(v1|unstable/org.matrix.msc2946)/hierarchy/
214214

215215
# Inbound federation transaction request
216216
^/_matrix/federation/v1/send/

synapse/federation/federation_client.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -1395,11 +1395,28 @@ async def get_room_hierarchy(
13951395
async def send_request(
13961396
destination: str,
13971397
) -> Tuple[JsonDict, Sequence[JsonDict], Sequence[str]]:
1398-
res = await self.transport_layer.get_room_hierarchy(
1399-
destination=destination,
1400-
room_id=room_id,
1401-
suggested_only=suggested_only,
1402-
)
1398+
try:
1399+
res = await self.transport_layer.get_room_hierarchy(
1400+
destination=destination,
1401+
room_id=room_id,
1402+
suggested_only=suggested_only,
1403+
)
1404+
except HttpResponseException as e:
1405+
# If an error is received that is due to an unrecognised endpoint,
1406+
# fallback to the unstable endpoint. Otherwise consider it a
1407+
# legitmate error and raise.
1408+
if not self._is_unknown_endpoint(e):
1409+
raise
1410+
1411+
logger.debug(
1412+
"Couldn't fetch room hierarchy with the v1 API, falling back to the unstable API"
1413+
)
1414+
1415+
res = await self.transport_layer.get_room_hierarchy_unstable(
1416+
destination=destination,
1417+
room_id=room_id,
1418+
suggested_only=suggested_only,
1419+
)
14031420

14041421
room = res.get("room")
14051422
if not isinstance(room, dict):
@@ -1449,6 +1466,10 @@ async def send_request(
14491466
if e.code != 502:
14501467
raise
14511468

1469+
logger.debug(
1470+
"Couldn't fetch room hierarchy, falling back to the spaces API"
1471+
)
1472+
14521473
# Fallback to the old federation API and translate the results if
14531474
# no servers implement the new API.
14541475
#

synapse/federation/transport/client.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -1192,10 +1192,24 @@ async def get_space_summary(
11921192
)
11931193

11941194
async def get_room_hierarchy(
1195-
self,
1196-
destination: str,
1197-
room_id: str,
1198-
suggested_only: bool,
1195+
self, destination: str, room_id: str, suggested_only: bool
1196+
) -> JsonDict:
1197+
"""
1198+
Args:
1199+
destination: The remote server
1200+
room_id: The room ID to ask about.
1201+
suggested_only: if True, only suggested rooms will be returned
1202+
"""
1203+
path = _create_v1_path("/hierarchy/%s", room_id)
1204+
1205+
return await self.client.get_json(
1206+
destination=destination,
1207+
path=path,
1208+
args={"suggested_only": "true" if suggested_only else "false"},
1209+
)
1210+
1211+
async def get_room_hierarchy_unstable(
1212+
self, destination: str, room_id: str, suggested_only: bool
11991213
) -> JsonDict:
12001214
"""
12011215
Args:

synapse/federation/transport/server/federation.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,6 @@ async def on_POST(
611611

612612

613613
class FederationRoomHierarchyServlet(BaseFederationServlet):
614-
PREFIX = FEDERATION_UNSTABLE_PREFIX + "/org.matrix.msc2946"
615614
PATH = "/hierarchy/(?P<room_id>[^/]*)"
616615

617616
def __init__(
@@ -637,6 +636,10 @@ async def on_GET(
637636
)
638637

639638

639+
class FederationRoomHierarchyUnstableServlet(FederationRoomHierarchyServlet):
640+
PREFIX = FEDERATION_UNSTABLE_PREFIX + "/org.matrix.msc2946"
641+
642+
640643
class RoomComplexityServlet(BaseFederationServlet):
641644
"""
642645
Indicates to other servers how complex (and therefore likely
@@ -701,6 +704,7 @@ async def on_GET(
701704
RoomComplexityServlet,
702705
FederationSpaceSummaryServlet,
703706
FederationRoomHierarchyServlet,
707+
FederationRoomHierarchyUnstableServlet,
704708
FederationV1SendKnockServlet,
705709
FederationMakeKnockServlet,
706710
)

0 commit comments

Comments
 (0)