mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-16 07:23:54 +01:00
Measure keyrings
This commit is contained in:
parent
39242090e3
commit
2426c2f21a
1 changed files with 36 additions and 34 deletions
|
@ -22,6 +22,7 @@ from synapse.util.logcontext import (
|
||||||
preserve_context_over_deferred, preserve_context_over_fn, PreserveLoggingContext,
|
preserve_context_over_deferred, preserve_context_over_fn, PreserveLoggingContext,
|
||||||
preserve_fn
|
preserve_fn
|
||||||
)
|
)
|
||||||
|
from synapse.util.metrics import Measure
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
|
@ -115,42 +116,43 @@ class Keyring(object):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def handle_key_deferred(verify_request):
|
def handle_key_deferred(verify_request):
|
||||||
server_name = verify_request.server_name
|
with Measure(self.clock, "handle_key_deferred"):
|
||||||
try:
|
server_name = verify_request.server_name
|
||||||
_, key_id, verify_key = yield verify_request.deferred
|
try:
|
||||||
except IOError as e:
|
_, key_id, verify_key = yield verify_request.deferred
|
||||||
logger.warn(
|
except IOError as e:
|
||||||
"Got IOError when downloading keys for %s: %s %s",
|
logger.warn(
|
||||||
server_name, type(e).__name__, str(e.message),
|
"Got IOError when downloading keys for %s: %s %s",
|
||||||
)
|
server_name, type(e).__name__, str(e.message),
|
||||||
raise SynapseError(
|
)
|
||||||
502,
|
raise SynapseError(
|
||||||
"Error downloading keys for %s" % (server_name,),
|
502,
|
||||||
Codes.UNAUTHORIZED,
|
"Error downloading keys for %s" % (server_name,),
|
||||||
)
|
Codes.UNAUTHORIZED,
|
||||||
except Exception as e:
|
)
|
||||||
logger.exception(
|
except Exception as e:
|
||||||
"Got Exception when downloading keys for %s: %s %s",
|
logger.exception(
|
||||||
server_name, type(e).__name__, str(e.message),
|
"Got Exception when downloading keys for %s: %s %s",
|
||||||
)
|
server_name, type(e).__name__, str(e.message),
|
||||||
raise SynapseError(
|
)
|
||||||
401,
|
raise SynapseError(
|
||||||
"No key for %s with id %s" % (server_name, key_ids),
|
401,
|
||||||
Codes.UNAUTHORIZED,
|
"No key for %s with id %s" % (server_name, key_ids),
|
||||||
)
|
Codes.UNAUTHORIZED,
|
||||||
|
)
|
||||||
|
|
||||||
json_object = verify_request.json_object
|
json_object = verify_request.json_object
|
||||||
|
|
||||||
try:
|
try:
|
||||||
verify_signed_json(json_object, server_name, verify_key)
|
verify_signed_json(json_object, server_name, verify_key)
|
||||||
except:
|
except:
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
401,
|
401,
|
||||||
"Invalid signature for server %s with key %s:%s" % (
|
"Invalid signature for server %s with key %s:%s" % (
|
||||||
server_name, verify_key.alg, verify_key.version
|
server_name, verify_key.alg, verify_key.version
|
||||||
),
|
),
|
||||||
Codes.UNAUTHORIZED,
|
Codes.UNAUTHORIZED,
|
||||||
)
|
)
|
||||||
|
|
||||||
server_to_deferred = {
|
server_to_deferred = {
|
||||||
server_name: defer.Deferred()
|
server_name: defer.Deferred()
|
||||||
|
|
Loading…
Reference in a new issue