From: Vsevolod Stakhov Date: Mon, 8 Jul 2019 14:01:42 +0000 (+0100) Subject: [Minor] Remove bloom filters: not used for ages X-Git-Tag: 2.0~633 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b266445f47dec06392a7e058f499325fa3c052b9;p=rspamd.git [Minor] Remove bloom filters: not used for ages --- diff --git a/src/libutil/CMakeLists.txt b/src/libutil/CMakeLists.txt index 5a94a732c..290841373 100644 --- a/src/libutil/CMakeLists.txt +++ b/src/libutil/CMakeLists.txt @@ -2,7 +2,6 @@ SET(LIBRSPAMDUTILSRC ${CMAKE_CURRENT_SOURCE_DIR}/addr.c ${CMAKE_CURRENT_SOURCE_DIR}/libev_helper.c - ${CMAKE_CURRENT_SOURCE_DIR}/bloom.c ${CMAKE_CURRENT_SOURCE_DIR}/expression.c ${CMAKE_CURRENT_SOURCE_DIR}/fstring.c ${CMAKE_CURRENT_SOURCE_DIR}/hash.c diff --git a/src/libutil/bloom.c b/src/libutil/bloom.c deleted file mode 100644 index 2447b1b10..000000000 --- a/src/libutil/bloom.c +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * Copyright 2016 Vsevolod Stakhov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "config.h" -#include "bloom.h" -#include "cryptobox.h" - -/* 4 bits are used for counting (implementing delete operation) */ -#define SIZE_BIT 4 - -/* These macroes are for 4 bits for counting element */ -#define INCBIT(a, n, acc) do { \ - acc = \ - a[n * SIZE_BIT / CHAR_BIT] & (0xF << \ - (n % (CHAR_BIT / SIZE_BIT) * SIZE_BIT)); \ - acc ++; \ - acc &= 0xF; \ - \ - a[n * SIZE_BIT / \ - CHAR_BIT] &= (0xF << (4 - (n % (CHAR_BIT / SIZE_BIT) * SIZE_BIT))); \ - a[n * SIZE_BIT / \ - CHAR_BIT] |= (acc << (n % (CHAR_BIT / SIZE_BIT) * SIZE_BIT)); \ -} while (0); - -#define DECBIT(a, n, acc) do { \ - acc = \ - a[n * SIZE_BIT / CHAR_BIT] & (0xF << \ - (n % (CHAR_BIT / SIZE_BIT) * SIZE_BIT)); \ - acc --; \ - acc &= 0xF; \ - \ - a[n * SIZE_BIT / \ - CHAR_BIT] &= (0xF << (4 - (n % (CHAR_BIT / SIZE_BIT) * SIZE_BIT))); \ - a[n * SIZE_BIT / \ - CHAR_BIT] |= (acc << (n % (CHAR_BIT / SIZE_BIT) * SIZE_BIT)); \ -} while (0); - -#define GETBIT(a, \ - n) (a[n * SIZE_BIT / CHAR_BIT] & (0xF << \ - (n % (CHAR_BIT / SIZE_BIT) * SIZE_BIT))) - -/* Common hash functions */ - - -rspamd_bloom_filter_t * -rspamd_bloom_create (size_t size, size_t nfuncs, ...) -{ - rspamd_bloom_filter_t *bloom; - va_list l; - gsize n; - - if (!(bloom = g_malloc (sizeof (rspamd_bloom_filter_t)))) { - return NULL; - } - if (!(bloom->a = - g_new0 (gchar, (size + CHAR_BIT - 1) / CHAR_BIT * SIZE_BIT))) { - g_free (bloom); - return NULL; - } - if (!(bloom->seeds = g_new0 (guint32, nfuncs))) { - g_free (bloom->a); - g_free (bloom); - return NULL; - } - - va_start (l, nfuncs); - for (n = 0; n < nfuncs; ++n) { - bloom->seeds[n] = va_arg (l, guint32); - } - va_end (l); - - bloom->nfuncs = nfuncs; - bloom->asize = size; - - return bloom; -} - -void -rspamd_bloom_destroy (rspamd_bloom_filter_t * bloom) -{ - g_free (bloom->a); - g_free (bloom->seeds); - g_free (bloom); -} - -gboolean -rspamd_bloom_add (rspamd_bloom_filter_t * bloom, const gchar *s) -{ - size_t n, len; - u_char t; - guint v; - - if (s == NULL) { - return FALSE; - } - len = strlen (s); - for (n = 0; n < bloom->nfuncs; ++n) { - v = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64, - s, len, bloom->seeds[n]) % bloom->asize; - INCBIT (bloom->a, v, t); - } - - return TRUE; -} - -gboolean -rspamd_bloom_del (rspamd_bloom_filter_t * bloom, const gchar *s) -{ - size_t n, len; - u_char t; - guint v; - - if (s == NULL) { - return FALSE; - } - len = strlen (s); - for (n = 0; n < bloom->nfuncs; ++n) { - v = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64, - s, len, bloom->seeds[n]) % bloom->asize; - DECBIT (bloom->a, v, t); - } - - return TRUE; - -} - -gboolean -rspamd_bloom_check (rspamd_bloom_filter_t * bloom, const gchar *s) -{ - size_t n, len; - guint v; - - if (s == NULL) { - return FALSE; - } - len = strlen (s); - for (n = 0; n < bloom->nfuncs; ++n) { - v = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64, - s, len, bloom->seeds[n]) % bloom->asize; - if (!(GETBIT (bloom->a, v))) { - return FALSE; - } - } - - return TRUE; -} diff --git a/src/libutil/bloom.h b/src/libutil/bloom.h deleted file mode 100644 index 9866e9988..000000000 --- a/src/libutil/bloom.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef __RSPAMD_BLOOM_H__ -#define __RSPAMD_BLOOM_H__ - -#include "config.h" - -typedef struct rspamd_bloom_filter_s { - size_t asize; - gchar *a; - size_t nfuncs; - guint32 *seeds; -} rspamd_bloom_filter_t; - - -/* - * Some random uint32 seeds for hashing - */ -#define RSPAMD_DEFAULT_BLOOM_HASHES 8, 0x61782caaU, 0x79ab8141U, 0xe45ee2d1U, \ - 0xf97542d1U, 0x1e2623edU, 0xf5a23cfeU, 0xa41b2508U, 0x85abdce8U - -/* - * Create new bloom filter - * @param size length of bloom buffer - * @param nfuncs number of hash functions - * @param ... hash functions list - */ -rspamd_bloom_filter_t * rspamd_bloom_create (size_t size, size_t nfuncs, ...); - -/* - * Destroy bloom filter - */ -void rspamd_bloom_destroy (rspamd_bloom_filter_t * bloom); - -/* - * Add a string to bloom filter - */ -gboolean rspamd_bloom_add (rspamd_bloom_filter_t * bloom, const gchar *s); - -/* - * Delete a string from bloom filter - */ -gboolean rspamd_bloom_del (rspamd_bloom_filter_t * bloom, const gchar *s); - -/* - * Check whether this string is in bloom filter (algorithm produces FALSE-POSITIVES, so result must be checked if it is positive) - */ -gboolean rspamd_bloom_check (rspamd_bloom_filter_t * bloom, const gchar *s); - -#endif