diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-09-11 21:40:12 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-09-11 21:40:12 +0100 |
commit | 88b2538ad7a0f89bcc77d6de3d2df28d66ce10e9 (patch) | |
tree | 75ab65cc5864a71b6ff5e8a66a3c11f852ae1a7d | |
parent | 4da7c81cb58f5b051e9cd6b90379e9b4cd4bc3dd (diff) | |
download | rspamd-88b2538ad7a0f89bcc77d6de3d2df28d66ce10e9.tar.gz rspamd-88b2538ad7a0f89bcc77d6de3d2df28d66ce10e9.zip |
[Project] Implement expiration
-rw-r--r-- | src/fuzzy_storage.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index ad1697dc1..770f428ad 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -138,6 +138,7 @@ struct fuzzy_key { double burst; double rate; ev_tstamp expire; + bool expired; ref_entry_t ref; }; @@ -1599,6 +1600,30 @@ rspamd_fuzzy_process_command(struct fuzzy_session *session) } } + if (session->key && !isnan(session->key->expire)) { + /* Check expire */ + static ev_tstamp today = NAN; + + if (isnan(today)) { + today = ev_time(); + } + else if (rspamd_random_uint64_fast() > 0xFFFF000000000000ULL) { + today = ev_time(); + } + + if (today > session->key->expire) { + if (!session->key->expired) { + msg_info("key %s is expired", session->key->name); + session->key->expired = true; + } + + result.v1.value = 503; + result.v1.prob = 0.0f; + rspamd_fuzzy_make_reply(cmd, &result, session, send_flags); + return; + } + } + if (is_rate_allowed) { REF_RETAIN(session); rspamd_fuzzy_backend_check(session->ctx->backend, cmd, |