use std::time::Duration;
use shared_ids::ClientId;
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, PartialOrd, Ord)]
pub enum TimeoutType {
Batch,
Client,
ViewChange,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Timeout {
pub timeout_type: TimeoutType,
pub duration: Duration,
pub stop_class: StopClass,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TimeoutAny {
pub timeout_type: TimeoutType,
pub duration: Duration,
}
impl TimeoutAny {
pub(super) fn client(duration: Duration) -> Self {
Self {
timeout_type: TimeoutType::Client,
duration,
}
}
}
#[derive(Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
#[repr(transparent)]
pub struct StopClass(pub(crate) u64);
impl Timeout {
pub fn batch(duration: Duration) -> Self {
Self {
timeout_type: TimeoutType::Batch,
duration,
stop_class: StopClass::default(),
}
}
pub fn client(client_id: ClientId, duration: Duration) -> Self {
Self {
timeout_type: TimeoutType::Client,
duration,
stop_class: StopClass(client_id.as_u64()),
}
}
pub fn view_change(duration: Duration) -> Self {
Self {
timeout_type: TimeoutType::ViewChange,
duration,
stop_class: StopClass::default(),
}
}
}