@@ -98,7 +98,7 @@ pub struct Init {
98
98
/// message. A node can decide to use that information to discover a potential update to its
99
99
/// public IPv4 address (NAT) and use that for a [`NodeAnnouncement`] update message containing
100
100
/// the new address.
101
- pub remote_network_address : Option < NetAddress > ,
101
+ pub remote_network_address : Option < SocketAddress > ,
102
102
}
103
103
104
104
/// An [`error`] message to be sent to or received from a peer.
@@ -746,16 +746,16 @@ pub struct AnnouncementSignatures {
746
746
747
747
/// An address which can be used to connect to a remote peer.
748
748
#[ derive( Clone , Debug , PartialEq , Eq ) ]
749
- pub enum NetAddress {
750
- /// An IPv4 address/ port on which the peer is listening.
751
- IPv4 {
749
+ pub enum SocketAddress {
750
+ /// An IPv4 address and port on which the peer is listening.
751
+ TcpIpV4 {
752
752
/// The 4-byte IPv4 address
753
753
addr : [ u8 ; 4 ] ,
754
754
/// The port on which the node is listening
755
755
port : u16 ,
756
756
} ,
757
- /// An IPv6 address/ port on which the peer is listening.
758
- IPv6 {
757
+ /// An IPv6 address and port on which the peer is listening.
758
+ TcpIpV6 {
759
759
/// The 16-byte IPv6 address
760
760
addr : [ u8 ; 16 ] ,
761
761
/// The port on which the node is listening
@@ -788,28 +788,28 @@ pub enum NetAddress {
788
788
port : u16 ,
789
789
} ,
790
790
}
791
- impl NetAddress {
791
+ impl SocketAddress {
792
792
/// Gets the ID of this address type. Addresses in [`NodeAnnouncement`] messages should be sorted
793
793
/// by this.
794
794
pub ( crate ) fn get_id ( & self ) -> u8 {
795
795
match self {
796
- & NetAddress :: IPv4 { ..} => { 1 } ,
797
- & NetAddress :: IPv6 { ..} => { 2 } ,
798
- & NetAddress :: OnionV2 ( _) => { 3 } ,
799
- & NetAddress :: OnionV3 { ..} => { 4 } ,
800
- & NetAddress :: Hostname { ..} => { 5 } ,
796
+ & SocketAddress :: TcpIpV4 { ..} => { 1 } ,
797
+ & SocketAddress :: TcpIpV6 { ..} => { 2 } ,
798
+ & SocketAddress :: OnionV2 ( _) => { 3 } ,
799
+ & SocketAddress :: OnionV3 { ..} => { 4 } ,
800
+ & SocketAddress :: Hostname { ..} => { 5 } ,
801
801
}
802
802
}
803
803
804
804
/// Strict byte-length of address descriptor, 1-byte type not recorded
805
805
fn len ( & self ) -> u16 {
806
806
match self {
807
- & NetAddress :: IPv4 { .. } => { 6 } ,
808
- & NetAddress :: IPv6 { .. } => { 18 } ,
809
- & NetAddress :: OnionV2 ( _) => { 12 } ,
810
- & NetAddress :: OnionV3 { .. } => { 37 } ,
807
+ & SocketAddress :: TcpIpV4 { .. } => { 6 } ,
808
+ & SocketAddress :: TcpIpV6 { .. } => { 18 } ,
809
+ & SocketAddress :: OnionV2 ( _) => { 12 } ,
810
+ & SocketAddress :: OnionV3 { .. } => { 37 } ,
811
811
// Consists of 1-byte hostname length, hostname bytes, and 2-byte port.
812
- & NetAddress :: Hostname { ref hostname, .. } => { u16:: from ( hostname. len ( ) ) + 3 } ,
812
+ & SocketAddress :: Hostname { ref hostname, .. } => { u16:: from ( hostname. len ( ) ) + 3 } ,
813
813
}
814
814
}
815
815
@@ -819,31 +819,31 @@ impl NetAddress {
819
819
pub ( crate ) const MAX_LEN : u16 = 258 ;
820
820
}
821
821
822
- impl Writeable for NetAddress {
822
+ impl Writeable for SocketAddress {
823
823
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
824
824
match self {
825
- & NetAddress :: IPv4 { ref addr, ref port } => {
825
+ & SocketAddress :: TcpIpV4 { ref addr, ref port } => {
826
826
1u8 . write ( writer) ?;
827
827
addr. write ( writer) ?;
828
828
port. write ( writer) ?;
829
829
} ,
830
- & NetAddress :: IPv6 { ref addr, ref port } => {
830
+ & SocketAddress :: TcpIpV6 { ref addr, ref port } => {
831
831
2u8 . write ( writer) ?;
832
832
addr. write ( writer) ?;
833
833
port. write ( writer) ?;
834
834
} ,
835
- & NetAddress :: OnionV2 ( bytes) => {
835
+ & SocketAddress :: OnionV2 ( bytes) => {
836
836
3u8 . write ( writer) ?;
837
837
bytes. write ( writer) ?;
838
838
} ,
839
- & NetAddress :: OnionV3 { ref ed25519_pubkey, ref checksum, ref version, ref port } => {
839
+ & SocketAddress :: OnionV3 { ref ed25519_pubkey, ref checksum, ref version, ref port } => {
840
840
4u8 . write ( writer) ?;
841
841
ed25519_pubkey. write ( writer) ?;
842
842
checksum. write ( writer) ?;
843
843
version. write ( writer) ?;
844
844
port. write ( writer) ?;
845
845
} ,
846
- & NetAddress :: Hostname { ref hostname, ref port } => {
846
+ & SocketAddress :: Hostname { ref hostname, ref port } => {
847
847
5u8 . write ( writer) ?;
848
848
hostname. write ( writer) ?;
849
849
port. write ( writer) ?;
@@ -853,33 +853,33 @@ impl Writeable for NetAddress {
853
853
}
854
854
}
855
855
856
- impl Readable for Result < NetAddress , u8 > {
857
- fn read < R : Read > ( reader : & mut R ) -> Result < Result < NetAddress , u8 > , DecodeError > {
856
+ impl Readable for Result < SocketAddress , u8 > {
857
+ fn read < R : Read > ( reader : & mut R ) -> Result < Result < SocketAddress , u8 > , DecodeError > {
858
858
let byte = <u8 as Readable >:: read ( reader) ?;
859
859
match byte {
860
860
1 => {
861
- Ok ( Ok ( NetAddress :: IPv4 {
861
+ Ok ( Ok ( SocketAddress :: TcpIpV4 {
862
862
addr : Readable :: read ( reader) ?,
863
863
port : Readable :: read ( reader) ?,
864
864
} ) )
865
865
} ,
866
866
2 => {
867
- Ok ( Ok ( NetAddress :: IPv6 {
867
+ Ok ( Ok ( SocketAddress :: TcpIpV6 {
868
868
addr : Readable :: read ( reader) ?,
869
869
port : Readable :: read ( reader) ?,
870
870
} ) )
871
871
} ,
872
- 3 => Ok ( Ok ( NetAddress :: OnionV2 ( Readable :: read ( reader) ?) ) ) ,
872
+ 3 => Ok ( Ok ( SocketAddress :: OnionV2 ( Readable :: read ( reader) ?) ) ) ,
873
873
4 => {
874
- Ok ( Ok ( NetAddress :: OnionV3 {
874
+ Ok ( Ok ( SocketAddress :: OnionV3 {
875
875
ed25519_pubkey : Readable :: read ( reader) ?,
876
876
checksum : Readable :: read ( reader) ?,
877
877
version : Readable :: read ( reader) ?,
878
878
port : Readable :: read ( reader) ?,
879
879
} ) )
880
880
} ,
881
881
5 => {
882
- Ok ( Ok ( NetAddress :: Hostname {
882
+ Ok ( Ok ( SocketAddress :: Hostname {
883
883
hostname : Readable :: read ( reader) ?,
884
884
port : Readable :: read ( reader) ?,
885
885
} ) )
@@ -889,8 +889,8 @@ impl Readable for Result<NetAddress, u8> {
889
889
}
890
890
}
891
891
892
- impl Readable for NetAddress {
893
- fn read < R : Read > ( reader : & mut R ) -> Result < NetAddress , DecodeError > {
892
+ impl Readable for SocketAddress {
893
+ fn read < R : Read > ( reader : & mut R ) -> Result < SocketAddress , DecodeError > {
894
894
match Readable :: read ( reader) {
895
895
Ok ( Ok ( res) ) => Ok ( res) ,
896
896
Ok ( Err ( _) ) => Err ( DecodeError :: UnknownVersion ) ,
@@ -938,7 +938,7 @@ pub struct UnsignedNodeAnnouncement {
938
938
/// This should be sanitized before use. There is no guarantee of uniqueness.
939
939
pub alias : NodeAlias ,
940
940
/// List of addresses on which this node is reachable
941
- pub addresses : Vec < NetAddress > ,
941
+ pub addresses : Vec < SocketAddress > ,
942
942
pub ( crate ) excess_address_data : Vec < u8 > ,
943
943
pub ( crate ) excess_data : Vec < u8 > ,
944
944
}
@@ -1773,7 +1773,7 @@ impl Readable for Init {
1773
1773
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
1774
1774
let global_features: InitFeatures = Readable :: read ( r) ?;
1775
1775
let features: InitFeatures = Readable :: read ( r) ?;
1776
- let mut remote_network_address: Option < NetAddress > = None ;
1776
+ let mut remote_network_address: Option < SocketAddress > = None ;
1777
1777
let mut networks: Option < WithoutLength < Vec < ChainHash > > > = None ;
1778
1778
decode_tlv_stream ! ( r, {
1779
1779
( 1 , networks, option) ,
@@ -2272,7 +2272,7 @@ impl Readable for UnsignedNodeAnnouncement {
2272
2272
let alias: NodeAlias = Readable :: read ( r) ?;
2273
2273
2274
2274
let addr_len: u16 = Readable :: read ( r) ?;
2275
- let mut addresses: Vec < NetAddress > = Vec :: new ( ) ;
2275
+ let mut addresses: Vec < SocketAddress > = Vec :: new ( ) ;
2276
2276
let mut addr_readpos = 0 ;
2277
2277
let mut excess = false ;
2278
2278
let mut excess_byte = 0 ;
@@ -2663,32 +2663,32 @@ mod tests {
2663
2663
} ;
2664
2664
let mut addresses = Vec :: new ( ) ;
2665
2665
if ipv4 {
2666
- addresses. push ( msgs:: NetAddress :: IPv4 {
2666
+ addresses. push ( msgs:: SocketAddress :: TcpIpV4 {
2667
2667
addr : [ 255 , 254 , 253 , 252 ] ,
2668
2668
port : 9735
2669
2669
} ) ;
2670
2670
}
2671
2671
if ipv6 {
2672
- addresses. push ( msgs:: NetAddress :: IPv6 {
2672
+ addresses. push ( msgs:: SocketAddress :: TcpIpV6 {
2673
2673
addr : [ 255 , 254 , 253 , 252 , 251 , 250 , 249 , 248 , 247 , 246 , 245 , 244 , 243 , 242 , 241 , 240 ] ,
2674
2674
port : 9735
2675
2675
} ) ;
2676
2676
}
2677
2677
if onionv2 {
2678
- addresses. push ( msgs:: NetAddress :: OnionV2 (
2678
+ addresses. push ( msgs:: SocketAddress :: OnionV2 (
2679
2679
[ 255 , 254 , 253 , 252 , 251 , 250 , 249 , 248 , 247 , 246 , 38 , 7 ]
2680
2680
) ) ;
2681
2681
}
2682
2682
if onionv3 {
2683
- addresses. push ( msgs:: NetAddress :: OnionV3 {
2683
+ addresses. push ( msgs:: SocketAddress :: OnionV3 {
2684
2684
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 ] ,
2685
2685
checksum : 32 ,
2686
2686
version : 16 ,
2687
2687
port : 9735
2688
2688
} ) ;
2689
2689
}
2690
2690
if hostname {
2691
- addresses. push ( msgs:: NetAddress :: Hostname {
2691
+ addresses. push ( msgs:: SocketAddress :: Hostname {
2692
2692
hostname : Hostname :: try_from ( String :: from ( "host" ) ) . unwrap ( ) ,
2693
2693
port : 9735 ,
2694
2694
} ) ;
@@ -3504,7 +3504,7 @@ mod tests {
3504
3504
} . encode( ) , hex:: decode( "00000000014001010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202" ) . unwrap( ) ) ;
3505
3505
let init_msg = msgs:: Init { features : InitFeatures :: from_le_bytes ( vec ! [ ] ) ,
3506
3506
networks : Some ( vec ! [ mainnet_hash] ) ,
3507
- remote_network_address : Some ( msgs:: NetAddress :: IPv4 {
3507
+ remote_network_address : Some ( msgs:: SocketAddress :: TcpIpV4 {
3508
3508
addr : [ 127 , 0 , 0 , 1 ] ,
3509
3509
port : 1000 ,
3510
3510
} ) ,
0 commit comments