diff --git a/src/config.rs b/src/config.rs index 78308c7f..6fe3a43e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -32,6 +32,8 @@ pub(crate) struct Config { pub(crate) server_name: OwnedServerName, pub(crate) database: DatabaseConfig, + #[serde(default)] + pub(crate) federation: FederationConfig, #[serde(default = "default_cache_capacity_modifier")] pub(crate) cache_capacity_modifier: f64, @@ -41,18 +43,12 @@ pub(crate) struct Config { pub(crate) cleanup_second_interval: u32, #[serde(default = "default_max_request_size")] pub(crate) max_request_size: u32, - #[serde(default = "default_max_concurrent_requests")] - pub(crate) max_concurrent_requests: u16, - #[serde(default = "default_max_fetch_prev_events")] - pub(crate) max_fetch_prev_events: u16, #[serde(default = "false_fn")] pub(crate) allow_registration: bool, pub(crate) registration_token: Option, #[serde(default = "true_fn")] pub(crate) allow_encryption: bool, #[serde(default = "true_fn")] - pub(crate) allow_federation: bool, - #[serde(default = "true_fn")] pub(crate) allow_room_creation: bool, #[serde(default = "true_fn")] pub(crate) allow_unstable_room_versions: bool, @@ -61,8 +57,6 @@ pub(crate) struct Config { #[serde(default)] pub(crate) proxy: ProxyConfig, pub(crate) jwt_secret: Option, - #[serde(default = "default_trusted_servers")] - pub(crate) trusted_servers: Vec, #[serde(default)] pub(crate) observability: ObservabilityConfig, #[serde(default)] @@ -249,6 +243,28 @@ pub(crate) struct ObservabilityConfig { pub(crate) logs: LogConfig, } +#[derive(Debug, Deserialize)] +#[serde(default)] +pub(crate) struct FederationConfig { + pub(crate) enable: bool, + pub(crate) trusted_servers: Vec, + pub(crate) max_fetch_prev_events: u16, + pub(crate) max_concurrent_requests: u16, +} + +impl Default for FederationConfig { + fn default() -> Self { + Self { + enable: true, + trusted_servers: vec![ + OwnedServerName::try_from("matrix.org").unwrap() + ], + max_fetch_prev_events: 100, + max_concurrent_requests: 100, + } + } +} + fn false_fn() -> bool { false } @@ -300,18 +316,6 @@ fn default_max_request_size() -> u32 { 20 * 1024 * 1024 } -fn default_max_concurrent_requests() -> u16 { - 100 -} - -fn default_max_fetch_prev_events() -> u16 { - 100_u16 -} - -fn default_trusted_servers() -> Vec { - vec![OwnedServerName::try_from("matrix.org").unwrap()] -} - fn default_tracing_filter() -> EnvFilterClone { "info,ruma_state_res=warn" .parse() diff --git a/src/main.rs b/src/main.rs index f68264a9..385dc470 100644 --- a/src/main.rs +++ b/src/main.rs @@ -463,7 +463,7 @@ fn routes(config: &Config) -> Router { .route("/", get(it_works)) .fallback(not_found); - if config.allow_federation { + if config.federation.enable { router .ruma_route(s2s::get_server_version_route) .route("/_matrix/key/v2/server", get(s2s::get_server_keys_route)) diff --git a/src/service/globals.rs b/src/service/globals.rs index e92cb0b1..681ba44a 100644 --- a/src/service/globals.rs +++ b/src/service/globals.rs @@ -324,7 +324,7 @@ impl Service { } pub(crate) fn max_fetch_prev_events(&self) -> u16 { - self.config.max_fetch_prev_events + self.config.federation.max_fetch_prev_events } pub(crate) fn allow_registration(&self) -> bool { @@ -336,7 +336,7 @@ impl Service { } pub(crate) fn allow_federation(&self) -> bool { - self.config.allow_federation + self.config.federation.enable } pub(crate) fn allow_room_creation(&self) -> bool { @@ -352,7 +352,7 @@ impl Service { } pub(crate) fn trusted_servers(&self) -> &[OwnedServerName] { - &self.config.trusted_servers + &self.config.federation.trusted_servers } pub(crate) fn dns_resolver(&self) -> &TokioAsyncResolver { diff --git a/src/service/sending.rs b/src/service/sending.rs index 095f5801..32573cc3 100644 --- a/src/service/sending.rs +++ b/src/service/sending.rs @@ -159,7 +159,7 @@ impl Service { sender, receiver: Mutex::new(receiver), maximum_requests: Arc::new(Semaphore::new( - config.max_concurrent_requests.into(), + config.federation.max_concurrent_requests.into(), )), }) }