aboutsummaryrefslogtreecommitdiff
path: root/examples/basalt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/basalt.rs')
-rw-r--r--examples/basalt.rs45
1 files changed, 38 insertions, 7 deletions
diff --git a/examples/basalt.rs b/examples/basalt.rs
index e486e08..bf00547 100644
--- a/examples/basalt.rs
+++ b/examples/basalt.rs
@@ -1,4 +1,5 @@
use std::net::SocketAddr;
+use std::sync::Arc;
use std::time::Duration;
use log::info;
@@ -25,6 +26,21 @@ pub struct Opt {
#[structopt(long = "listen-addr", short = "l", default_value = "127.0.0.1:1980")]
listen_addr: String,
+
+ #[structopt(long = "view-size", short = "v", default_value = "100")]
+ view_size: usize,
+
+ #[structopt(long = "cache-size", short = "c", default_value = "1000")]
+ cache_size: usize,
+
+ #[structopt(long = "exchange-interval-secs", short = "x", default_value = "1")]
+ exchange_interval: u64,
+
+ #[structopt(long = "reset-interval-secs", short = "r", default_value = "10")]
+ reset_interval: u64,
+
+ #[structopt(long = "reset-count", short = "k", default_value = "20")]
+ reset_count: usize,
}
#[tokio::main]
@@ -63,14 +79,29 @@ async fn main() {
}
}
- let basalt_params = BasaltParams{
- view_size: 100,
- cache_size: 1000,
- exchange_interval: Duration::from_secs(1),
- reset_interval: Duration::from_secs(10),
- reset_count: 20,
+ let basalt_params = BasaltParams {
+ view_size: opt.view_size,
+ cache_size: opt.cache_size,
+ exchange_interval: Duration::from_secs(opt.exchange_interval),
+ reset_interval: Duration::from_secs(opt.reset_interval),
+ reset_count: opt.reset_count,
};
let peering = Basalt::new(netapp.clone(), bootstrap_peers, basalt_params);
- tokio::join!(netapp.listen(), peering.run(),);
+ tokio::join!(
+ sampling_loop(peering.clone()),
+ netapp.listen(),
+ peering.run(),
+ );
+}
+
+async fn sampling_loop(basalt: Arc<Basalt>) {
+ loop {
+ tokio::time::delay_for(Duration::from_secs(10)).await;
+
+ let peers = basalt.sample(10);
+ for p in peers {
+ info!("Sampled: {}", hex::encode(p));
+ }
+ }
}