Skip to content

Commit ab66143

Browse files
committed
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.
1 parent f352d03 commit ab66143

File tree

15 files changed

+38
-38
lines changed

15 files changed

+38
-38
lines changed

fuzz/src/chanmon_consistency.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use lightning::ln::script::ShutdownScript;
4848
use lightning::ln::functional_test_utils::*;
4949
use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
5050
use lightning::offers::invoice_request::UnsignedInvoiceRequest;
51-
use lightning::onion_message::{Destination, MessageRouter, OnionMessagePath};
51+
use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath};
5252
use lightning::util::test_channel_signer::{TestChannelSigner, EnforcementState};
5353
use lightning::util::errors::APIError;
5454
use lightning::util::logger::Logger;

fuzz/src/full_stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use lightning::ln::script::ShutdownScript;
4545
use lightning::ln::functional_test_utils::*;
4646
use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
4747
use lightning::offers::invoice_request::UnsignedInvoiceRequest;
48-
use lightning::onion_message::{Destination, MessageRouter, OnionMessagePath};
48+
use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath};
4949
use lightning::routing::gossip::{P2PGossipSync, NetworkGraph};
5050
use lightning::routing::utxo::UtxoLookup;
5151
use lightning::routing::router::{InFlightHtlcs, PaymentParameters, Route, RouteParameters, Router};

fuzz/src/onion_message.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use lightning::sign::{Recipient, KeyMaterial, EntropySource, NodeSigner, SignerP
1616
use lightning::util::test_channel_signer::TestChannelSigner;
1717
use lightning::util::logger::Logger;
1818
use lightning::util::ser::{Readable, Writeable, Writer};
19-
use lightning::onion_message::{CustomOnionMessageHandler, Destination, MessageRouter, OffersMessage, OffersMessageHandler, OnionMessageContents, OnionMessagePath, OnionMessenger, PendingOnionMessage};
19+
use lightning::onion_message::messenger::{CustomOnionMessageHandler, Destination, MessageRouter, OnionMessagePath, OnionMessenger, PendingOnionMessage};
20+
use lightning::onion_message::offers::{OffersMessage, OffersMessageHandler};
21+
use lightning::onion_message::packet::OnionMessageContents;
2022

2123
use crate::utils::test_logger;
2224

lightning/src/blinded_path/message.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::blinded_path::utils;
55
use crate::io;
66
use crate::io::Cursor;
77
use crate::ln::onion_utils;
8-
use crate::onion_message::ControlTlvs;
8+
use crate::onion_message::packet::ControlTlvs;
99
use crate::prelude::*;
1010
use crate::sign::{NodeSigner, Recipient};
1111
use crate::util::chacha20poly1305rfc::ChaChaPolyReadAdapter;

lightning/src/blinded_path/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use bitcoin::secp256k1::ecdh::SharedSecret;
1818
use super::{BlindedHop, BlindedPath};
1919
use crate::ln::msgs::DecodeError;
2020
use crate::ln::onion_utils;
21-
use crate::onion_message::Destination;
21+
use crate::onion_message::messenger::Destination;
2222
use crate::util::chacha20poly1305rfc::ChaChaPolyWriteAdapter;
2323
use crate::util::ser::{Readable, Writeable};
2424

lightning/src/events/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,8 @@ pub enum Event {
540540
/// replies. Handlers should connect to the node otherwise any buffered messages may be lost.
541541
///
542542
/// [`OnionMessage`]: msgs::OnionMessage
543-
/// [`MessageRouter`]: crate::onion_message::MessageRouter
544-
/// [`Destination`]: crate::onion_message::Destination
543+
/// [`MessageRouter`]: crate::onion_message::messenger::MessageRouter
544+
/// [`Destination`]: crate::onion_message::messenger::Destination
545545
/// [`OnionMessageHandler`]: crate::ln::msgs::OnionMessageHandler
546546
ConnectionNeeded {
547547
/// The node id for the node needing a connection.

lightning/src/ln/channelmanager.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ use crate::offers::merkle::SignError;
6363
use crate::offers::offer::{DerivedMetadata, Offer, OfferBuilder};
6464
use crate::offers::parse::Bolt12SemanticError;
6565
use crate::offers::refund::{Refund, RefundBuilder};
66-
use crate::onion_message::{Destination, MessageRouter, OffersMessage, OffersMessageHandler, PendingOnionMessage, new_pending_onion_message};
66+
use crate::onion_message::messenger::{Destination, MessageRouter, PendingOnionMessage, new_pending_onion_message};
67+
use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
6768
use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
6869
use crate::sign::ecdsa::WriteableEcdsaChannelSigner;
6970
use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};

lightning/src/ln/msgs.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ pub struct OnionMessage {
695695
/// Used in decrypting the onion packet's payload.
696696
pub blinding_point: PublicKey,
697697
/// The full onion packet including hop data, pubkey, and hmac
698-
pub onion_routing_packet: onion_message::Packet,
698+
pub onion_routing_packet: onion_message::packet::Packet,
699699
}
700700

701701
/// An [`update_fulfill_htlc`] message to be sent to or received from a peer.
@@ -2245,7 +2245,8 @@ impl Readable for OnionMessage {
22452245
let blinding_point: PublicKey = Readable::read(r)?;
22462246
let len: u16 = Readable::read(r)?;
22472247
let mut packet_reader = FixedLengthReader::new(r, len as u64);
2248-
let onion_routing_packet: onion_message::Packet = <onion_message::Packet as LengthReadable>::read(&mut packet_reader)?;
2248+
let onion_routing_packet: onion_message::packet::Packet =
2249+
<onion_message::packet::Packet as LengthReadable>::read(&mut packet_reader)?;
22492250
Ok(Self {
22502251
blinding_point,
22512252
onion_routing_packet,

lightning/src/ln/peer_handler.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ use crate::ln::peer_channel_encryptor::{PeerChannelEncryptor, NextNoiseStep, Mes
3131
use crate::ln::wire;
3232
use crate::ln::wire::{Encode, Type};
3333
#[cfg(not(c_bindings))]
34-
use crate::onion_message::{SimpleArcOnionMessenger, SimpleRefOnionMessenger};
35-
use crate::onion_message::{CustomOnionMessageHandler, OffersMessage, OffersMessageHandler, OnionMessageContents, PendingOnionMessage};
34+
use crate::onion_message::messenger::{SimpleArcOnionMessenger, SimpleRefOnionMessenger};
35+
use crate::onion_message::messenger::{CustomOnionMessageHandler, PendingOnionMessage};
36+
use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
37+
use crate::onion_message::packet::OnionMessageContents;
3638
use crate::routing::gossip::{NodeId, NodeAlias};
3739
use crate::util::atomic_counter::AtomicCounter;
3840
use crate::util::logger::{Logger, WithContext};
@@ -384,7 +386,7 @@ pub struct MessageHandler<CM: Deref, RM: Deref, OM: Deref, CustomM: Deref> where
384386
/// A message handler which handles onion messages. This should generally be an
385387
/// [`OnionMessenger`], but can also be an [`IgnoringMessageHandler`].
386388
///
387-
/// [`OnionMessenger`]: crate::onion_message::OnionMessenger
389+
/// [`OnionMessenger`]: crate::onion_message::messenger::OnionMessenger
388390
pub onion_message_handler: OM,
389391

390392
/// A message handler which handles custom messages. The only LDK-provided implementation is

lightning/src/onion_message/functional_tests.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use crate::ln::msgs::{self, DecodeError, OnionMessageHandler, SocketAddress};
1616
use crate::sign::{EntropySource, NodeSigner, Recipient};
1717
use crate::util::ser::{FixedLengthReader, LengthReadable, Writeable, Writer};
1818
use crate::util::test_utils;
19-
use super::{CustomOnionMessageHandler, Destination, MessageRouter, OffersMessage, OffersMessageHandler, OnionMessageContents, OnionMessagePath, OnionMessenger, PendingOnionMessage, SendError};
19+
use super::messenger::{CustomOnionMessageHandler, Destination, MessageRouter, OnionMessagePath, OnionMessenger, PendingOnionMessage, SendError};
20+
use super::offers::{OffersMessage, OffersMessageHandler};
21+
use super::packet::{OnionMessageContents, Packet};
2022

2123
use bitcoin::network::constants::Network;
2224
use bitcoin::hashes::hex::FromHex;
@@ -571,8 +573,8 @@ fn spec_test_vector() {
571573
let sender_to_alice_packet_bytes_len = sender_to_alice_packet_bytes.len() as u64;
572574
let mut reader = io::Cursor::new(sender_to_alice_packet_bytes);
573575
let mut packet_reader = FixedLengthReader::new(&mut reader, sender_to_alice_packet_bytes_len);
574-
let sender_to_alice_packet: super::Packet =
575-
<super::Packet as LengthReadable>::read(&mut packet_reader).unwrap();
576+
let sender_to_alice_packet: Packet =
577+
<Packet as LengthReadable>::read(&mut packet_reader).unwrap();
576578
let secp_ctx = Secp256k1::new();
577579
let sender_to_alice_om = msgs::OnionMessage {
578580
blinding_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&<Vec<u8>>::from_hex("6363636363636363636363636363636363636363636363636363636363636363").unwrap()).unwrap()),

lightning/src/onion_message/messenger.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// You may not use this file except in accordance with one or both of these
88
// licenses.
99

10-
//! LDK sends, receives, and forwards onion messages via the [`OnionMessenger`]. See its docs for
11-
//! more information.
10+
//! LDK sends, receives, and forwards onion messages via this [`OnionMessenger`], which lives here,
11+
//! as well as various types, traits, and utilities that it uses.
1212
1313
use bitcoin::hashes::{Hash, HashEngine};
1414
use bitcoin::hashes::hmac::{Hmac, HmacEngine};
@@ -26,7 +26,7 @@ use crate::ln::features::{InitFeatures, NodeFeatures};
2626
use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler, SocketAddress};
2727
use crate::ln::onion_utils;
2828
use crate::routing::gossip::{NetworkGraph, NodeId};
29-
pub use super::packet::OnionMessageContents;
29+
use super::packet::OnionMessageContents;
3030
use super::packet::ParsedOnionMessageContents;
3131
use super::offers::OffersMessageHandler;
3232
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;
7474
/// # use lightning::blinded_path::BlindedPath;
7575
/// # use lightning::sign::{EntropySource, KeysManager};
7676
/// # use lightning::ln::peer_handler::IgnoringMessageHandler;
77-
/// # use lightning::onion_message::{OnionMessageContents, Destination, MessageRouter, OnionMessagePath, OnionMessenger};
77+
/// # use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath, OnionMessenger};
78+
/// # use lightning::onion_message::packet::OnionMessageContents;
7879
/// # use lightning::util::logger::{Logger, Record};
7980
/// # use lightning::util::ser::{Writeable, Writer};
8081
/// # use lightning::io;

lightning/src/onion_message/mod.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,10 @@
1919
//!
2020
//! [offers]: <https://github.com/lightning/bolts/pull/798>
2121
//! [blinded paths]: crate::blinded_path::BlindedPath
22+
//! [`OnionMessenger`]: self::messenger::OnionMessenger
2223
23-
mod messenger;
24-
mod offers;
25-
mod packet;
24+
pub mod messenger;
25+
pub mod offers;
26+
pub mod packet;
2627
#[cfg(test)]
2728
mod functional_tests;
28-
29-
// Re-export structs so they can be imported with just the `onion_message::` module prefix.
30-
pub use self::messenger::{CustomOnionMessageHandler, DefaultMessageRouter, Destination, MessageRouter, OnionMessageContents, OnionMessagePath, OnionMessenger, PeeledOnion, PendingOnionMessage, SendError};
31-
pub use self::messenger::{create_onion_message, peel_onion_message};
32-
#[cfg(not(c_bindings))]
33-
pub use self::messenger::{SimpleArcOnionMessenger, SimpleRefOnionMessenger};
34-
pub use self::offers::{OffersMessage, OffersMessageHandler};
35-
pub use self::packet::{Packet, ParsedOnionMessageContents};
36-
pub(crate) use self::packet::ControlTlvs;
37-
pub(crate) use self::messenger::new_pending_onion_message;

lightning/src/onion_message/offers.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::offers::invoice_error::InvoiceError;
1717
use crate::offers::invoice_request::InvoiceRequest;
1818
use crate::offers::invoice::Bolt12Invoice;
1919
use crate::offers::parse::Bolt12ParseError;
20-
use crate::onion_message::OnionMessageContents;
20+
use crate::onion_message::packet::OnionMessageContents;
2121
use crate::util::logger::Logger;
2222
use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
2323
#[cfg(not(c_bindings))]
@@ -39,7 +39,7 @@ pub trait OffersMessageHandler {
3939
///
4040
/// The returned [`OffersMessage`], if any, is enqueued to be sent by [`OnionMessenger`].
4141
///
42-
/// [`OnionMessenger`]: crate::onion_message::OnionMessenger
42+
/// [`OnionMessenger`]: crate::onion_message::messenger::OnionMessenger
4343
fn handle_message(&self, message: OffersMessage) -> Option<OffersMessage>;
4444

4545
/// Releases any [`OffersMessage`]s that need to be sent.
@@ -54,7 +54,7 @@ pub trait OffersMessageHandler {
5454
/// Typically, this is used for messages initiating a payment flow rather than in response to
5555
/// another message. The latter should use the return value of [`Self::handle_message`].
5656
#[cfg(c_bindings)]
57-
fn release_pending_messages(&self) -> Vec<(OffersMessage, crate::onion_message::Destination, Option<crate::blinded_path::BlindedPath>)> { vec![] }
57+
fn release_pending_messages(&self) -> Vec<(OffersMessage, crate::onion_message::messenger::Destination, Option<crate::blinded_path::BlindedPath>)> { vec![] }
5858
}
5959

6060
/// Possible BOLT 12 Offers messages sent and received via an [`OnionMessage`].

lightning/src/routing/router.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::ln::channelmanager::{ChannelDetails, PaymentId};
2020
use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures};
2121
use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
2222
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice};
23-
use crate::onion_message::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath};
23+
use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath};
2424
use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees};
2525
use crate::routing::scoring::{ChannelUsage, LockableScore, ScoreLookUp};
2626
use crate::sign::EntropySource;

lightning/src/util/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::ln::msgs::LightningError;
3232
use crate::ln::script::ShutdownScript;
3333
use crate::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
3434
use crate::offers::invoice_request::UnsignedInvoiceRequest;
35-
use crate::onion_message::{Destination, MessageRouter, OnionMessagePath};
35+
use crate::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath};
3636
use crate::routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId, RoutingFees};
3737
use crate::routing::utxo::{UtxoLookup, UtxoLookupError, UtxoResult};
3838
use crate::routing::router::{find_route, InFlightHtlcs, Path, Route, RouteParameters, RouteHintHop, Router, ScorerAccountingForInFlightHtlcs};

0 commit comments

Comments
 (0)