Files
synapse/rust/src/config/mod.rs
T
Erik JohnstonandClaude Opus 5 9b5697d378 Move per-homeserver Rust state into a RustRuntime object on the HomeServer (#20011)
Previously the tokio runtime was stashed in a hidden attribute on the
reactor object, installed lazily by whichever Rust code first needed it,
and started via `callWhenRunning`.

Instead, we create a `RustRuntime` (accessible via
`HomeServer.get_rust_runtime()`) that holds any per-reactor Rust state,
such as the tokio runtime. It is constructed lazily on use. Rust
consumers (`HttpClient`, `VersionsHandler`, the Python DB pool wrapper)
now receive the runtime or reactor handle explicitly, and the
`reactor.run()` / manual-startup workarounds in tests are no longer
needed.

We also add helper wrappers in Rust for `Reactor` and `HomeServer` that
exposes the needed functionality.

The aim is to allow us to have a Rust-side clock (mainly to get the
current time), that respects the unit test per-reactor time management.

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 18:48:37 +01:00

80 lines
2.4 KiB
Rust

/*
* This file is licensed under the Affero General Public License (AGPL) version 3.
*
* Copyright (C) 2026 Element Creations Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* See the GNU Affero General Public License for more details:
* <https://www.gnu.org/licenses/agpl-3.0.html>.
*
*/
use std::collections::BTreeSet;
use pyo3::prelude::*;
pub mod types;
/// A Rust-side view of Synapse's Python `HomeServerConfig`.
///
/// This only mirrors the subset of config that the Rust handlers need, rather
/// than the whole thing. Thanks to `#[derive(FromPyObject)]`, each field is
/// pulled directly off the corresponding attribute of the Python `config`
/// object, so you can populate it in one shot with:
/// ```ignore
/// let config: SynapseHomeServerConfig = homeserver.getattr("config")?.extract()?;
/// ```
#[derive(FromPyObject, Clone)]
pub struct SynapseHomeServerConfig {
pub room: RoomConfig,
pub auth: AuthConfig,
pub server: ServerConfig,
pub experimental: ExperimentalConfig,
}
#[derive(FromPyObject, Clone)]
pub struct RoomConfig {
pub encryption_enabled_by_default_for_room_presets: BTreeSet<types::RoomCreationPreset>,
}
#[derive(FromPyObject, Clone)]
pub struct AuthConfig {
pub login_via_existing_enabled: bool,
}
#[derive(FromPyObject, Clone)]
pub struct ServerConfig {
pub msc4140_enabled: bool,
pub public_baseurl: String,
pub include_profile_updates_in_sync: bool,
}
#[derive(FromPyObject, Clone)]
pub struct ExperimentalConfig {
pub msc3026_enabled: bool,
pub msc3773_enabled: bool,
pub msc2815_enabled: bool,
pub msc3881_enabled: bool,
pub msc3874_enabled: bool,
pub msc3912_enabled: bool,
pub msc3391_enabled: bool,
pub msc4069_profile_inhibit_propagation: bool,
pub msc4028_push_encrypted_events: bool,
pub msc4108_enabled: bool,
pub msc4108_delegation_endpoint: Option<String>,
pub msc3575_enabled: bool,
pub msc4133_enabled: bool,
pub msc4155_enabled: bool,
pub msc4306_enabled: bool,
pub msc4169_enabled: bool,
pub msc4354_enabled: bool,
pub msc4222_enabled: bool,
pub msc4491_enabled: bool,
pub msc4143_enabled: bool,
pub msc4446_enabled: bool,
pub msc4502_enabled: bool,
}