openmoat_proxy/audit.rs
1//! One record per connection decision.
2//!
3//! As with `moat guard`, the record is part of the decision: a connection that
4//! cannot be recorded is not made. The CLI records into the moat audit log;
5//! this crate stays free of storage.
6
7use openmoat_core::Decision;
8
9/// One connection decision.
10#[derive(Debug, Clone, Copy)]
11pub struct Connection<'a> {
12 /// Request method (`CONNECT`, `GET`, …); `None` when the head was unreadable.
13 pub method: Option<&'a str>,
14 /// Destination host and port; `None` when the head was unreadable.
15 pub destination: Option<(&'a str, u16)>,
16 /// The verdict and the rules behind it.
17 pub decision: &'a Decision,
18 /// Time from accepting the connection to this decision, in microseconds.
19 pub latency_us: u64,
20}
21
22/// Where connection decisions go. An error refuses the connection.
23pub trait Recorder: Send + Sync {
24 /// Record one decision.
25 fn record(&self, connection: &Connection<'_>) -> Result<(), RecordError>;
26}
27
28/// A decision could not be recorded.
29#[derive(Debug, thiserror::Error)]
30#[error("audit log unavailable: {0}")]
31pub struct RecordError(pub String);