summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-24 06:53:17 +0200
committertv <tv@krebsco.de>2026-10-24 06:53:17 +0200
commit8ee3b7f0d2f9b76cb24f0049431bd58d09d6c5a4 (patch)
tree6e9774ff74634029309e6720e7c8eccce62766cf /src/main.rs
parenteeae01887aa7bf5ab4dc4d9c5dc90e06c465accd (diff)
add node aliases
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 7261d6a..65134d8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -97,12 +97,32 @@ struct Args {
#[arg(long, value_name = "COUNT", default_value_t = 12)]
neighbours: usize,
+ /// A name for this node, shown next to its public key (/peers, metrics, logs).
+ /// Published in the swarm's member list; not unique, never an identity.
+ #[arg(long, value_name = "NAME", value_parser = parse_alias)]
+ alias: Option<String>,
+
/// Test hook: start on a non-genesis epoch of this generation (with a fixed dummy
/// id), to check that nodes on different epochs refuse to sync.
#[arg(long, hide = true, requires = "debug_api", value_name = "GENERATION")]
debug_epoch: Option<u64>,
}
+/// Up to 64 characters, no control characters, not blank.
+fn parse_alias(value: &str) -> Result<String, String> {
+ let alias = value.trim();
+ if alias.is_empty() {
+ return Err("must not be blank".to_owned());
+ }
+ if alias.chars().count() > 64 {
+ return Err("must be at most 64 characters".to_owned());
+ }
+ if alias.chars().any(char::is_control) {
+ return Err("must not contain control characters".to_owned());
+ }
+ Ok(alias.to_owned())
+}
+
#[tokio::main]
async fn main() -> Result<()> {
logging::init();
@@ -201,6 +221,7 @@ async fn main() -> Result<()> {
swarm_key,
run_id: uuid::Uuid::new_v4().into_bytes(),
neighbours_k: args.neighbours.max(2),
+ alias: args.alias,
neighbours: Default::default(),
pulling: Default::default(),
rtt: Default::default(),