changeset 1553:24ef62e7013f

add kick_me option to surge_protect
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 15 Sep 2006 19:42:53 +0200
parents f9639ed07af2
children 0739c71cc6a6
files MoinMoin/request/__init__.py
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/request/__init__.py	Thu Sep 14 23:09:53 2006 +0200
+++ b/MoinMoin/request/__init__.py	Fri Sep 15 19:42:53 2006 +0200
@@ -225,8 +225,10 @@
             self.reset()
             self.clock.stop('base__init__')
 
-    def surge_protect(self):
-        """ check if someone requesting too much from us """
+    def surge_protect(self, kick_him=False):
+        """ check if someone requesting too much from us,
+            if kick_him is True, we unconditionally blacklist the current user/ip
+        """
         limits = self.cfg.surge_action_limits
         if not limits:
             return False
@@ -277,6 +279,10 @@
                 maxnum, dt = limits.get(current_action, default_limit)
                 events = surgedict.setdefault(current_id, copy.copy({}))
                 timestamps = events.setdefault(current_action, copy.copy([]))
+
+                if kick_him: # ban this guy, NOW
+                    timestamps.extend([(now + self.cfg.surge_lockout_time, "!")] * (2*maxnum))
+
                 surge_detected = surge_detected or len(timestamps) > maxnum
 
                 surge_indicator = surge_detected and "!" or ""