-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Feature: Implement DNSADDR Protocol resolves addresses from a TXT record associated with the _dnsaddr subdomain
Overview
The current implementation of the dnsaddr
protocol in py-multiaddr does not follow the libp2p specification. The current implementation incorrectly resolves /dnsaddr/
addresses by querying A/AAAA records instead of TXT records, and converts IP addresses to multiaddrs instead of parsing dnsaddr=
entries from TXT records.
Current Implementation Issues
❌ What the current implementation does:
- Queries A and AAAA records from the domain (e.g.,
example.com
) - Converts IP addresses to
/ip4/
or/ip6/
multiaddrs - Ignores TXT records completely
- Does not parse
dnsaddr=
entries
✅ What the specification requires:
- Query TXT records from
_dnsaddr.<domain>
(e.g.,_dnsaddr.example.com
) - Parse
dnsaddr=<multiaddr>
entries from TXT records - Return the parsed multiaddrs as resolution results
- Support recursive resolution for nested dnsaddr entries
Specification Reference
According to the libp2p addressing specification:
A libp2p-specific DNS-backed format,
/dnsaddr
resolves addresses from aTXT
record associated with the_dnsaddr
subdomain of a given domain.
For example, resolving
/dnsaddr/libp2p.io
will perform aTXT
lookup for_dnsaddr.libp2p.io
. If the result contains entries of the formdnsaddr=<multiaddr>
, the embedded multiaddrs will be parsed and used.
Example from the specification:
> dig +short _dnsaddr.am6.bootstrap.libp2p.io txt
"dnsaddr=/dns6/am6.bootstrap.libp2p.io/tcp/443/wss/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb"
"dnsaddr=/ip4/147.75.87.27/tcp/4001/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb"
Implementation Plan
1. Update DNS Resolver
Modify multiaddr/resolvers/dns.py
to implement proper dnsaddr resolution:
- Query TXT records from
_dnsaddr.<hostname>
- Parse
dnsaddr=<multiaddr>
entries - Support recursive resolution with depth limiting
- Filter by peer ID if present in original multiaddr
2. Reference Implementation
The JavaScript implementation in js-multiaddr
already follows the specification correctly and can serve as a reference:
- File:
src/resolvers/dnsaddr.ts
- Queries
_dnsaddr.<hostname>
for TXT records - Parses
dnsaddr=<multiaddr>
entries - Supports recursive resolution with depth limiting
- Returns parsed multiaddrs, not IP addresses
3. Expected Behavior
For a multiaddr like /dnsaddr/example.com/p2p/QmPeerId
:
- Query TXT records from
_dnsaddr.example.com
- Parse entries starting with
dnsaddr=
- Filter results to include the peer ID
QmPeerId
- Return the matching multiaddrs
- If any returned multiaddr is itself a
/dnsaddr/
, recursively resolve it
Benefits
- Specification Compliance: Aligns with the official libp2p specification
- Interoperability: Ensures compatibility with other libp2p implementations
- Correct Functionality: Provides the intended dnsaddr resolution behavior
- Future-Proof: Follows the established standard for dnsaddr protocol
Testing
The implementation should be tested with real dnsaddr records, such as:
/dnsaddr/bootstrap.libp2p.io
/dnsaddr/example.com/p2p/QmPeerId
And should correctly resolve to the multiaddrs specified in the corresponding _dnsaddr.<domain>
TXT records.