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

@ -5,7 +5,7 @@ use std::{
sync::{Arc, Mutex},
};
pub use data::Data;
pub(crate) use data::Data;
use ruma::{
api::client::{
device::Device,
@ -25,27 +25,27 @@ use ruma::{
use crate::{services, Error, Result};
pub struct SlidingSyncCache {
pub(crate) struct SlidingSyncCache {
lists: BTreeMap<String, SyncRequestList>,
subscriptions: BTreeMap<OwnedRoomId, sync_events::v4::RoomSubscription>,
known_rooms: BTreeMap<String, BTreeMap<OwnedRoomId, u64>>, // For every room, the roomsince number
extensions: ExtensionsConfig,
}
pub struct Service {
pub db: &'static dyn Data,
pub(crate) struct Service {
pub(crate) db: &'static dyn Data,
#[allow(clippy::type_complexity)]
pub connections:
pub(crate) connections:
Mutex<BTreeMap<(OwnedUserId, OwnedDeviceId, String), Arc<Mutex<SlidingSyncCache>>>>,
}
impl Service {
/// Check if a user has an account on this homeserver.
pub fn exists(&self, user_id: &UserId) -> Result<bool> {
pub(crate) fn exists(&self, user_id: &UserId) -> Result<bool> {
self.db.exists(user_id)
}
pub fn forget_sync_request_connection(
pub(crate) fn forget_sync_request_connection(
&self,
user_id: OwnedUserId,
device_id: OwnedDeviceId,
@ -57,7 +57,7 @@ impl Service {
.remove(&(user_id, device_id, conn_id));
}
pub fn update_sync_request_with_cache(
pub(crate) fn update_sync_request_with_cache(
&self,
user_id: OwnedUserId,
device_id: OwnedDeviceId,
@ -186,7 +186,7 @@ impl Service {
cached.known_rooms.clone()
}
pub fn update_sync_subscriptions(
pub(crate) fn update_sync_subscriptions(
&self,
user_id: OwnedUserId,
device_id: OwnedDeviceId,
@ -212,7 +212,7 @@ impl Service {
cached.subscriptions = subscriptions;
}
pub fn update_sync_known_rooms(
pub(crate) fn update_sync_known_rooms(
&self,
user_id: OwnedUserId,
device_id: OwnedDeviceId,
@ -254,12 +254,12 @@ impl Service {
}
/// Check if account is deactivated
pub fn is_deactivated(&self, user_id: &UserId) -> Result<bool> {
pub(crate) fn is_deactivated(&self, user_id: &UserId) -> Result<bool> {
self.db.is_deactivated(user_id)
}
/// Check if a user is an admin
pub fn is_admin(&self, user_id: &UserId) -> Result<bool> {
pub(crate) fn is_admin(&self, user_id: &UserId) -> Result<bool> {
let admin_room_alias_id =
RoomAliasId::parse(format!("#admins:{}", services().globals.server_name()))
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid alias."))?;
@ -276,75 +276,83 @@ impl Service {
}
/// Create a new user account on this homeserver.
pub fn create(&self, user_id: &UserId, password: Option<&str>) -> Result<()> {
pub(crate) fn create(&self, user_id: &UserId, password: Option<&str>) -> Result<()> {
self.db.set_password(user_id, password)?;
Ok(())
}
/// Returns the number of users registered on this server.
pub fn count(&self) -> Result<usize> {
pub(crate) fn count(&self) -> Result<usize> {
self.db.count()
}
/// Find out which user an access token belongs to.
pub fn find_from_token(&self, token: &str) -> Result<Option<(OwnedUserId, String)>> {
pub(crate) fn find_from_token(&self, token: &str) -> Result<Option<(OwnedUserId, String)>> {
self.db.find_from_token(token)
}
/// Returns an iterator over all users on this homeserver.
pub fn iter(&self) -> impl Iterator<Item = Result<OwnedUserId>> + '_ {
pub(crate) fn iter(&self) -> impl Iterator<Item = Result<OwnedUserId>> + '_ {
self.db.iter()
}
/// Returns a list of local users as list of usernames.
///
/// A user account is considered `local` if the length of it's password is greater then zero.
pub fn list_local_users(&self) -> Result<Vec<String>> {
pub(crate) fn list_local_users(&self) -> Result<Vec<String>> {
self.db.list_local_users()
}
/// Returns the password hash for the given user.
pub fn password_hash(&self, user_id: &UserId) -> Result<Option<String>> {
pub(crate) fn password_hash(&self, user_id: &UserId) -> Result<Option<String>> {
self.db.password_hash(user_id)
}
/// Hash and set the user's password to the Argon2 hash
pub fn set_password(&self, user_id: &UserId, password: Option<&str>) -> Result<()> {
pub(crate) fn set_password(&self, user_id: &UserId, password: Option<&str>) -> Result<()> {
self.db.set_password(user_id, password)
}
/// Returns the displayname of a user on this homeserver.
pub fn displayname(&self, user_id: &UserId) -> Result<Option<String>> {
pub(crate) fn displayname(&self, user_id: &UserId) -> Result<Option<String>> {
self.db.displayname(user_id)
}
/// Sets a new displayname or removes it if displayname is None. You still need to nofify all rooms of this change.
pub fn set_displayname(&self, user_id: &UserId, displayname: Option<String>) -> Result<()> {
pub(crate) fn set_displayname(
&self,
user_id: &UserId,
displayname: Option<String>,
) -> Result<()> {
self.db.set_displayname(user_id, displayname)
}
/// Get the avatar_url of a user.
pub fn avatar_url(&self, user_id: &UserId) -> Result<Option<OwnedMxcUri>> {
pub(crate) fn avatar_url(&self, user_id: &UserId) -> Result<Option<OwnedMxcUri>> {
self.db.avatar_url(user_id)
}
/// Sets a new avatar_url or removes it if avatar_url is None.
pub fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option<OwnedMxcUri>) -> Result<()> {
pub(crate) fn set_avatar_url(
&self,
user_id: &UserId,
avatar_url: Option<OwnedMxcUri>,
) -> Result<()> {
self.db.set_avatar_url(user_id, avatar_url)
}
/// Get the blurhash of a user.
pub fn blurhash(&self, user_id: &UserId) -> Result<Option<String>> {
pub(crate) fn blurhash(&self, user_id: &UserId) -> Result<Option<String>> {
self.db.blurhash(user_id)
}
/// Sets a new avatar_url or removes it if avatar_url is None.
pub fn set_blurhash(&self, user_id: &UserId, blurhash: Option<String>) -> Result<()> {
pub(crate) fn set_blurhash(&self, user_id: &UserId, blurhash: Option<String>) -> Result<()> {
self.db.set_blurhash(user_id, blurhash)
}
/// Adds a new device to a user.
pub fn create_device(
pub(crate) fn create_device(
&self,
user_id: &UserId,
device_id: &DeviceId,
@ -356,12 +364,12 @@ impl Service {
}
/// Removes a device from a user.
pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> {
pub(crate) fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> {
self.db.remove_device(user_id, device_id)
}
/// Returns an iterator over all device ids of this user.
pub fn all_device_ids<'a>(
pub(crate) fn all_device_ids<'a>(
&'a self,
user_id: &UserId,
) -> impl Iterator<Item = Result<OwnedDeviceId>> + 'a {
@ -369,11 +377,16 @@ impl Service {
}
/// Replaces the access token of one device.
pub fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> {
pub(crate) fn set_token(
&self,
user_id: &UserId,
device_id: &DeviceId,
token: &str,
) -> Result<()> {
self.db.set_token(user_id, device_id, token)
}
pub fn add_one_time_key(
pub(crate) fn add_one_time_key(
&self,
user_id: &UserId,
device_id: &DeviceId,
@ -384,11 +397,11 @@ impl Service {
.add_one_time_key(user_id, device_id, one_time_key_key, one_time_key_value)
}
pub fn last_one_time_keys_update(&self, user_id: &UserId) -> Result<u64> {
pub(crate) fn last_one_time_keys_update(&self, user_id: &UserId) -> Result<u64> {
self.db.last_one_time_keys_update(user_id)
}
pub fn take_one_time_key(
pub(crate) fn take_one_time_key(
&self,
user_id: &UserId,
device_id: &DeviceId,
@ -397,7 +410,7 @@ impl Service {
self.db.take_one_time_key(user_id, device_id, key_algorithm)
}
pub fn count_one_time_keys(
pub(crate) fn count_one_time_keys(
&self,
user_id: &UserId,
device_id: &DeviceId,
@ -405,7 +418,7 @@ impl Service {
self.db.count_one_time_keys(user_id, device_id)
}
pub fn add_device_keys(
pub(crate) fn add_device_keys(
&self,
user_id: &UserId,
device_id: &DeviceId,
@ -414,7 +427,7 @@ impl Service {
self.db.add_device_keys(user_id, device_id, device_keys)
}
pub fn add_cross_signing_keys(
pub(crate) fn add_cross_signing_keys(
&self,
user_id: &UserId,
master_key: &Raw<CrossSigningKey>,
@ -431,7 +444,7 @@ impl Service {
)
}
pub fn sign_key(
pub(crate) fn sign_key(
&self,
target_id: &UserId,
key_id: &str,
@ -441,7 +454,7 @@ impl Service {
self.db.sign_key(target_id, key_id, signature, sender_id)
}
pub fn keys_changed<'a>(
pub(crate) fn keys_changed<'a>(
&'a self,
user_or_room_id: &str,
from: u64,
@ -450,11 +463,11 @@ impl Service {
self.db.keys_changed(user_or_room_id, from, to)
}
pub fn mark_device_key_update(&self, user_id: &UserId) -> Result<()> {
pub(crate) fn mark_device_key_update(&self, user_id: &UserId) -> Result<()> {
self.db.mark_device_key_update(user_id)
}
pub fn get_device_keys(
pub(crate) fn get_device_keys(
&self,
user_id: &UserId,
device_id: &DeviceId,
@ -462,7 +475,7 @@ impl Service {
self.db.get_device_keys(user_id, device_id)
}
pub fn parse_master_key(
pub(crate) fn parse_master_key(
&self,
user_id: &UserId,
master_key: &Raw<CrossSigningKey>,
@ -470,7 +483,7 @@ impl Service {
self.db.parse_master_key(user_id, master_key)
}
pub fn get_key(
pub(crate) fn get_key(
&self,
key: &[u8],
sender_user: Option<&UserId>,
@ -481,7 +494,7 @@ impl Service {
.get_key(key, sender_user, user_id, allowed_signatures)
}
pub fn get_master_key(
pub(crate) fn get_master_key(
&self,
sender_user: Option<&UserId>,
user_id: &UserId,
@ -491,7 +504,7 @@ impl Service {
.get_master_key(sender_user, user_id, allowed_signatures)
}
pub fn get_self_signing_key(
pub(crate) fn get_self_signing_key(
&self,
sender_user: Option<&UserId>,
user_id: &UserId,
@ -501,11 +514,14 @@ impl Service {
.get_self_signing_key(sender_user, user_id, allowed_signatures)
}
pub fn get_user_signing_key(&self, user_id: &UserId) -> Result<Option<Raw<CrossSigningKey>>> {
pub(crate) fn get_user_signing_key(
&self,
user_id: &UserId,
) -> Result<Option<Raw<CrossSigningKey>>> {
self.db.get_user_signing_key(user_id)
}
pub fn add_to_device_event(
pub(crate) fn add_to_device_event(
&self,
sender: &UserId,
target_user_id: &UserId,
@ -522,7 +538,7 @@ impl Service {
)
}
pub fn get_to_device_events(
pub(crate) fn get_to_device_events(
&self,
user_id: &UserId,
device_id: &DeviceId,
@ -530,7 +546,7 @@ impl Service {
self.db.get_to_device_events(user_id, device_id)
}
pub fn remove_to_device_events(
pub(crate) fn remove_to_device_events(
&self,
user_id: &UserId,
device_id: &DeviceId,
@ -539,7 +555,7 @@ impl Service {
self.db.remove_to_device_events(user_id, device_id, until)
}
pub fn update_device_metadata(
pub(crate) fn update_device_metadata(
&self,
user_id: &UserId,
device_id: &DeviceId,
@ -549,7 +565,7 @@ impl Service {
}
/// Get device metadata.
pub fn get_device_metadata(
pub(crate) fn get_device_metadata(
&self,
user_id: &UserId,
device_id: &DeviceId,
@ -557,11 +573,11 @@ impl Service {
self.db.get_device_metadata(user_id, device_id)
}
pub fn get_devicelist_version(&self, user_id: &UserId) -> Result<Option<u64>> {
pub(crate) fn get_devicelist_version(&self, user_id: &UserId) -> Result<Option<u64>> {
self.db.get_devicelist_version(user_id)
}
pub fn all_devices_metadata<'a>(
pub(crate) fn all_devices_metadata<'a>(
&'a self,
user_id: &UserId,
) -> impl Iterator<Item = Result<Device>> + 'a {
@ -569,7 +585,7 @@ impl Service {
}
/// Deactivate account
pub fn deactivate_account(&self, user_id: &UserId) -> Result<()> {
pub(crate) fn deactivate_account(&self, user_id: &UserId) -> Result<()> {
// Remove all associated devices
for device_id in self.all_device_ids(user_id) {
self.remove_device(user_id, &device_id?)?;
@ -585,11 +601,15 @@ impl Service {
}
/// Creates a new sync filter. Returns the filter id.
pub fn create_filter(&self, user_id: &UserId, filter: &FilterDefinition) -> Result<String> {
pub(crate) fn create_filter(
&self,
user_id: &UserId,
filter: &FilterDefinition,
) -> Result<String> {
self.db.create_filter(user_id, filter)
}
pub fn get_filter(
pub(crate) fn get_filter(
&self,
user_id: &UserId,
filter_id: &str,
@ -599,7 +619,7 @@ impl Service {
}
/// Ensure that a user only sees signatures from themselves and the target user
pub fn clean_signatures<F: Fn(&UserId) -> bool>(
pub(crate) fn clean_signatures<F: Fn(&UserId) -> bool>(
cross_signing_key: &mut serde_json::Value,
sender_user: Option<&UserId>,
user_id: &UserId,