From ea0c10a5c10397be571316c5b33b0b5c30655667 Mon Sep 17 00:00:00 2001 From: "B. Blechschmidt" Date: Sun, 23 Jun 2024 20:37:26 +0200 Subject: [PATCH] Add more comments to virtual DNS implementation --- src/virtual_dns.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/virtual_dns.rs b/src/virtual_dns.rs index f470bfe..966ae5a 100644 --- a/src/virtual_dns.rs +++ b/src/virtual_dns.rs @@ -113,26 +113,32 @@ impl VirtualDns { let now = Instant::now(); + // Iterate through all entries of the LRU cache and remove those that have expired. loop { let (ip, entry) = match self.lru_cache.iter().next() { None => break, Some((ip, entry)) => (ip, entry), }; + + // The entry has expired. if now > entry.expiry { let name = entry.name.clone(); self.lru_cache.remove(&ip.clone()); self.name_to_ip.remove(&name); - continue; + continue; // There might be another expired entry after this one. } - break; + + break; // The entry has not expired and all following entries are newer. } + // Return the IP if it is stored inside our LRU cache. if let Some(ip) = self.name_to_ip.get(&insert_name) { let ip = *ip; self.touch_ip(&ip); return Ok(ip); } + // Otherwise, store name and IP pair inside the LRU cache. let started_at = self.next_addr; loop {