mirror of
https://github.com/chatmail/relay.git
synced 2026-08-10 18:40:51 +00:00
feat: Configurable rate limiter max burst size (#28)
Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
This commit is contained in:
committed by
GitHub
parent
9a8e4fe65c
commit
23231d462c
@@ -17,7 +17,10 @@ pub struct Config {
|
||||
pub postfix_reinject_port_incoming: u16,
|
||||
#[serde(default = "Config::default_max_message_size")]
|
||||
pub max_message_size: usize,
|
||||
#[serde(default = "Config::default_max_user_send_per_minute")]
|
||||
pub max_user_send_per_minute: NonZeroU32,
|
||||
#[serde(default = "Config::default_max_user_send_burst_size")]
|
||||
pub max_user_send_burst_size: NonZeroU32,
|
||||
#[serde(default, deserialize_with = "deserialize_sequence")]
|
||||
pub passthrough_senders: Vec<String>,
|
||||
#[serde(default, deserialize_with = "deserialize_sequence")]
|
||||
@@ -94,4 +97,10 @@ impl Config {
|
||||
const fn default_max_message_size() -> usize {
|
||||
31457280
|
||||
}
|
||||
const fn default_max_user_send_per_minute() -> NonZeroU32 {
|
||||
NonZeroU32::new(60).expect("60 != 0")
|
||||
}
|
||||
const fn default_max_user_send_burst_size() -> NonZeroU32 {
|
||||
NonZeroU32::new(10).expect("10 != 0")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ pub struct OutgoingBeforeQueueHandler {
|
||||
|
||||
impl OutgoingBeforeQueueHandler {
|
||||
pub fn new(config: Config) -> Self {
|
||||
let quota = Quota::per_minute(config.max_user_send_per_minute);
|
||||
let quota = Quota::per_minute(config.max_user_send_per_minute)
|
||||
.allow_burst(config.max_user_send_burst_size);
|
||||
Self {
|
||||
config: Arc::new(config),
|
||||
send_rate_limiter: RateLimiter::keyed(quota),
|
||||
|
||||
Reference in New Issue
Block a user