Move federation config to separate config section

This renames:

allow_federation -> federation.enable
trusted_servers -> federation.trusted_servers
max_fetch_prev_events -> federation.max_fetch_prev_events
max_concurrent_requests -> federation.max_concurrent_requests
This commit is contained in:
Lambda 2024-06-26 06:45:23 +00:00 committed by Charles Hall
parent e0e7d8fd91
commit 5a6e4fac73
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
4 changed files with 29 additions and 25 deletions

View file

@ -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<String>,
#[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<String>,
#[serde(default = "default_trusted_servers")]
pub(crate) trusted_servers: Vec<OwnedServerName>,
#[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<OwnedServerName>,
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<OwnedServerName> {
vec![OwnedServerName::try_from("matrix.org").unwrap()]
}
fn default_tracing_filter() -> EnvFilterClone {
"info,ruma_state_res=warn"
.parse()

View file

@ -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))

View file

@ -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 {

View file

@ -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(),
)),
})
}