diff options
author | Alex Auvolat <alex@adnab.me> | 2020-12-02 18:10:07 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-12-02 18:10:07 +0100 |
commit | 46fae5d138cb7c0a74e2a8c7837541f18400ccf4 (patch) | |
tree | f4456300e4ed12ffa6dd918236ad74d4c89b0249 /examples/basalt.rs | |
parent | 9ed776d16ad40a4d47900814b2b7f1ef1c02fa4e (diff) | |
download | netapp-46fae5d138cb7c0a74e2a8c7837541f18400ccf4.tar.gz netapp-46fae5d138cb7c0a74e2a8c7837541f18400ccf4.zip |
Better handle requests to ourself
Diffstat (limited to 'examples/basalt.rs')
-rw-r--r-- | examples/basalt.rs | 45 |
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)); + } + } } |