1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-07-02 16:38:36 +00:00
This commit is contained in:
mikoto 2024-06-10 07:55:59 +02:00 committed by Matthias Ahouansou
parent 1f313c6807
commit 02cea0bb93
No known key found for this signature in database
7 changed files with 227 additions and 3 deletions

View file

@ -2,6 +2,7 @@ use std::{
collections::BTreeMap,
fmt,
net::{IpAddr, Ipv4Addr},
num::NonZeroU64,
};
use ruma::{OwnedServerName, RoomVersionId};
@ -82,6 +83,8 @@ pub struct Config {
pub turn_secret: String,
#[serde(default = "default_turn_ttl")]
pub turn_ttl: u64,
#[serde(default = "default_rate_limit")]
pub rate_limiting: BTreeMap<Restriction, Limitation>,
pub emergency_password: Option<String>,
@ -101,6 +104,27 @@ pub struct WellKnownConfig {
pub server: Option<OwnedServerName>,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(rename_all = "lowercase")]
pub enum Restriction {
Registration,
Login,
#[default]
#[serde(rename = "")]
CatchAll,
}
#[derive(Clone, Copy, Debug, Deserialize)]
pub struct Limitation {
#[serde(default = "default_non_zero")]
pub per_minute: NonZeroU64,
#[serde(default = "default_non_zero")]
pub burst_capacity: NonZeroU64,
#[serde(default = "default_non_zero")]
pub weight: NonZeroU64,
}
const DEPRECATED_KEYS: &[&str] = &["cache_capacity"];
impl Config {
@ -308,6 +332,21 @@ fn default_openid_token_ttl() -> u64 {
60 * 60
}
fn default_non_zero() -> NonZeroU64 {
NonZeroU64::new(1).unwrap()
}
pub fn default_rate_limit() -> BTreeMap<Restriction, Limitation> {
BTreeMap::from_iter([(
Restriction::default(),
Limitation {
per_minute: default_non_zero(),
burst_capacity: default_non_zero(),
weight: default_non_zero(),
},
)])
}
// I know, it's a great name
pub fn default_default_room_version() -> RoomVersionId {
RoomVersionId::V10