Skip to content

feat: add LookupTXTWithTTL to expose TXT record TTL#33

Open
lidel wants to merge 1 commit into
masterfrom
feat/lookup-txt-with-ttl
Open

feat: add LookupTXTWithTTL to expose TXT record TTL#33
lidel wants to merge 1 commit into
masterfrom
feat/lookup-txt-with-ttl

Conversation

@lidel
Copy link
Copy Markdown
Member

@lidel lidel commented Jun 3, 2026

Problem

LookupTXT computes the TXT record TTL (the smallest Hdr.Ttl across the answer) to size its internal cache, then throws it away before returning. Callers get the records but no indication of how long they are valid.

This blocks IPFS gateways from setting Cache-Control: max-age=<ttl> for DNSLink based on the DNS record's real TTL. DNSLink resolution flows through this resolver, but the TTL is lost at the LookupTXT boundary, so a boxo/gateway library (used by IPFS Desktop, Kubo, Rainbow, ipfs.io etc) emits no Cache-Control for /ipns/<dnslink-host> responses and falls back to a static value. See ipfs/boxo#329 and the path-gateway spec's Cache-Control section [1]; tracked for Kubo under ipfs/kubo#8717.

Fix

  • Add LookupTXTWithTTL(ctx, domain) ([]string, time.Duration, error), returning the records plus their TTL.
  • LookupTXT now delegates to it, so its behavior is unchanged and the resolver still satisfies madns.BasicResolver (the new method is additive).
  • On a cache hit, the returned TTL is the remaining lifetime of the cached entry, so it shrinks with age instead of over-reporting the original value.
  • The TTL is capped by the resolver's max cache TTL (WithMaxCacheTTL); a TTL of 0 means unknown.

This lets consumers such as boxo/namesys thread the DNS TTL through to the gateway's Cache-Control. A follow-up boxo change will consume it via a new TTL-aware lookup option.

[1] https://specs.ipfs.tech/http-gateways/path-gateway/#cache-control-response-header

LookupTXT discarded the TTL that doRequestTXT already computes from the
DNS answer, so callers had no way to learn how long a TXT record set is
valid. This blocks consumers (e.g. a gateway resolving DNSLink) from
setting Cache-Control max-age based on the real DNS TTL.

Add LookupTXTWithTTL which returns the records plus their TTL. LookupTXT
delegates to it so behavior is unchanged. On a cache hit the remaining
lifetime is returned so the value does not over-report as the entry
ages, and it is capped by the resolver max cache TTL. A TTL of 0 means
unknown.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant