Skip to content

Commit

Permalink
Fix bps to mbps; 0.0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
the2pizza committed Oct 29, 2024
1 parent 2436b03 commit 79b9da9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ config.toml
config-api.toml
deploy/servers
query.txt
query2.txt
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pony"
version = "0.0.16"
version = "0.0.17"
edition = "2021"

[dependencies]
Expand Down
101 changes: 0 additions & 101 deletions query.txt

This file was deleted.

4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::web::not_found;

#[derive(Parser)]
#[command(
version = "0.0.16",
version = "0.0.17",
about = "Pony - montiroing tool for Xray/Wireguard"
)]
struct Cli {
Expand Down Expand Up @@ -77,7 +77,7 @@ async fn main() -> std::io::Result<()> {
std::process::exit(1);
} else {
info!(">>> Settings: {:?}", settings);
info!(">>> Version: 0.0.16");
info!(">>> Version: 0.0.17");
}

let carbon_server = settings.carbon.address.clone();
Expand Down
43 changes: 21 additions & 22 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,26 @@ struct ConnectionsByType {
#[derive(Serialize)]
struct StatusResponse {
connections: ConnectionsByServer,
bps: BpsByServer,
mbps: MbpsByServer,
}

type Bps = Vec<HashMap<String, f64>>;
type BpsByServer = Vec<HashMap<String, HashMap<String, f64>>>;

fn convert_bps(rx: Bps, tx: Bps) -> BpsByServer {
let mut server_list: BpsByServer = Vec::new();

for (index, rx_map) in rx.iter().enumerate() {
if let Some(tx_map) = tx.get(index) {
for (server, &rx_value) in rx_map {
let tx_value = *tx_map.get(server).unwrap_or(&0.0);
let mut server_entry = HashMap::new();
server_entry.insert(
server.clone(),
HashMap::from([("rx".to_string(), rx_value), ("tx".to_string(), tx_value)]),
);
server_list.push(server_entry);
}
}
type Bps = HashMap<String, f64>;
type MbpsByServer = Vec<HashMap<String, HashMap<String, f64>>>;

fn convert_bps_to_mbps(rx: Bps, tx: Bps) -> MbpsByServer {
let mut server_list: MbpsByServer = Vec::new();

for (server, &rx_value) in &rx {
let tx_value = tx.get(server).copied().unwrap_or(0.0);
let mut server_entry = HashMap::new();
server_entry.insert(
server.clone(),
HashMap::from([
("rx".to_string(), (rx_value * 1500.0 / 1024.0 / 1024.0)),
("tx".to_string(), (tx_value * 1500.0 / 1024.0 / 1024.0)),
]),
);
server_list.push(server_entry);
}

server_list
Expand Down Expand Up @@ -175,14 +174,14 @@ pub async fn status(req: Path<Params>, ch_client: Data<Arc<Client>>) -> impl Res
}

let connections_by_server = convert_connections(connections_by_type.clone());
let bps_by_server = convert_bps(vec![rx.clone()], vec![tx.clone()]);
let mbps_by_server = convert_bps_to_mbps(rx.clone(), tx.clone());

debug!("Connections {:?}", connections_by_server);
debug!("Bps {:?} {:?}", rx, tx);
debug!("Mbps {:?}", mbps_by_server);

let response = StatusResponse {
connections: connections_by_server,
bps: bps_by_server,
mbps: mbps_by_server,
};

HttpResponse::Ok().json(response)
Expand Down

0 comments on commit 79b9da9

Please sign in to comment.