commit 6a1d7fc0218c9aae9fdc4930f3724112971c6320 Author: Isis Lovecruft isis@torproject.org Date: Mon May 5 19:08:58 2014 +0000
Change email request handler in Dist to record email wait time.
This now records how long a client must wait before they are no longer rate-limited for the email distributor. --- lib/bridgedb/Dist.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/lib/bridgedb/Dist.py b/lib/bridgedb/Dist.py index 580aa5d..5c0cbac 100644 --- a/lib/bridgedb/Dist.py +++ b/lib/bridgedb/Dist.py @@ -419,19 +419,19 @@ class EmailBasedDistributor(Distributor): logging.info("Attempting to return for %d bridges for %s..." % (N, emailaddress))
- if lastSaw is not None and lastSaw + MAX_EMAIL_RATE >= now: - logging.info("Client %s sent duplicate request within %d seconds." - % (emailaddress, MAX_EMAIL_RATE)) - if wasWarned: - logging.info( - "Client was already warned about duplicate requests.") - raise IgnoreEmail("Client was warned", emailaddress) - else: - logging.info("Sending duplicate request warning.") - db.setWarnedEmail(emailaddress, True, now) - db.commit() - - raise TooSoonEmail("Too many emails; wait till later", emailaddress) + if lastSaw is not None: + if (lastSaw + MAX_EMAIL_RATE) >= now: + wait = (lastSaw + MAX_EMAIL_RATE) - now + logging.info("Client %s must wait another %d seconds." + % (emailaddress, wait)) + if wasWarned: + raise IgnoreEmail("Client was warned.", emailaddress) + else: + logging.info("Sending duplicate request warning.") + db.setWarnedEmail(emailaddress, True, now) + db.commit() + raise TooSoonEmail("Must wait %d seconds" % wait, + emailaddress)
# warning period is over elif wasWarned: