From 46fae5d138cb7c0a74e2a8c7837541f18400ccf4 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 2 Dec 2020 18:10:07 +0100 Subject: Better handle requests to ourself --- examples/basalt.rs | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'examples/basalt.rs') 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) { + loop { + tokio::time::delay_for(Duration::from_secs(10)).await; + + let peers = basalt.sample(10); + for p in peers { + info!("Sampled: {}", hex::encode(p)); + } + } } -- cgit v1.2.3