Skip to content

Commit d6ae7e3

Browse files
committed
Make OnionMessageContents private for now
This doesn't change the API expressibility as its currently the only type of message that can be sent, but avoids a generation failure as we can't call `&self` methods on complex enums unless we can `clone` all the inner fields. The correct solution to this is to simply not expose those methods (which sucks, but at least for `OnionMessageContents` they don't really matter), but that doesn't have to come now.
1 parent 46a1a8e commit d6ae7e3

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lightning/src/onion_message/messenger.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::prelude::*;
4747
/// # use lightning::ln::msgs::DecodeError;
4848
/// # use lightning::ln::peer_handler::IgnoringMessageHandler;
4949
/// # use lightning::onion_message::messenger::{Destination, OnionMessenger};
50-
/// # use lightning::onion_message::packet::{CustomOnionMessageContents, OnionMessageContents};
50+
/// # use lightning::onion_message::packet::CustomOnionMessageContents;
5151
/// # use lightning::onion_message::blinded_route::BlindedRoute;
5252
/// # use lightning::util::logger::{Logger, Record};
5353
/// # use lightning::util::ser::{Writeable, Writer};
@@ -88,8 +88,7 @@ use crate::prelude::*;
8888
/// let intermediate_hops = [hop_node_id1, hop_node_id2];
8989
/// let reply_path = None;
9090
/// # let your_custom_message = YourCustomMessage {};
91-
/// let message = OnionMessageContents::Custom(your_custom_message);
92-
/// onion_messenger.send_onion_message(&intermediate_hops, Destination::Node(destination_node_id), message, reply_path);
91+
/// onion_messenger.send_custom_onion_message(&intermediate_hops, Destination::Node(destination_node_id), your_custom_message, reply_path);
9392
///
9493
/// // Create a blinded route to yourself, for someone to send an onion message to.
9594
/// # let your_node_id = hop_node_id1;
@@ -100,8 +99,7 @@ use crate::prelude::*;
10099
/// # let intermediate_hops = [hop_node_id1, hop_node_id2];
101100
/// let reply_path = None;
102101
/// # let your_custom_message = YourCustomMessage {};
103-
/// let message = OnionMessageContents::Custom(your_custom_message);
104-
/// onion_messenger.send_onion_message(&intermediate_hops, Destination::BlindedRoute(blinded_route), message, reply_path);
102+
/// onion_messenger.send_custom_onion_message(&intermediate_hops, Destination::BlindedRoute(blinded_route), your_custom_message, reply_path);
105103
/// ```
106104
///
107105
/// [offers]: <https://github.com/lightning/bolts/pull/798>
@@ -200,13 +198,19 @@ impl<Signer: Sign, K: Deref, L: Deref, CMH: Deref> OnionMessenger<Signer, K, L,
200198

201199
/// Send an onion message with contents `message` to `destination`, routing it through `intermediate_nodes`.
202200
/// See [`OnionMessenger`] for example usage.
203-
pub fn send_onion_message<T: CustomOnionMessageContents>(&self, intermediate_nodes: &[PublicKey], destination: Destination, message: OnionMessageContents<T>, reply_path: Option<BlindedRoute>) -> Result<(), SendError> {
201+
pub(crate) fn send_onion_message<T: CustomOnionMessageContents>(&self, intermediate_nodes: &[PublicKey], destination: Destination, msg: OnionMessageContents<T>, reply_path: Option<BlindedRoute>) -> Result<(), SendError> {
202+
let OnionMessageContents::Custom(message) = msg;
203+
self.send_custom_onion_message(intermediate_nodes, destination, message, reply_path)
204+
}
205+
206+
/// Send an onion message with contents `message` to `destination`, routing it through `intermediate_nodes`.
207+
/// See [`OnionMessenger`] for example usage.
208+
pub fn send_custom_onion_message<T: CustomOnionMessageContents>(&self, intermediate_nodes: &[PublicKey], destination: Destination, msg: T, reply_path: Option<BlindedRoute>) -> Result<(), SendError> {
204209
if let Destination::BlindedRoute(BlindedRoute { ref blinded_hops, .. }) = destination {
205210
if blinded_hops.len() < 2 {
206211
return Err(SendError::TooFewBlindedHops);
207212
}
208213
}
209-
let OnionMessageContents::Custom(ref msg) = message;
210214
if msg.tlv_type() < 64 { return Err(SendError::InvalidMessage) }
211215

212216
let blinding_secret_bytes = self.keys_manager.get_secure_random_bytes();
@@ -221,7 +225,7 @@ impl<Signer: Sign, K: Deref, L: Deref, CMH: Deref> OnionMessenger<Signer, K, L,
221225
}
222226
};
223227
let (packet_payloads, packet_keys) = packet_payloads_and_keys(
224-
&self.secp_ctx, intermediate_nodes, destination, message, reply_path, &blinding_secret)
228+
&self.secp_ctx, intermediate_nodes, destination, OnionMessageContents::Custom(msg), reply_path, &blinding_secret)
225229
.map_err(|e| SendError::Secp256k1(e))?;
226230

227231
let prng_seed = self.keys_manager.get_secure_random_bytes();

lightning/src/onion_message/packet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub(super) enum Payload<T: CustomOnionMessageContents> {
107107
#[derive(Debug)]
108108
/// The contents of an onion message. In the context of offers, this would be the invoice, invoice
109109
/// request, or invoice error.
110-
pub enum OnionMessageContents<T: CustomOnionMessageContents> {
110+
pub(crate) enum OnionMessageContents<T: CustomOnionMessageContents> {
111111
// Coming soon:
112112
// Invoice,
113113
// InvoiceRequest,

0 commit comments

Comments
 (0)