From: Valentine Wallace Date: Wed, 3 Aug 2022 15:42:54 +0000 (-0400) Subject: Expose onion message module as public X-Git-Tag: v0.0.111~20^2~3 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0b1f476b83756bb9667cb9c54186669ac1f16f74;p=rust-lightning Expose onion message module as public And fix warnings --- diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index 199a3cbee..1000966d5 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -79,11 +79,7 @@ pub mod util; pub mod chain; pub mod ln; pub mod routing; -#[cfg(fuzzing)] pub mod onion_message; -#[cfg(not(fuzzing))] -#[allow(unused)] -mod onion_message; // To be exposed after sending/receiving OMs is supported in PeerManager. #[cfg(feature = "std")] /// Re-export of either `core2::io` or `std::io`, depending on the `std` feature flag. diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index 5a83a0b2b..001d96e83 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -124,7 +124,7 @@ fn too_big_packet_error() { #[test] fn invalid_blinded_route_error() { // Make sure we error as expected if a provided blinded route has 0 or 1 hops. - let mut nodes = create_nodes(3); + let nodes = create_nodes(3); // 0 hops let secp_ctx = Secp256k1::new(); @@ -143,7 +143,7 @@ fn invalid_blinded_route_error() { #[test] fn reply_path() { - let mut nodes = create_nodes(4); + let nodes = create_nodes(4); let secp_ctx = Secp256k1::new(); // Destination::Node diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index 75eb4619b..3a14c78d0 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -24,7 +24,6 @@ use super::utils; use util::events::OnionMessageProvider; use util::logger::Logger; -use core::mem; use core::ops::Deref; use sync::{Arc, Mutex}; use prelude::*; @@ -35,9 +34,7 @@ use prelude::*; /// /// # Example /// -// Needs to be `ignore` until the `onion_message` module is made public, otherwise this is a test -// failure. -/// ```ignore +/// ``` /// # extern crate bitcoin; /// # use bitcoin::hashes::_export::_core::time::Duration; /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; @@ -66,7 +63,8 @@ use prelude::*; /// /// // Send an empty onion message to a node id. /// let intermediate_hops = [hop_node_id1, hop_node_id2]; -/// onion_messenger.send_onion_message(&intermediate_hops, Destination::Node(destination_node_id)); +/// let reply_path = None; +/// onion_messenger.send_onion_message(&intermediate_hops, Destination::Node(destination_node_id), reply_path); /// /// // Create a blinded route to yourself, for someone to send an onion message to. /// # let your_node_id = hop_node_id1; @@ -75,7 +73,8 @@ use prelude::*; /// /// // Send an empty onion message to a blinded route. /// # let intermediate_hops = [hop_node_id1, hop_node_id2]; -/// onion_messenger.send_onion_message(&intermediate_hops, Destination::BlindedRoute(blinded_route)); +/// let reply_path = None; +/// onion_messenger.send_onion_message(&intermediate_hops, Destination::BlindedRoute(blinded_route), reply_path); /// ``` /// /// [offers]: diff --git a/lightning/src/onion_message/packet.rs b/lightning/src/onion_message/packet.rs index 4ab53735e..1337bdb14 100644 --- a/lightning/src/onion_message/packet.rs +++ b/lightning/src/onion_message/packet.rs @@ -74,7 +74,7 @@ impl LengthReadable for Packet { while read_idx < hop_data_len { let mut read_buffer = [0; READ_BUFFER_SIZE]; let read_amt = cmp::min(hop_data_len - read_idx, READ_BUFFER_SIZE); - r.read_exact(&mut read_buffer[..read_amt]); + r.read_exact(&mut read_buffer[..read_amt])?; hop_data.extend_from_slice(&read_buffer[..read_amt]); read_idx += read_amt; } @@ -170,7 +170,7 @@ impl Writeable for (Payload, [u8; 32]) { // Uses the provided secret to simultaneously decode and decrypt the control TLVs. impl ReadableArgs for Payload { - fn read(mut r: &mut R, encrypted_tlvs_ss: SharedSecret) -> Result { + fn read(r: &mut R, encrypted_tlvs_ss: SharedSecret) -> Result { let v: BigSize = Readable::read(r)?; let mut rd = FixedLengthReader::new(r, v.0); let mut reply_path: Option = None;