Skip to content

Commit 7018be4

Browse files
committed
f use struct for queries
1 parent 72a01c9 commit 7018be4

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

lightning/src/onion_message/dns_resolution.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,14 @@ impl Readable for HumanReadableName {
256256
}
257257
}
258258

259+
#[cfg(feature = "dnssec")]
260+
struct PendingResolution {
261+
start_height: u32,
262+
context: DNSResolverContext,
263+
name: HumanReadableName,
264+
payment_id: PaymentId,
265+
}
266+
259267
/// A stateful resolver which maps BIP 353 Human Readable Names to URIs and BOLT12 [`Offer`]s.
260268
///
261269
/// It does not directly implement [`DNSResolverMessageHandler`] but implements all the core logic
@@ -266,8 +274,7 @@ impl Readable for HumanReadableName {
266274
/// blocks.
267275
#[cfg(feature = "dnssec")]
268276
pub struct OMNameResolver {
269-
pending_resolves:
270-
Mutex<HashMap<Name, Vec<(u32, DNSResolverContext, HumanReadableName, PaymentId)>>>,
277+
pending_resolves: Mutex<HashMap<Name, Vec<PendingResolution>>>,
271278
latest_block_time: AtomicUsize,
272279
latest_block_height: AtomicUsize,
273280
}
@@ -292,15 +299,7 @@ impl OMNameResolver {
292299
self.latest_block_height.store(height as usize, Ordering::Release);
293300
let mut resolves = self.pending_resolves.lock().unwrap();
294301
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);
304303
!queries.is_empty()
305304
});
306305
}
@@ -323,9 +322,10 @@ impl OMNameResolver {
323322
);
324323
let name_query = dns_name.clone().map(|q| DNSSECQuery(q));
325324
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;
327326
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 };
329329
pending_resolves.entry(dns_name).or_insert_with(Vec::new).push(resolution);
330330
}
331331
name_query
@@ -381,7 +381,7 @@ impl OMNameResolver {
381381
let DNSSECProof { name: answer_name, proof } = msg;
382382
let mut pending_resolves = self.pending_resolves.lock().unwrap();
383383
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) {
385385
// If we don't have any pending queries with the context included in the blinded
386386
// path (implying someone sent us this response not using the blinded path we gave
387387
// when making the query), return immediately to avoid the extra time for the proof
@@ -432,7 +432,7 @@ impl OMNameResolver {
432432
match (candidate_records.next(), candidate_records.next()) {
433433
(Some(txt), None) => {
434434
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();
436436
return Some((completed_requests, txt));
437437
},
438438
_ => {},

0 commit comments

Comments
 (0)