diff --git a/src/client.rs b/src/client.rs index 081a0b82a5..d61c791685 100644 --- a/src/client.rs +++ b/src/client.rs @@ -19,7 +19,7 @@ use crate::messages::{Request, CLIENT_GET_PRIORITY, DEFAULT_PRIORITY}; use crate::outbox::{EventBox, EventBuf}; use crate::routing_table::Authority; use crate::state_machine::{State, StateMachine}; -use crate::states::{Bootstrapping, BootstrappingTargetState}; +use crate::states::{BootstrappingPeer, TargetState}; use crate::types::{MessageId, RoutingActionSender}; use crate::xor_name::XorName; use crate::{BootstrapConfig, MIN_SECTION_SIZE}; @@ -72,16 +72,16 @@ impl Client { StateMachine::new( move |action_sender, crust_service, timer, _outbox2| { - Bootstrapping::new( + BootstrappingPeer::new( action_sender, Box::new(NullCache), - BootstrappingTargetState::Client { msg_expiry_dur }, + TargetState::Client { msg_expiry_dur }, crust_service, full_id, min_section_size, timer, ) - .map_or(State::Terminated, State::Bootstrapping) + .map_or(State::Terminated, State::BootstrappingPeer) }, pub_id, bootstrap_config, diff --git a/src/node.rs b/src/node.rs index 17a7419331..c4e5ae4feb 100644 --- a/src/node.rs +++ b/src/node.rs @@ -22,7 +22,7 @@ use crate::messages::{ use crate::outbox::{EventBox, EventBuf}; use crate::routing_table::Authority; use crate::state_machine::{State, StateMachine}; -use crate::states::{self, Bootstrapping, BootstrappingTargetState}; +use crate::states::{self, BootstrappingPeer, TargetState}; use crate::types::{MessageId, RoutingActionSender}; use crate::xor_name::XorName; #[cfg(feature = "mock_base")] @@ -159,16 +159,16 @@ impl NodeBuilder { outbox2.send_event(Event::Terminated); State::Terminated } else { - Bootstrapping::new( + BootstrappingPeer::new( action_sender, self.cache, - BootstrappingTargetState::RelocatingNode, + TargetState::RelocatingNode, crust_service, full_id, min_section_size, timer, ) - .map_or(State::Terminated, State::Bootstrapping) + .map_or(State::Terminated, State::BootstrappingPeer) } }, pub_id, diff --git a/src/state_machine.rs b/src/state_machine.rs index 13a2f93c66..970356908f 100644 --- a/src/state_machine.rs +++ b/src/state_machine.rs @@ -13,7 +13,7 @@ use crate::{ outbox::EventBox, routing_table::Prefix, states::common::Base, - states::{Bootstrapping, Client, EstablishingNode, Node, ProvingNode, RelocatingNode}, + states::{BootstrappingPeer, Client, EstablishingNode, Node, ProvingNode, RelocatingNode}, timer::Timer, types::RoutingActionSender, xor_name::XorName, @@ -37,7 +37,7 @@ use std::{ macro_rules! state_dispatch { ($self:expr, $state:pat => $expr:expr, Terminated => $term_expr:expr) => { match $self { - State::Bootstrapping($state) => $expr, + State::BootstrappingPeer($state) => $expr, State::Client($state) => $expr, State::RelocatingNode($state) => $expr, State::ProvingNode($state) => $expr, @@ -64,7 +64,7 @@ pub struct StateMachine { // FIXME - See https://maidsafe.atlassian.net/browse/MAID-2026 for info on removing this exclusion. #[allow(clippy::large_enum_variant)] pub enum State { - Bootstrapping(Bootstrapping), + BootstrappingPeer(BootstrappingPeer), Client(Client), RelocatingNode(RelocatingNode), ProvingNode(ProvingNode), @@ -127,7 +127,7 @@ impl State { match *self { State::EstablishingNode(ref state) => Some(state.chain()), State::Node(ref state) => Some(state.chain()), - State::Bootstrapping(_) + State::BootstrappingPeer(_) | State::Client(_) | State::RelocatingNode(_) | State::ProvingNode(_) @@ -200,7 +200,7 @@ impl State { pub fn get_timed_out_tokens(&mut self) -> Vec { match *self { - State::Bootstrapping(_) | State::Terminated => vec![], + State::BootstrappingPeer(_) | State::Terminated => vec![], State::Client(ref mut state) => state.get_timed_out_tokens(), State::RelocatingNode(ref mut state) => state.get_timed_out_tokens(), State::ProvingNode(ref mut state) => state.get_timed_out_tokens(), @@ -220,7 +220,7 @@ impl State { pub fn has_unpolled_observations(&self, filter_opaque: bool) -> bool { match *self { State::Terminated - | State::Bootstrapping(_) + | State::BootstrappingPeer(_) | State::Client(_) | State::RelocatingNode(_) | State::ProvingNode(_) => false, @@ -239,7 +239,7 @@ impl State { pub fn in_authority(&self, auth: &Authority) -> bool { match *self { - State::Terminated | State::Bootstrapping(_) => false, + State::Terminated | State::BootstrappingPeer(_) => false, State::Client(ref state) => state.in_authority(auth), State::RelocatingNode(ref state) => state.in_authority(auth), State::ProvingNode(ref state) => state.in_authority(auth), @@ -250,7 +250,7 @@ impl State { pub fn has_unacked_msg(&self) -> bool { match *self { - State::Terminated | State::Bootstrapping(_) => false, + State::Terminated | State::BootstrappingPeer(_) => false, State::Client(ref state) => state.ack_mgr().has_unacked_msg(), State::RelocatingNode(ref state) => state.ack_mgr().has_unacked_msg(), State::ProvingNode(ref state) => state.ack_mgr().has_unacked_msg(), @@ -409,7 +409,7 @@ impl StateMachine { match transition { Stay => (), IntoBootstrapped { proxy_public_id } => self.state.replace_with(|state| match state { - State::Bootstrapping(src) => src.into_target_state(proxy_public_id, outbox), + State::BootstrappingPeer(src) => src.into_target_state(proxy_public_id, outbox), _ => unreachable!(), }), IntoBootstrapping { diff --git a/src/states/bootstrapping.rs b/src/states/bootstrapping_peer.rs similarity index 97% rename from src/states/bootstrapping.rs rename to src/states/bootstrapping_peer.rs index 662c068aaa..0509ad29ac 100644 --- a/src/states/bootstrapping.rs +++ b/src/states/bootstrapping_peer.rs @@ -53,7 +53,7 @@ pub enum TargetState { } // State of Client or Node while bootstrapping. -pub struct Bootstrapping { +pub struct BootstrappingPeer { action_sender: RoutingActionSender, bootstrap_blacklist: HashSet, bootstrap_connection: Option<(PublicId, u64)>, @@ -65,7 +65,7 @@ pub struct Bootstrapping { timer: Timer, } -impl Bootstrapping { +impl BootstrappingPeer { pub fn new( action_sender: RoutingActionSender, cache: Box, @@ -86,7 +86,7 @@ impl Bootstrapping { } } } - Some(Bootstrapping { + Some(Self { action_sender, cache: cache, crust_service, @@ -208,7 +208,7 @@ impl Bootstrapping { } } -impl Base for Bootstrapping { +impl Base for BootstrappingPeer { fn crust_service(&self) -> &Service { &self.crust_service } @@ -366,9 +366,9 @@ impl Base for Bootstrapping { } } -impl Display for Bootstrapping { +impl Display for BootstrappingPeer { fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { - write!(formatter, "Bootstrapping({})", self.name()) + write!(formatter, "BootstrappingPeer({})", self.name()) } } @@ -423,7 +423,7 @@ mod tests { let pub_id = *full_id.public_id(); StateMachine::new( move |action_sender, crust_service, timer, _outbox2| { - Bootstrapping::new( + BootstrappingPeer::new( action_sender, Box::new(NullCache), TargetState::Client { @@ -434,7 +434,7 @@ mod tests { min_section_size, timer, ) - .map_or(State::Terminated, State::Bootstrapping) + .map_or(State::Terminated, State::BootstrappingPeer) }, pub_id, Some(config), @@ -455,14 +455,14 @@ mod tests { // caused it to send a `BootstrapRequest` and add the Crust service to its // `bootstrap_blacklist`. match *state_machine.current() { - State::Bootstrapping(ref state) => assert!(state.bootstrap_blacklist.is_empty()), + State::BootstrappingPeer(ref state) => assert!(state.bootstrap_blacklist.is_empty()), _ => panic!("Should be in `Bootstrapping` state."), } network.deliver_messages(); unwrap!(state_machine.step(&mut outbox)); assert!(outbox.take_all().is_empty()); match *state_machine.current() { - State::Bootstrapping(ref state) => assert_eq!(state.bootstrap_blacklist.len(), 1), + State::BootstrappingPeer(ref state) => assert_eq!(state.bootstrap_blacklist.len(), 1), _ => panic!("Should be in `Bootstrapping` state."), } diff --git a/src/states/mod.rs b/src/states/mod.rs index fc5f2d92b0..d2dcece947 100644 --- a/src/states/mod.rs +++ b/src/states/mod.rs @@ -6,7 +6,7 @@ // KIND, either express or implied. Please review the Licences for the specific language governing // permissions and limitations relating to use of the SAFE Network Software. -mod bootstrapping; +mod bootstrapping_peer; mod client; pub mod common; mod establishing_node; @@ -15,7 +15,7 @@ mod proving_node; mod relocating_node; pub use self::{ - bootstrapping::{Bootstrapping, TargetState as BootstrappingTargetState}, + bootstrapping_peer::{BootstrappingPeer, TargetState}, client::{Client, RATE_EXCEED_RETRY}, establishing_node::EstablishingNode, node::Node, diff --git a/src/states/relocating_node.rs b/src/states/relocating_node.rs index 3bc55c734a..57af7af637 100644 --- a/src/states/relocating_node.rs +++ b/src/states/relocating_node.rs @@ -8,7 +8,7 @@ use super::{ common::{proxied, Base, Bootstrapped, BootstrappedNotEstablished}, - Bootstrapping, BootstrappingTargetState, + BootstrappingPeer, TargetState, }; use crate::{ ack_manager::{Ack, AckManager}, @@ -104,11 +104,11 @@ impl RelocatingNode { crust_rx, crust_sender, ); - let target_state = BootstrappingTargetState::ProvingNode { + let target_state = TargetState::ProvingNode { old_full_id: self.full_id, our_section: our_section, }; - if let Some(bootstrapping) = Bootstrapping::new( + if let Some(peer) = BootstrappingPeer::new( self.action_sender, self.cache, target_state, @@ -117,7 +117,7 @@ impl RelocatingNode { self.min_section_size, self.timer, ) { - State::Bootstrapping(bootstrapping) + State::BootstrappingPeer(peer) } else { outbox.send_event(Event::RestartRequired); State::Terminated