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>
165 lines
5.2 KiB
Rust
165 lines
5.2 KiB
Rust
//! Client identity, the known-hosts (pinned fingerprint) store, and app settings.
|
|
//!
|
|
//! The identity shares `~/.config/punktfunk/client-{cert,key}.pem` with `punktfunk-probe`
|
|
//! so a box pairs once whichever client it uses.
|
|
|
|
use anyhow::{anyhow, Context, Result};
|
|
use punktfunk_core::quic::endpoint;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::path::PathBuf;
|
|
|
|
pub fn config_dir() -> Result<PathBuf> {
|
|
let home = std::env::var("HOME").context("HOME unset")?;
|
|
Ok(PathBuf::from(home).join(".config/punktfunk"))
|
|
}
|
|
|
|
/// This client's persistent identity, generated on first use — presented on every connect
|
|
/// so hosts can recognize it once paired.
|
|
pub fn load_or_create_identity() -> Result<(String, String)> {
|
|
let dir = config_dir()?;
|
|
let (cp, kp) = (dir.join("client-cert.pem"), dir.join("client-key.pem"));
|
|
if let (Ok(c), Ok(k)) = (std::fs::read_to_string(&cp), std::fs::read_to_string(&kp)) {
|
|
return Ok((c, k));
|
|
}
|
|
let (c, k) = endpoint::generate_identity().map_err(|e| anyhow!("generate identity: {e}"))?;
|
|
std::fs::create_dir_all(&dir)?;
|
|
std::fs::write(&cp, &c)?;
|
|
std::fs::write(&kp, &k)?;
|
|
tracing::info!(cert = %cp.display(), "generated client identity");
|
|
Ok((c, k))
|
|
}
|
|
|
|
pub fn hex(fp: &[u8; 32]) -> String {
|
|
fp.iter().map(|b| format!("{b:02x}")).collect()
|
|
}
|
|
|
|
pub fn parse_hex32(s: &str) -> Option<[u8; 32]> {
|
|
if s.len() != 64 {
|
|
return None;
|
|
}
|
|
let mut out = [0u8; 32];
|
|
for (i, b) in out.iter_mut().enumerate() {
|
|
*b = u8::from_str_radix(&s[2 * i..2 * i + 2], 16).ok()?;
|
|
}
|
|
Some(out)
|
|
}
|
|
|
|
/// One trusted host: its pinned certificate fingerprint plus how we got there (TOFU or a
|
|
/// PIN ceremony) and where we last reached it.
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct KnownHost {
|
|
pub name: String,
|
|
pub addr: String,
|
|
pub port: u16,
|
|
/// SHA-256 of the host certificate, lowercase hex — the pin for every later connect.
|
|
pub fp_hex: String,
|
|
/// True if trust came from the SPAKE2 PIN ceremony (vs. trust-on-first-use).
|
|
pub paired: bool,
|
|
}
|
|
|
|
#[derive(Default, Serialize, Deserialize)]
|
|
pub struct KnownHosts {
|
|
pub hosts: Vec<KnownHost>,
|
|
}
|
|
|
|
impl KnownHosts {
|
|
fn path() -> Result<PathBuf> {
|
|
Ok(config_dir()?.join("client-known-hosts.json"))
|
|
}
|
|
|
|
pub fn load() -> KnownHosts {
|
|
Self::path()
|
|
.and_then(|p| Ok(std::fs::read_to_string(p)?))
|
|
.ok()
|
|
.and_then(|s| serde_json::from_str(&s).ok())
|
|
.unwrap_or_default()
|
|
}
|
|
|
|
pub fn save(&self) -> Result<()> {
|
|
let p = Self::path()?;
|
|
std::fs::create_dir_all(p.parent().unwrap())?;
|
|
std::fs::write(&p, serde_json::to_string_pretty(self)?)?;
|
|
Ok(())
|
|
}
|
|
|
|
pub fn find_by_fp(&self, fp_hex: &str) -> Option<&KnownHost> {
|
|
self.hosts.iter().find(|h| h.fp_hex == fp_hex)
|
|
}
|
|
|
|
pub fn find_by_addr(&self, addr: &str, port: u16) -> Option<&KnownHost> {
|
|
self.hosts.iter().find(|h| h.addr == addr && h.port == port)
|
|
}
|
|
|
|
/// Insert or refresh an entry, keyed by fingerprint. `paired` only ever upgrades
|
|
/// (a later TOFU connect must not demote a PIN-paired host).
|
|
pub fn upsert(&mut self, entry: KnownHost) {
|
|
if let Some(h) = self.hosts.iter_mut().find(|h| h.fp_hex == entry.fp_hex) {
|
|
h.name = entry.name;
|
|
h.addr = entry.addr;
|
|
h.port = entry.port;
|
|
h.paired |= entry.paired;
|
|
} else {
|
|
self.hosts.push(entry);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// App settings, persisted as JSON. Stringly-typed gamepad/compositor prefs so the file
|
|
/// stays readable; parsed with `*Pref::from_name` at connect time.
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
#[serde(default)]
|
|
pub struct Settings {
|
|
/// Stream mode; `0` = the native size/refresh of the monitor the window is on,
|
|
/// resolved at connect time.
|
|
pub width: u32,
|
|
pub height: u32,
|
|
pub refresh_hz: u32,
|
|
/// Requested encoder bitrate (kbps); 0 = host default.
|
|
pub bitrate_kbps: u32,
|
|
pub gamepad: String,
|
|
/// Which host compositor backend to request (advisory; the host falls back to
|
|
/// auto-detect when unavailable).
|
|
pub compositor: String,
|
|
/// Grab compositor shortcuts (Alt+Tab, Super…) while input is captured.
|
|
pub inhibit_shortcuts: bool,
|
|
/// Stream the default microphone to the host's virtual mic source.
|
|
pub mic_enabled: bool,
|
|
}
|
|
|
|
impl Default for Settings {
|
|
fn default() -> Self {
|
|
Settings {
|
|
width: 0,
|
|
height: 0,
|
|
refresh_hz: 0,
|
|
bitrate_kbps: 0,
|
|
gamepad: "auto".into(),
|
|
compositor: "auto".into(),
|
|
inhibit_shortcuts: true,
|
|
mic_enabled: false,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Settings {
|
|
fn path() -> Result<PathBuf> {
|
|
Ok(config_dir()?.join("client-gtk-settings.json"))
|
|
}
|
|
|
|
pub fn load() -> Settings {
|
|
Self::path()
|
|
.and_then(|p| Ok(std::fs::read_to_string(p)?))
|
|
.ok()
|
|
.and_then(|s| serde_json::from_str(&s).ok())
|
|
.unwrap_or_default()
|
|
}
|
|
|
|
pub fn save(&self) {
|
|
let Ok(p) = Self::path() else { return };
|
|
let _ = std::fs::create_dir_all(p.parent().unwrap());
|
|
if let Ok(s) = serde_json::to_string_pretty(self) {
|
|
let _ = std::fs::write(&p, s);
|
|
}
|
|
}
|
|
}
|