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);
gpointer data,
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
#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>
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
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);