eeb69979afdd0d4dd243cd8a0983bf9e26d359e1
[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 NetGraphmsgHandler) with messages
15 //! they should handle, and encoding/sending response messages.
16
17 use std::str::FromStr;
18 use std::ffi::c_void;
19 use core::convert::Infallible;
20 use bitcoin::hashes::Hash;
21 use crate::c_types::*;
22
23 /// Handler for BOLT1-compliant messages.
24 #[repr(C)]
25 pub struct CustomMessageHandler {
26         /// An opaque pointer which is passed to your function implementations as an argument.
27         /// This has no meaning in the LDK, and can be NULL or any other value.
28         pub this_arg: *mut c_void,
29         /// Called with the message type that was received and the buffer to be read.
30         /// Can return a `MessageHandlingError` if the message could not be handled.
31         #[must_use]
32         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,
33         /// Gets the list of pending messages which were generated by the custom message
34         /// handler, clearing the list in the process. The first tuple element must
35         /// correspond to the intended recipients node ids. If no connection to one of the
36         /// specified node does not exist, the message is simply not sent to it.
37         #[must_use]
38         pub get_and_clear_pending_msg: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ,
39         /// Implementation of CustomMessageReader for this object.
40         pub CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader,
41         /// Frees any resources associated with this object given its this_arg pointer.
42         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
43         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
44 }
45 unsafe impl Send for CustomMessageHandler {}
46 unsafe impl Sync for CustomMessageHandler {}
47 #[no_mangle]
48 pub(crate) extern "C" fn CustomMessageHandler_clone_fields(orig: &CustomMessageHandler) -> CustomMessageHandler {
49         CustomMessageHandler {
50                 this_arg: orig.this_arg,
51                 handle_custom_message: Clone::clone(&orig.handle_custom_message),
52                 get_and_clear_pending_msg: Clone::clone(&orig.get_and_clear_pending_msg),
53                 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader_clone_fields(&orig.CustomMessageReader),
54                 free: Clone::clone(&orig.free),
55         }
56 }
57 impl lightning::ln::wire::CustomMessageReader for CustomMessageHandler {
58         type CustomMessage = crate::lightning::ln::wire::Type;
59         fn read<R:std::io::Read>(&self, mut message_type: u16, mut buffer: &mut R) -> Result<Option<crate::lightning::ln::wire::Type>, lightning::ln::msgs::DecodeError> {
60                 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)));
61                 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()) } })};
62                 local_ret
63         }
64 }
65
66 use lightning::ln::peer_handler::CustomMessageHandler as rustCustomMessageHandler;
67 impl rustCustomMessageHandler for CustomMessageHandler {
68         fn handle_custom_message(&self, mut msg: crate::lightning::ln::wire::Type, mut sender_node_id: &bitcoin::secp256k1::key::PublicKey) -> Result<(), lightning::ln::msgs::LightningError> {
69                 let mut ret = (self.handle_custom_message)(self.this_arg, Into::into(msg), crate::c_types::PublicKey::from_rust(&sender_node_id));
70                 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()) } })};
71                 local_ret
72         }
73         fn get_and_clear_pending_msg(&self) -> Vec<(bitcoin::secp256k1::key::PublicKey, crate::lightning::ln::wire::Type)> {
74                 let mut ret = (self.get_and_clear_pending_msg)(self.this_arg);
75                 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 }); };
76                 local_ret
77         }
78 }
79
80 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
81 // directly as a Deref trait in higher-level structs:
82 impl std::ops::Deref for CustomMessageHandler {
83         type Target = Self;
84         fn deref(&self) -> &Self {
85                 self
86         }
87 }
88 /// Calls the free function if one is set
89 #[no_mangle]
90 pub extern "C" fn CustomMessageHandler_free(this_ptr: CustomMessageHandler) { }
91 impl Drop for CustomMessageHandler {
92         fn drop(&mut self) {
93                 if let Some(f) = self.free {
94                         f(self.this_arg);
95                 }
96         }
97 }
98
99 use lightning::ln::peer_handler::IgnoringMessageHandler as nativeIgnoringMessageHandlerImport;
100 type nativeIgnoringMessageHandler = nativeIgnoringMessageHandlerImport;
101
102 /// A dummy struct which implements `RoutingMessageHandler` without storing any routing information
103 /// or doing any processing. You can provide one of these as the route_handler in a MessageHandler.
104 #[must_use]
105 #[repr(C)]
106 pub struct IgnoringMessageHandler {
107         /// A pointer to the opaque Rust object.
108
109         /// Nearly everywhere, inner must be non-null, however in places where
110         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
111         pub inner: *mut nativeIgnoringMessageHandler,
112         /// Indicates that this is the only struct which contains the same pointer.
113
114         /// Rust functions which take ownership of an object provided via an argument require
115         /// this to be true and invalidate the object pointed to by inner.
116         pub is_owned: bool,
117 }
118
119 impl Drop for IgnoringMessageHandler {
120         fn drop(&mut self) {
121                 if self.is_owned && !<*mut nativeIgnoringMessageHandler>::is_null(self.inner) {
122                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
123                 }
124         }
125 }
126 /// Frees any resources used by the IgnoringMessageHandler, if is_owned is set and inner is non-NULL.
127 #[no_mangle]
128 pub extern "C" fn IgnoringMessageHandler_free(this_obj: IgnoringMessageHandler) { }
129 #[allow(unused)]
130 /// Used only if an object of this type is returned as a trait impl by a method
131 extern "C" fn IgnoringMessageHandler_free_void(this_ptr: *mut c_void) {
132         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeIgnoringMessageHandler); }
133 }
134 #[allow(unused)]
135 impl IgnoringMessageHandler {
136         pub(crate) fn get_native_ref(&self) -> &'static nativeIgnoringMessageHandler {
137                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
138         }
139         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeIgnoringMessageHandler {
140                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
141         }
142         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
143         pub(crate) fn take_inner(mut self) -> *mut nativeIgnoringMessageHandler {
144                 assert!(self.is_owned);
145                 let ret = ObjOps::untweak_ptr(self.inner);
146                 self.inner = std::ptr::null_mut();
147                 ret
148         }
149 }
150 /// Constructs a new IgnoringMessageHandler given each field
151 #[must_use]
152 #[no_mangle]
153 pub extern "C" fn IgnoringMessageHandler_new() -> IgnoringMessageHandler {
154         IgnoringMessageHandler { inner: ObjOps::heap_alloc(nativeIgnoringMessageHandler {
155         }), is_owned: true }
156 }
157 impl From<nativeIgnoringMessageHandler> for crate::lightning::util::events::MessageSendEventsProvider {
158         fn from(obj: nativeIgnoringMessageHandler) -> Self {
159                 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
160                 let mut ret = IgnoringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
161                 // 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
162                 rust_obj.inner = std::ptr::null_mut();
163                 ret.free = Some(IgnoringMessageHandler_free_void);
164                 ret
165         }
166 }
167 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
168 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
169 #[no_mangle]
170 pub extern "C" fn IgnoringMessageHandler_as_MessageSendEventsProvider(this_arg: &IgnoringMessageHandler) -> crate::lightning::util::events::MessageSendEventsProvider {
171         crate::lightning::util::events::MessageSendEventsProvider {
172                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
173                 free: None,
174                 get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
175         }
176 }
177
178 #[must_use]
179 extern "C" fn IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
180         let mut ret = <nativeIgnoringMessageHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
181         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
182         local_ret.into()
183 }
184
185 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
186         fn from(obj: nativeIgnoringMessageHandler) -> Self {
187                 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
188                 let mut ret = IgnoringMessageHandler_as_RoutingMessageHandler(&rust_obj);
189                 // 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
190                 rust_obj.inner = std::ptr::null_mut();
191                 ret.free = Some(IgnoringMessageHandler_free_void);
192                 ret
193         }
194 }
195 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
196 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
197 #[no_mangle]
198 pub extern "C" fn IgnoringMessageHandler_as_RoutingMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
199         crate::lightning::ln::msgs::RoutingMessageHandler {
200                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
201                 free: None,
202                 handle_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement,
203                 handle_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement,
204                 handle_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update,
205                 get_next_channel_announcements: IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcements,
206                 get_next_node_announcements: IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcements,
207                 sync_routing_table: IgnoringMessageHandler_RoutingMessageHandler_sync_routing_table,
208                 handle_reply_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_channel_range,
209                 handle_reply_short_channel_ids_end: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
210                 handle_query_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_query_channel_range,
211                 handle_query_short_channel_ids: IgnoringMessageHandler_RoutingMessageHandler_handle_query_short_channel_ids,
212                 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
213                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
214                         free: None,
215                         get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
216                 },
217         }
218 }
219
220 #[must_use]
221 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 {
222         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _msg.get_native_ref());
223         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() };
224         local_ret
225 }
226 #[must_use]
227 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 {
228         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _msg.get_native_ref());
229         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() };
230         local_ret
231 }
232 #[must_use]
233 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 {
234         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _msg.get_native_ref());
235         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() };
236         local_ret
237 }
238 #[must_use]
239 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 {
240         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _starting_point, _batch_amount);
241         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() { std::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() { std::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 }); };
242         local_ret.into()
243 }
244 #[must_use]
245 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 {
246         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();
247         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);
248         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 } }); };
249         local_ret.into()
250 }
251 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_sync_routing_table(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, _init: &crate::lightning::ln::msgs::Init) {
252         <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::sync_routing_table(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &_their_node_id.into_rust(), _init.get_native_ref())
253 }
254 #[must_use]
255 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 {
256         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()) });
257         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() };
258         local_ret
259 }
260 #[must_use]
261 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 {
262         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()) });
263         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() };
264         local_ret
265 }
266 #[must_use]
267 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 {
268         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()) });
269         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() };
270         local_ret
271 }
272 #[must_use]
273 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 {
274         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()) });
275         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() };
276         local_ret
277 }
278
279 use core::convert::Infallible as nativeInfallible;
280 impl From<nativeInfallible> for crate::lightning::ln::wire::Type {
281         fn from(obj: nativeInfallible) -> Self {
282                 unreachable!();
283         }
284 }
285 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::wire::CustomMessageReader {
286         fn from(obj: nativeIgnoringMessageHandler) -> Self {
287                 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
288                 let mut ret = IgnoringMessageHandler_as_CustomMessageReader(&rust_obj);
289                 // 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
290                 rust_obj.inner = std::ptr::null_mut();
291                 ret.free = Some(IgnoringMessageHandler_free_void);
292                 ret
293         }
294 }
295 /// Constructs a new CustomMessageReader which calls the relevant methods on this_arg.
296 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageReader must be freed before this_arg is
297 #[no_mangle]
298 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageReader(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::wire::CustomMessageReader {
299         crate::lightning::ln::wire::CustomMessageReader {
300                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
301                 free: None,
302                 read: IgnoringMessageHandler_CustomMessageReader_read,
303         }
304 }
305
306 #[must_use]
307 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 {
308         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::wire::CustomMessageReader<>>::read(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _message_type, &mut _buffer.to_reader());
309         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() };
310         local_ret
311 }
312
313 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::peer_handler::CustomMessageHandler {
314         fn from(obj: nativeIgnoringMessageHandler) -> Self {
315                 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
316                 let mut ret = IgnoringMessageHandler_as_CustomMessageHandler(&rust_obj);
317                 // 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
318                 rust_obj.inner = std::ptr::null_mut();
319                 ret.free = Some(IgnoringMessageHandler_free_void);
320                 ret
321         }
322 }
323 /// Constructs a new CustomMessageHandler which calls the relevant methods on this_arg.
324 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageHandler must be freed before this_arg is
325 #[no_mangle]
326 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::peer_handler::CustomMessageHandler {
327         crate::lightning::ln::peer_handler::CustomMessageHandler {
328                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
329                 free: None,
330                 handle_custom_message: IgnoringMessageHandler_CustomMessageHandler_handle_custom_message,
331                 get_and_clear_pending_msg: IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg,
332                 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader {
333                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
334                         free: None,
335                         read: IgnoringMessageHandler_CustomMessageReader_read,
336                 },
337         }
338 }
339
340 #[must_use]
341 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 {
342         unreachable!();
343 }
344 #[must_use]
345 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ {
346         let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::get_and_clear_pending_msg(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
347         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 }); };
348         local_ret.into()
349 }
350
351
352 use lightning::ln::peer_handler::ErroringMessageHandler as nativeErroringMessageHandlerImport;
353 type nativeErroringMessageHandler = nativeErroringMessageHandlerImport;
354
355 /// A dummy struct which implements `ChannelMessageHandler` without having any channels.
356 /// You can provide one of these as the route_handler in a MessageHandler.
357 #[must_use]
358 #[repr(C)]
359 pub struct ErroringMessageHandler {
360         /// A pointer to the opaque Rust object.
361
362         /// Nearly everywhere, inner must be non-null, however in places where
363         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
364         pub inner: *mut nativeErroringMessageHandler,
365         /// Indicates that this is the only struct which contains the same pointer.
366
367         /// Rust functions which take ownership of an object provided via an argument require
368         /// this to be true and invalidate the object pointed to by inner.
369         pub is_owned: bool,
370 }
371
372 impl Drop for ErroringMessageHandler {
373         fn drop(&mut self) {
374                 if self.is_owned && !<*mut nativeErroringMessageHandler>::is_null(self.inner) {
375                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
376                 }
377         }
378 }
379 /// Frees any resources used by the ErroringMessageHandler, if is_owned is set and inner is non-NULL.
380 #[no_mangle]
381 pub extern "C" fn ErroringMessageHandler_free(this_obj: ErroringMessageHandler) { }
382 #[allow(unused)]
383 /// Used only if an object of this type is returned as a trait impl by a method
384 extern "C" fn ErroringMessageHandler_free_void(this_ptr: *mut c_void) {
385         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeErroringMessageHandler); }
386 }
387 #[allow(unused)]
388 impl ErroringMessageHandler {
389         pub(crate) fn get_native_ref(&self) -> &'static nativeErroringMessageHandler {
390                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
391         }
392         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeErroringMessageHandler {
393                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
394         }
395         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
396         pub(crate) fn take_inner(mut self) -> *mut nativeErroringMessageHandler {
397                 assert!(self.is_owned);
398                 let ret = ObjOps::untweak_ptr(self.inner);
399                 self.inner = std::ptr::null_mut();
400                 ret
401         }
402 }
403 /// Constructs a new ErroringMessageHandler
404 #[must_use]
405 #[no_mangle]
406 pub extern "C" fn ErroringMessageHandler_new() -> ErroringMessageHandler {
407         let mut ret = lightning::ln::peer_handler::ErroringMessageHandler::new();
408         ErroringMessageHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
409 }
410
411 impl From<nativeErroringMessageHandler> for crate::lightning::util::events::MessageSendEventsProvider {
412         fn from(obj: nativeErroringMessageHandler) -> Self {
413                 let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
414                 let mut ret = ErroringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
415                 // 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
416                 rust_obj.inner = std::ptr::null_mut();
417                 ret.free = Some(ErroringMessageHandler_free_void);
418                 ret
419         }
420 }
421 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
422 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
423 #[no_mangle]
424 pub extern "C" fn ErroringMessageHandler_as_MessageSendEventsProvider(this_arg: &ErroringMessageHandler) -> crate::lightning::util::events::MessageSendEventsProvider {
425         crate::lightning::util::events::MessageSendEventsProvider {
426                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
427                 free: None,
428                 get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
429         }
430 }
431
432 #[must_use]
433 extern "C" fn ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
434         let mut ret = <nativeErroringMessageHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
435         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
436         local_ret.into()
437 }
438
439 impl From<nativeErroringMessageHandler> for crate::lightning::ln::msgs::ChannelMessageHandler {
440         fn from(obj: nativeErroringMessageHandler) -> Self {
441                 let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
442                 let mut ret = ErroringMessageHandler_as_ChannelMessageHandler(&rust_obj);
443                 // 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
444                 rust_obj.inner = std::ptr::null_mut();
445                 ret.free = Some(ErroringMessageHandler_free_void);
446                 ret
447         }
448 }
449 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
450 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
451 #[no_mangle]
452 pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &ErroringMessageHandler) -> crate::lightning::ln::msgs::ChannelMessageHandler {
453         crate::lightning::ln::msgs::ChannelMessageHandler {
454                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
455                 free: None,
456                 handle_open_channel: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel,
457                 handle_accept_channel: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel,
458                 handle_funding_created: ErroringMessageHandler_ChannelMessageHandler_handle_funding_created,
459                 handle_funding_signed: ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed,
460                 handle_funding_locked: ErroringMessageHandler_ChannelMessageHandler_handle_funding_locked,
461                 handle_shutdown: ErroringMessageHandler_ChannelMessageHandler_handle_shutdown,
462                 handle_closing_signed: ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed,
463                 handle_update_add_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc,
464                 handle_update_fulfill_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc,
465                 handle_update_fail_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc,
466                 handle_update_fail_malformed_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_malformed_htlc,
467                 handle_commitment_signed: ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed,
468                 handle_revoke_and_ack: ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack,
469                 handle_update_fee: ErroringMessageHandler_ChannelMessageHandler_handle_update_fee,
470                 handle_announcement_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures,
471                 peer_disconnected: ErroringMessageHandler_ChannelMessageHandler_peer_disconnected,
472                 peer_connected: ErroringMessageHandler_ChannelMessageHandler_peer_connected,
473                 handle_channel_reestablish: ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish,
474                 handle_channel_update: ErroringMessageHandler_ChannelMessageHandler_handle_channel_update,
475                 handle_error: ErroringMessageHandler_ChannelMessageHandler_handle_error,
476                 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
477                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
478                         free: None,
479                         get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
480                 },
481         }
482 }
483
484 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) {
485         <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())
486 }
487 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) {
488         <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())
489 }
490 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) {
491         <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())
492 }
493 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) {
494         <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())
495 }
496 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_funding_locked(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingLocked) {
497         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_locked(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
498 }
499 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) {
500         <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())
501 }
502 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) {
503         <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())
504 }
505 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) {
506         <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())
507 }
508 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) {
509         <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())
510 }
511 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) {
512         <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())
513 }
514 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) {
515         <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())
516 }
517 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) {
518         <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())
519 }
520 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) {
521         <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())
522 }
523 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) {
524         <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())
525 }
526 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) {
527         <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())
528 }
529 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) {
530         <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())
531 }
532 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) {
533         <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())
534 }
535 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) {
536         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), _no_connection_possible)
537 }
538 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) {
539         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), _msg.get_native_ref())
540 }
541 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) {
542         <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), _msg.get_native_ref())
543 }
544
545
546 use lightning::ln::peer_handler::MessageHandler as nativeMessageHandlerImport;
547 type nativeMessageHandler = nativeMessageHandlerImport<crate::lightning::ln::msgs::ChannelMessageHandler, crate::lightning::ln::msgs::RoutingMessageHandler>;
548
549 /// Provides references to trait impls which handle different types of messages.
550 #[must_use]
551 #[repr(C)]
552 pub struct MessageHandler {
553         /// A pointer to the opaque Rust object.
554
555         /// Nearly everywhere, inner must be non-null, however in places where
556         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
557         pub inner: *mut nativeMessageHandler,
558         /// Indicates that this is the only struct which contains the same pointer.
559
560         /// Rust functions which take ownership of an object provided via an argument require
561         /// this to be true and invalidate the object pointed to by inner.
562         pub is_owned: bool,
563 }
564
565 impl Drop for MessageHandler {
566         fn drop(&mut self) {
567                 if self.is_owned && !<*mut nativeMessageHandler>::is_null(self.inner) {
568                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
569                 }
570         }
571 }
572 /// Frees any resources used by the MessageHandler, if is_owned is set and inner is non-NULL.
573 #[no_mangle]
574 pub extern "C" fn MessageHandler_free(this_obj: MessageHandler) { }
575 #[allow(unused)]
576 /// Used only if an object of this type is returned as a trait impl by a method
577 extern "C" fn MessageHandler_free_void(this_ptr: *mut c_void) {
578         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMessageHandler); }
579 }
580 #[allow(unused)]
581 impl MessageHandler {
582         pub(crate) fn get_native_ref(&self) -> &'static nativeMessageHandler {
583                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
584         }
585         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMessageHandler {
586                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
587         }
588         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
589         pub(crate) fn take_inner(mut self) -> *mut nativeMessageHandler {
590                 assert!(self.is_owned);
591                 let ret = ObjOps::untweak_ptr(self.inner);
592                 self.inner = std::ptr::null_mut();
593                 ret
594         }
595 }
596 /// A message handler which handles messages specific to channels. Usually this is just a
597 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
598 ///
599 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
600 #[no_mangle]
601 pub extern "C" fn MessageHandler_get_chan_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::ChannelMessageHandler {
602         let mut inner_val = &mut this_ptr.get_native_mut_ref().chan_handler;
603         inner_val
604 }
605 /// A message handler which handles messages specific to channels. Usually this is just a
606 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
607 ///
608 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
609 #[no_mangle]
610 pub extern "C" fn MessageHandler_set_chan_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::ChannelMessageHandler) {
611         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chan_handler = val;
612 }
613 /// A message handler which handles messages updating our knowledge of the network channel
614 /// graph. Usually this is just a [`NetGraphMsgHandler`] object or an
615 /// [`IgnoringMessageHandler`].
616 ///
617 /// [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler
618 #[no_mangle]
619 pub extern "C" fn MessageHandler_get_route_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::RoutingMessageHandler {
620         let mut inner_val = &mut this_ptr.get_native_mut_ref().route_handler;
621         inner_val
622 }
623 /// A message handler which handles messages updating our knowledge of the network channel
624 /// graph. Usually this is just a [`NetGraphMsgHandler`] object or an
625 /// [`IgnoringMessageHandler`].
626 ///
627 /// [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler
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 std::cmp::Eq for SocketDescriptor {}
710 impl std::cmp::PartialEq for SocketDescriptor {
711         fn eq(&self, o: &Self) -> bool { (self.eq)(self.this_arg, o) }
712 }
713 impl std::hash::Hash for SocketDescriptor {
714         fn hash<H: std::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 std::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 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 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 = std::ptr::null_mut();
809                 ret
810         }
811 }
812 /// Used to indicate that we probably can't make any future connections to this peer, implying
813 /// we should go ahead and force-close any channels we have with it.
814 #[no_mangle]
815 pub extern "C" fn PeerHandleError_get_no_connection_possible(this_ptr: &PeerHandleError) -> bool {
816         let mut inner_val = &mut this_ptr.get_native_mut_ref().no_connection_possible;
817         *inner_val
818 }
819 /// Used to indicate that we probably can't make any future connections to this peer, implying
820 /// we should go ahead and force-close any channels we have with it.
821 #[no_mangle]
822 pub extern "C" fn PeerHandleError_set_no_connection_possible(this_ptr: &mut PeerHandleError, mut val: bool) {
823         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.no_connection_possible = val;
824 }
825 /// Constructs a new PeerHandleError given each field
826 #[must_use]
827 #[no_mangle]
828 pub extern "C" fn PeerHandleError_new(mut no_connection_possible_arg: bool) -> PeerHandleError {
829         PeerHandleError { inner: ObjOps::heap_alloc(nativePeerHandleError {
830                 no_connection_possible: no_connection_possible_arg,
831         }), is_owned: true }
832 }
833 impl Clone for PeerHandleError {
834         fn clone(&self) -> Self {
835                 Self {
836                         inner: if <*mut nativePeerHandleError>::is_null(self.inner) { std::ptr::null_mut() } else {
837                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
838                         is_owned: true,
839                 }
840         }
841 }
842 #[allow(unused)]
843 /// Used only if an object of this type is returned as a trait impl by a method
844 pub(crate) extern "C" fn PeerHandleError_clone_void(this_ptr: *const c_void) -> *mut c_void {
845         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePeerHandleError)).clone() })) as *mut c_void
846 }
847 #[no_mangle]
848 /// Creates a copy of the PeerHandleError
849 pub extern "C" fn PeerHandleError_clone(orig: &PeerHandleError) -> PeerHandleError {
850         orig.clone()
851 }
852
853 use lightning::ln::peer_handler::PeerManager as nativePeerManagerImport;
854 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>;
855
856 /// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
857 /// socket events into messages which it passes on to its [`MessageHandler`].
858 ///
859 /// Locks are taken internally, so you must never assume that reentrancy from a
860 /// [`SocketDescriptor`] call back into [`PeerManager`] methods will not deadlock.
861 ///
862 /// Calls to [`read_event`] will decode relevant messages and pass them to the
863 /// [`ChannelMessageHandler`], likely doing message processing in-line. Thus, the primary form of
864 /// parallelism in Rust-Lightning is in calls to [`read_event`]. Note, however, that calls to any
865 /// [`PeerManager`] functions related to the same connection must occur only in serial, making new
866 /// calls only after previous ones have returned.
867 ///
868 /// Rather than using a plain PeerManager, it is preferable to use either a SimpleArcPeerManager
869 /// a SimpleRefPeerManager, for conciseness. See their documentation for more details, but
870 /// essentially you should default to using a SimpleRefPeerManager, and use a
871 /// SimpleArcPeerManager when you require a PeerManager with a static lifetime, such as when
872 /// you're using lightning-net-tokio.
873 ///
874 /// [`read_event`]: PeerManager::read_event
875 #[must_use]
876 #[repr(C)]
877 pub struct PeerManager {
878         /// A pointer to the opaque Rust object.
879
880         /// Nearly everywhere, inner must be non-null, however in places where
881         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
882         pub inner: *mut nativePeerManager,
883         /// Indicates that this is the only struct which contains the same pointer.
884
885         /// Rust functions which take ownership of an object provided via an argument require
886         /// this to be true and invalidate the object pointed to by inner.
887         pub is_owned: bool,
888 }
889
890 impl Drop for PeerManager {
891         fn drop(&mut self) {
892                 if self.is_owned && !<*mut nativePeerManager>::is_null(self.inner) {
893                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
894                 }
895         }
896 }
897 /// Frees any resources used by the PeerManager, if is_owned is set and inner is non-NULL.
898 #[no_mangle]
899 pub extern "C" fn PeerManager_free(this_obj: PeerManager) { }
900 #[allow(unused)]
901 /// Used only if an object of this type is returned as a trait impl by a method
902 extern "C" fn PeerManager_free_void(this_ptr: *mut c_void) {
903         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePeerManager); }
904 }
905 #[allow(unused)]
906 impl PeerManager {
907         pub(crate) fn get_native_ref(&self) -> &'static nativePeerManager {
908                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
909         }
910         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerManager {
911                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
912         }
913         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
914         pub(crate) fn take_inner(mut self) -> *mut nativePeerManager {
915                 assert!(self.is_owned);
916                 let ret = ObjOps::untweak_ptr(self.inner);
917                 self.inner = std::ptr::null_mut();
918                 ret
919         }
920 }
921 /// Constructs a new PeerManager with the given message handlers and node_id secret key
922 /// ephemeral_random_data is used to derive per-connection ephemeral keys and must be
923 /// cryptographically secure random bytes.
924 #[must_use]
925 #[no_mangle]
926 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) -> PeerManager {
927         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);
928         PeerManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
929 }
930
931 /// Get the list of node ids for peers which have completed the initial handshake.
932 ///
933 /// For outbound connections, this will be the same as the their_node_id parameter passed in to
934 /// new_outbound_connection, however entries will only appear once the initial handshake has
935 /// completed and we are sure the remote peer has the private key for the given node_id.
936 #[must_use]
937 #[no_mangle]
938 pub extern "C" fn PeerManager_get_peer_node_ids(this_arg: &PeerManager) -> crate::c_types::derived::CVec_PublicKeyZ {
939         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_peer_node_ids();
940         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::PublicKey::from_rust(&item) }); };
941         local_ret.into()
942 }
943
944 /// Indicates a new outbound connection has been established to a node with the given node_id.
945 /// Note that if an Err is returned here you MUST NOT call socket_disconnected for the new
946 /// descriptor but must disconnect the connection immediately.
947 ///
948 /// Returns a small number of bytes to send to the remote node (currently always 50).
949 ///
950 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
951 /// [`socket_disconnected()`].
952 ///
953 /// [`socket_disconnected()`]: PeerManager::socket_disconnected
954 #[must_use]
955 #[no_mangle]
956 pub extern "C" fn PeerManager_new_outbound_connection(this_arg: &PeerManager, mut their_node_id: crate::c_types::PublicKey, mut descriptor: crate::lightning::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_CVec_u8ZPeerHandleErrorZ {
957         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_outbound_connection(their_node_id.into_rust(), descriptor);
958         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() };
959         local_ret
960 }
961
962 /// Indicates a new inbound connection has been established.
963 ///
964 /// May refuse the connection by returning an Err, but will never write bytes to the remote end
965 /// (outbound connector always speaks first). Note that if an Err is returned here you MUST NOT
966 /// call socket_disconnected for the new descriptor but must disconnect the connection
967 /// immediately.
968 ///
969 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
970 /// [`socket_disconnected()`].
971 ///
972 /// [`socket_disconnected()`]: PeerManager::socket_disconnected
973 #[must_use]
974 #[no_mangle]
975 pub extern "C" fn PeerManager_new_inbound_connection(this_arg: &PeerManager, mut descriptor: crate::lightning::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ {
976         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_inbound_connection(descriptor);
977         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() };
978         local_ret
979 }
980
981 /// Indicates that there is room to write data to the given socket descriptor.
982 ///
983 /// May return an Err to indicate that the connection should be closed.
984 ///
985 /// May call [`send_data`] on the descriptor passed in (or an equal descriptor) before
986 /// returning. Thus, be very careful with reentrancy issues! The invariants around calling
987 /// [`write_buffer_space_avail`] in case a write did not fully complete must still hold - be
988 /// ready to call `[write_buffer_space_avail`] again if a write call generated here isn't
989 /// sufficient!
990 ///
991 /// [`send_data`]: SocketDescriptor::send_data
992 /// [`write_buffer_space_avail`]: PeerManager::write_buffer_space_avail
993 #[must_use]
994 #[no_mangle]
995 pub extern "C" fn PeerManager_write_buffer_space_avail(this_arg: &PeerManager, descriptor: &mut crate::lightning::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ {
996         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.write_buffer_space_avail(descriptor);
997         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() };
998         local_ret
999 }
1000
1001 /// Indicates that data was read from the given socket descriptor.
1002 ///
1003 /// May return an Err to indicate that the connection should be closed.
1004 ///
1005 /// Will *not* call back into [`send_data`] on any descriptors to avoid reentrancy complexity.
1006 /// Thus, however, you should call [`process_events`] after any `read_event` to generate
1007 /// [`send_data`] calls to handle responses.
1008 ///
1009 /// If `Ok(true)` is returned, further read_events should not be triggered until a
1010 /// [`send_data`] call on this descriptor has `resume_read` set (preventing DoS issues in the
1011 /// send buffer).
1012 ///
1013 /// [`send_data`]: SocketDescriptor::send_data
1014 /// [`process_events`]: PeerManager::process_events
1015 #[must_use]
1016 #[no_mangle]
1017 pub extern "C" fn PeerManager_read_event(this_arg: &PeerManager, peer_descriptor: &mut crate::lightning::ln::peer_handler::SocketDescriptor, mut data: crate::c_types::u8slice) -> crate::c_types::derived::CResult_boolPeerHandleErrorZ {
1018         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_event(peer_descriptor, data.to_slice());
1019         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() };
1020         local_ret
1021 }
1022
1023 /// Checks for any events generated by our handlers and processes them. Includes sending most
1024 /// response messages as well as messages generated by calls to handler functions directly (eg
1025 /// functions like [`ChannelManager::process_pending_htlc_forwards`] or [`send_payment`]).
1026 ///
1027 /// May call [`send_data`] on [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1028 /// issues!
1029 ///
1030 /// You don't have to call this function explicitly if you are using [`lightning-net-tokio`]
1031 /// or one of the other clients provided in our language bindings.
1032 ///
1033 /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1034 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
1035 /// [`send_data`]: SocketDescriptor::send_data
1036 #[no_mangle]
1037 pub extern "C" fn PeerManager_process_events(this_arg: &PeerManager) {
1038         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_events()
1039 }
1040
1041 /// Indicates that the given socket descriptor's connection is now closed.
1042 #[no_mangle]
1043 pub extern "C" fn PeerManager_socket_disconnected(this_arg: &PeerManager, descriptor: &crate::lightning::ln::peer_handler::SocketDescriptor) {
1044         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.socket_disconnected(descriptor)
1045 }
1046
1047 /// Disconnect a peer given its node id.
1048 ///
1049 /// Set `no_connection_possible` to true to prevent any further connection with this peer,
1050 /// force-closing any channels we have with it.
1051 ///
1052 /// If a peer is connected, this will call [`disconnect_socket`] on the descriptor for the
1053 /// peer. Thus, be very careful about reentrancy issues.
1054 ///
1055 /// [`disconnect_socket`]: SocketDescriptor::disconnect_socket
1056 #[no_mangle]
1057 pub extern "C" fn PeerManager_disconnect_by_node_id(this_arg: &PeerManager, mut node_id: crate::c_types::PublicKey, mut no_connection_possible: bool) {
1058         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_by_node_id(node_id.into_rust(), no_connection_possible)
1059 }
1060
1061 /// Send pings to each peer and disconnect those which did not respond to the last round of
1062 /// pings.
1063 ///
1064 /// This may be called on any timescale you want, however, roughly once every five to ten
1065 /// seconds is preferred. The call rate determines both how often we send a ping to our peers
1066 /// and how much time they have to respond before we disconnect them.
1067 ///
1068 /// May call [`send_data`] on all [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1069 /// issues!
1070 ///
1071 /// [`send_data`]: SocketDescriptor::send_data
1072 #[no_mangle]
1073 pub extern "C" fn PeerManager_timer_tick_occurred(this_arg: &PeerManager) {
1074         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1075 }
1076