Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache: clip ttl to hour..ttl..week #212

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions cache/dns_cache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,21 @@ and 1035 6.2:
maximum value! *)
let week = Int32.of_int Duration.(to_sec (of_day 7))

let clip_ttl_to_week entry =
let min_ttl = Int32.of_int (Duration.(to_sec (of_hour 1)))

let clip_ttl_to_min_hour_max_week entry =
let ttl = get_ttl entry in
if ttl < week then entry else with_ttl week entry
if ttl < min_ttl
then with_ttl min_ttl entry
else if ttl >= week
then with_ttl week entry
else entry

let pp_query ppf (name, query_type) =
Fmt.pf ppf "%a (%a)" Domain_name.pp name Packet.Question.pp_qtype query_type

let set cache ts name query_type rank entry =
let entry' = clip_ttl_to_week entry in
let entry' = clip_ttl_to_min_hour_max_week entry in
let cache' map = insert cache ?map ts name query_type rank entry' in
match find cache name query_type with
| map, Error _ ->
Expand Down