]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Use better sharding for ip_score
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 7 May 2018 14:37:58 +0000 (15:37 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 7 May 2018 14:41:24 +0000 (15:41 +0100)
Updating: true

src/plugins/lua/ip_score.lua

index 083556066eca705b30dff48bdc3f963cb2920b99..d861b480684857f18eede4840c697d953f577b0c 100644 (file)
@@ -53,22 +53,28 @@ local options = {
   servers = '', -- list of servers
   lower_bound = 10, -- minimum number of messages to be scored
   metric = 'default',
+  old_shard = false,
   min_score = nil,
   max_score = nil,
   score_divisor = 1,
 }
 
 local function ip_score_hash_key(asn, country, ipnet, ip)
-  -- We use the most common attribute as hashing key
-  if country then
-    return country
-  elseif asn then
-    return asn
-  elseif ipnet then
-    return ipnet
-  else
-    return ip:to_string()
+  if options.old_shard then
+    if country then
+      return country
+    elseif asn then
+      return asn
+    elseif ipnet then
+      return ipnet
+    else
+      return ip:to_string()
+    end
   end
+
+  -- Better sharding
+  return string.format('%s:%s:%s:%s', asn, country, ipnet,
+      ip:to_string())
 end
 
 local function ip_score_get_task_vars(task)