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

Rename VerifyKeyRequest.deferred field #5343

Merged
merged 1 commit into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5343.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rename VerifyKeyRequest.deferred field.
24 changes: 12 additions & 12 deletions synapse/crypto/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class VerifyKeyRequest(object):
minimum_valid_until_ts (int): time at which we require the signing key to
be valid. (0 implies we don't care)

deferred(Deferred[str, str, nacl.signing.VerifyKey]):
key_ready (Deferred[str, str, nacl.signing.VerifyKey]):
A deferred (server_name, key_id, verify_key) tuple that resolves when
a verify key has been fetched. The deferreds' callbacks are run with no
logcontext.
Expand All @@ -88,7 +88,7 @@ class VerifyKeyRequest(object):
key_ids = attr.ib()
json_object = attr.ib()
minimum_valid_until_ts = attr.ib()
deferred = attr.ib(default=attr.Factory(defer.Deferred))
key_ready = attr.ib(default=attr.Factory(defer.Deferred))


class KeyLookupError(ValueError):
Expand Down Expand Up @@ -204,7 +204,7 @@ def process(server_name, json_object, validity_time):
def _start_key_lookups(self, verify_requests):
"""Sets off the key fetches for each verify request

Once each fetch completes, verify_request.deferred will be resolved.
Once each fetch completes, verify_request.key_ready will be resolved.

Args:
verify_requests (List[VerifyKeyRequest]):
Expand Down Expand Up @@ -250,7 +250,7 @@ def remove_deferreds(res, verify_request):
return res

for verify_request in verify_requests:
verify_request.deferred.addBoth(remove_deferreds, verify_request)
verify_request.key_ready.addBoth(remove_deferreds, verify_request)
except Exception:
logger.exception("Error starting key lookups")

Expand Down Expand Up @@ -303,7 +303,7 @@ def rm(r, server_name_):
def _get_server_verify_keys(self, verify_requests):
"""Tries to find at least one key for each verify request

For each verify_request, verify_request.deferred is called back with
For each verify_request, verify_request.key_ready is called back with
params (server_name, key_id, VerifyKey) if a key is found, or errbacked
with a SynapseError if none of the keys are found.

Expand All @@ -312,7 +312,7 @@ def _get_server_verify_keys(self, verify_requests):
"""

remaining_requests = set(
(rq for rq in verify_requests if not rq.deferred.called)
(rq for rq in verify_requests if not rq.key_ready.called)
)

@defer.inlineCallbacks
Expand All @@ -326,7 +326,7 @@ def do_iterations():
# look for any requests which weren't satisfied
with PreserveLoggingContext():
for verify_request in remaining_requests:
verify_request.deferred.errback(
verify_request.key_ready.errback(
SynapseError(
401,
"No key for %s with ids in %s (min_validity %i)"
Expand All @@ -346,8 +346,8 @@ def on_err(err):
logger.error("Unexpected error in _get_server_verify_keys: %s", err)
with PreserveLoggingContext():
for verify_request in remaining_requests:
if not verify_request.deferred.called:
verify_request.deferred.errback(err)
if not verify_request.key_ready.called:
verify_request.key_ready.errback(err)

run_in_background(do_iterations).addErrback(on_err)

Expand All @@ -366,7 +366,7 @@ def _attempt_key_fetches_with_fetcher(self, fetcher, remaining_requests):

for verify_request in remaining_requests:
# any completed requests should already have been removed
assert not verify_request.deferred.called
assert not verify_request.key_ready.called
keys_for_server = missing_keys[verify_request.server_name]

for key_id in verify_request.key_ids:
Expand Down Expand Up @@ -402,7 +402,7 @@ def _attempt_key_fetches_with_fetcher(self, fetcher, remaining_requests):
continue

with PreserveLoggingContext():
verify_request.deferred.callback(
verify_request.key_ready.callback(
(server_name, key_id, fetch_key_result.verify_key)
)
completed.append(verify_request)
Expand Down Expand Up @@ -862,7 +862,7 @@ def _handle_key_deferred(verify_request):
"""
server_name = verify_request.server_name
with PreserveLoggingContext():
_, key_id, verify_key = yield verify_request.deferred
_, key_id, verify_key = yield verify_request.key_ready

json_object = verify_request.json_object

Expand Down