1 //! Feature flag definitions for the Lightning protocol according to [BOLT #9].
3 //! Lightning nodes advertise a supported set of operation through feature flags. Features are
4 //! applicable for a specific context as indicated in some [messages]. [`Features`] encapsulates
5 //! behavior for specifying and checking feature flags for a particular context. Each feature is
6 //! defined internally by a trait specifying the corresponding flags (i.e., even and odd bits). A
7 //! [`Context`] is used to parameterize [`Features`] and defines which features it can support.
9 //! Whether a feature is considered \"known\" or \"unknown\" is relative to the implementation, whereas
10 //! the term \"supports\" is used in reference to a particular set of [`Features`]. That is, a node
11 //! supports a feature if it advertises the feature (as either required or optional) to its peers.
12 //! And the implementation can interpret a feature if the feature is known to it.
14 //! [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md
15 //! [messages]: ../msgs/index.html
16 //! [`Features`]: struct.Features.html
17 //! [`Context`]: sealed/trait.Context.html
20 use bitcoin::hashes::Hash;
21 use crate::c_types::*;
24 use lightning::ln::features::InitFeatures as nativeInitFeaturesImport;
25 type nativeInitFeatures = nativeInitFeaturesImport;
27 /// Features used within an `init` message.
30 pub struct InitFeatures {
31 /// Nearly everywhere, inner must be non-null, however in places where
32 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
33 pub inner: *mut nativeInitFeatures,
37 impl Drop for InitFeatures {
39 if self.is_owned && !self.inner.is_null() {
40 let _ = unsafe { Box::from_raw(self.inner) };
45 pub extern "C" fn InitFeatures_free(this_ptr: InitFeatures) { }
47 /// Used only if an object of this type is returned as a trait impl by a method
48 extern "C" fn InitFeatures_free_void(this_ptr: *mut c_void) {
49 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInitFeatures); }
52 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
54 pub(crate) fn take_inner(mut self) -> *mut nativeInitFeatures {
55 assert!(self.is_owned);
57 self.inner = std::ptr::null_mut();
62 use lightning::ln::features::NodeFeatures as nativeNodeFeaturesImport;
63 type nativeNodeFeatures = nativeNodeFeaturesImport;
65 /// Features used within a `node_announcement` message.
68 pub struct NodeFeatures {
69 /// Nearly everywhere, inner must be non-null, however in places where
70 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
71 pub inner: *mut nativeNodeFeatures,
75 impl Drop for NodeFeatures {
77 if self.is_owned && !self.inner.is_null() {
78 let _ = unsafe { Box::from_raw(self.inner) };
83 pub extern "C" fn NodeFeatures_free(this_ptr: NodeFeatures) { }
85 /// Used only if an object of this type is returned as a trait impl by a method
86 extern "C" fn NodeFeatures_free_void(this_ptr: *mut c_void) {
87 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeFeatures); }
90 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
92 pub(crate) fn take_inner(mut self) -> *mut nativeNodeFeatures {
93 assert!(self.is_owned);
95 self.inner = std::ptr::null_mut();
100 use lightning::ln::features::ChannelFeatures as nativeChannelFeaturesImport;
101 type nativeChannelFeatures = nativeChannelFeaturesImport;
103 /// Features used within a `channel_announcement` message.
106 pub struct ChannelFeatures {
107 /// Nearly everywhere, inner must be non-null, however in places where
108 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
109 pub inner: *mut nativeChannelFeatures,
113 impl Drop for ChannelFeatures {
115 if self.is_owned && !self.inner.is_null() {
116 let _ = unsafe { Box::from_raw(self.inner) };
121 pub extern "C" fn ChannelFeatures_free(this_ptr: ChannelFeatures) { }
123 /// Used only if an object of this type is returned as a trait impl by a method
124 extern "C" fn ChannelFeatures_free_void(this_ptr: *mut c_void) {
125 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelFeatures); }
128 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
129 impl ChannelFeatures {
130 pub(crate) fn take_inner(mut self) -> *mut nativeChannelFeatures {
131 assert!(self.is_owned);
132 let ret = self.inner;
133 self.inner = std::ptr::null_mut();