Skip to content

Commit b0c55cd

Browse files
committed
f accept a handle argument
1 parent 3084b60 commit b0c55cd

File tree

1 file changed

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

1 file changed

+22
-1
lines changed

lightning-dns-resolver/src/lib.rs

+22-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,36 @@ 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(resolver, proof_handler, 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(
84+
resolver: SocketAddr, proof_handler: Option<PH>, runtime_handle: Handle,
85+
) -> Self {
6686
Self {
6787
state: Arc::new(OMResolverState {
6888
resolver,
6989
pending_replies: Mutex::new(Vec::new()),
7090
pending_query_count: AtomicUsize::new(0),
7191
}),
7292
proof_handler,
93+
runtime_handle,
7394
}
7495
}
7596
}
@@ -96,7 +117,7 @@ where
96117
return None;
97118
}
98119
let us = Arc::clone(&self.state);
99-
tokio::spawn(async move {
120+
self.runtime_handle.spawn(async move {
100121
if let Ok((proof, _ttl)) = build_txt_proof_async(us.resolver, &q.0).await {
101122
let contents = DNSResolverMessage::DNSSECProof(DNSSECProof { name: q.0, proof });
102123
let instructions = responder.respond().into_instructions();

0 commit comments

Comments
 (0)