From 8828a681b731cf4a03f9d823e0b8692987a300b2 Mon Sep 17 00:00:00 2001 From: bochaco Date: Tue, 8 Sep 2020 12:07:08 -0500 Subject: [PATCH] chore(node): solving clippy issues by temporarily disablig unused functs and vars --- Cargo.toml | 1 - examples/minimal.rs | 21 ++++++++++++++------- src/consensus/dkg.rs | 15 +++++++++++++-- src/lib.rs | 10 ++++------ src/node/event_stream.rs | 8 +------- src/node/mod.rs | 4 ++-- src/node/stage/approved.rs | 18 ++++++++++++++++-- src/node/stage/bootstrapping.rs | 8 +++----- src/node/stage/joining.rs | 5 +++-- src/node/stage/mod.rs | 2 +- src/section/member_info.rs | 3 +++ src/section/shared_state.rs | 7 ++++++- 12 files changed, 66 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e6faf2adef..d553b83f2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ env_logger = { version = "~0.7.1", optional = true } err-derive = "~0.2.4" sn_fake_clock = "~0.4.0" futures = "~0.3.5" -fxhash = "~0.2.1" hex_fmt = "~0.3.0" itertools = "~0.9.0" lazy_static = { version = "1", optional = true } diff --git a/examples/minimal.rs b/examples/minimal.rs index 9166d4cbb7..eb2d212454 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -34,7 +34,7 @@ //! use hex_fmt::HexFmt; -use log::{info, LevelFilter}; +use log::{debug, info, LevelFilter}; use sn_routing::{ event::{Connected, Event}, Node, NodeConfig, TransportConfig, @@ -201,16 +201,18 @@ async fn start_node( let contact_info = node .our_connection_info() + .await .expect("Failed to obtain node's contact info."); - run_node(index, node); + run_node(index, node).await; contact_info } // Runs the nodes event loop. Blocks until terminated. -fn run_node(index: usize, node: Node) { +async fn run_node(index: usize, node: Node) { let mut event_stream = node .listen_events() + .await .expect("Failed to start listening for events from node."); tokio::spawn(async move { @@ -285,14 +287,19 @@ fn handle_event(index: usize, event: Event) -> bool { "Node #{} relocation started - previous_name: {}", index, previous_name ), - Event::Terminated => { - info!("Node #{} terminated", index); - return false; - } Event::RestartRequired => { info!("Node #{} requires restart", index); return false; } + Event::ClientMessageReceived { + content, src, dst, .. + } => info!( + "Node #{} received message from client: {:?}, dst: {:?}, content: {}", + index, + src, + dst, + HexFmt(content) + ), } true diff --git a/src/consensus/dkg.rs b/src/consensus/dkg.rs index 1c4a5a2e4a..28b4a24240 100644 --- a/src/consensus/dkg.rs +++ b/src/consensus/dkg.rs @@ -129,7 +129,8 @@ impl DkgVoter { dkg_key, key_gen, elders_info: Some(elders_info), - timer_token: 0, + // TODO: review if we still need this + //timer_token: 0, }); Some(message) @@ -214,6 +215,8 @@ impl DkgVoter { // - `Some((dkg_key, Err(())))` if the DKG failed. The result should be sent to the DKG observers // for accumulation. // - `None` if there is no active DKG session. + // TODO: review if we still need this function + /* pub fn progress_dkg( &mut self, rng: &mut MainRng, @@ -235,6 +238,7 @@ impl DkgVoter { } } } + */ /// Returns the participants of the DKG session, if there is one. pub fn participants(&self) -> impl Iterator { @@ -348,17 +352,23 @@ impl DkgVoter { // Returns the timer token of the active DKG session if there is one. If this timer fires, we // should call `progress_dkg`. + // TODO: review if we still need this function + /* pub fn timer_token(&self) -> Option { self.participant.as_ref().map(|session| session.timer_token) } + */ // Sets the timer token for the active DKG session. This should be set after a successful DKG // initialization, or after handling a DKG message that produced at least one response. + // TODO: review if we still need this function + /* pub fn set_timer_token(&mut self, token: u64) { if let Some(session) = &mut self.participant { session.timer_token = token; } } + */ } // Data for a DKG participant. @@ -367,7 +377,8 @@ struct Participant { elders_info: Option, dkg_key: DkgKey, key_gen: KeyGen, - timer_token: u64, + // TODO: review if we still need this + //timer_token: u64, } // Data for a DKG observer. diff --git a/src/lib.rs b/src/lib.rs index 92dc75ce38..c1364a4378 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,7 @@ )] // For explanation of lint checks, run `rustc -W help` or see // https://github.com/maidsafe/QA/blob/master/Documentation/Rust%20Lint%20Checks.md -/*#![forbid( +#![forbid( arithmetic_overflow, mutable_transmutes, no_mangle_const_items, @@ -63,9 +63,7 @@ unused_results, clippy::needless_borrow )] -// Need this to stop clippy complaining about the `use quic_p2p` line which is actually necessary. -#![allow(clippy::single_component_path_imports)] -*/ + #[macro_use] extern crate serde; @@ -158,9 +156,9 @@ const ELDER_SIZE: usize = 7; // Quic-p2p #[cfg(feature = "mock")] -use mock_qp2p as q2p; +use mock_qp2p as qp2p; #[cfg(not(feature = "mock"))] -use qp2p; +use qp2p::{self}; #[cfg(test)] mod tests { diff --git a/src/node/event_stream.rs b/src/node/event_stream.rs index e30edd21df..d315eb2af5 100644 --- a/src/node/event_stream.rs +++ b/src/node/event_stream.rs @@ -37,13 +37,7 @@ impl EventStream { is_genesis: bool, ) -> Self { let (events_tx, events_rx) = mpsc::channel::(MAX_EVENTS_BUFFERED); - Self::spawn_connections_handler( - stage.clone(), - events_tx, - incoming_conns, - xorname, - is_genesis, - ); + Self::spawn_connections_handler(stage, events_tx, incoming_conns, xorname, is_genesis); Self { events_rx } } diff --git a/src/node/mod.rs b/src/node/mod.rs index 8178e244a1..4e2b6755b1 100644 --- a/src/node/mod.rs +++ b/src/node/mod.rs @@ -87,7 +87,7 @@ impl Node { pub async fn new(config: NodeConfig) -> Result { let mut rng = config.rng; let full_id = config.full_id.unwrap_or_else(|| FullId::gen(&mut rng)); - let node_name = full_id.public_id().name().clone(); + let node_name = *full_id.public_id().name(); let transport_config = config.transport_config; let network_params = config.network_params; let is_genesis = config.first; @@ -237,7 +237,7 @@ impl Node { // Set log identifier let str = self.stage.lock().await.name_and_prefix(); use std::fmt::Write; - log_utils::set_ident(|buffer| write!(buffer, "{}", str)); + let _log_ident = log_utils::set_ident(|buffer| write!(buffer, "{}", str)); self.stage .lock() diff --git a/src/node/stage/approved.rs b/src/node/stage/approved.rs index f659e93ef1..9fad0344a3 100644 --- a/src/node/stage/approved.rs +++ b/src/node/stage/approved.rs @@ -29,7 +29,6 @@ use crate::{ EldersInfo, MemberInfo, NeighbourEldersRemoved, SectionKeyShare, SectionKeysProvider, SectionUpdateBarrier, SharedState, MIN_AGE, }, - time::Duration, }; use bls_dkg::key_gen::message::Message as DkgMessage; use bytes::Bytes; @@ -38,8 +37,9 @@ use std::net::SocketAddr; use tokio::sync::mpsc; use xor_name::{Prefix, XorName}; +// TODO: review if we still need to set a timer for DKG // Interval to progress DKG timed phase -const DKG_PROGRESS_INTERVAL: Duration = Duration::from_secs(30); +// const DKG_PROGRESS_INTERVAL: Duration = Duration::from_secs(30); // The approved stage - node is a full member of a section and is performing its duties according // to its persona (infant, adult or elder). @@ -222,6 +222,9 @@ impl Approved { Ok(()) } + // TODO: review if we still need to invoke this function which used to + // be called when couldn't connect to a peer. + /* async fn handle_connection_failure(&mut self, addr: SocketAddr) -> Result<()> { let node = self .shared_state @@ -244,7 +247,11 @@ impl Approved { Ok(()) } + */ + // TODO: review if we still need to call this function which used to be + // called when a message to a peer wasn't not sent even after retrying. + /* async fn handle_peer_lost(&mut self, peer_addr: SocketAddr) -> Result<()> { let name = if let Some(node) = self.shared_state.find_p2p_node_from_addr(&peer_addr) { debug!("Lost known peer {}", node); @@ -265,7 +272,10 @@ impl Approved { Ok(()) } + */ + // TODO: review if we still need this function + /* async fn handle_timeout(&mut self, token: u64) { if self.dkg_voter.timer_token() == Some(token) { // TODO ?? @@ -277,6 +287,7 @@ impl Approved { } } } + */ async fn check_dkg(&mut self, dkg_key: DkgKey) -> Result<()> { match self.dkg_voter.check_dkg() { @@ -298,6 +309,8 @@ impl Approved { } } + // TODO: review if we still need this function + /* async fn progress_dkg(&mut self) -> Result<()> { match self.dkg_voter.progress_dkg(&mut self.rng) { Some((dkg_key, Ok(messages))) => { @@ -313,6 +326,7 @@ impl Approved { None => Ok(()), } } + */ /// Is the node with the given id an elder in our section? pub fn is_our_elder(&self, id: &PublicId) -> bool { diff --git a/src/node/stage/bootstrapping.rs b/src/node/stage/bootstrapping.rs index 34b8120986..876b40aae4 100644 --- a/src/node/stage/bootstrapping.rs +++ b/src/node/stage/bootstrapping.rs @@ -16,19 +16,18 @@ use crate::{ relocation::{RelocatePayload, SignedRelocateDetails}, rng::MainRng, section::EldersInfo, - time::Duration, }; -use fxhash::FxHashSet; use std::{iter, net::SocketAddr}; use xor_name::Prefix; +// TODO: review if we still need to set a timeout for joining /// Time after which bootstrap is cancelled (and possibly retried). -pub const BOOTSTRAP_TIMEOUT: Duration = Duration::from_secs(20); +// pub const BOOTSTRAP_TIMEOUT: Duration = Duration::from_secs(20); // The bootstrapping stage - node is trying to find the section to join. pub(crate) struct Bootstrapping { // Using `FxHashSet` for deterministic iteration order. - pending_requests: FxHashSet, + // TODO - we may not need it anymore: pending_requests: FxHashSet, relocate_details: Option, full_id: FullId, rng: MainRng, @@ -45,7 +44,6 @@ impl Bootstrapping { network_params: NetworkParams, ) -> Self { Self { - pending_requests: Default::default(), relocate_details, full_id, rng, diff --git a/src/node/stage/joining.rs b/src/node/stage/joining.rs index 15dd77539c..1706f931f1 100644 --- a/src/node/stage/joining.rs +++ b/src/node/stage/joining.rs @@ -20,12 +20,13 @@ use crate::{ rng::MainRng, section::{EldersInfo, SharedState}, }; -use std::{net::SocketAddr, time::Duration}; +use std::net::SocketAddr; use tokio::sync::mpsc; use xor_name::Prefix; +// TODO: review if we still need to set a timeout for joining /// Time after which an attempt to joining a section is cancelled (and possibly retried). -pub const JOIN_TIMEOUT: Duration = Duration::from_secs(60); +//pub const JOIN_TIMEOUT: Duration = Duration::from_secs(60); // The joining stage - node is waiting to be approved by the section. pub(crate) struct Joining { diff --git a/src/node/stage/mod.rs b/src/node/stage/mod.rs index fd47911e32..88a77f2ab6 100644 --- a/src/node/stage/mod.rs +++ b/src/node/stage/mod.rs @@ -122,7 +122,7 @@ impl Stage { pub fn approved(&self) -> Option<&Approved> { match &self.state { - State::Approved(stage) => Some(&stage), + State::Approved(stage) => Some(stage), _ => None, } } diff --git a/src/section/member_info.rs b/src/section/member_info.rs index f94dfde165..0c1233239c 100644 --- a/src/section/member_info.rs +++ b/src/section/member_info.rs @@ -36,12 +36,15 @@ impl MemberInfo { } // Converts this info into one with the state changed to `Left`. + // TODO: review if we still need this function + /* pub fn leave(self) -> Self { Self { state: MemberState::Left, ..self } } + */ // Convert this info into one with the state changed to `Relocated`. pub fn relocate(self, destination: XorName) -> Self { diff --git a/src/section/shared_state.rs b/src/section/shared_state.rs index 8a377be061..e5c7dc0be1 100644 --- a/src/section/shared_state.rs +++ b/src/section/shared_state.rs @@ -21,7 +21,6 @@ use std::{ collections::{BTreeMap, BTreeSet}, convert::TryInto, fmt::Debug, - net::SocketAddr, }; use xor_name::{Prefix, XorName}; @@ -146,6 +145,8 @@ impl SharedState { .filter(move |p2p_node| !self.is_peer_our_elder(p2p_node.name())) } + // TODO: review if we still need this function + /* /// Returns all nodes we know (our members + neighbour elders). pub fn known_nodes(&self) -> impl Iterator { self.our_members @@ -153,6 +154,7 @@ impl SharedState { .map(|info| &info.p2p_node) .chain(self.sections.neighbour_elders()) } + */ /// Returns our members that are either joined or are left but still elders. pub fn active_members(&self) -> impl Iterator { @@ -185,10 +187,13 @@ impl SharedState { self.our_members.is_adult(name) || self.is_peer_our_elder(name) } + // TODO: review if we still need this function + /* pub fn find_p2p_node_from_addr(&self, socket_addr: &SocketAddr) -> Option<&P2pNode> { self.known_nodes() .find(|p2p_node| p2p_node.peer_addr() == socket_addr) } + */ /// All section keys we know of, including the past keys of our section. pub fn section_keys(&self) -> impl Iterator {