use crate::live::BadSubscription;
pub const MAX_CONNECTIONS: usize = 10;
pub const MAX_NEW_CONNECTIONS_PER_MINUTE: usize = 30;
pub const MAX_SUBSCRIPTIONS: usize = 1_000;
pub const MAX_USERS: usize = 10;
pub const MAX_MESSAGES_PER_MINUTE: usize = 2_000;
pub const MAX_INFLIGHT_POSTS: usize = 100;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Limits {
pub subscriptions: usize,
pub users: usize,
pub posts: usize,
}
impl Limits {
pub const VENUE: Limits = Limits { subscriptions: MAX_SUBSCRIPTIONS, users: MAX_USERS, posts: MAX_INFLIGHT_POSTS };
}
impl Default for Limits {
fn default() -> Self {
Limits::VENUE
}
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum Refused {
#[error("{limit} subscriptions is the most this session holds; the venue allows an IP 1000")]
Subscriptions { limit: usize },
#[error("{limit} users is the most this session follows; the venue allows an IP 10")]
Users { limit: usize },
#[error("{limit} posts are already waiting for an answer; the venue allows an IP 100")]
Posts { limit: usize },
#[error("the socket is not open, and a post is never held to send later")]
Closed,
#[error(transparent)]
Bad(#[from] BadSubscription),
}
#[cfg(test)]
#[path = "tests/limits.rs"]
mod tests;