Skip to content

Commit 5d9d796

Browse files
committed
Reintroduce addresses to NodeAnnouncementInfo.
1 parent 1d452d0 commit 5d9d796

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

lightning/src/routing/gossip.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ pub struct ChannelInfo {
872872
/// The timestamp when we received the announcement, if we are running with feature = "std"
873873
/// (which we can probably assume we are - no-std environments probably won't have a full
874874
/// network graph in memory!).
875-
announcement_received_time: u64,
875+
pub announcement_received_time: u64,
876876
}
877877

878878
impl ChannelInfo {
@@ -1143,19 +1143,25 @@ pub struct NodeAnnouncementInfo {
11431143
/// May be invalid or malicious (eg control chars),
11441144
/// should not be exposed to the user.
11451145
pub alias: NodeAlias,
1146+
1147+
/// Internet-level addresses via which one can connect to the node
1148+
pub addresses: Vec<SocketAddress>,
1149+
1150+
/// List of addresses on which this node is reachable
1151+
// pub addresses: Vec<SocketAddress>,
11461152
/// An initial announcement of the node
11471153
/// Mostly redundant with the data we store in fields explicitly.
11481154
/// Everything else is useful only for sending out for initial routing sync.
11491155
/// Not stored if contains excess data to prevent DoS.
1150-
pub announcement_message: Option<NodeAnnouncement>
1156+
pub announcement_message: Option<NodeAnnouncement>,
11511157
}
11521158

11531159
impl NodeAnnouncementInfo {
11541160
/// Internet-level addresses via which one can connect to the node
11551161
pub fn addresses(&self) -> &[SocketAddress] {
11561162
self.announcement_message.as_ref()
11571163
.map(|msg| msg.contents.addresses.as_slice())
1158-
.unwrap_or_default()
1164+
.unwrap_or(self.addresses.as_slice())
11591165
}
11601166
}
11611167

@@ -1168,7 +1174,7 @@ impl Writeable for NodeAnnouncementInfo {
11681174
(4, self.rgb, required),
11691175
(6, self.alias, required),
11701176
(8, self.announcement_message, option),
1171-
(10, empty_addresses, required_vec), // Versions prior to 0.0.115 require this field
1177+
(10, self.addresses, required_vec), // Versions prior to 0.0.115 require this field
11721178
});
11731179
Ok(())
11741180
}
@@ -1182,11 +1188,16 @@ impl Readable for NodeAnnouncementInfo {
11821188
(4, rgb, required),
11831189
(6, alias, required),
11841190
(8, announcement_message, option),
1185-
(10, _addresses, optional_vec), // deprecated, not used anymore
1191+
(10, addresses, optional_vec),
11861192
});
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 })
1193+
Ok(Self {
1194+
features: features.0.unwrap(),
1195+
last_update: last_update.0.unwrap(),
1196+
rgb: rgb.0.unwrap(),
1197+
alias: alias.0.unwrap(),
1198+
addresses: addresses.unwrap_or(Vec::new()),
1199+
announcement_message,
1200+
})
11901201
}
11911202
}
11921203

@@ -1504,6 +1515,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
15041515
last_update: msg.timestamp,
15051516
rgb: msg.rgb,
15061517
alias: msg.alias,
1518+
addresses: msg.addresses.clone(),
15071519
announcement_message: if should_relay { full_msg.cloned() } else { None },
15081520
});
15091521

@@ -3453,6 +3465,7 @@ pub(crate) mod tests {
34533465
last_update: 0,
34543466
rgb: [0u8; 3],
34553467
alias: NodeAlias([0u8; 32]),
3468+
addresses: announcement_message.contents.addresses.clone(),
34563469
announcement_message: Some(announcement_message)
34573470
};
34583471

@@ -3487,8 +3500,8 @@ pub(crate) mod tests {
34873500
let old_ann_info_with_addresses = <Vec<u8>>::from_hex("3f0009000708a000080a51220204000000000403000000062000000000000000000000000000000000000000000000000000000000000000000a0505014104d2").unwrap();
34883501
let ann_info_with_addresses = NodeAnnouncementInfo::read(&mut old_ann_info_with_addresses.as_slice())
34893502
.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());
3503+
// This serialized info has no announcement_message but its address field should still be considered
3504+
assert!(!ann_info_with_addresses.addresses().is_empty());
34923505
}
34933506

34943507
#[test]

0 commit comments

Comments
 (0)