1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Top level peer message handling and socket handling logic lives here.
11 //! Instead of actually servicing sockets ourselves we require that you implement the
12 //! SocketDescriptor interface and use that to receive actions which you should perform on the
13 //! socket, and call into PeerManager with bytes read from the socket. The PeerManager will then
14 //! call into the provided message handlers (probably a ChannelManager and P2PGossipSync) with
15 //! messages they should handle, and encoding/sending response messages.
17 use alloc::str::FromStr;
18 use core::ffi::c_void;
19 use core::convert::Infallible;
20 use bitcoin::hashes::Hash;
21 use crate::c_types::*;
22 #[cfg(feature="no-std")]
23 use alloc::{vec::Vec, boxed::Box};
25 /// A handler provided to [`PeerManager`] for reading and handling custom messages.
27 /// [BOLT 1] specifies a custom message type range for use with experimental or application-specific
28 /// messages. `CustomMessageHandler` allows for user-defined handling of such types. See the
29 /// [`lightning_custom_message`] crate for tools useful in composing more than one custom handler.
31 /// [BOLT 1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
32 /// [`lightning_custom_message`]: https://docs.rs/lightning_custom_message/latest/lightning_custom_message
34 pub struct CustomMessageHandler {
35 /// An opaque pointer which is passed to your function implementations as an argument.
36 /// This has no meaning in the LDK, and can be NULL or any other value.
37 pub this_arg: *mut c_void,
38 /// Handles the given message sent from `sender_node_id`, possibly producing messages for
39 /// [`CustomMessageHandler::get_and_clear_pending_msg`] to return and thus for [`PeerManager`]
41 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,
42 /// Returns the list of pending messages that were generated by the handler, clearing the list
43 /// in the process. Each message is paired with the node id of the intended recipient. If no
44 /// connection to the node exists, then the message is simply not sent.
45 pub get_and_clear_pending_msg: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ,
46 /// Gets the node feature flags which this handler itself supports. All available handlers are
47 /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
48 /// which are broadcasted in our [`NodeAnnouncement`] message.
50 /// [`NodeAnnouncement`]: crate::ln::msgs::NodeAnnouncement
51 pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures,
52 /// Gets the init feature flags which should be sent to the given peer. All available handlers
53 /// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
54 /// which are sent in our [`Init`] message.
56 /// [`Init`]: crate::ln::msgs::Init
57 pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures,
58 /// Implementation of CustomMessageReader for this object.
59 pub CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader,
60 /// Frees any resources associated with this object given its this_arg pointer.
61 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
62 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
64 unsafe impl Send for CustomMessageHandler {}
65 unsafe impl Sync for CustomMessageHandler {}
67 pub(crate) extern "C" fn CustomMessageHandler_clone_fields(orig: &CustomMessageHandler) -> CustomMessageHandler {
68 CustomMessageHandler {
69 this_arg: orig.this_arg,
70 handle_custom_message: Clone::clone(&orig.handle_custom_message),
71 get_and_clear_pending_msg: Clone::clone(&orig.get_and_clear_pending_msg),
72 provided_node_features: Clone::clone(&orig.provided_node_features),
73 provided_init_features: Clone::clone(&orig.provided_init_features),
74 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader_clone_fields(&orig.CustomMessageReader),
75 free: Clone::clone(&orig.free),
78 impl lightning::ln::wire::CustomMessageReader for CustomMessageHandler {
79 type CustomMessage = crate::lightning::ln::wire::Type;
80 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> {
81 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)));
82 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() })};
87 use lightning::ln::peer_handler::CustomMessageHandler as rustCustomMessageHandler;
88 impl rustCustomMessageHandler for CustomMessageHandler {
89 fn handle_custom_message(&self, mut msg: crate::lightning::ln::wire::Type, mut sender_node_id: &bitcoin::secp256k1::PublicKey) -> Result<(), lightning::ln::msgs::LightningError> {
90 let mut ret = (self.handle_custom_message)(self.this_arg, Into::into(msg), crate::c_types::PublicKey::from_rust(&sender_node_id));
91 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()) } })};
94 fn get_and_clear_pending_msg(&self) -> Vec<(bitcoin::secp256k1::PublicKey, crate::lightning::ln::wire::Type)> {
95 let mut ret = (self.get_and_clear_pending_msg)(self.this_arg);
96 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 }); };
99 fn provided_node_features(&self) -> lightning::ln::features::NodeFeatures {
100 let mut ret = (self.provided_node_features)(self.this_arg);
101 *unsafe { Box::from_raw(ret.take_inner()) }
103 fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning::ln::features::InitFeatures {
104 let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id));
105 *unsafe { Box::from_raw(ret.take_inner()) }
109 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
110 // directly as a Deref trait in higher-level structs:
111 impl core::ops::Deref for CustomMessageHandler {
113 fn deref(&self) -> &Self {
117 /// Calls the free function if one is set
119 pub extern "C" fn CustomMessageHandler_free(this_ptr: CustomMessageHandler) { }
120 impl Drop for CustomMessageHandler {
122 if let Some(f) = self.free {
128 use lightning::ln::peer_handler::IgnoringMessageHandler as nativeIgnoringMessageHandlerImport;
129 pub(crate) type nativeIgnoringMessageHandler = nativeIgnoringMessageHandlerImport;
131 /// A dummy struct which implements `RoutingMessageHandler` without storing any routing information
132 /// or doing any processing. You can provide one of these as the route_handler in a MessageHandler.
135 pub struct IgnoringMessageHandler {
136 /// A pointer to the opaque Rust object.
138 /// Nearly everywhere, inner must be non-null, however in places where
139 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
140 pub inner: *mut nativeIgnoringMessageHandler,
141 /// Indicates that this is the only struct which contains the same pointer.
143 /// Rust functions which take ownership of an object provided via an argument require
144 /// this to be true and invalidate the object pointed to by inner.
148 impl Drop for IgnoringMessageHandler {
150 if self.is_owned && !<*mut nativeIgnoringMessageHandler>::is_null(self.inner) {
151 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
155 /// Frees any resources used by the IgnoringMessageHandler, if is_owned is set and inner is non-NULL.
157 pub extern "C" fn IgnoringMessageHandler_free(this_obj: IgnoringMessageHandler) { }
159 /// Used only if an object of this type is returned as a trait impl by a method
160 pub(crate) extern "C" fn IgnoringMessageHandler_free_void(this_ptr: *mut c_void) {
161 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeIgnoringMessageHandler) };
164 impl IgnoringMessageHandler {
165 pub(crate) fn get_native_ref(&self) -> &'static nativeIgnoringMessageHandler {
166 unsafe { &*ObjOps::untweak_ptr(self.inner) }
168 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeIgnoringMessageHandler {
169 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
171 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
172 pub(crate) fn take_inner(mut self) -> *mut nativeIgnoringMessageHandler {
173 assert!(self.is_owned);
174 let ret = ObjOps::untweak_ptr(self.inner);
175 self.inner = core::ptr::null_mut();
179 /// Constructs a new IgnoringMessageHandler given each field
182 pub extern "C" fn IgnoringMessageHandler_new() -> IgnoringMessageHandler {
183 IgnoringMessageHandler { inner: ObjOps::heap_alloc(nativeIgnoringMessageHandler {
186 impl From<nativeIgnoringMessageHandler> for crate::lightning::events::MessageSendEventsProvider {
187 fn from(obj: nativeIgnoringMessageHandler) -> Self {
188 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
189 let mut ret = IgnoringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
190 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
191 rust_obj.inner = core::ptr::null_mut();
192 ret.free = Some(IgnoringMessageHandler_free_void);
196 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
197 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
199 pub extern "C" fn IgnoringMessageHandler_as_MessageSendEventsProvider(this_arg: &IgnoringMessageHandler) -> crate::lightning::events::MessageSendEventsProvider {
200 crate::lightning::events::MessageSendEventsProvider {
201 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
203 get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
208 extern "C" fn IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
209 let mut ret = <nativeIgnoringMessageHandler as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
210 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
214 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
215 fn from(obj: nativeIgnoringMessageHandler) -> Self {
216 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
217 let mut ret = IgnoringMessageHandler_as_RoutingMessageHandler(&rust_obj);
218 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
219 rust_obj.inner = core::ptr::null_mut();
220 ret.free = Some(IgnoringMessageHandler_free_void);
224 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
225 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
227 pub extern "C" fn IgnoringMessageHandler_as_RoutingMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
228 crate::lightning::ln::msgs::RoutingMessageHandler {
229 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
231 handle_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement,
232 handle_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement,
233 handle_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update,
234 get_next_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcement,
235 get_next_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcement,
236 peer_connected: IgnoringMessageHandler_RoutingMessageHandler_peer_connected,
237 handle_reply_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_channel_range,
238 handle_reply_short_channel_ids_end: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
239 handle_query_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_query_channel_range,
240 handle_query_short_channel_ids: IgnoringMessageHandler_RoutingMessageHandler_handle_query_short_channel_ids,
241 processing_queue_high: IgnoringMessageHandler_RoutingMessageHandler_processing_queue_high,
242 provided_node_features: IgnoringMessageHandler_RoutingMessageHandler_provided_node_features,
243 provided_init_features: IgnoringMessageHandler_RoutingMessageHandler_provided_init_features,
244 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
245 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
247 get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
253 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 {
254 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
255 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() };
259 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 {
260 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
261 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() };
265 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 {
266 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, msg.get_native_ref());
267 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() };
271 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 {
272 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, starting_point);
273 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 }) };
277 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 {
278 let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) };
279 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, local_starting_point);
280 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 };
284 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 {
285 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);
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( { () /*e*/ }).into() };
290 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 {
291 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()) });
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_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 {
297 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()) });
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_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 {
303 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()) });
304 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() };
308 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 {
309 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()) });
310 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() };
314 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool {
315 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
319 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
320 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
321 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
324 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 {
325 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
326 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
329 impl From<nativeIgnoringMessageHandler> for crate::lightning::events::OnionMessageProvider {
330 fn from(obj: nativeIgnoringMessageHandler) -> Self {
331 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
332 let mut ret = IgnoringMessageHandler_as_OnionMessageProvider(&rust_obj);
333 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
334 rust_obj.inner = core::ptr::null_mut();
335 ret.free = Some(IgnoringMessageHandler_free_void);
339 /// Constructs a new OnionMessageProvider which calls the relevant methods on this_arg.
340 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageProvider must be freed before this_arg is
342 pub extern "C" fn IgnoringMessageHandler_as_OnionMessageProvider(this_arg: &IgnoringMessageHandler) -> crate::lightning::events::OnionMessageProvider {
343 crate::lightning::events::OnionMessageProvider {
344 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
346 next_onion_message_for_peer: IgnoringMessageHandler_OnionMessageProvider_next_onion_message_for_peer,
351 extern "C" fn IgnoringMessageHandler_OnionMessageProvider_next_onion_message_for_peer(this_arg: *const c_void, mut peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage {
352 let mut ret = <nativeIgnoringMessageHandler as lightning::events::OnionMessageProvider<>>::next_onion_message_for_peer(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, peer_node_id.into_rust());
353 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 };
357 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::OnionMessageHandler {
358 fn from(obj: nativeIgnoringMessageHandler) -> Self {
359 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
360 let mut ret = IgnoringMessageHandler_as_OnionMessageHandler(&rust_obj);
361 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
362 rust_obj.inner = core::ptr::null_mut();
363 ret.free = Some(IgnoringMessageHandler_free_void);
367 /// Constructs a new OnionMessageHandler which calls the relevant methods on this_arg.
368 /// This copies the `inner` pointer in this_arg and thus the returned OnionMessageHandler must be freed before this_arg is
370 pub extern "C" fn IgnoringMessageHandler_as_OnionMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::msgs::OnionMessageHandler {
371 crate::lightning::ln::msgs::OnionMessageHandler {
372 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
374 handle_onion_message: IgnoringMessageHandler_OnionMessageHandler_handle_onion_message,
375 peer_connected: IgnoringMessageHandler_OnionMessageHandler_peer_connected,
376 peer_disconnected: IgnoringMessageHandler_OnionMessageHandler_peer_disconnected,
377 provided_node_features: IgnoringMessageHandler_OnionMessageHandler_provided_node_features,
378 provided_init_features: IgnoringMessageHandler_OnionMessageHandler_provided_init_features,
379 OnionMessageProvider: crate::lightning::events::OnionMessageProvider {
380 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
382 next_onion_message_for_peer: IgnoringMessageHandler_OnionMessageProvider_next_onion_message_for_peer,
387 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) {
388 <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())
391 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 {
392 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);
393 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() };
396 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
397 <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust())
400 extern "C" fn IgnoringMessageHandler_OnionMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
401 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
402 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
405 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 {
406 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::OnionMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &their_node_id.into_rust());
407 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
410 impl From<nativeIgnoringMessageHandler> for crate::lightning::onion_message::offers::OffersMessageHandler {
411 fn from(obj: nativeIgnoringMessageHandler) -> Self {
412 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
413 let mut ret = IgnoringMessageHandler_as_OffersMessageHandler(&rust_obj);
414 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
415 rust_obj.inner = core::ptr::null_mut();
416 ret.free = Some(IgnoringMessageHandler_free_void);
420 /// Constructs a new OffersMessageHandler which calls the relevant methods on this_arg.
421 /// This copies the `inner` pointer in this_arg and thus the returned OffersMessageHandler must be freed before this_arg is
423 pub extern "C" fn IgnoringMessageHandler_as_OffersMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::onion_message::offers::OffersMessageHandler {
424 crate::lightning::onion_message::offers::OffersMessageHandler {
425 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
427 handle_message: IgnoringMessageHandler_OffersMessageHandler_handle_message,
432 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 {
433 let mut ret = <nativeIgnoringMessageHandler as lightning::onion_message::offers::OffersMessageHandler<>>::handle_message(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, message.into_native());
434 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()) }) };
438 impl From<nativeIgnoringMessageHandler> for crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
439 fn from(obj: nativeIgnoringMessageHandler) -> Self {
440 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
441 let mut ret = IgnoringMessageHandler_as_CustomOnionMessageHandler(&rust_obj);
442 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
443 rust_obj.inner = core::ptr::null_mut();
444 ret.free = Some(IgnoringMessageHandler_free_void);
448 /// Constructs a new CustomOnionMessageHandler which calls the relevant methods on this_arg.
449 /// This copies the `inner` pointer in this_arg and thus the returned CustomOnionMessageHandler must be freed before this_arg is
451 pub extern "C" fn IgnoringMessageHandler_as_CustomOnionMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
452 crate::lightning::onion_message::messenger::CustomOnionMessageHandler {
453 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
455 handle_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message,
456 read_custom_message: IgnoringMessageHandler_CustomOnionMessageHandler_read_custom_message,
461 extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_handle_custom_message(this_arg: *const c_void, mut msg: crate::lightning::onion_message::packet::CustomOnionMessageContents) -> crate::c_types::derived::COption_CustomOnionMessageContentsZ {
465 extern "C" fn IgnoringMessageHandler_CustomOnionMessageHandler_read_custom_message(this_arg: *const c_void, mut message_type: u64, mut buffer: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_CustomOnionMessageContentsZDecodeErrorZ {
466 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());
467 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = if o.is_none() { crate::c_types::derived::COption_CustomOnionMessageContentsZ::None } else { crate::c_types::derived::COption_CustomOnionMessageContentsZ::Some( { Into::into(o.unwrap()) }) }; local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
471 impl From<nativeInfallible> for crate::lightning::onion_message::packet::CustomOnionMessageContents {
472 fn from(obj: nativeInfallible) -> Self {
476 impl From<nativeInfallible> for crate::lightning::ln::wire::Type {
477 fn from(obj: nativeInfallible) -> Self {
481 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::wire::CustomMessageReader {
482 fn from(obj: nativeIgnoringMessageHandler) -> Self {
483 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
484 let mut ret = IgnoringMessageHandler_as_CustomMessageReader(&rust_obj);
485 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
486 rust_obj.inner = core::ptr::null_mut();
487 ret.free = Some(IgnoringMessageHandler_free_void);
491 /// Constructs a new CustomMessageReader which calls the relevant methods on this_arg.
492 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageReader must be freed before this_arg is
494 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageReader(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::wire::CustomMessageReader {
495 crate::lightning::ln::wire::CustomMessageReader {
496 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
498 read: IgnoringMessageHandler_CustomMessageReader_read,
503 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 {
504 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::wire::CustomMessageReader<>>::read(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, message_type, &mut buffer.to_reader());
505 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() };
509 impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::peer_handler::CustomMessageHandler {
510 fn from(obj: nativeIgnoringMessageHandler) -> Self {
511 let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
512 let mut ret = IgnoringMessageHandler_as_CustomMessageHandler(&rust_obj);
513 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
514 rust_obj.inner = core::ptr::null_mut();
515 ret.free = Some(IgnoringMessageHandler_free_void);
519 /// Constructs a new CustomMessageHandler which calls the relevant methods on this_arg.
520 /// This copies the `inner` pointer in this_arg and thus the returned CustomMessageHandler must be freed before this_arg is
522 pub extern "C" fn IgnoringMessageHandler_as_CustomMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::peer_handler::CustomMessageHandler {
523 crate::lightning::ln::peer_handler::CustomMessageHandler {
524 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
526 handle_custom_message: IgnoringMessageHandler_CustomMessageHandler_handle_custom_message,
527 get_and_clear_pending_msg: IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg,
528 provided_node_features: IgnoringMessageHandler_CustomMessageHandler_provided_node_features,
529 provided_init_features: IgnoringMessageHandler_CustomMessageHandler_provided_init_features,
530 CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader {
531 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
533 read: IgnoringMessageHandler_CustomMessageReader_read,
539 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 {
543 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ {
544 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::get_and_clear_pending_msg(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
545 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 }); };
549 extern "C" fn IgnoringMessageHandler_CustomMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
550 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
551 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
554 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 {
555 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());
556 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
560 use lightning::ln::peer_handler::ErroringMessageHandler as nativeErroringMessageHandlerImport;
561 pub(crate) type nativeErroringMessageHandler = nativeErroringMessageHandlerImport;
563 /// A dummy struct which implements `ChannelMessageHandler` without having any channels.
564 /// You can provide one of these as the route_handler in a MessageHandler.
567 pub struct ErroringMessageHandler {
568 /// A pointer to the opaque Rust object.
570 /// Nearly everywhere, inner must be non-null, however in places where
571 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
572 pub inner: *mut nativeErroringMessageHandler,
573 /// Indicates that this is the only struct which contains the same pointer.
575 /// Rust functions which take ownership of an object provided via an argument require
576 /// this to be true and invalidate the object pointed to by inner.
580 impl Drop for ErroringMessageHandler {
582 if self.is_owned && !<*mut nativeErroringMessageHandler>::is_null(self.inner) {
583 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
587 /// Frees any resources used by the ErroringMessageHandler, if is_owned is set and inner is non-NULL.
589 pub extern "C" fn ErroringMessageHandler_free(this_obj: ErroringMessageHandler) { }
591 /// Used only if an object of this type is returned as a trait impl by a method
592 pub(crate) extern "C" fn ErroringMessageHandler_free_void(this_ptr: *mut c_void) {
593 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeErroringMessageHandler) };
596 impl ErroringMessageHandler {
597 pub(crate) fn get_native_ref(&self) -> &'static nativeErroringMessageHandler {
598 unsafe { &*ObjOps::untweak_ptr(self.inner) }
600 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeErroringMessageHandler {
601 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
603 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
604 pub(crate) fn take_inner(mut self) -> *mut nativeErroringMessageHandler {
605 assert!(self.is_owned);
606 let ret = ObjOps::untweak_ptr(self.inner);
607 self.inner = core::ptr::null_mut();
611 /// Constructs a new ErroringMessageHandler
614 pub extern "C" fn ErroringMessageHandler_new() -> crate::lightning::ln::peer_handler::ErroringMessageHandler {
615 let mut ret = lightning::ln::peer_handler::ErroringMessageHandler::new();
616 crate::lightning::ln::peer_handler::ErroringMessageHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
619 impl From<nativeErroringMessageHandler> for crate::lightning::events::MessageSendEventsProvider {
620 fn from(obj: nativeErroringMessageHandler) -> Self {
621 let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
622 let mut ret = ErroringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
623 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
624 rust_obj.inner = core::ptr::null_mut();
625 ret.free = Some(ErroringMessageHandler_free_void);
629 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
630 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
632 pub extern "C" fn ErroringMessageHandler_as_MessageSendEventsProvider(this_arg: &ErroringMessageHandler) -> crate::lightning::events::MessageSendEventsProvider {
633 crate::lightning::events::MessageSendEventsProvider {
634 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
636 get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
641 extern "C" fn ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
642 let mut ret = <nativeErroringMessageHandler as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
643 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
647 impl From<nativeErroringMessageHandler> for crate::lightning::ln::msgs::ChannelMessageHandler {
648 fn from(obj: nativeErroringMessageHandler) -> Self {
649 let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
650 let mut ret = ErroringMessageHandler_as_ChannelMessageHandler(&rust_obj);
651 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
652 rust_obj.inner = core::ptr::null_mut();
653 ret.free = Some(ErroringMessageHandler_free_void);
657 /// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
658 /// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
660 pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &ErroringMessageHandler) -> crate::lightning::ln::msgs::ChannelMessageHandler {
661 crate::lightning::ln::msgs::ChannelMessageHandler {
662 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
664 handle_open_channel: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel,
665 handle_open_channel_v2: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel_v2,
666 handle_accept_channel: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel,
667 handle_accept_channel_v2: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel_v2,
668 handle_funding_created: ErroringMessageHandler_ChannelMessageHandler_handle_funding_created,
669 handle_funding_signed: ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed,
670 handle_channel_ready: ErroringMessageHandler_ChannelMessageHandler_handle_channel_ready,
671 handle_shutdown: ErroringMessageHandler_ChannelMessageHandler_handle_shutdown,
672 handle_closing_signed: ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed,
673 handle_tx_add_input: ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_input,
674 handle_tx_add_output: ErroringMessageHandler_ChannelMessageHandler_handle_tx_add_output,
675 handle_tx_remove_input: ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_input,
676 handle_tx_remove_output: ErroringMessageHandler_ChannelMessageHandler_handle_tx_remove_output,
677 handle_tx_complete: ErroringMessageHandler_ChannelMessageHandler_handle_tx_complete,
678 handle_tx_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_tx_signatures,
679 handle_tx_init_rbf: ErroringMessageHandler_ChannelMessageHandler_handle_tx_init_rbf,
680 handle_tx_ack_rbf: ErroringMessageHandler_ChannelMessageHandler_handle_tx_ack_rbf,
681 handle_tx_abort: ErroringMessageHandler_ChannelMessageHandler_handle_tx_abort,
682 handle_update_add_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc,
683 handle_update_fulfill_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc,
684 handle_update_fail_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc,
685 handle_update_fail_malformed_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_malformed_htlc,
686 handle_commitment_signed: ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed,
687 handle_revoke_and_ack: ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack,
688 handle_update_fee: ErroringMessageHandler_ChannelMessageHandler_handle_update_fee,
689 handle_announcement_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures,
690 peer_disconnected: ErroringMessageHandler_ChannelMessageHandler_peer_disconnected,
691 peer_connected: ErroringMessageHandler_ChannelMessageHandler_peer_connected,
692 handle_channel_reestablish: ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish,
693 handle_channel_update: ErroringMessageHandler_ChannelMessageHandler_handle_channel_update,
694 handle_error: ErroringMessageHandler_ChannelMessageHandler_handle_error,
695 provided_node_features: ErroringMessageHandler_ChannelMessageHandler_provided_node_features,
696 provided_init_features: ErroringMessageHandler_ChannelMessageHandler_provided_init_features,
697 get_genesis_hashes: ErroringMessageHandler_ChannelMessageHandler_get_genesis_hashes,
698 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
699 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
701 get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
706 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) {
707 <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())
709 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) {
710 <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())
712 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) {
713 <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())
715 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) {
716 <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())
718 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) {
719 <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())
721 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) {
722 <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())
724 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) {
725 <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())
727 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) {
728 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
730 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) {
731 <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())
733 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) {
734 <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())
736 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) {
737 <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())
739 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) {
740 <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())
742 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) {
743 <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())
745 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) {
746 <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())
748 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) {
749 <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())
751 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) {
752 <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())
754 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) {
755 <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())
757 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) {
758 <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())
760 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) {
761 <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())
763 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) {
764 <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())
766 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) {
767 <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())
769 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) {
770 <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())
772 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) {
773 <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())
775 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) {
776 <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())
778 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) {
779 <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())
781 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) {
782 <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())
784 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) {
785 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust())
788 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 {
789 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);
790 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() };
793 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) {
794 <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())
796 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) {
797 <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())
799 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) {
800 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), msg.get_native_ref())
803 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
804 let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
805 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
808 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 {
809 let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust());
810 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
813 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_get_genesis_hashes(this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ChainHashZZ {
814 let mut ret = <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::get_genesis_hashes(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
815 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_ChainHashZZ::None } else { crate::c_types::derived::COption_CVec_ChainHashZZ::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.to_bytes() } }); }; local_ret_0.into() }) };
820 use lightning::ln::peer_handler::MessageHandler as nativeMessageHandlerImport;
821 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>;
823 /// Provides references to trait impls which handle different types of messages.
826 pub struct MessageHandler {
827 /// A pointer to the opaque Rust object.
829 /// Nearly everywhere, inner must be non-null, however in places where
830 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
831 pub inner: *mut nativeMessageHandler,
832 /// Indicates that this is the only struct which contains the same pointer.
834 /// Rust functions which take ownership of an object provided via an argument require
835 /// this to be true and invalidate the object pointed to by inner.
839 impl Drop for MessageHandler {
841 if self.is_owned && !<*mut nativeMessageHandler>::is_null(self.inner) {
842 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
846 /// Frees any resources used by the MessageHandler, if is_owned is set and inner is non-NULL.
848 pub extern "C" fn MessageHandler_free(this_obj: MessageHandler) { }
850 /// Used only if an object of this type is returned as a trait impl by a method
851 pub(crate) extern "C" fn MessageHandler_free_void(this_ptr: *mut c_void) {
852 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMessageHandler) };
855 impl MessageHandler {
856 pub(crate) fn get_native_ref(&self) -> &'static nativeMessageHandler {
857 unsafe { &*ObjOps::untweak_ptr(self.inner) }
859 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMessageHandler {
860 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
862 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
863 pub(crate) fn take_inner(mut self) -> *mut nativeMessageHandler {
864 assert!(self.is_owned);
865 let ret = ObjOps::untweak_ptr(self.inner);
866 self.inner = core::ptr::null_mut();
870 /// A message handler which handles messages specific to channels. Usually this is just a
871 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
873 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
875 pub extern "C" fn MessageHandler_get_chan_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::ChannelMessageHandler {
876 let mut inner_val = &mut this_ptr.get_native_mut_ref().chan_handler;
879 /// A message handler which handles messages specific to channels. Usually this is just a
880 /// [`ChannelManager`] object or an [`ErroringMessageHandler`].
882 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
884 pub extern "C" fn MessageHandler_set_chan_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::ChannelMessageHandler) {
885 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chan_handler = val;
887 /// A message handler which handles messages updating our knowledge of the network channel
888 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
890 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
892 pub extern "C" fn MessageHandler_get_route_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::RoutingMessageHandler {
893 let mut inner_val = &mut this_ptr.get_native_mut_ref().route_handler;
896 /// A message handler which handles messages updating our knowledge of the network channel
897 /// graph. Usually this is just a [`P2PGossipSync`] object or an [`IgnoringMessageHandler`].
899 /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
901 pub extern "C" fn MessageHandler_set_route_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::RoutingMessageHandler) {
902 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_handler = val;
904 /// A message handler which handles onion messages. This should generally be an
905 /// [`OnionMessenger`], but can also be an [`IgnoringMessageHandler`].
907 /// [`OnionMessenger`]: crate::onion_message::OnionMessenger
909 pub extern "C" fn MessageHandler_get_onion_message_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::msgs::OnionMessageHandler {
910 let mut inner_val = &mut this_ptr.get_native_mut_ref().onion_message_handler;
913 /// A message handler which handles onion messages. This should generally be an
914 /// [`OnionMessenger`], but can also be an [`IgnoringMessageHandler`].
916 /// [`OnionMessenger`]: crate::onion_message::OnionMessenger
918 pub extern "C" fn MessageHandler_set_onion_message_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::msgs::OnionMessageHandler) {
919 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.onion_message_handler = val;
921 /// A message handler which handles custom messages. The only LDK-provided implementation is
922 /// [`IgnoringMessageHandler`].
924 pub extern "C" fn MessageHandler_get_custom_message_handler(this_ptr: &MessageHandler) -> *const crate::lightning::ln::peer_handler::CustomMessageHandler {
925 let mut inner_val = &mut this_ptr.get_native_mut_ref().custom_message_handler;
928 /// A message handler which handles custom messages. The only LDK-provided implementation is
929 /// [`IgnoringMessageHandler`].
931 pub extern "C" fn MessageHandler_set_custom_message_handler(this_ptr: &mut MessageHandler, mut val: crate::lightning::ln::peer_handler::CustomMessageHandler) {
932 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.custom_message_handler = val;
934 /// Constructs a new MessageHandler given each field
937 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 {
938 MessageHandler { inner: ObjOps::heap_alloc(nativeMessageHandler {
939 chan_handler: chan_handler_arg,
940 route_handler: route_handler_arg,
941 onion_message_handler: onion_message_handler_arg,
942 custom_message_handler: custom_message_handler_arg,
945 /// Provides an object which can be used to send data to and which uniquely identifies a connection
946 /// to a remote host. You will need to be able to generate multiple of these which meet Eq and
947 /// implement Hash to meet the PeerManager API.
949 /// For efficiency, [`Clone`] should be relatively cheap for this type.
951 /// Two descriptors may compare equal (by [`cmp::Eq`] and [`hash::Hash`]) as long as the original
952 /// has been disconnected, the [`PeerManager`] has been informed of the disconnection (either by it
953 /// having triggered the disconnection or a call to [`PeerManager::socket_disconnected`]), and no
954 /// further calls to the [`PeerManager`] related to the original socket occur. This allows you to
955 /// use a file descriptor for your SocketDescriptor directly, however for simplicity you may wish
956 /// to simply use another value which is guaranteed to be globally unique instead.
958 pub struct SocketDescriptor {
959 /// An opaque pointer which is passed to your function implementations as an argument.
960 /// This has no meaning in the LDK, and can be NULL or any other value.
961 pub this_arg: *mut c_void,
962 /// Attempts to send some data from the given slice to the peer.
964 /// Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
965 /// Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
966 /// called and further write attempts may occur until that time.
968 /// If the returned size is smaller than `data.len()`, a
969 /// [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
970 /// written. Additionally, until a `send_data` event completes fully, no further
971 /// [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
972 /// prevent denial-of-service issues, you should not read or buffer any data from the socket
975 /// If a [`PeerManager::read_event`] call on this descriptor had previously returned true
976 /// (indicating that read events should be paused to prevent DoS in the send buffer),
977 /// `resume_read` may be set indicating that read events on this descriptor should resume. A
978 /// `resume_read` of false carries no meaning, and should not cause any action.
979 pub send_data: extern "C" fn (this_arg: *mut c_void, data: crate::c_types::u8slice, resume_read: bool) -> usize,
980 /// Disconnect the socket pointed to by this SocketDescriptor.
982 /// You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
983 /// call (doing so is a noop).
984 pub disconnect_socket: extern "C" fn (this_arg: *mut c_void),
985 /// Checks if two objects are equal given this object's this_arg pointer and another object.
986 pub eq: extern "C" fn (this_arg: *const c_void, other_arg: &SocketDescriptor) -> bool,
987 /// Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.
988 /// This is used, for example, for inclusion of this object in a hash map.
989 pub hash: extern "C" fn (this_arg: *const c_void) -> u64,
990 /// Called, if set, after this SocketDescriptor has been cloned into a duplicate object.
991 /// The new SocketDescriptor is provided, and should be mutated as needed to perform a
992 /// deep copy of the object pointed to by this_arg or avoid any double-freeing.
993 pub cloned: Option<extern "C" fn (new_SocketDescriptor: &mut SocketDescriptor)>,
994 /// Frees any resources associated with this object given its this_arg pointer.
995 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
996 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
998 unsafe impl Send for SocketDescriptor {}
999 unsafe impl Sync for SocketDescriptor {}
1001 pub(crate) extern "C" fn SocketDescriptor_clone_fields(orig: &SocketDescriptor) -> SocketDescriptor {
1003 this_arg: orig.this_arg,
1004 send_data: Clone::clone(&orig.send_data),
1005 disconnect_socket: Clone::clone(&orig.disconnect_socket),
1006 eq: Clone::clone(&orig.eq),
1007 hash: Clone::clone(&orig.hash),
1008 cloned: Clone::clone(&orig.cloned),
1009 free: Clone::clone(&orig.free),
1012 impl core::cmp::Eq for SocketDescriptor {}
1013 impl core::cmp::PartialEq for SocketDescriptor {
1014 fn eq(&self, o: &Self) -> bool { (self.eq)(self.this_arg, o) }
1016 impl core::hash::Hash for SocketDescriptor {
1017 fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) { hasher.write_u64((self.hash)(self.this_arg)) }
1020 /// Creates a copy of a SocketDescriptor
1021 pub extern "C" fn SocketDescriptor_clone(orig: &SocketDescriptor) -> SocketDescriptor {
1022 let mut res = SocketDescriptor_clone_fields(orig);
1023 if let Some(f) = orig.cloned { (f)(&mut res) };
1026 impl Clone for SocketDescriptor {
1027 fn clone(&self) -> Self {
1028 SocketDescriptor_clone(self)
1032 use lightning::ln::peer_handler::SocketDescriptor as rustSocketDescriptor;
1033 impl rustSocketDescriptor for SocketDescriptor {
1034 fn send_data(&mut self, mut data: &[u8], mut resume_read: bool) -> usize {
1035 let mut local_data = crate::c_types::u8slice::from_slice(data);
1036 let mut ret = (self.send_data)(self.this_arg, local_data, resume_read);
1039 fn disconnect_socket(&mut self) {
1040 (self.disconnect_socket)(self.this_arg)
1044 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1045 // directly as a Deref trait in higher-level structs:
1046 impl core::ops::Deref for SocketDescriptor {
1048 fn deref(&self) -> &Self {
1052 /// Calls the free function if one is set
1054 pub extern "C" fn SocketDescriptor_free(this_ptr: SocketDescriptor) { }
1055 impl Drop for SocketDescriptor {
1056 fn drop(&mut self) {
1057 if let Some(f) = self.free {
1063 use lightning::ln::peer_handler::PeerHandleError as nativePeerHandleErrorImport;
1064 pub(crate) type nativePeerHandleError = nativePeerHandleErrorImport;
1066 /// Error for PeerManager errors. If you get one of these, you must disconnect the socket and
1067 /// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the
1071 pub struct PeerHandleError {
1072 /// A pointer to the opaque Rust object.
1074 /// Nearly everywhere, inner must be non-null, however in places where
1075 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1076 pub inner: *mut nativePeerHandleError,
1077 /// Indicates that this is the only struct which contains the same pointer.
1079 /// Rust functions which take ownership of an object provided via an argument require
1080 /// this to be true and invalidate the object pointed to by inner.
1084 impl Drop for PeerHandleError {
1085 fn drop(&mut self) {
1086 if self.is_owned && !<*mut nativePeerHandleError>::is_null(self.inner) {
1087 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1091 /// Frees any resources used by the PeerHandleError, if is_owned is set and inner is non-NULL.
1093 pub extern "C" fn PeerHandleError_free(this_obj: PeerHandleError) { }
1095 /// Used only if an object of this type is returned as a trait impl by a method
1096 pub(crate) extern "C" fn PeerHandleError_free_void(this_ptr: *mut c_void) {
1097 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePeerHandleError) };
1100 impl PeerHandleError {
1101 pub(crate) fn get_native_ref(&self) -> &'static nativePeerHandleError {
1102 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1104 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerHandleError {
1105 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1107 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1108 pub(crate) fn take_inner(mut self) -> *mut nativePeerHandleError {
1109 assert!(self.is_owned);
1110 let ret = ObjOps::untweak_ptr(self.inner);
1111 self.inner = core::ptr::null_mut();
1115 /// Constructs a new PeerHandleError given each field
1118 pub extern "C" fn PeerHandleError_new() -> PeerHandleError {
1119 PeerHandleError { inner: ObjOps::heap_alloc(nativePeerHandleError {
1120 }), is_owned: true }
1122 impl Clone for PeerHandleError {
1123 fn clone(&self) -> Self {
1125 inner: if <*mut nativePeerHandleError>::is_null(self.inner) { core::ptr::null_mut() } else {
1126 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1132 /// Used only if an object of this type is returned as a trait impl by a method
1133 pub(crate) extern "C" fn PeerHandleError_clone_void(this_ptr: *const c_void) -> *mut c_void {
1134 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePeerHandleError)).clone() })) as *mut c_void
1137 /// Creates a copy of the PeerHandleError
1138 pub extern "C" fn PeerHandleError_clone(orig: &PeerHandleError) -> PeerHandleError {
1142 use lightning::ln::peer_handler::PeerManager as nativePeerManagerImport;
1143 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>;
1145 /// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
1146 /// socket events into messages which it passes on to its [`MessageHandler`].
1148 /// Locks are taken internally, so you must never assume that reentrancy from a
1149 /// [`SocketDescriptor`] call back into [`PeerManager`] methods will not deadlock.
1151 /// Calls to [`read_event`] will decode relevant messages and pass them to the
1152 /// [`ChannelMessageHandler`], likely doing message processing in-line. Thus, the primary form of
1153 /// parallelism in Rust-Lightning is in calls to [`read_event`]. Note, however, that calls to any
1154 /// [`PeerManager`] functions related to the same connection must occur only in serial, making new
1155 /// calls only after previous ones have returned.
1157 /// Rather than using a plain [`PeerManager`], it is preferable to use either a [`SimpleArcPeerManager`]
1158 /// a [`SimpleRefPeerManager`], for conciseness. See their documentation for more details, but
1159 /// essentially you should default to using a [`SimpleRefPeerManager`], and use a
1160 /// [`SimpleArcPeerManager`] when you require a `PeerManager` with a static lifetime, such as when
1161 /// you're using lightning-net-tokio.
1163 /// [`read_event`]: PeerManager::read_event
1166 pub struct PeerManager {
1167 /// A pointer to the opaque Rust object.
1169 /// Nearly everywhere, inner must be non-null, however in places where
1170 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1171 pub inner: *mut nativePeerManager,
1172 /// Indicates that this is the only struct which contains the same pointer.
1174 /// Rust functions which take ownership of an object provided via an argument require
1175 /// this to be true and invalidate the object pointed to by inner.
1179 impl Drop for PeerManager {
1180 fn drop(&mut self) {
1181 if self.is_owned && !<*mut nativePeerManager>::is_null(self.inner) {
1182 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1186 /// Frees any resources used by the PeerManager, if is_owned is set and inner is non-NULL.
1188 pub extern "C" fn PeerManager_free(this_obj: PeerManager) { }
1190 /// Used only if an object of this type is returned as a trait impl by a method
1191 pub(crate) extern "C" fn PeerManager_free_void(this_ptr: *mut c_void) {
1192 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePeerManager) };
1196 pub(crate) fn get_native_ref(&self) -> &'static nativePeerManager {
1197 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1199 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePeerManager {
1200 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1202 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1203 pub(crate) fn take_inner(mut self) -> *mut nativePeerManager {
1204 assert!(self.is_owned);
1205 let ret = ObjOps::untweak_ptr(self.inner);
1206 self.inner = core::ptr::null_mut();
1210 /// Constructs a new `PeerManager` with the given message handlers.
1212 /// `ephemeral_random_data` is used to derive per-connection ephemeral keys and must be
1213 /// cryptographically secure random bytes.
1215 /// `current_time` is used as an always-increasing counter that survives across restarts and is
1216 /// incremented irregularly internally. In general it is best to simply use the current UNIX
1217 /// timestamp, however if it is not available a persistent counter that increases once per
1218 /// minute should suffice.
1221 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 {
1222 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);
1223 crate::lightning::ln::peer_handler::PeerManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1226 /// Get a list of tuples mapping from node id to network addresses for peers which have
1227 /// completed the initial handshake.
1229 /// For outbound connections, the [`PublicKey`] will be the same as the `their_node_id` parameter
1230 /// passed in to [`Self::new_outbound_connection`], however entries will only appear once the initial
1231 /// handshake has completed and we are sure the remote peer has the private key for the given
1234 /// The returned `Option`s will only be `Some` if an address had been previously given via
1235 /// [`Self::new_outbound_connection`] or [`Self::new_inbound_connection`].
1238 pub extern "C" fn PeerManager_get_peer_node_ids(this_arg: &crate::lightning::ln::peer_handler::PeerManager) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyCOption_NetAddressZZZ {
1239 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_peer_node_ids();
1240 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = if orig_ret_0_1.is_none() { crate::c_types::derived::COption_NetAddressZ::None } else { crate::c_types::derived::COption_NetAddressZ::Some( { crate::lightning::ln::msgs::NetAddress::native_into(orig_ret_0_1.unwrap()) }) }; let mut local_ret_0 = (crate::c_types::PublicKey::from_rust(&orig_ret_0_0), local_orig_ret_0_1).into(); local_ret_0 }); };
1244 /// Indicates a new outbound connection has been established to a node with the given `node_id`
1245 /// and an optional remote network address.
1247 /// The remote network address adds the option to report a remote IP address back to a connecting
1248 /// peer using the init message.
1249 /// The user should pass the remote network address of the host they are connected to.
1251 /// If an `Err` is returned here you must disconnect the connection immediately.
1253 /// Returns a small number of bytes to send to the remote node (currently always 50).
1255 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
1256 /// [`socket_disconnected`].
1258 /// [`socket_disconnected`]: PeerManager::socket_disconnected
1261 pub extern "C" fn PeerManager_new_outbound_connection(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut their_node_id: crate::c_types::PublicKey, mut descriptor: crate::lightning::ln::peer_handler::SocketDescriptor, mut remote_network_address: crate::c_types::derived::COption_NetAddressZ) -> crate::c_types::derived::CResult_CVec_u8ZPeerHandleErrorZ {
1262 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() }})} };
1263 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_outbound_connection(their_node_id.into_rust(), descriptor, local_remote_network_address);
1264 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() };
1268 /// Indicates a new inbound connection has been established to a node with an optional remote
1269 /// network address.
1271 /// The remote network address adds the option to report a remote IP address back to a connecting
1272 /// peer using the init message.
1273 /// The user should pass the remote network address of the host they are connected to.
1275 /// May refuse the connection by returning an Err, but will never write bytes to the remote end
1276 /// (outbound connector always speaks first). If an `Err` is returned here you must disconnect
1277 /// the connection immediately.
1279 /// Panics if descriptor is duplicative with some other descriptor which has not yet been
1280 /// [`socket_disconnected`].
1282 /// [`socket_disconnected`]: PeerManager::socket_disconnected
1285 pub extern "C" fn PeerManager_new_inbound_connection(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut descriptor: crate::lightning::ln::peer_handler::SocketDescriptor, mut remote_network_address: crate::c_types::derived::COption_NetAddressZ) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ {
1286 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() }})} };
1287 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.new_inbound_connection(descriptor, local_remote_network_address);
1288 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() };
1292 /// Indicates that there is room to write data to the given socket descriptor.
1294 /// May return an Err to indicate that the connection should be closed.
1296 /// May call [`send_data`] on the descriptor passed in (or an equal descriptor) before
1297 /// returning. Thus, be very careful with reentrancy issues! The invariants around calling
1298 /// [`write_buffer_space_avail`] in case a write did not fully complete must still hold - be
1299 /// ready to call [`write_buffer_space_avail`] again if a write call generated here isn't
1302 /// [`send_data`]: SocketDescriptor::send_data
1303 /// [`write_buffer_space_avail`]: PeerManager::write_buffer_space_avail
1306 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 {
1307 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.write_buffer_space_avail(descriptor);
1308 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() };
1312 /// Indicates that data was read from the given socket descriptor.
1314 /// May return an Err to indicate that the connection should be closed.
1316 /// Will *not* call back into [`send_data`] on any descriptors to avoid reentrancy complexity.
1317 /// Thus, however, you should call [`process_events`] after any `read_event` to generate
1318 /// [`send_data`] calls to handle responses.
1320 /// If `Ok(true)` is returned, further read_events should not be triggered until a
1321 /// [`send_data`] call on this descriptor has `resume_read` set (preventing DoS issues in the
1324 /// In order to avoid processing too many messages at once per peer, `data` should be on the
1327 /// [`send_data`]: SocketDescriptor::send_data
1328 /// [`process_events`]: PeerManager::process_events
1331 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 {
1332 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_event(peer_descriptor, data.to_slice());
1333 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() };
1337 /// Checks for any events generated by our handlers and processes them. Includes sending most
1338 /// response messages as well as messages generated by calls to handler functions directly (eg
1339 /// functions like [`ChannelManager::process_pending_htlc_forwards`] or [`send_payment`]).
1341 /// May call [`send_data`] on [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1344 /// You don't have to call this function explicitly if you are using [`lightning-net-tokio`]
1345 /// or one of the other clients provided in our language bindings.
1347 /// Note that if there are any other calls to this function waiting on lock(s) this may return
1348 /// without doing any work. All available events that need handling will be handled before the
1349 /// other calls return.
1351 /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1352 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
1353 /// [`send_data`]: SocketDescriptor::send_data
1355 pub extern "C" fn PeerManager_process_events(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1356 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_events()
1359 /// Indicates that the given socket descriptor's connection is now closed.
1361 pub extern "C" fn PeerManager_socket_disconnected(this_arg: &crate::lightning::ln::peer_handler::PeerManager, descriptor: &crate::lightning::ln::peer_handler::SocketDescriptor) {
1362 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.socket_disconnected(descriptor)
1365 /// Disconnect a peer given its node id.
1367 /// If a peer is connected, this will call [`disconnect_socket`] on the descriptor for the
1368 /// peer. Thus, be very careful about reentrancy issues.
1370 /// [`disconnect_socket`]: SocketDescriptor::disconnect_socket
1372 pub extern "C" fn PeerManager_disconnect_by_node_id(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut node_id: crate::c_types::PublicKey) {
1373 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_by_node_id(node_id.into_rust())
1376 /// Disconnects all currently-connected peers. This is useful on platforms where there may be
1377 /// an indication that TCP sockets have stalled even if we weren't around to time them out
1378 /// using regular ping/pongs.
1380 pub extern "C" fn PeerManager_disconnect_all_peers(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1381 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_all_peers()
1384 /// Send pings to each peer and disconnect those which did not respond to the last round of
1387 /// This may be called on any timescale you want, however, roughly once every ten seconds is
1388 /// preferred. The call rate determines both how often we send a ping to our peers and how much
1389 /// time they have to respond before we disconnect them.
1391 /// May call [`send_data`] on all [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1394 /// [`send_data`]: SocketDescriptor::send_data
1396 pub extern "C" fn PeerManager_timer_tick_occurred(this_arg: &crate::lightning::ln::peer_handler::PeerManager) {
1397 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timer_tick_occurred()
1400 /// Generates a signed node_announcement from the given arguments, sending it to all connected
1401 /// peers. Note that peers will likely ignore this message unless we have at least one public
1402 /// channel which has at least six confirmations on-chain.
1404 /// `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
1405 /// node to humans. They carry no in-protocol meaning.
1407 /// `addresses` represent the set (possibly empty) of socket addresses on which this node
1408 /// accepts incoming connections. These will be included in the node_announcement, publicly
1409 /// tying these addresses together and to this node. If you wish to preserve user privacy,
1410 /// addresses should likely contain only Tor Onion addresses.
1412 /// Panics if `addresses` is absurdly large (more than 100).
1414 /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
1416 pub extern "C" fn PeerManager_broadcast_node_announcement(this_arg: &crate::lightning::ln::peer_handler::PeerManager, mut rgb: crate::c_types::ThreeBytes, mut alias: crate::c_types::ThirtyTwoBytes, mut addresses: crate::c_types::derived::CVec_NetAddressZ) {
1417 let mut local_addresses = Vec::new(); for mut item in addresses.into_rust().drain(..) { local_addresses.push( { item.into_native() }); };
1418 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_node_announcement(rgb.data, alias.data, local_addresses)
1421 use core::convert::Infallible as nativeInfallible;