// nac-daemon/src/network.rs // NAC 网络模块 - NAC_lens 协议节点发现和连接 use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PeerInfo { pub node_id: String, pub address: String, pub port: u16, pub version: String, pub latency_ms: u64, pub connected: bool, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct NetworkStats { pub connected_peers: usize, pub total_known_peers: usize, pub inbound: usize, pub outbound: usize, pub bandwidth_in_kbps: f64, pub bandwidth_out_kbps: f64, } /// 获取已知引导节点列表(NAC_lens 协议) pub fn get_bootstrap_nodes() -> Vec { vec![ PeerInfo { node_id: "NAC_NODE_BOOTSTRAP_01".to_string(), address: "103.96.148.7".to_string(), port: 9090, version: "NAC_lens/4.0-alpha".to_string(), latency_ms: 0, connected: false, }, ] } /// 检查节点连通性 pub fn ping_node(address: &str, port: u16) -> bool { use std::net::TcpStream; use std::time::Duration; TcpStream::connect_timeout( &format!("{}:{}", address, port).parse().expect("mainnet: handle error"), Duration::from_secs(2), ).is_ok() }