From 8d10c3f5f541330b0d741954fa0c09f8e7c1dae2 Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Sat, 14 Feb 2026 15:30:45 +0000 Subject: [PATCH] chore: migrate to rust 2024 edition --- Cargo.toml | 2 +- conduit-config/src/error.rs | 4 +- conduit-config/src/lib.rs | 6 +-- conduit/src/api/appservice_server.rs | 4 +- conduit/src/api/client_server/account.rs | 12 +++--- conduit/src/api/client_server/alias.rs | 2 +- conduit/src/api/client_server/appservice.rs | 2 +- conduit/src/api/client_server/backup.rs | 2 +- conduit/src/api/client_server/capabilities.rs | 2 +- conduit/src/api/client_server/config.rs | 2 +- conduit/src/api/client_server/context.rs | 2 +- conduit/src/api/client_server/device.rs | 2 +- conduit/src/api/client_server/directory.rs | 8 ++-- conduit/src/api/client_server/filter.rs | 2 +- conduit/src/api/client_server/keys.rs | 8 ++-- conduit/src/api/client_server/media.rs | 4 +- conduit/src/api/client_server/membership.rs | 20 ++++++---- conduit/src/api/client_server/message.rs | 3 +- conduit/src/api/client_server/openid.rs | 2 +- conduit/src/api/client_server/presence.rs | 2 +- conduit/src/api/client_server/profile.rs | 4 +- conduit/src/api/client_server/push.rs | 4 +- conduit/src/api/client_server/read_marker.rs | 10 ++--- conduit/src/api/client_server/redact.rs | 4 +- conduit/src/api/client_server/relations.rs | 2 +- conduit/src/api/client_server/report.rs | 4 +- conduit/src/api/client_server/room.rs | 8 ++-- conduit/src/api/client_server/search.rs | 4 +- conduit/src/api/client_server/session.rs | 4 +- conduit/src/api/client_server/space.rs | 4 +- conduit/src/api/client_server/state.rs | 6 +-- conduit/src/api/client_server/sync.rs | 13 ++++--- conduit/src/api/client_server/tag.rs | 4 +- conduit/src/api/client_server/threads.rs | 2 +- conduit/src/api/client_server/to_device.rs | 2 +- conduit/src/api/client_server/typing.rs | 2 +- .../src/api/client_server/user_directory.rs | 4 +- conduit/src/api/client_server/voip.rs | 6 +-- conduit/src/api/client_server/well_known.rs | 2 +- conduit/src/api/ruma_wrapper/axum.rs | 14 +++---- conduit/src/api/ruma_wrapper/mod.rs | 6 +-- conduit/src/api/server_server.rs | 28 +++++++------- conduit/src/database/abstraction/rocksdb.rs | 4 +- conduit/src/database/abstraction/sqlite.rs | 2 +- conduit/src/database/abstraction/watchers.rs | 2 +- .../src/database/key_value/account_data.rs | 4 +- conduit/src/database/key_value/appservice.rs | 2 +- conduit/src/database/key_value/globals.rs | 7 ++-- conduit/src/database/key_value/key_backups.rs | 4 +- conduit/src/database/key_value/media.rs | 27 +++++++------ conduit/src/database/key_value/pusher.rs | 4 +- conduit/src/database/key_value/rooms/alias.rs | 6 +-- .../database/key_value/rooms/auth_chain.rs | 2 +- .../src/database/key_value/rooms/directory.rs | 2 +- .../database/key_value/rooms/edus/presence.rs | 4 +- .../key_value/rooms/edus/read_receipt.rs | 4 +- .../src/database/key_value/rooms/lazy_load.rs | 2 +- .../src/database/key_value/rooms/metadata.rs | 2 +- .../src/database/key_value/rooms/outlier.rs | 2 +- .../database/key_value/rooms/pdu_metadata.rs | 3 +- .../src/database/key_value/rooms/search.rs | 2 +- conduit/src/database/key_value/rooms/short.rs | 4 +- conduit/src/database/key_value/rooms/state.rs | 2 +- .../key_value/rooms/state_accessor.rs | 4 +- .../database/key_value/rooms/state_cache.rs | 7 ++-- .../key_value/rooms/state_compressor.rs | 3 +- .../src/database/key_value/rooms/threads.rs | 4 +- .../src/database/key_value/rooms/timeline.rs | 10 ++--- conduit/src/database/key_value/rooms/user.rs | 4 +- conduit/src/database/key_value/sending.rs | 3 +- .../src/database/key_value/transaction_ids.rs | 2 +- conduit/src/database/key_value/uiaa.rs | 4 +- conduit/src/database/key_value/users.rs | 7 ++-- conduit/src/database/mod.rs | 23 ++++++----- conduit/src/lib.rs | 2 +- conduit/src/main.rs | 32 ++++++++++------ conduit/src/service/account_data/data.rs | 2 +- conduit/src/service/account_data/mod.rs | 2 +- conduit/src/service/admin/mod.rs | 22 +++++------ conduit/src/service/appservice/mod.rs | 4 +- conduit/src/service/globals/data.rs | 4 +- conduit/src/service/globals/mod.rs | 14 +++---- conduit/src/service/key_backups/data.rs | 4 +- conduit/src/service/key_backups/mod.rs | 2 +- conduit/src/service/media/data.rs | 2 +- conduit/src/service/media/mod.rs | 8 ++-- conduit/src/service/mod.rs | 2 +- conduit/src/service/pdu.rs | 11 +++--- conduit/src/service/pusher/data.rs | 4 +- conduit/src/service/pusher/mod.rs | 9 +++-- conduit/src/service/rooms/alias/mod.rs | 6 +-- conduit/src/service/rooms/auth_chain/data.rs | 2 +- conduit/src/service/rooms/auth_chain/mod.rs | 6 +-- .../src/service/rooms/edus/presence/data.rs | 2 +- .../src/service/rooms/edus/presence/mod.rs | 2 +- .../service/rooms/edus/read_receipt/data.rs | 2 +- .../service/rooms/edus/read_receipt/mod.rs | 6 ++- conduit/src/service/rooms/edus/typing/mod.rs | 6 +-- .../src/service/rooms/event_handler/mod.rs | 38 ++++++++++++------- conduit/src/service/rooms/helpers/mod.rs | 30 ++++++++------- .../src/service/rooms/pdu_metadata/data.rs | 2 +- conduit/src/service/rooms/pdu_metadata/mod.rs | 8 ++-- conduit/src/service/rooms/search/mod.rs | 2 +- conduit/src/service/rooms/short/data.rs | 2 +- conduit/src/service/rooms/short/mod.rs | 2 +- conduit/src/service/rooms/spaces/mod.rs | 6 +-- conduit/src/service/rooms/state/mod.rs | 8 ++-- .../src/service/rooms/state_accessor/data.rs | 2 +- .../src/service/rooms/state_accessor/mod.rs | 8 ++-- conduit/src/service/rooms/state_cache/data.rs | 4 +- conduit/src/service/rooms/state_cache/mod.rs | 29 +++++++------- .../src/service/rooms/state_compressor/mod.rs | 2 +- conduit/src/service/rooms/threads/data.rs | 2 +- conduit/src/service/rooms/threads/mod.rs | 5 ++- conduit/src/service/rooms/timeline/mod.rs | 20 +++++----- conduit/src/service/rooms/user/mod.rs | 2 +- conduit/src/service/sending/mod.rs | 17 +++++---- conduit/src/service/uiaa/data.rs | 2 +- conduit/src/service/uiaa/mod.rs | 6 +-- conduit/src/service/users/data.rs | 6 +-- conduit/src/service/users/mod.rs | 10 ++--- conduit/src/utils/error.rs | 2 +- conduit/src/utils/mod.rs | 4 +- 123 files changed, 412 insertions(+), 353 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ee897ab1..49130dfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ str_to_string = "warn" [workspace.package] # See also `rust-toolchain.toml` -edition = "2021" +edition = "2024" homepage = "https://conduit.rs" repository = "https://gitlab.com/famedly/conduit" rust-version = "1.85.0" diff --git a/conduit-config/src/error.rs b/conduit-config/src/error.rs index 50e823c0..d6feabf9 100644 --- a/conduit-config/src/error.rs +++ b/conduit-config/src/error.rs @@ -4,7 +4,9 @@ pub type Result = std::result::Result; #[derive(Error, Debug)] pub enum Error { - #[error("The media directory structure depth multiplied by the length is equal to or greater than a sha256 hex hash, please reduce at least one of the two so that their product is less than 64")] + #[error( + "The media directory structure depth multiplied by the length is equal to or greater than a sha256 hex hash, please reduce at least one of the two so that their product is less than 64" + )] DirectoryStructureLengthDepthTooLarge, #[error("Invalid S3 config")] diff --git a/conduit-config/src/lib.rs b/conduit-config/src/lib.rs index 19efa744..5303a96c 100644 --- a/conduit-config/src/lib.rs +++ b/conduit-config/src/lib.rs @@ -8,10 +8,10 @@ use std::{ use bytesize::ByteSize; pub use error::Error; -use ruma::{api::federation::discovery::VerifyKey, serde::Base64, OwnedServerName, RoomVersionId}; +use ruma::{OwnedServerName, RoomVersionId, api::federation::discovery::VerifyKey, serde::Base64}; use serde::{ - de::{Error as _, IgnoredAny}, Deserialize, + de::{Error as _, IgnoredAny}, }; use url::Url; @@ -728,7 +728,7 @@ impl std::fmt::Display for Config { let mut msg: String = "Active config values:\n\n".to_owned(); for line in lines.into_iter().enumerate() { - msg += &format!("{}: {}\n", line.1 .0, line.1 .1); + msg += &format!("{}: {}\n", line.1.0, line.1.1); } write!(f, "{msg}") diff --git a/conduit/src/api/appservice_server.rs b/conduit/src/api/appservice_server.rs index fe4c1cb4..7eed8933 100644 --- a/conduit/src/api/appservice_server.rs +++ b/conduit/src/api/appservice_server.rs @@ -1,6 +1,6 @@ -use crate::{services, utils, Error, Result, SUPPORTED_VERSIONS}; +use crate::{Error, Result, SUPPORTED_VERSIONS, services, utils}; use bytes::BytesMut; -use ruma::api::{appservice::Registration, IncomingResponse, OutgoingRequest, SendAccessToken}; +use ruma::api::{IncomingResponse, OutgoingRequest, SendAccessToken, appservice::Registration}; use std::{fmt::Debug, mem, time::Duration}; use tracing::warn; diff --git a/conduit/src/api/client_server/account.rs b/conduit/src/api/client_server/account.rs index 63aa8545..616c5ceb 100644 --- a/conduit/src/api/client_server/account.rs +++ b/conduit/src/api/client_server/account.rs @@ -1,18 +1,20 @@ use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH}; -use crate::{api::client_server, services, utils, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, api::client_server, services, utils}; use ruma::{ + UserId, api::client::{ account::{ - change_password, deactivate, get_3pids, get_username_availability, + ThirdPartyIdRemovalStatus, change_password, deactivate, get_3pids, + get_username_availability, register::{self, LoginType}, request_3pid_management_token_via_email, request_3pid_management_token_via_msisdn, - whoami, ThirdPartyIdRemovalStatus, + whoami, }, error::ErrorKind, uiaa::{AuthFlow, AuthType, UiaaInfo}, }, - events::{room::message::RoomMessageEventContent, GlobalAccountDataEventType}, - push, UserId, + events::{GlobalAccountDataEventType, room::message::RoomMessageEventContent}, + push, }; use tracing::{info, warn}; diff --git a/conduit/src/api/client_server/alias.rs b/conduit/src/api/client_server/alias.rs index 6a7e8338..7f11550f 100644 --- a/conduit/src/api/client_server/alias.rs +++ b/conduit/src/api/client_server/alias.rs @@ -1,4 +1,4 @@ -use crate::{services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services}; use ruma::api::client::{ alias::{create_alias, delete_alias, get_alias}, error::ErrorKind, diff --git a/conduit/src/api/client_server/appservice.rs b/conduit/src/api/client_server/appservice.rs index b7a9ef12..9287657f 100644 --- a/conduit/src/api/client_server/appservice.rs +++ b/conduit/src/api/client_server/appservice.rs @@ -5,7 +5,7 @@ use ruma::api::{ client::{appservice::request_ping, error::ErrorKind}, }; -use crate::{api::appservice_server, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, api::appservice_server}; /// # `POST /_matrix/client/v1/appservice/{appserviceId}/ping` /// diff --git a/conduit/src/api/client_server/backup.rs b/conduit/src/api/client_server/backup.rs index 115cba7c..cf527e3e 100644 --- a/conduit/src/api/client_server/backup.rs +++ b/conduit/src/api/client_server/backup.rs @@ -1,4 +1,4 @@ -use crate::{services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services}; use ruma::api::client::{ backup::{ add_backup_keys, add_backup_keys_for_room, add_backup_keys_for_session, diff --git a/conduit/src/api/client_server/capabilities.rs b/conduit/src/api/client_server/capabilities.rs index 4bba3adc..16652f64 100644 --- a/conduit/src/api/client_server/capabilities.rs +++ b/conduit/src/api/client_server/capabilities.rs @@ -1,4 +1,4 @@ -use crate::{services, Result, Ruma}; +use crate::{Result, Ruma, services}; use ruma::api::client::discovery::get_capabilities::{ self, v3::{Capabilities, RoomVersionStability, RoomVersionsCapability}, diff --git a/conduit/src/api/client_server/config.rs b/conduit/src/api/client_server/config.rs index 37279e35..a9e41ff3 100644 --- a/conduit/src/api/client_server/config.rs +++ b/conduit/src/api/client_server/config.rs @@ -1,4 +1,4 @@ -use crate::{services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services}; use ruma::{ api::client::{ config::{ diff --git a/conduit/src/api/client_server/context.rs b/conduit/src/api/client_server/context.rs index a401a877..146607a0 100644 --- a/conduit/src/api/client_server/context.rs +++ b/conduit/src/api/client_server/context.rs @@ -1,4 +1,4 @@ -use crate::{services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services}; use ruma::{ api::client::{context::get_context, error::ErrorKind, filter::LazyLoadOptions}, events::StateEventType, diff --git a/conduit/src/api/client_server/device.rs b/conduit/src/api/client_server/device.rs index c5b52f05..949095dc 100644 --- a/conduit/src/api/client_server/device.rs +++ b/conduit/src/api/client_server/device.rs @@ -1,4 +1,4 @@ -use crate::{services, utils, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services, utils}; use ruma::api::client::{ device::{self, delete_device, delete_devices, get_device, get_devices, update_device}, error::ErrorKind, diff --git a/conduit/src/api/client_server/directory.rs b/conduit/src/api/client_server/directory.rs index ed08989f..ca13cdee 100644 --- a/conduit/src/api/client_server/directory.rs +++ b/conduit/src/api/client_server/directory.rs @@ -1,5 +1,6 @@ -use crate::{services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services}; use ruma::{ + ServerName, UInt, api::{ client::{ directory::{ @@ -13,6 +14,7 @@ use ruma::{ }, directory::{Filter, PublicRoomsChunk, RoomNetwork}, events::{ + StateEventType, room::{ avatar::RoomAvatarEventContent, canonical_alias::RoomCanonicalAliasEventContent, @@ -22,9 +24,7 @@ use ruma::{ join_rules::RoomJoinRulesEventContent, topic::RoomTopicEventContent, }, - StateEventType, }, - ServerName, UInt, }; use tracing::{error, info, warn}; @@ -169,7 +169,7 @@ pub(crate) async fn get_public_rooms_filtered_helper( return Err(Error::BadRequest( ErrorKind::InvalidParam, "Invalid `since` token", - )) + )); } }; diff --git a/conduit/src/api/client_server/filter.rs b/conduit/src/api/client_server/filter.rs index e9a359d6..3ead5836 100644 --- a/conduit/src/api/client_server/filter.rs +++ b/conduit/src/api/client_server/filter.rs @@ -1,4 +1,4 @@ -use crate::{services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services}; use ruma::api::client::{ error::ErrorKind, filter::{create_filter, get_filter}, diff --git a/conduit/src/api/client_server/keys.rs b/conduit/src/api/client_server/keys.rs index 1b2fc819..fc43e6b4 100644 --- a/conduit/src/api/client_server/keys.rs +++ b/conduit/src/api/client_server/keys.rs @@ -1,7 +1,8 @@ use super::SESSION_ID_LENGTH; -use crate::{services, utils, Error, Result, Ruma}; -use futures_util::{stream::FuturesUnordered, StreamExt}; +use crate::{Error, Result, Ruma, services, utils}; +use futures_util::{StreamExt, stream::FuturesUnordered}; use ruma::{ + OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId, api::{ client::{ error::ErrorKind, @@ -14,11 +15,10 @@ use ruma::{ federation, }, serde::Raw, - OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId, }; use serde_json::json; use std::{ - collections::{hash_map, BTreeMap, HashMap, HashSet}, + collections::{BTreeMap, HashMap, HashSet, hash_map}, time::{Duration, Instant}, }; use tracing::{debug, error}; diff --git a/conduit/src/api/client_server/media.rs b/conduit/src/api/client_server/media.rs index e922b157..b66fdc49 100644 --- a/conduit/src/api/client_server/media.rs +++ b/conduit/src/api/client_server/media.rs @@ -3,9 +3,10 @@ use std::time::Duration; -use crate::{service::media::FileMeta, services, utils, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, service::media::FileMeta, services, utils}; use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE}; use ruma::{ + ServerName, UInt, api::{ client::{ authenticated_media::{ @@ -18,7 +19,6 @@ use ruma::{ }, http_headers::{ContentDisposition, ContentDispositionType}, media::Method, - ServerName, UInt, }; const MXC_LENGTH: usize = 32; diff --git a/conduit/src/api/client_server/membership.rs b/conduit/src/api/client_server/membership.rs index 0ef0658a..30cf0fee 100644 --- a/conduit/src/api/client_server/membership.rs +++ b/conduit/src/api/client_server/membership.rs @@ -1,4 +1,5 @@ use ruma::{ + OwnedServerName, RoomId, UserId, api::{ client::{ error::ErrorKind, @@ -11,17 +12,16 @@ use ruma::{ }, federation::{ self, - membership::{create_invite, RawStrippedState}, + membership::{RawStrippedState, create_invite}, }, }, events::{ + StateEventType, TimelineEventType, room::{ join_rules::JoinRule, member::{MembershipState, RoomMemberEventContent}, }, - StateEventType, TimelineEventType, }, - OwnedServerName, RoomId, UserId, }; use serde_json::value::to_raw_value; use std::{ @@ -32,8 +32,9 @@ use tokio::sync::RwLock; use tracing::{error, info, warn}; use crate::{ - service::pdu::{gen_event_id_canonical_json, PduBuilder}, - services, utils, Error, PduEvent, Result, Ruma, + Error, PduEvent, Result, Ruma, + service::pdu::{PduBuilder, gen_event_id_canonical_json}, + services, utils, }; /// # `POST /_matrix/client/r0/rooms/{roomId}/join` @@ -253,7 +254,7 @@ pub async fn knock_room_route( return Err(Error::BadRequest( ErrorKind::forbidden(), "You are not allowed to knock on this room.", - )) + )); } }; @@ -774,7 +775,12 @@ pub(crate) async fn invite_helper( }; if *pdu.event_id != *event_id { - warn!("Server {} changed invite event, that's not allowed in the spec: ours: {:?}, theirs: {:?}", user_id.server_name(), pdu_json, value); + warn!( + "Server {} changed invite event, that's not allowed in the spec: ours: {:?}, theirs: {:?}", + user_id.server_name(), + pdu_json, + value + ); } let origin: OwnedServerName = serde_json::from_value( diff --git a/conduit/src/api/client_server/message.rs b/conduit/src/api/client_server/message.rs index c9a1b978..503da337 100644 --- a/conduit/src/api/client_server/message.rs +++ b/conduit/src/api/client_server/message.rs @@ -1,6 +1,7 @@ use crate::{ + Error, Result, Ruma, service::{pdu::PduBuilder, rooms::timeline::PduCount}, - services, utils, Error, Result, Ruma, + services, utils, }; use ruma::{ api::client::{ diff --git a/conduit/src/api/client_server/openid.rs b/conduit/src/api/client_server/openid.rs index 42160410..f014982c 100644 --- a/conduit/src/api/client_server/openid.rs +++ b/conduit/src/api/client_server/openid.rs @@ -2,7 +2,7 @@ use std::time::Duration; use ruma::{api::client::account, authentication::TokenType}; -use crate::{services, Result, Ruma}; +use crate::{Result, Ruma, services}; /// # `POST /_matrix/client/r0/user/{userId}/openid/request_token` /// diff --git a/conduit/src/api/client_server/presence.rs b/conduit/src/api/client_server/presence.rs index e5cd1b8e..da2db7fe 100644 --- a/conduit/src/api/client_server/presence.rs +++ b/conduit/src/api/client_server/presence.rs @@ -1,4 +1,4 @@ -use crate::{services, utils, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services, utils}; use ruma::api::client::{ error::ErrorKind, presence::{get_presence, set_presence}, diff --git a/conduit/src/api/client_server/profile.rs b/conduit/src/api/client_server/profile.rs index b90ae00e..8b9edd10 100644 --- a/conduit/src/api/client_server/profile.rs +++ b/conduit/src/api/client_server/profile.rs @@ -1,4 +1,4 @@ -use crate::{service::pdu::PduBuilder, services, utils, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, service::pdu::PduBuilder, services, utils}; use ruma::{ api::{ client::{ @@ -9,7 +9,7 @@ use ruma::{ }, federation::{self, query::get_profile_information::v1::ProfileField}, }, - events::{room::member::RoomMemberEventContent, StateEventType, TimelineEventType}, + events::{StateEventType, TimelineEventType, room::member::RoomMemberEventContent}, }; use serde_json::value::to_raw_value; use std::sync::Arc; diff --git a/conduit/src/api/client_server/push.rs b/conduit/src/api/client_server/push.rs index 2968455c..2d1ae93d 100644 --- a/conduit/src/api/client_server/push.rs +++ b/conduit/src/api/client_server/push.rs @@ -1,4 +1,4 @@ -use crate::{services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services}; use ruma::{ api::client::{ error::ErrorKind, @@ -8,7 +8,7 @@ use ruma::{ set_pushrule_enabled, }, }, - events::{push_rules::PushRulesEvent, GlobalAccountDataEventType}, + events::{GlobalAccountDataEventType, push_rules::PushRulesEvent}, push::{InsertPushRuleError, RemovePushRuleError}, }; diff --git a/conduit/src/api/client_server/read_marker.rs b/conduit/src/api/client_server/read_marker.rs index a5553d25..3e8be0a8 100644 --- a/conduit/src/api/client_server/read_marker.rs +++ b/conduit/src/api/client_server/read_marker.rs @@ -1,11 +1,11 @@ -use crate::{service::rooms::timeline::PduCount, services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, service::rooms::timeline::PduCount, services}; use ruma::{ + MilliSecondsSinceUnixEpoch, api::client::{error::ErrorKind, read_marker::set_read_marker, receipt::create_receipt}, events::{ - receipt::{ReceiptThread, ReceiptType}, RoomAccountDataEventType, + receipt::{ReceiptThread, ReceiptType}, }, - MilliSecondsSinceUnixEpoch, }; use std::collections::BTreeMap; @@ -55,7 +55,7 @@ pub async fn set_read_marker_route( return Err(Error::BadRequest( ErrorKind::InvalidParam, "Read receipt is in backfilled timeline", - )) + )); } PduCount::Normal(c) => c, }; @@ -165,7 +165,7 @@ pub async fn create_receipt_route( return Err(Error::BadRequest( ErrorKind::InvalidParam, "Read receipt is in backfilled timeline", - )) + )); } PduCount::Normal(c) => c, }; diff --git a/conduit/src/api/client_server/redact.rs b/conduit/src/api/client_server/redact.rs index fd6ac7b0..e9cace33 100644 --- a/conduit/src/api/client_server/redact.rs +++ b/conduit/src/api/client_server/redact.rs @@ -1,9 +1,9 @@ use std::sync::Arc; -use crate::{service::pdu::PduBuilder, services, Result, Ruma}; +use crate::{Result, Ruma, service::pdu::PduBuilder, services}; use ruma::{ api::client::redact::redact_event, - events::{room::redaction::RoomRedactionEventContent, TimelineEventType}, + events::{TimelineEventType, room::redaction::RoomRedactionEventContent}, }; use serde_json::value::to_raw_value; diff --git a/conduit/src/api/client_server/relations.rs b/conduit/src/api/client_server/relations.rs index 27c00729..a717ef36 100644 --- a/conduit/src/api/client_server/relations.rs +++ b/conduit/src/api/client_server/relations.rs @@ -3,7 +3,7 @@ use ruma::api::client::relations::{ get_relating_events_with_rel_type_and_event_type, }; -use crate::{services, Result, Ruma}; +use crate::{Result, Ruma, services}; /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}` pub async fn get_relating_events_with_rel_type_and_event_type_route( diff --git a/conduit/src/api/client_server/report.rs b/conduit/src/api/client_server/report.rs index ab5027cd..c91588bf 100644 --- a/conduit/src/api/client_server/report.rs +++ b/conduit/src/api/client_server/report.rs @@ -1,4 +1,4 @@ -use crate::{services, utils::HtmlEscape, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services, utils::HtmlEscape}; use ruma::{ api::client::{error::ErrorKind, room::report_content}, events::room::message, @@ -20,7 +20,7 @@ pub async fn report_event_route( return Err(Error::BadRequest( ErrorKind::InvalidParam, "Invalid Event ID", - )) + )); } }; diff --git a/conduit/src/api/client_server/room.rs b/conduit/src/api/client_server/room.rs index 4435256e..dd643e9c 100644 --- a/conduit/src/api/client_server/room.rs +++ b/conduit/src/api/client_server/room.rs @@ -1,12 +1,15 @@ use crate::{ - api::client_server::invite_helper, service::pdu::PduBuilder, services, Error, Result, Ruma, + Error, Result, Ruma, api::client_server::invite_helper, service::pdu::PduBuilder, services, }; use ruma::{ + CanonicalJsonObject, CanonicalJsonValue, Int, OwnedRoomAliasId, OwnedUserId, RoomAliasId, + RoomVersionId, api::client::{ error::ErrorKind, room::{self, aliases, create_room, get_room_event, upgrade_room}, }, events::{ + StateEventType, TimelineEventType, room::{ canonical_alias::RoomCanonicalAliasEventContent, create::RoomCreateEventContent, @@ -19,12 +22,9 @@ use ruma::{ tombstone::RoomTombstoneEventContent, topic::RoomTopicEventContent, }, - StateEventType, TimelineEventType, }, int, serde::JsonObject, - CanonicalJsonObject, CanonicalJsonValue, Int, OwnedRoomAliasId, OwnedUserId, RoomAliasId, - RoomVersionId, }; use serde::Deserialize; use serde_json::{json, value::to_raw_value}; diff --git a/conduit/src/api/client_server/search.rs b/conduit/src/api/client_server/search.rs index 3bbb1ce4..219bbe05 100644 --- a/conduit/src/api/client_server/search.rs +++ b/conduit/src/api/client_server/search.rs @@ -1,4 +1,4 @@ -use crate::{services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services}; use ruma::api::client::{ error::ErrorKind, search::search_events::{ @@ -63,7 +63,7 @@ pub async fn search_events_route( return Err(Error::BadRequest( ErrorKind::InvalidParam, "Invalid next_batch token.", - )) + )); } None => 0, // Default to the start }; diff --git a/conduit/src/api/client_server/session.rs b/conduit/src/api/client_server/session.rs index 581867dc..e1652747 100644 --- a/conduit/src/api/client_server/session.rs +++ b/conduit/src/api/client_server/session.rs @@ -1,12 +1,12 @@ use super::{DEVICE_ID_LENGTH, TOKEN_LENGTH}; -use crate::{services, utils, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services, utils}; use ruma::{ + UserId, api::client::{ error::ErrorKind, session::{get_login_types, login, logout, logout_all}, uiaa::UserIdentifier, }, - UserId, }; use serde::Deserialize; use tracing::{info, warn}; diff --git a/conduit/src/api/client_server/space.rs b/conduit/src/api/client_server/space.rs index 0bf9c567..3e18d8c7 100644 --- a/conduit/src/api/client_server/space.rs +++ b/conduit/src/api/client_server/space.rs @@ -1,9 +1,9 @@ use std::str::FromStr; -use crate::{service::rooms::spaces::PagnationToken, services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, service::rooms::spaces::PagnationToken, services}; use ruma::{ - api::client::{error::ErrorKind, space::get_hierarchy}, UInt, + api::client::{error::ErrorKind, space::get_hierarchy}, }; /// # `GET /_matrix/client/v1/rooms/{room_id}/hierarchy`` diff --git a/conduit/src/api/client_server/state.rs b/conduit/src/api/client_server/state.rs index a33f4af4..6d2755d0 100644 --- a/conduit/src/api/client_server/state.rs +++ b/conduit/src/api/client_server/state.rs @@ -1,7 +1,8 @@ use std::sync::Arc; -use crate::{service::pdu::PduBuilder, services, Error, Result, Ruma, RumaResponse}; +use crate::{Error, Result, Ruma, RumaResponse, service::pdu::PduBuilder, services}; use ruma::{ + EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId, api::client::{ error::ErrorKind, state::{ @@ -10,10 +11,9 @@ use ruma::{ }, }, events::{ - room::canonical_alias::RoomCanonicalAliasEventContent, AnyStateEventContent, StateEventType, + AnyStateEventContent, StateEventType, room::canonical_alias::RoomCanonicalAliasEventContent, }, serde::Raw, - EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId, }; use tracing::warn; diff --git a/conduit/src/api/client_server/sync.rs b/conduit/src/api/client_server/sync.rs index 7139091f..ba8a72e5 100644 --- a/conduit/src/api/client_server/sync.rs +++ b/conduit/src/api/client_server/sync.rs @@ -1,31 +1,32 @@ use crate::{ + Error, PduEvent, Result, Ruma, RumaResponse, service::{pdu::EventHash, rooms::timeline::PduCount}, - services, utils, Error, PduEvent, Result, Ruma, RumaResponse, + services, utils, }; use ruma::{ + DeviceId, EventId, JsOption, OwnedDeviceId, OwnedUserId, RoomId, UInt, UserId, api::client::{ filter::{FilterDefinition, LazyLoadOptions}, sync::sync_events::{ - self, + self, DeviceLists, UnreadNotificationsCount, v3::{ Ephemeral, Filter, GlobalAccountData, InviteState, InvitedRoom, JoinedRoom, KnockState, KnockedRoom, LeftRoom, Presence, RoomAccountData, RoomSummary, Rooms, State, StateEvents, Timeline, ToDevice, }, - DeviceLists, UnreadNotificationsCount, }, uiaa::UiaaResponse, }, events::{ - room::member::{MembershipState, RoomMemberEventContent}, StateEventType, TimelineEventType, + room::member::{MembershipState, RoomMemberEventContent}, }, serde::Raw, - uint, DeviceId, EventId, JsOption, OwnedDeviceId, OwnedUserId, RoomId, UInt, UserId, + uint, }; use std::{ - collections::{hash_map::Entry, BTreeMap, BTreeSet, HashMap, HashSet}, + collections::{BTreeMap, BTreeSet, HashMap, HashSet, hash_map::Entry}, sync::Arc, time::Duration, }; diff --git a/conduit/src/api/client_server/tag.rs b/conduit/src/api/client_server/tag.rs index 16f1600f..6626c995 100644 --- a/conduit/src/api/client_server/tag.rs +++ b/conduit/src/api/client_server/tag.rs @@ -1,9 +1,9 @@ -use crate::{services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services}; use ruma::{ api::client::tag::{create_tag, delete_tag, get_tags}, events::{ - tag::{TagEvent, TagEventContent}, RoomAccountDataEventType, + tag::{TagEvent, TagEventContent}, }, }; use std::collections::BTreeMap; diff --git a/conduit/src/api/client_server/threads.rs b/conduit/src/api/client_server/threads.rs index a095b420..fe9e54d9 100644 --- a/conduit/src/api/client_server/threads.rs +++ b/conduit/src/api/client_server/threads.rs @@ -1,6 +1,6 @@ use ruma::api::client::{error::ErrorKind, threads::get_threads}; -use crate::{services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services}; /// # `GET /_matrix/client/r0/rooms/{roomId}/threads` pub async fn get_threads_route( diff --git a/conduit/src/api/client_server/to_device.rs b/conduit/src/api/client_server/to_device.rs index 31590fc7..5c2717ab 100644 --- a/conduit/src/api/client_server/to_device.rs +++ b/conduit/src/api/client_server/to_device.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use crate::{services, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services}; use ruma::{ api::{ client::{error::ErrorKind, to_device::send_event_to_device}, diff --git a/conduit/src/api/client_server/typing.rs b/conduit/src/api/client_server/typing.rs index 21b7a4b2..7d65a870 100644 --- a/conduit/src/api/client_server/typing.rs +++ b/conduit/src/api/client_server/typing.rs @@ -1,4 +1,4 @@ -use crate::{services, utils, Error, Result, Ruma}; +use crate::{Error, Result, Ruma, services, utils}; use ruma::api::client::{error::ErrorKind, typing::create_typing_event}; /// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}` diff --git a/conduit/src/api/client_server/user_directory.rs b/conduit/src/api/client_server/user_directory.rs index 2c7a9c71..241ba23f 100644 --- a/conduit/src/api/client_server/user_directory.rs +++ b/conduit/src/api/client_server/user_directory.rs @@ -1,9 +1,9 @@ -use crate::{services, Result, Ruma}; +use crate::{Result, Ruma, services}; use ruma::{ api::client::user_directory::search_users, events::{ - room::join_rules::{JoinRule, RoomJoinRulesEventContent}, StateEventType, + room::join_rules::{JoinRule, RoomJoinRulesEventContent}, }, }; diff --git a/conduit/src/api/client_server/voip.rs b/conduit/src/api/client_server/voip.rs index 87714d3f..88677c91 100644 --- a/conduit/src/api/client_server/voip.rs +++ b/conduit/src/api/client_server/voip.rs @@ -1,10 +1,10 @@ -use crate::{services, Error, Result, Ruma}; -use base64::{engine::general_purpose, Engine as _}; +use crate::{Error, Result, Ruma, services}; +use base64::{Engine as _, engine::general_purpose}; use conduit_config::TurnAuth; use hmac::{Hmac, Mac}; use ruma::{ - api::client::{error::ErrorKind, voip::get_turn_server_info}, SecondsSinceUnixEpoch, + api::client::{error::ErrorKind, voip::get_turn_server_info}, }; use sha1::Sha1; use std::time::{Duration, SystemTime}; diff --git a/conduit/src/api/client_server/well_known.rs b/conduit/src/api/client_server/well_known.rs index 1776472d..650e0844 100644 --- a/conduit/src/api/client_server/well_known.rs +++ b/conduit/src/api/client_server/well_known.rs @@ -1,6 +1,6 @@ use ruma::api::client::discovery::discover_homeserver::{self, HomeserverInfo}; -use crate::{services, Result, Ruma}; +use crate::{Result, Ruma, services}; /// # `GET /.well-known/matrix/client` /// diff --git a/conduit/src/api/ruma_wrapper/axum.rs b/conduit/src/api/ruma_wrapper/axum.rs index 8b88b6f0..2b531adb 100644 --- a/conduit/src/api/ruma_wrapper/axum.rs +++ b/conduit/src/api/ruma_wrapper/axum.rs @@ -1,30 +1,30 @@ use std::{collections::BTreeMap, error::Error as _, iter::FromIterator, str}; use axum::{ + RequestPartsExt, body::Body, extract::{FromRequest, Path}, response::{IntoResponse, Response}, - RequestPartsExt, }; use axum_extra::{ - headers::{authorization::Bearer, Authorization}, - typed_header::TypedHeaderRejectionReason, TypedHeader, + headers::{Authorization, authorization::Bearer}, + typed_header::TypedHeaderRejectionReason, }; use bytes::{BufMut, BytesMut}; use http::{Request, StatusCode}; use ruma::{ + CanonicalJsonValue, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, UserId, api::{ - client::error::ErrorKind, federation::authentication::XMatrix, AuthScheme, IncomingRequest, - OutgoingResponse, + AuthScheme, IncomingRequest, OutgoingResponse, client::error::ErrorKind, + federation::authentication::XMatrix, }, - CanonicalJsonValue, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, UserId, }; use serde::Deserialize; use tracing::{debug, error, warn}; use super::{Ruma, RumaResponse}; -use crate::{service::appservice::RegistrationInfo, services, Error, Result}; +use crate::{Error, Result, service::appservice::RegistrationInfo, services}; enum Token { Appservice(Box), diff --git a/conduit/src/api/ruma_wrapper/mod.rs b/conduit/src/api/ruma_wrapper/mod.rs index 862da1dc..d8866194 100644 --- a/conduit/src/api/ruma_wrapper/mod.rs +++ b/conduit/src/api/ruma_wrapper/mod.rs @@ -1,7 +1,7 @@ -use crate::{service::appservice::RegistrationInfo, Error}; +use crate::{Error, service::appservice::RegistrationInfo}; use ruma::{ - api::client::uiaa::UiaaResponse, CanonicalJsonValue, OwnedDeviceId, OwnedServerName, - OwnedUserId, + CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId, + api::client::uiaa::UiaaResponse, }; use std::ops::Deref; diff --git a/conduit/src/api/server_server.rs b/conduit/src/api/server_server.rs index defccb2b..4036c6ee 100644 --- a/conduit/src/api/server_server.rs +++ b/conduit/src/api/server_server.rs @@ -1,33 +1,38 @@ #![allow(deprecated)] use crate::{ + Error, PduEvent, Result, Ruma, SUPPORTED_VERSIONS, api::client_server::{self, claim_keys_helper, get_keys_helper}, service::{ globals::SigningKeys, media::FileMeta, - pdu::{gen_event_id_canonical_json, PduBuilder}, + pdu::{PduBuilder, gen_event_id_canonical_json}, }, - services, utils, Error, PduEvent, Result, Ruma, SUPPORTED_VERSIONS, + services, utils, }; -use axum::{response::IntoResponse, Json}; +use axum::{Json, response::IntoResponse}; use axum_extra::headers::{CacheControl, Header}; use get_profile_information::v1::ProfileField; use http::header::AUTHORIZATION; use ruma::{ + CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, + OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, RoomId, RoomVersionId, + ServerName, Signatures, UserId, api::{ + EndpointError, IncomingResponse, OutgoingRequest, OutgoingResponse, SendAccessToken, client::error::{Error as RumaError, ErrorKind}, federation::{ authenticated_media::{ - get_content, get_content_thumbnail, Content, ContentMetadata, FileOrLocation, + Content, ContentMetadata, FileOrLocation, get_content, get_content_thumbnail, }, authorization::get_event_authorization, backfill::get_backfill, device::get_devices::{self, v1::UserDevice}, directory::{get_public_rooms, get_public_rooms_filtered}, discovery::{ - discover_homeserver, get_server_keys, get_server_version, ServerSigningKeys, - VerifyKey, + ServerSigningKeys, VerifyKey, discover_homeserver, get_server_keys, + get_server_version, }, event::{get_event, get_missing_events, get_room_state, get_room_state_ids}, keys::{claim_keys, get_keys}, @@ -43,25 +48,22 @@ use ruma::{ send_transaction_message, }, }, - EndpointError, IncomingResponse, OutgoingRequest, OutgoingResponse, SendAccessToken, }, directory::{Filter, RoomNetwork}, events::{ + StateEventType, TimelineEventType, receipt::{ReceiptEvent, ReceiptEventContent, ReceiptType}, room::{ join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent}, member::{MembershipState, RoomMemberEventContent}, }, - StateEventType, TimelineEventType, }, room_version_rules::{AuthorizationRules, RoomVersionRules}, serde::{Base64, JsonObject, Raw}, to_device::DeviceIdOrAllDevices, - uint, user_id, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, - OwnedEventId, OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, RoomId, - RoomVersionId, ServerName, Signatures, UserId, + uint, user_id, }; -use serde_json::value::{to_raw_value, RawValue as RawJsonValue}; +use serde_json::value::{RawValue as RawJsonValue, to_raw_value}; use std::{ collections::BTreeMap, fmt::Debug, @@ -2545,7 +2547,7 @@ pub async fn well_known_server( #[cfg(test)] mod tests { - use super::{add_port_to_hostname, get_ip_with_port, FedDest}; + use super::{FedDest, add_port_to_hostname, get_ip_with_port}; #[test] fn ips_get_default_ports() { diff --git a/conduit/src/database/abstraction/rocksdb.rs b/conduit/src/database/abstraction/rocksdb.rs index 3f5cf355..652e4d69 100644 --- a/conduit/src/database/abstraction/rocksdb.rs +++ b/conduit/src/database/abstraction/rocksdb.rs @@ -1,5 +1,5 @@ -use super::{watchers::Watchers, KeyValueDatabaseEngine, KvTree}; -use crate::{utils, Result}; +use super::{KeyValueDatabaseEngine, KvTree, watchers::Watchers}; +use crate::{Result, utils}; use conduit_config::Config; use std::{ future::Future, diff --git a/conduit/src/database/abstraction/sqlite.rs b/conduit/src/database/abstraction/sqlite.rs index e87b693b..697a12ed 100644 --- a/conduit/src/database/abstraction/sqlite.rs +++ b/conduit/src/database/abstraction/sqlite.rs @@ -1,4 +1,4 @@ -use super::{watchers::Watchers, KeyValueDatabaseEngine, KvTree}; +use super::{KeyValueDatabaseEngine, KvTree, watchers::Watchers}; use crate::Result; use conduit_config::Config; use parking_lot::{Mutex, MutexGuard}; diff --git a/conduit/src/database/abstraction/watchers.rs b/conduit/src/database/abstraction/watchers.rs index eb5792be..9e4055b5 100644 --- a/conduit/src/database/abstraction/watchers.rs +++ b/conduit/src/database/abstraction/watchers.rs @@ -1,5 +1,5 @@ use std::{ - collections::{hash_map, HashMap}, + collections::{HashMap, hash_map}, future::Future, pin::Pin, sync::RwLock, diff --git a/conduit/src/database/key_value/account_data.rs b/conduit/src/database/key_value/account_data.rs index edbaa68c..b32cb6fa 100644 --- a/conduit/src/database/key_value/account_data.rs +++ b/conduit/src/database/key_value/account_data.rs @@ -1,13 +1,13 @@ use std::collections::HashMap; use ruma::{ + RoomId, UserId, api::client::error::ErrorKind, events::{AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, RoomAccountDataEventType}, serde::Raw, - RoomId, UserId, }; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, services, utils}; impl service::account_data::Data for KeyValueDatabase { /// Places one event in the account data of the user and removes the previous entry. diff --git a/conduit/src/database/key_value/appservice.rs b/conduit/src/database/key_value/appservice.rs index b547e66a..9ffbfd75 100644 --- a/conduit/src/database/key_value/appservice.rs +++ b/conduit/src/database/key_value/appservice.rs @@ -1,6 +1,6 @@ use ruma::api::appservice::Registration; -use crate::{database::KeyValueDatabase, service, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, utils}; impl service::appservice::Data for KeyValueDatabase { /// Registers an appservice and returns the ID to the caller diff --git a/conduit/src/database/key_value/globals.rs b/conduit/src/database/key_value/globals.rs index 9e30cbe6..a81533b7 100644 --- a/conduit/src/database/key_value/globals.rs +++ b/conduit/src/database/key_value/globals.rs @@ -1,18 +1,19 @@ use std::collections::HashMap; use async_trait::async_trait; -use futures_util::{stream::FuturesUnordered, StreamExt}; +use futures_util::{StreamExt, stream::FuturesUnordered}; use lru_cache::LruCache; use ruma::{ + DeviceId, ServerName, UserId, api::federation::discovery::{OldVerifyKey, ServerSigningKeys}, signatures::Ed25519KeyPair, - DeviceId, ServerName, UserId, }; use crate::{ + Error, Result, database::KeyValueDatabase, service::{self, globals::SigningKeys}, - services, utils, Error, Result, + services, utils, }; pub const COUNTER: &[u8] = b"c"; diff --git a/conduit/src/database/key_value/key_backups.rs b/conduit/src/database/key_value/key_backups.rs index 900b700b..368f5a84 100644 --- a/conduit/src/database/key_value/key_backups.rs +++ b/conduit/src/database/key_value/key_backups.rs @@ -1,15 +1,15 @@ use std::collections::BTreeMap; use ruma::{ + OwnedRoomId, RoomId, UserId, api::client::{ backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup}, error::ErrorKind, }, serde::Raw, - OwnedRoomId, RoomId, UserId, }; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, services, utils}; impl service::key_backups::Data for KeyValueDatabase { fn create_backup( diff --git a/conduit/src/database/key_value/media.rs b/conduit/src/database/key_value/media.rs index cee04158..b2d3da0a 100644 --- a/conduit/src/database/key_value/media.rs +++ b/conduit/src/database/key_value/media.rs @@ -2,11 +2,12 @@ use std::{collections::BTreeMap, ops::Range, slice::Split}; use bytesize::ByteSize; use conduit_config::{MediaRetentionConfig, MediaRetentionScope}; -use ruma::{api::client::error::ErrorKind, OwnedServerName, ServerName, UserId}; -use sha2::{digest::Output, Sha256}; +use ruma::{OwnedServerName, ServerName, UserId, api::client::error::ErrorKind}; +use sha2::{Sha256, digest::Output}; use tracing::error; use crate::{ + Error, Result, database::KeyValueDatabase, service::{ self, @@ -15,7 +16,7 @@ use crate::{ MediaQueryFileInfo, MediaQueryThumbInfo, MediaType, ServerNameOrUserId, }, }, - services, utils, Error, Result, + services, utils, }; impl service::media::Data for KeyValueDatabase { @@ -664,9 +665,9 @@ impl service::media::Data for KeyValueDatabase { } } else { error!( - "Invalid format of key in filehash_servername_mediaid for media with sha256 content hash of {}", - hex::encode(&metadata.sha256_digest) - ); + "Invalid format of key in filehash_servername_mediaid for media with sha256 content hash of {}", + hex::encode(&metadata.sha256_digest) + ); errors.push(Error::BadDatabase( "Invalid format of key in filehash_servername_mediaid", )); @@ -675,9 +676,9 @@ impl service::media::Data for KeyValueDatabase { let thumbnail_id_error = || { error!( - "Invalid format of key in filehash_thumbnail_id for media with sha256 content hash of {}", - hex::encode(&metadata.sha256_digest) - ); + "Invalid format of key in filehash_thumbnail_id for media with sha256 content hash of {}", + hex::encode(&metadata.sha256_digest) + ); Error::BadDatabase("Invalid format of value in filehash_thumbnailid") }; @@ -732,7 +733,9 @@ impl service::media::Data for KeyValueDatabase { } Ok(None) => (), Ok(Some(Err(e))) => { - error!("Error parsing metadata for \"mxc://{server_name}/{media_id}\" from servernamemediaid_metadata: {e}"); + error!( + "Error parsing metadata for \"mxc://{server_name}/{media_id}\" from servernamemediaid_metadata: {e}" + ); errors.push(e); continue; } @@ -748,7 +751,9 @@ impl service::media::Data for KeyValueDatabase { maybe_remove_remaining_metadata(&metadata, &mut errors); } Err(e) => { - error!("Error parsing metadata for thumbnail of \"mxc://{server_name}/{media_id}\" from thumbnailid_metadata: {e}"); + error!( + "Error parsing metadata for thumbnail of \"mxc://{server_name}/{media_id}\" from thumbnailid_metadata: {e}" + ); errors.push(e); } } diff --git a/conduit/src/database/key_value/pusher.rs b/conduit/src/database/key_value/pusher.rs index 5148ccb0..a264fced 100644 --- a/conduit/src/database/key_value/pusher.rs +++ b/conduit/src/database/key_value/pusher.rs @@ -1,9 +1,9 @@ use ruma::{ - api::client::push::{set_pusher, Pusher}, UserId, + api::client::push::{Pusher, set_pusher}, }; -use crate::{database::KeyValueDatabase, service, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, utils}; impl service::pusher::Data for KeyValueDatabase { fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()> { diff --git a/conduit/src/database/key_value/rooms/alias.rs b/conduit/src/database/key_value/rooms/alias.rs index 2f7df781..22b274ac 100644 --- a/conduit/src/database/key_value/rooms/alias.rs +++ b/conduit/src/database/key_value/rooms/alias.rs @@ -1,9 +1,9 @@ use ruma::{ - api::client::error::ErrorKind, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, - UserId, + OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, UserId, + api::client::error::ErrorKind, }; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, services, utils}; impl service::rooms::alias::Data for KeyValueDatabase { fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId, user_id: &UserId) -> Result<()> { diff --git a/conduit/src/database/key_value/rooms/auth_chain.rs b/conduit/src/database/key_value/rooms/auth_chain.rs index 60057ac1..83712c0f 100644 --- a/conduit/src/database/key_value/rooms/auth_chain.rs +++ b/conduit/src/database/key_value/rooms/auth_chain.rs @@ -1,6 +1,6 @@ use std::{collections::HashSet, mem::size_of, sync::Arc}; -use crate::{database::KeyValueDatabase, service, utils, Result}; +use crate::{Result, database::KeyValueDatabase, service, utils}; impl service::rooms::auth_chain::Data for KeyValueDatabase { fn get_cached_eventid_authchain(&self, key: &[u64]) -> Result>>> { diff --git a/conduit/src/database/key_value/rooms/directory.rs b/conduit/src/database/key_value/rooms/directory.rs index e05dee82..91823825 100644 --- a/conduit/src/database/key_value/rooms/directory.rs +++ b/conduit/src/database/key_value/rooms/directory.rs @@ -1,6 +1,6 @@ use ruma::{OwnedRoomId, RoomId}; -use crate::{database::KeyValueDatabase, service, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, utils}; impl service::rooms::directory::Data for KeyValueDatabase { fn set_public(&self, room_id: &RoomId) -> Result<()> { diff --git a/conduit/src/database/key_value/rooms/edus/presence.rs b/conduit/src/database/key_value/rooms/edus/presence.rs index 904b1c44..7af70bad 100644 --- a/conduit/src/database/key_value/rooms/edus/presence.rs +++ b/conduit/src/database/key_value/rooms/edus/presence.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; use ruma::{ - events::presence::PresenceEvent, presence::PresenceState, OwnedUserId, RoomId, UInt, UserId, + OwnedUserId, RoomId, UInt, UserId, events::presence::PresenceEvent, presence::PresenceState, }; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, services, utils}; impl service::rooms::edus::presence::Data for KeyValueDatabase { fn update_presence( diff --git a/conduit/src/database/key_value/rooms/edus/read_receipt.rs b/conduit/src/database/key_value/rooms/edus/read_receipt.rs index 9fc05f64..0ee08b54 100644 --- a/conduit/src/database/key_value/rooms/edus/read_receipt.rs +++ b/conduit/src/database/key_value/rooms/edus/read_receipt.rs @@ -1,8 +1,8 @@ use ruma::{ - events::receipt::ReceiptEvent, serde::Raw, CanonicalJsonObject, OwnedUserId, RoomId, UserId, + CanonicalJsonObject, OwnedUserId, RoomId, UserId, events::receipt::ReceiptEvent, serde::Raw, }; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, services, utils}; impl service::rooms::edus::read_receipt::Data for KeyValueDatabase { fn readreceipt_update( diff --git a/conduit/src/database/key_value/rooms/lazy_load.rs b/conduit/src/database/key_value/rooms/lazy_load.rs index a19d52cb..1cbe2070 100644 --- a/conduit/src/database/key_value/rooms/lazy_load.rs +++ b/conduit/src/database/key_value/rooms/lazy_load.rs @@ -1,6 +1,6 @@ use ruma::{DeviceId, RoomId, UserId}; -use crate::{database::KeyValueDatabase, service, Result}; +use crate::{Result, database::KeyValueDatabase, service}; impl service::rooms::lazy_loading::Data for KeyValueDatabase { fn lazy_load_was_sent_before( diff --git a/conduit/src/database/key_value/rooms/metadata.rs b/conduit/src/database/key_value/rooms/metadata.rs index 57540c40..47fcba2a 100644 --- a/conduit/src/database/key_value/rooms/metadata.rs +++ b/conduit/src/database/key_value/rooms/metadata.rs @@ -1,6 +1,6 @@ use ruma::{OwnedRoomId, RoomId}; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, services, utils}; impl service::rooms::metadata::Data for KeyValueDatabase { fn exists(&self, room_id: &RoomId) -> Result { diff --git a/conduit/src/database/key_value/rooms/outlier.rs b/conduit/src/database/key_value/rooms/outlier.rs index 7985ba81..76bc39b5 100644 --- a/conduit/src/database/key_value/rooms/outlier.rs +++ b/conduit/src/database/key_value/rooms/outlier.rs @@ -1,6 +1,6 @@ use ruma::{CanonicalJsonObject, EventId}; -use crate::{database::KeyValueDatabase, service, Error, PduEvent, Result}; +use crate::{Error, PduEvent, Result, database::KeyValueDatabase, service}; impl service::rooms::outlier::Data for KeyValueDatabase { fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result> { diff --git a/conduit/src/database/key_value/rooms/pdu_metadata.rs b/conduit/src/database/key_value/rooms/pdu_metadata.rs index dbc9bfb8..22d8b75d 100644 --- a/conduit/src/database/key_value/rooms/pdu_metadata.rs +++ b/conduit/src/database/key_value/rooms/pdu_metadata.rs @@ -3,9 +3,10 @@ use std::sync::Arc; use ruma::{EventId, RoomId, UserId}; use crate::{ + Error, PduEvent, Result, database::KeyValueDatabase, service::{self, rooms::timeline::PduCount}, - services, utils, Error, PduEvent, Result, + services, utils, }; impl service::rooms::pdu_metadata::Data for KeyValueDatabase { diff --git a/conduit/src/database/key_value/rooms/search.rs b/conduit/src/database/key_value/rooms/search.rs index 8a2769bd..b358b896 100644 --- a/conduit/src/database/key_value/rooms/search.rs +++ b/conduit/src/database/key_value/rooms/search.rs @@ -1,6 +1,6 @@ use ruma::RoomId; -use crate::{database::KeyValueDatabase, service, services, utils, Result}; +use crate::{Result, database::KeyValueDatabase, service, services, utils}; /// Splits a string into tokens used as keys in the search inverted index /// diff --git a/conduit/src/database/key_value/rooms/short.rs b/conduit/src/database/key_value/rooms/short.rs index 98cfa48a..7aa803fc 100644 --- a/conduit/src/database/key_value/rooms/short.rs +++ b/conduit/src/database/key_value/rooms/short.rs @@ -1,8 +1,8 @@ use std::sync::Arc; -use ruma::{events::StateEventType, EventId, RoomId}; +use ruma::{EventId, RoomId, events::StateEventType}; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, services, utils}; impl service::rooms::short::Data for KeyValueDatabase { fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result { diff --git a/conduit/src/database/key_value/rooms/state.rs b/conduit/src/database/key_value/rooms/state.rs index f17d37bb..40fb3e1f 100644 --- a/conduit/src/database/key_value/rooms/state.rs +++ b/conduit/src/database/key_value/rooms/state.rs @@ -4,7 +4,7 @@ use std::collections::HashSet; use std::sync::Arc; use tokio::sync::MutexGuard; -use crate::{database::KeyValueDatabase, service, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, utils}; impl service::rooms::state::Data for KeyValueDatabase { fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result> { diff --git a/conduit/src/database/key_value/rooms/state_accessor.rs b/conduit/src/database/key_value/rooms/state_accessor.rs index fe40b937..c7e975ac 100644 --- a/conduit/src/database/key_value/rooms/state_accessor.rs +++ b/conduit/src/database/key_value/rooms/state_accessor.rs @@ -1,8 +1,8 @@ use std::{collections::HashMap, sync::Arc}; -use crate::{database::KeyValueDatabase, service, services, utils, Error, PduEvent, Result}; +use crate::{Error, PduEvent, Result, database::KeyValueDatabase, service, services, utils}; use async_trait::async_trait; -use ruma::{events::StateEventType, EventId, RoomId}; +use ruma::{EventId, RoomId, events::StateEventType}; #[async_trait] impl service::rooms::state_accessor::Data for KeyValueDatabase { diff --git a/conduit/src/database/key_value/rooms/state_cache.rs b/conduit/src/database/key_value/rooms/state_cache.rs index f439f5f3..91828cbb 100644 --- a/conduit/src/database/key_value/rooms/state_cache.rs +++ b/conduit/src/database/key_value/rooms/state_cache.rs @@ -1,15 +1,16 @@ use std::{collections::HashSet, sync::Arc}; use ruma::{ + OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, events::{AnyStrippedStateEvent, AnySyncStateEvent}, serde::Raw, - OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, }; use crate::{ - database::{abstraction::KvTree, KeyValueDatabase}, + Error, Result, + database::{KeyValueDatabase, abstraction::KvTree}, service::{self, appservice::RegistrationInfo}, - services, utils, Error, Result, + services, utils, }; use super::{get_room_and_user_byte_ids, get_userroom_id_bytes}; diff --git a/conduit/src/database/key_value/rooms/state_compressor.rs b/conduit/src/database/key_value/rooms/state_compressor.rs index 65ea603e..cdd3dde7 100644 --- a/conduit/src/database/key_value/rooms/state_compressor.rs +++ b/conduit/src/database/key_value/rooms/state_compressor.rs @@ -1,9 +1,10 @@ use std::{collections::HashSet, mem::size_of, sync::Arc}; use crate::{ + Error, Result, database::KeyValueDatabase, service::{self, rooms::state_compressor::data::StateDiff}, - utils, Error, Result, + utils, }; impl service::rooms::state_compressor::Data for KeyValueDatabase { diff --git a/conduit/src/database/key_value/rooms/threads.rs b/conduit/src/database/key_value/rooms/threads.rs index bfdc0cc5..d5363c4d 100644 --- a/conduit/src/database/key_value/rooms/threads.rs +++ b/conduit/src/database/key_value/rooms/threads.rs @@ -1,6 +1,6 @@ -use ruma::{api::client::threads::get_threads::v1::IncludeThreads, OwnedUserId, RoomId, UserId}; +use ruma::{OwnedUserId, RoomId, UserId, api::client::threads::get_threads::v1::IncludeThreads}; -use crate::{database::KeyValueDatabase, service, services, utils, Error, PduEvent, Result}; +use crate::{Error, PduEvent, Result, database::KeyValueDatabase, service, services, utils}; impl service::rooms::threads::Data for KeyValueDatabase { fn threads_until<'a>( diff --git a/conduit/src/database/key_value/rooms/timeline.rs b/conduit/src/database/key_value/rooms/timeline.rs index 0905d215..26574955 100644 --- a/conduit/src/database/key_value/rooms/timeline.rs +++ b/conduit/src/database/key_value/rooms/timeline.rs @@ -1,11 +1,11 @@ use std::{collections::hash_map, mem::size_of, sync::Arc}; use ruma::{ - api::client::error::ErrorKind, CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId, + CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId, api::client::error::ErrorKind, }; use tracing::error; -use crate::{database::KeyValueDatabase, service, services, utils, Error, PduEvent, Result}; +use crate::{Error, PduEvent, Result, database::KeyValueDatabase, service, services, utils}; use service::rooms::timeline::PduCount; @@ -346,11 +346,7 @@ fn count_to_id( pdu_id.extend_from_slice(&0_u64.to_be_bytes()); let num = u64::MAX - x; if subtract { - if num > 0 { - num - offset - } else { - num - } + if num > 0 { num - offset } else { num } } else { num + offset } diff --git a/conduit/src/database/key_value/rooms/user.rs b/conduit/src/database/key_value/rooms/user.rs index 2ba4240e..cd375554 100644 --- a/conduit/src/database/key_value/rooms/user.rs +++ b/conduit/src/database/key_value/rooms/user.rs @@ -1,6 +1,6 @@ use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId}; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service, services, utils}; use super::{get_room_and_user_byte_ids, get_userroom_id_bytes}; @@ -115,7 +115,7 @@ impl service::rooms::user::Data for KeyValueDatabase { let roomid_index = key .iter() .enumerate() - .find(|(_, &b)| b == 0xff) + .find(|&(_, &b)| b == 0xff) .ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))? .0 + 1; // +1 because the room id starts AFTER the separator diff --git a/conduit/src/database/key_value/sending.rs b/conduit/src/database/key_value/sending.rs index b7064610..446553d5 100644 --- a/conduit/src/database/key_value/sending.rs +++ b/conduit/src/database/key_value/sending.rs @@ -1,12 +1,13 @@ use ruma::{ServerName, UserId}; use crate::{ + Error, Result, database::KeyValueDatabase, service::{ self, sending::{OutgoingKind, SendingEventType}, }, - services, utils, Error, Result, + services, utils, }; impl service::sending::Data for KeyValueDatabase { diff --git a/conduit/src/database/key_value/transaction_ids.rs b/conduit/src/database/key_value/transaction_ids.rs index 2ea6ad4a..c284174b 100644 --- a/conduit/src/database/key_value/transaction_ids.rs +++ b/conduit/src/database/key_value/transaction_ids.rs @@ -1,6 +1,6 @@ use ruma::{DeviceId, TransactionId, UserId}; -use crate::{database::KeyValueDatabase, service, Result}; +use crate::{Result, database::KeyValueDatabase, service}; impl service::transaction_ids::Data for KeyValueDatabase { fn add_txnid( diff --git a/conduit/src/database/key_value/uiaa.rs b/conduit/src/database/key_value/uiaa.rs index d6119a8c..d41499fb 100644 --- a/conduit/src/database/key_value/uiaa.rs +++ b/conduit/src/database/key_value/uiaa.rs @@ -1,9 +1,9 @@ use ruma::{ - api::client::{error::ErrorKind, uiaa::UiaaInfo}, CanonicalJsonValue, DeviceId, UserId, + api::client::{error::ErrorKind, uiaa::UiaaInfo}, }; -use crate::{database::KeyValueDatabase, service, Error, Result}; +use crate::{Error, Result, database::KeyValueDatabase, service}; impl service::uiaa::Data for KeyValueDatabase { fn set_uiaa_request( diff --git a/conduit/src/database/key_value/users.rs b/conduit/src/database/key_value/users.rs index e8c22739..55f85f3b 100644 --- a/conduit/src/database/key_value/users.rs +++ b/conduit/src/database/key_value/users.rs @@ -1,20 +1,21 @@ use std::{collections::BTreeMap, mem::size_of}; use ruma::{ + DeviceId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedMxcUri, + OwnedOneTimeKeyId, OwnedUserId, UInt, UserId, api::client::{device::Device, error::ErrorKind, filter::FilterDefinition}, encryption::{CrossSigningKey, DeviceKeys, OneTimeKey}, events::{AnyToDeviceEvent, StateEventType}, serde::Raw, - DeviceId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedMxcUri, - OwnedOneTimeKeyId, OwnedUserId, UInt, UserId, }; use tracing::warn; use crate::{ + Error, Result, api::client_server::TOKEN_LENGTH, database::KeyValueDatabase, service::{self, users::clean_signatures}, - services, utils, Error, Result, + services, utils, }; impl service::users::Data for KeyValueDatabase { diff --git a/conduit/src/database/mod.rs b/conduit/src/database/mod.rs index cc9b88e7..a843e16f 100644 --- a/conduit/src/database/mod.rs +++ b/conduit/src/database/mod.rs @@ -2,24 +2,25 @@ pub mod abstraction; pub mod key_value; use crate::{ + Config, Error, PduEvent, Result, SERVICES, Services, service::{globals, rooms::timeline::PduCount}, - services, utils, Config, Error, PduEvent, Result, Services, SERVICES, + services, utils, }; use abstraction::{KeyValueDatabaseEngine, KvTree}; -use base64::{engine::general_purpose, Engine}; +use base64::{Engine, engine::general_purpose}; use conduit_config::DatabaseBackend; use key_value::media::FilehashMetadata; use lru_cache::LruCache; use ruma::{ + CanonicalJsonValue, EventId, OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedRoomId, + OwnedUserId, RoomId, UserId, events::{ + GlobalAccountDataEvent, GlobalAccountDataEventType, StateEventType, push_rules::{PushRulesEvent, PushRulesEventContent}, room::message::RoomMessageEventContent, - GlobalAccountDataEvent, GlobalAccountDataEventType, StateEventType, }, push::Ruleset, - CanonicalJsonValue, EventId, OwnedDeviceId, OwnedEventId, OwnedMxcUri, OwnedRoomId, - OwnedUserId, RoomId, UserId, }; use serde::Deserialize; use sha2::{Digest, Sha256}; @@ -446,7 +447,7 @@ impl KeyValueDatabase { conduit_user ); return Err(Error::bad_database( - "Cannot reuse an existing database after changing the server name, please delete the old one first." + "Cannot reuse an existing database after changing the server name, please delete the old one first.", )); } } @@ -1000,7 +1001,9 @@ impl KeyValueDatabase { } if services().globals.database_version()? < 17 { - warn!("Migrating media repository to new format. If you have a lot of media stored, this may take a while, so please be patiant!"); + warn!( + "Migrating media repository to new format. If you have a lot of media stored, this may take a while, so please be patiant!" + ); let tree = db._db.open_tree("mediaid_file")?; tree.clear().unwrap(); @@ -1117,7 +1120,9 @@ impl KeyValueDatabase { match set_emergency_access() { Ok(pwd_set) => { if pwd_set { - warn!("The Conduit account emergency password is set! Please unset it as soon as you finish admin account recovery!"); + warn!( + "The Conduit account emergency password is set! Please unset it as soon as you finish admin account recovery!" + ); services().admin.send_message(RoomMessageEventContent::text_plain("The Conduit account emergency password is set! Please unset it as soon as you finish admin account recovery!")); } } @@ -1210,7 +1215,7 @@ impl KeyValueDatabase { #[tracing::instrument] pub async fn start_cleanup_task() { #[cfg(unix)] - use tokio::signal::unix::{signal, SignalKind}; + use tokio::signal::unix::{SignalKind, signal}; use std::time::{Duration, Instant}; diff --git a/conduit/src/lib.rs b/conduit/src/lib.rs index ad04d417..05e2e37a 100644 --- a/conduit/src/lib.rs +++ b/conduit/src/lib.rs @@ -16,7 +16,7 @@ pub use api::ruma_wrapper::{Ruma, RumaResponse}; pub use conduit_config::Config; pub use database::KeyValueDatabase; use ruma::api::{MatrixVersion, SupportedVersions}; -pub use service::{pdu::PduEvent, Services}; +pub use service::{Services, pdu::PduEvent}; pub use utils::error::{Error, Result}; pub static SERVICES: RwLock> = RwLock::new(None); diff --git a/conduit/src/main.rs b/conduit/src/main.rs index 5707d75d..cdac738c 100644 --- a/conduit/src/main.rs +++ b/conduit/src/main.rs @@ -1,41 +1,41 @@ use std::{future::Future, io, net::SocketAddr, sync::atomic, time::Duration}; use axum::{ + Router, body::Body, extract::{FromRequestParts, MatchedPath}, middleware::map_response, response::{IntoResponse, Response}, - routing::{any, get, on, MethodFilter}, - Router, + routing::{MethodFilter, any, get, on}, }; -use axum_server::{bind, bind_rustls, tls_rustls::RustlsConfig, Handle as ServerHandle}; +use axum_server::{Handle as ServerHandle, bind, bind_rustls, tls_rustls::RustlsConfig}; use conduit::api::{client_server, server_server}; use figment::{ + Figment, providers::{Env, Format, Toml}, value::Uncased, - Figment, }; use http::{ - header::{self, HeaderName, CONTENT_SECURITY_POLICY}, Method, StatusCode, Uri, + header::{self, CONTENT_SECURITY_POLICY, HeaderName}, }; use opentelemetry::trace::TracerProvider; use ruma::api::{ + IncomingRequest, client::{ error::{Error as RumaError, ErrorBody, ErrorKind}, uiaa::UiaaResponse, }, - IncomingRequest, }; use tokio::signal; use tower::ServiceBuilder; use tower_http::{ + ServiceBuilderExt as _, cors::{self, CorsLayer}, trace::TraceLayer, - ServiceBuilderExt as _, }; use tracing::{debug, error, info, warn}; -use tracing_subscriber::{prelude::*, EnvFilter}; +use tracing_subscriber::{EnvFilter, prelude::*}; pub use conduit::*; // Re-export everything from the library crate @@ -124,7 +124,9 @@ async fn main() { } if was_deprecated { - warn!("Read conduit documentation and check your configuration if any new configuration parameters should be adjusted"); + warn!( + "Read conduit documentation and check your configuration if any new configuration parameters should be adjusted" + ); } let jaeger = if config.allow_jaeger { @@ -178,7 +180,9 @@ async fn main() { let filter_layer = match EnvFilter::try_new(&config.log) { Ok(s) => s, Err(e) => { - eprintln!("It looks like your config is invalid. The following error occurred while parsing it: {e}"); + eprintln!( + "It looks like your config is invalid. The following error occurred while parsing it: {e}" + ); EnvFilter::try_new("warn").unwrap() } }; @@ -217,7 +221,11 @@ async fn main() { /// Adds additional headers to prevent any potential XSS attacks via the media repo async fn set_csp_header(response: Response) -> impl IntoResponse { ( - [(CONTENT_SECURITY_POLICY, "sandbox; default-src 'none'; script-src 'none'; plugin-types application/pdf; style-src 'unsafe-inline'; object-src 'self';")], response + [( + CONTENT_SECURITY_POLICY, + "sandbox; default-src 'none'; script-src 'none'; plugin-types application/pdf; style-src 'unsafe-inline'; object-src 'self';", + )], + response, ) } @@ -665,7 +673,7 @@ fn method_to_filter(method: Method) -> MethodFilter { #[cfg(unix)] #[tracing::instrument(err)] fn maximize_fd_limit() -> Result<(), nix::errno::Errno> { - use nix::sys::resource::{getrlimit, setrlimit, Resource}; + use nix::sys::resource::{Resource, getrlimit, setrlimit}; let res = Resource::RLIMIT_NOFILE; diff --git a/conduit/src/service/account_data/data.rs b/conduit/src/service/account_data/data.rs index f60d4f26..80bea55f 100644 --- a/conduit/src/service/account_data/data.rs +++ b/conduit/src/service/account_data/data.rs @@ -2,9 +2,9 @@ use std::collections::HashMap; use crate::Result; use ruma::{ + RoomId, UserId, events::{AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, RoomAccountDataEventType}, serde::Raw, - RoomId, UserId, }; pub trait Data: Send + Sync { diff --git a/conduit/src/service/account_data/mod.rs b/conduit/src/service/account_data/mod.rs index dc5e0de7..64106001 100644 --- a/conduit/src/service/account_data/mod.rs +++ b/conduit/src/service/account_data/mod.rs @@ -3,9 +3,9 @@ mod data; pub use data::Data; use ruma::{ + RoomId, UserId, events::{AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, RoomAccountDataEventType}, serde::Raw, - RoomId, UserId, }; use std::collections::HashMap; diff --git a/conduit/src/service/admin/mod.rs b/conduit/src/service/admin/mod.rs index 0a3f87b9..48d0f65c 100644 --- a/conduit/src/service/admin/mod.rs +++ b/conduit/src/service/admin/mod.rs @@ -12,9 +12,13 @@ use clap::{Args, Parser}; use image::GenericImageView; use regex::Regex; use ruma::{ + EventId, MilliSecondsSinceUnixEpoch, MxcUri, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, + OwnedServerName, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, api::appservice::Registration, events::{ + TimelineEventType, room::{ + MediaSource, canonical_alias::RoomCanonicalAliasEventContent, create::RoomCreateEventContent, guest_access::{GuestAccess, RoomGuestAccessEventContent}, @@ -28,28 +32,24 @@ use ruma::{ name::RoomNameEventContent, power_levels::RoomPowerLevelsEventContent, topic::RoomTopicEventContent, - MediaSource, }, - TimelineEventType, }, room_version_rules::RoomVersionRules, - EventId, MilliSecondsSinceUnixEpoch, MxcUri, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, - OwnedServerName, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, }; use serde_json::value::to_raw_value; -use tokio::sync::{mpsc, Mutex, RwLock}; +use tokio::sync::{Mutex, RwLock, mpsc}; use crate::{ - api::client_server::{self, leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH}, + Error, PduEvent, Result, + api::client_server::{self, AUTO_GEN_PASSWORD_LENGTH, leave_all_rooms}, services, utils::{self, HtmlEscape}, - Error, PduEvent, Result, }; use super::{ media::{ - size, BlockedMediaInfo, FileInfo, MediaListItem, MediaQuery, MediaQueryFileInfo, - MediaQueryThumbInfo, ServerNameOrUserId, + BlockedMediaInfo, FileInfo, MediaListItem, MediaQuery, MediaQueryFileInfo, + MediaQueryThumbInfo, ServerNameOrUserId, size, }, pdu::PduBuilder, }; @@ -794,7 +794,7 @@ impl Service { return Ok(RoomMessageEventContent::text_plain(format!( "The supplied username is not a valid username: {e}" )) - .into()) + .into()); } }; @@ -849,7 +849,7 @@ impl Service { return Ok(RoomMessageEventContent::text_plain(format!( "The supplied username is not a valid username: {e}" )) - .into()) + .into()); } }; diff --git a/conduit/src/service/appservice/mod.rs b/conduit/src/service/appservice/mod.rs index 4bf22bc7..9c8a6a44 100644 --- a/conduit/src/service/appservice/mod.rs +++ b/conduit/src/service/appservice/mod.rs @@ -7,12 +7,12 @@ pub use data::Data; use futures_util::Future; use regex::RegexSet; use ruma::{ - api::appservice::{Namespace, Registration}, RoomAliasId, RoomId, UserId, + api::appservice::{Namespace, Registration}, }; use tokio::sync::RwLock; -use crate::{services, Result}; +use crate::{Result, services}; /// Compiled regular expressions for a namespace. #[derive(Clone, Debug)] diff --git a/conduit/src/service/globals/data.rs b/conduit/src/service/globals/data.rs index 49527454..4ae39835 100644 --- a/conduit/src/service/globals/data.rs +++ b/conduit/src/service/globals/data.rs @@ -3,13 +3,13 @@ use std::{ time::{Duration, SystemTime}, }; -use crate::{services, Result}; +use crate::{Result, services}; use async_trait::async_trait; use ruma::{ + DeviceId, MilliSecondsSinceUnixEpoch, ServerName, UserId, api::federation::discovery::{OldVerifyKey, ServerSigningKeys, VerifyKey}, serde::Base64, signatures::Ed25519KeyPair, - DeviceId, MilliSecondsSinceUnixEpoch, ServerName, UserId, }; use serde::Deserialize; diff --git a/conduit/src/service/globals/mod.rs b/conduit/src/service/globals/mod.rs index 73aba6e9..48e92825 100644 --- a/conduit/src/service/globals/mod.rs +++ b/conduit/src/service/globals/mod.rs @@ -1,21 +1,21 @@ mod data; pub use data::{Data, SigningKeys}; use ruma::{ - room_version_rules::RoomVersionRules, serde::Base64, MilliSecondsSinceUnixEpoch, OwnedDeviceId, - OwnedEventId, OwnedRoomAliasId, OwnedRoomId, OwnedServerName, OwnedUserId, RoomAliasId, + MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedEventId, OwnedRoomAliasId, OwnedRoomId, + OwnedServerName, OwnedUserId, RoomAliasId, room_version_rules::RoomVersionRules, serde::Base64, }; use crate::api::server_server::DestinationResponse; -use crate::{services, Config, Error, Result}; +use crate::{Config, Error, Result, services}; use conduit_config::{DirectoryStructure, MediaBackendConfig, TurnConfig}; use futures_util::FutureExt; use hickory_resolver::TokioResolver; use hyper_util::client::legacy::connect::dns::{GaiResolver, Name as HyperName}; use reqwest::dns::{Addrs, Name, Resolve, Resolving}; use ruma::{ - api::{client::sync::sync_events, federation::discovery::ServerSigningKeys}, DeviceId, RoomVersionId, ServerName, UserId, + api::{client::sync::sync_events, federation::discovery::ServerSigningKeys}, }; use std::{ collections::{BTreeMap, HashMap}, @@ -27,12 +27,12 @@ use std::{ path::PathBuf, str::FromStr, sync::{ - atomic::{self, AtomicBool}, Arc, RwLock as StdRwLock, + atomic::{self, AtomicBool}, }, time::{Duration, Instant}, }; -use tokio::sync::{broadcast, watch::Receiver, Mutex, RwLock, Semaphore}; +use tokio::sync::{Mutex, RwLock, Semaphore, broadcast, watch::Receiver}; use tower_service::Service as TowerService; use tracing::{error, info}; @@ -86,7 +86,7 @@ impl RotationHandler { Self(s) } - pub fn watch(&self) -> impl Future { + pub fn watch(&self) -> impl Future + use<> { let mut r = self.0.subscribe(); async move { diff --git a/conduit/src/service/key_backups/data.rs b/conduit/src/service/key_backups/data.rs index bf640015..f9af00bf 100644 --- a/conduit/src/service/key_backups/data.rs +++ b/conduit/src/service/key_backups/data.rs @@ -2,9 +2,9 @@ use std::collections::BTreeMap; use crate::Result; use ruma::{ + OwnedRoomId, RoomId, UserId, api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup}, serde::Raw, - OwnedRoomId, RoomId, UserId, }; pub trait Data: Send + Sync { @@ -26,7 +26,7 @@ pub trait Data: Send + Sync { fn get_latest_backup_version(&self, user_id: &UserId) -> Result>; fn get_latest_backup(&self, user_id: &UserId) - -> Result)>>; + -> Result)>>; fn get_backup(&self, user_id: &UserId, version: &str) -> Result>>; diff --git a/conduit/src/service/key_backups/mod.rs b/conduit/src/service/key_backups/mod.rs index 5fc52ced..003905d7 100644 --- a/conduit/src/service/key_backups/mod.rs +++ b/conduit/src/service/key_backups/mod.rs @@ -3,9 +3,9 @@ pub use data::Data; use crate::Result; use ruma::{ + OwnedRoomId, RoomId, UserId, api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup}, serde::Raw, - OwnedRoomId, RoomId, UserId, }; use std::collections::BTreeMap; diff --git a/conduit/src/service/media/data.rs b/conduit/src/service/media/data.rs index 1033c36b..43a0382a 100644 --- a/conduit/src/service/media/data.rs +++ b/conduit/src/service/media/data.rs @@ -1,6 +1,6 @@ use conduit_config::MediaRetentionConfig; use ruma::{OwnedServerName, ServerName, UserId}; -use sha2::{digest::Output, Sha256}; +use sha2::{Sha256, digest::Output}; use crate::{Error, Result}; diff --git a/conduit/src/service/media/mod.rs b/conduit/src/service/media/mod.rs index d8dabbea..5b2d57b1 100644 --- a/conduit/src/service/media/mod.rs +++ b/conduit/src/service/media/mod.rs @@ -5,18 +5,18 @@ use conduit_config::{DirectoryStructure, MediaBackendConfig, S3MediaBackend}; pub use data::Data; use http::StatusCode; use ruma::{ + OwnedServerName, ServerName, UserId, api::client::{error::ErrorKind, media::is_safe_inline_content_type}, http_headers::{ContentDisposition, ContentDispositionType}, - OwnedServerName, ServerName, UserId, }; use rusty_s3::{ - actions::{DeleteObjectsResponse, ObjectIdentifier}, S3Action, + actions::{DeleteObjectsResponse, ObjectIdentifier}, }; -use sha2::{digest::Output, Digest, Sha256}; +use sha2::{Digest, Sha256, digest::Output}; use tracing::{error, info, warn}; -use crate::{services, utils, Error, Result}; +use crate::{Error, Result, services, utils}; use image::imageops::FilterType; pub struct DbFileMeta { diff --git a/conduit/src/service/mod.rs b/conduit/src/service/mod.rs index 432c0e7a..a364d2fa 100644 --- a/conduit/src/service/mod.rs +++ b/conduit/src/service/mod.rs @@ -4,7 +4,7 @@ use std::{ }; use lru_cache::LruCache; -use tokio::sync::{broadcast, Mutex}; +use tokio::sync::{Mutex, broadcast}; use crate::{Config, Result}; use tokio::sync::RwLock; diff --git a/conduit/src/service/pdu.rs b/conduit/src/service/pdu.rs index 39117072..6982f8a4 100644 --- a/conduit/src/service/pdu.rs +++ b/conduit/src/service/pdu.rs @@ -1,23 +1,24 @@ use crate::Error; use ruma::{ + CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, + OwnedRoomId, OwnedUserId, RoomId, UInt, UserId, api::client::error::ErrorKind, canonical_json::redact_content_in_place, events::{ - room::{member::RoomMemberEventContent, redaction::RoomRedactionEventContent}, - space::child::HierarchySpaceChildEvent, AnyInitialStateEvent, AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent, AnySyncMessageLikeEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent, StateEvent, TimelineEventType, + room::{member::RoomMemberEventContent, redaction::RoomRedactionEventContent}, + space::child::HierarchySpaceChildEvent, }, room_version_rules::{RedactionRules, RoomVersionRules}, serde::{JsonCastable, Raw}, - state_res, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, - OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UInt, UserId, + state_res, }; use serde::{Deserialize, Serialize}; use serde_json::{ json, - value::{to_raw_value, RawValue as RawJsonValue}, + value::{RawValue as RawJsonValue, to_raw_value}, }; use std::{borrow::Cow, cmp::Ordering, collections::BTreeMap, sync::Arc}; use tracing::warn; diff --git a/conduit/src/service/pusher/data.rs b/conduit/src/service/pusher/data.rs index 2062f567..19c9b1cc 100644 --- a/conduit/src/service/pusher/data.rs +++ b/conduit/src/service/pusher/data.rs @@ -1,7 +1,7 @@ use crate::Result; use ruma::{ - api::client::push::{set_pusher, Pusher}, UserId, + api::client::push::{Pusher, set_pusher}, }; pub trait Data: Send + Sync { @@ -12,5 +12,5 @@ pub trait Data: Send + Sync { fn get_pushers(&self, sender: &UserId) -> Result>; fn get_pushkeys<'a>(&'a self, sender: &UserId) - -> Box> + 'a>; + -> Box> + 'a>; } diff --git a/conduit/src/service/pusher/mod.rs b/conduit/src/service/pusher/mod.rs index bbeee253..99dbe509 100644 --- a/conduit/src/service/pusher/mod.rs +++ b/conduit/src/service/pusher/mod.rs @@ -2,21 +2,22 @@ mod data; pub use data::Data; use ruma::{events::AnySyncTimelineEvent, push::PushConditionPowerLevelsCtx}; -use crate::{services, Error, PduEvent, Result, SUPPORTED_VERSIONS}; +use crate::{Error, PduEvent, Result, SUPPORTED_VERSIONS, services}; use bytes::BytesMut; use ruma::{ + RoomId, UInt, UserId, api::{ - client::push::{set_pusher, Pusher, PusherKind}, + IncomingResponse, OutgoingRequest, SendAccessToken, + client::push::{Pusher, PusherKind, set_pusher}, push_gateway::send_event_notification::{ self, v1::{Device, Notification, NotificationCounts, NotificationPriority}, }, - IncomingResponse, OutgoingRequest, SendAccessToken, }, events::TimelineEventType, push::{Action, PushConditionRoomCtx, PushFormat, Ruleset, Tweak}, serde::Raw, - uint, RoomId, UInt, UserId, + uint, }; use std::{fmt::Debug, mem}; diff --git a/conduit/src/service/rooms/alias/mod.rs b/conduit/src/service/rooms/alias/mod.rs index 20a0597e..3a6a7161 100644 --- a/conduit/src/service/rooms/alias/mod.rs +++ b/conduit/src/service/rooms/alias/mod.rs @@ -4,15 +4,15 @@ pub use data::Data; use rand::seq::SliceRandom; use tracing::warn; -use crate::{services, Error, Result}; +use crate::{Error, Result, services}; use ruma::{ + OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId, UserId, api::{ appservice, client::{alias::get_alias, error::ErrorKind}, federation, }, events::StateEventType, - OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId, UserId, }; pub struct Service { @@ -149,7 +149,7 @@ impl Service { return Err(Error::BadRequest( ErrorKind::NotFound, "Room with alias not found.", - )) + )); } }; diff --git a/conduit/src/service/rooms/auth_chain/data.rs b/conduit/src/service/rooms/auth_chain/data.rs index e8c379fc..7c14c9e4 100644 --- a/conduit/src/service/rooms/auth_chain/data.rs +++ b/conduit/src/service/rooms/auth_chain/data.rs @@ -7,5 +7,5 @@ pub trait Data: Send + Sync { shorteventid: &[u64], ) -> Result>>>; fn cache_auth_chain(&self, shorteventid: Vec, auth_chain: Arc>) - -> Result<()>; + -> Result<()>; } diff --git a/conduit/src/service/rooms/auth_chain/mod.rs b/conduit/src/service/rooms/auth_chain/mod.rs index 10be8586..b371258d 100644 --- a/conduit/src/service/rooms/auth_chain/mod.rs +++ b/conduit/src/service/rooms/auth_chain/mod.rs @@ -5,10 +5,10 @@ use std::{ }; pub use data::Data; -use ruma::{api::client::error::ErrorKind, state_res::StateMap, EventId, RoomId}; +use ruma::{EventId, RoomId, api::client::error::ErrorKind, state_res::StateMap}; use tracing::{debug, error, warn}; -use crate::{services, Error, Result}; +use crate::{Error, Result, services}; pub struct Service { pub db: &'static dyn Data, @@ -29,7 +29,7 @@ impl Service { &self, room_id: &RoomId, starting_events: Vec>, - ) -> Result> + 'a> { + ) -> Result> + 'a + use<'a>> { const NUM_BUCKETS: usize = 50; let mut buckets = vec![BTreeSet::new(); NUM_BUCKETS]; diff --git a/conduit/src/service/rooms/edus/presence/data.rs b/conduit/src/service/rooms/edus/presence/data.rs index 53329e08..b0654b47 100644 --- a/conduit/src/service/rooms/edus/presence/data.rs +++ b/conduit/src/service/rooms/edus/presence/data.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use crate::Result; -use ruma::{events::presence::PresenceEvent, OwnedUserId, RoomId, UserId}; +use ruma::{OwnedUserId, RoomId, UserId, events::presence::PresenceEvent}; pub trait Data: Send + Sync { /// Adds a presence event which will be saved until a new event replaces it. diff --git a/conduit/src/service/rooms/edus/presence/mod.rs b/conduit/src/service/rooms/edus/presence/mod.rs index 4b929d28..51eabf3d 100644 --- a/conduit/src/service/rooms/edus/presence/mod.rs +++ b/conduit/src/service/rooms/edus/presence/mod.rs @@ -2,7 +2,7 @@ mod data; use std::collections::HashMap; pub use data::Data; -use ruma::{events::presence::PresenceEvent, OwnedUserId, RoomId, UserId}; +use ruma::{OwnedUserId, RoomId, UserId, events::presence::PresenceEvent}; use crate::Result; diff --git a/conduit/src/service/rooms/edus/read_receipt/data.rs b/conduit/src/service/rooms/edus/read_receipt/data.rs index 044dad82..41d843c1 100644 --- a/conduit/src/service/rooms/edus/read_receipt/data.rs +++ b/conduit/src/service/rooms/edus/read_receipt/data.rs @@ -1,5 +1,5 @@ use crate::Result; -use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId}; +use ruma::{OwnedUserId, RoomId, UserId, events::receipt::ReceiptEvent, serde::Raw}; pub trait Data: Send + Sync { /// Replaces the previous read receipt. diff --git a/conduit/src/service/rooms/edus/read_receipt/mod.rs b/conduit/src/service/rooms/edus/read_receipt/mod.rs index c6035280..7faa86dc 100644 --- a/conduit/src/service/rooms/edus/read_receipt/mod.rs +++ b/conduit/src/service/rooms/edus/read_receipt/mod.rs @@ -3,7 +3,7 @@ mod data; pub use data::Data; use crate::Result; -use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId}; +use ruma::{OwnedUserId, RoomId, UserId, events::receipt::ReceiptEvent, serde::Raw}; pub struct Service { pub db: &'static dyn Data, @@ -32,7 +32,9 @@ impl Service { u64, Raw, )>, - > + 'a { + > + + 'a + + use<'a> { self.db.readreceipts_since(room_id, since) } diff --git a/conduit/src/service/rooms/edus/typing/mod.rs b/conduit/src/service/rooms/edus/typing/mod.rs index 7546aa84..43df6c26 100644 --- a/conduit/src/service/rooms/edus/typing/mod.rs +++ b/conduit/src/service/rooms/edus/typing/mod.rs @@ -1,8 +1,8 @@ -use ruma::{events::SyncEphemeralRoomEvent, OwnedRoomId, OwnedUserId, RoomId, UserId}; +use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId, events::SyncEphemeralRoomEvent}; use std::collections::BTreeMap; -use tokio::sync::{broadcast, RwLock}; +use tokio::sync::{RwLock, broadcast}; -use crate::{services, utils, Result}; +use crate::{Result, services, utils}; pub struct Service { pub typing: RwLock>>, // u64 is unix timestamp of timeout diff --git a/conduit/src/service/rooms/event_handler/mod.rs b/conduit/src/service/rooms/event_handler/mod.rs index c03583be..6123902b 100644 --- a/conduit/src/service/rooms/event_handler/mod.rs +++ b/conduit/src/service/rooms/event_handler/mod.rs @@ -2,15 +2,17 @@ type AsyncRecursiveType<'a, T> = Pin + 'a + Send>>; use std::{ - collections::{hash_map, BTreeMap, HashMap, HashSet}, + collections::{BTreeMap, HashMap, HashSet, hash_map}, pin::Pin, sync::Arc, time::{Duration, Instant, SystemTime}, }; -use futures_util::{stream::FuturesUnordered, Future, StreamExt}; +use futures_util::{Future, StreamExt, stream::FuturesUnordered}; use globals::SigningKeys; use ruma::{ + CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedServerName, + OwnedServerSigningKeyId, RoomId, ServerName, api::{ client::error::ErrorKind, federation::{ @@ -24,24 +26,23 @@ use ruma::{ }, }, events::{ + StateEventType, TimelineEventType, room::{ create::RoomCreateEventContent, redaction::RoomRedactionEventContent, server_acl::RoomServerAclEventContent, }, - StateEventType, TimelineEventType, }, int, room_version_rules::{AuthorizationRules, RoomVersionRules, StateResolutionV2Rules}, serde::Base64, state_res::{self, StateMap}, - uint, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, - OwnedServerName, OwnedServerSigningKeyId, RoomId, ServerName, + uint, }; use serde_json::value::RawValue as RawJsonValue; use tokio::sync::{RwLock, RwLockWriteGuard, Semaphore}; use tracing::{debug, error, info, trace, warn}; -use crate::{service::*, services, Error, PduEvent, Result}; +use crate::{Error, PduEvent, Result, service::*, services}; use super::state_compressor::CompressedStateEvent; @@ -371,7 +372,7 @@ impl Service { return Err(Error::BadRequest( ErrorKind::InvalidParam, "Redaction failed", - )) + )); } }; @@ -718,7 +719,10 @@ impl Service { .collect::>()?, ), Err(e) => { - warn!("State resolution on prev events failed, either an event could not be found or deserialization: {}", e); + warn!( + "State resolution on prev events failed, either an event could not be found or deserialization: {}", + e + ); None } } @@ -773,9 +777,11 @@ impl Service { hash_map::Entry::Vacant(v) => { v.insert(Arc::from(&*pdu.event_id)); } - hash_map::Entry::Occupied(_) => return Err( - Error::bad_database("State event's type and state_key combination exists multiple times."), - ), + hash_map::Entry::Occupied(_) => { + return Err(Error::bad_database( + "State event's type and state_key combination exists multiple times.", + )); + } } } @@ -1100,7 +1106,9 @@ impl Service { ) { Ok(new_state) => new_state, Err(_) => { - return Err(Error::bad_database("State resolution failed, either an event could not be found or deserialization")); + return Err(Error::bad_database( + "State resolution failed, either an event could not be found or deserialization", + )); } }; @@ -1241,8 +1249,10 @@ impl Service { }; if calculated_event_id != *next_id { - warn!("Server didn't return event id we requested: requested: {}, we got {}. Event: {:?}", - next_id, calculated_event_id, &res.pdu); + warn!( + "Server didn't return event id we requested: requested: {}, we got {}. Event: {:?}", + next_id, calculated_event_id, &res.pdu + ); } if let Some(auth_events) = diff --git a/conduit/src/service/rooms/helpers/mod.rs b/conduit/src/service/rooms/helpers/mod.rs index 4f49ffc1..0ef78064 100644 --- a/conduit/src/service/rooms/helpers/mod.rs +++ b/conduit/src/service/rooms/helpers/mod.rs @@ -1,38 +1,40 @@ use std::{ - collections::{hash_map::Entry, BTreeMap, HashMap}, + collections::{BTreeMap, HashMap, hash_map::Entry}, sync::Arc, time::{Duration, Instant}, }; use ruma::{ + CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, + OwnedServerName, RoomId, RoomVersionId, UserId, api::{ client::{ error::ErrorKind, - membership::{join_room_by_id, ThirdPartySigned}, + membership::{ThirdPartySigned, join_room_by_id}, }, federation, }, events::{ + TimelineEventType, room::{ join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent}, member::{MembershipState, RoomMemberEventContent}, }, - TimelineEventType, }, room_version_rules::RoomVersionRules, - state_res, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, - OwnedEventId, OwnedServerName, RoomId, RoomVersionId, UserId, + state_res, }; -use serde_json::value::{to_raw_value, RawValue as RawJsonValue}; +use serde_json::value::{RawValue as RawJsonValue, to_raw_value}; use tokio::sync::RwLock; use tracing::{debug, error, info, warn}; use crate::{ + Error, PduEvent, Result, service::{ globals::SigningKeys, - pdu::{gen_event_id_canonical_json, PduBuilder}, + pdu::{PduBuilder, gen_event_id_canonical_json}, }, - services, utils, Error, PduEvent, Result, + services, utils, }; pub struct Service; @@ -120,7 +122,9 @@ impl Service { info!("send_join finished"); if let Some(signed_raw) = &send_join_response.room_state.event { - info!("There is a signed event. This room is probably using restricted joins. Adding signature to our event"); + info!( + "There is a signed event. This room is probably using restricted joins. Adding signature to our event" + ); let (signed_event_id, signed_value) = match gen_event_id_canonical_json(signed_raw, &room_version_rules) { Ok(t) => t, @@ -162,8 +166,8 @@ impl Service { } Err(e) => { warn!( - "Server {remote_server} sent invalid signature in sendjoin signatures for event {signed_value:?}: {e:?}", - ); + "Server {remote_server} sent invalid signature in sendjoin signatures for event {signed_value:?}: {e:?}", + ); } } } @@ -426,8 +430,8 @@ impl Service { .any(|s| *s != services().globals.server_name()) { info!( - "We couldn't do the join locally, maybe federation can help to satisfy the restricted join requirements" - ); + "We couldn't do the join locally, maybe federation can help to satisfy the restricted join requirements" + ); let (make_join_response, remote_server) = make_join_request(sender_user, room_id, servers).await?; diff --git a/conduit/src/service/rooms/pdu_metadata/data.rs b/conduit/src/service/rooms/pdu_metadata/data.rs index a4df34cc..aabeb1f0 100644 --- a/conduit/src/service/rooms/pdu_metadata/data.rs +++ b/conduit/src/service/rooms/pdu_metadata/data.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use crate::{service::rooms::timeline::PduCount, PduEvent, Result}; +use crate::{PduEvent, Result, service::rooms::timeline::PduCount}; use ruma::{EventId, RoomId, UserId}; pub trait Data: Send + Sync { diff --git a/conduit/src/service/rooms/pdu_metadata/mod.rs b/conduit/src/service/rooms/pdu_metadata/mod.rs index 13fe7c3f..3005ebd7 100644 --- a/conduit/src/service/rooms/pdu_metadata/mod.rs +++ b/conduit/src/service/rooms/pdu_metadata/mod.rs @@ -3,13 +3,13 @@ use std::sync::Arc; pub use data::Data; use ruma::{ - api::{client::relations::get_relating_events, Direction}, - events::{relation::RelationType, TimelineEventType}, EventId, RoomId, UInt, UserId, + api::{Direction, client::relations::get_relating_events}, + events::{TimelineEventType, relation::RelationType}, }; use serde::Deserialize; -use crate::{services, PduEvent, Result}; +use crate::{PduEvent, Result, services}; use super::timeline::PduCount; @@ -197,7 +197,7 @@ impl Service { pdus.clone().iter().map(|pdu| (pdu.to_owned(), 1)).collect(); while let Some(stack_pdu) = stack.pop() { - let target = match stack_pdu.0 .0 { + let target = match stack_pdu.0.0 { PduCount::Normal(c) => c, // TODO: Support backfilled relations PduCount::Backfilled(_) => 0, // This will result in an empty iterator diff --git a/conduit/src/service/rooms/search/mod.rs b/conduit/src/service/rooms/search/mod.rs index aff9a31c..8921e33a 100644 --- a/conduit/src/service/rooms/search/mod.rs +++ b/conduit/src/service/rooms/search/mod.rs @@ -25,7 +25,7 @@ impl Service { &'a self, room_id: &RoomId, search_string: &str, - ) -> Result> + 'a, Vec)>> { + ) -> Result> + 'a + use<'a>, Vec)>> { self.db.search_pdus(room_id, search_string) } } diff --git a/conduit/src/service/rooms/short/data.rs b/conduit/src/service/rooms/short/data.rs index 652c525b..4e550ad8 100644 --- a/conduit/src/service/rooms/short/data.rs +++ b/conduit/src/service/rooms/short/data.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use crate::Result; -use ruma::{events::StateEventType, EventId, RoomId}; +use ruma::{EventId, RoomId, events::StateEventType}; pub trait Data: Send + Sync { fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result; diff --git a/conduit/src/service/rooms/short/mod.rs b/conduit/src/service/rooms/short/mod.rs index 45fadd74..f4c68697 100644 --- a/conduit/src/service/rooms/short/mod.rs +++ b/conduit/src/service/rooms/short/mod.rs @@ -2,7 +2,7 @@ mod data; use std::sync::Arc; pub use data::Data; -use ruma::{events::StateEventType, EventId, RoomId}; +use ruma::{EventId, RoomId, events::StateEventType}; use crate::Result; diff --git a/conduit/src/service/rooms/spaces/mod.rs b/conduit/src/service/rooms/spaces/mod.rs index b1bb8157..301c9933 100644 --- a/conduit/src/service/rooms/spaces/mod.rs +++ b/conduit/src/service/rooms/spaces/mod.rs @@ -5,11 +5,13 @@ use std::{ use lru_cache::LruCache; use ruma::{ + OwnedRoomId, OwnedServerName, RoomId, ServerName, UInt, UserId, api::{ client::{self, error::ErrorKind, space::SpaceHierarchyRoomsChunk}, federation::{self, space::SpaceHierarchyParentSummary}, }, events::{ + StateEventType, room::{ avatar::RoomAvatarEventContent, canonical_alias::RoomCanonicalAliasEventContent, @@ -19,16 +21,14 @@ use ruma::{ topic::RoomTopicEventContent, }, space::child::{HierarchySpaceChildEvent, SpaceChildEventContent}, - StateEventType, }, room::{JoinRuleSummary, RestrictedSummary, RoomSummary}, serde::Raw, - OwnedRoomId, OwnedServerName, RoomId, ServerName, UInt, UserId, }; use tokio::sync::Mutex; use tracing::{debug, error, info, warn}; -use crate::{services, Error, Result}; +use crate::{Error, Result, services}; pub struct CachedSpaceHierarchySummary { summary: SpaceHierarchyParentSummary, diff --git a/conduit/src/service/rooms/state/mod.rs b/conduit/src/service/rooms/state/mod.rs index c9b8685f..2158a7f1 100644 --- a/conduit/src/service/rooms/state/mod.rs +++ b/conduit/src/service/rooms/state/mod.rs @@ -6,22 +6,22 @@ use std::{ pub use data::Data; use ruma::{ + EventId, OwnedEventId, RoomId, RoomVersionId, UserId, api::{client::error::ErrorKind, federation::membership::RawStrippedState}, events::{ + AnyStrippedStateEvent, RECOMMENDED_STRIPPED_STATE_EVENT_TYPES, StateEventType, + TimelineEventType, room::{create::RoomCreateEventContent, member::MembershipState}, - AnyStrippedStateEvent, StateEventType, TimelineEventType, - RECOMMENDED_STRIPPED_STATE_EVENT_TYPES, }, room_version_rules::AuthorizationRules, serde::Raw, state_res::{self, StateMap}, - EventId, OwnedEventId, RoomId, RoomVersionId, UserId, }; use serde::Deserialize; use tokio::sync::MutexGuard; use tracing::warn; -use crate::{services, utils::calculate_hash, Error, PduEvent, Result}; +use crate::{Error, PduEvent, Result, services, utils::calculate_hash}; use super::state_compressor::CompressedStateEvent; diff --git a/conduit/src/service/rooms/state_accessor/data.rs b/conduit/src/service/rooms/state_accessor/data.rs index f3ae3c21..873b67bc 100644 --- a/conduit/src/service/rooms/state_accessor/data.rs +++ b/conduit/src/service/rooms/state_accessor/data.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, sync::Arc}; use async_trait::async_trait; -use ruma::{events::StateEventType, EventId, RoomId}; +use ruma::{EventId, RoomId, events::StateEventType}; use crate::{PduEvent, Result}; diff --git a/conduit/src/service/rooms/state_accessor/mod.rs b/conduit/src/service/rooms/state_accessor/mod.rs index 254b77b9..27bb4733 100644 --- a/conduit/src/service/rooms/state_accessor/mod.rs +++ b/conduit/src/service/rooms/state_accessor/mod.rs @@ -7,7 +7,9 @@ use std::{ pub use data::Data; use lru_cache::LruCache; use ruma::{ + EventId, JsOption, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, events::{ + StateEventType, room::{ avatar::RoomAvatarEventContent, guest_access::{GuestAccess, RoomGuestAccessEventContent}, @@ -17,17 +19,15 @@ use ruma::{ name::RoomNameEventContent, power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent}, }, - StateEventType, }, room::{JoinRuleSummary, RoomMembership}, - state_res::{events::RoomCreateEvent, Event}, - EventId, JsOption, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, + state_res::{Event, events::RoomCreateEvent}, }; use serde_json::value::to_raw_value; use tokio::sync::MutexGuard; use tracing::{error, warn}; -use crate::{service::pdu::PduBuilder, services, Error, PduEvent, Result}; +use crate::{Error, PduEvent, Result, service::pdu::PduBuilder, services}; pub struct Service { pub db: &'static dyn Data, diff --git a/conduit/src/service/rooms/state_cache/data.rs b/conduit/src/service/rooms/state_cache/data.rs index 3ee73dfa..8b052544 100644 --- a/conduit/src/service/rooms/state_cache/data.rs +++ b/conduit/src/service/rooms/state_cache/data.rs @@ -1,10 +1,10 @@ use std::{collections::HashSet, sync::Arc}; -use crate::{service::appservice::RegistrationInfo, Result}; +use crate::{Result, service::appservice::RegistrationInfo}; use ruma::{ + OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, events::{AnyStrippedStateEvent, AnySyncStateEvent}, serde::Raw, - OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, }; pub trait Data: Send + Sync { diff --git a/conduit/src/service/rooms/state_cache/mod.rs b/conduit/src/service/rooms/state_cache/mod.rs index d5c43ea5..0801ef95 100644 --- a/conduit/src/service/rooms/state_cache/mod.rs +++ b/conduit/src/service/rooms/state_cache/mod.rs @@ -4,19 +4,19 @@ use std::{collections::HashSet, sync::Arc}; pub use data::Data; use ruma::{ + OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, events::{ + AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType, + RoomAccountDataEventType, StateEventType, direct::DirectEvent, ignored_user_list::IgnoredUserListEvent, room::{create::RoomCreateEventContent, member::MembershipState}, - AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType, - RoomAccountDataEventType, StateEventType, }, serde::Raw, - OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, }; use tracing::warn; -use crate::{service::appservice::RegistrationInfo, services, Error, Result}; +use crate::{Error, Result, service::appservice::RegistrationInfo, services}; pub struct Service { pub db: &'static dyn Data, @@ -231,7 +231,7 @@ impl Service { pub fn room_servers<'a>( &'a self, room_id: &RoomId, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a + use<'a> { self.db.room_servers(room_id) } @@ -245,7 +245,7 @@ impl Service { pub fn server_rooms<'a>( &'a self, server: &ServerName, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a + use<'a> { self.db.server_rooms(server) } @@ -254,7 +254,7 @@ impl Service { pub fn room_members<'a>( &'a self, room_id: &RoomId, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a + use<'a> { self.db.room_members(room_id) } @@ -275,7 +275,7 @@ impl Service { pub fn room_useroncejoined<'a>( &'a self, room_id: &RoomId, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a + use<'a> { self.db.room_useroncejoined(room_id) } @@ -284,7 +284,7 @@ impl Service { pub fn room_members_invited<'a>( &'a self, room_id: &RoomId, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a + use<'a> { self.db.room_members_invited(room_id) } @@ -308,7 +308,7 @@ impl Service { pub fn rooms_joined<'a>( &'a self, user_id: &UserId, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a + use<'a> { self.db.rooms_joined(user_id) } @@ -317,7 +317,8 @@ impl Service { pub fn rooms_invited<'a>( &'a self, user_id: &UserId, - ) -> impl Iterator>)>> + 'a { + ) -> impl Iterator>)>> + 'a + use<'a> + { self.db.rooms_invited(user_id) } @@ -326,7 +327,8 @@ impl Service { pub fn rooms_knocked<'a>( &'a self, user_id: &UserId, - ) -> impl Iterator>)>> + 'a { + ) -> impl Iterator>)>> + 'a + use<'a> + { self.db.rooms_knocked(user_id) } @@ -362,7 +364,8 @@ impl Service { pub fn rooms_left<'a>( &'a self, user_id: &UserId, - ) -> impl Iterator>)>> + 'a { + ) -> impl Iterator>)>> + 'a + use<'a> + { self.db.rooms_left(user_id) } diff --git a/conduit/src/service/rooms/state_compressor/mod.rs b/conduit/src/service/rooms/state_compressor/mod.rs index 6118e06b..756e8a3b 100644 --- a/conduit/src/service/rooms/state_compressor/mod.rs +++ b/conduit/src/service/rooms/state_compressor/mod.rs @@ -9,7 +9,7 @@ pub use data::Data; use lru_cache::LruCache; use ruma::{EventId, RoomId}; -use crate::{services, utils, Result}; +use crate::{Result, services, utils}; use self::data::StateDiff; diff --git a/conduit/src/service/rooms/threads/data.rs b/conduit/src/service/rooms/threads/data.rs index e7159de0..1c4df7c0 100644 --- a/conduit/src/service/rooms/threads/data.rs +++ b/conduit/src/service/rooms/threads/data.rs @@ -1,5 +1,5 @@ use crate::{PduEvent, Result}; -use ruma::{api::client::threads::get_threads::v1::IncludeThreads, OwnedUserId, RoomId, UserId}; +use ruma::{OwnedUserId, RoomId, UserId, api::client::threads::get_threads::v1::IncludeThreads}; pub trait Data: Send + Sync { #[allow(clippy::type_complexity)] diff --git a/conduit/src/service/rooms/threads/mod.rs b/conduit/src/service/rooms/threads/mod.rs index 0471af2e..eb41d466 100644 --- a/conduit/src/service/rooms/threads/mod.rs +++ b/conduit/src/service/rooms/threads/mod.rs @@ -2,14 +2,15 @@ mod data; pub use data::Data; use ruma::{ + CanonicalJsonValue, EventId, RoomId, UserId, api::client::{error::ErrorKind, threads::get_threads::v1::IncludeThreads}, events::relation::BundledThread, - uint, CanonicalJsonValue, EventId, RoomId, UserId, + uint, }; use serde_json::json; -use crate::{services, Error, PduEvent, Result}; +use crate::{Error, PduEvent, Result, services}; pub struct Service { pub db: &'static dyn Data, diff --git a/conduit/src/service/rooms/timeline/mod.rs b/conduit/src/service/rooms/timeline/mod.rs index 82cabad2..4e133705 100644 --- a/conduit/src/service/rooms/timeline/mod.rs +++ b/conduit/src/service/rooms/timeline/mod.rs @@ -10,34 +10,36 @@ use std::{ pub use data::Data; use ruma::{ + CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, + OwnedRoomId, OwnedServerName, RoomId, ServerName, UserId, api::{client::error::ErrorKind, federation}, canonical_json::to_canonical_value, events::{ + GlobalAccountDataEventType, StateEventType, TimelineEventType, push_rules::PushRulesEvent, room::{ canonical_alias::RoomCanonicalAliasEventContent, create::RoomCreateEventContent, encrypted::Relation, member::MembershipState, redaction::RoomRedactionEventContent, }, - GlobalAccountDataEventType, StateEventType, TimelineEventType, }, push::{Action, PushConditionPowerLevelsCtx, Ruleset, Tweak}, room_version_rules::AuthorizationRules, state_res::{self, Event}, - uint, user_id, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, - OwnedEventId, OwnedRoomId, OwnedServerName, RoomId, ServerName, UserId, + uint, user_id, }; use serde::Deserialize; -use serde_json::value::{to_raw_value, RawValue as RawJsonValue}; +use serde_json::value::{RawValue as RawJsonValue, to_raw_value}; use tokio::sync::{Mutex, MutexGuard, RwLock}; use tracing::{error, info, warn}; use crate::{ + Error, PduEvent, Result, api::server_server, service::{ globals::SigningKeys, pdu::{EventHash, PduBuilder}, }, - services, utils, Error, PduEvent, Result, + services, utils, }; use super::state_compressor::CompressedStateEvent; @@ -858,7 +860,7 @@ impl Service { ErrorKind::Unknown, "Signing event failed", )), - } + }; } } @@ -1207,7 +1209,7 @@ impl Service { &'a self, user_id: &UserId, room_id: &RoomId, - ) -> Result> + 'a> { + ) -> Result> + 'a + use<'a>> { self.pdus_after(user_id, room_id, PduCount::min()) } @@ -1219,7 +1221,7 @@ impl Service { user_id: &UserId, room_id: &RoomId, until: PduCount, - ) -> Result> + 'a> { + ) -> Result> + 'a + use<'a>> { self.db.pdus_until(user_id, room_id, until) } @@ -1231,7 +1233,7 @@ impl Service { user_id: &UserId, room_id: &RoomId, from: PduCount, - ) -> Result> + 'a> { + ) -> Result> + 'a + use<'a>> { self.db.pdus_after(user_id, room_id, from) } diff --git a/conduit/src/service/rooms/user/mod.rs b/conduit/src/service/rooms/user/mod.rs index 672e502d..71dbb0a4 100644 --- a/conduit/src/service/rooms/user/mod.rs +++ b/conduit/src/service/rooms/user/mod.rs @@ -43,7 +43,7 @@ impl Service { pub fn get_shared_rooms( &self, users: Vec, - ) -> Result>> { + ) -> Result> + use<>> { self.db.get_shared_rooms(users) } } diff --git a/conduit/src/service/sending/mod.rs b/conduit/src/service/sending/mod.rs index f2d08a54..03c8fc75 100644 --- a/conduit/src/service/sending/mod.rs +++ b/conduit/src/service/sending/mod.rs @@ -10,18 +10,20 @@ use std::{ }; use crate::{ + Config, Error, PduEvent, Result, api::{appservice_server, server_server}, services, utils::calculate_hash, - Config, Error, PduEvent, Result, }; use federation::transactions::send_transaction_message; -use futures_util::{stream::FuturesUnordered, StreamExt}; +use futures_util::{StreamExt, stream::FuturesUnordered}; -use base64::{engine::general_purpose, Engine as _}; +use base64::{Engine as _, engine::general_purpose}; use ruma::{ + MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedUserId, ServerName, UInt, UserId, api::{ + OutgoingRequest, appservice::{self, Registration}, federation::{ self, @@ -29,18 +31,17 @@ use ruma::{ DeviceListUpdateContent, Edu, ReceiptContent, ReceiptData, ReceiptMap, }, }, - OutgoingRequest, }, device_id, events::{ - push_rules::PushRulesEvent, receipt::ReceiptType, AnySyncEphemeralRoomEvent, - GlobalAccountDataEventType, + AnySyncEphemeralRoomEvent, GlobalAccountDataEventType, push_rules::PushRulesEvent, + receipt::ReceiptType, }, - push, uint, MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedUserId, ServerName, UInt, UserId, + push, uint, }; use tokio::{ select, - sync::{mpsc, Mutex, Semaphore}, + sync::{Mutex, Semaphore, mpsc}, }; use tracing::{debug, error, warn}; diff --git a/conduit/src/service/uiaa/data.rs b/conduit/src/service/uiaa/data.rs index c64deb90..8e6963ab 100644 --- a/conduit/src/service/uiaa/data.rs +++ b/conduit/src/service/uiaa/data.rs @@ -1,5 +1,5 @@ use crate::Result; -use ruma::{api::client::uiaa::UiaaInfo, CanonicalJsonValue, DeviceId, UserId}; +use ruma::{CanonicalJsonValue, DeviceId, UserId, api::client::uiaa::UiaaInfo}; pub trait Data: Send + Sync { fn set_uiaa_request( diff --git a/conduit/src/service/uiaa/mod.rs b/conduit/src/service/uiaa/mod.rs index 696be958..19574517 100644 --- a/conduit/src/service/uiaa/mod.rs +++ b/conduit/src/service/uiaa/mod.rs @@ -3,15 +3,15 @@ mod data; pub use data::Data; use ruma::{ + CanonicalJsonValue, DeviceId, UserId, api::client::{ error::ErrorKind, uiaa::{AuthData, AuthType, Password, UiaaInfo, UserIdentifier}, }, - CanonicalJsonValue, DeviceId, UserId, }; use tracing::error; -use crate::{api::client_server::SESSION_ID_LENGTH, services, utils, Error, Result}; +use crate::{Error, Result, api::client_server::SESSION_ID_LENGTH, services, utils}; pub struct Service { pub db: &'static dyn Data, @@ -69,7 +69,7 @@ impl Service { return Err(Error::BadRequest( ErrorKind::Unrecognized, "Identifier type not recognized.", - )) + )); } }; diff --git a/conduit/src/service/users/data.rs b/conduit/src/service/users/data.rs index 74ec8f87..73b58679 100644 --- a/conduit/src/service/users/data.rs +++ b/conduit/src/service/users/data.rs @@ -1,11 +1,11 @@ use crate::Result; use ruma::{ + DeviceId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedMxcUri, + OwnedOneTimeKeyId, OwnedUserId, UInt, UserId, api::client::{device::Device, filter::FilterDefinition}, encryption::{CrossSigningKey, DeviceKeys, OneTimeKey}, events::AnyToDeviceEvent, serde::Raw, - DeviceId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedMxcUri, - OwnedOneTimeKeyId, OwnedUserId, UInt, UserId, }; use std::collections::BTreeMap; @@ -198,7 +198,7 @@ pub trait Data: Send + Sync { /// Get device metadata. fn get_device_metadata(&self, user_id: &UserId, device_id: &DeviceId) - -> Result>; + -> Result>; fn get_devicelist_version(&self, user_id: &UserId) -> Result>; diff --git a/conduit/src/service/users/mod.rs b/conduit/src/service/users/mod.rs index f5d57fb3..428b6a1a 100644 --- a/conduit/src/service/users/mod.rs +++ b/conduit/src/service/users/mod.rs @@ -8,6 +8,8 @@ use std::{ pub use data::Data; use ruma::{ + DeviceId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedMxcUri, + OwnedOneTimeKeyId, OwnedRoomId, OwnedUserId, UInt, UserId, api::client::{ device::Device, filter::FilterDefinition, @@ -16,13 +18,11 @@ use ruma::{ encryption::{CrossSigningKey, DeviceKeys, OneTimeKey}, events::AnyToDeviceEvent, serde::Raw, - DeviceId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedMxcUri, - OwnedOneTimeKeyId, OwnedRoomId, OwnedUserId, UInt, UserId, }; use tokio::{sync::Mutex, time::interval}; use tracing::{debug, warn}; -use crate::{services, Error, Result}; +use crate::{Error, Result, services}; pub struct SlidingSyncCache { lists: BTreeMap, @@ -374,7 +374,7 @@ impl Service { pub fn all_device_ids<'a>( &'a self, user_id: &UserId, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a + use<'a> { self.db.all_device_ids(user_id) } @@ -456,7 +456,7 @@ impl Service { user_or_room_id: &str, from: u64, to: Option, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a + use<'a> { self.db.keys_changed(user_or_room_id, from, to) } diff --git a/conduit/src/utils/error.rs b/conduit/src/utils/error.rs index 49c34ba9..c786e774 100644 --- a/conduit/src/utils/error.rs +++ b/conduit/src/utils/error.rs @@ -2,11 +2,11 @@ use std::convert::Infallible; use http::StatusCode; use ruma::{ + OwnedServerName, api::client::{ error::{Error as RumaError, ErrorBody, ErrorKind}, uiaa::{UiaaInfo, UiaaResponse}, }, - OwnedServerName, }; use thiserror::Error; use tracing::{error, info}; diff --git a/conduit/src/utils/mod.rs b/conduit/src/utils/mod.rs index 7bc20db3..b7719d74 100644 --- a/conduit/src/utils/mod.rs +++ b/conduit/src/utils/mod.rs @@ -5,13 +5,13 @@ use cmp::Ordering; use rand::prelude::*; use ring::digest; use ruma::{ + CanonicalJsonError, CanonicalJsonObject, CanonicalJsonValue, RoomId, api::{client::error::ErrorKind, federation::membership::RawStrippedState}, canonical_json::try_from_json_map, events::AnyStrippedStateEvent, room_version_rules::RoomVersionRules, serde::Raw, signatures::Verified, - CanonicalJsonError, CanonicalJsonObject, CanonicalJsonValue, RoomId, }; use serde_json::value::to_raw_value; use std::{ @@ -23,7 +23,7 @@ use std::{ use tokio::sync::RwLock; use tracing::warn; -use crate::{service::pdu::gen_event_id_canonical_json, services, Error, Result}; +use crate::{Error, Result, service::pdu::gen_event_id_canonical_json, services}; pub fn millis_since_unix_epoch() -> u64 { SystemTime::now()