@@ -256,6 +256,14 @@ impl Readable for HumanReadableName {
256
256
}
257
257
}
258
258
259
+ #[ cfg( feature = "dnssec" ) ]
260
+ struct PendingResolution {
261
+ start_height : u32 ,
262
+ context : DNSResolverContext ,
263
+ name : HumanReadableName ,
264
+ payment_id : PaymentId ,
265
+ }
266
+
259
267
/// A stateful resolver which maps BIP 353 Human Readable Names to URIs and BOLT12 [`Offer`]s.
260
268
///
261
269
/// It does not directly implement [`DNSResolverMessageHandler`] but implements all the core logic
@@ -266,8 +274,7 @@ impl Readable for HumanReadableName {
266
274
/// blocks.
267
275
#[ cfg( feature = "dnssec" ) ]
268
276
pub struct OMNameResolver {
269
- pending_resolves :
270
- Mutex < HashMap < Name , Vec < ( u32 , DNSResolverContext , HumanReadableName , PaymentId ) > > > ,
277
+ pending_resolves : Mutex < HashMap < Name , Vec < PendingResolution > > > ,
271
278
latest_block_time : AtomicUsize ,
272
279
latest_block_height : AtomicUsize ,
273
280
}
@@ -292,15 +299,7 @@ impl OMNameResolver {
292
299
self . latest_block_height . store ( height as usize , Ordering :: Release ) ;
293
300
let mut resolves = self . pending_resolves . lock ( ) . unwrap ( ) ;
294
301
resolves. retain ( |_, queries| {
295
- queries. retain_mut (
296
- |( res_height, _, _, _) | {
297
- if * res_height < height - 1 {
298
- false
299
- } else {
300
- true
301
- }
302
- } ,
303
- ) ;
302
+ queries. retain ( |query| query. start_height >= height - 1 ) ;
304
303
!queries. is_empty ( )
305
304
} ) ;
306
305
}
@@ -323,9 +322,10 @@ impl OMNameResolver {
323
322
) ;
324
323
let name_query = dns_name. clone ( ) . map ( |q| DNSSECQuery ( q) ) ;
325
324
if let Ok ( dns_name) = dns_name {
326
- let height = self . latest_block_height . load ( Ordering :: Acquire ) ;
325
+ let start_height = self . latest_block_height . load ( Ordering :: Acquire ) as u32 ;
327
326
let mut pending_resolves = self . pending_resolves . lock ( ) . unwrap ( ) ;
328
- let resolution = ( height as u32 , random_context, name, payment_id) ;
327
+ let context = random_context;
328
+ let resolution = PendingResolution { start_height, context, name, payment_id } ;
329
329
pending_resolves. entry ( dns_name) . or_insert_with ( Vec :: new) . push ( resolution) ;
330
330
}
331
331
name_query
@@ -381,7 +381,7 @@ impl OMNameResolver {
381
381
let DNSSECProof { name : answer_name, proof } = msg;
382
382
let mut pending_resolves = self . pending_resolves . lock ( ) . unwrap ( ) ;
383
383
if let hash_map:: Entry :: Occupied ( entry) = pending_resolves. entry ( answer_name) {
384
- if !entry. get ( ) . iter ( ) . any ( |query| query. 1 == context) {
384
+ if !entry. get ( ) . iter ( ) . any ( |query| query. context == context) {
385
385
// If we don't have any pending queries with the context included in the blinded
386
386
// path (implying someone sent us this response not using the blinded path we gave
387
387
// when making the query), return immediately to avoid the extra time for the proof
@@ -432,7 +432,7 @@ impl OMNameResolver {
432
432
match ( candidate_records. next ( ) , candidate_records. next ( ) ) {
433
433
( Some ( txt) , None ) => {
434
434
let completed_requests =
435
- requests. into_iter ( ) . map ( |( _ , _ , id , name ) | ( id , name ) ) . collect ( ) ;
435
+ requests. into_iter ( ) . map ( |r | ( r . name , r . payment_id ) ) . collect ( ) ;
436
436
return Some ( ( completed_requests, txt) ) ;
437
437
} ,
438
438
_ => { } ,
0 commit comments