Skip to content

Commit 4c1a03a

Browse files
committed
Wrap payment instructions parsing in tokio timeout
1 parent ec435ce commit 4c1a03a

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ enum NodeError {
325325
"AsyncPaymentServicesDisabled",
326326
"HrnParsingFailed",
327327
"HrnResolverNotConfigured",
328+
"TimeoutOccurred",
328329
};
329330

330331
dictionary NodeStatus {

src/builder.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,11 +1549,20 @@ fn build_with_store_internal(
15491549
})?;
15501550
}
15511551

1552-
let resolver = if config.is_hrn_resolver {
1553-
Resolver::DNS(Arc::new(OMDomainResolver::ignoring_incoming_proofs(
1554-
"8.8.8.8:53".parse().map_err(|_| BuildError::DNSResolverSetupFailed)?,
1555-
)))
1552+
let resolver = if let Some(hrn_config) = &config.hrn_config {
1553+
if hrn_config.is_hrn_resolver {
1554+
let dns_addr = hrn_config.dns_server_address.as_str();
1555+
1556+
Resolver::DNS(Arc::new(OMDomainResolver::ignoring_incoming_proofs(
1557+
dns_addr.parse().map_err(|_| BuildError::DNSResolverSetupFailed)?,
1558+
)))
1559+
} else {
1560+
Resolver::HRN(Arc::new(LDKOnionMessageDNSSECHrnResolver::new(Arc::clone(
1561+
&network_graph,
1562+
))))
1563+
}
15561564
} else {
1565+
// hrn_config is None, default to the HRN resolver.
15571566
Resolver::HRN(Arc::new(LDKOnionMessageDNSSECHrnResolver::new(Arc::clone(&network_graph))))
15581567
};
15591568

src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ pub enum Error {
129129
HrnParsingFailed,
130130
/// A HRN resolver was not configured
131131
HrnResolverNotConfigured,
132+
/// A Timeout occurred during an operation.
133+
TimeoutOccurred,
132134
}
133135

134136
impl fmt::Display for Error {
@@ -212,6 +214,9 @@ impl fmt::Display for Error {
212214
Self::HrnResolverNotConfigured => {
213215
write!(f, "A HRN resolver was not configured.")
214216
},
217+
Self::TimeoutOccurred => {
218+
write!(f, "A Timeout occured during an operation.")
219+
},
215220
}
216221
}
217222
}

src/payment/unified.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::payment::{Bolt11Payment, Bolt12Payment, OnchainPayment};
2121
use crate::types::HRNResolver;
2222
use crate::Config;
2323
use std::sync::Arc;
24+
use std::time::Duration;
2425
use std::vec::IntoIter;
2526

2627
use lightning::ln::channelmanager::PaymentId;
@@ -35,6 +36,7 @@ use bitcoin::{Amount, Txid};
3536
use bitcoin_payment_instructions::{
3637
amount::Amount as BPIAmount, PaymentInstructions, PaymentMethod,
3738
};
39+
use tokio::time::timeout;
3840

3941
type Uri<'a> = bip21::Uri<'a, NetworkChecked, Extras>;
4042

0 commit comments

Comments
 (0)