Made logging for rate limiting more informative.

This commit is contained in:
Jeremy Fincher 2003-06-05 10:00:31 +00:00
parent 4c6e33b72d
commit 51cb83d3e6

View File

@ -108,8 +108,10 @@ class RateLimiter:
return None return None
def put(self, msg): def put(self, msg):
if self.limit(msg) and not world.testing: t = self.limit(msg)
debug.msg('Limiting message from %s' % msg.prefix, 'low') if t and not world.testing:
s = 'Limiting message from %s for %s seconds' % (msg.prefix, t)
debug.msg(s, 'normal')
self.limited.append(msg) self.limited.append(msg)
else: else:
self.unlimited.append(msg) self.unlimited.append(msg)
@ -120,7 +122,7 @@ class RateLimiter:
key = '@'.join((user, host)) key = '@'.join((user, host))
now = time.time() now = time.time()
if ircdb.checkCapabilities(msg.prefix, ('owner', 'admin')): if ircdb.checkCapabilities(msg.prefix, ('owner', 'admin')):
return False return 0
if key in self.lastRequest: if key in self.lastRequest:
# Here's how we throttle requests. We keep a dictionary of # Here's how we throttle requests. We keep a dictionary of
# (lastRequest, wait period) tuples. When a request arrives, # (lastRequest, wait period) tuples. When a request arrives,
@ -133,18 +135,19 @@ class RateLimiter:
(t, wait) = self.lastRequest[key] (t, wait) = self.lastRequest[key]
if now - t <= wait: if now - t <= wait:
if penalize: if penalize:
self.lastRequest[key] = (now, wait+conf.throttleTime) newWait = wait + conf.throttleTime
else: else:
self.lastRequest[key] = (now, wait - (now - t)) newWait = wait - (now - t)
return True self.lastRequest[key] = (now, newWait)
return newWait
else: else:
self.lastRequest[key] = (now, conf.throttleTime) self.lastRequest[key] = (now, conf.throttleTime)
return False return 0
else: else:
self.lastRequest[key] = (now, conf.throttleTime) self.lastRequest[key] = (now, conf.throttleTime)
return False return 0
else: else:
return False return 0
class Error(Exception): class Error(Exception):