use crate::client::http::MOST_IN_BATCH;
use crate::live::BadSubscription;
use crate::utils::json::BadJson;
pub const MAX_CONNECTIONS: usize = 255;
pub const MAX_SUBSCRIPTIONS_PER_CONNECTION: usize = 500;
pub const MAX_SUBSCRIPTIONS: usize = 5_000;
pub const MAX_ACCOUNTS: usize = 5_000;
pub const MAX_MESSAGES_PER_MINUTE: usize = 200;
pub const MAX_INFLIGHT_MESSAGES: usize = 50;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Limits {
pub subscriptions: usize,
pub accounts: usize,
pub transactions: usize,
}
impl Limits {
pub const VENUE: Limits = Limits {
subscriptions: MAX_SUBSCRIPTIONS_PER_CONNECTION,
accounts: MAX_ACCOUNTS,
transactions: MAX_INFLIGHT_MESSAGES,
};
}
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 a connection 500")]
Subscriptions { limit: usize },
#[error("{limit} accounts is the most this session follows; the venue allows an IP 5000")]
Accounts { limit: usize },
#[error("{limit} transactions are already waiting for an answer")]
Transactions { limit: usize },
#[error("`{0}` needs the account's auth token, and the session has none")]
NoToken(String),
#[error("the socket is not open, and a transaction is never held to send later")]
Closed,
#[error("the read-only socket takes no transactions")]
ReadOnly,
#[error("a batch carries 1 to {MOST_IN_BATCH} transactions, not {0}")]
Batch(usize),
#[error("`tx_info` is not JSON: {0}")]
Unwritable(BadJson),
#[error(transparent)]
Bad(#[from] BadSubscription),
}
#[cfg(test)]
#[path = "tests/limits.rs"]
mod tests;