diff --git a/Cargo.lock b/Cargo.lock index 8585b99..5c90893 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1993,7 +1993,7 @@ dependencies = [ [[package]] name = "kaspa-addresses" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "borsh", "js-sys", @@ -2008,7 +2008,7 @@ dependencies = [ [[package]] name = "kaspa-bip32" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "borsh", "bs58", @@ -2035,7 +2035,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-client" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "ahash", "cfg-if 1.0.0", @@ -2064,7 +2064,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-core" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "async-trait", "borsh", @@ -2099,7 +2099,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-notify" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "async-channel 2.3.1", "cfg-if 1.0.0", @@ -2119,7 +2119,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-wasm" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "cfg-if 1.0.0", "faster-hex 0.6.1", @@ -2144,7 +2144,7 @@ dependencies = [ [[package]] name = "kaspa-core" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "cfg-if 1.0.0", "ctrlc", @@ -2163,7 +2163,7 @@ dependencies = [ [[package]] name = "kaspa-hashes" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "blake2b_simd", "borsh", @@ -2182,7 +2182,7 @@ dependencies = [ [[package]] name = "kaspa-index-core" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -2202,7 +2202,7 @@ dependencies = [ [[package]] name = "kaspa-math" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "borsh", "faster-hex 0.6.1", @@ -2222,7 +2222,7 @@ dependencies = [ [[package]] name = "kaspa-merkle" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "kaspa-hashes", ] @@ -2230,7 +2230,7 @@ dependencies = [ [[package]] name = "kaspa-metrics-core" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "async-trait", "borsh", @@ -2247,7 +2247,7 @@ dependencies = [ [[package]] name = "kaspa-mining-errors" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "kaspa-consensus-core", "thiserror", @@ -2256,7 +2256,7 @@ dependencies = [ [[package]] name = "kaspa-muhash" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "kaspa-hashes", "kaspa-math", @@ -2267,7 +2267,7 @@ dependencies = [ [[package]] name = "kaspa-notify" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -2299,7 +2299,7 @@ dependencies = [ [[package]] name = "kaspa-pow" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "js-sys", "kaspa-consensus-client", @@ -2363,7 +2363,7 @@ dependencies = [ [[package]] name = "kaspa-rpc-core" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -2405,7 +2405,7 @@ dependencies = [ [[package]] name = "kaspa-rpc-macros" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "convert_case 0.6.0", "proc-macro-error", @@ -2418,7 +2418,7 @@ dependencies = [ [[package]] name = "kaspa-txscript" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "blake2b_simd", "borsh", @@ -2449,7 +2449,7 @@ dependencies = [ [[package]] name = "kaspa-txscript-errors" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "secp256k1", "thiserror", @@ -2458,7 +2458,7 @@ dependencies = [ [[package]] name = "kaspa-utils" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "async-channel 2.3.1", "borsh", @@ -2486,7 +2486,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-core" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "aes", "ahash", @@ -2564,7 +2564,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-keys" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "async-trait", "borsh", @@ -2597,7 +2597,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-macros" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "convert_case 0.5.0", "proc-macro-error", @@ -2611,7 +2611,7 @@ dependencies = [ [[package]] name = "kaspa-wasm" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -2639,7 +2639,7 @@ dependencies = [ [[package]] name = "kaspa-wasm-core" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "faster-hex 0.6.1", "hexplay", @@ -2651,7 +2651,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-client" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "async-std", "async-trait", @@ -2687,7 +2687,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-wasm" version = "0.14.1" -source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#fad7bd1a74cb362cc374c77bbda42567edf3de73" +source = "git+https://github.com/aspectron/rusty-kaspa.git?branch=omega#2a1cff2e6f465a389e9216f80e8708f43a439dc3" dependencies = [ "ahash", "async-std", diff --git a/src/config.rs b/src/config.rs index 940e3b4..29a02ac 100644 --- a/src/config.rs +++ b/src/config.rs @@ -311,7 +311,11 @@ pub fn pack() -> Result<()> { let local_config_folder = local_config_folder().ok_or(Error::LocalConfigNotFound)?; let local_config_file = local_config_folder.join(local_config_file()); let local_data_file = local_config_folder.join(global_config_file()); - log::info(format!(" in: {}\nout: {}", local_config_file.display(),local_data_file.display()))?; + log::info(format!( + " in: {}\nout: {}", + local_config_file.display(), + local_data_file.display() + ))?; let toml = fs::read_to_string(local_config_file)?; Config::try_parse(toml.as_str())?; let data = chacha20poly1305::encrypt_slice(toml.as_bytes(), &key)?; diff --git a/src/connection.rs b/src/connection.rs index e3f895d..4f40e3f 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -22,7 +22,8 @@ pub struct Connection { // caps: Arc>>, caps: ArcSwapOption, is_synced: AtomicBool, - sockets: AtomicU64, + clients: AtomicU64, + peers: AtomicU64, node: Arc, monitor: Arc, params: PathParams, @@ -67,7 +68,8 @@ impl Connection { delegate: ArcSwap::new(Arc::new(None)), is_connected: AtomicBool::new(false), is_synced: AtomicBool::new(false), - sockets: AtomicU64::new(0), + clients: AtomicU64::new(0), + peers: AtomicU64::new(0), is_online: AtomicBool::new(false), }) } @@ -79,19 +81,18 @@ impl Connection { #[inline] pub fn score(&self) -> u64 { - self.sockets.load(Ordering::Relaxed) + self.clients.load(Ordering::Relaxed) } #[inline] pub fn is_available(&self) -> bool { self.is_delegate() && self.online() - && self - .caps - .load() - .as_ref() - .as_ref() - .is_some_and(|caps| caps.socket_capacity > self.sockets()) + && self.caps.load().as_ref().as_ref().is_some_and(|caps| { + let clients = self.clients(); + let peers = self.peers(); + clients < caps.clients_limit && clients + peers < caps.fd_limit + }) } #[inline] @@ -109,9 +110,19 @@ impl Connection { self.is_synced.load(Ordering::Relaxed) } + #[inline] + pub fn clients(&self) -> u64 { + self.clients.load(Ordering::Relaxed) + } + + #[inline] + pub fn peers(&self) -> u64 { + self.peers.load(Ordering::Relaxed) + } + #[inline] pub fn sockets(&self) -> u64 { - self.sockets.load(Ordering::Relaxed) + self.clients() + self.peers() } #[inline] @@ -239,7 +250,11 @@ impl Connection { self.is_online.store(online, Ordering::Relaxed); if online != previous { if self.verbose() { - log_error!("Offline","{}", self.node.address); + if online { + log_success!("Online","{}", self.node.address); + } else { + log_error!("Offline","{}", self.node.address); + } } self.update(); } @@ -343,35 +358,35 @@ impl Connection { if is_synced { match self.client.get_active_connections().await { - Ok(connections) => { + Ok(Connections { clients, peers: _ }) => { if self.verbose() { - let previous = self.sockets.load(Ordering::Relaxed); - if connections != previous { - self.sockets.store(connections, Ordering::Relaxed); + let previous = self.clients.load(Ordering::Relaxed); + if clients != previous { + self.clients.store(clients, Ordering::Relaxed); log_success!("Clients", "{self}"); } } else { - self.sockets.store(connections, Ordering::Relaxed); + self.clients.store(clients, Ordering::Relaxed); } Ok(()) } Err(err) => { - log_error!("Metrics", "{self}"); - log_error!("RPC", "{err}"); + log_error!("RPC", "{self}"); + log_error!("Error", "{err}"); Err(Error::Metrics) } } } else { if is_synced != previous_sync { - log_error!("Syncing", "{self}"); + log_error!("Sync", "{self}"); } Err(Error::Sync) } } Err(err) => { log_error!("RPC", "{self}"); - log_error!("RPC", "{err}"); + log_error!("Error", "{err}"); Err(Error::Status) } } @@ -416,7 +431,8 @@ pub struct Status<'a> { pub network: &'a NetworkId, pub cores: u64, pub status: &'static str, - pub connections: u64, + pub peers: u64, + pub clients: u64, pub capacity: u64, #[serde(skip_serializing_if = "Option::is_none")] pub delegates: Option>, @@ -436,7 +452,8 @@ impl<'a> From<&'a Arc> for Status<'a> { let encryption = node.params().tls(); let network = &node.network; let status = connection.status(); - let connections = delegate.sockets(); + let clients = delegate.clients(); + let peers = delegate.peers(); let (version, sid, capacity, cores) = delegate .caps() .as_ref() @@ -445,7 +462,7 @@ impl<'a> From<&'a Arc> for Status<'a> { ( caps.version.clone(), caps.system_id, - caps.socket_capacity, + caps.clients_limit, caps.cpu_physical_cores, ) }) @@ -471,7 +488,8 @@ impl<'a> From<&'a Arc> for Status<'a> { network, cores, status, - connections, + clients, + peers, capacity, delegates, } diff --git a/src/imports.rs b/src/imports.rs index 1dab112..fff266e 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -13,8 +13,8 @@ pub use crate::path::*; pub use crate::resolver::Resolver; pub use crate::result::Result; pub(crate) use crate::rpc; -pub use crate::rpc::Caps; pub use crate::rpc::ClientT; +pub use crate::rpc::{Caps, Connections}; pub use crate::services::Service; pub(crate) use crate::session::*; pub(crate) use crate::status; diff --git a/src/rpc/kaspa.rs b/src/rpc/kaspa.rs index fe60288..d0fd96c 100644 --- a/src/rpc/kaspa.rs +++ b/src/rpc/kaspa.rs @@ -1,6 +1,6 @@ -use super::Caps; +use super::{Caps, Connections}; use crate::imports::*; -use kaspa_rpc_core::GetSystemInfoResponse; +use kaspa_rpc_core::{GetConnectionsResponse, GetSystemInfoResponse}; pub use kaspa_wrpc_client::KaspaRpcClient; // reduce fd_limit by this amount to ensure the @@ -75,7 +75,7 @@ impl rpc::ClientT for Client { // 1024 connections per core (default NGINX worker configuration) // TODO: this should be increased in the future once a custom // proxy is implemented - let socket_capacity = fd_limit_actual.min(cpu_physical_cores * rpc::SOCKETS_PER_CORE); + let clients_limit = cpu_physical_cores * rpc::SOCKETS_PER_CORE; let system_id = system_id .and_then(|v| v[0..8].try_into().ok().map(u64::from_be_bytes)) .unwrap_or_default(); @@ -87,8 +87,8 @@ impl rpc::ClientT for Client { git_hash, total_memory, cpu_physical_cores, - fd_limit, - socket_capacity, + fd_limit: fd_limit_actual, + clients_limit, }) } @@ -96,10 +96,13 @@ impl rpc::ClientT for Client { Ok(self.client.get_sync_status().await?) } - async fn get_active_connections(&self) -> Result { - let sockets = self.client.get_connections().await?; + async fn get_active_connections(&self) -> Result { + let GetConnectionsResponse { clients, peers } = self.client.get_connections().await?; - Ok(sockets as u64) + Ok(Connections { + clients: clients as u64, + peers: peers as u64, + }) } fn trigger_abort(&self) -> Result<()> { diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index bab616b..a12f19e 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -18,10 +18,10 @@ pub struct Caps { pub total_memory: u64, // number of cores pub cpu_physical_cores: u64, - // number of utilized file descriptors + // number of available file descriptors pub fd_limit: u64, - // number of available sockets - pub socket_capacity: u64, + // number of available clients + pub clients_limit: u64, } impl Caps { @@ -30,6 +30,13 @@ impl Caps { } } +#[derive(Debug)] +pub struct Connections { + pub clients: u64, + #[allow(dead_code)] + pub peers: u64, +} + #[enum_dispatch] #[derive(Debug)] pub enum Client { @@ -63,7 +70,7 @@ pub trait ClientT: std::fmt::Debug + Sized + Send + Sync + 'static { unimplemented!() } - async fn get_active_connections(&self) -> Result { + async fn get_active_connections(&self) -> Result { unimplemented!() } diff --git a/templates/index.js b/templates/index.js index 4144f8d..38829e6 100644 --- a/templates/index.js +++ b/templates/index.js @@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', () => { thead = document.createElement('thead'); table.appendChild(thead); - thead.innerHTML = "SID:UIDSERVICEVERSIONFQDNPROTOENCODINGNETWORKSTATUSCONN/CAPLOAD"; + thead.innerHTML = "SID:UIDSERVICEVERSIONFQDNPROTOENCODINGNETWORKSTATUSPEERSCONN/CAPLOAD"; tbody = document.createElement('tbody'); tbody.id = "nodes"; @@ -58,9 +58,9 @@ function render() { .reduce((acc, node) => { const network = node.network; if (!acc[network]) { - acc[network] = { connections: 0, capacity: 0 }; + acc[network] = { clients: 0, capacity: 0 }; } - acc[network].connections += node.connections; + acc[network].clients += node.clients; acc[network].capacity += node.capacity; return acc; }, {}); @@ -79,7 +79,8 @@ function render() { network, cores, status, - connections, + peers, + clients, capacity, delegates, } = node; @@ -94,12 +95,13 @@ function render() { } el.className = filter(node, ctx); - let load = (connections / capacity * 100.0).toFixed(2); - let connections_ = connections.toLocaleString(); + let load = (clients / capacity * 100.0).toFixed(2); + let peers_ = peers.toLocaleString(); + let clients_ = clients.toLocaleString(); let capacity_ = capacity.toLocaleString(); el.innerHTML = `${sid}:${uid}${service}${version}${fqdn}${protocol}${encoding}${network}${status}`; if (status != "offline") { - el.innerHTML += `${connections_}/${capacity_}${load}%`; + el.innerHTML += `${peers_}${clients_}/${capacity_}${load}%`; } }); @@ -108,10 +110,10 @@ function render() { } document.getElementById('status').innerText = Object.entries(status).map(([network, status]) => { - let load = (status.connections / status.capacity * 100.0).toFixed(2); - let connections = status.connections.toLocaleString(); + let load = (status.clients / status.capacity * 100.0).toFixed(2); + let clients = status.connections.toLocaleString(); let capacity = status.capacity.toLocaleString(); - return `${network}: ${connections}/${capacity} ${load}%`; + return `${network}: ${clients}/${capacity} ${load}%`; }).join(' '); }