summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
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(),