]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Make OnionMessageContents private for now 2022-10-112-bindings-base
authorMatt Corallo <git@bluematt.me>
Wed, 26 Oct 2022 21:58:46 +0000 (21:58 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 27 Oct 2022 21:29:46 +0000 (21:29 +0000)
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.

lightning/src/onion_message/messenger.rs
lightning/src/onion_message/packet.rs

index 261f59c445b2ba88357a5fc63c0f179c9a793b96..6284c47c8e8f8384fe1b81305e3eedc1cfae6160 100644 (file)
@@ -47,7 +47,7 @@ use crate::prelude::*;
 /// # use lightning::ln::msgs::DecodeError;
 /// # use lightning::ln::peer_handler::IgnoringMessageHandler;
 /// # use lightning::onion_message::messenger::{Destination, OnionMessenger};
-/// # use lightning::onion_message::packet::{CustomOnionMessageContents, OnionMessageContents};
+/// # use lightning::onion_message::packet::CustomOnionMessageContents;
 /// # use lightning::onion_message::blinded_route::BlindedRoute;
 /// # use lightning::util::logger::{Logger, Record};
 /// # use lightning::util::ser::{Writeable, Writer};
@@ -88,8 +88,7 @@ use crate::prelude::*;
 /// let intermediate_hops = [hop_node_id1, hop_node_id2];
 /// let reply_path = None;
 /// # let your_custom_message = YourCustomMessage {};
-/// let message = OnionMessageContents::Custom(your_custom_message);
-/// onion_messenger.send_onion_message(&intermediate_hops, Destination::Node(destination_node_id), message, reply_path);
+/// onion_messenger.send_custom_onion_message(&intermediate_hops, Destination::Node(destination_node_id), your_custom_message, reply_path);
 ///
 /// // Create a blinded route to yourself, for someone to send an onion message to.
 /// # let your_node_id = hop_node_id1;
@@ -100,8 +99,7 @@ use crate::prelude::*;
 /// # let intermediate_hops = [hop_node_id1, hop_node_id2];
 /// let reply_path = None;
 /// # let your_custom_message = YourCustomMessage {};
-/// let message = OnionMessageContents::Custom(your_custom_message);
-/// onion_messenger.send_onion_message(&intermediate_hops, Destination::BlindedRoute(blinded_route), message, reply_path);
+/// onion_messenger.send_custom_onion_message(&intermediate_hops, Destination::BlindedRoute(blinded_route), your_custom_message, reply_path);
 /// ```
 ///
 /// [offers]: <https://github.com/lightning/bolts/pull/798>
@@ -139,7 +137,7 @@ impl Destination {
 
 /// Errors that may occur when [sending an onion message].
 ///
-/// [sending an onion message]: OnionMessenger::send_onion_message
+/// [sending an onion message]: OnionMessenger::send_custom_onion_message
 #[derive(Debug, PartialEq, Eq)]
 pub enum SendError {
        /// Errored computing onion message packet keys.
@@ -200,13 +198,19 @@ impl<Signer: Sign, K: Deref, L: Deref, CMH: Deref> OnionMessenger<Signer, K, L,
 
        /// Send an onion message with contents `message` to `destination`, routing it through `intermediate_nodes`.
        /// See [`OnionMessenger`] for example usage.
-       pub fn send_onion_message<T: CustomOnionMessageContents>(&self, intermediate_nodes: &[PublicKey], destination: Destination, message: OnionMessageContents<T>, reply_path: Option<BlindedRoute>) -> Result<(), SendError> {
+       pub(crate) fn send_onion_message<T: CustomOnionMessageContents>(&self, intermediate_nodes: &[PublicKey], destination: Destination, msg: OnionMessageContents<T>, reply_path: Option<BlindedRoute>) -> Result<(), SendError> {
+               let OnionMessageContents::Custom(message) = msg;
+               self.send_custom_onion_message(intermediate_nodes, destination, message, reply_path)
+       }
+
+       /// Send an onion message with contents `message` to `destination`, routing it through `intermediate_nodes`.
+       /// See [`OnionMessenger`] for example usage.
+       pub fn send_custom_onion_message<T: CustomOnionMessageContents>(&self, intermediate_nodes: &[PublicKey], destination: Destination, msg: T, reply_path: Option<BlindedRoute>) -> Result<(), SendError> {
                if let Destination::BlindedRoute(BlindedRoute { ref blinded_hops, .. }) = destination {
                        if blinded_hops.len() < 2 {
                                return Err(SendError::TooFewBlindedHops);
                        }
                }
-               let OnionMessageContents::Custom(ref msg) = message;
                if msg.tlv_type() < 64 { return Err(SendError::InvalidMessage) }
 
                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,
                        }
                };
                let (packet_payloads, packet_keys) = packet_payloads_and_keys(
-                       &self.secp_ctx, intermediate_nodes, destination, message, reply_path, &blinding_secret)
+                       &self.secp_ctx, intermediate_nodes, destination, OnionMessageContents::Custom(msg), reply_path, &blinding_secret)
                        .map_err(|e| SendError::Secp256k1(e))?;
 
                let prng_seed = self.keys_manager.get_secure_random_bytes();
index 73f58036c865c4c18f12a8cd3dd7191328ebaa87..3bc42f504229e392064c58f38ee13efe3e18bb0f 100644 (file)
@@ -107,7 +107,7 @@ pub(super) enum Payload<T: CustomOnionMessageContents> {
 #[derive(Debug)]
 /// The contents of an onion message. In the context of offers, this would be the invoice, invoice
 /// request, or invoice error.
-pub enum OnionMessageContents<T: CustomOnionMessageContents> {
+pub(crate) enum OnionMessageContents<T: CustomOnionMessageContents> {
        // Coming soon:
        // Invoice,
        // InvoiceRequest,