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 this [`OnionMessenger`], which lives here,
10 //! as well as various types, traits, and utilities that it uses.
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::blinded_path::NodeIdLookUp, 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::hashes::hex::FromHex;
47 /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey, self};
48 /// # use lightning::blinded_path::{BlindedPath, EmptyNodeIdLookUp};
49 /// # use lightning::sign::{EntropySource, KeysManager};
50 /// # use lightning::ln::peer_handler::IgnoringMessageHandler;
51 /// # use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath, OnionMessenger};
52 /// # use lightning::onion_message::packet::OnionMessageContents;
53 /// # use lightning::util::logger::{Logger, Record};
54 /// # use lightning::util::ser::{Writeable, Writer};
55 /// # use lightning::io;
56 /// # use std::sync::Arc;
57 /// # struct FakeLogger;
58 /// # impl Logger for FakeLogger {
59 /// # fn log(&self, record: Record) { println!(\"{:?}\" , record); }
61 /// # struct FakeMessageRouter {}
62 /// # impl MessageRouter for FakeMessageRouter {
63 /// # fn find_path(&self, sender: PublicKey, peers: Vec<PublicKey>, destination: Destination) -> Result<OnionMessagePath, ()> {
64 /// # let secp_ctx = Secp256k1::new();
65 /// # let node_secret = SecretKey::from_slice(&<Vec<u8>>::from_hex(\"0101010101010101010101010101010101010101010101010101010101010101\").unwrap()[..]).unwrap();
66 /// # let hop_node_id1 = PublicKey::from_secret_key(&secp_ctx, &node_secret);
67 /// # let hop_node_id2 = hop_node_id1;
68 /// # Ok(OnionMessagePath {
69 /// # intermediate_nodes: vec![hop_node_id1, hop_node_id2],
71 /// # first_node_addresses: None,
74 /// # fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
75 /// # &self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
76 /// # ) -> Result<Vec<BlindedPath>, ()> {
80 /// # let seed = [42u8; 32];
81 /// # let time = Duration::from_secs(123456);
82 /// # let keys_manager = KeysManager::new(&seed, time.as_secs(), time.subsec_nanos());
83 /// # let logger = Arc::new(FakeLogger {});
84 /// # let node_secret = SecretKey::from_slice(&<Vec<u8>>::from_hex(\"0101010101010101010101010101010101010101010101010101010101010101\").unwrap()[..]).unwrap();
85 /// # let secp_ctx = Secp256k1::new();
86 /// # let hop_node_id1 = PublicKey::from_secret_key(&secp_ctx, &node_secret);
87 /// # let (hop_node_id3, hop_node_id4) = (hop_node_id1, hop_node_id1);
88 /// # let destination_node_id = hop_node_id1;
89 /// # let node_id_lookup = EmptyNodeIdLookUp {};
90 /// # let message_router = Arc::new(FakeMessageRouter {});
91 /// # let custom_message_handler = IgnoringMessageHandler {};
92 /// # let offers_message_handler = IgnoringMessageHandler {};
93 /// // Create the onion messenger. This must use the same `keys_manager` as is passed to your
94 /// // ChannelManager.
95 /// let onion_messenger = OnionMessenger::new(
96 /// &keys_manager, &keys_manager, logger, &node_id_lookup, message_router,
97 /// &offers_message_handler, &custom_message_handler
100 /// # #[derive(Debug, Clone)]
101 /// # struct YourCustomMessage {}
102 /// impl Writeable for YourCustomMessage {
103 /// \tfn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
105 /// \t\t// Write your custom onion message to `w`
108 /// impl OnionMessageContents for YourCustomMessage {
109 /// \tfn tlv_type(&self) -> u64 {
110 /// \t\t# let your_custom_message_type = 42;
111 /// \t\tyour_custom_message_type
114 /// // Send a custom onion message to a node id.
115 /// let destination = Destination::Node(destination_node_id);
116 /// let reply_path = None;
117 /// # let message = YourCustomMessage {};
118 /// onion_messenger.send_onion_message(message, destination, reply_path);
120 /// // Create a blinded path to yourself, for someone to send an onion message to.
121 /// # let your_node_id = hop_node_id1;
122 /// let hops = [hop_node_id3, hop_node_id4, your_node_id];
123 /// let blinded_path = BlindedPath::new_for_message(&hops, &keys_manager, &secp_ctx).unwrap();
125 /// // Send a custom onion message to a blinded path.
126 /// let destination = Destination::BlindedPath(blinded_path);
127 /// let reply_path = None;
128 /// # let message = YourCustomMessage {};
129 /// onion_messenger.send_onion_message(message, destination, reply_path);
132 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
133 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
136 pub struct OnionMessenger {
137 /// A pointer to the opaque Rust object.
139 /// Nearly everywhere, inner must be non-null, however in places where
140 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
141 pub inner: *mut nativeOnionMessenger,
142 /// Indicates that this is the only struct which contains the same pointer.
144 /// Rust functions which take ownership of an object provided via an argument require
145 /// this to be true and invalidate the object pointed to by inner.
149 impl Drop for OnionMessenger {
151 if self.is_owned && !<*mut nativeOnionMessenger>::is_null(self.inner) {
152 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
156 /// Frees any resources used by the OnionMessenger, if is_owned is set and inner is non-NULL.
158 pub extern "C" fn OnionMessenger_free(this_obj: OnionMessenger) { }
160 /// Used only if an object of this type is returned as a trait impl by a method
161 pub(crate) extern "C" fn OnionMessenger_free_void(this_ptr: *mut c_void) {
162 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOnionMessenger) };
165 impl OnionMessenger {
166 pub(crate) fn get_native_ref(&self) -> &'static nativeOnionMessenger {
167 unsafe { &*ObjOps::untweak_ptr(self.inner) }
169 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOnionMessenger {
170 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
172 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
173 pub(crate) fn take_inner(mut self) -> *mut nativeOnionMessenger {
174 assert!(self.is_owned);
175 let ret = ObjOps::untweak_ptr(self.inner);
176 self.inner = core::ptr::null_mut();
180 /// A trait defining behavior for routing an [`OnionMessage`].
182 pub struct MessageRouter {
183 /// An opaque pointer which is passed to your function implementations as an argument.
184 /// This has no meaning in the LDK, and can be NULL or any other value.
185 pub this_arg: *mut c_void,
186 /// Returns a route for sending an [`OnionMessage`] to the given [`Destination`].
187 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,
188 /// Creates [`BlindedPath`]s to the `recipient` node. The nodes in `peers` are assumed to be
189 /// direct peers with the `recipient`.
190 pub create_blinded_paths: extern "C" fn (this_arg: *const c_void, recipient: crate::c_types::PublicKey, peers: crate::c_types::derived::CVec_PublicKeyZ) -> crate::c_types::derived::CResult_CVec_BlindedPathZNoneZ,
191 /// Frees any resources associated with this object given its this_arg pointer.
192 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
193 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
195 unsafe impl Send for MessageRouter {}
196 unsafe impl Sync for MessageRouter {}
198 pub(crate) fn MessageRouter_clone_fields(orig: &MessageRouter) -> MessageRouter {
200 this_arg: orig.this_arg,
201 find_path: Clone::clone(&orig.find_path),
202 create_blinded_paths: Clone::clone(&orig.create_blinded_paths),
203 free: Clone::clone(&orig.free),
207 use lightning::onion_message::messenger::MessageRouter as rustMessageRouter;
208 impl rustMessageRouter for MessageRouter {
209 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, ()> {
210 let mut local_peers = Vec::new(); for mut item in peers.drain(..) { local_peers.push( { crate::c_types::PublicKey::from_rust(&item) }); };
211 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));
212 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)) })*/ })};
215 fn create_blinded_paths<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, mut recipient: bitcoin::secp256k1::PublicKey, mut peers: Vec<bitcoin::secp256k1::PublicKey>, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<Vec<lightning::blinded_path::BlindedPath>, ()> {
216 let mut local_peers = Vec::new(); for mut item in peers.drain(..) { local_peers.push( { crate::c_types::PublicKey::from_rust(&item) }); };
217 let mut ret = (self.create_blinded_paths)(self.this_arg, crate::c_types::PublicKey::from_rust(&recipient), local_peers.into());
218 let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = Vec::new(); for mut item in (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust().drain(..) { local_ret_0.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
223 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
224 // directly as a Deref trait in higher-level structs:
225 impl core::ops::Deref for MessageRouter {
227 fn deref(&self) -> &Self {
231 impl core::ops::DerefMut for MessageRouter {
232 fn deref_mut(&mut self) -> &mut Self {
236 /// Calls the free function if one is set
238 pub extern "C" fn MessageRouter_free(this_ptr: MessageRouter) { }
239 impl Drop for MessageRouter {
241 if let Some(f) = self.free {
247 use lightning::onion_message::messenger::DefaultMessageRouter as nativeDefaultMessageRouterImport;
248 pub(crate) type nativeDefaultMessageRouter = nativeDefaultMessageRouterImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::util::logger::Logger, crate::lightning::sign::EntropySource, >;
250 /// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
253 pub struct DefaultMessageRouter {
254 /// A pointer to the opaque Rust object.
256 /// Nearly everywhere, inner must be non-null, however in places where
257 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
258 pub inner: *mut nativeDefaultMessageRouter,
259 /// Indicates that this is the only struct which contains the same pointer.
261 /// Rust functions which take ownership of an object provided via an argument require
262 /// this to be true and invalidate the object pointed to by inner.
266 impl Drop for DefaultMessageRouter {
268 if self.is_owned && !<*mut nativeDefaultMessageRouter>::is_null(self.inner) {
269 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
273 /// Frees any resources used by the DefaultMessageRouter, if is_owned is set and inner is non-NULL.
275 pub extern "C" fn DefaultMessageRouter_free(this_obj: DefaultMessageRouter) { }
277 /// Used only if an object of this type is returned as a trait impl by a method
278 pub(crate) extern "C" fn DefaultMessageRouter_free_void(this_ptr: *mut c_void) {
279 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDefaultMessageRouter) };
282 impl DefaultMessageRouter {
283 pub(crate) fn get_native_ref(&self) -> &'static nativeDefaultMessageRouter {
284 unsafe { &*ObjOps::untweak_ptr(self.inner) }
286 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDefaultMessageRouter {
287 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
289 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
290 pub(crate) fn take_inner(mut self) -> *mut nativeDefaultMessageRouter {
291 assert!(self.is_owned);
292 let ret = ObjOps::untweak_ptr(self.inner);
293 self.inner = core::ptr::null_mut();
297 /// Creates a [`DefaultMessageRouter`] using the given [`NetworkGraph`].
300 pub extern "C" fn DefaultMessageRouter_new(network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut entropy_source: crate::lightning::sign::EntropySource) -> crate::lightning::onion_message::messenger::DefaultMessageRouter {
301 let mut ret = lightning::onion_message::messenger::DefaultMessageRouter::new(network_graph.get_native_ref(), entropy_source);
302 crate::lightning::onion_message::messenger::DefaultMessageRouter { inner: ObjOps::heap_alloc(ret), is_owned: true }
305 impl From<nativeDefaultMessageRouter> for crate::lightning::onion_message::messenger::MessageRouter {
306 fn from(obj: nativeDefaultMessageRouter) -> Self {
307 let rust_obj = crate::lightning::onion_message::messenger::DefaultMessageRouter { inner: ObjOps::heap_alloc(obj), is_owned: true };
308 let mut ret = DefaultMessageRouter_as_MessageRouter(&rust_obj);
309 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
310 core::mem::forget(rust_obj);
311 ret.free = Some(DefaultMessageRouter_free_void);
315 /// Constructs a new MessageRouter which calls the relevant methods on this_arg.
316 /// This copies the `inner` pointer in this_arg and thus the returned MessageRouter must be freed before this_arg is
318 pub extern "C" fn DefaultMessageRouter_as_MessageRouter(this_arg: &DefaultMessageRouter) -> crate::lightning::onion_message::messenger::MessageRouter {
319 crate::lightning::onion_message::messenger::MessageRouter {
320 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
322 find_path: DefaultMessageRouter_MessageRouter_find_path,
323 create_blinded_paths: DefaultMessageRouter_MessageRouter_create_blinded_paths,
328 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 {
329 let mut local_peers = Vec::new(); for mut item in peers.into_rust().drain(..) { local_peers.push( { item.into_rust() }); };
330 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());
331 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() };
335 extern "C" fn DefaultMessageRouter_MessageRouter_create_blinded_paths(this_arg: *const c_void, mut recipient: crate::c_types::PublicKey, mut peers: crate::c_types::derived::CVec_PublicKeyZ) -> crate::c_types::derived::CResult_CVec_BlindedPathZNoneZ {
336 let mut local_peers = Vec::new(); for mut item in peers.into_rust().drain(..) { local_peers.push( { item.into_rust() }); };
337 let mut ret = <nativeDefaultMessageRouter as lightning::onion_message::messenger::MessageRouter>::create_blinded_paths(unsafe { &mut *(this_arg as *mut nativeDefaultMessageRouter) }, recipient.into_rust(), local_peers, secp256k1::global::SECP256K1);
338 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut item in o.drain(..) { local_ret_0.push( { crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
343 use lightning::onion_message::messenger::OnionMessagePath as nativeOnionMessagePathImport;
344 pub(crate) type nativeOnionMessagePath = nativeOnionMessagePathImport;
346 /// A path for sending an [`OnionMessage`].
349 pub struct OnionMessagePath {
350 /// A pointer to the opaque Rust object.
352 /// Nearly everywhere, inner must be non-null, however in places where
353 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
354 pub inner: *mut nativeOnionMessagePath,
355 /// Indicates that this is the only struct which contains the same pointer.
357 /// Rust functions which take ownership of an object provided via an argument require
358 /// this to be true and invalidate the object pointed to by inner.
362 impl Drop for OnionMessagePath {
364 if self.is_owned && !<*mut nativeOnionMessagePath>::is_null(self.inner) {
365 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
369 /// Frees any resources used by the OnionMessagePath, if is_owned is set and inner is non-NULL.
371 pub extern "C" fn OnionMessagePath_free(this_obj: OnionMessagePath) { }
373 /// Used only if an object of this type is returned as a trait impl by a method
374 pub(crate) extern "C" fn OnionMessagePath_free_void(this_ptr: *mut c_void) {
375 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOnionMessagePath) };
378 impl OnionMessagePath {
379 pub(crate) fn get_native_ref(&self) -> &'static nativeOnionMessagePath {
380 unsafe { &*ObjOps::untweak_ptr(self.inner) }
382 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOnionMessagePath {
383 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
385 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
386 pub(crate) fn take_inner(mut self) -> *mut nativeOnionMessagePath {
387 assert!(self.is_owned);
388 let ret = ObjOps::untweak_ptr(self.inner);
389 self.inner = core::ptr::null_mut();
393 /// Nodes on the path between the sender and the destination.
395 /// Returns a copy of the field.
397 pub extern "C" fn OnionMessagePath_get_intermediate_nodes(this_ptr: &OnionMessagePath) -> crate::c_types::derived::CVec_PublicKeyZ {
398 let mut inner_val = this_ptr.get_native_mut_ref().intermediate_nodes.clone();
399 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) }); };
400 local_inner_val.into()
402 /// Nodes on the path between the sender and the destination.
404 pub extern "C" fn OnionMessagePath_set_intermediate_nodes(this_ptr: &mut OnionMessagePath, mut val: crate::c_types::derived::CVec_PublicKeyZ) {
405 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); };
406 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.intermediate_nodes = local_val;
408 /// The recipient of the message.
410 pub extern "C" fn OnionMessagePath_get_destination(this_ptr: &OnionMessagePath) -> crate::lightning::onion_message::messenger::Destination {
411 let mut inner_val = &mut this_ptr.get_native_mut_ref().destination;
412 crate::lightning::onion_message::messenger::Destination::from_native(inner_val)
414 /// The recipient of the message.
416 pub extern "C" fn OnionMessagePath_set_destination(this_ptr: &mut OnionMessagePath, mut val: crate::lightning::onion_message::messenger::Destination) {
417 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.destination = val.into_native();
419 /// Addresses that may be used to connect to [`OnionMessagePath::first_node`].
421 /// Only needs to be set if a connection to the node is required. [`OnionMessenger`] may use
422 /// this to initiate such a connection.
424 /// Returns a copy of the field.
426 pub extern "C" fn OnionMessagePath_get_first_node_addresses(this_ptr: &OnionMessagePath) -> crate::c_types::derived::COption_CVec_SocketAddressZZ {
427 let mut inner_val = this_ptr.get_native_mut_ref().first_node_addresses.clone();
428 let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_SocketAddressZZ::None } else { crate::c_types::derived::COption_CVec_SocketAddressZZ::Some( { let mut local_inner_val_0 = Vec::new(); for mut item in inner_val.unwrap().drain(..) { local_inner_val_0.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; local_inner_val_0.into() }) };
431 /// Addresses that may be used to connect to [`OnionMessagePath::first_node`].
433 /// Only needs to be set if a connection to the node is required. [`OnionMessenger`] may use
434 /// this to initiate such a connection.
436 pub extern "C" fn OnionMessagePath_set_first_node_addresses(this_ptr: &mut OnionMessagePath, mut val: crate::c_types::derived::COption_CVec_SocketAddressZZ) {
437 let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { let mut local_val_0 = Vec::new(); for mut item in { val_opt.take() }.into_rust().drain(..) { local_val_0.push( { item.into_native() }); }; local_val_0 }})} };
438 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.first_node_addresses = local_val;
440 /// Constructs a new OnionMessagePath given each field
443 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, mut first_node_addresses_arg: crate::c_types::derived::COption_CVec_SocketAddressZZ) -> OnionMessagePath {
444 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() }); };
445 let mut local_first_node_addresses_arg = { /*first_node_addresses_arg*/ let first_node_addresses_arg_opt = first_node_addresses_arg; if first_node_addresses_arg_opt.is_none() { None } else { Some({ { let mut local_first_node_addresses_arg_0 = Vec::new(); for mut item in { first_node_addresses_arg_opt.take() }.into_rust().drain(..) { local_first_node_addresses_arg_0.push( { item.into_native() }); }; local_first_node_addresses_arg_0 }})} };
446 OnionMessagePath { inner: ObjOps::heap_alloc(nativeOnionMessagePath {
447 intermediate_nodes: local_intermediate_nodes_arg,
448 destination: destination_arg.into_native(),
449 first_node_addresses: local_first_node_addresses_arg,
452 impl Clone for OnionMessagePath {
453 fn clone(&self) -> Self {
455 inner: if <*mut nativeOnionMessagePath>::is_null(self.inner) { core::ptr::null_mut() } else {
456 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
462 /// Used only if an object of this type is returned as a trait impl by a method
463 pub(crate) extern "C" fn OnionMessagePath_clone_void(this_ptr: *const c_void) -> *mut c_void {
464 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOnionMessagePath)).clone() })) as *mut c_void
467 /// Creates a copy of the OnionMessagePath
468 pub extern "C" fn OnionMessagePath_clone(orig: &OnionMessagePath) -> OnionMessagePath {
471 /// Returns the first node in the path.
473 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
476 pub extern "C" fn OnionMessagePath_first_node(this_arg: &crate::lightning::onion_message::messenger::OnionMessagePath) -> crate::c_types::PublicKey {
477 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.first_node();
478 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
482 /// The destination of an onion message.
486 pub enum Destination {
487 /// We're sending this onion message to a node.
489 crate::c_types::PublicKey),
490 /// We're sending this onion message to a blinded path.
492 crate::lightning::blinded_path::BlindedPath),
494 use lightning::onion_message::messenger::Destination as DestinationImport;
495 pub(crate) type nativeDestination = DestinationImport;
499 pub(crate) fn to_native(&self) -> nativeDestination {
501 Destination::Node (ref a, ) => {
502 let mut a_nonref = Clone::clone(a);
503 nativeDestination::Node (
504 a_nonref.into_rust(),
507 Destination::BlindedPath (ref a, ) => {
508 let mut a_nonref = Clone::clone(a);
509 nativeDestination::BlindedPath (
510 *unsafe { Box::from_raw(a_nonref.take_inner()) },
516 pub(crate) fn into_native(self) -> nativeDestination {
518 Destination::Node (mut a, ) => {
519 nativeDestination::Node (
523 Destination::BlindedPath (mut a, ) => {
524 nativeDestination::BlindedPath (
525 *unsafe { Box::from_raw(a.take_inner()) },
531 pub(crate) fn from_native(native: &DestinationImport) -> Self {
532 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeDestination) };
534 nativeDestination::Node (ref a, ) => {
535 let mut a_nonref = Clone::clone(a);
537 crate::c_types::PublicKey::from_rust(&a_nonref),
540 nativeDestination::BlindedPath (ref a, ) => {
541 let mut a_nonref = Clone::clone(a);
542 Destination::BlindedPath (
543 crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
549 pub(crate) fn native_into(native: nativeDestination) -> Self {
551 nativeDestination::Node (mut a, ) => {
553 crate::c_types::PublicKey::from_rust(&a),
556 nativeDestination::BlindedPath (mut a, ) => {
557 Destination::BlindedPath (
558 crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(a), is_owned: true },
564 /// Frees any resources used by the Destination
566 pub extern "C" fn Destination_free(this_ptr: Destination) { }
567 /// Creates a copy of the Destination
569 pub extern "C" fn Destination_clone(orig: &Destination) -> Destination {
573 /// Used only if an object of this type is returned as a trait impl by a method
574 pub(crate) extern "C" fn Destination_clone_void(this_ptr: *const c_void) -> *mut c_void {
575 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Destination)).clone() })) as *mut c_void
578 /// Used only if an object of this type is returned as a trait impl by a method
579 pub(crate) extern "C" fn Destination_free_void(this_ptr: *mut c_void) {
580 let _ = unsafe { Box::from_raw(this_ptr as *mut Destination) };
583 /// Utility method to constructs a new Node-variant Destination
584 pub extern "C" fn Destination_node(a: crate::c_types::PublicKey) -> Destination {
585 Destination::Node(a, )
588 /// Utility method to constructs a new BlindedPath-variant Destination
589 pub extern "C" fn Destination_blinded_path(a: crate::lightning::blinded_path::BlindedPath) -> Destination {
590 Destination::BlindedPath(a, )
592 /// Generates a non-cryptographic 64-bit hash of the Destination.
594 pub extern "C" fn Destination_hash(o: &Destination) -> u64 {
595 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
597 let mut hasher = core::hash::SipHasher::new();
598 core::hash::Hash::hash(&o.to_native(), &mut hasher);
599 core::hash::Hasher::finish(&hasher)
601 /// Get a string which allows debug introspection of a Destination object
602 pub extern "C" fn Destination_debug_str_void(o: *const c_void) -> Str {
603 alloc::format!("{:?}", unsafe { o as *const crate::lightning::onion_message::messenger::Destination }).into()}
604 /// Checks if two Destinations contain equal inner contents.
605 /// This ignores pointers and is_owned flags and looks at the values in fields.
607 pub extern "C" fn Destination_eq(a: &Destination, b: &Destination) -> bool {
608 if &a.to_native() == &b.to_native() { true } else { false }
610 /// Attempts to resolve the [`IntroductionNode::DirectedShortChannelId`] of a
611 /// [`Destination::BlindedPath`] to a [`IntroductionNode::NodeId`], if applicable, using the
612 /// provided [`ReadOnlyNetworkGraph`].
614 pub extern "C" fn Destination_resolve(this_arg: &mut crate::lightning::onion_message::messenger::Destination, network_graph: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph) {
615 this_arg.to_native().resolve(network_graph.get_native_ref())
618 /// Result of successfully [sending an onion message].
620 /// [sending an onion message]: OnionMessenger::send_onion_message
624 pub enum SendSuccess {
625 /// The message was buffered and will be sent once it is processed by
626 /// [`OnionMessageHandler::next_onion_message_for_peer`].
628 /// The message was buffered and will be sent once the node is connected as a peer and it is
629 /// processed by [`OnionMessageHandler::next_onion_message_for_peer`].
630 BufferedAwaitingConnection(
631 crate::c_types::PublicKey),
633 use lightning::onion_message::messenger::SendSuccess as SendSuccessImport;
634 pub(crate) type nativeSendSuccess = SendSuccessImport;
638 pub(crate) fn to_native(&self) -> nativeSendSuccess {
640 SendSuccess::Buffered => nativeSendSuccess::Buffered,
641 SendSuccess::BufferedAwaitingConnection (ref a, ) => {
642 let mut a_nonref = Clone::clone(a);
643 nativeSendSuccess::BufferedAwaitingConnection (
644 a_nonref.into_rust(),
650 pub(crate) fn into_native(self) -> nativeSendSuccess {
652 SendSuccess::Buffered => nativeSendSuccess::Buffered,
653 SendSuccess::BufferedAwaitingConnection (mut a, ) => {
654 nativeSendSuccess::BufferedAwaitingConnection (
661 pub(crate) fn from_native(native: &SendSuccessImport) -> Self {
662 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeSendSuccess) };
664 nativeSendSuccess::Buffered => SendSuccess::Buffered,
665 nativeSendSuccess::BufferedAwaitingConnection (ref a, ) => {
666 let mut a_nonref = Clone::clone(a);
667 SendSuccess::BufferedAwaitingConnection (
668 crate::c_types::PublicKey::from_rust(&a_nonref),
674 pub(crate) fn native_into(native: nativeSendSuccess) -> Self {
676 nativeSendSuccess::Buffered => SendSuccess::Buffered,
677 nativeSendSuccess::BufferedAwaitingConnection (mut a, ) => {
678 SendSuccess::BufferedAwaitingConnection (
679 crate::c_types::PublicKey::from_rust(&a),
685 /// Frees any resources used by the SendSuccess
687 pub extern "C" fn SendSuccess_free(this_ptr: SendSuccess) { }
688 /// Creates a copy of the SendSuccess
690 pub extern "C" fn SendSuccess_clone(orig: &SendSuccess) -> SendSuccess {
694 /// Used only if an object of this type is returned as a trait impl by a method
695 pub(crate) extern "C" fn SendSuccess_clone_void(this_ptr: *const c_void) -> *mut c_void {
696 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SendSuccess)).clone() })) as *mut c_void
699 /// Used only if an object of this type is returned as a trait impl by a method
700 pub(crate) extern "C" fn SendSuccess_free_void(this_ptr: *mut c_void) {
701 let _ = unsafe { Box::from_raw(this_ptr as *mut SendSuccess) };
704 /// Utility method to constructs a new Buffered-variant SendSuccess
705 pub extern "C" fn SendSuccess_buffered() -> SendSuccess {
706 SendSuccess::Buffered}
708 /// Utility method to constructs a new BufferedAwaitingConnection-variant SendSuccess
709 pub extern "C" fn SendSuccess_buffered_awaiting_connection(a: crate::c_types::PublicKey) -> SendSuccess {
710 SendSuccess::BufferedAwaitingConnection(a, )
712 /// Generates a non-cryptographic 64-bit hash of the SendSuccess.
714 pub extern "C" fn SendSuccess_hash(o: &SendSuccess) -> u64 {
715 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
717 let mut hasher = core::hash::SipHasher::new();
718 core::hash::Hash::hash(&o.to_native(), &mut hasher);
719 core::hash::Hasher::finish(&hasher)
721 /// Get a string which allows debug introspection of a SendSuccess object
722 pub extern "C" fn SendSuccess_debug_str_void(o: *const c_void) -> Str {
723 alloc::format!("{:?}", unsafe { o as *const crate::lightning::onion_message::messenger::SendSuccess }).into()}
724 /// Checks if two SendSuccesss contain equal inner contents.
725 /// This ignores pointers and is_owned flags and looks at the values in fields.
727 pub extern "C" fn SendSuccess_eq(a: &SendSuccess, b: &SendSuccess) -> bool {
728 if &a.to_native() == &b.to_native() { true } else { false }
730 /// Errors that may occur when [sending an onion message].
732 /// [sending an onion message]: OnionMessenger::send_onion_message
737 /// Errored computing onion message packet keys.
739 crate::c_types::Secp256k1Error),
740 /// Because implementations such as Eclair will drop onion messages where the message packet
741 /// exceeds 32834 bytes, we refuse to send messages where the packet exceeds this size.
743 /// The provided [`Destination`] was an invalid [`BlindedPath`] due to not having any blinded
746 /// The first hop is not a peer and doesn't have a known [`SocketAddress`].
748 crate::c_types::PublicKey),
749 /// A path from the sender to the destination could not be found by the [`MessageRouter`].
751 /// Onion message contents must have a TLV type >= 64.
753 /// Our next-hop peer's buffer was full or our total outbound buffer was full.
755 /// Failed to retrieve our node id from the provided [`NodeSigner`].
757 /// [`NodeSigner`]: crate::sign::NodeSigner
759 /// The provided [`Destination`] has a blinded path with an unresolved introduction node. An
760 /// attempt to resolve it in the [`MessageRouter`] when finding an [`OnionMessagePath`] likely
762 UnresolvedIntroductionNode,
763 /// We attempted to send to a blinded path where we are the introduction node, and failed to
764 /// advance the blinded path to make the second hop the new introduction node. Either
765 /// [`NodeSigner::ecdh`] failed, we failed to tweak the current blinding point to get the
766 /// new blinding point, or we were attempting to send to ourselves.
767 BlindedPathAdvanceFailed,
769 use lightning::onion_message::messenger::SendError as SendErrorImport;
770 pub(crate) type nativeSendError = SendErrorImport;
774 pub(crate) fn to_native(&self) -> nativeSendError {
776 SendError::Secp256k1 (ref a, ) => {
777 let mut a_nonref = Clone::clone(a);
778 nativeSendError::Secp256k1 (
779 a_nonref.into_rust(),
782 SendError::TooBigPacket => nativeSendError::TooBigPacket,
783 SendError::TooFewBlindedHops => nativeSendError::TooFewBlindedHops,
784 SendError::InvalidFirstHop (ref a, ) => {
785 let mut a_nonref = Clone::clone(a);
786 nativeSendError::InvalidFirstHop (
787 a_nonref.into_rust(),
790 SendError::PathNotFound => nativeSendError::PathNotFound,
791 SendError::InvalidMessage => nativeSendError::InvalidMessage,
792 SendError::BufferFull => nativeSendError::BufferFull,
793 SendError::GetNodeIdFailed => nativeSendError::GetNodeIdFailed,
794 SendError::UnresolvedIntroductionNode => nativeSendError::UnresolvedIntroductionNode,
795 SendError::BlindedPathAdvanceFailed => nativeSendError::BlindedPathAdvanceFailed,
799 pub(crate) fn into_native(self) -> nativeSendError {
801 SendError::Secp256k1 (mut a, ) => {
802 nativeSendError::Secp256k1 (
806 SendError::TooBigPacket => nativeSendError::TooBigPacket,
807 SendError::TooFewBlindedHops => nativeSendError::TooFewBlindedHops,
808 SendError::InvalidFirstHop (mut a, ) => {
809 nativeSendError::InvalidFirstHop (
813 SendError::PathNotFound => nativeSendError::PathNotFound,
814 SendError::InvalidMessage => nativeSendError::InvalidMessage,
815 SendError::BufferFull => nativeSendError::BufferFull,
816 SendError::GetNodeIdFailed => nativeSendError::GetNodeIdFailed,
817 SendError::UnresolvedIntroductionNode => nativeSendError::UnresolvedIntroductionNode,
818 SendError::BlindedPathAdvanceFailed => nativeSendError::BlindedPathAdvanceFailed,
822 pub(crate) fn from_native(native: &SendErrorImport) -> Self {
823 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeSendError) };
825 nativeSendError::Secp256k1 (ref a, ) => {
826 let mut a_nonref = Clone::clone(a);
827 SendError::Secp256k1 (
828 crate::c_types::Secp256k1Error::from_rust(a_nonref),
831 nativeSendError::TooBigPacket => SendError::TooBigPacket,
832 nativeSendError::TooFewBlindedHops => SendError::TooFewBlindedHops,
833 nativeSendError::InvalidFirstHop (ref a, ) => {
834 let mut a_nonref = Clone::clone(a);
835 SendError::InvalidFirstHop (
836 crate::c_types::PublicKey::from_rust(&a_nonref),
839 nativeSendError::PathNotFound => SendError::PathNotFound,
840 nativeSendError::InvalidMessage => SendError::InvalidMessage,
841 nativeSendError::BufferFull => SendError::BufferFull,
842 nativeSendError::GetNodeIdFailed => SendError::GetNodeIdFailed,
843 nativeSendError::UnresolvedIntroductionNode => SendError::UnresolvedIntroductionNode,
844 nativeSendError::BlindedPathAdvanceFailed => SendError::BlindedPathAdvanceFailed,
848 pub(crate) fn native_into(native: nativeSendError) -> Self {
850 nativeSendError::Secp256k1 (mut a, ) => {
851 SendError::Secp256k1 (
852 crate::c_types::Secp256k1Error::from_rust(a),
855 nativeSendError::TooBigPacket => SendError::TooBigPacket,
856 nativeSendError::TooFewBlindedHops => SendError::TooFewBlindedHops,
857 nativeSendError::InvalidFirstHop (mut a, ) => {
858 SendError::InvalidFirstHop (
859 crate::c_types::PublicKey::from_rust(&a),
862 nativeSendError::PathNotFound => SendError::PathNotFound,
863 nativeSendError::InvalidMessage => SendError::InvalidMessage,
864 nativeSendError::BufferFull => SendError::BufferFull,
865 nativeSendError::GetNodeIdFailed => SendError::GetNodeIdFailed,
866 nativeSendError::UnresolvedIntroductionNode => SendError::UnresolvedIntroductionNode,
867 nativeSendError::BlindedPathAdvanceFailed => SendError::BlindedPathAdvanceFailed,
871 /// Frees any resources used by the SendError
873 pub extern "C" fn SendError_free(this_ptr: SendError) { }
874 /// Creates a copy of the SendError
876 pub extern "C" fn SendError_clone(orig: &SendError) -> SendError {
880 /// Used only if an object of this type is returned as a trait impl by a method
881 pub(crate) extern "C" fn SendError_clone_void(this_ptr: *const c_void) -> *mut c_void {
882 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SendError)).clone() })) as *mut c_void
885 /// Used only if an object of this type is returned as a trait impl by a method
886 pub(crate) extern "C" fn SendError_free_void(this_ptr: *mut c_void) {
887 let _ = unsafe { Box::from_raw(this_ptr as *mut SendError) };
890 /// Utility method to constructs a new Secp256k1-variant SendError
891 pub extern "C" fn SendError_secp256k1(a: crate::c_types::Secp256k1Error) -> SendError {
892 SendError::Secp256k1(a, )
895 /// Utility method to constructs a new TooBigPacket-variant SendError
896 pub extern "C" fn SendError_too_big_packet() -> SendError {
897 SendError::TooBigPacket}
899 /// Utility method to constructs a new TooFewBlindedHops-variant SendError
900 pub extern "C" fn SendError_too_few_blinded_hops() -> SendError {
901 SendError::TooFewBlindedHops}
903 /// Utility method to constructs a new InvalidFirstHop-variant SendError
904 pub extern "C" fn SendError_invalid_first_hop(a: crate::c_types::PublicKey) -> SendError {
905 SendError::InvalidFirstHop(a, )
908 /// Utility method to constructs a new PathNotFound-variant SendError
909 pub extern "C" fn SendError_path_not_found() -> SendError {
910 SendError::PathNotFound}
912 /// Utility method to constructs a new InvalidMessage-variant SendError
913 pub extern "C" fn SendError_invalid_message() -> SendError {
914 SendError::InvalidMessage}
916 /// Utility method to constructs a new BufferFull-variant SendError
917 pub extern "C" fn SendError_buffer_full() -> SendError {
918 SendError::BufferFull}
920 /// Utility method to constructs a new GetNodeIdFailed-variant SendError
921 pub extern "C" fn SendError_get_node_id_failed() -> SendError {
922 SendError::GetNodeIdFailed}
924 /// Utility method to constructs a new UnresolvedIntroductionNode-variant SendError
925 pub extern "C" fn SendError_unresolved_introduction_node() -> SendError {
926 SendError::UnresolvedIntroductionNode}
928 /// Utility method to constructs a new BlindedPathAdvanceFailed-variant SendError
929 pub extern "C" fn SendError_blinded_path_advance_failed() -> SendError {
930 SendError::BlindedPathAdvanceFailed}
931 /// Generates a non-cryptographic 64-bit hash of the SendError.
933 pub extern "C" fn SendError_hash(o: &SendError) -> u64 {
934 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
936 let mut hasher = core::hash::SipHasher::new();
937 core::hash::Hash::hash(&o.to_native(), &mut hasher);
938 core::hash::Hasher::finish(&hasher)
940 /// Get a string which allows debug introspection of a SendError object
941 pub extern "C" fn SendError_debug_str_void(o: *const c_void) -> Str {
942 alloc::format!("{:?}", unsafe { o as *const crate::lightning::onion_message::messenger::SendError }).into()}
943 /// Checks if two SendErrors contain equal inner contents.
944 /// This ignores pointers and is_owned flags and looks at the values in fields.
946 pub extern "C" fn SendError_eq(a: &SendError, b: &SendError) -> bool {
947 if &a.to_native() == &b.to_native() { true } else { false }
949 /// Handler for custom onion messages. If you are using [`SimpleArcOnionMessenger`],
950 /// [`SimpleRefOnionMessenger`], or prefer to ignore inbound custom onion messages,
951 /// [`IgnoringMessageHandler`] must be provided to [`OnionMessenger::new`]. Otherwise, a custom
952 /// implementation of this trait must be provided, with [`CustomMessage`] specifying the supported
955 /// See [`OnionMessenger`] for example usage.
957 /// [`IgnoringMessageHandler`]: crate::ln::peer_handler::IgnoringMessageHandler
958 /// [`CustomMessage`]: Self::CustomMessage
960 pub struct CustomOnionMessageHandler {
961 /// An opaque pointer which is passed to your function implementations as an argument.
962 /// This has no meaning in the LDK, and can be NULL or any other value.
963 pub this_arg: *mut c_void,
964 /// Called with the custom message that was received, returning a response to send, if any.
966 /// The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`].
967 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,
968 /// Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
969 /// message type is unknown.
970 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,
971 /// Releases any [`Self::CustomMessage`]s that need to be sent.
973 /// Typically, this is used for messages initiating a message flow rather than in response to
974 /// another message. The latter should use the return value of [`Self::handle_custom_message`].
975 pub release_pending_custom_messages: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ,
976 /// Frees any resources associated with this object given its this_arg pointer.
977 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
978 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
980 unsafe impl Send for CustomOnionMessageHandler {}
981 unsafe impl Sync for CustomOnionMessageHandler {}
983 pub(crate) fn CustomOnionMessageHandler_clone_fields(orig: &CustomOnionMessageHandler) -> CustomOnionMessageHandler {
984 CustomOnionMessageHandler {
985 this_arg: orig.this_arg,
986 handle_custom_message: Clone::clone(&orig.handle_custom_message),
987 read_custom_message: Clone::clone(&orig.read_custom_message),
988 release_pending_custom_messages: Clone::clone(&orig.release_pending_custom_messages),
989 free: Clone::clone(&orig.free),
993 use lightning::onion_message::messenger::CustomOnionMessageHandler as rustCustomOnionMessageHandler;
994 impl rustCustomOnionMessageHandler for CustomOnionMessageHandler {
995 type CustomMessage = crate::lightning::onion_message::packet::OnionMessageContents;
996 fn handle_custom_message(&self, mut msg: crate::lightning::onion_message::packet::OnionMessageContents) -> Option<crate::lightning::onion_message::packet::OnionMessageContents> {
997 let mut ret = (self.handle_custom_message)(self.this_arg, Into::into(msg));
998 let mut local_ret = { /*ret*/ let ret_opt = ret; if ret_opt.is_none() { None } else { Some({ { { ret_opt.take() } }})} };
1001 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> {
1002 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)));
1003 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() })};
1006 fn release_pending_custom_messages(&self) -> Vec<(crate::lightning::onion_message::packet::OnionMessageContents, lightning::onion_message::messenger::Destination, Option<lightning::blinded_path::BlindedPath>)> {
1007 let mut ret = (self.release_pending_custom_messages)(self.this_arg);
1008 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 }); };
1013 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1014 // directly as a Deref trait in higher-level structs:
1015 impl core::ops::Deref for CustomOnionMessageHandler {
1017 fn deref(&self) -> &Self {
1021 impl core::ops::DerefMut for CustomOnionMessageHandler {
1022 fn deref_mut(&mut self) -> &mut Self {
1026 /// Calls the free function if one is set
1028 pub extern "C" fn CustomOnionMessageHandler_free(this_ptr: CustomOnionMessageHandler) { }
1029 impl Drop for CustomOnionMessageHandler {
1030 fn drop(&mut self) {
1031 if let Some(f) = self.free {
1036 /// A processed incoming onion message, containing either a Forward (another onion message)
1037 /// or a Receive payload with decrypted contents.
1041 pub enum PeeledOnion {
1042 /// Forwarded onion, with the next node id and a new onion
1044 crate::lightning::blinded_path::NextMessageHop,
1045 crate::lightning::ln::msgs::OnionMessage),
1046 /// Received onion message, with decrypted contents, path_id, and reply path
1048 crate::lightning::onion_message::packet::ParsedOnionMessageContents,
1050 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1051 crate::c_types::ThirtyTwoBytes,
1053 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1054 crate::lightning::blinded_path::BlindedPath),
1056 use lightning::onion_message::messenger::PeeledOnion as PeeledOnionImport;
1057 pub(crate) type nativePeeledOnion = PeeledOnionImport<crate::lightning::onion_message::packet::OnionMessageContents, >;
1061 pub(crate) fn to_native(&self) -> nativePeeledOnion {
1063 PeeledOnion::Forward (ref a, ref b, ) => {
1064 let mut a_nonref = Clone::clone(a);
1065 let mut b_nonref = Clone::clone(b);
1066 nativePeeledOnion::Forward (
1067 a_nonref.into_native(),
1068 *unsafe { Box::from_raw(b_nonref.take_inner()) },
1071 PeeledOnion::Receive (ref a, ref b, ref c, ) => {
1072 let mut a_nonref = Clone::clone(a);
1073 let mut b_nonref = Clone::clone(b);
1074 let mut local_b_nonref = if b_nonref.data == [0; 32] { None } else { Some( { b_nonref.data }) };
1075 let mut c_nonref = Clone::clone(c);
1076 let mut local_c_nonref = if c_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(c_nonref.take_inner()) } }) };
1077 nativePeeledOnion::Receive (
1078 a_nonref.into_native(),
1086 pub(crate) fn into_native(self) -> nativePeeledOnion {
1088 PeeledOnion::Forward (mut a, mut b, ) => {
1089 nativePeeledOnion::Forward (
1091 *unsafe { Box::from_raw(b.take_inner()) },
1094 PeeledOnion::Receive (mut a, mut b, mut c, ) => {
1095 let mut local_b = if b.data == [0; 32] { None } else { Some( { b.data }) };
1096 let mut local_c = if c.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(c.take_inner()) } }) };
1097 nativePeeledOnion::Receive (
1106 pub(crate) fn from_native(native: &PeeledOnionImport<crate::lightning::onion_message::packet::OnionMessageContents, >) -> Self {
1107 let native = unsafe { &*(native as *const _ as *const c_void as *const nativePeeledOnion) };
1109 nativePeeledOnion::Forward (ref a, ref b, ) => {
1110 let mut a_nonref = Clone::clone(a);
1111 let mut b_nonref = Clone::clone(b);
1112 PeeledOnion::Forward (
1113 crate::lightning::blinded_path::NextMessageHop::native_into(a_nonref),
1114 crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(b_nonref), is_owned: true },
1117 nativePeeledOnion::Receive (ref a, ref b, ref c, ) => {
1118 let mut a_nonref = Clone::clone(a);
1119 let mut b_nonref = Clone::clone(b);
1120 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()) } } };
1121 let mut c_nonref = Clone::clone(c);
1122 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 };
1123 PeeledOnion::Receive (
1124 crate::lightning::onion_message::packet::ParsedOnionMessageContents::native_into(a_nonref),
1132 pub(crate) fn native_into(native: nativePeeledOnion) -> Self {
1134 nativePeeledOnion::Forward (mut a, mut b, ) => {
1135 PeeledOnion::Forward (
1136 crate::lightning::blinded_path::NextMessageHop::native_into(a),
1137 crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(b), is_owned: true },
1140 nativePeeledOnion::Receive (mut a, mut b, mut c, ) => {
1141 let mut local_b = if b.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (b.unwrap()) } } };
1142 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 };
1143 PeeledOnion::Receive (
1144 crate::lightning::onion_message::packet::ParsedOnionMessageContents::native_into(a),
1152 /// Frees any resources used by the PeeledOnion
1154 pub extern "C" fn PeeledOnion_free(this_ptr: PeeledOnion) { }
1155 /// Creates a copy of the PeeledOnion
1157 pub extern "C" fn PeeledOnion_clone(orig: &PeeledOnion) -> PeeledOnion {
1161 /// Used only if an object of this type is returned as a trait impl by a method
1162 pub(crate) extern "C" fn PeeledOnion_clone_void(this_ptr: *const c_void) -> *mut c_void {
1163 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PeeledOnion)).clone() })) as *mut c_void
1166 /// Used only if an object of this type is returned as a trait impl by a method
1167 pub(crate) extern "C" fn PeeledOnion_free_void(this_ptr: *mut c_void) {
1168 let _ = unsafe { Box::from_raw(this_ptr as *mut PeeledOnion) };
1171 /// Utility method to constructs a new Forward-variant PeeledOnion
1172 pub extern "C" fn PeeledOnion_forward(a: crate::lightning::blinded_path::NextMessageHop,b: crate::lightning::ln::msgs::OnionMessage) -> PeeledOnion {
1173 PeeledOnion::Forward(a, b, )
1176 /// Utility method to constructs a new Receive-variant PeeledOnion
1177 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 {
1178 PeeledOnion::Receive(a, b, c, )
1180 /// Get a string which allows debug introspection of a PeeledOnion object
1181 pub extern "C" fn PeeledOnion_debug_str_void(o: *const c_void) -> Str {
1182 alloc::format!("{:?}", unsafe { o as *const crate::lightning::onion_message::messenger::PeeledOnion }).into()}
1183 /// Creates an [`OnionMessage`] with the given `contents` for sending to the destination of
1184 /// `path`, first calling [`Destination::resolve`] on `path.destination` with the given
1185 /// [`ReadOnlyNetworkGraph`].
1187 /// Returns the node id of the peer to send the message to, the message itself, and any addresses
1188 /// needed to connect to the first node.
1190 /// Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None
1192 pub extern "C" fn create_onion_message_resolving_destination(entropy_source: &crate::lightning::sign::EntropySource, node_signer: &crate::lightning::sign::NodeSigner, node_id_lookup: &crate::lightning::blinded_path::NodeIdLookUp, network_graph: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, 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_C3Tuple_PublicKeyOnionMessageCOption_CVec_SocketAddressZZZSendErrorZ {
1193 let mut local_reply_path = if reply_path.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(reply_path.take_inner()) } }) };
1194 let mut ret = lightning::onion_message::messenger::create_onion_message_resolving_destination::<crate::lightning::sign::EntropySource, crate::lightning::sign::NodeSigner, crate::lightning::blinded_path::NodeIdLookUp, crate::lightning::onion_message::packet::OnionMessageContents, >(entropy_source, node_signer, node_id_lookup, network_graph.get_native_ref(), secp256k1::global::SECP256K1, *unsafe { Box::from_raw(path.take_inner()) }, contents, local_reply_path);
1195 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, mut orig_ret_0_2) = o; let mut local_orig_ret_0_2 = if orig_ret_0_2.is_none() { crate::c_types::derived::COption_CVec_SocketAddressZZ::None } else { crate::c_types::derived::COption_CVec_SocketAddressZZ::Some( { let mut local_orig_ret_0_2_0 = Vec::new(); for mut item in orig_ret_0_2.unwrap().drain(..) { local_orig_ret_0_2_0.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; local_orig_ret_0_2_0.into() }) }; 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 }, local_orig_ret_0_2).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::onion_message::messenger::SendError::native_into(e) }).into() };
1199 /// Creates an [`OnionMessage`] with the given `contents` for sending to the destination of
1202 /// Returns the node id of the peer to send the message to, the message itself, and any addresses
1203 /// needed to connect to the first node.
1205 /// Returns [`SendError::UnresolvedIntroductionNode`] if:
1206 /// - `destination` contains a blinded path with an [`IntroductionNode::DirectedShortChannelId`],
1207 /// - unless it can be resolved by [`NodeIdLookUp::next_node_id`].
1208 /// Use [`create_onion_message_resolving_destination`] instead to resolve the introduction node
1209 /// first with a [`ReadOnlyNetworkGraph`].
1211 /// Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None
1213 pub extern "C" fn create_onion_message(entropy_source: &crate::lightning::sign::EntropySource, node_signer: &crate::lightning::sign::NodeSigner, node_id_lookup: &crate::lightning::blinded_path::NodeIdLookUp, 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_C3Tuple_PublicKeyOnionMessageCOption_CVec_SocketAddressZZZSendErrorZ {
1214 let mut local_reply_path = if reply_path.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(reply_path.take_inner()) } }) };
1215 let mut ret = lightning::onion_message::messenger::create_onion_message::<crate::lightning::sign::EntropySource, crate::lightning::sign::NodeSigner, crate::lightning::blinded_path::NodeIdLookUp, crate::lightning::onion_message::packet::OnionMessageContents, >(entropy_source, node_signer, node_id_lookup, secp256k1::global::SECP256K1, *unsafe { Box::from_raw(path.take_inner()) }, contents, local_reply_path);
1216 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, mut orig_ret_0_2) = o; let mut local_orig_ret_0_2 = if orig_ret_0_2.is_none() { crate::c_types::derived::COption_CVec_SocketAddressZZ::None } else { crate::c_types::derived::COption_CVec_SocketAddressZZ::Some( { let mut local_orig_ret_0_2_0 = Vec::new(); for mut item in orig_ret_0_2.unwrap().drain(..) { local_orig_ret_0_2_0.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; local_orig_ret_0_2_0.into() }) }; 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 }, local_orig_ret_0_2).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::onion_message::messenger::SendError::native_into(e) }).into() };
1220 /// Decode one layer of an incoming [`OnionMessage`].
1222 /// Returns either the next layer of the onion for forwarding or the decrypted content for the
1225 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 {
1226 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);
1227 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() };
1231 /// Constructs a new `OnionMessenger` to send, forward, and delegate received onion messages to
1232 /// their respective handlers.
1235 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 node_id_lookup: crate::lightning::blinded_path::NodeIdLookUp, 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 {
1236 let mut ret = lightning::onion_message::messenger::OnionMessenger::new(entropy_source, node_signer, logger, node_id_lookup, message_router, offers_handler, custom_handler);
1237 crate::lightning::onion_message::messenger::OnionMessenger { inner: ObjOps::heap_alloc(ret), is_owned: true }
1240 /// Sends an [`OnionMessage`] with the given `contents` to `destination`.
1242 /// See [`OnionMessenger`] for example usage.
1244 /// Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None
1247 pub extern "C" fn OnionMessenger_send_onion_message(this_arg: &crate::lightning::onion_message::messenger::OnionMessenger, mut contents: crate::lightning::onion_message::packet::OnionMessageContents, mut destination: crate::lightning::onion_message::messenger::Destination, mut reply_path: crate::lightning::blinded_path::BlindedPath) -> crate::c_types::derived::CResult_SendSuccessSendErrorZ {
1248 let mut local_reply_path = if reply_path.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(reply_path.take_inner()) } }) };
1249 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_onion_message(contents, destination.into_native(), local_reply_path);
1250 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::onion_message::messenger::SendSuccess::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::onion_message::messenger::SendError::native_into(e) }).into() };
1254 impl From<nativeOnionMessenger> for crate::lightning::ln::msgs::OnionMessageHandler {
1255 fn from(obj: nativeOnionMessenger) -> Self {
1256 let rust_obj = crate::lightning::onion_message::messenger::OnionMessenger { inner: ObjOps::heap_alloc(obj), is_owned: true };
1257 let mut ret = OnionMessenger_as_OnionMessageHandler(&rust_obj);
1258 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
1259 core::mem::forget(rust_obj);
1260 ret.free = Some(OnionMessenger_free_void);
1264 /// Constructs a new OnionMessageHandler which calls the relevant methods on this_arg.
1265 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageHandler must be freed before this_arg is
1267 pub extern "C" fn OnionMessenger_as_OnionMessageHandler(this_arg: &OnionMessenger) -> crate::lightning::ln::msgs::OnionMessageHandler {
1268 crate::lightning::ln::msgs::OnionMessageHandler {
1269 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1271 get_and_clear_connections_needed: OnionMessenger_OnionMessageHandler_get_and_clear_connections_needed,
1272 handle_onion_message: OnionMessenger_OnionMessageHandler_handle_onion_message,
1273 next_onion_message_for_peer: OnionMessenger_OnionMessageHandler_next_onion_message_for_peer,
1274 peer_connected: OnionMessenger_OnionMessageHandler_peer_connected,
1275 peer_disconnected: OnionMessenger_OnionMessageHandler_peer_disconnected,
1276 timer_tick_occurred: OnionMessenger_OnionMessageHandler_timer_tick_occurred,
1277 provided_node_features: OnionMessenger_OnionMessageHandler_provided_node_features,
1278 provided_init_features: OnionMessenger_OnionMessageHandler_provided_init_features,
1283 extern "C" fn OnionMessenger_OnionMessageHandler_get_and_clear_connections_needed(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyCVec_SocketAddressZZZ {
1284 let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler>::get_and_clear_connections_needed(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, );
1285 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; let mut local_ret_0 = (crate::c_types::PublicKey::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }); };
1288 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) {
1289 <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())
1292 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 {
1293 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());
1294 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 };
1298 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 {
1299 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);
1300 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() };
1303 extern "C" fn OnionMessenger_OnionMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
1304 <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust())
1306 extern "C" fn OnionMessenger_OnionMessageHandler_timer_tick_occurred(this_arg: *const c_void) {
1307 <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler>::timer_tick_occurred(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, )
1310 extern "C" fn OnionMessenger_OnionMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
1311 let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, );
1312 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
1315 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 {
1316 let mut ret = <nativeOnionMessenger as lightning::ln::msgs::OnionMessageHandler>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeOnionMessenger) }, &their_node_id.into_rust());
1317 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }