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.
This commit is contained in:
Charles Hall 2024-05-01 22:26:21 -07:00
parent a626e7b0f0
commit d748544f0e
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
111 changed files with 1007 additions and 876 deletions

View file

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

View file

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

View file

@ -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<get_username_availability::v3::Request>,
) -> Result<get_username_availability::v3::Response> {
// 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<register::v3::Request>) -> Result<register::v3::Response> {
pub(crate) async fn register_route(
body: Ruma<register::v3::Request>,
) -> Result<register::v3::Response> {
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<register::v3::Request>) -> Result<registe
/// - 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 change_password_route(
pub(crate) async fn change_password_route(
body: Ruma<change_password::v3::Request>,
) -> Result<change_password::v3::Response> {
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<whoami::v3::Request>) -> Result<whoami::v3::Response> {
pub(crate) async fn whoami_route(body: Ruma<whoami::v3::Request>) -> Result<whoami::v3::Response> {
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<whoami::v3::Request>) -> Result<whoami::v3:
/// - Forgets all to-device events
/// - Triggers device list updates
/// - Removes ability to log in again
pub async fn deactivate_route(
pub(crate) async fn deactivate_route(
body: Ruma<deactivate::v3::Request>,
) -> Result<deactivate::v3::Response> {
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<get_3pids::v3::Request>,
) -> Result<get_3pids::v3::Response> {
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<request_3pid_management_token_via_email::v3::Request>,
) -> Result<request_3pid_management_token_via_email::v3::Response> {
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<request_3pid_management_token_via_msisdn::v3::Request>,
) -> Result<request_3pid_management_token_via_msisdn::v3::Response> {
Err(Error::BadRequest(

View file

@ -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<create_alias::v3::Request>,
) -> Result<create_alias::v3::Response> {
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<delete_alias::v3::Request>,
) -> Result<delete_alias::v3::Response> {
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<get_alias::v3::Request>,
) -> Result<get_alias::v3::Response> {
get_alias_helper(body.body.room_alias).await

View file

@ -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<create_backup_version::v3::Request>,
) -> Result<create_backup_version::v3::Response> {
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<update_backup_version::v3::Request>,
) -> Result<update_backup_version::v3::Response> {
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<get_latest_backup_info::v3::Request>,
) -> Result<get_latest_backup_info::v3::Response> {
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<get_backup_info::v3::Request>,
) -> Result<get_backup_info::v3::Response> {
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<delete_backup_version::v3::Request>,
) -> Result<delete_backup_version::v3::Response> {
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<add_backup_keys::v3::Request>,
) -> Result<add_backup_keys::v3::Response> {
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<add_backup_keys_for_room::v3::Request>,
) -> Result<add_backup_keys_for_room::v3::Response> {
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<add_backup_keys_for_session::v3::Request>,
) -> Result<add_backup_keys_for_session::v3::Response> {
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<get_backup_keys::v3::Request>,
) -> Result<get_backup_keys::v3::Response> {
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<get_backup_keys_for_room::v3::Request>,
) -> Result<get_backup_keys_for_room::v3::Response> {
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<get_backup_keys_for_session::v3::Request>,
) -> Result<get_backup_keys_for_session::v3::Response> {
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<delete_backup_keys::v3::Request>,
) -> Result<delete_backup_keys::v3::Response> {
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<delete_backup_keys_for_room::v3::Request>,
) -> Result<delete_backup_keys_for_room::v3::Response> {
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<delete_backup_keys_for_session::v3::Request>,
) -> Result<delete_backup_keys_for_session::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<get_capabilities::v3::Request>,
) -> Result<get_capabilities::v3::Response> {
let mut available = BTreeMap::new();

View file

@ -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<set_global_account_data::v3::Request>,
) -> Result<set_global_account_data::v3::Response> {
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<set_room_account_data::v3::Request>,
) -> Result<set_room_account_data::v3::Response> {
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<get_global_account_data::v3::Request>,
) -> Result<get_global_account_data::v3::Response> {
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<get_room_account_data::v3::Request>,
) -> Result<get_room_account_data::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<get_context::v3::Request>,
) -> Result<get_context::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<get_devices::v3::Request>,
) -> Result<get_devices::v3::Response> {
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<get_device::v3::Request>,
) -> Result<get_device::v3::Response> {
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<update_device::v3::Request>,
) -> Result<update_device::v3::Response> {
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<delete_device::v3::Request>,
) -> Result<delete_device::v3::Response> {
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<delete_devices::v3::Request>,
) -> Result<delete_devices::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<get_public_rooms_filtered::v3::Request>,
) -> Result<get_public_rooms_filtered::v3::Response> {
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<get_public_rooms::v3::Request>,
) -> Result<get_public_rooms::v3::Response> {
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<set_room_visibility::v3::Request>,
) -> Result<set_room_visibility::v3::Response> {
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<get_room_visibility::v3::Request>,
) -> Result<get_room_visibility::v3::Response> {
if !services().rooms.metadata.exists(&body.room_id)? {

View file

@ -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<get_filter::v3::Request>,
) -> Result<get_filter::v3::Response> {
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<create_filter::v3::Request>,
) -> Result<create_filter::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<upload_keys::v3::Request>,
) -> Result<upload_keys::v3::Response> {
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<get_keys::v3::Request>) -> Result<get_keys::v3::Response> {
pub(crate) async fn get_keys_route(
body: Ruma<get_keys::v3::Request>,
) -> Result<get_keys::v3::Response> {
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<get_keys::v3::Request>) -> Result<get_key
/// # `POST /_matrix/client/r0/keys/claim`
///
/// Claims one-time keys
pub async fn claim_keys_route(
pub(crate) async fn claim_keys_route(
body: Ruma<claim_keys::v3::Request>,
) -> Result<claim_keys::v3::Response> {
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<upload_signing_keys::v3::Request>,
) -> Result<upload_signing_keys::v3::Response> {
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<upload_signatures::v3::Request>,
) -> Result<upload_signatures::v3::Response> {
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<get_key_changes::v3::Request>,
) -> Result<get_key_changes::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<get_media_config::v3::Request>,
) -> Result<get_media_config::v3::Response> {
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<create_content::v3::Request>,
) -> Result<create_content::v3::Response> {
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<get_content::v3::Request>,
) -> Result<get_content::v3::Response> {
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<get_content_as_filename::v3::Request>,
) -> Result<get_content_as_filename::v3::Response> {
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<get_content_thumbnail::v3::Request>,
) -> Result<get_content_thumbnail::v3::Response> {
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);

View file

@ -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<join_room_by_id::v3::Request>,
) -> Result<join_room_by_id::v3::Response> {
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<join_room_by_id_or_alias::v3::Request>,
) -> Result<join_room_by_id_or_alias::v3::Response> {
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<leave_room::v3::Request>,
) -> Result<leave_room::v3::Response> {
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<invite_user::v3::Request>,
) -> Result<invite_user::v3::Response> {
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<kick_user::v3::Request>,
) -> Result<kick_user::v3::Response> {
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<ban_user::v3::Request>) -> Result<ban_user::v3::Response> {
pub(crate) async fn ban_user_route(
body: Ruma<ban_user::v3::Request>,
) -> Result<ban_user::v3::Response> {
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<ban_user::v3::Request>) -> Result<ban_use
/// # `POST /_matrix/client/r0/rooms/{roomId}/unban`
///
/// Tries to send an unban event into the room.
pub async fn unban_user_route(
pub(crate) async fn unban_user_route(
body: Ruma<unban_user::v3::Request>,
) -> Result<unban_user::v3::Response> {
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<forget_room::v3::Request>,
) -> Result<forget_room::v3::Response> {
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<joined_rooms::v3::Request>,
) -> Result<joined_rooms::v3::Response> {
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<get_member_events::v3::Request>,
) -> Result<get_member_events::v3::Response> {
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<joined_members::v3::Request>,
) -> Result<joined_members::v3::Response> {
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<String>) -> Result<()> {
pub(crate) async fn leave_room(
user_id: &UserId,
room_id: &RoomId,
reason: Option<String>,
) -> Result<()> {
// Ask a remote server if we don't have this room
if !services()
.rooms

View file

@ -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<send_message_event::v3::Request>,
) -> Result<send_message_event::v3::Response> {
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<get_message_events::v3::Request>,
) -> Result<get_message_events::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<set_display_name::v3::Request>,
) -> Result<set_display_name::v3::Response> {
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<get_display_name::v3::Request>,
) -> Result<get_display_name::v3::Response> {
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<set_avatar_url::v3::Request>,
) -> Result<set_avatar_url::v3::Response> {
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<get_avatar_url::v3::Request>,
) -> Result<get_avatar_url::v3::Response> {
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<get_profile::v3::Request>,
) -> Result<get_profile::v3::Response> {
if body.user_id.server_name() != services().globals.server_name() {

View file

@ -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<get_pushrules_all::v3::Request>,
) -> Result<get_pushrules_all::v3::Response> {
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<get_pushrule::v3::Request>,
) -> Result<get_pushrule::v3::Response> {
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<set_pushrule::v3::Request>,
) -> Result<set_pushrule::v3::Response> {
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<get_pushrule_actions::v3::Request>,
) -> Result<get_pushrule_actions::v3::Response> {
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<set_pushrule_actions::v3::Request>,
) -> Result<set_pushrule_actions::v3::Response> {
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<get_pushrule_enabled::v3::Request>,
) -> Result<get_pushrule_enabled::v3::Response> {
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<set_pushrule_enabled::v3::Request>,
) -> Result<set_pushrule_enabled::v3::Response> {
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<delete_pushrule::v3::Request>,
) -> Result<delete_pushrule::v3::Response> {
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<get_pushers::v3::Request>,
) -> Result<get_pushers::v3::Response> {
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<set_pusher::v3::Request>,
) -> Result<set_pusher::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<set_read_marker::v3::Request>,
) -> Result<set_read_marker::v3::Response> {
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<create_receipt::v3::Request>,
) -> Result<create_receipt::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<redact_event::v3::Request>,
) -> Result<redact_event::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<get_relating_events_with_rel_type_and_event_type::v1::Request>,
) -> Result<get_relating_events_with_rel_type_and_event_type::v1::Response> {
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<get_relating_events_with_rel_type::v1::Request>,
) -> Result<get_relating_events_with_rel_type::v1::Response> {
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<get_relating_events::v1::Request>,
) -> Result<get_relating_events::v1::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<report_content::v3::Request>,
) -> Result<report_content::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<create_room::v3::Request>,
) -> Result<create_room::v3::Response> {
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<get_room_event::v3::Request>,
) -> Result<get_room_event::v3::Response> {
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<aliases::v3::Request>,
) -> Result<aliases::v3::Response> {
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<upgrade_room::v3::Request>,
) -> Result<upgrade_room::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<search_events::v3::Request>,
) -> Result<search_events::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<get_login_types::v3::Request>,
) -> Result<get_login_types::v3::Response> {
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<login::v3::Request>) -> Result<login::v3::Response> {
pub(crate) async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Response> {
// To allow deprecated login methods
#![allow(deprecated)]
// Validate login method
@ -223,7 +223,7 @@ pub async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Re
/// - 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 logout_route(body: Ruma<logout::v3::Request>) -> Result<logout::v3::Response> {
pub(crate) async fn logout_route(body: Ruma<logout::v3::Request>) -> Result<logout::v3::Response> {
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<logout::v3::Request>) -> Result<logout::v3:
///
/// Note: This is equivalent to calling [`GET /_matrix/client/r0/logout`](fn.logout_route.html)
/// from each device of this user.
pub async fn logout_all_route(
pub(crate) async fn logout_all_route(
body: Ruma<logout_all::v3::Request>,
) -> Result<logout_all::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<get_hierarchy::v1::Request>,
) -> Result<get_hierarchy::v1::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<send_state_event::v3::Request>,
) -> Result<send_state_event::v3::Response> {
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<send_state_event::v3::Request>,
) -> Result<RumaResponse<send_state_event::v3::Response>> {
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<get_state_events::v3::Request>,
) -> Result<get_state_events::v3::Response> {
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<get_state_events_for_key::v3::Request>,
) -> Result<get_state_events_for_key::v3::Response> {
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<get_state_events_for_key::v3::Request>,
) -> Result<RumaResponse<get_state_events_for_key::v3::Response>> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<sync_events::v3::Request>,
) -> Result<sync_events::v3::Response, RumaResponse<UiaaResponse>> {
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<sync_events::v4::Request>,
) -> Result<sync_events::v4::Response, RumaResponse<UiaaResponse>> {
let sender_user = body.sender_user.expect("user is authenticated");

View file

@ -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<create_tag::v3::Request>,
) -> Result<create_tag::v3::Response> {
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<delete_tag::v3::Request>,
) -> Result<delete_tag::v3::Response> {
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<get_tags::v3::Request>) -> Result<get_tags::v3::Response> {
pub(crate) async fn get_tags_route(
body: Ruma<get_tags::v3::Request>,
) -> Result<get_tags::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let event = services().account_data.get(

View file

@ -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<get_protocols::v3::Request>,
) -> Result<get_protocols::v3::Response> {
// TODO

View file

@ -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<get_threads::v1::Request>,
) -> Result<get_threads::v1::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<send_event_to_device::v3::Request>,
) -> Result<send_event_to_device::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -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<create_typing_event::v3::Request>,
) -> Result<create_typing_event::v3::Response> {
use create_typing_event::v3::Typing;

View file

@ -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<get_supported_versions::Request>,
) -> Result<get_supported_versions::Response> {
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<get_supported_versions::Request>,
) -> Result<impl IntoResponse> {
let client_url = match services().globals.well_known_client() {

View file

@ -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<search_users::v3::Request>,
) -> Result<search_users::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -10,7 +10,7 @@ type HmacSha1 = Hmac<Sha1>;
/// # `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<get_turn_server_info::v3::Request>,
) -> Result<get_turn_server_info::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");

View file

@ -8,14 +8,14 @@ use std::ops::Deref;
mod axum;
/// Extractor for Ruma request structs
pub struct Ruma<T> {
pub body: T,
pub sender_user: Option<OwnedUserId>,
pub sender_device: Option<OwnedDeviceId>,
pub sender_servername: Option<OwnedServerName>,
pub(crate) struct Ruma<T> {
pub(crate) body: T,
pub(crate) sender_user: Option<OwnedUserId>,
pub(crate) sender_device: Option<OwnedDeviceId>,
pub(crate) sender_servername: Option<OwnedServerName>,
// This is None when body is not a valid string
pub json_body: Option<CanonicalJsonValue>,
pub appservice_info: Option<RegistrationInfo>,
pub(crate) json_body: Option<CanonicalJsonValue>,
pub(crate) appservice_info: Option<RegistrationInfo>,
}
impl<T> Deref for Ruma<T> {
@ -27,7 +27,7 @@ impl<T> Deref for Ruma<T> {
}
#[derive(Clone)]
pub struct RumaResponse<T>(pub T);
pub(crate) struct RumaResponse<T>(pub(crate) T);
impl<T> From<T> for RumaResponse<T> {
fn from(t: T) -> Self {

View file

@ -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<String> {
/// # `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<get_server_version::v1::Request>,
) -> Result<get_server_version::v1::Response> {
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<impl IntoResponse> {
pub(crate) async fn get_server_keys_route() -> Result<impl IntoResponse> {
let mut verify_keys: BTreeMap<OwnedServerSigningKeyId, VerifyKey> = BTreeMap::new();
verify_keys.insert(
format!("ed25519:{}", services().globals.keypair().version())
@ -588,14 +588,14 @@ pub async fn get_server_keys_route() -> Result<impl IntoResponse> {
///
/// - 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<get_public_rooms_filtered::v1::Request>,
) -> Result<get_public_rooms_filtered::v1::Response> {
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<get_public_rooms::v1::Request>,
) -> Result<get_public_rooms::v1::Response> {
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<send_transaction_message::v1::Request>,
) -> Result<send_transaction_message::v1::Response> {
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<get_event::v1::Request>,
) -> Result<get_event::v1::Response> {
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<get_backfill::v1::Request>,
) -> Result<get_backfill::v1::Response> {
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<get_missing_events::v1::Request>,
) -> Result<get_missing_events::v1::Response> {
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<get_event_authorization::v1::Request>,
) -> Result<get_event_authorization::v1::Response> {
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<get_room_state::v1::Request>,
) -> Result<get_room_state::v1::Response> {
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<get_room_state_ids::v1::Request>,
) -> Result<get_room_state_ids::v1::Response> {
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<prepare_join_event::v1::Request>,
) -> Result<prepare_join_event::v1::Response> {
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<create_join_event::v1::Request>,
) -> Result<create_join_event::v1::Response> {
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<create_join_event::v2::Request>,
) -> Result<create_join_event::v2::Response> {
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<create_invite::v2::Request>,
) -> Result<create_invite::v2::Response> {
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<get_devices::v1::Request>,
) -> Result<get_devices::v1::Response> {
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<get_room_information::v1::Request>,
) -> Result<get_room_information::v1::Response> {
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<get_profile_information::v1::Request>,
) -> Result<get_profile_information::v1::Response> {
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<get_keys::v1::Request>) -> Result<get_keys::v1::Response> {
pub(crate) async fn get_keys_route(
body: Ruma<get_keys::v1::Request>,
) -> Result<get_keys::v1::Response> {
if body
.device_keys
.iter()
@ -1889,7 +1891,7 @@ pub async fn get_keys_route(body: Ruma<get_keys::v1::Request>) -> Result<get_key
/// # `POST /_matrix/federation/v1/user/keys/claim`
///
/// Claims one-time keys.
pub async fn claim_keys_route(
pub(crate) async fn claim_keys_route(
body: Ruma<claim_keys::v1::Request>,
) -> Result<claim_keys::v1::Response> {
if body

View file

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

View file

@ -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<TlsConfig>,
pub(crate) port: u16,
pub(crate) tls: Option<TlsConfig>,
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<String>,
pub(crate) allow_registration: bool,
pub(crate) registration_token: Option<String>,
#[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<String>,
pub(crate) default_room_version: RoomVersionId,
pub(crate) well_known_client: Option<String>,
#[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<String>,
pub(crate) proxy: ProxyConfig,
pub(crate) jwt_secret: Option<String>,
#[serde(default = "default_trusted_servers")]
pub trusted_servers: Vec<OwnedServerName>,
pub(crate) trusted_servers: Vec<OwnedServerName>,
#[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<String>,
pub(crate) turn_uris: Vec<String>,
#[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<String>,
pub(crate) emergency_password: Option<String>,
#[serde(flatten)]
pub catchall: BTreeMap<String, IgnoredAny>,
pub(crate) catchall: BTreeMap<String, IgnoredAny>,
}
#[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
}

View file

@ -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<PartialProxyConfig>),
}
impl ProxyConfig {
pub fn to_proxy(&self) -> Result<Option<Proxy>> {
pub(crate) fn to_proxy(&self) -> Result<Option<Proxy>> {
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<WildCardedDomain>,
}
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,

View file

@ -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<dyn KeyValueDatabaseEngine>,
//pub globals: globals::Globals,
//pub(crate) globals: globals::Globals,
pub(super) global: Arc<dyn KvTree>,
pub(super) server_signingkeys: Arc<dyn KvTree>,
//pub users: users::Users,
//pub(crate) users: users::Users,
pub(super) userid_password: Arc<dyn KvTree>,
pub(super) userid_displayname: Arc<dyn KvTree>,
pub(super) userid_avatarurl: Arc<dyn KvTree>,
@ -58,12 +58,12 @@ pub struct KeyValueDatabase {
pub(super) todeviceid_events: Arc<dyn KvTree>, // ToDeviceId = UserId + DeviceId + Count
//pub uiaa: uiaa::Uiaa,
//pub(crate) uiaa: uiaa::Uiaa,
pub(super) userdevicesessionid_uiaainfo: Arc<dyn KvTree>, // User-interactive authentication
pub(super) userdevicesessionid_uiaarequest:
RwLock<BTreeMap<(OwnedUserId, OwnedDeviceId, String), CanonicalJsonValue>>,
//pub edus: RoomEdus,
//pub(crate) edus: RoomEdus,
pub(super) readreceiptid_readreceipt: Arc<dyn KvTree>, // ReadReceiptId = RoomId + Count + UserId
pub(super) roomuserid_privateread: Arc<dyn KvTree>, // RoomUserId = Room + User, PrivateRead = Count
pub(super) roomuserid_lastprivatereadupdate: Arc<dyn KvTree>, // LastPrivateReadUpdate = Count
@ -74,7 +74,7 @@ pub struct KeyValueDatabase {
#[allow(dead_code)]
pub(super) userid_lastpresenceupdate: Arc<dyn KvTree>, // LastPresenceUpdate = Count
//pub rooms: rooms::Rooms,
//pub(crate) rooms: rooms::Rooms,
pub(super) pduid_pdu: Arc<dyn KvTree>, // PduId = ShortRoomId + Count
pub(super) eventid_pduid: Arc<dyn KvTree>,
pub(super) roomid_pduleaves: Arc<dyn KvTree>,
@ -137,28 +137,28 @@ pub struct KeyValueDatabase {
/// RoomId + EventId -> Parent PDU EventId.
pub(super) referencedevents: Arc<dyn KvTree>,
//pub account_data: account_data::AccountData,
//pub(crate) account_data: account_data::AccountData,
pub(super) roomuserdataid_accountdata: Arc<dyn KvTree>, // RoomUserDataId = Room + User + Count + Type
pub(super) roomusertype_roomuserdataid: Arc<dyn KvTree>, // RoomUserType = Room + User + Type
//pub media: media::Media,
//pub(crate) media: media::Media,
pub(super) mediaid_file: Arc<dyn KvTree>, // MediaId = MXC + WidthHeight + ContentDisposition + ContentType
//pub key_backups: key_backups::KeyBackups,
//pub(crate) key_backups: key_backups::KeyBackups,
pub(super) backupid_algorithm: Arc<dyn KvTree>, // BackupId = UserId + Version(Count)
pub(super) backupid_etag: Arc<dyn KvTree>, // BackupId = UserId + Version(Count)
pub(super) backupkeyid_backup: Arc<dyn KvTree>, // BackupKeyId = UserId + Version + RoomId + SessionId
//pub transaction_ids: transaction_ids::TransactionIds,
//pub(crate) transaction_ids: transaction_ids::TransactionIds,
pub(super) userdevicetxnid_response: Arc<dyn KvTree>, // Response can be empty (/sendToDevice) or the event id (/send)
//pub sending: sending::Sending,
//pub(crate) sending: sending::Sending,
pub(super) servername_educount: Arc<dyn KvTree>, // EduCount: Count of last EDU sync
pub(super) servernameevent_data: Arc<dyn KvTree>, // ServernameEvent = (+ / $)SenderKey / ServerName / UserId + PduId / Id (for edus), Data = EDU content
pub(super) servercurrentevent_data: Arc<dyn KvTree>, // ServerCurrentEvents = (+ / $)ServerName / UserId + PduId / Id (for edus), Data = EDU content
//pub appservice: appservice::Appservice,
//pub(crate) appservice: appservice::Appservice,
pub(super) id_appserviceregistrations: Arc<dyn KvTree>,
//pub pusher: pusher::PushData,
//pub(crate) pusher: pusher::PushData,
pub(super) senderkey_pusher: Arc<dyn KvTree>,
pub(super) pdu_cache: Mutex<LruCache<OwnedEventId, Arc<PduEvent>>>,
@ -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)]

View file

@ -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<Self>
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<Option<Vec<u8>>>;
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>;

View file

@ -6,14 +6,14 @@ use std::{
sync::{Arc, RwLock},
};
pub struct Engine {
pub(crate) struct Engine {
rocks: rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>,
max_open_files: i32,
cache: rocksdb::Cache,
old_cfs: Vec<String>,
}
pub struct RocksDbEngineTree<'a> {
pub(crate) struct RocksDbEngineTree<'a> {
db: Arc<Engine>,
name: &'a str,
watchers: Watchers,

View file

@ -18,8 +18,8 @@ thread_local! {
}
struct PreparedStatementIterator<'a> {
pub iterator: Box<dyn Iterator<Item = TupleOfBytes> + 'a>,
pub _statement_ref: NonAliasingBox<rusqlite::Statement<'a>>,
pub(crate) iterator: Box<dyn Iterator<Item = TupleOfBytes> + 'a>,
pub(crate) _statement_ref: NonAliasingBox<rusqlite::Statement<'a>>,
}
impl Iterator for PreparedStatementIterator<'_> {
@ -37,7 +37,7 @@ impl<T> Drop for NonAliasingBox<T> {
}
}
pub struct Engine {
pub(crate) struct Engine {
writer: Mutex<Connection>,
read_conn_tls: ThreadLocal<Connection>,
read_iterator_conn_tls: ThreadLocal<Connection>,
@ -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<Self>) -> Result<()> {
pub(crate) fn flush_wal(self: &Arc<Self>) -> Result<()> {
self.write_lock()
.pragma_update(Some(Main), "wal_checkpoint", "RESTART")?;
Ok(())
@ -125,7 +125,7 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
}
}
pub struct SqliteTable {
pub(crate) struct SqliteTable {
engine: Arc<Engine>,
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<dyn Iterator<Item = TupleOfBytes> + 'a> {

View file

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

View file

@ -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<Option<&'static Services>> = RwLock::new(None);
pub(crate) static SERVICES: RwLock<Option<&'static Services>> = 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<T> {
pub(crate) trait RumaHandler<T> {
// 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.

View file

@ -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<admin::Service>,
pub globals: globals::Service,
pub key_backups: key_backups::Service,
pub media: media::Service,
pub sending: Arc<sending::Service>,
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<admin::Service>,
pub(crate) globals: globals::Service,
pub(crate) key_backups: key_backups::Service,
pub(crate) media: media::Service,
pub(crate) sending: Arc<sending::Service>,
}
impl Services {
pub fn build<
pub(crate) fn build<
D: appservice::Data
+ pusher::Data
+ rooms::Data

View file

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

View file

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

View file

@ -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<AdminRoomEvent>,
pub(crate) struct Service {
pub(crate) sender: mpsc::UnboundedSender<AdminRoomEvent>,
receiver: Mutex<mpsc::UnboundedReceiver<AdminRoomEvent>>,
}
impl Service {
pub fn build() -> Arc<Self> {
pub(crate) fn build() -> Arc<Self> {
let (sender, receiver) = mpsc::unbounded_channel();
Arc::new(Self {
sender,
@ -200,7 +200,7 @@ impl Service {
})
}
pub fn start_handler(self: &Arc<Self>) {
pub(crate) fn start_handler(self: &Arc<Self>) {
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();

View file

@ -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<RegexSet>,
pub non_exclusive: Option<RegexSet>,
pub(crate) struct NamespaceRegex {
pub(crate) exclusive: Option<RegexSet>,
pub(crate) non_exclusive: Option<RegexSet>,
}
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<Vec<Namespace>> 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<Registration> 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<BTreeMap<String, RegistrationInfo>>,
}
impl Service {
pub fn build(db: &'static dyn Data) -> Result<Self> {
pub(crate) fn build(db: &'static dyn Data) -> Result<Self> {
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<String> {
pub(crate) async fn register_appservice(&self, yaml: Registration) -> Result<String> {
//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<Registration> {
pub(crate) async fn get_registration(&self, id: &str) -> Option<Registration> {
self.registration_info
.read()
.await
@ -174,7 +174,7 @@ impl Service {
.map(|info| info.registration)
}
pub async fn iter_ids(&self) -> Vec<String> {
pub(crate) async fn iter_ids(&self) -> Vec<String> {
self.registration_info
.read()
.await
@ -183,7 +183,7 @@ impl Service {
.collect()
}
pub async fn find_from_token(&self, token: &str) -> Option<RegistrationInfo> {
pub(crate) async fn find_from_token(&self, token: &str) -> Option<RegistrationInfo> {
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<Output = tokio::sync::RwLockReadGuard<'_, BTreeMap<String, RegistrationInfo>>>
{

View file

@ -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<String>;

View file

@ -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<Option<Result<sync_events::v3::Response>>>, // rx
);
pub struct Service {
pub db: &'static dyn Data,
pub(crate) struct Service {
pub(crate) db: &'static dyn Data,
pub actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host
pub tls_name_override: Arc<StdRwLock<TlsNameMap>>,
pub config: Config,
pub(crate) actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host
pub(crate) tls_name_override: Arc<StdRwLock<TlsNameMap>>,
pub(crate) config: Config,
keypair: Arc<ruma::signatures::Ed25519KeyPair>,
dns_resolver: TokioAsyncResolver,
jwt_decoding_key: Option<jsonwebtoken::DecodingKey>,
federation_client: reqwest::Client,
default_client: reqwest::Client,
pub stable_room_versions: Vec<RoomVersionId>,
pub unstable_room_versions: Vec<RoomVersionId>,
pub bad_event_ratelimiter: Arc<RwLock<HashMap<OwnedEventId, RateLimitState>>>,
pub bad_signature_ratelimiter: Arc<RwLock<HashMap<Vec<String>, RateLimitState>>>,
pub bad_query_ratelimiter: Arc<RwLock<HashMap<OwnedServerName, RateLimitState>>>,
pub servername_ratelimiter: Arc<RwLock<HashMap<OwnedServerName, Arc<Semaphore>>>>,
pub sync_receivers: RwLock<HashMap<(OwnedUserId, OwnedDeviceId), SyncHandle>>,
pub roomid_mutex_insert: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
pub roomid_mutex_state: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
pub roomid_mutex_federation: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>, // this lock will be held longer
pub roomid_federationhandletime: RwLock<HashMap<OwnedRoomId, (OwnedEventId, Instant)>>,
pub stateres_mutex: Arc<Mutex<()>>,
pub rotate: RotationHandler,
pub(crate) stable_room_versions: Vec<RoomVersionId>,
pub(crate) unstable_room_versions: Vec<RoomVersionId>,
pub(crate) bad_event_ratelimiter: Arc<RwLock<HashMap<OwnedEventId, RateLimitState>>>,
pub(crate) bad_signature_ratelimiter: Arc<RwLock<HashMap<Vec<String>, RateLimitState>>>,
pub(crate) bad_query_ratelimiter: Arc<RwLock<HashMap<OwnedServerName, RateLimitState>>>,
pub(crate) servername_ratelimiter: Arc<RwLock<HashMap<OwnedServerName, Arc<Semaphore>>>>,
pub(crate) sync_receivers: RwLock<HashMap<(OwnedUserId, OwnedDeviceId), SyncHandle>>,
pub(crate) roomid_mutex_insert: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
pub(crate) roomid_mutex_state: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>,
pub(crate) roomid_mutex_federation: RwLock<HashMap<OwnedRoomId, Arc<Mutex<()>>>>, // this lock will be held longer
pub(crate) roomid_federationhandletime: RwLock<HashMap<OwnedRoomId, (OwnedEventId, Instant)>>,
pub(crate) stateres_mutex: Arc<Mutex<()>>,
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<Output = ()> {
pub(crate) fn watch(&self) -> impl Future<Output = ()> {
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<StdRwLock<TlsNameMap>>,
}
impl Resolver {
pub fn new(overrides: Arc<StdRwLock<TlsNameMap>>) -> Self {
pub(crate) fn new(overrides: Arc<StdRwLock<TlsNameMap>>) -> 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<Self> {
pub(crate) fn load(db: &'static dyn Data, config: Config) -> Result<Self> {
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<u64> {
pub(crate) fn next_count(&self) -> Result<u64> {
self.db.next_count()
}
#[tracing::instrument(skip(self))]
pub fn current_count(&self) -> Result<u64> {
pub(crate) fn current_count(&self) -> Result<u64> {
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<String> {
pub(crate) fn emergency_password(&self) -> &Option<String> {
&self.config.emergency_password
}
pub fn supported_room_versions(&self) -> Vec<RoomVersionId> {
pub(crate) fn supported_room_versions(&self) -> Vec<RoomVersionId> {
let mut room_versions: Vec<RoomVersionId> = 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<BTreeMap<OwnedServerSigningKeyId, VerifyKey>> {
@ -376,22 +376,22 @@ impl Service {
Ok(keys)
}
pub fn database_version(&self) -> Result<u64> {
pub(crate) fn database_version(&self) -> Result<u64> {
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<String> {
pub(crate) fn well_known_client(&self) -> &Option<String> {
&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...");

View file

@ -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<u64>;
fn current_count(&self) -> Result<u64>;
async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()>;

View file

@ -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<BackupAlgorithm>,
@ -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<Option<String>> {
pub(crate) fn get_latest_backup_version(&self, user_id: &UserId) -> Result<Option<String>> {
self.db.get_latest_backup_version(user_id)
}
pub fn get_latest_backup(
pub(crate) fn get_latest_backup(
&self,
user_id: &UserId,
) -> Result<Option<(String, Raw<BackupAlgorithm>)>> {
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<usize> {
pub(crate) fn count_keys(&self, user_id: &UserId, version: &str) -> Result<usize> {
self.db.count_keys(user_id, version)
}
pub fn get_etag(&self, user_id: &UserId, version: &str) -> Result<String> {
pub(crate) fn get_etag(&self, user_id: &UserId, version: &str) -> Result<String> {
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,

View file

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

View file

@ -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<String>,
pub content_type: Option<String>,
pub file: Vec<u8>,
pub(crate) struct FileMeta {
pub(crate) content_disposition: Option<String>,
pub(crate) content_type: Option<String>,
pub(crate) file: Vec<u8>,
}
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<Option<FileMeta>> {
pub(crate) async fn get(&self, mxc: String) -> Result<Option<FileMeta>> {
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,

View file

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

View file

@ -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<EventId>,
pub room_id: OwnedRoomId,
pub sender: OwnedUserId,
pub origin_server_ts: UInt,
pub(crate) struct PduEvent {
pub(crate) event_id: Arc<EventId>,
pub(crate) room_id: OwnedRoomId,
pub(crate) sender: OwnedUserId,
pub(crate) origin_server_ts: UInt,
#[serde(rename = "type")]
pub kind: TimelineEventType,
pub content: Box<RawJsonValue>,
pub(crate) kind: TimelineEventType,
pub(crate) content: Box<RawJsonValue>,
#[serde(skip_serializing_if = "Option::is_none")]
pub state_key: Option<String>,
pub prev_events: Vec<Arc<EventId>>,
pub depth: UInt,
pub auth_events: Vec<Arc<EventId>>,
pub(crate) state_key: Option<String>,
pub(crate) prev_events: Vec<Arc<EventId>>,
pub(crate) depth: UInt,
pub(crate) auth_events: Vec<Arc<EventId>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub redacts: Option<Arc<EventId>>,
pub(crate) redacts: Option<Arc<EventId>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub unsigned: Option<Box<RawJsonValue>>,
pub hashes: EventHash,
pub(crate) unsigned: Option<Box<RawJsonValue>>,
pub(crate) hashes: EventHash,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub signatures: Option<Box<RawJsonValue>>, // BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>
pub(crate) signatures: Option<Box<RawJsonValue>>, // BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>
}
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<String, Box<RawJsonValue>> =
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<String, Box<RawJsonValue>> = 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<Arc<EventId>>, Box<RawJsonValue>) {
pub(crate) fn copy_redacts(&self) -> (Option<Arc<EventId>>, Box<RawJsonValue>) {
if self.kind == TimelineEventType::RoomRedaction {
if let Ok(mut content) =
serde_json::from_str::<RoomRedactionEventContent>(self.content.get())
@ -130,7 +130,7 @@ impl PduEvent {
}
#[tracing::instrument(skip(self))]
pub fn to_sync_room_event(&self) -> Raw<AnySyncTimelineEvent> {
pub(crate) fn to_sync_room_event(&self) -> Raw<AnySyncTimelineEvent> {
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<AnyEphemeralRoomEvent> {
pub(crate) fn to_any_event(&self) -> Raw<AnyEphemeralRoomEvent> {
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<AnyTimelineEvent> {
pub(crate) fn to_room_event(&self) -> Raw<AnyTimelineEvent> {
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<AnyMessageLikeEvent> {
pub(crate) fn to_message_like_event(&self) -> Raw<AnyMessageLikeEvent> {
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<AnyStateEvent> {
pub(crate) fn to_state_event(&self) -> Raw<AnyStateEvent> {
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<AnySyncStateEvent> {
pub(crate) fn to_sync_state_event(&self) -> Raw<AnySyncStateEvent> {
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<AnyStrippedStateEvent> {
pub(crate) fn to_stripped_state_event(&self) -> Raw<AnyStrippedStateEvent> {
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<HierarchySpaceChildEvent> {
pub(crate) fn to_stripped_spacechild_state_event(&self) -> Raw<HierarchySpaceChildEvent> {
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<StateEvent<RoomMemberEventContent>> {
pub(crate) fn to_member_event(&self) -> Raw<StateEvent<RoomMemberEventContent>> {
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<RawJsonValue> {
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<Self, serde_json::Error> {
@ -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<RawJsonValue>,
pub unsigned: Option<BTreeMap<String, serde_json::Value>>,
pub state_key: Option<String>,
pub redacts: Option<Arc<EventId>>,
pub(crate) event_type: TimelineEventType,
pub(crate) content: Box<RawJsonValue>,
pub(crate) unsigned: Option<BTreeMap<String, serde_json::Value>>,
pub(crate) state_key: Option<String>,
pub(crate) redacts: Option<Arc<EventId>>,
}

View file

@ -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<Option<Pusher>> {
pub(crate) fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result<Option<Pusher>> {
self.db.get_pusher(sender, pushkey)
}
pub fn get_pushers(&self, sender: &UserId) -> Result<Vec<Pusher>> {
pub(crate) fn get_pushers(&self, sender: &UserId) -> Result<Vec<Pusher>> {
self.db.get_pushers(sender)
}
pub fn get_pushkeys(&self, sender: &UserId) -> Box<dyn Iterator<Item = Result<String>>> {
pub(crate) fn get_pushkeys(&self, sender: &UserId) -> Box<dyn Iterator<Item = Result<String>>> {
self.db.get_pushkeys(sender)
}
#[tracing::instrument(skip(self, destination, request))]
pub async fn send_request<T: OutgoingRequest>(
pub(crate) async fn send_request<T: OutgoingRequest>(
&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,

View file

@ -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<Option<Pusher>>;

View file

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

View file

@ -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<Option<OwnedRoomId>> {
pub(crate) fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result<Option<OwnedRoomId>> {
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<dyn Iterator<Item = Result<OwnedRoomAliasId>> + 'a> {

View file

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

View file

@ -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<Option<Arc<HashSet<u64>>>> {
pub(crate) fn get_cached_eventid_authchain(
&self,
key: &[u64],
) -> Result<Option<Arc<HashSet<u64>>>> {
self.db.get_cached_eventid_authchain(key)
}
#[tracing::instrument(skip(self))]
pub fn cache_auth_chain(&self, key: Vec<u64>, auth_chain: Arc<HashSet<u64>>) -> Result<()> {
pub(crate) fn cache_auth_chain(
&self,
key: Vec<u64>,
auth_chain: Arc<HashSet<u64>>,
) -> 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<Arc<EventId>>,

View file

@ -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],

View file

@ -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<bool> {
pub(crate) fn is_public_room(&self, room_id: &RoomId) -> Result<bool> {
self.db.is_public_room(room_id)
}
#[tracing::instrument(skip(self))]
pub fn public_rooms(&self) -> impl Iterator<Item = Result<OwnedRoomId>> + '_ {
pub(crate) fn public_rooms(&self) -> impl Iterator<Item = Result<OwnedRoomId>> + '_ {
self.db.public_rooms()
}
}

View file

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

View file

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

View file

@ -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<Option<u64>> {
pub(crate) fn private_read_get(
&self,
room_id: &RoomId,
user_id: &UserId,
) -> Result<Option<u64>> {
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<u64> {
pub(crate) fn last_privateread_update(
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<u64> {
self.db.last_privateread_update(user_id, room_id)
}
}

View file

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

View file

@ -4,16 +4,21 @@ use tokio::sync::{broadcast, RwLock};
use crate::{services, utils, Result};
pub struct Service {
pub typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>, // u64 is unix timestamp of timeout
pub last_typing_update: RwLock<BTreeMap<OwnedRoomId, u64>>, // timestamp of the last change to typing users
pub typing_update_sender: broadcast::Sender<OwnedRoomId>,
pub(crate) struct Service {
pub(crate) typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>, // u64 is unix timestamp of timeout
pub(crate) last_typing_update: RwLock<BTreeMap<OwnedRoomId, u64>>, // timestamp of the last change to typing users
pub(crate) typing_update_sender: broadcast::Sender<OwnedRoomId>,
}
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<u64> {
pub(crate) async fn last_typing_update(&self, room_id: &RoomId) -> Result<u64> {
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<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> {

View file

@ -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<PduEvent>,
val: BTreeMap<String, CanonicalJsonValue>,
@ -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<String>,

View file

@ -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<HashMap<(OwnedUserId, OwnedDeviceId, OwnedRoomId, PduCount), HashSet<OwnedUserId>>>,
}
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,

View file

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

View file

@ -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<bool> {
pub(crate) fn exists(&self, room_id: &RoomId) -> Result<bool> {
self.db.exists(room_id)
}
pub fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
pub(crate) fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
self.db.iter_ids()
}
pub fn is_disabled(&self, room_id: &RoomId) -> Result<bool> {
pub(crate) fn is_disabled(&self, room_id: &RoomId) -> Result<bool> {
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)
}
}

View file

@ -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<bool>;
fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a>;
fn is_disabled(&self, room_id: &RoomId) -> Result<bool>;

View file

@ -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<Option<CanonicalJsonObject>> {
pub(crate) fn get_outlier_pdu_json(
&self,
event_id: &EventId,
) -> Result<Option<CanonicalJsonObject>> {
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<Option<PduEvent>> {
pub(crate) fn get_pdu_outlier(&self, event_id: &EventId) -> Result<Option<PduEvent>> {
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)
}
}

View file

@ -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<Option<CanonicalJsonObject>>;
fn get_outlier_pdu(&self, event_id: &EventId) -> Result<Option<PduEvent>>;
fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()>;

View file

@ -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<EventId>]) -> Result<()> {
pub(crate) fn mark_as_referenced(
&self,
room_id: &RoomId,
event_ids: &[Arc<EventId>],
) -> 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<bool> {
pub(crate) fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> Result<bool> {
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<bool> {
pub(crate) fn is_event_soft_failed(&self, event_id: &EventId) -> Result<bool> {
self.db.is_event_soft_failed(event_id)
}
}

View file

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

View file

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

View file

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

View file

@ -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<u64> {
pub(crate) fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result<u64> {
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<Arc<EventId>> {
pub(crate) fn get_eventid_from_short(&self, shorteventid: u64) -> Result<Arc<EventId>> {
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<Option<u64>> {
pub(crate) fn get_shortroomid(&self, room_id: &RoomId) -> Result<Option<u64>> {
self.db.get_shortroomid(room_id)
}
pub fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result<u64> {
pub(crate) fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result<u64> {
self.db.get_or_create_shortroomid(room_id)
}
}

View file

@ -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<u64>;
fn get_shortstatekey(

View file

@ -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<OwnedRoomId>,
join_rule: CachedJoinRule,
}
pub struct Service {
pub roomid_spacechunk_cache: Mutex<LruCache<OwnedRoomId, Option<CachedSpaceChunk>>>,
pub(crate) struct Service {
pub(crate) roomid_spacechunk_cache: Mutex<LruCache<OwnedRoomId, Option<CachedSpaceChunk>>>,
}
impl Service {
pub async fn get_hierarchy(
pub(crate) async fn get_hierarchy(
&self,
sender_user: &UserId,
room_id: &RoomId,

View file

@ -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<u64> {
pub(crate) fn append_to_state(&self, new_pdu: &PduEvent) -> Result<u64> {
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<Vec<Raw<AnyStrippedStateEvent>>> {
@ -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<RoomVersionId> {
pub(crate) fn get_room_version(&self, room_id: &RoomId) -> Result<RoomVersionId> {
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<Option<u64>> {
pub(crate) fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result<Option<u64>> {
self.db.get_room_shortstatehash(room_id)
}
pub fn get_forward_extremities(&self, room_id: &RoomId) -> Result<HashSet<Arc<EventId>>> {
pub(crate) fn get_forward_extremities(
&self,
room_id: &RoomId,
) -> Result<HashSet<Arc<EventId>>> {
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<OwnedEventId>,
@ -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,

View file

@ -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<Option<u64>>;

View file

@ -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<LruCache<(OwnedServerName, u64), bool>>,
pub user_visibility_cache: Mutex<LruCache<(OwnedUserId, u64), bool>>,
pub(crate) struct Service {
pub(crate) db: &'static dyn Data,
pub(crate) server_visibility_cache: Mutex<LruCache<(OwnedServerName, u64), bool>>,
pub(crate) user_visibility_cache: Mutex<LruCache<(OwnedUserId, u64), bool>>,
}
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<HashMap<u64, Arc<EventId>>> {
pub(crate) async fn state_full_ids(
&self,
shortstatehash: u64,
) -> Result<HashMap<u64, Arc<EventId>>> {
self.db.state_full_ids(shortstatehash).await
}
pub async fn state_full(
pub(crate) async fn state_full(
&self,
shortstatehash: u64,
) -> Result<HashMap<(StateEventType, String), Arc<PduEvent>>> {
@ -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<bool> {
pub(crate) fn user_can_see_state_events(
&self,
user_id: &UserId,
room_id: &RoomId,
) -> Result<bool> {
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<Option<u64>> {
pub(crate) fn pdu_shortstatehash(&self, event_id: &EventId) -> Result<Option<u64>> {
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<HashMap<(StateEventType, String), Arc<PduEvent>>> {
@ -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<Option<String>> {
pub(crate) fn get_name(&self, room_id: &RoomId) -> Result<Option<String>> {
services()
.rooms
.state_accessor
@ -294,7 +301,7 @@ impl Service {
})
}
pub fn get_avatar(&self, room_id: &RoomId) -> Result<JsOption<RoomAvatarEventContent>> {
pub(crate) fn get_avatar(&self, room_id: &RoomId) -> Result<JsOption<RoomAvatarEventContent>> {
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,

View file

@ -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<HashMap<u64, Arc<EventId>>>;

View file

@ -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<Arc<HashSet<OwnedUserId>>> {
pub(crate) fn get_our_real_users(&self, room_id: &RoomId) -> Result<Arc<HashSet<OwnedUserId>>> {
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<Item = Result<OwnedServerName>> + '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<bool> {
pub(crate) fn server_in_room<'a>(
&'a self,
server: &ServerName,
room_id: &RoomId,
) -> Result<bool> {
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<Item = Result<OwnedRoomId>> + '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<Item = Result<OwnedUserId>> + 'a {
@ -249,18 +253,18 @@ impl Service {
}
#[tracing::instrument(skip(self))]
pub fn room_joined_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
pub(crate) fn room_joined_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
self.db.room_joined_count(room_id)
}
#[tracing::instrument(skip(self))]
pub fn room_invited_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
pub(crate) fn room_invited_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
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<Item = Result<OwnedUserId>> + '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<Item = Result<OwnedUserId>> + 'a {
@ -277,18 +281,22 @@ impl Service {
}
#[tracing::instrument(skip(self))]
pub fn get_invite_count(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> {
pub(crate) fn get_invite_count(
&self,
room_id: &RoomId,
user_id: &UserId,
) -> Result<Option<u64>> {
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<Option<u64>> {
pub(crate) fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> {
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<Item = Result<OwnedRoomId>> + '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<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + '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<Item = Result<(OwnedRoomId, Vec<Raw<AnySyncStateEvent>>)>> + 'a {
@ -332,22 +340,22 @@ impl Service {
}
#[tracing::instrument(skip(self))]
pub fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
pub(crate) fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
self.db.once_joined(user_id, room_id)
}
#[tracing::instrument(skip(self))]
pub fn is_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
pub(crate) fn is_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
self.db.is_joined(user_id, room_id)
}
#[tracing::instrument(skip(self))]
pub fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
pub(crate) fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
self.db.is_invited(user_id, room_id)
}
#[tracing::instrument(skip(self))]
pub fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
pub(crate) fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
self.db.is_left(user_id, room_id)
}
}

View file

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

View file

@ -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::<u64>()];
pub(crate) type CompressedStateEvent = [u8; 2 * size_of::<u64>()];
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<EventId>)> {
@ -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<HashSet<CompressedStateEvent>>,
@ -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<HashSet<CompressedStateEvent>>,

View file

@ -3,13 +3,13 @@ use std::{collections::HashSet, sync::Arc};
use super::CompressedStateEvent;
use crate::Result;
pub struct StateDiff {
pub parent: Option<u64>,
pub added: Arc<HashSet<CompressedStateEvent>>,
pub removed: Arc<HashSet<CompressedStateEvent>>,
pub(crate) struct StateDiff {
pub(crate) parent: Option<u64>,
pub(crate) added: Arc<HashSet<CompressedStateEvent>>,
pub(crate) removed: Arc<HashSet<CompressedStateEvent>>,
}
pub trait Data: Send + Sync {
pub(crate) trait Data: Send + Sync {
fn get_statediff(&self, shortstatehash: u64) -> Result<StateDiff>;
fn save_statediff(&self, shortstatehash: u64, diff: StateDiff) -> Result<()>;
}

View file

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

View file

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

View file

@ -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<Self> {
pub(crate) fn try_from_string(token: &str) -> Result<Self> {
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<HashMap<OwnedRoomId, PduCount>>,
pub(crate) lasttimelinecount_cache: Mutex<HashMap<OwnedRoomId, PduCount>>,
}
impl Service {
#[tracing::instrument(skip(self))]
pub fn first_pdu_in_room(&self, room_id: &RoomId) -> Result<Option<Arc<PduEvent>>> {
pub(crate) fn first_pdu_in_room(&self, room_id: &RoomId) -> Result<Option<Arc<PduEvent>>> {
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<PduCount> {
pub(crate) fn last_timeline_count(
&self,
sender_user: &UserId,
room_id: &RoomId,
) -> Result<PduCount> {
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<Option<PduCount>> {
pub(crate) fn get_pdu_count(&self, event_id: &EventId) -> Result<Option<PduCount>> {
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<u64> {
pub(crate) fn latest_pdu_count(&self, room_id: &RoomId) -> Result<u64> {
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<Option<CanonicalJsonObject>> {
pub(crate) fn get_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>> {
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<Option<CanonicalJsonObject>> {
@ -151,39 +155,42 @@ impl Service {
}
/// Returns the pdu's id.
pub fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<Vec<u8>>> {
pub(crate) fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<Vec<u8>>> {
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<Option<PduEvent>> {
pub(crate) fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result<Option<PduEvent>> {
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<Option<Arc<PduEvent>>> {
pub(crate) fn get_pdu(&self, event_id: &EventId) -> Result<Option<Arc<PduEvent>>> {
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<Option<PduEvent>> {
pub(crate) fn get_pdu_from_id(&self, pdu_id: &[u8]) -> Result<Option<PduEvent>> {
self.db.get_pdu_from_id(pdu_id)
}
/// Returns the pdu as a `BTreeMap<String, CanonicalJsonValue>`.
pub fn get_pdu_json_from_id(&self, pdu_id: &[u8]) -> Result<Option<CanonicalJsonObject>> {
pub(crate) fn get_pdu_json_from_id(
&self,
pdu_id: &[u8],
) -> Result<Option<CanonicalJsonObject>> {
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<RawJsonValue>,

View file

@ -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<PduCount>;
/// Returns the `count` of this pdu's id.

View file

@ -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<u64> {
pub(crate) fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
self.db.notification_count(user_id, room_id)
}
pub fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
pub(crate) fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
self.db.highlight_count(user_id, room_id)
}
pub fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
pub(crate) fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
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<Option<u64>> {
pub(crate) fn get_token_shortstatehash(
&self,
room_id: &RoomId,
token: u64,
) -> Result<Option<u64>> {
self.db.get_token_shortstatehash(room_id, token)
}
pub fn get_shared_rooms(
pub(crate) fn get_shared_rooms(
&self,
users: Vec<OwnedUserId>,
) -> Result<impl Iterator<Item = Result<OwnedRoomId>>> {

View file

@ -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<u64>;

Some files were not shown because too many files have changed in this diff Show more