From 24f5708081f58b7ff08f009e095388c76fb16f84 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 10 Jul 2024 14:20:33 +0000 Subject: [PATCH] Update to latest rust-lightning/dnssec-validator and fix warnings --- Cargo.toml | 4 ++-- src/lib.rs | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 00560d8..e89c308 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,8 @@ domain_resolver = ["lightning/std", "tokio/rt", "dnssec-prover/std"] name_resolver = ["dnssec-prover/validation", "lightning/no-std", "hex-conservative/alloc"] [dependencies] -lightning = { version = "0.0.121", default-features = false } -dnssec-prover = { version = "0.3", default-features = false } +lightning = { version = "0.0.123", default-features = false } +dnssec-prover = { version = "0.6", default-features = false } tokio = { version = "1.0", default-features = false, optional = true } hex-conservative = { version = "0.1", default-features = false, optional = true } diff --git a/src/lib.rs b/src/lib.rs index e5d2240..2fe6690 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ use std::sync::Mutex; // XXX: wont work without, should support no-std extern crate alloc; extern crate core; +#[cfg(feature = "name_resolver")] use core::str::FromStr; #[cfg(feature = "domain_resolver")] @@ -25,6 +26,7 @@ use dnssec_prover::query::build_txt_proof; use lightning::onion_message::packet::OnionMessageContents; use lightning::util::ser::{Readable, Writeable, Writer}; use lightning::ln::msgs::DecodeError; +#[cfg(feature = "name_resolver")] use lightning::offers::offer::Offer; #[cfg(any(feature = "domain_resolver", feature = "name_resolver"))] @@ -297,8 +299,8 @@ mod name_resolver { { const URI_PREFIX: &str = "bitcoin:"; let mut candidate_records = resolved_rrs.iter() - .filter_map(|rr| if let RR::Txt(txt) = rr { Some(&txt.data) } else { None }) - .filter_map(|data| if let Ok(s) = core::str::from_utf8(data) { Some(s) } else { None }) + .filter_map(|rr| if let RR::Txt(txt) = rr { Some(txt.data.as_vec()) } else { None }) + .filter_map(|data| if let Ok(s) = String::from_utf8(data) { Some(s) } else { None }) .filter(|data_string| data_string.len() > URI_PREFIX.len()) .filter(|data_string| data_string[..URI_PREFIX.len()].eq_ignore_ascii_case(URI_PREFIX)); let txt_record = @@ -392,4 +394,34 @@ mod test { assert!(payer.handle_custom_message(response).is_none()); offer_ref.lock().unwrap().take().unwrap(); } + + #[test] + fn bast() { + let secp_ctx = Secp256k1::new(); + let dummy_pk = PublicKey::from_slice(&[2; 33]).unwrap(); + + let resolver = OMDomainResolver::new("1.1.1.1:53".parse().unwrap()); + + let resolver_keys = KeysManager::new(&[0; 32], 42, 43); + let resolver_dest = Destination::Node(dummy_pk); + let payer_path = + BlindedPath::one_hop_for_message(dummy_pk, &resolver_keys, &secp_ctx).unwrap(); + let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs(); + let payer = OMNameResolver::new(resolver_dest.clone(), payer_path.clone(), now as u32, 1); + + let resolved_offer = Arc::new(Mutex::new(None)); + let offer_ref = Arc::clone(&resolved_offer); + let resolve_offer = Box::new(move |offer| *resolved_offer.lock().unwrap() = offer); + payer.resolve_name("me@t-bast.xyz".to_owned(), resolve_offer).unwrap(); + let mut msgs = payer.release_pending_custom_messages(); + assert_eq!(msgs.len(), 1); + + let msg = msgs.pop().unwrap(); + assert_eq!(msg.destination, resolver_dest); + assert_eq!(msg.reply_path, Some(payer_path)); + let response = resolver.handle_custom_message(msg.contents).unwrap(); + + assert!(payer.handle_custom_message(response).is_none()); + offer_ref.lock().unwrap().take().unwrap(); + } } -- 2.39.5