@@ -34,6 +34,7 @@ use util::events::{Event, EventHandler, MessageSendEvent, MessageSendEventsProvi
3434use util:: scid_utils:: { block_from_scid, scid_from_parts, MAX_SCID_BLOCK } ;
3535
3636use io;
37+ use io_extras:: { copy, sink} ;
3738use prelude:: * ;
3839use alloc:: collections:: { BTreeMap , btree_map:: Entry as BtreeEntry } ;
3940use core:: { cmp, fmt} ;
@@ -1089,11 +1090,54 @@ impl fmt::Display for NodeInfo {
10891090 }
10901091}
10911092
1092- impl_writeable_tlv_based ! ( NodeInfo , {
1093- ( 0 , lowest_inbound_channel_fees, option) ,
1094- ( 2 , announcement_info, option) ,
1095- ( 4 , channels, vec_type) ,
1096- } ) ;
1093+ impl Writeable for NodeInfo {
1094+ fn write < W : :: util:: ser:: Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
1095+ write_tlv_fields ! ( writer, {
1096+ ( 0 , self . lowest_inbound_channel_fees, option) ,
1097+ ( 2 , self . announcement_info, option) ,
1098+ ( 4 , self . channels, vec_type) ,
1099+ } ) ;
1100+ Ok ( ( ) )
1101+ }
1102+ }
1103+
1104+ // A wrapper allowing for the optional deseralization of `NodeAnnouncementInfo`. Utilizing this is
1105+ // necessary to maintain compatibility with previous serializations of `NetAddress` that have an
1106+ // invalid hostname set. We ignore and eat all errors until we are either able to read a
1107+ // `NodeAnnouncementInfo` or hit a `ShortRead`, i.e., read the TLV field to the end.
1108+ struct NodeAnnouncementInfoDeserWrapper ( NodeAnnouncementInfo ) ;
1109+
1110+ impl MaybeReadable for NodeAnnouncementInfoDeserWrapper {
1111+ fn read < R : io:: Read > ( reader : & mut R ) -> Result < Option < Self > , DecodeError > {
1112+ match :: util:: ser:: Readable :: read ( reader) {
1113+ Ok ( node_announcement_info) => return Ok ( Some ( Self ( node_announcement_info) ) ) ,
1114+ Err ( _) => {
1115+ copy ( reader, & mut sink ( ) ) . unwrap ( ) ;
1116+ return Ok ( None )
1117+ } ,
1118+ } ;
1119+ }
1120+ }
1121+
1122+ impl Readable for NodeInfo {
1123+ fn read < R : io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
1124+ init_tlv_field_var ! ( lowest_inbound_channel_fees, option) ;
1125+ let mut announcement_info_wrap: Option < NodeAnnouncementInfoDeserWrapper > = None ;
1126+ init_tlv_field_var ! ( channels, vec_type) ;
1127+
1128+ read_tlv_fields ! ( reader, {
1129+ ( 0 , lowest_inbound_channel_fees, option) ,
1130+ ( 2 , announcement_info_wrap, ignorable) ,
1131+ ( 4 , channels, vec_type) ,
1132+ } ) ;
1133+
1134+ Ok ( NodeInfo {
1135+ lowest_inbound_channel_fees : init_tlv_based_struct_field ! ( lowest_inbound_channel_fees, option) ,
1136+ announcement_info : announcement_info_wrap. map ( |w| w. 0 ) ,
1137+ channels : init_tlv_based_struct_field ! ( channels, vec_type) ,
1138+ } )
1139+ }
1140+ }
10971141
10981142const SERIALIZATION_VERSION : u8 = 1 ;
10991143const MIN_SERIALIZATION_VERSION : u8 = 1 ;
0 commit comments