summary refs log tree commit diff
path: root/synapse/crypto/keyring.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-02-17 17:20:56 +0000
committerErik Johnston <erik@matrix.org>2015-02-17 17:20:56 +0000
commit2b8f1a956c6a1d767a3b60e84e7d0afe5857fb0d (patch)
treeed4e08b47ac6c8a680ff5ba87b26077f70173776 /synapse/crypto/keyring.py
parentRate limit retries when fetching server keys. (diff)
downloadsynapse-2b8f1a956c6a1d767a3b60e84e7d0afe5857fb0d.tar.xz
Add per server retry limiting.
Factor out the pre destination retry logic from TransactionQueue so it
can be reused in both get_pdu and crypto.keyring
Diffstat (limited to 'synapse/crypto/keyring.py')
-rw-r--r--synapse/crypto/keyring.py22
1 files changed, 7 insertions, 15 deletions
diff --git a/synapse/crypto/keyring.py b/synapse/crypto/keyring.py
index 3250cff595..ea00c830c0 100644
--- a/synapse/crypto/keyring.py
+++ b/synapse/crypto/keyring.py
@@ -22,6 +22,8 @@ from syutil.crypto.signing_key import (
 from syutil.base64util import decode_base64, encode_base64
 from synapse.api.errors import SynapseError, Codes
 
+from synapse.util.retryutils import get_retry_limiter
+
 from OpenSSL import crypto
 
 import logging
@@ -88,19 +90,13 @@ class Keyring(object):
 
         # Try to fetch the key from the remote server.
 
-        retry_last_ts, retry_interval = (0, 0)
-        retry_timings = yield self.store.get_destination_retry_timings(
-            server_name
+        limiter = yield get_retry_limiter(
+            server_name,
+            self.clock,
+            self.store,
         )
-        if retry_timings:
-            retry_last_ts, retry_interval = (
-                retry_timings.retry_last_ts, retry_timings.retry_interval
-            )
-            if retry_last_ts + retry_interval > int(self.clock.time_msec()):
-                logger.info("%s not ready for retry", server_name)
-                raise ValueError("No verification key found for given key ids")
 
-        try:
+        with limiter:
             (response, tls_certificate) = yield fetch_server_key(
                 server_name, self.hs.tls_context_factory
             )
@@ -165,7 +161,3 @@ class Keyring(object):
                     return
 
             raise ValueError("No verification key found for given key ids")
-
-        except:
-            self.set_retrying(server_name, retry_interval)
-            raise