@@ -21,6 +21,8 @@ use lightning::onion_message::messenger::{
21
21
MessageSendInstructions , Responder , ResponseInstruction ,
22
22
} ;
23
23
24
+ use tokio:: runtime:: Handle ;
25
+
24
26
#[ cfg( not( any( target_pointer_width = "32" , target_pointer_width = "64" ) ) ) ]
25
27
const WE_REQUIRE_32_OR_64_BIT_USIZE : u8 = 424242 ;
26
28
32
34
{
33
35
state : Arc < OMResolverState > ,
34
36
proof_handler : Option < PH > ,
37
+ runtime_handle : Handle ,
35
38
}
36
39
37
40
const MAX_PENDING_RESPONSES : usize = 1024 ;
@@ -58,18 +61,34 @@ where
58
61
/// Creates a new [`OMDomainResolver`] given the [`SocketAddr`] of a DNS resolver listening on
59
62
/// TCP (e.g. 8.8.8.8:53, 1.1.1.1:53 or your local DNS resolver).
60
63
///
64
+ /// Uses `tokio`'s [`Handle::current`] to fetch the async runtime on which futures will be
65
+ /// spawned.
66
+ ///
61
67
/// The optional `proof_handler` can be provided to pass proofs coming back to us to the
62
68
/// underlying handler. This is useful when this resolver is handling incoming resolution
63
69
/// requests but some other handler is making proof requests of remote nodes and wants to get
64
70
/// results.
65
71
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 {
66
84
Self {
67
85
state : Arc :: new ( OMResolverState {
68
86
resolver,
69
87
pending_replies : Mutex :: new ( Vec :: new ( ) ) ,
70
88
pending_query_count : AtomicUsize :: new ( 0 ) ,
71
89
} ) ,
72
90
proof_handler,
91
+ runtime_handle,
73
92
}
74
93
}
75
94
}
96
115
return None ;
97
116
}
98
117
let us = Arc :: clone ( & self . state ) ;
99
- tokio :: spawn ( async move {
118
+ self . runtime_handle . spawn ( async move {
100
119
if let Ok ( ( proof, _ttl) ) = build_txt_proof_async ( us. resolver , & q. 0 ) . await {
101
120
let contents = DNSResolverMessage :: DNSSECProof ( DNSSECProof { name : q. 0 , proof } ) ;
102
121
let instructions = responder. respond ( ) . into_instructions ( ) ;
0 commit comments