use rttp::PulseFrameHeader;
use crossbeam::atomic::AtomicCell; use std::time::Instant;
pub const QUARANTINE_THRESHOLD: f32 = 0.95;
pub struct AnomalyManifold {
pub audit_vector: AtomicCell<u128>,
}
impl AnomalyManifold {
pub fn new() -> Self {
Self {
audit_vector: AtomicCell::new(0),
}
}
pub fn record_pathogen_event(&self, score: f64) {
let ts = Instant::now().elapsed().as_nanos() as u64;
let packed = ((score.to_bits() as u128) << 64) | (ts as u128);
self.audit_vector.store(packed);
}
}
pub fn classify_intent_stream(header: &PulseFrameHeader) -> (bool, f32) {
let mut score: f32 = 0.0001;
let local_now = Instant::now().elapsed().as_nanos() as u32;
let drift = (local_now as i64 - header.timestamp_ns as i64).abs();
if drift > 500_000 { score += 0.45;
}
if header.priority == 255 && (header.flags & 0b1000 == 0) {
score += 0.85;
}
let is_pathogen = score >= QUARANTINE_THRESHOLD;
if is_pathogen {
#[cfg(debug_assertions)]
log_anomaly(&format!(
"🚨 PATHOGEN CLASSIFIED | Score: {:.4} | Action: QUARANTINE",
score
));
}
(is_pathogen, score)
}
fn log_anomaly(msg: &str) {
eprintln!("\x1b[1;31m[RPKI-ANOMALY]\x1b[0m 👁️ {}", msg);
}