From 231748bb0e6f274eb91824bf1e3b1693370ec0de Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Fri, 15 Mar 2024 10:12:51 +0100 Subject: 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. --- src/lib/protocols/mining.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/lib/protocols/mining.c') 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; } -- cgit v1.2.3