From d748544f0e7f35c7a4149130bb76549bc3c8f985 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Wed, 1 May 2024 22:26:21 -0700 Subject: [PATCH] enable `unreachable_pub` lint This causes some other lints to start firing too (which is good), but I'm going to fix them in follow-up commits to keep things organized. --- Cargo.toml | 7 ++ src/api.rs | 8 +- src/api/client_server.rs | 74 +++++------ src/api/client_server/account.rs | 18 +-- src/api/client_server/alias.rs | 6 +- src/api/client_server/backup.rs | 28 ++--- src/api/client_server/capabilities.rs | 2 +- src/api/client_server/config.rs | 8 +- src/api/client_server/context.rs | 2 +- src/api/client_server/device.rs | 10 +- src/api/client_server/directory.rs | 8 +- src/api/client_server/filter.rs | 4 +- src/api/client_server/keys.rs | 14 ++- src/api/client_server/media.rs | 12 +- src/api/client_server/membership.rs | 32 +++-- src/api/client_server/message.rs | 4 +- src/api/client_server/profile.rs | 10 +- src/api/client_server/push.rs | 20 +-- src/api/client_server/read_marker.rs | 4 +- src/api/client_server/redact.rs | 2 +- src/api/client_server/relations.rs | 6 +- src/api/client_server/report.rs | 2 +- src/api/client_server/room.rs | 8 +- src/api/client_server/search.rs | 2 +- src/api/client_server/session.rs | 8 +- src/api/client_server/space.rs | 2 +- src/api/client_server/state.rs | 10 +- src/api/client_server/sync.rs | 4 +- src/api/client_server/tag.rs | 8 +- src/api/client_server/thirdparty.rs | 2 +- src/api/client_server/threads.rs | 2 +- src/api/client_server/to_device.rs | 2 +- src/api/client_server/typing.rs | 2 +- src/api/client_server/unversioned.rs | 4 +- src/api/client_server/user_directory.rs | 2 +- src/api/client_server/voip.rs | 2 +- src/api/ruma_wrapper.rs | 16 +-- src/api/server_server.rs | 48 ++++---- src/clap.rs | 4 +- src/config.rs | 82 ++++++------ src/config/proxy.rs | 14 +-- src/database.rs | 36 +++--- src/database/abstraction.rs | 10 +- src/database/abstraction/rocksdb.rs | 4 +- src/database/abstraction/sqlite.rs | 12 +- src/database/key_value/globals.rs | 2 +- src/main.rs | 20 +-- src/service.rs | 54 ++++---- src/service/account_data.rs | 12 +- src/service/account_data/data.rs | 2 +- src/service/admin.rs | 14 +-- src/service/appservice.rs | 50 ++++---- src/service/appservice/data.rs | 2 +- src/service/globals.rs | 122 +++++++++--------- src/service/globals/data.rs | 2 +- src/service/key_backups.rs | 36 +++--- src/service/key_backups/data.rs | 2 +- src/service/media.rs | 24 ++-- src/service/media/data.rs | 2 +- src/service/pdu.rs | 76 ++++++------ src/service/pusher.rs | 24 ++-- src/service/pusher/data.rs | 2 +- src/service/rooms.rs | 80 ++++++------ src/service/rooms/alias.rs | 14 +-- src/service/rooms/alias/data.rs | 2 +- src/service/rooms/auth_chain.rs | 19 ++- src/service/rooms/auth_chain/data.rs | 2 +- src/service/rooms/directory.rs | 14 +-- src/service/rooms/directory/data.rs | 2 +- src/service/rooms/edus.rs | 12 +- src/service/rooms/edus/read_receipt.rs | 29 +++-- src/service/rooms/edus/read_receipt/data.rs | 2 +- src/service/rooms/edus/typing.rs | 23 ++-- src/service/rooms/event_handler.rs | 8 +- src/service/rooms/lazy_loading.rs | 16 +-- src/service/rooms/lazy_loading/data.rs | 2 +- src/service/rooms/metadata.rs | 14 +-- src/service/rooms/metadata/data.rs | 2 +- src/service/rooms/outlier.rs | 19 ++- src/service/rooms/outlier/data.rs | 2 +- src/service/rooms/pdu_metadata.rs | 24 ++-- src/service/rooms/pdu_metadata/data.rs | 2 +- src/service/rooms/search.rs | 15 ++- src/service/rooms/search/data.rs | 2 +- src/service/rooms/short.rs | 25 ++-- src/service/rooms/short/data.rs | 2 +- src/service/rooms/spaces.rs | 10 +- src/service/rooms/state.rs | 29 +++-- src/service/rooms/state/data.rs | 2 +- src/service/rooms/state_accessor.rs | 49 ++++---- src/service/rooms/state_accessor/data.rs | 2 +- src/service/rooms/state_cache.rs | 62 ++++++---- src/service/rooms/state_cache/data.rs | 2 +- src/service/rooms/state_compressor.rs | 22 ++-- src/service/rooms/state_compressor/data.rs | 10 +- src/service/rooms/threads.rs | 10 +- src/service/rooms/threads/data.rs | 2 +- src/service/rooms/timeline.rs | 73 ++++++----- src/service/rooms/timeline/data.rs | 2 +- src/service/rooms/user.rs | 28 +++-- src/service/rooms/user/data.rs | 2 +- src/service/sending.rs | 37 +++--- src/service/sending/data.rs | 2 +- src/service/transaction_ids.rs | 10 +- src/service/transaction_ids/data.rs | 2 +- src/service/uiaa.rs | 12 +- src/service/uiaa/data.rs | 2 +- src/service/users.rs | 130 +++++++++++--------- src/service/users/data.rs | 2 +- src/utils.rs | 26 ++-- src/utils/error.rs | 12 +- 111 files changed, 1007 insertions(+), 876 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1229e72a..b185ccc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,12 +6,16 @@ macro_use_extern_crate = "warn" missing_abi = "warn" noop_method_call = "warn" pointer_structural_match = "warn" +unreachable_pub = "warn" unsafe_op_in_unsafe_fn = "warn" unused_extern_crates = "warn" unused_import_braces = "warn" unused_macro_rules = "warn" unused_qualifications = "warn" +# TODO: Remove these +dead_code = "allow" + # Keep alphabetically sorted [workspace.lints.clippy] assertions_on_result_states = "warn" @@ -47,6 +51,9 @@ unseparated_literal_suffix = "warn" verbose_file_reads = "warn" wildcard_dependencies = "warn" +# TODO: Remove these +enum_variant_names = "allow" + [package] name = "grapevine" description = "A Matrix homeserver written in Rust" diff --git a/src/api.rs b/src/api.rs index 0d2cd664..442d2f2b 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,4 +1,4 @@ -pub mod appservice_server; -pub mod client_server; -pub mod ruma_wrapper; -pub mod server_server; +pub(crate) mod appservice_server; +pub(crate) mod client_server; +pub(crate) mod ruma_wrapper; +pub(crate) mod server_server; diff --git a/src/api/client_server.rs b/src/api/client_server.rs index c50db8d5..65c5985d 100644 --- a/src/api/client_server.rs +++ b/src/api/client_server.rs @@ -32,41 +32,41 @@ mod unversioned; mod user_directory; mod voip; -pub use account::*; -pub use alias::*; -pub use backup::*; -pub use capabilities::*; -pub use config::*; -pub use context::*; -pub use device::*; -pub use directory::*; -pub use filter::*; -pub use keys::*; -pub use media::*; -pub use membership::*; -pub use message::*; -pub use profile::*; -pub use push::*; -pub use read_marker::*; -pub use redact::*; -pub use relations::*; -pub use report::*; -pub use room::*; -pub use search::*; -pub use session::*; -pub use space::*; -pub use state::*; -pub use sync::*; -pub use tag::*; -pub use thirdparty::*; -pub use threads::*; -pub use to_device::*; -pub use typing::*; -pub use unversioned::*; -pub use user_directory::*; -pub use voip::*; +pub(crate) use account::*; +pub(crate) use alias::*; +pub(crate) use backup::*; +pub(crate) use capabilities::*; +pub(crate) use config::*; +pub(crate) use context::*; +pub(crate) use device::*; +pub(crate) use directory::*; +pub(crate) use filter::*; +pub(crate) use keys::*; +pub(crate) use media::*; +pub(crate) use membership::*; +pub(crate) use message::*; +pub(crate) use profile::*; +pub(crate) use push::*; +pub(crate) use read_marker::*; +pub(crate) use redact::*; +pub(crate) use relations::*; +pub(crate) use report::*; +pub(crate) use room::*; +pub(crate) use search::*; +pub(crate) use session::*; +pub(crate) use space::*; +pub(crate) use state::*; +pub(crate) use sync::*; +pub(crate) use tag::*; +pub(crate) use thirdparty::*; +pub(crate) use threads::*; +pub(crate) use to_device::*; +pub(crate) use typing::*; +pub(crate) use unversioned::*; +pub(crate) use user_directory::*; +pub(crate) use voip::*; -pub const DEVICE_ID_LENGTH: usize = 10; -pub const TOKEN_LENGTH: usize = 32; -pub const SESSION_ID_LENGTH: usize = 32; -pub const AUTO_GEN_PASSWORD_LENGTH: usize = 15; +pub(crate) const DEVICE_ID_LENGTH: usize = 10; +pub(crate) const TOKEN_LENGTH: usize = 32; +pub(crate) const SESSION_ID_LENGTH: usize = 32; +pub(crate) const AUTO_GEN_PASSWORD_LENGTH: usize = 15; diff --git a/src/api/client_server/account.rs b/src/api/client_server/account.rs index 8f639687..9c3d2083 100644 --- a/src/api/client_server/account.rs +++ b/src/api/client_server/account.rs @@ -30,7 +30,7 @@ const RANDOM_USER_ID_LENGTH: usize = 10; /// - No user or appservice on this server already claimed this username /// /// Note: This will not reserve the username, so the username might become invalid when trying to register -pub async fn get_register_available_route( +pub(crate) async fn get_register_available_route( body: Ruma, ) -> Result { // Validate user id @@ -74,7 +74,9 @@ pub async fn get_register_available_route( /// - If type is not guest and no username is given: Always fails after UIAA check /// - Creates a new account and populates it with default account data /// - If `inhibit_login` is false: Creates a device and returns device id and access_token -pub async fn register_route(body: Ruma) -> Result { +pub(crate) async fn register_route( + body: Ruma, +) -> Result { if !services().globals.allow_registration() && body.appservice_info.is_none() { return Err(Error::BadRequest( ErrorKind::Forbidden, @@ -307,7 +309,7 @@ pub async fn register_route(body: Ruma) -> Result, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -373,7 +375,7 @@ pub async fn change_password_route( /// Get user_id of the sender user. /// /// Note: Also works for Application Services -pub async fn whoami_route(body: Ruma) -> Result { +pub(crate) async fn whoami_route(body: Ruma) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let device_id = body.sender_device.as_ref().cloned(); @@ -394,7 +396,7 @@ pub async fn whoami_route(body: Ruma) -> Result, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -452,7 +454,7 @@ pub async fn deactivate_route( /// Get a list of third party identifiers associated with this account. /// /// - Currently always returns empty list -pub async fn third_party_route( +pub(crate) async fn third_party_route( body: Ruma, ) -> Result { let _sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -465,7 +467,7 @@ pub async fn third_party_route( /// "This API should be used to request validation tokens when adding an email address to an account" /// /// - 403 signals that The homeserver does not allow the third party identifier as a contact option. -pub async fn request_3pid_management_token_via_email_route( +pub(crate) async fn request_3pid_management_token_via_email_route( _body: Ruma, ) -> Result { Err(Error::BadRequest( @@ -479,7 +481,7 @@ pub async fn request_3pid_management_token_via_email_route( /// "This API should be used to request validation tokens when adding an phone number to an account" /// /// - 403 signals that The homeserver does not allow the third party identifier as a contact option. -pub async fn request_3pid_management_token_via_msisdn_route( +pub(crate) async fn request_3pid_management_token_via_msisdn_route( _body: Ruma, ) -> Result { Err(Error::BadRequest( diff --git a/src/api/client_server/alias.rs b/src/api/client_server/alias.rs index 7cbe9fa1..6e198e26 100644 --- a/src/api/client_server/alias.rs +++ b/src/api/client_server/alias.rs @@ -15,7 +15,7 @@ use ruma::{ /// # `PUT /_matrix/client/r0/directory/room/{roomAlias}` /// /// Creates a new room alias on this server. -pub async fn create_alias_route( +pub(crate) async fn create_alias_route( body: Ruma, ) -> Result { if body.room_alias.server_name() != services().globals.server_name() { @@ -66,7 +66,7 @@ pub async fn create_alias_route( /// /// - TODO: additional access control checks /// - TODO: Update canonical alias event -pub async fn delete_alias_route( +pub(crate) async fn delete_alias_route( body: Ruma, ) -> Result { if body.room_alias.server_name() != services().globals.server_name() { @@ -106,7 +106,7 @@ pub async fn delete_alias_route( /// Resolve an alias locally or over federation. /// /// - TODO: Suggest more servers to join via -pub async fn get_alias_route( +pub(crate) async fn get_alias_route( body: Ruma, ) -> Result { get_alias_helper(body.body.room_alias).await diff --git a/src/api/client_server/backup.rs b/src/api/client_server/backup.rs index 115cba7c..0f9c8082 100644 --- a/src/api/client_server/backup.rs +++ b/src/api/client_server/backup.rs @@ -13,7 +13,7 @@ use ruma::api::client::{ /// # `POST /_matrix/client/r0/room_keys/version` /// /// Creates a new backup. -pub async fn create_backup_version_route( +pub(crate) async fn create_backup_version_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -27,7 +27,7 @@ pub async fn create_backup_version_route( /// # `PUT /_matrix/client/r0/room_keys/version/{version}` /// /// Update information about an existing backup. Only `auth_data` can be modified. -pub async fn update_backup_version_route( +pub(crate) async fn update_backup_version_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -41,7 +41,7 @@ pub async fn update_backup_version_route( /// # `GET /_matrix/client/r0/room_keys/version` /// /// Get information about the latest backup version. -pub async fn get_latest_backup_info_route( +pub(crate) async fn get_latest_backup_info_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -65,7 +65,7 @@ pub async fn get_latest_backup_info_route( /// # `GET /_matrix/client/r0/room_keys/version` /// /// Get information about an existing backup. -pub async fn get_backup_info_route( +pub(crate) async fn get_backup_info_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -95,7 +95,7 @@ pub async fn get_backup_info_route( /// Delete an existing key backup. /// /// - Deletes both information about the backup, as well as all key data related to the backup -pub async fn delete_backup_version_route( +pub(crate) async fn delete_backup_version_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -114,7 +114,7 @@ pub async fn delete_backup_version_route( /// - Only manipulating the most recently created version of the backup is allowed /// - Adds the keys to the backup /// - Returns the new number of keys in this backup and the etag -pub async fn add_backup_keys_route( +pub(crate) async fn add_backup_keys_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -161,7 +161,7 @@ pub async fn add_backup_keys_route( /// - Only manipulating the most recently created version of the backup is allowed /// - Adds the keys to the backup /// - Returns the new number of keys in this backup and the etag -pub async fn add_backup_keys_for_room_route( +pub(crate) async fn add_backup_keys_for_room_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -206,7 +206,7 @@ pub async fn add_backup_keys_for_room_route( /// - Only manipulating the most recently created version of the backup is allowed /// - Adds the keys to the backup /// - Returns the new number of keys in this backup and the etag -pub async fn add_backup_keys_for_session_route( +pub(crate) async fn add_backup_keys_for_session_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -245,7 +245,7 @@ pub async fn add_backup_keys_for_session_route( /// # `GET /_matrix/client/r0/room_keys/keys` /// /// Retrieves all keys from the backup. -pub async fn get_backup_keys_route( +pub(crate) async fn get_backup_keys_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -258,7 +258,7 @@ pub async fn get_backup_keys_route( /// # `GET /_matrix/client/r0/room_keys/keys/{roomId}` /// /// Retrieves all keys from the backup for a given room. -pub async fn get_backup_keys_for_room_route( +pub(crate) async fn get_backup_keys_for_room_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -273,7 +273,7 @@ pub async fn get_backup_keys_for_room_route( /// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}` /// /// Retrieves a key from the backup. -pub async fn get_backup_keys_for_session_route( +pub(crate) async fn get_backup_keys_for_session_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -292,7 +292,7 @@ pub async fn get_backup_keys_for_session_route( /// # `DELETE /_matrix/client/r0/room_keys/keys` /// /// Delete the keys from the backup. -pub async fn delete_backup_keys_route( +pub(crate) async fn delete_backup_keys_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -315,7 +315,7 @@ pub async fn delete_backup_keys_route( /// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}` /// /// Delete the keys from the backup for a given room. -pub async fn delete_backup_keys_for_room_route( +pub(crate) async fn delete_backup_keys_for_room_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -338,7 +338,7 @@ pub async fn delete_backup_keys_for_room_route( /// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}` /// /// Delete a key from the backup. -pub async fn delete_backup_keys_for_session_route( +pub(crate) async fn delete_backup_keys_for_session_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/capabilities.rs b/src/api/client_server/capabilities.rs index 233e3c9c..f248d1b9 100644 --- a/src/api/client_server/capabilities.rs +++ b/src/api/client_server/capabilities.rs @@ -7,7 +7,7 @@ use std::collections::BTreeMap; /// # `GET /_matrix/client/r0/capabilities` /// /// Get information on the supported feature set and other relevent capabilities of this server. -pub async fn get_capabilities_route( +pub(crate) async fn get_capabilities_route( _body: Ruma, ) -> Result { let mut available = BTreeMap::new(); diff --git a/src/api/client_server/config.rs b/src/api/client_server/config.rs index 37279e35..c650de1f 100644 --- a/src/api/client_server/config.rs +++ b/src/api/client_server/config.rs @@ -16,7 +16,7 @@ use serde_json::{json, value::RawValue as RawJsonValue}; /// # `PUT /_matrix/client/r0/user/{userId}/account_data/{type}` /// /// Sets some account data for the sender user. -pub async fn set_global_account_data_route( +pub(crate) async fn set_global_account_data_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -42,7 +42,7 @@ pub async fn set_global_account_data_route( /// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}` /// /// Sets some room account data for the sender user. -pub async fn set_room_account_data_route( +pub(crate) async fn set_room_account_data_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -68,7 +68,7 @@ pub async fn set_room_account_data_route( /// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}` /// /// Gets some account data for the sender user. -pub async fn get_global_account_data_route( +pub(crate) async fn get_global_account_data_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -88,7 +88,7 @@ pub async fn get_global_account_data_route( /// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}` /// /// Gets some room account data for the sender user. -pub async fn get_room_account_data_route( +pub(crate) async fn get_room_account_data_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/context.rs b/src/api/client_server/context.rs index 8e193e6b..205ecc3a 100644 --- a/src/api/client_server/context.rs +++ b/src/api/client_server/context.rs @@ -12,7 +12,7 @@ use tracing::error; /// /// - Only works if the user is joined (TODO: always allow, but only show events if the user was /// joined, depending on history_visibility) -pub async fn get_context_route( +pub(crate) async fn get_context_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/device.rs b/src/api/client_server/device.rs index aba061b2..03f55d77 100644 --- a/src/api/client_server/device.rs +++ b/src/api/client_server/device.rs @@ -10,7 +10,7 @@ use super::SESSION_ID_LENGTH; /// # `GET /_matrix/client/r0/devices` /// /// Get metadata on all devices of the sender user. -pub async fn get_devices_route( +pub(crate) async fn get_devices_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -27,7 +27,7 @@ pub async fn get_devices_route( /// # `GET /_matrix/client/r0/devices/{deviceId}` /// /// Get metadata on a single device of the sender user. -pub async fn get_device_route( +pub(crate) async fn get_device_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -43,7 +43,7 @@ pub async fn get_device_route( /// # `PUT /_matrix/client/r0/devices/{deviceId}` /// /// Updates the metadata on a given device of the sender user. -pub async fn update_device_route( +pub(crate) async fn update_device_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -71,7 +71,7 @@ pub async fn update_device_route( /// - Deletes device metadata (device id, device display name, last seen ip, last seen ts) /// - Forgets to-device events /// - Triggers device list updates -pub async fn delete_device_route( +pub(crate) async fn delete_device_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -125,7 +125,7 @@ pub async fn delete_device_route( /// - Deletes device metadata (device id, device display name, last seen ip, last seen ts) /// - Forgets to-device events /// - Triggers device list updates -pub async fn delete_devices_route( +pub(crate) async fn delete_devices_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/directory.rs b/src/api/client_server/directory.rs index 50ae9f15..feba5ff3 100644 --- a/src/api/client_server/directory.rs +++ b/src/api/client_server/directory.rs @@ -33,7 +33,7 @@ use tracing::{error, info, warn}; /// Lists the public rooms on this server. /// /// - Rooms are ordered by the number of joined members -pub async fn get_public_rooms_filtered_route( +pub(crate) async fn get_public_rooms_filtered_route( body: Ruma, ) -> Result { get_public_rooms_filtered_helper( @@ -51,7 +51,7 @@ pub async fn get_public_rooms_filtered_route( /// Lists the public rooms on this server. /// /// - Rooms are ordered by the number of joined members -pub async fn get_public_rooms_route( +pub(crate) async fn get_public_rooms_route( body: Ruma, ) -> Result { let response = get_public_rooms_filtered_helper( @@ -76,7 +76,7 @@ pub async fn get_public_rooms_route( /// Sets the visibility of a given room in the room directory. /// /// - TODO: Access control checks -pub async fn set_room_visibility_route( +pub(crate) async fn set_room_visibility_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -106,7 +106,7 @@ pub async fn set_room_visibility_route( /// # `GET /_matrix/client/r0/directory/list/room/{roomId}` /// /// Gets the visibility of a given room in the room directory. -pub async fn get_room_visibility_route( +pub(crate) async fn get_room_visibility_route( body: Ruma, ) -> Result { if !services().rooms.metadata.exists(&body.room_id)? { diff --git a/src/api/client_server/filter.rs b/src/api/client_server/filter.rs index e9a359d6..5293a95e 100644 --- a/src/api/client_server/filter.rs +++ b/src/api/client_server/filter.rs @@ -9,7 +9,7 @@ use ruma::api::client::{ /// Loads a filter that was previously created. /// /// - A user can only access their own filters -pub async fn get_filter_route( +pub(crate) async fn get_filter_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -24,7 +24,7 @@ pub async fn get_filter_route( /// # `PUT /_matrix/client/r0/user/{userId}/filter` /// /// Creates a new filter to be used by other endpoints. -pub async fn create_filter_route( +pub(crate) async fn create_filter_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/keys.rs b/src/api/client_server/keys.rs index 4af8890d..3ea66d7d 100644 --- a/src/api/client_server/keys.rs +++ b/src/api/client_server/keys.rs @@ -29,7 +29,7 @@ use tracing::debug; /// /// - Adds one time keys /// - If there are no device keys yet: Adds device keys (TODO: merge with existing keys?) -pub async fn upload_keys_route( +pub(crate) async fn upload_keys_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -69,7 +69,9 @@ pub async fn upload_keys_route( /// - Always fetches users from other servers over federation /// - Gets master keys, self-signing keys, user signing keys and device keys. /// - The master and self-signing keys contain signatures that the user is allowed to see -pub async fn get_keys_route(body: Ruma) -> Result { +pub(crate) async fn get_keys_route( + body: Ruma, +) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let response = @@ -81,7 +83,7 @@ pub async fn get_keys_route(body: Ruma) -> Result, ) -> Result { let response = claim_keys_helper(&body.one_time_keys).await?; @@ -94,7 +96,7 @@ pub async fn claim_keys_route( /// Uploads end-to-end key information for the sender user. /// /// - Requires UIAA to verify password -pub async fn upload_signing_keys_route( +pub(crate) async fn upload_signing_keys_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -146,7 +148,7 @@ pub async fn upload_signing_keys_route( /// # `POST /_matrix/client/r0/keys/signatures/upload` /// /// Uploads end-to-end key signatures from the sender user. -pub async fn upload_signatures_route( +pub(crate) async fn upload_signatures_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -204,7 +206,7 @@ pub async fn upload_signatures_route( /// Gets a list of users who have updated their device identity keys since the previous sync token. /// /// - TODO: left users -pub async fn get_key_changes_route( +pub(crate) async fn get_key_changes_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index 7fc65c26..62fe4c09 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -14,7 +14,7 @@ const MXC_LENGTH: usize = 32; /// # `GET /_matrix/media/r0/config` /// /// Returns max upload size. -pub async fn get_media_config_route( +pub(crate) async fn get_media_config_route( _body: Ruma, ) -> Result { Ok(get_media_config::v3::Response { @@ -28,7 +28,7 @@ pub async fn get_media_config_route( /// /// - Some metadata will be saved in the database /// - Media will be saved in the media/ directory -pub async fn create_content_route( +pub(crate) async fn create_content_route( body: Ruma, ) -> Result { let mxc = format!( @@ -56,7 +56,7 @@ pub async fn create_content_route( }) } -pub async fn get_remote_content( +pub(crate) async fn get_remote_content( mxc: &str, server_name: &ruma::ServerName, media_id: String, @@ -93,7 +93,7 @@ pub async fn get_remote_content( /// Load media from our server or over federation. /// /// - Only allows federation if `allow_remote` is true -pub async fn get_content_route( +pub(crate) async fn get_content_route( body: Ruma, ) -> Result { let mxc = format!("mxc://{}/{}", body.server_name, body.media_id); @@ -124,7 +124,7 @@ pub async fn get_content_route( /// Load media from our server or over federation, permitting desired filename. /// /// - Only allows federation if `allow_remote` is true -pub async fn get_content_as_filename_route( +pub(crate) async fn get_content_as_filename_route( body: Ruma, ) -> Result { let mxc = format!("mxc://{}/{}", body.server_name, body.media_id); @@ -161,7 +161,7 @@ pub async fn get_content_as_filename_route( /// Load media thumbnail from our server or over federation. /// /// - Only allows federation if `allow_remote` is true -pub async fn get_content_thumbnail_route( +pub(crate) async fn get_content_thumbnail_route( body: Ruma, ) -> Result { let mxc = format!("mxc://{}/{}", body.server_name, body.media_id); diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 6fe1e0ea..bc98c00b 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -44,7 +44,7 @@ use super::get_alias_helper; /// /// - If the server knowns about this room: creates the join event and does auth rules locally /// - If the server does not know about the room: asks other servers over federation -pub async fn join_room_by_id_route( +pub(crate) async fn join_room_by_id_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -87,7 +87,7 @@ pub async fn join_room_by_id_route( /// /// - If the server knowns about this room: creates the join event and does auth rules locally /// - If the server does not know about the room: asks other servers over federation -pub async fn join_room_by_id_or_alias_route( +pub(crate) async fn join_room_by_id_or_alias_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_deref().expect("user is authenticated"); @@ -145,7 +145,7 @@ pub async fn join_room_by_id_or_alias_route( /// Tries to leave the sender user from a room. /// /// - This should always work if the user is currently joined. -pub async fn leave_room_route( +pub(crate) async fn leave_room_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -158,7 +158,7 @@ pub async fn leave_room_route( /// # `POST /_matrix/client/r0/rooms/{roomId}/invite` /// /// Tries to send an invite event into the room. -pub async fn invite_user_route( +pub(crate) async fn invite_user_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -181,7 +181,7 @@ pub async fn invite_user_route( /// # `POST /_matrix/client/r0/rooms/{roomId}/kick` /// /// Tries to send a kick event into the room. -pub async fn kick_user_route( +pub(crate) async fn kick_user_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -251,7 +251,9 @@ pub async fn kick_user_route( /// # `POST /_matrix/client/r0/rooms/{roomId}/ban` /// /// Tries to send a ban event into the room. -pub async fn ban_user_route(body: Ruma) -> Result { +pub(crate) async fn ban_user_route( + body: Ruma, +) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); if let Ok(Some(membership_event)) = services() @@ -330,7 +332,7 @@ pub async fn ban_user_route(body: Ruma) -> Result, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -407,7 +409,7 @@ pub async fn unban_user_route( /// /// Note: Other devices of the user have no way of knowing the room was forgotten, so this has to /// be called from every device -pub async fn forget_room_route( +pub(crate) async fn forget_room_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -423,7 +425,7 @@ pub async fn forget_room_route( /// # `POST /_matrix/client/r0/joined_rooms` /// /// Lists all rooms the user has joined. -pub async fn joined_rooms_route( +pub(crate) async fn joined_rooms_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -443,7 +445,7 @@ pub async fn joined_rooms_route( /// Lists all joined users in a room (TODO: at a specific point in time, with a specific membership). /// /// - Only works if the user is currently joined -pub async fn get_member_events_route( +pub(crate) async fn get_member_events_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -478,7 +480,7 @@ pub async fn get_member_events_route( /// /// - The sender user must be in the room /// - TODO: An appservice just needs a puppet joined -pub async fn joined_members_route( +pub(crate) async fn joined_members_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -1378,7 +1380,7 @@ pub(crate) async fn invite_helper<'a>( } // Make a user leave all their joined rooms -pub async fn leave_all_rooms(user_id: &UserId) -> Result<()> { +pub(crate) async fn leave_all_rooms(user_id: &UserId) -> Result<()> { let all_rooms = services() .rooms .state_cache @@ -1404,7 +1406,11 @@ pub async fn leave_all_rooms(user_id: &UserId) -> Result<()> { Ok(()) } -pub async fn leave_room(user_id: &UserId, room_id: &RoomId, reason: Option) -> Result<()> { +pub(crate) async fn leave_room( + user_id: &UserId, + room_id: &RoomId, + reason: Option, +) -> Result<()> { // Ask a remote server if we don't have this room if !services() .rooms diff --git a/src/api/client_server/message.rs b/src/api/client_server/message.rs index 89f33591..36890cab 100644 --- a/src/api/client_server/message.rs +++ b/src/api/client_server/message.rs @@ -21,7 +21,7 @@ use std::{ /// - Is a NOOP if the txn id was already used before and returns the same event id again /// - The only requirement for the content is that it has to be valid json /// - Tries to send the event into the room, auth rules will determine if it is allowed -pub async fn send_message_event_route( +pub(crate) async fn send_message_event_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -111,7 +111,7 @@ pub async fn send_message_event_route( /// /// - Only works if the user is joined (TODO: always allow, but only show events where the user was /// joined, depending on history_visibility) -pub async fn get_message_events_route( +pub(crate) async fn get_message_events_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/profile.rs b/src/api/client_server/profile.rs index f1500439..eafa726f 100644 --- a/src/api/client_server/profile.rs +++ b/src/api/client_server/profile.rs @@ -19,7 +19,7 @@ use std::sync::Arc; /// Updates the displayname. /// /// - Also makes sure other users receive the update using presence EDUs -pub async fn set_displayname_route( +pub(crate) async fn set_displayname_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -99,7 +99,7 @@ pub async fn set_displayname_route( /// Returns the displayname of the user. /// /// - If user is on another server: Fetches displayname over federation -pub async fn get_displayname_route( +pub(crate) async fn get_displayname_route( body: Ruma, ) -> Result { if body.user_id.server_name() != services().globals.server_name() { @@ -129,7 +129,7 @@ pub async fn get_displayname_route( /// Updates the avatar_url and blurhash. /// /// - Also makes sure other users receive the update using presence EDUs -pub async fn set_avatar_url_route( +pub(crate) async fn set_avatar_url_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -213,7 +213,7 @@ pub async fn set_avatar_url_route( /// Returns the avatar_url and blurhash of the user. /// /// - If user is on another server: Fetches avatar_url and blurhash over federation -pub async fn get_avatar_url_route( +pub(crate) async fn get_avatar_url_route( body: Ruma, ) -> Result { if body.user_id.server_name() != services().globals.server_name() { @@ -245,7 +245,7 @@ pub async fn get_avatar_url_route( /// Returns the displayname, avatar_url and blurhash of the user. /// /// - If user is on another server: Fetches profile over federation -pub async fn get_profile_route( +pub(crate) async fn get_profile_route( body: Ruma, ) -> Result { if body.user_id.server_name() != services().globals.server_name() { diff --git a/src/api/client_server/push.rs b/src/api/client_server/push.rs index 72768662..cdb8cb82 100644 --- a/src/api/client_server/push.rs +++ b/src/api/client_server/push.rs @@ -15,7 +15,7 @@ use ruma::{ /// # `GET /_matrix/client/r0/pushrules` /// /// Retrieves the push rules event for this user. -pub async fn get_pushrules_all_route( +pub(crate) async fn get_pushrules_all_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -44,7 +44,7 @@ pub async fn get_pushrules_all_route( /// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}` /// /// Retrieves a single specified push rule for this user. -pub async fn get_pushrule_route( +pub(crate) async fn get_pushrule_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -83,7 +83,7 @@ pub async fn get_pushrule_route( /// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}` /// /// Creates a single specified push rule for this user. -pub async fn set_pushrule_route( +pub(crate) async fn set_pushrule_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -156,7 +156,7 @@ pub async fn set_pushrule_route( /// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions` /// /// Gets the actions of a single specified push rule for this user. -pub async fn get_pushrule_actions_route( +pub(crate) async fn get_pushrule_actions_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -199,7 +199,7 @@ pub async fn get_pushrule_actions_route( /// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions` /// /// Sets the actions of a single specified push rule for this user. -pub async fn set_pushrule_actions_route( +pub(crate) async fn set_pushrule_actions_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -251,7 +251,7 @@ pub async fn set_pushrule_actions_route( /// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled` /// /// Gets the enabled status of a single specified push rule for this user. -pub async fn get_pushrule_enabled_route( +pub(crate) async fn get_pushrule_enabled_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -293,7 +293,7 @@ pub async fn get_pushrule_enabled_route( /// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled` /// /// Sets the enabled status of a single specified push rule for this user. -pub async fn set_pushrule_enabled_route( +pub(crate) async fn set_pushrule_enabled_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -345,7 +345,7 @@ pub async fn set_pushrule_enabled_route( /// # `DELETE /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}` /// /// Deletes a single specified push rule for this user. -pub async fn delete_pushrule_route( +pub(crate) async fn delete_pushrule_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -404,7 +404,7 @@ pub async fn delete_pushrule_route( /// # `GET /_matrix/client/r0/pushers` /// /// Gets all currently active pushers for the sender user. -pub async fn get_pushers_route( +pub(crate) async fn get_pushers_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -419,7 +419,7 @@ pub async fn get_pushers_route( /// Adds a pusher for the sender user. /// /// - TODO: Handle `append` -pub async fn set_pushers_route( +pub(crate) async fn set_pushers_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/read_marker.rs b/src/api/client_server/read_marker.rs index a5553d25..fb614bc9 100644 --- a/src/api/client_server/read_marker.rs +++ b/src/api/client_server/read_marker.rs @@ -15,7 +15,7 @@ use std::collections::BTreeMap; /// /// - Updates fully-read account data event to `fully_read` /// - If `read_receipt` is set: Update private marker and public read receipt EDU -pub async fn set_read_marker_route( +pub(crate) async fn set_read_marker_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -98,7 +98,7 @@ pub async fn set_read_marker_route( /// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}` /// /// Sets private read marker and public read receipt EDU. -pub async fn create_receipt_route( +pub(crate) async fn create_receipt_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/redact.rs b/src/api/client_server/redact.rs index f0603f4b..0f774dd9 100644 --- a/src/api/client_server/redact.rs +++ b/src/api/client_server/redact.rs @@ -13,7 +13,7 @@ use serde_json::value::to_raw_value; /// Tries to send a redaction event into the room. /// /// - TODO: Handle txn id -pub async fn redact_event_route( +pub(crate) async fn redact_event_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/relations.rs b/src/api/client_server/relations.rs index 124f1310..abf3ea70 100644 --- a/src/api/client_server/relations.rs +++ b/src/api/client_server/relations.rs @@ -6,7 +6,7 @@ use ruma::api::client::relations::{ use crate::{service::rooms::timeline::PduCount, services, Result, Ruma}; /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}` -pub async fn get_relating_events_with_rel_type_and_event_type_route( +pub(crate) async fn get_relating_events_with_rel_type_and_event_type_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -56,7 +56,7 @@ pub async fn get_relating_events_with_rel_type_and_event_type_route( } /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}` -pub async fn get_relating_events_with_rel_type_route( +pub(crate) async fn get_relating_events_with_rel_type_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -104,7 +104,7 @@ pub async fn get_relating_events_with_rel_type_route( } /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}` -pub async fn get_relating_events_route( +pub(crate) async fn get_relating_events_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/report.rs b/src/api/client_server/report.rs index ab5027cd..8e7dbed2 100644 --- a/src/api/client_server/report.rs +++ b/src/api/client_server/report.rs @@ -9,7 +9,7 @@ use ruma::{ /// /// Reports an inappropriate event to homeserver admins /// -pub async fn report_event_route( +pub(crate) async fn report_event_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/room.rs b/src/api/client_server/room.rs index e3e8a746..f1f67076 100644 --- a/src/api/client_server/room.rs +++ b/src/api/client_server/room.rs @@ -45,7 +45,7 @@ use tracing::{info, warn}; /// - Send events listed in initial state /// - Send events implied by `name` and `topic` /// - Send invite events -pub async fn create_room_route( +pub(crate) async fn create_room_route( body: Ruma, ) -> Result { use create_room::v3::RoomPreset; @@ -502,7 +502,7 @@ pub async fn create_room_route( /// Gets a single event. /// /// - You have to currently be joined to the room (TODO: Respect history visibility) -pub async fn get_room_event_route( +pub(crate) async fn get_room_event_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -540,7 +540,7 @@ pub async fn get_room_event_route( /// Lists all aliases of the room. /// /// - Only users joined to the room are allowed to call this TODO: Allow any user to call it if history_visibility is world readable -pub async fn get_room_aliases_route( +pub(crate) async fn get_room_aliases_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -576,7 +576,7 @@ pub async fn get_room_aliases_route( /// - Transfers some state events /// - Moves local aliases /// - Modifies old room power levels to prevent users from speaking -pub async fn upgrade_room_route( +pub(crate) async fn upgrade_room_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/search.rs b/src/api/client_server/search.rs index e9fac365..1fb70253 100644 --- a/src/api/client_server/search.rs +++ b/src/api/client_server/search.rs @@ -14,7 +14,7 @@ use std::collections::BTreeMap; /// Searches rooms for messages. /// /// - Only works if the user is currently joined to the room (TODO: Respect history visibility) -pub async fn search_events_route( +pub(crate) async fn search_events_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/session.rs b/src/api/client_server/session.rs index 3e583fac..d18d384a 100644 --- a/src/api/client_server/session.rs +++ b/src/api/client_server/session.rs @@ -21,7 +21,7 @@ struct Claims { /// /// Get the supported login types of this server. One of these should be used as the `type` field /// when logging in. -pub async fn get_login_types_route( +pub(crate) async fn get_login_types_route( _body: Ruma, ) -> Result { Ok(get_login_types::v3::Response::new(vec![ @@ -41,7 +41,7 @@ pub async fn get_login_types_route( /// /// Note: You can use [`GET /_matrix/client/r0/login`](fn.get_supported_versions_route.html) to see /// supported login types. -pub async fn login_route(body: Ruma) -> Result { +pub(crate) async fn login_route(body: Ruma) -> Result { // To allow deprecated login methods #![allow(deprecated)] // Validate login method @@ -223,7 +223,7 @@ pub async fn login_route(body: Ruma) -> Result) -> Result { +pub(crate) async fn logout_route(body: Ruma) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_device = body.sender_device.as_ref().expect("user is authenticated"); @@ -252,7 +252,7 @@ pub async fn logout_route(body: Ruma) -> Result, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/space.rs b/src/api/client_server/space.rs index e2ea8c34..ffbd5b8d 100644 --- a/src/api/client_server/space.rs +++ b/src/api/client_server/space.rs @@ -4,7 +4,7 @@ use ruma::api::client::space::get_hierarchy; /// # `GET /_matrix/client/v1/rooms/{room_id}/hierarchy`` /// /// Paginates over the space tree in a depth-first manner to locate child rooms of a given space. -pub async fn get_hierarchy_route( +pub(crate) async fn get_hierarchy_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/state.rs b/src/api/client_server/state.rs index e62aa013..97d9821e 100644 --- a/src/api/client_server/state.rs +++ b/src/api/client_server/state.rs @@ -21,7 +21,7 @@ use tracing::log::warn; /// - The only requirement for the content is that it has to be valid json /// - Tries to send the event into the room, auth rules will determine if it is allowed /// - If event is new canonical_alias: Rejects if alias is incorrect -pub async fn send_state_event_for_key_route( +pub(crate) async fn send_state_event_for_key_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -46,7 +46,7 @@ pub async fn send_state_event_for_key_route( /// - The only requirement for the content is that it has to be valid json /// - Tries to send the event into the room, auth rules will determine if it is allowed /// - If event is new canonical_alias: Rejects if alias is incorrect -pub async fn send_state_event_for_empty_key_route( +pub(crate) async fn send_state_event_for_empty_key_route( body: Ruma, ) -> Result> { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -77,7 +77,7 @@ pub async fn send_state_event_for_empty_key_route( /// Get all state events for a room. /// /// - If not joined: Only works if current room history visibility is world readable -pub async fn get_state_events_route( +pub(crate) async fn get_state_events_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -110,7 +110,7 @@ pub async fn get_state_events_route( /// Get single state event of a room. /// /// - If not joined: Only works if current room history visibility is world readable -pub async fn get_state_events_for_key_route( +pub(crate) async fn get_state_events_for_key_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -149,7 +149,7 @@ pub async fn get_state_events_for_key_route( /// Get single state event of a room. /// /// - If not joined: Only works if current room history visibility is world readable -pub async fn get_state_events_for_empty_key_route( +pub(crate) async fn get_state_events_for_empty_key_route( body: Ruma, ) -> Result> { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index e561c320..e10563f4 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -65,7 +65,7 @@ use tracing::{error, info}; /// /// - Sync is handled in an async task, multiple requests from the same device with the same /// `since` will be cached -pub async fn sync_events_route( +pub(crate) async fn sync_events_route( body: Ruma, ) -> Result> { let sender_user = body.sender_user.expect("user is authenticated"); @@ -1180,7 +1180,7 @@ fn share_encrypted_room( .any(|encrypted| encrypted)) } -pub async fn sync_events_v4_route( +pub(crate) async fn sync_events_v4_route( body: Ruma, ) -> Result> { let sender_user = body.sender_user.expect("user is authenticated"); diff --git a/src/api/client_server/tag.rs b/src/api/client_server/tag.rs index 16f1600f..4c333821 100644 --- a/src/api/client_server/tag.rs +++ b/src/api/client_server/tag.rs @@ -13,7 +13,7 @@ use std::collections::BTreeMap; /// Adds a tag to the room. /// /// - Inserts the tag into the tag event of the room account data. -pub async fn update_tag_route( +pub(crate) async fn update_tag_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -57,7 +57,7 @@ pub async fn update_tag_route( /// Deletes a tag from the room. /// /// - Removes the tag from the tag event of the room account data. -pub async fn delete_tag_route( +pub(crate) async fn delete_tag_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); @@ -98,7 +98,9 @@ pub async fn delete_tag_route( /// Returns tags on the room. /// /// - Gets the tag event of the room account data. -pub async fn get_tags_route(body: Ruma) -> Result { +pub(crate) async fn get_tags_route( + body: Ruma, +) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let event = services().account_data.get( diff --git a/src/api/client_server/thirdparty.rs b/src/api/client_server/thirdparty.rs index c2c1adfd..3c678acf 100644 --- a/src/api/client_server/thirdparty.rs +++ b/src/api/client_server/thirdparty.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; /// # `GET /_matrix/client/r0/thirdparty/protocols` /// /// TODO: Fetches all metadata about protocols supported by the homeserver. -pub async fn get_protocols_route( +pub(crate) async fn get_protocols_route( _body: Ruma, ) -> Result { // TODO diff --git a/src/api/client_server/threads.rs b/src/api/client_server/threads.rs index a095b420..6c93644a 100644 --- a/src/api/client_server/threads.rs +++ b/src/api/client_server/threads.rs @@ -3,7 +3,7 @@ use ruma::api::client::{error::ErrorKind, threads::get_threads}; use crate::{services, Error, Result, Ruma}; /// # `GET /_matrix/client/r0/rooms/{roomId}/threads` -pub async fn get_threads_route( +pub(crate) async fn get_threads_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/to_device.rs b/src/api/client_server/to_device.rs index 31590fc7..bfa79631 100644 --- a/src/api/client_server/to_device.rs +++ b/src/api/client_server/to_device.rs @@ -12,7 +12,7 @@ use ruma::{ /// # `PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}` /// /// Send a to-device event to a set of client devices. -pub async fn send_event_to_device_route( +pub(crate) async fn send_event_to_device_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/typing.rs b/src/api/client_server/typing.rs index e9e93708..7a3dd5c9 100644 --- a/src/api/client_server/typing.rs +++ b/src/api/client_server/typing.rs @@ -4,7 +4,7 @@ use ruma::api::client::{error::ErrorKind, typing::create_typing_event}; /// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}` /// /// Sets the typing state of the sender user. -pub async fn create_typing_event_route( +pub(crate) async fn create_typing_event_route( body: Ruma, ) -> Result { use create_typing_event::v3::Typing; diff --git a/src/api/client_server/unversioned.rs b/src/api/client_server/unversioned.rs index 70e260ec..81899b68 100644 --- a/src/api/client_server/unversioned.rs +++ b/src/api/client_server/unversioned.rs @@ -15,7 +15,7 @@ use crate::{services, Error, Result, Ruma}; /// /// Note: Unstable features are used while developing new features. Clients should avoid using /// unstable features in their stable releases -pub async fn get_supported_versions_route( +pub(crate) async fn get_supported_versions_route( _body: Ruma, ) -> Result { let resp = get_supported_versions::Response { @@ -35,7 +35,7 @@ pub async fn get_supported_versions_route( } /// # `GET /.well-known/matrix/client` -pub async fn well_known_client_route( +pub(crate) async fn well_known_client_route( _body: Ruma, ) -> Result { let client_url = match services().globals.well_known_client() { diff --git a/src/api/client_server/user_directory.rs b/src/api/client_server/user_directory.rs index b4d11800..30f7686e 100644 --- a/src/api/client_server/user_directory.rs +++ b/src/api/client_server/user_directory.rs @@ -13,7 +13,7 @@ use ruma::{ /// /// - Hides any local users that aren't in any public rooms (i.e. those that have the join rule set to public) /// and don't share a room with the sender -pub async fn search_users_route( +pub(crate) async fn search_users_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/client_server/voip.rs b/src/api/client_server/voip.rs index f0d91f71..f7bce1a6 100644 --- a/src/api/client_server/voip.rs +++ b/src/api/client_server/voip.rs @@ -10,7 +10,7 @@ type HmacSha1 = Hmac; /// # `GET /_matrix/client/r0/voip/turnServer` /// /// TODO: Returns information about the recommended turn server. -pub async fn turn_server_route( +pub(crate) async fn turn_server_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); diff --git a/src/api/ruma_wrapper.rs b/src/api/ruma_wrapper.rs index 28659dfe..e3486a73 100644 --- a/src/api/ruma_wrapper.rs +++ b/src/api/ruma_wrapper.rs @@ -8,14 +8,14 @@ use std::ops::Deref; mod axum; /// Extractor for Ruma request structs -pub struct Ruma { - pub body: T, - pub sender_user: Option, - pub sender_device: Option, - pub sender_servername: Option, +pub(crate) struct Ruma { + pub(crate) body: T, + pub(crate) sender_user: Option, + pub(crate) sender_device: Option, + pub(crate) sender_servername: Option, // This is None when body is not a valid string - pub json_body: Option, - pub appservice_info: Option, + pub(crate) json_body: Option, + pub(crate) appservice_info: Option, } impl Deref for Ruma { @@ -27,7 +27,7 @@ impl Deref for Ruma { } #[derive(Clone)] -pub struct RumaResponse(pub T); +pub(crate) struct RumaResponse(pub(crate) T); impl From for RumaResponse { fn from(t: T) -> Self { diff --git a/src/api/server_server.rs b/src/api/server_server.rs index ad330c55..32a9b7f4 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -77,7 +77,7 @@ use tracing::{debug, error, warn}; /// # } /// ``` #[derive(Clone, Debug, PartialEq, Eq)] -pub enum FedDest { +pub(crate) enum FedDest { Literal(SocketAddr), Named(String, String), } @@ -524,7 +524,7 @@ async fn request_well_known(destination: &str) -> Option { /// # `GET /_matrix/federation/v1/version` /// /// Get version information on this server. -pub async fn get_server_version_route( +pub(crate) async fn get_server_version_route( _body: Ruma, ) -> Result { Ok(get_server_version::v1::Response { @@ -542,7 +542,7 @@ pub async fn get_server_version_route( /// - Matrix does not support invalidating public keys, so the key returned by this will be valid /// forever. // Response type for this endpoint is Json because we need to calculate a signature for the response -pub async fn get_server_keys_route() -> Result { +pub(crate) async fn get_server_keys_route() -> Result { let mut verify_keys: BTreeMap = BTreeMap::new(); verify_keys.insert( format!("ed25519:{}", services().globals.keypair().version()) @@ -588,14 +588,14 @@ pub async fn get_server_keys_route() -> Result { /// /// - Matrix does not support invalidating public keys, so the key returned by this will be valid /// forever. -pub async fn get_server_keys_deprecated_route() -> impl IntoResponse { +pub(crate) async fn get_server_keys_deprecated_route() -> impl IntoResponse { get_server_keys_route().await } /// # `POST /_matrix/federation/v1/publicRooms` /// /// Lists the public rooms on this server. -pub async fn get_public_rooms_filtered_route( +pub(crate) async fn get_public_rooms_filtered_route( body: Ruma, ) -> Result { let response = client_server::get_public_rooms_filtered_helper( @@ -618,7 +618,7 @@ pub async fn get_public_rooms_filtered_route( /// # `GET /_matrix/federation/v1/publicRooms` /// /// Lists the public rooms on this server. -pub async fn get_public_rooms_route( +pub(crate) async fn get_public_rooms_route( body: Ruma, ) -> Result { let response = client_server::get_public_rooms_filtered_helper( @@ -638,7 +638,7 @@ pub async fn get_public_rooms_route( }) } -pub fn parse_incoming_pdu( +pub(crate) fn parse_incoming_pdu( pdu: &RawJsonValue, ) -> Result<(OwnedEventId, CanonicalJsonObject, OwnedRoomId)> { let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| { @@ -672,7 +672,7 @@ pub fn parse_incoming_pdu( /// # `PUT /_matrix/federation/v1/send/{txnId}` /// /// Push EDUs and PDUs to this server. -pub async fn send_transaction_message_route( +pub(crate) async fn send_transaction_message_route( body: Ruma, ) -> Result { let sender_servername = body @@ -942,7 +942,7 @@ pub async fn send_transaction_message_route( /// Retrieves a single event from the server. /// /// - Only works if a user of this server is currently invited or joined the room -pub async fn get_event_route( +pub(crate) async fn get_event_route( body: Ruma, ) -> Result { let sender_servername = body @@ -1000,7 +1000,7 @@ pub async fn get_event_route( /// /// Retrieves events from before the sender joined the room, if the room's /// history visibility allows. -pub async fn get_backfill_route( +pub(crate) async fn get_backfill_route( body: Ruma, ) -> Result { let sender_servername = body @@ -1072,7 +1072,7 @@ pub async fn get_backfill_route( /// # `POST /_matrix/federation/v1/get_missing_events/{roomId}` /// /// Retrieves events that the sender is missing. -pub async fn get_missing_events_route( +pub(crate) async fn get_missing_events_route( body: Ruma, ) -> Result { let sender_servername = body @@ -1157,7 +1157,7 @@ pub async fn get_missing_events_route( /// Retrieves the auth chain for a given event. /// /// - This does not include the event itself -pub async fn get_event_authorization_route( +pub(crate) async fn get_event_authorization_route( body: Ruma, ) -> Result { let sender_servername = body @@ -1215,7 +1215,7 @@ pub async fn get_event_authorization_route( /// # `GET /_matrix/federation/v1/state/{roomId}` /// /// Retrieves the current state of the room. -pub async fn get_room_state_route( +pub(crate) async fn get_room_state_route( body: Ruma, ) -> Result { let sender_servername = body @@ -1291,7 +1291,7 @@ pub async fn get_room_state_route( /// # `GET /_matrix/federation/v1/state_ids/{roomId}` /// /// Retrieves the current state of the room. -pub async fn get_room_state_ids_route( +pub(crate) async fn get_room_state_ids_route( body: Ruma, ) -> Result { let sender_servername = body @@ -1348,7 +1348,7 @@ pub async fn get_room_state_ids_route( /// # `GET /_matrix/federation/v1/make_join/{roomId}/{userId}` /// /// Creates a join template. -pub async fn create_join_event_template_route( +pub(crate) async fn create_join_event_template_route( body: Ruma, ) -> Result { if !services().rooms.metadata.exists(&body.room_id)? { @@ -1592,7 +1592,7 @@ async fn create_join_event( /// # `PUT /_matrix/federation/v1/send_join/{roomId}/{eventId}` /// /// Submits a signed join event. -pub async fn create_join_event_v1_route( +pub(crate) async fn create_join_event_v1_route( body: Ruma, ) -> Result { let sender_servername = body @@ -1608,7 +1608,7 @@ pub async fn create_join_event_v1_route( /// # `PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}` /// /// Submits a signed join event. -pub async fn create_join_event_v2_route( +pub(crate) async fn create_join_event_v2_route( body: Ruma, ) -> Result { let sender_servername = body @@ -1635,7 +1635,7 @@ pub async fn create_join_event_v2_route( /// # `PUT /_matrix/federation/v2/invite/{roomId}/{eventId}` /// /// Invites a remote user to a room. -pub async fn create_invite_route( +pub(crate) async fn create_invite_route( body: Ruma, ) -> Result { let sender_servername = body @@ -1748,7 +1748,7 @@ pub async fn create_invite_route( /// # `GET /_matrix/federation/v1/user/devices/{userId}` /// /// Gets information on all devices of the user. -pub async fn get_devices_route( +pub(crate) async fn get_devices_route( body: Ruma, ) -> Result { if body.user_id.server_name() != services().globals.server_name() { @@ -1800,7 +1800,7 @@ pub async fn get_devices_route( /// # `GET /_matrix/federation/v1/query/directory` /// /// Resolve a room alias to a room id. -pub async fn get_room_information_route( +pub(crate) async fn get_room_information_route( body: Ruma, ) -> Result { let room_id = services() @@ -1821,7 +1821,7 @@ pub async fn get_room_information_route( /// # `GET /_matrix/federation/v1/query/profile` /// /// Gets information on a profile. -pub async fn get_profile_information_route( +pub(crate) async fn get_profile_information_route( body: Ruma, ) -> Result { if body.user_id.server_name() != services().globals.server_name() { @@ -1862,7 +1862,9 @@ pub async fn get_profile_information_route( /// # `POST /_matrix/federation/v1/user/keys/query` /// /// Gets devices and identity keys for the given users. -pub async fn get_keys_route(body: Ruma) -> Result { +pub(crate) async fn get_keys_route( + body: Ruma, +) -> Result { if body .device_keys .iter() @@ -1889,7 +1891,7 @@ pub async fn get_keys_route(body: Ruma) -> Result, ) -> Result { if body diff --git a/src/clap.rs b/src/clap.rs index 01563aee..7b7a420a 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -19,9 +19,9 @@ fn version() -> String { /// Command line arguments #[derive(Parser)] #[clap(about, version = version())] -pub struct Args {} +pub(crate) struct Args {} /// Parse command line arguments into structured data -pub fn parse() -> Args { +pub(crate) fn parse() -> Args { Args::parse() } diff --git a/src/config.rs b/src/config.rs index a000773f..449e91e4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,84 +13,84 @@ mod proxy; use self::proxy::ProxyConfig; #[derive(Clone, Debug, Deserialize)] -pub struct Config { +pub(crate) struct Config { #[serde(default = "default_address")] - pub address: IpAddr, + pub(crate) address: IpAddr, #[serde(default = "default_port")] - pub port: u16, - pub tls: Option, + pub(crate) port: u16, + pub(crate) tls: Option, - pub server_name: OwnedServerName, - pub database_backend: String, - pub database_path: String, + pub(crate) server_name: OwnedServerName, + pub(crate) database_backend: String, + pub(crate) database_path: String, #[serde(default = "default_db_cache_capacity_mb")] - pub db_cache_capacity_mb: f64, + pub(crate) db_cache_capacity_mb: f64, #[serde(default = "default_cache_capacity_modifier")] - pub cache_capacity_modifier: f64, + pub(crate) cache_capacity_modifier: f64, #[serde(default = "default_rocksdb_max_open_files")] - pub rocksdb_max_open_files: i32, + pub(crate) rocksdb_max_open_files: i32, #[serde(default = "default_pdu_cache_capacity")] - pub pdu_cache_capacity: u32, + pub(crate) pdu_cache_capacity: u32, #[serde(default = "default_cleanup_second_interval")] - pub cleanup_second_interval: u32, + pub(crate) cleanup_second_interval: u32, #[serde(default = "default_max_request_size")] - pub max_request_size: u32, + pub(crate) max_request_size: u32, #[serde(default = "default_max_concurrent_requests")] - pub max_concurrent_requests: u16, + pub(crate) max_concurrent_requests: u16, #[serde(default = "default_max_fetch_prev_events")] - pub max_fetch_prev_events: u16, + pub(crate) max_fetch_prev_events: u16, #[serde(default = "false_fn")] - pub allow_registration: bool, - pub registration_token: Option, + pub(crate) allow_registration: bool, + pub(crate) registration_token: Option, #[serde(default = "true_fn")] - pub allow_encryption: bool, + pub(crate) allow_encryption: bool, #[serde(default = "false_fn")] - pub allow_federation: bool, + pub(crate) allow_federation: bool, #[serde(default = "true_fn")] - pub allow_room_creation: bool, + pub(crate) allow_room_creation: bool, #[serde(default = "true_fn")] - pub allow_unstable_room_versions: bool, + pub(crate) allow_unstable_room_versions: bool, #[serde(default = "default_default_room_version")] - pub default_room_version: RoomVersionId, - pub well_known_client: Option, + pub(crate) default_room_version: RoomVersionId, + pub(crate) well_known_client: Option, #[serde(default = "false_fn")] - pub allow_jaeger: bool, + pub(crate) allow_jaeger: bool, #[serde(default = "false_fn")] - pub tracing_flame: bool, + pub(crate) tracing_flame: bool, #[serde(default)] - pub proxy: ProxyConfig, - pub jwt_secret: Option, + pub(crate) proxy: ProxyConfig, + pub(crate) jwt_secret: Option, #[serde(default = "default_trusted_servers")] - pub trusted_servers: Vec, + pub(crate) trusted_servers: Vec, #[serde(default = "default_log")] - pub log: String, + pub(crate) log: String, #[serde(default)] - pub turn_username: String, + pub(crate) turn_username: String, #[serde(default)] - pub turn_password: String, + pub(crate) turn_password: String, #[serde(default = "Vec::new")] - pub turn_uris: Vec, + pub(crate) turn_uris: Vec, #[serde(default)] - pub turn_secret: String, + pub(crate) turn_secret: String, #[serde(default = "default_turn_ttl")] - pub turn_ttl: u64, + pub(crate) turn_ttl: u64, - pub emergency_password: Option, + pub(crate) emergency_password: Option, #[serde(flatten)] - pub catchall: BTreeMap, + pub(crate) catchall: BTreeMap, } #[derive(Clone, Debug, Deserialize)] -pub struct TlsConfig { - pub certs: String, - pub key: String, +pub(crate) struct TlsConfig { + pub(crate) certs: String, + pub(crate) key: String, } const DEPRECATED_KEYS: &[&str] = &["cache_capacity"]; impl Config { - pub fn warn_deprecated(&self) { + pub(crate) fn warn_deprecated(&self) { let mut was_deprecated = false; for key in self .catchall @@ -259,6 +259,6 @@ fn default_turn_ttl() -> u64 { } // I know, it's a great name -pub fn default_default_room_version() -> RoomVersionId { +pub(crate) fn default_default_room_version() -> RoomVersionId { RoomVersionId::V10 } diff --git a/src/config/proxy.rs b/src/config/proxy.rs index c03463e7..bf725190 100644 --- a/src/config/proxy.rs +++ b/src/config/proxy.rs @@ -30,7 +30,7 @@ use crate::Result; #[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "snake_case")] #[derive(Default)] -pub enum ProxyConfig { +pub(crate) enum ProxyConfig { #[default] None, Global { @@ -40,7 +40,7 @@ pub enum ProxyConfig { ByDomain(Vec), } impl ProxyConfig { - pub fn to_proxy(&self) -> Result> { + pub(crate) fn to_proxy(&self) -> Result> { Ok(match self.clone() { ProxyConfig::None => None, ProxyConfig::Global { url } => Some(Proxy::all(url)?), @@ -52,7 +52,7 @@ impl ProxyConfig { } #[derive(Clone, Debug, Deserialize)] -pub struct PartialProxyConfig { +pub(crate) struct PartialProxyConfig { #[serde(deserialize_with = "crate::utils::deserialize_from_str")] url: Url, #[serde(default)] @@ -61,7 +61,7 @@ pub struct PartialProxyConfig { exclude: Vec, } impl PartialProxyConfig { - pub fn for_url(&self, url: &Url) -> Option<&Url> { + pub(crate) fn for_url(&self, url: &Url) -> Option<&Url> { let domain = url.domain()?; let mut included_because = None; // most specific reason it was included let mut excluded_because = None; // most specific reason it was excluded @@ -95,20 +95,20 @@ impl PartialProxyConfig { /// A domain name, that optionally allows a * as its first subdomain. #[derive(Clone, Debug)] -pub enum WildCardedDomain { +pub(crate) enum WildCardedDomain { WildCard, WildCarded(String), Exact(String), } impl WildCardedDomain { - pub fn matches(&self, domain: &str) -> bool { + pub(crate) fn matches(&self, domain: &str) -> bool { match self { WildCardedDomain::WildCard => true, WildCardedDomain::WildCarded(d) => domain.ends_with(d), WildCardedDomain::Exact(d) => domain == d, } } - pub fn more_specific_than(&self, other: &Self) -> bool { + pub(crate) fn more_specific_than(&self, other: &Self) -> bool { match (self, other) { (WildCardedDomain::WildCard, WildCardedDomain::WildCard) => false, (_, WildCardedDomain::WildCard) => true, diff --git a/src/database.rs b/src/database.rs index 6941b22b..0de879d4 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,5 +1,5 @@ -pub mod abstraction; -pub mod key_value; +pub(crate) mod abstraction; +pub(crate) mod key_value; use crate::{ service::rooms::timeline::PduCount, services, utils, Config, Error, PduEvent, Result, Services, @@ -29,14 +29,14 @@ use std::{ use tracing::{debug, error, info, warn}; -pub struct KeyValueDatabase { +pub(crate) struct KeyValueDatabase { _db: Arc, - //pub globals: globals::Globals, + //pub(crate) globals: globals::Globals, pub(super) global: Arc, pub(super) server_signingkeys: Arc, - //pub users: users::Users, + //pub(crate) users: users::Users, pub(super) userid_password: Arc, pub(super) userid_displayname: Arc, pub(super) userid_avatarurl: Arc, @@ -58,12 +58,12 @@ pub struct KeyValueDatabase { pub(super) todeviceid_events: Arc, // ToDeviceId = UserId + DeviceId + Count - //pub uiaa: uiaa::Uiaa, + //pub(crate) uiaa: uiaa::Uiaa, pub(super) userdevicesessionid_uiaainfo: Arc, // User-interactive authentication pub(super) userdevicesessionid_uiaarequest: RwLock>, - //pub edus: RoomEdus, + //pub(crate) edus: RoomEdus, pub(super) readreceiptid_readreceipt: Arc, // ReadReceiptId = RoomId + Count + UserId pub(super) roomuserid_privateread: Arc, // RoomUserId = Room + User, PrivateRead = Count pub(super) roomuserid_lastprivatereadupdate: Arc, // LastPrivateReadUpdate = Count @@ -74,7 +74,7 @@ pub struct KeyValueDatabase { #[allow(dead_code)] pub(super) userid_lastpresenceupdate: Arc, // LastPresenceUpdate = Count - //pub rooms: rooms::Rooms, + //pub(crate) rooms: rooms::Rooms, pub(super) pduid_pdu: Arc, // PduId = ShortRoomId + Count pub(super) eventid_pduid: Arc, pub(super) roomid_pduleaves: Arc, @@ -137,28 +137,28 @@ pub struct KeyValueDatabase { /// RoomId + EventId -> Parent PDU EventId. pub(super) referencedevents: Arc, - //pub account_data: account_data::AccountData, + //pub(crate) account_data: account_data::AccountData, pub(super) roomuserdataid_accountdata: Arc, // RoomUserDataId = Room + User + Count + Type pub(super) roomusertype_roomuserdataid: Arc, // RoomUserType = Room + User + Type - //pub media: media::Media, + //pub(crate) media: media::Media, pub(super) mediaid_file: Arc, // MediaId = MXC + WidthHeight + ContentDisposition + ContentType - //pub key_backups: key_backups::KeyBackups, + //pub(crate) key_backups: key_backups::KeyBackups, pub(super) backupid_algorithm: Arc, // BackupId = UserId + Version(Count) pub(super) backupid_etag: Arc, // BackupId = UserId + Version(Count) pub(super) backupkeyid_backup: Arc, // BackupKeyId = UserId + Version + RoomId + SessionId - //pub transaction_ids: transaction_ids::TransactionIds, + //pub(crate) transaction_ids: transaction_ids::TransactionIds, pub(super) userdevicetxnid_response: Arc, // Response can be empty (/sendToDevice) or the event id (/send) - //pub sending: sending::Sending, + //pub(crate) sending: sending::Sending, pub(super) servername_educount: Arc, // EduCount: Count of last EDU sync pub(super) servernameevent_data: Arc, // ServernameEvent = (+ / $)SenderKey / ServerName / UserId + PduId / Id (for edus), Data = EDU content pub(super) servercurrentevent_data: Arc, // ServerCurrentEvents = (+ / $)ServerName / UserId + PduId / Id (for edus), Data = EDU content - //pub appservice: appservice::Appservice, + //pub(crate) appservice: appservice::Appservice, pub(super) id_appserviceregistrations: Arc, - //pub pusher: pusher::PushData, + //pub(crate) pusher: pusher::PushData, pub(super) senderkey_pusher: Arc, pub(super) pdu_cache: Mutex>>, @@ -214,7 +214,7 @@ impl KeyValueDatabase { not(any(feature = "rocksdb", feature = "sqlite")), allow(unreachable_code) )] - pub async fn load_or_create(config: Config) -> Result<()> { + pub(crate) async fn load_or_create(config: Config) -> Result<()> { Self::check_db_setup(&config)?; if !Path::new(&config.database_path).exists() { @@ -959,7 +959,7 @@ impl KeyValueDatabase { } #[tracing::instrument(skip(self))] - pub fn flush(&self) -> Result<()> { + pub(crate) fn flush(&self) -> Result<()> { let start = std::time::Instant::now(); let res = self._db.flush(); @@ -970,7 +970,7 @@ impl KeyValueDatabase { } #[tracing::instrument] - pub async fn start_cleanup_task() { + pub(crate) async fn start_cleanup_task() { use tokio::time::interval; #[cfg(unix)] diff --git a/src/database/abstraction.rs b/src/database/abstraction.rs index 0e3829ba..3b64332e 100644 --- a/src/database/abstraction.rs +++ b/src/database/abstraction.rs @@ -4,15 +4,15 @@ use crate::Result; use std::{future::Future, pin::Pin, sync::Arc}; #[cfg(feature = "sqlite")] -pub mod sqlite; +pub(crate) mod sqlite; #[cfg(feature = "rocksdb")] -pub mod rocksdb; +pub(crate) mod rocksdb; #[cfg(any(feature = "sqlite", feature = "rocksdb",))] -pub mod watchers; +pub(crate) mod watchers; -pub trait KeyValueDatabaseEngine: Send + Sync { +pub(crate) trait KeyValueDatabaseEngine: Send + Sync { fn open(config: &Config) -> Result where Self: Sized; @@ -27,7 +27,7 @@ pub trait KeyValueDatabaseEngine: Send + Sync { fn clear_caches(&self) {} } -pub trait KvTree: Send + Sync { +pub(crate) trait KvTree: Send + Sync { fn get(&self, key: &[u8]) -> Result>>; fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>; diff --git a/src/database/abstraction/rocksdb.rs b/src/database/abstraction/rocksdb.rs index 447ee038..78e76524 100644 --- a/src/database/abstraction/rocksdb.rs +++ b/src/database/abstraction/rocksdb.rs @@ -6,14 +6,14 @@ use std::{ sync::{Arc, RwLock}, }; -pub struct Engine { +pub(crate) struct Engine { rocks: rocksdb::DBWithThreadMode, max_open_files: i32, cache: rocksdb::Cache, old_cfs: Vec, } -pub struct RocksDbEngineTree<'a> { +pub(crate) struct RocksDbEngineTree<'a> { db: Arc, name: &'a str, watchers: Watchers, diff --git a/src/database/abstraction/sqlite.rs b/src/database/abstraction/sqlite.rs index eae5e5c8..a5bfe540 100644 --- a/src/database/abstraction/sqlite.rs +++ b/src/database/abstraction/sqlite.rs @@ -18,8 +18,8 @@ thread_local! { } struct PreparedStatementIterator<'a> { - pub iterator: Box + 'a>, - pub _statement_ref: NonAliasingBox>, + pub(crate) iterator: Box + 'a>, + pub(crate) _statement_ref: NonAliasingBox>, } impl Iterator for PreparedStatementIterator<'_> { @@ -37,7 +37,7 @@ impl Drop for NonAliasingBox { } } -pub struct Engine { +pub(crate) struct Engine { writer: Mutex, read_conn_tls: ThreadLocal, read_iterator_conn_tls: ThreadLocal, @@ -73,7 +73,7 @@ impl Engine { .get_or(|| Self::prepare_conn(&self.path, self.cache_size_per_thread).unwrap()) } - pub fn flush_wal(self: &Arc) -> Result<()> { + pub(crate) fn flush_wal(self: &Arc) -> Result<()> { self.write_lock() .pragma_update(Some(Main), "wal_checkpoint", "RESTART")?; Ok(()) @@ -125,7 +125,7 @@ impl KeyValueDatabaseEngine for Arc { } } -pub struct SqliteTable { +pub(crate) struct SqliteTable { engine: Arc, name: String, watchers: Watchers, @@ -153,7 +153,7 @@ impl SqliteTable { Ok(()) } - pub fn iter_with_guard<'a>( + pub(crate) fn iter_with_guard<'a>( &'a self, guard: &'a Connection, ) -> Box + 'a> { diff --git a/src/database/key_value/globals.rs b/src/database/key_value/globals.rs index aa13e64f..1f47a445 100644 --- a/src/database/key_value/globals.rs +++ b/src/database/key_value/globals.rs @@ -11,7 +11,7 @@ use ruma::{ use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; -pub const COUNTER: &[u8] = b"c"; +pub(crate) const COUNTER: &[u8] = b"c"; #[async_trait] impl service::globals::Data for KeyValueDatabase { diff --git a/src/main.rs b/src/main.rs index d466c1c5..4b86b111 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,19 +38,19 @@ use tower_http::{ use tracing::{debug, error, info, warn}; use tracing_subscriber::{prelude::*, EnvFilter}; -pub mod api; -pub mod clap; +pub(crate) mod api; +pub(crate) mod clap; mod config; mod database; mod service; mod utils; -pub use api::ruma_wrapper::{Ruma, RumaResponse}; +pub(crate) use api::ruma_wrapper::{Ruma, RumaResponse}; use api::{client_server, server_server}; -pub use config::Config; -pub use database::KeyValueDatabase; -pub use service::{pdu::PduEvent, Services}; -pub use utils::error::{Error, Result}; +pub(crate) use config::Config; +pub(crate) use database::KeyValueDatabase; +pub(crate) use service::{pdu::PduEvent, Services}; +pub(crate) use utils::error::{Error, Result}; #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] use tikv_jemallocator::Jemalloc; @@ -59,12 +59,12 @@ use tikv_jemallocator::Jemalloc; #[global_allocator] static GLOBAL: Jemalloc = Jemalloc; -pub static SERVICES: RwLock> = RwLock::new(None); +pub(crate) static SERVICES: RwLock> = RwLock::new(None); // Not async due to services() being used in many closures, and async closures are not stable as of writing // This is the case for every other occurence of sync Mutex/RwLock, except for database related ones, where // the previous maintainer has asked to not modify those -pub fn services() -> &'static Services { +pub(crate) fn services() -> &'static Services { SERVICES .read() .unwrap() @@ -534,7 +534,7 @@ impl RouterExt for Router { } } -pub trait RumaHandler { +pub(crate) trait RumaHandler { // Can't transform to a handler without boxing or relying on the nightly-only // impl-trait-in-traits feature. Moving a small amount of extra logic into the trait // allows bypassing both. diff --git a/src/service.rs b/src/service.rs index 045168eb..4ab89c68 100644 --- a/src/service.rs +++ b/src/service.rs @@ -9,37 +9,37 @@ use tokio::sync::{broadcast, Mutex}; use crate::{Config, Result}; use tokio::sync::RwLock; -pub mod account_data; -pub mod admin; -pub mod appservice; -pub mod globals; -pub mod key_backups; -pub mod media; -pub mod pdu; -pub mod pusher; -pub mod rooms; -pub mod sending; -pub mod transaction_ids; -pub mod uiaa; -pub mod users; +pub(crate) mod account_data; +pub(crate) mod admin; +pub(crate) mod appservice; +pub(crate) mod globals; +pub(crate) mod key_backups; +pub(crate) mod media; +pub(crate) mod pdu; +pub(crate) mod pusher; +pub(crate) mod rooms; +pub(crate) mod sending; +pub(crate) mod transaction_ids; +pub(crate) mod uiaa; +pub(crate) mod users; -pub struct Services { - pub appservice: appservice::Service, - pub pusher: pusher::Service, - pub rooms: rooms::Service, - pub transaction_ids: transaction_ids::Service, - pub uiaa: uiaa::Service, - pub users: users::Service, - pub account_data: account_data::Service, - pub admin: Arc, - pub globals: globals::Service, - pub key_backups: key_backups::Service, - pub media: media::Service, - pub sending: Arc, +pub(crate) struct Services { + pub(crate) appservice: appservice::Service, + pub(crate) pusher: pusher::Service, + pub(crate) rooms: rooms::Service, + pub(crate) transaction_ids: transaction_ids::Service, + pub(crate) uiaa: uiaa::Service, + pub(crate) users: users::Service, + pub(crate) account_data: account_data::Service, + pub(crate) admin: Arc, + pub(crate) globals: globals::Service, + pub(crate) key_backups: key_backups::Service, + pub(crate) media: media::Service, + pub(crate) sending: Arc, } impl Services { - pub fn build< + pub(crate) fn build< D: appservice::Data + pusher::Data + rooms::Data diff --git a/src/service/account_data.rs b/src/service/account_data.rs index f9c49b1a..515b970e 100644 --- a/src/service/account_data.rs +++ b/src/service/account_data.rs @@ -1,6 +1,6 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use ruma::{ events::{AnyEphemeralRoomEvent, RoomAccountDataEventType}, @@ -12,14 +12,14 @@ use std::collections::HashMap; use crate::Result; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { /// Places one event in the account data of the user and removes the previous entry. #[tracing::instrument(skip(self, room_id, user_id, event_type, data))] - pub fn update( + pub(crate) fn update( &self, room_id: Option<&RoomId>, user_id: &UserId, @@ -31,7 +31,7 @@ impl Service { /// Searches the account data for a specific kind. #[tracing::instrument(skip(self, room_id, user_id, event_type))] - pub fn get( + pub(crate) fn get( &self, room_id: Option<&RoomId>, user_id: &UserId, @@ -42,7 +42,7 @@ impl Service { /// Returns all changes to the account data that happened after `since`. #[tracing::instrument(skip(self, room_id, user_id, since))] - pub fn changes_since( + pub(crate) fn changes_since( &self, room_id: Option<&RoomId>, user_id: &UserId, diff --git a/src/service/account_data/data.rs b/src/service/account_data/data.rs index c7c92981..92a17cab 100644 --- a/src/service/account_data/data.rs +++ b/src/service/account_data/data.rs @@ -7,7 +7,7 @@ use ruma::{ RoomId, UserId, }; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { /// Places one event in the account data of the user and removes the previous entry. fn update( &self, diff --git a/src/service/admin.rs b/src/service/admin.rs index 315dbdcf..f61938a1 100644 --- a/src/service/admin.rs +++ b/src/service/admin.rs @@ -181,18 +181,18 @@ enum AdminCommand { } #[derive(Debug)] -pub enum AdminRoomEvent { +pub(crate) enum AdminRoomEvent { ProcessMessage(String), SendMessage(RoomMessageEventContent), } -pub struct Service { - pub sender: mpsc::UnboundedSender, +pub(crate) struct Service { + pub(crate) sender: mpsc::UnboundedSender, receiver: Mutex>, } impl Service { - pub fn build() -> Arc { + pub(crate) fn build() -> Arc { let (sender, receiver) = mpsc::unbounded_channel(); Arc::new(Self { sender, @@ -200,7 +200,7 @@ impl Service { }) } - pub fn start_handler(self: &Arc) { + pub(crate) fn start_handler(self: &Arc) { let self2 = Arc::clone(self); tokio::spawn(async move { self2.handler().await; @@ -259,13 +259,13 @@ impl Service { } } - pub fn process_message(&self, room_message: String) { + pub(crate) fn process_message(&self, room_message: String) { self.sender .send(AdminRoomEvent::ProcessMessage(room_message)) .unwrap(); } - pub fn send_message(&self, message_content: RoomMessageEventContent) { + pub(crate) fn send_message(&self, message_content: RoomMessageEventContent) { self.sender .send(AdminRoomEvent::SendMessage(message_content)) .unwrap(); diff --git a/src/service/appservice.rs b/src/service/appservice.rs index 9db6609e..1d5346aa 100644 --- a/src/service/appservice.rs +++ b/src/service/appservice.rs @@ -2,7 +2,7 @@ mod data; use std::collections::BTreeMap; -pub use data::Data; +pub(crate) use data::Data; use futures_util::Future; use regex::RegexSet; @@ -16,14 +16,14 @@ use crate::{services, Result}; /// Compiled regular expressions for a namespace. #[derive(Clone, Debug)] -pub struct NamespaceRegex { - pub exclusive: Option, - pub non_exclusive: Option, +pub(crate) struct NamespaceRegex { + pub(crate) exclusive: Option, + pub(crate) non_exclusive: Option, } impl NamespaceRegex { /// Checks if this namespace has rights to a namespace - pub fn is_match(&self, heystack: &str) -> bool { + pub(crate) fn is_match(&self, heystack: &str) -> bool { if self.is_exclusive_match(heystack) { return true; } @@ -37,7 +37,7 @@ impl NamespaceRegex { } /// Checks if this namespace has exlusive rights to a namespace - pub fn is_exclusive_match(&self, heystack: &str) -> bool { + pub(crate) fn is_exclusive_match(&self, heystack: &str) -> bool { if let Some(exclusive) = &self.exclusive { if exclusive.is_match(heystack) { return true; @@ -79,20 +79,20 @@ impl TryFrom> for NamespaceRegex { /// Appservice registration combined with its compiled regular expressions. #[derive(Clone, Debug)] -pub struct RegistrationInfo { - pub registration: Registration, - pub users: NamespaceRegex, - pub aliases: NamespaceRegex, - pub rooms: NamespaceRegex, +pub(crate) struct RegistrationInfo { + pub(crate) registration: Registration, + pub(crate) users: NamespaceRegex, + pub(crate) aliases: NamespaceRegex, + pub(crate) rooms: NamespaceRegex, } impl RegistrationInfo { - pub fn is_user_match(&self, user_id: &UserId) -> bool { + pub(crate) fn is_user_match(&self, user_id: &UserId) -> bool { self.users.is_match(user_id.as_str()) || self.registration.sender_localpart == user_id.localpart() } - pub fn is_exclusive_user_match(&self, user_id: &UserId) -> bool { + pub(crate) fn is_exclusive_user_match(&self, user_id: &UserId) -> bool { self.users.is_exclusive_match(user_id.as_str()) || self.registration.sender_localpart == user_id.localpart() } @@ -111,13 +111,13 @@ impl TryFrom for RegistrationInfo { type Error = regex::Error; } -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, registration_info: RwLock>, } impl Service { - pub fn build(db: &'static dyn Data) -> Result { + pub(crate) fn build(db: &'static dyn Data) -> Result { let mut registration_info = BTreeMap::new(); // Inserting registrations into cache for appservice in db.all()? { @@ -136,7 +136,7 @@ impl Service { }) } /// Registers an appservice and returns the ID to the caller. - pub async fn register_appservice(&self, yaml: Registration) -> Result { + pub(crate) async fn register_appservice(&self, yaml: Registration) -> Result { //TODO: Check for collisions between exclusive appservice namespaces services() .appservice @@ -153,7 +153,7 @@ impl Service { /// # Arguments /// /// * `service_name` - the name you send to register the service previously - pub async fn unregister_appservice(&self, service_name: &str) -> Result<()> { + pub(crate) async fn unregister_appservice(&self, service_name: &str) -> Result<()> { services() .appservice .registration_info @@ -165,7 +165,7 @@ impl Service { self.db.unregister_appservice(service_name) } - pub async fn get_registration(&self, id: &str) -> Option { + pub(crate) async fn get_registration(&self, id: &str) -> Option { self.registration_info .read() .await @@ -174,7 +174,7 @@ impl Service { .map(|info| info.registration) } - pub async fn iter_ids(&self) -> Vec { + pub(crate) async fn iter_ids(&self) -> Vec { self.registration_info .read() .await @@ -183,7 +183,7 @@ impl Service { .collect() } - pub async fn find_from_token(&self, token: &str) -> Option { + pub(crate) async fn find_from_token(&self, token: &str) -> Option { self.read() .await .values() @@ -192,7 +192,7 @@ impl Service { } // Checks if a given user id matches any exclusive appservice regex - pub async fn is_exclusive_user_id(&self, user_id: &UserId) -> bool { + pub(crate) async fn is_exclusive_user_id(&self, user_id: &UserId) -> bool { self.read() .await .values() @@ -200,7 +200,7 @@ impl Service { } // Checks if a given room alias matches any exclusive appservice regex - pub async fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool { + pub(crate) async fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool { self.read() .await .values() @@ -208,14 +208,14 @@ impl Service { } // Checks if a given room id matches any exclusive appservice regex - pub async fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool { + pub(crate) async fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool { self.read() .await .values() .any(|info| info.rooms.is_exclusive_match(room_id.as_str())) } - pub fn read( + pub(crate) fn read( &self, ) -> impl Future>> { diff --git a/src/service/appservice/data.rs b/src/service/appservice/data.rs index ab19a50c..92da3a73 100644 --- a/src/service/appservice/data.rs +++ b/src/service/appservice/data.rs @@ -2,7 +2,7 @@ use ruma::api::appservice::Registration; use crate::Result; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { /// Registers an appservice and returns the ID to the caller fn register_appservice(&self, yaml: Registration) -> Result; diff --git a/src/service/globals.rs b/src/service/globals.rs index 6429a2af..d88dda3d 100644 --- a/src/service/globals.rs +++ b/src/service/globals.rs @@ -1,5 +1,5 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use ruma::{ serde::Base64, OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, @@ -49,46 +49,46 @@ type SyncHandle = ( Receiver>>, // rx ); -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, - pub actual_destination_cache: Arc>, // actual_destination, host - pub tls_name_override: Arc>, - pub config: Config, + pub(crate) actual_destination_cache: Arc>, // actual_destination, host + pub(crate) tls_name_override: Arc>, + pub(crate) config: Config, keypair: Arc, dns_resolver: TokioAsyncResolver, jwt_decoding_key: Option, federation_client: reqwest::Client, default_client: reqwest::Client, - pub stable_room_versions: Vec, - pub unstable_room_versions: Vec, - pub bad_event_ratelimiter: Arc>>, - pub bad_signature_ratelimiter: Arc, RateLimitState>>>, - pub bad_query_ratelimiter: Arc>>, - pub servername_ratelimiter: Arc>>>, - pub sync_receivers: RwLock>, - pub roomid_mutex_insert: RwLock>>>, - pub roomid_mutex_state: RwLock>>>, - pub roomid_mutex_federation: RwLock>>>, // this lock will be held longer - pub roomid_federationhandletime: RwLock>, - pub stateres_mutex: Arc>, - pub rotate: RotationHandler, + pub(crate) stable_room_versions: Vec, + pub(crate) unstable_room_versions: Vec, + pub(crate) bad_event_ratelimiter: Arc>>, + pub(crate) bad_signature_ratelimiter: Arc, RateLimitState>>>, + pub(crate) bad_query_ratelimiter: Arc>>, + pub(crate) servername_ratelimiter: Arc>>>, + pub(crate) sync_receivers: RwLock>, + pub(crate) roomid_mutex_insert: RwLock>>>, + pub(crate) roomid_mutex_state: RwLock>>>, + pub(crate) roomid_mutex_federation: RwLock>>>, // this lock will be held longer + pub(crate) roomid_federationhandletime: RwLock>, + pub(crate) stateres_mutex: Arc>, + pub(crate) rotate: RotationHandler, - pub shutdown: AtomicBool, + pub(crate) shutdown: AtomicBool, } /// Handles "rotation" of long-polling requests. "Rotation" in this context is similar to "rotation" of log files and the like. /// /// This is utilized to have sync workers return early and release read locks on the database. -pub struct RotationHandler(broadcast::Sender<()>, broadcast::Receiver<()>); +pub(crate) struct RotationHandler(broadcast::Sender<()>, broadcast::Receiver<()>); impl RotationHandler { - pub fn new() -> Self { + pub(crate) fn new() -> Self { let (s, r) = broadcast::channel(1); Self(s, r) } - pub fn watch(&self) -> impl Future { + pub(crate) fn watch(&self) -> impl Future { let mut r = self.0.subscribe(); async move { @@ -96,7 +96,7 @@ impl RotationHandler { } } - pub fn fire(&self) { + pub(crate) fn fire(&self) { let _ = self.0.send(()); } } @@ -107,13 +107,13 @@ impl Default for RotationHandler { } } -pub struct Resolver { +pub(crate) struct Resolver { inner: GaiResolver, overrides: Arc>, } impl Resolver { - pub fn new(overrides: Arc>) -> Self { + pub(crate) fn new(overrides: Arc>) -> Self { Resolver { inner: GaiResolver::new(), overrides, @@ -147,7 +147,7 @@ impl Resolve for Resolver { } impl Service { - pub fn load(db: &'static dyn Data, config: Config) -> Result { + pub(crate) fn load(db: &'static dyn Data, config: Config) -> Result { let keypair = db.load_keypair(); let keypair = match keypair { @@ -229,113 +229,113 @@ impl Service { } /// Returns this server's keypair. - pub fn keypair(&self) -> &ruma::signatures::Ed25519KeyPair { + pub(crate) fn keypair(&self) -> &ruma::signatures::Ed25519KeyPair { &self.keypair } /// Returns a reqwest client which can be used to send requests - pub fn default_client(&self) -> reqwest::Client { + pub(crate) fn default_client(&self) -> reqwest::Client { // Client is cheap to clone (Arc wrapper) and avoids lifetime issues self.default_client.clone() } /// Returns a client used for resolving .well-knowns - pub fn federation_client(&self) -> reqwest::Client { + pub(crate) fn federation_client(&self) -> reqwest::Client { // Client is cheap to clone (Arc wrapper) and avoids lifetime issues self.federation_client.clone() } #[tracing::instrument(skip(self))] - pub fn next_count(&self) -> Result { + pub(crate) fn next_count(&self) -> Result { self.db.next_count() } #[tracing::instrument(skip(self))] - pub fn current_count(&self) -> Result { + pub(crate) fn current_count(&self) -> Result { self.db.current_count() } - pub async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { + pub(crate) async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { self.db.watch(user_id, device_id).await } - pub fn cleanup(&self) -> Result<()> { + pub(crate) fn cleanup(&self) -> Result<()> { self.db.cleanup() } - pub fn server_name(&self) -> &ServerName { + pub(crate) fn server_name(&self) -> &ServerName { self.config.server_name.as_ref() } - pub fn max_request_size(&self) -> u32 { + pub(crate) fn max_request_size(&self) -> u32 { self.config.max_request_size } - pub fn max_fetch_prev_events(&self) -> u16 { + pub(crate) fn max_fetch_prev_events(&self) -> u16 { self.config.max_fetch_prev_events } - pub fn allow_registration(&self) -> bool { + pub(crate) fn allow_registration(&self) -> bool { self.config.allow_registration } - pub fn allow_encryption(&self) -> bool { + pub(crate) fn allow_encryption(&self) -> bool { self.config.allow_encryption } - pub fn allow_federation(&self) -> bool { + pub(crate) fn allow_federation(&self) -> bool { self.config.allow_federation } - pub fn allow_room_creation(&self) -> bool { + pub(crate) fn allow_room_creation(&self) -> bool { self.config.allow_room_creation } - pub fn allow_unstable_room_versions(&self) -> bool { + pub(crate) fn allow_unstable_room_versions(&self) -> bool { self.config.allow_unstable_room_versions } - pub fn default_room_version(&self) -> RoomVersionId { + pub(crate) fn default_room_version(&self) -> RoomVersionId { self.config.default_room_version.clone() } - pub fn trusted_servers(&self) -> &[OwnedServerName] { + pub(crate) fn trusted_servers(&self) -> &[OwnedServerName] { &self.config.trusted_servers } - pub fn dns_resolver(&self) -> &TokioAsyncResolver { + pub(crate) fn dns_resolver(&self) -> &TokioAsyncResolver { &self.dns_resolver } - pub fn jwt_decoding_key(&self) -> Option<&jsonwebtoken::DecodingKey> { + pub(crate) fn jwt_decoding_key(&self) -> Option<&jsonwebtoken::DecodingKey> { self.jwt_decoding_key.as_ref() } - pub fn turn_password(&self) -> &String { + pub(crate) fn turn_password(&self) -> &String { &self.config.turn_password } - pub fn turn_ttl(&self) -> u64 { + pub(crate) fn turn_ttl(&self) -> u64 { self.config.turn_ttl } - pub fn turn_uris(&self) -> &[String] { + pub(crate) fn turn_uris(&self) -> &[String] { &self.config.turn_uris } - pub fn turn_username(&self) -> &String { + pub(crate) fn turn_username(&self) -> &String { &self.config.turn_username } - pub fn turn_secret(&self) -> &String { + pub(crate) fn turn_secret(&self) -> &String { &self.config.turn_secret } - pub fn emergency_password(&self) -> &Option { + pub(crate) fn emergency_password(&self) -> &Option { &self.config.emergency_password } - pub fn supported_room_versions(&self) -> Vec { + pub(crate) fn supported_room_versions(&self) -> Vec { let mut room_versions: Vec = vec![]; room_versions.extend(self.stable_room_versions.clone()); if self.allow_unstable_room_versions() { @@ -348,7 +348,7 @@ impl Service { /// Remove the outdated keys and insert the new ones. /// /// This doesn't actually check that the keys provided are newer than the old set. - pub fn add_signing_key( + pub(crate) fn add_signing_key( &self, origin: &ServerName, new_keys: ServerSigningKeys, @@ -357,7 +357,7 @@ impl Service { } /// This returns an empty `Ok(BTreeMap<..>)` when there are no keys found for the server. - pub fn signing_keys_for( + pub(crate) fn signing_keys_for( &self, origin: &ServerName, ) -> Result> { @@ -376,22 +376,22 @@ impl Service { Ok(keys) } - pub fn database_version(&self) -> Result { + pub(crate) fn database_version(&self) -> Result { self.db.database_version() } - pub fn bump_database_version(&self, new_version: u64) -> Result<()> { + pub(crate) fn bump_database_version(&self, new_version: u64) -> Result<()> { self.db.bump_database_version(new_version) } - pub fn get_media_folder(&self) -> PathBuf { + pub(crate) fn get_media_folder(&self) -> PathBuf { let mut r = PathBuf::new(); r.push(self.config.database_path.clone()); r.push("media"); r } - pub fn get_media_file(&self, key: &[u8]) -> PathBuf { + pub(crate) fn get_media_file(&self, key: &[u8]) -> PathBuf { let mut r = PathBuf::new(); r.push(self.config.database_path.clone()); r.push("media"); @@ -399,11 +399,11 @@ impl Service { r } - pub fn well_known_client(&self) -> &Option { + pub(crate) fn well_known_client(&self) -> &Option { &self.config.well_known_client } - pub fn shutdown(&self) { + pub(crate) fn shutdown(&self) { self.shutdown.store(true, atomic::Ordering::Relaxed); // On shutdown info!(target: "shutdown-sync", "Received shutdown notification, notifying sync helpers..."); diff --git a/src/service/globals/data.rs b/src/service/globals/data.rs index 171b3fec..9d863ca9 100644 --- a/src/service/globals/data.rs +++ b/src/service/globals/data.rs @@ -10,7 +10,7 @@ use ruma::{ use crate::Result; #[async_trait] -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn next_count(&self) -> Result; fn current_count(&self) -> Result; async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()>; diff --git a/src/service/key_backups.rs b/src/service/key_backups.rs index 5fc52ced..542db640 100644 --- a/src/service/key_backups.rs +++ b/src/service/key_backups.rs @@ -1,5 +1,5 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use crate::Result; use ruma::{ @@ -9,12 +9,12 @@ use ruma::{ }; use std::collections::BTreeMap; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { - pub fn create_backup( + pub(crate) fn create_backup( &self, user_id: &UserId, backup_metadata: &Raw, @@ -22,11 +22,11 @@ impl Service { self.db.create_backup(user_id, backup_metadata) } - pub fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()> { + pub(crate) fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()> { self.db.delete_backup(user_id, version) } - pub fn update_backup( + pub(crate) fn update_backup( &self, user_id: &UserId, version: &str, @@ -35,18 +35,18 @@ impl Service { self.db.update_backup(user_id, version, backup_metadata) } - pub fn get_latest_backup_version(&self, user_id: &UserId) -> Result> { + pub(crate) fn get_latest_backup_version(&self, user_id: &UserId) -> Result> { self.db.get_latest_backup_version(user_id) } - pub fn get_latest_backup( + pub(crate) fn get_latest_backup( &self, user_id: &UserId, ) -> Result)>> { self.db.get_latest_backup(user_id) } - pub fn get_backup( + pub(crate) fn get_backup( &self, user_id: &UserId, version: &str, @@ -54,7 +54,7 @@ impl Service { self.db.get_backup(user_id, version) } - pub fn add_key( + pub(crate) fn add_key( &self, user_id: &UserId, version: &str, @@ -66,15 +66,15 @@ impl Service { .add_key(user_id, version, room_id, session_id, key_data) } - pub fn count_keys(&self, user_id: &UserId, version: &str) -> Result { + pub(crate) fn count_keys(&self, user_id: &UserId, version: &str) -> Result { self.db.count_keys(user_id, version) } - pub fn get_etag(&self, user_id: &UserId, version: &str) -> Result { + pub(crate) fn get_etag(&self, user_id: &UserId, version: &str) -> Result { self.db.get_etag(user_id, version) } - pub fn get_all( + pub(crate) fn get_all( &self, user_id: &UserId, version: &str, @@ -82,7 +82,7 @@ impl Service { self.db.get_all(user_id, version) } - pub fn get_room( + pub(crate) fn get_room( &self, user_id: &UserId, version: &str, @@ -91,7 +91,7 @@ impl Service { self.db.get_room(user_id, version, room_id) } - pub fn get_session( + pub(crate) fn get_session( &self, user_id: &UserId, version: &str, @@ -101,11 +101,11 @@ impl Service { self.db.get_session(user_id, version, room_id, session_id) } - pub fn delete_all_keys(&self, user_id: &UserId, version: &str) -> Result<()> { + pub(crate) fn delete_all_keys(&self, user_id: &UserId, version: &str) -> Result<()> { self.db.delete_all_keys(user_id, version) } - pub fn delete_room_keys( + pub(crate) fn delete_room_keys( &self, user_id: &UserId, version: &str, @@ -114,7 +114,7 @@ impl Service { self.db.delete_room_keys(user_id, version, room_id) } - pub fn delete_room_key( + pub(crate) fn delete_room_key( &self, user_id: &UserId, version: &str, diff --git a/src/service/key_backups/data.rs b/src/service/key_backups/data.rs index bf640015..c99fe1d6 100644 --- a/src/service/key_backups/data.rs +++ b/src/service/key_backups/data.rs @@ -7,7 +7,7 @@ use ruma::{ OwnedRoomId, RoomId, UserId, }; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn create_backup( &self, user_id: &UserId, diff --git a/src/service/media.rs b/src/service/media.rs index fc8fa569..9ecd2668 100644 --- a/src/service/media.rs +++ b/src/service/media.rs @@ -1,7 +1,7 @@ mod data; use std::io::Cursor; -pub use data::Data; +pub(crate) use data::Data; use crate::{services, Result}; use image::imageops::FilterType; @@ -11,19 +11,19 @@ use tokio::{ io::{AsyncReadExt, AsyncWriteExt, BufReader}, }; -pub struct FileMeta { - pub content_disposition: Option, - pub content_type: Option, - pub file: Vec, +pub(crate) struct FileMeta { + pub(crate) content_disposition: Option, + pub(crate) content_type: Option, + pub(crate) file: Vec, } -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { /// Uploads a file. - pub async fn create( + pub(crate) async fn create( &self, mxc: String, content_disposition: Option<&str>, @@ -43,7 +43,7 @@ impl Service { /// Uploads or replaces a file thumbnail. #[allow(clippy::too_many_arguments)] - pub async fn upload_thumbnail( + pub(crate) async fn upload_thumbnail( &self, mxc: String, content_disposition: Option<&str>, @@ -64,7 +64,7 @@ impl Service { } /// Downloads a file. - pub async fn get(&self, mxc: String) -> Result> { + pub(crate) async fn get(&self, mxc: String) -> Result> { if let Ok((content_disposition, content_type, key)) = self.db.search_file_metadata(mxc, 0, 0) { @@ -86,7 +86,7 @@ impl Service { /// Returns width, height of the thumbnail and whether it should be cropped. Returns None when /// the server should send the original file. - pub fn thumbnail_properties(&self, width: u32, height: u32) -> Option<(u32, u32, bool)> { + pub(crate) fn thumbnail_properties(&self, width: u32, height: u32) -> Option<(u32, u32, bool)> { match (width, height) { (0..=32, 0..=32) => Some((32, 32, true)), (0..=96, 0..=96) => Some((96, 96, true)), @@ -107,7 +107,7 @@ impl Service { /// - Server creates the thumbnail and sends it to the user /// /// For width,height <= 96 the server uses another thumbnailing algorithm which crops the image afterwards. - pub async fn get_thumbnail( + pub(crate) async fn get_thumbnail( &self, mxc: String, width: u32, diff --git a/src/service/media/data.rs b/src/service/media/data.rs index 75a682cb..ce2fc76c 100644 --- a/src/service/media/data.rs +++ b/src/service/media/data.rs @@ -1,6 +1,6 @@ use crate::Result; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn create_file_metadata( &self, mxc: String, diff --git a/src/service/pdu.rs b/src/service/pdu.rs index a51d7ec5..d535fc3f 100644 --- a/src/service/pdu.rs +++ b/src/service/pdu.rs @@ -21,37 +21,37 @@ use tracing::warn; /// Content hashes of a PDU. #[derive(Clone, Debug, Deserialize, Serialize)] -pub struct EventHash { +pub(crate) struct EventHash { /// The SHA-256 hash. - pub sha256: String, + pub(crate) sha256: String, } #[derive(Clone, Deserialize, Debug, Serialize)] -pub struct PduEvent { - pub event_id: Arc, - pub room_id: OwnedRoomId, - pub sender: OwnedUserId, - pub origin_server_ts: UInt, +pub(crate) struct PduEvent { + pub(crate) event_id: Arc, + pub(crate) room_id: OwnedRoomId, + pub(crate) sender: OwnedUserId, + pub(crate) origin_server_ts: UInt, #[serde(rename = "type")] - pub kind: TimelineEventType, - pub content: Box, + pub(crate) kind: TimelineEventType, + pub(crate) content: Box, #[serde(skip_serializing_if = "Option::is_none")] - pub state_key: Option, - pub prev_events: Vec>, - pub depth: UInt, - pub auth_events: Vec>, + pub(crate) state_key: Option, + pub(crate) prev_events: Vec>, + pub(crate) depth: UInt, + pub(crate) auth_events: Vec>, #[serde(skip_serializing_if = "Option::is_none")] - pub redacts: Option>, + pub(crate) redacts: Option>, #[serde(default, skip_serializing_if = "Option::is_none")] - pub unsigned: Option>, - pub hashes: EventHash, + pub(crate) unsigned: Option>, + pub(crate) hashes: EventHash, #[serde(default, skip_serializing_if = "Option::is_none")] - pub signatures: Option>, // BTreeMap, BTreeMap> + pub(crate) signatures: Option>, // BTreeMap, BTreeMap> } impl PduEvent { #[tracing::instrument(skip(self))] - pub fn redact( + pub(crate) fn redact( &mut self, room_version_id: RoomVersionId, reason: &PduEvent, @@ -72,7 +72,7 @@ impl PduEvent { Ok(()) } - pub fn remove_transaction_id(&mut self) -> crate::Result<()> { + pub(crate) fn remove_transaction_id(&mut self) -> crate::Result<()> { if let Some(unsigned) = &self.unsigned { let mut unsigned: BTreeMap> = serde_json::from_str(unsigned.get()) @@ -84,7 +84,7 @@ impl PduEvent { Ok(()) } - pub fn add_age(&mut self) -> crate::Result<()> { + pub(crate) fn add_age(&mut self) -> crate::Result<()> { let mut unsigned: BTreeMap> = self .unsigned .as_ref() @@ -109,7 +109,7 @@ impl PduEvent { /// > For improved compatibility with newer clients, servers should add a redacts property /// > to the content of m.room.redaction events in older room versions when serving /// > such events over the Client-Server API. - pub fn copy_redacts(&self) -> (Option>, Box) { + pub(crate) fn copy_redacts(&self) -> (Option>, Box) { if self.kind == TimelineEventType::RoomRedaction { if let Ok(mut content) = serde_json::from_str::(self.content.get()) @@ -130,7 +130,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub fn to_sync_room_event(&self) -> Raw { + pub(crate) fn to_sync_room_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); let mut json = json!({ "content": content, @@ -155,7 +155,7 @@ impl PduEvent { /// This only works for events that are also AnyRoomEvents. #[tracing::instrument(skip(self))] - pub fn to_any_event(&self) -> Raw { + pub(crate) fn to_any_event(&self) -> Raw { let mut json = json!({ "content": self.content, "type": self.kind, @@ -179,7 +179,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub fn to_room_event(&self) -> Raw { + pub(crate) fn to_room_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); let mut json = json!({ "content": content, @@ -204,7 +204,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub fn to_message_like_event(&self) -> Raw { + pub(crate) fn to_message_like_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); let mut json = json!({ "content": content, @@ -229,7 +229,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub fn to_state_event(&self) -> Raw { + pub(crate) fn to_state_event(&self) -> Raw { let mut json = json!({ "content": self.content, "type": self.kind, @@ -248,7 +248,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub fn to_sync_state_event(&self) -> Raw { + pub(crate) fn to_sync_state_event(&self) -> Raw { let mut json = json!({ "content": self.content, "type": self.kind, @@ -266,7 +266,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub fn to_stripped_state_event(&self) -> Raw { + pub(crate) fn to_stripped_state_event(&self) -> Raw { let json = json!({ "content": self.content, "type": self.kind, @@ -278,7 +278,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub fn to_stripped_spacechild_state_event(&self) -> Raw { + pub(crate) fn to_stripped_spacechild_state_event(&self) -> Raw { let json = json!({ "content": self.content, "type": self.kind, @@ -291,7 +291,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub fn to_member_event(&self) -> Raw> { + pub(crate) fn to_member_event(&self) -> Raw> { let mut json = json!({ "content": self.content, "type": self.kind, @@ -312,7 +312,7 @@ impl PduEvent { /// This does not return a full `Pdu` it is only to satisfy ruma's types. #[tracing::instrument] - pub fn convert_to_outgoing_federation_event( + pub(crate) fn convert_to_outgoing_federation_event( mut pdu_json: CanonicalJsonObject, ) -> Box { if let Some(unsigned) = pdu_json @@ -334,7 +334,7 @@ impl PduEvent { to_raw_value(&pdu_json).expect("CanonicalJson is valid serde_json::Value") } - pub fn from_id_val( + pub(crate) fn from_id_val( event_id: &EventId, mut json: CanonicalJsonObject, ) -> Result { @@ -436,11 +436,11 @@ pub(crate) fn gen_event_id_canonical_json( /// Build the start of a PDU in order to add it to the Database. #[derive(Debug, Deserialize)] -pub struct PduBuilder { +pub(crate) struct PduBuilder { #[serde(rename = "type")] - pub event_type: TimelineEventType, - pub content: Box, - pub unsigned: Option>, - pub state_key: Option, - pub redacts: Option>, + pub(crate) event_type: TimelineEventType, + pub(crate) content: Box, + pub(crate) unsigned: Option>, + pub(crate) state_key: Option, + pub(crate) redacts: Option>, } diff --git a/src/service/pusher.rs b/src/service/pusher.rs index 6ca86be7..1f7bf0a0 100644 --- a/src/service/pusher.rs +++ b/src/service/pusher.rs @@ -1,5 +1,5 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use ruma::{events::AnySyncTimelineEvent, push::PushConditionPowerLevelsCtx}; use crate::{services, Error, PduEvent, Result}; @@ -22,29 +22,33 @@ use ruma::{ use std::{fmt::Debug, mem}; use tracing::{info, warn}; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { - pub fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()> { + pub(crate) fn set_pusher( + &self, + sender: &UserId, + pusher: set_pusher::v3::PusherAction, + ) -> Result<()> { self.db.set_pusher(sender, pusher) } - pub fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result> { + pub(crate) fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result> { self.db.get_pusher(sender, pushkey) } - pub fn get_pushers(&self, sender: &UserId) -> Result> { + pub(crate) fn get_pushers(&self, sender: &UserId) -> Result> { self.db.get_pushers(sender) } - pub fn get_pushkeys(&self, sender: &UserId) -> Box>> { + pub(crate) fn get_pushkeys(&self, sender: &UserId) -> Box>> { self.db.get_pushkeys(sender) } #[tracing::instrument(skip(self, destination, request))] - pub async fn send_request( + pub(crate) async fn send_request( &self, destination: &str, request: T, @@ -128,7 +132,7 @@ impl Service { } #[tracing::instrument(skip(self, user, unread, pusher, ruleset, pdu))] - pub async fn send_push_notice( + pub(crate) async fn send_push_notice( &self, user: &UserId, unread: UInt, @@ -184,7 +188,7 @@ impl Service { } #[tracing::instrument(skip(self, user, ruleset, pdu))] - pub fn get_actions<'a>( + pub(crate) fn get_actions<'a>( &self, user: &UserId, ruleset: &'a Ruleset, diff --git a/src/service/pusher/data.rs b/src/service/pusher/data.rs index 2062f567..b13fcc3b 100644 --- a/src/service/pusher/data.rs +++ b/src/service/pusher/data.rs @@ -4,7 +4,7 @@ use ruma::{ UserId, }; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()>; fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result>; diff --git a/src/service/rooms.rs b/src/service/rooms.rs index f0739841..aab3cf00 100644 --- a/src/service/rooms.rs +++ b/src/service/rooms.rs @@ -1,24 +1,24 @@ -pub mod alias; -pub mod auth_chain; -pub mod directory; -pub mod edus; -pub mod event_handler; -pub mod lazy_loading; -pub mod metadata; -pub mod outlier; -pub mod pdu_metadata; -pub mod search; -pub mod short; -pub mod spaces; -pub mod state; -pub mod state_accessor; -pub mod state_cache; -pub mod state_compressor; -pub mod threads; -pub mod timeline; -pub mod user; +pub(crate) mod alias; +pub(crate) mod auth_chain; +pub(crate) mod directory; +pub(crate) mod edus; +pub(crate) mod event_handler; +pub(crate) mod lazy_loading; +pub(crate) mod metadata; +pub(crate) mod outlier; +pub(crate) mod pdu_metadata; +pub(crate) mod search; +pub(crate) mod short; +pub(crate) mod spaces; +pub(crate) mod state; +pub(crate) mod state_accessor; +pub(crate) mod state_cache; +pub(crate) mod state_compressor; +pub(crate) mod threads; +pub(crate) mod timeline; +pub(crate) mod user; -pub trait Data: +pub(crate) trait Data: alias::Data + auth_chain::Data + directory::Data @@ -39,24 +39,24 @@ pub trait Data: { } -pub struct Service { - pub alias: alias::Service, - pub auth_chain: auth_chain::Service, - pub directory: directory::Service, - pub edus: edus::Service, - pub event_handler: event_handler::Service, - pub lazy_loading: lazy_loading::Service, - pub metadata: metadata::Service, - pub outlier: outlier::Service, - pub pdu_metadata: pdu_metadata::Service, - pub search: search::Service, - pub short: short::Service, - pub state: state::Service, - pub state_accessor: state_accessor::Service, - pub state_cache: state_cache::Service, - pub state_compressor: state_compressor::Service, - pub timeline: timeline::Service, - pub threads: threads::Service, - pub spaces: spaces::Service, - pub user: user::Service, +pub(crate) struct Service { + pub(crate) alias: alias::Service, + pub(crate) auth_chain: auth_chain::Service, + pub(crate) directory: directory::Service, + pub(crate) edus: edus::Service, + pub(crate) event_handler: event_handler::Service, + pub(crate) lazy_loading: lazy_loading::Service, + pub(crate) metadata: metadata::Service, + pub(crate) outlier: outlier::Service, + pub(crate) pdu_metadata: pdu_metadata::Service, + pub(crate) search: search::Service, + pub(crate) short: short::Service, + pub(crate) state: state::Service, + pub(crate) state_accessor: state_accessor::Service, + pub(crate) state_cache: state_cache::Service, + pub(crate) state_compressor: state_compressor::Service, + pub(crate) timeline: timeline::Service, + pub(crate) threads: threads::Service, + pub(crate) spaces: spaces::Service, + pub(crate) user: user::Service, } diff --git a/src/service/rooms/alias.rs b/src/service/rooms/alias.rs index d26030c0..d078611a 100644 --- a/src/service/rooms/alias.rs +++ b/src/service/rooms/alias.rs @@ -1,32 +1,32 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use crate::Result; use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId}; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { #[tracing::instrument(skip(self))] - pub fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()> { + pub(crate) fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()> { self.db.set_alias(alias, room_id) } #[tracing::instrument(skip(self))] - pub fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> { + pub(crate) fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> { self.db.remove_alias(alias) } #[tracing::instrument(skip(self))] - pub fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result> { + pub(crate) fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result> { self.db.resolve_local_alias(alias) } #[tracing::instrument(skip(self))] - pub fn local_aliases_for_room<'a>( + pub(crate) fn local_aliases_for_room<'a>( &'a self, room_id: &RoomId, ) -> Box> + 'a> { diff --git a/src/service/rooms/alias/data.rs b/src/service/rooms/alias/data.rs index 629b1ee1..f0f442d0 100644 --- a/src/service/rooms/alias/data.rs +++ b/src/service/rooms/alias/data.rs @@ -1,7 +1,7 @@ use crate::Result; use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { /// Creates or updates the alias to the given room id. fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()>; diff --git a/src/service/rooms/auth_chain.rs b/src/service/rooms/auth_chain.rs index da1944e2..e1dc6527 100644 --- a/src/service/rooms/auth_chain.rs +++ b/src/service/rooms/auth_chain.rs @@ -4,28 +4,35 @@ use std::{ sync::Arc, }; -pub use data::Data; +pub(crate) use data::Data; use ruma::{api::client::error::ErrorKind, EventId, RoomId}; use tracing::{debug, error, warn}; use crate::{services, Error, Result}; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { - pub fn get_cached_eventid_authchain(&self, key: &[u64]) -> Result>>> { + pub(crate) fn get_cached_eventid_authchain( + &self, + key: &[u64], + ) -> Result>>> { self.db.get_cached_eventid_authchain(key) } #[tracing::instrument(skip(self))] - pub fn cache_auth_chain(&self, key: Vec, auth_chain: Arc>) -> Result<()> { + pub(crate) fn cache_auth_chain( + &self, + key: Vec, + auth_chain: Arc>, + ) -> Result<()> { self.db.cache_auth_chain(key, auth_chain) } #[tracing::instrument(skip(self, starting_events))] - pub async fn get_auth_chain<'a>( + pub(crate) async fn get_auth_chain<'a>( &self, room_id: &RoomId, starting_events: Vec>, diff --git a/src/service/rooms/auth_chain/data.rs b/src/service/rooms/auth_chain/data.rs index e8c379fc..7a865368 100644 --- a/src/service/rooms/auth_chain/data.rs +++ b/src/service/rooms/auth_chain/data.rs @@ -1,7 +1,7 @@ use crate::Result; use std::{collections::HashSet, sync::Arc}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn get_cached_eventid_authchain( &self, shorteventid: &[u64], diff --git a/src/service/rooms/directory.rs b/src/service/rooms/directory.rs index 10f782bb..9e43ac45 100644 --- a/src/service/rooms/directory.rs +++ b/src/service/rooms/directory.rs @@ -1,32 +1,32 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use ruma::{OwnedRoomId, RoomId}; use crate::Result; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { #[tracing::instrument(skip(self))] - pub fn set_public(&self, room_id: &RoomId) -> Result<()> { + pub(crate) fn set_public(&self, room_id: &RoomId) -> Result<()> { self.db.set_public(room_id) } #[tracing::instrument(skip(self))] - pub fn set_not_public(&self, room_id: &RoomId) -> Result<()> { + pub(crate) fn set_not_public(&self, room_id: &RoomId) -> Result<()> { self.db.set_not_public(room_id) } #[tracing::instrument(skip(self))] - pub fn is_public_room(&self, room_id: &RoomId) -> Result { + pub(crate) fn is_public_room(&self, room_id: &RoomId) -> Result { self.db.is_public_room(room_id) } #[tracing::instrument(skip(self))] - pub fn public_rooms(&self) -> impl Iterator> + '_ { + pub(crate) fn public_rooms(&self) -> impl Iterator> + '_ { self.db.public_rooms() } } diff --git a/src/service/rooms/directory/data.rs b/src/service/rooms/directory/data.rs index aca731ce..9aefaf6c 100644 --- a/src/service/rooms/directory/data.rs +++ b/src/service/rooms/directory/data.rs @@ -1,7 +1,7 @@ use crate::Result; use ruma::{OwnedRoomId, RoomId}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { /// Adds the room to the public room directory fn set_public(&self, room_id: &RoomId) -> Result<()>; diff --git a/src/service/rooms/edus.rs b/src/service/rooms/edus.rs index 869865f7..d9483465 100644 --- a/src/service/rooms/edus.rs +++ b/src/service/rooms/edus.rs @@ -1,9 +1,9 @@ -pub mod read_receipt; -pub mod typing; +pub(crate) mod read_receipt; +pub(crate) mod typing; -pub trait Data: read_receipt::Data + 'static {} +pub(crate) trait Data: read_receipt::Data + 'static {} -pub struct Service { - pub read_receipt: read_receipt::Service, - pub typing: typing::Service, +pub(crate) struct Service { + pub(crate) read_receipt: read_receipt::Service, + pub(crate) typing: typing::Service, } diff --git a/src/service/rooms/edus/read_receipt.rs b/src/service/rooms/edus/read_receipt.rs index c6035280..54628203 100644 --- a/src/service/rooms/edus/read_receipt.rs +++ b/src/service/rooms/edus/read_receipt.rs @@ -1,17 +1,17 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use crate::Result; use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId}; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { /// Replaces the previous read receipt. - pub fn readreceipt_update( + pub(crate) fn readreceipt_update( &self, user_id: &UserId, room_id: &RoomId, @@ -22,7 +22,7 @@ impl Service { /// Returns an iterator over the most recent read_receipts in a room that happened after the event with id `since`. #[tracing::instrument(skip(self))] - pub fn readreceipts_since<'a>( + pub(crate) fn readreceipts_since<'a>( &'a self, room_id: &RoomId, since: u64, @@ -38,18 +38,31 @@ impl Service { /// Sets a private read marker at `count`. #[tracing::instrument(skip(self))] - pub fn private_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) -> Result<()> { + pub(crate) fn private_read_set( + &self, + room_id: &RoomId, + user_id: &UserId, + count: u64, + ) -> Result<()> { self.db.private_read_set(room_id, user_id, count) } /// Returns the private read marker. #[tracing::instrument(skip(self))] - pub fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result> { + pub(crate) fn private_read_get( + &self, + room_id: &RoomId, + user_id: &UserId, + ) -> Result> { self.db.private_read_get(room_id, user_id) } /// Returns the count of the last typing update in this room. - pub fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub(crate) fn last_privateread_update( + &self, + user_id: &UserId, + room_id: &RoomId, + ) -> Result { self.db.last_privateread_update(user_id, room_id) } } diff --git a/src/service/rooms/edus/read_receipt/data.rs b/src/service/rooms/edus/read_receipt/data.rs index 044dad82..c25af24e 100644 --- a/src/service/rooms/edus/read_receipt/data.rs +++ b/src/service/rooms/edus/read_receipt/data.rs @@ -1,7 +1,7 @@ use crate::Result; use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { /// Replaces the previous read receipt. fn readreceipt_update( &self, diff --git a/src/service/rooms/edus/typing.rs b/src/service/rooms/edus/typing.rs index 7546aa84..76be3791 100644 --- a/src/service/rooms/edus/typing.rs +++ b/src/service/rooms/edus/typing.rs @@ -4,16 +4,21 @@ use tokio::sync::{broadcast, RwLock}; use crate::{services, utils, Result}; -pub struct Service { - pub typing: RwLock>>, // u64 is unix timestamp of timeout - pub last_typing_update: RwLock>, // timestamp of the last change to typing users - pub typing_update_sender: broadcast::Sender, +pub(crate) struct Service { + pub(crate) typing: RwLock>>, // u64 is unix timestamp of timeout + pub(crate) last_typing_update: RwLock>, // timestamp of the last change to typing users + pub(crate) typing_update_sender: broadcast::Sender, } impl Service { /// Sets a user as typing until the timeout timestamp is reached or roomtyping_remove is /// called. - pub async fn typing_add(&self, user_id: &UserId, room_id: &RoomId, timeout: u64) -> Result<()> { + pub(crate) async fn typing_add( + &self, + user_id: &UserId, + room_id: &RoomId, + timeout: u64, + ) -> Result<()> { self.typing .write() .await @@ -29,7 +34,7 @@ impl Service { } /// Removes a user from typing before the timeout is reached. - pub async fn typing_remove(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> { + pub(crate) async fn typing_remove(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> { self.typing .write() .await @@ -44,7 +49,7 @@ impl Service { Ok(()) } - pub async fn wait_for_update(&self, room_id: &RoomId) -> Result<()> { + pub(crate) async fn wait_for_update(&self, room_id: &RoomId) -> Result<()> { let mut receiver = self.typing_update_sender.subscribe(); while let Ok(next) = receiver.recv().await { if next == room_id { @@ -87,7 +92,7 @@ impl Service { } /// Returns the count of the last typing update in this room. - pub async fn last_typing_update(&self, room_id: &RoomId) -> Result { + pub(crate) async fn last_typing_update(&self, room_id: &RoomId) -> Result { self.typings_maintain(room_id).await?; Ok(self .last_typing_update @@ -99,7 +104,7 @@ impl Service { } /// Returns a new typing EDU. - pub async fn typings_all( + pub(crate) async fn typings_all( &self, room_id: &RoomId, ) -> Result> { diff --git a/src/service/rooms/event_handler.rs b/src/service/rooms/event_handler.rs index b7817e50..84b210e1 100644 --- a/src/service/rooms/event_handler.rs +++ b/src/service/rooms/event_handler.rs @@ -43,7 +43,7 @@ use crate::{service::*, services, Error, PduEvent, Result}; use super::state_compressor::CompressedStateEvent; -pub struct Service; +pub(crate) struct Service; impl Service { /// When receiving an event one needs to: @@ -480,7 +480,7 @@ impl Service { } #[tracing::instrument(skip(self, incoming_pdu, val, create_event, pub_key_map))] - pub async fn upgrade_outlier_to_timeline_pdu( + pub(crate) async fn upgrade_outlier_to_timeline_pdu( &self, incoming_pdu: Arc, val: BTreeMap, @@ -1636,7 +1636,7 @@ impl Service { } /// Returns Ok if the acl allows the server - pub fn acl_check(&self, server_name: &ServerName, room_id: &RoomId) -> Result<()> { + pub(crate) fn acl_check(&self, server_name: &ServerName, room_id: &RoomId) -> Result<()> { let acl_event = match services().rooms.state_accessor.room_state_get( room_id, &StateEventType::RoomServerAcl, @@ -1677,7 +1677,7 @@ impl Service { /// Search the DB for the signing keys of the given server, if we don't have them /// fetch them from the server and save to our DB. #[tracing::instrument(skip_all)] - pub async fn fetch_signing_keys( + pub(crate) async fn fetch_signing_keys( &self, origin: &ServerName, signature_ids: Vec, diff --git a/src/service/rooms/lazy_loading.rs b/src/service/rooms/lazy_loading.rs index e2594a0a..023e7fc2 100644 --- a/src/service/rooms/lazy_loading.rs +++ b/src/service/rooms/lazy_loading.rs @@ -1,7 +1,7 @@ mod data; use std::collections::{HashMap, HashSet}; -pub use data::Data; +pub(crate) use data::Data; use ruma::{DeviceId, OwnedDeviceId, OwnedRoomId, OwnedUserId, RoomId, UserId}; use tokio::sync::Mutex; @@ -9,17 +9,17 @@ use crate::Result; use super::timeline::PduCount; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, #[allow(clippy::type_complexity)] - pub lazy_load_waiting: + pub(crate) lazy_load_waiting: Mutex>>, } impl Service { #[tracing::instrument(skip(self))] - pub fn lazy_load_was_sent_before( + pub(crate) fn lazy_load_was_sent_before( &self, user_id: &UserId, device_id: &DeviceId, @@ -31,7 +31,7 @@ impl Service { } #[tracing::instrument(skip(self))] - pub async fn lazy_load_mark_sent( + pub(crate) async fn lazy_load_mark_sent( &self, user_id: &UserId, device_id: &DeviceId, @@ -51,7 +51,7 @@ impl Service { } #[tracing::instrument(skip(self))] - pub async fn lazy_load_confirm_delivery( + pub(crate) async fn lazy_load_confirm_delivery( &self, user_id: &UserId, device_id: &DeviceId, @@ -78,7 +78,7 @@ impl Service { } #[tracing::instrument(skip(self))] - pub fn lazy_load_reset( + pub(crate) fn lazy_load_reset( &self, user_id: &UserId, device_id: &DeviceId, diff --git a/src/service/rooms/lazy_loading/data.rs b/src/service/rooms/lazy_loading/data.rs index 9af8e21b..92f694a3 100644 --- a/src/service/rooms/lazy_loading/data.rs +++ b/src/service/rooms/lazy_loading/data.rs @@ -1,7 +1,7 @@ use crate::Result; use ruma::{DeviceId, RoomId, UserId}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn lazy_load_was_sent_before( &self, user_id: &UserId, diff --git a/src/service/rooms/metadata.rs b/src/service/rooms/metadata.rs index d1884691..5205a94a 100644 --- a/src/service/rooms/metadata.rs +++ b/src/service/rooms/metadata.rs @@ -1,30 +1,30 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use ruma::{OwnedRoomId, RoomId}; use crate::Result; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { /// Checks if a room exists. #[tracing::instrument(skip(self))] - pub fn exists(&self, room_id: &RoomId) -> Result { + pub(crate) fn exists(&self, room_id: &RoomId) -> Result { self.db.exists(room_id) } - pub fn iter_ids<'a>(&'a self) -> Box> + 'a> { + pub(crate) fn iter_ids<'a>(&'a self) -> Box> + 'a> { self.db.iter_ids() } - pub fn is_disabled(&self, room_id: &RoomId) -> Result { + pub(crate) fn is_disabled(&self, room_id: &RoomId) -> Result { self.db.is_disabled(room_id) } - pub fn disable_room(&self, room_id: &RoomId, disabled: bool) -> Result<()> { + pub(crate) fn disable_room(&self, room_id: &RoomId, disabled: bool) -> Result<()> { self.db.disable_room(room_id, disabled) } } diff --git a/src/service/rooms/metadata/data.rs b/src/service/rooms/metadata/data.rs index 339db573..9b49fdeb 100644 --- a/src/service/rooms/metadata/data.rs +++ b/src/service/rooms/metadata/data.rs @@ -1,7 +1,7 @@ use crate::Result; use ruma::{OwnedRoomId, RoomId}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn exists(&self, room_id: &RoomId) -> Result; fn iter_ids<'a>(&'a self) -> Box> + 'a>; fn is_disabled(&self, room_id: &RoomId) -> Result; diff --git a/src/service/rooms/outlier.rs b/src/service/rooms/outlier.rs index dae41e4b..64665fa5 100644 --- a/src/service/rooms/outlier.rs +++ b/src/service/rooms/outlier.rs @@ -1,28 +1,35 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use ruma::{CanonicalJsonObject, EventId}; use crate::{PduEvent, Result}; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { /// Returns the pdu from the outlier tree. - pub fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result> { + pub(crate) fn get_outlier_pdu_json( + &self, + event_id: &EventId, + ) -> Result> { self.db.get_outlier_pdu_json(event_id) } /// Returns the pdu from the outlier tree. - pub fn get_pdu_outlier(&self, event_id: &EventId) -> Result> { + pub(crate) fn get_pdu_outlier(&self, event_id: &EventId) -> Result> { self.db.get_outlier_pdu(event_id) } /// Append the PDU as an outlier. #[tracing::instrument(skip(self, pdu))] - pub fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()> { + pub(crate) fn add_pdu_outlier( + &self, + event_id: &EventId, + pdu: &CanonicalJsonObject, + ) -> Result<()> { self.db.add_pdu_outlier(event_id, pdu) } } diff --git a/src/service/rooms/outlier/data.rs b/src/service/rooms/outlier/data.rs index 0ed521dd..34505640 100644 --- a/src/service/rooms/outlier/data.rs +++ b/src/service/rooms/outlier/data.rs @@ -2,7 +2,7 @@ use ruma::{CanonicalJsonObject, EventId}; use crate::{PduEvent, Result}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result>; fn get_outlier_pdu(&self, event_id: &EventId) -> Result>; fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()>; diff --git a/src/service/rooms/pdu_metadata.rs b/src/service/rooms/pdu_metadata.rs index 411f4f54..ee904e07 100644 --- a/src/service/rooms/pdu_metadata.rs +++ b/src/service/rooms/pdu_metadata.rs @@ -1,7 +1,7 @@ mod data; use std::sync::Arc; -pub use data::Data; +pub(crate) use data::Data; use ruma::{ api::client::relations::get_relating_events, events::{relation::RelationType, TimelineEventType}, @@ -13,8 +13,8 @@ use crate::{services, PduEvent, Result}; use super::timeline::PduCount; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } #[derive(Clone, Debug, Deserialize)] @@ -29,7 +29,7 @@ struct ExtractRelatesToEventId { impl Service { #[tracing::instrument(skip(self, from, to))] - pub fn add_relation(&self, from: PduCount, to: PduCount) -> Result<()> { + pub(crate) fn add_relation(&self, from: PduCount, to: PduCount) -> Result<()> { match (from, to) { (PduCount::Normal(f), PduCount::Normal(t)) => self.db.add_relation(f, t), _ => { @@ -41,7 +41,7 @@ impl Service { } #[allow(clippy::too_many_arguments)] - pub fn paginate_relations_with_filter( + pub(crate) fn paginate_relations_with_filter( &self, sender_user: &UserId, room_id: &RoomId, @@ -152,7 +152,7 @@ impl Service { } } - pub fn relations_until<'a>( + pub(crate) fn relations_until<'a>( &'a self, user_id: &'a UserId, room_id: &'a RoomId, @@ -169,22 +169,26 @@ impl Service { } #[tracing::instrument(skip(self, room_id, event_ids))] - pub fn mark_as_referenced(&self, room_id: &RoomId, event_ids: &[Arc]) -> Result<()> { + pub(crate) fn mark_as_referenced( + &self, + room_id: &RoomId, + event_ids: &[Arc], + ) -> Result<()> { self.db.mark_as_referenced(room_id, event_ids) } #[tracing::instrument(skip(self))] - pub fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> Result { + pub(crate) fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> Result { self.db.is_event_referenced(room_id, event_id) } #[tracing::instrument(skip(self))] - pub fn mark_event_soft_failed(&self, event_id: &EventId) -> Result<()> { + pub(crate) fn mark_event_soft_failed(&self, event_id: &EventId) -> Result<()> { self.db.mark_event_soft_failed(event_id) } #[tracing::instrument(skip(self))] - pub fn is_event_soft_failed(&self, event_id: &EventId) -> Result { + pub(crate) fn is_event_soft_failed(&self, event_id: &EventId) -> Result { self.db.is_event_soft_failed(event_id) } } diff --git a/src/service/rooms/pdu_metadata/data.rs b/src/service/rooms/pdu_metadata/data.rs index a4df34cc..4e28474a 100644 --- a/src/service/rooms/pdu_metadata/data.rs +++ b/src/service/rooms/pdu_metadata/data.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use crate::{service::rooms::timeline::PduCount, PduEvent, Result}; use ruma::{EventId, RoomId, UserId}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn add_relation(&self, from: u64, to: u64) -> Result<()>; #[allow(clippy::type_complexity)] fn relations_until<'a>( diff --git a/src/service/rooms/search.rs b/src/service/rooms/search.rs index b6f35e79..48dacca2 100644 --- a/src/service/rooms/search.rs +++ b/src/service/rooms/search.rs @@ -1,22 +1,27 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use crate::Result; use ruma::RoomId; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { #[tracing::instrument(skip(self))] - pub fn index_pdu<'a>(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()> { + pub(crate) fn index_pdu<'a>( + &self, + shortroomid: u64, + pdu_id: &[u8], + message_body: &str, + ) -> Result<()> { self.db.index_pdu(shortroomid, pdu_id, message_body) } #[tracing::instrument(skip(self))] - pub fn search_pdus<'a>( + pub(crate) fn search_pdus<'a>( &'a self, room_id: &RoomId, search_string: &str, diff --git a/src/service/rooms/search/data.rs b/src/service/rooms/search/data.rs index 7ea7e3d1..9e68fe62 100644 --- a/src/service/rooms/search/data.rs +++ b/src/service/rooms/search/data.rs @@ -1,7 +1,7 @@ use crate::Result; use ruma::RoomId; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn index_pdu(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()>; #[allow(clippy::type_complexity)] diff --git a/src/service/rooms/short.rs b/src/service/rooms/short.rs index 45fadd74..b2ad4fc5 100644 --- a/src/service/rooms/short.rs +++ b/src/service/rooms/short.rs @@ -1,21 +1,21 @@ mod data; use std::sync::Arc; -pub use data::Data; +pub(crate) use data::Data; use ruma::{events::StateEventType, EventId, RoomId}; use crate::Result; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { - pub fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result { + pub(crate) fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result { self.db.get_or_create_shorteventid(event_id) } - pub fn get_shortstatekey( + pub(crate) fn get_shortstatekey( &self, event_type: &StateEventType, state_key: &str, @@ -23,7 +23,7 @@ impl Service { self.db.get_shortstatekey(event_type, state_key) } - pub fn get_or_create_shortstatekey( + pub(crate) fn get_or_create_shortstatekey( &self, event_type: &StateEventType, state_key: &str, @@ -31,24 +31,27 @@ impl Service { self.db.get_or_create_shortstatekey(event_type, state_key) } - pub fn get_eventid_from_short(&self, shorteventid: u64) -> Result> { + pub(crate) fn get_eventid_from_short(&self, shorteventid: u64) -> Result> { self.db.get_eventid_from_short(shorteventid) } - pub fn get_statekey_from_short(&self, shortstatekey: u64) -> Result<(StateEventType, String)> { + pub(crate) fn get_statekey_from_short( + &self, + shortstatekey: u64, + ) -> Result<(StateEventType, String)> { self.db.get_statekey_from_short(shortstatekey) } /// Returns (shortstatehash, already_existed) - pub fn get_or_create_shortstatehash(&self, state_hash: &[u8]) -> Result<(u64, bool)> { + pub(crate) fn get_or_create_shortstatehash(&self, state_hash: &[u8]) -> Result<(u64, bool)> { self.db.get_or_create_shortstatehash(state_hash) } - pub fn get_shortroomid(&self, room_id: &RoomId) -> Result> { + pub(crate) fn get_shortroomid(&self, room_id: &RoomId) -> Result> { self.db.get_shortroomid(room_id) } - pub fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result { + pub(crate) fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result { self.db.get_or_create_shortroomid(room_id) } } diff --git a/src/service/rooms/short/data.rs b/src/service/rooms/short/data.rs index 652c525b..2b7465f1 100644 --- a/src/service/rooms/short/data.rs +++ b/src/service/rooms/short/data.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use crate::Result; use ruma::{events::StateEventType, EventId, RoomId}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result; fn get_shortstatekey( diff --git a/src/service/rooms/spaces.rs b/src/service/rooms/spaces.rs index 981d4a37..27d00c30 100644 --- a/src/service/rooms/spaces.rs +++ b/src/service/rooms/spaces.rs @@ -31,23 +31,23 @@ use tracing::{debug, error, warn}; use crate::{services, Error, PduEvent, Result}; -pub enum CachedJoinRule { +pub(crate) enum CachedJoinRule { //Simplified(SpaceRoomJoinRule), Full(JoinRule), } -pub struct CachedSpaceChunk { +pub(crate) struct CachedSpaceChunk { chunk: SpaceHierarchyRoomsChunk, children: Vec, join_rule: CachedJoinRule, } -pub struct Service { - pub roomid_spacechunk_cache: Mutex>>, +pub(crate) struct Service { + pub(crate) roomid_spacechunk_cache: Mutex>>, } impl Service { - pub async fn get_hierarchy( + pub(crate) async fn get_hierarchy( &self, sender_user: &UserId, room_id: &RoomId, diff --git a/src/service/rooms/state.rs b/src/service/rooms/state.rs index f6581bb5..2b3da501 100644 --- a/src/service/rooms/state.rs +++ b/src/service/rooms/state.rs @@ -4,7 +4,7 @@ use std::{ sync::Arc, }; -pub use data::Data; +pub(crate) use data::Data; use ruma::{ api::client::error::ErrorKind, events::{ @@ -23,13 +23,13 @@ use crate::{services, utils::calculate_hash, Error, PduEvent, Result}; use super::state_compressor::CompressedStateEvent; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { /// Set the room to the given statehash and update caches. - pub async fn force_state( + pub(crate) async fn force_state( &self, room_id: &RoomId, shortstatehash: u64, @@ -115,7 +115,7 @@ impl Service { /// This adds all current state events (not including the incoming event) /// to `stateid_pduid` and adds the incoming event to `eventid_statehash`. #[tracing::instrument(skip(self, state_ids_compressed))] - pub fn set_event_state( + pub(crate) fn set_event_state( &self, event_id: &EventId, room_id: &RoomId, @@ -187,7 +187,7 @@ impl Service { /// This adds all current state events (not including the incoming event) /// to `stateid_pduid` and adds the incoming event to `eventid_statehash`. #[tracing::instrument(skip(self, new_pdu))] - pub fn append_to_state(&self, new_pdu: &PduEvent) -> Result { + pub(crate) fn append_to_state(&self, new_pdu: &PduEvent) -> Result { let shorteventid = services() .rooms .short @@ -259,7 +259,7 @@ impl Service { } #[tracing::instrument(skip(self, invite_event))] - pub fn calculate_invite_state( + pub(crate) fn calculate_invite_state( &self, invite_event: &PduEvent, ) -> Result>> { @@ -314,7 +314,7 @@ impl Service { /// Set the state hash to a new version, but does not update state_cache. #[tracing::instrument(skip(self))] - pub fn set_room_state( + pub(crate) fn set_room_state( &self, room_id: &RoomId, shortstatehash: u64, @@ -325,7 +325,7 @@ impl Service { /// Returns the room's version. #[tracing::instrument(skip(self))] - pub fn get_room_version(&self, room_id: &RoomId) -> Result { + pub(crate) fn get_room_version(&self, room_id: &RoomId) -> Result { let create_event = services().rooms.state_accessor.room_state_get( room_id, &StateEventType::RoomCreate, @@ -346,15 +346,18 @@ impl Service { Ok(create_event_content.room_version) } - pub fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result> { + pub(crate) fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result> { self.db.get_room_shortstatehash(room_id) } - pub fn get_forward_extremities(&self, room_id: &RoomId) -> Result>> { + pub(crate) fn get_forward_extremities( + &self, + room_id: &RoomId, + ) -> Result>> { self.db.get_forward_extremities(room_id) } - pub fn set_forward_extremities( + pub(crate) fn set_forward_extremities( &self, room_id: &RoomId, event_ids: Vec, @@ -366,7 +369,7 @@ impl Service { /// This fetches auth events from the current state. #[tracing::instrument(skip(self))] - pub fn get_auth_events( + pub(crate) fn get_auth_events( &self, room_id: &RoomId, kind: &TimelineEventType, diff --git a/src/service/rooms/state/data.rs b/src/service/rooms/state/data.rs index 96116b02..b8dda66b 100644 --- a/src/service/rooms/state/data.rs +++ b/src/service/rooms/state/data.rs @@ -3,7 +3,7 @@ use ruma::{EventId, OwnedEventId, RoomId}; use std::{collections::HashSet, sync::Arc}; use tokio::sync::MutexGuard; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { /// Returns the last state hash key added to the db for the given room. fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result>; diff --git a/src/service/rooms/state_accessor.rs b/src/service/rooms/state_accessor.rs index 53e3176f..6026677e 100644 --- a/src/service/rooms/state_accessor.rs +++ b/src/service/rooms/state_accessor.rs @@ -4,7 +4,7 @@ use std::{ sync::{Arc, Mutex}, }; -pub use data::Data; +pub(crate) use data::Data; use lru_cache::LruCache; use ruma::{ events::{ @@ -26,21 +26,24 @@ use tracing::{error, warn}; use crate::{service::pdu::PduBuilder, services, Error, PduEvent, Result}; -pub struct Service { - pub db: &'static dyn Data, - pub server_visibility_cache: Mutex>, - pub user_visibility_cache: Mutex>, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, + pub(crate) server_visibility_cache: Mutex>, + pub(crate) user_visibility_cache: Mutex>, } impl Service { /// Builds a StateMap by iterating over all keys that start /// with state_hash, this gives the full state for the given state_hash. #[tracing::instrument(skip(self))] - pub async fn state_full_ids(&self, shortstatehash: u64) -> Result>> { + pub(crate) async fn state_full_ids( + &self, + shortstatehash: u64, + ) -> Result>> { self.db.state_full_ids(shortstatehash).await } - pub async fn state_full( + pub(crate) async fn state_full( &self, shortstatehash: u64, ) -> Result>> { @@ -49,7 +52,7 @@ impl Service { /// Returns a single PDU from `room_id` with key (`event_type`, `state_key`). #[tracing::instrument(skip(self))] - pub fn state_get_id( + pub(crate) fn state_get_id( &self, shortstatehash: u64, event_type: &StateEventType, @@ -59,7 +62,7 @@ impl Service { } /// Returns a single PDU from `room_id` with key (`event_type`, `state_key`). - pub fn state_get( + pub(crate) fn state_get( &self, shortstatehash: u64, event_type: &StateEventType, @@ -100,7 +103,7 @@ impl Service { /// Whether a server is allowed to see an event through federation, based on /// the room's history_visibility at that event's state. #[tracing::instrument(skip(self, origin, room_id, event_id))] - pub fn server_can_see_event( + pub(crate) fn server_can_see_event( &self, origin: &ServerName, room_id: &RoomId, @@ -164,7 +167,7 @@ impl Service { /// Whether a user is allowed to see an event, based on /// the room's history_visibility at that event's state. #[tracing::instrument(skip(self, user_id, room_id, event_id))] - pub fn user_can_see_event( + pub(crate) fn user_can_see_event( &self, user_id: &UserId, room_id: &RoomId, @@ -224,7 +227,11 @@ impl Service { /// Whether a user is allowed to see an event, based on /// the room's history_visibility at that event's state. #[tracing::instrument(skip(self, user_id, room_id))] - pub fn user_can_see_state_events(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub(crate) fn user_can_see_state_events( + &self, + user_id: &UserId, + room_id: &RoomId, + ) -> Result { let currently_member = services().rooms.state_cache.is_joined(user_id, room_id)?; let history_visibility = self @@ -241,13 +248,13 @@ impl Service { } /// Returns the state hash for this pdu. - pub fn pdu_shortstatehash(&self, event_id: &EventId) -> Result> { + pub(crate) fn pdu_shortstatehash(&self, event_id: &EventId) -> Result> { self.db.pdu_shortstatehash(event_id) } /// Returns the full room state. #[tracing::instrument(skip(self))] - pub async fn room_state_full( + pub(crate) async fn room_state_full( &self, room_id: &RoomId, ) -> Result>> { @@ -256,7 +263,7 @@ impl Service { /// Returns a single PDU from `room_id` with key (`event_type`, `state_key`). #[tracing::instrument(skip(self))] - pub fn room_state_get_id( + pub(crate) fn room_state_get_id( &self, room_id: &RoomId, event_type: &StateEventType, @@ -267,7 +274,7 @@ impl Service { /// Returns a single PDU from `room_id` with key (`event_type`, `state_key`). #[tracing::instrument(skip(self))] - pub fn room_state_get( + pub(crate) fn room_state_get( &self, room_id: &RoomId, event_type: &StateEventType, @@ -276,7 +283,7 @@ impl Service { self.db.room_state_get(room_id, event_type, state_key) } - pub fn get_name(&self, room_id: &RoomId) -> Result> { + pub(crate) fn get_name(&self, room_id: &RoomId) -> Result> { services() .rooms .state_accessor @@ -294,7 +301,7 @@ impl Service { }) } - pub fn get_avatar(&self, room_id: &RoomId) -> Result> { + pub(crate) fn get_avatar(&self, room_id: &RoomId) -> Result> { services() .rooms .state_accessor @@ -305,7 +312,7 @@ impl Service { }) } - pub async fn user_can_invite( + pub(crate) async fn user_can_invite( &self, room_id: &RoomId, sender: &UserId, @@ -330,7 +337,7 @@ impl Service { .is_ok()) } - pub fn get_member( + pub(crate) fn get_member( &self, room_id: &RoomId, user_id: &UserId, @@ -350,7 +357,7 @@ impl Service { /// If `federation` is `true`, it allows redaction events from any user of the same server /// as the original event sender, [as required by room versions >= /// v3](https://spec.matrix.org/v1.10/rooms/v11/#handling-redactions) - pub fn user_can_redact( + pub(crate) fn user_can_redact( &self, redacts: &EventId, sender: &UserId, diff --git a/src/service/rooms/state_accessor/data.rs b/src/service/rooms/state_accessor/data.rs index f3ae3c21..a57cdb9d 100644 --- a/src/service/rooms/state_accessor/data.rs +++ b/src/service/rooms/state_accessor/data.rs @@ -6,7 +6,7 @@ use ruma::{events::StateEventType, EventId, RoomId}; use crate::{PduEvent, Result}; #[async_trait] -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { /// Builds a StateMap by iterating over all keys that start /// with state_hash, this gives the full state for the given state_hash. async fn state_full_ids(&self, shortstatehash: u64) -> Result>>; diff --git a/src/service/rooms/state_cache.rs b/src/service/rooms/state_cache.rs index c108695d..8b844f1e 100644 --- a/src/service/rooms/state_cache.rs +++ b/src/service/rooms/state_cache.rs @@ -1,7 +1,7 @@ mod data; use std::{collections::HashSet, sync::Arc}; -pub use data::Data; +pub(crate) use data::Data; use ruma::{ events::{ @@ -18,14 +18,14 @@ use tracing::warn; use crate::{service::appservice::RegistrationInfo, services, Error, Result}; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { /// Update current membership data. #[tracing::instrument(skip(self, last_state))] - pub fn update_membership( + pub(crate) fn update_membership( &self, room_id: &RoomId, user_id: &UserId, @@ -192,17 +192,17 @@ impl Service { } #[tracing::instrument(skip(self, room_id))] - pub fn update_joined_count(&self, room_id: &RoomId) -> Result<()> { + pub(crate) fn update_joined_count(&self, room_id: &RoomId) -> Result<()> { self.db.update_joined_count(room_id) } #[tracing::instrument(skip(self, room_id))] - pub fn get_our_real_users(&self, room_id: &RoomId) -> Result>> { + pub(crate) fn get_our_real_users(&self, room_id: &RoomId) -> Result>> { self.db.get_our_real_users(room_id) } #[tracing::instrument(skip(self, room_id, appservice))] - pub fn appservice_in_room( + pub(crate) fn appservice_in_room( &self, room_id: &RoomId, appservice: &RegistrationInfo, @@ -212,13 +212,13 @@ impl Service { /// Makes a user forget a room. #[tracing::instrument(skip(self))] - pub fn forget(&self, room_id: &RoomId, user_id: &UserId) -> Result<()> { + pub(crate) fn forget(&self, room_id: &RoomId, user_id: &UserId) -> Result<()> { self.db.forget(room_id, user_id) } /// Returns an iterator of all servers participating in this room. #[tracing::instrument(skip(self))] - pub fn room_servers<'a>( + pub(crate) fn room_servers<'a>( &'a self, room_id: &RoomId, ) -> impl Iterator> + 'a { @@ -226,13 +226,17 @@ impl Service { } #[tracing::instrument(skip(self))] - pub fn server_in_room<'a>(&'a self, server: &ServerName, room_id: &RoomId) -> Result { + pub(crate) fn server_in_room<'a>( + &'a self, + server: &ServerName, + room_id: &RoomId, + ) -> Result { self.db.server_in_room(server, room_id) } /// Returns an iterator of all rooms a server participates in (as far as we know). #[tracing::instrument(skip(self))] - pub fn server_rooms<'a>( + pub(crate) fn server_rooms<'a>( &'a self, server: &ServerName, ) -> impl Iterator> + 'a { @@ -241,7 +245,7 @@ impl Service { /// Returns an iterator over all joined members of a room. #[tracing::instrument(skip(self))] - pub fn room_members<'a>( + pub(crate) fn room_members<'a>( &'a self, room_id: &RoomId, ) -> impl Iterator> + 'a { @@ -249,18 +253,18 @@ impl Service { } #[tracing::instrument(skip(self))] - pub fn room_joined_count(&self, room_id: &RoomId) -> Result> { + pub(crate) fn room_joined_count(&self, room_id: &RoomId) -> Result> { self.db.room_joined_count(room_id) } #[tracing::instrument(skip(self))] - pub fn room_invited_count(&self, room_id: &RoomId) -> Result> { + pub(crate) fn room_invited_count(&self, room_id: &RoomId) -> Result> { self.db.room_invited_count(room_id) } /// Returns an iterator over all User IDs who ever joined a room. #[tracing::instrument(skip(self))] - pub fn room_useroncejoined<'a>( + pub(crate) fn room_useroncejoined<'a>( &'a self, room_id: &RoomId, ) -> impl Iterator> + 'a { @@ -269,7 +273,7 @@ impl Service { /// Returns an iterator over all invited members of a room. #[tracing::instrument(skip(self))] - pub fn room_members_invited<'a>( + pub(crate) fn room_members_invited<'a>( &'a self, room_id: &RoomId, ) -> impl Iterator> + 'a { @@ -277,18 +281,22 @@ impl Service { } #[tracing::instrument(skip(self))] - pub fn get_invite_count(&self, room_id: &RoomId, user_id: &UserId) -> Result> { + pub(crate) fn get_invite_count( + &self, + room_id: &RoomId, + user_id: &UserId, + ) -> Result> { self.db.get_invite_count(room_id, user_id) } #[tracing::instrument(skip(self))] - pub fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result> { + pub(crate) fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result> { self.db.get_left_count(room_id, user_id) } /// Returns an iterator over all rooms this user joined. #[tracing::instrument(skip(self))] - pub fn rooms_joined<'a>( + pub(crate) fn rooms_joined<'a>( &'a self, user_id: &UserId, ) -> impl Iterator> + 'a { @@ -297,7 +305,7 @@ impl Service { /// Returns an iterator over all rooms a user was invited to. #[tracing::instrument(skip(self))] - pub fn rooms_invited<'a>( + pub(crate) fn rooms_invited<'a>( &'a self, user_id: &UserId, ) -> impl Iterator>)>> + 'a { @@ -305,7 +313,7 @@ impl Service { } #[tracing::instrument(skip(self))] - pub fn invite_state( + pub(crate) fn invite_state( &self, user_id: &UserId, room_id: &RoomId, @@ -314,7 +322,7 @@ impl Service { } #[tracing::instrument(skip(self))] - pub fn left_state( + pub(crate) fn left_state( &self, user_id: &UserId, room_id: &RoomId, @@ -324,7 +332,7 @@ impl Service { /// Returns an iterator over all rooms a user left. #[tracing::instrument(skip(self))] - pub fn rooms_left<'a>( + pub(crate) fn rooms_left<'a>( &'a self, user_id: &UserId, ) -> impl Iterator>)>> + 'a { @@ -332,22 +340,22 @@ impl Service { } #[tracing::instrument(skip(self))] - pub fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub(crate) fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.once_joined(user_id, room_id) } #[tracing::instrument(skip(self))] - pub fn is_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub(crate) fn is_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.is_joined(user_id, room_id) } #[tracing::instrument(skip(self))] - pub fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub(crate) fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.is_invited(user_id, room_id) } #[tracing::instrument(skip(self))] - pub fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub(crate) fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.is_left(user_id, room_id) } } diff --git a/src/service/rooms/state_cache/data.rs b/src/service/rooms/state_cache/data.rs index b511919a..c92ec848 100644 --- a/src/service/rooms/state_cache/data.rs +++ b/src/service/rooms/state_cache/data.rs @@ -7,7 +7,7 @@ use ruma::{ OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, }; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn mark_as_once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>; fn mark_as_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>; fn mark_as_invited( diff --git a/src/service/rooms/state_compressor.rs b/src/service/rooms/state_compressor.rs index 6118e06b..8ba07634 100644 --- a/src/service/rooms/state_compressor.rs +++ b/src/service/rooms/state_compressor.rs @@ -1,11 +1,11 @@ -pub mod data; +pub(crate) mod data; use std::{ collections::HashSet, mem::size_of, sync::{Arc, Mutex}, }; -pub use data::Data; +pub(crate) use data::Data; use lru_cache::LruCache; use ruma::{EventId, RoomId}; @@ -13,11 +13,11 @@ use crate::{services, utils, Result}; use self::data::StateDiff; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, #[allow(clippy::type_complexity)] - pub stateinfo_cache: Mutex< + pub(crate) stateinfo_cache: Mutex< LruCache< u64, Vec<( @@ -30,13 +30,13 @@ pub struct Service { >, } -pub type CompressedStateEvent = [u8; 2 * size_of::()]; +pub(crate) type CompressedStateEvent = [u8; 2 * size_of::()]; impl Service { /// Returns a stack with info on shortstatehash, full state, added diff and removed diff for the selected shortstatehash and each parent layer. #[allow(clippy::type_complexity)] #[tracing::instrument(skip(self))] - pub fn load_shortstatehash_info( + pub(crate) fn load_shortstatehash_info( &self, shortstatehash: u64, ) -> Result< @@ -89,7 +89,7 @@ impl Service { } } - pub fn compress_state_event( + pub(crate) fn compress_state_event( &self, shortstatekey: u64, event_id: &EventId, @@ -106,7 +106,7 @@ impl Service { } /// Returns shortstatekey, event id - pub fn parse_compressed_state_event( + pub(crate) fn parse_compressed_state_event( &self, compressed_event: &CompressedStateEvent, ) -> Result<(u64, Arc)> { @@ -141,7 +141,7 @@ impl Service { diff_to_sibling, parent_states ))] - pub fn save_state_from_diff( + pub(crate) fn save_state_from_diff( &self, shortstatehash: u64, statediffnew: Arc>, @@ -257,7 +257,7 @@ impl Service { /// Returns the new shortstatehash, and the state diff from the previous room state #[allow(clippy::type_complexity)] - pub fn save_state( + pub(crate) fn save_state( &self, room_id: &RoomId, new_state_ids_compressed: Arc>, diff --git a/src/service/rooms/state_compressor/data.rs b/src/service/rooms/state_compressor/data.rs index d221d576..3000b4ad 100644 --- a/src/service/rooms/state_compressor/data.rs +++ b/src/service/rooms/state_compressor/data.rs @@ -3,13 +3,13 @@ use std::{collections::HashSet, sync::Arc}; use super::CompressedStateEvent; use crate::Result; -pub struct StateDiff { - pub parent: Option, - pub added: Arc>, - pub removed: Arc>, +pub(crate) struct StateDiff { + pub(crate) parent: Option, + pub(crate) added: Arc>, + pub(crate) removed: Arc>, } -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn get_statediff(&self, shortstatehash: u64) -> Result; fn save_statediff(&self, shortstatehash: u64, diff: StateDiff) -> Result<()>; } diff --git a/src/service/rooms/threads.rs b/src/service/rooms/threads.rs index c6193bc8..d7690c08 100644 --- a/src/service/rooms/threads.rs +++ b/src/service/rooms/threads.rs @@ -1,6 +1,6 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use ruma::{ api::client::{error::ErrorKind, threads::get_threads::v1::IncludeThreads}, events::relation::BundledThread, @@ -11,12 +11,12 @@ use serde_json::json; use crate::{services, Error, PduEvent, Result}; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { - pub fn threads_until<'a>( + pub(crate) fn threads_until<'a>( &'a self, user_id: &'a UserId, room_id: &'a RoomId, @@ -26,7 +26,7 @@ impl Service { self.db.threads_until(user_id, room_id, until, include) } - pub fn add_to_thread(&self, root_event_id: &EventId, pdu: &PduEvent) -> Result<()> { + pub(crate) fn add_to_thread(&self, root_event_id: &EventId, pdu: &PduEvent) -> Result<()> { let root_id = &services() .rooms .timeline diff --git a/src/service/rooms/threads/data.rs b/src/service/rooms/threads/data.rs index e7159de0..42596e9b 100644 --- a/src/service/rooms/threads/data.rs +++ b/src/service/rooms/threads/data.rs @@ -1,7 +1,7 @@ use crate::{PduEvent, Result}; use ruma::{api::client::threads::get_threads::v1::IncludeThreads, OwnedUserId, RoomId, UserId}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { #[allow(clippy::type_complexity)] fn threads_until<'a>( &'a self, diff --git a/src/service/rooms/timeline.rs b/src/service/rooms/timeline.rs index 6c15b751..e8a815b7 100644 --- a/src/service/rooms/timeline.rs +++ b/src/service/rooms/timeline.rs @@ -6,7 +6,7 @@ use std::{ sync::Arc, }; -pub use data::Data; +pub(crate) use data::Data; use ruma::{ api::{client::error::ErrorKind, federation}, @@ -42,20 +42,20 @@ use crate::{ use super::state_compressor::CompressedStateEvent; #[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)] -pub enum PduCount { +pub(crate) enum PduCount { Backfilled(u64), Normal(u64), } impl PduCount { - pub fn min() -> Self { + pub(crate) fn min() -> Self { Self::Backfilled(u64::MAX) } - pub fn max() -> Self { + pub(crate) fn max() -> Self { Self::Normal(u64::MAX) } - pub fn try_from_string(token: &str) -> Result { + pub(crate) fn try_from_string(token: &str) -> Result { if let Some(stripped) = token.strip_prefix('-') { stripped.parse().map(PduCount::Backfilled) } else { @@ -64,7 +64,7 @@ impl PduCount { .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid pagination token.")) } - pub fn stringify(&self) -> String { + pub(crate) fn stringify(&self) -> String { match self { PduCount::Backfilled(x) => format!("-{x}"), PduCount::Normal(x) => x.to_string(), @@ -89,15 +89,15 @@ impl Ord for PduCount { } } -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, - pub lasttimelinecount_cache: Mutex>, + pub(crate) lasttimelinecount_cache: Mutex>, } impl Service { #[tracing::instrument(skip(self))] - pub fn first_pdu_in_room(&self, room_id: &RoomId) -> Result>> { + pub(crate) fn first_pdu_in_room(&self, room_id: &RoomId) -> Result>> { self.all_pdus(user_id!("@doesntmatter:grapevine"), room_id)? .next() .map(|o| o.map(|(_, p)| Arc::new(p))) @@ -105,19 +105,23 @@ impl Service { } #[tracing::instrument(skip(self))] - pub fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result { + pub(crate) fn last_timeline_count( + &self, + sender_user: &UserId, + room_id: &RoomId, + ) -> Result { self.db.last_timeline_count(sender_user, room_id) } /// Returns the `count` of this pdu's id. - pub fn get_pdu_count(&self, event_id: &EventId) -> Result> { + pub(crate) fn get_pdu_count(&self, event_id: &EventId) -> Result> { self.db.get_pdu_count(event_id) } // TODO Is this the same as the function above? /* #[tracing::instrument(skip(self))] - pub fn latest_pdu_count(&self, room_id: &RoomId) -> Result { + pub(crate) fn latest_pdu_count(&self, room_id: &RoomId) -> Result { let prefix = self .get_shortroomid(room_id)? .expect("room exists") @@ -138,12 +142,12 @@ impl Service { */ /// Returns the json of a pdu. - pub fn get_pdu_json(&self, event_id: &EventId) -> Result> { + pub(crate) fn get_pdu_json(&self, event_id: &EventId) -> Result> { self.db.get_pdu_json(event_id) } /// Returns the json of a pdu. - pub fn get_non_outlier_pdu_json( + pub(crate) fn get_non_outlier_pdu_json( &self, event_id: &EventId, ) -> Result> { @@ -151,39 +155,42 @@ impl Service { } /// Returns the pdu's id. - pub fn get_pdu_id(&self, event_id: &EventId) -> Result>> { + pub(crate) fn get_pdu_id(&self, event_id: &EventId) -> Result>> { self.db.get_pdu_id(event_id) } /// Returns the pdu. /// /// Checks the `eventid_outlierpdu` Tree if not found in the timeline. - pub fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result> { + pub(crate) fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result> { self.db.get_non_outlier_pdu(event_id) } /// Returns the pdu. /// /// Checks the `eventid_outlierpdu` Tree if not found in the timeline. - pub fn get_pdu(&self, event_id: &EventId) -> Result>> { + pub(crate) fn get_pdu(&self, event_id: &EventId) -> Result>> { self.db.get_pdu(event_id) } /// Returns the pdu. /// /// This does __NOT__ check the outliers `Tree`. - pub fn get_pdu_from_id(&self, pdu_id: &[u8]) -> Result> { + pub(crate) fn get_pdu_from_id(&self, pdu_id: &[u8]) -> Result> { self.db.get_pdu_from_id(pdu_id) } /// Returns the pdu as a `BTreeMap`. - pub fn get_pdu_json_from_id(&self, pdu_id: &[u8]) -> Result> { + pub(crate) fn get_pdu_json_from_id( + &self, + pdu_id: &[u8], + ) -> Result> { self.db.get_pdu_json_from_id(pdu_id) } /// Removes a pdu and creates a new one with the same id. #[tracing::instrument(skip(self))] - pub fn replace_pdu( + pub(crate) fn replace_pdu( &self, pdu_id: &[u8], pdu_json: &CanonicalJsonObject, @@ -199,7 +206,7 @@ impl Service { /// /// Returns pdu id #[tracing::instrument(skip(self, pdu, pdu_json, leaves))] - pub async fn append_pdu<'a>( + pub(crate) async fn append_pdu<'a>( &self, pdu: &PduEvent, mut pdu_json: CanonicalJsonObject, @@ -624,7 +631,7 @@ impl Service { Ok(pdu_id) } - pub fn create_hash_and_sign_event( + pub(crate) fn create_hash_and_sign_event( &self, pdu_builder: PduBuilder, sender: &UserId, @@ -807,7 +814,7 @@ impl Service { /// Creates a new persisted data unit and adds it to a room. This function takes a /// roomid_mutex_state, meaning that only this function is able to mutate the room state. #[tracing::instrument(skip(self, state_lock))] - pub async fn build_and_append_pdu( + pub(crate) async fn build_and_append_pdu( &self, pdu_builder: PduBuilder, sender: &UserId, @@ -1007,7 +1014,7 @@ impl Service { /// Append the incoming event setting the state snapshot to the state from the /// server that sent the event. #[tracing::instrument(skip_all)] - pub async fn append_incoming_pdu<'a>( + pub(crate) async fn append_incoming_pdu<'a>( &self, pdu: &PduEvent, pdu_json: CanonicalJsonObject, @@ -1047,7 +1054,7 @@ impl Service { } /// Returns an iterator over all PDUs in a room. - pub fn all_pdus<'a>( + pub(crate) fn all_pdus<'a>( &'a self, user_id: &UserId, room_id: &RoomId, @@ -1058,7 +1065,7 @@ impl Service { /// Returns an iterator over all events and their tokens in a room that happened before the /// event with id `until` in reverse-chronological order. #[tracing::instrument(skip(self))] - pub fn pdus_until<'a>( + pub(crate) fn pdus_until<'a>( &'a self, user_id: &UserId, room_id: &RoomId, @@ -1070,7 +1077,7 @@ impl Service { /// Returns an iterator over all events and their token in a room that happened after the event /// with id `from` in chronological order. #[tracing::instrument(skip(self))] - pub fn pdus_after<'a>( + pub(crate) fn pdus_after<'a>( &'a self, user_id: &UserId, room_id: &RoomId, @@ -1081,7 +1088,7 @@ impl Service { /// Replace a PDU with the redacted form. #[tracing::instrument(skip(self, reason))] - pub fn redact_pdu(&self, event_id: &EventId, reason: &PduEvent) -> Result<()> { + pub(crate) fn redact_pdu(&self, event_id: &EventId, reason: &PduEvent) -> Result<()> { // TODO: Don't reserialize, keep original json if let Some(pdu_id) = self.get_pdu_id(event_id)? { let mut pdu = self @@ -1100,7 +1107,11 @@ impl Service { } #[tracing::instrument(skip(self, room_id))] - pub async fn backfill_if_required(&self, room_id: &RoomId, from: PduCount) -> Result<()> { + pub(crate) async fn backfill_if_required( + &self, + room_id: &RoomId, + from: PduCount, + ) -> Result<()> { let first_pdu = self .all_pdus(user_id!("@doesntmatter:grapevine"), room_id)? .next() @@ -1165,7 +1176,7 @@ impl Service { } #[tracing::instrument(skip(self, pdu))] - pub async fn backfill_pdu( + pub(crate) async fn backfill_pdu( &self, origin: &ServerName, pdu: Box, diff --git a/src/service/rooms/timeline/data.rs b/src/service/rooms/timeline/data.rs index 6290b8cc..025e3ef0 100644 --- a/src/service/rooms/timeline/data.rs +++ b/src/service/rooms/timeline/data.rs @@ -6,7 +6,7 @@ use crate::{PduEvent, Result}; use super::PduCount; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result; /// Returns the `count` of this pdu's id. diff --git a/src/service/rooms/user.rs b/src/service/rooms/user.rs index 672e502d..f50754f8 100644 --- a/src/service/rooms/user.rs +++ b/src/service/rooms/user.rs @@ -1,32 +1,36 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId}; use crate::Result; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { - pub fn reset_notification_counts(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> { + pub(crate) fn reset_notification_counts( + &self, + user_id: &UserId, + room_id: &RoomId, + ) -> Result<()> { self.db.reset_notification_counts(user_id, room_id) } - pub fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub(crate) fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.notification_count(user_id, room_id) } - pub fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub(crate) fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.highlight_count(user_id, room_id) } - pub fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub(crate) fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.last_notification_read(user_id, room_id) } - pub fn associate_token_shortstatehash( + pub(crate) fn associate_token_shortstatehash( &self, room_id: &RoomId, token: u64, @@ -36,11 +40,15 @@ impl Service { .associate_token_shortstatehash(room_id, token, shortstatehash) } - pub fn get_token_shortstatehash(&self, room_id: &RoomId, token: u64) -> Result> { + pub(crate) fn get_token_shortstatehash( + &self, + room_id: &RoomId, + token: u64, + ) -> Result> { self.db.get_token_shortstatehash(room_id, token) } - pub fn get_shared_rooms( + pub(crate) fn get_shared_rooms( &self, users: Vec, ) -> Result>> { diff --git a/src/service/rooms/user/data.rs b/src/service/rooms/user/data.rs index 4b8a4eca..6b5f1cde 100644 --- a/src/service/rooms/user/data.rs +++ b/src/service/rooms/user/data.rs @@ -1,7 +1,7 @@ use crate::Result; use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn reset_notification_counts(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>; fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> Result; diff --git a/src/service/sending.rs b/src/service/sending.rs index 7e54e8b4..f873f5ab 100644 --- a/src/service/sending.rs +++ b/src/service/sending.rs @@ -1,6 +1,6 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use std::{ collections::{BTreeMap, HashMap, HashSet}, @@ -45,7 +45,7 @@ use tokio::{ use tracing::{debug, error, warn}; #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub enum OutgoingKind { +pub(crate) enum OutgoingKind { Appservice(String), Push(OwnedUserId, String), // user and pushkey Normal(OwnedServerName), @@ -53,7 +53,7 @@ pub enum OutgoingKind { impl OutgoingKind { #[tracing::instrument(skip(self))] - pub fn get_prefix(&self) -> Vec { + pub(crate) fn get_prefix(&self) -> Vec { let mut prefix = match self { OutgoingKind::Appservice(server) => { let mut p = b"+".to_vec(); @@ -80,17 +80,17 @@ impl OutgoingKind { } #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub enum SendingEventType { +pub(crate) enum SendingEventType { Pdu(Vec), // pduid Edu(Vec), // pdu json } -pub struct Service { +pub(crate) struct Service { db: &'static dyn Data, /// The state for a given state hash. pub(super) maximum_requests: Arc, - pub sender: mpsc::UnboundedSender<(OutgoingKind, SendingEventType, Vec)>, + pub(crate) sender: mpsc::UnboundedSender<(OutgoingKind, SendingEventType, Vec)>, receiver: Mutex)>>, } @@ -101,7 +101,7 @@ enum TransactionStatus { } impl Service { - pub fn build(db: &'static dyn Data, config: &Config) -> Arc { + pub(crate) fn build(db: &'static dyn Data, config: &Config) -> Arc { let (sender, receiver) = mpsc::unbounded_channel(); Arc::new(Self { db, @@ -111,7 +111,7 @@ impl Service { }) } - pub fn start_handler(self: &Arc) { + pub(crate) fn start_handler(self: &Arc) { let self2 = Arc::clone(self); tokio::spawn(async move { self2.handler().await.unwrap(); @@ -267,7 +267,7 @@ impl Service { } #[tracing::instrument(skip(self, server_name))] - pub fn select_edus(&self, server_name: &ServerName) -> Result<(Vec>, u64)> { + pub(crate) fn select_edus(&self, server_name: &ServerName) -> Result<(Vec>, u64)> { // u64: count of last edu let since = self.db.get_latest_educount(server_name)?; let mut events = Vec::new(); @@ -370,7 +370,12 @@ impl Service { } #[tracing::instrument(skip(self, pdu_id, user, pushkey))] - pub fn send_push_pdu(&self, pdu_id: &[u8], user: &UserId, pushkey: String) -> Result<()> { + pub(crate) fn send_push_pdu( + &self, + pdu_id: &[u8], + user: &UserId, + pushkey: String, + ) -> Result<()> { let outgoing_kind = OutgoingKind::Push(user.to_owned(), pushkey); let event = SendingEventType::Pdu(pdu_id.to_owned()); let keys = self.db.queue_requests(&[(&outgoing_kind, event.clone())])?; @@ -382,7 +387,7 @@ impl Service { } #[tracing::instrument(skip(self, servers, pdu_id))] - pub fn send_pdu>( + pub(crate) fn send_pdu>( &self, servers: I, pdu_id: &[u8], @@ -412,7 +417,7 @@ impl Service { } #[tracing::instrument(skip(self, server, serialized))] - pub fn send_reliable_edu( + pub(crate) fn send_reliable_edu( &self, server: &ServerName, serialized: Vec, @@ -429,7 +434,7 @@ impl Service { } #[tracing::instrument(skip(self))] - pub fn send_pdu_appservice(&self, appservice_id: String, pdu_id: Vec) -> Result<()> { + pub(crate) fn send_pdu_appservice(&self, appservice_id: String, pdu_id: Vec) -> Result<()> { let outgoing_kind = OutgoingKind::Appservice(appservice_id); let event = SendingEventType::Pdu(pdu_id); let keys = self.db.queue_requests(&[(&outgoing_kind, event.clone())])?; @@ -444,7 +449,7 @@ impl Service { /// Used for instance after we remove an appservice registration /// #[tracing::instrument(skip(self))] - pub fn cleanup_events(&self, appservice_id: String) -> Result<()> { + pub(crate) fn cleanup_events(&self, appservice_id: String) -> Result<()> { self.db .delete_all_requests_for(&OutgoingKind::Appservice(appservice_id))?; @@ -675,7 +680,7 @@ impl Service { } #[tracing::instrument(skip(self, destination, request))] - pub async fn send_federation_request( + pub(crate) async fn send_federation_request( &self, destination: &ServerName, request: T, @@ -704,7 +709,7 @@ impl Service { /// /// Only returns None if there is no url specified in the appservice registration file #[tracing::instrument(skip(self, registration, request))] - pub async fn send_appservice_request( + pub(crate) async fn send_appservice_request( &self, registration: Registration, request: T, diff --git a/src/service/sending/data.rs b/src/service/sending/data.rs index 8b4d236f..f2351534 100644 --- a/src/service/sending/data.rs +++ b/src/service/sending/data.rs @@ -4,7 +4,7 @@ use crate::Result; use super::{OutgoingKind, SendingEventType}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { #[allow(clippy::type_complexity)] fn active_requests<'a>( &'a self, diff --git a/src/service/transaction_ids.rs b/src/service/transaction_ids.rs index 2fa3b02e..b28919c5 100644 --- a/src/service/transaction_ids.rs +++ b/src/service/transaction_ids.rs @@ -1,16 +1,16 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use crate::Result; use ruma::{DeviceId, TransactionId, UserId}; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { - pub fn add_txnid( + pub(crate) fn add_txnid( &self, user_id: &UserId, device_id: Option<&DeviceId>, @@ -20,7 +20,7 @@ impl Service { self.db.add_txnid(user_id, device_id, txn_id, data) } - pub fn existing_txnid( + pub(crate) fn existing_txnid( &self, user_id: &UserId, device_id: Option<&DeviceId>, diff --git a/src/service/transaction_ids/data.rs b/src/service/transaction_ids/data.rs index 74855318..6964abcd 100644 --- a/src/service/transaction_ids/data.rs +++ b/src/service/transaction_ids/data.rs @@ -1,7 +1,7 @@ use crate::Result; use ruma::{DeviceId, TransactionId, UserId}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn add_txnid( &self, user_id: &UserId, diff --git a/src/service/uiaa.rs b/src/service/uiaa.rs index ed39af99..190fb195 100644 --- a/src/service/uiaa.rs +++ b/src/service/uiaa.rs @@ -1,6 +1,6 @@ mod data; -pub use data::Data; +pub(crate) use data::Data; use ruma::{ api::client::{ @@ -13,13 +13,13 @@ use tracing::error; use crate::{api::client_server::SESSION_ID_LENGTH, services, utils, Error, Result}; -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, } impl Service { /// Creates a new Uiaa session. Make sure the session token is unique. - pub fn create( + pub(crate) fn create( &self, user_id: &UserId, device_id: &DeviceId, @@ -40,7 +40,7 @@ impl Service { ) } - pub fn try_auth( + pub(crate) fn try_auth( &self, user_id: &UserId, device_id: &DeviceId, @@ -145,7 +145,7 @@ impl Service { Ok((true, uiaainfo)) } - pub fn get_uiaa_request( + pub(crate) fn get_uiaa_request( &self, user_id: &UserId, device_id: &DeviceId, diff --git a/src/service/uiaa/data.rs b/src/service/uiaa/data.rs index c64deb90..9a63fbb8 100644 --- a/src/service/uiaa/data.rs +++ b/src/service/uiaa/data.rs @@ -1,7 +1,7 @@ use crate::Result; use ruma::{api::client::uiaa::UiaaInfo, CanonicalJsonValue, DeviceId, UserId}; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { fn set_uiaa_request( &self, user_id: &UserId, diff --git a/src/service/users.rs b/src/service/users.rs index fb983a41..6520446d 100644 --- a/src/service/users.rs +++ b/src/service/users.rs @@ -5,7 +5,7 @@ use std::{ sync::{Arc, Mutex}, }; -pub use data::Data; +pub(crate) use data::Data; use ruma::{ api::client::{ device::Device, @@ -25,27 +25,27 @@ use ruma::{ use crate::{services, Error, Result}; -pub struct SlidingSyncCache { +pub(crate) struct SlidingSyncCache { lists: BTreeMap, subscriptions: BTreeMap, known_rooms: BTreeMap>, // For every room, the roomsince number extensions: ExtensionsConfig, } -pub struct Service { - pub db: &'static dyn Data, +pub(crate) struct Service { + pub(crate) db: &'static dyn Data, #[allow(clippy::type_complexity)] - pub connections: + pub(crate) connections: Mutex>>>, } impl Service { /// Check if a user has an account on this homeserver. - pub fn exists(&self, user_id: &UserId) -> Result { + pub(crate) fn exists(&self, user_id: &UserId) -> Result { self.db.exists(user_id) } - pub fn forget_sync_request_connection( + pub(crate) fn forget_sync_request_connection( &self, user_id: OwnedUserId, device_id: OwnedDeviceId, @@ -57,7 +57,7 @@ impl Service { .remove(&(user_id, device_id, conn_id)); } - pub fn update_sync_request_with_cache( + pub(crate) fn update_sync_request_with_cache( &self, user_id: OwnedUserId, device_id: OwnedDeviceId, @@ -186,7 +186,7 @@ impl Service { cached.known_rooms.clone() } - pub fn update_sync_subscriptions( + pub(crate) fn update_sync_subscriptions( &self, user_id: OwnedUserId, device_id: OwnedDeviceId, @@ -212,7 +212,7 @@ impl Service { cached.subscriptions = subscriptions; } - pub fn update_sync_known_rooms( + pub(crate) fn update_sync_known_rooms( &self, user_id: OwnedUserId, device_id: OwnedDeviceId, @@ -254,12 +254,12 @@ impl Service { } /// Check if account is deactivated - pub fn is_deactivated(&self, user_id: &UserId) -> Result { + pub(crate) fn is_deactivated(&self, user_id: &UserId) -> Result { self.db.is_deactivated(user_id) } /// Check if a user is an admin - pub fn is_admin(&self, user_id: &UserId) -> Result { + pub(crate) fn is_admin(&self, user_id: &UserId) -> Result { let admin_room_alias_id = RoomAliasId::parse(format!("#admins:{}", services().globals.server_name())) .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid alias."))?; @@ -276,75 +276,83 @@ impl Service { } /// Create a new user account on this homeserver. - pub fn create(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { + pub(crate) fn create(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { self.db.set_password(user_id, password)?; Ok(()) } /// Returns the number of users registered on this server. - pub fn count(&self) -> Result { + pub(crate) fn count(&self) -> Result { self.db.count() } /// Find out which user an access token belongs to. - pub fn find_from_token(&self, token: &str) -> Result> { + pub(crate) fn find_from_token(&self, token: &str) -> Result> { self.db.find_from_token(token) } /// Returns an iterator over all users on this homeserver. - pub fn iter(&self) -> impl Iterator> + '_ { + pub(crate) fn iter(&self) -> impl Iterator> + '_ { self.db.iter() } /// Returns a list of local users as list of usernames. /// /// A user account is considered `local` if the length of it's password is greater then zero. - pub fn list_local_users(&self) -> Result> { + pub(crate) fn list_local_users(&self) -> Result> { self.db.list_local_users() } /// Returns the password hash for the given user. - pub fn password_hash(&self, user_id: &UserId) -> Result> { + pub(crate) fn password_hash(&self, user_id: &UserId) -> Result> { self.db.password_hash(user_id) } /// Hash and set the user's password to the Argon2 hash - pub fn set_password(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { + pub(crate) fn set_password(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { self.db.set_password(user_id, password) } /// Returns the displayname of a user on this homeserver. - pub fn displayname(&self, user_id: &UserId) -> Result> { + pub(crate) fn displayname(&self, user_id: &UserId) -> Result> { self.db.displayname(user_id) } /// Sets a new displayname or removes it if displayname is None. You still need to nofify all rooms of this change. - pub fn set_displayname(&self, user_id: &UserId, displayname: Option) -> Result<()> { + pub(crate) fn set_displayname( + &self, + user_id: &UserId, + displayname: Option, + ) -> Result<()> { self.db.set_displayname(user_id, displayname) } /// Get the avatar_url of a user. - pub fn avatar_url(&self, user_id: &UserId) -> Result> { + pub(crate) fn avatar_url(&self, user_id: &UserId) -> Result> { self.db.avatar_url(user_id) } /// Sets a new avatar_url or removes it if avatar_url is None. - pub fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option) -> Result<()> { + pub(crate) fn set_avatar_url( + &self, + user_id: &UserId, + avatar_url: Option, + ) -> Result<()> { self.db.set_avatar_url(user_id, avatar_url) } /// Get the blurhash of a user. - pub fn blurhash(&self, user_id: &UserId) -> Result> { + pub(crate) fn blurhash(&self, user_id: &UserId) -> Result> { self.db.blurhash(user_id) } /// Sets a new avatar_url or removes it if avatar_url is None. - pub fn set_blurhash(&self, user_id: &UserId, blurhash: Option) -> Result<()> { + pub(crate) fn set_blurhash(&self, user_id: &UserId, blurhash: Option) -> Result<()> { self.db.set_blurhash(user_id, blurhash) } /// Adds a new device to a user. - pub fn create_device( + pub(crate) fn create_device( &self, user_id: &UserId, device_id: &DeviceId, @@ -356,12 +364,12 @@ impl Service { } /// Removes a device from a user. - pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { + pub(crate) fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { self.db.remove_device(user_id, device_id) } /// Returns an iterator over all device ids of this user. - pub fn all_device_ids<'a>( + pub(crate) fn all_device_ids<'a>( &'a self, user_id: &UserId, ) -> impl Iterator> + 'a { @@ -369,11 +377,16 @@ impl Service { } /// Replaces the access token of one device. - pub fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> { + pub(crate) fn set_token( + &self, + user_id: &UserId, + device_id: &DeviceId, + token: &str, + ) -> Result<()> { self.db.set_token(user_id, device_id, token) } - pub fn add_one_time_key( + pub(crate) fn add_one_time_key( &self, user_id: &UserId, device_id: &DeviceId, @@ -384,11 +397,11 @@ impl Service { .add_one_time_key(user_id, device_id, one_time_key_key, one_time_key_value) } - pub fn last_one_time_keys_update(&self, user_id: &UserId) -> Result { + pub(crate) fn last_one_time_keys_update(&self, user_id: &UserId) -> Result { self.db.last_one_time_keys_update(user_id) } - pub fn take_one_time_key( + pub(crate) fn take_one_time_key( &self, user_id: &UserId, device_id: &DeviceId, @@ -397,7 +410,7 @@ impl Service { self.db.take_one_time_key(user_id, device_id, key_algorithm) } - pub fn count_one_time_keys( + pub(crate) fn count_one_time_keys( &self, user_id: &UserId, device_id: &DeviceId, @@ -405,7 +418,7 @@ impl Service { self.db.count_one_time_keys(user_id, device_id) } - pub fn add_device_keys( + pub(crate) fn add_device_keys( &self, user_id: &UserId, device_id: &DeviceId, @@ -414,7 +427,7 @@ impl Service { self.db.add_device_keys(user_id, device_id, device_keys) } - pub fn add_cross_signing_keys( + pub(crate) fn add_cross_signing_keys( &self, user_id: &UserId, master_key: &Raw, @@ -431,7 +444,7 @@ impl Service { ) } - pub fn sign_key( + pub(crate) fn sign_key( &self, target_id: &UserId, key_id: &str, @@ -441,7 +454,7 @@ impl Service { self.db.sign_key(target_id, key_id, signature, sender_id) } - pub fn keys_changed<'a>( + pub(crate) fn keys_changed<'a>( &'a self, user_or_room_id: &str, from: u64, @@ -450,11 +463,11 @@ impl Service { self.db.keys_changed(user_or_room_id, from, to) } - pub fn mark_device_key_update(&self, user_id: &UserId) -> Result<()> { + pub(crate) fn mark_device_key_update(&self, user_id: &UserId) -> Result<()> { self.db.mark_device_key_update(user_id) } - pub fn get_device_keys( + pub(crate) fn get_device_keys( &self, user_id: &UserId, device_id: &DeviceId, @@ -462,7 +475,7 @@ impl Service { self.db.get_device_keys(user_id, device_id) } - pub fn parse_master_key( + pub(crate) fn parse_master_key( &self, user_id: &UserId, master_key: &Raw, @@ -470,7 +483,7 @@ impl Service { self.db.parse_master_key(user_id, master_key) } - pub fn get_key( + pub(crate) fn get_key( &self, key: &[u8], sender_user: Option<&UserId>, @@ -481,7 +494,7 @@ impl Service { .get_key(key, sender_user, user_id, allowed_signatures) } - pub fn get_master_key( + pub(crate) fn get_master_key( &self, sender_user: Option<&UserId>, user_id: &UserId, @@ -491,7 +504,7 @@ impl Service { .get_master_key(sender_user, user_id, allowed_signatures) } - pub fn get_self_signing_key( + pub(crate) fn get_self_signing_key( &self, sender_user: Option<&UserId>, user_id: &UserId, @@ -501,11 +514,14 @@ impl Service { .get_self_signing_key(sender_user, user_id, allowed_signatures) } - pub fn get_user_signing_key(&self, user_id: &UserId) -> Result>> { + pub(crate) fn get_user_signing_key( + &self, + user_id: &UserId, + ) -> Result>> { self.db.get_user_signing_key(user_id) } - pub fn add_to_device_event( + pub(crate) fn add_to_device_event( &self, sender: &UserId, target_user_id: &UserId, @@ -522,7 +538,7 @@ impl Service { ) } - pub fn get_to_device_events( + pub(crate) fn get_to_device_events( &self, user_id: &UserId, device_id: &DeviceId, @@ -530,7 +546,7 @@ impl Service { self.db.get_to_device_events(user_id, device_id) } - pub fn remove_to_device_events( + pub(crate) fn remove_to_device_events( &self, user_id: &UserId, device_id: &DeviceId, @@ -539,7 +555,7 @@ impl Service { self.db.remove_to_device_events(user_id, device_id, until) } - pub fn update_device_metadata( + pub(crate) fn update_device_metadata( &self, user_id: &UserId, device_id: &DeviceId, @@ -549,7 +565,7 @@ impl Service { } /// Get device metadata. - pub fn get_device_metadata( + pub(crate) fn get_device_metadata( &self, user_id: &UserId, device_id: &DeviceId, @@ -557,11 +573,11 @@ impl Service { self.db.get_device_metadata(user_id, device_id) } - pub fn get_devicelist_version(&self, user_id: &UserId) -> Result> { + pub(crate) fn get_devicelist_version(&self, user_id: &UserId) -> Result> { self.db.get_devicelist_version(user_id) } - pub fn all_devices_metadata<'a>( + pub(crate) fn all_devices_metadata<'a>( &'a self, user_id: &UserId, ) -> impl Iterator> + 'a { @@ -569,7 +585,7 @@ impl Service { } /// Deactivate account - pub fn deactivate_account(&self, user_id: &UserId) -> Result<()> { + pub(crate) fn deactivate_account(&self, user_id: &UserId) -> Result<()> { // Remove all associated devices for device_id in self.all_device_ids(user_id) { self.remove_device(user_id, &device_id?)?; @@ -585,11 +601,15 @@ impl Service { } /// Creates a new sync filter. Returns the filter id. - pub fn create_filter(&self, user_id: &UserId, filter: &FilterDefinition) -> Result { + pub(crate) fn create_filter( + &self, + user_id: &UserId, + filter: &FilterDefinition, + ) -> Result { self.db.create_filter(user_id, filter) } - pub fn get_filter( + pub(crate) fn get_filter( &self, user_id: &UserId, filter_id: &str, @@ -599,7 +619,7 @@ impl Service { } /// Ensure that a user only sees signatures from themselves and the target user -pub fn clean_signatures bool>( +pub(crate) fn clean_signatures bool>( cross_signing_key: &mut serde_json::Value, sender_user: Option<&UserId>, user_id: &UserId, diff --git a/src/service/users/data.rs b/src/service/users/data.rs index ddf941e3..7a9b2610 100644 --- a/src/service/users/data.rs +++ b/src/service/users/data.rs @@ -9,7 +9,7 @@ use ruma::{ }; use std::collections::BTreeMap; -pub trait Data: Send + Sync { +pub(crate) trait Data: Send + Sync { /// Check if a user has an account on this homeserver. fn exists(&self, user_id: &UserId) -> Result; diff --git a/src/utils.rs b/src/utils.rs index 0ac81b62..a38a3fc6 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,4 @@ -pub mod error; +pub(crate) mod error; use argon2::{Config, Variant}; use cmp::Ordering; @@ -11,7 +11,7 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; -pub fn millis_since_unix_epoch() -> u64 { +pub(crate) fn millis_since_unix_epoch() -> u64 { SystemTime::now() .duration_since(UNIX_EPOCH) .expect("time is valid") @@ -19,7 +19,7 @@ pub fn millis_since_unix_epoch() -> u64 { } #[cfg(any(feature = "rocksdb", feature = "sqlite"))] -pub fn increment(old: Option<&[u8]>) -> Option> { +pub(crate) fn increment(old: Option<&[u8]>) -> Option> { let number = match old.map(|bytes| bytes.try_into()) { Some(Ok(bytes)) => { let number = u64::from_be_bytes(bytes); @@ -31,7 +31,7 @@ pub fn increment(old: Option<&[u8]>) -> Option> { Some(number.to_be_bytes().to_vec()) } -pub fn generate_keypair() -> Vec { +pub(crate) fn generate_keypair() -> Vec { let mut value = random_string(8).as_bytes().to_vec(); value.push(0xff); value.extend_from_slice( @@ -42,17 +42,17 @@ pub fn generate_keypair() -> Vec { } /// Parses the bytes into an u64. -pub fn u64_from_bytes(bytes: &[u8]) -> Result { +pub(crate) fn u64_from_bytes(bytes: &[u8]) -> Result { let array: [u8; 8] = bytes.try_into()?; Ok(u64::from_be_bytes(array)) } /// Parses the bytes into a string. -pub fn string_from_bytes(bytes: &[u8]) -> Result { +pub(crate) fn string_from_bytes(bytes: &[u8]) -> Result { String::from_utf8(bytes.to_vec()) } -pub fn random_string(length: usize) -> String { +pub(crate) fn random_string(length: usize) -> String { thread_rng() .sample_iter(&rand::distributions::Alphanumeric) .take(length) @@ -61,7 +61,7 @@ pub fn random_string(length: usize) -> String { } /// Calculate a new hash for the given password -pub fn calculate_password_hash(password: &str) -> Result { +pub(crate) fn calculate_password_hash(password: &str) -> Result { let hashing_config = Config { variant: Variant::Argon2id, ..Default::default() @@ -72,14 +72,14 @@ pub fn calculate_password_hash(password: &str) -> Result } #[tracing::instrument(skip(keys))] -pub fn calculate_hash(keys: &[&[u8]]) -> Vec { +pub(crate) fn calculate_hash(keys: &[&[u8]]) -> Vec { // We only hash the pdu's event ids, not the whole pdu let bytes = keys.join(&0xff); let hash = digest::digest(&digest::SHA256, &bytes); hash.as_ref().to_owned() } -pub fn common_elements( +pub(crate) fn common_elements( mut iterators: impl Iterator>>, check_order: impl Fn(&[u8], &[u8]) -> Ordering, ) -> Option>> { @@ -106,7 +106,7 @@ pub fn common_elements( /// Fallible conversion from any value that implements `Serialize` to a `CanonicalJsonObject`. /// /// `value` must serialize to an `serde_json::Value::Object`. -pub fn to_canonical_object( +pub(crate) fn to_canonical_object( value: T, ) -> Result { use serde::ser::Error; @@ -119,7 +119,7 @@ pub fn to_canonical_object( } } -pub fn deserialize_from_str< +pub(crate) fn deserialize_from_str< 'de, D: serde::de::Deserializer<'de>, T: FromStr, @@ -150,7 +150,7 @@ pub fn deserialize_from_str< /// Wrapper struct which will emit the HTML-escaped version of the contained /// string when passed to a format string. -pub struct HtmlEscape<'a>(pub &'a str); +pub(crate) struct HtmlEscape<'a>(pub(crate) &'a str); impl<'a> fmt::Display for HtmlEscape<'a> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/utils/error.rs b/src/utils/error.rs index 6fa7f7ec..f9c5b4ea 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -13,10 +13,10 @@ use tracing::{error, info}; use crate::RumaResponse; -pub type Result = std::result::Result; +pub(crate) type Result = std::result::Result; #[derive(Error, Debug)] -pub enum Error { +pub(crate) enum Error { #[cfg(feature = "sqlite")] #[error("There was a problem with the connection to the sqlite database: {source}")] SqliteError { @@ -77,19 +77,19 @@ pub enum Error { } impl Error { - pub fn bad_database(message: &'static str) -> Self { + pub(crate) fn bad_database(message: &'static str) -> Self { error!("BadDatabase: {}", message); Self::BadDatabase(message) } - pub fn bad_config(message: &'static str) -> Self { + pub(crate) fn bad_config(message: &'static str) -> Self { error!("BadConfig: {}", message); Self::BadConfig(message) } } impl Error { - pub fn to_response(&self) -> RumaResponse { + pub(crate) fn to_response(&self) -> RumaResponse { if let Self::Uiaa(uiaainfo) = self { return RumaResponse(UiaaResponse::AuthResponse(uiaainfo.clone())); } @@ -136,7 +136,7 @@ impl Error { } /// Sanitizes public-facing errors that can leak sensitive information. - pub fn sanitized_error(&self) -> String { + pub(crate) fn sanitized_error(&self) -> String { let db_error = String::from("Database or I/O error occurred."); match self {