Skip to content

Commit 591769f

Browse files
committed
Merge branch 'entity-manager' into lightweight-watcher
2 parents 425ae55 + 42bbbec commit 591769f

File tree

8 files changed

+618
-7
lines changed

8 files changed

+618
-7
lines changed

Cargo.lock

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ testresult = "0.4.1"
5959
tracing-subscriber = { version = "0.3.19", features = ["fmt"] }
6060
tracing-test = "0.2.5"
6161
walkdir = "2.5.0"
62+
atomic_refcell = "0.1.13"
63+
iroh = { version = "0.90", features = ["discovery-local-network"]}
6264

6365
[features]
6466
hide-proto-docs = []

examples/common/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![allow(dead_code)]
2+
use anyhow::Result;
3+
use iroh::SecretKey;
4+
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
5+
6+
/// Gets a secret key from the IROH_SECRET environment variable or generates a new random one.
7+
/// If the environment variable is set, it must be a valid string representation of a secret key.
8+
pub fn get_or_generate_secret_key() -> Result<SecretKey> {
9+
use std::{env, str::FromStr};
10+
11+
use anyhow::Context;
12+
use rand::thread_rng;
13+
if let Ok(secret) = env::var("IROH_SECRET") {
14+
// Parse the secret key from string
15+
SecretKey::from_str(&secret).context("Invalid secret key format")
16+
} else {
17+
// Generate a new random key
18+
let secret_key = SecretKey::generate(&mut thread_rng());
19+
println!(
20+
"Generated new secret key: {}",
21+
hex::encode(secret_key.to_bytes())
22+
);
23+
println!("To reuse this key, set the IROH_SECRET environment variable to this value");
24+
Ok(secret_key)
25+
}
26+
}
27+
28+
// set the RUST_LOG env var to one of {debug,info,warn} to see logging info
29+
pub fn setup_logging() {
30+
tracing_subscriber::registry()
31+
.with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr))
32+
.with(EnvFilter::from_default_env())
33+
.try_init()
34+
.ok();
35+
}

0 commit comments

Comments
 (0)