X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Fln%2Fpeer_handler.rs;h=07368ae85ce9eca703f593b39a6e22747e223927;hb=933eac0670cad94354d73ef144cbaf2c0e81be50;hp=9e7422a6eac6f4b5606201e80ebb53968ea762ff;hpb=09eb596c8fc031597eda096cbf4e9602a6c411c0;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/ln/peer_handler.rs b/lightning-c-bindings/src/ln/peer_handler.rs index 9e7422a..07368ae 100644 --- a/lightning-c-bindings/src/ln/peer_handler.rs +++ b/lightning-c-bindings/src/ln/peer_handler.rs @@ -1,3 +1,11 @@ +// This file is Copyright its original authors, visible in version control +// history and in the source files from which this was generated. +// +// This file is licensed under the license available in the LICENSE or LICENSE.md +// file in the root of this repository or, if no such file exists, the same +// license as that which applies to the original source files from which this +// source was automatically generated. + //! Top level peer message handling and socket handling logic lives here. //! //! Instead of actually servicing sockets ourselves we require that you implement the @@ -19,9 +27,15 @@ type nativeIgnoringMessageHandler = nativeIgnoringMessageHandlerImport; #[must_use] #[repr(C)] pub struct IgnoringMessageHandler { + /// A pointer to the opaque Rust object. + /// Nearly everywhere, inner must be non-null, however in places where /// the Rust equivalent takes an Option, it may be set to null to indicate None. pub inner: *mut nativeIgnoringMessageHandler, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. pub is_owned: bool, } @@ -32,8 +46,9 @@ impl Drop for IgnoringMessageHandler { } } } +/// Frees any resources used by the IgnoringMessageHandler, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn IgnoringMessageHandler_free(this_ptr: 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) { @@ -49,6 +64,7 @@ impl IgnoringMessageHandler { ret } } +/// Constructs a new IgnoringMessageHandler given each field #[must_use] #[no_mangle] pub extern "C" fn IgnoringMessageHandler_new() -> IgnoringMessageHandler { @@ -65,6 +81,8 @@ impl From for crate::util::events::MessageSendEven ret } } +/// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is #[no_mangle] pub extern "C" fn IgnoringMessageHandler_as_MessageSendEventsProvider(this_arg: &IgnoringMessageHandler) -> crate::util::events::MessageSendEventsProvider { crate::util::events::MessageSendEventsProvider { @@ -91,6 +109,8 @@ impl From for crate::ln::msgs::RoutingMessageHandl ret } } +/// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is #[no_mangle] pub extern "C" fn IgnoringMessageHandler_as_RoutingMessageHandler(this_arg: &IgnoringMessageHandler) -> crate::ln::msgs::RoutingMessageHandler { crate::ln::msgs::RoutingMessageHandler { @@ -110,7 +130,7 @@ pub extern "C" fn IgnoringMessageHandler_as_RoutingMessageHandler(this_arg: &Ign MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider { this_arg: unsafe { (*this_arg).inner as *mut c_void }, free: None, - get_and_clear_pending_msg_events: IgnoringMessageHandler_RoutingMessageHandler_get_and_clear_pending_msg_events, + get_and_clear_pending_msg_events: IgnoringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events, }, } } @@ -176,12 +196,6 @@ extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_handle_query_short_ch 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() }; local_ret } -#[must_use] -extern "C" fn IgnoringMessageHandler_RoutingMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeIgnoringMessageHandler) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; - local_ret.into() -} use lightning::ln::peer_handler::ErroringMessageHandler as nativeErroringMessageHandlerImport; @@ -192,9 +206,15 @@ type nativeErroringMessageHandler = nativeErroringMessageHandlerImport; #[must_use] #[repr(C)] pub struct ErroringMessageHandler { + /// A pointer to the opaque Rust object. + /// Nearly everywhere, inner must be non-null, however in places where /// the Rust equivalent takes an Option, it may be set to null to indicate None. pub inner: *mut nativeErroringMessageHandler, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. pub is_owned: bool, } @@ -205,8 +225,9 @@ impl Drop for ErroringMessageHandler { } } } +/// Frees any resources used by the ErroringMessageHandler, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn ErroringMessageHandler_free(this_ptr: 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) { @@ -240,6 +261,8 @@ impl From for crate::util::events::MessageSendEven ret } } +/// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is #[no_mangle] pub extern "C" fn ErroringMessageHandler_as_MessageSendEventsProvider(this_arg: &ErroringMessageHandler) -> crate::util::events::MessageSendEventsProvider { crate::util::events::MessageSendEventsProvider { @@ -266,6 +289,8 @@ impl From for crate::ln::msgs::ChannelMessageHandl ret } } +/// Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is #[no_mangle] pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &ErroringMessageHandler) -> crate::ln::msgs::ChannelMessageHandler { crate::ln::msgs::ChannelMessageHandler { @@ -289,11 +314,12 @@ pub extern "C" fn ErroringMessageHandler_as_ChannelMessageHandler(this_arg: &Err peer_disconnected: ErroringMessageHandler_ChannelMessageHandler_peer_disconnected, peer_connected: ErroringMessageHandler_ChannelMessageHandler_peer_connected, handle_channel_reestablish: ErroringMessageHandler_ChannelMessageHandler_handle_channel_reestablish, + handle_channel_update: ErroringMessageHandler_ChannelMessageHandler_handle_channel_update, handle_error: ErroringMessageHandler_ChannelMessageHandler_handle_error, MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider { this_arg: unsafe { (*this_arg).inner as *mut c_void }, free: None, - get_and_clear_pending_msg_events: ErroringMessageHandler_ChannelMessageHandler_get_and_clear_pending_msg_events, + get_and_clear_pending_msg_events: ErroringMessageHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events, }, } } @@ -346,6 +372,9 @@ extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_announcement_s 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) { >::handle_channel_reestablish(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &their_node_id.into_rust(), unsafe { &*msg.inner }) } +extern "C" fn ErroringMessageHandler_ChannelMessageHandler_handle_channel_update(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, _msg: &crate::ln::msgs::ChannelUpdate) { + >::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), unsafe { &*_msg.inner }) +} 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) { >::peer_disconnected(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), _no_connection_possible) } @@ -355,12 +384,6 @@ extern "C" fn ErroringMessageHandler_ChannelMessageHandler_peer_connected(this_a 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) { >::handle_error(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, &_their_node_id.into_rust(), unsafe { &*_msg.inner }) } -#[must_use] -extern "C" fn ErroringMessageHandler_ChannelMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeErroringMessageHandler) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); }; - local_ret.into() -} use lightning::ln::peer_handler::MessageHandler as nativeMessageHandlerImport; @@ -370,9 +393,15 @@ type nativeMessageHandler = nativeMessageHandlerImport pub extern "C" fn MessageHandler_set_route_handler(this_ptr: &mut MessageHandler, mut val: crate::ln::msgs::RoutingMessageHandler) { unsafe { &mut *this_ptr.inner }.route_handler = val; } +/// Constructs a new MessageHandler given each field #[must_use] #[no_mangle] pub extern "C" fn MessageHandler_new(mut chan_handler_arg: crate::ln::msgs::ChannelMessageHandler, mut route_handler_arg: crate::ln::msgs::RoutingMessageHandler) -> MessageHandler { @@ -447,6 +478,8 @@ pub extern "C" fn MessageHandler_new(mut chan_handler_arg: crate::ln::msgs::Chan /// PeerManager::socket_disconnected(). #[repr(C)] pub struct SocketDescriptor { + /// 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, /// Attempts to send some data from the given slice to the peer. /// @@ -470,9 +503,17 @@ pub struct SocketDescriptor { /// though races may occur whereby disconnect_socket is called after a call to /// socket_disconnected but prior to socket_disconnected returning. pub disconnect_socket: extern "C" fn (this_arg: *mut c_void), + /// Checks if two objects are equal given this object's this_arg pointer and another object. pub eq: extern "C" fn (this_arg: *const c_void, other_arg: &SocketDescriptor) -> bool, + /// Calculate a succinct non-cryptographic hash for an object given its this_arg pointer. + /// This is used, for example, for inclusion of this object in a hash map. pub hash: extern "C" fn (this_arg: *const c_void) -> u64, + /// Creates a copy of the object pointed to by this_arg, for a copy of this SocketDescriptor. + /// Note that the ultimate copy of the SocketDescriptor will have all function pointers the same as the original. + /// May be NULL if no action needs to be taken, the this_arg pointer will be copied into the new SocketDescriptor. pub clone: Option *mut c_void>, + /// 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, } impl std::cmp::Eq for SocketDescriptor {} @@ -483,15 +524,16 @@ impl std::hash::Hash for SocketDescriptor { fn hash(&self, hasher: &mut H) { hasher.write_u64((self.hash)(self.this_arg)) } } #[no_mangle] +/// Creates a copy of a SocketDescriptor pub extern "C" fn SocketDescriptor_clone(orig: &SocketDescriptor) -> SocketDescriptor { SocketDescriptor { this_arg: if let Some(f) = orig.clone { (f)(orig.this_arg) } else { orig.this_arg }, - send_data: orig.send_data.clone(), - disconnect_socket: orig.disconnect_socket.clone(), - eq: orig.eq.clone(), - hash: orig.hash.clone(), - clone: orig.clone.clone(), - free: orig.free.clone(), + send_data: Clone::clone(&orig.send_data), + disconnect_socket: Clone::clone(&orig.disconnect_socket), + eq: Clone::clone(&orig.eq), + hash: Clone::clone(&orig.hash), + clone: Clone::clone(&orig.clone), + free: Clone::clone(&orig.free), } } impl Clone for SocketDescriptor { @@ -540,9 +582,15 @@ type nativePeerHandleError = nativePeerHandleErrorImport; #[must_use] #[repr(C)] pub struct PeerHandleError { + /// A pointer to the opaque Rust object. + /// Nearly everywhere, inner must be non-null, however in places where /// the Rust equivalent takes an Option, it may be set to null to indicate None. pub inner: *mut nativePeerHandleError, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. pub is_owned: bool, } @@ -553,8 +601,9 @@ impl Drop for PeerHandleError { } } } +/// Frees any resources used by the PeerHandleError, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn PeerHandleError_free(this_ptr: 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) { @@ -583,6 +632,7 @@ pub extern "C" fn PeerHandleError_get_no_connection_possible(this_ptr: &PeerHand pub extern "C" fn PeerHandleError_set_no_connection_possible(this_ptr: &mut PeerHandleError, mut val: bool) { unsafe { &mut *this_ptr.inner }.no_connection_possible = val; } +/// Constructs a new PeerHandleError given each field #[must_use] #[no_mangle] pub extern "C" fn PeerHandleError_new(mut no_connection_possible_arg: bool) -> PeerHandleError { @@ -605,6 +655,7 @@ pub(crate) extern "C" fn PeerHandleError_clone_void(this_ptr: *const c_void) -> Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePeerHandleError)).clone() })) as *mut c_void } #[no_mangle] +/// Creates a copy of the PeerHandleError pub extern "C" fn PeerHandleError_clone(orig: &PeerHandleError) -> PeerHandleError { orig.clone() } @@ -623,9 +674,15 @@ type nativePeerManager = nativePeerManagerImport