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 alloc::string::String;
19 use core::ffi::c_void;
20 use core::convert::Infallible;
21 use bitcoin::hashes::Hash;
22 use crate::c_types::*;
23 #[cfg(feature="no-std")]
24 use alloc::{vec::Vec, boxed::Box};
26 /// A handler provided to [`PeerManager`] for reading and handling custom messages.
28 /// [BOLT 1] specifies a custom message type range for use with experimental or application-specific
29 /// messages. `CustomMessageHandler` allows for user-defined handling of such types. See the
30 /// [`lightning_custom_message`] crate for tools useful in composing more than one custom handler.
32 /// [BOLT 1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
33 /// [`lightning_custom_message`]: https://docs.rs/lightning_custom_message/latest/lightning_custom_message
35 pub struct CustomMessageHandler {
36 /// An opaque pointer which is passed to your function implementations as an argument.
37 /// This has no meaning in the LDK, and can be NULL or any other value.
38 pub this_arg: *mut c_void,
39 /// Handles the given message sent from `sender_node_id`, possibly producing messages for
40 /// [`CustomMessageHandler::get_and_clear_pending_msg`] to return and thus for [`PeerManager`]
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 pub get_and_clear_pending_msg: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ,
47 /// Gets the node feature flags which this handler itself supports. All available handlers are
48 /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
49 /// which are broadcasted in our [`NodeAnnouncement`] message.
51 /// [`NodeAnnouncement`]: crate::ln::msgs::NodeAnnouncement
52 pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures,
53 /// Gets the init feature flags which should be sent to the given peer. All available handlers
54 /// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
55 /// which are sent in our [`Init`] message.
57 /// [`Init`]: crate::ln::msgs::Init
58 pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures,
59 /// Implementation of CustomMessageReader for this object.
60 pub CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader,
61 /// Frees any resources associated with this object given its this_arg pointer.
62 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
63 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
65 unsafe impl Send for CustomMessageHandler {}
66 unsafe impl Sync for CustomMessageHandler {}
68 pub(crate) fn CustomMessageHandler_clone_fields(orig: &CustomMessageHandler) -> CustomMessageHandler {
69 CustomMessageHandler {
70 this_arg: orig.this_arg,
71 handle_custom_message: Clone::clone(&orig.handle_custom_message),
72 get_and_clear_pending_msg: Clone::clone(&orig.get_and_clear_pending_msg),
73 provided_node_features: Clone::clone(&orig.provided_node_features),
74 provided_init_features: Clone::clone(&orig.provided_init_features),
75 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader_clone_fields(&orig.CustomMessageReader),
76 free: Clone::clone(&orig.free),
79 impl lightning::ln::wire::CustomMessageReader for CustomMessageHandler {
80 type CustomMessage = crate::lightning::ln::wire::Type;
81 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> {
82 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)));
83 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() })};
88 use lightning::ln::peer_handler::CustomMessageHandler as rustCustomMessageHandler;
89 impl rustCustomMessageHandler for CustomMessageHandler {
90 fn handle_custom_message(&self, mut msg: crate::lightning::ln::wire::Type, mut sender_node_id: &bitcoin::secp256k1::PublicKey) -> Result<(), lightning::ln::msgs::LightningError> {
91 let mut ret = (self.handle_custom_message)(self.this_arg, Into::into(msg), crate::c_types::PublicKey::from_rust(&sender_node_id));
92 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()) } })};
95 fn get_and_clear_pending_msg(&self) -> Vec<(bitcoin::secp256k1::PublicKey, crate::lightning::ln::wire::Type)> {
96 let mut ret = (self.get_and_clear_pending_msg)(self.this_arg);
97 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 }); };
100 fn provided_node_features(&self) -> lightning::ln::features::NodeFeatures {
101 let mut ret = (self.provided_node_features)(self.this_arg);
102 *unsafe { Box::from_raw(ret.take_inner()) }
104 fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning::ln::features::InitFeatures {
105 let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id));
106 *unsafe { Box::from_raw(ret.take_inner()) }
110 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
111 // directly as a Deref trait in higher-level structs:
112 impl core::ops::Deref for CustomMessageHandler {
114 fn deref(&self) -> &Self {
118 impl core::ops::DerefMut for CustomMessageHandler {
119 fn deref_mut(&mut self) -> &mut Self {
123 /// Calls the free function if one is set
125 pub extern "C" fn CustomMessageHandler_free(this_ptr: CustomMessageHandler) { }
126 impl Drop for CustomMessageHandler {
128 if let Some(f) = self.free {
134 use lightning::ln::peer_handler::IgnoringMessageHandler as nativeIgnoringMessageHandlerImport;
135 pub(crate) type nativeIgnoringMessageHandler = nativeIgnoringMessageHandlerImport;
137 /// A dummy struct which implements `RoutingMessageHandler` without storing any routing information
138 /// or doing any processing. You can provide one of these as the route_handler in a MessageHandler.
141 pub struct IgnoringMessageHandler {
142 /// A pointer to the opaque Rust object.
144 /// Nearly everywhere, inner must be non-null, however in places where
145 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
146 pub inner: *mut nativeIgnoringMessageHandler,
147 /// Indicates that this is the only struct which contains the same pointer.
149 /// Rust functions which take ownership of an object provided via an argument require
150 /// this to be true and invalidate the object pointed to by inner.
154 impl Drop for IgnoringMessageHandler {
156 if self.is_owned && !<*mut nativeIgnoringMessageHandler>::is_null(self.inner) {
157 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
161 /// Frees any resources used by the IgnoringMessageHandler, if is_owned is set and inner is non-NULL.
163 pub extern "C" fn IgnoringMessageHandler_free(this_obj: IgnoringMessageHandler) { }
165 /// Used only if an object of this type is returned as a trait impl by a method
166 pub(crate) extern "C" fn IgnoringMessageHandler_free_void(this_ptr: *mut c_void) {
167 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeIgnoringMessageHandler) };
170 impl IgnoringMessageHandler {
171 pub(crate) fn get_native_ref(&self) -> &'static nativeIgnoringMessageHandler {
172 unsafe { &*ObjOps::untweak_ptr(self.inner) }
174 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeIgnoringMessageHandler {
175 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
177 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
178 pub(crate) fn take_inner(mut self) -> *mut nativeIgnoringMessageHandler {
179 assert!(self.is_owned);
180 let ret = ObjOps::untweak_ptr(self.inner);
181 self.inner = core::ptr::null_mut();
185 /// Constructs a new IgnoringMessageHandler given each field
188 pub extern "C" fn IgnoringMessageHandler_new() -> IgnoringMessageHandler {
189 IgnoringMessageHandler { inner: ObjOps::heap_alloc(nativeIgnoringMessageHandler {
192 impl From<nativeIgnoringMessageHandler> for crate::lightning::events::EventsProvider {
193 fn from(obj: nativeIgnoringMessageHandler) -> Self {
194 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
195 let mut ret = IgnoringMessageHandler_as_EventsProvider(&rust_obj);
196 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
197 core::mem::forget(rust_obj);
198 ret.free = Some(IgnoringMessageHandler_free_void);
202 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
203 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
205 pub extern "C" fn IgnoringMessageHandler_as_EventsProvider(this_arg: &IgnoringMessageHandler) -> crate::lightning::events::EventsProvider {
206 crate::lightning::events::EventsProvider {
207 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
209 process_pending_events: IgnoringMessageHandler_EventsProvider_process_pending_events,
213 extern "C" fn IgnoringMessageHandler_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::events::EventHandler) {
214 <nativeIgnoringMessageHandler as lightning::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, handler)
217 impl From<nativeIgnoringMessageHandler> for crate::lightning::events::MessageSendEventsProvider {
218 fn from(obj: nativeIgnoringMessageHandler) -> Self {
219 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
220 let mut ret = IgnoringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
221 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
222 core::mem::forget(rust_obj);
223 ret.free = Some(IgnoringMessageHandler_free_void);
227 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
228 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
230 pub extern "C" fn IgnoringMessageHandler_as_MessageSendEventsProvider(this_arg: &IgnoringMessageHandler) -> crate::lightning::events::MessageSendEventsProvider {
231 crate::lightning::events::MessageSendEventsProvider {
232 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
234 get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
239 extern "C" fn IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
240 let mut ret = <nativeIgnoringMessageHandler as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
241 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
245 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
246 fn from(obj: nativeIgnoringMessageHandler) -> Self {
247 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
248 let mut ret = IgnoringMessageHandler_as_RoutingMessageHandler(&rust_obj);
249 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
250 core::mem::forget(rust_obj);
251 ret.free = Some(IgnoringMessageHandler_free_void);
255 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
256 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
258 pub extern "C" fn IgnoringMessageHandler_as_RoutingMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
259 crate::lightning::ln::msgs::RoutingMessageHandler {
260 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
262 handle_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement,
263 handle_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement,
264 handle_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update,
265 get_next_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcement,
266 get_next_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcement,
267 peer_connected: IgnoringMessageHandler_RoutingMessageHandler_peer_connected,
268 handle_reply_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_channel_range,
269 handle_reply_short_channel_ids_end: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
270 handle_query_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_query_channel_range,
271 handle_query_short_channel_ids: IgnoringMessageHandler_RoutingMessageHandler_handle_query_short_channel_ids,
272 processing_queue_high: IgnoringMessageHandler_RoutingMessageHandler_processing_queue_high,
273 provided_node_features: IgnoringMessageHandler_RoutingMessageHandler_provided_node_features,
274 provided_init_features: IgnoringMessageHandler_RoutingMessageHandler_provided_init_features,
275 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
276 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
278 get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
284 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 {
285 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
286 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() };
290 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 {
291 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
292 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() };
296 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 {
297 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
298 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() };
302 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 {
303 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, starting_point);
304 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 }) };
308 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 {
309 let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) };
310 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, local_starting_point);
311 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 };
315 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 {
316 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);
317 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() };
321 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 {
322 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()) });
323 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() };
327 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 {
328 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()) });
329 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() };
333 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 {
334 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()) });
335 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() };
339 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 {
340 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()) });
341 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() };
345 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool {
346 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
350 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
351 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
352 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
355 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 {
356 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
357 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
360 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::OnionMessageHandler {
361 fn from(obj: nativeIgnoringMessageHandler) -> Self {
362 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
363 let mut ret = IgnoringMessageHandler_as_OnionMessageHandler(&rust_obj);
364 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
365 core::mem::forget(rust_obj);
366 ret.free = Some(IgnoringMessageHandler_free_void);
370 /// Constructs a new OnionMessageHandler which calls the relevant methods on this_arg.
371 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageHandler must be freed before this_arg is
373 pub extern "C" fn IgnoringMessageHandler_as_OnionMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::msgs::OnionMessageHandler {
374 crate::lightning::ln::msgs::OnionMessageHandler {
375 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
377 get_and_clear_connections_needed: IgnoringMessageHandler_OnionMessageHandler_get_and_clear_connections_needed,
378 handle_onion_message: IgnoringMessageHandler_OnionMessageHandler_handle_onion_message,
379 next_onion_message_for_peer: IgnoringMessageHandler_OnionMessageHandler_next_onion_message_for_peer,
380 peer_connected: IgnoringMessageHandler_OnionMessageHandler_peer_connected,
381 peer_disconnected: IgnoringMessageHandler_OnionMessageHandler_peer_disconnected,
382 timer_tick_occurred: IgnoringMessageHandler_OnionMessageHandler_timer_tick_occurred,
383 provided_node_features: IgnoringMessageHandler_OnionMessageHandler_provided_node_features,
384 provided_init_features: IgnoringMessageHandler_OnionMessageHandler_provided_init_features,
389 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_get_and_clear_connections_needed(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyCVec_SocketAddressZZZ {
390 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::get_and_clear_connections_needed(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
391 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 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; let mut local_ret_0 = (crate::c_types::PublicKey::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }); };
394 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) {
395 <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())
398 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_next_onion_message_for_peer(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage {
399 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::next_onion_message_for_peer(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, peer_node_id.into_rust());
400 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 };
404 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 {
405 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);
406 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() };
409 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
410 <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust())
412 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_timer_tick_occurred(this_arg: *const c_void) {
413 <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::timer_tick_occurred(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, )
416 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
417 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
418 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
421 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 {
422 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
423 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
426 impl From<nativeIgnoringMessageHandler> for crate::lightning::onion_message::offers::OffersMessageHandler {
427 fn from(obj: nativeIgnoringMessageHandler) -> Self {
428 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
429 let mut ret = IgnoringMessageHandler_as_OffersMessageHandler(&rust_obj);
430 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
431 core::mem::forget(rust_obj);
432 ret.free = Some(IgnoringMessageHandler_free_void);
436 /// Constructs a new OffersMessageHandler which calls the relevant methods on this_arg.
437 /// This copies the `inner` pointer in this_arg and thus the returned OffersMessageHandler must be freed before this_arg is
439 pub extern "C" fn IgnoringMessageHandler_as_OffersMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::onion_message::offers::OffersMessageHandler {
440 crate::lightning::onion_message::offers::OffersMessageHandler {
441 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
443 handle_message: IgnoringMessageHandler_OffersMessageHandler_handle_message,
444 release_pending_messages: IgnoringMessageHandler_OffersMessageHandler_release_pending_messages,
449 extern "C" fn IgnoringMessageHandler_OffersMessageHandler_handle_message(this_arg: *const c_void, mut message: crate::lightning::onion_message::offers::OffersMessage) -> crate::c_types::derived::COption_OffersMessageZ {
450 let mut ret = <nativeIgnoringMessageHandler as lightning::onion_message::offers::OffersMessageHandler<>>::handle_message(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, message.into_native());
451 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_OffersMessageZ::None } else { crate::c_types::derived::COption_OffersMessageZ::Some( { crate::lightning::onion_message::offers::OffersMessage::native_into(ret.unwrap()) }) };
455 extern "C" fn IgnoringMessageHandler_OffersMessageHandler_release_pending_messages(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OffersMessageDestinationBlindedPathZZ {
456 let mut ret = <nativeIgnoringMessageHandler as lightning::onion_message::offers::OffersMessageHandler<>>::release_pending_messages(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
457 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_2 = crate::lightning::blinded_path::BlindedPath { 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::onion_message::offers::OffersMessage::native_into(orig_ret_0_0), crate::lightning::onion_message::messenger::Destination::native_into(orig_ret_0_1), local_orig_ret_0_2).into(); local_ret_0 }); };
461 impl From<nativeIgnoringMessageHandler> for crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
462 fn from(obj: nativeIgnoringMessageHandler) -> Self {
463 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
464 let mut ret = IgnoringMessageHandler_as_CustomOnionMessageHandler(&rust_obj);
465 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
466 core::mem::forget(rust_obj);
467 ret.free = Some(IgnoringMessageHandler_free_void);
471 /// Constructs a new CustomOnionMessageHandler which calls the relevant methods on this_arg.
472 /// This copies the `inner` pointer in this_arg and thus the returned CustomOnionMessageHandler must be freed before this_arg is
474 pub extern "C" fn IgnoringMessageHandler_as_CustomOnionMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
475 crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
476 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
478 handle_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message,
479 read_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_read_custom_message,
480 release_pending_custom_messages: IgnoringMessageHandler_CustomOnionMessageHandler_release_pending_custom_messages,
485 extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message(this_arg: *const c_void, mut msg: crate::lightning::onion_message::packet::OnionMessageContents) -> crate::c_types::derived::COption_OnionMessageContentsZ {
489 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_OnionMessageContentsZDecodeErrorZ {
490 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());
491 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_OnionMessageContentsZ::None } else { crate::c_types::derived::COption_OnionMessageContentsZ::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() };
495 extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_release_pending_custom_messages(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OnionMessageContentsDestinationBlindedPathZZ {
496 let mut ret = <nativeIgnoringMessageHandler as lightning::onion_message::messenger::CustomOnionMessageHandler<>>::release_pending_custom_messages(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
497 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_2 = crate::lightning::blinded_path::BlindedPath { 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 = (Into::into(orig_ret_0_0), crate::lightning::onion_message::messenger::Destination::native_into(orig_ret_0_1), local_orig_ret_0_2).into(); local_ret_0 }); };
501 impl From<nativeInfallible> for crate::lightning::onion_message::packet::OnionMessageContents {
502 fn from(obj: nativeInfallible) -> Self {
506 impl From<nativeInfallible> for crate::lightning::ln::wire::Type {
507 fn from(obj: nativeInfallible) -> Self {
511 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::wire::CustomMessageReader {
512 fn from(obj: nativeIgnoringMessageHandler) -> Self {
513 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
514 let mut ret = IgnoringMessageHandler_as_CustomMessageReader(&rust_obj);
515 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
516 core::mem::forget(rust_obj);
517 ret.free = Some(IgnoringMessageHandler_free_void);
521 /// Constructs a new CustomMessageReader which calls the relevant methods on this_arg.
522 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageReader must be freed before this_arg is
524 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageReader(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::wire::CustomMessageReader {
525 crate::lightning::ln::wire::CustomMessageReader {
526 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
528 read: IgnoringMessageHandler_CustomMessageReader_read,
533 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 {
534 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::wire::CustomMessageReader<>>::read(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, message_type, &mut buffer.to_reader());
535 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() };
539 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::peer_handler::CustomMessageHandler {
540 fn from(obj: nativeIgnoringMessageHandler) -> Self {
541 let rust_obj = crate::lightning::ln::peer_handler::IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
542 let mut ret = IgnoringMessageHandler_as_CustomMessageHandler(&rust_obj);
543 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
544 core::mem::forget(rust_obj);
545 ret.free = Some(IgnoringMessageHandler_free_void);
549 /// Constructs a new CustomMessageHandler which calls the relevant methods on this_arg.
550 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageHandler must be freed before this_arg is
552 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::peer_handler::CustomMessageHandler {
553 crate::lightning::ln::peer_handler::CustomMessageHandler {
554 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
556 handle_custom_message: IgnoringMessageHandler_CustomMessageHandler_handle_custom_message,
557 get_and_clear_pending_msg: IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg,
558 provided_node_features: IgnoringMessageHandler_CustomMessageHandler_provided_node_features,
559 provided_init_features: IgnoringMessageHandler_CustomMessageHandler_provided_init_features,
560 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader {
561 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
563 read: IgnoringMessageHandler_CustomMessageReader_read,
569 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 {
573 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ {
574 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::get_and_clear_pending_msg(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
575 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 }); };
579 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
580 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
581 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
584 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_provided_init_features(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures {
585 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
586 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
590 use lightning::ln::peer_handler::ErroringMessageHandler as nativeErroringMessageHandlerImport;
591 pub(crate) type nativeErroringMessageHandler = nativeErroringMessageHandlerImport;
593 /// A dummy struct which implements `ChannelMessageHandler` without having any channels.
594 /// You can provide one of these as the route_handler in a MessageHandler.
597 pub struct ErroringMessageHandler {
598 /// A pointer to the opaque Rust object.
600 /// Nearly everywhere, inner must be non-null, however in places where
601 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
602 pub inner: *mut nativeErroringMessageHandler,
603 /// Indicates that this is the only struct which contains the same pointer.
605 /// Rust functions which take ownership of an object provided via an argument require
606 /// this to be true and invalidate the object pointed to by inner.
610 impl Drop for ErroringMessageHandler {
612 if self.is_owned && !<*mut nativeErroringMessageHandler>::is_null(self.inner) {
613 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
617 /// Frees any resources used by the ErroringMessageHandler, if is_owned is set and inner is non-NULL.
619 pub extern "C" fn ErroringMessageHandler_free(this_obj: ErroringMessageHandler) { }
621 /// Used only if an object of this type is returned as a trait impl by a method
622 pub(crate) extern "C" fn ErroringMessageHandler_free_void(this_ptr: *mut c_void) {
623 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeErroringMessageHandler) };
626 impl ErroringMessageHandler {
627 pub(crate) fn get_native_ref(&self) -> &'static nativeErroringMessageHandler {
628 unsafe { &*ObjOps::untweak_ptr(self.inner) }
630 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeErroringMessageHandler {
631 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
633 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
634 pub(crate) fn take_inner(mut self) -> *mut nativeErroringMessageHandler {
635 assert!(self.is_owned);
636 let ret = ObjOps::untweak_ptr(self.inner);
637 self.inner = core::ptr::null_mut();
641 /// Constructs a new ErroringMessageHandler
644 pub extern "C" fn ErroringMessageHandler_new() -> crate::lightning::ln::peer_handler::ErroringMessageHandler {
645 let mut ret = lightning::ln::peer_handler::ErroringMessageHandler::new();
646 crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
649 impl From<nativeErroringMessageHandler> for crate::lightning::events::MessageSendEventsProvider {
650 fn from(obj: nativeErroringMessageHandler) -> Self {
651 let rust_obj = crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
652 let mut ret = ErroringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
653 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
654 core::mem::forget(rust_obj);
655 ret.free = Some(ErroringMessageHandler_free_void);
659 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
660 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
662 pub extern "C" fn ErroringMessageHandler_as_MessageSendEventsProvider(this_arg: &ErroringMessageHandler) -> crate::lightning::events::MessageSendEventsProvider {
663 crate::lightning::events::MessageSendEventsProvider {
664 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
666 get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
671 extern "C" fn ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
672 let mut ret = <nativeErroringMessageHandler as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
673 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
677 impl From<nativeErroringMessageHandler> for crate::lightning::ln::msgs::ChannelMessageHandler {
678 fn from(obj: nativeErroringMessageHandler) -> Self {
679 let rust_obj = crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
680 let mut ret = ErroringMessageHandler_as_ChannelMessageHandler(&rust_obj);
681 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
682 core::mem::forget(rust_obj);
683 ret.free = Some(ErroringMessageHandler_free_void);
687 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
688 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
690 pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &ErroringMessageHandler) -> crate::lightning::ln::msgs::ChannelMessageHandler {
691 crate::lightning::ln::msgs::ChannelMessageHandler {
692 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
694 handle_open_channel: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel,
695 handle_open_channel_v2: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel_v2,
696 handle_accept_channel: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel,
697 handle_accept_channel_v2: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel_v2,
698 handle_funding_created: ErroringMessageHandler_ChannelMessageHandler_handle_funding_created,
699 handle_funding_signed: ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed,
700 handle_channel_ready: ErroringMessageHandler_ChannelMessageHandler_handle_channel_ready,
701 handle_shutdown: ErroringMessageHandler_ChannelMessageHandler_handle_shutdown,
702 handle_closing_signed: ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed,
703 handle_stfu: ErroringMessageHandler_ChannelMessageHandler_handle_stfu,
704 handle_splice: ErroringMessageHandler_ChannelMessageHandler_handle_splice,
705 handle_splice_ack: ErroringMessageHandler_ChannelMessageHandler_handle_splice_ack,
706 handle_splice_locked: ErroringMessageHandler_ChannelMessageHandler_handle_splice_locked,
707 handle_tx_add_input: ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_input,
708 handle_tx_add_output: ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_output,
709 handle_tx_remove_input: ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_input,
710 handle_tx_remove_output: ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_output,
711 handle_tx_complete: ErroringMessageHandler_ChannelMessageHandler_handle_tx_complete,
712 handle_tx_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_tx_signatures,
713 handle_tx_init_rbf: ErroringMessageHandler_ChannelMessageHandler_handle_tx_init_rbf,
714 handle_tx_ack_rbf: ErroringMessageHandler_ChannelMessageHandler_handle_tx_ack_rbf,
715 handle_tx_abort: ErroringMessageHandler_ChannelMessageHandler_handle_tx_abort,
716 handle_update_add_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc,
717 handle_update_fulfill_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc,
718 handle_update_fail_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc,
719 handle_update_fail_malformed_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_malformed_htlc,
720 handle_commitment_signed: ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed,
721 handle_revoke_and_ack: ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack,
722 handle_update_fee: ErroringMessageHandler_ChannelMessageHandler_handle_update_fee,
723 handle_announcement_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures,
724 peer_disconnected: ErroringMessageHandler_ChannelMessageHandler_peer_disconnected,
725 peer_connected: ErroringMessageHandler_ChannelMessageHandler_peer_connected,
726 handle_channel_reestablish: ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish,
727 handle_channel_update: ErroringMessageHandler_ChannelMessageHandler_handle_channel_update,
728 handle_error: ErroringMessageHandler_ChannelMessageHandler_handle_error,
729 provided_node_features: ErroringMessageHandler_ChannelMessageHandler_provided_node_features,
730 provided_init_features: ErroringMessageHandler_ChannelMessageHandler_provided_init_features,
731 get_chain_hashes: ErroringMessageHandler_ChannelMessageHandler_get_chain_hashes,
732 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
733 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
735 get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
740 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) {
741 <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())
743 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_open_channel_v2(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OpenChannelV2) {
744 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_open_channel_v2(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
746 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) {
747 <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())
749 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel_v2(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::AcceptChannelV2) {
750 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_accept_channel_v2(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
752 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) {
753 <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())
755 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) {
756 <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())
758 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) {
759 <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())
761 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) {
762 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
764 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) {
765 <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())
767 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_stfu(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Stfu) {
768 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_stfu(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
770 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_splice(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Splice) {
771 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_splice(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
773 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_splice_ack(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::SpliceAck) {
774 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_splice_ack(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
776 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_splice_locked(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::SpliceLocked) {
777 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_splice_locked(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
779 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_input(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAddInput) {
780 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_add_input(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
782 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_output(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAddOutput) {
783 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_add_output(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
785 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_input(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxRemoveInput) {
786 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_remove_input(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
788 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_output(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxRemoveOutput) {
789 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_remove_output(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
791 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_complete(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxComplete) {
792 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_complete(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
794 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_signatures(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxSignatures) {
795 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_signatures(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
797 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_init_rbf(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxInitRbf) {
798 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_init_rbf(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
800 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_ack_rbf(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAckRbf) {
801 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_ack_rbf(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
803 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_tx_abort(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAbort) {
804 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_tx_abort(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
806 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) {
807 <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())
809 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) {
810 <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())
812 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) {
813 <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())
815 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) {
816 <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())
818 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) {
819 <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())
821 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) {
822 <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())
824 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) {
825 <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())
827 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) {
828 <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())
830 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
831 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust())
834 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 {
835 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);
836 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() };
839 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) {
840 <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())
842 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) {
843 <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())
845 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) {
846 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
849 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
850 let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
851 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
854 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 {
855 let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust());
856 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
859 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_get_chain_hashes(this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
860 let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::get_chain_hashes(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
861 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::None } else { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::c_types::ThirtyTwoBytes { data: *item.as_ref() } }); }; local_ret_0.into() }) };
866 use lightning::ln::peer_handler::MessageHandler as nativeMessageHandlerImport;
867 pub(crate) type nativeMessageHandler = nativeMessageHandlerImport<crate::lightning::ln::msgs::ChannelMessageHandler, crate::lightning::ln::msgs::RoutingMessageHandler, crate::lightning::ln::msgs::OnionMessageHandler, crate::lightning::ln::peer_handler::CustomMessageHandler>;
869 /// Provides references to trait impls which handle different types of messages.
872 pub struct MessageHandler {
873 /// A pointer to the opaque Rust object.
875 /// Nearly everywhere, inner must be non-null, however in places where
876 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
877 pub inner: *mut nativeMessageHandler,
878 /// Indicates that this is the only struct which contains the same pointer.
880 /// Rust functions which take ownership of an object provided via an argument require
881 /// this to be true and invalidate the object pointed to by inner.
885 impl Drop for MessageHandler {
887 if self.is_owned && !<*mut nativeMessageHandler>::is_null(self.inner) {
888 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
892 /// Frees any resources used by the MessageHandler, if is_owned is set and inner is non-NULL.
894 pub extern "C" fn MessageHandler_free(this_obj: MessageHandler) { }
896 /// Used only if an object of this type is returned as a trait impl by a method
897 pub(crate) extern "C" fn MessageHandler_free_void(this_ptr: *mut c_void) {
898 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMessageHandler) };
901 impl MessageHandler {
902 pub(crate) fn get_native_ref(&self) -> &'static nativeMessageHandler {
903 unsafe { &*ObjOps::untweak_ptr(self.inner) }
905 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMessageHandler {
906 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
908 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
909 pub(crate) fn take_inner(mut self) -> *mut nativeMessageHandler {
910 assert!(self.is_owned);
911 let ret = ObjOps::untweak_ptr(self.inner);
912 self.inner = core::ptr::null_mut();
916 /// A message handler which handles messages specific to channels. Usually this is just a
917 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
919 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
921 pub extern "C" fn MessageHandler_get_chan_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::ChannelMessageHandler {
922 let mut inner_val = &mut this_ptr.get_native_mut_ref().chan_handler;
925 /// A message handler which handles messages specific to channels. Usually this is just a
926 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
928 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
930 pub extern "C" fn MessageHandler_set_chan_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::ChannelMessageHandler) {
931 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chan_handler = val;
933 /// A message handler which handles messages updating our knowledge of the network channel
934 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
936 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
938 pub extern "C" fn MessageHandler_get_route_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::RoutingMessageHandler {
939 let mut inner_val = &mut this_ptr.get_native_mut_ref().route_handler;
942 /// A message handler which handles messages updating our knowledge of the network channel
943 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
945 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
947 pub extern "C" fn MessageHandler_set_route_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::RoutingMessageHandler) {
948 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_handler = val;
950 /// A message handler which handles onion messages. This should generally be an
951 /// [`OnionMessenger`], but can also be an [`IgnoringMessageHandler`].
953 /// [`OnionMessenger`]: crate::onion_message::messenger::OnionMessenger
955 pub extern "C" fn MessageHandler_get_onion_message_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::OnionMessageHandler {
956 let mut inner_val = &mut this_ptr.get_native_mut_ref().onion_message_handler;
959 /// A message handler which handles onion messages. This should generally be an
960 /// [`OnionMessenger`], but can also be an [`IgnoringMessageHandler`].
962 /// [`OnionMessenger`]: crate::onion_message::messenger::OnionMessenger
964 pub extern "C" fn MessageHandler_set_onion_message_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::OnionMessageHandler) {
965 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.onion_message_handler = val;
967 /// A message handler which handles custom messages. The only LDK-provided implementation is
968 /// [`IgnoringMessageHandler`].
970 pub extern "C" fn MessageHandler_get_custom_message_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::peer_handler::CustomMessageHandler {
971 let mut inner_val = &mut this_ptr.get_native_mut_ref().custom_message_handler;
974 /// A message handler which handles custom messages. The only LDK-provided implementation is
975 /// [`IgnoringMessageHandler`].
977 pub extern "C" fn MessageHandler_set_custom_message_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::peer_handler::CustomMessageHandler) {
978 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.custom_message_handler = val;
980 /// Constructs a new MessageHandler given each field
983 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, mut custom_message_handler_arg: crate::lightning::ln::peer_handler::CustomMessageHandler) -> MessageHandler {
984 MessageHandler { inner: ObjOps::heap_alloc(nativeMessageHandler {
985 chan_handler: chan_handler_arg,
986 route_handler: route_handler_arg,
987 onion_message_handler: onion_message_handler_arg,
988 custom_message_handler: custom_message_handler_arg,
991 /// Provides an object which can be used to send data to and which uniquely identifies a connection
992 /// to a remote host. You will need to be able to generate multiple of these which meet Eq and
993 /// implement Hash to meet the PeerManager API.
995 /// For efficiency, [`Clone`] should be relatively cheap for this type.
997 /// Two descriptors may compare equal (by [`cmp::Eq`] and [`hash::Hash`]) as long as the original
998 /// has been disconnected, the [`PeerManager`] has been informed of the disconnection (either by it
999 /// having triggered the disconnection or a call to [`PeerManager::socket_disconnected`]), and no
1000 /// further calls to the [`PeerManager`] related to the original socket occur. This allows you to
1001 /// use a file descriptor for your SocketDescriptor directly, however for simplicity you may wish
1002 /// to simply use another value which is guaranteed to be globally unique instead.
1004 pub struct SocketDescriptor {
1005 /// An opaque pointer which is passed to your function implementations as an argument.
1006 /// This has no meaning in the LDK, and can be NULL or any other value.
1007 pub this_arg: *mut c_void,
1008 /// Attempts to send some data from the given slice to the peer.
1010 /// Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
1011 /// Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
1012 /// called and further write attempts may occur until that time.
1014 /// If the returned size is smaller than `data.len()`, a
1015 /// [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
1016 /// written. Additionally, until a `send_data` event completes fully, no further
1017 /// [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
1018 /// prevent denial-of-service issues, you should not read or buffer any data from the socket
1021 /// If a [`PeerManager::read_event`] call on this descriptor had previously returned true
1022 /// (indicating that read events should be paused to prevent DoS in the send buffer),
1023 /// `resume_read` may be set indicating that read events on this descriptor should resume. A
1024 /// `resume_read` of false carries no meaning, and should not cause any action.
1025 pub send_data: extern "C" fn (this_arg: *mut c_void, data: crate::c_types::u8slice, resume_read: bool) -> usize,
1026 /// Disconnect the socket pointed to by this SocketDescriptor.
1028 /// You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
1029 /// call (doing so is a noop).
1030 pub disconnect_socket: extern "C" fn (this_arg: *mut c_void),
1031 /// Checks if two objects are equal given this object's this_arg pointer and another object.
1032 pub eq: extern "C" fn (this_arg: *const c_void, other_arg: &SocketDescriptor) -> bool,
1033 /// Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.
1034 /// This is used, for example, for inclusion of this object in a hash map.
1035 pub hash: extern "C" fn (this_arg: *const c_void) -> u64,
1036 /// Called, if set, after this SocketDescriptor has been cloned into a duplicate object.
1037 /// The new SocketDescriptor is provided, and should be mutated as needed to perform a
1038 /// deep copy of the object pointed to by this_arg or avoid any double-freeing.
1039 pub cloned: Option<extern "C" fn (new_SocketDescriptor: &mut SocketDescriptor)>,
1040 /// Frees any resources associated with this object given its this_arg pointer.
1041 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1042 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1044 unsafe impl Send for SocketDescriptor {}
1045 unsafe impl Sync for SocketDescriptor {}
1047 pub(crate) fn SocketDescriptor_clone_fields(orig: &SocketDescriptor) -> SocketDescriptor {
1049 this_arg: orig.this_arg,
1050 send_data: Clone::clone(&orig.send_data),
1051 disconnect_socket: Clone::clone(&orig.disconnect_socket),
1052 eq: Clone::clone(&orig.eq),
1053 hash: Clone::clone(&orig.hash),
1054 cloned: Clone::clone(&orig.cloned),
1055 free: Clone::clone(&orig.free),
1058 impl core::cmp::Eq for SocketDescriptor {}
1059 impl core::cmp::PartialEq for SocketDescriptor {
1060 fn eq(&self, o: &Self) -> bool { (self.eq)(self.this_arg, o) }
1062 impl core::hash::Hash for SocketDescriptor {
1063 fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) { hasher.write_u64((self.hash)(self.this_arg)) }
1066 /// Creates a copy of a SocketDescriptor
1067 pub extern "C" fn SocketDescriptor_clone(orig: &SocketDescriptor) -> SocketDescriptor {
1068 let mut res = SocketDescriptor_clone_fields(orig);
1069 if let Some(f) = orig.cloned { (f)(&mut res) };
1072 impl Clone for SocketDescriptor {
1073 fn clone(&self) -> Self {
1074 SocketDescriptor_clone(self)
1078 use lightning::ln::peer_handler::SocketDescriptor as rustSocketDescriptor;
1079 impl rustSocketDescriptor for SocketDescriptor {
1080 fn send_data(&mut self, mut data: &[u8], mut resume_read: bool) -> usize {
1081 let mut local_data = crate::c_types::u8slice::from_slice(data);
1082 let mut ret = (self.send_data)(self.this_arg, local_data, resume_read);
1085 fn disconnect_socket(&mut self) {
1086 (self.disconnect_socket)(self.this_arg)
1090 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1091 // directly as a Deref trait in higher-level structs:
1092 impl core::ops::Deref for SocketDescriptor {
1094 fn deref(&self) -> &Self {
1098 impl core::ops::DerefMut for SocketDescriptor {
1099 fn deref_mut(&mut self) -> &mut Self {
1103 /// Calls the free function if one is set
1105 pub extern "C" fn SocketDescriptor_free(this_ptr: SocketDescriptor) { }
1106 impl Drop for SocketDescriptor {
1107 fn drop(&mut self) {
1108 if let Some(f) = self.free {
1114 use lightning::ln::peer_handler::PeerHandleError as nativePeerHandleErrorImport;
1115 pub(crate) type nativePeerHandleError = nativePeerHandleErrorImport;
1117 /// Error for PeerManager errors. If you get one of these, you must disconnect the socket and
1118 /// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the
1122 pub struct PeerHandleError {
1123 /// A pointer to the opaque Rust object.
1125 /// Nearly everywhere, inner must be non-null, however in places where
1126 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1127 pub inner: *mut nativePeerHandleError,
1128 /// Indicates that this is the only struct which contains the same pointer.
1130 /// Rust functions which take ownership of an object provided via an argument require
1131 /// this to be true and invalidate the object pointed to by inner.
1135 impl Drop for PeerHandleError {
1136 fn drop(&mut self) {
1137 if self.is_owned && !<*mut nativePeerHandleError>::is_null(self.inner) {
1138 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1142 /// Frees any resources used by the PeerHandleError, if is_owned is set and inner is non-NULL.
1144 pub extern "C" fn PeerHandleError_free(this_obj: PeerHandleError) { }
1146 /// Used only if an object of this type is returned as a trait impl by a method
1147 pub(crate) extern "C" fn PeerHandleError_free_void(this_ptr: *mut c_void) {
1148 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePeerHandleError) };
1151 impl PeerHandleError {
1152 pub(crate) fn get_native_ref(&self) -> &'static nativePeerHandleError {
1153 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1155 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerHandleError {
1156 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1158 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1159 pub(crate) fn take_inner(mut self) -> *mut nativePeerHandleError {
1160 assert!(self.is_owned);
1161 let ret = ObjOps::untweak_ptr(self.inner);
1162 self.inner = core::ptr::null_mut();
1166 /// Constructs a new PeerHandleError given each field
1169 pub extern "C" fn PeerHandleError_new() -> PeerHandleError {
1170 PeerHandleError { inner: ObjOps::heap_alloc(nativePeerHandleError {
1171 }), is_owned: true }
1173 impl Clone for PeerHandleError {
1174 fn clone(&self) -> Self {
1176 inner: if <*mut nativePeerHandleError>::is_null(self.inner) { core::ptr::null_mut() } else {
1177 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1183 /// Used only if an object of this type is returned as a trait impl by a method
1184 pub(crate) extern "C" fn PeerHandleError_clone_void(this_ptr: *const c_void) -> *mut c_void {
1185 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePeerHandleError)).clone() })) as *mut c_void
1188 /// Creates a copy of the PeerHandleError
1189 pub extern "C" fn PeerHandleError_clone(orig: &PeerHandleError) -> PeerHandleError {
1192 /// Get a string which allows debug introspection of a PeerHandleError object
1193 pub extern "C" fn PeerHandleError_debug_str_void(o: *const c_void) -> Str {
1194 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::peer_handler::PeerHandleError }).into()}
1196 use lightning::ln::peer_handler::PeerManager as nativePeerManagerImport;
1197 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::sign::NodeSigner>;
1199 /// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
1200 /// socket events into messages which it passes on to its [`MessageHandler`].
1202 /// Locks are taken internally, so you must never assume that reentrancy from a
1203 /// [`SocketDescriptor`] call back into [`PeerManager`] methods will not deadlock.
1205 /// Calls to [`read_event`] will decode relevant messages and pass them to the
1206 /// [`ChannelMessageHandler`], likely doing message processing in-line. Thus, the primary form of
1207 /// parallelism in Rust-Lightning is in calls to [`read_event`]. Note, however, that calls to any
1208 /// [`PeerManager`] functions related to the same connection must occur only in serial, making new
1209 /// calls only after previous ones have returned.
1211 /// Rather than using a plain [`PeerManager`], it is preferable to use either a [`SimpleArcPeerManager`]
1212 /// a [`SimpleRefPeerManager`], for conciseness. See their documentation for more details, but
1213 /// essentially you should default to using a [`SimpleRefPeerManager`], and use a
1214 /// [`SimpleArcPeerManager`] when you require a `PeerManager` with a static lifetime, such as when
1215 /// you're using lightning-net-tokio.
1217 /// [`read_event`]: PeerManager::read_event
1220 pub struct PeerManager {
1221 /// A pointer to the opaque Rust object.
1223 /// Nearly everywhere, inner must be non-null, however in places where
1224 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1225 pub inner: *mut nativePeerManager,
1226 /// Indicates that this is the only struct which contains the same pointer.
1228 /// Rust functions which take ownership of an object provided via an argument require
1229 /// this to be true and invalidate the object pointed to by inner.
1233 impl Drop for PeerManager {
1234 fn drop(&mut self) {
1235 if self.is_owned && !<*mut nativePeerManager>::is_null(self.inner) {
1236 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1240 /// Frees any resources used by the PeerManager, if is_owned is set and inner is non-NULL.
1242 pub extern "C" fn PeerManager_free(this_obj: PeerManager) { }
1244 /// Used only if an object of this type is returned as a trait impl by a method
1245 pub(crate) extern "C" fn PeerManager_free_void(this_ptr: *mut c_void) {
1246 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePeerManager) };
1250 pub(crate) fn get_native_ref(&self) -> &'static nativePeerManager {
1251 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1253 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerManager {
1254 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1256 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1257 pub(crate) fn take_inner(mut self) -> *mut nativePeerManager {
1258 assert!(self.is_owned);
1259 let ret = ObjOps::untweak_ptr(self.inner);
1260 self.inner = core::ptr::null_mut();
1264 /// Constructs a new `PeerManager` with the given message handlers.
1266 /// `ephemeral_random_data` is used to derive per-connection ephemeral keys and must be
1267 /// cryptographically secure random bytes.
1269 /// `current_time` is used as an always-increasing counter that survives across restarts and is
1270 /// incremented irregularly internally. In general it is best to simply use the current UNIX
1271 /// timestamp, however if it is not available a persistent counter that increases once per
1272 /// minute should suffice.
1275 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 node_signer: crate::lightning::sign::NodeSigner) -> crate::lightning::ln::peer_handler::PeerManager {
1276 let mut ret = lightning::ln::peer_handler::PeerManager::new(*unsafe { Box::from_raw(message_handler.take_inner()) }, current_time, unsafe { &*ephemeral_random_data}, logger, node_signer);
1277 crate::lightning::ln::peer_handler::PeerManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1280 /// Get a list of tuples mapping from node id to network addresses for peers which have
1281 /// completed the initial handshake.
1283 /// For outbound connections, the [`PublicKey`] will be the same as the `their_node_id` parameter
1284 /// passed in to [`Self::new_outbound_connection`], however entries will only appear once the initial
1285 /// handshake has completed and we are sure the remote peer has the private key for the given
1288 /// The returned `Option`s will only be `Some` if an address had been previously given via
1289 /// [`Self::new_outbound_connection`] or [`Self::new_inbound_connection`].
1292 pub extern "C" fn PeerManager_get_peer_node_ids(this_arg: &crate::lightning::ln::peer_handler::PeerManager) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyCOption_SocketAddressZZZ {
1293 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_peer_node_ids();
1294 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_SocketAddressZ::None } else { crate::c_types::derived::COption_SocketAddressZ::Some( { crate::lightning::ln::msgs::SocketAddress::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 }); };
1298 /// Indicates a new outbound connection has been established to a node with the given `node_id`
1299 /// and an optional remote network address.
1301 /// The remote network address adds the option to report a remote IP address back to a connecting
1302 /// peer using the init message.
1303 /// The user should pass the remote network address of the host they are connected to.
1305 /// If an `Err` is returned here you must disconnect the connection immediately.
1307 /// Returns a small number of bytes to send to the remote node (currently always 50).
1309 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
1310 /// [`socket_disconnected`].
1312 /// [`socket_disconnected`]: PeerManager::socket_disconnected
1315 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_SocketAddressZ) -> crate::c_types::derived::CResult_CVec_u8ZPeerHandleErrorZ {
1316 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() }})} };
1317 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_outbound_connection(their_node_id.into_rust(), descriptor, local_remote_network_address);
1318 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() };
1322 /// Indicates a new inbound connection has been established to a node with an optional remote
1323 /// network address.
1325 /// The remote network address adds the option to report a remote IP address back to a connecting
1326 /// peer using the init message.
1327 /// The user should pass the remote network address of the host they are connected to.
1329 /// May refuse the connection by returning an Err, but will never write bytes to the remote end
1330 /// (outbound connector always speaks first). If an `Err` is returned here you must disconnect
1331 /// the connection immediately.
1333 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
1334 /// [`socket_disconnected`].
1336 /// [`socket_disconnected`]: PeerManager::socket_disconnected
1339 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_SocketAddressZ) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ {
1340 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() }})} };
1341 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_inbound_connection(descriptor, local_remote_network_address);
1342 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() };
1346 /// Indicates that there is room to write data to the given socket descriptor.
1348 /// May return an Err to indicate that the connection should be closed.
1350 /// May call [`send_data`] on the descriptor passed in (or an equal descriptor) before
1351 /// returning. Thus, be very careful with reentrancy issues! The invariants around calling
1352 /// [`write_buffer_space_avail`] in case a write did not fully complete must still hold - be
1353 /// ready to call [`write_buffer_space_avail`] again if a write call generated here isn't
1356 /// [`send_data`]: SocketDescriptor::send_data
1357 /// [`write_buffer_space_avail`]: PeerManager::write_buffer_space_avail
1360 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 {
1361 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.write_buffer_space_avail(descriptor);
1362 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() };
1366 /// Indicates that data was read from the given socket descriptor.
1368 /// May return an Err to indicate that the connection should be closed.
1370 /// Will *not* call back into [`send_data`] on any descriptors to avoid reentrancy complexity.
1371 /// Thus, however, you should call [`process_events`] after any `read_event` to generate
1372 /// [`send_data`] calls to handle responses.
1374 /// If `Ok(true)` is returned, further read_events should not be triggered until a
1375 /// [`send_data`] call on this descriptor has `resume_read` set (preventing DoS issues in the
1378 /// In order to avoid processing too many messages at once per peer, `data` should be on the
1381 /// [`send_data`]: SocketDescriptor::send_data
1382 /// [`process_events`]: PeerManager::process_events
1385 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 {
1386 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_event(peer_descriptor, data.to_slice());
1387 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() };
1391 /// Checks for any events generated by our handlers and processes them. Includes sending most
1392 /// response messages as well as messages generated by calls to handler functions directly (eg
1393 /// functions like [`ChannelManager::process_pending_htlc_forwards`] or [`send_payment`]).
1395 /// May call [`send_data`] on [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1398 /// You don't have to call this function explicitly if you are using [`lightning-net-tokio`]
1399 /// or one of the other clients provided in our language bindings.
1401 /// Note that if there are any other calls to this function waiting on lock(s) this may return
1402 /// without doing any work. All available events that need handling will be handled before the
1403 /// other calls return.
1405 /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1406 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
1407 /// [`send_data`]: SocketDescriptor::send_data
1409 pub extern "C" fn PeerManager_process_events(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1410 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_events()
1413 /// Indicates that the given socket descriptor's connection is now closed.
1415 pub extern "C" fn PeerManager_socket_disconnected(this_arg: &crate::lightning::ln::peer_handler::PeerManager, descriptor: &crate::lightning::ln::peer_handler::SocketDescriptor) {
1416 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.socket_disconnected(descriptor)
1419 /// Disconnect a peer given its node id.
1421 /// If a peer is connected, this will call [`disconnect_socket`] on the descriptor for the
1422 /// peer. Thus, be very careful about reentrancy issues.
1424 /// [`disconnect_socket`]: SocketDescriptor::disconnect_socket
1426 pub extern "C" fn PeerManager_disconnect_by_node_id(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut node_id: crate::c_types::PublicKey) {
1427 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_by_node_id(node_id.into_rust())
1430 /// Disconnects all currently-connected peers. This is useful on platforms where there may be
1431 /// an indication that TCP sockets have stalled even if we weren't around to time them out
1432 /// using regular ping/pongs.
1434 pub extern "C" fn PeerManager_disconnect_all_peers(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1435 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_all_peers()
1438 /// Send pings to each peer and disconnect those which did not respond to the last round of
1441 /// This may be called on any timescale you want, however, roughly once every ten seconds is
1442 /// preferred. The call rate determines both how often we send a ping to our peers and how much
1443 /// time they have to respond before we disconnect them.
1445 /// May call [`send_data`] on all [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1448 /// [`send_data`]: SocketDescriptor::send_data
1450 pub extern "C" fn PeerManager_timer_tick_occurred(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1451 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1454 /// Generates a signed node_announcement from the given arguments, sending it to all connected
1455 /// peers. Note that peers will likely ignore this message unless we have at least one public
1456 /// channel which has at least six confirmations on-chain.
1458 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1459 /// node to humans. They carry no in-protocol meaning.
1461 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1462 /// accepts incoming connections. These will be included in the node_announcement, publicly
1463 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1464 /// addresses should likely contain only Tor Onion addresses.
1466 /// Panics if `addresses` is absurdly large (more than 100).
1468 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1470 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_SocketAddressZ) {
1471 let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1472 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1475 use core::convert::Infallible as nativeInfallible;