use anyhow::Result;
use async_trait::async_trait;
use bytes::Bytes;
use super::Hijacker;
use crate::resources::kv::KvStore;
pub struct L4PlusHijacker<'a> {
pub kv: &'a mut KvStore,
pub payloads: &'a ahash::AHashMap<String, Bytes>,
}
#[async_trait]
impl<'a> Hijacker for L4PlusHijacker<'a> {
fn can_handle(&self, key: &str) -> bool {
matches!(key, "tls.clienthello" | "quic.initial")
}
async fn resolve(&mut self, key: &str) -> Result<String> {
if let Some(cached) = self.kv.get(key) {
return Ok(cached.clone());
}
if let Some(raw) = self.payloads.get(key) {
let hex_encoded = hex::encode(raw);
self.kv.insert(key.to_owned(), hex_encoded.clone());
return Ok(hex_encoded);
}
anyhow::bail!("Raw data for key '{key}' not found in L4+ context")
}
}