//! call into the provided message handlers (probably a ChannelManager and NetGraphmsgHandler) with messages
//! they should handle, and encoding/sending response messages.
-use std::str::FromStr;
-use std::ffi::c_void;
+use alloc::str::FromStr;
+use core::ffi::c_void;
use core::convert::Infallible;
use bitcoin::hashes::Hash;
use crate::c_types::*;
+#[cfg(feature="no-std")]
+use alloc::{vec::Vec, boxed::Box};
/// Handler for BOLT1-compliant messages.
#[repr(C)]
}
impl lightning::ln::wire::CustomMessageReader for CustomMessageHandler {
type CustomMessage = crate::lightning::ln::wire::Type;
- fn read<R:std::io::Read>(&self, mut message_type: u16, mut buffer: &mut R) -> Result<Option<crate::lightning::ln::wire::Type>, lightning::ln::msgs::DecodeError> {
+ 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> {
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)));
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((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
local_ret
// We're essentially a pointer already, or at least a set of pointers, so allow us to be used
// directly as a Deref trait in higher-level structs:
-impl std::ops::Deref for CustomMessageHandler {
+impl core::ops::Deref for CustomMessageHandler {
type Target = Self;
fn deref(&self) -> &Self {
self
}
use lightning::ln::peer_handler::IgnoringMessageHandler as nativeIgnoringMessageHandlerImport;
-type nativeIgnoringMessageHandler = nativeIgnoringMessageHandlerImport;
+pub(crate) type nativeIgnoringMessageHandler = nativeIgnoringMessageHandlerImport;
/// A dummy struct which implements `RoutingMessageHandler` without storing any routing information
/// or doing any processing. You can provide one of these as the route_handler in a MessageHandler.
pub extern "C" fn IgnoringMessageHandler_free(this_obj: IgnoringMessageHandler) { }
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn IgnoringMessageHandler_free_void(this_ptr: *mut c_void) {
+pub(crate) extern "C" fn IgnoringMessageHandler_free_void(this_ptr: *mut c_void) {
unsafe { let _ = Box::from_raw(this_ptr as *mut nativeIgnoringMessageHandler); }
}
#[allow(unused)]
pub(crate) fn take_inner(mut self) -> *mut nativeIgnoringMessageHandler {
assert!(self.is_owned);
let ret = ObjOps::untweak_ptr(self.inner);
- self.inner = std::ptr::null_mut();
+ self.inner = core::ptr::null_mut();
ret
}
}
let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
let mut ret = IgnoringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
// 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
- rust_obj.inner = std::ptr::null_mut();
+ rust_obj.inner = core::ptr::null_mut();
ret.free = Some(IgnoringMessageHandler_free_void);
ret
}
let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
let mut ret = IgnoringMessageHandler_as_RoutingMessageHandler(&rust_obj);
// 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
- rust_obj.inner = std::ptr::null_mut();
+ rust_obj.inner = core::ptr::null_mut();
ret.free = Some(IgnoringMessageHandler_free_void);
ret
}
#[must_use]
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 {
let mut ret = <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _starting_point, _batch_amount);
- 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::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { std::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() { std::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 }); };
+ 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::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 }); };
local_ret.into()
}
#[must_use]
let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
let mut ret = IgnoringMessageHandler_as_CustomMessageReader(&rust_obj);
// 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
- rust_obj.inner = std::ptr::null_mut();
+ rust_obj.inner = core::ptr::null_mut();
ret.free = Some(IgnoringMessageHandler_free_void);
ret
}
let mut rust_obj = IgnoringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
let mut ret = IgnoringMessageHandler_as_CustomMessageHandler(&rust_obj);
// 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
- rust_obj.inner = std::ptr::null_mut();
+ rust_obj.inner = core::ptr::null_mut();
ret.free = Some(IgnoringMessageHandler_free_void);
ret
}
use lightning::ln::peer_handler::ErroringMessageHandler as nativeErroringMessageHandlerImport;
-type nativeErroringMessageHandler = nativeErroringMessageHandlerImport;
+pub(crate) type nativeErroringMessageHandler = nativeErroringMessageHandlerImport;
/// A dummy struct which implements `ChannelMessageHandler` without having any channels.
/// You can provide one of these as the route_handler in a MessageHandler.
pub extern "C" fn ErroringMessageHandler_free(this_obj: ErroringMessageHandler) { }
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn ErroringMessageHandler_free_void(this_ptr: *mut c_void) {
+pub(crate) extern "C" fn ErroringMessageHandler_free_void(this_ptr: *mut c_void) {
unsafe { let _ = Box::from_raw(this_ptr as *mut nativeErroringMessageHandler); }
}
#[allow(unused)]
pub(crate) fn take_inner(mut self) -> *mut nativeErroringMessageHandler {
assert!(self.is_owned);
let ret = ObjOps::untweak_ptr(self.inner);
- self.inner = std::ptr::null_mut();
+ self.inner = core::ptr::null_mut();
ret
}
}
let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
let mut ret = ErroringMessageHandler_as_MessageSendEventsProvider(&rust_obj);
// 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
- rust_obj.inner = std::ptr::null_mut();
+ rust_obj.inner = core::ptr::null_mut();
ret.free = Some(ErroringMessageHandler_free_void);
ret
}
let mut rust_obj = ErroringMessageHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
let mut ret = ErroringMessageHandler_as_ChannelMessageHandler(&rust_obj);
// 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
- rust_obj.inner = std::ptr::null_mut();
+ rust_obj.inner = core::ptr::null_mut();
ret.free = Some(ErroringMessageHandler_free_void);
ret
}
use lightning::ln::peer_handler::MessageHandler as nativeMessageHandlerImport;
-type nativeMessageHandler = nativeMessageHandlerImport<crate::lightning::ln::msgs::ChannelMessageHandler, crate::lightning::ln::msgs::RoutingMessageHandler>;
+pub(crate) type nativeMessageHandler = nativeMessageHandlerImport<crate::lightning::ln::msgs::ChannelMessageHandler, crate::lightning::ln::msgs::RoutingMessageHandler>;
/// Provides references to trait impls which handle different types of messages.
#[must_use]
pub extern "C" fn MessageHandler_free(this_obj: MessageHandler) { }
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn MessageHandler_free_void(this_ptr: *mut c_void) {
+pub(crate) extern "C" fn MessageHandler_free_void(this_ptr: *mut c_void) {
unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMessageHandler); }
}
#[allow(unused)]
pub(crate) fn take_inner(mut self) -> *mut nativeMessageHandler {
assert!(self.is_owned);
let ret = ObjOps::untweak_ptr(self.inner);
- self.inner = std::ptr::null_mut();
+ self.inner = core::ptr::null_mut();
ret
}
}
free: Clone::clone(&orig.free),
}
}
-impl std::cmp::Eq for SocketDescriptor {}
-impl std::cmp::PartialEq for SocketDescriptor {
+impl core::cmp::Eq for SocketDescriptor {}
+impl core::cmp::PartialEq for SocketDescriptor {
fn eq(&self, o: &Self) -> bool { (self.eq)(self.this_arg, o) }
}
-impl std::hash::Hash for SocketDescriptor {
- fn hash<H: std::hash::Hasher>(&self, hasher: &mut H) { hasher.write_u64((self.hash)(self.this_arg)) }
+impl core::hash::Hash for SocketDescriptor {
+ fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) { hasher.write_u64((self.hash)(self.this_arg)) }
}
#[no_mangle]
/// Creates a copy of a SocketDescriptor
// We're essentially a pointer already, or at least a set of pointers, so allow us to be used
// directly as a Deref trait in higher-level structs:
-impl std::ops::Deref for SocketDescriptor {
+impl core::ops::Deref for SocketDescriptor {
type Target = Self;
fn deref(&self) -> &Self {
self
}
use lightning::ln::peer_handler::PeerHandleError as nativePeerHandleErrorImport;
-type nativePeerHandleError = nativePeerHandleErrorImport;
+pub(crate) type nativePeerHandleError = nativePeerHandleErrorImport;
/// Error for PeerManager errors. If you get one of these, you must disconnect the socket and
/// generate no further read_event/write_buffer_space_avail/socket_disconnected calls for the
pub extern "C" fn PeerHandleError_free(this_obj: PeerHandleError) { }
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn PeerHandleError_free_void(this_ptr: *mut c_void) {
+pub(crate) extern "C" fn PeerHandleError_free_void(this_ptr: *mut c_void) {
unsafe { let _ = Box::from_raw(this_ptr as *mut nativePeerHandleError); }
}
#[allow(unused)]
pub(crate) fn take_inner(mut self) -> *mut nativePeerHandleError {
assert!(self.is_owned);
let ret = ObjOps::untweak_ptr(self.inner);
- self.inner = std::ptr::null_mut();
+ self.inner = core::ptr::null_mut();
ret
}
}
impl Clone for PeerHandleError {
fn clone(&self) -> Self {
Self {
- inner: if <*mut nativePeerHandleError>::is_null(self.inner) { std::ptr::null_mut() } else {
+ inner: if <*mut nativePeerHandleError>::is_null(self.inner) { core::ptr::null_mut() } else {
ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
is_owned: true,
}
}
use lightning::ln::peer_handler::PeerManager as nativePeerManagerImport;
-type nativePeerManager = nativePeerManagerImport<crate::lightning::ln::peer_handler::SocketDescriptor, crate::lightning::ln::msgs::ChannelMessageHandler, crate::lightning::ln::msgs::RoutingMessageHandler, crate::lightning::util::logger::Logger, crate::lightning::ln::peer_handler::CustomMessageHandler>;
+pub(crate) type nativePeerManager = nativePeerManagerImport<crate::lightning::ln::peer_handler::SocketDescriptor, crate::lightning::ln::msgs::ChannelMessageHandler, crate::lightning::ln::msgs::RoutingMessageHandler, crate::lightning::util::logger::Logger, crate::lightning::ln::peer_handler::CustomMessageHandler>;
/// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
/// socket events into messages which it passes on to its [`MessageHandler`].
pub extern "C" fn PeerManager_free(this_obj: PeerManager) { }
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn PeerManager_free_void(this_ptr: *mut c_void) {
+pub(crate) extern "C" fn PeerManager_free_void(this_ptr: *mut c_void) {
unsafe { let _ = Box::from_raw(this_ptr as *mut nativePeerManager); }
}
#[allow(unused)]
pub(crate) fn take_inner(mut self) -> *mut nativePeerManager {
assert!(self.is_owned);
let ret = ObjOps::untweak_ptr(self.inner);
- self.inner = std::ptr::null_mut();
+ self.inner = core::ptr::null_mut();
ret
}
}
unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_by_node_id(node_id.into_rust(), no_connection_possible)
}
+/// Disconnects all currently-connected peers. This is useful on platforms where there may be
+/// an indication that TCP sockets have stalled even if we weren't around to time them out
+/// using regular ping/pongs.
+#[no_mangle]
+pub extern "C" fn PeerManager_disconnect_all_peers(this_arg: &PeerManager) {
+ unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.disconnect_all_peers()
+}
+
/// Send pings to each peer and disconnect those which did not respond to the last round of
/// pings.
///