aboutsummaryrefslogtreecommitdiff
path: root/examples/basalt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/basalt.rs')
-rw-r--r--examples/basalt.rs41
1 files changed, 21 insertions, 20 deletions
diff --git a/examples/basalt.rs b/examples/basalt.rs
index 4c86cf8..eaf056b 100644
--- a/examples/basalt.rs
+++ b/examples/basalt.rs
@@ -1,20 +1,20 @@
+use std::io::Write;
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
-use std::io::Write;
use log::{debug, info, warn};
-use structopt::StructOpt;
use serde::{Deserialize, Serialize};
+use structopt::StructOpt;
use sodiumoxide::crypto::auth;
use sodiumoxide::crypto::sign::ed25519;
-use netapp::NetApp;
-use netapp::peering::basalt::*;
use netapp::message::*;
+use netapp::peering::basalt::*;
use netapp::proto::*;
+use netapp::NetApp;
#[derive(StructOpt, Debug)]
#[structopt(name = "netapp")]
@@ -52,17 +52,17 @@ async fn main() {
env_logger::Builder::new()
.parse_env("RUST_LOG")
.format(|buf, record| {
- writeln!(buf,
- "{} {} {} {}",
- chrono::Local::now().format("%s%.6f"),
- record.module_path().unwrap_or("_"),
- record.level(),
- record.args()
- )
+ writeln!(
+ buf,
+ "{} {} {} {}",
+ chrono::Local::now().format("%s%.6f"),
+ record.module_path().unwrap_or("_"),
+ record.level(),
+ record.args()
+ )
})
.init();
-
let opt = Opt::from_args();
let netid = match &opt.network_key {
@@ -108,10 +108,12 @@ async fn main() {
|_from: ed25519::PublicKey, msg: ExampleMessage| {
debug!("Got example message: {:?}, sending example response", msg);
async {
- ExampleResponse{example_field: false}
+ ExampleResponse {
+ example_field: false,
+ }
}
- }
- );
+ },
+ );
tokio::join!(
sampling_loop(netapp.clone(), peering.clone()),
@@ -120,8 +122,6 @@ async fn main() {
);
}
-
-
async fn sampling_loop(netapp: Arc<NetApp>, basalt: Arc<Basalt>) {
loop {
tokio::time::delay_for(Duration::from_secs(10)).await;
@@ -132,9 +132,10 @@ async fn sampling_loop(netapp: Arc<NetApp>, basalt: Arc<Basalt>) {
let netapp2 = netapp.clone();
tokio::spawn(async move {
- match netapp2.request(&p, ExampleMessage{
- example_field: 42,
- }, PRIO_NORMAL).await {
+ match netapp2
+ .request(&p, ExampleMessage { example_field: 42 }, PRIO_NORMAL)
+ .await
+ {
Ok(resp) => debug!("Got example response: {:?}", resp),
Err(e) => warn!("Error with example request: {}", e),
}