Skip to content

Commit 7213458

Browse files
Support forwarding prebuilt onion messages in OnionMessenger.
1 parent 1c28cc0 commit 7213458

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
@@ -943,6 +943,27 @@ where
943943
}
944944
}
945945

946+
/// Forwards an [`OnionMessage`] to `peer_node_id`. Useful if we initialized
947+
/// the [`OnionMessenger`] with [`Self::new_with_offline_peer_interception`]
948+
/// and want to forward a previously intercepted onion message to a peer that
949+
/// has just come online.
950+
pub fn forward_onion_message(
951+
&self, message: OnionMessage, peer_node_id: &PublicKey
952+
) -> Result<(), SendError> {
953+
let mut message_recipients = self.message_recipients.lock().unwrap();
954+
if outbound_buffer_full(&peer_node_id, &message_recipients) {
955+
return Err(SendError::BufferFull);
956+
}
957+
958+
match message_recipients.entry(*peer_node_id) {
959+
hash_map::Entry::Occupied(mut e) if e.get().is_connected() => {
960+
e.get_mut().enqueue_message(message);
961+
Ok(())
962+
},
963+
_ => Err(SendError::InvalidFirstHop(*peer_node_id))
964+
}
965+
}
966+
946967
#[cfg(any(test, feature = "_test_utils"))]
947968
pub fn send_onion_message_using_path<T: OnionMessageContents>(
948969
&self, path: OnionMessagePath, contents: T, reply_path: Option<BlindedPath>

0 commit comments

Comments
 (0)