use liminal::channel::Recipient;
use std::num::NonZeroU32;
use std::sync::Arc;
use std::time::Instant;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct TapFilter {
pub subject: String,
}
impl TapFilter {
#[must_use]
pub fn matches(&self, subject: &str) -> bool {
self.subject.strip_suffix('*').map_or_else(
|| self.subject.is_empty() || self.subject == subject,
|prefix| subject.starts_with(prefix),
)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PayloadGrant {
_sealed: (),
}
impl PayloadGrant {
#[cfg(test)]
#[must_use]
pub(crate) const fn server_issued() -> Self {
Self { _sealed: () }
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TapOutcome {
Delivered,
Answered,
Unanswered,
NoSubscriber,
NoneAccepted,
Unresolved,
Refused,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TapSource {
Connection(u64),
Server,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TapIdent {
Message(u64),
Call {
connection: u64,
operation: u64,
},
Observation(u64),
}
#[derive(Clone, Copy, Debug)]
pub struct PublishFact<'a> {
pub subject: &'a str,
pub payload: &'a [u8],
pub outcome: TapOutcome,
pub message_id: Option<u64>,
pub source: TapSource,
pub reply_to: Option<&'a str>,
pub recorded: Option<Recorded<'a>>,
}
#[derive(Clone, Copy, Debug)]
pub struct Recorded<'a> {
pub recipients: &'a [Recipient],
pub received_at: Instant,
pub appended_at: Option<Instant>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Reached {
pub station: Arc<str>,
pub queued_at: Instant,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Hop {
pub node: Arc<str>,
pub at_ms: u64,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TapMessage {
pub ident: TapIdent,
pub subject: String,
pub size: u64,
pub outcome: TapOutcome,
pub seen_at: Instant,
pub source: TapSource,
pub station: Option<Arc<str>>,
pub to_stations: Option<Arc<[Reached]>>,
pub hops: Vec<Hop>,
pub reply_to: Option<String>,
pub held: bool,
pub payload: Option<Vec<u8>>,
pub call: Option<CallDetails>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TapBatch {
pub seq: u64,
pub sampled: NonZeroU32,
pub dropped: u64,
pub messages: Vec<TapMessage>,
}
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
pub struct CallDetails {
#[serde(skip_serializing_if = "Option::is_none")]
pub latency_ms: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub refusal: Option<String>,
}
#[derive(Clone, Copy, Debug)]
pub struct CallFact<'a> {
pub subject: &'a str,
pub size: u64,
pub connection: u64,
pub operation: Option<u64>,
pub station: Option<&'a Arc<str>>,
pub served_by: Option<&'a Arc<str>>,
pub received_at: Instant,
pub forwarded_at: Instant,
pub finished_at: Instant,
pub outcome: TapOutcome,
pub refusal: Option<&'a str>,
}