From a4894bd3caa31a77044ec5c62149249df56d3ec5 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Wed, 4 Oct 2023 15:23:34 -1000 Subject: [PATCH] Clean up onion messenger parameters and docs --- lightning/src/onion_message/messenger.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index f271e2c2..3b65bb4b 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -267,11 +267,15 @@ pub enum PeeledOnion { Receive(OnionMessageContents, Option<[u8; 32]>, Option) } -/// Create an onion message with contents `message` to the destination of `path`. -/// Returns (first_node_id, onion_msg) +/// Creates an [`OnionMessage`] with the given `contents` for sending to the destination of +/// `path`. +/// +/// Returns both the node id of the peer to send the message to and the message itself. +/// +/// [`OnionMessage`]: msgs::OnionMessage pub fn create_onion_message( entropy_source: &ES, node_signer: &NS, secp_ctx: &Secp256k1, - path: OnionMessagePath, message: OnionMessageContents, reply_path: Option, + path: OnionMessagePath, contents: OnionMessageContents, reply_path: Option, ) -> Result<(PublicKey, msgs::OnionMessage), SendError> where ES::Target: EntropySource, @@ -284,7 +288,7 @@ where } } - if message.tlv_type() < 64 { return Err(SendError::InvalidMessage) } + if contents.tlv_type() < 64 { return Err(SendError::InvalidMessage) } // If we are sending straight to a blinded path and we are the introduction node, we need to // advance the blinded path by 1 hop so the second hop is the new introduction node. @@ -311,7 +315,7 @@ where } }; let (packet_payloads, packet_keys) = packet_payloads_and_keys( - &secp_ctx, &intermediate_nodes, destination, message, reply_path, &blinding_secret) + &secp_ctx, &intermediate_nodes, destination, contents, reply_path, &blinding_secret) .map_err(|e| SendError::Secp256k1(e))?; let prng_seed = entropy_source.get_secure_random_bytes(); @@ -449,16 +453,16 @@ where } } - /// Send an onion message with contents `message` to the destination of `path`. + /// Sends an [`msgs::OnionMessage`] with the given `contents` for sending to the destination of + /// `path`. /// /// See [`OnionMessenger`] for example usage. pub fn send_onion_message( - &self, path: OnionMessagePath, message: OnionMessageContents, + &self, path: OnionMessagePath, contents: OnionMessageContents, reply_path: Option ) -> Result<(), SendError> { let (first_node_id, onion_msg) = create_onion_message( - &self.entropy_source, &self.node_signer, &self.secp_ctx, - path, message, reply_path + &self.entropy_source, &self.node_signer, &self.secp_ctx, path, contents, reply_path )?; let mut pending_per_peer_msgs = self.pending_messages.lock().unwrap(); -- 2.30.2