]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Implement expiration
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 11 Sep 2024 20:40:12 +0000 (21:40 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 11 Sep 2024 20:40:12 +0000 (21:40 +0100)
src/fuzzy_storage.c

index ad1697dc10092c3402c95f6a2ebf55ccadeb88a2..770f428ad18705ae0606b4653fce36234220dfd0 100644 (file)
@@ -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,