Skip to content

Commit 020b479

Browse files
committed
Avoid returning references in NodeAnnouncementInfo accessors
1 parent 3ffb48d commit 020b479

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lightning/src/routing/gossip.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,9 +1252,10 @@ pub enum NodeAnnouncementInfo {
12521252
}
12531253

12541254
impl NodeAnnouncementInfo {
1255-
12561255
/// Protocol features the node announced support for
1257-
pub fn features(&self) -> &NodeFeatures {
1256+
pub fn features(&self) -> NodeFeatures { self.features_ref().clone() }
1257+
1258+
pub(crate) fn features_ref(&self) -> &NodeFeatures {
12581259
match self {
12591260
NodeAnnouncementInfo::Relayed(relayed) => {
12601261
&relayed.contents.features
@@ -1294,41 +1295,41 @@ impl NodeAnnouncementInfo {
12941295
/// Moniker assigned to the node.
12951296
///
12961297
/// May be invalid or malicious (eg control chars), should not be exposed to the user.
1297-
pub fn alias(&self) -> &NodeAlias {
1298+
pub fn alias(&self) -> NodeAlias {
12981299
match self {
12991300
NodeAnnouncementInfo::Relayed(relayed) => {
13001301
&relayed.contents.alias
13011302
}
13021303
NodeAnnouncementInfo::Local(local) => {
13031304
&local.alias
13041305
}
1305-
}
1306+
}.clone()
13061307
}
13071308

13081309
/// Internet-level addresses via which one can connect to the node
1309-
pub fn addresses(&self) -> &[SocketAddress] {
1310+
pub fn addresses(&self) -> Vec<SocketAddress> {
13101311
match self {
13111312
NodeAnnouncementInfo::Relayed(relayed) => {
13121313
&relayed.contents.addresses
13131314
}
13141315
NodeAnnouncementInfo::Local(local) => {
13151316
&local.addresses
13161317
}
1317-
}
1318+
}.to_vec()
13181319
}
13191320

13201321
/// An initial announcement of the node
13211322
///
13221323
/// Not stored if contains excess data to prevent DoS.
1323-
pub fn announcement_message(&self) -> Option<&NodeAnnouncement> {
1324+
pub fn announcement_message(&self) -> Option<NodeAnnouncement> {
13241325
match self {
13251326
NodeAnnouncementInfo::Relayed(announcement) => {
13261327
Some(announcement)
13271328
}
13281329
NodeAnnouncementInfo::Local(_) => {
13291330
None
13301331
}
1331-
}
1332+
}.cloned()
13321333
}
13331334
}
13341335

lightning/src/routing/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2717,7 +2717,7 @@ where L::Target: Logger {
27172717
}
27182718

27192719
let features = if let Some(node_info) = $node.announcement_info.as_ref() {
2720-
&node_info.features()
2720+
node_info.features_ref()
27212721
} else {
27222722
&default_node_features
27232723
};

0 commit comments

Comments
 (0)