From f2c2f222970ad2d29eea7d42f768c79dac12055d Mon Sep 17 00:00:00 2001 From: Kira Sotnikov Date: Tue, 29 Oct 2024 20:49:24 +0300 Subject: [PATCH] add total; 0.0.18 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 4 ++-- src/web.rs | 22 +++++++++++++++++++--- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a2135f8..30dea1d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1620,7 +1620,7 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "pony" -version = "0.0.17" +version = "0.0.18" dependencies = [ "actix-web", "actix-web-httpauth", diff --git a/Cargo.toml b/Cargo.toml index a01adc27..84807dff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pony" -version = "0.0.17" +version = "0.0.18" edition = "2021" [dependencies] diff --git a/src/main.rs b/src/main.rs index 5a77875b..28dd1554 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,7 @@ use crate::web::not_found; #[derive(Parser)] #[command( - version = "0.0.17", + version = "0.0.18", about = "Pony - montiroing tool for Xray/Wireguard" )] struct Cli { @@ -77,7 +77,7 @@ async fn main() -> std::io::Result<()> { std::process::exit(1); } else { info!(">>> Settings: {:?}", settings); - info!(">>> Version: 0.0.17"); + info!(">>> Version: 0.0.18"); } let carbon_server = settings.carbon.address.clone(); diff --git a/src/web.rs b/src/web.rs index 9cd83f65..fbb1087c 100644 --- a/src/web.rs +++ b/src/web.rs @@ -58,7 +58,7 @@ fn convert_bps_to_mbps(rx: Bps, tx: Bps) -> MbpsByServer { server_list } -type ConnectionsByServer = HashMap>>; +type ConnectionsByServer = HashMap>; fn convert_connections(connections: ConnectionsByType) -> ConnectionsByServer { let mut server_map: ConnectionsByServer = HashMap::new(); @@ -69,16 +69,32 @@ fn convert_connections(connections: ConnectionsByType) -> ConnectionsByServer { ("ss", connections.ss), ("wg", connections.wg), ] { - for conn in conn_list { + for conn in conn_list.clone() { for (server, &value) in &conn.connection { server_map .entry(server.clone()) .or_insert_with(Vec::new) - .push(HashMap::from([(conn_type.to_string(), value)])); + .push(Connection { + connection: HashMap::from([(conn_type.to_string(), value)]), + }); } } } + for (_, conn_list) in &mut server_map { + let mut total = 0.0; + + for conn in conn_list.iter() { + for &value in conn.connection.values() { + total += value; + } + } + + conn_list.push(Connection { + connection: HashMap::from([("total".to_string(), total)]), + }); + } + server_map }