LRU caches: add a generic (optional and configurable) expiration logic (#1855)

Two caches already implemented a similar mechanism: make it generic.
This commit is contained in:
Ivan Nardi
2023-01-18 18:18:36 +01:00
committed by GitHub
parent de24206adc
commit 1b98bec0ab
12 changed files with 196 additions and 63 deletions
+5 -3
View File
@@ -63,7 +63,7 @@ void ndpi_search_ookla(struct ndpi_detection_module_struct* ndpi_struct, struct
#ifdef OOKLA_DEBUG
printf("=>>>>>>>> [OOKLA IPv6] Adding %u\n", h);
#endif
ndpi_lru_add_to_cache(ndpi_struct->ookla_cache, h, 1 /* dummy */);
ndpi_lru_add_to_cache(ndpi_struct->ookla_cache, h, 1 /* dummy */, ndpi_get_current_time(flow));
}
return;
} else {
@@ -79,7 +79,8 @@ void ndpi_search_ookla(struct ndpi_detection_module_struct* ndpi_struct, struct
printf("=>>>>>>>> [OOKLA IPv6] Searching %u\n", h);
#endif
if(ndpi_lru_find_cache(ndpi_struct->ookla_cache, h, &dummy, 0 /* Don't remove it as it can be used for other connections */)) {
if(ndpi_lru_find_cache(ndpi_struct->ookla_cache, h, &dummy, 0 /* Don't remove it as it can be used for other connections */,
ndpi_get_current_time(flow))) {
NDPI_LOG_INFO(ndpi_struct, "found ookla tcp connection\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_CACHE);
#ifdef OOKLA_DEBUG
@@ -110,7 +111,8 @@ void ndpi_search_ookla(struct ndpi_detection_module_struct* ndpi_struct, struct
if(ndpi_struct->ookla_cache != NULL) {
u_int16_t dummy;
if(ndpi_lru_find_cache(ndpi_struct->ookla_cache, addr, &dummy, 0 /* Don't remove it as it can be used for other connections */)) {
if(ndpi_lru_find_cache(ndpi_struct->ookla_cache, addr, &dummy, 0 /* Don't remove it as it can be used for other connections */,
ndpi_get_current_time(flow))) {
NDPI_LOG_INFO(ndpi_struct, "found ookla tcp connection\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_CACHE);
#ifdef OOKLA_DEBUG