use crate::{
event::{api::SocketAddress, IntoEvent, Timestamp},
inet,
};
#[non_exhaustive]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Outcome {
#[non_exhaustive]
Allow,
#[non_exhaustive]
Retry,
#[non_exhaustive]
Drop,
#[non_exhaustive]
Close,
}
impl Outcome {
pub fn allow() -> Self {
Self::Allow
}
pub fn retry() -> Self {
Self::Retry
}
pub fn drop() -> Self {
Self::Drop
}
pub fn close() -> Self {
Self::Close
}
}
#[non_exhaustive]
#[derive(Debug)]
pub struct ConnectionAttempt<'a> {
pub inflight_handshakes: usize,
pub connection_count: usize,
pub remote_address: SocketAddress<'a>,
pub timestamp: Timestamp,
}
impl<'a> ConnectionAttempt<'a> {
#[doc(hidden)]
pub fn new(
inflight_handshakes: usize,
connection_count: usize,
remote_address: &'a inet::SocketAddress,
timestamp: Timestamp,
) -> Self {
Self {
inflight_handshakes,
connection_count,
remote_address: remote_address.into_event(),
timestamp,
}
}
}
pub trait Limiter: 'static + Send {
fn on_connection_attempt(&mut self, info: &ConnectionAttempt) -> Outcome;
}