aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--CHANGELOG.md3
-rw-r--r--docs/guides/federation/getting-started.md10
-rw-r--r--docs/lifecycle.md4
-rw-r--r--src/config/mod.rs47
-rw-r--r--src/lib.rs9
5 files changed, 65 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0f615be..84a9469 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,9 @@ it from the release before ([`docs/operations.md`](docs/operations.md),
## Unreleased
+* `continuum node-id FILE` prints the node ID of a node key, `--create` making it, without
+ starting a node ([`docs/lifecycle.md`](docs/lifecycle.md); [`src/config/mod.rs`](src/config/mod.rs)).
+
* `continuum-party status` says at a glance where the party and its node stand: the
store and its version, the party's keys and nodes, a stop, the proposals, refused
versions, and what to sign again; `values [PATH]` shows what counts, with who writes
diff --git a/docs/guides/federation/getting-started.md b/docs/guides/federation/getting-started.md
index fb4c791..d148672 100644
--- a/docs/guides/federation/getting-started.md
+++ b/docs/guides/federation/getting-started.md
@@ -32,14 +32,14 @@ Here one key does everything a party signs.
## A node for each party
Each node needs its node key, a user of its API, and its node ID, which the first
-version names before the federation starts. A node makes its key with
-`--node-key-create` and logs its ID before anything else (`Node identity`): start it so
-once, with nothing of a swarm, and stop it.
+version names before the federation starts. `continuum node-id` makes the key and says
+the ID, without starting the node:
```sh
+continuum node-id --create node.key
+# a new node key in node.key: a new node
+# continuum:5be1…
printf '%s' 'secret' | argon2 "$(openssl rand -hex 16)" -id -e | sed 's/^/tv:/' > htpasswd
-continuum --node-key-file node.key --node-key-create --htpasswd htpasswd --mycelium-enable
-# INFO Created a new node key: this is a new node node_id=continuum:5be1…
```
## The first version
diff --git a/docs/lifecycle.md b/docs/lifecycle.md
index 47cf051..a221063 100644
--- a/docs/lifecycle.md
+++ b/docs/lifecycle.md
@@ -45,7 +45,9 @@ What happens before the node talks to anyone, in order:
2. **The node key** (`--node-key-file`) and **the swarm key** (`--swarm-key-file`) are
read, so a bad file fails at once. A missing key file is an error, unless
`--node-key-create` asks for a new node key (a new node), or `--swarm-key-create`
- for a new swarm key (on the swarm's first node; the others need a copy).
+ for a new swarm key (on the swarm's first node; the others need a copy). `continuum
+ node-id FILE` prints the node ID of the key `FILE` holds, without starting a node
+ (`--create` makes the key first, where there is none).
3. **The state file** (`--state-file`) is read: the swarm ID the node belongs to and
members to reach it through.
4. **A document to start on**, if any: the document file (`--document-file`) or a
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 {
diff --git a/src/lib.rs b/src/lib.rs
index 1ac1f35..28d18e5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -83,6 +83,15 @@ pub async fn run() -> Result<()> {
logging::init();
let config = config::load()?;
+ if let Some((file, create)) = &config.node_id {
+ let new = !file.exists();
+ let key = identity::NodeKey::load(file, *create)?;
+ if new {
+ eprintln!("a new node key in {}: a new node", file.display());
+ }
+ println!("{}", key.id());
+ return Ok(());
+ }
if config.print_only {
println!(
"{}",