From 188055c812a8b6610bc2f6d3a707de9428beebc4 Mon Sep 17 00:00:00 2001 From: pcmid Date: Mon, 25 Oct 2021 16:39:14 +0800 Subject: [PATCH 1/3] Fix: multiply the number of bytes by 8 --- crates/librqbit/src/http_api.rs | 14 +++++++------- crates/librqbit_core/src/speed_estimator.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/librqbit/src/http_api.rs b/crates/librqbit/src/http_api.rs index 6ba2eba..dcff7a5 100644 --- a/crates/librqbit/src/http_api.rs +++ b/crates/librqbit/src/http_api.rs @@ -181,10 +181,10 @@ impl ApiInternal { managed.output_folder ), AddTorrentResponse::ListOnly(ListOnlyResponse { - info_hash, - info, - only_files, - }) => ApiAddTorrentResponse { + info_hash, + info, + only_files, + }) => ApiAddTorrentResponse { id: None, details: make_torrent_details(&info_hash, &info, only_files.as_deref()), }, @@ -221,7 +221,7 @@ impl ApiInternal { Some(StatsResponse { average_piece_download_time: snapshot.average_piece_download_time(), snapshot, - all_time_download_speed: (downloaded_mb / elapsed.as_secs_f64()).into(), + all_time_download_speed: (downloaded_mb * 8f64 / elapsed.as_secs_f64()).into(), download_speed: estimator.download_mbps().into(), time_remaining: estimator.time_remaining(), }) @@ -325,7 +325,7 @@ impl HttpApi { // clippy suggests something that doesn't work here. #[allow(clippy::redundant_closure)] - move || match inner.dht.as_ref() { + move || match inner.dht.as_ref() { Some(dht) => dht.with_routing_table(|r| json_response(r)), None => not_found_response("DHT is off".into()), } @@ -355,7 +355,7 @@ impl HttpApi { return Ok::<_, warp::Rejection>(make_response( 400, "invalid utf-8".into(), - )) + )); } }; let opts = AddTorrentOptions { diff --git a/crates/librqbit_core/src/speed_estimator.rs b/crates/librqbit_core/src/speed_estimator.rs index da94e21..f03491b 100644 --- a/crates/librqbit_core/src/speed_estimator.rs +++ b/crates/librqbit_core/src/speed_estimator.rs @@ -68,7 +68,7 @@ impl SpeedEstimator { let downloaded_bytes_diff = downloaded_bytes - first.downloaded_bytes; let elapsed = instant - first.instant; - let bps = downloaded_bytes_diff as f64 / elapsed.as_secs_f64(); + let bps = downloaded_bytes_diff as f64 * 8f64 / elapsed.as_secs_f64(); let time_remaining_millis_rounded: u64 = if downloaded_bytes_diff > 0 { let time_remaining_secs = remaining_bytes as f64 / bps; From 8b4027e3d6918c8ca5f235c0dcdd531e7f2778b2 Mon Sep 17 00:00:00 2001 From: pcmid Date: Mon, 25 Oct 2021 16:46:30 +0800 Subject: [PATCH 2/3] Format: cargo fmt --- crates/librqbit/src/http_api.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/librqbit/src/http_api.rs b/crates/librqbit/src/http_api.rs index dcff7a5..e815fbc 100644 --- a/crates/librqbit/src/http_api.rs +++ b/crates/librqbit/src/http_api.rs @@ -181,10 +181,10 @@ impl ApiInternal { managed.output_folder ), AddTorrentResponse::ListOnly(ListOnlyResponse { - info_hash, - info, - only_files, - }) => ApiAddTorrentResponse { + info_hash, + info, + only_files, + }) => ApiAddTorrentResponse { id: None, details: make_torrent_details(&info_hash, &info, only_files.as_deref()), }, @@ -325,7 +325,7 @@ impl HttpApi { // clippy suggests something that doesn't work here. #[allow(clippy::redundant_closure)] - move || match inner.dht.as_ref() { + move || match inner.dht.as_ref() { Some(dht) => dht.with_routing_table(|r| json_response(r)), None => not_found_response("DHT is off".into()), } From 18713515b96e9318508b0bd2c3b25707b7b0c19c Mon Sep 17 00:00:00 2001 From: pcmid Date: Mon, 25 Oct 2021 18:11:46 +0800 Subject: [PATCH 3/3] Update: change Mbps to MiB/s --- crates/librqbit/src/http_api.rs | 4 ++-- crates/librqbit_core/src/speed_estimator.rs | 2 +- crates/rqbit/src/main.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/librqbit/src/http_api.rs b/crates/librqbit/src/http_api.rs index e815fbc..ab20d0b 100644 --- a/crates/librqbit/src/http_api.rs +++ b/crates/librqbit/src/http_api.rs @@ -52,7 +52,7 @@ impl Speed { fn new(mbps: f64) -> Self { Self { mbps, - human_readable: format!("{:.2}Mbps", mbps), + human_readable: format!("{:.2} MiB/s", mbps), } } } @@ -221,7 +221,7 @@ impl ApiInternal { Some(StatsResponse { average_piece_download_time: snapshot.average_piece_download_time(), snapshot, - all_time_download_speed: (downloaded_mb * 8f64 / elapsed.as_secs_f64()).into(), + all_time_download_speed: (downloaded_mb / elapsed.as_secs_f64()).into(), download_speed: estimator.download_mbps().into(), time_remaining: estimator.time_remaining(), }) diff --git a/crates/librqbit_core/src/speed_estimator.rs b/crates/librqbit_core/src/speed_estimator.rs index f03491b..da94e21 100644 --- a/crates/librqbit_core/src/speed_estimator.rs +++ b/crates/librqbit_core/src/speed_estimator.rs @@ -68,7 +68,7 @@ impl SpeedEstimator { let downloaded_bytes_diff = downloaded_bytes - first.downloaded_bytes; let elapsed = instant - first.instant; - let bps = downloaded_bytes_diff as f64 * 8f64 / elapsed.as_secs_f64(); + let bps = downloaded_bytes_diff as f64 / elapsed.as_secs_f64(); let time_remaining_millis_rounded: u64 = if downloaded_bytes_diff > 0 { let time_remaining_secs = remaining_bytes as f64 / bps; diff --git a/crates/rqbit/src/main.rs b/crates/rqbit/src/main.rs index ac5e6cd..55bb930 100644 --- a/crates/rqbit/src/main.rs +++ b/crates/rqbit/src/main.rs @@ -216,7 +216,7 @@ async fn async_main(opts: Opts, spawner: BlockingSpawner) -> anyhow::Result<()> (progress as f64 / total as f64) * 100f64 }; info!( - "[{}]: {:.2}% ({:.2}), down speed {:.2} Mbps, fetched {}, remaining {:.2} of {:.2}, uploaded {:.2}, peers: {{live: {}, connecting: {}, queued: {}, seen: {}}}", + "[{}]: {:.2}% ({:.2}), down speed {:.2} MiB/s, fetched {}, remaining {:.2} of {:.2}, uploaded {:.2}, peers: {{live: {}, connecting: {}, queued: {}, seen: {}}}", idx, downloaded_pct, SF::new(progress),