Skip to content

feat(namesys): propagate DNSLink TXT TTL#1167

Open
lidel wants to merge 2 commits into
mainfrom
feat/dnslink-ttl
Open

feat(namesys): propagate DNSLink TXT TTL#1167
lidel wants to merge 2 commits into
mainfrom
feat/dnslink-ttl

Conversation

@lidel
Copy link
Copy Markdown
Member

@lidel lidel commented Jun 3, 2026

Problem

boxo's DNS resolver discards the TTL of DNSLink TXT records and returns 0. The gateway sets Cache-Control: max-age for mutable paths only when the TTL is non-zero, so DNSLink (/ipns/<dnslink-host>) responses go out with no max-age and fall back to a static value, even though the TXT record states exactly how long the mapping is valid (#329). Recursive names made it worse: a name resolved through several records was cached for only its final hop's TTL, ignoring shorter-lived links earlier in the chain.

Fix

  • Carry the TXT record TTL into the resolved result (AsyncResult.TTL / Result.TTL), which the gateway already turns into Cache-Control: max-age.
  • Add NewDNSResolverWithTTL, WithDNSResolverWithTTL, and LookupTXTWithTTLFunc for a TTL-aware lookup. WithDNSResolver auto-detects a resolver that implements madns.TXTWithTTLResolver and uses it.
  • Cap a resolved name's TTL to its shortest hop, so a DNSLink pointing at an IPNS name, or a recursive IPNS chain, is not cached past its earliest-expiring link. Hops with an unknown TTL (0) are ignored.

NewDNSResolver and LookupTXTFunc keep their signatures and report an unknown TTL (0), so existing callers are unchanged; the new behavior stays inert until the resolver passed to WithDNSResolver actually reports TTLs.

Upstream PRs to land first

Required before this PR can build and merge:

Needed only to switch DNSLink Cache-Control on end-to-end (a separate follow-up boxo PR, not this one):

Part of #329. ETag for resolved paths (the issue's other half) is out of scope.

@lidel lidel requested a review from a team as a code owner June 3, 2026 16:56
@lidel lidel added the status/blocked Unable to be worked further until needs are met label Jun 3, 2026
@lidel lidel marked this pull request as draft June 3, 2026 17:01
The DNS resolver dropped the TXT record TTL, so a gateway could not set
Cache-Control max-age for DNSLink (/ipns/<dnslink-host>) responses, and a
recursive name was cached for only its final hop's TTL.

- add LookupTXTWithTTLFunc and NewDNSResolverWithTTL; LookupTXTFunc and
  NewDNSResolver keep their signatures and report an unknown TTL (0)
- carry the looked-up TTL into AsyncResult.TTL in the DNS resolver
- WithDNSResolver detects a resolver implementing
  multiformats/go-multiaddr-dns#75 TXTWithTTLResolver and propagates the
  TTL; add WithDNSResolverWithTTL for a TTL-aware lookup
- cap a resolved name's TTL to its shortest hop, so a DNSLink or
  recursive IPNS name is not cached past its earliest-expiring link

Refs #329
@lidel lidel force-pushed the feat/dnslink-ttl branch from b2590e2 to fe47cf2 Compare June 3, 2026 17:09
@lidel lidel marked this pull request as ready for review June 3, 2026 17:10
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 3, 2026

Codecov Report

❌ Patch coverage is 79.16667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.39%. Comparing base (fc2837e) to head (4a82052).

Files with missing lines Patch % Lines
namesys/namesys.go 37.50% 4 Missing and 1 partial ⚠️

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1167   +/-   ##
=======================================
  Coverage   63.39%   63.39%           
=======================================
  Files         268      268           
  Lines       26967    26987   +20     
=======================================
+ Hits        17096    17109   +13     
- Misses       8147     8153    +6     
- Partials     1724     1725    +1     
Files with missing lines Coverage Δ
namesys/dns_resolver.go 73.68% <100.00%> (+1.46%) ⬆️
namesys/utilities.go 94.04% <100.00%> (+3.25%) ⬆️
namesys/namesys.go 57.89% <37.50%> (-2.11%) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread namesys/utilities.go Outdated
drop the min from negative inputs so a negative TTL is never
returned; cover the negative cases in the test table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/blocked Unable to be worked further until needs are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants