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

Commit

Permalink
make FederationClient.get_pdu async
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Feb 3, 2020
1 parent 0536d0c commit 0cb0c7b
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import copy
import itertools
import logging
from typing import Dict, Iterable, List, Tuple
from typing import Dict, Iterable, List, Optional, Tuple

from prometheus_client import Counter

Expand Down Expand Up @@ -211,30 +211,32 @@ async def backfill(

return pdus

@defer.inlineCallbacks
@log_function
def get_pdu(
self, destinations, event_id, room_version, outlier=False, timeout=None
):
async def get_pdu(
self,
destinations: Iterable[str],
event_id: str,
room_version: str,
outlier: bool = False,
timeout: Optional[int] = None,
) -> Optional[EventBase]:
"""Requests the PDU with given origin and ID from the remote home
servers.
Will attempt to get the PDU from each destination in the list until
one succeeds.
Args:
destinations (list): Which homeservers to query
event_id (str): event to fetch
room_version (str): version of the room
outlier (bool): Indicates whether the PDU is an `outlier`, i.e. if
destinations: Which homeservers to query
event_id: event to fetch
room_version: version of the room
outlier: Indicates whether the PDU is an `outlier`, i.e. if
it's from an arbitary point in the context as opposed to part
of the current block of PDUs. Defaults to `False`
timeout (int): How long to try (in ms) each destination for before
timeout: How long to try (in ms) each destination for before
moving to the next destination. None indicates no timeout.
Returns:
Deferred: Results in the requested PDU, or None if we were unable to find
it.
The requested PDU, or None if we were unable to find it.
"""

# TODO: Rate limit the number of times we try and get the same event.
Expand All @@ -255,7 +257,7 @@ def get_pdu(
continue

try:
transaction_data = yield self.transport_layer.get_event(
transaction_data = await self.transport_layer.get_event(
destination, event_id, timeout=timeout
)

Expand All @@ -275,7 +277,7 @@ def get_pdu(
pdu = pdu_list[0]

# Check signatures are correct.
signed_pdu = yield self._check_sigs_and_hash(room_version, pdu)
signed_pdu = await self._check_sigs_and_hash(room_version, pdu)

break

Expand Down

0 comments on commit 0cb0c7b

Please sign in to comment.