From 5ce08521d57f72606d9e0b7bdc1ad227bf56b478 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 11 Aug 2022 21:38:36 -0700 Subject: [PATCH] ircd::net::dns: Perturb the minimum TTL to avoid groupings on expiration. --- ircd/net_dns.cc | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/ircd/net_dns.cc b/ircd/net_dns.cc index a13992d73..35b1fdd6b 100644 --- a/ircd/net_dns.cc +++ b/ircd/net_dns.cc @@ -239,24 +239,29 @@ bool ircd::net::dns::expired(const json::object &rr, const time_t &rr_ts) { - const seconds &min_seconds - { - cache::min_ttl - }; - - const seconds &err_seconds - { - cache::error_ttl - }; - - const time_t &min + const seconds base { is_error(rr)? - err_seconds.count(): - min_seconds.count() + seconds(cache::error_ttl): + seconds(cache::min_ttl) }; - return expired(rr, rr_ts, min); + const pair perturb_range + { + 1, base.count() / 3 + }; + + const seconds perturb + { + rand::integer(perturb_range.first, perturb_range.second) + }; + + const seconds min + { + base + perturb + }; + + return expired(rr, rr_ts, min.count()); } bool