1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! Configuration options for BIP-353 resolver
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
use std::time::Duration;
/// Configuration for BIP-353 resolver
#[derive(Debug, Clone)]
pub struct ResolverConfig {
/// The DNS resolver to use (IP and port)
pub dns_resolver: SocketAddr,
/// Whether to enforce DNSSEC validation
pub enforce_dnssec: bool,
/// Timeout for DNS queries in milliseconds
pub timeout_ms: u64,
/// Whether to allow HTTP resolution fallback
/// (for domains that don't support BIP-353 DNS but do support LN-Address)
pub allow_http_fallback: bool,
/// Network to use for parsing payment instructions
pub network: bitcoin::Network,
}
impl Default for ResolverConfig {
fn default() -> Self {
Self {
// Google DNS with DNSSEC support
dns_resolver: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)), 53),
enforce_dnssec: true,
timeout_ms: 5000, // 5 second timeout
allow_http_fallback: true,
network: bitcoin::Network::Bitcoin,
}
}
}
impl ResolverConfig {
/// Create a configuration for testnet
pub fn testnet() -> Self {
Self {
network: bitcoin::Network::Testnet,
..Default::default()
}
}
/// Create a configuration for signet
pub fn signet() -> Self {
Self {
network: bitcoin::Network::Signet,
..Default::default()
}
}
/// Create a configuration for regtest
pub fn regtest() -> Self {
Self {
network: bitcoin::Network::Regtest,
..Default::default()
}
}
/// Set the DNS resolver
pub fn with_dns_resolver(mut self, resolver: SocketAddr) -> Self {
self.dns_resolver = resolver;
self
}
/// Set the DNSSEC enforcement
pub fn with_dnssec(mut self, enforce: bool) -> Self {
self.enforce_dnssec = enforce;
self
}
/// Set the timeout
pub fn with_timeout(mut self, timeout: Duration) -> Self {
self.timeout_ms = timeout.as_millis() as u64;
self
}
/// Set whether to allow HTTP fallback
pub fn with_http_fallback(mut self, allow: bool) -> Self {
self.allow_http_fallback = allow;
self
}
/// Set the network
pub fn with_network(mut self, network: bitcoin::Network) -> Self {
self.network = network;
self
}
/// Get the timeout as a Duration
pub fn timeout(&self) -> Duration {
Duration::from_millis(self.timeout_ms)
}
}