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

Commit f1d5c2f

Browse files
Split out federated PDU retrieval into a non-cached version (#11242)
Context: https://github.com/matrix-org/synapse/pull/11114/files#r741643968
1 parent 0ef69dd commit f1d5c2f

File tree

2 files changed

+59
-22
lines changed

2 files changed

+59
-22
lines changed

changelog.d/11242.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Split out federated PDU retrieval function into a non-cached version.

synapse/federation/federation_client.py

+58-22
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,58 @@ async def backfill(
277277

278278
return pdus
279279

280+
async def get_pdu_from_destination_raw(
281+
self,
282+
destination: str,
283+
event_id: str,
284+
room_version: RoomVersion,
285+
outlier: bool = False,
286+
timeout: Optional[int] = None,
287+
) -> Optional[EventBase]:
288+
"""Requests the PDU with given origin and ID from the remote home
289+
server. Does not have any caching or rate limiting!
290+
291+
Args:
292+
destination: Which homeserver to query
293+
event_id: event to fetch
294+
room_version: version of the room
295+
outlier: Indicates whether the PDU is an `outlier`, i.e. if
296+
it's from an arbitrary point in the context as opposed to part
297+
of the current block of PDUs. Defaults to `False`
298+
timeout: How long to try (in ms) each destination for before
299+
moving to the next destination. None indicates no timeout.
300+
301+
Returns:
302+
The requested PDU, or None if we were unable to find it.
303+
304+
Raises:
305+
SynapseError, NotRetryingDestination, FederationDeniedError
306+
"""
307+
transaction_data = await self.transport_layer.get_event(
308+
destination, event_id, timeout=timeout
309+
)
310+
311+
logger.debug(
312+
"retrieved event id %s from %s: %r",
313+
event_id,
314+
destination,
315+
transaction_data,
316+
)
317+
318+
pdu_list: List[EventBase] = [
319+
event_from_pdu_json(p, room_version, outlier=outlier)
320+
for p in transaction_data["pdus"]
321+
]
322+
323+
if pdu_list and pdu_list[0]:
324+
pdu = pdu_list[0]
325+
326+
# Check signatures are correct.
327+
signed_pdu = await self._check_sigs_and_hash(room_version, pdu)
328+
return signed_pdu
329+
330+
return None
331+
280332
async def get_pdu(
281333
self,
282334
destinations: Iterable[str],
@@ -321,30 +373,14 @@ async def get_pdu(
321373
continue
322374

323375
try:
324-
transaction_data = await self.transport_layer.get_event(
325-
destination, event_id, timeout=timeout
326-
)
327-
328-
logger.debug(
329-
"retrieved event id %s from %s: %r",
330-
event_id,
331-
destination,
332-
transaction_data,
376+
signed_pdu = await self.get_pdu_from_destination_raw(
377+
destination=destination,
378+
event_id=event_id,
379+
room_version=room_version,
380+
outlier=outlier,
381+
timeout=timeout,
333382
)
334383

335-
pdu_list: List[EventBase] = [
336-
event_from_pdu_json(p, room_version, outlier=outlier)
337-
for p in transaction_data["pdus"]
338-
]
339-
340-
if pdu_list and pdu_list[0]:
341-
pdu = pdu_list[0]
342-
343-
# Check signatures are correct.
344-
signed_pdu = await self._check_sigs_and_hash(room_version, pdu)
345-
346-
break
347-
348384
pdu_attempts[destination] = now
349385

350386
except SynapseError as e:

0 commit comments

Comments
 (0)