1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
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.
9 //! Top level peer message handling and socket handling logic lives here.
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.
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};
25 /// Handler for BOLT1-compliant messages.
27 pub struct CustomMessageHandler {
28 /// An opaque pointer which is passed to your function implementations as an argument.
29 /// This has no meaning in the LDK, and can be NULL or any other value.
30 pub this_arg: *mut c_void,
31 /// Called with the message type that was received and the buffer to be read.
32 /// Can return a `MessageHandlingError` if the message could not be handled.
34 pub handle_custom_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::ln::wire::Type, sender_node_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneLightningErrorZ,
35 /// Gets the list of pending messages which were generated by the custom message
36 /// handler, clearing the list in the process. The first tuple element must
37 /// correspond to the intended recipients node ids. If no connection to one of the
38 /// specified node does not exist, the message is simply not sent to it.
40 pub get_and_clear_pending_msg: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ,
41 /// Implementation of CustomMessageReader for this object.
42 pub CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader,
43 /// Frees any resources associated with this object given its this_arg pointer.
44 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
45 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
47 unsafe impl Send for CustomMessageHandler {}
48 unsafe impl Sync for CustomMessageHandler {}
50 pub(crate) extern "C" fn CustomMessageHandler_clone_fields(orig: &CustomMessageHandler) -> CustomMessageHandler {
51 CustomMessageHandler {
52 this_arg: orig.this_arg,
53 handle_custom_message: Clone::clone(&orig.handle_custom_message),
54 get_and_clear_pending_msg: Clone::clone(&orig.get_and_clear_pending_msg),
55 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader_clone_fields(&orig.CustomMessageReader),
56 free: Clone::clone(&orig.free),
59 impl lightning::ln::wire::CustomMessageReader for CustomMessageHandler {
60 type CustomMessage = crate::lightning::ln::wire::Type;
61 fn read<R:crate::c_types::io::Read>(&self, mut message_type: u16, mut buffer: &mut R) -> Result<Option<crate::lightning::ln::wire::Type>, lightning::ln::msgs::DecodeError> {
62 let mut ret = (self.CustomMessageReader.read)(self.CustomMessageReader.this_arg, message_type, crate::c_types::u8slice::from_vec(&crate::c_types::reader_to_vec(buffer)));
63 let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = { /* (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ let ret_0_opt = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }); { } if ret_0_opt.is_none() { None } else { Some({ ret_0_opt.take() }) } }; local_ret_0 }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
68 use lightning::ln::peer_handler::CustomMessageHandler as rustCustomMessageHandler;
69 impl rustCustomMessageHandler for CustomMessageHandler {
70 fn handle_custom_message(&self, mut msg: crate::lightning::ln::wire::Type, mut sender_node_id: &bitcoin::secp256k1::PublicKey) -> Result<(), lightning::ln::msgs::LightningError> {
71 let mut ret = (self.handle_custom_message)(self.this_arg, Into::into(msg), crate::c_types::PublicKey::from_rust(&sender_node_id));
72 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
75 fn get_and_clear_pending_msg(&self) -> Vec<(bitcoin::secp256k1::PublicKey, crate::lightning::ln::wire::Type)> {
76 let mut ret = (self.get_and_clear_pending_msg)(self.this_arg);
77 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item.to_rust(); let mut local_ret_0 = (orig_ret_0_0.into_rust(), orig_ret_0_1); local_ret_0 }); };
82 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
83 // directly as a Deref trait in higher-level structs:
84 impl core::ops::Deref for CustomMessageHandler {
86 fn deref(&self) -> &Self {
90 /// Calls the free function if one is set
92 pub extern "C" fn CustomMessageHandler_free(this_ptr: CustomMessageHandler) { }
93 impl Drop for CustomMessageHandler {
95 if let Some(f) = self.free {
101 use lightning::ln::peer_handler::IgnoringMessageHandler as nativeIgnoringMessageHandlerImport;
102 pub(crate) type nativeIgnoringMessageHandler = nativeIgnoringMessageHandlerImport;
104 /// A dummy struct which implements `RoutingMessageHandler` without storing any routing information
105 /// or doing any processing. You can provide one of these as the route_handler in a MessageHandler.
108 pub struct IgnoringMessageHandler {
109 /// A pointer to the opaque Rust object.
111 /// Nearly everywhere, inner must be non-null, however in places where
112 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
113 pub inner: *mut nativeIgnoringMessageHandler,
114 /// Indicates that this is the only struct which contains the same pointer.
116 /// Rust functions which take ownership of an object provided via an argument require
117 /// this to be true and invalidate the object pointed to by inner.
121 impl Drop for IgnoringMessageHandler {
123 if self.is_owned && !<*mut nativeIgnoringMessageHandler>::is_null(self.inner) {
124 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
128 /// Frees any resources used by the IgnoringMessageHandler, if is_owned is set and inner is non-NULL.
130 pub extern "C" fn IgnoringMessageHandler_free(this_obj: IgnoringMessageHandler) { }
132 /// Used only if an object of this type is returned as a trait impl by a method
133 pub(crate) extern "C" fn IgnoringMessageHandler_free_void(this_ptr: *mut c_void) {
134 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeIgnoringMessageHandler); }
137 impl IgnoringMessageHandler {
138 pub(crate) fn get_native_ref(&self) -> &'static nativeIgnoringMessageHandler {
139 unsafe { &*ObjOps::untweak_ptr(self.inner) }
141 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeIgnoringMessageHandler {
142 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
144 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
145 pub(crate) fn take_inner(mut self) -> *mut nativeIgnoringMessageHandler {
146 assert!(self.is_owned);
147 let ret = ObjOps::untweak_ptr(self.inner);
148 self.inner = core::ptr::null_mut();
152 /// Constructs a new IgnoringMessageHandler given each field
155 pub extern "C" fn IgnoringMessageHandler_new() -> IgnoringMessageHandler {
156 IgnoringMessageHandler { inner: ObjOps::heap_alloc(nativeIgnoringMessageHandler {
159 impl From<nativeIgnoringMessageHandler> for crate::lightning::util::events::MessageSendEventsProvider {
160 fn from(obj: nativeIgnoringMessageHandler) -> Self {
161 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
162 let mut ret = IgnoringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
163 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
164 rust_obj.inner = core::ptr::null_mut();
165 ret.free = Some(IgnoringMessageHandler_free_void);
169 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
170 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
172 pub extern "C" fn IgnoringMessageHandler_as_MessageSendEventsProvider(this_arg: &IgnoringMessageHandler) -> crate::lightning::util::events::MessageSendEventsProvider {
173 crate::lightning::util::events::MessageSendEventsProvider {
174 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
176 get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
181 extern "C" fn IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
182 let mut ret = <nativeIgnoringMessageHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
183 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
187 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
188 fn from(obj: nativeIgnoringMessageHandler) -> Self {
189 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
190 let mut ret = IgnoringMessageHandler_as_RoutingMessageHandler(&rust_obj);
191 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
192 rust_obj.inner = core::ptr::null_mut();
193 ret.free = Some(IgnoringMessageHandler_free_void);
197 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
198 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
200 pub extern "C" fn IgnoringMessageHandler_as_RoutingMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
201 crate::lightning::ln::msgs::RoutingMessageHandler {
202 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
204 handle_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement,
205 handle_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement,
206 handle_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update,
207 get_next_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcement,
208 get_next_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcement,
209 peer_connected: IgnoringMessageHandler_RoutingMessageHandler_peer_connected,
210 handle_reply_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_channel_range,
211 handle_reply_short_channel_ids_end: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
212 handle_query_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_query_channel_range,
213 handle_query_short_channel_ids: IgnoringMessageHandler_RoutingMessageHandler_handle_query_short_channel_ids,
214 provided_node_features: IgnoringMessageHandler_RoutingMessageHandler_provided_node_features,
215 provided_init_features: IgnoringMessageHandler_RoutingMessageHandler_provided_init_features,
216 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
217 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
219 get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
225 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
226 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
227 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
231 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
232 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
233 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
237 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
238 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
239 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
243 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcement(this_arg: *const c_void, mut starting_point: u64) -> crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ {
244 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, starting_point);
245 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ::None } else { crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ::Some( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = (ret.unwrap()); let mut local_orig_ret_0_1 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((orig_ret_0_1.unwrap())) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(orig_ret_0_0), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }) };
249 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcement(this_arg: *const c_void, mut starting_point: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::NodeAnnouncement {
250 let mut local_starting_point_base = if starting_point.is_null() { None } else { Some( { starting_point.into_rust() }) }; let mut local_starting_point = local_starting_point_base.as_ref();
251 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, local_starting_point);
252 let mut local_ret = crate::lightning::ln::msgs::NodeAnnouncement { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
256 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) -> crate::c_types::derived::CResult_NoneNoneZ {
257 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());
258 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() };
262 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 {
263 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()) });
264 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
268 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 {
269 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()) });
270 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
274 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 {
275 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()) });
276 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
280 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 {
281 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()) });
282 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() };
286 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
287 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
288 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
291 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 {
292 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
293 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
296 impl From<nativeIgnoringMessageHandler> for crate::lightning::util::events::OnionMessageProvider {
297 fn from(obj: nativeIgnoringMessageHandler) -> Self {
298 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
299 let mut ret = IgnoringMessageHandler_as_OnionMessageProvider(&rust_obj);
300 // 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
301 rust_obj.inner = core::ptr::null_mut();
302 ret.free = Some(IgnoringMessageHandler_free_void);
306 /// Constructs a new OnionMessageProvider which calls the relevant methods on this_arg.
307 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageProvider must be freed before this_arg is
309 pub extern "C" fn IgnoringMessageHandler_as_OnionMessageProvider(this_arg: &IgnoringMessageHandler) -> crate::lightning::util::events::OnionMessageProvider {
310 crate::lightning::util::events::OnionMessageProvider {
311 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
313 next_onion_message_for_peer: IgnoringMessageHandler_OnionMessageProvider_next_onion_message_for_peer,
318 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 {
319 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());
320 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 };
324 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::OnionMessageHandler {
325 fn from(obj: nativeIgnoringMessageHandler) -> Self {
326 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
327 let mut ret = IgnoringMessageHandler_as_OnionMessageHandler(&rust_obj);
328 // 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
329 rust_obj.inner = core::ptr::null_mut();
330 ret.free = Some(IgnoringMessageHandler_free_void);
334 /// Constructs a new OnionMessageHandler which calls the relevant methods on this_arg.
335 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageHandler must be freed before this_arg is
337 pub extern "C" fn IgnoringMessageHandler_as_OnionMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::msgs::OnionMessageHandler {
338 crate::lightning::ln::msgs::OnionMessageHandler {
339 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
341 handle_onion_message: IgnoringMessageHandler_OnionMessageHandler_handle_onion_message,
342 peer_connected: IgnoringMessageHandler_OnionMessageHandler_peer_connected,
343 peer_disconnected: IgnoringMessageHandler_OnionMessageHandler_peer_disconnected,
344 provided_node_features: IgnoringMessageHandler_OnionMessageHandler_provided_node_features,
345 provided_init_features: IgnoringMessageHandler_OnionMessageHandler_provided_init_features,
346 OnionMessageProvider: crate::lightning::util::events::OnionMessageProvider {
347 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
349 next_onion_message_for_peer: IgnoringMessageHandler_OnionMessageProvider_next_onion_message_for_peer,
354 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) {
355 <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())
358 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) -> crate::c_types::derived::CResult_NoneNoneZ {
359 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());
360 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() };
363 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut no_connection_possible: bool) {
364 <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust(), no_connection_possible)
367 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
368 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
369 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
372 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 {
373 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
374 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
377 impl From<nativeIgnoringMessageHandler> for crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
378 fn from(obj: nativeIgnoringMessageHandler) -> Self {
379 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
380 let mut ret = IgnoringMessageHandler_as_CustomOnionMessageHandler(&rust_obj);
381 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
382 rust_obj.inner = core::ptr::null_mut();
383 ret.free = Some(IgnoringMessageHandler_free_void);
387 /// Constructs a new CustomOnionMessageHandler which calls the relevant methods on this_arg.
388 /// This copies the `inner` pointer in this_arg and thus the returned CustomOnionMessageHandler must be freed before this_arg is
390 pub extern "C" fn IgnoringMessageHandler_as_CustomOnionMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
391 crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
392 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
394 handle_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message,
395 read_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_read_custom_message,
399 extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message(this_arg: *const c_void, mut msg: crate::lightning::onion_message::packet::CustomOnionMessageContents) {
403 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 {
404 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());
405 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() };
409 impl From<nativeInfallible> for crate::lightning::onion_message::packet::CustomOnionMessageContents {
410 fn from(obj: nativeInfallible) -> Self {
414 impl From<nativeInfallible> for crate::lightning::ln::wire::Type {
415 fn from(obj: nativeInfallible) -> Self {
419 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::wire::CustomMessageReader {
420 fn from(obj: nativeIgnoringMessageHandler) -> Self {
421 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
422 let mut ret = IgnoringMessageHandler_as_CustomMessageReader(&rust_obj);
423 // 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
424 rust_obj.inner = core::ptr::null_mut();
425 ret.free = Some(IgnoringMessageHandler_free_void);
429 /// Constructs a new CustomMessageReader which calls the relevant methods on this_arg.
430 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageReader must be freed before this_arg is
432 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageReader(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::wire::CustomMessageReader {
433 crate::lightning::ln::wire::CustomMessageReader {
434 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
436 read: IgnoringMessageHandler_CustomMessageReader_read,
441 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 {
442 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::wire::CustomMessageReader<>>::read(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, message_type, &mut buffer.to_reader());
443 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() };
447 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::peer_handler::CustomMessageHandler {
448 fn from(obj: nativeIgnoringMessageHandler) -> Self {
449 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
450 let mut ret = IgnoringMessageHandler_as_CustomMessageHandler(&rust_obj);
451 // 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
452 rust_obj.inner = core::ptr::null_mut();
453 ret.free = Some(IgnoringMessageHandler_free_void);
457 /// Constructs a new CustomMessageHandler which calls the relevant methods on this_arg.
458 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageHandler must be freed before this_arg is
460 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::peer_handler::CustomMessageHandler {
461 crate::lightning::ln::peer_handler::CustomMessageHandler {
462 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
464 handle_custom_message: IgnoringMessageHandler_CustomMessageHandler_handle_custom_message,
465 get_and_clear_pending_msg: IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg,
466 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader {
467 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
469 read: IgnoringMessageHandler_CustomMessageReader_read,
475 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 {
479 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ {
480 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::get_and_clear_pending_msg(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
481 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 }); };
486 use lightning::ln::peer_handler::ErroringMessageHandler as nativeErroringMessageHandlerImport;
487 pub(crate) type nativeErroringMessageHandler = nativeErroringMessageHandlerImport;
489 /// A dummy struct which implements `ChannelMessageHandler` without having any channels.
490 /// You can provide one of these as the route_handler in a MessageHandler.
493 pub struct ErroringMessageHandler {
494 /// A pointer to the opaque Rust object.
496 /// Nearly everywhere, inner must be non-null, however in places where
497 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
498 pub inner: *mut nativeErroringMessageHandler,
499 /// Indicates that this is the only struct which contains the same pointer.
501 /// Rust functions which take ownership of an object provided via an argument require
502 /// this to be true and invalidate the object pointed to by inner.
506 impl Drop for ErroringMessageHandler {
508 if self.is_owned && !<*mut nativeErroringMessageHandler>::is_null(self.inner) {
509 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
513 /// Frees any resources used by the ErroringMessageHandler, if is_owned is set and inner is non-NULL.
515 pub extern "C" fn ErroringMessageHandler_free(this_obj: ErroringMessageHandler) { }
517 /// Used only if an object of this type is returned as a trait impl by a method
518 pub(crate) extern "C" fn ErroringMessageHandler_free_void(this_ptr: *mut c_void) {
519 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeErroringMessageHandler); }
522 impl ErroringMessageHandler {
523 pub(crate) fn get_native_ref(&self) -> &'static nativeErroringMessageHandler {
524 unsafe { &*ObjOps::untweak_ptr(self.inner) }
526 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeErroringMessageHandler {
527 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
529 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
530 pub(crate) fn take_inner(mut self) -> *mut nativeErroringMessageHandler {
531 assert!(self.is_owned);
532 let ret = ObjOps::untweak_ptr(self.inner);
533 self.inner = core::ptr::null_mut();
537 /// Constructs a new ErroringMessageHandler
540 pub extern "C" fn ErroringMessageHandler_new() -> crate::lightning::ln::peer_handler::ErroringMessageHandler {
541 let mut ret = lightning::ln::peer_handler::ErroringMessageHandler::new();
542 crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
545 impl From<nativeErroringMessageHandler> for crate::lightning::util::events::MessageSendEventsProvider {
546 fn from(obj: nativeErroringMessageHandler) -> Self {
547 let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
548 let mut ret = ErroringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
549 // 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
550 rust_obj.inner = core::ptr::null_mut();
551 ret.free = Some(ErroringMessageHandler_free_void);
555 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
556 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
558 pub extern "C" fn ErroringMessageHandler_as_MessageSendEventsProvider(this_arg: &ErroringMessageHandler) -> crate::lightning::util::events::MessageSendEventsProvider {
559 crate::lightning::util::events::MessageSendEventsProvider {
560 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
562 get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
567 extern "C" fn ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
568 let mut ret = <nativeErroringMessageHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
569 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
573 impl From<nativeErroringMessageHandler> for crate::lightning::ln::msgs::ChannelMessageHandler {
574 fn from(obj: nativeErroringMessageHandler) -> Self {
575 let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
576 let mut ret = ErroringMessageHandler_as_ChannelMessageHandler(&rust_obj);
577 // 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
578 rust_obj.inner = core::ptr::null_mut();
579 ret.free = Some(ErroringMessageHandler_free_void);
583 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
584 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
586 pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &ErroringMessageHandler) -> crate::lightning::ln::msgs::ChannelMessageHandler {
587 crate::lightning::ln::msgs::ChannelMessageHandler {
588 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
590 handle_open_channel: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel,
591 handle_accept_channel: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel,
592 handle_funding_created: ErroringMessageHandler_ChannelMessageHandler_handle_funding_created,
593 handle_funding_signed: ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed,
594 handle_channel_ready: ErroringMessageHandler_ChannelMessageHandler_handle_channel_ready,
595 handle_shutdown: ErroringMessageHandler_ChannelMessageHandler_handle_shutdown,
596 handle_closing_signed: ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed,
597 handle_update_add_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc,
598 handle_update_fulfill_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc,
599 handle_update_fail_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc,
600 handle_update_fail_malformed_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_malformed_htlc,
601 handle_commitment_signed: ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed,
602 handle_revoke_and_ack: ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack,
603 handle_update_fee: ErroringMessageHandler_ChannelMessageHandler_handle_update_fee,
604 handle_announcement_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures,
605 peer_disconnected: ErroringMessageHandler_ChannelMessageHandler_peer_disconnected,
606 peer_connected: ErroringMessageHandler_ChannelMessageHandler_peer_connected,
607 handle_channel_reestablish: ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish,
608 handle_channel_update: ErroringMessageHandler_ChannelMessageHandler_handle_channel_update,
609 handle_error: ErroringMessageHandler_ChannelMessageHandler_handle_error,
610 provided_node_features: ErroringMessageHandler_ChannelMessageHandler_provided_node_features,
611 provided_init_features: ErroringMessageHandler_ChannelMessageHandler_provided_init_features,
612 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
613 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
615 get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
620 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_open_channel(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut their_features: crate::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::OpenChannel) {
621 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_open_channel(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(their_features.take_inner()) }, msg.get_native_ref())
623 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut their_features: crate::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::AcceptChannel) {
624 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_accept_channel(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(their_features.take_inner()) }, msg.get_native_ref())
626 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) {
627 <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())
629 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) {
630 <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())
632 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) {
633 <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())
635 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_shutdown(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, their_features: &crate::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::Shutdown) {
636 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), their_features.get_native_ref(), msg.get_native_ref())
638 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) {
639 <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())
641 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) {
642 <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())
644 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) {
645 <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())
647 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) {
648 <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())
650 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) {
651 <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())
653 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) {
654 <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())
656 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) {
657 <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())
659 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) {
660 <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())
662 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) {
663 <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())
665 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut no_connection_possible: bool) {
666 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), no_connection_possible)
669 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) -> crate::c_types::derived::CResult_NoneNoneZ {
670 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());
671 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() };
674 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) {
675 <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())
677 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) {
678 <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())
680 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) {
681 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
684 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
685 let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
686 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
689 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 {
690 let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust());
691 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
695 use lightning::ln::peer_handler::MessageHandler as nativeMessageHandlerImport;
696 pub(crate) type nativeMessageHandler = nativeMessageHandlerImport<crate::lightning::ln::msgs::ChannelMessageHandler, crate::lightning::ln::msgs::RoutingMessageHandler, crate::lightning::ln::msgs::OnionMessageHandler>;
698 /// Provides references to trait impls which handle different types of messages.
701 pub struct MessageHandler {
702 /// A pointer to the opaque Rust object.
704 /// Nearly everywhere, inner must be non-null, however in places where
705 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
706 pub inner: *mut nativeMessageHandler,
707 /// Indicates that this is the only struct which contains the same pointer.
709 /// Rust functions which take ownership of an object provided via an argument require
710 /// this to be true and invalidate the object pointed to by inner.
714 impl Drop for MessageHandler {
716 if self.is_owned && !<*mut nativeMessageHandler>::is_null(self.inner) {
717 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
721 /// Frees any resources used by the MessageHandler, if is_owned is set and inner is non-NULL.
723 pub extern "C" fn MessageHandler_free(this_obj: MessageHandler) { }
725 /// Used only if an object of this type is returned as a trait impl by a method
726 pub(crate) extern "C" fn MessageHandler_free_void(this_ptr: *mut c_void) {
727 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMessageHandler); }
730 impl MessageHandler {
731 pub(crate) fn get_native_ref(&self) -> &'static nativeMessageHandler {
732 unsafe { &*ObjOps::untweak_ptr(self.inner) }
734 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMessageHandler {
735 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
737 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
738 pub(crate) fn take_inner(mut self) -> *mut nativeMessageHandler {
739 assert!(self.is_owned);
740 let ret = ObjOps::untweak_ptr(self.inner);
741 self.inner = core::ptr::null_mut();
745 /// A message handler which handles messages specific to channels. Usually this is just a
746 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
748 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
750 pub extern "C" fn MessageHandler_get_chan_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::ChannelMessageHandler {
751 let mut inner_val = &mut this_ptr.get_native_mut_ref().chan_handler;
754 /// A message handler which handles messages specific to channels. Usually this is just a
755 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
757 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
759 pub extern "C" fn MessageHandler_set_chan_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::ChannelMessageHandler) {
760 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chan_handler = val;
762 /// A message handler which handles messages updating our knowledge of the network channel
763 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
765 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
767 pub extern "C" fn MessageHandler_get_route_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::RoutingMessageHandler {
768 let mut inner_val = &mut this_ptr.get_native_mut_ref().route_handler;
771 /// A message handler which handles messages updating our knowledge of the network channel
772 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
774 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
776 pub extern "C" fn MessageHandler_set_route_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::RoutingMessageHandler) {
777 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_handler = val;
779 /// A message handler which handles onion messages. For now, this can only be an
780 /// [`IgnoringMessageHandler`].
782 pub extern "C" fn MessageHandler_get_onion_message_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::OnionMessageHandler {
783 let mut inner_val = &mut this_ptr.get_native_mut_ref().onion_message_handler;
786 /// A message handler which handles onion messages. For now, this can only be an
787 /// [`IgnoringMessageHandler`].
789 pub extern "C" fn MessageHandler_set_onion_message_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::OnionMessageHandler) {
790 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.onion_message_handler = val;
792 /// Constructs a new MessageHandler given each field
795 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 {
796 MessageHandler { inner: ObjOps::heap_alloc(nativeMessageHandler {
797 chan_handler: chan_handler_arg,
798 route_handler: route_handler_arg,
799 onion_message_handler: onion_message_handler_arg,
802 /// Provides an object which can be used to send data to and which uniquely identifies a connection
803 /// to a remote host. You will need to be able to generate multiple of these which meet Eq and
804 /// implement Hash to meet the PeerManager API.
806 /// For efficiency, Clone should be relatively cheap for this type.
808 /// Two descriptors may compare equal (by [`cmp::Eq`] and [`hash::Hash`]) as long as the original
809 /// has been disconnected, the [`PeerManager`] has been informed of the disconnection (either by it
810 /// having triggered the disconnection or a call to [`PeerManager::socket_disconnected`]), and no
811 /// further calls to the [`PeerManager`] related to the original socket occur. This allows you to
812 /// use a file descriptor for your SocketDescriptor directly, however for simplicity you may wish
813 /// to simply use another value which is guaranteed to be globally unique instead.
815 pub struct SocketDescriptor {
816 /// An opaque pointer which is passed to your function implementations as an argument.
817 /// This has no meaning in the LDK, and can be NULL or any other value.
818 pub this_arg: *mut c_void,
819 /// Attempts to send some data from the given slice to the peer.
821 /// Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
822 /// Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
823 /// called and further write attempts may occur until that time.
825 /// If the returned size is smaller than `data.len()`, a
826 /// [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
827 /// written. Additionally, until a `send_data` event completes fully, no further
828 /// [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
829 /// prevent denial-of-service issues, you should not read or buffer any data from the socket
832 /// If a [`PeerManager::read_event`] call on this descriptor had previously returned true
833 /// (indicating that read events should be paused to prevent DoS in the send buffer),
834 /// `resume_read` may be set indicating that read events on this descriptor should resume. A
835 /// `resume_read` of false carries no meaning, and should not cause any action.
837 pub send_data: extern "C" fn (this_arg: *mut c_void, data: crate::c_types::u8slice, resume_read: bool) -> usize,
838 /// Disconnect the socket pointed to by this SocketDescriptor.
840 /// You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
841 /// call (doing so is a noop).
842 pub disconnect_socket: extern "C" fn (this_arg: *mut c_void),
843 /// Checks if two objects are equal given this object's this_arg pointer and another object.
844 pub eq: extern "C" fn (this_arg: *const c_void, other_arg: &SocketDescriptor) -> bool,
845 /// Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.
846 /// This is used, for example, for inclusion of this object in a hash map.
847 pub hash: extern "C" fn (this_arg: *const c_void) -> u64,
848 /// Called, if set, after this SocketDescriptor has been cloned into a duplicate object.
849 /// The new SocketDescriptor is provided, and should be mutated as needed to perform a
850 /// deep copy of the object pointed to by this_arg or avoid any double-freeing.
851 pub cloned: Option<extern "C" fn (new_SocketDescriptor: &mut SocketDescriptor)>,
852 /// Frees any resources associated with this object given its this_arg pointer.
853 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
854 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
856 unsafe impl Send for SocketDescriptor {}
857 unsafe impl Sync for SocketDescriptor {}
859 pub(crate) extern "C" fn SocketDescriptor_clone_fields(orig: &SocketDescriptor) -> SocketDescriptor {
861 this_arg: orig.this_arg,
862 send_data: Clone::clone(&orig.send_data),
863 disconnect_socket: Clone::clone(&orig.disconnect_socket),
864 eq: Clone::clone(&orig.eq),
865 hash: Clone::clone(&orig.hash),
866 cloned: Clone::clone(&orig.cloned),
867 free: Clone::clone(&orig.free),
870 impl core::cmp::Eq for SocketDescriptor {}
871 impl core::cmp::PartialEq for SocketDescriptor {
872 fn eq(&self, o: &Self) -> bool { (self.eq)(self.this_arg, o) }
874 impl core::hash::Hash for SocketDescriptor {
875 fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) { hasher.write_u64((self.hash)(self.this_arg)) }
878 /// Creates a copy of a SocketDescriptor
879 pub extern "C" fn SocketDescriptor_clone(orig: &SocketDescriptor) -> SocketDescriptor {
880 let mut res = SocketDescriptor_clone_fields(orig);
881 if let Some(f) = orig.cloned { (f)(&mut res) };
884 impl Clone for SocketDescriptor {
885 fn clone(&self) -> Self {
886 SocketDescriptor_clone(self)
890 use lightning::ln::peer_handler::SocketDescriptor as rustSocketDescriptor;
891 impl rustSocketDescriptor for SocketDescriptor {
892 fn send_data(&mut self, mut data: &[u8], mut resume_read: bool) -> usize {
893 let mut local_data = crate::c_types::u8slice::from_slice(data);
894 let mut ret = (self.send_data)(self.this_arg, local_data, resume_read);
897 fn disconnect_socket(&mut self) {
898 (self.disconnect_socket)(self.this_arg)
902 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
903 // directly as a Deref trait in higher-level structs:
904 impl core::ops::Deref for SocketDescriptor {
906 fn deref(&self) -> &Self {
910 /// Calls the free function if one is set
912 pub extern "C" fn SocketDescriptor_free(this_ptr: SocketDescriptor) { }
913 impl Drop for SocketDescriptor {
915 if let Some(f) = self.free {
921 use lightning::ln::peer_handler::PeerHandleError as nativePeerHandleErrorImport;
922 pub(crate) type nativePeerHandleError = nativePeerHandleErrorImport;
924 /// Error for PeerManager errors. If you get one of these, you must disconnect the socket and
925 /// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the
929 pub struct PeerHandleError {
930 /// A pointer to the opaque Rust object.
932 /// Nearly everywhere, inner must be non-null, however in places where
933 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
934 pub inner: *mut nativePeerHandleError,
935 /// Indicates that this is the only struct which contains the same pointer.
937 /// Rust functions which take ownership of an object provided via an argument require
938 /// this to be true and invalidate the object pointed to by inner.
942 impl Drop for PeerHandleError {
944 if self.is_owned && !<*mut nativePeerHandleError>::is_null(self.inner) {
945 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
949 /// Frees any resources used by the PeerHandleError, if is_owned is set and inner is non-NULL.
951 pub extern "C" fn PeerHandleError_free(this_obj: PeerHandleError) { }
953 /// Used only if an object of this type is returned as a trait impl by a method
954 pub(crate) extern "C" fn PeerHandleError_free_void(this_ptr: *mut c_void) {
955 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePeerHandleError); }
958 impl PeerHandleError {
959 pub(crate) fn get_native_ref(&self) -> &'static nativePeerHandleError {
960 unsafe { &*ObjOps::untweak_ptr(self.inner) }
962 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerHandleError {
963 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
965 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
966 pub(crate) fn take_inner(mut self) -> *mut nativePeerHandleError {
967 assert!(self.is_owned);
968 let ret = ObjOps::untweak_ptr(self.inner);
969 self.inner = core::ptr::null_mut();
973 /// Used to indicate that we probably can't make any future connections to this peer (e.g.
974 /// because we required features that our peer was missing, or vice versa).
976 /// While LDK's [`ChannelManager`] will not do it automatically, you likely wish to force-close
977 /// any channels with this peer or check for new versions of LDK.
979 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
981 pub extern "C" fn PeerHandleError_get_no_connection_possible(this_ptr: &PeerHandleError) -> bool {
982 let mut inner_val = &mut this_ptr.get_native_mut_ref().no_connection_possible;
985 /// Used to indicate that we probably can't make any future connections to this peer (e.g.
986 /// because we required features that our peer was missing, or vice versa).
988 /// While LDK's [`ChannelManager`] will not do it automatically, you likely wish to force-close
989 /// any channels with this peer or check for new versions of LDK.
991 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
993 pub extern "C" fn PeerHandleError_set_no_connection_possible(this_ptr: &mut PeerHandleError, mut val: bool) {
994 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.no_connection_possible = val;
996 /// Constructs a new PeerHandleError given each field
999 pub extern "C" fn PeerHandleError_new(mut no_connection_possible_arg: bool) -> PeerHandleError {
1000 PeerHandleError { inner: ObjOps::heap_alloc(nativePeerHandleError {
1001 no_connection_possible: no_connection_possible_arg,
1002 }), is_owned: true }
1004 impl Clone for PeerHandleError {
1005 fn clone(&self) -> Self {
1007 inner: if <*mut nativePeerHandleError>::is_null(self.inner) { core::ptr::null_mut() } else {
1008 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1014 /// Used only if an object of this type is returned as a trait impl by a method
1015 pub(crate) extern "C" fn PeerHandleError_clone_void(this_ptr: *const c_void) -> *mut c_void {
1016 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePeerHandleError)).clone() })) as *mut c_void
1019 /// Creates a copy of the PeerHandleError
1020 pub extern "C" fn PeerHandleError_clone(orig: &PeerHandleError) -> PeerHandleError {
1024 use lightning::ln::peer_handler::PeerManager as nativePeerManagerImport;
1025 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>;
1027 /// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
1028 /// socket events into messages which it passes on to its [`MessageHandler`].
1030 /// Locks are taken internally, so you must never assume that reentrancy from a
1031 /// [`SocketDescriptor`] call back into [`PeerManager`] methods will not deadlock.
1033 /// Calls to [`read_event`] will decode relevant messages and pass them to the
1034 /// [`ChannelMessageHandler`], likely doing message processing in-line. Thus, the primary form of
1035 /// parallelism in Rust-Lightning is in calls to [`read_event`]. Note, however, that calls to any
1036 /// [`PeerManager`] functions related to the same connection must occur only in serial, making new
1037 /// calls only after previous ones have returned.
1039 /// Rather than using a plain PeerManager, it is preferable to use either a SimpleArcPeerManager
1040 /// a SimpleRefPeerManager, for conciseness. See their documentation for more details, but
1041 /// essentially you should default to using a SimpleRefPeerManager, and use a
1042 /// SimpleArcPeerManager when you require a PeerManager with a static lifetime, such as when
1043 /// you're using lightning-net-tokio.
1045 /// [`read_event`]: PeerManager::read_event
1048 pub struct PeerManager {
1049 /// A pointer to the opaque Rust object.
1051 /// Nearly everywhere, inner must be non-null, however in places where
1052 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1053 pub inner: *mut nativePeerManager,
1054 /// Indicates that this is the only struct which contains the same pointer.
1056 /// Rust functions which take ownership of an object provided via an argument require
1057 /// this to be true and invalidate the object pointed to by inner.
1061 impl Drop for PeerManager {
1062 fn drop(&mut self) {
1063 if self.is_owned && !<*mut nativePeerManager>::is_null(self.inner) {
1064 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1068 /// Frees any resources used by the PeerManager, if is_owned is set and inner is non-NULL.
1070 pub extern "C" fn PeerManager_free(this_obj: PeerManager) { }
1072 /// Used only if an object of this type is returned as a trait impl by a method
1073 pub(crate) extern "C" fn PeerManager_free_void(this_ptr: *mut c_void) {
1074 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePeerManager); }
1078 pub(crate) fn get_native_ref(&self) -> &'static nativePeerManager {
1079 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1081 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerManager {
1082 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1084 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1085 pub(crate) fn take_inner(mut self) -> *mut nativePeerManager {
1086 assert!(self.is_owned);
1087 let ret = ObjOps::untweak_ptr(self.inner);
1088 self.inner = core::ptr::null_mut();
1092 /// Constructs a new PeerManager with the given message handlers and node_id secret key
1093 /// ephemeral_random_data is used to derive per-connection ephemeral keys and must be
1094 /// cryptographically secure random bytes.
1096 /// `current_time` is used as an always-increasing counter that survives across restarts and is
1097 /// incremented irregularly internally. In general it is best to simply use the current UNIX
1098 /// timestamp, however if it is not available a persistent counter that increases once per
1099 /// minute should suffice.
1102 pub extern "C" fn PeerManager_new(mut message_handler: crate::lightning::ln::peer_handler::MessageHandler, mut our_node_secret: crate::c_types::SecretKey, mut current_time: u32, ephemeral_random_data: *const [u8; 32], mut logger: crate::lightning::util::logger::Logger, mut custom_message_handler: crate::lightning::ln::peer_handler::CustomMessageHandler) -> crate::lightning::ln::peer_handler::PeerManager {
1103 let mut ret = lightning::ln::peer_handler::PeerManager::new(*unsafe { Box::from_raw(message_handler.take_inner()) }, our_node_secret.into_rust(), current_time, unsafe { &*ephemeral_random_data}, logger, custom_message_handler);
1104 crate::lightning::ln::peer_handler::PeerManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1107 /// Get the list of node ids for peers which have completed the initial handshake.
1109 /// For outbound connections, this will be the same as the their_node_id parameter passed in to
1110 /// new_outbound_connection, however entries will only appear once the initial handshake has
1111 /// completed and we are sure the remote peer has the private key for the given node_id.
1114 pub extern "C" fn PeerManager_get_peer_node_ids(this_arg: &crate::lightning::ln::peer_handler::PeerManager) -> crate::c_types::derived::CVec_PublicKeyZ {
1115 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_peer_node_ids();
1116 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::PublicKey::from_rust(&item) }); };
1120 /// Indicates a new outbound connection has been established to a node with the given node_id
1121 /// and an optional remote network address.
1123 /// The remote network address adds the option to report a remote IP address back to a connecting
1124 /// peer using the init message.
1125 /// The user should pass the remote network address of the host they are connected to.
1127 /// If an `Err` is returned here you must disconnect the connection immediately.
1129 /// Returns a small number of bytes to send to the remote node (currently always 50).
1131 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
1132 /// [`socket_disconnected()`].
1134 /// [`socket_disconnected()`]: PeerManager::socket_disconnected
1137 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 {
1138 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() }) } };
1139 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_outbound_connection(their_node_id.into_rust(), descriptor, local_remote_network_address);
1140 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() };
1144 /// Indicates a new inbound connection has been established to a node with an optional remote
1145 /// network address.
1147 /// The remote network address adds the option to report a remote IP address back to a connecting
1148 /// peer using the init message.
1149 /// The user should pass the remote network address of the host they are connected to.
1151 /// May refuse the connection by returning an Err, but will never write bytes to the remote end
1152 /// (outbound connector always speaks first). If an `Err` is returned here you must disconnect
1153 /// the connection immediately.
1155 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
1156 /// [`socket_disconnected()`].
1158 /// [`socket_disconnected()`]: PeerManager::socket_disconnected
1161 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 {
1162 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() }) } };
1163 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_inbound_connection(descriptor, local_remote_network_address);
1164 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() };
1168 /// Indicates that there is room to write data to the given socket descriptor.
1170 /// May return an Err to indicate that the connection should be closed.
1172 /// May call [`send_data`] on the descriptor passed in (or an equal descriptor) before
1173 /// returning. Thus, be very careful with reentrancy issues! The invariants around calling
1174 /// [`write_buffer_space_avail`] in case a write did not fully complete must still hold - be
1175 /// ready to call `[write_buffer_space_avail`] again if a write call generated here isn't
1178 /// [`send_data`]: SocketDescriptor::send_data
1179 /// [`write_buffer_space_avail`]: PeerManager::write_buffer_space_avail
1182 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 {
1183 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.write_buffer_space_avail(descriptor);
1184 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() };
1188 /// Indicates that data was read from the given socket descriptor.
1190 /// May return an Err to indicate that the connection should be closed.
1192 /// Will *not* call back into [`send_data`] on any descriptors to avoid reentrancy complexity.
1193 /// Thus, however, you should call [`process_events`] after any `read_event` to generate
1194 /// [`send_data`] calls to handle responses.
1196 /// If `Ok(true)` is returned, further read_events should not be triggered until a
1197 /// [`send_data`] call on this descriptor has `resume_read` set (preventing DoS issues in the
1200 /// [`send_data`]: SocketDescriptor::send_data
1201 /// [`process_events`]: PeerManager::process_events
1204 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 {
1205 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_event(peer_descriptor, data.to_slice());
1206 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() };
1210 /// Checks for any events generated by our handlers and processes them. Includes sending most
1211 /// response messages as well as messages generated by calls to handler functions directly (eg
1212 /// functions like [`ChannelManager::process_pending_htlc_forwards`] or [`send_payment`]).
1214 /// May call [`send_data`] on [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1217 /// You don't have to call this function explicitly if you are using [`lightning-net-tokio`]
1218 /// or one of the other clients provided in our language bindings.
1220 /// Note that if there are any other calls to this function waiting on lock(s) this may return
1221 /// without doing any work. All available events that need handling will be handled before the
1222 /// other calls return.
1224 /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1225 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
1226 /// [`send_data`]: SocketDescriptor::send_data
1228 pub extern "C" fn PeerManager_process_events(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1229 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_events()
1232 /// Indicates that the given socket descriptor's connection is now closed.
1234 pub extern "C" fn PeerManager_socket_disconnected(this_arg: &crate::lightning::ln::peer_handler::PeerManager, descriptor: &crate::lightning::ln::peer_handler::SocketDescriptor) {
1235 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.socket_disconnected(descriptor)
1238 /// Disconnect a peer given its node id.
1240 /// Set `no_connection_possible` to true to prevent any further connection with this peer,
1241 /// force-closing any channels we have with it.
1243 /// If a peer is connected, this will call [`disconnect_socket`] on the descriptor for the
1244 /// peer. Thus, be very careful about reentrancy issues.
1246 /// [`disconnect_socket`]: SocketDescriptor::disconnect_socket
1248 pub extern "C" fn PeerManager_disconnect_by_node_id(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut node_id: crate::c_types::PublicKey, mut no_connection_possible: bool) {
1249 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_by_node_id(node_id.into_rust(), no_connection_possible)
1252 /// Disconnects all currently-connected peers. This is useful on platforms where there may be
1253 /// an indication that TCP sockets have stalled even if we weren't around to time them out
1254 /// using regular ping/pongs.
1256 pub extern "C" fn PeerManager_disconnect_all_peers(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1257 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_all_peers()
1260 /// Send pings to each peer and disconnect those which did not respond to the last round of
1263 /// This may be called on any timescale you want, however, roughly once every ten seconds is
1264 /// preferred. The call rate determines both how often we send a ping to our peers and how much
1265 /// time they have to respond before we disconnect them.
1267 /// May call [`send_data`] on all [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1270 /// [`send_data`]: SocketDescriptor::send_data
1272 pub extern "C" fn PeerManager_timer_tick_occurred(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1273 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1276 /// Generates a signed node_announcement from the given arguments, sending it to all connected
1277 /// peers. Note that peers will likely ignore this message unless we have at least one public
1278 /// channel which has at least six confirmations on-chain.
1280 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1281 /// node to humans. They carry no in-protocol meaning.
1283 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1284 /// accepts incoming connections. These will be included in the node_announcement, publicly
1285 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1286 /// addresses should likely contain only Tor Onion addresses.
1288 /// Panics if `addresses` is absurdly large (more than 100).
1290 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1292 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) {
1293 let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1294 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1297 use core::convert::Infallible as nativeInfallible;