@@ -872,7 +872,7 @@ pub struct ChannelInfo {
872
872
/// The timestamp when we received the announcement, if we are running with feature = "std"
873
873
/// (which we can probably assume we are - no-std environments probably won't have a full
874
874
/// network graph in memory!).
875
- announcement_received_time : u64 ,
875
+ pub announcement_received_time : u64 ,
876
876
}
877
877
878
878
impl ChannelInfo {
@@ -1143,32 +1143,35 @@ pub struct NodeAnnouncementInfo {
1143
1143
/// May be invalid or malicious (eg control chars),
1144
1144
/// should not be exposed to the user.
1145
1145
pub alias : NodeAlias ,
1146
+
1147
+ /// Internet-level addresses via which one can connect to the node
1148
+ pub addresses : Vec < SocketAddress > ,
1149
+
1146
1150
/// An initial announcement of the node
1147
1151
/// Mostly redundant with the data we store in fields explicitly.
1148
1152
/// Everything else is useful only for sending out for initial routing sync.
1149
1153
/// Not stored if contains excess data to prevent DoS.
1150
- pub announcement_message : Option < NodeAnnouncement >
1154
+ pub announcement_message : Option < NodeAnnouncement > ,
1151
1155
}
1152
1156
1153
1157
impl NodeAnnouncementInfo {
1154
1158
/// Internet-level addresses via which one can connect to the node
1155
1159
pub fn addresses ( & self ) -> & [ SocketAddress ] {
1156
1160
self . announcement_message . as_ref ( )
1157
1161
. map ( |msg| msg. contents . addresses . as_slice ( ) )
1158
- . unwrap_or_default ( )
1162
+ . unwrap_or ( self . addresses . as_slice ( ) )
1159
1163
}
1160
1164
}
1161
1165
1162
1166
impl Writeable for NodeAnnouncementInfo {
1163
1167
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
1164
- let empty_addresses = Vec :: < SocketAddress > :: new ( ) ;
1165
1168
write_tlv_fields ! ( writer, {
1166
1169
( 0 , self . features, required) ,
1167
1170
( 2 , self . last_update, required) ,
1168
1171
( 4 , self . rgb, required) ,
1169
1172
( 6 , self . alias, required) ,
1170
1173
( 8 , self . announcement_message, option) ,
1171
- ( 10 , empty_addresses , required_vec) , // Versions prior to 0.0.115 require this field
1174
+ ( 10 , self . addresses , required_vec) , // Versions prior to 0.0.115 require this field
1172
1175
} ) ;
1173
1176
Ok ( ( ) )
1174
1177
}
@@ -1182,11 +1185,16 @@ impl Readable for NodeAnnouncementInfo {
1182
1185
( 4 , rgb, required) ,
1183
1186
( 6 , alias, required) ,
1184
1187
( 8 , announcement_message, option) ,
1185
- ( 10 , _addresses , optional_vec) , // deprecated, not used anymore
1188
+ ( 10 , addresses , optional_vec) ,
1186
1189
} ) ;
1187
- let _: Option < Vec < SocketAddress > > = _addresses;
1188
- Ok ( Self { features : features. 0 . unwrap ( ) , last_update : last_update. 0 . unwrap ( ) , rgb : rgb. 0 . unwrap ( ) ,
1189
- alias : alias. 0 . unwrap ( ) , announcement_message } )
1190
+ Ok ( Self {
1191
+ features : features. 0 . unwrap ( ) ,
1192
+ last_update : last_update. 0 . unwrap ( ) ,
1193
+ rgb : rgb. 0 . unwrap ( ) ,
1194
+ alias : alias. 0 . unwrap ( ) ,
1195
+ addresses : addresses. unwrap_or ( Vec :: new ( ) ) ,
1196
+ announcement_message,
1197
+ } )
1190
1198
}
1191
1199
}
1192
1200
@@ -1504,6 +1512,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1504
1512
last_update : msg. timestamp ,
1505
1513
rgb : msg. rgb ,
1506
1514
alias : msg. alias ,
1515
+ addresses : msg. addresses . clone ( ) ,
1507
1516
announcement_message : if should_relay { full_msg. cloned ( ) } else { None } ,
1508
1517
} ) ;
1509
1518
@@ -3453,6 +3462,7 @@ pub(crate) mod tests {
3453
3462
last_update : 0 ,
3454
3463
rgb : [ 0u8 ; 3 ] ,
3455
3464
alias : NodeAlias ( [ 0u8 ; 32 ] ) ,
3465
+ addresses : announcement_message. contents . addresses . clone ( ) ,
3456
3466
announcement_message : Some ( announcement_message)
3457
3467
} ;
3458
3468
@@ -3487,8 +3497,8 @@ pub(crate) mod tests {
3487
3497
let old_ann_info_with_addresses = <Vec < u8 > >:: from_hex ( "3f0009000708a000080a51220204000000000403000000062000000000000000000000000000000000000000000000000000000000000000000a0505014104d2" ) . unwrap ( ) ;
3488
3498
let ann_info_with_addresses = NodeAnnouncementInfo :: read ( & mut old_ann_info_with_addresses. as_slice ( ) )
3489
3499
. expect ( "to be able to read an old NodeAnnouncementInfo with addresses" ) ;
3490
- // This serialized info has an address field but no announcement_message, therefore the addresses returned by our function will still be empty
3491
- assert ! ( ann_info_with_addresses. addresses( ) . is_empty( ) ) ;
3500
+ // This serialized info has no announcement_message but its address field should still be considered
3501
+ assert ! ( ! ann_info_with_addresses. addresses( ) . is_empty( ) ) ;
3492
3502
}
3493
3503
3494
3504
#[ test]
0 commit comments