summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-09 16:49:23 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-10 17:26:17 +0200
commit212cd9d8acf8b4d6a76597f0ea8bf5ae3dbb8555 (patch)
treeb062827d28da5b786a38612d5503409418d37a8a /Userland/Services
parentedb21e02ea8ed69aee8f07f4d3129c2a9ca1d9ef (diff)
downloadserenity-212cd9d8acf8b4d6a76597f0ea8bf5ae3dbb8555.zip
LookupServer: Do cache eviction when mDNS cache flush bit is set
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/LookupServer/LookupServer.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/Userland/Services/LookupServer/LookupServer.cpp b/Userland/Services/LookupServer/LookupServer.cpp
index 46eec69369..5a3cb01360 100644
--- a/Userland/Services/LookupServer/LookupServer.cpp
+++ b/Userland/Services/LookupServer/LookupServer.cpp
@@ -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);
+ }
}
}