By default sort network addrs before inclusion in node_announcements
[rust-lightning] / lightning / src / ln / msgs.rs
index 974e30095109e3647e2acd006ce36bad03e9e928..be99596becd82d4627c21c229d9b6172ac385615 100644 (file)
@@ -390,6 +390,17 @@ pub enum NetAddress {
        },
 }
 impl NetAddress {
+       /// Gets the ID of this address type. Addresses in node_announcement messages should be sorted
+       /// by this.
+       pub(crate) fn get_id(&self) -> u8 {
+               match self {
+                       &NetAddress::IPv4 {..} => { 1 },
+                       &NetAddress::IPv6 {..} => { 2 },
+                       &NetAddress::OnionV2 {..} => { 3 },
+                       &NetAddress::OnionV3 {..} => { 4 },
+               }
+       }
+
        /// Strict byte-length of address descriptor, 1-byte type not recorded
        fn len(&self) -> u16 {
                match self {