diff --git a/Cargo.lock b/Cargo.lock index 2dc33bc..a989c25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1344,7 +1344,7 @@ dependencies = [ [[package]] name = "jocalsend" -version = "1.6.18033988" +version = "1.6.180339887" dependencies = [ "axum", "axum-server", diff --git a/Cargo.toml b/Cargo.toml index 1998cf7..bd4f71b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,9 @@ [package] name = "jocalsend" # 1.61803398874989484 -#-----------^ -version = "1.6.18033988" +#------------^ +version = "1.6.180339887" edition = "2024" -rust-version = "1.89" authors = ["Joe Ardent "] keywords = ["p2p", "localsend", "tui", "linux"] description = "A TUI for LocalSend" diff --git a/VERSION b/VERSION index ae28b93..2fce4ea 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.618033988 +1.6180339887 diff --git a/src/transfer.rs b/src/transfer.rs index c600894..8cd2e0f 100644 --- a/src/transfer.rs +++ b/src/transfer.rs @@ -1,4 +1,9 @@ -use std::{collections::BTreeMap, net::SocketAddr, path::PathBuf, time::Duration}; +use std::{ + collections::BTreeMap, + net::SocketAddr, + path::PathBuf, + time::{Duration, Instant}, +}; use axum::{ Json, @@ -152,10 +157,11 @@ impl JocalService { .map(|(_, peer)| peer.alias.as_str()) .unwrap_or("unknown peer") ); + let num_bytes = bytes.len(); let resp = do_send_bytes(sessions, client, &session_id, content_id, token, bytes).await; match resp { - Ok(_) => { + Ok(dur) => { send_tx( JocalEvent::SendSuccess { content: content_id.to_owned(), @@ -163,6 +169,11 @@ impl JocalService { }, &tx, ); + log::info!( + "transferred {num_bytes} bytes in {} seconds ({})", + dur.as_secs_f32(), + format_bytes_per_second(num_bytes as f32 / dur.as_secs_f32()) + ); } Err(e) => { send_tx( @@ -307,6 +318,8 @@ pub async fn handle_receive_upload( // Create file path let file_path = service.config.download_dir.join(&file_metadata.file_name); + let num_bytes = body.len(); + // Write file if let Err(e) = tokio::fs::write(&file_path, body).await { log::warn!("could not save content to {file_path:?}, got {e}"); @@ -314,7 +327,7 @@ pub async fn handle_receive_upload( } log::info!( - "saved content from {} to {file_path:?}", + "wrote {num_bytes} from {} to {file_path:?}", session.sender.alias ); if let Ok(id) = Julid::from_str(session_id) { @@ -371,7 +384,7 @@ async fn do_send_bytes( content_id: &str, token: &str, body: Bytes, -) -> Result<()> { +) -> Result { let session = sessions .read() .await @@ -394,13 +407,15 @@ async fn do_send_bytes( .body(body); debug!("Uploading bytes: {request:?}"); + let now = Instant::now(); let response = request.send().await?; + let dur = Instant::now() - now; if response.status() != 200 { log::warn!("non-200 remote response: {response:?}"); Err(LocalSendError::UploadFailed) } else { - Ok(()) + Ok(dur) } } @@ -464,3 +479,14 @@ async fn do_prepare_upload( Ok(response) } + +fn format_bytes_per_second(bps: f32) -> String { + if bps >= 1024.0f32.powi(2) { + return format!("{} MB/s", bps / 1024.0f32.powi(2)); + } + if bps >= 1024.0 { + return format!("{} KB/s", bps / 1024.0); + } + + format!("{bps} B/s") +}