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

Commit

Permalink
feat: nodes using different ages
Browse files Browse the repository at this point in the history
genesis node use age of 255
nodes of first section use age randomized between 6 and 100
later on node has to be age of 5
  • Loading branch information
maqi authored and dirvine committed Apr 5, 2021
1 parent ffd6030 commit abb39c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/routing/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
};
use bytes::Bytes;
use futures::future;
use rand::seq::IteratorRandom;
use resource_proof::ResourceProof;
use sn_messaging::{
node::NodeMessage,
Expand Down Expand Up @@ -123,6 +124,19 @@ impl<'a> State<'a> {
.bootstrap(bootstrap_addrs, relocate_details.as_ref())
.await?;

// For the first section, using age random among 6 - 100 to avoid relocating too many nodes
// at the same time.
if prefix == Prefix::default() {
let age: u8 = (6..100)
.choose(&mut rand::thread_rng())
.unwrap_or_else(|| 100);
let new_keypair = crypto::gen_keypair(&Prefix::default().range_inclusive(), age);
let new_name = crypto::name(&new_keypair.public);

info!("Changing name to {}", new_name);
self.node = Node::new(new_keypair, self.node.addr);
}

let relocate_payload = if let Some(details) = relocate_details {
Some(self.process_relocation(&prefix, details)?)
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ impl Routing {
let (connection_event_tx, mut connection_event_rx) = mpsc::channel(1);

let (state, comm, backlog) = if config.first {
// Genesis node having a fix age of 255.
let keypair = crypto::gen_keypair(&Prefix::default().range_inclusive(), 255);
let node_name = crypto::name(&keypair.public);

info!("{} Starting a new network as the genesis node.", node_name);

let comm = Comm::new(config.transport_config, connection_event_tx).await?;
let node = Node::new(keypair, comm.our_connection_info());
let state = Core::first_node(node, event_tx)?;
Expand Down

0 comments on commit abb39c1

Please sign in to comment.