aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/mycelium/mod.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-01 05:32:36 +0100
committertv <tv@krebsco.de>2026-11-01 05:32:36 +0100
commitdf74bf7026569514210982a2c7c3a4c36f469a32 (patch)
tree79b6b0d1fde6acfca37187de0dd459cea7c23335 /src/transport/mycelium/mod.rs
parent6bab0c4af15988e3c0d4e38de3ee9c1f8c4a8be2 (diff)
allow creating all key files
Diffstat (limited to 'src/transport/mycelium/mod.rs')
-rw-r--r--src/transport/mycelium/mod.rs28
1 files changed, 27 insertions, 1 deletions
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<bool>,
) -> Result<Option<MyceliumTransport>> {
+ // 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