summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index ef9bf54..96758ec 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,7 +15,7 @@ use anyhow::{Context, Result};
use automerge::AutoCommit;
use clap::Parser;
use tokio::sync::{broadcast, mpsc, watch, RwLock};
-use tracing::{debug, error, info, trace};
+use tracing::{debug, error, info, trace, warn};
use url::Url;
mod api;
@@ -75,6 +75,11 @@ struct Args {
#[arg(long, value_name = "PATH")]
htpasswd: String,
+ /// Pre-shared swarm key: only peers that know it may join (raw bytes, at least 16;
+ /// e.g. `head -c 32 /dev/urandom`). Without it, anyone who knows the swarm ID can.
+ #[arg(long, value_name = "PATH")]
+ swarm_key_file: Option<PathBuf>,
+
/// Keepalive interval; dormancy, resync and probe timings derive from it.
#[arg(long, value_name = "SECONDS", default_value_t = 60)]
keepalive_secs: u64,
@@ -91,6 +96,15 @@ async fn main() -> Result<()> {
let args = Args::parse();
+ // Read before anything starts, so a bad key file fails right away.
+ let swarm_key = match &args.swarm_key_file {
+ Some(path) => Some(Arc::new(swarm::auth::SwarmKey::from_file(path)?)),
+ None => {
+ warn!("No swarm key: any peer that learns the swarm ID can join");
+ None
+ }
+ };
+
// First thing: until a handler is installed, SIGINT and SIGTERM kill the process on
// the spot, and startup (spawning Mycelium, bootstrap) can take minutes.
let stop = watch_for_shutdown().context("Installing signal handlers")?;
@@ -163,6 +177,7 @@ async fn main() -> Result<()> {
change_events,
timing: Timing::from_keepalive(Duration::from_secs(args.keepalive_secs)),
remake: Arc::new(remake::RemakeState::default()),
+ swarm_key,
stale: Default::default(),
};