]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Rename SocketAddress from NetAddress
authorAntonio Yang <yanganto@gmail.com>
Mon, 4 Sep 2023 02:34:21 +0000 (10:34 +0800)
committerAntonio Yang <yanganto@gmail.com>
Fri, 8 Sep 2023 12:42:06 +0000 (20:42 +0800)
fuzz/src/fromstr_to_netaddress.rs
lightning-net-tokio/src/lib.rs
lightning/src/ln/msgs.rs
lightning/src/ln/peer_handler.rs
lightning/src/routing/gossip.rs
pending_changelog/move_netaddress_to_socketaddress.txt [new file with mode: 0644]

index 199841123696b89a52a27b288d09866953c33317..dba2d44451e3b5755115e41157d4a102fde9c9b5 100644 (file)
@@ -7,7 +7,7 @@
 // You may not use this file except in accordance with one or both of these
 // licenses.
 
-use lightning::ln::msgs::NetAddress;
+use lightning::ln::msgs::SocketAddress;
 use core::str::FromStr;
 
 use crate::utils::test_logger;
@@ -15,7 +15,7 @@ use crate::utils::test_logger;
 #[inline]
 pub fn do_test(data: &[u8]) {
        if let Ok(s) = std::str::from_utf8(data) {
-               let _ = NetAddress::from_str(s);
+               let _ = SocketAddress::from_str(s);
        }
 
 }
index 6e2ea3f14c14f54b890f8ff504e4f3fe6dd0a304..06aed3194f9bc18e27d146ea9cbedc23604edfe8 100644 (file)
@@ -39,7 +39,7 @@ use tokio::io::AsyncWrite;
 use lightning::ln::peer_handler;
 use lightning::ln::peer_handler::SocketDescriptor as LnSocketTrait;
 use lightning::ln::peer_handler::APeerManager;
-use lightning::ln::msgs::NetAddress;
+use lightning::ln::msgs::SocketAddress;
 
 use std::ops::Deref;
 use std::task::{self, Poll};
@@ -274,13 +274,13 @@ impl Connection {
        }
 }
 
-fn get_addr_from_stream(stream: &StdTcpStream) -> Option<NetAddress> {
+fn get_addr_from_stream(stream: &StdTcpStream) -> Option<SocketAddress> {
        match stream.peer_addr() {
-               Ok(SocketAddr::V4(sockaddr)) => Some(NetAddress::IPv4 {
+               Ok(SocketAddr::V4(sockaddr)) => Some(SocketAddress::TcpIpV4 {
                        addr: sockaddr.ip().octets(),
                        port: sockaddr.port(),
                }),
-               Ok(SocketAddr::V6(sockaddr)) => Some(NetAddress::IPv6 {
+               Ok(SocketAddr::V6(sockaddr)) => Some(SocketAddress::TcpIpV6 {
                        addr: sockaddr.ip().octets(),
                        port: sockaddr.port(),
                }),
index d12dafb65af8e92780373b4b1f7c4b03fd8ee154..6bd5ec3f7293fcac5c043bf3437e47eb90127d9d 100644 (file)
@@ -101,7 +101,7 @@ pub struct Init {
        /// message. A node can decide to use that information to discover a potential update to its
        /// public IPv4 address (NAT) and use that for a [`NodeAnnouncement`] update message containing
        /// the new address.
-       pub remote_network_address: Option<NetAddress>,
+       pub remote_network_address: Option<SocketAddress>,
 }
 
 /// An [`error`] message to be sent to or received from a peer.
@@ -749,16 +749,16 @@ pub struct AnnouncementSignatures {
 
 /// An address which can be used to connect to a remote peer.
 #[derive(Clone, Debug, PartialEq, Eq)]
-pub enum NetAddress {
-       /// An IPv4 address/port on which the peer is listening.
-       IPv4 {
+pub enum SocketAddress {
+       /// An IPv4 address and port on which the peer is listening.
+       TcpIpV4 {
                /// The 4-byte IPv4 address
                addr: [u8; 4],
                /// The port on which the node is listening
                port: u16,
        },
-       /// An IPv6 address/port on which the peer is listening.
-       IPv6 {
+       /// An IPv6 address and port on which the peer is listening.
+       TcpIpV6 {
                /// The 16-byte IPv6 address
                addr: [u8; 16],
                /// The port on which the node is listening
@@ -791,28 +791,28 @@ pub enum NetAddress {
                port: u16,
        },
 }
-impl NetAddress {
+impl SocketAddress {
        /// Gets the ID of this address type. Addresses in [`NodeAnnouncement`] 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 },
-                       &NetAddress::Hostname {..} => { 5 },
+                       &SocketAddress::TcpIpV4 {..} => { 1 },
+                       &SocketAddress::TcpIpV6 {..} => { 2 },
+                       &SocketAddress::OnionV2(_) => { 3 },
+                       &SocketAddress::OnionV3 {..} => { 4 },
+                       &SocketAddress::Hostname {..} => { 5 },
                }
        }
 
        /// Strict byte-length of address descriptor, 1-byte type not recorded
        fn len(&self) -> u16 {
                match self {
-                       &NetAddress::IPv4 { .. } => { 6 },
-                       &NetAddress::IPv6 { .. } => { 18 },
-                       &NetAddress::OnionV2(_) => { 12 },
-                       &NetAddress::OnionV3 { .. } => { 37 },
+                       &SocketAddress::TcpIpV4 { .. } => { 6 },
+                       &SocketAddress::TcpIpV6 { .. } => { 18 },
+                       &SocketAddress::OnionV2(_) => { 12 },
+                       &SocketAddress::OnionV3 { .. } => { 37 },
                        // Consists of 1-byte hostname length, hostname bytes, and 2-byte port.
-                       &NetAddress::Hostname { ref hostname, .. } => { u16::from(hostname.len()) + 3 },
+                       &SocketAddress::Hostname { ref hostname, .. } => { u16::from(hostname.len()) + 3 },
                }
        }
 
@@ -822,31 +822,31 @@ impl NetAddress {
        pub(crate) const MAX_LEN: u16 = 258;
 }
 
-impl Writeable for NetAddress {
+impl Writeable for SocketAddress {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                match self {
-                       &NetAddress::IPv4 { ref addr, ref port } => {
+                       &SocketAddress::TcpIpV4 { ref addr, ref port } => {
                                1u8.write(writer)?;
                                addr.write(writer)?;
                                port.write(writer)?;
                        },
-                       &NetAddress::IPv6 { ref addr, ref port } => {
+                       &SocketAddress::TcpIpV6 { ref addr, ref port } => {
                                2u8.write(writer)?;
                                addr.write(writer)?;
                                port.write(writer)?;
                        },
-                       &NetAddress::OnionV2(bytes) => {
+                       &SocketAddress::OnionV2(bytes) => {
                                3u8.write(writer)?;
                                bytes.write(writer)?;
                        },
-                       &NetAddress::OnionV3 { ref ed25519_pubkey, ref checksum, ref version, ref port } => {
+                       &SocketAddress::OnionV3 { ref ed25519_pubkey, ref checksum, ref version, ref port } => {
                                4u8.write(writer)?;
                                ed25519_pubkey.write(writer)?;
                                checksum.write(writer)?;
                                version.write(writer)?;
                                port.write(writer)?;
                        },
-                       &NetAddress::Hostname { ref hostname, ref port } => {
+                       &SocketAddress::Hostname { ref hostname, ref port } => {
                                5u8.write(writer)?;
                                hostname.write(writer)?;
                                port.write(writer)?;
@@ -856,25 +856,25 @@ impl Writeable for NetAddress {
        }
 }
 
-impl Readable for Result<NetAddress, u8> {
-       fn read<R: Read>(reader: &mut R) -> Result<Result<NetAddress, u8>, DecodeError> {
+impl Readable for Result<SocketAddress, u8> {
+       fn read<R: Read>(reader: &mut R) -> Result<Result<SocketAddress, u8>, DecodeError> {
                let byte = <u8 as Readable>::read(reader)?;
                match byte {
                        1 => {
-                               Ok(Ok(NetAddress::IPv4 {
+                               Ok(Ok(SocketAddress::TcpIpV4 {
                                        addr: Readable::read(reader)?,
                                        port: Readable::read(reader)?,
                                }))
                        },
                        2 => {
-                               Ok(Ok(NetAddress::IPv6 {
+                               Ok(Ok(SocketAddress::TcpIpV6 {
                                        addr: Readable::read(reader)?,
                                        port: Readable::read(reader)?,
                                }))
                        },
-                       3 => Ok(Ok(NetAddress::OnionV2(Readable::read(reader)?))),
+                       3 => Ok(Ok(SocketAddress::OnionV2(Readable::read(reader)?))),
                        4 => {
-                               Ok(Ok(NetAddress::OnionV3 {
+                               Ok(Ok(SocketAddress::OnionV3 {
                                        ed25519_pubkey: Readable::read(reader)?,
                                        checksum: Readable::read(reader)?,
                                        version: Readable::read(reader)?,
@@ -882,7 +882,7 @@ impl Readable for Result<NetAddress, u8> {
                                }))
                        },
                        5 => {
-                               Ok(Ok(NetAddress::Hostname {
+                               Ok(Ok(SocketAddress::Hostname {
                                        hostname: Readable::read(reader)?,
                                        port: Readable::read(reader)?,
                                }))
@@ -892,8 +892,8 @@ impl Readable for Result<NetAddress, u8> {
        }
 }
 
-impl Readable for NetAddress {
-       fn read<R: Read>(reader: &mut R) -> Result<NetAddress, DecodeError> {
+impl Readable for SocketAddress {
+       fn read<R: Read>(reader: &mut R) -> Result<SocketAddress, DecodeError> {
                match Readable::read(reader) {
                        Ok(Ok(res)) => Ok(res),
                        Ok(Err(_)) => Err(DecodeError::UnknownVersion),
@@ -902,9 +902,9 @@ impl Readable for NetAddress {
        }
 }
 
-/// [`NetAddress`] error variants
+/// [`SocketAddress`] error variants
 #[derive(Debug, Eq, PartialEq, Clone)]
-pub enum NetAddressParseError {
+pub enum SocketAddressParseError {
        /// Socket address (IPv4/IPv6) parsing error
        SocketAddrParse,
        /// Invalid input format
@@ -915,34 +915,34 @@ pub enum NetAddressParseError {
        InvalidOnionV3,
 }
 
-impl fmt::Display for NetAddressParseError {
+impl fmt::Display for SocketAddressParseError {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                match self {
-                       NetAddressParseError::SocketAddrParse => write!(f, "Socket address (IPv4/IPv6) parsing error"),
-                       NetAddressParseError::InvalidInput => write!(f, "Invalid input format. \
+                       SocketAddressParseError::SocketAddrParse => write!(f, "Socket address (IPv4/IPv6) parsing error"),
+                       SocketAddressParseError::InvalidInput => write!(f, "Invalid input format. \
                                Expected: \"<ipv4>:<port>\", \"[<ipv6>]:<port>\", \"<onion address>.onion:<port>\" or \"<hostname>:<port>\""),
-                       NetAddressParseError::InvalidPort => write!(f, "Invalid port"),
-                       NetAddressParseError::InvalidOnionV3 => write!(f, "Invalid onion v3 address"),
+                       SocketAddressParseError::InvalidPort => write!(f, "Invalid port"),
+                       SocketAddressParseError::InvalidOnionV3 => write!(f, "Invalid onion v3 address"),
                }
        }
 }
 
 #[cfg(feature = "std")]
-impl From<std::net::SocketAddrV4> for NetAddress {
+impl From<std::net::SocketAddrV4> for SocketAddress {
                fn from(addr: std::net::SocketAddrV4) -> Self {
-                       NetAddress::IPv4 { addr: addr.ip().octets(), port: addr.port() }
+                       SocketAddress::TcpIpV4 { addr: addr.ip().octets(), port: addr.port() }
                }
 }
 
 #[cfg(feature = "std")]
-impl From<std::net::SocketAddrV6> for NetAddress {
+impl From<std::net::SocketAddrV6> for SocketAddress {
                fn from(addr: std::net::SocketAddrV6) -> Self {
-                       NetAddress::IPv6 { addr: addr.ip().octets(), port: addr.port() }
+                       SocketAddress::TcpIpV6 { addr: addr.ip().octets(), port: addr.port() }
                }
 }
 
 #[cfg(feature = "std")]
-impl From<std::net::SocketAddr> for NetAddress {
+impl From<std::net::SocketAddr> for SocketAddress {
                fn from(addr: std::net::SocketAddr) -> Self {
                        match addr {
                                std::net::SocketAddr::V4(addr) => addr.into(),
@@ -951,15 +951,15 @@ impl From<std::net::SocketAddr> for NetAddress {
                }
 }
 
-fn parse_onion_address(host: &str, port: u16) -> Result<NetAddress, NetAddressParseError> {
+fn parse_onion_address(host: &str, port: u16) -> Result<SocketAddress, SocketAddressParseError> {
        if host.ends_with(".onion") {
                let domain = &host[..host.len() - ".onion".len()];
                if domain.len() != 56 {
-                       return Err(NetAddressParseError::InvalidOnionV3);
+                       return Err(SocketAddressParseError::InvalidOnionV3);
                }
-               let onion =  base32::Alphabet::RFC4648 { padding: false }.decode(&domain).map_err(|_| NetAddressParseError::InvalidOnionV3)?;
+               let onion =  base32::Alphabet::RFC4648 { padding: false }.decode(&domain).map_err(|_| SocketAddressParseError::InvalidOnionV3)?;
                if onion.len() != 35 {
-                       return Err(NetAddressParseError::InvalidOnionV3);
+                       return Err(SocketAddressParseError::InvalidOnionV3);
                }
                let version = onion[0];
                let first_checksum_flag = onion[1];
@@ -967,16 +967,16 @@ fn parse_onion_address(host: &str, port: u16) -> Result<NetAddress, NetAddressPa
                let mut ed25519_pubkey = [0; 32];
                ed25519_pubkey.copy_from_slice(&onion[3..35]);
                let checksum = u16::from_be_bytes([first_checksum_flag, second_checksum_flag]);
-               return Ok(NetAddress::OnionV3 { ed25519_pubkey, checksum, version, port });
+               return Ok(SocketAddress::OnionV3 { ed25519_pubkey, checksum, version, port });
 
        } else {
-               return Err(NetAddressParseError::InvalidInput);
+               return Err(SocketAddressParseError::InvalidInput);
        }
 }
 
 #[cfg(feature = "std")]
-impl FromStr for NetAddress {
-       type Err = NetAddressParseError;
+impl FromStr for SocketAddress {
+       type Err = SocketAddressParseError;
 
        fn from_str(s: &str) -> Result<Self, Self::Err> {
                match std::net::SocketAddr::from_str(s) {
@@ -984,17 +984,17 @@ impl FromStr for NetAddress {
                        Err(_) => {
                                let trimmed_input = match s.rfind(":") {
                                        Some(pos) => pos,
-                                       None => return Err(NetAddressParseError::InvalidInput),
+                                       None => return Err(SocketAddressParseError::InvalidInput),
                                };
                                let host = &s[..trimmed_input];
-                               let port: u16 = s[trimmed_input + 1..].parse().map_err(|_| NetAddressParseError::InvalidPort)?;
+                               let port: u16 = s[trimmed_input + 1..].parse().map_err(|_| SocketAddressParseError::InvalidPort)?;
                                if host.ends_with(".onion") {
                                        return parse_onion_address(host, port);
                                };
                                if let Ok(hostname) = Hostname::try_from(s[..trimmed_input].to_string()) {
-                                       return Ok(NetAddress::Hostname { hostname, port });
+                                       return Ok(SocketAddress::Hostname { hostname, port });
                                };
-                               return Err(NetAddressParseError::SocketAddrParse)
+                               return Err(SocketAddressParseError::SocketAddrParse)
                        },
                }
        }
@@ -1039,7 +1039,7 @@ pub struct UnsignedNodeAnnouncement {
        /// This should be sanitized before use. There is no guarantee of uniqueness.
        pub alias: NodeAlias,
        /// List of addresses on which this node is reachable
-       pub addresses: Vec<NetAddress>,
+       pub addresses: Vec<SocketAddress>,
        pub(crate) excess_address_data: Vec<u8>,
        pub(crate) excess_data: Vec<u8>,
 }
@@ -1874,7 +1874,7 @@ impl Readable for Init {
        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
                let global_features: InitFeatures = Readable::read(r)?;
                let features: InitFeatures = Readable::read(r)?;
-               let mut remote_network_address: Option<NetAddress> = None;
+               let mut remote_network_address: Option<SocketAddress> = None;
                let mut networks: Option<WithoutLength<Vec<ChainHash>>> = None;
                decode_tlv_stream!(r, {
                        (1, networks, option),
@@ -2373,7 +2373,7 @@ impl Readable for UnsignedNodeAnnouncement {
                let alias: NodeAlias = Readable::read(r)?;
 
                let addr_len: u16 = Readable::read(r)?;
-               let mut addresses: Vec<NetAddress> = Vec::new();
+               let mut addresses: Vec<SocketAddress> = Vec::new();
                let mut addr_readpos = 0;
                let mut excess = false;
                let mut excess_byte = 0;
@@ -2580,7 +2580,7 @@ mod tests {
        use crate::ln::ChannelId;
        use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
        use crate::ln::msgs::{self, FinalOnionHopData, OnionErrorPacket};
-       use crate::ln::msgs::NetAddress;
+       use crate::ln::msgs::SocketAddress;
        use crate::routing::gossip::{NodeAlias, NodeId};
        use crate::util::ser::{Writeable, Readable, Hostname, TransactionU16LenLimited};
 
@@ -2601,7 +2601,7 @@ mod tests {
 
        #[cfg(feature = "std")]
        use std::net::{Ipv4Addr, Ipv6Addr};
-       use crate::ln::msgs::NetAddressParseError;
+       use crate::ln::msgs::SocketAddressParseError;
 
        #[test]
        fn encoding_channel_reestablish() {
@@ -2768,24 +2768,24 @@ mod tests {
                };
                let mut addresses = Vec::new();
                if ipv4 {
-                       addresses.push(NetAddress::IPv4 {
+                       addresses.push(SocketAddress::TcpIpV4 {
                                addr: [255, 254, 253, 252],
                                port: 9735
                        });
                }
                if ipv6 {
-                       addresses.push(NetAddress::IPv6 {
+                       addresses.push(SocketAddress::TcpIpV6 {
                                addr: [255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240],
                                port: 9735
                        });
                }
                if onionv2 {
-                       addresses.push(NetAddress::OnionV2(
+                       addresses.push(msgs::SocketAddress::OnionV2(
                                [255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 38, 7]
                        ));
                }
                if onionv3 {
-                       addresses.push(NetAddress::OnionV3 {
+                       addresses.push(msgs::SocketAddress::OnionV3 {
                                ed25519_pubkey: [255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 237, 236, 235, 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224],
                                checksum: 32,
                                version: 16,
@@ -2793,7 +2793,7 @@ mod tests {
                        });
                }
                if hostname {
-                       addresses.push(NetAddress::Hostname {
+                       addresses.push(SocketAddress::Hostname {
                                hostname: Hostname::try_from(String::from("host")).unwrap(),
                                port: 9735,
                        });
@@ -3609,7 +3609,7 @@ mod tests {
                }.encode(), hex::decode("00000000014001010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202").unwrap());
                let init_msg = msgs::Init { features: InitFeatures::from_le_bytes(vec![]),
                        networks: Some(vec![mainnet_hash]),
-                       remote_network_address: Some(NetAddress::IPv4 {
+                       remote_network_address: Some(SocketAddress::TcpIpV4 {
                                addr: [127, 0, 0, 1],
                                port: 1000,
                        }),
@@ -3977,44 +3977,44 @@ mod tests {
 
        #[test]
        #[cfg(feature = "std")]
-       fn test_net_address_from_str() {
-               assert_eq!(NetAddress::IPv4 {
+       fn test_socket_address_from_str() {
+               assert_eq!(SocketAddress::TcpIpV4 {
                        addr: Ipv4Addr::new(127, 0, 0, 1).octets(),
                        port: 1234,
-               }, NetAddress::from_str("127.0.0.1:1234").unwrap());
+               }, SocketAddress::from_str("127.0.0.1:1234").unwrap());
 
-               assert_eq!(NetAddress::IPv6 {
+               assert_eq!(SocketAddress::TcpIpV6 {
                        addr: Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).octets(),
                        port: 1234,
-               }, NetAddress::from_str("[0:0:0:0:0:0:0:1]:1234").unwrap());
+               }, SocketAddress::from_str("[0:0:0:0:0:0:0:1]:1234").unwrap());
                assert_eq!(
-                       NetAddress::Hostname {
+                       SocketAddress::Hostname {
                                hostname: Hostname::try_from("lightning-node.mydomain.com".to_string()).unwrap(),
                                port: 1234,
-                       }, NetAddress::from_str("lightning-node.mydomain.com:1234").unwrap());
+                       }, SocketAddress::from_str("lightning-node.mydomain.com:1234").unwrap());
                assert_eq!(
-                       NetAddress::Hostname {
+                       SocketAddress::Hostname {
                                hostname: Hostname::try_from("example.com".to_string()).unwrap(),
                                port: 1234,
-                       }, NetAddress::from_str("example.com:1234").unwrap());
-               assert_eq!(NetAddress::OnionV3 {
+                       }, SocketAddress::from_str("example.com:1234").unwrap());
+               assert_eq!(SocketAddress::OnionV3 {
                        ed25519_pubkey: [37, 24, 75, 5, 25, 73, 117, 194, 139, 102, 182, 107, 4, 105, 247, 246, 85,
                        111, 177, 172, 49, 137, 167, 155, 64, 221, 163, 47, 31, 33, 71, 3],
                        checksum: 48326,
                        version: 121,
                        port: 1234
-               }, NetAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion:1234").unwrap());
-               assert_eq!(Err(NetAddressParseError::InvalidOnionV3), NetAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6.onion:1234"));
-               assert_eq!(Err(NetAddressParseError::InvalidInput), NetAddress::from_str("127.0.0.1@1234"));
-               assert_eq!(Err(NetAddressParseError::InvalidInput), "".parse::<NetAddress>());
-               assert!(NetAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion.onion:9735:94").is_err());
-               assert!(NetAddress::from_str("wrong$%#.com:1234").is_err());
-               assert_eq!(Err(NetAddressParseError::InvalidPort), NetAddress::from_str("example.com:wrong"));
-               assert!("localhost".parse::<NetAddress>().is_err());
-               assert!("localhost:invalid-port".parse::<NetAddress>().is_err());
-               assert!( "invalid-onion-v3-hostname.onion:8080".parse::<NetAddress>().is_err());
-               assert!("b32.example.onion:invalid-port".parse::<NetAddress>().is_err());
-               assert!("invalid-address".parse::<NetAddress>().is_err());
-               assert!(NetAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion.onion:1234").is_err());
+               }, SocketAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion:1234").unwrap());
+               assert_eq!(Err(SocketAddressParseError::InvalidOnionV3), SocketAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6.onion:1234"));
+               assert_eq!(Err(SocketAddressParseError::InvalidInput), SocketAddress::from_str("127.0.0.1@1234"));
+               assert_eq!(Err(SocketAddressParseError::InvalidInput), "".parse::<SocketAddress>());
+               assert!(SocketAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion.onion:9735:94").is_err());
+               assert!(SocketAddress::from_str("wrong$%#.com:1234").is_err());
+               assert_eq!(Err(SocketAddressParseError::InvalidPort), SocketAddress::from_str("example.com:wrong"));
+               assert!("localhost".parse::<SocketAddress>().is_err());
+               assert!("localhost:invalid-port".parse::<SocketAddress>().is_err());
+               assert!( "invalid-onion-v3-hostname.onion:8080".parse::<SocketAddress>().is_err());
+               assert!("b32.example.onion:invalid-port".parse::<SocketAddress>().is_err());
+               assert!("invalid-address".parse::<SocketAddress>().is_err());
+               assert!(SocketAddress::from_str("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion.onion:1234").is_err());
        }
 }
index 7565246fe3473fb8b5a78b345436b93ffd357231..1e0294073a25d2b01b470bbbbad16d9f9ab3d305 100644 (file)
@@ -23,7 +23,7 @@ use crate::events::{MessageSendEvent, MessageSendEventsProvider, OnionMessagePro
 use crate::ln::ChannelId;
 use crate::ln::features::{InitFeatures, NodeFeatures};
 use crate::ln::msgs;
-use crate::ln::msgs::{ChannelMessageHandler, LightningError, NetAddress, OnionMessageHandler, RoutingMessageHandler};
+use crate::ln::msgs::{ChannelMessageHandler, LightningError, SocketAddress, OnionMessageHandler, RoutingMessageHandler};
 use crate::ln::channelmanager::{SimpleArcChannelManager, SimpleRefChannelManager};
 use crate::util::ser::{VecWriter, Writeable, Writer};
 use crate::ln::peer_channel_encryptor::{PeerChannelEncryptor,NextNoiseStep};
@@ -483,7 +483,7 @@ struct Peer {
        /// handshake and can talk to this peer normally (though use [`Peer::handshake_complete`] to
        /// check this.
        their_features: Option<InitFeatures>,
-       their_net_address: Option<NetAddress>,
+       their_socket_address: Option<SocketAddress>,
 
        pending_outbound_buffer: LinkedList<Vec<u8>>,
        pending_outbound_buffer_first_msg_offset: usize,
@@ -855,28 +855,28 @@ impl core::fmt::Display for OptionalFromDebugger<'_> {
 /// A function used to filter out local or private addresses
 /// <https://www.iana.org./assignments/ipv4-address-space/ipv4-address-space.xhtml>
 /// <https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml>
-fn filter_addresses(ip_address: Option<NetAddress>) -> Option<NetAddress> {
+fn filter_addresses(ip_address: Option<SocketAddress>) -> Option<SocketAddress> {
        match ip_address{
                // For IPv4 range 10.0.0.0 - 10.255.255.255 (10/8)
-               Some(NetAddress::IPv4{addr: [10, _, _, _], port: _}) => None,
+               Some(SocketAddress::TcpIpV4{addr: [10, _, _, _], port: _}) => None,
                // For IPv4 range 0.0.0.0 - 0.255.255.255 (0/8)
-               Some(NetAddress::IPv4{addr: [0, _, _, _], port: _}) => None,
+               Some(SocketAddress::TcpIpV4{addr: [0, _, _, _], port: _}) => None,
                // For IPv4 range 100.64.0.0 - 100.127.255.255 (100.64/10)
-               Some(NetAddress::IPv4{addr: [100, 64..=127, _, _], port: _}) => None,
+               Some(SocketAddress::TcpIpV4{addr: [100, 64..=127, _, _], port: _}) => None,
                // For IPv4 range       127.0.0.0 - 127.255.255.255 (127/8)
-               Some(NetAddress::IPv4{addr: [127, _, _, _], port: _}) => None,
+               Some(SocketAddress::TcpIpV4{addr: [127, _, _, _], port: _}) => None,
                // For IPv4 range       169.254.0.0 - 169.254.255.255 (169.254/16)
-               Some(NetAddress::IPv4{addr: [169, 254, _, _], port: _}) => None,
+               Some(SocketAddress::TcpIpV4{addr: [169, 254, _, _], port: _}) => None,
                // For IPv4 range 172.16.0.0 - 172.31.255.255 (172.16/12)
-               Some(NetAddress::IPv4{addr: [172, 16..=31, _, _], port: _}) => None,
+               Some(SocketAddress::TcpIpV4{addr: [172, 16..=31, _, _], port: _}) => None,
                // For IPv4 range 192.168.0.0 - 192.168.255.255 (192.168/16)
-               Some(NetAddress::IPv4{addr: [192, 168, _, _], port: _}) => None,
+               Some(SocketAddress::TcpIpV4{addr: [192, 168, _, _], port: _}) => None,
                // For IPv4 range 192.88.99.0 - 192.88.99.255  (192.88.99/24)
-               Some(NetAddress::IPv4{addr: [192, 88, 99, _], port: _}) => None,
+               Some(SocketAddress::TcpIpV4{addr: [192, 88, 99, _], port: _}) => None,
                // For IPv6 range 2000:0000:0000:0000:0000:0000:0000:0000 - 3fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (2000::/3)
-               Some(NetAddress::IPv6{addr: [0x20..=0x3F, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], port: _}) => ip_address,
+               Some(SocketAddress::TcpIpV6{addr: [0x20..=0x3F, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _], port: _}) => ip_address,
                // For remaining addresses
-               Some(NetAddress::IPv6{addr: _, port: _}) => None,
+               Some(SocketAddress::TcpIpV6{addr: _, port: _}) => None,
                Some(..) => ip_address,
                None => None,
        }
@@ -933,14 +933,14 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
        ///
        /// The returned `Option`s will only be `Some` if an address had been previously given via
        /// [`Self::new_outbound_connection`] or [`Self::new_inbound_connection`].
-       pub fn get_peer_node_ids(&self) -> Vec<(PublicKey, Option<NetAddress>)> {
+       pub fn get_peer_node_ids(&self) -> Vec<(PublicKey, Option<SocketAddress>)> {
                let peers = self.peers.read().unwrap();
                peers.values().filter_map(|peer_mutex| {
                        let p = peer_mutex.lock().unwrap();
                        if !p.handshake_complete() {
                                return None;
                        }
-                       Some((p.their_node_id.unwrap().0, p.their_net_address.clone()))
+                       Some((p.their_node_id.unwrap().0, p.their_socket_address.clone()))
                }).collect()
        }
 
@@ -973,7 +973,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
        /// [`socket_disconnected`].
        ///
        /// [`socket_disconnected`]: PeerManager::socket_disconnected
-       pub fn new_outbound_connection(&self, their_node_id: PublicKey, descriptor: Descriptor, remote_network_address: Option<NetAddress>) -> Result<Vec<u8>, PeerHandleError> {
+       pub fn new_outbound_connection(&self, their_node_id: PublicKey, descriptor: Descriptor, remote_network_address: Option<SocketAddress>) -> Result<Vec<u8>, PeerHandleError> {
                let mut peer_encryptor = PeerChannelEncryptor::new_outbound(their_node_id.clone(), self.get_ephemeral_key());
                let res = peer_encryptor.get_act_one(&self.secp_ctx).to_vec();
                let pending_read_buffer = [0; 50].to_vec(); // Noise act two is 50 bytes
@@ -989,7 +989,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                        channel_encryptor: peer_encryptor,
                                        their_node_id: None,
                                        their_features: None,
-                                       their_net_address: remote_network_address,
+                                       their_socket_address: remote_network_address,
 
                                        pending_outbound_buffer: LinkedList::new(),
                                        pending_outbound_buffer_first_msg_offset: 0,
@@ -1030,7 +1030,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
        /// [`socket_disconnected`].
        ///
        /// [`socket_disconnected`]: PeerManager::socket_disconnected
-       pub fn new_inbound_connection(&self, descriptor: Descriptor, remote_network_address: Option<NetAddress>) -> Result<(), PeerHandleError> {
+       pub fn new_inbound_connection(&self, descriptor: Descriptor, remote_network_address: Option<SocketAddress>) -> Result<(), PeerHandleError> {
                let peer_encryptor = PeerChannelEncryptor::new_inbound(&self.node_signer);
                let pending_read_buffer = [0; 50].to_vec(); // Noise act one is 50 bytes
 
@@ -1045,7 +1045,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                        channel_encryptor: peer_encryptor,
                                        their_node_id: None,
                                        their_features: None,
-                                       their_net_address: remote_network_address,
+                                       their_socket_address: remote_network_address,
 
                                        pending_outbound_buffer: LinkedList::new(),
                                        pending_outbound_buffer_first_msg_offset: 0,
@@ -1368,7 +1368,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                                                insert_node_id!();
                                                                let features = self.init_features(&their_node_id);
                                                                let networks = self.message_handler.chan_handler.get_genesis_hashes();
-                                                               let resp = msgs::Init { features, networks, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
+                                                               let resp = msgs::Init { features, networks, remote_network_address: filter_addresses(peer.their_socket_address.clone()) };
                                                                self.enqueue_message(peer, &resp);
                                                                peer.awaiting_pong_timer_tick_intervals = 0;
                                                        },
@@ -1381,7 +1381,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                                                insert_node_id!();
                                                                let features = self.init_features(&their_node_id);
                                                                let networks = self.message_handler.chan_handler.get_genesis_hashes();
-                                                               let resp = msgs::Init { features, networks, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
+                                                               let resp = msgs::Init { features, networks, remote_network_address: filter_addresses(peer.their_socket_address.clone()) };
                                                                self.enqueue_message(peer, &resp);
                                                                peer.awaiting_pong_timer_tick_intervals = 0;
                                                        },
@@ -2399,7 +2399,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
        // be absurd. We ensure this by checking that at least 100 (our stated public contract on when
        // broadcast_node_announcement panics) of the maximum-length addresses would fit in a 64KB
        // message...
-       const HALF_MESSAGE_IS_ADDRS: u32 = ::core::u16::MAX as u32 / (NetAddress::MAX_LEN as u32 + 1) / 2;
+       const HALF_MESSAGE_IS_ADDRS: u32 = ::core::u16::MAX as u32 / (SocketAddress::MAX_LEN as u32 + 1) / 2;
        #[deny(const_err)]
        #[allow(dead_code)]
        // ...by failing to compile if the number of addresses that would be half of a message is
@@ -2421,7 +2421,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
        /// Panics if `addresses` is absurdly large (more than 100).
        ///
        /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
-       pub fn broadcast_node_announcement(&self, rgb: [u8; 3], alias: [u8; 32], mut addresses: Vec<NetAddress>) {
+       pub fn broadcast_node_announcement(&self, rgb: [u8; 3], alias: [u8; 32], mut addresses: Vec<SocketAddress>) {
                if addresses.len() > 100 {
                        panic!("More than half the message size was taken up by public addresses!");
                }
@@ -2488,7 +2488,7 @@ mod tests {
        use crate::ln::peer_channel_encryptor::PeerChannelEncryptor;
        use crate::ln::peer_handler::{CustomMessageHandler, PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler, filter_addresses};
        use crate::ln::{msgs, wire};
-       use crate::ln::msgs::{LightningError, NetAddress};
+       use crate::ln::msgs::{LightningError, SocketAddress};
        use crate::util::test_utils;
 
        use bitcoin::Network;
@@ -2647,13 +2647,13 @@ mod tests {
                        fd: 1, outbound_data: Arc::new(Mutex::new(Vec::new())),
                        disconnect: Arc::new(AtomicBool::new(false)),
                };
-               let addr_a = NetAddress::IPv4{addr: [127, 0, 0, 1], port: 1000};
+               let addr_a = SocketAddress::TcpIpV4{addr: [127, 0, 0, 1], port: 1000};
                let id_b = peer_b.node_signer.get_node_id(Recipient::Node).unwrap();
                let mut fd_b = FileDescriptor {
                        fd: 1, outbound_data: Arc::new(Mutex::new(Vec::new())),
                        disconnect: Arc::new(AtomicBool::new(false)),
                };
-               let addr_b = NetAddress::IPv4{addr: [127, 0, 0, 1], port: 1001};
+               let addr_b = SocketAddress::TcpIpV4{addr: [127, 0, 0, 1], port: 1001};
                let initial_data = peer_b.new_outbound_connection(id_a, fd_b.clone(), Some(addr_a.clone())).unwrap();
                peer_a.new_inbound_connection(fd_a.clone(), Some(addr_b.clone())).unwrap();
                assert_eq!(peer_a.read_event(&mut fd_a, &initial_data).unwrap(), false);
@@ -2698,12 +2698,12 @@ mod tests {
                                                fd: $id  + ctr * 3, outbound_data: Arc::new(Mutex::new(Vec::new())),
                                                disconnect: Arc::new(AtomicBool::new(false)),
                                        };
-                                       let addr_a = NetAddress::IPv4{addr: [127, 0, 0, 1], port: 1000};
+                                       let addr_a = SocketAddress::TcpIpV4{addr: [127, 0, 0, 1], port: 1000};
                                        let mut fd_b = FileDescriptor {
                                                fd: $id + ctr * 3, outbound_data: Arc::new(Mutex::new(Vec::new())),
                                                disconnect: Arc::new(AtomicBool::new(false)),
                                        };
-                                       let addr_b = NetAddress::IPv4{addr: [127, 0, 0, 1], port: 1001};
+                                       let addr_b = SocketAddress::TcpIpV4{addr: [127, 0, 0, 1], port: 1001};
                                        let initial_data = peers[1].new_outbound_connection(id_a, fd_b.clone(), Some(addr_a.clone())).unwrap();
                                        peers[0].new_inbound_connection(fd_a.clone(), Some(addr_b.clone())).unwrap();
                                        if peers[0].read_event(&mut fd_a, &initial_data).is_err() { break; }
@@ -2770,12 +2770,12 @@ mod tests {
                                fd: 1, outbound_data: Arc::new(Mutex::new(Vec::new())),
                                disconnect: Arc::new(AtomicBool::new(false)),
                        };
-                       let addr_a = NetAddress::IPv4{addr: [127, 0, 0, 1], port: 1000};
+                       let addr_a = SocketAddress::TcpIpV4{addr: [127, 0, 0, 1], port: 1000};
                        let mut fd_b = FileDescriptor {
                                fd: 1, outbound_data: Arc::new(Mutex::new(Vec::new())),
                                disconnect: Arc::new(AtomicBool::new(false)),
                        };
-                       let addr_b = NetAddress::IPv4{addr: [127, 0, 0, 1], port: 1001};
+                       let addr_b = SocketAddress::TcpIpV4{addr: [127, 0, 0, 1], port: 1001};
                        let initial_data = peer_b.new_outbound_connection(id_a, fd_b.clone(), Some(addr_a.clone())).unwrap();
                        peer_a.new_inbound_connection(fd_a.clone(), Some(addr_b.clone())).unwrap();
                        assert_eq!(peer_a.read_event(&mut fd_a, &initial_data).unwrap(), false);
@@ -2806,12 +2806,12 @@ mod tests {
                                fd: 1, outbound_data: Arc::new(Mutex::new(Vec::new())),
                                disconnect: Arc::new(AtomicBool::new(false)),
                        };
-                       let addr_a = NetAddress::IPv4{addr: [127, 0, 0, 1], port: 1000};
+                       let addr_a = SocketAddress::TcpIpV4{addr: [127, 0, 0, 1], port: 1000};
                        let mut fd_b = FileDescriptor {
                                fd: 1, outbound_data: Arc::new(Mutex::new(Vec::new())),
                                disconnect: Arc::new(AtomicBool::new(false)),
                        };
-                       let addr_b = NetAddress::IPv4{addr: [127, 0, 0, 1], port: 1001};
+                       let addr_b = SocketAddress::TcpIpV4{addr: [127, 0, 0, 1], port: 1001};
                        let initial_data = peer_b.new_outbound_connection(id_a, fd_b.clone(), Some(addr_a.clone())).unwrap();
                        peer_a.new_inbound_connection(fd_a.clone(), Some(addr_b.clone())).unwrap();
                        assert_eq!(peer_a.read_event(&mut fd_a, &initial_data).unwrap(), false);
@@ -2888,7 +2888,7 @@ mod tests {
                        fd: 3, outbound_data: Arc::new(Mutex::new(Vec::new())),
                        disconnect: Arc::new(AtomicBool::new(false)),
                };
-               let addr_dup = NetAddress::IPv4{addr: [127, 0, 0, 1], port: 1003};
+               let addr_dup = SocketAddress::TcpIpV4{addr: [127, 0, 0, 1], port: 1003};
                let id_a = cfgs[0].node_signer.get_node_id(Recipient::Node).unwrap();
                peers[0].new_inbound_connection(fd_dup.clone(), Some(addr_dup.clone())).unwrap();
 
@@ -3026,91 +3026,91 @@ mod tests {
                // Tests the filter_addresses function.
 
                // For (10/8)
-               let ip_address = NetAddress::IPv4{addr: [10, 0, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [10, 0, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [10, 0, 255, 201], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [10, 0, 255, 201], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [10, 255, 255, 255], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [10, 255, 255, 255], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
 
                // For (0/8)
-               let ip_address = NetAddress::IPv4{addr: [0, 0, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [0, 0, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [0, 0, 255, 187], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [0, 0, 255, 187], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [0, 255, 255, 255], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [0, 255, 255, 255], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
 
                // For (100.64/10)
-               let ip_address = NetAddress::IPv4{addr: [100, 64, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [100, 64, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [100, 78, 255, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [100, 78, 255, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [100, 127, 255, 255], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [100, 127, 255, 255], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
 
                // For (127/8)
-               let ip_address = NetAddress::IPv4{addr: [127, 0, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [127, 0, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [127, 65, 73, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [127, 65, 73, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [127, 255, 255, 255], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [127, 255, 255, 255], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
 
                // For (169.254/16)
-               let ip_address = NetAddress::IPv4{addr: [169, 254, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [169, 254, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [169, 254, 221, 101], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [169, 254, 221, 101], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [169, 254, 255, 255], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [169, 254, 255, 255], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
 
                // For (172.16/12)
-               let ip_address = NetAddress::IPv4{addr: [172, 16, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [172, 16, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [172, 27, 101, 23], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [172, 27, 101, 23], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [172, 31, 255, 255], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [172, 31, 255, 255], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
 
                // For (192.168/16)
-               let ip_address = NetAddress::IPv4{addr: [192, 168, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [192, 168, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [192, 168, 205, 159], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [192, 168, 205, 159], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [192, 168, 255, 255], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [192, 168, 255, 255], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
 
                // For (192.88.99/24)
-               let ip_address = NetAddress::IPv4{addr: [192, 88, 99, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [192, 88, 99, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [192, 88, 99, 140], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [192, 88, 99, 140], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv4{addr: [192, 88, 99, 255], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [192, 88, 99, 255], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
 
                // For other IPv4 addresses
-               let ip_address = NetAddress::IPv4{addr: [188, 255, 99, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [188, 255, 99, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), Some(ip_address.clone()));
-               let ip_address = NetAddress::IPv4{addr: [123, 8, 129, 14], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [123, 8, 129, 14], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), Some(ip_address.clone()));
-               let ip_address = NetAddress::IPv4{addr: [2, 88, 9, 255], port: 1000};
+               let ip_address = SocketAddress::TcpIpV4{addr: [2, 88, 9, 255], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), Some(ip_address.clone()));
 
                // For (2000::/3)
-               let ip_address = NetAddress::IPv6{addr: [32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV6{addr: [32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), Some(ip_address.clone()));
-               let ip_address = NetAddress::IPv6{addr: [45, 34, 209, 190, 0, 123, 55, 34, 0, 0, 3, 27, 201, 0, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV6{addr: [45, 34, 209, 190, 0, 123, 55, 34, 0, 0, 3, 27, 201, 0, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), Some(ip_address.clone()));
-               let ip_address = NetAddress::IPv6{addr: [63, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], port: 1000};
+               let ip_address = SocketAddress::TcpIpV6{addr: [63, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), Some(ip_address.clone()));
 
                // For other IPv6 addresses
-               let ip_address = NetAddress::IPv6{addr: [24, 240, 12, 32, 0, 0, 0, 0, 20, 97, 0, 32, 121, 254, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV6{addr: [24, 240, 12, 32, 0, 0, 0, 0, 20, 97, 0, 32, 121, 254, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv6{addr: [68, 23, 56, 63, 0, 0, 2, 7, 75, 109, 0, 39, 0, 0, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV6{addr: [68, 23, 56, 63, 0, 0, 2, 7, 75, 109, 0, 39, 0, 0, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
-               let ip_address = NetAddress::IPv6{addr: [101, 38, 140, 230, 100, 0, 30, 98, 0, 26, 0, 0, 57, 96, 0, 0], port: 1000};
+               let ip_address = SocketAddress::TcpIpV6{addr: [101, 38, 140, 230, 100, 0, 30, 98, 0, 26, 0, 0, 57, 96, 0, 0], port: 1000};
                assert_eq!(filter_addresses(Some(ip_address.clone())), None);
 
                // For (None)
index 64f3585b95332d464b7ec593c64d88152369a36f..ef776a44dc11c484526f7f5baeb64db06498710b 100644 (file)
@@ -25,7 +25,7 @@ use bitcoin::blockdata::constants::genesis_block;
 use crate::events::{MessageSendEvent, MessageSendEventsProvider};
 use crate::ln::ChannelId;
 use crate::ln::features::{ChannelFeatures, NodeFeatures, InitFeatures};
-use crate::ln::msgs::{DecodeError, ErrorAction, Init, LightningError, RoutingMessageHandler, NetAddress, MAX_VALUE_MSAT};
+use crate::ln::msgs::{DecodeError, ErrorAction, Init, LightningError, RoutingMessageHandler, SocketAddress, MAX_VALUE_MSAT};
 use crate::ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, GossipTimestampFilter};
 use crate::ln::msgs::{QueryChannelRange, ReplyChannelRange, QueryShortChannelIds, ReplyShortChannelIdsEnd};
 use crate::ln::msgs;
@@ -1128,7 +1128,7 @@ pub struct NodeAnnouncementInfo {
 
 impl NodeAnnouncementInfo {
        /// Internet-level addresses via which one can connect to the node
-       pub fn addresses(&self) -> &[NetAddress] {
+       pub fn addresses(&self) -> &[SocketAddress] {
                self.announcement_message.as_ref()
                        .map(|msg| msg.contents.addresses.as_slice())
                        .unwrap_or_default()
@@ -1137,7 +1137,7 @@ impl NodeAnnouncementInfo {
 
 impl Writeable for NodeAnnouncementInfo {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
-               let empty_addresses = Vec::<NetAddress>::new();
+               let empty_addresses = Vec::<SocketAddress>::new();
                write_tlv_fields!(writer, {
                        (0, self.features, required),
                        (2, self.last_update, required),
@@ -1160,7 +1160,7 @@ impl Readable for NodeAnnouncementInfo {
                        (8, announcement_message, option),
                        (10, _addresses, optional_vec), // deprecated, not used anymore
                });
-               let _: Option<Vec<NetAddress>> = _addresses;
+               let _: Option<Vec<SocketAddress>> = _addresses;
                Ok(Self { features: features.0.unwrap(), last_update: last_update.0.unwrap(), rgb: rgb.0.unwrap(),
                        alias: alias.0.unwrap(), announcement_message })
        }
@@ -1236,7 +1236,7 @@ impl Writeable for NodeInfo {
 }
 
 // A wrapper allowing for the optional deserialization of `NodeAnnouncementInfo`. Utilizing this is
-// necessary to maintain compatibility with previous serializations of `NetAddress` that have an
+// necessary to maintain compatibility with previous serializations of `SocketAddress` that have an
 // invalid hostname set. We ignore and eat all errors until we are either able to read a
 // `NodeAnnouncementInfo` or hit a `ShortRead`, i.e., read the TLV field to the end.
 struct NodeAnnouncementInfoDeserWrapper(NodeAnnouncementInfo);
@@ -2039,7 +2039,7 @@ impl ReadOnlyNetworkGraph<'_> {
        /// Get network addresses by node id.
        /// Returns None if the requested node is completely unknown,
        /// or if node announcement for the node was never received.
-       pub fn get_addresses(&self, pubkey: &PublicKey) -> Option<Vec<NetAddress>> {
+       pub fn get_addresses(&self, pubkey: &PublicKey) -> Option<Vec<SocketAddress>> {
                self.nodes.get(&NodeId::from_pubkey(&pubkey))
                        .and_then(|node| node.announcement_info.as_ref().map(|ann| ann.addresses().to_vec()))
        }
diff --git a/pending_changelog/move_netaddress_to_socketaddress.txt b/pending_changelog/move_netaddress_to_socketaddress.txt
new file mode 100644 (file)
index 0000000..5153ed1
--- /dev/null
@@ -0,0 +1 @@
+* The `NetAddress` has been moved to `SocketAddress`. The fieds `IPv4` and `IPv6` are also rename to `TcpIpV4` and `TcpIpV6` (#2358).