From df74bf7026569514210982a2c7c3a4c36f469a32 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 1 Nov 2026 05:32:36 +0100 Subject: allow creating all key files --- src/transport/mycelium/mod.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/transport/mycelium/mod.rs') diff --git a/src/transport/mycelium/mod.rs b/src/transport/mycelium/mod.rs index 21c939d..9078134 100644 --- a/src/transport/mycelium/mod.rs +++ b/src/transport/mycelium/mod.rs @@ -104,6 +104,9 @@ pub(crate) fn check(settings: &crate::config::Settings) -> Result<()> { ); } } + if settings.mycelium_key_create && settings.mycelium_key_file.is_none() { + anyhow::bail!("mycelium-key-create creates the key at mycelium-key-file; set that too"); + } // A private network has both; one alone would be ignored or invented. if settings.mycelium_network_key_file.is_some() != settings.mycelium_network_name.is_some() { anyhow::bail!("mycelium-network-key-file and mycelium-network-name go together"); @@ -113,9 +116,10 @@ pub(crate) fn check(settings: &crate::config::Settings) -> Result<()> { /// The options only a supervised Mycelium daemon takes, and whether each is set: the /// other side of `config::CONFLICTS`' `mycelium-rest-url` (a test keeps them the same). -pub(crate) fn supervised_only(settings: &crate::config::Settings) -> [(&'static str, bool); 4] { +pub(crate) fn supervised_only(settings: &crate::config::Settings) -> [(&'static str, bool); 5] { [ ("mycelium-key-file", settings.mycelium_key_file.is_some()), + ("mycelium-key-create", settings.mycelium_key_create), ( "mycelium-network-key-file", settings.mycelium_network_key_file.is_some(), @@ -138,6 +142,28 @@ pub(crate) async fn start( settings: &crate::config::Settings, mut stop: tokio::sync::watch::Receiver, ) -> Result> { + // The daemon's key, 32 raw bytes (as `daemon` hands it an ephemeral one): read, + // or made, here, so a missing file fails before the daemon starts. + if let Some(path) = &settings.mycelium_key_file { + let (bytes, created) = crate::files::key_file( + path, + "Mycelium key", + settings.mycelium_key_create, + "mycelium-key-create", + "a new Mycelium address", + 32, + )?; + if bytes.len() != 32 { + anyhow::bail!( + "The Mycelium key in {} has {} bytes; it has 32", + path.display(), + bytes.len() + ); + } + if created { + tracing::info!(path = %path.display(), "Created a new Mycelium key"); + } + } let spawn_config = MyceliumSpawnConfig { rest_url_opt: settings .mycelium_rest_url -- cgit v1.3.1