Added ndpi_murmur_hash to the nDPI API

This commit is contained in:
Luca Deri
2023-09-04 12:53:42 +02:00
parent f0dc3347ec
commit 4f2ce2d43b
3 changed files with 41 additions and 12 deletions
+1
View File
@@ -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);
/* ******************************* */ /* ******************************* */
+19
View File
@@ -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;
+9
View File
@@ -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 */