summaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-05 12:58:43 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-05 12:58:43 +0100
commitfc0d12749932139effc7656e147d13ff09f6c23c (patch)
tree6f5434e6411bfee29f5b7ba1ad0454ec4903d528 /src/libserver
parenta09cd72d58e5e0b557eefdcbcccf3f9f6a5a74cb (diff)
downloadrspamd-fc0d12749932139effc7656e147d13ff09f6c23c.tar.gz
rspamd-fc0d12749932139effc7656e147d13ff09f6c23c.zip
[Project] Update Redis backend to support refreshing
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/fuzzy_backend_redis.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/libserver/fuzzy_backend_redis.c b/src/libserver/fuzzy_backend_redis.c
index d25f057ed..550e76f6f 100644
--- a/src/libserver/fuzzy_backend_redis.c
+++ b/src/libserver/fuzzy_backend_redis.c
@@ -1157,6 +1157,40 @@ rspamd_fuzzy_update_append_command (struct rspamd_fuzzy_backend *bk,
return FALSE;
}
}
+ else if (cmd->cmd == FUZZY_REFRESH) {
+ /*
+ * Issue refresh command by just EXPIRE command
+ * EXPIRE <key> <expire>
+ * Where <key> is <prefix> || <digest>
+ */
+
+ klen = strlen (session->backend->redis_object) +
+ sizeof (cmd->digest) + 1;
+
+ /* EXPIRE */
+ key = g_string_sized_new (klen);
+ g_string_append (key, session->backend->redis_object);
+ g_string_append_len (key, cmd->digest, sizeof (cmd->digest));
+ value = g_string_sized_new (30);
+ rspamd_printf_gstring (value, "%d",
+ (gint)rspamd_fuzzy_backend_get_expire (bk));
+ session->argv[cur_shift] = g_strdup ("EXPIRE");
+ session->argv_lens[cur_shift++] = sizeof ("EXPIRE") - 1;
+ session->argv[cur_shift] = key->str;
+ session->argv_lens[cur_shift++] = key->len;
+ session->argv[cur_shift] = value->str;
+ session->argv_lens[cur_shift++] = value->len;
+ g_string_free (key, FALSE);
+ g_string_free (value, FALSE);
+
+ if (redisAsyncCommandArgv (session->ctx, NULL, NULL,
+ 3,
+ (const gchar **)&session->argv[cur_shift - 3],
+ &session->argv_lens[cur_shift - 3]) != REDIS_OK) {
+
+ return FALSE;
+ }
+ }
else {
g_assert_not_reached ();
}
@@ -1230,6 +1264,47 @@ rspamd_fuzzy_update_append_command (struct rspamd_fuzzy_backend *bk,
}
}
}
+ else if (cmd->cmd == FUZZY_REFRESH) {
+ klen = strlen (session->backend->redis_object) +
+ 64 + 1;
+
+ for (i = 0; i < RSPAMD_SHINGLE_SIZE; i ++) {
+ guchar *hval;
+ /*
+ * For each command with shingles we additionally emit 32 commands:
+ * EXPIRE <prefix>_<number>_<value> <expire>
+ */
+
+ /* Expire */
+ key = g_string_sized_new (klen);
+ rspamd_printf_gstring (key, "%s_%d_%uL",
+ session->backend->redis_object,
+ i,
+ io_cmd->cmd.shingle.sgl.hashes[i]);
+ value = g_string_sized_new (30);
+ rspamd_printf_gstring (value, "%d",
+ (gint)rspamd_fuzzy_backend_get_expire (bk));
+ hval = g_malloc (sizeof (io_cmd->cmd.shingle.basic.digest));
+ memcpy (hval, io_cmd->cmd.shingle.basic.digest,
+ sizeof (io_cmd->cmd.shingle.basic.digest));
+ session->argv[cur_shift] = g_strdup ("EXPIRE");
+ session->argv_lens[cur_shift++] = sizeof ("EXPIRE") - 1;
+ session->argv[cur_shift] = key->str;
+ session->argv_lens[cur_shift++] = key->len;
+ session->argv[cur_shift] = value->str;
+ session->argv_lens[cur_shift++] = value->len;
+ g_string_free (key, FALSE);
+ g_string_free (value, FALSE);
+
+ if (redisAsyncCommandArgv (session->ctx, NULL, NULL,
+ 3,
+ (const gchar **)&session->argv[cur_shift - 3],
+ &session->argv_lens[cur_shift - 3]) != REDIS_OK) {
+
+ return FALSE;
+ }
+ }
+ }
else {
g_assert_not_reached ();
}
@@ -1353,6 +1428,15 @@ rspamd_fuzzy_backend_update_redis (struct rspamd_fuzzy_backend *bk,
nargs += RSPAMD_SHINGLE_SIZE * 2;
}
}
+ else if (cmd->cmd == FUZZY_REFRESH) {
+ ncommands += 1;
+ nargs += 3;
+
+ if (io_cmd->is_shingle) {
+ ncommands += RSPAMD_SHINGLE_SIZE;
+ nargs += RSPAMD_SHINGLE_SIZE * 3;
+ }
+ }
}
/* Now we need to create a new request */