aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 04:57:36 +0100
committertv <tv@krebsco.de>2026-10-31 04:57:36 +0100
commitc02916c1f65cf283027c6880a1b87700dddbe484 (patch)
tree8024662df164b754446e638af3851533d22bbba8
parentedc143d3f24402c03197250b8431e0b7e000496b (diff)
move mycelium settings to mycelium module
-rw-r--r--src/config/mod.rs35
-rw-r--r--src/transport/mycelium/mod.rs27
2 files changed, 28 insertions, 34 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index b82ad9b..4afb0bb 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -567,35 +567,6 @@ fn default_mycelium_peers() -> Vec<String> {
}
impl Settings {
- /// `mycelium-rest-url`, parsed (checked when loading).
- #[cfg_attr(not(feature = "mycelium"), allow(dead_code))]
- pub(crate) fn mycelium_rest_url(&self) -> Option<url::Url> {
- self.mycelium_rest_url
- .as_deref()
- .and_then(|url| url::Url::parse(url).ok())
- }
-
- /// The options only a supervised Mycelium daemon takes, and whether each is set: the
- /// other side of `CONFLICTS`' `mycelium-rest-url` (a test keeps them the same).
- #[cfg_attr(not(any(feature = "mycelium", test)), allow(dead_code))]
- pub(crate) fn supervised_only(&self) -> [(&'static str, bool); 4] {
- [
- ("mycelium-key-file", self.mycelium_key_file.is_some()),
- (
- "mycelium-network-key-file",
- self.mycelium_network_key_file.is_some(),
- ),
- (
- "mycelium-network-name",
- self.mycelium_network_name.is_some(),
- ),
- (
- "mycelium-tcp-listen-port",
- self.mycelium_tcp_listen_port.is_some(),
- ),
- ]
- }
-
fn check(&self) -> Result<()> {
if crate::logging::LogFormat::parse(&self.log_format).is_none() {
bail!(
@@ -1659,7 +1630,8 @@ mod tests {
assert_eq!(named("tor"), None);
}
- /// `Settings::check` and the override rule name the same supervised-only options.
+ /// Mycelium's check and the override rule name the same supervised-only options.
+ #[cfg(feature = "mycelium")]
#[test]
fn supervised_only_options_are_the_conflicts() {
let settings = resolve(
@@ -1668,8 +1640,7 @@ mod tests {
)
.unwrap()
.settings;
- let names: Vec<&str> = settings
- .supervised_only()
+ let names: Vec<&str> = crate::transport::mycelium::supervised_only(&settings)
.iter()
.map(|(name, _)| *name)
.collect();
diff --git a/src/transport/mycelium/mod.rs b/src/transport/mycelium/mod.rs
index 04474fe..ac55ae9 100644
--- a/src/transport/mycelium/mod.rs
+++ b/src/transport/mycelium/mod.rs
@@ -98,7 +98,7 @@ pub(crate) struct MyceliumTransport {
pub(crate) fn check(settings: &crate::config::Settings) -> Result<()> {
if let Some(url) = &settings.mycelium_rest_url {
Url::parse(url).with_context(|| format!("mycelium-rest-url {url:?}"))?;
- if let Some((name, _)) = settings.supervised_only().iter().find(|(_, set)| *set) {
+ if let Some((name, _)) = supervised_only(settings).iter().find(|(_, set)| *set) {
anyhow::bail!(
"{name} is for a supervised Mycelium daemon and can't be combined with mycelium-rest-url"
);
@@ -111,6 +111,26 @@ pub(crate) fn check(settings: &crate::config::Settings) -> Result<()> {
Ok(())
}
+/// 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] {
+ [
+ ("mycelium-key-file", settings.mycelium_key_file.is_some()),
+ (
+ "mycelium-network-key-file",
+ settings.mycelium_network_key_file.is_some(),
+ ),
+ (
+ "mycelium-network-name",
+ settings.mycelium_network_name.is_some(),
+ ),
+ (
+ "mycelium-tcp-listen-port",
+ settings.mycelium_tcp_listen_port.is_some(),
+ ),
+ ]
+}
+
/// The transport as `settings` configure it (`transport::start`): its daemon supervised
/// (started, which can take a while) or one running elsewhere. None if `stop` came
/// first.
@@ -119,7 +139,10 @@ pub(crate) async fn start(
mut stop: tokio::sync::watch::Receiver<bool>,
) -> Result<Option<MyceliumTransport>> {
let spawn_config = MyceliumSpawnConfig {
- rest_url_opt: settings.mycelium_rest_url(),
+ rest_url_opt: settings
+ .mycelium_rest_url
+ .as_deref()
+ .and_then(|url| Url::parse(url).ok()),
key_file_opt: settings.mycelium_key_file.clone(),
network_key_file: settings.mycelium_network_key_file.clone(),
network_name: settings.mycelium_network_name.clone(),