use ace_sim::clock::{Duration, Instant};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum P2State {
Waiting,
Extended,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PendingRequest {
pub sid: u8,
pub sent_at: Instant,
pub deadline: Instant,
pub p2_state: P2State,
}
impl PendingRequest {
pub fn new(sid: u8, sent_at: Instant, p2_timeout: Duration) -> Self {
Self {
sid,
sent_at,
deadline: sent_at + p2_timeout,
p2_state: P2State::Waiting,
}
}
pub fn is_expired(&self, now: Instant) -> bool {
now > self.deadline
}
pub fn extend(&mut self, now: Instant, p2_extended_timeout: Duration) {
self.deadline = now + p2_extended_timeout;
self.p2_state = P2State::Extended;
}
}