Skip to content

Commit d4aff0e

Browse files
Support forwarding prebuilt onion messages in OnionMessenger.
1 parent 8469fed commit d4aff0e

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
@@ -854,6 +854,27 @@ where
854854
)
855855
}
856856

857+
/// Forwards an [`OnionMessage`] to `peer_node_id`. Useful if we initialized
858+
/// the [`OnionMessenger`] with [`Self::new_with_offline_peer_interception`]
859+
/// and want to forward a previously intercepted onion message to a peer that
860+
/// has just come online.
861+
pub fn forward_onion_message(
862+
&self, message: OnionMessage, peer_node_id: &PublicKey
863+
) -> Result<(), SendError> {
864+
let mut message_recipients = self.message_recipients.lock().unwrap();
865+
if outbound_buffer_full(&peer_node_id, &message_recipients) {
866+
return Err(SendError::BufferFull);
867+
}
868+
869+
match message_recipients.entry(*peer_node_id) {
870+
hash_map::Entry::Occupied(mut e) if e.get().is_connected() => {
871+
e.get_mut().enqueue_message(message);
872+
Ok(())
873+
},
874+
_ => Err(SendError::InvalidFirstHop(*peer_node_id))
875+
}
876+
}
877+
857878
fn find_path_and_enqueue_onion_message<T: OnionMessageContents>(
858879
&self, contents: T, destination: Destination, reply_path: Option<BlindedPath>,
859880
log_suffix: fmt::Arguments

0 commit comments

Comments
 (0)