From: Matt Corallo Date: Tue, 12 May 2020 01:07:02 +0000 (-0400) Subject: Move get_addresses to network_graph and drop now-useless log_trace X-Git-Tag: v0.0.12~66^2~4 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0e3bf19b664ad3f9dd252c9ed50ed365ff827524;p=rust-lightning Move get_addresses to network_graph and drop now-useless log_trace Because we expose the internals we don't need a method to log their contents anymore, and get_addresses can now avoid copying as we expose the RwLock directly --- diff --git a/lightning/src/routing/network_graph.rs b/lightning/src/routing/network_graph.rs index faf2b5ff2..dd6d7d7ed 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/network_graph.rs @@ -67,25 +67,6 @@ impl NetGraphMsgHandler { logger: logger.clone(), } } - - /// Get network addresses by node id. - /// Returns None if the requested node is completely unknown, - /// or if node announcement for the node was never received. - pub fn get_addresses(&self, pubkey: &PublicKey) -> Option> { - let network = self.network_graph.read().unwrap(); - if let Some(node) = network.get_nodes().get(pubkey) { - if let Some(node_info) = node.announcement_info.as_ref() { - return Some(node_info.addresses.clone()) - } - } - None - } - - /// Dumps the entire network view of this NetGraphMsgHandler to the logger provided in the constructor at - /// level Trace - pub fn trace_state(&self) { - log_trace!(self, "{}", self.network_graph.read().unwrap()); - } } @@ -509,6 +490,18 @@ impl NetworkGraph { /// Returns all known nodes' public keys along with announced node info. pub fn get_nodes<'a>(&'a self) -> &'a BTreeMap { &self.nodes } + /// Get network addresses by node id. + /// Returns None if the requested node is completely unknown, + /// or if node announcement for the node was never received. + pub fn get_addresses<'a>(&'a self, pubkey: &PublicKey) -> Option<&'a Vec> { + if let Some(node) = self.nodes.get(pubkey) { + if let Some(node_info) = node.announcement_info.as_ref() { + return Some(&node_info.addresses) + } + } + None + } + /// For an already known node (from channel announcements), update its stored properties from a given node announcement /// Announcement signatures are checked here only if Secp256k1 object is provided. fn update_node_from_announcement(&mut self, msg: &msgs::NodeAnnouncement, secp_ctx: Option<&Secp256k1>) -> Result {