aboutsummaryrefslogtreecommitdiffstats
path: root/src/config/mod.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-19 19:00:05 +0000
committertv <tv@krebsco.de>2026-11-19 20:13:16 +0100
commitc66f0f8f7297484e095e02d259c84469b6c42367 (patch)
treebb12683c006ef734689deb0fbe7bad40edc04dc8 /src/config/mod.rs
parent2a8575ce6562e1579f9c9bd9c9964e3ef36d08f1 (diff)
continuum node-id: a node key's ID, without starting the node
The founders name each node by its ID in the first version, before the federation starts; getting it meant starting a node once with --node-key-create and reading its log. `continuum node-id FILE` prints the node ID of the key FILE holds and exits, `--create` making the key there first where there is none (saying so on standard error). Logs are off for it, as for --print-config: the ID goes to standard output alone.
Diffstat (limited to 'src/config/mod.rs')
-rw-r--r--src/config/mod.rs47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 87f53ba..ea15e06 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -1884,10 +1884,27 @@ fn command() -> Command {
.long(PRINT_CONFIG)
.action(ArgAction::SetTrue)
.help("Print the effective configuration as JSON (with each value's source) and exit."),
+ )
+ .subcommand(
+ Command::new(NODE_ID)
+ .about(
+ "Print the node ID of the node key a file holds, as a version names the \
+ node, and exit: what to give the founders before the node first starts",
+ )
+ .arg(Arg::new("file").required(true).value_name("PATH"))
+ .arg(
+ Arg::new("create")
+ .long("create")
+ .action(ArgAction::SetTrue)
+ .help("Make a new key in the file where there is none, as node-key-create"),
+ ),
);
with_options(command, OPTIONS)
}
+/// `continuum node-id FILE`: the node ID of the key in `FILE` (`Loaded::node_id`).
+const NODE_ID: &str = "node-id";
+
/// `command` taking `options` as arguments, and configuration files for them
/// (`--config`) and unsets of what those set (`--unset`).
pub(crate) fn with_options(command: Command, options: &'static [OptionSpec]) -> Command {
@@ -2002,6 +2019,9 @@ pub(crate) struct Loaded {
pub(crate) files: Vec<PathBuf>,
/// `--print-config`: print [`Loaded::report`] and exit.
pub(crate) print_only: bool,
+ /// `node-id FILE [--create]`: print the node ID of the key `FILE` holds, made there
+ /// with `--create` where there is none, and exit.
+ pub(crate) node_id: Option<(PathBuf, bool)>,
}
impl Loaded {
@@ -2134,13 +2154,19 @@ impl Loaded {
pub(crate) fn load() -> Result<Loaded> {
let matches = command().get_matches();
let print_only = matches.get_flag(PRINT_CONFIG);
- if print_only {
- // Logs go to stdout too; the report says where each value came from anyway.
+ let node_id = matches.subcommand_matches(NODE_ID).map(|sub| {
+ let file = sub.get_one::<String>("file").expect("required");
+ (PathBuf::from(file), sub.get_flag("create"))
+ });
+ if print_only || node_id.is_some() {
+ // Logs go to stdout too: the report or the node ID goes there alone (the report
+ // says where each value came from anyway).
let _ = crate::logging::set_filter("off");
}
let (merged, files) = merged(&matches, OPTIONS)?;
let mut loaded = resolve(merged, files)?;
loaded.print_only = print_only;
+ loaded.node_id = node_id;
Ok(loaded)
}
@@ -2312,6 +2338,7 @@ fn resolve(merged: Layer, files: Vec<PathBuf>) -> Result<Loaded> {
.collect(),
files,
print_only: false,
+ node_id: None,
})
}
@@ -2441,6 +2468,22 @@ mod tests {
command().debug_assert();
}
+ /// `node-id FILE` asks for the node ID of the key in `FILE`, `--create` making one.
+ #[test]
+ fn the_node_id_is_asked_for() {
+ let matches = command()
+ .try_get_matches_from(["continuum", "node-id", "node.key", "--create"])
+ .unwrap();
+ let sub = matches.subcommand_matches(NODE_ID).unwrap();
+ assert_eq!(sub.get_one::<String>("file").unwrap(), "node.key");
+ assert!(sub.get_flag("create"));
+ assert!(
+ command()
+ .try_get_matches_from(["continuum", "node-id"])
+ .is_err()
+ );
+ }
+
#[test]
fn later_sources_override_conflicts_and_unset() {
let from = |provenance: Provenance, value: JsonValue| Entry {