diff options
-rw-r--r-- | Cargo.lock | 70 | ||||
-rw-r--r-- | client-native-lib/src/instance.rs | 18 | ||||
-rw-r--r-- | client-native-rift/Cargo.toml | 3 | ||||
-rw-r--r-- | client-native-rift/src/main.rs | 21 |
4 files changed, 110 insertions, 2 deletions
@@ -443,6 +443,20 @@ dependencies = [ ] [[package]] +name = "console" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc 0.2.132", + "terminal_size", + "unicode-width", + "winapi", +] + +[[package]] name = "const-oid" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -753,6 +767,12 @@ dependencies = [ ] [[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] name = "env_logger" version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1086,6 +1106,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] +name = "humansize" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a866837516f34ad34fb221f3ee01fd0db75f2c2f6abeda2047dc6963fb04ad9a" +dependencies = [ + "libm", +] + +[[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1142,6 +1171,17 @@ dependencies = [ ] [[package]] +name = "indicatif" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfddc9561e8baf264e0e45e197fd7696320026eb10a8180340debc27b18f535b" +dependencies = [ + "console", + "number_prefix", + "unicode-width", +] + +[[package]] name = "inout" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1233,6 +1273,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] +name = "libm" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565" + +[[package]] name = "listenfd" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1410,6 +1456,12 @@ dependencies = [ ] [[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + +[[package]] name = "oid-registry" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1757,6 +1809,8 @@ dependencies = [ "clap", "client-native-lib", "env_logger", + "humansize", + "indicatif", "log", "tokio", ] @@ -2175,6 +2229,16 @@ dependencies = [ ] [[package]] +name = "terminal_size" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +dependencies = [ + "libc 0.2.132", + "winapi", +] + +[[package]] name = "textwrap" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2451,6 +2515,12 @@ dependencies = [ ] [[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] name = "unicode-xid" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/client-native-lib/src/instance.rs b/client-native-lib/src/instance.rs index cd720f1..162241d 100644 --- a/client-native-lib/src/instance.rs +++ b/client-native-lib/src/instance.rs @@ -44,6 +44,24 @@ impl Instance { }) } + pub async fn spawn_ping(self: &Arc<Self>) { + let blub = self.clone(); + tokio::spawn(async move { + loop { + blub.ping(); + } + }); + } + + pub async fn ping(&self) { + self.conn + .send + .write() + .await + .send(ServerboundPacket::Ping) + .await; + } + pub async fn my_id(&self) -> usize { self.my_id.read().await.expect("not initialized yet") } diff --git a/client-native-rift/Cargo.toml b/client-native-rift/Cargo.toml index 08a08bb..460467f 100644 --- a/client-native-rift/Cargo.toml +++ b/client-native-rift/Cargo.toml @@ -12,3 +12,6 @@ log = "0.4" tokio = { version = "1.21", features = ["full"] } bytes = "1.2.1" + +indicatif = "0.17.1" +humansize = "2.0.0" diff --git a/client-native-rift/src/main.rs b/client-native-rift/src/main.rs index 72c8396..a3fb4e4 100644 --- a/client-native-rift/src/main.rs +++ b/client-native-rift/src/main.rs @@ -14,8 +14,16 @@ use client_native_lib::{ webrtc::data_channel::RTCDataChannel, Config, DynFut, EventHandler, LocalResource, }; +use humansize::DECIMAL; use log::{error, info, warn}; -use std::{future::Future, pin::Pin, sync::Arc}; +use std::{ + future::Future, + pin::Pin, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, +}; use tokio::{ fs::File, io::{stdin, stdout, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}, @@ -64,6 +72,7 @@ async fn run() { ) .await; + inst.spawn_ping().await; inst.receive_loop().await; tokio::signal::ctrl_c().await.unwrap(); @@ -120,6 +129,7 @@ impl EventHandler for Handler { if resource.kind != "file" { return error!("we got a non-file resource for some reason…"); } + let mut pos = Arc::new(AtomicUsize::new(0)); let writer: Arc<RwLock<Option<Pin<Box<dyn AsyncWrite + Send + Sync>>>>> = Arc::new(RwLock::new(None)); { @@ -149,8 +159,15 @@ impl EventHandler for Handler { let writer = writer.clone(); dc.on_message(box move |mesg| { let writer = writer.clone(); + let pos = pos.clone(); Box::pin(async move { - info!("{:?} bytes of data", mesg.data.len()); + let pos = pos.fetch_add(mesg.data.len(), Ordering::Relaxed); + info!( + "{:?} bytes of data ({} of {})", + mesg.data.len(), + humansize::format_size(pos, DECIMAL), + humansize::format_size(resource.size.unwrap_or(0), DECIMAL), + ); writer .write() .await |