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