From 3a7527c41849a0900d80355c349cb158eac8baff Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Wed, 24 Nov 2021 12:41:12 -0500 Subject: [PATCH] Improve banned forgiveness logic --- app/flood.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/flood.py b/app/flood.py index 3f068f1..4c458c7 100644 --- a/app/flood.py +++ b/app/flood.py @@ -7,10 +7,19 @@ active = False threshold = -1 -def clear_banned(): +def forgive_banned(): global banned - banned = {} + clear_list = [] + + for ip in banned: + if banned[ip] <= 0: + clear_list.append(ip) + else: + banned[ip] -= 1 + + for ip in clear_list: + del banned[ip] def setup(violations_threshold=100): global active @@ -20,7 +29,7 @@ def setup(violations_threshold=100): threshold = violations_threshold scheduler = BackgroundScheduler() - scheduler.add_job(func=clear_banned, trigger="interval", weeks=4) + scheduler.add_job(func=forgive_banned, trigger="interval", minutes=5) scheduler.start() # Shut down the scheduler when exiting the app