diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index 49078dde..af7bd79f 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -170,7 +170,7 @@ pub(super) async fn get_remote_pdu_list( server: Box, force: bool, ) -> Result { - if !self.services.globals.config.allow_federation { + if !self.services.server.config.allow_federation { return Ok(RoomMessageEventContent::text_plain( "Federation is disabled on this homeserver.", )); @@ -235,7 +235,7 @@ pub(super) async fn get_remote_pdu( event_id: Box, server: Box, ) -> Result { - if !self.services.globals.config.allow_federation { + if !self.services.server.config.allow_federation { return Ok(RoomMessageEventContent::text_plain( "Federation is disabled on this homeserver.", )); @@ -419,7 +419,7 @@ pub(super) async fn change_log_level( let handles = &["console"]; 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, | Err(e) => { return Ok(RoomMessageEventContent::text_plain(format!( @@ -438,7 +438,7 @@ pub(super) async fn change_log_level( | Ok(()) => { return Ok(RoomMessageEventContent::text_plain(format!( "Successfully changed log level back to config value {}", - self.services.globals.config.log + self.services.server.config.log ))); }, | Err(e) => { @@ -554,7 +554,7 @@ pub(super) async fn first_pdu_in_room( .services .rooms .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 { return Ok(RoomMessageEventContent::text_plain( @@ -583,7 +583,7 @@ pub(super) async fn latest_pdu_in_room( .services .rooms .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 { return Ok(RoomMessageEventContent::text_plain( @@ -613,7 +613,7 @@ pub(super) async fn force_set_room_state_from_server( .services .rooms .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 { return Ok(RoomMessageEventContent::text_plain( @@ -818,13 +818,13 @@ pub(super) async fn resolve_true_destination( server_name: Box, no_cache: bool, ) -> Result { - if !self.services.globals.config.allow_federation { + if !self.services.server.config.allow_federation { return Ok(RoomMessageEventContent::text_plain( "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( "Not allowed to send federation requests to ourselves. Please use `get-pdu` for \ fetching local PDUs.", diff --git a/src/admin/federation/commands.rs b/src/admin/federation/commands.rs index 75635b1b..be91ef0a 100644 --- a/src/admin/federation/commands.rs +++ b/src/admin/federation/commands.rs @@ -92,7 +92,7 @@ pub(super) async fn remote_user_in_rooms( &self, user_id: Box, ) -> Result { - 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( "User belongs to our server, please use `list-joined-rooms` user admin command \ instead.", diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 57aedd9c..64767a36 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -83,12 +83,12 @@ pub(super) async fn create_user( // content is set to the user's display name with a space before it if !self .services - .globals + .server .config .new_user_displayname_suffix .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"); } @@ -114,8 +114,8 @@ pub(super) async fn create_user( ) .await?; - if !self.services.globals.config.auto_join_rooms.is_empty() { - for room in &self.services.globals.config.auto_join_rooms { + if !self.services.server.config.auto_join_rooms.is_empty() { + for room in &self.services.server.config.auto_join_rooms { 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"); continue; diff --git a/src/api/client/account.rs b/src/api/client/account.rs index e6748124..cb25b276 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -299,7 +299,7 @@ pub(crate) async fn register_route( if !services.globals.new_user_displayname_suffix().is_empty() && 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"); } @@ -365,7 +365,7 @@ pub(crate) async fn register_route( \"{device_display_name}\"" ); - if services.globals.config.admin_room_notices { + if services.server.config.admin_room_notices { services .admin .send_message(RoomMessageEventContent::notice_plain(format!( @@ -378,7 +378,7 @@ pub(crate) async fn register_route( } else { info!("New user \"{user_id}\" registered on this server."); - if services.globals.config.admin_room_notices { + if services.server.config.admin_room_notices { services .admin .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."); if !device_display_name.is_empty() { - if services.globals.config.admin_room_notices { + if services.server.config.admin_room_notices { services .admin .send_message(RoomMessageEventContent::notice_plain(format!( @@ -407,7 +407,7 @@ pub(crate) async fn register_route( } } else { #[allow(clippy::collapsible_else_if)] - if services.globals.config.admin_room_notices { + if services.server.config.admin_room_notices { services .admin .send_message(RoomMessageEventContent::notice_plain(format!( @@ -438,10 +438,10 @@ pub(crate) async fn register_route( } 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) { - 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 { error!( "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."); - if services.globals.config.admin_room_notices { + if services.server.config.admin_room_notices { services .admin .send_message(RoomMessageEventContent::notice_plain(format!( @@ -673,7 +673,7 @@ pub(crate) async fn deactivate_route( info!("User {sender_user} deactivated their account."); - if services.globals.config.admin_room_notices { + if services.server.config.admin_room_notices { services .admin .send_message(RoomMessageEventContent::notice_plain(format!( diff --git a/src/api/client/directory.rs b/src/api/client/directory.rs index c8faaa46..9166eed9 100644 --- a/src/api/client/directory.rs +++ b/src/api/client/directory.rs @@ -152,7 +152,7 @@ pub(crate) async fn set_room_visibility_route( match &body.visibility { | 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 && body.appservice_info.is_none() { @@ -162,7 +162,7 @@ pub(crate) async fn set_room_visibility_route( body.room_id ); - if services.globals.config.admin_room_notices { + if services.server.config.admin_room_notices { services .admin .send_text(&format!( @@ -181,7 +181,7 @@ pub(crate) async fn set_room_visibility_route( services.rooms.directory.set_public(&body.room_id); - if services.globals.config.admin_room_notices { + if services.server.config.admin_room_notices { services .admin .send_text(&format!( diff --git a/src/api/client/media.rs b/src/api/client/media.rs index e58ba626..afbc218a 100644 --- a/src/api/client/media.rs +++ b/src/api/client/media.rs @@ -31,7 +31,7 @@ pub(crate) async fn get_media_config_route( _body: Ruma, ) -> Result { 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), }) } diff --git a/src/api/client/media_legacy.rs b/src/api/client/media_legacy.rs index 6f54a683..29cf3069 100644 --- a/src/api/client/media_legacy.rs +++ b/src/api/client/media_legacy.rs @@ -27,7 +27,7 @@ pub(crate) async fn get_media_config_legacy_route( _body: Ruma, ) -> Result { 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), }) } diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs index d94fc3c7..2e23dab9 100644 --- a/src/api/client/membership.rs +++ b/src/api/client/membership.rs @@ -71,7 +71,7 @@ async fn banned_room_check( if let Some(room_id) = room_id { if services.rooms.metadata.is_banned(room_id).await || services - .globals + .server .config .forbidden_remote_server_names .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}" ); - if services.globals.config.auto_deactivate_banned_room_attempts { + if services.server.config.auto_deactivate_banned_room_attempts { warn!( "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 .admin .send_message(RoomMessageEventContent::text_plain(format!( @@ -112,7 +112,7 @@ async fn banned_room_check( } } else if let Some(server_name) = server_name { if services - .globals + .server .config .forbidden_remote_server_names .contains(&server_name.to_owned()) @@ -122,12 +122,12 @@ async fn banned_room_check( 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!( "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 .admin .send_message(RoomMessageEventContent::text_plain(format!( diff --git a/src/api/client/openid.rs b/src/api/client/openid.rs index 4b2ff727..3547d284 100644 --- a/src/api/client/openid.rs +++ b/src/api/client/openid.rs @@ -37,7 +37,7 @@ pub(crate) async fn create_openid_token_route( Ok(account::request_openid_token::v3::Response { access_token, 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), }) } diff --git a/src/api/client/report.rs b/src/api/client/report.rs index fe23b7bd..2b25b518 100644 --- a/src/api/client/report.rs +++ b/src/api/client/report.rs @@ -50,7 +50,7 @@ pub(crate) async fn report_room_route( if !services .rooms .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 { return Err!(Request(NotFound( diff --git a/src/api/client/room/create.rs b/src/api/client/room/create.rs index a78242ca..1b6e8667 100644 --- a/src/api/client/room/create.rs +++ b/src/api/client/room/create.rs @@ -71,7 +71,7 @@ pub(crate) async fn create_room_route( let room_id: OwnedRoomId = if let Some(custom_room_id) = &body.room_id { custom_room_id_check(&services, custom_room_id)? } 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 @@ -83,7 +83,7 @@ pub(crate) async fn create_room_route( } 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 && body.appservice_info.is_none() { @@ -93,7 +93,7 @@ pub(crate) async fn create_room_route( &room_id ); - if services.globals.config.admin_room_notices { + if services.server.config.admin_room_notices { services .admin .send_text(&format!( @@ -450,7 +450,7 @@ pub(crate) async fn create_room_route( if body.visibility == room::Visibility::Public { services.rooms.directory.set_public(&room_id); - if services.globals.config.admin_room_notices { + if services.server.config.admin_room_notices { services .admin .send_text(&format!( diff --git a/src/api/client/typing.rs b/src/api/client/typing.rs index 6eabe96a..b311295b 100644 --- a/src/api/client/typing.rs +++ b/src/api/client/typing.rs @@ -1,5 +1,5 @@ use axum::extract::State; -use conduwuit::Err; +use conduwuit::{utils::math::Tried, Err}; use ruma::api::client::typing::create_typing_event; use crate::{utils, Result, Ruma}; @@ -31,17 +31,15 @@ pub(crate) async fn create_typing_event_route( let duration = utils::clamp( duration.as_millis().try_into().unwrap_or(u64::MAX), services - .globals + .server .config .typing_client_timeout_min_s - .checked_mul(1000) - .unwrap(), + .try_mul(1000)?, services - .globals + .server .config .typing_client_timeout_max_s - .checked_mul(1000) - .unwrap(), + .try_mul(1000)?, ); services .rooms diff --git a/src/api/client/voip.rs b/src/api/client/voip.rs index ec804570..c08b1fdf 100644 --- a/src/api/client/voip.rs +++ b/src/api/client/voip.rs @@ -38,7 +38,7 @@ pub(crate) async fn turn_server_route( let user = body.sender_user.unwrap_or_else(|| { UserId::parse_with_server_name( utils::random_string(RANDOM_USER_ID_LENGTH).to_lowercase(), - &services.globals.config.server_name, + &services.server.config.server_name, ) .unwrap() }); diff --git a/src/api/router/auth.rs b/src/api/router/auth.rs index dd25e091..ecea305b 100644 --- a/src/api/router/auth.rs +++ b/src/api/router/auth.rs @@ -71,7 +71,7 @@ pub(super) async fn auth( match metadata { | &get_public_rooms::v3::Request::METADATA => { if !services - .globals + .server .config .allow_public_room_directory_without_auth { @@ -94,7 +94,7 @@ pub(super) async fn auth( | &get_display_name::v3::Request::METADATA | &get_avatar_url::v3::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 { | Token::Appservice(_) | Token::User(_) => { // we should have validated the token above @@ -127,7 +127,7 @@ pub(super) async fn auth( }), | (AuthScheme::AccessToken, Token::None) => match metadata { | &get_turn_server_info::v3::Request::METADATA => { - if services.globals.config.turn_allow_guests { + if services.server.config.turn_allow_guests { Ok(Auth { origin: None, sender_user: None, diff --git a/src/api/router/request.rs b/src/api/router/request.rs index 627abd30..615a8bff 100644 --- a/src/api/router/request.rs +++ b/src/api/router/request.rs @@ -32,7 +32,7 @@ pub(super) async fn from( let query = serde_html_form::from_str(query) .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) .await diff --git a/src/api/server/invite.rs b/src/api/server/invite.rs index 1fea268b..27a4485c 100644 --- a/src/api/server/invite.rs +++ b/src/api/server/invite.rs @@ -37,7 +37,7 @@ pub(crate) async fn create_invite_route( if let Some(server) = body.room_id.server_name() { if services - .globals + .server .config .forbidden_remote_server_names .contains(&server.to_owned()) @@ -47,7 +47,7 @@ pub(crate) async fn create_invite_route( } if services - .globals + .server .config .forbidden_remote_server_names .contains(body.origin()) diff --git a/src/api/server/make_join.rs b/src/api/server/make_join.rs index 3900c418..b753346c 100644 --- a/src/api/server/make_join.rs +++ b/src/api/server/make_join.rs @@ -42,7 +42,7 @@ pub(crate) async fn create_join_event_template_route( .await?; if services - .globals + .server .config .forbidden_remote_server_names .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 services - .globals + .server .config .forbidden_remote_server_names .contains(&server.to_owned()) diff --git a/src/api/server/make_knock.rs b/src/api/server/make_knock.rs index 90b9b629..423e202d 100644 --- a/src/api/server/make_knock.rs +++ b/src/api/server/make_knock.rs @@ -34,7 +34,7 @@ pub(crate) async fn create_knock_event_template_route( .await?; if services - .globals + .server .config .forbidden_remote_server_names .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 services - .globals + .server .config .forbidden_remote_server_names .contains(&server.to_owned()) diff --git a/src/api/server/publicrooms.rs b/src/api/server/publicrooms.rs index 77cde15f..2c09385b 100644 --- a/src/api/server/publicrooms.rs +++ b/src/api/server/publicrooms.rs @@ -20,7 +20,7 @@ pub(crate) async fn get_public_rooms_filtered_route( body: Ruma, ) -> Result { if !services - .globals + .server .config .allow_public_room_directory_over_federation { diff --git a/src/api/server/query.rs b/src/api/server/query.rs index 0e5f7e56..69f62e94 100644 --- a/src/api/server/query.rs +++ b/src/api/server/query.rs @@ -63,7 +63,7 @@ pub(crate) async fn get_profile_information_route( body: Ruma, ) -> Result { if !services - .globals + .server .config .allow_inbound_profile_lookup_federation_requests { diff --git a/src/api/server/send.rs b/src/api/server/send.rs index 56a17c22..eec9bd11 100644 --- a/src/api/server/send.rs +++ b/src/api/server/send.rs @@ -309,7 +309,7 @@ async fn handle_edu_typing( origin: &ServerName, typing: TypingContent, ) { - if !services.globals.config.allow_incoming_typing { + if !services.server.config.allow_incoming_typing { return; } @@ -344,7 +344,7 @@ async fn handle_edu_typing( if typing.typing { let timeout = utils::millis_since_unix_epoch().saturating_add( services - .globals + .server .config .typing_federation_timeout_s .saturating_mul(1000), diff --git a/src/api/server/send_join.rs b/src/api/server/send_join.rs index 97a65bf8..e62089b4 100644 --- a/src/api/server/send_join.rs +++ b/src/api/server/send_join.rs @@ -268,7 +268,7 @@ pub(crate) async fn create_join_event_v1_route( body: Ruma, ) -> Result { if services - .globals + .server .config .forbidden_remote_server_names .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 services - .globals + .server .config .forbidden_remote_server_names .contains(&server.to_owned()) @@ -316,7 +316,7 @@ pub(crate) async fn create_join_event_v2_route( body: Ruma, ) -> Result { if services - .globals + .server .config .forbidden_remote_server_names .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 services - .globals + .server .config .forbidden_remote_server_names .contains(&server.to_owned()) diff --git a/src/api/server/send_knock.rs b/src/api/server/send_knock.rs index 95478081..b07620af 100644 --- a/src/api/server/send_knock.rs +++ b/src/api/server/send_knock.rs @@ -22,7 +22,7 @@ pub(crate) async fn create_knock_event_v1_route( body: Ruma, ) -> Result { if services - .globals + .server .config .forbidden_remote_server_names .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 services - .globals + .server .config .forbidden_remote_server_names .contains(&server.to_owned()) diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 399055aa..bc410631 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -338,7 +338,7 @@ impl Service { } // 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; } diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index fe84578a..ef34054f 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -7,7 +7,7 @@ use std::{ time::Instant, }; -use conduwuit::{error, utils::bytes::pretty, Config, Result}; +use conduwuit::{error, utils::bytes::pretty, Result, Server}; use data::Data; use regex::RegexSet; use ruma::{OwnedEventId, OwnedRoomAliasId, OwnedServerName, OwnedUserId, ServerName, UserId}; @@ -16,8 +16,8 @@ use crate::service; pub struct Service { pub db: Data, + server: Arc, - pub config: Config, pub bad_event_ratelimiter: Arc>>, pub server_user: OwnedUserId, pub admin_alias: OwnedRoomAliasId, @@ -57,9 +57,9 @@ impl crate::Service for Service { }, ); - let mut s = Self { + Ok(Arc::new(Self { db, - config: config.clone(), + server: args.server.clone(), bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())), admin_alias: OwnedRoomAliasId::try_from(format!("#admins:{}", &config.server_name)) .expect("#admins:server_name is valid alias name"), @@ -70,9 +70,7 @@ impl crate::Service for Service { .expect("@conduit:server_name is valid"), turn_secret, registration_token, - }; - - Ok(Arc::new(s)) + })) } fn memory_usage(&self, out: &mut dyn Write) -> Result { @@ -109,93 +107,97 @@ impl Service { pub fn current_count(&self) -> Result { Ok(self.db.current_count()) } #[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 { - 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 { - 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 { - 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 { - &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 { &self.config.emergency_password } + pub fn emergency_password(&self) -> &Option { &self.server.config.emergency_password } pub fn url_preview_domain_contains_allowlist(&self) -> &Vec { - &self.config.url_preview_domain_contains_allowlist + &self.server.config.url_preview_domain_contains_allowlist } pub fn url_preview_domain_explicit_allowlist(&self) -> &Vec { - &self.config.url_preview_domain_explicit_allowlist + &self.server.config.url_preview_domain_explicit_allowlist } pub fn url_preview_domain_explicit_denylist(&self) -> &Vec { - &self.config.url_preview_domain_explicit_denylist + &self.server.config.url_preview_domain_explicit_denylist } pub fn url_preview_url_contains_allowlist(&self) -> &Vec { - &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 { - 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 { - self.config.allow_incoming_read_receipts + self.server.config.allow_incoming_read_receipts } 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 #[inline] @@ -205,7 +207,7 @@ impl Service { #[inline] pub fn server_is_ours(&self, server_name: &ServerName) -> bool { - server_name == self.config.server_name + server_name == self.server.config.server_name } #[inline] diff --git a/src/service/rooms/alias/mod.rs b/src/service/rooms/alias/mod.rs index 0acbb116..91797d01 100644 --- a/src/service/rooms/alias/mod.rs +++ b/src/service/rooms/alias/mod.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use conduwuit::{ err, utils::{stream::TryIgnore, ReadyExt}, - Err, Result, + Err, Result, Server, }; use database::{Deserialized, Ignore, Interfix, Map}; use futures::{Stream, StreamExt, TryFutureExt}; @@ -31,6 +31,7 @@ struct Data { } struct Services { + server: Arc, admin: Dep, appservice: Dep, globals: Dep, @@ -47,6 +48,7 @@ impl crate::Service for Service { aliasid_alias: args.db["aliasid_alias"].clone(), }, services: Services { + server: args.server.clone(), admin: args.depend::("admin"), appservice: args.depend::("appservice"), globals: args.depend::("globals"), @@ -146,9 +148,9 @@ impl Service { let server_name = room_alias.server_name(); let server_is_ours = self.services.globals.server_is_ours(server_name); let servers_contains_ours = || { - servers.as_ref().is_some_and(|servers| { - servers.contains(&self.services.globals.config.server_name) - }) + servers + .as_ref() + .is_some_and(|servers| servers.contains(&self.services.server.config.server_name)) }; if !server_is_ours && !servers_contains_ours() {