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