This repository has been archived by the owner on Jun 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
WIP feat/routing: use node key as name #1115
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ use kademlia_routing_table::RoutingTable; | |
use maidsafe_utilities::serialisation; | ||
use std::fmt::{self, Debug, Formatter}; | ||
use std::sync::mpsc::Sender; | ||
use std::time::Duration; | ||
use std::time::{Duration, Instant}; | ||
|
||
use ack_manager::{Ack, AckManager}; | ||
use action::Action; | ||
|
@@ -44,19 +44,20 @@ use super::common::Testable; | |
use super::Node; | ||
use timer::Timer; | ||
use types::MessageId; | ||
#[cfg(feature = "use-mock-crust")] | ||
use xor_name::XorName; | ||
|
||
/// Time (in seconds) after which a `GetNodeName` request is resent. | ||
const GET_NODE_NAME_TIMEOUT_SECS: u64 = 60; | ||
/// Time (in seconds) after which a `GetNameRange` request is resent. | ||
const GET_NAME_RANGE_TIMEOUT_SECS: u64 = 60; | ||
/// Time (in seconds) for the duration to compute a valid new id. | ||
const COMPUTING_IDENTITY_TIMEOUT_SECS: u64 = 30; | ||
|
||
pub struct JoiningNode { | ||
ack_mgr: AckManager, | ||
cache: Box<Cache>, | ||
crust_service: Service, | ||
event_sender: Sender<Event>, | ||
full_id: FullId, | ||
get_node_name_timer_token: Option<u64>, | ||
get_name_range_timer_token: Option<u64>, | ||
msg_accumulator: MessageAccumulator, | ||
peer_mgr: PeerManager, | ||
signed_msg_filter: SignedMessageFilter, | ||
|
@@ -85,7 +86,7 @@ impl JoiningNode { | |
crust_service: crust_service, | ||
event_sender: event_sender, | ||
full_id: full_id, | ||
get_node_name_timer_token: None, | ||
get_name_range_timer_token: None, | ||
msg_accumulator: MessageAccumulator::with_quorum_size(quorum_size), | ||
peer_mgr: peer_mgr, | ||
signed_msg_filter: SignedMessageFilter::new(), | ||
|
@@ -183,8 +184,8 @@ impl JoiningNode { | |
} | ||
|
||
fn handle_timeout(&mut self, token: u64) -> bool { | ||
if self.get_node_name_timer_token == Some(token) { | ||
info!("{:?} Failed to get GetNodeName response.", self); | ||
if self.get_name_range_timer_token == Some(token) { | ||
info!("{:?} Failed to get GetNameRange response.", self); | ||
self.send_event(Event::RestartRequired); | ||
return false; | ||
} | ||
|
@@ -274,20 +275,18 @@ impl JoiningNode { | |
Transition::Stay | ||
} | ||
|
||
fn handle_get_node_name_response(&mut self, | ||
relocated_id: PublicId, | ||
mut close_group_ids: Vec<PublicId>, | ||
dst: Authority) | ||
-> Transition { | ||
self.full_id.public_id_mut().set_name(*relocated_id.name()); | ||
fn handle_get_name_range_response(&mut self, | ||
mut close_group_ids: Vec<PublicId>, | ||
dst: Authority) | ||
-> Transition { | ||
self.peer_mgr.reset_routing_table(*self.full_id.public_id()); | ||
|
||
close_group_ids.truncate(GROUP_SIZE / 2); | ||
|
||
let mut result = Transition::Stay; | ||
|
||
for close_node_id in close_group_ids { | ||
debug!("{:?} Sending connection info to {:?} on GetNodeName response.", | ||
debug!("{:?} Sending connection info to {:?} on GetNameRange response.", | ||
self, | ||
close_node_id); | ||
|
||
|
@@ -322,10 +321,10 @@ impl JoiningNode { | |
} | ||
|
||
fn relocate(&mut self) -> Result<(), RoutingError> { | ||
let duration = Duration::from_secs(GET_NODE_NAME_TIMEOUT_SECS); | ||
self.get_node_name_timer_token = Some(self.timer.schedule(duration)); | ||
let duration = Duration::from_secs(GET_NAME_RANGE_TIMEOUT_SECS); | ||
self.get_name_range_timer_token = Some(self.timer.schedule(duration)); | ||
|
||
let request_content = MessageContent::GetNodeName { | ||
let request_content = MessageContent::GetNameRange { | ||
current_id: *self.full_id.public_id(), | ||
message_id: MessageId::new(), | ||
}; | ||
|
@@ -361,6 +360,22 @@ impl JoiningNode { | |
let _ = self.crust_service.disconnect(*peer_id); | ||
} | ||
} | ||
|
||
fn compute_new_id(&mut self, name_range: &(XorName, XorName)) -> Result<(), RoutingError> { | ||
let now = Instant::now(); | ||
loop { | ||
if now.elapsed() > Duration::from_secs(COMPUTING_IDENTITY_TIMEOUT_SECS) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets hope the client/joining node is not busy, or it might not manage many iterations. Often this type of code allows a maximum number of tries instead of a timeout. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the network side is waiting based on timeout, so here needs to be wait on timeout as well. |
||
error!("{:?} failed to compute an id between {:?}", self, name_range); | ||
return Err(RoutingError::RejectedPublicId); | ||
} | ||
let new_id = FullId::new(); | ||
let new_public_name = *new_id.public_id().name(); | ||
if new_public_name > name_range.0 && new_public_name < name_range.1 { | ||
self.full_id = new_id; | ||
return Ok(()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl AnyState for JoiningNode { | ||
|
@@ -441,9 +456,12 @@ impl Bootstrapped for JoiningNode { | |
// Ack | ||
(MessageContent::Ack(ack, _), _, _) => Ok(self.handle_ack_response(ack)), | ||
// GetNodeNameResponse | ||
(MessageContent::GetNodeNameResponse { relocated_id, close_group_ids, .. }, | ||
(MessageContent::GetNameRangeResponse { name_range, close_group_ids, .. }, | ||
Authority::NodeManager(_), | ||
dst) => Ok(self.handle_get_node_name_response(relocated_id, close_group_ids, dst)), | ||
dst) => { | ||
try!(self.compute_new_id(&name_range)); | ||
Ok(self.handle_get_name_range_response(close_group_ids, dst)) | ||
} | ||
// ConnectionInfo | ||
(MessageContent::ConnectionInfo { encrypted_connection_info, nonce_bytes, public_id }, | ||
src @ Authority::Client { .. }, | ||
|
@@ -485,7 +503,7 @@ impl Bootstrapped for JoiningNode { | |
|
||
impl Connect for JoiningNode { | ||
fn handle_node_identify(&mut self, public_id: PublicId, peer_id: PeerId) -> Transition { | ||
debug!("{:?} Handling NodeIdentify from {:?}.", | ||
debug!("{:?} Handling NodeIdentify from {:?} as joining_node.", | ||
self, | ||
public_id.name()); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow... why would Z have A's original ID? For the previous line, it would be nicer if your addition was spelled out: "node Z (of
NaeManager
Y)"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the group X has notified group Y about A's original id