7c2354ed399a19c3aa3e1d41c6ee9a31c7f945d1
[ldk-c-bindings] / lightning-c-bindings / src / lightning / ln / peer_handler.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! Top level peer message handling and socket handling logic lives here.
10 //!
11 //! Instead of actually servicing sockets ourselves we require that you implement the
12 //! SocketDescriptor interface and use that to receive actions which you should perform on the
13 //! socket, and call into PeerManager with bytes read from the socket. The PeerManager will then
14 //! call into the provided message handlers (probably a ChannelManager and P2PGossipSync) with
15 //! messages they should handle, and encoding/sending response messages.
16
17 use alloc::str::FromStr;
18 use alloc::string::String;
19 use core::ffi::c_void;
20 use core::convert::Infallible;
21 use bitcoin::hashes::Hash;
22 use crate::c_types::*;
23 #[cfg(feature="no-std")]
24 use alloc::{vec::Vec, boxed::Box};
25
26 /// A handler provided to [`PeerManager`] for reading and handling custom messages.
27 ///
28 /// [BOLT 1] specifies a custom message type range for use with experimental or application-specific
29 /// messages. `CustomMessageHandler` allows for user-defined handling of such types. See the
30 /// [`lightning_custom_message`] crate for tools useful in composing more than one custom handler.
31 ///
32 /// [BOLT 1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
33 /// [`lightning_custom_message`]: https://docs.rs/lightning_custom_message/latest/lightning_custom_message
34 #[repr(C)]
35 pub struct CustomMessageHandler {
36         /// An opaque pointer which is passed to your function implementations as an argument.
37         /// This has no meaning in the LDK, and can be NULL or any other value.
38         pub this_arg: *mut c_void,
39         /// Handles the given message sent from `sender_node_id`, possibly producing messages for
40         /// [`CustomMessageHandler::get_and_clear_pending_msg`] to return and thus for [`PeerManager`]
41         /// to send.
42         pub handle_custom_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::ln::wire::Type, sender_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneLightningErrorZ,
43         /// Returns the list of pending messages that were generated by the handler, clearing the list
44         /// in the process. Each message is paired with the node id of the intended recipient. If no
45         /// connection to the node exists, then the message is simply not sent.
46         pub get_and_clear_pending_msg: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ,
47         /// Gets the node feature flags which this handler itself supports. All available handlers are
48         /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
49         /// which are broadcasted in our [`NodeAnnouncement`] message.
50         ///
51         /// [`NodeAnnouncement`]: crate::ln::msgs::NodeAnnouncement
52         pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures,
53         /// Gets the init feature flags which should be sent to the given peer. All available handlers
54         /// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
55         /// which are sent in our [`Init`] message.
56         ///
57         /// [`Init`]: crate::ln::msgs::Init
58         pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures,
59         /// Implementation of CustomMessageReader for this object.
60         pub CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader,
61         /// Frees any resources associated with this object given its this_arg pointer.
62         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
63         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
64 }
65 unsafe impl Send for CustomMessageHandler {}
66 unsafe impl Sync for CustomMessageHandler {}
67 #[allow(unused)]
68 pub(crate) fn CustomMessageHandler_clone_fields(orig: &CustomMessageHandler) -> CustomMessageHandler {
69         CustomMessageHandler {
70                 this_arg: orig.this_arg,
71                 handle_custom_message: Clone::clone(&orig.handle_custom_message),
72                 get_and_clear_pending_msg: Clone::clone(&orig.get_and_clear_pending_msg),
73                 provided_node_features: Clone::clone(&orig.provided_node_features),
74                 provided_init_features: Clone::clone(&orig.provided_init_features),
75                 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader_clone_fields(&orig.CustomMessageReader),
76                 free: Clone::clone(&orig.free),
77         }
78 }
79 impl lightning::ln::wire::CustomMessageReader for CustomMessageHandler {
80         type CustomMessage = crate::lightning::ln::wire::Type;
81         fn read<R:crate::c_types::io::Read>(&self, mut message_type: u16, mut buffer: &mut R) -> Result<Option<crate::lightning::ln::wire::Type>, lightning::ln::msgs::DecodeError> {
82                 let mut ret = (self.CustomMessageReader.read)(self.CustomMessageReader.this_arg, message_type, crate::c_types::u8slice::from_vec(&crate::c_types::reader_to_vec(buffer)));
83                 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() })};
84                 local_ret
85         }
86 }
87
88 use lightning::ln::peer_handler::CustomMessageHandler as rustCustomMessageHandler;
89 impl rustCustomMessageHandler for CustomMessageHandler {
90         fn handle_custom_message(&self, mut msg: crate::lightning::ln::wire::Type, mut sender_node_id: &bitcoin::secp256k1::PublicKey) -> Result<(), lightning::ln::msgs::LightningError> {
91                 let mut ret = (self.handle_custom_message)(self.this_arg, Into::into(msg), crate::c_types::PublicKey::from_rust(&sender_node_id));
92                 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
93                 local_ret
94         }
95         fn get_and_clear_pending_msg(&self) -> Vec<(bitcoin::secp256k1::PublicKey, crate::lightning::ln::wire::Type)> {
96                 let mut ret = (self.get_and_clear_pending_msg)(self.this_arg);
97                 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) = item.to_rust(); let mut local_ret_0 = (orig_ret_0_0.into_rust(), orig_ret_0_1); local_ret_0 }); };
98                 local_ret
99         }
100         fn provided_node_features(&self) -> lightning::ln::features::NodeFeatures {
101                 let mut ret = (self.provided_node_features)(self.this_arg);
102                 *unsafe { Box::from_raw(ret.take_inner()) }
103         }
104         fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning::ln::features::InitFeatures {
105                 let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id));
106                 *unsafe { Box::from_raw(ret.take_inner()) }
107         }
108 }
109
110 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
111 // directly as a Deref trait in higher-level structs:
112 impl core::ops::Deref for CustomMessageHandler {
113         type Target = Self;
114         fn deref(&self) -> &Self {
115                 self
116         }
117 }
118 impl core::ops::DerefMut for CustomMessageHandler {
119         fn deref_mut(&mut self) -> &mut Self {
120                 self
121         }
122 }
123 /// Calls the free function if one is set
124 #[no_mangle]
125 pub extern "C" fn CustomMessageHandler_free(this_ptr: CustomMessageHandler) { }
126 impl Drop for CustomMessageHandler {
127         fn drop(&mut self) {
128                 if let Some(f) = self.free {
129                         f(self.this_arg);
130                 }
131         }
132 }
133
134 use lightning::ln::peer_handler::IgnoringMessageHandler as nativeIgnoringMessageHandlerImport;
135 pub(crate) type nativeIgnoringMessageHandler = nativeIgnoringMessageHandlerImport;
136
137 /// A dummy struct which implements `RoutingMessageHandler` without storing any routing information
138 /// or doing any processing. You can provide one of these as the route_handler in a MessageHandler.
139 #[must_use]
140 #[repr(C)]
141 pub struct IgnoringMessageHandler {
142         /// A pointer to the opaque Rust object.
143
144         /// Nearly everywhere, inner must be non-null, however in places where
145         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
146         pub inner: *mut nativeIgnoringMessageHandler,
147         /// Indicates that this is the only struct which contains the same pointer.
148
149         /// Rust functions which take ownership of an object provided via an argument require
150         /// this to be true and invalidate the object pointed to by inner.
151         pub is_owned: bool,
152 }
153
154 impl Drop for IgnoringMessageHandler {
155         fn drop(&mut self) {
156                 if self.is_owned && !<*mut nativeIgnoringMessageHandler>::is_null(self.inner) {
157                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
158                 }
159         }
160 }
161 /// Frees any resources used by the IgnoringMessageHandler, if is_owned is set and inner is non-NULL.
162 #[no_mangle]
163 pub extern "C" fn IgnoringMessageHandler_free(this_obj: IgnoringMessageHandler) { }
164 #[allow(unused)]
165 /// Used only if an object of this type is returned as a trait impl by a method
166 pub(crate) extern "C" fn IgnoringMessageHandler_free_void(this_ptr: *mut c_void) {
167         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeIgnoringMessageHandler) };
168 }
169 #[allow(unused)]
170 impl IgnoringMessageHandler {
171         pub(crate) fn get_native_ref(&self) -> &'static nativeIgnoringMessageHandler {
172                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
173         }
174         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeIgnoringMessageHandler {
175                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
176         }
177         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
178         pub(crate) fn take_inner(mut self) -> *mut nativeIgnoringMessageHandler {
179                 assert!(self.is_owned);
180                 let ret = ObjOps::untweak_ptr(self.inner);
181                 self.inner = core::ptr::null_mut();
182                 ret
183         }
184 }
185 /// Constructs a new IgnoringMessageHandler given each field
186 #[must_use]
187 #[no_mangle]
188 pub extern "C" fn IgnoringMessageHandler_new() -> IgnoringMessageHandler {
189         IgnoringMessageHandler { inner: ObjOps::heap_alloc(nativeIgnoringMessageHandler {
190         }), is_owned: true }
191 }
192 impl From<nativeIgnoringMessageHandler> for crate::lightning::events::MessageSendEventsProvider {
193         fn from(obj: nativeIgnoringMessageHandler) -> Self {
194                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
195                 let mut ret = IgnoringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
196                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
197                 core::mem::forget(rust_obj);
198                 ret.free = Some(IgnoringMessageHandler_free_void);
199                 ret
200         }
201 }
202 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
203 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
204 #[no_mangle]
205 pub extern "C" fn IgnoringMessageHandler_as_MessageSendEventsProvider(this_arg: &IgnoringMessageHandler) -> crate::lightning::events::MessageSendEventsProvider {
206         crate::lightning::events::MessageSendEventsProvider {
207                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
208                 free: None,
209                 get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
210         }
211 }
212
213 #[must_use]
214 extern "C" fn IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
215         let mut ret = <nativeIgnoringMessageHandler as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
216         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
217         local_ret.into()
218 }
219
220 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
221         fn from(obj: nativeIgnoringMessageHandler) -> Self {
222                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
223                 let mut ret = IgnoringMessageHandler_as_RoutingMessageHandler(&rust_obj);
224                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
225                 core::mem::forget(rust_obj);
226                 ret.free = Some(IgnoringMessageHandler_free_void);
227                 ret
228         }
229 }
230 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
231 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
232 #[no_mangle]
233 pub extern "C" fn IgnoringMessageHandler_as_RoutingMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
234         crate::lightning::ln::msgs::RoutingMessageHandler {
235                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
236                 free: None,
237                 handle_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement,
238                 handle_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement,
239                 handle_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update,
240                 get_next_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcement,
241                 get_next_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcement,
242                 peer_connected: IgnoringMessageHandler_RoutingMessageHandler_peer_connected,
243                 handle_reply_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_channel_range,
244                 handle_reply_short_channel_ids_end: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
245                 handle_query_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_query_channel_range,
246                 handle_query_short_channel_ids: IgnoringMessageHandler_RoutingMessageHandler_handle_query_short_channel_ids,
247                 processing_queue_high: IgnoringMessageHandler_RoutingMessageHandler_processing_queue_high,
248                 provided_node_features: IgnoringMessageHandler_RoutingMessageHandler_provided_node_features,
249                 provided_init_features: IgnoringMessageHandler_RoutingMessageHandler_provided_init_features,
250                 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
251                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
252                         free: None,
253                         get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
254                 },
255         }
256 }
257
258 #[must_use]
259 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
260         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
261         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::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
262         local_ret
263 }
264 #[must_use]
265 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
266         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
267         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::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
268         local_ret
269 }
270 #[must_use]
271 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
272         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
273         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::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
274         local_ret
275 }
276 #[must_use]
277 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcement(this_arg: *const c_void, mut starting_point: u64) -> crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ {
278         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, starting_point);
279         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ::None } else { crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ::Some( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = (ret.unwrap()); let mut local_orig_ret_0_1 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((orig_ret_0_1.unwrap())) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(orig_ret_0_0), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }) };
280         local_ret
281 }
282 #[must_use]
283 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcement(this_arg: *const c_void, mut starting_point: crate::lightning::routing::gossip::NodeId) -> crate::lightning::ln::msgs::NodeAnnouncement {
284         let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) };
285         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, local_starting_point);
286         let mut local_ret = crate::lightning::ln::msgs::NodeAnnouncement { inner: if ret.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
287         local_ret
288 }
289 #[must_use]
290 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_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 {
291         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust(), init.get_native_ref(), inbound);
292         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() };
293         local_ret
294 }
295 #[must_use]
296 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_reply_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::lightning::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
297         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_channel_range(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
298         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::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
299         local_ret
300 }
301 #[must_use]
302 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::lightning::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
303         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_short_channel_ids_end(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
304         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::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
305         local_ret
306 }
307 #[must_use]
308 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_query_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::lightning::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
309         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_channel_range(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
310         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::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
311         local_ret
312 }
313 #[must_use]
314 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_query_short_channel_ids(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
315         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_short_channel_ids(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
316         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::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
317         local_ret
318 }
319 #[must_use]
320 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool {
321         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
322         ret
323 }
324 #[must_use]
325 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
326         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
327         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
328 }
329 #[must_use]
330 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_provided_init_features(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures {
331         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
332         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
333 }
334
335 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::OnionMessageHandler {
336         fn from(obj: nativeIgnoringMessageHandler) -> Self {
337                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
338                 let mut ret = IgnoringMessageHandler_as_OnionMessageHandler(&rust_obj);
339                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
340                 core::mem::forget(rust_obj);
341                 ret.free = Some(IgnoringMessageHandler_free_void);
342                 ret
343         }
344 }
345 /// Constructs a new OnionMessageHandler which calls the relevant methods on this_arg.
346 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageHandler must be freed before this_arg is
347 #[no_mangle]
348 pub extern "C" fn IgnoringMessageHandler_as_OnionMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::msgs::OnionMessageHandler {
349         crate::lightning::ln::msgs::OnionMessageHandler {
350                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
351                 free: None,
352                 handle_onion_message: IgnoringMessageHandler_OnionMessageHandler_handle_onion_message,
353                 next_onion_message_for_peer: IgnoringMessageHandler_OnionMessageHandler_next_onion_message_for_peer,
354                 peer_connected: IgnoringMessageHandler_OnionMessageHandler_peer_connected,
355                 peer_disconnected: IgnoringMessageHandler_OnionMessageHandler_peer_disconnected,
356                 provided_node_features: IgnoringMessageHandler_OnionMessageHandler_provided_node_features,
357                 provided_init_features: IgnoringMessageHandler_OnionMessageHandler_provided_init_features,
358         }
359 }
360
361 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_handle_onion_message(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OnionMessage) {
362         <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::handle_onion_message(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &peer_node_id.into_rust(), msg.get_native_ref())
363 }
364 #[must_use]
365 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_next_onion_message_for_peer(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage {
366         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::next_onion_message_for_peer(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, peer_node_id.into_rust());
367         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 };
368         local_ret
369 }
370 #[must_use]
371 extern "C" fn IgnoringMessageHandler_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 {
372         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust(), init.get_native_ref(), inbound);
373         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() };
374         local_ret
375 }
376 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
377         <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust())
378 }
379 #[must_use]
380 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
381         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
382         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
383 }
384 #[must_use]
385 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_provided_init_features(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures {
386         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
387         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
388 }
389
390 impl From<nativeIgnoringMessageHandler> for crate::lightning::onion_message::offers::OffersMessageHandler {
391         fn from(obj: nativeIgnoringMessageHandler) -> Self {
392                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
393                 let mut ret = IgnoringMessageHandler_as_OffersMessageHandler(&rust_obj);
394                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
395                 core::mem::forget(rust_obj);
396                 ret.free = Some(IgnoringMessageHandler_free_void);
397                 ret
398         }
399 }
400 /// Constructs a new OffersMessageHandler which calls the relevant methods on this_arg.
401 /// This copies the `inner` pointer in this_arg and thus the returned OffersMessageHandler must be freed before this_arg is
402 #[no_mangle]
403 pub extern "C" fn IgnoringMessageHandler_as_OffersMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::onion_message::offers::OffersMessageHandler {
404         crate::lightning::onion_message::offers::OffersMessageHandler {
405                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
406                 free: None,
407                 handle_message: IgnoringMessageHandler_OffersMessageHandler_handle_message,
408                 release_pending_messages: IgnoringMessageHandler_OffersMessageHandler_release_pending_messages,
409         }
410 }
411
412 #[must_use]
413 extern "C" fn IgnoringMessageHandler_OffersMessageHandler_handle_message(this_arg: *const c_void, mut message: crate::lightning::onion_message::offers::OffersMessage) -> crate::c_types::derived::COption_OffersMessageZ {
414         let mut ret = <nativeIgnoringMessageHandler as lightning::onion_message::offers::OffersMessageHandler<>>::handle_message(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, message.into_native());
415         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_OffersMessageZ::None } else { crate::c_types::derived::COption_OffersMessageZ::Some( { crate::lightning::onion_message::offers::OffersMessage::native_into(ret.unwrap()) }) };
416         local_ret
417 }
418 #[must_use]
419 extern "C" fn IgnoringMessageHandler_OffersMessageHandler_release_pending_messages(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ {
420         let mut ret = <nativeIgnoringMessageHandler as lightning::onion_message::offers::OffersMessageHandler<>>::release_pending_messages(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
421         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, mut orig_ret_0_2) = item; let mut local_orig_ret_0_2 = crate::lightning::blinded_path::BlindedPath { inner: if orig_ret_0_2.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (crate::lightning::onion_message::offers::OffersMessage::native_into(orig_ret_0_0), crate::lightning::onion_message::messenger::Destination::native_into(orig_ret_0_1), local_orig_ret_0_2).into(); local_ret_0 }); };
422         local_ret.into()
423 }
424
425 impl From<nativeIgnoringMessageHandler> for crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
426         fn from(obj: nativeIgnoringMessageHandler) -> Self {
427                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
428                 let mut ret = IgnoringMessageHandler_as_CustomOnionMessageHandler(&rust_obj);
429                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
430                 core::mem::forget(rust_obj);
431                 ret.free = Some(IgnoringMessageHandler_free_void);
432                 ret
433         }
434 }
435 /// Constructs a new CustomOnionMessageHandler which calls the relevant methods on this_arg.
436 /// This copies the `inner` pointer in this_arg and thus the returned CustomOnionMessageHandler must be freed before this_arg is
437 #[no_mangle]
438 pub extern "C" fn IgnoringMessageHandler_as_CustomOnionMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
439         crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
440                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
441                 free: None,
442                 handle_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message,
443                 read_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_read_custom_message,
444                 release_pending_custom_messages: IgnoringMessageHandler_CustomOnionMessageHandler_release_pending_custom_messages,
445         }
446 }
447
448 #[must_use]
449 extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message(this_arg: *const c_void, mut msg: crate::lightning::onion_message::packet::OnionMessageContents) -> crate::c_types::derived::COption_OnionMessageContentsZ {
450         unreachable!();
451 }
452 #[must_use]
453 extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_read_custom_message(this_arg: *const c_void, mut message_type: u64, mut buffer: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_OnionMessageContentsZDecodeErrorZ {
454         let mut ret = <nativeIgnoringMessageHandler as lightning::onion_message::messenger::CustomOnionMessageHandler<>>::read_custom_message(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, message_type, &mut buffer.to_reader());
455         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = if o.is_none() { crate::c_types::derived::COption_OnionMessageContentsZ::None } else { crate::c_types::derived::COption_OnionMessageContentsZ::Some( { Into::into(o.unwrap()) }) }; local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
456         local_ret
457 }
458 #[must_use]
459 extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_release_pending_custom_messages(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ {
460         let mut ret = <nativeIgnoringMessageHandler as lightning::onion_message::messenger::CustomOnionMessageHandler<>>::release_pending_custom_messages(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
461         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, mut orig_ret_0_2) = item; let mut local_orig_ret_0_2 = crate::lightning::blinded_path::BlindedPath { inner: if orig_ret_0_2.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (Into::into(orig_ret_0_0), crate::lightning::onion_message::messenger::Destination::native_into(orig_ret_0_1), local_orig_ret_0_2).into(); local_ret_0 }); };
462         local_ret.into()
463 }
464
465 impl From<nativeInfallible> for crate::lightning::onion_message::packet::OnionMessageContents {
466         fn from(obj: nativeInfallible) -> Self {
467                 unreachable!();
468         }
469 }
470 impl From<nativeInfallible> for crate::lightning::ln::wire::Type {
471         fn from(obj: nativeInfallible) -> Self {
472                 unreachable!();
473         }
474 }
475 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::wire::CustomMessageReader {
476         fn from(obj: nativeIgnoringMessageHandler) -> Self {
477                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
478                 let mut ret = IgnoringMessageHandler_as_CustomMessageReader(&rust_obj);
479                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
480                 core::mem::forget(rust_obj);
481                 ret.free = Some(IgnoringMessageHandler_free_void);
482                 ret
483         }
484 }
485 /// Constructs a new CustomMessageReader which calls the relevant methods on this_arg.
486 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageReader must be freed before this_arg is
487 #[no_mangle]
488 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageReader(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::wire::CustomMessageReader {
489         crate::lightning::ln::wire::CustomMessageReader {
490                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
491                 free: None,
492                 read: IgnoringMessageHandler_CustomMessageReader_read,
493         }
494 }
495
496 #[must_use]
497 extern "C" fn IgnoringMessageHandler_CustomMessageReader_read(this_arg: *const c_void, mut message_type: u16, mut buffer: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_TypeZDecodeErrorZ {
498         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::wire::CustomMessageReader<>>::read(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, message_type, &mut buffer.to_reader());
499         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = if o.is_none() { crate::c_types::derived::COption_TypeZ::None } else { crate::c_types::derived::COption_TypeZ::Some( { Into::into(o.unwrap()) }) }; local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
500         local_ret
501 }
502
503 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::peer_handler::CustomMessageHandler {
504         fn from(obj: nativeIgnoringMessageHandler) -> Self {
505                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
506                 let mut ret = IgnoringMessageHandler_as_CustomMessageHandler(&rust_obj);
507                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
508                 core::mem::forget(rust_obj);
509                 ret.free = Some(IgnoringMessageHandler_free_void);
510                 ret
511         }
512 }
513 /// Constructs a new CustomMessageHandler which calls the relevant methods on this_arg.
514 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageHandler must be freed before this_arg is
515 #[no_mangle]
516 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::peer_handler::CustomMessageHandler {
517         crate::lightning::ln::peer_handler::CustomMessageHandler {
518                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
519                 free: None,
520                 handle_custom_message: IgnoringMessageHandler_CustomMessageHandler_handle_custom_message,
521                 get_and_clear_pending_msg: IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg,
522                 provided_node_features: IgnoringMessageHandler_CustomMessageHandler_provided_node_features,
523                 provided_init_features: IgnoringMessageHandler_CustomMessageHandler_provided_init_features,
524                 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader {
525                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
526                         free: None,
527                         read: IgnoringMessageHandler_CustomMessageReader_read,
528                 },
529         }
530 }
531
532 #[must_use]
533 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_handle_custom_message(this_arg: *const c_void, mut msg: crate::lightning::ln::wire::Type, mut sender_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
534         unreachable!();
535 }
536 #[must_use]
537 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ {
538         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::get_and_clear_pending_msg(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
539         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_ret_0 = (crate::c_types::PublicKey::from_rust(&orig_ret_0_0), Into::into(orig_ret_0_1)).into(); local_ret_0 }); };
540         local_ret.into()
541 }
542 #[must_use]
543 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
544         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
545         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
546 }
547 #[must_use]
548 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_provided_init_features(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures {
549         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
550         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
551 }
552
553
554 use lightning::ln::peer_handler::ErroringMessageHandler as nativeErroringMessageHandlerImport;
555 pub(crate) type nativeErroringMessageHandler = nativeErroringMessageHandlerImport;
556
557 /// A dummy struct which implements `ChannelMessageHandler` without having any channels.
558 /// You can provide one of these as the route_handler in a MessageHandler.
559 #[must_use]
560 #[repr(C)]
561 pub struct ErroringMessageHandler {
562         /// A pointer to the opaque Rust object.
563
564         /// Nearly everywhere, inner must be non-null, however in places where
565         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
566         pub inner: *mut nativeErroringMessageHandler,
567         /// Indicates that this is the only struct which contains the same pointer.
568
569         /// Rust functions which take ownership of an object provided via an argument require
570         /// this to be true and invalidate the object pointed to by inner.
571         pub is_owned: bool,
572 }
573
574 impl Drop for ErroringMessageHandler {
575         fn drop(&mut self) {
576                 if self.is_owned && !<*mut nativeErroringMessageHandler>::is_null(self.inner) {
577                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
578                 }
579         }
580 }
581 /// Frees any resources used by the ErroringMessageHandler, if is_owned is set and inner is non-NULL.
582 #[no_mangle]
583 pub extern "C" fn ErroringMessageHandler_free(this_obj: ErroringMessageHandler) { }
584 #[allow(unused)]
585 /// Used only if an object of this type is returned as a trait impl by a method
586 pub(crate) extern "C" fn ErroringMessageHandler_free_void(this_ptr: *mut c_void) {
587         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeErroringMessageHandler) };
588 }
589 #[allow(unused)]
590 impl ErroringMessageHandler {
591         pub(crate) fn get_native_ref(&self) -> &'static nativeErroringMessageHandler {
592                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
593         }
594         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeErroringMessageHandler {
595                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
596         }
597         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
598         pub(crate) fn take_inner(mut self) -> *mut nativeErroringMessageHandler {
599                 assert!(self.is_owned);
600                 let ret = ObjOps::untweak_ptr(self.inner);
601                 self.inner = core::ptr::null_mut();
602                 ret
603         }
604 }
605 /// Constructs a new ErroringMessageHandler
606 #[must_use]
607 #[no_mangle]
608 pub extern "C" fn ErroringMessageHandler_new() -> crate::lightning::ln::peer_handler::ErroringMessageHandler {
609         let mut ret = lightning::ln::peer_handler::ErroringMessageHandler::new();
610         crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
611 }
612
613 impl From<nativeErroringMessageHandler> for crate::lightning::events::MessageSendEventsProvider {
614         fn from(obj: nativeErroringMessageHandler) -> Self {
615                 let rust_obj = crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
616                 let mut ret = ErroringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
617                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
618                 core::mem::forget(rust_obj);
619                 ret.free = Some(ErroringMessageHandler_free_void);
620                 ret
621         }
622 }
623 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
624 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
625 #[no_mangle]
626 pub extern "C" fn ErroringMessageHandler_as_MessageSendEventsProvider(this_arg: &ErroringMessageHandler) -> crate::lightning::events::MessageSendEventsProvider {
627         crate::lightning::events::MessageSendEventsProvider {
628                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
629                 free: None,
630                 get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
631         }
632 }
633
634 #[must_use]
635 extern "C" fn ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
636         let mut ret = <nativeErroringMessageHandler as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
637         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
638         local_ret.into()
639 }
640
641 impl From<nativeErroringMessageHandler> for crate::lightning::ln::msgs::ChannelMessageHandler {
642         fn from(obj: nativeErroringMessageHandler) -> Self {
643                 let rust_obj = crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
644                 let mut ret = ErroringMessageHandler_as_ChannelMessageHandler(&rust_obj);
645                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
646                 core::mem::forget(rust_obj);
647                 ret.free = Some(ErroringMessageHandler_free_void);
648                 ret
649         }
650 }
651 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
652 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
653 #[no_mangle]
654 pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &ErroringMessageHandler) -> crate::lightning::ln::msgs::ChannelMessageHandler {
655         crate::lightning::ln::msgs::ChannelMessageHandler {
656                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
657                 free: None,
658                 handle_open_channel: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel,
659                 handle_open_channel_v2: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel_v2,
660                 handle_accept_channel: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel,
661                 handle_accept_channel_v2: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel_v2,
662                 handle_funding_created: ErroringMessageHandler_ChannelMessageHandler_handle_funding_created,
663                 handle_funding_signed: ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed,
664                 handle_channel_ready: ErroringMessageHandler_ChannelMessageHandler_handle_channel_ready,
665                 handle_shutdown: ErroringMessageHandler_ChannelMessageHandler_handle_shutdown,
666                 handle_closing_signed: ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed,
667                 handle_tx_add_input: ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_input,
668                 handle_tx_add_output: ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_output,
669                 handle_tx_remove_input: ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_input,
670                 handle_tx_remove_output: ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_output,
671                 handle_tx_complete: ErroringMessageHandler_ChannelMessageHandler_handle_tx_complete,
672                 handle_tx_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_tx_signatures,
673                 handle_tx_init_rbf: ErroringMessageHandler_ChannelMessageHandler_handle_tx_init_rbf,
674                 handle_tx_ack_rbf: ErroringMessageHandler_ChannelMessageHandler_handle_tx_ack_rbf,
675                 handle_tx_abort: ErroringMessageHandler_ChannelMessageHandler_handle_tx_abort,
676                 handle_update_add_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc,
677                 handle_update_fulfill_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc,
678                 handle_update_fail_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc,
679                 handle_update_fail_malformed_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_malformed_htlc,
680                 handle_commitment_signed: ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed,
681                 handle_revoke_and_ack: ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack,
682                 handle_update_fee: ErroringMessageHandler_ChannelMessageHandler_handle_update_fee,
683                 handle_announcement_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures,
684                 peer_disconnected: ErroringMessageHandler_ChannelMessageHandler_peer_disconnected,
685                 peer_connected: ErroringMessageHandler_ChannelMessageHandler_peer_connected,
686                 handle_channel_reestablish: ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish,
687                 handle_channel_update: ErroringMessageHandler_ChannelMessageHandler_handle_channel_update,
688                 handle_error: ErroringMessageHandler_ChannelMessageHandler_handle_error,
689                 provided_node_features: ErroringMessageHandler_ChannelMessageHandler_provided_node_features,
690                 provided_init_features: ErroringMessageHandler_ChannelMessageHandler_provided_init_features,
691                 get_chain_hashes: ErroringMessageHandler_ChannelMessageHandler_get_chain_hashes,
692                 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
693                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
694                         free: None,
695                         get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
696                 },
697         }
698 }
699
700 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_open_channel(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OpenChannel) {
701         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_open_channel(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
702 }
703 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_open_channel_v2(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OpenChannelV2) {
704         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_open_channel_v2(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
705 }
706 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::AcceptChannel) {
707         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_accept_channel(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
708 }
709 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel_v2(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::AcceptChannelV2) {
710         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_accept_channel_v2(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
711 }
712 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_funding_created(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingCreated) {
713         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_created(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
714 }
715 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingSigned) {
716         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_signed(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
717 }
718 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_channel_ready(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelReady) {
719         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_ready(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
720 }
721 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_shutdown(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Shutdown) {
722         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
723 }
724 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ClosingSigned) {
725         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_closing_signed(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
726 }
727 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_input(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAddInput) {
728         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_add_input(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
729 }
730 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_output(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAddOutput) {
731         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_add_output(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
732 }
733 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_input(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxRemoveInput) {
734         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_remove_input(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
735 }
736 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_output(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxRemoveOutput) {
737         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_remove_output(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
738 }
739 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_complete(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxComplete) {
740         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_complete(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
741 }
742 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_signatures(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxSignatures) {
743         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_signatures(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
744 }
745 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_init_rbf(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxInitRbf) {
746         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_init_rbf(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
747 }
748 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_ack_rbf(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAckRbf) {
749         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_ack_rbf(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
750 }
751 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_abort(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAbort) {
752         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_abort(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
753 }
754 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateAddHTLC) {
755         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_add_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
756 }
757 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFulfillHTLC) {
758         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fulfill_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
759 }
760 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFailHTLC) {
761         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
762 }
763 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_malformed_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFailMalformedHTLC) {
764         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_malformed_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
765 }
766 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::CommitmentSigned) {
767         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_commitment_signed(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
768 }
769 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::RevokeAndACK) {
770         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_revoke_and_ack(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
771 }
772 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_fee(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFee) {
773         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fee(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
774 }
775 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::AnnouncementSignatures) {
776         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_announcement_signatures(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
777 }
778 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
779         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust())
780 }
781 #[must_use]
782 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Init, mut inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ {
783         let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref(), inbound);
784         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() };
785         local_ret
786 }
787 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelReestablish) {
788         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_reestablish(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
789 }
790 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_channel_update(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelUpdate) {
791         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
792 }
793 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_error(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ErrorMessage) {
794         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
795 }
796 #[must_use]
797 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
798         let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
799         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
800 }
801 #[must_use]
802 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_provided_init_features(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures {
803         let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust());
804         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
805 }
806 #[must_use]
807 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_get_chain_hashes(this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
808         let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::get_chain_hashes(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
809         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::None } else { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::c_types::ThirtyTwoBytes { data: item.to_bytes() } }); }; local_ret_0.into() }) };
810         local_ret
811 }
812
813
814 use lightning::ln::peer_handler::MessageHandler as nativeMessageHandlerImport;
815 pub(crate) type nativeMessageHandler = nativeMessageHandlerImport<crate::lightning::ln::msgs::ChannelMessageHandler, crate::lightning::ln::msgs::RoutingMessageHandler, crate::lightning::ln::msgs::OnionMessageHandler, crate::lightning::ln::peer_handler::CustomMessageHandler>;
816
817 /// Provides references to trait impls which handle different types of messages.
818 #[must_use]
819 #[repr(C)]
820 pub struct MessageHandler {
821         /// A pointer to the opaque Rust object.
822
823         /// Nearly everywhere, inner must be non-null, however in places where
824         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
825         pub inner: *mut nativeMessageHandler,
826         /// Indicates that this is the only struct which contains the same pointer.
827
828         /// Rust functions which take ownership of an object provided via an argument require
829         /// this to be true and invalidate the object pointed to by inner.
830         pub is_owned: bool,
831 }
832
833 impl Drop for MessageHandler {
834         fn drop(&mut self) {
835                 if self.is_owned && !<*mut nativeMessageHandler>::is_null(self.inner) {
836                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
837                 }
838         }
839 }
840 /// Frees any resources used by the MessageHandler, if is_owned is set and inner is non-NULL.
841 #[no_mangle]
842 pub extern "C" fn MessageHandler_free(this_obj: MessageHandler) { }
843 #[allow(unused)]
844 /// Used only if an object of this type is returned as a trait impl by a method
845 pub(crate) extern "C" fn MessageHandler_free_void(this_ptr: *mut c_void) {
846         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMessageHandler) };
847 }
848 #[allow(unused)]
849 impl MessageHandler {
850         pub(crate) fn get_native_ref(&self) -> &'static nativeMessageHandler {
851                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
852         }
853         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMessageHandler {
854                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
855         }
856         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
857         pub(crate) fn take_inner(mut self) -> *mut nativeMessageHandler {
858                 assert!(self.is_owned);
859                 let ret = ObjOps::untweak_ptr(self.inner);
860                 self.inner = core::ptr::null_mut();
861                 ret
862         }
863 }
864 /// A message handler which handles messages specific to channels. Usually this is just a
865 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
866 ///
867 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
868 #[no_mangle]
869 pub extern "C" fn MessageHandler_get_chan_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::ChannelMessageHandler {
870         let mut inner_val = &mut this_ptr.get_native_mut_ref().chan_handler;
871         inner_val
872 }
873 /// A message handler which handles messages specific to channels. Usually this is just a
874 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
875 ///
876 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
877 #[no_mangle]
878 pub extern "C" fn MessageHandler_set_chan_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::ChannelMessageHandler) {
879         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chan_handler = val;
880 }
881 /// A message handler which handles messages updating our knowledge of the network channel
882 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
883 ///
884 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
885 #[no_mangle]
886 pub extern "C" fn MessageHandler_get_route_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::RoutingMessageHandler {
887         let mut inner_val = &mut this_ptr.get_native_mut_ref().route_handler;
888         inner_val
889 }
890 /// A message handler which handles messages updating our knowledge of the network channel
891 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
892 ///
893 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
894 #[no_mangle]
895 pub extern "C" fn MessageHandler_set_route_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::RoutingMessageHandler) {
896         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_handler = val;
897 }
898 /// A message handler which handles onion messages. This should generally be an
899 /// [`OnionMessenger`], but can also be an [`IgnoringMessageHandler`].
900 ///
901 /// [`OnionMessenger`]: crate::onion_message::OnionMessenger
902 #[no_mangle]
903 pub extern "C" fn MessageHandler_get_onion_message_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::OnionMessageHandler {
904         let mut inner_val = &mut this_ptr.get_native_mut_ref().onion_message_handler;
905         inner_val
906 }
907 /// A message handler which handles onion messages. This should generally be an
908 /// [`OnionMessenger`], but can also be an [`IgnoringMessageHandler`].
909 ///
910 /// [`OnionMessenger`]: crate::onion_message::OnionMessenger
911 #[no_mangle]
912 pub extern "C" fn MessageHandler_set_onion_message_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::OnionMessageHandler) {
913         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.onion_message_handler = val;
914 }
915 /// A message handler which handles custom messages. The only LDK-provided implementation is
916 /// [`IgnoringMessageHandler`].
917 #[no_mangle]
918 pub extern "C" fn MessageHandler_get_custom_message_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::peer_handler::CustomMessageHandler {
919         let mut inner_val = &mut this_ptr.get_native_mut_ref().custom_message_handler;
920         inner_val
921 }
922 /// A message handler which handles custom messages. The only LDK-provided implementation is
923 /// [`IgnoringMessageHandler`].
924 #[no_mangle]
925 pub extern "C" fn MessageHandler_set_custom_message_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::peer_handler::CustomMessageHandler) {
926         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.custom_message_handler = val;
927 }
928 /// Constructs a new MessageHandler given each field
929 #[must_use]
930 #[no_mangle]
931 pub extern "C" fn MessageHandler_new(mut chan_handler_arg: crate::lightning::ln::msgs::ChannelMessageHandler, mut route_handler_arg: crate::lightning::ln::msgs::RoutingMessageHandler, mut onion_message_handler_arg: crate::lightning::ln::msgs::OnionMessageHandler, mut custom_message_handler_arg: crate::lightning::ln::peer_handler::CustomMessageHandler) -> MessageHandler {
932         MessageHandler { inner: ObjOps::heap_alloc(nativeMessageHandler {
933                 chan_handler: chan_handler_arg,
934                 route_handler: route_handler_arg,
935                 onion_message_handler: onion_message_handler_arg,
936                 custom_message_handler: custom_message_handler_arg,
937         }), is_owned: true }
938 }
939 /// Provides an object which can be used to send data to and which uniquely identifies a connection
940 /// to a remote host. You will need to be able to generate multiple of these which meet Eq and
941 /// implement Hash to meet the PeerManager API.
942 ///
943 /// For efficiency, [`Clone`] should be relatively cheap for this type.
944 ///
945 /// Two descriptors may compare equal (by [`cmp::Eq`] and [`hash::Hash`]) as long as the original
946 /// has been disconnected, the [`PeerManager`] has been informed of the disconnection (either by it
947 /// having triggered the disconnection or a call to [`PeerManager::socket_disconnected`]), and no
948 /// further calls to the [`PeerManager`] related to the original socket occur. This allows you to
949 /// use a file descriptor for your SocketDescriptor directly, however for simplicity you may wish
950 /// to simply use another value which is guaranteed to be globally unique instead.
951 #[repr(C)]
952 pub struct SocketDescriptor {
953         /// An opaque pointer which is passed to your function implementations as an argument.
954         /// This has no meaning in the LDK, and can be NULL or any other value.
955         pub this_arg: *mut c_void,
956         /// Attempts to send some data from the given slice to the peer.
957         ///
958         /// Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
959         /// Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
960         /// called and further write attempts may occur until that time.
961         ///
962         /// If the returned size is smaller than `data.len()`, a
963         /// [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
964         /// written. Additionally, until a `send_data` event completes fully, no further
965         /// [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
966         /// prevent denial-of-service issues, you should not read or buffer any data from the socket
967         /// until then.
968         ///
969         /// If a [`PeerManager::read_event`] call on this descriptor had previously returned true
970         /// (indicating that read events should be paused to prevent DoS in the send buffer),
971         /// `resume_read` may be set indicating that read events on this descriptor should resume. A
972         /// `resume_read` of false carries no meaning, and should not cause any action.
973         pub send_data: extern "C" fn (this_arg: *mut c_void, data: crate::c_types::u8slice, resume_read: bool) -> usize,
974         /// Disconnect the socket pointed to by this SocketDescriptor.
975         ///
976         /// You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
977         /// call (doing so is a noop).
978         pub disconnect_socket: extern "C" fn (this_arg: *mut c_void),
979         /// Checks if two objects are equal given this object's this_arg pointer and another object.
980         pub eq: extern "C" fn (this_arg: *const c_void, other_arg: &SocketDescriptor) -> bool,
981         /// Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.
982         /// This is used, for example, for inclusion of this object in a hash map.
983         pub hash: extern "C" fn (this_arg: *const c_void) -> u64,
984         /// Called, if set, after this SocketDescriptor has been cloned into a duplicate object.
985         /// The new SocketDescriptor is provided, and should be mutated as needed to perform a
986         /// deep copy of the object pointed to by this_arg or avoid any double-freeing.
987         pub cloned: Option<extern "C" fn (new_SocketDescriptor: &mut SocketDescriptor)>,
988         /// Frees any resources associated with this object given its this_arg pointer.
989         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
990         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
991 }
992 unsafe impl Send for SocketDescriptor {}
993 unsafe impl Sync for SocketDescriptor {}
994 #[allow(unused)]
995 pub(crate) fn SocketDescriptor_clone_fields(orig: &SocketDescriptor) -> SocketDescriptor {
996         SocketDescriptor {
997                 this_arg: orig.this_arg,
998                 send_data: Clone::clone(&orig.send_data),
999                 disconnect_socket: Clone::clone(&orig.disconnect_socket),
1000                 eq: Clone::clone(&orig.eq),
1001                 hash: Clone::clone(&orig.hash),
1002                 cloned: Clone::clone(&orig.cloned),
1003                 free: Clone::clone(&orig.free),
1004         }
1005 }
1006 impl core::cmp::Eq for SocketDescriptor {}
1007 impl core::cmp::PartialEq for SocketDescriptor {
1008         fn eq(&self, o: &Self) -> bool { (self.eq)(self.this_arg, o) }
1009 }
1010 impl core::hash::Hash for SocketDescriptor {
1011         fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) { hasher.write_u64((self.hash)(self.this_arg)) }
1012 }
1013 #[no_mangle]
1014 /// Creates a copy of a SocketDescriptor
1015 pub extern "C" fn SocketDescriptor_clone(orig: &SocketDescriptor) -> SocketDescriptor {
1016         let mut res = SocketDescriptor_clone_fields(orig);
1017         if let Some(f) = orig.cloned { (f)(&mut res) };
1018         res
1019 }
1020 impl Clone for SocketDescriptor {
1021         fn clone(&self) -> Self {
1022                 SocketDescriptor_clone(self)
1023         }
1024 }
1025
1026 use lightning::ln::peer_handler::SocketDescriptor as rustSocketDescriptor;
1027 impl rustSocketDescriptor for SocketDescriptor {
1028         fn send_data(&mut self, mut data: &[u8], mut resume_read: bool) -> usize {
1029                 let mut local_data = crate::c_types::u8slice::from_slice(data);
1030                 let mut ret = (self.send_data)(self.this_arg, local_data, resume_read);
1031                 ret
1032         }
1033         fn disconnect_socket(&mut self) {
1034                 (self.disconnect_socket)(self.this_arg)
1035         }
1036 }
1037
1038 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1039 // directly as a Deref trait in higher-level structs:
1040 impl core::ops::Deref for SocketDescriptor {
1041         type Target = Self;
1042         fn deref(&self) -> &Self {
1043                 self
1044         }
1045 }
1046 impl core::ops::DerefMut for SocketDescriptor {
1047         fn deref_mut(&mut self) -> &mut Self {
1048                 self
1049         }
1050 }
1051 /// Calls the free function if one is set
1052 #[no_mangle]
1053 pub extern "C" fn SocketDescriptor_free(this_ptr: SocketDescriptor) { }
1054 impl Drop for SocketDescriptor {
1055         fn drop(&mut self) {
1056                 if let Some(f) = self.free {
1057                         f(self.this_arg);
1058                 }
1059         }
1060 }
1061
1062 use lightning::ln::peer_handler::PeerHandleError as nativePeerHandleErrorImport;
1063 pub(crate) type nativePeerHandleError = nativePeerHandleErrorImport;
1064
1065 /// Error for PeerManager errors. If you get one of these, you must disconnect the socket and
1066 /// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the
1067 /// descriptor.
1068 #[must_use]
1069 #[repr(C)]
1070 pub struct PeerHandleError {
1071         /// A pointer to the opaque Rust object.
1072
1073         /// Nearly everywhere, inner must be non-null, however in places where
1074         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1075         pub inner: *mut nativePeerHandleError,
1076         /// Indicates that this is the only struct which contains the same pointer.
1077
1078         /// Rust functions which take ownership of an object provided via an argument require
1079         /// this to be true and invalidate the object pointed to by inner.
1080         pub is_owned: bool,
1081 }
1082
1083 impl Drop for PeerHandleError {
1084         fn drop(&mut self) {
1085                 if self.is_owned && !<*mut nativePeerHandleError>::is_null(self.inner) {
1086                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1087                 }
1088         }
1089 }
1090 /// Frees any resources used by the PeerHandleError, if is_owned is set and inner is non-NULL.
1091 #[no_mangle]
1092 pub extern "C" fn PeerHandleError_free(this_obj: PeerHandleError) { }
1093 #[allow(unused)]
1094 /// Used only if an object of this type is returned as a trait impl by a method
1095 pub(crate) extern "C" fn PeerHandleError_free_void(this_ptr: *mut c_void) {
1096         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePeerHandleError) };
1097 }
1098 #[allow(unused)]
1099 impl PeerHandleError {
1100         pub(crate) fn get_native_ref(&self) -> &'static nativePeerHandleError {
1101                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1102         }
1103         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerHandleError {
1104                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1105         }
1106         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1107         pub(crate) fn take_inner(mut self) -> *mut nativePeerHandleError {
1108                 assert!(self.is_owned);
1109                 let ret = ObjOps::untweak_ptr(self.inner);
1110                 self.inner = core::ptr::null_mut();
1111                 ret
1112         }
1113 }
1114 /// Constructs a new PeerHandleError given each field
1115 #[must_use]
1116 #[no_mangle]
1117 pub extern "C" fn PeerHandleError_new() -> PeerHandleError {
1118         PeerHandleError { inner: ObjOps::heap_alloc(nativePeerHandleError {
1119         }), is_owned: true }
1120 }
1121 impl Clone for PeerHandleError {
1122         fn clone(&self) -> Self {
1123                 Self {
1124                         inner: if <*mut nativePeerHandleError>::is_null(self.inner) { core::ptr::null_mut() } else {
1125                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1126                         is_owned: true,
1127                 }
1128         }
1129 }
1130 #[allow(unused)]
1131 /// Used only if an object of this type is returned as a trait impl by a method
1132 pub(crate) extern "C" fn PeerHandleError_clone_void(this_ptr: *const c_void) -> *mut c_void {
1133         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePeerHandleError)).clone() })) as *mut c_void
1134 }
1135 #[no_mangle]
1136 /// Creates a copy of the PeerHandleError
1137 pub extern "C" fn PeerHandleError_clone(orig: &PeerHandleError) -> PeerHandleError {
1138         orig.clone()
1139 }
1140
1141 use lightning::ln::peer_handler::PeerManager as nativePeerManagerImport;
1142 pub(crate) type nativePeerManager = nativePeerManagerImport<crate::lightning::ln::peer_handler::SocketDescriptor, crate::lightning::ln::msgs::ChannelMessageHandler, crate::lightning::ln::msgs::RoutingMessageHandler, crate::lightning::ln::msgs::OnionMessageHandler, crate::lightning::util::logger::Logger, crate::lightning::ln::peer_handler::CustomMessageHandler, crate::lightning::sign::NodeSigner>;
1143
1144 /// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
1145 /// socket events into messages which it passes on to its [`MessageHandler`].
1146 ///
1147 /// Locks are taken internally, so you must never assume that reentrancy from a
1148 /// [`SocketDescriptor`] call back into [`PeerManager`] methods will not deadlock.
1149 ///
1150 /// Calls to [`read_event`] will decode relevant messages and pass them to the
1151 /// [`ChannelMessageHandler`], likely doing message processing in-line. Thus, the primary form of
1152 /// parallelism in Rust-Lightning is in calls to [`read_event`]. Note, however, that calls to any
1153 /// [`PeerManager`] functions related to the same connection must occur only in serial, making new
1154 /// calls only after previous ones have returned.
1155 ///
1156 /// Rather than using a plain [`PeerManager`], it is preferable to use either a [`SimpleArcPeerManager`]
1157 /// a [`SimpleRefPeerManager`], for conciseness. See their documentation for more details, but
1158 /// essentially you should default to using a [`SimpleRefPeerManager`], and use a
1159 /// [`SimpleArcPeerManager`] when you require a `PeerManager` with a static lifetime, such as when
1160 /// you're using lightning-net-tokio.
1161 ///
1162 /// [`read_event`]: PeerManager::read_event
1163 #[must_use]
1164 #[repr(C)]
1165 pub struct PeerManager {
1166         /// A pointer to the opaque Rust object.
1167
1168         /// Nearly everywhere, inner must be non-null, however in places where
1169         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1170         pub inner: *mut nativePeerManager,
1171         /// Indicates that this is the only struct which contains the same pointer.
1172
1173         /// Rust functions which take ownership of an object provided via an argument require
1174         /// this to be true and invalidate the object pointed to by inner.
1175         pub is_owned: bool,
1176 }
1177
1178 impl Drop for PeerManager {
1179         fn drop(&mut self) {
1180                 if self.is_owned && !<*mut nativePeerManager>::is_null(self.inner) {
1181                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1182                 }
1183         }
1184 }
1185 /// Frees any resources used by the PeerManager, if is_owned is set and inner is non-NULL.
1186 #[no_mangle]
1187 pub extern "C" fn PeerManager_free(this_obj: PeerManager) { }
1188 #[allow(unused)]
1189 /// Used only if an object of this type is returned as a trait impl by a method
1190 pub(crate) extern "C" fn PeerManager_free_void(this_ptr: *mut c_void) {
1191         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePeerManager) };
1192 }
1193 #[allow(unused)]
1194 impl PeerManager {
1195         pub(crate) fn get_native_ref(&self) -> &'static nativePeerManager {
1196                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1197         }
1198         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerManager {
1199                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1200         }
1201         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1202         pub(crate) fn take_inner(mut self) -> *mut nativePeerManager {
1203                 assert!(self.is_owned);
1204                 let ret = ObjOps::untweak_ptr(self.inner);
1205                 self.inner = core::ptr::null_mut();
1206                 ret
1207         }
1208 }
1209 /// Constructs a new `PeerManager` with the given message handlers.
1210 ///
1211 /// `ephemeral_random_data` is used to derive per-connection ephemeral keys and must be
1212 /// cryptographically secure random bytes.
1213 ///
1214 /// `current_time` is used as an always-increasing counter that survives across restarts and is
1215 /// incremented irregularly internally. In general it is best to simply use the current UNIX
1216 /// timestamp, however if it is not available a persistent counter that increases once per
1217 /// minute should suffice.
1218 #[must_use]
1219 #[no_mangle]
1220 pub extern "C" fn PeerManager_new(mut message_handler: crate::lightning::ln::peer_handler::MessageHandler, mut current_time: u32, ephemeral_random_data: *const [u8; 32], mut logger: crate::lightning::util::logger::Logger, mut node_signer: crate::lightning::sign::NodeSigner) -> crate::lightning::ln::peer_handler::PeerManager {
1221         let mut ret = lightning::ln::peer_handler::PeerManager::new(*unsafe { Box::from_raw(message_handler.take_inner()) }, current_time, unsafe { &*ephemeral_random_data}, logger, node_signer);
1222         crate::lightning::ln::peer_handler::PeerManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1223 }
1224
1225 /// Get a list of tuples mapping from node id to network addresses for peers which have
1226 /// completed the initial handshake.
1227 ///
1228 /// For outbound connections, the [`PublicKey`] will be the same as the `their_node_id` parameter
1229 /// passed in to [`Self::new_outbound_connection`], however entries will only appear once the initial
1230 /// handshake has completed and we are sure the remote peer has the private key for the given
1231 /// [`PublicKey`].
1232 ///
1233 /// The returned `Option`s will only be `Some` if an address had been previously given via
1234 /// [`Self::new_outbound_connection`] or [`Self::new_inbound_connection`].
1235 #[must_use]
1236 #[no_mangle]
1237 pub extern "C" fn PeerManager_get_peer_node_ids(this_arg: &crate::lightning::ln::peer_handler::PeerManager) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyCOption_SocketAddressZZZ {
1238         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_peer_node_ids();
1239         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 = if orig_ret_0_1.is_none() { crate::c_types::derived::COption_SocketAddressZ::None } else { crate::c_types::derived::COption_SocketAddressZ::Some( { crate::lightning::ln::msgs::SocketAddress::native_into(orig_ret_0_1.unwrap()) }) }; let mut local_ret_0 = (crate::c_types::PublicKey::from_rust(&orig_ret_0_0), local_orig_ret_0_1).into(); local_ret_0 }); };
1240         local_ret.into()
1241 }
1242
1243 /// Indicates a new outbound connection has been established to a node with the given `node_id`
1244 /// and an optional remote network address.
1245 ///
1246 /// The remote network address adds the option to report a remote IP address back to a connecting
1247 /// peer using the init message.
1248 /// The user should pass the remote network address of the host they are connected to.
1249 ///
1250 /// If an `Err` is returned here you must disconnect the connection immediately.
1251 ///
1252 /// Returns a small number of bytes to send to the remote node (currently always 50).
1253 ///
1254 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
1255 /// [`socket_disconnected`].
1256 ///
1257 /// [`socket_disconnected`]: PeerManager::socket_disconnected
1258 #[must_use]
1259 #[no_mangle]
1260 pub extern "C" fn PeerManager_new_outbound_connection(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut their_node_id: crate::c_types::PublicKey, mut descriptor: crate::lightning::ln::peer_handler::SocketDescriptor, mut remote_network_address: crate::c_types::derived::COption_SocketAddressZ) -> crate::c_types::derived::CResult_CVec_u8ZPeerHandleErrorZ {
1261         let mut local_remote_network_address = { /*remote_network_address*/ let remote_network_address_opt = remote_network_address; if remote_network_address_opt.is_none() { None } else { Some({ { { remote_network_address_opt.take() }.into_native() }})} };
1262         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_outbound_connection(their_node_id.into_rust(), descriptor, local_remote_network_address);
1263         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( { item }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::peer_handler::PeerHandleError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1264         local_ret
1265 }
1266
1267 /// Indicates a new inbound connection has been established to a node with an optional remote
1268 /// network address.
1269 ///
1270 /// The remote network address adds the option to report a remote IP address back to a connecting
1271 /// peer using the init message.
1272 /// The user should pass the remote network address of the host they are connected to.
1273 ///
1274 /// May refuse the connection by returning an Err, but will never write bytes to the remote end
1275 /// (outbound connector always speaks first). If an `Err` is returned here you must disconnect
1276 /// the connection immediately.
1277 ///
1278 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
1279 /// [`socket_disconnected`].
1280 ///
1281 /// [`socket_disconnected`]: PeerManager::socket_disconnected
1282 #[must_use]
1283 #[no_mangle]
1284 pub extern "C" fn PeerManager_new_inbound_connection(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut descriptor: crate::lightning::ln::peer_handler::SocketDescriptor, mut remote_network_address: crate::c_types::derived::COption_SocketAddressZ) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ {
1285         let mut local_remote_network_address = { /*remote_network_address*/ let remote_network_address_opt = remote_network_address; if remote_network_address_opt.is_none() { None } else { Some({ { { remote_network_address_opt.take() }.into_native() }})} };
1286         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_inbound_connection(descriptor, local_remote_network_address);
1287         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::ln::peer_handler::PeerHandleError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1288         local_ret
1289 }
1290
1291 /// Indicates that there is room to write data to the given socket descriptor.
1292 ///
1293 /// May return an Err to indicate that the connection should be closed.
1294 ///
1295 /// May call [`send_data`] on the descriptor passed in (or an equal descriptor) before
1296 /// returning. Thus, be very careful with reentrancy issues! The invariants around calling
1297 /// [`write_buffer_space_avail`] in case a write did not fully complete must still hold - be
1298 /// ready to call [`write_buffer_space_avail`] again if a write call generated here isn't
1299 /// sufficient!
1300 ///
1301 /// [`send_data`]: SocketDescriptor::send_data
1302 /// [`write_buffer_space_avail`]: PeerManager::write_buffer_space_avail
1303 #[must_use]
1304 #[no_mangle]
1305 pub extern "C" fn PeerManager_write_buffer_space_avail(this_arg: &crate::lightning::ln::peer_handler::PeerManager, descriptor: &mut crate::lightning::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ {
1306         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.write_buffer_space_avail(descriptor);
1307         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::ln::peer_handler::PeerHandleError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1308         local_ret
1309 }
1310
1311 /// Indicates that data was read from the given socket descriptor.
1312 ///
1313 /// May return an Err to indicate that the connection should be closed.
1314 ///
1315 /// Will *not* call back into [`send_data`] on any descriptors to avoid reentrancy complexity.
1316 /// Thus, however, you should call [`process_events`] after any `read_event` to generate
1317 /// [`send_data`] calls to handle responses.
1318 ///
1319 /// If `Ok(true)` is returned, further read_events should not be triggered until a
1320 /// [`send_data`] call on this descriptor has `resume_read` set (preventing DoS issues in the
1321 /// send buffer).
1322 ///
1323 /// In order to avoid processing too many messages at once per peer, `data` should be on the
1324 /// order of 4KiB.
1325 ///
1326 /// [`send_data`]: SocketDescriptor::send_data
1327 /// [`process_events`]: PeerManager::process_events
1328 #[must_use]
1329 #[no_mangle]
1330 pub extern "C" fn PeerManager_read_event(this_arg: &crate::lightning::ln::peer_handler::PeerManager, peer_descriptor: &mut crate::lightning::ln::peer_handler::SocketDescriptor, mut data: crate::c_types::u8slice) -> crate::c_types::derived::CResult_boolPeerHandleErrorZ {
1331         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_event(peer_descriptor, data.to_slice());
1332         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::ln::peer_handler::PeerHandleError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1333         local_ret
1334 }
1335
1336 /// Checks for any events generated by our handlers and processes them. Includes sending most
1337 /// response messages as well as messages generated by calls to handler functions directly (eg
1338 /// functions like [`ChannelManager::process_pending_htlc_forwards`] or [`send_payment`]).
1339 ///
1340 /// May call [`send_data`] on [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1341 /// issues!
1342 ///
1343 /// You don't have to call this function explicitly if you are using [`lightning-net-tokio`]
1344 /// or one of the other clients provided in our language bindings.
1345 ///
1346 /// Note that if there are any other calls to this function waiting on lock(s) this may return
1347 /// without doing any work. All available events that need handling will be handled before the
1348 /// other calls return.
1349 ///
1350 /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1351 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
1352 /// [`send_data`]: SocketDescriptor::send_data
1353 #[no_mangle]
1354 pub extern "C" fn PeerManager_process_events(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1355         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_events()
1356 }
1357
1358 /// Indicates that the given socket descriptor's connection is now closed.
1359 #[no_mangle]
1360 pub extern "C" fn PeerManager_socket_disconnected(this_arg: &crate::lightning::ln::peer_handler::PeerManager, descriptor: &crate::lightning::ln::peer_handler::SocketDescriptor) {
1361         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.socket_disconnected(descriptor)
1362 }
1363
1364 /// Disconnect a peer given its node id.
1365 ///
1366 /// If a peer is connected, this will call [`disconnect_socket`] on the descriptor for the
1367 /// peer. Thus, be very careful about reentrancy issues.
1368 ///
1369 /// [`disconnect_socket`]: SocketDescriptor::disconnect_socket
1370 #[no_mangle]
1371 pub extern "C" fn PeerManager_disconnect_by_node_id(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut node_id: crate::c_types::PublicKey) {
1372         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_by_node_id(node_id.into_rust())
1373 }
1374
1375 /// Disconnects all currently-connected peers. This is useful on platforms where there may be
1376 /// an indication that TCP sockets have stalled even if we weren't around to time them out
1377 /// using regular ping/pongs.
1378 #[no_mangle]
1379 pub extern "C" fn PeerManager_disconnect_all_peers(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1380         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_all_peers()
1381 }
1382
1383 /// Send pings to each peer and disconnect those which did not respond to the last round of
1384 /// pings.
1385 ///
1386 /// This may be called on any timescale you want, however, roughly once every ten seconds is
1387 /// preferred. The call rate determines both how often we send a ping to our peers and how much
1388 /// time they have to respond before we disconnect them.
1389 ///
1390 /// May call [`send_data`] on all [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1391 /// issues!
1392 ///
1393 /// [`send_data`]: SocketDescriptor::send_data
1394 #[no_mangle]
1395 pub extern "C" fn PeerManager_timer_tick_occurred(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1396         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1397 }
1398
1399 /// Generates a signed node_announcement from the given arguments, sending it to all connected
1400 /// peers. Note that peers will likely ignore this message unless we have at least one public
1401 /// channel which has at least six confirmations on-chain.
1402 ///
1403 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1404 /// node to humans. They carry no in-protocol meaning.
1405 ///
1406 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1407 /// accepts incoming connections. These will be included in the node_announcement, publicly
1408 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1409 /// addresses should likely contain only Tor Onion addresses.
1410 ///
1411 /// Panics if `addresses` is absurdly large (more than 100).
1412 ///
1413 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1414 #[no_mangle]
1415 pub extern "C" fn PeerManager_broadcast_node_announcement(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut rgb: crate::c_types::ThreeBytes, mut alias: crate::c_types::ThirtyTwoBytes, mut addresses: crate::c_types::derived::CVec_SocketAddressZ) {
1416         let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1417         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1418 }
1419
1420 use core::convert::Infallible as nativeInfallible;