Skip to content

Commit 01ddd06

Browse files
committed
f accept a handle argument
1 parent e524863 commit 01ddd06

File tree

1 file changed

+20
-1
lines changed
  • lightning-dns-resolver/src

1 file changed

+20
-1
lines changed

lightning-dns-resolver/src/lib.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use lightning::onion_message::messenger::{
2121
MessageSendInstructions, Responder, ResponseInstruction,
2222
};
2323

24+
use tokio::runtime::Handle;
25+
2426
#[cfg(not(any(target_pointer_width = "32", target_pointer_width = "64")))]
2527
const WE_REQUIRE_32_OR_64_BIT_USIZE: u8 = 424242;
2628

@@ -32,6 +34,7 @@ where
3234
{
3335
state: Arc<OMResolverState>,
3436
proof_handler: Option<PH>,
37+
runtime_handle: Handle,
3538
}
3639

3740
const MAX_PENDING_RESPONSES: usize = 1024;
@@ -58,18 +61,34 @@ where
5861
/// Creates a new [`OMDomainResolver`] given the [`SocketAddr`] of a DNS resolver listening on
5962
/// TCP (e.g. 8.8.8.8:53, 1.1.1.1:53 or your local DNS resolver).
6063
///
64+
/// Uses `tokio`'s [`Handle::current`] to fetch the async runtime on which futures will be
65+
/// spawned.
66+
///
6167
/// The optional `proof_handler` can be provided to pass proofs coming back to us to the
6268
/// underlying handler. This is useful when this resolver is handling incoming resolution
6369
/// requests but some other handler is making proof requests of remote nodes and wants to get
6470
/// results.
6571
pub fn new(resolver: SocketAddr, proof_handler: Option<PH>) -> Self {
72+
Self::with_runtime(Handle::current())
73+
}
74+
75+
/// Creates a new [`OMDomainResolver`] given the [`SocketAddr`] of a DNS resolver listening on
76+
/// TCP (e.g. 8.8.8.8:53, 1.1.1.1:53 or your local DNS resolver) and a `tokio` runtime
77+
/// [`Handle`] on which futures will be spawned.
78+
///
79+
/// The optional `proof_handler` can be provided to pass proofs coming back to us to the
80+
/// underlying handler. This is useful when this resolver is handling incoming resolution
81+
/// requests but some other handler is making proof requests of remote nodes and wants to get
82+
/// results.
83+
pub fn with_runtime(resolver: SocketAddr, proof_handler: Option<PH>, runtime_handle: Handle) -> Self {
6684
Self {
6785
state: Arc::new(OMResolverState {
6886
resolver,
6987
pending_replies: Mutex::new(Vec::new()),
7088
pending_query_count: AtomicUsize::new(0),
7189
}),
7290
proof_handler,
91+
runtime_handle,
7392
}
7493
}
7594
}
@@ -96,7 +115,7 @@ where
96115
return None;
97116
}
98117
let us = Arc::clone(&self.state);
99-
tokio::spawn(async move {
118+
self.runtime_handle.spawn(async move {
100119
if let Ok((proof, _ttl)) = build_txt_proof_async(us.resolver, &q.0).await {
101120
let contents = DNSResolverMessage::DNSSECProof(DNSSECProof { name: q.0, proof });
102121
let instructions = responder.respond().into_instructions();

0 commit comments

Comments
 (0)