diff --git a/clients/android/native/src/decode.rs b/clients/android/native/src/decode.rs index 523b29e5..ecfd52b9 100644 --- a/clients/android/native/src/decode.rs +++ b/clients/android/native/src/decode.rs @@ -298,7 +298,13 @@ fn run_sync( // and excluded, so ADPF sees this thread's real per-frame CPU cost, not the poll timeout. let work_t0 = Instant::now(); if let Some(frame) = pending.take() { - if feed(&codec, &client, &frame.data, frame.pts_ns / 1000, &mut oversized_dropped) { + if feed( + &codec, + &client, + &frame.data, + frame.pts_ns / 1000, + &mut oversized_dropped, + ) { fed += 1; if fed % 300 == 0 { log::info!("decode: fed={fed} rendered={rendered} discarded={discarded}"); @@ -562,8 +568,8 @@ unsafe extern "C" fn on_frame_rendered( } } } - let e2e_ns = displayed_ns + t.clock_offset.load(Ordering::Relaxed) as i128 - - pts_us as i128 * 1000; + let e2e_ns = + displayed_ns + t.clock_offset.load(Ordering::Relaxed) as i128 - pts_us as i128 * 1000; let e2e_us = (e2e_ns > 0 && e2e_ns < 10_000_000_000).then_some((e2e_ns / 1000) as u64); let display_us = decoded_ns.map(|d| ((displayed_ns - d).max(0) / 1000) as u64); t.stats.note_displayed(e2e_us, display_us); @@ -857,14 +863,7 @@ fn run_async( std::thread::Builder::new() .name("pf-decode-feed".into()) .spawn(move || { - feeder_loop( - client, - stats, - in_flight, - clock_offset, - shutdown, - ev_tx, - ); + feeder_loop(client, stats, in_flight, clock_offset, shutdown, ev_tx); }) .ok() }; @@ -1357,7 +1356,11 @@ fn feed( // both valid for `n` bytes; `MaybeUninit` is layout-identical to `u8`, so // the cast write initializes exactly `dst[..n]`. unsafe { - std::ptr::copy_nonoverlapping(au.as_ptr(), dst.as_mut_ptr().cast::(), n); + std::ptr::copy_nonoverlapping( + au.as_ptr(), + dst.as_mut_ptr().cast::(), + n, + ); } n } diff --git a/clients/probe/src/main.rs b/clients/probe/src/main.rs index 2a3ddfac..42a10a89 100644 --- a/clients/probe/src/main.rs +++ b/clients/probe/src/main.rs @@ -548,9 +548,9 @@ async fn session(args: Args) -> Result<()> { // and require a sane, consistent estimate: both batches measure the same physical skew, so // they must agree to within RTT-scale error (the handshake's own uncertainty is ≈ RTT/2). if args.clock_resync { - let first = first_skew - .as_ref() - .ok_or_else(|| anyhow!("clock-resync: host never answered the connect-time handshake"))?; + let first = first_skew.as_ref().ok_or_else(|| { + anyhow!("clock-resync: host never answered the connect-time handshake") + })?; let second = punktfunk_core::quic::clock_sync(&mut send, &mut recv) .await .ok_or_else(|| anyhow!("clock-resync: host did not answer the re-probe"))?; @@ -573,7 +573,10 @@ async fn session(args: Args) -> Result<()> { bound_ns / 1000 )); } - println!("clock-resync OK: offsets {} / {} ns", first.offset_ns, second.offset_ns); + println!( + "clock-resync OK: offsets {} / {} ns", + first.offset_ns, second.offset_ns + ); } // Packet-level receive counters mirrored from `session.stats()` by the data-plane loop. The diff --git a/crates/punktfunk-core/src/quic/clock.rs b/crates/punktfunk-core/src/quic/clock.rs index 47bcbee4..1a22b7f1 100644 --- a/crates/punktfunk-core/src/quic/clock.rs +++ b/crates/punktfunk-core/src/quic/clock.rs @@ -127,7 +127,8 @@ impl ClockResync { if self.pending_t1 != Some(echo.t1_ns) { return ResyncStep::Idle; // stale (abandoned batch) or unsolicited } - self.samples.push((echo.t1_ns, echo.t2_ns, echo.t3_ns, now_ns)); + self.samples + .push((echo.t1_ns, echo.t2_ns, echo.t3_ns, now_ns)); if self.samples.len() < Self::ROUNDS { self.pending_t1 = Some(now_ns); return ResyncStep::Probe(ClockProbe { t1_ns: now_ns }); diff --git a/crates/punktfunk-core/src/quic/endpoint.rs b/crates/punktfunk-core/src/quic/endpoint.rs index 49077e77..652e3a0e 100644 --- a/crates/punktfunk-core/src/quic/endpoint.rs +++ b/crates/punktfunk-core/src/quic/endpoint.rs @@ -188,9 +188,7 @@ pub fn client_pinned_with_identity( use rustls::pki_types::pem::PemObject; let cert = rustls::pki_types::CertificateDer::from_pem_slice(cert_pem.as_bytes()) - .map_err(|e| { - anyhow_result::Error::msg(format!("client cert pem: {e}")) - })?; + .map_err(|e| anyhow_result::Error::msg(format!("client cert pem: {e}")))?; let key = rustls::pki_types::PrivateKeyDer::from_pem_slice(key_pem.as_bytes()) .map_err(|e| anyhow_result::Error::msg(format!("client key pem: {e}")))?; builder @@ -258,8 +256,7 @@ impl rustls::server::danger::ClientCertVerifier for AcceptAnyClientCert { _end_entity: &rustls::pki_types::CertificateDer<'_>, _intermediates: &[rustls::pki_types::CertificateDer<'_>], _now: rustls::pki_types::UnixTime, - ) -> std::result::Result - { + ) -> std::result::Result { Ok(rustls::server::danger::ClientCertVerified::assertion()) } @@ -268,8 +265,7 @@ impl rustls::server::danger::ClientCertVerifier for AcceptAnyClientCert { message: &[u8], cert: &rustls::pki_types::CertificateDer<'_>, dss: &rustls::DigitallySignedStruct, - ) -> std::result::Result - { + ) -> std::result::Result { rustls::crypto::verify_tls12_signature( message, cert, @@ -283,8 +279,7 @@ impl rustls::server::danger::ClientCertVerifier for AcceptAnyClientCert { message: &[u8], cert: &rustls::pki_types::CertificateDer<'_>, dss: &rustls::DigitallySignedStruct, - ) -> std::result::Result - { + ) -> std::result::Result { rustls::crypto::verify_tls13_signature( message, cert, @@ -314,8 +309,7 @@ impl rustls::client::danger::ServerCertVerifier for PinVerify { _server_name: &rustls::pki_types::ServerName<'_>, _ocsp: &[u8], _now: rustls::pki_types::UnixTime, - ) -> std::result::Result - { + ) -> std::result::Result { let fp = cert_fingerprint(end_entity.as_ref()); *self.observed.lock().unwrap() = Some(fp); if let Some(expected) = self.pin { @@ -337,8 +331,7 @@ impl rustls::client::danger::ServerCertVerifier for PinVerify { message: &[u8], cert: &rustls::pki_types::CertificateDer<'_>, dss: &rustls::DigitallySignedStruct, - ) -> std::result::Result - { + ) -> std::result::Result { rustls::crypto::verify_tls12_signature( message, cert, @@ -352,8 +345,7 @@ impl rustls::client::danger::ServerCertVerifier for PinVerify { message: &[u8], cert: &rustls::pki_types::CertificateDer<'_>, dss: &rustls::DigitallySignedStruct, - ) -> std::result::Result - { + ) -> std::result::Result { rustls::crypto::verify_tls13_signature( message, cert, diff --git a/crates/punktfunk-core/src/quic/msgs.rs b/crates/punktfunk-core/src/quic/msgs.rs index f5821b37..904c4a29 100644 --- a/crates/punktfunk-core/src/quic/msgs.rs +++ b/crates/punktfunk-core/src/quic/msgs.rs @@ -2,11 +2,11 @@ //! (`CTL_MAGIC` + type byte), including the pairing-ceremony messages. Wire codecs only //! — no transport state. +use super::{CTL_MAGIC, MAGIC}; use crate::config::{ CompositorPref, Config, FecConfig, FecScheme, GamepadPref, Mode, ProtocolPhase, Role, }; use crate::error::{PunktfunkError, Result}; -use super::{CTL_MAGIC, MAGIC}; /// `client → host`: open the session, requesting a display mode (the host creates its /// virtual output at exactly this size/refresh — native resolution end to end). diff --git a/crates/punktfunk-core/src/quic/tests.rs b/crates/punktfunk-core/src/quic/tests.rs index ddad5a34..8a9f82f9 100644 --- a/crates/punktfunk-core/src/quic/tests.rs +++ b/crates/punktfunk-core/src/quic/tests.rs @@ -42,7 +42,7 @@ fn welcome_roundtrip() { assert_eq!(w.session_config(Role::Host).max_frame_bytes, 64 << 20); let old_host = Welcome { bitrate_kbps: 0, - ..w.clone() + ..w }; assert_eq!( old_host.session_config(Role::Client).max_frame_bytes, @@ -56,7 +56,7 @@ fn welcome_roundtrip() { height: 1440, refresh_hz: 60, }, - ..w.clone() + ..w }; let derived = fat.session_config(Role::Client).max_frame_bytes; assert_eq!(derived, 4 * 1_500_000 * 125 / 60); @@ -573,10 +573,10 @@ fn loss_report_roundtrip() { // Disjoint from the other control messages (type byte + length). assert!(LossReport::decode(&RequestKeyframe.encode()).is_err()); assert!(RequestKeyframe::decode(&LossReport { loss_ppm: 0 }.encode()).is_err()); - assert!(LossReport::decode( - &[LossReport { loss_ppm: 0 }.encode().as_slice(), &[0]].concat() - ) - .is_err()); + assert!( + LossReport::decode(&[LossReport { loss_ppm: 0 }.encode().as_slice(), &[0]].concat()) + .is_err() + ); } #[test] @@ -676,8 +676,7 @@ fn clock_offset_picks_min_rtt_and_recovers_offset() { let n2 = (n1 as i64 + 200_000 + OFF) as u64; let n3 = n2 + 50_000; let n4 = (n3 as i64 - OFF + 5_000_000) as u64; // 5 ms return → big RTT - let (offset, rtt) = - clock_offset_ns(&[(n1, n2, n3, n4), (t1, t2, t3, t4)]).expect("non-empty"); + let (offset, rtt) = clock_offset_ns(&[(n1, n2, n3, n4), (t1, t2, t3, t4)]).expect("non-empty"); // The min-RTT sample recovers the offset exactly; its RTT is 2x200us, and the noisy // (asymmetric, 5 ms return) sample is ignored by the min-RTT selection. assert_eq!(offset, OFF); @@ -701,11 +700,17 @@ fn clock_resync_collects_rounds_and_ignores_stale_echoes() { let mut rs = ClockResync::new(); // An unsolicited echo before any batch is ignored. - assert_eq!(rs.on_echo(&echo_for(42, 100_000), 500_000), ResyncStep::Idle); + assert_eq!( + rs.on_echo(&echo_for(42, 100_000), 500_000), + ResyncStep::Idle + ); let mut probe = rs.begin(1_000_000); // A stale echo (wrong t1: the abandoned pre-begin probe) is ignored mid-batch. - assert_eq!(rs.on_echo(&echo_for(42, 100_000), 500_000), ResyncStep::Idle); + assert_eq!( + rs.on_echo(&echo_for(42, 100_000), 500_000), + ResyncStep::Idle + ); for round in 0..ClockResync::ROUNDS { // Round 3 is congested (5 ms one-way) — it must lose the min-RTT selection. let one_way = if round == 3 { 5_000_000 } else { 100_000 }; diff --git a/crates/punktfunk-core/src/session.rs b/crates/punktfunk-core/src/session.rs index 85c6b711..89065dec 100644 --- a/crates/punktfunk-core/src/session.rs +++ b/crates/punktfunk-core/src/session.rs @@ -594,11 +594,11 @@ mod wire_equivalence_tests { // shard_payload 64 × max_data_per_block 8: >512 bytes spans FEC blocks. let frames: Vec> = vec![ - pattern(3000), // multi-block + partial tail shard - pattern(1024), // exact multiple (2 full blocks) - pattern(100), // single block, partial tail - Vec::new(), // empty frame → 1 zeroed shard - pattern(64), // exactly one full shard + pattern(3000), // multi-block + partial tail shard + pattern(1024), // exact multiple (2 full blocks) + pattern(100), // single block, partial tail + Vec::new(), // empty frame → 1 zeroed shard + pattern(64), // exactly one full shard ]; for (i, frame) in frames.iter().enumerate() { let got = opt.seal_frame(frame, 1000 * i as u64, i as u32).unwrap(); diff --git a/crates/punktfunk-host/src/gamestream/audio.rs b/crates/punktfunk-host/src/gamestream/audio.rs index 2c80dbd3..d73436f8 100644 --- a/crates/punktfunk-host/src/gamestream/audio.rs +++ b/crates/punktfunk-host/src/gamestream/audio.rs @@ -271,8 +271,10 @@ fn run( .context("connect client audio endpoint")?; // Opt-in DSCP/QoS-tag this as the audio class (PUNKTFUNK_DSCP=1); the guard keeps the // Windows qWAVE flow alive for the whole stream (this function's scope IS the stream). - let _qos_flow = - punktfunk_core::transport::set_media_qos(&sock, punktfunk_core::transport::MediaClass::Audio); + let _qos_flow = punktfunk_core::transport::set_media_qos( + &sock, + punktfunk_core::transport::MediaClass::Audio, + ); tracing::info!(%client, "audio: client endpoint learned"); // Reuse the persistent capturer when its channel count still matches (drain stale diff --git a/crates/punktfunk-host/src/gamestream/stream.rs b/crates/punktfunk-host/src/gamestream/stream.rs index efa75654..90e60f12 100644 --- a/crates/punktfunk-host/src/gamestream/stream.rs +++ b/crates/punktfunk-host/src/gamestream/stream.rs @@ -114,8 +114,10 @@ fn run( .context("connect client video endpoint")?; // Opt-in DSCP/QoS-tag this as the video class (PUNKTFUNK_DSCP=1); the guard keeps the // Windows qWAVE flow alive for the whole stream (this function's scope IS the stream). - let _qos_flow = - punktfunk_core::transport::set_media_qos(&sock, punktfunk_core::transport::MediaClass::Video); + let _qos_flow = punktfunk_core::transport::set_media_qos( + &sock, + punktfunk_core::transport::MediaClass::Video, + ); tracing::info!(%client, "video: client endpoint learned"); // Short label for web-console stats captures: the client's peer IP. let client_label = client.ip().to_string();