Skip to content

Commit 0d987d0

Browse files
Support forwarding prebuilt onion messages in OnionMessenger.
1 parent 229f2f1 commit 0d987d0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,27 @@ where
769769
)
770770
}
771771

772+
/// Forwards an [`OnionMessage`] to `peer_node_id`. Useful if we initialized
773+
/// the [`OnionMessenger`] with [`Self::new_with_offline_peer_interception`]
774+
/// and want to forward a previously intercepted onion message to a peer that
775+
/// has just come online.
776+
pub fn forward_onion_message(
777+
&self, message: OnionMessage, peer_node_id: &PublicKey
778+
) -> Result<(), SendError> {
779+
let mut message_recipients = self.message_recipients.lock().unwrap();
780+
if outbound_buffer_full(&peer_node_id, &message_recipients) {
781+
return Err(SendError::BufferFull);
782+
}
783+
784+
match message_recipients.entry(*peer_node_id) {
785+
hash_map::Entry::Occupied(mut e) if e.get().is_connected() => {
786+
e.get_mut().enqueue_message(message);
787+
Ok(())
788+
},
789+
_ => Err(SendError::InvalidFirstHop(*peer_node_id))
790+
}
791+
}
792+
772793
fn find_path_and_enqueue_onion_message<T: OnionMessageContents>(
773794
&self, contents: T, destination: Destination, reply_path: Option<BlindedPath>,
774795
log_suffix: fmt::Arguments

0 commit comments

Comments
 (0)