aboutsummaryrefslogtreecommitdiff
path: root/examples/basalt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/basalt.rs')
-rw-r--r--examples/basalt.rs28
1 files changed, 20 insertions, 8 deletions
diff --git a/examples/basalt.rs b/examples/basalt.rs
index e09f627..141069a 100644
--- a/examples/basalt.rs
+++ b/examples/basalt.rs
@@ -1,8 +1,9 @@
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
+use std::io::Write;
-use log::{info, warn};
+use log::{debug, info, warn};
use structopt::StructOpt;
use serde::{Deserialize, Serialize};
@@ -48,7 +49,18 @@ pub struct Opt {
#[tokio::main]
async fn main() {
- pretty_env_logger::init();
+ env_logger::Builder::new()
+ .parse_env("RUST_LOG")
+ .format(|buf, record| {
+ writeln!(buf,
+ "{} {} {}",
+ chrono::Local::now().format("%s%.6f"),
+ record.level(),
+ record.args()
+ )
+ })
+ .init();
+
let opt = Opt::from_args();
@@ -56,7 +68,7 @@ async fn main() {
Some(k) => auth::Key::from_slice(&hex::decode(k).unwrap()).unwrap(),
None => auth::gen_key(),
};
- info!("Network key: {}", hex::encode(&netid));
+ info!("KYEV NK {}", hex::encode(&netid));
let privkey = match &opt.private_key {
Some(k) => ed25519::SecretKey::from_slice(&hex::decode(k).unwrap()).unwrap(),
@@ -66,8 +78,8 @@ async fn main() {
}
};
- info!("Node private key: {}", hex::encode(&privkey));
- info!("Node public key: {}", hex::encode(&privkey.public_key()));
+ info!("KYEV SK {}", hex::encode(&privkey));
+ info!("KYEV PK {}", hex::encode(&privkey.public_key()));
let listen_addr = opt.listen_addr.parse().unwrap();
let netapp = NetApp::new(listen_addr, netid, privkey);
@@ -93,7 +105,7 @@ async fn main() {
netapp.add_msg_handler::<ExampleMessage, _, _>(
|_from: ed25519::PublicKey, msg: ExampleMessage| {
- info!("Got example message: {:?}, sending example response", msg);
+ debug!("Got example message: {:?}, sending example response", msg);
async {
ExampleResponse{example_field: false}
}
@@ -115,14 +127,14 @@ async fn sampling_loop(netapp: Arc<NetApp>, basalt: Arc<Basalt>) {
let peers = basalt.sample(10);
for p in peers {
- info!("Sampled: {}", hex::encode(p));
+ info!("KYEV S {}", hex::encode(p));
let netapp2 = netapp.clone();
tokio::spawn(async move {
match netapp2.request(&p, ExampleMessage{
example_field: 42,
}, PRIO_NORMAL).await {
- Ok(resp) => info!("Got example response: {:?}", resp),
+ Ok(resp) => debug!("Got example response: {:?}", resp),
Err(e) => warn!("Error with example request: {}", e),
}
});