]> 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>
Tue, 3 Sep 2024 14:00:24 +0000 (14:00 +0000)
lightning/src/routing/gossip.rs
lightning/src/routing/router.rs

index 3ca52ab94200281ba1f9c062fb02c93bd2b29e8f..db53f9f72bda314a1949f522da52fad23099f544 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
                                };