diff --git a/src/api/client/account.rs b/src/api/client/account.rs index bbfe9473..59998292 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -889,7 +889,7 @@ pub async fn full_user_deactivate( services: &Services, user_id: &UserId, all_joined_rooms: &[OwnedRoomId], -) -> Result<()> { +) -> Result { services .users .deactivate_account(user_id) diff --git a/src/api/client/keys.rs b/src/api/client/keys.rs index cef98a25..3d155057 100644 --- a/src/api/client/keys.rs +++ b/src/api/client/keys.rs @@ -597,7 +597,7 @@ fn add_unsigned_device_display_name( keys: &mut Raw, metadata: ruma::api::client::device::Device, include_display_names: bool, -) -> serde_json::Result<()> { +) -> Result { if let Some(display_name) = metadata.display_name { let mut object = keys.deserialize_as::>()?; diff --git a/src/api/client/membership/leave.rs b/src/api/client/membership/leave.rs index dcdf7c91..e71e73f6 100644 --- a/src/api/client/membership/leave.rs +++ b/src/api/client/membership/leave.rs @@ -230,11 +230,7 @@ pub async fn leave_room( Ok(()) } -async fn remote_leave_room( - services: &Services, - user_id: &UserId, - room_id: &RoomId, -) -> Result<()> { +async fn remote_leave_room(services: &Services, user_id: &UserId, room_id: &RoomId) -> Result { let mut make_leave_response_and_server = Err!(BadServerResponse("No remote server available to assist in leaving {room_id}.")); diff --git a/src/api/client/report.rs b/src/api/client/report.rs index 4fc6d7d7..009c71ed 100644 --- a/src/api/client/report.rs +++ b/src/api/client/report.rs @@ -149,7 +149,7 @@ async fn is_event_report_valid( reason: Option<&String>, score: Option, pdu: &PduEvent, -) -> Result<()> { +) -> Result { debug_info!( "Checking if report from user {sender_user} for event {event_id} in room {room_id} is \ valid" diff --git a/src/api/router/auth.rs b/src/api/router/auth.rs index 5eb2f089..13365dce 100644 --- a/src/api/router/auth.rs +++ b/src/api/router/auth.rs @@ -309,7 +309,7 @@ async fn auth_server( }) } -fn auth_server_checks(services: &Services, x_matrix: &XMatrix) -> Result<()> { +fn auth_server_checks(services: &Services, x_matrix: &XMatrix) -> Result { if !services.server.config.allow_federation { return Err!(Config("allow_federation", "Federation is disabled.")); } diff --git a/src/core/config/check.rs b/src/core/config/check.rs index 0d87dce0..849e4c7b 100644 --- a/src/core/config/check.rs +++ b/src/core/config/check.rs @@ -321,7 +321,7 @@ fn warn_unknown_key(config: &Config) { /// Checks the presence of the `address` and `unix_socket_path` keys in the /// raw_config, exiting the process if both keys were detected. -pub(super) fn is_dual_listening(raw_config: &Figment) -> Result<()> { +pub(super) fn is_dual_listening(raw_config: &Figment) -> Result { let contains_address = raw_config.contains("address"); let contains_unix_socket = raw_config.contains("unix_socket_path"); if contains_address && contains_unix_socket { diff --git a/src/core/info/cargo.rs b/src/core/info/cargo.rs index cb444848..6346d220 100644 --- a/src/core/info/cargo.rs +++ b/src/core/info/cargo.rs @@ -78,7 +78,7 @@ fn init_features() -> Result> { Ok(features) } -fn append_features(features: &mut Vec, manifest: &str) -> Result<()> { +fn append_features(features: &mut Vec, manifest: &str) -> Result { let manifest = Manifest::from_str(manifest)?; features.extend(manifest.features.keys().cloned()); diff --git a/src/core/log/capture/util.rs b/src/core/log/capture/util.rs index 65524be5..fcb23305 100644 --- a/src/core/log/capture/util.rs +++ b/src/core/log/capture/util.rs @@ -22,7 +22,7 @@ where pub fn fmt(fun: F, out: Arc>) -> Box where - F: Fn(&mut S, &Level, &str, &str) -> Result<()> + Send + Sync + Copy + 'static, + F: Fn(&mut S, &Level, &str, &str) -> Result + Send + Sync + Copy + 'static, S: std::fmt::Write + Send + 'static, { Box::new(move |data| call(fun, &mut *out.lock().expect("locked"), &data)) @@ -30,7 +30,7 @@ where fn call(fun: F, out: &mut S, data: &Data<'_>) where - F: Fn(&mut S, &Level, &str, &str) -> Result<()>, + F: Fn(&mut S, &Level, &str, &str) -> Result, S: std::fmt::Write, { fun(out, &data.level(), data.span_name(), data.message()).expect("log line appended"); diff --git a/src/core/log/fmt.rs b/src/core/log/fmt.rs index b73d0c9b..9d4be4b1 100644 --- a/src/core/log/fmt.rs +++ b/src/core/log/fmt.rs @@ -3,7 +3,7 @@ use std::fmt::Write; use super::{Level, color}; use crate::Result; -pub fn html(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()> +pub fn html(out: &mut S, level: &Level, span: &str, msg: &str) -> Result where S: Write + ?Sized, { @@ -18,7 +18,7 @@ where Ok(()) } -pub fn markdown(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()> +pub fn markdown(out: &mut S, level: &Level, span: &str, msg: &str) -> Result where S: Write + ?Sized, { @@ -28,7 +28,7 @@ where Ok(()) } -pub fn markdown_table(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()> +pub fn markdown_table(out: &mut S, level: &Level, span: &str, msg: &str) -> Result where S: Write + ?Sized, { @@ -38,7 +38,7 @@ where Ok(()) } -pub fn markdown_table_head(out: &mut S) -> Result<()> +pub fn markdown_table_head(out: &mut S) -> Result where S: Write + ?Sized, { diff --git a/src/core/log/reload.rs b/src/core/log/reload.rs index c97a56e1..27726e82 100644 --- a/src/core/log/reload.rs +++ b/src/core/log/reload.rs @@ -49,7 +49,7 @@ impl LogLevelReloadHandles { .insert(name.into(), handle); } - pub fn reload(&self, new_value: &EnvFilter, names: Option<&[&str]>) -> Result<()> { + pub fn reload(&self, new_value: &EnvFilter, names: Option<&[&str]>) -> Result { self.handles .lock() .expect("locked") diff --git a/src/core/server.rs b/src/core/server.rs index ab6d5135..16920f7d 100644 --- a/src/core/server.rs +++ b/src/core/server.rs @@ -64,7 +64,7 @@ impl Server { } } - pub fn reload(&self) -> Result<()> { + pub fn reload(&self) -> Result { if cfg!(any(not(tuwunel_mods), not(feature = "tuwunel_mods"))) { return Err!("Reloading not enabled"); } @@ -103,7 +103,7 @@ impl Server { }) } - pub fn signal(&self, sig: &'static str) -> Result<()> { + pub fn signal(&self, sig: &'static str) -> Result { if let Err(e) = self.signal.send(sig) { return Err!("Failed to send signal: {e}"); } diff --git a/src/core/utils/hash/argon.rs b/src/core/utils/hash/argon.rs index 66dfab75..5659dcb8 100644 --- a/src/core/utils/hash/argon.rs +++ b/src/core/utils/hash/argon.rs @@ -36,7 +36,7 @@ pub(super) fn password(password: &str) -> Result { .map_err(map_err) } -pub(super) fn verify_password(password: &str, password_hash: &str) -> Result<()> { +pub(super) fn verify_password(password: &str, password_hash: &str) -> Result { let password_hash = PasswordHash::new(password_hash).map_err(map_err)?; ARGON .get_or_init(init_argon) diff --git a/src/core/utils/string.rs b/src/core/utils/string.rs index 179fe733..ca2e62b5 100644 --- a/src/core/utils/string.rs +++ b/src/core/utils/string.rs @@ -42,7 +42,7 @@ macro_rules! is_format { #[inline] pub fn collect_stream(func: F) -> Result where - F: FnOnce(&mut dyn std::fmt::Write) -> Result<()>, + F: FnOnce(&mut dyn std::fmt::Write) -> Result, { let mut out = String::new(); func(&mut out)?; @@ -63,7 +63,7 @@ pub fn camel_to_snake_string(s: &str) -> String { #[inline] #[allow(clippy::unbuffered_bytes)] // these are allocated string utilities, not file I/O utils -pub fn camel_to_snake_case(output: &mut O, input: I) -> Result<()> +pub fn camel_to_snake_case(output: &mut O, input: I) -> Result where I: std::io::Read, O: std::fmt::Write, diff --git a/src/database/de.rs b/src/database/de.rs index 1d4f7b53..2180e0fb 100644 --- a/src/database/de.rs +++ b/src/database/de.rs @@ -54,7 +54,7 @@ impl<'de> Deserializer<'de> { /// Determine if the input was fully consumed and error if bytes remaining. /// This is intended for debug assertions; not optimized for parsing logic. - fn finished(&self) -> Result<()> { + fn finished(&self) -> Result { let pos = self.pos; let len = self.buf.len(); let parsed = &self.buf[0..pos]; diff --git a/src/main/mods.rs b/src/main/mods.rs index 181d6b37..76e8dcd0 100644 --- a/src/main/mods.rs +++ b/src/main/mods.rs @@ -17,10 +17,10 @@ use crate::Server; type StartFuncResult = Pin>> + Send>>; type StartFuncProto = fn(&Arc) -> StartFuncResult; -type RunFuncResult = Pin> + Send>>; +type RunFuncResult = Pin + Send>>; type RunFuncProto = fn(&Arc) -> RunFuncResult; -type StopFuncResult = Pin> + Send>>; +type StopFuncResult = Pin + Send>>; type StopFuncProto = fn(Arc) -> StopFuncResult; const RESTART_THRESH: &str = "tuwunel_service"; diff --git a/src/router/mod.rs b/src/router/mod.rs index b7b3df31..73050ed9 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -30,7 +30,7 @@ pub extern "Rust" fn start( #[unsafe(no_mangle)] pub extern "Rust" fn stop( services: Arc, -) -> Pin> + Send>> { +) -> Pin + Send>> { AssertUnwindSafe(run::stop(services)) .catch_unwind() .map_err(Error::from_panic) @@ -41,7 +41,7 @@ pub extern "Rust" fn stop( #[unsafe(no_mangle)] pub extern "Rust" fn run( services: &Arc, -) -> Pin> + Send>> { +) -> Pin + Send>> { AssertUnwindSafe(run::run(services.clone())) .catch_unwind() .map_err(Error::from_panic) diff --git a/src/router/run.rs b/src/router/run.rs index 65bae548..c4580176 100644 --- a/src/router/run.rs +++ b/src/router/run.rs @@ -16,7 +16,7 @@ use crate::serve; /// Main loop base #[tracing::instrument(skip_all)] -pub(crate) async fn run(services: Arc) -> Result<()> { +pub(crate) async fn run(services: Arc) -> Result { let server = &services.server; debug!("Start"); @@ -70,7 +70,7 @@ pub(crate) async fn start(server: Arc) -> Result> { /// Async destructions #[tracing::instrument(skip_all)] -pub(crate) async fn stop(services: Arc) -> Result<()> { +pub(crate) async fn stop(services: Arc) -> Result { debug!("Shutting down..."); #[cfg(all(feature = "systemd", target_os = "linux"))] @@ -131,9 +131,9 @@ async fn handle_shutdown(server: Arc, tx: Sender<()>, handle: axum_serve async fn handle_services_poll( server: &Arc, - result: Result<()>, - listener: JoinHandle>, -) -> Result<()> { + result: Result, + listener: JoinHandle, +) -> Result { debug!("Service manager finished: {result:?}"); if server.running() { diff --git a/src/router/serve/plain.rs b/src/router/serve/plain.rs index 7e4a7e3f..1b604c53 100644 --- a/src/router/serve/plain.rs +++ b/src/router/serve/plain.rs @@ -13,7 +13,7 @@ pub(super) async fn serve( app: Router, handle: ServerHandle, addrs: Vec, -) -> Result<()> { +) -> Result { let app = app.into_make_service_with_connect_info::(); let mut join_set = JoinSet::new(); for addr in &addrs { diff --git a/src/router/serve/unix.rs b/src/router/serve/unix.rs index 769ea555..ed5efba5 100644 --- a/src/router/serve/unix.rs +++ b/src/router/serve/unix.rs @@ -38,7 +38,7 @@ pub(super) async fn serve( server: &Arc, app: Router, mut shutdown: broadcast::Receiver<()>, -) -> Result<()> { +) -> Result { let mut tasks = JoinSet::<()>::new(); let executor = TokioExecutor::new(); let app = app.into_make_service_with_connect_info::(); diff --git a/src/service/account_data/mod.rs b/src/service/account_data/mod.rs index 7124aaf0..7c260f1c 100644 --- a/src/service/account_data/mod.rs +++ b/src/service/account_data/mod.rs @@ -58,7 +58,7 @@ pub async fn update( user_id: &UserId, event_type: RoomAccountDataEventType, data: &serde_json::Value, -) -> Result<()> { +) -> Result { if data.get("type").is_none() || data.get("content").is_none() { return Err!(Request(InvalidParam("Account data doesn't have all required fields."))); } diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 67218c8b..89888990 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -275,7 +275,7 @@ impl Service { .ok_or_else(|| err!(Request(NotFound("Admin user not joined to admin room")))) } - async fn handle_response(&self, content: RoomMessageEventContent) -> Result<()> { + async fn handle_response(&self, content: RoomMessageEventContent) -> Result { let Some(Relation::Reply { in_reply_to }) = content.relates_to.as_ref() else { return Ok(()); }; @@ -309,7 +309,7 @@ impl Service { content: RoomMessageEventContent, room_id: &RoomId, user_id: &UserId, - ) -> Result<()> { + ) -> Result { assert!(self.user_is_admin(user_id).await, "sender is not admin"); let state_lock = self.services.state.mutex.lock(room_id).await; @@ -334,7 +334,7 @@ impl Service { room_id: &RoomId, user_id: &UserId, state_lock: &RoomMutexGuard, - ) -> Result<()> { + ) -> Result { error!("Failed to build and append admin room response PDU: \"{e}\""); let content = RoomMessageEventContent::text_plain(format!( "Failed to build and append admin room PDU: \"{e}\"\n\nThe original admin command \ diff --git a/src/service/federation/execute.rs b/src/service/federation/execute.rs index aadf5fd4..005a0920 100644 --- a/src/service/federation/execute.rs +++ b/src/service/federation/execute.rs @@ -119,7 +119,7 @@ fn prepare(&self, dest: &ServerName, mut request: http::Request>) -> Res } #[implement(super::Service)] -fn validate_url(&self, url: &Url) -> Result<()> { +fn validate_url(&self, url: &Url) -> Result { if let Some(url_host) = url.host_str() { if let Ok(ip) = IPAddress::parse(url_host) { trace!("Checking request URL IP {ip:?}"); diff --git a/src/service/key_backups/mod.rs b/src/service/key_backups/mod.rs index fff98585..739376e6 100644 --- a/src/service/key_backups/mod.rs +++ b/src/service/key_backups/mod.rs @@ -163,7 +163,7 @@ pub async fn add_key( room_id: &RoomId, session_id: &str, key_data: &Raw, -) -> Result<()> { +) -> Result { let key = (user_id, version); if self .db diff --git a/src/service/manager.rs b/src/service/manager.rs index 7ac513a4..1476c248 100644 --- a/src/service/manager.rs +++ b/src/service/manager.rs @@ -13,14 +13,14 @@ use tuwunel_core::{ use crate::{Services, service, service::Service}; pub(crate) struct Manager { - manager: Mutex>>>, + manager: Mutex>>, workers: Mutex, server: Arc, service: Arc, } type Workers = JoinSet; -type WorkerResult = (Arc, Result<()>); +type WorkerResult = (Arc, Result); type WorkersLocked<'a> = MutexGuard<'a, Workers>; const RESTART_DELAY_MS: u64 = 2500; @@ -35,7 +35,7 @@ impl Manager { }) } - pub(super) async fn poll(&self) -> Result<()> { + pub(super) async fn poll(&self) -> Result { if let Some(manager) = &mut *self.manager.lock().await { trace!("Polling service manager..."); return manager.await?; @@ -44,7 +44,7 @@ impl Manager { Ok(()) } - pub(super) async fn start(self: Arc) -> Result<()> { + pub(super) async fn start(self: Arc) -> Result { let mut workers = self.workers.lock().await; debug!("Starting service manager..."); @@ -83,7 +83,7 @@ impl Manager { } } - async fn worker(&self) -> Result<()> { + async fn worker(&self) -> Result { loop { let mut workers = self.workers.lock().await; tokio::select! { @@ -99,7 +99,7 @@ impl Manager { Ok(()) } - async fn handle_abort(&self, _workers: &mut WorkersLocked<'_>, error: Error) -> Result<()> { + async fn handle_abort(&self, _workers: &mut WorkersLocked<'_>, error: Error) -> Result { // not supported until service can be associated with abort unimplemented!("unexpected worker task abort {error:?}"); } @@ -108,7 +108,7 @@ impl Manager { &self, workers: &mut WorkersLocked<'_>, result: WorkerResult, - ) -> Result<()> { + ) -> Result { let (service, result) = result; match result { | Ok(()) => self.handle_finished(workers, &service).await, @@ -120,7 +120,7 @@ impl Manager { &self, _workers: &mut WorkersLocked<'_>, service: &Arc, - ) -> Result<()> { + ) -> Result { debug!("service {:?} worker finished", service.name()); Ok(()) } @@ -130,7 +130,7 @@ impl Manager { workers: &mut WorkersLocked<'_>, service: &Arc, error: Error, - ) -> Result<()> { + ) -> Result { let name = service.name(); error!("service {name:?} aborted: {error}"); @@ -155,7 +155,7 @@ impl Manager { &self, workers: &mut WorkersLocked<'_>, service: &Arc, - ) -> Result<()> { + ) -> Result { if !self.server.running() { return Err!( "Service {:?} worker not starting during server shutdown.", diff --git a/src/service/media/data.rs b/src/service/media/data.rs index f25a7444..db1346d3 100644 --- a/src/service/media/data.rs +++ b/src/service/media/data.rs @@ -165,7 +165,7 @@ impl Data { } #[inline] - pub(super) fn remove_url_preview(&self, url: &str) -> Result<()> { + pub(super) fn remove_url_preview(&self, url: &str) -> Result { self.url_previews.remove(url.as_bytes()); Ok(()) } @@ -175,7 +175,7 @@ impl Data { url: &str, data: &UrlPreviewData, timestamp: Duration, - ) -> Result<()> { + ) -> Result { let mut value = Vec::::new(); value.extend_from_slice(×tamp.as_secs().to_be_bytes()); value.push(0xFF); diff --git a/src/service/media/migrations.rs b/src/service/media/migrations.rs index dc6208fd..fc51e776 100644 --- a/src/service/media/migrations.rs +++ b/src/service/media/migrations.rs @@ -18,7 +18,7 @@ use crate::Services; /// Migrates a media directory from legacy base64 file names to sha2 file names. /// All errors are fatal. Upon success the database is keyed to not perform this /// again. -pub(crate) async fn migrate_sha256_media(services: &Services) -> Result<()> { +pub(crate) async fn migrate_sha256_media(services: &Services) -> Result { let db = &services.db; let config = &services.server.config; @@ -57,7 +57,7 @@ pub(crate) async fn migrate_sha256_media(services: &Services) -> Result<()> { /// - Going back and forth to non-sha256 legacy binaries (e.g. upstream). /// - Deletion of artifacts in the media directory which will then fall out of /// sync with the database. -pub(crate) async fn checkup_sha256_media(services: &Services) -> Result<()> { +pub(crate) async fn checkup_sha256_media(services: &Services) -> Result { use crate::media::encode_key; debug!("Checking integrity of media directory"); @@ -101,7 +101,7 @@ async fn handle_media_check( key: &[u8], new_path: &OsStr, old_path: &OsStr, -) -> Result<()> { +) -> Result { use crate::media::encode_key; let (mediaid_file, mediaid_user) = dbs; diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index 003781a4..91fba2d3 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -68,7 +68,7 @@ impl crate::Service for Service { })) } - async fn worker(self: Arc) -> Result<()> { + async fn worker(self: Arc) -> Result { self.create_media_dir().await?; Ok(()) @@ -86,7 +86,7 @@ impl Service { content_disposition: Option<&ContentDisposition>, content_type: Option<&str>, file: &[u8], - ) -> Result<()> { + ) -> Result { // Width, Height = 0 if it's not a thumbnail let key = self.db.create_file_metadata( mxc, @@ -104,7 +104,7 @@ impl Service { } /// Deletes a file in the database and from the media directory via an MXC - pub async fn delete(&self, mxc: &Mxc<'_>) -> Result<()> { + pub async fn delete(&self, mxc: &Mxc<'_>) -> Result { match self.db.search_mxc_metadata_prefix(mxc).await { | Ok(keys) => { for key in keys { @@ -341,12 +341,12 @@ impl Service { Ok(deletion_count) } - pub async fn create_media_dir(&self) -> Result<()> { + pub async fn create_media_dir(&self) -> Result { let dir = self.get_media_dir(); Ok(fs::create_dir_all(dir).await?) } - async fn remove_media_file(&self, key: &[u8]) -> Result<()> { + async fn remove_media_file(&self, key: &[u8]) -> Result { let path = self.get_media_file(key); let legacy = self.get_media_file_b64(key); debug!(?key, ?path, ?legacy, "Removing media file"); diff --git a/src/service/media/preview.rs b/src/service/media/preview.rs index f5921ec1..0253eac0 100644 --- a/src/service/media/preview.rs +++ b/src/service/media/preview.rs @@ -49,13 +49,13 @@ pub struct UrlPreviewData { } #[implement(Service)] -pub async fn remove_url_preview(&self, url: &str) -> Result<()> { +pub async fn remove_url_preview(&self, url: &str) -> Result { // TODO: also remove the downloaded image self.db.remove_url_preview(url) } #[implement(Service)] -pub async fn set_url_preview(&self, url: &str, data: &UrlPreviewData) -> Result<()> { +pub async fn set_url_preview(&self, url: &str, data: &UrlPreviewData) -> Result { let now = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .expect("valid system time"); diff --git a/src/service/media/remote.rs b/src/service/media/remote.rs index 56891942..4d7cba32 100644 --- a/src/service/media/remote.rs +++ b/src/service/media/remote.rs @@ -439,7 +439,7 @@ pub async fn fetch_remote_content_legacy( } #[implement(super::Service)] -fn check_fetch_authorized(&self, mxc: &Mxc<'_>) -> Result<()> { +fn check_fetch_authorized(&self, mxc: &Mxc<'_>) -> Result { if self .services .server @@ -463,7 +463,7 @@ fn check_fetch_authorized(&self, mxc: &Mxc<'_>) -> Result<()> { } #[implement(super::Service)] -fn check_legacy_freeze(&self) -> Result<()> { +fn check_legacy_freeze(&self) -> Result { self.services .server .config diff --git a/src/service/media/tests.rs b/src/service/media/tests.rs index 651e0ade..c44e9eea 100644 --- a/src/service/media/tests.rs +++ b/src/service/media/tests.rs @@ -44,7 +44,7 @@ async fn long_file_names_works() { Ok(key) } - fn delete_file_mxc(&self, _mxc: String) -> Result<()> { todo!() } + fn delete_file_mxc(&self, _mxc: String) -> Result { todo!() } fn search_mxc_metadata_prefix(&self, _mxc: String) -> Result>> { todo!() } @@ -59,14 +59,14 @@ async fn long_file_names_works() { todo!() } - fn remove_url_preview(&self, _url: &str) -> Result<()> { todo!() } + fn remove_url_preview(&self, _url: &str) -> Result { todo!() } fn set_url_preview( &self, _url: &str, _data: &UrlPreviewData, _timestamp: std::time::Duration, - ) -> Result<()> { + ) -> Result { todo!() } diff --git a/src/service/media/thumbnail.rs b/src/service/media/thumbnail.rs index 24a88d52..c485ee8a 100644 --- a/src/service/media/thumbnail.rs +++ b/src/service/media/thumbnail.rs @@ -35,7 +35,7 @@ impl super::Service { content_type: Option<&str>, dim: &Dim, file: &[u8], - ) -> Result<()> { + ) -> Result { let key = self.db .create_file_metadata(mxc, user, dim, content_disposition, content_type)?; diff --git a/src/service/migrations.rs b/src/service/migrations.rs index fe80dd67..8338f2d7 100644 --- a/src/service/migrations.rs +++ b/src/service/migrations.rs @@ -29,7 +29,7 @@ use crate::{Services, media}; /// equal or lesser version. These are expected to be backward-compatible. pub(crate) const DATABASE_VERSION: u64 = 17; -pub(crate) async fn migrations(services: &Services) -> Result<()> { +pub(crate) async fn migrations(services: &Services) -> Result { let users_count = services.users.count().await; // Matrix resource ownership is based on the server name; changing it @@ -52,7 +52,7 @@ pub(crate) async fn migrations(services: &Services) -> Result<()> { } } -async fn fresh(services: &Services) -> Result<()> { +async fn fresh(services: &Services) -> Result { let db = &services.db; services @@ -77,7 +77,7 @@ async fn fresh(services: &Services) -> Result<()> { } /// Apply any migrations -async fn migrate(services: &Services) -> Result<()> { +async fn migrate(services: &Services) -> Result { let db = &services.db; let config = &services.server.config; @@ -220,7 +220,7 @@ async fn migrate(services: &Services) -> Result<()> { Ok(()) } -async fn db_lt_12(services: &Services) -> Result<()> { +async fn db_lt_12(services: &Services) -> Result { for username in &services .users .list_local_users() @@ -306,7 +306,7 @@ async fn db_lt_12(services: &Services) -> Result<()> { Ok(()) } -async fn db_lt_13(services: &Services) -> Result<()> { +async fn db_lt_13(services: &Services) -> Result { for username in &services .users .list_local_users() @@ -353,7 +353,7 @@ async fn db_lt_13(services: &Services) -> Result<()> { Ok(()) } -async fn fix_bad_double_separator_in_state_cache(services: &Services) -> Result<()> { +async fn fix_bad_double_separator_in_state_cache(services: &Services) -> Result { warn!("Fixing bad double separator in state_cache roomuserid_joined"); let db = &services.db; @@ -397,7 +397,7 @@ async fn fix_bad_double_separator_in_state_cache(services: &Services) -> Result< Ok(()) } -async fn retroactively_fix_bad_data_from_roomuserid_joined(services: &Services) -> Result<()> { +async fn retroactively_fix_bad_data_from_roomuserid_joined(services: &Services) -> Result { warn!("Retroactively fixing bad data from broken roomuserid_joined"); let db = &services.db; diff --git a/src/service/presence/data.rs b/src/service/presence/data.rs index 9878192d..2cae1da8 100644 --- a/src/service/presence/data.rs +++ b/src/service/presence/data.rs @@ -58,7 +58,7 @@ impl Data { currently_active: Option, last_active_ago: Option, status_msg: Option, - ) -> Result<()> { + ) -> Result { let last_presence = self.get_presence(user_id).await; let state_changed = match last_presence { | Err(_) => true, diff --git a/src/service/presence/mod.rs b/src/service/presence/mod.rs index b929fbd1..0b958206 100644 --- a/src/service/presence/mod.rs +++ b/src/service/presence/mod.rs @@ -55,7 +55,7 @@ impl crate::Service for Service { })) } - async fn worker(self: Arc) -> Result<()> { + async fn worker(self: Arc) -> Result { let receiver = self.timer_channel.1.clone(); let mut presence_timers = FuturesUnordered::new(); @@ -99,7 +99,7 @@ impl Service { /// Pings the presence of the given user in the given room, setting the /// specified state. - pub async fn ping_presence(&self, user_id: &UserId, new_state: &PresenceState) -> Result<()> { + pub async fn ping_presence(&self, user_id: &UserId, new_state: &PresenceState) -> Result { const REFRESH_TIMEOUT: u64 = 60 * 1000; let last_presence = self.db.get_presence(user_id).await; @@ -140,7 +140,7 @@ impl Service { currently_active: Option, last_active_ago: Option, status_msg: Option, - ) -> Result<()> { + ) -> Result { let presence_state = match state.as_str() { | "" => &PresenceState::Offline, // default an empty string to 'offline' | &_ => state, @@ -257,7 +257,7 @@ impl Service { Ok(event) } - async fn process_presence_timer(&self, user_id: &OwnedUserId) -> Result<()> { + async fn process_presence_timer(&self, user_id: &OwnedUserId) -> Result { let mut presence_state = PresenceState::Offline; let mut last_active_ago = None; let mut status_msg = None; diff --git a/src/service/pusher/mod.rs b/src/service/pusher/mod.rs index 2d942efd..d7c33370 100644 --- a/src/service/pusher/mod.rs +++ b/src/service/pusher/mod.rs @@ -390,8 +390,7 @@ impl Service { pusher: &Pusher, tweaks: Vec, event: &Pdu, - ) -> Result - { + ) -> Result { // TODO: email match &pusher.kind { | PusherKind::Http(http) => { diff --git a/src/service/resolver/actual.rs b/src/service/resolver/actual.rs index b4cb4efe..c3ab9814 100644 --- a/src/service/resolver/actual.rs +++ b/src/service/resolver/actual.rs @@ -348,7 +348,7 @@ impl super::Service { Ok(None) } - fn handle_resolve_error(e: &ResolveError, host: &'_ str) -> Result<()> { + fn handle_resolve_error(e: &ResolveError, host: &'_ str) -> Result { use hickory_resolver::{ResolveErrorKind::Proto, proto::ProtoErrorKind}; match e.kind() { @@ -376,7 +376,7 @@ impl super::Service { } } - fn validate_dest(&self, dest: &ServerName) -> Result<()> { + fn validate_dest(&self, dest: &ServerName) -> Result { if dest == self.services.server.name && !self.services.server.config.federation_loopback { return Err!("Won't send federation request to ourselves"); } @@ -388,7 +388,7 @@ impl super::Service { Ok(()) } - fn validate_dest_ip_literal(&self, dest: &ServerName) -> Result<()> { + fn validate_dest_ip_literal(&self, dest: &ServerName) -> Result { trace!("Destination is an IP literal, checking against IP range denylist.",); debug_assert!( dest.is_ip_literal() || !IPAddress::is_valid(dest.host()), @@ -403,7 +403,7 @@ impl super::Service { Ok(()) } - pub(crate) fn validate_ip(&self, ip: &IPAddress) -> Result<()> { + pub(crate) fn validate_ip(&self, ip: &IPAddress) -> Result { if !self.services.client.valid_cidr_range(ip) { return Err!(BadServerResponse("Not allowed to send requests to this IP")); } diff --git a/src/service/rooms/alias/mod.rs b/src/service/rooms/alias/mod.rs index e37fe553..ddb4606a 100644 --- a/src/service/rooms/alias/mod.rs +++ b/src/service/rooms/alias/mod.rs @@ -64,12 +64,7 @@ impl crate::Service for Service { impl Service { #[tracing::instrument(skip(self))] - pub fn set_alias( - &self, - alias: &RoomAliasId, - room_id: &RoomId, - user_id: &UserId, - ) -> Result<()> { + pub fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId, user_id: &UserId) -> Result { if alias == self.services.globals.admin_alias && user_id != self.services.globals.server_user { @@ -96,7 +91,7 @@ impl Service { } #[tracing::instrument(skip(self))] - pub async fn remove_alias(&self, alias: &RoomAliasId, user_id: &UserId) -> Result<()> { + pub async fn remove_alias(&self, alias: &RoomAliasId, user_id: &UserId) -> Result { if !self.user_can_remove_alias(alias, user_id).await? { return Err!(Request(Forbidden("User is not permitted to remove this alias."))); } @@ -295,7 +290,7 @@ impl Service { &self, room_alias: &RoomAliasId, appservice_info: &Option, - ) -> Result<()> { + ) -> Result { if !self .services .globals diff --git a/src/service/rooms/timeline/backfill.rs b/src/service/rooms/timeline/backfill.rs index 5d8e5359..2e834ef0 100644 --- a/src/service/rooms/timeline/backfill.rs +++ b/src/service/rooms/timeline/backfill.rs @@ -24,7 +24,7 @@ use super::ExtractBody; #[implement(super::Service)] #[tracing::instrument(name = "backfill", level = "debug", skip(self))] -pub async fn backfill_if_required(&self, room_id: &RoomId, from: PduCount) -> Result<()> { +pub async fn backfill_if_required(&self, room_id: &RoomId, from: PduCount) -> Result { if self .services .state_cache @@ -143,7 +143,7 @@ pub async fn backfill_if_required(&self, room_id: &RoomId, from: PduCount) -> Re #[implement(super::Service)] #[tracing::instrument(skip(self, pdu), level = "debug")] -pub async fn backfill_pdu(&self, origin: &ServerName, pdu: Box) -> Result<()> { +pub async fn backfill_pdu(&self, origin: &ServerName, pdu: Box) -> Result { let (room_id, event_id, value) = self .services .event_handler diff --git a/src/service/rooms/typing/mod.rs b/src/service/rooms/typing/mod.rs index 250aa0bb..25e399d9 100644 --- a/src/service/rooms/typing/mod.rs +++ b/src/service/rooms/typing/mod.rs @@ -51,12 +51,7 @@ impl crate::Service for Service { impl Service { /// Sets a user as typing until the timeout timestamp is reached or /// roomtyping_remove is called. - pub async fn typing_add( - &self, - user_id: &UserId, - room_id: &RoomId, - timeout: u64, - ) -> Result<()> { + pub async fn typing_add(&self, user_id: &UserId, room_id: &RoomId, timeout: u64) -> Result { debug_info!("typing started {user_id:?} in {room_id:?} timeout:{timeout:?}"); // update clients self.typing @@ -89,7 +84,7 @@ impl Service { } /// Removes a user from typing before the timeout is reached. - pub async fn typing_remove(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> { + pub async fn typing_remove(&self, user_id: &UserId, room_id: &RoomId) -> Result { debug_info!("typing stopped {user_id:?} in {room_id:?}"); // update clients self.typing @@ -131,7 +126,7 @@ impl Service { } /// Makes sure that typing events with old timestamps get removed. - async fn typings_maintain(&self, room_id: &RoomId) -> Result<()> { + async fn typings_maintain(&self, room_id: &RoomId) -> Result { let current_timestamp = utils::millis_since_unix_epoch(); let mut removable = Vec::new(); @@ -226,12 +221,7 @@ impl Service { }) } - async fn federation_send( - &self, - room_id: &RoomId, - user_id: &UserId, - typing: bool, - ) -> Result<()> { + async fn federation_send(&self, room_id: &RoomId, user_id: &UserId, typing: bool) -> Result { debug_assert!( self.services.globals.user_is_local(user_id), "tried to broadcast typing status of remote user", diff --git a/src/service/sending/mod.rs b/src/service/sending/mod.rs index 8bb0f659..119289df 100644 --- a/src/service/sending/mod.rs +++ b/src/service/sending/mod.rs @@ -275,7 +275,7 @@ impl Service { } #[tracing::instrument(skip(self, room_id), level = "debug")] - pub async fn flush_room(&self, room_id: &RoomId) -> Result<()> { + pub async fn flush_room(&self, room_id: &RoomId) -> Result { let servers = self .services .state_cache @@ -286,7 +286,7 @@ impl Service { } #[tracing::instrument(skip(self, servers), level = "debug")] - pub async fn flush_servers<'a, S>(&self, servers: S) -> Result<()> + pub async fn flush_servers<'a, S>(&self, servers: S) -> Result where S: Stream + Send + 'a, { diff --git a/src/service/service.rs b/src/service/service.rs index f1ab6f4e..a1489a28 100644 --- a/src/service/service.rs +++ b/src/service/service.rs @@ -26,7 +26,7 @@ pub(crate) trait Service: Any + Send + Sync { /// Implement the service's worker loop. The service manager spawns a /// task and calls this function after all services have been built. - async fn worker(self: Arc) -> Result<()> { Ok(()) } + async fn worker(self: Arc) -> Result { Ok(()) } /// Interrupt the service. This is sent to initiate a graceful shutdown. /// The service worker should return from its work loop. diff --git a/src/service/services.rs b/src/service/services.rs index 37229c11..69eb1ac7 100644 --- a/src/service/services.rs +++ b/src/service/services.rs @@ -161,7 +161,7 @@ impl Services { debug_info!("Services shutdown complete."); } - pub async fn poll(&self) -> Result<()> { + pub async fn poll(&self) -> Result { if let Some(manager) = self.manager.lock().await.as_ref() { return manager.poll().await; }