1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:27:45 +00:00

LookupServer: Do cache eviction when mDNS cache flush bit is set

This commit is contained in:
Gunnar Beutner 2021-05-09 16:49:23 +02:00 committed by Andreas Kling
parent edb21e02ea
commit 212cd9d8ac

View file

@ -296,8 +296,23 @@ void LookupServer::put_in_cache(const DNSAnswer& answer)
auto it = m_lookup_cache.find(answer.name());
if (it == m_lookup_cache.end())
m_lookup_cache.set(answer.name(), { answer });
else
else {
if (answer.mdns_cache_flush()) {
auto now = time(nullptr);
it->value.remove_all_matching([&](DNSAnswer const& other_answer) {
if (other_answer.type() != answer.type() || other_answer.class_code() != answer.class_code())
return false;
if (other_answer.received_time() >= now - 1)
return false;
dbgln_if(LOOKUPSERVER_DEBUG, "Removing cache entry: {}", other_answer.name());
return true;
});
}
it->value.append(answer);
}
}
}