Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
fix(stress-test): fix probe message sending
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Mar 3, 2021
1 parent 0df5704 commit a8a184c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
19 changes: 13 additions & 6 deletions examples/stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,13 @@ impl Network {
RoutingEvent::Relocated { .. } => {
if let Some(Node::Joined {
node,
name,
age,
is_relocating,
..
}) = self.nodes.get_mut(&id)
{
*name = node.name().await;
*age = node.age().await;
*is_relocating = false;
self.stats.relocation_successes += 1;
Expand Down Expand Up @@ -410,18 +412,16 @@ impl Network {
let mut cache = BTreeMap::new();

let nodes = self.nodes.values().filter_map(|node| match node {
Node::Joined {
node, name, prefix, ..
} => Some((node, name, prefix)),
Node::Joined { node, prefix, .. } => Some((node, prefix)),
Node::Joining => None,
});

for (node, name, prefix) in nodes {
for (node, prefix) in nodes {
let dst = *cache
.entry(prefix)
.or_insert_with(|| prefix.substituted_in(rand::random()));

if self.try_send_probe(node, *name, dst).await? {
if self.try_send_probe(node, dst).await? {
self.probe_tracker.send(*prefix, dst);
}
}
Expand All @@ -433,7 +433,7 @@ impl Network {
Ok(())
}

async fn try_send_probe(&self, node: &Routing, src: XorName, dst: XorName) -> Result<bool> {
async fn try_send_probe(&self, node: &Routing, dst: XorName) -> Result<bool> {
let public_key_set = if let Ok(public_key_set) = node.public_key_set().await {
public_key_set
} else {
Expand All @@ -457,6 +457,13 @@ impl Network {
},
};
let bytes = bincode::serialize(&message)?.into();

// There can be a significant delay between a node being relocated and us receiving the
// `Relocated` event. Using the current node name instead of the one reported by the last
// `Relocated` event reduced send errors due to src location mismatch which would cause the
// section health to appear lower than it actually is.
let src = node.name().await;

let itinerary = Itinerary {
src: SrcLocation::Node(src),
dst: DstLocation::Section(dst),
Expand Down
9 changes: 8 additions & 1 deletion src/routing/approved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,10 @@ impl Approved {

// Send `vote` to `recipients`.
fn send_vote(&self, recipients: &[Peer], vote: Vote) -> Result<Vec<Command>> {
let key_share = self.section_keys_provider.key_share()?;
let key_share = self.section_keys_provider.key_share().map_err(|err| {
error!("Can't vote for {:?}: {}", vote, err);
err
})?;
self.send_vote_with(recipients, vote, key_share)
}

Expand Down Expand Up @@ -1113,6 +1116,10 @@ impl Approved {
// Keep it around even if we are not elder anymore, in case we need to resend it.
match self.relocate_state {
None => {
trace!(
"Received RelocatePromise to section at {}",
promise.destination
);
self.relocate_state = Some(RelocateState::Delayed(msg_bytes.clone()));
self.send_event(Event::RelocationStarted {
previous_name: self.node.name(),
Expand Down

0 comments on commit a8a184c

Please sign in to comment.