aboutsummaryrefslogtreecommitdiff
path: root/src/lib/protocols/mining.c
diff options
context:
space:
mode:
authorIvan Nardi <12729895+IvanNardi@users.noreply.github.com>2024-03-15 10:12:51 +0100
committerGitHub <noreply@github.com>2024-03-15 10:12:51 +0100
commit231748bb0e6f274eb91824bf1e3b1693370ec0de (patch)
treec770ac00021102d87d13f1af87aa05d2459699f1 /src/lib/protocols/mining.c
parent97fae6e00ad5b529ecc94a0bde2328da43426080 (diff)
LRU cache: move to 64 bits long keys (#2346)
Tradeoff between key comparison efficiency (i.e. no `memcmp`) and key length. At least in the ipv4 cases, we have no more different entries with the same key.
Diffstat (limited to 'src/lib/protocols/mining.c')
-rw-r--r--src/lib/protocols/mining.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/lib/protocols/mining.c b/src/lib/protocols/mining.c
index e6cdcf487..22d215927 100644
--- a/src/lib/protocols/mining.c
+++ b/src/lib/protocols/mining.c
@@ -28,14 +28,14 @@
/* ************************************************************************** */
-u_int32_t mining_make_lru_cache_key(struct ndpi_flow_struct *flow) {
- u_int32_t key;
+u_int64_t mining_make_lru_cache_key(struct ndpi_flow_struct *flow) {
+ u_int64_t key;
/* network byte order */
if(flow->is_ipv6)
- key = ndpi_quick_hash(flow->c_address.v6, 16) + ndpi_quick_hash(flow->s_address.v6, 16);
+ key = (ndpi_quick_hash64((const char *)flow->c_address.v6, 16) << 32) | (ndpi_quick_hash64((const char *)flow->s_address.v6, 16) & 0xFFFFFFFF);
else
- key = flow->c_address.v4 + flow->s_address.v4;
+ key = ((u_int64_t)flow->c_address.v4 << 32) | flow->s_address.v4;
return key;
}