1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! LDK sends, receives, and forwards onion messages via the [`OnionMessenger`]. See its docs for
12 use alloc::str::FromStr;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
21 use lightning::onion_message::messenger::OnionMessenger as nativeOnionMessengerImport;
22 pub(crate) type nativeOnionMessenger = nativeOnionMessengerImport<crate::lightning::chain::keysinterface::EntropySource, crate::lightning::chain::keysinterface::NodeSigner, crate::lightning::util::logger::Logger, crate::lightning::onion_message::messenger::CustomOnionMessageHandler>;
24 /// A sender, receiver and forwarder of onion messages. In upcoming releases, this object will be
25 /// used to retrieve invoices and fulfill invoice requests from [offers]. Currently, only sending
26 /// and receiving custom onion messages is supported.
31 /// # extern crate bitcoin;
32 /// # use bitcoin::hashes::_export::_core::time::Duration;
33 /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
34 /// # use lightning::blinded_path::BlindedPath;
35 /// # use lightning::chain::keysinterface::KeysManager;
36 /// # use lightning::ln::peer_handler::IgnoringMessageHandler;
37 /// # use lightning::onion_message::messenger::{Destination, OnionMessenger};
38 /// # use lightning::onion_message::packet::{CustomOnionMessageContents, OnionMessageContents};
39 /// # use lightning::util::logger::{Logger, Record};
40 /// # use lightning::util::ser::{Writeable, Writer};
41 /// # use lightning::io;
42 /// # use std::sync::Arc;
43 /// # struct FakeLogger;
44 /// # impl Logger for FakeLogger {
45 /// # fn log(&self, record: &Record) { unimplemented!() }
47 /// # let seed = [42u8; 32];
48 /// # let time = Duration::from_secs(123456);
49 /// # let keys_manager = KeysManager::new(&seed, time.as_secs(), time.subsec_nanos());
50 /// # let logger = Arc::new(FakeLogger {});
51 /// # let node_secret = SecretKey::from_slice(&hex::decode(\"0101010101010101010101010101010101010101010101010101010101010101\").unwrap()[..]).unwrap();
52 /// # let secp_ctx = Secp256k1::new();
53 /// # let hop_node_id1 = PublicKey::from_secret_key(&secp_ctx, &node_secret);
54 /// # let (hop_node_id2, hop_node_id3, hop_node_id4) = (hop_node_id1, hop_node_id1, hop_node_id1);
55 /// # let destination_node_id = hop_node_id1;
56 /// # let your_custom_message_handler = IgnoringMessageHandler {};
57 /// // Create the onion messenger. This must use the same `keys_manager` as is passed to your
58 /// // ChannelManager.
59 /// let onion_messenger = OnionMessenger::new(&keys_manager, &keys_manager, logger, &your_custom_message_handler);
61 /// # struct YourCustomMessage {}
62 /// impl Writeable for YourCustomMessage {
63 /// \tfn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
65 /// \t\t// Write your custom onion message to `w`
68 /// impl CustomOnionMessageContents for YourCustomMessage {
69 /// \tfn tlv_type(&self) -> u64 {
70 /// \t\t# let your_custom_message_type = 42;
71 /// \t\tyour_custom_message_type
74 /// // Send a custom onion message to a node id.
75 /// let intermediate_hops = [hop_node_id1, hop_node_id2];
76 /// let reply_path = None;
77 /// # let your_custom_message = YourCustomMessage {};
78 /// let message = OnionMessageContents::Custom(your_custom_message);
79 /// onion_messenger.send_onion_message(&intermediate_hops, Destination::Node(destination_node_id), message, reply_path);
81 /// // Create a blinded path to yourself, for someone to send an onion message to.
82 /// # let your_node_id = hop_node_id1;
83 /// let hops = [hop_node_id3, hop_node_id4, your_node_id];
84 /// let blinded_path = BlindedPath::new_for_message(&hops, &keys_manager, &secp_ctx).unwrap();
86 /// // Send a custom onion message to a blinded path.
87 /// # let intermediate_hops = [hop_node_id1, hop_node_id2];
88 /// let reply_path = None;
89 /// # let your_custom_message = YourCustomMessage {};
90 /// let message = OnionMessageContents::Custom(your_custom_message);
91 /// onion_messenger.send_onion_message(&intermediate_hops, Destination::BlindedPath(blinded_path), message, reply_path);
94 /// [offers]: <https://github.com/lightning/bolts/pull/798>
95 /// [`OnionMessenger`]: crate::onion_message::OnionMessenger
98 pub struct OnionMessenger {
99 /// A pointer to the opaque Rust object.
101 /// Nearly everywhere, inner must be non-null, however in places where
102 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
103 pub inner: *mut nativeOnionMessenger,
104 /// Indicates that this is the only struct which contains the same pointer.
106 /// Rust functions which take ownership of an object provided via an argument require
107 /// this to be true and invalidate the object pointed to by inner.
111 impl Drop for OnionMessenger {
113 if self.is_owned && !<*mut nativeOnionMessenger>::is_null(self.inner) {
114 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
118 /// Frees any resources used by the OnionMessenger, if is_owned is set and inner is non-NULL.
120 pub extern "C" fn OnionMessenger_free(this_obj: OnionMessenger) { }
122 /// Used only if an object of this type is returned as a trait impl by a method
123 pub(crate) extern "C" fn OnionMessenger_free_void(this_ptr: *mut c_void) {
124 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOnionMessenger) };
127 impl OnionMessenger {
128 pub(crate) fn get_native_ref(&self) -> &'static nativeOnionMessenger {
129 unsafe { &*ObjOps::untweak_ptr(self.inner) }
131 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOnionMessenger {
132 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
134 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
135 pub(crate) fn take_inner(mut self) -> *mut nativeOnionMessenger {
136 assert!(self.is_owned);
137 let ret = ObjOps::untweak_ptr(self.inner);
138 self.inner = core::ptr::null_mut();
142 /// The destination of an onion message.
146 pub enum Destination {
147 /// We're sending this onion message to a node.
149 crate::c_types::PublicKey),
150 /// We're sending this onion message to a blinded path.
152 crate::lightning::blinded_path::BlindedPath),
154 use lightning::onion_message::messenger::Destination as DestinationImport;
155 pub(crate) type nativeDestination = DestinationImport;
159 pub(crate) fn to_native(&self) -> nativeDestination {
161 Destination::Node (ref a, ) => {
162 let mut a_nonref = Clone::clone(a);
163 nativeDestination::Node (
164 a_nonref.into_rust(),
167 Destination::BlindedPath (ref a, ) => {
168 let mut a_nonref = Clone::clone(a);
169 nativeDestination::BlindedPath (
170 *unsafe { Box::from_raw(a_nonref.take_inner()) },
176 pub(crate) fn into_native(self) -> nativeDestination {
178 Destination::Node (mut a, ) => {
179 nativeDestination::Node (
183 Destination::BlindedPath (mut a, ) => {
184 nativeDestination::BlindedPath (
185 *unsafe { Box::from_raw(a.take_inner()) },
191 pub(crate) fn from_native(native: &nativeDestination) -> Self {
193 nativeDestination::Node (ref a, ) => {
194 let mut a_nonref = Clone::clone(a);
196 crate::c_types::PublicKey::from_rust(&a_nonref),
199 nativeDestination::BlindedPath (ref a, ) => {
200 let mut a_nonref = Clone::clone(a);
201 Destination::BlindedPath (
202 crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
208 pub(crate) fn native_into(native: nativeDestination) -> Self {
210 nativeDestination::Node (mut a, ) => {
212 crate::c_types::PublicKey::from_rust(&a),
215 nativeDestination::BlindedPath (mut a, ) => {
216 Destination::BlindedPath (
217 crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(a), is_owned: true },
223 /// Frees any resources used by the Destination
225 pub extern "C" fn Destination_free(this_ptr: Destination) { }
226 /// Creates a copy of the Destination
228 pub extern "C" fn Destination_clone(orig: &Destination) -> Destination {
232 /// Utility method to constructs a new Node-variant Destination
233 pub extern "C" fn Destination_node(a: crate::c_types::PublicKey) -> Destination {
234 Destination::Node(a, )
237 /// Utility method to constructs a new BlindedPath-variant Destination
238 pub extern "C" fn Destination_blinded_path(a: crate::lightning::blinded_path::BlindedPath) -> Destination {
239 Destination::BlindedPath(a, )
241 /// Errors that may occur when [sending an onion message].
243 /// [sending an onion message]: OnionMessenger::send_onion_message
248 /// Errored computing onion message packet keys.
250 crate::c_types::Secp256k1Error),
251 /// Because implementations such as Eclair will drop onion messages where the message packet
252 /// exceeds 32834 bytes, we refuse to send messages where the packet exceeds this size.
254 /// The provided [`Destination`] was an invalid [`BlindedPath`], due to having fewer than two
257 /// Our next-hop peer was offline or does not support onion message forwarding.
259 /// Onion message contents must have a TLV type >= 64.
261 /// Our next-hop peer's buffer was full or our total outbound buffer was full.
263 /// Failed to retrieve our node id from the provided [`NodeSigner`].
265 /// [`NodeSigner`]: crate::chain::keysinterface::NodeSigner
267 /// We attempted to send to a blinded path where we are the introduction node, and failed to
268 /// advance the blinded path to make the second hop the new introduction node. Either
269 /// [`NodeSigner::ecdh`] failed, we failed to tweak the current blinding point to get the
270 /// new blinding point, or we were attempting to send to ourselves.
271 BlindedPathAdvanceFailed,
273 use lightning::onion_message::messenger::SendError as SendErrorImport;
274 pub(crate) type nativeSendError = SendErrorImport;
278 pub(crate) fn to_native(&self) -> nativeSendError {
280 SendError::Secp256k1 (ref a, ) => {
281 let mut a_nonref = Clone::clone(a);
282 nativeSendError::Secp256k1 (
283 a_nonref.into_rust(),
286 SendError::TooBigPacket => nativeSendError::TooBigPacket,
287 SendError::TooFewBlindedHops => nativeSendError::TooFewBlindedHops,
288 SendError::InvalidFirstHop => nativeSendError::InvalidFirstHop,
289 SendError::InvalidMessage => nativeSendError::InvalidMessage,
290 SendError::BufferFull => nativeSendError::BufferFull,
291 SendError::GetNodeIdFailed => nativeSendError::GetNodeIdFailed,
292 SendError::BlindedPathAdvanceFailed => nativeSendError::BlindedPathAdvanceFailed,
296 pub(crate) fn into_native(self) -> nativeSendError {
298 SendError::Secp256k1 (mut a, ) => {
299 nativeSendError::Secp256k1 (
303 SendError::TooBigPacket => nativeSendError::TooBigPacket,
304 SendError::TooFewBlindedHops => nativeSendError::TooFewBlindedHops,
305 SendError::InvalidFirstHop => nativeSendError::InvalidFirstHop,
306 SendError::InvalidMessage => nativeSendError::InvalidMessage,
307 SendError::BufferFull => nativeSendError::BufferFull,
308 SendError::GetNodeIdFailed => nativeSendError::GetNodeIdFailed,
309 SendError::BlindedPathAdvanceFailed => nativeSendError::BlindedPathAdvanceFailed,
313 pub(crate) fn from_native(native: &nativeSendError) -> Self {
315 nativeSendError::Secp256k1 (ref a, ) => {
316 let mut a_nonref = Clone::clone(a);
317 SendError::Secp256k1 (
318 crate::c_types::Secp256k1Error::from_rust(a_nonref),
321 nativeSendError::TooBigPacket => SendError::TooBigPacket,
322 nativeSendError::TooFewBlindedHops => SendError::TooFewBlindedHops,
323 nativeSendError::InvalidFirstHop => SendError::InvalidFirstHop,
324 nativeSendError::InvalidMessage => SendError::InvalidMessage,
325 nativeSendError::BufferFull => SendError::BufferFull,
326 nativeSendError::GetNodeIdFailed => SendError::GetNodeIdFailed,
327 nativeSendError::BlindedPathAdvanceFailed => SendError::BlindedPathAdvanceFailed,
331 pub(crate) fn native_into(native: nativeSendError) -> Self {
333 nativeSendError::Secp256k1 (mut a, ) => {
334 SendError::Secp256k1 (
335 crate::c_types::Secp256k1Error::from_rust(a),
338 nativeSendError::TooBigPacket => SendError::TooBigPacket,
339 nativeSendError::TooFewBlindedHops => SendError::TooFewBlindedHops,
340 nativeSendError::InvalidFirstHop => SendError::InvalidFirstHop,
341 nativeSendError::InvalidMessage => SendError::InvalidMessage,
342 nativeSendError::BufferFull => SendError::BufferFull,
343 nativeSendError::GetNodeIdFailed => SendError::GetNodeIdFailed,
344 nativeSendError::BlindedPathAdvanceFailed => SendError::BlindedPathAdvanceFailed,
348 /// Frees any resources used by the SendError
350 pub extern "C" fn SendError_free(this_ptr: SendError) { }
351 /// Creates a copy of the SendError
353 pub extern "C" fn SendError_clone(orig: &SendError) -> SendError {
357 /// Utility method to constructs a new Secp256k1-variant SendError
358 pub extern "C" fn SendError_secp256k1(a: crate::c_types::Secp256k1Error) -> SendError {
359 SendError::Secp256k1(a, )
362 /// Utility method to constructs a new TooBigPacket-variant SendError
363 pub extern "C" fn SendError_too_big_packet() -> SendError {
364 SendError::TooBigPacket}
366 /// Utility method to constructs a new TooFewBlindedHops-variant SendError
367 pub extern "C" fn SendError_too_few_blinded_hops() -> SendError {
368 SendError::TooFewBlindedHops}
370 /// Utility method to constructs a new InvalidFirstHop-variant SendError
371 pub extern "C" fn SendError_invalid_first_hop() -> SendError {
372 SendError::InvalidFirstHop}
374 /// Utility method to constructs a new InvalidMessage-variant SendError
375 pub extern "C" fn SendError_invalid_message() -> SendError {
376 SendError::InvalidMessage}
378 /// Utility method to constructs a new BufferFull-variant SendError
379 pub extern "C" fn SendError_buffer_full() -> SendError {
380 SendError::BufferFull}
382 /// Utility method to constructs a new GetNodeIdFailed-variant SendError
383 pub extern "C" fn SendError_get_node_id_failed() -> SendError {
384 SendError::GetNodeIdFailed}
386 /// Utility method to constructs a new BlindedPathAdvanceFailed-variant SendError
387 pub extern "C" fn SendError_blinded_path_advance_failed() -> SendError {
388 SendError::BlindedPathAdvanceFailed}
389 /// Checks if two SendErrors contain equal inner contents.
390 /// This ignores pointers and is_owned flags and looks at the values in fields.
392 pub extern "C" fn SendError_eq(a: &SendError, b: &SendError) -> bool {
393 if &a.to_native() == &b.to_native() { true } else { false }
395 /// Handler for custom onion messages. If you are using [`SimpleArcOnionMessenger`],
396 /// [`SimpleRefOnionMessenger`], or prefer to ignore inbound custom onion messages,
397 /// [`IgnoringMessageHandler`] must be provided to [`OnionMessenger::new`]. Otherwise, a custom
398 /// implementation of this trait must be provided, with [`CustomMessage`] specifying the supported
401 /// See [`OnionMessenger`] for example usage.
403 /// [`IgnoringMessageHandler`]: crate::ln::peer_handler::IgnoringMessageHandler
404 /// [`CustomMessage`]: Self::CustomMessage
406 pub struct CustomOnionMessageHandler {
407 /// An opaque pointer which is passed to your function implementations as an argument.
408 /// This has no meaning in the LDK, and can be NULL or any other value.
409 pub this_arg: *mut c_void,
410 /// Called with the custom message that was received.
411 pub handle_custom_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::onion_message::packet::CustomOnionMessageContents),
412 /// Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
413 /// message type is unknown.
415 pub read_custom_message: extern "C" fn (this_arg: *const c_void, message_type: u64, buffer: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_CustomOnionMessageContentsZDecodeErrorZ,
416 /// Frees any resources associated with this object given its this_arg pointer.
417 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
418 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
420 unsafe impl Send for CustomOnionMessageHandler {}
421 unsafe impl Sync for CustomOnionMessageHandler {}
423 pub(crate) extern "C" fn CustomOnionMessageHandler_clone_fields(orig: &CustomOnionMessageHandler) -> CustomOnionMessageHandler {
424 CustomOnionMessageHandler {
425 this_arg: orig.this_arg,
426 handle_custom_message: Clone::clone(&orig.handle_custom_message),
427 read_custom_message: Clone::clone(&orig.read_custom_message),
428 free: Clone::clone(&orig.free),
432 use lightning::onion_message::messenger::CustomOnionMessageHandler as rustCustomOnionMessageHandler;
433 impl rustCustomOnionMessageHandler for CustomOnionMessageHandler {
434 type CustomMessage = crate::lightning::onion_message::packet::CustomOnionMessageContents;
435 fn handle_custom_message(&self, mut msg: crate::lightning::onion_message::packet::CustomOnionMessageContents) {
436 (self.handle_custom_message)(self.this_arg, Into::into(msg))
438 fn read_custom_message<R:crate::c_types::io::Read>(&self, mut message_type: u64, mut buffer: &mut R) -> Result<Option<crate::lightning::onion_message::packet::CustomOnionMessageContents>, lightning::ln::msgs::DecodeError> {
439 let mut ret = (self.read_custom_message)(self.this_arg, message_type, crate::c_types::u8slice::from_vec(&crate::c_types::reader_to_vec(buffer)));
440 let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = { /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ let ret_0_opt = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }); if ret_0_opt.is_none() { None } else { Some({ { { ret_0_opt.take() } }})} }; local_ret_0 }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
445 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
446 // directly as a Deref trait in higher-level structs:
447 impl core::ops::Deref for CustomOnionMessageHandler {
449 fn deref(&self) -> &Self {
453 /// Calls the free function if one is set
455 pub extern "C" fn CustomOnionMessageHandler_free(this_ptr: CustomOnionMessageHandler) { }
456 impl Drop for CustomOnionMessageHandler {
458 if let Some(f) = self.free {
463 /// Constructs a new `OnionMessenger` to send, forward, and delegate received onion messages to
464 /// their respective handlers.
467 pub extern "C" fn OnionMessenger_new(mut entropy_source: crate::lightning::chain::keysinterface::EntropySource, mut node_signer: crate::lightning::chain::keysinterface::NodeSigner, mut logger: crate::lightning::util::logger::Logger, mut custom_handler: crate::lightning::onion_message::messenger::CustomOnionMessageHandler) -> crate::lightning::onion_message::messenger::OnionMessenger {
468 let mut ret = lightning::onion_message::messenger::OnionMessenger::new(entropy_source, node_signer, logger, custom_handler);
469 crate::lightning::onion_message::messenger::OnionMessenger { inner: ObjOps::heap_alloc(ret), is_owned: true }
472 /// Send an onion message with contents `message` to `destination`, routing it through `intermediate_nodes`.
473 /// See [`OnionMessenger`] for example usage.
475 /// Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None
478 pub extern "C" fn OnionMessenger_send_onion_message(this_arg: &crate::lightning::onion_message::messenger::OnionMessenger, mut intermediate_nodes: crate::c_types::derived::CVec_PublicKeyZ, mut destination: crate::lightning::onion_message::messenger::Destination, mut message: crate::lightning::onion_message::packet::OnionMessageContents, mut reply_path: crate::lightning::blinded_path::BlindedPath) -> crate::c_types::derived::CResult_NoneSendErrorZ {
479 let mut local_intermediate_nodes = Vec::new(); for mut item in intermediate_nodes.into_rust().drain(..) { local_intermediate_nodes.push( { item.into_rust() }); };
480 let mut local_reply_path = if reply_path.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(reply_path.take_inner()) } }) };
481 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_onion_message(&local_intermediate_nodes[..], destination.into_native(), message.into_native(), local_reply_path);
482 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::onion_message::messenger::SendError::native_into(e) }).into() };
486 impl From<nativeOnionMessenger> for crate::lightning::ln::msgs::OnionMessageHandler {
487 fn from(obj: nativeOnionMessenger) -> Self {
488 let mut rust_obj = OnionMessenger { inner: ObjOps::heap_alloc(obj), is_owned: true };
489 let mut ret = OnionMessenger_as_OnionMessageHandler(&rust_obj);
490 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
491 rust_obj.inner = core::ptr::null_mut();
492 ret.free = Some(OnionMessenger_free_void);
496 /// Constructs a new OnionMessageHandler which calls the relevant methods on this_arg.
497 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageHandler must be freed before this_arg is
499 pub extern "C" fn OnionMessenger_as_OnionMessageHandler(this_arg: &OnionMessenger) -> crate::lightning::ln::msgs::OnionMessageHandler {
500 crate::lightning::ln::msgs::OnionMessageHandler {
501 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
503 handle_onion_message: OnionMessenger_OnionMessageHandler_handle_onion_message,
504 peer_connected: OnionMessenger_OnionMessageHandler_peer_connected,
505 peer_disconnected: OnionMessenger_OnionMessageHandler_peer_disconnected,
506 provided_node_features: OnionMessenger_OnionMessageHandler_provided_node_features,
507 provided_init_features: OnionMessenger_OnionMessageHandler_provided_init_features,
508 OnionMessageProvider: crate::lightning::events::OnionMessageProvider {
509 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
511 next_onion_message_for_peer: OnionMessenger_OnionMessageProvider_next_onion_message_for_peer,
516 extern "C" fn OnionMessenger_OnionMessageHandler_handle_onion_message(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OnionMessage) {
517 <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::handle_onion_message(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &peer_node_id.into_rust(), msg.get_native_ref())
520 extern "C" fn OnionMessenger_OnionMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init: &crate::lightning::ln::msgs::Init, mut inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ {
521 let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust(), init.get_native_ref(), inbound);
522 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
525 extern "C" fn OnionMessenger_OnionMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
526 <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust())
529 extern "C" fn OnionMessenger_OnionMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
530 let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, );
531 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
534 extern "C" fn OnionMessenger_OnionMessageHandler_provided_init_features(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures {
535 let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust());
536 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
539 impl From<nativeOnionMessenger> for crate::lightning::events::OnionMessageProvider {
540 fn from(obj: nativeOnionMessenger) -> Self {
541 let mut rust_obj = OnionMessenger { inner: ObjOps::heap_alloc(obj), is_owned: true };
542 let mut ret = OnionMessenger_as_OnionMessageProvider(&rust_obj);
543 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
544 rust_obj.inner = core::ptr::null_mut();
545 ret.free = Some(OnionMessenger_free_void);
549 /// Constructs a new OnionMessageProvider which calls the relevant methods on this_arg.
550 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageProvider must be freed before this_arg is
552 pub extern "C" fn OnionMessenger_as_OnionMessageProvider(this_arg: &OnionMessenger) -> crate::lightning::events::OnionMessageProvider {
553 crate::lightning::events::OnionMessageProvider {
554 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
556 next_onion_message_for_peer: OnionMessenger_OnionMessageProvider_next_onion_message_for_peer,
561 extern "C" fn OnionMessenger_OnionMessageProvider_next_onion_message_for_peer(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage {
562 let mut ret = <nativeOnionMessenger as lightning::events::OnionMessageProvider<>>::next_onion_message_for_peer(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, peer_node_id.into_rust());
563 let mut local_ret = crate::lightning::ln::msgs::OnionMessage { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };