X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fonion_message%2Fmessenger.rs;h=0e68d09143c00d251c69ee251162960b05ec3bed;hb=c70ea1d987baef7b0d658d476eb09c281f98bd65;hp=723e105d044cf549cfd8f392e206782b38a479af;hpb=10b8f4c44e94ef2f280decec43ee351502e2a218;p=rust-lightning diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index 723e105d..0e68d091 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -19,6 +19,7 @@ use crate::blinded_path::BlindedPath; use crate::blinded_path::message::{advance_path_by_one, ForwardTlvs, ReceiveTlvs}; use crate::blinded_path::utils; use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient}; +#[cfg(not(c_bindings))] use crate::ln::channelmanager::{SimpleArcChannelManager, SimpleRefChannelManager}; use crate::ln::features::{InitFeatures, NodeFeatures}; use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler}; @@ -58,6 +59,7 @@ use crate::prelude::*; /// ``` /// # extern crate bitcoin; /// # use bitcoin::hashes::_export::_core::time::Duration; +/// # use bitcoin::hashes::hex::FromHex; /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; /// # use lightning::blinded_path::BlindedPath; /// # use lightning::sign::KeysManager; @@ -81,7 +83,7 @@ use crate::prelude::*; /// # let time = Duration::from_secs(123456); /// # let keys_manager = KeysManager::new(&seed, time.as_secs(), time.subsec_nanos()); /// # let logger = Arc::new(FakeLogger {}); -/// # let node_secret = SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap(); +/// # let node_secret = SecretKey::from_slice(&>::from_hex("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap(); /// # let secp_ctx = Secp256k1::new(); /// # let hop_node_id1 = PublicKey::from_secret_key(&secp_ctx, &node_secret); /// # let (hop_node_id2, hop_node_id3, hop_node_id4) = (hop_node_id1, hop_node_id1, hop_node_id1); @@ -158,6 +160,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, @@ -169,6 +172,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`]. @@ -285,7 +304,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) @@ -380,7 +407,7 @@ where let blinding_factor = { let mut hmac = HmacEngine::::new(b"blinded_node_id"); hmac.input(control_tlvs_ss.as_ref()); - Hmac::from_engine(hmac).into_inner() + Hmac::from_engine(hmac).to_byte_array() }; match node_signer.ecdh(Recipient::Node, &msg.onion_routing_packet.public_key, Some(&Scalar::from_be_bytes(blinding_factor).unwrap())) @@ -685,7 +712,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") ); @@ -693,7 +723,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") ); @@ -712,10 +745,11 @@ where /// Useful for simplifying the parameters of [`SimpleArcChannelManager`] and /// [`SimpleArcPeerManager`]. See their docs for more details. /// -/// This is not exported to bindings users as `Arc`s don't make sense in bindings. +/// This is not exported to bindings users as type aliases aren't supported in most languages. /// /// [`SimpleArcChannelManager`]: crate::ln::channelmanager::SimpleArcChannelManager /// [`SimpleArcPeerManager`]: crate::ln::peer_handler::SimpleArcPeerManager +#[cfg(not(c_bindings))] pub type SimpleArcOnionMessenger = OnionMessenger< Arc, Arc, @@ -728,10 +762,11 @@ pub type SimpleArcOnionMessenger = OnionMessenger< /// Useful for simplifying the parameters of [`SimpleRefChannelManager`] and /// [`SimpleRefPeerManager`]. See their docs for more details. /// -/// This is not exported to bindings users as general type aliases don't make sense in bindings. +/// This is not exported to bindings users as type aliases aren't supported in most languages. /// /// [`SimpleRefChannelManager`]: crate::ln::channelmanager::SimpleRefChannelManager /// [`SimpleRefPeerManager`]: crate::ln::peer_handler::SimpleRefPeerManager +#[cfg(not(c_bindings))] pub type SimpleRefOnionMessenger< 'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, M, T, F, L > = OnionMessenger<