Replace address-only trust and pushed peer state with installation identities, SPKI-pinned QUIC, candidate-only discovery, and bounded responder-owned protocol-8 pulls. The runtime now owns each network generation and all admitted work through shutdown. Add exact bundled content identities, reproducible manifest publishing, capability-confined downloads, streaming BLAKE3 verification, quarantine and retry, and crash-recoverable download and install transactions. Ship generated fixture catalogs and fail closed when production manifests are absent. The Tauri backend exposes durable sharing policy, redacted identity state, and attempt-keyed transfer snapshots. Frontend consumption follows in the next commit. Repository-wide test certificates and protocol-7 paths are removed. BREAKING CHANGE: peers must use protocol 8 and exact catalog content artifacts; protocol-7 frames and shared-certificate identities are no longer accepted. Test Plan: - `just test` -- passed on the completed stack (708 workspace tests) - `just clippy` -- passed on the completed stack - `just build` -- passed with fixture catalogs on the completed stack - `just catalog-check-production` -- failed closed because the external production manifest corpus is absent - `git diff --cached --check` -- passed
127 lines
3.8 KiB
Rust
127 lines
3.8 KiB
Rust
//! Runtime fail-closed gate for local recovery state.
|
|
|
|
use std::{
|
|
collections::HashSet,
|
|
path::{Path, PathBuf},
|
|
sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard},
|
|
};
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub(crate) struct RecoveryQuarantine {
|
|
inner: Arc<RwLock<RecoveryState>>,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
struct RecoveryState {
|
|
root: PathBuf,
|
|
status: RecoveryStatus,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
enum RecoveryStatus {
|
|
Recovering,
|
|
Settled { failed_ids: HashSet<String> },
|
|
}
|
|
|
|
impl RecoveryQuarantine {
|
|
pub(crate) fn recovering(root: PathBuf) -> Self {
|
|
Self {
|
|
inner: Arc::new(RwLock::new(RecoveryState {
|
|
root,
|
|
status: RecoveryStatus::Recovering,
|
|
})),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn begin(&self, root: PathBuf) {
|
|
let mut state = self.write();
|
|
state.root = root;
|
|
state.status = RecoveryStatus::Recovering;
|
|
}
|
|
|
|
/// Settles the current recovery epoch. A result from a superseded root is
|
|
/// ignored and leaves the newer root fail-closed.
|
|
pub(crate) fn settle(&self, root: &Path, failed_ids: HashSet<String>) -> bool {
|
|
let mut state = self.write();
|
|
if state.root != root {
|
|
return false;
|
|
}
|
|
state.status = RecoveryStatus::Settled { failed_ids };
|
|
true
|
|
}
|
|
|
|
pub(crate) fn is_blocked(&self, current_root: &Path, game_id: &str) -> bool {
|
|
let state = self.read();
|
|
if state.root != current_root {
|
|
return true;
|
|
}
|
|
match &state.status {
|
|
RecoveryStatus::Recovering => true,
|
|
RecoveryStatus::Settled { failed_ids } => failed_ids.contains(game_id),
|
|
}
|
|
}
|
|
|
|
/// Returns the failed IDs for a settled snapshot of this exact root.
|
|
/// Recovering or mismatched roots deliberately return no projection: the
|
|
/// runtime gate still blocks every game until the authoritative load
|
|
/// publishes and settles.
|
|
pub(crate) fn failed_ids(&self, current_root: &Path) -> HashSet<String> {
|
|
let state = self.read();
|
|
if state.root != current_root {
|
|
return HashSet::new();
|
|
}
|
|
match &state.status {
|
|
RecoveryStatus::Recovering => HashSet::new(),
|
|
RecoveryStatus::Settled { failed_ids } => failed_ids.clone(),
|
|
}
|
|
}
|
|
|
|
fn read(&self) -> RwLockReadGuard<'_, RecoveryState> {
|
|
self.inner
|
|
.read()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
|
}
|
|
|
|
fn write(&self) -> RwLockWriteGuard<'_, RecoveryState> {
|
|
self.inner
|
|
.write()
|
|
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn recovering_and_root_mismatch_block_every_game() {
|
|
let gate = RecoveryQuarantine::recovering(PathBuf::from("/games"));
|
|
|
|
assert!(gate.is_blocked(Path::new("/games"), "healthy"));
|
|
assert!(gate.is_blocked(Path::new("/other"), "healthy"));
|
|
}
|
|
|
|
#[test]
|
|
fn settled_gate_blocks_only_failed_ids_for_exact_root() {
|
|
let gate = RecoveryQuarantine::recovering(PathBuf::from("/games"));
|
|
assert!(gate.settle(Path::new("/games"), HashSet::from(["broken".to_string()])));
|
|
|
|
assert!(gate.is_blocked(Path::new("/games"), "broken"));
|
|
assert!(!gate.is_blocked(Path::new("/games"), "healthy"));
|
|
assert!(gate.is_blocked(Path::new("/other"), "healthy"));
|
|
assert_eq!(
|
|
gate.failed_ids(Path::new("/games")),
|
|
HashSet::from(["broken".to_string()])
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn stale_root_cannot_settle_new_recovery_epoch() {
|
|
let gate = RecoveryQuarantine::recovering(PathBuf::from("/old"));
|
|
gate.begin(PathBuf::from("/new"));
|
|
|
|
assert!(!gate.settle(Path::new("/old"), HashSet::new()));
|
|
assert!(gate.is_blocked(Path::new("/new"), "game"));
|
|
}
|
|
}
|