mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:17:35 +00:00
LookupServer: Do cache eviction when mDNS cache flush bit is set
This commit is contained in:
parent
edb21e02ea
commit
212cd9d8ac
1 changed files with 16 additions and 1 deletions
|
@ -296,8 +296,23 @@ void LookupServer::put_in_cache(const DNSAnswer& answer)
|
||||||
auto it = m_lookup_cache.find(answer.name());
|
auto it = m_lookup_cache.find(answer.name());
|
||||||
if (it == m_lookup_cache.end())
|
if (it == m_lookup_cache.end())
|
||||||
m_lookup_cache.set(answer.name(), { answer });
|
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);
|
it->value.append(answer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue