Skip to content

Feature: Implement DNSADDR Protocol resolves addresses from a TXT record associated with the _dnsaddr subdomain #80

@acul71

Description

@acul71

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:

  1. Queries A and AAAA records from the domain (e.g., example.com)
  2. Converts IP addresses to /ip4/ or /ip6/ multiaddrs
  3. Ignores TXT records completely
  4. Does not parse dnsaddr= entries

✅ What the specification requires:

  1. Query TXT records from _dnsaddr.<domain> (e.g., _dnsaddr.example.com)
  2. Parse dnsaddr=<multiaddr> entries from TXT records
  3. Return the parsed multiaddrs as resolution results
  4. 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 a TXT record associated with the _dnsaddr subdomain of a given domain.

For example, resolving /dnsaddr/libp2p.io will perform a TXT lookup for _dnsaddr.libp2p.io. If the result contains entries of the form dnsaddr=<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:

  1. Query TXT records from _dnsaddr.example.com
  2. Parse entries starting with dnsaddr=
  3. Filter results to include the peer ID QmPeerId
  4. Return the matching multiaddrs
  5. If any returned multiaddr is itself a /dnsaddr/, recursively resolve it

Benefits

  1. Specification Compliance: Aligns with the official libp2p specification
  2. Interoperability: Ensures compatibility with other libp2p implementations
  3. Correct Functionality: Provides the intended dnsaddr resolution behavior
  4. 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.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions