From 42d65a559d7314633a8b3118bc5462fc2662930b Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Mon, 15 May 2023 23:15:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E4=BC=A0=E9=80=92=E7=BB=99?= =?UTF-8?q?=E6=9D=BF=E5=AD=90=E7=9A=84=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E7=B4=A7=E5=87=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 38 +++++++++++++++++++++----------------- src/udp_server.rs | 1 - 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 89ad247..22889b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,25 +64,29 @@ async fn main() { let state = statistics_manager.get_state().await; - // stdout() - // .write_all( - // format!( - // "len: {},speed_upload: {}, speed_download: {}, update_direct_speed: {}, download_direct_speed: {}, update_proxy_speed: {}, download_proxy_speed: {}\n", - // state.connections, - // state.speed_upload, - // state.speed_download, - // state.direct_upload_speed, - // state.direct_download_speed, - // state.proxy_upload_speed, - // state.proxy_download_speed, - // ) - // .as_bytes(), - // ) - // .await - // .unwrap(); + stdout() + .write_all( + format!( + "len: {},speed_upload: {}, speed_download: {}, update_direct_speed: {}, download_direct_speed: {}, update_proxy_speed: {}, download_proxy_speed: {}\n", + state.connections, + state.speed_upload, + state.speed_download, + state.direct_upload_speed, + state.direct_download_speed, + state.proxy_upload_speed, + state.proxy_download_speed, + ) + .as_bytes(), + ) + .await + .unwrap(); let udp_server = udp_server::UdpServer::global().await; - let buf = serde_json::to_vec(&state).unwrap(); + let mut buf = [0; 32]; + buf[0..8].copy_from_slice(&state.direct_upload_speed.to_le_bytes()); + buf[8..16].copy_from_slice(&state.direct_download_speed.to_le_bytes()); + buf[16..24].copy_from_slice(&state.proxy_upload_speed.to_le_bytes()); + buf[24..32].copy_from_slice(&state.proxy_download_speed.to_le_bytes()); udp_server.publish(&buf).await; }) }; diff --git a/src/udp_server.rs b/src/udp_server.rs index 639af4c..07881ce 100644 --- a/src/udp_server.rs +++ b/src/udp_server.rs @@ -62,7 +62,6 @@ impl UdpServer { let socket = UdpSocket::bind((self.listen_addr, self.listen_port)).await?; loop { - info!("Waiting for data"); let (len, addr) = socket.recv_from(&mut buf).await?; info!("Received data({}) from {}", len, addr);