Added ndpi_murmur_hash to the nDPI API
This commit is contained in:
@@ -1804,6 +1804,7 @@ extern "C" {
|
|||||||
u_int32_t ndpi_hash_string(char *str);
|
u_int32_t ndpi_hash_string(char *str);
|
||||||
u_int32_t ndpi_rev_hash_string(char *str);
|
u_int32_t ndpi_rev_hash_string(char *str);
|
||||||
u_int32_t ndpi_hash_string_len(char *str, u_int len);
|
u_int32_t ndpi_hash_string_len(char *str, u_int len);
|
||||||
|
u_int32_t ndpi_murmur_hash(char *str, u_int str_len);
|
||||||
|
|
||||||
/* ******************************* */
|
/* ******************************* */
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ bool ndpi_domain_classify_add(ndpi_domain_classify *c,
|
|||||||
u_int64_t hash1, hash2, hash;
|
u_int64_t hash1, hash2, hash;
|
||||||
char *dot = strrchr(domain, '.');
|
char *dot = strrchr(domain, '.');
|
||||||
|
|
||||||
|
#ifdef DEBUG_ADD
|
||||||
|
printf("[add] Trying to add %s\n", domain);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!dot) return(false);
|
if(!dot) return(false);
|
||||||
if((!strcmp(dot, ".arpa")) || (!strcmp(dot, ".local")))
|
if((!strcmp(dot, ".arpa")) || (!strcmp(dot, ".local")))
|
||||||
return(false);
|
return(false);
|
||||||
@@ -87,6 +91,10 @@ bool ndpi_domain_classify_add(ndpi_domain_classify *c,
|
|||||||
|
|
||||||
#ifdef DEBUG_ADD
|
#ifdef DEBUG_ADD
|
||||||
printf("[add] %s @ %u [hash: %llu]\n", domain, class_id, hash);
|
printf("[add] %s @ %u [hash: %llu]\n", domain, class_id, hash);
|
||||||
|
|
||||||
|
if(ndpi_binary_bitmap_isset(c->bitmap, hash, class_id)) {
|
||||||
|
printf("[add] False positive %s @ %u [hash: %llu]\n", domain, class_id, hash);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return(ndpi_binary_bitmap_set(c->bitmap, hash, class_id));
|
return(ndpi_binary_bitmap_set(c->bitmap, hash, class_id));
|
||||||
@@ -310,8 +318,19 @@ static bool ndpi_domain_search_add(ndpi_domain_search *search, char *domain) {
|
|||||||
if(elem == domain) {
|
if(elem == domain) {
|
||||||
/* We're adding the beginning of the domain, hence the last token before quitting */
|
/* We're adding the beginning of the domain, hence the last token before quitting */
|
||||||
h += END_OF_TOKENS_DELIMITER;
|
h += END_OF_TOKENS_DELIMITER;
|
||||||
|
|
||||||
|
#ifdef DEBUG_ADD
|
||||||
|
if(ndpi_bitmap_isset(search->bitmap[bitmap_id], h + hsum))
|
||||||
|
printf("[add] False positive while adding %s (%s) [%u][bitmap_id: %u]\n",
|
||||||
|
elem, domain, h + hsum, bitmap_id);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_ADD
|
||||||
|
printf("[add] Trying to add %s [%s][%u][bitmap_id: %u]\n",
|
||||||
|
elem, domain, h + hsum, bitmap_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
ndpi_bitmap_set(search->bitmap[bitmap_id], h + hsum);
|
ndpi_bitmap_set(search->bitmap[bitmap_id], h + hsum);
|
||||||
|
|
||||||
bitmap_id++, hsum += h;
|
bitmap_id++, hsum += h;
|
||||||
|
|||||||
@@ -25,6 +25,15 @@
|
|||||||
#include "ndpi_config.h"
|
#include "ndpi_config.h"
|
||||||
#include "ndpi_api.h"
|
#include "ndpi_api.h"
|
||||||
|
|
||||||
|
#include "third_party/include/MurmurHash3.h"
|
||||||
|
|
||||||
|
/* ******************************************************************** */
|
||||||
|
|
||||||
|
/* Based on djb2 hash - http://www.cse.yorku.ca/~oz/hash.html */
|
||||||
|
u_int32_t ndpi_murmur_hash(char *str, u_int str_len) {
|
||||||
|
return(MurmurHash((void*)str, str_len, 0x87654321));
|
||||||
|
}
|
||||||
|
|
||||||
/* ******************************************************************** */
|
/* ******************************************************************** */
|
||||||
|
|
||||||
/* Based on djb2 hash - http://www.cse.yorku.ca/~oz/hash.html */
|
/* Based on djb2 hash - http://www.cse.yorku.ca/~oz/hash.html */
|
||||||
|
|||||||
Reference in New Issue
Block a user