Pin compiler_builtins to 0.1.109 when building std
[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::EventsProvider {
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_EventsProvider(&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 EventsProvider which calls the relevant methods on this_arg.
203 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
204 #[no_mangle]
205 pub extern "C" fn IgnoringMessageHandler_as_EventsProvider(this_arg: &IgnoringMessageHandler) -> crate::lightning::events::EventsProvider {
206         crate::lightning::events::EventsProvider {
207                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
208                 free: None,
209                 process_pending_events: IgnoringMessageHandler_EventsProvider_process_pending_events,
210         }
211 }
212
213 extern "C" fn IgnoringMessageHandler_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::events::EventHandler) {
214         <nativeIgnoringMessageHandler as lightning::events::EventsProvider>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, handler)
215 }
216
217 impl From<nativeIgnoringMessageHandler> for crate::lightning::events::MessageSendEventsProvider {
218         fn from(obj: nativeIgnoringMessageHandler) -> Self {
219                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
220                 let mut ret = IgnoringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
221                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
222                 core::mem::forget(rust_obj);
223                 ret.free = Some(IgnoringMessageHandler_free_void);
224                 ret
225         }
226 }
227 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
228 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
229 #[no_mangle]
230 pub extern "C" fn IgnoringMessageHandler_as_MessageSendEventsProvider(this_arg: &IgnoringMessageHandler) -> crate::lightning::events::MessageSendEventsProvider {
231         crate::lightning::events::MessageSendEventsProvider {
232                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
233                 free: None,
234                 get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
235         }
236 }
237
238 #[must_use]
239 extern "C" fn IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
240         let mut ret = <nativeIgnoringMessageHandler as lightning::events::MessageSendEventsProvider>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
241         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
242         local_ret.into()
243 }
244
245 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
246         fn from(obj: nativeIgnoringMessageHandler) -> Self {
247                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
248                 let mut ret = IgnoringMessageHandler_as_RoutingMessageHandler(&rust_obj);
249                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
250                 core::mem::forget(rust_obj);
251                 ret.free = Some(IgnoringMessageHandler_free_void);
252                 ret
253         }
254 }
255 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
256 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
257 #[no_mangle]
258 pub extern "C" fn IgnoringMessageHandler_as_RoutingMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
259         crate::lightning::ln::msgs::RoutingMessageHandler {
260                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
261                 free: None,
262                 handle_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement,
263                 handle_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement,
264                 handle_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update,
265                 get_next_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcement,
266                 get_next_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcement,
267                 peer_connected: IgnoringMessageHandler_RoutingMessageHandler_peer_connected,
268                 handle_reply_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_channel_range,
269                 handle_reply_short_channel_ids_end: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
270                 handle_query_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_query_channel_range,
271                 handle_query_short_channel_ids: IgnoringMessageHandler_RoutingMessageHandler_handle_query_short_channel_ids,
272                 processing_queue_high: IgnoringMessageHandler_RoutingMessageHandler_processing_queue_high,
273                 provided_node_features: IgnoringMessageHandler_RoutingMessageHandler_provided_node_features,
274                 provided_init_features: IgnoringMessageHandler_RoutingMessageHandler_provided_init_features,
275                 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
276                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
277                         free: None,
278                         get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
279                 },
280         }
281 }
282
283 #[must_use]
284 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 {
285         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
286         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() };
287         local_ret
288 }
289 #[must_use]
290 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 {
291         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
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( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
293         local_ret
294 }
295 #[must_use]
296 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 {
297         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
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_get_next_channel_announcement(this_arg: *const c_void, mut starting_point: u64) -> crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ {
303         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler>::get_next_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, starting_point);
304         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 }) };
305         local_ret
306 }
307 #[must_use]
308 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 {
309         let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) };
310         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler>::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, local_starting_point);
311         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 };
312         local_ret
313 }
314 #[must_use]
315 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 {
316         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);
317         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() };
318         local_ret
319 }
320 #[must_use]
321 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 {
322         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()) });
323         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() };
324         local_ret
325 }
326 #[must_use]
327 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 {
328         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()) });
329         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() };
330         local_ret
331 }
332 #[must_use]
333 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 {
334         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()) });
335         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() };
336         local_ret
337 }
338 #[must_use]
339 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 {
340         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()) });
341         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() };
342         local_ret
343 }
344 #[must_use]
345 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool {
346         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler>::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
347         ret
348 }
349 #[must_use]
350 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
351         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
352         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
353 }
354 #[must_use]
355 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 {
356         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
357         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
358 }
359
360 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::OnionMessageHandler {
361         fn from(obj: nativeIgnoringMessageHandler) -> Self {
362                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
363                 let mut ret = IgnoringMessageHandler_as_OnionMessageHandler(&rust_obj);
364                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
365                 core::mem::forget(rust_obj);
366                 ret.free = Some(IgnoringMessageHandler_free_void);
367                 ret
368         }
369 }
370 /// Constructs a new OnionMessageHandler which calls the relevant methods on this_arg.
371 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageHandler must be freed before this_arg is
372 #[no_mangle]
373 pub extern "C" fn IgnoringMessageHandler_as_OnionMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::msgs::OnionMessageHandler {
374         crate::lightning::ln::msgs::OnionMessageHandler {
375                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
376                 free: None,
377                 get_and_clear_connections_needed: IgnoringMessageHandler_OnionMessageHandler_get_and_clear_connections_needed,
378                 handle_onion_message: IgnoringMessageHandler_OnionMessageHandler_handle_onion_message,
379                 next_onion_message_for_peer: IgnoringMessageHandler_OnionMessageHandler_next_onion_message_for_peer,
380                 peer_connected: IgnoringMessageHandler_OnionMessageHandler_peer_connected,
381                 peer_disconnected: IgnoringMessageHandler_OnionMessageHandler_peer_disconnected,
382                 timer_tick_occurred: IgnoringMessageHandler_OnionMessageHandler_timer_tick_occurred,
383                 provided_node_features: IgnoringMessageHandler_OnionMessageHandler_provided_node_features,
384                 provided_init_features: IgnoringMessageHandler_OnionMessageHandler_provided_init_features,
385         }
386 }
387
388 #[must_use]
389 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_get_and_clear_connections_needed(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyCVec_SocketAddressZZZ {
390         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler>::get_and_clear_connections_needed(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
391         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; let mut local_ret_0 = (crate::c_types::PublicKey::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }); };
392         local_ret.into()
393 }
394 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) {
395         <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())
396 }
397 #[must_use]
398 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 {
399         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());
400         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 };
401         local_ret
402 }
403 #[must_use]
404 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 {
405         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);
406         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() };
407         local_ret
408 }
409 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
410         <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust())
411 }
412 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_timer_tick_occurred(this_arg: *const c_void) {
413         <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler>::timer_tick_occurred(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, )
414 }
415 #[must_use]
416 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
417         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
418         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
419 }
420 #[must_use]
421 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 {
422         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
423         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
424 }
425
426 impl From<nativeIgnoringMessageHandler> for crate::lightning::onion_message::offers::OffersMessageHandler {
427         fn from(obj: nativeIgnoringMessageHandler) -> Self {
428                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
429                 let mut ret = IgnoringMessageHandler_as_OffersMessageHandler(&rust_obj);
430                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
431                 core::mem::forget(rust_obj);
432                 ret.free = Some(IgnoringMessageHandler_free_void);
433                 ret
434         }
435 }
436 /// Constructs a new OffersMessageHandler which calls the relevant methods on this_arg.
437 /// This copies the `inner` pointer in this_arg and thus the returned OffersMessageHandler must be freed before this_arg is
438 #[no_mangle]
439 pub extern "C" fn IgnoringMessageHandler_as_OffersMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::onion_message::offers::OffersMessageHandler {
440         crate::lightning::onion_message::offers::OffersMessageHandler {
441                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
442                 free: None,
443                 handle_message: IgnoringMessageHandler_OffersMessageHandler_handle_message,
444                 release_pending_messages: IgnoringMessageHandler_OffersMessageHandler_release_pending_messages,
445         }
446 }
447
448 #[must_use]
449 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 {
450         let mut ret = <nativeIgnoringMessageHandler as lightning::onion_message::offers::OffersMessageHandler>::handle_message(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, message.into_native());
451         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()) }) };
452         local_ret
453 }
454 #[must_use]
455 extern "C" fn IgnoringMessageHandler_OffersMessageHandler_release_pending_messages(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ {
456         let mut ret = <nativeIgnoringMessageHandler as lightning::onion_message::offers::OffersMessageHandler>::release_pending_messages(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
457         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 }); };
458         local_ret.into()
459 }
460
461 impl From<nativeIgnoringMessageHandler> for crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
462         fn from(obj: nativeIgnoringMessageHandler) -> Self {
463                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
464                 let mut ret = IgnoringMessageHandler_as_CustomOnionMessageHandler(&rust_obj);
465                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
466                 core::mem::forget(rust_obj);
467                 ret.free = Some(IgnoringMessageHandler_free_void);
468                 ret
469         }
470 }
471 /// Constructs a new CustomOnionMessageHandler which calls the relevant methods on this_arg.
472 /// This copies the `inner` pointer in this_arg and thus the returned CustomOnionMessageHandler must be freed before this_arg is
473 #[no_mangle]
474 pub extern "C" fn IgnoringMessageHandler_as_CustomOnionMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
475         crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
476                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
477                 free: None,
478                 handle_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message,
479                 read_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_read_custom_message,
480                 release_pending_custom_messages: IgnoringMessageHandler_CustomOnionMessageHandler_release_pending_custom_messages,
481         }
482 }
483
484 #[must_use]
485 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 {
486         unreachable!();
487 }
488 #[must_use]
489 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 {
490         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());
491         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() };
492         local_ret
493 }
494 #[must_use]
495 extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_release_pending_custom_messages(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ {
496         let mut ret = <nativeIgnoringMessageHandler as lightning::onion_message::messenger::CustomOnionMessageHandler>::release_pending_custom_messages(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
497         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 }); };
498         local_ret.into()
499 }
500
501 impl From<nativeInfallible> for crate::lightning::onion_message::packet::OnionMessageContents {
502         fn from(obj: nativeInfallible) -> Self {
503                 unreachable!();
504         }
505 }
506 impl From<nativeInfallible> for crate::lightning::ln::wire::Type {
507         fn from(obj: nativeInfallible) -> Self {
508                 unreachable!();
509         }
510 }
511 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::wire::CustomMessageReader {
512         fn from(obj: nativeIgnoringMessageHandler) -> Self {
513                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
514                 let mut ret = IgnoringMessageHandler_as_CustomMessageReader(&rust_obj);
515                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
516                 core::mem::forget(rust_obj);
517                 ret.free = Some(IgnoringMessageHandler_free_void);
518                 ret
519         }
520 }
521 /// Constructs a new CustomMessageReader which calls the relevant methods on this_arg.
522 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageReader must be freed before this_arg is
523 #[no_mangle]
524 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageReader(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::wire::CustomMessageReader {
525         crate::lightning::ln::wire::CustomMessageReader {
526                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
527                 free: None,
528                 read: IgnoringMessageHandler_CustomMessageReader_read,
529         }
530 }
531
532 #[must_use]
533 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 {
534         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::wire::CustomMessageReader>::read(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, message_type, &mut buffer.to_reader());
535         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() };
536         local_ret
537 }
538
539 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::peer_handler::CustomMessageHandler {
540         fn from(obj: nativeIgnoringMessageHandler) -> Self {
541                 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
542                 let mut ret = IgnoringMessageHandler_as_CustomMessageHandler(&rust_obj);
543                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
544                 core::mem::forget(rust_obj);
545                 ret.free = Some(IgnoringMessageHandler_free_void);
546                 ret
547         }
548 }
549 /// Constructs a new CustomMessageHandler which calls the relevant methods on this_arg.
550 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageHandler must be freed before this_arg is
551 #[no_mangle]
552 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::peer_handler::CustomMessageHandler {
553         crate::lightning::ln::peer_handler::CustomMessageHandler {
554                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
555                 free: None,
556                 handle_custom_message: IgnoringMessageHandler_CustomMessageHandler_handle_custom_message,
557                 get_and_clear_pending_msg: IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg,
558                 provided_node_features: IgnoringMessageHandler_CustomMessageHandler_provided_node_features,
559                 provided_init_features: IgnoringMessageHandler_CustomMessageHandler_provided_init_features,
560                 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader {
561                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
562                         free: None,
563                         read: IgnoringMessageHandler_CustomMessageReader_read,
564                 },
565         }
566 }
567
568 #[must_use]
569 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 {
570         unreachable!();
571 }
572 #[must_use]
573 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ {
574         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler>::get_and_clear_pending_msg(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
575         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 }); };
576         local_ret.into()
577 }
578 #[must_use]
579 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
580         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
581         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
582 }
583 #[must_use]
584 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 {
585         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());
586         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
587 }
588
589
590 use lightning::ln::peer_handler::ErroringMessageHandler as nativeErroringMessageHandlerImport;
591 pub(crate) type nativeErroringMessageHandler = nativeErroringMessageHandlerImport;
592
593 /// A dummy struct which implements `ChannelMessageHandler` without having any channels.
594 /// You can provide one of these as the route_handler in a MessageHandler.
595 #[must_use]
596 #[repr(C)]
597 pub struct ErroringMessageHandler {
598         /// A pointer to the opaque Rust object.
599
600         /// Nearly everywhere, inner must be non-null, however in places where
601         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
602         pub inner: *mut nativeErroringMessageHandler,
603         /// Indicates that this is the only struct which contains the same pointer.
604
605         /// Rust functions which take ownership of an object provided via an argument require
606         /// this to be true and invalidate the object pointed to by inner.
607         pub is_owned: bool,
608 }
609
610 impl Drop for ErroringMessageHandler {
611         fn drop(&mut self) {
612                 if self.is_owned && !<*mut nativeErroringMessageHandler>::is_null(self.inner) {
613                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
614                 }
615         }
616 }
617 /// Frees any resources used by the ErroringMessageHandler, if is_owned is set and inner is non-NULL.
618 #[no_mangle]
619 pub extern "C" fn ErroringMessageHandler_free(this_obj: ErroringMessageHandler) { }
620 #[allow(unused)]
621 /// Used only if an object of this type is returned as a trait impl by a method
622 pub(crate) extern "C" fn ErroringMessageHandler_free_void(this_ptr: *mut c_void) {
623         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeErroringMessageHandler) };
624 }
625 #[allow(unused)]
626 impl ErroringMessageHandler {
627         pub(crate) fn get_native_ref(&self) -> &'static nativeErroringMessageHandler {
628                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
629         }
630         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeErroringMessageHandler {
631                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
632         }
633         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
634         pub(crate) fn take_inner(mut self) -> *mut nativeErroringMessageHandler {
635                 assert!(self.is_owned);
636                 let ret = ObjOps::untweak_ptr(self.inner);
637                 self.inner = core::ptr::null_mut();
638                 ret
639         }
640 }
641 /// Constructs a new ErroringMessageHandler
642 #[must_use]
643 #[no_mangle]
644 pub extern "C" fn ErroringMessageHandler_new() -> crate::lightning::ln::peer_handler::ErroringMessageHandler {
645         let mut ret = lightning::ln::peer_handler::ErroringMessageHandler::new();
646         crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
647 }
648
649 impl From<nativeErroringMessageHandler> for crate::lightning::events::MessageSendEventsProvider {
650         fn from(obj: nativeErroringMessageHandler) -> Self {
651                 let rust_obj = crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
652                 let mut ret = ErroringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
653                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
654                 core::mem::forget(rust_obj);
655                 ret.free = Some(ErroringMessageHandler_free_void);
656                 ret
657         }
658 }
659 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
660 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
661 #[no_mangle]
662 pub extern "C" fn ErroringMessageHandler_as_MessageSendEventsProvider(this_arg: &ErroringMessageHandler) -> crate::lightning::events::MessageSendEventsProvider {
663         crate::lightning::events::MessageSendEventsProvider {
664                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
665                 free: None,
666                 get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
667         }
668 }
669
670 #[must_use]
671 extern "C" fn ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
672         let mut ret = <nativeErroringMessageHandler as lightning::events::MessageSendEventsProvider>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
673         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
674         local_ret.into()
675 }
676
677 impl From<nativeErroringMessageHandler> for crate::lightning::ln::msgs::ChannelMessageHandler {
678         fn from(obj: nativeErroringMessageHandler) -> Self {
679                 let rust_obj = crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
680                 let mut ret = ErroringMessageHandler_as_ChannelMessageHandler(&rust_obj);
681                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
682                 core::mem::forget(rust_obj);
683                 ret.free = Some(ErroringMessageHandler_free_void);
684                 ret
685         }
686 }
687 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
688 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
689 #[no_mangle]
690 pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &ErroringMessageHandler) -> crate::lightning::ln::msgs::ChannelMessageHandler {
691         crate::lightning::ln::msgs::ChannelMessageHandler {
692                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
693                 free: None,
694                 handle_open_channel: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel,
695                 handle_open_channel_v2: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel_v2,
696                 handle_accept_channel: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel,
697                 handle_accept_channel_v2: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel_v2,
698                 handle_funding_created: ErroringMessageHandler_ChannelMessageHandler_handle_funding_created,
699                 handle_funding_signed: ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed,
700                 handle_channel_ready: ErroringMessageHandler_ChannelMessageHandler_handle_channel_ready,
701                 handle_shutdown: ErroringMessageHandler_ChannelMessageHandler_handle_shutdown,
702                 handle_closing_signed: ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed,
703                 handle_stfu: ErroringMessageHandler_ChannelMessageHandler_handle_stfu,
704                 handle_tx_add_input: ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_input,
705                 handle_tx_add_output: ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_output,
706                 handle_tx_remove_input: ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_input,
707                 handle_tx_remove_output: ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_output,
708                 handle_tx_complete: ErroringMessageHandler_ChannelMessageHandler_handle_tx_complete,
709                 handle_tx_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_tx_signatures,
710                 handle_tx_init_rbf: ErroringMessageHandler_ChannelMessageHandler_handle_tx_init_rbf,
711                 handle_tx_ack_rbf: ErroringMessageHandler_ChannelMessageHandler_handle_tx_ack_rbf,
712                 handle_tx_abort: ErroringMessageHandler_ChannelMessageHandler_handle_tx_abort,
713                 handle_update_add_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc,
714                 handle_update_fulfill_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc,
715                 handle_update_fail_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc,
716                 handle_update_fail_malformed_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_malformed_htlc,
717                 handle_commitment_signed: ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed,
718                 handle_revoke_and_ack: ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack,
719                 handle_update_fee: ErroringMessageHandler_ChannelMessageHandler_handle_update_fee,
720                 handle_announcement_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures,
721                 peer_disconnected: ErroringMessageHandler_ChannelMessageHandler_peer_disconnected,
722                 peer_connected: ErroringMessageHandler_ChannelMessageHandler_peer_connected,
723                 handle_channel_reestablish: ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish,
724                 handle_channel_update: ErroringMessageHandler_ChannelMessageHandler_handle_channel_update,
725                 handle_error: ErroringMessageHandler_ChannelMessageHandler_handle_error,
726                 provided_node_features: ErroringMessageHandler_ChannelMessageHandler_provided_node_features,
727                 provided_init_features: ErroringMessageHandler_ChannelMessageHandler_provided_init_features,
728                 get_chain_hashes: ErroringMessageHandler_ChannelMessageHandler_get_chain_hashes,
729                 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
730                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
731                         free: None,
732                         get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
733                 },
734         }
735 }
736
737 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) {
738         <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())
739 }
740 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) {
741         <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())
742 }
743 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) {
744         <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())
745 }
746 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) {
747         <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())
748 }
749 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) {
750         <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())
751 }
752 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) {
753         <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())
754 }
755 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) {
756         <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())
757 }
758 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) {
759         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
760 }
761 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) {
762         <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())
763 }
764 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_stfu(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Stfu) {
765         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler>::handle_stfu(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
766 }
767 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) {
768         <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())
769 }
770 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) {
771         <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())
772 }
773 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) {
774         <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())
775 }
776 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) {
777         <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())
778 }
779 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) {
780         <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())
781 }
782 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) {
783         <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())
784 }
785 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) {
786         <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())
787 }
788 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) {
789         <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())
790 }
791 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) {
792         <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())
793 }
794 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) {
795         <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())
796 }
797 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) {
798         <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())
799 }
800 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) {
801         <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())
802 }
803 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) {
804         <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())
805 }
806 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) {
807         <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())
808 }
809 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) {
810         <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())
811 }
812 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) {
813         <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())
814 }
815 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) {
816         <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())
817 }
818 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
819         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust())
820 }
821 #[must_use]
822 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 {
823         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);
824         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() };
825         local_ret
826 }
827 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) {
828         <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())
829 }
830 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) {
831         <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())
832 }
833 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) {
834         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler>::handle_error(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
835 }
836 #[must_use]
837 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
838         let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
839         crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
840 }
841 #[must_use]
842 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 {
843         let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust());
844         crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
845 }
846 #[must_use]
847 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_get_chain_hashes(this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
848         let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler>::get_chain_hashes(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
849         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.as_ref() } }); }; local_ret_0.into() }) };
850         local_ret
851 }
852
853
854 use lightning::ln::peer_handler::MessageHandler as nativeMessageHandlerImport;
855 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, >;
856
857 /// Provides references to trait impls which handle different types of messages.
858 #[must_use]
859 #[repr(C)]
860 pub struct MessageHandler {
861         /// A pointer to the opaque Rust object.
862
863         /// Nearly everywhere, inner must be non-null, however in places where
864         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
865         pub inner: *mut nativeMessageHandler,
866         /// Indicates that this is the only struct which contains the same pointer.
867
868         /// Rust functions which take ownership of an object provided via an argument require
869         /// this to be true and invalidate the object pointed to by inner.
870         pub is_owned: bool,
871 }
872
873 impl Drop for MessageHandler {
874         fn drop(&mut self) {
875                 if self.is_owned && !<*mut nativeMessageHandler>::is_null(self.inner) {
876                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
877                 }
878         }
879 }
880 /// Frees any resources used by the MessageHandler, if is_owned is set and inner is non-NULL.
881 #[no_mangle]
882 pub extern "C" fn MessageHandler_free(this_obj: MessageHandler) { }
883 #[allow(unused)]
884 /// Used only if an object of this type is returned as a trait impl by a method
885 pub(crate) extern "C" fn MessageHandler_free_void(this_ptr: *mut c_void) {
886         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMessageHandler) };
887 }
888 #[allow(unused)]
889 impl MessageHandler {
890         pub(crate) fn get_native_ref(&self) -> &'static nativeMessageHandler {
891                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
892         }
893         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMessageHandler {
894                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
895         }
896         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
897         pub(crate) fn take_inner(mut self) -> *mut nativeMessageHandler {
898                 assert!(self.is_owned);
899                 let ret = ObjOps::untweak_ptr(self.inner);
900                 self.inner = core::ptr::null_mut();
901                 ret
902         }
903 }
904 /// A message handler which handles messages specific to channels. Usually this is just a
905 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
906 ///
907 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
908 #[no_mangle]
909 pub extern "C" fn MessageHandler_get_chan_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::ChannelMessageHandler {
910         let mut inner_val = &mut this_ptr.get_native_mut_ref().chan_handler;
911         inner_val
912 }
913 /// A message handler which handles messages specific to channels. Usually this is just a
914 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
915 ///
916 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
917 #[no_mangle]
918 pub extern "C" fn MessageHandler_set_chan_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::ChannelMessageHandler) {
919         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chan_handler = val;
920 }
921 /// A message handler which handles messages updating our knowledge of the network channel
922 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
923 ///
924 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
925 #[no_mangle]
926 pub extern "C" fn MessageHandler_get_route_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::RoutingMessageHandler {
927         let mut inner_val = &mut this_ptr.get_native_mut_ref().route_handler;
928         inner_val
929 }
930 /// A message handler which handles messages updating our knowledge of the network channel
931 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
932 ///
933 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
934 #[no_mangle]
935 pub extern "C" fn MessageHandler_set_route_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::RoutingMessageHandler) {
936         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_handler = val;
937 }
938 /// A message handler which handles onion messages. This should generally be an
939 /// [`OnionMessenger`], but can also be an [`IgnoringMessageHandler`].
940 ///
941 /// [`OnionMessenger`]: crate::onion_message::messenger::OnionMessenger
942 #[no_mangle]
943 pub extern "C" fn MessageHandler_get_onion_message_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::OnionMessageHandler {
944         let mut inner_val = &mut this_ptr.get_native_mut_ref().onion_message_handler;
945         inner_val
946 }
947 /// A message handler which handles onion messages. This should generally be an
948 /// [`OnionMessenger`], but can also be an [`IgnoringMessageHandler`].
949 ///
950 /// [`OnionMessenger`]: crate::onion_message::messenger::OnionMessenger
951 #[no_mangle]
952 pub extern "C" fn MessageHandler_set_onion_message_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::OnionMessageHandler) {
953         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.onion_message_handler = val;
954 }
955 /// A message handler which handles custom messages. The only LDK-provided implementation is
956 /// [`IgnoringMessageHandler`].
957 #[no_mangle]
958 pub extern "C" fn MessageHandler_get_custom_message_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::peer_handler::CustomMessageHandler {
959         let mut inner_val = &mut this_ptr.get_native_mut_ref().custom_message_handler;
960         inner_val
961 }
962 /// A message handler which handles custom messages. The only LDK-provided implementation is
963 /// [`IgnoringMessageHandler`].
964 #[no_mangle]
965 pub extern "C" fn MessageHandler_set_custom_message_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::peer_handler::CustomMessageHandler) {
966         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.custom_message_handler = val;
967 }
968 /// Constructs a new MessageHandler given each field
969 #[must_use]
970 #[no_mangle]
971 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 {
972         MessageHandler { inner: ObjOps::heap_alloc(nativeMessageHandler {
973                 chan_handler: chan_handler_arg,
974                 route_handler: route_handler_arg,
975                 onion_message_handler: onion_message_handler_arg,
976                 custom_message_handler: custom_message_handler_arg,
977         }), is_owned: true }
978 }
979 /// Provides an object which can be used to send data to and which uniquely identifies a connection
980 /// to a remote host. You will need to be able to generate multiple of these which meet Eq and
981 /// implement Hash to meet the PeerManager API.
982 ///
983 /// For efficiency, [`Clone`] should be relatively cheap for this type.
984 ///
985 /// Two descriptors may compare equal (by [`cmp::Eq`] and [`hash::Hash`]) as long as the original
986 /// has been disconnected, the [`PeerManager`] has been informed of the disconnection (either by it
987 /// having triggered the disconnection or a call to [`PeerManager::socket_disconnected`]), and no
988 /// further calls to the [`PeerManager`] related to the original socket occur. This allows you to
989 /// use a file descriptor for your SocketDescriptor directly, however for simplicity you may wish
990 /// to simply use another value which is guaranteed to be globally unique instead.
991 #[repr(C)]
992 pub struct SocketDescriptor {
993         /// An opaque pointer which is passed to your function implementations as an argument.
994         /// This has no meaning in the LDK, and can be NULL or any other value.
995         pub this_arg: *mut c_void,
996         /// Attempts to send some data from the given slice to the peer.
997         ///
998         /// Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
999         /// Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
1000         /// called and further write attempts may occur until that time.
1001         ///
1002         /// If the returned size is smaller than `data.len()`, a
1003         /// [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
1004         /// written. Additionally, until a `send_data` event completes fully, no further
1005         /// [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
1006         /// prevent denial-of-service issues, you should not read or buffer any data from the socket
1007         /// until then.
1008         ///
1009         /// If a [`PeerManager::read_event`] call on this descriptor had previously returned true
1010         /// (indicating that read events should be paused to prevent DoS in the send buffer),
1011         /// `resume_read` may be set indicating that read events on this descriptor should resume. A
1012         /// `resume_read` of false carries no meaning, and should not cause any action.
1013         pub send_data: extern "C" fn (this_arg: *mut c_void, data: crate::c_types::u8slice, resume_read: bool) -> usize,
1014         /// Disconnect the socket pointed to by this SocketDescriptor.
1015         ///
1016         /// You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
1017         /// call (doing so is a noop).
1018         pub disconnect_socket: extern "C" fn (this_arg: *mut c_void),
1019         /// Checks if two objects are equal given this object's this_arg pointer and another object.
1020         pub eq: extern "C" fn (this_arg: *const c_void, other_arg: &SocketDescriptor) -> bool,
1021         /// Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.
1022         /// This is used, for example, for inclusion of this object in a hash map.
1023         pub hash: extern "C" fn (this_arg: *const c_void) -> u64,
1024         /// Called, if set, after this SocketDescriptor has been cloned into a duplicate object.
1025         /// The new SocketDescriptor is provided, and should be mutated as needed to perform a
1026         /// deep copy of the object pointed to by this_arg or avoid any double-freeing.
1027         pub cloned: Option<extern "C" fn (new_SocketDescriptor: &mut SocketDescriptor)>,
1028         /// Frees any resources associated with this object given its this_arg pointer.
1029         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1030         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1031 }
1032 unsafe impl Send for SocketDescriptor {}
1033 unsafe impl Sync for SocketDescriptor {}
1034 #[allow(unused)]
1035 pub(crate) fn SocketDescriptor_clone_fields(orig: &SocketDescriptor) -> SocketDescriptor {
1036         SocketDescriptor {
1037                 this_arg: orig.this_arg,
1038                 send_data: Clone::clone(&orig.send_data),
1039                 disconnect_socket: Clone::clone(&orig.disconnect_socket),
1040                 eq: Clone::clone(&orig.eq),
1041                 hash: Clone::clone(&orig.hash),
1042                 cloned: Clone::clone(&orig.cloned),
1043                 free: Clone::clone(&orig.free),
1044         }
1045 }
1046 impl core::cmp::Eq for SocketDescriptor {}
1047 impl core::cmp::PartialEq for SocketDescriptor {
1048         fn eq(&self, o: &Self) -> bool { (self.eq)(self.this_arg, o) }
1049 }
1050 impl core::hash::Hash for SocketDescriptor {
1051         fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) { hasher.write_u64((self.hash)(self.this_arg)) }
1052 }
1053 #[no_mangle]
1054 /// Creates a copy of a SocketDescriptor
1055 pub extern "C" fn SocketDescriptor_clone(orig: &SocketDescriptor) -> SocketDescriptor {
1056         let mut res = SocketDescriptor_clone_fields(orig);
1057         if let Some(f) = orig.cloned { (f)(&mut res) };
1058         res
1059 }
1060 impl Clone for SocketDescriptor {
1061         fn clone(&self) -> Self {
1062                 SocketDescriptor_clone(self)
1063         }
1064 }
1065
1066 use lightning::ln::peer_handler::SocketDescriptor as rustSocketDescriptor;
1067 impl rustSocketDescriptor for SocketDescriptor {
1068         fn send_data(&mut self, mut data: &[u8], mut resume_read: bool) -> usize {
1069                 let mut local_data = crate::c_types::u8slice::from_slice(data);
1070                 let mut ret = (self.send_data)(self.this_arg, local_data, resume_read);
1071                 ret
1072         }
1073         fn disconnect_socket(&mut self) {
1074                 (self.disconnect_socket)(self.this_arg)
1075         }
1076 }
1077
1078 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1079 // directly as a Deref trait in higher-level structs:
1080 impl core::ops::Deref for SocketDescriptor {
1081         type Target = Self;
1082         fn deref(&self) -> &Self {
1083                 self
1084         }
1085 }
1086 impl core::ops::DerefMut for SocketDescriptor {
1087         fn deref_mut(&mut self) -> &mut Self {
1088                 self
1089         }
1090 }
1091 /// Calls the free function if one is set
1092 #[no_mangle]
1093 pub extern "C" fn SocketDescriptor_free(this_ptr: SocketDescriptor) { }
1094 impl Drop for SocketDescriptor {
1095         fn drop(&mut self) {
1096                 if let Some(f) = self.free {
1097                         f(self.this_arg);
1098                 }
1099         }
1100 }
1101
1102 use lightning::ln::peer_handler::PeerDetails as nativePeerDetailsImport;
1103 pub(crate) type nativePeerDetails = nativePeerDetailsImport;
1104
1105 /// Details of a connected peer as returned by [`PeerManager::list_peers`].
1106 #[must_use]
1107 #[repr(C)]
1108 pub struct PeerDetails {
1109         /// A pointer to the opaque Rust object.
1110
1111         /// Nearly everywhere, inner must be non-null, however in places where
1112         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1113         pub inner: *mut nativePeerDetails,
1114         /// Indicates that this is the only struct which contains the same pointer.
1115
1116         /// Rust functions which take ownership of an object provided via an argument require
1117         /// this to be true and invalidate the object pointed to by inner.
1118         pub is_owned: bool,
1119 }
1120
1121 impl Drop for PeerDetails {
1122         fn drop(&mut self) {
1123                 if self.is_owned && !<*mut nativePeerDetails>::is_null(self.inner) {
1124                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1125                 }
1126         }
1127 }
1128 /// Frees any resources used by the PeerDetails, if is_owned is set and inner is non-NULL.
1129 #[no_mangle]
1130 pub extern "C" fn PeerDetails_free(this_obj: PeerDetails) { }
1131 #[allow(unused)]
1132 /// Used only if an object of this type is returned as a trait impl by a method
1133 pub(crate) extern "C" fn PeerDetails_free_void(this_ptr: *mut c_void) {
1134         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePeerDetails) };
1135 }
1136 #[allow(unused)]
1137 impl PeerDetails {
1138         pub(crate) fn get_native_ref(&self) -> &'static nativePeerDetails {
1139                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1140         }
1141         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerDetails {
1142                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1143         }
1144         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1145         pub(crate) fn take_inner(mut self) -> *mut nativePeerDetails {
1146                 assert!(self.is_owned);
1147                 let ret = ObjOps::untweak_ptr(self.inner);
1148                 self.inner = core::ptr::null_mut();
1149                 ret
1150         }
1151 }
1152 /// The node id of the peer.
1153 ///
1154 /// For outbound connections, this [`PublicKey`] will be the same as the `their_node_id` parameter
1155 /// passed in to [`PeerManager::new_outbound_connection`].
1156 #[no_mangle]
1157 pub extern "C" fn PeerDetails_get_counterparty_node_id(this_ptr: &PeerDetails) -> crate::c_types::PublicKey {
1158         let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_node_id;
1159         crate::c_types::PublicKey::from_rust(&inner_val)
1160 }
1161 /// The node id of the peer.
1162 ///
1163 /// For outbound connections, this [`PublicKey`] will be the same as the `their_node_id` parameter
1164 /// passed in to [`PeerManager::new_outbound_connection`].
1165 #[no_mangle]
1166 pub extern "C" fn PeerDetails_set_counterparty_node_id(this_ptr: &mut PeerDetails, mut val: crate::c_types::PublicKey) {
1167         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_node_id = val.into_rust();
1168 }
1169 /// The socket address the peer provided in the initial handshake.
1170 ///
1171 /// Will only be `Some` if an address had been previously provided to
1172 /// [`PeerManager::new_outbound_connection`] or [`PeerManager::new_inbound_connection`].
1173 ///
1174 /// Returns a copy of the field.
1175 #[no_mangle]
1176 pub extern "C" fn PeerDetails_get_socket_address(this_ptr: &PeerDetails) -> crate::c_types::derived::COption_SocketAddressZ {
1177         let mut inner_val = this_ptr.get_native_mut_ref().socket_address.clone();
1178         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_SocketAddressZ::None } else { crate::c_types::derived::COption_SocketAddressZ::Some( { crate::lightning::ln::msgs::SocketAddress::native_into(inner_val.unwrap()) }) };
1179         local_inner_val
1180 }
1181 /// The socket address the peer provided in the initial handshake.
1182 ///
1183 /// Will only be `Some` if an address had been previously provided to
1184 /// [`PeerManager::new_outbound_connection`] or [`PeerManager::new_inbound_connection`].
1185 #[no_mangle]
1186 pub extern "C" fn PeerDetails_set_socket_address(this_ptr: &mut PeerDetails, mut val: crate::c_types::derived::COption_SocketAddressZ) {
1187         let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { { val_opt.take() }.into_native() }})} };
1188         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.socket_address = local_val;
1189 }
1190 /// The features the peer provided in the initial handshake.
1191 #[no_mangle]
1192 pub extern "C" fn PeerDetails_get_init_features(this_ptr: &PeerDetails) -> crate::lightning::ln::features::InitFeatures {
1193         let mut inner_val = &mut this_ptr.get_native_mut_ref().init_features;
1194         crate::lightning::ln::features::InitFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::InitFeatures<>) as *mut _) }, is_owned: false }
1195 }
1196 /// The features the peer provided in the initial handshake.
1197 #[no_mangle]
1198 pub extern "C" fn PeerDetails_set_init_features(this_ptr: &mut PeerDetails, mut val: crate::lightning::ln::features::InitFeatures) {
1199         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.init_features = *unsafe { Box::from_raw(val.take_inner()) };
1200 }
1201 /// Indicates the direction of the peer connection.
1202 ///
1203 /// Will be `true` for inbound connections, and `false` for outbound connections.
1204 #[no_mangle]
1205 pub extern "C" fn PeerDetails_get_is_inbound_connection(this_ptr: &PeerDetails) -> bool {
1206         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_inbound_connection;
1207         *inner_val
1208 }
1209 /// Indicates the direction of the peer connection.
1210 ///
1211 /// Will be `true` for inbound connections, and `false` for outbound connections.
1212 #[no_mangle]
1213 pub extern "C" fn PeerDetails_set_is_inbound_connection(this_ptr: &mut PeerDetails, mut val: bool) {
1214         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_inbound_connection = val;
1215 }
1216 /// Constructs a new PeerDetails given each field
1217 #[must_use]
1218 #[no_mangle]
1219 pub extern "C" fn PeerDetails_new(mut counterparty_node_id_arg: crate::c_types::PublicKey, mut socket_address_arg: crate::c_types::derived::COption_SocketAddressZ, mut init_features_arg: crate::lightning::ln::features::InitFeatures, mut is_inbound_connection_arg: bool) -> PeerDetails {
1220         let mut local_socket_address_arg = { /*socket_address_arg*/ let socket_address_arg_opt = socket_address_arg; if socket_address_arg_opt.is_none() { None } else { Some({ { { socket_address_arg_opt.take() }.into_native() }})} };
1221         PeerDetails { inner: ObjOps::heap_alloc(nativePeerDetails {
1222                 counterparty_node_id: counterparty_node_id_arg.into_rust(),
1223                 socket_address: local_socket_address_arg,
1224                 init_features: *unsafe { Box::from_raw(init_features_arg.take_inner()) },
1225                 is_inbound_connection: is_inbound_connection_arg,
1226         }), is_owned: true }
1227 }
1228
1229 use lightning::ln::peer_handler::PeerHandleError as nativePeerHandleErrorImport;
1230 pub(crate) type nativePeerHandleError = nativePeerHandleErrorImport;
1231
1232 /// Error for PeerManager errors. If you get one of these, you must disconnect the socket and
1233 /// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the
1234 /// descriptor.
1235 #[must_use]
1236 #[repr(C)]
1237 pub struct PeerHandleError {
1238         /// A pointer to the opaque Rust object.
1239
1240         /// Nearly everywhere, inner must be non-null, however in places where
1241         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1242         pub inner: *mut nativePeerHandleError,
1243         /// Indicates that this is the only struct which contains the same pointer.
1244
1245         /// Rust functions which take ownership of an object provided via an argument require
1246         /// this to be true and invalidate the object pointed to by inner.
1247         pub is_owned: bool,
1248 }
1249
1250 impl Drop for PeerHandleError {
1251         fn drop(&mut self) {
1252                 if self.is_owned && !<*mut nativePeerHandleError>::is_null(self.inner) {
1253                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1254                 }
1255         }
1256 }
1257 /// Frees any resources used by the PeerHandleError, if is_owned is set and inner is non-NULL.
1258 #[no_mangle]
1259 pub extern "C" fn PeerHandleError_free(this_obj: PeerHandleError) { }
1260 #[allow(unused)]
1261 /// Used only if an object of this type is returned as a trait impl by a method
1262 pub(crate) extern "C" fn PeerHandleError_free_void(this_ptr: *mut c_void) {
1263         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePeerHandleError) };
1264 }
1265 #[allow(unused)]
1266 impl PeerHandleError {
1267         pub(crate) fn get_native_ref(&self) -> &'static nativePeerHandleError {
1268                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1269         }
1270         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerHandleError {
1271                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1272         }
1273         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1274         pub(crate) fn take_inner(mut self) -> *mut nativePeerHandleError {
1275                 assert!(self.is_owned);
1276                 let ret = ObjOps::untweak_ptr(self.inner);
1277                 self.inner = core::ptr::null_mut();
1278                 ret
1279         }
1280 }
1281 /// Constructs a new PeerHandleError given each field
1282 #[must_use]
1283 #[no_mangle]
1284 pub extern "C" fn PeerHandleError_new() -> PeerHandleError {
1285         PeerHandleError { inner: ObjOps::heap_alloc(nativePeerHandleError {
1286         }), is_owned: true }
1287 }
1288 impl Clone for PeerHandleError {
1289         fn clone(&self) -> Self {
1290                 Self {
1291                         inner: if <*mut nativePeerHandleError>::is_null(self.inner) { core::ptr::null_mut() } else {
1292                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1293                         is_owned: true,
1294                 }
1295         }
1296 }
1297 #[allow(unused)]
1298 /// Used only if an object of this type is returned as a trait impl by a method
1299 pub(crate) extern "C" fn PeerHandleError_clone_void(this_ptr: *const c_void) -> *mut c_void {
1300         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePeerHandleError)).clone() })) as *mut c_void
1301 }
1302 #[no_mangle]
1303 /// Creates a copy of the PeerHandleError
1304 pub extern "C" fn PeerHandleError_clone(orig: &PeerHandleError) -> PeerHandleError {
1305         orig.clone()
1306 }
1307 /// Get a string which allows debug introspection of a PeerHandleError object
1308 pub extern "C" fn PeerHandleError_debug_str_void(o: *const c_void) -> Str {
1309         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::peer_handler::PeerHandleError }).into()}
1310
1311 use lightning::ln::peer_handler::PeerManager as nativePeerManagerImport;
1312 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, >;
1313
1314 /// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
1315 /// socket events into messages which it passes on to its [`MessageHandler`].
1316 ///
1317 /// Locks are taken internally, so you must never assume that reentrancy from a
1318 /// [`SocketDescriptor`] call back into [`PeerManager`] methods will not deadlock.
1319 ///
1320 /// Calls to [`read_event`] will decode relevant messages and pass them to the
1321 /// [`ChannelMessageHandler`], likely doing message processing in-line. Thus, the primary form of
1322 /// parallelism in Rust-Lightning is in calls to [`read_event`]. Note, however, that calls to any
1323 /// [`PeerManager`] functions related to the same connection must occur only in serial, making new
1324 /// calls only after previous ones have returned.
1325 ///
1326 /// Rather than using a plain [`PeerManager`], it is preferable to use either a [`SimpleArcPeerManager`]
1327 /// a [`SimpleRefPeerManager`], for conciseness. See their documentation for more details, but
1328 /// essentially you should default to using a [`SimpleRefPeerManager`], and use a
1329 /// [`SimpleArcPeerManager`] when you require a `PeerManager` with a static lifetime, such as when
1330 /// you're using lightning-net-tokio.
1331 ///
1332 /// [`read_event`]: PeerManager::read_event
1333 #[must_use]
1334 #[repr(C)]
1335 pub struct PeerManager {
1336         /// A pointer to the opaque Rust object.
1337
1338         /// Nearly everywhere, inner must be non-null, however in places where
1339         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1340         pub inner: *mut nativePeerManager,
1341         /// Indicates that this is the only struct which contains the same pointer.
1342
1343         /// Rust functions which take ownership of an object provided via an argument require
1344         /// this to be true and invalidate the object pointed to by inner.
1345         pub is_owned: bool,
1346 }
1347
1348 impl Drop for PeerManager {
1349         fn drop(&mut self) {
1350                 if self.is_owned && !<*mut nativePeerManager>::is_null(self.inner) {
1351                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1352                 }
1353         }
1354 }
1355 /// Frees any resources used by the PeerManager, if is_owned is set and inner is non-NULL.
1356 #[no_mangle]
1357 pub extern "C" fn PeerManager_free(this_obj: PeerManager) { }
1358 #[allow(unused)]
1359 /// Used only if an object of this type is returned as a trait impl by a method
1360 pub(crate) extern "C" fn PeerManager_free_void(this_ptr: *mut c_void) {
1361         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePeerManager) };
1362 }
1363 #[allow(unused)]
1364 impl PeerManager {
1365         pub(crate) fn get_native_ref(&self) -> &'static nativePeerManager {
1366                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1367         }
1368         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerManager {
1369                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1370         }
1371         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1372         pub(crate) fn take_inner(mut self) -> *mut nativePeerManager {
1373                 assert!(self.is_owned);
1374                 let ret = ObjOps::untweak_ptr(self.inner);
1375                 self.inner = core::ptr::null_mut();
1376                 ret
1377         }
1378 }
1379 /// Constructs a new `PeerManager` with the given message handlers.
1380 ///
1381 /// `ephemeral_random_data` is used to derive per-connection ephemeral keys and must be
1382 /// cryptographically secure random bytes.
1383 ///
1384 /// `current_time` is used as an always-increasing counter that survives across restarts and is
1385 /// incremented irregularly internally. In general it is best to simply use the current UNIX
1386 /// timestamp, however if it is not available a persistent counter that increases once per
1387 /// minute should suffice.
1388 #[must_use]
1389 #[no_mangle]
1390 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 {
1391         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);
1392         crate::lightning::ln::peer_handler::PeerManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1393 }
1394
1395 /// Returns a list of [`PeerDetails`] for connected peers that have completed the initial
1396 /// handshake.
1397 #[must_use]
1398 #[no_mangle]
1399 pub extern "C" fn PeerManager_list_peers(this_arg: &crate::lightning::ln::peer_handler::PeerManager) -> crate::c_types::derived::CVec_PeerDetailsZ {
1400         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_peers();
1401         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::peer_handler::PeerDetails { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1402         local_ret.into()
1403 }
1404
1405 /// Returns the [`PeerDetails`] of a connected peer that has completed the initial handshake.
1406 ///
1407 /// Will return `None` if the peer is unknown or it hasn't completed the initial handshake.
1408 ///
1409 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1410 #[must_use]
1411 #[no_mangle]
1412 pub extern "C" fn PeerManager_peer_by_node_id(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::peer_handler::PeerDetails {
1413         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.peer_by_node_id(&their_node_id.into_rust());
1414         let mut local_ret = crate::lightning::ln::peer_handler::PeerDetails { inner: if ret.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
1415         local_ret
1416 }
1417
1418 /// Indicates a new outbound connection has been established to a node with the given `node_id`
1419 /// and an optional remote network address.
1420 ///
1421 /// The remote network address adds the option to report a remote IP address back to a connecting
1422 /// peer using the init message.
1423 /// The user should pass the remote network address of the host they are connected to.
1424 ///
1425 /// If an `Err` is returned here you must disconnect the connection immediately.
1426 ///
1427 /// Returns a small number of bytes to send to the remote node (currently always 50).
1428 ///
1429 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
1430 /// [`socket_disconnected`].
1431 ///
1432 /// [`socket_disconnected`]: PeerManager::socket_disconnected
1433 #[must_use]
1434 #[no_mangle]
1435 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 {
1436         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() }})} };
1437         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_outbound_connection(their_node_id.into_rust(), descriptor, local_remote_network_address);
1438         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() };
1439         local_ret
1440 }
1441
1442 /// Indicates a new inbound connection has been established to a node with an optional remote
1443 /// network address.
1444 ///
1445 /// The remote network address adds the option to report a remote IP address back to a connecting
1446 /// peer using the init message.
1447 /// The user should pass the remote network address of the host they are connected to.
1448 ///
1449 /// May refuse the connection by returning an Err, but will never write bytes to the remote end
1450 /// (outbound connector always speaks first). If an `Err` is returned here you must disconnect
1451 /// the connection immediately.
1452 ///
1453 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
1454 /// [`socket_disconnected`].
1455 ///
1456 /// [`socket_disconnected`]: PeerManager::socket_disconnected
1457 #[must_use]
1458 #[no_mangle]
1459 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 {
1460         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() }})} };
1461         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_inbound_connection(descriptor, local_remote_network_address);
1462         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() };
1463         local_ret
1464 }
1465
1466 /// Indicates that there is room to write data to the given socket descriptor.
1467 ///
1468 /// May return an Err to indicate that the connection should be closed.
1469 ///
1470 /// May call [`send_data`] on the descriptor passed in (or an equal descriptor) before
1471 /// returning. Thus, be very careful with reentrancy issues! The invariants around calling
1472 /// [`write_buffer_space_avail`] in case a write did not fully complete must still hold - be
1473 /// ready to call [`write_buffer_space_avail`] again if a write call generated here isn't
1474 /// sufficient!
1475 ///
1476 /// [`send_data`]: SocketDescriptor::send_data
1477 /// [`write_buffer_space_avail`]: PeerManager::write_buffer_space_avail
1478 #[must_use]
1479 #[no_mangle]
1480 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 {
1481         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.write_buffer_space_avail(descriptor);
1482         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() };
1483         local_ret
1484 }
1485
1486 /// Indicates that data was read from the given socket descriptor.
1487 ///
1488 /// May return an Err to indicate that the connection should be closed.
1489 ///
1490 /// Will *not* call back into [`send_data`] on any descriptors to avoid reentrancy complexity.
1491 /// Thus, however, you should call [`process_events`] after any `read_event` to generate
1492 /// [`send_data`] calls to handle responses.
1493 ///
1494 /// If `Ok(true)` is returned, further read_events should not be triggered until a
1495 /// [`send_data`] call on this descriptor has `resume_read` set (preventing DoS issues in the
1496 /// send buffer).
1497 ///
1498 /// In order to avoid processing too many messages at once per peer, `data` should be on the
1499 /// order of 4KiB.
1500 ///
1501 /// [`send_data`]: SocketDescriptor::send_data
1502 /// [`process_events`]: PeerManager::process_events
1503 #[must_use]
1504 #[no_mangle]
1505 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 {
1506         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_event(peer_descriptor, data.to_slice());
1507         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() };
1508         local_ret
1509 }
1510
1511 /// Checks for any events generated by our handlers and processes them. Includes sending most
1512 /// response messages as well as messages generated by calls to handler functions directly (eg
1513 /// functions like [`ChannelManager::process_pending_htlc_forwards`] or [`send_payment`]).
1514 ///
1515 /// May call [`send_data`] on [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1516 /// issues!
1517 ///
1518 /// You don't have to call this function explicitly if you are using [`lightning-net-tokio`]
1519 /// or one of the other clients provided in our language bindings.
1520 ///
1521 /// Note that if there are any other calls to this function waiting on lock(s) this may return
1522 /// without doing any work. All available events that need handling will be handled before the
1523 /// other calls return.
1524 ///
1525 /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1526 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
1527 /// [`send_data`]: SocketDescriptor::send_data
1528 #[no_mangle]
1529 pub extern "C" fn PeerManager_process_events(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1530         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_events()
1531 }
1532
1533 /// Indicates that the given socket descriptor's connection is now closed.
1534 #[no_mangle]
1535 pub extern "C" fn PeerManager_socket_disconnected(this_arg: &crate::lightning::ln::peer_handler::PeerManager, descriptor: &crate::lightning::ln::peer_handler::SocketDescriptor) {
1536         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.socket_disconnected(descriptor)
1537 }
1538
1539 /// Disconnect a peer given its node id.
1540 ///
1541 /// If a peer is connected, this will call [`disconnect_socket`] on the descriptor for the
1542 /// peer. Thus, be very careful about reentrancy issues.
1543 ///
1544 /// [`disconnect_socket`]: SocketDescriptor::disconnect_socket
1545 #[no_mangle]
1546 pub extern "C" fn PeerManager_disconnect_by_node_id(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut node_id: crate::c_types::PublicKey) {
1547         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_by_node_id(node_id.into_rust())
1548 }
1549
1550 /// Disconnects all currently-connected peers. This is useful on platforms where there may be
1551 /// an indication that TCP sockets have stalled even if we weren't around to time them out
1552 /// using regular ping/pongs.
1553 #[no_mangle]
1554 pub extern "C" fn PeerManager_disconnect_all_peers(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1555         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_all_peers()
1556 }
1557
1558 /// Send pings to each peer and disconnect those which did not respond to the last round of
1559 /// pings.
1560 ///
1561 /// This may be called on any timescale you want, however, roughly once every ten seconds is
1562 /// preferred. The call rate determines both how often we send a ping to our peers and how much
1563 /// time they have to respond before we disconnect them.
1564 ///
1565 /// May call [`send_data`] on all [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1566 /// issues!
1567 ///
1568 /// [`send_data`]: SocketDescriptor::send_data
1569 #[no_mangle]
1570 pub extern "C" fn PeerManager_timer_tick_occurred(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1571         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1572 }
1573
1574 /// Generates a signed node_announcement from the given arguments, sending it to all connected
1575 /// peers. Note that peers will likely ignore this message unless we have at least one public
1576 /// channel which has at least six confirmations on-chain.
1577 ///
1578 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1579 /// node to humans. They carry no in-protocol meaning.
1580 ///
1581 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1582 /// accepts incoming connections. These will be included in the node_announcement, publicly
1583 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1584 /// addresses should likely contain only Tor Onion addresses.
1585 ///
1586 /// Panics if `addresses` is absurdly large (more than 100).
1587 ///
1588 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1589 #[no_mangle]
1590 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) {
1591         let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1592         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1593 }
1594
1595 use core::convert::Infallible as nativeInfallible;