By default the decayed TTL is considered as 'expiring' when it
is in the last 1% of its lifetime, or shorter than 5 seconds.
/** Record is expiring if it has less than 1% TTL (or less than 5s) */
-static inline bool is_expiring(uint32_t orig_ttl, uint32_t new_ttl)
+static inline bool is_expiring(uint32_t orig_ttl, uint32_t decayed_ttl)
{
- int64_t nttl = new_ttl; /* avoid potential over/under-flow */
- return 100 * (nttl - 5) < orig_ttl;
+ if (decayed_ttl < 5) {
+ return true;
+ }
+
+ return decayed_ttl <= (orig_ttl * KR_CACHE_EXPIRING_THRESHOLD) / 100;
}
/** Returns signed result so you can inspect how much stale the RR is.
#define KR_EDNS_PAYLOAD 4096 /* Default UDP payload (max unfragmented UDP is 1452B) */
#define KR_CACHE_DEFAULT_TTL_MIN (5) /* avoid bursts of queries */
#define KR_CACHE_DEFAULT_TTL_MAX (6 * 24 * 3600) /* 6 days, like the root NS TTL */
+#ifndef KR_CACHE_EXPIRING_THRESHOLD
+#define KR_CACHE_EXPIRING_THRESHOLD 1 /* When decayed TTL is in its last N%, it's considered expiring. */
+#endif
#define KR_DNAME_STR_MAXLEN (KNOT_DNAME_TXT_MAXLEN + 1)
#define KR_RRTYPE_STR_MAXLEN (16 + 1)