Rate limit retries when fetching server keys.

This commit is contained in:
Erik Johnston 2015-02-17 15:57:42 +00:00
parent 1a989c436c
commit 5025305fb2
1 changed files with 76 additions and 60 deletions

View File

@ -87,8 +87,20 @@ class Keyring(object):
return return
# Try to fetch the key from the remote server. # Try to fetch the key from the remote server.
# TODO(markjh): Ratelimit requests to a given server.
retry_last_ts, retry_interval = (0, 0)
retry_timings = yield self.store.get_destination_retry_timings(
server_name
)
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:
(response, tls_certificate) = yield fetch_server_key( (response, tls_certificate) = yield fetch_server_key(
server_name, self.hs.tls_context_factory server_name, self.hs.tls_context_factory
) )
@ -153,3 +165,7 @@ class Keyring(object):
return return
raise ValueError("No verification key found for given key ids") raise ValueError("No verification key found for given key ids")
except:
self.set_retrying(server_name, retry_interval)
raise