X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fonion_message%2Fmessenger.rs;fp=lightning%2Fsrc%2Fonion_message%2Fmessenger.rs;h=cf0f9e086b5c41a12c2e9b1b5e27f3a03949fae7;hb=49a5fdf6aa00c06645290da8343bb2efff0380ee;hp=200ee44ee32b89a93d8b8907c7dc949ce77522cb;hpb=3f416bc24e0e804e0cae1c8c5650b19500122b6d;p=rust-lightning diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index 200ee44e..cf0f9e08 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -159,6 +159,7 @@ where /// /// These are obtained when released from [`OnionMessenger`]'s handlers after which they are /// enqueued for sending. +#[cfg(not(c_bindings))] pub struct PendingOnionMessage { /// The message contents to send in an [`OnionMessage`]. pub contents: T, @@ -170,6 +171,22 @@ pub struct PendingOnionMessage { pub reply_path: Option, } +#[cfg(c_bindings)] +/// An [`OnionMessage`] for [`OnionMessenger`] to send. +/// +/// These are obtained when released from [`OnionMessenger`]'s handlers after which they are +/// enqueued for sending. +pub type PendingOnionMessage = (T, Destination, Option); + +pub(crate) fn new_pending_onion_message( + contents: T, destination: Destination, reply_path: Option +) -> PendingOnionMessage { + #[cfg(not(c_bindings))] + return PendingOnionMessage { contents, destination, reply_path }; + #[cfg(c_bindings)] + return (contents, destination, reply_path); +} + /// A trait defining behavior for routing an [`OnionMessage`]. pub trait MessageRouter { /// Returns a route for sending an [`OnionMessage`] to the given [`Destination`]. @@ -286,7 +303,15 @@ pub trait CustomOnionMessageHandler { /// /// Typically, this is used for messages initiating a message flow rather than in response to /// another message. The latter should use the return value of [`Self::handle_custom_message`]. + #[cfg(not(c_bindings))] fn release_pending_custom_messages(&self) -> Vec>; + + /// Releases any [`Self::CustomMessage`]s that need to be sent. + /// + /// Typically, this is used for messages initiating a message flow rather than in response to + /// another message. The latter should use the return value of [`Self::handle_custom_message`]. + #[cfg(c_bindings)] + fn release_pending_custom_messages(&self) -> Vec<(Self::CustomMessage, Destination, Option)>; } /// A processed incoming onion message, containing either a Forward (another onion message) @@ -686,7 +711,10 @@ where fn next_onion_message_for_peer(&self, peer_node_id: PublicKey) -> Option { // Enqueue any initiating `OffersMessage`s to send. for message in self.offers_handler.release_pending_messages() { + #[cfg(not(c_bindings))] let PendingOnionMessage { contents, destination, reply_path } = message; + #[cfg(c_bindings)] + let (contents, destination, reply_path) = message; self.find_path_and_enqueue_onion_message( contents, destination, reply_path, format_args!("when sending OffersMessage") ); @@ -694,7 +722,10 @@ where // Enqueue any initiating `CustomMessage`s to send. for message in self.custom_handler.release_pending_custom_messages() { + #[cfg(not(c_bindings))] let PendingOnionMessage { contents, destination, reply_path } = message; + #[cfg(c_bindings)] + let (contents, destination, reply_path) = message; self.find_path_and_enqueue_onion_message( contents, destination, reply_path, format_args!("when sending CustomMessage") );