@@ -545,6 +545,13 @@ pub enum NetAddress {
545545 /// The port on which the node is listening.
546546 port : u16 ,
547547 } ,
548+ /// A websocket address/port on which the peer is listening.
549+ Websocket {
550+ /// The hostname on which the node is listening.
551+ hostname : Hostname ,
552+ /// The port on which the node is listening.
553+ port : u16 ,
554+ } ,
548555}
549556impl NetAddress {
550557 /// Gets the ID of this address type. Addresses in [`NodeAnnouncement`] messages should be sorted
@@ -556,6 +563,7 @@ impl NetAddress {
556563 & NetAddress :: OnionV2 ( _) => { 3 } ,
557564 & NetAddress :: OnionV3 { ..} => { 4 } ,
558565 & NetAddress :: Hostname { ..} => { 5 } ,
566+ & NetAddress :: Websocket { ..} => { 6 } ,
559567 }
560568 }
561569
@@ -568,6 +576,8 @@ impl NetAddress {
568576 & NetAddress :: OnionV3 { .. } => { 37 } ,
569577 // Consists of 1-byte hostname length, hostname bytes, and 2-byte port.
570578 & NetAddress :: Hostname { ref hostname, .. } => { u16:: from ( hostname. len ( ) ) + 3 } ,
579+ // Consists of 1-byte hostname length, hostname bytes, and 2-byte port.
580+ & NetAddress :: Websocket { ref hostname, ..} => { u16:: from ( hostname. len ( ) ) + 3 } ,
571581 }
572582 }
573583
@@ -606,6 +616,11 @@ impl Writeable for NetAddress {
606616 hostname. write ( writer) ?;
607617 port. write ( writer) ?;
608618 } ,
619+ & NetAddress :: Websocket { ref hostname, ref port } => {
620+ 6u8 . write ( writer) ?;
621+ hostname. write ( writer) ?;
622+ port. write ( writer) ?;
623+ } ,
609624 }
610625 Ok ( ( ) )
611626 }
@@ -642,6 +657,12 @@ impl Readable for Result<NetAddress, u8> {
642657 port : Readable :: read ( reader) ?,
643658 } ) )
644659 } ,
660+ 6 => {
661+ Ok ( Ok ( NetAddress :: Websocket {
662+ hostname : Readable :: read ( reader) ?,
663+ port : Readable :: read ( reader) ?,
664+ } ) )
665+ } ,
645666 _ => return Ok ( Err ( byte) ) ,
646667 }
647668 }
@@ -2288,7 +2309,7 @@ mod tests {
22882309 do_encoding_channel_announcement ( true , true ) ;
22892310 }
22902311
2291- fn do_encoding_node_announcement ( unknown_features_bits : bool , ipv4 : bool , ipv6 : bool , onionv2 : bool , onionv3 : bool , hostname : bool , excess_address_data : bool , excess_data : bool ) {
2312+ fn do_encoding_node_announcement ( unknown_features_bits : bool , ipv4 : bool , ipv6 : bool , onionv2 : bool , onionv3 : bool , hostname : bool , websocket : bool , excess_address_data : bool , excess_data : bool ) {
22922313 let secp_ctx = Secp256k1 :: new ( ) ;
22932314 let ( privkey_1, pubkey_1) = get_keys_from ! ( "0101010101010101010101010101010101010101010101010101010101010101" , secp_ctx) ;
22942315 let sig_1 = get_sig_on ! ( privkey_1, secp_ctx, String :: from( "01010101010101010101010101010101" ) ) ;
@@ -2330,6 +2351,12 @@ mod tests {
23302351 port : 9735 ,
23312352 } ) ;
23322353 }
2354+ if websocket {
2355+ addresses. push ( msgs:: NetAddress :: Websocket {
2356+ hostname : Hostname :: try_from ( String :: from ( "host" ) ) . unwrap ( ) ,
2357+ port : 9736 ,
2358+ } ) ;
2359+ }
23332360 let mut addr_len = 0 ;
23342361 for addr in & addresses {
23352362 addr_len += addr. len ( ) + 1 ;
@@ -2373,6 +2400,9 @@ mod tests {
23732400 if hostname {
23742401 target_value. append ( & mut hex:: decode ( "0504686f73742607" ) . unwrap ( ) ) ;
23752402 }
2403+ if websocket {
2404+ target_value. append ( & mut hex:: decode ( "0604686f73742608" ) . unwrap ( ) ) ;
2405+ }
23762406 if excess_address_data {
23772407 target_value. append ( & mut hex:: decode ( "216c280b5395a2546e7e4b2663e04f811622f15a4f92e83aa2e92ba2a573c139142c54ae63072a1ec1ee7dc0c04bde5c847806172aa05c92c22ae8e308d1d269" ) . unwrap ( ) ) ;
23782408 }
@@ -2384,16 +2414,16 @@ mod tests {
23842414
23852415 #[ test]
23862416 fn encoding_node_announcement ( ) {
2387- do_encoding_node_announcement ( true , true , true , true , true , true , true , true ) ;
2388- do_encoding_node_announcement ( false , false , false , false , false , false , false , false ) ;
2389- do_encoding_node_announcement ( false , true , false , false , false , false , false , false ) ;
2390- do_encoding_node_announcement ( false , false , true , false , false , false , false , false ) ;
2391- do_encoding_node_announcement ( false , false , false , true , false , false , false , false ) ;
2392- do_encoding_node_announcement ( false , false , false , false , true , false , false , false ) ;
2393- do_encoding_node_announcement ( false , false , false , false , false , true , false , false ) ;
2394- do_encoding_node_announcement ( false , false , false , false , false , false , true , false ) ;
2395- do_encoding_node_announcement ( false , true , false , true , false , false , true , false ) ;
2396- do_encoding_node_announcement ( false , false , true , false , true , false , false , false ) ;
2417+ do_encoding_node_announcement ( true , true , true , true , true , true , true , true , true ) ;
2418+ do_encoding_node_announcement ( false , false , false , false , false , false , false , false , false ) ;
2419+ do_encoding_node_announcement ( false , true , false , false , false , false , false , false , false ) ;
2420+ do_encoding_node_announcement ( false , false , true , false , false , false , false , false , false ) ;
2421+ do_encoding_node_announcement ( false , false , false , true , false , false , false , false , false ) ;
2422+ do_encoding_node_announcement ( false , false , false , false , true , false , false , false , false ) ;
2423+ do_encoding_node_announcement ( false , false , false , false , false , true , false , false , false ) ;
2424+ do_encoding_node_announcement ( false , false , false , false , false , false , false , true , false ) ;
2425+ do_encoding_node_announcement ( false , true , false , true , false , false , false , true , false ) ;
2426+ do_encoding_node_announcement ( false , false , true , false , true , false , false , false , false ) ;
23972427 }
23982428
23992429 fn do_encoding_channel_update ( direction : bool , disable : bool , excess_data : bool ) {
0 commit comments