]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Support forwarding prebuilt onion messages in OnionMessenger.
authorValentine Wallace <vwallace@protonmail.com>
Mon, 25 Mar 2024 15:42:13 +0000 (11:42 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Thu, 9 May 2024 19:29:38 +0000 (15:29 -0400)
lightning/src/onion_message/messenger.rs

index d956b392a39631a6ce2ca761d0b457e7bb252da0..213ac7fc9e76730e655efbe7a8af79cb0c43e7ac 100644 (file)
@@ -943,6 +943,27 @@ where
                }
        }
 
+       /// Forwards an [`OnionMessage`] to `peer_node_id`. Useful if we initialized
+       /// the [`OnionMessenger`] with [`Self::new_with_offline_peer_interception`]
+       /// and want to forward a previously intercepted onion message to a peer that
+       /// has just come online.
+       pub fn forward_onion_message(
+               &self, message: OnionMessage, peer_node_id: &PublicKey
+       ) -> Result<(), SendError> {
+               let mut message_recipients = self.message_recipients.lock().unwrap();
+               if outbound_buffer_full(&peer_node_id, &message_recipients) {
+                       return Err(SendError::BufferFull);
+               }
+
+               match message_recipients.entry(*peer_node_id) {
+                       hash_map::Entry::Occupied(mut e) if e.get().is_connected() => {
+                               e.get_mut().enqueue_message(message);
+                               Ok(())
+                       },
+                       _ => Err(SendError::InvalidFirstHop(*peer_node_id))
+               }
+       }
+
        #[cfg(any(test, feature = "_test_utils"))]
        pub fn send_onion_message_using_path<T: OnionMessageContents>(
                &self, path: OnionMessagePath, contents: T, reply_path: Option<BlindedPath>