This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Stop using deprecated keyIds
param on /key/v2/server
#14525
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Stop using deprecated `keyIds` parameter when calling `/_matrix/key/v2/server`. |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Stop using deprecated `keyIds` parameter when calling `/_matrix/key/v2/server`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
|
||
import abc | ||
import logging | ||
import urllib | ||
from typing import TYPE_CHECKING, Callable, Dict, Iterable, List, Optional, Tuple | ||
|
||
import attr | ||
|
@@ -813,89 +812,69 @@ async def _fetch_keys( | |
|
||
results = {} | ||
|
||
async def get_key(key_to_fetch_item: _FetchKeyRequest) -> None: | ||
async def get_keys(key_to_fetch_item: _FetchKeyRequest) -> None: | ||
server_name = key_to_fetch_item.server_name | ||
key_ids = key_to_fetch_item.key_ids | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did wonder if |
||
|
||
try: | ||
keys = await self.get_server_verify_key_v2_direct(server_name, key_ids) | ||
keys = await self.get_server_verify_keys_v2_direct(server_name) | ||
results[server_name] = keys | ||
except KeyLookupError as e: | ||
logger.warning( | ||
"Error looking up keys %s from %s: %s", key_ids, server_name, e | ||
) | ||
logger.warning("Error looking up keys from %s: %s", server_name, e) | ||
except Exception: | ||
logger.exception("Error getting keys %s from %s", key_ids, server_name) | ||
logger.exception("Error getting keys from %s", server_name) | ||
|
||
await yieldable_gather_results(get_key, keys_to_fetch) | ||
await yieldable_gather_results(get_keys, keys_to_fetch) | ||
return results | ||
|
||
async def get_server_verify_key_v2_direct( | ||
self, server_name: str, key_ids: Iterable[str] | ||
async def get_server_verify_keys_v2_direct( | ||
self, server_name: str | ||
) -> Dict[str, FetchKeyResult]: | ||
""" | ||
|
||
Args: | ||
server_name: | ||
key_ids: | ||
server_name: Server to request keys from | ||
|
||
Returns: | ||
Map from key ID to lookup result | ||
|
||
Raises: | ||
KeyLookupError if there was a problem making the lookup | ||
""" | ||
keys: Dict[str, FetchKeyResult] = {} | ||
|
||
for requested_key_id in key_ids: | ||
# we may have found this key as a side-effect of asking for another. | ||
if requested_key_id in keys: | ||
continue | ||
|
||
time_now_ms = self.clock.time_msec() | ||
try: | ||
response = await self.client.get_json( | ||
destination=server_name, | ||
path="/_matrix/key/v2/server/" | ||
+ urllib.parse.quote(requested_key_id, safe=""), | ||
ignore_backoff=True, | ||
# we only give the remote server 10s to respond. It should be an | ||
# easy request to handle, so if it doesn't reply within 10s, it's | ||
# probably not going to. | ||
# | ||
# Furthermore, when we are acting as a notary server, we cannot | ||
# wait all day for all of the origin servers, as the requesting | ||
# server will otherwise time out before we can respond. | ||
# | ||
# (Note that get_json may make 4 attempts, so this can still take | ||
# almost 45 seconds to fetch the headers, plus up to another 60s to | ||
# read the response). | ||
timeout=10000, | ||
) | ||
except (NotRetryingDestination, RequestSendFailed) as e: | ||
# these both have str() representations which we can't really improve | ||
# upon | ||
raise KeyLookupError(str(e)) | ||
except HttpResponseException as e: | ||
raise KeyLookupError("Remote server returned an error: %s" % (e,)) | ||
|
||
assert isinstance(response, dict) | ||
if response["server_name"] != server_name: | ||
raise KeyLookupError( | ||
"Expected a response for server %r not %r" | ||
% (server_name, response["server_name"]) | ||
) | ||
|
||
response_keys = await self.process_v2_response( | ||
from_server=server_name, | ||
response_json=response, | ||
time_added_ms=time_now_ms, | ||
time_now_ms = self.clock.time_msec() | ||
try: | ||
response = await self.client.get_json( | ||
destination=server_name, | ||
path="/_matrix/key/v2/server", | ||
ignore_backoff=True, | ||
# we only give the remote server 10s to respond. It should be an | ||
# easy request to handle, so if it doesn't reply within 10s, it's | ||
# probably not going to. | ||
# | ||
# Furthermore, when we are acting as a notary server, we cannot | ||
# wait all day for all of the origin servers, as the requesting | ||
# server will otherwise time out before we can respond. | ||
# | ||
# (Note that get_json may make 4 attempts, so this can still take | ||
# almost 45 seconds to fetch the headers, plus up to another 60s to | ||
# read the response). | ||
timeout=10000, | ||
) | ||
await self.store.store_server_verify_keys( | ||
server_name, | ||
time_now_ms, | ||
((server_name, key_id, key) for key_id, key in response_keys.items()), | ||
except (NotRetryingDestination, RequestSendFailed) as e: | ||
# these both have str() representations which we can't really improve | ||
# upon | ||
raise KeyLookupError(str(e)) | ||
except HttpResponseException as e: | ||
raise KeyLookupError("Remote server returned an error: %s" % (e,)) | ||
|
||
assert isinstance(response, dict) | ||
if response["server_name"] != server_name: | ||
raise KeyLookupError( | ||
"Expected a response for server %r not %r" | ||
% (server_name, response["server_name"]) | ||
) | ||
keys.update(response_keys) | ||
|
||
return keys | ||
return await self.process_v2_response( | ||
from_server=server_name, | ||
response_json=response, | ||
time_added_ms=time_now_ms, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.