aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-08-24 16:49:57 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-08-24 16:49:57 +0100
commitefd981202a374cc75b2d5d1e61b518267e8527d8 (patch)
treeb93d28a00c28eb70a5deda98b2707d082fe590a8
parente1659e40db3f5da8492bf75a3e270146ce6cca32 (diff)
downloadrspamd-efd981202a374cc75b2d5d1e61b518267e8527d8.tar.gz
rspamd-efd981202a374cc75b2d5d1e61b518267e8527d8.zip
Replace murmur with xxhash32.
-rw-r--r--src/libserver/cfg_utils.c3
-rw-r--r--src/libutil/util.c171
-rw-r--r--src/libutil/util.h35
-rw-r--r--src/main.c17
4 files changed, 9 insertions, 217 deletions
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 765b0790a..2eae0b0c3 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -33,6 +33,7 @@
#include "kvstorage_config.h"
#include "map.h"
#include "dynamic_cfg.h"
+#include "xxhash.h"
#define DEFAULT_SCORE 10.0
@@ -1036,7 +1037,7 @@ rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data)
return;
}
- checksum = murmur32_hash (cbdata->buf->str, cbdata->buf->len);
+ checksum = XXH32 (cbdata->buf->str, cbdata->buf->len, 0xdead);
if (data->map->checksum != checksum) {
/* New data available */
parser = ucl_parser_new (0);
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 3ca0c1aca..f06b7a62d 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -1798,177 +1798,6 @@ rspamd_create_thread (const gchar *name,
return new;
}
-guint32
-murmur32_hash (const guint8 *in, gsize len)
-{
-
-
- const guint32 c1 = 0xcc9e2d51;
- const guint32 c2 = 0x1b873593;
-
- const int nblocks = len / 4;
- const guint32 *blocks = (const guint32 *)(in);
- const guint8 *tail;
- guint32 h = 0;
- gint i;
- guint32 k;
-
- if (in == NULL || len == 0) {
- return 0;
- }
-
- tail = (const guint8 *)(in + (nblocks * 4));
-
- for (i = 0; i < nblocks; i++) {
- k = blocks[i];
-
- k *= c1;
- k = (k << 15) | (k >> (32 - 15));
- k *= c2;
-
- h ^= k;
- h = (h << 13) | (h >> (32 - 13));
- h = (h * 5) + 0xe6546b64;
- }
-
- k = 0;
- switch (len & 3) {
- case 3:
- k ^= tail[2] << 16;
- case 2:
- k ^= tail[1] << 8;
- case 1:
- k ^= tail[0];
- k *= c1;
- k = (k << 13) | (k >> (32 - 15));
- k *= c2;
- h ^= k;
- };
-
- h ^= len;
-
- h ^= h >> 16;
- h *= 0x85ebca6b;
- h ^= h >> 13;
- h *= 0xc2b2ae35;
- h ^= h >> 16;
-
- return h;
-}
-
-void
-murmur128_hash (const guint8 *in, gsize len, guint64 out[])
-{
- const guint64 c1 = 0x87c37b91114253d5ULL;
- const guint64 c2 = 0x4cf5ad432745937fULL;
- const gint nblocks = len / 16;
- const guint64 *blocks = (const guint64 *)(in);
- const guint8 *tail;
- guint64 h1 = 0;
- guint64 h2 = 0;
- int i;
- guint64 k1, k2;
-
- if (in == NULL || len == 0 || out == NULL) {
- return;
- }
-
- tail = (const guint8 *)(in + (nblocks * 16));
-
- for (i = 0; i < nblocks; i++) {
- k1 = blocks[i * 2 + 0];
- k2 = blocks[i * 2 + 1];
-
- k1 *= c1;
- k1 = (k1 << 31) | (k1 >> (64 - 31));
- k1 *= c2;
- h1 ^= k1;
-
- h1 = (h1 << 27) | (h1 >> (64 - 27));
- h1 += h2;
- h1 = h1 * 5 + 0x52dce729;
-
- k2 *= c2;
- k2 = (k2 << 33) | (k2 >> (64 - 33));
- k2 *= c1;
- h2 ^= k2;
-
- h2 = (h2 << 31) | (h2 >> (64 - 31));
- h2 += h1;
- h2 = h2 * 5 + 0x38495ab5;
- }
-
- k1 = k2 = 0;
- switch (len & 15) {
- case 15:
- k2 ^= (guint64)(tail[14]) << 48;
- case 14:
- k2 ^= (guint64)(tail[13]) << 40;
- case 13:
- k2 ^= (guint64)(tail[12]) << 32;
- case 12:
- k2 ^= (guint64)(tail[11]) << 24;
- case 11:
- k2 ^= (guint64)(tail[10]) << 16;
- case 10:
- k2 ^= (guint64)(tail[ 9]) << 8;
- case 9:
- k2 ^= (guint64)(tail[ 8]) << 0;
- k2 *= c2;
- k2 = (k2 << 33) | (k2 >> (64 - 33));
- k2 *= c1;
- h2 ^= k2;
-
- case 8:
- k1 ^= (guint64)(tail[ 7]) << 56;
- case 7:
- k1 ^= (guint64)(tail[ 6]) << 48;
- case 6:
- k1 ^= (guint64)(tail[ 5]) << 40;
- case 5:
- k1 ^= (guint64)(tail[ 4]) << 32;
- case 4:
- k1 ^= (guint64)(tail[ 3]) << 24;
- case 3:
- k1 ^= (guint64)(tail[ 2]) << 16;
- case 2:
- k1 ^= (guint64)(tail[ 1]) << 8;
- case 1:
- k1 ^= (guint64)(tail[ 0]) << 0;
- k1 *= c1;
- k1 = (k1 << 31) | (k1 >> (64 - 31));
- k1 *= c2;
- h1 ^= k1;
- };
-
- //----------
- // finalization
-
- h1 ^= len;
- h2 ^= len;
-
- h1 += h2;
- h2 += h1;
-
- h1 ^= h1 >> 33;
- h1 *= 0xff51afd7ed558ccdULL;
- h1 ^= h1 >> 33;
- h1 *= 0xc4ceb9fe1a85ec53ULL;
- h1 ^= h1 >> 33;
-
- h2 ^= h2 >> 33;
- h2 *= 0xff51afd7ed558ccdULL;
- h2 ^= h2 >> 33;
- h2 *= 0xc4ceb9fe1a85ec53ULL;
- h2 ^= h2 >> 33;
-
- h1 += h2;
- h2 += h1;
-
- out[0] = h1;
- out[1] = h2;
-}
-
struct hash_copy_callback_data {
gpointer (*key_copy_func)(gconstpointer data, gpointer ud);
gpointer (*value_copy_func)(gconstpointer data, gpointer ud);
diff --git a/src/libutil/util.h b/src/libutil/util.h
index 9bef49a7e..3a44cb1d8 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -387,41 +387,6 @@ GThread * rspamd_create_thread (const gchar *name,
GError **err);
/**
- * Return 32bit murmur hash value for specified input
- * @param in input data
- * @param len length of the input data
- * @code
- * MurmurHash3 was created by Austin Appleby in 2008. The cannonical
- * implementations are in C++ and placed in the public.
- *
- * https://sites.google.com/site/murmurhash/
- *
- * Seungyoung Kim has ported it's cannonical implementation to C language
- * in 2012 and published it as a part of qLibc component.
- * @endcode
- * @return
- */
-guint32 murmur32_hash (const guint8 *in, gsize len);
-
-/**
- * Return 32bit murmur hash value for specified input
- * @param in input data
- * @param len length of the input data
- * @param out array of 2 guint64 variables
- * @code
- * MurmurHash3 was created by Austin Appleby in 2008. The cannonical
- * implementations are in C++ and placed in the public.
- *
- * https://sites.google.com/site/murmurhash/
- *
- * Seungyoung Kim has ported it's cannonical implementation to C language
- * in 2012 and published it as a part of qLibc component.
- * @endcode
- * @return
- */
-void murmur128_hash (const guint8 *in, gsize len, guint64 out[]);
-
-/**
* Deep copy of one hash table to another
* @param src source hash
* @param dst destination hash
diff --git a/src/main.c b/src/main.c
index 77143d1f0..c1fa93815 100644
--- a/src/main.c
+++ b/src/main.c
@@ -34,6 +34,7 @@
#include "symbols_cache.h"
#include "lua/lua_common.h"
#include "ottery.h"
+#include "xxhash.h"
#ifdef HAVE_OPENSSL
#include <openssl/rand.h>
#include <openssl/err.h>
@@ -652,13 +653,14 @@ fork_delayed (struct rspamd_main *rspamd)
static inline uintptr_t
make_listen_key (gint ai, const gchar *addr, gint port)
{
- uintptr_t res = 0;
+ gpointer xxh;
- res = murmur32_hash (addr, strlen (addr));
- res += murmur32_hash ((guchar *)&ai, sizeof (gint));
- res += murmur32_hash ((guchar *)&port, sizeof (gint));
+ xxh = XXH32_init (0xbeef);
+ XXH32_update (xxh, addr, strlen (addr));
+ XXH32_update (xxh, (guchar *)&ai, sizeof (gint));
+ XXH32_update (xxh, (guchar *)&port, sizeof (gint));
- return res;
+ return XXH32_digest (xxh);
}
static void
@@ -1218,11 +1220,6 @@ main (gint argc, gchar **argv, gchar **env)
pworker++;
}
- /* Init counters */
- rspamd_main->counters = rspamd_hash_new_shared (rspamd_main->server_pool,
- rspamd_str_hash,
- rspamd_str_equal,
- 64);
/* Init listen sockets hash */
listen_sockets = g_hash_table_new (g_direct_hash, g_direct_equal);