go-multiaddr-dns
go-multiaddr-dns copied to clipboard
feat: static resolution of p2p-forge domains
Problem: go-libp2p is sending both A and AAAA no matter if explicit /dns4 or /dns6 is present:
https://github.com/multiformats/go-multiaddr-dns/blob/2cbddc7ac862972e59b8abbc28ca53c8199c9e54/resolve.go#L150-L154
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
- :point_right: 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