1 //! Top level peer message handling and socket handling logic lives here.
3 //! Instead of actually servicing sockets ourselves we require that you implement the
4 //! SocketDescriptor interface and use that to receive actions which you should perform on the
5 //! socket, and call into PeerManager with bytes read from the socket. The PeerManager will then
6 //! call into the provided message handlers (probably a ChannelManager and NetGraphmsgHandler) with messages
7 //! they should handle, and encoding/sending response messages.
10 use bitcoin::hashes::Hash;
11 use crate::c_types::*;
14 use lightning::ln::peer_handler::IgnoringMessageHandler as nativeIgnoringMessageHandlerImport;
15 type nativeIgnoringMessageHandler = nativeIgnoringMessageHandlerImport;
17 /// A dummy struct which implements `RoutingMessageHandler` without storing any routing information
18 /// or doing any processing. You can provide one of these as the route_handler in a MessageHandler.
21 pub struct IgnoringMessageHandler {
22 /// Nearly everywhere, inner must be non-null, however in places where
23 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
24 pub inner: *mut nativeIgnoringMessageHandler,
28 impl Drop for IgnoringMessageHandler {
30 if self.is_owned && !<*mut nativeIgnoringMessageHandler>::is_null(self.inner) {
31 let _ = unsafe { Box::from_raw(self.inner) };
36 pub extern "C" fn IgnoringMessageHandler_free(this_ptr: IgnoringMessageHandler) { }
38 /// Used only if an object of this type is returned as a trait impl by a method
39 extern "C" fn IgnoringMessageHandler_free_void(this_ptr: *mut c_void) {
40 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeIgnoringMessageHandler); }
43 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
44 impl IgnoringMessageHandler {
45 pub(crate) fn take_inner(mut self) -> *mut nativeIgnoringMessageHandler {
46 assert!(self.is_owned);
48 self.inner = std::ptr::null_mut();
54 pub extern "C" fn IgnoringMessageHandler_new() -> IgnoringMessageHandler {
55 IgnoringMessageHandler { inner: Box::into_raw(Box::new(nativeIgnoringMessageHandler {
58 impl From<nativeIgnoringMessageHandler> for crate::util::events::MessageSendEventsProvider {
59 fn from(obj: nativeIgnoringMessageHandler) -> Self {
60 let mut rust_obj = IgnoringMessageHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
61 let mut ret = IgnoringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
62 // 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
63 rust_obj.inner = std::ptr::null_mut();
64 ret.free = Some(IgnoringMessageHandler_free_void);
69 pub extern "C" fn IgnoringMessageHandler_as_MessageSendEventsProvider(this_arg: &IgnoringMessageHandler) -> crate::util::events::MessageSendEventsProvider {
70 crate::util::events::MessageSendEventsProvider {
71 this_arg: unsafe { (*this_arg).inner as *mut c_void },
73 get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
78 extern "C" fn IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
79 let mut ret = <nativeIgnoringMessageHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
80 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
84 impl From<nativeIgnoringMessageHandler> for crate::ln::msgs::RoutingMessageHandler {
85 fn from(obj: nativeIgnoringMessageHandler) -> Self {
86 let mut rust_obj = IgnoringMessageHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
87 let mut ret = IgnoringMessageHandler_as_RoutingMessageHandler(&rust_obj);
88 // 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
89 rust_obj.inner = std::ptr::null_mut();
90 ret.free = Some(IgnoringMessageHandler_free_void);
95 pub extern "C" fn IgnoringMessageHandler_as_RoutingMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::ln::msgs::RoutingMessageHandler {
96 crate::ln::msgs::RoutingMessageHandler {
97 this_arg: unsafe { (*this_arg).inner as *mut c_void },
99 handle_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement,
100 handle_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement,
101 handle_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update,
102 handle_htlc_fail_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_htlc_fail_channel_update,
103 get_next_channel_announcements: IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcements,
104 get_next_node_announcements: IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcements,
105 sync_routing_table: IgnoringMessageHandler_RoutingMessageHandler_sync_routing_table,
106 handle_reply_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_channel_range,
107 handle_reply_short_channel_ids_end: IgnoringMessageHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
108 handle_query_channel_range: IgnoringMessageHandler_RoutingMessageHandler_handle_query_channel_range,
109 handle_query_short_channel_ids: IgnoringMessageHandler_RoutingMessageHandler_handle_query_short_channel_ids,
110 MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider {
111 this_arg: unsafe { (*this_arg).inner as *mut c_void },
113 get_and_clear_pending_msg_events: IgnoringMessageHandler_RoutingMessageHandler_get_and_clear_pending_msg_events,
119 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, _msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
120 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, unsafe { &*_msg.inner });
121 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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
125 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, _msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
126 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, unsafe { &*_msg.inner });
127 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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
131 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, _msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
132 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, unsafe { &*_msg.inner });
133 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::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
136 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, _update: &crate::ln::msgs::HTLCFailChannelUpdate) {
137 <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_htlc_fail_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &_update.to_native())
140 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcements(this_arg: *const c_void, mut _starting_point: u64, mut _batch_amount: u8) -> crate::c_types::derived::CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ {
141 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _starting_point, _batch_amount);
142 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_1 = crate::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((orig_ret_0_1.unwrap()))) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((orig_ret_0_2.unwrap()))) } }, is_owned: true }; let mut local_ret_0 = (crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(orig_ret_0_0)), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); };
146 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcements(this_arg: *const c_void, mut _starting_point: crate::c_types::PublicKey, mut _batch_amount: u8) -> crate::c_types::derived::CVec_NodeAnnouncementZ {
147 let mut local__starting_point_base = if _starting_point.is_null() { None } else { Some( { _starting_point.into_rust() }) }; let mut local__starting_point = local__starting_point_base.as_ref();
148 let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcements(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, local__starting_point, _batch_amount);
149 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
152 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_sync_routing_table(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, _init: &crate::ln::msgs::Init) {
153 <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::sync_routing_table(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &_their_node_id.into_rust(), unsafe { &*_init.inner })
156 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::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
157 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()) });
158 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
162 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::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
163 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()) });
164 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
168 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::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
169 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()) });
170 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
174 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::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
175 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()) });
176 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
180 extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
181 let mut ret = <nativeIgnoringMessageHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
182 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
187 use lightning::ln::peer_handler::ErroringMessageHandler as nativeErroringMessageHandlerImport;
188 type nativeErroringMessageHandler = nativeErroringMessageHandlerImport;
190 /// A dummy struct which implements `ChannelMessageHandler` without having any channels.
191 /// You can provide one of these as the route_handler in a MessageHandler.
194 pub struct ErroringMessageHandler {
195 /// Nearly everywhere, inner must be non-null, however in places where
196 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
197 pub inner: *mut nativeErroringMessageHandler,
201 impl Drop for ErroringMessageHandler {
203 if self.is_owned && !<*mut nativeErroringMessageHandler>::is_null(self.inner) {
204 let _ = unsafe { Box::from_raw(self.inner) };
209 pub extern "C" fn ErroringMessageHandler_free(this_ptr: ErroringMessageHandler) { }
211 /// Used only if an object of this type is returned as a trait impl by a method
212 extern "C" fn ErroringMessageHandler_free_void(this_ptr: *mut c_void) {
213 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeErroringMessageHandler); }
216 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
217 impl ErroringMessageHandler {
218 pub(crate) fn take_inner(mut self) -> *mut nativeErroringMessageHandler {
219 assert!(self.is_owned);
220 let ret = self.inner;
221 self.inner = std::ptr::null_mut();
225 /// Constructs a new ErroringMessageHandler
228 pub extern "C" fn ErroringMessageHandler_new() -> ErroringMessageHandler {
229 let mut ret = lightning::ln::peer_handler::ErroringMessageHandler::new();
230 ErroringMessageHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
233 impl From<nativeErroringMessageHandler> for crate::util::events::MessageSendEventsProvider {
234 fn from(obj: nativeErroringMessageHandler) -> Self {
235 let mut rust_obj = ErroringMessageHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
236 let mut ret = ErroringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
237 // 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
238 rust_obj.inner = std::ptr::null_mut();
239 ret.free = Some(ErroringMessageHandler_free_void);
244 pub extern "C" fn ErroringMessageHandler_as_MessageSendEventsProvider(this_arg: &ErroringMessageHandler) -> crate::util::events::MessageSendEventsProvider {
245 crate::util::events::MessageSendEventsProvider {
246 this_arg: unsafe { (*this_arg).inner as *mut c_void },
248 get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
253 extern "C" fn ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
254 let mut ret = <nativeErroringMessageHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
255 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
259 impl From<nativeErroringMessageHandler> for crate::ln::msgs::ChannelMessageHandler {
260 fn from(obj: nativeErroringMessageHandler) -> Self {
261 let mut rust_obj = ErroringMessageHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
262 let mut ret = ErroringMessageHandler_as_ChannelMessageHandler(&rust_obj);
263 // 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
264 rust_obj.inner = std::ptr::null_mut();
265 ret.free = Some(ErroringMessageHandler_free_void);
270 pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &ErroringMessageHandler) -> crate::ln::msgs::ChannelMessageHandler {
271 crate::ln::msgs::ChannelMessageHandler {
272 this_arg: unsafe { (*this_arg).inner as *mut c_void },
274 handle_open_channel: ErroringMessageHandler_ChannelMessageHandler_handle_open_channel,
275 handle_accept_channel: ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel,
276 handle_funding_created: ErroringMessageHandler_ChannelMessageHandler_handle_funding_created,
277 handle_funding_signed: ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed,
278 handle_funding_locked: ErroringMessageHandler_ChannelMessageHandler_handle_funding_locked,
279 handle_shutdown: ErroringMessageHandler_ChannelMessageHandler_handle_shutdown,
280 handle_closing_signed: ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed,
281 handle_update_add_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc,
282 handle_update_fulfill_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc,
283 handle_update_fail_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc,
284 handle_update_fail_malformed_htlc: ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_malformed_htlc,
285 handle_commitment_signed: ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed,
286 handle_revoke_and_ack: ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack,
287 handle_update_fee: ErroringMessageHandler_ChannelMessageHandler_handle_update_fee,
288 handle_announcement_signatures: ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures,
289 peer_disconnected: ErroringMessageHandler_ChannelMessageHandler_peer_disconnected,
290 peer_connected: ErroringMessageHandler_ChannelMessageHandler_peer_connected,
291 handle_channel_reestablish: ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish,
292 handle_error: ErroringMessageHandler_ChannelMessageHandler_handle_error,
293 MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider {
294 this_arg: unsafe { (*this_arg).inner as *mut c_void },
296 get_and_clear_pending_msg_events: ErroringMessageHandler_ChannelMessageHandler_get_and_clear_pending_msg_events,
301 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_open_channel(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut _their_features: crate::ln::features::InitFeatures, msg: &crate::ln::msgs::OpenChannel) {
302 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_open_channel(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(_their_features.take_inner()) }, unsafe { &*msg.inner })
304 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_accept_channel(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut _their_features: crate::ln::features::InitFeatures, msg: &crate::ln::msgs::AcceptChannel) {
305 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_accept_channel(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(_their_features.take_inner()) }, unsafe { &*msg.inner })
307 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_funding_created(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingCreated) {
308 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_created(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
310 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_funding_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingSigned) {
311 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_signed(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
313 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_funding_locked(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::FundingLocked) {
314 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_funding_locked(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
316 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_shutdown(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, _their_features: &crate::ln::features::InitFeatures, msg: &crate::ln::msgs::Shutdown) {
317 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_shutdown(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*_their_features.inner }, unsafe { &*msg.inner })
319 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_closing_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ClosingSigned) {
320 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_closing_signed(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
322 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_add_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateAddHTLC) {
323 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_add_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
325 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_fulfill_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFulfillHTLC) {
326 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fulfill_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
328 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_fail_htlc(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFailHTLC) {
329 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
331 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::ln::msgs::UpdateFailMalformedHTLC) {
332 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fail_malformed_htlc(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
334 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_commitment_signed(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::CommitmentSigned) {
335 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_commitment_signed(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
337 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_revoke_and_ack(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::RevokeAndACK) {
338 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_revoke_and_ack(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
340 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_update_fee(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::UpdateFee) {
341 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_update_fee(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
343 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_announcement_signatures(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::AnnouncementSignatures) {
344 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_announcement_signatures(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
346 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, msg: &crate::ln::msgs::ChannelReestablish) {
347 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_channel_reestablish(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner })
349 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_peer_disconnected(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _no_connection_possible: bool) {
350 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), _no_connection_possible)
352 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_peer_connected(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, _msg: &crate::ln::msgs::Init) {
353 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), unsafe { &*_msg.inner })
355 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_error(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, _msg: &crate::ln::msgs::ErrorMessage) {
356 <nativeErroringMessageHandler as lightning::ln::msgs::ChannelMessageHandler<>>::handle_error(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), unsafe { &*_msg.inner })
359 extern "C" fn ErroringMessageHandler_ChannelMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
360 let mut ret = <nativeErroringMessageHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, );
361 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
366 use lightning::ln::peer_handler::MessageHandler as nativeMessageHandlerImport;
367 type nativeMessageHandler = nativeMessageHandlerImport<crate::ln::msgs::ChannelMessageHandler, crate::ln::msgs::RoutingMessageHandler>;
369 /// Provides references to trait impls which handle different types of messages.
372 pub struct MessageHandler {
373 /// Nearly everywhere, inner must be non-null, however in places where
374 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
375 pub inner: *mut nativeMessageHandler,
379 impl Drop for MessageHandler {
381 if self.is_owned && !<*mut nativeMessageHandler>::is_null(self.inner) {
382 let _ = unsafe { Box::from_raw(self.inner) };
387 pub extern "C" fn MessageHandler_free(this_ptr: MessageHandler) { }
389 /// Used only if an object of this type is returned as a trait impl by a method
390 extern "C" fn MessageHandler_free_void(this_ptr: *mut c_void) {
391 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMessageHandler); }
394 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
395 impl MessageHandler {
396 pub(crate) fn take_inner(mut self) -> *mut nativeMessageHandler {
397 assert!(self.is_owned);
398 let ret = self.inner;
399 self.inner = std::ptr::null_mut();
403 /// A message handler which handles messages specific to channels. Usually this is just a
404 /// ChannelManager object or a ErroringMessageHandler.
406 pub extern "C" fn MessageHandler_get_chan_handler(this_ptr: &MessageHandler) -> *const crate::ln::msgs::ChannelMessageHandler {
407 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.chan_handler;
410 /// A message handler which handles messages specific to channels. Usually this is just a
411 /// ChannelManager object or a ErroringMessageHandler.
413 pub extern "C" fn MessageHandler_set_chan_handler(this_ptr: &mut MessageHandler, mut val: crate::ln::msgs::ChannelMessageHandler) {
414 unsafe { &mut *this_ptr.inner }.chan_handler = val;
416 /// A message handler which handles messages updating our knowledge of the network channel
417 /// graph. Usually this is just a NetGraphMsgHandlerMonitor object or an IgnoringMessageHandler.
419 pub extern "C" fn MessageHandler_get_route_handler(this_ptr: &MessageHandler) -> *const crate::ln::msgs::RoutingMessageHandler {
420 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.route_handler;
423 /// A message handler which handles messages updating our knowledge of the network channel
424 /// graph. Usually this is just a NetGraphMsgHandlerMonitor object or an IgnoringMessageHandler.
426 pub extern "C" fn MessageHandler_set_route_handler(this_ptr: &mut MessageHandler, mut val: crate::ln::msgs::RoutingMessageHandler) {
427 unsafe { &mut *this_ptr.inner }.route_handler = val;
431 pub extern "C" fn MessageHandler_new(mut chan_handler_arg: crate::ln::msgs::ChannelMessageHandler, mut route_handler_arg: crate::ln::msgs::RoutingMessageHandler) -> MessageHandler {
432 MessageHandler { inner: Box::into_raw(Box::new(nativeMessageHandler {
433 chan_handler: chan_handler_arg,
434 route_handler: route_handler_arg,
435 })), is_owned: true }
437 /// Provides an object which can be used to send data to and which uniquely identifies a connection
438 /// to a remote host. You will need to be able to generate multiple of these which meet Eq and
439 /// implement Hash to meet the PeerManager API.
441 /// For efficiency, Clone should be relatively cheap for this type.
443 /// You probably want to just extend an int and put a file descriptor in a struct and implement
444 /// send_data. Note that if you are using a higher-level net library that may call close() itself,
445 /// be careful to ensure you don't have races whereby you might register a new connection with an
446 /// fd which is the same as a previous one which has yet to be removed via
447 /// PeerManager::socket_disconnected().
449 pub struct SocketDescriptor {
450 pub this_arg: *mut c_void,
451 /// Attempts to send some data from the given slice to the peer.
453 /// Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
454 /// Note that in the disconnected case, socket_disconnected must still fire and further write
455 /// attempts may occur until that time.
457 /// If the returned size is smaller than data.len(), a write_available event must
458 /// trigger the next time more data can be written. Additionally, until the a send_data event
459 /// completes fully, no further read_events should trigger on the same peer!
461 /// If a read_event on this descriptor had previously returned true (indicating that read
462 /// events should be paused to prevent DoS in the send buffer), resume_read may be set
463 /// indicating that read events on this descriptor should resume. A resume_read of false does
464 /// *not* imply that further read events should be paused.
466 pub send_data: extern "C" fn (this_arg: *mut c_void, data: crate::c_types::u8slice, resume_read: bool) -> usize,
467 /// Disconnect the socket pointed to by this SocketDescriptor. Once this function returns, no
468 /// more calls to write_buffer_space_avail, read_event or socket_disconnected may be made with
469 /// this descriptor. No socket_disconnected call should be generated as a result of this call,
470 /// though races may occur whereby disconnect_socket is called after a call to
471 /// socket_disconnected but prior to socket_disconnected returning.
472 pub disconnect_socket: extern "C" fn (this_arg: *mut c_void),
473 pub eq: extern "C" fn (this_arg: *const c_void, other_arg: &SocketDescriptor) -> bool,
474 pub hash: extern "C" fn (this_arg: *const c_void) -> u64,
475 pub clone: Option<extern "C" fn (this_arg: *const c_void) -> *mut c_void>,
476 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
478 impl std::cmp::Eq for SocketDescriptor {}
479 impl std::cmp::PartialEq for SocketDescriptor {
480 fn eq(&self, o: &Self) -> bool { (self.eq)(self.this_arg, o) }
482 impl std::hash::Hash for SocketDescriptor {
483 fn hash<H: std::hash::Hasher>(&self, hasher: &mut H) { hasher.write_u64((self.hash)(self.this_arg)) }
486 pub extern "C" fn SocketDescriptor_clone(orig: &SocketDescriptor) -> SocketDescriptor {
488 this_arg: if let Some(f) = orig.clone { (f)(orig.this_arg) } else { orig.this_arg },
489 send_data: orig.send_data.clone(),
490 disconnect_socket: orig.disconnect_socket.clone(),
492 hash: orig.hash.clone(),
493 clone: orig.clone.clone(),
494 free: orig.free.clone(),
497 impl Clone for SocketDescriptor {
498 fn clone(&self) -> Self {
499 SocketDescriptor_clone(self)
503 use lightning::ln::peer_handler::SocketDescriptor as rustSocketDescriptor;
504 impl rustSocketDescriptor for SocketDescriptor {
505 fn send_data(&mut self, data: &[u8], resume_read: bool) -> usize {
506 let mut local_data = crate::c_types::u8slice::from_slice(data);
507 let mut ret = (self.send_data)(self.this_arg, local_data, resume_read);
510 fn disconnect_socket(&mut self) {
511 (self.disconnect_socket)(self.this_arg)
515 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
516 // directly as a Deref trait in higher-level structs:
517 impl std::ops::Deref for SocketDescriptor {
519 fn deref(&self) -> &Self {
523 /// Calls the free function if one is set
525 pub extern "C" fn SocketDescriptor_free(this_ptr: SocketDescriptor) { }
526 impl Drop for SocketDescriptor {
528 if let Some(f) = self.free {
534 use lightning::ln::peer_handler::PeerHandleError as nativePeerHandleErrorImport;
535 type nativePeerHandleError = nativePeerHandleErrorImport;
537 /// Error for PeerManager errors. If you get one of these, you must disconnect the socket and
538 /// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the
542 pub struct PeerHandleError {
543 /// Nearly everywhere, inner must be non-null, however in places where
544 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
545 pub inner: *mut nativePeerHandleError,
549 impl Drop for PeerHandleError {
551 if self.is_owned && !<*mut nativePeerHandleError>::is_null(self.inner) {
552 let _ = unsafe { Box::from_raw(self.inner) };
557 pub extern "C" fn PeerHandleError_free(this_ptr: PeerHandleError) { }
559 /// Used only if an object of this type is returned as a trait impl by a method
560 extern "C" fn PeerHandleError_free_void(this_ptr: *mut c_void) {
561 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePeerHandleError); }
564 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
565 impl PeerHandleError {
566 pub(crate) fn take_inner(mut self) -> *mut nativePeerHandleError {
567 assert!(self.is_owned);
568 let ret = self.inner;
569 self.inner = std::ptr::null_mut();
573 /// Used to indicate that we probably can't make any future connections to this peer, implying
574 /// we should go ahead and force-close any channels we have with it.
576 pub extern "C" fn PeerHandleError_get_no_connection_possible(this_ptr: &PeerHandleError) -> bool {
577 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.no_connection_possible;
580 /// Used to indicate that we probably can't make any future connections to this peer, implying
581 /// we should go ahead and force-close any channels we have with it.
583 pub extern "C" fn PeerHandleError_set_no_connection_possible(this_ptr: &mut PeerHandleError, mut val: bool) {
584 unsafe { &mut *this_ptr.inner }.no_connection_possible = val;
588 pub extern "C" fn PeerHandleError_new(mut no_connection_possible_arg: bool) -> PeerHandleError {
589 PeerHandleError { inner: Box::into_raw(Box::new(nativePeerHandleError {
590 no_connection_possible: no_connection_possible_arg,
591 })), is_owned: true }
593 impl Clone for PeerHandleError {
594 fn clone(&self) -> Self {
596 inner: if <*mut nativePeerHandleError>::is_null(self.inner) { std::ptr::null_mut() } else {
597 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
603 /// Used only if an object of this type is returned as a trait impl by a method
604 pub(crate) extern "C" fn PeerHandleError_clone_void(this_ptr: *const c_void) -> *mut c_void {
605 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePeerHandleError)).clone() })) as *mut c_void
608 pub extern "C" fn PeerHandleError_clone(orig: &PeerHandleError) -> PeerHandleError {
612 use lightning::ln::peer_handler::PeerManager as nativePeerManagerImport;
613 type nativePeerManager = nativePeerManagerImport<crate::ln::peer_handler::SocketDescriptor, crate::ln::msgs::ChannelMessageHandler, crate::ln::msgs::RoutingMessageHandler, crate::util::logger::Logger>;
615 /// A PeerManager manages a set of peers, described by their SocketDescriptor and marshalls socket
616 /// events into messages which it passes on to its MessageHandlers.
618 /// Rather than using a plain PeerManager, it is preferable to use either a SimpleArcPeerManager
619 /// a SimpleRefPeerManager, for conciseness. See their documentation for more details, but
620 /// essentially you should default to using a SimpleRefPeerManager, and use a
621 /// SimpleArcPeerManager when you require a PeerManager with a static lifetime, such as when
622 /// you're using lightning-net-tokio.
625 pub struct PeerManager {
626 /// Nearly everywhere, inner must be non-null, however in places where
627 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
628 pub inner: *mut nativePeerManager,
632 impl Drop for PeerManager {
634 if self.is_owned && !<*mut nativePeerManager>::is_null(self.inner) {
635 let _ = unsafe { Box::from_raw(self.inner) };
640 pub extern "C" fn PeerManager_free(this_ptr: PeerManager) { }
642 /// Used only if an object of this type is returned as a trait impl by a method
643 extern "C" fn PeerManager_free_void(this_ptr: *mut c_void) {
644 unsafe { let _ = Box::from_raw(this_ptr as *mut nativePeerManager); }
647 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
649 pub(crate) fn take_inner(mut self) -> *mut nativePeerManager {
650 assert!(self.is_owned);
651 let ret = self.inner;
652 self.inner = std::ptr::null_mut();
656 /// Constructs a new PeerManager with the given message handlers and node_id secret key
657 /// ephemeral_random_data is used to derive per-connection ephemeral keys and must be
658 /// cryptographically secure random bytes.
661 pub extern "C" fn PeerManager_new(mut message_handler: crate::ln::peer_handler::MessageHandler, mut our_node_secret: crate::c_types::SecretKey, ephemeral_random_data: *const [u8; 32], mut logger: crate::util::logger::Logger) -> PeerManager {
662 let mut ret = lightning::ln::peer_handler::PeerManager::new(*unsafe { Box::from_raw(message_handler.take_inner()) }, our_node_secret.into_rust(), unsafe { &*ephemeral_random_data}, logger);
663 PeerManager { inner: Box::into_raw(Box::new(ret)), is_owned: true }
666 /// Get the list of node ids for peers which have completed the initial handshake.
668 /// For outbound connections, this will be the same as the their_node_id parameter passed in to
669 /// new_outbound_connection, however entries will only appear once the initial handshake has
670 /// completed and we are sure the remote peer has the private key for the given node_id.
673 pub extern "C" fn PeerManager_get_peer_node_ids(this_arg: &PeerManager) -> crate::c_types::derived::CVec_PublicKeyZ {
674 let mut ret = unsafe { &*this_arg.inner }.get_peer_node_ids();
675 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::PublicKey::from_rust(&item) }); };
679 /// Indicates a new outbound connection has been established to a node with the given node_id.
680 /// Note that if an Err is returned here you MUST NOT call socket_disconnected for the new
681 /// descriptor but must disconnect the connection immediately.
683 /// Returns a small number of bytes to send to the remote node (currently always 50).
685 /// Panics if descriptor is duplicative with some other descriptor which has not yet had a
686 /// socket_disconnected().
689 pub extern "C" fn PeerManager_new_outbound_connection(this_arg: &PeerManager, mut their_node_id: crate::c_types::PublicKey, mut descriptor: crate::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_CVec_u8ZPeerHandleErrorZ {
690 let mut ret = unsafe { &*this_arg.inner }.new_outbound_connection(their_node_id.into_rust(), descriptor);
691 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::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
695 /// Indicates a new inbound connection has been established.
697 /// May refuse the connection by returning an Err, but will never write bytes to the remote end
698 /// (outbound connector always speaks first). Note that if an Err is returned here you MUST NOT
699 /// call socket_disconnected for the new descriptor but must disconnect the connection
702 /// Panics if descriptor is duplicative with some other descriptor which has not yet had
703 /// socket_disconnected called.
706 pub extern "C" fn PeerManager_new_inbound_connection(this_arg: &PeerManager, mut descriptor: crate::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ {
707 let mut ret = unsafe { &*this_arg.inner }.new_inbound_connection(descriptor);
708 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
712 /// Indicates that there is room to write data to the given socket descriptor.
714 /// May return an Err to indicate that the connection should be closed.
716 /// Will most likely call send_data on the descriptor passed in (or the descriptor handed into
717 /// new_*\\_connection) before returning. Thus, be very careful with reentrancy issues! The
718 /// invariants around calling write_buffer_space_avail in case a write did not fully complete
719 /// must still hold - be ready to call write_buffer_space_avail again if a write call generated
720 /// here isn't sufficient! Panics if the descriptor was not previously registered in a
721 /// new_\\*_connection event.
724 pub extern "C" fn PeerManager_write_buffer_space_avail(this_arg: &PeerManager, descriptor: &mut crate::ln::peer_handler::SocketDescriptor) -> crate::c_types::derived::CResult_NonePeerHandleErrorZ {
725 let mut ret = unsafe { &*this_arg.inner }.write_buffer_space_avail(descriptor);
726 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
730 /// Indicates that data was read from the given socket descriptor.
732 /// May return an Err to indicate that the connection should be closed.
734 /// Will *not* call back into send_data on any descriptors to avoid reentrancy complexity.
735 /// Thus, however, you almost certainly want to call process_events() after any read_event to
736 /// generate send_data calls to handle responses.
738 /// If Ok(true) is returned, further read_events should not be triggered until a send_data call
739 /// on this file descriptor has resume_read set (preventing DoS issues in the send buffer).
741 /// Panics if the descriptor was not previously registered in a new_*_connection event.
744 pub extern "C" fn PeerManager_read_event(this_arg: &PeerManager, peer_descriptor: &mut crate::ln::peer_handler::SocketDescriptor, mut data: crate::c_types::u8slice) -> crate::c_types::derived::CResult_boolPeerHandleErrorZ {
745 let mut ret = unsafe { &*this_arg.inner }.read_event(peer_descriptor, data.to_slice());
746 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::ln::peer_handler::PeerHandleError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
750 /// Checks for any events generated by our handlers and processes them. Includes sending most
751 /// response messages as well as messages generated by calls to handler functions directly (eg
752 /// functions like ChannelManager::process_pending_htlc_forward or send_payment).
754 pub extern "C" fn PeerManager_process_events(this_arg: &PeerManager) {
755 unsafe { &*this_arg.inner }.process_events()
758 /// Indicates that the given socket descriptor's connection is now closed.
760 /// This must only be called if the socket has been disconnected by the peer or your own
761 /// decision to disconnect it and must NOT be called in any case where other parts of this
762 /// library (eg PeerHandleError, explicit disconnect_socket calls) instruct you to disconnect
765 /// Panics if the descriptor was not previously registered in a successful new_*_connection event.
767 pub extern "C" fn PeerManager_socket_disconnected(this_arg: &PeerManager, descriptor: &crate::ln::peer_handler::SocketDescriptor) {
768 unsafe { &*this_arg.inner }.socket_disconnected(descriptor)
771 /// Disconnect a peer given its node id.
773 /// Set no_connection_possible to true to prevent any further connection with this peer,
774 /// force-closing any channels we have with it.
776 /// If a peer is connected, this will call `disconnect_socket` on the descriptor for the peer,
777 /// so be careful about reentrancy issues.
779 pub extern "C" fn PeerManager_disconnect_by_node_id(this_arg: &PeerManager, mut node_id: crate::c_types::PublicKey, mut no_connection_possible: bool) {
780 unsafe { &*this_arg.inner }.disconnect_by_node_id(node_id.into_rust(), no_connection_possible)
783 /// This function should be called roughly once every 30 seconds.
784 /// It will send pings to each peer and disconnect those which did not respond to the last round of pings.
785 /// Will most likely call send_data on all of the registered descriptors, thus, be very careful with reentrancy issues!
787 pub extern "C" fn PeerManager_timer_tick_occurred(this_arg: &PeerManager) {
788 unsafe { &*this_arg.inner }.timer_tick_occurred()