Improvement for reducing false positives
This commit is contained in:
@@ -5473,6 +5473,19 @@ void domainSearchUnitTest() {
|
|||||||
|
|
||||||
/* *********************************************** */
|
/* *********************************************** */
|
||||||
|
|
||||||
|
void domainSearchUnitTest2() {
|
||||||
|
ndpi_domain_classify *c = ndpi_domain_classify_alloc();
|
||||||
|
u_int16_t class_id = 9;
|
||||||
|
|
||||||
|
ndpi_domain_classify_add(c, class_id, "ntop.org");
|
||||||
|
ndpi_domain_classify_add(c, class_id, "apple.com");
|
||||||
|
|
||||||
|
assert(ndpi_domain_classify_contains(c,"ntop.com") == 0);
|
||||||
|
ndpi_domain_classify_free(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* *********************************************** */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief MAIN FUNCTION
|
@brief MAIN FUNCTION
|
||||||
**/
|
**/
|
||||||
@@ -5513,6 +5526,7 @@ int main(int argc, char **argv) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
domainSearchUnitTest();
|
domainSearchUnitTest();
|
||||||
|
domainSearchUnitTest2();
|
||||||
sketchUnitTest();
|
sketchUnitTest();
|
||||||
linearUnitTest();
|
linearUnitTest();
|
||||||
zscoreUnitTest();
|
zscoreUnitTest();
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ static u_int32_t ndpi_domain_search_size(ndpi_domain_search *search) {
|
|||||||
/* NOTE: domain will be modified: copy it if necessary */
|
/* NOTE: domain will be modified: copy it if necessary */
|
||||||
static bool ndpi_domain_search_add(ndpi_domain_search *search, char *domain) {
|
static bool ndpi_domain_search_add(ndpi_domain_search *search, char *domain) {
|
||||||
char *elem;
|
char *elem;
|
||||||
u_int32_t bitmap_id = 0, len;
|
u_int32_t bitmap_id = 0, len, hsum = 0;
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
|
|
||||||
if(domain == NULL) return(false);
|
if(domain == NULL) return(false);
|
||||||
@@ -133,9 +133,9 @@ static bool ndpi_domain_search_add(ndpi_domain_search *search, char *domain) {
|
|||||||
h += END_OF_TOKENS_DELIMITER;
|
h += END_OF_TOKENS_DELIMITER;
|
||||||
}
|
}
|
||||||
|
|
||||||
ndpi_bitmap_set(search->bitmap[bitmap_id], h);
|
ndpi_bitmap_set(search->bitmap[bitmap_id], h + hsum);
|
||||||
|
|
||||||
bitmap_id++;
|
bitmap_id++, hsum += h;
|
||||||
|
|
||||||
if(quit)
|
if(quit)
|
||||||
break;
|
break;
|
||||||
@@ -158,7 +158,7 @@ static bool ndpi_domain_search_add(ndpi_domain_search *search, char *domain) {
|
|||||||
|
|
||||||
static bool ndpi_domain_search_contains(ndpi_domain_search *search, char *domain) {
|
static bool ndpi_domain_search_contains(ndpi_domain_search *search, char *domain) {
|
||||||
char *elem;
|
char *elem;
|
||||||
u_int32_t bitmap_id = 0;
|
u_int32_t bitmap_id = 0, hsum = 0;
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
|
|
||||||
if((elem = strrchr(domain, '.')) == NULL)
|
if((elem = strrchr(domain, '.')) == NULL)
|
||||||
@@ -171,16 +171,16 @@ static bool ndpi_domain_search_contains(ndpi_domain_search *search, char *domain
|
|||||||
|
|
||||||
h = ndpi_hash_string(elem);
|
h = ndpi_hash_string(elem);
|
||||||
|
|
||||||
if(!ndpi_bitmap_isset(search->bitmap[bitmap_id], h)) {
|
if(!ndpi_bitmap_isset(search->bitmap[bitmap_id], h + hsum)) {
|
||||||
/* Exact match does not work, so let's see if a partial match works instead */
|
/* Exact match does not work, so let's see if a partial match works instead */
|
||||||
|
|
||||||
/* 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;
|
||||||
|
|
||||||
return(ndpi_bitmap_isset(search->bitmap[bitmap_id], h));
|
return(ndpi_bitmap_isset(search->bitmap[bitmap_id], h + hsum));
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmap_id++;
|
bitmap_id++, hsum += h;
|
||||||
|
|
||||||
if(quit)
|
if(quit)
|
||||||
break;
|
break;
|
||||||
@@ -306,7 +306,7 @@ u_int32_t ndpi_domain_classify_add_domains(ndpi_domain_classify *_s,
|
|||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
s->class[i]->class_id = class_id;
|
s->class[i]->class_id = class_id;
|
||||||
s->class[i]->domains = ndpi_domain_search_alloc();
|
s->class[i]->domains = ndpi_domain_search_alloc();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user