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 alloc::string::String;
14 use core::ffi::c_void;
15 use core::convert::Infallible;
16 use bitcoin::hashes::Hash;
17 use crate::c_types::*;
18 #[cfg(feature="no-std")]
19 use alloc::{vec::Vec, boxed::Box};
22 use lightning::onion_message::messenger::OnionMessenger as nativeOnionMessengerImport;
23 pub(crate) type nativeOnionMessenger = nativeOnionMessengerImport<crate::lightning::sign::EntropySource, crate::lightning::sign::NodeSigner, crate::lightning::util::logger::Logger, crate::lightning::onion_message::messenger::MessageRouter, crate::lightning::onion_message::offers::OffersMessageHandler, crate::lightning::onion_message::messenger::CustomOnionMessageHandler>;
25 /// A sender, receiver and forwarder of [`OnionMessage`]s.
27 /// # Handling Messages
29 /// `OnionMessenger` implements [`OnionMessageHandler`], making it responsible for either forwarding
30 /// messages to peers or delegating to the appropriate handler for the message type. Currently, the
31 /// available handlers are:
32 /// * [`OffersMessageHandler`], for responding to [`InvoiceRequest`]s and paying [`Bolt12Invoice`]s
33 /// * [`CustomOnionMessageHandler`], for handling user-defined message types
35 /// # Sending Messages
37 /// [`OnionMessage`]s are sent initially using [`OnionMessenger::send_onion_message`]. When handling
38 /// a message, the matched handler may return a response message which `OnionMessenger` will send
44 /// # extern crate bitcoin;
45 /// # use bitcoin::hashes::_export::_core::time::Duration;
46 /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
47 /// # use lightning::blinded_path::BlindedPath;
48 /// # use lightning::sign::KeysManager;
49 /// # use lightning::ln::peer_handler::IgnoringMessageHandler;
50 /// # use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessenger, OnionMessagePath};
51 /// # use lightning::onion_message::packet::OnionMessageContents;
52 /// # use lightning::util::logger::{Logger, Record};
53 /// # use lightning::util::ser::{Writeable, Writer};
54 /// # use lightning::io;
55 /// # use std::sync::Arc;
56 /// # struct FakeLogger;
57 /// # impl Logger for FakeLogger {
58 /// # fn log(&self, record: &Record) { unimplemented!() }
60 /// # struct FakeMessageRouter {}
61 /// # impl MessageRouter for FakeMessageRouter {
62 /// # fn find_path(&self, sender: PublicKey, peers: Vec<PublicKey>, destination: Destination) -> Result<OnionMessagePath, ()> {
63 /// # unimplemented!()
66 /// # let seed = [42u8; 32];
67 /// # let time = Duration::from_secs(123456);
68 /// # let keys_manager = KeysManager::new(&seed, time.as_secs(), time.subsec_nanos());
69 /// # let logger = Arc::new(FakeLogger {});
70 /// # let node_secret = SecretKey::from_slice(&hex::decode(\"0101010101010101010101010101010101010101010101010101010101010101\").unwrap()[..]).unwrap();
71 /// # let secp_ctx = Secp256k1::new();
72 /// # let hop_node_id1 = PublicKey::from_secret_key(&secp_ctx, &node_secret);
73 /// # let (hop_node_id2, hop_node_id3, hop_node_id4) = (hop_node_id1, hop_node_id1, hop_node_id1);
74 /// # let destination_node_id = hop_node_id1;
75 /// # let message_router = Arc::new(FakeMessageRouter {});
76 /// # let custom_message_handler = IgnoringMessageHandler {};
77 /// # let offers_message_handler = IgnoringMessageHandler {};
78 /// // Create the onion messenger. This must use the same `keys_manager` as is passed to your
79 /// // ChannelManager.
80 /// let onion_messenger = OnionMessenger::new(
81 /// &keys_manager, &keys_manager, logger, message_router, &offers_message_handler,
82 /// &custom_message_handler
85 /// # #[derive(Clone)]
86 /// # struct YourCustomMessage {}
87 /// impl Writeable for YourCustomMessage {
88 /// \tfn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
90 /// \t\t// Write your custom onion message to `w`
93 /// impl OnionMessageContents for YourCustomMessage {
94 /// \tfn tlv_type(&self) -> u64 {
95 /// \t\t# let your_custom_message_type = 42;
96 /// \t\tyour_custom_message_type
99 /// // Send a custom onion message to a node id.
100 /// let path = OnionMessagePath {
101 /// \tintermediate_nodes: vec![hop_node_id1, hop_node_id2],
102 /// \tdestination: Destination::Node(destination_node_id),
104 /// let reply_path = None;
105 /// # let message = YourCustomMessage {};
106 /// onion_messenger.send_onion_message(path, message, reply_path);
108 /// // Create a blinded path to yourself, for someone to send an onion message to.
109 /// # let your_node_id = hop_node_id1;
110 /// let hops = [hop_node_id3, hop_node_id4, your_node_id];
111 /// let blinded_path = BlindedPath::new_for_message(&hops, &keys_manager, &secp_ctx).unwrap();
113 /// // Send a custom onion message to a blinded path.
114 /// let path = OnionMessagePath {
115 /// \tintermediate_nodes: vec![hop_node_id1, hop_node_id2],
116 /// \tdestination: Destination::BlindedPath(blinded_path),
118 /// let reply_path = None;
119 /// # let message = YourCustomMessage {};
120 /// onion_messenger.send_onion_message(path, message, reply_path);
123 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
124 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
127 pub struct OnionMessenger {
128 /// A pointer to the opaque Rust object.
130 /// Nearly everywhere, inner must be non-null, however in places where
131 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
132 pub inner: *mut nativeOnionMessenger,
133 /// Indicates that this is the only struct which contains the same pointer.
135 /// Rust functions which take ownership of an object provided via an argument require
136 /// this to be true and invalidate the object pointed to by inner.
140 impl Drop for OnionMessenger {
142 if self.is_owned && !<*mut nativeOnionMessenger>::is_null(self.inner) {
143 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
147 /// Frees any resources used by the OnionMessenger, if is_owned is set and inner is non-NULL.
149 pub extern "C" fn OnionMessenger_free(this_obj: OnionMessenger) { }
151 /// Used only if an object of this type is returned as a trait impl by a method
152 pub(crate) extern "C" fn OnionMessenger_free_void(this_ptr: *mut c_void) {
153 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOnionMessenger) };
156 impl OnionMessenger {
157 pub(crate) fn get_native_ref(&self) -> &'static nativeOnionMessenger {
158 unsafe { &*ObjOps::untweak_ptr(self.inner) }
160 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOnionMessenger {
161 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
163 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
164 pub(crate) fn take_inner(mut self) -> *mut nativeOnionMessenger {
165 assert!(self.is_owned);
166 let ret = ObjOps::untweak_ptr(self.inner);
167 self.inner = core::ptr::null_mut();
171 /// A trait defining behavior for routing an [`OnionMessage`].
173 pub struct MessageRouter {
174 /// An opaque pointer which is passed to your function implementations as an argument.
175 /// This has no meaning in the LDK, and can be NULL or any other value.
176 pub this_arg: *mut c_void,
177 /// Returns a route for sending an [`OnionMessage`] to the given [`Destination`].
178 pub find_path: extern "C" fn (this_arg: *const c_void, sender: crate::c_types::PublicKey, peers: crate::c_types::derived::CVec_PublicKeyZ, destination: crate::lightning::onion_message::messenger::Destination) -> crate::c_types::derived::CResult_OnionMessagePathNoneZ,
179 /// Frees any resources associated with this object given its this_arg pointer.
180 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
181 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
183 unsafe impl Send for MessageRouter {}
184 unsafe impl Sync for MessageRouter {}
186 pub(crate) fn MessageRouter_clone_fields(orig: &MessageRouter) -> MessageRouter {
188 this_arg: orig.this_arg,
189 find_path: Clone::clone(&orig.find_path),
190 free: Clone::clone(&orig.free),
194 use lightning::onion_message::messenger::MessageRouter as rustMessageRouter;
195 impl rustMessageRouter for MessageRouter {
196 fn find_path(&self, mut sender: bitcoin::secp256k1::PublicKey, mut peers: Vec<bitcoin::secp256k1::PublicKey>, mut destination: lightning::onion_message::messenger::Destination) -> Result<lightning::onion_message::messenger::OnionMessagePath, ()> {
197 let mut local_peers = Vec::new(); for mut item in peers.drain(..) { local_peers.push( { crate::c_types::PublicKey::from_rust(&item) }); };
198 let mut ret = (self.find_path)(self.this_arg, crate::c_types::PublicKey::from_rust(&sender), local_peers.into(), crate::lightning::onion_message::messenger::Destination::native_into(destination));
199 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
204 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
205 // directly as a Deref trait in higher-level structs:
206 impl core::ops::Deref for MessageRouter {
208 fn deref(&self) -> &Self {
212 impl core::ops::DerefMut for MessageRouter {
213 fn deref_mut(&mut self) -> &mut Self {
217 /// Calls the free function if one is set
219 pub extern "C" fn MessageRouter_free(this_ptr: MessageRouter) { }
220 impl Drop for MessageRouter {
222 if let Some(f) = self.free {
228 use lightning::onion_message::messenger::DefaultMessageRouter as nativeDefaultMessageRouterImport;
229 pub(crate) type nativeDefaultMessageRouter = nativeDefaultMessageRouterImport;
231 /// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
234 pub struct DefaultMessageRouter {
235 /// A pointer to the opaque Rust object.
237 /// Nearly everywhere, inner must be non-null, however in places where
238 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
239 pub inner: *mut nativeDefaultMessageRouter,
240 /// Indicates that this is the only struct which contains the same pointer.
242 /// Rust functions which take ownership of an object provided via an argument require
243 /// this to be true and invalidate the object pointed to by inner.
247 impl Drop for DefaultMessageRouter {
249 if self.is_owned && !<*mut nativeDefaultMessageRouter>::is_null(self.inner) {
250 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
254 /// Frees any resources used by the DefaultMessageRouter, if is_owned is set and inner is non-NULL.
256 pub extern "C" fn DefaultMessageRouter_free(this_obj: DefaultMessageRouter) { }
258 /// Used only if an object of this type is returned as a trait impl by a method
259 pub(crate) extern "C" fn DefaultMessageRouter_free_void(this_ptr: *mut c_void) {
260 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDefaultMessageRouter) };
263 impl DefaultMessageRouter {
264 pub(crate) fn get_native_ref(&self) -> &'static nativeDefaultMessageRouter {
265 unsafe { &*ObjOps::untweak_ptr(self.inner) }
267 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDefaultMessageRouter {
268 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
270 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
271 pub(crate) fn take_inner(mut self) -> *mut nativeDefaultMessageRouter {
272 assert!(self.is_owned);
273 let ret = ObjOps::untweak_ptr(self.inner);
274 self.inner = core::ptr::null_mut();
278 /// Constructs a new DefaultMessageRouter given each field
281 pub extern "C" fn DefaultMessageRouter_new() -> DefaultMessageRouter {
282 DefaultMessageRouter { inner: ObjOps::heap_alloc(lightning::onion_message::messenger::DefaultMessageRouter {}), is_owned: true }
284 impl From<nativeDefaultMessageRouter> for crate::lightning::onion_message::messenger::MessageRouter {
285 fn from(obj: nativeDefaultMessageRouter) -> Self {
286 let rust_obj = crate::lightning::onion_message::messenger::DefaultMessageRouter { inner: ObjOps::heap_alloc(obj), is_owned: true };
287 let mut ret = DefaultMessageRouter_as_MessageRouter(&rust_obj);
288 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
289 core::mem::forget(rust_obj);
290 ret.free = Some(DefaultMessageRouter_free_void);
294 /// Constructs a new MessageRouter which calls the relevant methods on this_arg.
295 /// This copies the `inner` pointer in this_arg and thus the returned MessageRouter must be freed before this_arg is
297 pub extern "C" fn DefaultMessageRouter_as_MessageRouter(this_arg: &DefaultMessageRouter) -> crate::lightning::onion_message::messenger::MessageRouter {
298 crate::lightning::onion_message::messenger::MessageRouter {
299 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
301 find_path: DefaultMessageRouter_MessageRouter_find_path,
306 extern "C" fn DefaultMessageRouter_MessageRouter_find_path(this_arg: *const c_void, mut sender: crate::c_types::PublicKey, mut peers: crate::c_types::derived::CVec_PublicKeyZ, mut destination: crate::lightning::onion_message::messenger::Destination) -> crate::c_types::derived::CResult_OnionMessagePathNoneZ {
307 let mut local_peers = Vec::new(); for mut item in peers.into_rust().drain(..) { local_peers.push( { item.into_rust() }); };
308 let mut ret = <nativeDefaultMessageRouter as lightning::onion_message::messenger::MessageRouter<>>::find_path(unsafe { &mut *(this_arg as *mut nativeDefaultMessageRouter) }, sender.into_rust(), local_peers, destination.into_native());
309 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::onion_message::messenger::OnionMessagePath { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
314 use lightning::onion_message::messenger::OnionMessagePath as nativeOnionMessagePathImport;
315 pub(crate) type nativeOnionMessagePath = nativeOnionMessagePathImport;
317 /// A path for sending an [`OnionMessage`].
320 pub struct OnionMessagePath {
321 /// A pointer to the opaque Rust object.
323 /// Nearly everywhere, inner must be non-null, however in places where
324 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
325 pub inner: *mut nativeOnionMessagePath,
326 /// Indicates that this is the only struct which contains the same pointer.
328 /// Rust functions which take ownership of an object provided via an argument require
329 /// this to be true and invalidate the object pointed to by inner.
333 impl Drop for OnionMessagePath {
335 if self.is_owned && !<*mut nativeOnionMessagePath>::is_null(self.inner) {
336 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
340 /// Frees any resources used by the OnionMessagePath, if is_owned is set and inner is non-NULL.
342 pub extern "C" fn OnionMessagePath_free(this_obj: OnionMessagePath) { }
344 /// Used only if an object of this type is returned as a trait impl by a method
345 pub(crate) extern "C" fn OnionMessagePath_free_void(this_ptr: *mut c_void) {
346 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOnionMessagePath) };
349 impl OnionMessagePath {
350 pub(crate) fn get_native_ref(&self) -> &'static nativeOnionMessagePath {
351 unsafe { &*ObjOps::untweak_ptr(self.inner) }
353 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOnionMessagePath {
354 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
356 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
357 pub(crate) fn take_inner(mut self) -> *mut nativeOnionMessagePath {
358 assert!(self.is_owned);
359 let ret = ObjOps::untweak_ptr(self.inner);
360 self.inner = core::ptr::null_mut();
364 /// Nodes on the path between the sender and the destination.
366 /// Returns a copy of the field.
368 pub extern "C" fn OnionMessagePath_get_intermediate_nodes(this_ptr: &OnionMessagePath) -> crate::c_types::derived::CVec_PublicKeyZ {
369 let mut inner_val = this_ptr.get_native_mut_ref().intermediate_nodes.clone();
370 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { crate::c_types::PublicKey::from_rust(&item) }); };
371 local_inner_val.into()
373 /// Nodes on the path between the sender and the destination.
375 pub extern "C" fn OnionMessagePath_set_intermediate_nodes(this_ptr: &mut OnionMessagePath, mut val: crate::c_types::derived::CVec_PublicKeyZ) {
376 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); };
377 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.intermediate_nodes = local_val;
379 /// The recipient of the message.
381 pub extern "C" fn OnionMessagePath_get_destination(this_ptr: &OnionMessagePath) -> crate::lightning::onion_message::messenger::Destination {
382 let mut inner_val = &mut this_ptr.get_native_mut_ref().destination;
383 crate::lightning::onion_message::messenger::Destination::from_native(inner_val)
385 /// The recipient of the message.
387 pub extern "C" fn OnionMessagePath_set_destination(this_ptr: &mut OnionMessagePath, mut val: crate::lightning::onion_message::messenger::Destination) {
388 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.destination = val.into_native();
390 /// Constructs a new OnionMessagePath given each field
393 pub extern "C" fn OnionMessagePath_new(mut intermediate_nodes_arg: crate::c_types::derived::CVec_PublicKeyZ, mut destination_arg: crate::lightning::onion_message::messenger::Destination) -> OnionMessagePath {
394 let mut local_intermediate_nodes_arg = Vec::new(); for mut item in intermediate_nodes_arg.into_rust().drain(..) { local_intermediate_nodes_arg.push( { item.into_rust() }); };
395 OnionMessagePath { inner: ObjOps::heap_alloc(nativeOnionMessagePath {
396 intermediate_nodes: local_intermediate_nodes_arg,
397 destination: destination_arg.into_native(),
400 impl Clone for OnionMessagePath {
401 fn clone(&self) -> Self {
403 inner: if <*mut nativeOnionMessagePath>::is_null(self.inner) { core::ptr::null_mut() } else {
404 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
410 /// Used only if an object of this type is returned as a trait impl by a method
411 pub(crate) extern "C" fn OnionMessagePath_clone_void(this_ptr: *const c_void) -> *mut c_void {
412 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOnionMessagePath)).clone() })) as *mut c_void
415 /// Creates a copy of the OnionMessagePath
416 pub extern "C" fn OnionMessagePath_clone(orig: &OnionMessagePath) -> OnionMessagePath {
419 /// The destination of an onion message.
423 pub enum Destination {
424 /// We're sending this onion message to a node.
426 crate::c_types::PublicKey),
427 /// We're sending this onion message to a blinded path.
429 crate::lightning::blinded_path::BlindedPath),
431 use lightning::onion_message::messenger::Destination as DestinationImport;
432 pub(crate) type nativeDestination = DestinationImport;
436 pub(crate) fn to_native(&self) -> nativeDestination {
438 Destination::Node (ref a, ) => {
439 let mut a_nonref = Clone::clone(a);
440 nativeDestination::Node (
441 a_nonref.into_rust(),
444 Destination::BlindedPath (ref a, ) => {
445 let mut a_nonref = Clone::clone(a);
446 nativeDestination::BlindedPath (
447 *unsafe { Box::from_raw(a_nonref.take_inner()) },
453 pub(crate) fn into_native(self) -> nativeDestination {
455 Destination::Node (mut a, ) => {
456 nativeDestination::Node (
460 Destination::BlindedPath (mut a, ) => {
461 nativeDestination::BlindedPath (
462 *unsafe { Box::from_raw(a.take_inner()) },
468 pub(crate) fn from_native(native: &nativeDestination) -> Self {
470 nativeDestination::Node (ref a, ) => {
471 let mut a_nonref = Clone::clone(a);
473 crate::c_types::PublicKey::from_rust(&a_nonref),
476 nativeDestination::BlindedPath (ref a, ) => {
477 let mut a_nonref = Clone::clone(a);
478 Destination::BlindedPath (
479 crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
485 pub(crate) fn native_into(native: nativeDestination) -> Self {
487 nativeDestination::Node (mut a, ) => {
489 crate::c_types::PublicKey::from_rust(&a),
492 nativeDestination::BlindedPath (mut a, ) => {
493 Destination::BlindedPath (
494 crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(a), is_owned: true },
500 /// Frees any resources used by the Destination
502 pub extern "C" fn Destination_free(this_ptr: Destination) { }
503 /// Creates a copy of the Destination
505 pub extern "C" fn Destination_clone(orig: &Destination) -> Destination {
509 /// Used only if an object of this type is returned as a trait impl by a method
510 pub(crate) extern "C" fn Destination_clone_void(this_ptr: *const c_void) -> *mut c_void {
511 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Destination)).clone() })) as *mut c_void
514 /// Used only if an object of this type is returned as a trait impl by a method
515 pub(crate) extern "C" fn Destination_free_void(this_ptr: *mut c_void) {
516 let _ = unsafe { Box::from_raw(this_ptr as *mut Destination) };
519 /// Utility method to constructs a new Node-variant Destination
520 pub extern "C" fn Destination_node(a: crate::c_types::PublicKey) -> Destination {
521 Destination::Node(a, )
524 /// Utility method to constructs a new BlindedPath-variant Destination
525 pub extern "C" fn Destination_blinded_path(a: crate::lightning::blinded_path::BlindedPath) -> Destination {
526 Destination::BlindedPath(a, )
528 /// Errors that may occur when [sending an onion message].
530 /// [sending an onion message]: OnionMessenger::send_onion_message
535 /// Errored computing onion message packet keys.
537 crate::c_types::Secp256k1Error),
538 /// Because implementations such as Eclair will drop onion messages where the message packet
539 /// exceeds 32834 bytes, we refuse to send messages where the packet exceeds this size.
541 /// The provided [`Destination`] was an invalid [`BlindedPath`] due to not having any blinded
544 /// Our next-hop peer was offline or does not support onion message forwarding.
546 /// Onion message contents must have a TLV type >= 64.
548 /// Our next-hop peer's buffer was full or our total outbound buffer was full.
550 /// Failed to retrieve our node id from the provided [`NodeSigner`].
552 /// [`NodeSigner`]: crate::sign::NodeSigner
554 /// We attempted to send to a blinded path where we are the introduction node, and failed to
555 /// advance the blinded path to make the second hop the new introduction node. Either
556 /// [`NodeSigner::ecdh`] failed, we failed to tweak the current blinding point to get the
557 /// new blinding point, or we were attempting to send to ourselves.
558 BlindedPathAdvanceFailed,
560 use lightning::onion_message::messenger::SendError as SendErrorImport;
561 pub(crate) type nativeSendError = SendErrorImport;
565 pub(crate) fn to_native(&self) -> nativeSendError {
567 SendError::Secp256k1 (ref a, ) => {
568 let mut a_nonref = Clone::clone(a);
569 nativeSendError::Secp256k1 (
570 a_nonref.into_rust(),
573 SendError::TooBigPacket => nativeSendError::TooBigPacket,
574 SendError::TooFewBlindedHops => nativeSendError::TooFewBlindedHops,
575 SendError::InvalidFirstHop => nativeSendError::InvalidFirstHop,
576 SendError::InvalidMessage => nativeSendError::InvalidMessage,
577 SendError::BufferFull => nativeSendError::BufferFull,
578 SendError::GetNodeIdFailed => nativeSendError::GetNodeIdFailed,
579 SendError::BlindedPathAdvanceFailed => nativeSendError::BlindedPathAdvanceFailed,
583 pub(crate) fn into_native(self) -> nativeSendError {
585 SendError::Secp256k1 (mut a, ) => {
586 nativeSendError::Secp256k1 (
590 SendError::TooBigPacket => nativeSendError::TooBigPacket,
591 SendError::TooFewBlindedHops => nativeSendError::TooFewBlindedHops,
592 SendError::InvalidFirstHop => nativeSendError::InvalidFirstHop,
593 SendError::InvalidMessage => nativeSendError::InvalidMessage,
594 SendError::BufferFull => nativeSendError::BufferFull,
595 SendError::GetNodeIdFailed => nativeSendError::GetNodeIdFailed,
596 SendError::BlindedPathAdvanceFailed => nativeSendError::BlindedPathAdvanceFailed,
600 pub(crate) fn from_native(native: &nativeSendError) -> Self {
602 nativeSendError::Secp256k1 (ref a, ) => {
603 let mut a_nonref = Clone::clone(a);
604 SendError::Secp256k1 (
605 crate::c_types::Secp256k1Error::from_rust(a_nonref),
608 nativeSendError::TooBigPacket => SendError::TooBigPacket,
609 nativeSendError::TooFewBlindedHops => SendError::TooFewBlindedHops,
610 nativeSendError::InvalidFirstHop => SendError::InvalidFirstHop,
611 nativeSendError::InvalidMessage => SendError::InvalidMessage,
612 nativeSendError::BufferFull => SendError::BufferFull,
613 nativeSendError::GetNodeIdFailed => SendError::GetNodeIdFailed,
614 nativeSendError::BlindedPathAdvanceFailed => SendError::BlindedPathAdvanceFailed,
618 pub(crate) fn native_into(native: nativeSendError) -> Self {
620 nativeSendError::Secp256k1 (mut a, ) => {
621 SendError::Secp256k1 (
622 crate::c_types::Secp256k1Error::from_rust(a),
625 nativeSendError::TooBigPacket => SendError::TooBigPacket,
626 nativeSendError::TooFewBlindedHops => SendError::TooFewBlindedHops,
627 nativeSendError::InvalidFirstHop => SendError::InvalidFirstHop,
628 nativeSendError::InvalidMessage => SendError::InvalidMessage,
629 nativeSendError::BufferFull => SendError::BufferFull,
630 nativeSendError::GetNodeIdFailed => SendError::GetNodeIdFailed,
631 nativeSendError::BlindedPathAdvanceFailed => SendError::BlindedPathAdvanceFailed,
635 /// Frees any resources used by the SendError
637 pub extern "C" fn SendError_free(this_ptr: SendError) { }
638 /// Creates a copy of the SendError
640 pub extern "C" fn SendError_clone(orig: &SendError) -> SendError {
644 /// Used only if an object of this type is returned as a trait impl by a method
645 pub(crate) extern "C" fn SendError_clone_void(this_ptr: *const c_void) -> *mut c_void {
646 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SendError)).clone() })) as *mut c_void
649 /// Used only if an object of this type is returned as a trait impl by a method
650 pub(crate) extern "C" fn SendError_free_void(this_ptr: *mut c_void) {
651 let _ = unsafe { Box::from_raw(this_ptr as *mut SendError) };
654 /// Utility method to constructs a new Secp256k1-variant SendError
655 pub extern "C" fn SendError_secp256k1(a: crate::c_types::Secp256k1Error) -> SendError {
656 SendError::Secp256k1(a, )
659 /// Utility method to constructs a new TooBigPacket-variant SendError
660 pub extern "C" fn SendError_too_big_packet() -> SendError {
661 SendError::TooBigPacket}
663 /// Utility method to constructs a new TooFewBlindedHops-variant SendError
664 pub extern "C" fn SendError_too_few_blinded_hops() -> SendError {
665 SendError::TooFewBlindedHops}
667 /// Utility method to constructs a new InvalidFirstHop-variant SendError
668 pub extern "C" fn SendError_invalid_first_hop() -> SendError {
669 SendError::InvalidFirstHop}
671 /// Utility method to constructs a new InvalidMessage-variant SendError
672 pub extern "C" fn SendError_invalid_message() -> SendError {
673 SendError::InvalidMessage}
675 /// Utility method to constructs a new BufferFull-variant SendError
676 pub extern "C" fn SendError_buffer_full() -> SendError {
677 SendError::BufferFull}
679 /// Utility method to constructs a new GetNodeIdFailed-variant SendError
680 pub extern "C" fn SendError_get_node_id_failed() -> SendError {
681 SendError::GetNodeIdFailed}
683 /// Utility method to constructs a new BlindedPathAdvanceFailed-variant SendError
684 pub extern "C" fn SendError_blinded_path_advance_failed() -> SendError {
685 SendError::BlindedPathAdvanceFailed}
686 /// Checks if two SendErrors contain equal inner contents.
687 /// This ignores pointers and is_owned flags and looks at the values in fields.
689 pub extern "C" fn SendError_eq(a: &SendError, b: &SendError) -> bool {
690 if &a.to_native() == &b.to_native() { true } else { false }
692 /// Handler for custom onion messages. If you are using [`SimpleArcOnionMessenger`],
693 /// [`SimpleRefOnionMessenger`], or prefer to ignore inbound custom onion messages,
694 /// [`IgnoringMessageHandler`] must be provided to [`OnionMessenger::new`]. Otherwise, a custom
695 /// implementation of this trait must be provided, with [`CustomMessage`] specifying the supported
698 /// See [`OnionMessenger`] for example usage.
700 /// [`IgnoringMessageHandler`]: crate::ln::peer_handler::IgnoringMessageHandler
701 /// [`CustomMessage`]: Self::CustomMessage
703 pub struct CustomOnionMessageHandler {
704 /// An opaque pointer which is passed to your function implementations as an argument.
705 /// This has no meaning in the LDK, and can be NULL or any other value.
706 pub this_arg: *mut c_void,
707 /// Called with the custom message that was received, returning a response to send, if any.
709 /// The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`].
710 pub handle_custom_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::onion_message::packet::OnionMessageContents) -> crate::c_types::derived::COption_OnionMessageContentsZ,
711 /// Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
712 /// message type is unknown.
713 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_OnionMessageContentsZDecodeErrorZ,
714 /// Releases any [`Self::CustomMessage`]s that need to be sent.
716 /// Typically, this is used for messages initiating a message flow rather than in response to
717 /// another message. The latter should use the return value of [`Self::handle_custom_message`].
718 pub release_pending_custom_messages: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ,
719 /// Frees any resources associated with this object given its this_arg pointer.
720 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
721 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
723 unsafe impl Send for CustomOnionMessageHandler {}
724 unsafe impl Sync for CustomOnionMessageHandler {}
726 pub(crate) fn CustomOnionMessageHandler_clone_fields(orig: &CustomOnionMessageHandler) -> CustomOnionMessageHandler {
727 CustomOnionMessageHandler {
728 this_arg: orig.this_arg,
729 handle_custom_message: Clone::clone(&orig.handle_custom_message),
730 read_custom_message: Clone::clone(&orig.read_custom_message),
731 release_pending_custom_messages: Clone::clone(&orig.release_pending_custom_messages),
732 free: Clone::clone(&orig.free),
736 use lightning::onion_message::messenger::CustomOnionMessageHandler as rustCustomOnionMessageHandler;
737 impl rustCustomOnionMessageHandler for CustomOnionMessageHandler {
738 type CustomMessage = crate::lightning::onion_message::packet::OnionMessageContents;
739 fn handle_custom_message(&self, mut msg: crate::lightning::onion_message::packet::OnionMessageContents) -> Option<crate::lightning::onion_message::packet::OnionMessageContents> {
740 let mut ret = (self.handle_custom_message)(self.this_arg, Into::into(msg));
741 let mut local_ret = { /*ret*/ let ret_opt = ret; if ret_opt.is_none() { None } else { Some({ { { ret_opt.take() } }})} };
744 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::OnionMessageContents>, lightning::ln::msgs::DecodeError> {
745 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)));
746 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() })};
749 fn release_pending_custom_messages(&self) -> Vec<(crate::lightning::onion_message::packet::OnionMessageContents, lightning::onion_message::messenger::Destination, Option<lightning::blinded_path::BlindedPath>)> {
750 let mut ret = (self.release_pending_custom_messages)(self.this_arg);
751 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item.to_rust(); let mut local_orig_ret_0_2 = if orig_ret_0_2.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_2.take_inner()) } }) }; let mut local_ret_0 = (orig_ret_0_0, orig_ret_0_1.into_native(), local_orig_ret_0_2); local_ret_0 }); };
756 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
757 // directly as a Deref trait in higher-level structs:
758 impl core::ops::Deref for CustomOnionMessageHandler {
760 fn deref(&self) -> &Self {
764 impl core::ops::DerefMut for CustomOnionMessageHandler {
765 fn deref_mut(&mut self) -> &mut Self {
769 /// Calls the free function if one is set
771 pub extern "C" fn CustomOnionMessageHandler_free(this_ptr: CustomOnionMessageHandler) { }
772 impl Drop for CustomOnionMessageHandler {
774 if let Some(f) = self.free {
779 /// A processed incoming onion message, containing either a Forward (another onion message)
780 /// or a Receive payload with decrypted contents.
784 pub enum PeeledOnion {
785 /// Forwarded onion, with the next node id and a new onion
787 crate::c_types::PublicKey,
788 crate::lightning::ln::msgs::OnionMessage),
789 /// Received onion message, with decrypted contents, path_id, and reply path
791 crate::lightning::onion_message::packet::ParsedOnionMessageContents,
793 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
794 crate::c_types::ThirtyTwoBytes,
796 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
797 crate::lightning::blinded_path::BlindedPath),
799 use lightning::onion_message::messenger::PeeledOnion as PeeledOnionImport;
800 pub(crate) type nativePeeledOnion = PeeledOnionImport<crate::lightning::onion_message::packet::OnionMessageContents>;
804 pub(crate) fn to_native(&self) -> nativePeeledOnion {
806 PeeledOnion::Forward (ref a, ref b, ) => {
807 let mut a_nonref = Clone::clone(a);
808 let mut b_nonref = Clone::clone(b);
809 nativePeeledOnion::Forward (
810 a_nonref.into_rust(),
811 *unsafe { Box::from_raw(b_nonref.take_inner()) },
814 PeeledOnion::Receive (ref a, ref b, ref c, ) => {
815 let mut a_nonref = Clone::clone(a);
816 let mut b_nonref = Clone::clone(b);
817 let mut local_b_nonref = if b_nonref.data == [0; 32] { None } else { Some( { b_nonref.data }) };
818 let mut c_nonref = Clone::clone(c);
819 let mut local_c_nonref = if c_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(c_nonref.take_inner()) } }) };
820 nativePeeledOnion::Receive (
821 a_nonref.into_native(),
829 pub(crate) fn into_native(self) -> nativePeeledOnion {
831 PeeledOnion::Forward (mut a, mut b, ) => {
832 nativePeeledOnion::Forward (
834 *unsafe { Box::from_raw(b.take_inner()) },
837 PeeledOnion::Receive (mut a, mut b, mut c, ) => {
838 let mut local_b = if b.data == [0; 32] { None } else { Some( { b.data }) };
839 let mut local_c = if c.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(c.take_inner()) } }) };
840 nativePeeledOnion::Receive (
849 pub(crate) fn from_native(native: &nativePeeledOnion) -> Self {
851 nativePeeledOnion::Forward (ref a, ref b, ) => {
852 let mut a_nonref = Clone::clone(a);
853 let mut b_nonref = Clone::clone(b);
854 PeeledOnion::Forward (
855 crate::c_types::PublicKey::from_rust(&a_nonref),
856 crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(b_nonref), is_owned: true },
859 nativePeeledOnion::Receive (ref a, ref b, ref c, ) => {
860 let mut a_nonref = Clone::clone(a);
861 let mut b_nonref = Clone::clone(b);
862 let mut local_b_nonref = if b_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (b_nonref.unwrap()) } } };
863 let mut c_nonref = Clone::clone(c);
864 let mut local_c_nonref = crate::lightning::blinded_path::BlindedPath { inner: if c_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((c_nonref.unwrap())) } }, is_owned: true };
865 PeeledOnion::Receive (
866 crate::lightning::onion_message::packet::ParsedOnionMessageContents::native_into(a_nonref),
874 pub(crate) fn native_into(native: nativePeeledOnion) -> Self {
876 nativePeeledOnion::Forward (mut a, mut b, ) => {
877 PeeledOnion::Forward (
878 crate::c_types::PublicKey::from_rust(&a),
879 crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(b), is_owned: true },
882 nativePeeledOnion::Receive (mut a, mut b, mut c, ) => {
883 let mut local_b = if b.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (b.unwrap()) } } };
884 let mut local_c = crate::lightning::blinded_path::BlindedPath { inner: if c.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((c.unwrap())) } }, is_owned: true };
885 PeeledOnion::Receive (
886 crate::lightning::onion_message::packet::ParsedOnionMessageContents::native_into(a),
894 /// Frees any resources used by the PeeledOnion
896 pub extern "C" fn PeeledOnion_free(this_ptr: PeeledOnion) { }
897 /// Creates a copy of the PeeledOnion
899 pub extern "C" fn PeeledOnion_clone(orig: &PeeledOnion) -> PeeledOnion {
903 /// Used only if an object of this type is returned as a trait impl by a method
904 pub(crate) extern "C" fn PeeledOnion_clone_void(this_ptr: *const c_void) -> *mut c_void {
905 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PeeledOnion)).clone() })) as *mut c_void
908 /// Used only if an object of this type is returned as a trait impl by a method
909 pub(crate) extern "C" fn PeeledOnion_free_void(this_ptr: *mut c_void) {
910 let _ = unsafe { Box::from_raw(this_ptr as *mut PeeledOnion) };
913 /// Utility method to constructs a new Forward-variant PeeledOnion
914 pub extern "C" fn PeeledOnion_forward(a: crate::c_types::PublicKey,b: crate::lightning::ln::msgs::OnionMessage) -> PeeledOnion {
915 PeeledOnion::Forward(a, b, )
918 /// Utility method to constructs a new Receive-variant PeeledOnion
919 pub extern "C" fn PeeledOnion_receive(a: crate::lightning::onion_message::packet::ParsedOnionMessageContents,b: crate::c_types::ThirtyTwoBytes,c: crate::lightning::blinded_path::BlindedPath) -> PeeledOnion {
920 PeeledOnion::Receive(a, b, c, )
922 /// Creates an [`OnionMessage`] with the given `contents` for sending to the destination of
925 /// Returns both the node id of the peer to send the message to and the message itself.
927 /// Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None
929 pub extern "C" fn create_onion_message(entropy_source: &crate::lightning::sign::EntropySource, node_signer: &crate::lightning::sign::NodeSigner, mut path: crate::lightning::onion_message::messenger::OnionMessagePath, mut contents: crate::lightning::onion_message::packet::OnionMessageContents, mut reply_path: crate::lightning::blinded_path::BlindedPath) -> crate::c_types::derived::CResult_C2Tuple_PublicKeyOnionMessageZSendErrorZ {
930 let mut local_reply_path = if reply_path.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(reply_path.take_inner()) } }) };
931 let mut ret = lightning::onion_message::messenger::create_onion_message::<crate::lightning::sign::EntropySource, crate::lightning::sign::NodeSigner, crate::lightning::onion_message::packet::OnionMessageContents>(entropy_source, node_signer, secp256k1::global::SECP256K1, *unsafe { Box::from_raw(path.take_inner()) }, contents, local_reply_path);
932 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (crate::c_types::PublicKey::from_rust(&orig_ret_0_0), crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(orig_ret_0_1), is_owned: true }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::onion_message::messenger::SendError::native_into(e) }).into() };
936 /// Decode one layer of an incoming [`OnionMessage`].
938 /// Returns either the next layer of the onion for forwarding or the decrypted content for the
941 pub extern "C" fn peel_onion_message(msg: &crate::lightning::ln::msgs::OnionMessage, mut node_signer: crate::lightning::sign::NodeSigner, mut logger: crate::lightning::util::logger::Logger, mut custom_handler: crate::lightning::onion_message::messenger::CustomOnionMessageHandler) -> crate::c_types::derived::CResult_PeeledOnionNoneZ {
942 let mut ret = lightning::onion_message::messenger::peel_onion_message::<crate::lightning::sign::NodeSigner, crate::lightning::util::logger::Logger, crate::lightning::onion_message::messenger::CustomOnionMessageHandler>(msg.get_native_ref(), secp256k1::global::SECP256K1, node_signer, logger, custom_handler);
943 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::onion_message::messenger::PeeledOnion::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
947 /// Constructs a new `OnionMessenger` to send, forward, and delegate received onion messages to
948 /// their respective handlers.
951 pub extern "C" fn OnionMessenger_new(mut entropy_source: crate::lightning::sign::EntropySource, mut node_signer: crate::lightning::sign::NodeSigner, mut logger: crate::lightning::util::logger::Logger, mut message_router: crate::lightning::onion_message::messenger::MessageRouter, mut offers_handler: crate::lightning::onion_message::offers::OffersMessageHandler, mut custom_handler: crate::lightning::onion_message::messenger::CustomOnionMessageHandler) -> crate::lightning::onion_message::messenger::OnionMessenger {
952 let mut ret = lightning::onion_message::messenger::OnionMessenger::new(entropy_source, node_signer, logger, message_router, offers_handler, custom_handler);
953 crate::lightning::onion_message::messenger::OnionMessenger { inner: ObjOps::heap_alloc(ret), is_owned: true }
956 /// Sends an [`OnionMessage`] with the given `contents` for sending to the destination of
959 /// See [`OnionMessenger`] for example usage.
961 /// Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None
964 pub extern "C" fn OnionMessenger_send_onion_message(this_arg: &crate::lightning::onion_message::messenger::OnionMessenger, mut path: crate::lightning::onion_message::messenger::OnionMessagePath, mut contents: crate::lightning::onion_message::packet::OnionMessageContents, mut reply_path: crate::lightning::blinded_path::BlindedPath) -> crate::c_types::derived::CResult_NoneSendErrorZ {
965 let mut local_reply_path = if reply_path.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(reply_path.take_inner()) } }) };
966 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_onion_message(*unsafe { Box::from_raw(path.take_inner()) }, contents, local_reply_path);
967 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() };
971 impl From<nativeOnionMessenger> for crate::lightning::ln::msgs::OnionMessageHandler {
972 fn from(obj: nativeOnionMessenger) -> Self {
973 let rust_obj = crate::lightning::onion_message::messenger::OnionMessenger { inner: ObjOps::heap_alloc(obj), is_owned: true };
974 let mut ret = OnionMessenger_as_OnionMessageHandler(&rust_obj);
975 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
976 core::mem::forget(rust_obj);
977 ret.free = Some(OnionMessenger_free_void);
981 /// Constructs a new OnionMessageHandler which calls the relevant methods on this_arg.
982 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageHandler must be freed before this_arg is
984 pub extern "C" fn OnionMessenger_as_OnionMessageHandler(this_arg: &OnionMessenger) -> crate::lightning::ln::msgs::OnionMessageHandler {
985 crate::lightning::ln::msgs::OnionMessageHandler {
986 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
988 handle_onion_message: OnionMessenger_OnionMessageHandler_handle_onion_message,
989 next_onion_message_for_peer: OnionMessenger_OnionMessageHandler_next_onion_message_for_peer,
990 peer_connected: OnionMessenger_OnionMessageHandler_peer_connected,
991 peer_disconnected: OnionMessenger_OnionMessageHandler_peer_disconnected,
992 provided_node_features: OnionMessenger_OnionMessageHandler_provided_node_features,
993 provided_init_features: OnionMessenger_OnionMessageHandler_provided_init_features,
997 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) {
998 <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())
1001 extern "C" fn OnionMessenger_OnionMessageHandler_next_onion_message_for_peer(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage {
1002 let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::next_onion_message_for_peer(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, peer_node_id.into_rust());
1003 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 };
1007 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 {
1008 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);
1009 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() };
1012 extern "C" fn OnionMessenger_OnionMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
1013 <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust())
1016 extern "C" fn OnionMessenger_OnionMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
1017 let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, );
1018 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
1021 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 {
1022 let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust());
1023 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }