#![allow(dead_code)] use std::collections::HashMap; use std::sync::Mutex; use ed25519_dalek::{VerifyingKey, SigningKey}; use once_cell::sync::Lazy; use std::time::SystemTime; #[derive(Clone)] pub struct NodeInfo { pubkey: VerifyingKey, updated_at: SystemTime, } static NODES: Lazy>> = Lazy::new(|| { Mutex::new(HashMap::new()) }); static KEYS: Lazy>> = Lazy::new(|| { Mutex::new(HashMap::new()) }); pub fn add_key(pubkey: VerifyingKey, privkey: SigningKey) { let mut map = KEYS.lock().unwrap(); map.insert(pubkey, privkey); } pub fn remove_key(pubkey: &VerifyingKey) { let mut map = KEYS.lock().unwrap(); map.remove(pubkey); } pub fn get_privkey(pubkey: &VerifyingKey) -> Option { let map = KEYS.lock().unwrap(); map.get(pubkey).cloned() } pub fn add_node(ip: String, info: NodeInfo) { let mut map = NODES.lock().unwrap(); map.insert(ip, info); } pub fn remove_node(ip: &str) { let mut map = NODES.lock().unwrap(); map.remove(ip); } pub fn get_pubkey(ip: &str) -> Option { let map = NODES.lock().unwrap(); map.get(ip).cloned() }