Skip to content

Commit 7a90e84

Browse files
committed
Allow setting default DNS resolvers for HRNs
1 parent 62284c7 commit 7a90e84

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/builder.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use lightning::routing::scoring::{
4747
ProbabilisticScorer, ProbabilisticScoringDecayParameters, ProbabilisticScoringFeeParameters,
4848
};
4949
use lightning::sign::EntropySource;
50+
use lightning::onion_message::messenger::Destination;
5051

5152
use lightning::util::persist::{
5253
read_channel_monitors, CHANNEL_MANAGER_PERSISTENCE_KEY,
@@ -459,6 +460,12 @@ impl NodeBuilder {
459460
Ok(self)
460461
}
461462

463+
/// Sets the default dns_resolvers to be used when sending payments to HRNs.
464+
pub fn set_dns_resolvers(&mut self, dns_resolvers: Vec<Destination>) -> Result<&mut Self, BuildError> {
465+
self.config.dns_resolvers = Some(dns_resolvers);
466+
Ok(self)
467+
}
468+
462469
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
463470
/// previously configured.
464471
pub fn build(&self) -> Result<Node, BuildError> {

src/config.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::logger::LogLevel;
1111
use crate::payment::SendingParameters;
1212

1313
use lightning::ln::msgs::SocketAddress;
14+
use lightning::onion_message::messenger::Destination;
1415
use lightning::routing::gossip::NodeAlias;
1516
use lightning::util::config::ChannelConfig as LdkChannelConfig;
1617
use lightning::util::config::MaxDustHTLCExposure as LdkMaxDustHTLCExposure;
@@ -103,7 +104,8 @@ pub const WALLET_KEYS_SEED_LEN: usize = 64;
103104
/// | `log_level` | Debug |
104105
/// | `anchor_channels_config` | Some(..) |
105106
/// | `sending_parameters` | None |
106-
///
107+
/// | `dns_resolvers` | None |
108+
///
107109
/// See [`AnchorChannelsConfig`] and [`SendingParameters`] for more information regarding their
108110
/// respective default values.
109111
///
@@ -167,6 +169,11 @@ pub struct Config {
167169
/// **Note:** If unset, default parameters will be used, and you will be able to override the
168170
/// parameters on a per-payment basis in the corresponding method calls.
169171
pub sending_parameters: Option<SendingParameters>,
172+
/// The dns_resolver nodes (Destinations) to be used for resolving Human-readable Names.
173+
///
174+
/// If set to `Some`, the values set will be used as dns_resolvers when sending to HRNs.
175+
/// **Note:** If set to `None`, payments to HRNs will fail.
176+
pub dns_resolvers: Option<Vec<Destination>>,
170177
}
171178

172179
impl Default for Config {
@@ -181,6 +188,7 @@ impl Default for Config {
181188
anchor_channels_config: Some(AnchorChannelsConfig::default()),
182189
sending_parameters: None,
183190
node_alias: None,
191+
dns_resolvers: None,
184192
}
185193
}
186194
}

src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ pub enum Error {
122122
LiquidityFeeTooHigh,
123123
/// Parsing a Human-Readable Name has failed
124124
HrnParsingFailed,
125+
/// The given operation failed due to `dns-resolvers` not being configured in builder.
126+
DnsResolversNotConfigured,
125127
}
126128

127129
impl fmt::Display for Error {
@@ -198,6 +200,9 @@ impl fmt::Display for Error {
198200
Self::HrnParsingFailed => {
199201
write!(f, "Failed to parse a human-readable name.")
200202
},
203+
Self::DnsResolversNotConfigured => {
204+
write!(f, "The given operation failed due to `dns-resolvers` not being configured in builder.")
205+
},
201206
}
202207
}
203208
}

0 commit comments

Comments
 (0)