9c8fa9340c
apple / swift (push) Failing after 40s
audit / cargo-audit (push) Failing after 1m12s
windows-msix / package (push) Successful in 1m37s
windows / build (push) Successful in 1m14s
android / android (push) Successful in 4m48s
ci / web (push) Successful in 27s
ci / rust (push) Successful in 4m21s
ci / docs-site (push) Successful in 31s
ci / bench (push) Successful in 4m39s
decky / build-publish (push) Successful in 11s
docker / build-push (--build-arg FEDORA_VERSION=44, ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora44-rpm) (push) Successful in 5s
docker / build-push (., web/Dockerfile, punktfunk-web) (push) Successful in 4s
docker / build-push (ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora-rpm) (push) Successful in 4s
docker / build-push (ci, ci/rust-ci.Dockerfile, punktfunk-rust-ci) (push) Successful in 4s
docker / build-push (docs-site, docs-site/Dockerfile, punktfunk-docs) (push) Successful in 19s
deb / build-publish (push) Successful in 6m3s
flatpak / build-publish (push) Successful in 4m13s
rpm / build-publish (bazzite, punktfunk-fedora-rpm) (push) Successful in 8m15s
rpm / build-publish (fedora-44, punktfunk-fedora44-rpm) (push) Successful in 8m16s
docker / deploy-docs (push) Successful in 18s
Two bodies of work in one commit (the rename moved files the fixes also touched). Naming/structure cleanup (pre-launch): - Host modules m3.rs->punktfunk1.rs, m0.rs->spike.rs; CLI m3-host->punktfunk1-host, m0->spike; bare `punktfunk-host` now prints help. Types M3Options/M3Source-> Punktfunk1Options/Punktfunk1Source. - Clients consolidated out of crates/ into clients/: punktfunk-client-rs-> clients/probe (crate punktfunk-probe), client-linux->clients/linux, client-windows->clients/windows, punktfunk-android->clients/android/native (crate punktfunk-client-android; kept [lib] name=punktfunk_android so the JNI contract is unchanged). crates/ now holds only core + host. - Milestone codes M0-M4 purged from code/CLI/CLAUDE.md/README/docs/docs-site, kept only in docs/implementation-plan.md. docs/m2-plan.md-> docs/gamestream-host-plan.md. CI/gradle/flatpak paths updated. Client loss-recovery (video froze and never recovered after a brief drop): - Export punktfunk_connection_frames_dropped through the C ABI (the core already tracked it for the client keyframe-recovery loop; it was never reachable from the ABI clients). Regenerated punktfunk_core.h. - Apple (StreamPump + Stage2Pipeline) and Android (decode.rs) now poll frames_dropped and request a keyframe when it climbs -- the same loss-driven recovery Linux/Windows already had. Under infinite GOP the decoder silently conceals reference-missing frames, so the decode-error trigger rarely fires. Apple rumble robustness (worked then went spotty -- DualSense + Xbox): - Add CHHapticEngine stopped/reset handlers (rebuild on app background / audio interruption / server reset) and drop the permanent `broken` latch on a transient drive failure; latch only when the controller truly has no haptics. - Surface swallowed SDL set_rumble errors on Linux/Windows + diagnostic logging. Verified: cargo build/clippy/fmt --workspace, C-ABI harness, header drift. Not runnable on this box (verify in CI): Gitea workflows, gradle/Android, flatpak, Swift/decky. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
186 lines
6.1 KiB
Rust
186 lines
6.1 KiB
Rust
//! Core acceptance: round-trip access units through the full host→client path
|
|
//! (packetize → FEC → loopback with simulated loss → recover → reassemble) and assert
|
|
//! byte-exact recovery, for both FEC schemes, with and without encryption. Plus
|
|
//! property tests over the FEC layer's loss patterns.
|
|
|
|
use proptest::prelude::*;
|
|
use punktfunk_core::config::{Config, FecConfig, FecScheme, ProtocolPhase, Role};
|
|
use punktfunk_core::fec::coder_for;
|
|
use punktfunk_core::input::{InputEvent, InputKind};
|
|
use punktfunk_core::session::Session;
|
|
use punktfunk_core::transport::loopback_pair;
|
|
|
|
fn config(role: Role, scheme: FecScheme, encrypt: bool, drop_period: u32) -> Config {
|
|
Config {
|
|
role,
|
|
phase: match scheme {
|
|
FecScheme::Gf8 => ProtocolPhase::P1GameStream,
|
|
FecScheme::Gf16 => ProtocolPhase::P2Punktfunk,
|
|
},
|
|
fec: FecConfig {
|
|
scheme,
|
|
fec_percent: 25,
|
|
max_data_per_block: 32,
|
|
},
|
|
shard_payload: 1024,
|
|
max_frame_bytes: 8 * 1024 * 1024,
|
|
encrypt,
|
|
key: [7u8; 16],
|
|
salt: [1, 2, 3, 4],
|
|
loopback_drop_period: drop_period,
|
|
}
|
|
}
|
|
|
|
/// Drive `frames` access units host→client over a lossy loopback and assert each one
|
|
/// comes back byte-identical. Returns the client's final stats.
|
|
fn run_stream(
|
|
scheme: FecScheme,
|
|
encrypt: bool,
|
|
drop_period: u32,
|
|
frames: &[Vec<u8>],
|
|
) -> punktfunk_core::Stats {
|
|
let (host_tp, client_tp) = loopback_pair(drop_period, 0);
|
|
let mut host = Session::new(
|
|
config(Role::Host, scheme, encrypt, drop_period),
|
|
Box::new(host_tp),
|
|
)
|
|
.unwrap();
|
|
let mut client = Session::new(
|
|
config(Role::Client, scheme, encrypt, drop_period),
|
|
Box::new(client_tp),
|
|
)
|
|
.unwrap();
|
|
|
|
for (i, frame) in frames.iter().enumerate() {
|
|
host.submit_frame(frame, i as u64 * 1_000_000, 0).unwrap();
|
|
let got = client
|
|
.poll_frame()
|
|
.expect("frame should recover despite loss");
|
|
assert_eq!(&got.data, frame, "frame {i} mismatched after recovery");
|
|
assert_eq!(got.frame_index, i as u32);
|
|
assert_eq!(got.pts_ns, i as u64 * 1_000_000);
|
|
}
|
|
client.stats()
|
|
}
|
|
|
|
fn sample_frames() -> Vec<Vec<u8>> {
|
|
(0..5usize)
|
|
.map(|f| {
|
|
let len = 1 + f * 40_000; // 1, 40k, 80k, 120k, 160k → single- and multi-block
|
|
(0..len)
|
|
.map(|b| (b.wrapping_mul(31).wrapping_add(f * 7)) as u8)
|
|
.collect()
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
#[test]
|
|
fn gf8_stream_recovers_under_loss() {
|
|
let frames = sample_frames();
|
|
// drop_period 8 deletes the 1st of every 8 packets → real data-shard loss.
|
|
let stats = run_stream(FecScheme::Gf8, false, 8, &frames);
|
|
assert_eq!(stats.frames_completed, frames.len() as u64);
|
|
assert!(
|
|
stats.fec_recovered_shards > 0,
|
|
"loss should have forced FEC recovery"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn gf16_stream_recovers_under_loss() {
|
|
let frames = sample_frames();
|
|
let stats = run_stream(FecScheme::Gf16, false, 8, &frames);
|
|
assert_eq!(stats.frames_completed, frames.len() as u64);
|
|
assert!(stats.fec_recovered_shards > 0);
|
|
}
|
|
|
|
#[test]
|
|
fn encrypted_stream_recovers_under_loss() {
|
|
let frames = sample_frames();
|
|
let stats = run_stream(FecScheme::Gf8, true, 8, &frames);
|
|
assert_eq!(stats.frames_completed, frames.len() as u64);
|
|
}
|
|
|
|
#[test]
|
|
fn lossless_stream_is_exact() {
|
|
let frames = sample_frames();
|
|
let stats = run_stream(FecScheme::Gf16, false, 0, &frames);
|
|
assert_eq!(stats.frames_completed, frames.len() as u64);
|
|
assert_eq!(
|
|
stats.fec_recovered_shards, 0,
|
|
"no loss → nothing to recover"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn input_round_trips_client_to_host() {
|
|
let (host_tp, client_tp) = loopback_pair(0, 0);
|
|
let mut host = Session::new(
|
|
config(Role::Host, FecScheme::Gf8, false, 0),
|
|
Box::new(host_tp),
|
|
)
|
|
.unwrap();
|
|
let mut client = Session::new(
|
|
config(Role::Client, FecScheme::Gf8, false, 0),
|
|
Box::new(client_tp),
|
|
)
|
|
.unwrap();
|
|
|
|
let sent = InputEvent {
|
|
kind: InputKind::MouseMove,
|
|
_pad: [0; 3],
|
|
code: 0,
|
|
x: -7,
|
|
y: 13,
|
|
flags: 0,
|
|
};
|
|
client.send_input(&sent).unwrap();
|
|
let got = host
|
|
.poll_input()
|
|
.unwrap()
|
|
.expect("host should receive the input event");
|
|
assert_eq!(got, sent);
|
|
}
|
|
|
|
// ---- property tests over the FEC layer --------------------------------------
|
|
|
|
proptest! {
|
|
/// For random shard counts and an erasure set within the recovery budget, every
|
|
/// original shard is reconstructed byte-identically — for both backends.
|
|
#[test]
|
|
fn fec_recovers_any_loss_within_budget(
|
|
k in 1usize..40,
|
|
extra in 0usize..16, // recovery beyond the bare minimum
|
|
shard_half in 1usize..64, // shard_len = 2*shard_half (even)
|
|
seed in any::<u64>(),
|
|
) {
|
|
let m = (extra + 1).min(40);
|
|
let shard_len = shard_half * 2;
|
|
for coder in [coder_for(FecScheme::Gf8), coder_for(FecScheme::Gf16)] {
|
|
// Gf8 ceiling: data + recovery <= 255.
|
|
if matches!(coder.scheme(), FecScheme::Gf8) && k + m > 255 { continue; }
|
|
|
|
let data: Vec<Vec<u8>> = (0..k)
|
|
.map(|i| (0..shard_len).map(|b| (i ^ b).wrapping_add(seed as usize) as u8).collect())
|
|
.collect();
|
|
let recovery = coder.encode(&data, m).unwrap();
|
|
|
|
let mut received: Vec<Option<Vec<u8>>> =
|
|
data.iter().cloned().map(Some).chain(recovery.into_iter().map(Some)).collect();
|
|
|
|
// Erase up to `m` shards chosen by a cheap PRNG over the seed.
|
|
let total = k + m;
|
|
let lose = (seed as usize % (m + 1)).min(m);
|
|
let mut s = seed | 1;
|
|
for _ in 0..lose {
|
|
s = s.wrapping_mul(6364136223846793005).wrapping_add(1);
|
|
let idx = (s >> 33) as usize % total;
|
|
received[idx] = None;
|
|
}
|
|
|
|
let restored = coder.reconstruct(k, m, &mut received).unwrap();
|
|
prop_assert_eq!(restored, data);
|
|
}
|
|
}
|
|
}
|