Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / ln / peer_handler.rs
index fda89fc7528fa91e0d723bd6d0847134144efdea..9d712c84d6ffe8ca0b2b1f917e35da2153f2ee42 100644 (file)
 //! 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)]
+pub struct CustomMessageHandler {
+       /// An opaque pointer which is passed to your function implementations as an argument.
+       /// This has no meaning in the LDK, and can be NULL or any other value.
+       pub this_arg: *mut c_void,
+       /// Called with the message type that was received and the buffer to be read.
+       /// Can return a `MessageHandlingError` if the message could not be handled.
+       #[must_use]
+       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,
+       /// Gets the list of pending messages which were generated by the custom message
+       /// handler, clearing the list in the process. The first tuple element must
+       /// correspond to the intended recipients node ids. If no connection to one of the
+       /// specified node does not exist, the message is simply not sent to it.
+       #[must_use]
+       pub get_and_clear_pending_msg: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ,
+       /// Implementation of CustomMessageReader for this object.
+       pub CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader,
+       /// Frees any resources associated with this object given its this_arg pointer.
+       /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
+       pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
+}
+unsafe impl Send for CustomMessageHandler {}
+unsafe impl Sync for CustomMessageHandler {}
+#[no_mangle]
+pub(crate) extern "C" fn CustomMessageHandler_clone_fields(orig: &CustomMessageHandler) -> CustomMessageHandler {
+       CustomMessageHandler {
+               this_arg: orig.this_arg,
+               handle_custom_message: Clone::clone(&orig.handle_custom_message),
+               get_and_clear_pending_msg: Clone::clone(&orig.get_and_clear_pending_msg),
+               CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader_clone_fields(&orig.CustomMessageReader),
+               free: Clone::clone(&orig.free),
+       }
+}
+impl lightning::ln::wire::CustomMessageReader for CustomMessageHandler {
+       type CustomMessage = crate::lightning::ln::wire::Type;
+       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
+       }
+}
+
+use lightning::ln::peer_handler::CustomMessageHandler as rustCustomMessageHandler;
+impl rustCustomMessageHandler for CustomMessageHandler {
+       fn handle_custom_message(&self, mut msg: crate::lightning::ln::wire::Type, mut sender_node_id: &bitcoin::secp256k1::key::PublicKey) -> Result<(), lightning::ln::msgs::LightningError> {
+               let mut ret = (self.handle_custom_message)(self.this_arg, Into::into(msg), crate::c_types::PublicKey::from_rust(&sender_node_id));
+               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()) } })};
+               local_ret
+       }
+       fn get_and_clear_pending_msg(&self) -> Vec<(bitcoin::secp256k1::key::PublicKey, crate::lightning::ln::wire::Type)> {
+               let mut ret = (self.get_and_clear_pending_msg)(self.this_arg);
+               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 }); };
+               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 core::ops::Deref for CustomMessageHandler {
+       type Target = Self;
+       fn deref(&self) -> &Self {
+               self
+       }
+}
+/// Calls the free function if one is set
+#[no_mangle]
+pub extern "C" fn CustomMessageHandler_free(this_ptr: CustomMessageHandler) { }
+impl Drop for CustomMessageHandler {
+       fn drop(&mut self) {
+               if let Some(f) = self.free {
+                       f(self.this_arg);
+               }
+       }
+}
 
 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.
@@ -52,7 +130,7 @@ impl Drop for IgnoringMessageHandler {
 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)]
@@ -67,7 +145,7 @@ impl IgnoringMessageHandler {
        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
        }
 }
@@ -83,7 +161,7 @@ impl From<nativeIgnoringMessageHandler> for crate::lightning::util::events::Mess
                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
        }
@@ -111,7 +189,7 @@ impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::msgs::RoutingM
                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
        }
@@ -126,7 +204,6 @@ pub extern "C" fn IgnoringMessageHandler_as_RoutingMessageHandler(this_arg: &Ign
                handle_node_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_node_announcement,
                handle_channel_announcement: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_announcement,
                handle_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update,
-               handle_htlc_fail_channel_update: IgnoringMessageHandler_RoutingMessageHandler_handle_htlc_fail_channel_update,
                get_next_channel_announcements: IgnoringMessageHandler_RoutingMessageHandler_get_next_channel_announcements,
                get_next_node_announcements: IgnoringMessageHandler_RoutingMessageHandler_get_next_node_announcements,
                sync_routing_table: IgnoringMessageHandler_RoutingMessageHandler_sync_routing_table,
@@ -160,13 +237,10 @@ extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_channel_update
        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() };
        local_ret
 }
-extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, _update: &crate::lightning::ln::msgs::HTLCFailChannelUpdate) {
-       <nativeIgnoringMessageHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_htlc_fail_channel_update(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, &_update.to_native())
-}
 #[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]
@@ -204,9 +278,81 @@ extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_query_short_ch
        local_ret
 }
 
+use core::convert::Infallible as nativeInfallible;
+impl From<nativeInfallible> for crate::lightning::ln::wire::Type {
+       fn from(obj: nativeInfallible) -> Self {
+               unreachable!();
+       }
+}
+impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::wire::CustomMessageReader {
+       fn from(obj: nativeIgnoringMessageHandler) -> Self {
+               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 = core::ptr::null_mut();
+               ret.free = Some(IgnoringMessageHandler_free_void);
+               ret
+       }
+}
+/// Constructs a new CustomMessageReader which calls the relevant methods on this_arg.
+/// This copies the `inner` pointer in this_arg and thus the returned CustomMessageReader must be freed before this_arg is
+#[no_mangle]
+pub extern "C" fn IgnoringMessageHandler_as_CustomMessageReader(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::wire::CustomMessageReader {
+       crate::lightning::ln::wire::CustomMessageReader {
+               this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
+               free: None,
+               read: IgnoringMessageHandler_CustomMessageReader_read,
+       }
+}
+
+#[must_use]
+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 {
+       let mut ret = <nativeIgnoringMessageHandler as lightning::ln::wire::CustomMessageReader<>>::read(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, _message_type, &mut _buffer.to_reader());
+       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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
+       local_ret
+}
+
+impl From<nativeIgnoringMessageHandler> for crate::lightning::ln::peer_handler::CustomMessageHandler {
+       fn from(obj: nativeIgnoringMessageHandler) -> Self {
+               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 = core::ptr::null_mut();
+               ret.free = Some(IgnoringMessageHandler_free_void);
+               ret
+       }
+}
+/// Constructs a new CustomMessageHandler which calls the relevant methods on this_arg.
+/// This copies the `inner` pointer in this_arg and thus the returned CustomMessageHandler must be freed before this_arg is
+#[no_mangle]
+pub extern "C" fn IgnoringMessageHandler_as_CustomMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::lightning::ln::peer_handler::CustomMessageHandler {
+       crate::lightning::ln::peer_handler::CustomMessageHandler {
+               this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
+               free: None,
+               handle_custom_message: IgnoringMessageHandler_CustomMessageHandler_handle_custom_message,
+               get_and_clear_pending_msg: IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg,
+               CustomMessageReader: crate::lightning::ln::wire::CustomMessageReader {
+                       this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
+                       free: None,
+                       read: IgnoringMessageHandler_CustomMessageReader_read,
+               },
+       }
+}
+
+#[must_use]
+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 {
+       unreachable!();
+}
+#[must_use]
+extern "C" fn IgnoringMessageHandler_CustomMessageHandler_get_and_clear_pending_msg(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_PublicKeyTypeZZ {
+       let mut ret = <nativeIgnoringMessageHandler as lightning::ln::peer_handler::CustomMessageHandler<>>::get_and_clear_pending_msg(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, );
+       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 }); };
+       local_ret.into()
+}
+
 
 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.
@@ -237,7 +383,7 @@ impl Drop for ErroringMessageHandler {
 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)]
@@ -252,7 +398,7 @@ impl ErroringMessageHandler {
        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
        }
 }
@@ -269,7 +415,7 @@ impl From<nativeErroringMessageHandler> for crate::lightning::util::events::Mess
                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
        }
@@ -297,7 +443,7 @@ impl From<nativeErroringMessageHandler> for crate::lightning::ln::msgs::ChannelM
                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
        }
@@ -400,7 +546,7 @@ extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_error(this_arg
 
 
 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]
@@ -430,7 +576,7 @@ impl Drop for MessageHandler {
 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)]
@@ -445,7 +591,7 @@ impl MessageHandler {
        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
        }
 }
@@ -562,12 +708,12 @@ pub(crate) extern "C" fn SocketDescriptor_clone_fields(orig: &SocketDescriptor)
                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
@@ -596,7 +742,7 @@ impl rustSocketDescriptor for 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
@@ -614,7 +760,7 @@ impl Drop for SocketDescriptor {
 }
 
 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
@@ -646,7 +792,7 @@ impl Drop for PeerHandleError {
 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)]
@@ -661,7 +807,7 @@ impl PeerHandleError {
        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
        }
 }
@@ -689,7 +835,7 @@ pub extern "C" fn PeerHandleError_new(mut no_connection_possible_arg: bool) -> P
 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,
                }
@@ -707,7 +853,7 @@ pub extern "C" fn PeerHandleError_clone(orig: &PeerHandleError) -> PeerHandleErr
 }
 
 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>;
+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`].
@@ -755,7 +901,7 @@ impl Drop for PeerManager {
 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)]
@@ -770,7 +916,7 @@ impl PeerManager {
        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
        }
 }
@@ -779,8 +925,8 @@ impl PeerManager {
 /// cryptographically secure random bytes.
 #[must_use]
 #[no_mangle]
-pub extern "C" fn PeerManager_new(mut message_handler: crate::lightning::ln::peer_handler::MessageHandler, mut our_node_secret: crate::c_types::SecretKey, ephemeral_random_data: *const [u8; 32], mut logger: crate::lightning::util::logger::Logger) -> PeerManager {
-       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);
+pub extern "C" fn PeerManager_new(mut message_handler: crate::lightning::ln::peer_handler::MessageHandler, mut our_node_secret: crate::c_types::SecretKey, ephemeral_random_data: *const [u8; 32], mut logger: crate::lightning::util::logger::Logger, mut custom_message_handler: crate::lightning::ln::peer_handler::CustomMessageHandler) -> PeerManager {
+       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, custom_message_handler);
        PeerManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
 }
 
@@ -883,6 +1029,9 @@ pub extern "C" fn PeerManager_read_event(this_arg: &PeerManager, peer_descriptor
 /// May call [`send_data`] on [`SocketDescriptor`]s. Thus, be very careful with reentrancy
 /// issues!
 ///
+/// You don't have to call this function explicitly if you are using [`lightning-net-tokio`]
+/// or one of the other clients provided in our language bindings.
+///
 /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
 /// [`send_data`]: SocketDescriptor::send_data
@@ -911,6 +1060,14 @@ pub extern "C" fn PeerManager_disconnect_by_node_id(this_arg: &PeerManager, mut
        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.
 ///