DNS Discovery Crate
An isolated Rust crate for discovering Chia network peers using DNS introducers. This crate properly handles both IPv4 (A records) and IPv6 (AAAA records) lookups, returning separate lists for each protocol version.
Features
- π IPv4 Support: Performs A record DNS lookups for IPv4 addresses
- π IPv6 Support: Performs AAAA record DNS lookups for IPv6 addresses
- π Separate Results: Returns IPv4 and IPv6 peers in separate lists
- π² Randomization: Shuffles peer lists for load distribution
- π·οΈ Proper Formatting: IPv6 addresses are properly formatted with brackets for URL usage
- πΈοΈ Multiple Networks: Built-in support for Chia mainnet and testnet11
- π οΈ Customizable: Generic discovery for any list of DNS introducers
Usage
Basic Usage
use ;
async
Network-Specific Discovery
// Mainnet discovery
let mainnet_peers = discovery.discover_mainnet_peers.await?;
// Testnet11 discovery
let testnet_peers = discovery.discover_testnet11_peers.await?;
// Custom introducers
let custom_peers = discovery.discover_peers.await?;
Individual Protocol Lookups
// IPv4 only (A records)
let ipv4_addrs = discovery.resolve_ipv4.await?;
// IPv6 only (AAAA records)
let ipv6_addrs = discovery.resolve_ipv6.await?;
// Both protocols
let both = discovery.resolve_both.await?;
Data Structures
DiscoveryResult
Contains the results of DNS discovery:
PeerAddress
Represents a single peer address:
The display_address() method properly formats addresses:
- IPv4:
192.168.1.1:8444 - IPv6:
[2001:db8::1]:8444(with brackets)
Built-in DNS Introducers
Mainnet (port 8444)
dns-introducer.chia.netchia.ctrlaltdel.chseeder.dexie.spacechia.hoffmang.com
Testnet11 (port 58444)
dns-introducer-testnet11.chia.net
Key Differences from JavaScript Implementation
This Rust implementation provides several improvements over the JavaScript version in coin-monitor.js:
- Explicit Protocol Separation: Uses separate A and AAAA lookups instead of generic resolution
- Type Safety: Strongly typed IP addresses and error handling
- Proper IPv6 Formatting: Automatically handles bracket formatting for IPv6 URLs
- Performance: Concurrent DNS lookups with proper async/await
- Error Handling: Detailed error types with proper propagation
Running the Example
This will discover peers for both mainnet and testnet11, showing separate IPv4 and IPv6 results.
Testing
Tests include validation of DNS resolution, address formatting, and data structure operations.
Dependencies
tokio: Async runtimetrust-dns-resolver: DNS resolution with explicit A/AAAA record supportserde: Serialization support for data structuresthiserror: Error handlingtracing: Loggingrand: Peer list randomization