From: Matt Corallo Date: Sat, 24 Aug 2024 20:37:31 +0000 (+0000) Subject: Avoid returning references in `NodeAnnouncementInfo` accessors X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=3f1a9b1c934ef4f616b99148564c8e5c99f7e35c;p=rust-lightning Avoid returning references in `NodeAnnouncementInfo` accessors --- diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index e90ed1608..0d465d53a 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -1252,9 +1252,10 @@ pub enum NodeAnnouncementInfo { } impl NodeAnnouncementInfo { - /// Protocol features the node announced support for - pub fn features(&self) -> &NodeFeatures { + pub fn features(&self) -> NodeFeatures { self.features_ref().clone() } + + pub(crate) fn features_ref(&self) -> &NodeFeatures { match self { NodeAnnouncementInfo::Relayed(relayed) => { &relayed.contents.features @@ -1294,7 +1295,7 @@ impl NodeAnnouncementInfo { /// Moniker assigned to the node. /// /// May be invalid or malicious (eg control chars), should not be exposed to the user. - pub fn alias(&self) -> &NodeAlias { + pub fn alias(&self) -> NodeAlias { match self { NodeAnnouncementInfo::Relayed(relayed) => { &relayed.contents.alias @@ -1302,11 +1303,11 @@ impl NodeAnnouncementInfo { NodeAnnouncementInfo::Local(local) => { &local.alias } - } + }.clone() } /// Internet-level addresses via which one can connect to the node - pub fn addresses(&self) -> &[SocketAddress] { + pub fn addresses(&self) -> Vec { match self { NodeAnnouncementInfo::Relayed(relayed) => { &relayed.contents.addresses @@ -1314,13 +1315,13 @@ impl NodeAnnouncementInfo { NodeAnnouncementInfo::Local(local) => { &local.addresses } - } + }.to_vec() } /// An initial announcement of the node /// /// Not stored if contains excess data to prevent DoS. - pub fn announcement_message(&self) -> Option<&NodeAnnouncement> { + pub fn announcement_message(&self) -> Option { match self { NodeAnnouncementInfo::Relayed(announcement) => { Some(announcement) @@ -1328,7 +1329,7 @@ impl NodeAnnouncementInfo { NodeAnnouncementInfo::Local(_) => { None } - } + }.cloned() } } diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 47db2f3ec..da898f06e 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -2717,7 +2717,7 @@ where L::Target: Logger { } let features = if let Some(node_info) = $node.announcement_info.as_ref() { - &node_info.features() + node_info.features_ref() } else { &default_node_features };