aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua/ratelimit.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-07-08 19:22:25 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-07-08 19:22:25 +0100
commit69621218bc47eb54a0dffda7ce819c9309e42c67 (patch)
tree9e67fe84212e2ee03ce461aca28a7ed0aad240ca /src/plugins/lua/ratelimit.lua
parente9d6cfae21b9db130a7c83101954d2df1d6f89aa (diff)
downloadrspamd-69621218bc47eb54a0dffda7ce819c9309e42c67.tar.gz
rspamd-69621218bc47eb54a0dffda7ce819c9309e42c67.zip
[Rework] Introduce dynamic_rate_limit for ratelimits
Diffstat (limited to 'src/plugins/lua/ratelimit.lua')
-rw-r--r--src/plugins/lua/ratelimit.lua12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua
index add5741e8..470ac5f07 100644
--- a/src/plugins/lua/ratelimit.lua
+++ b/src/plugins/lua/ratelimit.lua
@@ -42,6 +42,8 @@ local settings = {
-- Do not check ratelimits for these recipients
whitelisted_rcpts = { 'postmaster', 'mailer-daemon' },
prefix = 'RL',
+ -- If enabled, we apply dynamic rate limiting based on the verdict
+ dynamic_rate_limit = false,
ham_factor_rate = 1.01,
spam_factor_rate = 0.99,
ham_factor_burst = 1.02,
@@ -361,17 +363,19 @@ local function make_prefix(redis_key, name, bucket)
local hash = settings.prefix ..
string.sub(rspamd_hash.create(redis_key):base32(), 1, hash_len)
-- Fill defaults
+ -- If settings.dynamic_rate_limit is false, then the default dynamic rate limits are 1.0
+ -- We always allow per-bucket overrides of the dyn rate limits
if not bucket.spam_factor_rate then
- bucket.spam_factor_rate = settings.spam_factor_rate
+ bucket.spam_factor_rate = settings.dynamic_rate_limit and settings.spam_factor_rate or 1.0
end
if not bucket.ham_factor_rate then
- bucket.ham_factor_rate = settings.ham_factor_rate
+ bucket.ham_factor_rate = settings.dynamic_rate_limit and settings.ham_factor_rate or 1.0
end
if not bucket.spam_factor_burst then
- bucket.spam_factor_burst = settings.spam_factor_burst
+ bucket.spam_factor_burst = settings.dynamic_rate_limit and settings.spam_factor_burst or 1.0
end
if not bucket.ham_factor_burst then
- bucket.ham_factor_burst = settings.ham_factor_burst
+ bucket.ham_factor_burst = settings.dynamic_rate_limit and settings.ham_factor_burst or 1.0
end
return {