diff --git a/other_crates/bones_matchmaker/src/cli.rs b/other_crates/bones_matchmaker/src/cli.rs index 8cb957ac9..01aab2c90 100644 --- a/other_crates/bones_matchmaker/src/cli.rs +++ b/other_crates/bones_matchmaker/src/cli.rs @@ -1,12 +1,23 @@ use clap::Parser; use tracing::metadata::LevelFilter; +use tracing::warn; pub async fn start() { configure_logging(); let args = crate::Config::parse(); + let secret_key = match std::env::var("BONES_MATCHMAKER_SECRET_KEY") { + Ok(key) => match key.parse::() { + Ok(key) => Some(key), + Err(_) => { + warn!("invalid matchmaker key provided"); + None + } + }, + Err(_) => None, + }; - if let Err(e) = super::server(args).await { + if let Err(e) = super::server(args, secret_key).await { eprintln!("Error: {e}"); } } diff --git a/other_crates/bones_matchmaker/src/lib.rs b/other_crates/bones_matchmaker/src/lib.rs index 65c9ffa09..cd7d0fe69 100644 --- a/other_crates/bones_matchmaker/src/lib.rs +++ b/other_crates/bones_matchmaker/src/lib.rs @@ -8,6 +8,7 @@ extern crate tracing; use std::net::SocketAddr; use bones_matchmaker_proto::MATCH_ALPN; +use iroh_net::key::SecretKey; pub mod cli; @@ -19,12 +20,29 @@ struct Config { /// The server address to listen on #[clap(short, long = "listen", default_value = "0.0.0.0:8943")] listen_addr: SocketAddr, + /// If enabled, prints the current secret key. Use with caution. + #[clap(long)] + print_secret_key: bool, } -async fn server(args: Config) -> anyhow::Result<()> { +async fn server(args: Config, secret_key: Option) -> anyhow::Result<()> { let port = args.listen_addr.port(); - let secret_key = iroh_net::key::SecretKey::generate(); + match secret_key { + Some(ref key) => { + info!("Using existing key: {}", key.public()); + } + None => { + info!("Generating new key"); + } + } + + let secret_key = secret_key.unwrap_or_else(SecretKey::generate); + + if args.print_secret_key { + println!("Secret Key: {}", secret_key); + } + let endpoint = iroh_net::MagicEndpoint::builder() .alpns(vec![MATCH_ALPN.to_vec()]) .discovery(Box::new(