|
|
@ -18,8 +18,6 @@ import logging |
|
|
|
import urllib |
|
|
|
import urllib |
|
|
|
from typing import Any, Dict, Optional |
|
|
|
from typing import Any, Dict, Optional |
|
|
|
|
|
|
|
|
|
|
|
from twisted.internet import defer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from synapse.api.constants import Membership |
|
|
|
from synapse.api.constants import Membership |
|
|
|
from synapse.api.errors import Codes, HttpResponseException, SynapseError |
|
|
|
from synapse.api.errors import Codes, HttpResponseException, SynapseError |
|
|
|
from synapse.api.urls import ( |
|
|
|
from synapse.api.urls import ( |
|
|
@ -51,7 +49,7 @@ class TransportLayerClient(object): |
|
|
|
event_id (str): The event we want the context at. |
|
|
|
event_id (str): The event we want the context at. |
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
Returns: |
|
|
|
Deferred: Results in a dict received from the remote homeserver. |
|
|
|
Awaitable: Results in a dict received from the remote homeserver. |
|
|
|
""" |
|
|
|
""" |
|
|
|
logger.debug("get_room_state_ids dest=%s, room=%s", destination, room_id) |
|
|
|
logger.debug("get_room_state_ids dest=%s, room=%s", destination, room_id) |
|
|
|
|
|
|
|
|
|
|
@ -75,7 +73,7 @@ class TransportLayerClient(object): |
|
|
|
giving up. None indicates no timeout. |
|
|
|
giving up. None indicates no timeout. |
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
Returns: |
|
|
|
Deferred: Results in a dict received from the remote homeserver. |
|
|
|
Awaitable: Results in a dict received from the remote homeserver. |
|
|
|
""" |
|
|
|
""" |
|
|
|
logger.debug("get_pdu dest=%s, event_id=%s", destination, event_id) |
|
|
|
logger.debug("get_pdu dest=%s, event_id=%s", destination, event_id) |
|
|
|
|
|
|
|
|
|
|
@ -96,7 +94,7 @@ class TransportLayerClient(object): |
|
|
|
limit (int) |
|
|
|
limit (int) |
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
Returns: |
|
|
|
Deferred: Results in a dict received from the remote homeserver. |
|
|
|
Awaitable: Results in a dict received from the remote homeserver. |
|
|
|
""" |
|
|
|
""" |
|
|
|
logger.debug( |
|
|
|
logger.debug( |
|
|
|
"backfill dest=%s, room_id=%s, event_tuples=%r, limit=%s", |
|
|
|
"backfill dest=%s, room_id=%s, event_tuples=%r, limit=%s", |
|
|
@ -118,16 +116,15 @@ class TransportLayerClient(object): |
|
|
|
destination, path=path, args=args, try_trailing_slash_on_400=True |
|
|
|
destination, path=path, args=args, try_trailing_slash_on_400=True |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def send_transaction(self, transaction, json_data_callback=None): |
|
|
|
async def send_transaction(self, transaction, json_data_callback=None): |
|
|
|
""" Sends the given Transaction to its destination |
|
|
|
""" Sends the given Transaction to its destination |
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
Args: |
|
|
|
transaction (Transaction) |
|
|
|
transaction (Transaction) |
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
Returns: |
|
|
|
Deferred: Succeeds when we get a 2xx HTTP response. The result |
|
|
|
Succeeds when we get a 2xx HTTP response. The result |
|
|
|
will be the decoded JSON body. |
|
|
|
will be the decoded JSON body. |
|
|
|
|
|
|
|
|
|
|
|
Fails with ``HTTPRequestException`` if we get an HTTP response |
|
|
|
Fails with ``HTTPRequestException`` if we get an HTTP response |
|
|
@ -154,7 +151,7 @@ class TransportLayerClient(object): |
|
|
|
|
|
|
|
|
|
|
|
path = _create_v1_path("/send/%s", transaction.transaction_id) |
|
|
|
path = _create_v1_path("/send/%s", transaction.transaction_id) |
|
|
|
|
|
|
|
|
|
|
|
response = yield self.client.put_json( |
|
|
|
response = await self.client.put_json( |
|
|
|
transaction.destination, |
|
|
|
transaction.destination, |
|
|
|
path=path, |
|
|
|
path=path, |
|
|
|
data=json_data, |
|
|
|
data=json_data, |
|
|
@ -166,14 +163,13 @@ class TransportLayerClient(object): |
|
|
|
|
|
|
|
|
|
|
|
return response |
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def make_query( |
|
|
|
async def make_query( |
|
|
|
self, destination, query_type, args, retry_on_dns_fail, ignore_backoff=False |
|
|
|
self, destination, query_type, args, retry_on_dns_fail, ignore_backoff=False |
|
|
|
): |
|
|
|
): |
|
|
|
path = _create_v1_path("/query/%s", query_type) |
|
|
|
path = _create_v1_path("/query/%s", query_type) |
|
|
|
|
|
|
|
|
|
|
|
content = yield self.client.get_json( |
|
|
|
content = await self.client.get_json( |
|
|
|
destination=destination, |
|
|
|
destination=destination, |
|
|
|
path=path, |
|
|
|
path=path, |
|
|
|
args=args, |
|
|
|
args=args, |
|
|
@ -184,9 +180,10 @@ class TransportLayerClient(object): |
|
|
|
|
|
|
|
|
|
|
|
return content |
|
|
|
return content |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def make_membership_event(self, destination, room_id, user_id, membership, params): |
|
|
|
async def make_membership_event( |
|
|
|
|
|
|
|
self, destination, room_id, user_id, membership, params |
|
|
|
|
|
|
|
): |
|
|
|
"""Asks a remote server to build and sign us a membership event |
|
|
|
"""Asks a remote server to build and sign us a membership event |
|
|
|
|
|
|
|
|
|
|
|
Note that this does not append any events to any graphs. |
|
|
|
Note that this does not append any events to any graphs. |
|
|
@ -200,7 +197,7 @@ class TransportLayerClient(object): |
|
|
|
request. |
|
|
|
request. |
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
Returns: |
|
|
|
Deferred: Succeeds when we get a 2xx HTTP response. The result |
|
|
|
Succeeds when we get a 2xx HTTP response. The result |
|
|
|
will be the decoded JSON body (ie, the new event). |
|
|
|
will be the decoded JSON body (ie, the new event). |
|
|
|
|
|
|
|
|
|
|
|
Fails with ``HTTPRequestException`` if we get an HTTP response |
|
|
|
Fails with ``HTTPRequestException`` if we get an HTTP response |
|
|
@ -231,7 +228,7 @@ class TransportLayerClient(object): |
|
|
|
ignore_backoff = True |
|
|
|
ignore_backoff = True |
|
|
|
retry_on_dns_fail = True |
|
|
|
retry_on_dns_fail = True |
|
|
|
|
|
|
|
|
|
|
|
content = yield self.client.get_json( |
|
|
|
content = await self.client.get_json( |
|
|
|
destination=destination, |
|
|
|
destination=destination, |
|
|
|
path=path, |
|
|
|
path=path, |
|
|
|
args=params, |
|
|
|
args=params, |
|
|
@ -242,34 +239,31 @@ class TransportLayerClient(object): |
|
|
|
|
|
|
|
|
|
|
|
return content |
|
|
|
return content |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def send_join_v1(self, destination, room_id, event_id, content): |
|
|
|
async def send_join_v1(self, destination, room_id, event_id, content): |
|
|
|
path = _create_v1_path("/send_join/%s/%s", room_id, event_id) |
|
|
|
path = _create_v1_path("/send_join/%s/%s", room_id, event_id) |
|
|
|
|
|
|
|
|
|
|
|
response = yield self.client.put_json( |
|
|
|
response = await self.client.put_json( |
|
|
|
destination=destination, path=path, data=content |
|
|
|
destination=destination, path=path, data=content |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return response |
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def send_join_v2(self, destination, room_id, event_id, content): |
|
|
|
async def send_join_v2(self, destination, room_id, event_id, content): |
|
|
|
path = _create_v2_path("/send_join/%s/%s", room_id, event_id) |
|
|
|
path = _create_v2_path("/send_join/%s/%s", room_id, event_id) |
|
|
|
|
|
|
|
|
|
|
|
response = yield self.client.put_json( |
|
|
|
response = await self.client.put_json( |
|
|
|
destination=destination, path=path, data=content |
|
|
|
destination=destination, path=path, data=content |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return response |
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def send_leave_v1(self, destination, room_id, event_id, content): |
|
|
|
async def send_leave_v1(self, destination, room_id, event_id, content): |
|
|
|
path = _create_v1_path("/send_leave/%s/%s", room_id, event_id) |
|
|
|
path = _create_v1_path("/send_leave/%s/%s", room_id, event_id) |
|
|
|
|
|
|
|
|
|
|
|
response = yield self.client.put_json( |
|
|
|
response = await self.client.put_json( |
|
|
|
destination=destination, |
|
|
|
destination=destination, |
|
|
|
path=path, |
|
|
|
path=path, |
|
|
|
data=content, |
|
|
|
data=content, |
|
|
@ -282,12 +276,11 @@ class TransportLayerClient(object): |
|
|
|
|
|
|
|
|
|
|
|
return response |
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def send_leave_v2(self, destination, room_id, event_id, content): |
|
|
|
async def send_leave_v2(self, destination, room_id, event_id, content): |
|
|
|
path = _create_v2_path("/send_leave/%s/%s", room_id, event_id) |
|
|
|
path = _create_v2_path("/send_leave/%s/%s", room_id, event_id) |
|
|
|
|
|
|
|
|
|
|
|
response = yield self.client.put_json( |
|
|
|
response = await self.client.put_json( |
|
|
|
destination=destination, |
|
|
|
destination=destination, |
|
|
|
path=path, |
|
|
|
path=path, |
|
|
|
data=content, |
|
|
|
data=content, |
|
|
@ -300,31 +293,28 @@ class TransportLayerClient(object): |
|
|
|
|
|
|
|
|
|
|
|
return response |
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def send_invite_v1(self, destination, room_id, event_id, content): |
|
|
|
async def send_invite_v1(self, destination, room_id, event_id, content): |
|
|
|
path = _create_v1_path("/invite/%s/%s", room_id, event_id) |
|
|
|
path = _create_v1_path("/invite/%s/%s", room_id, event_id) |
|
|
|
|
|
|
|
|
|
|
|
response = yield self.client.put_json( |
|
|
|
response = await self.client.put_json( |
|
|
|
destination=destination, path=path, data=content, ignore_backoff=True |
|
|
|
destination=destination, path=path, data=content, ignore_backoff=True |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return response |
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def send_invite_v2(self, destination, room_id, event_id, content): |
|
|
|
async def send_invite_v2(self, destination, room_id, event_id, content): |
|
|
|
path = _create_v2_path("/invite/%s/%s", room_id, event_id) |
|
|
|
path = _create_v2_path("/invite/%s/%s", room_id, event_id) |
|
|
|
|
|
|
|
|
|
|
|
response = yield self.client.put_json( |
|
|
|
response = await self.client.put_json( |
|
|
|
destination=destination, path=path, data=content, ignore_backoff=True |
|
|
|
destination=destination, path=path, data=content, ignore_backoff=True |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return response |
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def get_public_rooms( |
|
|
|
async def get_public_rooms( |
|
|
|
self, |
|
|
|
self, |
|
|
|
remote_server: str, |
|
|
|
remote_server: str, |
|
|
|
limit: Optional[int] = None, |
|
|
|
limit: Optional[int] = None, |
|
|
@ -355,7 +345,7 @@ class TransportLayerClient(object): |
|
|
|
data["filter"] = search_filter |
|
|
|
data["filter"] = search_filter |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
response = yield self.client.post_json( |
|
|
|
response = await self.client.post_json( |
|
|
|
destination=remote_server, path=path, data=data, ignore_backoff=True |
|
|
|
destination=remote_server, path=path, data=data, ignore_backoff=True |
|
|
|
) |
|
|
|
) |
|
|
|
except HttpResponseException as e: |
|
|
|
except HttpResponseException as e: |
|
|
@ -381,7 +371,7 @@ class TransportLayerClient(object): |
|
|
|
args["since"] = [since_token] |
|
|
|
args["since"] = [since_token] |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
response = yield self.client.get_json( |
|
|
|
response = await self.client.get_json( |
|
|
|
destination=remote_server, path=path, args=args, ignore_backoff=True |
|
|
|
destination=remote_server, path=path, args=args, ignore_backoff=True |
|
|
|
) |
|
|
|
) |
|
|
|
except HttpResponseException as e: |
|
|
|
except HttpResponseException as e: |
|
|
@ -396,29 +386,26 @@ class TransportLayerClient(object): |
|
|
|
|
|
|
|
|
|
|
|
return response |
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def exchange_third_party_invite(self, destination, room_id, event_dict): |
|
|
|
async def exchange_third_party_invite(self, destination, room_id, event_dict): |
|
|
|
path = _create_v1_path("/exchange_third_party_invite/%s", room_id) |
|
|
|
path = _create_v1_path("/exchange_third_party_invite/%s", room_id) |
|
|
|
|
|
|
|
|
|
|
|
response = yield self.client.put_json( |
|
|
|
response = await self.client.put_json( |
|
|
|
destination=destination, path=path, data=event_dict |
|
|
|
destination=destination, path=path, data=event_dict |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return response |
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def get_event_auth(self, destination, room_id, event_id): |
|
|
|
async def get_event_auth(self, destination, room_id, event_id): |
|
|
|
path = _create_v1_path("/event_auth/%s/%s", room_id, event_id) |
|
|
|
path = _create_v1_path("/event_auth/%s/%s", room_id, event_id) |
|
|
|
|
|
|
|
|
|
|
|
content = yield self.client.get_json(destination=destination, path=path) |
|
|
|
content = await self.client.get_json(destination=destination, path=path) |
|
|
|
|
|
|
|
|
|
|
|
return content |
|
|
|
return content |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def query_client_keys(self, destination, query_content, timeout): |
|
|
|
async def query_client_keys(self, destination, query_content, timeout): |
|
|
|
"""Query the device keys for a list of user ids hosted on a remote |
|
|
|
"""Query the device keys for a list of user ids hosted on a remote |
|
|
|
server. |
|
|
|
server. |
|
|
|
|
|
|
|
|
|
|
@ -453,14 +440,13 @@ class TransportLayerClient(object): |
|
|
|
""" |
|
|
|
""" |
|
|
|
path = _create_v1_path("/user/keys/query") |
|
|
|
path = _create_v1_path("/user/keys/query") |
|
|
|
|
|
|
|
|
|
|
|
content = yield self.client.post_json( |
|
|
|
content = await self.client.post_json( |
|
|
|
destination=destination, path=path, data=query_content, timeout=timeout |
|
|
|
destination=destination, path=path, data=query_content, timeout=timeout |
|
|
|
) |
|
|
|
) |
|
|
|
return content |
|
|
|
return content |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def query_user_devices(self, destination, user_id, timeout): |
|
|
|
async def query_user_devices(self, destination, user_id, timeout): |
|
|
|
"""Query the devices for a user id hosted on a remote server. |
|
|
|
"""Query the devices for a user id hosted on a remote server. |
|
|
|
|
|
|
|
|
|
|
|
Response: |
|
|
|
Response: |
|
|
@ -493,14 +479,13 @@ class TransportLayerClient(object): |
|
|
|
""" |
|
|
|
""" |
|
|
|
path = _create_v1_path("/user/devices/%s", user_id) |
|
|
|
path = _create_v1_path("/user/devices/%s", user_id) |
|
|
|
|
|
|
|
|
|
|
|
content = yield self.client.get_json( |
|
|
|
content = await self.client.get_json( |
|
|
|
destination=destination, path=path, timeout=timeout |
|
|
|
destination=destination, path=path, timeout=timeout |
|
|
|
) |
|
|
|
) |
|
|
|
return content |
|
|
|
return content |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def claim_client_keys(self, destination, query_content, timeout): |
|
|
|
async def claim_client_keys(self, destination, query_content, timeout): |
|
|
|
"""Claim one-time keys for a list of devices hosted on a remote server. |
|
|
|
"""Claim one-time keys for a list of devices hosted on a remote server. |
|
|
|
|
|
|
|
|
|
|
|
Request: |
|
|
|
Request: |
|
|
@ -532,14 +517,13 @@ class TransportLayerClient(object): |
|
|
|
|
|
|
|
|
|
|
|
path = _create_v1_path("/user/keys/claim") |
|
|
|
path = _create_v1_path("/user/keys/claim") |
|
|
|
|
|
|
|
|
|
|
|
content = yield self.client.post_json( |
|
|
|
content = await self.client.post_json( |
|
|
|
destination=destination, path=path, data=query_content, timeout=timeout |
|
|
|
destination=destination, path=path, data=query_content, timeout=timeout |
|
|
|
) |
|
|
|
) |
|
|
|
return content |
|
|
|
return content |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
|
|
|
|
@log_function |
|
|
|
@log_function |
|
|
|
def get_missing_events( |
|
|
|
async def get_missing_events( |
|
|
|
self, |
|
|
|
self, |
|
|
|
destination, |
|
|
|
destination, |
|
|
|
room_id, |
|
|
|
room_id, |
|
|
@ -551,7 +535,7 @@ class TransportLayerClient(object): |
|
|
|
): |
|
|
|
): |
|
|
|
path = _create_v1_path("/get_missing_events/%s", room_id) |
|
|
|
path = _create_v1_path("/get_missing_events/%s", room_id) |
|
|
|
|
|
|
|
|
|
|
|
content = yield self.client.post_json( |
|
|
|
content = await self.client.post_json( |
|
|
|
destination=destination, |
|
|
|
destination=destination, |
|
|
|
path=path, |
|
|
|
path=path, |
|
|
|
data={ |
|
|
|
data={ |
|
|
|