Skip to content

Commit b600c62

Browse files
committed
Avoid returning references in NodeAnnouncementInfo accessors
1 parent 688e310 commit b600c62

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lightning/src/routing/gossip.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,9 @@ pub enum NodeAnnouncementInfo {
13881388

13891389
impl NodeAnnouncementInfo {
13901390
/// Protocol features the node announced support for
1391-
pub fn features(&self) -> &NodeFeatures {
1391+
pub fn features(&self) -> NodeFeatures { self.features_ref().clone() }
1392+
1393+
pub(crate) fn features_ref(&self) -> &NodeFeatures {
13921394
match self {
13931395
NodeAnnouncementInfo::Relayed(relayed) => &relayed.contents.features,
13941396
NodeAnnouncementInfo::Local(local) => &local.features,
@@ -1416,29 +1418,29 @@ impl NodeAnnouncementInfo {
14161418
/// Moniker assigned to the node.
14171419
///
14181420
/// May be invalid or malicious (eg control chars), should not be exposed to the user.
1419-
pub fn alias(&self) -> &NodeAlias {
1421+
pub fn alias(&self) -> NodeAlias {
14201422
match self {
14211423
NodeAnnouncementInfo::Relayed(relayed) => &relayed.contents.alias,
14221424
NodeAnnouncementInfo::Local(local) => &local.alias,
1423-
}
1425+
}.clone()
14241426
}
14251427

14261428
/// Internet-level addresses via which one can connect to the node
1427-
pub fn addresses(&self) -> &[SocketAddress] {
1429+
pub fn addresses(&self) -> Vec<SocketAddress> {
14281430
match self {
14291431
NodeAnnouncementInfo::Relayed(relayed) => &relayed.contents.addresses,
14301432
NodeAnnouncementInfo::Local(local) => &local.addresses,
1431-
}
1433+
}.to_vec()
14321434
}
14331435

14341436
/// An initial announcement of the node
14351437
///
14361438
/// Not stored if contains excess data to prevent DoS.
1437-
pub fn announcement_message(&self) -> Option<&NodeAnnouncement> {
1439+
pub fn announcement_message(&self) -> Option<NodeAnnouncement> {
14381440
match self {
14391441
NodeAnnouncementInfo::Relayed(announcement) => Some(announcement),
14401442
NodeAnnouncementInfo::Local(_) => None,
1441-
}
1443+
}.cloned()
14421444
}
14431445
}
14441446

lightning/src/routing/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3167,7 +3167,7 @@ where L::Target: Logger {
31673167

31683168
if let Some(node) = network_nodes.get(&$node_id) {
31693169
let features = if let Some(node_info) = node.announcement_info.as_ref() {
3170-
&node_info.features()
3170+
node_info.features_ref()
31713171
} else {
31723172
&default_node_features
31733173
};

0 commit comments

Comments
 (0)