Skip to content

Conversation

@lidel
Copy link
Member

@lidel lidel commented Jul 11, 2025

Problem: go-libp2p is sending both A and AAAA no matter if explicit /dns4 or /dns6 is present:

go-multiaddr-dns/resolve.go

Lines 150 to 154 in 2cbddc7

// XXX: Unfortunately, go does a pretty terrible job of
// differentiating between IPv6 and IPv4. A v4-in-v6
// AAAA record will _look_ like an A record to us and
// there's nothing we can do about that.
records, err := rslv.LookupIPAddr(ctx, value)

This PR aims to mitigate this for the most popular dns addr type (AutoTLS ones) by adding support for static (deterministic) domains to reduce the number of DNS queries for A and AAAA a libp2p node needs to make. Yes, we can't avoid them in web browsers, but we can avoid them in non-browser contexts like Go.

TLDR:

  • Implement synthetic offline resolution for p2p-forge protocol ref. https://github.com/ipshipyard/p2p-forge#handled-dns-records
  • 👉 Saves client from sending two DNS queries (A + AAAA) for each multiaddr with DNS name that follows p2p-forge convention
  • This is not hardcoding libp2p.direct, it supports any domain suffix with valid libp2p peer IDs in second position
  • This is backward and forward compatible: if domain turns out to be false-positive, it fallbacks to normal DNS resolver
  • This should not impact perf, we avoid expensive parsing if DNS labels are too short

cc @sukunrt @aschmahmann

- Implement synthetic offline resolution for p2p-forge protocol
  ref. https://github.com/ipshipyard/p2p-forge
- Support any domain suffix with valid libp2p peer IDs in second position
- If domain turns out to be false-positive, it fallbacks to normal DNS resolver
- Saves client from sending A/AAAA DNS query for each dns multiaddr that follows p2p-forge convention
- Avoid expensive parsing if DNS labels are too short
@lidel lidel requested review from MarcoPolo and sukunrt July 11, 2025 16:24
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.

2 participants