From: Matt Corallo Date: Wed, 10 Jan 2024 18:27:57 +0000 (+0000) Subject: Expose `onion_message` items directly rather than via re-exports X-Git-Tag: v0.0.120~11^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=refs%2Fheads%2F2024-01-om-direct-export;p=rust-lightning Expose `onion_message` items directly rather than via re-exports When we originally added the `onion_message` module, there weren't a lot of public items in it, and it didn't make a lot of sense to export the whole sub-module structure publicly. So, instead, we exported the public items via re-exports directly in the `onion_message` top-level module. However, as time went on, more and more things entered the module, which left the top-level module rather cluttered. Worse, in 0.0.119, we exposed `onion_message::messenger::SendSuccess` via the return type of `send_message`, but forgot to re-export the enum itself, making it impossible to actually use from external code. Here we address both issues and simply replace the re-export with the underlying sub-module structure. --- diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 7a32434b8..81bf9f441 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -48,7 +48,7 @@ use lightning::ln::script::ShutdownScript; use lightning::ln::functional_test_utils::*; use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice}; use lightning::offers::invoice_request::UnsignedInvoiceRequest; -use lightning::onion_message::{Destination, MessageRouter, OnionMessagePath}; +use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath}; use lightning::util::test_channel_signer::{TestChannelSigner, EnforcementState}; use lightning::util::errors::APIError; use lightning::util::logger::Logger; diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index a2ce98cf4..1f5ceb212 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -45,7 +45,7 @@ use lightning::ln::script::ShutdownScript; use lightning::ln::functional_test_utils::*; use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice}; use lightning::offers::invoice_request::UnsignedInvoiceRequest; -use lightning::onion_message::{Destination, MessageRouter, OnionMessagePath}; +use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath}; use lightning::routing::gossip::{P2PGossipSync, NetworkGraph}; use lightning::routing::utxo::UtxoLookup; use lightning::routing::router::{InFlightHtlcs, PaymentParameters, Route, RouteParameters, Router}; diff --git a/fuzz/src/onion_message.rs b/fuzz/src/onion_message.rs index d2d60cfcf..4ad770fc2 100644 --- a/fuzz/src/onion_message.rs +++ b/fuzz/src/onion_message.rs @@ -16,7 +16,9 @@ use lightning::sign::{Recipient, KeyMaterial, EntropySource, NodeSigner, SignerP use lightning::util::test_channel_signer::TestChannelSigner; use lightning::util::logger::Logger; use lightning::util::ser::{Readable, Writeable, Writer}; -use lightning::onion_message::{CustomOnionMessageHandler, Destination, MessageRouter, OffersMessage, OffersMessageHandler, OnionMessageContents, OnionMessagePath, OnionMessenger, PendingOnionMessage}; +use lightning::onion_message::messenger::{CustomOnionMessageHandler, Destination, MessageRouter, OnionMessagePath, OnionMessenger, PendingOnionMessage}; +use lightning::onion_message::offers::{OffersMessage, OffersMessageHandler}; +use lightning::onion_message::packet::OnionMessageContents; use crate::utils::test_logger; diff --git a/lightning/src/blinded_path/message.rs b/lightning/src/blinded_path/message.rs index d2e81444e..2631a05f6 100644 --- a/lightning/src/blinded_path/message.rs +++ b/lightning/src/blinded_path/message.rs @@ -5,7 +5,7 @@ use crate::blinded_path::utils; use crate::io; use crate::io::Cursor; use crate::ln::onion_utils; -use crate::onion_message::ControlTlvs; +use crate::onion_message::packet::ControlTlvs; use crate::prelude::*; use crate::sign::{NodeSigner, Recipient}; use crate::util::chacha20poly1305rfc::ChaChaPolyReadAdapter; diff --git a/lightning/src/blinded_path/utils.rs b/lightning/src/blinded_path/utils.rs index 2e691898d..7ddb39c1b 100644 --- a/lightning/src/blinded_path/utils.rs +++ b/lightning/src/blinded_path/utils.rs @@ -18,7 +18,7 @@ use bitcoin::secp256k1::ecdh::SharedSecret; use super::{BlindedHop, BlindedPath}; use crate::ln::msgs::DecodeError; use crate::ln::onion_utils; -use crate::onion_message::Destination; +use crate::onion_message::messenger::Destination; use crate::util::chacha20poly1305rfc::ChaChaPolyWriteAdapter; use crate::util::ser::{Readable, Writeable}; diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 76e5f25c0..dede02a37 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -540,8 +540,8 @@ pub enum Event { /// replies. Handlers should connect to the node otherwise any buffered messages may be lost. /// /// [`OnionMessage`]: msgs::OnionMessage - /// [`MessageRouter`]: crate::onion_message::MessageRouter - /// [`Destination`]: crate::onion_message::Destination + /// [`MessageRouter`]: crate::onion_message::messenger::MessageRouter + /// [`Destination`]: crate::onion_message::messenger::Destination /// [`OnionMessageHandler`]: crate::ln::msgs::OnionMessageHandler ConnectionNeeded { /// The node id for the node needing a connection. diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index e04a3cd1a..09c64df1d 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -63,7 +63,8 @@ use crate::offers::merkle::SignError; use crate::offers::offer::{DerivedMetadata, Offer, OfferBuilder}; use crate::offers::parse::Bolt12SemanticError; use crate::offers::refund::{Refund, RefundBuilder}; -use crate::onion_message::{Destination, MessageRouter, OffersMessage, OffersMessageHandler, PendingOnionMessage, new_pending_onion_message}; +use crate::onion_message::messenger::{Destination, MessageRouter, PendingOnionMessage, new_pending_onion_message}; +use crate::onion_message::offers::{OffersMessage, OffersMessageHandler}; use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider}; use crate::sign::ecdsa::WriteableEcdsaChannelSigner; use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate}; diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 2e56e2fc2..83f5a8615 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -695,7 +695,7 @@ pub struct OnionMessage { /// Used in decrypting the onion packet's payload. pub blinding_point: PublicKey, /// The full onion packet including hop data, pubkey, and hmac - pub onion_routing_packet: onion_message::Packet, + pub onion_routing_packet: onion_message::packet::Packet, } /// An [`update_fulfill_htlc`] message to be sent to or received from a peer. @@ -2245,7 +2245,8 @@ impl Readable for OnionMessage { let blinding_point: PublicKey = Readable::read(r)?; let len: u16 = Readable::read(r)?; let mut packet_reader = FixedLengthReader::new(r, len as u64); - let onion_routing_packet: onion_message::Packet = ::read(&mut packet_reader)?; + let onion_routing_packet: onion_message::packet::Packet = + ::read(&mut packet_reader)?; Ok(Self { blinding_point, onion_routing_packet, diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 9f49b6793..6ffffec4d 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -31,8 +31,10 @@ use crate::ln::peer_channel_encryptor::{PeerChannelEncryptor, NextNoiseStep, Mes use crate::ln::wire; use crate::ln::wire::{Encode, Type}; #[cfg(not(c_bindings))] -use crate::onion_message::{SimpleArcOnionMessenger, SimpleRefOnionMessenger}; -use crate::onion_message::{CustomOnionMessageHandler, OffersMessage, OffersMessageHandler, OnionMessageContents, PendingOnionMessage}; +use crate::onion_message::messenger::{SimpleArcOnionMessenger, SimpleRefOnionMessenger}; +use crate::onion_message::messenger::{CustomOnionMessageHandler, PendingOnionMessage}; +use crate::onion_message::offers::{OffersMessage, OffersMessageHandler}; +use crate::onion_message::packet::OnionMessageContents; use crate::routing::gossip::{NodeId, NodeAlias}; use crate::util::atomic_counter::AtomicCounter; use crate::util::logger::{Logger, WithContext}; @@ -384,7 +386,7 @@ pub struct MessageHandler where /// A message handler which handles onion messages. This should generally be an /// [`OnionMessenger`], but can also be an [`IgnoringMessageHandler`]. /// - /// [`OnionMessenger`]: crate::onion_message::OnionMessenger + /// [`OnionMessenger`]: crate::onion_message::messenger::OnionMessenger pub onion_message_handler: OM, /// A message handler which handles custom messages. The only LDK-provided implementation is diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index b0031a6c3..23d27b189 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -16,7 +16,9 @@ use crate::ln::msgs::{self, DecodeError, OnionMessageHandler, SocketAddress}; use crate::sign::{EntropySource, NodeSigner, Recipient}; use crate::util::ser::{FixedLengthReader, LengthReadable, Writeable, Writer}; use crate::util::test_utils; -use super::{CustomOnionMessageHandler, Destination, MessageRouter, OffersMessage, OffersMessageHandler, OnionMessageContents, OnionMessagePath, OnionMessenger, PendingOnionMessage, SendError}; +use super::messenger::{CustomOnionMessageHandler, Destination, MessageRouter, OnionMessagePath, OnionMessenger, PendingOnionMessage, SendError}; +use super::offers::{OffersMessage, OffersMessageHandler}; +use super::packet::{OnionMessageContents, Packet}; use bitcoin::network::constants::Network; use bitcoin::hashes::hex::FromHex; @@ -571,8 +573,8 @@ fn spec_test_vector() { let sender_to_alice_packet_bytes_len = sender_to_alice_packet_bytes.len() as u64; let mut reader = io::Cursor::new(sender_to_alice_packet_bytes); let mut packet_reader = FixedLengthReader::new(&mut reader, sender_to_alice_packet_bytes_len); - let sender_to_alice_packet: super::Packet = - ::read(&mut packet_reader).unwrap(); + let sender_to_alice_packet: Packet = + ::read(&mut packet_reader).unwrap(); let secp_ctx = Secp256k1::new(); let sender_to_alice_om = msgs::OnionMessage { blinding_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&>::from_hex("6363636363636363636363636363636363636363636363636363636363636363").unwrap()).unwrap()), diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index a8ffcc024..5dc3bb422 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -7,8 +7,8 @@ // You may not use this file except in accordance with one or both of these // licenses. -//! LDK sends, receives, and forwards onion messages via the [`OnionMessenger`]. See its docs for -//! more information. +//! LDK sends, receives, and forwards onion messages via this [`OnionMessenger`], which lives here, +//! as well as various types, traits, and utilities that it uses. use bitcoin::hashes::{Hash, HashEngine}; use bitcoin::hashes::hmac::{Hmac, HmacEngine}; @@ -26,7 +26,7 @@ use crate::ln::features::{InitFeatures, NodeFeatures}; use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler, SocketAddress}; use crate::ln::onion_utils; use crate::routing::gossip::{NetworkGraph, NodeId}; -pub use super::packet::OnionMessageContents; +use super::packet::OnionMessageContents; use super::packet::ParsedOnionMessageContents; use super::offers::OffersMessageHandler; use super::packet::{BIG_PACKET_HOP_DATA_LEN, ForwardControlTlvs, Packet, Payload, ReceiveControlTlvs, SMALL_PACKET_HOP_DATA_LEN}; @@ -74,7 +74,8 @@ pub(super) const MAX_TIMER_TICKS: usize = 2; /// # use lightning::blinded_path::BlindedPath; /// # use lightning::sign::{EntropySource, KeysManager}; /// # use lightning::ln::peer_handler::IgnoringMessageHandler; -/// # use lightning::onion_message::{OnionMessageContents, Destination, MessageRouter, OnionMessagePath, OnionMessenger}; +/// # use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath, OnionMessenger}; +/// # use lightning::onion_message::packet::OnionMessageContents; /// # use lightning::util::logger::{Logger, Record}; /// # use lightning::util::ser::{Writeable, Writer}; /// # use lightning::io; diff --git a/lightning/src/onion_message/mod.rs b/lightning/src/onion_message/mod.rs index d106a542f..05a8b7d6f 100644 --- a/lightning/src/onion_message/mod.rs +++ b/lightning/src/onion_message/mod.rs @@ -19,19 +19,10 @@ //! //! [offers]: //! [blinded paths]: crate::blinded_path::BlindedPath +//! [`OnionMessenger`]: self::messenger::OnionMessenger -mod messenger; -mod offers; -mod packet; +pub mod messenger; +pub mod offers; +pub mod packet; #[cfg(test)] mod functional_tests; - -// Re-export structs so they can be imported with just the `onion_message::` module prefix. -pub use self::messenger::{CustomOnionMessageHandler, DefaultMessageRouter, Destination, MessageRouter, OnionMessageContents, OnionMessagePath, OnionMessenger, PeeledOnion, PendingOnionMessage, SendError}; -pub use self::messenger::{create_onion_message, peel_onion_message}; -#[cfg(not(c_bindings))] -pub use self::messenger::{SimpleArcOnionMessenger, SimpleRefOnionMessenger}; -pub use self::offers::{OffersMessage, OffersMessageHandler}; -pub use self::packet::{Packet, ParsedOnionMessageContents}; -pub(crate) use self::packet::ControlTlvs; -pub(crate) use self::messenger::new_pending_onion_message; diff --git a/lightning/src/onion_message/offers.rs b/lightning/src/onion_message/offers.rs index a65c0393a..6672b5dfc 100644 --- a/lightning/src/onion_message/offers.rs +++ b/lightning/src/onion_message/offers.rs @@ -17,7 +17,7 @@ use crate::offers::invoice_error::InvoiceError; use crate::offers::invoice_request::InvoiceRequest; use crate::offers::invoice::Bolt12Invoice; use crate::offers::parse::Bolt12ParseError; -use crate::onion_message::OnionMessageContents; +use crate::onion_message::packet::OnionMessageContents; use crate::util::logger::Logger; use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer}; #[cfg(not(c_bindings))] @@ -39,7 +39,7 @@ pub trait OffersMessageHandler { /// /// The returned [`OffersMessage`], if any, is enqueued to be sent by [`OnionMessenger`]. /// - /// [`OnionMessenger`]: crate::onion_message::OnionMessenger + /// [`OnionMessenger`]: crate::onion_message::messenger::OnionMessenger fn handle_message(&self, message: OffersMessage) -> Option; /// Releases any [`OffersMessage`]s that need to be sent. @@ -54,7 +54,7 @@ pub trait OffersMessageHandler { /// Typically, this is used for messages initiating a payment flow rather than in response to /// another message. The latter should use the return value of [`Self::handle_message`]. #[cfg(c_bindings)] - fn release_pending_messages(&self) -> Vec<(OffersMessage, crate::onion_message::Destination, Option)> { vec![] } + fn release_pending_messages(&self) -> Vec<(OffersMessage, crate::onion_message::messenger::Destination, Option)> { vec![] } } /// Possible BOLT 12 Offers messages sent and received via an [`OnionMessage`]. diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index f79da5ee9..277661862 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -20,7 +20,7 @@ use crate::ln::channelmanager::{ChannelDetails, PaymentId}; use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures}; use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT}; use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice}; -use crate::onion_message::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath}; +use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath}; use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees}; use crate::routing::scoring::{ChannelUsage, LockableScore, ScoreLookUp}; use crate::sign::EntropySource; diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index a006d37e9..1c45c4a4c 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -32,7 +32,7 @@ use crate::ln::msgs::LightningError; use crate::ln::script::ShutdownScript; use crate::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice}; use crate::offers::invoice_request::UnsignedInvoiceRequest; -use crate::onion_message::{Destination, MessageRouter, OnionMessagePath}; +use crate::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath}; use crate::routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId, RoutingFees}; use crate::routing::utxo::{UtxoLookup, UtxoLookupError, UtxoResult}; use crate::routing::router::{find_route, InFlightHtlcs, Path, Route, RouteParameters, RouteHintHop, Router, ScorerAccountingForInFlightHtlcs};