Skip to content

Commit 1cffc9c

Browse files
committed
Avoid returning references in NodeAnnouncementInfo accessors
1 parent ae63f5d commit 1cffc9c

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
@@ -1381,7 +1381,9 @@ pub enum NodeAnnouncementInfo {
13811381

13821382
impl NodeAnnouncementInfo {
13831383
/// Protocol features the node announced support for
1384-
pub fn features(&self) -> &NodeFeatures {
1384+
pub fn features(&self) -> NodeFeatures { self.features_ref().clone() }
1385+
1386+
pub(crate) fn features_ref(&self) -> &NodeFeatures {
13851387
match self {
13861388
NodeAnnouncementInfo::Relayed(relayed) => &relayed.contents.features,
13871389
NodeAnnouncementInfo::Local(local) => &local.features,
@@ -1409,29 +1411,29 @@ impl NodeAnnouncementInfo {
14091411
/// Moniker assigned to the node.
14101412
///
14111413
/// May be invalid or malicious (eg control chars), should not be exposed to the user.
1412-
pub fn alias(&self) -> &NodeAlias {
1414+
pub fn alias(&self) -> NodeAlias {
14131415
match self {
14141416
NodeAnnouncementInfo::Relayed(relayed) => &relayed.contents.alias,
14151417
NodeAnnouncementInfo::Local(local) => &local.alias,
1416-
}
1418+
}.clone()
14171419
}
14181420

14191421
/// Internet-level addresses via which one can connect to the node
1420-
pub fn addresses(&self) -> &[SocketAddress] {
1422+
pub fn addresses(&self) -> Vec<SocketAddress> {
14211423
match self {
14221424
NodeAnnouncementInfo::Relayed(relayed) => &relayed.contents.addresses,
14231425
NodeAnnouncementInfo::Local(local) => &local.addresses,
1424-
}
1426+
}.to_vec()
14251427
}
14261428

14271429
/// An initial announcement of the node
14281430
///
14291431
/// Not stored if contains excess data to prevent DoS.
1430-
pub fn announcement_message(&self) -> Option<&NodeAnnouncement> {
1432+
pub fn announcement_message(&self) -> Option<NodeAnnouncement> {
14311433
match self {
14321434
NodeAnnouncementInfo::Relayed(announcement) => Some(announcement),
14331435
NodeAnnouncementInfo::Local(_) => None,
1434-
}
1436+
}.cloned()
14351437
}
14361438
}
14371439

lightning/src/routing/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,7 @@ where L::Target: Logger {
27022702
}
27032703

27042704
let features = if let Some(node_info) = $node.announcement_info.as_ref() {
2705-
&node_info.features()
2705+
node_info.features_ref()
27062706
} else {
27072707
&default_node_features
27082708
};

0 commit comments

Comments
 (0)