1de59bc5a4edddd5f946a2ee52eec682bcf50d6e
[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_announcements: IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcements,
208                 get_next_node_announcements: IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcements,
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                 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
215                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
216                         free: None,
217                         get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
218                 },
219         }
220 }
221
222 #[must_use]
223 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 {
224         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _msg.get_native_ref());
225         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() };
226         local_ret
227 }
228 #[must_use]
229 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 {
230         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _msg.get_native_ref());
231         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() };
232         local_ret
233 }
234 #[must_use]
235 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 {
236         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _msg.get_native_ref());
237         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() };
238         local_ret
239 }
240 #[must_use]
241 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcements(this_arg: *const c_void, mut _starting_point: u64, mut _batch_amount: u8) -> crate::c_types::derived::CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ {
242         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _starting_point, _batch_amount);
243         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_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 }); };
244         local_ret.into()
245 }
246 #[must_use]
247 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcements(this_arg: *const c_void, mut _starting_point: crate::c_types::PublicKey, mut _batch_amount: u8) -> crate::c_types::derived::CVec_NodeAnnouncementZ {
248         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();
249         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcements(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, local__starting_point, _batch_amount);
250         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
251         local_ret.into()
252 }
253 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) {
254         <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &_their_node_id.into_rust(), _init.get_native_ref())
255 }
256 #[must_use]
257 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 {
258         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()) });
259         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() };
260         local_ret
261 }
262 #[must_use]
263 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 {
264         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()) });
265         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() };
266         local_ret
267 }
268 #[must_use]
269 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 {
270         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()) });
271         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() };
272         local_ret
273 }
274 #[must_use]
275 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 {
276         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()) });
277         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() };
278         local_ret
279 }
280
281 use core::convert::Infallible as nativeInfallible;
282 impl From<nativeInfallible> for crate::lightning::ln::wire::Type {
283         fn from(obj: nativeInfallible) -> Self {
284                 unreachable!();
285         }
286 }
287 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::wire::CustomMessageReader {
288         fn from(obj: nativeIgnoringMessageHandler) -> Self {
289                 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
290                 let mut ret = IgnoringMessageHandler_as_CustomMessageReader(&rust_obj);
291                 // 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
292                 rust_obj.inner = core::ptr::null_mut();
293                 ret.free = Some(IgnoringMessageHandler_free_void);
294                 ret
295         }
296 }
297 /// Constructs a new CustomMessageReader which calls the relevant methods on this_arg.
298 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageReader must be freed before this_arg is
299 #[no_mangle]
300 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageReader(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::wire::CustomMessageReader {
301         crate::lightning::ln::wire::CustomMessageReader {
302                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
303                 free: None,
304                 read: IgnoringMessageHandler_CustomMessageReader_read,
305         }
306 }
307
308 #[must_use]
309 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 {
310         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::wire::CustomMessageReader<>>::read(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _message_type, &mut _buffer.to_reader());
311         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() };
312         local_ret
313 }
314
315 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::peer_handler::CustomMessageHandler {
316         fn from(obj: nativeIgnoringMessageHandler) -> Self {
317                 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
318                 let mut ret = IgnoringMessageHandler_as_CustomMessageHandler(&rust_obj);
319                 // 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
320                 rust_obj.inner = core::ptr::null_mut();
321                 ret.free = Some(IgnoringMessageHandler_free_void);
322                 ret
323         }
324 }
325 /// Constructs a new CustomMessageHandler which calls the relevant methods on this_arg.
326 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageHandler must be freed before this_arg is
327 #[no_mangle]
328 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::peer_handler::CustomMessageHandler {
329         crate::lightning::ln::peer_handler::CustomMessageHandler {
330                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
331                 free: None,
332                 handle_custom_message: IgnoringMessageHandler_CustomMessageHandler_handle_custom_message,
333                 get_and_clear_pending_msg: IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg,
334                 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader {
335                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
336                         free: None,
337                         read: IgnoringMessageHandler_CustomMessageReader_read,
338                 },
339         }
340 }
341
342 #[must_use]
343 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 {
344         unreachable!();
345 }
346 #[must_use]
347 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ {
348         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::get_and_clear_pending_msg(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
349         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 }); };
350         local_ret.into()
351 }
352
353
354 use lightning::ln::peer_handler::ErroringMessageHandler as nativeErroringMessageHandlerImport;
355 pub(crate) type nativeErroringMessageHandler = nativeErroringMessageHandlerImport;
356
357 /// A dummy struct which implements `ChannelMessageHandler` without having any channels.
358 /// You can provide one of these as the route_handler in a MessageHandler.
359 #[must_use]
360 #[repr(C)]
361 pub struct ErroringMessageHandler {
362         /// A pointer to the opaque Rust object.
363
364         /// Nearly everywhere, inner must be non-null, however in places where
365         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
366         pub inner: *mut nativeErroringMessageHandler,
367         /// Indicates that this is the only struct which contains the same pointer.
368
369         /// Rust functions which take ownership of an object provided via an argument require
370         /// this to be true and invalidate the object pointed to by inner.
371         pub is_owned: bool,
372 }
373
374 impl Drop for ErroringMessageHandler {
375         fn drop(&mut self) {
376                 if self.is_owned && !<*mut nativeErroringMessageHandler>::is_null(self.inner) {
377                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
378                 }
379         }
380 }
381 /// Frees any resources used by the ErroringMessageHandler, if is_owned is set and inner is non-NULL.
382 #[no_mangle]
383 pub extern "C" fn ErroringMessageHandler_free(this_obj: ErroringMessageHandler) { }
384 #[allow(unused)]
385 /// Used only if an object of this type is returned as a trait impl by a method
386 pub(crate) extern "C" fn ErroringMessageHandler_free_void(this_ptr: *mut c_void) {
387         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeErroringMessageHandler); }
388 }
389 #[allow(unused)]
390 impl ErroringMessageHandler {
391         pub(crate) fn get_native_ref(&self) -> &'static nativeErroringMessageHandler {
392                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
393         }
394         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeErroringMessageHandler {
395                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
396         }
397         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
398         pub(crate) fn take_inner(mut self) -> *mut nativeErroringMessageHandler {
399                 assert!(self.is_owned);
400                 let ret = ObjOps::untweak_ptr(self.inner);
401                 self.inner = core::ptr::null_mut();
402                 ret
403         }
404 }
405 /// Constructs a new ErroringMessageHandler
406 #[must_use]
407 #[no_mangle]
408 pub extern "C" fn ErroringMessageHandler_new() -> crate::lightning::ln::peer_handler::ErroringMessageHandler {
409         let mut ret = lightning::ln::peer_handler::ErroringMessageHandler::new();
410         crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
411 }
412
413 impl From<nativeErroringMessageHandler> for crate::lightning::util::events::MessageSendEventsProvider {
414         fn from(obj: nativeErroringMessageHandler) -> Self {
415                 let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
416                 let mut ret = ErroringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
417                 // 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
418                 rust_obj.inner = core::ptr::null_mut();
419                 ret.free = Some(ErroringMessageHandler_free_void);
420                 ret
421         }
422 }
423 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
424 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
425 #[no_mangle]
426 pub extern "C" fn ErroringMessageHandler_as_MessageSendEventsProvider(this_arg: &ErroringMessageHandler) -> crate::lightning::util::events::MessageSendEventsProvider {
427         crate::lightning::util::events::MessageSendEventsProvider {
428                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
429                 free: None,
430                 get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
431         }
432 }
433
434 #[must_use]
435 extern "C" fn ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
436         let mut ret = <nativeErroringMessageHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
437         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
438         local_ret.into()
439 }
440
441 impl From<nativeErroringMessageHandler> for crate::lightning::ln::msgs::ChannelMessageHandler {
442         fn from(obj: nativeErroringMessageHandler) -> Self {
443                 let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
444                 let mut ret = ErroringMessageHandler_as_ChannelMessageHandler(&rust_obj);
445                 // 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
446                 rust_obj.inner = core::ptr::null_mut();
447                 ret.free = Some(ErroringMessageHandler_free_void);
448                 ret
449         }
450 }
451 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
452 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
453 #[no_mangle]
454 pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &ErroringMessageHandler) -> crate::lightning::ln::msgs::ChannelMessageHandler {
455         crate::lightning::ln::msgs::ChannelMessageHandler {
456                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
457                 free: None,
458                 handle_open_channel: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel,
459                 handle_accept_channel: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel,
460                 handle_funding_created: ErroringMessageHandler_ChannelMessageHandler_handle_funding_created,
461                 handle_funding_signed: ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed,
462                 handle_channel_ready: ErroringMessageHandler_ChannelMessageHandler_handle_channel_ready,
463                 handle_shutdown: ErroringMessageHandler_ChannelMessageHandler_handle_shutdown,
464                 handle_closing_signed: ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed,
465                 handle_update_add_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc,
466                 handle_update_fulfill_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc,
467                 handle_update_fail_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc,
468                 handle_update_fail_malformed_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_malformed_htlc,
469                 handle_commitment_signed: ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed,
470                 handle_revoke_and_ack: ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack,
471                 handle_update_fee: ErroringMessageHandler_ChannelMessageHandler_handle_update_fee,
472                 handle_announcement_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures,
473                 peer_disconnected: ErroringMessageHandler_ChannelMessageHandler_peer_disconnected,
474                 peer_connected: ErroringMessageHandler_ChannelMessageHandler_peer_connected,
475                 handle_channel_reestablish: ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish,
476                 handle_channel_update: ErroringMessageHandler_ChannelMessageHandler_handle_channel_update,
477                 handle_error: ErroringMessageHandler_ChannelMessageHandler_handle_error,
478                 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
479                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
480                         free: None,
481                         get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
482                 },
483         }
484 }
485
486 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) {
487         <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())
488 }
489 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) {
490         <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())
491 }
492 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) {
493         <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())
494 }
495 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) {
496         <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())
497 }
498 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) {
499         <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())
500 }
501 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) {
502         <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())
503 }
504 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) {
505         <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())
506 }
507 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) {
508         <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())
509 }
510 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) {
511         <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())
512 }
513 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) {
514         <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())
515 }
516 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) {
517         <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())
518 }
519 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) {
520         <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())
521 }
522 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) {
523         <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())
524 }
525 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) {
526         <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())
527 }
528 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) {
529         <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())
530 }
531 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) {
532         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), _no_connection_possible)
533 }
534 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) {
535         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), _msg.get_native_ref())
536 }
537 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) {
538         <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())
539 }
540 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) {
541         <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())
542 }
543 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) {
544         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), _msg.get_native_ref())
545 }
546
547
548 use lightning::ln::peer_handler::MessageHandler as nativeMessageHandlerImport;
549 pub(crate) type nativeMessageHandler = nativeMessageHandlerImport<crate::lightning::ln::msgs::ChannelMessageHandler, crate::lightning::ln::msgs::RoutingMessageHandler>;
550
551 /// Provides references to trait impls which handle different types of messages.
552 #[must_use]
553 #[repr(C)]
554 pub struct MessageHandler {
555         /// A pointer to the opaque Rust object.
556
557         /// Nearly everywhere, inner must be non-null, however in places where
558         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
559         pub inner: *mut nativeMessageHandler,
560         /// Indicates that this is the only struct which contains the same pointer.
561
562         /// Rust functions which take ownership of an object provided via an argument require
563         /// this to be true and invalidate the object pointed to by inner.
564         pub is_owned: bool,
565 }
566
567 impl Drop for MessageHandler {
568         fn drop(&mut self) {
569                 if self.is_owned && !<*mut nativeMessageHandler>::is_null(self.inner) {
570                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
571                 }
572         }
573 }
574 /// Frees any resources used by the MessageHandler, if is_owned is set and inner is non-NULL.
575 #[no_mangle]
576 pub extern "C" fn MessageHandler_free(this_obj: MessageHandler) { }
577 #[allow(unused)]
578 /// Used only if an object of this type is returned as a trait impl by a method
579 pub(crate) extern "C" fn MessageHandler_free_void(this_ptr: *mut c_void) {
580         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMessageHandler); }
581 }
582 #[allow(unused)]
583 impl MessageHandler {
584         pub(crate) fn get_native_ref(&self) -> &'static nativeMessageHandler {
585                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
586         }
587         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMessageHandler {
588                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
589         }
590         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
591         pub(crate) fn take_inner(mut self) -> *mut nativeMessageHandler {
592                 assert!(self.is_owned);
593                 let ret = ObjOps::untweak_ptr(self.inner);
594                 self.inner = core::ptr::null_mut();
595                 ret
596         }
597 }
598 /// A message handler which handles messages specific to channels. Usually this is just a
599 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
600 ///
601 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
602 #[no_mangle]
603 pub extern "C" fn MessageHandler_get_chan_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::ChannelMessageHandler {
604         let mut inner_val = &mut this_ptr.get_native_mut_ref().chan_handler;
605         inner_val
606 }
607 /// A message handler which handles messages specific to channels. Usually this is just a
608 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
609 ///
610 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
611 #[no_mangle]
612 pub extern "C" fn MessageHandler_set_chan_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::ChannelMessageHandler) {
613         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chan_handler = val;
614 }
615 /// A message handler which handles messages updating our knowledge of the network channel
616 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
617 ///
618 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
619 #[no_mangle]
620 pub extern "C" fn MessageHandler_get_route_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::RoutingMessageHandler {
621         let mut inner_val = &mut this_ptr.get_native_mut_ref().route_handler;
622         inner_val
623 }
624 /// A message handler which handles messages updating our knowledge of the network channel
625 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
626 ///
627 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
628 #[no_mangle]
629 pub extern "C" fn MessageHandler_set_route_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::RoutingMessageHandler) {
630         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_handler = val;
631 }
632 /// Constructs a new MessageHandler given each field
633 #[must_use]
634 #[no_mangle]
635 pub extern "C" fn MessageHandler_new(mut chan_handler_arg: crate::lightning::ln::msgs::ChannelMessageHandler, mut route_handler_arg: crate::lightning::ln::msgs::RoutingMessageHandler) -> MessageHandler {
636         MessageHandler { inner: ObjOps::heap_alloc(nativeMessageHandler {
637                 chan_handler: chan_handler_arg,
638                 route_handler: route_handler_arg,
639         }), is_owned: true }
640 }
641 /// Provides an object which can be used to send data to and which uniquely identifies a connection
642 /// to a remote host. You will need to be able to generate multiple of these which meet Eq and
643 /// implement Hash to meet the PeerManager API.
644 ///
645 /// For efficiency, Clone should be relatively cheap for this type.
646 ///
647 /// Two descriptors may compare equal (by [`cmp::Eq`] and [`hash::Hash`]) as long as the original
648 /// has been disconnected, the [`PeerManager`] has been informed of the disconnection (either by it
649 /// having triggered the disconnection or a call to [`PeerManager::socket_disconnected`]), and no
650 /// further calls to the [`PeerManager`] related to the original socket occur. This allows you to
651 /// use a file descriptor for your SocketDescriptor directly, however for simplicity you may wish
652 /// to simply use another value which is guaranteed to be globally unique instead.
653 #[repr(C)]
654 pub struct SocketDescriptor {
655         /// An opaque pointer which is passed to your function implementations as an argument.
656         /// This has no meaning in the LDK, and can be NULL or any other value.
657         pub this_arg: *mut c_void,
658         /// Attempts to send some data from the given slice to the peer.
659         ///
660         /// Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
661         /// Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
662         /// called and further write attempts may occur until that time.
663         ///
664         /// If the returned size is smaller than `data.len()`, a
665         /// [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
666         /// written. Additionally, until a `send_data` event completes fully, no further
667         /// [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
668         /// prevent denial-of-service issues, you should not read or buffer any data from the socket
669         /// until then.
670         ///
671         /// If a [`PeerManager::read_event`] call on this descriptor had previously returned true
672         /// (indicating that read events should be paused to prevent DoS in the send buffer),
673         /// `resume_read` may be set indicating that read events on this descriptor should resume. A
674         /// `resume_read` of false carries no meaning, and should not cause any action.
675         #[must_use]
676         pub send_data: extern "C" fn (this_arg: *mut c_void, data: crate::c_types::u8slice, resume_read: bool) -> usize,
677         /// Disconnect the socket pointed to by this SocketDescriptor.
678         ///
679         /// You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
680         /// call (doing so is a noop).
681         pub disconnect_socket: extern "C" fn (this_arg: *mut c_void),
682         /// Checks if two objects are equal given this object's this_arg pointer and another object.
683         pub eq: extern "C" fn (this_arg: *const c_void, other_arg: &SocketDescriptor) -> bool,
684         /// Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.
685         /// This is used, for example, for inclusion of this object in a hash map.
686         pub hash: extern "C" fn (this_arg: *const c_void) -> u64,
687         /// Called, if set, after this SocketDescriptor has been cloned into a duplicate object.
688         /// The new SocketDescriptor is provided, and should be mutated as needed to perform a
689         /// deep copy of the object pointed to by this_arg or avoid any double-freeing.
690         pub cloned: Option<extern "C" fn (new_SocketDescriptor: &mut SocketDescriptor)>,
691         /// Frees any resources associated with this object given its this_arg pointer.
692         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
693         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
694 }
695 unsafe impl Send for SocketDescriptor {}
696 unsafe impl Sync for SocketDescriptor {}
697 #[no_mangle]
698 pub(crate) extern "C" fn SocketDescriptor_clone_fields(orig: &SocketDescriptor) -> SocketDescriptor {
699         SocketDescriptor {
700                 this_arg: orig.this_arg,
701                 send_data: Clone::clone(&orig.send_data),
702                 disconnect_socket: Clone::clone(&orig.disconnect_socket),
703                 eq: Clone::clone(&orig.eq),
704                 hash: Clone::clone(&orig.hash),
705                 cloned: Clone::clone(&orig.cloned),
706                 free: Clone::clone(&orig.free),
707         }
708 }
709 impl core::cmp::Eq for SocketDescriptor {}
710 impl core::cmp::PartialEq for SocketDescriptor {
711         fn eq(&self, o: &Self) -> bool { (self.eq)(self.this_arg, o) }
712 }
713 impl core::hash::Hash for SocketDescriptor {
714         fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) { hasher.write_u64((self.hash)(self.this_arg)) }
715 }
716 #[no_mangle]
717 /// Creates a copy of a SocketDescriptor
718 pub extern "C" fn SocketDescriptor_clone(orig: &SocketDescriptor) -> SocketDescriptor {
719         let mut res = SocketDescriptor_clone_fields(orig);
720         if let Some(f) = orig.cloned { (f)(&mut res) };
721         res
722 }
723 impl Clone for SocketDescriptor {
724         fn clone(&self) -> Self {
725                 SocketDescriptor_clone(self)
726         }
727 }
728
729 use lightning::ln::peer_handler::SocketDescriptor as rustSocketDescriptor;
730 impl rustSocketDescriptor for SocketDescriptor {
731         fn send_data(&mut self, mut data: &[u8], mut resume_read: bool) -> usize {
732                 let mut local_data = crate::c_types::u8slice::from_slice(data);
733                 let mut ret = (self.send_data)(self.this_arg, local_data, resume_read);
734                 ret
735         }
736         fn disconnect_socket(&mut self) {
737                 (self.disconnect_socket)(self.this_arg)
738         }
739 }
740
741 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
742 // directly as a Deref trait in higher-level structs:
743 impl core::ops::Deref for SocketDescriptor {
744         type Target = Self;
745         fn deref(&self) -> &Self {
746                 self
747         }
748 }
749 /// Calls the free function if one is set
750 #[no_mangle]
751 pub extern "C" fn SocketDescriptor_free(this_ptr: SocketDescriptor) { }
752 impl Drop for SocketDescriptor {
753         fn drop(&mut self) {
754                 if let Some(f) = self.free {
755                         f(self.this_arg);
756                 }
757         }
758 }
759
760 use lightning::ln::peer_handler::PeerHandleError as nativePeerHandleErrorImport;
761 pub(crate) type nativePeerHandleError = nativePeerHandleErrorImport;
762
763 /// Error for PeerManager errors. If you get one of these, you must disconnect the socket and
764 /// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the
765 /// descriptor.
766 #[must_use]
767 #[repr(C)]
768 pub struct PeerHandleError {
769         /// A pointer to the opaque Rust object.
770
771         /// Nearly everywhere, inner must be non-null, however in places where
772         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
773         pub inner: *mut nativePeerHandleError,
774         /// Indicates that this is the only struct which contains the same pointer.
775
776         /// Rust functions which take ownership of an object provided via an argument require
777         /// this to be true and invalidate the object pointed to by inner.
778         pub is_owned: bool,
779 }
780
781 impl Drop for PeerHandleError {
782         fn drop(&mut self) {
783                 if self.is_owned && !<*mut nativePeerHandleError>::is_null(self.inner) {
784                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
785                 }
786         }
787 }
788 /// Frees any resources used by the PeerHandleError, if is_owned is set and inner is non-NULL.
789 #[no_mangle]
790 pub extern "C" fn PeerHandleError_free(this_obj: PeerHandleError) { }
791 #[allow(unused)]
792 /// Used only if an object of this type is returned as a trait impl by a method
793 pub(crate) extern "C" fn PeerHandleError_free_void(this_ptr: *mut c_void) {
794         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePeerHandleError); }
795 }
796 #[allow(unused)]
797 impl PeerHandleError {
798         pub(crate) fn get_native_ref(&self) -> &'static nativePeerHandleError {
799                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
800         }
801         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerHandleError {
802                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
803         }
804         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
805         pub(crate) fn take_inner(mut self) -> *mut nativePeerHandleError {
806                 assert!(self.is_owned);
807                 let ret = ObjOps::untweak_ptr(self.inner);
808                 self.inner = core::ptr::null_mut();
809                 ret
810         }
811 }
812 /// Used to indicate that we probably can't make any future connections to this peer (e.g.
813 /// because we required features that our peer was missing, or vice versa).
814 ///
815 /// While LDK's [`ChannelManager`] will not do it automatically, you likely wish to force-close
816 /// any channels with this peer or check for new versions of LDK.
817 ///
818 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
819 #[no_mangle]
820 pub extern "C" fn PeerHandleError_get_no_connection_possible(this_ptr: &PeerHandleError) -> bool {
821         let mut inner_val = &mut this_ptr.get_native_mut_ref().no_connection_possible;
822         *inner_val
823 }
824 /// Used to indicate that we probably can't make any future connections to this peer (e.g.
825 /// because we required features that our peer was missing, or vice versa).
826 ///
827 /// While LDK's [`ChannelManager`] will not do it automatically, you likely wish to force-close
828 /// any channels with this peer or check for new versions of LDK.
829 ///
830 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
831 #[no_mangle]
832 pub extern "C" fn PeerHandleError_set_no_connection_possible(this_ptr: &mut PeerHandleError, mut val: bool) {
833         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.no_connection_possible = val;
834 }
835 /// Constructs a new PeerHandleError given each field
836 #[must_use]
837 #[no_mangle]
838 pub extern "C" fn PeerHandleError_new(mut no_connection_possible_arg: bool) -> PeerHandleError {
839         PeerHandleError { inner: ObjOps::heap_alloc(nativePeerHandleError {
840                 no_connection_possible: no_connection_possible_arg,
841         }), is_owned: true }
842 }
843 impl Clone for PeerHandleError {
844         fn clone(&self) -> Self {
845                 Self {
846                         inner: if <*mut nativePeerHandleError>::is_null(self.inner) { core::ptr::null_mut() } else {
847                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
848                         is_owned: true,
849                 }
850         }
851 }
852 #[allow(unused)]
853 /// Used only if an object of this type is returned as a trait impl by a method
854 pub(crate) extern "C" fn PeerHandleError_clone_void(this_ptr: *const c_void) -> *mut c_void {
855         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePeerHandleError)).clone() })) as *mut c_void
856 }
857 #[no_mangle]
858 /// Creates a copy of the PeerHandleError
859 pub extern "C" fn PeerHandleError_clone(orig: &PeerHandleError) -> PeerHandleError {
860         orig.clone()
861 }
862
863 use lightning::ln::peer_handler::PeerManager as nativePeerManagerImport;
864 pub(crate) type nativePeerManager = nativePeerManagerImport<crate::lightning::ln::peer_handler::SocketDescriptor, crate::lightning::ln::msgs::ChannelMessageHandler, crate::lightning::ln::msgs::RoutingMessageHandler, crate::lightning::util::logger::Logger, crate::lightning::ln::peer_handler::CustomMessageHandler>;
865
866 /// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
867 /// socket events into messages which it passes on to its [`MessageHandler`].
868 ///
869 /// Locks are taken internally, so you must never assume that reentrancy from a
870 /// [`SocketDescriptor`] call back into [`PeerManager`] methods will not deadlock.
871 ///
872 /// Calls to [`read_event`] will decode relevant messages and pass them to the
873 /// [`ChannelMessageHandler`], likely doing message processing in-line. Thus, the primary form of
874 /// parallelism in Rust-Lightning is in calls to [`read_event`]. Note, however, that calls to any
875 /// [`PeerManager`] functions related to the same connection must occur only in serial, making new
876 /// calls only after previous ones have returned.
877 ///
878 /// Rather than using a plain PeerManager, it is preferable to use either a SimpleArcPeerManager
879 /// a SimpleRefPeerManager, for conciseness. See their documentation for more details, but
880 /// essentially you should default to using a SimpleRefPeerManager, and use a
881 /// SimpleArcPeerManager when you require a PeerManager with a static lifetime, such as when
882 /// you're using lightning-net-tokio.
883 ///
884 /// [`read_event`]: PeerManager::read_event
885 #[must_use]
886 #[repr(C)]
887 pub struct PeerManager {
888         /// A pointer to the opaque Rust object.
889
890         /// Nearly everywhere, inner must be non-null, however in places where
891         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
892         pub inner: *mut nativePeerManager,
893         /// Indicates that this is the only struct which contains the same pointer.
894
895         /// Rust functions which take ownership of an object provided via an argument require
896         /// this to be true and invalidate the object pointed to by inner.
897         pub is_owned: bool,
898 }
899
900 impl Drop for PeerManager {
901         fn drop(&mut self) {
902                 if self.is_owned && !<*mut nativePeerManager>::is_null(self.inner) {
903                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
904                 }
905         }
906 }
907 /// Frees any resources used by the PeerManager, if is_owned is set and inner is non-NULL.
908 #[no_mangle]
909 pub extern "C" fn PeerManager_free(this_obj: PeerManager) { }
910 #[allow(unused)]
911 /// Used only if an object of this type is returned as a trait impl by a method
912 pub(crate) extern "C" fn PeerManager_free_void(this_ptr: *mut c_void) {
913         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePeerManager); }
914 }
915 #[allow(unused)]
916 impl PeerManager {
917         pub(crate) fn get_native_ref(&self) -> &'static nativePeerManager {
918                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
919         }
920         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerManager {
921                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
922         }
923         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
924         pub(crate) fn take_inner(mut self) -> *mut nativePeerManager {
925                 assert!(self.is_owned);
926                 let ret = ObjOps::untweak_ptr(self.inner);
927                 self.inner = core::ptr::null_mut();
928                 ret
929         }
930 }
931 /// Constructs a new PeerManager with the given message handlers and node_id secret key
932 /// ephemeral_random_data is used to derive per-connection ephemeral keys and must be
933 /// cryptographically secure random bytes.
934 #[must_use]
935 #[no_mangle]
936 pub extern "C" fn PeerManager_new(mut message_handler: crate::lightning::ln::peer_handler::MessageHandler, mut our_node_secret: crate::c_types::SecretKey, 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 {
937         let mut ret = lightning::ln::peer_handler::PeerManager::new(*unsafe { Box::from_raw(message_handler.take_inner()) }, our_node_secret.into_rust(), unsafe { &*ephemeral_random_data}, logger, custom_message_handler);
938         crate::lightning::ln::peer_handler::PeerManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
939 }
940
941 /// Get the list of node ids for peers which have completed the initial handshake.
942 ///
943 /// For outbound connections, this will be the same as the their_node_id parameter passed in to
944 /// new_outbound_connection, however entries will only appear once the initial handshake has
945 /// completed and we are sure the remote peer has the private key for the given node_id.
946 #[must_use]
947 #[no_mangle]
948 pub extern "C" fn PeerManager_get_peer_node_ids(this_arg: &crate::lightning::ln::peer_handler::PeerManager) -> crate::c_types::derived::CVec_PublicKeyZ {
949         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_peer_node_ids();
950         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::PublicKey::from_rust(&item) }); };
951         local_ret.into()
952 }
953
954 /// Indicates a new outbound connection has been established to a node with the given node_id
955 /// and an optional remote network address.
956 ///
957 /// The remote network address adds the option to report a remote IP address back to a connecting
958 /// peer using the init message.
959 /// The user should pass the remote network address of the host they are connected to.
960 ///
961 /// Note that if an Err is returned here you MUST NOT call socket_disconnected for the new
962 /// descriptor but must disconnect the connection immediately.
963 ///
964 /// Returns a small number of bytes to send to the remote node (currently always 50).
965 ///
966 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
967 /// [`socket_disconnected()`].
968 ///
969 /// [`socket_disconnected()`]: PeerManager::socket_disconnected
970 #[must_use]
971 #[no_mangle]
972 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 {
973         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() }) } };
974         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_outbound_connection(their_node_id.into_rust(), descriptor, local_remote_network_address);
975         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() };
976         local_ret
977 }
978
979 /// Indicates a new inbound connection has been established to a node with an optional remote
980 /// network address.
981 ///
982 /// The remote network address adds the option to report a remote IP address back to a connecting
983 /// peer using the init message.
984 /// The user should pass the remote network address of the host they are connected to.
985 ///
986 /// May refuse the connection by returning an Err, but will never write bytes to the remote end
987 /// (outbound connector always speaks first). Note that if an Err is returned here you MUST NOT
988 /// call socket_disconnected for the new descriptor but must disconnect the connection
989 /// immediately.
990 ///
991 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
992 /// [`socket_disconnected()`].
993 ///
994 /// [`socket_disconnected()`]: PeerManager::socket_disconnected
995 #[must_use]
996 #[no_mangle]
997 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 {
998         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() }) } };
999         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_inbound_connection(descriptor, local_remote_network_address);
1000         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() };
1001         local_ret
1002 }
1003
1004 /// Indicates that there is room to write data to the given socket descriptor.
1005 ///
1006 /// May return an Err to indicate that the connection should be closed.
1007 ///
1008 /// May call [`send_data`] on the descriptor passed in (or an equal descriptor) before
1009 /// returning. Thus, be very careful with reentrancy issues! The invariants around calling
1010 /// [`write_buffer_space_avail`] in case a write did not fully complete must still hold - be
1011 /// ready to call `[write_buffer_space_avail`] again if a write call generated here isn't
1012 /// sufficient!
1013 ///
1014 /// [`send_data`]: SocketDescriptor::send_data
1015 /// [`write_buffer_space_avail`]: PeerManager::write_buffer_space_avail
1016 #[must_use]
1017 #[no_mangle]
1018 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 {
1019         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.write_buffer_space_avail(descriptor);
1020         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() };
1021         local_ret
1022 }
1023
1024 /// Indicates that data was read from the given socket descriptor.
1025 ///
1026 /// May return an Err to indicate that the connection should be closed.
1027 ///
1028 /// Will *not* call back into [`send_data`] on any descriptors to avoid reentrancy complexity.
1029 /// Thus, however, you should call [`process_events`] after any `read_event` to generate
1030 /// [`send_data`] calls to handle responses.
1031 ///
1032 /// If `Ok(true)` is returned, further read_events should not be triggered until a
1033 /// [`send_data`] call on this descriptor has `resume_read` set (preventing DoS issues in the
1034 /// send buffer).
1035 ///
1036 /// [`send_data`]: SocketDescriptor::send_data
1037 /// [`process_events`]: PeerManager::process_events
1038 #[must_use]
1039 #[no_mangle]
1040 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 {
1041         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_event(peer_descriptor, data.to_slice());
1042         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() };
1043         local_ret
1044 }
1045
1046 /// Checks for any events generated by our handlers and processes them. Includes sending most
1047 /// response messages as well as messages generated by calls to handler functions directly (eg
1048 /// functions like [`ChannelManager::process_pending_htlc_forwards`] or [`send_payment`]).
1049 ///
1050 /// May call [`send_data`] on [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1051 /// issues!
1052 ///
1053 /// You don't have to call this function explicitly if you are using [`lightning-net-tokio`]
1054 /// or one of the other clients provided in our language bindings.
1055 ///
1056 /// Note that if there are any other calls to this function waiting on lock(s) this may return
1057 /// without doing any work. All available events that need handling will be handled before the
1058 /// other calls return.
1059 ///
1060 /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1061 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
1062 /// [`send_data`]: SocketDescriptor::send_data
1063 #[no_mangle]
1064 pub extern "C" fn PeerManager_process_events(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1065         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_events()
1066 }
1067
1068 /// Indicates that the given socket descriptor's connection is now closed.
1069 #[no_mangle]
1070 pub extern "C" fn PeerManager_socket_disconnected(this_arg: &crate::lightning::ln::peer_handler::PeerManager, descriptor: &crate::lightning::ln::peer_handler::SocketDescriptor) {
1071         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.socket_disconnected(descriptor)
1072 }
1073
1074 /// Disconnect a peer given its node id.
1075 ///
1076 /// Set `no_connection_possible` to true to prevent any further connection with this peer,
1077 /// force-closing any channels we have with it.
1078 ///
1079 /// If a peer is connected, this will call [`disconnect_socket`] on the descriptor for the
1080 /// peer. Thus, be very careful about reentrancy issues.
1081 ///
1082 /// [`disconnect_socket`]: SocketDescriptor::disconnect_socket
1083 #[no_mangle]
1084 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) {
1085         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_by_node_id(node_id.into_rust(), no_connection_possible)
1086 }
1087
1088 /// Disconnects all currently-connected peers. This is useful on platforms where there may be
1089 /// an indication that TCP sockets have stalled even if we weren't around to time them out
1090 /// using regular ping/pongs.
1091 #[no_mangle]
1092 pub extern "C" fn PeerManager_disconnect_all_peers(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1093         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_all_peers()
1094 }
1095
1096 /// Send pings to each peer and disconnect those which did not respond to the last round of
1097 /// pings.
1098 ///
1099 /// This may be called on any timescale you want, however, roughly once every ten seconds is
1100 /// preferred. The call rate determines both how often we send a ping to our peers and how much
1101 /// time they have to respond before we disconnect them.
1102 ///
1103 /// May call [`send_data`] on all [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1104 /// issues!
1105 ///
1106 /// [`send_data`]: SocketDescriptor::send_data
1107 #[no_mangle]
1108 pub extern "C" fn PeerManager_timer_tick_occurred(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1109         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1110 }
1111