@@ -40,7 +40,7 @@ use io_extras::read_to_end;
40
40
41
41
use util:: events:: MessageSendEventsProvider ;
42
42
use util:: logger;
43
- use util:: ser:: { Readable , Writeable , Writer , FixedLengthReader , HighZeroBytesDroppedVarInt } ;
43
+ use util:: ser:: { Readable , Writeable , Writer , FixedLengthReader , HighZeroBytesDroppedVarInt , ShortAsciiString } ;
44
44
45
45
use ln:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
46
46
@@ -442,6 +442,14 @@ pub enum NetAddress {
442
442
/// The port on which the node is listening
443
443
port : u16 ,
444
444
} ,
445
+ /// A DNS hostname/port on which the peer is listening.
446
+ DNSHostname {
447
+ /// The hostname as an ASCII string with a variable length below or equal to 255.
448
+ /// Can be a Punycode encoding.
449
+ hostname : ShortAsciiString ,
450
+ /// The port on which the node is listening.
451
+ port : u16 ,
452
+ } ,
445
453
}
446
454
impl NetAddress {
447
455
/// Gets the ID of this address type. Addresses in node_announcement messages should be sorted
@@ -452,6 +460,7 @@ impl NetAddress {
452
460
& NetAddress :: IPv6 { ..} => { 2 } ,
453
461
& NetAddress :: OnionV2 ( _) => { 3 } ,
454
462
& NetAddress :: OnionV3 { ..} => { 4 } ,
463
+ & NetAddress :: DNSHostname { ..} => { 5 } ,
455
464
}
456
465
}
457
466
@@ -462,11 +471,12 @@ impl NetAddress {
462
471
& NetAddress :: IPv6 { .. } => { 18 } ,
463
472
& NetAddress :: OnionV2 ( _) => { 12 } ,
464
473
& NetAddress :: OnionV3 { .. } => { 37 } ,
474
+ & NetAddress :: DNSHostname { ref hostname, .. } => { u16:: from ( hostname. len ( ) ) + 3 } ,
465
475
}
466
476
}
467
477
468
478
/// The maximum length of any address descriptor, not including the 1-byte type
469
- pub ( crate ) const MAX_LEN : u16 = 37 ;
479
+ pub ( crate ) const MAX_LEN : u16 = u8 :: MAX as u16 + 3 ;
470
480
}
471
481
472
482
impl Writeable for NetAddress {
@@ -492,7 +502,12 @@ impl Writeable for NetAddress {
492
502
checksum. write ( writer) ?;
493
503
version. write ( writer) ?;
494
504
port. write ( writer) ?;
495
- }
505
+ } ,
506
+ & NetAddress :: DNSHostname { ref hostname, ref port } => {
507
+ 5u8 . write ( writer) ?;
508
+ hostname. write ( writer) ?;
509
+ port. write ( writer) ?;
510
+ } ,
496
511
}
497
512
Ok ( ( ) )
498
513
}
@@ -523,6 +538,12 @@ impl Readable for Result<NetAddress, u8> {
523
538
port : Readable :: read ( reader) ?,
524
539
} ) )
525
540
} ,
541
+ 5 => {
542
+ Ok ( Ok ( NetAddress :: DNSHostname {
543
+ hostname : Readable :: read ( reader) ?,
544
+ port : Readable :: read ( reader) ?,
545
+ } ) )
546
+ } ,
526
547
_ => return Ok ( Err ( byte) ) ,
527
548
}
528
549
}
@@ -1829,7 +1850,7 @@ mod tests {
1829
1850
use ln:: features:: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , NodeFeatures } ;
1830
1851
use ln:: msgs;
1831
1852
use ln:: msgs:: { FinalOnionHopData , OptionalField , OnionErrorPacket , OnionHopDataFormat } ;
1832
- use util:: ser:: { Writeable , Readable } ;
1853
+ use util:: ser:: { Writeable , Readable , ShortAsciiString } ;
1833
1854
1834
1855
use bitcoin:: hashes:: hex:: FromHex ;
1835
1856
use bitcoin:: util:: address:: Address ;
@@ -1843,6 +1864,7 @@ mod tests {
1843
1864
1844
1865
use io:: Cursor ;
1845
1866
use prelude:: * ;
1867
+ use std:: convert:: TryFrom ;
1846
1868
1847
1869
#[ test]
1848
1870
fn encoding_channel_reestablish_no_secret ( ) {
@@ -1971,7 +1993,7 @@ mod tests {
1971
1993
do_encoding_channel_announcement ( true , true ) ;
1972
1994
}
1973
1995
1974
- fn do_encoding_node_announcement ( unknown_features_bits : bool , ipv4 : bool , ipv6 : bool , onionv2 : bool , onionv3 : bool , excess_address_data : bool , excess_data : bool ) {
1996
+ fn do_encoding_node_announcement ( unknown_features_bits : bool , ipv4 : bool , ipv6 : bool , onionv2 : bool , onionv3 : bool , dns_hostname : bool , excess_address_data : bool , excess_data : bool ) {
1975
1997
let secp_ctx = Secp256k1 :: new ( ) ;
1976
1998
let ( privkey_1, pubkey_1) = get_keys_from ! ( "0101010101010101010101010101010101010101010101010101010101010101" , secp_ctx) ;
1977
1999
let sig_1 = get_sig_on ! ( privkey_1, secp_ctx, String :: from( "01010101010101010101010101010101" ) ) ;
@@ -2007,6 +2029,12 @@ mod tests {
2007
2029
port : 9735
2008
2030
} ) ;
2009
2031
}
2032
+ if dns_hostname {
2033
+ addresses. push ( msgs:: NetAddress :: DNSHostname {
2034
+ hostname : ShortAsciiString :: try_from ( "host" ) . unwrap ( ) ,
2035
+ port : 9735 ,
2036
+ } ) ;
2037
+ }
2010
2038
let mut addr_len = 0 ;
2011
2039
for addr in & addresses {
2012
2040
addr_len += addr. len ( ) + 1 ;
@@ -2047,6 +2075,9 @@ mod tests {
2047
2075
if onionv3 {
2048
2076
target_value. append ( & mut hex:: decode ( "04fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e00020102607" ) . unwrap ( ) ) ;
2049
2077
}
2078
+ if dns_hostname {
2079
+ target_value. append ( & mut hex:: decode ( "0504686f73742607" ) . unwrap ( ) ) ;
2080
+ }
2050
2081
if excess_address_data {
2051
2082
target_value. append ( & mut hex:: decode ( "216c280b5395a2546e7e4b2663e04f811622f15a4f92e83aa2e92ba2a573c139142c54ae63072a1ec1ee7dc0c04bde5c847806172aa05c92c22ae8e308d1d269" ) . unwrap ( ) ) ;
2052
2083
}
@@ -2058,15 +2089,16 @@ mod tests {
2058
2089
2059
2090
#[ test]
2060
2091
fn encoding_node_announcement ( ) {
2061
- do_encoding_node_announcement ( true , true , true , true , true , true , true ) ;
2062
- do_encoding_node_announcement ( false , false , false , false , false , false , false ) ;
2063
- do_encoding_node_announcement ( false , true , false , false , false , false , false ) ;
2064
- do_encoding_node_announcement ( false , false , true , false , false , false , false ) ;
2065
- do_encoding_node_announcement ( false , false , false , true , false , false , false ) ;
2066
- do_encoding_node_announcement ( false , false , false , false , true , false , false ) ;
2067
- do_encoding_node_announcement ( false , false , false , false , false , true , false ) ;
2068
- do_encoding_node_announcement ( false , true , false , true , false , true , false ) ;
2069
- do_encoding_node_announcement ( false , false , true , false , true , false , false ) ;
2092
+ do_encoding_node_announcement ( true , true , true , true , true , true , true , true ) ;
2093
+ do_encoding_node_announcement ( false , false , false , false , false , false , false , false ) ;
2094
+ do_encoding_node_announcement ( false , true , false , false , false , false , false , false ) ;
2095
+ do_encoding_node_announcement ( false , false , true , false , false , false , false , false ) ;
2096
+ do_encoding_node_announcement ( false , false , false , true , false , false , false , false ) ;
2097
+ do_encoding_node_announcement ( false , false , false , false , true , false , false , false ) ;
2098
+ do_encoding_node_announcement ( false , false , false , false , false , true , false , false ) ;
2099
+ do_encoding_node_announcement ( false , false , false , false , false , false , true , false ) ;
2100
+ do_encoding_node_announcement ( false , true , false , true , false , false , true , false ) ;
2101
+ do_encoding_node_announcement ( false , false , true , false , true , false , false , false ) ;
2070
2102
}
2071
2103
2072
2104
fn do_encoding_channel_update ( direction : bool , disable : bool , htlc_maximum_msat : bool , excess_data : bool ) {
0 commit comments