MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / create

Function create

nodedb/src/ctl/join_token.rs:27–46  ·  view source on GitHub ↗
(data_dir: &Path, for_node: u64, ttl: Duration)

Source from the content-addressed store, hash-verified

25const CLUSTER_SECRET_LEN: usize = 32;
26
27pub fn create(data_dir: &Path, for_node: u64, ttl: Duration) -> Result<(), String> {
28 let secret_path = data_dir.join("tls").join("cluster_secret.bin");
29 let secret = read_cluster_secret(&secret_path)?;
30
31 let expiry = SystemTime::now()
32 .duration_since(UNIX_EPOCH)
33 .map_err(|e| format!("system clock before UNIX epoch: {e}"))?
34 + ttl;
35 let expiry_secs = expiry.as_secs();
36
37 let hex = tok::issue_token(&secret, for_node, expiry_secs)
38 .map_err(|e| format!("issue token: {e}"))?;
39
40 println!("join token (expires at unix {expiry_secs}):");
41 println!("{hex}");
42 println!();
43 println!("usage on joiner:");
44 println!(" NODEDB_JOIN_TOKEN={hex} nodedb <config.toml>");
45 Ok(())
46}
47
48fn read_cluster_secret(path: &Path) -> Result<[u8; CLUSTER_SECRET_LEN], String> {
49 let bytes =

Callers 15

run_subcommandFunction · 0.70
write_secureFunction · 0.50
make_file_with_modeFunction · 0.50
make_key_fileFunction · 0.50
write_secureFunction · 0.50
openMethod · 0.50
openMethod · 0.50
openMethod · 0.50
openMethod · 0.50

Calls 5

nowFunction · 0.85
issue_tokenFunction · 0.85
joinMethod · 0.80
duration_sinceMethod · 0.80
read_cluster_secretFunction · 0.70