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::Sign, crate::lightning::chain::keysinterface::KeysInterface, 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::chain::keysinterface::{InMemorySigner, KeysManager, KeysInterface};
35 /// # use lightning::ln::msgs::DecodeError;
36 /// # use lightning::ln::peer_handler::IgnoringMessageHandler;
37 /// # use lightning::onion_message::messenger::{Destination, OnionMessenger};
38 /// # use lightning::onion_message::packet::CustomOnionMessageContents;
39 /// # use lightning::onion_message::blinded_route::BlindedRoute;
40 /// # use lightning::util::logger::{Logger, Record};
41 /// # use lightning::util::ser::{Writeable, Writer};
42 /// # use lightning::io;
43 /// # use std::sync::Arc;
44 /// # struct FakeLogger {};
45 /// # impl Logger for FakeLogger {
46 /// # fn log(&self, record: &Record) { unimplemented!() }
48 /// # let seed = [42u8; 32];
49 /// # let time = Duration::from_secs(123456);
50 /// # let keys_manager = KeysManager::new(&seed, time.as_secs(), time.subsec_nanos());
51 /// # let logger = Arc::new(FakeLogger {});
52 /// # let node_secret = SecretKey::from_slice(&hex::decode(\"0101010101010101010101010101010101010101010101010101010101010101\").unwrap()[..]).unwrap();
53 /// # let secp_ctx = Secp256k1::new();
54 /// # let hop_node_id1 = PublicKey::from_secret_key(&secp_ctx, &node_secret);
55 /// # let (hop_node_id2, hop_node_id3, hop_node_id4) = (hop_node_id1, hop_node_id1, hop_node_id1);
56 /// # let destination_node_id = hop_node_id1;
57 /// # let your_custom_message_handler = IgnoringMessageHandler {};
58 /// // Create the onion messenger. This must use the same `keys_manager` as is passed to your
59 /// // ChannelManager.
60 /// let onion_messenger = OnionMessenger::new(&keys_manager, logger, your_custom_message_handler);
62 /// # struct YourCustomMessage {}
63 /// impl Writeable for YourCustomMessage {
64 /// \tfn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
66 /// \t\t// Write your custom onion message to `w`
69 /// impl CustomOnionMessageContents for YourCustomMessage {
70 /// \tfn tlv_type(&self) -> u64 {
71 /// \t\t# let your_custom_message_type = 42;
72 /// \t\tyour_custom_message_type
75 /// // Send a custom onion message to a node id.
76 /// let intermediate_hops = [hop_node_id1, hop_node_id2];
77 /// let reply_path = None;
78 /// # let your_custom_message = YourCustomMessage {};
79 /// onion_messenger.send_custom_onion_message(&intermediate_hops, Destination::Node(destination_node_id), your_custom_message, reply_path);
81 /// // Create a blinded route 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_route = BlindedRoute::new(&hops, &keys_manager, &secp_ctx).unwrap();
86 /// // Send a custom onion message to a blinded route.
87 /// # let intermediate_hops = [hop_node_id1, hop_node_id2];
88 /// let reply_path = None;
89 /// # let your_custom_message = YourCustomMessage {};
90 /// onion_messenger.send_custom_onion_message(&intermediate_hops, Destination::BlindedRoute(blinded_route), your_custom_message, reply_path);
93 /// [offers]: <https://github.com/lightning/bolts/pull/798>
94 /// [`OnionMessenger`]: crate::onion_message::OnionMessenger
97 pub struct OnionMessenger {
98 /// A pointer to the opaque Rust object.
100 /// Nearly everywhere, inner must be non-null, however in places where
101 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
102 pub inner: *mut nativeOnionMessenger,
103 /// Indicates that this is the only struct which contains the same pointer.
105 /// Rust functions which take ownership of an object provided via an argument require
106 /// this to be true and invalidate the object pointed to by inner.
110 impl Drop for OnionMessenger {
112 if self.is_owned && !<*mut nativeOnionMessenger>::is_null(self.inner) {
113 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
117 /// Frees any resources used by the OnionMessenger, if is_owned is set and inner is non-NULL.
119 pub extern "C" fn OnionMessenger_free(this_obj: OnionMessenger) { }
121 /// Used only if an object of this type is returned as a trait impl by a method
122 pub(crate) extern "C" fn OnionMessenger_free_void(this_ptr: *mut c_void) {
123 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeOnionMessenger); }
126 impl OnionMessenger {
127 pub(crate) fn get_native_ref(&self) -> &'static nativeOnionMessenger {
128 unsafe { &*ObjOps::untweak_ptr(self.inner) }
130 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOnionMessenger {
131 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
133 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
134 pub(crate) fn take_inner(mut self) -> *mut nativeOnionMessenger {
135 assert!(self.is_owned);
136 let ret = ObjOps::untweak_ptr(self.inner);
137 self.inner = core::ptr::null_mut();
141 /// The destination of an onion message.
144 pub enum Destination {
145 /// We're sending this onion message to a node.
147 crate::c_types::PublicKey),
148 /// We're sending this onion message to a blinded route.
150 crate::lightning::onion_message::blinded_route::BlindedRoute),
152 use lightning::onion_message::messenger::Destination as DestinationImport;
153 pub(crate) type nativeDestination = DestinationImport;
157 pub(crate) fn into_native(self) -> nativeDestination {
159 Destination::Node (mut a, ) => {
160 nativeDestination::Node (
164 Destination::BlindedRoute (mut a, ) => {
165 nativeDestination::BlindedRoute (
166 *unsafe { Box::from_raw(a.take_inner()) },
172 pub(crate) fn native_into(native: nativeDestination) -> Self {
174 nativeDestination::Node (mut a, ) => {
176 crate::c_types::PublicKey::from_rust(&a),
179 nativeDestination::BlindedRoute (mut a, ) => {
180 Destination::BlindedRoute (
181 crate::lightning::onion_message::blinded_route::BlindedRoute { inner: ObjOps::heap_alloc(a), is_owned: true },
187 /// Frees any resources used by the Destination
189 pub extern "C" fn Destination_free(this_ptr: Destination) { }
191 /// Utility method to constructs a new Node-variant Destination
192 pub extern "C" fn Destination_node(a: crate::c_types::PublicKey) -> Destination {
193 Destination::Node(a, )
196 /// Utility method to constructs a new BlindedRoute-variant Destination
197 pub extern "C" fn Destination_blinded_route(a: crate::lightning::onion_message::blinded_route::BlindedRoute) -> Destination {
198 Destination::BlindedRoute(a, )
200 /// Errors that may occur when [sending an onion message].
202 /// [sending an onion message]: OnionMessenger::send_custom_onion_message
207 /// Errored computing onion message packet keys.
209 crate::c_types::Secp256k1Error),
210 /// Because implementations such as Eclair will drop onion messages where the message packet
211 /// exceeds 32834 bytes, we refuse to send messages where the packet exceeds this size.
213 /// The provided [`Destination`] was an invalid [`BlindedRoute`], due to having fewer than two
216 /// Our next-hop peer was offline or does not support onion message forwarding.
218 /// Onion message contents must have a TLV type >= 64.
220 /// Our next-hop peer's buffer was full or our total outbound buffer was full.
223 use lightning::onion_message::messenger::SendError as SendErrorImport;
224 pub(crate) type nativeSendError = SendErrorImport;
228 pub(crate) fn to_native(&self) -> nativeSendError {
230 SendError::Secp256k1 (ref a, ) => {
231 let mut a_nonref = (*a).clone();
232 nativeSendError::Secp256k1 (
233 a_nonref.into_rust(),
236 SendError::TooBigPacket => nativeSendError::TooBigPacket,
237 SendError::TooFewBlindedHops => nativeSendError::TooFewBlindedHops,
238 SendError::InvalidFirstHop => nativeSendError::InvalidFirstHop,
239 SendError::InvalidMessage => nativeSendError::InvalidMessage,
240 SendError::BufferFull => nativeSendError::BufferFull,
244 pub(crate) fn into_native(self) -> nativeSendError {
246 SendError::Secp256k1 (mut a, ) => {
247 nativeSendError::Secp256k1 (
251 SendError::TooBigPacket => nativeSendError::TooBigPacket,
252 SendError::TooFewBlindedHops => nativeSendError::TooFewBlindedHops,
253 SendError::InvalidFirstHop => nativeSendError::InvalidFirstHop,
254 SendError::InvalidMessage => nativeSendError::InvalidMessage,
255 SendError::BufferFull => nativeSendError::BufferFull,
259 pub(crate) fn from_native(native: &nativeSendError) -> Self {
261 nativeSendError::Secp256k1 (ref a, ) => {
262 let mut a_nonref = (*a).clone();
263 SendError::Secp256k1 (
264 crate::c_types::Secp256k1Error::from_rust(a_nonref),
267 nativeSendError::TooBigPacket => SendError::TooBigPacket,
268 nativeSendError::TooFewBlindedHops => SendError::TooFewBlindedHops,
269 nativeSendError::InvalidFirstHop => SendError::InvalidFirstHop,
270 nativeSendError::InvalidMessage => SendError::InvalidMessage,
271 nativeSendError::BufferFull => SendError::BufferFull,
275 pub(crate) fn native_into(native: nativeSendError) -> Self {
277 nativeSendError::Secp256k1 (mut a, ) => {
278 SendError::Secp256k1 (
279 crate::c_types::Secp256k1Error::from_rust(a),
282 nativeSendError::TooBigPacket => SendError::TooBigPacket,
283 nativeSendError::TooFewBlindedHops => SendError::TooFewBlindedHops,
284 nativeSendError::InvalidFirstHop => SendError::InvalidFirstHop,
285 nativeSendError::InvalidMessage => SendError::InvalidMessage,
286 nativeSendError::BufferFull => SendError::BufferFull,
290 /// Frees any resources used by the SendError
292 pub extern "C" fn SendError_free(this_ptr: SendError) { }
293 /// Creates a copy of the SendError
295 pub extern "C" fn SendError_clone(orig: &SendError) -> SendError {
299 /// Utility method to constructs a new Secp256k1-variant SendError
300 pub extern "C" fn SendError_secp256k1(a: crate::c_types::Secp256k1Error) -> SendError {
301 SendError::Secp256k1(a, )
304 /// Utility method to constructs a new TooBigPacket-variant SendError
305 pub extern "C" fn SendError_too_big_packet() -> SendError {
306 SendError::TooBigPacket}
308 /// Utility method to constructs a new TooFewBlindedHops-variant SendError
309 pub extern "C" fn SendError_too_few_blinded_hops() -> SendError {
310 SendError::TooFewBlindedHops}
312 /// Utility method to constructs a new InvalidFirstHop-variant SendError
313 pub extern "C" fn SendError_invalid_first_hop() -> SendError {
314 SendError::InvalidFirstHop}
316 /// Utility method to constructs a new InvalidMessage-variant SendError
317 pub extern "C" fn SendError_invalid_message() -> SendError {
318 SendError::InvalidMessage}
320 /// Utility method to constructs a new BufferFull-variant SendError
321 pub extern "C" fn SendError_buffer_full() -> SendError {
322 SendError::BufferFull}
323 /// Checks if two SendErrors contain equal inner contents.
324 /// This ignores pointers and is_owned flags and looks at the values in fields.
326 pub extern "C" fn SendError_eq(a: &SendError, b: &SendError) -> bool {
327 if &a.to_native() == &b.to_native() { true } else { false }
329 /// Handler for custom onion messages. If you are using [`SimpleArcOnionMessenger`],
330 /// [`SimpleRefOnionMessenger`], or prefer to ignore inbound custom onion messages,
331 /// [`IgnoringMessageHandler`] must be provided to [`OnionMessenger::new`]. Otherwise, a custom
332 /// implementation of this trait must be provided, with [`CustomMessage`] specifying the supported
335 /// See [`OnionMessenger`] for example usage.
337 /// [`IgnoringMessageHandler`]: crate::ln::peer_handler::IgnoringMessageHandler
338 /// [`CustomMessage`]: Self::CustomMessage
340 pub struct CustomOnionMessageHandler {
341 /// An opaque pointer which is passed to your function implementations as an argument.
342 /// This has no meaning in the LDK, and can be NULL or any other value.
343 pub this_arg: *mut c_void,
344 /// Called with the custom message that was received.
345 pub handle_custom_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::onion_message::packet::CustomOnionMessageContents),
346 /// Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
347 /// message type is unknown.
349 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,
350 /// Frees any resources associated with this object given its this_arg pointer.
351 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
352 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
354 unsafe impl Send for CustomOnionMessageHandler {}
355 unsafe impl Sync for CustomOnionMessageHandler {}
357 pub(crate) extern "C" fn CustomOnionMessageHandler_clone_fields(orig: &CustomOnionMessageHandler) -> CustomOnionMessageHandler {
358 CustomOnionMessageHandler {
359 this_arg: orig.this_arg,
360 handle_custom_message: Clone::clone(&orig.handle_custom_message),
361 read_custom_message: Clone::clone(&orig.read_custom_message),
362 free: Clone::clone(&orig.free),
366 use lightning::onion_message::messenger::CustomOnionMessageHandler as rustCustomOnionMessageHandler;
367 impl rustCustomOnionMessageHandler for CustomOnionMessageHandler {
368 type CustomMessage = crate::lightning::onion_message::packet::CustomOnionMessageContents;
369 fn handle_custom_message(&self, mut msg: crate::lightning::onion_message::packet::CustomOnionMessageContents) {
370 (self.handle_custom_message)(self.this_arg, Into::into(msg))
372 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> {
373 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)));
374 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() })};
379 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
380 // directly as a Deref trait in higher-level structs:
381 impl core::ops::Deref for CustomOnionMessageHandler {
383 fn deref(&self) -> &Self {
387 /// Calls the free function if one is set
389 pub extern "C" fn CustomOnionMessageHandler_free(this_ptr: CustomOnionMessageHandler) { }
390 impl Drop for CustomOnionMessageHandler {
392 if let Some(f) = self.free {
397 /// Constructs a new `OnionMessenger` to send, forward, and delegate received onion messages to
398 /// their respective handlers.
401 pub extern "C" fn OnionMessenger_new(mut keys_manager: crate::lightning::chain::keysinterface::KeysInterface, mut logger: crate::lightning::util::logger::Logger, mut custom_handler: crate::lightning::onion_message::messenger::CustomOnionMessageHandler) -> crate::lightning::onion_message::messenger::OnionMessenger {
402 let mut ret = lightning::onion_message::messenger::OnionMessenger::new(keys_manager, logger, custom_handler);
403 crate::lightning::onion_message::messenger::OnionMessenger { inner: ObjOps::heap_alloc(ret), is_owned: true }
406 /// Send an onion message with contents `message` to `destination`, routing it through `intermediate_nodes`.
407 /// See [`OnionMessenger`] for example usage.
409 /// Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None
412 pub extern "C" fn OnionMessenger_send_custom_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 msg: crate::lightning::onion_message::packet::CustomOnionMessageContents, mut reply_path: crate::lightning::onion_message::blinded_route::BlindedRoute) -> crate::c_types::derived::CResult_NoneSendErrorZ {
413 let mut local_intermediate_nodes = Vec::new(); for mut item in intermediate_nodes.into_rust().drain(..) { local_intermediate_nodes.push( { item.into_rust() }); };
414 let mut local_reply_path = if reply_path.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(reply_path.take_inner()) } }) };
415 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_custom_onion_message(&local_intermediate_nodes[..], destination.into_native(), msg, local_reply_path);
416 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() };
420 impl From<nativeOnionMessenger> for crate::lightning::ln::msgs::OnionMessageHandler {
421 fn from(obj: nativeOnionMessenger) -> Self {
422 let mut rust_obj = OnionMessenger { inner: ObjOps::heap_alloc(obj), is_owned: true };
423 let mut ret = OnionMessenger_as_OnionMessageHandler(&rust_obj);
424 // 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
425 rust_obj.inner = core::ptr::null_mut();
426 ret.free = Some(OnionMessenger_free_void);
430 /// Constructs a new OnionMessageHandler which calls the relevant methods on this_arg.
431 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageHandler must be freed before this_arg is
433 pub extern "C" fn OnionMessenger_as_OnionMessageHandler(this_arg: &OnionMessenger) -> crate::lightning::ln::msgs::OnionMessageHandler {
434 crate::lightning::ln::msgs::OnionMessageHandler {
435 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
437 handle_onion_message: OnionMessenger_OnionMessageHandler_handle_onion_message,
438 peer_connected: OnionMessenger_OnionMessageHandler_peer_connected,
439 peer_disconnected: OnionMessenger_OnionMessageHandler_peer_disconnected,
440 provided_node_features: OnionMessenger_OnionMessageHandler_provided_node_features,
441 provided_init_features: OnionMessenger_OnionMessageHandler_provided_init_features,
442 OnionMessageProvider: crate::lightning::util::events::OnionMessageProvider {
443 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
445 next_onion_message_for_peer: OnionMessenger_OnionMessageProvider_next_onion_message_for_peer,
450 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) {
451 <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())
454 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) -> crate::c_types::derived::CResult_NoneNoneZ {
455 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());
456 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() };
459 extern "C" fn OnionMessenger_OnionMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut no_connection_possible: bool) {
460 <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust(), no_connection_possible)
463 extern "C" fn OnionMessenger_OnionMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
464 let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, );
465 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
468 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 {
469 let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust());
470 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
473 impl From<nativeOnionMessenger> for crate::lightning::util::events::OnionMessageProvider {
474 fn from(obj: nativeOnionMessenger) -> Self {
475 let mut rust_obj = OnionMessenger { inner: ObjOps::heap_alloc(obj), is_owned: true };
476 let mut ret = OnionMessenger_as_OnionMessageProvider(&rust_obj);
477 // 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
478 rust_obj.inner = core::ptr::null_mut();
479 ret.free = Some(OnionMessenger_free_void);
483 /// Constructs a new OnionMessageProvider which calls the relevant methods on this_arg.
484 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageProvider must be freed before this_arg is
486 pub extern "C" fn OnionMessenger_as_OnionMessageProvider(this_arg: &OnionMessenger) -> crate::lightning::util::events::OnionMessageProvider {
487 crate::lightning::util::events::OnionMessageProvider {
488 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
490 next_onion_message_for_peer: OnionMessenger_OnionMessageProvider_next_onion_message_for_peer,
495 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 {
496 let mut ret = <nativeOnionMessenger as lightning::util::events::OnionMessageProvider<>>::next_onion_message_for_peer(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, peer_node_id.into_rust());
497 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 };