diff options
Diffstat (limited to 'src/config/mod.rs')
| -rw-r--r-- | src/config/mod.rs | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index ea323e1..25b39ea 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -201,7 +201,7 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[ "This node's key (Ed25519, 32 raw bytes): who the node is, whatever transport reaches it. Keep it with the node: a new key is a new node. Required, but with relay-only (then not allowed).", ), option( - "create-node-key", + "node-key-create", Kind::Flag, "BOOL", Some("false"), @@ -215,6 +215,13 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[ "Pre-shared swarm key: only nodes that know it may join (raw bytes, at least 16; e.g. `head -c 32 /dev/urandom`). Without it, any node that can reach a member may join.", ), option( + "swarm-key-create", + Kind::Flag, + "BOOL", + Some("false"), + "Create a new swarm key at swarm-key-file if there is no file there: on the swarm's first node, as the others need a copy of it (a key of their own keeps them out). Without it, a missing key file is an error.", + ), + option( "alias", Kind::Text, "NAME", @@ -373,6 +380,13 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[ "With the libp2p transport: its key (Ed25519, 32 raw bytes), which makes its peer ID; a new one each start if absent (the node ID stays the same either way).", ), option( + "libp2p-key-create", + Kind::Flag, + "BOOL", + Some("false"), + "With the libp2p transport: create a new libp2p key at libp2p-key-file if there is no file there (a new peer ID). Without it, a missing key file is an error.", + ), + option( "mycelium-rest-url", Kind::Text, "SCHEME://HOSTNAME:PORT", @@ -389,6 +403,13 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[ "Private key of the supervised Mycelium daemon (its identity); a new one each start if absent.", ), option( + "mycelium-key-create", + Kind::Flag, + "BOOL", + Some("false"), + "Create a new key for the supervised Mycelium daemon at mycelium-key-file if there is no file there (a new Mycelium address). Without it, a missing key file is an error.", + ), + option( "mycelium-network-key-file", Kind::Text, "PATH", @@ -470,8 +491,10 @@ pub(crate) struct Settings { /// Required (`check`), but not allowed with `relay_only`. pub(crate) node_key_file: Option<PathBuf>, #[serde(default)] - pub(crate) create_node_key: bool, + pub(crate) node_key_create: bool, pub(crate) swarm_key_file: Option<PathBuf>, + #[serde(default)] + pub(crate) swarm_key_create: bool, pub(crate) alias: Option<String>, #[serde(default = "default_keepalive", with = "crate::units::duration_option")] pub(crate) keepalive: Duration, @@ -530,6 +553,9 @@ pub(crate) struct Settings { pub(crate) libp2p_public: bool, #[cfg_attr(not(feature = "libp2p"), allow(dead_code))] pub(crate) libp2p_key_file: Option<PathBuf>, + #[serde(default)] + #[cfg_attr(not(feature = "libp2p"), allow(dead_code))] + pub(crate) libp2p_key_create: bool, #[cfg_attr(not(feature = "tor"), allow(dead_code))] pub(crate) tor_state_dir: Option<PathBuf>, #[serde(default = "default_tor_port")] @@ -541,6 +567,9 @@ pub(crate) struct Settings { pub(crate) mycelium_rest_url: Option<String>, #[cfg_attr(not(feature = "mycelium"), allow(dead_code))] pub(crate) mycelium_key_file: Option<PathBuf>, + #[serde(default)] + #[cfg_attr(not(feature = "mycelium"), allow(dead_code))] + pub(crate) mycelium_key_create: bool, #[cfg_attr(not(feature = "mycelium"), allow(dead_code))] pub(crate) mycelium_network_key_file: Option<PathBuf>, #[cfg_attr(not(feature = "mycelium"), allow(dead_code))] @@ -624,6 +653,12 @@ impl Settings { if self.genesis && self.recover_from.is_some() { bail!("recover-from starts the swarm from a backup; it can't be combined with genesis"); } + if self.node_key_create && self.node_key_file.is_none() { + bail!("node-key-create creates the key at node-key-file; set that too"); + } + if self.swarm_key_create && self.swarm_key_file.is_none() { + bail!("swarm-key-create creates the key at swarm-key-file; set that too"); + } if self.relay_only { self.check_relay_only()?; } else { @@ -632,7 +667,7 @@ impl Settings { } if self.node_key_file.is_none() { bail!( - "node-key-file is required: who this node is (create one with create-node-key)" + "node-key-file is required: who this node is (create one with node-key-create)" ); } } @@ -706,7 +741,7 @@ impl Settings { // Its listen address and key: libp2p's checks (`transport::libp2p::check`). let swarm_options = [ ("node-key-file", self.node_key_file.is_some()), - ("create-node-key", self.create_node_key), + ("node-key-create", self.node_key_create), ("seeds", !self.seeds.is_empty()), ("genesis", self.genesis), ("state-file", self.state_file.is_some()), @@ -714,6 +749,7 @@ impl Settings { ("recover-from", self.recover_from.is_some()), ("remake", self.remake.is_some()), ("swarm-key-file", self.swarm_key_file.is_some()), + ("swarm-key-create", self.swarm_key_create), ("protocol-writers", !self.protocol_writers.is_empty()), ("alias", self.alias.is_some()), ("debug-api", self.debug_api), @@ -840,6 +876,7 @@ const CONFLICTS: &[(&[&str], &[&str])] = &[( &["mycelium-rest-url"], &[ "mycelium-key-file", + "mycelium-key-create", "mycelium-network-key-file", "mycelium-network-name", "mycelium-tcp-listen-port", |
