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