eliminate references to services.globals.config

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-01-24 07:02:56 +00:00
parent 7c6b8b132a
commit 5be07ebc0f
26 changed files with 116 additions and 114 deletions

View file

@ -170,7 +170,7 @@ pub(super) async fn get_remote_pdu_list(
server: Box<ServerName>, server: Box<ServerName>,
force: bool, force: bool,
) -> Result<RoomMessageEventContent> { ) -> Result<RoomMessageEventContent> {
if !self.services.globals.config.allow_federation { if !self.services.server.config.allow_federation {
return Ok(RoomMessageEventContent::text_plain( return Ok(RoomMessageEventContent::text_plain(
"Federation is disabled on this homeserver.", "Federation is disabled on this homeserver.",
)); ));
@ -235,7 +235,7 @@ pub(super) async fn get_remote_pdu(
event_id: Box<EventId>, event_id: Box<EventId>,
server: Box<ServerName>, server: Box<ServerName>,
) -> Result<RoomMessageEventContent> { ) -> Result<RoomMessageEventContent> {
if !self.services.globals.config.allow_federation { if !self.services.server.config.allow_federation {
return Ok(RoomMessageEventContent::text_plain( return Ok(RoomMessageEventContent::text_plain(
"Federation is disabled on this homeserver.", "Federation is disabled on this homeserver.",
)); ));
@ -419,7 +419,7 @@ pub(super) async fn change_log_level(
let handles = &["console"]; let handles = &["console"];
if reset { if reset {
let old_filter_layer = match EnvFilter::try_new(&self.services.globals.config.log) { let old_filter_layer = match EnvFilter::try_new(&self.services.server.config.log) {
| Ok(s) => s, | Ok(s) => s,
| Err(e) => { | Err(e) => {
return Ok(RoomMessageEventContent::text_plain(format!( return Ok(RoomMessageEventContent::text_plain(format!(
@ -438,7 +438,7 @@ pub(super) async fn change_log_level(
| Ok(()) => { | Ok(()) => {
return Ok(RoomMessageEventContent::text_plain(format!( return Ok(RoomMessageEventContent::text_plain(format!(
"Successfully changed log level back to config value {}", "Successfully changed log level back to config value {}",
self.services.globals.config.log self.services.server.config.log
))); )));
}, },
| Err(e) => { | Err(e) => {
@ -554,7 +554,7 @@ pub(super) async fn first_pdu_in_room(
.services .services
.rooms .rooms
.state_cache .state_cache
.server_in_room(&self.services.globals.config.server_name, &room_id) .server_in_room(&self.services.server.config.server_name, &room_id)
.await .await
{ {
return Ok(RoomMessageEventContent::text_plain( return Ok(RoomMessageEventContent::text_plain(
@ -583,7 +583,7 @@ pub(super) async fn latest_pdu_in_room(
.services .services
.rooms .rooms
.state_cache .state_cache
.server_in_room(&self.services.globals.config.server_name, &room_id) .server_in_room(&self.services.server.config.server_name, &room_id)
.await .await
{ {
return Ok(RoomMessageEventContent::text_plain( return Ok(RoomMessageEventContent::text_plain(
@ -613,7 +613,7 @@ pub(super) async fn force_set_room_state_from_server(
.services .services
.rooms .rooms
.state_cache .state_cache
.server_in_room(&self.services.globals.config.server_name, &room_id) .server_in_room(&self.services.server.config.server_name, &room_id)
.await .await
{ {
return Ok(RoomMessageEventContent::text_plain( return Ok(RoomMessageEventContent::text_plain(
@ -818,13 +818,13 @@ pub(super) async fn resolve_true_destination(
server_name: Box<ServerName>, server_name: Box<ServerName>,
no_cache: bool, no_cache: bool,
) -> Result<RoomMessageEventContent> { ) -> Result<RoomMessageEventContent> {
if !self.services.globals.config.allow_federation { if !self.services.server.config.allow_federation {
return Ok(RoomMessageEventContent::text_plain( return Ok(RoomMessageEventContent::text_plain(
"Federation is disabled on this homeserver.", "Federation is disabled on this homeserver.",
)); ));
} }
if server_name == self.services.globals.config.server_name { if server_name == self.services.server.config.server_name {
return Ok(RoomMessageEventContent::text_plain( return Ok(RoomMessageEventContent::text_plain(
"Not allowed to send federation requests to ourselves. Please use `get-pdu` for \ "Not allowed to send federation requests to ourselves. Please use `get-pdu` for \
fetching local PDUs.", fetching local PDUs.",

View file

@ -92,7 +92,7 @@ pub(super) async fn remote_user_in_rooms(
&self, &self,
user_id: Box<UserId>, user_id: Box<UserId>,
) -> Result<RoomMessageEventContent> { ) -> Result<RoomMessageEventContent> {
if user_id.server_name() == self.services.globals.config.server_name { if user_id.server_name() == self.services.server.config.server_name {
return Ok(RoomMessageEventContent::text_plain( return Ok(RoomMessageEventContent::text_plain(
"User belongs to our server, please use `list-joined-rooms` user admin command \ "User belongs to our server, please use `list-joined-rooms` user admin command \
instead.", instead.",

View file

@ -83,12 +83,12 @@ pub(super) async fn create_user(
// content is set to the user's display name with a space before it // content is set to the user's display name with a space before it
if !self if !self
.services .services
.globals .server
.config .config
.new_user_displayname_suffix .new_user_displayname_suffix
.is_empty() .is_empty()
{ {
write!(displayname, " {}", self.services.globals.config.new_user_displayname_suffix) write!(displayname, " {}", self.services.server.config.new_user_displayname_suffix)
.expect("should be able to write to string buffer"); .expect("should be able to write to string buffer");
} }
@ -114,8 +114,8 @@ pub(super) async fn create_user(
) )
.await?; .await?;
if !self.services.globals.config.auto_join_rooms.is_empty() { if !self.services.server.config.auto_join_rooms.is_empty() {
for room in &self.services.globals.config.auto_join_rooms { for room in &self.services.server.config.auto_join_rooms {
let Ok(room_id) = self.services.rooms.alias.resolve(room).await else { let Ok(room_id) = self.services.rooms.alias.resolve(room).await else {
error!(%user_id, "Failed to resolve room alias to room ID when attempting to auto join {room}, skipping"); error!(%user_id, "Failed to resolve room alias to room ID when attempting to auto join {room}, skipping");
continue; continue;

View file

@ -299,7 +299,7 @@ pub(crate) async fn register_route(
if !services.globals.new_user_displayname_suffix().is_empty() if !services.globals.new_user_displayname_suffix().is_empty()
&& body.appservice_info.is_none() && body.appservice_info.is_none()
{ {
write!(displayname, " {}", services.globals.config.new_user_displayname_suffix) write!(displayname, " {}", services.server.config.new_user_displayname_suffix)
.expect("should be able to write to string buffer"); .expect("should be able to write to string buffer");
} }
@ -365,7 +365,7 @@ pub(crate) async fn register_route(
\"{device_display_name}\"" \"{device_display_name}\""
); );
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_message(RoomMessageEventContent::notice_plain(format!( .send_message(RoomMessageEventContent::notice_plain(format!(
@ -378,7 +378,7 @@ pub(crate) async fn register_route(
} else { } else {
info!("New user \"{user_id}\" registered on this server."); info!("New user \"{user_id}\" registered on this server.");
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_message(RoomMessageEventContent::notice_plain(format!( .send_message(RoomMessageEventContent::notice_plain(format!(
@ -395,7 +395,7 @@ pub(crate) async fn register_route(
info!("New guest user \"{user_id}\" registered on this server."); info!("New guest user \"{user_id}\" registered on this server.");
if !device_display_name.is_empty() { if !device_display_name.is_empty() {
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_message(RoomMessageEventContent::notice_plain(format!( .send_message(RoomMessageEventContent::notice_plain(format!(
@ -407,7 +407,7 @@ pub(crate) async fn register_route(
} }
} else { } else {
#[allow(clippy::collapsible_else_if)] #[allow(clippy::collapsible_else_if)]
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_message(RoomMessageEventContent::notice_plain(format!( .send_message(RoomMessageEventContent::notice_plain(format!(
@ -438,10 +438,10 @@ pub(crate) async fn register_route(
} }
if body.appservice_info.is_none() if body.appservice_info.is_none()
&& !services.globals.config.auto_join_rooms.is_empty() && !services.server.config.auto_join_rooms.is_empty()
&& (services.globals.allow_guests_auto_join_rooms() || !is_guest) && (services.globals.allow_guests_auto_join_rooms() || !is_guest)
{ {
for room in &services.globals.config.auto_join_rooms { for room in &services.server.config.auto_join_rooms {
let Ok(room_id) = services.rooms.alias.resolve(room).await else { let Ok(room_id) = services.rooms.alias.resolve(room).await else {
error!( error!(
"Failed to resolve room alias to room ID when attempting to auto join \ "Failed to resolve room alias to room ID when attempting to auto join \
@ -570,7 +570,7 @@ pub(crate) async fn change_password_route(
info!("User {sender_user} changed their password."); info!("User {sender_user} changed their password.");
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_message(RoomMessageEventContent::notice_plain(format!( .send_message(RoomMessageEventContent::notice_plain(format!(
@ -673,7 +673,7 @@ pub(crate) async fn deactivate_route(
info!("User {sender_user} deactivated their account."); info!("User {sender_user} deactivated their account.");
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_message(RoomMessageEventContent::notice_plain(format!( .send_message(RoomMessageEventContent::notice_plain(format!(

View file

@ -152,7 +152,7 @@ pub(crate) async fn set_room_visibility_route(
match &body.visibility { match &body.visibility {
| room::Visibility::Public => { | room::Visibility::Public => {
if services.globals.config.lockdown_public_room_directory if services.server.config.lockdown_public_room_directory
&& !services.users.is_admin(sender_user).await && !services.users.is_admin(sender_user).await
&& body.appservice_info.is_none() && body.appservice_info.is_none()
{ {
@ -162,7 +162,7 @@ pub(crate) async fn set_room_visibility_route(
body.room_id body.room_id
); );
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_text(&format!( .send_text(&format!(
@ -181,7 +181,7 @@ pub(crate) async fn set_room_visibility_route(
services.rooms.directory.set_public(&body.room_id); services.rooms.directory.set_public(&body.room_id);
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_text(&format!( .send_text(&format!(

View file

@ -31,7 +31,7 @@ pub(crate) async fn get_media_config_route(
_body: Ruma<get_media_config::v1::Request>, _body: Ruma<get_media_config::v1::Request>,
) -> Result<get_media_config::v1::Response> { ) -> Result<get_media_config::v1::Response> {
Ok(get_media_config::v1::Response { Ok(get_media_config::v1::Response {
upload_size: ruma_from_usize(services.globals.config.max_request_size), upload_size: ruma_from_usize(services.server.config.max_request_size),
}) })
} }

View file

@ -27,7 +27,7 @@ pub(crate) async fn get_media_config_legacy_route(
_body: Ruma<get_media_config::v3::Request>, _body: Ruma<get_media_config::v3::Request>,
) -> Result<get_media_config::v3::Response> { ) -> Result<get_media_config::v3::Response> {
Ok(get_media_config::v3::Response { Ok(get_media_config::v3::Response {
upload_size: ruma_from_usize(services.globals.config.max_request_size), upload_size: ruma_from_usize(services.server.config.max_request_size),
}) })
} }

View file

@ -71,7 +71,7 @@ async fn banned_room_check(
if let Some(room_id) = room_id { if let Some(room_id) = room_id {
if services.rooms.metadata.is_banned(room_id).await if services.rooms.metadata.is_banned(room_id).await
|| services || services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(&room_id.server_name().unwrap().to_owned()) .contains(&room_id.server_name().unwrap().to_owned())
@ -81,12 +81,12 @@ async fn banned_room_check(
attempted to join a banned room or banned room server name: {room_id}" attempted to join a banned room or banned room server name: {room_id}"
); );
if services.globals.config.auto_deactivate_banned_room_attempts { if services.server.config.auto_deactivate_banned_room_attempts {
warn!( warn!(
"Automatically deactivating user {user_id} due to attempted banned room join" "Automatically deactivating user {user_id} due to attempted banned room join"
); );
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_message(RoomMessageEventContent::text_plain(format!( .send_message(RoomMessageEventContent::text_plain(format!(
@ -112,7 +112,7 @@ async fn banned_room_check(
} }
} else if let Some(server_name) = server_name { } else if let Some(server_name) = server_name {
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(&server_name.to_owned()) .contains(&server_name.to_owned())
@ -122,12 +122,12 @@ async fn banned_room_check(
name {server_name} that is globally forbidden. Rejecting.", name {server_name} that is globally forbidden. Rejecting.",
); );
if services.globals.config.auto_deactivate_banned_room_attempts { if services.server.config.auto_deactivate_banned_room_attempts {
warn!( warn!(
"Automatically deactivating user {user_id} due to attempted banned room join" "Automatically deactivating user {user_id} due to attempted banned room join"
); );
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_message(RoomMessageEventContent::text_plain(format!( .send_message(RoomMessageEventContent::text_plain(format!(

View file

@ -37,7 +37,7 @@ pub(crate) async fn create_openid_token_route(
Ok(account::request_openid_token::v3::Response { Ok(account::request_openid_token::v3::Response {
access_token, access_token,
token_type: TokenType::Bearer, token_type: TokenType::Bearer,
matrix_server_name: services.globals.config.server_name.clone(), matrix_server_name: services.server.config.server_name.clone(),
expires_in: Duration::from_secs(expires_in), expires_in: Duration::from_secs(expires_in),
}) })
} }

View file

@ -50,7 +50,7 @@ pub(crate) async fn report_room_route(
if !services if !services
.rooms .rooms
.state_cache .state_cache
.server_in_room(&services.globals.config.server_name, &body.room_id) .server_in_room(&services.server.config.server_name, &body.room_id)
.await .await
{ {
return Err!(Request(NotFound( return Err!(Request(NotFound(

View file

@ -71,7 +71,7 @@ pub(crate) async fn create_room_route(
let room_id: OwnedRoomId = if let Some(custom_room_id) = &body.room_id { let room_id: OwnedRoomId = if let Some(custom_room_id) = &body.room_id {
custom_room_id_check(&services, custom_room_id)? custom_room_id_check(&services, custom_room_id)?
} else { } else {
RoomId::new(&services.globals.config.server_name) RoomId::new(&services.server.config.server_name)
}; };
// check if room ID doesn't already exist instead of erroring on auth check // check if room ID doesn't already exist instead of erroring on auth check
@ -83,7 +83,7 @@ pub(crate) async fn create_room_route(
} }
if body.visibility == room::Visibility::Public if body.visibility == room::Visibility::Public
&& services.globals.config.lockdown_public_room_directory && services.server.config.lockdown_public_room_directory
&& !services.users.is_admin(sender_user).await && !services.users.is_admin(sender_user).await
&& body.appservice_info.is_none() && body.appservice_info.is_none()
{ {
@ -93,7 +93,7 @@ pub(crate) async fn create_room_route(
&room_id &room_id
); );
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_text(&format!( .send_text(&format!(
@ -450,7 +450,7 @@ pub(crate) async fn create_room_route(
if body.visibility == room::Visibility::Public { if body.visibility == room::Visibility::Public {
services.rooms.directory.set_public(&room_id); services.rooms.directory.set_public(&room_id);
if services.globals.config.admin_room_notices { if services.server.config.admin_room_notices {
services services
.admin .admin
.send_text(&format!( .send_text(&format!(

View file

@ -1,5 +1,5 @@
use axum::extract::State; use axum::extract::State;
use conduwuit::Err; use conduwuit::{utils::math::Tried, Err};
use ruma::api::client::typing::create_typing_event; use ruma::api::client::typing::create_typing_event;
use crate::{utils, Result, Ruma}; use crate::{utils, Result, Ruma};
@ -31,17 +31,15 @@ pub(crate) async fn create_typing_event_route(
let duration = utils::clamp( let duration = utils::clamp(
duration.as_millis().try_into().unwrap_or(u64::MAX), duration.as_millis().try_into().unwrap_or(u64::MAX),
services services
.globals .server
.config .config
.typing_client_timeout_min_s .typing_client_timeout_min_s
.checked_mul(1000) .try_mul(1000)?,
.unwrap(),
services services
.globals .server
.config .config
.typing_client_timeout_max_s .typing_client_timeout_max_s
.checked_mul(1000) .try_mul(1000)?,
.unwrap(),
); );
services services
.rooms .rooms

View file

@ -38,7 +38,7 @@ pub(crate) async fn turn_server_route(
let user = body.sender_user.unwrap_or_else(|| { let user = body.sender_user.unwrap_or_else(|| {
UserId::parse_with_server_name( UserId::parse_with_server_name(
utils::random_string(RANDOM_USER_ID_LENGTH).to_lowercase(), utils::random_string(RANDOM_USER_ID_LENGTH).to_lowercase(),
&services.globals.config.server_name, &services.server.config.server_name,
) )
.unwrap() .unwrap()
}); });

View file

@ -71,7 +71,7 @@ pub(super) async fn auth(
match metadata { match metadata {
| &get_public_rooms::v3::Request::METADATA => { | &get_public_rooms::v3::Request::METADATA => {
if !services if !services
.globals .server
.config .config
.allow_public_room_directory_without_auth .allow_public_room_directory_without_auth
{ {
@ -94,7 +94,7 @@ pub(super) async fn auth(
| &get_display_name::v3::Request::METADATA | &get_display_name::v3::Request::METADATA
| &get_avatar_url::v3::Request::METADATA | &get_avatar_url::v3::Request::METADATA
| &get_timezone_key::unstable::Request::METADATA => { | &get_timezone_key::unstable::Request::METADATA => {
if services.globals.config.require_auth_for_profile_requests { if services.server.config.require_auth_for_profile_requests {
match token { match token {
| Token::Appservice(_) | Token::User(_) => { | Token::Appservice(_) | Token::User(_) => {
// we should have validated the token above // we should have validated the token above
@ -127,7 +127,7 @@ pub(super) async fn auth(
}), }),
| (AuthScheme::AccessToken, Token::None) => match metadata { | (AuthScheme::AccessToken, Token::None) => match metadata {
| &get_turn_server_info::v3::Request::METADATA => { | &get_turn_server_info::v3::Request::METADATA => {
if services.globals.config.turn_allow_guests { if services.server.config.turn_allow_guests {
Ok(Auth { Ok(Auth {
origin: None, origin: None,
sender_user: None, sender_user: None,

View file

@ -32,7 +32,7 @@ pub(super) async fn from(
let query = serde_html_form::from_str(query) let query = serde_html_form::from_str(query)
.map_err(|e| err!(Request(Unknown("Failed to read query parameters: {e}"))))?; .map_err(|e| err!(Request(Unknown("Failed to read query parameters: {e}"))))?;
let max_body_size = services.globals.config.max_request_size; let max_body_size = services.server.config.max_request_size;
let body = axum::body::to_bytes(body, max_body_size) let body = axum::body::to_bytes(body, max_body_size)
.await .await

View file

@ -37,7 +37,7 @@ pub(crate) async fn create_invite_route(
if let Some(server) = body.room_id.server_name() { if let Some(server) = body.room_id.server_name() {
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(&server.to_owned()) .contains(&server.to_owned())
@ -47,7 +47,7 @@ pub(crate) async fn create_invite_route(
} }
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(body.origin()) .contains(body.origin())

View file

@ -42,7 +42,7 @@ pub(crate) async fn create_join_event_template_route(
.await?; .await?;
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(body.origin()) .contains(body.origin())
@ -59,7 +59,7 @@ pub(crate) async fn create_join_event_template_route(
if let Some(server) = body.room_id.server_name() { if let Some(server) = body.room_id.server_name() {
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(&server.to_owned()) .contains(&server.to_owned())

View file

@ -34,7 +34,7 @@ pub(crate) async fn create_knock_event_template_route(
.await?; .await?;
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(body.origin()) .contains(body.origin())
@ -51,7 +51,7 @@ pub(crate) async fn create_knock_event_template_route(
if let Some(server) = body.room_id.server_name() { if let Some(server) = body.room_id.server_name() {
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(&server.to_owned()) .contains(&server.to_owned())

View file

@ -20,7 +20,7 @@ pub(crate) async fn get_public_rooms_filtered_route(
body: Ruma<get_public_rooms_filtered::v1::Request>, body: Ruma<get_public_rooms_filtered::v1::Request>,
) -> Result<get_public_rooms_filtered::v1::Response> { ) -> Result<get_public_rooms_filtered::v1::Response> {
if !services if !services
.globals .server
.config .config
.allow_public_room_directory_over_federation .allow_public_room_directory_over_federation
{ {

View file

@ -63,7 +63,7 @@ pub(crate) async fn get_profile_information_route(
body: Ruma<get_profile_information::v1::Request>, body: Ruma<get_profile_information::v1::Request>,
) -> Result<get_profile_information::v1::Response> { ) -> Result<get_profile_information::v1::Response> {
if !services if !services
.globals .server
.config .config
.allow_inbound_profile_lookup_federation_requests .allow_inbound_profile_lookup_federation_requests
{ {

View file

@ -309,7 +309,7 @@ async fn handle_edu_typing(
origin: &ServerName, origin: &ServerName,
typing: TypingContent, typing: TypingContent,
) { ) {
if !services.globals.config.allow_incoming_typing { if !services.server.config.allow_incoming_typing {
return; return;
} }
@ -344,7 +344,7 @@ async fn handle_edu_typing(
if typing.typing { if typing.typing {
let timeout = utils::millis_since_unix_epoch().saturating_add( let timeout = utils::millis_since_unix_epoch().saturating_add(
services services
.globals .server
.config .config
.typing_federation_timeout_s .typing_federation_timeout_s
.saturating_mul(1000), .saturating_mul(1000),

View file

@ -268,7 +268,7 @@ pub(crate) async fn create_join_event_v1_route(
body: Ruma<create_join_event::v1::Request>, body: Ruma<create_join_event::v1::Request>,
) -> Result<create_join_event::v1::Response> { ) -> Result<create_join_event::v1::Response> {
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(body.origin()) .contains(body.origin())
@ -284,7 +284,7 @@ pub(crate) async fn create_join_event_v1_route(
if let Some(server) = body.room_id.server_name() { if let Some(server) = body.room_id.server_name() {
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(&server.to_owned()) .contains(&server.to_owned())
@ -316,7 +316,7 @@ pub(crate) async fn create_join_event_v2_route(
body: Ruma<create_join_event::v2::Request>, body: Ruma<create_join_event::v2::Request>,
) -> Result<create_join_event::v2::Response> { ) -> Result<create_join_event::v2::Response> {
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(body.origin()) .contains(body.origin())
@ -326,7 +326,7 @@ pub(crate) async fn create_join_event_v2_route(
if let Some(server) = body.room_id.server_name() { if let Some(server) = body.room_id.server_name() {
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(&server.to_owned()) .contains(&server.to_owned())

View file

@ -22,7 +22,7 @@ pub(crate) async fn create_knock_event_v1_route(
body: Ruma<send_knock::v1::Request>, body: Ruma<send_knock::v1::Request>,
) -> Result<send_knock::v1::Response> { ) -> Result<send_knock::v1::Response> {
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(body.origin()) .contains(body.origin())
@ -38,7 +38,7 @@ pub(crate) async fn create_knock_event_v1_route(
if let Some(server) = body.room_id.server_name() { if let Some(server) = body.room_id.server_name() {
if services if services
.globals .server
.config .config
.forbidden_remote_server_names .forbidden_remote_server_names
.contains(&server.to_owned()) .contains(&server.to_owned())

View file

@ -338,7 +338,7 @@ impl Service {
} }
// Check if server-side command-escape is disabled by configuration // Check if server-side command-escape is disabled by configuration
if is_public_escape && !self.services.globals.config.admin_escape_commands { if is_public_escape && !self.services.server.config.admin_escape_commands {
return false; return false;
} }

View file

@ -7,7 +7,7 @@ use std::{
time::Instant, time::Instant,
}; };
use conduwuit::{error, utils::bytes::pretty, Config, Result}; use conduwuit::{error, utils::bytes::pretty, Result, Server};
use data::Data; use data::Data;
use regex::RegexSet; use regex::RegexSet;
use ruma::{OwnedEventId, OwnedRoomAliasId, OwnedServerName, OwnedUserId, ServerName, UserId}; use ruma::{OwnedEventId, OwnedRoomAliasId, OwnedServerName, OwnedUserId, ServerName, UserId};
@ -16,8 +16,8 @@ use crate::service;
pub struct Service { pub struct Service {
pub db: Data, pub db: Data,
server: Arc<Server>,
pub config: Config,
pub bad_event_ratelimiter: Arc<RwLock<HashMap<OwnedEventId, RateLimitState>>>, pub bad_event_ratelimiter: Arc<RwLock<HashMap<OwnedEventId, RateLimitState>>>,
pub server_user: OwnedUserId, pub server_user: OwnedUserId,
pub admin_alias: OwnedRoomAliasId, pub admin_alias: OwnedRoomAliasId,
@ -57,9 +57,9 @@ impl crate::Service for Service {
}, },
); );
let mut s = Self { Ok(Arc::new(Self {
db, db,
config: config.clone(), server: args.server.clone(),
bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())), bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
admin_alias: OwnedRoomAliasId::try_from(format!("#admins:{}", &config.server_name)) admin_alias: OwnedRoomAliasId::try_from(format!("#admins:{}", &config.server_name))
.expect("#admins:server_name is valid alias name"), .expect("#admins:server_name is valid alias name"),
@ -70,9 +70,7 @@ impl crate::Service for Service {
.expect("@conduit:server_name is valid"), .expect("@conduit:server_name is valid"),
turn_secret, turn_secret,
registration_token, registration_token,
}; }))
Ok(Arc::new(s))
} }
fn memory_usage(&self, out: &mut dyn Write) -> Result { fn memory_usage(&self, out: &mut dyn Write) -> Result {
@ -109,93 +107,97 @@ impl Service {
pub fn current_count(&self) -> Result<u64> { Ok(self.db.current_count()) } pub fn current_count(&self) -> Result<u64> { Ok(self.db.current_count()) }
#[inline] #[inline]
pub fn server_name(&self) -> &ServerName { self.config.server_name.as_ref() } pub fn server_name(&self) -> &ServerName { self.server.config.server_name.as_ref() }
pub fn allow_registration(&self) -> bool { self.config.allow_registration } pub fn allow_registration(&self) -> bool { self.server.config.allow_registration }
pub fn allow_guest_registration(&self) -> bool { self.config.allow_guest_registration } pub fn allow_guest_registration(&self) -> bool { self.server.config.allow_guest_registration }
pub fn allow_guests_auto_join_rooms(&self) -> bool { pub fn allow_guests_auto_join_rooms(&self) -> bool {
self.config.allow_guests_auto_join_rooms self.server.config.allow_guests_auto_join_rooms
} }
pub fn log_guest_registrations(&self) -> bool { self.config.log_guest_registrations } pub fn log_guest_registrations(&self) -> bool { self.server.config.log_guest_registrations }
pub fn allow_encryption(&self) -> bool { self.config.allow_encryption } pub fn allow_encryption(&self) -> bool { self.server.config.allow_encryption }
pub fn allow_federation(&self) -> bool { self.config.allow_federation } pub fn allow_federation(&self) -> bool { self.server.config.allow_federation }
pub fn allow_public_room_directory_over_federation(&self) -> bool { pub fn allow_public_room_directory_over_federation(&self) -> bool {
self.config.allow_public_room_directory_over_federation self.server
.config
.allow_public_room_directory_over_federation
} }
pub fn allow_device_name_federation(&self) -> bool { pub fn allow_device_name_federation(&self) -> bool {
self.config.allow_device_name_federation self.server.config.allow_device_name_federation
} }
pub fn allow_room_creation(&self) -> bool { self.config.allow_room_creation } pub fn allow_room_creation(&self) -> bool { self.server.config.allow_room_creation }
pub fn new_user_displayname_suffix(&self) -> &String { pub fn new_user_displayname_suffix(&self) -> &String {
&self.config.new_user_displayname_suffix &self.server.config.new_user_displayname_suffix
} }
pub fn allow_check_for_updates(&self) -> bool { self.config.allow_check_for_updates } pub fn allow_check_for_updates(&self) -> bool { self.server.config.allow_check_for_updates }
pub fn trusted_servers(&self) -> &[OwnedServerName] { &self.config.trusted_servers } pub fn trusted_servers(&self) -> &[OwnedServerName] { &self.server.config.trusted_servers }
pub fn turn_password(&self) -> &String { &self.config.turn_password } pub fn turn_password(&self) -> &String { &self.server.config.turn_password }
pub fn turn_ttl(&self) -> u64 { self.config.turn_ttl } pub fn turn_ttl(&self) -> u64 { self.server.config.turn_ttl }
pub fn turn_uris(&self) -> &[String] { &self.config.turn_uris } pub fn turn_uris(&self) -> &[String] { &self.server.config.turn_uris }
pub fn turn_username(&self) -> &String { &self.config.turn_username } pub fn turn_username(&self) -> &String { &self.server.config.turn_username }
pub fn notification_push_path(&self) -> &String { &self.config.notification_push_path } pub fn notification_push_path(&self) -> &String { &self.server.config.notification_push_path }
pub fn emergency_password(&self) -> &Option<String> { &self.config.emergency_password } pub fn emergency_password(&self) -> &Option<String> { &self.server.config.emergency_password }
pub fn url_preview_domain_contains_allowlist(&self) -> &Vec<String> { pub fn url_preview_domain_contains_allowlist(&self) -> &Vec<String> {
&self.config.url_preview_domain_contains_allowlist &self.server.config.url_preview_domain_contains_allowlist
} }
pub fn url_preview_domain_explicit_allowlist(&self) -> &Vec<String> { pub fn url_preview_domain_explicit_allowlist(&self) -> &Vec<String> {
&self.config.url_preview_domain_explicit_allowlist &self.server.config.url_preview_domain_explicit_allowlist
} }
pub fn url_preview_domain_explicit_denylist(&self) -> &Vec<String> { pub fn url_preview_domain_explicit_denylist(&self) -> &Vec<String> {
&self.config.url_preview_domain_explicit_denylist &self.server.config.url_preview_domain_explicit_denylist
} }
pub fn url_preview_url_contains_allowlist(&self) -> &Vec<String> { pub fn url_preview_url_contains_allowlist(&self) -> &Vec<String> {
&self.config.url_preview_url_contains_allowlist &self.server.config.url_preview_url_contains_allowlist
} }
pub fn url_preview_max_spider_size(&self) -> usize { self.config.url_preview_max_spider_size } pub fn url_preview_max_spider_size(&self) -> usize {
self.server.config.url_preview_max_spider_size
}
pub fn url_preview_check_root_domain(&self) -> bool { pub fn url_preview_check_root_domain(&self) -> bool {
self.config.url_preview_check_root_domain self.server.config.url_preview_check_root_domain
} }
pub fn forbidden_alias_names(&self) -> &RegexSet { &self.config.forbidden_alias_names } pub fn forbidden_alias_names(&self) -> &RegexSet { &self.server.config.forbidden_alias_names }
pub fn forbidden_usernames(&self) -> &RegexSet { &self.config.forbidden_usernames } pub fn forbidden_usernames(&self) -> &RegexSet { &self.server.config.forbidden_usernames }
pub fn allow_local_presence(&self) -> bool { self.config.allow_local_presence } pub fn allow_local_presence(&self) -> bool { self.server.config.allow_local_presence }
pub fn allow_incoming_presence(&self) -> bool { self.config.allow_incoming_presence } pub fn allow_incoming_presence(&self) -> bool { self.server.config.allow_incoming_presence }
pub fn allow_outgoing_presence(&self) -> bool { self.config.allow_outgoing_presence } pub fn allow_outgoing_presence(&self) -> bool { self.server.config.allow_outgoing_presence }
pub fn allow_incoming_read_receipts(&self) -> bool { pub fn allow_incoming_read_receipts(&self) -> bool {
self.config.allow_incoming_read_receipts self.server.config.allow_incoming_read_receipts
} }
pub fn allow_outgoing_read_receipts(&self) -> bool { pub fn allow_outgoing_read_receipts(&self) -> bool {
self.config.allow_outgoing_read_receipts self.server.config.allow_outgoing_read_receipts
} }
pub fn block_non_admin_invites(&self) -> bool { self.config.block_non_admin_invites } pub fn block_non_admin_invites(&self) -> bool { self.server.config.block_non_admin_invites }
/// checks if `user_id` is local to us via server_name comparison /// checks if `user_id` is local to us via server_name comparison
#[inline] #[inline]
@ -205,7 +207,7 @@ impl Service {
#[inline] #[inline]
pub fn server_is_ours(&self, server_name: &ServerName) -> bool { pub fn server_is_ours(&self, server_name: &ServerName) -> bool {
server_name == self.config.server_name server_name == self.server.config.server_name
} }
#[inline] #[inline]

View file

@ -5,7 +5,7 @@ use std::sync::Arc;
use conduwuit::{ use conduwuit::{
err, err,
utils::{stream::TryIgnore, ReadyExt}, utils::{stream::TryIgnore, ReadyExt},
Err, Result, Err, Result, Server,
}; };
use database::{Deserialized, Ignore, Interfix, Map}; use database::{Deserialized, Ignore, Interfix, Map};
use futures::{Stream, StreamExt, TryFutureExt}; use futures::{Stream, StreamExt, TryFutureExt};
@ -31,6 +31,7 @@ struct Data {
} }
struct Services { struct Services {
server: Arc<Server>,
admin: Dep<admin::Service>, admin: Dep<admin::Service>,
appservice: Dep<appservice::Service>, appservice: Dep<appservice::Service>,
globals: Dep<globals::Service>, globals: Dep<globals::Service>,
@ -47,6 +48,7 @@ impl crate::Service for Service {
aliasid_alias: args.db["aliasid_alias"].clone(), aliasid_alias: args.db["aliasid_alias"].clone(),
}, },
services: Services { services: Services {
server: args.server.clone(),
admin: args.depend::<admin::Service>("admin"), admin: args.depend::<admin::Service>("admin"),
appservice: args.depend::<appservice::Service>("appservice"), appservice: args.depend::<appservice::Service>("appservice"),
globals: args.depend::<globals::Service>("globals"), globals: args.depend::<globals::Service>("globals"),
@ -146,9 +148,9 @@ impl Service {
let server_name = room_alias.server_name(); let server_name = room_alias.server_name();
let server_is_ours = self.services.globals.server_is_ours(server_name); let server_is_ours = self.services.globals.server_is_ours(server_name);
let servers_contains_ours = || { let servers_contains_ours = || {
servers.as_ref().is_some_and(|servers| { servers
servers.contains(&self.services.globals.config.server_name) .as_ref()
}) .is_some_and(|servers| servers.contains(&self.services.server.config.server_name))
}; };
if !server_is_ours && !servers_contains_ours() { if !server_is_ours && !servers_contains_ours() {