]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Avoid returning references in `NodeAnnouncementInfo` accessors
authorMatt Corallo <git@bluematt.me>
Sat, 24 Aug 2024 20:37:31 +0000 (20:37 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 14 Oct 2024 19:15:11 +0000 (19:15 +0000)
lightning/src/routing/gossip.rs
lightning/src/routing/router.rs

index e90ed1608e06afa123e7f62bbe3b99828ab17c97..0d465d53a78707b646297613e15a56f41da59768 100644 (file)
@@ -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<SocketAddress> {
                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<NodeAnnouncement> {
                match self {
                        NodeAnnouncementInfo::Relayed(announcement) => {
                                Some(announcement)
@@ -1328,7 +1329,7 @@ impl NodeAnnouncementInfo {
                        NodeAnnouncementInfo::Local(_) => {
                                None
                        }
-               }
+               }.cloned()
        }
 }
 
index 47db2f3ec660b4ee0f5289fe7778b74e296814c7..da898f06e814c437668ebc01fd784c986d7d2e6b 100644 (file)
@@ -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
                                };