use std::num::NonZeroU64;
use serde::Deserialize;
use serde::Serialize;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Authentication {
Authenticated,
LocallyAddressed,
Unauthenticated,
}
impl Authentication {
pub const fn permits(self, event: MeasurementEvent) -> bool {
match self {
Self::Authenticated => true,
Self::LocallyAddressed => matches!(event, MeasurementEvent::FailedToSend),
Self::Unauthenticated => false,
}
}
pub const fn establishes_peer(self) -> bool {
matches!(self, Self::Authenticated)
}
pub const fn refreshes_peer_observation(self) -> bool {
matches!(self, Self::Authenticated)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum MeasurementEvent {
Connected,
Disconnected,
Sent {
useful_bytes: u64,
},
FailedToSend,
Received {
useful_bytes: u64,
},
FailedToReceive,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MeasurementBatch {
event: MeasurementEvent,
occurrences: NonZeroU64,
}
impl MeasurementBatch {
pub const fn new(event: MeasurementEvent, occurrences: NonZeroU64) -> Self {
Self { event, occurrences }
}
pub const fn single(event: MeasurementEvent) -> Self {
Self::new(event, NonZeroU64::MIN)
}
pub const fn event(self) -> MeasurementEvent {
self.event
}
pub const fn occurrences(self) -> NonZeroU64 {
self.occurrences
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Metric {
BytesSent,
BytesReceived,
Connected,
Disconnected,
Sent,
FailedToSend,
Received,
FailedToReceive,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ApplyOutcome {
Applied,
IgnoredUnattributable,
IgnoredUnknownPeer,
}