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

Commit e93caaf

Browse files
committed
Remove fallback for missing /federation/v1/state_ids API
This API was added way back in 0.17.0; the code here is annoying to maintain and entirely redundant.
1 parent 63d6ad1 commit e93caaf

File tree

3 files changed

+18
-96
lines changed

3 files changed

+18
-96
lines changed

changelog.d/6488.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove fallback for federation with old servers which lack the /federation/v1/state_ids API.

synapse/federation/federation_client.py

Lines changed: 17 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -324,87 +324,32 @@ def get_state_for_room(self, destination, room_id, event_id):
324324
A list of events in the state, and a list of events in the auth chain
325325
for the given event.
326326
"""
327-
try:
328-
# First we try and ask for just the IDs, as thats far quicker if
329-
# we have most of the state and auth_chain already.
330-
# However, this may 404 if the other side has an old synapse.
331-
result = yield self.transport_layer.get_room_state_ids(
332-
destination, room_id, event_id=event_id
333-
)
334-
335-
state_event_ids = result["pdu_ids"]
336-
auth_event_ids = result.get("auth_chain_ids", [])
337-
338-
fetched_events, failed_to_fetch = yield self.get_events_from_store_or_dest(
339-
destination, room_id, set(state_event_ids + auth_event_ids)
340-
)
341-
342-
if failed_to_fetch:
343-
logger.warning(
344-
"Failed to fetch missing state/auth events for %s: %s",
345-
room_id,
346-
failed_to_fetch,
347-
)
348-
349-
event_map = {ev.event_id: ev for ev in fetched_events}
350-
351-
pdus = [event_map[e_id] for e_id in state_event_ids if e_id in event_map]
352-
auth_chain = [
353-
event_map[e_id] for e_id in auth_event_ids if e_id in event_map
354-
]
355-
356-
auth_chain.sort(key=lambda e: e.depth)
357-
358-
return pdus, auth_chain
359-
except HttpResponseException as e:
360-
if e.code == 400 or e.code == 404:
361-
logger.info("Failed to use get_room_state_ids API, falling back")
362-
else:
363-
raise e
364-
365-
result = yield self.transport_layer.get_room_state(
327+
result = yield self.transport_layer.get_room_state_ids(
366328
destination, room_id, event_id=event_id
367329
)
368330

369-
room_version = yield self.store.get_room_version(room_id)
370-
format_ver = room_version_to_event_format(room_version)
371-
372-
pdus = [
373-
event_from_pdu_json(p, format_ver, outlier=True) for p in result["pdus"]
374-
]
331+
state_event_ids = result["pdu_ids"]
332+
auth_event_ids = result.get("auth_chain_ids", [])
375333

376-
auth_chain = [
377-
event_from_pdu_json(p, format_ver, outlier=True)
378-
for p in result.get("auth_chain", [])
379-
]
380-
381-
seen_events = yield self.store.get_events(
382-
[ev.event_id for ev in itertools.chain(pdus, auth_chain)]
334+
fetched_events, failed_to_fetch = yield self.get_events_from_store_or_dest(
335+
destination, room_id, set(state_event_ids + auth_event_ids)
383336
)
384337

385-
signed_pdus = yield self._check_sigs_and_hash_and_fetch(
386-
destination,
387-
[p for p in pdus if p.event_id not in seen_events],
388-
outlier=True,
389-
room_version=room_version,
390-
)
391-
signed_pdus.extend(
392-
seen_events[p.event_id] for p in pdus if p.event_id in seen_events
393-
)
338+
if failed_to_fetch:
339+
logger.warning(
340+
"Failed to fetch missing state/auth events for %s: %s",
341+
room_id,
342+
failed_to_fetch,
343+
)
394344

395-
signed_auth = yield self._check_sigs_and_hash_and_fetch(
396-
destination,
397-
[p for p in auth_chain if p.event_id not in seen_events],
398-
outlier=True,
399-
room_version=room_version,
400-
)
401-
signed_auth.extend(
402-
seen_events[p.event_id] for p in auth_chain if p.event_id in seen_events
403-
)
345+
event_map = {ev.event_id: ev for ev in fetched_events}
404346

405-
signed_auth.sort(key=lambda e: e.depth)
347+
pdus = [event_map[e_id] for e_id in state_event_ids if e_id in event_map]
348+
auth_chain = [event_map[e_id] for e_id in auth_event_ids if e_id in event_map]
349+
350+
auth_chain.sort(key=lambda e: e.depth)
406351

407-
return signed_pdus, signed_auth
352+
return pdus, auth_chain
408353

409354
@defer.inlineCallbacks
410355
def get_events_from_store_or_dest(self, destination, room_id, event_ids):

synapse/federation/transport/client.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,6 @@ def __init__(self, hs):
3838
self.server_name = hs.hostname
3939
self.client = hs.get_http_client()
4040

41-
@log_function
42-
def get_room_state(self, destination, room_id, event_id):
43-
""" Requests all state for a given room from the given server at the
44-
given event.
45-
46-
Args:
47-
destination (str): The host name of the remote homeserver we want
48-
to get the state from.
49-
context (str): The name of the context we want the state of
50-
event_id (str): The event we want the context at.
51-
52-
Returns:
53-
Deferred: Results in a dict received from the remote homeserver.
54-
"""
55-
logger.debug("get_room_state dest=%s, room=%s", destination, room_id)
56-
57-
path = _create_v1_path("/state/%s", room_id)
58-
return self.client.get_json(
59-
destination,
60-
path=path,
61-
args={"event_id": event_id},
62-
try_trailing_slash_on_400=True,
63-
)
64-
6541
@log_function
6642
def get_room_state_ids(self, destination, room_id, event_id):
6743
""" Requests all state for a given room from the given server at the

0 commit comments

Comments
 (0)