From 43c4dfc5dfeb282f71bf832c149e42b1392662ac Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 15:06:11 -0400 Subject: [PATCH 0001/2291] set content-disposition to attachment instead of inline Signed-off-by: strawberry --- src/api/client_server/media.rs | 13 +++++++------ src/service/media/mod.rs | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index 1ba1c6be..b2355138 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -130,7 +130,7 @@ pub(crate) async fn create_content_route( mxc.clone(), body.filename .as_ref() - .map(|filename| "inline; filename=".to_owned() + filename) + .map(|filename| format!("attachment; filename={filename}")) .as_deref(), body.content_type.as_deref(), &body.file, @@ -173,15 +173,16 @@ pub(crate) async fn get_content_route(body: Ruma) -> R let mxc = format!("mxc://{}/{}", body.server_name, body.media_id); if let Some(FileMeta { - content_disposition, content_type, file, + .. }) = services().media.get(mxc.clone()).await? { + // TODO: safely sanitise filename to be included in the content-disposition Ok(get_content::v3::Response { file, content_type, - content_disposition, + content_disposition: Some("attachment".to_owned()), cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), }) @@ -243,7 +244,7 @@ pub(crate) async fn get_content_as_filename_route( Ok(get_content_as_filename::v3::Response { file, content_type, - content_disposition: Some(format!("inline; filename={}", body.filename)), + content_disposition: Some("attachment".to_owned()), cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), }) @@ -258,7 +259,7 @@ pub(crate) async fn get_content_as_filename_route( .await { Ok(remote_content_response) => Ok(get_content_as_filename::v3::Response { - content_disposition: Some(format!("inline: filename={}", body.filename)), + content_disposition: Some("attachment".to_owned()), content_type: remote_content_response.content_type, file: remote_content_response.file, cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), @@ -434,7 +435,7 @@ async fn get_remote_content( .create( None, mxc.to_owned(), - content_response.content_disposition.as_deref(), + Some("attachment"), content_response.content_type.as_deref(), &content_response.file, ) diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index e87889d3..4b52ff9c 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -16,6 +16,7 @@ use crate::{services, utils, Error, Result}; #[derive(Debug)] pub(crate) struct FileMeta { + #[allow(dead_code)] pub(crate) content_disposition: Option, pub(crate) content_type: Option, pub(crate) file: Vec, From e2fb588a8cd551dca6bc0691fd4cd352e092849b Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 15:39:59 -0400 Subject: [PATCH 0002/2291] sent attachment content-disposition on thumbnails too Signed-off-by: strawberry --- Cargo.lock | 24 ++++++++++++------------ src/api/client_server/media.rs | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f95b6ce..1dc3d916 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2698,7 +2698,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.9.4" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "assign", "js_int", @@ -2718,7 +2718,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "js_int", "ruma-common", @@ -2730,7 +2730,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.17.4" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "as_variant", "assign", @@ -2752,7 +2752,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.12.1" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "as_variant", "base64 0.22.1", @@ -2782,7 +2782,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.27.11" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "as_variant", "indexmap 2.2.6", @@ -2804,7 +2804,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.8.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "js_int", "ruma-common", @@ -2816,7 +2816,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.3" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "js_int", "thiserror", @@ -2825,7 +2825,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.8.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "js_int", "ruma-common", @@ -2835,7 +2835,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.12.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "once_cell", "proc-macro-crate", @@ -2850,7 +2850,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.8.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "js_int", "ruma-common", @@ -2862,7 +2862,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.14.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "base64 0.22.1", "ed25519-dalek", @@ -2878,7 +2878,7 @@ dependencies = [ [[package]] name = "ruma-state-res" version = "0.10.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#1c291e18efd0559c2dd76b27d555c86471cbb0fd" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "itertools", "js_int", diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index b2355138..ccbbfcd2 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -328,6 +328,7 @@ pub(crate) async fn get_content_thumbnail_route( content_type, cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), + content_disposition: Some("attachment".to_owned()), }) } else if !server_is_ours(&body.server_name) && body.allow_remote { if services() @@ -372,7 +373,13 @@ pub(crate) async fn get_content_thumbnail_route( ) .await?; - Ok(get_thumbnail_response) + Ok(get_content_thumbnail::v3::Response { + file: get_thumbnail_response.file, + content_type: get_thumbnail_response.content_type, + cross_origin_resource_policy: get_thumbnail_response.cross_origin_resource_policy, + cache_control: get_thumbnail_response.cache_control, + content_disposition: Some("attachment".to_owned()), + }) }, Err(e) => { debug_warn!("Fetching media `{}` failed: {:?}", mxc, e); @@ -441,7 +448,13 @@ async fn get_remote_content( ) .await?; - Ok(content_response) + Ok(get_content::v3::Response { + file: content_response.file, + content_type: content_response.content_type, + content_disposition: Some("attachment".to_owned()), + cross_origin_resource_policy: content_response.cross_origin_resource_policy, + cache_control: content_response.cache_control, + }) } async fn download_image(client: &reqwest::Client, url: &str) -> Result { From bfb827a418e8ddd7f6e435bdcfdbd35c12407692 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 15:48:43 -0400 Subject: [PATCH 0003/2291] send Cache-Control and CORS header for remote thumbnail responses Signed-off-by: strawberry --- src/api/client_server/media.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index ccbbfcd2..0de61233 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -376,8 +376,8 @@ pub(crate) async fn get_content_thumbnail_route( Ok(get_content_thumbnail::v3::Response { file: get_thumbnail_response.file, content_type: get_thumbnail_response.content_type, - cross_origin_resource_policy: get_thumbnail_response.cross_origin_resource_policy, - cache_control: get_thumbnail_response.cache_control, + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), + cache_control: Some(CACHE_CONTROL_IMMUTABLE.to_owned()), content_disposition: Some("attachment".to_owned()), }) }, @@ -452,8 +452,8 @@ async fn get_remote_content( file: content_response.file, content_type: content_response.content_type, content_disposition: Some("attachment".to_owned()), - cross_origin_resource_policy: content_response.cross_origin_resource_policy, - cache_control: content_response.cache_control, + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), + cache_control: Some(CACHE_CONTROL_IMMUTABLE.to_owned()), }) } From cb70d51e2b8616004eccfa1072b3ebc16a82859d Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 16:52:08 -0400 Subject: [PATCH 0004/2291] bump conduwuit version to 0.3.2 Signed-off-by: strawberry --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1dc3d916..d91f30d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -568,7 +568,7 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "conduit" -version = "0.3.1" +version = "0.3.2" dependencies = [ "argon2", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 865c1ce1..a3b513d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ authors = [ homepage = "https://conduwuit.puppyirl.gay/" repository = "https://github.com/girlbossceo/conduwuit" readme = "README.md" -version = "0.3.1" +version = "0.3.2" edition = "2021" # See also `rust-toolchain.toml` From 706c1c993b203ab251db761b8ccda296c0810e7b Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 03:35:36 -0400 Subject: [PATCH 0005/2291] nix: don't run cargo test for crane buildpackage CI does this already Signed-off-by: strawberry --- nix/pkgs/main/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix index 3ede7ffd..cb173422 100644 --- a/nix/pkgs/main/default.nix +++ b/nix/pkgs/main/default.nix @@ -83,6 +83,9 @@ craneLib.buildPackage ( commonAttrs // { (features != []) "--features " + (builtins.concatStringsSep "," features); + # This is redundant with CI + cargoTestCommand = ""; + # This is redundant with CI doCheck = false; From 97e81885db4395405dfea5b3e93ff0dd803f93c8 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 10:53:11 -0400 Subject: [PATCH 0006/2291] use dep: syntax in cargo.toml features Signed-off-by: strawberry --- Cargo.toml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a3b513d8..144b3b4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -365,41 +365,41 @@ default = [ ] backend_sqlite = ["sqlite"] backend_rocksdb = ["rocksdb"] -rocksdb = ["rust-rocksdb"] +rocksdb = ["dep:rust-rocksdb"] jemalloc = [ - "tikv-jemalloc-sys", - "tikv-jemalloc-ctl", - "tikv-jemallocator", + "dep:tikv-jemalloc-sys", + "dep:tikv-jemalloc-ctl", + "dep:tikv-jemallocator", "rust-rocksdb/jemalloc", ] jemalloc_prof = ["tikv-jemalloc-sys/profiling"] -sqlite = ["rusqlite", "parking_lot", "thread_local"] -systemd = ["sd-notify"] -sentry_telemetry = ["sentry", "sentry-tracing", "sentry-tower"] +sqlite = ["dep:rusqlite", "dep:parking_lot", "dep:thread_local"] +systemd = ["dep:sd-notify"] +sentry_telemetry = ["dep:sentry", "dep:sentry-tracing", "dep:sentry-tower"] gzip_compression = ["tower-http/compression-gzip", "reqwest/gzip"] zstd_compression = ["tower-http/compression-zstd"] brotli_compression = ["tower-http/compression-br", "reqwest/brotli"] -sha256_media = ["sha2"] +sha256_media = ["dep:sha2"] io_uring = ["rust-rocksdb/io-uring"] -axum_dual_protocol = ["axum-server-dual-protocol"] +axum_dual_protocol = ["dep:axum-server-dual-protocol"] perf_measurements = [ - "opentelemetry", - "tracing-flame", - "tracing-opentelemetry", - "opentelemetry_sdk", - "opentelemetry-jaeger", + "dep:opentelemetry", + "dep:tracing-flame", + "dep:tracing-opentelemetry", + "dep:opentelemetry_sdk", + "dep:opentelemetry-jaeger", ] # enable the tokio_console server # incompatible with release_max_log_level -tokio_console = ["console-subscriber", "tokio/tracing"] +tokio_console = ["dep:console-subscriber", "tokio/tracing"] hot_reload = ["dep:hot-lib-reloader"] -hardened_malloc = ["hardened_malloc-rs"] +hardened_malloc = ["dep:hardened_malloc-rs"] # increases performance, reduces build times, and reduces binary size by not compiling or # genreating code for log level filters that users will generally not use (debug and trace) only in release builds From 3b2db9027acdb39b3d8a7158a8cb790ffd883a5f Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 10:53:39 -0400 Subject: [PATCH 0007/2291] envrc: allow loading env vars from `.env` if it exists from https://or.computer.surgery/charles/matrix/-/commit/ffd479d66fae5092073ff380d25fac3735d055bd This is primarily useful for replicating the environment from CI so that the `nix-build-and-cache` script is easier to invoke. Signed-off-by: strawberry --- .envrc | 2 ++ .gitignore | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.envrc b/.envrc index 403a9bdf..e080e228 100644 --- a/.envrc +++ b/.envrc @@ -3,3 +3,5 @@ use flake PATH_add bin + +dotenv_if_exists diff --git a/.gitignore b/.gitignore index aff8ab91..cf366522 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Local environment overrides +/.env + # CMake cmake-build-*/ From b66d2d44d0d2a2c76bb6da634b2e4ece5df094c1 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 10:59:36 -0400 Subject: [PATCH 0008/2291] chore: bump MSRV to 1.77.0 as 1.78.0 came out Signed-off-by: strawberry --- Cargo.toml | 2 +- flake.nix | 2 +- rust-toolchain.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 144b3b4a..291a241a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ version = "0.3.2" edition = "2021" # See also `rust-toolchain.toml` -rust-version = "1.76.0" +rust-version = "1.77.0" [dependencies] console-subscriber = { version = "0.2", optional = true } diff --git a/flake.nix b/flake.nix index 69b29f2e..980153c9 100644 --- a/flake.nix +++ b/flake.nix @@ -21,7 +21,7 @@ file = ./rust-toolchain.toml; # See also `rust-toolchain.toml` - sha256 = "sha256-e4mlaJehWBymYxJGgnbuCObVlqMlQSilZ8FljG9zPHY="; + sha256 = "sha256-+syqAd2kX8KVa8/U2gz3blIQTTsYYt3U63xBWaGOSc8"; }; scope = pkgs: pkgs.lib.makeScope pkgs.newScope (self: { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index e2636774..0ed021bd 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -11,7 +11,7 @@ # If you're having trouble making the relevant changes, bug a maintainer. [toolchain] -channel = "1.76.0" +channel = "1.77.0" components = [ # For rust-analyzer "rust-src", From 05314ec46c11a626b43d51ea8b42ec29e59de473 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 12:05:01 -0400 Subject: [PATCH 0009/2291] nix: set hardcoded NIX_OUTPATH_USED_AS_RANDOM_SEED for bindgen Signed-off-by: strawberry --- nix/pkgs/main/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix index cb173422..039d95ed 100644 --- a/nix/pkgs/main/default.nix +++ b/nix/pkgs/main/default.nix @@ -89,6 +89,9 @@ craneLib.buildPackage ( commonAttrs // { # This is redundant with CI doCheck = false; + # https://crane.dev/faq/rebuilds-bindgen.html + NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa"; + env = buildPackageEnv; passthru = { From 9ee148596058d84bd599ba082809dc1d11fbf6d4 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 12:06:49 -0400 Subject: [PATCH 0010/2291] enable overflow-checks for dev/debug profile Signed-off-by: strawberry --- Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 291a241a..bb17f727 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -459,9 +459,11 @@ systemd-units = { unit-name = "conduwuit" } [profile.dev] +#debug = 0 lto = 'off' codegen-units = 512 incremental = true +overflow-checks = true #panic = "abort" # seems to speed up continuous debug compilations From 6266e0ab5e7db05cb1f5aa4a72b9874ff5ab57e5 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 13:26:04 -0400 Subject: [PATCH 0011/2291] rocksdb: enable async_io if using io_uring feature Signed-off-by: strawberry --- src/database/rocksdb/kvtree.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/database/rocksdb/kvtree.rs b/src/database/rocksdb/kvtree.rs index 4761624b..a6026baa 100644 --- a/src/database/rocksdb/kvtree.rs +++ b/src/database/rocksdb/kvtree.rs @@ -19,6 +19,7 @@ impl KvTree for RocksDbEngineTree<'_> { fn get(&self, key: &[u8]) -> Result>> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); + readoptions.set_async_io(cfg!(feature = "io_uring")); Ok(self.db.rocks.get_cf_opt(&self.cf(), key, &readoptions)?) } @@ -26,6 +27,7 @@ impl KvTree for RocksDbEngineTree<'_> { fn multi_get(&self, keys: &[&[u8]]) -> Result>>> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); + readoptions.set_async_io(cfg!(feature = "io_uring")); // Optimization can be `true` if key vector is pre-sorted **by the column // comparator**. @@ -113,6 +115,7 @@ impl KvTree for RocksDbEngineTree<'_> { fn iter<'a>(&'a self) -> Box, Vec)> + 'a> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); + readoptions.set_async_io(cfg!(feature = "io_uring")); Box::new( self.db @@ -126,6 +129,7 @@ impl KvTree for RocksDbEngineTree<'_> { fn iter_from<'a>(&'a self, from: &[u8], backwards: bool) -> Box, Vec)> + 'a> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); + readoptions.set_async_io(cfg!(feature = "io_uring")); Box::new( self.db @@ -150,6 +154,8 @@ impl KvTree for RocksDbEngineTree<'_> { fn increment(&self, key: &[u8]) -> Result> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); + readoptions.set_async_io(cfg!(feature = "io_uring")); + let writeoptions = rust_rocksdb::WriteOptions::default(); let old = self.db.rocks.get_cf_opt(&self.cf(), key, &readoptions)?; @@ -168,6 +174,8 @@ impl KvTree for RocksDbEngineTree<'_> { fn increment_batch(&self, iter: &mut dyn Iterator>) -> Result<()> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); + readoptions.set_async_io(cfg!(feature = "io_uring")); + let writeoptions = rust_rocksdb::WriteOptions::default(); let mut batch = WriteBatchWithTransaction::::default(); @@ -190,6 +198,7 @@ impl KvTree for RocksDbEngineTree<'_> { fn scan_prefix<'a>(&'a self, prefix: Vec) -> Box, Vec)> + 'a> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); + readoptions.set_async_io(cfg!(feature = "io_uring")); Box::new( self.db From a198f0481a375760359e01da6150df0d80f3b27a Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 15:11:06 -0400 Subject: [PATCH 0012/2291] nix: add liburing to devshell Signed-off-by: strawberry --- flake.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flake.nix b/flake.nix index 980153c9..18d1d85b 100644 --- a/flake.nix +++ b/flake.nix @@ -179,6 +179,10 @@ # Useful for editing the book locally mdbook ]) + ++ (if !pkgsHost.stdenv.isDarwin then [ + # Needed for building with io_uring + pkgsHost.liburing + ] else []) ++ scopeHost.main.nativeBuildInputs; }; From 11ec0dff4f47cb55ac5a656c05804020b2f05264 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 15:11:42 -0400 Subject: [PATCH 0013/2291] add PATCH to list of allowed HTTP methods in CORS (MSC4138) https://github.com/matrix-org/matrix-spec-proposals/pull/4138 we already had HEAD Signed-off-by: strawberry --- src/router/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/router/mod.rs b/src/router/mod.rs index b612876a..03e8be60 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -131,9 +131,10 @@ fn request_result_log(method: &Method, uri: &Uri, result: &axum::response::Respo } fn cors_layer(_server: &Server) -> CorsLayer { - const METHODS: [Method; 6] = [ + const METHODS: [Method; 7] = [ Method::GET, Method::HEAD, + Method::PATCH, Method::POST, Method::PUT, Method::DELETE, From 67569cb9c8f128b6725d582a1ad1f41cac087ce6 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 17:04:23 -0400 Subject: [PATCH 0014/2291] nix: switch to fork of rocksdb input https://github.com/girlbossceo/rocksdb/commit/db6df0b185774778457dabfcbd822cb81760cade Signed-off-by: strawberry --- flake.lock | 10 +++++----- flake.nix | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 388772eb..40b38ef7 100644 --- a/flake.lock +++ b/flake.lock @@ -238,15 +238,15 @@ "rocksdb": { "flake": false, "locked": { - "lastModified": 1713810944, - "narHash": "sha256-/Xf0bzNJPclH9IP80QNaABfhj4IAR5LycYET18VFCXc=", - "owner": "facebook", + "lastModified": 1714770052, + "narHash": "sha256-NCPYF2wYBsB9OHEkZSOYoPlxjC9BBMhJp8EM5M1o3Mc=", + "owner": "girlbossceo", "repo": "rocksdb", - "rev": "6f7cabeac80a3a6150be2c8a8369fcecb107bf43", + "rev": "db6df0b185774778457dabfcbd822cb81760cade", "type": "github" }, "original": { - "owner": "facebook", + "owner": "girlbossceo", "ref": "v9.1.1", "repo": "rocksdb", "type": "github" diff --git a/flake.nix b/flake.nix index 18d1d85b..553ca023 100644 --- a/flake.nix +++ b/flake.nix @@ -8,7 +8,8 @@ flake-utils.url = "github:numtide/flake-utils?ref=main"; nix-filter.url = "github:numtide/nix-filter?ref=main"; nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; - rocksdb = { url = "github:facebook/rocksdb?ref=v9.1.1"; flake = false; }; + # https://github.com/girlbossceo/rocksdb/commit/db6df0b185774778457dabfcbd822cb81760cade + rocksdb = { url = "github:girlbossceo/rocksdb?ref=v9.1.1"; flake = false; }; }; outputs = inputs: From ac4590952b31c081dc3f3b1ed767d768382aa5d0 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 18:07:52 -0400 Subject: [PATCH 0015/2291] set io_uring for rocksdb a default feature this was already enabled by default by rocksdb technically, but it wasn't building with it properly. Signed-off-by: strawberry --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index bb17f727..0b638a7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -362,6 +362,7 @@ default = [ "brotli_compression", "zstd_compression", "release_max_log_level", + "io_uring", ] backend_sqlite = ["sqlite"] backend_rocksdb = ["rocksdb"] From b5c0c30a5e8f37a0d3069ade6974e04fdc987f9d Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 3 May 2024 21:42:47 -0400 Subject: [PATCH 0016/2291] resolve half of the integer_arithmetic lints, couple misc changes Signed-off-by: strawberry --- Cargo.toml | 1 + src/api/client_server/account.rs | 4 +- src/api/client_server/directory.rs | 7 +++- src/api/client_server/keys.rs | 17 +++++--- src/api/client_server/membership.rs | 25 +++++++---- src/api/client_server/room.rs | 8 +++- src/api/client_server/search.rs | 6 +-- src/api/client_server/sync.rs | 41 +++++++++++-------- src/api/client_server/typing.rs | 24 +++++++++-- src/api/client_server/voip.rs | 4 +- src/api/server_server.rs | 19 ++++++--- src/database/key_value/account_data.rs | 2 +- src/database/key_value/globals.rs | 13 +++--- src/database/key_value/rooms/pdu_metadata.rs | 4 +- src/database/key_value/rooms/read_receipt.rs | 2 +- .../key_value/rooms/state_accessor.rs | 8 ++-- src/database/key_value/rooms/state_cache.rs | 4 +- src/database/key_value/rooms/threads.rs | 2 +- src/database/key_value/rooms/timeline.rs | 12 +++--- src/database/key_value/rooms/user.rs | 3 +- src/database/key_value/users.rs | 6 +-- src/database/migrations.rs | 4 +- src/database/mod.rs | 8 ++-- src/database/rocksdb/opts.rs | 14 ++++++- .../admin/appservice/appservice_command.rs | 2 +- src/service/admin/debug/debug_commands.rs | 6 +-- src/service/admin/media/media_commands.rs | 11 +++-- .../admin/room/room_directory_commands.rs | 2 +- src/service/admin/server/server_commands.rs | 4 +- src/service/admin/user/user_commands.rs | 9 +++- src/service/globals/client.rs | 4 +- src/service/media/mod.rs | 2 +- src/service/rooms/event_handler/mod.rs | 17 ++++---- src/service/sending/send.rs | 2 +- 34 files changed, 188 insertions(+), 109 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0b638a7c..eeac6db2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -625,6 +625,7 @@ manual_let_else = "warn" trivially_copy_pass_by_ref = "warn" wildcard_imports = "warn" checked_conversions = "warn" +#integer_arithmetic = "warn" # some sadness missing_errors_doc = "allow" diff --git a/src/api/client_server/account.rs b/src/api/client_server/account.rs index 68d31191..b5d92d15 100644 --- a/src/api/client_server/account.rs +++ b/src/api/client_server/account.rs @@ -1,3 +1,5 @@ +use std::fmt::Write as _; + use register::RegistrationKind; use ruma::{ api::client::{ @@ -238,7 +240,7 @@ pub(crate) async fn register_route(body: Ruma) -> Result< // If `new_user_displayname_suffix` is set, registration will push whatever // content is set to the user's display name with a space before it if !services().globals.new_user_displayname_suffix().is_empty() { - displayname.push_str(&(" ".to_owned() + services().globals.new_user_displayname_suffix())); + _ = write!(displayname, " {}", services().globals.config.new_user_displayname_suffix); } services() diff --git a/src/api/client_server/directory.rs b/src/api/client_server/directory.rs index c8f0a23a..37745749 100644 --- a/src/api/client_server/directory.rs +++ b/src/api/client_server/directory.rs @@ -380,7 +380,12 @@ pub(crate) async fn get_public_rooms_filtered_helper( let next_batch = if chunk.len() < limit as usize { None } else { - Some(format!("n{}", num_since + limit)) + Some(format!( + "n{}", + num_since + .checked_add(limit) + .expect("num_since and limit should not be that large") + )) }; Ok(get_public_rooms_filtered::v3::Response { diff --git a/src/api/client_server/keys.rs b/src/api/client_server/keys.rs index 00ab426b..efd78b2f 100644 --- a/src/api/client_server/keys.rs +++ b/src/api/client_server/keys.rs @@ -1,4 +1,5 @@ use std::{ + cmp, collections::{hash_map, BTreeMap, HashMap, HashSet}, time::{Duration, Instant}, }; @@ -338,7 +339,15 @@ pub(crate) async fn get_keys_helper bool>( hash_map::Entry::Vacant(e) => { e.insert((Instant::now(), 1)); }, - hash_map::Entry::Occupied(mut e) => *e.get_mut() = (Instant::now(), e.get().1 + 1), + hash_map::Entry::Occupied(mut e) => { + *e.get_mut() = ( + Instant::now(), + e.get() + .1 + .checked_add(1) + .expect("bad_query_ratelimiter attempt/try count should not ever get this high"), + ); + }, } }; @@ -353,10 +362,8 @@ pub(crate) async fn get_keys_helper bool>( .get(server) { // Exponential backoff - let mut min_elapsed_duration = Duration::from_secs(5 * 60) * (*tries) * (*tries); - if min_elapsed_duration > Duration::from_secs(60 * 60 * 24) { - min_elapsed_duration = Duration::from_secs(60 * 60 * 24); - } + const MAX_DURATION: Duration = Duration::from_secs(60 * 60 * 24); + let min_elapsed_duration = cmp::min(MAX_DURATION, Duration::from_secs(5 * 60) * (*tries) * (*tries)); if time.elapsed() < min_elapsed_duration { debug!("Backing off query from {:?}", server); diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 225a021e..cd9edd4c 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -1,4 +1,5 @@ use std::{ + cmp, collections::{hash_map::Entry, BTreeMap, HashMap, HashSet}, sync::Arc, time::{Duration, Instant}, @@ -1301,8 +1302,8 @@ async fn make_join_request( ) -> Result<(federation::membership::prepare_join_event::v1::Response, OwnedServerName)> { let mut make_join_response_and_server = Err(Error::BadServerResponse("No server available to assist in joining.")); - let mut make_join_counter = 0; - let mut incompatible_room_version_count = 0; + let mut make_join_counter: u16 = 0; + let mut incompatible_room_version_count: u8 = 0; for remote_server in servers { if server_is_ours(remote_server) { @@ -1322,7 +1323,7 @@ async fn make_join_request( .await; trace!("make_join response: {:?}", make_join_response); - make_join_counter += 1; + make_join_counter = make_join_counter.saturating_add(1); if let Err(ref e) = make_join_response { trace!("make_join ErrorKind string: {:?}", e.error_code().to_string()); @@ -1336,7 +1337,7 @@ async fn make_join_request( .to_string() .contains("M_UNSUPPORTED_ROOM_VERSION") { - incompatible_room_version_count += 1; + incompatible_room_version_count = incompatible_room_version_count.saturating_add(1); } if incompatible_room_version_count > 15 { @@ -1393,7 +1394,15 @@ async fn validate_and_add_event_id( Entry::Vacant(e) => { e.insert((Instant::now(), 1)); }, - Entry::Occupied(mut e) => *e.get_mut() = (Instant::now(), e.get().1 + 1), + Entry::Occupied(mut e) => { + *e.get_mut() = ( + Instant::now(), + e.get() + .1 + .checked_add(1) + .expect("bad_event_ratelimiter attempt/try count should not ever get this high"), + ); + }, } }; @@ -1405,10 +1414,8 @@ async fn validate_and_add_event_id( .get(&event_id) { // Exponential backoff - let mut min_elapsed_duration = Duration::from_secs(5 * 60) * (*tries) * (*tries); - if min_elapsed_duration > Duration::from_secs(60 * 60 * 24) { - min_elapsed_duration = Duration::from_secs(60 * 60 * 24); - } + const MAX_DURATION: Duration = Duration::from_secs(60 * 60 * 24); + let min_elapsed_duration = cmp::min(MAX_DURATION, Duration::from_secs(5 * 60) * (*tries) * (*tries)); if time.elapsed() < min_elapsed_duration { debug!("Backing off from {}", event_id); diff --git a/src/api/client_server/room.rs b/src/api/client_server/room.rs index 75a8c0ad..d027c4f4 100644 --- a/src/api/client_server/room.rs +++ b/src/api/client_server/room.rs @@ -801,7 +801,13 @@ pub(crate) async fn upgrade_room_route(body: Ruma) -> .map_err(|_| Error::bad_database("Invalid room event in database."))?; // Setting events_default and invite to the greater of 50 and users_default + 1 - let new_level = max(int!(50), power_levels_event_content.users_default + int!(1)); + let new_level = max( + int!(50), + power_levels_event_content + .users_default + .checked_add(int!(1)) + .expect("user power level should not be this high"), + ); power_levels_event_content.events_default = new_level; power_levels_event_content.invite = new_level; diff --git a/src/api/client_server/search.rs b/src/api/client_server/search.rs index 23072355..b80694e6 100644 --- a/src/api/client_server/search.rs +++ b/src/api/client_server/search.rs @@ -106,14 +106,14 @@ pub(crate) async fn search_events_route(body: Ruma) } } - let skip = match body.next_batch.as_ref().map(|s| s.parse()) { + let skip: usize = match body.next_batch.as_ref().map(|s| s.parse()) { Some(Ok(s)) => s, Some(Err(_)) => return Err(Error::BadRequest(ErrorKind::InvalidParam, "Invalid next_batch token.")), None => 0, // Default to the start }; let mut results = Vec::new(); - for _ in 0..skip + limit { + for _ in 0_usize..skip.saturating_add(limit) { if let Some(s) = searches .iter_mut() .map(|s| (s.peek().cloned(), s)) @@ -162,7 +162,7 @@ pub(crate) async fn search_events_route(body: Ruma) let next_batch = if results.len() < limit { None } else { - Some((skip + limit).to_string()) + Some((skip.checked_add(limit).unwrap()).to_string()) }; Ok(search_events::v3::Response::new(ResultCategories { diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 46f4fc83..c5afacc0 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -539,7 +539,7 @@ async fn handle_left_room( left_state_ids.insert(leave_shortstatekey, left_event_id); - let mut i = 0; + let mut i: u8 = 0; for (key, id) in left_state_ids { if full_state || since_state_ids.get(&key) != Some(&id) { let (event_type, state_key) = services().rooms.short.get_statekey_from_short(key)?; @@ -557,7 +557,7 @@ async fn handle_left_room( left_state_events.push(pdu.to_sync_state_event()); - i += 1; + i = i.saturating_add(1); if i % 100 == 0 { tokio::task::yield_now().await; } @@ -705,7 +705,11 @@ async fn load_joined_room( // Recalculate heroes (first 5 members) let mut heroes = Vec::new(); - if joined_member_count + invited_member_count <= 5 { + if joined_member_count + .checked_add(invited_member_count) + .expect("joined/invite member count should not be this high") + <= 5 + { // Go through all PDUs and for each member event, check if the user is still // joined or invited until we have 5 or we reach the end @@ -784,7 +788,7 @@ async fn load_joined_room( let mut state_events = Vec::new(); let mut lazy_loaded = HashSet::new(); - let mut i = 0; + let mut i: u8 = 0; for (shortstatekey, id) in current_state_ids { let (event_type, state_key) = services() .rooms @@ -798,7 +802,7 @@ async fn load_joined_room( }; state_events.push(pdu); - i += 1; + i = i.saturating_add(1); if i % 100 == 0 { tokio::task::yield_now().await; } @@ -819,7 +823,7 @@ async fn load_joined_room( } state_events.push(pdu); - i += 1; + i = i.saturating_add(1); if i % 100 == 0 { tokio::task::yield_now().await; } @@ -1416,10 +1420,14 @@ pub(crate) async fn sync_events_v4_route( .ranges .into_iter() .map(|mut r| { - r.0 = - r.0.clamp(uint!(0), UInt::from(all_joined_rooms.len() as u32 - 1)); - r.1 = - r.1.clamp(r.0, UInt::from(all_joined_rooms.len() as u32 - 1)); + r.0 = r.0.clamp( + uint!(0), + UInt::try_from(all_joined_rooms.len().saturating_sub(1)).unwrap_or(UInt::MAX), + ); + r.1 = r.1.clamp( + r.0, + UInt::try_from(all_joined_rooms.len().saturating_sub(1)).unwrap_or(UInt::MAX), + ); let room_ids = all_joined_rooms[(u64::from(r.0) as usize)..=(u64::from(r.1) as usize)].to_vec(); new_known_rooms.extend(room_ids.iter().cloned()); for room_id in &room_ids { @@ -1592,14 +1600,13 @@ pub(crate) async fn sync_events_v4_route( .collect::>(); let name = match heroes.len().cmp(&(1_usize)) { Ordering::Greater => { + let firsts = heroes[1..] + .iter() + .map(|h| h.0.clone()) + .collect::>() + .join(", "); let last = heroes[0].0.clone(); - Some( - heroes[1..] - .iter() - .map(|h| h.0.clone()) - .collect::>() - .join(", ") + " and " + &last, - ) + Some(format!("{firsts} and {last}")) }, Ordering::Equal => Some(heroes[0].0.clone()), Ordering::Less => None, diff --git a/src/api/client_server/typing.rs b/src/api/client_server/typing.rs index 677906c0..52c8b353 100644 --- a/src/api/client_server/typing.rs +++ b/src/api/client_server/typing.rs @@ -22,14 +22,30 @@ pub(crate) async fn create_typing_event_route( if let Typing::Yes(duration) = body.state { let duration = utils::clamp( - duration.as_millis() as u64, - services().globals.config.typing_client_timeout_min_s * 1000, - services().globals.config.typing_client_timeout_max_s * 1000, + duration.as_millis().try_into().unwrap_or(u64::MAX), + services() + .globals + .config + .typing_client_timeout_min_s + .checked_mul(1000) + .unwrap(), + services() + .globals + .config + .typing_client_timeout_max_s + .checked_mul(1000) + .unwrap(), ); services() .rooms .typing - .typing_add(sender_user, &body.room_id, utils::millis_since_unix_epoch() + duration) + .typing_add( + sender_user, + &body.room_id, + utils::millis_since_unix_epoch() + .checked_add(duration) + .expect("user typing timeout should not get this high"), + ) .await?; } else { services() diff --git a/src/api/client_server/voip.rs b/src/api/client_server/voip.rs index a3868824..c5ea96f9 100644 --- a/src/api/client_server/voip.rs +++ b/src/api/client_server/voip.rs @@ -21,7 +21,9 @@ pub(crate) async fn turn_server_route( let (username, password) = if !turn_secret.is_empty() { let expiry = SecondsSinceUnixEpoch::from_system_time( - SystemTime::now() + Duration::from_secs(services().globals.turn_ttl()), + SystemTime::now() + .checked_add(Duration::from_secs(services().globals.turn_ttl())) + .expect("TURN TTL should not get this high"), ) .expect("time is valid"); diff --git a/src/api/server_server.rs b/src/api/server_server.rs index 1d0cbd9d..8b3650e0 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -101,7 +101,9 @@ pub(crate) async fn get_server_keys_route() -> Result { old_verify_keys: BTreeMap::new(), signatures: BTreeMap::new(), valid_until_ts: MilliSecondsSinceUnixEpoch::from_system_time( - SystemTime::now() + Duration::from_secs(86400 * 7), + SystemTime::now() + .checked_add(Duration::from_secs(86400 * 7)) + .expect("valid_until_ts should not get this high"), ) .expect("time is valid"), }) @@ -398,8 +400,13 @@ pub(crate) async fn send_transaction_message_route( .is_joined(&typing.user_id, &typing.room_id)? { if typing.typing { - let timeout = utils::millis_since_unix_epoch() - + services().globals.config.typing_federation_timeout_s * 1000; + let timeout = utils::millis_since_unix_epoch().saturating_add( + services() + .globals + .config + .typing_federation_timeout_s + .saturating_mul(1000), + ); services() .rooms .typing @@ -662,7 +669,7 @@ pub(crate) async fn get_missing_events_route( } if body.earliest_events.contains(&queued_events[i]) { - i += 1; + i = i.saturating_add(1); continue; } @@ -671,7 +678,7 @@ pub(crate) async fn get_missing_events_route( &body.room_id, &queued_events[i], )? { - i += 1; + i = i.saturating_add(1); continue; } @@ -688,7 +695,7 @@ pub(crate) async fn get_missing_events_route( ); events.push(PduEvent::convert_to_outgoing_federation_event(pdu)); } - i += 1; + i = i.saturating_add(1); } Ok(get_missing_events::v1::Response { diff --git a/src/database/key_value/account_data.rs b/src/database/key_value/account_data.rs index 54b61742..d67f8881 100644 --- a/src/database/key_value/account_data.rs +++ b/src/database/key_value/account_data.rs @@ -105,7 +105,7 @@ impl service::account_data::Data for KeyValueDatabase { // Skip the data that's exactly at since, because we sent that last time let mut first_possible = prefix.clone(); - first_possible.extend_from_slice(&(since + 1).to_be_bytes()); + first_possible.extend_from_slice(&(since.saturating_add(1)).to_be_bytes()); for r in self .roomuserdataid_accountdata diff --git a/src/database/key_value/globals.rs b/src/database/key_value/globals.rs index c53ce9e8..4ed07eba 100644 --- a/src/database/key_value/globals.rs +++ b/src/database/key_value/globals.rs @@ -158,18 +158,15 @@ impl service::globals::Data for KeyValueDatabase { let max_appservice_in_room_cache = self.appservice_in_room_cache.read().unwrap().capacity(); let max_lasttimelinecount_cache = self.lasttimelinecount_cache.lock().unwrap().capacity(); - let mut response = format!( + format!( "\ auth_chain_cache: {auth_chain_cache} / {max_auth_chain_cache} our_real_users_cache: {our_real_users_cache} / {max_our_real_users_cache} appservice_in_room_cache: {appservice_in_room_cache} / {max_appservice_in_room_cache} -lasttimelinecount_cache: {lasttimelinecount_cache} / {max_lasttimelinecount_cache}\n\n" - ); - if let Ok(db_stats) = self.db.memory_usage() { - response += &db_stats; - } - - response +lasttimelinecount_cache: {lasttimelinecount_cache} / {max_lasttimelinecount_cache}\n\n +{}", + self.db.memory_usage().unwrap_or_default() + ) } fn clear_caches(&self, amount: u32) { diff --git a/src/database/key_value/rooms/pdu_metadata.rs b/src/database/key_value/rooms/pdu_metadata.rs index b5c81f62..7e69788d 100644 --- a/src/database/key_value/rooms/pdu_metadata.rs +++ b/src/database/key_value/rooms/pdu_metadata.rs @@ -23,10 +23,10 @@ impl service::rooms::pdu_metadata::Data for KeyValueDatabase { let mut current = prefix.clone(); let count_raw = match until { - PduCount::Normal(x) => x - 1, + PduCount::Normal(x) => x.saturating_sub(1), PduCount::Backfilled(x) => { current.extend_from_slice(&0_u64.to_be_bytes()); - u64::MAX - x - 1 + u64::MAX.saturating_sub(x).saturating_sub(1) }, }; current.extend_from_slice(&count_raw.to_be_bytes()); diff --git a/src/database/key_value/rooms/read_receipt.rs b/src/database/key_value/rooms/read_receipt.rs index 63fa2520..e3f01a75 100644 --- a/src/database/key_value/rooms/read_receipt.rs +++ b/src/database/key_value/rooms/read_receipt.rs @@ -48,7 +48,7 @@ impl service::rooms::read_receipt::Data for KeyValueDatabase { let prefix2 = prefix.clone(); let mut first_possible_edu = prefix.clone(); - first_possible_edu.extend_from_slice(&(since + 1).to_be_bytes()); // +1 so we don't send the event at since + first_possible_edu.extend_from_slice(&(since.saturating_add(1)).to_be_bytes()); // +1 so we don't send the event at since Box::new( self.readreceiptid_readreceipt diff --git a/src/database/key_value/rooms/state_accessor.rs b/src/database/key_value/rooms/state_accessor.rs index 1ef7c4b5..c039299d 100644 --- a/src/database/key_value/rooms/state_accessor.rs +++ b/src/database/key_value/rooms/state_accessor.rs @@ -17,7 +17,7 @@ impl service::rooms::state_accessor::Data for KeyValueDatabase { .expect("there is always one layer") .1; let mut result = HashMap::new(); - let mut i = 0; + let mut i: u8 = 0; for compressed in full_state.iter() { let parsed = services() .rooms @@ -25,7 +25,7 @@ impl service::rooms::state_accessor::Data for KeyValueDatabase { .parse_compressed_state_event(compressed)?; result.insert(parsed.0, parsed.1); - i += 1; + i = i.saturating_add(1); if i % 100 == 0 { tokio::task::yield_now().await; } @@ -44,7 +44,7 @@ impl service::rooms::state_accessor::Data for KeyValueDatabase { .1; let mut result = HashMap::new(); - let mut i = 0; + let mut i: u8 = 0; for compressed in full_state.iter() { let (_, eventid) = services() .rooms @@ -63,7 +63,7 @@ impl service::rooms::state_accessor::Data for KeyValueDatabase { ); } - i += 1; + i = i.saturating_add(1); if i % 100 == 0 { tokio::task::yield_now().await; } diff --git a/src/database/key_value/rooms/state_cache.rs b/src/database/key_value/rooms/state_cache.rs index 5c5df762..1ca29ebd 100644 --- a/src/database/key_value/rooms/state_cache.rs +++ b/src/database/key_value/rooms/state_cache.rs @@ -154,11 +154,11 @@ impl service::rooms::state_cache::Data for KeyValueDatabase { if user_is_local(&joined) && !services().users.is_deactivated(&joined).unwrap_or(true) { real_users.insert(joined); } - joinedcount += 1; + joinedcount = joinedcount.saturating_add(1); } for _invited in self.room_members_invited(room_id).filter_map(Result::ok) { - invitedcount += 1; + invitedcount = invitedcount.saturating_add(1); } self.roomid_joinedcount diff --git a/src/database/key_value/rooms/threads.rs b/src/database/key_value/rooms/threads.rs index 4cb2591b..fa14f0ed 100644 --- a/src/database/key_value/rooms/threads.rs +++ b/src/database/key_value/rooms/threads.rs @@ -19,7 +19,7 @@ impl service::rooms::threads::Data for KeyValueDatabase { .to_vec(); let mut current = prefix.clone(); - current.extend_from_slice(&(until - 1).to_be_bytes()); + current.extend_from_slice(&(until.saturating_sub(1)).to_be_bytes()); Ok(Box::new( self.threadid_userids diff --git a/src/database/key_value/rooms/timeline.rs b/src/database/key_value/rooms/timeline.rs index c1ffb236..104678f9 100644 --- a/src/database/key_value/rooms/timeline.rs +++ b/src/database/key_value/rooms/timeline.rs @@ -256,7 +256,7 @@ fn pdu_count(pdu_id: &[u8]) -> Result { utils::u64_from_bytes(&pdu_id[pdu_id.len() - 2 * size_of::()..pdu_id.len() - size_of::()]); if matches!(second_last_u64, Ok(0)) { - Ok(PduCount::Backfilled(u64::MAX - last_u64)) + Ok(PduCount::Backfilled(u64::MAX.saturating_sub(last_u64))) } else { Ok(PduCount::Normal(last_u64)) } @@ -275,22 +275,22 @@ fn count_to_id(room_id: &RoomId, count: PduCount, offset: u64, subtract: bool) - let count_raw = match count { PduCount::Normal(x) => { if subtract { - x - offset + x.saturating_sub(offset) } else { - x + offset + x.saturating_add(offset) } }, PduCount::Backfilled(x) => { pdu_id.extend_from_slice(&0_u64.to_be_bytes()); - let num = u64::MAX - x; + let num = u64::MAX.saturating_sub(x); if subtract { if num > 0 { - num - offset + num.saturating_sub(offset) } else { num } } else { - num + offset + num.saturating_add(offset) } }, }; diff --git a/src/database/key_value/rooms/user.rs b/src/database/key_value/rooms/user.rs index d773a577..cc031747 100644 --- a/src/database/key_value/rooms/user.rs +++ b/src/database/key_value/rooms/user.rs @@ -110,7 +110,8 @@ impl service::rooms::user::Data for KeyValueDatabase { .enumerate() .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 + .0 + .saturating_add(1); // +1 because the room id starts AFTER the separator let room_id = key[roomid_index..].to_vec(); diff --git a/src/database/key_value/users.rs b/src/database/key_value/users.rs index b83e456f..9b10f2a5 100644 --- a/src/database/key_value/users.rs +++ b/src/database/key_value/users.rs @@ -5,7 +5,7 @@ use ruma::{ encryption::{CrossSigningKey, DeviceKeys, OneTimeKey}, events::{AnyToDeviceEvent, StateEventType}, serde::Raw, - DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedDeviceKeyId, + uint, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedDeviceKeyId, OwnedMxcUri, OwnedUserId, UInt, UserId, }; use tracing::warn; @@ -414,7 +414,7 @@ impl service::users::Data for KeyValueDatabase { .algorithm(), ) }) { - *counts.entry(algorithm?).or_default() += UInt::from(1_u32); + *counts.entry(algorithm?).or_default() += uint!(1); } Ok(counts) @@ -561,7 +561,7 @@ impl service::users::Data for KeyValueDatabase { prefix.push(0xFF); let mut start = prefix.clone(); - start.extend_from_slice(&(from + 1).to_be_bytes()); + start.extend_from_slice(&(from.saturating_add(1)).to_be_bytes()); let to = to.unwrap_or(u64::MAX); diff --git a/src/database/migrations.rs b/src/database/migrations.rs index 94989185..915841f1 100644 --- a/src/database/migrations.rs +++ b/src/database/migrations.rs @@ -173,13 +173,13 @@ pub(crate) async fn migrations(db: &KeyValueDatabase, config: &Config) -> Result let mut current_sstatehash: Option = None; let mut current_room = None; let mut current_state = HashSet::new(); - let mut counter = 0; + let mut counter: u32 = 0; let mut handle_state = |current_sstatehash: u64, current_room: &RoomId, current_state: HashSet<_>, last_roomstates: &mut HashMap<_, _>| { - counter += 1; + counter = counter.saturating_add(1); let last_roomsstatehash = last_roomstates.get(current_room); let states_parents = last_roomsstatehash.map_or_else( diff --git a/src/database/mod.rs b/src/database/mod.rs index ffcfc2b7..b61142ea 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -401,18 +401,18 @@ impl KeyValueDatabase { let sqlite_exists = path.join("conduit.db").exists(); let rocksdb_exists = path.join("IDENTITY").exists(); - let mut count = 0; + let mut count: u8 = 0; if sqlite_exists { - count += 1; + count = count.saturating_add(1); } if rocksdb_exists { - count += 1; + count = count.saturating_add(1); } if count > 1 { - warn!("Multiple databases at database_path detected"); + error!("Multiple databases at database_path detected"); return Ok(()); } diff --git a/src/database/rocksdb/opts.rs b/src/database/rocksdb/opts.rs index 8e90bec6..78b6db95 100644 --- a/src/database/rocksdb/opts.rs +++ b/src/database/rocksdb/opts.rs @@ -145,7 +145,14 @@ pub(crate) fn cf_options(cfg: &Config, name: &str, mut opts: Options, cache: &mu cache_size(cfg, cfg.statekeyshort_cache_capacity, 1024), ), - "pduid_pdu" => set_table_with_new_cache(&mut opts, cfg, cache, name, cfg.pdu_cache_capacity as usize * 1536), + #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] + "pduid_pdu" => set_table_with_new_cache( + &mut opts, + cfg, + cache, + name, + (cfg.pdu_cache_capacity as usize).saturating_mul(1536), + ), "eventid_outlierpdu" => set_table_with_shared_cache(&mut opts, cfg, cache, name, "pduid_pdu"), @@ -309,7 +316,10 @@ fn set_table_with_shared_cache( fn cache_size(config: &Config, base_size: u32, entity_size: usize) -> usize { let ents = f64::from(base_size) * config.conduit_cache_capacity_modifier; - ents as usize * entity_size + #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] + (ents as usize) + .checked_mul(entity_size) + .expect("cache capacity size is too large") } fn table_options(_config: &Config) -> BlockBasedOptions { diff --git a/src/service/admin/appservice/appservice_command.rs b/src/service/admin/appservice/appservice_command.rs index 3a5fdaf7..4e99c78b 100644 --- a/src/service/admin/appservice/appservice_command.rs +++ b/src/service/admin/appservice/appservice_command.rs @@ -4,7 +4,7 @@ use crate::{service::admin::escape_html, services, Result}; pub(crate) async fn register(body: Vec<&str>) -> Result { if body.len() > 2 && body[0].trim().starts_with("```") && body.last().unwrap().trim() == "```" { - let appservice_config = body[1..body.len() - 1].join("\n"); + let appservice_config = body[1..body.len().checked_sub(1).unwrap()].join("\n"); let parsed_config = serde_yaml::from_str::(&appservice_config); match parsed_config { Ok(yaml) => match services().appservice.register_appservice(yaml).await { diff --git a/src/service/admin/debug/debug_commands.rs b/src/service/admin/debug/debug_commands.rs index c27dd38c..3ce7fb14 100644 --- a/src/service/admin/debug/debug_commands.rs +++ b/src/service/admin/debug/debug_commands.rs @@ -121,7 +121,7 @@ pub(crate) async fn get_remote_pdu_list( if body.len() > 2 && body[0].trim().starts_with("```") && body.last().unwrap().trim() == "```" { let list = body .clone() - .drain(1..body.len() - 1) + .drain(1..body.len().checked_sub(1).unwrap()) .filter_map(|pdu| EventId::parse(pdu).ok()) .collect::>(); @@ -381,7 +381,7 @@ pub(crate) async fn change_log_level( pub(crate) async fn sign_json(body: Vec<&str>) -> Result { if body.len() > 2 && body[0].trim().starts_with("```") && body.last().unwrap().trim() == "```" { - let string = body[1..body.len() - 1].join("\n"); + let string = body[1..body.len().checked_sub(1).unwrap()].join("\n"); match serde_json::from_str(&string) { Ok(mut value) => { ruma::signatures::sign_json( @@ -404,7 +404,7 @@ pub(crate) async fn sign_json(body: Vec<&str>) -> Result) -> Result { if body.len() > 2 && body[0].trim().starts_with("```") && body.last().unwrap().trim() == "```" { - let string = body[1..body.len() - 1].join("\n"); + let string = body[1..body.len().checked_sub(1).unwrap()].join("\n"); match serde_json::from_str(&string) { Ok(value) => { let pub_key_map = RwLock::new(BTreeMap::new()); diff --git a/src/service/admin/media/media_commands.rs b/src/service/admin/media/media_commands.rs index 19e539dd..cb74a4bb 100644 --- a/src/service/admin/media/media_commands.rs +++ b/src/service/admin/media/media_commands.rs @@ -139,14 +139,19 @@ pub(crate) async fn delete( pub(crate) async fn delete_list(body: Vec<&str>) -> Result { if body.len() > 2 && body[0].trim().starts_with("```") && body.last().unwrap().trim() == "```" { - let mxc_list = body.clone().drain(1..body.len() - 1).collect::>(); + let mxc_list = body + .clone() + .drain(1..body.len().checked_sub(1).unwrap()) + .collect::>(); - let mut mxc_deletion_count = 0; + let mut mxc_deletion_count: u32 = 0; for mxc in mxc_list { debug!("Deleting MXC {mxc} in bulk"); services().media.delete(mxc.to_owned()).await?; - mxc_deletion_count += 1; + mxc_deletion_count = mxc_deletion_count + .checked_add(1) + .expect("mxc_deletion_count should not get this high"); } return Ok(RoomMessageEventContent::text_plain(format!( diff --git a/src/service/admin/room/room_directory_commands.rs b/src/service/admin/room/room_directory_commands.rs index bfdc7a60..dd4f599d 100644 --- a/src/service/admin/room/room_directory_commands.rs +++ b/src/service/admin/room/room_directory_commands.rs @@ -39,7 +39,7 @@ pub(crate) async fn process(command: RoomDirectoryCommand, _body: Vec<&str>) -> let rooms = rooms .into_iter() - .skip(page.saturating_sub(1) * PAGE_SIZE) + .skip(page.checked_sub(1).unwrap().checked_mul(PAGE_SIZE).unwrap()) .take(PAGE_SIZE) .collect::>(); diff --git a/src/service/admin/server/server_commands.rs b/src/service/admin/server/server_commands.rs index fd82ab38..df82fd86 100644 --- a/src/service/admin/server/server_commands.rs +++ b/src/service/admin/server/server_commands.rs @@ -33,9 +33,9 @@ pub(crate) async fn memory_usage(_body: Vec<&str>) -> Result Result { let version = conduwuit_version(); + let user_agent = format!("Conduwuit/{version}"); + let mut builder = reqwest::Client::builder() .hickory_dns(true) .connect_timeout(Duration::from_secs(config.request_conn_timeout)) @@ -96,7 +98,7 @@ impl Client { .timeout(Duration::from_secs(config.request_total_timeout)) .pool_idle_timeout(Duration::from_secs(config.request_idle_timeout)) .pool_max_idle_per_host(config.request_idle_per_host.into()) - .user_agent("Conduwuit".to_owned() + "/" + &version) + .user_agent(user_agent) .redirect(redirect::Policy::limited(6)) .connection_verbose(true); diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index 4b52ff9c..ca81fa67 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -188,7 +188,7 @@ impl Service { Ok(duration) => { debug!("Parsed duration: {:?}", duration); debug!("System time now: {:?}", SystemTime::now()); - SystemTime::now() - duration + SystemTime::now().checked_sub(duration).unwrap() }, Err(e) => { error!("Failed to parse user-specified time duration: {}", e); diff --git a/src/service/rooms/event_handler/mod.rs b/src/service/rooms/event_handler/mod.rs index 60ac41be..1a965c0e 100644 --- a/src/service/rooms/event_handler/mod.rs +++ b/src/service/rooms/event_handler/mod.rs @@ -236,6 +236,7 @@ impl Service { const MAX_DURATION: Duration = Duration::from_secs(60 * 60 * 24); let min_duration = cmp::min(MAX_DURATION, Duration::from_secs(5 * 60) * (*tries) * (*tries)); let duration = time.elapsed(); + if duration < min_duration { debug!( duration = ?duration, @@ -1003,7 +1004,7 @@ impl Service { hash_map::Entry::Vacant(e) => { e.insert((Instant::now(), 1)); }, - hash_map::Entry::Occupied(mut e) => *e.get_mut() = (Instant::now(), e.get().1 + 1), + hash_map::Entry::Occupied(mut e) => *e.get_mut() = (Instant::now(), e.get().1.saturating_add(1)), } }; @@ -1034,10 +1035,9 @@ impl Service { .get(&*next_id) { // Exponential backoff - let mut min_elapsed_duration = Duration::from_secs(5 * 60) * (*tries) * (*tries); - if min_elapsed_duration > Duration::from_secs(60 * 60 * 24) { - min_elapsed_duration = Duration::from_secs(60 * 60 * 24); - } + const MAX_DURATION: Duration = Duration::from_secs(60 * 60 * 24); + let min_elapsed_duration = + cmp::min(MAX_DURATION, Duration::from_secs(5 * 60) * (*tries) * (*tries)); if time.elapsed() < min_elapsed_duration { info!("Backing off from {}", next_id); @@ -1143,10 +1143,9 @@ impl Service { .get(&**next_id) { // Exponential backoff - let mut min_elapsed_duration = Duration::from_secs(5 * 60) * (*tries) * (*tries); - if min_elapsed_duration > Duration::from_secs(60 * 60 * 24) { - min_elapsed_duration = Duration::from_secs(60 * 60 * 24); - } + const MAX_DURATION: Duration = Duration::from_secs(60 * 60 * 24); + let min_elapsed_duration = + cmp::min(MAX_DURATION, Duration::from_secs(5 * 60) * (*tries) * (*tries)); if time.elapsed() < min_elapsed_duration { debug!("Backing off from {}", next_id); diff --git a/src/service/sending/send.rs b/src/service/sending/send.rs index 41ff692e..84da476d 100644 --- a/src/service/sending/send.rs +++ b/src/service/sending/send.rs @@ -818,7 +818,7 @@ impl FedDest { fn into_uri_string(self) -> String { match self { Self::Literal(addr) => addr.to_string(), - Self::Named(host, port) => host + &port, + Self::Named(host, port) => format!("{host}{port}"), } } From f8e12559945cde5e15289539dee16d51bcea155c Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 4 May 2024 09:03:32 -0400 Subject: [PATCH 0017/2291] presence: set empty string status msg to None Signed-off-by: strawberry --- src/api/client_server/presence.rs | 13 ++++++++++++- src/database/key_value/presence.rs | 14 +++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/api/client_server/presence.rs b/src/api/client_server/presence.rs index 3c62c9d5..066de1cc 100644 --- a/src/api/client_server/presence.rs +++ b/src/api/client_server/presence.rs @@ -49,9 +49,20 @@ pub(crate) async fn get_presence_route(body: Ruma) -> } if let Some(presence) = presence_event { + let status_msg = if presence + .content + .status_msg + .as_ref() + .is_some_and(String::is_empty) + { + None + } else { + presence.content.status_msg + }; + Ok(get_presence::v3::Response { // TODO: Should ruma just use the presenceeventcontent type here? - status_msg: presence.content.status_msg, + status_msg, currently_active: presence.content.currently_active, last_active_ago: presence .content diff --git a/src/database/key_value/presence.rs b/src/database/key_value/presence.rs index c123a339..17068f90 100644 --- a/src/database/key_value/presence.rs +++ b/src/database/key_value/presence.rs @@ -1,8 +1,8 @@ use ruma::{events::presence::PresenceEvent, presence::PresenceState, OwnedUserId, UInt, UserId}; -use tracing::debug; use crate::{ database::KeyValueDatabase, + debug_info, service::{self, presence::Presence}, services, utils::{self, user_id_from_bytes}, @@ -50,13 +50,21 @@ impl service::presence::Data for KeyValueDatabase { // tighten for state flicker? if !state_changed && last_active_ts <= last_last_active_ts { - debug!( + debug_info!( "presence spam {:?} last_active_ts:{:?} <= {:?}", - user_id, last_active_ts, last_last_active_ts + user_id, + last_active_ts, + last_last_active_ts ); return Ok(()); } + let status_msg = if status_msg.as_ref().is_some_and(String::is_empty) { + None + } else { + status_msg + }; + let presence = Presence::new( presence_state.to_owned(), currently_active.unwrap_or(false), From 0ebb32349026a64907585fe7d216498f0d681739 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 4 May 2024 09:45:37 -0400 Subject: [PATCH 0018/2291] resolve almost all as_conversions lints may need further opinion from others on these Signed-off-by: strawberry --- Cargo.toml | 2 +- src/api/client_server/backup.rs | 90 +++++++++++++++---------- src/api/client_server/context.rs | 4 +- src/api/client_server/directory.rs | 17 +++-- src/api/client_server/message.rs | 10 +-- src/api/client_server/search.rs | 11 ++- src/api/client_server/space.rs | 16 +++-- src/api/client_server/threads.rs | 8 ++- src/api/client_server/user_directory.rs | 2 +- src/database/mod.rs | 1 + src/database/rocksdb/mod.rs | 5 ++ src/database/sqlite/mod.rs | 44 +++++++----- src/database/watchers.rs | 2 +- src/service/globals/resolver.rs | 1 + src/service/mod.rs | 1 + src/service/pusher/mod.rs | 7 +- src/service/rooms/pdu_metadata/mod.rs | 7 +- src/utils/mod.rs | 1 + 18 files changed, 144 insertions(+), 85 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eeac6db2..54cd8268 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -626,6 +626,7 @@ trivially_copy_pass_by_ref = "warn" wildcard_imports = "warn" checked_conversions = "warn" #integer_arithmetic = "warn" +#as_conversions = "warn" # some sadness missing_errors_doc = "allow" @@ -646,7 +647,6 @@ map_err_ignore = "allow" missing_docs_in_private_items = "allow" multiple_inherent_impl = "allow" error_impl_error = "allow" -as_conversions = "allow" string_add = "allow" string_slice = "allow" ref_patterns = "allow" diff --git a/src/api/client_server/backup.rs b/src/api/client_server/backup.rs index 4dcb5ce9..fb7e7f31 100644 --- a/src/api/client_server/backup.rs +++ b/src/api/client_server/backup.rs @@ -1,11 +1,14 @@ -use ruma::api::client::{ - backup::{ - add_backup_keys, add_backup_keys_for_room, add_backup_keys_for_session, create_backup_version, - delete_backup_keys, delete_backup_keys_for_room, delete_backup_keys_for_session, delete_backup_version, - get_backup_info, get_backup_keys, get_backup_keys_for_room, get_backup_keys_for_session, - get_latest_backup_info, update_backup_version, +use ruma::{ + api::client::{ + backup::{ + add_backup_keys, add_backup_keys_for_room, add_backup_keys_for_session, create_backup_version, + delete_backup_keys, delete_backup_keys_for_room, delete_backup_keys_for_session, delete_backup_version, + get_backup_info, get_backup_keys, get_backup_keys_for_room, get_backup_keys_for_session, + get_latest_backup_info, update_backup_version, + }, + error::ErrorKind, }, - error::ErrorKind, + UInt, }; use crate::{services, Error, Result, Ruma}; @@ -56,7 +59,8 @@ pub(crate) async fn get_latest_backup_info_route( Ok(get_latest_backup_info::v3::Response { algorithm, - count: (services().key_backups.count_keys(sender_user, &version)? as u32).into(), + count: (UInt::try_from(services().key_backups.count_keys(sender_user, &version)?) + .expect("user backup keys count should not be that high")), etag: services().key_backups.get_etag(sender_user, &version)?, version, }) @@ -76,10 +80,12 @@ pub(crate) async fn get_backup_info_route( Ok(get_backup_info::v3::Response { algorithm, - count: (services() - .key_backups - .count_keys(sender_user, &body.version)? as u32) - .into(), + count: (UInt::try_from( + services() + .key_backups + .count_keys(sender_user, &body.version)?, + ) + .expect("user backup keys count should not be that high")), etag: services() .key_backups .get_etag(sender_user, &body.version)?, @@ -139,10 +145,12 @@ pub(crate) async fn add_backup_keys_route( } Ok(add_backup_keys::v3::Response { - count: (services() - .key_backups - .count_keys(sender_user, &body.version)? as u32) - .into(), + count: (UInt::try_from( + services() + .key_backups + .count_keys(sender_user, &body.version)?, + ) + .expect("user backup keys count should not be that high")), etag: services() .key_backups .get_etag(sender_user, &body.version)?, @@ -181,10 +189,12 @@ pub(crate) async fn add_backup_keys_for_room_route( } Ok(add_backup_keys_for_room::v3::Response { - count: (services() - .key_backups - .count_keys(sender_user, &body.version)? as u32) - .into(), + count: (UInt::try_from( + services() + .key_backups + .count_keys(sender_user, &body.version)?, + ) + .expect("user backup keys count should not be that high")), etag: services() .key_backups .get_etag(sender_user, &body.version)?, @@ -221,10 +231,12 @@ pub(crate) async fn add_backup_keys_for_session_route( .add_key(sender_user, &body.version, &body.room_id, &body.session_id, &body.session_data)?; Ok(add_backup_keys_for_session::v3::Response { - count: (services() - .key_backups - .count_keys(sender_user, &body.version)? as u32) - .into(), + count: (UInt::try_from( + services() + .key_backups + .count_keys(sender_user, &body.version)?, + ) + .expect("user backup keys count should not be that high")), etag: services() .key_backups .get_etag(sender_user, &body.version)?, @@ -294,10 +306,12 @@ pub(crate) async fn delete_backup_keys_route( .delete_all_keys(sender_user, &body.version)?; Ok(delete_backup_keys::v3::Response { - count: (services() - .key_backups - .count_keys(sender_user, &body.version)? as u32) - .into(), + count: (UInt::try_from( + services() + .key_backups + .count_keys(sender_user, &body.version)?, + ) + .expect("user backup keys count should not be that high")), etag: services() .key_backups .get_etag(sender_user, &body.version)?, @@ -317,10 +331,12 @@ pub(crate) async fn delete_backup_keys_for_room_route( .delete_room_keys(sender_user, &body.version, &body.room_id)?; Ok(delete_backup_keys_for_room::v3::Response { - count: (services() - .key_backups - .count_keys(sender_user, &body.version)? as u32) - .into(), + count: (UInt::try_from( + services() + .key_backups + .count_keys(sender_user, &body.version)?, + ) + .expect("user backup keys count should not be that high")), etag: services() .key_backups .get_etag(sender_user, &body.version)?, @@ -340,10 +356,12 @@ pub(crate) async fn delete_backup_keys_for_session_route( .delete_room_key(sender_user, &body.version, &body.room_id, &body.session_id)?; Ok(delete_backup_keys_for_session::v3::Response { - count: (services() - .key_backups - .count_keys(sender_user, &body.version)? as u32) - .into(), + count: (UInt::try_from( + services() + .key_backups + .count_keys(sender_user, &body.version)?, + ) + .expect("user backup keys count should not be that high")), etag: services() .key_backups .get_etag(sender_user, &body.version)?, diff --git a/src/api/client_server/context.rs b/src/api/client_server/context.rs index 2291e586..23a89f6c 100644 --- a/src/api/client_server/context.rs +++ b/src/api/client_server/context.rs @@ -63,8 +63,8 @@ pub(crate) async fn get_context_route(body: Ruma) -> R lazy_loaded.insert(base_event.sender.as_str().to_owned()); } - // Use limit with maximum 100 - let limit = u64::from(body.limit).min(100) as usize; + // Use limit or else 10, with maximum 100 + let limit = usize::try_from(body.limit).unwrap_or(10).min(100); let base_event = base_event.to_room_event(); diff --git a/src/api/client_server/directory.rs b/src/api/client_server/directory.rs index 37745749..094e007a 100644 --- a/src/api/client_server/directory.rs +++ b/src/api/client_server/directory.rs @@ -20,7 +20,7 @@ use ruma::{ }, StateEventType, }, - ServerName, UInt, + uint, ServerName, UInt, }; use tracing::{error, info, warn}; @@ -198,8 +198,9 @@ pub(crate) async fn get_public_rooms_filtered_helper( }); } + // Use limit or else 10, with maximum 100 let limit = limit.map_or(10, u64::from); - let mut num_since = 0_u64; + let mut num_since: u64 = 0; if let Some(s) = &since { let mut characters = s.chars(); @@ -363,12 +364,16 @@ pub(crate) async fn get_public_rooms_filtered_helper( all_rooms.sort_by(|l, r| r.num_joined_members.cmp(&l.num_joined_members)); - let total_room_count_estimate = (all_rooms.len() as u32).into(); + let total_room_count_estimate = UInt::try_from(all_rooms.len()).unwrap_or_else(|_| uint!(0)); let chunk: Vec<_> = all_rooms .into_iter() - .skip(num_since as usize) - .take(limit as usize) + .skip( + num_since + .try_into() + .expect("num_since should not be this high"), + ) + .take(limit.try_into().expect("limit should not be this high")) .collect(); let prev_batch = if num_since == 0 { @@ -377,7 +382,7 @@ pub(crate) async fn get_public_rooms_filtered_helper( Some(format!("p{num_since}")) }; - let next_batch = if chunk.len() < limit as usize { + let next_batch = if chunk.len() < limit.try_into().unwrap() { None } else { Some(format!( diff --git a/src/api/client_server/message.rs b/src/api/client_server/message.rs index 3a30ed15..0aa7792d 100644 --- a/src/api/client_server/message.rs +++ b/src/api/client_server/message.rs @@ -144,7 +144,7 @@ pub(crate) async fn get_message_events_route( .lazy_load_confirm_delivery(sender_user, sender_device, &body.room_id, from) .await?; - let limit = u64::from(body.limit).min(100) as usize; + let limit = usize::try_from(body.limit).unwrap_or(10).min(100); let next_token; @@ -159,8 +159,9 @@ pub(crate) async fn get_message_events_route( .timeline .pdus_after(sender_user, &body.room_id, from)? .filter_map(Result::ok) // Filter out buggy events - .filter(|(_, pdu)| contains_url_filter(pdu, &body.filter)) - .filter(|(_, pdu)| visibility_filter(pdu, sender_user, &body.room_id)) + .filter(|(_, pdu)| { contains_url_filter(pdu, &body.filter) && visibility_filter(pdu, sender_user, &body.room_id) + + }) .take_while(|&(k, _)| Some(k) != to) // Stop at `to` .take(limit) .collect(); @@ -205,8 +206,7 @@ pub(crate) async fn get_message_events_route( .timeline .pdus_until(sender_user, &body.room_id, from)? .filter_map(Result::ok) // Filter out buggy events - .filter(|(_, pdu)| contains_url_filter(pdu, &body.filter)) - .filter(|(_, pdu)| visibility_filter(pdu, sender_user, &body.room_id)) + .filter(|(_, pdu)| {contains_url_filter(pdu, &body.filter) && visibility_filter(pdu, sender_user, &body.room_id)}) .take_while(|&(k, _)| Some(k) != to) // Stop at `to` .take(limit) .collect(); diff --git a/src/api/client_server/search.rs b/src/api/client_server/search.rs index b80694e6..b09c6326 100644 --- a/src/api/client_server/search.rs +++ b/src/api/client_server/search.rs @@ -10,7 +10,7 @@ use ruma::{ }, events::AnyStateEvent, serde::Raw, - OwnedRoomId, + uint, OwnedRoomId, }; use tracing::debug; @@ -39,7 +39,12 @@ pub(crate) async fn search_events_route(body: Ruma) }); // Use limit or else 10, with maximum 100 - let limit = filter.limit.map_or(10, u64::from).min(100) as usize; + let limit: usize = filter + .limit + .unwrap_or_else(|| uint!(10)) + .try_into() + .unwrap_or(10) + .min(100); let mut room_states: BTreeMap>> = BTreeMap::new(); @@ -167,7 +172,7 @@ pub(crate) async fn search_events_route(body: Ruma) Ok(search_events::v3::Response::new(ResultCategories { room_events: ResultRoomEvents { - count: Some((results.len() as u32).into()), + count: Some(results.len().try_into().unwrap_or_else(|_| uint!(0))), groups: BTreeMap::new(), // TODO next_batch, results, diff --git a/src/api/client_server/space.rs b/src/api/client_server/space.rs index 69ccbc70..61431c01 100644 --- a/src/api/client_server/space.rs +++ b/src/api/client_server/space.rs @@ -2,7 +2,7 @@ use std::str::FromStr; use ruma::{ api::client::{error::ErrorKind, space::get_hierarchy}, - UInt, + uint, UInt, }; use crate::{service::rooms::spaces::PagnationToken, services, Error, Result, Ruma}; @@ -14,10 +14,12 @@ use crate::{service::rooms::spaces::PagnationToken, services, Error, Result, Rum pub(crate) async fn get_hierarchy_route(body: Ruma) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let limit = body + let limit: usize = body .limit - .unwrap_or_else(|| UInt::from(10_u32)) - .min(UInt::from(100_u32)); + .unwrap_or_else(|| uint!(10)) + .try_into() + .unwrap_or(10) + .min(100); let max_depth = body .max_depth @@ -45,9 +47,9 @@ pub(crate) async fn get_hierarchy_route(body: Ruma) .get_client_hierarchy( sender_user, &body.room_id, - u64::from(limit) as usize, - key.map_or(0, |token| u64::from(token.skip) as usize), - u64::from(max_depth) as usize, + limit, + key.map_or(0, |token| token.skip.try_into().unwrap_or(0)), + max_depth.try_into().unwrap_or(3), body.suggested_only, ) .await diff --git a/src/api/client_server/threads.rs b/src/api/client_server/threads.rs index 6b09f03c..2895573a 100644 --- a/src/api/client_server/threads.rs +++ b/src/api/client_server/threads.rs @@ -1,4 +1,7 @@ -use ruma::api::client::{error::ErrorKind, threads::get_threads}; +use ruma::{ + api::client::{error::ErrorKind, threads::get_threads}, + uint, +}; use crate::{services, Error, Result, Ruma}; @@ -9,7 +12,8 @@ pub(crate) async fn get_threads_route(body: Ruma) -> R // Use limit or else 10, with maximum 100 let limit = body .limit - .and_then(|l| l.try_into().ok()) + .unwrap_or_else(|| uint!(10)) + .try_into() .unwrap_or(10) .min(100); diff --git a/src/api/client_server/user_directory.rs b/src/api/client_server/user_directory.rs index c57f569e..4d9947f8 100644 --- a/src/api/client_server/user_directory.rs +++ b/src/api/client_server/user_directory.rs @@ -17,7 +17,7 @@ use crate::{services, Result, Ruma}; /// and don't share a room with the sender pub(crate) async fn search_users_route(body: Ruma) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let limit = u64::from(body.limit) as usize; + let limit = usize::try_from(body.limit).unwrap_or(10); // default limit is 10 let mut users = services().users.iter().filter_map(|user_id| { // Filter out buggy users (they should not exist, but you never know...) diff --git a/src/database/mod.rs b/src/database/mod.rs index b61142ea..825a21e8 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -340,6 +340,7 @@ impl KeyValueDatabase { roomid_inviteviaservers: builder.open_tree("roomid_inviteviaservers")?, + #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] auth_chain_cache: Mutex::new(LruCache::new( (f64::from(config.auth_chain_cache_capacity) * config.conduit_cache_capacity_modifier) as usize, )), diff --git a/src/database/rocksdb/mod.rs b/src/database/rocksdb/mod.rs index 1eec597a..4ef8f9a7 100644 --- a/src/database/rocksdb/mod.rs +++ b/src/database/rocksdb/mod.rs @@ -35,7 +35,11 @@ pub(crate) struct Engine { impl KeyValueDatabaseEngine for Arc { fn open(config: &Config) -> Result { let cache_capacity_bytes = config.db_cache_capacity_mb * 1024.0 * 1024.0; + + #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] let row_cache_capacity_bytes = (cache_capacity_bytes * 0.50) as usize; + + #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] let col_cache_capacity_bytes = (cache_capacity_bytes * 0.50) as usize; let mut col_cache = HashMap::new(); @@ -128,6 +132,7 @@ impl KeyValueDatabaseEngine for Arc { Ok(()) } + #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] fn memory_usage(&self) -> Result { let mut res = String::new(); let stats = rust_rocksdb::perf::get_memory_usage_stats(Some(&[&self.rocks]), Some(&[&self.row_cache]))?; diff --git a/src/database/sqlite/mod.rs b/src/database/sqlite/mod.rs index 60014ab0..c43d2fe0 100644 --- a/src/database/sqlite/mod.rs +++ b/src/database/sqlite/mod.rs @@ -21,7 +21,7 @@ thread_local! { struct PreparedStatementIterator<'a> { iterator: Box + 'a>, - _statement_ref: NonAliasingBox>, + _statement_ref: AliasableBox>, } impl Iterator for PreparedStatementIterator<'_> { @@ -30,16 +30,25 @@ impl Iterator for PreparedStatementIterator<'_> { fn next(&mut self) -> Option { self.iterator.next() } } -struct NonAliasingBox(*mut T); -impl Drop for NonAliasingBox { +struct AliasableBox(*mut T); +impl Drop for AliasableBox { fn drop(&mut self) { - // TODO: figure out why this is necessary, but also this is sqlite so dont think - // i care that much. i tried checking commit history but couldn't find out why - // this was done. - #[allow(clippy::undocumented_unsafe_blocks)] - unsafe { - _ = Box::from_raw(self.0); - }; + // SAFETY: This is cursed and relies on non-local reasoning. + // + // In order for this to be safe: + // + // * All aliased references to this value must have been dropped first, for + // example by coming after its referrers in struct fields, because struct + // fields are automatically dropped in order from top to bottom in the absence + // of an explicit Drop impl. Otherwise, the referrers may read into + // deallocated memory. + // * This type must not be copyable or cloneable. Otherwise, double-free can + // occur. + // + // These conditions are met, but again, note that changing safe code in + // this module can result in unsoundness if any of these constraints are + // violated. + unsafe { drop(Box::from_raw(self.0)) } } } @@ -93,8 +102,13 @@ impl KeyValueDatabaseEngine for Arc { // 2. divide by permanent connections + permanent iter connections + write // connection // 3. round down to nearest integer - let cache_size_per_thread: u32 = - ((config.db_cache_capacity_mb * 1024.0) / ((num_cpus::get().max(1) * 2) + 1) as f64) as u32; + #[allow( + clippy::as_conversions, + clippy::cast_possible_truncation, + clippy::cast_precision_loss, + clippy::cast_sign_loss + )] + let cache_size_per_thread = ((config.db_cache_capacity_mb * 1024.0) / ((num_cpus::get() as f64 * 2.0) + 1.0)) as u32; let writer = Mutex::new(Engine::prepare_conn(&path, cache_size_per_thread)?); @@ -161,7 +175,7 @@ impl SqliteTable { .unwrap(), )); - let statement_ref = NonAliasingBox(statement); + let statement_ref = AliasableBox(statement); //let name = self.name.clone(); @@ -250,7 +264,7 @@ impl KvTree for SqliteTable { .unwrap(), )); - let statement_ref = NonAliasingBox(statement); + let statement_ref = AliasableBox(statement); let iterator = Box::new( statement @@ -272,7 +286,7 @@ impl KvTree for SqliteTable { .unwrap(), )); - let statement_ref = NonAliasingBox(statement); + let statement_ref = AliasableBox(statement); let iterator = Box::new( statement diff --git a/src/database/watchers.rs b/src/database/watchers.rs index a4152a09..93c82b44 100644 --- a/src/database/watchers.rs +++ b/src/database/watchers.rs @@ -47,7 +47,7 @@ impl Watchers { let mut watchers = self.watchers.write().unwrap(); for prefix in triggered { if let Some(tx) = watchers.remove(prefix) { - _ = tx.0.send(()); + tx.0.send(()).expect("channel should still be open"); } } }; diff --git a/src/service/globals/resolver.rs b/src/service/globals/resolver.rs index 96ee7382..190c8579 100644 --- a/src/service/globals/resolver.rs +++ b/src/service/globals/resolver.rs @@ -30,6 +30,7 @@ pub(crate) struct Hooked { } impl Resolver { + #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] pub(crate) fn new(config: &Config) -> Self { let (sys_conf, mut opts) = hickory_resolver::system_conf::read_system_conf() .map_err(|e| { diff --git a/src/service/mod.rs b/src/service/mod.rs index 86fd103a..3fbc435a 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -40,6 +40,7 @@ pub(crate) struct Services<'a> { } impl Services<'_> { + #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] pub(crate) fn build< D: appservice::Data + pusher::Data diff --git a/src/service/pusher/mod.rs b/src/service/pusher/mod.rs index 9d2b53b7..3f7c5d80 100644 --- a/src/service/pusher/mod.rs +++ b/src/service/pusher/mod.rs @@ -188,13 +188,14 @@ impl Service { let ctx = PushConditionRoomCtx { room_id: room_id.to_owned(), - member_count: UInt::from( + member_count: UInt::try_from( services() .rooms .state_cache .room_joined_count(room_id)? - .unwrap_or(1) as u32, - ), + .unwrap_or(1), + ) + .unwrap_or_else(|_| uint!(0)), user_id: user.to_owned(), user_display_name: services() .users diff --git a/src/service/rooms/pdu_metadata/mod.rs b/src/service/rooms/pdu_metadata/mod.rs index d5afe247..0908c573 100644 --- a/src/service/rooms/pdu_metadata/mod.rs +++ b/src/service/rooms/pdu_metadata/mod.rs @@ -5,7 +5,7 @@ pub(crate) use data::Data; use ruma::{ api::{client::relations::get_relating_events, Direction}, events::{relation::RelationType, TimelineEventType}, - EventId, RoomId, UInt, UserId, + uint, EventId, RoomId, UInt, UserId, }; use serde::Deserialize; @@ -57,8 +57,9 @@ impl Service { // Use limit or else 10, with maximum 100 let limit = limit - .and_then(|u| u32::try_from(u).ok()) - .map_or(10_usize, |u| u as usize) + .unwrap_or_else(|| uint!(10)) + .try_into() + .unwrap_or(10) .min(100); let next_token; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 1184e181..ab472b28 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -21,6 +21,7 @@ use crate::{services, Error, Result}; pub(crate) fn clamp(val: T, min: T, max: T) -> T { cmp::min(cmp::max(val, min), max) } +#[allow(clippy::as_conversions)] pub(crate) fn millis_since_unix_epoch() -> u64 { SystemTime::now() .duration_since(UNIX_EPOCH) From 2f3194840cbe4b3ce9a50dbc011b078178c9febf Mon Sep 17 00:00:00 2001 From: Matt Moriarity Date: Fri, 26 Apr 2024 19:38:29 -0600 Subject: [PATCH 0019/2291] fix extra version when using flake-compat --- nix/pkgs/main/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix index 039d95ed..bdc97559 100644 --- a/nix/pkgs/main/default.nix +++ b/nix/pkgs/main/default.nix @@ -37,7 +37,7 @@ buildDepsOnlyEnv = }); buildPackageEnv = { - CONDUWUIT_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev; + CONDUWUIT_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev or ""; } // buildDepsOnlyEnv; commonAttrs = { From 29babebc4d0ce7c24f3946c0ecdc3453afb5f672 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 4 May 2024 10:35:56 -0400 Subject: [PATCH 0020/2291] adminroom: add count to list-joined-rooms user command Signed-off-by: strawberry --- src/service/admin/user/user_commands.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/service/admin/user/user_commands.rs b/src/service/admin/user/user_commands.rs index 8d389860..a8375064 100644 --- a/src/service/admin/user/user_commands.rs +++ b/src/service/admin/user/user_commands.rs @@ -239,7 +239,7 @@ pub(crate) async fn deactivate_all(body: Vec<&str>, leave_rooms: bool, force: bo } } - let mut deactivation_count = 0; + let mut deactivation_count: u16 = 0; let mut admins = Vec::new(); if !force { @@ -276,7 +276,7 @@ pub(crate) async fn deactivate_all(body: Vec<&str>, leave_rooms: bool, force: bo } if services().users.deactivate_account(user_id).is_ok() { - deactivation_count += 1; + deactivation_count = deactivation_count.saturating_add(1); } } @@ -316,7 +316,7 @@ pub(crate) async fn list_joined_rooms(_body: Vec<&str>, user_id: String) -> Resu }, }; - if user_id.server_name() != services().globals.server_name() { + if !user_is_local(&user_id) { return Ok(RoomMessageEventContent::text_plain("User does not belong to our server.")); } @@ -340,7 +340,8 @@ pub(crate) async fn list_joined_rooms(_body: Vec<&str>, user_id: String) -> Resu rooms.reverse(); let output_plain = format!( - "Rooms {user_id} Joined:\n{}", + "Rooms {user_id} Joined ({}):\n{}", + rooms.len(), rooms .iter() .map(|(id, members, name)| format!("{id}\tMembers: {members}\tName: {name}")) @@ -348,8 +349,9 @@ pub(crate) async fn list_joined_rooms(_body: Vec<&str>, user_id: String) -> Resu .join("\n") ); let output_html = format!( - "\n\t\t\n{}
Rooms {user_id} \ - Joined
idmembersname
", + "\n\t\t\n{}
Rooms {user_id} Joined \ + ({})
idmembersname
", + rooms.len(), rooms .iter() .fold(String::new(), |mut output, (id, members, name)| { From c6e6eb0af34e355dda411cfcd84104e8cf490288 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 4 May 2024 10:50:03 -0400 Subject: [PATCH 0021/2291] ignore empty CONDUWUIT_VERSION_EXTRA for server version Signed-off-by: strawberry --- src/utils/mod.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index ab472b28..11a2ed3b 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -197,9 +197,21 @@ impl fmt::Display for HtmlEscape<'_> { /// git commit hashes. pub(crate) fn conduwuit_version() -> String { match option_env!("CONDUWUIT_VERSION_EXTRA") { - Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra), + Some(extra) => { + if extra.is_empty() { + env!("CARGO_PKG_VERSION").to_owned() + } else { + format!("{} ({})", env!("CARGO_PKG_VERSION"), extra) + } + }, None => match option_env!("CONDUIT_VERSION_EXTRA") { - Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra), + Some(extra) => { + if extra.is_empty() { + env!("CARGO_PKG_VERSION").to_owned() + } else { + format!("{} ({})", env!("CARGO_PKG_VERSION"), extra) + } + }, None => env!("CARGO_PKG_VERSION").to_owned(), }, } From df203fa2449c72195453d71b8e31b6fb99ee5e46 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 4 May 2024 13:24:25 -0400 Subject: [PATCH 0022/2291] add a contributing guide Signed-off-by: strawberry --- CONTRIBUTING.md | 90 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 8 ---- docs/SUMMARY.md | 1 + docs/contributing.md | 1 + docs/development.md | 3 +- docs/introduction.md | 6 ++- 6 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 docs/contributing.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..1e3fe11e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,90 @@ +# Contributing guide + +This page is for about contributing to conduwuit. The [development](docs/development.md) page may be of interest for you as well. + +If you would like to work on an [issue][issues] that is not assigned, preferably ask in the Matrix room first at [#conduwuit:puppygock.gay][conduwuit-matrix], and comment on it. + +### Linting and Formatting + +It is mandatory all your changes satisfy the lints (clippy, rustc, rustdoc, etc) and your code is formatted via the **nightly** `cargo fmt`. A lot of the `rustfmt.toml` features depend on nightly toolchain. It would be ideal if they weren't nightly-exclusive features, but they currently still are. CI's rustfmt uses nightly. + +If you need to allow a lint, please make sure it's either obvious as to why (e.g. clippy saying redundant clone but it's actually required) or it has a comment saying why. Do not write inefficient code for the sake of satisfying lints. If a lint is wrong and provides a more inefficient solution or suggestion, allow the lint and mention that in a comment. + +### Running CI tests locally + +conduwuit's CI for tests, linting, formatting, audit, etc use [`engage`][engage]. engage can be installed from nixpkgs or `cargo install engage`. conduwuit's Nix flake devshell has the nixpkgs engage with `direnv`. Use `engage --help` for more usage details. + +To test, format, lint, etc that CI would do, install engage, allow the `.envrc` file using `direnv allow`, and run `engage`. + +All of the tasks are defined at the [engage.toml][engage.toml] file. You can view all of them neatly by running `engage list` + +If you would like to run only a specific engage task group, use `just`: +- `engage just ` +- Example: `engage just lints` + +If you would like to run a specific engage task in a specific group, use `just [TASK]`: `engage just lints cargo-fmt` + +The following binaries are used in [`engage.toml`][engage.toml]: + +- [`engage`][engage] +- `nix` +- [`direnv`][direnv] +- `rustc` +- `cargo` +- `cargo-fmt` +- `rustdoc` +- `cargo-clippy` +- [`cargo-audit`][cargo-audit] +- [`cargo-deb`][cargo-deb] +- [`lychee`][lychee] + +### Matrix tests + +CI runs [Complement][complement], but currently does not fail if results from the checked-in results differ with the new results. If your changes are done to fix Matrix tests, note that in your pull request. If more Complement tests start failing from your changes, please review the logs (they are uploaded as artifacts) and determine if they're intended or not. + +If you'd like to run Complement locally using Nix, see the [testing](docs/development/testing.md) page. + +[Sytest][sytest] support will come soon. + +### Writing documentation + +conduwuit's website uses [`mdbook`][mdbook] and deployed via CI using GitHub Pages in the [`documentation.yml`][documentation.yml] workflow file with Nix's mdbook in the devshell. All documentation is in the `docs/` directory at the top level. The compiled mdbook website is also uploaded as an artifact. + +To build the documentation using Nix, run: `bin/nix-build-and-cache just .#book` + +### Inclusivity and Diversity + +All **MUST** code and write with inclusivity and diversity in mind. See the [following page by Google on writing inclusive code and documentation](https://developers.google.com/style/inclusive-documentation). + +This **EXPLICITLY** forbids usage of terms like "blacklist"/"whitelist" and "master"/"slave", [forbids gender-specific words and phrases](https://developers.google.com/style/pronouns#gender-neutral-pronouns), forbids ableist language like "sanity-check", "cripple", or "insane", and forbids culture-specific language (e.g. US-only holidays or cultures). + +No exceptions are allowed. Dependencies that may use these terms are allowed but [do not replicate the name in your functions or variables](https://developers.google.com/style/inclusive-documentation#write-around). + +In addition to language, write and code with the user experience in mind. This is software that intends to be used by everyone, so make it easy and comfortable for everyone to use. 🏳️‍⚧️ + +### Variable, comment, function, etc standards + +Rust's default style and standards with regards to [function names, variable names, comments](https://rust-lang.github.io/api-guidelines/naming.html), etc applies here. + +### Creating pull requests + +Please try to keep contributions to the GitHub. While the mirrors of conduwuit allow for pull/merge requests, there is no guarantee I will see them in a timely manner. + +If you open a pull request on one of the mirrors, it is your responsibility to inform me about its existence. In the future I may try to solve this with more repo bots in the conduwuit Matrix room. There is no mailing list or email-patch support on the sr.ht mirror, but if you'd like to email me a git patch you can do so at `strawberry@puppygock.gay`. + +Direct all PRs/MRs to the `dev` branch. Pull requests to `main` should only be done by a maintainer, or if the change is necessary enough to go straight to the main branch (e.g. critical fix). + +By sending a pull request or patch, you are agreeing that your changes are allowed to be licenced under the Apache-2.0 licence and all of your conduct is in line with the Contributor's Covenant. + +[issues]: https://github.com/girlbossceo/conduwuit/issues +[conduwuit-matrix]: https://matrix.to/#/#conduwuit:puppygock.gay +[complement]: https://github.com/matrix-org/complement/ +[engage.toml]: https://github.com/girlbossceo/conduwuit/blob/main/engage.toml +[engage]: https://charles.page.computer.surgery/engage/ +[sytest]: https://github.com/matrix-org/sytest/ +[cargo-deb]: https://github.com/kornelski/cargo-deb +[lychee]: https://github.com/lycheeverse/lychee +[cargo-audit]: https://github.com/RustSec/rustsec/tree/main/cargo-audit +[direnv]: https://direnv.net/ +[mdbook]: https://rust-lang.github.io/mdBook/ +[documentation.yml]: https://github.com/girlbossceo/conduwuit/blob/main/.github/workflows/documentation.yml diff --git a/README.md b/README.md index 14fab289..e110cd80 100644 --- a/README.md +++ b/README.md @@ -37,14 +37,6 @@ from time to time. -#### How can I contribute? - -1. Look for an issue you would like to work on and make sure it's not assigned - to other users -2. Ask someone to assign the issue to you (comment on the issue or chat in - [#conduwuit:puppygock.gay](https://matrix.to/#/#conduwuit:puppygock.gay)) -3. Fork the repo and work on the issue. -4. Submit a PR (please keep contributions to the GitHub repo, main development is done here, not the GitLab repo which exists just as a mirror. If you are avoiding GitHub, feel free to join our Matrix chat to get your patch in.) #### Contact diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index da125422..937a5e2c 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -13,3 +13,4 @@ - [Appservices](appservices.md) - [Development](development.md) - [Testing](development/testing.md) + - [Contributing](contributing.md) diff --git a/docs/contributing.md b/docs/contributing.md new file mode 100644 index 00000000..81ddb505 --- /dev/null +++ b/docs/contributing.md @@ -0,0 +1 @@ +{{#include ../CONTRIBUTING.md}} diff --git a/docs/development.md b/docs/development.md index 49e055e1..18cd6c2e 100644 --- a/docs/development.md +++ b/docs/development.md @@ -1,7 +1,8 @@ # Development Information about developing the project. If you are only interested in using -it, you can safely ignore this section. +it, you can safely ignore this section. If you plan on contributing, see the +[contributor's guide](contributing.md). ## Debugging with `tokio-console` diff --git a/docs/introduction.md b/docs/introduction.md index 7b879aec..17d7e83f 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -6,7 +6,7 @@ #### What's different about your fork than upstream Conduit? -See [differences.md](differences.md) +See the [differences](differences.md) page #### How can I deploy my own? @@ -14,4 +14,8 @@ See [differences.md](differences.md) If you want to connect an Appservice to Conduwuit, take a look at the [appservices documentation](appservices.md). +#### How can I contribute? + +See the [contributor's guide](contributing.md) + {{#include ../README.md:footer}} From a6f4dc2b74cc776aeff2a92b8a5f2700eeab0e46 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 4 May 2024 14:58:49 -0400 Subject: [PATCH 0023/2291] engage(lychee): check all markdown files too, enable verbose mode Signed-off-by: strawberry --- engage.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engage.toml b/engage.toml index b19b89c5..315b3c55 100644 --- a/engage.toml +++ b/engage.toml @@ -131,7 +131,7 @@ cargo clippy \ [[task]] name = "lychee" group = "lints" -script = "lychee --offline docs" +script = "lychee --verbose --offline docs *.md" [[task]] name = "cargo" From bbdced9c90a911121ac310aef27b9478d5f7189d Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 4 May 2024 21:09:22 +0000 Subject: [PATCH 0024/2291] Fix appservice namespace check for room aliases Only normal users should be prevented from creating an alias within an exclusive namespace, not the appservice itself. This mirrors the behaviour in api/client_server/room.rs on room creation. --- src/api/client_server/alias.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/api/client_server/alias.rs b/src/api/client_server/alias.rs index b9008d63..821fa0c2 100644 --- a/src/api/client_server/alias.rs +++ b/src/api/client_server/alias.rs @@ -269,9 +269,7 @@ async fn alias_checks(room_alias: &OwnedRoomAliasId, appservice_info: &Option Date: Sat, 4 May 2024 19:23:12 +0000 Subject: [PATCH 0025/2291] utils: add helper for adding unbounded slices to tracing spans --- src/utils/mod.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 11a2ed3b..dbcef82d 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -216,3 +216,41 @@ pub(crate) fn conduwuit_version() -> String { }, } } + +/// Debug-formats the given slice, but only up to the first `max_len` elements. +/// Any further elements are replaced by an ellipsis. +/// +/// See also [`debug_slice_truncated()`], +pub(crate) struct TruncatedDebugSlice<'a, T> { + inner: &'a [T], + max_len: usize, +} + +impl fmt::Debug for TruncatedDebugSlice<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if self.inner.len() <= self.max_len { + write!(f, "{:?}", self.inner) + } else { + f.debug_list() + .entries(&self.inner[..self.max_len]) + .entry(&"...") + .finish() + } + } +} + +/// See [`TruncatedDebugSlice`]. Useful for `#[instrument]`: +/// +/// ``` +/// #[tracing::instrument(fields( +/// foos = debug_slice_truncated(foos, N) +/// ))] +/// ``` +pub(crate) fn debug_slice_truncated( + slice: &[T], max_len: usize, +) -> tracing::field::DebugValue> { + tracing::field::debug(TruncatedDebugSlice { + inner: slice, + max_len, + }) +} From 136cb038cfa7bdfe5bd11229517e26ac66e5eca1 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 4 May 2024 19:24:48 +0000 Subject: [PATCH 0026/2291] auth_chain: add useful debug logging --- src/service/rooms/auth_chain/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/service/rooms/auth_chain/mod.rs b/src/service/rooms/auth_chain/mod.rs index 10c52d02..4a59d989 100644 --- a/src/service/rooms/auth_chain/mod.rs +++ b/src/service/rooms/auth_chain/mod.rs @@ -6,9 +6,9 @@ use std::{ pub(crate) use data::Data; use ruma::{api::client::error::ErrorKind, EventId, RoomId}; -use tracing::{debug, error, warn}; +use tracing::{debug, error, trace, warn}; -use crate::{services, Error, Result}; +use crate::{services, utils::debug_slice_truncated, Error, Result}; pub(crate) struct Service { pub(crate) db: &'static dyn Data, @@ -30,7 +30,7 @@ impl Service { .filter_map(move |sid| services().rooms.short.get_eventid_from_short(sid).ok())) } - #[tracing::instrument(skip_all)] + #[tracing::instrument(skip(self), fields(starting_events = debug_slice_truncated(starting_events, 5)))] pub(crate) async fn get_auth_chain(&self, room_id: &RoomId, starting_events: &[&EventId]) -> Result> { const NUM_BUCKETS: usize = 50; //TODO: change possible w/o disrupting db? const BUCKET: BTreeSet<(u64, &EventId)> = BTreeSet::new(); @@ -68,6 +68,7 @@ impl Service { .auth_chain .get_cached_eventid_authchain(&chunk_key)? { + trace!("Found cache entry for whole chunk"); full_auth_chain.extend(cached.iter().copied()); hits += 1; continue; @@ -82,6 +83,7 @@ impl Service { .auth_chain .get_cached_eventid_authchain(&[sevent_id])? { + trace!(?event_id, "Found cache entry for event"); chunk_cache.extend(cached.iter().copied()); hits2 += 1; } else { @@ -132,15 +134,18 @@ impl Service { Ok(full_auth_chain) } - #[tracing::instrument(skip(self, event_id))] + #[tracing::instrument(skip(self, room_id))] fn get_auth_chain_inner(&self, room_id: &RoomId, event_id: &EventId) -> Result> { let mut todo = vec![Arc::from(event_id)]; let mut found = HashSet::new(); while let Some(event_id) = todo.pop() { + trace!(?event_id, "processing auth event"); + match services().rooms.timeline.get_pdu(&event_id) { Ok(Some(pdu)) => { if pdu.room_id != room_id { + error!(?event_id, ?pdu, "auth event for incorrect room_id"); return Err(Error::BadRequest(ErrorKind::forbidden(), "Evil event in db")); } for auth_event in &pdu.auth_events { @@ -150,6 +155,7 @@ impl Service { .get_or_create_shorteventid(auth_event)?; if found.insert(sauthevent) { + trace!(?event_id, ?auth_event, "adding auth event to processing queue"); todo.push(auth_event.clone()); } } From 2472c7c47a8eb61ac2b50a58b252141047b3831e Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 00:01:14 -0400 Subject: [PATCH 0027/2291] ci: don't run on `dev` anymore, run on main and non-draft PRs Signed-off-by: strawberry --- .github/workflows/ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eaddf17d..97614353 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,10 +14,8 @@ on: - 'docs/**' - 'debian/**' - 'docker/**' - - 'test_results/**' branches: - main - - dev # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -138,7 +136,7 @@ jobs: name: Build runs-on: ubuntu-latest needs: tests - if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' + if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) strategy: matrix: include: @@ -223,7 +221,7 @@ jobs: name: Docker publish runs-on: ubuntu-latest needs: build - if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name != 'pull_request' + if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) env: DOCKER_ARM64: docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-arm64v8 DOCKER_AMD64: docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-amd64 From cabf4362befa1f1764804fa88c097542e9eac773 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 00:02:34 -0400 Subject: [PATCH 0028/2291] docs: direct all PRs to main Signed-off-by: strawberry --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1e3fe11e..aff492f6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -72,7 +72,7 @@ Please try to keep contributions to the GitHub. While the mirrors of conduwuit a If you open a pull request on one of the mirrors, it is your responsibility to inform me about its existence. In the future I may try to solve this with more repo bots in the conduwuit Matrix room. There is no mailing list or email-patch support on the sr.ht mirror, but if you'd like to email me a git patch you can do so at `strawberry@puppygock.gay`. -Direct all PRs/MRs to the `dev` branch. Pull requests to `main` should only be done by a maintainer, or if the change is necessary enough to go straight to the main branch (e.g. critical fix). +Direct all PRs/MRs to the `main` branch. By sending a pull request or patch, you are agreeing that your changes are allowed to be licenced under the Apache-2.0 licence and all of your conduct is in line with the Contributor's Covenant. From ed60f189cc7500c1989f73eea4598fbfaf3f80a7 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 01:36:47 -0400 Subject: [PATCH 0029/2291] docs: remove dev docker images Signed-off-by: strawberry --- docs/deploying/docker.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/deploying/docker.md b/docs/deploying/docker.md index 7d21000a..bb52bc70 100644 --- a/docs/deploying/docker.md +++ b/docs/deploying/docker.md @@ -17,17 +17,12 @@ OCI images for conduwuit are available in the registries listed below. | GitHub Registry | [ghcr.io/girlbossceo/conduwuit:main][gh] | ![Image Size][shield-main] | Stable main branch. | | GitLab Registry | [registry.gitlab.com/girlbossceo/conduwuit:main][gl] | ![Image Size][shield-main] | Stable main branch. | | Docker Hub | [docker.io/girlbossceo/conduwuit:main][dh] | ![Image Size][shield-main] | Stable main branch. | -| GitHub Registry | [ghcr.io/girlbossceo/conduwuit:dev][gh] | ![Image Size][shield-dev] | Development version/branch. | -| GitLab Registry | [registry.gitlab.com/girlbossceo/conduwuit:dev][gl] | ![Image Size][shield-dev] | Development version/branch. | -| Docker Hub | [docker.io/girlbossceo/conduwuit:dev][dh] | ![Image Size][shield-dev] | Development version/branch. | - [dh]: https://hub.docker.com/repository/docker/girlbossceo/conduwuit [gh]: https://github.com/girlbossceo/conduwuit/pkgs/container/conduwuit [gl]: https://gitlab.com/girlbossceo/conduwuit/container_registry/6351657 [shield-latest]: https://img.shields.io/docker/image-size/girlbossceo/conduwuit/latest [shield-main]: https://img.shields.io/docker/image-size/girlbossceo/conduwuit/main -[shield-dev]: https://img.shields.io/docker/image-size/girlbossceo/conduwuit/dev Use From 56f1d8be1ffec1f04a23775967bd52ea8a8e5bd6 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 01:46:30 -0400 Subject: [PATCH 0030/2291] ci(docker): publish `latest` only if ref starts with our tag format Signed-off-by: strawberry --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97614353..a976461e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -226,15 +226,15 @@ jobs: DOCKER_ARM64: docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-arm64v8 DOCKER_AMD64: docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-amd64 DOCKER_TAG: docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }} - DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (github.ref == 'refs/heads/main' && 'latest') || github.ref_name }} + DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || github.ref_name }} GHCR_ARM64: ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-arm64v8 GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-amd64 GHCR_TAG: ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }} - GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (github.ref == 'refs/heads/main' && 'latest') || github.ref_name }} + GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || github.ref_name }} GLCR_ARM64: registry.gitlab.com/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-arm64v8 GLCR_AMD64: registry.gitlab.com/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-amd64 GLCR_TAG: registry.gitlab.com/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }} - GLCR_BRANCH: registry.gitlab.com/${{ github.repository }}:${{ (github.ref == 'refs/heads/main' && 'latest') || github.ref_name }} + GLCR_BRANCH: registry.gitlab.com/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || github.ref_name }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} steps: From 91ff6a36a4e4fa8543af8caad29b4ca385a1ded7 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 02:10:47 -0400 Subject: [PATCH 0031/2291] ci: abort workflow if latest repo tag does not match with running tag ref protects against a maintainer creating a downgrading version tag, and uploading artifacts with that version this check is only ran via workflow dispatch on the tag Signed-off-by: strawberry --- .github/workflows/ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a976461e..13a97664 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,18 @@ jobs: - name: Sync repository uses: actions/checkout@v4 + - name: Tag comparison check + if: startsWith('refs/tags/v', github.ref) + run: | + # Tag mismatch with latest repo tag check to prevent potential downgrades + LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) + + if [ $LATEST_TAG != ${{ github.ref_name }} ]; then + echo '# WARNING: Attempting to run this workflow for a tag that is not the latest repo tag. Aborting.' + echo '# WARNING: Attempting to run this workflow for a tag that is not the latest repo tag. Aborting.' >> $GITHUB_STEP_SUMMARY + exit 1 + fi + - name: Install Nix uses: DeterminateSystems/nix-installer-action@main From 9e1bbc165024de9630de823167478ea132b7a577 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 02:18:15 -0400 Subject: [PATCH 0032/2291] ci: run on new tag pushes Signed-off-by: strawberry --- .github/workflows/ci.yml | 2 ++ .github/workflows/documentation.yml | 2 ++ .github/workflows/trivy.yml | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13a97664..352b1387 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,8 @@ on: - 'docker/**' branches: - main + tags: + - '*' # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index de8087c9..ae0c9a85 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -5,6 +5,8 @@ on: push: branches: - main + tags: + - '*' # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index 5b4b7248..e045e381 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -5,6 +5,8 @@ on: push: branches: - main + tags: + - '*' schedule: - cron: '00 12 * * *' @@ -37,4 +39,4 @@ jobs: scan-type: fs format: sarif output: trivy-results.sarif - severity: CRITICAL,HIGH,MEDIUM,LOW \ No newline at end of file + severity: CRITICAL,HIGH,MEDIUM,LOW From 16a98b068353c3579599697691594549eadfdd96 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 20:13:52 -0400 Subject: [PATCH 0033/2291] ci: push docker images for PRs in the `merge-PR_NUMBER-HEAD_REF` format, fix main pushes Signed-off-by: strawberry --- .github/workflows/ci.yml | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 352b1387..be07a4d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -150,7 +150,7 @@ jobs: name: Build runs-on: ubuntu-latest needs: tests - if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) + if: startsWith('refs/tags/v', github.ref) || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) strategy: matrix: include: @@ -235,20 +235,21 @@ jobs: name: Docker publish runs-on: ubuntu-latest needs: build - if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) + if: startsWith('refs/tags/v', github.ref) || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) env: - DOCKER_ARM64: docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-arm64v8 - DOCKER_AMD64: docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-amd64 - DOCKER_TAG: docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }} - DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || github.ref_name }} - GHCR_ARM64: ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-arm64v8 - GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-amd64 - GHCR_TAG: ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }} - GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || github.ref_name }} - GLCR_ARM64: registry.gitlab.com/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-arm64v8 - GLCR_AMD64: registry.gitlab.com/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-amd64 - GLCR_TAG: registry.gitlab.com/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }} - GLCR_BRANCH: registry.gitlab.com/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || github.ref_name }} + DOCKER_ARM64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }}-arm64v8 + DOCKER_AMD64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_namee }}-${{ github.sha }}-amd64 + DOCKER_TAG: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }} + DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }} + GHCR_ARM64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }}-arm64v8 + GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_namee }}-${{ github.sha }}-amd64 + GHCR_TAG: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }} + GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }} + GLCR_ARM64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }}-arm64v8 + GLCR_AMD64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_namee }}-${{ github.sha }}-amd64 + GLCR_TAG: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }} + GLCR_BRANCH: registry.gitlab.com/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} steps: From 321e197d8c211cc444d0730bf6aaefd581714147 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 20:40:58 -0400 Subject: [PATCH 0034/2291] correct arithmetic adjustments Signed-off-by: strawberry --- src/api/client_server/keys.rs | 8 +------- src/api/client_server/membership.rs | 8 +------- src/api/client_server/room.rs | 4 +++- src/api/client_server/sync.rs | 12 ++++-------- src/database/key_value/rooms/state_accessor.rs | 4 ++-- src/database/key_value/rooms/timeline.rs | 6 +----- src/database/migrations.rs | 10 ++++------ src/database/mod.rs | 15 ++------------- src/service/admin/media/media_commands.rs | 2 +- src/service/admin/room/room_commands.rs | 2 +- src/service/admin/room/room_directory_commands.rs | 2 +- src/service/media/mod.rs | 4 +++- 12 files changed, 24 insertions(+), 53 deletions(-) diff --git a/src/api/client_server/keys.rs b/src/api/client_server/keys.rs index efd78b2f..040916b0 100644 --- a/src/api/client_server/keys.rs +++ b/src/api/client_server/keys.rs @@ -340,13 +340,7 @@ pub(crate) async fn get_keys_helper bool>( e.insert((Instant::now(), 1)); }, hash_map::Entry::Occupied(mut e) => { - *e.get_mut() = ( - Instant::now(), - e.get() - .1 - .checked_add(1) - .expect("bad_query_ratelimiter attempt/try count should not ever get this high"), - ); + *e.get_mut() = (Instant::now(), e.get().1.saturating_add(1)); }, } }; diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index cd9edd4c..54af1d41 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -1395,13 +1395,7 @@ async fn validate_and_add_event_id( e.insert((Instant::now(), 1)); }, Entry::Occupied(mut e) => { - *e.get_mut() = ( - Instant::now(), - e.get() - .1 - .checked_add(1) - .expect("bad_event_ratelimiter attempt/try count should not ever get this high"), - ); + *e.get_mut() = (Instant::now(), e.get().1.saturating_add(1)); }, } }; diff --git a/src/api/client_server/room.rs b/src/api/client_server/room.rs index d027c4f4..46ad4454 100644 --- a/src/api/client_server/room.rs +++ b/src/api/client_server/room.rs @@ -806,7 +806,9 @@ pub(crate) async fn upgrade_room_route(body: Ruma) -> power_levels_event_content .users_default .checked_add(int!(1)) - .expect("user power level should not be this high"), + .ok_or_else(|| { + Error::BadRequest(ErrorKind::BadJson, "users_default power levels event content is not valid") + })?, ); power_levels_event_content.events_default = new_level; power_levels_event_content.invite = new_level; diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index c5afacc0..647ce905 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -557,7 +557,7 @@ async fn handle_left_room( left_state_events.push(pdu.to_sync_state_event()); - i = i.saturating_add(1); + i = i.wrapping_add(1); if i % 100 == 0 { tokio::task::yield_now().await; } @@ -705,11 +705,7 @@ async fn load_joined_room( // Recalculate heroes (first 5 members) let mut heroes = Vec::new(); - if joined_member_count - .checked_add(invited_member_count) - .expect("joined/invite member count should not be this high") - <= 5 - { + if joined_member_count.saturating_add(invited_member_count) <= 5 { // Go through all PDUs and for each member event, check if the user is still // joined or invited until we have 5 or we reach the end @@ -802,7 +798,7 @@ async fn load_joined_room( }; state_events.push(pdu); - i = i.saturating_add(1); + i = i.wrapping_add(1); if i % 100 == 0 { tokio::task::yield_now().await; } @@ -823,7 +819,7 @@ async fn load_joined_room( } state_events.push(pdu); - i = i.saturating_add(1); + i = i.wrapping_add(1); if i % 100 == 0 { tokio::task::yield_now().await; } diff --git a/src/database/key_value/rooms/state_accessor.rs b/src/database/key_value/rooms/state_accessor.rs index c039299d..5b3a71d0 100644 --- a/src/database/key_value/rooms/state_accessor.rs +++ b/src/database/key_value/rooms/state_accessor.rs @@ -25,7 +25,7 @@ impl service::rooms::state_accessor::Data for KeyValueDatabase { .parse_compressed_state_event(compressed)?; result.insert(parsed.0, parsed.1); - i = i.saturating_add(1); + i = i.wrapping_add(1); if i % 100 == 0 { tokio::task::yield_now().await; } @@ -63,7 +63,7 @@ impl service::rooms::state_accessor::Data for KeyValueDatabase { ); } - i = i.saturating_add(1); + i = i.wrapping_add(1); if i % 100 == 0 { tokio::task::yield_now().await; } diff --git a/src/database/key_value/rooms/timeline.rs b/src/database/key_value/rooms/timeline.rs index 104678f9..d583c7ec 100644 --- a/src/database/key_value/rooms/timeline.rs +++ b/src/database/key_value/rooms/timeline.rs @@ -284,11 +284,7 @@ fn count_to_id(room_id: &RoomId, count: PduCount, offset: u64, subtract: bool) - pdu_id.extend_from_slice(&0_u64.to_be_bytes()); let num = u64::MAX.saturating_sub(x); if subtract { - if num > 0 { - num.saturating_sub(offset) - } else { - num - } + num.saturating_sub(offset) } else { num.saturating_add(offset) } diff --git a/src/database/migrations.rs b/src/database/migrations.rs index 915841f1..a6726528 100644 --- a/src/database/migrations.rs +++ b/src/database/migrations.rs @@ -173,13 +173,11 @@ pub(crate) async fn migrations(db: &KeyValueDatabase, config: &Config) -> Result let mut current_sstatehash: Option = None; let mut current_room = None; let mut current_state = HashSet::new(); - let mut counter: u32 = 0; - let mut handle_state = |current_sstatehash: u64, - current_room: &RoomId, - current_state: HashSet<_>, - last_roomstates: &mut HashMap<_, _>| { - counter = counter.saturating_add(1); + let handle_state = |current_sstatehash: u64, + current_room: &RoomId, + current_state: HashSet<_>, + last_roomstates: &mut HashMap<_, _>| { let last_roomsstatehash = last_roomstates.get(current_room); let states_parents = last_roomsstatehash.map_or_else( diff --git a/src/database/mod.rs b/src/database/mod.rs index 825a21e8..4fbc3f97 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -402,19 +402,8 @@ impl KeyValueDatabase { let sqlite_exists = path.join("conduit.db").exists(); let rocksdb_exists = path.join("IDENTITY").exists(); - let mut count: u8 = 0; - - if sqlite_exists { - count = count.saturating_add(1); - } - - if rocksdb_exists { - count = count.saturating_add(1); - } - - if count > 1 { - error!("Multiple databases at database_path detected"); - return Ok(()); + if sqlite_exists && rocksdb_exists { + return Err(Error::bad_config("Multiple databases at database_path detected.")); } if sqlite_exists && config.database_backend != "sqlite" { diff --git a/src/service/admin/media/media_commands.rs b/src/service/admin/media/media_commands.rs index cb74a4bb..3f1fc8bf 100644 --- a/src/service/admin/media/media_commands.rs +++ b/src/service/admin/media/media_commands.rs @@ -144,7 +144,7 @@ pub(crate) async fn delete_list(body: Vec<&str>) -> Result>(); - let mut mxc_deletion_count: u32 = 0; + let mut mxc_deletion_count: usize = 0; for mxc in mxc_list { debug!("Deleting MXC {mxc} in bulk"); diff --git a/src/service/admin/room/room_commands.rs b/src/service/admin/room/room_commands.rs index 399f3c09..4e4e60e1 100644 --- a/src/service/admin/room/room_commands.rs +++ b/src/service/admin/room/room_commands.rs @@ -22,7 +22,7 @@ pub(crate) async fn list(_body: Vec<&str>, page: Option) -> Result>(); diff --git a/src/service/admin/room/room_directory_commands.rs b/src/service/admin/room/room_directory_commands.rs index dd4f599d..ccce2164 100644 --- a/src/service/admin/room/room_directory_commands.rs +++ b/src/service/admin/room/room_directory_commands.rs @@ -39,7 +39,7 @@ pub(crate) async fn process(command: RoomDirectoryCommand, _body: Vec<&str>) -> let rooms = rooms .into_iter() - .skip(page.checked_sub(1).unwrap().checked_mul(PAGE_SIZE).unwrap()) + .skip(page.saturating_sub(1).saturating_mul(PAGE_SIZE)) .take(PAGE_SIZE) .collect::>(); diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index ca81fa67..73c8e089 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -188,7 +188,9 @@ impl Service { Ok(duration) => { debug!("Parsed duration: {:?}", duration); debug!("System time now: {:?}", SystemTime::now()); - SystemTime::now().checked_sub(duration).unwrap() + SystemTime::now().checked_sub(duration).ok_or_else(|| { + Error::bad_database("Duration specified is not valid against the current system time") + })? }, Err(e) => { error!("Failed to parse user-specified time duration: {}", e); From d657fa32e9c9389cbceac2d0e44a3b8897130624 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 5 May 2024 22:07:37 -0400 Subject: [PATCH 0035/2291] ci: format string Signed-off-by: strawberry --- .github/workflows/ci.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be07a4d6..88f594fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -237,18 +237,18 @@ jobs: needs: build if: startsWith('refs/tags/v', github.ref) || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) env: - DOCKER_ARM64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }}-arm64v8 - DOCKER_AMD64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_namee }}-${{ github.sha }}-amd64 - DOCKER_TAG: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }} - DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }} - GHCR_ARM64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }}-arm64v8 - GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_namee }}-${{ github.sha }}-amd64 - GHCR_TAG: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }} - GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }} - GLCR_ARM64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }}-arm64v8 - GLCR_AMD64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_namee }}-${{ github.sha }}-amd64 - GLCR_TAG: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }}-${{ github.sha }} - GLCR_BRANCH: registry.gitlab.com/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && 'merge-github.event.number-github.head_ref') || github.ref_name }} + DOCKER_ARM64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-arm64v8 + DOCKER_AMD64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_namee }}-${{ github.sha }}-amd64 + DOCKER_TAG: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }} + DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }} + GHCR_ARM64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-arm64v8 + GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_namee }}-${{ github.sha }}-amd64 + GHCR_TAG: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }} + GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }} + GLCR_ARM64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-arm64v8 + GLCR_AMD64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_namee }}-${{ github.sha }}-amd64 + GLCR_TAG: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }} + GLCR_BRANCH: registry.gitlab.com/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} From 8c21388f0149ca6044670f547d6ad8083d99a743 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Mon, 6 May 2024 00:08:20 -0400 Subject: [PATCH 0036/2291] fix nix-build-and-cache Now it actually caches everything. Signed-off-by: strawberry --- bin/nix-build-and-cache | 80 ++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/bin/nix-build-and-cache b/bin/nix-build-and-cache index 140fd561..67e3aa4e 100755 --- a/bin/nix-build-and-cache +++ b/bin/nix-build-and-cache @@ -13,41 +13,55 @@ just() { nix build -L "$@" fi - if [ ! -z "$ATTIC_TOKEN" ]; then - # historical "conduit" store for compatibility purposes, same as conduwuit - nix run --inputs-from "$toplevel" attic -- \ - login \ - conduit \ - "${ATTIC_ENDPOINT:-https://attic.kennel.juneis.dog/conduit}" \ - "$ATTIC_TOKEN" - - readarray -t outputs < <(nix path-info "$@") - readarray -t derivations < <(nix path-info "$@" --derivation) - - # Push the target installable and its build dependencies - nix run --inputs-from "$toplevel" attic -- \ - push \ - conduit \ - "${outputs[@]}" \ - "${derivations[@]}" - - # main "conduwuit" store - nix run --inputs-from "$toplevel" attic -- \ - login \ - conduwuit \ - "${ATTIC_ENDPOINT:-https://attic.kennel.juneis.dog/conduwuit}" \ - "$ATTIC_TOKEN" - - # Push the target installable and its build dependencies - nix run --inputs-from "$toplevel" attic -- \ - push \ - conduwuit \ - "${outputs[@]}" \ - "${derivations[@]}" - else + if [ -z "$ATTIC_TOKEN" ]; then echo "\$ATTIC_TOKEN is unset, skipping uploading to the binary cache" + return fi + # historical "conduit" store for compatibility purposes, same as conduwuit + nix run --inputs-from "$toplevel" attic -- \ + login \ + conduit \ + "${ATTIC_ENDPOINT:-https://attic.kennel.juneis.dog/conduit}" \ + "$ATTIC_TOKEN" + + # Find all output paths of the installables and their build dependencies + readarray -t derivations < <(nix path-info --derivation "$@") + cache=() + for derivation in "${derivations[@]}"; do + cache+=( + "$(nix-store --query --requisites --include-outputs "$derivation")" + ) + done + + # Upload them to Attic (conduit store) + # + # Use `xargs` and a here-string because something would probably explode if + # several thousand arguments got passed to a command at once. Hopefully no + # store paths include a newline in them. + ( + IFS=$'\n' + nix shell --inputs-from "$toplevel" attic -c xargs \ + attic push conduit <<< "${cache[*]}" + ) + + # main "conduwuit" store + nix run --inputs-from "$toplevel" attic -- \ + login \ + conduwuit \ + "${ATTIC_ENDPOINT:-https://attic.kennel.juneis.dog/conduwuit}" \ + "$ATTIC_TOKEN" + + # Upload them to Attic (conduwuit store) + # + # Use `xargs` and a here-string because something would probably explode if + # several thousand arguments got passed to a command at once. Hopefully no + # store paths include a newline in them. + ( + IFS=$'\n' + nix shell --inputs-from "$toplevel" attic -c xargs \ + attic push conduwuit <<< "${cache[*]}" + ) } # Build and cache things needed for CI @@ -56,7 +70,7 @@ ci() { --inputs-from "$toplevel" # Keep sorted - "$toplevel#devShells.x86_64-linux.default.inputDerivation" + "$toplevel#devShells.x86_64-linux.default" attic#default nixpkgs#direnv nixpkgs#jq From 86ec20e7875d5168d91787f57a6c6cf0ee24c882 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 6 May 2024 00:31:39 -0400 Subject: [PATCH 0037/2291] docs: remove last dev branch mention Signed-off-by: strawberry --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index e110cd80..bbdbcbcb 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ `main` / stable: [![CI and Artifacts](https://github.com/girlbossceo/conduwuit/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/girlbossceo/conduwuit/actions/workflows/ci.yml) -`dev`: [![CI and Artifacts](https://github.com/girlbossceo/conduwuit/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/girlbossceo/conduwuit/actions/workflows/ci.yml) - ### a very cool, featureful fork of [Conduit](https://conduit.rs/) From 1f8a7a707c797b9e51d13ecfe20b118fed01f4aa Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 6 May 2024 01:09:51 -0400 Subject: [PATCH 0038/2291] nix: cache complement outputs using nix-build-and-cache Signed-off-by: strawberry --- bin/complement | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bin/complement b/bin/complement index fd6ab58d..c2c6ab34 100755 --- a/bin/complement +++ b/bin/complement @@ -20,12 +20,9 @@ OCI_IMAGE="complement-conduit:dev" toplevel="$(git rev-parse --show-toplevel)" pushd "$toplevel" > /dev/null -# uses nix-output-monitor (nom) if available -if command -v nom &> /dev/null; then - nom build .#complement -else - nix build -L .#complement -fi + +bin/nix-build-and-cache just .#complement + docker load < result popd > /dev/null From 7b25ef2e6c828f4c541b63706d8651b03e4c896d Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 6 May 2024 02:40:16 -0400 Subject: [PATCH 0039/2291] make next_batch token a variable in search, revert threads_until change Signed-off-by: strawberry --- src/api/client_server/search.rs | 6 ++++-- src/database/key_value/rooms/threads.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api/client_server/search.rs b/src/api/client_server/search.rs index b09c6326..2441f555 100644 --- a/src/api/client_server/search.rs +++ b/src/api/client_server/search.rs @@ -118,7 +118,9 @@ pub(crate) async fn search_events_route(body: Ruma) }; let mut results = Vec::new(); - for _ in 0_usize..skip.saturating_add(limit) { + let next_batch: usize = skip.saturating_add(limit); + + for _ in 0..next_batch { if let Some(s) = searches .iter_mut() .map(|s| (s.peek().cloned(), s)) @@ -167,7 +169,7 @@ pub(crate) async fn search_events_route(body: Ruma) let next_batch = if results.len() < limit { None } else { - Some((skip.checked_add(limit).unwrap()).to_string()) + Some(next_batch.to_string()) }; Ok(search_events::v3::Response::new(ResultCategories { diff --git a/src/database/key_value/rooms/threads.rs b/src/database/key_value/rooms/threads.rs index fa14f0ed..4cb2591b 100644 --- a/src/database/key_value/rooms/threads.rs +++ b/src/database/key_value/rooms/threads.rs @@ -19,7 +19,7 @@ impl service::rooms::threads::Data for KeyValueDatabase { .to_vec(); let mut current = prefix.clone(); - current.extend_from_slice(&(until.saturating_sub(1)).to_be_bytes()); + current.extend_from_slice(&(until - 1).to_be_bytes()); Ok(Box::new( self.threadid_userids From 99d98efeb187bcac21856dedbdfbb7d458a6a176 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 6 May 2024 12:09:24 -0400 Subject: [PATCH 0040/2291] ci: fix docker publishing typo Signed-off-by: strawberry --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88f594fb..369fe6a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -238,15 +238,15 @@ jobs: if: startsWith('refs/tags/v', github.ref) || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) env: DOCKER_ARM64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-arm64v8 - DOCKER_AMD64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_namee }}-${{ github.sha }}-amd64 + DOCKER_AMD64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-amd64 DOCKER_TAG: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }} DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }} GHCR_ARM64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-arm64v8 - GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_namee }}-${{ github.sha }}-amd64 + GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-amd64 GHCR_TAG: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }} GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }} GLCR_ARM64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-arm64v8 - GLCR_AMD64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_namee }}-${{ github.sha }}-amd64 + GLCR_AMD64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-amd64 GLCR_TAG: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }} GLCR_BRANCH: registry.gitlab.com/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }} From 43b07be3fc81f8cabfba193784fb92c997fd2293 Mon Sep 17 00:00:00 2001 From: strawberry Date: Tue, 7 May 2024 01:56:26 -0400 Subject: [PATCH 0041/2291] ci: use PR author instead of branch name for docker image publishing Signed-off-by: strawberry --- .github/workflows/ci.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 369fe6a5..1b5f47f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -237,18 +237,18 @@ jobs: needs: build if: startsWith('refs/tags/v', github.ref) || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) env: - DOCKER_ARM64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-arm64v8 - DOCKER_AMD64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-amd64 - DOCKER_TAG: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }} - DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }} - GHCR_ARM64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-arm64v8 - GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-amd64 - GHCR_TAG: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }} - GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }} - GLCR_ARM64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-arm64v8 - GLCR_AMD64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }}-amd64 - GLCR_TAG: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }}-${{ github.sha }} - GLCR_BRANCH: registry.gitlab.com/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.head_ref)) || github.ref_name }} + DOCKER_ARM64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-arm64v8 + DOCKER_AMD64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-amd64 + DOCKER_TAG: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }} + DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} + GHCR_ARM64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-arm64v8 + GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-amd64 + GHCR_TAG: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }} + GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} + GLCR_ARM64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-arm64v8 + GLCR_AMD64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-amd64 + GLCR_TAG: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }} + GLCR_BRANCH: registry.gitlab.com/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} From 245c34e65918738e6d07685aadfe97da9a274791 Mon Sep 17 00:00:00 2001 From: strawberry Date: Tue, 7 May 2024 23:56:14 -0400 Subject: [PATCH 0042/2291] ci: dont run docker publishing if none of the usernames are set Signed-off-by: strawberry --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b5f47f6..ee346ade 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -235,7 +235,7 @@ jobs: name: Docker publish runs-on: ubuntu-latest needs: build - if: startsWith('refs/tags/v', github.ref) || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) + if: (startsWith('refs/tags/v', github.ref) || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)) && (vars.DOCKER_USERNAME != '') && (vars.GITLAB_USERNAME != '') env: DOCKER_ARM64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-arm64v8 DOCKER_AMD64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-amd64 From ddb87168edc053aebb80d3727bf75666cabb9334 Mon Sep 17 00:00:00 2001 From: strawberry Date: Tue, 7 May 2024 13:37:55 -0400 Subject: [PATCH 0043/2291] update gitlab repo link Signed-off-by: strawberry --- README.md | 2 +- docs/deploying/docker.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bbdbcbcb..d00ce5a4 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Both, but I prefer conduwuit. #### Mirrors of conduwuit - GitHub: -- GitLab: +- GitLab: - git.gay: - Codeberg: - sourcehut: diff --git a/docs/deploying/docker.md b/docs/deploying/docker.md index bb52bc70..2e0f5ba0 100644 --- a/docs/deploying/docker.md +++ b/docs/deploying/docker.md @@ -12,15 +12,15 @@ OCI images for conduwuit are available in the registries listed below. | Registry | Image | Size | Notes | | --------------- | --------------------------------------------------------------- | ----------------------------- | ---------------------- | | GitHub Registry | [ghcr.io/girlbossceo/conduwuit:latest][gh] | ![Image Size][shield-latest] | Stable tagged image. | -| GitLab Registry | [registry.gitlab.com/girlbossceo/conduwuit:latest][gl] | ![Image Size][shield-latest] | Stable tagged image. | +| GitLab Registry | [registry.gitlab.com/conduwuit/conduwuit:latest][gl] | ![Image Size][shield-latest] | Stable tagged image. | | Docker Hub | [docker.io/girlbossceo/conduwuit:latest][dh] | ![Image Size][shield-latest] | Stable tagged image. | | GitHub Registry | [ghcr.io/girlbossceo/conduwuit:main][gh] | ![Image Size][shield-main] | Stable main branch. | -| GitLab Registry | [registry.gitlab.com/girlbossceo/conduwuit:main][gl] | ![Image Size][shield-main] | Stable main branch. | +| GitLab Registry | [registry.gitlab.com/conduwuit/conduwuit:main][gl] | ![Image Size][shield-main] | Stable main branch. | | Docker Hub | [docker.io/girlbossceo/conduwuit:main][dh] | ![Image Size][shield-main] | Stable main branch. | [dh]: https://hub.docker.com/repository/docker/girlbossceo/conduwuit [gh]: https://github.com/girlbossceo/conduwuit/pkgs/container/conduwuit -[gl]: https://gitlab.com/girlbossceo/conduwuit/container_registry/6351657 +[gl]: https://gitlab.com/conduwuit/conduwuit/container_registry/6351657 [shield-latest]: https://img.shields.io/docker/image-size/girlbossceo/conduwuit/latest [shield-main]: https://img.shields.io/docker/image-size/girlbossceo/conduwuit/main From e99aac95507479e253966a6c6ee24fae6f4811b1 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 8 May 2024 14:11:25 -0400 Subject: [PATCH 0044/2291] ci: fix gitlab container registry destination Signed-off-by: strawberry --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee346ade..93698534 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -245,10 +245,10 @@ jobs: GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-amd64 GHCR_TAG: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }} GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} - GLCR_ARM64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-arm64v8 - GLCR_AMD64: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-amd64 - GLCR_TAG: registry.gitlab.com/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }} - GLCR_BRANCH: registry.gitlab.com/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} + GLCR_ARM64: registry.gitlab.com/conduwuit/conduwuit:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-arm64v8 + GLCR_AMD64: registry.gitlab.com/conduwuit/conduwuit:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-amd64 + GLCR_TAG: registry.gitlab.com/conduwuit/conduwuit:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }} + GLCR_BRANCH: registry.gitlab.com/conduwuit/conduwuit:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} From e4e1636da8d87a1fcaf5a65ce9ad14ac69d8f23a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 8 May 2024 06:08:52 +0000 Subject: [PATCH 0045/2291] chore(deps): update aquasecurity/trivy-action action to v0.20.0 --- .github/workflows/trivy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index e045e381..881d18f7 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v4 - name: Run Trivy code and vulnerability scanner on repo - uses: aquasecurity/trivy-action@0.19.0 + uses: aquasecurity/trivy-action@0.20.0 with: scan-type: repo format: sarif @@ -34,7 +34,7 @@ jobs: severity: CRITICAL,HIGH,MEDIUM,LOW - name: Run Trivy code and vulnerability scanner on filesystem - uses: aquasecurity/trivy-action@0.19.0 + uses: aquasecurity/trivy-action@0.20.0 with: scan-type: fs format: sarif From d4d9f92adeaf3ae6d312b3f1a98db13f9e6d2bf5 Mon Sep 17 00:00:00 2001 From: strawberry Date: Tue, 7 May 2024 12:53:30 -0400 Subject: [PATCH 0046/2291] add security response HTTP headers if not present Signed-off-by: strawberry --- Cargo.toml | 1 + src/api/client_server/media.rs | 2 +- src/router/mod.rs | 35 +++++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 54cd8268..ea2d1770 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -109,6 +109,7 @@ features = [ "add-extension", "cors", "sensitive-headers", + "set-header", "trace", "util", "catch-panic", diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index 0de61233..12899b39 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -25,7 +25,7 @@ use crate::{ const MXC_LENGTH: usize = 32; /// Cache control for immutable objects -const CACHE_CONTROL_IMMUTABLE: &str = "public, max-age=31536000, immutable"; +const CACHE_CONTROL_IMMUTABLE: &str = "public,max-age=31536000,immutable"; const CORP_CROSS_ORIGIN: &str = "cross-origin"; diff --git a/src/router/mod.rs b/src/router/mod.rs index 03e8be60..aa928685 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -6,7 +6,7 @@ use axum::{ Router, }; use http::{ - header::{self, HeaderName}, + header::{self, HeaderName, HeaderValue}, Method, StatusCode, Uri, }; use ruma::api::client::{ @@ -17,6 +17,7 @@ use tower::ServiceBuilder; use tower_http::{ catch_panic::CatchPanicLayer, cors::{self, CorsLayer}, + set_header::SetResponseHeaderLayer, trace::{DefaultOnFailure, DefaultOnRequest, DefaultOnResponse, TraceLayer}, ServiceBuilderExt as _, }; @@ -32,6 +33,9 @@ pub(crate) async fn build(server: &Server) -> io::Result>::new_from_top()); let x_forwarded_for = HeaderName::from_static("x-forwarded-for"); + let permissions_policy = HeaderName::from_static("permissions-policy"); + let origin_agent_cluster = HeaderName::from_static("origin-agent-cluster"); // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin-Agent-Cluster + let middlewares = base_middlewares .sensitive_headers([header::AUTHORIZATION]) .sensitive_request_headers([x_forwarded_for].into()) @@ -44,6 +48,33 @@ pub(crate) async fn build(server: &Server) -> io::Result fn cors_layer(_server: &Server) -> CorsLayer { const METHODS: [Method; 7] = [ Method::GET, From 2231ccf11829d6400ef72ed0ad754c6909bcbf94 Mon Sep 17 00:00:00 2001 From: strawberry Date: Tue, 7 May 2024 16:36:22 -0400 Subject: [PATCH 0047/2291] return `inline` Content-Disposition based on the detected file type (e.g. image/video) Signed-off-by: strawberry --- Cargo.lock | 7 ++++ Cargo.toml | 2 ++ src/api/client_server/media.rs | 62 ++++++++++++++++++++++++++++------ 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d91f30d0..9935aa21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -594,6 +594,7 @@ dependencies = [ "hyper 1.3.1", "hyper-util", "image", + "infer", "ipaddress", "itertools", "jsonwebtoken", @@ -1605,6 +1606,12 @@ dependencies = [ "serde", ] +[[package]] +name = "infer" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "865e8a58ae8e24d2c4412c31344afa1d302a3740ad67528c10f50d6876cdcf55" + [[package]] name = "inlinable_string" version = "0.1.15" diff --git a/Cargo.toml b/Cargo.toml index ea2d1770..681057a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,8 @@ rust-version = "1.77.0" [dependencies] console-subscriber = { version = "0.2", optional = true } +infer = { version = "0.3", default-features = false } + # for hot lib reload hot-lib-reloader = { version = "^0.7", optional = true } diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index 12899b39..53091d3a 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -1,6 +1,7 @@ use std::{io::Cursor, sync::Arc, time::Duration}; use image::io::Reader as ImgReader; +use infer::MatcherType; use ipaddress::IPAddress; use reqwest::Url; use ruma::api::client::{ @@ -178,11 +179,13 @@ pub(crate) async fn get_content_route(body: Ruma) -> R .. }) = services().media.get(mxc.clone()).await? { + let content_disposition = Some(String::from(content_disposition_type(&file, &content_type))); + // TODO: safely sanitise filename to be included in the content-disposition Ok(get_content::v3::Response { file, content_type, - content_disposition: Some("attachment".to_owned()), + content_disposition, cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), }) @@ -241,10 +244,12 @@ pub(crate) async fn get_content_as_filename_route( .. }) = services().media.get(mxc.clone()).await? { + let content_disposition = Some(String::from(content_disposition_type(&file, &content_type))); + Ok(get_content_as_filename::v3::Response { file, content_type, - content_disposition: Some("attachment".to_owned()), + content_disposition, cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), }) @@ -258,13 +263,20 @@ pub(crate) async fn get_content_as_filename_route( ) .await { - Ok(remote_content_response) => Ok(get_content_as_filename::v3::Response { - content_disposition: Some("attachment".to_owned()), - content_type: remote_content_response.content_type, - file: remote_content_response.file, - cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), - cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), - }), + Ok(remote_content_response) => { + let content_disposition = Some(String::from(content_disposition_type( + &remote_content_response.file, + &remote_content_response.content_type, + ))); + + Ok(get_content_as_filename::v3::Response { + content_disposition, + content_type: remote_content_response.content_type, + file: remote_content_response.file, + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), + cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), + }) + }, Err(e) => { debug_warn!("Fetching media `{}` failed: {:?}", mxc, e); Err(Error::BadRequest(ErrorKind::NotFound, "Remote media error.")) @@ -323,12 +335,14 @@ pub(crate) async fn get_content_thumbnail_route( ) .await? { + let content_disposition = Some(String::from(content_disposition_type(&file, &content_type))); + Ok(get_content_thumbnail::v3::Response { file, content_type, cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), - content_disposition: Some("attachment".to_owned()), + content_disposition, }) } else if !server_is_ours(&body.server_name) && body.allow_remote { if services() @@ -373,12 +387,17 @@ pub(crate) async fn get_content_thumbnail_route( ) .await?; + let content_disposition = Some(String::from(content_disposition_type( + &get_thumbnail_response.file, + &get_thumbnail_response.content_type, + ))); + Ok(get_content_thumbnail::v3::Response { file: get_thumbnail_response.file, content_type: get_thumbnail_response.content_type, cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.to_owned()), - content_disposition: Some("attachment".to_owned()), + content_disposition, }) }, Err(e) => { @@ -688,3 +707,24 @@ fn url_preview_allowed(url_str: &str) -> bool { false } + +/// Returns a Content-Disposition of `attachment` or `inline`, depending on the +/// *parsed* contents of the file uploaded via format magic keys using `infer` +/// crate (basically libmagic without needing libmagic). +/// +/// This forbids trusting what the client or remote server says the file is from +/// their `Content-Type` and we try to detect it ourselves. Also returns +/// `attachment` if the Content-Type does not match what we detected. +/// +/// TODO: add a "strict" function for comparing the Content-Type with what we +/// detected: `file_type.mime_type() != content_type` +fn content_disposition_type(buf: &[u8], _content_type: &Option) -> &'static str { + let Some(file_type) = infer::get(buf) else { + return "attachment"; + }; + + match file_type.matcher_type() { + MatcherType::IMAGE | MatcherType::AUDIO | MatcherType::TEXT | MatcherType::VIDEO => "inline", + _ => "attachment", + } +} From 154b2ab49051bf14ca62a143e5d2edf9e0ef5c93 Mon Sep 17 00:00:00 2001 From: strawberry Date: Tue, 7 May 2024 21:32:06 -0400 Subject: [PATCH 0048/2291] media: additional sanitisation on the `Content-Disposition` filename Signed-off-by: strawberry --- Cargo.lock | 11 ++++ Cargo.toml | 1 + src/api/client_server/media.rs | 85 ++++++++++++++++-------------- src/utils/content_disposition.rs | 88 ++++++++++++++++++++++++++++++++ src/utils/mod.rs | 1 + 5 files changed, 148 insertions(+), 38 deletions(-) create mode 100644 src/utils/content_disposition.rs diff --git a/Cargo.lock b/Cargo.lock index 9935aa21..6944d8d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -615,6 +615,7 @@ dependencies = [ "ruma-identifiers-validation", "rusqlite", "rust-rocksdb", + "sanitize-filename", "sd-notify", "sentry", "sentry-tower", @@ -3054,6 +3055,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "sanitize-filename" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ed72fbaf78e6f2d41744923916966c4fbe3d7c74e3037a8ee482f1115572603" +dependencies = [ + "lazy_static", + "regex", +] + [[package]] name = "schannel" version = "0.1.23" diff --git a/Cargo.toml b/Cargo.toml index 681057a0..f24789f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,6 +79,7 @@ url = { version = "2.5.0", features = ["serde"] } async-trait = "0.1.80" lru-cache = "0.1.2" +sanitize-filename = "0.5.0" # standard date and time tools [dependencies.chrono] diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index 53091d3a..e4e7376d 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -1,7 +1,6 @@ use std::{io::Cursor, sync::Arc, time::Duration}; use image::io::Reader as ImgReader; -use infer::MatcherType; use ipaddress::IPAddress; use reqwest::Url; use ruma::api::client::{ @@ -18,7 +17,11 @@ use crate::{ debug_warn, service::media::{FileMeta, UrlPreviewData}, services, - utils::{self, server_name::server_is_ours}, + utils::{ + self, + content_disposition::{content_disposition_type, make_content_disposition, sanitise_filename}, + server_name::server_is_ours, + }, Error, Result, Ruma, RumaResponse, }; @@ -131,7 +134,13 @@ pub(crate) async fn create_content_route( mxc.clone(), body.filename .as_ref() - .map(|filename| format!("attachment; filename={filename}")) + .map(|filename| { + format!( + "{}; filename={}", + content_disposition_type(&body.file, &body.content_type), + sanitise_filename(filename.to_owned()) + ) + }) .as_deref(), body.content_type.as_deref(), &body.file, @@ -176,12 +185,11 @@ pub(crate) async fn get_content_route(body: Ruma) -> R if let Some(FileMeta { content_type, file, - .. + content_disposition, }) = services().media.get(mxc.clone()).await? { - let content_disposition = Some(String::from(content_disposition_type(&file, &content_type))); + let content_disposition = Some(make_content_disposition(&file, &content_type, content_disposition)); - // TODO: safely sanitise filename to be included in the content-disposition Ok(get_content::v3::Response { file, content_type, @@ -190,7 +198,7 @@ pub(crate) async fn get_content_route(body: Ruma) -> R cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), }) } else if !server_is_ours(&body.server_name) && body.allow_remote { - get_remote_content( + let response = get_remote_content( &mxc, &body.server_name, body.media_id.clone(), @@ -201,6 +209,20 @@ pub(crate) async fn get_content_route(body: Ruma) -> R .map_err(|e| { debug_warn!("Fetching media `{}` failed: {:?}", mxc, e); Error::BadRequest(ErrorKind::NotFound, "Remote media error.") + })?; + + let content_disposition = Some(make_content_disposition( + &response.file, + &response.content_type, + response.content_disposition, + )); + + Ok(get_content::v3::Response { + file: response.file, + content_type: response.content_type, + content_disposition, + cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), + cache_control: Some(CACHE_CONTROL_IMMUTABLE.to_owned()), }) } else { Err(Error::BadRequest(ErrorKind::NotFound, "Media not found.")) @@ -241,10 +263,10 @@ pub(crate) async fn get_content_as_filename_route( if let Some(FileMeta { content_type, file, - .. + content_disposition, }) = services().media.get(mxc.clone()).await? { - let content_disposition = Some(String::from(content_disposition_type(&file, &content_type))); + let content_disposition = Some(make_content_disposition(&file, &content_type, content_disposition)); Ok(get_content_as_filename::v3::Response { file, @@ -264,10 +286,11 @@ pub(crate) async fn get_content_as_filename_route( .await { Ok(remote_content_response) => { - let content_disposition = Some(String::from(content_disposition_type( + let content_disposition = Some(make_content_disposition( &remote_content_response.file, &remote_content_response.content_type, - ))); + remote_content_response.content_disposition, + )); Ok(get_content_as_filename::v3::Response { content_disposition, @@ -321,7 +344,7 @@ pub(crate) async fn get_content_thumbnail_route( if let Some(FileMeta { content_type, file, - .. + content_disposition, }) = services() .media .get_thumbnail( @@ -335,7 +358,7 @@ pub(crate) async fn get_content_thumbnail_route( ) .await? { - let content_disposition = Some(String::from(content_disposition_type(&file, &content_type))); + let content_disposition = Some(make_content_disposition(&file, &content_type, content_disposition)); Ok(get_content_thumbnail::v3::Response { file, @@ -387,10 +410,11 @@ pub(crate) async fn get_content_thumbnail_route( ) .await?; - let content_disposition = Some(String::from(content_disposition_type( + let content_disposition = Some(make_content_disposition( &get_thumbnail_response.file, &get_thumbnail_response.content_type, - ))); + get_thumbnail_response.content_disposition, + )); Ok(get_content_thumbnail::v3::Response { file: get_thumbnail_response.file, @@ -456,12 +480,18 @@ async fn get_remote_content( ) .await?; + let content_disposition = Some(make_content_disposition( + &content_response.file, + &content_response.content_type, + content_response.content_disposition, + )); + services() .media .create( None, mxc.to_owned(), - Some("attachment"), + content_disposition.as_deref(), content_response.content_type.as_deref(), &content_response.file, ) @@ -470,7 +500,7 @@ async fn get_remote_content( Ok(get_content::v3::Response { file: content_response.file, content_type: content_response.content_type, - content_disposition: Some("attachment".to_owned()), + content_disposition, cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.to_owned()), }) @@ -707,24 +737,3 @@ fn url_preview_allowed(url_str: &str) -> bool { false } - -/// Returns a Content-Disposition of `attachment` or `inline`, depending on the -/// *parsed* contents of the file uploaded via format magic keys using `infer` -/// crate (basically libmagic without needing libmagic). -/// -/// This forbids trusting what the client or remote server says the file is from -/// their `Content-Type` and we try to detect it ourselves. Also returns -/// `attachment` if the Content-Type does not match what we detected. -/// -/// TODO: add a "strict" function for comparing the Content-Type with what we -/// detected: `file_type.mime_type() != content_type` -fn content_disposition_type(buf: &[u8], _content_type: &Option) -> &'static str { - let Some(file_type) = infer::get(buf) else { - return "attachment"; - }; - - match file_type.matcher_type() { - MatcherType::IMAGE | MatcherType::AUDIO | MatcherType::TEXT | MatcherType::VIDEO => "inline", - _ => "attachment", - } -} diff --git a/src/utils/content_disposition.rs b/src/utils/content_disposition.rs new file mode 100644 index 00000000..6df0e14f --- /dev/null +++ b/src/utils/content_disposition.rs @@ -0,0 +1,88 @@ +use infer::MatcherType; + +/// Returns a Content-Disposition of `attachment` or `inline`, depending on the +/// *parsed* contents of the file uploaded via format magic keys using `infer` +/// crate (basically libmagic without needing libmagic). +/// +/// This forbids trusting what the client or remote server says the file is from +/// their `Content-Type` and we try to detect it ourselves. Also returns +/// `attachment` if the Content-Type does not match what we detected. +/// +/// TODO: add a "strict" function for comparing the Content-Type with what we +/// detected: `file_type.mime_type() != content_type` +pub(crate) fn content_disposition_type(buf: &[u8], _content_type: &Option) -> &'static str { + let Some(file_type) = infer::get(buf) else { + return "attachment"; + }; + + match file_type.matcher_type() { + MatcherType::IMAGE | MatcherType::AUDIO | MatcherType::TEXT | MatcherType::VIDEO => "inline", + _ => "attachment", + } +} + +/// sanitises the file name for the Content-Disposition using +/// `sanitize_filename` crate +#[tracing::instrument] +pub(crate) fn sanitise_filename(filename: String) -> String { + let options = sanitize_filename::Options { + truncate: false, + ..Default::default() + }; + + sanitize_filename::sanitize_with_options(filename, options) +} + +/// creates the final Content-Disposition based on whether the filename exists +/// or not. +/// +/// if filename exists: `Content-Disposition: attachment/inline; +/// filename=filename.ext` else: `Content-Disposition: attachment/inline` +#[tracing::instrument(skip(file))] +pub(crate) fn make_content_disposition( + file: &[u8], content_type: &Option, content_disposition: Option, +) -> String { + let filename = content_disposition.map_or_else(String::new, |content_disposition| { + let (_, filename) = content_disposition + .split_once("filename=") + .unwrap_or(("", "")); + + if filename.is_empty() { + String::new() + } else { + sanitise_filename(filename.to_owned()) + } + }); + + if !filename.is_empty() { + // Content-Disposition: attachment/inline; filename=filename.ext + format!("{}; filename={}", content_disposition_type(file, content_type), filename) + } else { + // Content-Disposition: attachment/inline + String::from(content_disposition_type(file, content_type)) + } +} + +#[cfg(test)] +mod tests { + #[test] + fn string_sanitisation() { + const SAMPLE: &str = + "🏳️‍⚧️this\\r\\n įs \r\\n ä \\r\nstrïng 🥴that\n\r ../../../../../../../may be\r\n malicious🏳️‍⚧️"; + const SANITISED: &str = "🏳️‍⚧️thisrn įs n ä rstrïng 🥴that ..............may be malicious🏳️‍⚧️"; + + let options = sanitize_filename::Options { + windows: true, + truncate: true, + replacement: "", + }; + + // cargo test -- --nocapture + println!("{}", SAMPLE); + println!("{}", sanitize_filename::sanitize_with_options(SAMPLE, options.clone())); + println!("{:?}", SAMPLE); + println!("{:?}", sanitize_filename::sanitize_with_options(SAMPLE, options.clone())); + + assert_eq!(SANITISED, sanitize_filename::sanitize_with_options(SAMPLE, options.clone())); + } +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index dbcef82d..2ceb0ff5 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,4 +1,5 @@ pub(crate) mod clap; +pub(crate) mod content_disposition; pub(crate) mod debug; pub(crate) mod error; pub(crate) mod server_name; From 3504e6e724c43ff0db1ee0b244ba0d45b1ea6560 Mon Sep 17 00:00:00 2001 From: strawberry Date: Thu, 9 May 2024 09:40:56 -0400 Subject: [PATCH 0049/2291] fix broken reports Signed-off-by: strawberry --- src/api/client_server/report.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/client_server/report.rs b/src/api/client_server/report.rs index 185d7edb..3e6ba880 100644 --- a/src/api/client_server/report.rs +++ b/src/api/client_server/report.rs @@ -91,12 +91,12 @@ fn is_report_valid( )); } - if services() + if !services() .rooms .state_cache .room_members(&pdu.room_id) .filter_map(Result::ok) - .any(|user_id| user_id != *sender_user) + .any(|user_id| user_id == *sender_user) { return Err(Error::BadRequest( ErrorKind::NotFound, From adbe9268cebd7a2c06443ccbe3d75e6dbc13f1f6 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 8 May 2024 21:26:05 -0400 Subject: [PATCH 0050/2291] docs: add troubleshooting, maintenance, various improvements and fixes Signed-off-by: strawberry --- CONTRIBUTING.md | 2 + debian/README.md | 3 +- debian/conduwuit.service | 14 +++--- debian/postinst | 8 ++-- docs/SUMMARY.md | 10 ++-- docs/deploying/arch-linux.md | 8 ++++ docs/deploying/docker.md | 91 ++---------------------------------- docs/deploying/generic.md | 68 ++++++++------------------- docs/maintenance.md | 63 +++++++++++++++++++++++++ docs/troubleshooting.md | 62 ++++++++++++++++++++++++ docs/turn.md | 62 +++++++++++++++++------- nix/pkgs/book/default.nix | 1 + 12 files changed, 223 insertions(+), 169 deletions(-) create mode 100644 docs/deploying/arch-linux.md create mode 100644 docs/maintenance.md create mode 100644 docs/troubleshooting.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aff492f6..7e1e3924 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -52,6 +52,8 @@ conduwuit's website uses [`mdbook`][mdbook] and deployed via CI using GitHub Pag To build the documentation using Nix, run: `bin/nix-build-and-cache just .#book` +The output of the mdbook generation is in `result/`. mdbooks can be opened in your browser from the individual HTML files without any web server needed. + ### Inclusivity and Diversity All **MUST** code and write with inclusivity and diversity in mind. See the [following page by Google on writing inclusive code and documentation](https://developers.google.com/style/inclusive-documentation). diff --git a/debian/README.md b/debian/README.md index 95a43cc2..280f6585 100644 --- a/debian/README.md +++ b/debian/README.md @@ -1,5 +1,4 @@ -conduwuit for Debian -================== +# conduwuit for Debian Installation ------------ diff --git a/debian/conduwuit.service b/debian/conduwuit.service index a9cb09b7..46f4cbbf 100644 --- a/debian/conduwuit.service +++ b/debian/conduwuit.service @@ -1,13 +1,18 @@ [Unit] Description=conduwuit Matrix homeserver +Documentation=https://conduwuit.puppyirl.gay/ After=network-online.target [Service] DynamicUser=yes -User=_conduwuit -Group=_conduwuit +User=conduwuit +Group=conduwuit Type=notify +Environment="CONDUWUIT_CONFIG=/etc/conduwuit/conduwuit.toml" + +ExecStart=/usr/sbin/conduwuit + AmbientCapabilities= CapabilityBoundingSet= @@ -39,14 +44,11 @@ SystemCallArchitectures=native SystemCallFilter=@system-service @resources SystemCallFilter=~@clock @debug @module @mount @reboot @swap @cpu-emulation @obsolete @timer @chown @setuid @privileged @keyring @ipc SystemCallErrorNumber=EPERM -StateDirectory=matrix-conduit +StateDirectory=conduwuit RuntimeDirectory=conduit RuntimeDirectoryMode=0750 -Environment="CONDUIT_CONFIG=/etc/conduwuit/conduwuit.toml" - -ExecStart=/usr/sbin/conduwuit Restart=on-failure RestartSec=5 diff --git a/debian/postinst b/debian/postinst index a91e136c..551e8cfd 100644 --- a/debian/postinst +++ b/debian/postinst @@ -7,21 +7,21 @@ CONDUWUIT_DATABASE_PATH=/var/lib/conduwuit/ case "$1" in configure) - # Create the `_conduwuit` user if it does not exist yet. - if ! getent passwd _conduwuit > /dev/null ; then + # Create the `conduwuit` user if it does not exist yet. + if ! getent passwd conduwuit > /dev/null ; then echo 'Adding system user for the conduwuit Matrix homeserver' 1>&2 adduser --system --group --quiet \ --home "$CONDUWUIT_DATABASE_PATH" \ --disabled-login \ --shell "/usr/sbin/nologin" \ --force-badname \ - _conduwuit + conduwuit fi # Create the database path if it does not exist yet and fix up ownership # and permissions. mkdir -p "$CONDUWUIT_DATABASE_PATH" - chown _conduwuit:_conduwuit -R "$CONDUWUIT_DATABASE_PATH" + chown conduwuit:conduwuit -R "$CONDUWUIT_DATABASE_PATH" chmod 700 "$CONDUWUIT_DATABASE_PATH" ;; esac diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 937a5e2c..e4577959 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -2,15 +2,17 @@ - [Introduction](introduction.md) - [Differences from upstream Conduit](differences.md) - - [Example configuration](configuration.md) - [Deploying](deploying.md) - [Generic](deploying/generic.md) - - [Debian](deploying/debian.md) - - [Docker](deploying/docker.md) - [NixOS](deploying/nixos.md) + - [Docker](deploying/docker.md) + - [Arch Linux](deploying/arch-linux.md) + - [Debian](deploying/debian.md) - [TURN](turn.md) - [Appservices](appservices.md) +- [Maintenance](maintenance.md) +- [Troubleshooting](troubleshooting.md) - [Development](development.md) - - [Testing](development/testing.md) - [Contributing](contributing.md) + - [Testing](development/testing.md) diff --git a/docs/deploying/arch-linux.md b/docs/deploying/arch-linux.md new file mode 100644 index 00000000..ec9fe25c --- /dev/null +++ b/docs/deploying/arch-linux.md @@ -0,0 +1,8 @@ +# conduwuit for Arch Linux + +Currently conduwuit is only on the Arch User Repository (AUR). + +The conduwuit AUR packages are community maintained and are not maintained by conduwuit development team, but the AUR package maintainers are in the Matrix room. Please attempt to verify your AUR package's PKGBUILD file looks fine before asking for support. + +- [conduwuit](https://aur.archlinux.org/packages/conduwuit) - latest tagged conduwuit +- [conduwuit-git](https://aur.archlinux.org/packages/conduwuit-git) - latest git conduwuit from `main` branch diff --git a/docs/deploying/docker.md b/docs/deploying/docker.md index 2e0f5ba0..e6826768 100644 --- a/docs/deploying/docker.md +++ b/docs/deploying/docker.md @@ -51,9 +51,9 @@ docker run -d -p 8448:6167 \ or you can use [docker compose](#docker-compose). -The `-d` flag lets the container run in detached mode. You may supply an optional `conduwuit.toml` config file, an example can be found [here](../configuration.md). +The `-d` flag lets the container run in detached mode. You may supply an optional `conduwuit.toml` config file, the example config can be found [here](../configuration.md). You can pass in different env vars to change config values on the fly. You can even configure conduwuit completely by using env vars. For an overview of possible -values, please take a look at the `docker-compose.yml` file. +values, please take a look at the [`docker-compose.yml`](docker-compose.yml) file. If you just want to test conduwuit for a short time, you can use the `--rm` flag, which will clean up everything related to your container after you stop it. @@ -107,92 +107,7 @@ either expose ports `443` and `8448` or serve two endpoints `.well-known/matrix/ With the service `well-known` we use a single `nginx` container that will serve those two files. -So...step by step: - -1. Copy [`docker-compose.for-traefik.yml`](docker-compose.for-traefik.yml) (or -[`docker-compose.with-traefik.yml`](docker-compose.with-traefik.yml)) and [`docker-compose.override.yml`](docker-compose.override.yml) from the repository and remove `.for-traefik` (or `.with-traefik`) from the filename. -2. Open both files and modify/adjust them to your needs. Meaning, change the `CONDUIT_SERVER_NAME` and the volume host mappings according to your needs. -3. Create the `conduwuit.toml` config file, an example can be found [here](../configuration.md), or set `CONDUIT_CONFIG=""` and configure conduwuit per env vars. -4. Uncomment the `element-web` service if you want to host your own Element Web Client and create a `element_config.json`. -5. Create the files needed by the `well-known` service. - - - `./nginx/matrix.conf` (relative to the compose file, you can change this, but then also need to change the volume mapping) - - ```nginx - server { - server_name .; - listen 80 default_server; - - location /.well-known/matrix/server { - return 200 '{"m.server": ".:443"}'; - types { } default_type "application/json; charset=utf-8"; - } - - location /.well-known/matrix/client { - return 200 '{"m.homeserver": {"base_url": "https://."}}'; - types { } default_type "application/json; charset=utf-8"; - add_header "Access-Control-Allow-Origin" *; - } - - location / { - return 404; - } - } - ``` - -6. Run `docker compose up -d` -7. Connect to your homeserver with your preferred client and create a user. You should do this immediately after starting Conduit, because the first created user is the admin. - - - ## Voice communication -In order to make or receive calls, a TURN server is required. conduwuit suggests using [Coturn](https://github.com/coturn/coturn) for this purpose, which is also available as a Docker image. Before proceeding with the software installation, it is essential to have the necessary configurations in place. - -### Configuration - -Create a configuration file called `coturn.conf` containing: - -```conf -use-auth-secret -static-auth-secret= -realm= -``` -A common way to generate a suitable alphanumeric secret key is by using `pwgen -s 64 1`. - -These same values need to be set in conduwuit. You can either modify conduwuit.toml to include these lines: -``` -turn_uris = ["turn:?transport=udp", "turn:?transport=tcp"] -turn_secret = "" -``` -or append the following to the docker environment variables dependig on which configuration method you used earlier: -```yml -CONDUIT_TURN_URIS: '["turn:?transport=udp", "turn:?transport=tcp"]' -CONDUIT_TURN_SECRET: "" -``` -Restart Conduit to apply these changes. - -### Run -Run the [Coturn](https://hub.docker.com/r/coturn/coturn) image using -```bash -docker run -d --network=host -v $(pwd)/coturn.conf:/etc/coturn/turnserver.conf coturn/coturn -``` - -or docker-compose. For the latter, paste the following section into a file called `docker-compose.yml` -and run `docker compose up -d` in the same directory. - -```yml -version: 3 -services: - turn: - container_name: coturn-server - image: docker.io/coturn/coturn - restart: unless-stopped - network_mode: "host" - volumes: - - ./coturn.conf:/etc/coturn/turnserver.conf -``` - -To understand why the host networking mode is used and explore alternative configuration options, please visit the following link: https://github.com/coturn/coturn/blob/master/docker/coturn/README.md. -For security recommendations see Synapse's [Coturn documentation](https://github.com/matrix-org/synapse/blob/develop/docs/setup/turn/coturn.md#configuration). +See the [TURN](../turn.md) page. diff --git a/docs/deploying/generic.md b/docs/deploying/generic.md index dc15f34e..abc8cc41 100644 --- a/docs/deploying/generic.md +++ b/docs/deploying/generic.md @@ -1,7 +1,5 @@ # Generic deployment documentation -### Please note that this documentation is not fully representative of conduwuit at the moment. Assume majority of it is outdated. - > ## Getting help > > If you run into any problems while setting up conduwuit, ask us @@ -13,23 +11,16 @@ You may simply download the binary that fits your machine. Run `uname -m` to see Prebuilt binaries can be downloaded from the latest tagged release [here](https://github.com/girlbossceo/conduwuit/releases/latest). -Alternatively, you may compile the binary yourself. First, install any dependencies: +The latest tagged release also includes the Debian packages. -```bash -# Debian -$ sudo apt install libclang-dev build-essential +Alternatively, you may compile the binary yourself. We recommend using [Lix](https://lix.systems) to build conduwuit as this has the most guaranteed +reproducibiltiy and easiest to get a build environment and output going. -# RHEL -$ sudo dnf install clang -``` -Then, `cd` into the source tree of conduwuit and run: -```bash -$ cargo build --release -``` +Otherwise, follow standard Rust project build guides (installing git and cloning the repo, getting the Rust toolchain via rustup, installing LLVM toolchain + libclang, installing liburing for io_uring and RocksDB, etc). ## Adding a conduwuit user -While conduwuit can run as any user it is usually better to use dedicated users for different services. This also allows +While conduwuit can run as any user it is better to use dedicated users for different services. This also allows you to make sure that the file permissions are correctly set up. In Debian or RHEL, you can use this command to create a conduwuit user: @@ -38,6 +29,12 @@ In Debian or RHEL, you can use this command to create a conduwuit user: sudo adduser --system conduwuit --group --disabled-login --no-create-home ``` +For distros without `adduser`: + +```bash +sudo useradd -r --shell /usr/bin/nologin --no-create-home conduwuit +``` + ## Forwarding ports in the firewall or the router conduwuit uses the ports 443 and 8448 both of which need to be open in the firewall. @@ -46,45 +43,18 @@ If conduwuit runs behind a router or in a container and has a different public I ## Setting up a systemd service -Now we'll set up a systemd service for conduwuit, so it's easy to start/stop conduwuit and set it to autostart when your -server reboots. Simply paste the default systemd service you can find below into -`/etc/systemd/system/conduwuit.service`. - -```systemd -[Unit] -Description=conduwuit Matrix Server -After=network.target - -[Service] -Environment="CONDUWUIT_CONFIG=/etc/conduwuit/conduwuit.toml" -User=conduwuit -Group=conduwuit -RuntimeDirectory=conduwuit -RuntimeDirectoryMode=0750 -Restart=always -ExecStart=/usr/local/bin/conduwuit - -[Install] -WantedBy=multi-user.target -``` - -Finally, run - -```bash -$ sudo systemctl daemon-reload -``` +The systemd unit for conduwuit can be found [here](../../debian/conduwuit.service). You may need to change the `ExecStart=` path to where you placed the conduwuit binary. ## Creating the conduwuit configuration file -Now we need to create the conduwuit's config file in `/etc/conduwuit/conduwuit.toml`. Paste this in **and take a moment -to read it. You need to change at least the server name.** -RocksDB (`rocksdb`) is the only supported database backend. SQLite only exists for historical reasons and is not recommended. Any performance issues, storage issues, database issues, etc will not be assisted if using SQLite and you will be asked to migrate to RocksDB first. +Now we need to create the conduwuit's config file in `/etc/conduwuit/conduwuit.toml`. The example config can be found at [conduwuit-example.toml](../configuration.md).**Please take a moment to read it. You need to change at least the server name.** -See the following example config at [conduwuit-example.toml](../configuration.md) +RocksDB (`rocksdb`) is the only supported database backend. SQLite only exists for historical reasons and is not recommended. Any performance issues, storage issues, database issues, etc will not be assisted if using SQLite and you will be asked to migrate to RocksDB first. ## Setting the correct file permissions -As we are using a conduwuit specific user we need to allow it to read the config. To do that you can run this command on +If you are using a dedicated user for conduwuit, you will need to allow it to read the config. To do that you can run this command on + Debian or RHEL: ```bash @@ -102,7 +72,7 @@ sudo chmod 700 /var/lib/conduwuit/ ## Setting up the Reverse Proxy -Refer to the documentation or various guides online of your chosen reverse proxy software. A Caddy example will be provided as this is the recommended reverse proxy for new users and is very trivial. +Refer to the documentation or various guides online of your chosen reverse proxy software. A [Caddy](https://caddyserver.com/) example will be provided as this is the recommended reverse proxy for new users and is very trivial to use (handles TLS, reverse proxy headers, etc transparently with proper defaults). ### Caddy @@ -118,10 +88,10 @@ your.server.name, your.server.name:8448 { } ``` -That's it! Just start or enable the service and you're set. +That's it! Just start and enable the service and you're set. ```bash -$ sudo systemctl enable caddy +$ sudo systemctl enable --now caddy ``` ## You're done! diff --git a/docs/maintenance.md b/docs/maintenance.md new file mode 100644 index 00000000..407340bf --- /dev/null +++ b/docs/maintenance.md @@ -0,0 +1,63 @@ +# Maintaining your conduwuit setup + +## Moderation + +conduwuit has moderation through admin room commands. "binary commands" (medium priority) and an admin API (low priority) is planned. Some moderation-related config options are available in the example config such as "global ACLs" and blocking media requests to certain servers. See the example config for the moderation config options under the "Moderation / Privacy / Security" section. + +conduwuit has moderation admin commands for: +- managing room aliases (`!admin rooms alias`) +- managing room directory (`!admin rooms directory`) +- managing room banning/blocking and user removal (`!admin rooms moderation`) +- managing user accounts (`!admin users`) +- fetching `/.well-known/matrix/support` from servers (`!admin federation`) +- blocking incoming federation for certain rooms (not the same as room banning) (`!admin federation`) +- deleting media (see [the media section](#media)) + +Any commands with `-list` in them will require a codeblock in the message with each object being newline delimited. An example of doing this is: + +```` +!admin rooms moderation ban-list-of-rooms +``` +!roomid1:server.name +!roomid2:server.name +!roomid3:server.name +``` +```` + +## Database + +If using RocksDB, there's very little you need to do. Compaction is ran automatically based on various defined thresholds tuned for conduwuit to be high performance with the least I/O amplifcation or overhead. Manually running compaction is not recommended, or compaction via a timer. RocksDB is built with io_uring support via liburing for async read I/O. + +Some RocksDB settings can be adjusted such as the compression method chosen. See the RocksDB section in the [example config](configuration.md). btrfs users may benefit from disabling compression on RocksDB if CoW is in use. + +RocksDB troubleshooting can be found [in the RocksDB section of troubleshooting](troubleshooting.md). + +## Backups + +Currently only RocksDB supports online backups. If you'd like to backup your database online without any downtime, see the `!admin server` command for the backup commands and the `database_backup_path` config options in the example config. Please note that the format of the database backup is not the exact same. This is unfortunately a bad design choice by Facebook as we are using the database backup engine API from RocksDB, however the data is still there and can still be joined together. + +To restore a backup from an online RocksDB backup: +- shutdown conduwuit +- create a new directory for merging together the data +- in the online backup created, copy all `.sst` files in `$DATABASE_BACKUP_PATH/shared_checksum` to your new directory +- trim all the strings so instead of `######_sxxxxxxxxx.sst`, it reads `######.sst`. A way of doing this with sed and bash is `for file in *.sst; do mv "$file" "$(echo "$file" | sed 's/_s.*/.sst/')"; done` +- copy all the files in `$DATABASE_BACKUP_PATH/1` to your new directory +- set your `database_path` config option to your new directory, or replace your old one with the new one you crafted +- start up conduwuit again and it should open as normal + +If you'd like to do an offline backup, shutdown conduwuit and copy your `database_path` directory elsewhere. This can be restored with no modifications needed. + +Backing up media is also just copying the `media/` directory from your database directory. + +## Media + +Media still needs various work, however conduwuit implements media deletion via: +- MXC URI +- Delete list of MXC URIs +- Delete remote media in the past `N` seconds/minutes + +See the `!admin media` command for further information. All media in conduwuit is stored at `$DATABASE_DIR/media`. This will be configurable soon. + +If you are finding yourself needing extensive granular control over media, we recommend looking into [Matrix Media Repo](https://github.com/t2bot/matrix-media-repo). conduwuit intends to implement various utilities for media, but MMR is dedicated to extensive media management. + +Built-in S3 support is also planned, but for now using a "S3 filesystem" on `media/` works. conduwuit also sends a `Cache-Control` header of 1 year and immutable for all media requests (download and thumbnail) to reduce unnecessary media requests from browsers. diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md new file mode 100644 index 00000000..6f8dc1c2 --- /dev/null +++ b/docs/troubleshooting.md @@ -0,0 +1,62 @@ +# Troubleshooting conduwuit + +> ## Docker users ⚠️ +> +> Docker is extremely UX unfriendly. Because of this, a ton of issues or support is actually Docker support, not conduwuit support. We also cannot document the ever-growing list of Docker issues here. +> +> If you intend on asking for support and you are using Docker, **PLEASE** triple validate your issues are **NOT** because you have a misconfiguration in your Docker setup. +> +> If there are things like Compose file issues or Dockerhub image issues, those can still be mentioned as long as they're something we can fix. + +## Rocksdb / database issues + +#### Direct IO + +Some filesystems may not like RocksDB using [Direct IO](https://github.com/facebook/rocksdb/wiki/Direct-IO). Direct IO is for non-buffered I/O which improves conduwuit performance, but at least FUSE is a filesystem potentially known to not like this. See the [example config](configuration.md) for disabling it if needed. Issues from Direct IO on unsupported filesystems are usually shown as startup errors. + +#### Database corruption + +If your database is corrupted and is failing to start (e.g. checksum mismatch), it may be recoverable but careful steps must be taken, and there is no guarantee it may be recoverable. + +RocksDB has the following recovery modes: + +- `TolerateCorruptedTailRecords` +- `AbsoluteConsistency` +- `PointInTime` +- `SkipAnyCorruptedRecord` + +By default, conduwuit uses `TolerateCorruptedTailRecords` as generally these may be due to bad federation and we can re-fetch the correct data over federation. The RocksDB default is `PointInTime` which will attempt to restore a "snapshot" of the data when it was last known to be good. This data can be either a few seconds old, or multiple minutes prior. `PointInTime` may not be suitable for default usage due to clients and servers possibly not being able to handle sudden "backwards time travels", and `AbsoluteConsistency` may be too strict. + +`AbsoluteConsistency` will fail to start the database if any sign of corruption is detected. `SkipAnyCorruptedRecord` will skip all forms of corruption unless it forbids the database from opening (e.g. too severe). Usage of `SkipAnyCorruptedRecord` voids any support as this may cause more damage and/or leave your database in a permanently inconsistent state, but it may do something if `PointInTime` does not work as a last ditch effort. + +With this in mind: +- First start conduwuit with the `PointInTime` recovery method. See the [example config](configuration.md) for how to do this using `rocksdb_recovery_mode` +- If your database successfully opens, clients are recommended to clear their client cache to account for the rollback +- Leave your conduwuit running in `PointInTime` for at least 30-60 minutes so as much possible corruption is restored +- If all goes will, you should be able to restore back to using `TolerateCorruptedTailRecords` and you have successfully recovered your database + +## Media + +#### "File name too long" + +If you are running into the "file name is too long" OS error for media requests, your filesystem cannot handle file name lengths >=255 characters. This is unfortuntely due to Conduit (upstream) using base64 for file name keys which is very problematic for some filesystems as the base64 input is untrusted and long file names or specific inputs can cause this. If you would like to avoid this, you may build conduwuit yourself with the `sha256_media` feature. **This will lose database compatibility with upstream**. + +## Debugging + +Note that users should not really be debugging things. If you find yourself debugging and find the issue, please let us know and/or how we can fix it. Various debug commands can be found in `!admin debug`. + +#### Debug/Trace log level + +conduwuit builds without debug or trace log levels by default for at least performance reasons. This may change in the future and/or binaries providing such configurations may be provided. If you need to access debug/trace log levels, you will need to build without the `release_max_log_level` feature. + +#### Changing log level dynamically + +conduwuit supports changing the tracing log environment filter on-the-fly using the admin command `!admin debug change-log-level`. This accepts a string **without quotes** the same format as the `log` config option. + +#### Pinging servers + +conduwuit can ping other servers using `!admin debug ping`. This takes a server name and goes through the server discovery process and queries `/_matrix/federation/v1/version`. Errors are outputted. + +#### Allocator memory stats + +If using jemalloc (for now) and built with jemallocator's `stats` feature, you can see conduwuit's jemalloc memory stats by using `!admin debug memory-stats` diff --git a/docs/turn.md b/docs/turn.md index 63c1e99f..3b143d80 100644 --- a/docs/turn.md +++ b/docs/turn.md @@ -1,25 +1,55 @@ # Setting up TURN/STURN -## General instructions +In order to make or receive calls, a TURN server is required. conduwuit suggests using [Coturn](https://github.com/coturn/coturn) for this purpose, which is also available as a Docker image. -* It is assumed you have a [Coturn server](https://github.com/coturn/coturn) up and running. See [Synapse reference implementation](https://github.com/matrix-org/synapse/blob/develop/docs/turn-howto.md). +### Configuration -## Edit/Add a few settings to your existing conduit.toml +Create a configuration file called `coturn.conf` containing: + +```conf +use-auth-secret +static-auth-secret= +realm= +``` +A common way to generate a suitable alphanumeric secret key is by using `pwgen -s 64 1`. + +These same values need to be set in conduwuit. You can either modify conduwuit.toml to include these lines: ``` -# Refer to your Coturn settings. -# `your.turn.url` has to match the REALM setting of your Coturn as well as `transport`. -turn_uris = ["turn:your.turn.url?transport=udp", "turn:your.turn.url?transport=tcp"] - -# static-auth-secret of your turnserver -turn_secret = "ADD SECRET HERE" - -# If you have your TURN server configured to use a username and password -# you can provide these information too. In this case comment out `turn_secret above`! -#turn_username = "" -#turn_password = "" +turn_uris = ["turn:?transport=udp", "turn:?transport=tcp"] +turn_secret = "" ``` -## Apply settings +or append the following to the docker environment variables dependig on which configuration method you used earlier: -Restart Conduit. \ No newline at end of file +```yml +CONDUIT_TURN_URIS: '["turn:?transport=udp", "turn:?transport=tcp"]' +CONDUIT_TURN_SECRET: "" +``` + +Restart conduwuit to apply these changes. + +### Run +Run the [Coturn](https://hub.docker.com/r/coturn/coturn) image using +```bash +docker run -d --network=host -v $(pwd)/coturn.conf:/etc/coturn/turnserver.conf coturn/coturn +``` + +or docker-compose. For the latter, paste the following section into a file called `docker-compose.yml` +and run `docker compose up -d` in the same directory. + +```yml +version: 3 +services: + turn: + container_name: coturn-server + image: docker.io/coturn/coturn + restart: unless-stopped + network_mode: "host" + volumes: + - ./coturn.conf:/etc/coturn/turnserver.conf +``` + +To understand why the host networking mode is used and explore alternative configuration options, please visit [Coturn's Docker documentation](https://github.com/coturn/coturn/blob/master/docker/coturn/README.md). + +For security recommendations see Synapse's [Coturn documentation](https://element-hq.github.io/synapse/latest/turn-howto.html). diff --git a/nix/pkgs/book/default.nix b/nix/pkgs/book/default.nix index a3e9e28f..23c6e783 100644 --- a/nix/pkgs/book/default.nix +++ b/nix/pkgs/book/default.nix @@ -14,6 +14,7 @@ stdenv.mkDerivation { include = [ "book.toml" "conduwuit-example.toml" + "CONTRIBUTING.md" "README.md" "debian/README.md" "docs" From dfa01541b3883f330ba00d71dcf4fb469cb6adb0 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 8 May 2024 21:37:07 -0400 Subject: [PATCH 0051/2291] docs: transfem.dev has rules Signed-off-by: strawberry --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index d00ce5a4..d8dfc8b6 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ friends or company. An official conduwuit server ran by me is available at transfem.dev ([element.transfem.dev](https://element.transfem.dev) / [cinny.transfem.dev](https://cinny.transfem.dev)) +transfem.dev is a public homeserver that can be used, it is not a "test only homeserver". This means there are rules, so please read the rules: [https://transfem.dev/homeserver_rules.txt](https://transfem.dev/homeserver_rules.txt) + +transfem.dev is also listed at [servers.joinmatrix.org](https://servers.joinmatrix.org/) + #### What is the current status? conduwuit is a hard fork of Conduit which is in beta, meaning you can join and participate in most From 484e7d1d2a9380d9b5866c34f7f57cb255ed2417 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 8 May 2024 21:39:29 -0400 Subject: [PATCH 0052/2291] docs: add my selfhosted forgejo mirror Signed-off-by: strawberry --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d8dfc8b6..92648bf8 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Both, but I prefer conduwuit. - GitHub: - GitLab: +- git.girlcock.ceo: - git.gay: - Codeberg: - sourcehut: From 6de9f52d5abcf5915be97996ec00d9d3c2aac006 Mon Sep 17 00:00:00 2001 From: strawberry Date: Thu, 9 May 2024 02:08:28 -0400 Subject: [PATCH 0053/2291] docs: update differences.md Signed-off-by: strawberry --- CONTRIBUTING.md | 2 +- docs/differences.md | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7e1e3924..2a32c0ec 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,7 +70,7 @@ Rust's default style and standards with regards to [function names, variable nam ### Creating pull requests -Please try to keep contributions to the GitHub. While the mirrors of conduwuit allow for pull/merge requests, there is no guarantee I will see them in a timely manner. +Please try to keep contributions to the GitHub. While the mirrors of conduwuit allow for pull/merge requests, there is no guarantee I will see them in a timely manner. Additionally, please mark WIP or unfinished or incomplete PRs as drafts. This prevents me from having to ping once in a while to double check the status of it, especially when the CI completed successfully and everything so it *looks* done. If you open a pull request on one of the mirrors, it is your responsibility to inform me about its existence. In the future I may try to solve this with more repo bots in the conduwuit Matrix room. There is no mailing list or email-patch support on the sr.ht mirror, but if you'd like to email me a git patch you can do so at `strawberry@puppygock.gay`. diff --git a/docs/differences.md b/docs/differences.md index d7e1058b..5135c529 100644 --- a/docs/differences.md +++ b/docs/differences.md @@ -6,7 +6,7 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence! ## Performance: - Concurrency support for key fetching for faster remote room joins and room joins that will error less frequently -- Send `Cache-Control` response header with `immutable` and 1 year cache length for all media requests to instruct clients to cache media, and reduce server load from media requests that could be otherwise cached +- Send `Cache-Control` response header with `immutable` and 1 year cache length for all media requests (download and thumbnail) to instruct clients to cache media, and reduce server load from media requests that could be otherwise cached - Add feature flags and config options to enable/build with zstd, brotli, and/or gzip HTTP body compression (response and request) - Eliminate all usage of the thread-blocking `getaddrinfo(3)` call upon DNS queries, significantly improving federation latency/ping and cache DNS results (NXDOMAINs, successful queries, etc) using hickory-dns / hickory-resolver - Vastly improve RocksDB default settings to use new features that help with performance significantly, uses settings tailored to SSDs, various ways to tweak RocksDB, and a conduwuit setting to tell RocksDB to use settings that are tailored to HDDs or slow spinning rust storage or buggy filesystems. @@ -22,6 +22,7 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence! - Add config options for RocksDB compression and bottommost compression, including choosing the algorithm and compression level - Use [loole](https://github.com/mahdi-shojaee/loole) MPSC channels instead of tokio MPSC channels for huge performance boosts in sending channels (mainly relevant for federation) and presence channels - Use `tracing`/`log`'s `release_max_level_info` feature to improve performance, build speeds, binary size, and CPU usage in release builds by avoid compiling debug/trace log level macros that users will generally never use (can be disabled with a build-time feature flag) +- Enable RocksDB async read I/O via `io_uring` by default ## General Fixes: @@ -35,7 +36,7 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence! - Increased graceful shutdown timeout from a low 60 seconds to 180 seconds to avoid killing connections and let the remaining ones finish processing - Return joined member count of rooms for push rules/conditions instead of a hardcoded value of 10 - Make `CONDUIT_CONFIG` optional, relevant for container users that configure only by environment variables and no longer need to set `CONDUIT_CONFIG` to an empty string. -- Allow HEAD HTTP requests in CORS for clients (despite not being explicity mentioned in Matrix spec, HTTP spec says all HEAD requests need to behave the same as GET requests, Synapse supports HEAD requests) +- Allow HEAD and PATCH (MSC4138) HTTP requests in CORS for clients (despite not being explicity mentioned in Matrix spec, HTTP spec says all HEAD requests need to behave the same as GET requests, Synapse supports HEAD requests) - Resolve and remove some "features" from upstream that result in concurrency hazards, exponential backoff issues, or arbitrary performance limiters - Find more servers for outbound federation `/hierarchy` requests instead of just the room ID server name - Support for suggesting servers to join through at `/_matrix/client/v3/directory/room/{roomAlias}` @@ -55,6 +56,7 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence! - On new public room creations, only allow moderators to send `m.call.invite`, `org.matrix.msc3401.call`, and `org.matrix.msc3401.call.member` events - Add support for a "global ACLs" feature (`forbidden_remote_server_names`) that blocks inbound remote room invites, room joins by room ID on server name, room joins by room alias on server name, incoming federated joins, and incoming federated room directory requests. This is very helpful for blocking servers that are purely toxic/bad and serve no value in allowing our users to suffer from things like room invite spam or such. Please note that this is not a substitute for room ACLs. - Add support for a config option to forbid our local users from sending federated room directory requests for (`forbidden_remote_room_directory_server_names`). Similar to above, useful for blocking servers that help prevent our users from wandering into bad areas of Matrix via room directories of those malicious servers. +- Add config option for auto remediating/deactivating local non-admin users who attempt to join bad/forbidden rooms (`auto_deactivate_banned_room_attempts`) ## Privacy/Security: @@ -68,6 +70,9 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence! - Config option to disable incoming and/or outgoing remote read receipts - Config option to disable incoming and/or outgoing remote typing indicators - Config option to disable incoming, outgoing, and/or local presence +- Sanitise file names for the `Content-Disposition` header for all media requests (thumbnails, downloads, uploads) +- Return `inline` or `attachment` based on the detected file MIME type for the `Content-Disposition` and only allow images/videos/text/audio to be `inline` +- Send secure default HTTP headers such as a strong restrictive CSP, deny iframes, disable `X-XSS-Protection`, disable interest cohort in `Permission-Policy`, etc to mitigate any potential attack surface such as from untrusted media ## Administration/Logging: @@ -81,7 +86,7 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence! - Warn on unknown config options specified - Add `/_conduwuit/server_version` route to return the version of conduwuit without relying on the federation API `/_matrix/federation/v1/version` - Add configurable RocksDB recovery modes to aid in recovering corrupted RocksDB databases -- Support config options via `CONDUWUIT_` prefix +- Support config options via `CONDUWUIT_` prefix and accessing non-global struct config options with the `__` split (e.g. `CONDUWUIT_WELL_KNOWN__SERVER`) - Add support for listening on multiple TCP ports - Disable update check by default as it's not useful for conduwuit - **Opt-in** Sentry.io telemetry and metrics, mainly used for crash reporting @@ -89,7 +94,8 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence! ## Maintenance/Stability: - GitLab CI ported to GitHub Actions -- Repo is mirrored to GitHub, GitLab, git.gay, sourcehut, and Codeberg (see README.md for their links) +- Repo is mirrored to GitHub, GitLab, git.gay, git.girlcock.ceo, sourcehut, and Codeberg (see README.md for their links) +- Docker container images published to GitLab Container Registry, GitHub Container Registry, and Dockerhub - Extensively revamp the example config to be extremely helpful and useful to both new users and power users - Fixed every single clippy (default lints) and rustc warnings, including some that were performance related or potential safety issues / unsoundness - Add a **lot** of other clippy and rustc lints and a rustfmt.toml file @@ -146,6 +152,7 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence! - Implement running and diff'ing Complement results in CI - Interest in supporting other operating systems such as macOS, BSDs, and Windows, and getting them added into CI and doing builds for them - Add config option for disabling RocksDB Direct IO if needed +- Add various documentation on maintaining conduwuit, using RocksDB online backups, some troubleshooting, using admin commands, etc - (Developers): Add support for tokio-console - (Developers): Add support for tracing flame graphs - Add `release-debuginfo` Cargo build profile From 653ec3799e758abbac4d34993a221a0f65a5244c Mon Sep 17 00:00:00 2001 From: strawberry Date: Thu, 9 May 2024 12:20:55 -0400 Subject: [PATCH 0054/2291] bump various deps Signed-off-by: strawberry --- Cargo.lock | 296 ++++++++++++++++--------------- Cargo.toml | 10 +- src/utils/content_disposition.rs | 2 +- 3 files changed, 162 insertions(+), 146 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6944d8d1..b2ae344f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,15 +61,15 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anyhow" -version = "1.0.82" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" [[package]] name = "arc-swap" @@ -103,9 +103,9 @@ checksum = "5f093eed78becd229346bf859eec0aa4dd7ddde0757287b2b4107a1f09c80002" [[package]] name = "async-compression" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e9eabd7a98fe442131a17c316bd9349c43695e49e730c3c8e12cfb5f4da2693" +checksum = "9c90a406b4495d129f00461241616194cb8a032c8d1c53c657f0961d5f8e0498" dependencies = [ "brotli", "flate2", @@ -136,7 +136,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -147,7 +147,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "axum" @@ -375,7 +375,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -410,9 +410,9 @@ dependencies = [ [[package]] name = "brotli" -version = "5.0.0" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19483b140a7ac7174d34b5a581b406c64f84da5409d3e09cf4fff604f9270e67" +checksum = "74f7971dbd9326d58187408ab83117d8ac1bb9c17b085fdacd1cf2f598719b6b" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -472,9 +472,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.96" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" dependencies = [ "jobserver", "libc", @@ -551,7 +551,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -776,7 +776,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -880,7 +880,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -1048,7 +1048,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -1092,9 +1092,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "js-sys", @@ -1359,16 +1359,16 @@ dependencies = [ [[package]] name = "html5ever" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bea68cab48b8459f17cf1c944c67ddc572d272d9f2b274140f223ecb1da4a3b7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ "log", "mac", "markup5ever", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.61", ] [[package]] @@ -1609,9 +1609,9 @@ dependencies = [ [[package]] name = "infer" -version = "0.3.7" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "865e8a58ae8e24d2c4412c31344afa1d302a3740ad67528c10f50d6876cdcf55" +checksum = "cb33622da908807a06f9513c19b3c1ad50fab3e4137d82a78107d502075aa199" [[package]] name = "inlinable_string" @@ -1893,9 +1893,9 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" [[package]] name = "markup5ever" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" dependencies = [ "log", "phf", @@ -1907,9 +1907,9 @@ dependencies = [ [[package]] name = "markup5ever_rcdom" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9521dd6750f8e80ee6c53d65e2e4656d7de37064f3a7a5d2d11d05df93839c2" +checksum = "edaa21ab3701bfee5099ade5f7e1f84553fd19228cf332f13cd6e964bf59be18" dependencies = [ "html5ever", "markup5ever", @@ -2051,9 +2051,9 @@ dependencies = [ [[package]] name = "num" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3135b08af27d103b0a51f2ae0f8632117b7b185ccf931445affa8df530576a41" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" dependencies = [ "num-bigint", "num-complex", @@ -2065,20 +2065,19 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ - "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-complex" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "num-traits", ] @@ -2100,9 +2099,9 @@ dependencies = [ [[package]] name = "num-iter" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" dependencies = [ "autocfg", "num-integer", @@ -2111,11 +2110,10 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ - "autocfg", "num-bigint", "num-integer", "num-traits", @@ -2123,9 +2121,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -2295,9 +2293,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pear" @@ -2319,7 +2317,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -2340,21 +2338,21 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "phf" -version = "0.10.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ - "phf_shared", + "phf_shared 0.11.2", ] [[package]] name = "phf_codegen" -version = "0.10.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" dependencies = [ - "phf_generator", - "phf_shared", + "phf_generator 0.11.2", + "phf_shared 0.11.2", ] [[package]] @@ -2363,7 +2361,17 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" dependencies = [ - "phf_shared", + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", "rand", ] @@ -2376,6 +2384,15 @@ dependencies = [ "siphasher", ] +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project" version = "1.1.5" @@ -2393,7 +2410,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -2472,9 +2489,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] @@ -2487,7 +2504,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", "version_check", "yansi", ] @@ -2504,15 +2521,15 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" +checksum = "9554e3ab233f0a932403704f1a1d08c30d5ccd931adfdfa1e8b5a19b52c1d55a" dependencies = [ "anyhow", "itertools", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -2705,8 +2722,8 @@ dependencies = [ [[package]] name = "ruma" -version = "0.9.4" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.10.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "assign", "js_int", @@ -2725,8 +2742,8 @@ dependencies = [ [[package]] name = "ruma-appservice-api" -version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.10.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "js_int", "ruma-common", @@ -2737,8 +2754,8 @@ dependencies = [ [[package]] name = "ruma-client-api" -version = "0.17.4" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.18.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "as_variant", "assign", @@ -2759,8 +2776,8 @@ dependencies = [ [[package]] name = "ruma-common" -version = "0.12.1" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.13.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "as_variant", "base64 0.22.1", @@ -2789,8 +2806,8 @@ dependencies = [ [[package]] name = "ruma-events" -version = "0.27.11" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.28.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "as_variant", "indexmap 2.2.6", @@ -2811,8 +2828,8 @@ dependencies = [ [[package]] name = "ruma-federation-api" -version = "0.8.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.9.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "js_int", "ruma-common", @@ -2823,8 +2840,8 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" -version = "0.9.3" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.9.5" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "js_int", "thiserror", @@ -2832,8 +2849,8 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" -version = "0.8.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.9.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "js_int", "ruma-common", @@ -2842,8 +2859,8 @@ dependencies = [ [[package]] name = "ruma-macros" -version = "0.12.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.13.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "once_cell", "proc-macro-crate", @@ -2851,14 +2868,14 @@ dependencies = [ "quote", "ruma-identifiers-validation", "serde", - "syn 2.0.60", + "syn 2.0.61", "toml", ] [[package]] name = "ruma-push-gateway-api" -version = "0.8.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.9.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "js_int", "ruma-common", @@ -2869,8 +2886,8 @@ dependencies = [ [[package]] name = "ruma-signatures" -version = "0.14.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.15.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "base64 0.22.1", "ed25519-dalek", @@ -2885,8 +2902,8 @@ dependencies = [ [[package]] name = "ruma-state-res" -version = "0.10.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.11.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "itertools", "js_int", @@ -2914,7 +2931,7 @@ dependencies = [ [[package]] name = "rust-librocksdb-sys" version = "0.21.0+9.1.1" -source = "git+https://github.com/zaidoon1/rust-rocksdb?branch=master#c5cd6bd25152ef1f8a488761351da0c3d29ed93a" +source = "git+https://github.com/zaidoon1/rust-rocksdb?branch=master#6f0afedb3c29239b1d8a15a97ed8e6b74e0a9b33" dependencies = [ "bindgen", "bzip2-sys", @@ -2931,7 +2948,7 @@ dependencies = [ [[package]] name = "rust-rocksdb" version = "0.25.0" -source = "git+https://github.com/zaidoon1/rust-rocksdb?branch=master#c5cd6bd25152ef1f8a488761351da0c3d29ed93a" +source = "git+https://github.com/zaidoon1/rust-rocksdb?branch=master#6f0afedb3c29239b1d8a15a97ed8e6b74e0a9b33" dependencies = [ "libc", "rust-librocksdb-sys", @@ -2939,9 +2956,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hash" @@ -3009,9 +3026,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.5.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beb461507cee2c2ff151784c52762cf4d9ff6a61f3e80968600ed24fa837fa54" +checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" [[package]] name = "rustls-webpki" @@ -3036,15 +3053,15 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" +checksum = "092474d1a01ea8278f69e6a358998405fae5b8b963ddaeb2b0b04a128bf1dfb0" [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "same-file" @@ -3098,11 +3115,11 @@ checksum = "621e3680f3e07db4c9c2c3fb07c6223ab2fab2e54bd3c04c3ae037990f428c32" [[package]] name = "security-framework" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "core-foundation", "core-foundation-sys", "libc", @@ -3111,9 +3128,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -3121,9 +3138,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "sentry" @@ -3262,22 +3279,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.200" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.200" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -3295,9 +3312,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -3498,7 +3515,7 @@ dependencies = [ "new_debug_unreachable", "once_cell", "parking_lot", - "phf_shared", + "phf_shared 0.10.0", "precomputed-hash", "serde", ] @@ -3509,8 +3526,8 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" dependencies = [ - "phf_generator", - "phf_shared", + "phf_generator 0.10.0", + "phf_shared 0.10.0", "proc-macro2", "quote", ] @@ -3543,9 +3560,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.60" +version = "2.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "c993ed8ccba56ae856363b1845da7266a7cb78e1d146c8a32d54b45a8b831fc9" dependencies = [ "proc-macro2", "quote", @@ -3577,22 +3594,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.59" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.59" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -3741,7 +3758,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -3790,16 +3807,15 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] @@ -3844,7 +3860,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.7", + "winnow 0.6.8", ] [[package]] @@ -3947,7 +3963,7 @@ source = "git+https://github.com/girlbossceo/tracing?branch=tracing-subscriber/e dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -4218,7 +4234,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", "wasm-bindgen-shared", ] @@ -4252,7 +4268,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4295,9 +4311,9 @@ dependencies = [ [[package]] name = "webpage" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb86b12e58d490a99867f561ce8466ffa7b73e24d015a8e7f5bc111d4424ba2" +checksum = "70862efc041d46e6bbaa82bb9c34ae0596d090e86cbd14bd9e93b36ee6802eac" dependencies = [ "html5ever", "markup5ever_rcdom", @@ -4538,9 +4554,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" +checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" dependencies = [ "memchr", ] @@ -4567,9 +4583,9 @@ dependencies = [ [[package]] name = "xml5ever" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4034e1d05af98b51ad7214527730626f019682d797ba38b51689212118d8e650" +checksum = "7c376f76ed09df711203e20c3ef5ce556f0166fa03d39590016c0fd625437fad" dependencies = [ "log", "mac", @@ -4584,22 +4600,22 @@ checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f24789f6..b7a3c53a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ rust-version = "1.77.0" [dependencies] console-subscriber = { version = "0.2", optional = true } -infer = { version = "0.3", default-features = false } +infer = { version = "0.15", default-features = false } # for hot lib reload hot-lib-reloader = { version = "^0.7", optional = true } @@ -28,7 +28,7 @@ hot-lib-reloader = { version = "^0.7", optional = true } rand = "0.8.5" # Used for conduit::Error type -thiserror = "1.0.59" +thiserror = "1.0.60" # Used to encode server public key base64 = "0.22.1" @@ -133,14 +133,14 @@ features = ["rustls-tls-native-roots", "socks", "hickory-dns"] # all the serde stuff # Used for pdu definition [dependencies.serde] -version = "1.0.200" +version = "1.0.201" features = ["rc"] # Used for appservice registration files [dependencies.serde_yaml] version = "0.9.34" # Used for ruma wrapper [dependencies.serde_json] -version = "1.0.116" +version = "1.0.117" features = ["raw_value"] @@ -234,7 +234,7 @@ features = ["use_std"] # for URL previews [dependencies.webpage] -version = "2.0" +version = "2.0.1" default-features = false # to support multiple variations of setting a config option diff --git a/src/utils/content_disposition.rs b/src/utils/content_disposition.rs index 6df0e14f..f2c1e712 100644 --- a/src/utils/content_disposition.rs +++ b/src/utils/content_disposition.rs @@ -16,7 +16,7 @@ pub(crate) fn content_disposition_type(buf: &[u8], _content_type: &Option "inline", + MatcherType::Image | MatcherType::Audio | MatcherType::Text | MatcherType::Video => "inline", _ => "attachment", } } From 09d32403651471c17801e5fced5b5412e383755d Mon Sep 17 00:00:00 2001 From: strawberry Date: Thu, 9 May 2024 12:21:27 -0400 Subject: [PATCH 0055/2291] bump conduwuit version to 0.3.3 Signed-off-by: strawberry --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b2ae344f..73209431 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -568,7 +568,7 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "conduit" -version = "0.3.2" +version = "0.3.3" dependencies = [ "argon2", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index b7a3c53a..9ca75672 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ authors = [ homepage = "https://conduwuit.puppyirl.gay/" repository = "https://github.com/girlbossceo/conduwuit" readme = "README.md" -version = "0.3.2" +version = "0.3.3" edition = "2021" # See also `rust-toolchain.toml` From 6946eead28c1e1c216031442b904b98ff061f16a Mon Sep 17 00:00:00 2001 From: strawberry Date: Thu, 9 May 2024 13:58:14 -0400 Subject: [PATCH 0056/2291] pin rust-rocksdb to before snappy update it seems to break nix builds Signed-off-by: strawberry --- Cargo.lock | 4 ++-- Cargo.toml | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73209431..20352010 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2931,7 +2931,7 @@ dependencies = [ [[package]] name = "rust-librocksdb-sys" version = "0.21.0+9.1.1" -source = "git+https://github.com/zaidoon1/rust-rocksdb?branch=master#6f0afedb3c29239b1d8a15a97ed8e6b74e0a9b33" +source = "git+https://github.com/zaidoon1/rust-rocksdb?rev=c5cd6bd25152ef1f8a488761351da0c3d29ed93a#c5cd6bd25152ef1f8a488761351da0c3d29ed93a" dependencies = [ "bindgen", "bzip2-sys", @@ -2948,7 +2948,7 @@ dependencies = [ [[package]] name = "rust-rocksdb" version = "0.25.0" -source = "git+https://github.com/zaidoon1/rust-rocksdb?branch=master#6f0afedb3c29239b1d8a15a97ed8e6b74e0a9b33" +source = "git+https://github.com/zaidoon1/rust-rocksdb?rev=c5cd6bd25152ef1f8a488761351da0c3d29ed93a#c5cd6bd25152ef1f8a488761351da0c3d29ed93a" dependencies = [ "libc", "rust-librocksdb-sys", diff --git a/Cargo.toml b/Cargo.toml index 9ca75672..f6420cbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -299,7 +299,8 @@ default-features = false [dependencies.rust-rocksdb] git = "https://github.com/zaidoon1/rust-rocksdb" -branch = "master" +rev = "c5cd6bd25152ef1f8a488761351da0c3d29ed93a" +#branch = "master" optional = true default-features = true features = ["multi-threaded-cf", "zstd"] From d15e46130310539f41fccb46e5c94c9303049998 Mon Sep 17 00:00:00 2001 From: strawberry Date: Tue, 7 May 2024 22:39:55 -0400 Subject: [PATCH 0057/2291] config option to auto-remediate bad users joining bad rooms or servers also forgets all rooms upon leave_all_rooms Signed-off-by: strawberry --- conduwuit-example.toml | 13 ++ src/api/client_server/account.rs | 2 +- src/api/client_server/membership.rs | 236 ++++++++++-------------- src/config/mod.rs | 6 + src/service/admin/user/user_commands.rs | 4 +- 5 files changed, 117 insertions(+), 144 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index b726fd28..90a84ac1 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -269,6 +269,19 @@ url_preview_check_root_domain = false # Defaults to true allow_profile_lookup_federation_requests = true +# Config option to automatically deactivate the account of any user who attempts to join a: +# - banned room +# - forbidden room alias +# - room alias or ID with a forbidden server name +# +# This may be useful if all your banned lists consist of toxic rooms or servers that no good faith user would ever attempt to join, and +# to automatically remediate the problem without any admin user intervention. +# +# This will also make the user leave all rooms. Federation (e.g. remote room invites) are ignored here. +# +# Defaults to false as rooms can be banned for non-moderation-related reasons +#auto_deactivate_banned_room_attempts = false + ### Misc diff --git a/src/api/client_server/account.rs b/src/api/client_server/account.rs index b5d92d15..41343183 100644 --- a/src/api/client_server/account.rs +++ b/src/api/client_server/account.rs @@ -533,7 +533,7 @@ pub(crate) async fn deactivate_route(body: Ruma) -> Res } // Make the user leave all rooms before deactivation - client_server::leave_all_rooms(sender_user).await?; + client_server::leave_all_rooms(sender_user).await; // Remove devices and mark account as deactivated services().users.deactivate_account(sender_user)?; diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 54af1d41..edda0c64 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -21,12 +21,13 @@ use ruma::{ room::{ join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent}, member::{MembershipState, RoomMemberEventContent}, + message::RoomMessageEventContent, }, StateEventType, TimelineEventType, }, serde::Base64, state_res, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId, OwnedServerName, - OwnedUserId, RoomId, RoomVersionId, UserId, + OwnedUserId, RoomId, RoomVersionId, ServerName, UserId, }; use serde_json::value::{to_raw_value, RawValue as RawJsonValue}; use tokio::sync::RwLock; @@ -40,6 +41,91 @@ use crate::{ Error, PduEvent, Result, Ruma, }; +/// Checks if the room is banned in any way possible and the sender user is not +/// an admin. +/// +/// Performs automatic deactivation if `auto_deactivate_banned_room_attempts` is +/// enabled +#[tracing::instrument] +async fn banned_room_check(user_id: &UserId, room_id: Option<&RoomId>, server_name: Option<&ServerName>) -> Result<()> { + if !services().users.is_admin(user_id)? { + if let Some(room_id) = room_id { + if services().rooms.metadata.is_banned(room_id)? + || services() + .globals + .config + .forbidden_remote_server_names + .contains(&room_id.server_name().unwrap().to_owned()) + { + warn!( + "User {user_id} who is not an admin attempted to send an invite for or attempted to join a banned \ + room or banned room server name: {room_id}." + ); + + if services() + .globals + .config + .auto_deactivate_banned_room_attempts + { + warn!("Automatically deactivating user {user_id} due to attempted banned room join"); + services() + .admin + .send_message(RoomMessageEventContent::text_plain(format!( + "Automatically deactivating user {user_id} due to attempted banned room join" + ))) + .await; + + // ignore errors + leave_all_rooms(user_id).await; + _ = services().users.deactivate_account(user_id); + } + + return Err(Error::BadRequest( + ErrorKind::forbidden(), + "This room is banned on this homeserver.", + )); + } + } else if let Some(server_name) = server_name { + if services() + .globals + .config + .forbidden_remote_server_names + .contains(&server_name.to_owned()) + { + warn!( + "User {user_id} who is not an admin tried joining a room which has the server name {server_name} \ + that is globally forbidden. Rejecting.", + ); + + if services() + .globals + .config + .auto_deactivate_banned_room_attempts + { + warn!("Automatically deactivating user {user_id} due to attempted banned room join"); + services() + .admin + .send_message(RoomMessageEventContent::text_plain(format!( + "Automatically deactivating user {user_id} due to attempted banned room join" + ))) + .await; + + // ignore errors + leave_all_rooms(user_id).await; + _ = services().users.deactivate_account(user_id); + } + + return Err(Error::BadRequest( + ErrorKind::forbidden(), + "This remote server is banned on this homeserver.", + )); + } + } + } + + Ok(()) +} + /// # `POST /_matrix/client/r0/rooms/{roomId}/join` /// /// Tries to join the sender user into a room. @@ -53,32 +139,7 @@ pub(crate) async fn join_room_by_id_route( ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - if services().rooms.metadata.is_banned(&body.room_id)? && !services().users.is_admin(sender_user)? { - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "This room is banned on this homeserver.", - )); - } - - if let Some(server) = body.room_id.server_name() { - if services() - .globals - .config - .forbidden_remote_server_names - .contains(&server.to_owned()) - && !services().users.is_admin(sender_user)? - { - warn!( - "User {sender_user} tried joining room ID {} which has a server name that is globally forbidden. \ - Rejecting.", - body.room_id - ); - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "This remote server is banned on this homeserver.", - )); - } - } + banned_room_check(sender_user, Some(&body.room_id), body.room_id.server_name()).await?; // There is no body.server_name for /roomId/join let mut servers = services() @@ -131,31 +192,7 @@ pub(crate) async fn join_room_by_id_or_alias_route( let (servers, room_id) = match OwnedRoomId::try_from(body.room_id_or_alias) { Ok(room_id) => { - if services().rooms.metadata.is_banned(&room_id)? && !services().users.is_admin(sender_user)? { - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "This room is banned on this homeserver.", - )); - } - - if let Some(server) = room_id.server_name() { - if services() - .globals - .config - .forbidden_remote_server_names - .contains(&server.to_owned()) - && !services().users.is_admin(sender_user)? - { - warn!( - "User {sender_user} tried joining room ID {room_id} which has a server name that is globally \ - forbidden. Rejecting.", - ); - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "This remote server is banned on this homeserver.", - )); - } - } + banned_room_check(sender_user, Some(&room_id), room_id.server_name()).await?; let mut servers = body.server_name.clone(); servers.extend( @@ -186,69 +223,9 @@ pub(crate) async fn join_room_by_id_or_alias_route( (servers, room_id) }, Err(room_alias) => { - if services() - .globals - .config - .forbidden_remote_server_names - .contains(&room_alias.server_name().to_owned()) - && !services().users.is_admin(sender_user)? - { - warn!( - "User {sender_user} tried joining room alias {room_alias} which has a server name that is \ - globally forbidden. Rejecting.", - ); - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "This remote server is banned on this homeserver.", - )); - } - let response = get_alias_helper(room_alias.clone(), Some(body.server_name.clone())).await?; - if services().rooms.metadata.is_banned(&response.room_id)? && !services().users.is_admin(sender_user)? { - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "This room is banned on this homeserver.", - )); - } - - if services() - .globals - .config - .forbidden_remote_server_names - .contains(&room_alias.server_name().to_owned()) - && !services().users.is_admin(sender_user)? - { - warn!( - "User {sender_user} tried joining room alias {room_alias} with room ID {}, which the alias has a \ - server name that is globally forbidden. Rejecting.", - &response.room_id - ); - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "This remote server is banned on this homeserver.", - )); - } - - if let Some(server) = response.room_id.server_name() { - if services() - .globals - .config - .forbidden_remote_server_names - .contains(&server.to_owned()) - && !services().users.is_admin(sender_user)? - { - warn!( - "User {sender_user} tried joining room alias {room_alias} with room ID {}, which has a server \ - name that is globally forbidden. Rejecting.", - &response.room_id - ); - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "This remote server is banned on this homeserver.", - )); - } - } + banned_room_check(sender_user, Some(&response.room_id), Some(room_alias.server_name())).await?; let mut servers = body.server_name; servers.extend(response.servers); @@ -321,30 +298,7 @@ pub(crate) async fn invite_user_route(body: Ruma) -> R )); } - if services().rooms.metadata.is_banned(&body.room_id)? && !services().users.is_admin(sender_user)? { - info!( - "Local user {} who is not an admin attempted to send an invite for banned room {}.", - &sender_user, &body.room_id - ); - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "This room is banned on this homeserver.", - )); - } - - if let Some(server) = body.room_id.server_name() { - if services() - .globals - .config - .forbidden_remote_server_names - .contains(&server.to_owned()) - { - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "Server is banned on this homeserver.", - )); - } - } + banned_room_check(sender_user, Some(&body.room_id), body.room_id.server_name()).await?; if let invite_user::v3::InvitationRecipient::UserId { user_id, @@ -1606,8 +1560,9 @@ pub(crate) async fn invite_helper( Ok(()) } -// Make a user leave all their joined rooms -pub(crate) async fn leave_all_rooms(user_id: &UserId) -> Result<()> { +// Make a user leave all their joined rooms, forgets all rooms, and ignores +// errors +pub(crate) async fn leave_all_rooms(user_id: &UserId) { let all_rooms = services() .rooms .state_cache @@ -1627,10 +1582,9 @@ pub(crate) async fn leave_all_rooms(user_id: &UserId) -> Result<()> { }; // ignore errors + _ = services().rooms.state_cache.forget(&room_id, user_id); _ = leave_room(user_id, &room_id, None).await; } - - Ok(()) } pub(crate) async fn leave_room(user_id: &UserId, room_id: &RoomId, reason: Option) -> Result<()> { diff --git a/src/config/mod.rs b/src/config/mod.rs index 3a7471f8..8b84a9b1 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -207,6 +207,8 @@ pub(crate) struct Config { #[serde(default = "Vec::new")] pub(crate) auto_join_rooms: Vec, + #[serde(default)] + pub(crate) auto_deactivate_banned_room_attempts: bool, #[serde(default = "default_rocksdb_log_level")] pub(crate) rocksdb_log_level: String, @@ -612,6 +614,10 @@ impl fmt::Display for Config { "Allow incoming profile lookup federation requests", &self.allow_profile_lookup_federation_requests.to_string(), ), + ( + "Auto deactivate banned room join attempts", + &self.auto_deactivate_banned_room_attempts.to_string(), + ), ("Notification push path", &self.notification_push_path), ("Allow room creation", &self.allow_room_creation.to_string()), ( diff --git a/src/service/admin/user/user_commands.rs b/src/service/admin/user/user_commands.rs index a8375064..1aa8d4ea 100644 --- a/src/service/admin/user/user_commands.rs +++ b/src/service/admin/user/user_commands.rs @@ -167,7 +167,7 @@ pub(crate) async fn deactivate( services().users.deactivate_account(&user_id)?; if leave_rooms { - leave_all_rooms(&user_id).await?; + leave_all_rooms(&user_id).await; } Ok(RoomMessageEventContent::text_plain(format!( @@ -282,7 +282,7 @@ pub(crate) async fn deactivate_all(body: Vec<&str>, leave_rooms: bool, force: bo if leave_rooms { for &user_id in &user_ids { - _ = leave_all_rooms(user_id).await; + leave_all_rooms(user_id).await; } } From 328502c1cd0218cd1c4ff0dc19a5eeea158c0530 Mon Sep 17 00:00:00 2001 From: strawberry Date: Thu, 9 May 2024 11:26:55 -0400 Subject: [PATCH 0058/2291] dont send avatar url or display name for ban membership events the display name or avatar may be offensive Signed-off-by: strawberry --- src/api/client_server/membership.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index edda0c64..a1908327 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -400,11 +400,11 @@ pub(crate) async fn ban_user_route(body: Ruma) -> Result< .map_or( Ok(RoomMemberEventContent { membership: MembershipState::Ban, - displayname: services().users.displayname(&body.user_id)?, - avatar_url: services().users.avatar_url(&body.user_id)?, + displayname: None, + avatar_url: None, is_direct: None, third_party_invite: None, - blurhash: services().users.blurhash(&body.user_id)?, + blurhash: services().users.blurhash(&body.user_id).unwrap_or_default(), reason: body.reason.clone(), join_authorized_via_users_server: None, }), @@ -412,14 +412,8 @@ pub(crate) async fn ban_user_route(body: Ruma) -> Result< serde_json::from_str(event.content.get()) .map(|event: RoomMemberEventContent| RoomMemberEventContent { membership: MembershipState::Ban, - displayname: services() - .users - .displayname(&body.user_id) - .unwrap_or_default(), - avatar_url: services() - .users - .avatar_url(&body.user_id) - .unwrap_or_default(), + displayname: None, + avatar_url: None, blurhash: services().users.blurhash(&body.user_id).unwrap_or_default(), reason: body.reason.clone(), join_authorized_via_users_server: None, From 6b918966d40aa29ab6a2be022e031000f9708df0 Mon Sep 17 00:00:00 2001 From: strawberry Date: Thu, 9 May 2024 22:27:21 -0400 Subject: [PATCH 0059/2291] Revert "bump various deps" This reverts commit 653ec3799e758abbac4d34993a221a0f65a5244c. --- Cargo.lock | 292 +++++++++++++++---------------- Cargo.toml | 10 +- src/utils/content_disposition.rs | 2 +- 3 files changed, 144 insertions(+), 160 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 20352010..2ec7ec52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,15 +61,15 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] name = "anyhow" -version = "1.0.83" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "arc-swap" @@ -103,9 +103,9 @@ checksum = "5f093eed78becd229346bf859eec0aa4dd7ddde0757287b2b4107a1f09c80002" [[package]] name = "async-compression" -version = "0.4.10" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c90a406b4495d129f00461241616194cb8a032c8d1c53c657f0961d5f8e0498" +checksum = "4e9eabd7a98fe442131a17c316bd9349c43695e49e730c3c8e12cfb5f4da2693" dependencies = [ "brotli", "flate2", @@ -136,7 +136,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -147,7 +147,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.3.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "axum" @@ -375,7 +375,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -410,9 +410,9 @@ dependencies = [ [[package]] name = "brotli" -version = "6.0.0" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f7971dbd9326d58187408ab83117d8ac1bb9c17b085fdacd1cf2f598719b6b" +checksum = "19483b140a7ac7174d34b5a581b406c64f84da5409d3e09cf4fff604f9270e67" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -472,9 +472,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.97" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd" dependencies = [ "jobserver", "libc", @@ -551,7 +551,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -776,7 +776,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -880,7 +880,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -1048,7 +1048,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -1092,9 +1092,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" dependencies = [ "cfg-if", "js-sys", @@ -1359,16 +1359,16 @@ dependencies = [ [[package]] name = "html5ever" -version = "0.27.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" +checksum = "bea68cab48b8459f17cf1c944c67ddc572d272d9f2b274140f223ecb1da4a3b7" dependencies = [ "log", "mac", "markup5ever", "proc-macro2", "quote", - "syn 2.0.61", + "syn 1.0.109", ] [[package]] @@ -1609,9 +1609,9 @@ dependencies = [ [[package]] name = "infer" -version = "0.15.0" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb33622da908807a06f9513c19b3c1ad50fab3e4137d82a78107d502075aa199" +checksum = "865e8a58ae8e24d2c4412c31344afa1d302a3740ad67528c10f50d6876cdcf55" [[package]] name = "inlinable_string" @@ -1893,9 +1893,9 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" [[package]] name = "markup5ever" -version = "0.12.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" +checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016" dependencies = [ "log", "phf", @@ -1907,9 +1907,9 @@ dependencies = [ [[package]] name = "markup5ever_rcdom" -version = "0.3.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edaa21ab3701bfee5099ade5f7e1f84553fd19228cf332f13cd6e964bf59be18" +checksum = "b9521dd6750f8e80ee6c53d65e2e4656d7de37064f3a7a5d2d11d05df93839c2" dependencies = [ "html5ever", "markup5ever", @@ -2051,9 +2051,9 @@ dependencies = [ [[package]] name = "num" -version = "0.4.3" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" +checksum = "3135b08af27d103b0a51f2ae0f8632117b7b185ccf931445affa8df530576a41" dependencies = [ "num-bigint", "num-complex", @@ -2065,19 +2065,20 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.5" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" dependencies = [ + "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-complex" -version = "0.4.6" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" dependencies = [ "num-traits", ] @@ -2099,9 +2100,9 @@ dependencies = [ [[package]] name = "num-iter" -version = "0.1.45" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" dependencies = [ "autocfg", "num-integer", @@ -2110,10 +2111,11 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.4.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ + "autocfg", "num-bigint", "num-integer", "num-traits", @@ -2121,9 +2123,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.19" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] @@ -2293,9 +2295,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.15" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "pear" @@ -2317,7 +2319,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -2338,21 +2340,21 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "phf" -version = "0.11.2" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" dependencies = [ - "phf_shared 0.11.2", + "phf_shared", ] [[package]] name = "phf_codegen" -version = "0.11.2" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" dependencies = [ - "phf_generator 0.11.2", - "phf_shared 0.11.2", + "phf_generator", + "phf_shared", ] [[package]] @@ -2361,17 +2363,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" dependencies = [ - "phf_shared 0.10.0", - "rand", -] - -[[package]] -name = "phf_generator" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" -dependencies = [ - "phf_shared 0.11.2", + "phf_shared", "rand", ] @@ -2384,15 +2376,6 @@ dependencies = [ "siphasher", ] -[[package]] -name = "phf_shared" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" -dependencies = [ - "siphasher", -] - [[package]] name = "pin-project" version = "1.1.5" @@ -2410,7 +2393,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -2489,9 +2472,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] @@ -2504,7 +2487,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", "version_check", "yansi", ] @@ -2521,15 +2504,15 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.5" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9554e3ab233f0a932403704f1a1d08c30d5ccd931adfdfa1e8b5a19b52c1d55a" +checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" dependencies = [ "anyhow", "itertools", "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -2722,8 +2705,8 @@ dependencies = [ [[package]] name = "ruma" -version = "0.10.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.9.4" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "assign", "js_int", @@ -2742,8 +2725,8 @@ dependencies = [ [[package]] name = "ruma-appservice-api" -version = "0.10.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.9.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "js_int", "ruma-common", @@ -2754,8 +2737,8 @@ dependencies = [ [[package]] name = "ruma-client-api" -version = "0.18.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.17.4" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "as_variant", "assign", @@ -2776,8 +2759,8 @@ dependencies = [ [[package]] name = "ruma-common" -version = "0.13.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.12.1" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "as_variant", "base64 0.22.1", @@ -2806,8 +2789,8 @@ dependencies = [ [[package]] name = "ruma-events" -version = "0.28.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.27.11" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "as_variant", "indexmap 2.2.6", @@ -2828,8 +2811,8 @@ dependencies = [ [[package]] name = "ruma-federation-api" -version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.8.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "js_int", "ruma-common", @@ -2840,8 +2823,8 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" -version = "0.9.5" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.9.3" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "js_int", "thiserror", @@ -2849,8 +2832,8 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" -version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.8.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "js_int", "ruma-common", @@ -2859,8 +2842,8 @@ dependencies = [ [[package]] name = "ruma-macros" -version = "0.13.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.12.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "once_cell", "proc-macro-crate", @@ -2868,14 +2851,14 @@ dependencies = [ "quote", "ruma-identifiers-validation", "serde", - "syn 2.0.61", + "syn 2.0.60", "toml", ] [[package]] name = "ruma-push-gateway-api" -version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.8.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "js_int", "ruma-common", @@ -2886,8 +2869,8 @@ dependencies = [ [[package]] name = "ruma-signatures" -version = "0.15.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.14.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "base64 0.22.1", "ed25519-dalek", @@ -2902,8 +2885,8 @@ dependencies = [ [[package]] name = "ruma-state-res" -version = "0.11.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +version = "0.10.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" dependencies = [ "itertools", "js_int", @@ -2956,9 +2939,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.24" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustc-hash" @@ -3026,9 +3009,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.7.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" +checksum = "beb461507cee2c2ff151784c52762cf4d9ff6a61f3e80968600ed24fa837fa54" [[package]] name = "rustls-webpki" @@ -3053,15 +3036,15 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.16" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "092474d1a01ea8278f69e6a358998405fae5b8b963ddaeb2b0b04a128bf1dfb0" +checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" [[package]] name = "ryu" -version = "1.0.18" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "same-file" @@ -3115,11 +3098,11 @@ checksum = "621e3680f3e07db4c9c2c3fb07c6223ab2fab2e54bd3c04c3ae037990f428c32" [[package]] name = "security-framework" -version = "2.11.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" dependencies = [ - "bitflags 2.5.0", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -3128,9 +3111,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" +checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" dependencies = [ "core-foundation-sys", "libc", @@ -3138,9 +3121,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.23" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "sentry" @@ -3279,22 +3262,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.201" +version = "1.0.200" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.201" +version = "1.0.200" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -3312,9 +3295,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "itoa", "ryu", @@ -3515,7 +3498,7 @@ dependencies = [ "new_debug_unreachable", "once_cell", "parking_lot", - "phf_shared 0.10.0", + "phf_shared", "precomputed-hash", "serde", ] @@ -3526,8 +3509,8 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" dependencies = [ - "phf_generator 0.10.0", - "phf_shared 0.10.0", + "phf_generator", + "phf_shared", "proc-macro2", "quote", ] @@ -3560,9 +3543,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.61" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c993ed8ccba56ae856363b1845da7266a7cb78e1d146c8a32d54b45a8b831fc9" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -3594,22 +3577,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.60" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.60" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -3758,7 +3741,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -3807,15 +3790,16 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.11" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", + "tracing", ] [[package]] @@ -3860,7 +3844,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.8", + "winnow 0.6.7", ] [[package]] @@ -3963,7 +3947,7 @@ source = "git+https://github.com/girlbossceo/tracing?branch=tracing-subscriber/e dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -4234,7 +4218,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", "wasm-bindgen-shared", ] @@ -4268,7 +4252,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4311,9 +4295,9 @@ dependencies = [ [[package]] name = "webpage" -version = "2.0.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70862efc041d46e6bbaa82bb9c34ae0596d090e86cbd14bd9e93b36ee6802eac" +checksum = "3fb86b12e58d490a99867f561ce8466ffa7b73e24d015a8e7f5bc111d4424ba2" dependencies = [ "html5ever", "markup5ever_rcdom", @@ -4554,9 +4538,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.8" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" +checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" dependencies = [ "memchr", ] @@ -4583,9 +4567,9 @@ dependencies = [ [[package]] name = "xml5ever" -version = "0.18.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c376f76ed09df711203e20c3ef5ce556f0166fa03d39590016c0fd625437fad" +checksum = "4034e1d05af98b51ad7214527730626f019682d797ba38b51689212118d8e650" dependencies = [ "log", "mac", @@ -4600,22 +4584,22 @@ checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "zerocopy" -version = "0.7.34" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.34" +version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f6420cbc..d0d06032 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ rust-version = "1.77.0" [dependencies] console-subscriber = { version = "0.2", optional = true } -infer = { version = "0.15", default-features = false } +infer = { version = "0.3", default-features = false } # for hot lib reload hot-lib-reloader = { version = "^0.7", optional = true } @@ -28,7 +28,7 @@ hot-lib-reloader = { version = "^0.7", optional = true } rand = "0.8.5" # Used for conduit::Error type -thiserror = "1.0.60" +thiserror = "1.0.59" # Used to encode server public key base64 = "0.22.1" @@ -133,14 +133,14 @@ features = ["rustls-tls-native-roots", "socks", "hickory-dns"] # all the serde stuff # Used for pdu definition [dependencies.serde] -version = "1.0.201" +version = "1.0.200" features = ["rc"] # Used for appservice registration files [dependencies.serde_yaml] version = "0.9.34" # Used for ruma wrapper [dependencies.serde_json] -version = "1.0.117" +version = "1.0.116" features = ["raw_value"] @@ -234,7 +234,7 @@ features = ["use_std"] # for URL previews [dependencies.webpage] -version = "2.0.1" +version = "2.0" default-features = false # to support multiple variations of setting a config option diff --git a/src/utils/content_disposition.rs b/src/utils/content_disposition.rs index f2c1e712..6df0e14f 100644 --- a/src/utils/content_disposition.rs +++ b/src/utils/content_disposition.rs @@ -16,7 +16,7 @@ pub(crate) fn content_disposition_type(buf: &[u8], _content_type: &Option "inline", + MatcherType::IMAGE | MatcherType::AUDIO | MatcherType::TEXT | MatcherType::VIDEO => "inline", _ => "attachment", } } From 9f19a2025d9a561d216786c8649711b49063cc8e Mon Sep 17 00:00:00 2001 From: morguldir Date: Sat, 11 May 2024 01:26:00 +0200 Subject: [PATCH 0060/2291] Revert "feat(membership): check if user already has the membership that is requested to be set" This reverts commit 321a6ca0fefccc87b334d7410aba18c512fcee2b. These checks were not working as intended, resulting in the unban button not working The join check gets kept since it slightly reduces the amount of sent joins in some cases This check will probably be replaced soon for a more universal solution to the "made no change" issue Signed-off-by: morguldir --- src/api/client_server/membership.rs | 31 ----------------------------- 1 file changed, 31 deletions(-) diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index a1908327..4fad8cf2 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -317,15 +317,6 @@ pub(crate) async fn invite_user_route(body: Ruma) -> R pub(crate) async fn kick_user_route(body: Ruma) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - if let Ok(true) = services() - .rooms - .state_cache - .is_left(sender_user, &body.room_id) - { - info!("{} is not in room {}", &body.user_id, &body.room_id); - return Ok(kick_user::v3::Response {}); - } - let mut event: RoomMemberEventContent = serde_json::from_str( services() .rooms @@ -382,17 +373,6 @@ pub(crate) async fn kick_user_route(body: Ruma) -> Resul pub(crate) async fn ban_user_route(body: Ruma) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - if let Ok(Some(membership_event)) = services() - .rooms - .state_accessor - .get_member(&body.room_id, sender_user) - { - if membership_event.membership == MembershipState::Ban { - info!("{} is already banned in {}", &body.user_id, &body.room_id); - return Ok(ban_user::v3::Response {}); - } - } - let event = services() .rooms .state_accessor @@ -462,17 +442,6 @@ pub(crate) async fn ban_user_route(body: Ruma) -> Result< pub(crate) async fn unban_user_route(body: Ruma) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - if let Ok(Some(membership_event)) = services() - .rooms - .state_accessor - .get_member(&body.room_id, sender_user) - { - if membership_event.membership != MembershipState::Ban { - info!("{} is already unbanned in {}", &body.user_id, &body.room_id); - return Ok(unban_user::v3::Response {}); - } - } - let mut event: RoomMemberEventContent = serde_json::from_str( services() .rooms From 09fca89ac55511c92b86733787cdf9d5f5154bcc Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 10 May 2024 19:32:11 -0400 Subject: [PATCH 0061/2291] Revert "rocksdb: enable async_io if using io_uring feature" This reverts commit 6266e0ab5e7db05cb1f5aa4a72b9874ff5ab57e5. --- src/database/rocksdb/kvtree.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/database/rocksdb/kvtree.rs b/src/database/rocksdb/kvtree.rs index a6026baa..4761624b 100644 --- a/src/database/rocksdb/kvtree.rs +++ b/src/database/rocksdb/kvtree.rs @@ -19,7 +19,6 @@ impl KvTree for RocksDbEngineTree<'_> { fn get(&self, key: &[u8]) -> Result>> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); - readoptions.set_async_io(cfg!(feature = "io_uring")); Ok(self.db.rocks.get_cf_opt(&self.cf(), key, &readoptions)?) } @@ -27,7 +26,6 @@ impl KvTree for RocksDbEngineTree<'_> { fn multi_get(&self, keys: &[&[u8]]) -> Result>>> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); - readoptions.set_async_io(cfg!(feature = "io_uring")); // Optimization can be `true` if key vector is pre-sorted **by the column // comparator**. @@ -115,7 +113,6 @@ impl KvTree for RocksDbEngineTree<'_> { fn iter<'a>(&'a self) -> Box, Vec)> + 'a> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); - readoptions.set_async_io(cfg!(feature = "io_uring")); Box::new( self.db @@ -129,7 +126,6 @@ impl KvTree for RocksDbEngineTree<'_> { fn iter_from<'a>(&'a self, from: &[u8], backwards: bool) -> Box, Vec)> + 'a> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); - readoptions.set_async_io(cfg!(feature = "io_uring")); Box::new( self.db @@ -154,8 +150,6 @@ impl KvTree for RocksDbEngineTree<'_> { fn increment(&self, key: &[u8]) -> Result> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); - readoptions.set_async_io(cfg!(feature = "io_uring")); - let writeoptions = rust_rocksdb::WriteOptions::default(); let old = self.db.rocks.get_cf_opt(&self.cf(), key, &readoptions)?; @@ -174,8 +168,6 @@ impl KvTree for RocksDbEngineTree<'_> { fn increment_batch(&self, iter: &mut dyn Iterator>) -> Result<()> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); - readoptions.set_async_io(cfg!(feature = "io_uring")); - let writeoptions = rust_rocksdb::WriteOptions::default(); let mut batch = WriteBatchWithTransaction::::default(); @@ -198,7 +190,6 @@ impl KvTree for RocksDbEngineTree<'_> { fn scan_prefix<'a>(&'a self, prefix: Vec) -> Box, Vec)> + 'a> { let mut readoptions = rust_rocksdb::ReadOptions::default(); readoptions.set_total_order_seek(true); - readoptions.set_async_io(cfg!(feature = "io_uring")); Box::new( self.db From 18e43e1d35c70e71b5fbaf44059f96a0bc4cf49e Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 10 May 2024 19:32:33 -0400 Subject: [PATCH 0062/2291] Reapply "bump various deps" This reverts commit 6b918966d40aa29ab6a2be022e031000f9708df0. --- Cargo.lock | 292 ++++++++++++++++--------------- Cargo.toml | 10 +- src/utils/content_disposition.rs | 2 +- 3 files changed, 160 insertions(+), 144 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ec7ec52..20352010 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,15 +61,15 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anyhow" -version = "1.0.82" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" [[package]] name = "arc-swap" @@ -103,9 +103,9 @@ checksum = "5f093eed78becd229346bf859eec0aa4dd7ddde0757287b2b4107a1f09c80002" [[package]] name = "async-compression" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e9eabd7a98fe442131a17c316bd9349c43695e49e730c3c8e12cfb5f4da2693" +checksum = "9c90a406b4495d129f00461241616194cb8a032c8d1c53c657f0961d5f8e0498" dependencies = [ "brotli", "flate2", @@ -136,7 +136,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -147,7 +147,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "axum" @@ -375,7 +375,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -410,9 +410,9 @@ dependencies = [ [[package]] name = "brotli" -version = "5.0.0" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19483b140a7ac7174d34b5a581b406c64f84da5409d3e09cf4fff604f9270e67" +checksum = "74f7971dbd9326d58187408ab83117d8ac1bb9c17b085fdacd1cf2f598719b6b" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -472,9 +472,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.96" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" dependencies = [ "jobserver", "libc", @@ -551,7 +551,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -776,7 +776,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -880,7 +880,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -1048,7 +1048,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -1092,9 +1092,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "js-sys", @@ -1359,16 +1359,16 @@ dependencies = [ [[package]] name = "html5ever" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bea68cab48b8459f17cf1c944c67ddc572d272d9f2b274140f223ecb1da4a3b7" +checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ "log", "mac", "markup5ever", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.61", ] [[package]] @@ -1609,9 +1609,9 @@ dependencies = [ [[package]] name = "infer" -version = "0.3.7" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "865e8a58ae8e24d2c4412c31344afa1d302a3740ad67528c10f50d6876cdcf55" +checksum = "cb33622da908807a06f9513c19b3c1ad50fab3e4137d82a78107d502075aa199" [[package]] name = "inlinable_string" @@ -1893,9 +1893,9 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" [[package]] name = "markup5ever" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016" +checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" dependencies = [ "log", "phf", @@ -1907,9 +1907,9 @@ dependencies = [ [[package]] name = "markup5ever_rcdom" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9521dd6750f8e80ee6c53d65e2e4656d7de37064f3a7a5d2d11d05df93839c2" +checksum = "edaa21ab3701bfee5099ade5f7e1f84553fd19228cf332f13cd6e964bf59be18" dependencies = [ "html5ever", "markup5ever", @@ -2051,9 +2051,9 @@ dependencies = [ [[package]] name = "num" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3135b08af27d103b0a51f2ae0f8632117b7b185ccf931445affa8df530576a41" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" dependencies = [ "num-bigint", "num-complex", @@ -2065,20 +2065,19 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ - "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-complex" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "num-traits", ] @@ -2100,9 +2099,9 @@ dependencies = [ [[package]] name = "num-iter" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" dependencies = [ "autocfg", "num-integer", @@ -2111,11 +2110,10 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ - "autocfg", "num-bigint", "num-integer", "num-traits", @@ -2123,9 +2121,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -2295,9 +2293,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pear" @@ -2319,7 +2317,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -2340,21 +2338,21 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "phf" -version = "0.10.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ - "phf_shared", + "phf_shared 0.11.2", ] [[package]] name = "phf_codegen" -version = "0.10.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" dependencies = [ - "phf_generator", - "phf_shared", + "phf_generator 0.11.2", + "phf_shared 0.11.2", ] [[package]] @@ -2363,7 +2361,17 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" dependencies = [ - "phf_shared", + "phf_shared 0.10.0", + "rand", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared 0.11.2", "rand", ] @@ -2376,6 +2384,15 @@ dependencies = [ "siphasher", ] +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project" version = "1.1.5" @@ -2393,7 +2410,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -2472,9 +2489,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] @@ -2487,7 +2504,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", "version_check", "yansi", ] @@ -2504,15 +2521,15 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" +checksum = "9554e3ab233f0a932403704f1a1d08c30d5ccd931adfdfa1e8b5a19b52c1d55a" dependencies = [ "anyhow", "itertools", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -2705,8 +2722,8 @@ dependencies = [ [[package]] name = "ruma" -version = "0.9.4" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.10.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "assign", "js_int", @@ -2725,8 +2742,8 @@ dependencies = [ [[package]] name = "ruma-appservice-api" -version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.10.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "js_int", "ruma-common", @@ -2737,8 +2754,8 @@ dependencies = [ [[package]] name = "ruma-client-api" -version = "0.17.4" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.18.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "as_variant", "assign", @@ -2759,8 +2776,8 @@ dependencies = [ [[package]] name = "ruma-common" -version = "0.12.1" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.13.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "as_variant", "base64 0.22.1", @@ -2789,8 +2806,8 @@ dependencies = [ [[package]] name = "ruma-events" -version = "0.27.11" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.28.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "as_variant", "indexmap 2.2.6", @@ -2811,8 +2828,8 @@ dependencies = [ [[package]] name = "ruma-federation-api" -version = "0.8.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.9.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "js_int", "ruma-common", @@ -2823,8 +2840,8 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" -version = "0.9.3" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.9.5" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "js_int", "thiserror", @@ -2832,8 +2849,8 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" -version = "0.8.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.9.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "js_int", "ruma-common", @@ -2842,8 +2859,8 @@ dependencies = [ [[package]] name = "ruma-macros" -version = "0.12.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.13.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "once_cell", "proc-macro-crate", @@ -2851,14 +2868,14 @@ dependencies = [ "quote", "ruma-identifiers-validation", "serde", - "syn 2.0.60", + "syn 2.0.61", "toml", ] [[package]] name = "ruma-push-gateway-api" -version = "0.8.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.9.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "js_int", "ruma-common", @@ -2869,8 +2886,8 @@ dependencies = [ [[package]] name = "ruma-signatures" -version = "0.14.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.15.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "base64 0.22.1", "ed25519-dalek", @@ -2885,8 +2902,8 @@ dependencies = [ [[package]] name = "ruma-state-res" -version = "0.10.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#b8f30d4da497d7f74a64c5b92f64e551685445ae" +version = "0.11.0" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" dependencies = [ "itertools", "js_int", @@ -2939,9 +2956,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hash" @@ -3009,9 +3026,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.5.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beb461507cee2c2ff151784c52762cf4d9ff6a61f3e80968600ed24fa837fa54" +checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" [[package]] name = "rustls-webpki" @@ -3036,15 +3053,15 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" +checksum = "092474d1a01ea8278f69e6a358998405fae5b8b963ddaeb2b0b04a128bf1dfb0" [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "same-file" @@ -3098,11 +3115,11 @@ checksum = "621e3680f3e07db4c9c2c3fb07c6223ab2fab2e54bd3c04c3ae037990f428c32" [[package]] name = "security-framework" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "core-foundation", "core-foundation-sys", "libc", @@ -3111,9 +3128,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -3121,9 +3138,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "sentry" @@ -3262,22 +3279,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.200" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.200" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -3295,9 +3312,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -3498,7 +3515,7 @@ dependencies = [ "new_debug_unreachable", "once_cell", "parking_lot", - "phf_shared", + "phf_shared 0.10.0", "precomputed-hash", "serde", ] @@ -3509,8 +3526,8 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" dependencies = [ - "phf_generator", - "phf_shared", + "phf_generator 0.10.0", + "phf_shared 0.10.0", "proc-macro2", "quote", ] @@ -3543,9 +3560,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.60" +version = "2.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "c993ed8ccba56ae856363b1845da7266a7cb78e1d146c8a32d54b45a8b831fc9" dependencies = [ "proc-macro2", "quote", @@ -3577,22 +3594,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.59" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.59" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -3741,7 +3758,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -3790,16 +3807,15 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] @@ -3844,7 +3860,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.7", + "winnow 0.6.8", ] [[package]] @@ -3947,7 +3963,7 @@ source = "git+https://github.com/girlbossceo/tracing?branch=tracing-subscriber/e dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -4218,7 +4234,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", "wasm-bindgen-shared", ] @@ -4252,7 +4268,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4295,9 +4311,9 @@ dependencies = [ [[package]] name = "webpage" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb86b12e58d490a99867f561ce8466ffa7b73e24d015a8e7f5bc111d4424ba2" +checksum = "70862efc041d46e6bbaa82bb9c34ae0596d090e86cbd14bd9e93b36ee6802eac" dependencies = [ "html5ever", "markup5ever_rcdom", @@ -4538,9 +4554,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" +checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" dependencies = [ "memchr", ] @@ -4567,9 +4583,9 @@ dependencies = [ [[package]] name = "xml5ever" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4034e1d05af98b51ad7214527730626f019682d797ba38b51689212118d8e650" +checksum = "7c376f76ed09df711203e20c3ef5ce556f0166fa03d39590016c0fd625437fad" dependencies = [ "log", "mac", @@ -4584,22 +4600,22 @@ checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d0d06032..f6420cbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ rust-version = "1.77.0" [dependencies] console-subscriber = { version = "0.2", optional = true } -infer = { version = "0.3", default-features = false } +infer = { version = "0.15", default-features = false } # for hot lib reload hot-lib-reloader = { version = "^0.7", optional = true } @@ -28,7 +28,7 @@ hot-lib-reloader = { version = "^0.7", optional = true } rand = "0.8.5" # Used for conduit::Error type -thiserror = "1.0.59" +thiserror = "1.0.60" # Used to encode server public key base64 = "0.22.1" @@ -133,14 +133,14 @@ features = ["rustls-tls-native-roots", "socks", "hickory-dns"] # all the serde stuff # Used for pdu definition [dependencies.serde] -version = "1.0.200" +version = "1.0.201" features = ["rc"] # Used for appservice registration files [dependencies.serde_yaml] version = "0.9.34" # Used for ruma wrapper [dependencies.serde_json] -version = "1.0.116" +version = "1.0.117" features = ["raw_value"] @@ -234,7 +234,7 @@ features = ["use_std"] # for URL previews [dependencies.webpage] -version = "2.0" +version = "2.0.1" default-features = false # to support multiple variations of setting a config option diff --git a/src/utils/content_disposition.rs b/src/utils/content_disposition.rs index 6df0e14f..f2c1e712 100644 --- a/src/utils/content_disposition.rs +++ b/src/utils/content_disposition.rs @@ -16,7 +16,7 @@ pub(crate) fn content_disposition_type(buf: &[u8], _content_type: &Option "inline", + MatcherType::Image | MatcherType::Audio | MatcherType::Text | MatcherType::Video => "inline", _ => "attachment", } } From fe637f481d3dab691f1a755ce590d4b21b688041 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 11 May 2024 03:41:47 -0400 Subject: [PATCH 0063/2291] ci: fix incorrect startsWith syntax Signed-off-by: strawberry --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93698534..88271ea5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: uses: actions/checkout@v4 - name: Tag comparison check - if: startsWith('refs/tags/v', github.ref) + if: startsWith(github.ref, 'refs/tags/v') run: | # Tag mismatch with latest repo tag check to prevent potential downgrades LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) @@ -150,7 +150,7 @@ jobs: name: Build runs-on: ubuntu-latest needs: tests - if: startsWith('refs/tags/v', github.ref) || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) + if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) strategy: matrix: include: @@ -235,20 +235,20 @@ jobs: name: Docker publish runs-on: ubuntu-latest needs: build - if: (startsWith('refs/tags/v', github.ref) || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)) && (vars.DOCKER_USERNAME != '') && (vars.GITLAB_USERNAME != '') + if: (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)) && (vars.DOCKER_USERNAME != '') && (vars.GITLAB_USERNAME != '') env: DOCKER_ARM64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-arm64v8 DOCKER_AMD64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-amd64 DOCKER_TAG: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }} - DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} + DOCKER_BRANCH: docker.io/${{ github.repository }}:${{ (startsWith(github.ref, 'refs/tags/v') && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} GHCR_ARM64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-arm64v8 GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-amd64 GHCR_TAG: ghcr.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }} - GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} + GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (startsWith(github.ref, 'refs/tags/v') && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} GLCR_ARM64: registry.gitlab.com/conduwuit/conduwuit:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-arm64v8 GLCR_AMD64: registry.gitlab.com/conduwuit/conduwuit:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-amd64 GLCR_TAG: registry.gitlab.com/conduwuit/conduwuit:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }} - GLCR_BRANCH: registry.gitlab.com/conduwuit/conduwuit:${{ (startsWith('refs/tags/v', github.ref) && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} + GLCR_BRANCH: registry.gitlab.com/conduwuit/conduwuit:${{ (startsWith(github.ref, 'refs/tags/v') && 'latest') || (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} From ddce9496f25cd039e4fe8e86c9c69c987984f923 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 11 May 2024 23:30:37 -0400 Subject: [PATCH 0064/2291] nix: fix building rust on macOS (Security apple_sdk framework) Signed-off-by: strawberry --- nix/pkgs/main/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix index bdc97559..30b93e58 100644 --- a/nix/pkgs/main/default.nix +++ b/nix/pkgs/main/default.nix @@ -66,7 +66,11 @@ commonAttrs = { # right thing here. pkgsBuildHost.rustPlatform.bindgenHook ] - ++ lib.optionals stdenv.isDarwin [ libiconv ]; + # https://github.com/NixOS/nixpkgs/issues/206242 + ++ lib.optionals stdenv.isDarwin [ libiconv ] + # https://stackoverflow.com/questions/69869574/properly-adding-darwin-apple-sdk-to-a-nix-shell + # https://discourse.nixos.org/t/compile-a-rust-binary-on-macos-dbcrossbar/8612 + ++ lib.optionals stdenv.isDarwin [ pkgsBuildHost.darwin.apple_sdk.frameworks.Security ]; }; in From ba150a118598209593a80a202e586d35e11257aa Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 11 May 2024 23:31:10 -0400 Subject: [PATCH 0065/2291] nix: stop running unnecessary cargo check on builds Signed-off-by: strawberry --- nix/pkgs/main/default.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix index 30b93e58..3829bfd8 100644 --- a/nix/pkgs/main/default.nix +++ b/nix/pkgs/main/default.nix @@ -89,8 +89,7 @@ craneLib.buildPackage ( commonAttrs // { # This is redundant with CI cargoTestCommand = ""; - - # This is redundant with CI + cargoCheckCommand = ""; doCheck = false; # https://crane.dev/faq/rebuilds-bindgen.html From 37b2c90e620fc1616854a1875b10db7dad163d82 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 11 May 2024 23:32:25 -0400 Subject: [PATCH 0066/2291] chore(nix): bump flake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Updated input 'complement': 'github:matrix-org/complement/891d18872c153d39a9ce63b545045efddb845738' (2024-04-30) → 'github:matrix-org/complement/370a014dca0f720614e0c8f68b9a3e66ecf7f516' (2024-05-02) • Updated input 'crane': 'github:ipetkov/crane/f6c6a2fb1b8bd9b65d65ca9342dd0eb180a63f11' (2024-04-21) → 'github:ipetkov/crane/27025ab71bdca30e7ed0a16c88fd74c5970fc7f5' (2024-05-09) • Updated input 'fenix': 'github:nix-community/fenix/73124e1356bde9411b163d636b39fe4804b7ca45' (2024-05-01) → 'github:nix-community/fenix/297c756ba6249d483c1dafe42378560458842173' (2024-05-10) • Updated input 'fenix/rust-analyzer-src': 'github:rust-lang/rust-analyzer/55d9a533b309119c8acd13061581b43ae8840823' (2024-04-20) → 'github:rust-lang/rust-analyzer/5bf2f85c8054d80424899fa581db1b192230efb5' (2024-05-09) • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/5c24cf2f0a12ad855f444c30b2421d044120c66f' (2024-04-19) → 'github:NixOS/nixpkgs/f1010e0469db743d14519a1efd37e23f8513d714' (2024-05-09) Signed-off-by: strawberry --- flake.lock | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/flake.lock b/flake.lock index 40b38ef7..f38d07bc 100644 --- a/flake.lock +++ b/flake.lock @@ -26,11 +26,11 @@ "complement": { "flake": false, "locked": { - "lastModified": 1714472853, - "narHash": "sha256-CNRHSZe3TE+3tFj2dHNyxTMjDqL0MKY3P/3jqUgA7YE=", + "lastModified": 1714661560, + "narHash": "sha256-E1ZiUbOgo7rWo8zt2M2vzCVSykCxK0Ot2dUAxTL6cpU=", "owner": "matrix-org", "repo": "complement", - "rev": "891d18872c153d39a9ce63b545045efddb845738", + "rev": "370a014dca0f720614e0c8f68b9a3e66ecf7f516", "type": "github" }, "original": { @@ -68,11 +68,11 @@ ] }, "locked": { - "lastModified": 1713738183, - "narHash": "sha256-qd/MuLm7OfKQKyd4FAMqV4H6zYyOfef5lLzRrmXwKJM=", + "lastModified": 1715274763, + "narHash": "sha256-3Iv1PGHJn9sV3HO4FlOVaaztOxa9uGLfOmUWrH7v7+A=", "owner": "ipetkov", "repo": "crane", - "rev": "f6c6a2fb1b8bd9b65d65ca9342dd0eb180a63f11", + "rev": "27025ab71bdca30e7ed0a16c88fd74c5970fc7f5", "type": "github" }, "original": { @@ -90,11 +90,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1714544767, - "narHash": "sha256-kF1bX+YFMedf1g0PAJYwGUkzh22JmULtj8Rm4IXAQKs=", + "lastModified": 1715322226, + "narHash": "sha256-ezoe/FwfJpA7sskLoLP2iwfwkYnscEFCP6Vk5kPwh9k=", "owner": "nix-community", "repo": "fenix", - "rev": "73124e1356bde9411b163d636b39fe4804b7ca45", + "rev": "297c756ba6249d483c1dafe42378560458842173", "type": "github" }, "original": { @@ -221,11 +221,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1713537308, - "narHash": "sha256-XtTSSIB2DA6tOv+l0FhvfDMiyCmhoRbNB+0SeInZkbk=", + "lastModified": 1715266358, + "narHash": "sha256-doPgfj+7FFe9rfzWo1siAV2mVCasW+Bh8I1cToAXEE4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5c24cf2f0a12ad855f444c30b2421d044120c66f", + "rev": "f1010e0469db743d14519a1efd37e23f8513d714", "type": "github" }, "original": { @@ -268,11 +268,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1713628977, - "narHash": "sha256-iN5QUlUq527lswmBC+RopfXdu6Xx7mmTaBSH2l59FtM=", + "lastModified": 1715255944, + "narHash": "sha256-vLLgYpdtKBaGYTamNLg1rbRo1bPXp4Jgded/gnprPVw=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "55d9a533b309119c8acd13061581b43ae8840823", + "rev": "5bf2f85c8054d80424899fa581db1b192230efb5", "type": "github" }, "original": { From da9a0eb77bc634dde0039520b84efef9a0f3da41 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 11 May 2024 23:53:42 -0400 Subject: [PATCH 0067/2291] docs: fix broken systemd unit link Signed-off-by: strawberry --- debian/README.md | 2 +- docs/configuration.md | 6 ++++++ docs/deploying/generic.md | 2 +- nix/pkgs/book/default.nix | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/debian/README.md b/debian/README.md index 280f6585..a3f5d57c 100644 --- a/debian/README.md +++ b/debian/README.md @@ -22,7 +22,7 @@ file size for download/upload, enabling federation, etc. Running ------- -The package uses the `conduwuit.service` systemd unit file to start and +The package uses the [`conduwuit.service`](../configuration.md#example-systemd-unit-file) systemd unit file to start and stop conduwuit. It loads the configuration file mentioned above to set up the environment before running the server. diff --git a/docs/configuration.md b/docs/configuration.md index 70069af0..6627c3b6 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -3,3 +3,9 @@ ``` toml {{#include ../conduwuit-example.toml}} ``` + +# Example systemd unit file + +``` +{{#include ../debian/conduwuit.service}} +``` diff --git a/docs/deploying/generic.md b/docs/deploying/generic.md index abc8cc41..e23c75d4 100644 --- a/docs/deploying/generic.md +++ b/docs/deploying/generic.md @@ -43,7 +43,7 @@ If conduwuit runs behind a router or in a container and has a different public I ## Setting up a systemd service -The systemd unit for conduwuit can be found [here](../../debian/conduwuit.service). You may need to change the `ExecStart=` path to where you placed the conduwuit binary. +The systemd unit for conduwuit can be found [here](../configuration.md#example-systemd-unit-file). You may need to change the `ExecStart=` path to where you placed the conduwuit binary. ## Creating the conduwuit configuration file diff --git a/nix/pkgs/book/default.nix b/nix/pkgs/book/default.nix index 23c6e783..c1e5b8e4 100644 --- a/nix/pkgs/book/default.nix +++ b/nix/pkgs/book/default.nix @@ -16,6 +16,7 @@ stdenv.mkDerivation { "conduwuit-example.toml" "CONTRIBUTING.md" "README.md" + "debian/conduwuit.service" "debian/README.md" "docs" ]; From 1cd57f40f62def93d0a3152b10dd5d18ce569933 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 12 May 2024 00:22:10 -0400 Subject: [PATCH 0068/2291] upload complement OCI image from CI, document where it can be found, use `main` instead of `dev` for tag Signed-off-by: strawberry --- .github/workflows/ci.yml | 8 ++++++++ bin/complement | 2 +- docs/development/testing.md | 10 ++++++---- nix/pkgs/complement/default.nix | 4 ++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88271ea5..a1c1839d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -107,6 +107,14 @@ jobs: - name: Run Complement tests run: | direnv exec . bin/complement 'complement_src' 'complement_test_logs.jsonl' 'complement_test_results.jsonl' + cp -v -f result complement_oci_image.tar.gz + + - name: Upload Complement OCI image + uses: actions/upload-artifact@v4 + with: + name: complement_oci_image.tar.gz + path: complement_oci_image.tar.gz + if-no-files-found: error - name: Upload Complement logs uses: actions/upload-artifact@v4 diff --git a/bin/complement b/bin/complement index c2c6ab34..115a94e0 100755 --- a/bin/complement +++ b/bin/complement @@ -15,7 +15,7 @@ LOG_FILE="$2" # A `.jsonl` file to write test results to RESULTS_FILE="$3" -OCI_IMAGE="complement-conduit:dev" +OCI_IMAGE="complement-conduit:main" toplevel="$(git rev-parse --show-toplevel)" diff --git a/docs/development/testing.md b/docs/development/testing.md index d4838988..680e6fb9 100644 --- a/docs/development/testing.md +++ b/docs/development/testing.md @@ -5,13 +5,15 @@ Have a look at [Complement's repository][complement] for an explanation of what it is. -To test against Complement, with Nix and direnv installed and set up, you can -either: +To test against Complement, with Nix and direnv installed and set up, you can: * Run `./bin/complement "$COMPLEMENT_SRC" ./path/to/logs.jsonl ./path/to/results.jsonl` to build a Complement image, run the tests, and output the logs and results - to the specified paths + to the specified paths. This will also output the OCI image at `result` * Run `nix build .#complement` from the root of the repository to just build a - Complement image + Complement OCI image outputted to `result` (it's a `.tar.gz` file) +* Or download the latest Complement OCI image from the CI workflow artifacts output + from the commit/revision you want to test (e.g. from main) [here][ci-workflows] +[ci-workflows]: https://github.com/girlbossceo/conduwuit/actions/workflows/ci.yml?query=event%3Apush+is%3Asuccess+actor%3Agirlbossceo [complement]: https://github.com/matrix-org/complement diff --git a/nix/pkgs/complement/default.nix b/nix/pkgs/complement/default.nix index 0399f1e8..f7bb483f 100644 --- a/nix/pkgs/complement/default.nix +++ b/nix/pkgs/complement/default.nix @@ -53,7 +53,7 @@ in dockerTools.buildImage { name = "complement-${main.pname}"; - tag = "dev"; + tag = "main"; copyToRoot = buildEnv { name = "root"; @@ -81,7 +81,7 @@ dockerTools.buildImage { Env = [ "SSL_CERT_FILE=/complement/ca/ca.crt" - "CONDUIT_CONFIG=${./config.toml}" + "CONDUWUIT_CONFIG=${./config.toml}" ]; ExposedPorts = { From 714b3e714494f5cb46c23eb52e88eda8e818c186 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 12 May 2024 00:37:00 -0400 Subject: [PATCH 0069/2291] s/nix/lix in a couple places Signed-off-by: strawberry --- docs/deploying/nixos.md | 3 ++- docs/development/testing.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/deploying/nixos.md b/docs/deploying/nixos.md index 094aab02..6074e2a7 100644 --- a/docs/deploying/nixos.md +++ b/docs/deploying/nixos.md @@ -1,6 +1,6 @@ # conduwuit for NixOS -conduwuit can be acquired by Nix from various places: +conduwuit can be acquired by [Lix][lix] from various places: * The `flake.nix` at the root of the repo * The `default.nix` at the root of the repo @@ -26,5 +26,6 @@ If you want to run the latest code, you should get Conduwuit from the `flake.nix or `default.nix` and set [`services.matrix-conduit.package`][package] appropriately. +[lix]: https://lix.systems/ [module]: https://search.nixos.org/options?channel=unstable&query=services.matrix-conduit [package]: https://search.nixos.org/options?channel=unstable&query=services.matrix-conduit.package diff --git a/docs/development/testing.md b/docs/development/testing.md index 680e6fb9..f3fb7d9d 100644 --- a/docs/development/testing.md +++ b/docs/development/testing.md @@ -5,7 +5,7 @@ Have a look at [Complement's repository][complement] for an explanation of what it is. -To test against Complement, with Nix and direnv installed and set up, you can: +To test against Complement, with [Lix][lix] and direnv installed and set up, you can: * Run `./bin/complement "$COMPLEMENT_SRC" ./path/to/logs.jsonl ./path/to/results.jsonl` to build a Complement image, run the tests, and output the logs and results @@ -15,5 +15,6 @@ To test against Complement, with Nix and direnv installed and set up, you can: * Or download the latest Complement OCI image from the CI workflow artifacts output from the commit/revision you want to test (e.g. from main) [here][ci-workflows] +[lix]: https://lix.systems/ [ci-workflows]: https://github.com/girlbossceo/conduwuit/actions/workflows/ci.yml?query=event%3Apush+is%3Asuccess+actor%3Agirlbossceo [complement]: https://github.com/matrix-org/complement From 78994deb1ea37ef748d194f28a2701aadc2fcabe Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 12 May 2024 01:13:23 -0400 Subject: [PATCH 0070/2291] nix: simplify isDarwin lib check Signed-off-by: strawberry --- nix/pkgs/main/default.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix index 3829bfd8..f546a328 100644 --- a/nix/pkgs/main/default.nix +++ b/nix/pkgs/main/default.nix @@ -66,11 +66,14 @@ commonAttrs = { # right thing here. pkgsBuildHost.rustPlatform.bindgenHook ] + ++ lib.optionals stdenv.isDarwin [ # https://github.com/NixOS/nixpkgs/issues/206242 - ++ lib.optionals stdenv.isDarwin [ libiconv ] + libiconv + # https://stackoverflow.com/questions/69869574/properly-adding-darwin-apple-sdk-to-a-nix-shell # https://discourse.nixos.org/t/compile-a-rust-binary-on-macos-dbcrossbar/8612 - ++ lib.optionals stdenv.isDarwin [ pkgsBuildHost.darwin.apple_sdk.frameworks.Security ]; + pkgsBuildHost.darwin.apple_sdk.frameworks.Security + ]; }; in From 80bc1cd78a2523e9ead709c6ac88b1631e56aeb5 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 12 May 2024 01:14:03 -0400 Subject: [PATCH 0071/2291] ci: output 100 failure summary lines instead of 50 Signed-off-by: strawberry --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1c1839d..15562d35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -140,7 +140,7 @@ jobs: run: | echo '# Complement diff results' >> $GITHUB_STEP_SUMMARY echo '```diff' >> $GITHUB_STEP_SUMMARY - tail -n 50 complement_test_output.log | sed 's/\x1b\[[0-9;]*m//g' >> $GITHUB_STEP_SUMMARY + tail -n 100 complement_test_output.log | sed 's/\x1b\[[0-9;]*m//g' >> $GITHUB_STEP_SUMMARY echo '```' >> $GITHUB_STEP_SUMMARY - name: Update Job Summary From 040cf2905109a4cdce7229a248b5a3111d7d6ab1 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 12 May 2024 01:31:05 -0400 Subject: [PATCH 0072/2291] ci: add lix binary cache, update .gitlab-ci file Signed-off-by: strawberry --- .github/workflows/ci.yml | 4 ++-- .gitlab-ci.yml | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15562d35..9fc2cf60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,8 +75,8 @@ jobs: - name: Apply Nix binary cache configuration run: | sudo tee -a /etc/nix/nix.conf > /dev/null < /dev/null && [ -n "$ATTIC_ENDPOINT" ]; then echo "extra-substituters = $ATTIC_ENDPOINT" >> /etc/nix/nix.conf; fi - if command -v nix > /dev/null && [ -n "$ATTIC_PUBLIC_KEY" ]; then echo "extra-trusted-public-keys = $ATTIC_PUBLIC_KEY" >> /etc/nix/nix.conf; fi + # Add Lix binary cache + - if command -v nix > /dev/null; then echo "extra-substituters = https://cache.lix.systems" >> /etc/nix/nix.conf; fi + - if command -v nix > /dev/null; then echo "extra-trusted-public-keys = cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o=" >> /etc/nix/nix.conf; fi + # Add crane binary cache - if command -v nix > /dev/null; then echo "extra-substituters = https://crane.cachix.org" >> /etc/nix/nix.conf; fi - if command -v nix > /dev/null; then echo "extra-trusted-public-keys = crane.cachix.org-1:8Scfpmn9w+hGdXH/Q9tTLiYAE/2dnJYRJP7kl80GuRk=" >> /etc/nix/nix.conf; fi @@ -49,12 +53,15 @@ before_script: # Allow .envrc - if command -v nix > /dev/null; then direnv allow; fi + # Cache attic client + - if command -v nix > /dev/null; then ./bin/nix-build-and-cache --inputs-from . attic; fi + # Set CARGO_HOME to a cacheable path - export CARGO_HOME="$(git rev-parse --show-toplevel)/.gitlab-ci.d/cargo" ci: stage: ci - image: nixos/nix:2.22.0 + image: nixos/nix:2.22.1 script: # Cache CI dependencies - ./bin/nix-build-and-cache ci From bfa33f8713b458deada91f43a523daf34be100d6 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 12 May 2024 01:49:38 -0400 Subject: [PATCH 0073/2291] unpin rust-rocksdb version Signed-off-by: strawberry --- Cargo.lock | 4 ++-- Cargo.toml | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 20352010..73209431 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2931,7 +2931,7 @@ dependencies = [ [[package]] name = "rust-librocksdb-sys" version = "0.21.0+9.1.1" -source = "git+https://github.com/zaidoon1/rust-rocksdb?rev=c5cd6bd25152ef1f8a488761351da0c3d29ed93a#c5cd6bd25152ef1f8a488761351da0c3d29ed93a" +source = "git+https://github.com/zaidoon1/rust-rocksdb?branch=master#6f0afedb3c29239b1d8a15a97ed8e6b74e0a9b33" dependencies = [ "bindgen", "bzip2-sys", @@ -2948,7 +2948,7 @@ dependencies = [ [[package]] name = "rust-rocksdb" version = "0.25.0" -source = "git+https://github.com/zaidoon1/rust-rocksdb?rev=c5cd6bd25152ef1f8a488761351da0c3d29ed93a#c5cd6bd25152ef1f8a488761351da0c3d29ed93a" +source = "git+https://github.com/zaidoon1/rust-rocksdb?branch=master#6f0afedb3c29239b1d8a15a97ed8e6b74e0a9b33" dependencies = [ "libc", "rust-librocksdb-sys", diff --git a/Cargo.toml b/Cargo.toml index f6420cbc..9ca75672 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -299,8 +299,7 @@ default-features = false [dependencies.rust-rocksdb] git = "https://github.com/zaidoon1/rust-rocksdb" -rev = "c5cd6bd25152ef1f8a488761351da0c3d29ed93a" -#branch = "master" +branch = "master" optional = true default-features = true features = ["multi-threaded-cf", "zstd"] From 2bd7a92256849dd2a49c8a01c4bd3254bf023ef7 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 12 May 2024 02:41:04 -0400 Subject: [PATCH 0074/2291] complement: add `-tags="conduwuit_blacklist"` Signed-off-by: strawberry --- bin/complement | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/complement b/bin/complement index 115a94e0..68f48680 100755 --- a/bin/complement +++ b/bin/complement @@ -31,7 +31,7 @@ set +o pipefail env \ -C "$COMPLEMENT_SRC" \ COMPLEMENT_BASE_IMAGE="$OCI_IMAGE" \ - go test -vet=off -timeout 1h -json ./tests | tee "$LOG_FILE" + go test -tags="conduwuit_blacklist" -v -timeout 1h -json ./tests | tee "$LOG_FILE" set -o pipefail # Post-process the results into an easy-to-compare format, sorted by Test name for reproducible results From 829307c83b06885ba85ff1bcee47c13eb352b060 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 12 May 2024 03:18:13 -0400 Subject: [PATCH 0075/2291] disallow svg MIME types to be `inline` Content-Disposition Signed-off-by: strawberry --- src/utils/content_disposition.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/content_disposition.rs b/src/utils/content_disposition.rs index f2c1e712..f93f6728 100644 --- a/src/utils/content_disposition.rs +++ b/src/utils/content_disposition.rs @@ -16,7 +16,13 @@ pub(crate) fn content_disposition_type(buf: &[u8], _content_type: &Option "inline", + MatcherType::Image | MatcherType::Audio | MatcherType::Text | MatcherType::Video => { + if file_type.mime_type().contains("svg") { + "attachment" + } else { + "inline" + } + }, _ => "attachment", } } From 4185a3374757f0e19b8d8961c4b910aec6450d32 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 12 May 2024 12:42:34 -0400 Subject: [PATCH 0076/2291] fix: we should be checking for `xml` MIME type instead Signed-off-by: strawberry --- src/utils/content_disposition.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/content_disposition.rs b/src/utils/content_disposition.rs index f93f6728..591d5c40 100644 --- a/src/utils/content_disposition.rs +++ b/src/utils/content_disposition.rs @@ -1,5 +1,7 @@ use infer::MatcherType; +use crate::debug_info; + /// Returns a Content-Disposition of `attachment` or `inline`, depending on the /// *parsed* contents of the file uploaded via format magic keys using `infer` /// crate (basically libmagic without needing libmagic). @@ -15,9 +17,11 @@ pub(crate) fn content_disposition_type(buf: &[u8], _content_type: &Option { - if file_type.mime_type().contains("svg") { + if file_type.mime_type().contains("xml") { "attachment" } else { "inline" From 434b5118cc41b3359b502794bf3d39583d5f9e26 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 12 May 2024 14:50:27 -0400 Subject: [PATCH 0077/2291] media: return our detected MIME type for Content-Type Signed-off-by: strawberry --- src/api/client_server/media.rs | 38 ++++++++++++++++++--------- src/utils/content_disposition.rs | 44 +++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 19 deletions(-) diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index e4e7376d..b294fec2 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -19,7 +19,9 @@ use crate::{ services, utils::{ self, - content_disposition::{content_disposition_type, make_content_disposition, sanitise_filename}, + content_disposition::{ + content_disposition_type, make_content_disposition, make_content_type, sanitise_filename, + }, server_name::server_is_ours, }, Error, Result, Ruma, RumaResponse, @@ -127,6 +129,8 @@ pub(crate) async fn create_content_route( utils::random_string(MXC_LENGTH) ); + let content_type = Some(make_content_type(&body.file, &body.content_type).to_owned()); + services() .media .create( @@ -137,20 +141,18 @@ pub(crate) async fn create_content_route( .map(|filename| { format!( "{}; filename={}", - content_disposition_type(&body.file, &body.content_type), + content_disposition_type(&body.file, &content_type), sanitise_filename(filename.to_owned()) ) }) .as_deref(), - body.content_type.as_deref(), + content_type.as_deref(), &body.file, ) .await?; - let content_uri = mxc.into(); - Ok(create_content::v3::Response { - content_uri, + content_uri: mxc.into(), blurhash: None, }) } @@ -189,6 +191,7 @@ pub(crate) async fn get_content_route(body: Ruma) -> R }) = services().media.get(mxc.clone()).await? { let content_disposition = Some(make_content_disposition(&file, &content_type, content_disposition)); + let content_type = Some(make_content_type(&file, &content_type).to_owned()); Ok(get_content::v3::Response { file, @@ -216,10 +219,11 @@ pub(crate) async fn get_content_route(body: Ruma) -> R &response.content_type, response.content_disposition, )); + let content_type = Some(make_content_type(&response.file, &response.content_type).to_owned()); Ok(get_content::v3::Response { file: response.file, - content_type: response.content_type, + content_type, content_disposition, cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.to_owned()), @@ -267,6 +271,7 @@ pub(crate) async fn get_content_as_filename_route( }) = services().media.get(mxc.clone()).await? { let content_disposition = Some(make_content_disposition(&file, &content_type, content_disposition)); + let content_type = Some(make_content_type(&file, &content_type).to_owned()); Ok(get_content_as_filename::v3::Response { file, @@ -291,10 +296,13 @@ pub(crate) async fn get_content_as_filename_route( &remote_content_response.content_type, remote_content_response.content_disposition, )); + let content_type = Some( + make_content_type(&remote_content_response.file, &remote_content_response.content_type).to_owned(), + ); Ok(get_content_as_filename::v3::Response { content_disposition, - content_type: remote_content_response.content_type, + content_type, file: remote_content_response.file, cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), @@ -359,6 +367,7 @@ pub(crate) async fn get_content_thumbnail_route( .await? { let content_disposition = Some(make_content_disposition(&file, &content_type, content_disposition)); + let content_type = Some(make_content_type(&file, &content_type).to_owned()); Ok(get_content_thumbnail::v3::Response { file, @@ -371,7 +380,7 @@ pub(crate) async fn get_content_thumbnail_route( if services() .globals .prevent_media_downloads_from() - .contains(&body.server_name.clone()) + .contains(&body.server_name) { // we'll lie to the client and say the blocked server's media was not found and // log. the client has no way of telling anyways so this is a security bonus. @@ -415,10 +424,13 @@ pub(crate) async fn get_content_thumbnail_route( &get_thumbnail_response.content_type, get_thumbnail_response.content_disposition, )); + let content_type = Some( + make_content_type(&get_thumbnail_response.file, &get_thumbnail_response.content_type).to_owned(), + ); Ok(get_content_thumbnail::v3::Response { file: get_thumbnail_response.file, - content_type: get_thumbnail_response.content_type, + content_type, cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.to_owned()), content_disposition, @@ -486,20 +498,22 @@ async fn get_remote_content( content_response.content_disposition, )); + let content_type = Some(make_content_type(&content_response.file, &content_response.content_type).to_owned()); + services() .media .create( None, mxc.to_owned(), content_disposition.as_deref(), - content_response.content_type.as_deref(), + content_type.as_deref(), &content_response.file, ) .await?; Ok(get_content::v3::Response { file: content_response.file, - content_type: content_response.content_type, + content_type, content_disposition, cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()), cache_control: Some(CACHE_CONTROL_IMMUTABLE.to_owned()), diff --git a/src/utils/content_disposition.rs b/src/utils/content_disposition.rs index 591d5c40..9ef93bbf 100644 --- a/src/utils/content_disposition.rs +++ b/src/utils/content_disposition.rs @@ -2,6 +2,11 @@ use infer::MatcherType; use crate::debug_info; +const ATTACHMENT: &str = "attachment"; +const INLINE: &str = "inline"; +const APPLICATION_OCTET_STREAM: &str = "application/octet-stream"; +const IMAGE_SVG_XML: &str = "image/svg+xml"; + /// Returns a Content-Disposition of `attachment` or `inline`, depending on the /// *parsed* contents of the file uploaded via format magic keys using `infer` /// crate (basically libmagic without needing libmagic). @@ -12,9 +17,10 @@ use crate::debug_info; /// /// TODO: add a "strict" function for comparing the Content-Type with what we /// detected: `file_type.mime_type() != content_type` -pub(crate) fn content_disposition_type(buf: &[u8], _content_type: &Option) -> &'static str { +#[tracing::instrument(skip(buf))] +pub(crate) fn content_disposition_type(buf: &[u8], content_type: &Option) -> &'static str { let Some(file_type) = infer::get(buf) else { - return "attachment"; + return ATTACHMENT; }; debug_info!("MIME type: {}", file_type.mime_type()); @@ -22,15 +28,37 @@ pub(crate) fn content_disposition_type(buf: &[u8], _content_type: &Option { if file_type.mime_type().contains("xml") { - "attachment" + ATTACHMENT } else { - "inline" + INLINE } }, - _ => "attachment", + _ => ATTACHMENT, } } +/// overrides the Content-Type with what we detected +/// +/// SVG is special-cased due to the MIME type being classified as `text/xml` but +/// browsers need `image/svg+xml` +#[tracing::instrument(skip(buf))] +pub(crate) fn make_content_type(buf: &[u8], content_type: &Option) -> &'static str { + let Some(file_type) = infer::get(buf) else { + debug_info!("Failed to infer the file's contents"); + return APPLICATION_OCTET_STREAM; + }; + + let Some(claimed_content_type) = content_type else { + return file_type.mime_type(); + }; + + if claimed_content_type.contains("svg") && file_type.mime_type().contains("xml") { + return IMAGE_SVG_XML; + } + + file_type.mime_type() +} + /// sanitises the file name for the Content-Disposition using /// `sanitize_filename` crate #[tracing::instrument] @@ -46,8 +74,10 @@ pub(crate) fn sanitise_filename(filename: String) -> String { /// creates the final Content-Disposition based on whether the filename exists /// or not. /// -/// if filename exists: `Content-Disposition: attachment/inline; -/// filename=filename.ext` else: `Content-Disposition: attachment/inline` +/// if filename exists: +/// `Content-Disposition: attachment/inline; filename=filename.ext` +/// +/// else: `Content-Disposition: attachment/inline` #[tracing::instrument(skip(file))] pub(crate) fn make_content_disposition( file: &[u8], content_type: &Option, content_disposition: Option, From edd67a102a16af0dd37e9276d822f6ccbe5de3dc Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 13 May 2024 15:36:20 -0400 Subject: [PATCH 0078/2291] ci(debian): add missing `--target=` for arm64 debs, add `--verbose` Signed-off-by: strawberry --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9fc2cf60..4caf034a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -209,7 +209,7 @@ jobs: bin/nix-build-and-cache just .#static-${{ matrix.target }} mkdir -p target/release cp -v -f result/bin/conduit target/release/ - direnv exec . cargo deb --no-build --no-strip --output target/debian/${{ matrix.target }}.deb + direnv exec . cargo deb --verbose --no-build --no-strip --target=${{ matrix.target }} --output target/debian/${{ matrix.target }}.deb mv target/release/conduit static-${{ matrix.target }} - name: Upload static-${{ matrix.target }} From 6e9f68bf811f2d408bc80c3a3782ce4ea84d7787 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 13 May 2024 16:52:21 -0400 Subject: [PATCH 0079/2291] chore: update complement test results Signed-off-by: strawberry --- .../complement/test_results.jsonl | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tests/test_results/complement/test_results.jsonl b/tests/test_results/complement/test_results.jsonl index a04371af..f40204ba 100644 --- a/tests/test_results/complement/test_results.jsonl +++ b/tests/test_results/complement/test_results.jsonl @@ -67,7 +67,7 @@ {"Action":"pass","Test":"TestFederationRoomsInvite/Parallel/Invited_user_can_reject_invite_over_federation_for_empty_room"} {"Action":"fail","Test":"TestFederationRoomsInvite/Parallel/Invited_user_can_reject_invite_over_federation_several_times"} {"Action":"pass","Test":"TestFederationRoomsInvite/Parallel/Invited_user_has_'is_direct'_flag_in_prev_content_after_joining"} -{"Action":"fail","Test":"TestFederationRoomsInvite/Parallel/Remote_invited_user_can_see_room_metadata"} +{"Action":"pass","Test":"TestFederationRoomsInvite/Parallel/Remote_invited_user_can_see_room_metadata"} {"Action":"fail","Test":"TestGetMissingEventsGapFilling"} {"Action":"fail","Test":"TestInboundCanReturnMissingEvents"} {"Action":"fail","Test":"TestInboundCanReturnMissingEvents/Inbound_federation_can_return_missing_events_for_invited_visibility"} @@ -83,6 +83,7 @@ {"Action":"pass","Test":"TestIsDirectFlagLocal"} {"Action":"pass","Test":"TestJoinFederatedRoomFailOver"} {"Action":"fail","Test":"TestJoinFederatedRoomFromApplicationServiceBridgeUser"} +{"Action":"fail","Test":"TestJoinFederatedRoomFromApplicationServiceBridgeUser/join_remote_federated_room_as_application_service_user"} {"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents"} {"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_missing_signatures_shouldn't_block_room_join"} {"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_with_bad_signatures_shouldn't_block_room_join"} @@ -90,6 +91,20 @@ {"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_with_unobtainable_keys_shouldn't_block_room_join"} {"Action":"pass","Test":"TestJoinViaRoomIDAndServerName"} {"Action":"fail","Test":"TestJumpToDateEndpoint"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/federation"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/federation/can_paginate_after_getting_remote_event_from_timestamp_to_event_endpoint"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/federation/looking_backwards,_should_be_able_to_find_event_that_was_sent_before_we_joined"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/federation/looking_forwards,_should_be_able_to_find_event_that_was_sent_before_we_joined"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/federation/when_looking_backwards_before_the_room_was_created,_should_be_able_to_find_event_that_was_imported"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_find_event_after_given_timestmap"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_find_event_before_given_timestmap"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_find_next_event_topologically_after_given_timestmap_when_all_message_timestamps_are_the_same"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_find_next_event_topologically_before_given_timestamp_when_all_message_timestamps_are_the_same"} +{"Action":"pass","Test":"TestJumpToDateEndpoint/parallel/should_find_nothing_after_the_latest_timestmap"} +{"Action":"pass","Test":"TestJumpToDateEndpoint/parallel/should_find_nothing_before_the_earliest_timestmap"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_not_be_able_to_query_a_private_room_you_are_not_a_member_of"} +{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_not_be_able_to_query_a_public_room_you_are_not_a_member_of"} {"Action":"fail","Test":"TestKnockRoomsInPublicRoomsDirectory"} {"Action":"fail","Test":"TestKnockRoomsInPublicRoomsDirectoryInMSC3787Room"} {"Action":"fail","Test":"TestKnocking"} @@ -151,7 +166,7 @@ {"Action":"pass","Test":"TestMediaFilenames/Parallel/ASCII/Can_download_file_'ascii'"} {"Action":"fail","Test":"TestMediaFilenames/Parallel/ASCII/Can_download_file_'name;with;semicolons'"} {"Action":"fail","Test":"TestMediaFilenames/Parallel/ASCII/Can_download_file_'name_with_spaces'"} -{"Action":"pass","Test":"TestMediaFilenames/Parallel/ASCII/Can_download_specifying_a_different_ASCII_file_name"} +{"Action":"fail","Test":"TestMediaFilenames/Parallel/ASCII/Can_download_specifying_a_different_ASCII_file_name"} {"Action":"pass","Test":"TestMediaFilenames/Parallel/ASCII/Can_upload_with_ASCII_file_name"} {"Action":"fail","Test":"TestMediaFilenames/Parallel/Unicode"} {"Action":"fail","Test":"TestMediaFilenames/Parallel/Unicode/Can_download_specifying_a_different_Unicode_file_name"} @@ -161,10 +176,10 @@ {"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_safe_media_types_as_inline"} {"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_safe_media_types_with_parameters_as_inline"} {"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_unsafe_media_types_as_attachments"} -{"Action":"pass","Test":"TestMediaWithoutFileName"} -{"Action":"pass","Test":"TestMediaWithoutFileName/parallel"} -{"Action":"pass","Test":"TestMediaWithoutFileName/parallel/Can_download_without_a_file_name_locally"} -{"Action":"pass","Test":"TestMediaWithoutFileName/parallel/Can_download_without_a_file_name_over_federation"} +{"Action":"fail","Test":"TestMediaWithoutFileName"} +{"Action":"fail","Test":"TestMediaWithoutFileName/parallel"} +{"Action":"fail","Test":"TestMediaWithoutFileName/parallel/Can_download_without_a_file_name_locally"} +{"Action":"fail","Test":"TestMediaWithoutFileName/parallel/Can_download_without_a_file_name_over_federation"} {"Action":"pass","Test":"TestMediaWithoutFileName/parallel/Can_upload_without_a_file_name"} {"Action":"fail","Test":"TestNetworkPartitionOrdering"} {"Action":"fail","Test":"TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6"} @@ -208,11 +223,12 @@ {"Action":"fail","Test":"TestRestrictedRoomsSpacesSummaryFederation"} {"Action":"fail","Test":"TestRestrictedRoomsSpacesSummaryLocal"} {"Action":"skip","Test":"TestSendJoinPartialStateResponse"} +{"Action":"pass","Test":"TestSyncOmitsStateChangeOnFilteredEvents"} {"Action":"fail","Test":"TestToDeviceMessagesOverFederation"} {"Action":"pass","Test":"TestToDeviceMessagesOverFederation/good_connectivity"} {"Action":"pass","Test":"TestToDeviceMessagesOverFederation/interrupted_connectivity"} {"Action":"fail","Test":"TestToDeviceMessagesOverFederation/stopped_server"} -{"Action":"fail","Test":"TestUnbanViaInvite"} +{"Action":"pass","Test":"TestUnbanViaInvite"} {"Action":"fail","Test":"TestUnknownEndpoints"} {"Action":"pass","Test":"TestUnknownEndpoints/Client-server_endpoints"} {"Action":"fail","Test":"TestUnknownEndpoints/Key_endpoints"} From 60742984264b5bd1dcb608cd7ad5305d14ad8659 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 13 May 2024 17:25:15 -0400 Subject: [PATCH 0080/2291] ci: allow build job to be ran for all events except for draft PRs this allows build to be ran for workflow_dispatch Signed-off-by: strawberry --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4caf034a..873b29bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -158,7 +158,7 @@ jobs: name: Build runs-on: ubuntu-latest needs: tests - if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false) + if: github.event.pull_request.draft != true strategy: matrix: include: @@ -243,7 +243,7 @@ jobs: name: Docker publish runs-on: ubuntu-latest needs: build - if: (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)) && (vars.DOCKER_USERNAME != '') && (vars.GITLAB_USERNAME != '') + if: (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || (github.event.pull_request.draft != true)) && (vars.DOCKER_USERNAME != '') && (vars.GITLAB_USERNAME != '') env: DOCKER_ARM64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-arm64v8 DOCKER_AMD64: docker.io/${{ github.repository }}:${{ (github.head_ref != '' && format('merge-{0}-{1}', github.event.number, github.event.pull_request.user.login)) || github.ref_name }}-${{ github.sha }}-amd64 From 4c11c9f048f8b1154893e3383c6eb354f63bb8d1 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 13 May 2024 17:35:23 -0400 Subject: [PATCH 0081/2291] ci: use target-specific dirs for cargo-deb, fix cargo-deb paths Signed-off-by: strawberry --- .github/workflows/ci.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 873b29bc..e0abde96 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -207,10 +207,11 @@ jobs: - name: Build static ${{ matrix.target }} run: | bin/nix-build-and-cache just .#static-${{ matrix.target }} - mkdir -p target/release - cp -v -f result/bin/conduit target/release/ - direnv exec . cargo deb --verbose --no-build --no-strip --target=${{ matrix.target }} --output target/debian/${{ matrix.target }}.deb - mv target/release/conduit static-${{ matrix.target }} + mkdir -p target/release/${{ matrix.target }} + cp -v -f result/bin/conduit target/release/${{ matrix.target }} + direnv exec . cargo deb --verbose --no-build --no-strip --target=${{ matrix.target }} --output target/release/${{ matrix.target }}/${{ matrix.target }}.deb + mv -v target/release/${{ matrix.target }}/conduit static-${{ matrix.target }} + mv -v target/release/${{ matrix.target }}/${{ matrix.target }}.deb ${{ matrix.target }}.deb - name: Upload static-${{ matrix.target }} uses: actions/upload-artifact@v4 @@ -223,7 +224,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: deb-${{ matrix.target }} - path: target/debian/${{ matrix.target }}.deb + path: ${{ matrix.target }}.deb if-no-files-found: error - name: Build OCI image ${{ matrix.target }} From de6b296eb55b8218fd201d64562134e1504f1b37 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 13 May 2024 17:36:19 -0400 Subject: [PATCH 0082/2291] ci: use verbose for mv operations Signed-off-by: strawberry --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0abde96..e24e777e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -290,8 +290,8 @@ jobs: - name: Move OCI images into position run: | - mv oci-image-x86_64-*-jemalloc/*.tar.gz oci-image-amd64.tar.gz - mv oci-image-aarch64-*-jemalloc/*.tar.gz oci-image-arm64v8.tar.gz + mv -v oci-image-x86_64-*-jemalloc/*.tar.gz oci-image-amd64.tar.gz + mv -v oci-image-aarch64-*-jemalloc/*.tar.gz oci-image-arm64v8.tar.gz - name: Load and push amd64 image if: ${{ (vars.DOCKER_USERNAME != '') && (env.DOCKERHUB_TOKEN != '') }} From ffb63c9c8d1cca040d770cf5959ab2d957479516 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 13 May 2024 18:19:59 -0400 Subject: [PATCH 0083/2291] ci: regex out the cargo/rustc target for cargo-deb Signed-off-by: strawberry --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e24e777e..7dc0584d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -206,10 +206,12 @@ jobs: - name: Build static ${{ matrix.target }} run: | + CARGO_DEB_TARGET_TUPLE=$(echo ${{ matrix.target }} | grep -o -E '^([^-]*-){3}[^-]*') + bin/nix-build-and-cache just .#static-${{ matrix.target }} mkdir -p target/release/${{ matrix.target }} cp -v -f result/bin/conduit target/release/${{ matrix.target }} - direnv exec . cargo deb --verbose --no-build --no-strip --target=${{ matrix.target }} --output target/release/${{ matrix.target }}/${{ matrix.target }}.deb + direnv exec . cargo deb --verbose --no-build --no-strip --target=$CARGO_DEB_TARGET_TUPLE --output target/release/${{ matrix.target }}/${{ matrix.target }}.deb mv -v target/release/${{ matrix.target }}/conduit static-${{ matrix.target }} mv -v target/release/${{ matrix.target }}/${{ matrix.target }}.deb ${{ matrix.target }}.deb From 1c6ef66e3ee3d38b22753467a7d0dc6743e0d7fd Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 13 May 2024 18:28:38 -0400 Subject: [PATCH 0084/2291] fix gitlab ci Signed-off-by: strawberry --- .gitlab-ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1d0f67a8..e0d6eb79 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -53,9 +53,6 @@ before_script: # Allow .envrc - if command -v nix > /dev/null; then direnv allow; fi - # Cache attic client - - if command -v nix > /dev/null; then ./bin/nix-build-and-cache --inputs-from . attic; fi - # Set CARGO_HOME to a cacheable path - export CARGO_HOME="$(git rev-parse --show-toplevel)/.gitlab-ci.d/cargo" @@ -86,7 +83,7 @@ ci: artifacts: stage: artifacts - image: nixos/nix:2.22.0 + image: nixos/nix:2.22.1 script: - ./bin/nix-build-and-cache just .#static-x86_64-unknown-linux-musl - cp result/bin/conduit x86_64-unknown-linux-musl From 53974320e5746d8c5b2c7ee8410f298545e8b6b5 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 13 May 2024 22:14:24 -0400 Subject: [PATCH 0085/2291] debian: create system account verbosely Signed-off-by: strawberry --- debian/postinst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/postinst b/debian/postinst index 551e8cfd..f6e10a97 100644 --- a/debian/postinst +++ b/debian/postinst @@ -14,7 +14,7 @@ case "$1" in --home "$CONDUWUIT_DATABASE_PATH" \ --disabled-login \ --shell "/usr/sbin/nologin" \ - --force-badname \ + --verbose \ conduwuit fi From 5069c88f774f56c352b89816d02afeb0954e6034 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 13 May 2024 22:14:38 -0400 Subject: [PATCH 0086/2291] ci: correct paths for debian package creation, use `conduwuit` Signed-off-by: strawberry --- .github/workflows/ci.yml | 13 ++++++++----- Cargo.toml | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7dc0584d..df66516e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -209,11 +209,13 @@ jobs: CARGO_DEB_TARGET_TUPLE=$(echo ${{ matrix.target }} | grep -o -E '^([^-]*-){3}[^-]*') bin/nix-build-and-cache just .#static-${{ matrix.target }} - mkdir -p target/release/${{ matrix.target }} - cp -v -f result/bin/conduit target/release/${{ matrix.target }} - direnv exec . cargo deb --verbose --no-build --no-strip --target=$CARGO_DEB_TARGET_TUPLE --output target/release/${{ matrix.target }}/${{ matrix.target }}.deb - mv -v target/release/${{ matrix.target }}/conduit static-${{ matrix.target }} - mv -v target/release/${{ matrix.target }}/${{ matrix.target }}.deb ${{ matrix.target }}.deb + mkdir -v -p target/release/ + mkdir -v -p target/$CARGO_DEB_TARGET_TUPLE/release/ + cp -v -f result/bin/conduit target/release/conduwuit + cp -v -f result/bin/conduit target/$CARGO_DEB_TARGET_TUPLE/release/conduwuit + direnv exec . cargo deb --verbose --no-build --no-strip --target=$CARGO_DEB_TARGET_TUPLE --output target/release/${{ matrix.target }}.deb + mv -v target/release/conduwuit static-${{ matrix.target }} + mv -v target/release/${{ matrix.target }}.deb ${{ matrix.target }}.deb - name: Upload static-${{ matrix.target }} uses: actions/upload-artifact@v4 @@ -228,6 +230,7 @@ jobs: name: deb-${{ matrix.target }} path: ${{ matrix.target }}.deb if-no-files-found: error + compression-level: 0 - name: Build OCI image ${{ matrix.target }} run: | diff --git a/Cargo.toml b/Cargo.toml index 9ca75672..9a4f40fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -448,7 +448,7 @@ assets = [ "644", ], [ - "target/release/conduit", + "target/release/conduwuit", "usr/sbin/conduwuit", "755", ], From a063a6d08863dc09259d7bb668d9de83e8549d41 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 13 May 2024 22:50:40 -0400 Subject: [PATCH 0087/2291] debian: make the docs actually coherent and understandable, and update it the language here is very poor and i'm not sure why it was written like this. Signed-off-by: strawberry --- debian/README.md | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/debian/README.md b/debian/README.md index a3f5d57c..3fe62212 100644 --- a/debian/README.md +++ b/debian/README.md @@ -1,33 +1,22 @@ # conduwuit for Debian -Installation ------------- +Information about downloading and deploying the Debian package. This may also be referenced for other `apt`-based distros such as Ubuntu. -Information about downloading, building and deploying the Debian package, see -the "Installing conduwuit" section in the Deploying docs. -All following sections until "Setting up the Reverse Proxy" be ignored because -this is handled automatically by the packaging. +### Installation -Configuration -------------- +It is recommended to see the [generic deployment guide](../deploying/generic.md) for further information if needed as usage of the Debian package is generally related. -When installed, Debconf generates the configuration of the homeserver -(host)name, the address and port it listens on. This configuration ends up in -`/etc/conduwuit/conduwuit.toml`. +### Configuration -You can tweak more detailed settings by uncommenting and setting the variables -in `/etc/conduwuit/conduwuit.toml`. This involves settings such as the maximum -file size for download/upload, enabling federation, etc. +When installed, the example config is placed at `/etc/conduwuit/conduwuit.toml` as the default config. At the minimum, you will need to change your `server_name` here. -Running -------- +You can tweak more detailed settings by uncommenting and setting the config options +in `/etc/conduwuit/conduwuit.toml`. -The package uses the [`conduwuit.service`](../configuration.md#example-systemd-unit-file) systemd unit file to start and -stop conduwuit. It loads the configuration file mentioned above to set up the -environment before running the server. +### Running -This package assumes by default that conduwuit will be placed behind a reverse -proxy. This default deployment entails just listening -on `127.0.0.1` and the free port `6167` and is reachable via a client using the URL -. Matrix federation requires TLS, so you will need to set up -some certificates and renewal, for it to work properly. +The package uses the [`conduwuit.service`](../configuration.md#example-systemd-unit-file) systemd unit file to start and stop conduwuit. The binary is installed at `/usr/sbin/conduwuit`. + +This package assumes by default that conduwuit will be placed behind a reverse proxy. The default config options apply (listening on `localhost` and TCP port `6167`). Matrix federation requires a valid domain name and TLS, so you will need to set up TLS certificates and renewal for it to work properly if you intend to federate. + +Consult various online documentation and guides on setting up a reverse proxy and TLS. Caddy is documented at the [generic deployment guide](../deploying/generic.md#setting-up-the-reverse-proxy) as it's the easiest and most user friendly. From a8446f910abd6fbdac2b254b1c68e3668a692a81 Mon Sep 17 00:00:00 2001 From: strawberry Date: Mon, 13 May 2024 22:51:32 -0400 Subject: [PATCH 0088/2291] debian: fix config permissions, delete debconf support debconf support needs to be done in a way that does not duplicate the config file like upstream does. Signed-off-by: strawberry --- debian/config | 23 ++++++++++++----------- debian/postinst | 20 ++++++++++++++------ debian/postrm | 6 +++--- debian/templates | 21 --------------------- 4 files changed, 29 insertions(+), 41 deletions(-) delete mode 100644 debian/templates diff --git a/debian/config b/debian/config index 8e605873..ec84aaa1 100644 --- a/debian/config +++ b/debian/config @@ -1,17 +1,18 @@ #!/bin/sh set -e +# TODO: implement debconf support that is maintainable without duplicating the config # Source debconf library. -. /usr/share/debconf/confmodule - -# Ask for the Matrix homeserver name, address and port. -db_input high conduwuit/hostname || true -db_go - -db_input low conduwuit/address || true -db_go - -db_input medium conduwuit/port || true -db_go +#. /usr/share/debconf/confmodule +# +## Ask for the Matrix homeserver name, address and port. +#db_input high conduwuit/hostname || true +#db_go +# +#db_input low conduwuit/address || true +#db_go +# +#db_input medium conduwuit/port || true +#db_go exit 0 diff --git a/debian/postinst b/debian/postinst index f6e10a97..e2eab94b 100644 --- a/debian/postinst +++ b/debian/postinst @@ -1,9 +1,12 @@ #!/bin/sh set -e -. /usr/share/debconf/confmodule +# TODO: implement debconf support that is maintainable without duplicating the config +#. /usr/share/debconf/confmodule -CONDUWUIT_DATABASE_PATH=/var/lib/conduwuit/ +CONDUWUIT_DATABASE_PATH=/var/lib/conduwuit +CONDUWUIT_CONFIG_PATH=/etc/conduwuit +CONDUWUIT_CONFIG_FILE="${CONDUWUIT_CONFIG_PATH}/conduwuit.toml" case "$1" in configure) @@ -19,10 +22,15 @@ case "$1" in fi # Create the database path if it does not exist yet and fix up ownership - # and permissions. - mkdir -p "$CONDUWUIT_DATABASE_PATH" - chown conduwuit:conduwuit -R "$CONDUWUIT_DATABASE_PATH" - chmod 700 "$CONDUWUIT_DATABASE_PATH" + # and permissions for the config. + mkdir -v -p "$CONDUWUIT_DATABASE_PATH" + + chown -v conduwuit:conduwuit -R "$CONDUWUIT_DATABASE_PATH" + chown -v conduwuit:conduwuit -R "$CONDUWUIT_CONFIG_PATH" + chown -v conduwuit:conduwuit -R "$CONDUWUIT_CONFIG_FILE" + + chmod -v 740 "$CONDUWUIT_DATABASE_PATH" + ;; esac diff --git a/debian/postrm b/debian/postrm index 1feb6815..d77a885e 100644 --- a/debian/postrm +++ b/debian/postrm @@ -1,7 +1,7 @@ #!/bin/sh set -e -. /usr/share/debconf/confmodule +#. /usr/share/debconf/confmodule CONDUWUIT_CONFIG_PATH=/etc/conduwuit CONDUWUIT_DATABASE_PATH=/var/lib/conduwuit @@ -15,11 +15,11 @@ case $1 in # "configuration files must be preserved when the package is removed, and # only deleted when the package is purged." if [ -d "$CONDUWUIT_CONFIG_PATH" ]; then - rm -r "$CONDUWUIT_CONFIG_PATH" + rm -v -r "$CONDUWUIT_CONFIG_PATH" fi if [ -d "$CONDUWUIT_DATABASE_PATH" ]; then - rm -r "$CONDUWUIT_DATABASE_PATH" + rm -v -r "$CONDUWUIT_DATABASE_PATH" fi ;; esac diff --git a/debian/templates b/debian/templates deleted file mode 100644 index 1aa82674..00000000 --- a/debian/templates +++ /dev/null @@ -1,21 +0,0 @@ -Template: conduwuit/hostname -Type: string -Default: localhost -Description: The server (host)name of the Matrix homeserver - This is the hostname the homeserver will be reachable at via a client. - . - If set to "localhost", you can connect with a client locally and clients - from other hosts and also other homeservers will not be able to reach you! - -Template: conduwuit/address -Type: string -Default: 127.0.0.1 -Description: The listen address of the Matrix homeserver - This is the address the homeserver will listen on. Leave it set to 127.0.0.1 - when using a reverse proxy. - -Template: conduwuit/port -Type: string -Default: 6167 -Description: The port of the Matrix homeserver - This port is most often just accessed by a reverse proxy. From 296d7c58ee502728e9f485dec2e03f8fac28f92e Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 15 May 2024 01:26:53 -0400 Subject: [PATCH 0089/2291] nix: bump complement input for conduwuit support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/matrix-org/complement/pull/723 • Updated input 'complement': 'github:matrix-org/complement/370a014dca0f720614e0c8f68b9a3e66ecf7f516' (2024-05-02) → 'github:matrix-org/complement/8587fb3cbe746754b2c883ff6c818ca4d987d0a5' (2024-05-14) Signed-off-by: strawberry --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index f38d07bc..8d5479ab 100644 --- a/flake.lock +++ b/flake.lock @@ -26,11 +26,11 @@ "complement": { "flake": false, "locked": { - "lastModified": 1714661560, - "narHash": "sha256-E1ZiUbOgo7rWo8zt2M2vzCVSykCxK0Ot2dUAxTL6cpU=", + "lastModified": 1715700731, + "narHash": "sha256-cie+b5N/TQAFD8vF/XbqfyFJkFU0qUPDbtJQDm/TfQc=", "owner": "matrix-org", "repo": "complement", - "rev": "370a014dca0f720614e0c8f68b9a3e66ecf7f516", + "rev": "8587fb3cbe746754b2c883ff6c818ca4d987d0a5", "type": "github" }, "original": { From 9a63e7cc9ba953a5baccd44dafeca10c5aac4bd9 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 15 May 2024 02:05:18 -0400 Subject: [PATCH 0090/2291] flip order of complement diff checking, update test results we now pass all Content-Disposition checks/tests Signed-off-by: strawberry --- .github/workflows/ci.yml | 2 +- tests/test_results/complement/test_results.jsonl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df66516e..143dfc56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -134,7 +134,7 @@ jobs: # TODO: figure out why our complement results are not 100% consistent so we don't need to allow failures continue-on-error: true run: | - diff -u --color=always complement_test_results.jsonl tests/test_results/complement/test_results.jsonl > >(tee -a complement_test_output.log) + diff -u --color=always tests/test_results/complement/test_results.jsonl complement_test_results.jsonl > >(tee -a complement_test_output.log) - name: Add Complement diff result to Job Summary run: | diff --git a/tests/test_results/complement/test_results.jsonl b/tests/test_results/complement/test_results.jsonl index f40204ba..aaa14360 100644 --- a/tests/test_results/complement/test_results.jsonl +++ b/tests/test_results/complement/test_results.jsonl @@ -173,9 +173,9 @@ {"Action":"fail","Test":"TestMediaFilenames/Parallel/Unicode/Can_download_with_Unicode_file_name_locally"} {"Action":"fail","Test":"TestMediaFilenames/Parallel/Unicode/Can_download_with_Unicode_file_name_over_federation"} {"Action":"pass","Test":"TestMediaFilenames/Parallel/Unicode/Can_upload_with_Unicode_file_name"} -{"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_safe_media_types_as_inline"} -{"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_safe_media_types_with_parameters_as_inline"} -{"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_unsafe_media_types_as_attachments"} +{"Action":"pass","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_safe_media_types_as_inline"} +{"Action":"pass","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_safe_media_types_with_parameters_as_inline"} +{"Action":"pass","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_unsafe_media_types_as_attachments"} {"Action":"fail","Test":"TestMediaWithoutFileName"} {"Action":"fail","Test":"TestMediaWithoutFileName/parallel"} {"Action":"fail","Test":"TestMediaWithoutFileName/parallel/Can_download_without_a_file_name_locally"} From f5864afb5279a3737c3a90d0760c8375a0a8d995 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 15 May 2024 03:06:06 -0400 Subject: [PATCH 0091/2291] remove namespace check on username login, code simplification on login route the namespace check on username login is unnecessary, hashes aren't ever going to match, and axum auth handles this kind of stuff already Signed-off-by: strawberry --- src/api/client_server/session.rs | 39 +++++++++----------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/src/api/client_server/session.rs b/src/api/client_server/session.rs index 554af631..28df625f 100644 --- a/src/api/client_server/session.rs +++ b/src/api/client_server/session.rs @@ -18,7 +18,7 @@ use ruma::{ UserId, }; use serde::Deserialize; -use tracing::{debug, error, info, warn}; +use tracing::{debug, info, warn}; use super::{DEVICE_ID_LENGTH, TOKEN_LENGTH}; use crate::{services, utils, Error, Result, Ruma}; @@ -76,14 +76,7 @@ pub(crate) async fn login_route(body: Ruma) -> Result) -> Result) -> Result Date: Wed, 15 May 2024 11:45:35 -0400 Subject: [PATCH 0092/2291] debian: dont start service immediately, add postinst instructions Signed-off-by: strawberry --- Cargo.toml | 2 +- debian/postinst | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9a4f40fd..d084a797 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -460,7 +460,7 @@ assets = [ ] conf-files = ["/etc/conduwuit/conduwuit.toml"] maintainer-scripts = "debian/" -systemd-units = { unit-name = "conduwuit" } +systemd-units = { unit-name = "conduwuit", start = false } [profile.dev] diff --git a/debian/postinst b/debian/postinst index e2eab94b..9383bbac 100644 --- a/debian/postinst +++ b/debian/postinst @@ -31,6 +31,11 @@ case "$1" in chmod -v 740 "$CONDUWUIT_DATABASE_PATH" + echo '' + echo 'Make sure you edit the example config at /etc/conduwuit/conduwuit.toml before starting!' + echo 'To start the server, run: systemctl start conduwuit.service' + echo '' + ;; esac From c64a507691f2da61154fb129b6e889974c51b24c Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 15 May 2024 11:53:30 -0400 Subject: [PATCH 0093/2291] correct default database path to `/var/lib/conduwuit` Signed-off-by: strawberry --- conduwuit-example.toml | 5 +++-- debian/postinst | 3 +++ docs/deploying/docker-compose.for-traefik.yml | 6 +++--- docs/deploying/docker-compose.yml | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 90a84ac1..910ebe8f 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -60,8 +60,9 @@ ### Database configuration -# This is the only directory where conduwuit will save its data, including media -database_path = "/var/lib/matrix-conduit/" +# This is the only directory where conduwuit will save its data, including media. +# Note: this was previously "/var/lib/matrix-conduit" +database_path = "/var/lib/conduwuit" # Database backend: Only rocksdb and sqlite are supported. Please note that sqlite # will perform significantly worse than rocksdb as it is not intended to be used the diff --git a/debian/postinst b/debian/postinst index 9383bbac..d07ad36b 100644 --- a/debian/postinst +++ b/debian/postinst @@ -25,6 +25,9 @@ case "$1" in # and permissions for the config. mkdir -v -p "$CONDUWUIT_DATABASE_PATH" + # symlink the previous location for compatibility + ln -s -v "$CONDUWUIT_DATABASE_PATH" "/var/lib/matrix-conduit" + chown -v conduwuit:conduwuit -R "$CONDUWUIT_DATABASE_PATH" chown -v conduwuit:conduwuit -R "$CONDUWUIT_CONFIG_PATH" chown -v conduwuit:conduwuit -R "$CONDUWUIT_CONFIG_FILE" diff --git a/docs/deploying/docker-compose.for-traefik.yml b/docs/deploying/docker-compose.for-traefik.yml index 70f4bb0c..84d7ea59 100644 --- a/docs/deploying/docker-compose.for-traefik.yml +++ b/docs/deploying/docker-compose.for-traefik.yml @@ -3,7 +3,7 @@ version: '2.4' # uses '2.4' for cpuset services: homeserver: - ### If you already built the Conduit image with 'docker build' or want to use the Docker Hub image, + ### If you already built the conduduwit image with 'docker build' or want to use the Docker Hub image, ### then you are ready to go. image: girlbossceo/conduwuit:latest ### If you want to build a fresh image from the sources, then comment the image line and uncomment the @@ -18,13 +18,13 @@ services: # GIT_REF: origin/master restart: unless-stopped volumes: - - db:/var/lib/matrix-conduit + - db:/var/lib/conduwuit #- ./conduwuit.toml:/etc/conduit.toml networks: - proxy environment: CONDUIT_SERVER_NAME: your.server.name # EDIT THIS - CONDUIT_DATABASE_PATH: /var/lib/matrix-conduit + CONDUIT_DATABASE_PATH: /var/lib/conduwuit CONDUIT_DATABASE_BACKEND: rocksdb CONDUIT_PORT: 6167 CONDUIT_MAX_REQUEST_SIZE: 20_000_000 # in bytes, ~20 MB diff --git a/docs/deploying/docker-compose.yml b/docs/deploying/docker-compose.yml index c386b77f..1d80c677 100644 --- a/docs/deploying/docker-compose.yml +++ b/docs/deploying/docker-compose.yml @@ -20,11 +20,11 @@ services: ports: - 8448:6167 volumes: - - db:/var/lib/matrix-conduit + - db:/var/lib/conduwuit #- ./conduwuit.toml:/etc/conduit.toml environment: CONDUIT_SERVER_NAME: your.server.name # EDIT THIS - CONDUIT_DATABASE_PATH: /var/lib/matrix-conduit + CONDUIT_DATABASE_PATH: /var/lib/conduwuit CONDUIT_DATABASE_BACKEND: rocksdb CONDUIT_PORT: 6167 CONDUIT_MAX_REQUEST_SIZE: 20_000_000 # in bytes, ~20 MB From 004354353ad907fe7133e937cfcf5aa311c59569 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 15 May 2024 12:00:25 -0400 Subject: [PATCH 0094/2291] docker-compose: slight cleanups, correct database paths, fix branding Signed-off-by: strawberry --- docs/deploying/docker-compose.for-traefik.yml | 40 ++++++--------- docs/deploying/docker-compose.override.yml | 10 ++-- .../deploying/docker-compose.with-traefik.yml | 49 +++++++------------ docs/deploying/docker-compose.yml | 42 ++++++---------- 4 files changed, 55 insertions(+), 86 deletions(-) diff --git a/docs/deploying/docker-compose.for-traefik.yml b/docs/deploying/docker-compose.for-traefik.yml index 84d7ea59..ec3e720c 100644 --- a/docs/deploying/docker-compose.for-traefik.yml +++ b/docs/deploying/docker-compose.for-traefik.yml @@ -1,4 +1,4 @@ -# Conduit - Behind Traefik Reverse Proxy +# conduwuit - Behind Traefik Reverse Proxy version: '2.4' # uses '2.4' for cpuset services: @@ -6,35 +6,25 @@ services: ### If you already built the conduduwit image with 'docker build' or want to use the Docker Hub image, ### then you are ready to go. image: girlbossceo/conduwuit:latest - ### If you want to build a fresh image from the sources, then comment the image line and uncomment the - ### build lines. If you want meaningful labels in your built Conduit image, you should run docker compose like this: - ### CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ') VERSION=$(grep -m1 -o '[0-9].[0-9].[0-9]' Cargo.toml) docker compose up -d - # build: - # context: . - # args: - # CREATED: '2021-03-16T08:18:27Z' - # VERSION: '0.1.0' - # LOCAL: 'false' - # GIT_REF: origin/master restart: unless-stopped volumes: - db:/var/lib/conduwuit - #- ./conduwuit.toml:/etc/conduit.toml + #- ./conduwuit.toml:/etc/conduwuit.toml networks: - proxy environment: - CONDUIT_SERVER_NAME: your.server.name # EDIT THIS - CONDUIT_DATABASE_PATH: /var/lib/conduwuit - CONDUIT_DATABASE_BACKEND: rocksdb - CONDUIT_PORT: 6167 - CONDUIT_MAX_REQUEST_SIZE: 20_000_000 # in bytes, ~20 MB - CONDUIT_ALLOW_REGISTRATION: 'true' - CONDUIT_ALLOW_FEDERATION: 'true' - CONDUIT_ALLOW_CHECK_FOR_UPDATES: 'true' - CONDUIT_TRUSTED_SERVERS: '["matrix.org"]' - #CONDUIT_LOG: warn,state_res=warn - CONDUIT_ADDRESS: 0.0.0.0 - #CONDUIT_CONFIG: './conduwuit.toml' # Uncomment if you mapped config toml above + CONDUWUIT_SERVER_NAME: your.server.name # EDIT THIS + CONDUWUIT_DATABASE_PATH: /var/lib/conduwuit + CONDUWUIT_DATABASE_BACKEND: rocksdb + CONDUWUIT_PORT: 6167 + CONDUWUIT_MAX_REQUEST_SIZE: 20_000_000 # in bytes, ~20 MB + CONDUWUIT_ALLOW_REGISTRATION: 'true' + CONDUWUIT_ALLOW_FEDERATION: 'true' + CONDUWUIT_ALLOW_CHECK_FOR_UPDATES: 'true' + CONDUWUIT_TRUSTED_SERVERS: '["matrix.org"]' + #CONDUWUIT_LOG: warn,state_res=warn + CONDUWUIT_ADDRESS: 0.0.0.0 + #CONDUWUIT_CONFIG: './conduwuit.toml' # Uncomment if you mapped config toml above #cpuset: "0-4" # Uncomment to limit to specific CPU cores # We need some way to server the client and server .well-known json. The simplest way is to use a nginx container @@ -48,7 +38,7 @@ services: - ./nginx/www:/var/www/ # location of the client and server .well-known-files ### Uncomment if you want to use your own Element-Web App. ### Note: You need to provide a config.json for Element and you also need a second - ### Domain or Subdomain for the communication between Element and Conduit + ### Domain or Subdomain for the communication between Element and conduwuit ### Config-Docs: https://github.com/vector-im/element-web/blob/develop/docs/config.md # element-web: # image: vectorim/element-web:latest diff --git a/docs/deploying/docker-compose.override.yml b/docs/deploying/docker-compose.override.yml index 13a1c917..2e937e75 100644 --- a/docs/deploying/docker-compose.override.yml +++ b/docs/deploying/docker-compose.override.yml @@ -1,4 +1,4 @@ -# Conduit - Traefik Reverse Proxy Labels +# conduwuit - Traefik Reverse Proxy Labels version: '2.4' # uses '2.4' for cpuset services: @@ -7,10 +7,10 @@ services: - "traefik.enable=true" - "traefik.docker.network=proxy" # Change this to the name of your Traefik docker proxy network - - "traefik.http.routers.to-conduit.rule=Host(`.`)" # Change to the address on which Conduit is hosted - - "traefik.http.routers.to-conduit.tls=true" - - "traefik.http.routers.to-conduit.tls.certresolver=letsencrypt" - - "traefik.http.routers.to-conduit.middlewares=cors-headers@docker" + - "traefik.http.routers.to-conduwuit.rule=Host(`.`)" # Change to the address on which conduwuit is hosted + - "traefik.http.routers.to-conduwuit.tls=true" + - "traefik.http.routers.to-conduwuit.tls.certresolver=letsencrypt" + - "traefik.http.routers.to-conduwuit.middlewares=cors-headers@docker" - "traefik.http.middlewares.cors-headers.headers.accessControlAllowOriginList=*" - "traefik.http.middlewares.cors-headers.headers.accessControlAllowHeaders=Origin, X-Requested-With, Content-Type, Accept, Authorization" diff --git a/docs/deploying/docker-compose.with-traefik.yml b/docs/deploying/docker-compose.with-traefik.yml index d9ec1c29..c93f5414 100644 --- a/docs/deploying/docker-compose.with-traefik.yml +++ b/docs/deploying/docker-compose.with-traefik.yml @@ -1,44 +1,33 @@ -# Conduit - Behind Traefik Reverse Proxy +# conduwuit - Behind Traefik Reverse Proxy version: '2.4' # uses '2.4' for cpuset services: homeserver: - ### If you already built the Conduit image with 'docker build' or want to use the Docker Hub image, + ### If you already built the conduwuit image with 'docker build' or want to use the Docker Hub image, ### then you are ready to go. image: girlbossceo/conduwuit:latest - ### If you want to build a fresh image from the sources, then comment the image line and uncomment the - ### build lines. If you want meaningful labels in your built Conduit image, you should run docker compose like this: - ### CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ') VERSION=$(grep -m1 -o '[0-9].[0-9].[0-9]' Cargo.toml) docker compose up -d - # build: - # context: . - # args: - # CREATED: '2021-03-16T08:18:27Z' - # VERSION: '0.1.0' - # LOCAL: 'false' - # GIT_REF: origin/master restart: unless-stopped volumes: - - db:/srv/conduit/.local/share/conduit - #- ./conduwuit.toml:/etc/conduit.toml + - db:/srv/conduwuit/.local/share/conduwuit + #- ./conduwuit.toml:/etc/conduwuit.toml networks: - proxy environment: - CONDUIT_SERVER_NAME: your.server.name # EDIT THIS - CONDUIT_TRUSTED_SERVERS: '["matrix.org"]' - CONDUIT_ALLOW_REGISTRATION : 'true' - #CONDUIT_CONFIG: './conduwuit.toml' # Uncomment if you mapped config toml above + CONDUWUIT_SERVER_NAME: your.server.name # EDIT THIS + CONDUWUIT_TRUSTED_SERVERS: '["matrix.org"]' + CONDUWUIT_ALLOW_REGISTRATION : 'true' + #CONDUWUIT_CONFIG: './conduwuit.toml' # Uncomment if you mapped config toml above ### Uncomment and change values as desired - # CONDUIT_ADDRESS: 0.0.0.0 - # CONDUIT_PORT: 6167 - # Available levels are: error, warn, info, debug, trace - more info at: https://docs.rs/env_logger/*/env_logger/#enabling-logging - # CONDUIT_LOG: info # default is: "warn,state_res=warn" - # CONDUIT_ALLOW_JAEGER: 'false' - # CONDUIT_ALLOW_ENCRYPTION: 'true' - # CONDUIT_ALLOW_FEDERATION: 'true' - # CONDUIT_ALLOW_CHECK_FOR_UPDATES: 'true' - # CONDUIT_DATABASE_PATH: /srv/conduit/.local/share/conduit - # CONDUIT_WORKERS: 10 - # CONDUIT_MAX_REQUEST_SIZE: 20_000_000 # in bytes, ~20 MB + # CONDUWUIT_ADDRESS: 0.0.0.0 + # CONDUWUIT_PORT: 6167 + # CONDUWUIT_LOG: info # default is: "warn,state_res=warn" + # CONDUWUIT_ALLOW_JAEGER: 'false' + # CONDUWUIT_ALLOW_ENCRYPTION: 'true' + # CONDUWUIT_ALLOW_FEDERATION: 'true' + # CONDUWUIT_ALLOW_CHECK_FOR_UPDATES: 'true' + # CONDUWUIT_DATABASE_PATH: /srv/conduwuit/.local/share/conduwuit + # CONDUWUIT_WORKERS: 10 + # CONDUWUIT_MAX_REQUEST_SIZE: 20000000 # in bytes, ~20 MB #cpuset: "0-4" # Uncomment to limit to specific CPU cores # We need some way to server the client and server .well-known json. The simplest way is to use a nginx container @@ -53,7 +42,7 @@ services: ### Uncomment if you want to use your own Element-Web App. ### Note: You need to provide a config.json for Element and you also need a second - ### Domain or Subdomain for the communication between Element and Conduit + ### Domain or Subdomain for the communication between Element and conduwuit ### Config-Docs: https://github.com/vector-im/element-web/blob/develop/docs/config.md # element-web: # image: vectorim/element-web:latest diff --git a/docs/deploying/docker-compose.yml b/docs/deploying/docker-compose.yml index 1d80c677..066c8fe1 100644 --- a/docs/deploying/docker-compose.yml +++ b/docs/deploying/docker-compose.yml @@ -1,45 +1,35 @@ -# Conduit +# conduwuit version: '2.4' # uses '2.4' for cpuset services: homeserver: - ### If you already built the Conduit image with 'docker build' or want to use a registry image, + ### If you already built the conduwuit image with 'docker build' or want to use a registry image, ### then you are ready to go. image: girlbossceo/conduwuit:latest - ### If you want to build a fresh image from the sources, then comment the image line and uncomment the - ### build lines. If you want meaningful labels in your built Conduit image, you should run docker compose like this: - ### CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ') VERSION=$(grep -m1 -o '[0-9].[0-9].[0-9]' Cargo.toml) docker compose up -d - # build: - # context: . - # args: - # CREATED: '2021-03-16T08:18:27Z' - # VERSION: '0.1.0' - # LOCAL: 'false' - # GIT_REF: origin/master restart: unless-stopped ports: - 8448:6167 volumes: - db:/var/lib/conduwuit - #- ./conduwuit.toml:/etc/conduit.toml + #- ./conduwuit.toml:/etc/conduwuit.toml environment: - CONDUIT_SERVER_NAME: your.server.name # EDIT THIS - CONDUIT_DATABASE_PATH: /var/lib/conduwuit - CONDUIT_DATABASE_BACKEND: rocksdb - CONDUIT_PORT: 6167 - CONDUIT_MAX_REQUEST_SIZE: 20_000_000 # in bytes, ~20 MB - CONDUIT_ALLOW_REGISTRATION: 'true' - CONDUIT_ALLOW_FEDERATION: 'true' - CONDUIT_ALLOW_CHECK_FOR_UPDATES: 'true' - CONDUIT_TRUSTED_SERVERS: '["matrix.org"]' - #CONDUIT_LOG: warn,state_res=warn - CONDUIT_ADDRESS: 0.0.0.0 - #CONDUIT_CONFIG: './conduwuit.toml' # Uncomment if you mapped config toml above + CONDUWUIT_SERVER_NAME: your.server.name # EDIT THIS + CONDUWUIT_DATABASE_PATH: /var/lib/conduwuit + CONDUWUIT_DATABASE_BACKEND: rocksdb + CONDUWUIT_PORT: 6167 + CONDUWUIT_MAX_REQUEST_SIZE: 20_000_000 # in bytes, ~20 MB + CONDUWUIT_ALLOW_REGISTRATION: 'true' + CONDUWUIT_ALLOW_FEDERATION: 'true' + CONDUWUIT_ALLOW_CHECK_FOR_UPDATES: 'true' + CONDUWUIT_TRUSTED_SERVERS: '["matrix.org"]' + #CONDUWUIT_LOG: warn,state_res=warn + CONDUWUIT_ADDRESS: 0.0.0.0 + #CONDUWUIT_CONFIG: './conduwuit.toml' # Uncomment if you mapped config toml above #cpuset: "0-4" # Uncomment to limit to specific CPU cores # ### Uncomment if you want to use your own Element-Web App. ### Note: You need to provide a config.json for Element and you also need a second - ### Domain or Subdomain for the communication between Element and Conduit + ### Domain or Subdomain for the communication between Element and conduwuit ### Config-Docs: https://github.com/vector-im/element-web/blob/develop/docs/config.md # element-web: # image: vectorim/element-web:latest From 91064fe8734be216413e8e1207b5cc664e3f6928 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 15 May 2024 13:34:23 -0400 Subject: [PATCH 0095/2291] fix up systemd unit file, remove chown on config file for debian Signed-off-by: strawberry --- debian/conduwuit.service | 10 ++++++---- debian/postinst | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/debian/conduwuit.service b/debian/conduwuit.service index 46f4cbbf..ef59f098 100644 --- a/debian/conduwuit.service +++ b/debian/conduwuit.service @@ -13,6 +13,8 @@ Environment="CONDUWUIT_CONFIG=/etc/conduwuit/conduwuit.toml" ExecStart=/usr/sbin/conduwuit +ReadWritePaths=/var/lib/conduwuit /etc/conduwuit + AmbientCapabilities= CapabilityBoundingSet= @@ -44,16 +46,16 @@ SystemCallArchitectures=native SystemCallFilter=@system-service @resources SystemCallFilter=~@clock @debug @module @mount @reboot @swap @cpu-emulation @obsolete @timer @chown @setuid @privileged @keyring @ipc SystemCallErrorNumber=EPERM -StateDirectory=conduwuit +#StateDirectory=conduwuit -RuntimeDirectory=conduit +RuntimeDirectory=conduwuit RuntimeDirectoryMode=0750 Restart=on-failure RestartSec=5 -TimeoutStopSec=4m -TimeoutStartSec=4m +TimeoutStopSec=2m +TimeoutStartSec=2m StartLimitInterval=1m StartLimitBurst=5 diff --git a/debian/postinst b/debian/postinst index d07ad36b..f82cbfff 100644 --- a/debian/postinst +++ b/debian/postinst @@ -30,7 +30,6 @@ case "$1" in chown -v conduwuit:conduwuit -R "$CONDUWUIT_DATABASE_PATH" chown -v conduwuit:conduwuit -R "$CONDUWUIT_CONFIG_PATH" - chown -v conduwuit:conduwuit -R "$CONDUWUIT_CONFIG_FILE" chmod -v 740 "$CONDUWUIT_DATABASE_PATH" From 4389e086868cc10b97a464478e88c03dc4f2e00a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 18:34:40 +0000 Subject: [PATCH 0096/2291] chore(deps): update cachix/install-nix-action action to v27 --- .github/workflows/documentation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index ae0c9a85..f8f01d2b 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -49,7 +49,7 @@ jobs: uses: actions/configure-pages@v5 - name: Install Nix (with flakes and nix-command enabled) - uses: cachix/install-nix-action@v26 + uses: cachix/install-nix-action@v27 with: nix_path: nixpkgs=channel:nixos-unstable From 7cd72d8447e01da549bc2016f3b6ede04fedae2c Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Thu, 16 May 2024 23:52:31 -0700 Subject: [PATCH 0097/2291] bump lockfile --- Cargo.lock | 149 +++++++++++++++++++++++++---------------------------- 1 file changed, 71 insertions(+), 78 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73209431..79cff215 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,12 +53,6 @@ dependencies = [ "alloc-no-stdlib", ] -[[package]] -name = "allocator-api2" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" - [[package]] name = "anstyle" version = "1.0.7" @@ -136,7 +130,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -147,7 +141,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -375,7 +369,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -437,9 +431,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" +checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5" [[package]] name = "byteorder" @@ -551,7 +545,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -776,7 +770,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -864,9 +858,9 @@ dependencies = [ [[package]] name = "either" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" dependencies = [ "serde", ] @@ -880,7 +874,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -912,15 +906,15 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38793c55593b33412e3ae40c2c9781ffaa6f438f6f8c10f24e71846fbd7ae01e" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "figment" -version = "0.10.18" +version = "0.10.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d032832d74006f99547004d49410a4b4218e4c33382d56ca3ff89df74f86b953" +checksum = "8cb01cd46b0cf372153850f4c6c272d9cbea2da513e07538405148f95bd789f3" dependencies = [ "atomic", "pear", @@ -1048,7 +1042,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -1092,9 +1086,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" dependencies = [ "cfg-if", "js-sys", @@ -1182,14 +1176,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", - "allocator-api2", ] [[package]] name = "hashlink" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692eaaf7f7607518dd3cef090f1474b61edc5301d8012f09579920df68b725ee" +checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" dependencies = [ "hashbrown 0.14.5", ] @@ -1368,7 +1361,7 @@ dependencies = [ "markup5ever", "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -1797,9 +1790,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.154" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libloading" @@ -1823,9 +1816,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.16" +version = "1.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e143b5e666b2695d28f6bca6497720813f699c9602dd7f5cac91008b8ada7f9" +checksum = "0078520875cbd94735b332bca766d640ca0754e5419dce654dcee9115c4239f0" dependencies = [ "cc", "pkg-config", @@ -2317,7 +2310,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -2410,7 +2403,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -2504,7 +2497,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", "version_check", "yansi", ] @@ -2521,15 +2514,15 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.5" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9554e3ab233f0a932403704f1a1d08c30d5ccd931adfdfa1e8b5a19b52c1d55a" +checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" dependencies = [ "anyhow", "itertools", "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -2723,7 +2716,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.10.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "assign", "js_int", @@ -2743,7 +2736,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "js_int", "ruma-common", @@ -2755,7 +2748,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "as_variant", "assign", @@ -2777,7 +2770,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "as_variant", "base64 0.22.1", @@ -2807,7 +2800,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "as_variant", "indexmap 2.2.6", @@ -2829,7 +2822,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "js_int", "ruma-common", @@ -2841,7 +2834,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "js_int", "thiserror", @@ -2850,7 +2843,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "js_int", "ruma-common", @@ -2860,7 +2853,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "once_cell", "proc-macro-crate", @@ -2868,14 +2861,14 @@ dependencies = [ "quote", "ruma-identifiers-validation", "serde", - "syn 2.0.61", + "syn 2.0.64", "toml", ] [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "js_int", "ruma-common", @@ -2887,7 +2880,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "base64 0.22.1", "ed25519-dalek", @@ -2903,7 +2896,7 @@ dependencies = [ [[package]] name = "ruma-state-res" version = "0.11.0" -source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#9e29e07ae1561fa7e6ed1897192f9c43c111b026" +source = "git+https://github.com/girlbossceo/ruma?branch=conduwuit-changes#62aca1e976d0c161d5b2c413bde6d0079f75f3ee" dependencies = [ "itertools", "js_int", @@ -2996,7 +2989,7 @@ dependencies = [ "log", "ring", "rustls-pki-types", - "rustls-webpki 0.102.3", + "rustls-webpki 0.102.4", "subtle", "zeroize", ] @@ -3042,9 +3035,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.102.3" +version = "0.102.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3bce581c0dd41bce533ce695a1437fa16a7ab5ac3ccfa99fe1a620a7885eabf" +checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" dependencies = [ "ring", "rustls-pki-types", @@ -3053,9 +3046,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "092474d1a01ea8278f69e6a358998405fae5b8b963ddaeb2b0b04a128bf1dfb0" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "ryu" @@ -3279,22 +3272,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.201" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.201" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -3343,9 +3336,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" dependencies = [ "serde", ] @@ -3560,9 +3553,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.61" +version = "2.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c993ed8ccba56ae856363b1845da7266a7cb78e1d146c8a32d54b45a8b831fc9" +checksum = "7ad3dee41f36859875573074334c200d1add8e4a87bb37113ebd31d926b7b11f" dependencies = [ "proc-macro2", "quote", @@ -3609,7 +3602,7 @@ checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -3758,7 +3751,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -3820,21 +3813,21 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.12" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.12", + "toml_edit 0.22.13", ] [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" dependencies = [ "serde", ] @@ -3852,9 +3845,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.12" +version = "0.22.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" +checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c" dependencies = [ "indexmap 2.2.6", "serde", @@ -3963,7 +3956,7 @@ source = "git+https://github.com/girlbossceo/tracing?branch=tracing-subscriber/e dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] @@ -4131,7 +4124,7 @@ dependencies = [ "once_cell", "rustls 0.22.4", "rustls-pki-types", - "rustls-webpki 0.102.3", + "rustls-webpki 0.102.4", "url", "webpki-roots 0.26.1", ] @@ -4234,7 +4227,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", "wasm-bindgen-shared", ] @@ -4268,7 +4261,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4615,7 +4608,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.64", ] [[package]] From 302592f21914c660c8ab91fb43d7c42b6a04eab1 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 17 May 2024 03:17:11 -0400 Subject: [PATCH 0098/2291] bump conduwuit version to 0.3.4 Signed-off-by: strawberry --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79cff215..ca640037 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -562,7 +562,7 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "conduit" -version = "0.3.3" +version = "0.3.4" dependencies = [ "argon2", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index d084a797..aa9d8107 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ authors = [ homepage = "https://conduwuit.puppyirl.gay/" repository = "https://github.com/girlbossceo/conduwuit" readme = "README.md" -version = "0.3.3" +version = "0.3.4" edition = "2021" # See also `rust-toolchain.toml` From 6ef4781050c2fa7fd89bcce0bd1f427b8f864a77 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 17 May 2024 03:41:05 -0400 Subject: [PATCH 0099/2291] downgrade zlib/libz-sys to 1.1.16 as it breaks nix Signed-off-by: strawberry --- Cargo.lock | 6 ++++-- Cargo.toml | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca640037..a7934719 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,6 +592,7 @@ dependencies = [ "ipaddress", "itertools", "jsonwebtoken", + "libz-sys", "log", "loole", "lru-cache", @@ -1816,11 +1817,12 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.17" +version = "1.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0078520875cbd94735b332bca766d640ca0754e5419dce654dcee9115c4239f0" +checksum = "5e143b5e666b2695d28f6bca6497720813f699c9602dd7f5cac91008b8ada7f9" dependencies = [ "cc", + "libc", "pkg-config", "vcpkg", ] diff --git a/Cargo.toml b/Cargo.toml index aa9d8107..d7b9454b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,9 @@ edition = "2021" rust-version = "1.77.0" [dependencies] +# 1.1.17 seems broken on nix from a permission error? +libz-sys = "=1.1.16" + console-subscriber = { version = "0.2", optional = true } infer = { version = "0.15", default-features = false } From 8bffcfe82b3cc50bb095f41afc585fabacb963e3 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Thu, 16 May 2024 21:02:05 -0700 Subject: [PATCH 0100/2291] remove sync response cache This cache can serve invalid responses, and has an extremely low hit rate. It serves invalid responses because because it's only keyed off the `since` parameter, but many of the other request parameters also affect the response or it's side effects. This will become worse once we implement filtering, because there will be a wider space of parameters with different responses. This problem is fixable, but not worth it because of the low hit rate. The low hit rate is because normal clients will always issue the next sync request with `since` set to the `prev_batch` value of the previous response. The only time we expect to see multiple requests with the same `since` is when the response is empty, but we don't cache empty responses. This was confirmed experimentally by logging cache hits and misses over 15 minutes with a wide variety of clients. This test was run on matrix.computer.surgery, which has only a few active users, but a large volume of sync traffic from many rooms. Over the test period, we had 3 hits and 5309 misses. All hits occurred in the first minute, so I suspect that they had something to do with client recovery from an offline state. The clients that were connected during the test are: - element web - schildichat web - iamb - gomuks - nheko - fractal - fluffychat web - fluffychat android - cinny web - element android - element X android Fixes: #336 --- src/api/client_server/sync.rs | 103 ++-------------------------------- src/service/globals/mod.rs | 14 ++--- 2 files changed, 8 insertions(+), 109 deletions(-) diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 647ce905..25dbe67d 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -25,10 +25,9 @@ use ruma::{ StateEventType, TimelineEventType, }, serde::Raw, - uint, DeviceId, EventId, OwnedDeviceId, OwnedUserId, RoomId, UInt, UserId, + uint, DeviceId, EventId, OwnedUserId, RoomId, UInt, UserId, }; -use tokio::sync::watch::Sender; -use tracing::{debug, error, Instrument as _, Span}; +use tracing::{error, Instrument as _, Span}; use crate::{ service::{pdu::EventHash, rooms::timeline::PduCount}, @@ -73,10 +72,6 @@ use crate::{ /// For left rooms: /// - If the user left after `since`: `prev_batch` token, empty state (TODO: /// subset of the state at the point of the leave) -/// -/// - Sync is handled in an async task, multiple requests from the same device -/// with the same -/// `since` will be cached pub(crate) async fn sync_events_route( body: Ruma, ) -> Result> { @@ -84,95 +79,6 @@ pub(crate) async fn sync_events_route( let sender_device = body.sender_device.expect("user is authenticated"); let body = body.body; - let mut rx = match services() - .globals - .sync_receivers - .write() - .await - .entry((sender_user.clone(), sender_device.clone())) - { - Entry::Vacant(v) => { - let (tx, rx) = tokio::sync::watch::channel(None); - - v.insert((body.since.clone(), rx.clone())); - - tokio::spawn(sync_helper_wrapper(sender_user.clone(), sender_device.clone(), body, tx)); - - rx - }, - Entry::Occupied(mut o) => { - if o.get().0 != body.since { - let (tx, rx) = tokio::sync::watch::channel(None); - - o.insert((body.since.clone(), rx.clone())); - - debug!("Sync started for {sender_user}"); - - tokio::spawn(sync_helper_wrapper(sender_user.clone(), sender_device.clone(), body, tx)); - - rx - } else { - o.get().1.clone() - } - }, - }; - - let we_have_to_wait = rx.borrow().is_none(); - if we_have_to_wait { - if let Err(e) = rx.changed().await { - error!("Error waiting for sync: {}", e); - } - } - - let result = match rx - .borrow() - .as_ref() - .expect("When sync channel changes it's always set to some") - { - Ok(response) => Ok(response.clone()), - Err(error) => Err(error.to_response()), - }; - - result -} - -async fn sync_helper_wrapper( - sender_user: OwnedUserId, sender_device: OwnedDeviceId, body: sync_events::v3::Request, - tx: Sender>>, -) { - let since = body.since.clone(); - - let r = sync_helper(sender_user.clone(), sender_device.clone(), body).await; - - if let Ok((_, caching_allowed)) = r { - if !caching_allowed { - match services() - .globals - .sync_receivers - .write() - .await - .entry((sender_user, sender_device)) - { - Entry::Occupied(o) => { - // Only remove if the device didn't start a different /sync already - if o.get().0 == since { - o.remove(); - } - }, - Entry::Vacant(_) => {}, - } - } - } - - _ = tx.send(Some(r.map(|(r, _)| r))); -} - -async fn sync_helper( - sender_user: OwnedUserId, - sender_device: OwnedDeviceId, - body: sync_events::v3::Request, - // bool = caching allowed -) -> Result<(sync_events::v3::Response, bool), Error> { // Presence update if services().globals.allow_local_presence() { services() @@ -414,10 +320,9 @@ async fn sync_helper( duration = Duration::from_secs(30); } _ = tokio::time::timeout(duration, watcher).await; - Ok((response, false)) - } else { - Ok((response, since != next_batch)) // Only cache if we made progress } + + Ok(response) } #[tracing::instrument(skip_all, fields(user_id = %sender_user, room_id = %room_id))] diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index 402934ef..4484b816 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -18,14 +18,14 @@ use ipaddress::IPAddress; use regex::RegexSet; use ruma::{ api::{ - client::{discovery::discover_support::ContactRole, sync::sync_events}, + client::discovery::discover_support::ContactRole, federation::discovery::{ServerSigningKeys, VerifyKey}, }, serde::Base64, - DeviceId, OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, - RoomVersionId, ServerName, UserId, + DeviceId, OwnedEventId, OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, RoomVersionId, + ServerName, UserId, }; -use tokio::sync::{broadcast, watch::Receiver, Mutex, RwLock}; +use tokio::sync::{broadcast, Mutex, RwLock}; use tracing::{error, info, trace}; use url::Url; @@ -36,10 +36,6 @@ mod data; mod resolver; type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries -type SyncHandle = ( - Option, // since - Receiver>>, // rx -); pub(crate) struct Service<'a> { pub(crate) db: &'static dyn Data, @@ -56,7 +52,6 @@ pub(crate) struct Service<'a> { pub(crate) bad_event_ratelimiter: Arc>>, pub(crate) bad_signature_ratelimiter: Arc, RateLimitState>>>, pub(crate) bad_query_ratelimiter: Arc>>, - pub(crate) sync_receivers: RwLock>, pub(crate) roomid_mutex_insert: RwLock>>>, pub(crate) roomid_mutex_state: RwLock>>>, pub(crate) roomid_mutex_federation: RwLock>>>, // this lock will be held longer @@ -163,7 +158,6 @@ impl Service<'_> { roomid_mutex_federation: RwLock::new(HashMap::new()), roomid_federationhandletime: RwLock::new(HashMap::new()), stateres_mutex: Arc::new(Mutex::new(())), - sync_receivers: RwLock::new(HashMap::new()), rotate: RotationHandler::new(), started: SystemTime::now(), shutdown: AtomicBool::new(false), From 9eb0784f6f5afe99bd997d931c67dca42d52e9fa Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Fri, 10 May 2024 17:17:50 -0700 Subject: [PATCH 0101/2291] don't return extra member count or e2ee device updates from sync Previously, we were returning redundant member count updates or encrypted device updates from the /sync endpoint in some cases. The extra member count updates are spec-compliant, but unnecessary, while the extra encrypted device updates violate the spec. The refactor necessary to fix this bug is also necessary to support filtering on state events in sync. Details: Joined room incremental sync needs to examine state events for four purposes: 1. determining whether we need to return an update to room member counts 2. determining the set of left/joined devices for encrypted rooms (returned in `device_lists`) 3. returning state events to the client (in `rooms.joined.*.state`) 4. tracking which member events we have sent to the client, so they can be omitted on future requests when lazy-loading is enabled. The state events that we need to examine for the first two cases is member events in the delta between `since` and the end of `timeline`. For the second two cases, we need the delta between `since` and the start of `timeline`, plus contextual member events for any senders that occur in `timeline`. The second list is subject to filtering, while the first is not. Before this change, we were using the same set of state events that we are returning to the client (cases 3/4) to do the analysis for cases 1/2. In a compliant implementation, this would result in us missing some relevant member events in 1/2 in addition to seeing redundant member events. In current conduwuit this is not the case because the set of events that we return to the client is always a superset of the set that is needed for cases 1/2. This is because we don't support filtering, and we have an existing bug[1] where we are returning the delta between `since` and the end of `timeline` rather than the start. [1]: https://github.com/girlbossceo/conduwuit/issues/361 Fixing this is necessary to implement filtering because otherwise we would start missing some member events for member count or encrypted device updates if the relevant member events are rejected by the filter. This would be much worse than our current behavior. --- src/api/client_server/sync.rs | 103 ++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 48 deletions(-) diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 25dbe67d..8e7282fe 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -750,8 +750,7 @@ async fn load_joined_room( // Incremental /sync let since_shortstatehash = since_shortstatehash.unwrap(); - let mut state_events = Vec::new(); - let mut lazy_loaded = HashSet::new(); + let mut delta_state_events = Vec::new(); if since_shortstatehash != current_shortstatehash { let current_state_ids = services() @@ -772,55 +771,12 @@ async fn load_joined_room( continue; }; - if pdu.kind == TimelineEventType::RoomMember { - match UserId::parse( - pdu.state_key - .as_ref() - .expect("State event has state key") - .clone(), - ) { - Ok(state_key_userid) => { - lazy_loaded.insert(state_key_userid); - }, - Err(e) => error!("Invalid state key for member event: {}", e), - } - } - - state_events.push(pdu); + delta_state_events.push(pdu); tokio::task::yield_now().await; } } } - for (_, event) in &timeline_pdus { - if lazy_loaded.contains(&event.sender) { - continue; - } - - if !services().rooms.lazy_loading.lazy_load_was_sent_before( - sender_user, - sender_device, - room_id, - &event.sender, - )? || lazy_load_send_redundant - { - if let Some(member_event) = services().rooms.state_accessor.room_state_get( - room_id, - &StateEventType::RoomMember, - event.sender.as_str(), - )? { - lazy_loaded.insert(event.sender.clone()); - state_events.push(member_event); - } - } - } - - services() - .rooms - .lazy_loading - .lazy_load_mark_sent(sender_user, sender_device, room_id, lazy_loaded, next_batchcount) - .await; - let encrypted_room = services() .rooms .state_accessor @@ -836,12 +792,12 @@ async fn load_joined_room( // Calculations: let new_encrypted_room = encrypted_room && since_encryption.is_none(); - let send_member_count = state_events + let send_member_count = delta_state_events .iter() .any(|event| event.kind == TimelineEventType::RoomMember); if encrypted_room { - for state_event in &state_events { + for state_event in &delta_state_events { if state_event.kind != TimelineEventType::RoomMember { continue; } @@ -902,6 +858,57 @@ async fn load_joined_room( (None, None, Vec::new()) }; + let mut state_events = delta_state_events; + let mut lazy_loaded = HashSet::new(); + + // Mark all member events we're returning as lazy-loaded + for pdu in &state_events { + if pdu.kind == TimelineEventType::RoomMember { + match UserId::parse( + pdu.state_key + .as_ref() + .expect("State event has state key") + .clone(), + ) { + Ok(state_key_userid) => { + lazy_loaded.insert(state_key_userid); + }, + Err(e) => error!("Invalid state key for member event: {}", e), + } + } + } + + // Fetch contextual member state events for events from the timeline, and + // mark them as lazy-loaded as well. + for (_, event) in &timeline_pdus { + if lazy_loaded.contains(&event.sender) { + continue; + } + + if !services().rooms.lazy_loading.lazy_load_was_sent_before( + sender_user, + sender_device, + room_id, + &event.sender, + )? || lazy_load_send_redundant + { + if let Some(member_event) = services().rooms.state_accessor.room_state_get( + room_id, + &StateEventType::RoomMember, + event.sender.as_str(), + )? { + lazy_loaded.insert(event.sender.clone()); + state_events.push(member_event); + } + } + } + + services() + .rooms + .lazy_loading + .lazy_load_mark_sent(sender_user, sender_device, room_id, lazy_loaded, next_batchcount) + .await; + ( heroes, joined_member_count, From ae1a4fd2835b8d9576a2f1528b1cc051ce90d0f3 Mon Sep 17 00:00:00 2001 From: slonkazoid Date: Tue, 21 May 2024 11:36:35 +0300 Subject: [PATCH 0102/2291] add modification time fallback if birth time is not supported on this platform --- src/service/media/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index 73c8e089..5e39085d 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -251,7 +251,14 @@ impl Service { let file_metadata = fs::metadata(path.clone()).await?; debug!("File metadata: {:?}", file_metadata); - let file_created_at = file_metadata.created()?; + let file_created_at = match file_metadata.created() { + Ok(value) => value, + Err(err) if err.kind() == std::io::ErrorKind::Unsupported => { + debug!("btime is unsupported, using mtime instead"); + file_metadata.modified()? + }, + Err(err) => return Err(err.into()), + }; debug!("File created at: {:?}", file_created_at); if file_created_at >= user_duration { From 6c1434c1657c5a911c98a9cfbe06c984d4079690 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 9 May 2024 15:59:08 -0700 Subject: [PATCH 0103/2291] Hot-Reloading Refactor Signed-off-by: Jason Volk --- Cargo.toml | 808 ++++++++++-------- deps/rust-rocksdb/Cargo.toml | 32 + deps/rust-rocksdb/lib.rs | 59 ++ nix/pkgs/main/default.nix | 2 +- src/admin/Cargo.toml | 63 ++ .../admin/appservice/appservice_command.rs | 2 +- src/{service => }/admin/appservice/mod.rs | 2 +- .../admin/debug/debug_commands.rs | 16 +- src/{service => }/admin/debug/mod.rs | 0 .../admin/federation/federation_commands.rs | 7 +- src/{service => }/admin/federation/mod.rs | 0 src/{service => }/admin/fsck/fsck_commands.rs | 0 src/{service => }/admin/fsck/mod.rs | 0 src/admin/handler.rs | 305 +++++++ .../admin/media/media_commands.rs | 4 +- src/{service => }/admin/media/mod.rs | 4 +- src/admin/mod.rs | 55 ++ src/{service => }/admin/query/account_data.rs | 0 src/{service => }/admin/query/appservice.rs | 0 src/{service => }/admin/query/globals.rs | 0 src/{service => }/admin/query/mod.rs | 0 src/{service => }/admin/query/presence.rs | 0 src/{service => }/admin/query/room_alias.rs | 0 src/{service => }/admin/query/sending.rs | 0 src/{service => }/admin/query/users.rs | 0 src/{service => }/admin/room/mod.rs | 0 .../admin/room/room_alias_commands.rs | 2 +- src/{service => }/admin/room/room_commands.rs | 5 +- .../admin/room/room_directory_commands.rs | 5 +- .../admin/room/room_moderation_commands.rs | 92 +- src/{service => }/admin/server/mod.rs | 0 .../admin/server/server_commands.rs | 19 +- src/{service => }/admin/tester/mod.rs | 2 +- src/{service => }/admin/user/mod.rs | 0 src/{service => }/admin/user/user_commands.rs | 14 +- src/admin/utils.rs | 30 + src/alloc/default.rs | 7 - src/alloc/hardened.rs | 8 - src/api/Cargo.toml | 66 ++ src/api/client_server/account.rs | 7 +- src/api/client_server/alias.rs | 8 +- src/api/client_server/directory.rs | 2 +- src/api/client_server/keys.rs | 3 +- src/api/client_server/media.rs | 6 +- src/api/client_server/membership.rs | 13 +- src/api/client_server/message.rs | 6 +- src/api/client_server/mod.rs | 77 +- src/api/client_server/profile.rs | 5 +- src/api/client_server/read_marker.rs | 3 +- src/api/client_server/room.rs | 4 +- src/api/client_server/state.rs | 6 +- src/api/client_server/sync.rs | 6 +- src/api/client_server/to_device.rs | 2 +- src/api/mod.rs | 16 +- src/{router/routes.rs => api/router.rs} | 23 +- src/api/ruma_wrapper/axum.rs | 83 +- src/api/ruma_wrapper/mod.rs | 20 +- src/api/ruma_wrapper/xmatrix.rs | 61 ++ src/api/server_server.rs | 40 +- src/bin/Cargo.toml | 123 +++ src/bin/main.rs | 96 +++ src/bin/mods.rs | 129 +++ src/bin/server.rs | 186 ++++ src/core/Cargo.toml | 133 +++ src/core/alloc/default.rs | 9 + src/core/alloc/hardened.rs | 10 + src/{ => core}/alloc/je.rs | 6 +- src/{ => core}/alloc/mod.rs | 12 +- src/{ => core}/config/check.rs | 4 +- src/{ => core}/config/mod.rs | 320 +++---- src/{ => core}/config/proxy.rs | 9 +- src/{utils => core}/debug.rs | 33 + src/{utils => core}/error.rs | 126 +-- src/core/log.rs | 79 ++ src/core/mod.rs | 27 + src/core/mods/canary.rs | 28 + src/core/mods/macros.rs | 44 + src/core/mods/mod.rs | 11 + src/core/mods/module.rs | 74 ++ src/core/mods/new.rs | 23 + src/core/mods/path.rs | 40 + src/core/pducount.rs | 51 ++ src/core/server.rs | 72 ++ src/{ => core}/utils/clap.rs | 8 +- src/{ => core}/utils/content_disposition.rs | 10 +- src/core/utils/defer.rs | 22 + src/{ => core}/utils/mod.rs | 89 +- src/database/Cargo.toml | 81 ++ src/database/cork.rs | 4 +- src/database/kvdatabase.rs | 320 +++++++ src/database/kvengine.rs | 2 +- src/database/kvtree.rs | 2 +- src/database/mod.rs | 576 +------------ src/database/rocksdb/kvtree.rs | 5 +- src/database/rocksdb/mod.rs | 40 +- src/database/rocksdb/opts.rs | 12 +- src/database/sqlite/mod.rs | 6 +- src/main.rs | 503 ----------- src/router/Cargo.toml | 85 ++ src/router/layers.rs | 190 ++++ src/router/mod.rs | 267 +----- src/router/request.rs | 102 +++ src/router/router.rs | 20 + src/router/run.rs | 185 ++++ src/router/serve.rs | 137 +++ src/service/Cargo.toml | 115 +++ src/service/account_data/data.rs | 2 +- src/service/account_data/mod.rs | 14 +- src/service/{admin/mod.rs => admin.rs} | 463 ++-------- src/service/admin/test_cmd/mod.rs | 41 - src/service/appservice/data.rs | 2 +- src/service/appservice/mod.rs | 58 +- src/service/globals/client.rs | 18 +- src/service/globals/data.rs | 2 +- src/service/globals/emerg_access.rs | 66 ++ .../globals}/migrations.rs | 6 +- src/service/globals/mod.rs | 253 +++--- src/service/globals/resolver.rs | 18 +- src/service/globals/updates.rs | 76 ++ src/service/key_backups/data.rs | 2 +- src/service/key_backups/mod.rs | 44 +- .../key_value/account_data.rs | 4 +- .../key_value/appservice.rs | 4 +- .../key_value/globals.rs | 11 +- .../key_value/key_backups.rs | 4 +- src/{database => service}/key_value/media.rs | 9 +- src/{database => service}/key_value/mod.rs | 0 .../key_value/presence.rs | 9 +- src/{database => service}/key_value/pusher.rs | 4 +- .../key_value/rooms/alias.rs | 4 +- .../key_value/rooms/auth_chain.rs | 4 +- .../key_value/rooms/directory.rs | 4 +- .../key_value/rooms/lazy_load.rs | 4 +- .../key_value/rooms/metadata.rs | 4 +- .../key_value/rooms/mod.rs | 4 +- .../key_value/rooms/outlier.rs | 4 +- .../key_value/rooms/pdu_metadata.rs | 8 +- .../key_value/rooms/read_receipt.rs | 4 +- .../key_value/rooms/search.rs | 4 +- .../key_value/rooms/short.rs | 4 +- .../key_value/rooms/state.rs | 4 +- .../key_value/rooms/state_accessor.rs | 4 +- .../key_value/rooms/state_cache.rs | 11 +- .../key_value/rooms/state_compressor.rs | 8 +- .../key_value/rooms/threads.rs | 4 +- .../key_value/rooms/timeline.rs | 5 +- .../key_value/rooms/user.rs | 4 +- .../key_value/sending.rs | 10 +- .../key_value/transaction_ids.rs | 4 +- src/{database => service}/key_value/uiaa.rs | 4 +- src/{database => service}/key_value/users.rs | 23 +- src/service/media/data.rs | 2 +- src/service/media/mod.rs | 54 +- src/service/mod.rs | 334 +------- src/service/pdu.rs | 82 +- src/service/presence/data.rs | 2 +- src/service/presence/mod.rs | 91 +- src/service/pusher/data.rs | 2 +- src/service/pusher/mod.rs | 23 +- src/service/rooms/alias/data.rs | 2 +- src/service/rooms/alias/mod.rs | 20 +- src/service/rooms/auth_chain/data.rs | 2 +- src/service/rooms/auth_chain/mod.rs | 16 +- src/service/rooms/directory/data.rs | 2 +- src/service/rooms/directory/mod.rs | 16 +- src/service/rooms/event_handler/mod.rs | 31 +- .../rooms/event_handler/parse_incoming_pdu.rs | 31 + .../rooms/event_handler/signing_keys.rs | 13 +- src/service/rooms/lazy_loading/data.rs | 2 +- src/service/rooms/lazy_loading/mod.rs | 25 +- src/service/rooms/metadata/data.rs | 2 +- src/service/rooms/metadata/mod.rs | 24 +- src/service/rooms/mod.rs | 84 +- src/service/rooms/outlier/data.rs | 2 +- src/service/rooms/outlier/mod.rs | 16 +- src/service/rooms/pdu_metadata/data.rs | 4 +- src/service/rooms/pdu_metadata/mod.rs | 28 +- src/service/rooms/read_receipt/data.rs | 2 +- src/service/rooms/read_receipt/mod.rs | 18 +- src/service/rooms/search/data.rs | 2 +- src/service/rooms/search/mod.rs | 12 +- src/service/rooms/short/data.rs | 2 +- src/service/rooms/short/mod.rs | 24 +- src/service/rooms/spaces/mod.rs | 22 +- src/service/rooms/state/data.rs | 2 +- src/service/rooms/state/mod.rs | 26 +- src/service/rooms/state_accessor/data.rs | 2 +- src/service/rooms/state_accessor/mod.rs | 48 +- src/service/rooms/state_cache/data.rs | 2 +- src/service/rooms/state_cache/mod.rs | 80 +- src/service/rooms/state_compressor/data.rs | 10 +- src/service/rooms/state_compressor/mod.rs | 24 +- src/service/rooms/threads/data.rs | 2 +- src/service/rooms/threads/mod.rs | 12 +- src/service/rooms/timeline/data.rs | 2 +- src/service/rooms/timeline/mod.rs | 117 +-- src/service/rooms/typing/mod.rs | 26 +- src/service/rooms/user/data.rs | 2 +- src/service/rooms/user/mod.rs | 26 +- src/service/sending/data.rs | 2 +- src/service/sending/mod.rs | 71 +- src/service/sending/send.rs | 222 +---- src/service/sending/sender.rs | 38 +- src/service/services.rs | 342 ++++++++ src/service/transaction_ids/data.rs | 2 +- src/service/transaction_ids/mod.rs | 12 +- src/service/uiaa/data.rs | 2 +- src/service/uiaa/mod.rs | 20 +- src/service/users/data.rs | 2 +- src/service/users/mod.rs | 118 ++- src/utils/server_name.rs | 8 - src/utils/user_id.rs | 8 - 212 files changed, 5679 insertions(+), 4206 deletions(-) create mode 100644 deps/rust-rocksdb/Cargo.toml create mode 100644 deps/rust-rocksdb/lib.rs create mode 100644 src/admin/Cargo.toml rename src/{service => }/admin/appservice/appservice_command.rs (97%) rename src/{service => }/admin/appservice/mod.rs (98%) rename src/{service => }/admin/debug/debug_commands.rs (98%) rename src/{service => }/admin/debug/mod.rs (100%) rename src/{service => }/admin/federation/federation_commands.rs (97%) rename src/{service => }/admin/federation/mod.rs (100%) rename src/{service => }/admin/fsck/fsck_commands.rs (100%) rename src/{service => }/admin/fsck/mod.rs (100%) create mode 100644 src/admin/handler.rs rename src/{service => }/admin/media/media_commands.rs (98%) rename src/{service => }/admin/media/mod.rs (96%) create mode 100644 src/admin/mod.rs rename src/{service => }/admin/query/account_data.rs (100%) rename src/{service => }/admin/query/appservice.rs (100%) rename src/{service => }/admin/query/globals.rs (100%) rename src/{service => }/admin/query/mod.rs (100%) rename src/{service => }/admin/query/presence.rs (100%) rename src/{service => }/admin/query/room_alias.rs (100%) rename src/{service => }/admin/query/sending.rs (100%) rename src/{service => }/admin/query/users.rs (100%) rename src/{service => }/admin/room/mod.rs (100%) rename src/{service => }/admin/room/room_alias_commands.rs (98%) rename src/{service => }/admin/room/room_commands.rs (93%) rename src/{service => }/admin/room/room_directory_commands.rs (96%) rename src/{service => }/admin/room/room_moderation_commands.rs (83%) rename src/{service => }/admin/server/mod.rs (100%) rename src/{service => }/admin/server/server_commands.rs (90%) rename src/{service => }/admin/tester/mod.rs (92%) rename src/{service => }/admin/user/mod.rs (100%) rename src/{service => }/admin/user/user_commands.rs (97%) create mode 100644 src/admin/utils.rs delete mode 100644 src/alloc/default.rs delete mode 100644 src/alloc/hardened.rs create mode 100644 src/api/Cargo.toml rename src/{router/routes.rs => api/router.rs} (96%) create mode 100644 src/api/ruma_wrapper/xmatrix.rs create mode 100644 src/bin/Cargo.toml create mode 100644 src/bin/main.rs create mode 100644 src/bin/mods.rs create mode 100644 src/bin/server.rs create mode 100644 src/core/Cargo.toml create mode 100644 src/core/alloc/default.rs create mode 100644 src/core/alloc/hardened.rs rename src/{ => core}/alloc/je.rs (95%) rename src/{ => core}/alloc/mod.rs (80%) rename src/{ => core}/config/check.rs (98%) rename src/{ => core}/config/mod.rs (80%) rename src/{ => core}/config/proxy.rs (95%) rename src/{utils => core}/debug.rs (66%) rename src/{utils => core}/error.rs (78%) create mode 100644 src/core/log.rs create mode 100644 src/core/mod.rs create mode 100644 src/core/mods/canary.rs create mode 100644 src/core/mods/macros.rs create mode 100644 src/core/mods/mod.rs create mode 100644 src/core/mods/module.rs create mode 100644 src/core/mods/new.rs create mode 100644 src/core/mods/path.rs create mode 100644 src/core/pducount.rs create mode 100644 src/core/server.rs rename src/{ => core}/utils/clap.rs (73%) rename src/{ => core}/utils/content_disposition.rs (93%) create mode 100644 src/core/utils/defer.rs rename src/{ => core}/utils/mod.rs (72%) create mode 100644 src/database/Cargo.toml create mode 100644 src/database/kvdatabase.rs delete mode 100644 src/main.rs create mode 100644 src/router/Cargo.toml create mode 100644 src/router/layers.rs create mode 100644 src/router/request.rs create mode 100644 src/router/router.rs create mode 100644 src/router/run.rs create mode 100644 src/router/serve.rs create mode 100644 src/service/Cargo.toml rename src/service/{admin/mod.rs => admin.rs} (51%) delete mode 100644 src/service/admin/test_cmd/mod.rs create mode 100644 src/service/globals/emerg_access.rs rename src/{database => service/globals}/migrations.rs (99%) create mode 100644 src/service/globals/updates.rs rename src/{database => service}/key_value/account_data.rs (96%) rename src/{database => service}/key_value/appservice.rs (92%) rename src/{database => service}/key_value/globals.rs (96%) rename src/{database => service}/key_value/key_backups.rs (98%) rename src/{database => service}/key_value/media.rs (97%) rename src/{database => service}/key_value/mod.rs (100%) rename src/{database => service}/key_value/presence.rs (96%) rename src/{database => service}/key_value/pusher.rs (94%) rename src/{database => service}/key_value/rooms/alias.rs (94%) rename src/{database => service}/key_value/rooms/auth_chain.rs (91%) rename src/{database => service}/key_value/rooms/directory.rs (85%) rename src/{database => service}/key_value/rooms/lazy_load.rs (92%) rename src/{database => service}/key_value/rooms/metadata.rs (93%) rename src/{database => service}/key_value/rooms/mod.rs (71%) rename src/{database => service}/key_value/rooms/outlier.rs (85%) rename src/{database => service}/key_value/rooms/pdu_metadata.rs (92%) rename src/{database => service}/key_value/rooms/read_receipt.rs (96%) rename src/{database => service}/key_value/rooms/search.rs (93%) rename src/{database => service}/key_value/rooms/short.rs (97%) rename src/{database => service}/key_value/rooms/state.rs (94%) rename src/{database => service}/key_value/rooms/state_accessor.rs (96%) rename src/{database => service}/key_value/rooms/state_cache.rs (98%) rename src/{database => service}/key_value/rooms/state_compressor.rs (88%) rename src/{database => service}/key_value/rooms/threads.rs (93%) rename src/{database => service}/key_value/rooms/timeline.rs (97%) rename src/{database => service}/key_value/rooms/user.rs (96%) rename src/{database => service}/key_value/sending.rs (96%) rename src/{database => service}/key_value/transaction_ids.rs (88%) rename src/{database => service}/key_value/uiaa.rs (94%) rename src/{database => service}/key_value/users.rs (98%) create mode 100644 src/service/rooms/event_handler/parse_incoming_pdu.rs create mode 100644 src/service/services.rs delete mode 100644 src/utils/server_name.rs delete mode 100644 src/utils/user_id.rs diff --git a/Cargo.toml b/Cargo.toml index d7b9454b..2e2153a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,115 +1,95 @@ -[package] -# TODO: when can we rename to conduwuit? -name = "conduit" +#cargo-features = ["profile-rustflags"] + +[workspace] +resolver = "2" +members = ["src/*"] +default-members = ["src/*"] + +[workspace.package] description = "a very cool fork of Conduit, a Matrix homeserver written in Rust" license = "Apache-2.0" authors = [ "strawberry ", "timokoesters ", ] +version = "0.3.4" +edition = "2021" +# See also `rust-toolchain.toml` +rust-version = "1.77.0" homepage = "https://conduwuit.puppyirl.gay/" repository = "https://github.com/girlbossceo/conduwuit" readme = "README.md" -version = "0.3.4" -edition = "2021" -# See also `rust-toolchain.toml` -rust-version = "1.77.0" - -[dependencies] # 1.1.17 seems broken on nix from a permission error? -libz-sys = "=1.1.16" +[workspace.dependencies.libz-sys] +version = "=1.1.16" -console-subscriber = { version = "0.2", optional = true } +[workspace.dependencies.sanitize-filename] +version = "0.5.0" -infer = { version = "0.15", default-features = false } +[workspace.dependencies.infer] +version = "0.15" +default-features = false -# for hot lib reload -hot-lib-reloader = { version = "^0.7", optional = true } +[workspace.dependencies.jsonwebtoken] +version = "9.3.0" -# Used for secure identifiers -rand = "0.8.5" - -# Used for conduit::Error type -thiserror = "1.0.60" - -# Used to encode server public key -base64 = "0.22.1" - -# Used when hashing the state -ring = "0.17.8" - -# Used to find matching events for appservices -regex = "1.10.4" - -# Used to load forbidden room/user regex from config -serde_regex = "1.1.0" - -# Used to make working with iterators easier, was already a transitive depdendency -itertools = "0.12.1" - -# jwt jsonwebtokens -jsonwebtoken = "9.3.0" - -# Used for ruma wrapper -serde_html_form = "0.2.6" +[workspace.dependencies.base64] +version = "0.22.1" # used for TURN server authentication -hmac = "0.12.1" -sha-1 = "0.10.1" +[workspace.dependencies.hmac] +version = "0.12.1" + +[workspace.dependencies.sha-1] +version = "0.10.1" # used for checking if an IP is in specific subnets / CIDR ranges easier -ipaddress = "0.1.3" +[workspace.dependencies.ipaddress] +version = "0.1.3" -# to get the client IP address of requests -#axum-client-ip = "0.4.2" +[workspace.dependencies.rand] +version = "0.8.5" -# to parse user-friendly time durations in admin commands -cyborgtime = "2.1.1" - -# all the web/HTTP dependencies # Used for the http request / response body type for Ruma endpoints used with reqwest -bytes = "1.6.0" -http = "1.1.0" -http-body-util = "0.1.1" +[workspace.dependencies.bytes] +version = "1.6.0" -# used to replace the channels of the tokio runtime -loole = "0.3.0" +[workspace.dependencies.http-body-util] +version = "0.1.1" -# Validating urls in config, was already a transitive dependency -url = { version = "2.5.0", features = ["serde"] } +[workspace.dependencies.http] +version = "1.1.0" -async-trait = "0.1.80" +[workspace.dependencies.regex] +version = "1.10.4" -lru-cache = "0.1.2" -sanitize-filename = "0.5.0" - -# standard date and time tools -[dependencies.chrono] -version = "0.4.38" -features = ["alloc"] -default-features = false - -# Web framework -[dependencies.axum] +[workspace.dependencies.axum] version = "0.7.5" default-features = false -features = ["form", "http1", "http2", "json", "matched-path"] +features = [ + "form", + "http1", + "http2", + "json", + "matched-path", + "tokio", +] -[dependencies.axum-extra] +[workspace.dependencies.axum-extra] version = "0.9.3" default-features = false features = ["typed-header"] -[dependencies.axum-server] +[workspace.dependencies.axum-server] version = "0.6.0" features = ["tls-rustls"] -[dependencies.tower] +[workspace.dependencies.tower] version = "0.4.13" features = ["util"] -[dependencies.tower-http] +[workspace.dependencies.tower-http] version = "0.5.2" features = [ "add-extension", @@ -121,153 +101,170 @@ features = [ "catch-panic", ] -[dependencies.hyper] -version = "1.3.1" -features = ["server", "http1", "http2"] - -[dependencies.hyper-util] -version = "0.1.3" - -[dependencies.reqwest] +[workspace.dependencies.reqwest] version = "0.12.4" default-features = false -features = ["rustls-tls-native-roots", "socks", "hickory-dns"] +features = [ + "rustls-tls-native-roots", + "socks", + "hickory-dns", +] -# all the serde stuff -# Used for pdu definition -[dependencies.serde] +[workspace.dependencies.serde] version = "1.0.201" features = ["rc"] -# Used for appservice registration files -[dependencies.serde_yaml] -version = "0.9.34" -# Used for ruma wrapper -[dependencies.serde_json] + +[workspace.dependencies.serde_json] version = "1.0.117" features = ["raw_value"] +# Used for appservice registration files +[workspace.dependencies.serde_yaml] +version = "0.9.34" + +# Used to load forbidden room/user regex from config +[workspace.dependencies.serde_regex] +version = "1.1.0" + +# Used for ruma wrapper +[workspace.dependencies.serde_html_form] +version = "0.2.6" # Used for password hashing -[dependencies.argon2] +[workspace.dependencies.argon2] version = "0.5.3" features = ["alloc", "rand"] default-features = false # Used to generate thumbnails for images -[dependencies.image] +[workspace.dependencies.image] version = "0.25.1" default-features = false -features = ["jpeg", "png", "gif", "webp"] +features = [ + "jpeg", + "png", + "gif", + "webp", +] # logging -[dependencies.log] +[workspace.dependencies.log] version = "0.4.21" default-features = false -[dependencies.tracing] +[workspace.dependencies.tracing] version = "0.1.40" default-features = false -[dependencies.tracing-subscriber] +[workspace.dependencies.tracing-subscriber] version = "0.3.18" features = ["env-filter"] -# optional SHA256 media keys feature -[dependencies.sha2] -version = "0.10.8" -optional = true - -# optional opentelemetry, performance measurements, flamegraphs, etc for performance measurements and monitoring -[dependencies.opentelemetry] -version = "0.21.0" -optional = true -[dependencies.tracing-flame] -version = "0.2.0" -optional = true -[dependencies.tracing-opentelemetry] -version = "0.22.0" -optional = true -[dependencies.opentelemetry_sdk] -version = "0.21.2" -optional = true -features = ["rt-tokio"] -[dependencies.opentelemetry-jaeger] -version = "0.20.0" -optional = true -features = ["rt-tokio"] - -# optional sentry metrics for crash/panic reporting -[dependencies.sentry] -version = "0.32.3" -optional = true -default-features = false -features = [ - "backtrace", - "contexts", - "debug-images", - "panic", - "rustls", - "tower", - "tower-http", - "tracing", - "reqwest", - "log", -] -[dependencies.sentry-tracing] -version = "0.32.3" -optional = true -[dependencies.sentry-tower] -version = "0.32.3" -optional = true - -# optional jemalloc usage -[dependencies.tikv-jemalloc-sys] -version = "0.5.4" -optional = true -default-features = false -features = ["stats", "unprefixed_malloc_on_supported_platforms"] -[dependencies.tikv-jemallocator] -version = "0.5.4" -optional = true -default-features = false -features = ["stats", "unprefixed_malloc_on_supported_platforms"] -[dependencies.tikv-jemalloc-ctl] -version = "0.5.4" -optional = true -default-features = false -features = ["use_std"] - # for URL previews -[dependencies.webpage] +[workspace.dependencies.webpage] version = "2.0.1" default-features = false -# to support multiple variations of setting a config option -[dependencies.either] -version = "1.11.0" -features = ["serde"] - -# to listen on both HTTP and HTTPS if listening on TLS dierctly from conduwuit for complement or sytest -[dependencies.axum-server-dual-protocol] -version = "0.6" -optional = true - # used for conduit's CLI and admin room command parsing -[dependencies.clap] +[workspace.dependencies.clap] version = "4.5.4" default-features = false -features = ["std", "derive", "help", "usage", "error-context", "string"] +features = [ + "std", + "derive", + "help", + "usage", + "error-context", + "string", +] -[dependencies.futures-util] +[workspace.dependencies.futures-util] version = "0.3.30" default-features = false +[workspace.dependencies.tokio] +version = "1.37.0" +features = [ + "fs", + "net", + "macros", + "sync", + "signal", + "time", + "rt-multi-thread", + "io-util", +] + +[workspace.dependencies.libloading] +version = "0.8.3" + +# Validating urls in config, was already a transitive dependency +[workspace.dependencies.url] +version = "2.5.0" +features = ["serde"] + +# standard date and time tools +[workspace.dependencies.chrono] +version = "0.4.38" +features = ["alloc"] +default-features = false + +[workspace.dependencies.hyper] +version = "1.3.1" +features = [ + "server", + "http1", + "http2", +] + +[workspace.dependencies.hyper-util] +version = "0.1.3" + +# to support multiple variations of setting a config option +[workspace.dependencies.either] +version = "1.11.0" +features = ["serde"] + # Used for reading the configuration from conduwuit.toml & environment variables -[dependencies.figment] +[workspace.dependencies.figment] version = "0.10.18" features = ["env", "toml"] +[workspace.dependencies.hickory-resolver] +version = "0.24.1" +default-features = false + +# Used for conduit::Error type +[workspace.dependencies.thiserror] +version = "1.0.60" + +# Used when hashing the state +[workspace.dependencies.ring] +version = "0.17.8" + +# Used to make working with iterators easier, was already a transitive depdendency +[workspace.dependencies.itertools] +version = "0.12.1" + +# to parse user-friendly time durations in admin commands +#TODO: overlaps chrono? +[workspace.dependencies.cyborgtime] +version = "2.1.1" + +# used to replace the channels of the tokio runtime +[workspace.dependencies.loole] +version = "0.3.0" + +[workspace.dependencies.async-trait] +version = "0.1.80" + +[workspace.dependencies.lru-cache] +version = "0.1.2" + +[workspace.dependencies.num_cpus] +version = "1.16.0" + # Used for matrix spec type definitions and helpers -[dependencies.ruma] -git = "https://github.com/girlbossceo/ruma" +[workspace.dependencies.ruma] +git = "https://github.com/girlbossceo/ruwuma" branch = "conduwuit-changes" features = [ "compat", @@ -292,60 +289,128 @@ features = [ "unstable-extensible-events", ] -[dependencies.ruma-identifiers-validation] -git = "https://github.com/girlbossceo/ruma" +[workspace.dependencies.ruma-identifiers-validation] +git = "https://github.com/girlbossceo/ruwuma" branch = "conduwuit-changes" -[dependencies.hickory-resolver] -version = "0.24.1" +[workspace.dependencies.rust-rocksdb] +path = "deps/rust-rocksdb" +package = "rust-rocksdb-uwu" +features = [ + "multi-threaded-cf", + "mt_static", + "snappy", + "lz4", + "zstd", + "zlib", + "bzip2", +] + +[workspace.dependencies.zstd] +version = "0.13.1" + +# to listen on both HTTP and HTTPS if listening on TLS dierctly from conduwuit for complement or sytest +[workspace.dependencies.axum-server-dual-protocol] +version = "0.6" + +# optional SHA256 media keys feature +[workspace.dependencies.sha2] +version = "0.10.8" + +# optional opentelemetry, performance measurements, flamegraphs, etc for performance measurements and monitoring +[workspace.dependencies.opentelemetry] +version = "0.21.0" + +[workspace.dependencies.tracing-flame] +version = "0.2.0" + +[workspace.dependencies.tracing-opentelemetry] +version = "0.22.0" + +[workspace.dependencies.opentelemetry_sdk] +version = "0.21.2" +features = ["rt-tokio"] + +[workspace.dependencies.opentelemetry-jaeger] +version = "0.20.0" +features = ["rt-tokio"] + +# optional sentry metrics for crash/panic reporting +[workspace.dependencies.sentry] +version = "0.32.3" default-features = false +features = [ + "backtrace", + "contexts", + "debug-images", + "panic", + "rustls", + "tower", + "tower-http", + "tracing", + "reqwest", + "log", +] -[dependencies.rust-rocksdb] -git = "https://github.com/zaidoon1/rust-rocksdb" -branch = "master" -optional = true -default-features = true -features = ["multi-threaded-cf", "zstd"] +[workspace.dependencies.sentry-tracing] +version = "0.32.3" +[workspace.dependencies.sentry-tower] +version = "0.32.3" -[dependencies.rusqlite] +# optional jemalloc usage +[workspace.dependencies.tikv-jemalloc-sys] +version = "0.5.4" +default-features = false +features = ["unprefixed_malloc_on_supported_platforms"] +[workspace.dependencies.tikv-jemallocator] +version = "0.5.4" +default-features = false +features = ["unprefixed_malloc_on_supported_platforms"] +[workspace.dependencies.tikv-jemalloc-ctl] +version = "0.5.4" +default-features = false +features = ["use_std"] + +[workspace.dependencies.rusqlite] git = "https://github.com/rusqlite/rusqlite" #branch = "master" rev = "e00b626e2b1c67347d789fb7f600281705c89381" -optional = true features = ["bundled"] # used only by rusqlite -[dependencies.parking_lot] +[workspace.dependencies.parking_lot] version = "0.12.2" -optional = true # used only by rusqlite -[dependencies.thread_local] +[workspace.dependencies.thread_local] version = "1.1.8" -optional = true -# used only by rusqlite and rust-rocksdb -[dependencies.num_cpus] -version = "1.16.0" +[workspace.dependencies.tokio-metrics] +version = "0.3.1" +default-features = false -[dependencies.tokio] -version = "1.37.0" -features = ["fs", "macros", "sync", "signal"] +[workspace.dependencies.console-subscriber] +version = "0.2" -# *nix-specific dependencies -[target.'cfg(unix)'.dependencies] -nix = { version = "0.28.0", features = ["resource"] } -sd-notify = { version = "0.4.1", optional = true } # systemd is only available/relevant on *nix platforms +[workspace.dependencies.nix] +version = "0.28.0" +features = ["resource"] +[workspace.dependencies.sd-notify] +version = "0.4.1" -[target.'cfg(all(not(target_env = "msvc"), target_os = "linux"))'.dependencies] -hardened_malloc-rs = { version = "0.1.2", optional = true, features = [ - "static", - "gcc", - "light", -], default-features = false } -#hardened_malloc-rs = { optional = true, features = ["static","clang","light"], path = "../hardened_malloc-rs", default-features = false } +[workspace.dependencies.hardened_malloc-rs] +version = "0.1.2" +default-features = false +features = [ + "static", + "gcc", + "light", +] +# +# Patches +# # backport of [https://github.com/tokio-rs/tracing/pull/2956] to the 0.1.x branch of tracing. # we can switch back to upstream if #2956 is merged and backported in the upstream repo. @@ -359,166 +424,213 @@ branch = "tracing-subscriber/env-filter-clone-0.1.x-backport" git = "https://github.com/girlbossceo/tracing" branch = "tracing-subscriber/env-filter-clone-0.1.x-backport" -[features] -default = [ - "backend_rocksdb", - "systemd", - "element_hacks", - "sentry_telemetry", - "gzip_compression", - "brotli_compression", - "zstd_compression", - "release_max_log_level", - "io_uring", -] -backend_sqlite = ["sqlite"] -backend_rocksdb = ["rocksdb"] -rocksdb = ["dep:rust-rocksdb"] -jemalloc = [ - "dep:tikv-jemalloc-sys", - "dep:tikv-jemalloc-ctl", - "dep:tikv-jemallocator", - "rust-rocksdb/jemalloc", -] -jemalloc_prof = ["tikv-jemalloc-sys/profiling"] -sqlite = ["dep:rusqlite", "dep:parking_lot", "dep:thread_local"] -systemd = ["dep:sd-notify"] -sentry_telemetry = ["dep:sentry", "dep:sentry-tracing", "dep:sentry-tower"] - -gzip_compression = ["tower-http/compression-gzip", "reqwest/gzip"] -zstd_compression = ["tower-http/compression-zstd"] -brotli_compression = ["tower-http/compression-br", "reqwest/brotli"] - -sha256_media = ["dep:sha2"] -io_uring = ["rust-rocksdb/io-uring"] -axum_dual_protocol = ["dep:axum-server-dual-protocol"] - -perf_measurements = [ - "dep:opentelemetry", - "dep:tracing-flame", - "dep:tracing-opentelemetry", - "dep:opentelemetry_sdk", - "dep:opentelemetry-jaeger", -] - -# enable the tokio_console server -# incompatible with release_max_log_level -tokio_console = ["dep:console-subscriber", "tokio/tracing"] - -hot_reload = ["dep:hot-lib-reloader"] - -hardened_malloc = ["dep:hardened_malloc-rs"] - -# increases performance, reduces build times, and reduces binary size by not compiling or -# genreating code for log level filters that users will generally not use (debug and trace) only in release builds # -# the expense is obviously losing those log level filters for usage at runtime. debug builds will still have all log levels -release_max_log_level = [ - "tracing/max_level_trace", - "tracing/release_max_level_info", - "log/max_level_trace", - "log/release_max_level_info", -] - -# developer feature useful only in debug builds. -dev_release_log_level = [] - -# client/server interopability hacks +# Our crates # -## element has various non-spec compliant behaviour -element_hacks = [] +[workspace.dependencies.conduit-router] +package = "conduit_router" +path = "src/router" +default-features = false -[package.metadata.deb] -name = "conduwuit" -maintainer = "strawberry " -copyright = "2024, strawberry " -license-file = ["LICENSE", "3"] -depends = "$auto, ca-certificates" -extended-description = """\ -a cool hard fork of Conduit, a Matrix homeserver written in Rust""" -section = "net" -priority = "optional" -assets = [ - [ - "debian/README.md", - "usr/share/doc/conduwuit/README.Debian", - "644", - ], - [ - "README.md", - "usr/share/doc/conduwuit/", - "644", - ], - [ - "target/release/conduwuit", - "usr/sbin/conduwuit", - "755", - ], - [ - "conduwuit-example.toml", - "etc/conduwuit/conduwuit.toml", - "640", - ], -] -conf-files = ["/etc/conduwuit/conduwuit.toml"] -maintainer-scripts = "debian/" -systemd-units = { unit-name = "conduwuit", start = false } +[workspace.dependencies.conduit-admin] +package = "conduit_admin" +path = "src/admin" +default-features = false +[workspace.dependencies.conduit-api] +package = "conduit_api" +path = "src/api" +default-features = false -[profile.dev] -#debug = 0 -lto = 'off' -codegen-units = 512 -incremental = true -overflow-checks = true -#panic = "abort" +[workspace.dependencies.conduit-service] +package = "conduit_service" +path = "src/service" +default-features = false -# seems to speed up continuous debug compilations -[profile.dev.build-override] -opt-level = 3 -[profile.dev.package."*"] # external dependencies -opt-level = 1 -[profile.dev.package."tokio"] -opt-level = 3 +[workspace.dependencies.conduit-database] +package = "conduit_database" +path = "src/database" +default-features = false + +[workspace.dependencies.conduit-core] +package = "conduit_core" +path = "src/core" +default-features = false + +############################################################################### +# +# Release profiles +# -# default release profile [profile.release] -lto = 'thin' -incremental = false -opt-level = 3 strip = "symbols" -control-flow-guard = true # Windows only -debug = 0 +lto = "thin" # release profile with debug symbols [profile.release-debuginfo] inherits = "release" -strip = "none" debug = "full" +strip = "none" - -# high performance release profile which uses fat LTO across all crates, 1 codegen unit, max opt-level, and optimises across all crates [profile.release-high-perf] inherits = "release" -lto = 'fat' +lto = "fat" codegen-units = 1 panic = "abort" -# For releases also try to max optimizations for dependencies: -[profile.release-high-perf.build-override] -debug = 0 -opt-level = 3 +# do not use without profile-rustflags enabled +[profile.release-max-perf] +inherits = "release" +strip = "symbols" +lto = "fat" +#rustflags = [ +# '-Ctarget-cpu=native', +# '-Ztune-cpu=native', +# '-Ctarget-feature=+crt-static', +# '-Crelocation-model=static', +# '-Ztls-model=local-exec', +# '-Zinline-in-all-cgus=true', +# '-Zinline-mir=true', +# '-Zmir-opt-level=3', +# '-Clink-arg=-fuse-ld=mold', +# '-Clink-arg=-Wl,--threads', +# '-Clink-arg=-Wl,--gc-sections', +# '-Ztime-passes', +# '-Ztime-llvm-passes', +#] + +[profile.release-max-perf.build-override] +inherits = "release-max-perf" +opt-level = 0 +#rustflags = [ +# '-Ctarget-feature=-crt-static', +#] + +[profile.bench] +inherits = "release" +#rustflags = [ +# "-Cremark=all", +# '-Ztime-passes', +# '-Ztime-llvm-passes', +#] + +############################################################################### +# +# Developer profile +# + +# To enable hot-reloading: +# 1. Uncomment all of the rustflags here. +# 2. Uncomment crate-type=dylib in src/*/Cargo.toml and deps/rust-rocksdb/Cargo.toml +# 2. Build with the 'mods' feature. +# +# opt-level, mir-opt-level, validate-mir are not known to interfere with reloading +# and can be raised if build times are tolerable. + +[profile.dev] +debug = 1 +opt-level = 0 +panic = "unwind" +debug-assertions = true +incremental = true +codegen-units = 64 +rpath = true +#rustflags = [ +# '-Ztime-passes', +# '-Zmir-opt-level=0', +# '-Zvalidate-mir=false', +# '-Ztls-model=global-dynamic', +# '-Cprefer-dynamic=true', +# '-Zstaticlib-prefer-dynamic=true', +# '-Zstaticlib-allow-rdylib-deps=true', +# '-Zpacked-bundled-libs=false', +# '-Zplt=true', +# '-Crpath=true', +# '-Clink-arg=-Wl,--as-needed', +# '-Clink-arg=-Wl,--allow-shlib-undefined', +# '-Clink-arg=-Wl,-z,keep-text-section-prefix', +# '-Clink-arg=-Wl,-z,lazy', +#] + +[profile.dev.package.conduit_core] +inherits = "dev" +incremental = false +#rustflags = [ +# '-Ztime-passes', +# '-Zmir-opt-level=0', +# '-Ztls-model=initial-exec', +# '-Cprefer-dynamic=true', +# '-Zstaticlib-prefer-dynamic=true', +# '-Zstaticlib-allow-rdylib-deps=true', +# '-Zpacked-bundled-libs=false', +# '-Zplt=true', +# '-Clink-arg=-Wl,--as-needed', +# '-Clink-arg=-Wl,--allow-shlib-undefined', +# '-Clink-arg=-Wl,-z,lazy', +# '-Clink-arg=-Wl,-z,unique', +# '-Clink-arg=-Wl,-z,nodlopen', +# '-Clink-arg=-Wl,-z,nodelete', +#] + +[profile.dev.package.conduit] +inherits = "dev" +incremental = false +#rustflags = [ +# '-Ztime-passes', +# '-Zmir-opt-level=0', +# '-Zvalidate-mir=false', +# '-Ztls-model=global-dynamic', +# '-Cprefer-dynamic=true', +# '-Zexport-executable-symbols=true', +# '-Zplt=true', +# '-Crpath=true', +# '-Clink-arg=-Wl,--as-needed', +# '-Clink-arg=-Wl,--allow-shlib-undefined', +# '-Clink-arg=-Wl,--export-dynamic', +# '-Clink-arg=-Wl,-z,lazy', +#] + +[profile.dev.package.rust-rocksdb-uwu] +inherits = "dev" +debug = 'limited' +incremental = false codegen-units = 1 +opt-level = 'z' +#rustflags = [ +# '-Ztls-model=initial-exec', +# '-Cprefer-dynamic=true', +# '-Zstaticlib-prefer-dynamic=true', +# '-Zstaticlib-allow-rdylib-deps=true', +# '-Zpacked-bundled-libs=true', +# '-Zplt=true', +# '-Clink-arg=-Wl,--no-as-needed', +# '-Clink-arg=-Wl,--allow-shlib-undefined', +# '-Clink-arg=-Wl,-z,lazy', +# '-Clink-arg=-Wl,-z,nodlopen', +# '-Clink-arg=-Wl,-z,nodelete', +#] -[profile.release-high-perf.package."*"] -debug = 0 -opt-level = 3 +[profile.dev.package.'*'] +inherits = "dev" +debug = 'limited' +incremental = false codegen-units = 1 +opt-level = 'z' +#rustflags = [ +# '-Ztls-model=global-dynamic', +# '-Cprefer-dynamic=true', +# '-Zstaticlib-prefer-dynamic=true', +# '-Zstaticlib-allow-rdylib-deps=true', +# '-Zpacked-bundled-libs=true', +# '-Zplt=true', +# '-Clink-arg=-Wl,--as-needed', +# '-Clink-arg=-Wl,-z,lazy', +# '-Clink-arg=-Wl,-z,nodelete', +#] - -[lints] -workspace = true +[profile.test] +incremental = false [workspace.lints.rust] missing_abi = "warn" @@ -543,7 +655,6 @@ unused_braces = "allow" # some sadness missing_docs = "allow" - [workspace.lints.clippy] # pedantic = "warn" @@ -615,7 +726,6 @@ unnecessary_box_returns = "warn" map_unwrap_or = "warn" implicit_clone = "warn" match_wildcard_for_single_variants = "warn" -unnecessary_wraps = "warn" match_same_arms = "warn" ignored_unit_patterns = "warn" redundant_else = "warn" @@ -650,6 +760,7 @@ unwrap_used = "allow" expect_used = "allow" if_then_some_else_none = "allow" let_underscore_must_use = "allow" +let_underscore_future = "allow" map_err_ignore = "allow" missing_docs_in_private_items = "allow" multiple_inherent_impl = "allow" @@ -657,3 +768,4 @@ error_impl_error = "allow" string_add = "allow" string_slice = "allow" ref_patterns = "allow" +unnecessary_wraps = "allow" diff --git a/deps/rust-rocksdb/Cargo.toml b/deps/rust-rocksdb/Cargo.toml new file mode 100644 index 00000000..f5e3211e --- /dev/null +++ b/deps/rust-rocksdb/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "rust-rocksdb-uwu" +version = "0.0.1" +edition = "2021" + +[features] +default = ["snappy", "lz4", "zstd", "zlib", "bzip2"] +jemalloc = ["rust-rocksdb/jemalloc"] +io-uring = ["rust-rocksdb/io-uring"] +valgrind = ["rust-rocksdb/valgrind"] +snappy = ["rust-rocksdb/snappy"] +lz4 = ["rust-rocksdb/lz4"] +zstd = ["rust-rocksdb/zstd"] +zlib = ["rust-rocksdb/zlib"] +bzip2 = ["rust-rocksdb/bzip2"] +rtti = ["rust-rocksdb/rtti"] +mt_static = ["rust-rocksdb/mt_static"] +multi-threaded-cf = ["rust-rocksdb/multi-threaded-cf"] +serde1 = ["rust-rocksdb/serde1"] +malloc-usable-size = ["rust-rocksdb/malloc-usable-size"] + +[dependencies.rust-rocksdb] +git = "https://github.com/zaidoon1/rust-rocksdb" +branch = "master" +default-features = false + +[lib] +path = "lib.rs" +crate-type = [ + "rlib", +# "dylib" +] diff --git a/deps/rust-rocksdb/lib.rs b/deps/rust-rocksdb/lib.rs new file mode 100644 index 00000000..ae11159e --- /dev/null +++ b/deps/rust-rocksdb/lib.rs @@ -0,0 +1,59 @@ +pub use rust_rocksdb::*; + +#[link(name = "rocksdb", kind = "static")] +extern "C" { + pub fn rocksdb_list_column_families(); + pub fn rocksdb_logger_create_stderr_logger(); + pub fn rocksdb_options_set_info_log(); + pub fn rocksdb_get_options_from_string(); + pub fn rocksdb_writebatch_create(); + pub fn rocksdb_writebatch_put_cf(); + pub fn rocksdb_writebatch_delete_cf(); + pub fn rocksdb_iter_value(); + pub fn rocksdb_iter_seek_to_last(); + pub fn rocksdb_iter_seek_for_prev(); + pub fn rocksdb_iter_seek_to_first(); + pub fn rocksdb_iter_next(); + pub fn rocksdb_iter_prev(); + pub fn rocksdb_iter_seek(); + pub fn rocksdb_iter_valid(); + pub fn rocksdb_iter_get_error(); + pub fn rocksdb_iter_key(); + pub fn rocksdb_iter_destroy(); + pub fn rocksdb_livefiles(); + pub fn rocksdb_livefiles_count(); + pub fn rocksdb_livefiles_destroy(); + pub fn rocksdb_livefiles_column_family_name(); + pub fn rocksdb_livefiles_name(); + pub fn rocksdb_livefiles_size(); + pub fn rocksdb_livefiles_level(); + pub fn rocksdb_livefiles_smallestkey(); + pub fn rocksdb_livefiles_largestkey(); + pub fn rocksdb_livefiles_entries(); + pub fn rocksdb_livefiles_deletions(); + pub fn rocksdb_put_cf(); + pub fn rocksdb_delete_cf(); + pub fn rocksdb_get_pinned_cf(); + pub fn rocksdb_create_column_family(); + pub fn rocksdb_get_latest_sequence_number(); + pub fn rocksdb_batched_multi_get_cf(); + pub fn rocksdb_cancel_all_background_work(); + pub fn rocksdb_repair_db(); + pub fn rocksdb_list_column_families_destroy(); + pub fn rocksdb_flush(); + pub fn rocksdb_flush_wal(); + pub fn rocksdb_open_column_families(); + pub fn rocksdb_open_for_read_only_column_families(); + pub fn rocksdb_open_as_secondary_column_families(); + pub fn rocksdb_open_column_families_with_ttl(); + pub fn rocksdb_open(); + pub fn rocksdb_open_for_read_only(); + pub fn rocksdb_open_with_ttl(); + pub fn rocksdb_open_as_secondary(); + pub fn rocksdb_write(); + pub fn rocksdb_create_iterator_cf(); + pub fn rocksdb_backup_engine_create_new_backup_flush(); + pub fn rocksdb_backup_engine_options_create(); + pub fn rocksdb_write_buffer_manager_destroy(); + pub fn rocksdb_options_set_ttl(); +} diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix index f546a328..ec2aebc2 100644 --- a/nix/pkgs/main/default.nix +++ b/nix/pkgs/main/default.nix @@ -55,7 +55,7 @@ commonAttrs = { include = [ "Cargo.lock" "Cargo.toml" - "hot_lib" + "deps" "src" ]; }; diff --git a/src/admin/Cargo.toml b/src/admin/Cargo.toml new file mode 100644 index 00000000..49ec4267 --- /dev/null +++ b/src/admin/Cargo.toml @@ -0,0 +1,63 @@ +[package] +name = "conduit_admin" +version.workspace = true +edition.workspace = true + +[lib] +path = "mod.rs" +crate-type = [ + "rlib", +# "dylib", +] + +[features] +default = [ + "rocksdb", + "io_uring", + "jemalloc", + "zstd_compression", + "release_max_log_level", +] + +dev_release_log_level = [] +release_max_log_level = [ + "tracing/max_level_trace", + "tracing/release_max_level_info", + "log/max_level_trace", + "log/release_max_level_info", +] +rocksdb = [ + "dep:rust-rocksdb", +] +jemalloc = [ + "rust-rocksdb/jemalloc", +] +io_uring = [ + "rust-rocksdb/io-uring", +] +zstd_compression = [ + "rust-rocksdb/zstd", +] + +[dependencies] +clap.workspace = true +conduit-api.workspace = true +conduit-core.workspace = true +conduit-database.workspace = true +conduit-service.workspace = true +futures-util.workspace = true +log.workspace = true +loole.workspace = true +regex.workspace = true +ruma.workspace = true +rust-rocksdb.optional = true +rust-rocksdb.workspace = true +serde_json.workspace = true +serde.workspace = true +serde_yaml.workspace = true +tokio.workspace = true +tracing-subscriber.workspace = true +tracing.workspace = true + +[lints] +workspace = true diff --git a/src/service/admin/appservice/appservice_command.rs b/src/admin/appservice/appservice_command.rs similarity index 97% rename from src/service/admin/appservice/appservice_command.rs rename to src/admin/appservice/appservice_command.rs index 4e99c78b..409ef83b 100644 --- a/src/service/admin/appservice/appservice_command.rs +++ b/src/admin/appservice/appservice_command.rs @@ -1,6 +1,6 @@ use ruma::{api::appservice::Registration, events::room::message::RoomMessageEventContent}; -use crate::{service::admin::escape_html, services, Result}; +use crate::{escape_html, services, Result}; pub(crate) async fn register(body: Vec<&str>) -> Result { if body.len() > 2 && body[0].trim().starts_with("```") && body.last().unwrap().trim() == "```" { diff --git a/src/service/admin/appservice/mod.rs b/src/admin/appservice/mod.rs similarity index 98% rename from src/service/admin/appservice/mod.rs rename to src/admin/appservice/mod.rs index b0d225aa..8cf246b9 100644 --- a/src/service/admin/appservice/mod.rs +++ b/src/admin/appservice/mod.rs @@ -1,8 +1,8 @@ use clap::Subcommand; +use conduit::Result; use ruma::events::room::message::RoomMessageEventContent; use self::appservice_command::{list, register, show, unregister}; -use crate::Result; pub(crate) mod appservice_command; diff --git a/src/service/admin/debug/debug_commands.rs b/src/admin/debug/debug_commands.rs similarity index 98% rename from src/service/admin/debug/debug_commands.rs rename to src/admin/debug/debug_commands.rs index 3ce7fb14..838c4b22 100644 --- a/src/service/admin/debug/debug_commands.rs +++ b/src/admin/debug/debug_commands.rs @@ -1,18 +1,15 @@ use std::{collections::BTreeMap, sync::Arc, time::Instant}; +use conduit::{utils::HtmlEscape, Error, Result}; use ruma::{ api::client::error::ErrorKind, events::room::message::RoomMessageEventContent, CanonicalJsonObject, EventId, RoomId, RoomVersionId, ServerName, }; +use service::{rooms::event_handler::parse_incoming_pdu, sending::send::resolve_actual_dest, services, PduEvent}; use tokio::sync::RwLock; use tracing::{debug, info, warn}; use tracing_subscriber::EnvFilter; -use crate::{ - api::server_server::parse_incoming_pdu, service::sending::send::resolve_actual_dest, services, utils::HtmlEscape, - Error, PduEvent, Result, -}; - pub(crate) async fn get_auth_chain(_body: Vec<&str>, event_id: Box) -> Result { let event_id = Arc::::from(event_id); if let Some(event) = services().rooms.timeline.get_pdu_json(&event_id)? { @@ -332,7 +329,7 @@ pub(crate) async fn change_log_level( }; match services() - .globals + .server .tracing_reload_handle .reload(&old_filter_layer) { @@ -361,7 +358,7 @@ pub(crate) async fn change_log_level( }; match services() - .globals + .server .tracing_reload_handle .reload(&new_filter_layer) { @@ -447,15 +444,16 @@ pub(crate) async fn resolve_true_destination( )); } - let (actual_dest, hostname_uri) = resolve_actual_dest(&server_name, no_cache, true).await?; + let (actual_dest, hostname_uri) = resolve_actual_dest(&server_name, no_cache).await?; Ok(RoomMessageEventContent::text_plain(format!( "Actual destination: {actual_dest:?} | Hostname URI: {hostname_uri}" ))) } +#[must_use] pub(crate) fn memory_stats() -> RoomMessageEventContent { - let html_body = crate::alloc::memory_stats(); + let html_body = conduit::alloc::memory_stats(); if html_body.is_empty() { return RoomMessageEventContent::text_plain("malloc stats are not supported on your compiled malloc."); diff --git a/src/service/admin/debug/mod.rs b/src/admin/debug/mod.rs similarity index 100% rename from src/service/admin/debug/mod.rs rename to src/admin/debug/mod.rs diff --git a/src/service/admin/federation/federation_commands.rs b/src/admin/federation/federation_commands.rs similarity index 97% rename from src/service/admin/federation/federation_commands.rs rename to src/admin/federation/federation_commands.rs index b69fe73c..f461c237 100644 --- a/src/service/admin/federation/federation_commands.rs +++ b/src/admin/federation/federation_commands.rs @@ -2,12 +2,7 @@ use std::fmt::Write as _; use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, RoomId, ServerName, UserId}; -use crate::{ - service::admin::{escape_html, get_room_info}, - services, - utils::HtmlEscape, - Result, -}; +use crate::{escape_html, get_room_info, services, utils::HtmlEscape, Result}; pub(crate) async fn disable_room(_body: Vec<&str>, room_id: Box) -> Result { services().rooms.metadata.disable_room(&room_id, true)?; diff --git a/src/service/admin/federation/mod.rs b/src/admin/federation/mod.rs similarity index 100% rename from src/service/admin/federation/mod.rs rename to src/admin/federation/mod.rs diff --git a/src/service/admin/fsck/fsck_commands.rs b/src/admin/fsck/fsck_commands.rs similarity index 100% rename from src/service/admin/fsck/fsck_commands.rs rename to src/admin/fsck/fsck_commands.rs diff --git a/src/service/admin/fsck/mod.rs b/src/admin/fsck/mod.rs similarity index 100% rename from src/service/admin/fsck/mod.rs rename to src/admin/fsck/mod.rs diff --git a/src/admin/handler.rs b/src/admin/handler.rs new file mode 100644 index 00000000..7b7396ef --- /dev/null +++ b/src/admin/handler.rs @@ -0,0 +1,305 @@ +use std::sync::Arc; + +use clap::Parser; +use regex::Regex; +use ruma::{ + events::{ + relation::InReplyTo, + room::message::{Relation::Reply, RoomMessageEventContent}, + TimelineEventType, + }, + OwnedRoomId, OwnedUserId, ServerName, UserId, +}; +use serde_json::value::to_raw_value; +use tokio::sync::MutexGuard; +use tracing::error; + +extern crate conduit_service as service; + +use conduit::{Error, Result}; +pub(crate) use service::admin::{AdminRoomEvent, Service}; +use service::{admin::HandlerResult, pdu::PduBuilder}; + +use self::{fsck::FsckCommand, tester::TesterCommands}; +use crate::{ + appservice, appservice::AppserviceCommand, debug, debug::DebugCommand, escape_html, federation, + federation::FederationCommand, fsck, media, media::MediaCommand, query, query::QueryCommand, room, + room::RoomCommand, server, server::ServerCommand, services, tester, user, user::UserCommand, +}; +pub(crate) const PAGE_SIZE: usize = 100; + +#[cfg_attr(test, derive(Debug))] +#[derive(Parser)] +#[command(name = "@conduit:server.name:", version = env!("CARGO_PKG_VERSION"))] +pub(crate) enum AdminCommand { + #[command(subcommand)] + /// - Commands for managing appservices + Appservices(AppserviceCommand), + + #[command(subcommand)] + /// - Commands for managing local users + Users(UserCommand), + + #[command(subcommand)] + /// - Commands for managing rooms + Rooms(RoomCommand), + + #[command(subcommand)] + /// - Commands for managing federation + Federation(FederationCommand), + + #[command(subcommand)] + /// - Commands for managing the server + Server(ServerCommand), + + #[command(subcommand)] + /// - Commands for managing media + Media(MediaCommand), + + #[command(subcommand)] + /// - Commands for debugging things + Debug(DebugCommand), + + #[command(subcommand)] + /// - Query all the database getters and iterators + Query(QueryCommand), + + #[command(subcommand)] + /// - Query all the database getters and iterators + Fsck(FsckCommand), + + #[command(subcommand)] + Tester(TesterCommands), +} + +#[must_use] +pub fn handle(event: AdminRoomEvent, room: OwnedRoomId, user: OwnedUserId) -> HandlerResult { + Box::pin(handle_event(event, room, user)) +} + +async fn handle_event(event: AdminRoomEvent, admin_room: OwnedRoomId, server_user: OwnedUserId) -> Result<()> { + let (mut message_content, reply) = match event { + AdminRoomEvent::SendMessage(content) => (content, None), + AdminRoomEvent::ProcessMessage(room_message, reply_id) => { + (process_admin_message(room_message).await, Some(reply_id)) + }, + }; + + let mutex_state = Arc::clone( + services() + .globals + .roomid_mutex_state + .write() + .await + .entry(admin_room.clone()) + .or_default(), + ); + let state_lock = mutex_state.lock().await; + + if let Some(reply) = reply { + message_content.relates_to = Some(Reply { + in_reply_to: InReplyTo { + event_id: reply.into(), + }, + }); + } + + let response_pdu = PduBuilder { + event_type: TimelineEventType::RoomMessage, + content: to_raw_value(&message_content).expect("event is valid, we just created it"), + unsigned: None, + state_key: None, + redacts: None, + }; + + if let Err(e) = services() + .rooms + .timeline + .build_and_append_pdu(response_pdu, &server_user, &admin_room, &state_lock) + .await + { + handle_response_error(&e, &admin_room, &server_user, &state_lock).await?; + } + + Ok(()) +} + +async fn handle_response_error( + e: &Error, admin_room: &OwnedRoomId, server_user: &UserId, state_lock: &MutexGuard<'_, ()>, +) -> Result<()> { + error!("Failed to build and append admin room response PDU: \"{e}\""); + let error_room_message = RoomMessageEventContent::text_plain(format!( + "Failed to build and append admin room PDU: \"{e}\"\n\nThe original admin command may have finished \ + successfully, but we could not return the output." + )); + + let response_pdu = PduBuilder { + event_type: TimelineEventType::RoomMessage, + content: to_raw_value(&error_room_message).expect("event is valid, we just created it"), + unsigned: None, + state_key: None, + redacts: None, + }; + + services() + .rooms + .timeline + .build_and_append_pdu(response_pdu, server_user, admin_room, state_lock) + .await?; + + Ok(()) +} + +// Parse and process a message from the admin room +async fn process_admin_message(room_message: String) -> RoomMessageEventContent { + let mut lines = room_message.lines().filter(|l| !l.trim().is_empty()); + let command_line = lines.next().expect("each string has at least one line"); + let body = lines.collect::>(); + + let admin_command = match parse_admin_command(command_line) { + Ok(command) => command, + Err(error) => { + let server_name = services().globals.server_name(); + let message = error.replace("server.name", server_name.as_str()); + let html_message = usage_to_html(&message, server_name); + + return RoomMessageEventContent::text_html(message, html_message); + }, + }; + + match process_admin_command(admin_command, body).await { + Ok(reply_message) => reply_message, + Err(error) => { + let markdown_message = format!("Encountered an error while handling the command:\n```\n{error}\n```",); + let html_message = format!("Encountered an error while handling the command:\n
\n{error}\n
",); + + RoomMessageEventContent::text_html(markdown_message, html_message) + }, + } +} + +// Parse chat messages from the admin room into an AdminCommand object +fn parse_admin_command(command_line: &str) -> Result { + // Note: argv[0] is `@conduit:servername:`, which is treated as the main command + let mut argv = command_line.split_whitespace().collect::>(); + + // Replace `help command` with `command --help` + // Clap has a help subcommand, but it omits the long help description. + if argv.len() > 1 && argv[1] == "help" { + argv.remove(1); + argv.push("--help"); + } + + // Backwards compatibility with `register_appservice`-style commands + let command_with_dashes_argv1; + if argv.len() > 1 && argv[1].contains('_') { + command_with_dashes_argv1 = argv[1].replace('_', "-"); + argv[1] = &command_with_dashes_argv1; + } + + // Backwards compatibility with `register_appservice`-style commands + let command_with_dashes_argv2; + if argv.len() > 2 && argv[2].contains('_') { + command_with_dashes_argv2 = argv[2].replace('_', "-"); + argv[2] = &command_with_dashes_argv2; + } + + // if the user is using the `query` command (argv[1]), replace the database + // function/table calls with underscores to match the codebase + let command_with_dashes_argv3; + if argv.len() > 3 && argv[1].eq("query") { + command_with_dashes_argv3 = argv[3].replace('_', "-"); + argv[3] = &command_with_dashes_argv3; + } + + AdminCommand::try_parse_from(argv).map_err(|error| error.to_string()) +} + +async fn process_admin_command(command: AdminCommand, body: Vec<&str>) -> Result { + let reply_message_content = match command { + AdminCommand::Appservices(command) => appservice::process(command, body).await?, + AdminCommand::Media(command) => media::process(command, body).await?, + AdminCommand::Users(command) => user::process(command, body).await?, + AdminCommand::Rooms(command) => room::process(command, body).await?, + AdminCommand::Federation(command) => federation::process(command, body).await?, + AdminCommand::Server(command) => server::process(command, body).await?, + AdminCommand::Debug(command) => debug::process(command, body).await?, + AdminCommand::Query(command) => query::process(command, body).await?, + AdminCommand::Fsck(command) => fsck::process(command, body).await?, + AdminCommand::Tester(command) => tester::process(command, body).await?, + }; + + Ok(reply_message_content) +} + +// Utility to turn clap's `--help` text to HTML. +fn usage_to_html(text: &str, server_name: &ServerName) -> String { + // Replace `@conduit:servername:-subcmdname` with `@conduit:servername: + // subcmdname` + let text = text.replace(&format!("@conduit:{server_name}:-"), &format!("@conduit:{server_name}: ")); + + // For the conduit admin room, subcommands become main commands + let text = text.replace("SUBCOMMAND", "COMMAND"); + let text = text.replace("subcommand", "command"); + + // Escape option names (e.g. ``) since they look like HTML tags + let text = escape_html(&text); + + // Italicize the first line (command name and version text) + let re = Regex::new("^(.*?)\n").expect("Regex compilation should not fail"); + let text = re.replace_all(&text, "$1\n"); + + // Unmerge wrapped lines + let text = text.replace("\n ", " "); + + // Wrap option names in backticks. The lines look like: + // -V, --version Prints version information + // And are converted to: + // -V, --version: Prints version information + // (?m) enables multi-line mode for ^ and $ + let re = Regex::new("(?m)^ {4}(([a-zA-Z_&;-]+(, )?)+) +(.*)$").expect("Regex compilation should not fail"); + let text = re.replace_all(&text, "$1: $4"); + + // Look for a `[commandbody]` tag. If it exists, use all lines below it that + // start with a `#` in the USAGE section. + let mut text_lines = text.lines().collect::>(); + let mut command_body = String::new(); + + if let Some(line_index) = text_lines.iter().position(|line| *line == "[commandbody]") { + text_lines.remove(line_index); + + while text_lines + .get(line_index) + .is_some_and(|line| line.starts_with('#')) + { + command_body += if text_lines[line_index].starts_with("# ") { + &text_lines[line_index][2..] + } else { + &text_lines[line_index][1..] + }; + command_body += "[nobr]\n"; + text_lines.remove(line_index); + } + } + + let text = text_lines.join("\n"); + + // Improve the usage section + let text = if command_body.is_empty() { + // Wrap the usage line in code tags + let re = Regex::new("(?m)^USAGE:\n {4}(@conduit:.*)$").expect("Regex compilation should not fail"); + re.replace_all(&text, "USAGE:\n$1").to_string() + } else { + // Wrap the usage line in a code block, and add a yaml block example + // This makes the usage of e.g. `register-appservice` more accurate + let re = Regex::new("(?m)^USAGE:\n {4}(.*?)\n\n").expect("Regex compilation should not fail"); + re.replace_all(&text, "USAGE:\n
$1[nobr]\n[commandbodyblock]
") + .replace("[commandbodyblock]", &command_body) + }; + + // Add HTML line-breaks + + text.replace("\n\n\n", "\n\n") + .replace('\n', "
\n") + .replace("[nobr]
", "") +} diff --git a/src/service/admin/media/media_commands.rs b/src/admin/media/media_commands.rs similarity index 98% rename from src/service/admin/media/media_commands.rs rename to src/admin/media/media_commands.rs index 3f1fc8bf..8e87b736 100644 --- a/src/service/admin/media/media_commands.rs +++ b/src/admin/media/media_commands.rs @@ -1,7 +1,7 @@ -use ruma::{events::room::message::RoomMessageEventContent, EventId}; +use ruma::{events::room::message::RoomMessageEventContent, EventId, MxcUri}; use tracing::{debug, info}; -use crate::{service::admin::MxcUri, services, Result}; +use crate::{services, Result}; pub(crate) async fn delete( _body: Vec<&str>, mxc: Option>, event_id: Option>, diff --git a/src/service/admin/media/mod.rs b/src/admin/media/mod.rs similarity index 96% rename from src/service/admin/media/mod.rs rename to src/admin/media/mod.rs index d091f94a..4e21b750 100644 --- a/src/service/admin/media/mod.rs +++ b/src/admin/media/mod.rs @@ -1,8 +1,8 @@ use clap::Subcommand; -use ruma::{events::room::message::RoomMessageEventContent, EventId}; +use ruma::{events::room::message::RoomMessageEventContent, EventId, MxcUri}; use self::media_commands::{delete, delete_list, delete_past_remote_media}; -use crate::{service::admin::MxcUri, Result}; +use crate::Result; pub(crate) mod media_commands; diff --git a/src/admin/mod.rs b/src/admin/mod.rs new file mode 100644 index 00000000..1832cc9b --- /dev/null +++ b/src/admin/mod.rs @@ -0,0 +1,55 @@ +pub(crate) mod appservice; +pub(crate) mod debug; +pub(crate) mod federation; +pub(crate) mod fsck; +pub(crate) mod handler; +pub(crate) mod media; +pub(crate) mod query; +pub(crate) mod room; +pub(crate) mod server; +pub(crate) mod tester; +pub(crate) mod user; +pub(crate) mod utils; + +extern crate conduit_api as api; +extern crate conduit_core as conduit; +extern crate conduit_service as service; + +pub(crate) use conduit::{mod_ctor, mod_dtor, Result}; +pub use handler::handle; +pub(crate) use service::{services, user_is_local}; + +pub(crate) use crate::{ + handler::Service, + utils::{escape_html, get_room_info}, +}; + +mod_ctor! {} +mod_dtor! {} + +#[cfg(test)] +mod test { + use clap::Parser; + + use crate::handler::AdminCommand; + + #[test] + fn get_help_short() { get_help_inner("-h"); } + + #[test] + fn get_help_long() { get_help_inner("--help"); } + + #[test] + fn get_help_subcommand() { get_help_inner("help"); } + + fn get_help_inner(input: &str) { + let error = AdminCommand::try_parse_from(["argv[0] doesn't matter", input]) + .unwrap_err() + .to_string(); + + // Search for a handful of keywords that suggest the help printed properly + assert!(error.contains("Usage:")); + assert!(error.contains("Commands:")); + assert!(error.contains("Options:")); + } +} diff --git a/src/service/admin/query/account_data.rs b/src/admin/query/account_data.rs similarity index 100% rename from src/service/admin/query/account_data.rs rename to src/admin/query/account_data.rs diff --git a/src/service/admin/query/appservice.rs b/src/admin/query/appservice.rs similarity index 100% rename from src/service/admin/query/appservice.rs rename to src/admin/query/appservice.rs diff --git a/src/service/admin/query/globals.rs b/src/admin/query/globals.rs similarity index 100% rename from src/service/admin/query/globals.rs rename to src/admin/query/globals.rs diff --git a/src/service/admin/query/mod.rs b/src/admin/query/mod.rs similarity index 100% rename from src/service/admin/query/mod.rs rename to src/admin/query/mod.rs diff --git a/src/service/admin/query/presence.rs b/src/admin/query/presence.rs similarity index 100% rename from src/service/admin/query/presence.rs rename to src/admin/query/presence.rs diff --git a/src/service/admin/query/room_alias.rs b/src/admin/query/room_alias.rs similarity index 100% rename from src/service/admin/query/room_alias.rs rename to src/admin/query/room_alias.rs diff --git a/src/service/admin/query/sending.rs b/src/admin/query/sending.rs similarity index 100% rename from src/service/admin/query/sending.rs rename to src/admin/query/sending.rs diff --git a/src/service/admin/query/users.rs b/src/admin/query/users.rs similarity index 100% rename from src/service/admin/query/users.rs rename to src/admin/query/users.rs diff --git a/src/service/admin/room/mod.rs b/src/admin/room/mod.rs similarity index 100% rename from src/service/admin/room/mod.rs rename to src/admin/room/mod.rs diff --git a/src/service/admin/room/room_alias_commands.rs b/src/admin/room/room_alias_commands.rs similarity index 98% rename from src/service/admin/room/room_alias_commands.rs rename to src/admin/room/room_alias_commands.rs index 516df071..f2b5c7eb 100644 --- a/src/service/admin/room/room_alias_commands.rs +++ b/src/admin/room/room_alias_commands.rs @@ -3,7 +3,7 @@ use std::fmt::Write as _; use ruma::{events::room::message::RoomMessageEventContent, RoomAliasId}; use super::RoomAliasCommand; -use crate::{service::admin::escape_html, services, Result}; +use crate::{escape_html, services, Result}; pub(crate) async fn process(command: RoomAliasCommand, _body: Vec<&str>) -> Result { match command { diff --git a/src/service/admin/room/room_commands.rs b/src/admin/room/room_commands.rs similarity index 93% rename from src/service/admin/room/room_commands.rs rename to src/admin/room/room_commands.rs index 4e4e60e1..701cfb54 100644 --- a/src/service/admin/room/room_commands.rs +++ b/src/admin/room/room_commands.rs @@ -2,10 +2,7 @@ use std::fmt::Write as _; use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId}; -use crate::{ - service::admin::{escape_html, get_room_info, PAGE_SIZE}, - services, Result, -}; +use crate::{escape_html, get_room_info, handler::PAGE_SIZE, services, Result}; pub(crate) async fn list(_body: Vec<&str>, page: Option) -> Result { // TODO: i know there's a way to do this with clap, but i can't seem to find it diff --git a/src/service/admin/room/room_directory_commands.rs b/src/admin/room/room_directory_commands.rs similarity index 96% rename from src/service/admin/room/room_directory_commands.rs rename to src/admin/room/room_directory_commands.rs index ccce2164..f6429dee 100644 --- a/src/service/admin/room/room_directory_commands.rs +++ b/src/admin/room/room_directory_commands.rs @@ -3,10 +3,7 @@ use std::fmt::Write as _; use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId}; use super::RoomDirectoryCommand; -use crate::{ - service::admin::{escape_html, get_room_info, PAGE_SIZE}, - services, Result, -}; +use crate::{escape_html, get_room_info, handler::PAGE_SIZE, services, Result}; pub(crate) async fn process(command: RoomDirectoryCommand, _body: Vec<&str>) -> Result { match command { diff --git a/src/service/admin/room/room_moderation_commands.rs b/src/admin/room/room_moderation_commands.rs similarity index 83% rename from src/service/admin/room/room_moderation_commands.rs rename to src/admin/room/room_moderation_commands.rs index 5c62e360..03de4cde 100644 --- a/src/service/admin/room/room_moderation_commands.rs +++ b/src/admin/room/room_moderation_commands.rs @@ -1,18 +1,16 @@ -use std::fmt::Write as _; +use std::fmt::Write; +use api::client_server::{get_alias_helper, leave_room}; use ruma::{ events::room::message::RoomMessageEventContent, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, RoomOrAliasId, }; use tracing::{debug, error, info, warn}; -use super::RoomModerationCommand; -use crate::{ - api::client_server::{get_alias_helper, leave_room}, - service::admin::{escape_html, Service}, - services, - utils::user_id::user_is_local, - Result, +use super::{ + super::{escape_html, Service}, + RoomModerationCommand, }; +use crate::{services, user_is_local, Result}; pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> Result { match command { @@ -105,16 +103,16 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> .filter_map(|user| { user.ok().filter(|local_user| { user_is_local(local_user) - // additional wrapped check here is to avoid adding remote users - // who are in the admin room to the list of local users (would fail auth check) - && (user_is_local(local_user) - && services() - .users - .is_admin(local_user) - .unwrap_or(true)) // since this is a force - // operation, assume user - // is an admin if somehow - // this fails + // additional wrapped check here is to avoid adding remote users + // who are in the admin room to the list of local users (would fail auth check) + && (user_is_local(local_user) + && services() + .users + .is_admin(local_user) + .unwrap_or(true)) // since this is a force + // operation, assume user + // is an admin if somehow + // this fails }) }) .collect::>() @@ -134,14 +132,14 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> .filter_map(|user| { user.ok().filter(|local_user| { local_user.server_name() == services().globals.server_name() - // additional wrapped check here is to avoid adding remote users - // who are in the admin room to the list of local users (would fail auth check) - && (local_user.server_name() - == services().globals.server_name() - && !services() - .users - .is_admin(local_user) - .unwrap_or(false)) + // additional wrapped check here is to avoid adding remote users + // who are in the admin room to the list of local users (would fail auth check) + && (local_user.server_name() + == services().globals.server_name() + && !services() + .users + .is_admin(local_user) + .unwrap_or(false)) }) }) .collect::>() @@ -309,19 +307,19 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> .filter_map(|user| { user.ok().filter(|local_user| { local_user.server_name() == services().globals.server_name() - // additional wrapped check here is to avoid adding remote users - // who are in the admin room to the list of local users (would fail auth check) - && (local_user.server_name() - == services().globals.server_name() - && services() - .users - .is_admin(local_user) - .unwrap_or(true)) // since this is a - // force operation, - // assume user is - // an admin if - // somehow this - // fails + // additional wrapped check here is to avoid adding remote users + // who are in the admin room to the list of local users (would fail auth check) + && (local_user.server_name() + == services().globals.server_name() + && services() + .users + .is_admin(local_user) + .unwrap_or(true)) // since this is a + // force operation, + // assume user is + // an admin if + // somehow this + // fails }) }) .collect::>() @@ -341,14 +339,14 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> .filter_map(|user| { user.ok().filter(|local_user| { local_user.server_name() == services().globals.server_name() - // additional wrapped check here is to avoid adding remote users - // who are in the admin room to the list of local users (would fail auth check) - && (local_user.server_name() - == services().globals.server_name() - && !services() - .users - .is_admin(local_user) - .unwrap_or(false)) + // additional wrapped check here is to avoid adding remote users + // who are in the admin room to the list of local users (would fail auth check) + && (local_user.server_name() + == services().globals.server_name() + && !services() + .users + .is_admin(local_user) + .unwrap_or(false)) }) }) .collect::>() diff --git a/src/service/admin/server/mod.rs b/src/admin/server/mod.rs similarity index 100% rename from src/service/admin/server/mod.rs rename to src/admin/server/mod.rs diff --git a/src/service/admin/server/server_commands.rs b/src/admin/server/server_commands.rs similarity index 90% rename from src/service/admin/server/server_commands.rs rename to src/admin/server/server_commands.rs index df82fd86..d80cc3d7 100644 --- a/src/service/admin/server/server_commands.rs +++ b/src/admin/server/server_commands.rs @@ -4,7 +4,7 @@ use crate::{services, Result}; pub(crate) async fn uptime(_body: Vec<&str>) -> Result { let seconds = services() - .globals + .server .started .elapsed() .expect("standard duration") @@ -28,7 +28,7 @@ pub(crate) async fn show_config(_body: Vec<&str>) -> Result) -> Result { let response0 = services().memory_usage().await; let response1 = services().globals.db.memory_usage(); - let response2 = crate::alloc::memory_usage(); + let response2 = conduit::alloc::memory_usage(); Ok(RoomMessageEventContent::text_plain(format!( "Services:\n{response0}\n\nDatabase:\n{response1}\n{}", @@ -69,12 +69,15 @@ pub(crate) async fn backup_database(_body: Vec<&str>) -> Result String::new(), - Err(e) => (*e).to_string(), - }) - .await - .unwrap(); + let mut result = services() + .server + .runtime() + .spawn_blocking(move || match services().globals.db.backup() { + Ok(()) => String::new(), + Err(e) => (*e).to_string(), + }) + .await + .unwrap(); if result.is_empty() { result = services().globals.db.backup_list()?; diff --git a/src/service/admin/tester/mod.rs b/src/admin/tester/mod.rs similarity index 92% rename from src/service/admin/tester/mod.rs rename to src/admin/tester/mod.rs index c0f3df15..f7b4ecea 100644 --- a/src/service/admin/tester/mod.rs +++ b/src/admin/tester/mod.rs @@ -9,6 +9,6 @@ pub(crate) enum TesterCommands { } pub(crate) async fn process(command: TesterCommands, _body: Vec<&str>) -> Result { Ok(match command { - TesterCommands::Tester => RoomMessageEventContent::notice_plain(String::from("complete")), + TesterCommands::Tester => RoomMessageEventContent::notice_plain(String::from("completed")), }) } diff --git a/src/service/admin/user/mod.rs b/src/admin/user/mod.rs similarity index 100% rename from src/service/admin/user/mod.rs rename to src/admin/user/mod.rs diff --git a/src/service/admin/user/user_commands.rs b/src/admin/user/user_commands.rs similarity index 97% rename from src/service/admin/user/user_commands.rs rename to src/admin/user/user_commands.rs index 1aa8d4ea..2ec23f0d 100644 --- a/src/service/admin/user/user_commands.rs +++ b/src/admin/user/user_commands.rs @@ -1,15 +1,13 @@ use std::{fmt::Write as _, sync::Arc}; +use api::client_server::{join_room_by_id_helper, leave_all_rooms}; +use conduit::utils; use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, UserId}; use tracing::{error, info, warn}; -use crate::{ - api::client_server::{join_room_by_id_helper, leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH}, - service::admin::{escape_html, get_room_info}, - services, - utils::{self, user_id::user_is_local}, - Result, -}; +use crate::{escape_html, get_room_info, services, user_is_local, Result}; + +const AUTO_GEN_PASSWORD_LENGTH: usize = 25; pub(crate) async fn list(_body: Vec<&str>) -> Result { match services().users.list_local_users() { @@ -111,7 +109,7 @@ pub(crate) async fn create( ) .await { - Ok(_) => { + Ok(_response) => { info!("Automatically joined room {room} for user {user_id}"); }, Err(e) => { diff --git a/src/admin/utils.rs b/src/admin/utils.rs new file mode 100644 index 00000000..7031b848 --- /dev/null +++ b/src/admin/utils.rs @@ -0,0 +1,30 @@ +pub(crate) use conduit::utils::HtmlEscape; +use ruma::OwnedRoomId; + +use crate::services; + +pub(crate) fn escape_html(s: &str) -> String { + s.replace('&', "&") + .replace('<', "<") + .replace('>', ">") +} + +pub(crate) fn get_room_info(id: &OwnedRoomId) -> (OwnedRoomId, u64, String) { + ( + id.clone(), + services() + .rooms + .state_cache + .room_joined_count(id) + .ok() + .flatten() + .unwrap_or(0), + services() + .rooms + .state_accessor + .get_name(id) + .ok() + .flatten() + .unwrap_or_else(|| id.to_string()), + ) +} diff --git a/src/alloc/default.rs b/src/alloc/default.rs deleted file mode 100644 index 1d61682e..00000000 --- a/src/alloc/default.rs +++ /dev/null @@ -1,7 +0,0 @@ -//! Default allocator with no special features - -/// Always returns the empty string -pub(crate) fn memory_stats() -> String { Default::default() } - -/// Always returns the empty string -pub(crate) fn memory_usage() -> String { Default::default() } diff --git a/src/alloc/hardened.rs b/src/alloc/hardened.rs deleted file mode 100644 index 9ac84f9a..00000000 --- a/src/alloc/hardened.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[global_allocator] -static HMALLOC: hardened_malloc_rs::HardenedMalloc = hardened_malloc_rs::HardenedMalloc; - -pub(crate) fn memory_usage() -> String { - String::default() //TODO: get usage -} - -pub(crate) fn memory_stats() -> String { "Extended statistics are not available from hardened_malloc.".to_owned() } diff --git a/src/api/Cargo.toml b/src/api/Cargo.toml new file mode 100644 index 00000000..890d66af --- /dev/null +++ b/src/api/Cargo.toml @@ -0,0 +1,66 @@ +[package] +name = "conduit_api" +version.workspace = true +edition.workspace = true + +[lib] +path = "mod.rs" +crate-type = [ + "rlib", +# "dylib", +] + +[features] +default = [ + "element_hacks", + "gzip_compression", + "brotli_compression", + "release_max_log_level", +] + +element_hacks = [] +dev_release_log_level = [] +release_max_log_level = [ + "tracing/max_level_trace", + "tracing/release_max_level_info", + "log/max_level_trace", + "log/release_max_level_info", +] +gzip_compression = [ + "reqwest/gzip", +] +brotli_compression = [ + "reqwest/brotli", +] + +[dependencies] +argon2.workspace = true +axum-extra.workspace = true +axum.workspace = true +base64.workspace = true +bytes.workspace = true +conduit-core.workspace = true +conduit-database.workspace = true +conduit-service.workspace = true +futures-util.workspace = true +hmac.workspace = true +http.workspace = true +hyper.workspace = true +image.workspace = true +ipaddress.workspace = true +jsonwebtoken.workspace = true +log.workspace = true +rand.workspace = true +reqwest.workspace = true +ruma.workspace = true +serde_html_form.workspace = true +serde_json.workspace = true +serde.workspace = true +sha-1.workspace = true +thiserror.workspace = true +tokio.workspace = true +tracing.workspace = true +webpage.workspace = true + +[lints] +workspace = true diff --git a/src/api/client_server/account.rs b/src/api/client_server/account.rs index 41343183..14c8fead 100644 --- a/src/api/client_server/account.rs +++ b/src/api/client_server/account.rs @@ -19,9 +19,10 @@ use tracing::{error, info, warn}; use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH}; use crate::{ - api::client_server::{self, join_room_by_id_helper}, - service, services, - utils::{self, user_id::user_is_local}, + client_server::{self, join_room_by_id_helper}, + service::user_is_local, + services, + utils::{self}, Error, Result, Ruma, }; diff --git a/src/api/client_server/alias.rs b/src/api/client_server/alias.rs index 821fa0c2..8c3c0e4c 100644 --- a/src/api/client_server/alias.rs +++ b/src/api/client_server/alias.rs @@ -13,8 +13,9 @@ use ruma::{ use tracing::debug; use crate::{ - debug_info, debug_warn, service::appservice::RegistrationInfo, services, utils::server_name::server_is_ours, Error, - Result, Ruma, + debug_info, debug_warn, + service::{appservice::RegistrationInfo, server_is_ours}, + services, Error, Result, Ruma, }; /// # `PUT /_matrix/client/v3/directory/room/{roomAlias}` @@ -65,7 +66,6 @@ pub(crate) async fn create_alias_route(body: Ruma) -> /// - TODO: Update canonical alias event pub(crate) async fn delete_alias_route(body: Ruma) -> Result { alias_checks(&body.room_alias, &body.appservice_info).await?; - if services() .rooms .alias @@ -99,7 +99,7 @@ pub(crate) async fn get_alias_route(body: Ruma) -> Resul get_alias_helper(body.body.room_alias, None).await } -pub(crate) async fn get_alias_helper( +pub async fn get_alias_helper( room_alias: OwnedRoomAliasId, servers: Option>, ) -> Result { debug!("get_alias_helper servers: {servers:?}"); diff --git a/src/api/client_server/directory.rs b/src/api/client_server/directory.rs index 094e007a..7cfb3392 100644 --- a/src/api/client_server/directory.rs +++ b/src/api/client_server/directory.rs @@ -24,7 +24,7 @@ use ruma::{ }; use tracing::{error, info, warn}; -use crate::{services, utils::server_name::server_is_ours, Error, Result, Ruma}; +use crate::{service::server_is_ours, services, Error, Result, Ruma}; /// # `POST /_matrix/client/v3/publicRooms` /// diff --git a/src/api/client_server/keys.rs b/src/api/client_server/keys.rs index 040916b0..b021bea1 100644 --- a/src/api/client_server/keys.rs +++ b/src/api/client_server/keys.rs @@ -22,8 +22,9 @@ use tracing::debug; use super::SESSION_ID_LENGTH; use crate::{ + service::user_is_local, services, - utils::{self, user_id::user_is_local}, + utils::{self}, Error, Result, Ruma, }; diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index b294fec2..0e70c1dc 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -15,14 +15,16 @@ use webpage::HTML; use crate::{ debug_warn, - service::media::{FileMeta, UrlPreviewData}, + service::{ + media::{FileMeta, UrlPreviewData}, + server_is_ours, + }, services, utils::{ self, content_disposition::{ content_disposition_type, make_content_disposition, make_content_type, sanitise_filename, }, - server_name::server_is_ours, }, Error, Result, Ruma, RumaResponse, }; diff --git a/src/api/client_server/membership.rs b/src/api/client_server/membership.rs index 4fad8cf2..1cee7720 100644 --- a/src/api/client_server/membership.rs +++ b/src/api/client_server/membership.rs @@ -35,9 +35,12 @@ use tracing::{debug, error, info, trace, warn}; use super::get_alias_helper; use crate::{ - service::pdu::{gen_event_id_canonical_json, PduBuilder}, + service::{ + pdu::{gen_event_id_canonical_json, PduBuilder}, + server_is_ours, user_is_local, + }, services, - utils::{self, server_name::server_is_ours, user_id::user_is_local}, + utils::{self}, Error, PduEvent, Result, Ruma, }; @@ -607,7 +610,7 @@ pub(crate) async fn joined_members_route( }) } -pub(crate) async fn join_room_by_id_helper( +pub async fn join_room_by_id_helper( sender_user: Option<&UserId>, room_id: &RoomId, reason: Option, servers: &[OwnedServerName], _third_party_signed: Option<&ThirdPartySigned>, ) -> Result { @@ -1525,7 +1528,7 @@ pub(crate) async fn invite_helper( // Make a user leave all their joined rooms, forgets all rooms, and ignores // errors -pub(crate) async fn leave_all_rooms(user_id: &UserId) { +pub async fn leave_all_rooms(user_id: &UserId) { let all_rooms = services() .rooms .state_cache @@ -1550,7 +1553,7 @@ pub(crate) async fn leave_all_rooms(user_id: &UserId) { } } -pub(crate) async fn leave_room(user_id: &UserId, room_id: &RoomId, reason: Option) -> Result<()> { +pub async fn leave_room(user_id: &UserId, room_id: &RoomId, reason: Option) -> Result<()> { // Ask a remote server if we don't have this room if !services() .rooms diff --git a/src/api/client_server/message.rs b/src/api/client_server/message.rs index 0aa7792d..5bb683f2 100644 --- a/src/api/client_server/message.rs +++ b/src/api/client_server/message.rs @@ -3,6 +3,7 @@ use std::{ sync::Arc, }; +use conduit::PduCount; use ruma::{ api::client::{ error::ErrorKind, @@ -14,10 +15,7 @@ use ruma::{ }; use serde_json::{from_str, Value}; -use crate::{ - service::{pdu::PduBuilder, rooms::timeline::PduCount}, - services, utils, Error, PduEvent, Result, Ruma, -}; +use crate::{service::pdu::PduBuilder, services, utils, Error, PduEvent, Result, Ruma}; /// # `PUT /_matrix/client/v3/rooms/{roomId}/send/{eventType}/{txnId}` /// diff --git a/src/api/client_server/mod.rs b/src/api/client_server/mod.rs index 59d851bf..171e9bbe 100644 --- a/src/api/client_server/mod.rs +++ b/src/api/client_server/mod.rs @@ -1,40 +1,41 @@ -mod account; -mod alias; -mod backup; -mod capabilities; -mod config; -mod context; -mod device; -mod directory; -mod filter; -mod keys; -mod media; -mod membership; -mod message; -mod presence; -mod profile; -mod push; -mod read_marker; -mod redact; -mod relations; -mod report; -mod room; -mod search; -mod session; -mod space; -mod state; -mod sync; -mod tag; -mod thirdparty; -mod threads; -mod to_device; -mod typing; -mod unstable; -mod unversioned; -mod user_directory; -mod voip; +pub(crate) mod account; +pub(crate) mod alias; +pub(crate) mod backup; +pub(crate) mod capabilities; +pub(crate) mod config; +pub(crate) mod context; +pub(crate) mod device; +pub(crate) mod directory; +pub(crate) mod filter; +pub(crate) mod keys; +pub(crate) mod media; +pub(crate) mod membership; +pub(crate) mod message; +pub(crate) mod presence; +pub(crate) mod profile; +pub(crate) mod push; +pub(crate) mod read_marker; +pub(crate) mod redact; +pub(crate) mod relations; +pub(crate) mod report; +pub(crate) mod room; +pub(crate) mod search; +pub(crate) mod session; +pub(crate) mod space; +pub(crate) mod state; +pub(crate) mod sync; +pub(crate) mod tag; +pub(crate) mod thirdparty; +pub(crate) mod threads; +pub(crate) mod to_device; +pub(crate) mod typing; +pub(crate) mod unstable; +pub(crate) mod unversioned; +pub(crate) mod user_directory; +pub(crate) mod voip; pub(crate) use account::*; +pub use alias::get_alias_helper; pub(crate) use alias::*; pub(crate) use backup::*; pub(crate) use capabilities::*; @@ -46,6 +47,7 @@ pub(crate) use filter::*; pub(crate) use keys::*; pub(crate) use media::*; pub(crate) use membership::*; +pub use membership::{join_room_by_id_helper, leave_all_rooms, leave_room}; pub(crate) use message::*; pub(crate) use presence::*; pub(crate) use profile::*; @@ -77,7 +79,4 @@ const DEVICE_ID_LENGTH: usize = 10; const TOKEN_LENGTH: usize = 32; /// generated user session ID length -pub(crate) const SESSION_ID_LENGTH: usize = 32; - -/// auto-generated password length -pub(crate) const AUTO_GEN_PASSWORD_LENGTH: usize = 25; +const SESSION_ID_LENGTH: usize = service::uiaa::SESSION_ID_LENGTH; diff --git a/src/api/client_server/profile.rs b/src/api/client_server/profile.rs index a8cf9af2..b6e4598d 100644 --- a/src/api/client_server/profile.rs +++ b/src/api/client_server/profile.rs @@ -13,7 +13,10 @@ use ruma::{ }; use serde_json::value::to_raw_value; -use crate::{service::pdu::PduBuilder, services, utils::user_id::user_is_local, Error, Result, Ruma}; +use crate::{ + service::{pdu::PduBuilder, user_is_local}, + services, Error, Result, Ruma, +}; /// # `PUT /_matrix/client/r0/profile/{userId}/displayname` /// diff --git a/src/api/client_server/read_marker.rs b/src/api/client_server/read_marker.rs index f3d6c362..0f43eeef 100644 --- a/src/api/client_server/read_marker.rs +++ b/src/api/client_server/read_marker.rs @@ -1,5 +1,6 @@ use std::collections::BTreeMap; +use conduit::PduCount; use ruma::{ api::client::{error::ErrorKind, read_marker::set_read_marker, receipt::create_receipt}, events::{ @@ -9,7 +10,7 @@ use ruma::{ MilliSecondsSinceUnixEpoch, }; -use crate::{service::rooms::timeline::PduCount, services, Error, Result, Ruma}; +use crate::{services, Error, Result, Ruma}; /// # `POST /_matrix/client/r0/rooms/{roomId}/read_markers` /// diff --git a/src/api/client_server/room.rs b/src/api/client_server/room.rs index 46ad4454..db0d4e4a 100644 --- a/src/api/client_server/room.rs +++ b/src/api/client_server/room.rs @@ -1,5 +1,6 @@ use std::{cmp::max, collections::BTreeMap, sync::Arc}; +use conduit::{debug_info, debug_warn}; use ruma::{ api::client::{ error::ErrorKind, @@ -28,8 +29,7 @@ use serde_json::{json, value::to_raw_value}; use tracing::{error, info, warn}; use crate::{ - api::client_server::invite_helper, - debug_info, debug_warn, + client_server::invite_helper, service::{appservice::RegistrationInfo, pdu::PduBuilder}, services, Error, Result, Ruma, }; diff --git a/src/api/client_server/state.rs b/src/api/client_server/state.rs index 03152e3e..7445cc40 100644 --- a/src/api/client_server/state.rs +++ b/src/api/client_server/state.rs @@ -19,10 +19,8 @@ use ruma::{ use tracing::{error, log::warn}; use crate::{ - service::{self, pdu::PduBuilder}, - services, - utils::server_name::server_is_ours, - Error, Result, Ruma, RumaResponse, + service::{pdu::PduBuilder, server_is_ours}, + services, Error, Result, Ruma, RumaResponse, }; /// # `PUT /_matrix/client/*/rooms/{roomId}/state/{eventType}/{stateKey}` diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 8e7282fe..4967ca86 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -5,6 +5,7 @@ use std::{ time::Duration, }; +use conduit::PduCount; use ruma::{ api::client::{ filter::{FilterDefinition, LazyLoadOptions}, @@ -29,10 +30,7 @@ use ruma::{ }; use tracing::{error, Instrument as _, Span}; -use crate::{ - service::{pdu::EventHash, rooms::timeline::PduCount}, - services, utils, Error, PduEvent, Result, Ruma, RumaResponse, -}; +use crate::{service::pdu::EventHash, services, utils, Error, PduEvent, Result, Ruma, RumaResponse}; /// # `GET /_matrix/client/r0/sync` /// diff --git a/src/api/client_server/to_device.rs b/src/api/client_server/to_device.rs index e85b991f..011e08f7 100644 --- a/src/api/client_server/to_device.rs +++ b/src/api/client_server/to_device.rs @@ -8,7 +8,7 @@ use ruma::{ to_device::DeviceIdOrAllDevices, }; -use crate::{services, utils::user_id::user_is_local, Error, Result, Ruma}; +use crate::{services, user_is_local, Error, Result, Ruma}; /// # `PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}` /// diff --git a/src/api/mod.rs b/src/api/mod.rs index 285b9f51..7fe02cfe 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,3 +1,15 @@ -pub(crate) mod client_server; +pub mod client_server; +pub mod router; pub(crate) mod ruma_wrapper; -pub(crate) mod server_server; +pub mod server_server; + +extern crate conduit_core as conduit; +extern crate conduit_service as service; + +pub use client_server::membership::{join_room_by_id_helper, leave_all_rooms}; +pub(crate) use conduit::{debug_error, debug_info, debug_warn, error::RumaResponse, utils, Error, Result}; +pub(crate) use ruma_wrapper::Ruma; +pub(crate) use service::{pdu::PduEvent, services, user_is_local}; + +conduit::mod_ctor! {} +conduit::mod_dtor! {} diff --git a/src/router/routes.rs b/src/api/router.rs similarity index 96% rename from src/router/routes.rs rename to src/api/router.rs index d8b73b4f..068dc375 100644 --- a/src/router/routes.rs +++ b/src/api/router.rs @@ -6,16 +6,15 @@ use axum::{ routing::{any, get, on, post, MethodFilter}, Router, }; +use conduit::{Error, Result, Server}; use http::{Method, Uri}; use ruma::api::{client::error::ErrorKind, IncomingRequest}; -use crate::{ - api::{client_server, server_server}, - Config, Error, Result, Ruma, RumaResponse, -}; +use crate::{client_server, server_server, Ruma, RumaResponse}; -pub(crate) fn routes(config: &Config) -> Router { - let router = Router::new() +pub fn build(router: Router, server: &Server) -> Router { + let config = &server.config; + let router = router .ruma_route(client_server::get_supported_versions_route) .ruma_route(client_server::get_register_available_route) .ruma_route(client_server::register_route) @@ -187,9 +186,7 @@ pub(crate) fn routes(config: &Config) -> Router { .route("/_conduwuit/server_version", get(client_server::conduwuit_server_version)) .route("/_matrix/client/r0/rooms/:room_id/initialSync", get(initial_sync)) .route("/_matrix/client/v3/rooms/:room_id/initialSync", get(initial_sync)) - .route("/client/server.json", get(client_server::syncv3_client_server_json)) - .route("/", get(it_works)) - .fallback(not_found); + .route("/client/server.json", get(client_server::syncv3_client_server_json)); if config.allow_federation { router @@ -230,16 +227,10 @@ pub(crate) fn routes(config: &Config) -> Router { } } -async fn not_found(_uri: Uri) -> impl IntoResponse { - Error::BadRequest(ErrorKind::Unrecognized, "Unrecognized request") -} - async fn initial_sync(_uri: Uri) -> impl IntoResponse { Error::BadRequest(ErrorKind::GuestAccessForbidden, "Guest access not implemented") } -async fn it_works() -> &'static str { "hewwo from conduwuit woof!" } - async fn federation_disabled() -> impl IntoResponse { Error::bad_config("Federation is disabled.") } trait RouterExt { @@ -259,7 +250,7 @@ impl RouterExt for Router { } } -pub(crate) trait RumaHandler { +trait RumaHandler { // Can't transform to a handler without boxing or relying on the nightly-only // impl-trait-in-traits feature. Moving a small amount of extra logic into the // trait allows bypassing both. diff --git a/src/api/ruma_wrapper/axum.rs b/src/api/ruma_wrapper/axum.rs index 5443cc5f..93252b7c 100644 --- a/src/api/ruma_wrapper/axum.rs +++ b/src/api/ruma_wrapper/axum.rs @@ -3,30 +3,26 @@ use std::{collections::BTreeMap, str}; use axum::{ async_trait, extract::{FromRequest, Path}, - response::{IntoResponse, Response}, RequestExt, RequestPartsExt, }; use axum_extra::{ - headers::{ - authorization::{Bearer, Credentials}, - Authorization, - }, + headers::{authorization::Bearer, Authorization}, typed_header::TypedHeaderRejectionReason, TypedHeader, }; use bytes::{BufMut, BytesMut}; -use http::{uri::PathAndQuery, StatusCode}; -use http_body_util::Full; +use conduit::debug_warn; +use http::uri::PathAndQuery; use hyper::Request; use ruma::{ - api::{client::error::ErrorKind, AuthScheme, IncomingRequest, OutgoingResponse}, - CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId, UserId, + api::{client::error::ErrorKind, AuthScheme, IncomingRequest}, + CanonicalJsonValue, OwnedDeviceId, OwnedUserId, UserId, }; use serde::Deserialize; use tracing::{debug, error, trace, warn}; -use super::{Ruma, RumaResponse}; -use crate::{debug_warn, service::appservice::RegistrationInfo, services, Error, Result}; +use super::{xmatrix::XMatrix, Ruma}; +use crate::{service::appservice::RegistrationInfo, services, Error, Result}; enum Token { Appservice(Box), @@ -332,68 +328,3 @@ where }) } } - -struct XMatrix { - origin: OwnedServerName, - destination: Option, - key: String, // KeyName? - sig: String, -} - -impl Credentials for XMatrix { - const SCHEME: &'static str = "X-Matrix"; - - fn decode(value: &http::HeaderValue) -> Option { - debug_assert!( - value.as_bytes().starts_with(b"X-Matrix "), - "HeaderValue to decode should start with \"X-Matrix ..\", received = {value:?}", - ); - - let parameters = str::from_utf8(&value.as_bytes()["X-Matrix ".len()..]) - .ok()? - .trim_start(); - - let mut origin = None; - let mut destination = None; - let mut key = None; - let mut sig = None; - - for entry in parameters.split_terminator(',') { - let (name, value) = entry.split_once('=')?; - - // It's not at all clear why some fields are quoted and others not in the spec, - // let's simply accept either form for every field. - let value = value - .strip_prefix('"') - .and_then(|rest| rest.strip_suffix('"')) - .unwrap_or(value); - - // FIXME: Catch multiple fields of the same name - match name { - "origin" => origin = Some(value.try_into().ok()?), - "key" => key = Some(value.to_owned()), - "sig" => sig = Some(value.to_owned()), - "destination" => destination = Some(value.to_owned()), - _ => debug!("Unexpected field `{name}` in X-Matrix Authorization header"), - } - } - - Some(Self { - origin: origin?, - key: key?, - sig: sig?, - destination, - }) - } - - fn encode(&self) -> http::HeaderValue { todo!() } -} - -impl IntoResponse for RumaResponse { - fn into_response(self) -> Response { - match self.0.try_into_http_response::() { - Ok(res) => res.map(BytesMut::freeze).map(Full::new).into_response(), - Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), - } - } -} diff --git a/src/api/ruma_wrapper/mod.rs b/src/api/ruma_wrapper/mod.rs index 93474816..e32efb5f 100644 --- a/src/api/ruma_wrapper/mod.rs +++ b/src/api/ruma_wrapper/mod.rs @@ -1,10 +1,11 @@ +pub(crate) mod axum; +mod xmatrix; + use std::ops::Deref; -use ruma::{api::client::uiaa::UiaaResponse, CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId}; +use ruma::{CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId}; -use crate::{service::appservice::RegistrationInfo, Error}; - -mod axum; +use crate::service::appservice::RegistrationInfo; /// Extractor for Ruma request structs pub(crate) struct Ruma { @@ -21,14 +22,3 @@ impl Deref for Ruma { fn deref(&self) -> &Self::Target { &self.body } } - -#[derive(Clone)] -pub(crate) struct RumaResponse(pub(crate) T); - -impl From for RumaResponse { - fn from(t: T) -> Self { Self(t) } -} - -impl From for RumaResponse { - fn from(t: Error) -> Self { t.to_response() } -} diff --git a/src/api/ruma_wrapper/xmatrix.rs b/src/api/ruma_wrapper/xmatrix.rs new file mode 100644 index 00000000..74fb7d20 --- /dev/null +++ b/src/api/ruma_wrapper/xmatrix.rs @@ -0,0 +1,61 @@ +use std::str; + +use axum_extra::headers::authorization::Credentials; +use ruma::OwnedServerName; +use tracing::debug; + +pub(crate) struct XMatrix { + pub(crate) origin: OwnedServerName, + pub(crate) destination: Option, + pub(crate) key: String, // KeyName? + pub(crate) sig: String, +} + +impl Credentials for XMatrix { + const SCHEME: &'static str = "X-Matrix"; + + fn decode(value: &http::HeaderValue) -> Option { + debug_assert!( + value.as_bytes().starts_with(b"X-Matrix "), + "HeaderValue to decode should start with \"X-Matrix ..\", received = {value:?}", + ); + + let parameters = str::from_utf8(&value.as_bytes()["X-Matrix ".len()..]) + .ok()? + .trim_start(); + + let mut origin = None; + let mut destination = None; + let mut key = None; + let mut sig = None; + + for entry in parameters.split_terminator(',') { + let (name, value) = entry.split_once('=')?; + + // It's not at all clear why some fields are quoted and others not in the spec, + // let's simply accept either form for every field. + let value = value + .strip_prefix('"') + .and_then(|rest| rest.strip_suffix('"')) + .unwrap_or(value); + + // FIXME: Catch multiple fields of the same name + match name { + "origin" => origin = Some(value.try_into().ok()?), + "key" => key = Some(value.to_owned()), + "sig" => sig = Some(value.to_owned()), + "destination" => destination = Some(value.to_owned()), + _ => debug!("Unexpected field `{name}` in X-Matrix Authorization header"), + } + } + + Some(Self { + origin: origin?, + key: key?, + sig: sig?, + destination, + }) + } + + fn encode(&self) -> http::HeaderValue { todo!() } +} diff --git a/src/api/server_server.rs b/src/api/server_server.rs index 8b3650e0..f9592e3b 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -44,19 +44,23 @@ use ruma::{ }, serde::{Base64, JsonObject, Raw}, to_device::DeviceIdOrAllDevices, - uint, user_id, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, - OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, RoomId, RoomVersionId, ServerName, + uint, user_id, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedServerName, + OwnedServerSigningKeyId, OwnedUserId, RoomId, RoomVersionId, ServerName, }; use serde_json::value::{to_raw_value, RawValue as RawJsonValue}; use tokio::sync::RwLock; use tracing::{debug, error, trace, warn}; use crate::{ - api::client_server::{self, claim_keys_helper, get_keys_helper}, + client_server::{self, claim_keys_helper, get_keys_helper}, debug_error, - service::pdu::{gen_event_id_canonical_json, PduBuilder}, + service::{ + pdu::{gen_event_id_canonical_json, PduBuilder}, + rooms::event_handler::parse_incoming_pdu, + server_is_ours, user_is_local, + }, services, - utils::{self, server_name::server_is_ours, user_id::user_is_local}, + utils::{self}, Error, PduEvent, Result, Ruma, }; @@ -196,32 +200,6 @@ pub(crate) async fn get_public_rooms_route( }) } -pub(crate) fn parse_incoming_pdu(pdu: &RawJsonValue) -> Result<(OwnedEventId, CanonicalJsonObject, OwnedRoomId)> { - let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| { - warn!("Error parsing incoming event {:?}: {:?}", pdu, e); - Error::BadServerResponse("Invalid PDU in server response") - })?; - - let room_id: OwnedRoomId = value - .get("room_id") - .and_then(|id| RoomId::parse(id.as_str()?).ok()) - .ok_or(Error::BadRequest(ErrorKind::InvalidParam, "Invalid room id in pdu"))?; - - let Ok(room_version_id) = services().rooms.state.get_room_version(&room_id) else { - return Err(Error::Err(format!("Server is not in room {room_id}"))); - }; - - let Ok((event_id, value)) = gen_event_id_canonical_json(pdu, &room_version_id) else { - // Event could not be converted to canonical json - return Err(Error::BadRequest( - ErrorKind::InvalidParam, - "Could not convert event to canonical json.", - )); - }; - - Ok((event_id, value, room_id)) -} - /// # `PUT /_matrix/federation/v1/send/{txnId}` /// /// Push EDUs and PDUs to this server. diff --git a/src/bin/Cargo.toml b/src/bin/Cargo.toml new file mode 100644 index 00000000..e50dba24 --- /dev/null +++ b/src/bin/Cargo.toml @@ -0,0 +1,123 @@ +[package] +# TODO: when can we rename to conduwuit? +name = "conduit" +default-run = "conduit" +description.workspace = true +license.workspace = true +authors.workspace = true +homepage.workspace = true +repository.workspace = true +readme.workspace = true +version.workspace = true +edition.workspace = true +rust-version.workspace = true + +[package.metadata.deb] +name = "conduwuit" +maintainer = "strawberry " +copyright = "2024, strawberry " +license-file = ["LICENSE", "3"] +depends = "$auto, ca-certificates" +extended-description = """\ +a cool hard fork of Conduit, a Matrix homeserver written in Rust""" +section = "net" +priority = "optional" +conf-files = ["/etc/conduwuit/conduwuit.toml"] +maintainer-scripts = "debian/" +systemd-units = { unit-name = "conduwuit", start = false } +assets = [ + ["debian/README.md", "usr/share/doc/conduwuit/README.Debian", "644"], + ["README.md", "usr/share/doc/conduwuit/", "644"], + ["target/release/conduwuit", "usr/sbin/conduwuit", "755"], + ["conduwuit-example.toml", "etc/conduwuit/conduwuit.toml", "640"], +] + +[features] +default = [ + "sentry_telemetry", + "release_max_log_level", +] + +# increases performance, reduces build times, and reduces binary size by not compiling or +# genreating code for log level filters that users will generally not use (debug and trace) +release_max_log_level = [ + "tracing/max_level_trace", + "tracing/release_max_level_info", + "log/max_level_trace", + "log/release_max_level_info", +] +sentry_telemetry = [ + "dep:sentry", + "dep:sentry-tracing", + "dep:sentry-tower", +] +# enable the tokio_console server ncompatible with release_max_log_level +tokio_console = [ + "dep:console-subscriber", + "tokio/tracing", +] +perf_measurements = [ + "dep:opentelemetry", + "dep:tracing-flame", + "dep:tracing-opentelemetry", + "dep:opentelemetry_sdk", + "dep:opentelemetry-jaeger", +] +jemalloc = [ + "dep:tikv-jemallocator", +] +panic_trap = [] +mods = [] + +[dependencies] +conduit-router.workspace = true +conduit-admin.workspace = true +conduit-api.workspace = true +conduit-service.workspace = true +conduit-database.workspace = true +conduit-core.workspace = true + +tokio.workspace = true +log.workspace = true +tracing.workspace = true +tracing-subscriber.workspace = true +clap.workspace = true +num_cpus.workspace = true + +opentelemetry.workspace = true +opentelemetry.optional = true +tracing-flame.workspace = true +tracing-flame.optional = true +tracing-opentelemetry.workspace = true +tracing-opentelemetry.optional = true +opentelemetry_sdk.workspace = true +opentelemetry_sdk.optional = true +opentelemetry-jaeger.workspace = true +opentelemetry-jaeger.optional = true + +sentry.workspace = true +sentry.optional = true +sentry-tracing.workspace = true +sentry-tracing.optional = true +sentry-tower.workspace = true +sentry-tower.optional = true + +tikv-jemallocator.workspace = true +tikv-jemallocator.optional = true + +tokio-metrics.workspace = true +tokio-metrics.optional = true + +console-subscriber.workspace = true +console-subscriber.optional = true + +[target.'cfg(all(not(target_env = "msvc"), target_os = "linux"))'.dependencies] +hardened_malloc-rs.workspace = true +hardened_malloc-rs.optional = true + +[lints] +workspace = true + +[[bin]] +name = "conduit" +path = "main.rs" diff --git a/src/bin/main.rs b/src/bin/main.rs new file mode 100644 index 00000000..0d049fcb --- /dev/null +++ b/src/bin/main.rs @@ -0,0 +1,96 @@ +mod mods; +mod server; + +extern crate conduit_core as conduit; + +use std::{cmp, sync::Arc, time::Duration}; + +use conduit::{debug_info, error, utils::clap, Error, Result}; +use server::Server; +use tokio::runtime; + +const WORKER_NAME: &str = "conduwuit:worker"; +const WORKER_MIN: usize = 2; +const WORKER_KEEPALIVE_MS: u64 = 2500; + +fn main() -> Result<(), Error> { + let args = clap::parse(); + let runtime = runtime::Builder::new_multi_thread() + .enable_io() + .enable_time() + .thread_name(WORKER_NAME) + .worker_threads(cmp::max(WORKER_MIN, num_cpus::get())) + .thread_keep_alive(Duration::from_millis(WORKER_KEEPALIVE_MS)) + .build() + .expect("built runtime"); + + let handle = runtime.handle(); + let server: Arc = Server::build(args, Some(handle))?; + runtime.block_on(async { async_main(server.clone()).await })?; + + // explicit drop here to trace thread and tls dtors + drop(runtime); + + debug_info!("Exit"); + Ok(()) +} + +/// Operate the server normally in release-mode static builds. This will start, +/// run and stop the server within the asynchronous runtime. +#[cfg(not(feature = "mods"))] +async fn async_main(server: Arc) -> Result<(), Error> { + extern crate conduit_router as router; + use tracing::error; + + if let Err(error) = router::start(&server.server).await { + error!("Critical error starting server: {error}"); + return Err(error); + } + + if let Err(error) = router::run(&server.server).await { + error!("Critical error running server: {error}"); + return Err(error); + } + + if let Err(error) = router::stop(&server.server).await { + error!("Critical error stopping server: {error}"); + return Err(error); + } + + debug_info!("Exit runtime"); + Ok(()) +} + +/// Operate the server in developer-mode dynamic builds. This will start, run, +/// and hot-reload portions of the server as-needed before returning for an +/// actual shutdown. This is not available in release-mode or static builds. +#[cfg(feature = "mods")] +async fn async_main(server: Arc) -> Result<(), Error> { + let mut starts = true; + let mut reloads = true; + while reloads { + if let Err(error) = mods::open(&server).await { + error!("Loading router: {error}"); + return Err(error); + } + + let result = mods::run(&server, starts).await; + if let Ok(result) = result { + (starts, reloads) = result; + } + + let force = !reloads || result.is_err(); + if let Err(error) = mods::close(&server, force).await { + error!("Unloading router: {error}"); + return Err(error); + } + + if let Err(error) = result { + error!("{error}"); + return Err(error); + } + } + + debug_info!("Exit runtime"); + Ok(()) +} diff --git a/src/bin/mods.rs b/src/bin/mods.rs new file mode 100644 index 00000000..404fa467 --- /dev/null +++ b/src/bin/mods.rs @@ -0,0 +1,129 @@ +#![cfg(feature = "mods")] +#[cfg(not(any(clippy, debug_assertions, doctest, test)))] +compile_error!("Feature 'mods' is only available in developer builds"); + +use std::{ + future::Future, + pin::Pin, + sync::{atomic::Ordering, Arc}, +}; + +use conduit::{mods, Error, Result}; +use tracing::{debug, error}; + +use crate::Server; + +type RunFuncResult = Pin>>>; +type RunFuncProto = fn(&Arc) -> RunFuncResult; + +const RESTART_THRESH: &str = "conduit_service"; +const MODULE_NAMES: &[&str] = &[ + //"conduit_core", + "conduit_database", + "conduit_service", + "conduit_api", + "conduit_admin", + "conduit_router", +]; + +#[cfg(feature = "panic_trap")] +conduit::mod_init! {{ + conduit::debug::set_panic_trap(); +}} + +pub(crate) async fn run(server: &Arc, starts: bool) -> Result<(bool, bool), Error> { + let main_lock = server.mods.read().await; + let main_mod = (*main_lock).last().expect("main module loaded"); + if starts { + let start = main_mod.get::("start")?; + if let Err(error) = start(&server.server).await { + error!("Starting server: {error}"); + return Err(error); + } + } + let run = main_mod.get::("run")?; + if let Err(error) = run(&server.server).await { + error!("Running server: {error}"); + return Err(error); + } + let reloads = server.server.reload.swap(false, Ordering::AcqRel); + let stops = !reloads || stale(server).await? <= restart_thresh(); + let starts = reloads && stops; + if stops { + let stop = main_mod.get::("stop")?; + if let Err(error) = stop(&server.server).await { + error!("Stopping server: {error}"); + return Err(error); + } + } + + Ok((starts, reloads)) +} + +pub(crate) async fn open(server: &Arc) -> Result { + let mut mods_lock = server.mods.write().await; + let mods: &mut Vec = &mut mods_lock; + debug!( + available = %available(), + loaded = %mods.len(), + "Loading modules", + ); + + for (i, name) in MODULE_NAMES.iter().enumerate() { + if mods.get(i).is_none() { + mods.push(mods::Module::from_name(name)?); + } + } + + Ok(mods.len()) +} + +pub(crate) async fn close(server: &Arc, force: bool) -> Result { + let stale = stale_count(server).await; + let mut mods_lock = server.mods.write().await; + let mods: &mut Vec = &mut mods_lock; + debug!( + available = %available(), + loaded = %mods.len(), + stale = %stale, + force, + "Unloading modules", + ); + + while mods.last().is_some() { + let module = &mods.last().expect("module"); + if force || module.deleted()? { + mods.pop(); + } else { + break; + } + } + + Ok(mods.len()) +} + +async fn stale_count(server: &Arc) -> usize { + let watermark = stale(server).await.unwrap_or(available()); + available() - watermark +} + +async fn stale(server: &Arc) -> Result { + let mods_lock = server.mods.read().await; + let mods: &Vec = &mods_lock; + for (i, module) in mods.iter().enumerate() { + if module.deleted()? { + return Ok(i); + } + } + + Ok(mods.len()) +} + +fn restart_thresh() -> usize { + MODULE_NAMES + .iter() + .position(|&name| name.ends_with(RESTART_THRESH)) + .unwrap_or(MODULE_NAMES.len()) +} + +const fn available() -> usize { MODULE_NAMES.len() } diff --git a/src/bin/server.rs b/src/bin/server.rs new file mode 100644 index 00000000..e63c0dc0 --- /dev/null +++ b/src/bin/server.rs @@ -0,0 +1,186 @@ +use std::sync::Arc; + +use conduit::{ + conduwuit_version, + config::Config, + info, + log::{LogLevelReloadHandles, ReloadHandle}, + utils::{clap, maximize_fd_limit}, + Error, Result, +}; +use tokio::runtime; +use tracing_subscriber::{prelude::*, reload, EnvFilter, Registry}; + +/// Server runtime state; complete +pub(crate) struct Server { + /// Server runtime state; public portion + pub(crate) server: Arc, + + _tracing_flame_guard: TracingFlameGuard, + + #[cfg(feature = "sentry_telemetry")] + _sentry_guard: Option, + + // Module instances; TODO: move to mods::loaded mgmt vector + #[cfg(feature = "mods")] + pub(crate) mods: tokio::sync::RwLock>, +} + +impl Server { + pub(crate) fn build(args: clap::Args, runtime: Option<&runtime::Handle>) -> Result, Error> { + let config = Config::new(args.config)?; + #[cfg(feature = "sentry_telemetry")] + let sentry_guard = init_sentry(&config); + let (tracing_reload_handle, tracing_flame_guard) = init_tracing(&config); + + config.check()?; + #[cfg(unix)] + maximize_fd_limit().expect("Unable to increase maximum soft and hard file descriptor limit"); + info!( + server_name = %config.server_name, + database_path = ?config.database_path, + log_levels = %config.log, + "{}", + conduwuit_version(), + ); + + Ok(Arc::new(Server { + server: Arc::new(conduit::Server::new(config, runtime.cloned(), tracing_reload_handle)), + + _tracing_flame_guard: tracing_flame_guard, + + #[cfg(feature = "sentry_telemetry")] + _sentry_guard: sentry_guard, + + #[cfg(feature = "mods")] + mods: tokio::sync::RwLock::new(Vec::new()), + })) + } +} + +#[cfg(feature = "sentry_telemetry")] +fn init_sentry(config: &Config) -> Option { + if !config.sentry { + return None; + } + + let sentry_endpoint = config + .sentry_endpoint + .as_ref() + .expect("init_sentry should only be called if sentry is enabled and this is not None") + .as_str(); + + let server_name = if config.sentry_send_server_name { + Some(config.server_name.to_string().into()) + } else { + None + }; + + Some(sentry::init(( + sentry_endpoint, + sentry::ClientOptions { + release: sentry::release_name!(), + traces_sample_rate: config.sentry_traces_sample_rate, + server_name, + ..Default::default() + }, + ))) +} + +#[cfg(feature = "perf_measurements")] +type TracingFlameGuard = Option>>; +#[cfg(not(feature = "perf_measurements"))] +type TracingFlameGuard = (); + +// clippy thinks the filter_layer clones are redundant if the next usage is +// behind a disabled feature. +#[allow(clippy::redundant_clone)] +fn init_tracing(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard) { + let registry = Registry::default(); + let fmt_layer = tracing_subscriber::fmt::Layer::new(); + 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 occured while parsing it: {e}"); + EnvFilter::try_new("warn").unwrap() + }, + }; + + let mut reload_handles = Vec:: + Send + Sync>>::new(); + let subscriber = registry; + + #[cfg(feature = "tokio_console")] + let subscriber = { + let console_layer = console_subscriber::spawn(); + subscriber.with(console_layer) + }; + + let (fmt_reload_filter, fmt_reload_handle) = reload::Layer::new(filter_layer.clone()); + reload_handles.push(Box::new(fmt_reload_handle)); + let subscriber = subscriber.with(fmt_layer.with_filter(fmt_reload_filter)); + + #[cfg(feature = "sentry_telemetry")] + let subscriber = { + let sentry_layer = sentry_tracing::layer(); + let (sentry_reload_filter, sentry_reload_handle) = reload::Layer::new(filter_layer.clone()); + reload_handles.push(Box::new(sentry_reload_handle)); + subscriber.with(sentry_layer.with_filter(sentry_reload_filter)) + }; + + #[cfg(feature = "perf_measurements")] + let (subscriber, flame_guard) = { + let (flame_layer, flame_guard) = if config.tracing_flame { + let flame_filter = match EnvFilter::try_new(&config.tracing_flame_filter) { + Ok(flame_filter) => flame_filter, + Err(e) => panic!("tracing_flame_filter config value is invalid: {e}"), + }; + + let (flame_layer, flame_guard) = + match tracing_flame::FlameLayer::with_file(&config.tracing_flame_output_path) { + Ok(ok) => ok, + Err(e) => { + panic!("failed to initialize tracing-flame: {e}"); + }, + }; + let flame_layer = flame_layer + .with_empty_samples(false) + .with_filter(flame_filter); + (Some(flame_layer), Some(flame_guard)) + } else { + (None, None) + }; + + let jaeger_layer = if config.allow_jaeger { + opentelemetry::global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new()); + let tracer = opentelemetry_jaeger::new_agent_pipeline() + .with_auto_split_batch(true) + .with_service_name("conduwuit") + .install_batch(opentelemetry_sdk::runtime::Tokio) + .unwrap(); + let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); + + let (jaeger_reload_filter, jaeger_reload_handle) = reload::Layer::new(filter_layer); + reload_handles.push(Box::new(jaeger_reload_handle)); + Some(telemetry.with_filter(jaeger_reload_filter)) + } else { + None + }; + + let subscriber = subscriber.with(flame_layer).with(jaeger_layer); + (subscriber, flame_guard) + }; + + #[cfg(not(feature = "perf_measurements"))] + #[cfg_attr(not(feature = "perf_measurements"), allow(clippy::let_unit_value))] + let flame_guard = (); + + tracing::subscriber::set_global_default(subscriber).unwrap(); + + #[cfg(all(feature = "tokio_console", feature = "release_max_log_level"))] + tracing::error!( + "'tokio_console' feature and 'release_max_log_level' feature are incompatible, because console-subscriber \ + needs access to trace-level events. 'release_max_log_level' must be disabled to use tokio-console." + ); + + (LogLevelReloadHandles::new(reload_handles), flame_guard) +} diff --git a/src/core/Cargo.toml b/src/core/Cargo.toml new file mode 100644 index 00000000..89ec7248 --- /dev/null +++ b/src/core/Cargo.toml @@ -0,0 +1,133 @@ +[package] +name = "conduit_core" +version.workspace = true +edition.workspace = true + +[lib] +path = "mod.rs" +crate-type = [ + "rlib", +# "dylib", +] + +[features] +default = [ + "rocksdb", + "io_uring", + "jemalloc", + "gzip_compression", + "zstd_compression", + "brotli_compression", + "sentry_telemetry", + "release_max_log_level", +] + +dev_release_log_level = [] +release_max_log_level = [ + "tracing/max_level_trace", + "tracing/release_max_level_info", + "log/max_level_trace", + "log/release_max_level_info", +] +sqlite = [ + "dep:rusqlite", + "dep:parking_lot", + "dep:thread_local", +] +rocksdb = [ + "dep:rust-rocksdb", +] +jemalloc = [ + "dep:tikv-jemalloc-sys", + "dep:tikv-jemalloc-ctl", + "dep:tikv-jemallocator", + "rust-rocksdb/jemalloc", +] +jemalloc_prof = [ + "tikv-jemalloc-sys/profiling", +] +hardened_malloc = [ + "dep:hardened_malloc-rs" +] +io_uring = [ + "rust-rocksdb/io-uring", +] +zstd_compression = [ + "rust-rocksdb/zstd", +] +gzip_compression = [ + "reqwest/gzip", +] +brotli_compression = [ + "reqwest/brotli", +] +perf_measurements = [] +sentry_telemetry = [] +mods = [ + "dep:libloading" +] +panic_trap = [] + +[dependencies] +async-trait.workspace = true +axum-server.workspace = true +axum.workspace = true +base64.workspace = true +bytes.workspace = true +clap.workspace = true +cyborgtime.workspace = true +either.workspace = true +figment.workspace = true +futures-util.workspace = true +http-body-util.workspace = true +http.workspace = true +image.workspace = true +infer.workspace = true +ipaddress.workspace = true +itertools.workspace = true +libloading.workspace = true +libloading.optional = true +log.workspace = true +lru-cache.workspace = true +parking_lot.optional = true +parking_lot.workspace = true +rand.workspace = true +regex.workspace = true +reqwest.workspace = true +ring.workspace = true +ruma.workspace = true +rusqlite.optional = true +rusqlite.workspace = true +rust-rocksdb.optional = true +rust-rocksdb.workspace = true +sanitize-filename.workspace = true +serde_json.workspace = true +serde_regex.workspace = true +serde.workspace = true +serde_yaml.workspace = true +sha-1.workspace = true +thiserror.workspace = true +thread_local.optional = true +thread_local.workspace = true +tikv-jemallocator.optional = true +tikv-jemallocator.workspace = true +tikv-jemalloc-ctl.optional = true +tikv-jemalloc-ctl.workspace = true +tikv-jemalloc-sys.optional = true +tikv-jemalloc-sys.workspace = true +tokio.workspace = true +tracing-subscriber.workspace = true +tracing.workspace = true +url.workspace = true +zstd.optional = true +zstd.workspace = true + +[target.'cfg(unix)'.dependencies] +nix.workspace = true + +[target.'cfg(all(not(target_env = "msvc"), target_os = "linux"))'.dependencies] +hardened_malloc-rs.workspace = true +hardened_malloc-rs.optional = true + +[lints] +workspace = true diff --git a/src/core/alloc/default.rs b/src/core/alloc/default.rs new file mode 100644 index 00000000..6e4128bf --- /dev/null +++ b/src/core/alloc/default.rs @@ -0,0 +1,9 @@ +//! Default allocator with no special features + +/// Always returns the empty string +#[must_use] +pub fn memory_stats() -> String { Default::default() } + +/// Always returns the empty string +#[must_use] +pub fn memory_usage() -> String { Default::default() } diff --git a/src/core/alloc/hardened.rs b/src/core/alloc/hardened.rs new file mode 100644 index 00000000..4c9563cf --- /dev/null +++ b/src/core/alloc/hardened.rs @@ -0,0 +1,10 @@ +#[global_allocator] +static HMALLOC: hardened_malloc_rs::HardenedMalloc = hardened_malloc_rs::HardenedMalloc; + +#[must_use] +pub fn memory_usage() -> String { + String::default() //TODO: get usage +} + +#[must_use] +pub fn memory_stats() -> String { "Extended statistics are not available from hardened_malloc.".to_owned() } diff --git a/src/alloc/je.rs b/src/core/alloc/je.rs similarity index 95% rename from src/alloc/je.rs rename to src/core/alloc/je.rs index 1a33de79..4092d815 100644 --- a/src/alloc/je.rs +++ b/src/core/alloc/je.rs @@ -7,7 +7,8 @@ use tikv_jemallocator as jemalloc; #[global_allocator] static JEMALLOC: jemalloc::Jemalloc = jemalloc::Jemalloc; -pub(crate) fn memory_usage() -> String { +#[must_use] +pub fn memory_usage() -> String { use mallctl::stats; let allocated = stats::allocated::read().unwrap_or_default() as f64 / 1024.0 / 1024.0; let active = stats::active::read().unwrap_or_default() as f64 / 1024.0 / 1024.0; @@ -21,7 +22,8 @@ pub(crate) fn memory_usage() -> String { ) } -pub(crate) fn memory_stats() -> String { +#[must_use] +pub fn memory_stats() -> String { const MAX_LENGTH: usize = 65536 - 4096; let opts_s = "d"; diff --git a/src/alloc/mod.rs b/src/core/alloc/mod.rs similarity index 80% rename from src/alloc/mod.rs rename to src/core/alloc/mod.rs index 6b7c89a1..ceb9f498 100644 --- a/src/alloc/mod.rs +++ b/src/core/alloc/mod.rs @@ -2,24 +2,24 @@ // jemalloc #[cfg(all(not(target_env = "msvc"), feature = "jemalloc", not(feature = "hardened_malloc")))] -mod je; +pub mod je; #[cfg(all(not(target_env = "msvc"), feature = "jemalloc", not(feature = "hardened_malloc")))] -pub(crate) use je::{memory_stats, memory_usage}; +pub use je::{memory_stats, memory_usage}; // hardened_malloc #[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", target_os = "linux", not(feature = "jemalloc")))] -mod hardened; +pub mod hardened; #[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", target_os = "linux", not(feature = "jemalloc")))] -pub(crate) use hardened::{memory_stats, memory_usage}; +pub use hardened::{memory_stats, memory_usage}; // default, enabled when none or multiple of the above are enabled #[cfg(any( not(any(feature = "jemalloc", feature = "hardened_malloc")), all(feature = "jemalloc", feature = "hardened_malloc"), ))] -mod default; +pub mod default; #[cfg(any( not(any(feature = "jemalloc", feature = "hardened_malloc")), all(feature = "jemalloc", feature = "hardened_malloc"), ))] -pub(crate) use default::{memory_stats, memory_usage}; +pub use default::{memory_stats, memory_usage}; diff --git a/src/config/check.rs b/src/core/config/check.rs similarity index 98% rename from src/config/check.rs rename to src/core/config/check.rs index 62a874d6..99ca3cfd 100644 --- a/src/config/check.rs +++ b/src/core/config/check.rs @@ -3,9 +3,9 @@ use std::path::Path; // not unix specific, just only for UNIX sockets stuff and use tracing::{debug, error, info, warn}; -use crate::{utils::error::Error, Config}; +use crate::{error::Error, Config}; -pub(crate) fn check(config: &Config) -> Result<(), Error> { +pub fn check(config: &Config) -> Result<(), Error> { config.warn_deprecated(); config.warn_unknown_key(); diff --git a/src/config/mod.rs b/src/core/config/mod.rs similarity index 80% rename from src/config/mod.rs rename to src/core/config/mod.rs index 8b84a9b1..4b85fb53 100644 --- a/src/config/mod.rs +++ b/src/core/config/mod.rs @@ -22,11 +22,12 @@ use serde::{de::IgnoredAny, Deserialize}; use tracing::{debug, error, warn}; use url::Url; -use self::{check::check, proxy::ProxyConfig}; -use crate::utils::error::Error; +pub use self::check::check; +use self::proxy::ProxyConfig; +use crate::error::Error; -pub(crate) mod check; -mod proxy; +pub mod check; +pub mod proxy; #[derive(Deserialize, Clone, Debug)] #[serde(transparent)] @@ -38,310 +39,310 @@ struct ListeningPort { /// all the config options for conduwuit #[derive(Clone, Debug, Deserialize)] #[allow(clippy::struct_excessive_bools)] -pub(crate) struct Config { +pub struct Config { /// [`IpAddr`] conduwuit will listen on (can be IPv4 or IPv6) #[serde(default = "default_address")] - pub(crate) address: IpAddr, + pub address: IpAddr, /// default TCP port(s) conduwuit will listen on #[serde(default = "default_port")] port: ListeningPort, - pub(crate) tls: Option, - pub(crate) unix_socket_path: Option, + pub tls: Option, + pub unix_socket_path: Option, #[serde(default = "default_unix_socket_perms")] - pub(crate) unix_socket_perms: u32, - pub(crate) server_name: OwnedServerName, + pub unix_socket_perms: u32, + pub server_name: OwnedServerName, #[serde(default = "default_database_backend")] - pub(crate) database_backend: String, - pub(crate) database_path: PathBuf, - pub(crate) database_backup_path: Option, + pub database_backend: String, + pub database_path: PathBuf, + pub database_backup_path: Option, #[serde(default = "default_database_backups_to_keep")] - pub(crate) database_backups_to_keep: i16, + pub database_backups_to_keep: i16, #[serde(default = "default_db_cache_capacity_mb")] - pub(crate) db_cache_capacity_mb: f64, + pub db_cache_capacity_mb: f64, #[serde(default = "default_new_user_displayname_suffix")] - pub(crate) new_user_displayname_suffix: String, + pub new_user_displayname_suffix: String, #[serde(default)] - pub(crate) allow_check_for_updates: bool, + pub allow_check_for_updates: bool, #[serde(default = "default_pdu_cache_capacity")] - pub(crate) pdu_cache_capacity: u32, + pub pdu_cache_capacity: u32, #[serde(default = "default_conduit_cache_capacity_modifier")] - pub(crate) conduit_cache_capacity_modifier: f64, + pub conduit_cache_capacity_modifier: f64, #[serde(default = "default_auth_chain_cache_capacity")] - pub(crate) auth_chain_cache_capacity: u32, + pub auth_chain_cache_capacity: u32, #[serde(default = "default_shorteventid_cache_capacity")] - pub(crate) shorteventid_cache_capacity: u32, + pub shorteventid_cache_capacity: u32, #[serde(default = "default_eventidshort_cache_capacity")] - pub(crate) eventidshort_cache_capacity: u32, + pub eventidshort_cache_capacity: u32, #[serde(default = "default_shortstatekey_cache_capacity")] - pub(crate) shortstatekey_cache_capacity: u32, + pub shortstatekey_cache_capacity: u32, #[serde(default = "default_statekeyshort_cache_capacity")] - pub(crate) statekeyshort_cache_capacity: u32, + pub statekeyshort_cache_capacity: u32, #[serde(default = "default_server_visibility_cache_capacity")] - pub(crate) server_visibility_cache_capacity: u32, + pub server_visibility_cache_capacity: u32, #[serde(default = "default_user_visibility_cache_capacity")] - pub(crate) user_visibility_cache_capacity: u32, + pub user_visibility_cache_capacity: u32, #[serde(default = "default_stateinfo_cache_capacity")] - pub(crate) stateinfo_cache_capacity: u32, + pub stateinfo_cache_capacity: u32, #[serde(default = "default_roomid_spacehierarchy_cache_capacity")] - pub(crate) roomid_spacehierarchy_cache_capacity: u32, + pub roomid_spacehierarchy_cache_capacity: u32, #[serde(default = "default_cleanup_second_interval")] - pub(crate) cleanup_second_interval: u32, + pub cleanup_second_interval: u32, #[serde(default = "default_dns_cache_entries")] - pub(crate) dns_cache_entries: u32, + pub dns_cache_entries: u32, #[serde(default = "default_dns_min_ttl")] - pub(crate) dns_min_ttl: u64, + pub dns_min_ttl: u64, #[serde(default = "default_dns_min_ttl_nxdomain")] - pub(crate) dns_min_ttl_nxdomain: u64, + pub dns_min_ttl_nxdomain: u64, #[serde(default = "default_dns_attempts")] - pub(crate) dns_attempts: u16, + pub dns_attempts: u16, #[serde(default = "default_dns_timeout")] - pub(crate) dns_timeout: u64, + pub dns_timeout: u64, #[serde(default = "true_fn")] - pub(crate) dns_tcp_fallback: bool, + pub dns_tcp_fallback: bool, #[serde(default = "true_fn")] - pub(crate) query_all_nameservers: bool, + pub query_all_nameservers: bool, #[serde(default)] - pub(crate) query_over_tcp_only: bool, + pub query_over_tcp_only: bool, #[serde(default = "default_ip_lookup_strategy")] - pub(crate) ip_lookup_strategy: u8, + pub ip_lookup_strategy: u8, #[serde(default = "default_max_request_size")] - pub(crate) max_request_size: u32, + pub max_request_size: u32, #[serde(default = "default_max_fetch_prev_events")] - pub(crate) max_fetch_prev_events: u16, + pub max_fetch_prev_events: u16, #[serde(default = "default_request_conn_timeout")] - pub(crate) request_conn_timeout: u64, + pub request_conn_timeout: u64, #[serde(default = "default_request_timeout")] - pub(crate) request_timeout: u64, + pub request_timeout: u64, #[serde(default = "default_request_total_timeout")] - pub(crate) request_total_timeout: u64, + pub request_total_timeout: u64, #[serde(default = "default_request_idle_timeout")] - pub(crate) request_idle_timeout: u64, + pub request_idle_timeout: u64, #[serde(default = "default_request_idle_per_host")] - pub(crate) request_idle_per_host: u16, + pub request_idle_per_host: u16, #[serde(default = "default_well_known_conn_timeout")] - pub(crate) well_known_conn_timeout: u64, + pub well_known_conn_timeout: u64, #[serde(default = "default_well_known_timeout")] - pub(crate) well_known_timeout: u64, + pub well_known_timeout: u64, #[serde(default = "default_federation_timeout")] - pub(crate) federation_timeout: u64, + pub federation_timeout: u64, #[serde(default = "default_federation_idle_timeout")] - pub(crate) federation_idle_timeout: u64, + pub federation_idle_timeout: u64, #[serde(default = "default_federation_idle_per_host")] - pub(crate) federation_idle_per_host: u16, + pub federation_idle_per_host: u16, #[serde(default = "default_sender_timeout")] - pub(crate) sender_timeout: u64, + pub sender_timeout: u64, #[serde(default = "default_sender_idle_timeout")] - pub(crate) sender_idle_timeout: u64, + pub sender_idle_timeout: u64, #[serde(default = "default_sender_retry_backoff_limit")] - pub(crate) sender_retry_backoff_limit: u64, + pub sender_retry_backoff_limit: u64, #[serde(default = "default_appservice_timeout")] - pub(crate) appservice_timeout: u64, + pub appservice_timeout: u64, #[serde(default = "default_appservice_idle_timeout")] - pub(crate) appservice_idle_timeout: u64, + pub appservice_idle_timeout: u64, #[serde(default = "default_pusher_idle_timeout")] - pub(crate) pusher_idle_timeout: u64, + pub pusher_idle_timeout: u64, #[serde(default)] - pub(crate) allow_registration: bool, + pub allow_registration: bool, #[serde(default)] - pub(crate) yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse: bool, - pub(crate) registration_token: Option, + pub yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse: bool, + pub registration_token: Option, #[serde(default = "true_fn")] - pub(crate) allow_encryption: bool, + pub allow_encryption: bool, #[serde(default = "true_fn")] - pub(crate) allow_federation: bool, + pub allow_federation: bool, #[serde(default)] - pub(crate) allow_public_room_directory_over_federation: bool, + pub allow_public_room_directory_over_federation: bool, #[serde(default)] - pub(crate) allow_public_room_directory_without_auth: bool, + pub allow_public_room_directory_without_auth: bool, #[serde(default)] - pub(crate) lockdown_public_room_directory: bool, + pub lockdown_public_room_directory: bool, #[serde(default)] - pub(crate) allow_device_name_federation: bool, + pub allow_device_name_federation: bool, #[serde(default = "true_fn")] - pub(crate) allow_profile_lookup_federation_requests: bool, + pub allow_profile_lookup_federation_requests: bool, #[serde(default = "true_fn")] - pub(crate) allow_room_creation: bool, + pub allow_room_creation: bool, #[serde(default = "true_fn")] - pub(crate) allow_unstable_room_versions: bool, + pub allow_unstable_room_versions: bool, #[serde(default = "default_default_room_version")] - pub(crate) default_room_version: RoomVersionId, + pub default_room_version: RoomVersionId, #[serde(default)] - pub(crate) well_known: WellKnownConfig, + pub well_known: WellKnownConfig, #[serde(default)] #[cfg(feature = "perf_measurements")] - pub(crate) allow_jaeger: bool, + pub allow_jaeger: bool, #[serde(default)] #[cfg(feature = "perf_measurements")] - pub(crate) tracing_flame: bool, + pub tracing_flame: bool, #[serde(default = "default_tracing_flame_filter")] #[cfg(feature = "perf_measurements")] - pub(crate) tracing_flame_filter: String, + pub tracing_flame_filter: String, #[serde(default = "default_tracing_flame_output_path")] #[cfg(feature = "perf_measurements")] - pub(crate) tracing_flame_output_path: String, + pub tracing_flame_output_path: String, #[serde(default)] - pub(crate) proxy: ProxyConfig, - pub(crate) jwt_secret: Option, + pub proxy: ProxyConfig, + pub jwt_secret: Option, #[serde(default = "default_trusted_servers")] - pub(crate) trusted_servers: Vec, + pub trusted_servers: Vec, #[serde(default = "true_fn")] - pub(crate) query_trusted_key_servers_first: bool, + pub query_trusted_key_servers_first: bool, #[serde(default = "default_log")] - pub(crate) log: String, + pub log: String, #[serde(default)] - pub(crate) turn_username: String, + pub turn_username: String, #[serde(default)] - pub(crate) turn_password: String, + pub turn_password: String, #[serde(default = "Vec::new")] - pub(crate) turn_uris: Vec, + pub turn_uris: Vec, #[serde(default)] - pub(crate) turn_secret: String, + pub turn_secret: String, #[serde(default = "default_turn_ttl")] - pub(crate) turn_ttl: u64, + pub turn_ttl: u64, #[serde(default = "Vec::new")] - pub(crate) auto_join_rooms: Vec, + pub auto_join_rooms: Vec, #[serde(default)] - pub(crate) auto_deactivate_banned_room_attempts: bool, + pub auto_deactivate_banned_room_attempts: bool, #[serde(default = "default_rocksdb_log_level")] - pub(crate) rocksdb_log_level: String, + pub rocksdb_log_level: String, #[serde(default)] - pub(crate) rocksdb_log_stderr: bool, + pub rocksdb_log_stderr: bool, #[serde(default = "default_rocksdb_max_log_file_size")] - pub(crate) rocksdb_max_log_file_size: usize, + pub rocksdb_max_log_file_size: usize, #[serde(default = "default_rocksdb_log_time_to_roll")] - pub(crate) rocksdb_log_time_to_roll: usize, + pub rocksdb_log_time_to_roll: usize, #[serde(default)] - pub(crate) rocksdb_optimize_for_spinning_disks: bool, + pub rocksdb_optimize_for_spinning_disks: bool, #[serde(default = "true_fn")] - pub(crate) rocksdb_direct_io: bool, + pub rocksdb_direct_io: bool, #[serde(default = "default_rocksdb_parallelism_threads")] - pub(crate) rocksdb_parallelism_threads: usize, + pub rocksdb_parallelism_threads: usize, #[serde(default = "default_rocksdb_max_log_files")] - pub(crate) rocksdb_max_log_files: usize, + pub rocksdb_max_log_files: usize, #[serde(default = "default_rocksdb_compression_algo")] - pub(crate) rocksdb_compression_algo: String, + pub rocksdb_compression_algo: String, #[serde(default = "default_rocksdb_compression_level")] - pub(crate) rocksdb_compression_level: i32, + pub rocksdb_compression_level: i32, #[serde(default = "default_rocksdb_bottommost_compression_level")] - pub(crate) rocksdb_bottommost_compression_level: i32, + pub rocksdb_bottommost_compression_level: i32, #[serde(default)] - pub(crate) rocksdb_bottommost_compression: bool, + pub rocksdb_bottommost_compression: bool, #[serde(default = "default_rocksdb_recovery_mode")] - pub(crate) rocksdb_recovery_mode: u8, + pub rocksdb_recovery_mode: u8, #[serde(default)] - pub(crate) rocksdb_repair: bool, + pub rocksdb_repair: bool, #[serde(default)] - pub(crate) rocksdb_read_only: bool, + pub rocksdb_read_only: bool, #[serde(default)] - pub(crate) rocksdb_periodic_cleanup: bool, + pub rocksdb_periodic_cleanup: bool, #[serde(default)] - pub(crate) rocksdb_compaction_prio_idle: bool, + pub rocksdb_compaction_prio_idle: bool, #[serde(default = "true_fn")] - pub(crate) rocksdb_compaction_ioprio_idle: bool, + pub rocksdb_compaction_ioprio_idle: bool, - pub(crate) emergency_password: Option, + pub emergency_password: Option, #[serde(default = "default_notification_push_path")] - pub(crate) notification_push_path: String, + pub notification_push_path: String, #[serde(default = "true_fn")] - pub(crate) allow_local_presence: bool, + pub allow_local_presence: bool, #[serde(default = "true_fn")] - pub(crate) allow_incoming_presence: bool, + pub allow_incoming_presence: bool, #[serde(default = "true_fn")] - pub(crate) allow_outgoing_presence: bool, + pub allow_outgoing_presence: bool, #[serde(default = "default_presence_idle_timeout_s")] - pub(crate) presence_idle_timeout_s: u64, + pub presence_idle_timeout_s: u64, #[serde(default = "default_presence_offline_timeout_s")] - pub(crate) presence_offline_timeout_s: u64, + pub presence_offline_timeout_s: u64, #[serde(default = "true_fn")] - pub(crate) presence_timeout_remote_users: bool, + pub presence_timeout_remote_users: bool, #[serde(default = "true_fn")] - pub(crate) allow_incoming_read_receipts: bool, + pub allow_incoming_read_receipts: bool, #[serde(default = "true_fn")] - pub(crate) allow_outgoing_read_receipts: bool, + pub allow_outgoing_read_receipts: bool, #[serde(default = "true_fn")] - pub(crate) allow_outgoing_typing: bool, + pub allow_outgoing_typing: bool, #[serde(default = "true_fn")] - pub(crate) allow_incoming_typing: bool, + pub allow_incoming_typing: bool, #[serde(default = "default_typing_federation_timeout_s")] - pub(crate) typing_federation_timeout_s: u64, + pub typing_federation_timeout_s: u64, #[serde(default = "default_typing_client_timeout_min_s")] - pub(crate) typing_client_timeout_min_s: u64, + pub typing_client_timeout_min_s: u64, #[serde(default = "default_typing_client_timeout_max_s")] - pub(crate) typing_client_timeout_max_s: u64, + pub typing_client_timeout_max_s: u64, #[serde(default)] - pub(crate) zstd_compression: bool, + pub zstd_compression: bool, #[serde(default)] - pub(crate) gzip_compression: bool, + pub gzip_compression: bool, #[serde(default)] - pub(crate) brotli_compression: bool, + pub brotli_compression: bool, #[serde(default)] - pub(crate) allow_guest_registration: bool, + pub allow_guest_registration: bool, #[serde(default)] - pub(crate) log_guest_registrations: bool, + pub log_guest_registrations: bool, #[serde(default)] - pub(crate) allow_guests_auto_join_rooms: bool, + pub allow_guests_auto_join_rooms: bool, #[serde(default = "Vec::new")] - pub(crate) prevent_media_downloads_from: Vec, + pub prevent_media_downloads_from: Vec, #[serde(default = "Vec::new")] - pub(crate) forbidden_remote_server_names: Vec, + pub forbidden_remote_server_names: Vec, #[serde(default = "Vec::new")] - pub(crate) forbidden_remote_room_directory_server_names: Vec, + pub forbidden_remote_room_directory_server_names: Vec, #[serde(default = "default_ip_range_denylist")] - pub(crate) ip_range_denylist: Vec, + pub ip_range_denylist: Vec, #[serde(default = "Vec::new")] - pub(crate) url_preview_domain_contains_allowlist: Vec, + pub url_preview_domain_contains_allowlist: Vec, #[serde(default = "Vec::new")] - pub(crate) url_preview_domain_explicit_allowlist: Vec, + pub url_preview_domain_explicit_allowlist: Vec, #[serde(default = "Vec::new")] - pub(crate) url_preview_domain_explicit_denylist: Vec, + pub url_preview_domain_explicit_denylist: Vec, #[serde(default = "Vec::new")] - pub(crate) url_preview_url_contains_allowlist: Vec, + pub url_preview_url_contains_allowlist: Vec, #[serde(default = "default_url_preview_max_spider_size")] - pub(crate) url_preview_max_spider_size: usize, + pub url_preview_max_spider_size: usize, #[serde(default)] - pub(crate) url_preview_check_root_domain: bool, + pub url_preview_check_root_domain: bool, #[serde(default = "RegexSet::empty")] #[serde(with = "serde_regex")] - pub(crate) forbidden_alias_names: RegexSet, + pub forbidden_alias_names: RegexSet, #[serde(default = "RegexSet::empty")] #[serde(with = "serde_regex")] - pub(crate) forbidden_usernames: RegexSet, + pub forbidden_usernames: RegexSet, #[serde(default = "true_fn")] - pub(crate) startup_netburst: bool, + pub startup_netburst: bool, #[serde(default = "default_startup_netburst_keep")] - pub(crate) startup_netburst_keep: i64, + pub startup_netburst_keep: i64, #[serde(default)] - pub(crate) block_non_admin_invites: bool, + pub block_non_admin_invites: bool, #[serde(default)] - pub(crate) sentry: bool, + pub sentry: bool, #[serde(default = "default_sentry_endpoint")] - pub(crate) sentry_endpoint: Option, + pub sentry_endpoint: Option, #[serde(default)] - pub(crate) sentry_send_server_name: bool, + pub sentry_send_server_name: bool, #[serde(default = "default_sentry_traces_sample_rate")] - pub(crate) sentry_traces_sample_rate: f32, + pub sentry_traces_sample_rate: f32, #[serde(flatten)] #[allow(clippy::zero_sized_map_values)] // this is a catchall, the map shouldn't be zero at runtime @@ -349,24 +350,24 @@ pub(crate) struct Config { } #[derive(Clone, Debug, Deserialize)] -pub(crate) struct TlsConfig { - pub(crate) certs: String, - pub(crate) key: String, +pub struct TlsConfig { + pub certs: String, + pub key: String, #[serde(default)] /// Whether to listen and allow for HTTP and HTTPS connections (insecure!) /// Only works / does something if the `axum_dual_protocol` feature flag was /// built - pub(crate) dual_protocol: bool, + pub dual_protocol: bool, } #[derive(Clone, Debug, Deserialize, Default)] -pub(crate) struct WellKnownConfig { - pub(crate) client: Option, - pub(crate) server: Option, - pub(crate) support_page: Option, - pub(crate) support_role: Option, - pub(crate) support_email: Option, - pub(crate) support_mxid: Option, +pub struct WellKnownConfig { + pub client: Option, + pub server: Option, + pub support_page: Option, + pub support_role: Option, + pub support_email: Option, + pub support_mxid: Option, } const DEPRECATED_KEYS: &[&str] = &[ @@ -382,7 +383,7 @@ const DEPRECATED_KEYS: &[&str] = &[ impl Config { /// Initialize config - pub(crate) fn new(path: Option) -> Result { + pub fn new(path: Option) -> Result { let raw_config = if let Some(config_file_env) = Env::var("CONDUIT_CONFIG") { Figment::new() .merge(Toml::file(config_file_env).nested()) @@ -469,7 +470,7 @@ impl Config { } #[must_use] - pub(crate) fn get_bind_addrs(&self) -> Vec { + pub fn get_bind_addrs(&self) -> Vec { match &self.port.ports { Left(port) => { // Left is only 1 value, so make a vec with 1 value only @@ -489,7 +490,7 @@ impl Config { } } - pub(crate) fn check(&self) -> Result<(), Error> { check(self) } + pub fn check(&self) -> Result<(), Error> { check(self) } } impl fmt::Display for Config { @@ -1027,7 +1028,8 @@ fn default_rocksdb_compression_level() -> i32 { 32767 } fn default_rocksdb_bottommost_compression_level() -> i32 { 32767 } // I know, it's a great name -pub(crate) fn default_default_room_version() -> RoomVersionId { RoomVersionId::V10 } +#[must_use] +pub fn default_default_room_version() -> RoomVersionId { RoomVersionId::V10 } fn default_ip_range_denylist() -> Vec { vec![ diff --git a/src/config/proxy.rs b/src/core/config/proxy.rs similarity index 95% rename from src/config/proxy.rs rename to src/core/config/proxy.rs index 691c3394..f41a92f6 100644 --- a/src/config/proxy.rs +++ b/src/core/config/proxy.rs @@ -30,7 +30,7 @@ use crate::Result; /// `ordinary.onion`, `matrix.myspecial.onion`, but not `hello.myspecial.onion`. #[derive(Clone, Default, Debug, Deserialize)] #[serde(rename_all = "snake_case")] -pub(crate) enum ProxyConfig { +pub enum ProxyConfig { #[default] None, Global { @@ -40,7 +40,7 @@ pub(crate) enum ProxyConfig { ByDomain(Vec), } impl ProxyConfig { - pub(crate) fn to_proxy(&self) -> Result> { + pub fn to_proxy(&self) -> Result> { Ok(match self.clone() { ProxyConfig::None => None, ProxyConfig::Global { @@ -55,7 +55,7 @@ impl ProxyConfig { } #[derive(Clone, Debug, Deserialize)] -pub(crate) struct PartialProxyConfig { +pub struct PartialProxyConfig { #[serde(deserialize_with = "crate::utils::deserialize_from_str")] url: Url, #[serde(default)] @@ -64,7 +64,8 @@ pub(crate) struct PartialProxyConfig { exclude: Vec, } impl PartialProxyConfig { - pub(crate) fn for_url(&self, url: &Url) -> Option<&Url> { + #[must_use] + pub fn for_url(&self, url: &Url) -> Option<&Url> { let domain = url.domain()?; let mut included_because = None; // most specific reason it was included let mut excluded_because = None; // most specific reason it was excluded diff --git a/src/utils/debug.rs b/src/core/debug.rs similarity index 66% rename from src/utils/debug.rs rename to src/core/debug.rs index 3974ae67..fa998265 100644 --- a/src/utils/debug.rs +++ b/src/core/debug.rs @@ -1,3 +1,7 @@ +#![allow(dead_code)] // this is a developer's toolbox + +use std::{panic, panic::PanicInfo}; + /// Log event at given level in debug-mode (when debug-assertions are enabled). /// In release-mode it becomes DEBUG level, and possibly subject to elision. /// @@ -43,3 +47,32 @@ macro_rules! debug_info { $crate::debug_event!(tracing::Level::INFO, $($x)+ ); } } + +pub fn set_panic_trap() { + let next = panic::take_hook(); + panic::set_hook(Box::new(move |info| { + panic_handler(info, &next); + })); +} + +#[inline(always)] +fn panic_handler(info: &PanicInfo<'_>, next: &dyn Fn(&PanicInfo<'_>)) { + trap(); + next(info); +} + +#[inline(always)] +#[allow(unexpected_cfgs)] +pub fn trap() { + #[cfg(core_intrinsics)] + //SAFETY: embeds llvm intrinsic for hardware breakpoint + unsafe { + std::intrinsics::breakpoint(); + } + + #[cfg(all(not(core_intrinsics), target_arch = "x86_64"))] + //SAFETY: embeds instruction for hardware breakpoint + unsafe { + std::arch::asm!("int3"); + } +} diff --git a/src/utils/error.rs b/src/core/error.rs similarity index 78% rename from src/utils/error.rs rename to src/core/error.rs index 04ed6bf3..5a671da4 100644 --- a/src/utils/error.rs +++ b/src/core/error.rs @@ -1,10 +1,16 @@ use std::{convert::Infallible, fmt}; +use axum::response::{IntoResponse, Response}; +use bytes::BytesMut; use http::StatusCode; +use http_body_util::Full; use ruma::{ - api::client::{ - error::{Error as RumaError, ErrorBody, ErrorKind}, - uiaa::{UiaaInfo, UiaaResponse}, + api::{ + client::{ + error::{Error as RumaError, ErrorBody, ErrorKind}, + uiaa::{UiaaInfo, UiaaResponse}, + }, + OutgoingResponse, }, OwnedServerName, }; @@ -15,12 +21,10 @@ use ErrorKind::{ TooLarge, Unauthorized, Unknown, UnknownToken, Unrecognized, UserDeactivated, WrongRoomKeysVersion, }; -use crate::RumaResponse; - -pub(crate) type Result = std::result::Result; +pub type Result = std::result::Result; #[derive(Error)] -pub(crate) enum Error { +pub enum Error { #[cfg(feature = "sqlite")] #[error("There was a problem with the connection to the sqlite database: {source}")] Sqlite { @@ -83,17 +87,70 @@ pub(crate) enum Error { } impl Error { - pub(crate) fn bad_database(message: &'static str) -> Self { + pub fn bad_database(message: &'static str) -> Self { error!("BadDatabase: {}", message); Self::BadDatabase(message) } - pub(crate) fn bad_config(message: &str) -> Self { + pub fn bad_config(message: &str) -> Self { error!("BadConfig: {}", message); Self::BadConfig(message.to_owned()) } - pub(crate) fn to_response(&self) -> RumaResponse { + /// Returns the Matrix error code / error kind + pub fn error_code(&self) -> ErrorKind { + if let Self::Federation(_, error) = self { + return error.error_kind().unwrap_or_else(|| &Unknown).clone(); + } + + match self { + Self::BadRequest(kind, _) => kind.clone(), + _ => Unknown, + } + } + + /// Sanitizes public-facing errors that can leak sensitive information. + pub fn sanitized_error(&self) -> String { + let db_error = String::from("Database or I/O error occurred."); + + match self { + #[cfg(feature = "sqlite")] + Self::Sqlite { + .. + } => db_error, + #[cfg(feature = "rocksdb")] + Self::RocksDb { + .. + } => db_error, + Self::Io { + .. + } => db_error, + _ => self.to_string(), + } + } +} + +impl From for Error { + fn from(i: Infallible) -> Self { match i {} } +} + +impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self) } +} + +#[derive(Clone)] +pub struct RumaResponse(pub T); + +impl From for RumaResponse { + fn from(t: T) -> Self { Self(t) } +} + +impl From for RumaResponse { + fn from(t: Error) -> Self { t.to_response() } +} + +impl Error { + pub fn to_response(&self) -> RumaResponse { if let Self::Uiaa(uiaainfo) = self { return RumaResponse(UiaaResponse::AuthResponse(uiaainfo.clone())); } @@ -147,48 +204,17 @@ impl Error { status_code, })) } +} - /// Returns the Matrix error code / error kind - pub(crate) fn error_code(&self) -> ErrorKind { - if let Self::Federation(_, error) = self { - return error.error_kind().unwrap_or_else(|| &Unknown).clone(); - } +impl ::axum::response::IntoResponse for Error { + fn into_response(self) -> ::axum::response::Response { self.to_response().into_response() } +} - match self { - Self::BadRequest(kind, _) => kind.clone(), - _ => Unknown, - } - } - - /// Sanitizes public-facing errors that can leak sensitive information. - pub(crate) fn sanitized_error(&self) -> String { - let db_error = String::from("Database or I/O error occurred."); - - match self { - #[cfg(feature = "sqlite")] - Self::Sqlite { - .. - } => db_error, - #[cfg(feature = "rocksdb")] - Self::RocksDb { - .. - } => db_error, - Self::Io { - .. - } => db_error, - _ => self.to_string(), +impl IntoResponse for RumaResponse { + fn into_response(self) -> Response { + match self.0.try_into_http_response::() { + Ok(res) => res.map(BytesMut::freeze).map(Full::new).into_response(), + Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), } } } - -impl From for Error { - fn from(i: Infallible) -> Self { match i {} } -} - -impl axum::response::IntoResponse for Error { - fn into_response(self) -> axum::response::Response { self.to_response().into_response() } -} - -impl fmt::Debug for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self) } -} diff --git a/src/core/log.rs b/src/core/log.rs new file mode 100644 index 00000000..d31ca194 --- /dev/null +++ b/src/core/log.rs @@ -0,0 +1,79 @@ +use std::sync::Arc; + +use tracing_subscriber::{reload, EnvFilter}; + +/// We need to store a reload::Handle value, but can't name it's type explicitly +/// because the S type parameter depends on the subscriber's previous layers. In +/// our case, this includes unnameable 'impl Trait' types. +/// +/// This is fixed[1] in the unreleased tracing-subscriber from the master +/// branch, which removes the S parameter. Unfortunately can't use it without +/// pulling in a version of tracing that's incompatible with the rest of our +/// deps. +/// +/// To work around this, we define an trait without the S paramter that forwards +/// to the reload::Handle::reload method, and then store the handle as a trait +/// object. +/// +/// [1]: +pub trait ReloadHandle { + fn reload(&self, new_value: L) -> Result<(), reload::Error>; +} + +impl ReloadHandle for reload::Handle { + fn reload(&self, new_value: L) -> Result<(), reload::Error> { reload::Handle::reload(self, new_value) } +} + +struct LogLevelReloadHandlesInner { + handles: Vec + Send + Sync>>, +} + +/// Wrapper to allow reloading the filter on several several +/// [`tracing_subscriber::reload::Handle`]s at once, with the same value. +#[derive(Clone)] +pub struct LogLevelReloadHandles { + inner: Arc, +} + +impl LogLevelReloadHandles { + #[must_use] + pub fn new(handles: Vec + Send + Sync>>) -> LogLevelReloadHandles { + LogLevelReloadHandles { + inner: Arc::new(LogLevelReloadHandlesInner { + handles, + }), + } + } + + pub fn reload(&self, new_value: &EnvFilter) -> Result<(), reload::Error> { + for handle in &self.inner.handles { + handle.reload(new_value.clone())?; + } + Ok(()) + } +} + +#[macro_export] +macro_rules! error { + ( $($x:tt)+ ) => { tracing::error!( $($x)+ ); } +} + +#[macro_export] +macro_rules! warn { + ( $($x:tt)+ ) => { tracing::warn!( $($x)+ ); } +} + +#[macro_export] +macro_rules! info { + ( $($x:tt)+ ) => { tracing::info!( $($x)+ ); } +} + +#[macro_export] +macro_rules! debug { + ( $($x:tt)+ ) => { tracing::debug!( $($x)+ ); } +} + +#[macro_export] +macro_rules! trace { + ( $($x:tt)+ ) => { tracing::trace!( $($x)+ ); } +} diff --git a/src/core/mod.rs b/src/core/mod.rs new file mode 100644 index 00000000..8e0a481b --- /dev/null +++ b/src/core/mod.rs @@ -0,0 +1,27 @@ +pub mod alloc; +pub mod config; +pub mod debug; +pub mod error; +pub mod log; +pub mod mods; +pub mod pducount; +pub mod server; +pub mod utils; + +pub use config::Config; +pub use error::{Error, Result, RumaResponse}; +pub use pducount::PduCount; +pub use server::Server; +pub use utils::conduwuit_version; + +#[cfg(not(feature = "mods"))] +mod mods { + #[macro_export] + macro_rules! mod_ctor { + () => {}; + } + #[macro_export] + macro_rules! mod_dtor { + () => {}; + } +} diff --git a/src/core/mods/canary.rs b/src/core/mods/canary.rs new file mode 100644 index 00000000..6095608c --- /dev/null +++ b/src/core/mods/canary.rs @@ -0,0 +1,28 @@ +use std::sync::atomic::{AtomicI32, Ordering}; + +const ORDERING: Ordering = Ordering::Relaxed; +static STATIC_DTORS: AtomicI32 = AtomicI32::new(0); + +/// Called by Module::unload() to indicate module is about to be unloaded and +/// static destruction is intended. This will allow verifying it actually took +/// place. +pub(crate) fn prepare() { + let count = STATIC_DTORS.fetch_sub(1, ORDERING); + debug_assert!(count <= 0, "STATIC_DTORS should not be greater than zero."); +} + +/// Called by static destructor of a module. This call should only be found +/// inside a mod_fini! macro. Do not call from anywhere else. +#[inline(always)] +pub fn report() { let _count = STATIC_DTORS.fetch_add(1, ORDERING); } + +/// Called by Module::unload() (see check()) with action in case a check() +/// failed. This can allow a stuck module to be noted while allowing for other +/// independent modules to be diagnosed. +pub(crate) fn check_and_reset() -> bool { STATIC_DTORS.swap(0, ORDERING) == 0 } + +/// Called by Module::unload() after unload to verify static destruction took +/// place. A call to prepare() must be made prior to Module::unload() and making +/// this call. +#[allow(dead_code)] +pub(crate) fn check() -> bool { STATIC_DTORS.load(ORDERING) == 0 } diff --git a/src/core/mods/macros.rs b/src/core/mods/macros.rs new file mode 100644 index 00000000..aa0999c9 --- /dev/null +++ b/src/core/mods/macros.rs @@ -0,0 +1,44 @@ +#[macro_export] +macro_rules! mod_ctor { + ( $($body:block)? ) => { + $crate::mod_init! {{ + $crate::debug_info!("Module loaded"); + $($body)? + }} + } +} + +#[macro_export] +macro_rules! mod_dtor { + ( $($body:block)? ) => { + $crate::mod_fini! {{ + $crate::debug_info!("Module unloading"); + $($body)? + $crate::mods::canary::report(); + }} + } +} + +#[macro_export] +macro_rules! mod_init { + ($body:block) => { + #[used] + #[cfg_attr(target_family = "unix", link_section = ".init_array")] + static MOD_INIT: extern "C" fn() = { _mod_init }; + + #[cfg_attr(target_family = "unix", link_section = ".text.startup")] + extern "C" fn _mod_init() -> () $body + }; +} + +#[macro_export] +macro_rules! mod_fini { + ($body:block) => { + #[used] + #[cfg_attr(target_family = "unix", link_section = ".fini_array")] + static MOD_FINI: extern "C" fn() = { _mod_fini }; + + #[cfg_attr(target_family = "unix", link_section = ".text.startup")] + extern "C" fn _mod_fini() -> () $body + }; +} diff --git a/src/core/mods/mod.rs b/src/core/mods/mod.rs new file mode 100644 index 00000000..e60a0f5e --- /dev/null +++ b/src/core/mods/mod.rs @@ -0,0 +1,11 @@ +#![cfg(feature = "mods")] + +pub(crate) use libloading::os::unix::{Library, Symbol}; + +pub mod canary; +pub mod macros; +pub mod module; +pub mod new; +pub mod path; + +pub use module::Module; diff --git a/src/core/mods/module.rs b/src/core/mods/module.rs new file mode 100644 index 00000000..ff181e4f --- /dev/null +++ b/src/core/mods/module.rs @@ -0,0 +1,74 @@ +use std::{ + ffi::{CString, OsString}, + time::SystemTime, +}; + +use super::{canary, new, path, Library, Symbol}; +use crate::{error, Result}; + +pub struct Module { + handle: Option, + loaded: SystemTime, + path: OsString, +} + +impl Module { + pub fn from_name(name: &str) -> Result { Self::from_path(path::from_name(name)?) } + + pub fn from_path(path: OsString) -> Result { + Ok(Self { + handle: Some(new::from_path(&path)?), + loaded: SystemTime::now(), + path, + }) + } + + pub fn unload(&mut self) { + canary::prepare(); + self.close(); + if !canary::check_and_reset() { + let name = self.name().expect("Module is named"); + error!("Module {name:?} is stuck and failed to unload."); + } + } + + pub(crate) fn close(&mut self) { + if let Some(handle) = self.handle.take() { + handle.close().expect("Module handle closed"); + } + } + + pub fn get(&self, name: &str) -> Result> { + let cname = CString::new(name.to_owned()).expect("terminated string from provided name"); + let handle = self + .handle + .as_ref() + .expect("backing library loaded by this instance"); + // SAFETY: Calls dlsym(3) on unix platforms. This might not have to be unsafe + // if wrapped in libloading with_dlerror(). + let sym = unsafe { handle.get::(cname.as_bytes()) }; + let sym = sym.expect("symbol found; binding successful"); + + Ok(sym) + } + + pub fn deleted(&self) -> Result { + let mtime = path::mtime(self.path())?; + let res = mtime > self.loaded; + + Ok(res) + } + + pub fn name(&self) -> Result { path::to_name(self.path()) } + + #[must_use] + pub fn path(&self) -> &OsString { &self.path } +} + +impl Drop for Module { + fn drop(&mut self) { + if self.handle.is_some() { + self.unload(); + } + } +} diff --git a/src/core/mods/new.rs b/src/core/mods/new.rs new file mode 100644 index 00000000..99d7756a --- /dev/null +++ b/src/core/mods/new.rs @@ -0,0 +1,23 @@ +use std::ffi::OsStr; + +use super::{path, Library}; +use crate::{Error, Result}; + +const OPEN_FLAGS: i32 = libloading::os::unix::RTLD_LAZY | libloading::os::unix::RTLD_GLOBAL; + +pub fn from_name(name: &str) -> Result { + let path = path::from_name(name)?; + from_path(&path) +} + +pub fn from_path(path: &OsStr) -> Result { + //SAFETY: Calls dlopen(3) on unix platforms. This might not have to be unsafe + // if wrapped in with_dlerror. + let lib = unsafe { Library::open(Some(path), OPEN_FLAGS) }; + if let Err(e) = lib { + let name = path::to_name(path)?; + return Err(Error::Err(format!("Loading module {name:?} failed: {e}"))); + } + + Ok(lib.expect("module loaded")) +} diff --git a/src/core/mods/path.rs b/src/core/mods/path.rs new file mode 100644 index 00000000..cde251b3 --- /dev/null +++ b/src/core/mods/path.rs @@ -0,0 +1,40 @@ +use std::{ + env::current_exe, + ffi::{OsStr, OsString}, + path::{Path, PathBuf}, + time::SystemTime, +}; + +use libloading::library_filename; + +use crate::Result; + +pub fn from_name(name: &str) -> Result { + let root = PathBuf::new(); + let exe_path = current_exe()?; + let exe_dir = exe_path.parent().unwrap_or(&root); + let mut mod_path = exe_dir.to_path_buf(); + let mod_file = library_filename(name); + mod_path.push(mod_file); + + Ok(mod_path.into_os_string()) +} + +pub fn to_name(path: &OsStr) -> Result { + let path = Path::new(path); + let name = path + .file_stem() + .expect("path file stem") + .to_str() + .expect("name string"); + let name = name.strip_prefix("lib").unwrap_or(name).to_owned(); + + Ok(name) +} + +pub fn mtime(path: &OsStr) -> Result { + let meta = std::fs::metadata(path)?; + let mtime = meta.modified()?; + + Ok(mtime) +} diff --git a/src/core/pducount.rs b/src/core/pducount.rs new file mode 100644 index 00000000..8adb4ca5 --- /dev/null +++ b/src/core/pducount.rs @@ -0,0 +1,51 @@ +use std::cmp::Ordering; + +use ruma::api::client::error::ErrorKind; + +use crate::{Error, Result}; + +#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)] +pub enum PduCount { + Backfilled(u64), + Normal(u64), +} + +impl PduCount { + #[must_use] + pub fn min() -> Self { Self::Backfilled(u64::MAX) } + + #[must_use] + pub fn max() -> Self { Self::Normal(u64::MAX) } + + pub fn try_from_string(token: &str) -> Result { + if let Some(stripped_token) = token.strip_prefix('-') { + stripped_token.parse().map(PduCount::Backfilled) + } else { + token.parse().map(PduCount::Normal) + } + .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid pagination token.")) + } + + #[must_use] + pub fn stringify(&self) -> String { + match self { + PduCount::Backfilled(x) => format!("-{x}"), + PduCount::Normal(x) => x.to_string(), + } + } +} + +impl PartialOrd for PduCount { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } +} + +impl Ord for PduCount { + fn cmp(&self, other: &Self) -> Ordering { + match (self, other) { + (PduCount::Normal(s), PduCount::Normal(o)) => s.cmp(o), + (PduCount::Backfilled(s), PduCount::Backfilled(o)) => o.cmp(s), + (PduCount::Normal(_), PduCount::Backfilled(_)) => Ordering::Greater, + (PduCount::Backfilled(_), PduCount::Normal(_)) => Ordering::Less, + } + } +} diff --git a/src/core/server.rs b/src/core/server.rs new file mode 100644 index 00000000..4bfff340 --- /dev/null +++ b/src/core/server.rs @@ -0,0 +1,72 @@ +use std::{ + sync::{ + atomic::{AtomicBool, AtomicU32}, + Mutex, + }, + time::SystemTime, +}; + +use tokio::runtime; + +use crate::{config::Config, log::LogLevelReloadHandles}; + +/// Server runtime state; public portion +pub struct Server { + /// Server-wide configuration instance + pub config: Config, + + /// Timestamp server was started; used for uptime. + pub started: SystemTime, + + /// Reload/shutdown signal channel. Called from the signal handler or admin + /// command to initiate shutdown. + pub shutdown: Mutex>, + + /// Reload/shutdown desired indicator; when false, shutdown is desired. This + /// is an observable used on shutdown and modifying is not recommended. + pub reload: AtomicBool, + + /// Reload/shutdown pending indicator; server is shutting down. This is an + /// observable used on shutdown and should not be modified. + pub interrupt: AtomicBool, + + /// Handle to the runtime + pub runtime: Option, + + /// Log level reload handles. + pub tracing_reload_handle: LogLevelReloadHandles, + + /// TODO: move stats + pub requests_spawn_active: AtomicU32, + pub requests_spawn_finished: AtomicU32, + pub requests_handle_active: AtomicU32, + pub requests_handle_finished: AtomicU32, + pub requests_panic: AtomicU32, +} + +impl Server { + #[must_use] + pub fn new(config: Config, runtime: Option, tracing_reload_handle: LogLevelReloadHandles) -> Self { + Self { + config, + started: SystemTime::now(), + shutdown: Mutex::new(None), + reload: AtomicBool::new(false), + interrupt: AtomicBool::new(false), + runtime, + tracing_reload_handle, + requests_spawn_active: AtomicU32::new(0), + requests_spawn_finished: AtomicU32::new(0), + requests_handle_active: AtomicU32::new(0), + requests_handle_finished: AtomicU32::new(0), + requests_panic: AtomicU32::new(0), + } + } + + #[inline] + pub fn runtime(&self) -> &runtime::Handle { + self.runtime + .as_ref() + .expect("runtime handle available in Server") + } +} diff --git a/src/utils/clap.rs b/src/core/utils/clap.rs similarity index 73% rename from src/utils/clap.rs rename to src/core/utils/clap.rs index 4c88d836..c1dcb586 100644 --- a/src/utils/clap.rs +++ b/src/core/utils/clap.rs @@ -2,19 +2,19 @@ use std::path::PathBuf; -use clap::Parser; +pub use clap::Parser; use super::conduwuit_version; /// Commandline arguments #[derive(Parser, Debug)] #[clap(version = conduwuit_version(), about, long_about = None)] -pub(crate) struct Args { +pub struct Args { #[arg(short, long)] /// Optional argument to the path of a conduwuit config TOML file - pub(crate) config: Option, + pub config: Option, } /// Parse commandline arguments into structured data #[must_use] -pub(crate) fn parse() -> Args { Args::parse() } +pub fn parse() -> Args { Args::parse() } diff --git a/src/utils/content_disposition.rs b/src/core/utils/content_disposition.rs similarity index 93% rename from src/utils/content_disposition.rs rename to src/core/utils/content_disposition.rs index 9ef93bbf..85828be7 100644 --- a/src/utils/content_disposition.rs +++ b/src/core/utils/content_disposition.rs @@ -17,8 +17,9 @@ const IMAGE_SVG_XML: &str = "image/svg+xml"; /// /// TODO: add a "strict" function for comparing the Content-Type with what we /// detected: `file_type.mime_type() != content_type` +#[must_use] #[tracing::instrument(skip(buf))] -pub(crate) fn content_disposition_type(buf: &[u8], content_type: &Option) -> &'static str { +pub fn content_disposition_type(buf: &[u8], content_type: &Option) -> &'static str { let Some(file_type) = infer::get(buf) else { return ATTACHMENT; }; @@ -41,8 +42,9 @@ pub(crate) fn content_disposition_type(buf: &[u8], content_type: &Option /// /// SVG is special-cased due to the MIME type being classified as `text/xml` but /// browsers need `image/svg+xml` +#[must_use] #[tracing::instrument(skip(buf))] -pub(crate) fn make_content_type(buf: &[u8], content_type: &Option) -> &'static str { +pub fn make_content_type(buf: &[u8], content_type: &Option) -> &'static str { let Some(file_type) = infer::get(buf) else { debug_info!("Failed to infer the file's contents"); return APPLICATION_OCTET_STREAM; @@ -62,7 +64,7 @@ pub(crate) fn make_content_type(buf: &[u8], content_type: &Option) -> &' /// sanitises the file name for the Content-Disposition using /// `sanitize_filename` crate #[tracing::instrument] -pub(crate) fn sanitise_filename(filename: String) -> String { +pub fn sanitise_filename(filename: String) -> String { let options = sanitize_filename::Options { truncate: false, ..Default::default() @@ -79,7 +81,7 @@ pub(crate) fn sanitise_filename(filename: String) -> String { /// /// else: `Content-Disposition: attachment/inline` #[tracing::instrument(skip(file))] -pub(crate) fn make_content_disposition( +pub fn make_content_disposition( file: &[u8], content_type: &Option, content_disposition: Option, ) -> String { let filename = content_disposition.map_or_else(String::new, |content_disposition| { diff --git a/src/core/utils/defer.rs b/src/core/utils/defer.rs new file mode 100644 index 00000000..2762d4fa --- /dev/null +++ b/src/core/utils/defer.rs @@ -0,0 +1,22 @@ +#[macro_export] +macro_rules! defer { + ($body:block) => { + struct _Defer_ + where + F: FnMut(), + { + closure: F, + } + + impl Drop for _Defer_ + where + F: FnMut(), + { + fn drop(&mut self) { (self.closure)(); } + } + + let _defer_ = _Defer_ { + closure: || $body, + }; + }; +} diff --git a/src/utils/mod.rs b/src/core/utils/mod.rs similarity index 72% rename from src/utils/mod.rs rename to src/core/utils/mod.rs index 2ceb0ff5..1cdb6727 100644 --- a/src/utils/mod.rs +++ b/src/core/utils/mod.rs @@ -1,10 +1,3 @@ -pub(crate) mod clap; -pub(crate) mod content_disposition; -pub(crate) mod debug; -pub(crate) mod error; -pub(crate) mod server_name; -pub(crate) mod user_id; - use std::{ cmp, cmp::Ordering, @@ -13,24 +6,29 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; -use argon2::{password_hash::SaltString, PasswordHasher}; use rand::prelude::*; use ring::digest; use ruma::{canonical_json::try_from_json_map, CanonicalJsonError, CanonicalJsonObject, OwnedUserId}; +use tracing::debug; -use crate::{services, Error, Result}; +use crate::{Error, Result}; -pub(crate) fn clamp(val: T, min: T, max: T) -> T { cmp::min(cmp::max(val, min), max) } +pub mod clap; +pub mod content_disposition; +pub mod defer; +pub fn clamp(val: T, min: T, max: T) -> T { cmp::min(cmp::max(val, min), max) } + +#[must_use] #[allow(clippy::as_conversions)] -pub(crate) fn millis_since_unix_epoch() -> u64 { +pub fn millis_since_unix_epoch() -> u64 { SystemTime::now() .duration_since(UNIX_EPOCH) .expect("time is valid") .as_millis() as u64 } -pub(crate) fn increment(old: Option<&[u8]>) -> Vec { +pub fn increment(old: Option<&[u8]>) -> Vec { let number = match old.map(TryInto::try_into) { Some(Ok(bytes)) => { let number = u64::from_be_bytes(bytes); @@ -42,7 +40,8 @@ pub(crate) fn increment(old: Option<&[u8]>) -> Vec { number.to_be_bytes().to_vec() } -pub(crate) fn generate_keypair() -> Vec { +#[must_use] +pub fn generate_keypair() -> Vec { let mut value = random_string(8).as_bytes().to_vec(); value.push(0xFF); value.extend_from_slice( @@ -52,25 +51,25 @@ pub(crate) fn generate_keypair() -> Vec { } /// Parses the bytes into an u64. -pub(crate) fn u64_from_bytes(bytes: &[u8]) -> Result { +pub fn u64_from_bytes(bytes: &[u8]) -> Result { let array: [u8; 8] = bytes.try_into()?; Ok(u64::from_be_bytes(array)) } /// Parses the bytes into a string. -pub(crate) fn string_from_bytes(bytes: &[u8]) -> Result { +pub fn string_from_bytes(bytes: &[u8]) -> Result { String::from_utf8(bytes.to_vec()) } /// Parses a `OwnedUserId` from bytes. -pub(crate) fn user_id_from_bytes(bytes: &[u8]) -> Result { +pub fn user_id_from_bytes(bytes: &[u8]) -> Result { OwnedUserId::try_from( string_from_bytes(bytes).map_err(|_| Error::bad_database("Failed to parse string from bytes"))?, ) .map_err(|_| Error::bad_database("Failed to parse user id from bytes")) } -pub(crate) fn random_string(length: usize) -> String { +pub fn random_string(length: usize) -> String { thread_rng() .sample_iter(&rand::distributions::Alphanumeric) .take(length) @@ -78,25 +77,16 @@ pub(crate) fn random_string(length: usize) -> String { .collect() } -/// Calculate a new hash for the given password -pub(crate) fn calculate_password_hash(password: &str) -> Result { - let salt = SaltString::generate(thread_rng()); - services() - .globals - .argon - .hash_password(password.as_bytes(), &salt) - .map(|it| it.to_string()) -} - #[tracing::instrument(skip(keys))] -pub(crate) fn calculate_hash(keys: &[&[u8]]) -> Vec { +pub fn calculate_hash(keys: &[&[u8]]) -> Vec { // We only hash the pdu's event ids, not the whole pdu let bytes = keys.join(&0xFF); let hash = digest::digest(&digest::SHA256, &bytes); hash.as_ref().to_owned() } -pub(crate) fn common_elements( +#[allow(clippy::impl_trait_in_params)] +pub fn common_elements( mut iterators: impl Iterator>>, check_order: impl Fn(&[u8], &[u8]) -> Ordering, ) -> Option>> { let first_iterator = iterators.next()?; @@ -123,7 +113,7 @@ pub(crate) fn common_elements( /// `CanonicalJsonObject`. /// /// `value` must serialize to an `serde_json::Value::Object`. -pub(crate) fn to_canonical_object(value: T) -> Result { +pub fn to_canonical_object(value: T) -> Result { use serde::ser::Error; match serde_json::to_value(value).map_err(CanonicalJsonError::SerDe)? { @@ -132,7 +122,7 @@ pub(crate) fn to_canonical_object(value: T) -> Result, T: FromStr, E: fmt::Display>( +pub fn deserialize_from_str<'de, D: serde::de::Deserializer<'de>, T: FromStr, E: fmt::Display>( deserializer: D, ) -> Result { struct Visitor, E>(std::marker::PhantomData); @@ -158,7 +148,7 @@ pub(crate) fn deserialize_from_str<'de, D: serde::de::Deserializer<'de>, T: From /// Wrapper struct which will emit the HTML-escaped version of the contained /// string when passed to a format string. -pub(crate) struct HtmlEscape<'a>(pub(crate) &'a str); +pub struct HtmlEscape<'a>(pub &'a str); impl fmt::Display for HtmlEscape<'_> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -196,7 +186,8 @@ impl fmt::Display for HtmlEscape<'_> { /// Set the environment variable `CONDUWUIT_VERSION_EXTRA` to any UTF-8 string /// to include it in parenthesis after the SemVer version. A common value are /// git commit hashes. -pub(crate) fn conduwuit_version() -> String { +#[must_use] +pub fn conduwuit_version() -> String { match option_env!("CONDUWUIT_VERSION_EXTRA") { Some(extra) => { if extra.is_empty() { @@ -222,7 +213,7 @@ pub(crate) fn conduwuit_version() -> String { /// Any further elements are replaced by an ellipsis. /// /// See also [`debug_slice_truncated()`], -pub(crate) struct TruncatedDebugSlice<'a, T> { +pub struct TruncatedDebugSlice<'a, T> { inner: &'a [T], max_len: usize, } @@ -243,11 +234,12 @@ impl fmt::Debug for TruncatedDebugSlice<'_, T> { /// See [`TruncatedDebugSlice`]. Useful for `#[instrument]`: /// /// ``` -/// #[tracing::instrument(fields( -/// foos = debug_slice_truncated(foos, N) -/// ))] +/// use conduit_core::utils::debug_slice_truncated; +/// +/// #[tracing::instrument(fields(foos = debug_slice_truncated(foos, 42)))] +/// fn bar(foos: &[&str]); /// ``` -pub(crate) fn debug_slice_truncated( +pub fn debug_slice_truncated( slice: &[T], max_len: usize, ) -> tracing::field::DebugValue> { tracing::field::debug(TruncatedDebugSlice { @@ -255,3 +247,24 @@ pub(crate) fn debug_slice_truncated( max_len, }) } + +/// This is needed for opening lots of file descriptors, which tends to +/// happen more often when using RocksDB and making lots of federation +/// connections at startup. The soft limit is usually 1024, and the hard +/// limit is usually 512000; I've personally seen it hit >2000. +/// +/// * +/// * +#[cfg(unix)] +pub fn maximize_fd_limit() -> Result<(), nix::errno::Errno> { + use nix::sys::resource::{getrlimit, setrlimit, Resource::RLIMIT_NOFILE as NOFILE}; + + let (soft_limit, hard_limit) = getrlimit(NOFILE)?; + if soft_limit < hard_limit { + setrlimit(NOFILE, hard_limit, hard_limit)?; + assert_eq!((hard_limit, hard_limit), getrlimit(NOFILE)?, "getrlimit != setrlimit"); + debug!(to = hard_limit, from = soft_limit, "Raised RLIMIT_NOFILE",); + } + + Ok(()) +} diff --git a/src/database/Cargo.toml b/src/database/Cargo.toml new file mode 100644 index 00000000..990a303b --- /dev/null +++ b/src/database/Cargo.toml @@ -0,0 +1,81 @@ +[package] +name = "conduit_database" +version.workspace = true +edition.workspace = true + +[lib] +path = "mod.rs" +crate-type = [ + "rlib", +# "dylib", +] + +[features] +default = [ + "rocksdb", + "io_uring", + "jemalloc", + "zstd_compression", + "release_max_log_level", +] + +dev_release_log_level = [] +release_max_log_level = [ + "tracing/max_level_trace", + "tracing/release_max_level_info", + "log/max_level_trace", + "log/release_max_level_info", +] +sqlite = [ + "dep:rusqlite", + "dep:parking_lot", + "dep:thread_local", +] +rocksdb = [ + "dep:rust-rocksdb", +] +jemalloc = [ + "dep:tikv-jemalloc-sys", + "dep:tikv-jemalloc-ctl", + "dep:tikv-jemallocator", + "rust-rocksdb/jemalloc", +] +jemalloc_prof = [ + "tikv-jemalloc-sys/profiling", +] +io_uring = [ + "rust-rocksdb/io-uring", +] +zstd_compression = [ + "rust-rocksdb/zstd", +] + +[dependencies] +chrono.workspace = true +conduit-core.workspace = true +futures-util.workspace = true +log.workspace = true +lru-cache.workspace = true +num_cpus.workspace = true +parking_lot.optional = true +parking_lot.workspace = true +ruma.workspace = true +rusqlite.optional = true +rusqlite.workspace = true +rust-rocksdb.optional = true +rust-rocksdb.workspace = true +thread_local.optional = true +thread_local.workspace = true +tikv-jemallocator.optional = true +tikv-jemallocator.workspace = true +tikv-jemalloc-ctl.optional = true +tikv-jemalloc-ctl.workspace = true +tikv-jemalloc-sys.optional = true +tikv-jemalloc-sys.workspace = true +tokio.workspace = true +tracing.workspace = true +zstd.optional = true +zstd.workspace = true + +[lints] +workspace = true diff --git a/src/database/cork.rs b/src/database/cork.rs index db7dfac2..752260a6 100644 --- a/src/database/cork.rs +++ b/src/database/cork.rs @@ -2,14 +2,14 @@ use std::sync::Arc; use super::KeyValueDatabaseEngine; -pub(crate) struct Cork { +pub struct Cork { db: Arc, flush: bool, sync: bool, } impl Cork { - pub(crate) fn new(db: &Arc, flush: bool, sync: bool) -> Self { + pub fn new(db: &Arc, flush: bool, sync: bool) -> Self { db.cork().unwrap(); Cork { db: db.clone(), diff --git a/src/database/kvdatabase.rs b/src/database/kvdatabase.rs new file mode 100644 index 00000000..ddbb8e92 --- /dev/null +++ b/src/database/kvdatabase.rs @@ -0,0 +1,320 @@ +use std::{ + collections::{BTreeMap, HashMap, HashSet}, + path::Path, + sync::{Arc, Mutex, RwLock}, +}; + +use conduit::{Config, Error, PduCount, Result, Server}; +use lru_cache::LruCache; +use ruma::{CanonicalJsonValue, OwnedDeviceId, OwnedRoomId, OwnedUserId}; +use tracing::debug; + +use crate::{KeyValueDatabaseEngine, KvTree}; + +pub struct KeyValueDatabase { + pub db: Arc, + + //pub globals: globals::Globals, + pub global: Arc, + pub server_signingkeys: Arc, + + pub roomid_inviteviaservers: Arc, + + //pub users: users::Users, + pub userid_password: Arc, + pub userid_displayname: Arc, + pub userid_avatarurl: Arc, + pub userid_blurhash: Arc, + pub userdeviceid_token: Arc, + pub userdeviceid_metadata: Arc, // This is also used to check if a device exists + pub userid_devicelistversion: Arc, // DevicelistVersion = u64 + pub token_userdeviceid: Arc, + + pub onetimekeyid_onetimekeys: Arc, // OneTimeKeyId = UserId + DeviceKeyId + pub userid_lastonetimekeyupdate: Arc, // LastOneTimeKeyUpdate = Count + pub keychangeid_userid: Arc, // KeyChangeId = UserId/RoomId + Count + pub keyid_key: Arc, // KeyId = UserId + KeyId (depends on key type) + pub userid_masterkeyid: Arc, + pub userid_selfsigningkeyid: Arc, + pub userid_usersigningkeyid: Arc, + + pub userfilterid_filter: Arc, // UserFilterId = UserId + FilterId + pub todeviceid_events: Arc, // ToDeviceId = UserId + DeviceId + Count + pub userid_presenceid: Arc, // UserId => Count + pub presenceid_presence: Arc, // Count + UserId => Presence + + //pub uiaa: uiaa::Uiaa, + pub userdevicesessionid_uiaainfo: Arc, // User-interactive authentication + pub userdevicesessionid_uiaarequest: RwLock>, + + //pub edus: RoomEdus, + pub readreceiptid_readreceipt: Arc, // ReadReceiptId = RoomId + Count + UserId + pub roomuserid_privateread: Arc, // RoomUserId = Room + User, PrivateRead = Count + pub roomuserid_lastprivatereadupdate: Arc, // LastPrivateReadUpdate = Count + + //pub rooms: rooms::Rooms, + pub pduid_pdu: Arc, // PduId = ShortRoomId + Count + pub eventid_pduid: Arc, + pub roomid_pduleaves: Arc, + pub alias_roomid: Arc, + pub aliasid_alias: Arc, // AliasId = RoomId + Count + pub publicroomids: Arc, + + pub threadid_userids: Arc, // ThreadId = RoomId + Count + + pub tokenids: Arc, // TokenId = ShortRoomId + Token + PduIdCount + + /// Participating servers in a room. + pub roomserverids: Arc, // RoomServerId = RoomId + ServerName + pub serverroomids: Arc, // ServerRoomId = ServerName + RoomId + + pub userroomid_joined: Arc, + pub roomuserid_joined: Arc, + pub roomid_joinedcount: Arc, + pub roomid_invitedcount: Arc, + pub roomuseroncejoinedids: Arc, + pub userroomid_invitestate: Arc, // InviteState = Vec> + pub roomuserid_invitecount: Arc, // InviteCount = Count + pub userroomid_leftstate: Arc, + pub roomuserid_leftcount: Arc, + + pub disabledroomids: Arc, // Rooms where incoming federation handling is disabled + + pub bannedroomids: Arc, // Rooms where local users are not allowed to join + + pub lazyloadedids: Arc, // LazyLoadedIds = UserId + DeviceId + RoomId + LazyLoadedUserId + + pub userroomid_notificationcount: Arc, // NotifyCount = u64 + pub userroomid_highlightcount: Arc, // HightlightCount = u64 + pub roomuserid_lastnotificationread: Arc, // LastNotificationRead = u64 + + /// Remember the current state hash of a room. + pub roomid_shortstatehash: Arc, + pub roomsynctoken_shortstatehash: Arc, + /// Remember the state hash at events in the past. + pub shorteventid_shortstatehash: Arc, + pub statekey_shortstatekey: Arc, /* StateKey = EventType + StateKey, ShortStateKey = + * Count */ + pub shortstatekey_statekey: Arc, + + pub roomid_shortroomid: Arc, + + pub shorteventid_eventid: Arc, + pub eventid_shorteventid: Arc, + + pub statehash_shortstatehash: Arc, + pub shortstatehash_statediff: Arc, /* StateDiff = parent (or 0) + + * (shortstatekey+shorteventid++) + 0_u64 + + * (shortstatekey+shorteventid--) */ + + pub shorteventid_authchain: Arc, + + /// RoomId + EventId -> outlier PDU. + /// Any pdu that has passed the steps 1-8 in the incoming event + /// /federation/send/txn. + pub eventid_outlierpdu: Arc, + pub softfailedeventids: Arc, + + /// ShortEventId + ShortEventId -> (). + pub tofrom_relation: Arc, + /// RoomId + EventId -> Parent PDU EventId. + pub referencedevents: Arc, + + //pub account_data: account_data::AccountData, + pub roomuserdataid_accountdata: Arc, // RoomUserDataId = Room + User + Count + Type + pub roomusertype_roomuserdataid: Arc, // RoomUserType = Room + User + Type + + //pub media: media::Media, + pub mediaid_file: Arc, // MediaId = MXC + WidthHeight + ContentDisposition + ContentType + pub url_previews: Arc, + pub mediaid_user: Arc, + //pub key_backups: key_backups::KeyBackups, + pub backupid_algorithm: Arc, // BackupId = UserId + Version(Count) + pub backupid_etag: Arc, // BackupId = UserId + Version(Count) + pub backupkeyid_backup: Arc, // BackupKeyId = UserId + Version + RoomId + SessionId + + //pub transaction_ids: transaction_ids::TransactionIds, + pub userdevicetxnid_response: Arc, /* Response can be empty (/sendToDevice) or the event id + * (/send) */ + //pub sending: sending::Sending, + pub servername_educount: Arc, // EduCount: Count of last EDU sync + pub servernameevent_data: Arc, /* ServernameEvent = (+ / $)SenderKey / ServerName / UserId + + * PduId / Id (for edus), Data = EDU content */ + pub servercurrentevent_data: Arc, /* ServerCurrentEvents = (+ / $)ServerName / UserId + PduId + * / Id (for edus), Data = EDU content */ + + //pub appservice: appservice::Appservice, + pub id_appserviceregistrations: Arc, + + //pub pusher: pusher::PushData, + pub senderkey_pusher: Arc, + + pub auth_chain_cache: Mutex, Arc<[u64]>>>, + pub our_real_users_cache: RwLock>>>, + pub appservice_in_room_cache: RwLock>>, + pub lasttimelinecount_cache: Mutex>, +} + +impl KeyValueDatabase { + /// Load an existing database or create a new one. + #[allow(clippy::too_many_lines)] + pub async fn load_or_create(server: &Arc) -> Result { + let config = &server.config; + check_db_setup(config)?; + let builder = build(config)?; + Ok(Self { + db: builder.clone(), + userid_password: builder.open_tree("userid_password")?, + userid_displayname: builder.open_tree("userid_displayname")?, + userid_avatarurl: builder.open_tree("userid_avatarurl")?, + userid_blurhash: builder.open_tree("userid_blurhash")?, + userdeviceid_token: builder.open_tree("userdeviceid_token")?, + userdeviceid_metadata: builder.open_tree("userdeviceid_metadata")?, + userid_devicelistversion: builder.open_tree("userid_devicelistversion")?, + token_userdeviceid: builder.open_tree("token_userdeviceid")?, + onetimekeyid_onetimekeys: builder.open_tree("onetimekeyid_onetimekeys")?, + userid_lastonetimekeyupdate: builder.open_tree("userid_lastonetimekeyupdate")?, + keychangeid_userid: builder.open_tree("keychangeid_userid")?, + keyid_key: builder.open_tree("keyid_key")?, + userid_masterkeyid: builder.open_tree("userid_masterkeyid")?, + userid_selfsigningkeyid: builder.open_tree("userid_selfsigningkeyid")?, + userid_usersigningkeyid: builder.open_tree("userid_usersigningkeyid")?, + userfilterid_filter: builder.open_tree("userfilterid_filter")?, + todeviceid_events: builder.open_tree("todeviceid_events")?, + userid_presenceid: builder.open_tree("userid_presenceid")?, + presenceid_presence: builder.open_tree("presenceid_presence")?, + + userdevicesessionid_uiaainfo: builder.open_tree("userdevicesessionid_uiaainfo")?, + userdevicesessionid_uiaarequest: RwLock::new(BTreeMap::new()), + readreceiptid_readreceipt: builder.open_tree("readreceiptid_readreceipt")?, + roomuserid_privateread: builder.open_tree("roomuserid_privateread")?, // "Private" read receipt + roomuserid_lastprivatereadupdate: builder.open_tree("roomuserid_lastprivatereadupdate")?, + pduid_pdu: builder.open_tree("pduid_pdu")?, + eventid_pduid: builder.open_tree("eventid_pduid")?, + roomid_pduleaves: builder.open_tree("roomid_pduleaves")?, + + alias_roomid: builder.open_tree("alias_roomid")?, + aliasid_alias: builder.open_tree("aliasid_alias")?, + publicroomids: builder.open_tree("publicroomids")?, + + threadid_userids: builder.open_tree("threadid_userids")?, + + tokenids: builder.open_tree("tokenids")?, + + roomserverids: builder.open_tree("roomserverids")?, + serverroomids: builder.open_tree("serverroomids")?, + userroomid_joined: builder.open_tree("userroomid_joined")?, + roomuserid_joined: builder.open_tree("roomuserid_joined")?, + roomid_joinedcount: builder.open_tree("roomid_joinedcount")?, + roomid_invitedcount: builder.open_tree("roomid_invitedcount")?, + roomuseroncejoinedids: builder.open_tree("roomuseroncejoinedids")?, + userroomid_invitestate: builder.open_tree("userroomid_invitestate")?, + roomuserid_invitecount: builder.open_tree("roomuserid_invitecount")?, + userroomid_leftstate: builder.open_tree("userroomid_leftstate")?, + roomuserid_leftcount: builder.open_tree("roomuserid_leftcount")?, + + disabledroomids: builder.open_tree("disabledroomids")?, + + bannedroomids: builder.open_tree("bannedroomids")?, + + lazyloadedids: builder.open_tree("lazyloadedids")?, + + userroomid_notificationcount: builder.open_tree("userroomid_notificationcount")?, + userroomid_highlightcount: builder.open_tree("userroomid_highlightcount")?, + roomuserid_lastnotificationread: builder.open_tree("userroomid_highlightcount")?, + + statekey_shortstatekey: builder.open_tree("statekey_shortstatekey")?, + shortstatekey_statekey: builder.open_tree("shortstatekey_statekey")?, + + shorteventid_authchain: builder.open_tree("shorteventid_authchain")?, + + roomid_shortroomid: builder.open_tree("roomid_shortroomid")?, + + shortstatehash_statediff: builder.open_tree("shortstatehash_statediff")?, + eventid_shorteventid: builder.open_tree("eventid_shorteventid")?, + shorteventid_eventid: builder.open_tree("shorteventid_eventid")?, + shorteventid_shortstatehash: builder.open_tree("shorteventid_shortstatehash")?, + roomid_shortstatehash: builder.open_tree("roomid_shortstatehash")?, + roomsynctoken_shortstatehash: builder.open_tree("roomsynctoken_shortstatehash")?, + statehash_shortstatehash: builder.open_tree("statehash_shortstatehash")?, + + eventid_outlierpdu: builder.open_tree("eventid_outlierpdu")?, + softfailedeventids: builder.open_tree("softfailedeventids")?, + + tofrom_relation: builder.open_tree("tofrom_relation")?, + referencedevents: builder.open_tree("referencedevents")?, + roomuserdataid_accountdata: builder.open_tree("roomuserdataid_accountdata")?, + roomusertype_roomuserdataid: builder.open_tree("roomusertype_roomuserdataid")?, + mediaid_file: builder.open_tree("mediaid_file")?, + url_previews: builder.open_tree("url_previews")?, + mediaid_user: builder.open_tree("mediaid_user")?, + backupid_algorithm: builder.open_tree("backupid_algorithm")?, + backupid_etag: builder.open_tree("backupid_etag")?, + backupkeyid_backup: builder.open_tree("backupkeyid_backup")?, + userdevicetxnid_response: builder.open_tree("userdevicetxnid_response")?, + servername_educount: builder.open_tree("servername_educount")?, + servernameevent_data: builder.open_tree("servernameevent_data")?, + servercurrentevent_data: builder.open_tree("servercurrentevent_data")?, + id_appserviceregistrations: builder.open_tree("id_appserviceregistrations")?, + senderkey_pusher: builder.open_tree("senderkey_pusher")?, + global: builder.open_tree("global")?, + server_signingkeys: builder.open_tree("server_signingkeys")?, + + roomid_inviteviaservers: builder.open_tree("roomid_inviteviaservers")?, + + auth_chain_cache: Mutex::new(LruCache::new( + (f64::from(config.auth_chain_cache_capacity) * config.conduit_cache_capacity_modifier) as usize, + )), + our_real_users_cache: RwLock::new(HashMap::new()), + appservice_in_room_cache: RwLock::new(HashMap::new()), + lasttimelinecount_cache: Mutex::new(HashMap::new()), + }) + } +} + +fn build(config: &Config) -> Result> { + match &*config.database_backend { + "sqlite" => { + debug!("Got sqlite database backend"); + #[cfg(not(feature = "sqlite"))] + return Err(Error::bad_config("Database backend not found.")); + #[cfg(feature = "sqlite")] + Ok(Arc::new(Arc::::open(config)?)) + }, + "rocksdb" => { + debug!("Got rocksdb database backend"); + #[cfg(not(feature = "rocksdb"))] + return Err(Error::bad_config("Database backend not found.")); + #[cfg(feature = "rocksdb")] + Ok(Arc::new(Arc::::open(config)?)) + }, + _ => Err(Error::bad_config( + "Database backend not found. sqlite (not recommended) and rocksdb are the only supported backends.", + )), + } +} + +fn check_db_setup(config: &Config) -> Result<()> { + let path = Path::new(&config.database_path); + + let sqlite_exists = path.join("conduit.db").exists(); + let rocksdb_exists = path.join("IDENTITY").exists(); + + if sqlite_exists && rocksdb_exists { + return Err(Error::bad_config("Multiple databases at database_path detected.")); + } + + if sqlite_exists && config.database_backend != "sqlite" { + return Err(Error::bad_config( + "Found sqlite at database_path, but is not specified in config.", + )); + } + + if rocksdb_exists && config.database_backend != "rocksdb" { + return Err(Error::bad_config( + "Found rocksdb at database_path, but is not specified in config.", + )); + } + + Ok(()) +} diff --git a/src/database/kvengine.rs b/src/database/kvengine.rs index c67a7e98..1b27c571 100644 --- a/src/database/kvengine.rs +++ b/src/database/kvengine.rs @@ -3,7 +3,7 @@ use std::{error::Error, sync::Arc}; use super::{Config, KvTree}; use crate::Result; -pub(crate) trait KeyValueDatabaseEngine: Send + Sync { +pub trait KeyValueDatabaseEngine: Send + Sync { fn open(config: &Config) -> Result where Self: Sized; diff --git a/src/database/kvtree.rs b/src/database/kvtree.rs index 52e5b146..009e45d5 100644 --- a/src/database/kvtree.rs +++ b/src/database/kvtree.rs @@ -2,7 +2,7 @@ use std::{future::Future, pin::Pin}; use crate::Result; -pub(crate) trait KvTree: Send + Sync { +pub trait KvTree: Send + Sync { fn get(&self, key: &[u8]) -> Result>>; #[allow(dead_code)] diff --git a/src/database/mod.rs b/src/database/mod.rs index 4fbc3f97..506f7ac1 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -1,573 +1,23 @@ -mod cork; -mod key_value; +pub mod cork; +mod kvdatabase; mod kvengine; mod kvtree; -mod migrations; #[cfg(feature = "rocksdb")] -mod rocksdb; +pub(crate) mod rocksdb; #[cfg(feature = "sqlite")] -mod sqlite; +pub(crate) mod sqlite; #[cfg(any(feature = "sqlite", feature = "rocksdb"))] pub(crate) mod watchers; -use std::{ - collections::{BTreeMap, HashMap, HashSet}, - fs::{self}, - path::Path, - sync::{Arc, Mutex, RwLock}, - time::Duration, -}; - -pub(crate) use cork::Cork; -pub(crate) use kvengine::KeyValueDatabaseEngine; -pub(crate) use kvtree::KvTree; -use lru_cache::LruCache; -use ruma::{ - events::{ - push_rules::PushRulesEventContent, room::message::RoomMessageEventContent, GlobalAccountDataEvent, - GlobalAccountDataEventType, - }, - push::Ruleset, - CanonicalJsonValue, OwnedDeviceId, OwnedRoomId, OwnedUserId, UserId, -}; -use serde::Deserialize; -#[cfg(unix)] -use tokio::signal::unix::{signal, SignalKind}; -use tokio::time::{interval, Instant}; -use tracing::{debug, error, warn}; - -use crate::{ - database::migrations::migrations, service::rooms::timeline::PduCount, services, Config, Error, - LogLevelReloadHandles, Result, Services, SERVICES, -}; - -pub(crate) struct KeyValueDatabase { - db: Arc, - - //pub(crate) globals: globals::Globals, - pub(crate) global: Arc, - pub(crate) server_signingkeys: Arc, - - pub(crate) roomid_inviteviaservers: Arc, - - //pub(crate) users: users::Users, - pub(crate) userid_password: Arc, - pub(crate) userid_displayname: Arc, - pub(crate) userid_avatarurl: Arc, - pub(crate) userid_blurhash: Arc, - pub(crate) userdeviceid_token: Arc, - pub(crate) userdeviceid_metadata: Arc, // This is also used to check if a device exists - pub(crate) userid_devicelistversion: Arc, // DevicelistVersion = u64 - pub(crate) token_userdeviceid: Arc, - - pub(crate) onetimekeyid_onetimekeys: Arc, // OneTimeKeyId = UserId + DeviceKeyId - pub(crate) userid_lastonetimekeyupdate: Arc, // LastOneTimeKeyUpdate = Count - pub(crate) keychangeid_userid: Arc, // KeyChangeId = UserId/RoomId + Count - pub(crate) keyid_key: Arc, // KeyId = UserId + KeyId (depends on key type) - pub(crate) userid_masterkeyid: Arc, - pub(crate) userid_selfsigningkeyid: Arc, - pub(crate) userid_usersigningkeyid: Arc, - - pub(crate) userfilterid_filter: Arc, // UserFilterId = UserId + FilterId - pub(crate) todeviceid_events: Arc, // ToDeviceId = UserId + DeviceId + Count - pub(crate) userid_presenceid: Arc, // UserId => Count - pub(crate) presenceid_presence: Arc, // Count + UserId => Presence - - //pub(crate) uiaa: uiaa::Uiaa, - pub(crate) userdevicesessionid_uiaainfo: Arc, // User-interactive authentication - pub(crate) userdevicesessionid_uiaarequest: - RwLock>, - - //pub(crate) edus: RoomEdus, - pub(crate) readreceiptid_readreceipt: Arc, // ReadReceiptId = RoomId + Count + UserId - pub(crate) roomuserid_privateread: Arc, // RoomUserId = Room + User, PrivateRead = Count - pub(crate) roomuserid_lastprivatereadupdate: Arc, // LastPrivateReadUpdate = Count - - //pub(crate) rooms: rooms::Rooms, - pub(crate) pduid_pdu: Arc, // PduId = ShortRoomId + Count - pub(crate) eventid_pduid: Arc, - pub(crate) roomid_pduleaves: Arc, - pub(crate) alias_roomid: Arc, - pub(crate) aliasid_alias: Arc, // AliasId = RoomId + Count - pub(crate) publicroomids: Arc, - - pub(crate) threadid_userids: Arc, // ThreadId = RoomId + Count - - pub(crate) tokenids: Arc, // TokenId = ShortRoomId + Token + PduIdCount - - /// Participating servers in a room. - pub(crate) roomserverids: Arc, // RoomServerId = RoomId + ServerName - pub(crate) serverroomids: Arc, // ServerRoomId = ServerName + RoomId - - pub(crate) userroomid_joined: Arc, - pub(crate) roomuserid_joined: Arc, - pub(crate) roomid_joinedcount: Arc, - pub(crate) roomid_invitedcount: Arc, - pub(crate) roomuseroncejoinedids: Arc, - pub(crate) userroomid_invitestate: Arc, // InviteState = Vec> - pub(crate) roomuserid_invitecount: Arc, // InviteCount = Count - pub(crate) userroomid_leftstate: Arc, - pub(crate) roomuserid_leftcount: Arc, - - pub(crate) disabledroomids: Arc, // Rooms where incoming federation handling is disabled - - pub(crate) bannedroomids: Arc, // Rooms where local users are not allowed to join - - pub(crate) lazyloadedids: Arc, // LazyLoadedIds = UserId + DeviceId + RoomId + LazyLoadedUserId - - pub(crate) userroomid_notificationcount: Arc, // NotifyCount = u64 - pub(crate) userroomid_highlightcount: Arc, // HightlightCount = u64 - pub(crate) roomuserid_lastnotificationread: Arc, // LastNotificationRead = u64 - - /// Remember the current state hash of a room. - pub(crate) roomid_shortstatehash: Arc, - pub(crate) roomsynctoken_shortstatehash: Arc, - /// Remember the state hash at events in the past. - pub(crate) shorteventid_shortstatehash: Arc, - pub(crate) statekey_shortstatekey: Arc, /* StateKey = EventType + StateKey, ShortStateKey = - * Count */ - pub(crate) shortstatekey_statekey: Arc, - - pub(crate) roomid_shortroomid: Arc, - - pub(crate) shorteventid_eventid: Arc, - pub(crate) eventid_shorteventid: Arc, - - pub(crate) statehash_shortstatehash: Arc, - pub(crate) shortstatehash_statediff: Arc, /* StateDiff = parent (or 0) + - * (shortstatekey+shorteventid++) + 0_u64 + - * (shortstatekey+shorteventid--) */ - - pub(crate) shorteventid_authchain: Arc, - - /// RoomId + EventId -> outlier PDU. - /// Any pdu that has passed the steps 1-8 in the incoming event - /// /federation/send/txn. - pub(crate) eventid_outlierpdu: Arc, - pub(crate) softfailedeventids: Arc, - - /// ShortEventId + ShortEventId -> (). - pub(crate) tofrom_relation: Arc, - /// RoomId + EventId -> Parent PDU EventId. - pub(crate) referencedevents: Arc, - - //pub(crate) account_data: account_data::AccountData, - pub(crate) roomuserdataid_accountdata: Arc, // RoomUserDataId = Room + User + Count + Type - pub(crate) roomusertype_roomuserdataid: Arc, // RoomUserType = Room + User + Type - - //pub(crate) media: media::Media, - pub(crate) mediaid_file: Arc, // MediaId = MXC + WidthHeight + ContentDisposition + ContentType - pub(crate) url_previews: Arc, - pub(crate) mediaid_user: Arc, - //pub(crate) key_backups: key_backups::KeyBackups, - pub(crate) backupid_algorithm: Arc, // BackupId = UserId + Version(Count) - pub(crate) backupid_etag: Arc, // BackupId = UserId + Version(Count) - pub(crate) backupkeyid_backup: Arc, // BackupKeyId = UserId + Version + RoomId + SessionId - - //pub(crate) transaction_ids: transaction_ids::TransactionIds, - pub(crate) userdevicetxnid_response: Arc, /* Response can be empty (/sendToDevice) or the event id - * (/send) */ - //pub(crate) sending: sending::Sending, - pub(crate) servername_educount: Arc, // EduCount: Count of last EDU sync - pub(crate) servernameevent_data: Arc, /* ServernameEvent = (+ / $)SenderKey / ServerName / UserId + - * PduId / Id (for edus), Data = EDU content */ - pub(crate) servercurrentevent_data: Arc, /* ServerCurrentEvents = (+ / $)ServerName / UserId + PduId - * / Id (for edus), Data = EDU content */ - - //pub(crate) appservice: appservice::Appservice, - pub(crate) id_appserviceregistrations: Arc, - - //pub(crate) pusher: pusher::PushData, - pub(crate) senderkey_pusher: Arc, - - pub(crate) auth_chain_cache: Mutex, Arc<[u64]>>>, - pub(crate) our_real_users_cache: RwLock>>>, - pub(crate) appservice_in_room_cache: RwLock>>, - pub(crate) lasttimelinecount_cache: Mutex>, -} - -#[derive(Deserialize)] -struct CheckForUpdatesResponseEntry { - id: u64, - date: String, - message: String, -} -#[derive(Deserialize)] -struct CheckForUpdatesResponse { - updates: Vec, -} - -impl KeyValueDatabase { - /// Load an existing database or create a new one. - #[allow(clippy::too_many_lines)] - pub(crate) async fn load_or_create(config: Config, tracing_reload_handler: LogLevelReloadHandles) -> Result<()> { - Self::check_db_setup(&config)?; - - if !Path::new(&config.database_path).exists() { - debug!("Database path does not exist, assuming this is a new setup and creating it"); - fs::create_dir_all(&config.database_path).map_err(|e| { - error!("Failed to create database path: {e}"); - Error::bad_config( - "Database folder doesn't exists and couldn't be created (e.g. due to missing permissions). Please \ - create the database folder yourself or allow conduwuit the permissions to create directories and \ - files.", - ) - })?; - } - - let builder: Arc = match &*config.database_backend { - "sqlite" => { - debug!("Got sqlite database backend"); - #[cfg(not(feature = "sqlite"))] - return Err(Error::bad_config("Database backend not found.")); - #[cfg(feature = "sqlite")] - Arc::new(Arc::::open(&config)?) - }, - "rocksdb" => { - debug!("Got rocksdb database backend"); - #[cfg(not(feature = "rocksdb"))] - return Err(Error::bad_config("Database backend not found.")); - #[cfg(feature = "rocksdb")] - Arc::new(Arc::::open(&config)?) - }, - _ => { - return Err(Error::bad_config( - "Database backend not found. sqlite (not recommended) and rocksdb are the only supported backends.", - )); - }, - }; - - let db_raw = Box::new(Self { - db: builder.clone(), - userid_password: builder.open_tree("userid_password")?, - userid_displayname: builder.open_tree("userid_displayname")?, - userid_avatarurl: builder.open_tree("userid_avatarurl")?, - userid_blurhash: builder.open_tree("userid_blurhash")?, - userdeviceid_token: builder.open_tree("userdeviceid_token")?, - userdeviceid_metadata: builder.open_tree("userdeviceid_metadata")?, - userid_devicelistversion: builder.open_tree("userid_devicelistversion")?, - token_userdeviceid: builder.open_tree("token_userdeviceid")?, - onetimekeyid_onetimekeys: builder.open_tree("onetimekeyid_onetimekeys")?, - userid_lastonetimekeyupdate: builder.open_tree("userid_lastonetimekeyupdate")?, - keychangeid_userid: builder.open_tree("keychangeid_userid")?, - keyid_key: builder.open_tree("keyid_key")?, - userid_masterkeyid: builder.open_tree("userid_masterkeyid")?, - userid_selfsigningkeyid: builder.open_tree("userid_selfsigningkeyid")?, - userid_usersigningkeyid: builder.open_tree("userid_usersigningkeyid")?, - userfilterid_filter: builder.open_tree("userfilterid_filter")?, - todeviceid_events: builder.open_tree("todeviceid_events")?, - userid_presenceid: builder.open_tree("userid_presenceid")?, - presenceid_presence: builder.open_tree("presenceid_presence")?, - - userdevicesessionid_uiaainfo: builder.open_tree("userdevicesessionid_uiaainfo")?, - userdevicesessionid_uiaarequest: RwLock::new(BTreeMap::new()), - readreceiptid_readreceipt: builder.open_tree("readreceiptid_readreceipt")?, - roomuserid_privateread: builder.open_tree("roomuserid_privateread")?, // "Private" read receipt - roomuserid_lastprivatereadupdate: builder.open_tree("roomuserid_lastprivatereadupdate")?, - pduid_pdu: builder.open_tree("pduid_pdu")?, - eventid_pduid: builder.open_tree("eventid_pduid")?, - roomid_pduleaves: builder.open_tree("roomid_pduleaves")?, - - alias_roomid: builder.open_tree("alias_roomid")?, - aliasid_alias: builder.open_tree("aliasid_alias")?, - publicroomids: builder.open_tree("publicroomids")?, - - threadid_userids: builder.open_tree("threadid_userids")?, - - tokenids: builder.open_tree("tokenids")?, - - roomserverids: builder.open_tree("roomserverids")?, - serverroomids: builder.open_tree("serverroomids")?, - userroomid_joined: builder.open_tree("userroomid_joined")?, - roomuserid_joined: builder.open_tree("roomuserid_joined")?, - roomid_joinedcount: builder.open_tree("roomid_joinedcount")?, - roomid_invitedcount: builder.open_tree("roomid_invitedcount")?, - roomuseroncejoinedids: builder.open_tree("roomuseroncejoinedids")?, - userroomid_invitestate: builder.open_tree("userroomid_invitestate")?, - roomuserid_invitecount: builder.open_tree("roomuserid_invitecount")?, - userroomid_leftstate: builder.open_tree("userroomid_leftstate")?, - roomuserid_leftcount: builder.open_tree("roomuserid_leftcount")?, - - disabledroomids: builder.open_tree("disabledroomids")?, - - bannedroomids: builder.open_tree("bannedroomids")?, - - lazyloadedids: builder.open_tree("lazyloadedids")?, - - userroomid_notificationcount: builder.open_tree("userroomid_notificationcount")?, - userroomid_highlightcount: builder.open_tree("userroomid_highlightcount")?, - roomuserid_lastnotificationread: builder.open_tree("userroomid_highlightcount")?, - - statekey_shortstatekey: builder.open_tree("statekey_shortstatekey")?, - shortstatekey_statekey: builder.open_tree("shortstatekey_statekey")?, - - shorteventid_authchain: builder.open_tree("shorteventid_authchain")?, - - roomid_shortroomid: builder.open_tree("roomid_shortroomid")?, - - shortstatehash_statediff: builder.open_tree("shortstatehash_statediff")?, - eventid_shorteventid: builder.open_tree("eventid_shorteventid")?, - shorteventid_eventid: builder.open_tree("shorteventid_eventid")?, - shorteventid_shortstatehash: builder.open_tree("shorteventid_shortstatehash")?, - roomid_shortstatehash: builder.open_tree("roomid_shortstatehash")?, - roomsynctoken_shortstatehash: builder.open_tree("roomsynctoken_shortstatehash")?, - statehash_shortstatehash: builder.open_tree("statehash_shortstatehash")?, - - eventid_outlierpdu: builder.open_tree("eventid_outlierpdu")?, - softfailedeventids: builder.open_tree("softfailedeventids")?, - - tofrom_relation: builder.open_tree("tofrom_relation")?, - referencedevents: builder.open_tree("referencedevents")?, - roomuserdataid_accountdata: builder.open_tree("roomuserdataid_accountdata")?, - roomusertype_roomuserdataid: builder.open_tree("roomusertype_roomuserdataid")?, - mediaid_file: builder.open_tree("mediaid_file")?, - url_previews: builder.open_tree("url_previews")?, - mediaid_user: builder.open_tree("mediaid_user")?, - backupid_algorithm: builder.open_tree("backupid_algorithm")?, - backupid_etag: builder.open_tree("backupid_etag")?, - backupkeyid_backup: builder.open_tree("backupkeyid_backup")?, - userdevicetxnid_response: builder.open_tree("userdevicetxnid_response")?, - servername_educount: builder.open_tree("servername_educount")?, - servernameevent_data: builder.open_tree("servernameevent_data")?, - servercurrentevent_data: builder.open_tree("servercurrentevent_data")?, - id_appserviceregistrations: builder.open_tree("id_appserviceregistrations")?, - senderkey_pusher: builder.open_tree("senderkey_pusher")?, - global: builder.open_tree("global")?, - server_signingkeys: builder.open_tree("server_signingkeys")?, - - roomid_inviteviaservers: builder.open_tree("roomid_inviteviaservers")?, - - #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] - auth_chain_cache: Mutex::new(LruCache::new( - (f64::from(config.auth_chain_cache_capacity) * config.conduit_cache_capacity_modifier) as usize, - )), - our_real_users_cache: RwLock::new(HashMap::new()), - appservice_in_room_cache: RwLock::new(HashMap::new()), - lasttimelinecount_cache: Mutex::new(HashMap::new()), - }); - - let db = Box::leak(db_raw); - - let services_raw = Box::new(Services::build(db, &config, tracing_reload_handler)?); - - // This is the first and only time we initialize the SERVICE static - *SERVICES.write().unwrap() = Some(Box::leak(services_raw)); - - migrations(db, &config).await?; - - services().admin.start_handler(); - - // Set emergency access for the conduit user - 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!" - ); - 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!", - )) - .await; - } - }, - Err(e) => { - error!("Could not set the configured emergency password for the conduit user: {}", e); - }, - }; - - services().sending.start_handler(); - - if config.allow_local_presence { - services().presence.start_handler(); - } - - Self::start_cleanup_task().await; - if services().globals.allow_check_for_updates() { - Self::start_check_for_updates_task().await; - } - - Ok(()) - } - - fn check_db_setup(config: &Config) -> Result<()> { - let path = Path::new(&config.database_path); - - let sqlite_exists = path.join("conduit.db").exists(); - let rocksdb_exists = path.join("IDENTITY").exists(); - - if sqlite_exists && rocksdb_exists { - return Err(Error::bad_config("Multiple databases at database_path detected.")); - } - - if sqlite_exists && config.database_backend != "sqlite" { - return Err(Error::bad_config( - "Found sqlite at database_path, but is not specified in config.", - )); - } - - if rocksdb_exists && config.database_backend != "rocksdb" { - return Err(Error::bad_config( - "Found rocksdb at database_path, but is not specified in config.", - )); - } - - Ok(()) - } - - #[tracing::instrument] - async fn start_check_for_updates_task() { - let timer_interval = Duration::from_secs(7200); // 2 hours - - tokio::spawn(async move { - let mut i = interval(timer_interval); - - loop { - tokio::select! { - _ = i.tick() => { - debug!(target: "start_check_for_updates_task", "Timer ticked"); - }, - } - - _ = Self::try_handle_updates().await; - } - }); - } - - async fn try_handle_updates() -> Result<()> { - let response = services() - .globals - .client - .default - .get("https://pupbrain.dev/check-for-updates/stable") - .send() - .await?; - - let response = serde_json::from_str::(&response.text().await?).map_err(|e| { - error!("Bad check for updates response: {e}"); - Error::BadServerResponse("Bad version check response") - })?; - - let mut last_update_id = services().globals.last_check_for_updates_id()?; - for update in response.updates { - last_update_id = last_update_id.max(update.id); - if update.id > services().globals.last_check_for_updates_id()? { - error!("{}", update.message); - services() - .admin - .send_message(RoomMessageEventContent::text_plain(format!( - "@room: the following is a message from the conduwuit puppy. it was sent on '{}':\n\n{}", - update.date, update.message - ))) - .await; - } - } - services() - .globals - .update_check_for_updates_id(last_update_id)?; - - Ok(()) - } - - #[tracing::instrument] - async fn start_cleanup_task() { - let timer_interval = Duration::from_secs(u64::from(services().globals.config.cleanup_second_interval)); - - tokio::spawn(async move { - let mut i = interval(timer_interval); - - #[cfg(unix)] - let mut hangup = signal(SignalKind::hangup()).expect("Failed to register SIGHUP signal receiver"); - #[cfg(unix)] - let mut ctrl_c = signal(SignalKind::interrupt()).expect("Failed to register SIGINT signal receiver"); - #[cfg(unix)] - let mut terminate = signal(SignalKind::terminate()).expect("Failed to register SIGTERM signal receiver"); - - loop { - #[cfg(unix)] - tokio::select! { - _ = i.tick() => { - debug!(target: "database-cleanup", "Timer ticked"); - } - _ = hangup.recv() => { - debug!(target: "database-cleanup","Received SIGHUP"); - } - _ = ctrl_c.recv() => { - debug!(target: "database-cleanup", "Received Ctrl+C"); - } - _ = terminate.recv() => { - debug!(target: "database-cleanup","Received SIGTERM"); - } - } - - #[cfg(not(unix))] - { - i.tick().await; - debug!(target: "database-cleanup", "Timer ticked") - } - - Self::perform_cleanup(); - } - }); - } - - fn perform_cleanup() { - if !services().globals.config.rocksdb_periodic_cleanup { - return; - } - - let start = Instant::now(); - if let Err(e) = services().globals.cleanup() { - error!(target: "database-cleanup", "Ran into an error during cleanup: {}", e); - } else { - debug!(target: "database-cleanup", "Finished cleanup in {:#?}.", start.elapsed()); - } - } - - #[allow(dead_code)] - fn flush(&self) -> Result<()> { - let start = std::time::Instant::now(); - - let res = self.db.flush(); - - debug!("flush: took {:?}", start.elapsed()); - - res - } -} - -/// Sets the emergency password and push rules for the @conduit account in case -/// emergency password is set -fn set_emergency_access() -> Result { - let conduit_user = UserId::parse_with_server_name("conduit", services().globals.server_name()) - .expect("@conduit:server_name is a valid UserId"); - - services() - .users - .set_password(&conduit_user, services().globals.emergency_password().as_deref())?; - - let (ruleset, res) = match services().globals.emergency_password() { - Some(_) => (Ruleset::server_default(&conduit_user), Ok(true)), - None => (Ruleset::new(), Ok(false)), - }; - - services().account_data.update( - None, - &conduit_user, - GlobalAccountDataEventType::PushRules.to_string().into(), - &serde_json::to_value(&GlobalAccountDataEvent { - content: PushRulesEventContent { - global: ruleset, - }, - }) - .expect("to json value always works"), - )?; - - res -} +extern crate conduit_core as conduit; +pub(crate) use conduit::{Config, Result}; +pub use cork::Cork; +pub use kvdatabase::KeyValueDatabase; +pub use kvengine::KeyValueDatabaseEngine; +pub use kvtree::KvTree; + +conduit::mod_ctor! {} +conduit::mod_dtor! {} diff --git a/src/database/rocksdb/kvtree.rs b/src/database/rocksdb/kvtree.rs index 4761624b..02a0f3bf 100644 --- a/src/database/rocksdb/kvtree.rs +++ b/src/database/rocksdb/kvtree.rs @@ -1,9 +1,8 @@ use std::{future::Future, pin::Pin, sync::Arc}; -use rust_rocksdb::WriteBatchWithTransaction; +use conduit::{utils, Result}; -use super::{watchers::Watchers, Engine, KeyValueDatabaseEngine, KvTree}; -use crate::{utils, Result}; +use super::{rust_rocksdb::WriteBatchWithTransaction, watchers::Watchers, Engine, KeyValueDatabaseEngine, KvTree}; pub(crate) struct RocksDbEngineTree<'a> { pub(crate) db: Arc, diff --git a/src/database/rocksdb/mod.rs b/src/database/rocksdb/mod.rs index 4ef8f9a7..3f39c292 100644 --- a/src/database/rocksdb/mod.rs +++ b/src/database/rocksdb/mod.rs @@ -1,3 +1,8 @@ +// no_link to prevent double-inclusion of librocksdb.a here and with +// libconduit_core.so +#[no_link] +extern crate rust_rocksdb; + use std::{ collections::HashMap, sync::{atomic::AtomicU32, Arc}, @@ -6,12 +11,12 @@ use std::{ use chrono::{DateTime, Utc}; use rust_rocksdb::{ backup::{BackupEngine, BackupEngineOptions}, + perf::get_memory_usage_stats, Cache, ColumnFamilyDescriptor, DBCommon, DBWithThreadMode as Db, Env, MultiThreaded, Options, }; use tracing::{debug, error, info, warn}; -use super::{super::Config, watchers::Watchers, KeyValueDatabaseEngine, KvTree}; -use crate::Result; +use crate::{watchers::Watchers, Config, KeyValueDatabaseEngine, KvTree, Result}; pub(crate) mod kvtree; pub(crate) mod opts; @@ -22,13 +27,13 @@ use opts::{cf_options, db_options}; use super::watchers; pub(crate) struct Engine { - rocks: Db, + config: Config, row_cache: Cache, col_cache: HashMap, - old_cfs: Vec, opts: Options, env: Env, - config: Config, + old_cfs: Vec, + rocks: Db, corks: AtomicU32, } @@ -79,13 +84,13 @@ impl KeyValueDatabaseEngine for Arc { load_time.elapsed() ); Ok(Arc::new(Engine { - rocks: db, + config: config.clone(), row_cache, col_cache, - old_cfs: cfs, opts: db_opts, env: db_env, - config: config.clone(), + old_cfs: cfs, + rocks: db, corks: AtomicU32::new(0), })) } @@ -135,7 +140,7 @@ impl KeyValueDatabaseEngine for Arc { #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] fn memory_usage(&self) -> Result { let mut res = String::new(); - let stats = rust_rocksdb::perf::get_memory_usage_stats(Some(&[&self.rocks]), Some(&[&self.row_cache]))?; + let stats = get_memory_usage_stats(Some(&[&self.rocks]), Some(&[&self.row_cache]))?; _ = std::fmt::write( &mut res, format_args!( @@ -258,3 +263,20 @@ impl KeyValueDatabaseEngine for Arc { #[allow(dead_code)] fn clear_caches(&self) {} } + +impl Drop for Engine { + fn drop(&mut self) { + debug!("Waiting for background tasks to finish..."); + const BLOCKING: bool = true; + self.rocks.cancel_all_background_work(BLOCKING); + + debug!("Shutting down background threads"); + self.env.set_high_priority_background_threads(0); + self.env.set_low_priority_background_threads(0); + self.env.set_bottom_priority_background_threads(0); + self.env.set_background_threads(0); + + debug!("Joining background threads..."); + self.env.join_all_threads(); + } +} diff --git a/src/database/rocksdb/opts.rs b/src/database/rocksdb/opts.rs index 78b6db95..b417b126 100644 --- a/src/database/rocksdb/opts.rs +++ b/src/database/rocksdb/opts.rs @@ -1,14 +1,14 @@ #![allow(dead_code)] - use std::collections::HashMap; -use rust_rocksdb::{ - BlockBasedOptions, Cache, DBCompactionStyle, DBCompressionType, DBRecoveryMode, Env, LogLevel, Options, - UniversalCompactOptions, UniversalCompactionStopStyle, +use super::{ + rust_rocksdb::{ + BlockBasedOptions, Cache, DBCompactionStyle, DBCompressionType, DBRecoveryMode, Env, LogLevel, Options, + UniversalCompactOptions, UniversalCompactionStopStyle, + }, + Config, }; -use super::Config; - /// Create database-wide options suitable for opening the database. This also /// sets our default column options in case of opening a column with the same /// resulting value. Note that we require special per-column options on some diff --git a/src/database/sqlite/mod.rs b/src/database/sqlite/mod.rs index c43d2fe0..4e8c079e 100644 --- a/src/database/sqlite/mod.rs +++ b/src/database/sqlite/mod.rs @@ -6,13 +6,13 @@ use std::{ sync::Arc, }; +use conduit::{Config, Result}; use parking_lot::{Mutex, MutexGuard}; use rusqlite::{Connection, DatabaseName::Main, OptionalExtension}; use thread_local::ThreadLocal; use tracing::debug; use super::{watchers::Watchers, KeyValueDatabaseEngine, KvTree}; -use crate::{database::Config, Result}; thread_local! { static READ_CONNECTION: RefCell> = const { RefCell::new(None) }; @@ -224,7 +224,7 @@ impl KvTree for SqliteTable { guard.execute("BEGIN", [])?; for key in iter { let old = self.get_with_guard(&guard, &key)?; - let new = crate::utils::increment(old.as_deref()); + let new = conduit::utils::increment(old.as_deref()); self.insert_with_guard(&guard, &key, &new)?; } guard.execute("COMMIT", [])?; @@ -307,7 +307,7 @@ impl KvTree for SqliteTable { let old = self.get_with_guard(&guard, key)?; - let new = crate::utils::increment(old.as_deref()); + let new = conduit::utils::increment(old.as_deref()); self.insert_with_guard(&guard, key, &new)?; diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 7f40038b..00000000 --- a/src/main.rs +++ /dev/null @@ -1,503 +0,0 @@ -#[cfg(unix)] -use std::fs::Permissions; // not unix specific, just only for UNIX sockets stuff and *nix container checks -#[cfg(unix)] -use std::os::unix::fs::PermissionsExt as _; /* not unix specific, just only for UNIX sockets stuff and *nix - * container checks */ -// Not async due to services() being used in many closures, and async closures -// are not stable as of writing This is the case for every other occurence of -// sync Mutex/RwLock, except for database related ones -use std::sync::{Arc, RwLock}; -use std::{io, net::SocketAddr, time::Duration}; - -use api::ruma_wrapper::{Ruma, RumaResponse}; -use axum::Router; -use axum_server::{bind, bind_rustls, tls_rustls::RustlsConfig, Handle as ServerHandle}; -#[cfg(feature = "axum_dual_protocol")] -use axum_server_dual_protocol::ServerExt; -use config::Config; -use database::KeyValueDatabase; -use service::{pdu::PduEvent, Services}; -use tokio::{ - signal, - sync::oneshot::{self, Sender}, - task::JoinSet, -}; -use tracing::{debug, error, info, warn}; -use tracing_subscriber::{prelude::*, reload, EnvFilter, Registry}; -use utils::{ - clap, - error::{Error, Result}, -}; - -pub(crate) mod alloc; -mod api; -mod config; -mod database; -mod router; -mod service; -mod utils; - -pub(crate) static SERVICES: RwLock>> = RwLock::new(None); - -#[must_use] -pub(crate) fn services() -> &'static Services<'static> { - SERVICES - .read() - .unwrap() - .expect("SERVICES should be initialized when this is called") -} - -pub(crate) struct Server { - config: Config, - - runtime: tokio::runtime::Runtime, - - tracing_reload_handle: LogLevelReloadHandles, - - #[cfg(feature = "sentry_telemetry")] - _sentry_guard: Option, - - _tracing_flame_guard: TracingFlameGuard, -} - -fn main() -> Result<(), Error> { - let args = clap::parse(); - let conduwuit: Server = init(args)?; - - conduwuit - .runtime - .block_on(async { async_main(&conduwuit).await }) -} - -async fn async_main(server: &Server) -> Result<(), Error> { - if let Err(error) = start(server).await { - error!("Critical error starting server: {error}"); - return Err(Error::Err(format!("{error}"))); - } - - if let Err(error) = run(server).await { - error!("Critical error running server: {error}"); - return Err(Error::Err(format!("{error}"))); - } - - if let Err(error) = stop(server).await { - error!("Critical error stopping server: {error}"); - return Err(Error::Err(format!("{error}"))); - } - - Ok(()) -} - -async fn run(server: &Server) -> io::Result<()> { - let app = router::build(server).await?; - let (tx, rx) = oneshot::channel::<()>(); - let handle = ServerHandle::new(); - tokio::spawn(shutdown(handle.clone(), tx)); - - #[cfg(unix)] - if server.config.unix_socket_path.is_some() { - return run_unix_socket_server(server, app, rx).await; - } - - let addrs = server.config.get_bind_addrs(); - if server.config.tls.is_some() { - return run_tls_server(server, app, handle, addrs).await; - } - - let mut join_set = JoinSet::new(); - for addr in &addrs { - join_set.spawn(bind(*addr).handle(handle.clone()).serve(app.clone())); - } - - #[allow(clippy::let_underscore_untyped)] // error[E0658]: attributes on expressions are experimental - #[cfg(feature = "systemd")] - let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Ready]); - - info!("Listening on {:?}", addrs); - join_set.join_next().await; - - Ok(()) -} - -async fn run_tls_server( - server: &Server, app: axum::routing::IntoMakeService, handle: ServerHandle, addrs: Vec, -) -> io::Result<()> { - let tls = server.config.tls.as_ref().unwrap(); - - debug!( - "Using direct TLS. Certificate path {} and certificate private key path {}", - &tls.certs, &tls.key - ); - info!( - "Note: It is strongly recommended that you use a reverse proxy instead of running conduwuit directly with TLS." - ); - let conf = RustlsConfig::from_pem_file(&tls.certs, &tls.key).await?; - - if cfg!(feature = "axum_dual_protocol") { - info!( - "conduwuit was built with axum_dual_protocol feature to listen on both HTTP and HTTPS. This will only \ - take affect if `dual_protocol` is enabled in `[global.tls]`" - ); - } - - let mut join_set = JoinSet::new(); - - if cfg!(feature = "axum_dual_protocol") && tls.dual_protocol { - #[cfg(feature = "axum_dual_protocol")] - for addr in &addrs { - join_set.spawn( - axum_server_dual_protocol::bind_dual_protocol(*addr, conf.clone()) - .set_upgrade(false) - .handle(handle.clone()) - .serve(app.clone()), - ); - } - } else { - for addr in &addrs { - join_set.spawn( - bind_rustls(*addr, conf.clone()) - .handle(handle.clone()) - .serve(app.clone()), - ); - } - } - - #[allow(clippy::let_underscore_untyped)] // error[E0658]: attributes on expressions are experimental - #[cfg(feature = "systemd")] - let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Ready]); - - if cfg!(feature = "axum_dual_protocol") && tls.dual_protocol { - warn!( - "Listening on {:?} with TLS certificate {} and supporting plain text (HTTP) connections too (insecure!)", - addrs, &tls.certs - ); - } else { - info!("Listening on {:?} with TLS certificate {}", addrs, &tls.certs); - } - - join_set.join_next().await; - - Ok(()) -} - -#[cfg(unix)] -#[allow(unused_variables)] -async fn run_unix_socket_server( - server: &Server, app: axum::routing::IntoMakeService, rx: oneshot::Receiver<()>, -) -> io::Result<()> { - let path = server.config.unix_socket_path.as_ref().unwrap(); - - if path.exists() { - warn!( - "UNIX socket path {:#?} already exists (unclean shutdown?), attempting to remove it.", - path.display() - ); - tokio::fs::remove_file(&path).await?; - } - - tokio::fs::create_dir_all(path.parent().unwrap()).await?; - - let socket_perms = server.config.unix_socket_perms.to_string(); - let octal_perms = u32::from_str_radix(&socket_perms, 8).unwrap(); - tokio::fs::set_permissions(&path, Permissions::from_mode(octal_perms)) - .await - .unwrap(); - - #[allow(clippy::let_underscore_untyped)] // error[E0658]: attributes on expressions are experimental - #[cfg(feature = "systemd")] - let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Ready]); - let bind = tokio::net::UnixListener::bind(path)?; - info!("Listening at {:?}", path); - - Ok(()) -} - -async fn shutdown(handle: ServerHandle, tx: Sender<()>) -> Result<()> { - let ctrl_c = async { - signal::ctrl_c() - .await - .expect("failed to install Ctrl+C handler"); - }; - - #[cfg(unix)] - let terminate = async { - signal::unix::signal(signal::unix::SignalKind::terminate()) - .expect("failed to install SIGTERM handler") - .recv() - .await; - }; - - let sig: &str; - #[cfg(unix)] - tokio::select! { - () = ctrl_c => { sig = "Ctrl+C"; }, - () = terminate => { sig = "SIGTERM"; }, - } - #[cfg(not(unix))] - tokio::select! { - _ = ctrl_c => { sig = "Ctrl+C"; }, - } - - warn!("Received {}, shutting down...", sig); - handle.graceful_shutdown(Some(Duration::from_secs(180))); - services().globals.shutdown(); - - #[allow(clippy::let_underscore_untyped)] // error[E0658]: attributes on expressions are experimental - #[cfg(feature = "systemd")] - let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Stopping]); - - tx.send(()).expect( - "failed sending shutdown transaction to oneshot channel (this is unlikely a conduwuit bug and more so your \ - system may not be in an okay/ideal state.)", - ); - - Ok(()) -} - -async fn stop(_server: &Server) -> io::Result<()> { - info!("Shutdown complete."); - - Ok(()) -} - -/// Async initializations -async fn start(server: &Server) -> Result<(), Error> { - KeyValueDatabase::load_or_create(server.config.clone(), server.tracing_reload_handle.clone()).await?; - - Ok(()) -} - -/// Non-async initializations -fn init(args: clap::Args) -> Result { - let config = Config::new(args.config)?; - - #[cfg(feature = "sentry_telemetry")] - let sentry_guard = if config.sentry { - Some(init_sentry(&config)) - } else { - None - }; - - let (tracing_reload_handle, tracing_flame_guard) = init_tracing(&config); - - config.check()?; - - info!( - server_name = ?config.server_name, - database_path = ?config.database_path, - log_levels = ?config.log, - "{}", - utils::conduwuit_version(), - ); - - #[cfg(unix)] - maximize_fd_limit().expect("Unable to increase maximum soft and hard file descriptor limit"); - - Ok(Server { - config, - - runtime: tokio::runtime::Builder::new_multi_thread() - .enable_io() - .enable_time() - .thread_name("conduwuit:worker") - .worker_threads(std::cmp::max(2, num_cpus::get())) - .build() - .unwrap(), - - tracing_reload_handle, - - #[cfg(feature = "sentry_telemetry")] - _sentry_guard: sentry_guard, - _tracing_flame_guard: tracing_flame_guard, - }) -} - -#[cfg(feature = "sentry_telemetry")] -fn init_sentry(config: &Config) -> sentry::ClientInitGuard { - sentry::init(( - config - .sentry_endpoint - .as_ref() - .expect("init_sentry should only be called if sentry is enabled and this is not None") - .as_str(), - sentry::ClientOptions { - release: sentry::release_name!(), - traces_sample_rate: config.sentry_traces_sample_rate, - server_name: if config.sentry_send_server_name { - Some(config.server_name.to_string().into()) - } else { - None - }, - ..Default::default() - }, - )) -} - -/// We need to store a reload::Handle value, but can't name it's type explicitly -/// because the S type parameter depends on the subscriber's previous layers. In -/// our case, this includes unnameable 'impl Trait' types. -/// -/// This is fixed[1] in the unreleased tracing-subscriber from the master -/// branch, which removes the S parameter. Unfortunately can't use it without -/// pulling in a version of tracing that's incompatible with the rest of our -/// deps. -/// -/// To work around this, we define an trait without the S paramter that forwards -/// to the reload::Handle::reload method, and then store the handle as a trait -/// object. -/// -/// [1]: -trait ReloadHandle { - fn reload(&self, new_value: L) -> Result<(), reload::Error>; -} - -impl ReloadHandle for reload::Handle { - fn reload(&self, new_value: L) -> Result<(), reload::Error> { reload::Handle::reload(self, new_value) } -} - -struct LogLevelReloadHandlesInner { - handles: Vec + Send + Sync>>, -} - -/// Wrapper to allow reloading the filter on several several -/// [`tracing_subscriber::reload::Handle`]s at once, with the same value. -#[derive(Clone)] -struct LogLevelReloadHandles { - inner: Arc, -} - -impl LogLevelReloadHandles { - fn new(handles: Vec + Send + Sync>>) -> LogLevelReloadHandles { - LogLevelReloadHandles { - inner: Arc::new(LogLevelReloadHandlesInner { - handles, - }), - } - } - - fn reload(&self, new_value: &EnvFilter) -> Result<(), reload::Error> { - for handle in &self.inner.handles { - handle.reload(new_value.clone())?; - } - Ok(()) - } -} - -#[cfg(feature = "perf_measurements")] -type TracingFlameGuard = Option>>; -#[cfg(not(feature = "perf_measurements"))] -type TracingFlameGuard = (); - -// clippy thinks the filter_layer clones are redundant if the next usage is -// behind a disabled feature. -#[allow(clippy::redundant_clone)] -fn init_tracing(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard) { - let registry = Registry::default(); - let fmt_layer = tracing_subscriber::fmt::Layer::new(); - 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 occured while parsing it: {e}"); - EnvFilter::try_new("warn").unwrap() - }, - }; - - let mut reload_handles = Vec:: + Send + Sync>>::new(); - let subscriber = registry; - - #[cfg(feature = "tokio_console")] - let subscriber = { - let console_layer = console_subscriber::spawn(); - subscriber.with(console_layer) - }; - - let (fmt_reload_filter, fmt_reload_handle) = reload::Layer::new(filter_layer.clone()); - reload_handles.push(Box::new(fmt_reload_handle)); - let subscriber = subscriber.with(fmt_layer.with_filter(fmt_reload_filter)); - - #[cfg(feature = "sentry_telemetry")] - let subscriber = { - let sentry_layer = sentry_tracing::layer(); - let (sentry_reload_filter, sentry_reload_handle) = reload::Layer::new(filter_layer.clone()); - reload_handles.push(Box::new(sentry_reload_handle)); - subscriber.with(sentry_layer.with_filter(sentry_reload_filter)) - }; - - #[cfg(feature = "perf_measurements")] - let (subscriber, flame_guard) = { - let (flame_layer, flame_guard) = if config.tracing_flame { - let flame_filter = match EnvFilter::try_new(&config.tracing_flame_filter) { - Ok(flame_filter) => flame_filter, - Err(e) => panic!("tracing_flame_filter config value is invalid: {e}"), - }; - - let (flame_layer, flame_guard) = - match tracing_flame::FlameLayer::with_file(&config.tracing_flame_output_path) { - Ok(ok) => ok, - Err(e) => { - panic!("failed to initialize tracing-flame: {e}"); - }, - }; - let flame_layer = flame_layer - .with_empty_samples(false) - .with_filter(flame_filter); - (Some(flame_layer), Some(flame_guard)) - } else { - (None, None) - }; - - let jaeger_layer = if config.allow_jaeger { - opentelemetry::global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new()); - let tracer = opentelemetry_jaeger::new_agent_pipeline() - .with_auto_split_batch(true) - .with_service_name("conduwuit") - .install_batch(opentelemetry_sdk::runtime::Tokio) - .unwrap(); - let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); - - let (jaeger_reload_filter, jaeger_reload_handle) = reload::Layer::new(filter_layer); - reload_handles.push(Box::new(jaeger_reload_handle)); - Some(telemetry.with_filter(jaeger_reload_filter)) - } else { - None - }; - - let subscriber = subscriber.with(flame_layer).with(jaeger_layer); - (subscriber, flame_guard) - }; - - #[cfg(not(feature = "perf_measurements"))] - #[cfg_attr(not(feature = "perf_measurements"), allow(clippy::let_unit_value))] - let flame_guard = (); - - tracing::subscriber::set_global_default(subscriber).unwrap(); - - #[cfg(all(feature = "tokio_console", feature = "release_max_log_level"))] - error!( - "'tokio_console' feature and 'release_max_log_level' feature are incompatible, because console-subscriber \ - needs access to trace-level events. 'release_max_log_level' must be disabled to use tokio-console." - ); - - (LogLevelReloadHandles::new(reload_handles), flame_guard) -} - -/// This is needed for opening lots of file descriptors, which tends to -/// happen more often when using RocksDB and making lots of federation -/// connections at startup. The soft limit is usually 1024, and the hard -/// limit is usually 512000; I've personally seen it hit >2000. -/// -/// * -/// * -#[cfg(unix)] -fn maximize_fd_limit() -> Result<(), nix::errno::Errno> { - use nix::sys::resource::{getrlimit, setrlimit, Resource::RLIMIT_NOFILE as NOFILE}; - - let (soft_limit, hard_limit) = getrlimit(NOFILE)?; - if soft_limit < hard_limit { - setrlimit(NOFILE, hard_limit, hard_limit)?; - assert_eq!((hard_limit, hard_limit), getrlimit(NOFILE)?, "getrlimit != setrlimit"); - debug!(to = hard_limit, from = soft_limit, "Raised RLIMIT_NOFILE",); - } - - Ok(()) -} diff --git a/src/router/Cargo.toml b/src/router/Cargo.toml new file mode 100644 index 00000000..dae9d14c --- /dev/null +++ b/src/router/Cargo.toml @@ -0,0 +1,85 @@ +[package] +name = "conduit_router" +version.workspace = true +edition.workspace = true + +[lib] +path = "mod.rs" +crate-type = [ + "rlib", +# "dylib", +] + +[features] +default = [ + "systemd", + "sentry_telemetry", + "gzip_compression", + "zstd_compression", + "brotli_compression", + "release_max_log_level", +] + +dev_release_log_level = [] +release_max_log_level = [ + "tracing/max_level_trace", + "tracing/release_max_level_info", + "log/max_level_trace", + "log/release_max_level_info", +] +sentry_telemetry = [ + "dep:sentry", + "dep:sentry-tracing", + "dep:sentry-tower", +] +zstd_compression = [ + "tower-http/compression-zstd", +] +gzip_compression = [ + "tower-http/compression-gzip", +] +brotli_compression = [ + "tower-http/compression-br", +] +systemd = [ + "dep:sd-notify", +] +axum_dual_protocol = [ + "dep:axum-server-dual-protocol" +] + +[dependencies] +axum-server-dual-protocol.optional = true +axum-server-dual-protocol.workspace = true +axum-server.workspace = true +axum.workspace = true +conduit-admin.workspace = true +conduit-api.workspace = true +conduit-core.workspace = true +conduit-database.workspace = true +conduit-service.workspace = true +log.workspace = true +tokio.workspace = true +tower.workspace = true +tracing.workspace = true +bytes.workspace = true +clap.workspace = true +http-body-util.workspace = true +http.workspace = true +regex.workspace = true +ruma.workspace = true +sentry.optional = true +sentry-tower.optional = true +sentry-tower.workspace = true +sentry-tracing.optional = true +sentry-tracing.workspace = true +sentry.workspace = true +serde_json.workspace = true +tower-http.workspace = true + +[target.'cfg(unix)'.dependencies] +sd-notify.workspace = true +sd-notify.optional = true + +[lints] +workspace = true diff --git a/src/router/layers.rs b/src/router/layers.rs new file mode 100644 index 00000000..a6e30e98 --- /dev/null +++ b/src/router/layers.rs @@ -0,0 +1,190 @@ +use std::{any::Any, io, sync::Arc, time::Duration}; + +use axum::{ + extract::{DefaultBodyLimit, MatchedPath}, + Router, +}; +use conduit::Server; +use http::{ + header::{self, HeaderName}, + HeaderValue, Method, StatusCode, +}; +use tower::ServiceBuilder; +use tower_http::{ + catch_panic::CatchPanicLayer, + cors::{self, CorsLayer}, + set_header::SetResponseHeaderLayer, + trace::{DefaultOnFailure, DefaultOnRequest, DefaultOnResponse, TraceLayer}, + ServiceBuilderExt as _, +}; +use tracing::Level; + +use crate::{request, router}; + +pub(crate) fn build(server: &Arc) -> io::Result> { + let layers = ServiceBuilder::new(); + + #[cfg(feature = "sentry_telemetry")] + let layers = layers.layer(sentry_tower::NewSentryLayer::>::new_from_top()); + + #[cfg(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression"))] + let layers = layers.layer(compression_layer(server)); + + let layers = layers + .sensitive_headers([header::AUTHORIZATION]) + .sensitive_request_headers([HeaderName::from_static("x-forwarded-for")].into()) + .layer(axum::middleware::from_fn_with_state(Arc::clone(server), request::spawn)) + .layer( + TraceLayer::new_for_http() + .make_span_with(tracing_span::<_>) + .on_failure(DefaultOnFailure::new().level(Level::ERROR)) + .on_request(DefaultOnRequest::new().level(Level::TRACE)) + .on_response(DefaultOnResponse::new().level(Level::DEBUG)), + ) + .layer(axum::middleware::from_fn_with_state(Arc::clone(server), request::handle)) + .layer(SetResponseHeaderLayer::if_not_present( + HeaderName::from_static("origin-agent-cluster"), // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin-Agent-Cluster + HeaderValue::from_static("?1"), + )) + .layer(SetResponseHeaderLayer::if_not_present( + header::X_CONTENT_TYPE_OPTIONS, + HeaderValue::from_static("nosniff"), + )) + .layer(SetResponseHeaderLayer::if_not_present( + header::X_XSS_PROTECTION, + HeaderValue::from_static("0"), + )) + .layer(SetResponseHeaderLayer::if_not_present( + header::X_FRAME_OPTIONS, + HeaderValue::from_static("DENY"), + )) + .layer(SetResponseHeaderLayer::if_not_present( + HeaderName::from_static("permissions-policy"), + HeaderValue::from_static("interest-cohort=(),browsing-topics=()"), + )) + .layer(SetResponseHeaderLayer::if_not_present( + header::CONTENT_SECURITY_POLICY, + HeaderValue::from_static( + "sandbox; default-src 'none'; font-src 'none'; script-src 'none'; plugin-types application/pdf; \ + style-src 'unsafe-inline'; object-src 'self'; frame-ancesors 'none';", + ), + )) + .layer(cors_layer(server)) + .layer(body_limit_layer(server)) + .layer(CatchPanicLayer::custom(catch_panic)); + + let routes = router::build(server); + let layers = routes.layer(layers); + + Ok(layers.into_make_service()) +} + +#[cfg(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression"))] +fn compression_layer(server: &Server) -> tower_http::compression::CompressionLayer { + let mut compression_layer = tower_http::compression::CompressionLayer::new(); + + #[cfg(feature = "zstd_compression")] + { + if server.config.zstd_compression { + compression_layer = compression_layer.zstd(true); + } else { + compression_layer = compression_layer.no_zstd(); + }; + }; + + #[cfg(feature = "gzip_compression")] + { + if server.config.gzip_compression { + compression_layer = compression_layer.gzip(true); + } else { + compression_layer = compression_layer.no_gzip(); + }; + }; + + #[cfg(feature = "brotli_compression")] + { + if server.config.brotli_compression { + compression_layer = compression_layer.br(true); + } else { + compression_layer = compression_layer.no_br(); + }; + }; + + compression_layer +} + +fn cors_layer(_server: &Server) -> CorsLayer { + const METHODS: [Method; 7] = [ + Method::GET, + Method::HEAD, + Method::PATCH, + Method::POST, + Method::PUT, + Method::DELETE, + Method::OPTIONS, + ]; + + let headers: [HeaderName; 5] = [ + header::ORIGIN, + HeaderName::from_lowercase(b"x-requested-with").unwrap(), + header::CONTENT_TYPE, + header::ACCEPT, + header::AUTHORIZATION, + ]; + + CorsLayer::new() + .allow_origin(cors::Any) + .allow_methods(METHODS) + .allow_headers(headers) + .max_age(Duration::from_secs(86400)) +} + +fn body_limit_layer(server: &Server) -> DefaultBodyLimit { + DefaultBodyLimit::max( + server + .config + .max_request_size + .try_into() + .expect("failed to convert max request size"), + ) +} + +#[allow(clippy::needless_pass_by_value)] +#[tracing::instrument(skip_all)] +fn catch_panic(err: Box) -> http::Response> { + conduit_service::services() + .server + .requests_panic + .fetch_add(1, std::sync::atomic::Ordering::Release); + + let details = if let Some(s) = err.downcast_ref::() { + s.clone() + } else if let Some(s) = err.downcast_ref::<&str>() { + s.to_string() + } else { + "Unknown internal server error occurred.".to_owned() + }; + + let body = serde_json::json!({ + "errcode": "M_UNKNOWN", + "error": "M_UNKNOWN: Internal server error occurred", + "details": details, + }) + .to_string(); + + http::Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .header(header::CONTENT_TYPE, "application/json") + .body(http_body_util::Full::from(body)) + .expect("Failed to create response for our panic catcher?") +} + +fn tracing_span(request: &http::Request) -> tracing::Span { + let path = if let Some(path) = request.extensions().get::() { + path.as_str() + } else { + request.uri().path() + }; + + tracing::info_span!("router:", %path) +} diff --git a/src/router/mod.rs b/src/router/mod.rs index aa928685..6467d5ee 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -1,258 +1,29 @@ -use std::{any::Any, io, sync::atomic, time::Duration}; +pub(crate) mod layers; +pub(crate) mod request; +pub(crate) mod router; +pub(crate) mod run; +pub(crate) mod serve; -use axum::{ - extract::{DefaultBodyLimit, MatchedPath}, - response::IntoResponse, - Router, -}; -use http::{ - header::{self, HeaderName, HeaderValue}, - Method, StatusCode, Uri, -}; -use ruma::api::client::{ - error::{Error as RumaError, ErrorBody, ErrorKind}, - uiaa::UiaaResponse, -}; -use tower::ServiceBuilder; -use tower_http::{ - catch_panic::CatchPanicLayer, - cors::{self, CorsLayer}, - set_header::SetResponseHeaderLayer, - trace::{DefaultOnFailure, DefaultOnRequest, DefaultOnResponse, TraceLayer}, - ServiceBuilderExt as _, -}; -use tracing::{debug, error, trace, Level}; +extern crate conduit_core as conduit; -use super::{api::ruma_wrapper::RumaResponse, debug_error, services, utils::error::Result, Server}; +use std::{future::Future, pin::Pin, sync::Arc}; -mod routes; +use conduit::{Result, Server}; -pub(crate) async fn build(server: &Server) -> io::Result> { - let base_middlewares = ServiceBuilder::new(); - #[cfg(feature = "sentry_telemetry")] - let base_middlewares = base_middlewares.layer(sentry_tower::NewSentryLayer::>::new_from_top()); +conduit::mod_ctor! {} +conduit::mod_dtor! {} - let x_forwarded_for = HeaderName::from_static("x-forwarded-for"); - let permissions_policy = HeaderName::from_static("permissions-policy"); - let origin_agent_cluster = HeaderName::from_static("origin-agent-cluster"); // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin-Agent-Cluster - - let middlewares = base_middlewares - .sensitive_headers([header::AUTHORIZATION]) - .sensitive_request_headers([x_forwarded_for].into()) - .layer(axum::middleware::from_fn(request_spawn)) - .layer( - TraceLayer::new_for_http() - .make_span_with(tracing_span::<_>) - .on_failure(DefaultOnFailure::new().level(Level::ERROR)) - .on_request(DefaultOnRequest::new().level(Level::TRACE)) - .on_response(DefaultOnResponse::new().level(Level::DEBUG)), - ) - .layer(axum::middleware::from_fn(request_handle)) - .layer(SetResponseHeaderLayer::if_not_present( - origin_agent_cluster, - HeaderValue::from_static("?1"), - )) - .layer(SetResponseHeaderLayer::if_not_present( - header::X_CONTENT_TYPE_OPTIONS, - HeaderValue::from_static("nosniff"), - )) - .layer(SetResponseHeaderLayer::if_not_present( - header::X_XSS_PROTECTION, - HeaderValue::from_static("0"), - )) - .layer(SetResponseHeaderLayer::if_not_present( - header::X_FRAME_OPTIONS, - HeaderValue::from_static("DENY"), - )) - .layer(SetResponseHeaderLayer::if_not_present( - permissions_policy, - HeaderValue::from_static("interest-cohort=(),browsing-topics=()"), - )) - .layer(SetResponseHeaderLayer::if_not_present( - header::CONTENT_SECURITY_POLICY, - HeaderValue::from_static( - "sandbox; default-src 'none'; font-src 'none'; script-src 'none'; plugin-types application/pdf; \ - style-src 'unsafe-inline'; object-src 'self'; frame-ancesors 'none';", - ), - )) - .layer(cors_layer(server)) - .layer(DefaultBodyLimit::max( - server - .config - .max_request_size - .try_into() - .expect("failed to convert max request size"), - )) - .layer(CatchPanicLayer::custom(catch_panic_layer)); - - #[cfg(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression"))] - { - Ok(routes::routes(&server.config) - .layer(compression_layer(server)) - .layer(middlewares) - .into_make_service()) - } - #[cfg(not(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression")))] - { - Ok(routes::routes().layer(middlewares).into_make_service()) - } +#[no_mangle] +pub extern "Rust" fn start(server: &Arc) -> Pin>>> { + Box::pin(run::start(server.clone())) } -#[tracing::instrument(skip_all, name = "spawn")] -async fn request_spawn( - req: http::Request, next: axum::middleware::Next, -) -> Result { - if services().globals.shutdown.load(atomic::Ordering::Relaxed) { - return Err(StatusCode::SERVICE_UNAVAILABLE); - } - - let fut = next.run(req); - let task = tokio::spawn(fut); - task.await.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) +#[no_mangle] +pub extern "Rust" fn stop(server: &Arc) -> Pin>>> { + Box::pin(run::stop(server.clone())) } -#[tracing::instrument(skip_all, name = "handle")] -async fn request_handle( - req: http::Request, next: axum::middleware::Next, -) -> Result { - let method = req.method().clone(); - let uri = req.uri().clone(); - let result = next.run(req).await; - request_result(&method, &uri, result) -} - -fn request_result( - method: &Method, uri: &Uri, result: axum::response::Response, -) -> Result { - request_result_log(method, uri, &result); - match result.status() { - StatusCode::METHOD_NOT_ALLOWED => request_result_403(method, uri, &result), - _ => Ok(result), - } -} - -#[allow(clippy::unnecessary_wraps)] -fn request_result_403( - _method: &Method, _uri: &Uri, result: &axum::response::Response, -) -> Result { - let error = UiaaResponse::MatrixError(RumaError { - status_code: result.status(), - body: ErrorBody::Standard { - kind: ErrorKind::Unrecognized, - message: "M_UNRECOGNIZED: Method not allowed for endpoint".to_owned(), - }, - }); - - Ok(RumaResponse(error).into_response()) -} - -fn request_result_log(method: &Method, uri: &Uri, result: &axum::response::Response) { - let status = result.status(); - let reason = status.canonical_reason().unwrap_or("Unknown Reason"); - let code = status.as_u16(); - if status.is_server_error() { - error!(method = ?method, uri = ?uri, "{code} {reason}"); - } else if status.is_client_error() { - debug_error!(method = ?method, uri = ?uri, "{code} {reason}"); - } else if status.is_redirection() { - debug!(method = ?method, uri = ?uri, "{code} {reason}"); - } else { - trace!(method = ?method, uri = ?uri, "{code} {reason}"); - } -} - -/// Cross-Origin-Resource-Sharing header as defined by spec: -/// -fn cors_layer(_server: &Server) -> CorsLayer { - const METHODS: [Method; 7] = [ - Method::GET, - Method::HEAD, - Method::PATCH, - Method::POST, - Method::PUT, - Method::DELETE, - Method::OPTIONS, - ]; - - let headers: [HeaderName; 5] = [ - header::ORIGIN, - HeaderName::from_lowercase(b"x-requested-with").unwrap(), - header::CONTENT_TYPE, - header::ACCEPT, - header::AUTHORIZATION, - ]; - - CorsLayer::new() - .allow_origin(cors::Any) - .allow_methods(METHODS) - .allow_headers(headers) - .max_age(Duration::from_secs(86400)) -} - -#[cfg(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression"))] -fn compression_layer(server: &Server) -> tower_http::compression::CompressionLayer { - let mut compression_layer = tower_http::compression::CompressionLayer::new(); - - #[cfg(feature = "zstd_compression")] - { - if server.config.zstd_compression { - compression_layer = compression_layer.zstd(true); - } else { - compression_layer = compression_layer.no_zstd(); - }; - }; - - #[cfg(feature = "gzip_compression")] - { - if server.config.gzip_compression { - compression_layer = compression_layer.gzip(true); - } else { - compression_layer = compression_layer.no_gzip(); - }; - }; - - #[cfg(feature = "brotli_compression")] - { - if server.config.brotli_compression { - compression_layer = compression_layer.br(true); - } else { - compression_layer = compression_layer.no_br(); - }; - }; - - compression_layer -} - -fn tracing_span(request: &http::Request) -> tracing::Span { - let path = if let Some(path) = request.extensions().get::() { - path.as_str() - } else { - request.uri().path() - }; - - tracing::info_span!("router:", %path) -} - -#[allow(clippy::needless_pass_by_value)] -fn catch_panic_layer(err: Box) -> http::Response> { - let details = if let Some(s) = err.downcast_ref::() { - s.clone() - } else if let Some(s) = err.downcast_ref::<&str>() { - s.to_string() - } else { - "Unknown internal server error occurred.".to_owned() - }; - - let body = serde_json::json!({ - "errcode": "M_UNKNOWN", - "error": "M_UNKNOWN: Internal server error occurred", - "details": details, - }) - .to_string(); - - http::Response::builder() - .status(StatusCode::INTERNAL_SERVER_ERROR) - .header(header::CONTENT_TYPE, "application/json") - .body(http_body_util::Full::from(body)) - .expect("Failed to create response for our panic catcher?") +#[no_mangle] +pub extern "Rust" fn run(server: &Arc) -> Pin>>> { + Box::pin(run::run(server.clone())) } diff --git a/src/router/request.rs b/src/router/request.rs new file mode 100644 index 00000000..25bdd98e --- /dev/null +++ b/src/router/request.rs @@ -0,0 +1,102 @@ +use std::sync::{atomic::Ordering, Arc}; + +use axum::{extract::State, response::IntoResponse}; +use conduit::{debug_error, debug_warn, defer, Result, RumaResponse, Server}; +use http::{Method, StatusCode, Uri}; +use ruma::api::client::{ + error::{Error as RumaError, ErrorBody, ErrorKind}, + uiaa::UiaaResponse, +}; +use tracing::{debug, error, trace}; + +#[tracing::instrument(skip_all)] +pub(crate) async fn spawn( + State(server): State>, req: http::Request, next: axum::middleware::Next, +) -> Result { + if server.interrupt.load(Ordering::Relaxed) { + debug_warn!("unavailable pending shutdown"); + return Err(StatusCode::SERVICE_UNAVAILABLE); + } + + let active = server.requests_spawn_active.fetch_add(1, Ordering::Relaxed); + trace!(active, "enter"); + defer! {{ + let active = server.requests_spawn_active.fetch_sub(1, Ordering::Relaxed); + let finished = server.requests_spawn_finished.fetch_add(1, Ordering::Relaxed); + trace!(active, finished, "leave"); + }}; + + let fut = next.run(req); + let task = server.runtime().spawn(fut); + task.await.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) +} + +#[tracing::instrument(skip_all, name = "handle")] +pub(crate) async fn handle( + State(server): State>, req: http::Request, next: axum::middleware::Next, +) -> Result { + if server.interrupt.load(Ordering::Relaxed) { + debug_warn!( + method = %req.method(), + uri = %req.uri(), + "unavailable pending shutdown" + ); + + return Err(StatusCode::SERVICE_UNAVAILABLE); + } + + let active = server + .requests_handle_active + .fetch_add(1, Ordering::Relaxed); + trace!(active, "enter"); + defer! {{ + let active = server.requests_handle_active.fetch_sub(1, Ordering::Relaxed); + let finished = server.requests_handle_finished.fetch_add(1, Ordering::Relaxed); + trace!(active, finished, "leave"); + }}; + + let method = req.method().clone(); + let uri = req.uri().clone(); + let result = next.run(req).await; + handle_result(&method, &uri, result) +} + +fn handle_result( + method: &Method, uri: &Uri, result: axum::response::Response, +) -> Result { + handle_result_log(method, uri, &result); + match result.status() { + StatusCode::METHOD_NOT_ALLOWED => handle_result_403(method, uri, &result), + _ => Ok(result), + } +} + +#[allow(clippy::unnecessary_wraps)] +fn handle_result_403( + _method: &Method, _uri: &Uri, result: &axum::response::Response, +) -> Result { + let error = UiaaResponse::MatrixError(RumaError { + status_code: result.status(), + body: ErrorBody::Standard { + kind: ErrorKind::Unrecognized, + message: "M_UNRECOGNIZED: Method not allowed for endpoint".to_owned(), + }, + }); + + Ok(RumaResponse(error).into_response()) +} + +fn handle_result_log(method: &Method, uri: &Uri, result: &axum::response::Response) { + let status = result.status(); + let reason = status.canonical_reason().unwrap_or("Unknown Reason"); + let code = status.as_u16(); + if status.is_server_error() { + error!(method = ?method, uri = ?uri, "{code} {reason}"); + } else if status.is_client_error() { + debug_error!(method = ?method, uri = ?uri, "{code} {reason}"); + } else if status.is_redirection() { + debug!(method = ?method, uri = ?uri, "{code} {reason}"); + } else { + trace!(method = ?method, uri = ?uri, "{code} {reason}"); + } +} diff --git a/src/router/router.rs b/src/router/router.rs new file mode 100644 index 00000000..4f45df54 --- /dev/null +++ b/src/router/router.rs @@ -0,0 +1,20 @@ +use std::sync::Arc; + +use axum::{response::IntoResponse, routing::get, Router}; +use conduit::{Error, Server}; +use http::Uri; +use ruma::api::client::error::ErrorKind; + +extern crate conduit_api as api; + +pub(crate) fn build(server: &Arc) -> Router { + let router = Router::new().fallback(not_found).route("/", get(it_works)); + + api::router::build(router, server) +} + +async fn not_found(_uri: Uri) -> impl IntoResponse { + Error::BadRequest(ErrorKind::Unrecognized, "Unrecognized request") +} + +async fn it_works() -> &'static str { "hewwo from conduwuit woof!" } diff --git a/src/router/run.rs b/src/router/run.rs new file mode 100644 index 00000000..ee75ffec --- /dev/null +++ b/src/router/run.rs @@ -0,0 +1,185 @@ +use std::{sync::Arc, time::Duration}; + +use axum_server::Handle as ServerHandle; +use tokio::{ + signal, + sync::oneshot::{self, Sender}, +}; +use tracing::{debug, info, warn}; + +extern crate conduit_admin as admin; +extern crate conduit_core as conduit; +extern crate conduit_database as database; +extern crate conduit_service as service; + +use std::sync::atomic::Ordering; + +use conduit::{debug_info, trace, Error, Result, Server}; +use database::KeyValueDatabase; +use service::{services, Services}; + +use crate::{layers, serve}; + +/// Main loop base +#[tracing::instrument(skip_all)] +pub(crate) async fn run(server: Arc) -> Result<(), Error> { + let config = &server.config; + let app = layers::build(&server)?; + let addrs = config.get_bind_addrs(); + + // Install the admin room callback here for now + _ = services().admin.handle.lock().await.insert(admin::handle); + + // Setup shutdown/signal handling + let handle = ServerHandle::new(); + _ = server + .shutdown + .lock() + .expect("locked") + .insert(handle.clone()); + + server.interrupt.store(false, Ordering::Release); + let (tx, rx) = oneshot::channel::<()>(); + let sigs = server.runtime().spawn(sighandle(server.clone(), tx)); + + // Prepare to serve http clients + let res; + // Serve clients + if cfg!(unix) && config.unix_socket_path.is_some() { + res = serve::unix_socket(&server, app, rx).await; + } else if config.tls.is_some() { + res = serve::tls(&server, app, handle.clone(), addrs).await; + } else { + res = serve::plain(&server, app, handle.clone(), addrs).await; + } + + // Join the signal handler before we leave. + sigs.abort(); + _ = sigs.await; + + // Reset the axum handle instance; this should be reusable and might be + // reload-survivable but better to be safe than sorry. + _ = server.shutdown.lock().expect("locked").take(); + + // Remove the admin room callback + _ = services().admin.handle.lock().await.take(); + + debug_info!("Finished"); + Ok(res?) +} + +/// Async initializations +#[tracing::instrument(skip_all)] +pub(crate) async fn start(server: Arc) -> Result<(), Error> { + debug!("Starting..."); + let d = Arc::new(KeyValueDatabase::load_or_create(&server).await?); + let s = Box::new(Services::build(server, d.clone()).await?); + _ = service::SERVICES + .write() + .expect("write locked") + .insert(Box::leak(s)); + services().start().await?; + + #[cfg(feature = "systemd")] + #[allow(clippy::let_underscore_untyped)] // error[E0658]: attributes on expressions are experimental + let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Ready]); + + debug!("Started"); + Ok(()) +} + +/// Async destructions +#[tracing::instrument(skip_all)] +pub(crate) async fn stop(_server: Arc) -> Result<(), Error> { + debug!("Shutting down..."); + + // Wait for all completions before dropping or we'll lose them to the module + // unload and explode. + services().shutdown().await; + + // Deactivate services(). Any further use will panic the caller. + let s = service::SERVICES + .write() + .expect("write locked") + .take() + .unwrap(); + + let s = std::ptr::from_ref(s) as *mut Services; + //SAFETY: Services was instantiated in start() and leaked into the SERVICES + // global perusing as 'static for the duration of run_server(). Now we reclaim + // it to drop it before unloading the module. If this is not done there will be + // multiple instances after module reload. + let s = unsafe { Box::from_raw(s) }; + debug!("Cleaning up..."); + // Drop it so we encounter any trouble before the infolog message + drop(s); + + #[cfg(feature = "systemd")] + #[allow(clippy::let_underscore_untyped)] // error[E0658]: attributes on expressions are experimental + let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Stopping]); + + info!("Shutdown complete."); + Ok(()) +} + +#[tracing::instrument(skip_all)] +async fn sighandle(server: Arc, tx: Sender<()>) -> Result<(), Error> { + let ctrl_c = async { + signal::ctrl_c() + .await + .expect("failed to install Ctrl+C handler"); + + let reload = cfg!(unix) && cfg!(debug_assertions); + server.reload.store(reload, Ordering::Release); + }; + + #[cfg(unix)] + let ctrl_bs = async { + signal::unix::signal(signal::unix::SignalKind::quit()) + .expect("failed to install Ctrl+\\ handler") + .recv() + .await; + }; + + #[cfg(unix)] + let terminate = async { + signal::unix::signal(signal::unix::SignalKind::terminate()) + .expect("failed to install SIGTERM handler") + .recv() + .await; + }; + + debug!("Installed signal handlers"); + let sig: &str; + #[cfg(unix)] + tokio::select! { + () = ctrl_c => { sig = "Ctrl+C"; }, + () = ctrl_bs => { sig = "Ctrl+\\"; }, + () = terminate => { sig = "SIGTERM"; }, + } + + #[cfg(not(unix))] + tokio::select! { + _ = ctrl_c => { sig = "Ctrl+C"; }, + } + + warn!("Received {}", sig); + server.interrupt.store(true, Ordering::Release); + services().globals.rotate.fire(); + tx.send(()) + .expect("failed sending shutdown transaction to oneshot channel"); + + if let Some(handle) = server.shutdown.lock().expect("locked").as_ref() { + let pending = server.requests_spawn_active.load(Ordering::Relaxed); + if pending > 0 { + let timeout = Duration::from_secs(36); + trace!(pending, ?timeout, "Notifying for graceful shutdown"); + handle.graceful_shutdown(Some(timeout)); + } else { + debug!(pending, "Notifying for immediate shutdown"); + handle.shutdown(); + } + } + + Ok(()) +} diff --git a/src/router/serve.rs b/src/router/serve.rs new file mode 100644 index 00000000..37ed9902 --- /dev/null +++ b/src/router/serve.rs @@ -0,0 +1,137 @@ +#[cfg(unix)] +use std::fs::Permissions; // only for UNIX sockets stuff and *nix container checks +#[cfg(unix)] +use std::os::unix::fs::PermissionsExt as _; +use std::{ + io, + net::SocketAddr, + sync::{atomic::Ordering, Arc}, +}; + +use axum::Router; +use axum_server::{bind, bind_rustls, tls_rustls::RustlsConfig, Handle as ServerHandle}; +#[cfg(feature = "axum_dual_protocol")] +use axum_server_dual_protocol::ServerExt; +use conduit::{debug_info, Server}; +use tokio::{ + sync::oneshot::{self}, + task::JoinSet, +}; +use tracing::{debug, info, warn}; + +pub(crate) async fn plain( + server: &Arc, app: axum::routing::IntoMakeService, handle: ServerHandle, addrs: Vec, +) -> io::Result<()> { + let mut join_set = JoinSet::new(); + for addr in &addrs { + join_set.spawn_on(bind(*addr).handle(handle.clone()).serve(app.clone()), server.runtime()); + } + + info!("Listening on {addrs:?}"); + while join_set.join_next().await.is_some() {} + + let spawn_active = server.requests_spawn_active.load(Ordering::Relaxed); + let handle_active = server.requests_handle_active.load(Ordering::Relaxed); + debug_info!( + spawn_finished = server.requests_spawn_finished.load(Ordering::Relaxed), + handle_finished = server.requests_handle_finished.load(Ordering::Relaxed), + panics = server.requests_panic.load(Ordering::Relaxed), + spawn_active, + handle_active, + "Stopped listening on {addrs:?}", + ); + + debug_assert!(spawn_active == 0, "active request tasks are not joined"); + debug_assert!(handle_active == 0, "active request handles still pending"); + + Ok(()) +} + +pub(crate) async fn tls( + server: &Arc, app: axum::routing::IntoMakeService, handle: ServerHandle, addrs: Vec, +) -> io::Result<()> { + let config = &server.config; + let tls = config.tls.as_ref().expect("TLS configuration"); + + debug!( + "Using direct TLS. Certificate path {} and certificate private key path {}", + &tls.certs, &tls.key + ); + info!( + "Note: It is strongly recommended that you use a reverse proxy instead of running conduwuit directly with TLS." + ); + let conf = RustlsConfig::from_pem_file(&tls.certs, &tls.key).await?; + + if cfg!(feature = "axum_dual_protocol") { + info!( + "conduwuit was built with axum_dual_protocol feature to listen on both HTTP and HTTPS. This will only \ + take effect if `dual_protocol` is enabled in `[global.tls]`" + ); + } + + let mut join_set = JoinSet::new(); + if cfg!(feature = "axum_dual_protocol") && tls.dual_protocol { + #[cfg(feature = "axum_dual_protocol")] + for addr in &addrs { + join_set.spawn_on( + axum_server_dual_protocol::bind_dual_protocol(*addr, conf.clone()) + .set_upgrade(false) + .handle(handle.clone()) + .serve(app.clone()), + server.runtime(), + ); + } + } else { + for addr in &addrs { + join_set.spawn_on( + bind_rustls(*addr, conf.clone()) + .handle(handle.clone()) + .serve(app.clone()), + server.runtime(), + ); + } + } + + if cfg!(feature = "axum_dual_protocol") && tls.dual_protocol { + warn!( + "Listening on {:?} with TLS certificate {} and supporting plain text (HTTP) connections too (insecure!)", + addrs, &tls.certs + ); + } else { + info!("Listening on {:?} with TLS certificate {}", addrs, &tls.certs); + } + + while join_set.join_next().await.is_some() {} + + Ok(()) +} + +#[cfg(unix)] +#[allow(unused_variables)] +pub(crate) async fn unix_socket( + server: &Arc, app: axum::routing::IntoMakeService, rx: oneshot::Receiver<()>, +) -> io::Result<()> { + let config = &server.config; + let path = config.unix_socket_path.as_ref().unwrap(); + + if path.exists() { + warn!( + "UNIX socket path {:#?} already exists (unclean shutdown?), attempting to remove it.", + path.display() + ); + tokio::fs::remove_file(&path).await?; + } + + tokio::fs::create_dir_all(path.parent().unwrap()).await?; + + let socket_perms = config.unix_socket_perms.to_string(); + let octal_perms = u32::from_str_radix(&socket_perms, 8).unwrap(); + tokio::fs::set_permissions(&path, Permissions::from_mode(octal_perms)) + .await + .unwrap(); + + let bind = tokio::net::UnixListener::bind(path)?; + info!("Listening at {:?}", path); + + Ok(()) +} diff --git a/src/service/Cargo.toml b/src/service/Cargo.toml new file mode 100644 index 00000000..580706ff --- /dev/null +++ b/src/service/Cargo.toml @@ -0,0 +1,115 @@ +[package] +name = "conduit_service" +version.workspace = true +edition.workspace = true + +[lib] +path = "mod.rs" +crate-type = [ + "rlib", +# "dylib", +] + +[features] +default = [ + "rocksdb", + "io_uring", + "jemalloc", + "gzip_compression", + "zstd_compression", + "brotli_compression", + "release_max_log_level", +] + +dev_release_log_level = [] +release_max_log_level = [ + "tracing/max_level_trace", + "tracing/release_max_level_info", + "log/max_level_trace", + "log/release_max_level_info", +] +sqlite = [ + "dep:rusqlite", + "dep:parking_lot", + "dep:thread_local", +] +rocksdb = [ + "dep:rust-rocksdb", +] +jemalloc = [ + "dep:tikv-jemalloc-sys", + "dep:tikv-jemalloc-ctl", + "dep:tikv-jemallocator", + "rust-rocksdb/jemalloc", +] +io_uring = [ + "rust-rocksdb/io-uring", +] +zstd_compression = [ + "rust-rocksdb/zstd", +] +gzip_compression = [ + "reqwest/gzip", +] +brotli_compression = [ + "reqwest/brotli", +] +sha256_media = [ + "dep:sha2", +] + +[dependencies] +argon2.workspace = true +async-trait.workspace = true +base64.workspace = true +bytes.workspace = true +clap.workspace = true +conduit-core.workspace = true +conduit-database.workspace = true +cyborgtime.workspace = true +futures-util.workspace = true +hickory-resolver.workspace = true +hmac.workspace = true +http.workspace = true +image.workspace = true +ipaddress.workspace = true +itertools.workspace = true +jsonwebtoken.workspace = true +log.workspace = true +loole.workspace = true +lru-cache.workspace = true +parking_lot.optional = true +parking_lot.workspace = true +rand.workspace = true +regex.workspace = true +reqwest.workspace = true +ruma-identifiers-validation.workspace = true +ruma.workspace = true +rusqlite.optional = true +rusqlite.workspace = true +rust-rocksdb.optional = true +rust-rocksdb.workspace = true +serde_json.workspace = true +serde.workspace = true +serde_yaml.workspace = true +sha-1.workspace = true +sha2.optional = true +sha2.workspace = true +thread_local.optional = true +thread_local.workspace = true +tikv-jemallocator.optional = true +tikv-jemallocator.workspace = true +tikv-jemalloc-ctl.optional = true +tikv-jemalloc-ctl.workspace = true +tikv-jemalloc-sys.optional = true +tikv-jemalloc-sys.workspace = true +tokio.workspace = true +tracing-subscriber.workspace = true +tracing.workspace = true +url.workspace = true +webpage.workspace = true +zstd.optional = true +zstd.workspace = true + +[lints] +workspace = true diff --git a/src/service/account_data/data.rs b/src/service/account_data/data.rs index b538ef76..492c500c 100644 --- a/src/service/account_data/data.rs +++ b/src/service/account_data/data.rs @@ -8,7 +8,7 @@ use ruma::{ use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { /// Places one event in the account data of the user and removes the /// previous entry. fn update( diff --git a/src/service/account_data/mod.rs b/src/service/account_data/mod.rs index e8de80e6..7e17e145 100644 --- a/src/service/account_data/mod.rs +++ b/src/service/account_data/mod.rs @@ -1,8 +1,8 @@ mod data; -use std::collections::HashMap; +use std::{collections::HashMap, sync::Arc}; -pub(crate) use data::Data; +pub use data::Data; use ruma::{ events::{AnyEphemeralRoomEvent, RoomAccountDataEventType}, serde::Raw, @@ -11,15 +11,15 @@ use ruma::{ use crate::Result; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { /// Places one event in the account data of the user and removes the /// previous entry. #[tracing::instrument(skip(self, room_id, user_id, event_type, data))] - pub(crate) fn update( + pub fn update( &self, room_id: Option<&RoomId>, user_id: &UserId, event_type: RoomAccountDataEventType, data: &serde_json::Value, ) -> Result<()> { @@ -28,7 +28,7 @@ impl Service { /// Searches the account data for a specific kind. #[tracing::instrument(skip(self, room_id, user_id, event_type))] - pub(crate) fn get( + pub fn get( &self, room_id: Option<&RoomId>, user_id: &UserId, event_type: RoomAccountDataEventType, ) -> Result>> { self.db.get(room_id, user_id, event_type) @@ -36,7 +36,7 @@ impl Service { /// Returns all changes to the account data that happened after `since`. #[tracing::instrument(skip(self, room_id, user_id, since))] - pub(crate) fn changes_since( + pub fn changes_since( &self, room_id: Option<&RoomId>, user_id: &UserId, since: u64, ) -> Result>> { self.db.changes_since(room_id, user_id, since) diff --git a/src/service/admin/mod.rs b/src/service/admin.rs similarity index 51% rename from src/service/admin/mod.rs rename to src/service/admin.rs index 8907869e..b44c9d0c 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin.rs @@ -1,11 +1,9 @@ -use std::{collections::BTreeMap, sync::Arc}; +use std::{collections::BTreeMap, future::Future, pin::Pin, sync::Arc}; -use clap::Parser; -use regex::Regex; +use conduit::{Error, Result}; use ruma::{ api::client::error::ErrorKind, events::{ - relation::InReplyTo, room::{ canonical_alias::RoomCanonicalAliasEventContent, create::RoomCreateEventContent, @@ -13,133 +11,62 @@ use ruma::{ history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent}, join_rules::{JoinRule, RoomJoinRulesEventContent}, member::{MembershipState, RoomMemberEventContent}, - message::{Relation::Reply, RoomMessageEventContent}, + message::RoomMessageEventContent, name::RoomNameEventContent, power_levels::RoomPowerLevelsEventContent, topic::RoomTopicEventContent, }, TimelineEventType, }, - EventId, MxcUri, OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId, + EventId, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, RoomVersionId, UserId, }; use serde_json::value::to_raw_value; -use tokio::sync::{Mutex, MutexGuard}; +use tokio::{sync::Mutex, task::JoinHandle}; use tracing::{error, warn}; -use self::{fsck::FsckCommand, tester::TesterCommands}; -use super::pdu::PduBuilder; -use crate::{ - service::admin::{ - appservice::AppserviceCommand, debug::DebugCommand, federation::FederationCommand, media::MediaCommand, - query::QueryCommand, room::RoomCommand, server::ServerCommand, user::UserCommand, - }, - services, Error, Result, -}; +use crate::{pdu::PduBuilder, services}; -pub(crate) mod appservice; -pub(crate) mod debug; -pub(crate) mod federation; -pub(crate) mod fsck; -pub(crate) mod media; -pub(crate) mod query; -pub(crate) mod room; -pub(crate) mod server; -pub(crate) mod tester; -pub(crate) mod user; +pub type HandlerResult = Pin> + Send>>; +pub type Handler = fn(AdminRoomEvent, OwnedRoomId, OwnedUserId) -> HandlerResult; -const PAGE_SIZE: usize = 100; - -#[cfg_attr(test, derive(Debug))] -#[derive(Parser)] -#[command(name = "@conduit:server.name:", version = env!("CARGO_PKG_VERSION"))] -enum AdminCommand { - #[command(subcommand)] - /// - Commands for managing appservices - Appservices(AppserviceCommand), - - #[command(subcommand)] - /// - Commands for managing local users - Users(UserCommand), - - #[command(subcommand)] - /// - Commands for managing rooms - Rooms(RoomCommand), - - #[command(subcommand)] - /// - Commands for managing federation - Federation(FederationCommand), - - #[command(subcommand)] - /// - Commands for managing the server - Server(ServerCommand), - - #[command(subcommand)] - /// - Commands for managing media - Media(MediaCommand), - - #[command(subcommand)] - /// - Commands for debugging things - Debug(DebugCommand), - - #[command(subcommand)] - /// - Query all the database getters and iterators - Query(QueryCommand), - - #[command(subcommand)] - /// - Query all the database getters and iterators - Fsck(FsckCommand), - - #[command(subcommand)] - Tester(TesterCommands), +pub struct Service { + sender: loole::Sender, + receiver: Mutex>, + handler_join: Mutex>>, + pub handle: Mutex>, } #[derive(Debug)] -pub(crate) enum AdminRoomEvent { +pub enum AdminRoomEvent { ProcessMessage(String, Arc), SendMessage(RoomMessageEventContent), } -pub(crate) struct Service { - pub(crate) sender: loole::Sender, - receiver: Mutex>, -} - impl Service { - pub(crate) fn build() -> Arc { + #[must_use] + pub fn build() -> Arc { let (sender, receiver) = loole::unbounded(); Arc::new(Self { sender, receiver: Mutex::new(receiver), + handler_join: Mutex::new(None), + handle: Mutex::new(None), }) } - pub(crate) fn start_handler(self: &Arc) { - let self2 = Arc::clone(self); - tokio::spawn(async move { - self2 + pub async fn start_handler(self: &Arc) { + let self_ = Arc::clone(self); + let handle = services().server.runtime().spawn(async move { + self_ .handler() .await .expect("Failed to initialize admin room handler"); }); + + _ = self.handler_join.lock().await.insert(handle); } - pub(crate) async fn process_message(&self, room_message: String, event_id: Arc) { - self.send(AdminRoomEvent::ProcessMessage(room_message, event_id)) - .await; - } - - pub(crate) async fn send_message(&self, message_content: RoomMessageEventContent) { - self.send(AdminRoomEvent::SendMessage(message_content)) - .await; - } - - async fn send(&self, message: AdminRoomEvent) { - debug_assert!(!self.sender.is_full(), "channel full"); - debug_assert!(!self.sender.is_closed(), "channel closed"); - self.sender.send(message).expect("message sent"); - } - - async fn handler(&self) -> Result<()> { + async fn handler(self: &Arc) -> Result<()> { let receiver = self.receiver.lock().await; let Ok(Some(admin_room)) = Self::get_admin_room().await else { return Ok(()); @@ -151,246 +78,72 @@ impl Service { debug_assert!(!receiver.is_closed(), "channel closed"); tokio::select! { event = receiver.recv_async() => match event { - Ok(event) => self.handle_event(event, &admin_room, &server_user).await?, - Err(e) => error!("Failed to receive admin room event from channel: {e}"), + Ok(event) => self.receive(event, &admin_room, &server_user).await?, + Err(_e) => return Ok(()), } } } } - async fn handle_event(&self, event: AdminRoomEvent, admin_room: &OwnedRoomId, server_user: &UserId) -> Result<()> { - let (mut message_content, reply) = match event { - AdminRoomEvent::SendMessage(content) => (content, None), - AdminRoomEvent::ProcessMessage(room_message, reply_id) => { - (self.process_admin_message(room_message).await, Some(reply_id)) - }, - }; - - let mutex_state = Arc::clone( - services() - .globals - .roomid_mutex_state - .write() - .await - .entry(admin_room.clone()) - .or_default(), - ); - let state_lock = mutex_state.lock().await; - - if let Some(reply) = reply { - message_content.relates_to = Some(Reply { - in_reply_to: InReplyTo { - event_id: reply.into(), - }, - }); + pub async fn close(&self) { + self.interrupt(); + if let Some(handler_join) = self.handler_join.lock().await.take() { + if let Err(e) = handler_join.await { + error!("Failed to shutdown: {e:?}"); + } } - - let response_pdu = PduBuilder { - event_type: TimelineEventType::RoomMessage, - content: to_raw_value(&message_content).expect("event is valid, we just created it"), - unsigned: None, - state_key: None, - redacts: None, - }; - - if let Err(e) = services() - .rooms - .timeline - .build_and_append_pdu(response_pdu, server_user, admin_room, &state_lock) - .await - { - self.handle_response_error(&e, admin_room, server_user, &state_lock) - .await?; - } - - Ok(()) } - async fn handle_response_error( - &self, e: &Error, admin_room: &OwnedRoomId, server_user: &UserId, state_lock: &MutexGuard<'_, ()>, - ) -> Result<()> { - error!("Failed to build and append admin room response PDU: \"{e}\""); - let error_room_message = RoomMessageEventContent::text_plain(format!( - "Failed to build and append admin room PDU: \"{e}\"\n\nThe original admin command may have finished \ - successfully, but we could not return the output." - )); + pub fn interrupt(&self) { + if !self.sender.is_closed() { + self.sender.close(); + } + } - let response_pdu = PduBuilder { - event_type: TimelineEventType::RoomMessage, - content: to_raw_value(&error_room_message).expect("event is valid, we just created it"), - unsigned: None, - state_key: None, - redacts: None, - }; + pub async fn send_message(&self, message_content: RoomMessageEventContent) { + self.send(AdminRoomEvent::SendMessage(message_content)) + .await; + } + + pub async fn process_message(&self, room_message: String, event_id: Arc) { + self.send(AdminRoomEvent::ProcessMessage(room_message, event_id)) + .await; + } + + async fn receive(&self, event: AdminRoomEvent, room: &OwnedRoomId, user: &UserId) -> Result<(), Error> { + if let Some(handle) = self.handle.lock().await.as_ref() { + handle(event, room.clone(), user.into()).await + } else { + Err(Error::Err("Admin module is not loaded.".into())) + } + } + + async fn send(&self, message: AdminRoomEvent) { + debug_assert!(!self.sender.is_full(), "channel full"); + debug_assert!(!self.sender.is_closed(), "channel closed"); + self.sender.send(message).expect("message sent"); + } + + /// Gets the room ID of the admin room + /// + /// Errors are propagated from the database, and will have None if there is + /// no admin room + pub async fn get_admin_room() -> Result> { + let admin_room_alias: Box = format!("#admins:{}", services().globals.server_name()) + .try_into() + .expect("#admins:server_name is a valid alias name"); services() .rooms - .timeline - .build_and_append_pdu(response_pdu, server_user, admin_room, state_lock) - .await?; - - Ok(()) - } - - // Parse and process a message from the admin room - async fn process_admin_message(&self, room_message: String) -> RoomMessageEventContent { - let mut lines = room_message.lines().filter(|l| !l.trim().is_empty()); - let command_line = lines.next().expect("each string has at least one line"); - let body = lines.collect::>(); - - let admin_command = match self.parse_admin_command(command_line) { - Ok(command) => command, - Err(error) => { - let server_name = services().globals.server_name(); - let message = error.replace("server.name", server_name.as_str()); - let html_message = self.usage_to_html(&message, server_name); - - return RoomMessageEventContent::text_html(message, html_message); - }, - }; - - match self.process_admin_command(admin_command, body).await { - Ok(reply_message) => reply_message, - Err(error) => { - let markdown_message = format!("Encountered an error while handling the command:\n```\n{error}\n```",); - let html_message = format!("Encountered an error while handling the command:\n
\n{error}\n
",); - - RoomMessageEventContent::text_html(markdown_message, html_message) - }, - } - } - - // Parse chat messages from the admin room into an AdminCommand object - fn parse_admin_command(&self, command_line: &str) -> Result { - // Note: argv[0] is `@conduit:servername:`, which is treated as the main command - let mut argv = command_line.split_whitespace().collect::>(); - - // Replace `help command` with `command --help` - // Clap has a help subcommand, but it omits the long help description. - if argv.len() > 1 && argv[1] == "help" { - argv.remove(1); - argv.push("--help"); - } - - // Backwards compatibility with `register_appservice`-style commands - let command_with_dashes_argv1; - if argv.len() > 1 && argv[1].contains('_') { - command_with_dashes_argv1 = argv[1].replace('_', "-"); - argv[1] = &command_with_dashes_argv1; - } - - // Backwards compatibility with `register_appservice`-style commands - let command_with_dashes_argv2; - if argv.len() > 2 && argv[2].contains('_') { - command_with_dashes_argv2 = argv[2].replace('_', "-"); - argv[2] = &command_with_dashes_argv2; - } - - // if the user is using the `query` command (argv[1]), replace the database - // function/table calls with underscores to match the codebase - let command_with_dashes_argv3; - if argv.len() > 3 && argv[1].eq("query") { - command_with_dashes_argv3 = argv[3].replace('_', "-"); - argv[3] = &command_with_dashes_argv3; - } - - AdminCommand::try_parse_from(argv).map_err(|error| error.to_string()) - } - - async fn process_admin_command(&self, command: AdminCommand, body: Vec<&str>) -> Result { - let reply_message_content = match command { - AdminCommand::Appservices(command) => appservice::process(command, body).await?, - AdminCommand::Media(command) => media::process(command, body).await?, - AdminCommand::Users(command) => user::process(command, body).await?, - AdminCommand::Rooms(command) => room::process(command, body).await?, - AdminCommand::Federation(command) => federation::process(command, body).await?, - AdminCommand::Server(command) => server::process(command, body).await?, - AdminCommand::Debug(command) => debug::process(command, body).await?, - AdminCommand::Query(command) => query::process(command, body).await?, - AdminCommand::Fsck(command) => fsck::process(command, body).await?, - AdminCommand::Tester(command) => tester::process(command, body).await?, - }; - - Ok(reply_message_content) - } - - // Utility to turn clap's `--help` text to HTML. - fn usage_to_html(&self, text: &str, server_name: &ServerName) -> String { - // Replace `@conduit:servername:-subcmdname` with `@conduit:servername: - // subcmdname` - let text = text.replace(&format!("@conduit:{server_name}:-"), &format!("@conduit:{server_name}: ")); - - // For the conduit admin room, subcommands become main commands - let text = text.replace("SUBCOMMAND", "COMMAND"); - let text = text.replace("subcommand", "command"); - - // Escape option names (e.g. ``) since they look like HTML tags - let text = escape_html(&text); - - // Italicize the first line (command name and version text) - let re = Regex::new("^(.*?)\n").expect("Regex compilation should not fail"); - let text = re.replace_all(&text, "$1\n"); - - // Unmerge wrapped lines - let text = text.replace("\n ", " "); - - // Wrap option names in backticks. The lines look like: - // -V, --version Prints version information - // And are converted to: - // -V, --version: Prints version information - // (?m) enables multi-line mode for ^ and $ - let re = Regex::new("(?m)^ {4}(([a-zA-Z_&;-]+(, )?)+) +(.*)$").expect("Regex compilation should not fail"); - let text = re.replace_all(&text, "$1: $4"); - - // Look for a `[commandbody]` tag. If it exists, use all lines below it that - // start with a `#` in the USAGE section. - let mut text_lines = text.lines().collect::>(); - let mut command_body = String::new(); - - if let Some(line_index) = text_lines.iter().position(|line| *line == "[commandbody]") { - text_lines.remove(line_index); - - while text_lines - .get(line_index) - .is_some_and(|line| line.starts_with('#')) - { - command_body += if text_lines[line_index].starts_with("# ") { - &text_lines[line_index][2..] - } else { - &text_lines[line_index][1..] - }; - command_body += "[nobr]\n"; - text_lines.remove(line_index); - } - } - - let text = text_lines.join("\n"); - - // Improve the usage section - let text = if command_body.is_empty() { - // Wrap the usage line in code tags - let re = Regex::new("(?m)^USAGE:\n {4}(@conduit:.*)$").expect("Regex compilation should not fail"); - re.replace_all(&text, "USAGE:\n$1").to_string() - } else { - // Wrap the usage line in a code block, and add a yaml block example - // This makes the usage of e.g. `register-appservice` more accurate - let re = Regex::new("(?m)^USAGE:\n {4}(.*?)\n\n").expect("Regex compilation should not fail"); - re.replace_all(&text, "USAGE:\n
$1[nobr]\n[commandbodyblock]
") - .replace("[commandbodyblock]", &command_body) - }; - - // Add HTML line-breaks - - text.replace("\n\n\n", "\n\n") - .replace('\n', "
\n") - .replace("[nobr]
", "") + .alias + .resolve_local_alias(&admin_room_alias) } /// Create the admin room. /// /// Users in this room are considered admins by conduit, and the room can be /// used to issue admin commands by talking to the server user inside it. - pub(crate) async fn create_admin_room(&self) -> Result<()> { + pub async fn create_admin_room(&self) -> Result<()> { let room_id = RoomId::new(services().globals.server_name()); services().rooms.short.get_or_create_shortroomid(&room_id)?; @@ -637,25 +390,10 @@ impl Service { Ok(()) } - /// Gets the room ID of the admin room - /// - /// Errors are propagated from the database, and will have None if there is - /// no admin room - pub(crate) async fn get_admin_room() -> Result> { - let admin_room_alias: Box = format!("#admins:{}", services().globals.server_name()) - .try_into() - .expect("#admins:server_name is a valid alias name"); - - services() - .rooms - .alias - .resolve_local_alias(&admin_room_alias) - } - /// Invite the user to the conduit admin room. /// /// In conduit, this is equivalent to granting admin privileges. - pub(crate) async fn make_user_admin(&self, user_id: &UserId, displayname: String) -> Result<()> { + pub async fn make_user_admin(&self, user_id: &UserId, displayname: String) -> Result<()> { if let Some(room_id) = Self::get_admin_room().await? { let mutex_state = Arc::clone( services() @@ -754,7 +492,7 @@ impl Service { // Send welcome message services().rooms.timeline.build_and_append_pdu( - PduBuilder { + PduBuilder { event_type: TimelineEventType::RoomMessage, content: to_raw_value(&RoomMessageEventContent::text_html( format!("## Thank you for trying out conduwuit!\n\nconduwuit is a fork of upstream Conduit which is in Beta. This means you can join and participate in most Matrix rooms, but not all features are supported and you might run into bugs from time to time.\n\nHelpful links:\n> Git and Documentation: https://github.com/girlbossceo/conduwuit\n> Report issues: https://github.com/girlbossceo/conduwuit/issues\n\nFor a list of available commands, send the following message in this room: `@conduit:{}: --help`\n\nHere are some rooms you can join (by typing the command):\n\nconduwuit room (Ask questions and get notified on updates):\n`/join #conduwuit:puppygock.gay`", services().globals.server_name()), @@ -776,54 +514,3 @@ impl Service { } } } - -fn escape_html(s: &str) -> String { - s.replace('&', "&") - .replace('<', "<") - .replace('>', ">") -} - -fn get_room_info(id: &OwnedRoomId) -> (OwnedRoomId, u64, String) { - ( - id.clone(), - services() - .rooms - .state_cache - .room_joined_count(id) - .ok() - .flatten() - .unwrap_or(0), - services() - .rooms - .state_accessor - .get_name(id) - .ok() - .flatten() - .unwrap_or_else(|| id.to_string()), - ) -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn get_help_short() { get_help_inner("-h"); } - - #[test] - fn get_help_long() { get_help_inner("--help"); } - - #[test] - fn get_help_subcommand() { get_help_inner("help"); } - - fn get_help_inner(input: &str) { - let error = AdminCommand::try_parse_from(["argv[0] doesn't matter", input]) - .unwrap_err() - .to_string(); - - // Search for a handful of keywords that suggest the help printed properly - assert!(error.contains("Usage:")); - assert!(error.contains("Commands:")); - assert!(error.contains("Options:")); - } -} diff --git a/src/service/admin/test_cmd/mod.rs b/src/service/admin/test_cmd/mod.rs deleted file mode 100644 index fc49885e..00000000 --- a/src/service/admin/test_cmd/mod.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! test commands generally used for hot lib reloadable functions. -//! see for more details if you are a dev - -//#[cfg(not(feature = "hot_reload"))] -//#[allow(unused_imports)] -//#[allow(clippy::wildcard_imports)] -// non hot reloadable functions (?) -//use hot_lib::*; -#[cfg(feature = "hot_reload")] -#[allow(unused_imports)] -#[allow(clippy::wildcard_imports)] -use hot_lib_funcs::*; -use ruma::events::room::message::RoomMessageEventContent; - -use crate::{debug_error, Result}; - -#[cfg(feature = "hot_reload")] -#[hot_lib_reloader::hot_module(dylib = "lib")] -mod hot_lib_funcs { - // these will be functions from lib.rs, so `use hot_lib_funcs::test_command;` - hot_functions_from_file!("hot_lib/src/lib.rs"); -} - -#[cfg_attr(test, derive(Debug))] -#[derive(clap::Subcommand)] -pub(crate) enum TestCommands { - // !admin test test1 - Test1, -} - -pub(crate) async fn process(command: TestCommands, _body: Vec<&str>) -> Result { - Ok(match command { - TestCommands::Test1 => { - debug_error!("before calling test_command"); - test_command(); - debug_error!("after calling test_command"); - - RoomMessageEventContent::notice_plain(String::from("loaded")) - }, - }) -} diff --git a/src/service/appservice/data.rs b/src/service/appservice/data.rs index cb19ebb0..52c8b34d 100644 --- a/src/service/appservice/data.rs +++ b/src/service/appservice/data.rs @@ -2,7 +2,7 @@ use ruma::api::appservice::Registration; use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { /// Registers an appservice and returns the ID to the caller fn register_appservice(&self, yaml: Registration) -> Result; diff --git a/src/service/appservice/mod.rs b/src/service/appservice/mod.rs index 1fd46d68..1d3bc98a 100644 --- a/src/service/appservice/mod.rs +++ b/src/service/appservice/mod.rs @@ -1,8 +1,8 @@ mod data; -use std::collections::BTreeMap; +use std::{collections::BTreeMap, sync::Arc}; -pub(crate) use data::Data; +pub use data::Data; use futures_util::Future; use regex::RegexSet; use ruma::{ @@ -15,14 +15,15 @@ use crate::{services, Result}; /// Compiled regular expressions for a namespace #[derive(Clone, Debug)] -pub(crate) struct NamespaceRegex { - pub(crate) exclusive: Option, - pub(crate) non_exclusive: Option, +pub struct NamespaceRegex { + pub exclusive: Option, + pub non_exclusive: Option, } impl NamespaceRegex { /// Checks if this namespace has rights to a namespace - pub(crate) fn is_match(&self, heystack: &str) -> bool { + #[must_use] + pub fn is_match(&self, heystack: &str) -> bool { if self.is_exclusive_match(heystack) { return true; } @@ -36,7 +37,8 @@ impl NamespaceRegex { } /// Checks if this namespace has exlusive rights to a namespace - pub(crate) fn is_exclusive_match(&self, heystack: &str) -> bool { + #[must_use] + pub fn is_exclusive_match(&self, heystack: &str) -> bool { if let Some(exclusive) = &self.exclusive { if exclusive.is_match(heystack) { return true; @@ -47,11 +49,13 @@ impl NamespaceRegex { } impl RegistrationInfo { - pub(crate) fn is_user_match(&self, user_id: &UserId) -> bool { + #[must_use] + pub fn is_user_match(&self, user_id: &UserId) -> bool { self.users.is_match(user_id.as_str()) || self.registration.sender_localpart == user_id.localpart() } - pub(crate) fn is_exclusive_user_match(&self, user_id: &UserId) -> bool { + #[must_use] + pub fn is_exclusive_user_match(&self, user_id: &UserId) -> bool { self.users.is_exclusive_match(user_id.as_str()) || self.registration.sender_localpart == user_id.localpart() } } @@ -88,11 +92,11 @@ impl TryFrom> for NamespaceRegex { /// Appservice registration combined with its compiled regular expressions. #[derive(Clone, Debug)] -pub(crate) struct RegistrationInfo { - pub(crate) registration: Registration, - pub(crate) users: NamespaceRegex, - pub(crate) aliases: NamespaceRegex, - pub(crate) rooms: NamespaceRegex, +pub struct RegistrationInfo { + pub registration: Registration, + pub users: NamespaceRegex, + pub aliases: NamespaceRegex, + pub rooms: NamespaceRegex, } impl TryFrom for RegistrationInfo { @@ -108,13 +112,13 @@ impl TryFrom for RegistrationInfo { } } -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, registration_info: RwLock>, } impl Service { - pub(crate) fn build(db: &'static dyn Data) -> Result { + pub fn build(db: Arc) -> Result { let mut registration_info = BTreeMap::new(); // Inserting registrations into cache for appservice in db.all()? { @@ -134,7 +138,7 @@ impl Service { } /// Registers an appservice and returns the ID to the caller - pub(crate) async fn register_appservice(&self, yaml: Registration) -> Result { + pub async fn register_appservice(&self, yaml: Registration) -> Result { //TODO: Check for collisions between exclusive appservice namespaces services() .appservice @@ -151,7 +155,7 @@ impl Service { /// # Arguments /// /// * `service_name` - the name you send to register the service previously - pub(crate) async fn unregister_appservice(&self, service_name: &str) -> Result<()> { + pub async fn unregister_appservice(&self, service_name: &str) -> Result<()> { // removes the appservice registration info services() .appservice @@ -171,7 +175,7 @@ impl Service { Ok(()) } - pub(crate) async fn get_registration(&self, id: &str) -> Option { + pub async fn get_registration(&self, id: &str) -> Option { self.registration_info .read() .await @@ -180,7 +184,7 @@ impl Service { .map(|info| info.registration) } - pub(crate) async fn iter_ids(&self) -> Vec { + pub async fn iter_ids(&self) -> Vec { self.registration_info .read() .await @@ -189,7 +193,7 @@ impl Service { .collect() } - pub(crate) async fn find_from_token(&self, token: &str) -> Option { + pub async fn find_from_token(&self, token: &str) -> Option { self.read() .await .values() @@ -198,7 +202,7 @@ impl Service { } /// Checks if a given user id matches any exclusive appservice regex - pub(crate) async fn is_exclusive_user_id(&self, user_id: &UserId) -> bool { + pub async fn is_exclusive_user_id(&self, user_id: &UserId) -> bool { self.read() .await .values() @@ -206,7 +210,7 @@ impl Service { } /// Checks if a given room alias matches any exclusive appservice regex - pub(crate) async fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool { + pub async fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool { self.read() .await .values() @@ -217,16 +221,14 @@ impl Service { /// /// TODO: use this? #[allow(dead_code)] - pub(crate) async fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool { + pub async fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool { self.read() .await .values() .any(|info| info.rooms.is_exclusive_match(room_id.as_str())) } - pub(crate) fn read( - &self, - ) -> impl Future>> { + pub fn read(&self) -> impl Future>> { self.registration_info.read() } } diff --git a/src/service/globals/client.rs b/src/service/globals/client.rs index c652eef9..82747ae7 100644 --- a/src/service/globals/client.rs +++ b/src/service/globals/client.rs @@ -4,18 +4,18 @@ use reqwest::redirect; use crate::{service::globals::resolver, utils::conduwuit_version, Config, Result}; -pub(crate) struct Client { - pub(crate) default: reqwest::Client, - pub(crate) url_preview: reqwest::Client, - pub(crate) well_known: reqwest::Client, - pub(crate) federation: reqwest::Client, - pub(crate) sender: reqwest::Client, - pub(crate) appservice: reqwest::Client, - pub(crate) pusher: reqwest::Client, +pub struct Client { + pub default: reqwest::Client, + pub url_preview: reqwest::Client, + pub well_known: reqwest::Client, + pub federation: reqwest::Client, + pub sender: reqwest::Client, + pub appservice: reqwest::Client, + pub pusher: reqwest::Client, } impl Client { - pub(crate) fn new(config: &Config, resolver: &Arc) -> Client { + pub fn new(config: &Config, resolver: &Arc) -> Client { Client { default: Self::base(config) .unwrap() diff --git a/src/service/globals/data.rs b/src/service/globals/data.rs index 1d75867c..59ed4534 100644 --- a/src/service/globals/data.rs +++ b/src/service/globals/data.rs @@ -10,7 +10,7 @@ use ruma::{ use crate::{database::Cork, Result}; #[async_trait] -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn next_count(&self) -> Result; fn current_count(&self) -> Result; fn last_check_for_updates_id(&self) -> Result; diff --git a/src/service/globals/emerg_access.rs b/src/service/globals/emerg_access.rs new file mode 100644 index 00000000..bda664d6 --- /dev/null +++ b/src/service/globals/emerg_access.rs @@ -0,0 +1,66 @@ +use conduit::Result; +use ruma::{ + events::{ + push_rules::PushRulesEventContent, room::message::RoomMessageEventContent, GlobalAccountDataEvent, + GlobalAccountDataEventType, + }, + push::Ruleset, + UserId, +}; +use tracing::{error, warn}; + +use crate::services; + +pub(crate) async fn init_emergency_access() { + // Set emergency access for the conduit user + 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!" + ); + 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!", + )) + .await; + } + }, + Err(e) => { + error!("Could not set the configured emergency password for the conduit user: {}", e); + }, + }; +} + +/// Sets the emergency password and push rules for the @conduit account in case +/// emergency password is set +fn set_emergency_access() -> Result { + let conduit_user = UserId::parse_with_server_name("conduit", services().globals.server_name()) + .expect("@conduit:server_name is a valid UserId"); + + services() + .users + .set_password(&conduit_user, services().globals.emergency_password().as_deref())?; + + let (ruleset, res) = match services().globals.emergency_password() { + Some(_) => (Ruleset::server_default(&conduit_user), Ok(true)), + None => (Ruleset::new(), Ok(false)), + }; + + services().account_data.update( + None, + &conduit_user, + GlobalAccountDataEventType::PushRules.to_string().into(), + &serde_json::to_value(&GlobalAccountDataEvent { + content: PushRulesEventContent { + global: ruleset, + }, + }) + .expect("to json value always works"), + )?; + + res +} diff --git a/src/database/migrations.rs b/src/service/globals/migrations.rs similarity index 99% rename from src/database/migrations.rs rename to src/service/globals/migrations.rs index a6726528..0e04caeb 100644 --- a/src/database/migrations.rs +++ b/src/service/globals/migrations.rs @@ -7,6 +7,7 @@ use std::{ }; use argon2::{password_hash::SaltString, PasswordHasher, PasswordVerifier}; +use database::KeyValueDatabase; use itertools::Itertools; use rand::thread_rng; use ruma::{ @@ -16,7 +17,6 @@ use ruma::{ }; use tracing::{debug, error, info, warn}; -use super::KeyValueDatabase; use crate::{services, utils, Config, Error, Result}; pub(crate) async fn migrations(db: &KeyValueDatabase, config: &Config) -> Result<()> { @@ -567,7 +567,7 @@ pub(crate) async fn migrations(db: &KeyValueDatabase, config: &Config) -> Result ); { - let patterns = &config.forbidden_usernames; + let patterns = services().globals.forbidden_usernames(); if !patterns.is_empty() { for user_id in services() .users @@ -592,7 +592,7 @@ pub(crate) async fn migrations(db: &KeyValueDatabase, config: &Config) -> Result } { - let patterns = &config.forbidden_alias_names; + let patterns = services().globals.forbidden_alias_names(); if !patterns.is_empty() { for address in services().rooms.metadata.iter_ids() { let room_id = address?; diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index 4484b816..85fdad0e 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -3,16 +3,13 @@ use std::{ fs, future::Future, path::PathBuf, - sync::{ - atomic::{self, AtomicBool}, - Arc, - }, - time::{Instant, SystemTime}, + sync::Arc, + time::Instant, }; use argon2::Argon2; use base64::{engine::general_purpose, Engine as _}; -pub(crate) use data::Data; +pub use data::Data; use hickory_resolver::TokioAsyncResolver; use ipaddress::IPAddress; use regex::RegexSet; @@ -25,42 +22,46 @@ use ruma::{ DeviceId, OwnedEventId, OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, RoomVersionId, ServerName, UserId, }; -use tokio::sync::{broadcast, Mutex, RwLock}; -use tracing::{error, info, trace}; +use tokio::{ + sync::{broadcast, Mutex, RwLock}, + task::JoinHandle, +}; +use tracing::{error, trace}; use url::Url; -use crate::{services, Config, LogLevelReloadHandles, Result}; +use crate::{services, Config, Result}; mod client; -mod data; +pub mod data; +pub(crate) mod emerg_access; +pub(crate) mod migrations; mod resolver; +pub(crate) mod updates; type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries -pub(crate) struct Service<'a> { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, - pub(crate) tracing_reload_handle: LogLevelReloadHandles, - pub(crate) config: Config, - pub(crate) cidr_range_denylist: Vec, + pub config: Config, + pub cidr_range_denylist: Vec, keypair: Arc, jwt_decoding_key: Option, - pub(crate) resolver: Arc, - pub(crate) client: client::Client, - pub(crate) stable_room_versions: Vec, - pub(crate) unstable_room_versions: Vec, - pub(crate) bad_event_ratelimiter: Arc>>, - pub(crate) bad_signature_ratelimiter: Arc, RateLimitState>>>, - pub(crate) bad_query_ratelimiter: Arc>>, - pub(crate) roomid_mutex_insert: RwLock>>>, - pub(crate) roomid_mutex_state: RwLock>>>, - pub(crate) roomid_mutex_federation: RwLock>>>, // this lock will be held longer - pub(crate) roomid_federationhandletime: RwLock>, - pub(crate) stateres_mutex: Arc>, - pub(crate) rotate: RotationHandler, - pub(crate) started: SystemTime, - pub(crate) shutdown: AtomicBool, - pub(crate) argon: Argon2<'a>, + pub resolver: Arc, + pub client: client::Client, + pub stable_room_versions: Vec, + pub unstable_room_versions: Vec, + pub bad_event_ratelimiter: Arc>>, + pub bad_signature_ratelimiter: Arc, RateLimitState>>>, + pub bad_query_ratelimiter: Arc>>, + pub roomid_mutex_insert: RwLock>>>, + pub roomid_mutex_state: RwLock>>>, + pub roomid_mutex_federation: RwLock>>>, // this lock will be held longer + pub roomid_federationhandletime: RwLock>, + pub updates_handle: Mutex>>, + pub stateres_mutex: Arc>, + pub rotate: RotationHandler, + pub argon: Argon2<'static>, } /// Handles "rotation" of long-polling requests. "Rotation" in this context is @@ -68,7 +69,7 @@ pub(crate) struct Service<'a> { /// /// This is utilized to have sync workers return early and release read locks on /// the database. -pub(crate) struct RotationHandler(broadcast::Sender<()>, ()); +pub struct RotationHandler(broadcast::Sender<()>, ()); impl RotationHandler { fn new() -> Self { @@ -76,25 +77,22 @@ impl RotationHandler { Self(s, ()) } - pub(crate) fn watch(&self) -> impl Future { + pub fn watch(&self) -> impl Future { let mut r = self.0.subscribe(); - async move { _ = r.recv().await; } } - fn fire(&self) { _ = self.0.send(()); } + pub fn fire(&self) { _ = self.0.send(()); } } impl Default for RotationHandler { fn default() -> Self { Self::new() } } -impl Service<'_> { - pub(crate) fn load( - db: &'static dyn Data, config: &Config, tracing_reload_handle: LogLevelReloadHandles, - ) -> Result { +impl Service { + pub fn load(db: Arc, config: &Config) -> Result { let keypair = db.load_keypair(); let keypair = match keypair { @@ -140,7 +138,6 @@ impl Service<'_> { } let mut s = Self { - tracing_reload_handle, db, config: config.clone(), cidr_range_denylist, @@ -157,10 +154,9 @@ impl Service<'_> { roomid_mutex_insert: RwLock::new(HashMap::new()), roomid_mutex_federation: RwLock::new(HashMap::new()), roomid_federationhandletime: RwLock::new(HashMap::new()), + updates_handle: Mutex::new(None), stateres_mutex: Arc::new(Mutex::new(())), rotate: RotationHandler::new(), - started: SystemTime::now(), - shutdown: AtomicBool::new(false), argon, }; @@ -178,145 +174,141 @@ impl Service<'_> { } /// Returns this server's keypair. - pub(crate) fn keypair(&self) -> &ruma::signatures::Ed25519KeyPair { &self.keypair } + pub fn keypair(&self) -> &ruma::signatures::Ed25519KeyPair { &self.keypair } #[tracing::instrument(skip(self))] - pub(crate) fn next_count(&self) -> Result { self.db.next_count() } + pub fn next_count(&self) -> Result { self.db.next_count() } #[tracing::instrument(skip(self))] - pub(crate) fn current_count(&self) -> Result { self.db.current_count() } + pub fn current_count(&self) -> Result { self.db.current_count() } #[tracing::instrument(skip(self))] - pub(crate) fn last_check_for_updates_id(&self) -> Result { self.db.last_check_for_updates_id() } + pub fn last_check_for_updates_id(&self) -> Result { self.db.last_check_for_updates_id() } #[tracing::instrument(skip(self))] - pub(crate) fn update_check_for_updates_id(&self, id: u64) -> Result<()> { self.db.update_check_for_updates_id(id) } + pub fn update_check_for_updates_id(&self, id: u64) -> Result<()> { self.db.update_check_for_updates_id(id) } - pub(crate) async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { + pub async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { self.db.watch(user_id, device_id).await } - pub(crate) fn cleanup(&self) -> Result<()> { self.db.cleanup() } + pub fn cleanup(&self) -> Result<()> { self.db.cleanup() } /// TODO: use this? #[allow(dead_code)] - pub(crate) fn flush(&self) -> Result<()> { self.db.flush() } + pub fn flush(&self) -> Result<()> { self.db.flush() } - pub(crate) fn server_name(&self) -> &ServerName { self.config.server_name.as_ref() } + pub fn server_name(&self) -> &ServerName { self.config.server_name.as_ref() } - pub(crate) fn max_request_size(&self) -> u32 { self.config.max_request_size } + pub fn max_request_size(&self) -> u32 { self.config.max_request_size } - pub(crate) fn max_fetch_prev_events(&self) -> u16 { self.config.max_fetch_prev_events } + pub fn max_fetch_prev_events(&self) -> u16 { self.config.max_fetch_prev_events } - pub(crate) fn allow_registration(&self) -> bool { self.config.allow_registration } + pub fn allow_registration(&self) -> bool { self.config.allow_registration } - pub(crate) fn allow_guest_registration(&self) -> bool { self.config.allow_guest_registration } + pub fn allow_guest_registration(&self) -> bool { self.config.allow_guest_registration } - pub(crate) fn allow_guests_auto_join_rooms(&self) -> bool { self.config.allow_guests_auto_join_rooms } + pub fn allow_guests_auto_join_rooms(&self) -> bool { self.config.allow_guests_auto_join_rooms } - pub(crate) fn log_guest_registrations(&self) -> bool { self.config.log_guest_registrations } + pub fn log_guest_registrations(&self) -> bool { self.config.log_guest_registrations } - pub(crate) fn allow_encryption(&self) -> bool { self.config.allow_encryption } + pub fn allow_encryption(&self) -> bool { self.config.allow_encryption } - pub(crate) fn allow_federation(&self) -> bool { self.config.allow_federation } + pub fn allow_federation(&self) -> bool { self.config.allow_federation } - pub(crate) fn allow_public_room_directory_over_federation(&self) -> bool { + pub fn allow_public_room_directory_over_federation(&self) -> bool { self.config.allow_public_room_directory_over_federation } - pub(crate) fn allow_device_name_federation(&self) -> bool { self.config.allow_device_name_federation } + pub fn allow_device_name_federation(&self) -> bool { self.config.allow_device_name_federation } - pub(crate) fn allow_room_creation(&self) -> bool { self.config.allow_room_creation } + pub fn allow_room_creation(&self) -> bool { self.config.allow_room_creation } - pub(crate) fn allow_unstable_room_versions(&self) -> bool { self.config.allow_unstable_room_versions } + pub fn allow_unstable_room_versions(&self) -> bool { self.config.allow_unstable_room_versions } - pub(crate) fn default_room_version(&self) -> RoomVersionId { self.config.default_room_version.clone() } + pub fn default_room_version(&self) -> RoomVersionId { self.config.default_room_version.clone() } - pub(crate) fn new_user_displayname_suffix(&self) -> &String { &self.config.new_user_displayname_suffix } + pub fn new_user_displayname_suffix(&self) -> &String { &self.config.new_user_displayname_suffix } - pub(crate) fn allow_check_for_updates(&self) -> bool { self.config.allow_check_for_updates } + pub fn allow_check_for_updates(&self) -> bool { self.config.allow_check_for_updates } - pub(crate) fn trusted_servers(&self) -> &[OwnedServerName] { &self.config.trusted_servers } + pub fn trusted_servers(&self) -> &[OwnedServerName] { &self.config.trusted_servers } - pub(crate) fn query_trusted_key_servers_first(&self) -> bool { self.config.query_trusted_key_servers_first } + pub fn query_trusted_key_servers_first(&self) -> bool { self.config.query_trusted_key_servers_first } - pub(crate) fn dns_resolver(&self) -> &TokioAsyncResolver { &self.resolver.resolver } + pub fn dns_resolver(&self) -> &TokioAsyncResolver { &self.resolver.resolver } - pub(crate) fn actual_destinations(&self) -> &Arc> { &self.resolver.destinations } + pub fn actual_destinations(&self) -> &Arc> { &self.resolver.destinations } - pub(crate) fn jwt_decoding_key(&self) -> Option<&jsonwebtoken::DecodingKey> { self.jwt_decoding_key.as_ref() } + pub fn jwt_decoding_key(&self) -> Option<&jsonwebtoken::DecodingKey> { self.jwt_decoding_key.as_ref() } - pub(crate) fn turn_password(&self) -> &String { &self.config.turn_password } + pub fn turn_password(&self) -> &String { &self.config.turn_password } - pub(crate) fn turn_ttl(&self) -> u64 { self.config.turn_ttl } + pub fn turn_ttl(&self) -> u64 { self.config.turn_ttl } - pub(crate) fn turn_uris(&self) -> &[String] { &self.config.turn_uris } + pub fn turn_uris(&self) -> &[String] { &self.config.turn_uris } - pub(crate) fn turn_username(&self) -> &String { &self.config.turn_username } + pub fn turn_username(&self) -> &String { &self.config.turn_username } - pub(crate) fn turn_secret(&self) -> &String { &self.config.turn_secret } + pub fn turn_secret(&self) -> &String { &self.config.turn_secret } - pub(crate) fn allow_profile_lookup_federation_requests(&self) -> bool { + pub fn allow_profile_lookup_federation_requests(&self) -> bool { self.config.allow_profile_lookup_federation_requests } - pub(crate) fn notification_push_path(&self) -> &String { &self.config.notification_push_path } + pub fn notification_push_path(&self) -> &String { &self.config.notification_push_path } - pub(crate) fn emergency_password(&self) -> &Option { &self.config.emergency_password } + pub fn emergency_password(&self) -> &Option { &self.config.emergency_password } - pub(crate) fn url_preview_domain_contains_allowlist(&self) -> &Vec { + pub fn url_preview_domain_contains_allowlist(&self) -> &Vec { &self.config.url_preview_domain_contains_allowlist } - pub(crate) fn url_preview_domain_explicit_allowlist(&self) -> &Vec { + pub fn url_preview_domain_explicit_allowlist(&self) -> &Vec { &self.config.url_preview_domain_explicit_allowlist } - pub(crate) fn url_preview_domain_explicit_denylist(&self) -> &Vec { + pub fn url_preview_domain_explicit_denylist(&self) -> &Vec { &self.config.url_preview_domain_explicit_denylist } - pub(crate) fn url_preview_url_contains_allowlist(&self) -> &Vec { - &self.config.url_preview_url_contains_allowlist - } + pub fn url_preview_url_contains_allowlist(&self) -> &Vec { &self.config.url_preview_url_contains_allowlist } - pub(crate) fn url_preview_max_spider_size(&self) -> usize { self.config.url_preview_max_spider_size } + pub fn url_preview_max_spider_size(&self) -> usize { self.config.url_preview_max_spider_size } - pub(crate) fn url_preview_check_root_domain(&self) -> bool { self.config.url_preview_check_root_domain } + pub fn url_preview_check_root_domain(&self) -> bool { self.config.url_preview_check_root_domain } - pub(crate) fn forbidden_alias_names(&self) -> &RegexSet { &self.config.forbidden_alias_names } + pub fn forbidden_alias_names(&self) -> &RegexSet { &self.config.forbidden_alias_names } - pub(crate) fn forbidden_usernames(&self) -> &RegexSet { &self.config.forbidden_usernames } + pub fn forbidden_usernames(&self) -> &RegexSet { &self.config.forbidden_usernames } - pub(crate) fn allow_local_presence(&self) -> bool { self.config.allow_local_presence } + pub fn allow_local_presence(&self) -> bool { self.config.allow_local_presence } - pub(crate) fn allow_incoming_presence(&self) -> bool { self.config.allow_incoming_presence } + pub fn allow_incoming_presence(&self) -> bool { self.config.allow_incoming_presence } - pub(crate) fn allow_outgoing_presence(&self) -> bool { self.config.allow_outgoing_presence } + pub fn allow_outgoing_presence(&self) -> bool { self.config.allow_outgoing_presence } - pub(crate) fn allow_incoming_read_receipts(&self) -> bool { self.config.allow_incoming_read_receipts } + pub fn allow_incoming_read_receipts(&self) -> bool { self.config.allow_incoming_read_receipts } - pub(crate) fn allow_outgoing_read_receipts(&self) -> bool { self.config.allow_outgoing_read_receipts } + pub fn allow_outgoing_read_receipts(&self) -> bool { self.config.allow_outgoing_read_receipts } - pub(crate) fn prevent_media_downloads_from(&self) -> &[OwnedServerName] { - &self.config.prevent_media_downloads_from - } + pub fn prevent_media_downloads_from(&self) -> &[OwnedServerName] { &self.config.prevent_media_downloads_from } - pub(crate) fn forbidden_remote_room_directory_server_names(&self) -> &[OwnedServerName] { + pub fn forbidden_remote_room_directory_server_names(&self) -> &[OwnedServerName] { &self.config.forbidden_remote_room_directory_server_names } - pub(crate) fn well_known_support_page(&self) -> &Option { &self.config.well_known.support_page } + pub fn well_known_support_page(&self) -> &Option { &self.config.well_known.support_page } - pub(crate) fn well_known_support_role(&self) -> &Option { &self.config.well_known.support_role } + pub fn well_known_support_role(&self) -> &Option { &self.config.well_known.support_role } - pub(crate) fn well_known_support_email(&self) -> &Option { &self.config.well_known.support_email } + pub fn well_known_support_email(&self) -> &Option { &self.config.well_known.support_email } - pub(crate) fn well_known_support_mxid(&self) -> &Option { &self.config.well_known.support_mxid } + pub fn well_known_support_mxid(&self) -> &Option { &self.config.well_known.support_mxid } - pub(crate) fn block_non_admin_invites(&self) -> bool { self.config.block_non_admin_invites } + pub fn block_non_admin_invites(&self) -> bool { self.config.block_non_admin_invites } - pub(crate) fn supported_room_versions(&self) -> Vec { + pub fn supported_room_versions(&self) -> Vec { let mut room_versions: Vec = vec![]; room_versions.extend(self.stable_room_versions.clone()); if self.allow_unstable_room_versions() { @@ -332,7 +324,7 @@ impl Service<'_> { /// /// This doesn't actually check that the keys provided are newer than the /// old set. - pub(crate) fn add_signing_key( + pub fn add_signing_key( &self, origin: &ServerName, new_keys: ServerSigningKeys, ) -> Result> { self.db.add_signing_key(origin, new_keys) @@ -340,7 +332,7 @@ impl Service<'_> { /// This returns an empty `Ok(BTreeMap<..>)` when there are no keys found /// for the server. - pub(crate) fn signing_keys_for(&self, origin: &ServerName) -> Result> { + pub fn signing_keys_for(&self, origin: &ServerName) -> Result> { let mut keys = self.db.signing_keys_for(origin)?; if origin == self.server_name() { keys.insert( @@ -356,13 +348,11 @@ impl Service<'_> { Ok(keys) } - pub(crate) fn database_version(&self) -> Result { self.db.database_version() } + pub fn database_version(&self) -> Result { self.db.database_version() } - pub(crate) fn bump_database_version(&self, new_version: u64) -> Result<()> { - self.db.bump_database_version(new_version) - } + pub fn bump_database_version(&self, new_version: u64) -> Result<()> { self.db.bump_database_version(new_version) } - pub(crate) fn get_media_folder(&self) -> PathBuf { + pub fn get_media_folder(&self) -> PathBuf { let mut r = PathBuf::new(); r.push(self.config.database_path.clone()); r.push("media"); @@ -373,7 +363,7 @@ impl Service<'_> { /// flag enabled and database migrated uses SHA256 hash of the base64 key as /// the file name #[cfg(feature = "sha256_media")] - pub(crate) fn get_media_file_new(&self, key: &[u8]) -> PathBuf { + pub fn get_media_file_new(&self, key: &[u8]) -> PathBuf { let mut r = PathBuf::new(); r.push(self.config.database_path.clone()); r.push("media"); @@ -387,7 +377,7 @@ impl Service<'_> { /// old base64 file name media function /// This is the old version of `get_media_file` that uses the full base64 /// key as the filename. - pub(crate) fn get_media_file(&self, key: &[u8]) -> PathBuf { + pub fn get_media_file(&self, key: &[u8]) -> PathBuf { let mut r = PathBuf::new(); r.push(self.config.database_path.clone()); r.push("media"); @@ -395,13 +385,13 @@ impl Service<'_> { r } - pub(crate) fn well_known_client(&self) -> &Option { &self.config.well_known.client } + pub fn well_known_client(&self) -> &Option { &self.config.well_known.client } - pub(crate) fn well_known_server(&self) -> &Option { &self.config.well_known.server } + pub fn well_known_server(&self) -> &Option { &self.config.well_known.server } - pub(crate) fn unix_socket_path(&self) -> &Option { &self.config.unix_socket_path } + pub fn unix_socket_path(&self) -> &Option { &self.config.unix_socket_path } - pub(crate) fn valid_cidr_range(&self, ip: &IPAddress) -> bool { + pub fn valid_cidr_range(&self, ip: &IPAddress) -> bool { for cidr in &self.cidr_range_denylist { if cidr.includes(ip) { return false; @@ -410,24 +400,13 @@ impl Service<'_> { true } - - pub(crate) fn shutdown(&self) { - self.shutdown.store(true, atomic::Ordering::Relaxed); - // On shutdown - - if self.unix_socket_path().is_some() { - match &self.unix_socket_path() { - Some(path) => { - fs::remove_file(path).unwrap(); - }, - None => error!( - "Unable to remove socket file at {:?} during shutdown.", - &self.unix_socket_path() - ), - }; - }; - - info!(target: "shutdown-sync", "Received shutdown notification, notifying sync helpers..."); - services().globals.rotate.fire(); - } } + +#[inline] +#[must_use] +pub fn server_is_ours(server_name: &ServerName) -> bool { server_name == services().globals.config.server_name } + +/// checks if `user_id` is local to us via server_name comparison +#[inline] +#[must_use] +pub fn user_is_local(user_id: &UserId) -> bool { server_is_ours(user_id.server_name()) } diff --git a/src/service/globals/resolver.rs b/src/service/globals/resolver.rs index 190c8579..d109d389 100644 --- a/src/service/globals/resolver.rs +++ b/src/service/globals/resolver.rs @@ -17,21 +17,21 @@ use crate::{service::sending::FedDest, Config, Error}; pub(crate) type WellKnownMap = HashMap; type TlsNameMap = HashMap, u16)>; -pub(crate) struct Resolver { - pub(crate) destinations: Arc>, // actual_destination, host - pub(crate) overrides: Arc>, - pub(crate) resolver: Arc, - pub(crate) hooked: Arc, +pub struct Resolver { + pub destinations: Arc>, // actual_destination, host + pub overrides: Arc>, + pub resolver: Arc, + pub hooked: Arc, } -pub(crate) struct Hooked { - pub(crate) overrides: Arc>, - pub(crate) resolver: Arc, +pub struct Hooked { + pub overrides: Arc>, + pub resolver: Arc, } impl Resolver { #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] - pub(crate) fn new(config: &Config) -> Self { + pub fn new(config: &Config) -> Self { let (sys_conf, mut opts) = hickory_resolver::system_conf::read_system_conf() .map_err(|e| { error!("Failed to set up hickory dns resolver with system config: {}", e); diff --git a/src/service/globals/updates.rs b/src/service/globals/updates.rs new file mode 100644 index 00000000..5f530736 --- /dev/null +++ b/src/service/globals/updates.rs @@ -0,0 +1,76 @@ +use std::time::Duration; + +use ruma::events::room::message::RoomMessageEventContent; +use serde::Deserialize; +use tokio::{task::JoinHandle, time::interval}; +use tracing::{debug, error}; + +use crate::{ + conduit::{Error, Result}, + services, +}; + +#[derive(Deserialize)] +struct CheckForUpdatesResponseEntry { + id: u64, + date: String, + message: String, +} +#[derive(Deserialize)] +struct CheckForUpdatesResponse { + updates: Vec, +} + +#[tracing::instrument] +pub async fn start_check_for_updates_task() -> Result> { + let timer_interval = Duration::from_secs(7200); // 2 hours + + Ok(services().server.runtime().spawn(async move { + let mut i = interval(timer_interval); + + loop { + tokio::select! { + _ = i.tick() => { + debug!(target: "start_check_for_updates_task", "Timer ticked"); + }, + } + + _ = try_handle_updates().await; + } + })) +} + +async fn try_handle_updates() -> Result<()> { + let response = services() + .globals + .client + .default + .get("https://pupbrain.dev/check-for-updates/stable") + .send() + .await?; + + let response = serde_json::from_str::(&response.text().await?).map_err(|e| { + error!("Bad check for updates response: {e}"); + Error::BadServerResponse("Bad version check response") + })?; + + let mut last_update_id = services().globals.last_check_for_updates_id()?; + for update in response.updates { + last_update_id = last_update_id.max(update.id); + if update.id > services().globals.last_check_for_updates_id()? { + error!("{}", update.message); + services() + .admin + .send_message(RoomMessageEventContent::text_plain(format!( + "@room: the following is a message from the conduwuit puppy. it was sent on '{}':\n\n{}", + update.date, update.message + ))) + .await; + } + } + services() + .globals + .update_check_for_updates_id(last_update_id)?; + + Ok(()) +} diff --git a/src/service/key_backups/data.rs b/src/service/key_backups/data.rs index 5aefbd49..ac595a6b 100644 --- a/src/service/key_backups/data.rs +++ b/src/service/key_backups/data.rs @@ -8,7 +8,7 @@ use ruma::{ use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn create_backup(&self, user_id: &UserId, backup_metadata: &Raw) -> Result; fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()>; diff --git a/src/service/key_backups/mod.rs b/src/service/key_backups/mod.rs index d071ccc4..abab604c 100644 --- a/src/service/key_backups/mod.rs +++ b/src/service/key_backups/mod.rs @@ -1,7 +1,7 @@ mod data; -use std::collections::BTreeMap; +use std::{collections::BTreeMap, sync::Arc}; -pub(crate) use data::Data; +pub use data::Data; use ruma::{ api::client::backup::{BackupAlgorithm, KeyBackupData, RoomKeyBackup}, serde::Raw, @@ -10,79 +10,73 @@ use ruma::{ use crate::Result; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { - pub(crate) fn create_backup(&self, user_id: &UserId, backup_metadata: &Raw) -> Result { + pub fn create_backup(&self, user_id: &UserId, backup_metadata: &Raw) -> Result { self.db.create_backup(user_id, backup_metadata) } - pub(crate) fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()> { + pub fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()> { self.db.delete_backup(user_id, version) } - pub(crate) fn update_backup( + pub fn update_backup( &self, user_id: &UserId, version: &str, backup_metadata: &Raw, ) -> Result { self.db.update_backup(user_id, version, backup_metadata) } - pub(crate) fn get_latest_backup_version(&self, user_id: &UserId) -> Result> { + pub fn get_latest_backup_version(&self, user_id: &UserId) -> Result> { self.db.get_latest_backup_version(user_id) } - pub(crate) fn get_latest_backup(&self, user_id: &UserId) -> Result)>> { + pub fn get_latest_backup(&self, user_id: &UserId) -> Result)>> { self.db.get_latest_backup(user_id) } - pub(crate) fn get_backup(&self, user_id: &UserId, version: &str) -> Result>> { + pub fn get_backup(&self, user_id: &UserId, version: &str) -> Result>> { self.db.get_backup(user_id, version) } - pub(crate) fn add_key( + pub fn add_key( &self, user_id: &UserId, version: &str, room_id: &RoomId, session_id: &str, key_data: &Raw, ) -> Result<()> { self.db .add_key(user_id, version, room_id, session_id, key_data) } - pub(crate) fn count_keys(&self, user_id: &UserId, version: &str) -> Result { - self.db.count_keys(user_id, version) - } + pub fn count_keys(&self, user_id: &UserId, version: &str) -> Result { self.db.count_keys(user_id, version) } - pub(crate) fn get_etag(&self, user_id: &UserId, version: &str) -> Result { - self.db.get_etag(user_id, version) - } + pub fn get_etag(&self, user_id: &UserId, version: &str) -> Result { self.db.get_etag(user_id, version) } - pub(crate) fn get_all(&self, user_id: &UserId, version: &str) -> Result> { + pub fn get_all(&self, user_id: &UserId, version: &str) -> Result> { self.db.get_all(user_id, version) } - pub(crate) fn get_room( + pub fn get_room( &self, user_id: &UserId, version: &str, room_id: &RoomId, ) -> Result>> { self.db.get_room(user_id, version, room_id) } - pub(crate) fn get_session( + pub fn get_session( &self, user_id: &UserId, version: &str, room_id: &RoomId, session_id: &str, ) -> Result>> { self.db.get_session(user_id, version, room_id, session_id) } - pub(crate) fn delete_all_keys(&self, user_id: &UserId, version: &str) -> Result<()> { + pub fn delete_all_keys(&self, user_id: &UserId, version: &str) -> Result<()> { self.db.delete_all_keys(user_id, version) } - pub(crate) fn delete_room_keys(&self, user_id: &UserId, version: &str, room_id: &RoomId) -> Result<()> { + pub fn delete_room_keys(&self, user_id: &UserId, version: &str, room_id: &RoomId) -> Result<()> { self.db.delete_room_keys(user_id, version, room_id) } - pub(crate) fn delete_room_key( - &self, user_id: &UserId, version: &str, room_id: &RoomId, session_id: &str, - ) -> Result<()> { + pub fn delete_room_key(&self, user_id: &UserId, version: &str, room_id: &RoomId, session_id: &str) -> Result<()> { self.db .delete_room_key(user_id, version, room_id, session_id) } diff --git a/src/database/key_value/account_data.rs b/src/service/key_value/account_data.rs similarity index 96% rename from src/database/key_value/account_data.rs rename to src/service/key_value/account_data.rs index d67f8881..981f1b8c 100644 --- a/src/database/key_value/account_data.rs +++ b/src/service/key_value/account_data.rs @@ -8,9 +8,9 @@ use ruma::{ }; use tracing::warn; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{services, utils, Error, KeyValueDatabase, Result}; -impl service::account_data::Data for KeyValueDatabase { +impl crate::account_data::Data for KeyValueDatabase { /// Places one event in the account data of the user and removes the /// previous entry. #[tracing::instrument(skip(self, room_id, user_id, event_type, data))] diff --git a/src/database/key_value/appservice.rs b/src/service/key_value/appservice.rs similarity index 92% rename from src/database/key_value/appservice.rs rename to src/service/key_value/appservice.rs index ead37c2b..f030d5e7 100644 --- a/src/database/key_value/appservice.rs +++ b/src/service/key_value/appservice.rs @@ -1,8 +1,8 @@ use ruma::api::appservice::Registration; -use crate::{database::KeyValueDatabase, service, utils, Error, Result}; +use crate::{utils, Error, KeyValueDatabase, Result}; -impl service::appservice::Data for KeyValueDatabase { +impl crate::appservice::Data for KeyValueDatabase { /// Registers an appservice and returns the ID to the caller fn register_appservice(&self, yaml: Registration) -> Result { let id = yaml.id.as_str(); diff --git a/src/database/key_value/globals.rs b/src/service/key_value/globals.rs similarity index 96% rename from src/database/key_value/globals.rs rename to src/service/key_value/globals.rs index 4ed07eba..e56f9feb 100644 --- a/src/database/key_value/globals.rs +++ b/src/service/key_value/globals.rs @@ -8,17 +8,15 @@ use ruma::{ signatures::Ed25519KeyPair, DeviceId, MilliSecondsSinceUnixEpoch, OwnedServerSigningKeyId, ServerName, UserId, }; +use tracing::trace; -use crate::{ - database::{Cork, KeyValueDatabase}, - service, services, utils, Error, Result, -}; +use crate::{database::Cork, services, utils, Error, KeyValueDatabase, Result}; const COUNTER: &[u8] = b"c"; const LAST_CHECK_FOR_UPDATES_COUNT: &[u8] = b"u"; #[async_trait] -impl service::globals::Data for KeyValueDatabase { +impl crate::globals::Data for KeyValueDatabase { fn next_count(&self) -> Result { utils::u64_from_bytes(&self.global.increment(COUNTER)?) .map_err(|_| Error::bad_database("Count has invalid bytes.")) @@ -47,6 +45,7 @@ impl service::globals::Data for KeyValueDatabase { } #[allow(unused_qualifications)] // async traits + #[tracing::instrument(skip(self))] async fn watch(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { let userid_bytes = user_id.as_bytes().to_vec(); let mut userid_prefix = userid_bytes.clone(); @@ -132,7 +131,9 @@ impl service::globals::Data for KeyValueDatabase { futures.push(Box::pin(services().globals.rotate.watch())); // Wait until one of them finds something + trace!(futures = futures.len(), "watch started"); futures.next().await; + trace!(futures = futures.len(), "watch finished"); Ok(()) } diff --git a/src/database/key_value/key_backups.rs b/src/service/key_value/key_backups.rs similarity index 98% rename from src/database/key_value/key_backups.rs rename to src/service/key_value/key_backups.rs index 7ed1da4c..82bbdd48 100644 --- a/src/database/key_value/key_backups.rs +++ b/src/service/key_value/key_backups.rs @@ -9,9 +9,9 @@ use ruma::{ OwnedRoomId, RoomId, UserId, }; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{services, utils, Error, KeyValueDatabase, Result}; -impl service::key_backups::Data for KeyValueDatabase { +impl crate::key_backups::Data for KeyValueDatabase { fn create_backup(&self, user_id: &UserId, backup_metadata: &Raw) -> Result { let version = services().globals.next_count()?.to_string(); diff --git a/src/database/key_value/media.rs b/src/service/key_value/media.rs similarity index 97% rename from src/database/key_value/media.rs rename to src/service/key_value/media.rs index d86b50f1..07d8dde3 100644 --- a/src/database/key_value/media.rs +++ b/src/service/key_value/media.rs @@ -1,14 +1,9 @@ use ruma::api::client::error::ErrorKind; use tracing::debug; -use crate::{ - database::KeyValueDatabase, - service::{self, media::UrlPreviewData}, - utils::string_from_bytes, - Error, Result, -}; +use crate::{media::UrlPreviewData, utils::string_from_bytes, Error, KeyValueDatabase, Result}; -impl service::media::Data for KeyValueDatabase { +impl crate::media::Data for KeyValueDatabase { fn create_file_metadata( &self, sender_user: Option<&str>, mxc: String, width: u32, height: u32, content_disposition: Option<&str>, content_type: Option<&str>, diff --git a/src/database/key_value/mod.rs b/src/service/key_value/mod.rs similarity index 100% rename from src/database/key_value/mod.rs rename to src/service/key_value/mod.rs diff --git a/src/database/key_value/presence.rs b/src/service/key_value/presence.rs similarity index 96% rename from src/database/key_value/presence.rs rename to src/service/key_value/presence.rs index 17068f90..9defd06d 100644 --- a/src/database/key_value/presence.rs +++ b/src/service/key_value/presence.rs @@ -1,15 +1,14 @@ +use conduit::debug_info; use ruma::{events::presence::PresenceEvent, presence::PresenceState, OwnedUserId, UInt, UserId}; use crate::{ - database::KeyValueDatabase, - debug_info, - service::{self, presence::Presence}, + presence::Presence, services, utils::{self, user_id_from_bytes}, - Error, Result, + Error, KeyValueDatabase, Result, }; -impl service::presence::Data for KeyValueDatabase { +impl crate::presence::Data for KeyValueDatabase { fn get_presence(&self, user_id: &UserId) -> Result> { if let Some(count_bytes) = self.userid_presenceid.get(user_id.as_bytes())? { let count = utils::u64_from_bytes(&count_bytes) diff --git a/src/database/key_value/pusher.rs b/src/service/key_value/pusher.rs similarity index 94% rename from src/database/key_value/pusher.rs rename to src/service/key_value/pusher.rs index 851831ec..876b531c 100644 --- a/src/database/key_value/pusher.rs +++ b/src/service/key_value/pusher.rs @@ -3,9 +3,9 @@ use ruma::{ UserId, }; -use crate::{database::KeyValueDatabase, service, utils, Error, Result}; +use crate::{utils, Error, KeyValueDatabase, Result}; -impl service::pusher::Data for KeyValueDatabase { +impl crate::pusher::Data for KeyValueDatabase { fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()> { match &pusher { set_pusher::v3::PusherAction::Post(data) => { diff --git a/src/database/key_value/rooms/alias.rs b/src/service/key_value/rooms/alias.rs similarity index 94% rename from src/database/key_value/rooms/alias.rs rename to src/service/key_value/rooms/alias.rs index b5a976c7..402e59fd 100644 --- a/src/database/key_value/rooms/alias.rs +++ b/src/service/key_value/rooms/alias.rs @@ -1,8 +1,8 @@ use ruma::{api::client::error::ErrorKind, OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId}; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{services, utils, Error, KeyValueDatabase, Result}; -impl service::rooms::alias::Data for KeyValueDatabase { +impl crate::rooms::alias::Data for KeyValueDatabase { fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()> { self.alias_roomid .insert(alias.alias().as_bytes(), room_id.as_bytes())?; diff --git a/src/database/key_value/rooms/auth_chain.rs b/src/service/key_value/rooms/auth_chain.rs similarity index 91% rename from src/database/key_value/rooms/auth_chain.rs rename to src/service/key_value/rooms/auth_chain.rs index 435a1c03..f01ff4aa 100644 --- a/src/database/key_value/rooms/auth_chain.rs +++ b/src/service/key_value/rooms/auth_chain.rs @@ -1,8 +1,8 @@ use std::{mem::size_of, sync::Arc}; -use crate::{database::KeyValueDatabase, service, utils, Result}; +use crate::{utils, KeyValueDatabase, Result}; -impl service::rooms::auth_chain::Data for KeyValueDatabase { +impl crate::rooms::auth_chain::Data for KeyValueDatabase { fn get_cached_eventid_authchain(&self, key: &[u64]) -> Result>> { // Check RAM cache if let Some(result) = self.auth_chain_cache.lock().unwrap().get_mut(key) { diff --git a/src/database/key_value/rooms/directory.rs b/src/service/key_value/rooms/directory.rs similarity index 85% rename from src/database/key_value/rooms/directory.rs rename to src/service/key_value/rooms/directory.rs index 20ccfb55..9265d2c8 100644 --- a/src/database/key_value/rooms/directory.rs +++ b/src/service/key_value/rooms/directory.rs @@ -1,8 +1,8 @@ use ruma::{OwnedRoomId, RoomId}; -use crate::{database::KeyValueDatabase, service, utils, Error, Result}; +use crate::{utils, Error, KeyValueDatabase, Result}; -impl service::rooms::directory::Data for KeyValueDatabase { +impl crate::rooms::directory::Data for KeyValueDatabase { fn set_public(&self, room_id: &RoomId) -> Result<()> { self.publicroomids.insert(room_id.as_bytes(), &[]) } fn set_not_public(&self, room_id: &RoomId) -> Result<()> { self.publicroomids.remove(room_id.as_bytes()) } diff --git a/src/database/key_value/rooms/lazy_load.rs b/src/service/key_value/rooms/lazy_load.rs similarity index 92% rename from src/database/key_value/rooms/lazy_load.rs rename to src/service/key_value/rooms/lazy_load.rs index 080eb4b8..700505cd 100644 --- a/src/database/key_value/rooms/lazy_load.rs +++ b/src/service/key_value/rooms/lazy_load.rs @@ -1,8 +1,8 @@ use ruma::{DeviceId, RoomId, UserId}; -use crate::{database::KeyValueDatabase, service, Result}; +use crate::{KeyValueDatabase, Result}; -impl service::rooms::lazy_loading::Data for KeyValueDatabase { +impl crate::rooms::lazy_loading::Data for KeyValueDatabase { fn lazy_load_was_sent_before( &self, user_id: &UserId, device_id: &DeviceId, room_id: &RoomId, ll_user: &UserId, ) -> Result { diff --git a/src/database/key_value/rooms/metadata.rs b/src/service/key_value/rooms/metadata.rs similarity index 93% rename from src/database/key_value/rooms/metadata.rs rename to src/service/key_value/rooms/metadata.rs index 9528da1e..ab8c1a78 100644 --- a/src/database/key_value/rooms/metadata.rs +++ b/src/service/key_value/rooms/metadata.rs @@ -1,9 +1,9 @@ use ruma::{OwnedRoomId, RoomId}; use tracing::error; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{services, utils, Error, KeyValueDatabase, Result}; -impl service::rooms::metadata::Data for KeyValueDatabase { +impl crate::rooms::metadata::Data for KeyValueDatabase { fn exists(&self, room_id: &RoomId) -> Result { let prefix = match services().rooms.short.get_shortroomid(room_id)? { Some(b) => b.to_be_bytes().to_vec(), diff --git a/src/database/key_value/rooms/mod.rs b/src/service/key_value/rooms/mod.rs similarity index 71% rename from src/database/key_value/rooms/mod.rs rename to src/service/key_value/rooms/mod.rs index 087f2711..d69cf141 100644 --- a/src/database/key_value/rooms/mod.rs +++ b/src/service/key_value/rooms/mod.rs @@ -16,6 +16,6 @@ mod threads; mod timeline; mod user; -use crate::{database::KeyValueDatabase, service}; +use crate::KeyValueDatabase; -impl service::rooms::Data for KeyValueDatabase {} +impl crate::rooms::Data for KeyValueDatabase {} diff --git a/src/database/key_value/rooms/outlier.rs b/src/service/key_value/rooms/outlier.rs similarity index 85% rename from src/database/key_value/rooms/outlier.rs rename to src/service/key_value/rooms/outlier.rs index 933660e8..701e4cb2 100644 --- a/src/database/key_value/rooms/outlier.rs +++ b/src/service/key_value/rooms/outlier.rs @@ -1,8 +1,8 @@ use ruma::{CanonicalJsonObject, EventId}; -use crate::{database::KeyValueDatabase, service, Error, PduEvent, Result}; +use crate::{Error, KeyValueDatabase, PduEvent, Result}; -impl service::rooms::outlier::Data for KeyValueDatabase { +impl crate::rooms::outlier::Data for KeyValueDatabase { fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result> { self.eventid_outlierpdu .get(event_id.as_bytes())? diff --git a/src/database/key_value/rooms/pdu_metadata.rs b/src/service/key_value/rooms/pdu_metadata.rs similarity index 92% rename from src/database/key_value/rooms/pdu_metadata.rs rename to src/service/key_value/rooms/pdu_metadata.rs index 7e69788d..225ed1cc 100644 --- a/src/database/key_value/rooms/pdu_metadata.rs +++ b/src/service/key_value/rooms/pdu_metadata.rs @@ -2,13 +2,9 @@ use std::{mem, sync::Arc}; use ruma::{EventId, RoomId, UserId}; -use crate::{ - database::KeyValueDatabase, - service::{self, rooms::timeline::PduCount}, - services, utils, Error, PduEvent, Result, -}; +use crate::{services, utils, Error, KeyValueDatabase, PduCount, PduEvent, Result}; -impl service::rooms::pdu_metadata::Data for KeyValueDatabase { +impl crate::rooms::pdu_metadata::Data for KeyValueDatabase { fn add_relation(&self, from: u64, to: u64) -> Result<()> { let mut key = to.to_be_bytes().to_vec(); key.extend_from_slice(&from.to_be_bytes()); diff --git a/src/database/key_value/rooms/read_receipt.rs b/src/service/key_value/rooms/read_receipt.rs similarity index 96% rename from src/database/key_value/rooms/read_receipt.rs rename to src/service/key_value/rooms/read_receipt.rs index e3f01a75..6cd913e7 100644 --- a/src/database/key_value/rooms/read_receipt.rs +++ b/src/service/key_value/rooms/read_receipt.rs @@ -2,9 +2,9 @@ use std::mem; use ruma::{events::receipt::ReceiptEvent, serde::Raw, CanonicalJsonObject, OwnedUserId, RoomId, UserId}; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{services, utils, Error, KeyValueDatabase, Result}; -impl service::rooms::read_receipt::Data for KeyValueDatabase { +impl crate::rooms::read_receipt::Data for KeyValueDatabase { fn readreceipt_update(&self, user_id: &UserId, room_id: &RoomId, event: ReceiptEvent) -> Result<()> { let mut prefix = room_id.as_bytes().to_vec(); prefix.push(0xFF); diff --git a/src/database/key_value/rooms/search.rs b/src/service/key_value/rooms/search.rs similarity index 93% rename from src/database/key_value/rooms/search.rs rename to src/service/key_value/rooms/search.rs index 6c5d1bc2..ab826172 100644 --- a/src/database/key_value/rooms/search.rs +++ b/src/service/key_value/rooms/search.rs @@ -1,10 +1,10 @@ use ruma::RoomId; -use crate::{database::KeyValueDatabase, service, services, utils, Result}; +use crate::{services, utils, KeyValueDatabase, Result}; type SearchPdusResult<'a> = Result> + 'a>, Vec)>>; -impl service::rooms::search::Data for KeyValueDatabase { +impl crate::rooms::search::Data for KeyValueDatabase { fn index_pdu(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()> { let mut batch = message_body .split_terminator(|c: char| !c.is_alphanumeric()) diff --git a/src/database/key_value/rooms/short.rs b/src/service/key_value/rooms/short.rs similarity index 97% rename from src/database/key_value/rooms/short.rs rename to src/service/key_value/rooms/short.rs index e0c3daac..69d85da4 100644 --- a/src/database/key_value/rooms/short.rs +++ b/src/service/key_value/rooms/short.rs @@ -3,9 +3,9 @@ use std::sync::Arc; use ruma::{events::StateEventType, EventId, RoomId}; use tracing::warn; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{services, utils, Error, KeyValueDatabase, Result}; -impl service::rooms::short::Data for KeyValueDatabase { +impl crate::rooms::short::Data for KeyValueDatabase { fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result { let short = if let Some(shorteventid) = self.eventid_shorteventid.get(event_id.as_bytes())? { utils::u64_from_bytes(&shorteventid).map_err(|_| Error::bad_database("Invalid shorteventid in db."))? diff --git a/src/database/key_value/rooms/state.rs b/src/service/key_value/rooms/state.rs similarity index 94% rename from src/database/key_value/rooms/state.rs rename to src/service/key_value/rooms/state.rs index 79ef202f..f7637c57 100644 --- a/src/database/key_value/rooms/state.rs +++ b/src/service/key_value/rooms/state.rs @@ -3,9 +3,9 @@ use std::{collections::HashSet, sync::Arc}; use ruma::{EventId, OwnedEventId, RoomId}; use tokio::sync::MutexGuard; -use crate::{database::KeyValueDatabase, service, utils, Error, Result}; +use crate::{utils, Error, KeyValueDatabase, Result}; -impl service::rooms::state::Data for KeyValueDatabase { +impl crate::rooms::state::Data for KeyValueDatabase { fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result> { self.roomid_shortstatehash .get(room_id.as_bytes())? diff --git a/src/database/key_value/rooms/state_accessor.rs b/src/service/key_value/rooms/state_accessor.rs similarity index 96% rename from src/database/key_value/rooms/state_accessor.rs rename to src/service/key_value/rooms/state_accessor.rs index 5b3a71d0..c36fd1cf 100644 --- a/src/database/key_value/rooms/state_accessor.rs +++ b/src/service/key_value/rooms/state_accessor.rs @@ -3,10 +3,10 @@ use std::{collections::HashMap, sync::Arc}; use async_trait::async_trait; use ruma::{events::StateEventType, EventId, RoomId}; -use crate::{database::KeyValueDatabase, service, services, utils, Error, PduEvent, Result}; +use crate::{services, utils, Error, KeyValueDatabase, PduEvent, Result}; #[async_trait] -impl service::rooms::state_accessor::Data for KeyValueDatabase { +impl crate::rooms::state_accessor::Data for KeyValueDatabase { #[allow(unused_qualifications)] // async traits async fn state_full_ids(&self, shortstatehash: u64) -> Result>> { let full_state = services() diff --git a/src/database/key_value/rooms/state_cache.rs b/src/service/key_value/rooms/state_cache.rs similarity index 98% rename from src/database/key_value/rooms/state_cache.rs rename to src/service/key_value/rooms/state_cache.rs index 1ca29ebd..795da576 100644 --- a/src/database/key_value/rooms/state_cache.rs +++ b/src/service/key_value/rooms/state_cache.rs @@ -9,18 +9,17 @@ use ruma::{ use tracing::error; use crate::{ - database::KeyValueDatabase, - service::{self, appservice::RegistrationInfo}, - services, - utils::{self, user_id::user_is_local}, - Error, Result, + appservice::RegistrationInfo, + services, user_is_local, + utils::{self}, + Error, KeyValueDatabase, Result, }; type StrippedStateEventIter<'a> = Box>)>> + 'a>; type AnySyncStateEventIter<'a> = Box>)>> + 'a>; -impl service::rooms::state_cache::Data for KeyValueDatabase { +impl crate::rooms::state_cache::Data for KeyValueDatabase { fn mark_as_once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> { let mut userroom_id = user_id.as_bytes().to_vec(); userroom_id.push(0xFF); diff --git a/src/database/key_value/rooms/state_compressor.rs b/src/service/key_value/rooms/state_compressor.rs similarity index 88% rename from src/database/key_value/rooms/state_compressor.rs rename to src/service/key_value/rooms/state_compressor.rs index 0043a1ba..bc0a2c33 100644 --- a/src/database/key_value/rooms/state_compressor.rs +++ b/src/service/key_value/rooms/state_compressor.rs @@ -1,12 +1,8 @@ use std::{collections::HashSet, mem::size_of, sync::Arc}; -use crate::{ - database::KeyValueDatabase, - service::{self, rooms::state_compressor::data::StateDiff}, - utils, Error, Result, -}; +use crate::{rooms::state_compressor::data::StateDiff, utils, Error, KeyValueDatabase, Result}; -impl service::rooms::state_compressor::Data for KeyValueDatabase { +impl crate::rooms::state_compressor::Data for KeyValueDatabase { fn get_statediff(&self, shortstatehash: u64) -> Result { let value = self .shortstatehash_statediff diff --git a/src/database/key_value/rooms/threads.rs b/src/service/key_value/rooms/threads.rs similarity index 93% rename from src/database/key_value/rooms/threads.rs rename to src/service/key_value/rooms/threads.rs index 4cb2591b..9f0aad3a 100644 --- a/src/database/key_value/rooms/threads.rs +++ b/src/service/key_value/rooms/threads.rs @@ -2,11 +2,11 @@ use std::mem; use ruma::{api::client::threads::get_threads::v1::IncludeThreads, OwnedUserId, RoomId, UserId}; -use crate::{database::KeyValueDatabase, service, services, utils, Error, PduEvent, Result}; +use crate::{services, utils, Error, KeyValueDatabase, PduEvent, Result}; type PduEventIterResult<'a> = Result> + 'a>>; -impl service::rooms::threads::Data for KeyValueDatabase { +impl crate::rooms::threads::Data for KeyValueDatabase { fn threads_until<'a>( &'a self, user_id: &'a UserId, room_id: &'a RoomId, until: u64, _include: &'a IncludeThreads, ) -> PduEventIterResult<'a> { diff --git a/src/database/key_value/rooms/timeline.rs b/src/service/key_value/rooms/timeline.rs similarity index 97% rename from src/database/key_value/rooms/timeline.rs rename to src/service/key_value/rooms/timeline.rs index d583c7ec..7f22354c 100644 --- a/src/database/key_value/rooms/timeline.rs +++ b/src/service/key_value/rooms/timeline.rs @@ -1,12 +1,11 @@ use std::{collections::hash_map, mem::size_of, sync::Arc}; use ruma::{api::client::error::ErrorKind, CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId}; -use service::rooms::timeline::PduCount; use tracing::error; -use crate::{database::KeyValueDatabase, service, services, utils, Error, PduEvent, Result}; +use crate::{services, utils, Error, KeyValueDatabase, PduCount, PduEvent, Result}; -impl service::rooms::timeline::Data for KeyValueDatabase { +impl crate::rooms::timeline::Data for KeyValueDatabase { fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result { match self .lasttimelinecount_cache diff --git a/src/database/key_value/rooms/user.rs b/src/service/key_value/rooms/user.rs similarity index 96% rename from src/database/key_value/rooms/user.rs rename to src/service/key_value/rooms/user.rs index cc031747..a49dc815 100644 --- a/src/database/key_value/rooms/user.rs +++ b/src/service/key_value/rooms/user.rs @@ -1,8 +1,8 @@ use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId}; -use crate::{database::KeyValueDatabase, service, services, utils, Error, Result}; +use crate::{services, utils, Error, KeyValueDatabase, Result}; -impl service::rooms::user::Data for KeyValueDatabase { +impl crate::rooms::user::Data for KeyValueDatabase { fn reset_notification_counts(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> { let mut userroom_id = user_id.as_bytes().to_vec(); userroom_id.push(0xFF); diff --git a/src/database/key_value/sending.rs b/src/service/key_value/sending.rs similarity index 96% rename from src/database/key_value/sending.rs rename to src/service/key_value/sending.rs index ae662f3b..544d37c9 100644 --- a/src/database/key_value/sending.rs +++ b/src/service/key_value/sending.rs @@ -1,15 +1,11 @@ use ruma::{ServerName, UserId}; use crate::{ - database::KeyValueDatabase, - service::{ - self, - sending::{Destination, SendingEvent}, - }, - services, utils, Error, Result, + sending::{Destination, SendingEvent}, + services, utils, Error, KeyValueDatabase, Result, }; -impl service::sending::Data for KeyValueDatabase { +impl crate::sending::Data for KeyValueDatabase { fn active_requests<'a>(&'a self) -> Box, Destination, SendingEvent)>> + 'a> { Box::new( self.servercurrentevent_data diff --git a/src/database/key_value/transaction_ids.rs b/src/service/key_value/transaction_ids.rs similarity index 88% rename from src/database/key_value/transaction_ids.rs rename to src/service/key_value/transaction_ids.rs index f88ae69f..2dfcdfb1 100644 --- a/src/database/key_value/transaction_ids.rs +++ b/src/service/key_value/transaction_ids.rs @@ -1,8 +1,8 @@ use ruma::{DeviceId, TransactionId, UserId}; -use crate::{database::KeyValueDatabase, service, Result}; +use crate::{KeyValueDatabase, Result}; -impl service::transaction_ids::Data for KeyValueDatabase { +impl crate::transaction_ids::Data for KeyValueDatabase { fn add_txnid( &self, user_id: &UserId, device_id: Option<&DeviceId>, txn_id: &TransactionId, data: &[u8], ) -> Result<()> { diff --git a/src/database/key_value/uiaa.rs b/src/service/key_value/uiaa.rs similarity index 94% rename from src/database/key_value/uiaa.rs rename to src/service/key_value/uiaa.rs index a8047656..801f08c1 100644 --- a/src/database/key_value/uiaa.rs +++ b/src/service/key_value/uiaa.rs @@ -3,9 +3,9 @@ use ruma::{ CanonicalJsonValue, DeviceId, UserId, }; -use crate::{database::KeyValueDatabase, service, Error, Result}; +use crate::{Error, KeyValueDatabase, Result}; -impl service::uiaa::Data for KeyValueDatabase { +impl crate::uiaa::Data for KeyValueDatabase { fn set_uiaa_request( &self, user_id: &UserId, device_id: &DeviceId, session: &str, request: &CanonicalJsonValue, ) -> Result<()> { diff --git a/src/database/key_value/users.rs b/src/service/key_value/users.rs similarity index 98% rename from src/database/key_value/users.rs rename to src/service/key_value/users.rs index 9b10f2a5..c8adb39f 100644 --- a/src/database/key_value/users.rs +++ b/src/service/key_value/users.rs @@ -1,5 +1,6 @@ use std::{collections::BTreeMap, mem::size_of}; +use argon2::{password_hash::SaltString, PasswordHasher}; use ruma::{ api::client::{device::Device, error::ErrorKind, filter::FilterDefinition}, encryption::{CrossSigningKey, DeviceKeys, OneTimeKey}, @@ -10,13 +11,9 @@ use ruma::{ }; use tracing::warn; -use crate::{ - database::KeyValueDatabase, - service::{self, users::clean_signatures}, - services, utils, Error, Result, -}; +use crate::{services, users::clean_signatures, utils, Error, KeyValueDatabase, Result}; -impl service::users::Data for KeyValueDatabase { +impl crate::users::Data for KeyValueDatabase { /// Check if a user has an account on this homeserver. fn exists(&self, user_id: &UserId) -> Result { Ok(self.userid_password.get(user_id.as_bytes())?.is_some()) } @@ -95,7 +92,7 @@ impl service::users::Data for KeyValueDatabase { /// Hash and set the user's password to the Argon2 hash fn set_password(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { if let Some(password) = password { - if let Ok(hash) = utils::calculate_password_hash(password) { + if let Ok(hash) = calculate_password_hash(password) { self.userid_password .insert(user_id.as_bytes(), hash.as_bytes())?; Ok(()) @@ -871,8 +868,6 @@ impl service::users::Data for KeyValueDatabase { } } -impl KeyValueDatabase {} - /// Will only return with Some(username) if the password was not empty and the /// username could be successfully parsed. /// If `utils::string_from_bytes`(...) returns an error that username will be @@ -891,3 +886,13 @@ fn get_username_with_valid_password(username: &[u8], password: &[u8]) -> Option< } } } + +/// Calculate a new hash for the given password +fn calculate_password_hash(password: &str) -> Result { + let salt = SaltString::generate(rand::thread_rng()); + services() + .globals + .argon + .hash_password(password.as_bytes(), &salt) + .map(|it| it.to_string()) +} diff --git a/src/service/media/data.rs b/src/service/media/data.rs index 7a1710b6..b20f8773 100644 --- a/src/service/media/data.rs +++ b/src/service/media/data.rs @@ -1,6 +1,6 @@ use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn create_file_metadata( &self, sender_user: Option<&str>, mxc: String, width: u32, height: u32, content_disposition: Option<&str>, content_type: Option<&str>, diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index 5e39085d..7494e9b3 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -1,7 +1,7 @@ mod data; use std::{collections::HashMap, io::Cursor, sync::Arc, time::SystemTime}; -pub(crate) use data::Data; +pub use data::Data; use image::imageops::FilterType; use ruma::{OwnedMxcUri, OwnedUserId}; use serde::Serialize; @@ -15,37 +15,37 @@ use tracing::{debug, error}; use crate::{services, utils, Error, Result}; #[derive(Debug)] -pub(crate) struct FileMeta { +pub struct FileMeta { #[allow(dead_code)] - pub(crate) content_disposition: Option, - pub(crate) content_type: Option, - pub(crate) file: Vec, + pub content_disposition: Option, + pub content_type: Option, + pub file: Vec, } #[derive(Serialize, Default)] -pub(crate) struct UrlPreviewData { +pub struct UrlPreviewData { #[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:title"))] - pub(crate) title: Option, + pub title: Option, #[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:description"))] - pub(crate) description: Option, + pub description: Option, #[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:image"))] - pub(crate) image: Option, + pub image: Option, #[serde(skip_serializing_if = "Option::is_none", rename(serialize = "matrix:image:size"))] - pub(crate) image_size: Option, + pub image_size: Option, #[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:image:width"))] - pub(crate) image_width: Option, + pub image_width: Option, #[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:image:height"))] - pub(crate) image_height: Option, + pub image_height: Option, } -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, - pub(crate) url_preview_mutex: RwLock>>>, +pub struct Service { + pub db: Arc, + pub url_preview_mutex: RwLock>>>, } impl Service { /// Uploads a file. - pub(crate) async fn create( + pub async fn create( &self, sender_user: Option, mxc: String, content_disposition: Option<&str>, content_type: Option<&str>, file: &[u8], ) -> Result<()> { @@ -79,7 +79,7 @@ impl Service { } /// Deletes a file in the database and from the media directory via an MXC - pub(crate) async fn delete(&self, mxc: String) -> Result<()> { + pub async fn delete(&self, mxc: String) -> Result<()> { if let Ok(keys) = self.db.search_mxc_metadata_prefix(mxc.clone()) { for key in keys { let file_path; @@ -116,7 +116,7 @@ impl Service { /// Uploads or replaces a file thumbnail. #[allow(clippy::too_many_arguments)] - pub(crate) async fn upload_thumbnail( + pub async fn upload_thumbnail( &self, sender_user: Option, mxc: String, content_disposition: Option<&str>, content_type: Option<&str>, width: u32, height: u32, file: &[u8], ) -> Result<()> { @@ -149,7 +149,7 @@ impl Service { } /// Downloads a file. - pub(crate) async fn get(&self, mxc: String) -> Result> { + pub async fn get(&self, mxc: String) -> Result> { if let Ok((content_disposition, content_type, key)) = self.db.search_file_metadata(mxc, 0, 0) { let path; @@ -182,7 +182,7 @@ impl Service { /// Deletes all remote only media files in the given at or after /// time/duration. Returns a u32 with the amount of media files deleted. - pub(crate) async fn delete_all_remote_media_at_after_time(&self, time: String) -> Result { + pub async fn delete_all_remote_media_at_after_time(&self, time: String) -> Result { if let Ok(all_keys) = self.db.get_all_media_keys() { let user_duration: SystemTime = match cyborgtime::parse_duration(&time) { Ok(duration) => { @@ -296,7 +296,7 @@ impl Service { /// Returns width, height of the thumbnail and whether it should be cropped. /// Returns None when the server should send the original file. - pub(crate) fn thumbnail_properties(&self, width: u32, height: u32) -> Option<(u32, u32, bool)> { + pub fn thumbnail_properties(&self, width: u32, height: u32) -> Option<(u32, u32, bool)> { match (width, height) { (0..=32, 0..=32) => Some((32, 32, true)), (0..=96, 0..=96) => Some((96, 96, true)), @@ -320,7 +320,7 @@ impl Service { /// /// For width,height <= 96 the server uses another thumbnailing algorithm /// which crops the image afterwards. - pub(crate) async fn get_thumbnail(&self, mxc: String, width: u32, height: u32) -> Result> { + pub async fn get_thumbnail(&self, mxc: String, width: u32, height: u32) -> Result> { let (width, height, crop) = self .thumbnail_properties(width, height) .unwrap_or((0, 0, false)); // 0, 0 because that's the original file @@ -467,16 +467,16 @@ impl Service { } } - pub(crate) async fn get_url_preview(&self, url: &str) -> Option { self.db.get_url_preview(url) } + pub async fn get_url_preview(&self, url: &str) -> Option { self.db.get_url_preview(url) } /// TODO: use this? #[allow(dead_code)] - pub(crate) 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) } - pub(crate) 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"); @@ -548,9 +548,9 @@ mod tests { fn get_url_preview(&self, _url: &str) -> Option { todo!() } } - static DB: MockedKVDatabase = MockedKVDatabase; + let db: Arc = Arc::new(MockedKVDatabase); let media = Service { - db: &DB, + db, url_preview_mutex: RwLock::new(HashMap::new()), }; diff --git a/src/service/mod.rs b/src/service/mod.rs index 3fbc435a..386e8662 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -1,298 +1,50 @@ -use std::{ - collections::{BTreeMap, HashMap}, - sync::{Arc, Mutex as StdMutex}, -}; +pub(crate) mod key_value; +pub mod pdu; +pub mod services; -use lru_cache::LruCache; -use tokio::sync::{broadcast, Mutex, RwLock}; +pub mod account_data; +pub mod admin; +pub mod appservice; +pub mod globals; +pub mod key_backups; +pub mod media; +pub mod presence; +pub mod pusher; +pub mod rooms; +pub mod sending; +pub mod transaction_ids; +pub mod uiaa; +pub mod users; -use crate::{Config, LogLevelReloadHandles, Result}; +extern crate conduit_core as conduit; +extern crate conduit_database as database; +use std::sync::RwLock; -pub(crate) mod account_data; -pub(crate) mod admin; -pub(crate) mod appservice; -pub(crate) mod globals; -pub(crate) mod key_backups; -pub(crate) mod media; -pub(crate) mod pdu; -pub(crate) mod presence; -pub(crate) mod pusher; -pub(crate) mod rooms; -pub(crate) mod sending; -pub(crate) mod transaction_ids; -pub(crate) mod uiaa; -pub(crate) mod users; +pub(crate) use conduit::{config, debug_error, debug_info, debug_warn, utils, Config, Error, PduCount, Result}; +pub(crate) use database::KeyValueDatabase; +pub use globals::{server_is_ours, user_is_local}; +pub use pdu::PduEvent; +pub use services::Services; -pub(crate) struct Services<'a> { - pub(crate) appservice: appservice::Service, - pub(crate) pusher: pusher::Service, - pub(crate) rooms: rooms::Service, - pub(crate) transaction_ids: transaction_ids::Service, - pub(crate) uiaa: uiaa::Service, - pub(crate) users: users::Service, - pub(crate) account_data: account_data::Service, - pub(crate) presence: Arc, - pub(crate) admin: Arc, - pub(crate) globals: globals::Service<'a>, - pub(crate) key_backups: key_backups::Service, - pub(crate) media: media::Service, - pub(crate) sending: Arc, +pub(crate) use crate as service; + +conduit::mod_ctor! {} +conduit::mod_dtor! {} + +pub static SERVICES: RwLock> = RwLock::new(None); + +#[must_use] +pub fn services() -> &'static Services { + SERVICES + .read() + .expect("SERVICES locked for reading") + .expect("SERVICES initialized with Services instance") } -impl Services<'_> { - #[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)] - pub(crate) fn build< - D: appservice::Data - + pusher::Data - + rooms::Data - + transaction_ids::Data - + uiaa::Data - + users::Data - + account_data::Data - + presence::Data - + globals::Data - + key_backups::Data - + media::Data - + sending::Data - + 'static, - >( - db: &'static D, config: &Config, tracing_reload_handle: LogLevelReloadHandles, - ) -> Result { - Ok(Self { - appservice: appservice::Service::build(db)?, - pusher: pusher::Service { - db, - }, - rooms: rooms::Service { - alias: rooms::alias::Service { - db, - }, - auth_chain: rooms::auth_chain::Service { - db, - }, - directory: rooms::directory::Service { - db, - }, - event_handler: rooms::event_handler::Service, - lazy_loading: rooms::lazy_loading::Service { - db, - lazy_load_waiting: Mutex::new(HashMap::new()), - }, - metadata: rooms::metadata::Service { - db, - }, - outlier: rooms::outlier::Service { - db, - }, - pdu_metadata: rooms::pdu_metadata::Service { - db, - }, - read_receipt: rooms::read_receipt::Service { - db, - }, - search: rooms::search::Service { - db, - }, - short: rooms::short::Service { - db, - }, - state: rooms::state::Service { - db, - }, - state_accessor: rooms::state_accessor::Service { - db, - server_visibility_cache: StdMutex::new(LruCache::new( - (f64::from(config.server_visibility_cache_capacity) * config.conduit_cache_capacity_modifier) - as usize, - )), - user_visibility_cache: StdMutex::new(LruCache::new( - (f64::from(config.user_visibility_cache_capacity) * config.conduit_cache_capacity_modifier) - as usize, - )), - }, - state_cache: rooms::state_cache::Service { - db, - }, - state_compressor: rooms::state_compressor::Service { - db, - stateinfo_cache: StdMutex::new(LruCache::new( - (f64::from(config.stateinfo_cache_capacity) * config.conduit_cache_capacity_modifier) as usize, - )), - }, - timeline: rooms::timeline::Service { - db, - lasttimelinecount_cache: Mutex::new(HashMap::new()), - }, - threads: rooms::threads::Service { - db, - }, - typing: rooms::typing::Service { - typing: RwLock::new(BTreeMap::new()), - last_typing_update: RwLock::new(BTreeMap::new()), - typing_update_sender: broadcast::channel(100).0, - }, - spaces: rooms::spaces::Service { - roomid_spacehierarchy_cache: Mutex::new(LruCache::new( - (f64::from(config.roomid_spacehierarchy_cache_capacity) - * config.conduit_cache_capacity_modifier) as usize, - )), - }, - user: rooms::user::Service { - db, - }, - }, - transaction_ids: transaction_ids::Service { - db, - }, - uiaa: uiaa::Service { - db, - }, - users: users::Service { - db, - connections: StdMutex::new(BTreeMap::new()), - }, - account_data: account_data::Service { - db, - }, - presence: presence::Service::build(db, config), - admin: admin::Service::build(), - key_backups: key_backups::Service { - db, - }, - media: media::Service { - db, - url_preview_mutex: RwLock::new(HashMap::new()), - }, - sending: sending::Service::build(db, config), - - globals: globals::Service::load(db, config, tracing_reload_handle)?, - }) - } - - async fn memory_usage(&self) -> String { - let lazy_load_waiting = self.rooms.lazy_loading.lazy_load_waiting.lock().await.len(); - let server_visibility_cache = self - .rooms - .state_accessor - .server_visibility_cache - .lock() - .unwrap() - .len(); - let user_visibility_cache = self - .rooms - .state_accessor - .user_visibility_cache - .lock() - .unwrap() - .len(); - let stateinfo_cache = self - .rooms - .state_compressor - .stateinfo_cache - .lock() - .unwrap() - .len(); - let lasttimelinecount_cache = self - .rooms - .timeline - .lasttimelinecount_cache - .lock() - .await - .len(); - let roomid_spacehierarchy_cache = self - .rooms - .spaces - .roomid_spacehierarchy_cache - .lock() - .await - .len(); - let resolver_overrides_cache = self.globals.resolver.overrides.read().unwrap().len(); - let resolver_destinations_cache = self.globals.resolver.destinations.read().await.len(); - let bad_event_ratelimiter = self.globals.bad_event_ratelimiter.read().await.len(); - let bad_query_ratelimiter = self.globals.bad_query_ratelimiter.read().await.len(); - let bad_signature_ratelimiter = self.globals.bad_signature_ratelimiter.read().await.len(); - - format!( - "\ -lazy_load_waiting: {lazy_load_waiting} -server_visibility_cache: {server_visibility_cache} -user_visibility_cache: {user_visibility_cache} -stateinfo_cache: {stateinfo_cache} -lasttimelinecount_cache: {lasttimelinecount_cache} -roomid_spacehierarchy_cache: {roomid_spacehierarchy_cache} -resolver_overrides_cache: {resolver_overrides_cache} -resolver_destinations_cache: {resolver_destinations_cache} -bad_event_ratelimiter: {bad_event_ratelimiter} -bad_query_ratelimiter: {bad_query_ratelimiter} -bad_signature_ratelimiter: {bad_signature_ratelimiter} -" - ) - } - - async fn clear_caches(&self, amount: u32) { - if amount > 0 { - self.rooms - .lazy_loading - .lazy_load_waiting - .lock() - .await - .clear(); - } - if amount > 1 { - self.rooms - .state_accessor - .server_visibility_cache - .lock() - .unwrap() - .clear(); - } - if amount > 2 { - self.rooms - .state_accessor - .user_visibility_cache - .lock() - .unwrap() - .clear(); - } - if amount > 3 { - self.rooms - .state_compressor - .stateinfo_cache - .lock() - .unwrap() - .clear(); - } - if amount > 4 { - self.rooms - .timeline - .lasttimelinecount_cache - .lock() - .await - .clear(); - } - if amount > 5 { - self.rooms - .spaces - .roomid_spacehierarchy_cache - .lock() - .await - .clear(); - } - if amount > 6 { - self.globals.resolver.overrides.write().unwrap().clear(); - self.globals.resolver.destinations.write().await.clear(); - } - if amount > 7 { - self.globals.resolver.resolver.clear_cache(); - } - if amount > 8 { - self.globals.bad_event_ratelimiter.write().await.clear(); - } - if amount > 9 { - self.globals.bad_query_ratelimiter.write().await.clear(); - } - if amount > 10 { - self.globals.bad_signature_ratelimiter.write().await.clear(); - } - } +#[inline] +pub fn available() -> bool { + SERVICES + .read() + .expect("SERVICES locked for reading") + .is_some() } diff --git a/src/service/pdu.rs b/src/service/pdu.rs index 51f276d4..4912f1c4 100644 --- a/src/service/pdu.rs +++ b/src/service/pdu.rs @@ -23,40 +23,40 @@ use crate::{services, Error}; /// Content hashes of a PDU. #[derive(Clone, Debug, Deserialize, Serialize)] -pub(crate) struct EventHash { +pub struct EventHash { /// The SHA-256 hash. - pub(crate) sha256: String, + pub sha256: String, } #[derive(Clone, Deserialize, Serialize, Debug)] -pub(crate) struct PduEvent { - pub(crate) event_id: Arc, - pub(crate) room_id: OwnedRoomId, - pub(crate) sender: OwnedUserId, +pub struct PduEvent { + pub event_id: Arc, + pub room_id: OwnedRoomId, + pub sender: OwnedUserId, #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) origin: Option, - pub(crate) origin_server_ts: UInt, + pub origin: Option, + pub origin_server_ts: UInt, #[serde(rename = "type")] - pub(crate) kind: TimelineEventType, - pub(crate) content: Box, + pub kind: TimelineEventType, + pub content: Box, #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) state_key: Option, - pub(crate) prev_events: Vec>, - pub(crate) depth: UInt, - pub(crate) auth_events: Vec>, + pub state_key: Option, + pub prev_events: Vec>, + pub depth: UInt, + pub auth_events: Vec>, #[serde(skip_serializing_if = "Option::is_none")] - pub(crate) redacts: Option>, + pub redacts: Option>, #[serde(default, skip_serializing_if = "Option::is_none")] - pub(crate) unsigned: Option>, - pub(crate) hashes: EventHash, + pub unsigned: Option>, + pub hashes: EventHash, #[serde(default, skip_serializing_if = "Option::is_none")] - pub(crate) signatures: Option>, /* BTreeMap, BTreeMap> */ + pub signatures: Option>, /* BTreeMap, BTreeMap> */ } impl PduEvent { #[tracing::instrument(skip(self))] - pub(crate) fn redact(&mut self, room_version_id: RoomVersionId, reason: &PduEvent) -> crate::Result<()> { + pub fn redact(&mut self, room_version_id: RoomVersionId, reason: &PduEvent) -> crate::Result<()> { self.unsigned = None; let mut content = serde_json::from_str(self.content.get()) @@ -76,7 +76,7 @@ impl PduEvent { Ok(()) } - pub(crate) fn remove_transaction_id(&mut self) -> crate::Result<()> { + pub fn remove_transaction_id(&mut self) -> crate::Result<()> { if let Some(unsigned) = &self.unsigned { let mut unsigned: BTreeMap> = serde_json::from_str(unsigned.get()) .map_err(|_| Error::bad_database("Invalid unsigned in pdu event"))?; @@ -87,7 +87,7 @@ impl PduEvent { Ok(()) } - pub(crate) fn add_age(&mut self) -> crate::Result<()> { + pub fn add_age(&mut self) -> crate::Result<()> { let mut unsigned: BTreeMap> = self .unsigned .as_ref() @@ -118,7 +118,7 @@ impl PduEvent { /// > serving /// > such events over the Client-Server API. #[must_use] - pub(crate) fn copy_redacts(&self) -> (Option>, Box) { + pub fn copy_redacts(&self) -> (Option>, Box) { if self.kind == TimelineEventType::RoomRedaction { if let Ok(mut content) = serde_json::from_str::(self.content.get()) { if let Some(redacts) = content.redacts { @@ -137,7 +137,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub(crate) fn to_sync_room_event(&self) -> Raw { + pub fn to_sync_room_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); let mut json = json!({ "content": content, @@ -162,7 +162,7 @@ impl PduEvent { /// This only works for events that are also AnyRoomEvents. #[tracing::instrument(skip(self))] - pub(crate) fn to_any_event(&self) -> Raw { + pub fn to_any_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); let mut json = json!({ "content": content, @@ -187,7 +187,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub(crate) fn to_room_event(&self) -> Raw { + pub fn to_room_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); let mut json = json!({ "content": content, @@ -212,7 +212,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub(crate) fn to_message_like_event(&self) -> Raw { + pub fn to_message_like_event(&self) -> Raw { let (redacts, content) = self.copy_redacts(); let mut json = json!({ "content": content, @@ -237,7 +237,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub(crate) fn to_state_event(&self) -> Raw { + pub fn to_state_event(&self) -> Raw { let mut json = json!({ "content": self.content, "type": self.kind, @@ -256,7 +256,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub(crate) fn to_sync_state_event(&self) -> Raw { + pub fn to_sync_state_event(&self) -> Raw { let mut json = json!({ "content": self.content, "type": self.kind, @@ -274,7 +274,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub(crate) fn to_stripped_state_event(&self) -> Raw { + pub fn to_stripped_state_event(&self) -> Raw { let json = json!({ "content": self.content, "type": self.kind, @@ -286,7 +286,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub(crate) fn to_stripped_spacechild_state_event(&self) -> Raw { + pub fn to_stripped_spacechild_state_event(&self) -> Raw { let json = json!({ "content": self.content, "type": self.kind, @@ -299,7 +299,7 @@ impl PduEvent { } #[tracing::instrument(skip(self))] - pub(crate) fn to_member_event(&self) -> Raw> { + pub fn to_member_event(&self) -> Raw> { let mut json = json!({ "content": self.content, "type": self.kind, @@ -320,7 +320,7 @@ impl PduEvent { /// This does not return a full `Pdu` it is only to satisfy ruma's types. #[tracing::instrument] - pub(crate) fn convert_to_outgoing_federation_event(mut pdu_json: CanonicalJsonObject) -> Box { + pub fn convert_to_outgoing_federation_event(mut pdu_json: CanonicalJsonObject) -> Box { if let Some(unsigned) = pdu_json .get_mut("unsigned") .and_then(|val| val.as_object_mut()) @@ -357,7 +357,7 @@ impl PduEvent { to_raw_value(&pdu_json).expect("CanonicalJson is valid serde_json::Value") } - pub(crate) fn from_id_val(event_id: &EventId, mut json: CanonicalJsonObject) -> Result { + pub fn from_id_val(event_id: &EventId, mut json: CanonicalJsonObject) -> Result { json.insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.as_str().to_owned())); serde_json::from_value(serde_json::to_value(json).expect("valid JSON")) @@ -405,7 +405,7 @@ impl Ord for PduEvent { /// /// Returns a tuple of the new `EventId` and the PDU as a `BTreeMap`. -pub(crate) fn gen_event_id_canonical_json( +pub fn gen_event_id_canonical_json( pdu: &RawJsonValue, room_version_id: &RoomVersionId, ) -> crate::Result<(OwnedEventId, CanonicalJsonObject)> { let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| { @@ -426,11 +426,11 @@ pub(crate) fn gen_event_id_canonical_json( /// Build the start of a PDU in order to add it to the Database. #[derive(Debug, Deserialize)] -pub(crate) struct PduBuilder { +pub struct PduBuilder { #[serde(rename = "type")] - pub(crate) event_type: TimelineEventType, - pub(crate) content: Box, - pub(crate) unsigned: Option>, - pub(crate) state_key: Option, - pub(crate) redacts: Option>, + pub event_type: TimelineEventType, + pub content: Box, + pub unsigned: Option>, + pub state_key: Option, + pub redacts: Option>, } diff --git a/src/service/presence/data.rs b/src/service/presence/data.rs index 6cd1e822..6f0f58f8 100644 --- a/src/service/presence/data.rs +++ b/src/service/presence/data.rs @@ -2,7 +2,7 @@ use ruma::{events::presence::PresenceEvent, presence::PresenceState, OwnedUserId use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { /// Returns the latest presence event for the given user. fn get_presence(&self, user_id: &UserId) -> Result>; diff --git a/src/service/presence/mod.rs b/src/service/presence/mod.rs index d2d1bb39..58be2ddf 100644 --- a/src/service/presence/mod.rs +++ b/src/service/presence/mod.rs @@ -2,7 +2,7 @@ mod data; use std::{sync::Arc, time::Duration}; -pub(crate) use data::Data; +pub use data::Data; use futures_util::{stream::FuturesUnordered, StreamExt}; use ruma::{ events::presence::{PresenceEvent, PresenceEventContent}, @@ -10,19 +10,19 @@ use ruma::{ OwnedUserId, UInt, UserId, }; use serde::{Deserialize, Serialize}; -use tokio::{sync::Mutex, time::sleep}; +use tokio::{sync::Mutex, task::JoinHandle, time::sleep}; use tracing::{debug, error}; use crate::{ - services, - utils::{self, user_id::user_is_local}, + services, user_is_local, + utils::{self}, Config, Error, Result, }; /// Represents data required to be kept in order to implement the presence /// specification. #[derive(Serialize, Deserialize, Debug, Clone)] -pub(crate) struct Presence { +pub struct Presence { state: PresenceState, currently_active: bool, last_active_ts: u64, @@ -30,9 +30,8 @@ pub(crate) struct Presence { } impl Presence { - pub(crate) fn new( - state: PresenceState, currently_active: bool, last_active_ts: u64, status_msg: Option, - ) -> Self { + #[must_use] + pub fn new(state: PresenceState, currently_active: bool, last_active_ts: u64, status_msg: Option) -> Self { Self { state, currently_active, @@ -41,21 +40,21 @@ impl Presence { } } - pub(crate) fn from_json_bytes_to_event(bytes: &[u8], user_id: &UserId) -> Result { + pub fn from_json_bytes_to_event(bytes: &[u8], user_id: &UserId) -> Result { let presence = Self::from_json_bytes(bytes)?; presence.to_presence_event(user_id) } - pub(crate) fn from_json_bytes(bytes: &[u8]) -> Result { + pub fn from_json_bytes(bytes: &[u8]) -> Result { serde_json::from_slice(bytes).map_err(|_| Error::bad_database("Invalid presence data in database")) } - pub(crate) fn to_json_bytes(&self) -> Result> { + pub fn to_json_bytes(&self) -> Result> { serde_json::to_vec(self).map_err(|_| Error::bad_database("Could not serialize Presence to JSON")) } /// Creates a PresenceEvent from available data. - pub(crate) fn to_presence_event(&self, user_id: &UserId) -> Result { + pub fn to_presence_event(&self, user_id: &UserId) -> Result { let now = utils::millis_since_unix_epoch(); let last_active_ago = if self.currently_active { None @@ -77,37 +76,55 @@ impl Presence { } } -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, - pub(crate) timer_sender: loole::Sender<(OwnedUserId, Duration)>, +pub struct Service { + pub db: Arc, + pub timer_sender: loole::Sender<(OwnedUserId, Duration)>, timer_receiver: Mutex>, + handler_join: Mutex>>, timeout_remote_users: bool, } impl Service { - pub(crate) fn build(db: &'static dyn Data, config: &Config) -> Arc { + pub fn build(db: Arc, config: &Config) -> Arc { let (timer_sender, timer_receiver) = loole::unbounded(); - Arc::new(Self { db, timer_sender, timer_receiver: Mutex::new(timer_receiver), + handler_join: Mutex::new(None), timeout_remote_users: config.presence_timeout_remote_users, }) } - pub(crate) fn start_handler(self: &Arc) { + pub async fn start_handler(self: &Arc) { let self_ = Arc::clone(self); - tokio::spawn(async move { + let handle = services().server.runtime().spawn(async move { self_ .handler() .await .expect("Failed to start presence handler"); }); + + _ = self.handler_join.lock().await.insert(handle); + } + + pub async fn close(&self) { + self.interrupt(); + if let Some(handler_join) = self.handler_join.lock().await.take() { + if let Err(e) = handler_join.await { + error!("Failed to shutdown: {e:?}"); + } + } + } + + pub fn interrupt(&self) { + if !self.timer_sender.is_closed() { + self.timer_sender.close(); + } } /// Returns the latest presence event for the given user. - pub(crate) fn get_presence(&self, user_id: &UserId) -> Result> { + pub fn get_presence(&self, user_id: &UserId) -> Result> { if let Some((_, presence)) = self.db.get_presence(user_id)? { Ok(Some(presence)) } else { @@ -117,7 +134,7 @@ impl Service { /// Pings the presence of the given user in the given room, setting the /// specified state. - pub(crate) fn ping_presence(&self, user_id: &UserId, new_state: &PresenceState) -> Result<()> { + pub fn ping_presence(&self, user_id: &UserId, new_state: &PresenceState) -> Result<()> { const REFRESH_TIMEOUT: u64 = 60 * 25 * 1000; let last_presence = self.db.get_presence(user_id)?; @@ -146,7 +163,7 @@ impl Service { } /// Adds a presence event which will be saved until a new event replaces it. - pub(crate) fn set_presence( + pub fn set_presence( &self, user_id: &UserId, state: &PresenceState, currently_active: Option, last_active_ago: Option, status_msg: Option, ) -> Result<()> { @@ -179,11 +196,11 @@ impl Service { /// /// TODO: Why is this not used? #[allow(dead_code)] - pub(crate) fn remove_presence(&self, user_id: &UserId) -> Result<()> { self.db.remove_presence(user_id) } + pub fn remove_presence(&self, user_id: &UserId) -> Result<()> { self.db.remove_presence(user_id) } /// Returns the most recent presence updates that happened after the event /// with id `since`. - pub(crate) fn presence_since(&self, since: u64) -> Box)>> { + pub fn presence_since(&self, since: u64) -> Box)> + '_> { self.db.presence_since(since) } @@ -191,24 +208,16 @@ impl Service { let mut presence_timers = FuturesUnordered::new(); let receiver = self.timer_receiver.lock().await; loop { + debug_assert!(!receiver.is_closed(), "channel error"); tokio::select! { - event = receiver.recv_async() => { - - match event { - Ok((user_id, timeout)) => { - debug!("Adding timer {}: {user_id} timeout:{timeout:?}", presence_timers.len()); - presence_timers.push(presence_timer(user_id, timeout)); - } - Err(e) => { - // generally shouldn't happen - error!("Failed to receive presence timer through channel: {e}"); - } - } - } - - Some(user_id) = presence_timers.next() => { - process_presence_timer(&user_id)?; - } + Some(user_id) = presence_timers.next() => process_presence_timer(&user_id)?, + event = receiver.recv_async() => match event { + Err(_e) => return Ok(()), + Ok((user_id, timeout)) => { + debug!("Adding timer {}: {user_id} timeout:{timeout:?}", presence_timers.len()); + presence_timers.push(presence_timer(user_id, timeout)); + }, + }, } } } diff --git a/src/service/pusher/data.rs b/src/service/pusher/data.rs index 0a5e2eb9..b58cd3fc 100644 --- a/src/service/pusher/data.rs +++ b/src/service/pusher/data.rs @@ -5,7 +5,7 @@ use ruma::{ use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()>; fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result>; diff --git a/src/service/pusher/mod.rs b/src/service/pusher/mod.rs index 3f7c5d80..19a570c4 100644 --- a/src/service/pusher/mod.rs +++ b/src/service/pusher/mod.rs @@ -1,8 +1,8 @@ mod data; -use std::{fmt::Debug, mem}; +use std::{fmt::Debug, mem, sync::Arc}; use bytes::BytesMut; -pub(crate) use data::Data; +pub use data::Data; use ipaddress::IPAddress; use ruma::{ api::{ @@ -24,27 +24,28 @@ use tracing::{info, trace, warn}; use crate::{debug_info, services, Error, PduEvent, Result}; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { - pub(crate) fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()> { + pub fn set_pusher(&self, sender: &UserId, pusher: set_pusher::v3::PusherAction) -> Result<()> { self.db.set_pusher(sender, pusher) } - pub(crate) fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result> { + pub fn get_pusher(&self, sender: &UserId, pushkey: &str) -> Result> { self.db.get_pusher(sender, pushkey) } - pub(crate) fn get_pushers(&self, sender: &UserId) -> Result> { self.db.get_pushers(sender) } + pub fn get_pushers(&self, sender: &UserId) -> Result> { self.db.get_pushers(sender) } - pub(crate) fn get_pushkeys(&self, sender: &UserId) -> Box>> { + #[must_use] + pub fn get_pushkeys(&self, sender: &UserId) -> Box> + '_> { self.db.get_pushkeys(sender) } #[tracing::instrument(skip(self, dest, request))] - pub(crate) async fn send_request(&self, dest: &str, request: T) -> Result + pub async fn send_request(&self, dest: &str, request: T) -> Result where T: OutgoingRequest + Debug, { @@ -131,7 +132,7 @@ impl Service { } #[tracing::instrument(skip(self, user, unread, pusher, ruleset, pdu))] - pub(crate) async fn send_push_notice( + pub async fn send_push_notice( &self, user: &UserId, unread: UInt, pusher: &Pusher, ruleset: Ruleset, pdu: &PduEvent, ) -> Result<()> { let mut notify = None; @@ -176,7 +177,7 @@ impl Service { } #[tracing::instrument(skip(self, user, ruleset, pdu))] - pub(crate) fn get_actions<'a>( + pub fn get_actions<'a>( &self, user: &UserId, ruleset: &'a Ruleset, power_levels: &RoomPowerLevelsEventContent, pdu: &Raw, room_id: &RoomId, ) -> Result<&'a [Action]> { diff --git a/src/service/rooms/alias/data.rs b/src/service/rooms/alias/data.rs index acb2ecd6..095d6e66 100644 --- a/src/service/rooms/alias/data.rs +++ b/src/service/rooms/alias/data.rs @@ -2,7 +2,7 @@ use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId}; use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { /// Creates or updates the alias to the given room id. fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()>; diff --git a/src/service/rooms/alias/mod.rs b/src/service/rooms/alias/mod.rs index 0c95a8a9..6e8b386a 100644 --- a/src/service/rooms/alias/mod.rs +++ b/src/service/rooms/alias/mod.rs @@ -1,37 +1,37 @@ mod data; -pub(crate) use data::Data; +use std::sync::Arc; + +pub use data::Data; use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId}; use crate::Result; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { #[tracing::instrument(skip(self))] - pub(crate) fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()> { - self.db.set_alias(alias, room_id) - } + pub fn set_alias(&self, alias: &RoomAliasId, room_id: &RoomId) -> Result<()> { self.db.set_alias(alias, room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> { self.db.remove_alias(alias) } + pub fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> { self.db.remove_alias(alias) } #[tracing::instrument(skip(self))] - pub(crate) fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result> { + pub fn resolve_local_alias(&self, alias: &RoomAliasId) -> Result> { self.db.resolve_local_alias(alias) } #[tracing::instrument(skip(self))] - pub(crate) fn local_aliases_for_room<'a>( + pub fn local_aliases_for_room<'a>( &'a self, room_id: &RoomId, ) -> Box> + 'a> { self.db.local_aliases_for_room(room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn all_local_aliases<'a>(&'a self) -> Box> + 'a> { + pub fn all_local_aliases<'a>(&'a self) -> Box> + 'a> { self.db.all_local_aliases() } } diff --git a/src/service/rooms/auth_chain/data.rs b/src/service/rooms/auth_chain/data.rs index baa63ebd..f77d2d90 100644 --- a/src/service/rooms/auth_chain/data.rs +++ b/src/service/rooms/auth_chain/data.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn get_cached_eventid_authchain(&self, shorteventid: &[u64]) -> Result>>; fn cache_auth_chain(&self, shorteventid: Vec, auth_chain: Arc<[u64]>) -> Result<()>; } diff --git a/src/service/rooms/auth_chain/mod.rs b/src/service/rooms/auth_chain/mod.rs index 4a59d989..4c9152b0 100644 --- a/src/service/rooms/auth_chain/mod.rs +++ b/src/service/rooms/auth_chain/mod.rs @@ -4,18 +4,18 @@ use std::{ sync::Arc, }; -pub(crate) use data::Data; +pub use data::Data; use ruma::{api::client::error::ErrorKind, EventId, RoomId}; use tracing::{debug, error, trace, warn}; use crate::{services, utils::debug_slice_truncated, Error, Result}; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { - pub(crate) async fn event_ids_iter<'a>( + pub async fn event_ids_iter<'a>( &self, room_id: &RoomId, starting_events_: Vec>, ) -> Result> + 'a> { let mut starting_events: Vec<&EventId> = Vec::with_capacity(starting_events_.len()); @@ -31,7 +31,7 @@ impl Service { } #[tracing::instrument(skip(self), fields(starting_events = debug_slice_truncated(starting_events, 5)))] - pub(crate) async fn get_auth_chain(&self, room_id: &RoomId, starting_events: &[&EventId]) -> Result> { + pub async fn get_auth_chain(&self, room_id: &RoomId, starting_events: &[&EventId]) -> Result> { const NUM_BUCKETS: usize = 50; //TODO: change possible w/o disrupting db? const BUCKET: BTreeSet<(u64, &EventId)> = BTreeSet::new(); @@ -172,18 +172,18 @@ impl Service { Ok(found) } - pub(crate) fn get_cached_eventid_authchain(&self, key: &[u64]) -> Result>> { + pub fn get_cached_eventid_authchain(&self, key: &[u64]) -> Result>> { self.db.get_cached_eventid_authchain(key) } #[tracing::instrument(skip(self))] - pub(crate) fn cache_auth_chain(&self, key: Vec, auth_chain: &HashSet) -> Result<()> { + pub fn cache_auth_chain(&self, key: Vec, auth_chain: &HashSet) -> Result<()> { self.db .cache_auth_chain(key, auth_chain.iter().copied().collect::>()) } #[tracing::instrument(skip(self))] - pub(crate) fn cache_auth_chain_vec(&self, key: Vec, auth_chain: &Vec) -> Result<()> { + pub fn cache_auth_chain_vec(&self, key: Vec, auth_chain: &Vec) -> Result<()> { self.db .cache_auth_chain(key, auth_chain.iter().copied().collect::>()) } diff --git a/src/service/rooms/directory/data.rs b/src/service/rooms/directory/data.rs index 6efb1af4..691b8604 100644 --- a/src/service/rooms/directory/data.rs +++ b/src/service/rooms/directory/data.rs @@ -2,7 +2,7 @@ use ruma::{OwnedRoomId, RoomId}; use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { /// Adds the room to the public room directory fn set_public(&self, room_id: &RoomId) -> Result<()>; diff --git a/src/service/rooms/directory/mod.rs b/src/service/rooms/directory/mod.rs index 63a0abbf..ab69d003 100644 --- a/src/service/rooms/directory/mod.rs +++ b/src/service/rooms/directory/mod.rs @@ -1,24 +1,26 @@ mod data; -pub(crate) use data::Data; +use std::sync::Arc; + +pub use data::Data; use ruma::{OwnedRoomId, RoomId}; use crate::Result; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { #[tracing::instrument(skip(self))] - pub(crate) fn set_public(&self, room_id: &RoomId) -> Result<()> { self.db.set_public(room_id) } + pub fn set_public(&self, room_id: &RoomId) -> Result<()> { self.db.set_public(room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn set_not_public(&self, room_id: &RoomId) -> Result<()> { self.db.set_not_public(room_id) } + pub fn set_not_public(&self, room_id: &RoomId) -> Result<()> { self.db.set_not_public(room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn is_public_room(&self, room_id: &RoomId) -> Result { self.db.is_public_room(room_id) } + pub fn is_public_room(&self, room_id: &RoomId) -> Result { self.db.is_public_room(room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn public_rooms(&self) -> impl Iterator> + '_ { self.db.public_rooms() } + pub fn public_rooms(&self) -> impl Iterator> + '_ { self.db.public_rooms() } } diff --git a/src/service/rooms/event_handler/mod.rs b/src/service/rooms/event_handler/mod.rs index 1a965c0e..499d1d63 100644 --- a/src/service/rooms/event_handler/mod.rs +++ b/src/service/rooms/event_handler/mod.rs @@ -1,11 +1,17 @@ +mod parse_incoming_pdu; +mod signing_keys; +pub struct Service; + use std::{ cmp, - collections::{hash_map, HashSet}, + collections::{hash_map, BTreeMap, HashMap, HashSet}, pin::Pin, + sync::Arc, time::{Duration, Instant}, }; use futures_util::Future; +pub use parse_incoming_pdu::parse_incoming_pdu; use ruma::{ api::{ client::error::ErrorKind, @@ -24,14 +30,7 @@ use tokio::sync::RwLock; use tracing::{debug, error, info, trace, warn}; use super::state_compressor::CompressedStateEvent; -use crate::{ - debug_error, debug_info, - service::{pdu, Arc, BTreeMap, HashMap, Result}, - services, Error, PduEvent, -}; - -mod signing_keys; -pub(crate) struct Service; +use crate::{debug_error, debug_info, pdu, services, Error, PduEvent, Result}; // We use some AsyncRecursiveType hacks here so we can call async funtion // recursively. @@ -70,7 +69,7 @@ impl Service { /// 14. Check if the event passes auth based on the "current state" of the /// room, if not soft fail it #[tracing::instrument(skip(self, origin, value, is_timeline_event, pub_key_map), name = "pdu")] - pub(crate) async fn handle_incoming_pdu<'a>( + pub async fn handle_incoming_pdu<'a>( &self, origin: &'a ServerName, room_id: &'a RoomId, event_id: &'a EventId, value: BTreeMap, is_timeline_event: bool, pub_key_map: &'a RwLock>>, @@ -207,7 +206,7 @@ impl Service { skip(self, origin, event_id, room_id, pub_key_map, eventid_info, create_event, first_pdu_in_room), name = "prev" )] - pub(crate) async fn handle_prev_pdu<'a>( + pub async fn handle_prev_pdu<'a>( &self, origin: &'a ServerName, event_id: &'a EventId, room_id: &'a RoomId, pub_key_map: &'a RwLock>>, eventid_info: &mut HashMap, (Arc, BTreeMap)>, @@ -427,7 +426,7 @@ impl Service { }) } - pub(crate) async fn upgrade_outlier_to_timeline_pdu( + pub async fn upgrade_outlier_to_timeline_pdu( &self, incoming_pdu: Arc, val: BTreeMap, create_event: &PduEvent, origin: &ServerName, room_id: &RoomId, pub_key_map: &RwLock>>, ) -> Result>> { @@ -748,7 +747,7 @@ impl Service { // TODO: if we know the prev_events of the incoming event we can avoid the // request and build the state from a known point and resolve if > 1 prev_event #[tracing::instrument(skip_all, name = "state")] - pub(crate) async fn state_at_incoming_degree_one( + pub async fn state_at_incoming_degree_one( &self, incoming_pdu: &Arc, ) -> Result>>> { let prev_event = &*incoming_pdu.prev_events[0]; @@ -796,7 +795,7 @@ impl Service { } #[tracing::instrument(skip_all, name = "state")] - pub(crate) async fn state_at_incoming_resolved( + pub async fn state_at_incoming_resolved( &self, incoming_pdu: &Arc, room_id: &RoomId, room_version_id: &RoomVersionId, ) -> Result>>> { debug!("Calculating state at event using state res"); @@ -988,7 +987,7 @@ impl Service { /// b. Look at outlier pdu tree /// c. Ask origin server over federation /// d. TODO: Ask other servers over federation? - pub(crate) fn fetch_and_handle_outliers<'a>( + pub fn fetch_and_handle_outliers<'a>( &'a self, origin: &'a ServerName, events: &'a [Arc], create_event: &'a PduEvent, room_id: &'a RoomId, room_version_id: &'a RoomVersionId, pub_key_map: &'a RwLock>>, ) -> AsyncRecursiveCanonicalJsonVec<'a> { @@ -1275,7 +1274,7 @@ impl Service { /// Returns Ok if the acl allows the server #[tracing::instrument(skip_all)] - pub(crate) fn acl_check(&self, server_name: &ServerName, room_id: &RoomId) -> Result<()> { + pub fn acl_check(&self, server_name: &ServerName, room_id: &RoomId) -> Result<()> { let acl_event = if let Some(acl) = services() .rooms diff --git a/src/service/rooms/event_handler/parse_incoming_pdu.rs b/src/service/rooms/event_handler/parse_incoming_pdu.rs new file mode 100644 index 00000000..133ab66e --- /dev/null +++ b/src/service/rooms/event_handler/parse_incoming_pdu.rs @@ -0,0 +1,31 @@ +use ruma::{api::client::error::ErrorKind, CanonicalJsonObject, OwnedEventId, OwnedRoomId, RoomId}; +use serde_json::value::RawValue as RawJsonValue; +use tracing::warn; + +use crate::{service::pdu::gen_event_id_canonical_json, services, Error, Result}; + +pub fn parse_incoming_pdu(pdu: &RawJsonValue) -> Result<(OwnedEventId, CanonicalJsonObject, OwnedRoomId)> { + let value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| { + warn!("Error parsing incoming event {:?}: {:?}", pdu, e); + Error::BadServerResponse("Invalid PDU in server response") + })?; + + let room_id: OwnedRoomId = value + .get("room_id") + .and_then(|id| RoomId::parse(id.as_str()?).ok()) + .ok_or(Error::BadRequest(ErrorKind::InvalidParam, "Invalid room id in pdu"))?; + + let Ok(room_version_id) = services().rooms.state.get_room_version(&room_id) else { + return Err(Error::Err(format!("Server is not in room {room_id}"))); + }; + + let Ok((event_id, value)) = gen_event_id_canonical_json(pdu, &room_version_id) else { + // Event could not be converted to canonical json + return Err(Error::BadRequest( + ErrorKind::InvalidParam, + "Could not convert event to canonical json.", + )); + }; + + Ok((event_id, value, room_id)) +} diff --git a/src/service/rooms/event_handler/signing_keys.rs b/src/service/rooms/event_handler/signing_keys.rs index 81986a12..98751034 100644 --- a/src/service/rooms/event_handler/signing_keys.rs +++ b/src/service/rooms/event_handler/signing_keys.rs @@ -1,5 +1,5 @@ use std::{ - collections::HashSet, + collections::{BTreeMap, HashMap, HashSet}, time::{Duration, SystemTime}, }; @@ -21,13 +21,10 @@ use serde_json::value::RawValue as RawJsonValue; use tokio::sync::{RwLock, RwLockWriteGuard}; use tracing::{debug, error, info, trace, warn}; -use crate::{ - service::{BTreeMap, HashMap, Result}, - services, Error, -}; +use crate::{services, Error, Result}; impl super::Service { - pub(crate) async fn fetch_required_signing_keys<'a, E>( + pub async fn fetch_required_signing_keys<'a, E>( &'a self, events: E, pub_key_map: &RwLock>>, ) -> Result<()> where @@ -265,7 +262,7 @@ impl super::Service { Ok(()) } - pub(crate) async fn fetch_join_signing_keys( + pub async fn fetch_join_signing_keys( &self, event: &create_join_event::v2::Response, room_version: &RoomVersionId, pub_key_map: &RwLock>>, ) -> Result<()> { @@ -342,7 +339,7 @@ impl super::Service { /// Search the DB for the signing keys of the given server, if we don't have /// them fetch them from the server and save to our DB. #[tracing::instrument(skip_all)] - pub(crate) async fn fetch_signing_keys_for_server( + pub async fn fetch_signing_keys_for_server( &self, origin: &ServerName, signature_ids: Vec, ) -> Result> { let contains_all_ids = |keys: &BTreeMap| signature_ids.iter().all(|id| keys.contains_key(id)); diff --git a/src/service/rooms/lazy_loading/data.rs b/src/service/rooms/lazy_loading/data.rs index 36db0ac8..890a2f98 100644 --- a/src/service/rooms/lazy_loading/data.rs +++ b/src/service/rooms/lazy_loading/data.rs @@ -2,7 +2,7 @@ use ruma::{DeviceId, RoomId, UserId}; use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn lazy_load_was_sent_before( &self, user_id: &UserId, device_id: &DeviceId, room_id: &RoomId, ll_user: &UserId, ) -> Result; diff --git a/src/service/rooms/lazy_loading/mod.rs b/src/service/rooms/lazy_loading/mod.rs index 104da8fc..565a186d 100644 --- a/src/service/rooms/lazy_loading/mod.rs +++ b/src/service/rooms/lazy_loading/mod.rs @@ -1,24 +1,25 @@ mod data; -use std::collections::{HashMap, HashSet}; +use std::{ + collections::{HashMap, HashSet}, + sync::Arc, +}; -pub(crate) use data::Data; +pub use data::Data; use ruma::{DeviceId, OwnedDeviceId, OwnedRoomId, OwnedUserId, RoomId, UserId}; use tokio::sync::Mutex; -use super::timeline::PduCount; -use crate::Result; +use crate::{PduCount, Result}; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, #[allow(clippy::type_complexity)] - pub(crate) lazy_load_waiting: - Mutex>>, + pub lazy_load_waiting: Mutex>>, } impl Service { #[tracing::instrument(skip(self))] - pub(crate) fn lazy_load_was_sent_before( + pub fn lazy_load_was_sent_before( &self, user_id: &UserId, device_id: &DeviceId, room_id: &RoomId, ll_user: &UserId, ) -> Result { self.db @@ -26,7 +27,7 @@ impl Service { } #[tracing::instrument(skip(self))] - pub(crate) async fn lazy_load_mark_sent( + pub async fn lazy_load_mark_sent( &self, user_id: &UserId, device_id: &DeviceId, room_id: &RoomId, lazy_load: HashSet, count: PduCount, ) { @@ -37,7 +38,7 @@ impl Service { } #[tracing::instrument(skip(self))] - pub(crate) async fn lazy_load_confirm_delivery( + pub async fn lazy_load_confirm_delivery( &self, user_id: &UserId, device_id: &DeviceId, room_id: &RoomId, since: PduCount, ) -> Result<()> { if let Some(user_ids) = self.lazy_load_waiting.lock().await.remove(&( @@ -56,7 +57,7 @@ impl Service { } #[tracing::instrument(skip(self))] - pub(crate) fn lazy_load_reset(&self, user_id: &UserId, device_id: &DeviceId, room_id: &RoomId) -> Result<()> { + pub fn lazy_load_reset(&self, user_id: &UserId, device_id: &DeviceId, room_id: &RoomId) -> Result<()> { self.db.lazy_load_reset(user_id, device_id, room_id) } } diff --git a/src/service/rooms/metadata/data.rs b/src/service/rooms/metadata/data.rs index 58d570d0..d702b203 100644 --- a/src/service/rooms/metadata/data.rs +++ b/src/service/rooms/metadata/data.rs @@ -2,7 +2,7 @@ use ruma::{OwnedRoomId, RoomId}; use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn exists(&self, room_id: &RoomId) -> Result; fn iter_ids<'a>(&'a self) -> Box> + 'a>; fn is_disabled(&self, room_id: &RoomId) -> Result; diff --git a/src/service/rooms/metadata/mod.rs b/src/service/rooms/metadata/mod.rs index dd70745a..e14d539d 100644 --- a/src/service/rooms/metadata/mod.rs +++ b/src/service/rooms/metadata/mod.rs @@ -1,32 +1,36 @@ mod data; -pub(crate) use data::Data; +use std::sync::Arc; + +pub use data::Data; use ruma::{OwnedRoomId, RoomId}; use crate::Result; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { /// Checks if a room exists. #[tracing::instrument(skip(self))] - pub(crate) fn exists(&self, room_id: &RoomId) -> Result { self.db.exists(room_id) } + pub fn exists(&self, room_id: &RoomId) -> Result { self.db.exists(room_id) } - pub(crate) fn iter_ids<'a>(&'a self) -> Box> + 'a> { self.db.iter_ids() } + #[must_use] + pub fn iter_ids<'a>(&'a self) -> Box> + 'a> { self.db.iter_ids() } - pub(crate) fn is_disabled(&self, room_id: &RoomId) -> Result { self.db.is_disabled(room_id) } + pub fn is_disabled(&self, room_id: &RoomId) -> Result { self.db.is_disabled(room_id) } - pub(crate) fn disable_room(&self, room_id: &RoomId, disabled: bool) -> Result<()> { + pub fn disable_room(&self, room_id: &RoomId, disabled: bool) -> Result<()> { self.db.disable_room(room_id, disabled) } - pub(crate) fn is_banned(&self, room_id: &RoomId) -> Result { self.db.is_banned(room_id) } + pub fn is_banned(&self, room_id: &RoomId) -> Result { self.db.is_banned(room_id) } - pub(crate) fn ban_room(&self, room_id: &RoomId, banned: bool) -> Result<()> { self.db.ban_room(room_id, banned) } + pub fn ban_room(&self, room_id: &RoomId, banned: bool) -> Result<()> { self.db.ban_room(room_id, banned) } - pub(crate) fn list_banned_rooms<'a>(&'a self) -> Box> + 'a> { + #[must_use] + pub fn list_banned_rooms<'a>(&'a self) -> Box> + 'a> { self.db.list_banned_rooms() } } diff --git a/src/service/rooms/mod.rs b/src/service/rooms/mod.rs index 1b78b1e2..baf3f7b5 100644 --- a/src/service/rooms/mod.rs +++ b/src/service/rooms/mod.rs @@ -1,25 +1,25 @@ -pub(crate) mod alias; -pub(crate) mod auth_chain; -pub(crate) mod directory; -pub(crate) mod event_handler; -pub(crate) mod lazy_loading; -pub(crate) mod metadata; -pub(crate) mod outlier; -pub(crate) mod pdu_metadata; -pub(crate) mod read_receipt; -pub(crate) mod search; -pub(crate) mod short; -pub(crate) mod spaces; -pub(crate) mod state; -pub(crate) mod state_accessor; -pub(crate) mod state_cache; -pub(crate) mod state_compressor; -pub(crate) mod threads; -pub(crate) mod timeline; -pub(crate) mod typing; -pub(crate) mod user; +pub mod alias; +pub mod auth_chain; +pub mod directory; +pub mod event_handler; +pub mod lazy_loading; +pub mod metadata; +pub mod outlier; +pub mod pdu_metadata; +pub mod read_receipt; +pub mod search; +pub mod short; +pub mod spaces; +pub mod state; +pub mod state_accessor; +pub mod state_cache; +pub mod state_compressor; +pub mod threads; +pub mod timeline; +pub mod typing; +pub mod user; -pub(crate) trait Data: +pub trait Data: alias::Data + auth_chain::Data + directory::Data @@ -40,25 +40,25 @@ pub(crate) trait Data: { } -pub(crate) struct Service { - pub(crate) alias: alias::Service, - pub(crate) auth_chain: auth_chain::Service, - pub(crate) directory: directory::Service, - pub(crate) event_handler: event_handler::Service, - pub(crate) lazy_loading: lazy_loading::Service, - pub(crate) metadata: metadata::Service, - pub(crate) outlier: outlier::Service, - pub(crate) pdu_metadata: pdu_metadata::Service, - pub(crate) read_receipt: read_receipt::Service, - pub(crate) search: search::Service, - pub(crate) short: short::Service, - pub(crate) state: state::Service, - pub(crate) state_accessor: state_accessor::Service, - pub(crate) state_cache: state_cache::Service, - pub(crate) state_compressor: state_compressor::Service, - pub(crate) timeline: timeline::Service, - pub(crate) threads: threads::Service, - pub(crate) typing: typing::Service, - pub(crate) spaces: spaces::Service, - pub(crate) user: user::Service, +pub struct Service { + pub alias: alias::Service, + pub auth_chain: auth_chain::Service, + pub directory: directory::Service, + pub event_handler: event_handler::Service, + pub lazy_loading: lazy_loading::Service, + pub metadata: metadata::Service, + pub outlier: outlier::Service, + pub pdu_metadata: pdu_metadata::Service, + pub read_receipt: read_receipt::Service, + pub search: search::Service, + pub short: short::Service, + pub state: state::Service, + pub state_accessor: state_accessor::Service, + pub state_cache: state_cache::Service, + pub state_compressor: state_compressor::Service, + pub timeline: timeline::Service, + pub threads: threads::Service, + pub typing: typing::Service, + pub spaces: spaces::Service, + pub user: user::Service, } diff --git a/src/service/rooms/outlier/data.rs b/src/service/rooms/outlier/data.rs index a5202a0f..18eb3190 100644 --- a/src/service/rooms/outlier/data.rs +++ b/src/service/rooms/outlier/data.rs @@ -2,7 +2,7 @@ use ruma::{CanonicalJsonObject, EventId}; use crate::{PduEvent, Result}; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result>; fn get_outlier_pdu(&self, event_id: &EventId) -> Result>; fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()>; diff --git a/src/service/rooms/outlier/mod.rs b/src/service/rooms/outlier/mod.rs index 0de6d366..9ec4010c 100644 --- a/src/service/rooms/outlier/mod.rs +++ b/src/service/rooms/outlier/mod.rs @@ -1,17 +1,19 @@ mod data; -pub(crate) use data::Data; +use std::sync::Arc; + +pub use data::Data; use ruma::{CanonicalJsonObject, EventId}; use crate::{PduEvent, Result}; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { /// Returns the pdu from the outlier tree. - pub(crate) fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result> { + pub fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result> { self.db.get_outlier_pdu_json(event_id) } @@ -19,13 +21,11 @@ impl Service { /// /// TODO: use this? #[allow(dead_code)] - pub(crate) fn get_pdu_outlier(&self, event_id: &EventId) -> Result> { - self.db.get_outlier_pdu(event_id) - } + pub fn get_pdu_outlier(&self, event_id: &EventId) -> Result> { self.db.get_outlier_pdu(event_id) } /// Append the PDU as an outlier. #[tracing::instrument(skip(self, pdu))] - pub(crate) fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()> { + pub fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()> { self.db.add_pdu_outlier(event_id, pdu) } } diff --git a/src/service/rooms/pdu_metadata/data.rs b/src/service/rooms/pdu_metadata/data.rs index d4026f55..ccc14edd 100644 --- a/src/service/rooms/pdu_metadata/data.rs +++ b/src/service/rooms/pdu_metadata/data.rs @@ -2,9 +2,9 @@ use std::sync::Arc; use ruma::{EventId, RoomId, UserId}; -use crate::{service::rooms::timeline::PduCount, PduEvent, Result}; +use crate::{PduCount, PduEvent, Result}; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn add_relation(&self, from: u64, to: u64) -> Result<()>; #[allow(clippy::type_complexity)] fn relations_until<'a>( diff --git a/src/service/rooms/pdu_metadata/mod.rs b/src/service/rooms/pdu_metadata/mod.rs index 0908c573..7e0da835 100644 --- a/src/service/rooms/pdu_metadata/mod.rs +++ b/src/service/rooms/pdu_metadata/mod.rs @@ -1,7 +1,8 @@ mod data; + use std::sync::Arc; -pub(crate) use data::Data; +pub use data::Data; use ruma::{ api::{client::relations::get_relating_events, Direction}, events::{relation::RelationType, TimelineEventType}, @@ -9,11 +10,10 @@ use ruma::{ }; use serde::Deserialize; -use super::timeline::PduCount; -use crate::{services, PduEvent, Result}; +use crate::{services, PduCount, PduEvent, Result}; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } #[derive(Clone, Debug, Deserialize)] @@ -28,7 +28,7 @@ struct ExtractRelatesToEventId { impl Service { #[tracing::instrument(skip(self, from, to))] - pub(crate) fn add_relation(&self, from: PduCount, to: PduCount) -> Result<()> { + pub fn add_relation(&self, from: PduCount, to: PduCount) -> Result<()> { match (from, to) { (PduCount::Normal(f), PduCount::Normal(t)) => self.db.add_relation(f, t), _ => { @@ -40,7 +40,7 @@ impl Service { } #[allow(clippy::too_many_arguments)] - pub(crate) fn paginate_relations_with_filter( + pub fn paginate_relations_with_filter( &self, sender_user: &UserId, room_id: &RoomId, target: &EventId, filter_event_type: &Option, filter_rel_type: &Option, from: &Option, to: &Option, limit: &Option, recurse: bool, dir: Direction, @@ -174,7 +174,7 @@ impl Service { } } - pub(crate) fn relations_until<'a>( + pub fn relations_until<'a>( &'a self, user_id: &'a UserId, room_id: &'a RoomId, target: &'a EventId, until: PduCount, max_depth: u8, ) -> Result> { let room_id = services().rooms.short.get_or_create_shortroomid(room_id)?; @@ -216,22 +216,18 @@ impl Service { } #[tracing::instrument(skip(self, room_id, event_ids))] - pub(crate) fn mark_as_referenced(&self, room_id: &RoomId, event_ids: &[Arc]) -> Result<()> { + pub fn mark_as_referenced(&self, room_id: &RoomId, event_ids: &[Arc]) -> Result<()> { self.db.mark_as_referenced(room_id, event_ids) } #[tracing::instrument(skip(self))] - pub(crate) fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> Result { + pub fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> Result { self.db.is_event_referenced(room_id, event_id) } #[tracing::instrument(skip(self))] - pub(crate) fn mark_event_soft_failed(&self, event_id: &EventId) -> Result<()> { - self.db.mark_event_soft_failed(event_id) - } + pub fn mark_event_soft_failed(&self, event_id: &EventId) -> Result<()> { self.db.mark_event_soft_failed(event_id) } #[tracing::instrument(skip(self))] - pub(crate) fn is_event_soft_failed(&self, event_id: &EventId) -> Result { - self.db.is_event_soft_failed(event_id) - } + pub fn is_event_soft_failed(&self, event_id: &EventId) -> Result { self.db.is_event_soft_failed(event_id) } } diff --git a/src/service/rooms/read_receipt/data.rs b/src/service/rooms/read_receipt/data.rs index 006b5df8..4fe7be59 100644 --- a/src/service/rooms/read_receipt/data.rs +++ b/src/service/rooms/read_receipt/data.rs @@ -9,7 +9,7 @@ use crate::Result; type AnySyncEphemeralRoomEventIter<'a> = Box)>> + 'a>; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { /// Replaces the previous read receipt. fn readreceipt_update(&self, user_id: &UserId, room_id: &RoomId, event: ReceiptEvent) -> Result<()>; diff --git a/src/service/rooms/read_receipt/mod.rs b/src/service/rooms/read_receipt/mod.rs index 006204ab..a5b9c325 100644 --- a/src/service/rooms/read_receipt/mod.rs +++ b/src/service/rooms/read_receipt/mod.rs @@ -1,17 +1,19 @@ mod data; -pub(crate) use data::Data; +use std::sync::Arc; + +pub use data::Data; use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId}; use crate::{services, Result}; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { /// Replaces the previous read receipt. - pub(crate) fn readreceipt_update(&self, user_id: &UserId, room_id: &RoomId, event: ReceiptEvent) -> Result<()> { + pub fn readreceipt_update(&self, user_id: &UserId, room_id: &RoomId, event: ReceiptEvent) -> Result<()> { self.db.readreceipt_update(user_id, room_id, event)?; services().sending.flush_room(room_id)?; @@ -21,7 +23,7 @@ impl Service { /// Returns an iterator over the most recent read_receipts in a room that /// happened after the event with id `since`. #[tracing::instrument(skip(self))] - pub(crate) fn readreceipts_since<'a>( + pub fn readreceipts_since<'a>( &'a self, room_id: &RoomId, since: u64, ) -> impl Iterator)>> + 'a { self.db.readreceipts_since(room_id, since) @@ -29,18 +31,18 @@ impl Service { /// Sets a private read marker at `count`. #[tracing::instrument(skip(self))] - pub(crate) fn private_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) -> Result<()> { + pub fn private_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) -> Result<()> { self.db.private_read_set(room_id, user_id, count) } /// Returns the private read marker. #[tracing::instrument(skip(self))] - pub(crate) fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result> { + pub fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result> { self.db.private_read_get(room_id, user_id) } /// Returns the count of the last typing update in this room. - pub(crate) fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.last_privateread_update(user_id, room_id) } } diff --git a/src/service/rooms/search/data.rs b/src/service/rooms/search/data.rs index 48edc42b..96439adf 100644 --- a/src/service/rooms/search/data.rs +++ b/src/service/rooms/search/data.rs @@ -4,7 +4,7 @@ use crate::Result; type SearchPdusResult<'a> = Result> + 'a>, Vec)>>; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn index_pdu(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()>; fn search_pdus<'a>(&'a self, room_id: &RoomId, search_string: &str) -> SearchPdusResult<'a>; diff --git a/src/service/rooms/search/mod.rs b/src/service/rooms/search/mod.rs index 50843ae4..569761a3 100644 --- a/src/service/rooms/search/mod.rs +++ b/src/service/rooms/search/mod.rs @@ -1,22 +1,24 @@ mod data; -pub(crate) use data::Data; +use std::sync::Arc; + +pub use data::Data; use ruma::RoomId; use crate::Result; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { #[tracing::instrument(skip(self))] - pub(crate) fn index_pdu(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()> { + pub fn index_pdu(&self, shortroomid: u64, pdu_id: &[u8], message_body: &str) -> Result<()> { self.db.index_pdu(shortroomid, pdu_id, message_body) } #[tracing::instrument(skip(self))] - pub(crate) fn search_pdus<'a>( + pub fn search_pdus<'a>( &'a self, room_id: &RoomId, search_string: &str, ) -> Result> + 'a, Vec)>> { self.db.search_pdus(room_id, search_string) diff --git a/src/service/rooms/short/data.rs b/src/service/rooms/short/data.rs index 4bbed670..d0e2085f 100644 --- a/src/service/rooms/short/data.rs +++ b/src/service/rooms/short/data.rs @@ -4,7 +4,7 @@ use ruma::{events::StateEventType, EventId, RoomId}; use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result; fn multi_get_or_create_shorteventid(&self, event_id: &[&EventId]) -> Result>; diff --git a/src/service/rooms/short/mod.rs b/src/service/rooms/short/mod.rs index ed2eae97..657de66a 100644 --- a/src/service/rooms/short/mod.rs +++ b/src/service/rooms/short/mod.rs @@ -1,48 +1,48 @@ mod data; use std::sync::Arc; -pub(crate) use data::Data; +pub use data::Data; use ruma::{events::StateEventType, EventId, RoomId}; use crate::Result; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { - pub(crate) fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result { + pub fn get_or_create_shorteventid(&self, event_id: &EventId) -> Result { self.db.get_or_create_shorteventid(event_id) } - pub(crate) fn multi_get_or_create_shorteventid(&self, event_ids: &[&EventId]) -> Result> { + pub fn multi_get_or_create_shorteventid(&self, event_ids: &[&EventId]) -> Result> { self.db.multi_get_or_create_shorteventid(event_ids) } - pub(crate) fn get_shortstatekey(&self, event_type: &StateEventType, state_key: &str) -> Result> { + pub fn get_shortstatekey(&self, event_type: &StateEventType, state_key: &str) -> Result> { self.db.get_shortstatekey(event_type, state_key) } - pub(crate) fn get_or_create_shortstatekey(&self, event_type: &StateEventType, state_key: &str) -> Result { + pub fn get_or_create_shortstatekey(&self, event_type: &StateEventType, state_key: &str) -> Result { self.db.get_or_create_shortstatekey(event_type, state_key) } - pub(crate) fn get_eventid_from_short(&self, shorteventid: u64) -> Result> { + pub fn get_eventid_from_short(&self, shorteventid: u64) -> Result> { self.db.get_eventid_from_short(shorteventid) } - pub(crate) fn get_statekey_from_short(&self, shortstatekey: u64) -> Result<(StateEventType, String)> { + pub fn get_statekey_from_short(&self, shortstatekey: u64) -> Result<(StateEventType, String)> { self.db.get_statekey_from_short(shortstatekey) } /// Returns (shortstatehash, already_existed) - pub(crate) fn get_or_create_shortstatehash(&self, state_hash: &[u8]) -> Result<(u64, bool)> { + pub fn get_or_create_shortstatehash(&self, state_hash: &[u8]) -> Result<(u64, bool)> { self.db.get_or_create_shortstatehash(state_hash) } - pub(crate) fn get_shortroomid(&self, room_id: &RoomId) -> Result> { self.db.get_shortroomid(room_id) } + pub fn get_shortroomid(&self, room_id: &RoomId) -> Result> { self.db.get_shortroomid(room_id) } - pub(crate) fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result { + pub fn get_or_create_shortroomid(&self, room_id: &RoomId) -> Result { self.db.get_or_create_shortroomid(room_id) } } diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index d2624197..219b8c39 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -32,9 +32,9 @@ use ruma::{ use tokio::sync::Mutex; use tracing::{debug, error, warn}; -use crate::{debug_info, services, utils::server_name::server_is_ours, Error, Result}; +use crate::{debug_info, server_is_ours, services, Error, Result}; -pub(crate) struct CachedSpaceHierarchySummary { +pub struct CachedSpaceHierarchySummary { summary: SpaceHierarchyParentSummary, } @@ -235,11 +235,11 @@ impl Arena { // Note: perhaps use some better form of token rather than just room count #[derive(Debug, PartialEq)] -pub(crate) struct PagnationToken { - pub(crate) skip: UInt, - pub(crate) limit: UInt, - pub(crate) max_depth: UInt, - pub(crate) suggested_only: bool, +pub struct PagnationToken { + pub skip: UInt, + pub limit: UInt, + pub max_depth: UInt, + pub suggested_only: bool, } impl FromStr for PagnationToken { @@ -294,8 +294,8 @@ enum Identifier<'a> { None, } -pub(crate) struct Service { - pub(crate) roomid_spacehierarchy_cache: Mutex>>, +pub struct Service { + pub roomid_spacehierarchy_cache: Mutex>>, } // Here because cannot implement `From` across ruma-federation-api and @@ -338,7 +338,7 @@ impl Service { /// ///Panics if the room does not exist, so a check if the room exists should /// be done - pub(crate) async fn get_federation_hierarchy( + pub async fn get_federation_hierarchy( &self, room_id: &RoomId, server_name: &ServerName, suggested_only: bool, ) -> Result { match self @@ -624,7 +624,7 @@ impl Service { } // TODO: make this a lot less messy - pub(crate) async fn get_client_hierarchy( + pub async fn get_client_hierarchy( &self, sender_user: &UserId, room_id: &RoomId, limit: usize, skip: usize, max_depth: usize, suggested_only: bool, ) -> Result { diff --git a/src/service/rooms/state/data.rs b/src/service/rooms/state/data.rs index 88d9fe92..f486f1f8 100644 --- a/src/service/rooms/state/data.rs +++ b/src/service/rooms/state/data.rs @@ -5,7 +5,7 @@ use tokio::sync::MutexGuard; use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { /// Returns the last state hash key added to the db for the given room. fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result>; diff --git a/src/service/rooms/state/mod.rs b/src/service/rooms/state/mod.rs index bbc561f2..8031d566 100644 --- a/src/service/rooms/state/mod.rs +++ b/src/service/rooms/state/mod.rs @@ -4,7 +4,7 @@ use std::{ sync::Arc, }; -pub(crate) use data::Data; +pub use data::Data; use ruma::{ api::client::error::ErrorKind, events::{ @@ -21,13 +21,13 @@ use tracing::warn; use super::state_compressor::CompressedStateEvent; use crate::{services, utils::calculate_hash, Error, PduEvent, Result}; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { /// Set the room to the given statehash and update caches. - pub(crate) async fn force_state( + pub async fn force_state( &self, room_id: &RoomId, shortstatehash: u64, @@ -104,7 +104,7 @@ impl Service { /// This adds all current state events (not including the incoming event) /// to `stateid_pduid` and adds the incoming event to `eventid_statehash`. #[tracing::instrument(skip(self, state_ids_compressed))] - pub(crate) fn set_event_state( + pub fn set_event_state( &self, event_id: &EventId, room_id: &RoomId, state_ids_compressed: Arc>, ) -> Result { let shorteventid = services() @@ -172,7 +172,7 @@ impl Service { /// This adds all current state events (not including the incoming event) /// to `stateid_pduid` and adds the incoming event to `eventid_statehash`. #[tracing::instrument(skip(self, new_pdu))] - pub(crate) fn append_to_state(&self, new_pdu: &PduEvent) -> Result { + pub fn append_to_state(&self, new_pdu: &PduEvent) -> Result { let shorteventid = services() .rooms .short @@ -244,7 +244,7 @@ impl Service { } #[tracing::instrument(skip(self, invite_event))] - pub(crate) fn calculate_invite_state(&self, invite_event: &PduEvent) -> Result>> { + pub fn calculate_invite_state(&self, invite_event: &PduEvent) -> Result>> { let mut state = Vec::new(); // Add recommended events if let Some(e) = @@ -300,7 +300,7 @@ impl Service { /// Set the state hash to a new version, but does not update state_cache. #[tracing::instrument(skip(self))] - pub(crate) fn set_room_state( + pub fn set_room_state( &self, room_id: &RoomId, shortstatehash: u64, @@ -311,7 +311,7 @@ impl Service { /// Returns the room's version. #[tracing::instrument(skip(self))] - pub(crate) fn get_room_version(&self, room_id: &RoomId) -> Result { + pub fn get_room_version(&self, room_id: &RoomId) -> Result { let create_event = services() .rooms .state_accessor @@ -331,15 +331,15 @@ impl Service { Ok(create_event_content.room_version) } - pub(crate) fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result> { + pub fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result> { self.db.get_room_shortstatehash(room_id) } - pub(crate) fn get_forward_extremities(&self, room_id: &RoomId) -> Result>> { + pub fn get_forward_extremities(&self, room_id: &RoomId) -> Result>> { self.db.get_forward_extremities(room_id) } - pub(crate) fn set_forward_extremities( + pub fn set_forward_extremities( &self, room_id: &RoomId, event_ids: Vec, @@ -351,7 +351,7 @@ impl Service { /// This fetches auth events from the current state. #[tracing::instrument(skip(self))] - pub(crate) fn get_auth_events( + pub fn get_auth_events( &self, room_id: &RoomId, kind: &TimelineEventType, sender: &UserId, state_key: Option<&str>, content: &serde_json::value::RawValue, ) -> Result>> { diff --git a/src/service/rooms/state_accessor/data.rs b/src/service/rooms/state_accessor/data.rs index 9bc2667f..5fd58864 100644 --- a/src/service/rooms/state_accessor/data.rs +++ b/src/service/rooms/state_accessor/data.rs @@ -6,7 +6,7 @@ use ruma::{events::StateEventType, EventId, RoomId}; use crate::{PduEvent, Result}; #[async_trait] -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { /// Builds a StateMap by iterating over all keys that start /// with state_hash, this gives the full state for the given state_hash. #[allow(unused_qualifications)] // async traits diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index 43cbb3bd..d2e51361 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -4,7 +4,7 @@ use std::{ sync::{Arc, Mutex}, }; -pub(crate) use data::Data; +pub use data::Data; use lru_cache::LruCache; use ruma::{ events::{ @@ -24,30 +24,28 @@ use tracing::{error, warn}; use crate::{service::pdu::PduBuilder, services, Error, PduEvent, Result}; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, - pub(crate) server_visibility_cache: Mutex>, - pub(crate) user_visibility_cache: Mutex>, +pub struct Service { + pub db: Arc, + pub server_visibility_cache: Mutex>, + pub user_visibility_cache: Mutex>, } impl Service { /// Builds a StateMap by iterating over all keys that start /// with state_hash, this gives the full state for the given state_hash. #[tracing::instrument(skip(self))] - pub(crate) async fn state_full_ids(&self, shortstatehash: u64) -> Result>> { + pub async fn state_full_ids(&self, shortstatehash: u64) -> Result>> { self.db.state_full_ids(shortstatehash).await } - pub(crate) async fn state_full( - &self, shortstatehash: u64, - ) -> Result>> { + pub async fn state_full(&self, shortstatehash: u64) -> Result>> { self.db.state_full(shortstatehash).await } /// Returns a single PDU from `room_id` with key (`event_type`, /// `state_key`). #[tracing::instrument(skip(self))] - pub(crate) fn state_get_id( + pub fn state_get_id( &self, shortstatehash: u64, event_type: &StateEventType, state_key: &str, ) -> Result>> { self.db.state_get_id(shortstatehash, event_type, state_key) @@ -55,7 +53,7 @@ impl Service { /// Returns a single PDU from `room_id` with key (`event_type`, /// `state_key`). - pub(crate) fn state_get( + pub fn state_get( &self, shortstatehash: u64, event_type: &StateEventType, state_key: &str, ) -> Result>> { self.db.state_get(shortstatehash, event_type, state_key) @@ -90,9 +88,7 @@ impl Service { /// Whether a server is allowed to see an event through federation, based on /// the room's history_visibility at that event's state. #[tracing::instrument(skip(self, origin, room_id, event_id))] - pub(crate) fn server_can_see_event( - &self, origin: &ServerName, room_id: &RoomId, event_id: &EventId, - ) -> Result { + pub fn server_can_see_event(&self, origin: &ServerName, room_id: &RoomId, event_id: &EventId) -> Result { let Some(shortstatehash) = self.pdu_shortstatehash(event_id)? else { return Ok(true); }; @@ -155,7 +151,7 @@ impl Service { /// Whether a user is allowed to see an event, based on /// the room's history_visibility at that event's state. #[tracing::instrument(skip(self, user_id, room_id, event_id))] - pub(crate) fn user_can_see_event(&self, user_id: &UserId, room_id: &RoomId, event_id: &EventId) -> Result { + pub fn user_can_see_event(&self, user_id: &UserId, room_id: &RoomId, event_id: &EventId) -> Result { let Some(shortstatehash) = self.pdu_shortstatehash(event_id)? else { return Ok(true); }; @@ -214,7 +210,7 @@ impl Service { /// Whether a user is allowed to see an event, based on /// the room's history_visibility at that event's state. #[tracing::instrument(skip(self, user_id, room_id))] - pub(crate) fn user_can_see_state_events(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub fn user_can_see_state_events(&self, user_id: &UserId, room_id: &RoomId) -> Result { let currently_member = services().rooms.state_cache.is_joined(user_id, room_id)?; let history_visibility = self @@ -236,22 +232,18 @@ impl Service { } /// Returns the state hash for this pdu. - pub(crate) fn pdu_shortstatehash(&self, event_id: &EventId) -> Result> { - self.db.pdu_shortstatehash(event_id) - } + pub fn pdu_shortstatehash(&self, event_id: &EventId) -> Result> { self.db.pdu_shortstatehash(event_id) } /// Returns the full room state. #[tracing::instrument(skip(self))] - pub(crate) async fn room_state_full( - &self, room_id: &RoomId, - ) -> Result>> { + pub async fn room_state_full(&self, room_id: &RoomId) -> Result>> { self.db.room_state_full(room_id).await } /// Returns a single PDU from `room_id` with key (`event_type`, /// `state_key`). #[tracing::instrument(skip(self))] - pub(crate) fn room_state_get_id( + pub fn room_state_get_id( &self, room_id: &RoomId, event_type: &StateEventType, state_key: &str, ) -> Result>> { self.db.room_state_get_id(room_id, event_type, state_key) @@ -260,13 +252,13 @@ impl Service { /// Returns a single PDU from `room_id` with key (`event_type`, /// `state_key`). #[tracing::instrument(skip(self))] - pub(crate) fn room_state_get( + pub fn room_state_get( &self, room_id: &RoomId, event_type: &StateEventType, state_key: &str, ) -> Result>> { self.db.room_state_get(room_id, event_type, state_key) } - pub(crate) fn get_name(&self, room_id: &RoomId) -> Result> { + pub fn get_name(&self, room_id: &RoomId) -> Result> { services() .rooms .state_accessor @@ -276,7 +268,7 @@ impl Service { }) } - pub(crate) fn get_avatar(&self, room_id: &RoomId) -> Result> { + pub fn get_avatar(&self, room_id: &RoomId) -> Result> { services() .rooms .state_accessor @@ -287,7 +279,7 @@ impl Service { }) } - pub(crate) fn get_member(&self, room_id: &RoomId, user_id: &UserId) -> Result> { + pub fn get_member(&self, room_id: &RoomId, user_id: &UserId) -> Result> { services() .rooms .state_accessor @@ -298,7 +290,7 @@ impl Service { }) } - pub(crate) async fn user_can_invite( + pub async fn user_can_invite( &self, room_id: &RoomId, sender: &UserId, target_user: &UserId, state_lock: &MutexGuard<'_, ()>, ) -> Result { let content = to_raw_value(&RoomMemberEventContent::new(MembershipState::Invite)) diff --git a/src/service/rooms/state_cache/data.rs b/src/service/rooms/state_cache/data.rs index 828d4284..70fcd6d1 100644 --- a/src/service/rooms/state_cache/data.rs +++ b/src/service/rooms/state_cache/data.rs @@ -12,7 +12,7 @@ type StrippedStateEventIter<'a> = Box = Box>)>> + 'a>; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn mark_as_once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>; fn mark_as_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>; fn mark_as_invited( diff --git a/src/service/rooms/state_cache/mod.rs b/src/service/rooms/state_cache/mod.rs index 9f2ccdf4..976d858b 100644 --- a/src/service/rooms/state_cache/mod.rs +++ b/src/service/rooms/state_cache/mod.rs @@ -1,6 +1,6 @@ use std::{collections::HashSet, sync::Arc}; -pub(crate) use data::Data; +pub use data::Data; use itertools::Itertools; use ruma::{ events::{ @@ -19,19 +19,19 @@ use ruma::{ }; use tracing::{error, warn}; -use crate::{service::appservice::RegistrationInfo, services, utils::user_id::user_is_local, Error, Result}; +use crate::{service::appservice::RegistrationInfo, services, user_is_local, Error, Result}; mod data; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { /// Update current membership data. #[tracing::instrument(skip(self, last_state))] #[allow(clippy::too_many_arguments)] - pub(crate) fn update_membership( + pub fn update_membership( &self, room_id: &RoomId, user_id: &UserId, membership_event: RoomMemberEventContent, sender: &UserId, last_state: Option>>, invite_via: Option>, update_joined_count: bool, @@ -210,43 +210,43 @@ impl Service { } #[tracing::instrument(skip(self, room_id))] - pub(crate) fn update_joined_count(&self, room_id: &RoomId) -> Result<()> { self.db.update_joined_count(room_id) } + pub fn update_joined_count(&self, room_id: &RoomId) -> Result<()> { self.db.update_joined_count(room_id) } #[tracing::instrument(skip(self, room_id))] - pub(crate) fn get_our_real_users(&self, room_id: &RoomId) -> Result>> { + pub fn get_our_real_users(&self, room_id: &RoomId) -> Result>> { self.db.get_our_real_users(room_id) } #[tracing::instrument(skip(self, room_id, appservice))] - pub(crate) fn appservice_in_room(&self, room_id: &RoomId, appservice: &RegistrationInfo) -> Result { + pub fn appservice_in_room(&self, room_id: &RoomId, appservice: &RegistrationInfo) -> Result { self.db.appservice_in_room(room_id, appservice) } /// Makes a user forget a room. #[tracing::instrument(skip(self))] - pub(crate) fn forget(&self, room_id: &RoomId, user_id: &UserId) -> Result<()> { self.db.forget(room_id, user_id) } + pub fn forget(&self, room_id: &RoomId, user_id: &UserId) -> Result<()> { self.db.forget(room_id, user_id) } /// Returns an iterator of all servers participating in this room. #[tracing::instrument(skip(self))] - pub(crate) fn room_servers<'a>(&'a self, room_id: &RoomId) -> impl Iterator> + 'a { + pub fn room_servers<'a>(&'a self, room_id: &RoomId) -> impl Iterator> + 'a { self.db.room_servers(room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn server_in_room(&self, server: &ServerName, room_id: &RoomId) -> Result { + pub fn server_in_room(&self, server: &ServerName, room_id: &RoomId) -> Result { self.db.server_in_room(server, room_id) } /// Returns an iterator of all rooms a server participates in (as far as we /// know). #[tracing::instrument(skip(self))] - pub(crate) fn server_rooms<'a>(&'a self, server: &ServerName) -> impl Iterator> + 'a { + pub fn server_rooms<'a>(&'a self, server: &ServerName) -> impl Iterator> + 'a { self.db.server_rooms(server) } /// Returns true if server can see user by sharing at least one room. #[tracing::instrument(skip(self))] - pub(crate) fn server_sees_user(&self, server: &ServerName, user_id: &UserId) -> Result { + pub fn server_sees_user(&self, server: &ServerName, user_id: &UserId) -> Result { Ok(self .server_rooms(server) .filter_map(Result::ok) @@ -255,7 +255,7 @@ impl Service { /// Returns true if user_a and user_b share at least one room. #[tracing::instrument(skip(self))] - pub(crate) fn user_sees_user(&self, user_a: &UserId, user_b: &UserId) -> Result { + pub fn user_sees_user(&self, user_a: &UserId, user_b: &UserId) -> Result { // Minimize number of point-queries by iterating user with least nr rooms let (a, b) = if self.rooms_joined(user_a).count() < self.rooms_joined(user_b).count() { (user_a, user_b) @@ -271,104 +271,88 @@ impl Service { /// Returns an iterator over all joined members of a room. #[tracing::instrument(skip(self))] - pub(crate) fn room_members<'a>(&'a self, room_id: &RoomId) -> impl Iterator> + 'a { + pub fn room_members<'a>(&'a self, room_id: &RoomId) -> impl Iterator> + 'a { self.db.room_members(room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn room_joined_count(&self, room_id: &RoomId) -> Result> { - self.db.room_joined_count(room_id) - } + pub fn room_joined_count(&self, room_id: &RoomId) -> Result> { self.db.room_joined_count(room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn room_invited_count(&self, room_id: &RoomId) -> Result> { - self.db.room_invited_count(room_id) - } + pub fn room_invited_count(&self, room_id: &RoomId) -> Result> { self.db.room_invited_count(room_id) } /// Returns an iterator over all User IDs who ever joined a room. #[tracing::instrument(skip(self))] - pub(crate) fn room_useroncejoined<'a>( - &'a self, room_id: &RoomId, - ) -> impl Iterator> + 'a { + pub fn room_useroncejoined<'a>(&'a self, room_id: &RoomId) -> impl Iterator> + 'a { self.db.room_useroncejoined(room_id) } /// Returns an iterator over all invited members of a room. #[tracing::instrument(skip(self))] - pub(crate) fn room_members_invited<'a>( - &'a self, room_id: &RoomId, - ) -> impl Iterator> + 'a { + pub fn room_members_invited<'a>(&'a self, room_id: &RoomId) -> impl Iterator> + 'a { self.db.room_members_invited(room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn get_invite_count(&self, room_id: &RoomId, user_id: &UserId) -> Result> { + pub fn get_invite_count(&self, room_id: &RoomId, user_id: &UserId) -> Result> { self.db.get_invite_count(room_id, user_id) } #[tracing::instrument(skip(self))] - pub(crate) fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result> { + pub fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result> { self.db.get_left_count(room_id, user_id) } /// Returns an iterator over all rooms this user joined. #[tracing::instrument(skip(self))] - pub(crate) fn rooms_joined<'a>(&'a self, user_id: &UserId) -> impl Iterator> + 'a { + pub fn rooms_joined<'a>(&'a self, user_id: &UserId) -> impl Iterator> + 'a { self.db.rooms_joined(user_id) } /// Returns an iterator over all rooms a user was invited to. #[tracing::instrument(skip(self))] - pub(crate) fn rooms_invited<'a>( + pub fn rooms_invited<'a>( &'a self, user_id: &UserId, ) -> impl Iterator>)>> + 'a { self.db.rooms_invited(user_id) } #[tracing::instrument(skip(self))] - pub(crate) fn invite_state( - &self, user_id: &UserId, room_id: &RoomId, - ) -> Result>>> { + pub fn invite_state(&self, user_id: &UserId, room_id: &RoomId) -> Result>>> { self.db.invite_state(user_id, room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn left_state( - &self, user_id: &UserId, room_id: &RoomId, - ) -> Result>>> { + pub fn left_state(&self, user_id: &UserId, room_id: &RoomId) -> Result>>> { self.db.left_state(user_id, room_id) } /// Returns an iterator over all rooms a user left. #[tracing::instrument(skip(self))] - pub(crate) fn rooms_left<'a>( + pub fn rooms_left<'a>( &'a self, user_id: &UserId, ) -> impl Iterator>)>> + 'a { self.db.rooms_left(user_id) } #[tracing::instrument(skip(self))] - pub(crate) fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.once_joined(user_id, room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn is_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result { - self.db.is_joined(user_id, room_id) - } + pub fn is_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.is_joined(user_id, room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.is_invited(user_id, room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> Result { - self.db.is_left(user_id, room_id) - } + pub fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.is_left(user_id, room_id) } #[tracing::instrument(skip(self))] - pub(crate) fn servers_invite_via(&self, room_id: &RoomId) -> Result>> { + pub fn servers_invite_via(&self, room_id: &RoomId) -> Result>> { self.db.servers_invite_via(room_id) } @@ -377,7 +361,7 @@ impl Service { /// /// See #[tracing::instrument(skip(self))] - pub(crate) fn servers_route_via(&self, room_id: &RoomId) -> Result> { + pub fn servers_route_via(&self, room_id: &RoomId) -> Result> { let most_powerful_user_server = services() .rooms .state_accessor diff --git a/src/service/rooms/state_compressor/data.rs b/src/service/rooms/state_compressor/data.rs index 32f902a2..eddc8716 100644 --- a/src/service/rooms/state_compressor/data.rs +++ b/src/service/rooms/state_compressor/data.rs @@ -3,13 +3,13 @@ use std::{collections::HashSet, sync::Arc}; use super::CompressedStateEvent; use crate::Result; -pub(crate) struct StateDiff { - pub(crate) parent: Option, - pub(crate) added: Arc>, - pub(crate) removed: Arc>, +pub struct StateDiff { + pub parent: Option, + pub added: Arc>, + pub removed: Arc>, } -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn get_statediff(&self, shortstatehash: u64) -> Result; fn save_statediff(&self, shortstatehash: u64, diff: StateDiff) -> Result<()>; } diff --git a/src/service/rooms/state_compressor/mod.rs b/src/service/rooms/state_compressor/mod.rs index 8187d8cc..a3622b7b 100644 --- a/src/service/rooms/state_compressor/mod.rs +++ b/src/service/rooms/state_compressor/mod.rs @@ -1,11 +1,11 @@ -pub(crate) mod data; +pub mod data; use std::{ collections::HashSet, mem::size_of, sync::{Arc, Mutex}, }; -pub(crate) use data::Data; +pub use data::Data; use lru_cache::LruCache; use ruma::{EventId, RoomId}; @@ -42,19 +42,19 @@ type ParentStatesVec = Vec<( type HashSetCompressStateEvent = Result<(u64, Arc>, Arc>)>; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, - pub(crate) stateinfo_cache: StateInfoLruCache, + pub stateinfo_cache: StateInfoLruCache, } -pub(crate) type CompressedStateEvent = [u8; 2 * size_of::()]; +pub type CompressedStateEvent = [u8; 2 * size_of::()]; impl Service { /// Returns a stack with info on shortstatehash, full state, added diff and /// removed diff for the selected shortstatehash and each parent layer. #[tracing::instrument(skip(self))] - pub(crate) fn load_shortstatehash_info(&self, shortstatehash: u64) -> ShortStateInfoResult { + pub fn load_shortstatehash_info(&self, shortstatehash: u64) -> ShortStateInfoResult { if let Some(r) = self .stateinfo_cache .lock() @@ -97,7 +97,7 @@ impl Service { } } - pub(crate) fn compress_state_event(&self, shortstatekey: u64, event_id: &EventId) -> Result { + pub fn compress_state_event(&self, shortstatekey: u64, event_id: &EventId) -> Result { let mut v = shortstatekey.to_be_bytes().to_vec(); v.extend_from_slice( &services() @@ -110,9 +110,7 @@ impl Service { } /// Returns shortstatekey, event id - pub(crate) fn parse_compressed_state_event( - &self, compressed_event: &CompressedStateEvent, - ) -> Result<(u64, Arc)> { + pub fn parse_compressed_state_event(&self, compressed_event: &CompressedStateEvent) -> Result<(u64, Arc)> { Ok(( utils::u64_from_bytes(&compressed_event[0..size_of::()]).expect("bytes have right length"), services().rooms.short.get_eventid_from_short( @@ -140,7 +138,7 @@ impl Service { /// * `parent_states` - A stack with info on shortstatehash, full state, /// added diff and removed diff for each parent layer #[tracing::instrument(skip(self, statediffnew, statediffremoved, diff_to_sibling, parent_states))] - pub(crate) fn save_state_from_diff( + pub fn save_state_from_diff( &self, shortstatehash: u64, statediffnew: Arc>, statediffremoved: Arc>, diff_to_sibling: usize, mut parent_states: ParentStatesVec, @@ -252,7 +250,7 @@ impl Service { /// Returns the new shortstatehash, and the state diff from the previous /// room state - pub(crate) fn save_state( + pub fn save_state( &self, room_id: &RoomId, new_state_ids_compressed: Arc>, ) -> HashSetCompressStateEvent { let previous_shortstatehash = services().rooms.state.get_room_shortstatehash(room_id)?; diff --git a/src/service/rooms/threads/data.rs b/src/service/rooms/threads/data.rs index 41a4bdc1..b18f4b79 100644 --- a/src/service/rooms/threads/data.rs +++ b/src/service/rooms/threads/data.rs @@ -4,7 +4,7 @@ use crate::{PduEvent, Result}; type PduEventIterResult<'a> = Result> + 'a>>; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn threads_until<'a>( &'a self, user_id: &'a UserId, room_id: &'a RoomId, until: u64, include: &'a IncludeThreads, ) -> PduEventIterResult<'a>; diff --git a/src/service/rooms/threads/mod.rs b/src/service/rooms/threads/mod.rs index 578b21d3..05833a91 100644 --- a/src/service/rooms/threads/mod.rs +++ b/src/service/rooms/threads/mod.rs @@ -1,8 +1,8 @@ mod data; -use std::collections::BTreeMap; +use std::{collections::BTreeMap, sync::Arc}; -pub(crate) use data::Data; +pub use data::Data; use ruma::{ api::client::{error::ErrorKind, threads::get_threads::v1::IncludeThreads}, events::relation::BundledThread, @@ -12,18 +12,18 @@ use serde_json::json; use crate::{services, Error, PduEvent, Result}; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { - pub(crate) fn threads_until<'a>( + pub fn threads_until<'a>( &'a self, user_id: &'a UserId, room_id: &'a RoomId, until: u64, include: &'a IncludeThreads, ) -> Result> + 'a> { self.db.threads_until(user_id, room_id, until, include) } - pub(crate) fn add_to_thread(&self, root_event_id: &EventId, pdu: &PduEvent) -> Result<()> { + pub fn add_to_thread(&self, root_event_id: &EventId, pdu: &PduEvent) -> Result<()> { let root_id = &services() .rooms .timeline diff --git a/src/service/rooms/timeline/data.rs b/src/service/rooms/timeline/data.rs index 48b3088e..a036b455 100644 --- a/src/service/rooms/timeline/data.rs +++ b/src/service/rooms/timeline/data.rs @@ -5,7 +5,7 @@ use ruma::{CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId}; use super::PduCount; use crate::{PduEvent, Result}; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result; /// Returns the `count` of this pdu's id. diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index ea9f1613..82266437 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -1,12 +1,11 @@ -pub(crate) mod data; +pub mod data; use std::{ - cmp::Ordering, collections::{BTreeMap, HashMap, HashSet}, sync::Arc, }; -pub(crate) use data::Data; +pub use data::Data; use rand::prelude::SliceRandom; use ruma::{ api::{client::error::ErrorKind, federation}, @@ -35,60 +34,22 @@ use tracing::{debug, error, info, warn}; use super::state_compressor::CompressedStateEvent; use crate::{ - api::server_server, + server_is_ours, + //api::server_server, service::{ self, appservice::NamespaceRegex, pdu::{EventHash, PduBuilder}, + rooms::event_handler::parse_incoming_pdu, }, services, - utils::{self, server_name::server_is_ours}, - Error, PduEvent, Result, + utils::{self}, + Error, + PduCount, + PduEvent, + Result, }; -#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)] -pub(crate) enum PduCount { - Backfilled(u64), - Normal(u64), -} - -impl PduCount { - pub(crate) fn min() -> Self { Self::Backfilled(u64::MAX) } - - pub(crate) fn max() -> Self { Self::Normal(u64::MAX) } - - pub(crate) fn try_from_string(token: &str) -> Result { - if let Some(stripped_token) = token.strip_prefix('-') { - stripped_token.parse().map(PduCount::Backfilled) - } else { - token.parse().map(PduCount::Normal) - } - .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid pagination token.")) - } - - pub(crate) fn stringify(&self) -> String { - match self { - PduCount::Backfilled(x) => format!("-{x}"), - PduCount::Normal(x) => x.to_string(), - } - } -} - -impl PartialOrd for PduCount { - fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } -} - -impl Ord for PduCount { - fn cmp(&self, other: &Self) -> Ordering { - match (self, other) { - (PduCount::Normal(s), PduCount::Normal(o)) => s.cmp(o), - (PduCount::Backfilled(s), PduCount::Backfilled(o)) => o.cmp(s), - (PduCount::Normal(_), PduCount::Backfilled(_)) => Ordering::Greater, - (PduCount::Backfilled(_), PduCount::Normal(_)) => Ordering::Less, - } - } -} - // Update Relationships #[derive(Deserialize)] struct ExtractRelatesTo { @@ -106,15 +67,15 @@ struct ExtractRelatesToEventId { relates_to: ExtractEventId, } -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, - pub(crate) lasttimelinecount_cache: Mutex>, + pub lasttimelinecount_cache: Mutex>, } impl Service { #[tracing::instrument(skip(self))] - pub(crate) fn first_pdu_in_room(&self, room_id: &RoomId) -> Result>> { + pub fn first_pdu_in_room(&self, room_id: &RoomId) -> Result>> { self.all_pdus(user_id!("@doesntmatter:conduit.rs"), room_id)? .next() .map(|o| o.map(|(_, p)| Arc::new(p))) @@ -122,19 +83,17 @@ impl Service { } #[tracing::instrument(skip(self))] - pub(crate) fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result { + pub fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result { self.db.last_timeline_count(sender_user, room_id) } /// Returns the `count` of this pdu's id. - pub(crate) fn get_pdu_count(&self, event_id: &EventId) -> Result> { - self.db.get_pdu_count(event_id) - } + pub fn get_pdu_count(&self, event_id: &EventId) -> Result> { self.db.get_pdu_count(event_id) } // TODO Is this the same as the function above? /* #[tracing::instrument(skip(self))] - pub(crate) fn latest_pdu_count(&self, room_id: &RoomId) -> Result { + pub fn latest_pdu_count(&self, room_id: &RoomId) -> Result { let prefix = self .get_shortroomid(room_id)? .expect("room exists") @@ -158,7 +117,7 @@ impl Service { /// /// TODO: use this? #[allow(dead_code)] - pub(crate) fn get_room_version(&self, room_id: &RoomId) -> Result> { + pub fn get_room_version(&self, room_id: &RoomId) -> Result> { let create_event = services() .rooms .state_accessor @@ -178,17 +137,17 @@ impl Service { } /// Returns the json of a pdu. - pub(crate) fn get_pdu_json(&self, event_id: &EventId) -> Result> { + pub fn get_pdu_json(&self, event_id: &EventId) -> Result> { self.db.get_pdu_json(event_id) } /// Returns the json of a pdu. - pub(crate) fn get_non_outlier_pdu_json(&self, event_id: &EventId) -> Result> { + pub fn get_non_outlier_pdu_json(&self, event_id: &EventId) -> Result> { self.db.get_non_outlier_pdu_json(event_id) } /// Returns the pdu's id. - pub(crate) fn get_pdu_id(&self, event_id: &EventId) -> Result>> { self.db.get_pdu_id(event_id) } + pub fn get_pdu_id(&self, event_id: &EventId) -> Result>> { self.db.get_pdu_id(event_id) } /// Returns the pdu. /// @@ -196,28 +155,28 @@ impl Service { /// /// TODO: use this? #[allow(dead_code)] - pub(crate) fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result> { + pub fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result> { self.db.get_non_outlier_pdu(event_id) } /// Returns the pdu. /// /// Checks the `eventid_outlierpdu` Tree if not found in the timeline. - pub(crate) fn get_pdu(&self, event_id: &EventId) -> Result>> { self.db.get_pdu(event_id) } + pub fn get_pdu(&self, event_id: &EventId) -> Result>> { self.db.get_pdu(event_id) } /// Returns the pdu. /// /// This does __NOT__ check the outliers `Tree`. - pub(crate) fn get_pdu_from_id(&self, pdu_id: &[u8]) -> Result> { self.db.get_pdu_from_id(pdu_id) } + pub fn get_pdu_from_id(&self, pdu_id: &[u8]) -> Result> { self.db.get_pdu_from_id(pdu_id) } /// Returns the pdu as a `BTreeMap`. - pub(crate) fn get_pdu_json_from_id(&self, pdu_id: &[u8]) -> Result> { + pub fn get_pdu_json_from_id(&self, pdu_id: &[u8]) -> Result> { self.db.get_pdu_json_from_id(pdu_id) } /// Removes a pdu and creates a new one with the same id. #[tracing::instrument(skip(self))] - pub(crate) fn replace_pdu(&self, pdu_id: &[u8], pdu_json: &CanonicalJsonObject, pdu: &PduEvent) -> Result<()> { + pub fn replace_pdu(&self, pdu_id: &[u8], pdu_json: &CanonicalJsonObject, pdu: &PduEvent) -> Result<()> { self.db.replace_pdu(pdu_id, pdu_json, pdu) } @@ -228,7 +187,7 @@ impl Service { /// /// Returns pdu id #[tracing::instrument(skip(self, pdu, pdu_json, leaves))] - pub(crate) async fn append_pdu( + pub async fn append_pdu( &self, pdu: &PduEvent, mut pdu_json: CanonicalJsonObject, @@ -513,7 +472,6 @@ impl Service { // This will evaluate to false if the emergency password is set up so that // the administrator can execute commands as conduit let from_conduit = pdu.sender == server_user && services().globals.emergency_password().is_none(); - if let Some(admin_room) = service::admin::Service::get_admin_room().await? { if to_conduit && !from_conduit && admin_room == pdu.room_id { services() @@ -628,7 +586,7 @@ impl Service { Ok(pdu_id) } - pub(crate) fn create_hash_and_sign_event( + pub fn create_hash_and_sign_event( &self, pdu_builder: PduBuilder, sender: &UserId, @@ -811,7 +769,7 @@ impl Service { /// takes a roomid_mutex_state, meaning that only this function is able to /// mutate the room state. #[tracing::instrument(skip(self, state_lock))] - pub(crate) async fn build_and_append_pdu( + pub async fn build_and_append_pdu( &self, pdu_builder: PduBuilder, sender: &UserId, @@ -819,7 +777,6 @@ impl Service { state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex ) -> Result> { let (pdu, pdu_json) = self.create_hash_and_sign_event(pdu_builder, sender, room_id, state_lock)?; - if let Some(admin_room) = service::admin::Service::get_admin_room().await? { if admin_room == room_id { match pdu.event_type() { @@ -951,7 +908,7 @@ impl Service { /// Append the incoming event setting the state snapshot to the state from /// the server that sent the event. #[tracing::instrument(skip_all)] - pub(crate) async fn append_incoming_pdu( + pub async fn append_incoming_pdu( &self, pdu: &PduEvent, pdu_json: CanonicalJsonObject, @@ -990,7 +947,7 @@ impl Service { } /// Returns an iterator over all PDUs in a room. - pub(crate) fn all_pdus<'a>( + pub fn all_pdus<'a>( &'a self, user_id: &UserId, room_id: &RoomId, ) -> Result> + 'a> { self.pdus_after(user_id, room_id, PduCount::min()) @@ -1000,7 +957,7 @@ impl Service { /// happened before the event with id `until` in reverse-chronological /// order. #[tracing::instrument(skip(self))] - pub(crate) fn pdus_until<'a>( + pub fn pdus_until<'a>( &'a self, user_id: &UserId, room_id: &RoomId, until: PduCount, ) -> Result> + 'a> { self.db.pdus_until(user_id, room_id, until) @@ -1009,7 +966,7 @@ impl Service { /// Returns an iterator over all events and their token in a room that /// happened after the event with id `from` in chronological order. #[tracing::instrument(skip(self))] - pub(crate) fn pdus_after<'a>( + pub fn pdus_after<'a>( &'a self, user_id: &UserId, room_id: &RoomId, from: PduCount, ) -> Result> + 'a> { self.db.pdus_after(user_id, room_id, from) @@ -1017,7 +974,7 @@ impl Service { /// Replace a PDU with the redacted form. #[tracing::instrument(skip(self, reason))] - pub(crate) fn redact_pdu(&self, event_id: &EventId, reason: &PduEvent) -> Result<()> { + pub fn redact_pdu(&self, event_id: &EventId, reason: &PduEvent) -> Result<()> { // TODO: Don't reserialize, keep original json if let Some(pdu_id) = self.get_pdu_id(event_id)? { let mut pdu = self @@ -1039,7 +996,7 @@ impl Service { } #[tracing::instrument(skip(self, room_id))] - pub(crate) 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<()> { let first_pdu = self .all_pdus(user_id!("@doesntmatter:conduit.rs"), room_id)? .next() @@ -1154,11 +1111,11 @@ impl Service { } #[tracing::instrument(skip(self, pdu, pub_key_map))] - pub(crate) async fn backfill_pdu( + pub async fn backfill_pdu( &self, origin: &ServerName, pdu: Box, pub_key_map: &RwLock>>, ) -> Result<()> { - let (event_id, value, room_id) = server_server::parse_incoming_pdu(&pdu)?; + let (event_id, value, room_id) = parse_incoming_pdu(&pdu)?; // Lock so we cannot backfill the same pdu twice at the same time let mutex = Arc::clone( diff --git a/src/service/rooms/typing/mod.rs b/src/service/rooms/typing/mod.rs index 61a226fc..dab9d8d6 100644 --- a/src/service/rooms/typing/mod.rs +++ b/src/service/rooms/typing/mod.rs @@ -8,23 +8,23 @@ use ruma::{ use tokio::sync::{broadcast, RwLock}; use crate::{ - debug_info, services, - utils::{self, user_id::user_is_local}, + debug_info, services, user_is_local, + utils::{self}, Result, }; -pub(crate) struct Service { - pub(crate) typing: RwLock>>, // u64 is unix timestamp of timeout - pub(crate) last_typing_update: RwLock>, /* timestamp of the last change to - * typing - * users */ - pub(crate) typing_update_sender: broadcast::Sender, +pub struct Service { + pub typing: RwLock>>, // u64 is unix timestamp of timeout + pub last_typing_update: RwLock>, /* timestamp of the last change to + * typing + * users */ + pub typing_update_sender: broadcast::Sender, } impl Service { /// Sets a user as typing until the timeout timestamp is reached or /// roomtyping_remove is called. - pub(crate) 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 {:?} in {:?} timeout:{:?}", user_id, room_id, timeout); // update clients self.typing @@ -48,7 +48,7 @@ impl Service { } /// Removes a user from typing before the timeout is reached. - pub(crate) 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 {:?} in {:?}", user_id, room_id); // update clients self.typing @@ -71,7 +71,7 @@ impl Service { Ok(()) } - pub(crate) async fn wait_for_update(&self, room_id: &RoomId) -> Result<()> { + pub async fn wait_for_update(&self, room_id: &RoomId) -> Result<()> { let mut receiver = self.typing_update_sender.subscribe(); while let Ok(next) = receiver.recv().await { if next == room_id { @@ -128,7 +128,7 @@ impl Service { } /// Returns the count of the last typing update in this room. - pub(crate) async fn last_typing_update(&self, room_id: &RoomId) -> Result { + pub async fn last_typing_update(&self, room_id: &RoomId) -> Result { self.typings_maintain(room_id).await?; Ok(self .last_typing_update @@ -140,7 +140,7 @@ impl Service { } /// Returns a new typing EDU. - pub(crate) async fn typings_all( + pub async fn typings_all( &self, room_id: &RoomId, ) -> Result> { Ok(SyncEphemeralRoomEvent { diff --git a/src/service/rooms/user/data.rs b/src/service/rooms/user/data.rs index d10eae21..2fd1c29e 100644 --- a/src/service/rooms/user/data.rs +++ b/src/service/rooms/user/data.rs @@ -2,7 +2,7 @@ use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId}; use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn reset_notification_counts(&self, user_id: &UserId, room_id: &RoomId) -> Result<()>; fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> Result; diff --git a/src/service/rooms/user/mod.rs b/src/service/rooms/user/mod.rs index 58d6ea55..5f4d4708 100644 --- a/src/service/rooms/user/mod.rs +++ b/src/service/rooms/user/mod.rs @@ -1,45 +1,43 @@ mod data; -pub(crate) use data::Data; +use std::sync::Arc; + +pub use data::Data; use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId}; use crate::Result; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { - pub(crate) fn reset_notification_counts(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> { + pub fn reset_notification_counts(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> { self.db.reset_notification_counts(user_id, room_id) } - pub(crate) fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.notification_count(user_id, room_id) } - pub(crate) fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.highlight_count(user_id, room_id) } - pub(crate) fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> Result { + pub fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> Result { self.db.last_notification_read(user_id, room_id) } - pub(crate) fn associate_token_shortstatehash( - &self, room_id: &RoomId, token: u64, shortstatehash: u64, - ) -> Result<()> { + pub fn associate_token_shortstatehash(&self, room_id: &RoomId, token: u64, shortstatehash: u64) -> Result<()> { self.db .associate_token_shortstatehash(room_id, token, shortstatehash) } - pub(crate) fn get_token_shortstatehash(&self, room_id: &RoomId, token: u64) -> Result> { + pub fn get_token_shortstatehash(&self, room_id: &RoomId, token: u64) -> Result> { self.db.get_token_shortstatehash(room_id, token) } - pub(crate) fn get_shared_rooms( - &self, users: Vec, - ) -> Result>> { + pub fn get_shared_rooms(&self, users: Vec) -> Result> + '_> { self.db.get_shared_rooms(users) } } diff --git a/src/service/sending/data.rs b/src/service/sending/data.rs index 04dfd5da..41479021 100644 --- a/src/service/sending/data.rs +++ b/src/service/sending/data.rs @@ -6,7 +6,7 @@ use crate::Result; type OutgoingSendingIter<'a> = Box, Destination, SendingEvent)>> + 'a>; type SendingEventIter<'a> = Box, SendingEvent)>> + 'a>; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn active_requests(&self) -> OutgoingSendingIter<'_>; fn active_requests_for(&self, destination: &Destination) -> SendingEventIter<'_>; fn delete_active_request(&self, key: Vec) -> Result<()>; diff --git a/src/service/sending/mod.rs b/src/service/sending/mod.rs index ed01e797..b4a6fdeb 100644 --- a/src/service/sending/mod.rs +++ b/src/service/sending/mod.rs @@ -1,27 +1,28 @@ use std::{fmt::Debug, sync::Arc}; -pub(crate) use data::Data; +pub use data::Data; use ruma::{ api::{appservice::Registration, OutgoingRequest}, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, }; -use tokio::sync::Mutex; -use tracing::warn; +use tokio::{sync::Mutex, task::JoinHandle}; +use tracing::{error, warn}; -use crate::{services, utils::server_name::server_is_ours, Config, Error, Result}; +use crate::{server_is_ours, services, Config, Error, Result}; mod appservice; mod data; -pub(crate) mod send; -pub(crate) mod sender; -pub(crate) use send::FedDest; +pub mod send; +pub mod sender; +pub use send::FedDest; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, /// The state for a given state hash. sender: loole::Sender, receiver: Mutex>, + handler_join: Mutex>>, startup_netburst: bool, startup_netburst_keep: i64, } @@ -34,7 +35,7 @@ struct Msg { } #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub(crate) enum Destination { +pub enum Destination { Appservice(String), Push(OwnedUserId, String), // user and pushkey Normal(OwnedServerName), @@ -42,26 +43,42 @@ pub(crate) enum Destination { #[allow(clippy::module_name_repetitions)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub(crate) enum SendingEvent { +pub enum SendingEvent { Pdu(Vec), // pduid Edu(Vec), // pdu json Flush, // none } impl Service { - pub(crate) fn build(db: &'static dyn Data, config: &Config) -> Arc { + pub fn build(db: Arc, config: &Config) -> Arc { let (sender, receiver) = loole::unbounded(); Arc::new(Self { db, sender, receiver: Mutex::new(receiver), + handler_join: Mutex::new(None), startup_netburst: config.startup_netburst, startup_netburst_keep: config.startup_netburst_keep, }) } + pub async fn close(&self) { + self.interrupt(); + if let Some(handler_join) = self.handler_join.lock().await.take() { + if let Err(e) = handler_join.await { + error!("Failed to shutdown: {e:?}"); + } + } + } + + pub fn interrupt(&self) { + if !self.sender.is_closed() { + self.sender.close(); + } + } + #[tracing::instrument(skip(self, pdu_id, user, pushkey))] - pub(crate) fn send_pdu_push(&self, pdu_id: &[u8], user: &UserId, pushkey: String) -> Result<()> { + pub fn send_pdu_push(&self, pdu_id: &[u8], user: &UserId, pushkey: String) -> Result<()> { let dest = Destination::Push(user.to_owned(), pushkey); let event = SendingEvent::Pdu(pdu_id.to_owned()); let _cork = services().globals.db.cork()?; @@ -74,7 +91,7 @@ impl Service { } #[tracing::instrument(skip(self))] - pub(crate) fn send_pdu_appservice(&self, appservice_id: String, pdu_id: Vec) -> Result<()> { + pub fn send_pdu_appservice(&self, appservice_id: String, pdu_id: Vec) -> Result<()> { let dest = Destination::Appservice(appservice_id); let event = SendingEvent::Pdu(pdu_id); let _cork = services().globals.db.cork()?; @@ -87,7 +104,7 @@ impl Service { } #[tracing::instrument(skip(self, room_id, pdu_id))] - pub(crate) fn send_pdu_room(&self, room_id: &RoomId, pdu_id: &[u8]) -> Result<()> { + pub fn send_pdu_room(&self, room_id: &RoomId, pdu_id: &[u8]) -> Result<()> { let servers = services() .rooms .state_cache @@ -99,9 +116,7 @@ impl Service { } #[tracing::instrument(skip(self, servers, pdu_id))] - pub(crate) fn send_pdu_servers>( - &self, servers: I, pdu_id: &[u8], - ) -> Result<()> { + pub fn send_pdu_servers>(&self, servers: I, pdu_id: &[u8]) -> Result<()> { let requests = servers .into_iter() .map(|server| (Destination::Normal(server), SendingEvent::Pdu(pdu_id.to_owned()))) @@ -125,7 +140,7 @@ impl Service { } #[tracing::instrument(skip(self, server, serialized))] - pub(crate) fn send_edu_server(&self, server: &ServerName, serialized: Vec) -> Result<()> { + pub fn send_edu_server(&self, server: &ServerName, serialized: Vec) -> Result<()> { let dest = Destination::Normal(server.to_owned()); let event = SendingEvent::Edu(serialized); let _cork = services().globals.db.cork()?; @@ -138,7 +153,7 @@ impl Service { } #[tracing::instrument(skip(self, room_id, serialized))] - pub(crate) fn send_edu_room(&self, room_id: &RoomId, serialized: Vec) -> Result<()> { + pub fn send_edu_room(&self, room_id: &RoomId, serialized: Vec) -> Result<()> { let servers = services() .rooms .state_cache @@ -150,9 +165,7 @@ impl Service { } #[tracing::instrument(skip(self, servers, serialized))] - pub(crate) fn send_edu_servers>( - &self, servers: I, serialized: Vec, - ) -> Result<()> { + pub fn send_edu_servers>(&self, servers: I, serialized: Vec) -> Result<()> { let requests = servers .into_iter() .map(|server| (Destination::Normal(server), SendingEvent::Edu(serialized.clone()))) @@ -177,7 +190,7 @@ impl Service { } #[tracing::instrument(skip(self, room_id))] - pub(crate) fn flush_room(&self, room_id: &RoomId) -> Result<()> { + pub fn flush_room(&self, room_id: &RoomId) -> Result<()> { let servers = services() .rooms .state_cache @@ -189,7 +202,7 @@ impl Service { } #[tracing::instrument(skip(self, servers))] - pub(crate) fn flush_servers>(&self, servers: I) -> Result<()> { + pub fn flush_servers>(&self, servers: I) -> Result<()> { let requests = servers.into_iter().map(Destination::Normal); for dest in requests { self.dispatch(Msg { @@ -203,7 +216,7 @@ impl Service { } #[tracing::instrument(skip(self, request), name = "request")] - pub(crate) async fn send_federation_request(&self, dest: &ServerName, request: T) -> Result + pub async fn send_federation_request(&self, dest: &ServerName, request: T) -> Result where T: OutgoingRequest + Debug, { @@ -215,7 +228,7 @@ impl Service { /// /// Only returns None if there is no url specified in the appservice /// registration file - pub(crate) async fn send_appservice_request( + pub async fn send_appservice_request( &self, registration: Registration, request: T, ) -> Result> where @@ -227,7 +240,7 @@ impl Service { /// Cleanup event data /// Used for instance after we remove an appservice registration #[tracing::instrument(skip(self))] - pub(crate) fn cleanup_events(&self, appservice_id: String) -> Result<()> { + pub fn cleanup_events(&self, appservice_id: String) -> Result<()> { self.db .delete_all_requests_for(&Destination::Appservice(appservice_id))?; @@ -243,7 +256,7 @@ impl Service { impl Destination { #[tracing::instrument(skip(self))] - pub(crate) fn get_prefix(&self) -> Vec { + pub fn get_prefix(&self) -> Vec { let mut prefix = match self { Destination::Appservice(server) => { let mut p = b"+".to_vec(); diff --git a/src/service/sending/send.rs b/src/service/sending/send.rs index 84da476d..a835e438 100644 --- a/src/service/sending/send.rs +++ b/src/service/sending/send.rs @@ -13,7 +13,6 @@ use ruma::{ client::error::Error as RumaError, EndpointError, IncomingResponse, MatrixVersion, OutgoingRequest, SendAccessToken, }, - events::room::message::RoomMessageEventContent, OwnedServerName, ServerName, }; use tracing::{debug, error, trace}; @@ -28,7 +27,7 @@ use crate::{debug_error, debug_info, debug_warn, services, Error, Result}; /// /// # Examples: /// ```rust -/// # use conduit::api::server_server::FedDest; +/// # use conduit_service::sending::FedDest; /// # fn main() -> Result<(), std::net::AddrParseError> { /// FedDest::Literal("198.51.100.3:8448".parse()?); /// FedDest::Literal("[2001:db8::4:5]:443".parse()?); @@ -39,7 +38,7 @@ use crate::{debug_error, debug_info, debug_warn, services, Error, Result}; /// # } /// ``` #[derive(Clone, Debug, PartialEq, Eq)] -pub(crate) enum FedDest { +pub enum FedDest { Literal(SocketAddr), Named(String, String), } @@ -52,7 +51,7 @@ struct ActualDest { } #[tracing::instrument(skip_all, name = "send")] -pub(crate) async fn send(client: &Client, dest: &ServerName, req: T) -> Result +pub async fn send(client: &Client, dest: &ServerName, req: T) -> Result where T: OutgoingRequest + Debug, { @@ -195,7 +194,7 @@ async fn get_actual_dest(server_name: &ServerName) -> Result { } else { cached = false; validate_dest(server_name)?; - resolve_actual_dest(server_name, false, false).await? + resolve_actual_dest(server_name, false).await? }; let string = dest.clone().into_https_string(); @@ -211,162 +210,49 @@ async fn get_actual_dest(server_name: &ServerName) -> Result { /// Implemented according to the specification at /// Numbers in comments below refer to bullet points in linked section of /// specification -pub(crate) async fn resolve_actual_dest( - dest: &'_ ServerName, no_cache_dest: bool, admin_room_caller: bool, -) -> Result<(FedDest, String)> { +pub async fn resolve_actual_dest(dest: &ServerName, no_cache_dest: bool) -> Result<(FedDest, String)> { trace!("Finding actual destination for {dest}"); let dest_str = dest.as_str().to_owned(); let mut hostname = dest_str.clone(); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain( - "Checking for 1: IP literal with provided or default port", - )) - .await; - } - #[allow(clippy::single_match_else)] let actual_dest = match get_ip_with_port(&dest_str) { Some(host_port) => { debug!("1: IP literal with provided or default port"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "1: IP literal with provided or default port\n\nHost and Port: {host_port:?}" - ))) - .await; - } - host_port }, None => { - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain( - "Checking for 2: Hostname with included port", - )) - .await; - } - if let Some(pos) = dest_str.find(':') { debug!("2: Hostname with included port"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain("2: Hostname with included port")) - .await; - } - let (host, port) = dest_str.split_at(pos); if !no_cache_dest { query_and_cache_override(host, host, port.parse::().unwrap_or(8448)).await?; } - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!("Host: {host} | Port: {port}"))) - .await; - } - FedDest::Named(host.to_owned(), port.to_owned()) } else { trace!("Requesting well known for {dest}"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "Checking for 3: A .well-known file is available. Requesting well-known for {dest}" - ))) - .await; - } - if let Some(delegated_hostname) = request_well_known(dest.as_str()).await? { debug!("3: A .well-known file is available"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain("3: A .well-known file is available")) - .await; - } - hostname = add_port_to_hostname(&delegated_hostname).into_uri_string(); match get_ip_with_port(&delegated_hostname) { Some(host_and_port) => { debug!("3.1: IP literal in .well-known file"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "3.1: IP literal in .well-known file\n\nHost and Port: {host_and_port:?}" - ))) - .await; - } - host_and_port }, None => { - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain( - "Checking for 3.2: Hostname with port in .well-known file", - )) - .await; - } - if let Some(pos) = delegated_hostname.find(':') { debug!("3.2: Hostname with port in .well-known file"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain( - "3.2: Hostname with port in .well-known file", - )) - .await; - } - let (host, port) = delegated_hostname.split_at(pos); if !no_cache_dest { query_and_cache_override(host, host, port.parse::().unwrap_or(8448)).await?; } - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "Host: {host} | Port: {port}" - ))) - .await; - } - FedDest::Named(host.to_owned(), port.to_owned()) } else { trace!("Delegated hostname has no port in this branch"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain( - "Delegated hostname has no port specified", - )) - .await; - } - if let Some(hostname_override) = query_srv_record(&delegated_hostname).await? { debug!("3.3: SRV lookup successful"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain( - "3.3: SRV lookup successful", - )) - .await; - } - let force_port = hostname_override.port(); if !no_cache_dest { query_and_cache_override( @@ -378,53 +264,17 @@ pub(crate) async fn resolve_actual_dest( } if let Some(port) = force_port { - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "Host: {delegated_hostname} | Port: {port}" - ))) - .await; - } - FedDest::Named(delegated_hostname, format!(":{port}")) } else { - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "Host: {delegated_hostname} | Port: 8448" - ))) - .await; - } - add_port_to_hostname(&delegated_hostname) } } else { debug!("3.4: No SRV records, just use the hostname from .well-known"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain( - "3.4: No SRV records, just use the hostname from .well-known", - )) - .await; - } - if !no_cache_dest { query_and_cache_override(&delegated_hostname, &delegated_hostname, 8448) .await?; } - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "Host: {delegated_hostname} | Port: 8448" - ))) - .await; - } - add_port_to_hostname(&delegated_hostname) } } @@ -432,26 +282,8 @@ pub(crate) async fn resolve_actual_dest( } } else { trace!("4: No .well-known or an error occured"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain( - "4: No .well-known or an error occured", - )) - .await; - } - if let Some(hostname_override) = query_srv_record(&dest_str).await? { debug!("4: No .well-known; SRV record found"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain( - "4: No .well-known; SRV record found", - )) - .await; - } - let force_port = hostname_override.port(); if !no_cache_dest { @@ -464,52 +296,16 @@ pub(crate) async fn resolve_actual_dest( } if let Some(port) = force_port { - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "Host: {hostname} | Port: {port}" - ))) - .await; - } - FedDest::Named(hostname.clone(), format!(":{port}")) } else { - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "Host: {hostname} | Port: 8448" - ))) - .await; - } - add_port_to_hostname(&hostname) } } else { debug!("4: No .well-known; 5: No SRV record found"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain( - "4: No .well-known; 5: No SRV record found", - )) - .await; - } - if !no_cache_dest { query_and_cache_override(&dest_str, &dest_str, 8448).await?; } - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "Host: {dest_str} | Port: 8448" - ))) - .await; - } - add_port_to_hostname(&dest_str) } } @@ -531,14 +327,6 @@ pub(crate) async fn resolve_actual_dest( }; debug!("Actual destination: {actual_dest:?} hostname: {hostname:?}"); - if admin_room_caller { - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "Actual destination: {actual_dest:?} | Hostname: {hostname:?}" - ))) - .await; - } Ok((actual_dest, hostname.into_uri_string())) } diff --git a/src/service/sending/sender.rs b/src/service/sending/sender.rs index e7d00234..3d1d89da 100644 --- a/src/service/sending/sender.rs +++ b/src/service/sending/sender.rs @@ -23,12 +23,7 @@ use ruma::{ use tracing::{debug, error, warn}; use super::{appservice, send, Destination, Msg, SendingEvent, Service}; -use crate::{ - service::presence::Presence, - services, - utils::{calculate_hash, user_id::user_is_local}, - Error, PduEvent, Result, -}; +use crate::{service::presence::Presence, services, user_is_local, utils::calculate_hash, Error, PduEvent, Result}; #[derive(Debug)] enum TransactionStatus { @@ -47,25 +42,31 @@ const DEQUEUE_LIMIT: usize = 48; const SELECT_EDU_LIMIT: usize = 16; impl Service { - pub(crate) fn start_handler(self: &Arc) { - let self2 = Arc::clone(self); - tokio::spawn(async move { - self2.handler().await; + pub async fn start_handler(self: &Arc) { + let self_ = Arc::clone(self); + let handle = services().server.runtime().spawn(async move { + self_ + .handler() + .await + .expect("Failed to start sending handler"); }); + + _ = self.handler_join.lock().await.insert(handle); } #[tracing::instrument(skip_all, name = "sender")] - async fn handler(&self) { + async fn handler(&self) -> Result<()> { let receiver = self.receiver.lock().await; - debug_assert!(!receiver.is_closed(), "channel error"); - let mut futures: SendingFutures<'_> = FuturesUnordered::new(); let mut statuses: CurTransactionStatus = CurTransactionStatus::new(); + self.initial_transactions(&mut futures, &mut statuses); loop { + debug_assert!(!receiver.is_closed(), "channel error"); tokio::select! { - Ok(request) = receiver.recv_async() => { - self.handle_request(request, &mut futures, &mut statuses); + request = receiver.recv_async() => match request { + Ok(request) => self.handle_request(request, &mut futures, &mut statuses), + Err(_) => return Ok(()), }, Some(response) = futures.next() => { self.handle_response(response, &mut futures, &mut statuses); @@ -396,7 +397,7 @@ fn select_edus_receipts( } async fn send_events(dest: Destination, events: Vec) -> SendingResult { - debug_assert!(!events.is_empty(), "sending empty transaction"); + //debug_assert!(!events.is_empty(), "sending empty transaction"); match dest { Destination::Normal(ref server) => send_events_dest_normal(&dest, server, events).await, Destination::Appservice(ref id) => send_events_dest_appservice(&dest, id, events).await, @@ -433,7 +434,7 @@ async fn send_events_dest_appservice(dest: &Destination, id: &String, events: Ve } } - debug_assert!(!pdu_jsons.is_empty(), "sending empty transaction"); + //debug_assert!(!pdu_jsons.is_empty(), "sending empty transaction"); match appservice::send_request( services() .appservice @@ -584,7 +585,8 @@ async fn send_events_dest_normal( } let client = &services().globals.client.sender; - debug_assert!(pdu_jsons.len() + edu_jsons.len() > 0, "sending empty transaction"); + //debug_assert!(pdu_jsons.len() + edu_jsons.len() > 0, "sending empty + // transaction"); send::send( client, server_name, diff --git a/src/service/services.rs b/src/service/services.rs new file mode 100644 index 00000000..291cba62 --- /dev/null +++ b/src/service/services.rs @@ -0,0 +1,342 @@ +use std::{ + collections::{BTreeMap, HashMap}, + sync::{atomic, Arc, Mutex as StdMutex}, +}; + +use conduit::{debug_info, Result, Server}; +use database::KeyValueDatabase; +use lru_cache::LruCache; +use tokio::{ + fs, + sync::{broadcast, Mutex, RwLock}, +}; +use tracing::{debug, info, trace}; + +use crate::{ + account_data, admin, appservice, globals, key_backups, media, presence, pusher, rooms, sending, transaction_ids, + uiaa, users, +}; + +pub struct Services { + pub appservice: appservice::Service, + pub pusher: pusher::Service, + pub rooms: rooms::Service, + pub transaction_ids: transaction_ids::Service, + pub uiaa: uiaa::Service, + pub users: users::Service, + pub account_data: account_data::Service, + pub presence: Arc, + pub admin: Arc, + pub globals: globals::Service, + pub key_backups: key_backups::Service, + pub media: media::Service, + pub sending: Arc, + pub server: Arc, + pub db: Arc, +} + +impl Services { + pub async fn build(server: Arc, db: Arc) -> Result { + let config = &server.config; + Ok(Self { + appservice: appservice::Service::build(db.clone())?, + pusher: pusher::Service { + db: db.clone(), + }, + rooms: rooms::Service { + alias: rooms::alias::Service { + db: db.clone(), + }, + auth_chain: rooms::auth_chain::Service { + db: db.clone(), + }, + directory: rooms::directory::Service { + db: db.clone(), + }, + event_handler: rooms::event_handler::Service, + lazy_loading: rooms::lazy_loading::Service { + db: db.clone(), + lazy_load_waiting: Mutex::new(HashMap::new()), + }, + metadata: rooms::metadata::Service { + db: db.clone(), + }, + outlier: rooms::outlier::Service { + db: db.clone(), + }, + pdu_metadata: rooms::pdu_metadata::Service { + db: db.clone(), + }, + read_receipt: rooms::read_receipt::Service { + db: db.clone(), + }, + search: rooms::search::Service { + db: db.clone(), + }, + short: rooms::short::Service { + db: db.clone(), + }, + state: rooms::state::Service { + db: db.clone(), + }, + state_accessor: rooms::state_accessor::Service { + db: db.clone(), + server_visibility_cache: StdMutex::new(LruCache::new( + (f64::from(config.server_visibility_cache_capacity) * config.conduit_cache_capacity_modifier) + as usize, + )), + user_visibility_cache: StdMutex::new(LruCache::new( + (f64::from(config.user_visibility_cache_capacity) * config.conduit_cache_capacity_modifier) + as usize, + )), + }, + state_cache: rooms::state_cache::Service { + db: db.clone(), + }, + state_compressor: rooms::state_compressor::Service { + db: db.clone(), + stateinfo_cache: StdMutex::new(LruCache::new( + (f64::from(config.stateinfo_cache_capacity) * config.conduit_cache_capacity_modifier) as usize, + )), + }, + timeline: rooms::timeline::Service { + db: db.clone(), + lasttimelinecount_cache: Mutex::new(HashMap::new()), + }, + threads: rooms::threads::Service { + db: db.clone(), + }, + typing: rooms::typing::Service { + typing: RwLock::new(BTreeMap::new()), + last_typing_update: RwLock::new(BTreeMap::new()), + typing_update_sender: broadcast::channel(100).0, + }, + spaces: rooms::spaces::Service { + roomid_spacehierarchy_cache: Mutex::new(LruCache::new( + (f64::from(config.roomid_spacehierarchy_cache_capacity) + * config.conduit_cache_capacity_modifier) as usize, + )), + }, + user: rooms::user::Service { + db: db.clone(), + }, + }, + transaction_ids: transaction_ids::Service { + db: db.clone(), + }, + uiaa: uiaa::Service { + db: db.clone(), + }, + users: users::Service { + db: db.clone(), + connections: StdMutex::new(BTreeMap::new()), + }, + account_data: account_data::Service { + db: db.clone(), + }, + presence: presence::Service::build(db.clone(), config), + admin: admin::Service::build(), + key_backups: key_backups::Service { + db: db.clone(), + }, + media: media::Service { + db: db.clone(), + url_preview_mutex: RwLock::new(HashMap::new()), + }, + sending: sending::Service::build(db.clone(), config), + globals: globals::Service::load(db.clone(), config)?, + server, + db, + }) + } + + pub async fn memory_usage(&self) -> String { + let lazy_load_waiting = self.rooms.lazy_loading.lazy_load_waiting.lock().await.len(); + let server_visibility_cache = self + .rooms + .state_accessor + .server_visibility_cache + .lock() + .unwrap() + .len(); + let user_visibility_cache = self + .rooms + .state_accessor + .user_visibility_cache + .lock() + .unwrap() + .len(); + let stateinfo_cache = self + .rooms + .state_compressor + .stateinfo_cache + .lock() + .unwrap() + .len(); + let lasttimelinecount_cache = self + .rooms + .timeline + .lasttimelinecount_cache + .lock() + .await + .len(); + let roomid_spacehierarchy_cache = self + .rooms + .spaces + .roomid_spacehierarchy_cache + .lock() + .await + .len(); + let resolver_overrides_cache = self.globals.resolver.overrides.read().unwrap().len(); + let resolver_destinations_cache = self.globals.resolver.destinations.read().await.len(); + let bad_event_ratelimiter = self.globals.bad_event_ratelimiter.read().await.len(); + let bad_query_ratelimiter = self.globals.bad_query_ratelimiter.read().await.len(); + let bad_signature_ratelimiter = self.globals.bad_signature_ratelimiter.read().await.len(); + + format!( + "\ +lazy_load_waiting: {lazy_load_waiting} +server_visibility_cache: {server_visibility_cache} +user_visibility_cache: {user_visibility_cache} +stateinfo_cache: {stateinfo_cache} +lasttimelinecount_cache: {lasttimelinecount_cache} +roomid_spacehierarchy_cache: {roomid_spacehierarchy_cache} +resolver_overrides_cache: {resolver_overrides_cache} +resolver_destinations_cache: {resolver_destinations_cache} +bad_event_ratelimiter: {bad_event_ratelimiter} +bad_query_ratelimiter: {bad_query_ratelimiter} +bad_signature_ratelimiter: {bad_signature_ratelimiter} +" + ) + } + + pub async fn clear_caches(&self, amount: u32) { + if amount > 0 { + self.rooms + .lazy_loading + .lazy_load_waiting + .lock() + .await + .clear(); + } + if amount > 1 { + self.rooms + .state_accessor + .server_visibility_cache + .lock() + .unwrap() + .clear(); + } + if amount > 2 { + self.rooms + .state_accessor + .user_visibility_cache + .lock() + .unwrap() + .clear(); + } + if amount > 3 { + self.rooms + .state_compressor + .stateinfo_cache + .lock() + .unwrap() + .clear(); + } + if amount > 4 { + self.rooms + .timeline + .lasttimelinecount_cache + .lock() + .await + .clear(); + } + if amount > 5 { + self.rooms + .spaces + .roomid_spacehierarchy_cache + .lock() + .await + .clear(); + } + if amount > 6 { + self.globals.resolver.overrides.write().unwrap().clear(); + self.globals.resolver.destinations.write().await.clear(); + } + if amount > 7 { + self.globals.resolver.resolver.clear_cache(); + } + if amount > 8 { + self.globals.bad_event_ratelimiter.write().await.clear(); + } + if amount > 9 { + self.globals.bad_query_ratelimiter.write().await.clear(); + } + if amount > 10 { + self.globals.bad_signature_ratelimiter.write().await.clear(); + } + } + + pub async fn start(&self) -> Result<()> { + debug_info!("Starting services"); + globals::migrations::migrations(&self.db, &self.globals.config).await?; + + self.admin.start_handler().await; + + globals::emerg_access::init_emergency_access().await; + + self.sending.start_handler().await; + + if self.globals.config.allow_local_presence { + self.presence.start_handler().await; + } + + if self.globals.allow_check_for_updates() { + let handle = globals::updates::start_check_for_updates_task().await?; + _ = self.globals.updates_handle.lock().await.insert(handle); + } + + debug_info!("Services startup complete."); + Ok(()) + } + + pub async fn interrupt(&self) { + trace!("Interrupting services..."); + self.server.interrupt.store(true, atomic::Ordering::Release); + + self.globals.rotate.fire(); + self.sending.interrupt(); + self.presence.interrupt(); + self.admin.interrupt(); + + trace!("Services interrupt complete."); + } + + #[tracing::instrument(skip_all)] + pub async fn shutdown(&self) { + info!("Shutting down services"); + self.interrupt().await; + + debug!("Removing unix socket file."); + if let Some(path) = self.globals.unix_socket_path().as_ref() { + _ = fs::remove_file(path).await; + } + + debug!("Waiting for update worker..."); + if let Some(updates_handle) = self.globals.updates_handle.lock().await.take() { + updates_handle.abort(); + _ = updates_handle.await; + } + + debug!("Waiting for admin worker..."); + self.admin.close().await; + + debug!("Waiting for presence worker..."); + self.presence.close().await; + + debug!("Waiting for sender..."); + self.sending.close().await; + + debug_info!("Services shutdown complete."); + } +} diff --git a/src/service/transaction_ids/data.rs b/src/service/transaction_ids/data.rs index 1a0abb62..2aed1981 100644 --- a/src/service/transaction_ids/data.rs +++ b/src/service/transaction_ids/data.rs @@ -2,7 +2,7 @@ use ruma::{DeviceId, TransactionId, UserId}; use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn add_txnid( &self, user_id: &UserId, device_id: Option<&DeviceId>, txn_id: &TransactionId, data: &[u8], ) -> Result<()>; diff --git a/src/service/transaction_ids/mod.rs b/src/service/transaction_ids/mod.rs index 0bdaf925..ba9869e7 100644 --- a/src/service/transaction_ids/mod.rs +++ b/src/service/transaction_ids/mod.rs @@ -1,22 +1,24 @@ mod data; -pub(crate) use data::Data; +use std::sync::Arc; + +pub use data::Data; use ruma::{DeviceId, TransactionId, UserId}; use crate::Result; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub struct Service { + pub db: Arc, } impl Service { - pub(crate) fn add_txnid( + pub fn add_txnid( &self, user_id: &UserId, device_id: Option<&DeviceId>, txn_id: &TransactionId, data: &[u8], ) -> Result<()> { self.db.add_txnid(user_id, device_id, txn_id, data) } - pub(crate) fn existing_txnid( + pub fn existing_txnid( &self, user_id: &UserId, device_id: Option<&DeviceId>, txn_id: &TransactionId, ) -> Result>> { self.db.existing_txnid(user_id, device_id, txn_id) diff --git a/src/service/uiaa/data.rs b/src/service/uiaa/data.rs index 1b43ff8f..3a157068 100644 --- a/src/service/uiaa/data.rs +++ b/src/service/uiaa/data.rs @@ -2,7 +2,7 @@ use ruma::{api::client::uiaa::UiaaInfo, CanonicalJsonValue, DeviceId, UserId}; use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { fn set_uiaa_request( &self, user_id: &UserId, device_id: &DeviceId, session: &str, request: &CanonicalJsonValue, ) -> Result<()>; diff --git a/src/service/uiaa/mod.rs b/src/service/uiaa/mod.rs index 6e38bbcc..cd131c52 100644 --- a/src/service/uiaa/mod.rs +++ b/src/service/uiaa/mod.rs @@ -1,7 +1,10 @@ mod data; +use std::sync::Arc; + use argon2::{PasswordHash, PasswordVerifier}; -pub(crate) use data::Data; +use conduit::{utils, Error, Result}; +pub use data::Data; use ruma::{ api::client::{ error::ErrorKind, @@ -11,15 +14,17 @@ use ruma::{ }; use tracing::error; -use crate::{api::client_server::SESSION_ID_LENGTH, services, utils, Error, Result}; +use crate::services; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, +pub const SESSION_ID_LENGTH: usize = 32; + +pub struct Service { + pub db: Arc, } impl Service { /// Creates a new Uiaa session. Make sure the session token is unique. - pub(crate) fn create( + pub fn create( &self, user_id: &UserId, device_id: &DeviceId, uiaainfo: &UiaaInfo, json_body: &CanonicalJsonValue, ) -> Result<()> { self.db.set_uiaa_request( @@ -37,7 +42,7 @@ impl Service { ) } - pub(crate) fn try_auth( + pub fn try_auth( &self, user_id: &UserId, device_id: &DeviceId, auth: &AuthData, uiaainfo: &UiaaInfo, ) -> Result<(bool, UiaaInfo)> { let mut uiaainfo = auth.session().map_or_else( @@ -135,7 +140,8 @@ impl Service { Ok((true, uiaainfo)) } - pub(crate) fn get_uiaa_request( + #[must_use] + pub fn get_uiaa_request( &self, user_id: &UserId, device_id: &DeviceId, session: &str, ) -> Option { self.db.get_uiaa_request(user_id, device_id, session) diff --git a/src/service/users/data.rs b/src/service/users/data.rs index 9ce7ecdc..04074e85 100644 --- a/src/service/users/data.rs +++ b/src/service/users/data.rs @@ -10,7 +10,7 @@ use ruma::{ use crate::Result; -pub(crate) trait Data: Send + Sync { +pub trait Data: Send + Sync { /// Check if a user has an account on this homeserver. fn exists(&self, user_id: &UserId) -> Result; diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index 3ae9931d..fde2ed89 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -5,7 +5,7 @@ use std::{ sync::{Arc, Mutex}, }; -pub(crate) use data::Data; +pub use data::Data; use ruma::{ api::client::{ device::Device, @@ -25,7 +25,7 @@ use ruma::{ use crate::{services, Error, Result}; -pub(crate) struct SlidingSyncCache { +pub struct SlidingSyncCache { lists: BTreeMap, subscriptions: BTreeMap, known_rooms: BTreeMap>, // For every room, the roomsince number @@ -34,25 +34,23 @@ pub(crate) struct SlidingSyncCache { type DbConnections = Mutex>>>; -pub(crate) struct Service { - pub(crate) db: &'static dyn Data, - pub(crate) connections: DbConnections, +pub struct Service { + pub db: Arc, + pub connections: DbConnections, } impl Service { /// Check if a user has an account on this homeserver. - pub(crate) fn exists(&self, user_id: &UserId) -> Result { self.db.exists(user_id) } + pub fn exists(&self, user_id: &UserId) -> Result { self.db.exists(user_id) } - pub(crate) fn forget_sync_request_connection( - &self, user_id: OwnedUserId, device_id: OwnedDeviceId, conn_id: String, - ) { + pub fn forget_sync_request_connection(&self, user_id: OwnedUserId, device_id: OwnedDeviceId, conn_id: String) { self.connections .lock() .unwrap() .remove(&(user_id, device_id, conn_id)); } - pub(crate) fn update_sync_request_with_cache( + pub fn update_sync_request_with_cache( &self, user_id: OwnedUserId, device_id: OwnedDeviceId, request: &mut sync_events::v4::Request, ) -> BTreeMap> { let Some(conn_id) = request.conn_id.clone() else { @@ -172,7 +170,7 @@ impl Service { cached.known_rooms.clone() } - pub(crate) fn update_sync_subscriptions( + pub fn update_sync_subscriptions( &self, user_id: OwnedUserId, device_id: OwnedDeviceId, conn_id: String, subscriptions: BTreeMap, ) { @@ -195,7 +193,7 @@ impl Service { cached.subscriptions = subscriptions; } - pub(crate) fn update_sync_known_rooms( + pub fn update_sync_known_rooms( &self, user_id: OwnedUserId, device_id: OwnedDeviceId, conn_id: String, list_id: String, new_cached_rooms: BTreeSet, globalsince: u64, ) { @@ -232,10 +230,10 @@ impl Service { } /// Check if account is deactivated - pub(crate) fn is_deactivated(&self, user_id: &UserId) -> Result { self.db.is_deactivated(user_id) } + pub fn is_deactivated(&self, user_id: &UserId) -> Result { self.db.is_deactivated(user_id) } /// Check if a user is an admin - pub(crate) fn is_admin(&self, user_id: &UserId) -> Result { + pub fn is_admin(&self, user_id: &UserId) -> Result { let admin_room_alias_id = RoomAliasId::parse(format!("#admins:{}", services().globals.server_name())) .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid alias."))?; let admin_room_id = services() @@ -251,63 +249,63 @@ impl Service { } /// Create a new user account on this homeserver. - pub(crate) fn create(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { + pub fn create(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { self.db.set_password(user_id, password)?; Ok(()) } /// Returns the number of users registered on this server. - pub(crate) fn count(&self) -> Result { self.db.count() } + pub fn count(&self) -> Result { self.db.count() } /// Find out which user an access token belongs to. - pub(crate) fn find_from_token(&self, token: &str) -> Result> { + pub fn find_from_token(&self, token: &str) -> Result> { self.db.find_from_token(token) } /// Returns an iterator over all users on this homeserver. - pub(crate) fn iter(&self) -> impl Iterator> + '_ { self.db.iter() } + pub fn iter(&self) -> impl Iterator> + '_ { self.db.iter() } /// Returns a list of local users as list of usernames. /// /// A user account is considered `local` if the length of it's password is /// greater then zero. - pub(crate) fn list_local_users(&self) -> Result> { self.db.list_local_users() } + pub fn list_local_users(&self) -> Result> { self.db.list_local_users() } /// Returns the password hash for the given user. - pub(crate) fn password_hash(&self, user_id: &UserId) -> Result> { self.db.password_hash(user_id) } + pub fn password_hash(&self, user_id: &UserId) -> Result> { self.db.password_hash(user_id) } /// Hash and set the user's password to the Argon2 hash - pub(crate) fn set_password(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { + pub fn set_password(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { self.db.set_password(user_id, password) } /// Returns the displayname of a user on this homeserver. - pub(crate) fn displayname(&self, user_id: &UserId) -> Result> { self.db.displayname(user_id) } + pub fn displayname(&self, user_id: &UserId) -> Result> { self.db.displayname(user_id) } /// Sets a new displayname or removes it if displayname is None. You still /// need to nofify all rooms of this change. - pub(crate) async fn set_displayname(&self, user_id: &UserId, displayname: Option) -> Result<()> { + pub async fn set_displayname(&self, user_id: &UserId, displayname: Option) -> Result<()> { self.db.set_displayname(user_id, displayname) } /// Get the avatar_url of a user. - pub(crate) fn avatar_url(&self, user_id: &UserId) -> Result> { self.db.avatar_url(user_id) } + pub fn avatar_url(&self, user_id: &UserId) -> Result> { self.db.avatar_url(user_id) } /// Sets a new avatar_url or removes it if avatar_url is None. - pub(crate) async fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option) -> Result<()> { + pub async fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option) -> Result<()> { self.db.set_avatar_url(user_id, avatar_url) } /// Get the blurhash of a user. - pub(crate) fn blurhash(&self, user_id: &UserId) -> Result> { self.db.blurhash(user_id) } + pub fn blurhash(&self, user_id: &UserId) -> Result> { self.db.blurhash(user_id) } /// Sets a new avatar_url or removes it if avatar_url is None. - pub(crate) async fn set_blurhash(&self, user_id: &UserId, blurhash: Option) -> Result<()> { + pub async fn set_blurhash(&self, user_id: &UserId, blurhash: Option) -> Result<()> { self.db.set_blurhash(user_id, blurhash) } /// Adds a new device to a user. - pub(crate) fn create_device( + pub fn create_device( &self, user_id: &UserId, device_id: &DeviceId, token: &str, initial_device_display_name: Option, ) -> Result<()> { self.db @@ -315,21 +313,21 @@ impl Service { } /// Removes a device from a user. - pub(crate) fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { + pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { self.db.remove_device(user_id, device_id) } /// Returns an iterator over all device ids of this user. - pub(crate) fn all_device_ids<'a>(&'a self, user_id: &UserId) -> impl Iterator> + 'a { + pub fn all_device_ids<'a>(&'a self, user_id: &UserId) -> impl Iterator> + 'a { self.db.all_device_ids(user_id) } /// Replaces the access token of one device. - pub(crate) fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> { + pub fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> { self.db.set_token(user_id, device_id, token) } - pub(crate) fn add_one_time_key( + pub fn add_one_time_key( &self, user_id: &UserId, device_id: &DeviceId, one_time_key_key: &DeviceKeyId, one_time_key_value: &Raw, ) -> Result<()> { @@ -339,29 +337,27 @@ impl Service { // TODO: use this ? #[allow(dead_code)] - pub(crate) fn last_one_time_keys_update(&self, user_id: &UserId) -> Result { + pub fn last_one_time_keys_update(&self, user_id: &UserId) -> Result { self.db.last_one_time_keys_update(user_id) } - pub(crate) fn take_one_time_key( + pub fn take_one_time_key( &self, user_id: &UserId, device_id: &DeviceId, key_algorithm: &DeviceKeyAlgorithm, ) -> Result)>> { self.db.take_one_time_key(user_id, device_id, key_algorithm) } - pub(crate) fn count_one_time_keys( + pub fn count_one_time_keys( &self, user_id: &UserId, device_id: &DeviceId, ) -> Result> { self.db.count_one_time_keys(user_id, device_id) } - pub(crate) fn add_device_keys( - &self, user_id: &UserId, device_id: &DeviceId, device_keys: &Raw, - ) -> Result<()> { + pub fn add_device_keys(&self, user_id: &UserId, device_id: &DeviceId, device_keys: &Raw) -> Result<()> { self.db.add_device_keys(user_id, device_id, device_keys) } - pub(crate) fn add_cross_signing_keys( + pub fn add_cross_signing_keys( &self, user_id: &UserId, master_key: &Raw, self_signing_key: &Option>, user_signing_key: &Option>, notify: bool, ) -> Result<()> { @@ -369,58 +365,56 @@ impl Service { .add_cross_signing_keys(user_id, master_key, self_signing_key, user_signing_key, notify) } - pub(crate) fn sign_key( + pub fn sign_key( &self, target_id: &UserId, key_id: &str, signature: (String, String), sender_id: &UserId, ) -> Result<()> { self.db.sign_key(target_id, key_id, signature, sender_id) } - pub(crate) fn keys_changed<'a>( + pub fn keys_changed<'a>( &'a self, user_or_room_id: &str, from: u64, to: Option, ) -> impl Iterator> + 'a { self.db.keys_changed(user_or_room_id, from, to) } - pub(crate) fn mark_device_key_update(&self, user_id: &UserId) -> Result<()> { - self.db.mark_device_key_update(user_id) - } + pub fn mark_device_key_update(&self, user_id: &UserId) -> Result<()> { self.db.mark_device_key_update(user_id) } - pub(crate) fn get_device_keys(&self, user_id: &UserId, device_id: &DeviceId) -> Result>> { + pub fn get_device_keys(&self, user_id: &UserId, device_id: &DeviceId) -> Result>> { self.db.get_device_keys(user_id, device_id) } - pub(crate) fn parse_master_key( + pub fn parse_master_key( &self, user_id: &UserId, master_key: &Raw, ) -> Result<(Vec, CrossSigningKey)> { self.db.parse_master_key(user_id, master_key) } - pub(crate) fn get_key( + pub fn get_key( &self, key: &[u8], sender_user: Option<&UserId>, user_id: &UserId, allowed_signatures: &dyn Fn(&UserId) -> bool, ) -> Result>> { self.db .get_key(key, sender_user, user_id, allowed_signatures) } - pub(crate) fn get_master_key( + pub fn get_master_key( &self, sender_user: Option<&UserId>, user_id: &UserId, allowed_signatures: &dyn Fn(&UserId) -> bool, ) -> Result>> { self.db .get_master_key(sender_user, user_id, allowed_signatures) } - pub(crate) fn get_self_signing_key( + pub fn get_self_signing_key( &self, sender_user: Option<&UserId>, user_id: &UserId, allowed_signatures: &dyn Fn(&UserId) -> bool, ) -> Result>> { self.db .get_self_signing_key(sender_user, user_id, allowed_signatures) } - pub(crate) fn get_user_signing_key(&self, user_id: &UserId) -> Result>> { + pub fn get_user_signing_key(&self, user_id: &UserId) -> Result>> { self.db.get_user_signing_key(user_id) } - pub(crate) fn add_to_device_event( + pub fn add_to_device_event( &self, sender: &UserId, target_user_id: &UserId, target_device_id: &DeviceId, event_type: &str, content: serde_json::Value, ) -> Result<()> { @@ -428,35 +422,33 @@ impl Service { .add_to_device_event(sender, target_user_id, target_device_id, event_type, content) } - pub(crate) fn get_to_device_events( - &self, user_id: &UserId, device_id: &DeviceId, - ) -> Result>> { + pub fn get_to_device_events(&self, user_id: &UserId, device_id: &DeviceId) -> Result>> { self.db.get_to_device_events(user_id, device_id) } - pub(crate) fn remove_to_device_events(&self, user_id: &UserId, device_id: &DeviceId, until: u64) -> Result<()> { + pub fn remove_to_device_events(&self, user_id: &UserId, device_id: &DeviceId, until: u64) -> Result<()> { self.db.remove_to_device_events(user_id, device_id, until) } - pub(crate) fn update_device_metadata(&self, user_id: &UserId, device_id: &DeviceId, device: &Device) -> Result<()> { + pub fn update_device_metadata(&self, user_id: &UserId, device_id: &DeviceId, device: &Device) -> Result<()> { self.db.update_device_metadata(user_id, device_id, device) } /// Get device metadata. - pub(crate) fn get_device_metadata(&self, user_id: &UserId, device_id: &DeviceId) -> Result> { + pub fn get_device_metadata(&self, user_id: &UserId, device_id: &DeviceId) -> Result> { self.db.get_device_metadata(user_id, device_id) } - pub(crate) fn get_devicelist_version(&self, user_id: &UserId) -> Result> { + pub fn get_devicelist_version(&self, user_id: &UserId) -> Result> { self.db.get_devicelist_version(user_id) } - pub(crate) fn all_devices_metadata<'a>(&'a self, user_id: &UserId) -> impl Iterator> + 'a { + pub fn all_devices_metadata<'a>(&'a self, user_id: &UserId) -> impl Iterator> + 'a { self.db.all_devices_metadata(user_id) } /// Deactivate account - pub(crate) fn deactivate_account(&self, user_id: &UserId) -> Result<()> { + pub fn deactivate_account(&self, user_id: &UserId) -> Result<()> { // Remove all associated devices for device_id in self.all_device_ids(user_id) { self.remove_device(user_id, &device_id?)?; @@ -473,17 +465,17 @@ impl Service { } /// Creates a new sync filter. Returns the filter id. - pub(crate) fn create_filter(&self, user_id: &UserId, filter: &FilterDefinition) -> Result { + pub fn create_filter(&self, user_id: &UserId, filter: &FilterDefinition) -> Result { self.db.create_filter(user_id, filter) } - pub(crate) fn get_filter(&self, user_id: &UserId, filter_id: &str) -> Result> { + pub fn get_filter(&self, user_id: &UserId, filter_id: &str) -> Result> { self.db.get_filter(user_id, filter_id) } } /// Ensure that a user only sees signatures from themselves and the target user -pub(crate) fn clean_signatures bool>( +pub fn clean_signatures bool>( cross_signing_key: &mut serde_json::Value, sender_user: Option<&UserId>, user_id: &UserId, allowed_signatures: F, ) -> Result<(), Error> { if let Some(signatures) = cross_signing_key diff --git a/src/utils/server_name.rs b/src/utils/server_name.rs deleted file mode 100644 index 11303f9a..00000000 --- a/src/utils/server_name.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! utilities for doing/checking things with ServerName's/server_name's - -use ruma::ServerName; - -use crate::services; - -/// checks if `server_name` is ours -pub(crate) fn server_is_ours(server_name: &ServerName) -> bool { server_name == services().globals.config.server_name } diff --git a/src/utils/user_id.rs b/src/utils/user_id.rs deleted file mode 100644 index ae312792..00000000 --- a/src/utils/user_id.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! utilities for doing things with UserId's / usernames - -use ruma::UserId; - -use crate::services; - -/// checks if `user_id` is local to us via server_name comparison -pub(crate) fn user_is_local(user_id: &UserId) -> bool { user_id.server_name() == services().globals.config.server_name } From 9bfa89a5553de66a896eb6abb62baaaddb095ab5 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 18 May 2024 22:32:02 -0400 Subject: [PATCH 0104/2291] adjust debian metadata, set crane workspace name Signed-off-by: strawberry --- .github/workflows/ci.yml | 3 ++- Cargo.toml | 3 +++ src/bin/Cargo.toml | 13 +++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 143dfc56..fd13c073 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -213,7 +213,8 @@ jobs: mkdir -v -p target/$CARGO_DEB_TARGET_TUPLE/release/ cp -v -f result/bin/conduit target/release/conduwuit cp -v -f result/bin/conduit target/$CARGO_DEB_TARGET_TUPLE/release/conduwuit - direnv exec . cargo deb --verbose --no-build --no-strip --target=$CARGO_DEB_TARGET_TUPLE --output target/release/${{ matrix.target }}.deb + # -p conduit is the main crate name + direnv exec . cargo deb --verbose --no-build --no-strip -p conduit --target=$CARGO_DEB_TARGET_TUPLE --output target/release/${{ matrix.target }}.deb mv -v target/release/conduwuit static-${{ matrix.target }} mv -v target/release/${{ matrix.target }}.deb ${{ matrix.target }}.deb diff --git a/Cargo.toml b/Cargo.toml index 2e2153a9..798cd0f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,9 @@ homepage = "https://conduwuit.puppyirl.gay/" repository = "https://github.com/girlbossceo/conduwuit" readme = "README.md" +[workspace.metadata.crane] +name = "conduit" + # 1.1.17 seems broken on nix from a permission error? [workspace.dependencies.libz-sys] version = "=1.1.16" diff --git a/src/bin/Cargo.toml b/src/bin/Cargo.toml index e50dba24..282f6aac 100644 --- a/src/bin/Cargo.toml +++ b/src/bin/Cargo.toml @@ -11,25 +11,26 @@ readme.workspace = true version.workspace = true edition.workspace = true rust-version.workspace = true +metadata.crane.workspace = true [package.metadata.deb] name = "conduwuit" maintainer = "strawberry " copyright = "2024, strawberry " -license-file = ["LICENSE", "3"] +license-file = ["../../LICENSE", "3"] depends = "$auto, ca-certificates" extended-description = """\ a cool hard fork of Conduit, a Matrix homeserver written in Rust""" section = "net" priority = "optional" conf-files = ["/etc/conduwuit/conduwuit.toml"] -maintainer-scripts = "debian/" +maintainer-scripts = "../../debian/" systemd-units = { unit-name = "conduwuit", start = false } assets = [ - ["debian/README.md", "usr/share/doc/conduwuit/README.Debian", "644"], - ["README.md", "usr/share/doc/conduwuit/", "644"], - ["target/release/conduwuit", "usr/sbin/conduwuit", "755"], - ["conduwuit-example.toml", "etc/conduwuit/conduwuit.toml", "640"], + ["../../debian/README.md", "usr/share/doc/conduwuit/README.Debian", "644"], + ["../../README.md", "usr/share/doc/conduwuit/", "644"], + ["../../target/release/conduwuit", "usr/sbin/conduwuit", "755"], + ["../../conduwuit-example.toml", "etc/conduwuit/conduwuit.toml", "640"], ] [features] From 4aeec78ab4a455066235cde3b89e26bb9303c7d9 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 18 May 2024 23:26:58 -0400 Subject: [PATCH 0105/2291] debian: remove old symlink on postrm Signed-off-by: strawberry --- debian/postrm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/debian/postrm b/debian/postrm index d77a885e..f516f2a2 100644 --- a/debian/postrm +++ b/debian/postrm @@ -5,6 +5,7 @@ set -e CONDUWUIT_CONFIG_PATH=/etc/conduwuit CONDUWUIT_DATABASE_PATH=/var/lib/conduwuit +CONDUWUIT_DATABASE_PATH_SYMLINK=/var/lib/matrix-conduit case $1 in purge) @@ -21,6 +22,10 @@ case $1 in if [ -d "$CONDUWUIT_DATABASE_PATH" ]; then rm -v -r "$CONDUWUIT_DATABASE_PATH" fi + + if [ -d "$CONDUWUIT_DATABASE_PATH_SYMLINK" ]; then + rm -v -r "$CONDUWUIT_DATABASE_PATH_SYMLINK" + fi ;; esac From 362649ff870f288c01d0fcd894100f084f6a28b5 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 19 May 2024 07:40:12 +0000 Subject: [PATCH 0106/2291] rename src/bin to src/main Signed-off-by: Jason Volk --- src/{bin => main}/Cargo.toml | 0 src/{bin => main}/main.rs | 0 src/{bin => main}/mods.rs | 0 src/{bin => main}/server.rs | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/{bin => main}/Cargo.toml (100%) rename src/{bin => main}/main.rs (100%) rename src/{bin => main}/mods.rs (100%) rename src/{bin => main}/server.rs (100%) diff --git a/src/bin/Cargo.toml b/src/main/Cargo.toml similarity index 100% rename from src/bin/Cargo.toml rename to src/main/Cargo.toml diff --git a/src/bin/main.rs b/src/main/main.rs similarity index 100% rename from src/bin/main.rs rename to src/main/main.rs diff --git a/src/bin/mods.rs b/src/main/mods.rs similarity index 100% rename from src/bin/mods.rs rename to src/main/mods.rs diff --git a/src/bin/server.rs b/src/main/server.rs similarity index 100% rename from src/bin/server.rs rename to src/main/server.rs From 1f3a9a40e5ab537119beaf27a2c644e212aa0b46 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 19 May 2024 10:56:59 +0000 Subject: [PATCH 0107/2291] lint clippy::collapsible_match (nightly) Signed-off-by: Jason Volk --- src/service/pdu.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/service/pdu.rs b/src/service/pdu.rs index 4912f1c4..f608200b 100644 --- a/src/service/pdu.rs +++ b/src/service/pdu.rs @@ -328,20 +328,17 @@ impl PduEvent { unsigned.remove("transaction_id"); } + // room v3 and above removed the "event_id" field from remote PDU format if let Some(room_id) = pdu_json .get("room_id") .and_then(|val| RoomId::parse(val.as_str()?).ok()) { - if let Ok(room_version_id) = services().rooms.state.get_room_version(&room_id) { - // room v3 and above removed the "event_id" field from remote PDU format - match room_version_id { + match services().rooms.state.get_room_version(&room_id) { + Ok(room_version_id) => match room_version_id { RoomVersionId::V1 | RoomVersionId::V2 => {}, - _ => { - pdu_json.remove("event_id"); - }, - }; - } else { - pdu_json.remove("event_id"); + _ => _ = pdu_json.remove("event_id"), + }, + Err(_) => _ = pdu_json.remove("event_id"), } } else { pdu_json.remove("event_id"); From fdc9a9a1b80459325557ab602478c69044802838 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 20 May 2024 07:41:45 +0000 Subject: [PATCH 0108/2291] add cargo smoketest Signed-off-by: Jason Volk --- tests/cargo_smoke.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 tests/cargo_smoke.sh diff --git a/tests/cargo_smoke.sh b/tests/cargo_smoke.sh new file mode 100755 index 00000000..90a7f124 --- /dev/null +++ b/tests/cargo_smoke.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +run () { + RUN_COMMAND=$@ + echo -e "\033[1;33mTEST\033[0m $RUN_COMMAND" + ERRORS=$($RUN_COMMAND 2>&1>/tmp/uwu_smoketest.out) + RESULT=$? + if test $RESULT -ne 0; then + cat /tmp/uwu_smoketest.out + echo -e "$ERRORS" + echo -e "\033[1;5;41;37mFAIL\033[0m exit ($RESULT): $RUN_COMMAND" + exit $RESULT + else + echo -ne "\033[1F" + echo -e "\033[1;32mPASS\033[0m $RUN_COMMAND" + echo -e "\033[1;32mPASS\033[0m $RUN_COMMAND" + fi +} + +conduwuit () { + UWU_OPTS=$@ + rm -rf /tmp/uwu_smoketest.db + echo -e "[global]\nserver_name = \"localhost\"\ndatabase_path = \"/tmp/uwu_smoketest.db\"" > /tmp/uwu_smoketest.toml + cargo run $UWU_OPTS -- -c /tmp/uwu_smoketest.toml & + sleep 5s + kill -QUIT %1 + wait %1 + return $? +} + +element () { + ELEMENT_OPTS=$@ + run cargo check $ELEMENT_OPTS --all-targets + run cargo clippy $ELEMENT_OPTS --all-targets -- -D warnings + run cargo build $ELEMENT_OPTS --all-targets + run cargo test $ELEMENT_OPTS --all-targets + run cargo bench $ELEMENT_OPTS --all-targets + run cargo run $ELEMENT_OPTS --bin conduit -- -V + run conduwuit $ELEMENT_OPTS --bin conduit +} + +vector () { + VECTOR_OPTS=$@ + element $VECTOR_OPTS --no-default-features --features="rocksdb" + element $VECTOR_OPTS --features=default + element $VECTOR_OPTS --all-features +} + +matrix () { + run cargo fmt --all --check + vector --profile=dev + vector --profile=release +} + +matrix && +exit 0 From 74832bdc47d56bc37657ced23dc687c1464be985 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 19 May 2024 13:02:55 +0000 Subject: [PATCH 0109/2291] fix smoke from builds produced by --all-features Signed-off-by: Jason Volk --- Cargo.toml | 11 ++++++++++- src/core/Cargo.toml | 5 ----- src/core/debug.rs | 1 - src/core/mod.rs | 4 ++-- src/core/mods/mod.rs | 2 +- src/main/Cargo.toml | 2 -- src/main/main.rs | 4 ++-- src/main/mods.rs | 6 ++---- src/main/server.rs | 8 ++++---- 9 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 798cd0f2..4dc05d71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -526,7 +526,6 @@ inherits = "release" # To enable hot-reloading: # 1. Uncomment all of the rustflags here. # 2. Uncomment crate-type=dylib in src/*/Cargo.toml and deps/rust-rocksdb/Cargo.toml -# 2. Build with the 'mods' feature. # # opt-level, mir-opt-level, validate-mir are not known to interfere with reloading # and can be raised if build times are tolerable. @@ -540,6 +539,7 @@ incremental = true codegen-units = 64 rpath = true #rustflags = [ +# '--cfg', 'conduit_mods', # '-Ztime-passes', # '-Zmir-opt-level=0', # '-Zvalidate-mir=false', @@ -560,6 +560,7 @@ rpath = true inherits = "dev" incremental = false #rustflags = [ +# '--cfg', 'conduit_mods', # '-Ztime-passes', # '-Zmir-opt-level=0', # '-Ztls-model=initial-exec', @@ -580,6 +581,7 @@ incremental = false inherits = "dev" incremental = false #rustflags = [ +# '--cfg', 'conduit_mods', # '-Ztime-passes', # '-Zmir-opt-level=0', # '-Zvalidate-mir=false', @@ -601,6 +603,7 @@ incremental = false codegen-units = 1 opt-level = 'z' #rustflags = [ +# '--cfg', 'conduit_mods', # '-Ztls-model=initial-exec', # '-Cprefer-dynamic=true', # '-Zstaticlib-prefer-dynamic=true', @@ -621,6 +624,7 @@ incremental = false codegen-units = 1 opt-level = 'z' #rustflags = [ +# '--cfg', 'conduit_mods', # '-Ztls-model=global-dynamic', # '-Cprefer-dynamic=true', # '-Zstaticlib-prefer-dynamic=true', @@ -655,6 +659,11 @@ unreachable_pub = "warn" # this seems to suggest broken code and is not working correctly unused_braces = "allow" +# cfgs cannot be limited to features or cargo build --all-features panics for unsuspecting users. +# cfgs cannot be limited to expected cfgs or their de facto non-transitive/opt-in use-case e.g. +# tokio_unstable will warn. +unexpected_cfgs = "allow" + # some sadness missing_docs = "allow" diff --git a/src/core/Cargo.toml b/src/core/Cargo.toml index 89ec7248..6b700f1f 100644 --- a/src/core/Cargo.toml +++ b/src/core/Cargo.toml @@ -63,10 +63,6 @@ brotli_compression = [ ] perf_measurements = [] sentry_telemetry = [] -mods = [ - "dep:libloading" -] -panic_trap = [] [dependencies] async-trait.workspace = true @@ -86,7 +82,6 @@ infer.workspace = true ipaddress.workspace = true itertools.workspace = true libloading.workspace = true -libloading.optional = true log.workspace = true lru-cache.workspace = true parking_lot.optional = true diff --git a/src/core/debug.rs b/src/core/debug.rs index fa998265..6db9a4dd 100644 --- a/src/core/debug.rs +++ b/src/core/debug.rs @@ -62,7 +62,6 @@ fn panic_handler(info: &PanicInfo<'_>, next: &dyn Fn(&PanicInfo<'_>)) { } #[inline(always)] -#[allow(unexpected_cfgs)] pub fn trap() { #[cfg(core_intrinsics)] //SAFETY: embeds llvm intrinsic for hardware breakpoint diff --git a/src/core/mod.rs b/src/core/mod.rs index 8e0a481b..5911e027 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -14,8 +14,8 @@ pub use pducount::PduCount; pub use server::Server; pub use utils::conduwuit_version; -#[cfg(not(feature = "mods"))] -mod mods { +#[cfg(not(conduit_mods))] +pub mod mods { #[macro_export] macro_rules! mod_ctor { () => {}; diff --git a/src/core/mods/mod.rs b/src/core/mods/mod.rs index e60a0f5e..118bfc29 100644 --- a/src/core/mods/mod.rs +++ b/src/core/mods/mod.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "mods")] +#![cfg(conduit_mods)] pub(crate) use libloading::os::unix::{Library, Symbol}; diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 282f6aac..a866b466 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -67,8 +67,6 @@ perf_measurements = [ jemalloc = [ "dep:tikv-jemallocator", ] -panic_trap = [] -mods = [] [dependencies] conduit-router.workspace = true diff --git a/src/main/main.rs b/src/main/main.rs index 0d049fcb..0f841563 100644 --- a/src/main/main.rs +++ b/src/main/main.rs @@ -37,7 +37,7 @@ fn main() -> Result<(), Error> { /// Operate the server normally in release-mode static builds. This will start, /// run and stop the server within the asynchronous runtime. -#[cfg(not(feature = "mods"))] +#[cfg(not(conduit_mods))] async fn async_main(server: Arc) -> Result<(), Error> { extern crate conduit_router as router; use tracing::error; @@ -64,7 +64,7 @@ async fn async_main(server: Arc) -> Result<(), Error> { /// Operate the server in developer-mode dynamic builds. This will start, run, /// and hot-reload portions of the server as-needed before returning for an /// actual shutdown. This is not available in release-mode or static builds. -#[cfg(feature = "mods")] +#[cfg(conduit_mods)] async fn async_main(server: Arc) -> Result<(), Error> { let mut starts = true; let mut reloads = true; diff --git a/src/main/mods.rs b/src/main/mods.rs index 404fa467..90a25f97 100644 --- a/src/main/mods.rs +++ b/src/main/mods.rs @@ -1,6 +1,4 @@ -#![cfg(feature = "mods")] -#[cfg(not(any(clippy, debug_assertions, doctest, test)))] -compile_error!("Feature 'mods' is only available in developer builds"); +#![cfg(conduit_mods)] use std::{ future::Future, @@ -26,7 +24,7 @@ const MODULE_NAMES: &[&str] = &[ "conduit_router", ]; -#[cfg(feature = "panic_trap")] +#[cfg(panic_trap)] conduit::mod_init! {{ conduit::debug::set_panic_trap(); }} diff --git a/src/main/server.rs b/src/main/server.rs index e63c0dc0..8b68d1c4 100644 --- a/src/main/server.rs +++ b/src/main/server.rs @@ -21,8 +21,8 @@ pub(crate) struct Server { #[cfg(feature = "sentry_telemetry")] _sentry_guard: Option, + #[cfg(conduit_mods)] // Module instances; TODO: move to mods::loaded mgmt vector - #[cfg(feature = "mods")] pub(crate) mods: tokio::sync::RwLock>, } @@ -52,7 +52,7 @@ impl Server { #[cfg(feature = "sentry_telemetry")] _sentry_guard: sentry_guard, - #[cfg(feature = "mods")] + #[cfg(conduit_mods)] mods: tokio::sync::RwLock::new(Vec::new()), })) } @@ -109,7 +109,7 @@ fn init_tracing(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard) { let mut reload_handles = Vec:: + Send + Sync>>::new(); let subscriber = registry; - #[cfg(feature = "tokio_console")] + #[cfg(all(feature = "tokio_console", tokio_unstable))] let subscriber = { let console_layer = console_subscriber::spawn(); subscriber.with(console_layer) @@ -176,7 +176,7 @@ fn init_tracing(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard) { tracing::subscriber::set_global_default(subscriber).unwrap(); - #[cfg(all(feature = "tokio_console", feature = "release_max_log_level"))] + #[cfg(all(feature = "tokio_console", feature = "release_max_log_level", tokio_unstable))] tracing::error!( "'tokio_console' feature and 'release_max_log_level' feature are incompatible, because console-subscriber \ needs access to trace-level events. 'release_max_log_level' must be disabled to use tokio-console." From 2dd5cf8c6821d369ac671517051d35facca8b728 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 20 May 2024 08:11:05 +0000 Subject: [PATCH 0110/2291] move clap; fix version Signed-off-by: Jason Volk --- src/core/utils/mod.rs | 1 - src/{core/utils => main}/clap.rs | 11 +++++------ src/main/main.rs | 3 ++- src/main/server.rs | 6 ++++-- 4 files changed, 11 insertions(+), 10 deletions(-) rename src/{core/utils => main}/clap.rs (65%) diff --git a/src/core/utils/mod.rs b/src/core/utils/mod.rs index 1cdb6727..a91e6447 100644 --- a/src/core/utils/mod.rs +++ b/src/core/utils/mod.rs @@ -13,7 +13,6 @@ use tracing::debug; use crate::{Error, Result}; -pub mod clap; pub mod content_disposition; pub mod defer; diff --git a/src/core/utils/clap.rs b/src/main/clap.rs similarity index 65% rename from src/core/utils/clap.rs rename to src/main/clap.rs index c1dcb586..81a6da72 100644 --- a/src/core/utils/clap.rs +++ b/src/main/clap.rs @@ -2,19 +2,18 @@ use std::path::PathBuf; -pub use clap::Parser; - -use super::conduwuit_version; +use clap::Parser; +use conduit_core::utils::conduwuit_version; /// Commandline arguments #[derive(Parser, Debug)] #[clap(version = conduwuit_version(), about, long_about = None)] -pub struct Args { +pub(crate) struct Args { #[arg(short, long)] /// Optional argument to the path of a conduwuit config TOML file - pub config: Option, + pub(crate) config: Option, } /// Parse commandline arguments into structured data #[must_use] -pub fn parse() -> Args { Args::parse() } +pub(crate) fn parse() -> Args { Args::parse() } diff --git a/src/main/main.rs b/src/main/main.rs index 0f841563..68b7a1c2 100644 --- a/src/main/main.rs +++ b/src/main/main.rs @@ -1,3 +1,4 @@ +pub(crate) mod clap; mod mods; mod server; @@ -5,7 +6,7 @@ extern crate conduit_core as conduit; use std::{cmp, sync::Arc, time::Duration}; -use conduit::{debug_info, error, utils::clap, Error, Result}; +use conduit::{debug_info, error, Error, Result}; use server::Server; use tokio::runtime; diff --git a/src/main/server.rs b/src/main/server.rs index 8b68d1c4..c3f6a928 100644 --- a/src/main/server.rs +++ b/src/main/server.rs @@ -5,12 +5,14 @@ use conduit::{ config::Config, info, log::{LogLevelReloadHandles, ReloadHandle}, - utils::{clap, maximize_fd_limit}, + utils::maximize_fd_limit, Error, Result, }; use tokio::runtime; use tracing_subscriber::{prelude::*, reload, EnvFilter, Registry}; +use crate::clap::Args; + /// Server runtime state; complete pub(crate) struct Server { /// Server runtime state; public portion @@ -27,7 +29,7 @@ pub(crate) struct Server { } impl Server { - pub(crate) fn build(args: clap::Args, runtime: Option<&runtime::Handle>) -> Result, Error> { + pub(crate) fn build(args: Args, runtime: Option<&runtime::Handle>) -> Result, Error> { let config = Config::new(args.config)?; #[cfg(feature = "sentry_telemetry")] let sentry_guard = init_sentry(&config); From 981ec51ec09c7592f4e54a3c46bde56b4270bccb Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 19 May 2024 18:28:26 -0400 Subject: [PATCH 0111/2291] docs: add initial docs for hot reload Signed-off-by: strawberry --- docs/development/assets/libraries.png | Bin 0 -> 77853 bytes docs/development/assets/reload_order.png | Bin 0 -> 62733 bytes docs/development/hot_reload.md | 77 +++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 docs/development/assets/libraries.png create mode 100644 docs/development/assets/reload_order.png create mode 100644 docs/development/hot_reload.md diff --git a/docs/development/assets/libraries.png b/docs/development/assets/libraries.png new file mode 100644 index 0000000000000000000000000000000000000000..e8edf878feea9e691f559398a64e36d2802c4e99 GIT binary patch literal 77853 zcmeFZXH=8h*Do42Qj{iwfYL=o1p!fd-+-VrDN>|~RB54i2vS9)iGWBIq$41`M?mSl z_t1Oj2_zxOd4l^r|NVZr<9@n#oN>k*J|xe2=9+8HRpwl4&fg;PxrQ>;m77;UAQ074 z6-8|jh|CBCB26Iw3n;mLX`~eRB7Lo@tO&vr{<50$6F?vi&{IWuUGKErc^`ihk91j_ z+s8X^W~$!I2#bK1TG^|6OF%f_i&hl{+D5-k%w zZQ(V=;b5x=^tP%L^9BvW+$JL;jx)DUGhpnZ^-o7{s{_9m(l(B1*lXwf2C&~`7PdB8 z1~4s}OiEgSOdyaP<%wjl#a`V?%$_OfMTyD8c$LVme{4Ai6XBUd(nAOe*S+PxS^us5 zf*{4?Qa9ZE+LB%;MKBSeq(XfoWG?2~Qc^_sKLv(1*XBLxmQIK&UJ(d_jE7ySQoSy9 z5*|Qt=?!V*Q6U#qUG>RsfOixPSST;v?98b89!nhGx}bAaP4xjQ>u_B>beXWKM_;`} zOn5kXx^-4NFWz?XVzr@WgZv*s(B-=1bIA0yix->B)NVH77eCS8n&j*S2|wke9-or; zhF!Fc{-%5G*U9Sj`R2vrRmN-P1d^b-IP!~TeuXLi=>h)Rf0}aPq`l~(cNCF-m>H{t zUQ}KF`__g0|HA?V`k%f4$^CyiFE*36NaUzfCB2;Tl0gA;O+Lp$&7mT?z(-FnkL?@Y zq8GpXqmwPa_x5aoS*-NlR;Qs6CdKrx6PIa2jGW)?wjrzFSDV6HuDuzyb%$JQN!Pz; z+M>*)kW(uql;LA#oouIVDF7L+JUDB4eReeVEmC*R->>)MWua5lbL`*Xo|+l(Q@Fz5 z(`5fI#!MA@_lc6o74oZkf=OD3QeP^yH)m3a)=HfTUN#wHX^TmVj~|dnP~3=bodGA3 z6bEdof6q3r7qsMz6m-|?6*FLd8ScBfy3JVeLUS^3`>hyL#j}Rn*d5C0C$}ga>BtmBcD9}~ zZHgDtL})X=OU)=IaDDVu(2^%ouu7hVa=L8e@1>qb=n@zANkImNpi?SB5grx7iMbrc zN%1uFs|nDk>%8f=7BF>lpW`pFYH zhZ}!isaM7RO^KQi2eDA;aAgT|adB*X>p{K~*k=0sN{Ywh6~%FZ)zTbx?p@~1I5%yp zoos5$G{7iRa)zR4-ac_&^utt&IW2-2*K6^1xN?E|YCW5U8PNj2r|KDg-Ct|td;Mqpb0`Qj^dj#`+_?5vXCEJ*JjTC3C-ncS#KHm8 z_$2-VJk;bN9JW){$gO-c)02ss?S}FK%c+#>ZUW4i?3cP< z#KMjfxU03UUXmZepYh@jd%7L5ZO@vJU9o#+DL_Y%w~dUh2ckwEq9R)6hgQm5WaFOyCp4)?r*f(a9U@$iJlu zv1~)RSfo7J#0#*uRd>(YzQaP51=#Tx-(CKD?Bc%YlNX8kWbtbHC^`C0gkGwra+}K1W|+*f-dg@VkID$A`MfVwMtmX!h)i%S@r0 zl*VC0}o@BR}RX$ctTmrq>*4Rtk2ql<$V-Y+eglgfo2E)tCzI;*S$=Q4CzSZuZ9wb??uhX zSXH3sYt4)d*)PdoT}_NFc0^S$fNQ_HBMnDmVW<-U_PXP4gx{Bi2i}g;=dusP5FzY% z%&Ep*>X0n+*-9GhxgW&W#wPps8;0idO>m&36B5(nJ}TZxY3pW@JoN+pn~WW|vakPQ zlC`OakwFIE8_}cT2NSL}5f88pG>Z7h`j7E=x!n`kxE04*%!V4zp@E+4m4;79?sc*i z^YNwnA13NAc(?xIWDRH)E1Iub-H^qbtX06Phg*4k4u6~B(eX>287^24ePf9q5Jv5h zUokuo?@36rary^fo*hSIod4F$aDL8WT(J@B#4k5-MDae2hjHMkR{Ov_2HAo-ht8qKz9gmoXnLE=E$u8WT?DIg zLWO8b`R~7P{*J8IdVN|a3Wwi2KEV+QwYk`0s*l4iL6dA!YrGX6MkCBl{-WUFeot6*hi1uXiL`_-^YiE3C( zQL-$uOxD{@Nxh=E-(h~BmJPb!DDWT z%zm78q=F^AEY0&7p!n(t2pZlYCPq%C)`D|mZ?QFqk~;et9?^md$t-oSpb2Vl4G z=-TmOFn0F=PnEGdb_R7Cxb}9kwz_&nbI$~S77N9U#1*8o=Oq40N)9|kWb(~ChjkQg zdzGTb)4lZO&r<}_4Xw3#;?i%oozS{28Pmb1Yj#^?Wl-yH^^6MMD)`=_rT$pV-VCw2 zb%Vql7gX`oB7*9Q{X}!6kBtdEiTtNIar_cVJ~&_lQz$0Z$Nu>B?&^|Kq>0gl!<<`| zizXA?@UU@TTKL$0|HeX7OM!JO4fHruVE-wYxxM_=b01WJJocKOm%~&=?cr2``N}Bt zy!DU{DwVGsC=z43T_cj{1>qW{AZk#<{#CV7j)B|m7r_G7Bp;YwUB8|jEo0qwz!|0m zANXDjo7PT$FPZZTImw3IkUVY)oJD<~`OXJYsi%_3~)Y#zw8N+WX^T9Kim zo}+l{%5g+r!?r@E&;AE3CG)G7BIm)fCn1>&m?!G=ic~w9=ne%cz%5XJ@txt7kG|-%sgLg?VMnJ7tHa_E~D5#aK1#9XXff(ENvG%6j(cTEv(e!xH3};rKiKf zlB5=hS1!YLmC$Y_%_#Pxc>)iQ*=1^dAoQ2yt2UxLTTo|J_|u+;4-`UeVLh1($Ho%W z)R@?Yvl$x5a?|D9ElIyIxVHz+LN?I7yHQ~fv+U8C$QGE-4)=9jfJ&EVOL+7+5AE*A z;PiP|=k$Nh3TNjVmNJ#y$90bAMA55 zGQ`TPjb<+VSkGiPn!ZXRKX$NZFW}H(xy%&rEF$!0mt(8kiGi|_H5eD`Gb1% z5Zs25tbcPeitz!YyouJW6mzOMaC82aPPagc^Y8x5zF7E5m}-KY}%-0UgMAzrUrt@U?{!~Gq8;UtZQ(SR(`-MJ;UP0#xR9gNjL4|vextX z$}))`_bf^2sFt0)YLD4k=L4TfWB1p*Yy5eE{9oN%KC0d5xyoaxZ0N+rzMN^vF~N!t8FP`H3W{3w>;dKIW`K+f;UM*%~_4)D`53@Tj~zcMk_7hb;l z`4qd-pPy8lXb>7gmcKtaQ6AWu4mD}cSrXicDbj~Fa5j$-xedtd-JSJp&n60)MRj;U z4Er>)uOweTG#CLedWcNj*@?#iB?chxOF914c`Sa?EGW4MkS`e>;_O5g;7yhTcCxthMnvU za@Cl0AwKZ*x+1Wp)~yX}pZT>*htAcgFb_cACRvHi9P98}m*A?$j_*VKOscHl%toi8 z8c|Gc6EOevw!$z+s0?JTPkasXvR2%qIJUVAyH1uFxHLsEknYi%wi3gxHD^6(gheCv zZ>N6TJ%9Kp*1a(Oqpa)lX45O9`#~`^;MwV`EUpSNL2Ac-kxcOvHi_ls5SP5kq4|%P z8b{;9iEu9w$JwTU)6(YZY7Z(&k+Iy&368Yte|C5?qqsoHnfjcDEhlGrG25wkF?n@i zYim|M^7m<}v*#siMZX1y+HN2jcX>lUduP)1>?c{h+9NTQupC(prCBy=s{=qA4duvzL{g;;T zBX$h~U5Nq?O6}9~sE-&VJSzBuXd9^N7VUt<%}~ED#-E)g%kAe!A%VD90Y0M|E3=R} z#;ho93-Zz0xq#d6Sp*g0)FkV01jgjW#vt?6a{tk_OkVtu6$@4=JYPLsr|2i{z_o!mzjp&+c4fb<(Gc3}?VhH=XBIRjxe^ zRurOT`P#Hp3C2$CE;YjZ&o&^&O_EoFIcA#ABV_%y&IZ$ED&{5G*J8!iitwKUJF+)2 z{QO&sqeRB49D3g&!A4^Ho#5~IgGrnna`PNG%_h}mMqQ(#lAis+JTCf}<_iS{#e3hA zc~HzdMX^TPt9w?i<}uH7kC&Uh0^x&3H}}g~)@g3YuB46TWr|tNg~lsHP_YSS-Sypy zz@LwA%&J8Z*;*#u{gp5?nC5(tMbsbZ+`k~r+ALO7Sg7t*A09?bDjM^doGkHi=IwgF z!BVdIqi`jwPBmHUXSk}uFiCKuo7M{<@?hK35g4#l*1@f1FGVbz)uVnc)4K83`wnpH z!>3Os+LDu{DxJHF_eBCM1fJ7x8 z>ht9HqI^novWQ&j?KTd^0lf!ht2~v0I?;9vc;u|Qi?i6P<#AE`T68{@Y#qtZ=rFgC zKZk6&$*_ zz&U!g#8Y#m@CB8)$KLmiW-Nr!K~oWMeEfl%t+0W!6X0}|I=@bHGoa6}RBB!NI^@Tj zt@Hi4<9zP%!qfq{+4*vh$wu14+mxz3q>SP60V{)z0iy$VnT9PMI%aRDt8bA@gLgk4 z<)BoFHaP=@<#URPirBH6$|vhA5l=G4^rNq_f!Q7` zlydomFy$ZbA{%nVqn4hsXRPkv>x0_!Je`R|M46Vo@f87YR(0p3YKNXjCgkOd?nXur zHdnxH$=1V(txeqeF;CX>HExc#c);d0o99ssQRU7j-O2csPHP%RW8F`4)r}IsjNBCU zJvnnPPn&Bx|2~s}aftW!`n{a44x#hOeU$ep(j{{piUjny2`1I|Izbd#q#A z-6Ee2gu1d+#qQ>9U^_qJ{wTVMvs2CP*t08=;dGY6?}e`JHzy|rtX|?YhXPRnFu2bY}Cuas$+)oEnOYfXSZVB9s zAhu5P^Vhk}!adOkaUIqYbqOVoso%2Lhyf3TW}aEEp=**SVzO!1+DDeaE?V0Weate5 z&?WWE2ie3?nLZx&M!eBQu(S5%Z4E4Cx99pDWk0iXY}C$|j9zBn^AsIlCmE8T@sEW6 zx|x`qOo+ga7IQq{OO^0Z!=)C&b#*IG7@@MKtHnI@qEL>RM%-_9obv*^sP$&ftEsZ` z@_Uyw_7>_8a*wwbY0Zam*MUGxi2k->n{(CngzO1Sw#jCE!IFMGQ4O`pDC^U|+Lq({ zp3fr5*1vGiTL+UuPc61m@u&le9%}$X8rk9fgSbKB1Uw>~?xi|h`e2U&hC_|y5w)7* z-)tC*S1W}BTl5`iwToH@SSqlr{h5>jm^I-xuI!4FD>yU%I>WmcgpzS z8x(<)fG%{q)(hJ|alDZs<6->td8OMia}=ZW;Ru>FeWo1oq3LTvCxT{jPo3(X(bHbHdOA7C^XG~u3CiA1= zI=z#VdB=-~lYy%x56Q^Nl{!t2emqLTbsjf>#TQ=ab6 z9d+HkOMXJv;QtfO& z;F3_Y7wl4JzbYBcT)OAntTos^0TCiysNdRgEaWuVUR#y=xK}{RPg`d-UKXBxtQmOp zRUesaeR<#T1Pa5oG258R*dNu6w5=|{?M=;&ejVG_jFFf#g=@K=J@Bu>BVhjcO5TCb zeoIez)bBFWPr#?n2iiy|*i5v?-F3DEA!li+{A`5^OkEn+%wMZBq>Udbo1xwsLe7w? zMs$S%M(|mIb6lzb%gM)b+p(~G2I)p;$2&J&C^W^v$SFn!2Nl3(3Oo3qp!hdi^ISa< z*YDUBdFhUi@#Jvqimp~ob4|3=*)^6`wZ%sjiM*&TI4lUXA5T&gY=Y6sDos3%4k#!o z={xy*)2c{vZ!9o8469j>%rhzqJitzR0zBS*Y+Ud`;WC^2A*p3>(evzBn0x;(g^@Yu zq3KE3L94o~?`Ar2v=Oqumkm8#5iujCgo~q9P?boDW%$szzLMO0RNc8S1)FL+{~lqD zJEa;`ZR2={ls=s$Dc;H9Aiw4}A$_>0i972Jew!OYx-L4lJ5yQ4`E28d#Xu(J>(l;y zM(T98-tj2t$2%iC)|MAb7^x)=x1pGyRh&MKPT$(vmLAEXe-F-i zZhfM?fmYXZ@3YE;zBcyNRiq!+2m74%BaCWx3pJmZLpgP1-FG%{sPNHz#u;*JNjH^B zBQf9e0)|J1ZMc<=n10zW`I|apV1AwXxHlv@_nn#%`!Go#6(}{b*nFuxWfF#*o?WMW z<2K4l{n>RCUhBWRS`myKq-FTj{{_=s208z9q_ICs(P4HFR-FIX+%S{uzpwzLMOv<- znGjSCw=fWAUJ9x#Ys59sMKIJ%g-+`3PgMk*F06~y*^c-?Py!I~=G83jwOHtCIJD8f z?Pty84TjiskJ)6WFMcy;4H`^FG(0)bT_qaiO#+69YBdqm8DhGU)PZO2r(Hf&|~?Wr$avq4ZBv*oc(xv-qPE zYx$=AH&kb-70rjc62SGyG0vr7DW!>rs*g)`z2*wBB}3pT!^uG8H@75dWambvFXDT( z-}WdSU0YMO`AUAe2htGYg8T4Li8aws%y}e22A})LGyplN*<9iLJ83(7U5AoMV(*h- zWog~&$!Jfb#J(itoO?2G83BfDRDZd9C3|&1b{^BU+dY|S1RTgDR>B2Gn{v_%n(ZEKU)iIH5ZP!*_iSdSA~5a1JE`!eWnj~=Bt-wWH&+n-8S3#jX27JI#2 z&uHun=YFJo{gV9axgTpNRZ$*^ndXSFmChJ(C*%WITHT@z)CXCgl&M1+Ed$?mD{J;2 z;3SSAs!(N88fNvHqrD`*4e2fc_9|)uUj-x`7}6Rl=YY)I0&j0*PWZN$zQdcFN_x5? zj>|(DW}>m%$i1mLkJFa$bD~^@&ZOk3&BkctzV~T=5w@G-E|ZWax(l~uBXQ^n1jMVs z`*uyIih*03DLK?wYyJ5NFA)dvA*R!$4{3rvU0)|hK2}Q>FUShTer^?r6USCsh57z(&c?(H9pqDW^9|xdX4XX zALM1zm2mZbvk}Oni171roNn>c3^45;TFU7~*Gd(bpRSLmB1JCA0|)N)sdahAE#Zyp ziRu|*Ra+Jcy84v?D-+U~YbfGp5z!CWH!*J`tX@-E0x9U4x3?HhNNgel6*|%cSG%aG zD9ET&rF;xhH4*F*$g{7?NKf(VWY0@GZmeEU`oQu+=*U@MXIJ7_ zwL|^hjmcJuwqSXycCtjO{qrl#G|Xa_b3beJhrkB~DUOZ{vxaU4215R>PxTo=apu>| z(PD;z&IafY9A1THAkgN0Ab6R?#{_Z>Hq0jEctJu+x8}S~azQ6|H}0M0La$^o0%(9Q z3RlFRU1YtUhHmLtwu0i^{*}r^lLIV&{U_IXyKPm|}I~1f1VgJdnDSl47 zO+gwY)Bc})>7CB5;I~dT)c02T5fmVh2{-K>o33D@|DJ>ca6nng|4G6<4ehoAkU^Wr z{}QL-6Ccy2@Os?eK-!v+_q%3Z5iiCBTK-p4|1C9pB-9LmbzXl5vb#F%>_G-v|CRp* z(!2i^NFnqT0YCIl;_@QZ_}}u8Lc)K6g4F(%E+l#f*n7@@I{E*)sxMQ4C2j3{S#I)M zkLN;@k8fU&oP8-yOE(`%2t@%8~{6**82Taj^E9O znUMN^t&(;Lq}&c9*U5v&9xG%`dh~K=0pNkotLC6C4gg6(8p6d9;jY?hCmc+G0}N2c z1hHhl;`CDqUE&~BmWz=(3XObv>BZt}G>$kI`<5qXG~NB93iwbPdhA zVb2J8UEu5-k(Q;)S^Sxc@_T=(D0pwK9yrgOF5mFzq0t4{T^W^zT*S{ zBFqG!NTeXkliueB{FFDwDoFi+NdAbVet-B7>&+!Ci{*W^1N`gc#B%z%IK;_5$BA?iGXXJhlBWAtTJn|^ z=;R~dnse$m{{n2x5E%e|2x3WU8Cm&AbMo*X%D*B7uTpp>5fFoK0Z2-h$@kL3x>e$U z@a=E{7NuF?7UfC6pZ5e<3I|WMk4Gmr`zEojC@`nVHifU5XT?@lUIOZ?BmjWJ`uva` z34WBEhR!^}qGyRd4Sn0vH*gJjpT!N}4dX1R{geO(U0VMLAQUM$WHW6@kPry_k%C;G z@|3Ls5{N5%C`c6s1TFB;lA`ZOssitW6rKVaqz&g5ivcZAYhAR!!F9V$j@{DcGC(kN zhtL9Z%py8kRVI$^kBD9LKns&oe_Bum5RR)sTrI9ZA6SZyQyqRo5(%jQI^O%EBP#(k zIlXtcY#I>3Q1y=peILn*10vG7ffnRCZ?}Qu^mdYpg#i&5wEu{(LJ-0HLIh_6LNEDw zta#i^_U9-ra3TP52nIpU?A0F`Zx9GnJuue^1gifKa03Jbf4Xt=HbIGK-_4m1fD$f$ zy2+9zQZR0Imydwcl+Xl}uuNxbzE4mh?$1COD&3-775vjp{P6@Oav4iI0VQsHZ2-V7 zGIBLQVSUe^fhZ;@!LU`$`w&n<;Lk{L0JyBTX@C0B`4WMkW^>J65FjY~r=tNg@OIAP zkCv7M0==%TamHl-EXIG7s0NgX`B53lbYDPVaB)d)P-`9pY6he|VU>CD_nzH;gDQZ3 zsU5Q>+i>Y7^Zf)!-t&s6C?KeP8vp}>+~vtK?>DZU7amuk_yHizEsITcX)PDlF|i?g zT~Uyn^%gCutC5!n6XHbtEp^ou7vBa_8fhr~W#4xMPTpHq{zM={jab3BN7Pu|=^U_^ zZEd`W`R1Eu!`Bj5zKRw)fr56wDl>ISH&3@0n=$#mykFg|`#l$??|o@r0~l(nr^8m= zLZFHSHggWqZ?Z3}SLa9B?^Rz`sO=5^(i1K$2TPzzOr)|0QNJ)X4SXC4*J7g%Qe^6) znm&l+XPy9t#&D-x-cewVwqfnH!y?hl?F*o-ubyUTWq3P?<%SypXB(6=ZYnf8di+aL z3|h{Vr4E3bfWp1WR0ZY}3S##RHgkZ{VnNmW*M1EGbX32;jpKg&wYK2&xTSc?rmq4NQ1zQueu zNrOtb0kbFen4;y3%d-Il0@5IY__yoxu67%IjHE$)08UQhO(F>a+nkknaz~t%3IHy1 zP}BnroA!#GEyvE?p(X_dQCH18N^Kwo5hij(`~tLxK!5ylFEgwS6ekU|AD`snY_0zn z2vo0fml8yPBEqkc5rcjX(_JB!(~BopnEllXm;jT|f9OeF0Ccmvz*j+#J*suHl- z^IfFOpbEgyy&SCsdP=${i5Wy#{*I%-W(_nyAObvU+@d5K{ti4g|Lg!B0dX9M>IuZZ ztbs?>|3IW|*Hi6*a?pt*;7t2#rvMA5oLe(@QwT(`NrX3`|AAVAIR0;fom&#Z@@fLW zf(3!l9Fc;Cz~eLi3()+$>Mb?B1OSo?I0?~@sOMKlWlxCLGIc|Ka;F@O^q4?u^rprYVteGpxMvtR+;zD#ig|b z%{0%pZi@&cP2(CESa2LUfDVH7f^z)twnbzy8)W-_=BV|CyAqoz$r;{G3p8ZxZd=@w zrjYH>w-M{#Bh#ZY{myI#`F-udx9kvOs^$9-AG#+QW5FXIo;TD!lJcwH@Ns4eVsaw>S^>ga(Anp!f_0*=uTZ~XMi z%U#v%FO&NLi^@<_vjm6zE_8Ys5T=8b8T+m%%XlE_mXR2*9P}4yVX_7P^96RPBd1=g zRjQi?A7$?U@avvGg_)q79B20#xRDN~X9<}lf!Ly1r%dUha%?65)8&{2PN!VJpilD@ z1z`6wv1gG*X!kxKO!L@$Zq+51n1aqv6#TN%uCoOQW^1)4c@&GVirE`OJ3>Vy%F!); z&{Jo(Am;V!)G3cW&o@72Z~h#h+AlRROOUYnG}XMD;Rl87(`7c=DK@5lDe%O!$qqog zb#`=p4}Ny+Ef*l8GjY46JrAOHD33`$WO{Cw9Oi^024%}_j^8JiHC0sKp(W9B?QBzq zVn!>Vn6WV;QWapT)<3(YmU)Yjw2N)HML)Cd^oKhO3xm28>dT->;J`!T)H|n7Jd76n zw_7@SGpA)vdT0W@J&&i}&E#s%9q+gYF(>s&ZG;;MNO>4*jZ%CRwm0?JG=lmCI+_6S z`YQ16W*YobsL_IGefnGKZUDG6TO)gcP@-ZH58TYcq0Hk%&ptf00^mr)ElNN_#MXj^ zWj#3^*}db`^ja;d?^K%I0DB&b#~xZqX5W405YTjV7$tN3*23W{;4@j)R@7keR}?M- zy>7@^k4?!GScq4{a`v%5+R?$E3TWIMsi+mnDRnwyLTDo2s0Y*3hw?y59i6Bc(KV3^8t)6aR9-rK!Xlr`g z*#y~BE=ze>F&-58D+zTfFrD(!#z1h33*vK(d2*fQFJ%FO%Y?cBtHf2n~Rp? zKKqbnX(+`eeWJA)MlEwNoEVZH27~3Iil)$Lo1KtU1A50AZ z!ok67w)pVc)W4QE3LuU+{CWE$c#}~TMAdPn-BR7dL+JC=gb`o`EG2<#JTQ+p9}H)} zXX&;?W=7%_B$&ySg=f7Uf1}~MA^xo(WMa8#WNFQ(b*4kn>$GMbAwOh&%h?QyOc+&chs4|2MoY%F~ElY`ee+M z#S@0|d2nk~F?;kuwRxbaTQc~QgNpmX49B}`RPx7iu%;&dK^Jn&brG8Z)FT;0*r3VC zgySy3-%wNW|N4R%AUgTrEZ3cNa))cC(hY0_{>8vRbN|gk`tE!sG>156rdfEaM4XRB zsyv65&Jk+zbSv&;mb*5=Dkt6aG(UVd{9FCdLATNKxJKj2_obkCi&2w? zVH}V^@N$0jdbT6FKl0$bMjm?0L8^rTTMF+_Bf=Gh#RYNk#j6veuj zz1n`gjRrFc^O-f-7OMc;)XiC7()O!Y&+qU!1+PA2z_{T6O8rb$}00p4TvtqJoa6gk#LQb-&Efcmp72Ji=d z5v*HQdrc4Z^^B3bvFv`8oCK6f?e^P7=+Q{zhMCmL=WeTz_s2ls9*XJcNnVH6yjBIE zysa@C`>2I8{BbT_PlGR`Bw%|>IB4%o0I^u*8P_crZWL?PayUu5waIyXSu?~F zHH_R@kCi~Jm(4$S=~<*^xOvGuaQc^Oi+iu*Q|&NbC!r>PbJpP||QG}pN; zo=mslvG}%Ez?P!+X=o&^p`e^~C~=P_c4$05@NUs;wS8yImu3Wtn3RS^%6;f(TYGM? zIsS)Dy4Q-~#{86XmhW*)y5IISb7*#J?i!aWdc(_qF(?7t@ z6moLckLeRge_VK?vT)DCU2E&z(Fm=wzZBqDCO#4z3vg}&Y6H8nOl}IoJ<}k)+id~L zW>@5ZuwBghLCXnY*9IK6R0undKNQp|z}5+vOu&Z_KXJ_fast3d;^{3l>I4#E&;h>E zD}UHy;naL1bHjA;wb|t$4x*17_nu{oXg69u72)=IYQIy36ib=1ljcFX=Q%A?N`bK zzj{eP?&>9Pfir&@0e_W6nce{J7{o@h>^X2TCs~Qs`o+kFcCRkeo9o?pa3N%p8m;yC z&_(g$m3wU^f4#ie>+?}4eQwGFWCu>^LfWC-I{y?mDwcvl6>%5WhF@{ty*ML)T)ti$ z+(Ey>{_Ax4{(^~|@&6DICc^)*{op2zotLg}ApwEvlGOR@fn}7w!%P$;rX9K@r3zf1 z2Z2f*|1*?vVbNS5(5o;52Vyy=du`4{%*w#*c=2k93RIs>uHbnGI7YmhHnb*|8@Sgd znEVD{YoL`h2Z~d8FWA?64!CbVE(!-w7ukD3%ZHCDU-bhQ^?P4izj2fUQfR8Q;k%0F zKn;FZAp1q5#I(+R1&EF$CWH`il-+GBzp4dH*V0fR3W9n<8?O49HOzxR{cU>3Mw|(B z6mg3(S;P-p1RP+0wyl?>ti1wt@siZH5E-!E(f{FxRQqmk!%!FNKd=pKW`a3pHSB>2 zy~?S?#NVFA&oX5OFs~R6CgK1CdO>fhi~uI!;{O6nTkF+Ujsmlp;}WqPPAAlStHg`w zsP)mH6y2rPQjB}Dix(A{D z8}sg48;}bwmbw3CeluAZWv>R*Uwr+akp%tRE)PvHyO720zj68bF+bpfOJCl=p3#~G@FPQvSDZyN< z=3M`>aZ&m!?cY4S^xQvQ@VIL8FS+Fc>#sa&>HtEHK~vgk807zXD;d!rLw7AiJ zveas;o+7Q2pvcvWxdaO0(|cX+b(D6EP-J6G$Va3m*e2Wad&@9pnsEW{V!8bT5d9V? zT@Qz@1OMM3$XkdD&~d~v!DOp`5!Gj`e-j{j-9{i%6~El-<4pqyr5|zQKf)2DywC~w zzL-wH_r=Hq-xtyY-=O7ej!98a@l=MipKAaG$mNII#sD|_4!)GA^viss*9Mva6r}n* zbgAMV1xO!;!(!Y3D&v_xZ9^d7*_2D(ZdF%DBD%*v(47u+LW_8_jph1e0nlTfq*qutqe%jXW&4iJ)z@ULJop4nxYt7|kM#5+m)3?I#UP=Su#11nFkGH@Jl zA+HXt%QBUK^dtLwK|V`Q>H#>w{ioe+Ai&w86>4q@tZb06IIxfjm8QFa2Fi_rHBTV7 zssMJP4{&EcD=Pa)gVJ{~7ZoDcO30H~(3!P8(i-PR|Sil@xSy z*S@6$bzT0~@&ZWy)5(OH1$_RWN8$fRf~a6)7_bSa$!=k1^~R!x2{&a_=IRh%p=Pzd zdY6Z%78C@|t<3HK#pIJB^H|>g>$q`1OODj>V=rmYEAHq_;F^)MZ3Q`x>X#fA*udIT zuTw9UT@5nensKCC_13t@DWI!Nrul-a2YY~R~dBYo*TX<0!&#P7w&ITP)Xh9 z+?IZe@8Yjl^z;++*!{hRQjtCcD-j6v>ytDR6qGnQG5g4Y7g$O`b2`BKNMwjkXQ3yo z)T6fm=aM=%9@0mI1ue%$Scumd)YI&lyAkR@(^oG6<>kvl3RoU4E`pUrWf3Mh$XIFX zuq7a0V|O1eEi55J%b=UAJ8uBpYDc_Si;|MLDLdg4To}#Ihe`~e?m_(#QzaxS%j=HpD1Ueu{zQQ`5TX4_v`=l=&jm#5H ze8y)VSMnP*TV|$RES(FyZYA)kykOKfHEZ095w1p%P_P5{-<|7$x%e*9))pT>iHDQH zc}6QcJ!Uhc50QA2`n9N9r>0+5!PaN#$Xe(zjtm_AZKLTZpJxH(`EjDPjXN6WM5eKzUv#jq*iY%Nd!$=~8<6X8}0Q>oHZ@yiK zPwK(c;tyFri~ZQa=)vRnwhm`wr>2mi9b_!dwY?AIWDutk+Ir4ol2L4#aKn4aM!>(a z8N%0_s_x|hJx1u0dcpkg5dt6D^j#70IIqC{aV%NqhPaTlcNQWMGB=GiI-PgH?3ypx zo{f7!(9sinUr{m4`vJ(IQSj*;wwl!_Rlr8^-O|qSjn4}q3DG%-ox^L_sKvW(d)*;r z`~HgxGz{ub1`opfY0jT04ZfoH$PhonR<@@QZrmGA9EJ7U_gZ@lhZp_2Zp___&5*#2 zWSl5UTxnMH{TEz=2aGwhf3WnCfZ zxrtevwlV}lPog#Ef~LSTznS0fNJrk%`j<&_q-Q9f^&7jxZ$qqROLJM686A)je zZNbh@s3Y^|?$+EyBYgg>6YRx9>F+ny)AqbKU`+@lE?#Zoa7u98+05}UDqlI6LoKlc zTmM}&zz#c8oxoK*>^-|hjGrA`ko^(^gcv(!aM|DY6^x2`yht?Y#{&xrMaYGeBWUo8 zy9cY&*SHbvP7B(8T64xnFZctY7Ibvx2L7Y#lK3SLW)XFzDK!Xe7{Bv#XOLP$CL9nA zzMnaN4lPOdB?l(K*UAWplptdB+HYpuu=FXUWcOSSY~6JF+hSj4`uaTNxCXHS^LRXT z*dZE=(9n1oVUEJivY#ia3tMf#e#Z!$u%bJ5z)dnYm9*AZ4+9{>Cy@fWDRiWz4`XF< zbC|6%%L@(>EM@h1IX@Fq;v53 zY_5}`-y2E3PsLAkAa<;6y35Ob=2@XKbIlm%NpBz|o`+EL!z67}seZOLX(l<0ypr(I$M|AEuk;3)hlV$h1+1zvSfIZtP%-EoHx@Dn$ zY&efK8~7?|l-&|tvvS54HePBSX4y$0Q8LZI{3;|mR$n8%99oHm_q`sV0^G15;95)H zn6T!@s^cZpgyBV*Uif)#Rr=&f?mQmrM_eWry#a4~8=o0`yx$@Q@UU0KHZ-I(hm1<^ z)9@kP_8IDY)wK>!eD6z)pl41Sp71CBdi0$&Un0NEc)ENk3FR3=-dp=ZGXQ7uc)`um z`7m_q9bkx`PV~A715ew}GAlm#p5*cPOX6WOFD0^L2Sf413$-7yFv_ z4JKP5$R5dK6Ay3i25Dt3lN_z*OQUOm*W(4Y_CKo~sw`H|Gf26A=O*f#(&rpjV$&lq zewvijo*zC?s;Paj4v$S|k21-#tQXS1O!59cow;DWxdJ^^3~(u@#?DV%U!Y(HmrLac zg)GmlhQtIPCZx0bHy(%V-&Pfwbo8(C=`BTXA5p|G?R`OT2DU4hkVOP5y>lS^3oSk} zLZ6!t|2im9cZ#C8QkFGo?Te1VpG^&CW=PMawn;&xH zb=w3Dr<`@_=UWJx6V_8TU)pu%9QUeU9XF#r&ex2}0{7MM&NVCTf|S8`88A zIRNZd41tq_GZlr7{rhX?f;S{`etdnq$6?!4@<`F5jLp~MPGXWi>@1PBc0u2F>96G; z(Yj^{{ma39ugqpqCXernehTk}AOy#ota}H`rjMqX$xJ01PR$_B)~>vfw#z4O>0Ggo z86(V#>YHv4Ka9H!SYHjKM`n~=5f$O&s2_>l1TDTyvMnn3f+`E}&00A)TkD^CLI>B( zU`zj!rY;h=gq+>T8(DMqD7|(mWg=$OWR!+O>wmHL-a%0=(Z1*y02L4r2@(|pNLF%2 zNlM%Zl5>`va}tyw0xCHR2uK=`oO6(za~N{Y8D^MyJ>%Z@>~pGKo%e3Nx^=7W>pz&8 zkN!HW?q0ptZ>?Tkv=T6Ay9}ivjfB;1Hx_Wl$hOWh3<*4Uiz>`0t25YmJK*ZFdDyJ# z%>@Qn0%%-w8l=$tY+V5%ABv1VK{s;-i#t2Q@W$MS>UGKYgk9|26F!RDZI7l|;+PH^ z#;kR(((9$mK5-Zj+z-d}xRnOSrJeo2#EB|u&OgjSy;sn^V!IUPe$gj_LeyQx@J#~_$W8!9 zuL>5hjrQP+cy1o`59>71qmDA_-5eH2;kir}-v%n@cX$+Ny)rHIIBztwe@?5Mc&7NK zIGdgKIqCHmgc(yQuGOW>E7AB7Decks&gZ)4ZD`$HP`2*#8kLzfY0PU|1W#<{*6Js8 z5ip*Drxbi}qfK~w&d!VjJTrc|qVuy^+Meh`aV_IHbaB_Kr`h+Wg8 zP>w*g5255~u$U=;+F8%??&oov9Pr;2x$H9K@lMNLU+Fx^@w2tG+;dfcJ8ZYZsFH)y z?vo24q-;hm=X*mfNKb)R&g5HN-IPsDh}toFA&-vmz|POIQxNK7!{e5m1E&XHz1aG^ zCCEpIXOM@jfyk|vxoLc|TNJ{x%I8C)NJp^ct_*jm*4dk&ss_KMnbml>7K%_yyohDi zITdw-9VUq#dR=JbI5*EoNTtLl_JyW}g_Wb;wjZ5J-u5gvyo}k5nP(i@&CrumO!F{W zo7=y{2{-kTuv-qTcVC<=itAy5&Iw5_T8Z%TpBr&_c}dlk?ymW~A|3tl1}knLc_4US z@5zf8pM}iru^!|^-cr2ov|C?xZGoUjWH4Bs&%M0zVY?PdtJ);oDv{CR#pOVMgQ!uU z_a-j3Jj7Bjj_StwCfryS~;_r)2c13NE zLmOD>;)>q{Oy^>xxd~r)+OCWGaff<)m=gg(A~m&0ia&0Su=^C0ZKOwtUw!gm#6#o& z*Xi*gqEVJsTNyRp8}4Ogp`8s5XincF#8x8(c*lM0Cgnwx?QY-9^u?$Tzum(2{C)?u zU2|dKFXv`@ZWyBD;y{`3NA4JBfaw(LBrhHFPai~bxYgNQ=xz${kg$^(AvRX&+f5ql z%5#oQ^UkLG8bc-Nb1h7ZhqIz$LzlX2yk}V;?wg^RppetCvZ35iIt!1`=wIr0uQ%Fj zJ-*>r_}#$Jc;=dmkEg|E0;=y>p-?Po7VPR zAG?yLqUf$?RA}gE$^12kDPPUug?aZ8zGDh`*Yy{FDXNrbucZago7GsXX|1a9OJ|zP zbZ+8C6cf-;ZVNr<Lc?&dB%CsqxjHOU9iFOo93^gA(h~UH zXJ&=YYVZp=Qf9yd;R@mMKZrkaJtnbGQZFb^+dvf919cuE5=%iVWgR{l()eBZNIlLR!v?@EUT1t{b3?9oy$0$d~ z7+vb5<5>Ga?`$K zEf@e7T3U$}1b=y)?r6cVAT9D`eRskB4nQ4^f8(U!0U_DHut0Q<|8p!4&01NfpMge) zrV4lE(rm4V3)JR1WC7q|hs>|R_6Vsc!;lz56fsinFtB5j82kd*Jb?SKEU7>i)%PEH zAWLZMElvyk*Vr@;AHtV)qge}$py^4d+g}sC4Ul`bLo|Z+nYr-FeOiX5FRk6(eq2mI zundXID7^yUIu;4?B4Pk;>Q(**hgn4K>c_?ak4A{9{B3|Orrl_MiN^6O?x1meN&v9y zJKr5e=l%-7!DRr;1GEnSiO0EUM>5=mVv}fpfbid4y1>?Riq&e}nJ6|rDCfYPZkuW4 ztELBD4D@6Q@@Al-z`Obtcn(#zdOo1|-;&?}3lVRc{>{0BoPNuVN3z68C5kp3Hs&Qoz%`Gdr3{Tt6NWHe5? z@dt@V>ofnOlw);0(s498+;A0aU?BYgm*1{@Q))m%)R2|*e_`l(PeKw=7>N2y)W0C= zLUXOrr2-6|AMzjLcMX!;e8ssDbndB2pDeMXVD&@;A)V3D`mp9=3tBLmu zSh_y^Dg5=nR*ooAqisS5gZ`sIIgkj!pg_K4MSJC73i17S(cvm)$$yY|hkutbt3L1= zQ-)~bzuSGj%-Fq0L5xPZW&Q=9{(h)x<^HD>g@2b)SJCNEjluKD{}Z17QvQiEruTMe z8lGE^LACh=snC-@4g9X;f#vN0>q~UTDyuCG2FTAt&mdsLQ44OI?QoE80K6tK4m7~t zQa()^3b1!APw!ALctHdlXvDuFo)Q^P23}a`z+mwaa?Tm6eybb~+V9YrZlW`>E8{ z0e@z}rHJLZL6g-vu)ffEJhNVJ`~=hj@i2gMGy z*1Mo|m4|5LK9mmc@Eb7y&UFR@s{nZEH(2%%-(|W#*&pCykb5*kaC=D<;D!PD|6wKU zF>(L42^yJ#=$?@1Bx8W`1KST7JKAgcfAA>vSTv9Nhl2qf2W%6-V6=MP0d$c+hRN>b ztZ_8s0;WrRBZ#Ox(7@2?fA3A<&pd@@I-+o;U|zp`@_wYP+mx1Avfw#*iGkLuq77Ir zzvqRq5SOYQ^3L`5hOPtL7|SQuk{<`!I|Dh2M)R(lRplcLGW& zami+_^%0Jz9jXEXVR*NX<&C~!Wp6BWZd#1Z{K_n=yFc~*KkOObMx1!O++@Vu$gjT` z9`e}gIEe@hl$2^VGJZYeQ(n81#G~t@&j}oXWFxo6Jy%UPNhhzldhV^&`;;G_i359x z_`9wcn~5r6Jiq%xlNW<2N%w$we#6giQq$XGYI4{!E2vGuxx9XK#0`z!3sOJ6#rUa< z=WTwih1KH9a1-jMcbo#~*4zd_z21YT6)vnz{;B&25SZ?e~^P7?)dB9EVJ4 zXcV>d9A$IZ_-yv4ss^@kkkOnOZ8jR|kN9iuA~K=_;w#%Ts^J2+owI;X6C9Uze0VQ) z>35x2-{o$;_O*dw^(N(k^eG-2R+@_;rPb%aGSfJfPU0eDySZ|HVa|E7;Q{w{bY=#f zePx+bYq&kk)ZCZ~Ew93%SNJ9!YE(okJm7qh@8ff}S2rKL*2Hr#9qf|gnzgjDGF9hz zxx&(Q0%iyViq=6OWEAT@t10z}1zo4Up2mo@qq+B^s>ppA_-yRqHX3D5M(CbWd%D?L z<0bK1*PKp>DWKXYX-hIzYaJu+ttXNDoYtBmjV)Fi@<|$WxDjMt`=t;|N`Wy^~Eb2Zy~QfqTNPTO%;f{fsPZ zHc$GleRKm=Vu3wWuS|CJ^mfhp=-KdYlhH&d{-zBh+fyLm-geyC-P(GEqe%GZ&9a55 z!f#1KoLR3Gg7D)oIqGNzHjA19Z#f4$#yA@5O)H=5^m>s`eheGD@X1|TM!5fW=(75% zQTjl!=`3RNVeLaQ(viZS6?AytNLUC|YY+2hfnNE-apz+MbxMIXL-%Xw+i9=@FunlJ z@jFBLHkny|wmBw;fnB6Rk(8m^KBp5lCC8yX)1t9?jJgh9>hC0;J6Qi*O`3iGp5d0C zndi^L{KkE$&TsPv!hqZPMrGX472xOR2WH#c*+qawgP5;N7pxF_^R=ycS^`%7o1pq_J zbNyL4U+tA8nRfq1TCr&ubxrF033JvxSENz9@*qC0wax5b)#EO-_|7zEW9=sPwrW}f z2d$be-X%G%7jy$_{p+-Kr){SS_`~JXry`?d3L^f-o1V~Don^vSKNiQH(xCP!j?Yp$wvAvBQMJ)B+r$R1dJ>C*(%2hi<0u&-{L#}^) zk?u)!xt9W3-OyPS&JMBF;S_vk=Ux9nPw}Z!+UaklA;VUE^Tkz-mA3wl-N;cL)P83+ z@rg@WebObz4B$J~mTqe)IxtVW+qZ#!riFU7C_7I*<8d(DFiq{jA*DcLku(Y6&C@J* zTTMe<3e3PRly%)NJS7Nb3J;-ad2Dz}AB*kxibT-Ug9NSd6c67eQ7E{b_AtM|tH5IE zO^RRiyKUYPz9dB^O77|BFr6Fv=Vcq;I_^`1o>JZGMpoK__Q9&5P{&zP?TYkwhL=Y! zI09kYNrzWl;-IGT#|kqJYWwq<0hV^$xogT}>k&irxFHF&*)lBF6|QlZu1gnLTnAnM z2LJ~_KVNVMDOUZ0b9PdMmt&iM)M+oJ_Mq3(l$M4jLD>9< z1?MeBR$=`L=b2G~A{{f09Fs1o&RJBWC}6=1UKbM_539K&yQ$bGy^cQ4XTO^o zcnp`L9mLd>P@C9`*)wE>)r`^$-e0xZ8RySGZQ8c4o%6g=(unqI53-7 zeoYH9lH=^Mq}viet57wBC_uLGzSdST)dLOg=@GKcF~;q|D92>S3)W0P$c%22#A zpVQ;y^m5?~O1Wipm?UvU`xSWbl(qYoOFU`i<<8*8R!Z7@0o%PTjEQPi5ySiGAbg4# zTWQk0B=h2oQ=WXL>Kax}WjAD~(S@WG>7}GShTBJ@MH5oO%=j_O^K(t-%K@mu<%v@$ z*N{4IJnyB}>MPE3zk_e5muwxX%}-5MseIqbYbi!Z5R+0<+oFWXLcX>~i1; zwvuB>$TW%Ops$+LUE88aksS`63`{WphD(zur>0VFXKJ76dWu;4-SNJaYyR(+qa7tC z(i*+;Mc^+yRLe5?9KYw6Y;_Quh=9weg<8BdV zdT#5g!`)=>4IHm^AkgX^&A}B=2NR(wX699uMKwA1sVFH0XNQnl@O_>@`ZR_ck_4y$ zO(&lUhsAiN+Nq+z_)*~j5Bo>A(t;Z~h=Ex2Ld{ibsBQ9ba^c*{rn8{q%12Wv^d4sB zx+@@pG#@+m$*NorDEd}po96L-F{(^Vgnvi`V2IhZC@G0$5!joE&Smt-RcN7CI17ah zym0{f3p7nu7xvX=Ti}BB+efZ!a^W2CUfC8AK6H*&4QLI0oPEfYJ&jp=UB+WKAbJ{V74sni)|Kf-?i@4s zKMfkrG+#57YVTW}^UDdJE!&iFa>%tPDp}4w^Ra~{&GRqD{bT8NSc-*@SB@1a@yddHkU?2Rc)3bKehgl1g-WvJnFQbDm*O1 z7fA0`JKeMGI~#XZQ&U$SRnv;Cz1~Mk%FQ)>MnGYWz!`Au`)#{BK5q7x+E?ij(wN9@ z)fdfa9%Z}c@w4Zt6+aL~-XF3HS5{z^S(Ppuy&;;6tVEhT<(_M&6j>rPY;WIk!sJMl zXUmUg;boHPhGNv|53j9@tLIcyRs2}^##8C%FDTHEW^~3Y8Ou}_bh)AhCDl-`zmbKe z&wHimb#=mH<%JvD6UFpsl^-Og-vFNg>3>@vVszvF7vr+*V*uy)Kf-N!D-N;UeYG3_ zJiR+0Lc~EwYXtHCz2ox#@2rgRDE^;uR^CJP&3Xm4IwiZ&)~7sm9H{=_E>`Q(@v7)? zrNl2D=TYZ{Z!38&5s!Znn-;@?D@<`PkKN18wqTh=*F}o@z56_Z}KmHD+q4v`%PTFjaOaWwv#0aPatOlZgJ%tW=;#=jJ)DV{bdH>X(+9`{fLMBYo4Qn z&@_zQHRdc6bWY+!pVgo92jf^?(&2X#eSpW8TSNYvW}3deJ{S)|m*{I%qx`q!WeMm2 zKnqSI4Xh-_0iYLhb{7Wl(GgsOv(MAxugzvN%9)emb z94kk@;oGFDN?%0}VuK!rDzSqcQ!fst-jwc}x`})i`(H$J zW1E@+W_b*)HSU8+3EpR4vqN7AIhUpUs^x5#`Q9pLi_x18=-CKCT*L4Vi_Y%HN|@g_ zXy2nhL2A(b3y7u=&-Z09$|R;yQ95}xKT9SkTB&I63bUH5Eu4+VI`5ulTH(m=x|eqn zK5Km}>)~i5TevyZJGm%v9v4LtL$MXWcc1@}xqH)|+t<|X(i_~YI@5z3>E)rN9(tO`kVv46aWWa;X`}EInX+Ut3=WRI=U-Y zLIbj3V3vaANK+*VK6ZbNEF-;7aZu4-Pv8N(YU1K0`SS;qI3jLkKYrDw=y-iAKCw5P z+1Zi-1W)y;gWkfI z*qdJmI^L5ym8PjuawQald!#maiMeyis3tCQ{mc_cGnl`oDlXEc1!Af9jG6nD)*=xo zlN7e?Y97p9bM2b;L+tRuH^M6?qt^%o_d1yhTs`hW=6IAv5q@jmXCy-D81M7y_r$(- zc|`xHVp7Zuo{{#jp4a)rPbnm*Oxqp)W+d&|S84>ylyhq569ej~=ZhAGQW@BlX?mu{ zt(9a&1iLvFP+=%*k9W1_S^BfYOEhWrOg*1~`8J#87bCBuMdJ92(`-DyIU+)%{Fch7 z{_Emov!Aa-l&r_-CM(pm{$l5Uo{>b^5*)-p!b$IRPW+J0AL`XdMIwZpD$a0s8C47< zB^q!NVAVz%$V$JWt$U2A!p<=ie9op{UD%aPI?YfVYj5n4?FfFFUf``itfFP>ToF62 zk6Y)ZO*P$3#lLbWCZ^HrV%~L2!5+nnF2Fk!P4Y8FrN7kjvMU+YC_|Ua!jgZ!yy|~# z3iZ|PrKiEt2wO?*^QX{nDTW@lvS3!58C_9@Ec=pRyR9yeiERW=^uH*H)bu<&-8Trq5{fS_%^fQ>#t_Aw$^Y0 z0)<<*gG)60f9$EIY>lt1y?vCI6gt9^Papa2m2cFa?$Z8gPO24LVb>%mw`JUNY8xT31ly2cMGZsrg0jjIss=u(R@cd$|RD~#rAu5Ld#!@{r<{7J>a%AeVl z{NssdbKP;ceisHplHTfy9V6muSZ(rn8JHdUZ_>`{aSq?rsSQnh%HS@mSFK<_IlW0f zKfE17Y~eBBajpvG4*hGuuKCSVFb;UH*y<5Q<$(~0*IFYE?a>J#;s)&}FiJcO#u$63wZ{#MH2M3v%HZsw(h9wFy|J>%#YKq)F%5KJ&=doeTqRz0PI%Dt{ zKN|_Y`OyCwb8nj;6IKG-(pGM9`BLLeG1FPT4Sz!G*${B;(_qX?=Oh;|aIG;={?y)LXX{+(~cC)b-^6=oP7zBsC(h#;kn0c+3 zD(%?azaEY7I$#-~0mP?GEu@;D2XiNW2v*huUCO4Pw5DO<>6xkq{ECrShPq35f8Y$)8lz_Cd1!Lm8^s zx8Zm2PGDu-f0;;fR`OM|Qr6}3j_yySRm=uHQckbV^NjSpE_d#A+6_ntq0UL%CY z#6bE^p!ly$n8}EK{GY_b3m~=ozJG<)Dz3Y?vGZ}z($C34ako3S1_y-)Yu5*NncZORxf1wi2z+0J zwPIKT3_K-c@w?AFOdc%{Uh5q%(akAgW>pF%4CnV zjzV6rJx@MAf%S5^dN7-bjiq?+NcADkD#uXnHScA~YmN3#fC#P>IS?C5v$U;YkNbNPRR*i|Lg&5DvVQJiiMX#MtD6uJy{jqNX&sy8RVU+c8Y!n$=VTNW zZ($gZL^k8EQW;3AArEO`&juoH2C`0|RtR*3V?~TQ`jDF(5#2MozKdrZ>ugrpV+L`1 zJ-VJwP8Ay`H)@^{gdwPXW;Bh>vU9epq${R2t!(yc$t`S5T^ke)3bIQr((MlgszoBI z>|F`CW#$;oKfJf#eT-Rsuyh%h0+fS_;#;qt^UK}Zit3y`+(*=8vtCSx2DS2WBBp)> z%hq0k1XbR!03otO4RxhaXdI#E@l@Et;%?39zD4!HhI?t9H|p_4@@%istBo0^Z!FSN zY&!_}v(66#On(!!A?96mk2NQbUO>;z*5)x+;_qoiYX+IlPgudicW<2T3$ArG)0&K! zE9wu$v{JdSDB2B8b*mXt${u1 zJ2f3E(%F-Xhw470CKkKXrzf(SUq0Sv<)I)3;-xMZEI9eAZ z$MPUBnkxPI05?XyZq)w;&kBj_kK}S6pJ3tN#2ndlnb3Hm9C4mx5c%fwD{>(zTKzfx z_4W08_wLQopee`xd*B!TOj?r?t=C52>Dwv)X0bdks>d4}=_yne{fxFNY3sj)Ni|RA z1<98^if<)qC=V|g6Kj^9IYlq&IJ-Y`-|Ev%V>{@U#qNm}c;;zi62)QDH^7vlzV6e= zFW8cW9LG8%WF$j(D}0fYQYb5Lp6K$+qm6IZaKbs?k?_A;{>-lXdFsN1#&IN0%q@VF z>k${%$m9n6__3R+plZmZLcO@|Qg$33O$tAkTCj6+hp?tt6ubK;3jOaa82#T@SmJ$Q z3db$(43urN8#O;_z8z&~r?x)O!&Xx)viT;I!*;C}cHSm(``s?rF^E!or3KFflr?>NuF8~pdw)b38)>ul7vU|p4 zszi(3%1mHA0=n4|y`SPW-;wcbjHN-{&b@Dwc6-XFtYpySR)}0OpU;E{G?}0I=ZO0h zrROSTv)4me>%KxwDAfA*0-MNwEmmqMmJ|{>52bF${j~9j^NHQYR%=SV*XSDMN~eyS z_tc4hb$F71s+RW5qXz@Q5vDz;KrRRRfCOu`gHW4CZpM@SHR-1Ou^m%1GSipU+cV?r z%6q?`KFv(ZN-D!8>*ZhVr5hIuFPw)^Gj^KE$`Tx$Fo5y)ec^Xiza%pW-;^yf^19a% zt7W(SVHHK&i#H#e zlScS+pQBFdcWrue2YNPZ-#F@TR)yfmPoG54t9*8PSh;O!XzLPC{X)P(A-Si1?f1pH zE&<7Se2nJXZ`FtCHJ5>XKDz=b39y5yfn$2^y8T?IcH9K$<;xstdl#GEQz>p22@0P2 z#x?5~k6~w$c&1kR?Hu>mS*+wcq1KkLdna7InAc__!YC$m1lJpGO zSTsNa*$ay1jlHU`m66M~eZJV3{!!HY3;Imfb@-WvAJW z?Lb^8Z%Hlhp$l7h{9eJ~;xvBG7QG8CqwOcR@otjz9&16En|`ydcU?x|i;$lUOHUmJ zpF9?SCASm&P_q~px1i6F<>}$r=kudV4(FN3Vmq6O9*YGHiQo(A(f8MmHCpZp*vum+ zJH=;)L)>ghNuns}I`8n*@GU3@zteR!ag^AuRPZ?|U*ytYekwy#Zxf$um47SDDoK;V zSiQjNP4wQ<$71@h;OApYDdW*^|5_d{H3hd%taQ{@j3iARIu$;1G!3ZcdK-l^dls%> zVc~bjr0<>p`gM*I@RONA%}=6ee6aAF}Wi-wa%0-Mb@n z2t}PPOBniTf1SwjC_DJUVu~YL>w*%1? z=!UN${;?N<7(>BwmR5=uMwmpZ;m1Bc>#yEzQU+)LELqMjSfa`w2}`7g_sx33&!S&R zs_u+Cl_`eAE~-v*PUcT8Ikyijy7l9ejNE21ptwWi;H1pRZoXB)5Xh2yPTBY?o4Bo{ zH!{@1rYBy|W&4yy%eIuKwNsNv_%xrVkIM``Ar#08)mW6Qnnkwt*WTN?on9s{S9iHC zHS{LIP-PM6Z{xX2fD@8bwehhr-SoHrWuv)i>_$M<~4*TPKSxHvTb^+1s*l}^=B$v8?I+!-#^n6&JB zyEHN1-U*<1kbV$$d@c5={=lV(+tJFhl4K|?pQWt5YhS!%EZwU2B2!2~+jlyHPswgm zwGr1MgLq|5shAzBO3AeyI2~+4RiX!&R@Q#D@zITYyE9PFNC!}tNQi{2lR!}OpY}t5vxowo%TPk(uP3^>) zDbg)4%qG1ZOmxA)Lp2e2BQ6N)T~9{<;=*iKY?DBfC*GoNzu`H9Z&OgM=~T{x$JKId z@!WiK)8lC83Yc$7nE57Z1LhksqifUZZZg#fT=?ge2dP%9?^X1N-bD1!(N*!H>}v($ zen2N`Hwps3v#8`GGXy|%Y{YT^k$RPf`tpLQ_Q8EADfnVB8?Q;r(G{v7VuV=iYk^?JKQ zWu^yTOr2TfF`a=+#mMTt3L=2xejH5&fl|R(&t;CT_O&#c#oSV$diEoHCnO`yu&DL_njw~^hHFT?%>&%26PoF& z)hd**kbC85{)1Qp!*p3_Wlm1^bAFGUiOIzGu(K8SlD94%&9?a}r4cIEtW(3;`%9yf zo9s*5-uI%JfvD8v-8Y0d%}kLKgId>3$&&&+dK5aR65J-U-!2VDDNVyGvaImspj=o1 z*wsQgvFhb=u-GK^g6&n2S#8fv>fq4!+go{@;<937tce3Sw45{XIL5aND?Z6v$yL>+ zsTHgZ;GG6^82kzv7jM}y^YRy)QA_qZ8-GtsW`7{Vs;V+JJY^;C!kuHiHX4v>#hpM( z^h+b3h8hb2bd@>MF?GuXEwv!D<-#}Dx+X1*nOw&x*T$@FQ|*Nj($>Sb;8KSh1uEB= zGP+H2)hDQvbF!RS$|xxVp!xaF#Q}(;R{v<3{4;>+t<55EaWBy(7~hjGSj|(P{hHon z1qIzw2qM^JBq~elMU=D)1j$!uMqlxPx4nooXyi;bu6?JG~q z$U6g}fiTyTz=RMh4Xn1%dgJp%tn7!9kHsafXZwYF!~1-?4lRjw!9vy6)|mJyq5R76 z`Y#&yAUT}1vgqQe(E$vo;HP(Xt36{zsxyf$?J9jnrX$H?Zj)_c4HJg0HNGyT=`iEB zEo<{)vV5v|+rRmeOcQu^swkuQs7}HrZ^cGfzoxuAtzY51H&Ts4z7Ew6xuqG)-E+-l zy!vbPp`Nt#XD*q#W`-W7!RM1acjjsOZ2Nd|!4B@!GqN;HL`tOXw3cu6n42YYtx^Fw z2OJPsh88ABbeDGm^zT-Dvrw{>PC<}d@di5P8egx=z*w2p)DyaQ@80Rq;6U`|7GtmK z5e|{imnW-nTWh#FEM!y4*P(XcG5AD^Ux#dx?+m*&WLt#W2y5j=86PafbLaRjMN@>U(FvK>2Mn|KnadNu`K~_u0RTyj%qR9J5Z$ zRobnut?MTwB6+qPz1}F@qOSc`-;C%PedcG}cgF#tlhb}1)>%#3eLp-X0~F&Nezg%k zlXw)mRdhkU20^RtW_7TC!L8k5;1fz=SZJMXM<@Zb#bbe|I7iTOM@;!Lk zn)blTh+JtG0+L7g-n$;^?yl^yTVwsk?R1 z9U>*mg+kFN%>wGxlllmu^$;bxYb`o<&pa*#cIzDw(k{gF@+L*bxelhy{iUm6E0lDM zW=B7t{cvA*b<#}}?N+OUM~ zq-~5b!0OtHK)^`Sj6oSRjq=pr9(F z(ScCzo1)QWF3#op%UqQEm;pYaRD_s}S*O*hY=@i2YTORzogJemS!$ZeBg+A)77B@i z`eSKVpC|w|Xu01It+wky9s&bXL*G+l>bR=8`KSJ&7L&59ZD_YcCqo6hlP^H z_H_Ujb>(>f08=S2Nc?=jLCPF_)KH45O~g?oI$ZheIjKMv8SAm4L2w@6ULx}qv@_2t9B z@PrbBWw~5>$ujBAyu}^FWM3M0-9^W*#hBd9(x;ECmul`gh*Z1xekd$Do={(v=XNrU zqV8RC;)k(2ZX+*EH%fnge-@G%Fu-wDD6?c#LFhO#r~(O?EDOu_zQy9gf*|i5$n3}+ z`_lUxS0_gXPoDF(r9_FBY3%wSxz>T20yc z$a`W4RqFf(^|pu07nxJxvd1lofkpUCqN%O56Ox zYxy@ECkJ0KI@Lin{5TlMW6I-^0%VeL;#0j_T0Xry+w*7XP;NZ-+;LIA?;@oi^nh-*W9Y35?DLXvKhquBZoo-+kQsCO!-J5R?1BzI1d0x3!vx_%_A zgmIq2K2_ggcXFB>zMqklK`A1vGt}%+mfBu5&hFUr)x|l6GVLWj3+i(p;=z?`;QkfB zq`sh;RDoyCc(O~|e(7?-a2j#7rK-DK2*9eIYnnX`ap-f+6s>0e!@O3`_jb7!RlOQ<4F8&(un zeL1hoa+5Zy|G0K-P7!FFSDHt?4}3%grLBfU+JQC>_Z?tV9o$R zsTzYlL&SP9(3}v^Vivx=#wLG({OwdiYXbVe6jKB4Qu29yCe zU0_U?AXXkY^##OF;6nhJldJ8{2?AGgu<&MrXARV77SS;F)d7?U6h2@k@Evn~l!0!^ z4NMsoe{6A_=!UqjpRfs`9W2NZTGjEYx?Uqw*ItaFTQ49Ot3c#*#Ww|PtluAsbNmDO z!X*B*E*XtE>&)#Np<9O_1tsr%x4Zr?)L8gaA}+*tHXS_lZoX~$9eCmRB1fg-?kbW& z&K>}&O=D2zrXAx349Z*=1oA@^Qq2iOMf6lTd_luS>o*4)1)Of$V*c*1m<+bPX5G!lM-L->HBg4GOlhS1>n)2!`;w&S7x%x{v5a z3BP2(YfuXE$KeEnutt9wEed+t@V)&RmS{N9t!ryS3v=(o&`|anA(}`R8k>K`YLSbU zm&^iv1_QtM(_Zj-0FwH?_-uH~ch(|l@eA%XTd4#uEW15l6Eyq`fy5vC^hQNTkEVbl z0}U<}gNfi;71*({O#dO8=S;>z&XOrn2I8cGH_%;8Ih1xH0i?l`29w@Z1&F?DY{kf6=TAW2x)H_MrEG#( z=yFLlsdN>)*^i8j<0np*qRYWO8gjzlmA=XIfFFSC zX#kCUg@;!b9d)zhdAtMYH<}v2aF>8rL4Rn_6ZkS!MC4_Jn|=dWT2&u06WiS%km};o z=3#NUL1uK{p13x-C@3=wQ2*}ZiQ&G+z|A8{D`^dL!Q6B2~@1QgO1m%~a5!9km-J?P-zAWc0t zu(J6-d{O-$u1|ZBX`kD;Vf#G_2UBHMoBI}M*D~(geRkAJ*4-sefs~2JvqE)KbsFlc7qC zr4gsX)9bgWEl9WG2gaN?GE_ASb&d;qkeNaE`WLtd??ZrAAiK#sUj6WjFH)RgT8jI3 zf-*3m@jx$UvE3pJKZTo7<9N6{f?%@((;HaaYlPtDARkGFEp;&5-H#wXD^+7u9xn?X z0t?zxV6>wEdcH8I;6Cv0a{aV_d zx?#O1VYuv7#)QiniSQ-XH;HKXQS%_pJ+mn;j8d zEk{dS_66lqU=5~#rH^qH^To-?${GS!P0nd+HR3}mh_oO2mQ_5bfJ`n=3LUg_@C<-8 z$uGq;k8By4hFrY2P;I77!@iDQlD@((h`|Ri9S1>)(4W3YNha{1<|BF;HyoM){sBID z20-Z`^~2KEDo4Ah(#=uHe=0QWN?J|Ur*sdNbTEzN;cYAmNo zU>c11Ty;35KspXggWqv6S(9UulZBrNO@NGGe!N#aYP=vzaodp+>0#um5h8VLVwgEe zhg~9KY--C=6Ls%;QvPwWf*h4A-TRpJ$p5+i5nH-tvx^VhIqX5^?*yNNd=Gl3dg)%f zou~rD@{lx3G*ODrNf*;%R8Wwj*IFx&E=ecvI~y%JEMX4r_K{I+4|B)QHzv3 zQHoFSXwgy(NNYAnL~V2W<5Xq2;Z}0D3D{<$;p>@Q@+>R!#j3rx-y~}q(&G*+OC|dp znZmr!Mv_RZh`~ujO>G#W-z_6EVEB-q(Q&rvW5<($lMqUdz9BjCIoA z>y|jHRH#3dLA3OFJ4a5Wn@d1McXN z2)`TIe%&Y?$z|Ur(tU4!!bRYQS^$gsS0fdJyVO$=a*yy*B+yg=Qj<@5I6F3x#mh+o zniQXm7as$$-75BaolO+v^GS`VxlQ$RCF^O_4FhopqGCEJ_|0)r{gi0Ek4#;ZN3q3Q zJ`yv|ylQ2OPdqShlrXhAnH7Y0Kbx^E!8;;Ad&@!u!-c^ZoRKKm{%Bv+Ba+fT8E^*x zHJ`P;Wx`aXn^EXCYYRgM+inTvho`*U0lXCtGe7)N3WyVT92qD+Pu^j~cfEl^pWp}E znU#V20Y&B5RC5+6gkLF26UIsHc2Ul*-(+crdUAilnHcr7@t;OCySUH>WLH1d+mk zmETN#&lkIMr@bfX*Fo>Sbh-ps%;6x^G$?1i%E(crH4_WR2GHu@@Vhsz-aQ_`sx z{)^0A!CHGG-|7&n9u-gLF*ptZRVNcO)QXe&!LwfvvlP@%CftSsvAGMns6@Qq{Orts zCVkKsvp#T>TJHXw#Q$IqbuVU*(005%rLvl18^lgVB2#Z}Edk>v1xv)*QQg_~kt#~R zPukoz8=G$GrIIthYNr(XD(R0eB3l?HijhW9+97=U^EqFIY7wvsd)sCd!cM_D$y&$7 zZ9iC!QelVBVN6L^jRRU-GMuccY#GF0(Rp^Ahw{XHn?cCkbLx;5iuzuN+_<$V!$u3A z^C!l^tvi6Z^n|Umf9Je)irCo4H{A$biQ&WL7CeUIQwwQgv7RAM>p1(k3{So#(W2HX zFUfK~N1vC*kfk7uhO%qvZ7#zDN9AvAI5BT9%p#Gr-YIWw^HV;iKR<0kPKU%LgnO=d zpj<7?3-3H5&^-ItmvXkQdk}9)Qmr%o+~Z(7Ta`m!JK^wzmIDnMJ}U6u%FMMZ)C{q5 zQ)tzM!7pjUw7{X=qWrQ7cKBk`qULFz>sei(jlyjeIs@r@F-8-A8M;L4R4qkbPvbee z&n<(V_BQ-cRqTwD-vr!LNw#J5k+tsX|5O@SuNtQ$t%M{w&{L= zQ-8kw_08B6RTRI^{Qt$wcNnyY(v2{5 zH_{DCcMLJ~(9I0Zx8Z%?-#KTk@BI0Fd$Cxv_RQY<*-zfjeO>o;?;bzP-5zSsr_SO~ zQA6ou+i55L`ITDob6qB9P+3tu&rDMBIUe#RoM6rkuwB3}u9rP5z;A$@*cbIad6$tY z9`{HMd36k5q|?^erj{Phzg*%Mo%Bv^a9VxBWpLD!-aCbpSmWN`EJhfrM?Of5oRqf} z&|H74@J2~ZK4jZ2H_NFh+fVP}a-EsGH*SBcYU{YS(Y7mRyzets0-Ehf1Sz7q)X7P_ z;2Ajc888Id!nXQMuYr%gQb2-+$Ej{P3ppE(vj0uU_#YQwVAO-q%*SbA`Uin7 z8P8clQ6FjNWK84Xejf{av;syH^G-8CWuqoZ^t8QO-Y2ca@uY8|b&4RLsw$n#q$LzJE*hhT zylnjdBP4}&U#zz0D`t_J$Tl3&HXcRo5%ro(;o8;~F~Q6<&Se(^w7mi{SO46Ph@=3V z@_j$v@o&_A@@`97z8(fQbN!3EEvt{voB8#A{-oUE@{O2OV0Zy|K+;R2m4V8VbhpF& zj2u$>G|Im1XxOg#FZxMt zYfy}bpXL4_vS1CD0jDK!Byw!GYdT#3qW4l2fjEhA&Y1IO1!-&~)gMpxxfzIb8W_)7 zMyGyjNU(d)(S~D10_4^(U7-(%A6Lz^7!pVY&O6XitGbgc$GQBMCtzx6g48zk= z(}heI*yEm-2*lqnIR&o!o+y2z5eN9jXb9lkBCWoi*jn%qB8=t0EVwpy8OK z9Tw(tG4bNOus?qmbAE=R!k4T%KUvGJ6UtH@`moa3TPcv8^%Ax`Gj*2ZMu^z7XM(0%gbn z;f|2ou$K~BS{{M7eW5}K4teF_igB3Uk!|qzz?bhsl^j)M3!V)%<0v~|X~};LR@*5u zCBGn3V99G&ah*C5bh7?ivL(5nH14Hz_f?jUSM$5Fz(P(|ixF@dHDij`>7W@zQ_4su zsUcb#`+1R@)!&~!XD|CzQyj8&p?AM&q1$UC3RUD>U?nvroA$sMH!CTDUESHSMJ`mz}}7;8Lft`7-x~XrBf|fH!+?bz4b}oyGMu@g&IW z|RmF^^apGxG3om>0B5r!OA&oso%f#NI)v? zwwT!MDZ>t-v^8e96)M|HWc&K#>v77jGutdX zmG@$UzRpKnzmTXoJZIlkJV*x$?Mdann3l~g+5bcMLLOKd0yk?DeQY{%ZRwpI0|2Ab z*PDx5*e!H=V@pAQS0Or@09Ov652Gp#DVz_cOLn|J*1R9z?(fN^;LRRx9i8 ztX8-e11{R@PY)vns82wax?&i;AqG(87W7+BNWC7n! znH*aE4G9??YkEC?vEQbOOwS16qp7K>90RZ?;%&J_;$K(SaV6yEn{j0QE06^Fw(>%x z)3YjI>wNoOBjD-40nFZ2pRrvgHAge$sL>idjl6}-*_Zt4L8~3O*v`olweTKhL%H}8 zM^k-TJVkzzNaY%Lt>^6>F0nn?yRlsK;Et$LMZIl_yb%6|%LBb_0i|s&KgRxg6wlS+ zu&vNV7h$s3S&p8lKmk8>Y(h@cu>lbSFlXH*EBbu`;l;r;qTOxaq$GT64ti45X;28O zi%27HRt8^|R*1?Qy9b4&jabdPAz;EwI?d#hL=V#WeKYd15hiLlr? z{@!st4bK7l-@ImmIgQMv!3U)D;F?2YU6rW_T{8!`FJ;b;wY)5e1ZX)OY9?7uV+s)m<*&pA4AH z_w0(K5-s0C(iatI$&>d3;W%SE>=RQ$6PcS z`!!y+q(dQHc`!VMPe#$~VMnhm7noiZ7yMpBjQ5pp(KfjJdLNSQYk+GbwVAH<$pmU2 zt^tJ{^lNW-%C&SYxlbX+Mn>9|#G#u`K*DaY<-7eq>0>(`x{f7j@H-7!`AR6xCngGM zN!5_6^Q>XDLKwCoXD{O7v`AF&qqV=|@)+T)@W?OmyRw>gR|VXrN`!QZK_NIm zI)lZ7?=)qO2usJ9BZ5uO6pgaPW9@K-Z)E-hVoqXm}CW(wq@Zlx_q&{ zo=uKFwap(ijuvD5&P!iBpon?3MQH>Fl1&5FJ>IvS5KJhE;^`5V$-AWMj zkT6Wo$XSA-XT9i;G(%o6=2yFE*qh~juwyn_7_EM*ljN1!B;fu#f!fjI?_(P3f^@|Y zyOZI@&2Jh>`l4Ph^DGd6g+&N+DIS|he@CXh4S&pxzixSqOxA>}5d77_d`MRm*oICXZh zSsX9hq7E3z3Aml?9^C;Y|4dH)pPiH#i}`-53)22FDy*M(?KBO`w$7#L$eJY9eoDAX zL)7hZrj)=&AS*4pH|`Q~f;Flsqi~=ahQHSqS0-Sx(%Z^uHJem1Z@!_TVMsQ+H}M5t zV_pW6ix=cEbeJbGYmVFeOwt;F>CUNRc1FuG(4@peUhNVogg41N&HZrdcE_kq} zo_rE8n5@L#YZN_96lk)V*z{M2XNne2mwRieMq%G0d9}A<>#3LQVcI!q zIrG8Qrr!gldGX;cgM7or&p2)==s1<9h1eJgz++u-aLK0{R7|7fLMQX$I$t=c<=6;T zY#rg}T)BIE`+LzI9GD&G2WvcW>bw&1N$as0N$j5W!zU%6w?P}8n0-KNhZ@f-)*RCzBX8rUQiJ1#z*!SbJF?L8lD&{5m zn|ZM;8SRf#3ns&KTXANs<1uQ^%D;2l2f%4PbY>jykJ?O}x*qd!998;g2pg?e67tjZ z|IOq1+`1qUmh9G@mJq{G{qvQU1ZU#IlfecYv%ybE?Rh&p`R!j(*G#xILVkF!5}fG615Bvguu-^dbShLV*Y>ty{-bC%sg z2M><5>t1Y3Njzz8sK@45AsHK)lzlTlAG9bTqss+bD~-Hg7PuPkMcY`Nr^-t5!s3K% zoT1|K7~az1h3*EDf;nW5%sQ@*61wzXw1m4Z&l+l}2NYhO6EdVs>~A-Jk;IW=iGR-Y z+3drSZI zM_w&PBIiy-1x$QtIYw{08K&pHMo*++M|-eIs#Ch{N81o-7UMf2+4$2NmM))I48cXp zUM&W=`7?WapYCkOl27=+_$YFvgDtnle#EB#d6*{4&ztOaQqs81Ms~1Da!lqXtOTuw59Dyd z5~6;*pzA>#JxO(r)MlR0QS_{=EJS>`6+O2Uczp7{l@Z&;89bLSa?l-dq6Y05%jV4~ zBfT3EI6)!pLbgKNps2I<((kUMtTa^;DJA0cu-_uDi=|6cRYwakF<^}IjUXtQRMbjW zS^a|td<6ZukxDRXk;U(WfkgyrW@tURYK!1?IeR0UkFCb!NsYfC`?F7C5|V^E(UCvQ z(Ls*@9EYn3FmM|>lN-HS>1#=Ojn9WNM24?M6Uz@P6;jUkw3XI=%0i-Le+$$h@0sEd z$WxKb>cJ?f98W5R<481>_1CS-!Y?=oIzT{hGpN_m%ewirOcKeOTWIZ&7nF9e;Xn{d zA$XvtBpJF{j9X-rUA-FvB=>F@S{)g$N7t84mPz(|Wk-mvKrH3dq9ZMdmuv{>YpQH#h6K>T8HD((JI?1Q z?^(Rm&S(4UJVU6)D{F85Q?=iM$9K>`g~Uu(D7n6@Z`P85V~6>V+l9>ZmDx_i;-X-8 z-IX3j`Diweo~#-}?84}bV?kiiAO5=OA@T7bR7+i7Okd-e=swd!8fRuozGts-p3A*; zPn`Hp4cXQy47cLVbCDIs9CW@bWs@#_9`=%A?ZA5($jl?)up)x`BWc#)khIZYJyz=R zNQ{{X#1U}qp1eagQwi%t*jBC>`09gux^%A4byfe1mY0XK)%3iwHn8+H;um3W1;ZqXa^vtSWA|vtSifks6?UvE*P`0=Xj4+GIT&1! zC~~G1u3npODa#;hZ>EM@WkW9i6wcJ@h$RoGrPx}$QYk%x(QYFV3k}Bd=0#=ev>yBy zsivzy)-upjFxcG4H)9SAcmpc1=m5|toXkGqhTK2COjL%UW9+?vHt)(b4iARgy zOf&yXS2G)|1iE1g6OC~X^?fg|L!b>41y8my^5c4e0#VF8G(RZ}m1fbw(UoI;#^u%9 zb4C5nMPD#ic2*A$+n@jR>g;!|@&3g&_J_HI`#q_J!^>oIb4#u|r|-A!w19h;YjL3- z6--Lz?#jxa|2i~O7Y@brT4G9g0+6^Bq8^#4z%)u?7}keR$nB;XlAxt2NNl`iA$);k zU%W8!+T)Aq%0p1b$R(p|h zUt-iOtlJRSYkm3^#w9^^5V_%f9JX;=IJhAWJY0q)d=D>>S&&g+zzDP?2 zScCB1Tfk?*pf!EOQ*<((|L2oevTc&c$vSO+?5iBs{t9S8a>K5s9!%f*m5{$`blqRp zhKVQGA%Vhd2Rvn&av!MW2WNA=u+|g?Sxtha6EP7c-8)jj>+zm)ad6dMb$2c3IIb&! zni?eF_;%B)pD8KwpRUQ4z6yZ=Oag2+pX8K@hO<|-kCDY{H78|zdKur z zV|n&6pB2ygW2N4ox1osoioQZy2c@#IfQ*RGQulFp1Pu~e3`;p=tyEm4R{d!CAW35Q zR_^=25;Pc0s9i*5C#?k5Qn^m44KI519Ay9Qp@sj zvg(>>oFw8$0z$Oq%z1wupJnlCy>-{k54ni9=_2^Sm-%BeFnRRx^-Vb|MJVn=&8Jt$t;8}+r z>Z@i5;Z;r_#e_Onxd9{&pjqz!PqTCg+jj4DhPkvg1M$-@ZP!qxkJ321oX$3%rf#N| zfO)BxU_OT;4J@c!~Ejon8dnN)6# zvBI6{&J9Y=g6l+_P4qapU0(Rkz^D5_3_91W8>^-k#7JAoSth?e#-w~|N^&S~!L&nN z5X%^zpSBvCRn;zpZyPm^KE3bDo%`$8ui{@q1MsF-i%w&-9KvN~xvA~D{bE36lZUKQ z+|sY((U6sLdg(t9RZyTCRQ-GBi(P{~hBNq-=~4xKH;36^G^0Qh+GZ|#QTxc^id&es zW(urpw(NlIBBX>`F9Y(QfYf?4s&)broN4SV3zU_I!UM*760EAz0(=c5ZaRe@5UanK z#LUW)d!TKe$Ub=>QvffERjaB{X|UhzE!u`Sj7_N}=A}g(jQPh2c73g=TH1_0Pofp^ z*xuZZ@2W?I=(0?sLoxhU1)0D!zLJR5@$>xrJmG@sk{T9Stl7#ML!J%yoHctJAdfx|PZ%Z?u9f$9#5N-`*E zdCK~FSw6N7WaQuOp1o_VY((2L_BD?%! zZY!=7@oawOndlw7+Lq7zZ<+t}_Y)qz?(mcKVgJ2iv}p-yg$?WBLXBJf@jubr=Loy5 zh-93&-KN8yuZ1|e*5&2=q`dsmkZBtBF5-I24qnk@9GH=cefZ^N6~wF3DL28y(hYp}2|BHZV9ew3PaN+c96Jp&ot8N>t4DQfTC@{Ls- zin*{FOw2QCwHi8VP>(B6aCm{b(r-V~>kr0N8pMqNvw2l|ahaLsyB_AYZ$uawaxArU znTBb_*Dn2xQbRtXO;hfP+}^3V1=^(}DfOJ)C;18ZX1cQJXeWi|hTqJo&ePfit!?6g} z_h)rlzQ6w>y{f*ZprASLt(Ad=!85Y1&rx2zo0KmSrl>UAsGV~y7=4Q@1v89f5^m@tPaldUW}eTqoAB(AACZ@cR(U~N8c*d z?vAg)GVIBx8)+CaraX4T&+KVo*w#6NK{+v6ev<$V@k#v91`ZohgrSE0kr_9ycCD%sqbOk`=ApP>x&xB1}^M}Na*+euD;zv1KzZLJ^O$6*n zknc|}UeT?4)sO)=IVaPjdtA4f9uj~@u1Oikdfwib*Hc{BZIExshfeIKomVAy=>Fki zHN9hHV?vSE{~S@Nm2}2x3agQ0etaLB?B?5lpZe_ay*a(M=H?rA05Gi%0S&y2LSef< zUL;5bxH!)U2rPjK8j#(%<~ua4LYeU9x`?o`A^$xB9`+IBMCkX|?-rgE=HQ;)$K4xF z->&HObSY7`EkIDs<@;&XuJ9>vr|8#&z^$%lZ<${C+Be&PNz}os7k>ZB@7MUba^r_wY3^{oS#r1(6e8^V@)fF7(Dqzw!V3UR|$= zz=XSMjB|MXB?z=AXYi)FsF?t`%;29IQ2X%VgZc-W|JJP=^%Y=Ydig&K!@sozTnv8% z@B^=p|M!PLZyFxd^zORpL7%P{CeWPEe=EhmR2;6M8@uxtu+RYwP5Y17;y1bfPab;* z&Y0{99uNa@ty@hLKN}G9P5D<#KtdBR98w=IUH6Hn51-w?H&9flbZ2lk_J%n-=hLtj z4s@Bj?oR>LCe#qyD|*rAPw8%P39693s%bzcasTn_1pRM)rRnI;wc^)d?#9vp34R1_ z*saW)KB14-)!&~5WK-v|bPD^Tv@ZsTaA~WCIozEw{d~>(Qo>MzK_DH^EJ+Fxf@yqv zmw(L}xPrkO0kc1#^)9)zCXHgVT!Ehpx14Z0yuVCSuPS`g8`-->&XB14nE-fbNMY$+`-h-K?Qx4A?uD%L zwMSopK;HC&$iSb_Ph7r4tq&O0f&NoZ2N32K^nLcWnr@cR`=C4O-rgcUO1J%RL_n>< z5i%bEy6-74xb=nT2+&36=bp&WA!Qsa@&LdTStA2*>{Xz>4+B1sHyuN%gk-KI(&)ZH ze%}Jc0K=UF?!hF(fv4ZI;avz^4ncBcsFOFnnuiR|Jarjn1JC_VplrIon`C+Xl!XZ> zPR#hlX_Pj3llti5IS|HTurO895D65#DYi3+0I01$#H+VJ&CQs54KUNC!hx@ZQ@8Ha zN{cRoacORyoSfXfdl&d$)Lqu_`>PuY^bKDJRZh9I{g!#o7T|Ql0mVPA`@;4Hsf}E| zC4QJKx}3Z((A3Ar4XZy14tVu|KkS+DnSP6w6hN{~f|b}nf1rlLx>m9k^svsglSW`p7-T@%I;yWmBQ9$brKq7k=w4YRTbcB~s3=9mXcF%#~&jRf3W`CsA zn)XsOh5|w)ROfZ1pkc(^OdYQdGntaM@&-<}OCzgV$y_ykc z3;CaD2tG&J6ii|YycoOktBF`id&{z4hhZDtNEiZ_kVj3cK(?o}Ml##uiy5nkmboZz z5{_@XH%#wV#wc;N_tbD24p6SI4{}LOeriZDynPUuYczjf2?wN%7tUl{y_%XE>>`bD z(Yk%Nh5U3!OMPgB5-uaIv$yVSR*Cc zXxW@Tr$14b4H}B7&;6}999$`+T&hqrn@B<~F7N+Db~>Jz zly;s%2uOdPBD%l@;+tg=#8#KO0-wi8&KopLpELNe4A$8Au!qvkaeC_CL^gnK_f3_e zwC7>VB#fFb_+yT-nT=`-?>iEYKYk`8;h#@E9JbUb&%G8u_a$ zm`^@MjZaTVzA@1{iI%5fatNAGj27nQge(owm)B;O?)sIP5%N}42J&)%?JQOfAv_CU zjxzk@h@%R?IDIV2)8V-WUmnfU6>-^qEoM~FO&48!n4K=ZHW>omY_JqIDa{i98h}or zuynCFisSE+#*Fi;)av;EC8ebiWo6z#^yL4oYzVo$S0gZss0ruqmd1>Ys=Z1iDCv-7 z(2Wu}LLYuL_c1}W+DAJ5UE>GXmv5$q8p}PGN24>7=>2S!qsb~?%`j*w8h7OaFD(5X zr`nhuYhnTycDWxM)m>-8nZ)8*RZ}nq@DR;nFfEP{3in^7rJIQ1_BXy#VTU5-KmoG%M2iz*iiom^z_%Wk!P*gnAW9E8# zV_^X^k?%KuGPJEv#UxxjQovr<9XS**lWHJ3g->d7suy<%eF6NFiKI_BGxszhy?JG)m@)g87XJ372L z>FWAPDA|{{G@%-;aQCIGC^J#dy8OSXD(_rZwjMc{`D<0wuFX}$IaPTf*ZxHtZ9`o} z^jB~HjD*W-pMwZq4t6OGFe=Nm@7sOAwJ4X!IXk#{SOe3W#Uz{T)yQ|C*`85Pto(KX zBnlf*Nt%%_0_5eTdU4AHHCd}tifjiYMo)wrg<}pssv;>x9@5!GCQZq2s$~{GiHjI# zXm4jV8$4-2^^H~pZcO~u;bheFknD8#FD~iRY0qMN_P$Cc`K4$JVo3S$Jg1C)7R~Ob zB`sWGB4~yFYBA0L6?a{)N*39-DbuR$yE<826PM0RKdcqw+n(B&Nzw{ol5X1^*>odH zb)NCgtufZpk=BCg#C1O0GwJ#nH_tG-a#YEyMiDNBrG9+tA7%{beqzl&RzJUMd0=UV zr~6=+7F;kb_^4WmpV}R>*QIJ(RrkTq6#2t()jUI*(#bYvY$l!zsS=Pwjp7@1D-RS9 zLe>0!hN4FND5f7)^QPzF>mkFDi*HyQme5_E(%2!5%4zsM~-tsfj zr25P0=ptGU+re!yv;N0sX!V1+Z+{e289eqoQJjs!9V?V;iC-h1@4$e+oa+%S>qNcU=-XvMb?MUpAQ9c;Ve6X-7t0gkMHTeB> zVXGj*b_XI}#4&}DsRtTDYu${r;CF^Yz`MS0J~_++Pjg_kQs1I@McP;vt}EgTbMqY8 z`E_1wU<>GL;nuk6Sxc(0QaA0#FX_~M-1C!lIDAu>R1HlZr?Cg1^!xif*qr5*1E{W$ z?@u%%1vq*5T~;SEf~EBiNAvs6m7&V3;Xn+htQ54)I)nD*6E9(IhoBn%H^k8S~`)faro`fm{0~j&v zc^ay@Gr-qL!?Q71;UdK6vfhJhq{f^RL8>7Rtt+TtoFOCIC+NFRy&PGtQRURp+;GJ9 z?mdnQIE^)aeF{>gf1fhp$14NfD!&L~r82>WZ;gV&nR#4VlS4(pdnVSh;_P0Rxq&ta z`@SkMwlYTc8uNfa0p@2I#MgoCAf3ow8)Bj@8)rpX2{%R9{$lxD0IADYiw>bjV)(9Lr1{}t9BFtKlohA*c+ti zv0m{GrVt`2Ipwa?$X7>$TreGOznhsF^h_!d@$qG}o1={yd$Ds=m0)?GBAR@PK5wJJ zRBg1`bP(JXSZw0Tq0d_ z_;G6dH=yVxxp2Jb^NgNqegWmXhfG@e&xpX*Y4}xn;(z`A9{M+wfWcjcVIRPnkvO4M zI)|^*WtoWzLP=vJL#i=)Bx+9Mw{+r&ovZN`RLeA=P>&h^ZR^!0{r}93+im7Bk)046 z_MdTBiMVp@h21j6%tUrOB5I1PU~nNKt-#tpuq{(g8{whvLI3vA76U!d>h^-C`B5s= zMN@Q7NJuJ#*twxW=*Y|dOFBpbwVd@U9sF83pWVh$8g}BS$g*N&G?9eIfg9k9n@k(> z&=^W2B{Co;8XUDQz{&;#(_mm=EL&3Z&uv=)cuj+`gPUF0l{0^>r##M*f-3c`+%bv9 zgr``u6W_&8zYRiY2ZvCa-_V&-$XgYi#svCe<>)9%))xKa2R9@|V1f967bXUUMz%Y@ z--4wO4>NEIYE<+V=s0B|t>YZkzM9!iR#UL2r4{zQd!oPeib+SM@uDrb%eXQ)&^%_o z`ggceh6(41;=zhu6z}LL)#=_@K#eH#bNl_6OtVgO?G|DK7zRWpm4{ZvPr+%Mrh4qT zKqrWa{?Wblw}CIKzQA()WdGvGsl9-mm%uDxd}9qVM)g&}EiwRRggs}EU5;AdD4N$o zn1Ubq|081#4BpoYnct1yQYK%-nT-yrwQc-_6$Mx6u0kkLLz|}lvykCXdf2~>tAU_(Cs#3!cYap zLh;(Eje4vwW;Pxk`_eud=CPX6(&H~bqAzp-iUuR>?fS=&59=#s4FZd8(G)g2JVcfL z9kEg5LnE_@Li)5RdxQ#FuNJfEjEL#K_`|O#28AhnSq16igi5LAD#Erb*&H_3gvIo1 z-9l_hd7{W^>`r=i!+QslyRIgym!njRRHGxmCQ=UZn0B_M`%Q?c93VwqkN$StA}lZ3 z3(JHHO;bW1W)1`z(?@BR!}s!~%3H~;^Fp1VLYrvtqP}0aR(giUD0-4`%NCic%N(6rVIJR0Cum1vm>(T z7nr977;jpX-JI^P$5TX0Mh(nOf=aX^11V$x;HoS76{BKgAfIJrlI>23e0i3oM<{@z z;lxqXdR2d3)aA=+SeT%+)@5hmwm#`6<2X0h>}o6i@!^V>iCjg}?Ki*k(@1s;)pTN_ zf;@h;a*7y@x)be?XW*6MY-M|)W9-KF*Q)|B8f5m==mX-Q&?;*Ihs-psm#a3cms@*7 z4U8hVT2XPN&%ibH9Tw&a%odMOCyR2c@$m~@eYj7O&?7=FhsHUiL_yMjlWf-*i3s|G z%9)95J!W!3;vr07<1llgnf-p@B5&AEACgvdH%3YFQrB^zAh@(Ol)WIvTKQMnm~n_~865u&iXXw>fcI^J#~ov|}iz zUVlr23!MY)#NzHGVV_MrI1A5msh^&%kMZAFnw$}ZXe!TE%YQ>70Oo0$A>435!qS&~ z13)fr-uZTi5FM;*r1U~kxF*AS$Hj#gu-@f(J#yo_W<@*-Cx9*EY4%eUqQ4QU{>dH{ zIw65C+6#N%?MgvP|W0tK6xMYPos4T3d7QM%(s8UMnX`IM>H|!^04_69zQbMz;@DF)2{F{9>dcduTc3E%wBLja`ZQz z*_v%-V+}8_gT(KdO$%WKmD1Yw<s6Hp`T@~n}D=xtbkL2F@URsrGvum!l{0O3pOo->@f6)fq)w|*N z3qycfaC~co_YdkqDF1j8Cn=Fh9PuNM$=e_G_5by3zMhMv%k;F+?8Okoj9J1f(QQ{F z$q#{P4gdWV7yr>fvT&^j!K za)nrReo1<%e_)q4$);PR

>Fl4lqdR#BWP8*H5mjfV>nQ$n6*0%~VP<}_R&Wh3K}sd+DybWZp41{pI!3xSv9Mq+I8f=RHQ9 zRCJY~@0QBj62q2c5-HtJZp)H{H@tL4rc&5S%l@Tt>5$3;>=2f#nLdmjY)^u*=VE)> zLP^k48$X~^V@kQ=m_D4{_tQZq*vlG|UWpj*?}P|~%`CsTR6 z`+M^Jd3gcn(`{`~(eHNvC)_gN)}q{Z7|+*Otg-`K z_6uW0dYoW+k&~r|$!CDWKJcBCcVJ5AOHJ1KdjOxG+)0=UuIcySoNz~__R42CBb_bJ*O^a69vai7|U5<1raJj!hMQEFZ2tK+sqzSD`f!XN}J!w|b zR?z@7b@=E$ag@}PM@hP+yXNT$Xe|yI67*Md+Z}c`-v@i%8_j0&cn@nBBNAogS4OPt%;vD+2hVp&C{rp-NKjb zC$rAAu@C;**;~g?|MgE%mV!s5XtZ0^n4F zK9|!L=t3Ai&+4x~*_`6^P+Eb;Mg_7vkMU>nT`jq~RSdeXPN#~YICM4RB8bhrywH*P zd#WG^2!6suC`v*cCq$RN?`yr@In2S6^^EJ?f1B*ztLQCyGg!q7jRl*(y@6EL7I6aT zKDY70vQB5`yOlDD#ru102MJOkE~8_Qt19{3>-_&xkq`?!V{o!KZG#bmH$PGDuD)P`{ioy831qG9N+$z5HXkT4eD`yy2)-Kt?+^>Io6i|czCu#@k__=*8mgoCs z&3hKW<#hkM73YitmAwH7Yj9Ef4HeZ0+b5cvY6p>9G`vIwF(&VNO_3a?F9qDOk^xDi zNQ-g<9(gPvKt7d~iRu2~Ll7vY3P}A8R2irv1c2*-4_}6XG_|L=SgVv8H;@q?#Tx*A z0S)98N}Ht3&kaTGJBIn+Y6^Jjx(Of<_vVM#Vj;QL4^7#w$Y@|Sv!DMZwv7c^1bh)( zPla!k4giUYfWnZaLUTa=;~Fe@41fi1etA$OhSLI)-N2=X@J?PHopHd^tOAs+d$q=! z9v7fhfbJEZ9q|C5CJ26=_a$Z9?xViswRimv-E}e;34pQjOCAvK2HGd;8ZXgT21?{E zd2`ES-2b@_cR~O9Cym$nV#w)%2Z#`1U-w||w!3`5t$~6LJmLjJQ$S6{3*nR?Ul0J0 zxJzDKKWNTH+Z3Soe0&Zlcx0;rCqNP)vRR-200udLd!t_r^on-iHlO~_j`i`DOW{A( zkG>Va2ytKF0Dc3~S3lvXX8r@1flvQk_hj_o#bQlBrfL3tD`}djpp4Cj(V(MHE8yv)|v|~T~uRi%*JMhcjYk=;b(>G+8 z>ymN3y#~tOpdNg6W4?ybuFruMZv(mvjn5tvnEqEHFQ8q{zkPUR{$C&O04klF^lMA= zjrI=khI^j?A$Fvl;e)sTU1Kt`eT)27qUGoRRMrV=nf);Hc?xE{-VV*YK*t{Ja zTZNDr2El>W>yy3;*UB!SZ#oiMO4SSxulu#{%~YV@Gi1#!>-34{W_Rai7lMiN?xQ;~ulo;)VO7e@sycp*~uFxTYVuIOEzl zd%VV81+_2c>f5`{<@!xywltcLZr}^>*(i$s2tp{M_ftPa`u*7{Y9*fw+g<1l)Q?Sv zA9Hr~Vq+!pmT@)cy!WQ}`RdPE3+{y&p(vm-(W|h`zDB|6=YZ>|Jga>5%jqda7@t;4 zrfE+#D|dRQO8vZrh_;G%acV<;ef{XevcIHcq{7^MCI)Xk!!wFpKs62aJDk!Kbzra| zLCRr9++GpJ}3R9vfMaU zoMcZuFQDZji94#tCYv?4zS5chsm4+b$0fJ8sp6+Xy`39*xfOxR{F3sT!pt3`p6ey` z9-`(O!P>H0B|O{fq|=u27amyz=Udt)8CfWk%c=GNAKM^JAprgCdU5p;%QyFzW`y}up=VCz| zPi;$!5pz*cp4qp`J*VU&YV$rg#SwX^!P?6CWP1(+%!lNZ+RI^=8Hb27p5brNp*|vq zg^UA>4``yxCvu)EzMk9N0Z18m-)$TPg|^zmwq`FriRlH(MFp4Zn9r|R2^{1J*H%>= zjkc>%CU;P0Rnla~A1{SHfk_CBd@3|I#+93!HbZYt_I`g+X=|o z$4pviGgLxYIb|A57vg^E*!k3|%mG!1)40phMLeuhxnV7QP&VU%{w+xR!Vg8C)&D&> zknaim))97J3^fd6PPCQdVRwc7URn)FKD(ie7lY)v9zJ$e6>4|g@tQj#V@Rx@Y+@gS z&I6#Xo7shh1cwhl&jKd$+2OD}z?K1VAuQB-e`X2Wu!FlE6Hz4DRB1*5^53bpW2Q6b zr$2>t?22DVa`bE2`eQy{?$nBgo>9uY$G$?r^ah3 zx)Wy`7X^htUTxADmrgV!jopyS4V_UfKdwE(-$H74G&(F&FXS-#_0JO5C}P5MZgmm> z1`I4?mxtd|gU>D#uE<{(4>}3P99DbtpJiUc1t+{X^ zygF*W@DB_umDNjhx$4TVaO0lj=F980J9V7Y(-YXuBc#+iL#T}fR*d)eH8LFJ9u|KL zTO7$5%HrF;8l5%GYINr1s=PMMeBTVwxFj%XxsLfy9u$T>*iyJes5%^0Q@EgNiOyOq zU=7hv2ECq`d{=+vwv1Uy@`31}hQMhXECh`&o-OKLiMM=7P3Wg}OKpIUmM|N)kfHi@ zM&O-an9p<9xo7glm;eEGUcZzJoe

From e3ae024ed37ce869e66a45f1d567b54600a90cf7 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 1 May 2025 21:21:28 +0100 Subject: [PATCH 1974/2291] chore: Link to Matrix rooms directly --- src/web/templates/index.html.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/templates/index.html.j2 b/src/web/templates/index.html.j2 index 648f5ddd..7f11cb1c 100644 --- a/src/web/templates/index.html.j2 +++ b/src/web/templates/index.html.j2 @@ -7,7 +7,7 @@

To get started, you can:

From d78fc53577b38d0cd9f93341804d1ca930d0d719 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 1 May 2025 21:27:12 +0100 Subject: [PATCH 1975/2291] ci: Fix bad comparison --- .forgejo/workflows/release-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 69d7d2fd..704a3bbf 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -214,7 +214,7 @@ jobs: type=semver,pattern=v{{version}} type=semver,pattern=v{{major}}.{{minor}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.0.') }} type=semver,pattern=v{{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} - type=ref,event=branch,prefix=${{ format('refs/heads/{0}', github.event.repository.default_branch) 1= github.ref && 'branch-' || '' }} + type=ref,event=branch,prefix=${{ format('refs/heads/{0}', github.event.repository.default_branch) != github.ref && 'branch-' || '' }} type=ref,event=pr type=sha,format=long images: ${{needs.define-variables.outputs.images}} From 01594a62439176aee1c1544c5be0cce0ddedcdf0 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 6 May 2025 20:51:12 +0100 Subject: [PATCH 1976/2291] chore: Fix typos across the codebase --- .typos.toml | 5 +++++ docs/deploying/docker-compose.for-traefik.yml | 2 +- docs/deploying/docker-compose.with-traefik.yml | 2 +- docs/maintenance.md | 2 +- src/api/client/capabilities.rs | 2 +- src/api/client/well_known.rs | 2 +- src/core/info/cargo.rs | 2 +- src/core/log/reload.rs | 6 +++--- src/core/utils/string/between.rs | 6 +++--- src/database/engine/cf_opts.rs | 2 +- src/main/main.rs | 2 +- src/main/restart.rs | 4 ++-- src/service/admin/execute.rs | 4 ++-- src/service/admin/mod.rs | 2 +- src/service/appservice/namespace_regex.rs | 2 +- src/service/media/remote.rs | 17 ++++++++++++----- src/service/resolver/actual.rs | 2 +- src/service/rooms/spaces/mod.rs | 2 +- src/service/rooms/timeline/mod.rs | 18 +++++++++--------- theme/css/chrome.css | 2 +- theme/css/variables.css | 12 ++++++------ 21 files changed, 55 insertions(+), 43 deletions(-) create mode 100644 .typos.toml diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 00000000..1e46469c --- /dev/null +++ b/.typos.toml @@ -0,0 +1,5 @@ +[default.extend-words] +"allocatedp" = "allocatedp" +"conduwuit" = "conduwuit" +"continuwuity" = "continuwuity" +"execuse" = "execuse" diff --git a/docs/deploying/docker-compose.for-traefik.yml b/docs/deploying/docker-compose.for-traefik.yml index 04142e0c..83fb64ff 100644 --- a/docs/deploying/docker-compose.for-traefik.yml +++ b/docs/deploying/docker-compose.for-traefik.yml @@ -28,7 +28,7 @@ services: #CONDUWUIT_CONFIG: '/etc/conduwuit.toml' # Uncomment if you mapped config toml above # We need some way to serve the client and server .well-known json. The simplest way is via the CONDUWUIT_WELL_KNOWN - # variable / config option, there are multiple ways to do this, e.g. in the conduwuit.toml file, and in a seperate + # variable / config option, there are multiple ways to do this, e.g. in the conduwuit.toml file, and in a separate # see the override file for more information about delegation CONDUWUIT_WELL_KNOWN: | { diff --git a/docs/deploying/docker-compose.with-traefik.yml b/docs/deploying/docker-compose.with-traefik.yml index 9083b796..a45893da 100644 --- a/docs/deploying/docker-compose.with-traefik.yml +++ b/docs/deploying/docker-compose.with-traefik.yml @@ -36,7 +36,7 @@ services: # CONDUWUIT_NEW_USER_DISPLAYNAME_SUFFIX = "🏳<200d>⚧" # We need some way to serve the client and server .well-known json. The simplest way is via the CONDUWUIT_WELL_KNOWN - # variable / config option, there are multiple ways to do this, e.g. in the conduwuit.toml file, and in a seperate + # variable / config option, there are multiple ways to do this, e.g. in the conduwuit.toml file, and in a separate # reverse proxy, but since you do not have a reverse proxy and following this guide, this example is included CONDUWUIT_WELL_KNOWN: | { diff --git a/docs/maintenance.md b/docs/maintenance.md index b85a1971..16ec5a4e 100644 --- a/docs/maintenance.md +++ b/docs/maintenance.md @@ -71,7 +71,7 @@ related to WAL tracking. The only safe files that can be deleted are the `LOG` files (all caps). These are the real RocksDB telemetry/log files, however Continuwuity has already -configured to only store up to 3 RocksDB `LOG` files due to generall being +configured to only store up to 3 RocksDB `LOG` files due to generally being useless for average users unless troubleshooting something low-level. If you would like to store nearly none at all, see the `rocksdb_max_log_files` config option. diff --git a/src/api/client/capabilities.rs b/src/api/client/capabilities.rs index 470ff6ab..7362c4f9 100644 --- a/src/api/client/capabilities.rs +++ b/src/api/client/capabilities.rs @@ -15,7 +15,7 @@ use crate::Ruma; /// # `GET /_matrix/client/v3/capabilities` /// -/// Get information on the supported feature set and other relevent capabilities +/// Get information on the supported feature set and other relevant capabilities /// of this server. pub(crate) async fn get_capabilities_route( State(services): State, diff --git a/src/api/client/well_known.rs b/src/api/client/well_known.rs index eedab981..35b7fc1e 100644 --- a/src/api/client/well_known.rs +++ b/src/api/client/well_known.rs @@ -60,7 +60,7 @@ pub(crate) async fn well_known_support( return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")); } - // TOOD: support defining multiple contacts in the config + // TODO: support defining multiple contacts in the config let mut contacts: Vec = vec![]; if let Some(role) = role { diff --git a/src/core/info/cargo.rs b/src/core/info/cargo.rs index 28c6590e..e70bdcd5 100644 --- a/src/core/info/cargo.rs +++ b/src/core/info/cargo.rs @@ -36,7 +36,7 @@ const MAIN_MANIFEST: &'static str = (); /// For *enabled* features see the info::rustc module instead. static FEATURES: OnceLock> = OnceLock::new(); -/// Processed list of dependencies. This is generated from the datas captured in +/// Processed list of dependencies. This is generated from the data captured in /// the MANIFEST. static DEPENDENCIES: OnceLock = OnceLock::new(); diff --git a/src/core/log/reload.rs b/src/core/log/reload.rs index e6a16c9f..f72fde47 100644 --- a/src/core/log/reload.rs +++ b/src/core/log/reload.rs @@ -16,9 +16,9 @@ use crate::{Result, error}; /// pulling in a version of tracing that's incompatible with the rest of our /// deps. /// -/// To work around this, we define an trait without the S paramter that forwards -/// to the reload::Handle::reload method, and then store the handle as a trait -/// object. +/// To work around this, we define an trait without the S parameter that +/// forwards to the reload::Handle::reload method, and then store the handle as +/// a trait object. /// /// [1]: pub trait ReloadHandle { diff --git a/src/core/utils/string/between.rs b/src/core/utils/string/between.rs index 05c137b4..8d3b6979 100644 --- a/src/core/utils/string/between.rs +++ b/src/core/utils/string/between.rs @@ -1,12 +1,12 @@ type Delim<'a> = (&'a str, &'a str); -/// Slice a string between a pair of delimeters. +/// Slice a string between a pair of delimiters. pub trait Between<'a> { - /// Extract a string between the delimeters. If the delimeters were not + /// Extract a string between the delimiters. If the delimiters were not /// found None is returned, otherwise the first extraction is returned. fn between(&self, delim: Delim<'_>) -> Option<&'a str>; - /// Extract a string between the delimeters. If the delimeters were not + /// Extract a string between the delimiters. If the delimiters were not /// found the original string is returned; take note of this behavior, /// if an empty slice is desired for this case use the fallible version and /// unwrap to EMPTY. diff --git a/src/database/engine/cf_opts.rs b/src/database/engine/cf_opts.rs index 7ceec722..cbbd1012 100644 --- a/src/database/engine/cf_opts.rs +++ b/src/database/engine/cf_opts.rs @@ -193,7 +193,7 @@ fn get_cache(ctx: &Context, desc: &Descriptor) -> Option { return None; } - // Some cache capacities are overriden by server config in a strange but + // Some cache capacities are overridden by server config in a strange but // legacy-compat way let config = &ctx.server.config; let cap = match desc.name { diff --git a/src/main/main.rs b/src/main/main.rs index 1a9d3fe4..3416bc68 100644 --- a/src/main/main.rs +++ b/src/main/main.rs @@ -73,7 +73,7 @@ async fn async_main(server: &Arc) -> Result<(), Error> { .lock() .await .take() - .expect("services initialied"), + .expect("services initialized"), ) .await { diff --git a/src/main/restart.rs b/src/main/restart.rs index b9d1dc94..631c1e21 100644 --- a/src/main/restart.rs +++ b/src/main/restart.rs @@ -13,8 +13,8 @@ pub(super) fn restart() -> ! { // // We can (and do) prevent that panic by checking the result of current_exe() // prior to committing to restart, returning an error to the user without any - // unexpected shutdown. In a nutshell that is the execuse for this unsafety. - // Nevertheless, we still want a way to override the restart preventation (i.e. + // unexpected shutdown. In a nutshell that is the excuse for this unsafety. + // Nevertheless, we still want a way to override the restart presentation (i.e. // admin server restart --force). let exe = unsafe { utils::sys::current_exe().expect("program path must be available") }; let envs = env::vars(); diff --git a/src/service/admin/execute.rs b/src/service/admin/execute.rs index 174b28ed..e0d724bd 100644 --- a/src/service/admin/execute.rs +++ b/src/service/admin/execute.rs @@ -25,7 +25,7 @@ pub(super) async fn console_auto_stop(&self) { /// Execute admin commands after startup #[implement(super::Service)] pub(super) async fn startup_execute(&self) -> Result { - // List of comamnds to execute + // List of commands to execute let commands = &self.services.server.config.admin_execute; // Determine if we're running in smoketest-mode which will change some behaviors @@ -64,7 +64,7 @@ pub(super) async fn startup_execute(&self) -> Result { /// Execute admin commands after signal #[implement(super::Service)] pub(super) async fn signal_execute(&self) -> Result { - // List of comamnds to execute + // List of commands to execute let commands = self.services.server.config.admin_signal_execute.clone(); // When true, errors are ignored and execution continues. diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index b3466711..683f5400 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -166,7 +166,7 @@ impl Service { .map_err(|e| err!("Failed to enqueue admin command: {e:?}")) } - /// Dispatches a comamnd to the processor on the current task and waits for + /// Dispatches a command to the processor on the current task and waits for /// completion. pub async fn command_in_place( &self, diff --git a/src/service/appservice/namespace_regex.rs b/src/service/appservice/namespace_regex.rs index fe0fd91f..76b754ae 100644 --- a/src/service/appservice/namespace_regex.rs +++ b/src/service/appservice/namespace_regex.rs @@ -26,7 +26,7 @@ impl NamespaceRegex { false } - /// Checks if this namespace has exlusive rights to a namespace + /// Checks if this namespace has exclusive rights to a namespace #[inline] #[must_use] pub fn is_exclusive_match(&self, heystack: &str) -> bool { diff --git a/src/service/media/remote.rs b/src/service/media/remote.rs index a1e874d8..f234fa13 100644 --- a/src/service/media/remote.rs +++ b/src/service/media/remote.rs @@ -338,7 +338,7 @@ fn handle_federation_error( return fallback(); } - // Reached for 5xx errors. This is where we don't fallback given the likelyhood + // Reached for 5xx errors. This is where we don't fallback given the likelihood // the other endpoint will also be a 5xx and we're wasting time. error } @@ -356,7 +356,7 @@ pub async fn fetch_remote_thumbnail_legacy( self.check_legacy_freeze()?; self.check_fetch_authorized(&mxc)?; - let reponse = self + let response = self .services .sending .send_federation_request(mxc.server_name, media::get_content_thumbnail::v3::Request { @@ -373,10 +373,17 @@ pub async fn fetch_remote_thumbnail_legacy( .await?; let dim = Dim::from_ruma(body.width, body.height, body.method.clone())?; - self.upload_thumbnail(&mxc, None, None, reponse.content_type.as_deref(), &dim, &reponse.file) - .await?; + self.upload_thumbnail( + &mxc, + None, + None, + response.content_type.as_deref(), + &dim, + &response.file, + ) + .await?; - Ok(reponse) + Ok(response) } #[implement(super::Service)] diff --git a/src/service/resolver/actual.rs b/src/service/resolver/actual.rs index 0151c4d7..d23ef95a 100644 --- a/src/service/resolver/actual.rs +++ b/src/service/resolver/actual.rs @@ -296,7 +296,7 @@ impl super::Service { expire: CachedOverride::default_expire(), overriding: (hostname != untername) .then_some(hostname.into()) - .inspect(|_| debug_info!("{untername:?} overriden by {hostname:?}")), + .inspect(|_| debug_info!("{untername:?} overridden by {hostname:?}")), }); Ok(()) diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index ea9756ba..53d2b742 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -399,7 +399,7 @@ async fn get_room_summary( Ok(summary) } -/// With the given identifier, checks if a room is accessable +/// With the given identifier, checks if a room is accessible #[implement(Service)] async fn is_accessible_child<'a, I>( &self, diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index 947e1c38..4b2f3cb2 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -267,15 +267,15 @@ impl Service { /// /// Returns pdu id #[tracing::instrument(level = "debug", skip_all)] - pub async fn append_pdu<'a, Leafs>( + pub async fn append_pdu<'a, Leaves>( &'a self, pdu: &'a PduEvent, mut pdu_json: CanonicalJsonObject, - leafs: Leafs, + leaves: Leaves, state_lock: &'a RoomMutexGuard, ) -> Result where - Leafs: Iterator + Send + 'a, + Leaves: Iterator + Send + 'a, { // Coalesce database writes for the remainder of this scope. let _cork = self.db.db.cork_and_flush(); @@ -344,7 +344,7 @@ impl Service { self.services .state - .set_forward_extremities(&pdu.room_id, leafs, state_lock) + .set_forward_extremities(&pdu.room_id, leaves, state_lock) .await; let insert_lock = self.mutex_insert.lock(&pdu.room_id).await; @@ -951,17 +951,17 @@ impl Service { /// Append the incoming event setting the state snapshot to the state from /// the server that sent the event. #[tracing::instrument(level = "debug", skip_all)] - pub async fn append_incoming_pdu<'a, Leafs>( + pub async fn append_incoming_pdu<'a, Leaves>( &'a self, pdu: &'a PduEvent, pdu_json: CanonicalJsonObject, - new_room_leafs: Leafs, + new_room_leaves: Leaves, state_ids_compressed: Arc, soft_fail: bool, state_lock: &'a RoomMutexGuard, ) -> Result> where - Leafs: Iterator + Send + 'a, + Leaves: Iterator + Send + 'a, { // We append to state before appending the pdu, so we don't have a moment in // time with the pdu without it's state. This is okay because append_pdu can't @@ -978,14 +978,14 @@ impl Service { self.services .state - .set_forward_extremities(&pdu.room_id, new_room_leafs, state_lock) + .set_forward_extremities(&pdu.room_id, new_room_leaves, state_lock) .await; return Ok(None); } let pdu_id = self - .append_pdu(pdu, pdu_json, new_room_leafs, state_lock) + .append_pdu(pdu, pdu_json, new_room_leaves, state_lock) .await?; Ok(Some(pdu_id)) diff --git a/theme/css/chrome.css b/theme/css/chrome.css index 52b35c2c..d6cc2b32 100644 --- a/theme/css/chrome.css +++ b/theme/css/chrome.css @@ -495,7 +495,7 @@ ul#searchresults span.teaser em { .chapter li { display: flex; - color: var(--sidebar-non-existant); + color: var(--sidebar-non-existent); } .chapter li a { display: block; diff --git a/theme/css/variables.css b/theme/css/variables.css index e7feed98..ca9fd271 100644 --- a/theme/css/variables.css +++ b/theme/css/variables.css @@ -20,7 +20,7 @@ --sidebar-bg: #14191f; --sidebar-fg: #c8c9db; - --sidebar-non-existant: #5c6773; + --sidebar-non-existent: #5c6773; --sidebar-active: #ffb454; --sidebar-spacer: #2d334f; @@ -64,7 +64,7 @@ --sidebar-bg: #292c2f; --sidebar-fg: #a1adb8; - --sidebar-non-existant: #505254; + --sidebar-non-existent: #505254; --sidebar-active: #3473ad; --sidebar-spacer: #393939; @@ -108,7 +108,7 @@ --sidebar-bg: #fafafa; --sidebar-fg: #AE518E; - --sidebar-non-existant: #aaaaaa; + --sidebar-non-existent: #aaaaaa; --sidebar-active: #2F7E86; --sidebar-spacer: #f4f4f4; @@ -152,7 +152,7 @@ --sidebar-bg: #282d3f; --sidebar-fg: #fdcbec; - --sidebar-non-existant: #505274; + --sidebar-non-existent: #505274; --sidebar-active: #5BCEFA; --sidebar-spacer: #2d334f; @@ -196,7 +196,7 @@ --sidebar-bg: #3b2e2a; --sidebar-fg: #c8c9db; - --sidebar-non-existant: #505254; + --sidebar-non-existent: #505254; --sidebar-active: #e69f67; --sidebar-spacer: #45373a; @@ -241,7 +241,7 @@ --sidebar-bg: #292c2f; --sidebar-fg: #a1adb8; - --sidebar-non-existant: #505254; + --sidebar-non-existent: #505254; --sidebar-active: #3473ad; --sidebar-spacer: #393939; From c0f46269b58c4f6faef3084e328e12dbe9ce7742 Mon Sep 17 00:00:00 2001 From: Jade Date: Tue, 6 May 2025 21:49:41 +0000 Subject: [PATCH 1977/2291] docs: Fix name in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf4f5613..fdcdafb7 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ It's a community continuation of the [conduwuit](https://github.com/girlbossceo/ The original conduwuit project has been archived and is no longer maintained. Rather than letting this Rust-based Matrix homeserver disappear, a group of community contributors have forked the project to continue its development, fix outstanding issues, and add new features. -We aim to provide a stable, well-maintained alternative for current Conduit users and welcome newcomers seeking a lightweight, efficient Matrix homeserver. +We aim to provide a stable, well-maintained alternative for current conduwuit users and welcome newcomers seeking a lightweight, efficient Matrix homeserver. ### Who are we? From 5577ddca270f2b0eb453987d08482565da01af0f Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 6 May 2025 22:56:23 +0100 Subject: [PATCH 1978/2291] chore: Add CONTINUWUITY_ environment variables Also updates some examples to match --- arch/conduwuit.service | 8 ++++---- debian/conduwuit.service | 7 ++++--- nix/pkgs/complement/default.nix | 6 +++--- src/core/config/mod.rs | 9 +++++++-- src/main/clap.rs | 18 ++++++++++++++++-- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/arch/conduwuit.service b/arch/conduwuit.service index 4f45ddc0..c86e37bd 100644 --- a/arch/conduwuit.service +++ b/arch/conduwuit.service @@ -1,11 +1,11 @@ [Unit] -Description=conduwuit Matrix homeserver + +Description=Continuwuity - Matrix homeserver Wants=network-online.target After=network-online.target -Documentation=https://conduwuit.puppyirl.gay/ +Documentation=https://continuwuity.org/ RequiresMountsFor=/var/lib/private/conduwuit Alias=matrix-conduwuit.service - [Service] DynamicUser=yes Type=notify-reload @@ -59,7 +59,7 @@ StateDirectory=conduwuit RuntimeDirectory=conduwuit RuntimeDirectoryMode=0750 -Environment="CONDUWUIT_CONFIG=/etc/conduwuit/conduwuit.toml" +Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml" BindPaths=/var/lib/private/conduwuit:/var/lib/matrix-conduit BindPaths=/var/lib/private/conduwuit:/var/lib/private/matrix-conduit diff --git a/debian/conduwuit.service b/debian/conduwuit.service index 3d2fbc9b..be2f3dae 100644 --- a/debian/conduwuit.service +++ b/debian/conduwuit.service @@ -1,9 +1,10 @@ [Unit] -Description=conduwuit Matrix homeserver + +Description=Continuwuity - Matrix homeserver Wants=network-online.target After=network-online.target -Alias=matrix-conduwuit.service Documentation=https://continuwuity.org/ +Alias=matrix-conduwuit.service [Service] DynamicUser=yes @@ -11,7 +12,7 @@ User=conduwuit Group=conduwuit Type=notify -Environment="CONDUWUIT_CONFIG=/etc/conduwuit/conduwuit.toml" +Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml" ExecStart=/usr/sbin/conduwuit diff --git a/nix/pkgs/complement/default.nix b/nix/pkgs/complement/default.nix index 9b010e14..1295cb03 100644 --- a/nix/pkgs/complement/default.nix +++ b/nix/pkgs/complement/default.nix @@ -75,9 +75,9 @@ dockerTools.buildImage { else []; Env = [ - "CONDUWUIT_TLS__KEY=${./private_key.key}" - "CONDUWUIT_TLS__CERTS=${./certificate.crt}" - "CONDUWUIT_CONFIG=${./config.toml}" + "CONTINUWUITY_TLS__KEY=${./private_key.key}" + "CONTINUWUITY_TLS__CERTS=${./certificate.crt}" + "CONTINUWUITY_CONFIG=${./config.toml}" "RUST_BACKTRACE=full" ]; diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 5374c2c2..5648a126 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -1962,7 +1962,11 @@ impl Config { where I: Iterator, { - let envs = [Env::var("CONDUIT_CONFIG"), Env::var("CONDUWUIT_CONFIG")]; + let envs = [ + Env::var("CONDUIT_CONFIG"), + Env::var("CONDUWUIT_CONFIG"), + Env::var("CONTINUWUITY_CONFIG"), + ]; let config = envs .into_iter() @@ -1971,7 +1975,8 @@ impl Config { .chain(paths.map(Toml::file)) .fold(Figment::new(), |config, file| config.merge(file.nested())) .merge(Env::prefixed("CONDUIT_").global().split("__")) - .merge(Env::prefixed("CONDUWUIT_").global().split("__")); + .merge(Env::prefixed("CONDUWUIT_").global().split("__")) + .merge(Env::prefixed("CONTINUWUITY_").global().split("__")); Ok(config) } diff --git a/src/main/clap.rs b/src/main/clap.rs index 707a1c76..9b63af19 100644 --- a/src/main/clap.rs +++ b/src/main/clap.rs @@ -74,17 +74,30 @@ pub(crate) struct Args { /// with the exception of the last bucket, try increasing this value to e.g. /// 50 or 100. Inversely, decrease to 10 etc if the histogram lacks /// resolution. - #[arg(long, hide(true), env = "CONDUWUIT_RUNTIME_HISTOGRAM_INTERVAL", default_value = "25")] + #[arg( + long, + hide(true), + env = "CONTINUWUITY_RUNTIME_HISTOGRAM_INTERVAL", + env = "CONDUWUIT_RUNTIME_HISTOGRAM_INTERVAL", + default_value = "25" + )] pub(crate) worker_histogram_interval: u64, /// Set the histogram bucket count (tokio_unstable). Default is 20. - #[arg(long, hide(true), env = "CONDUWUIT_RUNTIME_HISTOGRAM_BUCKETS", default_value = "20")] + #[arg( + long, + hide(true), + env = "CONTINUWUITY_RUNTIME_HISTOGRAM_BUCKETS", + env = "CONDUWUIT_RUNTIME_HISTOGRAM_BUCKETS", + default_value = "20" + )] pub(crate) worker_histogram_buckets: usize, /// Toggles worker affinity feature. #[arg( long, hide(true), + env = "CONTINUWUITY_RUNTIME_WORKER_AFFINITY", env = "CONDUWUIT_RUNTIME_WORKER_AFFINITY", action = ArgAction::Set, num_args = 0..=1, @@ -99,6 +112,7 @@ pub(crate) struct Args { #[arg( long, hide(true), + env = "CONTINUWUITY_RUNTIME_GC_ON_PARK", env = "CONDUWUIT_RUNTIME_GC_ON_PARK", action = ArgAction::Set, num_args = 0..=1, From 7c58e40c967d984f1105738b589e81cc9f6069be Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 10 May 2025 13:29:59 +0100 Subject: [PATCH 1979/2291] chore(typos): Ignore certificate files --- .typos.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.typos.toml b/.typos.toml index 1e46469c..fe958292 100644 --- a/.typos.toml +++ b/.typos.toml @@ -1,3 +1,6 @@ +[files] +extend-exclude = ["*.csr"] + [default.extend-words] "allocatedp" = "allocatedp" "conduwuit" = "conduwuit" From beee996f723101d8ca61de7ebd46446f99298555 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 10 May 2025 20:37:08 +0100 Subject: [PATCH 1980/2291] docs: Rename conduwuit to continuwuity in more places --- .typos.toml | 1 + CONTRIBUTING.md | 4 +- Cargo.toml | 2 +- conduwuit-example.toml | 175 ++++++++--------- debian/README.md | 4 +- docs/deploying/docker-compose.for-traefik.yml | 38 ++-- docs/deploying/docker-compose.override.yml | 10 +- docs/deploying/docker-compose.with-caddy.yml | 30 +-- .../deploying/docker-compose.with-traefik.yml | 48 ++--- docs/deploying/docker-compose.yml | 30 +-- docs/deploying/docker.md | 10 +- docs/deploying/generic.md | 2 +- docs/development/hot_reload.md | 2 +- docs/development/testing.md | 5 +- nix/pkgs/oci-image/default.nix | 8 +- src/admin/processor.rs | 2 +- src/core/config/check.rs | 4 +- src/core/config/mod.rs | 177 +++++++++--------- src/service/admin/create.rs | 2 +- 19 files changed, 279 insertions(+), 275 deletions(-) diff --git a/.typos.toml b/.typos.toml index fe958292..41c81085 100644 --- a/.typos.toml +++ b/.typos.toml @@ -5,4 +5,5 @@ extend-exclude = ["*.csr"] "allocatedp" = "allocatedp" "conduwuit" = "conduwuit" "continuwuity" = "continuwuity" +"continuwity" = "continuwuity" "execuse" = "execuse" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ecff7173..da426801 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing guide -This page is for about contributing to conduwuit. The +This page is for about contributing to Continuwuity. The [development](./development.md) page may be of interest for you as well. If you would like to work on an [issue][issues] that is not assigned, preferably @@ -73,7 +73,7 @@ If you'd like to run Complement locally using Nix, see the ### Writing documentation -conduwuit's website uses [`mdbook`][mdbook] and deployed via CI using GitHub +Continuwuity's website uses [`mdbook`][mdbook] and deployed via CI using GitHub Pages in the [`documentation.yml`][documentation.yml] workflow file with Nix's mdbook in the devshell. All documentation is in the `docs/` directory at the top level. The compiled mdbook website is also uploaded as an artifact. diff --git a/Cargo.toml b/Cargo.toml index 43cd3f4f..79f767a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -298,7 +298,7 @@ version = "1.15.0" default-features = false features = ["serde"] -# Used for reading the configuration from conduwuit.toml & environment variables +# Used for reading the configuration from continuwuity.toml & environment variables [workspace.dependencies.figment] version = "0.10.19" default-features = false diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 3d92ab15..6934e67c 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -1,4 +1,4 @@ -### conduwuit Configuration +### continuwuity Configuration ### ### THIS FILE IS GENERATED. CHANGES/CONTRIBUTIONS IN THE REPO WILL BE ### OVERWRITTEN! @@ -13,7 +13,7 @@ ### that say "YOU NEED TO EDIT THIS". ### ### For more information, see: -### https://conduwuit.puppyirl.gay/configuration.html +### https://continuwuity.org/configuration.html [global] @@ -21,7 +21,7 @@ # suffix for user and room IDs/aliases. # # See the docs for reverse proxying and delegation: -# https://conduwuit.puppyirl.gay/deploying/generic.html#setting-up-the-reverse-proxy +# https://continuwuity.org/deploying/generic.html#setting-up-the-reverse-proxy # # Also see the `[global.well_known]` config section at the very bottom. # @@ -32,11 +32,11 @@ # YOU NEED TO EDIT THIS. THIS CANNOT BE CHANGED AFTER WITHOUT A DATABASE # WIPE. # -# example: "conduwuit.woof" +# example: "continuwuity.org" # #server_name = -# The default address (IPv4 or IPv6) conduwuit will listen on. +# The default address (IPv4 or IPv6) continuwuity will listen on. # # If you are using Docker or a container NAT networking setup, this must # be "0.0.0.0". @@ -46,10 +46,10 @@ # #address = ["127.0.0.1", "::1"] -# The port(s) conduwuit will listen on. +# The port(s) continuwuity will listen on. # # For reverse proxying, see: -# https://conduwuit.puppyirl.gay/deploying/generic.html#setting-up-the-reverse-proxy +# https://continuwuity.org/deploying/generic.html#setting-up-the-reverse-proxy # # If you are using Docker, don't change this, you'll need to map an # external port to this. @@ -58,16 +58,17 @@ # #port = 8008 -# The UNIX socket conduwuit will listen on. +# The UNIX socket continuwuity will listen on. # -# conduwuit cannot listen on both an IP address and a UNIX socket. If +# continuwuity cannot listen on both an IP address and a UNIX socket. If # listening on a UNIX socket, you MUST remove/comment the `address` key. # # Remember to make sure that your reverse proxy has access to this socket -# file, either by adding your reverse proxy to the 'conduwuit' group or -# granting world R/W permissions with `unix_socket_perms` (666 minimum). +# file, either by adding your reverse proxy to the appropriate user group +# or granting world R/W permissions with `unix_socket_perms` (666 +# minimum). # -# example: "/run/conduwuit/conduwuit.sock" +# example: "/run/continuwuity/continuwuity.sock" # #unix_socket_path = @@ -75,23 +76,23 @@ # #unix_socket_perms = 660 -# This is the only directory where conduwuit will save its data, including -# media. Note: this was previously "/var/lib/matrix-conduit". +# This is the only directory where continuwuity will save its data, +# including media. Note: this was previously "/var/lib/matrix-conduit". # # YOU NEED TO EDIT THIS. # -# example: "/var/lib/conduwuit" +# example: "/var/lib/continuwuity" # #database_path = -# conduwuit supports online database backups using RocksDB's Backup engine -# API. To use this, set a database backup path that conduwuit can write -# to. +# continuwuity supports online database backups using RocksDB's Backup +# engine API. To use this, set a database backup path that continuwuity +# can write to. # # For more information, see: -# https://conduwuit.puppyirl.gay/maintenance.html#backups +# https://continuwuity.org/maintenance.html#backups # -# example: "/opt/conduwuit-db-backups" +# example: "/opt/continuwuity-db-backups" # #database_backup_path = @@ -112,14 +113,14 @@ # #new_user_displayname_suffix = "🏳️‍⚧️" -# If enabled, conduwuit will send a simple GET request periodically to +# If enabled, continuwuity will send a simple GET request periodically to # `https://continuwuity.org/.well-known/continuwuity/announcements` for any new # announcements or major updates. This is not an update check endpoint. # #allow_announcements_check = true -# Set this to any float value to multiply conduwuit's in-memory LRU caches -# with such as "auth_chain_cache_capacity". +# Set this to any float value to multiply continuwuity's in-memory LRU +# caches with such as "auth_chain_cache_capacity". # # May be useful if you have significant memory to spare to increase # performance. @@ -131,7 +132,7 @@ # #cache_capacity_modifier = 1.0 -# Set this to any float value in megabytes for conduwuit to tell the +# Set this to any float value in megabytes for continuwuity to tell the # database engine that this much memory is available for database read # caches. # @@ -145,7 +146,7 @@ # #db_cache_capacity_mb = varies by system -# Set this to any float value in megabytes for conduwuit to tell the +# Set this to any float value in megabytes for continuwuity to tell the # database engine that this much memory is available for database write # caches. # @@ -250,9 +251,9 @@ # Enable using *only* TCP for querying your specified nameservers instead # of UDP. # -# If you are running conduwuit in a container environment, this config +# If you are running continuwuity in a container environment, this config # option may need to be enabled. For more details, see: -# https://conduwuit.puppyirl.gay/troubleshooting.html#potential-dns-issues-when-using-docker +# https://continuwuity.org/troubleshooting.html#potential-dns-issues-when-using-docker # #query_over_tcp_only = false @@ -418,9 +419,9 @@ # tokens. Multiple tokens can be added if you separate them with # whitespace # -# conduwuit must be able to access the file, and it must not be empty +# continuwuity must be able to access the file, and it must not be empty # -# example: "/etc/conduwuit/.reg_token" +# example: "/etc/continuwuity/.reg_token" # #registration_token_file = @@ -512,16 +513,16 @@ #allow_room_creation = true # Set to false to disable users from joining or creating room versions -# that aren't officially supported by conduwuit. +# that aren't officially supported by continuwuity. # -# conduwuit officially supports room versions 6 - 11. +# continuwuity officially supports room versions 6 - 11. # -# conduwuit has slightly experimental (though works fine in practice) +# continuwuity has slightly experimental (though works fine in practice) # support for versions 3 - 5. # #allow_unstable_room_versions = true -# Default room version conduwuit will create rooms with. +# Default room version continuwuity will create rooms with. # # Per spec, room version 11 is the default. # @@ -587,7 +588,7 @@ # Servers listed here will be used to gather public keys of other servers # (notary trusted key servers). # -# Currently, conduwuit doesn't support inbound batched key requests, so +# Currently, continuwuity doesn't support inbound batched key requests, so # this list should only contain other Synapse servers. # # example: ["matrix.org", "tchncs.de"] @@ -628,7 +629,7 @@ # #trusted_server_batch_size = 1024 -# Max log level for conduwuit. Allows debug, info, warn, or error. +# Max log level for continuwuity. Allows debug, info, warn, or error. # # See also: # https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives @@ -649,8 +650,9 @@ # #log_span_events = "none" -# Configures whether CONDUWUIT_LOG EnvFilter matches values using regular -# expressions. See the tracing_subscriber documentation on Directives. +# Configures whether CONTINUWUITY_LOG EnvFilter matches values using +# regular expressions. See the tracing_subscriber documentation on +# Directives. # #log_filter_regex = true @@ -718,7 +720,7 @@ # This takes priority over "turn_secret" first, and falls back to # "turn_secret" if invalid or failed to open. # -# example: "/etc/conduwuit/.turn_secret" +# example: "/etc/continuwuity/.turn_secret" # #turn_secret_file = @@ -726,12 +728,12 @@ # #turn_ttl = 86400 -# List/vector of room IDs or room aliases that conduwuit will make newly -# registered users join. The rooms specified must be rooms that you have -# joined at least once on the server, and must be public. +# List/vector of room IDs or room aliases that continuwuity will make +# newly registered users join. The rooms specified must be rooms that you +# have joined at least once on the server, and must be public. # -# example: ["#conduwuit:puppygock.gay", -# "!eoIzvAvVwY23LPDay8:puppygock.gay"] +# example: ["#continuwuity:continuwuity.org", +# "!main-1:continuwuity.org"] # #auto_join_rooms = [] @@ -754,10 +756,10 @@ # #auto_deactivate_banned_room_attempts = false -# RocksDB log level. This is not the same as conduwuit's log level. This -# is the log level for the RocksDB engine/library which show up in your -# database folder/path as `LOG` files. conduwuit will log RocksDB errors -# as normal through tracing or panics if severe for safety. +# RocksDB log level. This is not the same as continuwuity's log level. +# This is the log level for the RocksDB engine/library which show up in +# your database folder/path as `LOG` files. continuwuity will log RocksDB +# errors as normal through tracing or panics if severe for safety. # #rocksdb_log_level = "error" @@ -777,7 +779,7 @@ # Set this to true to use RocksDB config options that are tailored to HDDs # (slower device storage). # -# It is worth noting that by default, conduwuit will use RocksDB with +# It is worth noting that by default, continuwuity will use RocksDB with # Direct IO enabled. *Generally* speaking this improves performance as it # bypasses buffered I/O (system page cache). However there is a potential # chance that Direct IO may cause issues with database operations if your @@ -785,7 +787,7 @@ # possibly ZFS filesystem. RocksDB generally deals/corrects these issues # but it cannot account for all setups. If you experience any weird # RocksDB issues, try enabling this option as it turns off Direct IO and -# feel free to report in the conduwuit Matrix room if this option fixes +# feel free to report in the continuwuity Matrix room if this option fixes # your DB issues. # # For more information, see: @@ -840,7 +842,7 @@ # as they all differ. See their `kDefaultCompressionLevel`. # # Note when using the default value we may override it with a setting -# tailored specifically conduwuit. +# tailored specifically for continuwuity. # #rocksdb_compression_level = 32767 @@ -856,7 +858,7 @@ # algorithm. # # Note when using the default value we may override it with a setting -# tailored specifically conduwuit. +# tailored specifically for continuwuity. # #rocksdb_bottommost_compression_level = 32767 @@ -896,13 +898,13 @@ # 0 = AbsoluteConsistency # 1 = TolerateCorruptedTailRecords (default) # 2 = PointInTime (use me if trying to recover) -# 3 = SkipAnyCorruptedRecord (you now voided your Conduwuit warranty) +# 3 = SkipAnyCorruptedRecord (you now voided your Continuwuity warranty) # # For more information on these modes, see: # https://github.com/facebook/rocksdb/wiki/WAL-Recovery-Modes # # For more details on recovering a corrupt database, see: -# https://conduwuit.puppyirl.gay/troubleshooting.html#database-corruption +# https://continuwuity.org/troubleshooting.html#database-corruption # #rocksdb_recovery_mode = 1 @@ -942,7 +944,7 @@ # - Disabling repair mode and restarting the server is recommended after # running the repair. # -# See https://conduwuit.puppyirl.gay/troubleshooting.html#database-corruption for more details on recovering a corrupt database. +# See https://continuwuity.org/troubleshooting.html#database-corruption for more details on recovering a corrupt database. # #rocksdb_repair = false @@ -969,7 +971,7 @@ # Enables RocksDB compaction. You should never ever have to set this # option to false. If you for some reason find yourself needing to use # this option as part of troubleshooting or a bug, please reach out to us -# in the conduwuit Matrix room with information and details. +# in the continuwuity Matrix room with information and details. # # Disabling compaction will lead to a significantly bloated and # explosively large database, gradually poor performance, unnecessarily @@ -995,7 +997,7 @@ # purposes such as recovering/recreating your admin room, or inviting # yourself back. # -# See https://conduwuit.puppyirl.gay/troubleshooting.html#lost-access-to-admin-room for other ways to get back into your admin room. +# See https://continuwuity.org/troubleshooting.html#lost-access-to-admin-room for other ways to get back into your admin room. # # Once this password is unset, all sessions will be logged out for # security purposes. @@ -1010,8 +1012,8 @@ # Allow local (your server only) presence updates/requests. # -# Note that presence on conduwuit is very fast unlike Synapse's. If using -# outgoing presence, this MUST be enabled. +# Note that presence on continuwuity is very fast unlike Synapse's. If +# using outgoing presence, this MUST be enabled. # #allow_local_presence = true @@ -1019,7 +1021,7 @@ # # This option receives presence updates from other servers, but does not # send any unless `allow_outgoing_presence` is true. Note that presence on -# conduwuit is very fast unlike Synapse's. +# continuwuity is very fast unlike Synapse's. # #allow_incoming_presence = true @@ -1027,8 +1029,8 @@ # # This option sends presence updates to other servers, but does not # receive any unless `allow_incoming_presence` is true. Note that presence -# on conduwuit is very fast unlike Synapse's. If using outgoing presence, -# you MUST enable `allow_local_presence` as well. +# on continuwuity is very fast unlike Synapse's. If using outgoing +# presence, you MUST enable `allow_local_presence` as well. # #allow_outgoing_presence = true @@ -1081,8 +1083,8 @@ # #typing_client_timeout_max_s = 45 -# Set this to true for conduwuit to compress HTTP response bodies using -# zstd. This option does nothing if conduwuit was not built with +# Set this to true for continuwuity to compress HTTP response bodies using +# zstd. This option does nothing if continuwuity was not built with # `zstd_compression` feature. Please be aware that enabling HTTP # compression may weaken TLS. Most users should not need to enable this. # See https://breachattack.com/ and https://wikipedia.org/wiki/BREACH @@ -1090,8 +1092,8 @@ # #zstd_compression = false -# Set this to true for conduwuit to compress HTTP response bodies using -# gzip. This option does nothing if conduwuit was not built with +# Set this to true for continuwuity to compress HTTP response bodies using +# gzip. This option does nothing if continuwuity was not built with # `gzip_compression` feature. Please be aware that enabling HTTP # compression may weaken TLS. Most users should not need to enable this. # See https://breachattack.com/ and https://wikipedia.org/wiki/BREACH before @@ -1102,8 +1104,8 @@ # #gzip_compression = false -# Set this to true for conduwuit to compress HTTP response bodies using -# brotli. This option does nothing if conduwuit was not built with +# Set this to true for continuwuity to compress HTTP response bodies using +# brotli. This option does nothing if continuwuity was not built with # `brotli_compression` feature. Please be aware that enabling HTTP # compression may weaken TLS. Most users should not need to enable this. # See https://breachattack.com/ and https://wikipedia.org/wiki/BREACH @@ -1165,7 +1167,7 @@ # Otherwise setting this to false reduces filesystem clutter and overhead # for managing these symlinks in the directory. This is now disabled by # default. You may still return to upstream Conduit but you have to run -# conduwuit at least once with this set to true and allow the +# continuwuity at least once with this set to true and allow the # media_startup_check to take place before shutting down to return to # Conduit. # @@ -1210,8 +1212,8 @@ # #allowed_remote_server_names = [] -# Vector list of regex patterns of server names that conduwuit will refuse -# to download remote media from. +# Vector list of regex patterns of server names that continuwuity will +# refuse to download remote media from. # # example: ["badserver\.tld$", "badphrase", "19dollarfortnitecards"] # @@ -1225,7 +1227,7 @@ # #forbidden_remote_room_directory_server_names = [] -# Vector list of regex patterns of server names that conduwuit will not +# Vector list of regex patterns of server names that continuwuity will not # send messages to the client from. # # Note that there is no way for clients to receive messages once a server @@ -1249,7 +1251,7 @@ #send_messages_from_ignored_users_to_client = false # Vector list of IPv4 and IPv6 CIDR ranges / subnets *in quotes* that you -# do not want conduwuit to send outbound requests to. Defaults to +# do not want continuwuity to send outbound requests to. Defaults to # RFC1918, unroutable, loopback, multicast, and testnet addresses for # security. # @@ -1399,26 +1401,26 @@ # Allow admins to enter commands in rooms other than "#admins" (admin # room) by prefixing your message with "\!admin" or "\\!admin" followed up -# a normal conduwuit admin command. The reply will be publicly visible to -# the room, originating from the sender. +# a normal continuwuity admin command. The reply will be publicly visible +# to the room, originating from the sender. # # example: \\!admin debug ping puppygock.gay # #admin_escape_commands = true -# Automatically activate the conduwuit admin room console / CLI on -# startup. This option can also be enabled with `--console` conduwuit +# Automatically activate the continuwuity admin room console / CLI on +# startup. This option can also be enabled with `--console` continuwuity # argument. # #admin_console_automatic = false # List of admin commands to execute on startup. # -# This option can also be configured with the `--execute` conduwuit +# This option can also be configured with the `--execute` continuwuity # argument and can take standard shell commands and environment variables # -# For example: `./conduwuit --execute "server admin-notice conduwuit has -# started up at $(date)"` +# For example: `./continuwuity --execute "server admin-notice continuwuity +# has started up at $(date)"` # # example: admin_execute = ["debug ping puppygock.gay", "debug echo hi"]` # @@ -1426,7 +1428,7 @@ # Ignore errors in startup commands. # -# If false, conduwuit will error and fail to start if an admin execute +# If false, continuwuity will error and fail to start if an admin execute # command (`--execute` / `admin_execute`) fails. # #admin_execute_errors_ignore = false @@ -1447,15 +1449,14 @@ # The default room tag to apply on the admin room. # # On some clients like Element, the room tag "m.server_notice" is a -# special pinned room at the very bottom of your room list. The conduwuit -# admin room can be pinned here so you always have an easy-to-access -# shortcut dedicated to your admin room. +# special pinned room at the very bottom of your room list. The +# continuwuity admin room can be pinned here so you always have an +# easy-to-access shortcut dedicated to your admin room. # #admin_room_tag = "m.server_notice" # Sentry.io crash/panic reporting, performance monitoring/metrics, etc. -# This is NOT enabled by default. conduwuit's default Sentry reporting -# endpoint domain is `o4506996327251968.ingest.us.sentry.io`. +# This is NOT enabled by default. # #sentry = false @@ -1463,7 +1464,7 @@ # #sentry_endpoint = "" -# Report your conduwuit server_name in Sentry.io crash reports and +# Report your continuwuity server_name in Sentry.io crash reports and # metrics. # #sentry_send_server_name = false @@ -1500,7 +1501,7 @@ # Enable the tokio-console. This option is only relevant to developers. # # For more information, see: -# https://conduwuit.puppyirl.gay/development.html#debugging-with-tokio-console +# https://continuwuity.org/development.html#debugging-with-tokio-console # #tokio_console = false diff --git a/debian/README.md b/debian/README.md index 800a2e09..4a8e58d2 100644 --- a/debian/README.md +++ b/debian/README.md @@ -1,4 +1,4 @@ -# conduwuit for Debian +# Continuwuity for Debian Information about downloading and deploying the Debian package. This may also be referenced for other `apt`-based distros such as Ubuntu. @@ -22,7 +22,7 @@ options in `/etc/conduwuit/conduwuit.toml`. ### Running -The package uses the [`conduwuit.service`](../configuration/examples.md#example-systemd-unit-file) systemd unit file to start and stop conduwuit. The binary is installed at `/usr/sbin/conduwuit`. +The package uses the [`conduwuit.service`](../configuration/examples.md#example-systemd-unit-file) systemd unit file to start and stop Continuwuity. The binary is installed at `/usr/sbin/conduwuit`. This package assumes by default that conduwuit will be placed behind a reverse proxy. The default config options apply (listening on `localhost` and TCP port `6167`). Matrix federation requires a valid domain name and TLS, so you will need to set up TLS certificates and renewal for it to work properly if you intend to federate. diff --git a/docs/deploying/docker-compose.for-traefik.yml b/docs/deploying/docker-compose.for-traefik.yml index 83fb64ff..547712b6 100644 --- a/docs/deploying/docker-compose.for-traefik.yml +++ b/docs/deploying/docker-compose.for-traefik.yml @@ -7,30 +7,30 @@ services: image: forgejo.ellis.link/continuwuation/continuwuity:latest restart: unless-stopped volumes: - - db:/var/lib/conduwuit - - /etc/resolv.conf:/etc/resolv.conf:ro # Use the host's DNS resolver rather than Docker's. - #- ./conduwuit.toml:/etc/conduwuit.toml + - db:/var/lib/continuwuity + - /etc/resolv.conf:/etc/resolv.conf:ro # Use the host's DNS resolver rather than Docker's. + #- ./continuwuity.toml:/etc/continuwuity.toml networks: - proxy environment: - CONDUWUIT_SERVER_NAME: your.server.name.example # EDIT THIS - CONDUWUIT_DATABASE_PATH: /var/lib/conduwuit - CONDUWUIT_PORT: 6167 # should match the loadbalancer traefik label - CONDUWUIT_MAX_REQUEST_SIZE: 20000000 # in bytes, ~20 MB - CONDUWUIT_ALLOW_REGISTRATION: 'true' - CONDUWUIT_REGISTRATION_TOKEN: 'YOUR_TOKEN' # A registration token is required when registration is allowed. - #CONDUWUIT_YES_I_AM_VERY_VERY_SURE_I_WANT_AN_OPEN_REGISTRATION_SERVER_PRONE_TO_ABUSE: 'true' - CONDUWUIT_ALLOW_FEDERATION: 'true' - CONDUWUIT_ALLOW_CHECK_FOR_UPDATES: 'true' - CONDUWUIT_TRUSTED_SERVERS: '["matrix.org"]' - #CONDUWUIT_LOG: warn,state_res=warn - CONDUWUIT_ADDRESS: 0.0.0.0 - #CONDUWUIT_CONFIG: '/etc/conduwuit.toml' # Uncomment if you mapped config toml above + CONTINUWUITY_SERVER_NAME: your.server.name.example # EDIT THIS + CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity + CONTINUWUITY_PORT: 6167 # should match the loadbalancer traefik label + CONTINUWUITY_MAX_REQUEST_SIZE: 20000000 # in bytes, ~20 MB + CONTINUWUITY_ALLOW_REGISTRATION: 'true' + CONTINUWUITY_REGISTRATION_TOKEN: 'YOUR_TOKEN' # A registration token is required when registration is allowed. + #CONTINUWUITY_YES_I_AM_VERY_VERY_SURE_I_WANT_AN_OPEN_REGISTRATION_SERVER_PRONE_TO_ABUSE: 'true' + CONTINUWUITY_ALLOW_FEDERATION: 'true' + CONTINUWUITY_ALLOW_CHECK_FOR_UPDATES: 'true' + CONTINUWUITY_TRUSTED_SERVERS: '["matrix.org"]' + #CONTINUWUITY_LOG: warn,state_res=warn + CONTINUWUITY_ADDRESS: 0.0.0.0 + #CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above - # We need some way to serve the client and server .well-known json. The simplest way is via the CONDUWUIT_WELL_KNOWN - # variable / config option, there are multiple ways to do this, e.g. in the conduwuit.toml file, and in a separate + # We need some way to serve the client and server .well-known json. The simplest way is via the CONTINUWUITY_WELL_KNOWN + # variable / config option, there are multiple ways to do this, e.g. in the continuwuity.toml file, and in a separate # see the override file for more information about delegation - CONDUWUIT_WELL_KNOWN: | + CONTINUWUITY_WELL_KNOWN: | { client=https://your.server.name.example, server=your.server.name.example:443 diff --git a/docs/deploying/docker-compose.override.yml b/docs/deploying/docker-compose.override.yml index ec82fac3..168b1ae6 100644 --- a/docs/deploying/docker-compose.override.yml +++ b/docs/deploying/docker-compose.override.yml @@ -6,11 +6,11 @@ services: - "traefik.enable=true" - "traefik.docker.network=proxy" # Change this to the name of your Traefik docker proxy network - - "traefik.http.routers.to-conduwuit.rule=Host(`.`)" # Change to the address on which Continuwuity is hosted - - "traefik.http.routers.to-conduwuit.tls=true" - - "traefik.http.routers.to-conduwuit.tls.certresolver=letsencrypt" - - "traefik.http.routers.to-conduwuit.middlewares=cors-headers@docker" - - "traefik.http.services.to_conduwuit.loadbalancer.server.port=6167" + - "traefik.http.routers.to-continuwuity.rule=Host(`.`)" # Change to the address on which Continuwuity is hosted + - "traefik.http.routers.to-continuwuity.tls=true" + - "traefik.http.routers.to-continuwuity.tls.certresolver=letsencrypt" + - "traefik.http.routers.to-continuwuity.middlewares=cors-headers@docker" + - "traefik.http.services.to_continuwuity.loadbalancer.server.port=6167" - "traefik.http.middlewares.cors-headers.headers.accessControlAllowOriginList=*" - "traefik.http.middlewares.cors-headers.headers.accessControlAllowHeaders=Origin, X-Requested-With, Content-Type, Accept, Authorization" diff --git a/docs/deploying/docker-compose.with-caddy.yml b/docs/deploying/docker-compose.with-caddy.yml index 9ee98428..3dfc9d85 100644 --- a/docs/deploying/docker-compose.with-caddy.yml +++ b/docs/deploying/docker-compose.with-caddy.yml @@ -25,23 +25,23 @@ services: image: forgejo.ellis.link/continuwuation/continuwuity:latest restart: unless-stopped volumes: - - db:/var/lib/conduwuit + - db:/var/lib/continuwuity - /etc/resolv.conf:/etc/resolv.conf:ro # Use the host's DNS resolver rather than Docker's. - #- ./conduwuit.toml:/etc/conduwuit.toml + #- ./continuwuity.toml:/etc/continuwuity.toml environment: - CONDUWUIT_SERVER_NAME: example.com # EDIT THIS - CONDUWUIT_DATABASE_PATH: /var/lib/conduwuit - CONDUWUIT_PORT: 6167 - CONDUWUIT_MAX_REQUEST_SIZE: 20000000 # in bytes, ~20 MB - CONDUWUIT_ALLOW_REGISTRATION: 'true' - CONDUWUIT_REGISTRATION_TOKEN: 'YOUR_TOKEN' # A registration token is required when registration is allowed. - #CONDUWUIT_YES_I_AM_VERY_VERY_SURE_I_WANT_AN_OPEN_REGISTRATION_SERVER_PRONE_TO_ABUSE: 'true' - CONDUWUIT_ALLOW_FEDERATION: 'true' - CONDUWUIT_ALLOW_CHECK_FOR_UPDATES: 'true' - CONDUWUIT_TRUSTED_SERVERS: '["matrix.org"]' - #CONDUWUIT_LOG: warn,state_res=warn - CONDUWUIT_ADDRESS: 0.0.0.0 - #CONDUWUIT_CONFIG: '/etc/conduwuit.toml' # Uncomment if you mapped config toml above + CONTINUWUITY_SERVER_NAME: example.com # EDIT THIS + CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity + CONTINUWUITY_PORT: 6167 + CONTINUWUITY_MAX_REQUEST_SIZE: 20000000 # in bytes, ~20 MB + CONTINUWUITY_ALLOW_REGISTRATION: 'true' + CONTINUWUITY_REGISTRATION_TOKEN: 'YOUR_TOKEN' # A registration token is required when registration is allowed. + #CONTINUWUITY_YES_I_AM_VERY_VERY_SURE_I_WANT_AN_OPEN_REGISTRATION_SERVER_PRONE_TO_ABUSE: 'true' + CONTINUWUITY_ALLOW_FEDERATION: 'true' + CONTINUWUITY_ALLOW_CHECK_FOR_UPDATES: 'true' + CONTINUWUITY_TRUSTED_SERVERS: '["matrix.org"]' + #CONTINUWUITY_LOG: warn,state_res=warn + CONTINUWUITY_ADDRESS: 0.0.0.0 + #CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above networks: - caddy labels: diff --git a/docs/deploying/docker-compose.with-traefik.yml b/docs/deploying/docker-compose.with-traefik.yml index a45893da..9acc4221 100644 --- a/docs/deploying/docker-compose.with-traefik.yml +++ b/docs/deploying/docker-compose.with-traefik.yml @@ -7,38 +7,38 @@ services: image: forgejo.ellis.link/continuwuation/continuwuity:latest restart: unless-stopped volumes: - - db:/var/lib/conduwuit + - db:/var/lib/continuwuity - /etc/resolv.conf:/etc/resolv.conf:ro # Use the host's DNS resolver rather than Docker's. - #- ./conduwuit.toml:/etc/conduwuit.toml + #- ./continuwuity.toml:/etc/continuwuity.toml networks: - proxy environment: - CONDUWUIT_SERVER_NAME: your.server.name.example # EDIT THIS - CONDUWUIT_TRUSTED_SERVERS: '["matrix.org"]' - CONDUWUIT_ALLOW_REGISTRATION: 'false' # After setting a secure registration token, you can enable this - CONDUWUIT_REGISTRATION_TOKEN: "" # This is a token you can use to register on the server - #CONDUWUIT_REGISTRATION_TOKEN_FILE: "" # Alternatively you can configure a path to a token file to read - CONDUWUIT_ADDRESS: 0.0.0.0 - CONDUWUIT_PORT: 6167 # you need to match this with the traefik load balancer label if you're want to change it - CONDUWUIT_DATABASE_PATH: /var/lib/conduwuit - #CONDUWUIT_CONFIG: '/etc/conduit.toml' # Uncomment if you mapped config toml above + CONTINUWUITY_SERVER_NAME: your.server.name.example # EDIT THIS + CONTINUWUITY_TRUSTED_SERVERS: '["matrix.org"]' + CONTINUWUITY_ALLOW_REGISTRATION: 'false' # After setting a secure registration token, you can enable this + CONTINUWUITY_REGISTRATION_TOKEN: "" # This is a token you can use to register on the server + #CONTINUWUITY_REGISTRATION_TOKEN_FILE: "" # Alternatively you can configure a path to a token file to read + CONTINUWUITY_ADDRESS: 0.0.0.0 + CONTINUWUITY_PORT: 6167 # you need to match this with the traefik load balancer label if you're want to change it + CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity + #CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above ### Uncomment and change values as desired, note that Continuwuity has plenty of config options, so you should check out the example example config too # Available levels are: error, warn, info, debug, trace - more info at: https://docs.rs/env_logger/*/env_logger/#enabling-logging - # CONDUWUIT_LOG: info # default is: "warn,state_res=warn" - # CONDUWUIT_ALLOW_ENCRYPTION: 'true' - # CONDUWUIT_ALLOW_FEDERATION: 'true' - # CONDUWUIT_ALLOW_CHECK_FOR_UPDATES: 'true' - # CONDUWUIT_ALLOW_INCOMING_PRESENCE: true - # CONDUWUIT_ALLOW_OUTGOING_PRESENCE: true - # CONDUWUIT_ALLOW_LOCAL_PRESENCE: true - # CONDUWUIT_WORKERS: 10 - # CONDUWUIT_MAX_REQUEST_SIZE: 20000000 # in bytes, ~20 MB - # CONDUWUIT_NEW_USER_DISPLAYNAME_SUFFIX = "🏳<200d>⚧" + # CONTINUWUITY_LOG: info # default is: "warn,state_res=warn" + # CONTINUWUITY_ALLOW_ENCRYPTION: 'true' + # CONTINUWUITY_ALLOW_FEDERATION: 'true' + # CONTINUWUITY_ALLOW_CHECK_FOR_UPDATES: 'true' + # CONTINUWUITY_ALLOW_INCOMING_PRESENCE: true + # CONTINUWUITY_ALLOW_OUTGOING_PRESENCE: true + # CONTINUWUITY_ALLOW_LOCAL_PRESENCE: true + # CONTINUWUITY_WORKERS: 10 + # CONTINUWUITY_MAX_REQUEST_SIZE: 20000000 # in bytes, ~20 MB + # CONTINUWUITY_NEW_USER_DISPLAYNAME_SUFFIX = "🏳<200d>⚧" - # We need some way to serve the client and server .well-known json. The simplest way is via the CONDUWUIT_WELL_KNOWN - # variable / config option, there are multiple ways to do this, e.g. in the conduwuit.toml file, and in a separate + # We need some way to serve the client and server .well-known json. The simplest way is via the CONTINUWUITY_WELL_KNOWN + # variable / config option, there are multiple ways to do this, e.g. in the continuwuity.toml file, and in a separate # reverse proxy, but since you do not have a reverse proxy and following this guide, this example is included - CONDUWUIT_WELL_KNOWN: | + CONTINUWUITY_WELL_KNOWN: | { client=https://your.server.name.example, server=your.server.name.example:443 diff --git a/docs/deploying/docker-compose.yml b/docs/deploying/docker-compose.yml index 1a3ab811..fbb50e35 100644 --- a/docs/deploying/docker-compose.yml +++ b/docs/deploying/docker-compose.yml @@ -9,22 +9,22 @@ services: ports: - 8448:6167 volumes: - - db:/var/lib/conduwuit - #- ./conduwuit.toml:/etc/conduwuit.toml + - db:/var/lib/continuwuity + #- ./continuwuity.toml:/etc/continuwuity.toml environment: - CONDUWUIT_SERVER_NAME: your.server.name # EDIT THIS - CONDUWUIT_DATABASE_PATH: /var/lib/conduwuit - CONDUWUIT_PORT: 6167 - CONDUWUIT_MAX_REQUEST_SIZE: 20000000 # in bytes, ~20 MB - CONDUWUIT_ALLOW_REGISTRATION: 'true' - CONDUWUIT_REGISTRATION_TOKEN: 'YOUR_TOKEN' # A registration token is required when registration is allowed. - #CONDUWUIT_YES_I_AM_VERY_VERY_SURE_I_WANT_AN_OPEN_REGISTRATION_SERVER_PRONE_TO_ABUSE: 'true' - CONDUWUIT_ALLOW_FEDERATION: 'true' - CONDUWUIT_ALLOW_CHECK_FOR_UPDATES: 'true' - CONDUWUIT_TRUSTED_SERVERS: '["matrix.org"]' - #CONDUWUIT_LOG: warn,state_res=warn - CONDUWUIT_ADDRESS: 0.0.0.0 - #CONDUWUIT_CONFIG: '/etc/conduwuit.toml' # Uncomment if you mapped config toml above + CONTINUWUITY_SERVER_NAME: your.server.name # EDIT THIS + CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity + CONTINUWUITY_PORT: 6167 + CONTINUWUITY_MAX_REQUEST_SIZE: 20000000 # in bytes, ~20 MB + CONTINUWUITY_ALLOW_REGISTRATION: 'true' + CONTINUWUITY_REGISTRATION_TOKEN: 'YOUR_TOKEN' # A registration token is required when registration is allowed. + #CONTINUWUITY_YES_I_AM_VERY_VERY_SURE_I_WANT_AN_OPEN_REGISTRATION_SERVER_PRONE_TO_ABUSE: 'true' + CONTINUWUITY_ALLOW_FEDERATION: 'true' + CONTINUWUITY_ALLOW_CHECK_FOR_UPDATES: 'true' + CONTINUWUITY_TRUSTED_SERVERS: '["matrix.org"]' + #CONTINUWUITY_LOG: warn,state_res=warn + CONTINUWUITY_ADDRESS: 0.0.0.0 + #CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above # ### Uncomment if you want to use your own Element-Web App. ### Note: You need to provide a config.json for Element and you also need a second diff --git a/docs/deploying/docker.md b/docs/deploying/docker.md index 08a0dc4f..051ed89b 100644 --- a/docs/deploying/docker.md +++ b/docs/deploying/docker.md @@ -30,16 +30,16 @@ When you have the image you can simply run it with ```bash docker run -d -p 8448:6167 \ - -v db:/var/lib/conduwuit/ \ - -e CONDUWUIT_SERVER_NAME="your.server.name" \ - -e CONDUWUIT_ALLOW_REGISTRATION=false \ - --name conduwuit $LINK + -v db:/var/lib/continuwuity/ \ + -e CONTINUWUITY_SERVER_NAME="your.server.name" \ + -e CONTINUWUITY_ALLOW_REGISTRATION=false \ + --name continuwuity $LINK ``` or you can use [docker compose](#docker-compose). The `-d` flag lets the container run in detached mode. You may supply an -optional `conduwuit.toml` config file, the example config can be found +optional `continuwuity.toml` config file, the example config can be found [here](../configuration/examples.md). You can pass in different env vars to change config values on the fly. You can even configure Continuwuity completely by using env vars. For an overview of possible values, please take a look at the diff --git a/docs/deploying/generic.md b/docs/deploying/generic.md index 46b9b439..9128f346 100644 --- a/docs/deploying/generic.md +++ b/docs/deploying/generic.md @@ -115,7 +115,7 @@ ReadWritePaths=/path/to/custom/database/path ## Creating the Continuwuity configuration file Now we need to create the Continuwuity's config file in -`/etc/conduwuit/conduwuit.toml`. The example config can be found at +`/etc/continuwuity/continuwuity.toml`. The example config can be found at [conduwuit-example.toml](../configuration/examples.md). **Please take a moment to read the config. You need to change at least the diff --git a/docs/development/hot_reload.md b/docs/development/hot_reload.md index ecfb6396..194ea3bc 100644 --- a/docs/development/hot_reload.md +++ b/docs/development/hot_reload.md @@ -190,7 +190,7 @@ The initial implementation PR is available [here][1]. - [Workspace-level metadata (cargo-deb)](https://github.com/kornelski/cargo-deb/issues/68) -[1]: https://github.com/girlbossceo/conduwuit/pull/387 +[1]: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/387 [2]: https://wiki.musl-libc.org/functional-differences-from-glibc.html#Unloading-libraries [3]: https://github.com/rust-lang/rust/issues/28794 [4]: https://github.com/rust-lang/rust/issues/28794#issuecomment-368693049 diff --git a/docs/development/testing.md b/docs/development/testing.md index a577698a..d28bb874 100644 --- a/docs/development/testing.md +++ b/docs/development/testing.md @@ -24,8 +24,9 @@ and run the script. If you're on macOS and need to build an image, run `nix build .#linux-complement`. We have a Complement fork as some tests have needed to be fixed. This can be found -at: +at: -[ci-workflows]: https://github.com/girlbossceo/conduwuit/actions/workflows/ci.yml?query=event%3Apush+is%3Asuccess+actor%3Agirlbossceo +[ci-workflows]: +https://forgejo.ellis.link/continuwuation/continuwuity/actions/?workflow=ci.yml&actor=0&status=1 [complement]: https://github.com/matrix-org/complement [direnv]: https://direnv.net/docs/hook.html diff --git a/nix/pkgs/oci-image/default.nix b/nix/pkgs/oci-image/default.nix index 1650053d..953407ef 100644 --- a/nix/pkgs/oci-image/default.nix +++ b/nix/pkgs/oci-image/default.nix @@ -33,13 +33,13 @@ dockerTools.buildLayeredImage { "; "org.opencontainers.image.created" ="@${toString inputs.self.lastModified}"; "org.opencontainers.image.description" = "a very cool Matrix chat homeserver written in Rust"; - "org.opencontainers.image.documentation" = "https://conduwuit.puppyirl.gay/"; + "org.opencontainers.image.documentation" = "https://continuwuity.org/"; "org.opencontainers.image.licenses" = "Apache-2.0"; "org.opencontainers.image.revision" = inputs.self.rev or inputs.self.dirtyRev or ""; - "org.opencontainers.image.source" = "https://github.com/girlbossceo/conduwuit"; + "org.opencontainers.image.source" = "https://forgejo.ellis.link/continuwuation/continuwuity"; "org.opencontainers.image.title" = main.pname; - "org.opencontainers.image.url" = "https://conduwuit.puppyirl.gay/"; - "org.opencontainers.image.vendor" = "girlbossceo"; + "org.opencontainers.image.url" = "https://continuwuity.org/"; + "org.opencontainers.image.vendor" = "continuwuation"; "org.opencontainers.image.version" = main.version; }; }; diff --git a/src/admin/processor.rs b/src/admin/processor.rs index 8282a846..f7b7140f 100644 --- a/src/admin/processor.rs +++ b/src/admin/processor.rs @@ -94,7 +94,7 @@ async fn process_command(services: Arc, input: &CommandInput) -> Proce #[allow(clippy::result_large_err)] fn handle_panic(error: &Error, command: &CommandInput) -> ProcessorResult { let link = - "Please submit a [bug report](https://github.com/girlbossceo/conduwuit/issues/new). 🥺"; + "Please submit a [bug report](https://forgejo.ellis.link/continuwuation/continuwuity/issues/new). 🥺"; let msg = format!("Panic occurred while processing command:\n```\n{error:#?}\n```\n{link}"); let content = RoomMessageEventContent::notice_markdown(msg); error!("Panic while processing command: {error:?}"); diff --git a/src/core/config/check.rs b/src/core/config/check.rs index f9d51eeb..ded9533d 100644 --- a/src/core/config/check.rs +++ b/src/core/config/check.rs @@ -118,7 +118,7 @@ pub fn check(config: &Config) -> Result { if cfg!(not(debug_assertions)) && config.server_name == "your.server.name" { return Err!(Config( "server_name", - "You must specify a valid server name for production usage of conduwuit." + "You must specify a valid server name for production usage of continuwuity." )); } @@ -290,7 +290,7 @@ fn warn_deprecated(config: &Config) { if was_deprecated { warn!( - "Read conduwuit config documentation at https://conduwuit.puppyirl.gay/configuration.html and check your \ + "Read continuwuity config documentation at https://continuwuity.org/configuration.html and check your \ configuration if any new configuration parameters should be adjusted" ); } diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 5648a126..66ed0b2e 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -27,7 +27,7 @@ use self::proxy::ProxyConfig; pub use self::{check::check, manager::Manager}; use crate::{Result, err, error::Error, utils::sys}; -/// All the config options for conduwuit. +/// All the config options for continuwuity. #[allow(clippy::struct_excessive_bools)] #[allow(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)] #[derive(Clone, Debug, Deserialize)] @@ -35,7 +35,7 @@ use crate::{Result, err, error::Error, utils::sys}; filename = "conduwuit-example.toml", section = "global", undocumented = "# This item is undocumented. Please contribute documentation for it.", - header = r#"### conduwuit Configuration + header = r#"### continuwuity Configuration ### ### THIS FILE IS GENERATED. CHANGES/CONTRIBUTIONS IN THE REPO WILL BE ### OVERWRITTEN! @@ -50,7 +50,7 @@ use crate::{Result, err, error::Error, utils::sys}; ### that say "YOU NEED TO EDIT THIS". ### ### For more information, see: -### https://conduwuit.puppyirl.gay/configuration.html +### https://continuwuity.org/configuration.html "#, ignore = "catchall well_known tls blurhashing allow_invalid_tls_certificates_yes_i_know_what_the_fuck_i_am_doing_with_this_and_i_know_this_is_insecure" )] @@ -59,7 +59,7 @@ pub struct Config { /// suffix for user and room IDs/aliases. /// /// See the docs for reverse proxying and delegation: - /// https://conduwuit.puppyirl.gay/deploying/generic.html#setting-up-the-reverse-proxy + /// https://continuwuity.org/deploying/generic.html#setting-up-the-reverse-proxy /// /// Also see the `[global.well_known]` config section at the very bottom. /// @@ -70,10 +70,10 @@ pub struct Config { /// YOU NEED TO EDIT THIS. THIS CANNOT BE CHANGED AFTER WITHOUT A DATABASE /// WIPE. /// - /// example: "conduwuit.woof" + /// example: "continuwuity.org" pub server_name: OwnedServerName, - /// The default address (IPv4 or IPv6) conduwuit will listen on. + /// The default address (IPv4 or IPv6) continuwuity will listen on. /// /// If you are using Docker or a container NAT networking setup, this must /// be "0.0.0.0". @@ -85,10 +85,10 @@ pub struct Config { #[serde(default = "default_address")] address: ListeningAddr, - /// The port(s) conduwuit will listen on. + /// The port(s) continuwuity will listen on. /// /// For reverse proxying, see: - /// https://conduwuit.puppyirl.gay/deploying/generic.html#setting-up-the-reverse-proxy + /// https://continuwuity.org/deploying/generic.html#setting-up-the-reverse-proxy /// /// If you are using Docker, don't change this, you'll need to map an /// external port to this. @@ -103,16 +103,17 @@ pub struct Config { #[serde(default)] pub tls: TlsConfig, - /// The UNIX socket conduwuit will listen on. + /// The UNIX socket continuwuity will listen on. /// - /// conduwuit cannot listen on both an IP address and a UNIX socket. If + /// continuwuity cannot listen on both an IP address and a UNIX socket. If /// listening on a UNIX socket, you MUST remove/comment the `address` key. /// /// Remember to make sure that your reverse proxy has access to this socket - /// file, either by adding your reverse proxy to the 'conduwuit' group or - /// granting world R/W permissions with `unix_socket_perms` (666 minimum). + /// file, either by adding your reverse proxy to the appropriate user group + /// or granting world R/W permissions with `unix_socket_perms` (666 + /// minimum). /// - /// example: "/run/conduwuit/conduwuit.sock" + /// example: "/run/continuwuity/continuwuity.sock" pub unix_socket_path: Option, /// The default permissions (in octal) to create the UNIX socket with. @@ -121,22 +122,22 @@ pub struct Config { #[serde(default = "default_unix_socket_perms")] pub unix_socket_perms: u32, - /// This is the only directory where conduwuit will save its data, including - /// media. Note: this was previously "/var/lib/matrix-conduit". + /// This is the only directory where continuwuity will save its data, + /// including media. Note: this was previously "/var/lib/matrix-conduit". /// /// YOU NEED TO EDIT THIS. /// - /// example: "/var/lib/conduwuit" + /// example: "/var/lib/continuwuity" pub database_path: PathBuf, - /// conduwuit supports online database backups using RocksDB's Backup engine - /// API. To use this, set a database backup path that conduwuit can write - /// to. + /// continuwuity supports online database backups using RocksDB's Backup + /// engine API. To use this, set a database backup path that continuwuity + /// can write to. /// /// For more information, see: - /// https://conduwuit.puppyirl.gay/maintenance.html#backups + /// https://continuwuity.org/maintenance.html#backups /// - /// example: "/opt/conduwuit-db-backups" + /// example: "/opt/continuwuity-db-backups" pub database_backup_path: Option, /// The amount of online RocksDB database backups to keep/retain, if using @@ -160,7 +161,7 @@ pub struct Config { #[serde(default = "default_new_user_displayname_suffix")] pub new_user_displayname_suffix: String, - /// If enabled, conduwuit will send a simple GET request periodically to + /// If enabled, continuwuity will send a simple GET request periodically to /// `https://continuwuity.org/.well-known/continuwuity/announcements` for any new /// announcements or major updates. This is not an update check endpoint. /// @@ -168,8 +169,8 @@ pub struct Config { #[serde(alias = "allow_check_for_updates", default = "true_fn")] pub allow_announcements_check: bool, - /// Set this to any float value to multiply conduwuit's in-memory LRU caches - /// with such as "auth_chain_cache_capacity". + /// Set this to any float value to multiply continuwuity's in-memory LRU + /// caches with such as "auth_chain_cache_capacity". /// /// May be useful if you have significant memory to spare to increase /// performance. @@ -186,7 +187,7 @@ pub struct Config { )] pub cache_capacity_modifier: f64, - /// Set this to any float value in megabytes for conduwuit to tell the + /// Set this to any float value in megabytes for continuwuity to tell the /// database engine that this much memory is available for database read /// caches. /// @@ -202,7 +203,7 @@ pub struct Config { #[serde(default = "default_db_cache_capacity_mb")] pub db_cache_capacity_mb: f64, - /// Set this to any float value in megabytes for conduwuit to tell the + /// Set this to any float value in megabytes for continuwuity to tell the /// database engine that this much memory is available for database write /// caches. /// @@ -319,9 +320,9 @@ pub struct Config { /// Enable using *only* TCP for querying your specified nameservers instead /// of UDP. /// - /// If you are running conduwuit in a container environment, this config + /// If you are running continuwuity in a container environment, this config /// option may need to be enabled. For more details, see: - /// https://conduwuit.puppyirl.gay/troubleshooting.html#potential-dns-issues-when-using-docker + /// https://continuwuity.org/troubleshooting.html#potential-dns-issues-when-using-docker #[serde(default)] pub query_over_tcp_only: bool, @@ -534,9 +535,9 @@ pub struct Config { /// tokens. Multiple tokens can be added if you separate them with /// whitespace /// - /// conduwuit must be able to access the file, and it must not be empty + /// continuwuity must be able to access the file, and it must not be empty /// - /// example: "/etc/conduwuit/.reg_token" + /// example: "/etc/continuwuity/.reg_token" pub registration_token_file: Option, /// Controls whether encrypted rooms and events are allowed. @@ -627,16 +628,16 @@ pub struct Config { pub allow_room_creation: bool, /// Set to false to disable users from joining or creating room versions - /// that aren't officially supported by conduwuit. + /// that aren't officially supported by continuwuity. /// - /// conduwuit officially supports room versions 6 - 11. + /// continuwuity officially supports room versions 6 - 11. /// - /// conduwuit has slightly experimental (though works fine in practice) + /// continuwuity has slightly experimental (though works fine in practice) /// support for versions 3 - 5. #[serde(default = "true_fn")] pub allow_unstable_room_versions: bool, - /// Default room version conduwuit will create rooms with. + /// Default room version continuwuity will create rooms with. /// /// Per spec, room version 11 is the default. /// @@ -710,7 +711,7 @@ pub struct Config { /// Servers listed here will be used to gather public keys of other servers /// (notary trusted key servers). /// - /// Currently, conduwuit doesn't support inbound batched key requests, so + /// Currently, continuwuity doesn't support inbound batched key requests, so /// this list should only contain other Synapse servers. /// /// example: ["matrix.org", "tchncs.de"] @@ -755,7 +756,7 @@ pub struct Config { #[serde(default = "default_trusted_server_batch_size")] pub trusted_server_batch_size: usize, - /// Max log level for conduwuit. Allows debug, info, warn, or error. + /// Max log level for continuwuity. Allows debug, info, warn, or error. /// /// See also: /// https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives @@ -780,8 +781,9 @@ pub struct Config { #[serde(default = "default_log_span_events")] pub log_span_events: String, - /// Configures whether CONDUWUIT_LOG EnvFilter matches values using regular - /// expressions. See the tracing_subscriber documentation on Directives. + /// Configures whether CONTINUWUITY_LOG EnvFilter matches values using + /// regular expressions. See the tracing_subscriber documentation on + /// Directives. /// /// default: true #[serde(default = "true_fn")] @@ -863,7 +865,7 @@ pub struct Config { /// This takes priority over "turn_secret" first, and falls back to /// "turn_secret" if invalid or failed to open. /// - /// example: "/etc/conduwuit/.turn_secret" + /// example: "/etc/continuwuity/.turn_secret" pub turn_secret_file: Option, /// TURN TTL, in seconds. @@ -872,12 +874,12 @@ pub struct Config { #[serde(default = "default_turn_ttl")] pub turn_ttl: u64, - /// List/vector of room IDs or room aliases that conduwuit will make newly - /// registered users join. The rooms specified must be rooms that you have - /// joined at least once on the server, and must be public. + /// List/vector of room IDs or room aliases that continuwuity will make + /// newly registered users join. The rooms specified must be rooms that you + /// have joined at least once on the server, and must be public. /// - /// example: ["#conduwuit:puppygock.gay", - /// "!eoIzvAvVwY23LPDay8:puppygock.gay"] + /// example: ["#continuwuity:continuwuity.org", + /// "!main-1:continuwuity.org"] /// /// default: [] #[serde(default = "Vec::new")] @@ -902,10 +904,10 @@ pub struct Config { #[serde(default)] pub auto_deactivate_banned_room_attempts: bool, - /// RocksDB log level. This is not the same as conduwuit's log level. This - /// is the log level for the RocksDB engine/library which show up in your - /// database folder/path as `LOG` files. conduwuit will log RocksDB errors - /// as normal through tracing or panics if severe for safety. + /// RocksDB log level. This is not the same as continuwuity's log level. + /// This is the log level for the RocksDB engine/library which show up in + /// your database folder/path as `LOG` files. continuwuity will log RocksDB + /// errors as normal through tracing or panics if severe for safety. /// /// default: "error" #[serde(default = "default_rocksdb_log_level")] @@ -930,7 +932,7 @@ pub struct Config { /// Set this to true to use RocksDB config options that are tailored to HDDs /// (slower device storage). /// - /// It is worth noting that by default, conduwuit will use RocksDB with + /// It is worth noting that by default, continuwuity will use RocksDB with /// Direct IO enabled. *Generally* speaking this improves performance as it /// bypasses buffered I/O (system page cache). However there is a potential /// chance that Direct IO may cause issues with database operations if your @@ -938,7 +940,7 @@ pub struct Config { /// possibly ZFS filesystem. RocksDB generally deals/corrects these issues /// but it cannot account for all setups. If you experience any weird /// RocksDB issues, try enabling this option as it turns off Direct IO and - /// feel free to report in the conduwuit Matrix room if this option fixes + /// feel free to report in the continuwuity Matrix room if this option fixes /// your DB issues. /// /// For more information, see: @@ -999,7 +1001,7 @@ pub struct Config { /// as they all differ. See their `kDefaultCompressionLevel`. /// /// Note when using the default value we may override it with a setting - /// tailored specifically conduwuit. + /// tailored specifically for continuwuity. /// /// default: 32767 #[serde(default = "default_rocksdb_compression_level")] @@ -1017,7 +1019,7 @@ pub struct Config { /// algorithm. /// /// Note when using the default value we may override it with a setting - /// tailored specifically conduwuit. + /// tailored specifically for continuwuity. /// /// default: 32767 #[serde(default = "default_rocksdb_bottommost_compression_level")] @@ -1059,13 +1061,13 @@ pub struct Config { /// 0 = AbsoluteConsistency /// 1 = TolerateCorruptedTailRecords (default) /// 2 = PointInTime (use me if trying to recover) - /// 3 = SkipAnyCorruptedRecord (you now voided your Conduwuit warranty) + /// 3 = SkipAnyCorruptedRecord (you now voided your Continuwuity warranty) /// /// For more information on these modes, see: /// https://github.com/facebook/rocksdb/wiki/WAL-Recovery-Modes /// /// For more details on recovering a corrupt database, see: - /// https://conduwuit.puppyirl.gay/troubleshooting.html#database-corruption + /// https://continuwuity.org/troubleshooting.html#database-corruption /// /// default: 1 #[serde(default = "default_rocksdb_recovery_mode")] @@ -1109,7 +1111,7 @@ pub struct Config { /// - Disabling repair mode and restarting the server is recommended after /// running the repair. /// - /// See https://conduwuit.puppyirl.gay/troubleshooting.html#database-corruption for more details on recovering a corrupt database. + /// See https://continuwuity.org/troubleshooting.html#database-corruption for more details on recovering a corrupt database. #[serde(default)] pub rocksdb_repair: bool, @@ -1134,7 +1136,7 @@ pub struct Config { /// Enables RocksDB compaction. You should never ever have to set this /// option to false. If you for some reason find yourself needing to use /// this option as part of troubleshooting or a bug, please reach out to us - /// in the conduwuit Matrix room with information and details. + /// in the continuwuity Matrix room with information and details. /// /// Disabling compaction will lead to a significantly bloated and /// explosively large database, gradually poor performance, unnecessarily @@ -1162,7 +1164,7 @@ pub struct Config { /// purposes such as recovering/recreating your admin room, or inviting /// yourself back. /// - /// See https://conduwuit.puppyirl.gay/troubleshooting.html#lost-access-to-admin-room for other ways to get back into your admin room. + /// See https://continuwuity.org/troubleshooting.html#lost-access-to-admin-room for other ways to get back into your admin room. /// /// Once this password is unset, all sessions will be logged out for /// security purposes. @@ -1178,8 +1180,8 @@ pub struct Config { /// Allow local (your server only) presence updates/requests. /// - /// Note that presence on conduwuit is very fast unlike Synapse's. If using - /// outgoing presence, this MUST be enabled. + /// Note that presence on continuwuity is very fast unlike Synapse's. If + /// using outgoing presence, this MUST be enabled. #[serde(default = "true_fn")] pub allow_local_presence: bool, @@ -1187,7 +1189,7 @@ pub struct Config { /// /// This option receives presence updates from other servers, but does not /// send any unless `allow_outgoing_presence` is true. Note that presence on - /// conduwuit is very fast unlike Synapse's. + /// continuwuity is very fast unlike Synapse's. #[serde(default = "true_fn")] pub allow_incoming_presence: bool, @@ -1195,8 +1197,8 @@ pub struct Config { /// /// This option sends presence updates to other servers, but does not /// receive any unless `allow_incoming_presence` is true. Note that presence - /// on conduwuit is very fast unlike Synapse's. If using outgoing presence, - /// you MUST enable `allow_local_presence` as well. + /// on continuwuity is very fast unlike Synapse's. If using outgoing + /// presence, you MUST enable `allow_local_presence` as well. #[serde(default = "true_fn")] pub allow_outgoing_presence: bool, @@ -1259,8 +1261,8 @@ pub struct Config { #[serde(default = "default_typing_client_timeout_max_s")] pub typing_client_timeout_max_s: u64, - /// Set this to true for conduwuit to compress HTTP response bodies using - /// zstd. This option does nothing if conduwuit was not built with + /// Set this to true for continuwuity to compress HTTP response bodies using + /// zstd. This option does nothing if continuwuity was not built with /// `zstd_compression` feature. Please be aware that enabling HTTP /// compression may weaken TLS. Most users should not need to enable this. /// See https://breachattack.com/ and https://wikipedia.org/wiki/BREACH @@ -1268,8 +1270,8 @@ pub struct Config { #[serde(default)] pub zstd_compression: bool, - /// Set this to true for conduwuit to compress HTTP response bodies using - /// gzip. This option does nothing if conduwuit was not built with + /// Set this to true for continuwuity to compress HTTP response bodies using + /// gzip. This option does nothing if continuwuity was not built with /// `gzip_compression` feature. Please be aware that enabling HTTP /// compression may weaken TLS. Most users should not need to enable this. /// See https://breachattack.com/ and https://wikipedia.org/wiki/BREACH before @@ -1280,8 +1282,8 @@ pub struct Config { #[serde(default)] pub gzip_compression: bool, - /// Set this to true for conduwuit to compress HTTP response bodies using - /// brotli. This option does nothing if conduwuit was not built with + /// Set this to true for continuwuity to compress HTTP response bodies using + /// brotli. This option does nothing if continuwuity was not built with /// `brotli_compression` feature. Please be aware that enabling HTTP /// compression may weaken TLS. Most users should not need to enable this. /// See https://breachattack.com/ and https://wikipedia.org/wiki/BREACH @@ -1342,7 +1344,7 @@ pub struct Config { /// Otherwise setting this to false reduces filesystem clutter and overhead /// for managing these symlinks in the directory. This is now disabled by /// default. You may still return to upstream Conduit but you have to run - /// conduwuit at least once with this set to true and allow the + /// continuwuity at least once with this set to true and allow the /// media_startup_check to take place before shutting down to return to /// Conduit. #[serde(default)] @@ -1391,8 +1393,8 @@ pub struct Config { #[serde(default, with = "serde_regex")] pub allowed_remote_server_names: RegexSet, - /// Vector list of regex patterns of server names that conduwuit will refuse - /// to download remote media from. + /// Vector list of regex patterns of server names that continuwuity will + /// refuse to download remote media from. /// /// example: ["badserver\.tld$", "badphrase", "19dollarfortnitecards"] /// @@ -1410,7 +1412,7 @@ pub struct Config { #[serde(default, with = "serde_regex")] pub forbidden_remote_room_directory_server_names: RegexSet, - /// Vector list of regex patterns of server names that conduwuit will not + /// Vector list of regex patterns of server names that continuwuity will not /// send messages to the client from. /// /// Note that there is no way for clients to receive messages once a server @@ -1436,7 +1438,7 @@ pub struct Config { pub send_messages_from_ignored_users_to_client: bool, /// Vector list of IPv4 and IPv6 CIDR ranges / subnets *in quotes* that you - /// do not want conduwuit to send outbound requests to. Defaults to + /// do not want continuwuity to send outbound requests to. Defaults to /// RFC1918, unroutable, loopback, multicast, and testnet addresses for /// security. /// @@ -1604,26 +1606,26 @@ pub struct Config { /// Allow admins to enter commands in rooms other than "#admins" (admin /// room) by prefixing your message with "\!admin" or "\\!admin" followed up - /// a normal conduwuit admin command. The reply will be publicly visible to - /// the room, originating from the sender. + /// a normal continuwuity admin command. The reply will be publicly visible + /// to the room, originating from the sender. /// /// example: \\!admin debug ping puppygock.gay #[serde(default = "true_fn")] pub admin_escape_commands: bool, - /// Automatically activate the conduwuit admin room console / CLI on - /// startup. This option can also be enabled with `--console` conduwuit + /// Automatically activate the continuwuity admin room console / CLI on + /// startup. This option can also be enabled with `--console` continuwuity /// argument. #[serde(default)] pub admin_console_automatic: bool, /// List of admin commands to execute on startup. /// - /// This option can also be configured with the `--execute` conduwuit + /// This option can also be configured with the `--execute` continuwuity /// argument and can take standard shell commands and environment variables /// - /// For example: `./conduwuit --execute "server admin-notice conduwuit has - /// started up at $(date)"` + /// For example: `./continuwuity --execute "server admin-notice continuwuity + /// has started up at $(date)"` /// /// example: admin_execute = ["debug ping puppygock.gay", "debug echo hi"]` /// @@ -1633,7 +1635,7 @@ pub struct Config { /// Ignore errors in startup commands. /// - /// If false, conduwuit will error and fail to start if an admin execute + /// If false, continuwuity will error and fail to start if an admin execute /// command (`--execute` / `admin_execute`) fails. #[serde(default)] pub admin_execute_errors_ignore: bool, @@ -1658,17 +1660,16 @@ pub struct Config { /// The default room tag to apply on the admin room. /// /// On some clients like Element, the room tag "m.server_notice" is a - /// special pinned room at the very bottom of your room list. The conduwuit - /// admin room can be pinned here so you always have an easy-to-access - /// shortcut dedicated to your admin room. + /// special pinned room at the very bottom of your room list. The + /// continuwuity admin room can be pinned here so you always have an + /// easy-to-access shortcut dedicated to your admin room. /// /// default: "m.server_notice" #[serde(default = "default_admin_room_tag")] pub admin_room_tag: String, /// Sentry.io crash/panic reporting, performance monitoring/metrics, etc. - /// This is NOT enabled by default. conduwuit's default Sentry reporting - /// endpoint domain is `o4506996327251968.ingest.us.sentry.io`. + /// This is NOT enabled by default. #[serde(default)] pub sentry: bool, @@ -1679,7 +1680,7 @@ pub struct Config { #[serde(default = "default_sentry_endpoint")] pub sentry_endpoint: Option, - /// Report your conduwuit server_name in Sentry.io crash reports and + /// Report your continuwuity server_name in Sentry.io crash reports and /// metrics. #[serde(default)] pub sentry_send_server_name: bool, @@ -1720,7 +1721,7 @@ pub struct Config { /// Enable the tokio-console. This option is only relevant to developers. /// /// For more information, see: - /// https://conduwuit.puppyirl.gay/development.html#debugging-with-tokio-console + /// https://continuwuity.org/development.html#debugging-with-tokio-console #[serde(default)] pub tokio_console: bool, diff --git a/src/service/admin/create.rs b/src/service/admin/create.rs index cd0fc5a9..157b4d65 100644 --- a/src/service/admin/create.rs +++ b/src/service/admin/create.rs @@ -165,7 +165,7 @@ pub async fn create_admin_room(services: &Services) -> Result { .timeline .build_and_append_pdu( PduBuilder::state(String::new(), &RoomTopicEventContent { - topic: format!("Manage {} | Run commands prefixed with `!admin` | Run `!admin -h` for help | Documentation: https://conduwuit.puppyirl.gay/", services.config.server_name), + topic: format!("Manage {} | Run commands prefixed with `!admin` | Run `!admin -h` for help | Documentation: https://continuwuity.org/", services.config.server_name), }), server_user, &room_id, From 066794fe90c4af11c5c4ae5ce55d7db2fe6cf2da Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 11 May 2025 17:15:37 +0100 Subject: [PATCH 1981/2291] ci: Don't try build images on PR --- .forgejo/workflows/release-image.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 704a3bbf..1c7457a5 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -3,7 +3,6 @@ concurrency: group: "release-image-${{ github.ref }}" on: - pull_request: push: paths-ignore: - "*.md" From d03325c65a6749669924c0a66b98795fe8babf26 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 11 May 2025 17:27:54 +0100 Subject: [PATCH 1982/2291] chore: Set editorconfig for workflows --- .editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.editorconfig b/.editorconfig index 2d7438a4..91f073bd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -22,3 +22,7 @@ indent_size = 2 [*.rs] indent_style = tab max_line_length = 98 + +[{.forgejo/**/*.yml,.github/**/*.yml}] +indent_size = 2 +indent_style = space From f14725a51b9be2b6fb6fda597e57afe770e4cdca Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 11 May 2025 17:42:57 +0100 Subject: [PATCH 1983/2291] ci: Check formatting Also moves rustup installation to a seperate workflow and enables caching. The sccache action required a github.com api token, so we set all that up too. --- .forgejo/actions/rust-toolchain/action.yml | 45 ++++++++++++++++++++++ .forgejo/actions/sccache/action.yml | 29 ++++++++++++++ .forgejo/workflows/formatting.yml | 44 +++++++++++++++++++++ .forgejo/workflows/release-image.yml | 7 +--- 4 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 .forgejo/actions/rust-toolchain/action.yml create mode 100644 .forgejo/actions/sccache/action.yml create mode 100644 .forgejo/workflows/formatting.yml diff --git a/.forgejo/actions/rust-toolchain/action.yml b/.forgejo/actions/rust-toolchain/action.yml new file mode 100644 index 00000000..68f59d00 --- /dev/null +++ b/.forgejo/actions/rust-toolchain/action.yml @@ -0,0 +1,45 @@ +name: rust-toolchain +description: | + Install a Rust toolchain using rustup. + See https://rust-lang.github.io/rustup/concepts/toolchains.html#toolchain-specification + for more information about toolchains. +inputs: + toolchain: + description: | + Rust toolchain name. + See https://rust-lang.github.io/rustup/concepts/toolchains.html#toolchain-specification + required: false + target: + description: Target triple to install for this toolchain + required: false + components: + description: Space-separated list of components to be additionally installed for a new toolchain + required: false + +runs: + using: composite + steps: + - name: Cache rustup toolchains + uses: actions/cache@v3 + with: + path: | + ~/.rustup + !~/.rustup/tmp + !~/.rustup/downloads + # Requires repo to be cloned if toolchain is not specified + key: ${{ runner.os }}-rustup-${{ inputs.toolchain || hashFiles('**/rust-toolchain.toml') }} + - name: Install Rust toolchain + shell: bash + run: | + if ! command -v rustup &> /dev/null ; then + curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y + echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH + fi + - shell: bash + run: | + set -x + ${{ inputs.toolchain && format('rustup override set {0}', inputs.toolchain) }} + ${{ inputs.target && format('rustup target add {0}', inputs.target) }} + ${{ inputs.components && format('rustup component add {0}', inputs.components) }} + cargo --version + rustc --version diff --git a/.forgejo/actions/sccache/action.yml b/.forgejo/actions/sccache/action.yml new file mode 100644 index 00000000..b5e5dcf4 --- /dev/null +++ b/.forgejo/actions/sccache/action.yml @@ -0,0 +1,29 @@ +name: sccache +description: | + Install sccache for caching builds in GitHub Actions. + +inputs: + token: + description: 'A Github PAT' + required: false + +runs: + using: composite + steps: + - name: Install sccache + uses: https://github.com/mozilla-actions/sccache-action@v0.0.9 + with: + token: ${{ inputs.token }} + - name: Configure sccache + uses: https://github.com/actions/github-script@v7 + with: + script: | + core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + - shell: bash + run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CMAKE_C_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV + echo "CMAKE_CXX_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV + echo "CMAKE_CUDA_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV diff --git a/.forgejo/workflows/formatting.yml b/.forgejo/workflows/formatting.yml new file mode 100644 index 00000000..e51560e7 --- /dev/null +++ b/.forgejo/workflows/formatting.yml @@ -0,0 +1,44 @@ +name: Rust Formatting + +on: + push: + pull_request: + +jobs: + format: + name: Format + runs-on: ubuntu-latest + env: + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Install rust + uses: ./.forgejo/actions/rust-toolchain + with: + toolchain: "nightly" + components: "rustfmt" + + - uses: https://github.com/actions/create-github-app-token@v2 + id: app-token + with: + app-id: ${{ vars.GH_APP_ID }} + private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} + github-api-url: https://api.github.com + owner: ${{ vars.GH_APP_OWNER }} + repositories: "" + - name: Install sccache + uses: ./.forgejo/actions/sccache + with: + token: ${{ steps.app-token.outputs.token }} + - name: Check formatting + run: | + cargo +nightly fmt --all -- --check + + - name: Show sccache stats + run: sccache --show-stats diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 1c7457a5..f6064617 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -79,16 +79,13 @@ jobs: run: echo '${{ toJSON(fromJSON(needs.define-variables.outputs.build_matrix)) }}' - name: Echo matrix run: echo '${{ toJSON(matrix) }}' - - run: | - if ! command -v rustup &> /dev/null ; then - curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y - echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH - fi - name: Checkout repository uses: actions/checkout@v4 with: persist-credentials: false + - name: Install rust + uses: ./.forgejo/actions/rust-toolchain - name: Cache timelord-cli installation id: cache-timelord-bin From ec08e16b9f6e01f356a3a32890742a293b9ecbd4 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 11 May 2025 19:39:44 +0100 Subject: [PATCH 1984/2291] build: Allow builder to decide on incremental or not --- Cargo.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 79f767a2..249ff84c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -745,7 +745,6 @@ incremental = true [profile.dev.package.conduwuit_core] inherits = "dev" -incremental = false #rustflags = [ # '--cfg', 'conduwuit_mods', # '-Ztime-passes', @@ -785,7 +784,6 @@ inherits = "dev" [profile.dev.package.'*'] inherits = "dev" debug = 'limited' -incremental = false codegen-units = 1 opt-level = 'z' #rustflags = [ @@ -807,7 +805,6 @@ inherits = "dev" strip = false opt-level = 0 codegen-units = 16 -incremental = false [profile.test.package.'*'] inherits = "dev" @@ -815,7 +812,6 @@ debug = 0 strip = false opt-level = 0 codegen-units = 16 -incremental = false ############################################################################### # From c5db43ba9aef530e02f0b6048eaa4a95662a8396 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 11 May 2025 19:43:51 +0100 Subject: [PATCH 1985/2291] chore: Docker ignore forgejo files --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index 8ca2e3f8..5054844f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -15,6 +15,7 @@ docker/ .gitea .gitlab .github +.forgejo # Dot files .env From e31d261e668259eacd2c11799d927b3e78354b16 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 11 May 2025 19:43:56 +0100 Subject: [PATCH 1986/2291] ci: Run clippy check --- .forgejo/workflows/formatting.yml | 39 +++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/.forgejo/workflows/formatting.yml b/.forgejo/workflows/formatting.yml index e51560e7..332f98e2 100644 --- a/.forgejo/workflows/formatting.yml +++ b/.forgejo/workflows/formatting.yml @@ -1,29 +1,43 @@ name: Rust Formatting on: - push: - pull_request: + push: + pull_request: jobs: format: name: Format runs-on: ubuntu-latest - env: - SCCACHE_GHA_ENABLED: "true" - RUSTC_WRAPPER: "sccache" steps: - name: Checkout repository uses: actions/checkout@v4 with: persist-credentials: false - + - name: Install rust uses: ./.forgejo/actions/rust-toolchain with: toolchain: "nightly" components: "rustfmt" + - name: Check formatting + run: | + cargo +nightly fmt --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Install rust + uses: ./.forgejo/actions/rust-toolchain + - uses: https://github.com/actions/create-github-app-token@v2 id: app-token with: @@ -36,9 +50,20 @@ jobs: uses: ./.forgejo/actions/sccache with: token: ${{ steps.app-token.outputs.token }} + - run: sudo apt-get update + - name: Install system dependencies + uses: https://github.com/awalsh128/cache-apt-pkgs-action@v1 + with: + packages: clang liburing-dev + version: 1 - name: Check formatting run: | - cargo +nightly fmt --all -- --check + cargo clippy \ + --workspace \ + --locked \ + --profile test \ + -- \ + -D warnings - name: Show sccache stats run: sccache --show-stats From 034762c6197bc48f4515ae63966fbd1849b2cccd Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 11 May 2025 20:03:14 +0100 Subject: [PATCH 1987/2291] chore: Allow raw string hashes for metadata crate --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 249ff84c..1abff107 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -988,3 +988,6 @@ let_underscore_future = { level = "allow", priority = 1 } # rust doesnt understand conduwuit's custom log macros literal_string_with_formatting_args = { level = "allow", priority = 1 } + + +needless_raw_string_hashes = "allow" From e200a7d991ccec06282360d4e6dccd6b08e23663 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 11 May 2025 20:23:30 +0100 Subject: [PATCH 1988/2291] ci: Cache Rust registry --- .forgejo/workflows/formatting.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.forgejo/workflows/formatting.yml b/.forgejo/workflows/formatting.yml index 332f98e2..7ca327b6 100644 --- a/.forgejo/workflows/formatting.yml +++ b/.forgejo/workflows/formatting.yml @@ -56,6 +56,15 @@ jobs: with: packages: clang liburing-dev version: 1 + - name: Cache Rust registry + uses: actions/cache@v3 + with: + path: | + ~/.cargo/git + !~/.cargo/git/checkouts + ~/.cargo/registry + !~/.cargo/registry/src + key: rust-registry-${{hashFiles('**/Cargo.lock') }} - name: Check formatting run: | cargo clippy \ From b5d2ef9a4a7758bc74d3a91cec9b5fc8cf9055f7 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 11 May 2025 20:34:22 +0100 Subject: [PATCH 1989/2291] ci: Refactor timelord to its own action --- .forgejo/actions/timelord/action.yml | 46 ++++++++++++++++++++++++++++ .forgejo/workflows/release-image.yml | 26 +++------------- 2 files changed, 50 insertions(+), 22 deletions(-) create mode 100644 .forgejo/actions/timelord/action.yml diff --git a/.forgejo/actions/timelord/action.yml b/.forgejo/actions/timelord/action.yml new file mode 100644 index 00000000..bb9766d5 --- /dev/null +++ b/.forgejo/actions/timelord/action.yml @@ -0,0 +1,46 @@ +name: timelord +description: | + Use timelord to set file timestamps +inputs: + key: + description: | + The key to use for caching the timelord data. + This should be unique to the repository and the runner. + required: true + default: timelord-v0 + path: + description: | + The path to the directory to be timestamped. + This should be the root of the repository. + required: true + default: . + +runs: + using: composite + steps: + - name: Cache timelord-cli installation + id: cache-timelord-bin + uses: actions/cache@v3 + with: + path: ~/.cargo/bin/timelord + key: timelord-cli-v3.0.1 + - name: Install timelord-cli + uses: https://github.com/cargo-bins/cargo-binstall@main + if: steps.cache-timelord-bin.outputs.cache-hit != 'true' + - run: cargo binstall timelord-cli@3.0.1 + shell: bash + if: steps.cache-timelord-bin.outputs.cache-hit != 'true' + + - name: Load timelord files + uses: actions/cache/restore@v3 + with: + path: /timelord/ + key: ${{ inputs.key }} + - name: Run timelord to set timestamps + shell: bash + run: timelord sync --source-dir ${{ inputs.path }} --cache-dir /timelord/ + - name: Save timelord + uses: actions/cache/save@v3 + with: + path: /timelord/ + key: ${{ inputs.key }} diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index f6064617..0735fec7 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -87,18 +87,6 @@ jobs: - name: Install rust uses: ./.forgejo/actions/rust-toolchain - - name: Cache timelord-cli installation - id: cache-timelord-bin - uses: actions/cache@v3 - with: - path: ~/.cargo/bin/timelord - key: timelord-cli-v3.0.1 - - name: Install timelord-cli - uses: https://github.com/cargo-bins/cargo-binstall@main - if: steps.cache-timelord-bin.outputs.cache-hit != 'true' - - run: cargo binstall timelord-cli@3.0.1 - if: steps.cache-timelord-bin.outputs.cache-hit != 'true' - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Set up QEMU @@ -132,18 +120,12 @@ jobs: echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV - name: Get Git commit timestamps run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV - - name: Set up timelord - uses: actions/cache/restore@v3 + + - uses: ./.forgejo/actions/timelord with: - path: /timelord/ - key: timelord-v0 # Cache is already split per runner - - name: Run timelord to set timestamps - run: timelord sync --source-dir . --cache-dir /timelord/ - - name: Save timelord - uses: actions/cache/save@v3 - with: - path: /timelord/ key: timelord-v0 + path: . + - name: Build and push Docker image by digest id: build uses: docker/build-push-action@v6 From a325dfa56aa1f3a638b9fc6b760befa8ac780952 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 11 May 2025 20:39:50 +0100 Subject: [PATCH 1990/2291] ci: Use timelord in clippy check --- .forgejo/workflows/formatting.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.forgejo/workflows/formatting.yml b/.forgejo/workflows/formatting.yml index 7ca327b6..2f513b91 100644 --- a/.forgejo/workflows/formatting.yml +++ b/.forgejo/workflows/formatting.yml @@ -65,7 +65,11 @@ jobs: ~/.cargo/registry !~/.cargo/registry/src key: rust-registry-${{hashFiles('**/Cargo.lock') }} - - name: Check formatting + - uses: ./.forgejo/actions/timelord + with: + key: sccache-v0 + path: . + - name: Clippy run: | cargo clippy \ --workspace \ @@ -75,4 +79,4 @@ jobs: -D warnings - name: Show sccache stats - run: sccache --show-stats + run: sccache --show-stats \ No newline at end of file From 1f57508879fd6bea3eec8068d0a11882943c18b1 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 20 May 2025 21:15:32 +0100 Subject: [PATCH 1991/2291] ci: Don't clippy check dependancies --- .forgejo/workflows/{formatting.yml => rust-checks.yml} | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) rename .forgejo/workflows/{formatting.yml => rust-checks.yml} (94%) diff --git a/.forgejo/workflows/formatting.yml b/.forgejo/workflows/rust-checks.yml similarity index 94% rename from .forgejo/workflows/formatting.yml rename to .forgejo/workflows/rust-checks.yml index 2f513b91..eef3bd0a 100644 --- a/.forgejo/workflows/formatting.yml +++ b/.forgejo/workflows/rust-checks.yml @@ -1,8 +1,7 @@ -name: Rust Formatting +name: Rust Checks on: push: - pull_request: jobs: format: @@ -65,7 +64,8 @@ jobs: ~/.cargo/registry !~/.cargo/registry/src key: rust-registry-${{hashFiles('**/Cargo.lock') }} - - uses: ./.forgejo/actions/timelord + - name: Timelord + uses: ./.forgejo/actions/timelord with: key: sccache-v0 path: . @@ -74,6 +74,7 @@ jobs: cargo clippy \ --workspace \ --locked \ + --no-deps \ --profile test \ -- \ -D warnings From a4ad72e11ddce01d64aa5e2e3a002c45f9c5b767 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 20 May 2025 21:17:11 +0100 Subject: [PATCH 1992/2291] ci: Run `cargo test` --- .forgejo/workflows/rust-checks.yml | 59 +++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/.forgejo/workflows/rust-checks.yml b/.forgejo/workflows/rust-checks.yml index eef3bd0a..1feb9e89 100644 --- a/.forgejo/workflows/rust-checks.yml +++ b/.forgejo/workflows/rust-checks.yml @@ -80,4 +80,61 @@ jobs: -D warnings - name: Show sccache stats - run: sccache --show-stats \ No newline at end of file + run: sccache --show-stats + + cargo-test: + name: Cargo Test + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Install rust + uses: ./.forgejo/actions/rust-toolchain + + - uses: https://github.com/actions/create-github-app-token@v2 + id: app-token + with: + app-id: ${{ vars.GH_APP_ID }} + private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} + github-api-url: https://api.github.com + owner: ${{ vars.GH_APP_OWNER }} + repositories: "" + - name: Install sccache + uses: ./.forgejo/actions/sccache + with: + token: ${{ steps.app-token.outputs.token }} + - run: sudo apt-get update + - name: Install system dependencies + uses: https://github.com/awalsh128/cache-apt-pkgs-action@v1 + with: + packages: clang liburing-dev + version: 1 + - name: Cache Rust registry + uses: actions/cache@v3 + with: + path: | + ~/.cargo/git + !~/.cargo/git/checkouts + ~/.cargo/registry + !~/.cargo/registry/src + key: rust-registry-${{hashFiles('**/Cargo.lock') }} + - name: Timelord + uses: ./.forgejo/actions/timelord + with: + key: sccache-v0 + path: . + - name: Cargo Test + run: | + cargo test \ + --workspace \ + --locked \ + --profile test \ + --all-targets \ + --no-fail-fast + + - name: Show sccache stats + run: sccache --show-stats From 4ed04b343a8c8c95ffb83cd7b35bc0c1601c36c5 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 20 May 2025 22:13:13 +0100 Subject: [PATCH 1993/2291] build: Use xtrace in bash scripts in Dockerfile --- docker/Dockerfile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 3029282f..44e74180 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -18,13 +18,14 @@ ARG LLVM_VERSION=19 # Line three: for xx-verify RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked \ -apt-get update && apt-get install -y \ + apt-get update && apt-get install -y \ clang-${LLVM_VERSION} lld-${LLVM_VERSION} pkg-config make jq \ curl git \ file # Create symlinks for LLVM tools RUN <> /etc/environment # Configure pkg-config RUN <> /etc/environment echo "PKG_CONFIG=/usr/bin/$(xx-info)-pkg-config" >> /etc/environment echo "PKG_CONFIG_ALLOW_CROSS=true" >> /etc/environment @@ -82,12 +85,14 @@ EOF # Configure cc to use clang version RUN <> /etc/environment echo "CXX=clang++" >> /etc/environment EOF # Cross-language LTO RUN <> /etc/environment echo "CXXFLAGS=-flto" >> /etc/environment # Linker is set to target-compatible clang by xx @@ -98,6 +103,7 @@ EOF ARG TARGET_CPU= RUN <> /etc/environment @@ -118,7 +124,6 @@ COPY . . ARG TARGETPLATFORM # Verify environment configuration -RUN cat /etc/environment RUN xx-cargo --print-target-triple # Conduwuit version info @@ -142,6 +147,7 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/app/target \ bash <<'EOF' set -o allexport + set -o xtrace . /etc/environment TARGET_DIR=($(cargo metadata --no-deps --format-version 1 | \ jq -r ".target_directory")) @@ -162,6 +168,7 @@ EOF RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git/db \ bash <<'EOF' + set -o xtrace mkdir /out/sbom typeset -A PACKAGES for BINARY in /out/sbin/*; do @@ -180,6 +187,7 @@ EOF # Extract dynamically linked dependencies RUN < Date: Tue, 20 May 2025 22:47:55 +0100 Subject: [PATCH 1994/2291] build: Split docker target cache by target platform --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 44e74180..e734fb81 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -144,7 +144,7 @@ ENV CONTINUWUITY_VERSION_EXTRA=$CONTINUWUITY_VERSION_EXTRA # Build the binary RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git/db \ - --mount=type=cache,target=/app/target \ + --mount=type=cache,target=/app/target,id=cargo-target-${TARGETPLATFORM} \ bash <<'EOF' set -o allexport set -o xtrace From 7a46563f23c1e4527310c400b604707c2213e498 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 20 May 2025 22:56:51 +0100 Subject: [PATCH 1995/2291] ci: Cache docker image build mounts --- .forgejo/actions/rust-toolchain/action.yml | 8 ++++ .forgejo/workflows/release-image.yml | 49 +++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/.forgejo/actions/rust-toolchain/action.yml b/.forgejo/actions/rust-toolchain/action.yml index 68f59d00..71fb96f5 100644 --- a/.forgejo/actions/rust-toolchain/action.yml +++ b/.forgejo/actions/rust-toolchain/action.yml @@ -15,6 +15,10 @@ inputs: components: description: Space-separated list of components to be additionally installed for a new toolchain required: false +outputs: + rustc_version: + description: The rustc version installed + value: ${{ steps.rustc-version.outputs.version }} runs: using: composite @@ -43,3 +47,7 @@ runs: ${{ inputs.components && format('rustup component add {0}', inputs.components) }} cargo --version rustc --version + - id: rustc-version + shell: bash + run: | + echo "version=$(rustc --version)" >> $GITHUB_OUTPUT diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 0735fec7..ec466c58 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -79,12 +79,13 @@ jobs: run: echo '${{ toJSON(fromJSON(needs.define-variables.outputs.build_matrix)) }}' - name: Echo matrix run: echo '${{ toJSON(matrix) }}' - + - name: Checkout repository uses: actions/checkout@v4 with: persist-credentials: false - name: Install rust + id: rust-toolchain uses: ./.forgejo/actions/rust-toolchain - name: Set up Docker Buildx @@ -126,6 +127,52 @@ jobs: key: timelord-v0 path: . + - name: Cache Rust registry + uses: actions/cache@v3 + with: + path: | + .cargo/git + .cargo/git/checkouts + .cargo/registry + .cargo/registry/src + key: rust-registry-image-${{hashFiles('**/Cargo.lock') }} + - name: Cache cargo target + id: cache-cargo-target + uses: actions/cache@v3 + with: + path: | + cargo-target-${{ matrix.slug }} + key: cargo-target-${{ matrix.slug }}-${{hashFiles('**/Cargo.lock') }}-${{steps.rust-toolchain.outputs.rustc_version}} + - name: Cache apt cache + id: cache-apt + uses: actions/cache@v3 + with: + path: | + var-cache-apt-${{ matrix.slug }} + key: var-cache-apt-${{ matrix.slug }} + - name: Cache apt lib + id: cache-apt-lib + uses: actions/cache@v3 + with: + path: | + var-lib-apt-${{ matrix.slug }} + key: var-lib-apt-${{ matrix.slug }} + - name: inject cache into docker + uses: https://github.com/reproducible-containers/buildkit-cache-dance@v3.1.0 + with: + cache-map: | + { + ".cargo/registry": "/usr/local/cargo/registry", + ".cargo/git/db": "/usr/local/cargo/git/db", + "cargo-target-${{ matrix.slug }}": { + "target": "/app/target", + "id": "cargo-target-${{ matrix.platform }}" + }, + "var-cache-apt-${{ matrix.slug }}": "/var/cache/apt", + "var-lib-apt-${{ matrix.slug }}": "/var/lib/apt" + } + skip-extraction: ${{ steps.cache.outputs.cache-hit }} + - name: Build and push Docker image by digest id: build uses: docker/build-push-action@v6 From 9b8b37f162b75fe503b557876632bb5115aa35da Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 21 May 2025 02:51:09 +0100 Subject: [PATCH 1996/2291] docs: Badges for mirrors --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fdcdafb7..e3eb807f 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,15 @@ [continuwuity] is a Matrix homeserver written in Rust. -It's a community continuation of the [conduwuit](https://github.com/girlbossceo/conduwuit) homeserver. +It's a community continuation of the [conduwuit](https://github.com/girlbossceo/conduwuit) homeserver. +[![forgejo.ellis.link](https://img.shields.io/badge/Ellis%20Git-main+packages-green?style=flat&logo=forgejo&labelColor=fff)](https://forgejo.ellis.link/continuwuation/continuwuity) ![](https://forgejo.ellis.link/continuwuation/continuwuity/badges/stars.svg?style=flat) [![](https://forgejo.ellis.link/continuwuation/continuwuity/badges/issues/open.svg?style=flat)](https://forgejo.ellis.link/continuwuation/continuwuity/issues?state=open) [![](https://forgejo.ellis.link/continuwuation/continuwuity/badges/pulls/open.svg?style=flat)](https://forgejo.ellis.link/continuwuation/continuwuity/pulls?state=open) + +[![GitHub](https://img.shields.io/badge/GitHub-mirror-blue?style=flat&logo=github&labelColor=fff&logoColor=24292f)](https://github.com/continuwuity/continuwuity) ![](https://img.shields.io/github/stars/continuwuity/continuwuity?style=flat) + +[![Codeberg](https://img.shields.io/badge/Codeberg-mirror-2185D0?style=flat&logo=codeberg&labelColor=fff)](https://codeberg.org/nexy7574/continuwuity) ![](https://codeberg.org/nexy7574/continuwuity/badges/stars.svg?style=flat) ### Why does this exist? @@ -112,4 +117,3 @@ Join our [Matrix room](https://matrix.to/#/#continuwuity:continuwuity.org) and [ [continuwuity]: https://forgejo.ellis.link/continuwuation/continuwuity - From fcd5669aa117afc229f95ee43f072bd3b462ed09 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 22 Apr 2025 06:29:30 +0000 Subject: [PATCH 1997/2291] Join jemalloc background threads prior to exit. Co-authored-by: Jade Ellis Signed-off-by: Jason Volk --- src/core/alloc/je.rs | 4 ++++ src/main/runtime.rs | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/core/alloc/je.rs b/src/core/alloc/je.rs index 2424e99c..e138233e 100644 --- a/src/core/alloc/je.rs +++ b/src/core/alloc/je.rs @@ -274,6 +274,10 @@ pub fn set_dirty_decay>>(arena: I, decay_ms: isize) -> Res } } +pub fn background_thread_enable(enable: bool) -> Result { + set::(&mallctl!("background_thread"), enable.into()).map(is_nonzero!()) +} + #[inline] #[must_use] pub fn is_affine_arena() -> bool { is_percpu_arena() || is_phycpu_arena() } diff --git a/src/main/runtime.rs b/src/main/runtime.rs index 1c58ea81..e9029012 100644 --- a/src/main/runtime.rs +++ b/src/main/runtime.rs @@ -98,12 +98,7 @@ pub(super) fn shutdown(server: &Arc, runtime: tokio::runtime::Runtime) { Level::INFO }; - debug!( - timeout = ?SHUTDOWN_TIMEOUT, - "Waiting for runtime..." - ); - - runtime.shutdown_timeout(SHUTDOWN_TIMEOUT); + wait_shutdown(server, runtime); let runtime_metrics = server.server.metrics.runtime_interval().unwrap_or_default(); event!(LEVEL, ?runtime_metrics, "Final runtime metrics"); @@ -111,13 +106,23 @@ pub(super) fn shutdown(server: &Arc, runtime: tokio::runtime::Runtime) { #[cfg(not(tokio_unstable))] #[tracing::instrument(name = "stop", level = "info", skip_all)] -pub(super) fn shutdown(_server: &Arc, runtime: tokio::runtime::Runtime) { +pub(super) fn shutdown(server: &Arc, runtime: tokio::runtime::Runtime) { + wait_shutdown(server, runtime); +} + +fn wait_shutdown(_server: &Arc, runtime: tokio::runtime::Runtime) { debug!( timeout = ?SHUTDOWN_TIMEOUT, "Waiting for runtime..." ); runtime.shutdown_timeout(SHUTDOWN_TIMEOUT); + + // Join any jemalloc threads so they don't appear in use at exit. + #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] + conduwuit_core::alloc::je::background_thread_enable(false) + .log_debug_err() + .ok(); } #[tracing::instrument( From bfb0a2b76a544af87fb9c2181f4f93eada14d635 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 22 Apr 2025 09:33:17 +0000 Subject: [PATCH 1998/2291] Remove unused Pdu::into_any_event(). Signed-off-by: Jason Volk --- src/core/matrix/pdu/strip.rs | 69 ++++++++++-------------------------- 1 file changed, 19 insertions(+), 50 deletions(-) diff --git a/src/core/matrix/pdu/strip.rs b/src/core/matrix/pdu/strip.rs index 3683caaa..a39e7d35 100644 --- a/src/core/matrix/pdu/strip.rs +++ b/src/core/matrix/pdu/strip.rs @@ -1,8 +1,8 @@ use ruma::{ events::{ - AnyEphemeralRoomEvent, AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent, - AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent, StateEvent, - room::member::RoomMemberEventContent, space::child::HierarchySpaceChildEvent, + AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent, AnySyncStateEvent, + AnySyncTimelineEvent, AnyTimelineEvent, StateEvent, room::member::RoomMemberEventContent, + space::child::HierarchySpaceChildEvent, }, serde::Raw, }; @@ -10,41 +10,6 @@ use serde_json::{json, value::Value as JsonValue}; use crate::implement; -/// This only works for events that are also AnyRoomEvents. -#[must_use] -#[implement(super::Pdu)] -pub fn into_any_event(self) -> Raw { - serde_json::from_value(self.into_any_event_value()).expect("Raw::from_value always works") -} - -/// This only works for events that are also AnyRoomEvents. -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn into_any_event_value(self) -> JsonValue { - let (redacts, content) = self.copy_redacts(); - let mut json = json!({ - "content": content, - "type": self.kind, - "event_id": self.event_id, - "sender": self.sender, - "origin_server_ts": self.origin_server_ts, - "room_id": self.room_id, - }); - - if let Some(unsigned) = &self.unsigned { - json["unsigned"] = json!(unsigned); - } - if let Some(state_key) = &self.state_key { - json["state_key"] = json!(state_key); - } - if let Some(redacts) = &redacts { - json["redacts"] = json!(redacts); - } - - json -} - #[implement(super::Pdu)] #[must_use] #[inline] @@ -53,7 +18,8 @@ pub fn into_room_event(self) -> Raw { self.to_room_event() } #[implement(super::Pdu)] #[must_use] pub fn to_room_event(&self) -> Raw { - serde_json::from_value(self.to_room_event_value()).expect("Raw::from_value always works") + let value = self.to_room_event_value(); + serde_json::from_value(value).expect("Failed to serialize Event value") } #[implement(super::Pdu)] @@ -91,8 +57,8 @@ pub fn into_message_like_event(self) -> Raw { self.to_messa #[implement(super::Pdu)] #[must_use] pub fn to_message_like_event(&self) -> Raw { - serde_json::from_value(self.to_message_like_event_value()) - .expect("Raw::from_value always works") + let value = self.to_message_like_event_value(); + serde_json::from_value(value).expect("Failed to serialize Event value") } #[implement(super::Pdu)] @@ -130,7 +96,8 @@ pub fn into_sync_room_event(self) -> Raw { self.to_sync_ro #[implement(super::Pdu)] #[must_use] pub fn to_sync_room_event(&self) -> Raw { - serde_json::from_value(self.to_sync_room_event_value()).expect("Raw::from_value always works") + let value = self.to_sync_room_event_value(); + serde_json::from_value(value).expect("Failed to serialize Event value") } #[implement(super::Pdu)] @@ -162,7 +129,8 @@ pub fn to_sync_room_event_value(&self) -> JsonValue { #[implement(super::Pdu)] #[must_use] pub fn into_state_event(self) -> Raw { - serde_json::from_value(self.into_state_event_value()).expect("Raw::from_value always works") + let value = self.into_state_event_value(); + serde_json::from_value(value).expect("Failed to serialize Event value") } #[implement(super::Pdu)] @@ -189,8 +157,8 @@ pub fn into_state_event_value(self) -> JsonValue { #[implement(super::Pdu)] #[must_use] pub fn into_sync_state_event(self) -> Raw { - serde_json::from_value(self.into_sync_state_event_value()) - .expect("Raw::from_value always works") + let value = self.into_sync_state_event_value(); + serde_json::from_value(value).expect("Failed to serialize Event value") } #[implement(super::Pdu)] @@ -223,8 +191,8 @@ pub fn into_stripped_state_event(self) -> Raw { #[implement(super::Pdu)] #[must_use] pub fn to_stripped_state_event(&self) -> Raw { - serde_json::from_value(self.to_stripped_state_event_value()) - .expect("Raw::from_value always works") + let value = self.to_stripped_state_event_value(); + serde_json::from_value(value).expect("Failed to serialize Event value") } #[implement(super::Pdu)] @@ -242,8 +210,8 @@ pub fn to_stripped_state_event_value(&self) -> JsonValue { #[implement(super::Pdu)] #[must_use] pub fn into_stripped_spacechild_state_event(self) -> Raw { - serde_json::from_value(self.into_stripped_spacechild_state_event_value()) - .expect("Raw::from_value always works") + let value = self.into_stripped_spacechild_state_event_value(); + serde_json::from_value(value).expect("Failed to serialize Event value") } #[implement(super::Pdu)] @@ -262,7 +230,8 @@ pub fn into_stripped_spacechild_state_event_value(self) -> JsonValue { #[implement(super::Pdu)] #[must_use] pub fn into_member_event(self) -> Raw> { - serde_json::from_value(self.into_member_event_value()).expect("Raw::from_value always works") + let value = self.into_member_event_value(); + serde_json::from_value(value).expect("Failed to serialize Event value") } #[implement(super::Pdu)] From 44302ce73289bc70b0e05755f1a23f5d0770f752 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 22 Apr 2025 11:00:07 +0000 Subject: [PATCH 1999/2291] Eliminate explicit parallel_fetches argument. Signed-off-by: Jason Volk --- src/core/matrix/state_res/benches.rs | 4 - src/core/matrix/state_res/mod.rs | 83 +++++++------------ src/core/matrix/state_res/test_utils.rs | 16 ++-- .../rooms/event_handler/resolve_state.rs | 13 +-- 4 files changed, 38 insertions(+), 78 deletions(-) diff --git a/src/core/matrix/state_res/benches.rs b/src/core/matrix/state_res/benches.rs index 01218b01..1aa8552b 100644 --- a/src/core/matrix/state_res/benches.rs +++ b/src/core/matrix/state_res/benches.rs @@ -52,7 +52,6 @@ fn lexico_topo_sort(c: &mut test::Bencher) { #[cfg(conduwuit_bench)] #[cfg_attr(conduwuit_bench, bench)] fn resolution_shallow_auth_chain(c: &mut test::Bencher) { - let parallel_fetches = 32; let mut store = TestStore(hashmap! {}); // build up the DAG @@ -78,7 +77,6 @@ fn resolution_shallow_auth_chain(c: &mut test::Bencher) { &auth_chain_sets, &fetch, &exists, - parallel_fetches, ) .await { @@ -91,7 +89,6 @@ fn resolution_shallow_auth_chain(c: &mut test::Bencher) { #[cfg(conduwuit_bench)] #[cfg_attr(conduwuit_bench, bench)] fn resolve_deeper_event_set(c: &mut test::Bencher) { - let parallel_fetches = 32; let mut inner = INITIAL_EVENTS(); let ban = BAN_STATE_SET(); @@ -153,7 +150,6 @@ fn resolve_deeper_event_set(c: &mut test::Bencher) { &auth_chain_sets, &fetch, &exists, - parallel_fetches, ) .await { diff --git a/src/core/matrix/state_res/mod.rs b/src/core/matrix/state_res/mod.rs index 2ab7cb64..d37368c9 100644 --- a/src/core/matrix/state_res/mod.rs +++ b/src/core/matrix/state_res/mod.rs @@ -69,9 +69,6 @@ type Result = crate::Result; /// * `event_fetch` - Any event not found in the `event_map` will defer to this /// closure to find the event. /// -/// * `parallel_fetches` - The number of asynchronous fetch requests in-flight -/// for any given operation. -/// /// ## Invariants /// /// The caller of `resolve` must ensure that all the events are from the same @@ -85,7 +82,6 @@ pub async fn resolve<'a, E, Sets, SetIter, Hasher, Fetch, FetchFut, Exists, Exis auth_chain_sets: &'a [HashSet], event_fetch: &Fetch, event_exists: &Exists, - parallel_fetches: usize, ) -> Result> where Fetch: Fn(E::Id) -> FetchFut + Sync, @@ -147,13 +143,8 @@ where // Sort the control events based on power_level/clock/event_id and // outgoing/incoming edges - let sorted_control_levels = reverse_topological_power_sort( - control_events, - &all_conflicted, - &event_fetch, - parallel_fetches, - ) - .await?; + let sorted_control_levels = + reverse_topological_power_sort(control_events, &all_conflicted, &event_fetch).await?; debug!(count = sorted_control_levels.len(), "power events"); trace!(list = ?sorted_control_levels, "sorted power events"); @@ -295,7 +286,6 @@ async fn reverse_topological_power_sort( events_to_sort: Vec, auth_diff: &HashSet, fetch_event: &F, - parallel_fetches: usize, ) -> Result> where F: Fn(E::Id) -> Fut + Sync, @@ -311,26 +301,25 @@ where } // This is used in the `key_fn` passed to the lexico_topo_sort fn - let event_to_pl = graph + let event_to_pl: HashMap<_, _> = graph .keys() .stream() - .map(|event_id| { - get_power_level_for_sender(event_id.clone(), fetch_event) - .map(move |res| res.map(|pl| (event_id, pl))) + .broad_filter_map(async |event_id| { + let pl = get_power_level_for_sender(&event_id, fetch_event) + .await + .ok()?; + Some((event_id, pl)) }) - .buffer_unordered(parallel_fetches) - .ready_try_fold(HashMap::new(), |mut event_to_pl, (event_id, pl)| { + .inspect(|(event_id, pl)| { debug!( - event_id = event_id.borrow().as_str(), - power_level = i64::from(pl), + event_id = event_id.as_str(), + power_level = i64::from(*pl), "found the power level of an event's sender", ); - - event_to_pl.insert(event_id.clone(), pl); - Ok(event_to_pl) }) + .collect() .boxed() - .await?; + .await; let event_to_pl = &event_to_pl; let fetcher = |event_id: E::Id| async move { @@ -909,7 +898,7 @@ mod tests { let fetcher = |id| ready(events.get(&id).cloned()); let sorted_power_events = - super::reverse_topological_power_sort(power_events, &auth_chain, &fetcher, 1) + super::reverse_topological_power_sort(power_events, &auth_chain, &fetcher) .await .unwrap(); @@ -1312,19 +1301,13 @@ mod tests { }) .collect(); - let resolved = match super::resolve( - &RoomVersionId::V2, - &state_sets, - &auth_chain, - &fetcher, - &exists, - 1, - ) - .await - { - | Ok(state) => state, - | Err(e) => panic!("{e}"), - }; + let resolved = + match super::resolve(&RoomVersionId::V2, &state_sets, &auth_chain, &fetcher, &exists) + .await + { + | Ok(state) => state, + | Err(e) => panic!("{e}"), + }; assert_eq!(expected, resolved); } @@ -1429,21 +1412,15 @@ mod tests { }) .collect(); - let fetcher = |id: ::Id| ready(ev_map.get(&id).cloned()); - let exists = |id: ::Id| ready(ev_map.get(&id).is_some()); - let resolved = match super::resolve( - &RoomVersionId::V6, - &state_sets, - &auth_chain, - &fetcher, - &exists, - 1, - ) - .await - { - | Ok(state) => state, - | Err(e) => panic!("{e}"), - }; + let fetcher = |id: OwnedEventId| ready(ev_map.get(&id).cloned()); + let exists = |id: OwnedEventId| ready(ev_map.get(&id).is_some()); + let resolved = + match super::resolve(&RoomVersionId::V6, &state_sets, &auth_chain, &fetcher, &exists) + .await + { + | Ok(state) => state, + | Err(e) => panic!("{e}"), + }; debug!( resolved = ?resolved diff --git a/src/core/matrix/state_res/test_utils.rs b/src/core/matrix/state_res/test_utils.rs index a666748a..ff7b30d0 100644 --- a/src/core/matrix/state_res/test_utils.rs +++ b/src/core/matrix/state_res/test_utils.rs @@ -133,17 +133,11 @@ pub(crate) async fn do_check( .collect(); let event_map = &event_map; - let fetch = |id: ::Id| ready(event_map.get(&id).cloned()); - let exists = |id: ::Id| ready(event_map.get(&id).is_some()); - let resolved = super::resolve( - &RoomVersionId::V6, - state_sets, - &auth_chain_sets, - &fetch, - &exists, - 1, - ) - .await; + let fetch = |id: OwnedEventId| ready(event_map.get(&id).cloned()); + let exists = |id: OwnedEventId| ready(event_map.get(&id).is_some()); + let resolved = + super::resolve(&RoomVersionId::V6, state_sets, &auth_chain_sets, &fetch, &exists) + .await; match resolved { | Ok(state) => state, diff --git a/src/service/rooms/event_handler/resolve_state.rs b/src/service/rooms/event_handler/resolve_state.rs index b3a7a71b..a67ac3b7 100644 --- a/src/service/rooms/event_handler/resolve_state.rs +++ b/src/service/rooms/event_handler/resolve_state.rs @@ -112,14 +112,7 @@ where { let event_fetch = |event_id| self.event_fetch(event_id); let event_exists = |event_id| self.event_exists(event_id); - state_res::resolve( - room_version, - state_sets, - auth_chain_sets, - &event_fetch, - &event_exists, - automatic_width(), - ) - .map_err(|e| err!(error!("State resolution failed: {e:?}"))) - .await + state_res::resolve(room_version, state_sets, auth_chain_sets, &event_fetch, &event_exists) + .map_err(|e| err!(error!("State resolution failed: {e:?}"))) + .await } From f605913ea92d2f741616f0cfd838cf348dc22a34 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 22 Apr 2025 11:00:55 +0000 Subject: [PATCH 2000/2291] Eliminate associated Id type from trait Event. Co-authored-by: Jade Ellis Signed-off-by: Jason Volk --- src/core/matrix/event.rs | 26 ++-- src/core/matrix/pdu.rs | 14 +- src/core/matrix/state_res/benches.rs | 38 +++--- src/core/matrix/state_res/event_auth.rs | 8 +- src/core/matrix/state_res/mod.rs | 128 +++++++++--------- src/core/matrix/state_res/test_utils.rs | 30 ++-- .../rooms/event_handler/resolve_state.rs | 2 +- 7 files changed, 116 insertions(+), 130 deletions(-) diff --git a/src/core/matrix/event.rs b/src/core/matrix/event.rs index 29153334..e4c478cd 100644 --- a/src/core/matrix/event.rs +++ b/src/core/matrix/event.rs @@ -1,18 +1,10 @@ -use std::{ - borrow::Borrow, - fmt::{Debug, Display}, - hash::Hash, -}; - use ruma::{EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId, events::TimelineEventType}; use serde_json::value::RawValue as RawJsonValue; /// Abstraction of a PDU so users can have their own PDU types. pub trait Event { - type Id: Clone + Debug + Display + Eq + Ord + Hash + Send + Borrow; - /// The `EventId` of this event. - fn event_id(&self) -> &Self::Id; + fn event_id(&self) -> &EventId; /// The `RoomId` of this event. fn room_id(&self) -> &RoomId; @@ -34,20 +26,18 @@ pub trait Event { /// The events before this event. // Requires GATs to avoid boxing (and TAIT for making it convenient). - fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_; + fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_; /// All the authenticating events for this event. // Requires GATs to avoid boxing (and TAIT for making it convenient). - fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_; + fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_; /// If this event is a redaction event this is the event it redacts. - fn redacts(&self) -> Option<&Self::Id>; + fn redacts(&self) -> Option<&EventId>; } impl Event for &T { - type Id = T::Id; - - fn event_id(&self) -> &Self::Id { (*self).event_id() } + fn event_id(&self) -> &EventId { (*self).event_id() } fn room_id(&self) -> &RoomId { (*self).room_id() } @@ -61,13 +51,13 @@ impl Event for &T { fn state_key(&self) -> Option<&str> { (*self).state_key() } - fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_ { + fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_ { (*self).prev_events() } - fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_ { + fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_ { (*self).auth_events() } - fn redacts(&self) -> Option<&Self::Id> { (*self).redacts() } + fn redacts(&self) -> Option<&EventId> { (*self).redacts() } } diff --git a/src/core/matrix/pdu.rs b/src/core/matrix/pdu.rs index 7e1ecfa8..188586bd 100644 --- a/src/core/matrix/pdu.rs +++ b/src/core/matrix/pdu.rs @@ -79,9 +79,7 @@ impl Pdu { } impl Event for Pdu { - type Id = OwnedEventId; - - fn event_id(&self) -> &Self::Id { &self.event_id } + fn event_id(&self) -> &EventId { &self.event_id } fn room_id(&self) -> &RoomId { &self.room_id } @@ -97,15 +95,15 @@ impl Event for Pdu { fn state_key(&self) -> Option<&str> { self.state_key.as_deref() } - fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_ { - self.prev_events.iter() + fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_ { + self.prev_events.iter().map(AsRef::as_ref) } - fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_ { - self.auth_events.iter() + fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_ { + self.auth_events.iter().map(AsRef::as_ref) } - fn redacts(&self) -> Option<&Self::Id> { self.redacts.as_ref() } + fn redacts(&self) -> Option<&EventId> { self.redacts.as_deref() } } /// Prevent derived equality which wouldn't limit itself to event_id diff --git a/src/core/matrix/state_res/benches.rs b/src/core/matrix/state_res/benches.rs index 1aa8552b..12eeab9d 100644 --- a/src/core/matrix/state_res/benches.rs +++ b/src/core/matrix/state_res/benches.rs @@ -186,7 +186,11 @@ impl TestStore { } /// Returns a Vec of the related auth events to the given `event`. - fn auth_event_ids(&self, room_id: &RoomId, event_ids: Vec) -> Result> { + fn auth_event_ids( + &self, + room_id: &RoomId, + event_ids: Vec, + ) -> Result> { let mut result = HashSet::new(); let mut stack = event_ids; @@ -212,8 +216,8 @@ impl TestStore { fn auth_chain_diff( &self, room_id: &RoomId, - event_ids: Vec>, - ) -> Result> { + event_ids: Vec>, + ) -> Result> { let mut auth_chain_sets = vec![]; for ids in event_ids { // TODO state store `auth_event_ids` returns self in the event ids list @@ -234,7 +238,7 @@ impl TestStore { Ok(auth_chain_sets .into_iter() .flatten() - .filter(|id| !common.contains(id.borrow())) + .filter(|id| !common.contains(id)) .collect()) } else { Ok(vec![]) @@ -561,7 +565,7 @@ impl EventTypeExt for &TimelineEventType { mod event { use ruma::{ - MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId, + EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId, events::{TimelineEventType, pdu::Pdu}, }; use serde::{Deserialize, Serialize}; @@ -570,9 +574,7 @@ mod event { use super::Event; impl Event for PduEvent { - type Id = OwnedEventId; - - fn event_id(&self) -> &Self::Id { &self.event_id } + fn event_id(&self) -> &EventId { &self.event_id } fn room_id(&self) -> &RoomId { match &self.rest { @@ -628,28 +630,30 @@ mod event { } } - fn prev_events(&self) -> Box + Send + '_> { + fn prev_events(&self) -> Box + Send + '_> { match &self.rest { - | Pdu::RoomV1Pdu(ev) => Box::new(ev.prev_events.iter().map(|(id, _)| id)), - | Pdu::RoomV3Pdu(ev) => Box::new(ev.prev_events.iter()), + | Pdu::RoomV1Pdu(ev) => + Box::new(ev.prev_events.iter().map(|(id, _)| id.as_ref())), + | Pdu::RoomV3Pdu(ev) => Box::new(ev.prev_events.iter().map(AsRef::as_ref)), #[cfg(not(feature = "unstable-exhaustive-types"))] | _ => unreachable!("new PDU version"), } } - fn auth_events(&self) -> Box + Send + '_> { + fn auth_events(&self) -> Box + Send + '_> { match &self.rest { - | Pdu::RoomV1Pdu(ev) => Box::new(ev.auth_events.iter().map(|(id, _)| id)), - | Pdu::RoomV3Pdu(ev) => Box::new(ev.auth_events.iter()), + | Pdu::RoomV1Pdu(ev) => + Box::new(ev.auth_events.iter().map(|(id, _)| id.as_ref())), + | Pdu::RoomV3Pdu(ev) => Box::new(ev.auth_events.iter().map(AsRef::as_ref)), #[cfg(not(feature = "unstable-exhaustive-types"))] | _ => unreachable!("new PDU version"), } } - fn redacts(&self) -> Option<&Self::Id> { + fn redacts(&self) -> Option<&EventId> { match &self.rest { - | Pdu::RoomV1Pdu(ev) => ev.redacts.as_ref(), - | Pdu::RoomV3Pdu(ev) => ev.redacts.as_ref(), + | Pdu::RoomV1Pdu(ev) => ev.redacts.as_deref(), + | Pdu::RoomV3Pdu(ev) => ev.redacts.as_deref(), #[cfg(not(feature = "unstable-exhaustive-types"))] | _ => unreachable!("new PDU version"), } diff --git a/src/core/matrix/state_res/event_auth.rs b/src/core/matrix/state_res/event_auth.rs index c69db50e..715e5156 100644 --- a/src/core/matrix/state_res/event_auth.rs +++ b/src/core/matrix/state_res/event_auth.rs @@ -133,7 +133,7 @@ pub fn auth_types_for_event( level = "debug", skip_all, fields( - event_id = incoming_event.event_id().borrow().as_str() + event_id = incoming_event.event_id().as_str(), ) )] pub async fn auth_check( @@ -259,7 +259,7 @@ where // 3. If event does not have m.room.create in auth_events reject if !incoming_event .auth_events() - .any(|id| id.borrow() == room_create_event.event_id().borrow()) + .any(|id| id == room_create_event.event_id()) { warn!("no m.room.create event in auth events"); return Ok(false); @@ -1021,11 +1021,11 @@ fn check_redaction( // If the domain of the event_id of the event being redacted is the same as the // domain of the event_id of the m.room.redaction, allow - if redaction_event.event_id().borrow().server_name() + if redaction_event.event_id().server_name() == redaction_event .redacts() .as_ref() - .and_then(|&id| id.borrow().server_name()) + .and_then(|&id| id.server_name()) { debug!("redaction event allowed via room version 1 rules"); return Ok(true); diff --git a/src/core/matrix/state_res/mod.rs b/src/core/matrix/state_res/mod.rs index d37368c9..651f6130 100644 --- a/src/core/matrix/state_res/mod.rs +++ b/src/core/matrix/state_res/mod.rs @@ -20,7 +20,7 @@ use std::{ use futures::{Future, FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt, future}; use ruma::{ - EventId, Int, MilliSecondsSinceUnixEpoch, RoomVersionId, + EventId, Int, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomVersionId, events::{ StateEventType, TimelineEventType, room::member::{MembershipState, RoomMemberEventContent}, @@ -39,9 +39,7 @@ use crate::{ debug, debug_error, matrix::{event::Event, pdu::StateKey}, trace, - utils::stream::{ - BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, TryReadyExt, WidebandExt, - }, + utils::stream::{BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, WidebandExt}, warn, }; @@ -79,20 +77,19 @@ type Result = crate::Result; pub async fn resolve<'a, E, Sets, SetIter, Hasher, Fetch, FetchFut, Exists, ExistsFut>( room_version: &RoomVersionId, state_sets: Sets, - auth_chain_sets: &'a [HashSet], + auth_chain_sets: &'a [HashSet], event_fetch: &Fetch, event_exists: &Exists, -) -> Result> +) -> Result> where - Fetch: Fn(E::Id) -> FetchFut + Sync, + Fetch: Fn(OwnedEventId) -> FetchFut + Sync, FetchFut: Future> + Send, - Exists: Fn(E::Id) -> ExistsFut + Sync, + Exists: Fn(OwnedEventId) -> ExistsFut + Sync, ExistsFut: Future + Send, Sets: IntoIterator + Send, - SetIter: Iterator> + Clone + Send, + SetIter: Iterator> + Clone + Send, Hasher: BuildHasher + Send + Sync, E: Event + Clone + Send + Sync, - E::Id: Borrow + Send + Sync, for<'b> &'b E: Send, { debug!("State resolution starting"); @@ -153,7 +150,7 @@ where // Sequentially auth check each control event. let resolved_control = iterative_auth_check( &room_version, - sorted_control_levels.iter().stream(), + sorted_control_levels.iter().stream().map(AsRef::as_ref), clean.clone(), &event_fetch, ) @@ -170,7 +167,7 @@ where // that failed auth let events_to_resolve: Vec<_> = all_conflicted .iter() - .filter(|&id| !deduped_power_ev.contains(id.borrow())) + .filter(|&id| !deduped_power_ev.contains(id)) .cloned() .collect(); @@ -190,7 +187,7 @@ where let mut resolved_state = iterative_auth_check( &room_version, - sorted_left_events.iter().stream(), + sorted_left_events.iter().stream().map(AsRef::as_ref), resolved_control, // The control events are added to the final resolved state &event_fetch, ) @@ -283,15 +280,14 @@ where /// earlier (further back in time) origin server timestamp. #[tracing::instrument(level = "debug", skip_all)] async fn reverse_topological_power_sort( - events_to_sort: Vec, - auth_diff: &HashSet, + events_to_sort: Vec, + auth_diff: &HashSet, fetch_event: &F, -) -> Result> +) -> Result> where - F: Fn(E::Id) -> Fut + Sync, + F: Fn(OwnedEventId) -> Fut + Sync, Fut: Future> + Send, E: Event + Send + Sync, - E::Id: Borrow + Send + Sync, { debug!("reverse topological sort of power events"); @@ -303,6 +299,7 @@ where // This is used in the `key_fn` passed to the lexico_topo_sort fn let event_to_pl: HashMap<_, _> = graph .keys() + .cloned() .stream() .broad_filter_map(async |event_id| { let pl = get_power_level_for_sender(&event_id, fetch_event) @@ -321,14 +318,15 @@ where .boxed() .await; - let event_to_pl = &event_to_pl; - let fetcher = |event_id: E::Id| async move { + let fetcher = async |event_id: OwnedEventId| { let pl = *event_to_pl - .get(event_id.borrow()) + .get(&event_id) .ok_or_else(|| Error::NotFound(String::new()))?; + let ev = fetch_event(event_id) .await .ok_or_else(|| Error::NotFound(String::new()))?; + Ok((pl, ev.origin_server_ts())) }; @@ -465,18 +463,17 @@ where /// the eventId at the eventId's generation (we walk backwards to `EventId`s /// most recent previous power level event). async fn get_power_level_for_sender( - event_id: E::Id, + event_id: &EventId, fetch_event: &F, ) -> serde_json::Result where - F: Fn(E::Id) -> Fut + Sync, + F: Fn(OwnedEventId) -> Fut + Sync, Fut: Future> + Send, E: Event + Send, - E::Id: Borrow + Send, { debug!("fetch event ({event_id}) senders power level"); - let event = fetch_event(event_id).await; + let event = fetch_event(event_id.to_owned()).await; let auth_events = event.as_ref().map(Event::auth_events); @@ -484,7 +481,7 @@ where .into_iter() .flatten() .stream() - .broadn_filter_map(5, |aid| fetch_event(aid.clone())) + .broadn_filter_map(5, |aid| fetch_event(aid.to_owned())) .ready_find(|aev| is_type_and_key(aev, &TimelineEventType::RoomPowerLevels, "")) .await; @@ -517,14 +514,13 @@ where async fn iterative_auth_check<'a, E, F, Fut, S>( room_version: &RoomVersion, events_to_check: S, - unconflicted_state: StateMap, + unconflicted_state: StateMap, fetch_event: &F, -) -> Result> +) -> Result> where - F: Fn(E::Id) -> Fut + Sync, + F: Fn(OwnedEventId) -> Fut + Sync, Fut: Future> + Send, - E::Id: Borrow + Clone + Eq + Ord + Send + Sync + 'a, - S: Stream + Send + 'a, + S: Stream + Send + 'a, E: Event + Clone + Send + Sync, { debug!("starting iterative auth check"); @@ -532,7 +528,7 @@ where let events_to_check: Vec<_> = events_to_check .map(Result::Ok) .broad_and_then(async |event_id| { - fetch_event(event_id.clone()) + fetch_event(event_id.to_owned()) .await .ok_or_else(|| Error::NotFound(format!("Failed to find {event_id}"))) }) @@ -540,16 +536,16 @@ where .boxed() .await?; - let auth_event_ids: HashSet = events_to_check + let auth_event_ids: HashSet = events_to_check .iter() - .flat_map(|event: &E| event.auth_events().map(Clone::clone)) + .flat_map(|event: &E| event.auth_events().map(ToOwned::to_owned)) .collect(); - let auth_events: HashMap = auth_event_ids + let auth_events: HashMap = auth_event_ids .into_iter() .stream() .broad_filter_map(fetch_event) - .map(|auth_event| (auth_event.event_id().clone(), auth_event)) + .map(|auth_event| (auth_event.event_id().to_owned(), auth_event)) .collect() .boxed() .await; @@ -570,7 +566,7 @@ where let mut auth_state = StateMap::new(); for aid in event.auth_events() { - if let Some(ev) = auth_events.get(aid.borrow()) { + if let Some(ev) = auth_events.get(aid) { //TODO: synapse checks "rejected_reason" which is most likely related to // soft-failing auth_state.insert( @@ -581,7 +577,7 @@ where ev.clone(), ); } else { - warn!(event_id = aid.borrow().as_str(), "missing auth event"); + warn!(event_id = aid.as_str(), "missing auth event"); } } @@ -590,7 +586,7 @@ where .stream() .ready_filter_map(|key| Some((key, resolved_state.get(key)?))) .filter_map(|(key, ev_id)| async move { - if let Some(event) = auth_events.get(ev_id.borrow()) { + if let Some(event) = auth_events.get(ev_id) { Some((key, event.clone())) } else { Some((key, fetch_event(ev_id.clone()).await?)) @@ -622,7 +618,7 @@ where // add event to resolved state map resolved_state.insert( event.event_type().with_state_key(state_key), - event.event_id().clone(), + event.event_id().to_owned(), ); }, | Ok(false) => { @@ -649,15 +645,14 @@ where /// level as a parent) will be marked as depth 1. depth 1 is "older" than depth /// 0. async fn mainline_sort( - to_sort: &[E::Id], - resolved_power_level: Option, + to_sort: &[OwnedEventId], + resolved_power_level: Option, fetch_event: &F, -) -> Result> +) -> Result> where - F: Fn(E::Id) -> Fut + Sync, + F: Fn(OwnedEventId) -> Fut + Sync, Fut: Future> + Send, E: Event + Clone + Send + Sync, - E::Id: Borrow + Clone + Send + Sync, { debug!("mainline sort of events"); @@ -677,7 +672,7 @@ where pl = None; for aid in event.auth_events() { - let ev = fetch_event(aid.clone()) + let ev = fetch_event(aid.to_owned()) .await .ok_or_else(|| Error::NotFound(format!("Failed to find {aid}")))?; @@ -723,26 +718,25 @@ where /// that has an associated mainline depth. async fn get_mainline_depth( mut event: Option, - mainline_map: &HashMap, + mainline_map: &HashMap, fetch_event: &F, ) -> Result where - F: Fn(E::Id) -> Fut + Sync, + F: Fn(OwnedEventId) -> Fut + Sync, Fut: Future> + Send, E: Event + Send + Sync, - E::Id: Borrow + Send + Sync, { while let Some(sort_ev) = event { - debug!(event_id = sort_ev.event_id().borrow().as_str(), "mainline"); + debug!(event_id = sort_ev.event_id().as_str(), "mainline"); let id = sort_ev.event_id(); - if let Some(depth) = mainline_map.get(id.borrow()) { + if let Some(depth) = mainline_map.get(id) { return Ok(*depth); } event = None; for aid in sort_ev.auth_events() { - let aev = fetch_event(aid.clone()) + let aev = fetch_event(aid.to_owned()) .await .ok_or_else(|| Error::NotFound(format!("Failed to find {aid}")))?; @@ -757,15 +751,14 @@ where } async fn add_event_and_auth_chain_to_graph( - graph: &mut HashMap>, - event_id: E::Id, - auth_diff: &HashSet, + graph: &mut HashMap>, + event_id: OwnedEventId, + auth_diff: &HashSet, fetch_event: &F, ) where - F: Fn(E::Id) -> Fut + Sync, + F: Fn(OwnedEventId) -> Fut + Sync, Fut: Future> + Send, E: Event + Send + Sync, - E::Id: Borrow + Clone + Send + Sync, { let mut state = vec![event_id]; while let Some(eid) = state.pop() { @@ -775,26 +768,27 @@ async fn add_event_and_auth_chain_to_graph( // Prefer the store to event as the store filters dedups the events for aid in auth_events { - if auth_diff.contains(aid.borrow()) { - if !graph.contains_key(aid.borrow()) { + if auth_diff.contains(aid) { + if !graph.contains_key(aid) { state.push(aid.to_owned()); } - // We just inserted this at the start of the while loop - graph.get_mut(eid.borrow()).unwrap().insert(aid.to_owned()); + graph + .get_mut(&eid) + .expect("We just inserted this at the start of the while loop") + .insert(aid.to_owned()); } } } } -async fn is_power_event_id(event_id: &E::Id, fetch: &F) -> bool +async fn is_power_event_id(event_id: &EventId, fetch: &F) -> bool where - F: Fn(E::Id) -> Fut + Sync, + F: Fn(OwnedEventId) -> Fut + Sync, Fut: Future> + Send, E: Event + Send, - E::Id: Borrow + Send + Sync, { - match fetch(event_id.clone()).await.as_ref() { + match fetch(event_id.to_owned()).await.as_ref() { | Some(state) => is_power_event(state), | _ => false, } @@ -904,7 +898,7 @@ mod tests { let resolved_power = super::iterative_auth_check( &RoomVersion::V6, - sorted_power_events.iter().stream(), + sorted_power_events.iter().map(AsRef::as_ref).stream(), HashMap::new(), // unconflicted events &fetcher, ) @@ -1289,7 +1283,7 @@ mod tests { let ev_map = store.0.clone(); let fetcher = |id| ready(ev_map.get(&id).cloned()); - let exists = |id: ::Id| ready(ev_map.get(&*id).is_some()); + let exists = |id: OwnedEventId| ready(ev_map.get(&*id).is_some()); let state_sets = [state_at_bob, state_at_charlie]; let auth_chain: Vec<_> = state_sets diff --git a/src/core/matrix/state_res/test_utils.rs b/src/core/matrix/state_res/test_utils.rs index ff7b30d0..c6945f66 100644 --- a/src/core/matrix/state_res/test_utils.rs +++ b/src/core/matrix/state_res/test_utils.rs @@ -241,8 +241,8 @@ impl TestStore { pub(crate) fn auth_event_ids( &self, room_id: &RoomId, - event_ids: Vec, - ) -> Result> { + event_ids: Vec, + ) -> Result> { let mut result = HashSet::new(); let mut stack = event_ids; @@ -578,7 +578,7 @@ pub(crate) fn INITIAL_EDGES() -> Vec { pub(crate) mod event { use ruma::{ - MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId, + EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId, events::{TimelineEventType, pdu::Pdu}, }; use serde::{Deserialize, Serialize}; @@ -587,9 +587,7 @@ pub(crate) mod event { use crate::Event; impl Event for PduEvent { - type Id = OwnedEventId; - - fn event_id(&self) -> &Self::Id { &self.event_id } + fn event_id(&self) -> &EventId { &self.event_id } fn room_id(&self) -> &RoomId { match &self.rest { @@ -646,29 +644,31 @@ pub(crate) mod event { } #[allow(refining_impl_trait)] - fn prev_events(&self) -> Box + Send + '_> { + fn prev_events(&self) -> Box + Send + '_> { match &self.rest { - | Pdu::RoomV1Pdu(ev) => Box::new(ev.prev_events.iter().map(|(id, _)| id)), - | Pdu::RoomV3Pdu(ev) => Box::new(ev.prev_events.iter()), + | Pdu::RoomV1Pdu(ev) => + Box::new(ev.prev_events.iter().map(|(id, _)| id.as_ref())), + | Pdu::RoomV3Pdu(ev) => Box::new(ev.prev_events.iter().map(AsRef::as_ref)), #[allow(unreachable_patterns)] | _ => unreachable!("new PDU version"), } } #[allow(refining_impl_trait)] - fn auth_events(&self) -> Box + Send + '_> { + fn auth_events(&self) -> Box + Send + '_> { match &self.rest { - | Pdu::RoomV1Pdu(ev) => Box::new(ev.auth_events.iter().map(|(id, _)| id)), - | Pdu::RoomV3Pdu(ev) => Box::new(ev.auth_events.iter()), + | Pdu::RoomV1Pdu(ev) => + Box::new(ev.auth_events.iter().map(|(id, _)| id.as_ref())), + | Pdu::RoomV3Pdu(ev) => Box::new(ev.auth_events.iter().map(AsRef::as_ref)), #[allow(unreachable_patterns)] | _ => unreachable!("new PDU version"), } } - fn redacts(&self) -> Option<&Self::Id> { + fn redacts(&self) -> Option<&EventId> { match &self.rest { - | Pdu::RoomV1Pdu(ev) => ev.redacts.as_ref(), - | Pdu::RoomV3Pdu(ev) => ev.redacts.as_ref(), + | Pdu::RoomV1Pdu(ev) => ev.redacts.as_deref(), + | Pdu::RoomV3Pdu(ev) => ev.redacts.as_deref(), #[allow(unreachable_patterns)] | _ => unreachable!("new PDU version"), } diff --git a/src/service/rooms/event_handler/resolve_state.rs b/src/service/rooms/event_handler/resolve_state.rs index a67ac3b7..cd747e04 100644 --- a/src/service/rooms/event_handler/resolve_state.rs +++ b/src/service/rooms/event_handler/resolve_state.rs @@ -8,7 +8,7 @@ use conduwuit::{ Error, Result, err, implement, state_res::{self, StateMap}, trace, - utils::stream::{IterStream, ReadyExt, TryWidebandExt, WidebandExt, automatic_width}, + utils::stream::{IterStream, ReadyExt, TryWidebandExt, WidebandExt}, }; use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, future::try_join}; use ruma::{OwnedEventId, RoomId, RoomVersionId}; From 3e4e696761e75bc5e673aea66bd6407088523944 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 21 May 2025 12:35:25 +0100 Subject: [PATCH 2001/2291] fix: Make sure empty VERSION_EXTRA strings are ignored Also updates built & removes unused optional features --- Cargo.lock | 45 ++++++------------------------- src/build_metadata/Cargo.toml | 8 +++--- src/build_metadata/build.rs | 1 + src/build_metadata/mod.rs | 11 +++++--- src/core/info/version.rs | 2 +- src/web/mod.rs | 2 +- src/web/templates/_layout.html.j2 | 2 +- 7 files changed, 24 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18375234..04e4f36e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -584,9 +584,12 @@ name = "built" version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56ed6191a7e78c36abdb16ab65341eefd73d64d303fffccdbb00d51e4205967b" -dependencies = [ - "cargo-lock", -] + +[[package]] +name = "built" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ad8f11f288f48ca24471bbd51ac257aaeaaa07adae295591266b792902ae64" [[package]] name = "bumpalo" @@ -634,19 +637,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "cargo-lock" -version = "10.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06acb4f71407ba205a07cb453211e0e6a67b21904e47f6ba1f9589e38f2e454" -dependencies = [ - "petgraph", - "semver", - "serde", - "toml", - "url", -] - [[package]] name = "cargo_toml" version = "0.21.0" @@ -876,7 +866,7 @@ dependencies = [ name = "conduwuit_build_metadata" version = "0.5.0-rc.5" dependencies = [ - "built", + "built 0.8.0", ] [[package]] @@ -1541,12 +1531,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "fixedbitset" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" - [[package]] name = "flate2" version = "1.1.1" @@ -3164,16 +3148,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "petgraph" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" -dependencies = [ - "fixedbitset", - "indexmap 2.8.0", -] - [[package]] name = "phf" version = "0.11.3" @@ -3565,7 +3539,7 @@ dependencies = [ "arrayvec", "av1-grain", "bitstream-io", - "built", + "built 0.7.7", "cfg-if", "interpolate_name", "itertools 0.12.1", @@ -4169,9 +4143,6 @@ name = "semver" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" -dependencies = [ - "serde", -] [[package]] name = "sentry" diff --git a/src/build_metadata/Cargo.toml b/src/build_metadata/Cargo.toml index 3a98c6bf..62c4dc70 100644 --- a/src/build_metadata/Cargo.toml +++ b/src/build_metadata/Cargo.toml @@ -13,13 +13,13 @@ version.workspace = true build = "build.rs" # [[bin]] # path = "main.rs" -# name = "conduwuit_build_metadata" +# name = "conduwuit_build_metadata" [lib] path = "mod.rs" crate-type = [ - "rlib", -# "dylib", + "rlib", + # "dylib", ] [features] @@ -28,7 +28,7 @@ crate-type = [ [dependencies] [build-dependencies] -built = {version = "0.7", features = ["cargo-lock", "dependency-tree"]} +built = { version = "0.8", features = [] } [lints] workspace = true diff --git a/src/build_metadata/build.rs b/src/build_metadata/build.rs index 2fec16a7..bfdf20b1 100644 --- a/src/build_metadata/build.rs +++ b/src/build_metadata/build.rs @@ -78,6 +78,7 @@ fn main() { } // --- Rerun Triggers --- + // TODO: The git rerun triggers seem to always run // Rerun if the git HEAD changes println!("cargo:rerun-if-changed=.git/HEAD"); // Rerun if the ref pointed to by HEAD changes (e.g., new commit on branch) diff --git a/src/build_metadata/mod.rs b/src/build_metadata/mod.rs index cf3364c1..f50018d2 100644 --- a/src/build_metadata/mod.rs +++ b/src/build_metadata/mod.rs @@ -12,11 +12,16 @@ pub static VERSION_EXTRA: Option<&str> = v } else if let v @ Some(_) = option_env!("CONDUWUIT_VERSION_EXTRA") { v - } else if let v @ Some(_) = option_env!("CONDUIT_VERSION_EXTRA") { - v } else { - GIT_COMMIT_HASH_SHORT + option_env!("CONDUIT_VERSION_EXTRA") }; + +pub fn version_tag() -> Option<&'static str> { + VERSION_EXTRA + .filter(|s| !s.is_empty()) + .or(GIT_COMMIT_HASH_SHORT) +} + pub static GIT_REMOTE_WEB_URL: Option<&str> = option_env!("GIT_REMOTE_WEB_URL"); pub static GIT_REMOTE_COMMIT_URL: Option<&str> = option_env!("GIT_REMOTE_COMMIT_URL"); diff --git a/src/core/info/version.rs b/src/core/info/version.rs index 523c40a2..c22c8ec8 100644 --- a/src/core/info/version.rs +++ b/src/core/info/version.rs @@ -26,6 +26,6 @@ pub fn user_agent() -> &'static str { USER_AGENT.get_or_init(init_user_agent) } fn init_user_agent() -> String { format!("{}/{}", name(), version()) } fn init_version() -> String { - conduwuit_build_metadata::VERSION_EXTRA + conduwuit_build_metadata::version_tag() .map_or(SEMANTIC.to_owned(), |extra| format!("{SEMANTIC} ({extra})")) } diff --git a/src/web/mod.rs b/src/web/mod.rs index 25ec868c..9c6a5d83 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -6,7 +6,7 @@ use axum::{ response::{Html, IntoResponse, Response}, routing::get, }; -use conduwuit_build_metadata::{GIT_REMOTE_COMMIT_URL, GIT_REMOTE_WEB_URL, VERSION_EXTRA}; +use conduwuit_build_metadata::{GIT_REMOTE_COMMIT_URL, GIT_REMOTE_WEB_URL, version_tag}; use conduwuit_service::state; pub fn build() -> Router { diff --git a/src/web/templates/_layout.html.j2 b/src/web/templates/_layout.html.j2 index fd0a5b29..d298b68c 100644 --- a/src/web/templates/_layout.html.j2 +++ b/src/web/templates/_layout.html.j2 @@ -18,7 +18,7 @@ {%~ block footer ~%}

Powered by Continuwuity - {%~ if let Some(version_info) = VERSION_EXTRA ~%} + {%~ if let Some(version_info) = self::version_tag() ~%} {%~ if let Some(url) = GIT_REMOTE_COMMIT_URL.or(GIT_REMOTE_WEB_URL) ~%} ({{ version_info }}) {%~ else ~%} From fce024b30b60fde435b211e7edd2131c8a2613c4 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 21 May 2025 12:45:14 +0100 Subject: [PATCH 2002/2291] chore: Add must_use annotation --- src/build_metadata/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/build_metadata/mod.rs b/src/build_metadata/mod.rs index f50018d2..86a8a800 100644 --- a/src/build_metadata/mod.rs +++ b/src/build_metadata/mod.rs @@ -16,6 +16,7 @@ pub static VERSION_EXTRA: Option<&str> = option_env!("CONDUIT_VERSION_EXTRA") }; +#[must_use] pub fn version_tag() -> Option<&'static str> { VERSION_EXTRA .filter(|s| !s.is_empty()) From dcbc4b54c51b6325925d477f2cf31e2679d34759 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 21 May 2025 12:45:25 +0100 Subject: [PATCH 2003/2291] ci: Always show sccache stats --- .forgejo/workflows/rust-checks.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.forgejo/workflows/rust-checks.yml b/.forgejo/workflows/rust-checks.yml index 1feb9e89..35ca1ad7 100644 --- a/.forgejo/workflows/rust-checks.yml +++ b/.forgejo/workflows/rust-checks.yml @@ -80,6 +80,7 @@ jobs: -D warnings - name: Show sccache stats + if: always() run: sccache --show-stats cargo-test: @@ -137,4 +138,5 @@ jobs: --no-fail-fast - name: Show sccache stats + if: always() run: sccache --show-stats From ce40304667f5bcb31f16978d955a51595da26c2a Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 21 May 2025 15:28:46 +0100 Subject: [PATCH 2004/2291] chore: Upgrade deps --- Cargo.lock | 431 ++++++++++++++++++++++++----------------------------- 1 file changed, 191 insertions(+), 240 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04e4f36e..160be0c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,9 +55,9 @@ checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anyhow" -version = "1.0.97" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" [[package]] name = "arbitrary" @@ -170,9 +170,9 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a194f9d963d8099596278594b3107448656ba73831c9d8c783e613ce86da64" +checksum = "b37fc50485c4f3f736a4fb14199f6d5f5ba008d7f28fe710306c92780f004c07" dependencies = [ "brotli", "flate2", @@ -184,17 +184,6 @@ dependencies = [ "zstd-safe", ] -[[package]] -name = "async-recursion" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "async-stream" version = "0.3.6" @@ -284,9 +273,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.28.0" +version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f7720b74ed28ca77f90769a71fd8c637a0137f6fae4ae947e1050229cff57f" +checksum = "bfa9b6986f250236c27e5a204062434a773a13243d2ffc2955f37bdba4c5c6a1" dependencies = [ "bindgen 0.69.5", "cc", @@ -426,9 +415,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.74" +version = "0.3.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002" dependencies = [ "addr2line", "cfg-if", @@ -560,9 +549,9 @@ dependencies = [ [[package]] name = "brotli" -version = "7.0.0" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc97b8f16f944bba54f0433f07e30be199b6dc2bd25937444bbad560bcea29bd" +checksum = "9991eea70ea4f293524138648e41ee89b0b2b12ddef3b255effa43c8056e0e0d" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -571,9 +560,9 @@ dependencies = [ [[package]] name = "brotli-decompressor" -version = "4.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74fa05ad7d803d413eb8380983b092cbbaf9a85f151b871360e7b00cd7060b37" +checksum = "874bb8112abecc98cbd6d81ea4fa7e94fb9449648c93cc89aa40c81c24d7de03" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -599,9 +588,9 @@ checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" [[package]] name = "bytemuck" -version = "1.22.0" +version = "1.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6b1fc10dbac614ebc03540c9dbd60e83887fda27794998c6528f1782047d540" +checksum = "9134a6ef01ce4b366b50689c94f82c14bc72bc5d0386829828a2e2752ef7958c" [[package]] name = "byteorder" @@ -649,9 +638,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.17" +version = "1.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a" +checksum = "32db95edf998450acc7881c932f94cd9b05c87b4b2599e8bab064753da4acfd1" dependencies = [ "jobserver", "libc", @@ -700,9 +689,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.40" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" dependencies = [ "num-traits", ] @@ -720,9 +709,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.35" +version = "4.5.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8aa86934b44c19c50f87cc2790e19f54f7a67aedb64101c2e1a2e5ecfb73944" +checksum = "ed93b9805f8ba930df42c2590f05453d5ec36cbb85d018868a5b24d31f6ac000" dependencies = [ "clap_builder", "clap_derive", @@ -730,9 +719,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.35" +version = "4.5.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2414dbb2dd0695280da6ea9261e327479e9d37b0630f6b53ba2a11c60c679fd9" +checksum = "379026ff283facf611b0ea629334361c4211d1b12ee01024eec1591133b04120" dependencies = [ "anstyle", "clap_lex", @@ -1003,7 +992,7 @@ dependencies = [ "const-str", "either", "futures", - "hickory-resolver 0.25.1", + "hickory-resolver 0.25.2", "http", "image", "ipaddress", @@ -1326,9 +1315,9 @@ checksum = "817fa642fb0ee7fe42e95783e00e0969927b96091bdd4b9b1af082acd943913b" [[package]] name = "data-encoding" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "575f75dfd25738df5b91b8e43e14d44bda14637a58fae779fd2b064f8bf3e010" +checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" [[package]] name = "date_header" @@ -1447,9 +1436,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" dependencies = [ "libc", "windows-sys 0.59.0", @@ -1690,7 +1679,7 @@ dependencies = [ "libc", "log", "rustversion", - "windows 0.58.0", + "windows", ] [[package]] @@ -1705,9 +1694,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "js-sys", @@ -1718,9 +1707,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", "js-sys", @@ -1754,9 +1743,9 @@ checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "h2" -version = "0.4.8" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5017294ff4bb30944501348f6f8e42e6ad28f42c8bbef7a74029aff064a4e3c2" +checksum = "a9421a676d1b147b16b82c9225157dc629087ef8ec4d5e2960f9437a90dac0a5" dependencies = [ "atomic-waker", "bytes", @@ -1764,7 +1753,7 @@ dependencies = [ "futures-core", "futures-sink", "http", - "indexmap 2.8.0", + "indexmap 2.9.0", "slab", "tokio", "tokio-util", @@ -1773,9 +1762,9 @@ dependencies = [ [[package]] name = "half" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7db2ff139bba50379da6aa0766b52fdcb62cb5b263009b09ed58ba604e14bbd1" +checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9" dependencies = [ "cfg-if", "crunchy", @@ -1795,9 +1784,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.15.2" +version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" [[package]] name = "hdrhistogram" @@ -1880,14 +1869,12 @@ dependencies = [ [[package]] name = "hickory-proto" -version = "0.25.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d844af74f7b799e41c78221be863bade11c430d46042c3b49ca8ae0c6d27287" +checksum = "f8a6fe56c0038198998a6f217ca4e7ef3a5e51f46163bd6dd60b5c71ca6c6502" dependencies = [ - "async-recursion", "async-trait", "cfg-if", - "critical-section", "data-encoding", "enum-as-inner", "futures-channel", @@ -1896,7 +1883,7 @@ dependencies = [ "idna", "ipnet", "once_cell", - "rand 0.9.0", + "rand 0.9.1", "ring", "serde", "thiserror 2.0.12", @@ -1929,18 +1916,18 @@ dependencies = [ [[package]] name = "hickory-resolver" -version = "0.25.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a128410b38d6f931fcc6ca5c107a3b02cabd6c05967841269a4ad65d23c44331" +checksum = "dc62a9a99b0bfb44d2ab95a7208ac952d31060efc16241c87eaf36406fecf87a" dependencies = [ "cfg-if", "futures-util", - "hickory-proto 0.25.1", + "hickory-proto 0.25.2", "ipconfig", "moka", "once_cell", "parking_lot", - "rand 0.9.0", + "rand 0.9.1", "resolv-conf", "serde", "smallvec", @@ -1969,13 +1956,13 @@ dependencies = [ [[package]] name = "hostname" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9c7c7c8ac16c798734b8a24560c1362120597c40d5e1459f09498f8f6c8f2ba" +checksum = "a56f203cd1c76362b69e3863fd987520ac36cf70a8c92627449b2f64a8cf7d65" dependencies = [ "cfg-if", "libc", - "windows 0.52.0", + "windows-link", ] [[package]] @@ -2127,21 +2114,22 @@ dependencies = [ [[package]] name = "icu_collections" -version = "1.5.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +checksum = "200072f5d0e3614556f94a9930d5dc3e0662a652823904c3a75dc3b0af7fee47" dependencies = [ "displaydoc", + "potential_utf", "yoke", "zerofrom", "zerovec", ] [[package]] -name = "icu_locid" -version = "1.5.0" +name = "icu_locale_core" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +checksum = "0cde2700ccaed3872079a65fb1a78f6c0a36c91570f28755dda67bc8f7d9f00a" dependencies = [ "displaydoc", "litemap", @@ -2150,31 +2138,11 @@ dependencies = [ "zerovec", ] -[[package]] -name = "icu_locid_transform" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" -dependencies = [ - "displaydoc", - "icu_locid", - "icu_locid_transform_data", - "icu_provider", - "tinystr", - "zerovec", -] - -[[package]] -name = "icu_locid_transform_data" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d" - [[package]] name = "icu_normalizer" -version = "1.5.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +checksum = "436880e8e18df4d7bbc06d58432329d6458cc84531f7ac5f024e93deadb37979" dependencies = [ "displaydoc", "icu_collections", @@ -2182,67 +2150,54 @@ dependencies = [ "icu_properties", "icu_provider", "smallvec", - "utf16_iter", - "utf8_iter", - "write16", "zerovec", ] [[package]] name = "icu_normalizer_data" -version = "1.5.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e8338228bdc8ab83303f16b797e177953730f601a96c25d10cb3ab0daa0cb7" +checksum = "00210d6893afc98edb752b664b8890f0ef174c8adbb8d0be9710fa66fbbf72d3" [[package]] name = "icu_properties" -version = "1.5.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +checksum = "2549ca8c7241c82f59c80ba2a6f415d931c5b58d24fb8412caa1a1f02c49139a" dependencies = [ "displaydoc", "icu_collections", - "icu_locid_transform", + "icu_locale_core", "icu_properties_data", "icu_provider", - "tinystr", + "potential_utf", + "zerotrie", "zerovec", ] [[package]] name = "icu_properties_data" -version = "1.5.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85fb8799753b75aee8d2a21d7c14d9f38921b54b3dbda10f5a3c7a7b82dba5e2" +checksum = "8197e866e47b68f8f7d95249e172903bec06004b18b2937f1095d40a0c57de04" [[package]] name = "icu_provider" -version = "1.5.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +checksum = "03c80da27b5f4187909049ee2d72f276f0d9f99a42c306bd0131ecfe04d8e5af" dependencies = [ "displaydoc", - "icu_locid", - "icu_provider_macros", + "icu_locale_core", "stable_deref_trait", "tinystr", "writeable", "yoke", "zerofrom", + "zerotrie", "zerovec", ] -[[package]] -name = "icu_provider_macros" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "idna" version = "1.0.3" @@ -2256,9 +2211,9 @@ dependencies = [ [[package]] name = "idna_adapter" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" dependencies = [ "icu_normalizer", "icu_properties", @@ -2315,12 +2270,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" dependencies = [ "equivalent", - "hashbrown 0.15.2", + "hashbrown 0.15.3", "serde", ] @@ -2418,7 +2373,7 @@ version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" dependencies = [ - "getrandom 0.3.2", + "getrandom 0.3.3", "libc", ] @@ -2519,9 +2474,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.171" +version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "libfuzzer-sys" @@ -2535,12 +2490,12 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" +checksum = "6a793df0d7afeac54f95b471d3af7f0d4fb975699f972341a4b76988d49cdf0c" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.53.0", ] [[package]] @@ -2568,9 +2523,9 @@ checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" [[package]] name = "litemap" -version = "0.7.5" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" +checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" [[package]] name = "lock_api" @@ -2590,9 +2545,9 @@ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "loole" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2998397c725c822c6b2ba605fd9eb4c6a7a0810f1629ba3cc232ef4f0308d96" +checksum = "1a3932a13b27d6b2d37efec3e4047017d59a8c9f2283a29bde29151d22f00fe9" dependencies = [ "futures-core", "futures-sink", @@ -2716,9 +2671,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "minicbor" -version = "0.26.3" +version = "0.26.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1936e27fffe7d8557c060eb82cb71668608cd1a5fb56b63e66d22ae8d7564321" +checksum = "8a309f581ade7597820083bc275075c4c6986e57e53f8d26f88507cfefc8c987" dependencies = [ "minicbor-derive", ] @@ -2761,9 +2716,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5" +checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" dependencies = [ "adler2", "simd-adler32", @@ -2983,7 +2938,7 @@ checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" dependencies = [ "futures-core", "futures-sink", - "indexmap 2.8.0", + "indexmap 2.9.0", "js-sys", "once_cell", "pin-project-lite", @@ -3253,6 +3208,15 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" +[[package]] +name = "potential_utf" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5a7c30837279ca13e7c867e9e40053bc68740f988cb07f7ca6df43cc734b585" +dependencies = [ + "zerovec", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -3295,9 +3259,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -3426,8 +3390,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b820744eb4dc9b57a3398183639c511b5a26d2ed702cedd3febaa1393caa22cc" dependencies = [ "bytes", - "getrandom 0.3.2", - "rand 0.9.0", + "getrandom 0.3.3", + "rand 0.9.1", "ring", "rustc-hash 2.1.1", "rustls", @@ -3481,13 +3445,12 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" dependencies = [ "rand_chacha 0.9.0", "rand_core 0.9.3", - "zerocopy", ] [[package]] @@ -3516,7 +3479,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.15", + "getrandom 0.2.16", ] [[package]] @@ -3525,7 +3488,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ - "getrandom 0.3.2", + "getrandom 0.3.3", ] [[package]] @@ -3565,9 +3528,9 @@ dependencies = [ [[package]] name = "ravif" -version = "0.11.11" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2413fd96bd0ea5cdeeb37eaf446a22e6ed7b981d792828721e74ded1980a45c6" +checksum = "d6a5f31fcf7500f9401fea858ea4ab5525c99f2322cfcee732c0e6c74208c0c6" dependencies = [ "avif-serialize", "imgref", @@ -3600,9 +3563,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.10" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1" +checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" dependencies = [ "bitflags 2.9.0", ] @@ -3723,7 +3686,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom 0.2.15", + "getrandom 0.2.16", "libc", "untrusted", "windows-sys 0.52.0", @@ -3793,9 +3756,9 @@ dependencies = [ "base64 0.22.1", "bytes", "form_urlencoded", - "getrandom 0.2.15", + "getrandom 0.2.16", "http", - "indexmap 2.8.0", + "indexmap 2.9.0", "js_int", "konst", "percent-encoding", @@ -3822,7 +3785,7 @@ version = "0.28.1" source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" dependencies = [ "as_variant", - "indexmap 2.8.0", + "indexmap 2.9.0", "js_int", "js_option", "percent-encoding", @@ -3993,9 +3956,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.25" +version = "0.23.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "822ee9188ac4ec04a2f0531e55d035fb2de73f18b41a63c70c2712503b6fb13c" +checksum = "730944ca083c1c233a75c09f199e973ca499344a2b7ba9e755c457e86fb4a321" dependencies = [ "aws-lc-rs", "log", @@ -4030,18 +3993,19 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" +checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" dependencies = [ "web-time 1.1.0", + "zeroize", ] [[package]] name = "rustls-webpki" -version = "0.103.1" +version = "0.103.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03" +checksum = "e4a72fe2bcf7a6ac6fd7d0b9e5cb68aeb7d4c0a0271730218b3e92d43b4eb435" dependencies = [ "aws-lc-rs", "ring", @@ -4306,7 +4270,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d2de91cf02bbc07cde38891769ccd5d4f073d22a40683aa4bc7a95781aaa2c4" dependencies = [ "form_urlencoded", - "indexmap 2.8.0", + "indexmap 2.9.0", "itoa", "ryu", "serde", @@ -4371,7 +4335,7 @@ version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.8.0", + "indexmap 2.9.0", "itoa", "ryu", "serde", @@ -4391,9 +4355,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.8" +version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", "cpufeatures", @@ -4438,9 +4402,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.2" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" dependencies = [ "libc", ] @@ -4496,9 +4460,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" +checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" dependencies = [ "serde", ] @@ -4577,9 +4541,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.100" +version = "2.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" dependencies = [ "proc-macro2", "quote", @@ -4597,9 +4561,9 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", @@ -4644,9 +4608,9 @@ dependencies = [ [[package]] name = "termimad" -version = "0.31.2" +version = "0.31.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8e19c6dbf107bec01d0e216bb8219485795b7d75328e4fa5ef2756c1be4f8dc" +checksum = "7301d9c2c4939c97f25376b70d3c13311f8fefdee44092fc361d2a98adc2cbb6" dependencies = [ "coolor", "crokey", @@ -4654,7 +4618,7 @@ dependencies = [ "lazy-regex", "minimad", "serde", - "thiserror 1.0.69", + "thiserror 2.0.12", "unicode-width 0.1.14", ] @@ -4812,9 +4776,9 @@ dependencies = [ [[package]] name = "tinystr" -version = "0.7.6" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +checksum = "5d4f6d1145dcb577acf783d4e601bc1d76a13337bb54e6233add580b07344c8b" dependencies = [ "displaydoc", "zerovec", @@ -4837,9 +4801,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.44.2" +version = "1.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" +checksum = "2513ca694ef9ede0fb23fe71a4ee4107cb102b9dc1930f6d0fd77aae068ae165" dependencies = [ "backtrace", "bytes", @@ -4866,9 +4830,9 @@ dependencies = [ [[package]] name = "tokio-metrics" -version = "0.4.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb2bb07a8451c4c6fa8b3497ad198510d8b8dffa5df5cfb97a64102a58b113c8" +checksum = "7817b32d36c9b94744d7aa3f8fc13526aa0f5112009d7045f3c659413a6e44ac" dependencies = [ "futures-util", "pin-project-lite", @@ -4911,9 +4875,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.14" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034" +checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df" dependencies = [ "bytes", "futures-core", @@ -4924,9 +4888,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.20" +version = "0.8.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148" +checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae" dependencies = [ "serde", "serde_spanned", @@ -4936,26 +4900,33 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.8" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.24" +version = "0.22.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" +checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e" dependencies = [ - "indexmap 2.8.0", + "indexmap 2.9.0", "serde", "serde_spanned", "toml_datetime", + "toml_write", "winnow", ] +[[package]] +name = "toml_write" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076" + [[package]] name = "tonic" version = "0.12.3" @@ -5023,9 +4994,9 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.6.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403fa3b783d4b626a8ad51d766ab03cb6d2dbfc46b1c5d4448395e6628dc9697" +checksum = "0fdb0c213ca27a9f57ab69ddb290fd80d970922355b83ae380b395d3986b8a2e" dependencies = [ "async-compression", "bitflags 2.9.0", @@ -5267,12 +5238,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "utf16_iter" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" - [[package]] name = "utf8_iter" version = "1.0.4" @@ -5285,7 +5250,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "458f7a779bf54acc9f347480ac654f68407d3aab21269a6e3c9f922acd9e2da9" dependencies = [ - "getrandom 0.3.2", + "getrandom 0.3.3", "serde", ] @@ -5522,32 +5487,13 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" -dependencies = [ - "windows-core 0.52.0", - "windows-targets 0.52.6", -] - [[package]] name = "windows" version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" dependencies = [ - "windows-core 0.58.0", - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ + "windows-core", "windows-targets 0.52.6", ] @@ -5854,9 +5800,9 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "winnow" -version = "0.7.4" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36" +checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" dependencies = [ "memchr", ] @@ -5880,17 +5826,11 @@ dependencies = [ "bitflags 2.9.0", ] -[[package]] -name = "write16" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" - [[package]] name = "writeable" -version = "0.5.5" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" +checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" [[package]] name = "xml5ever" @@ -5911,9 +5851,9 @@ checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "yoke" -version = "0.7.5" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +checksum = "5f41bb01b8226ef4bfd589436a297c53d118f65921786300e427be8d487695cc" dependencies = [ "serde", "stable_deref_trait", @@ -5923,9 +5863,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.7.5" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" dependencies = [ "proc-macro2", "quote", @@ -5935,18 +5875,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.24" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" +checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.24" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" +checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" dependencies = [ "proc-macro2", "quote", @@ -5981,10 +5921,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" [[package]] -name = "zerovec" -version = "0.10.4" +name = "zerotrie" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +checksum = "36f0bbd478583f79edad978b407914f61b2972f5af6fa089686016be8f9af595" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a05eb080e015ba39cc9e23bbe5e7fb04d5fb040350f99f34e338d5fdd294428" dependencies = [ "yoke", "zerofrom", @@ -5993,9 +5944,9 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.10.3" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" dependencies = [ "proc-macro2", "quote", From 60960c6e099c7ec249dd29c7396328a4907fe6ba Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 21 May 2025 20:29:53 +0100 Subject: [PATCH 2005/2291] feat: Automatically set well-known support contacts --- conduwuit-example.toml | 20 +++++++++---- src/api/client/well_known.rs | 54 +++++++++++++++++++++++++----------- src/core/config/mod.rs | 16 +++++++++++ 3 files changed, 69 insertions(+), 21 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 6934e67c..1a8be2aa 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -1641,19 +1641,29 @@ # #server = -# This item is undocumented. Please contribute documentation for it. +# URL to a support page for the server, which will be served as part of +# the MSC1929 server support endpoint at /.well-known/matrix/support. +# Will be included alongside any contact information # #support_page = -# This item is undocumented. Please contribute documentation for it. +# Role string for server support contacts, to be served as part of the +# MSC1929 server support endpoint at /.well-known/matrix/support. # -#support_role = +#support_role = "m.role.admin" -# This item is undocumented. Please contribute documentation for it. +# Email address for server support contacts, to be served as part of the +# MSC1929 server support endpoint. +# This will be used along with support_mxid if specified. # #support_email = -# This item is undocumented. Please contribute documentation for it. +# Matrix ID for server support contacts, to be served as part of the +# MSC1929 server support endpoint. +# This will be used along with support_email if specified. +# +# If no email or mxid is specified, all of the server's admins will be +# listed. # #support_mxid = diff --git a/src/api/client/well_known.rs b/src/api/client/well_known.rs index 35b7fc1e..4981ccb4 100644 --- a/src/api/client/well_known.rs +++ b/src/api/client/well_known.rs @@ -1,5 +1,6 @@ use axum::{Json, extract::State, response::IntoResponse}; use conduwuit::{Error, Result}; +use futures::StreamExt; use ruma::api::client::{ discovery::{ discover_homeserver::{self, HomeserverInfo, SlidingSyncProxyInfo}, @@ -33,6 +34,8 @@ pub(crate) async fn well_known_client( /// # `GET /.well-known/matrix/support` /// /// Server support contact and support page of a homeserver's domain. +/// Implements MSC1929 for server discovery. +/// If no configuration is set, uses admin users as contacts. pub(crate) async fn well_known_support( State(services): State, _body: Ruma, @@ -45,32 +48,51 @@ pub(crate) async fn well_known_support( .as_ref() .map(ToString::to_string); - let role = services.server.config.well_known.support_role.clone(); - - // support page or role must be either defined for this to be valid - if support_page.is_none() && role.is_none() { - return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")); - } - let email_address = services.server.config.well_known.support_email.clone(); let matrix_id = services.server.config.well_known.support_mxid.clone(); - // if a role is specified, an email address or matrix id is required - if role.is_some() && (email_address.is_none() && matrix_id.is_none()) { - return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")); - } - // TODO: support defining multiple contacts in the config let mut contacts: Vec = vec![]; - if let Some(role) = role { - let contact = Contact { role, email_address, matrix_id }; + let role_value = services + .server + .config + .well_known + .support_role + .clone() + .unwrap_or_else(|| "m.role.admin".to_owned().into()); - contacts.push(contact); + // Add configured contact if at least one contact method is specified + if email_address.is_some() || matrix_id.is_some() { + contacts.push(Contact { + role: role_value.clone(), + email_address: email_address.clone(), + matrix_id: matrix_id.clone(), + }); + } + + // Try to add admin users as contacts if no contacts are configured + if contacts.is_empty() { + if let Ok(admin_room) = services.admin.get_admin_room().await { + let admin_users = services.rooms.state_cache.room_members(&admin_room); + let mut stream = admin_users; + + while let Some(user_id) = stream.next().await { + // Skip server user + if *user_id == services.globals.server_user { + break; + } + contacts.push(Contact { + role: role_value.clone(), + email_address: None, + matrix_id: Some(user_id.to_owned()), + }); + } + } } - // support page or role+contacts must be either defined for this to be valid if contacts.is_empty() && support_page.is_none() { + // No admin room, no configured contacts, and no support page return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")); } diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 66ed0b2e..d4a10345 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -1897,12 +1897,28 @@ pub struct WellKnownConfig { /// example: "matrix.example.com:443" pub server: Option, + /// URL to a support page for the server, which will be served as part of + /// the MSC1929 server support endpoint at /.well-known/matrix/support. + /// Will be included alongside any contact information pub support_page: Option, + /// Role string for server support contacts, to be served as part of the + /// MSC1929 server support endpoint at /.well-known/matrix/support. + /// + /// default: "m.role.admin" pub support_role: Option, + /// Email address for server support contacts, to be served as part of the + /// MSC1929 server support endpoint. + /// This will be used along with support_mxid if specified. pub support_email: Option, + /// Matrix ID for server support contacts, to be served as part of the + /// MSC1929 server support endpoint. + /// This will be used along with support_email if specified. + /// + /// If no email or mxid is specified, all of the server's admins will be + /// listed. pub support_mxid: Option, } From 2ccbd7d60b12c9c9d65bde027f4c974665022b28 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 21 May 2025 21:06:44 +0100 Subject: [PATCH 2006/2291] fix: Reference config directly --- src/api/client/well_known.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/api/client/well_known.rs b/src/api/client/well_known.rs index 4981ccb4..fe2281ba 100644 --- a/src/api/client/well_known.rs +++ b/src/api/client/well_known.rs @@ -18,7 +18,7 @@ pub(crate) async fn well_known_client( State(services): State, _body: Ruma, ) -> Result { - let client_url = match services.server.config.well_known.client.as_ref() { + let client_url = match services.config.well_known.client.as_ref() { | Some(url) => url.to_string(), | None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")), }; @@ -41,21 +41,19 @@ pub(crate) async fn well_known_support( _body: Ruma, ) -> Result { let support_page = services - .server .config .well_known .support_page .as_ref() .map(ToString::to_string); - let email_address = services.server.config.well_known.support_email.clone(); - let matrix_id = services.server.config.well_known.support_mxid.clone(); + let email_address = services.config.well_known.support_email.clone(); + let matrix_id = services.config.well_known.support_mxid.clone(); // TODO: support defining multiple contacts in the config let mut contacts: Vec = vec![]; let role_value = services - .server .config .well_known .support_role @@ -106,9 +104,9 @@ pub(crate) async fn well_known_support( pub(crate) async fn syncv3_client_server_json( State(services): State, ) -> Result { - let server_url = match services.server.config.well_known.client.as_ref() { + let server_url = match services.config.well_known.client.as_ref() { | Some(url) => url.to_string(), - | None => match services.server.config.well_known.server.as_ref() { + | None => match services.config.well_known.server.as_ref() { | Some(url) => url.to_string(), | None => return Err(Error::BadRequest(ErrorKind::NotFound, "Not found.")), }, From 0ba77674c72324b6f533acfc8d2cbf328b9448a0 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 25 May 2025 00:36:28 +0100 Subject: [PATCH 2007/2291] docs: Security policy --- SECURITY.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ docs/SUMMARY.md | 1 + docs/security.md | 1 + 3 files changed, 61 insertions(+) create mode 100644 SECURITY.md create mode 100644 docs/security.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..c5355491 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,59 @@ +# Security Policy for Continuwuity + +This document outlines the security policy for Continuwuity. Our goal is to maintain a secure platform for all users, and we take security matters seriously. + +## Supported Versions + +We provide security updates for the following versions of Continuwuity: + +| Version | Supported | +| -------------- |:----------------:| +| Latest release | ✅ | +| Main branch | ✅ | +| Older releases | ❌ | + +## Reporting a Vulnerability + +### Responsible Disclosure + +We appreciate the efforts of security researchers and the community in identifying and reporting vulnerabilities. To ensure that potential vulnerabilities are addressed properly, please follow these guidelines: + +1. **Email the security team** directly at [security@continuwuity.org](mailto:security@continuwuity.org) +2. Contact members of the team over E2EE private message. + - [@jade:ellis.link](https://matrix.to/#/@jade:ellis.link) + - [@nex:nexy7574.co.uk](https://matrix.to/#/@nex:nexy7574.co.uk) +3. **Do not disclose the vulnerability publicly** until it has been addressed +4. **Provide detailed information** about the vulnerability, including: + - A clear description of the issue + - Steps to reproduce + - Potential impact + - Any possible mitigations + - Version(s) affected, including specific commits if possible + +### What to Expect + +When you report a security vulnerability: + +1. **Acknowledgment**: We will acknowledge receipt of your report. +2. **Assessment**: We will assess the vulnerability and determine its impact on our users +3. **Updates**: We will provide updates on our progress in addressing the vulnerability, and may request you help test mitigations +4. **Resolution**: Once resolved, we will notify you and discuss coordinated disclosure +5. **Credit**: We will recognize your contribution (unless you prefer to remain anonymous) + +## Security Update Process + +When security vulnerabilities are identified: + +1. We will develop and test fixes in a private branch +2. Security updates will be released as soon as possible +3. Release notes will include information about the vulnerabilities, avoiding details that could facilitate exploitation where possible +4. Critical security updates may be backported to the previous stable release + +## Additional Resources + +- [Matrix Security Disclosure Policy](https://matrix.org/security-disclosure-policy/) +- [Continuwuity Documentation](https://continuwuity.org/introduction) + +--- + +This security policy was last updated on May 25, 2025. diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 473c9e74..af729003 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -20,3 +20,4 @@ - [Testing](development/testing.md) - [Hot Reloading ("Live" Development)](development/hot_reload.md) - [Community (and Guidelines)](community.md) +- [Security](security.md) diff --git a/docs/security.md b/docs/security.md new file mode 100644 index 00000000..b4474cf5 --- /dev/null +++ b/docs/security.md @@ -0,0 +1 @@ +{{#include ../SECURITY.md}} From e8d823a65340a891693339dd5a5dd53e6732fb61 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Mon, 26 May 2025 15:01:58 +0100 Subject: [PATCH 2008/2291] docs: Apply feedback on security policy --- SECURITY.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index c5355491..a9aa183e 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -12,16 +12,18 @@ We provide security updates for the following versions of Continuwuity: | Main branch | ✅ | | Older releases | ❌ | +We may backport fixes to the previous release at our discretion, but we don't guarantee this. + ## Reporting a Vulnerability ### Responsible Disclosure We appreciate the efforts of security researchers and the community in identifying and reporting vulnerabilities. To ensure that potential vulnerabilities are addressed properly, please follow these guidelines: -1. **Email the security team** directly at [security@continuwuity.org](mailto:security@continuwuity.org) -2. Contact members of the team over E2EE private message. +1. Contact members of the team over E2EE private message. - [@jade:ellis.link](https://matrix.to/#/@jade:ellis.link) - [@nex:nexy7574.co.uk](https://matrix.to/#/@nex:nexy7574.co.uk) +2. **Email the security team** directly at [security@continuwuity.org](mailto:security@continuwuity.org). This is not E2EE, so don't include sensitive details. 3. **Do not disclose the vulnerability publicly** until it has been addressed 4. **Provide detailed information** about the vulnerability, including: - A clear description of the issue @@ -30,6 +32,8 @@ We appreciate the efforts of security researchers and the community in identifyi - Any possible mitigations - Version(s) affected, including specific commits if possible +If you have any doubts about a potential security vulnerability, contact us via private channels first! We'd prefer that you bother us, instead of having a vulnerability disclosed without a fix. + ### What to Expect When you report a security vulnerability: From 2b268fdaf3c9a8ff96c7e6d438a754e7d4cdec3d Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 21 May 2025 14:16:58 +0100 Subject: [PATCH 2009/2291] fix: Allow joining via invite for knock_restricted rooms --- src/core/matrix/state_res/event_auth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/matrix/state_res/event_auth.rs b/src/core/matrix/state_res/event_auth.rs index 715e5156..759ab5cb 100644 --- a/src/core/matrix/state_res/event_auth.rs +++ b/src/core/matrix/state_res/event_auth.rs @@ -638,7 +638,7 @@ fn valid_membership_change( warn!(?target_user_membership_event_id, "Banned user can't join"); false } else if (join_rules == JoinRule::Invite - || room_version.allow_knocking && join_rules == JoinRule::Knock) + || room_version.allow_knocking && (join_rules == JoinRule::Knock || matches!(join_rules, JoinRule::KnockRestricted(_)))) // If the join_rule is invite then allow if membership state is invite or join && (target_user_current_membership == MembershipState::Join || target_user_current_membership == MembershipState::Invite) From 640714922bb058e6b3251ff17eff84bd07b90c5f Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 21 May 2025 14:17:47 +0100 Subject: [PATCH 2010/2291] feat: For knock_restricted rooms, automatically join rooms we meet restrictions for rather than knocking --- src/api/client/membership.rs | 109 +++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs index 2847d668..e587d806 100644 --- a/src/api/client/membership.rs +++ b/src/api/client/membership.rs @@ -2162,6 +2162,109 @@ async fn knock_room_by_id_helper( } } + // For knock_restricted rooms, check if the user meets the restricted conditions + // If they do, attempt to join instead of knock + // This is not mentioned in the spec, but should be allowable (we're allowed to + // auto-join invites to knocked rooms) + let join_rule = services.rooms.state_accessor.get_join_rules(room_id).await; + if let JoinRule::KnockRestricted(restricted) = &join_rule { + let restriction_rooms: Vec<_> = restricted + .allow + .iter() + .filter_map(|a| match a { + | AllowRule::RoomMembership(r) => Some(&r.room_id), + | _ => None, + }) + .collect(); + + // Check if the user is in any of the allowed rooms + let mut user_meets_restrictions = false; + for restriction_room_id in &restriction_rooms { + if services + .rooms + .state_cache + .is_joined(sender_user, restriction_room_id) + .await + { + user_meets_restrictions = true; + break; + } + } + + // If the user meets the restrictions, try joining instead + if user_meets_restrictions { + debug_info!( + "{sender_user} meets the restricted criteria in knock_restricted room \ + {room_id}, attempting to join instead of knock" + ); + // For this case, we need to drop the state lock and get a new one in + // join_room_by_id_helper We need to release the lock here and let + // join_room_by_id_helper acquire it again + drop(state_lock); + match join_room_by_id_helper( + services, + sender_user, + room_id, + reason.clone(), + servers, + None, + &None, + ) + .await + { + | Ok(_) => return Ok(knock_room::v3::Response::new(room_id.to_owned())), + | Err(e) => { + debug_warn!( + "Failed to convert knock to join for {sender_user} in {room_id}: {e:?}" + ); + // Get a new state lock for the remaining knock logic + let new_state_lock = services.rooms.state.mutex.lock(room_id).await; + + let server_in_room = services + .rooms + .state_cache + .server_in_room(services.globals.server_name(), room_id) + .await; + + let local_knock = server_in_room + || servers.is_empty() + || (servers.len() == 1 && services.globals.server_is_ours(&servers[0])); + + if local_knock { + knock_room_helper_local( + services, + sender_user, + room_id, + reason, + servers, + new_state_lock, + ) + .boxed() + .await?; + } else { + knock_room_helper_remote( + services, + sender_user, + room_id, + reason, + servers, + new_state_lock, + ) + .boxed() + .await?; + } + + return Ok(knock_room::v3::Response::new(room_id.to_owned())); + }, + } + } + } else if !matches!(join_rule, JoinRule::Knock | JoinRule::KnockRestricted(_)) { + debug_warn!( + "{sender_user} attempted to knock on room {room_id} but its join rule is \ + {join_rule:?}, not knock or knock_restricted" + ); + } + let server_in_room = services .rooms .state_cache @@ -2209,6 +2312,12 @@ async fn knock_room_helper_local( return Err!(Request(Forbidden("This room does not support knocking."))); } + // Verify that this room has a valid knock or knock_restricted join rule + let join_rule = services.rooms.state_accessor.get_join_rules(room_id).await; + if !matches!(join_rule, JoinRule::Knock | JoinRule::KnockRestricted(_)) { + return Err!(Request(Forbidden("This room's join rule does not allow knocking."))); + } + let content = RoomMemberEventContent { displayname: services.users.displayname(sender_user).await.ok(), avatar_url: services.users.avatar_url(sender_user).await.ok(), From 94ae82414947342ac967bd05c8933d54d9ffc223 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 22 May 2025 14:01:16 +0100 Subject: [PATCH 2011/2291] ci: Don't install rustup if it's already there --- .forgejo/actions/rust-toolchain/action.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.forgejo/actions/rust-toolchain/action.yml b/.forgejo/actions/rust-toolchain/action.yml index 71fb96f5..ae5cfcee 100644 --- a/.forgejo/actions/rust-toolchain/action.yml +++ b/.forgejo/actions/rust-toolchain/action.yml @@ -19,11 +19,20 @@ outputs: rustc_version: description: The rustc version installed value: ${{ steps.rustc-version.outputs.version }} + rustup_version: + description: The rustup version installed + value: ${{ steps.rustup-version.outputs.version }} runs: using: composite steps: + - name: Check if rustup is already installed + shell: bash + id: rustup-version + run: | + echo "version=$(rustup --version)" >> $GITHUB_OUTPUT - name: Cache rustup toolchains + if: steps.rustup-version.outputs.version == '' uses: actions/cache@v3 with: path: | @@ -33,6 +42,7 @@ runs: # Requires repo to be cloned if toolchain is not specified key: ${{ runner.os }}-rustup-${{ inputs.toolchain || hashFiles('**/rust-toolchain.toml') }} - name: Install Rust toolchain + if: steps.rustup-version.outputs.version == '' shell: bash run: | if ! command -v rustup &> /dev/null ; then From b9d60c64e5e3c05a5263955649bc1a0f60b1d172 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 22 May 2025 14:07:22 +0100 Subject: [PATCH 2012/2291] ci: Don't specify container for image builder --- .forgejo/workflows/release-image.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index ec466c58..ec05fb45 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -57,7 +57,6 @@ jobs: build-image: runs-on: dind - container: ghcr.io/catthehacker/ubuntu:act-latest needs: define-variables permissions: contents: read @@ -211,7 +210,6 @@ jobs: merge: runs-on: dind - container: ghcr.io/catthehacker/ubuntu:act-latest needs: [define-variables, build-image] steps: - name: Download digests From ea5dc8e09d11065564f4483a622f82bb12450783 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 23 May 2025 21:10:48 +0100 Subject: [PATCH 2013/2291] fix: Use correct brand in clap version string --- src/core/mod.rs | 5 ++++- src/main/clap.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/mod.rs b/src/core/mod.rs index b91cdf0b..aaacd4d8 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -21,7 +21,10 @@ pub use ::toml; pub use ::tracing; pub use config::Config; pub use error::Error; -pub use info::{rustc_flags_capture, version, version::version}; +pub use info::{ + rustc_flags_capture, version, + version::{name, version}, +}; pub use matrix::{Event, EventTypeExt, PduCount, PduEvent, PduId, RoomVersion, pdu, state_res}; pub use server::Server; pub use utils::{ctor, dtor, implement, result, result::Result}; diff --git a/src/main/clap.rs b/src/main/clap.rs index 9b63af19..a3b2b19a 100644 --- a/src/main/clap.rs +++ b/src/main/clap.rs @@ -15,7 +15,7 @@ use conduwuit_core::{ #[clap( about, long_about = None, - name = "conduwuit", + name = conduwuit_core::name(), version = conduwuit_core::version(), )] pub(crate) struct Args { From b57be072c7fdab5c880fdebaeebe11f02648ac08 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 22 May 2025 14:14:06 +0100 Subject: [PATCH 2014/2291] build: Don't rerun on git changes --- src/build_metadata/build.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/build_metadata/build.rs b/src/build_metadata/build.rs index bfdf20b1..bf84d508 100644 --- a/src/build_metadata/build.rs +++ b/src/build_metadata/build.rs @@ -79,12 +79,12 @@ fn main() { // --- Rerun Triggers --- // TODO: The git rerun triggers seem to always run - // Rerun if the git HEAD changes - println!("cargo:rerun-if-changed=.git/HEAD"); - // Rerun if the ref pointed to by HEAD changes (e.g., new commit on branch) - if let Some(ref_path) = run_git_command(&["symbolic-ref", "--quiet", "HEAD"]) { - println!("cargo:rerun-if-changed=.git/{ref_path}"); - } + // // Rerun if the git HEAD changes + // println!("cargo:rerun-if-changed=.git/HEAD"); + // // Rerun if the ref pointed to by HEAD changes (e.g., new commit on branch) + // if let Some(ref_path) = run_git_command(&["symbolic-ref", "--quiet", "HEAD"]) + // { println!("cargo:rerun-if-changed=.git/{ref_path}"); + // } println!("cargo:rerun-if-env-changed=GIT_COMMIT_HASH"); println!("cargo:rerun-if-env-changed=GIT_COMMIT_HASH_SHORT"); From 3c44dccd6555d38c19e46ca8b5ad8acf49d99f52 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Mon, 26 May 2025 19:16:50 +0100 Subject: [PATCH 2015/2291] ci: HACK, disable saving to actions cache --- .forgejo/workflows/release-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index ec05fb45..92a5b7c4 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -187,7 +187,7 @@ jobs: labels: ${{ steps.meta.outputs.labels }} annotations: ${{ steps.meta.outputs.annotations }} cache-from: type=gha - cache-to: type=gha,mode=max + # cache-to: type=gha,mode=max sbom: true outputs: type=image,"name=${{ needs.define-variables.outputs.images_list }}",push-by-digest=true,name-canonical=true,push=true env: From 1d45e0b68cd86a72393bf3cb3f866d5943056018 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 13 Jun 2025 13:39:50 +0100 Subject: [PATCH 2016/2291] feat: Add warning when admin users will be exposed as support contacts --- src/core/config/check.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/config/check.rs b/src/core/config/check.rs index ded9533d..3dc45e2f 100644 --- a/src/core/config/check.rs +++ b/src/core/config/check.rs @@ -219,6 +219,15 @@ pub fn check(config: &Config) -> Result { )); } + // Check if support contact information is configured + if config.well_known.support_email.is_none() && config.well_known.support_mxid.is_none() { + warn!( + "No support contact information (support_email or support_mxid) is configured in \ + the well_known section. Users in the admin room will be automatically listed as \ + support contacts in the /.well-known/matrix/support endpoint." + ); + } + if config .url_preview_domain_contains_allowlist .contains(&"*".to_owned()) From d7514178ab3aaf594bc2b55bb115842f5ba9f2ca Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 13 Jun 2025 14:29:14 +0100 Subject: [PATCH 2017/2291] ci: Fix extra bracket in commit shorthash --- .forgejo/workflows/release-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 92a5b7c4..55b303b2 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -180,7 +180,7 @@ jobs: file: "docker/Dockerfile" build-args: | GIT_COMMIT_HASH=${{ github.sha }}) - GIT_COMMIT_HASH_SHORT=${{ env.COMMIT_SHORT_SHA }}) + GIT_COMMIT_HASH_SHORT=${{ env.COMMIT_SHORT_SHA }} GIT_REMOTE_URL=${{github.event.repository.html_url }} GIT_REMOTE_COMMIT_URL=${{github.event.head_commit.url }} platforms: ${{ matrix.platform }} From 44e60d0ea60fec116eb1535239cc8007d73992f0 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 30 May 2025 23:50:29 +0100 Subject: [PATCH 2018/2291] docs: Tiny phrasing changes to the security policy --- SECURITY.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index a9aa183e..2869ce58 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -20,10 +20,10 @@ We may backport fixes to the previous release at our discretion, but we don't gu We appreciate the efforts of security researchers and the community in identifying and reporting vulnerabilities. To ensure that potential vulnerabilities are addressed properly, please follow these guidelines: -1. Contact members of the team over E2EE private message. +1. **Contact members of the team directly** over E2EE private message. - [@jade:ellis.link](https://matrix.to/#/@jade:ellis.link) - [@nex:nexy7574.co.uk](https://matrix.to/#/@nex:nexy7574.co.uk) -2. **Email the security team** directly at [security@continuwuity.org](mailto:security@continuwuity.org). This is not E2EE, so don't include sensitive details. +2. **Email the security team** at [security@continuwuity.org](mailto:security@continuwuity.org). This is not E2EE, so don't include sensitive details. 3. **Do not disclose the vulnerability publicly** until it has been addressed 4. **Provide detailed information** about the vulnerability, including: - A clear description of the issue @@ -48,7 +48,7 @@ When you report a security vulnerability: When security vulnerabilities are identified: -1. We will develop and test fixes in a private branch +1. We will develop and test fixes in a private fork 2. Security updates will be released as soon as possible 3. Release notes will include information about the vulnerabilities, avoiding details that could facilitate exploitation where possible 4. Critical security updates may be backported to the previous stable release From 5d44653e3a9bc278f9dbe3084e2e34a9a0799e1f Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 14 Jun 2025 16:28:57 +0100 Subject: [PATCH 2019/2291] fix: Incorrect command descriptions --- src/admin/debug/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index 9b86f18c..1fd4e263 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -125,13 +125,13 @@ pub(super) enum DebugCommand { reset: bool, }, - /// - Verify json signatures + /// - Sign JSON blob /// /// This command needs a JSON blob provided in a Markdown code block below /// the command. SignJson, - /// - Verify json signatures + /// - Verify JSON signatures /// /// This command needs a JSON blob provided in a Markdown code block below /// the command. From d0f00e6f5ca2be3c8524c5383bcb32585c849278 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 14 Jun 2025 18:54:02 +0100 Subject: [PATCH 2020/2291] feat: Allow mentioning @room in an admin announcement --- docs/static/announcements.schema.json | 8 ++++++-- src/service/announcements/mod.rs | 29 +++++++++++++++------------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/static/announcements.schema.json b/docs/static/announcements.schema.json index 95b1d153..cacd10c9 100644 --- a/docs/static/announcements.schema.json +++ b/docs/static/announcements.schema.json @@ -3,7 +3,7 @@ "$id": "https://continwuity.org/schema/announcements.schema.json", "type": "object", "properties": { - "updates": { + "announcements": { "type": "array", "items": { "type": "object", @@ -16,6 +16,10 @@ }, "date": { "type": "string" + }, + "mention_room": { + "type": "boolean", + "description": "Whether to mention the room (@room) when posting this announcement" } }, "required": [ @@ -26,6 +30,6 @@ } }, "required": [ - "updates" + "announcements" ] } \ No newline at end of file diff --git a/src/service/announcements/mod.rs b/src/service/announcements/mod.rs index 4df8971b..2a70344d 100644 --- a/src/service/announcements/mod.rs +++ b/src/service/announcements/mod.rs @@ -20,7 +20,7 @@ use std::{sync::Arc, time::Duration}; use async_trait::async_trait; use conduwuit::{Result, Server, debug, info, warn}; use database::{Deserialized, Map}; -use ruma::events::room::message::RoomMessageEventContent; +use ruma::events::{Mentions, room::message::RoomMessageEventContent}; use serde::Deserialize; use tokio::{ sync::Notify, @@ -53,6 +53,8 @@ struct CheckForAnnouncementsResponseEntry { id: u64, date: Option, message: String, + #[serde(default, skip_serializing_if = "bool::not")] + mention_room: bool, } const CHECK_FOR_ANNOUNCEMENTS_URL: &str = @@ -139,19 +141,20 @@ impl Service { } else { info!("[announcements] {:#}", announcement.message); } + let mut message = RoomMessageEventContent::text_markdown(format!( + "### New announcement{}\n\n{}", + announcement + .date + .as_ref() + .map_or_else(String::new, |date| format!(" - `{date}`")), + announcement.message + )); - self.services - .admin - .send_message(RoomMessageEventContent::text_markdown(format!( - "### New announcement{}\n\n{}", - announcement - .date - .as_ref() - .map_or_else(String::new, |date| format!(" - `{date}`")), - announcement.message - ))) - .await - .ok(); + if announcement.mention_room { + message = message.add_mentions(Mentions::with_room_mention()); + } + + self.services.admin.send_message(message).await.ok(); } #[inline] From 0870c8d6478dfa24ef09d8fe52b578d101024edf Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 14 Jun 2025 20:53:00 +0100 Subject: [PATCH 2021/2291] chore: Release --- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 160be0c7..ec6e848d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -771,7 +771,7 @@ dependencies = [ [[package]] name = "conduwuit" -version = "0.5.0-rc.5" +version = "0.5.0-rc.6" dependencies = [ "clap", "conduwuit_admin", @@ -800,7 +800,7 @@ dependencies = [ [[package]] name = "conduwuit_admin" -version = "0.5.0-rc.5" +version = "0.5.0-rc.6" dependencies = [ "clap", "conduwuit_api", @@ -821,7 +821,7 @@ dependencies = [ [[package]] name = "conduwuit_api" -version = "0.5.0-rc.5" +version = "0.5.0-rc.6" dependencies = [ "async-trait", "axum", @@ -853,14 +853,14 @@ dependencies = [ [[package]] name = "conduwuit_build_metadata" -version = "0.5.0-rc.5" +version = "0.5.0-rc.6" dependencies = [ "built 0.8.0", ] [[package]] name = "conduwuit_core" -version = "0.5.0-rc.5" +version = "0.5.0-rc.6" dependencies = [ "argon2", "arrayvec", @@ -919,7 +919,7 @@ dependencies = [ [[package]] name = "conduwuit_database" -version = "0.5.0-rc.5" +version = "0.5.0-rc.6" dependencies = [ "async-channel", "conduwuit_core", @@ -937,7 +937,7 @@ dependencies = [ [[package]] name = "conduwuit_macros" -version = "0.5.0-rc.5" +version = "0.5.0-rc.6" dependencies = [ "itertools 0.14.0", "proc-macro2", @@ -947,7 +947,7 @@ dependencies = [ [[package]] name = "conduwuit_router" -version = "0.5.0-rc.5" +version = "0.5.0-rc.6" dependencies = [ "axum", "axum-client-ip", @@ -981,7 +981,7 @@ dependencies = [ [[package]] name = "conduwuit_service" -version = "0.5.0-rc.5" +version = "0.5.0-rc.6" dependencies = [ "async-trait", "base64 0.22.1", @@ -1018,7 +1018,7 @@ dependencies = [ [[package]] name = "conduwuit_web" -version = "0.5.0-rc.5" +version = "0.5.0-rc.6" dependencies = [ "askama", "axum", diff --git a/Cargo.toml b/Cargo.toml index 1abff107..af904447 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ license = "Apache-2.0" readme = "README.md" repository = "https://forgejo.ellis.link/continuwuation/continuwuity" rust-version = "1.86.0" -version = "0.5.0-rc.5" +version = "0.5.0-rc.6" [workspace.metadata.crane] name = "conduwuit" From 6e16a6ef8f90ee4a1b2a92435475ddf7359ba837 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 14 Jun 2025 22:34:24 +0100 Subject: [PATCH 2022/2291] chore: Release announcement --- docs/static/announcements.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/static/announcements.json b/docs/static/announcements.json index 9b97d091..7dd2fb72 100644 --- a/docs/static/announcements.json +++ b/docs/static/announcements.json @@ -4,6 +4,10 @@ { "id": 1, "message": "Welcome to Continuwuity! Important announcements about the project will appear here." + }, + { + "id": 2, + "message": "🎉 Continuwuity v0.5.0-rc.6 is now available! This release includes improved knock-restricted room handling, automatic support contact configuration, and a new HTML landing page. Check [the release notes for full details](https://forgejo.ellis.link/continuwuation/continuwuity/releases/tag/v0.5.0-rc.6) and upgrade instructions." } ] -} \ No newline at end of file +} From d6fd30393c224c216867f46341616c041bbcd97a Mon Sep 17 00:00:00 2001 From: Kimiblock Date: Thu, 19 Jun 2025 12:36:49 +0000 Subject: [PATCH 2023/2291] Update docs/deploying/arch-linux.md --- docs/deploying/arch-linux.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/deploying/arch-linux.md b/docs/deploying/arch-linux.md index a14201e3..52d2afb2 100644 --- a/docs/deploying/arch-linux.md +++ b/docs/deploying/arch-linux.md @@ -1,3 +1,5 @@ # Continuwuity for Arch Linux -Continuwuity does not have any Arch Linux packages at this time. +Continuwuity is available on the `archlinuxcn` repository and AUR, with the same package name `continuwuity`, which includes latest taggged version. The development version is available on AUR as `continuwuity-git` + +Simply install the `continuwuity` package. Configure the service in `/etc/conduwuit/conduwuit.toml`, then enable/start the continuwuity.service. \ No newline at end of file From e508b1197f3a6e485f35edf0d3c529cb58c391b5 Mon Sep 17 00:00:00 2001 From: nex Date: Thu, 19 Jun 2025 21:27:50 +0000 Subject: [PATCH 2024/2291] feat: allow overriding the "most recent event" when forcing a state download (#853) Add option to select which event to set the state at to, for the force-set-room-state admin command. This allows us to work around issues where the latest PDU is one that remote servers don't know about (i.e. failed federation for whatever reason) Closes #852 Reviewed-on: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/853 Reviewed-by: Jade Ellis Co-authored-by: nex Co-committed-by: nex --- src/admin/debug/commands.rs | 37 +++++++++++++++++++++++-------------- src/admin/debug/mod.rs | 3 +++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index d0debc2a..a397e0fc 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -239,10 +239,11 @@ pub(super) async fn get_remote_pdu( }) .await { - | Err(e) => + | Err(e) => { return Err!( "Remote server did not have PDU or failed sending request to remote server: {e}" - ), + ); + }, | Ok(response) => { let json: CanonicalJsonObject = serde_json::from_str(response.pdu.get()).map_err(|e| { @@ -384,8 +385,9 @@ pub(super) async fn change_log_level(&self, filter: Option, reset: bool) .reload .reload(&old_filter_layer, Some(handles)) { - | Err(e) => - return Err!("Failed to modify and reload the global tracing log level: {e}"), + | Err(e) => { + return Err!("Failed to modify and reload the global tracing log level: {e}"); + }, | Ok(()) => { let value = &self.services.server.config.log; let out = format!("Successfully changed log level back to config value {value}"); @@ -408,8 +410,9 @@ pub(super) async fn change_log_level(&self, filter: Option, reset: bool) .reload(&new_filter_layer, Some(handles)) { | Ok(()) => return self.write_str("Successfully changed log level").await, - | Err(e) => - return Err!("Failed to modify and reload the global tracing log level: {e}"), + | Err(e) => { + return Err!("Failed to modify and reload the global tracing log level: {e}"); + }, } } @@ -529,6 +532,7 @@ pub(super) async fn force_set_room_state_from_server( &self, room_id: OwnedRoomId, server_name: OwnedServerName, + at_event: Option, ) -> Result { if !self .services @@ -540,13 +544,18 @@ pub(super) async fn force_set_room_state_from_server( return Err!("We are not participating in the room / we don't know about the room ID."); } - let first_pdu = self - .services - .rooms - .timeline - .latest_pdu_in_room(&room_id) - .await - .map_err(|_| err!(Database("Failed to find the latest PDU in database")))?; + let at_event_id = match at_event { + | Some(event_id) => event_id, + | None => self + .services + .rooms + .timeline + .latest_pdu_in_room(&room_id) + .await + .map_err(|_| err!(Database("Failed to find the latest PDU in database")))? + .event_id + .clone(), + }; let room_version = self.services.rooms.state.get_room_version(&room_id).await?; @@ -557,7 +566,7 @@ pub(super) async fn force_set_room_state_from_server( .sending .send_federation_request(&server_name, get_room_state::v1::Request { room_id: room_id.clone(), - event_id: first_pdu.event_id.clone(), + event_id: at_event_id, }) .await?; diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index 1fd4e263..bceee9ba 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -177,6 +177,9 @@ pub(super) enum DebugCommand { room_id: OwnedRoomId, /// The server we will use to query the room state for server_name: OwnedServerName, + /// The event ID of the latest known PDU in the room. Will be found + /// automatically if not provided. + event_id: Option, }, /// - Runs a server name through conduwuit's true destination resolution From a737d845a436016b9eaf55ca19cbdd4cc419337a Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 21 May 2025 20:41:34 +0100 Subject: [PATCH 2025/2291] chore: Don't specify targets in rust-toolchain --- rust-toolchain.toml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index aadc8f99..65890260 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -19,11 +19,3 @@ components = [ "rustfmt", "clippy", ] -targets = [ - #"x86_64-apple-darwin", - "x86_64-unknown-linux-gnu", - "x86_64-unknown-linux-musl", - "aarch64-unknown-linux-musl", - "aarch64-unknown-linux-gnu", - #"aarch64-apple-darwin", -] From b526935d45429be72b7e99aef7e57e236b2e84bf Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 20 Jun 2025 21:35:03 +0100 Subject: [PATCH 2026/2291] build: Specify debian version --- docker/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index e734fb81..dfda57fb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,8 +1,9 @@ ARG RUST_VERSION=1 +ARG DEBIAN_VERSION=bookworm FROM --platform=$BUILDPLATFORM docker.io/tonistiigi/xx AS xx -FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-slim-bookworm AS base -FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-slim-bookworm AS toolchain +FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-slim-${DEBIAN_VERSION} AS base +FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-slim-${DEBIAN_VERSION} AS toolchain # Prevent deletion of apt cache RUN rm -f /etc/apt/apt.conf.d/docker-clean From 08fbcbba691234b6240c03805354424deb2931e9 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 20 Jun 2025 21:35:48 +0100 Subject: [PATCH 2027/2291] build: Use newer LLVM for rust 1.87 --- docker/Dockerfile | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index dfda57fb..e40438e9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -10,7 +10,7 @@ RUN rm -f /etc/apt/apt.conf.d/docker-clean # Match Rustc version as close as possible # rustc -vV -ARG LLVM_VERSION=19 +ARG LLVM_VERSION=20 # ENV RUSTUP_TOOLCHAIN=${RUST_VERSION} # Install repo tools @@ -20,10 +20,18 @@ ARG LLVM_VERSION=19 RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked \ apt-get update && apt-get install -y \ - clang-${LLVM_VERSION} lld-${LLVM_VERSION} pkg-config make jq \ - curl git \ + pkg-config make jq \ + curl git software-properties-common \ file +# LLVM packages +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + curl https://apt.llvm.org/llvm.sh > llvm.sh && \ + chmod +x llvm.sh && \ + ./llvm.sh ${LLVM_VERSION} && \ + rm llvm.sh + # Create symlinks for LLVM tools RUN < Date: Fri, 20 Jun 2025 21:45:29 +0100 Subject: [PATCH 2028/2291] build: Upgrade to Rust 1.87 --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 65890260..bdb608aa 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -9,7 +9,7 @@ # If you're having trouble making the relevant changes, bug a maintainer. [toolchain] -channel = "1.86.0" +channel = "1.87.0" profile = "minimal" components = [ # For rust-analyzer From 01200d9b545bdad3f59b0db447a1480aa6314d50 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 20 Jun 2025 21:48:37 +0100 Subject: [PATCH 2029/2291] build: Allow specifying build profile Additionally splits caches by target CPU --- .forgejo/workflows/release-image.yml | 12 ++++++++---- docker/Dockerfile | 5 +++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 55b303b2..170fe668 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -49,6 +49,7 @@ jobs: const platforms = ['linux/amd64', 'linux/arm64'] core.setOutput('build_matrix', JSON.stringify({ platform: platforms, + target_cpu: ['base'], include: platforms.map(platform => { return { platform, slug: platform.replace('/', '-') @@ -66,6 +67,8 @@ jobs: strategy: matrix: { + "target_cpu": ["base"], + "profile": ["release"], "include": [ { "platform": "linux/amd64", "slug": "linux-amd64" }, @@ -73,6 +76,7 @@ jobs: ], "platform": ["linux/amd64", "linux/arm64"], } + steps: - name: Echo strategy run: echo '${{ toJSON(fromJSON(needs.define-variables.outputs.build_matrix)) }}' @@ -140,8 +144,8 @@ jobs: uses: actions/cache@v3 with: path: | - cargo-target-${{ matrix.slug }} - key: cargo-target-${{ matrix.slug }}-${{hashFiles('**/Cargo.lock') }}-${{steps.rust-toolchain.outputs.rustc_version}} + cargo-target-${{ matrix.target_cpu }}-${{ matrix.slug }}-${{ matrix.profile }} + key: cargo-target-${{ matrix.target_cpu }}-${{ matrix.slug }}-${{ matrix.profile }}-${{hashFiles('**/Cargo.lock') }}-${{steps.rust-toolchain.outputs.rustc_version}} - name: Cache apt cache id: cache-apt uses: actions/cache@v3 @@ -163,9 +167,9 @@ jobs: { ".cargo/registry": "/usr/local/cargo/registry", ".cargo/git/db": "/usr/local/cargo/git/db", - "cargo-target-${{ matrix.slug }}": { + "cargo-target-${{ matrix.target_cpu }}-${{ matrix.slug }}-${{ matrix.profile }}": { "target": "/app/target", - "id": "cargo-target-${{ matrix.platform }}" + "id": "cargo-target-${{ matrix.target_cpu }}-${{ matrix.slug }}-${{ matrix.profile }}" }, "var-cache-apt-${{ matrix.slug }}": "/var/cache/apt", "var-lib-apt-${{ matrix.slug }}": "/var/lib/apt" diff --git a/docker/Dockerfile b/docker/Dockerfile index e40438e9..bd6e72d1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -149,11 +149,12 @@ ENV GIT_REMOTE_COMMIT_URL=$GIT_REMOTE_COMMIT_URL ENV CONDUWUIT_VERSION_EXTRA=$CONDUWUIT_VERSION_EXTRA ENV CONTINUWUITY_VERSION_EXTRA=$CONTINUWUITY_VERSION_EXTRA +ARG RUST_PROFILE=release # Build the binary RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git/db \ - --mount=type=cache,target=/app/target,id=cargo-target-${TARGETPLATFORM} \ + --mount=type=cache,target=/app/target,id=cargo-target-${TARGET_CPU}-${TARGETPLATFORM}-${RUST_PROFILE} \ bash <<'EOF' set -o allexport set -o xtrace @@ -162,7 +163,7 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ jq -r ".target_directory")) mkdir /out/sbin PACKAGE=conduwuit - xx-cargo build --locked --release \ + xx-cargo build --locked --profile ${RUST_PROFILE} \ -p $PACKAGE; BINARIES=($(cargo metadata --no-deps --format-version 1 | \ jq -r ".packages[] | select(.name == \"$PACKAGE\") | .targets[] | select( .kind | map(. == \"bin\") | any ) | .name")) From add5c7052c8a2aa61a78a785500530ecdd394626 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 20 Jun 2025 21:51:53 +0100 Subject: [PATCH 2030/2291] chore: Update lockfile --- Cargo.lock | 647 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 415 insertions(+), 232 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec6e848d..59662da2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "adler2" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "aho-corasick" @@ -28,9 +28,12 @@ dependencies = [ [[package]] name = "aligned-vec" -version = "0.5.0" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" +checksum = "dc890384c8602f339876ded803c97ad529f3842aba97f6392b3dba0dd171769b" +dependencies = [ + "equator", +] [[package]] name = "alloc-no-stdlib" @@ -49,9 +52,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" [[package]] name = "anyhow" @@ -170,9 +173,9 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.4.23" +version = "0.4.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b37fc50485c4f3f736a4fb14199f6d5f5ba008d7f28fe710306c92780f004c07" +checksum = "40f6024f3f856663b45fd0c9b6f2024034a702f453549449e0d84a305900dad4" dependencies = [ "brotli", "flate2", @@ -219,9 +222,9 @@ dependencies = [ [[package]] name = "atomic" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d818003e740b63afc82337e3160717f4f63078720a810b7b903e70a5d1d2994" +checksum = "a89cbf775b137e9b968e67227ef7f775587cde3fd31b0d8599dbd0f598a48340" dependencies = [ "bytemuck", ] @@ -234,15 +237,15 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "av1-grain" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6678909d8c5d46a42abcf571271e15fdbc0a225e3646cf23762cd415046c78bf" +checksum = "4f3efb2ca85bc610acfa917b5aaa36f3fcbebed5b3182d7f877b02531c4b80c8" dependencies = [ "anyhow", "arrayvec", @@ -263,9 +266,9 @@ dependencies = [ [[package]] name = "aws-lc-rs" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b756939cb2f8dc900aa6dcd505e6e2428e9cae7ff7b028c49e3946efa70878" +checksum = "93fcc8f365936c834db5514fc45aee5b1202d677e6b40e48468aaaa8183ca8c7" dependencies = [ "aws-lc-sys", "zeroize", @@ -273,9 +276,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.28.2" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa9b6986f250236c27e5a204062434a773a13243d2ffc2955f37bdba4c5c6a1" +checksum = "61b1d86e7705efe1be1b569bab41d4fa1e14e220b60a160f78de2db687add079" dependencies = [ "bindgen 0.69.5", "cc", @@ -442,9 +445,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64ct" -version = "1.7.3" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" +checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" [[package]] name = "basic-toml" @@ -461,7 +464,7 @@ version = "0.69.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "cexpr", "clang-sys", "itertools 0.12.1", @@ -484,7 +487,7 @@ version = "0.71.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "cexpr", "clang-sys", "itertools 0.13.0", @@ -510,9 +513,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" [[package]] name = "bitstream-io" @@ -582,15 +585,15 @@ checksum = "f4ad8f11f288f48ca24471bbd51ac257aaeaaa07adae295591266b792902ae64" [[package]] name = "bumpalo" -version = "3.17.0" +version = "3.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" +checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee" [[package]] name = "bytemuck" -version = "1.23.0" +version = "1.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9134a6ef01ce4b366b50689c94f82c14bc72bc5d0386829828a2e2752ef7958c" +checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422" [[package]] name = "byteorder" @@ -638,9 +641,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.22" +version = "1.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32db95edf998450acc7881c932f94cd9b05c87b4b2599e8bab064753da4acfd1" +checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc" dependencies = [ "jobserver", "libc", @@ -668,9 +671,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "cfg_aliases" @@ -709,9 +712,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.38" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed93b9805f8ba930df42c2590f05453d5ec36cbb85d018868a5b24d31f6ac000" +checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" dependencies = [ "clap_builder", "clap_derive", @@ -719,9 +722,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.38" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "379026ff283facf611b0ea629334361c4211d1b12ee01024eec1591133b04120" +checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" dependencies = [ "anstyle", "clap_lex", @@ -729,9 +732,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.32" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" +checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" dependencies = [ "heck", "proc-macro2", @@ -741,9 +744,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "cmake" @@ -1088,19 +1091,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2459fc9262a1aa204eb4b5764ad4f189caec88aea9634389c0a25f8be7f6265e" [[package]] -name = "coolor" -version = "1.0.0" +name = "convert_case" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "691defa50318376447a73ced869862baecfab35f6aabaa91a4cd726b315bfe1a" +checksum = "bb402b8d4c85569410425650ce3eddc7d698ed96d39a73f941b08fb63082f1e7" dependencies = [ - "crossterm", + "unicode-segmentation", +] + +[[package]] +name = "coolor" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "980c2afde4af43d6a05c5be738f9eae595cff86dce1f38f88b95058a98c027f3" +dependencies = [ + "crossterm 0.29.0", ] [[package]] name = "core-foundation" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" dependencies = [ "core-foundation-sys", "libc", @@ -1148,12 +1160,12 @@ checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" [[package]] name = "crokey" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5ff945e42bb93d29b10ba509970066a269903a932f0ea07d99d8621f97e90d7" +checksum = "5282b45c96c5978c8723ea83385cb9a488b64b7d175733f48d07bf9da514a863" dependencies = [ "crokey-proc_macros", - "crossterm", + "crossterm 0.29.0", "once_cell", "serde", "strict", @@ -1161,11 +1173,11 @@ dependencies = [ [[package]] name = "crokey-proc_macros" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "665f2180fd82d0ba2bf3deb45fafabb18f23451024ff71ee47f6bfdfb4bbe09e" +checksum = "2ea0218d3fedf0797fa55676f1964ef5d27103d41ed0281b4bbd2a6e6c3d8d28" dependencies = [ - "crossterm", + "crossterm 0.29.0", "proc-macro2", "quote", "strict", @@ -1234,12 +1246,30 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "crossterm_winapi", "futures-core", "mio", "parking_lot", - "rustix", + "rustix 0.38.44", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" +dependencies = [ + "bitflags 2.9.1", + "crossterm_winapi", + "derive_more", + "document-features", + "mio", + "parking_lot", + "rustix 1.0.7", "signal-hook", "signal-hook-mio", "winapi", @@ -1337,9 +1367,9 @@ dependencies = [ [[package]] name = "der" -version = "0.7.9" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" dependencies = [ "const-oid", "zeroize", @@ -1354,6 +1384,27 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive_more" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "digest" version = "0.10.7" @@ -1376,6 +1427,15 @@ dependencies = [ "syn", ] +[[package]] +name = "document-features" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d" +dependencies = [ + "litrs", +] + [[package]] name = "dunce" version = "1.0.5" @@ -1428,6 +1488,26 @@ dependencies = [ "syn", ] +[[package]] +name = "equator" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4711b213838dfee0117e3be6ac926007d7f433d7bbe33595975d4190cb07e6fc" +dependencies = [ + "equator-macro", +] + +[[package]] +name = "equator-macro" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44f23cf4b44bfce11a86ace86f8a73ffdec849c9fd00a386a53d278bd9e81fb3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "equivalent" version = "1.0.2" @@ -1436,12 +1516,12 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" -version = "0.3.11" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" +checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -1522,9 +1602,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" +checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d" dependencies = [ "crc32fast", "miniz_oxide", @@ -1557,9 +1637,9 @@ dependencies = [ [[package]] name = "fs-err" -version = "3.1.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f89bda4c2a21204059a977ed3bfe746677dfd137b83c339e702b0ac91d482aa" +checksum = "88d7be93788013f265201256d58f04936a8079ad5dc898743aa20525f503b683" dependencies = [ "autocfg", "tokio", @@ -1671,10 +1751,11 @@ dependencies = [ [[package]] name = "generator" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc6bd114ceda131d3b1d665eba35788690ad37f5916457286b32ab6fd3c438dd" +checksum = "d18470a76cb7f8ff746cf1f7470914f900252ec36bbc40b569d74b1258446827" dependencies = [ + "cc", "cfg-if", "libc", "log", @@ -1701,7 +1782,7 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi 0.11.1+wasi-snapshot-preview1", "wasm-bindgen", ] @@ -1784,9 +1865,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.15.3" +version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" +checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" [[package]] name = "hdrhistogram" @@ -1803,11 +1884,11 @@ dependencies = [ [[package]] name = "headers" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322106e6bd0cba2d5ead589ddb8150a13d7c4217cf80d7c4f682ca994ccc6aa9" +checksum = "b3314d5adb5d94bcdf56771f2e50dbbc80bb4bdf88967526706205ac9eff24eb" dependencies = [ - "base64 0.21.7", + "base64 0.22.1", "bytes", "headers-core", "http", @@ -1833,9 +1914,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.3.9" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" [[package]] name = "hex" @@ -2063,11 +2144,10 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.5" +version = "0.27.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" dependencies = [ - "futures-util", "http", "hyper", "hyper-util", @@ -2077,7 +2157,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", - "webpki-roots", + "webpki-roots 1.0.1", ] [[package]] @@ -2161,9 +2241,9 @@ checksum = "00210d6893afc98edb752b664b8890f0ef174c8adbb8d0be9710fa66fbbf72d3" [[package]] name = "icu_properties" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2549ca8c7241c82f59c80ba2a6f415d931c5b58d24fb8412caa1a1f02c49139a" +checksum = "016c619c1eeb94efb86809b015c58f479963de65bdb6253345c1a1276f22e32b" dependencies = [ "displaydoc", "icu_collections", @@ -2177,9 +2257,9 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8197e866e47b68f8f7d95249e172903bec06004b18b2937f1095d40a0c57de04" +checksum = "298459143998310acd25ffe6810ed544932242d3f07083eee1084d83a71bd632" [[package]] name = "icu_provider" @@ -2244,9 +2324,9 @@ dependencies = [ [[package]] name = "image-webp" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b77d01e822461baa8409e156015a1d91735549f0f2c17691bd2d996bef238f7f" +checksum = "f6970fe7a5300b4b42e62c52efa0187540a5bef546c60edaf554ef595d2e6f0b" dependencies = [ "byteorder-lite", "quick-error", @@ -2275,7 +2355,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" dependencies = [ "equivalent", - "hashbrown 0.15.3", + "hashbrown 0.15.4", "serde", ] @@ -2474,9 +2554,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.172" +version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libfuzzer-sys" @@ -2490,12 +2570,12 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a793df0d7afeac54f95b471d3af7f0d4fb975699f972341a4b76988d49cdf0c" +checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if", - "windows-targets 0.53.0", + "windows-targets 0.53.2", ] [[package]] @@ -2521,6 +2601,12 @@ version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" +[[package]] +name = "linux-raw-sys" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" + [[package]] name = "litemap" version = "0.8.0" @@ -2528,10 +2614,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" [[package]] -name = "lock_api" -version = "0.4.12" +name = "litrs" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" + +[[package]] +name = "lock_api" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" dependencies = [ "autocfg", "scopeguard", @@ -2584,6 +2676,12 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + [[package]] name = "lz4-sys" version = "1.11.1+lz4-1.10.0" @@ -2659,9 +2757,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "mime" @@ -2716,9 +2814,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" dependencies = [ "adler2", "simd-adler32", @@ -2726,14 +2824,14 @@ dependencies = [ [[package]] name = "mio" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.52.0", + "wasi 0.11.1+wasi-snapshot-preview1", + "windows-sys 0.59.0", ] [[package]] @@ -2767,7 +2865,7 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "cfg-if", "cfg_aliases", "libc", @@ -2897,9 +2995,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" dependencies = [ "hermit-abi", "libc", @@ -3013,11 +3111,12 @@ dependencies = [ [[package]] name = "os_info" -version = "3.10.0" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a604e53c24761286860eba4e2c8b23a0161526476b1de520139d69cdb85a6b5" +checksum = "d0e1ac5fde8d43c34139135df8ea9ee9465394b2d8d20f032d38998f64afffc3" dependencies = [ "log", + "plist", "serde", "windows-sys 0.52.0", ] @@ -3036,9 +3135,9 @@ checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" [[package]] name = "parking_lot" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" dependencies = [ "lock_api", "parking_lot_core", @@ -3046,9 +3145,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.10" +version = "0.9.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" dependencies = [ "cfg-if", "libc", @@ -3189,6 +3288,19 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "plist" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d77244ce2d584cd84f6a15f86195b8c9b2a0dfbfd817c09e0464244091a58ed" +dependencies = [ + "base64 0.22.1", + "indexmap 2.9.0", + "quick-xml", + "serde", + "time", +] + [[package]] name = "png" version = "0.17.16" @@ -3204,9 +3316,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" +checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" [[package]] name = "potential_utf" @@ -3240,9 +3352,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "prettyplease" -version = "0.2.31" +version = "0.2.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5316f57387668042f561aae71480de936257848f9c43ce528e311d89a07cadeb" +checksum = "061c1221631e079b26479d25bbf2275bfe5917ae8419cd7e34f13bfc2aa7539a" dependencies = [ "proc-macro2", "syn", @@ -3336,7 +3448,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e8bbe1a966bd2f362681a44f6edce3c2310ac21e4d5067a6e7ec396297a6ea0" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "memchr", "pulldown-cmark-escape", "unicase", @@ -3364,10 +3476,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] -name = "quinn" -version = "0.11.7" +name = "quick-xml" +version = "0.37.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3bd15a6f2967aef83887dcb9fec0014580467e33720d073560cf015a5683012" +checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb" +dependencies = [ + "memchr", +] + +[[package]] +name = "quinn" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626214629cda6781b6dc1d316ba307189c85ba657213ce642d9c77670f8202c8" dependencies = [ "bytes", "cfg_aliases", @@ -3385,12 +3506,13 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.10" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b820744eb4dc9b57a3398183639c511b5a26d2ed702cedd3febaa1393caa22cc" +checksum = "49df843a9161c85bb8aae55f101bc0bac8bcafd637a620d9122fd7e0b2f7422e" dependencies = [ "bytes", "getrandom 0.3.3", + "lru-slab", "rand 0.9.1", "ring", "rustc-hash 2.1.1", @@ -3405,9 +3527,9 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.11" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "541d0f57c6ec747a90738a52741d3221f7960e8ac2f0ff4b1a63680e033b4ab5" +checksum = "fcebb1209ee276352ef14ff8732e24cc2b02bbac986cd74a4c81bcb2f9881970" dependencies = [ "cfg_aliases", "libc", @@ -3428,9 +3550,9 @@ dependencies = [ [[package]] name = "r-efi" -version = "5.2.0" +version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rand" @@ -3563,11 +3685,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.12" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" +checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", ] [[package]] @@ -3660,7 +3782,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", + "webpki-roots 0.26.11", "windows-registry", ] @@ -3916,9 +4038,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.24" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" [[package]] name = "rustc-hash" @@ -3947,18 +4069,31 @@ version = "0.38.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.4.15", + "windows-sys 0.59.0", +] + +[[package]] +name = "rustix" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" +dependencies = [ + "bitflags 2.9.1", + "errno", + "libc", + "linux-raw-sys 0.9.4", "windows-sys 0.59.0", ] [[package]] name = "rustls" -version = "0.23.27" +version = "0.23.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "730944ca083c1c233a75c09f199e973ca499344a2b7ba9e755c457e86fb4a321" +checksum = "7160e3e10bf4535308537f3c4e1641468cd0e485175d6163087c0393c7d46643" dependencies = [ "aws-lc-rs", "log", @@ -4015,23 +4150,23 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" +checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" [[package]] name = "rustyline-async" version = "0.4.3" source = "git+https://forgejo.ellis.link/continuwuation/rustyline-async?rev=deaeb0694e2083f53d363b648da06e10fc13900c#deaeb0694e2083f53d363b648da06e10fc13900c" dependencies = [ - "crossterm", + "crossterm 0.28.1", "futures-channel", "futures-util", "pin-project", "thingbuf", "thiserror 2.0.12", "unicode-segmentation", - "unicode-width 0.2.0", + "unicode-width 0.2.1", ] [[package]] @@ -4085,7 +4220,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "core-foundation", "core-foundation-sys", "libc", @@ -4127,7 +4262,7 @@ dependencies = [ "sentry-tracing", "tokio", "ureq", - "webpki-roots", + "webpki-roots 0.26.11", ] [[package]] @@ -4310,9 +4445,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.8" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" dependencies = [ "serde", ] @@ -4381,9 +4516,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" dependencies = [ "libc", "signal-hook-registry", @@ -4441,12 +4576,9 @@ checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "slab" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] +checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d" [[package]] name = "smallstr" @@ -4460,18 +4592,18 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.15.0" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" dependencies = [ "serde", ] [[package]] name = "socket2" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" dependencies = [ "libc", "windows-sys 0.52.0", @@ -4541,9 +4673,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.101" +version = "2.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" dependencies = [ "proc-macro2", "quote", @@ -4674,12 +4806,11 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" dependencies = [ "cfg-if", - "once_cell", ] [[package]] @@ -4801,9 +4932,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.45.0" +version = "1.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2513ca694ef9ede0fb23fe71a4ee4107cb102b9dc1930f6d0fd77aae068ae165" +checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779" dependencies = [ "backtrace", "bytes", @@ -4888,9 +5019,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.22" +version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" dependencies = [ "serde", "serde_spanned", @@ -4900,18 +5031,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.9" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.26" +version = "0.22.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap 2.9.0", "serde", @@ -4923,9 +5054,9 @@ dependencies = [ [[package]] name = "toml_write" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" [[package]] name = "tonic" @@ -4994,12 +5125,12 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.6.4" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdb0c213ca27a9f57ab69ddb290fd80d970922355b83ae380b395d3986b8a2e" +checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" dependencies = [ "async-compression", - "bitflags 2.9.0", + "bitflags 2.9.1", "bytes", "futures-core", "futures-util", @@ -5183,9 +5314,9 @@ checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "unicode-width" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" +checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c" [[package]] name = "unsafe-libyaml" @@ -5211,7 +5342,7 @@ dependencies = [ "rustls", "rustls-pki-types", "url", - "webpki-roots", + "webpki-roots 0.26.11", ] [[package]] @@ -5246,19 +5377,21 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "uuid" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "458f7a779bf54acc9f347480ac654f68407d3aab21269a6e3c9f922acd9e2da9" +checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" dependencies = [ "getrandom 0.3.3", + "js-sys", "serde", + "wasm-bindgen", ] [[package]] name = "v_frame" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6f32aaa24bacd11e488aa9ba66369c7cd514885742c9fe08cfe85884db3e92b" +checksum = "666b7727c8875d6ab5db9533418d7c764233ac9c0cff1d469aec8fa127597be2" dependencies = [ "aligned-vec", "num-traits", @@ -5300,9 +5433,9 @@ dependencies = [ [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" @@ -5428,18 +5561,27 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.26.8" +version = "0.26.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2210b291f7ea53617fbafcc4939f10914214ec15aace5ba62293a668f322c5c9" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.1", +] + +[[package]] +name = "webpki-roots" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8782dd5a41a24eed3a4f40b606249b3e236ca61adf1f25ea4d45c73de122b502" dependencies = [ "rustls-pki-types", ] [[package]] name = "weezl" -version = "0.1.8" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" +checksum = "a751b3277700db47d3e574514de2eced5e54dc8a5436a3bf7a0b248b2cee16f3" [[package]] name = "which" @@ -5450,7 +5592,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix", + "rustix 0.38.44", ] [[package]] @@ -5489,32 +5631,55 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.58.0" +version = "0.61.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" +dependencies = [ + "windows-collections", + "windows-core", + "windows-future", + "windows-link", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" dependencies = [ "windows-core", - "windows-targets 0.52.6", ] [[package]] name = "windows-core" -version = "0.58.0" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ "windows-implement", "windows-interface", - "windows-result 0.2.0", - "windows-strings 0.1.0", - "windows-targets 0.52.6", + "windows-link", + "windows-result", + "windows-strings 0.4.2", +] + +[[package]] +name = "windows-future" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" +dependencies = [ + "windows-core", + "windows-link", + "windows-threading", ] [[package]] name = "windows-implement" -version = "0.58.0" +version = "0.60.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" dependencies = [ "proc-macro2", "quote", @@ -5523,9 +5688,9 @@ dependencies = [ [[package]] name = "windows-interface" -version = "0.58.0" +version = "0.59.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" dependencies = [ "proc-macro2", "quote", @@ -5534,9 +5699,19 @@ dependencies = [ [[package]] name = "windows-link" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-numerics" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" +dependencies = [ + "windows-core", + "windows-link", +] [[package]] name = "windows-registry" @@ -5544,39 +5719,20 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" dependencies = [ - "windows-result 0.3.2", + "windows-result", "windows-strings 0.3.1", - "windows-targets 0.53.0", + "windows-targets 0.53.2", ] [[package]] name = "windows-result" -version = "0.2.0" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" -dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-result" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" dependencies = [ "windows-link", ] -[[package]] -name = "windows-strings" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" -dependencies = [ - "windows-result 0.2.0", - "windows-targets 0.52.6", -] - [[package]] name = "windows-strings" version = "0.3.1" @@ -5586,6 +5742,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -5613,6 +5778,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.2", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -5646,9 +5820,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.53.0" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b" +checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef" dependencies = [ "windows_aarch64_gnullvm 0.53.0", "windows_aarch64_msvc 0.53.0", @@ -5660,6 +5834,15 @@ dependencies = [ "windows_x86_64_msvc 0.53.0", ] +[[package]] +name = "windows-threading" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" +dependencies = [ + "windows-link", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -5800,9 +5983,9 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "winnow" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" +checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" dependencies = [ "memchr", ] @@ -5823,7 +6006,7 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", ] [[package]] @@ -5875,18 +6058,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.25" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.25" +version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", @@ -5999,9 +6182,9 @@ dependencies = [ [[package]] name = "zune-jpeg" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99a5bab8d7dedf81405c4bb1f2b83ea057643d9cb28778cea9eecddeedd2e028" +checksum = "0f6fe2e33d02a98ee64423802e16df3de99c43e5cf5ff983767e1128b394c8ac" dependencies = [ "zune-core", ] From bae8192fb3cef6dbe6a14015ab46639df14ee288 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 20 Jun 2025 23:39:20 +0100 Subject: [PATCH 2031/2291] chore: Bump resolv-conf from 0.7.1 to 0.7.4 --- Cargo.lock | 7 ++----- Cargo.toml | 9 ++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59662da2..a8bab900 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3788,11 +3788,8 @@ dependencies = [ [[package]] name = "resolv-conf" -version = "0.7.1" -source = "git+https://forgejo.ellis.link/continuwuation/resolv-conf?rev=200e958941d522a70c5877e3d846f55b5586c68d#200e958941d522a70c5877e3d846f55b5586c68d" -dependencies = [ - "hostname", -] +version = "0.7.4" +source = "git+https://forgejo.ellis.link/continuwuation/resolv-conf?rev=56251316cc4127bcbf36e68ce5e2093f4d33e227#56251316cc4127bcbf36e68ce5e2093f4d33e227" [[package]] name = "rgb" diff --git a/Cargo.toml b/Cargo.toml index af904447..0ebb758c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -381,7 +381,7 @@ features = [ "unstable-msc4121", "unstable-msc4125", "unstable-msc4186", - "unstable-msc4203", # sending to-device events to appservices + "unstable-msc4203", # sending to-device events to appservices "unstable-msc4210", # remove legacy mentions "unstable-extensible-events", "unstable-pdu", @@ -580,12 +580,11 @@ rev = "9c8e51510c35077df888ee72a36b4b05637147da" git = "https://forgejo.ellis.link/continuwuation/hyper-util" rev = "e4ae7628fe4fcdacef9788c4c8415317a4489941" -# allows no-aaaa option in resolv.conf -# bumps rust edition and toolchain to 1.86.0 and 2024 -# use sat_add on line number errors +# Allows no-aaaa option in resolv.conf +# Use 1-indexed line numbers when displaying parse error messages [patch.crates-io.resolv-conf] git = "https://forgejo.ellis.link/continuwuation/resolv-conf" -rev = "200e958941d522a70c5877e3d846f55b5586c68d" +rev = "56251316cc4127bcbf36e68ce5e2093f4d33e227" # # Our crates From 70df8364b38137011b540cf39821967c91c41efa Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 21 Jun 2025 00:50:02 +0100 Subject: [PATCH 2032/2291] chore: Bump rustyline-async from 0.4.3 to 0.4.6 --- Cargo.lock | 31 +++++++------------------------ Cargo.toml | 6 +++--- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a8bab900..7852d2ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1105,7 +1105,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "980c2afde4af43d6a05c5be738f9eae595cff86dce1f38f88b95058a98c027f3" dependencies = [ - "crossterm 0.29.0", + "crossterm", ] [[package]] @@ -1165,7 +1165,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5282b45c96c5978c8723ea83385cb9a488b64b7d175733f48d07bf9da514a863" dependencies = [ "crokey-proc_macros", - "crossterm 0.29.0", + "crossterm", "once_cell", "serde", "strict", @@ -1177,7 +1177,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ea0218d3fedf0797fa55676f1964ef5d27103d41ed0281b4bbd2a6e6c3d8d28" dependencies = [ - "crossterm 0.29.0", + "crossterm", "proc-macro2", "quote", "strict", @@ -1240,23 +1240,6 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" -[[package]] -name = "crossterm" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" -dependencies = [ - "bitflags 2.9.1", - "crossterm_winapi", - "futures-core", - "mio", - "parking_lot", - "rustix 0.38.44", - "signal-hook", - "signal-hook-mio", - "winapi", -] - [[package]] name = "crossterm" version = "0.29.0" @@ -1267,6 +1250,7 @@ dependencies = [ "crossterm_winapi", "derive_more", "document-features", + "futures-core", "mio", "parking_lot", "rustix 1.0.7", @@ -4153,11 +4137,10 @@ checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" [[package]] name = "rustyline-async" -version = "0.4.3" -source = "git+https://forgejo.ellis.link/continuwuation/rustyline-async?rev=deaeb0694e2083f53d363b648da06e10fc13900c#deaeb0694e2083f53d363b648da06e10fc13900c" +version = "0.4.6" +source = "git+https://forgejo.ellis.link/continuwuation/rustyline-async?rev=e9f01cf8c6605483cb80b3b0309b400940493d7f#e9f01cf8c6605483cb80b3b0309b400940493d7f" dependencies = [ - "crossterm 0.28.1", - "futures-channel", + "crossterm", "futures-util", "pin-project", "thingbuf", diff --git a/Cargo.toml b/Cargo.toml index 0ebb758c..f3de5d7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -556,11 +556,11 @@ rev = "1e64095a8051a1adf0d1faa307f9f030889ec2aa" git = "https://forgejo.ellis.link/continuwuation/tracing" rev = "1e64095a8051a1adf0d1faa307f9f030889ec2aa" -# adds a tab completion callback: https://forgejo.ellis.link/continuwuation/rustyline-async/commit/de26100b0db03e419a3d8e1dd26895d170d1fe50 -# adds event for CTRL+\: https://forgejo.ellis.link/continuwuation/rustyline-async/commit/67d8c49aeac03a5ef4e818f663eaa94dd7bf339b +# adds a tab completion callback: https://forgejo.ellis.link/continuwuation/rustyline-async/src/branch/main/.patchy/0002-add-tab-completion-callback.patch +# adds event for CTRL+\: https://forgejo.ellis.link/continuwuation/rustyline-async/src/branch/main/.patchy/0001-add-event-for-ctrl.patch [patch.crates-io.rustyline-async] git = "https://forgejo.ellis.link/continuwuation/rustyline-async" -rev = "deaeb0694e2083f53d363b648da06e10fc13900c" +rev = "e9f01cf8c6605483cb80b3b0309b400940493d7f" # adds LIFO queue scheduling; this should be updated with PR progress. [patch.crates-io.event-listener] From 93719018a881f7aa2e150c43647565995b5c6b0e Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 21 Jun 2025 17:58:28 +0100 Subject: [PATCH 2033/2291] ci: Run additional sanity checks on repository --- .editorconfig | 2 +- .forgejo/actions/prefligit/action.yml | 22 +++++++++++ .forgejo/workflows/prefligit-checks.yml | 15 ++++++++ .forgejo/workflows/rust-checks.yml | 2 +- .pre-commit-config.yaml | 50 +++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 .forgejo/actions/prefligit/action.yml create mode 100644 .forgejo/workflows/prefligit-checks.yml create mode 100644 .pre-commit-config.yaml diff --git a/.editorconfig b/.editorconfig index 91f073bd..17bb0c17 100644 --- a/.editorconfig +++ b/.editorconfig @@ -23,6 +23,6 @@ indent_size = 2 indent_style = tab max_line_length = 98 -[{.forgejo/**/*.yml,.github/**/*.yml}] +[{**/*.yml}] indent_size = 2 indent_style = space diff --git a/.forgejo/actions/prefligit/action.yml b/.forgejo/actions/prefligit/action.yml new file mode 100644 index 00000000..10f47af9 --- /dev/null +++ b/.forgejo/actions/prefligit/action.yml @@ -0,0 +1,22 @@ +name: reflighit +description: | + Runs reflighit, pre-commit reimplemented in Rust. +inputs: + extra_args: + description: options to pass to pre-commit run + required: false + default: '--all-files' + +runs: + using: composite + steps: + - name: Install Prefligit + shell: bash + run: | + curl --proto '=https' --tlsv1.2 -LsSf https://github.com/j178/prefligit/releases/download/v0.0.10/prefligit-installer.sh | sh + - uses: actions/cache@v3 + with: + path: ~/.cache/prefligit + key: prefligit-0|${{ hashFiles('.pre-commit-config.yaml') }} + - run: prefligit run --show-diff-on-failure --color=always ${{ inputs.extra_args }} + shell: bash diff --git a/.forgejo/workflows/prefligit-checks.yml b/.forgejo/workflows/prefligit-checks.yml new file mode 100644 index 00000000..8eae8451 --- /dev/null +++ b/.forgejo/workflows/prefligit-checks.yml @@ -0,0 +1,15 @@ +name: Checks / Prefligit + +on: + push: + +jobs: + prefligit: + runs-on: ubuntu-latest + env: + FROM_REF: ${{ github.event.pull_request.base.sha || (!github.event.forced && ( github.event.before != '0000000000000000000000000000000000000000' && github.event.before || github.sha )) || format('{0}~', github.sha) }} + TO_REF: ${{ github.sha }} + steps: + - uses: ./.forgejo/actions/prefligit + with: + extra_args: --from-ref ${{ env.FROM_REF }} --to-ref ${{ env.TO_REF }} --hook-stage manual diff --git a/.forgejo/workflows/rust-checks.yml b/.forgejo/workflows/rust-checks.yml index 35ca1ad7..105efd0f 100644 --- a/.forgejo/workflows/rust-checks.yml +++ b/.forgejo/workflows/rust-checks.yml @@ -1,4 +1,4 @@ -name: Rust Checks +name: Checks / Rust on: push: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..fc0f9d71 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,50 @@ +default_install_hook_types: + - pre-commit + - commit-msg +default_stages: + - pre-commit + - manual + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-byte-order-marker + - id: check-case-conflict + - id: check-symlinks + - id: destroyed-symlinks + - id: check-yaml + - id: check-json + - id: check-toml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: mixed-line-ending + - id: check-merge-conflict + - id: check-added-large-files + + - repo: https://github.com/crate-ci/typos + rev: v1.26.0 + hooks: + - id: typos + + - repo: local + hooks: + - id: cargo-fmt + name: cargo fmt + entry: cargo +nightly fmt -- + language: system + types: [rust] + pass_filenames: false + stages: + - pre-commit + + - repo: local + hooks: + - id: cargo-clippy + name: cargo clippy + language: system + types: [rust] + pass_filenames: false + entry: cargo clippy --workspace --locked --no-deps --profile test -- -D warnings + stages: + - pre-commit From 46c193e74b2ce86c48ce802333a0aabce37fd6e9 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 21 Jun 2025 17:59:01 +0100 Subject: [PATCH 2034/2291] chore: fix end of files & trailing whitespace --- .gitattributes | 2 +- docs/deploying/arch-linux.md | 2 +- docs/deploying/docker-compose.override.yml | 1 - docs/deploying/docker-compose.with-caddy.yml | 2 +- docs/deploying/docker-compose.with-traefik.yml | 2 +- docs/deploying/nixos.md | 2 +- docs/static/_headers | 2 +- docs/static/announcements.schema.json | 2 +- docs/static/support | 2 +- theme/css/chrome.css | 1 - 10 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.gitattributes b/.gitattributes index 3dfaca65..a1a845b6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -84,4 +84,4 @@ Cargo.lock text *.zst binary # Text files where line endings should be preserved -*.patch -text \ No newline at end of file +*.patch -text diff --git a/docs/deploying/arch-linux.md b/docs/deploying/arch-linux.md index 52d2afb2..6e50410d 100644 --- a/docs/deploying/arch-linux.md +++ b/docs/deploying/arch-linux.md @@ -2,4 +2,4 @@ Continuwuity is available on the `archlinuxcn` repository and AUR, with the same package name `continuwuity`, which includes latest taggged version. The development version is available on AUR as `continuwuity-git` -Simply install the `continuwuity` package. Configure the service in `/etc/conduwuit/conduwuit.toml`, then enable/start the continuwuity.service. \ No newline at end of file +Simply install the `continuwuity` package. Configure the service in `/etc/conduwuit/conduwuit.toml`, then enable/start the continuwuity.service. diff --git a/docs/deploying/docker-compose.override.yml b/docs/deploying/docker-compose.override.yml index 168b1ae6..c1a7248c 100644 --- a/docs/deploying/docker-compose.override.yml +++ b/docs/deploying/docker-compose.override.yml @@ -34,4 +34,3 @@ services: # - "traefik.http.routers.to-element-web.tls.certresolver=letsencrypt" # vim: ts=2:sw=2:expandtab - diff --git a/docs/deploying/docker-compose.with-caddy.yml b/docs/deploying/docker-compose.with-caddy.yml index 3dfc9d85..dd6a778f 100644 --- a/docs/deploying/docker-compose.with-caddy.yml +++ b/docs/deploying/docker-compose.with-caddy.yml @@ -26,7 +26,7 @@ services: restart: unless-stopped volumes: - db:/var/lib/continuwuity - - /etc/resolv.conf:/etc/resolv.conf:ro # Use the host's DNS resolver rather than Docker's. + - /etc/resolv.conf:/etc/resolv.conf:ro # Use the host's DNS resolver rather than Docker's. #- ./continuwuity.toml:/etc/continuwuity.toml environment: CONTINUWUITY_SERVER_NAME: example.com # EDIT THIS diff --git a/docs/deploying/docker-compose.with-traefik.yml b/docs/deploying/docker-compose.with-traefik.yml index 9acc4221..49b7c905 100644 --- a/docs/deploying/docker-compose.with-traefik.yml +++ b/docs/deploying/docker-compose.with-traefik.yml @@ -8,7 +8,7 @@ services: restart: unless-stopped volumes: - db:/var/lib/continuwuity - - /etc/resolv.conf:/etc/resolv.conf:ro # Use the host's DNS resolver rather than Docker's. + - /etc/resolv.conf:/etc/resolv.conf:ro # Use the host's DNS resolver rather than Docker's. #- ./continuwuity.toml:/etc/continuwuity.toml networks: - proxy diff --git a/docs/deploying/nixos.md b/docs/deploying/nixos.md index cf2c09e4..2fdcbe5c 100644 --- a/docs/deploying/nixos.md +++ b/docs/deploying/nixos.md @@ -29,7 +29,7 @@ appropriately to use Continuwuity instead of Conduit. Due to the lack of a Continuwuity NixOS module, when using the `services.matrix-conduit` module a workaround like the one below is necessary to use UNIX sockets. This is because the UNIX -socket option does not exist in Conduit, and the module forcibly sets the `address` and +socket option does not exist in Conduit, and the module forcibly sets the `address` and `port` config options. ```nix diff --git a/docs/static/_headers b/docs/static/_headers index 6e52de9f..dd07f21b 100644 --- a/docs/static/_headers +++ b/docs/static/_headers @@ -3,4 +3,4 @@ Content-Type: application/json /.well-known/continuwuity/* Access-Control-Allow-Origin: * - Content-Type: application/json \ No newline at end of file + Content-Type: application/json diff --git a/docs/static/announcements.schema.json b/docs/static/announcements.schema.json index cacd10c9..474c0d29 100644 --- a/docs/static/announcements.schema.json +++ b/docs/static/announcements.schema.json @@ -32,4 +32,4 @@ "required": [ "announcements" ] - } \ No newline at end of file + } diff --git a/docs/static/support b/docs/static/support index 6b7a9860..88a85c7d 100644 --- a/docs/static/support +++ b/docs/static/support @@ -21,4 +21,4 @@ } ], "support_page": "https://continuwuity.org/introduction#contact" -} \ No newline at end of file +} diff --git a/theme/css/chrome.css b/theme/css/chrome.css index d6cc2b32..f14ffc2c 100644 --- a/theme/css/chrome.css +++ b/theme/css/chrome.css @@ -605,4 +605,3 @@ ul#searchresults span.teaser em { margin-inline-start: -14px; width: 14px; } - From a682e9dbb879340c63772d1978ca8b74eb28840f Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 21 Jun 2025 18:03:38 +0100 Subject: [PATCH 2035/2291] chore: Add commit to ignored revs --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 33f738f3..ddfc0568 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -5,3 +5,5 @@ f419c64aca300a338096b4e0db4c73ace54f23d0 # use chain_width 60 162948313c212193965dece50b816ef0903172ba 5998a0d883d31b866f7c8c46433a8857eae51a89 +# trailing whitespace and newlines +46c193e74b2ce86c48ce802333a0aabce37fd6e9 From 2ecbd75d64a6f48a8baaf61145d684ff880ea986 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 21 Jun 2025 18:20:04 +0100 Subject: [PATCH 2036/2291] ci: fixes - Install UV - Verbose run - Set permissions explicitly - Check all files --- .editorconfig | 2 +- .forgejo/actions/prefligit/action.yml | 11 ++++++++--- .forgejo/workflows/prefligit-checks.yml | 9 ++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.editorconfig b/.editorconfig index 17bb0c17..3e7fd1b8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -23,6 +23,6 @@ indent_size = 2 indent_style = tab max_line_length = 98 -[{**/*.yml}] +[*.yml] indent_size = 2 indent_style = space diff --git a/.forgejo/actions/prefligit/action.yml b/.forgejo/actions/prefligit/action.yml index 10f47af9..8cbd4500 100644 --- a/.forgejo/actions/prefligit/action.yml +++ b/.forgejo/actions/prefligit/action.yml @@ -1,6 +1,6 @@ -name: reflighit +name: prefligit description: | - Runs reflighit, pre-commit reimplemented in Rust. + Runs prefligit, pre-commit reimplemented in Rust. inputs: extra_args: description: options to pass to pre-commit run @@ -10,6 +10,11 @@ inputs: runs: using: composite steps: + - name: Install uv + uses: https://github.com/astral-sh/setup-uv@v6 + with: + enable-cache: true + ignore-nothing-to-cache: true - name: Install Prefligit shell: bash run: | @@ -18,5 +23,5 @@ runs: with: path: ~/.cache/prefligit key: prefligit-0|${{ hashFiles('.pre-commit-config.yaml') }} - - run: prefligit run --show-diff-on-failure --color=always ${{ inputs.extra_args }} + - run: prefligit run --show-diff-on-failure --color=always -v ${{ inputs.extra_args }} shell: bash diff --git a/.forgejo/workflows/prefligit-checks.yml b/.forgejo/workflows/prefligit-checks.yml index 8eae8451..cc512496 100644 --- a/.forgejo/workflows/prefligit-checks.yml +++ b/.forgejo/workflows/prefligit-checks.yml @@ -2,6 +2,9 @@ name: Checks / Prefligit on: push: + pull_request: +permissions: + contents: read jobs: prefligit: @@ -10,6 +13,10 @@ jobs: FROM_REF: ${{ github.event.pull_request.base.sha || (!github.event.forced && ( github.event.before != '0000000000000000000000000000000000000000' && github.event.before || github.sha )) || format('{0}~', github.sha) }} TO_REF: ${{ github.sha }} steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false - uses: ./.forgejo/actions/prefligit with: - extra_args: --from-ref ${{ env.FROM_REF }} --to-ref ${{ env.TO_REF }} --hook-stage manual + extra_args: --all-files --hook-stage manual From 4f174324baadfd154a48d9e6e79b20ca63770854 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Mon, 23 Jun 2025 01:04:27 +0100 Subject: [PATCH 2037/2291] docs: Update contributing guide --- CONTRIBUTING.md | 92 ++++++++++++++++++++------------------------- docs/development.md | 76 ++++++++++++++++++++++--------------- 2 files changed, 86 insertions(+), 82 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index da426801..c57de8b4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing guide -This page is for about contributing to Continuwuity. The +This page is about contributing to Continuwuity. The [development](./development.md) page may be of interest for you as well. If you would like to work on an [issue][issues] that is not assigned, preferably @@ -10,7 +10,7 @@ and comment on it. ### Linting and Formatting It is mandatory all your changes satisfy the lints (clippy, rustc, rustdoc, etc) -and your code is formatted via the **nightly** `cargo fmt`. A lot of the +and your code is formatted via the **nightly** rustfmt (`cargo +nightly fmt`). A lot of the `rustfmt.toml` features depend on nightly toolchain. It would be ideal if they weren't nightly-exclusive features, but they currently still are. CI's rustfmt uses nightly. @@ -21,67 +21,62 @@ comment saying why. Do not write inefficient code for the sake of satisfying lints. If a lint is wrong and provides a more inefficient solution or suggestion, allow the lint and mention that in a comment. -### Running CI tests locally +### Running tests locally -continuwuity's CI for tests, linting, formatting, audit, etc use -[`engage`][engage]. engage can be installed from nixpkgs or `cargo install -engage`. continuwuity's Nix flake devshell has the nixpkgs engage with `direnv`. -Use `engage --help` for more usage details. +Tests, compilation, and linting can be run with standard Cargo commands: -To test, format, lint, etc that CI would do, install engage, allow the `.envrc` -file using `direnv allow`, and run `engage`. +```bash +# Run tests +cargo test -All of the tasks are defined at the [engage.toml][engage.toml] file. You can -view all of them neatly by running `engage list` +# Check compilation +cargo check --workspace -If you would like to run only a specific engage task group, use `just`: +# Run lints +cargo clippy --workspace +# Auto-fix: cargo clippy --workspace --fix --allow-staged; -- `engage just ` -- Example: `engage just lints` +# Format code (must use nightly) +cargo +nightly fmt +``` -If you would like to run a specific engage task in a specific group, use `just - [TASK]`: `engage just lints cargo-fmt` +### Building Docker images -The following binaries are used in [`engage.toml`][engage.toml]: +Docker images can be built using the standard Docker build command: -- [`engage`][engage] -- `nix` -- [`direnv`][direnv] -- `rustc` -- `cargo` -- `cargo-fmt` -- `rustdoc` -- `cargo-clippy` -- [`cargo-audit`][cargo-audit] -- [`cargo-deb`][cargo-deb] -- [`lychee`][lychee] -- [`markdownlint-cli`][markdownlint-cli] -- `dpkg` +```bash +docker build -f docker/Dockerfile . +``` + +The Docker image can be cross-compiled for different architectures if needed. ### Matrix tests -CI runs [Complement][complement], but currently does not fail if results from -the checked-in results differ with the new results. If your changes are done to -fix Matrix tests, note that in your pull request. If more Complement tests start -failing from your changes, please review the logs (they are uploaded as -artifacts) and determine if they're intended or not. +Continuwuity uses [Complement][complement] for Matrix protocol compliance testing. Complement tests are run manually by developers, and documentation on how to run these tests locally is currently being developed. -If you'd like to run Complement locally using Nix, see the -[testing](development/testing.md) page. +If your changes are done to fix Matrix tests, please note that in your pull request. If more Complement tests start failing from your changes, please review the logs and determine if they're intended or not. -[Sytest][sytest] support will come soon. +[Sytest][sytest] is currently unsupported. ### Writing documentation -Continuwuity's website uses [`mdbook`][mdbook] and deployed via CI using GitHub -Pages in the [`documentation.yml`][documentation.yml] workflow file with Nix's -mdbook in the devshell. All documentation is in the `docs/` directory at the top -level. The compiled mdbook website is also uploaded as an artifact. +Continuwuity's website uses [`mdbook`][mdbook] and is deployed via CI using Cloudflare Pages +in the [`documentation.yml`][documentation.yml] workflow file. All documentation is in the `docs/` +directory at the top level. -To build the documentation using Nix, run: `bin/nix-build-and-cache just .#book` +To build the documentation locally: -The output of the mdbook generation is in `result/`. mdbooks can be opened in -your browser from the individual HTML files without any web server needed. +1. Install mdbook if you don't have it already: + ```bash + cargo install mdbook # or cargo binstall, or another method + ``` + +2. Build the documentation: + ```bash + mdbook build + ``` + +The output of the mdbook generation is in `public/`. You can open the HTML files directly in your browser without needing a web server. ### Inclusivity and Diversity @@ -132,13 +127,6 @@ continuwuityMatrix rooms for Code of Conduct violations. [issues]: https://forgejo.ellis.link/continuwuation/continuwuity/issues [continuwuity-matrix]: https://matrix.to/#/#continuwuity:continuwuity.org [complement]: https://github.com/matrix-org/complement/ -[engage.toml]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/engage.toml -[engage]: https://charles.page.computer.surgery/engage/ [sytest]: https://github.com/matrix-org/sytest/ -[cargo-deb]: https://github.com/kornelski/cargo-deb -[lychee]: https://github.com/lycheeverse/lychee -[markdownlint-cli]: https://github.com/igorshubovych/markdownlint-cli -[cargo-audit]: https://github.com/RustSec/rustsec/tree/main/cargo-audit -[direnv]: https://direnv.net/ [mdbook]: https://rust-lang.github.io/mdBook/ [documentation.yml]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/.forgejo/workflows/documentation.yml diff --git a/docs/development.md b/docs/development.md index 1e344f41..dfbddea0 100644 --- a/docs/development.md +++ b/docs/development.md @@ -68,31 +68,22 @@ do this if Rust supported workspace-level features to begin with. ## List of forked dependencies -During Continuwuity development, we have had to fork -some dependencies to support our use-cases in some areas. This ranges from -things said upstream project won't accept for any reason, faster-paced -development (unresponsive or slow upstream), Continuwuity-specific usecases, or -lack of time to upstream some things. +During Continuwuity (and prior projects) development, we have had to fork some dependencies to support our use-cases. +These forks exist for various reasons including features that upstream projects won't accept, +faster-paced development, Continuwuity-specific usecases, or lack of time to upstream changes. -- [ruma/ruma][1]: - various performance -improvements, more features, faster-paced development, better client/server interop -hacks upstream won't accept, etc -- [facebook/rocksdb][2]: - liburing -build fixes and GCC debug build fix -- [tikv/jemallocator][3]: - musl -builds seem to be broken on upstream, fixes some broken/suspicious code in -places, additional safety measures, and support redzones for Valgrind -- [zyansheep/rustyline-async][4]: - - tab completion callback and -`CTRL+\` signal quit event for Continuwuity console CLI -- [rust-rocksdb/rust-rocksdb][5]: - - [`@zaidoon1`][8]'s fork -has quicker updates, more up to date dependencies, etc. Our fork fixes musl build -issues, removes unnecessary `gtest` include, and uses our RocksDB and jemallocator -forks. -- [tokio-rs/tracing][6]: - Implements -`Clone` for `EnvFilter` to support dynamically changing tracing envfilter's -alongside other logging/metrics things +All forked dependencies are maintained under the [continuwuation organization on Forgejo](https://forgejo.ellis.link/continuwuation): + +- [ruwuma][continuwuation-ruwuma] - Fork of [ruma/ruma][ruma] with various performance improvements, more features and better client/server interop +- [rocksdb][continuwuation-rocksdb] - Fork of [facebook/rocksdb][rocksdb] via [`@zaidoon1`][8] with liburing build fixes and GCC debug build fixes +- [jemallocator][continuwuation-jemallocator] - Fork of [tikv/jemallocator][jemallocator] fixing musl builds, suspicious code, + and adding support for redzones in Valgrind +- [rustyline-async][continuwuation-rustyline-async] - Fork of [zyansheep/rustyline-async][rustyline-async] with tab completion callback + and `CTRL+\` signal quit event for Continuwuity console CLI +- [rust-rocksdb][continuwuation-rust-rocksdb] - Fork of [rust-rocksdb/rust-rocksdb][rust-rocksdb] fixing musl build issues, + removing unnecessary `gtest` include, and using our RocksDB and jemallocator forks +- [tracing][continuwuation-tracing] - Fork of [tokio-rs/tracing][tracing] implementing `Clone` for `EnvFilter` to + support dynamically changing tracing environments ## Debugging with `tokio-console` @@ -113,12 +104,37 @@ You will also need to enable the `tokio_console` config option in Continuwuity w starting it. This was due to tokio-console causing gradual memory leak/usage if left enabled. -[1]: https://github.com/ruma/ruma/ -[2]: https://github.com/facebook/rocksdb/ -[3]: https://github.com/tikv/jemallocator/ -[4]: https://github.com/zyansheep/rustyline-async/ -[5]: https://github.com/rust-rocksdb/rust-rocksdb/ -[6]: https://github.com/tokio-rs/tracing/ +## Building Docker Images + +To build a Docker image for Continuwuity, use the standard Docker build command: + +```bash +docker build -f docker/Dockerfile . +``` + +The image can be cross-compiled for different architectures. + +## Matrix Protocol Compliance Testing + +Complement (the Matrix protocol compliance testing suite) is run manually by developers. +Documentation on how to run Complement tests locally is being developed and will be added soon. + +Sytest is currently unsupported. + +[continuwuation-ruwuma]: https://forgejo.ellis.link/continuwuation/ruwuma +[continuwuation-rocksdb]: https://forgejo.ellis.link/continuwuation/rocksdb +[continuwuation-jemallocator]: https://forgejo.ellis.link/continuwuation/jemallocator +[continuwuation-rustyline-async]: https://forgejo.ellis.link/continuwuation/rustyline-async +[continuwuation-rust-rocksdb]: https://forgejo.ellis.link/continuwuation/rust-rocksdb +[continuwuation-tracing]: https://forgejo.ellis.link/continuwuation/tracing + +[ruma]: https://github.com/ruma/ruma/ +[rocksdb]: https://github.com/facebook/rocksdb/ +[jemallocator]: https://github.com/tikv/jemallocator/ +[rustyline-async]: https://github.com/zyansheep/rustyline-async/ +[rust-rocksdb]: https://github.com/rust-rocksdb/rust-rocksdb/ +[tracing]: https://github.com/tokio-rs/tracing/ + [7]: https://docs.rs/tokio-console/latest/tokio_console/ [8]: https://github.com/zaidoon1/ [9]: https://github.com/rust-lang/cargo/issues/12162 From 4d69a1ad511b1fc81a668ef319fb1e053788dfc2 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Mon, 23 Jun 2025 01:25:38 +0100 Subject: [PATCH 2038/2291] docs: Deduplicate sections --- CONTRIBUTING.md | 14 ++------------ docs/development.md | 7 ------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c57de8b4..3dc99dc2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,16 +40,6 @@ cargo clippy --workspace cargo +nightly fmt ``` -### Building Docker images - -Docker images can be built using the standard Docker build command: - -```bash -docker build -f docker/Dockerfile . -``` - -The Docker image can be cross-compiled for different architectures if needed. - ### Matrix tests Continuwuity uses [Complement][complement] for Matrix protocol compliance testing. Complement tests are run manually by developers, and documentation on how to run these tests locally is currently being developed. @@ -120,9 +110,9 @@ By sending a pull request or patch, you are agreeing that your changes are allowed to be licenced under the Apache-2.0 licence and all of your conduct is in line with the Contributor's Covenant, and continuwuity's Code of Conduct. -Contribution by users who violate either of these code of conducts will not have +Contribution by users who violate either of these code of conducts may not have their contributions accepted. This includes users who have been banned from -continuwuityMatrix rooms for Code of Conduct violations. +continuwuity Matrix rooms for Code of Conduct violations. [issues]: https://forgejo.ellis.link/continuwuation/continuwuity/issues [continuwuity-matrix]: https://matrix.to/#/#continuwuity:continuwuity.org diff --git a/docs/development.md b/docs/development.md index dfbddea0..68b963c8 100644 --- a/docs/development.md +++ b/docs/development.md @@ -114,13 +114,6 @@ docker build -f docker/Dockerfile . The image can be cross-compiled for different architectures. -## Matrix Protocol Compliance Testing - -Complement (the Matrix protocol compliance testing suite) is run manually by developers. -Documentation on how to run Complement tests locally is being developed and will be added soon. - -Sytest is currently unsupported. - [continuwuation-ruwuma]: https://forgejo.ellis.link/continuwuation/ruwuma [continuwuation-rocksdb]: https://forgejo.ellis.link/continuwuation/rocksdb [continuwuation-jemallocator]: https://forgejo.ellis.link/continuwuation/jemallocator From 4a289a9feedc720dd17a3af08d7dc7d4b255e55f Mon Sep 17 00:00:00 2001 From: Kimiblock Moe Date: Tue, 24 Jun 2025 19:01:21 +0800 Subject: [PATCH 2039/2291] arch systemd: use credentials to load config --- arch/conduwuit.service | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/conduwuit.service b/arch/conduwuit.service index c86e37bd..d5a65e4d 100644 --- a/arch/conduwuit.service +++ b/arch/conduwuit.service @@ -6,6 +6,7 @@ After=network-online.target Documentation=https://continuwuity.org/ RequiresMountsFor=/var/lib/private/conduwuit Alias=matrix-conduwuit.service + [Service] DynamicUser=yes Type=notify-reload @@ -59,7 +60,8 @@ StateDirectory=conduwuit RuntimeDirectory=conduwuit RuntimeDirectoryMode=0750 -Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml" +Environment=CONTINUWUITY_CONFIG=${CREDENTIALS_DIRECTORY}/config.toml +LoadCredential=config.toml:/etc/conduwuit/conduwuit.toml BindPaths=/var/lib/private/conduwuit:/var/lib/matrix-conduit BindPaths=/var/lib/private/conduwuit:/var/lib/private/matrix-conduit From 3177545a6f966c19a2f219a3641b9fa5c8bfdb38 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 24 Jun 2025 21:45:54 +0100 Subject: [PATCH 2040/2291] chore: Remove clippy pre-commit hook It's too slow for a good git experience --- .pre-commit-config.yaml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fc0f9d71..22bcd09c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,14 +37,3 @@ repos: pass_filenames: false stages: - pre-commit - - - repo: local - hooks: - - id: cargo-clippy - name: cargo clippy - language: system - types: [rust] - pass_filenames: false - entry: cargo clippy --workspace --locked --no-deps --profile test -- -D warnings - stages: - - pre-commit From 9bbe333082cc74926609a6b7c92eb76de877c452 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 24 Jun 2025 21:48:33 +0100 Subject: [PATCH 2041/2291] ci: Don't run docs flow when the secret is inaccessible --- .forgejo/workflows/documentation.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.forgejo/workflows/documentation.yml b/.forgejo/workflows/documentation.yml index 7d95a317..4f3e903c 100644 --- a/.forgejo/workflows/documentation.yml +++ b/.forgejo/workflows/documentation.yml @@ -17,6 +17,7 @@ jobs: docs: name: Build and Deploy Documentation runs-on: ubuntu-latest + if: secrets.CLOUDFLARE_API_TOKEN != '' steps: - name: Sync repository From eb75c4ecb0b5ac0cec38df85c634323103a28f6d Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 24 Jun 2025 22:05:52 +0100 Subject: [PATCH 2042/2291] chore: Fix typos in commit messages automatically --- .pre-commit-config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 22bcd09c..facebcc4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,6 +26,9 @@ repos: rev: v1.26.0 hooks: - id: typos + - id: typos + name: commit-msg-typos + stages: [commit-msg] - repo: local hooks: From b787e97dc173da7a6673df9f5ea628a60340a497 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 24 Jun 2025 22:22:13 +0100 Subject: [PATCH 2043/2291] chore: Document & enforce conventional commit messages --- .pre-commit-config.yaml | 5 +++ CONTRIBUTING.md | 80 +++++++++++++++++++++++++++++++++++++++++ committed.toml | 2 ++ 3 files changed, 87 insertions(+) create mode 100644 committed.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index facebcc4..68e3a982 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,6 +30,11 @@ repos: name: commit-msg-typos stages: [commit-msg] + - repo: https://github.com/crate-ci/committed + rev: v1.1.7 + hooks: + - id: committed + - repo: local hooks: - id: cargo-fmt diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3dc99dc2..1c091183 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,6 +21,45 @@ comment saying why. Do not write inefficient code for the sake of satisfying lints. If a lint is wrong and provides a more inefficient solution or suggestion, allow the lint and mention that in a comment. +### Pre-commit Checks + +Continuwuity uses pre-commit hooks to enforce various coding standards and catch common issues before they're committed. These checks include: + +- Code formatting and linting +- Typo detection (both in code and commit messages) +- Checking for large files +- Ensuring proper line endings and no trailing whitespace +- Validating YAML, JSON, and TOML files +- Checking for merge conflicts + +You can run these checks locally by installing [prefligit](https://github.com/j178/prefligit): + + +```bash +# Install prefligit using cargo-binstall +cargo binstall prefligit + +# Install git hooks to run checks automatically +prefligit install + +# Run all checks +prefligit --all-files +``` + +Alternatively, you can use [pre-commit](https://pre-commit.com/): +```bash +# Install pre-commit +pip install pre-commit + +# Install the hooks +pre-commit install + +# Run all checks manually +pre-commit run --all-files +``` + +These same checks are run in CI via the prefligit-checks workflow to ensure consistency. + ### Running tests locally Tests, compilation, and linting can be run with standard Cargo commands: @@ -94,6 +133,40 @@ Rust's default style and standards with regards to [function names, variable names, comments](https://rust-lang.github.io/api-guidelines/naming.html), etc applies here. +### Commit Messages + +Continuwuity follows the [Conventional Commits](https://www.conventionalcommits.org/) specification for commit messages. This provides a standardized format that makes the commit history more readable and enables automated tools to generate changelogs. + +The basic structure is: +``` +[(optional scope)]: + +[optional body] + +[optional footer(s)] +``` + +The allowed types for commits are: +- `fix`: Bug fixes +- `feat`: New features +- `docs`: Documentation changes +- `style`: Changes that don't affect the meaning of the code (formatting, etc.) +- `refactor`: Code changes that neither fix bugs nor add features +- `perf`: Performance improvements +- `test`: Adding or fixing tests +- `build`: Changes to the build system or dependencies +- `ci`: Changes to CI configuration +- `chore`: Other changes that don't modify source or test files + +Examples: +``` +feat: add user authentication +fix(database): resolve connection pooling issue +docs: update installation instructions +``` + +The project uses the `committed` hook to validate commit messages in pre-commit. This ensures all commits follow the conventional format. + ### Creating pull requests Please try to keep contributions to the Forgejo Instance. While the mirrors of continuwuity @@ -103,6 +176,13 @@ This prevents us from having to ping once in a while to double check the status of it, especially when the CI completed successfully and everything so it *looks* done. +Before submitting a pull request, please ensure: +1. Your code passes all CI checks (formatting, linting, typo detection, etc.) +2. Your commit messages follow the conventional commits format +3. Tests are added for new functionality +4. Documentation is updated if needed + + Direct all PRs/MRs to the `main` branch. diff --git a/committed.toml b/committed.toml new file mode 100644 index 00000000..64f7f18a --- /dev/null +++ b/committed.toml @@ -0,0 +1,2 @@ +style = "conventional" +allowed_types = ["ci", "build", "fix", "feat", "chore", "docs", "style", "refactor", "perf", "test"] From a24278dc1b59b6d20b985e128b515257de1e5143 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 24 Jun 2025 23:12:09 +0100 Subject: [PATCH 2044/2291] docs: Update mirror badges --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e3eb807f..e71178dc 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,13 @@ It's a community continuation of the [conduwuit](https://github.com/girlbossceo/ -[![forgejo.ellis.link](https://img.shields.io/badge/Ellis%20Git-main+packages-green?style=flat&logo=forgejo&labelColor=fff)](https://forgejo.ellis.link/continuwuation/continuwuity) ![](https://forgejo.ellis.link/continuwuation/continuwuity/badges/stars.svg?style=flat) [![](https://forgejo.ellis.link/continuwuation/continuwuity/badges/issues/open.svg?style=flat)](https://forgejo.ellis.link/continuwuation/continuwuity/issues?state=open) [![](https://forgejo.ellis.link/continuwuation/continuwuity/badges/pulls/open.svg?style=flat)](https://forgejo.ellis.link/continuwuation/continuwuity/pulls?state=open) +[![forgejo.ellis.link](https://img.shields.io/badge/Ellis%20Git-main+packages-green?style=flat&logo=forgejo&labelColor=fff)](https://forgejo.ellis.link/continuwuation/continuwuity) [![Stars](https://forgejo.ellis.link/continuwuation/continuwuity/badges/stars.svg?style=flat)](https://forgejo.ellis.link/continuwuation/continuwuity/stars) [![Issues](https://forgejo.ellis.link/continuwuation/continuwuity/badges/issues/open.svg?style=flat)](https://forgejo.ellis.link/continuwuation/continuwuity/issues?state=open) [![Pull Requests](https://forgejo.ellis.link/continuwuation/continuwuity/badges/pulls/open.svg?style=flat)](https://forgejo.ellis.link/continuwuation/continuwuity/pulls?state=open) -[![GitHub](https://img.shields.io/badge/GitHub-mirror-blue?style=flat&logo=github&labelColor=fff&logoColor=24292f)](https://github.com/continuwuity/continuwuity) ![](https://img.shields.io/github/stars/continuwuity/continuwuity?style=flat) +[![GitHub](https://img.shields.io/badge/GitHub-mirror-blue?style=flat&logo=github&labelColor=fff&logoColor=24292f)](https://github.com/continuwuity/continuwuity) [![Stars](https://img.shields.io/github/stars/continuwuity/continuwuity?style=flat)](https://github.com/continuwuity/continuwuity/stargazers) -[![Codeberg](https://img.shields.io/badge/Codeberg-mirror-2185D0?style=flat&logo=codeberg&labelColor=fff)](https://codeberg.org/nexy7574/continuwuity) ![](https://codeberg.org/nexy7574/continuwuity/badges/stars.svg?style=flat) +[![GitLab](https://img.shields.io/badge/GitLab-mirror-blue?style=flat&logo=gitlab&labelColor=fff)](https://gitlab.com/continuwuity/continuwuity) [![Stars](https://img.shields.io/gitlab/stars/continuwuity/continuwuity?style=flat)](https://gitlab.com/continuwuity/continuwuity/-/starrers) + +[![Codeberg](https://img.shields.io/badge/Codeberg-mirror-2185D0?style=flat&logo=codeberg&labelColor=fff)](https://codeberg.org/continuwuity/continuwuity) [![Stars](https://codeberg.org/continuwuity/continuwuity/badges/stars.svg?style=flat)](https://codeberg.org/continuwuity/continuwuity/stars) ### Why does this exist? From 63962fc04098802abdf3334f147f25ada0f1d36c Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 24 Jun 2025 23:13:28 +0100 Subject: [PATCH 2045/2291] docs: Remove completed items from the README --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index e71178dc..506a62db 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,6 @@ There are currently no open registration Continuwuity instances available. We're working our way through all of the issues in the [Forgejo project](https://forgejo.ellis.link/continuwuation/continuwuity/issues). -- [Replacing old conduwuit links with working continuwuity links](https://forgejo.ellis.link/continuwuation/continuwuity/issues/742) -- [Getting CI and docs deployment working on the new Forgejo project](https://forgejo.ellis.link/continuwuation/continuwuity/issues/740) - [Packaging & availability in more places](https://forgejo.ellis.link/continuwuation/continuwuity/issues/747) - [Appservices bugs & features](https://forgejo.ellis.link/continuwuation/continuwuity/issues?q=&type=all&state=open&labels=178&milestone=0&assignee=0&poster=0) - [Improving compatibility and spec compliance](https://forgejo.ellis.link/continuwuation/continuwuity/issues?labels=119) From f1ca84fcaff3b5a2c6cc4f1889611f7003859a33 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Tue, 24 Jun 2025 23:16:48 +0100 Subject: [PATCH 2046/2291] fix: Correct project brand in admin & OTEL --- src/admin/admin.rs | 2 +- src/main/logging.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/admin/admin.rs b/src/admin/admin.rs index 0d636c72..50b9db7c 100644 --- a/src/admin/admin.rs +++ b/src/admin/admin.rs @@ -9,7 +9,7 @@ use crate::{ }; #[derive(Debug, Parser)] -#[command(name = "conduwuit", version = conduwuit::version())] +#[command(name = conduwuit_core::name(), version = conduwuit_core::version())] pub(super) enum AdminCommand { #[command(subcommand)] /// - Commands for managing appservices diff --git a/src/main/logging.rs b/src/main/logging.rs index eeeda127..aec50bd4 100644 --- a/src/main/logging.rs +++ b/src/main/logging.rs @@ -77,7 +77,7 @@ pub(crate) fn init( ); let tracer = opentelemetry_jaeger::new_agent_pipeline() .with_auto_split_batch(true) - .with_service_name("conduwuit") + .with_service_name(conduwuit_core::name()) .install_batch(opentelemetry_sdk::runtime::Tokio) .expect("jaeger agent pipeline"); let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); From db58d841aa4c99e1bc573faea3113557cc68589e Mon Sep 17 00:00:00 2001 From: Jacob Taylor Date: Fri, 25 Apr 2025 20:59:52 -0700 Subject: [PATCH 2047/2291] fix: Only load children of nested spaces --- src/api/client/space.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/api/client/space.rs b/src/api/client/space.rs index 92768926..23b1e80f 100644 --- a/src/api/client/space.rs +++ b/src/api/client/space.rs @@ -121,7 +121,9 @@ where .map(|(key, val)| (key, val.collect())) .collect(); - if !populate { + if populate { + rooms.push(summary_to_chunk(summary.clone())); + } else { children = children .iter() .rev() @@ -144,10 +146,8 @@ where .collect(); } - if populate { - rooms.push(summary_to_chunk(summary.clone())); - } else if queue.is_empty() && children.is_empty() { - return Err!(Request(InvalidParam("Room IDs in token were not found."))); + if !populate && queue.is_empty() && children.is_empty() { + break; } parents.insert(current_room.clone()); From c82ea24069d58b8e33d00b836ac7d5c126ffb217 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 27 Jun 2025 18:44:46 +0100 Subject: [PATCH 2048/2291] docs: Add Matrix chat and space badges to README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 506a62db..60dcf81d 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ ## A community-driven [Matrix](https://matrix.org/) homeserver in Rust +[![Chat on Matrix](https://img.shields.io/matrix/continuwuity%3Acontinuwuity.org?server_fqdn=matrix.continuwuity.org&fetchMode=summary&logo=matrix)](https://matrix.to/#/#continuwuity:continuwuity.org?via=continuwuity.org&via=ellis.link&via=explodie.org&via=matrix.org) [![Join the space](https://img.shields.io/matrix/space%3Acontinuwuity.org?server_fqdn=matrix.continuwuity.org&fetchMode=summary&logo=matrix&label=space)](https://matrix.to/#/#space:continuwuity.org?via=continuwuity.org&via=ellis.link&via=explodie.org&via=matrix.org) + + + [continuwuity] is a Matrix homeserver written in Rust. From 543ab27747dbf31b583175dd81d7d3aa3c82df79 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Fri, 27 Jun 2025 20:58:52 +0100 Subject: [PATCH 2049/2291] fix: Additional sanity checks when creating a PDU Prevents creating events that are most likely catastrophically invalid --- src/service/rooms/timeline/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index 4b2f3cb2..94d306d1 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -719,6 +719,18 @@ impl Service { ); } } + if event_type != TimelineEventType::RoomCreate && prev_events.is_empty() { + return Err!(Request(Unknown("Event incorrectly had zero prev_events."))); + } + if state_key.is_none() && depth.le(&uint!(2)) { + // The first two events in a room are always m.room.create and m.room.member, + // so any other events with that same depth are illegal. + warn!( + "Had unsafe depth {depth} when creating non-state event in {room_id}. Cowardly \ + aborting" + ); + return Err!(Request(Unknown("Unsafe depth for non-state event."))); + } let mut pdu = PduEvent { event_id: ruma::event_id!("$thiswillbefilledinlater").into(), From f508e7654c51070e2231b136506c326305f37d3c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 28 Jun 2025 00:29:07 +0000 Subject: [PATCH 2050/2291] fix: off by one. --- src/service/rooms/timeline/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index 94d306d1..37963246 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -722,7 +722,7 @@ impl Service { if event_type != TimelineEventType::RoomCreate && prev_events.is_empty() { return Err!(Request(Unknown("Event incorrectly had zero prev_events."))); } - if state_key.is_none() && depth.le(&uint!(2)) { + if state_key.is_none() && depth.lt(&uint!(2)) { // The first two events in a room are always m.room.create and m.room.member, // so any other events with that same depth are illegal. warn!( From 52e042cb06e05a028340e93bf3ff0d2d37d211b5 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Mon, 26 May 2025 01:22:19 +0100 Subject: [PATCH 2051/2291] Always calculate state diff IDs in syncv3 seemingly fixes #779 --- src/api/client/sync/v3.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/api/client/sync/v3.rs b/src/api/client/sync/v3.rs index 8eac6b66..7bc74c95 100644 --- a/src/api/client/sync/v3.rs +++ b/src/api/client/sync/v3.rs @@ -1009,8 +1009,6 @@ async fn calculate_state_incremental<'a>( ) -> Result { let since_shortstatehash = since_shortstatehash.unwrap_or(current_shortstatehash); - let state_changed = since_shortstatehash != current_shortstatehash; - let encrypted_room = services .rooms .state_accessor @@ -1042,7 +1040,7 @@ async fn calculate_state_incremental<'a>( }) .into(); - let state_diff_ids: OptionFuture<_> = (!full_state && state_changed) + let state_diff_ids: OptionFuture<_> = (!full_state) .then(|| { StreamExt::into_future( services From 9b6ac6c45f44a18d68208038b360212205830a7f Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 19:57:02 +0100 Subject: [PATCH 2052/2291] fix: Ignore existing membership when room is disconnected --- src/api/client/membership.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs index e587d806..1800fa60 100644 --- a/src/api/client/membership.rs +++ b/src/api/client/membership.rs @@ -925,24 +925,32 @@ pub async fn join_room_by_id_helper( return Ok(join_room_by_id::v3::Response { room_id: room_id.into() }); } - if let Ok(membership) = services - .rooms - .state_accessor - .get_member(room_id, sender_user) - .await - { - if membership.membership == MembershipState::Ban { - debug_warn!("{sender_user} is banned from {room_id} but attempted to join"); - return Err!(Request(Forbidden("You are banned from the room."))); - } - } - let server_in_room = services .rooms .state_cache .server_in_room(services.globals.server_name(), room_id) .await; + // Only check our known membership if we're already in the room. + // See: https://forgejo.ellis.link/continuwuation/continuwuity/issues/855 + let membership = if server_in_room { + services + .rooms + .state_accessor + .get_member(room_id, sender_user) + .await + } else { + debug!("Ignoring local state for join {room_id}, we aren't in the room yet."); + Ok(RoomMemberEventContent::new(MembershipState::Leave)) + }; + if let Ok(m) = membership { + if m.membership == MembershipState::Ban { + debug_warn!("{sender_user} is banned from {room_id} but attempted to join"); + // TODO: return reason + return Err!(Request(Forbidden("You are banned from the room."))); + } + } + let local_join = server_in_room || servers.is_empty() || (servers.len() == 1 && services.globals.server_is_ours(&servers[0])); From d63c8b9fcaccb93981b0afcccb6c1c6d823d0f73 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 29 Jun 2025 13:16:31 +0100 Subject: [PATCH 2053/2291] feat: Support passing through MSC4293 redact_events --- Cargo.lock | 22 +++++++++++----------- Cargo.toml | 2 +- src/api/client/membership.rs | 1 + 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7852d2ca..ab5702e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3798,7 +3798,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.10.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" dependencies = [ "assign", "js_int", @@ -3818,7 +3818,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" dependencies = [ "js_int", "ruma-common", @@ -3830,7 +3830,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" dependencies = [ "as_variant", "assign", @@ -3853,7 +3853,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" dependencies = [ "as_variant", "base64 0.22.1", @@ -3885,7 +3885,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" dependencies = [ "as_variant", "indexmap 2.9.0", @@ -3910,7 +3910,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" dependencies = [ "bytes", "headers", @@ -3932,7 +3932,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" dependencies = [ "js_int", "thiserror 2.0.12", @@ -3941,7 +3941,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" dependencies = [ "js_int", "ruma-common", @@ -3951,7 +3951,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" dependencies = [ "cfg-if", "proc-macro-crate", @@ -3966,7 +3966,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" dependencies = [ "js_int", "ruma-common", @@ -3978,7 +3978,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" dependencies = [ "base64 0.22.1", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index f3de5d7f..d54b86a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -350,7 +350,7 @@ version = "0.1.2" [workspace.dependencies.ruma] git = "https://forgejo.ellis.link/continuwuation/ruwuma" #branch = "conduwuit-changes" -rev = "d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +rev = "0012040617213eccb682b65d0ac76c0e5cc94d8c" features = [ "compat", "rand", diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs index 1800fa60..b05e2003 100644 --- a/src/api/client/membership.rs +++ b/src/api/client/membership.rs @@ -646,6 +646,7 @@ pub(crate) async fn ban_user_route( is_direct: None, join_authorized_via_users_server: None, third_party_invite: None, + redact_events: body.redact_events, ..current_member_content }), sender_user, From 4b5e8df95c60435fd3e6bce016229108c0494911 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 29 Jun 2025 13:29:27 +0100 Subject: [PATCH 2054/2291] fix: Add missing init fields --- src/api/client/membership.rs | 1 + src/api/client/profile.rs | 2 ++ src/api/client/room/upgrade.rs | 1 + 3 files changed, 4 insertions(+) diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs index b05e2003..145b3cde 100644 --- a/src/api/client/membership.rs +++ b/src/api/client/membership.rs @@ -1824,6 +1824,7 @@ pub async fn leave_room( displayname: None, third_party_invite: None, blurhash: None, + redact_events: None, }; let is_banned = services.rooms.metadata.is_banned(room_id); diff --git a/src/api/client/profile.rs b/src/api/client/profile.rs index 3699b590..e2d1c934 100644 --- a/src/api/client/profile.rs +++ b/src/api/client/profile.rs @@ -343,6 +343,7 @@ pub async fn update_displayname( reason: None, is_direct: None, third_party_invite: None, + redact_events: None, }); Ok((pdu, room_id)) @@ -396,6 +397,7 @@ pub async fn update_avatar_url( reason: None, is_direct: None, third_party_invite: None, + redact_events: None, }); Ok((pdu, room_id)) diff --git a/src/api/client/room/upgrade.rs b/src/api/client/room/upgrade.rs index 9ec0b3bb..da5b49fe 100644 --- a/src/api/client/room/upgrade.rs +++ b/src/api/client/room/upgrade.rs @@ -189,6 +189,7 @@ pub(crate) async fn upgrade_room_route( blurhash: services.users.blurhash(sender_user).await.ok(), reason: None, join_authorized_via_users_server: None, + redact_events: None, }) .expect("event is valid, we just created it"), unsigned: None, From b4bdd1ee65dc1c0aa4ff974c13a0237542552fc2 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 29 Jun 2025 13:43:27 +0100 Subject: [PATCH 2055/2291] chore: Update ruwuma Fixes the wrong field name being serialised --- Cargo.lock | 22 +++++++++++----------- Cargo.toml | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab5702e8..92044b92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3798,7 +3798,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.10.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" dependencies = [ "assign", "js_int", @@ -3818,7 +3818,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" dependencies = [ "js_int", "ruma-common", @@ -3830,7 +3830,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" dependencies = [ "as_variant", "assign", @@ -3853,7 +3853,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" dependencies = [ "as_variant", "base64 0.22.1", @@ -3885,7 +3885,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" dependencies = [ "as_variant", "indexmap 2.9.0", @@ -3910,7 +3910,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" dependencies = [ "bytes", "headers", @@ -3932,7 +3932,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" dependencies = [ "js_int", "thiserror 2.0.12", @@ -3941,7 +3941,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" dependencies = [ "js_int", "ruma-common", @@ -3951,7 +3951,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" dependencies = [ "cfg-if", "proc-macro-crate", @@ -3966,7 +3966,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" dependencies = [ "js_int", "ruma-common", @@ -3978,7 +3978,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=0012040617213eccb682b65d0ac76c0e5cc94d8c#0012040617213eccb682b65d0ac76c0e5cc94d8c" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" dependencies = [ "base64 0.22.1", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index d54b86a4..5c289adf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -350,7 +350,7 @@ version = "0.1.2" [workspace.dependencies.ruma] git = "https://forgejo.ellis.link/continuwuation/ruwuma" #branch = "conduwuit-changes" -rev = "0012040617213eccb682b65d0ac76c0e5cc94d8c" +rev = "9b65f83981f6f53d185ce77da37aaef9dfd764a9" features = [ "compat", "rand", From fac9e090cdebbd21c3b282ed04c61d0b8c86ebdd Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 20:32:02 +0100 Subject: [PATCH 2056/2291] feat: Add suspension helper to user service --- src/service/users/mod.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index 701561a8..1a9f6600 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -15,6 +15,7 @@ use ruma::{ AnyToDeviceEvent, GlobalAccountDataEventType, ignored_user_list::IgnoredUserListEvent, }, serde::Raw, + uint, }; use serde_json::json; @@ -52,6 +53,7 @@ struct Data { userid_lastonetimekeyupdate: Arc, userid_masterkeyid: Arc, userid_password: Arc, + userid_suspended: Arc, userid_selfsigningkeyid: Arc, userid_usersigningkeyid: Arc, useridprofilekey_value: Arc, @@ -87,6 +89,7 @@ impl crate::Service for Service { userid_lastonetimekeyupdate: args.db["userid_lastonetimekeyupdate"].clone(), userid_masterkeyid: args.db["userid_masterkeyid"].clone(), userid_password: args.db["userid_password"].clone(), + userid_suspended: args.db["userid_suspended"].clone(), userid_selfsigningkeyid: args.db["userid_selfsigningkeyid"].clone(), userid_usersigningkeyid: args.db["userid_usersigningkeyid"].clone(), useridprofilekey_value: args.db["useridprofilekey_value"].clone(), @@ -143,6 +146,16 @@ impl Service { Ok(()) } + /// Suspend account, placing it in a read-only state + pub async fn suspend_account(&self, user_id: &UserId) -> () { + self.db.userid_suspended.insert(user_id, "1"); + } + + /// Unsuspend account, placing it in a read-write state + pub async fn unsuspend_account(&self, user_id: &UserId) -> () { + self.db.userid_suspended.remove(user_id); + } + /// Check if a user has an account on this homeserver. #[inline] pub async fn exists(&self, user_id: &UserId) -> bool { @@ -159,6 +172,16 @@ impl Service { .await } + /// Check if account is suspended + pub async fn is_suspended(&self, user_id: &UserId) -> Result { + self.db + .userid_suspended + .get(user_id) + .map_ok(|val| val.is_empty()) + .map_err(|_| err!(Request(NotFound("User does not exist.")))) + .await + } + /// Check if account is active, infallible pub async fn is_active(&self, user_id: &UserId) -> bool { !self.is_deactivated(user_id).await.unwrap_or(true) From accfda258638d7eef9b2c35c15e2b1658a478743 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 20:35:58 +0100 Subject: [PATCH 2057/2291] feat: Prevent suspended users sending events --- src/api/client/send.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/api/client/send.rs b/src/api/client/send.rs index f753fa65..b87d1822 100644 --- a/src/api/client/send.rs +++ b/src/api/client/send.rs @@ -23,6 +23,9 @@ pub(crate) async fn send_message_event_route( let sender_user = body.sender_user(); let sender_device = body.sender_device.as_deref(); let appservice_info = body.appservice_info.as_ref(); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } // Forbid m.room.encrypted if encryption is disabled if MessageLikeEventType::RoomEncrypted == body.event_type && !services.config.allow_encryption From 286974cb9a676bb58501835fbdf1fce08b3d9c6c Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 20:37:09 +0100 Subject: [PATCH 2058/2291] feat: Prevent suspended users redacting events --- src/api/client/redact.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/client/redact.rs b/src/api/client/redact.rs index 8dbe47a6..a8eaf91d 100644 --- a/src/api/client/redact.rs +++ b/src/api/client/redact.rs @@ -1,5 +1,5 @@ use axum::extract::State; -use conduwuit::{Result, matrix::pdu::PduBuilder}; +use conduwuit::{Err, Result, matrix::pdu::PduBuilder}; use ruma::{ api::client::redact::redact_event, events::room::redaction::RoomRedactionEventContent, }; @@ -17,6 +17,10 @@ pub(crate) async fn redact_event_route( ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let body = body.body; + if services.users.is_suspended(sender_user).await? { + // TODO: Users can redact their own messages while suspended + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } let state_lock = services.rooms.state.mutex.lock(&body.room_id).await; From a6ba9e3045e7cdaccbae006d0037b045c1348016 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 20:39:24 +0100 Subject: [PATCH 2059/2291] feat: Prevent suspended users changing their profile --- src/api/client/profile.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/api/client/profile.rs b/src/api/client/profile.rs index e2d1c934..bdba4078 100644 --- a/src/api/client/profile.rs +++ b/src/api/client/profile.rs @@ -36,6 +36,9 @@ pub(crate) async fn set_displayname_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } if *sender_user != body.user_id && body.appservice_info.is_none() { return Err!(Request(Forbidden("You cannot update the profile of another user"))); @@ -125,6 +128,9 @@ pub(crate) async fn set_avatar_url_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } if *sender_user != body.user_id && body.appservice_info.is_none() { return Err!(Request(Forbidden("You cannot update the profile of another user"))); From a94128e6986f7f05909329de694e547543b4dc36 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 20:39:57 +0100 Subject: [PATCH 2060/2291] feat: Prevent suspended users joining/knocking on rooms --- src/api/client/membership.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs index 145b3cde..d78ebdec 100644 --- a/src/api/client/membership.rs +++ b/src/api/client/membership.rs @@ -178,6 +178,9 @@ pub(crate) async fn join_room_by_id_route( body: Ruma, ) -> Result { let sender_user = body.sender_user(); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } banned_room_check( &services, @@ -249,6 +252,9 @@ pub(crate) async fn join_room_by_id_or_alias_route( let sender_user = body.sender_user.as_deref().expect("user is authenticated"); let appservice_info = &body.appservice_info; let body = body.body; + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } let (servers, room_id) = match OwnedRoomId::try_from(body.room_id_or_alias) { | Ok(room_id) => { @@ -369,6 +375,9 @@ pub(crate) async fn knock_room_route( ) -> Result { let sender_user = body.sender_user(); let body = &body.body; + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } let (servers, room_id) = match OwnedRoomId::try_from(body.room_id_or_alias.clone()) { | Ok(room_id) => { @@ -492,6 +501,9 @@ pub(crate) async fn invite_user_route( body: Ruma, ) -> Result { let sender_user = body.sender_user(); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } if !services.users.is_admin(sender_user).await && services.config.block_non_admin_invites { debug_error!( From e127c4e5a2e08498c61df30b8424a01f30671bca Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 20:46:22 +0100 Subject: [PATCH 2061/2291] feat: Add un/suspend admin commands --- src/admin/user/commands.rs | 34 ++++++++++++++++++++++++++++++++++ src/admin/user/mod.rs | 22 ++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index e5e481e5..297e4bb3 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -224,6 +224,40 @@ pub(super) async fn deactivate(&self, no_leave_rooms: bool, user_id: String) -> .await } +#[admin_command] +pub(super) async fn suspend(&self, user_id: String) -> Result { + let user_id = parse_local_user_id(self.services, &user_id)?; + + if user_id == self.services.globals.server_user { + return Err!("Not allowed to suspend the server service account.",); + } + + if !self.services.users.exists(&user_id).await { + return Err!("User {user_id} does not exist."); + } + self.services.users.suspend_account(&user_id).await; + + self.write_str(&format!("User {user_id} has been suspended.")) + .await +} + +#[admin_command] +pub(super) async fn unsuspend(&self, user_id: String) -> Result { + let user_id = parse_local_user_id(self.services, &user_id)?; + + if user_id == self.services.globals.server_user { + return Err!("Not allowed to unsuspend the server service account.",); + } + + if !self.services.users.exists(&user_id).await { + return Err!("User {user_id} does not exist."); + } + self.services.users.unsuspend_account(&user_id).await; + + self.write_str(&format!("User {user_id} has been unsuspended.")) + .await +} + #[admin_command] pub(super) async fn reset_password(&self, username: String, password: Option) -> Result { let user_id = parse_local_user_id(self.services, &username)?; diff --git a/src/admin/user/mod.rs b/src/admin/user/mod.rs index e789376a..645d3637 100644 --- a/src/admin/user/mod.rs +++ b/src/admin/user/mod.rs @@ -59,6 +59,28 @@ pub(super) enum UserCommand { force: bool, }, + /// - Suspend a user + /// + /// Suspended users are able to log in, sync, and read messages, but are not + /// able to send events nor redact them, cannot change their profile, and + /// are unable to join, invite to, or knock on rooms. + /// + /// Suspended users can still leave rooms and deactivate their account. + /// Suspending them effectively makes them read-only. + Suspend { + /// Username of the user to suspend + user_id: String, + }, + + /// - Unsuspend a user + /// + /// Reverses the effects of the `suspend` command, allowing the user to send + /// messages, change their profile, create room invites, etc. + Unsuspend { + /// Username of the user to unsuspend + user_id: String, + }, + /// - List local users in the database #[clap(alias = "list")] ListUsers, From 5d5350a9fee3b4959ef66b0d18a588d2f2be7dde Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 20:47:02 +0100 Subject: [PATCH 2062/2291] feat: Prevent suspended users creating new rooms --- src/api/client/room/create.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/api/client/room/create.rs b/src/api/client/room/create.rs index be3fd23b..d1dffc51 100644 --- a/src/api/client/room/create.rs +++ b/src/api/client/room/create.rs @@ -70,6 +70,10 @@ pub(crate) async fn create_room_route( )); } + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } + let room_id: OwnedRoomId = match &body.room_id { | Some(custom_room_id) => custom_room_id_check(&services, custom_room_id)?, | _ => RoomId::new(&services.server.name), From 968c0e236c37d204d9718689dd79888cf32f54e5 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 21:19:10 +0100 Subject: [PATCH 2063/2291] fix: Create the column appropriately --- src/database/maps.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/database/maps.rs b/src/database/maps.rs index 19f9ced4..91ba2ebe 100644 --- a/src/database/maps.rs +++ b/src/database/maps.rs @@ -378,6 +378,10 @@ pub(super) static MAPS: &[Descriptor] = &[ name: "userid_password", ..descriptor::RANDOM }, + Descriptor { + name: "userid_suspended", + ..descriptor::RANDOM_SMALL + }, Descriptor { name: "userid_presenceid", ..descriptor::RANDOM_SMALL From 8791a9b851f8fc3cd827fe898406561fc4104287 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 21:19:37 +0100 Subject: [PATCH 2064/2291] fix: Inappropriate empty check I once again, assumed `true` is actually `false`. --- src/service/users/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index 1a9f6600..6d3b662f 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -177,7 +177,7 @@ impl Service { self.db .userid_suspended .get(user_id) - .map_ok(|val| val.is_empty()) + .map_ok(|val| !val.is_empty()) .map_err(|_| err!(Request(NotFound("User does not exist.")))) .await } From cc864dc8bbb299b7a48c6fb963a61b6979ceb278 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 21:20:56 +0100 Subject: [PATCH 2065/2291] feat: Do not allow suspending admin users --- src/admin/user/commands.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 297e4bb3..61f10a86 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -235,6 +235,9 @@ pub(super) async fn suspend(&self, user_id: String) -> Result { if !self.services.users.exists(&user_id).await { return Err!("User {user_id} does not exist."); } + if self.services.users.is_admin(&user_id).await { + return Err!("Admin users cannot be suspended."); + } self.services.users.suspend_account(&user_id).await; self.write_str(&format!("User {user_id} has been suspended.")) From 1ff8af8e9e6ef723287dd9b174dc69844bf8631c Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 21:24:20 +0100 Subject: [PATCH 2066/2291] style: Remove unneeded statements (clippy) --- src/service/users/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index 6d3b662f..f6a98858 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -15,7 +15,6 @@ use ruma::{ AnyToDeviceEvent, GlobalAccountDataEventType, ignored_user_list::IgnoredUserListEvent, }, serde::Raw, - uint, }; use serde_json::json; @@ -147,12 +146,12 @@ impl Service { } /// Suspend account, placing it in a read-only state - pub async fn suspend_account(&self, user_id: &UserId) -> () { + pub async fn suspend_account(&self, user_id: &UserId) { self.db.userid_suspended.insert(user_id, "1"); } /// Unsuspend account, placing it in a read-write state - pub async fn unsuspend_account(&self, user_id: &UserId) -> () { + pub async fn unsuspend_account(&self, user_id: &UserId) { self.db.userid_suspended.remove(user_id); } From d0548ec0644ebb0e3538f65088db9b16ce0eb5a8 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 21:30:07 +0100 Subject: [PATCH 2067/2291] feat: Forbid suspended users from sending state events --- src/api/client/state.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/api/client/state.rs b/src/api/client/state.rs index 2ddc8f14..07802b1b 100644 --- a/src/api/client/state.rs +++ b/src/api/client/state.rs @@ -33,6 +33,10 @@ pub(crate) async fn send_state_event_for_key_route( ) -> Result { let sender_user = body.sender_user(); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } + Ok(send_state_event::v3::Response { event_id: send_state_event_for_key_helper( &services, From 90180916eb13cdcf4e81c668fa6255222c781f1d Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 22:42:31 +0100 Subject: [PATCH 2068/2291] feat: Prevent suspended users performing room changes Prevents kicks, bans, unbans, and alias modification --- src/api/client/alias.rs | 6 ++++++ src/api/client/directory.rs | 3 +++ src/api/client/membership.rs | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/api/client/alias.rs b/src/api/client/alias.rs index 9f1b05f8..dc7aad44 100644 --- a/src/api/client/alias.rs +++ b/src/api/client/alias.rs @@ -18,6 +18,9 @@ pub(crate) async fn create_alias_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } services .rooms @@ -63,6 +66,9 @@ pub(crate) async fn delete_alias_route( body: Ruma, ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } services .rooms diff --git a/src/api/client/directory.rs b/src/api/client/directory.rs index aa6ae168..2e219fd9 100644 --- a/src/api/client/directory.rs +++ b/src/api/client/directory.rs @@ -128,6 +128,9 @@ pub(crate) async fn set_room_visibility_route( // Return 404 if the room doesn't exist return Err!(Request(NotFound("Room not found"))); } + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } if services .users diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs index d78ebdec..e6392533 100644 --- a/src/api/client/membership.rs +++ b/src/api/client/membership.rs @@ -578,6 +578,10 @@ pub(crate) async fn kick_user_route( State(services): State, body: Ruma, ) -> Result { + let sender_user = body.sender_user(); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } let state_lock = services.rooms.state.mutex.lock(&body.room_id).await; let Ok(event) = services @@ -613,7 +617,7 @@ pub(crate) async fn kick_user_route( third_party_invite: None, ..event }), - body.sender_user(), + sender_user, &body.room_id, &state_lock, ) @@ -637,6 +641,10 @@ pub(crate) async fn ban_user_route( return Err!(Request(Forbidden("You cannot ban yourself."))); } + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } + let state_lock = services.rooms.state.mutex.lock(&body.room_id).await; let current_member_content = services @@ -679,6 +687,10 @@ pub(crate) async fn unban_user_route( State(services): State, body: Ruma, ) -> Result { + let sender_user = body.sender_user(); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } let state_lock = services.rooms.state.mutex.lock(&body.room_id).await; let current_member_content = services @@ -707,7 +719,7 @@ pub(crate) async fn unban_user_route( is_direct: None, ..current_member_content }), - body.sender_user(), + sender_user, &body.room_id, &state_lock, ) From 8e06571e7c7e88c14580c7e6206aecdb12a5eb44 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 22:42:49 +0100 Subject: [PATCH 2069/2291] feat: Prevent suspended users uploading media --- src/api/client/media.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/api/client/media.rs b/src/api/client/media.rs index 94572413..11d5450c 100644 --- a/src/api/client/media.rs +++ b/src/api/client/media.rs @@ -52,6 +52,9 @@ pub(crate) async fn create_content_route( body: Ruma, ) -> Result { let user = body.sender_user.as_ref().expect("user is authenticated"); + if services.users.is_suspended(user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } let filename = body.filename.as_deref(); let content_type = body.content_type.as_deref(); From 08527a28804f673817793af86ea94086fcba3a5c Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 22:43:35 +0100 Subject: [PATCH 2070/2291] feat: Prevent suspended users upgrading rooms --- src/api/client/room/upgrade.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/client/room/upgrade.rs b/src/api/client/room/upgrade.rs index da5b49fe..d8f5ea83 100644 --- a/src/api/client/room/upgrade.rs +++ b/src/api/client/room/upgrade.rs @@ -2,7 +2,7 @@ use std::cmp::max; use axum::extract::State; use conduwuit::{ - Error, Result, err, info, + Err, Error, Result, err, info, matrix::{StateKey, pdu::PduBuilder}, }; use futures::StreamExt; @@ -63,6 +63,10 @@ pub(crate) async fn upgrade_room_route( )); } + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } + // Create a replacement room let replacement_room = RoomId::new(services.globals.server_name()); From 1124097bd17eea3d10b35b9f05539321050b248a Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 22:52:20 +0100 Subject: [PATCH 2071/2291] feat: Only allow private read receipts when suspended --- src/api/client/read_marker.rs | 49 +++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/api/client/read_marker.rs b/src/api/client/read_marker.rs index fbfc8fea..e152869c 100644 --- a/src/api/client/read_marker.rs +++ b/src/api/client/read_marker.rs @@ -58,29 +58,34 @@ pub(crate) async fn set_read_marker_route( } if let Some(event) = &body.read_receipt { - let receipt_content = BTreeMap::from_iter([( - event.to_owned(), - BTreeMap::from_iter([( - ReceiptType::Read, - BTreeMap::from_iter([(sender_user.to_owned(), ruma::events::receipt::Receipt { - ts: Some(MilliSecondsSinceUnixEpoch::now()), - thread: ReceiptThread::Unthreaded, - })]), - )]), - )]); + if !services.users.is_suspended(sender_user).await? { + let receipt_content = BTreeMap::from_iter([( + event.to_owned(), + BTreeMap::from_iter([( + ReceiptType::Read, + BTreeMap::from_iter([( + sender_user.to_owned(), + ruma::events::receipt::Receipt { + ts: Some(MilliSecondsSinceUnixEpoch::now()), + thread: ReceiptThread::Unthreaded, + }, + )]), + )]), + )]); - services - .rooms - .read_receipt - .readreceipt_update( - sender_user, - &body.room_id, - &ruma::events::receipt::ReceiptEvent { - content: ruma::events::receipt::ReceiptEventContent(receipt_content), - room_id: body.room_id.clone(), - }, - ) - .await; + services + .rooms + .read_receipt + .readreceipt_update( + sender_user, + &body.room_id, + &ruma::events::receipt::ReceiptEvent { + content: ruma::events::receipt::ReceiptEventContent(receipt_content), + room_id: body.room_id.clone(), + }, + ) + .await; + } } if let Some(event) = &body.private_read_receipt { From 72f8cb30384a32b1489b676fcfc76fc59f323c42 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Jun 2025 22:53:25 +0100 Subject: [PATCH 2072/2291] feat: Do not allow suspended users to send typing statuses --- src/api/client/typing.rs | 67 ++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/api/client/typing.rs b/src/api/client/typing.rs index 1d8d02fd..7b0df538 100644 --- a/src/api/client/typing.rs +++ b/src/api/client/typing.rs @@ -26,41 +26,42 @@ pub(crate) async fn create_typing_event_route( { return Err!(Request(Forbidden("You are not in this room."))); } - - match body.state { - | Typing::Yes(duration) => { - let duration = utils::clamp( - duration.as_millis().try_into().unwrap_or(u64::MAX), + if !services.users.is_suspended(sender_user).await? { + match body.state { + | Typing::Yes(duration) => { + let duration = utils::clamp( + duration.as_millis().try_into().unwrap_or(u64::MAX), + services + .server + .config + .typing_client_timeout_min_s + .try_mul(1000)?, + services + .server + .config + .typing_client_timeout_max_s + .try_mul(1000)?, + ); services - .server - .config - .typing_client_timeout_min_s - .try_mul(1000)?, + .rooms + .typing + .typing_add( + sender_user, + &body.room_id, + utils::millis_since_unix_epoch() + .checked_add(duration) + .expect("user typing timeout should not get this high"), + ) + .await?; + }, + | _ => { services - .server - .config - .typing_client_timeout_max_s - .try_mul(1000)?, - ); - services - .rooms - .typing - .typing_add( - sender_user, - &body.room_id, - utils::millis_since_unix_epoch() - .checked_add(duration) - .expect("user typing timeout should not get this high"), - ) - .await?; - }, - | _ => { - services - .rooms - .typing - .typing_remove(sender_user, &body.room_id) - .await?; - }, + .rooms + .typing + .typing_remove(sender_user, &body.room_id) + .await?; + }, + } } // ping presence From eb2e3b3bb70af18ad0821d046fe51926977b5d0a Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 29 Jun 2025 01:52:02 +0100 Subject: [PATCH 2073/2291] fix: Missing suspensions shouldn't error Turns out copying and pasting the function above verbatim actually introduces more problems than it solves! --- src/service/users/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index f6a98858..d80a7e22 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, mem, sync::Arc}; use conduwuit::{ Err, Error, Result, Server, at, debug_warn, err, trace, - utils::{self, ReadyExt, stream::TryIgnore, string::Unquoted}, + utils::{self, ReadyExt, TryFutureExtExt, stream::TryIgnore, string::Unquoted}, }; use database::{Deserialized, Ignore, Interfix, Json, Map}; use futures::{Stream, StreamExt, TryFutureExt}; @@ -176,8 +176,7 @@ impl Service { self.db .userid_suspended .get(user_id) - .map_ok(|val| !val.is_empty()) - .map_err(|_| err!(Request(NotFound("User does not exist.")))) + .map_ok_or(Ok(false), |_| Ok(true)) .await } From d8a27eeb54b79a1126dd08c48f8f20d9cc0c0104 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 29 Jun 2025 02:28:04 +0100 Subject: [PATCH 2074/2291] fix: Failing open on database errors oops --- src/service/users/mod.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index d80a7e22..5db7dc1d 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -1,11 +1,11 @@ use std::{collections::BTreeMap, mem, sync::Arc}; use conduwuit::{ - Err, Error, Result, Server, at, debug_warn, err, trace, + Err, Error, Result, Server, at, debug_warn, err, result, trace, utils::{self, ReadyExt, TryFutureExtExt, stream::TryIgnore, string::Unquoted}, }; use database::{Deserialized, Ignore, Interfix, Json, Map}; -use futures::{Stream, StreamExt, TryFutureExt}; +use futures::{Stream, StreamExt, TryFutureExt, TryStreamExt}; use ruma::{ DeviceId, KeyId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OneTimeKeyId, OneTimeKeyName, OwnedDeviceId, OwnedKeyId, OwnedMxcUri, OwnedUserId, RoomId, UInt, UserId, @@ -176,7 +176,19 @@ impl Service { self.db .userid_suspended .get(user_id) - .map_ok_or(Ok(false), |_| Ok(true)) + .map_ok_or_else( + |err| { + if err.is_not_found() { + Ok(false) + } else { + err!(Database(error!( + "Failed to check if user {user_id} is suspended: {err}" + ))); + Ok(true) + } + }, + |_| Ok(true), + ) .await } From 13e17d52e02f33847bed089d4451d248694be854 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 29 Jun 2025 02:30:52 +0100 Subject: [PATCH 2075/2291] style: Remove unnecessary imports (clippy) --- src/service/users/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index 5db7dc1d..b2a42959 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -1,11 +1,11 @@ use std::{collections::BTreeMap, mem, sync::Arc}; use conduwuit::{ - Err, Error, Result, Server, at, debug_warn, err, result, trace, - utils::{self, ReadyExt, TryFutureExtExt, stream::TryIgnore, string::Unquoted}, + Err, Error, Result, Server, at, debug_warn, err, trace, + utils::{self, ReadyExt, stream::TryIgnore, string::Unquoted}, }; use database::{Deserialized, Ignore, Interfix, Json, Map}; -use futures::{Stream, StreamExt, TryFutureExt, TryStreamExt}; +use futures::{Stream, StreamExt, TryFutureExt}; use ruma::{ DeviceId, KeyId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OneTimeKeyId, OneTimeKeyName, OwnedDeviceId, OwnedKeyId, OwnedMxcUri, OwnedUserId, RoomId, UInt, UserId, From ecc6fda98b135e9e5fdb9cd93124baac7a4fc001 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 29 Jun 2025 15:07:04 +0100 Subject: [PATCH 2076/2291] feat: Record metadata about user suspensions --- src/admin/user/commands.rs | 6 +++- src/database/maps.rs | 2 +- src/service/users/mod.rs | 56 ++++++++++++++++++++++++-------------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 61f10a86..ad2d1c78 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -238,7 +238,11 @@ pub(super) async fn suspend(&self, user_id: String) -> Result { if self.services.users.is_admin(&user_id).await { return Err!("Admin users cannot be suspended."); } - self.services.users.suspend_account(&user_id).await; + // TODO: Record the actual user that sent the suspension where possible + self.services + .users + .suspend_account(&user_id, self.services.globals.server_user.as_ref()) + .await; self.write_str(&format!("User {user_id} has been suspended.")) .await diff --git a/src/database/maps.rs b/src/database/maps.rs index 91ba2ebe..214dbf34 100644 --- a/src/database/maps.rs +++ b/src/database/maps.rs @@ -379,7 +379,7 @@ pub(super) static MAPS: &[Descriptor] = &[ ..descriptor::RANDOM }, Descriptor { - name: "userid_suspended", + name: "userid_suspension", ..descriptor::RANDOM_SMALL }, Descriptor { diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index b2a42959..d2dfccd9 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -16,10 +16,21 @@ use ruma::{ }, serde::Raw, }; +use serde::{Deserialize, Serialize}; use serde_json::json; use crate::{Dep, account_data, admin, globals, rooms}; +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct UserSuspension { + /// Whether the user is currently suspended + pub suspended: bool, + /// When the user was suspended (Unix timestamp in milliseconds) + pub suspended_at: u64, + /// User ID of who suspended this user + pub suspended_by: String, +} + pub struct Service { services: Services, db: Data, @@ -52,7 +63,7 @@ struct Data { userid_lastonetimekeyupdate: Arc, userid_masterkeyid: Arc, userid_password: Arc, - userid_suspended: Arc, + userid_suspension: Arc, userid_selfsigningkeyid: Arc, userid_usersigningkeyid: Arc, useridprofilekey_value: Arc, @@ -88,7 +99,7 @@ impl crate::Service for Service { userid_lastonetimekeyupdate: args.db["userid_lastonetimekeyupdate"].clone(), userid_masterkeyid: args.db["userid_masterkeyid"].clone(), userid_password: args.db["userid_password"].clone(), - userid_suspended: args.db["userid_suspended"].clone(), + userid_suspension: args.db["userid_suspension"].clone(), userid_selfsigningkeyid: args.db["userid_selfsigningkeyid"].clone(), userid_usersigningkeyid: args.db["userid_usersigningkeyid"].clone(), useridprofilekey_value: args.db["useridprofilekey_value"].clone(), @@ -146,13 +157,20 @@ impl Service { } /// Suspend account, placing it in a read-only state - pub async fn suspend_account(&self, user_id: &UserId) { - self.db.userid_suspended.insert(user_id, "1"); + pub async fn suspend_account(&self, user_id: &UserId, suspending_user: &UserId) { + self.db.userid_suspension.raw_put( + user_id, + Json(UserSuspension { + suspended: true, + suspended_at: MilliSecondsSinceUnixEpoch::now().get().into(), + suspended_by: suspending_user.to_string(), + }), + ); } /// Unsuspend account, placing it in a read-write state pub async fn unsuspend_account(&self, user_id: &UserId) { - self.db.userid_suspended.remove(user_id); + self.db.userid_suspension.remove(user_id); } /// Check if a user has an account on this homeserver. @@ -173,23 +191,21 @@ impl Service { /// Check if account is suspended pub async fn is_suspended(&self, user_id: &UserId) -> Result { - self.db - .userid_suspended + match self + .db + .userid_suspension .get(user_id) - .map_ok_or_else( - |err| { - if err.is_not_found() { - Ok(false) - } else { - err!(Database(error!( - "Failed to check if user {user_id} is suspended: {err}" - ))); - Ok(true) - } - }, - |_| Ok(true), - ) .await + .deserialized::() + { + | Ok(s) => Ok(s.suspended), + | Err(e) => + if e.is_not_found() { + Ok(false) + } else { + Err(e) + }, + } } /// Check if account is active, infallible From acb74faa070801c4ee48cc76f6d3dd19174876b9 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 29 Jun 2025 15:17:27 +0100 Subject: [PATCH 2077/2291] feat: Pass sender through admin commands --- src/admin/context.rs | 15 ++++++++++++++- src/admin/processor.rs | 1 + src/admin/user/commands.rs | 2 +- src/service/admin/mod.rs | 23 ++++++++++++++++++++--- src/service/rooms/timeline/mod.rs | 8 +++++--- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/admin/context.rs b/src/admin/context.rs index 270537be..b453d88f 100644 --- a/src/admin/context.rs +++ b/src/admin/context.rs @@ -7,13 +7,14 @@ use futures::{ io::{AsyncWriteExt, BufWriter}, lock::Mutex, }; -use ruma::EventId; +use ruma::{EventId, UserId}; pub(crate) struct Context<'a> { pub(crate) services: &'a Services, pub(crate) body: &'a [&'a str], pub(crate) timer: SystemTime, pub(crate) reply_id: Option<&'a EventId>, + pub(crate) sender: Option<&'a UserId>, pub(crate) output: Mutex>>, } @@ -36,4 +37,16 @@ impl Context<'_> { output.write_all(s.as_bytes()).map_err(Into::into).await }) } + + /// Get the sender of the admin command, if available + pub(crate) fn sender(&self) -> Option<&UserId> { self.sender } + + /// Check if the command has sender information + pub(crate) fn has_sender(&self) -> bool { self.sender.is_some() } + + /// Get the sender as a string, or service user ID if not available + pub(crate) fn sender_or_service_user(&self) -> &UserId { + self.sender + .unwrap_or_else(|| self.services.globals.server_user.as_ref()) + } } diff --git a/src/admin/processor.rs b/src/admin/processor.rs index f7b7140f..8d1fe89c 100644 --- a/src/admin/processor.rs +++ b/src/admin/processor.rs @@ -63,6 +63,7 @@ async fn process_command(services: Arc, input: &CommandInput) -> Proce body: &body, timer: SystemTime::now(), reply_id: input.reply_id.as_deref(), + sender: input.sender.as_deref(), output: BufWriter::new(Vec::new()).into(), }; diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index ad2d1c78..d094fc5f 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -241,7 +241,7 @@ pub(super) async fn suspend(&self, user_id: String) -> Result { // TODO: Record the actual user that sent the suspension where possible self.services .users - .suspend_account(&user_id, self.services.globals.server_user.as_ref()) + .suspend_account(&user_id, self.sender_or_service_user()) .await; self.write_str(&format!("User {user_id} has been suspended.")) diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 683f5400..86e12c3c 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -45,11 +45,13 @@ struct Services { services: StdRwLock>>, } -/// Inputs to a command are a multi-line string and optional reply_id. +/// Inputs to a command are a multi-line string, optional reply_id, and optional +/// sender. #[derive(Debug)] pub struct CommandInput { pub command: String, pub reply_id: Option, + pub sender: Option>, } /// Prototype of the tab-completer. The input is buffered text when tab @@ -162,7 +164,22 @@ impl Service { pub fn command(&self, command: String, reply_id: Option) -> Result<()> { self.channel .0 - .send(CommandInput { command, reply_id }) + .send(CommandInput { command, reply_id, sender: None }) + .map_err(|e| err!("Failed to enqueue admin command: {e:?}")) + } + + /// Posts a command to the command processor queue with sender information + /// and returns. Processing will take place on the service worker's task + /// asynchronously. Errors if the queue is full. + pub fn command_with_sender( + &self, + command: String, + reply_id: Option, + sender: Box, + ) -> Result<()> { + self.channel + .0 + .send(CommandInput { command, reply_id, sender: Some(sender) }) .map_err(|e| err!("Failed to enqueue admin command: {e:?}")) } @@ -173,7 +190,7 @@ impl Service { command: String, reply_id: Option, ) -> ProcessorResult { - self.process_command(CommandInput { command, reply_id }) + self.process_command(CommandInput { command, reply_id, sender: None }) .await } diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index 37963246..534d8faf 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -536,9 +536,11 @@ impl Service { self.services.search.index_pdu(shortroomid, &pdu_id, &body); if self.services.admin.is_admin_command(pdu, &body).await { - self.services - .admin - .command(body, Some((*pdu.event_id).into()))?; + self.services.admin.command_with_sender( + body, + Some((*pdu.event_id).into()), + pdu.sender.clone().into(), + )?; } } }, From d4862b8ead02a6ef61580ddefb24febb56c108b4 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 29 Jun 2025 16:26:04 +0100 Subject: [PATCH 2078/2291] style: Remove redundant, unused functions --- src/admin/context.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/admin/context.rs b/src/admin/context.rs index b453d88f..3d3cffb7 100644 --- a/src/admin/context.rs +++ b/src/admin/context.rs @@ -38,12 +38,6 @@ impl Context<'_> { }) } - /// Get the sender of the admin command, if available - pub(crate) fn sender(&self) -> Option<&UserId> { self.sender } - - /// Check if the command has sender information - pub(crate) fn has_sender(&self) -> bool { self.sender.is_some() } - /// Get the sender as a string, or service user ID if not available pub(crate) fn sender_or_service_user(&self) -> &UserId { self.sender From ec9d3d613e3b3be018ac73c791c956ae44cc6611 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 29 Jun 2025 23:02:15 +0100 Subject: [PATCH 2079/2291] chore: Add funding --- .github/FUNDING.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..321dc74c --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +github: [JadedBlueEyes] +# Doesn't support an array, so we can only list nex +ko_fi: nexy7574 From 17930708d86dd73c5d39dbe758d489621b2626e5 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 29 Jun 2025 23:06:26 +0100 Subject: [PATCH 2080/2291] chore: Add second ko-fi as custom link --- .github/FUNDING.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 321dc74c..fcfaade5 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,5 @@ github: [JadedBlueEyes] # Doesn't support an array, so we can only list nex ko_fi: nexy7574 +custom: + - https://ko-fi.com/JadedBlueEyes From 97e5cc4e2db5fee0495d8f597180fe774b11aa0d Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 1 Jul 2025 01:55:13 +0100 Subject: [PATCH 2081/2291] feat: Implement user reporting --- Cargo.lock | 22 ++++++------ Cargo.toml | 2 +- src/api/client/report.rs | 72 ++++++++++++++++++++++++++++++++-------- src/api/router.rs | 1 + 4 files changed, 71 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 92044b92..8719c6ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3798,7 +3798,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.10.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" dependencies = [ "assign", "js_int", @@ -3818,7 +3818,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" dependencies = [ "js_int", "ruma-common", @@ -3830,7 +3830,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" dependencies = [ "as_variant", "assign", @@ -3853,7 +3853,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" dependencies = [ "as_variant", "base64 0.22.1", @@ -3885,7 +3885,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" dependencies = [ "as_variant", "indexmap 2.9.0", @@ -3910,7 +3910,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" dependencies = [ "bytes", "headers", @@ -3932,7 +3932,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" dependencies = [ "js_int", "thiserror 2.0.12", @@ -3941,7 +3941,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" dependencies = [ "js_int", "ruma-common", @@ -3951,7 +3951,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" dependencies = [ "cfg-if", "proc-macro-crate", @@ -3966,7 +3966,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" dependencies = [ "js_int", "ruma-common", @@ -3978,7 +3978,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=9b65f83981f6f53d185ce77da37aaef9dfd764a9#9b65f83981f6f53d185ce77da37aaef9dfd764a9" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" dependencies = [ "base64 0.22.1", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index 5c289adf..83afd482 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -350,7 +350,7 @@ version = "0.1.2" [workspace.dependencies.ruma] git = "https://forgejo.ellis.link/continuwuation/ruwuma" #branch = "conduwuit-changes" -rev = "9b65f83981f6f53d185ce77da37aaef9dfd764a9" +rev = "f899fff6738dd57d191474b0f12a4509cf8f0981" features = [ "compat", "rand", diff --git a/src/api/client/report.rs b/src/api/client/report.rs index 4ee8ebe5..f63e78ed 100644 --- a/src/api/client/report.rs +++ b/src/api/client/report.rs @@ -9,6 +9,7 @@ use ruma::{ EventId, RoomId, UserId, api::client::{ error::ErrorKind, + report_user, room::{report_content, report_room}, }, events::room::message, @@ -30,12 +31,6 @@ pub(crate) async fn report_room_route( // user authentication let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - info!( - "Received room report by user {sender_user} for room {} with reason: \"{}\"", - body.room_id, - body.reason.as_deref().unwrap_or("") - ); - if body.reason.as_ref().is_some_and(|s| s.len() > 750) { return Err(Error::BadRequest( ErrorKind::InvalidParam, @@ -55,6 +50,11 @@ pub(crate) async fn report_room_route( "Room does not exist to us, no local users have joined at all" ))); } + info!( + "Received room report by user {sender_user} for room {} with reason: \"{}\"", + body.room_id, + body.reason.as_deref().unwrap_or("") + ); // send admin room message that we received the report with an @room ping for // urgency @@ -84,14 +84,6 @@ pub(crate) async fn report_event_route( // user authentication let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - info!( - "Received event report by user {sender_user} for room {} and event ID {}, with reason: \ - \"{}\"", - body.room_id, - body.event_id, - body.reason.as_deref().unwrap_or("") - ); - delay_response().await; // check if we know about the reported event ID or if it's invalid @@ -109,6 +101,13 @@ pub(crate) async fn report_event_route( &pdu, ) .await?; + info!( + "Received event report by user {sender_user} for room {} and event ID {}, with reason: \ + \"{}\"", + body.room_id, + body.event_id, + body.reason.as_deref().unwrap_or("") + ); // send admin room message that we received the report with an @room ping for // urgency @@ -130,6 +129,51 @@ pub(crate) async fn report_event_route( Ok(report_content::v3::Response {}) } +#[tracing::instrument(skip_all, fields(%client), name = "report_user")] +pub(crate) async fn report_user_route( + State(services): State, + InsecureClientIp(client): InsecureClientIp, + body: Ruma, +) -> Result { + // user authentication + let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + + if body.reason.as_ref().is_some_and(|s| s.len() > 750) { + return Err(Error::BadRequest( + ErrorKind::InvalidParam, + "Reason too long, should be 750 characters or fewer", + )); + } + + delay_response().await; + + if !services.users.is_active_local(&body.user_id) { + // return 200 as to not reveal if the user exists. Recommended by spec. + return Ok(report_user::v3::Response {}); + } + + info!( + "Received room report from {sender_user} for user {} with reason: \"{}\"", + body.user_id, + body.reason.as_deref().unwrap_or("") + ); + + // send admin room message that we received the report with an @room ping for + // urgency + services + .admin + .send_message(message::RoomMessageEventContent::text_markdown(format!( + "@room User report received from {} -\n\nUser ID: {}\n\nReport Reason: {}", + sender_user.to_owned(), + body.user_id, + body.reason.as_deref().unwrap_or("") + ))) + .await + .ok(); + + Ok(report_user::v3::Response {}) +} + /// in the following order: /// /// check if the room ID from the URI matches the PDU's room ID diff --git a/src/api/router.rs b/src/api/router.rs index 5416e9e9..d1b05a91 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -94,6 +94,7 @@ pub fn build(router: Router, server: &Server) -> Router { .ruma_route(&client::redact_event_route) .ruma_route(&client::report_event_route) .ruma_route(&client::report_room_route) + .ruma_route(&client::report_user_route) .ruma_route(&client::create_alias_route) .ruma_route(&client::delete_alias_route) .ruma_route(&client::get_alias_route) From 59912709aa603d66bc24c074f0337c71fdeaa56c Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 1 Jul 2025 15:42:38 +0100 Subject: [PATCH 2082/2291] feat: Send intentional mentions in report messages --- src/api/client/report.rs | 125 +++++++++++++++++++++++++-------------- 1 file changed, 81 insertions(+), 44 deletions(-) diff --git a/src/api/client/report.rs b/src/api/client/report.rs index f63e78ed..1f237fcb 100644 --- a/src/api/client/report.rs +++ b/src/api/client/report.rs @@ -1,4 +1,7 @@ -use std::time::Duration; +use std::{ + ops::{Mul, Sub}, + time::Duration, +}; use axum::extract::State; use axum_client_ip::InsecureClientIp; @@ -6,19 +9,35 @@ use conduwuit::{Err, Error, Result, debug_info, info, matrix::pdu::PduEvent, uti use conduwuit_service::Services; use rand::Rng; use ruma::{ - EventId, RoomId, UserId, + EventId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId, api::client::{ error::ErrorKind, report_user, room::{report_content, report_room}, }, - events::room::message, + events::{ + Mentions, + room::{ + message, + message::{RoomMessageEvent, RoomMessageEventContent}, + }, + }, int, }; use tokio::time::sleep; use crate::Ruma; +struct Report { + sender: OwnedUserId, + room_id: Option, + event_id: Option, + user_id: Option, + report_type: String, + reason: Option, + score: Option, +} + /// # `POST /_matrix/client/v3/rooms/{roomId}/report` /// /// Reports an abusive room to homeserver admins @@ -56,18 +75,17 @@ pub(crate) async fn report_room_route( body.reason.as_deref().unwrap_or("") ); - // send admin room message that we received the report with an @room ping for - // urgency - services - .admin - .send_message(message::RoomMessageEventContent::text_markdown(format!( - "@room Room report received from {} -\n\nRoom ID: {}\n\nReport Reason: {}", - sender_user.to_owned(), - body.room_id, - body.reason.as_deref().unwrap_or("") - ))) - .await - .ok(); + let report = Report { + sender: sender_user.to_owned(), + room_id: Some(body.room_id.to_owned()), + event_id: None, + user_id: None, + report_type: "room".to_string(), + reason: body.reason.clone(), + score: None, + }; + + services.admin.send_message(build_report(report)).await.ok(); Ok(report_room::v3::Response {}) } @@ -108,23 +126,16 @@ pub(crate) async fn report_event_route( body.event_id, body.reason.as_deref().unwrap_or("") ); - - // send admin room message that we received the report with an @room ping for - // urgency - services - .admin - .send_message(message::RoomMessageEventContent::text_markdown(format!( - "@room Event report received from {} -\n\nEvent ID: {}\nRoom ID: {}\nSent By: \ - {}\n\nReport Score: {}\nReport Reason: {}", - sender_user.to_owned(), - pdu.event_id, - pdu.room_id, - pdu.sender, - body.score.unwrap_or_else(|| ruma::Int::from(0)), - body.reason.as_deref().unwrap_or("") - ))) - .await - .ok(); + let report = Report { + sender: sender_user.to_owned(), + room_id: Some(body.room_id.to_owned()), + event_id: Some(body.event_id.to_owned()), + user_id: None, + report_type: "event".to_string(), + reason: body.reason.clone(), + score: body.score, + }; + services.admin.send_message(build_report(report)).await.ok(); Ok(report_content::v3::Response {}) } @@ -152,24 +163,23 @@ pub(crate) async fn report_user_route( return Ok(report_user::v3::Response {}); } + let report = Report { + sender: sender_user.to_owned(), + room_id: None, + event_id: None, + user_id: Some(body.user_id.to_owned()), + report_type: "user".to_string(), + reason: body.reason.clone(), + score: None, + }; + info!( "Received room report from {sender_user} for user {} with reason: \"{}\"", body.user_id, body.reason.as_deref().unwrap_or("") ); - // send admin room message that we received the report with an @room ping for - // urgency - services - .admin - .send_message(message::RoomMessageEventContent::text_markdown(format!( - "@room User report received from {} -\n\nUser ID: {}\n\nReport Reason: {}", - sender_user.to_owned(), - body.user_id, - body.reason.as_deref().unwrap_or("") - ))) - .await - .ok(); + services.admin.send_message(build_report(report)).await.ok(); Ok(report_user::v3::Response {}) } @@ -231,6 +241,33 @@ async fn is_event_report_valid( Ok(()) } +/// Builds a report message to be sent to the admin room. +fn build_report(report: Report) -> RoomMessageEventContent { + let mut text = + format!("@room New {} report received from {}:\n\n", report.report_type, report.sender); + if report.user_id.is_some() { + text.push_str(&format!("- Reported User ID: `{}`\n", report.user_id.unwrap())); + } + if report.room_id.is_some() { + text.push_str(&format!("- Reported Room ID: `{}`\n", report.room_id.unwrap())); + } + if report.event_id.is_some() { + text.push_str(&format!("- Reported Event ID: `{}`\n", report.event_id.unwrap())); + } + if let Some(score) = report.score { + if score < int!(0) { + score.mul(int!(-1)); // invert the score to make it N/100 + // unsure why the spec says -100 to 0, but 0 to 100 is more human. + } + text.push_str(&format!("- User-supplied offensiveness score: {}%\n", -score)); + } + if let Some(reason) = report.reason { + text.push_str(&format!("- Report Reason: {}\n", reason)); + } + + RoomMessageEventContent::text_markdown(text).add_mentions(Mentions::with_room_mention()); +} + /// even though this is kinda security by obscurity, let's still make a small /// random delay sending a response per spec suggestion regarding /// enumerating for potential events existing in our server. From f49c73c0317e65b290bb7d50e81ae6a326e2bed6 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 1 Jul 2025 15:44:04 +0100 Subject: [PATCH 2083/2291] feat: Forbid suspended users from sending reports --- src/api/client/report.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/api/client/report.rs b/src/api/client/report.rs index 1f237fcb..d0d21829 100644 --- a/src/api/client/report.rs +++ b/src/api/client/report.rs @@ -49,6 +49,9 @@ pub(crate) async fn report_room_route( ) -> Result { // user authentication let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } if body.reason.as_ref().is_some_and(|s| s.len() > 750) { return Err(Error::BadRequest( @@ -101,6 +104,9 @@ pub(crate) async fn report_event_route( ) -> Result { // user authentication let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } delay_response().await; @@ -148,6 +154,9 @@ pub(crate) async fn report_user_route( ) -> Result { // user authentication let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } if body.reason.as_ref().is_some_and(|s| s.len() > 750) { return Err(Error::BadRequest( From 24d2a514e22930e15d27825063cb0a8e9244ddc9 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 1 Jul 2025 18:00:28 +0100 Subject: [PATCH 2084/2291] chore: Resolve linting errors --- Cargo.lock | 22 ++++++++--------- Cargo.toml | 2 +- src/api/client/report.rs | 45 +++++++++++++---------------------- src/api/client/unversioned.rs | 1 + 4 files changed, 29 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8719c6ca..82e7a20d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3798,7 +3798,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.10.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=a4b948b40417a65ab0282ae47cc50035dd455e02#a4b948b40417a65ab0282ae47cc50035dd455e02" dependencies = [ "assign", "js_int", @@ -3818,7 +3818,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=a4b948b40417a65ab0282ae47cc50035dd455e02#a4b948b40417a65ab0282ae47cc50035dd455e02" dependencies = [ "js_int", "ruma-common", @@ -3830,7 +3830,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=a4b948b40417a65ab0282ae47cc50035dd455e02#a4b948b40417a65ab0282ae47cc50035dd455e02" dependencies = [ "as_variant", "assign", @@ -3853,7 +3853,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=a4b948b40417a65ab0282ae47cc50035dd455e02#a4b948b40417a65ab0282ae47cc50035dd455e02" dependencies = [ "as_variant", "base64 0.22.1", @@ -3885,7 +3885,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=a4b948b40417a65ab0282ae47cc50035dd455e02#a4b948b40417a65ab0282ae47cc50035dd455e02" dependencies = [ "as_variant", "indexmap 2.9.0", @@ -3910,7 +3910,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=a4b948b40417a65ab0282ae47cc50035dd455e02#a4b948b40417a65ab0282ae47cc50035dd455e02" dependencies = [ "bytes", "headers", @@ -3932,7 +3932,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=a4b948b40417a65ab0282ae47cc50035dd455e02#a4b948b40417a65ab0282ae47cc50035dd455e02" dependencies = [ "js_int", "thiserror 2.0.12", @@ -3941,7 +3941,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=a4b948b40417a65ab0282ae47cc50035dd455e02#a4b948b40417a65ab0282ae47cc50035dd455e02" dependencies = [ "js_int", "ruma-common", @@ -3951,7 +3951,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=a4b948b40417a65ab0282ae47cc50035dd455e02#a4b948b40417a65ab0282ae47cc50035dd455e02" dependencies = [ "cfg-if", "proc-macro-crate", @@ -3966,7 +3966,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=a4b948b40417a65ab0282ae47cc50035dd455e02#a4b948b40417a65ab0282ae47cc50035dd455e02" dependencies = [ "js_int", "ruma-common", @@ -3978,7 +3978,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=f899fff6738dd57d191474b0f12a4509cf8f0981#f899fff6738dd57d191474b0f12a4509cf8f0981" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=a4b948b40417a65ab0282ae47cc50035dd455e02#a4b948b40417a65ab0282ae47cc50035dd455e02" dependencies = [ "base64 0.22.1", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index 83afd482..b815e2b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -350,7 +350,7 @@ version = "0.1.2" [workspace.dependencies.ruma] git = "https://forgejo.ellis.link/continuwuation/ruwuma" #branch = "conduwuit-changes" -rev = "f899fff6738dd57d191474b0f12a4509cf8f0981" +rev = "a4b948b40417a65ab0282ae47cc50035dd455e02" features = [ "compat", "rand", diff --git a/src/api/client/report.rs b/src/api/client/report.rs index d0d21829..5113b42f 100644 --- a/src/api/client/report.rs +++ b/src/api/client/report.rs @@ -1,7 +1,4 @@ -use std::{ - ops::{Mul, Sub}, - time::Duration, -}; +use std::{fmt::Write as _, ops::Mul, time::Duration}; use axum::extract::State; use axum_client_ip::InsecureClientIp; @@ -15,13 +12,7 @@ use ruma::{ report_user, room::{report_content, report_room}, }, - events::{ - Mentions, - room::{ - message, - message::{RoomMessageEvent, RoomMessageEventContent}, - }, - }, + events::{Mentions, room::message::RoomMessageEventContent}, int, }; use tokio::time::sleep; @@ -80,10 +71,10 @@ pub(crate) async fn report_room_route( let report = Report { sender: sender_user.to_owned(), - room_id: Some(body.room_id.to_owned()), + room_id: Some(body.room_id.clone()), event_id: None, user_id: None, - report_type: "room".to_string(), + report_type: "room".to_owned(), reason: body.reason.clone(), score: None, }; @@ -134,10 +125,10 @@ pub(crate) async fn report_event_route( ); let report = Report { sender: sender_user.to_owned(), - room_id: Some(body.room_id.to_owned()), - event_id: Some(body.event_id.to_owned()), + room_id: Some(body.room_id.clone()), + event_id: Some(body.event_id.clone()), user_id: None, - report_type: "event".to_string(), + report_type: "event".to_owned(), reason: body.reason.clone(), score: body.score, }; @@ -167,7 +158,7 @@ pub(crate) async fn report_user_route( delay_response().await; - if !services.users.is_active_local(&body.user_id) { + if !services.users.is_active_local(&body.user_id).await { // return 200 as to not reveal if the user exists. Recommended by spec. return Ok(report_user::v3::Response {}); } @@ -176,8 +167,8 @@ pub(crate) async fn report_user_route( sender: sender_user.to_owned(), room_id: None, event_id: None, - user_id: Some(body.user_id.to_owned()), - report_type: "user".to_string(), + user_id: Some(body.user_id.clone()), + report_type: "user".to_owned(), reason: body.reason.clone(), score: None, }; @@ -255,26 +246,22 @@ fn build_report(report: Report) -> RoomMessageEventContent { let mut text = format!("@room New {} report received from {}:\n\n", report.report_type, report.sender); if report.user_id.is_some() { - text.push_str(&format!("- Reported User ID: `{}`\n", report.user_id.unwrap())); + let _ = writeln!(text, "- Reported User ID: `{}`", report.user_id.unwrap()); } if report.room_id.is_some() { - text.push_str(&format!("- Reported Room ID: `{}`\n", report.room_id.unwrap())); + let _ = writeln!(text, "- Reported Room ID: `{}`", report.room_id.unwrap()); } if report.event_id.is_some() { - text.push_str(&format!("- Reported Event ID: `{}`\n", report.event_id.unwrap())); + let _ = writeln!(text, "- Reported Event ID: `{}`", report.event_id.unwrap()); } if let Some(score) = report.score { - if score < int!(0) { - score.mul(int!(-1)); // invert the score to make it N/100 - // unsure why the spec says -100 to 0, but 0 to 100 is more human. - } - text.push_str(&format!("- User-supplied offensiveness score: {}%\n", -score)); + let _ = writeln!(text, "- User-supplied offensiveness score: {}%", score.mul(int!(-1))); } if let Some(reason) = report.reason { - text.push_str(&format!("- Report Reason: {}\n", reason)); + let _ = writeln!(text, "- Report Reason: {reason}"); } - RoomMessageEventContent::text_markdown(text).add_mentions(Mentions::with_room_mention()); + RoomMessageEventContent::text_markdown(text).add_mentions(Mentions::with_room_mention()) } /// even though this is kinda security by obscurity, let's still make a small diff --git a/src/api/client/unversioned.rs b/src/api/client/unversioned.rs index 232d5b28..ad377ca4 100644 --- a/src/api/client/unversioned.rs +++ b/src/api/client/unversioned.rs @@ -38,6 +38,7 @@ pub(crate) async fn get_supported_versions_route( "v1.4".to_owned(), "v1.5".to_owned(), "v1.11".to_owned(), + "v1.14".to_owned(), ], unstable_features: BTreeMap::from_iter([ ("org.matrix.e2e_cross_signing".to_owned(), true), From 4f69da47c6899e5d6e3280c34524e6aa53f838f4 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 1 Jul 2025 18:38:48 +0100 Subject: [PATCH 2085/2291] feat: Advertise support for spec v1.8, 1.12, 1.13, and 1.14 --- committed.toml | 1 + src/api/client/unversioned.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/committed.toml b/committed.toml index 64f7f18a..59750fa5 100644 --- a/committed.toml +++ b/committed.toml @@ -1,2 +1,3 @@ style = "conventional" +subject_length = 72 allowed_types = ["ci", "build", "fix", "feat", "chore", "docs", "style", "refactor", "perf", "test"] diff --git a/src/api/client/unversioned.rs b/src/api/client/unversioned.rs index ad377ca4..a4136d1a 100644 --- a/src/api/client/unversioned.rs +++ b/src/api/client/unversioned.rs @@ -37,7 +37,10 @@ pub(crate) async fn get_supported_versions_route( "v1.3".to_owned(), "v1.4".to_owned(), "v1.5".to_owned(), + "v1.8".to_owned(), "v1.11".to_owned(), + "v1.12".to_owned(), + "v1.13".to_owned(), "v1.14".to_owned(), ], unstable_features: BTreeMap::from_iter([ From b44791799c8141d93cf50634eb799505cae8f15a Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 1 Jul 2025 23:14:41 +0100 Subject: [PATCH 2086/2291] fix: Room bans preventing federated leaves Fixes the issue where room bans prevent federating leave events, resulting in local users being stuck in remote rooms --- src/admin/room/moderation.rs | 62 +++++++++++------------------------- 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/src/admin/room/moderation.rs b/src/admin/room/moderation.rs index ee429fc6..921249bd 100644 --- a/src/admin/room/moderation.rs +++ b/src/admin/room/moderation.rs @@ -1,7 +1,7 @@ use api::client::leave_room; use clap::Subcommand; use conduwuit::{ - Err, Result, debug, + Err, Result, debug, info, utils::{IterStream, ReadyExt}, warn, }; @@ -70,7 +70,6 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result { }; debug!("Room specified is a room ID, banning room ID"); - self.services.rooms.metadata.ban_room(room_id, true); room_id.to_owned() } else if room.is_room_alias_id() { @@ -90,47 +89,25 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result { locally, if not using get_alias_helper to fetch room ID remotely" ); - let room_id = match self + match self .services .rooms .alias - .resolve_local_alias(room_alias) + .resolve_alias(room_alias, None) .await { - | Ok(room_id) => room_id, - | _ => { + | Ok((room_id, servers)) => { debug!( - "We don't have this room alias to a room ID locally, attempting to fetch \ - room ID over federation" + ?room_id, + ?servers, + "Got federation response fetching room ID for room {room}" ); - - match self - .services - .rooms - .alias - .resolve_alias(room_alias, None) - .await - { - | Ok((room_id, servers)) => { - debug!( - ?room_id, - ?servers, - "Got federation response fetching room ID for {room_id}" - ); - room_id - }, - | Err(e) => { - return Err!( - "Failed to resolve room alias {room_alias} to a room ID: {e}" - ); - }, - } + room_id }, - }; - - self.services.rooms.metadata.ban_room(&room_id, true); - - room_id + | Err(e) => { + return Err!("Failed to resolve room alias {room} to a room ID: {e}"); + }, + } } else { return Err!( "Room specified is not a room ID or room alias. Please note that this requires a \ @@ -139,7 +116,7 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result { ); }; - debug!("Making all users leave the room {room_id} and forgetting it"); + info!("Making all users leave the room {room_id} and forgetting it"); let mut users = self .services .rooms @@ -150,7 +127,7 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result { .boxed(); while let Some(ref user_id) = users.next().await { - debug!( + info!( "Attempting leave for user {user_id} in room {room_id} (ignoring all errors, \ evicting admins too)", ); @@ -177,10 +154,9 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result { }) .await; - // unpublish from room directory - self.services.rooms.directory.set_not_public(&room_id); - - self.services.rooms.metadata.disable_room(&room_id, true); + self.services.rooms.directory.set_not_public(&room_id); // remove from the room directory + self.services.rooms.metadata.ban_room(&room_id, true); // prevent further joins + self.services.rooms.metadata.disable_room(&room_id, true); // disable federation self.write_str( "Room banned, removed all our local users, and disabled incoming federation with room.", @@ -302,8 +278,6 @@ async fn ban_list_of_rooms(&self) -> Result { } for room_id in room_ids { - self.services.rooms.metadata.ban_room(&room_id, true); - debug!("Banned {room_id} successfully"); room_ban_count = room_ban_count.saturating_add(1); @@ -346,9 +320,9 @@ async fn ban_list_of_rooms(&self) -> Result { }) .await; + self.services.rooms.metadata.ban_room(&room_id, true); // unpublish from room directory, ignore errors self.services.rooms.directory.set_not_public(&room_id); - self.services.rooms.metadata.disable_room(&room_id, true); } From 68afb07c27368c0ec4d9fc936ef0cf39eb2233be Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 1 Jul 2025 01:36:58 +0100 Subject: [PATCH 2087/2291] feat: Stabilise room summary API (MSC3266) # Conflicts: # Cargo.lock # Cargo.toml --- src/api/client/room/summary.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/api/client/room/summary.rs b/src/api/client/room/summary.rs index 67d2e2ad..ab534765 100644 --- a/src/api/client/room/summary.rs +++ b/src/api/client/room/summary.rs @@ -43,10 +43,9 @@ pub(crate) async fn get_room_summary_legacy( } /// # `GET /_matrix/client/unstable/im.nheko.summary/summary/{roomIdOrAlias}` +/// # `GET /_matrix/client/v1/room_summary/{roomIdOrAlias}` /// /// Returns a short description of the state of a room. -/// -/// An implementation of [MSC3266](https://github.com/matrix-org/matrix-spec-proposals/pull/3266) #[tracing::instrument(skip_all, fields(%client), name = "room_summary")] pub(crate) async fn get_room_summary( State(services): State, From 6e609185847023cfb3caf85b98f03a6e3efb6e2e Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 2 Jul 2025 00:41:34 +0100 Subject: [PATCH 2088/2291] feat: Suspend new users on registration --- conduwuit-example.toml | 11 +++++++++++ src/api/client/account.rs | 20 ++++++++++++++++++++ src/core/config/mod.rs | 11 +++++++++++ src/service/admin/mod.rs | 16 +++++++++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 1a8be2aa..794ab870 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -398,6 +398,17 @@ # #allow_registration = false +# If registration is enabled, and this setting is true, new users +# registered after the first admin user will be automatically suspended +# and will require an admin to run `!admin users unsuspend `. +# +# Suspended users are still able to read messages, make profile updates, +# leave rooms, and deactivate their account, however cannot send messages, +# invites, or create/join or otherwise modify rooms. +# They are effectively read-only. +# +#suspend_on_register = false + # Enabling this setting opens registration to anyone without restrictions. # This makes your server vulnerable to abuse # diff --git a/src/api/client/account.rs b/src/api/client/account.rs index 32f2530c..32ac7bc2 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -2,6 +2,7 @@ use std::fmt::Write; use axum::extract::State; use axum_client_ip::InsecureClientIp; +use axum_extra::headers::UserAgent; use conduwuit::{ Err, Error, Result, debug_info, err, error, info, is_equal_to, matrix::pdu::PduBuilder, @@ -490,6 +491,25 @@ pub(crate) async fn register_route( { services.admin.make_user_admin(&user_id).await?; warn!("Granting {user_id} admin privileges as the first user"); + } else if services.config.suspend_on_register { + // This is not an admin, suspend them. + // Note that we can still do auto joins for suspended users + services + .users + .suspend_account(&user_id, &services.globals.server_user) + .await; + // And send an @room notice to the admin room, to prompt admins to review the + // new user and ideally unsuspend them if deemed appropriate. + if services.server.config.admin_room_notices { + services + .admin + .send_loud_message(RoomMessageEventContent::text_plain(format!( + "User {user_id} has been suspended as they are not the first user \ + on this server. Please review and unsuspend them if appropriate." + ))) + .await + .ok(); + } } } } diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index d4a10345..c735193b 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -513,6 +513,17 @@ pub struct Config { #[serde(default)] pub allow_registration: bool, + /// If registration is enabled, and this setting is true, new users + /// registered after the first admin user will be automatically suspended + /// and will require an admin to run `!admin users unsuspend `. + /// + /// Suspended users are still able to read messages, make profile updates, + /// leave rooms, and deactivate their account, however cannot send messages, + /// invites, or create/join or otherwise modify rooms. + /// They are effectively read-only. + #[serde(default)] + pub suspend_on_register: bool, + /// Enabling this setting opens registration to anyone without restrictions. /// This makes your server vulnerable to abuse #[serde(default)] diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 86e12c3c..11d93cc2 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -18,7 +18,10 @@ use futures::{FutureExt, TryFutureExt}; use loole::{Receiver, Sender}; use ruma::{ OwnedEventId, OwnedRoomId, RoomId, UserId, - events::room::message::{Relation, RoomMessageEventContent}, + events::{ + Mentions, + room::message::{Relation, RoomMessageEventContent}, + }, }; use tokio::sync::RwLock; @@ -158,6 +161,17 @@ impl Service { .await } + /// Sends a message, the same as send_message() but with an @room ping to + /// notify all users in the room. + pub async fn send_loud_message( + &self, + mut message_content: RoomMessageEventContent, + ) -> Result<()> { + // Add @room ping + message_content = message_content.add_mentions(Mentions::with_room_mention()); + self.send_message(message_content).await + } + /// Posts a command to the command processor queue and returns. Processing /// will take place on the service worker's task asynchronously. Errors if /// the queue is full. From 8e0852e5b5697bb7d39639719c7d7e3f969e9c42 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 2 Jul 2025 00:44:47 +0100 Subject: [PATCH 2089/2291] docs: Add suggestion about auto join room Adds suggestion to suspend_on_register doc that admins should add a room that contains information to their auto_join_rooms as to not confuse new users who may be lost at the fact they can't join any rooms or send any messages. --- src/core/config/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index c735193b..e3db4900 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -521,6 +521,11 @@ pub struct Config { /// leave rooms, and deactivate their account, however cannot send messages, /// invites, or create/join or otherwise modify rooms. /// They are effectively read-only. + /// + /// If you want to use this to screen people who register on your server, + /// you should add a room to `auto_join_rooms` that is public, and contains + /// information that new users can read (since they won't be able to DM + /// anyone, or send a message, and may be confused). #[serde(default)] pub suspend_on_register: bool, From d6aa03ea7308fae430dd99df1d1ce4f5360a1d12 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 2 Jul 2025 01:53:21 +0100 Subject: [PATCH 2090/2291] style: Remove extraneous import --- src/api/client/account.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api/client/account.rs b/src/api/client/account.rs index 32ac7bc2..56b1a81c 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -2,7 +2,6 @@ use std::fmt::Write; use axum::extract::State; use axum_client_ip::InsecureClientIp; -use axum_extra::headers::UserAgent; use conduwuit::{ Err, Error, Result, debug_info, err, error, info, is_equal_to, matrix::pdu::PduBuilder, From 49f7a2487f70ffcfeb0b355e8625a8a694e7ca6c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 26 Apr 2025 23:06:43 +0000 Subject: [PATCH 2091/2291] Modernize various sender_user/sender_device lets. Signed-off-by: Jason Volk --- src/api/client/account.rs | 27 +++++++++++---------------- src/api/client/alias.rs | 4 ++-- src/api/client/device.rs | 8 ++------ src/api/client/filter.rs | 10 ++++------ src/api/client/keys.rs | 11 +++++------ src/api/client/media.rs | 10 +++++----- src/api/client/media_legacy.rs | 2 +- src/api/client/membership.rs | 6 +++--- src/api/client/openid.rs | 4 ++-- src/api/client/profile.rs | 4 ++-- src/api/client/push.rs | 21 ++++++++++----------- src/api/client/redact.rs | 4 ++-- src/api/client/report.rs | 5 ++--- src/api/client/room/aliases.rs | 2 +- src/api/client/room/create.rs | 6 +++--- src/api/client/session.rs | 15 ++++----------- src/api/client/state.rs | 2 +- src/api/client/tag.rs | 6 +++--- src/api/client/to_device.rs | 4 ++-- src/api/client/unstable.rs | 8 ++++---- 20 files changed, 69 insertions(+), 90 deletions(-) diff --git a/src/api/client/account.rs b/src/api/client/account.rs index 56b1a81c..30f8b89c 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -603,7 +603,6 @@ pub(crate) async fn change_password_route( .sender_user .as_ref() .ok_or_else(|| err!(Request(MissingToken("Missing access token."))))?; - let sender_device = body.sender_device(); let mut uiaainfo = UiaaInfo { flows: vec![AuthFlow { stages: vec![AuthType::Password] }], @@ -617,7 +616,7 @@ pub(crate) async fn change_password_route( | Some(auth) => { let (worked, uiaainfo) = services .uiaa - .try_auth(sender_user, sender_device, auth, &uiaainfo) + .try_auth(sender_user, body.sender_device(), auth, &uiaainfo) .await?; if !worked { @@ -631,7 +630,7 @@ pub(crate) async fn change_password_route( uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); services .uiaa - .create(sender_user, sender_device, &uiaainfo, json); + .create(sender_user, body.sender_device(), &uiaainfo, json); return Err(Error::Uiaa(uiaainfo)); }, @@ -650,7 +649,7 @@ pub(crate) async fn change_password_route( services .users .all_device_ids(sender_user) - .ready_filter(|id| *id != sender_device) + .ready_filter(|id| *id != body.sender_device()) .for_each(|id| services.users.remove_device(sender_user, id)) .await; @@ -659,17 +658,17 @@ pub(crate) async fn change_password_route( .pusher .get_pushkeys(sender_user) .map(ToOwned::to_owned) - .broad_filter_map(|pushkey| async move { + .broad_filter_map(async |pushkey| { services .pusher .get_pusher_device(&pushkey) .await .ok() - .filter(|pusher_device| pusher_device != sender_device) + .filter(|pusher_device| pusher_device != body.sender_device()) .is_some() .then_some(pushkey) }) - .for_each(|pushkey| async move { + .for_each(async |pushkey| { services.pusher.delete_pusher(sender_user, &pushkey).await; }) .await; @@ -699,13 +698,10 @@ pub(crate) async fn whoami_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let device_id = body.sender_device.clone(); - Ok(whoami::v3::Response { - user_id: sender_user.clone(), - device_id, - is_guest: services.users.is_deactivated(sender_user).await? + user_id: body.sender_user().to_owned(), + device_id: body.sender_device.clone(), + is_guest: services.users.is_deactivated(body.sender_user()).await? && body.appservice_info.is_none(), }) } @@ -733,7 +729,6 @@ pub(crate) async fn deactivate_route( .sender_user .as_ref() .ok_or_else(|| err!(Request(MissingToken("Missing access token."))))?; - let sender_device = body.sender_device(); let mut uiaainfo = UiaaInfo { flows: vec![AuthFlow { stages: vec![AuthType::Password] }], @@ -747,7 +742,7 @@ pub(crate) async fn deactivate_route( | Some(auth) => { let (worked, uiaainfo) = services .uiaa - .try_auth(sender_user, sender_device, auth, &uiaainfo) + .try_auth(sender_user, body.sender_device(), auth, &uiaainfo) .await?; if !worked { @@ -760,7 +755,7 @@ pub(crate) async fn deactivate_route( uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); services .uiaa - .create(sender_user, sender_device, &uiaainfo, json); + .create(sender_user, body.sender_device(), &uiaainfo, json); return Err(Error::Uiaa(uiaainfo)); }, diff --git a/src/api/client/alias.rs b/src/api/client/alias.rs index dc7aad44..97c1a1bd 100644 --- a/src/api/client/alias.rs +++ b/src/api/client/alias.rs @@ -17,7 +17,7 @@ pub(crate) async fn create_alias_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if services.users.is_suspended(sender_user).await? { return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); } @@ -65,7 +65,7 @@ pub(crate) async fn delete_alias_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if services.users.is_suspended(sender_user).await? { return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); } diff --git a/src/api/client/device.rs b/src/api/client/device.rs index 5519a1a5..b0a7e142 100644 --- a/src/api/client/device.rs +++ b/src/api/client/device.rs @@ -21,11 +21,9 @@ pub(crate) async fn get_devices_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let devices: Vec = services .users - .all_devices_metadata(sender_user) + .all_devices_metadata(body.sender_user()) .collect() .await; @@ -39,11 +37,9 @@ pub(crate) async fn get_device_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let device = services .users - .get_device_metadata(sender_user, &body.body.device_id) + .get_device_metadata(body.sender_user(), &body.body.device_id) .await .map_err(|_| err!(Request(NotFound("Device not found."))))?; diff --git a/src/api/client/filter.rs b/src/api/client/filter.rs index 97044ffc..9814d366 100644 --- a/src/api/client/filter.rs +++ b/src/api/client/filter.rs @@ -13,11 +13,9 @@ pub(crate) async fn get_filter_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - services .users - .get_filter(sender_user, &body.filter_id) + .get_filter(body.sender_user(), &body.filter_id) .await .map(get_filter::v3::Response::new) .map_err(|_| err!(Request(NotFound("Filter not found.")))) @@ -30,9 +28,9 @@ pub(crate) async fn create_filter_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - - let filter_id = services.users.create_filter(sender_user, &body.filter); + let filter_id = services + .users + .create_filter(body.sender_user(), &body.filter); Ok(create_filter::v3::Response::new(filter_id)) } diff --git a/src/api/client/keys.rs b/src/api/client/keys.rs index 650c573f..d2bd46a0 100644 --- a/src/api/client/keys.rs +++ b/src/api/client/keys.rs @@ -126,7 +126,7 @@ pub(crate) async fn get_keys_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); get_keys_helper( &services, @@ -157,8 +157,7 @@ pub(crate) async fn upload_signing_keys_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let sender_device = body.sender_device.as_ref().expect("user is authenticated"); + let (sender_user, sender_device) = body.sender(); // UIAA let mut uiaainfo = UiaaInfo { @@ -203,12 +202,12 @@ pub(crate) async fn upload_signing_keys_route( } // Success! }, - | _ => match body.json_body { + | _ => match body.json_body.as_ref() { | Some(json) => { uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); services .uiaa - .create(sender_user, sender_device, &uiaainfo, &json); + .create(sender_user, sender_device, &uiaainfo, json); return Err(Error::Uiaa(uiaainfo)); }, @@ -373,7 +372,7 @@ pub(crate) async fn get_key_changes_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); let mut device_list_updates = HashSet::new(); diff --git a/src/api/client/media.rs b/src/api/client/media.rs index 11d5450c..3f491d54 100644 --- a/src/api/client/media.rs +++ b/src/api/client/media.rs @@ -51,7 +51,7 @@ pub(crate) async fn create_content_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - let user = body.sender_user.as_ref().expect("user is authenticated"); + let user = body.sender_user(); if services.users.is_suspended(user).await? { return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); } @@ -97,7 +97,7 @@ pub(crate) async fn get_content_thumbnail_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - let user = body.sender_user.as_ref().expect("user is authenticated"); + let user = body.sender_user(); let dim = Dim::from_ruma(body.width, body.height, body.method.clone())?; let mxc = Mxc { @@ -134,7 +134,7 @@ pub(crate) async fn get_content_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - let user = body.sender_user.as_ref().expect("user is authenticated"); + let user = body.sender_user(); let mxc = Mxc { server_name: &body.server_name, @@ -170,7 +170,7 @@ pub(crate) async fn get_content_as_filename_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - let user = body.sender_user.as_ref().expect("user is authenticated"); + let user = body.sender_user(); let mxc = Mxc { server_name: &body.server_name, @@ -206,7 +206,7 @@ pub(crate) async fn get_media_preview_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); let url = &body.url; let url = Url::parse(&body.url).map_err(|e| { diff --git a/src/api/client/media_legacy.rs b/src/api/client/media_legacy.rs index d9f24f77..930daab4 100644 --- a/src/api/client/media_legacy.rs +++ b/src/api/client/media_legacy.rs @@ -55,7 +55,7 @@ pub(crate) async fn get_media_preview_legacy_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); let url = &body.url; let url = Url::parse(&body.url).map_err(|e| { diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs index e6392533..b5356b94 100644 --- a/src/api/client/membership.rs +++ b/src/api/client/membership.rs @@ -249,14 +249,14 @@ pub(crate) async fn join_room_by_id_or_alias_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_deref().expect("user is authenticated"); + let sender_user = body.sender_user(); let appservice_info = &body.appservice_info; - let body = body.body; + let body = &body.body; if services.users.is_suspended(sender_user).await? { return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); } - let (servers, room_id) = match OwnedRoomId::try_from(body.room_id_or_alias) { + let (servers, room_id) = match OwnedRoomId::try_from(body.room_id_or_alias.clone()) { | Ok(room_id) => { banned_room_check( &services, diff --git a/src/api/client/openid.rs b/src/api/client/openid.rs index 8d2de68d..e27b3ab8 100644 --- a/src/api/client/openid.rs +++ b/src/api/client/openid.rs @@ -19,9 +19,9 @@ pub(crate) async fn create_openid_token_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); - if sender_user != &body.user_id { + if sender_user != body.user_id { return Err(Error::BadRequest( ErrorKind::InvalidParam, "Not allowed to request OpenID tokens on behalf of other users", diff --git a/src/api/client/profile.rs b/src/api/client/profile.rs index bdba4078..76b5dc6d 100644 --- a/src/api/client/profile.rs +++ b/src/api/client/profile.rs @@ -35,7 +35,7 @@ pub(crate) async fn set_displayname_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if services.users.is_suspended(sender_user).await? { return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); } @@ -127,7 +127,7 @@ pub(crate) async fn set_avatar_url_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if services.users.is_suspended(sender_user).await? { return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); } diff --git a/src/api/client/push.rs b/src/api/client/push.rs index 81020ffa..125b26bb 100644 --- a/src/api/client/push.rs +++ b/src/api/client/push.rs @@ -106,7 +106,7 @@ pub(crate) async fn get_pushrules_global_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); let Some(content_value) = services .account_data @@ -234,9 +234,8 @@ pub(crate) async fn set_pushrule_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let body = body.body; - + let sender_user = body.sender_user(); + let body = &body.body; let mut account_data: PushRulesEvent = services .account_data .get_global(sender_user, GlobalAccountDataEventType::PushRules) @@ -295,7 +294,7 @@ pub(crate) async fn get_pushrule_actions_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); // remove old deprecated mentions push rules as per MSC4210 #[allow(deprecated)] @@ -329,7 +328,7 @@ pub(crate) async fn set_pushrule_actions_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); let mut account_data: PushRulesEvent = services .account_data @@ -366,7 +365,7 @@ pub(crate) async fn get_pushrule_enabled_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); // remove old deprecated mentions push rules as per MSC4210 #[allow(deprecated)] @@ -400,7 +399,7 @@ pub(crate) async fn set_pushrule_enabled_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); let mut account_data: PushRulesEvent = services .account_data @@ -437,7 +436,7 @@ pub(crate) async fn delete_pushrule_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); let mut account_data: PushRulesEvent = services .account_data @@ -483,7 +482,7 @@ pub(crate) async fn get_pushers_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); Ok(get_pushers::v3::Response { pushers: services.pusher.get_pushers(sender_user).await, @@ -499,7 +498,7 @@ pub(crate) async fn set_pushers_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); services .pusher diff --git a/src/api/client/redact.rs b/src/api/client/redact.rs index a8eaf91d..86d871ff 100644 --- a/src/api/client/redact.rs +++ b/src/api/client/redact.rs @@ -15,8 +15,8 @@ pub(crate) async fn redact_event_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let body = body.body; + let sender_user = body.sender_user(); + let body = &body.body; if services.users.is_suspended(sender_user).await? { // TODO: Users can redact their own messages while suspended return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); diff --git a/src/api/client/report.rs b/src/api/client/report.rs index 5113b42f..8ece3ab1 100644 --- a/src/api/client/report.rs +++ b/src/api/client/report.rs @@ -38,8 +38,7 @@ pub(crate) async fn report_room_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - // user authentication - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if services.users.is_suspended(sender_user).await? { return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); } @@ -94,7 +93,7 @@ pub(crate) async fn report_event_route( body: Ruma, ) -> Result { // user authentication - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if services.users.is_suspended(sender_user).await? { return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); } diff --git a/src/api/client/room/aliases.rs b/src/api/client/room/aliases.rs index 3f0016af..a944971c 100644 --- a/src/api/client/room/aliases.rs +++ b/src/api/client/room/aliases.rs @@ -15,7 +15,7 @@ pub(crate) async fn get_room_aliases_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if !services .rooms diff --git a/src/api/client/room/create.rs b/src/api/client/room/create.rs index d1dffc51..4ca64fd8 100644 --- a/src/api/client/room/create.rs +++ b/src/api/client/room/create.rs @@ -58,7 +58,7 @@ pub(crate) async fn create_room_route( ) -> Result { use create_room::v3::RoomPreset; - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if !services.globals.allow_room_creation() && body.appservice_info.is_none() @@ -174,7 +174,7 @@ pub(crate) async fn create_room_route( let content = match room_version { | V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => - RoomCreateEventContent::new_v1(sender_user.clone()), + RoomCreateEventContent::new_v1(sender_user.to_owned()), | _ => RoomCreateEventContent::new_v11(), }; let mut content = serde_json::from_str::( @@ -239,7 +239,7 @@ pub(crate) async fn create_room_route( | _ => RoomPreset::PrivateChat, // Room visibility should not be custom }); - let mut users = BTreeMap::from_iter([(sender_user.clone(), int!(100))]); + let mut users = BTreeMap::from_iter([(sender_user.to_owned(), int!(100))]); if preset == RoomPreset::TrustedPrivateChat { for invite in &body.invite { diff --git a/src/api/client/session.rs b/src/api/client/session.rs index 2499a43d..992073c6 100644 --- a/src/api/client/session.rs +++ b/src/api/client/session.rs @@ -269,11 +269,9 @@ pub(crate) async fn login_token_route( return Err!(Request(Forbidden("Login via an existing session is not enabled"))); } - let sender_user = body.sender_user(); - let sender_device = body.sender_device(); - // This route SHOULD have UIA // TODO: How do we make only UIA sessions that have not been used before valid? + let (sender_user, sender_device) = body.sender(); let mut uiaainfo = uiaa::UiaaInfo { flows: vec![uiaa::AuthFlow { stages: vec![uiaa::AuthType::Password] }], @@ -335,12 +333,9 @@ pub(crate) async fn logout_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let sender_device = body.sender_device.as_ref().expect("user is authenticated"); - services .users - .remove_device(sender_user, sender_device) + .remove_device(body.sender_user(), body.sender_device()) .await; Ok(logout::v3::Response::new()) @@ -365,12 +360,10 @@ pub(crate) async fn logout_all_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - services .users - .all_device_ids(sender_user) - .for_each(|device_id| services.users.remove_device(sender_user, device_id)) + .all_device_ids(body.sender_user()) + .for_each(|device_id| services.users.remove_device(body.sender_user(), device_id)) .await; Ok(logout_all::v3::Response::new()) diff --git a/src/api/client/state.rs b/src/api/client/state.rs index 07802b1b..cf371728 100644 --- a/src/api/client/state.rs +++ b/src/api/client/state.rs @@ -77,7 +77,7 @@ pub(crate) async fn get_state_events_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if !services .rooms diff --git a/src/api/client/tag.rs b/src/api/client/tag.rs index caafe10d..dd799105 100644 --- a/src/api/client/tag.rs +++ b/src/api/client/tag.rs @@ -21,7 +21,7 @@ pub(crate) async fn update_tag_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); let mut tags_event = services .account_data @@ -58,7 +58,7 @@ pub(crate) async fn delete_tag_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); let mut tags_event = services .account_data @@ -92,7 +92,7 @@ pub(crate) async fn get_tags_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); let tags_event = services .account_data diff --git a/src/api/client/to_device.rs b/src/api/client/to_device.rs index 8ad9dc99..581f4a72 100644 --- a/src/api/client/to_device.rs +++ b/src/api/client/to_device.rs @@ -21,7 +21,7 @@ pub(crate) async fn send_event_to_device_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); let sender_device = body.sender_device.as_deref(); // Check if this is a new transaction id @@ -47,7 +47,7 @@ pub(crate) async fn send_event_to_device_route( serde_json::to_writer( &mut buf, &federation::transactions::edu::Edu::DirectToDevice(DirectDeviceContent { - sender: sender_user.clone(), + sender: sender_user.to_owned(), ev_type: body.event_type.clone(), message_id: count.to_string().into(), messages, diff --git a/src/api/client/unstable.rs b/src/api/client/unstable.rs index e21eaf21..08f70975 100644 --- a/src/api/client/unstable.rs +++ b/src/api/client/unstable.rs @@ -69,7 +69,7 @@ pub(crate) async fn delete_timezone_key_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if *sender_user != body.user_id && body.appservice_info.is_none() { return Err!(Request(Forbidden("You cannot update the profile of another user"))); @@ -97,7 +97,7 @@ pub(crate) async fn set_timezone_key_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if *sender_user != body.user_id && body.appservice_info.is_none() { return Err!(Request(Forbidden("You cannot update the profile of another user"))); @@ -125,7 +125,7 @@ pub(crate) async fn set_profile_key_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if *sender_user != body.user_id && body.appservice_info.is_none() { return Err!(Request(Forbidden("You cannot update the profile of another user"))); @@ -218,7 +218,7 @@ pub(crate) async fn delete_profile_key_route( State(services): State, body: Ruma, ) -> Result { - let sender_user = body.sender_user.as_ref().expect("user is authenticated"); + let sender_user = body.sender_user(); if *sender_user != body.user_id && body.appservice_info.is_none() { return Err!(Request(Forbidden("You cannot update the profile of another user"))); From 2051c22a281b6daeda252e75c1332d26edd6f48f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 28 Apr 2025 01:32:13 +0000 Subject: [PATCH 2092/2291] Support optional device_id's in lazy-loading context. Co-authored-by: Jade Ellis Signed-off-by: Jason Volk --- src/api/client/context.rs | 2 +- src/api/client/message.rs | 28 +++++++++++++-------------- src/api/client/sync/v3.rs | 2 +- src/service/rooms/lazy_loading/mod.rs | 4 ++-- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/api/client/context.rs b/src/api/client/context.rs index dbc2a22f..ca787a16 100644 --- a/src/api/client/context.rs +++ b/src/api/client/context.rs @@ -111,7 +111,7 @@ pub(crate) async fn get_context_route( let lazy_loading_context = lazy_loading::Context { user_id: sender_user, - device_id: sender_device, + device_id: Some(sender_device), room_id, token: Some(base_count.into_unsigned()), options: Some(&filter.lazy_load_options), diff --git a/src/api/client/message.rs b/src/api/client/message.rs index e442850b..7a87a9b0 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -1,5 +1,3 @@ -use core::panic; - use axum::extract::State; use conduwuit::{ Err, Result, at, @@ -34,6 +32,7 @@ use ruma::{ }, serde::Raw, }; +use tracing::warn; use crate::Ruma; @@ -73,7 +72,7 @@ pub(crate) async fn get_message_events_route( ) -> Result { debug_assert!(IGNORED_MESSAGE_TYPES.is_sorted(), "IGNORED_MESSAGE_TYPES is not sorted"); let sender_user = body.sender_user(); - let sender_device = body.sender_device.as_ref(); + let sender_device = body.sender_device.as_deref(); let room_id = &body.room_id; let filter = &body.filter; @@ -137,18 +136,17 @@ pub(crate) async fn get_message_events_route( let lazy_loading_context = lazy_loading::Context { user_id: sender_user, - device_id: match sender_device { - | Some(device_id) => device_id, - | None => - if let Some(registration) = body.appservice_info.as_ref() { - <&DeviceId>::from(registration.registration.id.as_str()) - } else { - panic!( - "No device_id provided and no appservice registration found, this \ - should be unreachable" - ); - }, - }, + device_id: sender_device.or_else(|| { + if let Some(registration) = body.appservice_info.as_ref() { + Some(<&DeviceId>::from(registration.registration.id.as_str())) + } else { + warn!( + "No device_id provided and no appservice registration found, this should be \ + unreachable" + ); + None + } + }), room_id, token: Some(from.into_unsigned()), options: Some(&filter.lazy_load_options), diff --git a/src/api/client/sync/v3.rs b/src/api/client/sync/v3.rs index 7bc74c95..feaf8689 100644 --- a/src/api/client/sync/v3.rs +++ b/src/api/client/sync/v3.rs @@ -645,7 +645,7 @@ async fn load_joined_room( let lazy_loading_context = &lazy_loading::Context { user_id: sender_user, - device_id: sender_device, + device_id: Some(sender_device), room_id, token: Some(since), options: Some(&filter.room.state.lazy_load_options), diff --git a/src/service/rooms/lazy_loading/mod.rs b/src/service/rooms/lazy_loading/mod.rs index 346314d1..61f081a9 100644 --- a/src/service/rooms/lazy_loading/mod.rs +++ b/src/service/rooms/lazy_loading/mod.rs @@ -27,7 +27,7 @@ pub trait Options: Send + Sync { #[derive(Clone, Debug)] pub struct Context<'a> { pub user_id: &'a UserId, - pub device_id: &'a DeviceId, + pub device_id: Option<&'a DeviceId>, pub room_id: &'a RoomId, pub token: Option, pub options: Option<&'a LazyLoadOptions>, @@ -40,7 +40,7 @@ pub enum Status { } pub type Witness = HashSet; -type Key<'a> = (&'a UserId, &'a DeviceId, &'a RoomId, &'a UserId); +type Key<'a> = (&'a UserId, Option<&'a DeviceId>, &'a RoomId, &'a UserId); impl crate::Service for Service { fn build(args: crate::Args<'_>) -> Result> { From f3dd90df39da1d5ff1e4aabc150990efe5e64f5e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 26 Apr 2025 08:23:57 +0000 Subject: [PATCH 2093/2291] Mitigate large futures Signed-off-by: Jason Volk --- src/admin/room/moderation.rs | 12 +++++++++--- src/admin/user/commands.rs | 6 ++++-- src/api/client/account.rs | 6 ++++-- src/api/client/membership.rs | 12 +++++++++--- src/api/client/state.rs | 3 ++- src/service/admin/mod.rs | 3 +-- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/admin/room/moderation.rs b/src/admin/room/moderation.rs index 921249bd..5fb5bb3e 100644 --- a/src/admin/room/moderation.rs +++ b/src/admin/room/moderation.rs @@ -5,7 +5,7 @@ use conduwuit::{ utils::{IterStream, ReadyExt}, warn, }; -use futures::StreamExt; +use futures::{FutureExt, StreamExt}; use ruma::{OwnedRoomId, OwnedRoomOrAliasId, RoomAliasId, RoomId, RoomOrAliasId}; use crate::{admin_command, admin_command_dispatch, get_room_info}; @@ -132,7 +132,10 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result { evicting admins too)", ); - if let Err(e) = leave_room(self.services, user_id, &room_id, None).await { + if let Err(e) = leave_room(self.services, user_id, &room_id, None) + .boxed() + .await + { warn!("Failed to leave room: {e}"); } @@ -297,7 +300,10 @@ async fn ban_list_of_rooms(&self) -> Result { evicting admins too)", ); - if let Err(e) = leave_room(self.services, user_id, &room_id, None).await { + if let Err(e) = leave_room(self.services, user_id, &room_id, None) + .boxed() + .await + { warn!("Failed to leave room: {e}"); } diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index d094fc5f..89f7a9fc 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -8,7 +8,7 @@ use conduwuit::{ warn, }; use conduwuit_api::client::{leave_all_rooms, update_avatar_url, update_displayname}; -use futures::StreamExt; +use futures::{FutureExt, StreamExt}; use ruma::{ OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedUserId, UserId, events::{ @@ -696,7 +696,9 @@ pub(super) async fn force_leave_room( return Err!("{user_id} is not joined in the room"); } - leave_room(self.services, &user_id, &room_id, None).await?; + leave_room(self.services, &user_id, &room_id, None) + .boxed() + .await?; self.write_str(&format!("{user_id} has left {room_id}.",)) .await diff --git a/src/api/client/account.rs b/src/api/client/account.rs index 30f8b89c..2e822f02 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -777,7 +777,9 @@ pub(crate) async fn deactivate_route( super::update_displayname(&services, sender_user, None, &all_joined_rooms).await; super::update_avatar_url(&services, sender_user, None, None, &all_joined_rooms).await; - full_user_deactivate(&services, sender_user, &all_joined_rooms).await?; + full_user_deactivate(&services, sender_user, &all_joined_rooms) + .boxed() + .await?; info!("User {sender_user} deactivated their account."); @@ -929,7 +931,7 @@ pub async fn full_user_deactivate( } } - super::leave_all_rooms(services, user_id).await; + super::leave_all_rooms(services, user_id).boxed().await; Ok(()) } diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs index b5356b94..85d0cd21 100644 --- a/src/api/client/membership.rs +++ b/src/api/client/membership.rs @@ -114,7 +114,9 @@ async fn banned_room_check( .collect() .await; - full_user_deactivate(services, user_id, &all_joined_rooms).await?; + full_user_deactivate(services, user_id, &all_joined_rooms) + .boxed() + .await?; } return Err!(Request(Forbidden("This room is banned on this homeserver."))); @@ -153,7 +155,9 @@ async fn banned_room_check( .collect() .await; - full_user_deactivate(services, user_id, &all_joined_rooms).await?; + full_user_deactivate(services, user_id, &all_joined_rooms) + .boxed() + .await?; } return Err!(Request(Forbidden("This remote server is banned on this homeserver."))); @@ -265,6 +269,7 @@ pub(crate) async fn join_room_by_id_or_alias_route( room_id.server_name(), client, ) + .boxed() .await?; let mut servers = body.via.clone(); @@ -487,6 +492,7 @@ pub(crate) async fn leave_room_route( body: Ruma, ) -> Result { leave_room(&services, body.sender_user(), &body.room_id, body.reason.clone()) + .boxed() .await .map(|()| leave_room::v3::Response::new()) } @@ -1825,7 +1831,7 @@ pub async fn leave_all_rooms(services: &Services, user_id: &UserId) { for room_id in all_rooms { // ignore errors - if let Err(e) = leave_room(services, user_id, &room_id, None).await { + if let Err(e) = leave_room(services, user_id, &room_id, None).boxed().await { warn!(%user_id, "Failed to leave {room_id} remotely: {e}"); } diff --git a/src/api/client/state.rs b/src/api/client/state.rs index cf371728..c0303200 100644 --- a/src/api/client/state.rs +++ b/src/api/client/state.rs @@ -5,7 +5,7 @@ use conduwuit::{ utils::BoolExt, }; use conduwuit_service::Services; -use futures::TryStreamExt; +use futures::{FutureExt, TryStreamExt}; use ruma::{ OwnedEventId, RoomId, UserId, api::client::state::{get_state_events, get_state_events_for_key, send_state_event}, @@ -63,6 +63,7 @@ pub(crate) async fn send_state_event_for_empty_key_route( body: Ruma, ) -> Result> { send_state_event_for_key_route(State(services), body) + .boxed() .await .map(RumaResponse) } diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 11d93cc2..19a523ca 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -4,7 +4,6 @@ mod execute; mod grant; use std::{ - future::Future, pin::Pin, sync::{Arc, RwLock as StdRwLock, Weak}, }; @@ -14,7 +13,7 @@ use conduwuit::{ Error, PduEvent, Result, Server, debug, err, error, error::default_log, pdu::PduBuilder, }; pub use create::create_admin_room; -use futures::{FutureExt, TryFutureExt}; +use futures::{Future, FutureExt, TryFutureExt}; use loole::{Receiver, Sender}; use ruma::{ OwnedEventId, OwnedRoomId, RoomId, UserId, From 732a77f3a8f1e02c6a436604792c5377ff4d4bf9 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 26 Apr 2025 23:01:21 +0000 Subject: [PATCH 2094/2291] Use integrated error instead of panic on some legacy codepaths Signed-off-by: Jason Volk --- src/api/client/account.rs | 6 +-- src/api/client/capabilities.rs | 16 +++---- src/api/client/push.rs | 86 ++++++++++++---------------------- src/api/client/read_marker.rs | 4 +- src/api/client/room/create.rs | 22 +++------ src/api/client/tag.rs | 4 +- 6 files changed, 49 insertions(+), 89 deletions(-) diff --git a/src/api/client/account.rs b/src/api/client/account.rs index 2e822f02..b6ff0f2b 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -351,8 +351,7 @@ pub(crate) async fn register_route( if !services.globals.new_user_displayname_suffix().is_empty() && body.appservice_info.is_none() { - write!(displayname, " {}", services.server.config.new_user_displayname_suffix) - .expect("should be able to write to string buffer"); + write!(displayname, " {}", services.server.config.new_user_displayname_suffix)?; } services @@ -370,8 +369,7 @@ pub(crate) async fn register_route( content: ruma::events::push_rules::PushRulesEventContent { global: push::Ruleset::server_default(&user_id), }, - }) - .expect("to json always works"), + })?, ) .await?; diff --git a/src/api/client/capabilities.rs b/src/api/client/capabilities.rs index 7362c4f9..c42c6dfd 100644 --- a/src/api/client/capabilities.rs +++ b/src/api/client/capabilities.rs @@ -26,8 +26,8 @@ pub(crate) async fn get_capabilities_route( let mut capabilities = Capabilities::default(); capabilities.room_versions = RoomVersionsCapability { - default: services.server.config.default_room_version.clone(), available, + default: services.server.config.default_room_version.clone(), }; // we do not implement 3PID stuff @@ -38,16 +38,12 @@ pub(crate) async fn get_capabilities_route( }; // MSC4133 capability - capabilities - .set("uk.tcpip.msc4133.profile_fields", json!({"enabled": true})) - .expect("this is valid JSON we created"); + capabilities.set("uk.tcpip.msc4133.profile_fields", json!({"enabled": true}))?; - capabilities - .set( - "org.matrix.msc4267.forget_forced_upon_leave", - json!({"enabled": services.config.forget_forced_upon_leave}), - ) - .expect("valid JSON we created"); + capabilities.set( + "org.matrix.msc4267.forget_forced_upon_leave", + json!({"enabled": services.config.forget_forced_upon_leave}), + )?; Ok(get_capabilities::v3::Response { capabilities }) } diff --git a/src/api/client/push.rs b/src/api/client/push.rs index 125b26bb..74e29422 100644 --- a/src/api/client/push.rs +++ b/src/api/client/push.rs @@ -79,17 +79,14 @@ pub(crate) async fn get_pushrules_all_route( global_ruleset.update_with_server_default(Ruleset::server_default(sender_user)); + let ty = GlobalAccountDataEventType::PushRules; + let event = PushRulesEvent { + content: PushRulesEventContent { global: global_ruleset.clone() }, + }; + services .account_data - .update( - None, - sender_user, - GlobalAccountDataEventType::PushRules.to_string().into(), - &serde_json::to_value(PushRulesEvent { - content: PushRulesEventContent { global: global_ruleset.clone() }, - }) - .expect("to json always works"), - ) + .update(None, sender_user, ty.to_string().into(), &serde_json::to_value(event)?) .await?; } }; @@ -118,19 +115,17 @@ pub(crate) async fn get_pushrules_global_route( else { // user somehow has non-existent push rule event. recreate it and return server // default silently + + let ty = GlobalAccountDataEventType::PushRules; + let event = PushRulesEvent { + content: PushRulesEventContent { + global: Ruleset::server_default(sender_user), + }, + }; + services .account_data - .update( - None, - sender_user, - GlobalAccountDataEventType::PushRules.to_string().into(), - &serde_json::to_value(PushRulesEvent { - content: PushRulesEventContent { - global: Ruleset::server_default(sender_user), - }, - }) - .expect("to json always works"), - ) + .update(None, sender_user, ty.to_string().into(), &serde_json::to_value(event)?) .await?; return Ok(get_pushrules_global_scope::v3::Response { @@ -274,14 +269,10 @@ pub(crate) async fn set_pushrule_route( return Err(err); } + let ty = GlobalAccountDataEventType::PushRules; services .account_data - .update( - None, - sender_user, - GlobalAccountDataEventType::PushRules.to_string().into(), - &serde_json::to_value(account_data).expect("to json value always works"), - ) + .update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?) .await?; Ok(set_pushrule::v3::Response {}) @@ -345,14 +336,10 @@ pub(crate) async fn set_pushrule_actions_route( return Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found.")); } + let ty = GlobalAccountDataEventType::PushRules; services .account_data - .update( - None, - sender_user, - GlobalAccountDataEventType::PushRules.to_string().into(), - &serde_json::to_value(account_data).expect("to json value always works"), - ) + .update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?) .await?; Ok(set_pushrule_actions::v3::Response {}) @@ -416,14 +403,10 @@ pub(crate) async fn set_pushrule_enabled_route( return Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found.")); } + let ty = GlobalAccountDataEventType::PushRules; services .account_data - .update( - None, - sender_user, - GlobalAccountDataEventType::PushRules.to_string().into(), - &serde_json::to_value(account_data).expect("to json value always works"), - ) + .update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?) .await?; Ok(set_pushrule_enabled::v3::Response {}) @@ -462,14 +445,10 @@ pub(crate) async fn delete_pushrule_route( return Err(err); } + let ty = GlobalAccountDataEventType::PushRules; services .account_data - .update( - None, - sender_user, - GlobalAccountDataEventType::PushRules.to_string().into(), - &serde_json::to_value(account_data).expect("to json value always works"), - ) + .update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?) .await?; Ok(delete_pushrule::v3::Response {}) @@ -514,19 +493,16 @@ async fn recreate_push_rules_and_return( services: &Services, sender_user: &ruma::UserId, ) -> Result { + let ty = GlobalAccountDataEventType::PushRules; + let event = PushRulesEvent { + content: PushRulesEventContent { + global: Ruleset::server_default(sender_user), + }, + }; + services .account_data - .update( - None, - sender_user, - GlobalAccountDataEventType::PushRules.to_string().into(), - &serde_json::to_value(PushRulesEvent { - content: PushRulesEventContent { - global: Ruleset::server_default(sender_user), - }, - }) - .expect("to json always works"), - ) + .update(None, sender_user, ty.to_string().into(), &serde_json::to_value(event)?) .await?; Ok(get_pushrules_all::v3::Response { diff --git a/src/api/client/read_marker.rs b/src/api/client/read_marker.rs index e152869c..9d813294 100644 --- a/src/api/client/read_marker.rs +++ b/src/api/client/read_marker.rs @@ -37,7 +37,7 @@ pub(crate) async fn set_read_marker_route( Some(&body.room_id), sender_user, RoomAccountDataEventType::FullyRead, - &serde_json::to_value(fully_read_event).expect("to json value always works"), + &serde_json::to_value(fully_read_event)?, ) .await?; } @@ -151,7 +151,7 @@ pub(crate) async fn create_receipt_route( Some(&body.room_id), sender_user, RoomAccountDataEventType::FullyRead, - &serde_json::to_value(fully_read_event).expect("to json value always works"), + &serde_json::to_value(fully_read_event)?, ) .await?; }, diff --git a/src/api/client/room/create.rs b/src/api/client/room/create.rs index 4ca64fd8..aa54e1e9 100644 --- a/src/api/client/room/create.rs +++ b/src/api/client/room/create.rs @@ -177,18 +177,10 @@ pub(crate) async fn create_room_route( RoomCreateEventContent::new_v1(sender_user.to_owned()), | _ => RoomCreateEventContent::new_v11(), }; - let mut content = serde_json::from_str::( - to_raw_value(&content) - .expect("we just created this as content was None") - .get(), - ) - .unwrap(); - content.insert( - "room_version".into(), - json!(room_version.as_str()) - .try_into() - .expect("we just created this as content was None"), - ); + let mut content = + serde_json::from_str::(to_raw_value(&content)?.get()) + .unwrap(); + content.insert("room_version".into(), json!(room_version.as_str()).try_into()?); content }, }; @@ -200,8 +192,7 @@ pub(crate) async fn create_room_route( .build_and_append_pdu( PduBuilder { event_type: TimelineEventType::RoomCreate, - content: to_raw_value(&create_content) - .expect("create event content serialization"), + content: to_raw_value(&create_content)?, state_key: Some(StateKey::new()), ..Default::default() }, @@ -267,8 +258,7 @@ pub(crate) async fn create_room_route( .build_and_append_pdu( PduBuilder { event_type: TimelineEventType::RoomPowerLevels, - content: to_raw_value(&power_levels_content) - .expect("serialized power_levels event content"), + content: to_raw_value(&power_levels_content)?, state_key: Some(StateKey::new()), ..Default::default() }, diff --git a/src/api/client/tag.rs b/src/api/client/tag.rs index dd799105..68105e4f 100644 --- a/src/api/client/tag.rs +++ b/src/api/client/tag.rs @@ -42,7 +42,7 @@ pub(crate) async fn update_tag_route( Some(&body.room_id), sender_user, RoomAccountDataEventType::Tag, - &serde_json::to_value(tags_event).expect("to json value always works"), + &serde_json::to_value(tags_event)?, ) .await?; @@ -76,7 +76,7 @@ pub(crate) async fn delete_tag_route( Some(&body.room_id), sender_user, RoomAccountDataEventType::Tag, - &serde_json::to_value(tags_event).expect("to json value always works"), + &serde_json::to_value(tags_event)?, ) .await?; From 21bbee8e3cd7c982e2fbc38aeebf8f387da05165 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 26 Apr 2025 23:04:58 +0000 Subject: [PATCH 2095/2291] Simplify api to send notices to admin room Signed-off-by: Jason Volk --- src/api/client/account.rs | 60 +++++++++++------------------------ src/api/client/room/create.rs | 14 ++++---- src/service/admin/mod.rs | 7 ++++ 3 files changed, 32 insertions(+), 49 deletions(-) diff --git a/src/api/client/account.rs b/src/api/client/account.rs index b6ff0f2b..27d93bef 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -26,10 +26,7 @@ use ruma::{ }, events::{ GlobalAccountDataEventType, StateEventType, - room::{ - message::RoomMessageEventContent, - power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent}, - }, + room::power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent}, }, push, }; @@ -414,32 +411,21 @@ pub(crate) async fn register_route( // log in conduit admin channel if a non-guest user registered if body.appservice_info.is_none() && !is_guest { if !device_display_name.is_empty() { - info!( - "New user \"{user_id}\" registered on this server with device display name: \ - \"{device_display_name}\"" + let notice = format!( + "New user \"{user_id}\" registered on this server from IP {client} and device \ + display name \"{device_display_name}\"" ); + info!("{notice}"); if services.server.config.admin_room_notices { - services - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "New user \"{user_id}\" registered on this server from IP {client} and \ - device display name \"{device_display_name}\"" - ))) - .await - .ok(); + services.admin.notice(¬ice).await; } } else { - info!("New user \"{user_id}\" registered on this server."); + let notice = format!("New user \"{user_id}\" registered on this server."); + info!("{notice}"); if services.server.config.admin_room_notices { - services - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "New user \"{user_id}\" registered on this server from IP {client}" - ))) - .await - .ok(); + services.admin.notice(¬ice).await; } } } @@ -452,24 +438,22 @@ pub(crate) async fn register_route( if services.server.config.admin_room_notices { services .admin - .send_message(RoomMessageEventContent::notice_plain(format!( + .notice(&format!( "Guest user \"{user_id}\" with device display name \ \"{device_display_name}\" registered on this server from IP {client}" - ))) - .await - .ok(); + )) + .await; } } else { #[allow(clippy::collapsible_else_if)] if services.server.config.admin_room_notices { services .admin - .send_message(RoomMessageEventContent::notice_plain(format!( + .notice(&format!( "Guest user \"{user_id}\" with no device display name registered on \ this server from IP {client}", - ))) - .await - .ok(); + )) + .await; } } } @@ -677,11 +661,8 @@ pub(crate) async fn change_password_route( if services.server.config.admin_room_notices { services .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "User {sender_user} changed their password." - ))) - .await - .ok(); + .notice(&format!("User {sender_user} changed their password.")) + .await; } Ok(change_password::v3::Response {}) @@ -784,11 +765,8 @@ pub(crate) async fn deactivate_route( if services.server.config.admin_room_notices { services .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "User {sender_user} deactivated their account." - ))) - .await - .ok(); + .notice(&format!("User {sender_user} deactivated their account.")) + .await; } Ok(deactivate::v3::Response { diff --git a/src/api/client/room/create.rs b/src/api/client/room/create.rs index aa54e1e9..8b93fcfd 100644 --- a/src/api/client/room/create.rs +++ b/src/api/client/room/create.rs @@ -92,19 +92,17 @@ pub(crate) async fn create_room_route( && !services.users.is_admin(sender_user).await && body.appservice_info.is_none() { - info!( - "Non-admin user {sender_user} tried to publish {0} to the room directory while \ - \"lockdown_public_room_directory\" is enabled", - &room_id + warn!( + "Non-admin user {sender_user} tried to publish {room_id} to the room directory \ + while \"lockdown_public_room_directory\" is enabled" ); if services.server.config.admin_room_notices { services .admin - .send_text(&format!( - "Non-admin user {sender_user} tried to publish {0} to the room directory \ - while \"lockdown_public_room_directory\" is enabled", - &room_id + .notice(&format!( + "Non-admin user {sender_user} tried to publish {room_id} to the room \ + directory while \"lockdown_public_room_directory\" is enabled" )) .await; } diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 19a523ca..a76c3ef6 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -142,6 +142,13 @@ impl crate::Service for Service { } impl Service { + /// Sends markdown notice to the admin room as the admin user. + pub async fn notice(&self, body: &str) { + self.send_message(RoomMessageEventContent::notice_markdown(body)) + .await + .ok(); + } + /// Sends markdown message (not an m.notice for notification reasons) to the /// admin room as the admin user. pub async fn send_text(&self, body: &str) { From 667afedd24d40db1d63fa052dbd55e872b493225 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 26 Apr 2025 23:50:03 +0000 Subject: [PATCH 2096/2291] Macroize various remaining Error constructions. Signed-off-by: Jason Volk --- src/api/client/account.rs | 16 +-- src/api/client/openid.rs | 13 +-- src/api/client/profile.rs | 15 ++- src/api/client/push.rs | 6 +- src/api/client/report.rs | 32 ++---- src/api/client/room/aliases.rs | 9 +- src/api/client/room/create.rs | 100 ++++++++---------- src/api/server/invite.rs | 2 +- .../rooms/event_handler/handle_outlier_pdu.rs | 10 +- 9 files changed, 78 insertions(+), 125 deletions(-) diff --git a/src/api/client/account.rs b/src/api/client/account.rs index 27d93bef..14bbcf98 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -13,22 +13,14 @@ use conduwuit_service::Services; use futures::{FutureExt, StreamExt}; use register::RegistrationKind; use ruma::{ - OwnedRoomId, UserId, api::client::{ account::{ - ThirdPartyIdRemovalStatus, change_password, check_registration_token_validity, - deactivate, get_3pids, get_username_availability, - register::{self, LoginType}, - request_3pid_management_token_via_email, request_3pid_management_token_via_msisdn, - whoami, + change_password, check_registration_token_validity, deactivate, get_3pids, get_username_availability, register::{self, LoginType}, request_3pid_management_token_via_email, request_3pid_management_token_via_msisdn, whoami, ThirdPartyIdRemovalStatus }, uiaa::{AuthFlow, AuthType, UiaaInfo}, - }, - events::{ - GlobalAccountDataEventType, StateEventType, - room::power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent}, - }, - push, + }, events::{ + room::{message::RoomMessageEventContent, power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent}}, GlobalAccountDataEventType, StateEventType + }, push, OwnedRoomId, UserId }; use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH, join_room_by_id_helper}; diff --git a/src/api/client/openid.rs b/src/api/client/openid.rs index e27b3ab8..0390b4b3 100644 --- a/src/api/client/openid.rs +++ b/src/api/client/openid.rs @@ -1,11 +1,8 @@ use std::time::Duration; use axum::extract::State; -use conduwuit::{Error, Result, utils}; -use ruma::{ - api::client::{account, error::ErrorKind}, - authentication::TokenType, -}; +use conduwuit::{Err, Result, utils}; +use ruma::{api::client::account, authentication::TokenType}; use super::TOKEN_LENGTH; use crate::Ruma; @@ -22,14 +19,12 @@ pub(crate) async fn create_openid_token_route( let sender_user = body.sender_user(); if sender_user != body.user_id { - return Err(Error::BadRequest( - ErrorKind::InvalidParam, + return Err!(Request(InvalidParam( "Not allowed to request OpenID tokens on behalf of other users", - )); + ))); } let access_token = utils::random_string(TOKEN_LENGTH); - let expires_in = services .users .create_openid_token(&body.user_id, &access_token)?; diff --git a/src/api/client/profile.rs b/src/api/client/profile.rs index 76b5dc6d..6efad64e 100644 --- a/src/api/client/profile.rs +++ b/src/api/client/profile.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use axum::extract::State; use conduwuit::{ - Err, Error, Result, + Err, Result, matrix::pdu::PduBuilder, utils::{IterStream, stream::TryIgnore}, warn, @@ -12,11 +12,8 @@ use futures::{StreamExt, TryStreamExt, future::join3}; use ruma::{ OwnedMxcUri, OwnedRoomId, UserId, api::{ - client::{ - error::ErrorKind, - profile::{ - get_avatar_url, get_display_name, get_profile, set_avatar_url, set_display_name, - }, + client::profile::{ + get_avatar_url, get_display_name, get_profile, set_avatar_url, set_display_name, }, federation, }, @@ -110,7 +107,7 @@ pub(crate) async fn get_displayname_route( if !services.users.exists(&body.user_id).await { // Return 404 if this user doesn't exist and we couldn't fetch it over // federation - return Err(Error::BadRequest(ErrorKind::NotFound, "Profile was not found.")); + return Err!(Request(NotFound("Profile was not found."))); } Ok(get_display_name::v3::Response { @@ -214,7 +211,7 @@ pub(crate) async fn get_avatar_url_route( if !services.users.exists(&body.user_id).await { // Return 404 if this user doesn't exist and we couldn't fetch it over // federation - return Err(Error::BadRequest(ErrorKind::NotFound, "Profile was not found.")); + return Err!(Request(NotFound("Profile was not found."))); } Ok(get_avatar_url::v3::Response { @@ -287,7 +284,7 @@ pub(crate) async fn get_profile_route( if !services.users.exists(&body.user_id).await { // Return 404 if this user doesn't exist and we couldn't fetch it over // federation - return Err(Error::BadRequest(ErrorKind::NotFound, "Profile was not found.")); + return Err!(Request(NotFound("Profile was not found."))); } let mut custom_profile_fields: BTreeMap = services diff --git a/src/api/client/push.rs b/src/api/client/push.rs index 74e29422..d8d84ec7 100644 --- a/src/api/client/push.rs +++ b/src/api/client/push.rs @@ -218,7 +218,7 @@ pub(crate) async fn get_pushrule_route( if let Some(rule) = rule { Ok(get_pushrule::v3::Response { rule }) } else { - Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found.")) + Err!(Request(NotFound("Push rule not found."))) } } @@ -333,7 +333,7 @@ pub(crate) async fn set_pushrule_actions_route( .set_actions(body.kind.clone(), &body.rule_id, body.actions.clone()) .is_err() { - return Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found.")); + return Err!(Request(NotFound("Push rule not found."))); } let ty = GlobalAccountDataEventType::PushRules; @@ -400,7 +400,7 @@ pub(crate) async fn set_pushrule_enabled_route( .set_enabled(body.kind.clone(), &body.rule_id, body.enabled) .is_err() { - return Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found.")); + return Err!(Request(NotFound("Push rule not found."))); } let ty = GlobalAccountDataEventType::PushRules; diff --git a/src/api/client/report.rs b/src/api/client/report.rs index 8ece3ab1..1019b358 100644 --- a/src/api/client/report.rs +++ b/src/api/client/report.rs @@ -2,7 +2,7 @@ use std::{fmt::Write as _, ops::Mul, time::Duration}; use axum::extract::State; use axum_client_ip::InsecureClientIp; -use conduwuit::{Err, Error, Result, debug_info, info, matrix::pdu::PduEvent, utils::ReadyExt}; +use conduwuit::{Err, Result, debug_info, info, matrix::pdu::PduEvent, utils::ReadyExt}; use conduwuit_service::Services; use rand::Rng; use ruma::{ @@ -44,9 +44,8 @@ pub(crate) async fn report_room_route( } if body.reason.as_ref().is_some_and(|s| s.len() > 750) { - return Err(Error::BadRequest( - ErrorKind::InvalidParam, - "Reason too long, should be 750 characters or fewer", + return Err!(Request( + InvalidParam("Reason too long, should be 750 characters or fewer",) )); } @@ -149,9 +148,8 @@ pub(crate) async fn report_user_route( } if body.reason.as_ref().is_some_and(|s| s.len() > 750) { - return Err(Error::BadRequest( - ErrorKind::InvalidParam, - "Reason too long, should be 750 characters or fewer", + return Err!(Request( + InvalidParam("Reason too long, should be 750 characters or fewer",) )); } @@ -204,23 +202,16 @@ async fn is_event_report_valid( ); if room_id != pdu.room_id { - return Err(Error::BadRequest( - ErrorKind::NotFound, - "Event ID does not belong to the reported room", - )); + return Err!(Request(NotFound("Event ID does not belong to the reported room",))); } if score.is_some_and(|s| s > int!(0) || s < int!(-100)) { - return Err(Error::BadRequest( - ErrorKind::InvalidParam, - "Invalid score, must be within 0 to -100", - )); + return Err!(Request(InvalidParam("Invalid score, must be within 0 to -100",))); } if reason.as_ref().is_some_and(|s| s.len() > 750) { - return Err(Error::BadRequest( - ErrorKind::InvalidParam, - "Reason too long, should be 750 characters or fewer", + return Err!(Request( + InvalidParam("Reason too long, should be 750 characters or fewer",) )); } @@ -231,10 +222,7 @@ async fn is_event_report_valid( .ready_any(|user_id| user_id == sender_user) .await { - return Err(Error::BadRequest( - ErrorKind::NotFound, - "You are not in the room you are reporting.", - )); + return Err!(Request(NotFound("You are not in the room you are reporting.",))); } Ok(()) diff --git a/src/api/client/room/aliases.rs b/src/api/client/room/aliases.rs index a944971c..0b072b74 100644 --- a/src/api/client/room/aliases.rs +++ b/src/api/client/room/aliases.rs @@ -1,7 +1,7 @@ use axum::extract::State; -use conduwuit::{Error, Result}; +use conduwuit::{Err, Result}; use futures::StreamExt; -use ruma::api::client::{error::ErrorKind, room::aliases}; +use ruma::api::client::room::aliases; use crate::Ruma; @@ -23,10 +23,7 @@ pub(crate) async fn get_room_aliases_route( .user_can_see_state_events(sender_user, &body.room_id) .await { - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "You don't have permission to view this room.", - )); + return Err!(Request(Forbidden("You don't have permission to view this room.",))); } Ok(aliases::v3::Response { diff --git a/src/api/client/room/create.rs b/src/api/client/room/create.rs index 8b93fcfd..238691d1 100644 --- a/src/api/client/room/create.rs +++ b/src/api/client/room/create.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use axum::extract::State; use conduwuit::{ - Err, Error, Result, debug_info, debug_warn, err, error, info, + Err, Result, debug_info, debug_warn, err, info, matrix::{StateKey, pdu::PduBuilder}, warn, }; @@ -10,10 +10,7 @@ use conduwuit_service::{Services, appservice::RegistrationInfo}; use futures::FutureExt; use ruma::{ CanonicalJsonObject, Int, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomId, RoomVersionId, - api::client::{ - error::ErrorKind, - room::{self, create_room}, - }, + api::client::room::{self, create_room}, events::{ TimelineEventType, room::{ @@ -64,10 +61,7 @@ pub(crate) async fn create_room_route( && body.appservice_info.is_none() && !services.users.is_admin(sender_user).await { - return Err(Error::BadRequest( - ErrorKind::forbidden(), - "Room creation has been disabled.", - )); + return Err!(Request(Forbidden("Room creation has been disabled.",))); } if services.users.is_suspended(sender_user).await? { @@ -81,10 +75,7 @@ pub(crate) async fn create_room_route( // check if room ID doesn't already exist instead of erroring on auth check if services.rooms.short.get_shortroomid(&room_id).await.is_ok() { - return Err(Error::BadRequest( - ErrorKind::RoomInUse, - "Room with that custom room ID already exists", - )); + return Err!(Request(RoomInUse("Room with that custom room ID already exists",))); } if body.visibility == room::Visibility::Public @@ -127,10 +118,9 @@ pub(crate) async fn create_room_route( if services.server.supported_room_version(&room_version) { room_version } else { - return Err(Error::BadRequest( - ErrorKind::UnsupportedRoomVersion, - "This server does not support that room version.", - )); + return Err!(Request(UnsupportedRoomVersion( + "This server does not support that room version." + ))); }, | None => services.server.config.default_room_version.clone(), }; @@ -142,16 +132,17 @@ pub(crate) async fn create_room_route( let mut content = content .deserialize_as::() .map_err(|e| { - error!("Failed to deserialise content as canonical JSON: {}", e); - Error::bad_database("Failed to deserialise content as canonical JSON.") + err!(Request(BadJson(error!( + "Failed to deserialise content as canonical JSON: {e}" + )))) })?; + match room_version { | V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => { content.insert( "creator".into(), json!(&sender_user).try_into().map_err(|e| { - info!("Invalid creation content: {e}"); - Error::BadRequest(ErrorKind::BadJson, "Invalid creation content") + err!(Request(BadJson(debug_error!("Invalid creation content: {e}")))) })?, ); }, @@ -161,9 +152,9 @@ pub(crate) async fn create_room_route( } content.insert( "room_version".into(), - json!(room_version.as_str()).try_into().map_err(|_| { - Error::BadRequest(ErrorKind::BadJson, "Invalid creation content") - })?, + json!(room_version.as_str()) + .try_into() + .map_err(|e| err!(Request(BadJson("Invalid creation content: {e}"))))?, ); content }, @@ -345,8 +336,7 @@ pub(crate) async fn create_room_route( // 6. Events listed in initial_state for event in &body.initial_state { let mut pdu_builder = event.deserialize_as::().map_err(|e| { - warn!("Invalid initial state event: {:?}", e); - Error::BadRequest(ErrorKind::InvalidParam, "Invalid initial state event.") + err!(Request(InvalidParam(warn!("Invalid initial state event: {e:?}")))) })?; debug_info!("Room creation initial state event: {event:?}"); @@ -355,7 +345,7 @@ pub(crate) async fn create_room_route( // state event in there with the content of literally `{}` (not null or empty // string), let's just skip it over and warn. if pdu_builder.content.get().eq("{}") { - info!("skipping empty initial state event with content of `{{}}`: {event:?}"); + debug_warn!("skipping empty initial state event with content of `{{}}`: {event:?}"); debug_warn!("content: {}", pdu_builder.content.get()); continue; } @@ -502,9 +492,7 @@ fn default_power_levels_content( if let Some(power_level_content_override) = power_level_content_override { let json: JsonObject = serde_json::from_str(power_level_content_override.json().get()) - .map_err(|_| { - Error::BadRequest(ErrorKind::BadJson, "Invalid power_level_content_override.") - })?; + .map_err(|e| err!(Request(BadJson("Invalid power_level_content_override: {e:?}"))))?; for (key, value) in json { power_levels_content[key] = value; @@ -522,16 +510,14 @@ async fn room_alias_check( ) -> Result { // Basic checks on the room alias validity if room_alias_name.contains(':') { - return Err(Error::BadRequest( - ErrorKind::InvalidParam, + return Err!(Request(InvalidParam( "Room alias contained `:` which is not allowed. Please note that this expects a \ localpart, not the full room alias.", - )); + ))); } else if room_alias_name.contains(char::is_whitespace) { - return Err(Error::BadRequest( - ErrorKind::InvalidParam, + return Err!(Request(InvalidParam( "Room alias contained spaces which is not a valid room alias.", - )); + ))); } // check if room alias is forbidden @@ -540,7 +526,7 @@ async fn room_alias_check( .forbidden_alias_names() .is_match(room_alias_name) { - return Err(Error::BadRequest(ErrorKind::Unknown, "Room alias name is forbidden.")); + return Err!(Request(Unknown("Room alias name is forbidden."))); } let server_name = services.globals.server_name(); @@ -560,25 +546,19 @@ async fn room_alias_check( .await .is_ok() { - return Err(Error::BadRequest(ErrorKind::RoomInUse, "Room alias already exists.")); + return Err!(Request(RoomInUse("Room alias already exists."))); } if let Some(info) = appservice_info { if !info.aliases.is_match(full_room_alias.as_str()) { - return Err(Error::BadRequest( - ErrorKind::Exclusive, - "Room alias is not in namespace.", - )); + return Err!(Request(Exclusive("Room alias is not in namespace."))); } } else if services .appservice .is_exclusive_alias(&full_room_alias) .await { - return Err(Error::BadRequest( - ErrorKind::Exclusive, - "Room alias reserved by appservice.", - )); + return Err!(Request(Exclusive("Room alias reserved by appservice.",))); } debug_info!("Full room alias: {full_room_alias}"); @@ -594,24 +574,33 @@ fn custom_room_id_check(services: &Services, custom_room_id: &str) -> Result Result( v.insert(auth_event); }, | hash_map::Entry::Occupied(_) => { - return Err(Error::BadRequest( - ErrorKind::InvalidParam, + return Err!(Request(InvalidParam( "Auth event's type and state_key combination exists multiple times.", - )); + ))); }, } } From 3d0360bcd65ad8842120f305dfd1905e36868099 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 27 Apr 2025 00:17:39 +0000 Subject: [PATCH 2097/2291] Dedup and parallelize current key backup count and etag fetching. Signed-off-by: Jason Volk --- src/api/client/backup.rs | 134 +++++++++++++-------------------------- 1 file changed, 43 insertions(+), 91 deletions(-) diff --git a/src/api/client/backup.rs b/src/api/client/backup.rs index 2ad37cf3..a3038f26 100644 --- a/src/api/client/backup.rs +++ b/src/api/client/backup.rs @@ -2,8 +2,10 @@ use std::cmp::Ordering; use axum::extract::State; use conduwuit::{Err, Result, err}; +use conduwuit_service::Services; +use futures::{FutureExt, future::try_join}; use ruma::{ - UInt, + UInt, UserId, api::client::backup::{ add_backup_keys, add_backup_keys_for_room, add_backup_keys_for_session, create_backup_version, delete_backup_keys, delete_backup_keys_for_room, @@ -58,21 +60,9 @@ pub(crate) async fn get_latest_backup_info_route( .await .map_err(|_| err!(Request(NotFound("Key backup does not exist."))))?; - Ok(get_latest_backup_info::v3::Response { - algorithm, - count: (UInt::try_from( - services - .key_backups - .count_keys(body.sender_user(), &version) - .await, - ) - .expect("user backup keys count should not be that high")), - etag: services - .key_backups - .get_etag(body.sender_user(), &version) - .await, - version, - }) + let (count, etag) = get_count_etag(&services, body.sender_user(), &version).await?; + + Ok(get_latest_backup_info::v3::Response { algorithm, count, etag, version }) } /// # `GET /_matrix/client/v3/room_keys/version/{version}` @@ -90,17 +80,12 @@ pub(crate) async fn get_backup_info_route( err!(Request(NotFound("Key backup does not exist at version {:?}", body.version))) })?; + let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?; + Ok(get_backup_info::v3::Response { algorithm, - count: services - .key_backups - .count_keys(body.sender_user(), &body.version) - .await - .try_into()?, - etag: services - .key_backups - .get_etag(body.sender_user(), &body.version) - .await, + count, + etag, version: body.version.clone(), }) } @@ -155,17 +140,9 @@ pub(crate) async fn add_backup_keys_route( } } - Ok(add_backup_keys::v3::Response { - count: services - .key_backups - .count_keys(body.sender_user(), &body.version) - .await - .try_into()?, - etag: services - .key_backups - .get_etag(body.sender_user(), &body.version) - .await, - }) + let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?; + + Ok(add_backup_keys::v3::Response { count, etag }) } /// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}` @@ -198,17 +175,9 @@ pub(crate) async fn add_backup_keys_for_room_route( .await?; } - Ok(add_backup_keys_for_room::v3::Response { - count: services - .key_backups - .count_keys(body.sender_user(), &body.version) - .await - .try_into()?, - etag: services - .key_backups - .get_etag(body.sender_user(), &body.version) - .await, - }) + let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?; + + Ok(add_backup_keys_for_room::v3::Response { count, etag }) } /// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}` @@ -306,17 +275,9 @@ pub(crate) async fn add_backup_keys_for_session_route( .await?; } - Ok(add_backup_keys_for_session::v3::Response { - count: services - .key_backups - .count_keys(body.sender_user(), &body.version) - .await - .try_into()?, - etag: services - .key_backups - .get_etag(body.sender_user(), &body.version) - .await, - }) + let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?; + + Ok(add_backup_keys_for_session::v3::Response { count, etag }) } /// # `GET /_matrix/client/r0/room_keys/keys` @@ -379,17 +340,9 @@ pub(crate) async fn delete_backup_keys_route( .delete_all_keys(body.sender_user(), &body.version) .await; - Ok(delete_backup_keys::v3::Response { - count: services - .key_backups - .count_keys(body.sender_user(), &body.version) - .await - .try_into()?, - etag: services - .key_backups - .get_etag(body.sender_user(), &body.version) - .await, - }) + let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?; + + Ok(delete_backup_keys::v3::Response { count, etag }) } /// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}` @@ -404,17 +357,9 @@ pub(crate) async fn delete_backup_keys_for_room_route( .delete_room_keys(body.sender_user(), &body.version, &body.room_id) .await; - Ok(delete_backup_keys_for_room::v3::Response { - count: services - .key_backups - .count_keys(body.sender_user(), &body.version) - .await - .try_into()?, - etag: services - .key_backups - .get_etag(body.sender_user(), &body.version) - .await, - }) + let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?; + + Ok(delete_backup_keys_for_room::v3::Response { count, etag }) } /// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}` @@ -429,15 +374,22 @@ pub(crate) async fn delete_backup_keys_for_session_route( .delete_room_key(body.sender_user(), &body.version, &body.room_id, &body.session_id) .await; - Ok(delete_backup_keys_for_session::v3::Response { - count: services - .key_backups - .count_keys(body.sender_user(), &body.version) - .await - .try_into()?, - etag: services - .key_backups - .get_etag(body.sender_user(), &body.version) - .await, - }) + let (count, etag) = get_count_etag(&services, body.sender_user(), &body.version).await?; + + Ok(delete_backup_keys_for_session::v3::Response { count, etag }) +} + +async fn get_count_etag( + services: &Services, + sender_user: &UserId, + version: &str, +) -> Result<(UInt, String)> { + let count = services + .key_backups + .count_keys(sender_user, version) + .map(TryInto::try_into); + + let etag = services.key_backups.get_etag(sender_user, version).map(Ok); + + Ok(try_join(count, etag).await?) } From 116f85360fa17b16e8e9353b20be5e21dc87e2de Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 26 Apr 2025 08:24:47 +0000 Subject: [PATCH 2098/2291] Toward abstracting Pdu into trait Event. Co-authored-by: Jade Ellis Signed-off-by: Jason Volk --- src/admin/debug/commands.rs | 11 +- src/admin/user/commands.rs | 8 +- src/api/client/context.rs | 12 +- src/api/client/membership.rs | 5 +- src/api/client/message.rs | 4 +- src/api/client/relations.rs | 4 +- src/api/client/room/event.rs | 2 +- src/api/client/room/initial_sync.rs | 6 +- src/api/client/search.rs | 6 +- src/api/client/state.rs | 18 +- src/api/client/sync/v3.rs | 13 +- src/api/client/sync/v4.rs | 7 +- src/api/client/sync/v5.rs | 12 +- src/api/client/threads.rs | 7 +- src/api/server/invite.rs | 7 +- src/core/matrix/event.rs | 141 +++++++--- src/core/matrix/event/content.rs | 21 ++ src/core/matrix/event/format.rs | 219 +++++++++++++++ src/core/matrix/event/redact.rs | 86 ++++++ src/core/matrix/event/type_ext.rs | 32 +++ src/core/matrix/mod.rs | 8 +- src/core/matrix/pdu.rs | 123 +++++++-- src/core/matrix/pdu/id.rs | 1 + src/core/matrix/pdu/redact.rs | 116 +------- src/core/matrix/pdu/strip.rs | 257 ------------------ src/core/matrix/{pdu => }/state_key.rs | 3 - src/core/matrix/state_res/benches.rs | 167 ++---------- src/core/matrix/state_res/event_auth.rs | 61 +++-- src/core/matrix/state_res/mod.rs | 29 +- src/core/matrix/state_res/test_utils.rs | 192 +++---------- src/core/mod.rs | 4 +- src/service/admin/mod.rs | 21 +- src/service/pusher/mod.rs | 56 ++-- .../rooms/event_handler/handle_outlier_pdu.rs | 2 +- .../event_handler/upgrade_outlier_pdu.rs | 4 +- src/service/rooms/search/mod.rs | 4 +- src/service/rooms/spaces/mod.rs | 8 +- src/service/rooms/state/mod.rs | 22 +- src/service/rooms/threads/mod.rs | 16 +- src/service/rooms/timeline/mod.rs | 7 +- src/service/sending/sender.rs | 6 +- 41 files changed, 842 insertions(+), 886 deletions(-) create mode 100644 src/core/matrix/event/content.rs create mode 100644 src/core/matrix/event/format.rs create mode 100644 src/core/matrix/event/redact.rs create mode 100644 src/core/matrix/event/type_ext.rs delete mode 100644 src/core/matrix/pdu/strip.rs rename src/core/matrix/{pdu => }/state_key.rs (67%) diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index a397e0fc..2323e3b8 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -7,7 +7,10 @@ use std::{ use conduwuit::{ Err, Result, debug_error, err, info, - matrix::pdu::{PduEvent, PduId, RawPduId}, + matrix::{ + Event, + pdu::{PduEvent, PduId, RawPduId}, + }, trace, utils, utils::{ stream::{IterStream, ReadyExt}, @@ -19,7 +22,7 @@ use futures::{FutureExt, StreamExt, TryStreamExt}; use ruma::{ CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, RoomId, RoomVersionId, - api::federation::event::get_room_state, + api::federation::event::get_room_state, events::AnyStateEvent, serde::Raw, }; use service::rooms::{ short::{ShortEventId, ShortRoomId}, @@ -296,12 +299,12 @@ pub(super) async fn get_remote_pdu( #[admin_command] pub(super) async fn get_room_state(&self, room: OwnedRoomOrAliasId) -> Result { let room_id = self.services.rooms.alias.resolve(&room).await?; - let room_state: Vec<_> = self + let room_state: Vec> = self .services .rooms .state_accessor .room_state_full_pdus(&room_id) - .map_ok(PduEvent::into_state_event) + .map_ok(Event::into_format) .try_collect() .await?; diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 89f7a9fc..3750d758 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -1,13 +1,15 @@ use std::{collections::BTreeMap, fmt::Write as _}; -use api::client::{full_user_deactivate, join_room_by_id_helper, leave_room}; +use api::client::{ + full_user_deactivate, join_room_by_id_helper, leave_all_rooms, leave_room, update_avatar_url, + update_displayname, +}; use conduwuit::{ Err, Result, debug, debug_warn, error, info, is_equal_to, - matrix::pdu::PduBuilder, + matrix::{Event, pdu::PduBuilder}, utils::{self, ReadyExt}, warn, }; -use conduwuit_api::client::{leave_all_rooms, update_avatar_url, update_displayname}; use futures::{FutureExt, StreamExt}; use ruma::{ OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedUserId, UserId, diff --git a/src/api/client/context.rs b/src/api/client/context.rs index ca787a16..4a7d34d2 100644 --- a/src/api/client/context.rs +++ b/src/api/client/context.rs @@ -1,8 +1,6 @@ use axum::extract::State; use conduwuit::{ - Err, Result, at, debug_warn, err, - matrix::pdu::PduEvent, - ref_at, + Err, Event, Result, at, debug_warn, err, ref_at, utils::{ IterStream, future::TryExtExt, @@ -179,12 +177,12 @@ pub(crate) async fn get_context_route( .broad_filter_map(|event_id: &OwnedEventId| { services.rooms.timeline.get_pdu(event_id.as_ref()).ok() }) - .map(PduEvent::into_state_event) + .map(Event::into_format) .collect() .await; Ok(get_context::v3::Response { - event: base_event.map(at!(1)).map(PduEvent::into_room_event), + event: base_event.map(at!(1)).map(Event::into_format), start: events_before .last() @@ -203,13 +201,13 @@ pub(crate) async fn get_context_route( events_before: events_before .into_iter() .map(at!(1)) - .map(PduEvent::into_room_event) + .map(Event::into_format) .collect(), events_after: events_after .into_iter() .map(at!(1)) - .map(PduEvent::into_room_event) + .map(Event::into_format) .collect(), state, diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs index 85d0cd21..3c2a6fe3 100644 --- a/src/api/client/membership.rs +++ b/src/api/client/membership.rs @@ -9,7 +9,8 @@ use std::{ use axum::extract::State; use axum_client_ip::InsecureClientIp; use conduwuit::{ - Err, Result, at, debug, debug_error, debug_info, debug_warn, err, error, info, is_matching, + Err, Event, Result, at, debug, debug_error, debug_info, debug_warn, err, error, info, + is_matching, matrix::{ StateKey, pdu::{PduBuilder, PduEvent, gen_event_id, gen_event_id_canonical_json}, @@ -880,7 +881,7 @@ pub(crate) async fn get_member_events_route( .ready_filter(|((ty, _), _)| *ty == StateEventType::RoomMember) .map(at!(1)) .ready_filter_map(|pdu| membership_filter(pdu, membership, not_membership)) - .map(PduEvent::into_member_event) + .map(Event::into_format) .collect() .await, }) diff --git a/src/api/client/message.rs b/src/api/client/message.rs index 7a87a9b0..e32d020f 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -175,7 +175,7 @@ pub(crate) async fn get_message_events_route( let chunk = events .into_iter() .map(at!(1)) - .map(PduEvent::into_room_event) + .map(Event::into_format) .collect(); Ok(get_message_events::v3::Response { @@ -241,7 +241,7 @@ async fn get_member_event( .rooms .state_accessor .room_state_get(room_id, &StateEventType::RoomMember, user_id.as_str()) - .map_ok(PduEvent::into_state_event) + .map_ok(Event::into_format) .await .ok() } diff --git a/src/api/client/relations.rs b/src/api/client/relations.rs index b8c2dd4d..ad726b90 100644 --- a/src/api/client/relations.rs +++ b/src/api/client/relations.rs @@ -1,7 +1,7 @@ use axum::extract::State; use conduwuit::{ Result, at, - matrix::pdu::PduCount, + matrix::{Event, pdu::PduCount}, utils::{IterStream, ReadyExt, result::FlatOk, stream::WidebandExt}, }; use conduwuit_service::{Services, rooms::timeline::PdusIterItem}; @@ -167,7 +167,7 @@ async fn paginate_relations_with_filter( chunk: events .into_iter() .map(at!(1)) - .map(|pdu| pdu.to_message_like_event()) + .map(Event::into_format) .collect(), }) } diff --git a/src/api/client/room/event.rs b/src/api/client/room/event.rs index 2b115b5c..47228d67 100644 --- a/src/api/client/room/event.rs +++ b/src/api/client/room/event.rs @@ -40,5 +40,5 @@ pub(crate) async fn get_room_event_route( event.add_age().ok(); - Ok(get_room_event::v3::Response { event: event.into_room_event() }) + Ok(get_room_event::v3::Response { event: event.into_format() }) } diff --git a/src/api/client/room/initial_sync.rs b/src/api/client/room/initial_sync.rs index ca63610b..8b9f3ca0 100644 --- a/src/api/client/room/initial_sync.rs +++ b/src/api/client/room/initial_sync.rs @@ -1,6 +1,6 @@ use axum::extract::State; use conduwuit::{ - Err, PduEvent, Result, at, + Err, Event, Result, at, utils::{BoolExt, stream::TryTools}, }; use futures::TryStreamExt; @@ -38,7 +38,7 @@ pub(crate) async fn room_initial_sync_route( .rooms .state_accessor .room_state_full_pdus(room_id) - .map_ok(PduEvent::into_state_event) + .map_ok(Event::into_format) .try_collect() .await?; @@ -55,7 +55,7 @@ pub(crate) async fn room_initial_sync_route( chunk: events .into_iter() .map(at!(1)) - .map(PduEvent::into_room_event) + .map(Event::into_format) .collect(), }; diff --git a/src/api/client/search.rs b/src/api/client/search.rs index d4dcde57..cc745694 100644 --- a/src/api/client/search.rs +++ b/src/api/client/search.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use axum::extract::State; use conduwuit::{ Err, Result, at, is_true, - matrix::pdu::PduEvent, + matrix::Event, result::FlatOk, utils::{IterStream, stream::ReadyExt}, }; @@ -144,7 +144,7 @@ async fn category_room_events( .map(at!(2)) .flatten() .stream() - .map(PduEvent::into_room_event) + .map(Event::into_format) .map(|result| SearchResult { rank: None, result: Some(result), @@ -185,7 +185,7 @@ async fn procure_room_state(services: &Services, room_id: &RoomId) -> Result>(); let account_data_events = services @@ -877,10 +875,7 @@ async fn load_joined_room( events: room_events, }, state: RoomState { - events: state_events - .into_iter() - .map(PduEvent::into_sync_state_event) - .collect(), + events: state_events.into_iter().map(Event::into_format).collect(), }, ephemeral: Ephemeral { events: edus }, unread_thread_notifications: BTreeMap::new(), diff --git a/src/api/client/sync/v4.rs b/src/api/client/sync/v4.rs index f153b2da..cabd67e4 100644 --- a/src/api/client/sync/v4.rs +++ b/src/api/client/sync/v4.rs @@ -6,7 +6,7 @@ use std::{ use axum::extract::State; use conduwuit::{ - Err, Error, PduCount, PduEvent, Result, debug, error, extract_variant, + Err, Error, Event, PduCount, PduEvent, Result, at, debug, error, extract_variant, matrix::TypeStateKey, utils::{ BoolExt, IterStream, ReadyExt, TryFutureExtExt, @@ -604,7 +604,8 @@ pub(crate) async fn sync_events_v4_route( .iter() .stream() .filter_map(|item| ignored_filter(&services, item.clone(), sender_user)) - .map(|(_, pdu)| pdu.to_sync_room_event()) + .map(at!(1)) + .map(Event::into_format) .collect() .await; @@ -626,7 +627,7 @@ pub(crate) async fn sync_events_v4_route( .state_accessor .room_state_get(room_id, &state.0, &state.1) .await - .map(PduEvent::into_sync_state_event) + .map(PduEvent::into_format) .ok() }) .collect() diff --git a/src/api/client/sync/v5.rs b/src/api/client/sync/v5.rs index f3fc0f44..e4cefba0 100644 --- a/src/api/client/sync/v5.rs +++ b/src/api/client/sync/v5.rs @@ -7,11 +7,8 @@ use std::{ use axum::extract::State; use conduwuit::{ - Err, Error, Result, error, extract_variant, is_equal_to, - matrix::{ - TypeStateKey, - pdu::{PduCount, PduEvent}, - }, + Err, Error, Result, at, error, extract_variant, is_equal_to, + matrix::{Event, TypeStateKey, pdu::PduCount}, trace, utils::{ BoolExt, FutureBoolExt, IterStream, ReadyExt, TryFutureExtExt, @@ -515,7 +512,8 @@ where .iter() .stream() .filter_map(|item| ignored_filter(services, item.clone(), sender_user)) - .map(|(_, pdu)| pdu.to_sync_room_event()) + .map(at!(1)) + .map(Event::into_format) .collect() .await; @@ -537,7 +535,7 @@ where .state_accessor .room_state_get(room_id, &state.0, &state.1) .await - .map(PduEvent::into_sync_state_event) + .map(Event::into_format) .ok() }) .collect() diff --git a/src/api/client/threads.rs b/src/api/client/threads.rs index 5b838bef..ca176eda 100644 --- a/src/api/client/threads.rs +++ b/src/api/client/threads.rs @@ -1,7 +1,10 @@ use axum::extract::State; use conduwuit::{ Result, at, - matrix::pdu::{PduCount, PduEvent}, + matrix::{ + Event, + pdu::{PduCount, PduEvent}, + }, }; use futures::StreamExt; use ruma::{api::client::threads::get_threads, uint}; @@ -56,7 +59,7 @@ pub(crate) async fn get_threads_route( chunk: threads .into_iter() .map(at!(1)) - .map(PduEvent::into_room_event) + .map(Event::into_format) .collect(), }) } diff --git a/src/api/server/invite.rs b/src/api/server/invite.rs index 01961378..0d26d787 100644 --- a/src/api/server/invite.rs +++ b/src/api/server/invite.rs @@ -2,7 +2,8 @@ use axum::extract::State; use axum_client_ip::InsecureClientIp; use base64::{Engine as _, engine::general_purpose}; use conduwuit::{ - Err, Error, PduEvent, Result, err, pdu::gen_event_id, utils, utils::hash::sha256, warn, + Err, Error, PduEvent, Result, err, matrix::Event, pdu::gen_event_id, utils, + utils::hash::sha256, warn, }; use ruma::{ CanonicalJsonValue, OwnedUserId, UserId, @@ -111,7 +112,7 @@ pub(crate) async fn create_invite_route( let pdu: PduEvent = serde_json::from_value(event.into()) .map_err(|e| err!(Request(BadJson("Invalid invite event PDU: {e}"))))?; - invite_state.push(pdu.to_stripped_state_event()); + invite_state.push(pdu.to_format()); // If we are active in the room, the remote server will notify us about the // join/invite through /send. If we are not in the room, we need to manually @@ -144,7 +145,7 @@ pub(crate) async fn create_invite_route( .send_appservice_request( appservice.registration.clone(), ruma::api::appservice::event::push_events::v1::Request { - events: vec![pdu.to_room_event()], + events: vec![pdu.to_format()], txn_id: general_purpose::URL_SAFE_NO_PAD .encode(sha256::hash(pdu.event_id.as_bytes())) .into(), diff --git a/src/core/matrix/event.rs b/src/core/matrix/event.rs index e4c478cd..5b12770b 100644 --- a/src/core/matrix/event.rs +++ b/src/core/matrix/event.rs @@ -1,63 +1,114 @@ -use ruma::{EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId, events::TimelineEventType}; -use serde_json::value::RawValue as RawJsonValue; +mod content; +mod format; +mod redact; +mod type_ext; + +use ruma::{ + EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, RoomVersionId, UserId, + events::TimelineEventType, +}; +use serde::Deserialize; +use serde_json::{Value as JsonValue, value::RawValue as RawJsonValue}; + +pub use self::type_ext::TypeExt; +use super::state_key::StateKey; +use crate::Result; /// Abstraction of a PDU so users can have their own PDU types. pub trait Event { + /// Serialize into a Ruma JSON format, consuming. + #[inline] + fn into_format(self) -> T + where + T: From>, + Self: Sized, + { + format::Owned(self).into() + } + + /// Serialize into a Ruma JSON format + #[inline] + fn to_format<'a, T>(&'a self) -> T + where + T: From>, + Self: Sized + 'a, + { + format::Ref(self).into() + } + + #[inline] + fn get_content_as_value(&self) -> JsonValue + where + Self: Sized, + { + content::as_value(self) + } + + #[inline] + fn get_content(&self) -> Result + where + for<'de> T: Deserialize<'de>, + Self: Sized, + { + content::get::(self) + } + + #[inline] + fn redacts_id(&self, room_version: &RoomVersionId) -> Option + where + Self: Sized, + { + redact::redacts_id(self, room_version) + } + + #[inline] + fn is_redacted(&self) -> bool + where + Self: Sized, + { + redact::is_redacted(self) + } + + fn is_owned(&self) -> bool; + + // + // Canonical properties + // + + /// All the authenticating events for this event. + fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_; + + /// The event's content. + fn content(&self) -> &RawJsonValue; + /// The `EventId` of this event. fn event_id(&self) -> &EventId; + /// The time of creation on the originating server. + fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch; + + /// The events before this event. + fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_; + + /// If this event is a redaction event this is the event it redacts. + fn redacts(&self) -> Option<&EventId>; + /// The `RoomId` of this event. fn room_id(&self) -> &RoomId; /// The `UserId` of this event. fn sender(&self) -> &UserId; - /// The time of creation on the originating server. - fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch; - - /// The event type. - fn event_type(&self) -> &TimelineEventType; - - /// The event's content. - fn content(&self) -> &RawJsonValue; - /// The state key for this event. fn state_key(&self) -> Option<&str>; - /// The events before this event. - // Requires GATs to avoid boxing (and TAIT for making it convenient). - fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_; + /// The event type. + fn kind(&self) -> &TimelineEventType; - /// All the authenticating events for this event. - // Requires GATs to avoid boxing (and TAIT for making it convenient). - fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_; + /// Metadata container; peer-trusted only. + fn unsigned(&self) -> Option<&RawJsonValue>; - /// If this event is a redaction event this is the event it redacts. - fn redacts(&self) -> Option<&EventId>; -} - -impl Event for &T { - fn event_id(&self) -> &EventId { (*self).event_id() } - - fn room_id(&self) -> &RoomId { (*self).room_id() } - - fn sender(&self) -> &UserId { (*self).sender() } - - fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { (*self).origin_server_ts() } - - fn event_type(&self) -> &TimelineEventType { (*self).event_type() } - - fn content(&self) -> &RawJsonValue { (*self).content() } - - fn state_key(&self) -> Option<&str> { (*self).state_key() } - - fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_ { - (*self).prev_events() - } - - fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_ { - (*self).auth_events() - } - - fn redacts(&self) -> Option<&EventId> { (*self).redacts() } + //#[deprecated] + #[inline] + fn event_type(&self) -> &TimelineEventType { self.kind() } } diff --git a/src/core/matrix/event/content.rs b/src/core/matrix/event/content.rs new file mode 100644 index 00000000..1ee7ebd2 --- /dev/null +++ b/src/core/matrix/event/content.rs @@ -0,0 +1,21 @@ +use serde::Deserialize; +use serde_json::value::Value as JsonValue; + +use super::Event; +use crate::{Result, err}; + +#[inline] +#[must_use] +pub(super) fn as_value(event: &E) -> JsonValue { + get(event).expect("Failed to represent Event content as JsonValue") +} + +#[inline] +pub(super) fn get(event: &E) -> Result +where + T: for<'de> Deserialize<'de>, + E: Event, +{ + serde_json::from_str(event.content().get()) + .map_err(|e| err!(Request(BadJson("Failed to deserialize content into type: {e}")))) +} diff --git a/src/core/matrix/event/format.rs b/src/core/matrix/event/format.rs new file mode 100644 index 00000000..988cf4f0 --- /dev/null +++ b/src/core/matrix/event/format.rs @@ -0,0 +1,219 @@ +use ruma::{ + events::{ + AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent, AnySyncStateEvent, + AnySyncTimelineEvent, AnyTimelineEvent, StateEvent, room::member::RoomMemberEventContent, + space::child::HierarchySpaceChildEvent, + }, + serde::Raw, +}; +use serde_json::json; + +use super::{Event, redact}; + +pub struct Owned(pub(super) E); + +pub struct Ref<'a, E: Event>(pub(super) &'a E); + +impl From> for Raw { + fn from(event: Owned) -> Self { Ref(&event.0).into() } +} + +impl<'a, E: Event> From> for Raw { + fn from(event: Ref<'a, E>) -> Self { + let event = event.0; + let (redacts, content) = redact::copy(event); + let mut json = json!({ + "content": content, + "event_id": event.event_id(), + "origin_server_ts": event.origin_server_ts(), + "sender": event.sender(), + "type": event.event_type(), + }); + + if let Some(redacts) = redacts { + json["redacts"] = json!(redacts); + } + if let Some(state_key) = event.state_key() { + json["state_key"] = json!(state_key); + } + if let Some(unsigned) = event.unsigned() { + json["unsigned"] = json!(unsigned); + } + + serde_json::from_value(json).expect("Failed to serialize Event value") + } +} + +impl From> for Raw { + fn from(event: Owned) -> Self { Ref(&event.0).into() } +} + +impl<'a, E: Event> From> for Raw { + fn from(event: Ref<'a, E>) -> Self { + let event = event.0; + let (redacts, content) = redact::copy(event); + let mut json = json!({ + "content": content, + "event_id": event.event_id(), + "origin_server_ts": event.origin_server_ts(), + "room_id": event.room_id(), + "sender": event.sender(), + "type": event.kind(), + }); + + if let Some(redacts) = redacts { + json["redacts"] = json!(redacts); + } + if let Some(state_key) = event.state_key() { + json["state_key"] = json!(state_key); + } + if let Some(unsigned) = event.unsigned() { + json["unsigned"] = json!(unsigned); + } + + serde_json::from_value(json).expect("Failed to serialize Event value") + } +} + +impl From> for Raw { + fn from(event: Owned) -> Self { Ref(&event.0).into() } +} + +impl<'a, E: Event> From> for Raw { + fn from(event: Ref<'a, E>) -> Self { + let event = event.0; + let (redacts, content) = redact::copy(event); + let mut json = json!({ + "content": content, + "event_id": event.event_id(), + "origin_server_ts": event.origin_server_ts(), + "room_id": event.room_id(), + "sender": event.sender(), + "type": event.kind(), + }); + + if let Some(redacts) = &redacts { + json["redacts"] = json!(redacts); + } + if let Some(state_key) = event.state_key() { + json["state_key"] = json!(state_key); + } + if let Some(unsigned) = event.unsigned() { + json["unsigned"] = json!(unsigned); + } + + serde_json::from_value(json).expect("Failed to serialize Event value") + } +} + +impl From> for Raw { + fn from(event: Owned) -> Self { Ref(&event.0).into() } +} + +impl<'a, E: Event> From> for Raw { + fn from(event: Ref<'a, E>) -> Self { + let event = event.0; + let mut json = json!({ + "content": event.content(), + "event_id": event.event_id(), + "origin_server_ts": event.origin_server_ts(), + "room_id": event.room_id(), + "sender": event.sender(), + "state_key": event.state_key(), + "type": event.kind(), + }); + + if let Some(unsigned) = event.unsigned() { + json["unsigned"] = json!(unsigned); + } + + serde_json::from_value(json).expect("Failed to serialize Event value") + } +} + +impl From> for Raw { + fn from(event: Owned) -> Self { Ref(&event.0).into() } +} + +impl<'a, E: Event> From> for Raw { + fn from(event: Ref<'a, E>) -> Self { + let event = event.0; + let mut json = json!({ + "content": event.content(), + "event_id": event.event_id(), + "origin_server_ts": event.origin_server_ts(), + "sender": event.sender(), + "state_key": event.state_key(), + "type": event.kind(), + }); + + if let Some(unsigned) = event.unsigned() { + json["unsigned"] = json!(unsigned); + } + + serde_json::from_value(json).expect("Failed to serialize Event value") + } +} + +impl From> for Raw { + fn from(event: Owned) -> Self { Ref(&event.0).into() } +} + +impl<'a, E: Event> From> for Raw { + fn from(event: Ref<'a, E>) -> Self { + let event = event.0; + let json = json!({ + "content": event.content(), + "sender": event.sender(), + "state_key": event.state_key(), + "type": event.kind(), + }); + + serde_json::from_value(json).expect("Failed to serialize Event value") + } +} + +impl From> for Raw { + fn from(event: Owned) -> Self { Ref(&event.0).into() } +} + +impl<'a, E: Event> From> for Raw { + fn from(event: Ref<'a, E>) -> Self { + let event = event.0; + let json = json!({ + "content": event.content(), + "origin_server_ts": event.origin_server_ts(), + "sender": event.sender(), + "state_key": event.state_key(), + "type": event.kind(), + }); + + serde_json::from_value(json).expect("Failed to serialize Event value") + } +} + +impl From> for Raw> { + fn from(event: Owned) -> Self { Ref(&event.0).into() } +} + +impl<'a, E: Event> From> for Raw> { + fn from(event: Ref<'a, E>) -> Self { + let event = event.0; + let mut json = json!({ + "content": event.content(), + "event_id": event.event_id(), + "origin_server_ts": event.origin_server_ts(), + "redacts": event.redacts(), + "room_id": event.room_id(), + "sender": event.sender(), + "state_key": event.state_key(), + "type": event.kind(), + }); + + if let Some(unsigned) = event.unsigned() { + json["unsigned"] = json!(unsigned); + } + + serde_json::from_value(json).expect("Failed to serialize Event value") + } +} diff --git a/src/core/matrix/event/redact.rs b/src/core/matrix/event/redact.rs new file mode 100644 index 00000000..5deac874 --- /dev/null +++ b/src/core/matrix/event/redact.rs @@ -0,0 +1,86 @@ +use ruma::{ + OwnedEventId, RoomVersionId, + events::{TimelineEventType, room::redaction::RoomRedactionEventContent}, +}; +use serde::Deserialize; +use serde_json::value::{RawValue as RawJsonValue, to_raw_value}; + +use super::Event; + +/// Copies the `redacts` property of the event to the `content` dict and +/// vice-versa. +/// +/// This follows the specification's +/// [recommendation](https://spec.matrix.org/v1.10/rooms/v11/#moving-the-redacts-property-of-mroomredaction-events-to-a-content-property): +/// +/// > For backwards-compatibility with older clients, servers should add a +/// > redacts property to the top level of m.room.redaction events in when +/// > serving such events over the Client-Server API. +/// +/// > For improved compatibility with newer clients, servers should add a +/// > redacts property to the content of m.room.redaction events in older +/// > room versions when serving such events over the Client-Server API. +#[must_use] +pub(super) fn copy(event: &E) -> (Option, Box) { + if *event.event_type() != TimelineEventType::RoomRedaction { + return (event.redacts().map(ToOwned::to_owned), event.content().to_owned()); + } + + let Ok(mut content) = event.get_content::() else { + return (event.redacts().map(ToOwned::to_owned), event.content().to_owned()); + }; + + if let Some(redacts) = content.redacts { + return (Some(redacts), event.content().to_owned()); + } + + if let Some(redacts) = event.redacts().map(ToOwned::to_owned) { + content.redacts = Some(redacts); + return ( + event.redacts().map(ToOwned::to_owned), + to_raw_value(&content).expect("Must be valid, we only added redacts field"), + ); + } + + (event.redacts().map(ToOwned::to_owned), event.content().to_owned()) +} + +#[must_use] +pub(super) fn is_redacted(event: &E) -> bool { + let Some(unsigned) = event.unsigned() else { + return false; + }; + + let Ok(unsigned) = ExtractRedactedBecause::deserialize(unsigned) else { + return false; + }; + + unsigned.redacted_because.is_some() +} + +#[must_use] +pub(super) fn redacts_id( + event: &E, + room_version: &RoomVersionId, +) -> Option { + use RoomVersionId::*; + + if *event.kind() != TimelineEventType::RoomRedaction { + return None; + } + + match *room_version { + | V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => + event.redacts().map(ToOwned::to_owned), + | _ => + event + .get_content::() + .ok()? + .redacts, + } +} + +#[derive(Deserialize)] +struct ExtractRedactedBecause { + redacted_because: Option, +} diff --git a/src/core/matrix/event/type_ext.rs b/src/core/matrix/event/type_ext.rs new file mode 100644 index 00000000..9b824d41 --- /dev/null +++ b/src/core/matrix/event/type_ext.rs @@ -0,0 +1,32 @@ +use ruma::events::{StateEventType, TimelineEventType}; + +use super::StateKey; + +/// Convenience trait for adding event type plus state key to state maps. +pub trait TypeExt { + fn with_state_key(self, state_key: impl Into) -> (StateEventType, StateKey); +} + +impl TypeExt for StateEventType { + fn with_state_key(self, state_key: impl Into) -> (StateEventType, StateKey) { + (self, state_key.into()) + } +} + +impl TypeExt for &StateEventType { + fn with_state_key(self, state_key: impl Into) -> (StateEventType, StateKey) { + (self.clone(), state_key.into()) + } +} + +impl TypeExt for TimelineEventType { + fn with_state_key(self, state_key: impl Into) -> (StateEventType, StateKey) { + (self.into(), state_key.into()) + } +} + +impl TypeExt for &TimelineEventType { + fn with_state_key(self, state_key: impl Into) -> (StateEventType, StateKey) { + (self.clone().into(), state_key.into()) + } +} diff --git a/src/core/matrix/mod.rs b/src/core/matrix/mod.rs index 8c978173..b38d4c9a 100644 --- a/src/core/matrix/mod.rs +++ b/src/core/matrix/mod.rs @@ -2,8 +2,10 @@ pub mod event; pub mod pdu; +pub mod state_key; pub mod state_res; -pub use event::Event; -pub use pdu::{PduBuilder, PduCount, PduEvent, PduId, RawPduId, StateKey}; -pub use state_res::{EventTypeExt, RoomVersion, StateMap, TypeStateKey}; +pub use event::{Event, TypeExt as EventTypeExt}; +pub use pdu::{Pdu, PduBuilder, PduCount, PduEvent, PduId, RawPduId, ShortId}; +pub use state_key::StateKey; +pub use state_res::{RoomVersion, StateMap, TypeStateKey}; diff --git a/src/core/matrix/pdu.rs b/src/core/matrix/pdu.rs index 188586bd..e64baeb8 100644 --- a/src/core/matrix/pdu.rs +++ b/src/core/matrix/pdu.rs @@ -7,8 +7,6 @@ mod id; mod raw_id; mod redact; mod relation; -mod state_key; -mod strip; #[cfg(test)] mod tests; mod unsigned; @@ -27,37 +25,50 @@ pub use self::{ builder::{Builder, Builder as PduBuilder}, count::Count, event_id::*, - id::*, + id::{ShortId, *}, raw_id::*, - state_key::{ShortStateKey, StateKey}, }; -use super::Event; +use super::{Event, StateKey}; use crate::Result; /// Persistent Data Unit (Event) #[derive(Clone, Deserialize, Serialize, Debug)] pub struct Pdu { pub event_id: OwnedEventId, + pub room_id: OwnedRoomId, + pub sender: OwnedUserId, + #[serde(skip_serializing_if = "Option::is_none")] pub origin: Option, + pub origin_server_ts: UInt, + #[serde(rename = "type")] pub kind: TimelineEventType, + pub content: Box, + #[serde(skip_serializing_if = "Option::is_none")] pub state_key: Option, + pub prev_events: Vec, + pub depth: UInt, + pub auth_events: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub redacts: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] pub unsigned: Option>, + pub hashes: EventHash, - #[serde(default, skip_serializing_if = "Option::is_none")] + // BTreeMap, BTreeMap> + #[serde(default, skip_serializing_if = "Option::is_none")] pub signatures: Option>, } @@ -79,31 +90,91 @@ impl Pdu { } impl Event for Pdu { - fn event_id(&self) -> &EventId { &self.event_id } - - fn room_id(&self) -> &RoomId { &self.room_id } - - fn sender(&self) -> &UserId { &self.sender } - - fn event_type(&self) -> &TimelineEventType { &self.kind } - - fn content(&self) -> &RawJsonValue { &self.content } - - fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { - MilliSecondsSinceUnixEpoch(self.origin_server_ts) - } - - fn state_key(&self) -> Option<&str> { self.state_key.as_deref() } - - fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_ { - self.prev_events.iter().map(AsRef::as_ref) - } - + #[inline] fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_ { self.auth_events.iter().map(AsRef::as_ref) } + #[inline] + fn content(&self) -> &RawJsonValue { &self.content } + + #[inline] + fn event_id(&self) -> &EventId { &self.event_id } + + #[inline] + fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { + MilliSecondsSinceUnixEpoch(self.origin_server_ts) + } + + #[inline] + fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_ { + self.prev_events.iter().map(AsRef::as_ref) + } + + #[inline] fn redacts(&self) -> Option<&EventId> { self.redacts.as_deref() } + + #[inline] + fn room_id(&self) -> &RoomId { &self.room_id } + + #[inline] + fn sender(&self) -> &UserId { &self.sender } + + #[inline] + fn state_key(&self) -> Option<&str> { self.state_key.as_deref() } + + #[inline] + fn kind(&self) -> &TimelineEventType { &self.kind } + + #[inline] + fn unsigned(&self) -> Option<&RawJsonValue> { self.unsigned.as_deref() } + + #[inline] + fn is_owned(&self) -> bool { true } +} + +impl Event for &Pdu { + #[inline] + fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_ { + self.auth_events.iter().map(AsRef::as_ref) + } + + #[inline] + fn content(&self) -> &RawJsonValue { &self.content } + + #[inline] + fn event_id(&self) -> &EventId { &self.event_id } + + #[inline] + fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { + MilliSecondsSinceUnixEpoch(self.origin_server_ts) + } + + #[inline] + fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_ { + self.prev_events.iter().map(AsRef::as_ref) + } + + #[inline] + fn redacts(&self) -> Option<&EventId> { self.redacts.as_deref() } + + #[inline] + fn room_id(&self) -> &RoomId { &self.room_id } + + #[inline] + fn sender(&self) -> &UserId { &self.sender } + + #[inline] + fn state_key(&self) -> Option<&str> { self.state_key.as_deref() } + + #[inline] + fn kind(&self) -> &TimelineEventType { &self.kind } + + #[inline] + fn unsigned(&self) -> Option<&RawJsonValue> { self.unsigned.as_deref() } + + #[inline] + fn is_owned(&self) -> bool { false } } /// Prevent derived equality which wouldn't limit itself to event_id diff --git a/src/core/matrix/pdu/id.rs b/src/core/matrix/pdu/id.rs index 0b23a29f..896d677b 100644 --- a/src/core/matrix/pdu/id.rs +++ b/src/core/matrix/pdu/id.rs @@ -3,6 +3,7 @@ use crate::utils::u64_from_u8x8; pub type ShortRoomId = ShortId; pub type ShortEventId = ShortId; +pub type ShortStateKey = ShortId; pub type ShortId = u64; #[derive(Clone, Copy, Debug, Eq, PartialEq)] diff --git a/src/core/matrix/pdu/redact.rs b/src/core/matrix/pdu/redact.rs index 409debfe..e6a03209 100644 --- a/src/core/matrix/pdu/redact.rs +++ b/src/core/matrix/pdu/redact.rs @@ -1,117 +1,29 @@ -use ruma::{ - OwnedEventId, RoomVersionId, - canonical_json::redact_content_in_place, - events::{TimelineEventType, room::redaction::RoomRedactionEventContent}, -}; -use serde::Deserialize; -use serde_json::{ - json, - value::{RawValue as RawJsonValue, to_raw_value}, -}; +use ruma::{RoomVersionId, canonical_json::redact_content_in_place}; +use serde_json::{json, value::to_raw_value}; -use crate::{Error, Result, implement}; - -#[derive(Deserialize)] -struct ExtractRedactedBecause { - redacted_because: Option, -} +use crate::{Error, Result, err, implement}; #[implement(super::Pdu)] pub fn redact(&mut self, room_version_id: &RoomVersionId, reason: &Self) -> Result { self.unsigned = None; let mut content = serde_json::from_str(self.content.get()) - .map_err(|_| Error::bad_database("PDU in db has invalid content."))?; + .map_err(|e| err!(Request(BadJson("Failed to deserialize content into type: {e}"))))?; redact_content_in_place(&mut content, room_version_id, self.kind.to_string()) .map_err(|e| Error::Redaction(self.sender.server_name().to_owned(), e))?; - self.unsigned = Some( - to_raw_value(&json!({ - "redacted_because": serde_json::to_value(reason).expect("to_value(Pdu) always works") - })) - .expect("to string always works"), - ); + let reason = serde_json::to_value(reason).expect("Failed to preserialize reason"); - self.content = to_raw_value(&content).expect("to string always works"); + let redacted_because = json!({ + "redacted_because": reason, + }); + + self.unsigned = to_raw_value(&redacted_because) + .expect("Failed to serialize unsigned") + .into(); + + self.content = to_raw_value(&content).expect("Failed to serialize content"); Ok(()) } - -#[implement(super::Pdu)] -#[must_use] -pub fn is_redacted(&self) -> bool { - let Some(unsigned) = &self.unsigned else { - return false; - }; - - let Ok(unsigned) = ExtractRedactedBecause::deserialize(&**unsigned) else { - return false; - }; - - unsigned.redacted_because.is_some() -} - -/// Copies the `redacts` property of the event to the `content` dict and -/// vice-versa. -/// -/// This follows the specification's -/// [recommendation](https://spec.matrix.org/v1.10/rooms/v11/#moving-the-redacts-property-of-mroomredaction-events-to-a-content-property): -/// -/// > For backwards-compatibility with older clients, servers should add a -/// > redacts -/// > property to the top level of m.room.redaction events in when serving -/// > such events -/// > over the Client-Server API. -/// -/// > For improved compatibility with newer clients, servers should add a -/// > redacts property -/// > to the content of m.room.redaction events in older room versions when -/// > serving -/// > such events over the Client-Server API. -#[implement(super::Pdu)] -#[must_use] -pub fn copy_redacts(&self) -> (Option, Box) { - if self.kind == TimelineEventType::RoomRedaction { - if let Ok(mut content) = - serde_json::from_str::(self.content.get()) - { - match content.redacts { - | Some(redacts) => { - return (Some(redacts), self.content.clone()); - }, - | _ => match self.redacts.clone() { - | Some(redacts) => { - content.redacts = Some(redacts); - return ( - self.redacts.clone(), - to_raw_value(&content) - .expect("Must be valid, we only added redacts field"), - ); - }, - | _ => {}, - }, - } - } - } - - (self.redacts.clone(), self.content.clone()) -} - -#[implement(super::Pdu)] -#[must_use] -pub fn redacts_id(&self, room_version: &RoomVersionId) -> Option { - use RoomVersionId::*; - - if self.kind != TimelineEventType::RoomRedaction { - return None; - } - - match *room_version { - | V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => self.redacts.clone(), - | _ => - self.get_content::() - .ok()? - .redacts, - } -} diff --git a/src/core/matrix/pdu/strip.rs b/src/core/matrix/pdu/strip.rs deleted file mode 100644 index a39e7d35..00000000 --- a/src/core/matrix/pdu/strip.rs +++ /dev/null @@ -1,257 +0,0 @@ -use ruma::{ - events::{ - AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent, AnySyncStateEvent, - AnySyncTimelineEvent, AnyTimelineEvent, StateEvent, room::member::RoomMemberEventContent, - space::child::HierarchySpaceChildEvent, - }, - serde::Raw, -}; -use serde_json::{json, value::Value as JsonValue}; - -use crate::implement; - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn into_room_event(self) -> Raw { self.to_room_event() } - -#[implement(super::Pdu)] -#[must_use] -pub fn to_room_event(&self) -> Raw { - let value = self.to_room_event_value(); - serde_json::from_value(value).expect("Failed to serialize Event value") -} - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn to_room_event_value(&self) -> JsonValue { - let (redacts, content) = self.copy_redacts(); - let mut json = json!({ - "content": content, - "type": self.kind, - "event_id": self.event_id, - "sender": self.sender, - "origin_server_ts": self.origin_server_ts, - "room_id": self.room_id, - }); - - if let Some(unsigned) = &self.unsigned { - json["unsigned"] = json!(unsigned); - } - if let Some(state_key) = &self.state_key { - json["state_key"] = json!(state_key); - } - if let Some(redacts) = &redacts { - json["redacts"] = json!(redacts); - } - - json -} - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn into_message_like_event(self) -> Raw { self.to_message_like_event() } - -#[implement(super::Pdu)] -#[must_use] -pub fn to_message_like_event(&self) -> Raw { - let value = self.to_message_like_event_value(); - serde_json::from_value(value).expect("Failed to serialize Event value") -} - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn to_message_like_event_value(&self) -> JsonValue { - let (redacts, content) = self.copy_redacts(); - let mut json = json!({ - "content": content, - "type": self.kind, - "event_id": self.event_id, - "sender": self.sender, - "origin_server_ts": self.origin_server_ts, - "room_id": self.room_id, - }); - - if let Some(unsigned) = &self.unsigned { - json["unsigned"] = json!(unsigned); - } - if let Some(state_key) = &self.state_key { - json["state_key"] = json!(state_key); - } - if let Some(redacts) = &redacts { - json["redacts"] = json!(redacts); - } - - json -} - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn into_sync_room_event(self) -> Raw { self.to_sync_room_event() } - -#[implement(super::Pdu)] -#[must_use] -pub fn to_sync_room_event(&self) -> Raw { - let value = self.to_sync_room_event_value(); - serde_json::from_value(value).expect("Failed to serialize Event value") -} - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn to_sync_room_event_value(&self) -> JsonValue { - let (redacts, content) = self.copy_redacts(); - let mut json = json!({ - "content": content, - "type": self.kind, - "event_id": self.event_id, - "sender": self.sender, - "origin_server_ts": self.origin_server_ts, - }); - - if let Some(unsigned) = &self.unsigned { - json["unsigned"] = json!(unsigned); - } - if let Some(state_key) = &self.state_key { - json["state_key"] = json!(state_key); - } - if let Some(redacts) = &redacts { - json["redacts"] = json!(redacts); - } - - json -} - -#[implement(super::Pdu)] -#[must_use] -pub fn into_state_event(self) -> Raw { - let value = self.into_state_event_value(); - serde_json::from_value(value).expect("Failed to serialize Event value") -} - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn into_state_event_value(self) -> JsonValue { - let mut json = json!({ - "content": self.content, - "type": self.kind, - "event_id": self.event_id, - "sender": self.sender, - "origin_server_ts": self.origin_server_ts, - "room_id": self.room_id, - "state_key": self.state_key, - }); - - if let Some(unsigned) = self.unsigned { - json["unsigned"] = json!(unsigned); - } - - json -} - -#[implement(super::Pdu)] -#[must_use] -pub fn into_sync_state_event(self) -> Raw { - let value = self.into_sync_state_event_value(); - serde_json::from_value(value).expect("Failed to serialize Event value") -} - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn into_sync_state_event_value(self) -> JsonValue { - let mut json = json!({ - "content": self.content, - "type": self.kind, - "event_id": self.event_id, - "sender": self.sender, - "origin_server_ts": self.origin_server_ts, - "state_key": self.state_key, - }); - - if let Some(unsigned) = &self.unsigned { - json["unsigned"] = json!(unsigned); - } - - json -} - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn into_stripped_state_event(self) -> Raw { - self.to_stripped_state_event() -} - -#[implement(super::Pdu)] -#[must_use] -pub fn to_stripped_state_event(&self) -> Raw { - let value = self.to_stripped_state_event_value(); - serde_json::from_value(value).expect("Failed to serialize Event value") -} - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn to_stripped_state_event_value(&self) -> JsonValue { - json!({ - "content": self.content, - "type": self.kind, - "sender": self.sender, - "state_key": self.state_key, - }) -} - -#[implement(super::Pdu)] -#[must_use] -pub fn into_stripped_spacechild_state_event(self) -> Raw { - let value = self.into_stripped_spacechild_state_event_value(); - serde_json::from_value(value).expect("Failed to serialize Event value") -} - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn into_stripped_spacechild_state_event_value(self) -> JsonValue { - json!({ - "content": self.content, - "type": self.kind, - "sender": self.sender, - "state_key": self.state_key, - "origin_server_ts": self.origin_server_ts, - }) -} - -#[implement(super::Pdu)] -#[must_use] -pub fn into_member_event(self) -> Raw> { - let value = self.into_member_event_value(); - serde_json::from_value(value).expect("Failed to serialize Event value") -} - -#[implement(super::Pdu)] -#[must_use] -#[inline] -pub fn into_member_event_value(self) -> JsonValue { - let mut json = json!({ - "content": self.content, - "type": self.kind, - "event_id": self.event_id, - "sender": self.sender, - "origin_server_ts": self.origin_server_ts, - "redacts": self.redacts, - "room_id": self.room_id, - "state_key": self.state_key, - }); - - if let Some(unsigned) = self.unsigned { - json["unsigned"] = json!(unsigned); - } - - json -} diff --git a/src/core/matrix/pdu/state_key.rs b/src/core/matrix/state_key.rs similarity index 67% rename from src/core/matrix/pdu/state_key.rs rename to src/core/matrix/state_key.rs index 4af4fcf7..06d614f8 100644 --- a/src/core/matrix/pdu/state_key.rs +++ b/src/core/matrix/state_key.rs @@ -1,8 +1,5 @@ use smallstr::SmallString; -use super::ShortId; - pub type StateKey = SmallString<[u8; INLINE_SIZE]>; -pub type ShortStateKey = ShortId; const INLINE_SIZE: usize = 48; diff --git a/src/core/matrix/state_res/benches.rs b/src/core/matrix/state_res/benches.rs index 12eeab9d..69088369 100644 --- a/src/core/matrix/state_res/benches.rs +++ b/src/core/matrix/state_res/benches.rs @@ -13,7 +13,6 @@ use ruma::{ EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, RoomVersionId, Signatures, UserId, events::{ StateEventType, TimelineEventType, - pdu::{EventHash, Pdu, RoomV3Pdu}, room::{ join_rules::{JoinRule, RoomJoinRulesEventContent}, member::{MembershipState, RoomMemberEventContent}, @@ -26,8 +25,10 @@ use serde_json::{ value::{RawValue as RawJsonValue, to_raw_value as to_raw_json_value}, }; -use self::event::PduEvent; -use crate::state_res::{self as state_res, Error, Event, Result, StateMap}; +use crate::{ + matrix::{Event, Pdu, pdu::EventHash}, + state_res::{self as state_res, Error, Result, StateMap}, +}; static SERVER_TIMESTAMP: AtomicU64 = AtomicU64::new(0); @@ -60,7 +61,7 @@ fn resolution_shallow_auth_chain(c: &mut test::Bencher) { c.iter(|| async { let ev_map = store.0.clone(); let state_sets = [&state_at_bob, &state_at_charlie]; - let fetch = |id: OwnedEventId| ready(ev_map.get(&id).clone()); + let fetch = |id: OwnedEventId| ready(ev_map.get(&id).map(ToOwned::to_owned)); let exists = |id: OwnedEventId| ready(ev_map.get(&id).is_some()); let auth_chain_sets: Vec> = state_sets .iter() @@ -142,7 +143,7 @@ fn resolve_deeper_event_set(c: &mut test::Bencher) { }) .collect(); - let fetch = |id: OwnedEventId| ready(inner.get(&id).clone()); + let fetch = |id: OwnedEventId| ready(inner.get(&id).map(ToOwned::to_owned)); let exists = |id: OwnedEventId| ready(inner.get(&id).is_some()); let _ = match state_res::resolve( &RoomVersionId::V6, @@ -246,7 +247,7 @@ impl TestStore { } } -impl TestStore { +impl TestStore { #[allow(clippy::type_complexity)] fn set_up( &mut self, @@ -380,7 +381,7 @@ fn to_pdu_event( content: Box, auth_events: &[S], prev_events: &[S], -) -> PduEvent +) -> Pdu where S: AsRef, { @@ -403,30 +404,28 @@ where .map(event_id) .collect::>(); - let state_key = state_key.map(ToOwned::to_owned); - PduEvent { + Pdu { event_id: id.try_into().unwrap(), - rest: Pdu::RoomV3Pdu(RoomV3Pdu { - room_id: room_id().to_owned(), - sender: sender.to_owned(), - origin_server_ts: MilliSecondsSinceUnixEpoch(ts.try_into().unwrap()), - state_key, - kind: ev_type, - content, - redacts: None, - unsigned: btreemap! {}, - auth_events, - prev_events, - depth: uint!(0), - hashes: EventHash::new(String::new()), - signatures: Signatures::new(), - }), + room_id: room_id().to_owned(), + sender: sender.to_owned(), + origin_server_ts: ts.try_into().unwrap(), + state_key: state_key.map(Into::into), + kind: ev_type, + content, + origin: None, + redacts: None, + unsigned: None, + auth_events, + prev_events, + depth: uint!(0), + hashes: EventHash { sha256: String::new() }, + signatures: None, } } // all graphs start with these input events #[allow(non_snake_case)] -fn INITIAL_EVENTS() -> HashMap { +fn INITIAL_EVENTS() -> HashMap { vec![ to_pdu_event::<&EventId>( "CREATE", @@ -508,7 +507,7 @@ fn INITIAL_EVENTS() -> HashMap { // all graphs start with these input events #[allow(non_snake_case)] -fn BAN_STATE_SET() -> HashMap { +fn BAN_STATE_SET() -> HashMap { vec![ to_pdu_event( "PA", @@ -551,119 +550,3 @@ fn BAN_STATE_SET() -> HashMap { .map(|ev| (ev.event_id().to_owned(), ev)) .collect() } - -/// Convenience trait for adding event type plus state key to state maps. -trait EventTypeExt { - fn with_state_key(self, state_key: impl Into) -> (StateEventType, String); -} - -impl EventTypeExt for &TimelineEventType { - fn with_state_key(self, state_key: impl Into) -> (StateEventType, String) { - (self.to_string().into(), state_key.into()) - } -} - -mod event { - use ruma::{ - EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId, - events::{TimelineEventType, pdu::Pdu}, - }; - use serde::{Deserialize, Serialize}; - use serde_json::value::RawValue as RawJsonValue; - - use super::Event; - - impl Event for PduEvent { - fn event_id(&self) -> &EventId { &self.event_id } - - fn room_id(&self) -> &RoomId { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => &ev.room_id, - | Pdu::RoomV3Pdu(ev) => &ev.room_id, - #[cfg(not(feature = "unstable-exhaustive-types"))] - | _ => unreachable!("new PDU version"), - } - } - - fn sender(&self) -> &UserId { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => &ev.sender, - | Pdu::RoomV3Pdu(ev) => &ev.sender, - #[cfg(not(feature = "unstable-exhaustive-types"))] - | _ => unreachable!("new PDU version"), - } - } - - fn event_type(&self) -> &TimelineEventType { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => &ev.kind, - | Pdu::RoomV3Pdu(ev) => &ev.kind, - #[cfg(not(feature = "unstable-exhaustive-types"))] - | _ => unreachable!("new PDU version"), - } - } - - fn content(&self) -> &RawJsonValue { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => &ev.content, - | Pdu::RoomV3Pdu(ev) => &ev.content, - #[cfg(not(feature = "unstable-exhaustive-types"))] - | _ => unreachable!("new PDU version"), - } - } - - fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => ev.origin_server_ts, - | Pdu::RoomV3Pdu(ev) => ev.origin_server_ts, - #[cfg(not(feature = "unstable-exhaustive-types"))] - | _ => unreachable!("new PDU version"), - } - } - - fn state_key(&self) -> Option<&str> { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => ev.state_key.as_deref(), - | Pdu::RoomV3Pdu(ev) => ev.state_key.as_deref(), - #[cfg(not(feature = "unstable-exhaustive-types"))] - | _ => unreachable!("new PDU version"), - } - } - - fn prev_events(&self) -> Box + Send + '_> { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => - Box::new(ev.prev_events.iter().map(|(id, _)| id.as_ref())), - | Pdu::RoomV3Pdu(ev) => Box::new(ev.prev_events.iter().map(AsRef::as_ref)), - #[cfg(not(feature = "unstable-exhaustive-types"))] - | _ => unreachable!("new PDU version"), - } - } - - fn auth_events(&self) -> Box + Send + '_> { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => - Box::new(ev.auth_events.iter().map(|(id, _)| id.as_ref())), - | Pdu::RoomV3Pdu(ev) => Box::new(ev.auth_events.iter().map(AsRef::as_ref)), - #[cfg(not(feature = "unstable-exhaustive-types"))] - | _ => unreachable!("new PDU version"), - } - } - - fn redacts(&self) -> Option<&EventId> { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => ev.redacts.as_deref(), - | Pdu::RoomV3Pdu(ev) => ev.redacts.as_deref(), - #[cfg(not(feature = "unstable-exhaustive-types"))] - | _ => unreachable!("new PDU version"), - } - } - } - - #[derive(Clone, Debug, Deserialize, Serialize)] - pub(crate) struct PduEvent { - pub(crate) event_id: OwnedEventId, - #[serde(flatten)] - pub(crate) rest: Pdu, - } -} diff --git a/src/core/matrix/state_res/event_auth.rs b/src/core/matrix/state_res/event_auth.rs index 759ab5cb..8c760860 100644 --- a/src/core/matrix/state_res/event_auth.rs +++ b/src/core/matrix/state_res/event_auth.rs @@ -136,17 +136,17 @@ pub fn auth_types_for_event( event_id = incoming_event.event_id().as_str(), ) )] -pub async fn auth_check( +pub async fn auth_check( room_version: &RoomVersion, - incoming_event: &Incoming, - current_third_party_invite: Option<&Incoming>, + incoming_event: &E, + current_third_party_invite: Option<&E>, fetch_state: F, ) -> Result where F: Fn(&StateEventType, &str) -> Fut + Send, - Fut: Future> + Send, - Fetched: Event + Send, - Incoming: Event + Send + Sync, + Fut: Future> + Send, + E: Event + Send + Sync, + for<'a> &'a E: Event + Send, { debug!( event_id = format!("{}", incoming_event.event_id()), @@ -514,20 +514,24 @@ where /// event and the current State. #[allow(clippy::too_many_arguments)] #[allow(clippy::cognitive_complexity)] -fn valid_membership_change( +fn valid_membership_change( room_version: &RoomVersion, target_user: &UserId, - target_user_membership_event: Option<&impl Event>, + target_user_membership_event: Option<&E>, sender: &UserId, - sender_membership_event: Option<&impl Event>, - current_event: impl Event, - current_third_party_invite: Option<&impl Event>, - power_levels_event: Option<&impl Event>, - join_rules_event: Option<&impl Event>, + sender_membership_event: Option<&E>, + current_event: &E, + current_third_party_invite: Option<&E>, + power_levels_event: Option<&E>, + join_rules_event: Option<&E>, user_for_join_auth: Option<&UserId>, user_for_join_auth_membership: &MembershipState, - create_room: &impl Event, -) -> Result { + create_room: &E, +) -> Result +where + E: Event + Send + Sync, + for<'a> &'a E: Event + Send, +{ #[derive(Deserialize)] struct GetThirdPartyInvite { third_party_invite: Option>, @@ -820,7 +824,7 @@ fn valid_membership_change( /// /// Does the event have the correct userId as its state_key if it's not the "" /// state_key. -fn can_send_event(event: impl Event, ple: Option, user_level: Int) -> bool { +fn can_send_event(event: &impl Event, ple: Option<&impl Event>, user_level: Int) -> bool { let event_type_power_level = get_send_level(event.event_type(), event.state_key(), ple); debug!( @@ -846,8 +850,8 @@ fn can_send_event(event: impl Event, ple: Option, user_level: Int) - /// Confirm that the event sender has the required power levels. fn check_power_levels( room_version: &RoomVersion, - power_event: impl Event, - previous_power_event: Option, + power_event: &impl Event, + previous_power_event: Option<&impl Event>, user_level: Int, ) -> Option { match power_event.state_key() { @@ -1010,7 +1014,7 @@ fn get_deserialize_levels( /// given event. fn check_redaction( _room_version: &RoomVersion, - redaction_event: impl Event, + redaction_event: &impl Event, user_level: Int, redact_level: Int, ) -> Result { @@ -1039,7 +1043,7 @@ fn check_redaction( fn get_send_level( e_type: &TimelineEventType, state_key: Option<&str>, - power_lvl: Option, + power_lvl: Option<&impl Event>, ) -> Int { power_lvl .and_then(|ple| { @@ -1062,7 +1066,7 @@ fn verify_third_party_invite( target_user: Option<&UserId>, sender: &UserId, tp_id: &ThirdPartyInvite, - current_third_party_invite: Option, + current_third_party_invite: Option<&impl Event>, ) -> bool { // 1. Check for user being banned happens before this is called // checking for mxid and token keys is done by ruma when deserializing @@ -1128,12 +1132,15 @@ mod tests { }; use serde_json::value::to_raw_value as to_raw_json_value; - use crate::state_res::{ - Event, EventTypeExt, RoomVersion, StateMap, - event_auth::valid_membership_change, - test_utils::{ - INITIAL_EVENTS, INITIAL_EVENTS_CREATE_ROOM, PduEvent, alice, charlie, ella, event_id, - member_content_ban, member_content_join, room_id, to_pdu_event, + use crate::{ + matrix::{Event, EventTypeExt, Pdu as PduEvent}, + state_res::{ + RoomVersion, StateMap, + event_auth::valid_membership_change, + test_utils::{ + INITIAL_EVENTS, INITIAL_EVENTS_CREATE_ROOM, alice, charlie, ella, event_id, + member_content_ban, member_content_join, room_id, to_pdu_event, + }, }, }; diff --git a/src/core/matrix/state_res/mod.rs b/src/core/matrix/state_res/mod.rs index 651f6130..ed5aa034 100644 --- a/src/core/matrix/state_res/mod.rs +++ b/src/core/matrix/state_res/mod.rs @@ -37,7 +37,7 @@ pub use self::{ }; use crate::{ debug, debug_error, - matrix::{event::Event, pdu::StateKey}, + matrix::{Event, StateKey}, trace, utils::stream::{BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, WidebandExt}, warn, @@ -90,7 +90,7 @@ where SetIter: Iterator> + Clone + Send, Hasher: BuildHasher + Send + Sync, E: Event + Clone + Send + Sync, - for<'b> &'b E: Send, + for<'b> &'b E: Event + Send, { debug!("State resolution starting"); @@ -522,6 +522,7 @@ where Fut: Future> + Send, S: Stream + Send + 'a, E: Event + Clone + Send + Sync, + for<'b> &'b E: Event + Send, { debug!("starting iterative auth check"); @@ -552,7 +553,7 @@ where let auth_events = &auth_events; let mut resolved_state = unconflicted_state; - for event in &events_to_check { + for event in events_to_check { let state_key = event .state_key() .ok_or_else(|| Error::InvalidPdu("State event had no state key".to_owned()))?; @@ -607,11 +608,15 @@ where }); let fetch_state = |ty: &StateEventType, key: &str| { - future::ready(auth_state.get(&ty.with_state_key(key))) + future::ready( + auth_state + .get(&ty.with_state_key(key)) + .map(ToOwned::to_owned), + ) }; let auth_result = - auth_check(room_version, &event, current_third_party.as_ref(), fetch_state).await; + auth_check(room_version, &event, current_third_party, fetch_state).await; match auth_result { | Ok(true) => { @@ -794,11 +799,11 @@ where } } -fn is_type_and_key(ev: impl Event, ev_type: &TimelineEventType, state_key: &str) -> bool { +fn is_type_and_key(ev: &impl Event, ev_type: &TimelineEventType, state_key: &str) -> bool { ev.event_type() == ev_type && ev.state_key() == Some(state_key) } -fn is_power_event(event: impl Event) -> bool { +fn is_power_event(event: &impl Event) -> bool { match event.event_type() { | TimelineEventType::RoomPowerLevels | TimelineEventType::RoomJoinRules @@ -859,15 +864,19 @@ mod tests { use serde_json::{json, value::to_raw_value as to_raw_json_value}; use super::{ - Event, EventTypeExt, StateMap, is_power_event, + StateMap, is_power_event, room_version::RoomVersion, test_utils::{ - INITIAL_EVENTS, PduEvent, TestStore, alice, bob, charlie, do_check, ella, event_id, + INITIAL_EVENTS, TestStore, alice, bob, charlie, do_check, ella, event_id, member_content_ban, member_content_join, room_id, to_init_pdu_event, to_pdu_event, zara, }, }; - use crate::{debug, utils::stream::IterStream}; + use crate::{ + debug, + matrix::{Event, EventTypeExt, Pdu as PduEvent}, + utils::stream::IterStream, + }; async fn test_event_sort() { use futures::future::ready; diff --git a/src/core/matrix/state_res/test_utils.rs b/src/core/matrix/state_res/test_utils.rs index c6945f66..9f24c51b 100644 --- a/src/core/matrix/state_res/test_utils.rs +++ b/src/core/matrix/state_res/test_utils.rs @@ -10,7 +10,6 @@ use ruma::{ UserId, event_id, events::{ TimelineEventType, - pdu::{EventHash, Pdu, RoomV3Pdu}, room::{ join_rules::{JoinRule, RoomJoinRulesEventContent}, member::{MembershipState, RoomMemberEventContent}, @@ -23,17 +22,16 @@ use serde_json::{ value::{RawValue as RawJsonValue, to_raw_value as to_raw_json_value}, }; -pub(crate) use self::event::PduEvent; use super::auth_types_for_event; use crate::{ Result, info, - matrix::{Event, EventTypeExt, StateMap}, + matrix::{Event, EventTypeExt, Pdu, StateMap, pdu::EventHash}, }; static SERVER_TIMESTAMP: AtomicU64 = AtomicU64::new(0); pub(crate) async fn do_check( - events: &[PduEvent], + events: &[Pdu], edges: Vec>, expected_state_ids: Vec, ) { @@ -81,8 +79,8 @@ pub(crate) async fn do_check( } } - // event_id -> PduEvent - let mut event_map: HashMap = HashMap::new(); + // event_id -> Pdu + let mut event_map: HashMap = HashMap::new(); // event_id -> StateMap let mut state_at_event: HashMap> = HashMap::new(); @@ -265,7 +263,7 @@ impl TestStore { // A StateStore implementation for testing #[allow(clippy::type_complexity)] -impl TestStore { +impl TestStore { pub(crate) fn set_up( &mut self, ) -> (StateMap, StateMap, StateMap) { @@ -390,7 +388,7 @@ pub(crate) fn to_init_pdu_event( ev_type: TimelineEventType, state_key: Option<&str>, content: Box, -) -> PduEvent { +) -> Pdu { let ts = SERVER_TIMESTAMP.fetch_add(1, SeqCst); let id = if id.contains('$') { id.to_owned() @@ -398,24 +396,22 @@ pub(crate) fn to_init_pdu_event( format!("${id}:foo") }; - let state_key = state_key.map(ToOwned::to_owned); - PduEvent { + Pdu { event_id: id.try_into().unwrap(), - rest: Pdu::RoomV3Pdu(RoomV3Pdu { - room_id: room_id().to_owned(), - sender: sender.to_owned(), - origin_server_ts: MilliSecondsSinceUnixEpoch(ts.try_into().unwrap()), - state_key, - kind: ev_type, - content, - redacts: None, - unsigned: BTreeMap::new(), - auth_events: vec![], - prev_events: vec![], - depth: uint!(0), - hashes: EventHash::new("".to_owned()), - signatures: ServerSignatures::default(), - }), + room_id: room_id().to_owned(), + sender: sender.to_owned(), + origin_server_ts: ts.try_into().unwrap(), + state_key: state_key.map(Into::into), + kind: ev_type, + content, + origin: None, + redacts: None, + unsigned: None, + auth_events: vec![], + prev_events: vec![], + depth: uint!(0), + hashes: EventHash { sha256: "".to_owned() }, + signatures: None, } } @@ -427,7 +423,7 @@ pub(crate) fn to_pdu_event( content: Box, auth_events: &[S], prev_events: &[S], -) -> PduEvent +) -> Pdu where S: AsRef, { @@ -448,30 +444,28 @@ where .map(event_id) .collect::>(); - let state_key = state_key.map(ToOwned::to_owned); - PduEvent { + Pdu { event_id: id.try_into().unwrap(), - rest: Pdu::RoomV3Pdu(RoomV3Pdu { - room_id: room_id().to_owned(), - sender: sender.to_owned(), - origin_server_ts: MilliSecondsSinceUnixEpoch(ts.try_into().unwrap()), - state_key, - kind: ev_type, - content, - redacts: None, - unsigned: BTreeMap::new(), - auth_events, - prev_events, - depth: uint!(0), - hashes: EventHash::new("".to_owned()), - signatures: ServerSignatures::default(), - }), + room_id: room_id().to_owned(), + sender: sender.to_owned(), + origin_server_ts: ts.try_into().unwrap(), + state_key: state_key.map(Into::into), + kind: ev_type, + content, + origin: None, + redacts: None, + unsigned: None, + auth_events, + prev_events, + depth: uint!(0), + hashes: EventHash { sha256: "".to_owned() }, + signatures: None, } } // all graphs start with these input events #[allow(non_snake_case)] -pub(crate) fn INITIAL_EVENTS() -> HashMap { +pub(crate) fn INITIAL_EVENTS() -> HashMap { vec![ to_pdu_event::<&EventId>( "CREATE", @@ -553,7 +547,7 @@ pub(crate) fn INITIAL_EVENTS() -> HashMap { // all graphs start with these input events #[allow(non_snake_case)] -pub(crate) fn INITIAL_EVENTS_CREATE_ROOM() -> HashMap { +pub(crate) fn INITIAL_EVENTS_CREATE_ROOM() -> HashMap { vec![to_pdu_event::<&EventId>( "CREATE", alice(), @@ -575,111 +569,3 @@ pub(crate) fn INITIAL_EDGES() -> Vec { .map(event_id) .collect::>() } - -pub(crate) mod event { - use ruma::{ - EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId, - events::{TimelineEventType, pdu::Pdu}, - }; - use serde::{Deserialize, Serialize}; - use serde_json::value::RawValue as RawJsonValue; - - use crate::Event; - - impl Event for PduEvent { - fn event_id(&self) -> &EventId { &self.event_id } - - fn room_id(&self) -> &RoomId { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => &ev.room_id, - | Pdu::RoomV3Pdu(ev) => &ev.room_id, - #[allow(unreachable_patterns)] - | _ => unreachable!("new PDU version"), - } - } - - fn sender(&self) -> &UserId { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => &ev.sender, - | Pdu::RoomV3Pdu(ev) => &ev.sender, - #[allow(unreachable_patterns)] - | _ => unreachable!("new PDU version"), - } - } - - fn event_type(&self) -> &TimelineEventType { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => &ev.kind, - | Pdu::RoomV3Pdu(ev) => &ev.kind, - #[allow(unreachable_patterns)] - | _ => unreachable!("new PDU version"), - } - } - - fn content(&self) -> &RawJsonValue { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => &ev.content, - | Pdu::RoomV3Pdu(ev) => &ev.content, - #[allow(unreachable_patterns)] - | _ => unreachable!("new PDU version"), - } - } - - fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => ev.origin_server_ts, - | Pdu::RoomV3Pdu(ev) => ev.origin_server_ts, - #[allow(unreachable_patterns)] - | _ => unreachable!("new PDU version"), - } - } - - fn state_key(&self) -> Option<&str> { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => ev.state_key.as_deref(), - | Pdu::RoomV3Pdu(ev) => ev.state_key.as_deref(), - #[allow(unreachable_patterns)] - | _ => unreachable!("new PDU version"), - } - } - - #[allow(refining_impl_trait)] - fn prev_events(&self) -> Box + Send + '_> { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => - Box::new(ev.prev_events.iter().map(|(id, _)| id.as_ref())), - | Pdu::RoomV3Pdu(ev) => Box::new(ev.prev_events.iter().map(AsRef::as_ref)), - #[allow(unreachable_patterns)] - | _ => unreachable!("new PDU version"), - } - } - - #[allow(refining_impl_trait)] - fn auth_events(&self) -> Box + Send + '_> { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => - Box::new(ev.auth_events.iter().map(|(id, _)| id.as_ref())), - | Pdu::RoomV3Pdu(ev) => Box::new(ev.auth_events.iter().map(AsRef::as_ref)), - #[allow(unreachable_patterns)] - | _ => unreachable!("new PDU version"), - } - } - - fn redacts(&self) -> Option<&EventId> { - match &self.rest { - | Pdu::RoomV1Pdu(ev) => ev.redacts.as_deref(), - | Pdu::RoomV3Pdu(ev) => ev.redacts.as_deref(), - #[allow(unreachable_patterns)] - | _ => unreachable!("new PDU version"), - } - } - } - - #[derive(Clone, Debug, Deserialize, Serialize)] - #[allow(clippy::exhaustive_structs)] - pub(crate) struct PduEvent { - pub(crate) event_id: OwnedEventId, - #[serde(flatten)] - pub(crate) rest: Pdu, - } -} diff --git a/src/core/mod.rs b/src/core/mod.rs index aaacd4d8..d99139be 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -25,7 +25,9 @@ pub use info::{ rustc_flags_capture, version, version::{name, version}, }; -pub use matrix::{Event, EventTypeExt, PduCount, PduEvent, PduId, RoomVersion, pdu, state_res}; +pub use matrix::{ + Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, RoomVersion, pdu, state_res, +}; pub use server::Server; pub use utils::{ctor, dtor, implement, result, result::Result}; diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index a76c3ef6..66c373ec 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -9,8 +9,8 @@ use std::{ }; use async_trait::async_trait; -use conduwuit::{ - Error, PduEvent, Result, Server, debug, err, error, error::default_log, pdu::PduBuilder, +use conduwuit_core::{ + Error, Event, Result, Server, debug, err, error, error::default_log, pdu::PduBuilder, }; pub use create::create_admin_room; use futures::{Future, FutureExt, TryFutureExt}; @@ -361,7 +361,10 @@ impl Service { Ok(()) } - pub async fn is_admin_command(&self, pdu: &PduEvent, body: &str) -> bool { + pub async fn is_admin_command(&self, event: &E, body: &str) -> bool + where + E: Event + Send + Sync, + { // Server-side command-escape with public echo let is_escape = body.starts_with('\\'); let is_public_escape = is_escape && body.trim_start_matches('\\').starts_with("!admin"); @@ -376,8 +379,10 @@ impl Service { return false; } + let user_is_local = self.services.globals.user_is_local(event.sender()); + // only allow public escaped commands by local admins - if is_public_escape && !self.services.globals.user_is_local(&pdu.sender) { + if is_public_escape && !user_is_local { return false; } @@ -387,20 +392,20 @@ impl Service { } // Prevent unescaped !admin from being used outside of the admin room - if is_public_prefix && !self.is_admin_room(&pdu.room_id).await { + if is_public_prefix && !self.is_admin_room(event.room_id()).await { return false; } // Only senders who are admin can proceed - if !self.user_is_admin(&pdu.sender).await { + if !self.user_is_admin(event.sender()).await { return false; } // This will evaluate to false if the emergency password is set up so that // the administrator can execute commands as the server user let emergency_password_set = self.services.server.config.emergency_password.is_some(); - let from_server = pdu.sender == *server_user && !emergency_password_set; - if from_server && self.is_admin_room(&pdu.room_id).await { + let from_server = event.sender() == server_user && !emergency_password_set; + if from_server && self.is_admin_room(event.room_id()).await { return false; } diff --git a/src/service/pusher/mod.rs b/src/service/pusher/mod.rs index 27490fb8..192ef447 100644 --- a/src/service/pusher/mod.rs +++ b/src/service/pusher/mod.rs @@ -1,12 +1,12 @@ use std::{fmt::Debug, mem, sync::Arc}; use bytes::BytesMut; -use conduwuit::{ - Err, PduEvent, Result, debug_warn, err, trace, +use conduwuit_core::{ + Err, Event, Result, debug_warn, err, trace, utils::{stream::TryIgnore, string_from_bytes}, warn, }; -use database::{Deserialized, Ignore, Interfix, Json, Map}; +use conduwuit_database::{Deserialized, Ignore, Interfix, Json, Map}; use futures::{Stream, StreamExt}; use ipaddress::IPAddress; use ruma::{ @@ -272,22 +272,26 @@ impl Service { } } - #[tracing::instrument(skip(self, user, unread, pusher, ruleset, pdu))] - pub async fn send_push_notice( + #[tracing::instrument(skip(self, user, unread, pusher, ruleset, event))] + pub async fn send_push_notice( &self, user: &UserId, unread: UInt, pusher: &Pusher, ruleset: Ruleset, - pdu: &PduEvent, - ) -> Result<()> { + event: &E, + ) -> Result + where + E: Event + Send + Sync, + for<'a> &'a E: Event + Send, + { let mut notify = None; let mut tweaks = Vec::new(); let power_levels: RoomPowerLevelsEventContent = self .services .state_accessor - .room_state_get(&pdu.room_id, &StateEventType::RoomPowerLevels, "") + .room_state_get(event.room_id(), &StateEventType::RoomPowerLevels, "") .await .and_then(|ev| { serde_json::from_str(ev.content.get()).map_err(|e| { @@ -296,8 +300,9 @@ impl Service { }) .unwrap_or_default(); + let serialized = event.to_format(); for action in self - .get_actions(user, &ruleset, &power_levels, &pdu.to_sync_room_event(), &pdu.room_id) + .get_actions(user, &ruleset, &power_levels, &serialized, event.room_id()) .await { let n = match action { @@ -319,7 +324,7 @@ impl Service { } if notify == Some(true) { - self.send_notice(unread, pusher, tweaks, pdu).await?; + self.send_notice(unread, pusher, tweaks, event).await?; } // Else the event triggered no actions @@ -369,13 +374,16 @@ impl Service { } #[tracing::instrument(skip(self, unread, pusher, tweaks, event))] - async fn send_notice( + async fn send_notice( &self, unread: UInt, pusher: &Pusher, tweaks: Vec, - event: &PduEvent, - ) -> Result { + event: &E, + ) -> Result + where + E: Event + Send + Sync, + { // TODO: email match &pusher.kind { | PusherKind::Http(http) => { @@ -421,8 +429,8 @@ impl Service { let d = vec![device]; let mut notifi = Notification::new(d); - notifi.event_id = Some((*event.event_id).to_owned()); - notifi.room_id = Some((*event.room_id).to_owned()); + notifi.event_id = Some(event.event_id().to_owned()); + notifi.room_id = Some(event.room_id().to_owned()); if http .data .get("org.matrix.msc4076.disable_badge_count") @@ -442,7 +450,7 @@ impl Service { ) .await?; } else { - if event.kind == TimelineEventType::RoomEncrypted + if *event.kind() == TimelineEventType::RoomEncrypted || tweaks .iter() .any(|t| matches!(t, Tweak::Highlight(true) | Tweak::Sound(_))) @@ -451,29 +459,29 @@ impl Service { } else { notifi.prio = NotificationPriority::Low; } - notifi.sender = Some(event.sender.clone()); - notifi.event_type = Some(event.kind.clone()); - notifi.content = serde_json::value::to_raw_value(&event.content).ok(); + notifi.sender = Some(event.sender().to_owned()); + notifi.event_type = Some(event.kind().to_owned()); + notifi.content = serde_json::value::to_raw_value(event.content()).ok(); - if event.kind == TimelineEventType::RoomMember { + if *event.kind() == TimelineEventType::RoomMember { notifi.user_is_target = - event.state_key.as_deref() == Some(event.sender.as_str()); + event.state_key() == Some(event.sender().as_str()); } notifi.sender_display_name = - self.services.users.displayname(&event.sender).await.ok(); + self.services.users.displayname(event.sender()).await.ok(); notifi.room_name = self .services .state_accessor - .get_name(&event.room_id) + .get_name(event.room_id()) .await .ok(); notifi.room_alias = self .services .state_accessor - .get_canonical_alias(&event.room_id) + .get_canonical_alias(event.room_id()) .await .ok(); diff --git a/src/service/rooms/event_handler/handle_outlier_pdu.rs b/src/service/rooms/event_handler/handle_outlier_pdu.rs index feebf8c1..5cc6be55 100644 --- a/src/service/rooms/event_handler/handle_outlier_pdu.rs +++ b/src/service/rooms/event_handler/handle_outlier_pdu.rs @@ -126,7 +126,7 @@ pub(super) async fn handle_outlier_pdu<'a>( let state_fetch = |ty: &StateEventType, sk: &str| { let key = (ty.to_owned(), sk.into()); - ready(auth_events.get(&key)) + ready(auth_events.get(&key).map(ToOwned::to_owned)) }; let auth_check = state_res::event_auth::auth_check( diff --git a/src/service/rooms/event_handler/upgrade_outlier_pdu.rs b/src/service/rooms/event_handler/upgrade_outlier_pdu.rs index 97d3df97..00b18c06 100644 --- a/src/service/rooms/event_handler/upgrade_outlier_pdu.rs +++ b/src/service/rooms/event_handler/upgrade_outlier_pdu.rs @@ -2,7 +2,7 @@ use std::{borrow::Borrow, collections::BTreeMap, iter::once, sync::Arc, time::In use conduwuit::{ Err, Result, debug, debug_info, err, implement, - matrix::{EventTypeExt, PduEvent, StateKey, state_res}, + matrix::{Event, EventTypeExt, PduEvent, StateKey, state_res}, trace, utils::stream::{BroadbandExt, ReadyExt}, warn, @@ -108,7 +108,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( let state_fetch = |k: &StateEventType, s: &str| { let key = k.with_state_key(s); - ready(auth_events.get(&key).cloned()) + ready(auth_events.get(&key).map(ToOwned::to_owned)) }; let auth_check = state_res::event_auth::auth_check( diff --git a/src/service/rooms/search/mod.rs b/src/service/rooms/search/mod.rs index 4100dd75..b9d067a6 100644 --- a/src/service/rooms/search/mod.rs +++ b/src/service/rooms/search/mod.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use conduwuit::{ - PduCount, PduEvent, Result, +use conduwuit_core::{ + Event, PduCount, PduEvent, Result, arrayvec::ArrayVec, implement, utils::{ diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs index 53d2b742..de2647ca 100644 --- a/src/service/rooms/spaces/mod.rs +++ b/src/service/rooms/spaces/mod.rs @@ -5,8 +5,8 @@ mod tests; use std::{fmt::Write, sync::Arc}; use async_trait::async_trait; -use conduwuit::{ - Err, Error, PduEvent, Result, implement, +use conduwuit_core::{ + Err, Error, Event, PduEvent, Result, implement, utils::{ IterStream, future::{BoolExt, TryExtExt}, @@ -142,7 +142,7 @@ pub async fn get_summary_and_children_local( let children_pdus: Vec<_> = self .get_space_child_events(current_room) - .map(PduEvent::into_stripped_spacechild_state_event) + .map(Event::into_format) .collect() .await; @@ -511,7 +511,7 @@ async fn cache_insert( room_id: room_id.clone(), children_state: self .get_space_child_events(&room_id) - .map(PduEvent::into_stripped_spacechild_state_event) + .map(Event::into_format) .collect() .await, encryption, diff --git a/src/service/rooms/state/mod.rs b/src/service/rooms/state/mod.rs index 803ba9d7..9eb02221 100644 --- a/src/service/rooms/state/mod.rs +++ b/src/service/rooms/state/mod.rs @@ -1,8 +1,8 @@ use std::{collections::HashMap, fmt::Write, iter::once, sync::Arc}; use async_trait::async_trait; -use conduwuit::{ - PduEvent, Result, err, +use conduwuit_core::{ + Event, PduEvent, Result, err, result::FlatOk, state_res::{self, StateMap}, utils::{ @@ -11,7 +11,7 @@ use conduwuit::{ }, warn, }; -use database::{Deserialized, Ignore, Interfix, Map}; +use conduwuit_database::{Deserialized, Ignore, Interfix, Map}; use futures::{ FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt, future::join_all, pin_mut, }; @@ -319,30 +319,34 @@ impl Service { } #[tracing::instrument(skip_all, level = "debug")] - pub async fn summary_stripped(&self, event: &PduEvent) -> Vec> { + pub async fn summary_stripped<'a, E>(&self, event: &'a E) -> Vec> + where + E: Event + Send + Sync, + &'a E: Event + Send, + { let cells = [ (&StateEventType::RoomCreate, ""), (&StateEventType::RoomJoinRules, ""), (&StateEventType::RoomCanonicalAlias, ""), (&StateEventType::RoomName, ""), (&StateEventType::RoomAvatar, ""), - (&StateEventType::RoomMember, event.sender.as_str()), // Add recommended events + (&StateEventType::RoomMember, event.sender().as_str()), // Add recommended events (&StateEventType::RoomEncryption, ""), (&StateEventType::RoomTopic, ""), ]; - let fetches = cells.iter().map(|(event_type, state_key)| { + let fetches = cells.into_iter().map(|(event_type, state_key)| { self.services .state_accessor - .room_state_get(&event.room_id, event_type, state_key) + .room_state_get(event.room_id(), event_type, state_key) }); join_all(fetches) .await .into_iter() .filter_map(Result::ok) - .map(PduEvent::into_stripped_state_event) - .chain(once(event.to_stripped_state_event())) + .map(Event::into_format) + .chain(once(event.to_format())) .collect() } diff --git a/src/service/rooms/threads/mod.rs b/src/service/rooms/threads/mod.rs index a680df55..9566eb61 100644 --- a/src/service/rooms/threads/mod.rs +++ b/src/service/rooms/threads/mod.rs @@ -1,7 +1,7 @@ use std::{collections::BTreeMap, sync::Arc}; -use conduwuit::{ - Result, err, +use conduwuit_core::{ + Event, Result, err, matrix::pdu::{PduCount, PduEvent, PduId, RawPduId}, utils::{ ReadyExt, @@ -49,7 +49,11 @@ impl crate::Service for Service { } impl Service { - pub async fn add_to_thread(&self, root_event_id: &EventId, pdu: &PduEvent) -> Result<()> { + pub async fn add_to_thread<'a, E>(&self, root_event_id: &EventId, event: &'a E) -> Result + where + E: Event + Send + Sync, + &'a E: Event + Send, + { let root_id = self .services .timeline @@ -86,7 +90,7 @@ impl Service { }) { // Thread already existed relations.count = relations.count.saturating_add(uint!(1)); - relations.latest_event = pdu.to_message_like_event(); + relations.latest_event = event.to_format(); let content = serde_json::to_value(relations).expect("to_value always works"); @@ -99,7 +103,7 @@ impl Service { } else { // New thread let relations = BundledThread { - latest_event: pdu.to_message_like_event(), + latest_event: event.to_format(), count: uint!(1), current_user_participated: true, }; @@ -129,7 +133,7 @@ impl Service { users.push(root_pdu.sender); }, } - users.push(pdu.sender.clone()); + users.push(event.sender().to_owned()); self.update_participants(&root_id, &users) } diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index 534d8faf..bcad1309 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -375,8 +375,6 @@ impl Service { .await .unwrap_or_default(); - let sync_pdu = pdu.to_sync_room_event(); - let mut push_target: HashSet<_> = self .services .state_cache @@ -401,6 +399,7 @@ impl Service { } } + let serialized = pdu.to_format(); for user in &push_target { let rules_for_user = self .services @@ -418,7 +417,7 @@ impl Service { for action in self .services .pusher - .get_actions(user, &rules_for_user, &power_levels, &sync_pdu, &pdu.room_id) + .get_actions(user, &rules_for_user, &power_levels, &serialized, &pdu.room_id) .await { match action { @@ -768,7 +767,7 @@ impl Service { let auth_fetch = |k: &StateEventType, s: &str| { let key = (k.clone(), s.into()); - ready(auth_events.get(&key)) + ready(auth_events.get(&key).map(ToOwned::to_owned)) }; let auth_check = state_res::auth_check( diff --git a/src/service/sending/sender.rs b/src/service/sending/sender.rs index fab02f6b..408ab17d 100644 --- a/src/service/sending/sender.rs +++ b/src/service/sending/sender.rs @@ -9,8 +9,8 @@ use std::{ }; use base64::{Engine as _, engine::general_purpose::URL_SAFE_NO_PAD}; -use conduwuit::{ - Error, Result, debug, err, error, +use conduwuit_core::{ + Error, Event, Result, debug, err, error, result::LogErr, trace, utils::{ @@ -697,7 +697,7 @@ impl Service { match event { | SendingEvent::Pdu(pdu_id) => { if let Ok(pdu) = self.services.timeline.get_pdu_from_id(pdu_id).await { - pdu_jsons.push(pdu.into_room_event()); + pdu_jsons.push(pdu.to_format()); } }, | SendingEvent::Edu(edu) => From af4f66c768c8edc1c0da66f583ddb4c17201c4f0 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 27 Apr 2025 00:58:56 +0000 Subject: [PATCH 2099/2291] Cleanup/improve other async queries in some client handlers. Signed-off-by: Jason Volk --- src/admin/debug/commands.rs | 4 +- src/admin/processor.rs | 3 +- src/admin/user/commands.rs | 5 +- src/api/client/membership.rs | 2771 -------------------------- src/api/client/membership/ban.rs | 60 + src/api/client/membership/forget.rs | 52 + src/api/client/membership/invite.rs | 238 +++ src/api/client/membership/join.rs | 988 +++++++++ src/api/client/membership/kick.rs | 65 + src/api/client/membership/knock.rs | 767 +++++++ src/api/client/membership/leave.rs | 386 ++++ src/api/client/membership/members.rs | 147 ++ src/api/client/membership/mod.rs | 156 ++ src/api/client/membership/unban.rs | 58 + src/api/client/profile.rs | 54 +- src/api/client/room/initial_sync.rs | 41 +- 16 files changed, 2977 insertions(+), 2818 deletions(-) delete mode 100644 src/api/client/membership.rs create mode 100644 src/api/client/membership/ban.rs create mode 100644 src/api/client/membership/forget.rs create mode 100644 src/api/client/membership/invite.rs create mode 100644 src/api/client/membership/join.rs create mode 100644 src/api/client/membership/kick.rs create mode 100644 src/api/client/membership/knock.rs create mode 100644 src/api/client/membership/leave.rs create mode 100644 src/api/client/membership/members.rs create mode 100644 src/api/client/membership/mod.rs create mode 100644 src/api/client/membership/unban.rs diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index 2323e3b8..74355311 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -412,7 +412,9 @@ pub(super) async fn change_log_level(&self, filter: Option, reset: bool) .reload .reload(&new_filter_layer, Some(handles)) { - | Ok(()) => return self.write_str("Successfully changed log level").await, + | Ok(()) => { + return self.write_str("Successfully changed log level").await; + }, | Err(e) => { return Err!("Failed to modify and reload the global tracing log level: {e}"); }, diff --git a/src/admin/processor.rs b/src/admin/processor.rs index 8d1fe89c..e80000c1 100644 --- a/src/admin/processor.rs +++ b/src/admin/processor.rs @@ -94,8 +94,7 @@ async fn process_command(services: Arc, input: &CommandInput) -> Proce #[allow(clippy::result_large_err)] fn handle_panic(error: &Error, command: &CommandInput) -> ProcessorResult { - let link = - "Please submit a [bug report](https://forgejo.ellis.link/continuwuation/continuwuity/issues/new). 🥺"; + let link = "Please submit a [bug report](https://forgejo.ellis.link/continuwuation/continuwuity/issues/new). 🥺"; let msg = format!("Panic occurred while processing command:\n```\n{error:#?}\n```\n{link}"); let content = RoomMessageEventContent::notice_markdown(msg); error!("Panic while processing command: {error:?}"); diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 3750d758..e15c0b2c 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -286,8 +286,9 @@ pub(super) async fn reset_password(&self, username: String, password: Option return Err!("Couldn't reset the password for user {user_id}: {e}"), - | Ok(()) => - write!(self, "Successfully reset the password for user {user_id}: `{new_password}`"), + | Ok(()) => { + write!(self, "Successfully reset the password for user {user_id}: `{new_password}`") + }, } .await } diff --git a/src/api/client/membership.rs b/src/api/client/membership.rs deleted file mode 100644 index 3c2a6fe3..00000000 --- a/src/api/client/membership.rs +++ /dev/null @@ -1,2771 +0,0 @@ -use std::{ - borrow::Borrow, - collections::{HashMap, HashSet}, - iter::once, - net::IpAddr, - sync::Arc, -}; - -use axum::extract::State; -use axum_client_ip::InsecureClientIp; -use conduwuit::{ - Err, Event, Result, at, debug, debug_error, debug_info, debug_warn, err, error, info, - is_matching, - matrix::{ - StateKey, - pdu::{PduBuilder, PduEvent, gen_event_id, gen_event_id_canonical_json}, - state_res, - }, - result::{FlatOk, NotFound}, - trace, - utils::{ - self, FutureBoolExt, - future::ReadyEqExt, - shuffle, - stream::{BroadbandExt, IterStream, ReadyExt}, - }, - warn, -}; -use conduwuit_service::{ - Services, - appservice::RegistrationInfo, - rooms::{ - state::RoomMutexGuard, - state_compressor::{CompressedState, HashSetCompressStateEvent}, - }, -}; -use futures::{FutureExt, StreamExt, TryFutureExt, join, pin_mut}; -use ruma::{ - CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedServerName, - OwnedUserId, RoomId, RoomVersionId, ServerName, UserId, - api::{ - client::{ - error::ErrorKind, - knock::knock_room, - membership::{ - ThirdPartySigned, ban_user, forget_room, - get_member_events::{self, v3::MembershipEventFilter}, - invite_user, join_room_by_id, join_room_by_id_or_alias, - joined_members::{self, v3::RoomMember}, - joined_rooms, kick_user, leave_room, unban_user, - }, - }, - federation::{self, membership::create_invite}, - }, - canonical_json::to_canonical_value, - events::{ - StateEventType, - room::{ - join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent}, - member::{MembershipState, RoomMemberEventContent}, - }, - }, -}; - -use crate::{Ruma, client::full_user_deactivate}; - -/// Checks if the room is banned in any way possible and the sender user is not -/// an admin. -/// -/// Performs automatic deactivation if `auto_deactivate_banned_room_attempts` is -/// enabled -#[tracing::instrument(skip(services))] -async fn banned_room_check( - services: &Services, - user_id: &UserId, - room_id: Option<&RoomId>, - server_name: Option<&ServerName>, - client_ip: IpAddr, -) -> Result { - if services.users.is_admin(user_id).await { - return Ok(()); - } - - if let Some(room_id) = room_id { - if services.rooms.metadata.is_banned(room_id).await - || services - .moderation - .is_remote_server_forbidden(room_id.server_name().expect("legacy room mxid")) - { - warn!( - "User {user_id} who is not an admin attempted to send an invite for or \ - attempted to join a banned room or banned room server name: {room_id}" - ); - - if services.server.config.auto_deactivate_banned_room_attempts { - warn!( - "Automatically deactivating user {user_id} due to attempted banned room join" - ); - - if services.server.config.admin_room_notices { - services - .admin - .send_text(&format!( - "Automatically deactivating user {user_id} due to attempted banned \ - room join from IP {client_ip}" - )) - .await; - } - - let all_joined_rooms: Vec = services - .rooms - .state_cache - .rooms_joined(user_id) - .map(Into::into) - .collect() - .await; - - full_user_deactivate(services, user_id, &all_joined_rooms) - .boxed() - .await?; - } - - return Err!(Request(Forbidden("This room is banned on this homeserver."))); - } - } else if let Some(server_name) = server_name { - if services - .config - .forbidden_remote_server_names - .is_match(server_name.host()) - { - warn!( - "User {user_id} who is not an admin tried joining a room which has the server \ - name {server_name} that is globally forbidden. Rejecting.", - ); - - if services.server.config.auto_deactivate_banned_room_attempts { - warn!( - "Automatically deactivating user {user_id} due to attempted banned room join" - ); - - if services.server.config.admin_room_notices { - services - .admin - .send_text(&format!( - "Automatically deactivating user {user_id} due to attempted banned \ - room join from IP {client_ip}" - )) - .await; - } - - let all_joined_rooms: Vec = services - .rooms - .state_cache - .rooms_joined(user_id) - .map(Into::into) - .collect() - .await; - - full_user_deactivate(services, user_id, &all_joined_rooms) - .boxed() - .await?; - } - - return Err!(Request(Forbidden("This remote server is banned on this homeserver."))); - } - } - - Ok(()) -} - -/// # `POST /_matrix/client/r0/rooms/{roomId}/join` -/// -/// Tries to join the sender user into a room. -/// -/// - If the server knowns about this room: creates the join event and does auth -/// rules locally -/// - If the server does not know about the room: asks other servers over -/// federation -#[tracing::instrument(skip_all, fields(%client), name = "join")] -pub(crate) async fn join_room_by_id_route( - State(services): State, - InsecureClientIp(client): InsecureClientIp, - body: Ruma, -) -> Result { - let sender_user = body.sender_user(); - if services.users.is_suspended(sender_user).await? { - return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); - } - - banned_room_check( - &services, - sender_user, - Some(&body.room_id), - body.room_id.server_name(), - client, - ) - .await?; - - // There is no body.server_name for /roomId/join - let mut servers: Vec<_> = services - .rooms - .state_cache - .servers_invite_via(&body.room_id) - .map(ToOwned::to_owned) - .collect() - .await; - - servers.extend( - services - .rooms - .state_cache - .invite_state(sender_user, &body.room_id) - .await - .unwrap_or_default() - .iter() - .filter_map(|event| event.get_field("sender").ok().flatten()) - .filter_map(|sender: &str| UserId::parse(sender).ok()) - .map(|user| user.server_name().to_owned()), - ); - - if let Some(server) = body.room_id.server_name() { - servers.push(server.into()); - } - - servers.sort_unstable(); - servers.dedup(); - shuffle(&mut servers); - - join_room_by_id_helper( - &services, - sender_user, - &body.room_id, - body.reason.clone(), - &servers, - body.third_party_signed.as_ref(), - &body.appservice_info, - ) - .boxed() - .await -} - -/// # `POST /_matrix/client/r0/join/{roomIdOrAlias}` -/// -/// Tries to join the sender user into a room. -/// -/// - If the server knowns about this room: creates the join event and does auth -/// rules locally -/// - If the server does not know about the room: use the server name query -/// param if specified. if not specified, asks other servers over federation -/// via room alias server name and room ID server name -#[tracing::instrument(skip_all, fields(%client), name = "join")] -pub(crate) async fn join_room_by_id_or_alias_route( - State(services): State, - InsecureClientIp(client): InsecureClientIp, - body: Ruma, -) -> Result { - let sender_user = body.sender_user(); - let appservice_info = &body.appservice_info; - let body = &body.body; - if services.users.is_suspended(sender_user).await? { - return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); - } - - let (servers, room_id) = match OwnedRoomId::try_from(body.room_id_or_alias.clone()) { - | Ok(room_id) => { - banned_room_check( - &services, - sender_user, - Some(&room_id), - room_id.server_name(), - client, - ) - .boxed() - .await?; - - let mut servers = body.via.clone(); - servers.extend( - services - .rooms - .state_cache - .servers_invite_via(&room_id) - .map(ToOwned::to_owned) - .collect::>() - .await, - ); - - servers.extend( - services - .rooms - .state_cache - .invite_state(sender_user, &room_id) - .await - .unwrap_or_default() - .iter() - .filter_map(|event| event.get_field("sender").ok().flatten()) - .filter_map(|sender: &str| UserId::parse(sender).ok()) - .map(|user| user.server_name().to_owned()), - ); - - if let Some(server) = room_id.server_name() { - servers.push(server.to_owned()); - } - - servers.sort_unstable(); - servers.dedup(); - shuffle(&mut servers); - - (servers, room_id) - }, - | Err(room_alias) => { - let (room_id, mut servers) = services - .rooms - .alias - .resolve_alias(&room_alias, Some(body.via.clone())) - .await?; - - banned_room_check( - &services, - sender_user, - Some(&room_id), - Some(room_alias.server_name()), - client, - ) - .await?; - - let addl_via_servers = services - .rooms - .state_cache - .servers_invite_via(&room_id) - .map(ToOwned::to_owned); - - let addl_state_servers = services - .rooms - .state_cache - .invite_state(sender_user, &room_id) - .await - .unwrap_or_default(); - - let mut addl_servers: Vec<_> = addl_state_servers - .iter() - .map(|event| event.get_field("sender")) - .filter_map(FlatOk::flat_ok) - .map(|user: &UserId| user.server_name().to_owned()) - .stream() - .chain(addl_via_servers) - .collect() - .await; - - addl_servers.sort_unstable(); - addl_servers.dedup(); - shuffle(&mut addl_servers); - servers.append(&mut addl_servers); - - (servers, room_id) - }, - }; - - let join_room_response = join_room_by_id_helper( - &services, - sender_user, - &room_id, - body.reason.clone(), - &servers, - body.third_party_signed.as_ref(), - appservice_info, - ) - .boxed() - .await?; - - Ok(join_room_by_id_or_alias::v3::Response { room_id: join_room_response.room_id }) -} - -/// # `POST /_matrix/client/*/knock/{roomIdOrAlias}` -/// -/// Tries to knock the room to ask permission to join for the sender user. -#[tracing::instrument(skip_all, fields(%client), name = "knock")] -pub(crate) async fn knock_room_route( - State(services): State, - InsecureClientIp(client): InsecureClientIp, - body: Ruma, -) -> Result { - let sender_user = body.sender_user(); - let body = &body.body; - if services.users.is_suspended(sender_user).await? { - return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); - } - - let (servers, room_id) = match OwnedRoomId::try_from(body.room_id_or_alias.clone()) { - | Ok(room_id) => { - banned_room_check( - &services, - sender_user, - Some(&room_id), - room_id.server_name(), - client, - ) - .await?; - - let mut servers = body.via.clone(); - servers.extend( - services - .rooms - .state_cache - .servers_invite_via(&room_id) - .map(ToOwned::to_owned) - .collect::>() - .await, - ); - - servers.extend( - services - .rooms - .state_cache - .invite_state(sender_user, &room_id) - .await - .unwrap_or_default() - .iter() - .filter_map(|event| event.get_field("sender").ok().flatten()) - .filter_map(|sender: &str| UserId::parse(sender).ok()) - .map(|user| user.server_name().to_owned()), - ); - - if let Some(server) = room_id.server_name() { - servers.push(server.to_owned()); - } - - servers.sort_unstable(); - servers.dedup(); - shuffle(&mut servers); - - (servers, room_id) - }, - | Err(room_alias) => { - let (room_id, mut servers) = services - .rooms - .alias - .resolve_alias(&room_alias, Some(body.via.clone())) - .await?; - - banned_room_check( - &services, - sender_user, - Some(&room_id), - Some(room_alias.server_name()), - client, - ) - .await?; - - let addl_via_servers = services - .rooms - .state_cache - .servers_invite_via(&room_id) - .map(ToOwned::to_owned); - - let addl_state_servers = services - .rooms - .state_cache - .invite_state(sender_user, &room_id) - .await - .unwrap_or_default(); - - let mut addl_servers: Vec<_> = addl_state_servers - .iter() - .map(|event| event.get_field("sender")) - .filter_map(FlatOk::flat_ok) - .map(|user: &UserId| user.server_name().to_owned()) - .stream() - .chain(addl_via_servers) - .collect() - .await; - - addl_servers.sort_unstable(); - addl_servers.dedup(); - shuffle(&mut addl_servers); - servers.append(&mut addl_servers); - - (servers, room_id) - }, - }; - - knock_room_by_id_helper(&services, sender_user, &room_id, body.reason.clone(), &servers) - .boxed() - .await -} - -/// # `POST /_matrix/client/v3/rooms/{roomId}/leave` -/// -/// Tries to leave the sender user from a room. -/// -/// - This should always work if the user is currently joined. -pub(crate) async fn leave_room_route( - State(services): State, - body: Ruma, -) -> Result { - leave_room(&services, body.sender_user(), &body.room_id, body.reason.clone()) - .boxed() - .await - .map(|()| leave_room::v3::Response::new()) -} - -/// # `POST /_matrix/client/r0/rooms/{roomId}/invite` -/// -/// Tries to send an invite event into the room. -#[tracing::instrument(skip_all, fields(%client), name = "invite")] -pub(crate) async fn invite_user_route( - State(services): State, - InsecureClientIp(client): InsecureClientIp, - body: Ruma, -) -> Result { - let sender_user = body.sender_user(); - if services.users.is_suspended(sender_user).await? { - return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); - } - - if !services.users.is_admin(sender_user).await && services.config.block_non_admin_invites { - debug_error!( - "User {sender_user} is not an admin and attempted to send an invite to room {}", - &body.room_id - ); - return Err!(Request(Forbidden("Invites are not allowed on this server."))); - } - - banned_room_check( - &services, - sender_user, - Some(&body.room_id), - body.room_id.server_name(), - client, - ) - .await?; - - match &body.recipient { - | invite_user::v3::InvitationRecipient::UserId { user_id } => { - let sender_ignored_recipient = services.users.user_is_ignored(sender_user, user_id); - let recipient_ignored_by_sender = - services.users.user_is_ignored(user_id, sender_user); - - let (sender_ignored_recipient, recipient_ignored_by_sender) = - join!(sender_ignored_recipient, recipient_ignored_by_sender); - - if sender_ignored_recipient { - return Ok(invite_user::v3::Response {}); - } - - if let Ok(target_user_membership) = services - .rooms - .state_accessor - .get_member(&body.room_id, user_id) - .await - { - if target_user_membership.membership == MembershipState::Ban { - return Err!(Request(Forbidden("User is banned from this room."))); - } - } - - if recipient_ignored_by_sender { - // silently drop the invite to the recipient if they've been ignored by the - // sender, pretend it worked - return Ok(invite_user::v3::Response {}); - } - - invite_helper( - &services, - sender_user, - user_id, - &body.room_id, - body.reason.clone(), - false, - ) - .boxed() - .await?; - - Ok(invite_user::v3::Response {}) - }, - | _ => { - Err!(Request(NotFound("User not found."))) - }, - } -} - -/// # `POST /_matrix/client/r0/rooms/{roomId}/kick` -/// -/// Tries to send a kick event into the room. -pub(crate) async fn kick_user_route( - State(services): State, - body: Ruma, -) -> Result { - let sender_user = body.sender_user(); - if services.users.is_suspended(sender_user).await? { - return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); - } - let state_lock = services.rooms.state.mutex.lock(&body.room_id).await; - - let Ok(event) = services - .rooms - .state_accessor - .get_member(&body.room_id, &body.user_id) - .await - else { - // copy synapse's behaviour of returning 200 without any change to the state - // instead of erroring on left users - return Ok(kick_user::v3::Response::new()); - }; - - if !matches!( - event.membership, - MembershipState::Invite | MembershipState::Knock | MembershipState::Join, - ) { - return Err!(Request(Forbidden( - "Cannot kick a user who is not apart of the room (current membership: {})", - event.membership - ))); - } - - services - .rooms - .timeline - .build_and_append_pdu( - PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent { - membership: MembershipState::Leave, - reason: body.reason.clone(), - is_direct: None, - join_authorized_via_users_server: None, - third_party_invite: None, - ..event - }), - sender_user, - &body.room_id, - &state_lock, - ) - .await?; - - drop(state_lock); - - Ok(kick_user::v3::Response::new()) -} - -/// # `POST /_matrix/client/r0/rooms/{roomId}/ban` -/// -/// Tries to send a ban event into the room. -pub(crate) async fn ban_user_route( - State(services): State, - body: Ruma, -) -> Result { - let sender_user = body.sender_user(); - - if sender_user == body.user_id { - return Err!(Request(Forbidden("You cannot ban yourself."))); - } - - if services.users.is_suspended(sender_user).await? { - return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); - } - - let state_lock = services.rooms.state.mutex.lock(&body.room_id).await; - - let current_member_content = services - .rooms - .state_accessor - .get_member(&body.room_id, &body.user_id) - .await - .unwrap_or_else(|_| RoomMemberEventContent::new(MembershipState::Ban)); - - services - .rooms - .timeline - .build_and_append_pdu( - PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent { - membership: MembershipState::Ban, - reason: body.reason.clone(), - displayname: None, // display name may be offensive - avatar_url: None, // avatar may be offensive - is_direct: None, - join_authorized_via_users_server: None, - third_party_invite: None, - redact_events: body.redact_events, - ..current_member_content - }), - sender_user, - &body.room_id, - &state_lock, - ) - .await?; - - drop(state_lock); - - Ok(ban_user::v3::Response::new()) -} - -/// # `POST /_matrix/client/r0/rooms/{roomId}/unban` -/// -/// Tries to send an unban event into the room. -pub(crate) async fn unban_user_route( - State(services): State, - body: Ruma, -) -> Result { - let sender_user = body.sender_user(); - if services.users.is_suspended(sender_user).await? { - return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); - } - let state_lock = services.rooms.state.mutex.lock(&body.room_id).await; - - let current_member_content = services - .rooms - .state_accessor - .get_member(&body.room_id, &body.user_id) - .await - .unwrap_or_else(|_| RoomMemberEventContent::new(MembershipState::Leave)); - - if current_member_content.membership != MembershipState::Ban { - return Err!(Request(Forbidden( - "Cannot unban a user who is not banned (current membership: {})", - current_member_content.membership - ))); - } - - services - .rooms - .timeline - .build_and_append_pdu( - PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent { - membership: MembershipState::Leave, - reason: body.reason.clone(), - join_authorized_via_users_server: None, - third_party_invite: None, - is_direct: None, - ..current_member_content - }), - sender_user, - &body.room_id, - &state_lock, - ) - .await?; - - drop(state_lock); - - Ok(unban_user::v3::Response::new()) -} - -/// # `POST /_matrix/client/v3/rooms/{roomId}/forget` -/// -/// Forgets about a room. -/// -/// - If the sender user currently left the room: Stops sender user from -/// receiving information about the room -/// -/// Note: Other devices of the user have no way of knowing the room was -/// forgotten, so this has to be called from every device -pub(crate) async fn forget_room_route( - State(services): State, - body: Ruma, -) -> Result { - let user_id = body.sender_user(); - let room_id = &body.room_id; - - let joined = services.rooms.state_cache.is_joined(user_id, room_id); - let knocked = services.rooms.state_cache.is_knocked(user_id, room_id); - let invited = services.rooms.state_cache.is_invited(user_id, room_id); - - pin_mut!(joined, knocked, invited); - if joined.or(knocked).or(invited).await { - return Err!(Request(Unknown("You must leave the room before forgetting it"))); - } - - let membership = services - .rooms - .state_accessor - .get_member(room_id, user_id) - .await; - - if membership.is_not_found() { - return Err!(Request(Unknown("No membership event was found, room was never joined"))); - } - - let non_membership = membership - .map(|member| member.membership) - .is_ok_and(is_matching!(MembershipState::Leave | MembershipState::Ban)); - - if non_membership || services.rooms.state_cache.is_left(user_id, room_id).await { - services.rooms.state_cache.forget(room_id, user_id); - } - - Ok(forget_room::v3::Response::new()) -} - -/// # `POST /_matrix/client/r0/joined_rooms` -/// -/// Lists all rooms the user has joined. -pub(crate) async fn joined_rooms_route( - State(services): State, - body: Ruma, -) -> Result { - Ok(joined_rooms::v3::Response { - joined_rooms: services - .rooms - .state_cache - .rooms_joined(body.sender_user()) - .map(ToOwned::to_owned) - .collect() - .await, - }) -} - -fn membership_filter( - pdu: PduEvent, - for_membership: Option<&MembershipEventFilter>, - not_membership: Option<&MembershipEventFilter>, -) -> Option { - let membership_state_filter = match for_membership { - | Some(MembershipEventFilter::Ban) => MembershipState::Ban, - | Some(MembershipEventFilter::Invite) => MembershipState::Invite, - | Some(MembershipEventFilter::Knock) => MembershipState::Knock, - | Some(MembershipEventFilter::Leave) => MembershipState::Leave, - | Some(_) | None => MembershipState::Join, - }; - - let not_membership_state_filter = match not_membership { - | Some(MembershipEventFilter::Ban) => MembershipState::Ban, - | Some(MembershipEventFilter::Invite) => MembershipState::Invite, - | Some(MembershipEventFilter::Join) => MembershipState::Join, - | Some(MembershipEventFilter::Knock) => MembershipState::Knock, - | Some(_) | None => MembershipState::Leave, - }; - - let evt_membership = pdu.get_content::().ok()?.membership; - - if for_membership.is_some() && not_membership.is_some() { - if membership_state_filter != evt_membership - || not_membership_state_filter == evt_membership - { - None - } else { - Some(pdu) - } - } else if for_membership.is_some() && not_membership.is_none() { - if membership_state_filter != evt_membership { - None - } else { - Some(pdu) - } - } else if not_membership.is_some() && for_membership.is_none() { - if not_membership_state_filter == evt_membership { - None - } else { - Some(pdu) - } - } else { - Some(pdu) - } -} - -/// # `POST /_matrix/client/r0/rooms/{roomId}/members` -/// -/// Lists all joined users in a room (TODO: at a specific point in time, with a -/// specific membership). -/// -/// - Only works if the user is currently joined -pub(crate) async fn get_member_events_route( - State(services): State, - body: Ruma, -) -> Result { - let sender_user = body.sender_user(); - let membership = body.membership.as_ref(); - let not_membership = body.not_membership.as_ref(); - - if !services - .rooms - .state_accessor - .user_can_see_state_events(sender_user, &body.room_id) - .await - { - return Err!(Request(Forbidden("You don't have permission to view this room."))); - } - - Ok(get_member_events::v3::Response { - chunk: services - .rooms - .state_accessor - .room_state_full(&body.room_id) - .ready_filter_map(Result::ok) - .ready_filter(|((ty, _), _)| *ty == StateEventType::RoomMember) - .map(at!(1)) - .ready_filter_map(|pdu| membership_filter(pdu, membership, not_membership)) - .map(Event::into_format) - .collect() - .await, - }) -} - -/// # `POST /_matrix/client/r0/rooms/{roomId}/joined_members` -/// -/// Lists all members of a room. -/// -/// - The sender user must be in the room -/// - TODO: An appservice just needs a puppet joined -pub(crate) async fn joined_members_route( - State(services): State, - body: Ruma, -) -> Result { - if !services - .rooms - .state_accessor - .user_can_see_state_events(body.sender_user(), &body.room_id) - .await - { - return Err!(Request(Forbidden("You don't have permission to view this room."))); - } - - Ok(joined_members::v3::Response { - joined: services - .rooms - .state_cache - .room_members(&body.room_id) - .map(ToOwned::to_owned) - .broad_then(|user_id| async move { - let member = RoomMember { - display_name: services.users.displayname(&user_id).await.ok(), - avatar_url: services.users.avatar_url(&user_id).await.ok(), - }; - - (user_id, member) - }) - .collect() - .await, - }) -} - -pub async fn join_room_by_id_helper( - services: &Services, - sender_user: &UserId, - room_id: &RoomId, - reason: Option, - servers: &[OwnedServerName], - third_party_signed: Option<&ThirdPartySigned>, - appservice_info: &Option, -) -> Result { - let state_lock = services.rooms.state.mutex.lock(room_id).await; - - let user_is_guest = services - .users - .is_deactivated(sender_user) - .await - .unwrap_or(false) - && appservice_info.is_none(); - - if user_is_guest && !services.rooms.state_accessor.guest_can_join(room_id).await { - return Err!(Request(Forbidden("Guests are not allowed to join this room"))); - } - - if services - .rooms - .state_cache - .is_joined(sender_user, room_id) - .await - { - debug_warn!("{sender_user} is already joined in {room_id}"); - return Ok(join_room_by_id::v3::Response { room_id: room_id.into() }); - } - - let server_in_room = services - .rooms - .state_cache - .server_in_room(services.globals.server_name(), room_id) - .await; - - // Only check our known membership if we're already in the room. - // See: https://forgejo.ellis.link/continuwuation/continuwuity/issues/855 - let membership = if server_in_room { - services - .rooms - .state_accessor - .get_member(room_id, sender_user) - .await - } else { - debug!("Ignoring local state for join {room_id}, we aren't in the room yet."); - Ok(RoomMemberEventContent::new(MembershipState::Leave)) - }; - if let Ok(m) = membership { - if m.membership == MembershipState::Ban { - debug_warn!("{sender_user} is banned from {room_id} but attempted to join"); - // TODO: return reason - return Err!(Request(Forbidden("You are banned from the room."))); - } - } - - let local_join = server_in_room - || servers.is_empty() - || (servers.len() == 1 && services.globals.server_is_ours(&servers[0])); - - if local_join { - join_room_by_id_helper_local( - services, - sender_user, - room_id, - reason, - servers, - third_party_signed, - state_lock, - ) - .boxed() - .await?; - } else { - // Ask a remote server if we are not participating in this room - join_room_by_id_helper_remote( - services, - sender_user, - room_id, - reason, - servers, - third_party_signed, - state_lock, - ) - .boxed() - .await?; - } - - Ok(join_room_by_id::v3::Response::new(room_id.to_owned())) -} - -#[tracing::instrument(skip_all, fields(%sender_user, %room_id), name = "join_remote")] -async fn join_room_by_id_helper_remote( - services: &Services, - sender_user: &UserId, - room_id: &RoomId, - reason: Option, - servers: &[OwnedServerName], - _third_party_signed: Option<&ThirdPartySigned>, - state_lock: RoomMutexGuard, -) -> Result { - info!("Joining {room_id} over federation."); - - let (make_join_response, remote_server) = - make_join_request(services, sender_user, room_id, servers).await?; - - info!("make_join finished"); - - let Some(room_version_id) = make_join_response.room_version else { - return Err!(BadServerResponse("Remote room version is not supported by conduwuit")); - }; - - if !services.server.supported_room_version(&room_version_id) { - return Err!(BadServerResponse( - "Remote room version {room_version_id} is not supported by conduwuit" - )); - } - - let mut join_event_stub: CanonicalJsonObject = - serde_json::from_str(make_join_response.event.get()).map_err(|e| { - err!(BadServerResponse(warn!( - "Invalid make_join event json received from server: {e:?}" - ))) - })?; - - let join_authorized_via_users_server = { - use RoomVersionId::*; - if !matches!(room_version_id, V1 | V2 | V3 | V4 | V5 | V6 | V7) { - join_event_stub - .get("content") - .map(|s| { - s.as_object()? - .get("join_authorised_via_users_server")? - .as_str() - }) - .and_then(|s| OwnedUserId::try_from(s.unwrap_or_default()).ok()) - } else { - None - } - }; - - join_event_stub.insert( - "origin".to_owned(), - CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()), - ); - join_event_stub.insert( - "origin_server_ts".to_owned(), - CanonicalJsonValue::Integer( - utils::millis_since_unix_epoch() - .try_into() - .expect("Timestamp is valid js_int value"), - ), - ); - join_event_stub.insert( - "content".to_owned(), - to_canonical_value(RoomMemberEventContent { - displayname: services.users.displayname(sender_user).await.ok(), - avatar_url: services.users.avatar_url(sender_user).await.ok(), - blurhash: services.users.blurhash(sender_user).await.ok(), - reason, - join_authorized_via_users_server: join_authorized_via_users_server.clone(), - ..RoomMemberEventContent::new(MembershipState::Join) - }) - .expect("event is valid, we just created it"), - ); - - // We keep the "event_id" in the pdu only in v1 or - // v2 rooms - match room_version_id { - | RoomVersionId::V1 | RoomVersionId::V2 => {}, - | _ => { - join_event_stub.remove("event_id"); - }, - } - - // In order to create a compatible ref hash (EventID) the `hashes` field needs - // to be present - services - .server_keys - .hash_and_sign_event(&mut join_event_stub, &room_version_id)?; - - // Generate event id - let event_id = gen_event_id(&join_event_stub, &room_version_id)?; - - // Add event_id back - join_event_stub - .insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into())); - - // It has enough fields to be called a proper event now - let mut join_event = join_event_stub; - - info!("Asking {remote_server} for send_join in room {room_id}"); - let send_join_request = federation::membership::create_join_event::v2::Request { - room_id: room_id.to_owned(), - event_id: event_id.clone(), - omit_members: false, - pdu: services - .sending - .convert_to_outgoing_federation_event(join_event.clone()) - .await, - }; - - let send_join_response = match services - .sending - .send_synapse_request(&remote_server, send_join_request) - .await - { - | Ok(response) => response, - | Err(e) => { - error!("send_join failed: {e}"); - return Err(e); - }, - }; - - info!("send_join finished"); - - if join_authorized_via_users_server.is_some() { - if let Some(signed_raw) = &send_join_response.room_state.event { - debug_info!( - "There is a signed event with join_authorized_via_users_server. This room is \ - probably using restricted joins. Adding signature to our event" - ); - - let (signed_event_id, signed_value) = - gen_event_id_canonical_json(signed_raw, &room_version_id).map_err(|e| { - err!(Request(BadJson(warn!( - "Could not convert event to canonical JSON: {e}" - )))) - })?; - - if signed_event_id != event_id { - return Err!(Request(BadJson(warn!( - %signed_event_id, %event_id, - "Server {remote_server} sent event with wrong event ID" - )))); - } - - match signed_value["signatures"] - .as_object() - .ok_or_else(|| { - err!(BadServerResponse(warn!( - "Server {remote_server} sent invalid signatures type" - ))) - }) - .and_then(|e| { - e.get(remote_server.as_str()).ok_or_else(|| { - err!(BadServerResponse(warn!( - "Server {remote_server} did not send its signature for a restricted \ - room" - ))) - }) - }) { - | Ok(signature) => { - join_event - .get_mut("signatures") - .expect("we created a valid pdu") - .as_object_mut() - .expect("we created a valid pdu") - .insert(remote_server.to_string(), signature.clone()); - }, - | Err(e) => { - warn!( - "Server {remote_server} sent invalid signature in send_join signatures \ - for event {signed_value:?}: {e:?}", - ); - }, - } - } - } - - services - .rooms - .short - .get_or_create_shortroomid(room_id) - .await; - - info!("Parsing join event"); - let parsed_join_pdu = PduEvent::from_id_val(&event_id, join_event.clone()) - .map_err(|e| err!(BadServerResponse("Invalid join event PDU: {e:?}")))?; - - info!("Acquiring server signing keys for response events"); - let resp_events = &send_join_response.room_state; - let resp_state = &resp_events.state; - let resp_auth = &resp_events.auth_chain; - services - .server_keys - .acquire_events_pubkeys(resp_auth.iter().chain(resp_state.iter())) - .await; - - info!("Going through send_join response room_state"); - let cork = services.db.cork_and_flush(); - let state = send_join_response - .room_state - .state - .iter() - .stream() - .then(|pdu| { - services - .server_keys - .validate_and_add_event_id_no_fetch(pdu, &room_version_id) - }) - .ready_filter_map(Result::ok) - .fold(HashMap::new(), |mut state, (event_id, value)| async move { - let pdu = match PduEvent::from_id_val(&event_id, value.clone()) { - | Ok(pdu) => pdu, - | Err(e) => { - debug_warn!("Invalid PDU in send_join response: {e:?}: {value:#?}"); - return state; - }, - }; - - services.rooms.outlier.add_pdu_outlier(&event_id, &value); - if let Some(state_key) = &pdu.state_key { - let shortstatekey = services - .rooms - .short - .get_or_create_shortstatekey(&pdu.kind.to_string().into(), state_key) - .await; - - state.insert(shortstatekey, pdu.event_id.clone()); - } - - state - }) - .await; - - drop(cork); - - info!("Going through send_join response auth_chain"); - let cork = services.db.cork_and_flush(); - send_join_response - .room_state - .auth_chain - .iter() - .stream() - .then(|pdu| { - services - .server_keys - .validate_and_add_event_id_no_fetch(pdu, &room_version_id) - }) - .ready_filter_map(Result::ok) - .ready_for_each(|(event_id, value)| { - services.rooms.outlier.add_pdu_outlier(&event_id, &value); - }) - .await; - - drop(cork); - - debug!("Running send_join auth check"); - let fetch_state = &state; - let state_fetch = |k: StateEventType, s: StateKey| async move { - let shortstatekey = services.rooms.short.get_shortstatekey(&k, &s).await.ok()?; - - let event_id = fetch_state.get(&shortstatekey)?; - services.rooms.timeline.get_pdu(event_id).await.ok() - }; - - let auth_check = state_res::event_auth::auth_check( - &state_res::RoomVersion::new(&room_version_id)?, - &parsed_join_pdu, - None, // TODO: third party invite - |k, s| state_fetch(k.clone(), s.into()), - ) - .await - .map_err(|e| err!(Request(Forbidden(warn!("Auth check failed: {e:?}")))))?; - - if !auth_check { - return Err!(Request(Forbidden("Auth check failed"))); - } - - info!("Compressing state from send_join"); - let compressed: CompressedState = services - .rooms - .state_compressor - .compress_state_events(state.iter().map(|(ssk, eid)| (ssk, eid.borrow()))) - .collect() - .await; - - debug!("Saving compressed state"); - let HashSetCompressStateEvent { - shortstatehash: statehash_before_join, - added, - removed, - } = services - .rooms - .state_compressor - .save_state(room_id, Arc::new(compressed)) - .await?; - - debug!("Forcing state for new room"); - services - .rooms - .state - .force_state(room_id, statehash_before_join, added, removed, &state_lock) - .await?; - - info!("Updating joined counts for new room"); - services - .rooms - .state_cache - .update_joined_count(room_id) - .await; - - // We append to state before appending the pdu, so we don't have a moment in - // time with the pdu without it's state. This is okay because append_pdu can't - // fail. - let statehash_after_join = services - .rooms - .state - .append_to_state(&parsed_join_pdu) - .await?; - - info!("Appending new room join event"); - services - .rooms - .timeline - .append_pdu( - &parsed_join_pdu, - join_event, - once(parsed_join_pdu.event_id.borrow()), - &state_lock, - ) - .await?; - - info!("Setting final room state for new room"); - // We set the room state after inserting the pdu, so that we never have a moment - // in time where events in the current room state do not exist - services - .rooms - .state - .set_room_state(room_id, statehash_after_join, &state_lock); - - Ok(()) -} - -#[tracing::instrument(skip_all, fields(%sender_user, %room_id), name = "join_local")] -async fn join_room_by_id_helper_local( - services: &Services, - sender_user: &UserId, - room_id: &RoomId, - reason: Option, - servers: &[OwnedServerName], - _third_party_signed: Option<&ThirdPartySigned>, - state_lock: RoomMutexGuard, -) -> Result { - debug_info!("We can join locally"); - - let join_rules_event_content = services - .rooms - .state_accessor - .room_state_get_content::( - room_id, - &StateEventType::RoomJoinRules, - "", - ) - .await; - - let restriction_rooms = match join_rules_event_content { - | Ok(RoomJoinRulesEventContent { - join_rule: JoinRule::Restricted(restricted) | JoinRule::KnockRestricted(restricted), - }) => restricted - .allow - .into_iter() - .filter_map(|a| match a { - | AllowRule::RoomMembership(r) => Some(r.room_id), - | _ => None, - }) - .collect(), - | _ => Vec::new(), - }; - - let join_authorized_via_users_server: Option = { - if restriction_rooms - .iter() - .stream() - .any(|restriction_room_id| { - services - .rooms - .state_cache - .is_joined(sender_user, restriction_room_id) - }) - .await - { - services - .rooms - .state_cache - .local_users_in_room(room_id) - .filter(|user| { - services.rooms.state_accessor.user_can_invite( - room_id, - user, - sender_user, - &state_lock, - ) - }) - .boxed() - .next() - .await - .map(ToOwned::to_owned) - } else { - None - } - }; - - let content = RoomMemberEventContent { - displayname: services.users.displayname(sender_user).await.ok(), - avatar_url: services.users.avatar_url(sender_user).await.ok(), - blurhash: services.users.blurhash(sender_user).await.ok(), - reason: reason.clone(), - join_authorized_via_users_server, - ..RoomMemberEventContent::new(MembershipState::Join) - }; - - // Try normal join first - let Err(error) = services - .rooms - .timeline - .build_and_append_pdu( - PduBuilder::state(sender_user.to_string(), &content), - sender_user, - room_id, - &state_lock, - ) - .await - else { - return Ok(()); - }; - - if restriction_rooms.is_empty() - && (servers.is_empty() - || servers.len() == 1 && services.globals.server_is_ours(&servers[0])) - { - return Err(error); - } - - warn!( - "We couldn't do the join locally, maybe federation can help to satisfy the restricted \ - join requirements" - ); - let Ok((make_join_response, remote_server)) = - make_join_request(services, sender_user, room_id, servers).await - else { - return Err(error); - }; - - let Some(room_version_id) = make_join_response.room_version else { - return Err!(BadServerResponse("Remote room version is not supported by conduwuit")); - }; - - if !services.server.supported_room_version(&room_version_id) { - return Err!(BadServerResponse( - "Remote room version {room_version_id} is not supported by conduwuit" - )); - } - - let mut join_event_stub: CanonicalJsonObject = - serde_json::from_str(make_join_response.event.get()).map_err(|e| { - err!(BadServerResponse("Invalid make_join event json received from server: {e:?}")) - })?; - - let join_authorized_via_users_server = join_event_stub - .get("content") - .map(|s| { - s.as_object()? - .get("join_authorised_via_users_server")? - .as_str() - }) - .and_then(|s| OwnedUserId::try_from(s.unwrap_or_default()).ok()); - - join_event_stub.insert( - "origin".to_owned(), - CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()), - ); - join_event_stub.insert( - "origin_server_ts".to_owned(), - CanonicalJsonValue::Integer( - utils::millis_since_unix_epoch() - .try_into() - .expect("Timestamp is valid js_int value"), - ), - ); - join_event_stub.insert( - "content".to_owned(), - to_canonical_value(RoomMemberEventContent { - displayname: services.users.displayname(sender_user).await.ok(), - avatar_url: services.users.avatar_url(sender_user).await.ok(), - blurhash: services.users.blurhash(sender_user).await.ok(), - reason, - join_authorized_via_users_server, - ..RoomMemberEventContent::new(MembershipState::Join) - }) - .expect("event is valid, we just created it"), - ); - - // We keep the "event_id" in the pdu only in v1 or - // v2 rooms - match room_version_id { - | RoomVersionId::V1 | RoomVersionId::V2 => {}, - | _ => { - join_event_stub.remove("event_id"); - }, - } - - // In order to create a compatible ref hash (EventID) the `hashes` field needs - // to be present - services - .server_keys - .hash_and_sign_event(&mut join_event_stub, &room_version_id)?; - - // Generate event id - let event_id = gen_event_id(&join_event_stub, &room_version_id)?; - - // Add event_id back - join_event_stub - .insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into())); - - // It has enough fields to be called a proper event now - let join_event = join_event_stub; - - let send_join_response = services - .sending - .send_synapse_request( - &remote_server, - federation::membership::create_join_event::v2::Request { - room_id: room_id.to_owned(), - event_id: event_id.clone(), - omit_members: false, - pdu: services - .sending - .convert_to_outgoing_federation_event(join_event.clone()) - .await, - }, - ) - .await?; - - if let Some(signed_raw) = send_join_response.room_state.event { - let (signed_event_id, signed_value) = - gen_event_id_canonical_json(&signed_raw, &room_version_id).map_err(|e| { - err!(Request(BadJson(warn!("Could not convert event to canonical JSON: {e}")))) - })?; - - if signed_event_id != event_id { - return Err!(Request(BadJson( - warn!(%signed_event_id, %event_id, "Server {remote_server} sent event with wrong event ID") - ))); - } - - drop(state_lock); - services - .rooms - .event_handler - .handle_incoming_pdu(&remote_server, room_id, &signed_event_id, signed_value, true) - .boxed() - .await?; - } else { - return Err(error); - } - - Ok(()) -} - -async fn make_join_request( - services: &Services, - sender_user: &UserId, - room_id: &RoomId, - servers: &[OwnedServerName], -) -> Result<(federation::membership::prepare_join_event::v1::Response, OwnedServerName)> { - let mut make_join_response_and_server = - Err!(BadServerResponse("No server available to assist in joining.")); - - let mut make_join_counter: usize = 0; - let mut incompatible_room_version_count: usize = 0; - - for remote_server in servers { - if services.globals.server_is_ours(remote_server) { - continue; - } - info!("Asking {remote_server} for make_join ({make_join_counter})"); - let make_join_response = services - .sending - .send_federation_request( - remote_server, - federation::membership::prepare_join_event::v1::Request { - room_id: room_id.to_owned(), - user_id: sender_user.to_owned(), - ver: services.server.supported_room_versions().collect(), - }, - ) - .await; - - trace!("make_join response: {:?}", make_join_response); - make_join_counter = make_join_counter.saturating_add(1); - - if let Err(ref e) = make_join_response { - if matches!( - e.kind(), - ErrorKind::IncompatibleRoomVersion { .. } | ErrorKind::UnsupportedRoomVersion - ) { - incompatible_room_version_count = - incompatible_room_version_count.saturating_add(1); - } - - if incompatible_room_version_count > 15 { - info!( - "15 servers have responded with M_INCOMPATIBLE_ROOM_VERSION or \ - M_UNSUPPORTED_ROOM_VERSION, assuming that conduwuit does not support the \ - room version {room_id}: {e}" - ); - make_join_response_and_server = - Err!(BadServerResponse("Room version is not supported by Conduwuit")); - return make_join_response_and_server; - } - - if make_join_counter > 40 { - warn!( - "40 servers failed to provide valid make_join response, assuming no server \ - can assist in joining." - ); - make_join_response_and_server = - Err!(BadServerResponse("No server available to assist in joining.")); - - return make_join_response_and_server; - } - } - - make_join_response_and_server = make_join_response.map(|r| (r, remote_server.clone())); - - if make_join_response_and_server.is_ok() { - break; - } - } - - make_join_response_and_server -} - -pub(crate) async fn invite_helper( - services: &Services, - sender_user: &UserId, - user_id: &UserId, - room_id: &RoomId, - reason: Option, - is_direct: bool, -) -> Result { - if !services.users.is_admin(sender_user).await && services.config.block_non_admin_invites { - info!( - "User {sender_user} is not an admin and attempted to send an invite to room \ - {room_id}" - ); - return Err!(Request(Forbidden("Invites are not allowed on this server."))); - } - - if !services.globals.user_is_local(user_id) { - let (pdu, pdu_json, invite_room_state) = { - let state_lock = services.rooms.state.mutex.lock(room_id).await; - - let content = RoomMemberEventContent { - avatar_url: services.users.avatar_url(user_id).await.ok(), - is_direct: Some(is_direct), - reason, - ..RoomMemberEventContent::new(MembershipState::Invite) - }; - - let (pdu, pdu_json) = services - .rooms - .timeline - .create_hash_and_sign_event( - PduBuilder::state(user_id.to_string(), &content), - sender_user, - room_id, - &state_lock, - ) - .await?; - - let invite_room_state = services.rooms.state.summary_stripped(&pdu).await; - - drop(state_lock); - - (pdu, pdu_json, invite_room_state) - }; - - let room_version_id = services.rooms.state.get_room_version(room_id).await?; - - let response = services - .sending - .send_federation_request(user_id.server_name(), create_invite::v2::Request { - room_id: room_id.to_owned(), - event_id: (*pdu.event_id).to_owned(), - room_version: room_version_id.clone(), - event: services - .sending - .convert_to_outgoing_federation_event(pdu_json.clone()) - .await, - invite_room_state, - via: services - .rooms - .state_cache - .servers_route_via(room_id) - .await - .ok(), - }) - .await?; - - // We do not add the event_id field to the pdu here because of signature and - // hashes checks - let (event_id, value) = gen_event_id_canonical_json(&response.event, &room_version_id) - .map_err(|e| { - err!(Request(BadJson(warn!("Could not convert event to canonical JSON: {e}")))) - })?; - - if pdu.event_id != event_id { - return Err!(Request(BadJson(warn!( - %pdu.event_id, %event_id, - "Server {} sent event with wrong event ID", - user_id.server_name() - )))); - } - - let origin: OwnedServerName = serde_json::from_value(serde_json::to_value( - value - .get("origin") - .ok_or_else(|| err!(Request(BadJson("Event missing origin field."))))?, - )?) - .map_err(|e| { - err!(Request(BadJson(warn!("Origin field in event is not a valid server name: {e}")))) - })?; - - let pdu_id = services - .rooms - .event_handler - .handle_incoming_pdu(&origin, room_id, &event_id, value, true) - .boxed() - .await? - .ok_or_else(|| { - err!(Request(InvalidParam("Could not accept incoming PDU as timeline event."))) - })?; - - return services.sending.send_pdu_room(room_id, &pdu_id).await; - } - - if !services - .rooms - .state_cache - .is_joined(sender_user, room_id) - .await - { - return Err!(Request(Forbidden( - "You must be joined in the room you are trying to invite from." - ))); - } - - let state_lock = services.rooms.state.mutex.lock(room_id).await; - - let content = RoomMemberEventContent { - displayname: services.users.displayname(user_id).await.ok(), - avatar_url: services.users.avatar_url(user_id).await.ok(), - blurhash: services.users.blurhash(user_id).await.ok(), - is_direct: Some(is_direct), - reason, - ..RoomMemberEventContent::new(MembershipState::Invite) - }; - - services - .rooms - .timeline - .build_and_append_pdu( - PduBuilder::state(user_id.to_string(), &content), - sender_user, - room_id, - &state_lock, - ) - .await?; - - drop(state_lock); - - Ok(()) -} - -// Make a user leave all their joined rooms, rescinds knocks, forgets all rooms, -// and ignores errors -pub async fn leave_all_rooms(services: &Services, user_id: &UserId) { - let rooms_joined = services - .rooms - .state_cache - .rooms_joined(user_id) - .map(ToOwned::to_owned); - - let rooms_invited = services - .rooms - .state_cache - .rooms_invited(user_id) - .map(|(r, _)| r); - - let rooms_knocked = services - .rooms - .state_cache - .rooms_knocked(user_id) - .map(|(r, _)| r); - - let all_rooms: Vec<_> = rooms_joined - .chain(rooms_invited) - .chain(rooms_knocked) - .collect() - .await; - - for room_id in all_rooms { - // ignore errors - if let Err(e) = leave_room(services, user_id, &room_id, None).boxed().await { - warn!(%user_id, "Failed to leave {room_id} remotely: {e}"); - } - - services.rooms.state_cache.forget(&room_id, user_id); - } -} - -pub async fn leave_room( - services: &Services, - user_id: &UserId, - room_id: &RoomId, - reason: Option, -) -> Result { - let default_member_content = RoomMemberEventContent { - membership: MembershipState::Leave, - reason: reason.clone(), - join_authorized_via_users_server: None, - is_direct: None, - avatar_url: None, - displayname: None, - third_party_invite: None, - blurhash: None, - redact_events: None, - }; - - let is_banned = services.rooms.metadata.is_banned(room_id); - let is_disabled = services.rooms.metadata.is_disabled(room_id); - - pin_mut!(is_banned, is_disabled); - if is_banned.or(is_disabled).await { - // the room is banned/disabled, the room must be rejected locally since we - // cant/dont want to federate with this server - services - .rooms - .state_cache - .update_membership( - room_id, - user_id, - default_member_content, - user_id, - None, - None, - true, - ) - .await?; - - return Ok(()); - } - - let dont_have_room = services - .rooms - .state_cache - .server_in_room(services.globals.server_name(), room_id) - .eq(&false); - - let not_knocked = services - .rooms - .state_cache - .is_knocked(user_id, room_id) - .eq(&false); - - // Ask a remote server if we don't have this room and are not knocking on it - if dont_have_room.and(not_knocked).await { - if let Err(e) = remote_leave_room(services, user_id, room_id, reason.clone()) - .boxed() - .await - { - warn!(%user_id, "Failed to leave room {room_id} remotely: {e}"); - // Don't tell the client about this error - } - - let last_state = services - .rooms - .state_cache - .invite_state(user_id, room_id) - .or_else(|_| services.rooms.state_cache.knock_state(user_id, room_id)) - .or_else(|_| services.rooms.state_cache.left_state(user_id, room_id)) - .await - .ok(); - - // We always drop the invite, we can't rely on other servers - services - .rooms - .state_cache - .update_membership( - room_id, - user_id, - default_member_content, - user_id, - last_state, - None, - true, - ) - .await?; - } else { - let state_lock = services.rooms.state.mutex.lock(room_id).await; - - let Ok(event) = services - .rooms - .state_accessor - .room_state_get_content::( - room_id, - &StateEventType::RoomMember, - user_id.as_str(), - ) - .await - else { - debug_warn!( - "Trying to leave a room you are not a member of, marking room as left locally." - ); - - return services - .rooms - .state_cache - .update_membership( - room_id, - user_id, - default_member_content, - user_id, - None, - None, - true, - ) - .await; - }; - - services - .rooms - .timeline - .build_and_append_pdu( - PduBuilder::state(user_id.to_string(), &RoomMemberEventContent { - membership: MembershipState::Leave, - reason, - join_authorized_via_users_server: None, - is_direct: None, - ..event - }), - user_id, - room_id, - &state_lock, - ) - .await?; - } - - Ok(()) -} - -async fn remote_leave_room( - services: &Services, - user_id: &UserId, - room_id: &RoomId, - reason: Option, -) -> Result<()> { - let mut make_leave_response_and_server = - Err!(BadServerResponse("No remote server available to assist in leaving {room_id}.")); - - let mut servers: HashSet = services - .rooms - .state_cache - .servers_invite_via(room_id) - .map(ToOwned::to_owned) - .collect() - .await; - - match services - .rooms - .state_cache - .invite_state(user_id, room_id) - .await - { - | Ok(invite_state) => { - servers.extend( - invite_state - .iter() - .filter_map(|event| event.get_field("sender").ok().flatten()) - .filter_map(|sender: &str| UserId::parse(sender).ok()) - .map(|user| user.server_name().to_owned()), - ); - }, - | _ => { - match services - .rooms - .state_cache - .knock_state(user_id, room_id) - .await - { - | Ok(knock_state) => { - servers.extend( - knock_state - .iter() - .filter_map(|event| event.get_field("sender").ok().flatten()) - .filter_map(|sender: &str| UserId::parse(sender).ok()) - .filter_map(|sender| { - if !services.globals.user_is_local(sender) { - Some(sender.server_name().to_owned()) - } else { - None - } - }), - ); - }, - | _ => {}, - } - }, - } - - if let Some(room_id_server_name) = room_id.server_name() { - servers.insert(room_id_server_name.to_owned()); - } - - debug_info!("servers in remote_leave_room: {servers:?}"); - - for remote_server in servers { - let make_leave_response = services - .sending - .send_federation_request( - &remote_server, - federation::membership::prepare_leave_event::v1::Request { - room_id: room_id.to_owned(), - user_id: user_id.to_owned(), - }, - ) - .await; - - make_leave_response_and_server = make_leave_response.map(|r| (r, remote_server)); - - if make_leave_response_and_server.is_ok() { - break; - } - } - - let (make_leave_response, remote_server) = make_leave_response_and_server?; - - let Some(room_version_id) = make_leave_response.room_version else { - return Err!(BadServerResponse(warn!( - "No room version was returned by {remote_server} for {room_id}, room version is \ - likely not supported by conduwuit" - ))); - }; - - if !services.server.supported_room_version(&room_version_id) { - return Err!(BadServerResponse(warn!( - "Remote room version {room_version_id} for {room_id} is not supported by conduwuit", - ))); - } - - let mut leave_event_stub = serde_json::from_str::( - make_leave_response.event.get(), - ) - .map_err(|e| { - err!(BadServerResponse(warn!( - "Invalid make_leave event json received from {remote_server} for {room_id}: {e:?}" - ))) - })?; - - // TODO: Is origin needed? - leave_event_stub.insert( - "origin".to_owned(), - CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()), - ); - leave_event_stub.insert( - "origin_server_ts".to_owned(), - CanonicalJsonValue::Integer( - utils::millis_since_unix_epoch() - .try_into() - .expect("Timestamp is valid js_int value"), - ), - ); - // Inject the reason key into the event content dict if it exists - if let Some(reason) = reason { - if let Some(CanonicalJsonValue::Object(content)) = leave_event_stub.get_mut("content") { - content.insert("reason".to_owned(), CanonicalJsonValue::String(reason)); - } - } - - // room v3 and above removed the "event_id" field from remote PDU format - match room_version_id { - | RoomVersionId::V1 | RoomVersionId::V2 => {}, - | _ => { - leave_event_stub.remove("event_id"); - }, - } - - // In order to create a compatible ref hash (EventID) the `hashes` field needs - // to be present - services - .server_keys - .hash_and_sign_event(&mut leave_event_stub, &room_version_id)?; - - // Generate event id - let event_id = gen_event_id(&leave_event_stub, &room_version_id)?; - - // Add event_id back - leave_event_stub - .insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into())); - - // It has enough fields to be called a proper event now - let leave_event = leave_event_stub; - - services - .sending - .send_federation_request( - &remote_server, - federation::membership::create_leave_event::v2::Request { - room_id: room_id.to_owned(), - event_id, - pdu: services - .sending - .convert_to_outgoing_federation_event(leave_event.clone()) - .await, - }, - ) - .await?; - - Ok(()) -} - -async fn knock_room_by_id_helper( - services: &Services, - sender_user: &UserId, - room_id: &RoomId, - reason: Option, - servers: &[OwnedServerName], -) -> Result { - let state_lock = services.rooms.state.mutex.lock(room_id).await; - - if services - .rooms - .state_cache - .is_invited(sender_user, room_id) - .await - { - debug_warn!("{sender_user} is already invited in {room_id} but attempted to knock"); - return Err!(Request(Forbidden( - "You cannot knock on a room you are already invited/accepted to." - ))); - } - - if services - .rooms - .state_cache - .is_joined(sender_user, room_id) - .await - { - debug_warn!("{sender_user} is already joined in {room_id} but attempted to knock"); - return Err!(Request(Forbidden("You cannot knock on a room you are already joined in."))); - } - - if services - .rooms - .state_cache - .is_knocked(sender_user, room_id) - .await - { - debug_warn!("{sender_user} is already knocked in {room_id}"); - return Ok(knock_room::v3::Response { room_id: room_id.into() }); - } - - if let Ok(membership) = services - .rooms - .state_accessor - .get_member(room_id, sender_user) - .await - { - if membership.membership == MembershipState::Ban { - debug_warn!("{sender_user} is banned from {room_id} but attempted to knock"); - return Err!(Request(Forbidden("You cannot knock on a room you are banned from."))); - } - } - - // For knock_restricted rooms, check if the user meets the restricted conditions - // If they do, attempt to join instead of knock - // This is not mentioned in the spec, but should be allowable (we're allowed to - // auto-join invites to knocked rooms) - let join_rule = services.rooms.state_accessor.get_join_rules(room_id).await; - if let JoinRule::KnockRestricted(restricted) = &join_rule { - let restriction_rooms: Vec<_> = restricted - .allow - .iter() - .filter_map(|a| match a { - | AllowRule::RoomMembership(r) => Some(&r.room_id), - | _ => None, - }) - .collect(); - - // Check if the user is in any of the allowed rooms - let mut user_meets_restrictions = false; - for restriction_room_id in &restriction_rooms { - if services - .rooms - .state_cache - .is_joined(sender_user, restriction_room_id) - .await - { - user_meets_restrictions = true; - break; - } - } - - // If the user meets the restrictions, try joining instead - if user_meets_restrictions { - debug_info!( - "{sender_user} meets the restricted criteria in knock_restricted room \ - {room_id}, attempting to join instead of knock" - ); - // For this case, we need to drop the state lock and get a new one in - // join_room_by_id_helper We need to release the lock here and let - // join_room_by_id_helper acquire it again - drop(state_lock); - match join_room_by_id_helper( - services, - sender_user, - room_id, - reason.clone(), - servers, - None, - &None, - ) - .await - { - | Ok(_) => return Ok(knock_room::v3::Response::new(room_id.to_owned())), - | Err(e) => { - debug_warn!( - "Failed to convert knock to join for {sender_user} in {room_id}: {e:?}" - ); - // Get a new state lock for the remaining knock logic - let new_state_lock = services.rooms.state.mutex.lock(room_id).await; - - let server_in_room = services - .rooms - .state_cache - .server_in_room(services.globals.server_name(), room_id) - .await; - - let local_knock = server_in_room - || servers.is_empty() - || (servers.len() == 1 && services.globals.server_is_ours(&servers[0])); - - if local_knock { - knock_room_helper_local( - services, - sender_user, - room_id, - reason, - servers, - new_state_lock, - ) - .boxed() - .await?; - } else { - knock_room_helper_remote( - services, - sender_user, - room_id, - reason, - servers, - new_state_lock, - ) - .boxed() - .await?; - } - - return Ok(knock_room::v3::Response::new(room_id.to_owned())); - }, - } - } - } else if !matches!(join_rule, JoinRule::Knock | JoinRule::KnockRestricted(_)) { - debug_warn!( - "{sender_user} attempted to knock on room {room_id} but its join rule is \ - {join_rule:?}, not knock or knock_restricted" - ); - } - - let server_in_room = services - .rooms - .state_cache - .server_in_room(services.globals.server_name(), room_id) - .await; - - let local_knock = server_in_room - || servers.is_empty() - || (servers.len() == 1 && services.globals.server_is_ours(&servers[0])); - - if local_knock { - knock_room_helper_local(services, sender_user, room_id, reason, servers, state_lock) - .boxed() - .await?; - } else { - knock_room_helper_remote(services, sender_user, room_id, reason, servers, state_lock) - .boxed() - .await?; - } - - Ok(knock_room::v3::Response::new(room_id.to_owned())) -} - -async fn knock_room_helper_local( - services: &Services, - sender_user: &UserId, - room_id: &RoomId, - reason: Option, - servers: &[OwnedServerName], - state_lock: RoomMutexGuard, -) -> Result { - debug_info!("We can knock locally"); - - let room_version_id = services.rooms.state.get_room_version(room_id).await?; - - if matches!( - room_version_id, - RoomVersionId::V1 - | RoomVersionId::V2 - | RoomVersionId::V3 - | RoomVersionId::V4 - | RoomVersionId::V5 - | RoomVersionId::V6 - ) { - return Err!(Request(Forbidden("This room does not support knocking."))); - } - - // Verify that this room has a valid knock or knock_restricted join rule - let join_rule = services.rooms.state_accessor.get_join_rules(room_id).await; - if !matches!(join_rule, JoinRule::Knock | JoinRule::KnockRestricted(_)) { - return Err!(Request(Forbidden("This room's join rule does not allow knocking."))); - } - - let content = RoomMemberEventContent { - displayname: services.users.displayname(sender_user).await.ok(), - avatar_url: services.users.avatar_url(sender_user).await.ok(), - blurhash: services.users.blurhash(sender_user).await.ok(), - reason: reason.clone(), - ..RoomMemberEventContent::new(MembershipState::Knock) - }; - - // Try normal knock first - let Err(error) = services - .rooms - .timeline - .build_and_append_pdu( - PduBuilder::state(sender_user.to_string(), &content), - sender_user, - room_id, - &state_lock, - ) - .await - else { - return Ok(()); - }; - - if servers.is_empty() || (servers.len() == 1 && services.globals.server_is_ours(&servers[0])) - { - return Err(error); - } - - warn!("We couldn't do the knock locally, maybe federation can help to satisfy the knock"); - - let (make_knock_response, remote_server) = - make_knock_request(services, sender_user, room_id, servers).await?; - - info!("make_knock finished"); - - let room_version_id = make_knock_response.room_version; - - if !services.server.supported_room_version(&room_version_id) { - return Err!(BadServerResponse( - "Remote room version {room_version_id} is not supported by conduwuit" - )); - } - - let mut knock_event_stub = serde_json::from_str::( - make_knock_response.event.get(), - ) - .map_err(|e| { - err!(BadServerResponse("Invalid make_knock event json received from server: {e:?}")) - })?; - - knock_event_stub.insert( - "origin".to_owned(), - CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()), - ); - knock_event_stub.insert( - "origin_server_ts".to_owned(), - CanonicalJsonValue::Integer( - utils::millis_since_unix_epoch() - .try_into() - .expect("Timestamp is valid js_int value"), - ), - ); - knock_event_stub.insert( - "content".to_owned(), - to_canonical_value(RoomMemberEventContent { - displayname: services.users.displayname(sender_user).await.ok(), - avatar_url: services.users.avatar_url(sender_user).await.ok(), - blurhash: services.users.blurhash(sender_user).await.ok(), - reason, - ..RoomMemberEventContent::new(MembershipState::Knock) - }) - .expect("event is valid, we just created it"), - ); - - // In order to create a compatible ref hash (EventID) the `hashes` field needs - // to be present - services - .server_keys - .hash_and_sign_event(&mut knock_event_stub, &room_version_id)?; - - // Generate event id - let event_id = gen_event_id(&knock_event_stub, &room_version_id)?; - - // Add event_id - knock_event_stub - .insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into())); - - // It has enough fields to be called a proper event now - let knock_event = knock_event_stub; - - info!("Asking {remote_server} for send_knock in room {room_id}"); - let send_knock_request = federation::knock::send_knock::v1::Request { - room_id: room_id.to_owned(), - event_id: event_id.clone(), - pdu: services - .sending - .convert_to_outgoing_federation_event(knock_event.clone()) - .await, - }; - - let send_knock_response = services - .sending - .send_federation_request(&remote_server, send_knock_request) - .await?; - - info!("send_knock finished"); - - services - .rooms - .short - .get_or_create_shortroomid(room_id) - .await; - - info!("Parsing knock event"); - - let parsed_knock_pdu = PduEvent::from_id_val(&event_id, knock_event.clone()) - .map_err(|e| err!(BadServerResponse("Invalid knock event PDU: {e:?}")))?; - - info!("Updating membership locally to knock state with provided stripped state events"); - services - .rooms - .state_cache - .update_membership( - room_id, - sender_user, - parsed_knock_pdu - .get_content::() - .expect("we just created this"), - sender_user, - Some(send_knock_response.knock_room_state), - None, - false, - ) - .await?; - - info!("Appending room knock event locally"); - services - .rooms - .timeline - .append_pdu( - &parsed_knock_pdu, - knock_event, - once(parsed_knock_pdu.event_id.borrow()), - &state_lock, - ) - .await?; - - Ok(()) -} - -async fn knock_room_helper_remote( - services: &Services, - sender_user: &UserId, - room_id: &RoomId, - reason: Option, - servers: &[OwnedServerName], - state_lock: RoomMutexGuard, -) -> Result { - info!("Knocking {room_id} over federation."); - - let (make_knock_response, remote_server) = - make_knock_request(services, sender_user, room_id, servers).await?; - - info!("make_knock finished"); - - let room_version_id = make_knock_response.room_version; - - if !services.server.supported_room_version(&room_version_id) { - return Err!(BadServerResponse( - "Remote room version {room_version_id} is not supported by conduwuit" - )); - } - - let mut knock_event_stub: CanonicalJsonObject = - serde_json::from_str(make_knock_response.event.get()).map_err(|e| { - err!(BadServerResponse("Invalid make_knock event json received from server: {e:?}")) - })?; - - knock_event_stub.insert( - "origin".to_owned(), - CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()), - ); - knock_event_stub.insert( - "origin_server_ts".to_owned(), - CanonicalJsonValue::Integer( - utils::millis_since_unix_epoch() - .try_into() - .expect("Timestamp is valid js_int value"), - ), - ); - knock_event_stub.insert( - "content".to_owned(), - to_canonical_value(RoomMemberEventContent { - displayname: services.users.displayname(sender_user).await.ok(), - avatar_url: services.users.avatar_url(sender_user).await.ok(), - blurhash: services.users.blurhash(sender_user).await.ok(), - reason, - ..RoomMemberEventContent::new(MembershipState::Knock) - }) - .expect("event is valid, we just created it"), - ); - - // In order to create a compatible ref hash (EventID) the `hashes` field needs - // to be present - services - .server_keys - .hash_and_sign_event(&mut knock_event_stub, &room_version_id)?; - - // Generate event id - let event_id = gen_event_id(&knock_event_stub, &room_version_id)?; - - // Add event_id - knock_event_stub - .insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into())); - - // It has enough fields to be called a proper event now - let knock_event = knock_event_stub; - - info!("Asking {remote_server} for send_knock in room {room_id}"); - let send_knock_request = federation::knock::send_knock::v1::Request { - room_id: room_id.to_owned(), - event_id: event_id.clone(), - pdu: services - .sending - .convert_to_outgoing_federation_event(knock_event.clone()) - .await, - }; - - let send_knock_response = services - .sending - .send_federation_request(&remote_server, send_knock_request) - .await?; - - info!("send_knock finished"); - - services - .rooms - .short - .get_or_create_shortroomid(room_id) - .await; - - info!("Parsing knock event"); - let parsed_knock_pdu = PduEvent::from_id_val(&event_id, knock_event.clone()) - .map_err(|e| err!(BadServerResponse("Invalid knock event PDU: {e:?}")))?; - - info!("Going through send_knock response knock state events"); - let state = send_knock_response - .knock_room_state - .iter() - .map(|event| serde_json::from_str::(event.clone().into_json().get())) - .filter_map(Result::ok); - - let mut state_map: HashMap = HashMap::new(); - - for event in state { - let Some(state_key) = event.get("state_key") else { - debug_warn!("send_knock stripped state event missing state_key: {event:?}"); - continue; - }; - let Some(event_type) = event.get("type") else { - debug_warn!("send_knock stripped state event missing event type: {event:?}"); - continue; - }; - - let Ok(state_key) = serde_json::from_value::(state_key.clone().into()) else { - debug_warn!("send_knock stripped state event has invalid state_key: {event:?}"); - continue; - }; - let Ok(event_type) = serde_json::from_value::(event_type.clone().into()) - else { - debug_warn!("send_knock stripped state event has invalid event type: {event:?}"); - continue; - }; - - let event_id = gen_event_id(&event, &room_version_id)?; - let shortstatekey = services - .rooms - .short - .get_or_create_shortstatekey(&event_type, &state_key) - .await; - - services.rooms.outlier.add_pdu_outlier(&event_id, &event); - state_map.insert(shortstatekey, event_id.clone()); - } - - info!("Compressing state from send_knock"); - let compressed: CompressedState = services - .rooms - .state_compressor - .compress_state_events(state_map.iter().map(|(ssk, eid)| (ssk, eid.borrow()))) - .collect() - .await; - - debug!("Saving compressed state"); - let HashSetCompressStateEvent { - shortstatehash: statehash_before_knock, - added, - removed, - } = services - .rooms - .state_compressor - .save_state(room_id, Arc::new(compressed)) - .await?; - - debug!("Forcing state for new room"); - services - .rooms - .state - .force_state(room_id, statehash_before_knock, added, removed, &state_lock) - .await?; - - let statehash_after_knock = services - .rooms - .state - .append_to_state(&parsed_knock_pdu) - .await?; - - info!("Updating membership locally to knock state with provided stripped state events"); - services - .rooms - .state_cache - .update_membership( - room_id, - sender_user, - parsed_knock_pdu - .get_content::() - .expect("we just created this"), - sender_user, - Some(send_knock_response.knock_room_state), - None, - false, - ) - .await?; - - info!("Appending room knock event locally"); - services - .rooms - .timeline - .append_pdu( - &parsed_knock_pdu, - knock_event, - once(parsed_knock_pdu.event_id.borrow()), - &state_lock, - ) - .await?; - - info!("Setting final room state for new room"); - // We set the room state after inserting the pdu, so that we never have a moment - // in time where events in the current room state do not exist - services - .rooms - .state - .set_room_state(room_id, statehash_after_knock, &state_lock); - - Ok(()) -} - -async fn make_knock_request( - services: &Services, - sender_user: &UserId, - room_id: &RoomId, - servers: &[OwnedServerName], -) -> Result<(federation::knock::create_knock_event_template::v1::Response, OwnedServerName)> { - let mut make_knock_response_and_server = - Err!(BadServerResponse("No server available to assist in knocking.")); - - let mut make_knock_counter: usize = 0; - - for remote_server in servers { - if services.globals.server_is_ours(remote_server) { - continue; - } - - info!("Asking {remote_server} for make_knock ({make_knock_counter})"); - - let make_knock_response = services - .sending - .send_federation_request( - remote_server, - federation::knock::create_knock_event_template::v1::Request { - room_id: room_id.to_owned(), - user_id: sender_user.to_owned(), - ver: services.server.supported_room_versions().collect(), - }, - ) - .await; - - trace!("make_knock response: {make_knock_response:?}"); - make_knock_counter = make_knock_counter.saturating_add(1); - - make_knock_response_and_server = make_knock_response.map(|r| (r, remote_server.clone())); - - if make_knock_response_and_server.is_ok() { - break; - } - - if make_knock_counter > 40 { - warn!( - "50 servers failed to provide valid make_knock response, assuming no server can \ - assist in knocking." - ); - make_knock_response_and_server = - Err!(BadServerResponse("No server available to assist in knocking.")); - - return make_knock_response_and_server; - } - } - - make_knock_response_and_server -} diff --git a/src/api/client/membership/ban.rs b/src/api/client/membership/ban.rs new file mode 100644 index 00000000..339dcf2e --- /dev/null +++ b/src/api/client/membership/ban.rs @@ -0,0 +1,60 @@ +use axum::extract::State; +use conduwuit::{Err, Result, matrix::pdu::PduBuilder}; +use ruma::{ + api::client::membership::ban_user, + events::room::member::{MembershipState, RoomMemberEventContent}, +}; + +use crate::Ruma; + +/// # `POST /_matrix/client/r0/rooms/{roomId}/ban` +/// +/// Tries to send a ban event into the room. +pub(crate) async fn ban_user_route( + State(services): State, + body: Ruma, +) -> Result { + let sender_user = body.sender_user(); + + if sender_user == body.user_id { + return Err!(Request(Forbidden("You cannot ban yourself."))); + } + + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } + + let state_lock = services.rooms.state.mutex.lock(&body.room_id).await; + + let current_member_content = services + .rooms + .state_accessor + .get_member(&body.room_id, &body.user_id) + .await + .unwrap_or_else(|_| RoomMemberEventContent::new(MembershipState::Ban)); + + services + .rooms + .timeline + .build_and_append_pdu( + PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent { + membership: MembershipState::Ban, + reason: body.reason.clone(), + displayname: None, // display name may be offensive + avatar_url: None, // avatar may be offensive + is_direct: None, + join_authorized_via_users_server: None, + third_party_invite: None, + redact_events: body.redact_events, + ..current_member_content + }), + sender_user, + &body.room_id, + &state_lock, + ) + .await?; + + drop(state_lock); + + Ok(ban_user::v3::Response::new()) +} diff --git a/src/api/client/membership/forget.rs b/src/api/client/membership/forget.rs new file mode 100644 index 00000000..7f3a1a57 --- /dev/null +++ b/src/api/client/membership/forget.rs @@ -0,0 +1,52 @@ +use axum::extract::State; +use conduwuit::{Err, Result, is_matching, result::NotFound, utils::FutureBoolExt}; +use futures::pin_mut; +use ruma::{api::client::membership::forget_room, events::room::member::MembershipState}; + +use crate::Ruma; + +/// # `POST /_matrix/client/v3/rooms/{roomId}/forget` +/// +/// Forgets about a room. +/// +/// - If the sender user currently left the room: Stops sender user from +/// receiving information about the room +/// +/// Note: Other devices of the user have no way of knowing the room was +/// forgotten, so this has to be called from every device +pub(crate) async fn forget_room_route( + State(services): State, + body: Ruma, +) -> Result { + let user_id = body.sender_user(); + let room_id = &body.room_id; + + let joined = services.rooms.state_cache.is_joined(user_id, room_id); + let knocked = services.rooms.state_cache.is_knocked(user_id, room_id); + let invited = services.rooms.state_cache.is_invited(user_id, room_id); + + pin_mut!(joined, knocked, invited); + if joined.or(knocked).or(invited).await { + return Err!(Request(Unknown("You must leave the room before forgetting it"))); + } + + let membership = services + .rooms + .state_accessor + .get_member(room_id, user_id) + .await; + + if membership.is_not_found() { + return Err!(Request(Unknown("No membership event was found, room was never joined"))); + } + + let non_membership = membership + .map(|member| member.membership) + .is_ok_and(is_matching!(MembershipState::Leave | MembershipState::Ban)); + + if non_membership || services.rooms.state_cache.is_left(user_id, room_id).await { + services.rooms.state_cache.forget(room_id, user_id); + } + + Ok(forget_room::v3::Response::new()) +} diff --git a/src/api/client/membership/invite.rs b/src/api/client/membership/invite.rs new file mode 100644 index 00000000..4ca3efb8 --- /dev/null +++ b/src/api/client/membership/invite.rs @@ -0,0 +1,238 @@ +use axum::extract::State; +use axum_client_ip::InsecureClientIp; +use conduwuit::{ + Err, Result, debug_error, err, info, + matrix::pdu::{PduBuilder, gen_event_id_canonical_json}, +}; +use futures::{FutureExt, join}; +use ruma::{ + OwnedServerName, RoomId, UserId, + api::{client::membership::invite_user, federation::membership::create_invite}, + events::room::member::{MembershipState, RoomMemberEventContent}, +}; +use service::Services; + +use super::banned_room_check; +use crate::Ruma; + +/// # `POST /_matrix/client/r0/rooms/{roomId}/invite` +/// +/// Tries to send an invite event into the room. +#[tracing::instrument(skip_all, fields(%client), name = "invite")] +pub(crate) async fn invite_user_route( + State(services): State, + InsecureClientIp(client): InsecureClientIp, + body: Ruma, +) -> Result { + let sender_user = body.sender_user(); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } + + if !services.users.is_admin(sender_user).await && services.config.block_non_admin_invites { + debug_error!( + "User {sender_user} is not an admin and attempted to send an invite to room {}", + &body.room_id + ); + return Err!(Request(Forbidden("Invites are not allowed on this server."))); + } + + banned_room_check( + &services, + sender_user, + Some(&body.room_id), + body.room_id.server_name(), + client, + ) + .await?; + + match &body.recipient { + | invite_user::v3::InvitationRecipient::UserId { user_id } => { + let sender_ignored_recipient = services.users.user_is_ignored(sender_user, user_id); + let recipient_ignored_by_sender = + services.users.user_is_ignored(user_id, sender_user); + + let (sender_ignored_recipient, recipient_ignored_by_sender) = + join!(sender_ignored_recipient, recipient_ignored_by_sender); + + if sender_ignored_recipient { + return Ok(invite_user::v3::Response {}); + } + + if let Ok(target_user_membership) = services + .rooms + .state_accessor + .get_member(&body.room_id, user_id) + .await + { + if target_user_membership.membership == MembershipState::Ban { + return Err!(Request(Forbidden("User is banned from this room."))); + } + } + + if recipient_ignored_by_sender { + // silently drop the invite to the recipient if they've been ignored by the + // sender, pretend it worked + return Ok(invite_user::v3::Response {}); + } + + invite_helper( + &services, + sender_user, + user_id, + &body.room_id, + body.reason.clone(), + false, + ) + .boxed() + .await?; + + Ok(invite_user::v3::Response {}) + }, + | _ => { + Err!(Request(NotFound("User not found."))) + }, + } +} + +pub(crate) async fn invite_helper( + services: &Services, + sender_user: &UserId, + user_id: &UserId, + room_id: &RoomId, + reason: Option, + is_direct: bool, +) -> Result { + if !services.users.is_admin(sender_user).await && services.config.block_non_admin_invites { + info!( + "User {sender_user} is not an admin and attempted to send an invite to room \ + {room_id}" + ); + return Err!(Request(Forbidden("Invites are not allowed on this server."))); + } + + if !services.globals.user_is_local(user_id) { + let (pdu, pdu_json, invite_room_state) = { + let state_lock = services.rooms.state.mutex.lock(room_id).await; + + let content = RoomMemberEventContent { + avatar_url: services.users.avatar_url(user_id).await.ok(), + is_direct: Some(is_direct), + reason, + ..RoomMemberEventContent::new(MembershipState::Invite) + }; + + let (pdu, pdu_json) = services + .rooms + .timeline + .create_hash_and_sign_event( + PduBuilder::state(user_id.to_string(), &content), + sender_user, + room_id, + &state_lock, + ) + .await?; + + let invite_room_state = services.rooms.state.summary_stripped(&pdu).await; + + drop(state_lock); + + (pdu, pdu_json, invite_room_state) + }; + + let room_version_id = services.rooms.state.get_room_version(room_id).await?; + + let response = services + .sending + .send_federation_request(user_id.server_name(), create_invite::v2::Request { + room_id: room_id.to_owned(), + event_id: (*pdu.event_id).to_owned(), + room_version: room_version_id.clone(), + event: services + .sending + .convert_to_outgoing_federation_event(pdu_json.clone()) + .await, + invite_room_state, + via: services + .rooms + .state_cache + .servers_route_via(room_id) + .await + .ok(), + }) + .await?; + + // We do not add the event_id field to the pdu here because of signature and + // hashes checks + let (event_id, value) = gen_event_id_canonical_json(&response.event, &room_version_id) + .map_err(|e| { + err!(Request(BadJson(warn!("Could not convert event to canonical JSON: {e}")))) + })?; + + if pdu.event_id != event_id { + return Err!(Request(BadJson(warn!( + %pdu.event_id, %event_id, + "Server {} sent event with wrong event ID", + user_id.server_name() + )))); + } + + let origin: OwnedServerName = serde_json::from_value(serde_json::to_value( + value + .get("origin") + .ok_or_else(|| err!(Request(BadJson("Event missing origin field."))))?, + )?) + .map_err(|e| { + err!(Request(BadJson(warn!("Origin field in event is not a valid server name: {e}")))) + })?; + + let pdu_id = services + .rooms + .event_handler + .handle_incoming_pdu(&origin, room_id, &event_id, value, true) + .boxed() + .await? + .ok_or_else(|| { + err!(Request(InvalidParam("Could not accept incoming PDU as timeline event."))) + })?; + + return services.sending.send_pdu_room(room_id, &pdu_id).await; + } + + if !services + .rooms + .state_cache + .is_joined(sender_user, room_id) + .await + { + return Err!(Request(Forbidden( + "You must be joined in the room you are trying to invite from." + ))); + } + + let state_lock = services.rooms.state.mutex.lock(room_id).await; + + let content = RoomMemberEventContent { + displayname: services.users.displayname(user_id).await.ok(), + avatar_url: services.users.avatar_url(user_id).await.ok(), + blurhash: services.users.blurhash(user_id).await.ok(), + is_direct: Some(is_direct), + reason, + ..RoomMemberEventContent::new(MembershipState::Invite) + }; + + services + .rooms + .timeline + .build_and_append_pdu( + PduBuilder::state(user_id.to_string(), &content), + sender_user, + room_id, + &state_lock, + ) + .await?; + + drop(state_lock); + + Ok(()) +} diff --git a/src/api/client/membership/join.rs b/src/api/client/membership/join.rs new file mode 100644 index 00000000..669e9399 --- /dev/null +++ b/src/api/client/membership/join.rs @@ -0,0 +1,988 @@ +use std::{borrow::Borrow, collections::HashMap, iter::once, sync::Arc}; + +use axum::extract::State; +use axum_client_ip::InsecureClientIp; +use conduwuit::{ + Err, Result, debug, debug_info, debug_warn, err, error, info, + matrix::{ + StateKey, + pdu::{PduBuilder, PduEvent, gen_event_id, gen_event_id_canonical_json}, + state_res, + }, + result::FlatOk, + trace, + utils::{ + self, shuffle, + stream::{IterStream, ReadyExt}, + }, + warn, +}; +use futures::{FutureExt, StreamExt}; +use ruma::{ + CanonicalJsonObject, CanonicalJsonValue, OwnedRoomId, OwnedServerName, OwnedUserId, RoomId, + RoomVersionId, UserId, + api::{ + client::{ + error::ErrorKind, + membership::{ThirdPartySigned, join_room_by_id, join_room_by_id_or_alias}, + }, + federation::{self}, + }, + canonical_json::to_canonical_value, + events::{ + StateEventType, + room::{ + join_rules::{AllowRule, JoinRule, RoomJoinRulesEventContent}, + member::{MembershipState, RoomMemberEventContent}, + }, + }, +}; +use service::{ + Services, + appservice::RegistrationInfo, + rooms::{ + state::RoomMutexGuard, + state_compressor::{CompressedState, HashSetCompressStateEvent}, + }, +}; + +use super::banned_room_check; +use crate::Ruma; + +/// # `POST /_matrix/client/r0/rooms/{roomId}/join` +/// +/// Tries to join the sender user into a room. +/// +/// - If the server knowns about this room: creates the join event and does auth +/// rules locally +/// - If the server does not know about the room: asks other servers over +/// federation +#[tracing::instrument(skip_all, fields(%client), name = "join")] +pub(crate) async fn join_room_by_id_route( + State(services): State, + InsecureClientIp(client): InsecureClientIp, + body: Ruma, +) -> Result { + let sender_user = body.sender_user(); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } + + banned_room_check( + &services, + sender_user, + Some(&body.room_id), + body.room_id.server_name(), + client, + ) + .await?; + + // There is no body.server_name for /roomId/join + let mut servers: Vec<_> = services + .rooms + .state_cache + .servers_invite_via(&body.room_id) + .map(ToOwned::to_owned) + .collect() + .await; + + servers.extend( + services + .rooms + .state_cache + .invite_state(sender_user, &body.room_id) + .await + .unwrap_or_default() + .iter() + .filter_map(|event| event.get_field("sender").ok().flatten()) + .filter_map(|sender: &str| UserId::parse(sender).ok()) + .map(|user| user.server_name().to_owned()), + ); + + if let Some(server) = body.room_id.server_name() { + servers.push(server.into()); + } + + servers.sort_unstable(); + servers.dedup(); + shuffle(&mut servers); + + join_room_by_id_helper( + &services, + sender_user, + &body.room_id, + body.reason.clone(), + &servers, + body.third_party_signed.as_ref(), + &body.appservice_info, + ) + .boxed() + .await +} + +/// # `POST /_matrix/client/r0/join/{roomIdOrAlias}` +/// +/// Tries to join the sender user into a room. +/// +/// - If the server knowns about this room: creates the join event and does auth +/// rules locally +/// - If the server does not know about the room: use the server name query +/// param if specified. if not specified, asks other servers over federation +/// via room alias server name and room ID server name +#[tracing::instrument(skip_all, fields(%client), name = "join")] +pub(crate) async fn join_room_by_id_or_alias_route( + State(services): State, + InsecureClientIp(client): InsecureClientIp, + body: Ruma, +) -> Result { + let sender_user = body.sender_user(); + let appservice_info = &body.appservice_info; + let body = &body.body; + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } + + let (servers, room_id) = match OwnedRoomId::try_from(body.room_id_or_alias.clone()) { + | Ok(room_id) => { + banned_room_check( + &services, + sender_user, + Some(&room_id), + room_id.server_name(), + client, + ) + .boxed() + .await?; + + let mut servers = body.via.clone(); + servers.extend( + services + .rooms + .state_cache + .servers_invite_via(&room_id) + .map(ToOwned::to_owned) + .collect::>() + .await, + ); + + servers.extend( + services + .rooms + .state_cache + .invite_state(sender_user, &room_id) + .await + .unwrap_or_default() + .iter() + .filter_map(|event| event.get_field("sender").ok().flatten()) + .filter_map(|sender: &str| UserId::parse(sender).ok()) + .map(|user| user.server_name().to_owned()), + ); + + if let Some(server) = room_id.server_name() { + servers.push(server.to_owned()); + } + + servers.sort_unstable(); + servers.dedup(); + shuffle(&mut servers); + + (servers, room_id) + }, + | Err(room_alias) => { + let (room_id, mut servers) = services + .rooms + .alias + .resolve_alias(&room_alias, Some(body.via.clone())) + .await?; + + banned_room_check( + &services, + sender_user, + Some(&room_id), + Some(room_alias.server_name()), + client, + ) + .await?; + + let addl_via_servers = services + .rooms + .state_cache + .servers_invite_via(&room_id) + .map(ToOwned::to_owned); + + let addl_state_servers = services + .rooms + .state_cache + .invite_state(sender_user, &room_id) + .await + .unwrap_or_default(); + + let mut addl_servers: Vec<_> = addl_state_servers + .iter() + .map(|event| event.get_field("sender")) + .filter_map(FlatOk::flat_ok) + .map(|user: &UserId| user.server_name().to_owned()) + .stream() + .chain(addl_via_servers) + .collect() + .await; + + addl_servers.sort_unstable(); + addl_servers.dedup(); + shuffle(&mut addl_servers); + servers.append(&mut addl_servers); + + (servers, room_id) + }, + }; + + let join_room_response = join_room_by_id_helper( + &services, + sender_user, + &room_id, + body.reason.clone(), + &servers, + body.third_party_signed.as_ref(), + appservice_info, + ) + .boxed() + .await?; + + Ok(join_room_by_id_or_alias::v3::Response { room_id: join_room_response.room_id }) +} + +pub async fn join_room_by_id_helper( + services: &Services, + sender_user: &UserId, + room_id: &RoomId, + reason: Option, + servers: &[OwnedServerName], + third_party_signed: Option<&ThirdPartySigned>, + appservice_info: &Option, +) -> Result { + let state_lock = services.rooms.state.mutex.lock(room_id).await; + + let user_is_guest = services + .users + .is_deactivated(sender_user) + .await + .unwrap_or(false) + && appservice_info.is_none(); + + if user_is_guest && !services.rooms.state_accessor.guest_can_join(room_id).await { + return Err!(Request(Forbidden("Guests are not allowed to join this room"))); + } + + if services + .rooms + .state_cache + .is_joined(sender_user, room_id) + .await + { + debug_warn!("{sender_user} is already joined in {room_id}"); + return Ok(join_room_by_id::v3::Response { room_id: room_id.into() }); + } + + let server_in_room = services + .rooms + .state_cache + .server_in_room(services.globals.server_name(), room_id) + .await; + + // Only check our known membership if we're already in the room. + // See: https://forgejo.ellis.link/continuwuation/continuwuity/issues/855 + let membership = if server_in_room { + services + .rooms + .state_accessor + .get_member(room_id, sender_user) + .await + } else { + debug!("Ignoring local state for join {room_id}, we aren't in the room yet."); + Ok(RoomMemberEventContent::new(MembershipState::Leave)) + }; + if let Ok(m) = membership { + if m.membership == MembershipState::Ban { + debug_warn!("{sender_user} is banned from {room_id} but attempted to join"); + // TODO: return reason + return Err!(Request(Forbidden("You are banned from the room."))); + } + } + + let local_join = server_in_room + || servers.is_empty() + || (servers.len() == 1 && services.globals.server_is_ours(&servers[0])); + + if local_join { + join_room_by_id_helper_local( + services, + sender_user, + room_id, + reason, + servers, + third_party_signed, + state_lock, + ) + .boxed() + .await?; + } else { + // Ask a remote server if we are not participating in this room + join_room_by_id_helper_remote( + services, + sender_user, + room_id, + reason, + servers, + third_party_signed, + state_lock, + ) + .boxed() + .await?; + } + + Ok(join_room_by_id::v3::Response::new(room_id.to_owned())) +} + +#[tracing::instrument(skip_all, fields(%sender_user, %room_id), name = "join_remote")] +async fn join_room_by_id_helper_remote( + services: &Services, + sender_user: &UserId, + room_id: &RoomId, + reason: Option, + servers: &[OwnedServerName], + _third_party_signed: Option<&ThirdPartySigned>, + state_lock: RoomMutexGuard, +) -> Result { + info!("Joining {room_id} over federation."); + + let (make_join_response, remote_server) = + make_join_request(services, sender_user, room_id, servers).await?; + + info!("make_join finished"); + + let Some(room_version_id) = make_join_response.room_version else { + return Err!(BadServerResponse("Remote room version is not supported by conduwuit")); + }; + + if !services.server.supported_room_version(&room_version_id) { + return Err!(BadServerResponse( + "Remote room version {room_version_id} is not supported by conduwuit" + )); + } + + let mut join_event_stub: CanonicalJsonObject = + serde_json::from_str(make_join_response.event.get()).map_err(|e| { + err!(BadServerResponse(warn!( + "Invalid make_join event json received from server: {e:?}" + ))) + })?; + + let join_authorized_via_users_server = { + use RoomVersionId::*; + if !matches!(room_version_id, V1 | V2 | V3 | V4 | V5 | V6 | V7) { + join_event_stub + .get("content") + .map(|s| { + s.as_object()? + .get("join_authorised_via_users_server")? + .as_str() + }) + .and_then(|s| OwnedUserId::try_from(s.unwrap_or_default()).ok()) + } else { + None + } + }; + + join_event_stub.insert( + "origin".to_owned(), + CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()), + ); + join_event_stub.insert( + "origin_server_ts".to_owned(), + CanonicalJsonValue::Integer( + utils::millis_since_unix_epoch() + .try_into() + .expect("Timestamp is valid js_int value"), + ), + ); + join_event_stub.insert( + "content".to_owned(), + to_canonical_value(RoomMemberEventContent { + displayname: services.users.displayname(sender_user).await.ok(), + avatar_url: services.users.avatar_url(sender_user).await.ok(), + blurhash: services.users.blurhash(sender_user).await.ok(), + reason, + join_authorized_via_users_server: join_authorized_via_users_server.clone(), + ..RoomMemberEventContent::new(MembershipState::Join) + }) + .expect("event is valid, we just created it"), + ); + + // We keep the "event_id" in the pdu only in v1 or + // v2 rooms + match room_version_id { + | RoomVersionId::V1 | RoomVersionId::V2 => {}, + | _ => { + join_event_stub.remove("event_id"); + }, + } + + // In order to create a compatible ref hash (EventID) the `hashes` field needs + // to be present + services + .server_keys + .hash_and_sign_event(&mut join_event_stub, &room_version_id)?; + + // Generate event id + let event_id = gen_event_id(&join_event_stub, &room_version_id)?; + + // Add event_id back + join_event_stub + .insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into())); + + // It has enough fields to be called a proper event now + let mut join_event = join_event_stub; + + info!("Asking {remote_server} for send_join in room {room_id}"); + let send_join_request = federation::membership::create_join_event::v2::Request { + room_id: room_id.to_owned(), + event_id: event_id.clone(), + omit_members: false, + pdu: services + .sending + .convert_to_outgoing_federation_event(join_event.clone()) + .await, + }; + + let send_join_response = match services + .sending + .send_synapse_request(&remote_server, send_join_request) + .await + { + | Ok(response) => response, + | Err(e) => { + error!("send_join failed: {e}"); + return Err(e); + }, + }; + + info!("send_join finished"); + + if join_authorized_via_users_server.is_some() { + if let Some(signed_raw) = &send_join_response.room_state.event { + debug_info!( + "There is a signed event with join_authorized_via_users_server. This room is \ + probably using restricted joins. Adding signature to our event" + ); + + let (signed_event_id, signed_value) = + gen_event_id_canonical_json(signed_raw, &room_version_id).map_err(|e| { + err!(Request(BadJson(warn!( + "Could not convert event to canonical JSON: {e}" + )))) + })?; + + if signed_event_id != event_id { + return Err!(Request(BadJson(warn!( + %signed_event_id, %event_id, + "Server {remote_server} sent event with wrong event ID" + )))); + } + + match signed_value["signatures"] + .as_object() + .ok_or_else(|| { + err!(BadServerResponse(warn!( + "Server {remote_server} sent invalid signatures type" + ))) + }) + .and_then(|e| { + e.get(remote_server.as_str()).ok_or_else(|| { + err!(BadServerResponse(warn!( + "Server {remote_server} did not send its signature for a restricted \ + room" + ))) + }) + }) { + | Ok(signature) => { + join_event + .get_mut("signatures") + .expect("we created a valid pdu") + .as_object_mut() + .expect("we created a valid pdu") + .insert(remote_server.to_string(), signature.clone()); + }, + | Err(e) => { + warn!( + "Server {remote_server} sent invalid signature in send_join signatures \ + for event {signed_value:?}: {e:?}", + ); + }, + } + } + } + + services + .rooms + .short + .get_or_create_shortroomid(room_id) + .await; + + info!("Parsing join event"); + let parsed_join_pdu = PduEvent::from_id_val(&event_id, join_event.clone()) + .map_err(|e| err!(BadServerResponse("Invalid join event PDU: {e:?}")))?; + + info!("Acquiring server signing keys for response events"); + let resp_events = &send_join_response.room_state; + let resp_state = &resp_events.state; + let resp_auth = &resp_events.auth_chain; + services + .server_keys + .acquire_events_pubkeys(resp_auth.iter().chain(resp_state.iter())) + .await; + + info!("Going through send_join response room_state"); + let cork = services.db.cork_and_flush(); + let state = send_join_response + .room_state + .state + .iter() + .stream() + .then(|pdu| { + services + .server_keys + .validate_and_add_event_id_no_fetch(pdu, &room_version_id) + }) + .ready_filter_map(Result::ok) + .fold(HashMap::new(), |mut state, (event_id, value)| async move { + let pdu = match PduEvent::from_id_val(&event_id, value.clone()) { + | Ok(pdu) => pdu, + | Err(e) => { + debug_warn!("Invalid PDU in send_join response: {e:?}: {value:#?}"); + return state; + }, + }; + + services.rooms.outlier.add_pdu_outlier(&event_id, &value); + if let Some(state_key) = &pdu.state_key { + let shortstatekey = services + .rooms + .short + .get_or_create_shortstatekey(&pdu.kind.to_string().into(), state_key) + .await; + + state.insert(shortstatekey, pdu.event_id.clone()); + } + + state + }) + .await; + + drop(cork); + + info!("Going through send_join response auth_chain"); + let cork = services.db.cork_and_flush(); + send_join_response + .room_state + .auth_chain + .iter() + .stream() + .then(|pdu| { + services + .server_keys + .validate_and_add_event_id_no_fetch(pdu, &room_version_id) + }) + .ready_filter_map(Result::ok) + .ready_for_each(|(event_id, value)| { + services.rooms.outlier.add_pdu_outlier(&event_id, &value); + }) + .await; + + drop(cork); + + debug!("Running send_join auth check"); + let fetch_state = &state; + let state_fetch = |k: StateEventType, s: StateKey| async move { + let shortstatekey = services.rooms.short.get_shortstatekey(&k, &s).await.ok()?; + + let event_id = fetch_state.get(&shortstatekey)?; + services.rooms.timeline.get_pdu(event_id).await.ok() + }; + + let auth_check = state_res::event_auth::auth_check( + &state_res::RoomVersion::new(&room_version_id)?, + &parsed_join_pdu, + None, // TODO: third party invite + |k, s| state_fetch(k.clone(), s.into()), + ) + .await + .map_err(|e| err!(Request(Forbidden(warn!("Auth check failed: {e:?}")))))?; + + if !auth_check { + return Err!(Request(Forbidden("Auth check failed"))); + } + + info!("Compressing state from send_join"); + let compressed: CompressedState = services + .rooms + .state_compressor + .compress_state_events(state.iter().map(|(ssk, eid)| (ssk, eid.borrow()))) + .collect() + .await; + + debug!("Saving compressed state"); + let HashSetCompressStateEvent { + shortstatehash: statehash_before_join, + added, + removed, + } = services + .rooms + .state_compressor + .save_state(room_id, Arc::new(compressed)) + .await?; + + debug!("Forcing state for new room"); + services + .rooms + .state + .force_state(room_id, statehash_before_join, added, removed, &state_lock) + .await?; + + info!("Updating joined counts for new room"); + services + .rooms + .state_cache + .update_joined_count(room_id) + .await; + + // We append to state before appending the pdu, so we don't have a moment in + // time with the pdu without it's state. This is okay because append_pdu can't + // fail. + let statehash_after_join = services + .rooms + .state + .append_to_state(&parsed_join_pdu) + .await?; + + info!("Appending new room join event"); + services + .rooms + .timeline + .append_pdu( + &parsed_join_pdu, + join_event, + once(parsed_join_pdu.event_id.borrow()), + &state_lock, + ) + .await?; + + info!("Setting final room state for new room"); + // We set the room state after inserting the pdu, so that we never have a moment + // in time where events in the current room state do not exist + services + .rooms + .state + .set_room_state(room_id, statehash_after_join, &state_lock); + + Ok(()) +} + +#[tracing::instrument(skip_all, fields(%sender_user, %room_id), name = "join_local")] +async fn join_room_by_id_helper_local( + services: &Services, + sender_user: &UserId, + room_id: &RoomId, + reason: Option, + servers: &[OwnedServerName], + _third_party_signed: Option<&ThirdPartySigned>, + state_lock: RoomMutexGuard, +) -> Result { + debug_info!("We can join locally"); + + let join_rules_event_content = services + .rooms + .state_accessor + .room_state_get_content::( + room_id, + &StateEventType::RoomJoinRules, + "", + ) + .await; + + let restriction_rooms = match join_rules_event_content { + | Ok(RoomJoinRulesEventContent { + join_rule: JoinRule::Restricted(restricted) | JoinRule::KnockRestricted(restricted), + }) => restricted + .allow + .into_iter() + .filter_map(|a| match a { + | AllowRule::RoomMembership(r) => Some(r.room_id), + | _ => None, + }) + .collect(), + | _ => Vec::new(), + }; + + let join_authorized_via_users_server: Option = { + if restriction_rooms + .iter() + .stream() + .any(|restriction_room_id| { + services + .rooms + .state_cache + .is_joined(sender_user, restriction_room_id) + }) + .await + { + services + .rooms + .state_cache + .local_users_in_room(room_id) + .filter(|user| { + services.rooms.state_accessor.user_can_invite( + room_id, + user, + sender_user, + &state_lock, + ) + }) + .boxed() + .next() + .await + .map(ToOwned::to_owned) + } else { + None + } + }; + + let content = RoomMemberEventContent { + displayname: services.users.displayname(sender_user).await.ok(), + avatar_url: services.users.avatar_url(sender_user).await.ok(), + blurhash: services.users.blurhash(sender_user).await.ok(), + reason: reason.clone(), + join_authorized_via_users_server, + ..RoomMemberEventContent::new(MembershipState::Join) + }; + + // Try normal join first + let Err(error) = services + .rooms + .timeline + .build_and_append_pdu( + PduBuilder::state(sender_user.to_string(), &content), + sender_user, + room_id, + &state_lock, + ) + .await + else { + return Ok(()); + }; + + if restriction_rooms.is_empty() + && (servers.is_empty() + || servers.len() == 1 && services.globals.server_is_ours(&servers[0])) + { + return Err(error); + } + + warn!( + "We couldn't do the join locally, maybe federation can help to satisfy the restricted \ + join requirements" + ); + let Ok((make_join_response, remote_server)) = + make_join_request(services, sender_user, room_id, servers).await + else { + return Err(error); + }; + + let Some(room_version_id) = make_join_response.room_version else { + return Err!(BadServerResponse("Remote room version is not supported by conduwuit")); + }; + + if !services.server.supported_room_version(&room_version_id) { + return Err!(BadServerResponse( + "Remote room version {room_version_id} is not supported by conduwuit" + )); + } + + let mut join_event_stub: CanonicalJsonObject = + serde_json::from_str(make_join_response.event.get()).map_err(|e| { + err!(BadServerResponse("Invalid make_join event json received from server: {e:?}")) + })?; + + let join_authorized_via_users_server = join_event_stub + .get("content") + .map(|s| { + s.as_object()? + .get("join_authorised_via_users_server")? + .as_str() + }) + .and_then(|s| OwnedUserId::try_from(s.unwrap_or_default()).ok()); + + join_event_stub.insert( + "origin".to_owned(), + CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()), + ); + join_event_stub.insert( + "origin_server_ts".to_owned(), + CanonicalJsonValue::Integer( + utils::millis_since_unix_epoch() + .try_into() + .expect("Timestamp is valid js_int value"), + ), + ); + join_event_stub.insert( + "content".to_owned(), + to_canonical_value(RoomMemberEventContent { + displayname: services.users.displayname(sender_user).await.ok(), + avatar_url: services.users.avatar_url(sender_user).await.ok(), + blurhash: services.users.blurhash(sender_user).await.ok(), + reason, + join_authorized_via_users_server, + ..RoomMemberEventContent::new(MembershipState::Join) + }) + .expect("event is valid, we just created it"), + ); + + // We keep the "event_id" in the pdu only in v1 or + // v2 rooms + match room_version_id { + | RoomVersionId::V1 | RoomVersionId::V2 => {}, + | _ => { + join_event_stub.remove("event_id"); + }, + } + + // In order to create a compatible ref hash (EventID) the `hashes` field needs + // to be present + services + .server_keys + .hash_and_sign_event(&mut join_event_stub, &room_version_id)?; + + // Generate event id + let event_id = gen_event_id(&join_event_stub, &room_version_id)?; + + // Add event_id back + join_event_stub + .insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into())); + + // It has enough fields to be called a proper event now + let join_event = join_event_stub; + + let send_join_response = services + .sending + .send_synapse_request( + &remote_server, + federation::membership::create_join_event::v2::Request { + room_id: room_id.to_owned(), + event_id: event_id.clone(), + omit_members: false, + pdu: services + .sending + .convert_to_outgoing_federation_event(join_event.clone()) + .await, + }, + ) + .await?; + + if let Some(signed_raw) = send_join_response.room_state.event { + let (signed_event_id, signed_value) = + gen_event_id_canonical_json(&signed_raw, &room_version_id).map_err(|e| { + err!(Request(BadJson(warn!("Could not convert event to canonical JSON: {e}")))) + })?; + + if signed_event_id != event_id { + return Err!(Request(BadJson( + warn!(%signed_event_id, %event_id, "Server {remote_server} sent event with wrong event ID") + ))); + } + + drop(state_lock); + services + .rooms + .event_handler + .handle_incoming_pdu(&remote_server, room_id, &signed_event_id, signed_value, true) + .boxed() + .await?; + } else { + return Err(error); + } + + Ok(()) +} + +async fn make_join_request( + services: &Services, + sender_user: &UserId, + room_id: &RoomId, + servers: &[OwnedServerName], +) -> Result<(federation::membership::prepare_join_event::v1::Response, OwnedServerName)> { + let mut make_join_response_and_server = + Err!(BadServerResponse("No server available to assist in joining.")); + + let mut make_join_counter: usize = 0; + let mut incompatible_room_version_count: usize = 0; + + for remote_server in servers { + if services.globals.server_is_ours(remote_server) { + continue; + } + info!("Asking {remote_server} for make_join ({make_join_counter})"); + let make_join_response = services + .sending + .send_federation_request( + remote_server, + federation::membership::prepare_join_event::v1::Request { + room_id: room_id.to_owned(), + user_id: sender_user.to_owned(), + ver: services.server.supported_room_versions().collect(), + }, + ) + .await; + + trace!("make_join response: {:?}", make_join_response); + make_join_counter = make_join_counter.saturating_add(1); + + if let Err(ref e) = make_join_response { + if matches!( + e.kind(), + ErrorKind::IncompatibleRoomVersion { .. } | ErrorKind::UnsupportedRoomVersion + ) { + incompatible_room_version_count = + incompatible_room_version_count.saturating_add(1); + } + + if incompatible_room_version_count > 15 { + info!( + "15 servers have responded with M_INCOMPATIBLE_ROOM_VERSION or \ + M_UNSUPPORTED_ROOM_VERSION, assuming that conduwuit does not support the \ + room version {room_id}: {e}" + ); + make_join_response_and_server = + Err!(BadServerResponse("Room version is not supported by Conduwuit")); + return make_join_response_and_server; + } + + if make_join_counter > 40 { + warn!( + "40 servers failed to provide valid make_join response, assuming no server \ + can assist in joining." + ); + make_join_response_and_server = + Err!(BadServerResponse("No server available to assist in joining.")); + + return make_join_response_and_server; + } + } + + make_join_response_and_server = make_join_response.map(|r| (r, remote_server.clone())); + + if make_join_response_and_server.is_ok() { + break; + } + } + + make_join_response_and_server +} diff --git a/src/api/client/membership/kick.rs b/src/api/client/membership/kick.rs new file mode 100644 index 00000000..5e0e86e2 --- /dev/null +++ b/src/api/client/membership/kick.rs @@ -0,0 +1,65 @@ +use axum::extract::State; +use conduwuit::{Err, Result, matrix::pdu::PduBuilder}; +use ruma::{ + api::client::membership::kick_user, + events::room::member::{MembershipState, RoomMemberEventContent}, +}; + +use crate::Ruma; + +/// # `POST /_matrix/client/r0/rooms/{roomId}/kick` +/// +/// Tries to send a kick event into the room. +pub(crate) async fn kick_user_route( + State(services): State, + body: Ruma, +) -> Result { + let sender_user = body.sender_user(); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } + let state_lock = services.rooms.state.mutex.lock(&body.room_id).await; + + let Ok(event) = services + .rooms + .state_accessor + .get_member(&body.room_id, &body.user_id) + .await + else { + // copy synapse's behaviour of returning 200 without any change to the state + // instead of erroring on left users + return Ok(kick_user::v3::Response::new()); + }; + + if !matches!( + event.membership, + MembershipState::Invite | MembershipState::Knock | MembershipState::Join, + ) { + return Err!(Request(Forbidden( + "Cannot kick a user who is not apart of the room (current membership: {})", + event.membership + ))); + } + + services + .rooms + .timeline + .build_and_append_pdu( + PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent { + membership: MembershipState::Leave, + reason: body.reason.clone(), + is_direct: None, + join_authorized_via_users_server: None, + third_party_invite: None, + ..event + }), + sender_user, + &body.room_id, + &state_lock, + ) + .await?; + + drop(state_lock); + + Ok(kick_user::v3::Response::new()) +} diff --git a/src/api/client/membership/knock.rs b/src/api/client/membership/knock.rs new file mode 100644 index 00000000..544dcfb3 --- /dev/null +++ b/src/api/client/membership/knock.rs @@ -0,0 +1,767 @@ +use std::{borrow::Borrow, collections::HashMap, iter::once, sync::Arc}; + +use axum::extract::State; +use axum_client_ip::InsecureClientIp; +use conduwuit::{ + Err, Result, debug, debug_info, debug_warn, err, info, + matrix::pdu::{PduBuilder, PduEvent, gen_event_id}, + result::FlatOk, + trace, + utils::{self, shuffle, stream::IterStream}, + warn, +}; +use futures::{FutureExt, StreamExt}; +use ruma::{ + CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedServerName, RoomId, + RoomVersionId, UserId, + api::{ + client::knock::knock_room, + federation::{self}, + }, + canonical_json::to_canonical_value, + events::{ + StateEventType, + room::{ + join_rules::{AllowRule, JoinRule}, + member::{MembershipState, RoomMemberEventContent}, + }, + }, +}; +use service::{ + Services, + rooms::{ + state::RoomMutexGuard, + state_compressor::{CompressedState, HashSetCompressStateEvent}, + }, +}; + +use super::{banned_room_check, join::join_room_by_id_helper}; +use crate::Ruma; + +/// # `POST /_matrix/client/*/knock/{roomIdOrAlias}` +/// +/// Tries to knock the room to ask permission to join for the sender user. +#[tracing::instrument(skip_all, fields(%client), name = "knock")] +pub(crate) async fn knock_room_route( + State(services): State, + InsecureClientIp(client): InsecureClientIp, + body: Ruma, +) -> Result { + let sender_user = body.sender_user(); + let body = &body.body; + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } + + let (servers, room_id) = match OwnedRoomId::try_from(body.room_id_or_alias.clone()) { + | Ok(room_id) => { + banned_room_check( + &services, + sender_user, + Some(&room_id), + room_id.server_name(), + client, + ) + .await?; + + let mut servers = body.via.clone(); + servers.extend( + services + .rooms + .state_cache + .servers_invite_via(&room_id) + .map(ToOwned::to_owned) + .collect::>() + .await, + ); + + servers.extend( + services + .rooms + .state_cache + .invite_state(sender_user, &room_id) + .await + .unwrap_or_default() + .iter() + .filter_map(|event| event.get_field("sender").ok().flatten()) + .filter_map(|sender: &str| UserId::parse(sender).ok()) + .map(|user| user.server_name().to_owned()), + ); + + if let Some(server) = room_id.server_name() { + servers.push(server.to_owned()); + } + + servers.sort_unstable(); + servers.dedup(); + shuffle(&mut servers); + + (servers, room_id) + }, + | Err(room_alias) => { + let (room_id, mut servers) = services + .rooms + .alias + .resolve_alias(&room_alias, Some(body.via.clone())) + .await?; + + banned_room_check( + &services, + sender_user, + Some(&room_id), + Some(room_alias.server_name()), + client, + ) + .await?; + + let addl_via_servers = services + .rooms + .state_cache + .servers_invite_via(&room_id) + .map(ToOwned::to_owned); + + let addl_state_servers = services + .rooms + .state_cache + .invite_state(sender_user, &room_id) + .await + .unwrap_or_default(); + + let mut addl_servers: Vec<_> = addl_state_servers + .iter() + .map(|event| event.get_field("sender")) + .filter_map(FlatOk::flat_ok) + .map(|user: &UserId| user.server_name().to_owned()) + .stream() + .chain(addl_via_servers) + .collect() + .await; + + addl_servers.sort_unstable(); + addl_servers.dedup(); + shuffle(&mut addl_servers); + servers.append(&mut addl_servers); + + (servers, room_id) + }, + }; + + knock_room_by_id_helper(&services, sender_user, &room_id, body.reason.clone(), &servers) + .boxed() + .await +} + +async fn knock_room_by_id_helper( + services: &Services, + sender_user: &UserId, + room_id: &RoomId, + reason: Option, + servers: &[OwnedServerName], +) -> Result { + let state_lock = services.rooms.state.mutex.lock(room_id).await; + + if services + .rooms + .state_cache + .is_invited(sender_user, room_id) + .await + { + debug_warn!("{sender_user} is already invited in {room_id} but attempted to knock"); + return Err!(Request(Forbidden( + "You cannot knock on a room you are already invited/accepted to." + ))); + } + + if services + .rooms + .state_cache + .is_joined(sender_user, room_id) + .await + { + debug_warn!("{sender_user} is already joined in {room_id} but attempted to knock"); + return Err!(Request(Forbidden("You cannot knock on a room you are already joined in."))); + } + + if services + .rooms + .state_cache + .is_knocked(sender_user, room_id) + .await + { + debug_warn!("{sender_user} is already knocked in {room_id}"); + return Ok(knock_room::v3::Response { room_id: room_id.into() }); + } + + if let Ok(membership) = services + .rooms + .state_accessor + .get_member(room_id, sender_user) + .await + { + if membership.membership == MembershipState::Ban { + debug_warn!("{sender_user} is banned from {room_id} but attempted to knock"); + return Err!(Request(Forbidden("You cannot knock on a room you are banned from."))); + } + } + + // For knock_restricted rooms, check if the user meets the restricted conditions + // If they do, attempt to join instead of knock + // This is not mentioned in the spec, but should be allowable (we're allowed to + // auto-join invites to knocked rooms) + let join_rule = services.rooms.state_accessor.get_join_rules(room_id).await; + + if let JoinRule::KnockRestricted(restricted) = &join_rule { + let restriction_rooms: Vec<_> = restricted + .allow + .iter() + .filter_map(|a| match a { + | AllowRule::RoomMembership(r) => Some(&r.room_id), + | _ => None, + }) + .collect(); + + // Check if the user is in any of the allowed rooms + let mut user_meets_restrictions = false; + for restriction_room_id in &restriction_rooms { + if services + .rooms + .state_cache + .is_joined(sender_user, restriction_room_id) + .await + { + user_meets_restrictions = true; + break; + } + } + + // If the user meets the restrictions, try joining instead + if user_meets_restrictions { + debug_info!( + "{sender_user} meets the restricted criteria in knock_restricted room \ + {room_id}, attempting to join instead of knock" + ); + // For this case, we need to drop the state lock and get a new one in + // join_room_by_id_helper We need to release the lock here and let + // join_room_by_id_helper acquire it again + drop(state_lock); + match join_room_by_id_helper( + services, + sender_user, + room_id, + reason.clone(), + servers, + None, + &None, + ) + .await + { + | Ok(_) => return Ok(knock_room::v3::Response::new(room_id.to_owned())), + | Err(e) => { + debug_warn!( + "Failed to convert knock to join for {sender_user} in {room_id}: {e:?}" + ); + // Get a new state lock for the remaining knock logic + let new_state_lock = services.rooms.state.mutex.lock(room_id).await; + + let server_in_room = services + .rooms + .state_cache + .server_in_room(services.globals.server_name(), room_id) + .await; + + let local_knock = server_in_room + || servers.is_empty() + || (servers.len() == 1 && services.globals.server_is_ours(&servers[0])); + + if local_knock { + knock_room_helper_local( + services, + sender_user, + room_id, + reason, + servers, + new_state_lock, + ) + .boxed() + .await?; + } else { + knock_room_helper_remote( + services, + sender_user, + room_id, + reason, + servers, + new_state_lock, + ) + .boxed() + .await?; + } + + return Ok(knock_room::v3::Response::new(room_id.to_owned())); + }, + } + } + } else if !matches!(join_rule, JoinRule::Knock | JoinRule::KnockRestricted(_)) { + debug_warn!( + "{sender_user} attempted to knock on room {room_id} but its join rule is \ + {join_rule:?}, not knock or knock_restricted" + ); + } + + let server_in_room = services + .rooms + .state_cache + .server_in_room(services.globals.server_name(), room_id) + .await; + + let local_knock = server_in_room + || servers.is_empty() + || (servers.len() == 1 && services.globals.server_is_ours(&servers[0])); + + if local_knock { + knock_room_helper_local(services, sender_user, room_id, reason, servers, state_lock) + .boxed() + .await?; + } else { + knock_room_helper_remote(services, sender_user, room_id, reason, servers, state_lock) + .boxed() + .await?; + } + + Ok(knock_room::v3::Response::new(room_id.to_owned())) +} + +async fn knock_room_helper_local( + services: &Services, + sender_user: &UserId, + room_id: &RoomId, + reason: Option, + servers: &[OwnedServerName], + state_lock: RoomMutexGuard, +) -> Result { + debug_info!("We can knock locally"); + + let room_version_id = services.rooms.state.get_room_version(room_id).await?; + + if matches!( + room_version_id, + RoomVersionId::V1 + | RoomVersionId::V2 + | RoomVersionId::V3 + | RoomVersionId::V4 + | RoomVersionId::V5 + | RoomVersionId::V6 + ) { + return Err!(Request(Forbidden("This room does not support knocking."))); + } + + let content = RoomMemberEventContent { + displayname: services.users.displayname(sender_user).await.ok(), + avatar_url: services.users.avatar_url(sender_user).await.ok(), + blurhash: services.users.blurhash(sender_user).await.ok(), + reason: reason.clone(), + ..RoomMemberEventContent::new(MembershipState::Knock) + }; + + // Try normal knock first + let Err(error) = services + .rooms + .timeline + .build_and_append_pdu( + PduBuilder::state(sender_user.to_string(), &content), + sender_user, + room_id, + &state_lock, + ) + .await + else { + return Ok(()); + }; + + if servers.is_empty() || (servers.len() == 1 && services.globals.server_is_ours(&servers[0])) + { + return Err(error); + } + + warn!("We couldn't do the knock locally, maybe federation can help to satisfy the knock"); + + let (make_knock_response, remote_server) = + make_knock_request(services, sender_user, room_id, servers).await?; + + info!("make_knock finished"); + + let room_version_id = make_knock_response.room_version; + + if !services.server.supported_room_version(&room_version_id) { + return Err!(BadServerResponse( + "Remote room version {room_version_id} is not supported by conduwuit" + )); + } + + let mut knock_event_stub = serde_json::from_str::( + make_knock_response.event.get(), + ) + .map_err(|e| { + err!(BadServerResponse("Invalid make_knock event json received from server: {e:?}")) + })?; + + knock_event_stub.insert( + "origin".to_owned(), + CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()), + ); + knock_event_stub.insert( + "origin_server_ts".to_owned(), + CanonicalJsonValue::Integer( + utils::millis_since_unix_epoch() + .try_into() + .expect("Timestamp is valid js_int value"), + ), + ); + knock_event_stub.insert( + "content".to_owned(), + to_canonical_value(RoomMemberEventContent { + displayname: services.users.displayname(sender_user).await.ok(), + avatar_url: services.users.avatar_url(sender_user).await.ok(), + blurhash: services.users.blurhash(sender_user).await.ok(), + reason, + ..RoomMemberEventContent::new(MembershipState::Knock) + }) + .expect("event is valid, we just created it"), + ); + + // In order to create a compatible ref hash (EventID) the `hashes` field needs + // to be present + services + .server_keys + .hash_and_sign_event(&mut knock_event_stub, &room_version_id)?; + + // Generate event id + let event_id = gen_event_id(&knock_event_stub, &room_version_id)?; + + // Add event_id + knock_event_stub + .insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into())); + + // It has enough fields to be called a proper event now + let knock_event = knock_event_stub; + + info!("Asking {remote_server} for send_knock in room {room_id}"); + let send_knock_request = federation::knock::send_knock::v1::Request { + room_id: room_id.to_owned(), + event_id: event_id.clone(), + pdu: services + .sending + .convert_to_outgoing_federation_event(knock_event.clone()) + .await, + }; + + let send_knock_response = services + .sending + .send_federation_request(&remote_server, send_knock_request) + .await?; + + info!("send_knock finished"); + + services + .rooms + .short + .get_or_create_shortroomid(room_id) + .await; + + info!("Parsing knock event"); + + let parsed_knock_pdu = PduEvent::from_id_val(&event_id, knock_event.clone()) + .map_err(|e| err!(BadServerResponse("Invalid knock event PDU: {e:?}")))?; + + info!("Updating membership locally to knock state with provided stripped state events"); + services + .rooms + .state_cache + .update_membership( + room_id, + sender_user, + parsed_knock_pdu + .get_content::() + .expect("we just created this"), + sender_user, + Some(send_knock_response.knock_room_state), + None, + false, + ) + .await?; + + info!("Appending room knock event locally"); + services + .rooms + .timeline + .append_pdu( + &parsed_knock_pdu, + knock_event, + once(parsed_knock_pdu.event_id.borrow()), + &state_lock, + ) + .await?; + + Ok(()) +} + +async fn knock_room_helper_remote( + services: &Services, + sender_user: &UserId, + room_id: &RoomId, + reason: Option, + servers: &[OwnedServerName], + state_lock: RoomMutexGuard, +) -> Result { + info!("Knocking {room_id} over federation."); + + let (make_knock_response, remote_server) = + make_knock_request(services, sender_user, room_id, servers).await?; + + info!("make_knock finished"); + + let room_version_id = make_knock_response.room_version; + + if !services.server.supported_room_version(&room_version_id) { + return Err!(BadServerResponse( + "Remote room version {room_version_id} is not supported by conduwuit" + )); + } + + let mut knock_event_stub: CanonicalJsonObject = + serde_json::from_str(make_knock_response.event.get()).map_err(|e| { + err!(BadServerResponse("Invalid make_knock event json received from server: {e:?}")) + })?; + + knock_event_stub.insert( + "origin".to_owned(), + CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()), + ); + knock_event_stub.insert( + "origin_server_ts".to_owned(), + CanonicalJsonValue::Integer( + utils::millis_since_unix_epoch() + .try_into() + .expect("Timestamp is valid js_int value"), + ), + ); + knock_event_stub.insert( + "content".to_owned(), + to_canonical_value(RoomMemberEventContent { + displayname: services.users.displayname(sender_user).await.ok(), + avatar_url: services.users.avatar_url(sender_user).await.ok(), + blurhash: services.users.blurhash(sender_user).await.ok(), + reason, + ..RoomMemberEventContent::new(MembershipState::Knock) + }) + .expect("event is valid, we just created it"), + ); + + // In order to create a compatible ref hash (EventID) the `hashes` field needs + // to be present + services + .server_keys + .hash_and_sign_event(&mut knock_event_stub, &room_version_id)?; + + // Generate event id + let event_id = gen_event_id(&knock_event_stub, &room_version_id)?; + + // Add event_id + knock_event_stub + .insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into())); + + // It has enough fields to be called a proper event now + let knock_event = knock_event_stub; + + info!("Asking {remote_server} for send_knock in room {room_id}"); + let send_knock_request = federation::knock::send_knock::v1::Request { + room_id: room_id.to_owned(), + event_id: event_id.clone(), + pdu: services + .sending + .convert_to_outgoing_federation_event(knock_event.clone()) + .await, + }; + + let send_knock_response = services + .sending + .send_federation_request(&remote_server, send_knock_request) + .await?; + + info!("send_knock finished"); + + services + .rooms + .short + .get_or_create_shortroomid(room_id) + .await; + + info!("Parsing knock event"); + let parsed_knock_pdu = PduEvent::from_id_val(&event_id, knock_event.clone()) + .map_err(|e| err!(BadServerResponse("Invalid knock event PDU: {e:?}")))?; + + info!("Going through send_knock response knock state events"); + let state = send_knock_response + .knock_room_state + .iter() + .map(|event| serde_json::from_str::(event.clone().into_json().get())) + .filter_map(Result::ok); + + let mut state_map: HashMap = HashMap::new(); + + for event in state { + let Some(state_key) = event.get("state_key") else { + debug_warn!("send_knock stripped state event missing state_key: {event:?}"); + continue; + }; + let Some(event_type) = event.get("type") else { + debug_warn!("send_knock stripped state event missing event type: {event:?}"); + continue; + }; + + let Ok(state_key) = serde_json::from_value::(state_key.clone().into()) else { + debug_warn!("send_knock stripped state event has invalid state_key: {event:?}"); + continue; + }; + let Ok(event_type) = serde_json::from_value::(event_type.clone().into()) + else { + debug_warn!("send_knock stripped state event has invalid event type: {event:?}"); + continue; + }; + + let event_id = gen_event_id(&event, &room_version_id)?; + let shortstatekey = services + .rooms + .short + .get_or_create_shortstatekey(&event_type, &state_key) + .await; + + services.rooms.outlier.add_pdu_outlier(&event_id, &event); + state_map.insert(shortstatekey, event_id.clone()); + } + + info!("Compressing state from send_knock"); + let compressed: CompressedState = services + .rooms + .state_compressor + .compress_state_events(state_map.iter().map(|(ssk, eid)| (ssk, eid.borrow()))) + .collect() + .await; + + debug!("Saving compressed state"); + let HashSetCompressStateEvent { + shortstatehash: statehash_before_knock, + added, + removed, + } = services + .rooms + .state_compressor + .save_state(room_id, Arc::new(compressed)) + .await?; + + debug!("Forcing state for new room"); + services + .rooms + .state + .force_state(room_id, statehash_before_knock, added, removed, &state_lock) + .await?; + + let statehash_after_knock = services + .rooms + .state + .append_to_state(&parsed_knock_pdu) + .await?; + + info!("Updating membership locally to knock state with provided stripped state events"); + services + .rooms + .state_cache + .update_membership( + room_id, + sender_user, + parsed_knock_pdu + .get_content::() + .expect("we just created this"), + sender_user, + Some(send_knock_response.knock_room_state), + None, + false, + ) + .await?; + + info!("Appending room knock event locally"); + services + .rooms + .timeline + .append_pdu( + &parsed_knock_pdu, + knock_event, + once(parsed_knock_pdu.event_id.borrow()), + &state_lock, + ) + .await?; + + info!("Setting final room state for new room"); + // We set the room state after inserting the pdu, so that we never have a moment + // in time where events in the current room state do not exist + services + .rooms + .state + .set_room_state(room_id, statehash_after_knock, &state_lock); + + Ok(()) +} + +async fn make_knock_request( + services: &Services, + sender_user: &UserId, + room_id: &RoomId, + servers: &[OwnedServerName], +) -> Result<(federation::knock::create_knock_event_template::v1::Response, OwnedServerName)> { + let mut make_knock_response_and_server = + Err!(BadServerResponse("No server available to assist in knocking.")); + + let mut make_knock_counter: usize = 0; + + for remote_server in servers { + if services.globals.server_is_ours(remote_server) { + continue; + } + + info!("Asking {remote_server} for make_knock ({make_knock_counter})"); + + let make_knock_response = services + .sending + .send_federation_request( + remote_server, + federation::knock::create_knock_event_template::v1::Request { + room_id: room_id.to_owned(), + user_id: sender_user.to_owned(), + ver: services.server.supported_room_versions().collect(), + }, + ) + .await; + + trace!("make_knock response: {make_knock_response:?}"); + make_knock_counter = make_knock_counter.saturating_add(1); + + make_knock_response_and_server = make_knock_response.map(|r| (r, remote_server.clone())); + + if make_knock_response_and_server.is_ok() { + break; + } + + if make_knock_counter > 40 { + warn!( + "50 servers failed to provide valid make_knock response, assuming no server can \ + assist in knocking." + ); + make_knock_response_and_server = + Err!(BadServerResponse("No server available to assist in knocking.")); + + return make_knock_response_and_server; + } + } + + make_knock_response_and_server +} diff --git a/src/api/client/membership/leave.rs b/src/api/client/membership/leave.rs new file mode 100644 index 00000000..a64fb41f --- /dev/null +++ b/src/api/client/membership/leave.rs @@ -0,0 +1,386 @@ +use std::collections::HashSet; + +use axum::extract::State; +use conduwuit::{ + Err, Result, debug_info, debug_warn, err, + matrix::pdu::{PduBuilder, gen_event_id}, + utils::{self, FutureBoolExt, future::ReadyEqExt}, + warn, +}; +use futures::{FutureExt, StreamExt, TryFutureExt, pin_mut}; +use ruma::{ + CanonicalJsonObject, CanonicalJsonValue, OwnedServerName, RoomId, RoomVersionId, UserId, + api::{ + client::membership::leave_room, + federation::{self}, + }, + events::{ + StateEventType, + room::member::{MembershipState, RoomMemberEventContent}, + }, +}; +use service::Services; + +use crate::Ruma; + +/// # `POST /_matrix/client/v3/rooms/{roomId}/leave` +/// +/// Tries to leave the sender user from a room. +/// +/// - This should always work if the user is currently joined. +pub(crate) async fn leave_room_route( + State(services): State, + body: Ruma, +) -> Result { + leave_room(&services, body.sender_user(), &body.room_id, body.reason.clone()) + .boxed() + .await + .map(|()| leave_room::v3::Response::new()) +} + +// Make a user leave all their joined rooms, rescinds knocks, forgets all rooms, +// and ignores errors +pub async fn leave_all_rooms(services: &Services, user_id: &UserId) { + let rooms_joined = services + .rooms + .state_cache + .rooms_joined(user_id) + .map(ToOwned::to_owned); + + let rooms_invited = services + .rooms + .state_cache + .rooms_invited(user_id) + .map(|(r, _)| r); + + let rooms_knocked = services + .rooms + .state_cache + .rooms_knocked(user_id) + .map(|(r, _)| r); + + let all_rooms: Vec<_> = rooms_joined + .chain(rooms_invited) + .chain(rooms_knocked) + .collect() + .await; + + for room_id in all_rooms { + // ignore errors + if let Err(e) = leave_room(services, user_id, &room_id, None).boxed().await { + warn!(%user_id, "Failed to leave {room_id} remotely: {e}"); + } + + services.rooms.state_cache.forget(&room_id, user_id); + } +} + +pub async fn leave_room( + services: &Services, + user_id: &UserId, + room_id: &RoomId, + reason: Option, +) -> Result { + let default_member_content = RoomMemberEventContent { + membership: MembershipState::Leave, + reason: reason.clone(), + join_authorized_via_users_server: None, + is_direct: None, + avatar_url: None, + displayname: None, + third_party_invite: None, + blurhash: None, + redact_events: None, + }; + + let is_banned = services.rooms.metadata.is_banned(room_id); + let is_disabled = services.rooms.metadata.is_disabled(room_id); + + pin_mut!(is_banned, is_disabled); + if is_banned.or(is_disabled).await { + // the room is banned/disabled, the room must be rejected locally since we + // cant/dont want to federate with this server + services + .rooms + .state_cache + .update_membership( + room_id, + user_id, + default_member_content, + user_id, + None, + None, + true, + ) + .await?; + + return Ok(()); + } + + let dont_have_room = services + .rooms + .state_cache + .server_in_room(services.globals.server_name(), room_id) + .eq(&false); + + let not_knocked = services + .rooms + .state_cache + .is_knocked(user_id, room_id) + .eq(&false); + + // Ask a remote server if we don't have this room and are not knocking on it + if dont_have_room.and(not_knocked).await { + if let Err(e) = remote_leave_room(services, user_id, room_id, reason.clone()) + .boxed() + .await + { + warn!(%user_id, "Failed to leave room {room_id} remotely: {e}"); + // Don't tell the client about this error + } + + let last_state = services + .rooms + .state_cache + .invite_state(user_id, room_id) + .or_else(|_| services.rooms.state_cache.knock_state(user_id, room_id)) + .or_else(|_| services.rooms.state_cache.left_state(user_id, room_id)) + .await + .ok(); + + // We always drop the invite, we can't rely on other servers + services + .rooms + .state_cache + .update_membership( + room_id, + user_id, + default_member_content, + user_id, + last_state, + None, + true, + ) + .await?; + } else { + let state_lock = services.rooms.state.mutex.lock(room_id).await; + + let Ok(event) = services + .rooms + .state_accessor + .room_state_get_content::( + room_id, + &StateEventType::RoomMember, + user_id.as_str(), + ) + .await + else { + debug_warn!( + "Trying to leave a room you are not a member of, marking room as left locally." + ); + + return services + .rooms + .state_cache + .update_membership( + room_id, + user_id, + default_member_content, + user_id, + None, + None, + true, + ) + .await; + }; + + services + .rooms + .timeline + .build_and_append_pdu( + PduBuilder::state(user_id.to_string(), &RoomMemberEventContent { + membership: MembershipState::Leave, + reason, + join_authorized_via_users_server: None, + is_direct: None, + ..event + }), + user_id, + room_id, + &state_lock, + ) + .await?; + } + + Ok(()) +} + +async fn remote_leave_room( + services: &Services, + user_id: &UserId, + room_id: &RoomId, + reason: Option, +) -> Result<()> { + let mut make_leave_response_and_server = + Err!(BadServerResponse("No remote server available to assist in leaving {room_id}.")); + + let mut servers: HashSet = services + .rooms + .state_cache + .servers_invite_via(room_id) + .map(ToOwned::to_owned) + .collect() + .await; + + match services + .rooms + .state_cache + .invite_state(user_id, room_id) + .await + { + | Ok(invite_state) => { + servers.extend( + invite_state + .iter() + .filter_map(|event| event.get_field("sender").ok().flatten()) + .filter_map(|sender: &str| UserId::parse(sender).ok()) + .map(|user| user.server_name().to_owned()), + ); + }, + | _ => { + match services + .rooms + .state_cache + .knock_state(user_id, room_id) + .await + { + | Ok(knock_state) => { + servers.extend( + knock_state + .iter() + .filter_map(|event| event.get_field("sender").ok().flatten()) + .filter_map(|sender: &str| UserId::parse(sender).ok()) + .filter_map(|sender| { + if !services.globals.user_is_local(sender) { + Some(sender.server_name().to_owned()) + } else { + None + } + }), + ); + }, + | _ => {}, + } + }, + } + + if let Some(room_id_server_name) = room_id.server_name() { + servers.insert(room_id_server_name.to_owned()); + } + + debug_info!("servers in remote_leave_room: {servers:?}"); + + for remote_server in servers { + let make_leave_response = services + .sending + .send_federation_request( + &remote_server, + federation::membership::prepare_leave_event::v1::Request { + room_id: room_id.to_owned(), + user_id: user_id.to_owned(), + }, + ) + .await; + + make_leave_response_and_server = make_leave_response.map(|r| (r, remote_server)); + + if make_leave_response_and_server.is_ok() { + break; + } + } + + let (make_leave_response, remote_server) = make_leave_response_and_server?; + + let Some(room_version_id) = make_leave_response.room_version else { + return Err!(BadServerResponse(warn!( + "No room version was returned by {remote_server} for {room_id}, room version is \ + likely not supported by conduwuit" + ))); + }; + + if !services.server.supported_room_version(&room_version_id) { + return Err!(BadServerResponse(warn!( + "Remote room version {room_version_id} for {room_id} is not supported by conduwuit", + ))); + } + + let mut leave_event_stub = serde_json::from_str::( + make_leave_response.event.get(), + ) + .map_err(|e| { + err!(BadServerResponse(warn!( + "Invalid make_leave event json received from {remote_server} for {room_id}: {e:?}" + ))) + })?; + + // TODO: Is origin needed? + leave_event_stub.insert( + "origin".to_owned(), + CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()), + ); + leave_event_stub.insert( + "origin_server_ts".to_owned(), + CanonicalJsonValue::Integer( + utils::millis_since_unix_epoch() + .try_into() + .expect("Timestamp is valid js_int value"), + ), + ); + // Inject the reason key into the event content dict if it exists + if let Some(reason) = reason { + if let Some(CanonicalJsonValue::Object(content)) = leave_event_stub.get_mut("content") { + content.insert("reason".to_owned(), CanonicalJsonValue::String(reason)); + } + } + + // room v3 and above removed the "event_id" field from remote PDU format + match room_version_id { + | RoomVersionId::V1 | RoomVersionId::V2 => {}, + | _ => { + leave_event_stub.remove("event_id"); + }, + } + + // In order to create a compatible ref hash (EventID) the `hashes` field needs + // to be present + services + .server_keys + .hash_and_sign_event(&mut leave_event_stub, &room_version_id)?; + + // Generate event id + let event_id = gen_event_id(&leave_event_stub, &room_version_id)?; + + // Add event_id back + leave_event_stub + .insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into())); + + // It has enough fields to be called a proper event now + let leave_event = leave_event_stub; + + services + .sending + .send_federation_request( + &remote_server, + federation::membership::create_leave_event::v2::Request { + room_id: room_id.to_owned(), + event_id, + pdu: services + .sending + .convert_to_outgoing_federation_event(leave_event.clone()) + .await, + }, + ) + .await?; + + Ok(()) +} diff --git a/src/api/client/membership/members.rs b/src/api/client/membership/members.rs new file mode 100644 index 00000000..4a7abf6d --- /dev/null +++ b/src/api/client/membership/members.rs @@ -0,0 +1,147 @@ +use axum::extract::State; +use conduwuit::{ + Err, Event, Result, at, + matrix::pdu::PduEvent, + utils::{ + future::TryExtExt, + stream::{BroadbandExt, ReadyExt}, + }, +}; +use futures::{StreamExt, future::join}; +use ruma::{ + api::client::membership::{ + get_member_events::{self, v3::MembershipEventFilter}, + joined_members::{self, v3::RoomMember}, + }, + events::{ + StateEventType, + room::member::{MembershipState, RoomMemberEventContent}, + }, +}; + +use crate::Ruma; + +/// # `POST /_matrix/client/r0/rooms/{roomId}/members` +/// +/// Lists all joined users in a room (TODO: at a specific point in time, with a +/// specific membership). +/// +/// - Only works if the user is currently joined +pub(crate) async fn get_member_events_route( + State(services): State, + body: Ruma, +) -> Result { + let sender_user = body.sender_user(); + let membership = body.membership.as_ref(); + let not_membership = body.not_membership.as_ref(); + + if !services + .rooms + .state_accessor + .user_can_see_state_events(sender_user, &body.room_id) + .await + { + return Err!(Request(Forbidden("You don't have permission to view this room."))); + } + + Ok(get_member_events::v3::Response { + chunk: services + .rooms + .state_accessor + .room_state_full(&body.room_id) + .ready_filter_map(Result::ok) + .ready_filter(|((ty, _), _)| *ty == StateEventType::RoomMember) + .map(at!(1)) + .ready_filter_map(|pdu| membership_filter(pdu, membership, not_membership)) + .map(Event::into_format) + .collect() + .await, + }) +} + +/// # `POST /_matrix/client/r0/rooms/{roomId}/joined_members` +/// +/// Lists all members of a room. +/// +/// - The sender user must be in the room +/// - TODO: An appservice just needs a puppet joined +pub(crate) async fn joined_members_route( + State(services): State, + body: Ruma, +) -> Result { + if !services + .rooms + .state_accessor + .user_can_see_state_events(body.sender_user(), &body.room_id) + .await + { + return Err!(Request(Forbidden("You don't have permission to view this room."))); + } + + Ok(joined_members::v3::Response { + joined: services + .rooms + .state_cache + .room_members(&body.room_id) + .map(ToOwned::to_owned) + .broad_then(|user_id| async move { + let (display_name, avatar_url) = join( + services.users.displayname(&user_id).ok(), + services.users.avatar_url(&user_id).ok(), + ) + .await; + + (user_id, RoomMember { display_name, avatar_url }) + }) + .collect() + .await, + }) +} + +fn membership_filter( + pdu: PduEvent, + for_membership: Option<&MembershipEventFilter>, + not_membership: Option<&MembershipEventFilter>, +) -> Option { + let membership_state_filter = match for_membership { + | Some(MembershipEventFilter::Ban) => MembershipState::Ban, + | Some(MembershipEventFilter::Invite) => MembershipState::Invite, + | Some(MembershipEventFilter::Knock) => MembershipState::Knock, + | Some(MembershipEventFilter::Leave) => MembershipState::Leave, + | Some(_) | None => MembershipState::Join, + }; + + let not_membership_state_filter = match not_membership { + | Some(MembershipEventFilter::Ban) => MembershipState::Ban, + | Some(MembershipEventFilter::Invite) => MembershipState::Invite, + | Some(MembershipEventFilter::Join) => MembershipState::Join, + | Some(MembershipEventFilter::Knock) => MembershipState::Knock, + | Some(_) | None => MembershipState::Leave, + }; + + let evt_membership = pdu.get_content::().ok()?.membership; + + if for_membership.is_some() && not_membership.is_some() { + if membership_state_filter != evt_membership + || not_membership_state_filter == evt_membership + { + None + } else { + Some(pdu) + } + } else if for_membership.is_some() && not_membership.is_none() { + if membership_state_filter != evt_membership { + None + } else { + Some(pdu) + } + } else if not_membership.is_some() && for_membership.is_none() { + if not_membership_state_filter == evt_membership { + None + } else { + Some(pdu) + } + } else { + Some(pdu) + } +} diff --git a/src/api/client/membership/mod.rs b/src/api/client/membership/mod.rs new file mode 100644 index 00000000..7a6f19ad --- /dev/null +++ b/src/api/client/membership/mod.rs @@ -0,0 +1,156 @@ +mod ban; +mod forget; +mod invite; +mod join; +mod kick; +mod knock; +mod leave; +mod members; +mod unban; + +use std::net::IpAddr; + +use axum::extract::State; +use conduwuit::{Err, Result, warn}; +use futures::{FutureExt, StreamExt}; +use ruma::{OwnedRoomId, RoomId, ServerName, UserId, api::client::membership::joined_rooms}; +use service::Services; + +pub(crate) use self::{ + ban::ban_user_route, + forget::forget_room_route, + invite::{invite_helper, invite_user_route}, + join::{join_room_by_id_or_alias_route, join_room_by_id_route}, + kick::kick_user_route, + knock::knock_room_route, + leave::leave_room_route, + members::{get_member_events_route, joined_members_route}, + unban::unban_user_route, +}; +pub use self::{ + join::join_room_by_id_helper, + leave::{leave_all_rooms, leave_room}, +}; +use crate::{Ruma, client::full_user_deactivate}; + +/// # `POST /_matrix/client/r0/joined_rooms` +/// +/// Lists all rooms the user has joined. +pub(crate) async fn joined_rooms_route( + State(services): State, + body: Ruma, +) -> Result { + Ok(joined_rooms::v3::Response { + joined_rooms: services + .rooms + .state_cache + .rooms_joined(body.sender_user()) + .map(ToOwned::to_owned) + .collect() + .await, + }) +} + +/// Checks if the room is banned in any way possible and the sender user is not +/// an admin. +/// +/// Performs automatic deactivation if `auto_deactivate_banned_room_attempts` is +/// enabled +#[tracing::instrument(skip(services))] +pub(crate) async fn banned_room_check( + services: &Services, + user_id: &UserId, + room_id: Option<&RoomId>, + server_name: Option<&ServerName>, + client_ip: IpAddr, +) -> Result { + if services.users.is_admin(user_id).await { + return Ok(()); + } + + if let Some(room_id) = room_id { + if services.rooms.metadata.is_banned(room_id).await + || services + .moderation + .is_remote_server_forbidden(room_id.server_name().expect("legacy room mxid")) + { + warn!( + "User {user_id} who is not an admin attempted to send an invite for or \ + attempted to join a banned room or banned room server name: {room_id}" + ); + + if services.server.config.auto_deactivate_banned_room_attempts { + warn!( + "Automatically deactivating user {user_id} due to attempted banned room join" + ); + + if services.server.config.admin_room_notices { + services + .admin + .send_text(&format!( + "Automatically deactivating user {user_id} due to attempted banned \ + room join from IP {client_ip}" + )) + .await; + } + + let all_joined_rooms: Vec = services + .rooms + .state_cache + .rooms_joined(user_id) + .map(Into::into) + .collect() + .await; + + full_user_deactivate(services, user_id, &all_joined_rooms) + .boxed() + .await?; + } + + return Err!(Request(Forbidden("This room is banned on this homeserver."))); + } + } else if let Some(server_name) = server_name { + if services + .config + .forbidden_remote_server_names + .is_match(server_name.host()) + { + warn!( + "User {user_id} who is not an admin tried joining a room which has the server \ + name {server_name} that is globally forbidden. Rejecting.", + ); + + if services.server.config.auto_deactivate_banned_room_attempts { + warn!( + "Automatically deactivating user {user_id} due to attempted banned room join" + ); + + if services.server.config.admin_room_notices { + services + .admin + .send_text(&format!( + "Automatically deactivating user {user_id} due to attempted banned \ + room join from IP {client_ip}" + )) + .await; + } + + let all_joined_rooms: Vec = services + .rooms + .state_cache + .rooms_joined(user_id) + .map(Into::into) + .collect() + .await; + + full_user_deactivate(services, user_id, &all_joined_rooms) + .boxed() + .await?; + } + + return Err!(Request(Forbidden("This remote server is banned on this homeserver."))); + } + } + + Ok(()) +} diff --git a/src/api/client/membership/unban.rs b/src/api/client/membership/unban.rs new file mode 100644 index 00000000..34c5eace --- /dev/null +++ b/src/api/client/membership/unban.rs @@ -0,0 +1,58 @@ +use axum::extract::State; +use conduwuit::{Err, Result, matrix::pdu::PduBuilder}; +use ruma::{ + api::client::membership::unban_user, + events::room::member::{MembershipState, RoomMemberEventContent}, +}; + +use crate::Ruma; + +/// # `POST /_matrix/client/r0/rooms/{roomId}/unban` +/// +/// Tries to send an unban event into the room. +pub(crate) async fn unban_user_route( + State(services): State, + body: Ruma, +) -> Result { + let sender_user = body.sender_user(); + if services.users.is_suspended(sender_user).await? { + return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); + } + let state_lock = services.rooms.state.mutex.lock(&body.room_id).await; + + let current_member_content = services + .rooms + .state_accessor + .get_member(&body.room_id, &body.user_id) + .await + .unwrap_or_else(|_| RoomMemberEventContent::new(MembershipState::Leave)); + + if current_member_content.membership != MembershipState::Ban { + return Err!(Request(Forbidden( + "Cannot unban a user who is not banned (current membership: {})", + current_member_content.membership + ))); + } + + services + .rooms + .timeline + .build_and_append_pdu( + PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent { + membership: MembershipState::Leave, + reason: body.reason.clone(), + join_authorized_via_users_server: None, + third_party_invite: None, + is_direct: None, + ..current_member_content + }), + sender_user, + &body.room_id, + &state_lock, + ) + .await?; + + drop(state_lock); + + Ok(unban_user::v3::Response::new()) +} diff --git a/src/api/client/profile.rs b/src/api/client/profile.rs index 6efad64e..ff8c2a0b 100644 --- a/src/api/client/profile.rs +++ b/src/api/client/profile.rs @@ -4,11 +4,14 @@ use axum::extract::State; use conduwuit::{ Err, Result, matrix::pdu::PduBuilder, - utils::{IterStream, stream::TryIgnore}, + utils::{IterStream, future::TryExtExt, stream::TryIgnore}, warn, }; use conduwuit_service::Services; -use futures::{StreamExt, TryStreamExt, future::join3}; +use futures::{ + StreamExt, TryStreamExt, + future::{join, join3, join4}, +}; use ruma::{ OwnedMxcUri, OwnedRoomId, UserId, api::{ @@ -214,10 +217,13 @@ pub(crate) async fn get_avatar_url_route( return Err!(Request(NotFound("Profile was not found."))); } - Ok(get_avatar_url::v3::Response { - avatar_url: services.users.avatar_url(&body.user_id).await.ok(), - blurhash: services.users.blurhash(&body.user_id).await.ok(), - }) + let (avatar_url, blurhash) = join( + services.users.avatar_url(&body.user_id).ok(), + services.users.blurhash(&body.user_id).ok(), + ) + .await; + + Ok(get_avatar_url::v3::Response { avatar_url, blurhash }) } /// # `GET /_matrix/client/v3/profile/{userId}` @@ -297,11 +303,19 @@ pub(crate) async fn get_profile_route( custom_profile_fields.remove("us.cloke.msc4175.tz"); custom_profile_fields.remove("m.tz"); + let (avatar_url, blurhash, displayname, tz) = join4( + services.users.avatar_url(&body.user_id).ok(), + services.users.blurhash(&body.user_id).ok(), + services.users.displayname(&body.user_id).ok(), + services.users.timezone(&body.user_id).ok(), + ) + .await; + Ok(get_profile::v3::Response { - avatar_url: services.users.avatar_url(&body.user_id).await.ok(), - blurhash: services.users.blurhash(&body.user_id).await.ok(), - displayname: services.users.displayname(&body.user_id).await.ok(), - tz: services.users.timezone(&body.user_id).await.ok(), + avatar_url, + blurhash, + displayname, + tz, custom_profile_fields, }) } @@ -313,16 +327,12 @@ pub async fn update_displayname( all_joined_rooms: &[OwnedRoomId], ) { let (current_avatar_url, current_blurhash, current_displayname) = join3( - services.users.avatar_url(user_id), - services.users.blurhash(user_id), - services.users.displayname(user_id), + services.users.avatar_url(user_id).ok(), + services.users.blurhash(user_id).ok(), + services.users.displayname(user_id).ok(), ) .await; - let current_avatar_url = current_avatar_url.ok(); - let current_blurhash = current_blurhash.ok(); - let current_displayname = current_displayname.ok(); - if displayname == current_displayname { return; } @@ -366,16 +376,12 @@ pub async fn update_avatar_url( all_joined_rooms: &[OwnedRoomId], ) { let (current_avatar_url, current_blurhash, current_displayname) = join3( - services.users.avatar_url(user_id), - services.users.blurhash(user_id), - services.users.displayname(user_id), + services.users.avatar_url(user_id).ok(), + services.users.blurhash(user_id).ok(), + services.users.displayname(user_id).ok(), ) .await; - let current_avatar_url = current_avatar_url.ok(); - let current_blurhash = current_blurhash.ok(); - let current_displayname = current_displayname.ok(); - if current_avatar_url == avatar_url && current_blurhash == blurhash { return; } diff --git a/src/api/client/room/initial_sync.rs b/src/api/client/room/initial_sync.rs index 8b9f3ca0..c2f59d4c 100644 --- a/src/api/client/room/initial_sync.rs +++ b/src/api/client/room/initial_sync.rs @@ -1,9 +1,9 @@ use axum::extract::State; use conduwuit::{ Err, Event, Result, at, - utils::{BoolExt, stream::TryTools}, + utils::{BoolExt, future::TryExtExt, stream::TryTools}, }; -use futures::TryStreamExt; +use futures::{FutureExt, TryStreamExt, future::try_join4}; use ruma::api::client::room::initial_sync::v3::{PaginationChunk, Request, Response}; use crate::Ruma; @@ -25,22 +25,31 @@ pub(crate) async fn room_initial_sync_route( return Err!(Request(Forbidden("No room preview available."))); } - let limit = LIMIT_MAX; - let events: Vec<_> = services + let membership = services .rooms - .timeline - .pdus_rev(None, room_id, None) - .try_take(limit) - .try_collect() - .await?; + .state_cache + .user_membership(body.sender_user(), room_id) + .map(Ok); - let state: Vec<_> = services + let visibility = services.rooms.directory.visibility(room_id).map(Ok); + + let state = services .rooms .state_accessor .room_state_full_pdus(room_id) .map_ok(Event::into_format) - .try_collect() - .await?; + .try_collect::>(); + + let limit = LIMIT_MAX; + let events = services + .rooms + .timeline + .pdus_rev(None, room_id, None) + .try_take(limit) + .try_collect::>(); + + let (membership, visibility, state, events) = + try_join4(membership, visibility, state, events).await?; let messages = PaginationChunk { start: events.last().map(at!(0)).as_ref().map(ToString::to_string), @@ -64,11 +73,7 @@ pub(crate) async fn room_initial_sync_route( account_data: None, state: state.into(), messages: messages.chunk.is_empty().or_some(messages), - visibility: services.rooms.directory.visibility(room_id).await.into(), - membership: services - .rooms - .state_cache - .user_membership(body.sender_user(), room_id) - .await, + visibility: visibility.into(), + membership, }) } From 364293608de928c3acd8e7253522ca31713c8435 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 27 Apr 2025 02:39:28 +0000 Subject: [PATCH 2100/2291] Post-formatting aesthetic and spacing corrections Signed-off-by: Jason Volk --- src/admin/debug/commands.rs | 4 +- src/admin/user/commands.rs | 17 ++-- src/api/client/account.rs | 32 +++++-- src/api/client/directory.rs | 6 +- src/api/client/membership/invite.rs | 2 +- src/api/client/membership/join.rs | 3 +- src/api/client/membership/knock.rs | 5 +- src/api/client/membership/leave.rs | 2 +- src/api/client/membership/members.rs | 10 +- src/api/client/message.rs | 33 ++++--- src/api/client/profile.rs | 5 - src/api/client/relations.rs | 18 ++-- src/api/client/report.rs | 1 + src/api/client/room/initial_sync.rs | 4 +- src/api/client/room/summary.rs | 4 +- src/api/client/room/upgrade.rs | 4 +- src/api/client/sync/v4.rs | 4 +- src/api/server/invite.rs | 6 +- src/api/server/send_join.rs | 2 +- src/api/server/send_knock.rs | 2 +- src/api/server/send_leave.rs | 2 +- src/core/config/proxy.rs | 5 +- src/core/info/cargo.rs | 6 +- src/core/matrix/event.rs | 90 ++++++++++++++++-- src/core/matrix/event/filter.rs | 93 +++++++++++++++++++ .../matrix/{pdu/event_id.rs => event/id.rs} | 0 src/core/matrix/event/relation.rs | 28 ++++++ src/core/matrix/event/unsigned.rs | 51 ++++++++++ src/core/matrix/pdu.rs | 28 ++++-- src/core/matrix/pdu/content.rs | 20 ---- src/core/matrix/pdu/filter.rs | 90 ------------------ src/core/matrix/pdu/redact.rs | 4 +- src/core/matrix/pdu/relation.rs | 22 ----- src/core/matrix/pdu/unsigned.rs | 43 +-------- src/core/matrix/state_res/mod.rs | 10 +- src/core/mods/module.rs | 1 + src/core/mods/path.rs | 1 + src/core/utils/html.rs | 2 + src/core/utils/json.rs | 28 +++--- src/core/utils/time.rs | 3 - src/database/watchers.rs | 1 - src/main/logging.rs | 13 +++ src/main/mods.rs | 4 + src/main/sentry.rs | 8 +- src/router/request.rs | 2 +- src/service/admin/mod.rs | 6 +- src/service/pusher/mod.rs | 6 +- src/service/rooms/alias/mod.rs | 4 +- .../fetch_and_handle_outliers.rs | 35 ++++--- src/service/rooms/event_handler/fetch_prev.rs | 49 ++++++---- .../rooms/event_handler/fetch_state.rs | 25 ++--- .../event_handler/handle_incoming_pdu.rs | 15 +-- .../rooms/event_handler/handle_outlier_pdu.rs | 35 ++++--- .../rooms/event_handler/handle_prev_pdu.rs | 18 ++-- src/service/rooms/event_handler/mod.rs | 12 +-- .../rooms/event_handler/parse_incoming_pdu.rs | 4 +- .../rooms/event_handler/state_at_incoming.rs | 48 ++++++---- .../event_handler/upgrade_outlier_pdu.rs | 50 +++++----- src/service/rooms/outlier/mod.rs | 4 +- src/service/rooms/pdu_metadata/data.rs | 10 +- src/service/rooms/pdu_metadata/mod.rs | 19 ++-- src/service/rooms/read_receipt/mod.rs | 10 +- src/service/rooms/search/mod.rs | 12 ++- src/service/rooms/state/mod.rs | 4 +- .../rooms/state_accessor/room_state.rs | 8 +- src/service/rooms/state_accessor/state.rs | 18 ++-- src/service/rooms/state_accessor/user_can.rs | 14 +-- src/service/rooms/threads/mod.rs | 13 ++- src/service/rooms/timeline/data.rs | 1 - src/service/rooms/timeline/mod.rs | 89 +++++++++--------- src/service/sending/sender.rs | 2 +- src/service/server_keys/verify.rs | 2 +- 72 files changed, 704 insertions(+), 528 deletions(-) create mode 100644 src/core/matrix/event/filter.rs rename src/core/matrix/{pdu/event_id.rs => event/id.rs} (100%) create mode 100644 src/core/matrix/event/relation.rs create mode 100644 src/core/matrix/event/unsigned.rs delete mode 100644 src/core/matrix/pdu/content.rs delete mode 100644 src/core/matrix/pdu/filter.rs delete mode 100644 src/core/matrix/pdu/relation.rs diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index 74355311..81b0e9da 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -558,8 +558,8 @@ pub(super) async fn force_set_room_state_from_server( .latest_pdu_in_room(&room_id) .await .map_err(|_| err!(Database("Failed to find the latest PDU in database")))? - .event_id - .clone(), + .event_id() + .to_owned(), }; let room_version = self.services.rooms.state.get_room_version(&room_id).await?; diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index e15c0b2c..86206c2b 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -738,7 +738,7 @@ pub(super) async fn force_demote(&self, user_id: String, room_id: OwnedRoomOrAli .state_accessor .room_state_get(&room_id, &StateEventType::RoomCreate, "") .await - .is_ok_and(|event| event.sender == user_id); + .is_ok_and(|event| event.sender() == user_id); if !user_can_demote_self { return Err!("User is not allowed to modify their own power levels in the room.",); @@ -889,10 +889,7 @@ pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result { return Err!("Event is already redacted."); } - let room_id = event.room_id; - let sender_user = event.sender; - - if !self.services.globals.user_is_local(&sender_user) { + if !self.services.globals.user_is_local(event.sender()) { return Err!("This command only works on local users."); } @@ -902,21 +899,21 @@ pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result { ); let redaction_event_id = { - let state_lock = self.services.rooms.state.mutex.lock(&room_id).await; + let state_lock = self.services.rooms.state.mutex.lock(event.room_id()).await; self.services .rooms .timeline .build_and_append_pdu( PduBuilder { - redacts: Some(event.event_id.clone()), + redacts: Some(event.event_id().to_owned()), ..PduBuilder::timeline(&RoomRedactionEventContent { - redacts: Some(event.event_id.clone()), + redacts: Some(event.event_id().to_owned()), reason: Some(reason), }) }, - &sender_user, - &room_id, + event.sender(), + event.room_id(), &state_lock, ) .await? diff --git a/src/api/client/account.rs b/src/api/client/account.rs index 14bbcf98..df938c17 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -3,10 +3,9 @@ use std::fmt::Write; use axum::extract::State; use axum_client_ip::InsecureClientIp; use conduwuit::{ - Err, Error, Result, debug_info, err, error, info, is_equal_to, + Err, Error, Event, Result, debug_info, err, error, info, is_equal_to, matrix::pdu::PduBuilder, - utils, - utils::{ReadyExt, stream::BroadbandExt}, + utils::{self, ReadyExt, stream::BroadbandExt}, warn, }; use conduwuit_service::Services; @@ -140,16 +139,32 @@ pub(crate) async fn register_route( if !services.config.allow_registration && body.appservice_info.is_none() { match (body.username.as_ref(), body.initial_device_display_name.as_ref()) { | (Some(username), Some(device_display_name)) => { - info!(%is_guest, user = %username, device_name = %device_display_name, "Rejecting registration attempt as registration is disabled"); + info!( + %is_guest, + user = %username, + device_name = %device_display_name, + "Rejecting registration attempt as registration is disabled" + ); }, | (Some(username), _) => { - info!(%is_guest, user = %username, "Rejecting registration attempt as registration is disabled"); + info!( + %is_guest, + user = %username, + "Rejecting registration attempt as registration is disabled" + ); }, | (_, Some(device_display_name)) => { - info!(%is_guest, device_name = %device_display_name, "Rejecting registration attempt as registration is disabled"); + info!( + %is_guest, + device_name = %device_display_name, + "Rejecting registration attempt as registration is disabled" + ); }, | (None, _) => { - info!(%is_guest, "Rejecting registration attempt as registration is disabled"); + info!( + %is_guest, + "Rejecting registration attempt as registration is disabled" + ); }, } @@ -835,6 +850,7 @@ pub async fn full_user_deactivate( all_joined_rooms: &[OwnedRoomId], ) -> Result<()> { services.users.deactivate_account(user_id).await.ok(); + super::update_displayname(services, user_id, None, all_joined_rooms).await; super::update_avatar_url(services, user_id, None, None, all_joined_rooms).await; @@ -871,7 +887,7 @@ pub async fn full_user_deactivate( .state_accessor .room_state_get(room_id, &StateEventType::RoomCreate, "") .await - .is_ok_and(|event| event.sender == user_id); + .is_ok_and(|event| event.sender() == user_id); if user_can_demote_self { let mut power_levels_content = room_power_levels.unwrap_or_default(); diff --git a/src/api/client/directory.rs b/src/api/client/directory.rs index 2e219fd9..00879274 100644 --- a/src/api/client/directory.rs +++ b/src/api/client/directory.rs @@ -1,7 +1,7 @@ use axum::extract::State; use axum_client_ip::InsecureClientIp; use conduwuit::{ - Err, Result, err, info, + Err, Event, Result, err, info, utils::{ TryFutureExtExt, math::Expected, @@ -352,7 +352,7 @@ async fn user_can_publish_room( .room_state_get(room_id, &StateEventType::RoomPowerLevels, "") .await { - | Ok(event) => serde_json::from_str(event.content.get()) + | Ok(event) => serde_json::from_str(event.content().get()) .map_err(|_| err!(Database("Invalid event content for m.room.power_levels"))) .map(|content: RoomPowerLevelsEventContent| { RoomPowerLevels::from(content) @@ -365,7 +365,7 @@ async fn user_can_publish_room( .room_state_get(room_id, &StateEventType::RoomCreate, "") .await { - | Ok(event) => Ok(event.sender == user_id), + | Ok(event) => Ok(event.sender() == user_id), | _ => Err!(Request(Forbidden("User is not allowed to publish this room"))), } }, diff --git a/src/api/client/membership/invite.rs b/src/api/client/membership/invite.rs index 4ca3efb8..018fb774 100644 --- a/src/api/client/membership/invite.rs +++ b/src/api/client/membership/invite.rs @@ -2,7 +2,7 @@ use axum::extract::State; use axum_client_ip::InsecureClientIp; use conduwuit::{ Err, Result, debug_error, err, info, - matrix::pdu::{PduBuilder, gen_event_id_canonical_json}, + matrix::{event::gen_event_id_canonical_json, pdu::PduBuilder}, }; use futures::{FutureExt, join}; use ruma::{ diff --git a/src/api/client/membership/join.rs b/src/api/client/membership/join.rs index 669e9399..9d19d3bc 100644 --- a/src/api/client/membership/join.rs +++ b/src/api/client/membership/join.rs @@ -6,7 +6,8 @@ use conduwuit::{ Err, Result, debug, debug_info, debug_warn, err, error, info, matrix::{ StateKey, - pdu::{PduBuilder, PduEvent, gen_event_id, gen_event_id_canonical_json}, + event::{gen_event_id, gen_event_id_canonical_json}, + pdu::{PduBuilder, PduEvent}, state_res, }, result::FlatOk, diff --git a/src/api/client/membership/knock.rs b/src/api/client/membership/knock.rs index 544dcfb3..79f16631 100644 --- a/src/api/client/membership/knock.rs +++ b/src/api/client/membership/knock.rs @@ -4,7 +4,10 @@ use axum::extract::State; use axum_client_ip::InsecureClientIp; use conduwuit::{ Err, Result, debug, debug_info, debug_warn, err, info, - matrix::pdu::{PduBuilder, PduEvent, gen_event_id}, + matrix::{ + event::{Event, gen_event_id}, + pdu::{PduBuilder, PduEvent}, + }, result::FlatOk, trace, utils::{self, shuffle, stream::IterStream}, diff --git a/src/api/client/membership/leave.rs b/src/api/client/membership/leave.rs index a64fb41f..f4f1666b 100644 --- a/src/api/client/membership/leave.rs +++ b/src/api/client/membership/leave.rs @@ -3,7 +3,7 @@ use std::collections::HashSet; use axum::extract::State; use conduwuit::{ Err, Result, debug_info, debug_warn, err, - matrix::pdu::{PduBuilder, gen_event_id}, + matrix::{event::gen_event_id, pdu::PduBuilder}, utils::{self, FutureBoolExt, future::ReadyEqExt}, warn, }; diff --git a/src/api/client/membership/members.rs b/src/api/client/membership/members.rs index 4a7abf6d..05ba1c43 100644 --- a/src/api/client/membership/members.rs +++ b/src/api/client/membership/members.rs @@ -1,13 +1,12 @@ use axum::extract::State; use conduwuit::{ Err, Event, Result, at, - matrix::pdu::PduEvent, utils::{ future::TryExtExt, stream::{BroadbandExt, ReadyExt}, }, }; -use futures::{StreamExt, future::join}; +use futures::{FutureExt, StreamExt, future::join}; use ruma::{ api::client::membership::{ get_member_events::{self, v3::MembershipEventFilter}, @@ -55,6 +54,7 @@ pub(crate) async fn get_member_events_route( .ready_filter_map(|pdu| membership_filter(pdu, membership, not_membership)) .map(Event::into_format) .collect() + .boxed() .await, }) } @@ -98,11 +98,11 @@ pub(crate) async fn joined_members_route( }) } -fn membership_filter( - pdu: PduEvent, +fn membership_filter( + pdu: Pdu, for_membership: Option<&MembershipEventFilter>, not_membership: Option<&MembershipEventFilter>, -) -> Option { +) -> Option { let membership_state_filter = match for_membership { | Some(MembershipEventFilter::Ban) => MembershipState::Ban, | Some(MembershipEventFilter::Invite) => MembershipState::Invite, diff --git a/src/api/client/message.rs b/src/api/client/message.rs index e32d020f..f8818ebb 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -2,9 +2,10 @@ use axum::extract::State; use conduwuit::{ Err, Result, at, matrix::{ - Event, - pdu::{PduCount, PduEvent}, + event::{Event, Matches}, + pdu::PduCount, }, + ref_at, utils::{ IterStream, ReadyExt, result::{FlatOk, LogErr}, @@ -216,7 +217,9 @@ where pin_mut!(receipts); let witness: Witness = events .stream() - .map(|(_, pdu)| pdu.sender.clone()) + .map(ref_at!(1)) + .map(Event::sender) + .map(ToOwned::to_owned) .chain( receipts .ready_take_while(|(_, c, _)| *c <= newest.into_unsigned()) @@ -261,27 +264,33 @@ pub(crate) async fn ignored_filter( } #[inline] -pub(crate) async fn is_ignored_pdu( +pub(crate) async fn is_ignored_pdu( services: &Services, - pdu: &PduEvent, + event: &Pdu, user_id: &UserId, -) -> bool { +) -> bool +where + Pdu: Event + Send + Sync, +{ // exclude Synapse's dummy events from bloating up response bodies. clients // don't need to see this. - if pdu.kind.to_cow_str() == "org.matrix.dummy_event" { + if event.kind().to_cow_str() == "org.matrix.dummy_event" { return true; } - let ignored_type = IGNORED_MESSAGE_TYPES.binary_search(&pdu.kind).is_ok(); + let ignored_type = IGNORED_MESSAGE_TYPES.binary_search(event.kind()).is_ok(); let ignored_server = services .moderation - .is_remote_server_ignored(pdu.sender().server_name()); + .is_remote_server_ignored(event.sender().server_name()); if ignored_type && (ignored_server || (!services.config.send_messages_from_ignored_users_to_client - && services.users.user_is_ignored(&pdu.sender, user_id).await)) + && services + .users + .user_is_ignored(event.sender(), user_id) + .await)) { return true; } @@ -300,7 +309,7 @@ pub(crate) async fn visibility_filter( services .rooms .state_accessor - .user_can_see_event(user_id, &pdu.room_id, &pdu.event_id) + .user_can_see_event(user_id, pdu.room_id(), pdu.event_id()) .await .then_some(item) } @@ -308,7 +317,7 @@ pub(crate) async fn visibility_filter( #[inline] pub(crate) fn event_filter(item: PdusIterItem, filter: &RoomEventFilter) -> Option { let (_, pdu) = &item; - pdu.matches(filter).then_some(item) + filter.matches(pdu).then_some(item) } #[cfg_attr(debug_assertions, conduwuit::ctor)] diff --git a/src/api/client/profile.rs b/src/api/client/profile.rs index ff8c2a0b..1882495c 100644 --- a/src/api/client/profile.rs +++ b/src/api/client/profile.rs @@ -195,11 +195,9 @@ pub(crate) async fn get_avatar_url_route( services .users .set_displayname(&body.user_id, response.displayname.clone()); - services .users .set_avatar_url(&body.user_id, response.avatar_url.clone()); - services .users .set_blurhash(&body.user_id, response.blurhash.clone()); @@ -256,15 +254,12 @@ pub(crate) async fn get_profile_route( services .users .set_displayname(&body.user_id, response.displayname.clone()); - services .users .set_avatar_url(&body.user_id, response.avatar_url.clone()); - services .users .set_blurhash(&body.user_id, response.blurhash.clone()); - services .users .set_timezone(&body.user_id, response.tz.clone()); diff --git a/src/api/client/relations.rs b/src/api/client/relations.rs index ad726b90..1aa34ada 100644 --- a/src/api/client/relations.rs +++ b/src/api/client/relations.rs @@ -1,10 +1,10 @@ use axum::extract::State; use conduwuit::{ Result, at, - matrix::{Event, pdu::PduCount}, + matrix::{Event, event::RelationTypeEqual, pdu::PduCount}, utils::{IterStream, ReadyExt, result::FlatOk, stream::WidebandExt}, }; -use conduwuit_service::{Services, rooms::timeline::PdusIterItem}; +use conduwuit_service::Services; use futures::StreamExt; use ruma::{ EventId, RoomId, UInt, UserId, @@ -129,7 +129,7 @@ async fn paginate_relations_with_filter( // Spec (v1.10) recommends depth of at least 3 let depth: u8 = if recurse { 3 } else { 1 }; - let events: Vec = services + let events: Vec<_> = services .rooms .pdu_metadata .get_relations(sender_user, room_id, target, start, limit, depth, dir) @@ -138,12 +138,12 @@ async fn paginate_relations_with_filter( .filter(|(_, pdu)| { filter_event_type .as_ref() - .is_none_or(|kind| *kind == pdu.kind) + .is_none_or(|kind| kind == pdu.kind()) }) .filter(|(_, pdu)| { filter_rel_type .as_ref() - .is_none_or(|rel_type| pdu.relation_type_equal(rel_type)) + .is_none_or(|rel_type| rel_type.relation_type_equal(pdu)) }) .stream() .ready_take_while(|(count, _)| Some(*count) != to) @@ -172,17 +172,17 @@ async fn paginate_relations_with_filter( }) } -async fn visibility_filter( +async fn visibility_filter( services: &Services, sender_user: &UserId, - item: PdusIterItem, -) -> Option { + item: (PduCount, Pdu), +) -> Option<(PduCount, Pdu)> { let (_, pdu) = &item; services .rooms .state_accessor - .user_can_see_event(sender_user, &pdu.room_id, &pdu.event_id) + .user_can_see_event(sender_user, pdu.room_id(), pdu.event_id()) .await .then_some(item) } diff --git a/src/api/client/report.rs b/src/api/client/report.rs index 1019b358..052329d1 100644 --- a/src/api/client/report.rs +++ b/src/api/client/report.rs @@ -260,5 +260,6 @@ async fn delay_response() { "Got successful /report request, waiting {time_to_wait} seconds before sending \ successful response." ); + sleep(Duration::from_secs(time_to_wait)).await; } diff --git a/src/api/client/room/initial_sync.rs b/src/api/client/room/initial_sync.rs index c2f59d4c..2aca5b9d 100644 --- a/src/api/client/room/initial_sync.rs +++ b/src/api/client/room/initial_sync.rs @@ -49,7 +49,9 @@ pub(crate) async fn room_initial_sync_route( .try_collect::>(); let (membership, visibility, state, events) = - try_join4(membership, visibility, state, events).await?; + try_join4(membership, visibility, state, events) + .boxed() + .await?; let messages = PaginationChunk { start: events.last().map(at!(0)).as_ref().map(ToString::to_string), diff --git a/src/api/client/room/summary.rs b/src/api/client/room/summary.rs index ab534765..635f5a8a 100644 --- a/src/api/client/room/summary.rs +++ b/src/api/client/room/summary.rs @@ -112,13 +112,15 @@ async fn local_room_summary_response( ) -> Result { trace!(?sender_user, "Sending local room summary response for {room_id:?}"); let join_rule = services.rooms.state_accessor.get_join_rules(room_id); + let world_readable = services.rooms.state_accessor.is_world_readable(room_id); + let guest_can_join = services.rooms.state_accessor.guest_can_join(room_id); let (join_rule, world_readable, guest_can_join) = join3(join_rule, world_readable, guest_can_join).await; - trace!("{join_rule:?}, {world_readable:?}, {guest_can_join:?}"); + trace!("{join_rule:?}, {world_readable:?}, {guest_can_join:?}"); user_can_see_summary( services, room_id, diff --git a/src/api/client/room/upgrade.rs b/src/api/client/room/upgrade.rs index d8f5ea83..ae632235 100644 --- a/src/api/client/room/upgrade.rs +++ b/src/api/client/room/upgrade.rs @@ -2,7 +2,7 @@ use std::cmp::max; use axum::extract::State; use conduwuit::{ - Err, Error, Result, err, info, + Err, Error, Event, Result, err, info, matrix::{StateKey, pdu::PduBuilder}, }; use futures::StreamExt; @@ -215,7 +215,7 @@ pub(crate) async fn upgrade_room_route( .room_state_get(&body.room_id, event_type, "") .await { - | Ok(v) => v.content.clone(), + | Ok(v) => v.content().to_owned(), | Err(_) => continue, // Skipping missing events. }; diff --git a/src/api/client/sync/v4.rs b/src/api/client/sync/v4.rs index cabd67e4..14cd50d8 100644 --- a/src/api/client/sync/v4.rs +++ b/src/api/client/sync/v4.rs @@ -6,7 +6,7 @@ use std::{ use axum::extract::State; use conduwuit::{ - Err, Error, Event, PduCount, PduEvent, Result, at, debug, error, extract_variant, + Err, Error, Event, PduCount, Result, at, debug, error, extract_variant, matrix::TypeStateKey, utils::{ BoolExt, IterStream, ReadyExt, TryFutureExtExt, @@ -627,7 +627,7 @@ pub(crate) async fn sync_events_v4_route( .state_accessor .room_state_get(room_id, &state.0, &state.1) .await - .map(PduEvent::into_format) + .map(Event::into_format) .ok() }) .collect() diff --git a/src/api/server/invite.rs b/src/api/server/invite.rs index 0d26d787..0a9b2e10 100644 --- a/src/api/server/invite.rs +++ b/src/api/server/invite.rs @@ -2,8 +2,10 @@ use axum::extract::State; use axum_client_ip::InsecureClientIp; use base64::{Engine as _, engine::general_purpose}; use conduwuit::{ - Err, Error, PduEvent, Result, err, matrix::Event, pdu::gen_event_id, utils, - utils::hash::sha256, warn, + Err, Error, PduEvent, Result, err, + matrix::{Event, event::gen_event_id}, + utils::{self, hash::sha256}, + warn, }; use ruma::{ CanonicalJsonValue, OwnedUserId, UserId, diff --git a/src/api/server/send_join.rs b/src/api/server/send_join.rs index 895eca81..652451c7 100644 --- a/src/api/server/send_join.rs +++ b/src/api/server/send_join.rs @@ -5,7 +5,7 @@ use std::borrow::Borrow; use axum::extract::State; use conduwuit::{ Err, Result, at, err, - pdu::gen_event_id_canonical_json, + matrix::event::gen_event_id_canonical_json, utils::stream::{IterStream, TryBroadbandExt}, warn, }; diff --git a/src/api/server/send_knock.rs b/src/api/server/send_knock.rs index 8d3697d2..ffd41ada 100644 --- a/src/api/server/send_knock.rs +++ b/src/api/server/send_knock.rs @@ -1,7 +1,7 @@ use axum::extract::State; use conduwuit::{ Err, Result, err, - matrix::pdu::{PduEvent, gen_event_id_canonical_json}, + matrix::{event::gen_event_id_canonical_json, pdu::PduEvent}, warn, }; use futures::FutureExt; diff --git a/src/api/server/send_leave.rs b/src/api/server/send_leave.rs index d3dc994c..b6336e1a 100644 --- a/src/api/server/send_leave.rs +++ b/src/api/server/send_leave.rs @@ -1,7 +1,7 @@ #![allow(deprecated)] use axum::extract::State; -use conduwuit::{Err, Result, err, matrix::pdu::gen_event_id_canonical_json}; +use conduwuit::{Err, Result, err, matrix::event::gen_event_id_canonical_json}; use conduwuit_service::Services; use futures::FutureExt; use ruma::{ diff --git a/src/core/config/proxy.rs b/src/core/config/proxy.rs index ea388f24..77c4531a 100644 --- a/src/core/config/proxy.rs +++ b/src/core/config/proxy.rs @@ -88,10 +88,7 @@ impl PartialProxyConfig { } } match (included_because, excluded_because) { - | (Some(a), Some(b)) if a.more_specific_than(b) => Some(&self.url), /* included for - * a more specific - * reason */ - // than excluded + | (Some(a), Some(b)) if a.more_specific_than(b) => Some(&self.url), | (Some(_), None) => Some(&self.url), | _ => None, } diff --git a/src/core/info/cargo.rs b/src/core/info/cargo.rs index e70bdcd5..61a97508 100644 --- a/src/core/info/cargo.rs +++ b/src/core/info/cargo.rs @@ -84,10 +84,12 @@ fn append_features(features: &mut Vec, manifest: &str) -> Result<()> { fn init_dependencies() -> Result { let manifest = Manifest::from_str(WORKSPACE_MANIFEST)?; - Ok(manifest + let deps_set = manifest .workspace .as_ref() .expect("manifest has workspace section") .dependencies - .clone()) + .clone(); + + Ok(deps_set) } diff --git a/src/core/matrix/event.rs b/src/core/matrix/event.rs index 5b12770b..a1d1339e 100644 --- a/src/core/matrix/event.rs +++ b/src/core/matrix/event.rs @@ -1,21 +1,27 @@ mod content; +mod filter; mod format; +mod id; mod redact; +mod relation; mod type_ext; +mod unsigned; + +use std::fmt::Debug; use ruma::{ - EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, RoomVersionId, UserId, - events::TimelineEventType, + CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, + RoomVersionId, UserId, events::TimelineEventType, }; use serde::Deserialize; use serde_json::{Value as JsonValue, value::RawValue as RawJsonValue}; -pub use self::type_ext::TypeExt; -use super::state_key::StateKey; -use crate::Result; +pub use self::{filter::Matches, id::*, relation::RelationTypeEqual, type_ext::TypeExt}; +use super::{pdu::Pdu, state_key::StateKey}; +use crate::{Result, utils}; /// Abstraction of a PDU so users can have their own PDU types. -pub trait Event { +pub trait Event: Clone + Debug { /// Serialize into a Ruma JSON format, consuming. #[inline] fn into_format(self) -> T @@ -36,6 +42,41 @@ pub trait Event { format::Ref(self).into() } + #[inline] + fn contains_unsigned_property(&self, property: &str, is_type: T) -> bool + where + T: FnOnce(&JsonValue) -> bool, + Self: Sized, + { + unsigned::contains_unsigned_property::(self, property, is_type) + } + + #[inline] + fn get_unsigned_property(&self, property: &str) -> Result + where + T: for<'de> Deserialize<'de>, + Self: Sized, + { + unsigned::get_unsigned_property::(self, property) + } + + #[inline] + fn get_unsigned_as_value(&self) -> JsonValue + where + Self: Sized, + { + unsigned::get_unsigned_as_value(self) + } + + #[inline] + fn get_unsigned(&self) -> Result + where + T: for<'de> Deserialize<'de>, + Self: Sized, + { + unsigned::get_unsigned::(self) + } + #[inline] fn get_content_as_value(&self) -> JsonValue where @@ -69,6 +110,39 @@ pub trait Event { redact::is_redacted(self) } + #[inline] + fn into_canonical_object(self) -> CanonicalJsonObject + where + Self: Sized, + { + utils::to_canonical_object(self.into_pdu()).expect("failed to create Value::Object") + } + + #[inline] + fn to_canonical_object(&self) -> CanonicalJsonObject { + utils::to_canonical_object(self.as_pdu()).expect("failed to create Value::Object") + } + + #[inline] + fn into_value(self) -> JsonValue + where + Self: Sized, + { + serde_json::to_value(self.into_pdu()).expect("failed to create JSON Value") + } + + #[inline] + fn to_value(&self) -> JsonValue { + serde_json::to_value(self.as_pdu()).expect("failed to create JSON Value") + } + + #[inline] + fn as_mut_pdu(&mut self) -> &mut Pdu { unimplemented!("not a mutable Pdu") } + + fn as_pdu(&self) -> &Pdu; + + fn into_pdu(self) -> Pdu; + fn is_owned(&self) -> bool; // @@ -76,7 +150,7 @@ pub trait Event { // /// All the authenticating events for this event. - fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_; + fn auth_events(&self) -> impl DoubleEndedIterator + Clone + Send + '_; /// The event's content. fn content(&self) -> &RawJsonValue; @@ -88,7 +162,7 @@ pub trait Event { fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch; /// The events before this event. - fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_; + fn prev_events(&self) -> impl DoubleEndedIterator + Clone + Send + '_; /// If this event is a redaction event this is the event it redacts. fn redacts(&self) -> Option<&EventId>; diff --git a/src/core/matrix/event/filter.rs b/src/core/matrix/event/filter.rs new file mode 100644 index 00000000..d3a225b6 --- /dev/null +++ b/src/core/matrix/event/filter.rs @@ -0,0 +1,93 @@ +use ruma::api::client::filter::{RoomEventFilter, UrlFilter}; +use serde_json::Value; + +use super::Event; +use crate::is_equal_to; + +pub trait Matches { + fn matches(&self, event: &E) -> bool; +} + +impl Matches for &RoomEventFilter { + #[inline] + fn matches(&self, event: &E) -> bool { + if !matches_sender(event, self) { + return false; + } + + if !matches_room(event, self) { + return false; + } + + if !matches_type(event, self) { + return false; + } + + if !matches_url(event, self) { + return false; + } + + true + } +} + +fn matches_room(event: &E, filter: &RoomEventFilter) -> bool { + if filter.not_rooms.iter().any(is_equal_to!(event.room_id())) { + return false; + } + + if let Some(rooms) = filter.rooms.as_ref() { + if !rooms.iter().any(is_equal_to!(event.room_id())) { + return false; + } + } + + true +} + +fn matches_sender(event: &E, filter: &RoomEventFilter) -> bool { + if filter.not_senders.iter().any(is_equal_to!(event.sender())) { + return false; + } + + if let Some(senders) = filter.senders.as_ref() { + if !senders.iter().any(is_equal_to!(event.sender())) { + return false; + } + } + + true +} + +fn matches_type(event: &E, filter: &RoomEventFilter) -> bool { + let kind = event.kind().to_cow_str(); + + if filter.not_types.iter().any(is_equal_to!(&kind)) { + return false; + } + + if let Some(types) = filter.types.as_ref() { + if !types.iter().any(is_equal_to!(&kind)) { + return false; + } + } + + true +} + +fn matches_url(event: &E, filter: &RoomEventFilter) -> bool { + let Some(url_filter) = filter.url_filter.as_ref() else { + return true; + }; + + //TODO: might be better to use Ruma's Raw rather than serde here + let url = event + .get_content_as_value() + .get("url") + .is_some_and(Value::is_string); + + match url_filter { + | UrlFilter::EventsWithUrl => url, + | UrlFilter::EventsWithoutUrl => !url, + } +} diff --git a/src/core/matrix/pdu/event_id.rs b/src/core/matrix/event/id.rs similarity index 100% rename from src/core/matrix/pdu/event_id.rs rename to src/core/matrix/event/id.rs diff --git a/src/core/matrix/event/relation.rs b/src/core/matrix/event/relation.rs new file mode 100644 index 00000000..58324e86 --- /dev/null +++ b/src/core/matrix/event/relation.rs @@ -0,0 +1,28 @@ +use ruma::events::relation::RelationType; +use serde::Deserialize; + +use super::Event; + +pub trait RelationTypeEqual { + fn relation_type_equal(&self, event: &E) -> bool; +} + +#[derive(Clone, Debug, Deserialize)] +struct ExtractRelatesToEventId { + #[serde(rename = "m.relates_to")] + relates_to: ExtractRelType, +} + +#[derive(Clone, Debug, Deserialize)] +struct ExtractRelType { + rel_type: RelationType, +} + +impl RelationTypeEqual for RelationType { + fn relation_type_equal(&self, event: &E) -> bool { + event + .get_content() + .map(|c: ExtractRelatesToEventId| c.relates_to.rel_type) + .is_ok_and(|r| r == *self) + } +} diff --git a/src/core/matrix/event/unsigned.rs b/src/core/matrix/event/unsigned.rs new file mode 100644 index 00000000..42928af4 --- /dev/null +++ b/src/core/matrix/event/unsigned.rs @@ -0,0 +1,51 @@ +use serde::Deserialize; +use serde_json::value::Value as JsonValue; + +use super::Event; +use crate::{Result, err, is_true}; + +pub(super) fn contains_unsigned_property(event: &E, property: &str, is_type: F) -> bool +where + F: FnOnce(&JsonValue) -> bool, + E: Event, +{ + get_unsigned_as_value(event) + .get(property) + .map(is_type) + .is_some_and(is_true!()) +} + +pub(super) fn get_unsigned_property(event: &E, property: &str) -> Result +where + T: for<'de> Deserialize<'de>, + E: Event, +{ + get_unsigned_as_value(event) + .get_mut(property) + .map(JsonValue::take) + .map(serde_json::from_value) + .ok_or(err!(Request(NotFound("property not found in unsigned object"))))? + .map_err(|e| err!(Database("Failed to deserialize unsigned.{property} into type: {e}"))) +} + +#[must_use] +pub(super) fn get_unsigned_as_value(event: &E) -> JsonValue +where + E: Event, +{ + get_unsigned::(event).unwrap_or_default() +} + +pub(super) fn get_unsigned(event: &E) -> Result +where + T: for<'de> Deserialize<'de>, + E: Event, +{ + event + .unsigned() + .as_ref() + .map(|raw| raw.get()) + .map(serde_json::from_str) + .ok_or(err!(Request(NotFound("\"unsigned\" property not found in pdu"))))? + .map_err(|e| err!(Database("Failed to deserialize \"unsigned\" into value: {e}"))) +} diff --git a/src/core/matrix/pdu.rs b/src/core/matrix/pdu.rs index e64baeb8..bff0c203 100644 --- a/src/core/matrix/pdu.rs +++ b/src/core/matrix/pdu.rs @@ -1,12 +1,8 @@ mod builder; -mod content; mod count; -mod event_id; -mod filter; mod id; mod raw_id; mod redact; -mod relation; #[cfg(test)] mod tests; mod unsigned; @@ -24,7 +20,6 @@ pub use self::{ Count as PduCount, Id as PduId, Pdu as PduEvent, RawId as RawPduId, builder::{Builder, Builder as PduBuilder}, count::Count, - event_id::*, id::{ShortId, *}, raw_id::*, }; @@ -91,7 +86,7 @@ impl Pdu { impl Event for Pdu { #[inline] - fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_ { + fn auth_events(&self) -> impl DoubleEndedIterator + Clone + Send + '_ { self.auth_events.iter().map(AsRef::as_ref) } @@ -107,7 +102,7 @@ impl Event for Pdu { } #[inline] - fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_ { + fn prev_events(&self) -> impl DoubleEndedIterator + Clone + Send + '_ { self.prev_events.iter().map(AsRef::as_ref) } @@ -129,13 +124,22 @@ impl Event for Pdu { #[inline] fn unsigned(&self) -> Option<&RawJsonValue> { self.unsigned.as_deref() } + #[inline] + fn as_mut_pdu(&mut self) -> &mut Pdu { self } + + #[inline] + fn as_pdu(&self) -> &Pdu { self } + + #[inline] + fn into_pdu(self) -> Pdu { self } + #[inline] fn is_owned(&self) -> bool { true } } impl Event for &Pdu { #[inline] - fn auth_events(&self) -> impl DoubleEndedIterator + Send + '_ { + fn auth_events(&self) -> impl DoubleEndedIterator + Clone + Send + '_ { self.auth_events.iter().map(AsRef::as_ref) } @@ -151,7 +155,7 @@ impl Event for &Pdu { } #[inline] - fn prev_events(&self) -> impl DoubleEndedIterator + Send + '_ { + fn prev_events(&self) -> impl DoubleEndedIterator + Clone + Send + '_ { self.prev_events.iter().map(AsRef::as_ref) } @@ -173,6 +177,12 @@ impl Event for &Pdu { #[inline] fn unsigned(&self) -> Option<&RawJsonValue> { self.unsigned.as_deref() } + #[inline] + fn as_pdu(&self) -> &Pdu { self } + + #[inline] + fn into_pdu(self) -> Pdu { self.clone() } + #[inline] fn is_owned(&self) -> bool { false } } diff --git a/src/core/matrix/pdu/content.rs b/src/core/matrix/pdu/content.rs deleted file mode 100644 index 4e60ce6e..00000000 --- a/src/core/matrix/pdu/content.rs +++ /dev/null @@ -1,20 +0,0 @@ -use serde::Deserialize; -use serde_json::value::Value as JsonValue; - -use crate::{Result, err, implement}; - -#[must_use] -#[implement(super::Pdu)] -pub fn get_content_as_value(&self) -> JsonValue { - self.get_content() - .expect("pdu content must be a valid JSON value") -} - -#[implement(super::Pdu)] -pub fn get_content(&self) -> Result -where - T: for<'de> Deserialize<'de>, -{ - serde_json::from_str(self.content.get()) - .map_err(|e| err!(Database("Failed to deserialize pdu content into type: {e}"))) -} diff --git a/src/core/matrix/pdu/filter.rs b/src/core/matrix/pdu/filter.rs deleted file mode 100644 index aabf13db..00000000 --- a/src/core/matrix/pdu/filter.rs +++ /dev/null @@ -1,90 +0,0 @@ -use ruma::api::client::filter::{RoomEventFilter, UrlFilter}; -use serde_json::Value; - -use crate::{implement, is_equal_to}; - -#[implement(super::Pdu)] -#[must_use] -pub fn matches(&self, filter: &RoomEventFilter) -> bool { - if !self.matches_sender(filter) { - return false; - } - - if !self.matches_room(filter) { - return false; - } - - if !self.matches_type(filter) { - return false; - } - - if !self.matches_url(filter) { - return false; - } - - true -} - -#[implement(super::Pdu)] -fn matches_room(&self, filter: &RoomEventFilter) -> bool { - if filter.not_rooms.contains(&self.room_id) { - return false; - } - - if let Some(rooms) = filter.rooms.as_ref() { - if !rooms.contains(&self.room_id) { - return false; - } - } - - true -} - -#[implement(super::Pdu)] -fn matches_sender(&self, filter: &RoomEventFilter) -> bool { - if filter.not_senders.contains(&self.sender) { - return false; - } - - if let Some(senders) = filter.senders.as_ref() { - if !senders.contains(&self.sender) { - return false; - } - } - - true -} - -#[implement(super::Pdu)] -fn matches_type(&self, filter: &RoomEventFilter) -> bool { - let event_type = &self.kind.to_cow_str(); - if filter.not_types.iter().any(is_equal_to!(event_type)) { - return false; - } - - if let Some(types) = filter.types.as_ref() { - if !types.iter().any(is_equal_to!(event_type)) { - return false; - } - } - - true -} - -#[implement(super::Pdu)] -fn matches_url(&self, filter: &RoomEventFilter) -> bool { - let Some(url_filter) = filter.url_filter.as_ref() else { - return true; - }; - - //TODO: might be better to use Ruma's Raw rather than serde here - let url = serde_json::from_str::(self.content.get()) - .expect("parsing content JSON failed") - .get("url") - .is_some_and(Value::is_string); - - match url_filter { - | UrlFilter::EventsWithUrl => url, - | UrlFilter::EventsWithoutUrl => !url, - } -} diff --git a/src/core/matrix/pdu/redact.rs b/src/core/matrix/pdu/redact.rs index e6a03209..896e03f8 100644 --- a/src/core/matrix/pdu/redact.rs +++ b/src/core/matrix/pdu/redact.rs @@ -1,10 +1,10 @@ use ruma::{RoomVersionId, canonical_json::redact_content_in_place}; -use serde_json::{json, value::to_raw_value}; +use serde_json::{Value as JsonValue, json, value::to_raw_value}; use crate::{Error, Result, err, implement}; #[implement(super::Pdu)] -pub fn redact(&mut self, room_version_id: &RoomVersionId, reason: &Self) -> Result { +pub fn redact(&mut self, room_version_id: &RoomVersionId, reason: JsonValue) -> Result { self.unsigned = None; let mut content = serde_json::from_str(self.content.get()) diff --git a/src/core/matrix/pdu/relation.rs b/src/core/matrix/pdu/relation.rs deleted file mode 100644 index 2968171e..00000000 --- a/src/core/matrix/pdu/relation.rs +++ /dev/null @@ -1,22 +0,0 @@ -use ruma::events::relation::RelationType; -use serde::Deserialize; - -use crate::implement; - -#[derive(Clone, Debug, Deserialize)] -struct ExtractRelType { - rel_type: RelationType, -} -#[derive(Clone, Debug, Deserialize)] -struct ExtractRelatesToEventId { - #[serde(rename = "m.relates_to")] - relates_to: ExtractRelType, -} - -#[implement(super::Pdu)] -#[must_use] -pub fn relation_type_equal(&self, rel_type: &RelationType) -> bool { - self.get_content() - .map(|c: ExtractRelatesToEventId| c.relates_to.rel_type) - .is_ok_and(|r| r == *rel_type) -} diff --git a/src/core/matrix/pdu/unsigned.rs b/src/core/matrix/pdu/unsigned.rs index 23897519..0c58bb68 100644 --- a/src/core/matrix/pdu/unsigned.rs +++ b/src/core/matrix/pdu/unsigned.rs @@ -1,11 +1,10 @@ use std::collections::BTreeMap; use ruma::MilliSecondsSinceUnixEpoch; -use serde::Deserialize; use serde_json::value::{RawValue as RawJsonValue, Value as JsonValue, to_raw_value}; use super::Pdu; -use crate::{Result, err, implement, is_true}; +use crate::{Result, err, implement}; #[implement(Pdu)] pub fn remove_transaction_id(&mut self) -> Result { @@ -74,43 +73,3 @@ pub fn add_relation(&mut self, name: &str, pdu: Option<&Pdu>) -> Result { Ok(()) } - -#[implement(Pdu)] -pub fn contains_unsigned_property(&self, property: &str, is_type: F) -> bool -where - F: FnOnce(&JsonValue) -> bool, -{ - self.get_unsigned_as_value() - .get(property) - .map(is_type) - .is_some_and(is_true!()) -} - -#[implement(Pdu)] -pub fn get_unsigned_property(&self, property: &str) -> Result -where - T: for<'de> Deserialize<'de>, -{ - self.get_unsigned_as_value() - .get_mut(property) - .map(JsonValue::take) - .map(serde_json::from_value) - .ok_or(err!(Request(NotFound("property not found in unsigned object"))))? - .map_err(|e| err!(Database("Failed to deserialize unsigned.{property} into type: {e}"))) -} - -#[implement(Pdu)] -#[must_use] -pub fn get_unsigned_as_value(&self) -> JsonValue { - self.get_unsigned::().unwrap_or_default() -} - -#[implement(Pdu)] -pub fn get_unsigned(&self) -> Result { - self.unsigned - .as_ref() - .map(|raw| raw.get()) - .map(serde_json::from_str) - .ok_or(err!(Request(NotFound("\"unsigned\" property not found in pdu"))))? - .map_err(|e| err!(Database("Failed to deserialize \"unsigned\" into value: {e}"))) -} diff --git a/src/core/matrix/state_res/mod.rs b/src/core/matrix/state_res/mod.rs index ed5aa034..ce9d9276 100644 --- a/src/core/matrix/state_res/mod.rs +++ b/src/core/matrix/state_res/mod.rs @@ -74,7 +74,7 @@ type Result = crate::Result; /// event is part of the same room. //#[tracing::instrument(level = "debug", skip(state_sets, auth_chain_sets, //#[tracing::instrument(level event_fetch))] -pub async fn resolve<'a, E, Sets, SetIter, Hasher, Fetch, FetchFut, Exists, ExistsFut>( +pub async fn resolve<'a, Pdu, Sets, SetIter, Hasher, Fetch, FetchFut, Exists, ExistsFut>( room_version: &RoomVersionId, state_sets: Sets, auth_chain_sets: &'a [HashSet], @@ -83,14 +83,14 @@ pub async fn resolve<'a, E, Sets, SetIter, Hasher, Fetch, FetchFut, Exists, Exis ) -> Result> where Fetch: Fn(OwnedEventId) -> FetchFut + Sync, - FetchFut: Future> + Send, + FetchFut: Future> + Send, Exists: Fn(OwnedEventId) -> ExistsFut + Sync, ExistsFut: Future + Send, Sets: IntoIterator + Send, SetIter: Iterator> + Clone + Send, Hasher: BuildHasher + Send + Sync, - E: Event + Clone + Send + Sync, - for<'b> &'b E: Event + Send, + Pdu: Event + Clone + Send + Sync, + for<'b> &'b Pdu: Event + Send, { debug!("State resolution starting"); @@ -221,6 +221,7 @@ where let state_sets_iter = state_sets_iter.inspect(|_| state_set_count = state_set_count.saturating_add(1)); + for (k, v) in state_sets_iter.flatten() { occurrences .entry(k) @@ -305,6 +306,7 @@ where let pl = get_power_level_for_sender(&event_id, fetch_event) .await .ok()?; + Some((event_id, pl)) }) .inspect(|(event_id, pl)| { diff --git a/src/core/mods/module.rs b/src/core/mods/module.rs index b65bbca2..bcadf5aa 100644 --- a/src/core/mods/module.rs +++ b/src/core/mods/module.rs @@ -44,6 +44,7 @@ impl Module { .handle .as_ref() .expect("backing library loaded by this instance"); + // SAFETY: Calls dlsym(3) on unix platforms. This might not have to be unsafe // if wrapped in libloading with_dlerror(). let sym = unsafe { handle.get::(cname.as_bytes()) }; diff --git a/src/core/mods/path.rs b/src/core/mods/path.rs index cde251b3..b792890b 100644 --- a/src/core/mods/path.rs +++ b/src/core/mods/path.rs @@ -27,6 +27,7 @@ pub fn to_name(path: &OsStr) -> Result { .expect("path file stem") .to_str() .expect("name string"); + let name = name.strip_prefix("lib").unwrap_or(name).to_owned(); Ok(name) diff --git a/src/core/utils/html.rs b/src/core/utils/html.rs index f2b6d861..eac4c47f 100644 --- a/src/core/utils/html.rs +++ b/src/core/utils/html.rs @@ -23,8 +23,10 @@ impl fmt::Display for Escape<'_> { | '"' => """, | _ => continue, }; + fmt.write_str(&pile_o_bits[last..i])?; fmt.write_str(s)?; + // NOTE: we only expect single byte characters here - which is fine as long as // we only match single byte characters last = i.saturating_add(1); diff --git a/src/core/utils/json.rs b/src/core/utils/json.rs index 3f2f225e..df4ccd13 100644 --- a/src/core/utils/json.rs +++ b/src/core/utils/json.rs @@ -1,4 +1,4 @@ -use std::{fmt, str::FromStr}; +use std::{fmt, marker::PhantomData, str::FromStr}; use ruma::{CanonicalJsonError, CanonicalJsonObject, canonical_json::try_from_json_map}; @@ -11,25 +11,28 @@ use crate::Result; pub fn to_canonical_object( value: T, ) -> Result { + use CanonicalJsonError::SerDe; use serde::ser::Error; - match serde_json::to_value(value).map_err(CanonicalJsonError::SerDe)? { + match serde_json::to_value(value).map_err(SerDe)? { | serde_json::Value::Object(map) => try_from_json_map(map), - | _ => - Err(CanonicalJsonError::SerDe(serde_json::Error::custom("Value must be an object"))), + | _ => Err(SerDe(serde_json::Error::custom("Value must be an object"))), } } -pub fn deserialize_from_str< - 'de, +pub fn deserialize_from_str<'de, D, T, E>(deserializer: D) -> Result +where D: serde::de::Deserializer<'de>, T: FromStr, E: fmt::Display, ->( - deserializer: D, -) -> Result { - struct Visitor, E>(std::marker::PhantomData); - impl, Err: fmt::Display> serde::de::Visitor<'_> for Visitor { +{ + struct Visitor, E>(PhantomData); + + impl serde::de::Visitor<'_> for Visitor + where + T: FromStr, + Err: fmt::Display, + { type Value = T; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -43,5 +46,6 @@ pub fn deserialize_from_str< v.parse().map_err(serde::de::Error::custom) } } - deserializer.deserialize_str(Visitor(std::marker::PhantomData)) + + deserializer.deserialize_str(Visitor(PhantomData)) } diff --git a/src/core/utils/time.rs b/src/core/utils/time.rs index 73f73971..394e08cb 100644 --- a/src/core/utils/time.rs +++ b/src/core/utils/time.rs @@ -105,14 +105,11 @@ pub fn whole_unit(d: Duration) -> Unit { | 86_400.. => Days(d.as_secs() / 86_400), | 3_600..=86_399 => Hours(d.as_secs() / 3_600), | 60..=3_599 => Mins(d.as_secs() / 60), - | _ => match d.as_micros() { | 1_000_000.. => Secs(d.as_secs()), | 1_000..=999_999 => Millis(d.subsec_millis().into()), - | _ => match d.as_nanos() { | 1_000.. => Micros(d.subsec_micros().into()), - | _ => Nanos(d.subsec_nanos().into()), }, }, diff --git a/src/database/watchers.rs b/src/database/watchers.rs index b3907833..efb939d7 100644 --- a/src/database/watchers.rs +++ b/src/database/watchers.rs @@ -37,7 +37,6 @@ impl Watchers { pub(crate) fn wake(&self, key: &[u8]) { let watchers = self.watchers.read().unwrap(); let mut triggered = Vec::new(); - for length in 0..=key.len() { if watchers.contains_key(&key[..length]) { triggered.push(&key[..length]); diff --git a/src/main/logging.rs b/src/main/logging.rs index aec50bd4..36a8896c 100644 --- a/src/main/logging.rs +++ b/src/main/logging.rs @@ -22,10 +22,12 @@ pub(crate) fn init( let reload_handles = LogLevelReloadHandles::default(); let console_span_events = fmt_span::from_str(&config.log_span_events).unwrap_or_err(); + let console_filter = EnvFilter::builder() .with_regex(config.log_filter_regex) .parse(&config.log) .map_err(|e| err!(Config("log", "{e}.")))?; + let console_layer = fmt::Layer::new() .with_span_events(console_span_events) .event_format(ConsoleFormat::new(config)) @@ -34,6 +36,7 @@ pub(crate) fn init( let (console_reload_filter, console_reload_handle) = reload::Layer::new(console_filter.clone()); + reload_handles.add("console", Box::new(console_reload_handle)); let cap_state = Arc::new(capture::State::new()); @@ -47,8 +50,10 @@ pub(crate) fn init( let subscriber = { let sentry_filter = EnvFilter::try_new(&config.sentry_filter) .map_err(|e| err!(Config("sentry_filter", "{e}.")))?; + let sentry_layer = sentry_tracing::layer(); let (sentry_reload_filter, sentry_reload_handle) = reload::Layer::new(sentry_filter); + reload_handles.add("sentry", Box::new(sentry_reload_handle)); subscriber.with(sentry_layer.with_filter(sentry_reload_filter)) }; @@ -58,12 +63,15 @@ pub(crate) fn init( let (flame_layer, flame_guard) = if config.tracing_flame { let flame_filter = EnvFilter::try_new(&config.tracing_flame_filter) .map_err(|e| err!(Config("tracing_flame_filter", "{e}.")))?; + let (flame_layer, flame_guard) = tracing_flame::FlameLayer::with_file(&config.tracing_flame_output_path) .map_err(|e| err!(Config("tracing_flame_output_path", "{e}.")))?; + let flame_layer = flame_layer .with_empty_samples(false) .with_filter(flame_filter); + (Some(flame_layer), Some(flame_guard)) } else { (None, None) @@ -71,19 +79,24 @@ pub(crate) fn init( let jaeger_filter = EnvFilter::try_new(&config.jaeger_filter) .map_err(|e| err!(Config("jaeger_filter", "{e}.")))?; + let jaeger_layer = config.allow_jaeger.then(|| { opentelemetry::global::set_text_map_propagator( opentelemetry_jaeger::Propagator::new(), ); + let tracer = opentelemetry_jaeger::new_agent_pipeline() .with_auto_split_batch(true) .with_service_name(conduwuit_core::name()) .install_batch(opentelemetry_sdk::runtime::Tokio) .expect("jaeger agent pipeline"); + let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); + let (jaeger_reload_filter, jaeger_reload_handle) = reload::Layer::new(jaeger_filter.clone()); reload_handles.add("jaeger", Box::new(jaeger_reload_handle)); + Some(telemetry.with_filter(jaeger_reload_filter)) }); diff --git a/src/main/mods.rs b/src/main/mods.rs index d585a381..6140cc6e 100644 --- a/src/main/mods.rs +++ b/src/main/mods.rs @@ -51,7 +51,9 @@ pub(crate) async fn run(server: &Arc, starts: bool) -> Result<(bool, boo }, }; } + server.server.stopping.store(false, Ordering::Release); + let run = main_mod.get::("run")?; if let Err(error) = run(server .services @@ -64,7 +66,9 @@ pub(crate) async fn run(server: &Arc, starts: bool) -> Result<(bool, boo error!("Running server: {error}"); return Err(error); } + let reloads = server.server.reloading.swap(false, Ordering::AcqRel); + let stops = !reloads || stale(server).await? <= restart_thresh(); let starts = reloads && stops; if stops { diff --git a/src/main/sentry.rs b/src/main/sentry.rs index 68f12eb7..2a09f415 100644 --- a/src/main/sentry.rs +++ b/src/main/sentry.rs @@ -35,11 +35,13 @@ fn options(config: &Config) -> ClientOptions { .expect("init_sentry should only be called if sentry is enabled and this is not None") .as_str(); + let server_name = config + .sentry_send_server_name + .then(|| config.server_name.to_string().into()); + ClientOptions { dsn: Some(Dsn::from_str(dsn).expect("sentry_endpoint must be a valid URL")), - server_name: config - .sentry_send_server_name - .then(|| config.server_name.to_string().into()), + server_name, traces_sample_rate: config.sentry_traces_sample_rate, debug: cfg!(debug_assertions), release: sentry::release_name!(), diff --git a/src/router/request.rs b/src/router/request.rs index dba90324..3bbeae03 100644 --- a/src/router/request.rs +++ b/src/router/request.rs @@ -98,8 +98,8 @@ async fn execute( fn handle_result(method: &Method, uri: &Uri, result: Response) -> Result { let status = result.status(); - let reason = status.canonical_reason().unwrap_or("Unknown Reason"); let code = status.as_u16(); + let reason = status.canonical_reason().unwrap_or("Unknown Reason"); if status.is_server_error() { error!(method = ?method, uri = ?uri, "{code} {reason}"); diff --git a/src/service/admin/mod.rs b/src/service/admin/mod.rs index 66c373ec..d971ce95 100644 --- a/src/service/admin/mod.rs +++ b/src/service/admin/mod.rs @@ -305,13 +305,13 @@ impl Service { return Ok(()); }; - let response_sender = if self.is_admin_room(&pdu.room_id).await { + let response_sender = if self.is_admin_room(pdu.room_id()).await { &self.services.globals.server_user } else { - &pdu.sender + pdu.sender() }; - self.respond_to_room(content, &pdu.room_id, response_sender) + self.respond_to_room(content, pdu.room_id(), response_sender) .boxed() .await } diff --git a/src/service/pusher/mod.rs b/src/service/pusher/mod.rs index 192ef447..baa7a72e 100644 --- a/src/service/pusher/mod.rs +++ b/src/service/pusher/mod.rs @@ -293,11 +293,7 @@ impl Service { .state_accessor .room_state_get(event.room_id(), &StateEventType::RoomPowerLevels, "") .await - .and_then(|ev| { - serde_json::from_str(ev.content.get()).map_err(|e| { - err!(Database(error!("invalid m.room.power_levels event: {e:?}"))) - }) - }) + .and_then(|event| event.get_content()) .unwrap_or_default(); let serialized = event.to_format(); diff --git a/src/service/rooms/alias/mod.rs b/src/service/rooms/alias/mod.rs index 866e45a9..7675efd4 100644 --- a/src/service/rooms/alias/mod.rs +++ b/src/service/rooms/alias/mod.rs @@ -3,7 +3,7 @@ mod remote; use std::sync::Arc; use conduwuit::{ - Err, Result, Server, err, + Err, Event, Result, Server, err, utils::{ReadyExt, stream::TryIgnore}, }; use database::{Deserialized, Ignore, Interfix, Map}; @@ -241,7 +241,7 @@ impl Service { .room_state_get(&room_id, &StateEventType::RoomCreate, "") .await { - return Ok(event.sender == user_id); + return Ok(event.sender() == user_id); } Err!(Database("Room has no m.room.create event")) diff --git a/src/service/rooms/event_handler/fetch_and_handle_outliers.rs b/src/service/rooms/event_handler/fetch_and_handle_outliers.rs index b0a7d827..44027e04 100644 --- a/src/service/rooms/event_handler/fetch_and_handle_outliers.rs +++ b/src/service/rooms/event_handler/fetch_and_handle_outliers.rs @@ -4,11 +4,13 @@ use std::{ }; use conduwuit::{ - PduEvent, debug, debug_error, debug_warn, implement, pdu, trace, - utils::continue_exponential_backoff_secs, warn, + Event, PduEvent, debug, debug_error, debug_warn, implement, + matrix::event::gen_event_id_canonical_json, trace, utils::continue_exponential_backoff_secs, + warn, }; use ruma::{ - CanonicalJsonValue, OwnedEventId, RoomId, ServerName, api::federation::event::get_event, + CanonicalJsonValue, EventId, OwnedEventId, RoomId, ServerName, + api::federation::event::get_event, }; use super::get_room_version_id; @@ -23,13 +25,17 @@ use super::get_room_version_id; /// c. Ask origin server over federation /// d. TODO: Ask other servers over federation? #[implement(super::Service)] -pub(super) async fn fetch_and_handle_outliers<'a>( +pub(super) async fn fetch_and_handle_outliers<'a, Pdu, Events>( &self, origin: &'a ServerName, - events: &'a [OwnedEventId], - create_event: &'a PduEvent, + events: Events, + create_event: &'a Pdu, room_id: &'a RoomId, -) -> Vec<(PduEvent, Option>)> { +) -> Vec<(PduEvent, Option>)> +where + Pdu: Event + Send + Sync, + Events: Iterator + Clone + Send, +{ let back_off = |id| match self .services .globals @@ -46,22 +52,23 @@ pub(super) async fn fetch_and_handle_outliers<'a>( }, }; - let mut events_with_auth_events = Vec::with_capacity(events.len()); + let mut events_with_auth_events = Vec::with_capacity(events.clone().count()); + for id in events { // a. Look in the main timeline (pduid_pdu tree) // b. Look at outlier pdu tree // (get_pdu_json checks both) if let Ok(local_pdu) = self.services.timeline.get_pdu(id).await { - trace!("Found {id} in db"); - events_with_auth_events.push((id, Some(local_pdu), vec![])); + events_with_auth_events.push((id.to_owned(), Some(local_pdu), vec![])); continue; } // c. Ask origin server over federation // We also handle its auth chain here so we don't get a stack overflow in // handle_outlier_pdu. - let mut todo_auth_events: VecDeque<_> = [id.clone()].into(); + let mut todo_auth_events: VecDeque<_> = [id.to_owned()].into(); let mut events_in_reverse_order = Vec::with_capacity(todo_auth_events.len()); + let mut events_all = HashSet::with_capacity(todo_auth_events.len()); while let Some(next_id) = todo_auth_events.pop_front() { if let Some((time, tries)) = self @@ -117,7 +124,7 @@ pub(super) async fn fetch_and_handle_outliers<'a>( }; let Ok((calculated_event_id, value)) = - pdu::gen_event_id_canonical_json(&res.pdu, &room_version_id) + gen_event_id_canonical_json(&res.pdu, &room_version_id) else { back_off((*next_id).to_owned()); continue; @@ -160,7 +167,8 @@ pub(super) async fn fetch_and_handle_outliers<'a>( }, } } - events_with_auth_events.push((id, None, events_in_reverse_order)); + + events_with_auth_events.push((id.to_owned(), None, events_in_reverse_order)); } let mut pdus = Vec::with_capacity(events_with_auth_events.len()); @@ -217,5 +225,6 @@ pub(super) async fn fetch_and_handle_outliers<'a>( } } } + pdus } diff --git a/src/service/rooms/event_handler/fetch_prev.rs b/src/service/rooms/event_handler/fetch_prev.rs index 0f92d6e6..efc7a434 100644 --- a/src/service/rooms/event_handler/fetch_prev.rs +++ b/src/service/rooms/event_handler/fetch_prev.rs @@ -1,13 +1,16 @@ -use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; +use std::{ + collections::{BTreeMap, HashMap, HashSet, VecDeque}, + iter::once, +}; use conduwuit::{ - PduEvent, Result, debug_warn, err, implement, + Event, PduEvent, Result, debug_warn, err, implement, state_res::{self}, }; use futures::{FutureExt, future}; use ruma::{ - CanonicalJsonValue, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, ServerName, UInt, int, - uint, + CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, ServerName, + int, uint, }; use super::check_room_id; @@ -19,20 +22,26 @@ use super::check_room_id; fields(%origin), )] #[allow(clippy::type_complexity)] -pub(super) async fn fetch_prev( +pub(super) async fn fetch_prev<'a, Pdu, Events>( &self, origin: &ServerName, - create_event: &PduEvent, + create_event: &Pdu, room_id: &RoomId, - first_ts_in_room: UInt, - initial_set: Vec, + first_ts_in_room: MilliSecondsSinceUnixEpoch, + initial_set: Events, ) -> Result<( Vec, HashMap)>, -)> { - let mut graph: HashMap = HashMap::with_capacity(initial_set.len()); +)> +where + Pdu: Event + Send + Sync, + Events: Iterator + Clone + Send, +{ + let num_ids = initial_set.clone().count(); let mut eventid_info = HashMap::new(); - let mut todo_outlier_stack: VecDeque = initial_set.into(); + let mut graph: HashMap = HashMap::with_capacity(num_ids); + let mut todo_outlier_stack: VecDeque = + initial_set.map(ToOwned::to_owned).collect(); let mut amount = 0; @@ -40,7 +49,12 @@ pub(super) async fn fetch_prev( self.services.server.check_running()?; match self - .fetch_and_handle_outliers(origin, &[prev_event_id.clone()], create_event, room_id) + .fetch_and_handle_outliers( + origin, + once(prev_event_id.as_ref()), + create_event, + room_id, + ) .boxed() .await .pop() @@ -65,17 +79,17 @@ pub(super) async fn fetch_prev( } if let Some(json) = json_opt { - if pdu.origin_server_ts > first_ts_in_room { + if pdu.origin_server_ts() > first_ts_in_room { amount = amount.saturating_add(1); - for prev_prev in &pdu.prev_events { + for prev_prev in pdu.prev_events() { if !graph.contains_key(prev_prev) { - todo_outlier_stack.push_back(prev_prev.clone()); + todo_outlier_stack.push_back(prev_prev.to_owned()); } } graph.insert( prev_event_id.clone(), - pdu.prev_events.iter().cloned().collect(), + pdu.prev_events().map(ToOwned::to_owned).collect(), ); } else { // Time based check failed @@ -98,8 +112,7 @@ pub(super) async fn fetch_prev( let event_fetch = |event_id| { let origin_server_ts = eventid_info .get(&event_id) - .cloned() - .map_or_else(|| uint!(0), |info| info.0.origin_server_ts); + .map_or_else(|| uint!(0), |info| info.0.origin_server_ts().get()); // This return value is the key used for sorting events, // events are then sorted by power level, time, diff --git a/src/service/rooms/event_handler/fetch_state.rs b/src/service/rooms/event_handler/fetch_state.rs index 0f9e093b..d68a3542 100644 --- a/src/service/rooms/event_handler/fetch_state.rs +++ b/src/service/rooms/event_handler/fetch_state.rs @@ -1,6 +1,6 @@ use std::collections::{HashMap, hash_map}; -use conduwuit::{Err, Error, PduEvent, Result, debug, debug_warn, implement}; +use conduwuit::{Err, Event, Result, debug, debug_warn, err, implement}; use futures::FutureExt; use ruma::{ EventId, OwnedEventId, RoomId, ServerName, api::federation::event::get_room_state_ids, @@ -18,13 +18,16 @@ use crate::rooms::short::ShortStateKey; skip_all, fields(%origin), )] -pub(super) async fn fetch_state( +pub(super) async fn fetch_state( &self, origin: &ServerName, - create_event: &PduEvent, + create_event: &Pdu, room_id: &RoomId, event_id: &EventId, -) -> Result>> { +) -> Result>> +where + Pdu: Event + Send + Sync, +{ let res = self .services .sending @@ -36,27 +39,27 @@ pub(super) async fn fetch_state( .inspect_err(|e| debug_warn!("Fetching state for event failed: {e}"))?; debug!("Fetching state events"); + let state_ids = res.pdu_ids.iter().map(AsRef::as_ref); let state_vec = self - .fetch_and_handle_outliers(origin, &res.pdu_ids, create_event, room_id) + .fetch_and_handle_outliers(origin, state_ids, create_event, room_id) .boxed() .await; let mut state: HashMap = HashMap::with_capacity(state_vec.len()); for (pdu, _) in state_vec { let state_key = pdu - .state_key - .clone() - .ok_or_else(|| Error::bad_database("Found non-state pdu in state events."))?; + .state_key() + .ok_or_else(|| err!(Database("Found non-state pdu in state events.")))?; let shortstatekey = self .services .short - .get_or_create_shortstatekey(&pdu.kind.to_string().into(), &state_key) + .get_or_create_shortstatekey(&pdu.kind().to_string().into(), state_key) .await; match state.entry(shortstatekey) { | hash_map::Entry::Vacant(v) => { - v.insert(pdu.event_id.clone()); + v.insert(pdu.event_id().to_owned()); }, | hash_map::Entry::Occupied(_) => { return Err!(Database( @@ -73,7 +76,7 @@ pub(super) async fn fetch_state( .get_shortstatekey(&StateEventType::RoomCreate, "") .await?; - if state.get(&create_shortstatekey) != Some(&create_event.event_id) { + if state.get(&create_shortstatekey).map(AsRef::as_ref) != Some(create_event.event_id()) { return Err!(Database("Incoming event refers to wrong create event.")); } diff --git a/src/service/rooms/event_handler/handle_incoming_pdu.rs b/src/service/rooms/event_handler/handle_incoming_pdu.rs index 77cae41d..86a05e0a 100644 --- a/src/service/rooms/event_handler/handle_incoming_pdu.rs +++ b/src/service/rooms/event_handler/handle_incoming_pdu.rs @@ -4,7 +4,7 @@ use std::{ }; use conduwuit::{ - Err, Result, debug, debug::INFO_SPAN_LEVEL, defer, err, implement, utils::stream::IterStream, + Err, Event, Result, debug::INFO_SPAN_LEVEL, defer, err, implement, utils::stream::IterStream, warn, }; use futures::{ @@ -12,6 +12,7 @@ use futures::{ future::{OptionFuture, try_join5}, }; use ruma::{CanonicalJsonValue, EventId, RoomId, ServerName, UserId, events::StateEventType}; +use tracing::debug; use crate::rooms::timeline::RawPduId; @@ -121,22 +122,16 @@ pub async fn handle_incoming_pdu<'a>( .timeline .first_pdu_in_room(room_id) .await? - .origin_server_ts; + .origin_server_ts(); - if incoming_pdu.origin_server_ts < first_ts_in_room { + if incoming_pdu.origin_server_ts() < first_ts_in_room { return Ok(None); } // 9. Fetch any missing prev events doing all checks listed here starting at 1. // These are timeline events let (sorted_prev_events, mut eventid_info) = self - .fetch_prev( - origin, - create_event, - room_id, - first_ts_in_room, - incoming_pdu.prev_events.clone(), - ) + .fetch_prev(origin, create_event, room_id, first_ts_in_room, incoming_pdu.prev_events()) .await?; debug!( diff --git a/src/service/rooms/event_handler/handle_outlier_pdu.rs b/src/service/rooms/event_handler/handle_outlier_pdu.rs index 5cc6be55..d79eed77 100644 --- a/src/service/rooms/event_handler/handle_outlier_pdu.rs +++ b/src/service/rooms/event_handler/handle_outlier_pdu.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, HashMap, hash_map}; use conduwuit::{ - Err, PduEvent, Result, debug, debug_info, err, implement, state_res, trace, warn, + Err, Event, PduEvent, Result, debug, debug_info, err, implement, state_res, trace, warn, }; use futures::future::ready; use ruma::{ @@ -12,15 +12,18 @@ use super::{check_room_id, get_room_version_id, to_room_version}; #[implement(super::Service)] #[allow(clippy::too_many_arguments)] -pub(super) async fn handle_outlier_pdu<'a>( +pub(super) async fn handle_outlier_pdu<'a, Pdu>( &self, origin: &'a ServerName, - create_event: &'a PduEvent, + create_event: &'a Pdu, event_id: &'a EventId, room_id: &'a RoomId, mut value: CanonicalJsonObject, auth_events_known: bool, -) -> Result<(PduEvent, BTreeMap)> { +) -> Result<(PduEvent, BTreeMap)> +where + Pdu: Event + Send + Sync, +{ // 1. Remove unsigned field value.remove("unsigned"); @@ -29,7 +32,7 @@ pub(super) async fn handle_outlier_pdu<'a>( // 2. Check signatures, otherwise drop // 3. check content hash, redact if doesn't match let room_version_id = get_room_version_id(create_event)?; - let mut val = match self + let mut incoming_pdu = match self .services .server_keys .verify_event(&value, Some(&room_version_id)) @@ -61,13 +64,15 @@ pub(super) async fn handle_outlier_pdu<'a>( // Now that we have checked the signature and hashes we can add the eventID and // convert to our PduEvent type - val.insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.as_str().to_owned())); - let incoming_pdu = serde_json::from_value::( - serde_json::to_value(&val).expect("CanonicalJsonObj is a valid JsonValue"), + incoming_pdu + .insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.as_str().to_owned())); + + let pdu_event = serde_json::from_value::( + serde_json::to_value(&incoming_pdu).expect("CanonicalJsonObj is a valid JsonValue"), ) .map_err(|e| err!(Request(BadJson(debug_warn!("Event is not a valid PDU: {e}")))))?; - check_room_id(room_id, &incoming_pdu)?; + check_room_id(room_id, &pdu_event)?; if !auth_events_known { // 4. fetch any missing auth events doing all checks listed here starting at 1. @@ -78,7 +83,7 @@ pub(super) async fn handle_outlier_pdu<'a>( debug!("Fetching auth events"); Box::pin(self.fetch_and_handle_outliers( origin, - &incoming_pdu.auth_events, + pdu_event.auth_events(), create_event, room_id, )) @@ -89,8 +94,8 @@ pub(super) async fn handle_outlier_pdu<'a>( // auth events debug!("Checking based on auth events"); // Build map of auth events - let mut auth_events = HashMap::with_capacity(incoming_pdu.auth_events.len()); - for id in &incoming_pdu.auth_events { + let mut auth_events = HashMap::with_capacity(pdu_event.auth_events().count()); + for id in pdu_event.auth_events() { let Ok(auth_event) = self.services.timeline.get_pdu(id).await else { warn!("Could not find auth event {id}"); continue; @@ -131,7 +136,7 @@ pub(super) async fn handle_outlier_pdu<'a>( let auth_check = state_res::event_auth::auth_check( &to_room_version(&room_version_id), - &incoming_pdu, + &pdu_event, None, // TODO: third party invite state_fetch, ) @@ -147,9 +152,9 @@ pub(super) async fn handle_outlier_pdu<'a>( // 7. Persist the event as an outlier. self.services .outlier - .add_pdu_outlier(&incoming_pdu.event_id, &val); + .add_pdu_outlier(pdu_event.event_id(), &incoming_pdu); trace!("Added pdu as outlier."); - Ok((incoming_pdu, val)) + Ok((pdu_event, incoming_pdu)) } diff --git a/src/service/rooms/event_handler/handle_prev_pdu.rs b/src/service/rooms/event_handler/handle_prev_pdu.rs index d612b2bf..cd46310a 100644 --- a/src/service/rooms/event_handler/handle_prev_pdu.rs +++ b/src/service/rooms/event_handler/handle_prev_pdu.rs @@ -1,10 +1,11 @@ use std::{collections::BTreeMap, time::Instant}; use conduwuit::{ - Err, PduEvent, Result, debug, debug::INFO_SPAN_LEVEL, defer, implement, + Err, Event, PduEvent, Result, debug::INFO_SPAN_LEVEL, defer, implement, utils::continue_exponential_backoff_secs, }; -use ruma::{CanonicalJsonValue, EventId, RoomId, ServerName, UInt}; +use ruma::{CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName}; +use tracing::debug; #[implement(super::Service)] #[allow(clippy::type_complexity)] @@ -15,16 +16,19 @@ use ruma::{CanonicalJsonValue, EventId, RoomId, ServerName, UInt}; skip_all, fields(%prev_id), )] -pub(super) async fn handle_prev_pdu<'a>( +pub(super) async fn handle_prev_pdu<'a, Pdu>( &self, origin: &'a ServerName, event_id: &'a EventId, room_id: &'a RoomId, eventid_info: Option<(PduEvent, BTreeMap)>, - create_event: &'a PduEvent, - first_ts_in_room: UInt, + create_event: &'a Pdu, + first_ts_in_room: MilliSecondsSinceUnixEpoch, prev_id: &'a EventId, -) -> Result { +) -> Result +where + Pdu: Event + Send + Sync, +{ // Check for disabled again because it might have changed if self.services.metadata.is_disabled(room_id).await { return Err!(Request(Forbidden(debug_warn!( @@ -59,7 +63,7 @@ pub(super) async fn handle_prev_pdu<'a>( }; // Skip old events - if pdu.origin_server_ts < first_ts_in_room { + if pdu.origin_server_ts() < first_ts_in_room { return Ok(()); } diff --git a/src/service/rooms/event_handler/mod.rs b/src/service/rooms/event_handler/mod.rs index 45675da8..aed38e1e 100644 --- a/src/service/rooms/event_handler/mod.rs +++ b/src/service/rooms/event_handler/mod.rs @@ -18,7 +18,7 @@ use std::{ }; use async_trait::async_trait; -use conduwuit::{Err, PduEvent, Result, RoomVersion, Server, utils::MutexMap}; +use conduwuit::{Err, Event, PduEvent, Result, RoomVersion, Server, utils::MutexMap}; use ruma::{ OwnedEventId, OwnedRoomId, RoomId, RoomVersionId, events::room::create::RoomCreateEventContent, @@ -104,11 +104,11 @@ impl Service { } } -fn check_room_id(room_id: &RoomId, pdu: &PduEvent) -> Result { - if pdu.room_id != room_id { +fn check_room_id(room_id: &RoomId, pdu: &Pdu) -> Result { + if pdu.room_id() != room_id { return Err!(Request(InvalidParam(error!( - pdu_event_id = ?pdu.event_id, - pdu_room_id = ?pdu.room_id, + pdu_event_id = ?pdu.event_id(), + pdu_room_id = ?pdu.room_id(), ?room_id, "Found event from room in room", )))); @@ -117,7 +117,7 @@ fn check_room_id(room_id: &RoomId, pdu: &PduEvent) -> Result { Ok(()) } -fn get_room_version_id(create_event: &PduEvent) -> Result { +fn get_room_version_id(create_event: &Pdu) -> Result { let content: RoomCreateEventContent = create_event.get_content()?; let room_version = content.room_version; diff --git a/src/service/rooms/event_handler/parse_incoming_pdu.rs b/src/service/rooms/event_handler/parse_incoming_pdu.rs index a49fc541..65cf1752 100644 --- a/src/service/rooms/event_handler/parse_incoming_pdu.rs +++ b/src/service/rooms/event_handler/parse_incoming_pdu.rs @@ -1,4 +1,6 @@ -use conduwuit::{Result, err, implement, pdu::gen_event_id_canonical_json, result::FlatOk}; +use conduwuit::{ + Result, err, implement, matrix::event::gen_event_id_canonical_json, result::FlatOk, +}; use ruma::{CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId}; use serde_json::value::RawValue as RawJsonValue; diff --git a/src/service/rooms/event_handler/state_at_incoming.rs b/src/service/rooms/event_handler/state_at_incoming.rs index eb38c2c3..d3bb8f79 100644 --- a/src/service/rooms/event_handler/state_at_incoming.rs +++ b/src/service/rooms/event_handler/state_at_incoming.rs @@ -6,7 +6,7 @@ use std::{ use conduwuit::{ Result, debug, err, implement, - matrix::{PduEvent, StateMap}, + matrix::{Event, StateMap}, trace, utils::stream::{BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, TryWidebandExt}, }; @@ -19,11 +19,18 @@ use crate::rooms::short::ShortStateHash; #[implement(super::Service)] // request and build the state from a known point and resolve if > 1 prev_event #[tracing::instrument(name = "state", level = "debug", skip_all)] -pub(super) async fn state_at_incoming_degree_one( +pub(super) async fn state_at_incoming_degree_one( &self, - incoming_pdu: &PduEvent, -) -> Result>> { - let prev_event = &incoming_pdu.prev_events[0]; + incoming_pdu: &Pdu, +) -> Result>> +where + Pdu: Event + Send + Sync, +{ + let prev_event = incoming_pdu + .prev_events() + .next() + .expect("at least one prev_event"); + let Ok(prev_event_sstatehash) = self .services .state_accessor @@ -55,7 +62,7 @@ pub(super) async fn state_at_incoming_degree_one( .get_or_create_shortstatekey(&prev_pdu.kind.to_string().into(), state_key) .await; - state.insert(shortstatekey, prev_event.clone()); + state.insert(shortstatekey, prev_event.to_owned()); // Now it's the state after the pdu } @@ -66,16 +73,18 @@ pub(super) async fn state_at_incoming_degree_one( #[implement(super::Service)] #[tracing::instrument(name = "state", level = "debug", skip_all)] -pub(super) async fn state_at_incoming_resolved( +pub(super) async fn state_at_incoming_resolved( &self, - incoming_pdu: &PduEvent, + incoming_pdu: &Pdu, room_id: &RoomId, room_version_id: &RoomVersionId, -) -> Result>> { +) -> Result>> +where + Pdu: Event + Send + Sync, +{ trace!("Calculating extremity statehashes..."); let Ok(extremity_sstatehashes) = incoming_pdu - .prev_events - .iter() + .prev_events() .try_stream() .broad_and_then(|prev_eventid| { self.services @@ -133,12 +142,15 @@ pub(super) async fn state_at_incoming_resolved( } #[implement(super::Service)] -async fn state_at_incoming_fork( +async fn state_at_incoming_fork( &self, room_id: &RoomId, sstatehash: ShortStateHash, - prev_event: PduEvent, -) -> Result<(StateMap, HashSet)> { + prev_event: Pdu, +) -> Result<(StateMap, HashSet)> +where + Pdu: Event, +{ let mut leaf_state: HashMap<_, _> = self .services .state_accessor @@ -146,15 +158,15 @@ async fn state_at_incoming_fork( .collect() .await; - if let Some(state_key) = &prev_event.state_key { + if let Some(state_key) = prev_event.state_key() { let shortstatekey = self .services .short - .get_or_create_shortstatekey(&prev_event.kind.to_string().into(), state_key) + .get_or_create_shortstatekey(&prev_event.kind().to_string().into(), state_key) .await; - let event_id = &prev_event.event_id; - leaf_state.insert(shortstatekey, event_id.clone()); + let event_id = prev_event.event_id(); + leaf_state.insert(shortstatekey, event_id.to_owned()); // Now it's the state after the pdu } diff --git a/src/service/rooms/event_handler/upgrade_outlier_pdu.rs b/src/service/rooms/event_handler/upgrade_outlier_pdu.rs index 00b18c06..4093cb05 100644 --- a/src/service/rooms/event_handler/upgrade_outlier_pdu.rs +++ b/src/service/rooms/event_handler/upgrade_outlier_pdu.rs @@ -1,7 +1,7 @@ use std::{borrow::Borrow, collections::BTreeMap, iter::once, sync::Arc, time::Instant}; use conduwuit::{ - Err, Result, debug, debug_info, err, implement, + Err, Result, debug, debug_info, err, implement, is_equal_to, matrix::{Event, EventTypeExt, PduEvent, StateKey, state_res}, trace, utils::stream::{BroadbandExt, ReadyExt}, @@ -17,19 +17,22 @@ use crate::rooms::{ }; #[implement(super::Service)] -pub(super) async fn upgrade_outlier_to_timeline_pdu( +pub(super) async fn upgrade_outlier_to_timeline_pdu( &self, incoming_pdu: PduEvent, val: BTreeMap, - create_event: &PduEvent, + create_event: &Pdu, origin: &ServerName, room_id: &RoomId, -) -> Result> { +) -> Result> +where + Pdu: Event + Send + Sync, +{ // Skip the PDU if we already have it as a timeline event if let Ok(pduid) = self .services .timeline - .get_pdu_id(&incoming_pdu.event_id) + .get_pdu_id(incoming_pdu.event_id()) .await { return Ok(Some(pduid)); @@ -38,7 +41,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( if self .services .pdu_metadata - .is_event_soft_failed(&incoming_pdu.event_id) + .is_event_soft_failed(incoming_pdu.event_id()) .await { return Err!(Request(InvalidParam("Event has been soft failed"))); @@ -53,7 +56,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( // These are not timeline events. debug!("Resolving state at event"); - let mut state_at_incoming_event = if incoming_pdu.prev_events.len() == 1 { + let mut state_at_incoming_event = if incoming_pdu.prev_events().count() == 1 { self.state_at_incoming_degree_one(&incoming_pdu).await? } else { self.state_at_incoming_resolved(&incoming_pdu, room_id, &room_version_id) @@ -62,12 +65,13 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( if state_at_incoming_event.is_none() { state_at_incoming_event = self - .fetch_state(origin, create_event, room_id, &incoming_pdu.event_id) + .fetch_state(origin, create_event, room_id, incoming_pdu.event_id()) .await?; } let state_at_incoming_event = state_at_incoming_event.expect("we always set this to some above"); + let room_version = to_room_version(&room_version_id); debug!("Performing auth check"); @@ -99,10 +103,10 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( .state .get_auth_events( room_id, - &incoming_pdu.kind, - &incoming_pdu.sender, - incoming_pdu.state_key.as_deref(), - &incoming_pdu.content, + incoming_pdu.kind(), + incoming_pdu.sender(), + incoming_pdu.state_key(), + incoming_pdu.content(), ) .await?; @@ -129,7 +133,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( !self .services .state_accessor - .user_can_redact(&redact_id, &incoming_pdu.sender, &incoming_pdu.room_id, true) + .user_can_redact(&redact_id, incoming_pdu.sender(), incoming_pdu.room_id(), true) .await?, }; @@ -149,7 +153,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( .map(ToOwned::to_owned) .ready_filter(|event_id| { // Remove any that are referenced by this incoming event's prev_events - !incoming_pdu.prev_events.contains(event_id) + !incoming_pdu.prev_events().any(is_equal_to!(event_id)) }) .broad_filter_map(|event_id| async move { // Only keep those extremities were not referenced yet @@ -166,7 +170,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( debug!( "Retained {} extremities checked against {} prev_events", extremities.len(), - incoming_pdu.prev_events.len() + incoming_pdu.prev_events().count() ); let state_ids_compressed: Arc = self @@ -181,20 +185,20 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( .map(Arc::new) .await; - if incoming_pdu.state_key.is_some() { + if incoming_pdu.state_key().is_some() { debug!("Event is a state-event. Deriving new room state"); // We also add state after incoming event to the fork states let mut state_after = state_at_incoming_event.clone(); - if let Some(state_key) = &incoming_pdu.state_key { + if let Some(state_key) = incoming_pdu.state_key() { let shortstatekey = self .services .short - .get_or_create_shortstatekey(&incoming_pdu.kind.to_string().into(), state_key) + .get_or_create_shortstatekey(&incoming_pdu.kind().to_string().into(), state_key) .await; - let event_id = &incoming_pdu.event_id; - state_after.insert(shortstatekey, event_id.clone()); + let event_id = incoming_pdu.event_id(); + state_after.insert(shortstatekey, event_id.to_owned()); } let new_room_state = self @@ -236,9 +240,9 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( // Soft fail, we keep the event as an outlier but don't add it to the timeline self.services .pdu_metadata - .mark_event_soft_failed(&incoming_pdu.event_id); + .mark_event_soft_failed(incoming_pdu.event_id()); - warn!("Event was soft failed: {incoming_pdu:?}"); + warn!("Event was soft failed: {:?}", incoming_pdu.event_id()); return Err!(Request(InvalidParam("Event has been soft failed"))); } @@ -249,7 +253,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu( let extremities = extremities .iter() .map(Borrow::borrow) - .chain(once(incoming_pdu.event_id.borrow())); + .chain(once(incoming_pdu.event_id())); let pdu_id = self .services diff --git a/src/service/rooms/outlier/mod.rs b/src/service/rooms/outlier/mod.rs index 12b56935..6ab2c026 100644 --- a/src/service/rooms/outlier/mod.rs +++ b/src/service/rooms/outlier/mod.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use conduwuit::{Result, implement, matrix::pdu::PduEvent}; -use conduwuit_database::{Deserialized, Json, Map}; +use conduwuit::{Result, implement, matrix::PduEvent}; +use database::{Deserialized, Json, Map}; use ruma::{CanonicalJsonObject, EventId}; pub struct Service { diff --git a/src/service/rooms/pdu_metadata/data.rs b/src/service/rooms/pdu_metadata/data.rs index f0beab5a..c1376cb0 100644 --- a/src/service/rooms/pdu_metadata/data.rs +++ b/src/service/rooms/pdu_metadata/data.rs @@ -1,8 +1,8 @@ use std::{mem::size_of, sync::Arc}; use conduwuit::{ - PduCount, PduEvent, arrayvec::ArrayVec, + matrix::{Event, PduCount}, result::LogErr, utils::{ ReadyExt, @@ -33,8 +33,6 @@ struct Services { timeline: Dep, } -pub(super) type PdusIterItem = (PduCount, PduEvent); - impl Data { pub(super) fn new(args: &crate::Args<'_>) -> Self { let db = &args.db; @@ -62,7 +60,7 @@ impl Data { target: ShortEventId, from: PduCount, dir: Direction, - ) -> impl Stream + Send + '_ { + ) -> impl Stream + Send + '_ { let mut current = ArrayVec::::new(); current.extend(target.to_be_bytes()); current.extend(from.saturating_inc(dir).into_unsigned().to_be_bytes()); @@ -80,8 +78,8 @@ impl Data { let mut pdu = self.services.timeline.get_pdu_from_id(&pdu_id).await.ok()?; - if pdu.sender != user_id { - pdu.remove_transaction_id().log_err().ok(); + if pdu.sender() != user_id { + pdu.as_mut_pdu().remove_transaction_id().log_err().ok(); } Some((shorteventid, pdu)) diff --git a/src/service/rooms/pdu_metadata/mod.rs b/src/service/rooms/pdu_metadata/mod.rs index 18221c2d..c8e863fa 100644 --- a/src/service/rooms/pdu_metadata/mod.rs +++ b/src/service/rooms/pdu_metadata/mod.rs @@ -1,11 +1,14 @@ mod data; use std::sync::Arc; -use conduwuit::{PduCount, Result}; +use conduwuit::{ + Result, + matrix::{Event, PduCount}, +}; use futures::{StreamExt, future::try_join}; use ruma::{EventId, RoomId, UserId, api::Direction}; -use self::data::{Data, PdusIterItem}; +use self::data::Data; use crate::{Dep, rooms}; pub struct Service { @@ -44,16 +47,16 @@ impl Service { } #[allow(clippy::too_many_arguments)] - pub async fn get_relations( - &self, - user_id: &UserId, - room_id: &RoomId, - target: &EventId, + pub async fn get_relations<'a>( + &'a self, + user_id: &'a UserId, + room_id: &'a RoomId, + target: &'a EventId, from: PduCount, limit: usize, max_depth: u8, dir: Direction, - ) -> Vec { + ) -> Vec<(PduCount, impl Event)> { let room_id = self.services.short.get_shortroomid(room_id); let target = self.services.timeline.get_pdu_count(target); diff --git a/src/service/rooms/read_receipt/mod.rs b/src/service/rooms/read_receipt/mod.rs index 69e859c4..68ce9b7f 100644 --- a/src/service/rooms/read_receipt/mod.rs +++ b/src/service/rooms/read_receipt/mod.rs @@ -4,7 +4,10 @@ use std::{collections::BTreeMap, sync::Arc}; use conduwuit::{ Result, debug, err, - matrix::pdu::{PduCount, PduId, RawPduId}, + matrix::{ + Event, + pdu::{PduCount, PduId, RawPduId}, + }, warn, }; use futures::{Stream, TryFutureExt, try_join}; @@ -74,14 +77,13 @@ impl Service { let shortroomid = self.services.short.get_shortroomid(room_id).map_err(|e| { err!(Database(warn!("Short room ID does not exist in database for {room_id}: {e}"))) }); - let (pdu_count, shortroomid) = try_join!(pdu_count, shortroomid)?; + let (pdu_count, shortroomid) = try_join!(pdu_count, shortroomid)?; let shorteventid = PduCount::Normal(pdu_count); let pdu_id: RawPduId = PduId { shortroomid, shorteventid }.into(); - let pdu = self.services.timeline.get_pdu_from_id(&pdu_id).await?; - let event_id: OwnedEventId = pdu.event_id; + let event_id: OwnedEventId = pdu.event_id().to_owned(); let user_id: OwnedUserId = user_id.to_owned(); let content: BTreeMap = BTreeMap::from_iter([( event_id, diff --git a/src/service/rooms/search/mod.rs b/src/service/rooms/search/mod.rs index b9d067a6..afe3061b 100644 --- a/src/service/rooms/search/mod.rs +++ b/src/service/rooms/search/mod.rs @@ -1,9 +1,10 @@ use std::sync::Arc; -use conduwuit_core::{ - Event, PduCount, PduEvent, Result, +use conduwuit::{ + PduCount, Result, arrayvec::ArrayVec, implement, + matrix::event::{Event, Matches}, utils::{ ArrayVecExt, IterStream, ReadyExt, set, stream::{TryIgnore, WidebandExt}, @@ -103,9 +104,10 @@ pub fn deindex_pdu(&self, shortroomid: ShortRoomId, pdu_id: &RawPduId, message_b pub async fn search_pdus<'a>( &'a self, query: &'a RoomQuery<'a>, -) -> Result<(usize, impl Stream + Send + 'a)> { +) -> Result<(usize, impl Stream> + Send + '_)> { let pdu_ids: Vec<_> = self.search_pdu_ids(query).await?.collect().await; + let filter = &query.criteria.filter; let count = pdu_ids.len(); let pdus = pdu_ids .into_iter() @@ -118,11 +120,11 @@ pub async fn search_pdus<'a>( .ok() }) .ready_filter(|pdu| !pdu.is_redacted()) - .ready_filter(|pdu| pdu.matches(&query.criteria.filter)) + .ready_filter(move |pdu| filter.matches(pdu)) .wide_filter_map(move |pdu| async move { self.services .state_accessor - .user_can_see_event(query.user_id?, &pdu.room_id, &pdu.event_id) + .user_can_see_event(query.user_id?, pdu.room_id(), pdu.event_id()) .await .then_some(pdu) }) diff --git a/src/service/rooms/state/mod.rs b/src/service/rooms/state/mod.rs index 9eb02221..641aa6a9 100644 --- a/src/service/rooms/state/mod.rs +++ b/src/service/rooms/state/mod.rs @@ -356,8 +356,8 @@ impl Service { &self, room_id: &RoomId, shortstatehash: u64, - _mutex_lock: &RoomMutexGuard, /* Take mutex guard to make sure users get the room - * state mutex */ + // Take mutex guard to make sure users get the room state mutex + _mutex_lock: &RoomMutexGuard, ) { const BUFSIZE: usize = size_of::(); diff --git a/src/service/rooms/state_accessor/room_state.rs b/src/service/rooms/state_accessor/room_state.rs index 89fa2a83..89a66f0c 100644 --- a/src/service/rooms/state_accessor/room_state.rs +++ b/src/service/rooms/state_accessor/room_state.rs @@ -2,7 +2,7 @@ use std::borrow::Borrow; use conduwuit::{ Result, err, implement, - matrix::{PduEvent, StateKey}, + matrix::{Event, StateKey}, }; use futures::{Stream, StreamExt, TryFutureExt}; use ruma::{EventId, RoomId, events::StateEventType}; @@ -30,7 +30,7 @@ where pub fn room_state_full<'a>( &'a self, room_id: &'a RoomId, -) -> impl Stream> + Send + 'a { +) -> impl Stream> + Send + 'a { self.services .state .get_room_shortstatehash(room_id) @@ -45,7 +45,7 @@ pub fn room_state_full<'a>( pub fn room_state_full_pdus<'a>( &'a self, room_id: &'a RoomId, -) -> impl Stream> + Send + 'a { +) -> impl Stream> + Send + 'a { self.services .state .get_room_shortstatehash(room_id) @@ -84,7 +84,7 @@ pub async fn room_state_get( room_id: &RoomId, event_type: &StateEventType, state_key: &str, -) -> Result { +) -> Result { self.services .state .get_room_shortstatehash(room_id) diff --git a/src/service/rooms/state_accessor/state.rs b/src/service/rooms/state_accessor/state.rs index 169e69e9..a46ce380 100644 --- a/src/service/rooms/state_accessor/state.rs +++ b/src/service/rooms/state_accessor/state.rs @@ -2,14 +2,14 @@ use std::{borrow::Borrow, ops::Deref, sync::Arc}; use conduwuit::{ Result, at, err, implement, - matrix::{PduEvent, StateKey}, + matrix::{Event, StateKey}, pair_of, utils::{ result::FlatOk, stream::{BroadbandExt, IterStream, ReadyExt, TryIgnore}, }, }; -use conduwuit_database::Deserialized; +use database::Deserialized; use futures::{FutureExt, Stream, StreamExt, TryFutureExt, future::try_join, pin_mut}; use ruma::{ EventId, OwnedEventId, UserId, @@ -125,11 +125,9 @@ pub async fn state_get( shortstatehash: ShortStateHash, event_type: &StateEventType, state_key: &str, -) -> Result { +) -> Result { self.state_get_id(shortstatehash, event_type, state_key) - .and_then(|event_id: OwnedEventId| async move { - self.services.timeline.get_pdu(&event_id).await - }) + .and_then(async |event_id: OwnedEventId| self.services.timeline.get_pdu(&event_id).await) .await } @@ -316,18 +314,16 @@ pub fn state_added( pub fn state_full( &self, shortstatehash: ShortStateHash, -) -> impl Stream + Send + '_ { +) -> impl Stream + Send + '_ { self.state_full_pdus(shortstatehash) - .ready_filter_map(|pdu| { - Some(((pdu.kind.to_string().into(), pdu.state_key.clone()?), pdu)) - }) + .ready_filter_map(|pdu| Some(((pdu.kind().clone().into(), pdu.state_key()?.into()), pdu))) } #[implement(super::Service)] pub fn state_full_pdus( &self, shortstatehash: ShortStateHash, -) -> impl Stream + Send + '_ { +) -> impl Stream + Send + '_ { let short_ids = self .state_full_shortids(shortstatehash) .ignore_err() diff --git a/src/service/rooms/state_accessor/user_can.rs b/src/service/rooms/state_accessor/user_can.rs index 67e0b52b..221263a8 100644 --- a/src/service/rooms/state_accessor/user_can.rs +++ b/src/service/rooms/state_accessor/user_can.rs @@ -1,4 +1,4 @@ -use conduwuit::{Err, Result, implement, pdu::PduBuilder}; +use conduwuit::{Err, Result, implement, matrix::Event, pdu::PduBuilder}; use ruma::{ EventId, RoomId, UserId, events::{ @@ -29,14 +29,14 @@ pub async fn user_can_redact( if redacting_event .as_ref() - .is_ok_and(|pdu| pdu.kind == TimelineEventType::RoomCreate) + .is_ok_and(|pdu| *pdu.kind() == TimelineEventType::RoomCreate) { return Err!(Request(Forbidden("Redacting m.room.create is not safe, forbidding."))); } if redacting_event .as_ref() - .is_ok_and(|pdu| pdu.kind == TimelineEventType::RoomServerAcl) + .is_ok_and(|pdu| *pdu.kind() == TimelineEventType::RoomServerAcl) { return Err!(Request(Forbidden( "Redacting m.room.server_acl will result in the room being inaccessible for \ @@ -59,9 +59,9 @@ pub async fn user_can_redact( && match redacting_event { | Ok(redacting_event) => if federation { - redacting_event.sender.server_name() == sender.server_name() + redacting_event.sender().server_name() == sender.server_name() } else { - redacting_event.sender == sender + redacting_event.sender() == sender }, | _ => false, }) @@ -72,10 +72,10 @@ pub async fn user_can_redact( .room_state_get(room_id, &StateEventType::RoomCreate, "") .await { - | Ok(room_create) => Ok(room_create.sender == sender + | Ok(room_create) => Ok(room_create.sender() == sender || redacting_event .as_ref() - .is_ok_and(|redacting_event| redacting_event.sender == sender)), + .is_ok_and(|redacting_event| redacting_event.sender() == sender)), | _ => Err!(Database( "No m.room.power_levels or m.room.create events in database for room" )), diff --git a/src/service/rooms/threads/mod.rs b/src/service/rooms/threads/mod.rs index 9566eb61..59319ba6 100644 --- a/src/service/rooms/threads/mod.rs +++ b/src/service/rooms/threads/mod.rs @@ -49,10 +49,9 @@ impl crate::Service for Service { } impl Service { - pub async fn add_to_thread<'a, E>(&self, root_event_id: &EventId, event: &'a E) -> Result + pub async fn add_to_thread(&self, root_event_id: &EventId, event: &E) -> Result where E: Event + Send + Sync, - &'a E: Event + Send, { let root_id = self .services @@ -120,7 +119,7 @@ impl Service { self.services .timeline - .replace_pdu(&root_id, &root_pdu_json, &root_pdu) + .replace_pdu(&root_id, &root_pdu_json) .await?; } @@ -130,7 +129,7 @@ impl Service { users.extend_from_slice(&userids); }, | _ => { - users.push(root_pdu.sender); + users.push(root_pdu.sender().to_owned()); }, } users.push(event.sender().to_owned()); @@ -162,10 +161,10 @@ impl Service { .ready_take_while(move |pdu_id| pdu_id.shortroomid() == shortroomid.to_be_bytes()) .wide_filter_map(move |pdu_id| async move { let mut pdu = self.services.timeline.get_pdu_from_id(&pdu_id).await.ok()?; - let pdu_id: PduId = pdu_id.into(); - if pdu.sender != user_id { - pdu.remove_transaction_id().ok(); + let pdu_id: PduId = pdu_id.into(); + if pdu.sender() != user_id { + pdu.as_mut_pdu().remove_transaction_id().ok(); } Some((pdu_id.shorteventid, pdu)) diff --git a/src/service/rooms/timeline/data.rs b/src/service/rooms/timeline/data.rs index 94c78bb0..fa10a5c0 100644 --- a/src/service/rooms/timeline/data.rs +++ b/src/service/rooms/timeline/data.rs @@ -207,7 +207,6 @@ impl Data { &self, pdu_id: &RawPduId, pdu_json: &CanonicalJsonObject, - _pdu: &PduEvent, ) -> Result { if self.pduid_pdu.get(pdu_id).await.is_not_found() { return Err!(Request(NotFound("PDU does not exist."))); diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index bcad1309..a381fcf6 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -14,8 +14,8 @@ pub use conduwuit::matrix::pdu::{PduId, RawPduId}; use conduwuit::{ Err, Error, Result, Server, at, debug, debug_warn, err, error, implement, info, matrix::{ - Event, - pdu::{EventHash, PduBuilder, PduCount, PduEvent, gen_event_id}, + event::{Event, gen_event_id}, + pdu::{EventHash, PduBuilder, PduCount, PduEvent}, state_res::{self, RoomVersion}, }, utils::{ @@ -159,12 +159,12 @@ impl crate::Service for Service { impl Service { #[tracing::instrument(skip(self), level = "debug")] - pub async fn first_pdu_in_room(&self, room_id: &RoomId) -> Result { + pub async fn first_pdu_in_room(&self, room_id: &RoomId) -> Result { self.first_item_in_room(room_id).await.map(at!(1)) } #[tracing::instrument(skip(self), level = "debug")] - pub async fn first_item_in_room(&self, room_id: &RoomId) -> Result<(PduCount, PduEvent)> { + pub async fn first_item_in_room(&self, room_id: &RoomId) -> Result<(PduCount, impl Event)> { let pdus = self.pdus(None, room_id, None); pin_mut!(pdus); @@ -174,7 +174,7 @@ impl Service { } #[tracing::instrument(skip(self), level = "debug")] - pub async fn latest_pdu_in_room(&self, room_id: &RoomId) -> Result { + pub async fn latest_pdu_in_room(&self, room_id: &RoomId) -> Result { self.db.latest_pdu_in_room(None, room_id).await } @@ -216,13 +216,14 @@ impl Service { /// /// Checks the `eventid_outlierpdu` Tree if not found in the timeline. #[inline] - pub async fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result { + pub async fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result { self.db.get_non_outlier_pdu(event_id).await } /// Returns the pdu. /// /// Checks the `eventid_outlierpdu` Tree if not found in the timeline. + #[inline] pub async fn get_pdu(&self, event_id: &EventId) -> Result { self.db.get_pdu(event_id).await } @@ -230,11 +231,13 @@ impl Service { /// Returns the pdu. /// /// This does __NOT__ check the outliers `Tree`. + #[inline] pub async fn get_pdu_from_id(&self, pdu_id: &RawPduId) -> Result { self.db.get_pdu_from_id(pdu_id).await } /// Returns the pdu as a `BTreeMap`. + #[inline] pub async fn get_pdu_json_from_id(&self, pdu_id: &RawPduId) -> Result { self.db.get_pdu_json_from_id(pdu_id).await } @@ -242,6 +245,7 @@ impl Service { /// Checks if pdu exists /// /// Checks the `eventid_outlierpdu` Tree if not found in the timeline. + #[inline] pub fn pdu_exists<'a>( &'a self, event_id: &'a EventId, @@ -251,13 +255,8 @@ impl Service { /// Removes a pdu and creates a new one with the same id. #[tracing::instrument(skip(self), level = "debug")] - pub async fn replace_pdu( - &self, - pdu_id: &RawPduId, - pdu_json: &CanonicalJsonObject, - pdu: &PduEvent, - ) -> Result<()> { - self.db.replace_pdu(pdu_id, pdu_json, pdu).await + pub async fn replace_pdu(&self, pdu_id: &RawPduId, pdu_json: &CanonicalJsonObject) -> Result { + self.db.replace_pdu(pdu_id, pdu_json).await } /// Creates a new persisted data unit and adds it to a room. @@ -310,25 +309,21 @@ impl Service { unsigned.insert( "prev_content".to_owned(), CanonicalJsonValue::Object( - utils::to_canonical_object(prev_state.content.clone()).map_err( - |e| { - error!( - "Failed to convert prev_state to canonical JSON: {e}" - ); - Error::bad_database( - "Failed to convert prev_state to canonical JSON.", - ) - }, - )?, + utils::to_canonical_object(prev_state.get_content_as_value()) + .map_err(|e| { + err!(Database(error!( + "Failed to convert prev_state to canonical JSON: {e}", + ))) + })?, ), ); unsigned.insert( String::from("prev_sender"), - CanonicalJsonValue::String(prev_state.sender.to_string()), + CanonicalJsonValue::String(prev_state.sender().to_string()), ); unsigned.insert( String::from("replaces_state"), - CanonicalJsonValue::String(prev_state.event_id.to_string()), + CanonicalJsonValue::String(prev_state.event_id().to_string()), ); } } @@ -709,14 +704,11 @@ impl Service { .await { unsigned.insert("prev_content".to_owned(), prev_pdu.get_content_as_value()); - unsigned.insert( - "prev_sender".to_owned(), - serde_json::to_value(&prev_pdu.sender) - .expect("UserId::to_value always works"), - ); + unsigned + .insert("prev_sender".to_owned(), serde_json::to_value(prev_pdu.sender())?); unsigned.insert( "replaces_state".to_owned(), - serde_json::to_value(&prev_pdu.event_id).expect("EventId is valid json"), + serde_json::to_value(prev_pdu.event_id())?, ); } } @@ -759,7 +751,7 @@ impl Service { unsigned: if unsigned.is_empty() { None } else { - Some(to_raw_value(&unsigned).expect("to_raw_value always works")) + Some(to_raw_value(&unsigned)?) }, hashes: EventHash { sha256: "aaa".to_owned() }, signatures: None, @@ -1041,10 +1033,10 @@ impl Service { /// Replace a PDU with the redacted form. #[tracing::instrument(name = "redact", level = "debug", skip(self))] - pub async fn redact_pdu( + pub async fn redact_pdu( &self, event_id: &EventId, - reason: &PduEvent, + reason: &Pdu, shortroomid: ShortRoomId, ) -> Result { // TODO: Don't reserialize, keep original json @@ -1053,9 +1045,13 @@ impl Service { return Ok(()); }; - let mut pdu = self.get_pdu_from_id(&pdu_id).await.map_err(|e| { - err!(Database(error!(?pdu_id, ?event_id, ?e, "PDU ID points to invalid PDU."))) - })?; + let mut pdu = self + .get_pdu_from_id(&pdu_id) + .await + .map(Event::into_pdu) + .map_err(|e| { + err!(Database(error!(?pdu_id, ?event_id, ?e, "PDU ID points to invalid PDU."))) + })?; if let Ok(content) = pdu.get_content::() { if let Some(body) = content.body { @@ -1065,15 +1061,15 @@ impl Service { } } - let room_version_id = self.services.state.get_room_version(&pdu.room_id).await?; + let room_version_id = self.services.state.get_room_version(pdu.room_id()).await?; - pdu.redact(&room_version_id, reason)?; + pdu.redact(&room_version_id, reason.to_value())?; let obj = utils::to_canonical_object(&pdu).map_err(|e| { err!(Database(error!(?event_id, ?e, "Failed to convert PDU to canonical JSON"))) })?; - self.replace_pdu(&pdu_id, &obj, &pdu).await + self.replace_pdu(&pdu_id, &obj).await } #[tracing::instrument(name = "backfill", level = "debug", skip(self))] @@ -1163,7 +1159,7 @@ impl Service { backfill_server, federation::backfill::get_backfill::v1::Request { room_id: room_id.to_owned(), - v: vec![first_pdu.1.event_id.clone()], + v: vec![first_pdu.1.event_id().to_owned()], limit: uint!(100), }, ) @@ -1248,8 +1244,11 @@ impl Service { #[implement(Service)] #[tracing::instrument(skip_all, level = "debug")] -async fn check_pdu_for_admin_room(&self, pdu: &PduEvent, sender: &UserId) -> Result<()> { - match &pdu.kind { +async fn check_pdu_for_admin_room(&self, pdu: &Pdu, sender: &UserId) -> Result +where + Pdu: Event + Send + Sync, +{ + match pdu.kind() { | TimelineEventType::RoomEncryption => { return Err!(Request(Forbidden(error!("Encryption not supported in admins room.")))); }, @@ -1273,7 +1272,7 @@ async fn check_pdu_for_admin_room(&self, pdu: &PduEvent, sender: &UserId) -> Res let count = self .services .state_cache - .room_members(&pdu.room_id) + .room_members(pdu.room_id()) .ready_filter(|user| self.services.globals.user_is_local(user)) .ready_filter(|user| *user != target) .boxed() @@ -1297,7 +1296,7 @@ async fn check_pdu_for_admin_room(&self, pdu: &PduEvent, sender: &UserId) -> Res let count = self .services .state_cache - .room_members(&pdu.room_id) + .room_members(pdu.room_id()) .ready_filter(|user| self.services.globals.user_is_local(user)) .ready_filter(|user| *user != target) .boxed() diff --git a/src/service/sending/sender.rs b/src/service/sending/sender.rs index 408ab17d..a708f746 100644 --- a/src/service/sending/sender.rs +++ b/src/service/sending/sender.rs @@ -798,7 +798,7 @@ impl Service { let unread: UInt = self .services .user - .notification_count(&user_id, &pdu.room_id) + .notification_count(&user_id, pdu.room_id()) .await .try_into() .expect("notification count can't go that high"); diff --git a/src/service/server_keys/verify.rs b/src/service/server_keys/verify.rs index 84433628..9cc3655a 100644 --- a/src/service/server_keys/verify.rs +++ b/src/service/server_keys/verify.rs @@ -1,4 +1,4 @@ -use conduwuit::{Err, Result, implement, pdu::gen_event_id_canonical_json}; +use conduwuit::{Err, Result, implement, matrix::event::gen_event_id_canonical_json}; use ruma::{ CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, RoomVersionId, signatures::Verified, }; From c06aa49a903a18c87e709a72128662a707cc79ec Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 13 May 2025 21:33:07 +0000 Subject: [PATCH 2101/2291] Fix regression 75aadd5c6a Signed-off-by: Jason Volk --- src/api/client/user_directory.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/api/client/user_directory.rs b/src/api/client/user_directory.rs index 748fc049..9a1f86b8 100644 --- a/src/api/client/user_directory.rs +++ b/src/api/client/user_directory.rs @@ -1,10 +1,7 @@ use axum::extract::State; use conduwuit::{ Result, - utils::{ - future::BoolExt, - stream::{BroadbandExt, ReadyExt}, - }, + utils::{future::BoolExt, stream::BroadbandExt}, }; use futures::{FutureExt, StreamExt, pin_mut}; use ruma::{ @@ -37,17 +34,18 @@ pub(crate) async fn search_users_route( let mut users = services .users .stream() - .ready_filter(|user_id| user_id.as_str().to_lowercase().contains(&search_term)) .map(ToOwned::to_owned) .broad_filter_map(async |user_id| { let display_name = services.users.displayname(&user_id).await.ok(); + let user_id_matches = user_id.as_str().to_lowercase().contains(&search_term); + let display_name_matches = display_name .as_deref() .map(str::to_lowercase) .is_some_and(|display_name| display_name.contains(&search_term)); - if !display_name_matches { + if !user_id_matches && !display_name_matches { return None; } From c5c309ec4301a3d38bda4a8978a499ffa245f834 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 29 Apr 2025 06:39:30 +0000 Subject: [PATCH 2102/2291] Split timeline service. Signed-off-by: Jason Volk --- src/api/client/room/initial_sync.rs | 2 +- src/service/rooms/timeline/append.rs | 446 ++++++++++ src/service/rooms/timeline/backfill.rs | 191 +++++ src/service/rooms/timeline/build.rs | 226 +++++ src/service/rooms/timeline/create.rs | 214 +++++ src/service/rooms/timeline/mod.rs | 1084 +----------------------- src/service/rooms/timeline/redact.rs | 51 ++ 7 files changed, 1146 insertions(+), 1068 deletions(-) create mode 100644 src/service/rooms/timeline/append.rs create mode 100644 src/service/rooms/timeline/backfill.rs create mode 100644 src/service/rooms/timeline/build.rs create mode 100644 src/service/rooms/timeline/create.rs create mode 100644 src/service/rooms/timeline/redact.rs diff --git a/src/api/client/room/initial_sync.rs b/src/api/client/room/initial_sync.rs index 2aca5b9d..d40f6b4f 100644 --- a/src/api/client/room/initial_sync.rs +++ b/src/api/client/room/initial_sync.rs @@ -1,7 +1,7 @@ use axum::extract::State; use conduwuit::{ Err, Event, Result, at, - utils::{BoolExt, future::TryExtExt, stream::TryTools}, + utils::{BoolExt, stream::TryTools}, }; use futures::{FutureExt, TryStreamExt, future::try_join4}; use ruma::api::client::room::initial_sync::v3::{PaginationChunk, Request, Response}; diff --git a/src/service/rooms/timeline/append.rs b/src/service/rooms/timeline/append.rs new file mode 100644 index 00000000..a7b558c2 --- /dev/null +++ b/src/service/rooms/timeline/append.rs @@ -0,0 +1,446 @@ +use std::{ + collections::{BTreeMap, HashSet}, + sync::Arc, +}; + +use conduwuit_core::{ + Result, err, error, implement, + matrix::{ + event::Event, + pdu::{PduCount, PduEvent, PduId, RawPduId}, + }, + utils::{self, ReadyExt}, +}; +use futures::StreamExt; +use ruma::{ + CanonicalJsonObject, CanonicalJsonValue, EventId, RoomVersionId, UserId, + events::{ + GlobalAccountDataEventType, StateEventType, TimelineEventType, + push_rules::PushRulesEvent, + room::{ + encrypted::Relation, + member::{MembershipState, RoomMemberEventContent}, + power_levels::RoomPowerLevelsEventContent, + redaction::RoomRedactionEventContent, + }, + }, + push::{Action, Ruleset, Tweak}, +}; + +use super::{ExtractBody, ExtractRelatesTo, ExtractRelatesToEventId, RoomMutexGuard}; +use crate::{appservice::NamespaceRegex, rooms::state_compressor::CompressedState}; + +/// Append the incoming event setting the state snapshot to the state from +/// the server that sent the event. +#[implement(super::Service)] +#[tracing::instrument(level = "debug", skip_all)] +pub async fn append_incoming_pdu<'a, Leaves>( + &'a self, + pdu: &'a PduEvent, + pdu_json: CanonicalJsonObject, + new_room_leaves: Leaves, + state_ids_compressed: Arc, + soft_fail: bool, + state_lock: &'a RoomMutexGuard, +) -> Result> +where + Leaves: Iterator + Send + 'a, +{ + // We append to state before appending the pdu, so we don't have a moment in + // time with the pdu without it's state. This is okay because append_pdu can't + // fail. + self.services + .state + .set_event_state(&pdu.event_id, &pdu.room_id, state_ids_compressed) + .await?; + + if soft_fail { + self.services + .pdu_metadata + .mark_as_referenced(&pdu.room_id, pdu.prev_events.iter().map(AsRef::as_ref)); + + self.services + .state + .set_forward_extremities(&pdu.room_id, new_room_leaves, state_lock) + .await; + + return Ok(None); + } + + let pdu_id = self + .append_pdu(pdu, pdu_json, new_room_leaves, state_lock) + .await?; + + Ok(Some(pdu_id)) +} + +/// Creates a new persisted data unit and adds it to a room. +/// +/// By this point the incoming event should be fully authenticated, no auth +/// happens in `append_pdu`. +/// +/// Returns pdu id +#[implement(super::Service)] +#[tracing::instrument(level = "debug", skip_all)] +pub async fn append_pdu<'a, Leaves>( + &'a self, + pdu: &'a PduEvent, + mut pdu_json: CanonicalJsonObject, + leaves: Leaves, + state_lock: &'a RoomMutexGuard, +) -> Result +where + Leaves: Iterator + Send + 'a, +{ + // Coalesce database writes for the remainder of this scope. + let _cork = self.db.db.cork_and_flush(); + + let shortroomid = self + .services + .short + .get_shortroomid(pdu.room_id()) + .await + .map_err(|_| err!(Database("Room does not exist")))?; + + // Make unsigned fields correct. This is not properly documented in the spec, + // but state events need to have previous content in the unsigned field, so + // clients can easily interpret things like membership changes + if let Some(state_key) = pdu.state_key() { + if let CanonicalJsonValue::Object(unsigned) = pdu_json + .entry("unsigned".to_owned()) + .or_insert_with(|| CanonicalJsonValue::Object(BTreeMap::default())) + { + if let Ok(shortstatehash) = self + .services + .state_accessor + .pdu_shortstatehash(pdu.event_id()) + .await + { + if let Ok(prev_state) = self + .services + .state_accessor + .state_get(shortstatehash, &pdu.kind().to_string().into(), state_key) + .await + { + unsigned.insert( + "prev_content".to_owned(), + CanonicalJsonValue::Object( + utils::to_canonical_object(prev_state.get_content_as_value()) + .map_err(|e| { + err!(Database(error!( + "Failed to convert prev_state to canonical JSON: {e}", + ))) + })?, + ), + ); + unsigned.insert( + String::from("prev_sender"), + CanonicalJsonValue::String(prev_state.sender().to_string()), + ); + unsigned.insert( + String::from("replaces_state"), + CanonicalJsonValue::String(prev_state.event_id().to_string()), + ); + } + } + } else { + error!("Invalid unsigned type in pdu."); + } + } + + // We must keep track of all events that have been referenced. + self.services + .pdu_metadata + .mark_as_referenced(pdu.room_id(), pdu.prev_events().map(AsRef::as_ref)); + + self.services + .state + .set_forward_extremities(pdu.room_id(), leaves, state_lock) + .await; + + let insert_lock = self.mutex_insert.lock(pdu.room_id()).await; + + let count1 = self.services.globals.next_count().unwrap(); + + // Mark as read first so the sending client doesn't get a notification even if + // appending fails + self.services + .read_receipt + .private_read_set(pdu.room_id(), pdu.sender(), count1); + + self.services + .user + .reset_notification_counts(pdu.sender(), pdu.room_id()); + + let count2 = PduCount::Normal(self.services.globals.next_count().unwrap()); + let pdu_id: RawPduId = PduId { shortroomid, shorteventid: count2 }.into(); + + // Insert pdu + self.db.append_pdu(&pdu_id, pdu, &pdu_json, count2).await; + + drop(insert_lock); + + // See if the event matches any known pushers via power level + let power_levels: RoomPowerLevelsEventContent = self + .services + .state_accessor + .room_state_get_content(pdu.room_id(), &StateEventType::RoomPowerLevels, "") + .await + .unwrap_or_default(); + + let mut push_target: HashSet<_> = self + .services + .state_cache + .active_local_users_in_room(pdu.room_id()) + .map(ToOwned::to_owned) + // Don't notify the sender of their own events, and dont send from ignored users + .ready_filter(|user| *user != pdu.sender()) + .filter_map(|recipient_user| async move { (!self.services.users.user_is_ignored(pdu.sender(), &recipient_user).await).then_some(recipient_user) }) + .collect() + .await; + + let mut notifies = Vec::with_capacity(push_target.len().saturating_add(1)); + let mut highlights = Vec::with_capacity(push_target.len().saturating_add(1)); + + if *pdu.kind() == TimelineEventType::RoomMember { + if let Some(state_key) = pdu.state_key() { + let target_user_id = UserId::parse(state_key)?; + + if self.services.users.is_active_local(target_user_id).await { + push_target.insert(target_user_id.to_owned()); + } + } + } + + let serialized = pdu.to_format(); + for user in &push_target { + let rules_for_user = self + .services + .account_data + .get_global(user, GlobalAccountDataEventType::PushRules) + .await + .map_or_else( + |_| Ruleset::server_default(user), + |ev: PushRulesEvent| ev.content.global, + ); + + let mut highlight = false; + let mut notify = false; + + for action in self + .services + .pusher + .get_actions(user, &rules_for_user, &power_levels, &serialized, pdu.room_id()) + .await + { + match action { + | Action::Notify => notify = true, + | Action::SetTweak(Tweak::Highlight(true)) => { + highlight = true; + }, + | _ => {}, + } + + // Break early if both conditions are true + if notify && highlight { + break; + } + } + + if notify { + notifies.push(user.clone()); + } + + if highlight { + highlights.push(user.clone()); + } + + self.services + .pusher + .get_pushkeys(user) + .ready_for_each(|push_key| { + self.services + .sending + .send_pdu_push(&pdu_id, user, push_key.to_owned()) + .expect("TODO: replace with future"); + }) + .await; + } + + self.db + .increment_notification_counts(pdu.room_id(), notifies, highlights); + + match *pdu.kind() { + | TimelineEventType::RoomRedaction => { + use RoomVersionId::*; + + let room_version_id = self.services.state.get_room_version(pdu.room_id()).await?; + match room_version_id { + | V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => { + if let Some(redact_id) = pdu.redacts() { + if self + .services + .state_accessor + .user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false) + .await? + { + self.redact_pdu(redact_id, pdu, shortroomid).await?; + } + } + }, + | _ => { + let content: RoomRedactionEventContent = pdu.get_content()?; + if let Some(redact_id) = &content.redacts { + if self + .services + .state_accessor + .user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false) + .await? + { + self.redact_pdu(redact_id, pdu, shortroomid).await?; + } + } + }, + } + }, + | TimelineEventType::SpaceChild => + if let Some(_state_key) = pdu.state_key() { + self.services + .spaces + .roomid_spacehierarchy_cache + .lock() + .await + .remove(pdu.room_id()); + }, + | TimelineEventType::RoomMember => { + if let Some(state_key) = pdu.state_key() { + // if the state_key fails + let target_user_id = + UserId::parse(state_key).expect("This state_key was previously validated"); + + let content: RoomMemberEventContent = pdu.get_content()?; + let stripped_state = match content.membership { + | MembershipState::Invite | MembershipState::Knock => + self.services.state.summary_stripped(pdu).await.into(), + | _ => None, + }; + + // Update our membership info, we do this here incase a user is invited or + // knocked and immediately leaves we need the DB to record the invite or + // knock event for auth + self.services + .state_cache + .update_membership( + pdu.room_id(), + target_user_id, + content, + pdu.sender(), + stripped_state, + None, + true, + ) + .await?; + } + }, + | TimelineEventType::RoomMessage => { + let content: ExtractBody = pdu.get_content()?; + if let Some(body) = content.body { + self.services.search.index_pdu(shortroomid, &pdu_id, &body); + + if self.services.admin.is_admin_command(pdu, &body).await { + self.services + .admin + .command_with_sender(body, Some((pdu.event_id()).into()), pdu.sender.clone().into())?; + } + } + }, + | _ => {}, + } + + if let Ok(content) = pdu.get_content::() { + if let Ok(related_pducount) = self.get_pdu_count(&content.relates_to.event_id).await { + self.services + .pdu_metadata + .add_relation(count2, related_pducount); + } + } + + if let Ok(content) = pdu.get_content::() { + match content.relates_to { + | Relation::Reply { in_reply_to } => { + // We need to do it again here, because replies don't have + // event_id as a top level field + if let Ok(related_pducount) = self.get_pdu_count(&in_reply_to.event_id).await { + self.services + .pdu_metadata + .add_relation(count2, related_pducount); + } + }, + | Relation::Thread(thread) => { + self.services + .threads + .add_to_thread(&thread.event_id, pdu) + .await?; + }, + | _ => {}, // TODO: Aggregate other types + } + } + + for appservice in self.services.appservice.read().await.values() { + if self + .services + .state_cache + .appservice_in_room(pdu.room_id(), appservice) + .await + { + self.services + .sending + .send_pdu_appservice(appservice.registration.id.clone(), pdu_id)?; + continue; + } + + // If the RoomMember event has a non-empty state_key, it is targeted at someone. + // If it is our appservice user, we send this PDU to it. + if *pdu.kind() == TimelineEventType::RoomMember { + if let Some(state_key_uid) = &pdu + .state_key + .as_ref() + .and_then(|state_key| UserId::parse(state_key.as_str()).ok()) + { + let appservice_uid = appservice.registration.sender_localpart.as_str(); + if state_key_uid == &appservice_uid { + self.services + .sending + .send_pdu_appservice(appservice.registration.id.clone(), pdu_id)?; + continue; + } + } + } + + let matching_users = |users: &NamespaceRegex| { + appservice.users.is_match(pdu.sender().as_str()) + || *pdu.kind() == TimelineEventType::RoomMember + && pdu + .state_key + .as_ref() + .is_some_and(|state_key| users.is_match(state_key)) + }; + let matching_aliases = |aliases: NamespaceRegex| { + self.services + .alias + .local_aliases_for_room(pdu.room_id()) + .ready_any(move |room_alias| aliases.is_match(room_alias.as_str())) + }; + + if matching_aliases(appservice.aliases.clone()).await + || appservice.rooms.is_match(pdu.room_id().as_str()) + || matching_users(&appservice.users) + { + self.services + .sending + .send_pdu_appservice(appservice.registration.id.clone(), pdu_id)?; + } + } + + Ok(pdu_id) +} diff --git a/src/service/rooms/timeline/backfill.rs b/src/service/rooms/timeline/backfill.rs new file mode 100644 index 00000000..e976981e --- /dev/null +++ b/src/service/rooms/timeline/backfill.rs @@ -0,0 +1,191 @@ +use std::iter::once; + +use conduwuit_core::{ + Result, debug, debug_warn, implement, info, + matrix::{ + event::Event, + pdu::{PduCount, PduId, RawPduId}, + }, + utils::{IterStream, ReadyExt}, + validated, warn, +}; +use futures::{FutureExt, StreamExt}; +use ruma::{ + RoomId, ServerName, + api::federation, + events::{ + StateEventType, TimelineEventType, room::power_levels::RoomPowerLevelsEventContent, + }, + uint, +}; +use serde_json::value::RawValue as RawJsonValue; + +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<()> { + if self + .services + .state_cache + .room_joined_count(room_id) + .await + .is_ok_and(|count| count <= 1) + && !self + .services + .state_accessor + .is_world_readable(room_id) + .await + { + // Room is empty (1 user or none), there is no one that can backfill + return Ok(()); + } + + let first_pdu = self + .first_item_in_room(room_id) + .await + .expect("Room is not empty"); + + if first_pdu.0 < from { + // No backfill required, there are still events between them + return Ok(()); + } + + let power_levels: RoomPowerLevelsEventContent = self + .services + .state_accessor + .room_state_get_content(room_id, &StateEventType::RoomPowerLevels, "") + .await + .unwrap_or_default(); + + let room_mods = power_levels.users.iter().filter_map(|(user_id, level)| { + if level > &power_levels.users_default && !self.services.globals.user_is_local(user_id) { + Some(user_id.server_name()) + } else { + None + } + }); + + let canonical_room_alias_server = once( + self.services + .state_accessor + .get_canonical_alias(room_id) + .await, + ) + .filter_map(Result::ok) + .map(|alias| alias.server_name().to_owned()) + .stream(); + + let mut servers = room_mods + .stream() + .map(ToOwned::to_owned) + .chain(canonical_room_alias_server) + .chain( + self.services + .server + .config + .trusted_servers + .iter() + .map(ToOwned::to_owned) + .stream(), + ) + .ready_filter(|server_name| !self.services.globals.server_is_ours(server_name)) + .filter_map(|server_name| async move { + self.services + .state_cache + .server_in_room(&server_name, room_id) + .await + .then_some(server_name) + }) + .boxed(); + + while let Some(ref backfill_server) = servers.next().await { + info!("Asking {backfill_server} for backfill"); + let response = self + .services + .sending + .send_federation_request( + backfill_server, + federation::backfill::get_backfill::v1::Request { + room_id: room_id.to_owned(), + v: vec![first_pdu.1.event_id().to_owned()], + limit: uint!(100), + }, + ) + .await; + match response { + | Ok(response) => { + for pdu in response.pdus { + if let Err(e) = self.backfill_pdu(backfill_server, pdu).boxed().await { + debug_warn!("Failed to add backfilled pdu in room {room_id}: {e}"); + } + } + return Ok(()); + }, + | Err(e) => { + warn!("{backfill_server} failed to provide backfill for room {room_id}: {e}"); + }, + } + } + + info!("No servers could backfill, but backfill was needed in room {room_id}"); + Ok(()) +} + +#[implement(super::Service)] +#[tracing::instrument(skip(self, pdu), level = "debug")] +pub async fn backfill_pdu(&self, origin: &ServerName, pdu: Box) -> Result<()> { + let (room_id, event_id, value) = self.services.event_handler.parse_incoming_pdu(&pdu).await?; + + // Lock so we cannot backfill the same pdu twice at the same time + let mutex_lock = self + .services + .event_handler + .mutex_federation + .lock(&room_id) + .await; + + // Skip the PDU if we already have it as a timeline event + if let Ok(pdu_id) = self.get_pdu_id(&event_id).await { + debug!("We already know {event_id} at {pdu_id:?}"); + return Ok(()); + } + + self.services + .event_handler + .handle_incoming_pdu(origin, &room_id, &event_id, value, false) + .boxed() + .await?; + + let value = self.get_pdu_json(&event_id).await?; + + let pdu = self.get_pdu(&event_id).await?; + + let shortroomid = self.services.short.get_shortroomid(&room_id).await?; + + let insert_lock = self.mutex_insert.lock(&room_id).await; + + let count: i64 = self.services.globals.next_count().unwrap().try_into()?; + + let pdu_id: RawPduId = PduId { + shortroomid, + shorteventid: PduCount::Backfilled(validated!(0 - count)), + } + .into(); + + // Insert pdu + self.db.prepend_backfill_pdu(&pdu_id, &event_id, &value); + + drop(insert_lock); + + if pdu.kind == TimelineEventType::RoomMessage { + let content: ExtractBody = pdu.get_content()?; + if let Some(body) = content.body { + self.services.search.index_pdu(shortroomid, &pdu_id, &body); + } + } + drop(mutex_lock); + + debug!("Prepended backfill pdu"); + Ok(()) +} diff --git a/src/service/rooms/timeline/build.rs b/src/service/rooms/timeline/build.rs new file mode 100644 index 00000000..a522c531 --- /dev/null +++ b/src/service/rooms/timeline/build.rs @@ -0,0 +1,226 @@ +use std::{collections::HashSet, iter::once}; + +use conduwuit_core::{ + Err, Result, implement, + matrix::{event::Event, pdu::PduBuilder}, + utils::{IterStream, ReadyExt}, +}; +use futures::{FutureExt, StreamExt}; +use ruma::{ + OwnedEventId, OwnedServerName, RoomId, RoomVersionId, UserId, + events::{ + TimelineEventType, + room::{ + member::{MembershipState, RoomMemberEventContent}, + redaction::RoomRedactionEventContent, + }, + }, +}; + +use super::RoomMutexGuard; + +/// Creates a new persisted data unit and adds it to a room. This function +/// takes a roomid_mutex_state, meaning that only this function is able to +/// mutate the room state. +#[implement(super::Service)] +#[tracing::instrument(skip(self, state_lock), level = "debug")] +pub async fn build_and_append_pdu( + &self, + pdu_builder: PduBuilder, + sender: &UserId, + room_id: &RoomId, + state_lock: &RoomMutexGuard, +) -> Result { + let (pdu, pdu_json) = self + .create_hash_and_sign_event(pdu_builder, sender, room_id, state_lock) + .await?; + + if self.services.admin.is_admin_room(pdu.room_id()).await { + self.check_pdu_for_admin_room(&pdu, sender).boxed().await?; + } + + // If redaction event is not authorized, do not append it to the timeline + if *pdu.kind() == TimelineEventType::RoomRedaction { + use RoomVersionId::*; + match self.services.state.get_room_version(pdu.room_id()).await? { + | V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => { + if let Some(redact_id) = pdu.redacts() { + if !self + .services + .state_accessor + .user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false) + .await? + { + return Err!(Request(Forbidden("User cannot redact this event."))); + } + } + }, + | _ => { + let content: RoomRedactionEventContent = pdu.get_content()?; + if let Some(redact_id) = &content.redacts { + if !self + .services + .state_accessor + .user_can_redact(redact_id, pdu.sender(), pdu.room_id(), false) + .await? + { + return Err!(Request(Forbidden("User cannot redact this event."))); + } + } + }, + } + } + + if *pdu.kind() == TimelineEventType::RoomMember { + let content: RoomMemberEventContent = pdu.get_content()?; + + if content.join_authorized_via_users_server.is_some() + && content.membership != MembershipState::Join + { + return Err!(Request(BadJson( + "join_authorised_via_users_server is only for member joins" + ))); + } + + if content + .join_authorized_via_users_server + .as_ref() + .is_some_and(|authorising_user| { + !self.services.globals.user_is_local(authorising_user) + }) { + return Err!(Request(InvalidParam( + "Authorising user does not belong to this homeserver" + ))); + } + } + + // We append to state before appending the pdu, so we don't have a moment in + // time with the pdu without it's state. This is okay because append_pdu can't + // fail. + let statehashid = self.services.state.append_to_state(&pdu).await?; + + let pdu_id = self + .append_pdu( + &pdu, + pdu_json, + // Since this PDU references all pdu_leaves we can update the leaves + // of the room + once(pdu.event_id()), + state_lock, + ) + .boxed() + .await?; + + // We set the room state after inserting the pdu, so that we never have a moment + // in time where events in the current room state do not exist + self.services + .state + .set_room_state(pdu.room_id(), statehashid, state_lock); + + let mut servers: HashSet = self + .services + .state_cache + .room_servers(pdu.room_id()) + .map(ToOwned::to_owned) + .collect() + .await; + + // In case we are kicking or banning a user, we need to inform their server of + // the change + if *pdu.kind() == TimelineEventType::RoomMember { + if let Some(state_key_uid) = &pdu + .state_key + .as_ref() + .and_then(|state_key| UserId::parse(state_key.as_str()).ok()) + { + servers.insert(state_key_uid.server_name().to_owned()); + } + } + + // Remove our server from the server list since it will be added to it by + // room_servers() and/or the if statement above + servers.remove(self.services.globals.server_name()); + + self.services + .sending + .send_pdu_servers(servers.iter().map(AsRef::as_ref).stream(), &pdu_id) + .await?; + + Ok(pdu.event_id().to_owned()) +} + +#[implement(super::Service)] +#[tracing::instrument(skip_all, level = "debug")] +async fn check_pdu_for_admin_room(&self, pdu: &Pdu, sender: &UserId) -> Result +where + Pdu: Event + Send + Sync, +{ + match pdu.kind() { + | TimelineEventType::RoomEncryption => { + return Err!(Request(Forbidden(error!("Encryption not supported in admins room.")))); + }, + | TimelineEventType::RoomMember => { + let target = pdu + .state_key() + .filter(|v| v.starts_with('@')) + .unwrap_or(sender.as_str()); + + let server_user = &self.services.globals.server_user.to_string(); + + let content: RoomMemberEventContent = pdu.get_content()?; + match content.membership { + | MembershipState::Leave => { + if target == server_user { + return Err!(Request(Forbidden(error!( + "Server user cannot leave the admins room." + )))); + } + + let count = self + .services + .state_cache + .room_members(pdu.room_id()) + .ready_filter(|user| self.services.globals.user_is_local(user)) + .ready_filter(|user| *user != target) + .boxed() + .count() + .await; + + if count < 2 { + return Err!(Request(Forbidden(error!( + "Last admin cannot leave the admins room." + )))); + } + }, + + | MembershipState::Ban if pdu.state_key().is_some() => { + if target == server_user { + return Err!(Request(Forbidden(error!( + "Server cannot be banned from admins room." + )))); + } + + let count = self + .services + .state_cache + .room_members(pdu.room_id()) + .ready_filter(|user| self.services.globals.user_is_local(user)) + .ready_filter(|user| *user != target) + .boxed() + .count() + .await; + + if count < 2 { + return Err!(Request(Forbidden(error!( + "Last admin cannot be banned from admins room." + )))); + } + }, + | _ => {}, + } + }, + | _ => {}, + } + + Ok(()) +} diff --git a/src/service/rooms/timeline/create.rs b/src/service/rooms/timeline/create.rs new file mode 100644 index 00000000..d890e88e --- /dev/null +++ b/src/service/rooms/timeline/create.rs @@ -0,0 +1,214 @@ +use std::cmp; + +use conduwuit_core::{ + Err, Error, Result, err, implement, + matrix::{ + event::{Event, gen_event_id}, + pdu::{EventHash, PduBuilder, PduEvent}, + state_res::{self, RoomVersion}, + }, + utils::{self, IterStream, ReadyExt, stream::TryIgnore}, +}; +use futures::{StreamExt, TryStreamExt, future, future::ready}; +use ruma::{ + CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, RoomId, RoomVersionId, UserId, + canonical_json::to_canonical_value, + events::{StateEventType, TimelineEventType, room::create::RoomCreateEventContent}, + uint, +}; +use serde_json::value::to_raw_value; +use tracing::warn; + +use super::RoomMutexGuard; + +#[implement(super::Service)] +pub async fn create_hash_and_sign_event( + &self, + pdu_builder: PduBuilder, + sender: &UserId, + room_id: &RoomId, + _mutex_lock: &RoomMutexGuard, /* Take mutex guard to make sure users get the room + * state mutex */ +) -> Result<(PduEvent, CanonicalJsonObject)> { + let PduBuilder { + event_type, + content, + unsigned, + state_key, + redacts, + timestamp, + } = pdu_builder; + + let prev_events: Vec = self + .services + .state + .get_forward_extremities(room_id) + .take(20) + .map(Into::into) + .collect() + .await; + + // If there was no create event yet, assume we are creating a room + let room_version_id = self + .services + .state + .get_room_version(room_id) + .await + .or_else(|_| { + if event_type == TimelineEventType::RoomCreate { + let content: RoomCreateEventContent = serde_json::from_str(content.get())?; + Ok(content.room_version) + } else { + Err(Error::InconsistentRoomState( + "non-create event for room of unknown version", + room_id.to_owned(), + )) + } + })?; + + let room_version = RoomVersion::new(&room_version_id).expect("room version is supported"); + + let auth_events = self + .services + .state + .get_auth_events(room_id, &event_type, sender, state_key.as_deref(), &content) + .await?; + + // Our depth is the maximum depth of prev_events + 1 + let depth = prev_events + .iter() + .stream() + .map(Ok) + .and_then(|event_id| self.get_pdu(event_id)) + .and_then(|pdu| future::ok(pdu.depth)) + .ignore_err() + .ready_fold(uint!(0), cmp::max) + .await + .saturating_add(uint!(1)); + + let mut unsigned = unsigned.unwrap_or_default(); + + if let Some(state_key) = &state_key { + if let Ok(prev_pdu) = self + .services + .state_accessor + .room_state_get(room_id, &event_type.to_string().into(), state_key) + .await + { + unsigned.insert("prev_content".to_owned(), prev_pdu.get_content_as_value()); + unsigned.insert("prev_sender".to_owned(), serde_json::to_value(prev_pdu.sender())?); + unsigned + .insert("replaces_state".to_owned(), serde_json::to_value(prev_pdu.event_id())?); + } + } + + if event_type != TimelineEventType::RoomCreate && prev_events.is_empty() { + return Err!(Request(Unknown("Event incorrectly had zero prev_events."))); + } + if state_key.is_none() && depth.lt(&uint!(2)) { + // The first two events in a room are always m.room.create and m.room.member, + // so any other events with that same depth are illegal. + warn!( + "Had unsafe depth {depth} when creating non-state event in {room_id}. Cowardly \ + aborting" + ); + return Err!(Request(Unknown("Unsafe depth for non-state event."))); + } + + let mut pdu = PduEvent { + event_id: ruma::event_id!("$thiswillbefilledinlater").into(), + room_id: room_id.to_owned(), + sender: sender.to_owned(), + origin: None, + origin_server_ts: timestamp.map_or_else( + || { + utils::millis_since_unix_epoch() + .try_into() + .expect("u64 fits into UInt") + }, + |ts| ts.get(), + ), + kind: event_type, + content, + state_key, + prev_events, + depth, + auth_events: auth_events + .values() + .map(|pdu| pdu.event_id.clone()) + .collect(), + redacts, + unsigned: if unsigned.is_empty() { + None + } else { + Some(to_raw_value(&unsigned)?) + }, + hashes: EventHash { sha256: "aaa".to_owned() }, + signatures: None, + }; + + let auth_fetch = |k: &StateEventType, s: &str| { + let key = (k.clone(), s.into()); + ready(auth_events.get(&key).map(ToOwned::to_owned)) + }; + + let auth_check = state_res::auth_check( + &room_version, + &pdu, + None, // TODO: third_party_invite + auth_fetch, + ) + .await + .map_err(|e| err!(Request(Forbidden(warn!("Auth check failed: {e:?}")))))?; + + if !auth_check { + return Err!(Request(Forbidden("Event is not authorized."))); + } + + // Hash and sign + let mut pdu_json = utils::to_canonical_object(&pdu).map_err(|e| { + err!(Request(BadJson(warn!("Failed to convert PDU to canonical JSON: {e}")))) + })?; + + // room v3 and above removed the "event_id" field from remote PDU format + match room_version_id { + | RoomVersionId::V1 | RoomVersionId::V2 => {}, + | _ => { + pdu_json.remove("event_id"); + }, + } + + // Add origin because synapse likes that (and it's required in the spec) + pdu_json.insert( + "origin".to_owned(), + to_canonical_value(self.services.globals.server_name()) + .expect("server name is a valid CanonicalJsonValue"), + ); + + if let Err(e) = self + .services + .server_keys + .hash_and_sign_event(&mut pdu_json, &room_version_id) + { + return match e { + | Error::Signatures(ruma::signatures::Error::PduSize) => { + Err!(Request(TooLarge("Message/PDU is too long (exceeds 65535 bytes)"))) + }, + | _ => Err!(Request(Unknown(warn!("Signing event failed: {e}")))), + }; + } + + // Generate event id + pdu.event_id = gen_event_id(&pdu_json, &room_version_id)?; + + pdu_json.insert("event_id".into(), CanonicalJsonValue::String(pdu.event_id.clone().into())); + + // Generate short event id + let _shorteventid = self + .services + .short + .get_or_create_shorteventid(&pdu.event_id) + .await; + + Ok((pdu, pdu_json)) +} diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index a381fcf6..70c98a09 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -1,61 +1,34 @@ +mod append; +mod backfill; +mod build; +mod create; mod data; +mod redact; -use std::{ - borrow::Borrow, - cmp, - collections::{BTreeMap, HashSet}, - fmt::Write, - iter::once, - sync::Arc, -}; +use std::{fmt::Write, sync::Arc}; use async_trait::async_trait; -pub use conduwuit::matrix::pdu::{PduId, RawPduId}; -use conduwuit::{ - Err, Error, Result, Server, at, debug, debug_warn, err, error, implement, info, +pub use conduwuit_core::matrix::pdu::{PduId, RawPduId}; +use conduwuit_core::{ + Result, Server, at, err, matrix::{ - event::{Event, gen_event_id}, - pdu::{EventHash, PduBuilder, PduCount, PduEvent}, - state_res::{self, RoomVersion}, + event::Event, + pdu::{PduCount, PduEvent}, }, - utils::{ - self, IterStream, MutexMap, MutexMapGuard, ReadyExt, future::TryExtExt, stream::TryIgnore, - }, - validated, warn, -}; -use futures::{ - Future, FutureExt, Stream, StreamExt, TryStreamExt, future, future::ready, pin_mut, + utils::{MutexMap, MutexMapGuard, future::TryExtExt, stream::TryIgnore}, + warn, }; +use futures::{Future, Stream, TryStreamExt, pin_mut}; use ruma::{ - CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId, OwnedServerName, - RoomId, RoomVersionId, ServerName, UserId, - api::federation, - canonical_json::to_canonical_value, - events::{ - GlobalAccountDataEventType, StateEventType, TimelineEventType, - push_rules::PushRulesEvent, - room::{ - create::RoomCreateEventContent, - encrypted::Relation, - member::{MembershipState, RoomMemberEventContent}, - power_levels::RoomPowerLevelsEventContent, - redaction::RoomRedactionEventContent, - }, - }, - push::{Action, Ruleset, Tweak}, - uint, + CanonicalJsonObject, EventId, OwnedEventId, OwnedRoomId, RoomId, UserId, + events::room::encrypted::Relation, }; use serde::Deserialize; -use serde_json::value::{RawValue as RawJsonValue, to_raw_value}; use self::data::Data; pub use self::data::PdusIterItem; use crate::{ - Dep, account_data, admin, appservice, - appservice::NamespaceRegex, - globals, pusher, rooms, - rooms::{short::ShortRoomId, state_compressor::CompressedState}, - sending, server_keys, users, + Dep, account_data, admin, appservice, globals, pusher, rooms, sending, server_keys, users, }; // Update Relationships @@ -259,743 +232,6 @@ impl Service { self.db.replace_pdu(pdu_id, pdu_json).await } - /// Creates a new persisted data unit and adds it to a room. - /// - /// By this point the incoming event should be fully authenticated, no auth - /// happens in `append_pdu`. - /// - /// Returns pdu id - #[tracing::instrument(level = "debug", skip_all)] - pub async fn append_pdu<'a, Leaves>( - &'a self, - pdu: &'a PduEvent, - mut pdu_json: CanonicalJsonObject, - leaves: Leaves, - state_lock: &'a RoomMutexGuard, - ) -> Result - where - Leaves: Iterator + Send + 'a, - { - // Coalesce database writes for the remainder of this scope. - let _cork = self.db.db.cork_and_flush(); - - let shortroomid = self - .services - .short - .get_shortroomid(&pdu.room_id) - .await - .map_err(|_| err!(Database("Room does not exist")))?; - - // Make unsigned fields correct. This is not properly documented in the spec, - // but state events need to have previous content in the unsigned field, so - // clients can easily interpret things like membership changes - if let Some(state_key) = &pdu.state_key { - if let CanonicalJsonValue::Object(unsigned) = pdu_json - .entry("unsigned".to_owned()) - .or_insert_with(|| CanonicalJsonValue::Object(BTreeMap::default())) - { - if let Ok(shortstatehash) = self - .services - .state_accessor - .pdu_shortstatehash(&pdu.event_id) - .await - { - if let Ok(prev_state) = self - .services - .state_accessor - .state_get(shortstatehash, &pdu.kind.to_string().into(), state_key) - .await - { - unsigned.insert( - "prev_content".to_owned(), - CanonicalJsonValue::Object( - utils::to_canonical_object(prev_state.get_content_as_value()) - .map_err(|e| { - err!(Database(error!( - "Failed to convert prev_state to canonical JSON: {e}", - ))) - })?, - ), - ); - unsigned.insert( - String::from("prev_sender"), - CanonicalJsonValue::String(prev_state.sender().to_string()), - ); - unsigned.insert( - String::from("replaces_state"), - CanonicalJsonValue::String(prev_state.event_id().to_string()), - ); - } - } - } else { - error!("Invalid unsigned type in pdu."); - } - } - - // We must keep track of all events that have been referenced. - self.services - .pdu_metadata - .mark_as_referenced(&pdu.room_id, pdu.prev_events.iter().map(AsRef::as_ref)); - - self.services - .state - .set_forward_extremities(&pdu.room_id, leaves, state_lock) - .await; - - let insert_lock = self.mutex_insert.lock(&pdu.room_id).await; - - let count1 = self.services.globals.next_count().unwrap(); - // Mark as read first so the sending client doesn't get a notification even if - // appending fails - self.services - .read_receipt - .private_read_set(&pdu.room_id, &pdu.sender, count1); - self.services - .user - .reset_notification_counts(&pdu.sender, &pdu.room_id); - - let count2 = PduCount::Normal(self.services.globals.next_count().unwrap()); - let pdu_id: RawPduId = PduId { shortroomid, shorteventid: count2 }.into(); - - // Insert pdu - self.db.append_pdu(&pdu_id, pdu, &pdu_json, count2).await; - - drop(insert_lock); - - // See if the event matches any known pushers via power level - let power_levels: RoomPowerLevelsEventContent = self - .services - .state_accessor - .room_state_get_content(&pdu.room_id, &StateEventType::RoomPowerLevels, "") - .await - .unwrap_or_default(); - - let mut push_target: HashSet<_> = self - .services - .state_cache - .active_local_users_in_room(&pdu.room_id) - .map(ToOwned::to_owned) - // Don't notify the sender of their own events, and dont send from ignored users - .ready_filter(|user| *user != pdu.sender) - .filter_map(|recipient_user| async move { (!self.services.users.user_is_ignored(&pdu.sender, &recipient_user).await).then_some(recipient_user) }) - .collect() - .await; - - let mut notifies = Vec::with_capacity(push_target.len().saturating_add(1)); - let mut highlights = Vec::with_capacity(push_target.len().saturating_add(1)); - - if pdu.kind == TimelineEventType::RoomMember { - if let Some(state_key) = &pdu.state_key { - let target_user_id = UserId::parse(state_key)?; - - if self.services.users.is_active_local(target_user_id).await { - push_target.insert(target_user_id.to_owned()); - } - } - } - - let serialized = pdu.to_format(); - for user in &push_target { - let rules_for_user = self - .services - .account_data - .get_global(user, GlobalAccountDataEventType::PushRules) - .await - .map_or_else( - |_| Ruleset::server_default(user), - |ev: PushRulesEvent| ev.content.global, - ); - - let mut highlight = false; - let mut notify = false; - - for action in self - .services - .pusher - .get_actions(user, &rules_for_user, &power_levels, &serialized, &pdu.room_id) - .await - { - match action { - | Action::Notify => notify = true, - | Action::SetTweak(Tweak::Highlight(true)) => { - highlight = true; - }, - | _ => {}, - } - - // Break early if both conditions are true - if notify && highlight { - break; - } - } - - if notify { - notifies.push(user.clone()); - } - - if highlight { - highlights.push(user.clone()); - } - - self.services - .pusher - .get_pushkeys(user) - .ready_for_each(|push_key| { - self.services - .sending - .send_pdu_push(&pdu_id, user, push_key.to_owned()) - .expect("TODO: replace with future"); - }) - .await; - } - - self.db - .increment_notification_counts(&pdu.room_id, notifies, highlights); - - match pdu.kind { - | TimelineEventType::RoomRedaction => { - use RoomVersionId::*; - - let room_version_id = self.services.state.get_room_version(&pdu.room_id).await?; - match room_version_id { - | V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => { - if let Some(redact_id) = &pdu.redacts { - if self - .services - .state_accessor - .user_can_redact(redact_id, &pdu.sender, &pdu.room_id, false) - .await? - { - self.redact_pdu(redact_id, pdu, shortroomid).await?; - } - } - }, - | _ => { - let content: RoomRedactionEventContent = pdu.get_content()?; - if let Some(redact_id) = &content.redacts { - if self - .services - .state_accessor - .user_can_redact(redact_id, &pdu.sender, &pdu.room_id, false) - .await? - { - self.redact_pdu(redact_id, pdu, shortroomid).await?; - } - } - }, - } - }, - | TimelineEventType::SpaceChild => - if let Some(_state_key) = &pdu.state_key { - self.services - .spaces - .roomid_spacehierarchy_cache - .lock() - .await - .remove(&pdu.room_id); - }, - | TimelineEventType::RoomMember => { - if let Some(state_key) = &pdu.state_key { - // if the state_key fails - let target_user_id = UserId::parse(state_key) - .expect("This state_key was previously validated"); - - let content: RoomMemberEventContent = pdu.get_content()?; - let stripped_state = match content.membership { - | MembershipState::Invite | MembershipState::Knock => - self.services.state.summary_stripped(pdu).await.into(), - | _ => None, - }; - - // Update our membership info, we do this here incase a user is invited or - // knocked and immediately leaves we need the DB to record the invite or - // knock event for auth - self.services - .state_cache - .update_membership( - &pdu.room_id, - target_user_id, - content, - &pdu.sender, - stripped_state, - None, - true, - ) - .await?; - } - }, - | TimelineEventType::RoomMessage => { - let content: ExtractBody = pdu.get_content()?; - if let Some(body) = content.body { - self.services.search.index_pdu(shortroomid, &pdu_id, &body); - - if self.services.admin.is_admin_command(pdu, &body).await { - self.services.admin.command_with_sender( - body, - Some((*pdu.event_id).into()), - pdu.sender.clone().into(), - )?; - } - } - }, - | _ => {}, - } - - if let Ok(content) = pdu.get_content::() { - if let Ok(related_pducount) = self.get_pdu_count(&content.relates_to.event_id).await { - self.services - .pdu_metadata - .add_relation(count2, related_pducount); - } - } - - if let Ok(content) = pdu.get_content::() { - match content.relates_to { - | Relation::Reply { in_reply_to } => { - // We need to do it again here, because replies don't have - // event_id as a top level field - if let Ok(related_pducount) = self.get_pdu_count(&in_reply_to.event_id).await - { - self.services - .pdu_metadata - .add_relation(count2, related_pducount); - } - }, - | Relation::Thread(thread) => { - self.services - .threads - .add_to_thread(&thread.event_id, pdu) - .await?; - }, - | _ => {}, // TODO: Aggregate other types - } - } - - for appservice in self.services.appservice.read().await.values() { - if self - .services - .state_cache - .appservice_in_room(&pdu.room_id, appservice) - .await - { - self.services - .sending - .send_pdu_appservice(appservice.registration.id.clone(), pdu_id)?; - continue; - } - - // If the RoomMember event has a non-empty state_key, it is targeted at someone. - // If it is our appservice user, we send this PDU to it. - if pdu.kind == TimelineEventType::RoomMember { - if let Some(state_key_uid) = &pdu - .state_key - .as_ref() - .and_then(|state_key| UserId::parse(state_key.as_str()).ok()) - { - let appservice_uid = appservice.registration.sender_localpart.as_str(); - if state_key_uid == &appservice_uid { - self.services - .sending - .send_pdu_appservice(appservice.registration.id.clone(), pdu_id)?; - continue; - } - } - } - - let matching_users = |users: &NamespaceRegex| { - appservice.users.is_match(pdu.sender.as_str()) - || pdu.kind == TimelineEventType::RoomMember - && pdu - .state_key - .as_ref() - .is_some_and(|state_key| users.is_match(state_key)) - }; - let matching_aliases = |aliases: NamespaceRegex| { - self.services - .alias - .local_aliases_for_room(&pdu.room_id) - .ready_any(move |room_alias| aliases.is_match(room_alias.as_str())) - }; - - if matching_aliases(appservice.aliases.clone()).await - || appservice.rooms.is_match(pdu.room_id.as_str()) - || matching_users(&appservice.users) - { - self.services - .sending - .send_pdu_appservice(appservice.registration.id.clone(), pdu_id)?; - } - } - - Ok(pdu_id) - } - - pub async fn create_hash_and_sign_event( - &self, - pdu_builder: PduBuilder, - sender: &UserId, - room_id: &RoomId, - _mutex_lock: &RoomMutexGuard, /* Take mutex guard to make sure users get the room - * state mutex */ - ) -> Result<(PduEvent, CanonicalJsonObject)> { - let PduBuilder { - event_type, - content, - unsigned, - state_key, - redacts, - timestamp, - } = pdu_builder; - - let prev_events: Vec = self - .services - .state - .get_forward_extremities(room_id) - .take(20) - .map(Into::into) - .collect() - .await; - - // If there was no create event yet, assume we are creating a room - let room_version_id = self - .services - .state - .get_room_version(room_id) - .await - .or_else(|_| { - if event_type == TimelineEventType::RoomCreate { - let content: RoomCreateEventContent = serde_json::from_str(content.get())?; - Ok(content.room_version) - } else { - Err(Error::InconsistentRoomState( - "non-create event for room of unknown version", - room_id.to_owned(), - )) - } - })?; - - let room_version = RoomVersion::new(&room_version_id).expect("room version is supported"); - - let auth_events = self - .services - .state - .get_auth_events(room_id, &event_type, sender, state_key.as_deref(), &content) - .await?; - - // Our depth is the maximum depth of prev_events + 1 - let depth = prev_events - .iter() - .stream() - .map(Ok) - .and_then(|event_id| self.get_pdu(event_id)) - .and_then(|pdu| future::ok(pdu.depth)) - .ignore_err() - .ready_fold(uint!(0), cmp::max) - .await - .saturating_add(uint!(1)); - - let mut unsigned = unsigned.unwrap_or_default(); - - if let Some(state_key) = &state_key { - if let Ok(prev_pdu) = self - .services - .state_accessor - .room_state_get(room_id, &event_type.to_string().into(), state_key) - .await - { - unsigned.insert("prev_content".to_owned(), prev_pdu.get_content_as_value()); - unsigned - .insert("prev_sender".to_owned(), serde_json::to_value(prev_pdu.sender())?); - unsigned.insert( - "replaces_state".to_owned(), - serde_json::to_value(prev_pdu.event_id())?, - ); - } - } - if event_type != TimelineEventType::RoomCreate && prev_events.is_empty() { - return Err!(Request(Unknown("Event incorrectly had zero prev_events."))); - } - if state_key.is_none() && depth.lt(&uint!(2)) { - // The first two events in a room are always m.room.create and m.room.member, - // so any other events with that same depth are illegal. - warn!( - "Had unsafe depth {depth} when creating non-state event in {room_id}. Cowardly \ - aborting" - ); - return Err!(Request(Unknown("Unsafe depth for non-state event."))); - } - - let mut pdu = PduEvent { - event_id: ruma::event_id!("$thiswillbefilledinlater").into(), - room_id: room_id.to_owned(), - sender: sender.to_owned(), - origin: None, - origin_server_ts: timestamp.map_or_else( - || { - utils::millis_since_unix_epoch() - .try_into() - .expect("u64 fits into UInt") - }, - |ts| ts.get(), - ), - kind: event_type, - content, - state_key, - prev_events, - depth, - auth_events: auth_events - .values() - .map(|pdu| pdu.event_id.clone()) - .collect(), - redacts, - unsigned: if unsigned.is_empty() { - None - } else { - Some(to_raw_value(&unsigned)?) - }, - hashes: EventHash { sha256: "aaa".to_owned() }, - signatures: None, - }; - - let auth_fetch = |k: &StateEventType, s: &str| { - let key = (k.clone(), s.into()); - ready(auth_events.get(&key).map(ToOwned::to_owned)) - }; - - let auth_check = state_res::auth_check( - &room_version, - &pdu, - None, // TODO: third_party_invite - auth_fetch, - ) - .await - .map_err(|e| err!(Request(Forbidden(warn!("Auth check failed: {e:?}")))))?; - - if !auth_check { - return Err!(Request(Forbidden("Event is not authorized."))); - } - - // Hash and sign - let mut pdu_json = utils::to_canonical_object(&pdu).map_err(|e| { - err!(Request(BadJson(warn!("Failed to convert PDU to canonical JSON: {e}")))) - })?; - - // room v3 and above removed the "event_id" field from remote PDU format - match room_version_id { - | RoomVersionId::V1 | RoomVersionId::V2 => {}, - | _ => { - pdu_json.remove("event_id"); - }, - } - - // Add origin because synapse likes that (and it's required in the spec) - pdu_json.insert( - "origin".to_owned(), - to_canonical_value(self.services.globals.server_name()) - .expect("server name is a valid CanonicalJsonValue"), - ); - - if let Err(e) = self - .services - .server_keys - .hash_and_sign_event(&mut pdu_json, &room_version_id) - { - return match e { - | Error::Signatures(ruma::signatures::Error::PduSize) => { - Err!(Request(TooLarge("Message/PDU is too long (exceeds 65535 bytes)"))) - }, - | _ => Err!(Request(Unknown(warn!("Signing event failed: {e}")))), - }; - } - - // Generate event id - pdu.event_id = gen_event_id(&pdu_json, &room_version_id)?; - - pdu_json - .insert("event_id".into(), CanonicalJsonValue::String(pdu.event_id.clone().into())); - - // Generate short event id - let _shorteventid = self - .services - .short - .get_or_create_shorteventid(&pdu.event_id) - .await; - - Ok((pdu, pdu_json)) - } - - /// Creates a new persisted data unit and adds it to a room. This function - /// takes a roomid_mutex_state, meaning that only this function is able to - /// mutate the room state. - #[tracing::instrument(skip(self, state_lock), level = "debug")] - pub async fn build_and_append_pdu( - &self, - pdu_builder: PduBuilder, - sender: &UserId, - room_id: &RoomId, - state_lock: &RoomMutexGuard, - ) -> Result { - let (pdu, pdu_json) = self - .create_hash_and_sign_event(pdu_builder, sender, room_id, state_lock) - .await?; - - if self.services.admin.is_admin_room(&pdu.room_id).await { - self.check_pdu_for_admin_room(&pdu, sender).boxed().await?; - } - - // If redaction event is not authorized, do not append it to the timeline - if pdu.kind == TimelineEventType::RoomRedaction { - use RoomVersionId::*; - match self.services.state.get_room_version(&pdu.room_id).await? { - | V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => { - if let Some(redact_id) = &pdu.redacts { - if !self - .services - .state_accessor - .user_can_redact(redact_id, &pdu.sender, &pdu.room_id, false) - .await? - { - return Err!(Request(Forbidden("User cannot redact this event."))); - } - } - }, - | _ => { - let content: RoomRedactionEventContent = pdu.get_content()?; - if let Some(redact_id) = &content.redacts { - if !self - .services - .state_accessor - .user_can_redact(redact_id, &pdu.sender, &pdu.room_id, false) - .await? - { - return Err!(Request(Forbidden("User cannot redact this event."))); - } - } - }, - } - } - - if pdu.kind == TimelineEventType::RoomMember { - let content: RoomMemberEventContent = pdu.get_content()?; - - if content.join_authorized_via_users_server.is_some() - && content.membership != MembershipState::Join - { - return Err!(Request(BadJson( - "join_authorised_via_users_server is only for member joins" - ))); - } - - if content - .join_authorized_via_users_server - .as_ref() - .is_some_and(|authorising_user| { - !self.services.globals.user_is_local(authorising_user) - }) { - return Err!(Request(InvalidParam( - "Authorising user does not belong to this homeserver" - ))); - } - } - - // We append to state before appending the pdu, so we don't have a moment in - // time with the pdu without it's state. This is okay because append_pdu can't - // fail. - let statehashid = self.services.state.append_to_state(&pdu).await?; - - let pdu_id = self - .append_pdu( - &pdu, - pdu_json, - // Since this PDU references all pdu_leaves we can update the leaves - // of the room - once(pdu.event_id.borrow()), - state_lock, - ) - .boxed() - .await?; - - // We set the room state after inserting the pdu, so that we never have a moment - // in time where events in the current room state do not exist - self.services - .state - .set_room_state(&pdu.room_id, statehashid, state_lock); - - let mut servers: HashSet = self - .services - .state_cache - .room_servers(&pdu.room_id) - .map(ToOwned::to_owned) - .collect() - .await; - - // In case we are kicking or banning a user, we need to inform their server of - // the change - if pdu.kind == TimelineEventType::RoomMember { - if let Some(state_key_uid) = &pdu - .state_key - .as_ref() - .and_then(|state_key| UserId::parse(state_key.as_str()).ok()) - { - servers.insert(state_key_uid.server_name().to_owned()); - } - } - - // Remove our server from the server list since it will be added to it by - // room_servers() and/or the if statement above - servers.remove(self.services.globals.server_name()); - - self.services - .sending - .send_pdu_servers(servers.iter().map(AsRef::as_ref).stream(), &pdu_id) - .await?; - - Ok(pdu.event_id) - } - - /// Append the incoming event setting the state snapshot to the state from - /// the server that sent the event. - #[tracing::instrument(level = "debug", skip_all)] - pub async fn append_incoming_pdu<'a, Leaves>( - &'a self, - pdu: &'a PduEvent, - pdu_json: CanonicalJsonObject, - new_room_leaves: Leaves, - state_ids_compressed: Arc, - soft_fail: bool, - state_lock: &'a RoomMutexGuard, - ) -> Result> - where - Leaves: Iterator + Send + 'a, - { - // We append to state before appending the pdu, so we don't have a moment in - // time with the pdu without it's state. This is okay because append_pdu can't - // fail. - self.services - .state - .set_event_state(&pdu.event_id, &pdu.room_id, state_ids_compressed) - .await?; - - if soft_fail { - self.services - .pdu_metadata - .mark_as_referenced(&pdu.room_id, pdu.prev_events.iter().map(AsRef::as_ref)); - - self.services - .state - .set_forward_extremities(&pdu.room_id, new_room_leaves, state_lock) - .await; - - return Ok(None); - } - - let pdu_id = self - .append_pdu(pdu, pdu_json, new_room_leaves, state_lock) - .await?; - - Ok(Some(pdu_id)) - } - /// Returns an iterator over all PDUs in a room. Unknown rooms produce no /// items. #[inline] @@ -1030,290 +266,4 @@ impl Service { self.db .pdus(user_id, room_id, from.unwrap_or_else(PduCount::min)) } - - /// Replace a PDU with the redacted form. - #[tracing::instrument(name = "redact", level = "debug", skip(self))] - pub async fn redact_pdu( - &self, - event_id: &EventId, - reason: &Pdu, - shortroomid: ShortRoomId, - ) -> Result { - // TODO: Don't reserialize, keep original json - let Ok(pdu_id) = self.get_pdu_id(event_id).await else { - // If event does not exist, just noop - return Ok(()); - }; - - let mut pdu = self - .get_pdu_from_id(&pdu_id) - .await - .map(Event::into_pdu) - .map_err(|e| { - err!(Database(error!(?pdu_id, ?event_id, ?e, "PDU ID points to invalid PDU."))) - })?; - - if let Ok(content) = pdu.get_content::() { - if let Some(body) = content.body { - self.services - .search - .deindex_pdu(shortroomid, &pdu_id, &body); - } - } - - let room_version_id = self.services.state.get_room_version(pdu.room_id()).await?; - - pdu.redact(&room_version_id, reason.to_value())?; - - let obj = utils::to_canonical_object(&pdu).map_err(|e| { - err!(Database(error!(?event_id, ?e, "Failed to convert PDU to canonical JSON"))) - })?; - - self.replace_pdu(&pdu_id, &obj).await - } - - #[tracing::instrument(name = "backfill", level = "debug", skip(self))] - pub async fn backfill_if_required(&self, room_id: &RoomId, from: PduCount) -> Result<()> { - if self - .services - .state_cache - .room_joined_count(room_id) - .await - .is_ok_and(|count| count <= 1) - && !self - .services - .state_accessor - .is_world_readable(room_id) - .await - { - // Room is empty (1 user or none), there is no one that can backfill - return Ok(()); - } - - let first_pdu = self - .first_item_in_room(room_id) - .await - .expect("Room is not empty"); - - if first_pdu.0 < from { - // No backfill required, there are still events between them - return Ok(()); - } - - let power_levels: RoomPowerLevelsEventContent = self - .services - .state_accessor - .room_state_get_content(room_id, &StateEventType::RoomPowerLevels, "") - .await - .unwrap_or_default(); - - let room_mods = power_levels.users.iter().filter_map(|(user_id, level)| { - if level > &power_levels.users_default - && !self.services.globals.user_is_local(user_id) - { - Some(user_id.server_name()) - } else { - None - } - }); - - let canonical_room_alias_server = once( - self.services - .state_accessor - .get_canonical_alias(room_id) - .await, - ) - .filter_map(Result::ok) - .map(|alias| alias.server_name().to_owned()) - .stream(); - - let mut servers = room_mods - .stream() - .map(ToOwned::to_owned) - .chain(canonical_room_alias_server) - .chain( - self.services - .server - .config - .trusted_servers - .iter() - .map(ToOwned::to_owned) - .stream(), - ) - .ready_filter(|server_name| !self.services.globals.server_is_ours(server_name)) - .filter_map(|server_name| async move { - self.services - .state_cache - .server_in_room(&server_name, room_id) - .await - .then_some(server_name) - }) - .boxed(); - - while let Some(ref backfill_server) = servers.next().await { - info!("Asking {backfill_server} for backfill"); - let response = self - .services - .sending - .send_federation_request( - backfill_server, - federation::backfill::get_backfill::v1::Request { - room_id: room_id.to_owned(), - v: vec![first_pdu.1.event_id().to_owned()], - limit: uint!(100), - }, - ) - .await; - match response { - | Ok(response) => { - for pdu in response.pdus { - if let Err(e) = self.backfill_pdu(backfill_server, pdu).boxed().await { - debug_warn!("Failed to add backfilled pdu in room {room_id}: {e}"); - } - } - return Ok(()); - }, - | Err(e) => { - warn!("{backfill_server} failed to provide backfill for room {room_id}: {e}"); - }, - } - } - - info!("No servers could backfill, but backfill was needed in room {room_id}"); - Ok(()) - } - - #[tracing::instrument(skip(self, pdu), level = "debug")] - pub async fn backfill_pdu(&self, origin: &ServerName, pdu: Box) -> Result<()> { - let (room_id, event_id, value) = - self.services.event_handler.parse_incoming_pdu(&pdu).await?; - - // Lock so we cannot backfill the same pdu twice at the same time - let mutex_lock = self - .services - .event_handler - .mutex_federation - .lock(&room_id) - .await; - - // Skip the PDU if we already have it as a timeline event - if let Ok(pdu_id) = self.get_pdu_id(&event_id).await { - debug!("We already know {event_id} at {pdu_id:?}"); - return Ok(()); - } - - self.services - .event_handler - .handle_incoming_pdu(origin, &room_id, &event_id, value, false) - .boxed() - .await?; - - let value = self.get_pdu_json(&event_id).await?; - - let pdu = self.get_pdu(&event_id).await?; - - let shortroomid = self.services.short.get_shortroomid(&room_id).await?; - - let insert_lock = self.mutex_insert.lock(&room_id).await; - - let count: i64 = self.services.globals.next_count().unwrap().try_into()?; - - let pdu_id: RawPduId = PduId { - shortroomid, - shorteventid: PduCount::Backfilled(validated!(0 - count)), - } - .into(); - - // Insert pdu - self.db.prepend_backfill_pdu(&pdu_id, &event_id, &value); - - drop(insert_lock); - - if pdu.kind == TimelineEventType::RoomMessage { - let content: ExtractBody = pdu.get_content()?; - if let Some(body) = content.body { - self.services.search.index_pdu(shortroomid, &pdu_id, &body); - } - } - drop(mutex_lock); - - debug!("Prepended backfill pdu"); - Ok(()) - } -} - -#[implement(Service)] -#[tracing::instrument(skip_all, level = "debug")] -async fn check_pdu_for_admin_room(&self, pdu: &Pdu, sender: &UserId) -> Result -where - Pdu: Event + Send + Sync, -{ - match pdu.kind() { - | TimelineEventType::RoomEncryption => { - return Err!(Request(Forbidden(error!("Encryption not supported in admins room.")))); - }, - | TimelineEventType::RoomMember => { - let target = pdu - .state_key() - .filter(|v| v.starts_with('@')) - .unwrap_or(sender.as_str()); - - let server_user = &self.services.globals.server_user.to_string(); - - let content: RoomMemberEventContent = pdu.get_content()?; - match content.membership { - | MembershipState::Leave => { - if target == server_user { - return Err!(Request(Forbidden(error!( - "Server user cannot leave the admins room." - )))); - } - - let count = self - .services - .state_cache - .room_members(pdu.room_id()) - .ready_filter(|user| self.services.globals.user_is_local(user)) - .ready_filter(|user| *user != target) - .boxed() - .count() - .await; - - if count < 2 { - return Err!(Request(Forbidden(error!( - "Last admin cannot leave the admins room." - )))); - } - }, - - | MembershipState::Ban if pdu.state_key().is_some() => { - if target == server_user { - return Err!(Request(Forbidden(error!( - "Server cannot be banned from admins room." - )))); - } - - let count = self - .services - .state_cache - .room_members(pdu.room_id()) - .ready_filter(|user| self.services.globals.user_is_local(user)) - .ready_filter(|user| *user != target) - .boxed() - .count() - .await; - - if count < 2 { - return Err!(Request(Forbidden(error!( - "Last admin cannot be banned from admins room." - )))); - } - }, - | _ => {}, - } - }, - | _ => {}, - } - - Ok(()) } diff --git a/src/service/rooms/timeline/redact.rs b/src/service/rooms/timeline/redact.rs new file mode 100644 index 00000000..d51a8462 --- /dev/null +++ b/src/service/rooms/timeline/redact.rs @@ -0,0 +1,51 @@ +use conduwuit_core::{ + Result, err, implement, + matrix::event::Event, + utils::{self}, +}; +use ruma::EventId; + +use super::ExtractBody; +use crate::rooms::short::ShortRoomId; + +/// Replace a PDU with the redacted form. +#[implement(super::Service)] +#[tracing::instrument(name = "redact", level = "debug", skip(self))] +pub async fn redact_pdu( + &self, + event_id: &EventId, + reason: &Pdu, + shortroomid: ShortRoomId, +) -> Result { + // TODO: Don't reserialize, keep original json + let Ok(pdu_id) = self.get_pdu_id(event_id).await else { + // If event does not exist, just noop + return Ok(()); + }; + + let mut pdu = self + .get_pdu_from_id(&pdu_id) + .await + .map(Event::into_pdu) + .map_err(|e| { + err!(Database(error!(?pdu_id, ?event_id, ?e, "PDU ID points to invalid PDU."))) + })?; + + if let Ok(content) = pdu.get_content::() { + if let Some(body) = content.body { + self.services + .search + .deindex_pdu(shortroomid, &pdu_id, &body); + } + } + + let room_version_id = self.services.state.get_room_version(pdu.room_id()).await?; + + pdu.redact(&room_version_id, reason.to_value())?; + + let obj = utils::to_canonical_object(&pdu).map_err(|e| { + err!(Database(error!(?event_id, ?e, "Failed to convert PDU to canonical JSON"))) + })?; + + self.replace_pdu(&pdu_id, &obj).await +} From 56420a67ca8dad57923aa184de860ecbd871b9f1 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 29 Apr 2025 06:55:54 +0000 Subject: [PATCH 2103/2291] Outdent state_compressor service. Signed-off-by: Jason Volk --- src/service/rooms/state_compressor/mod.rs | 678 +++++++++++----------- 1 file changed, 341 insertions(+), 337 deletions(-) diff --git a/src/service/rooms/state_compressor/mod.rs b/src/service/rooms/state_compressor/mod.rs index 56a91d0e..a33fb342 100644 --- a/src/service/rooms/state_compressor/mod.rs +++ b/src/service/rooms/state_compressor/mod.rs @@ -9,7 +9,7 @@ use async_trait::async_trait; use conduwuit::{ Result, arrayvec::ArrayVec, - at, checked, err, expected, utils, + at, checked, err, expected, implement, utils, utils::{bytes, math::usize_from_f64, stream::IterStream}, }; use database::Map; @@ -115,29 +115,30 @@ impl crate::Service for Service { fn name(&self) -> &str { crate::service::make_name(std::module_path!()) } } -impl Service { - /// Returns a stack with info on shortstatehash, full state, added diff and - /// removed diff for the selected shortstatehash and each parent layer. - #[tracing::instrument(name = "load", level = "debug", skip(self))] - pub async fn load_shortstatehash_info( - &self, - shortstatehash: ShortStateHash, - ) -> Result { - if let Some(r) = self.stateinfo_cache.lock()?.get_mut(&shortstatehash) { - return Ok(r.clone()); - } - - let stack = self.new_shortstatehash_info(shortstatehash).await?; - - self.cache_shortstatehash_info(shortstatehash, stack.clone()) - .await?; - - Ok(stack) +/// Returns a stack with info on shortstatehash, full state, added diff and +/// removed diff for the selected shortstatehash and each parent layer. +#[implement(Service)] +#[tracing::instrument(name = "load", level = "debug", skip(self))] +pub async fn load_shortstatehash_info( + &self, + shortstatehash: ShortStateHash, +) -> Result { + if let Some(r) = self.stateinfo_cache.lock()?.get_mut(&shortstatehash) { + return Ok(r.clone()); } - /// Returns a stack with info on shortstatehash, full state, added diff and - /// removed diff for the selected shortstatehash and each parent layer. - #[tracing::instrument( + let stack = self.new_shortstatehash_info(shortstatehash).await?; + + self.cache_shortstatehash_info(shortstatehash, stack.clone()) + .await?; + + Ok(stack) +} + +/// Returns a stack with info on shortstatehash, full state, added diff and +/// removed diff for the selected shortstatehash and each parent layer. +#[implement(Service)] +#[tracing::instrument( name = "cache", level = "debug", skip_all, @@ -146,362 +147,365 @@ impl Service { stack = stack.len(), ), )] - async fn cache_shortstatehash_info( - &self, - shortstatehash: ShortStateHash, - stack: ShortStateInfoVec, - ) -> Result { - self.stateinfo_cache.lock()?.insert(shortstatehash, stack); +async fn cache_shortstatehash_info( + &self, + shortstatehash: ShortStateHash, + stack: ShortStateInfoVec, +) -> Result { + self.stateinfo_cache.lock()?.insert(shortstatehash, stack); - Ok(()) - } + Ok(()) +} - async fn new_shortstatehash_info( - &self, - shortstatehash: ShortStateHash, - ) -> Result { - let StateDiff { parent, added, removed } = self.get_statediff(shortstatehash).await?; +#[implement(Service)] +async fn new_shortstatehash_info( + &self, + shortstatehash: ShortStateHash, +) -> Result { + let StateDiff { parent, added, removed } = self.get_statediff(shortstatehash).await?; - let Some(parent) = parent else { - return Ok(vec![ShortStateInfo { - shortstatehash, - full_state: added.clone(), - added, - removed, - }]); - }; - - let mut stack = Box::pin(self.load_shortstatehash_info(parent)).await?; - let top = stack.last().expect("at least one frame"); - - let mut full_state = (*top.full_state).clone(); - full_state.extend(added.iter().copied()); - - let removed = (*removed).clone(); - for r in &removed { - full_state.remove(r); - } - - stack.push(ShortStateInfo { + let Some(parent) = parent else { + return Ok(vec![ShortStateInfo { shortstatehash, + full_state: added.clone(), added, - removed: Arc::new(removed), - full_state: Arc::new(full_state), - }); + removed, + }]); + }; - Ok(stack) + let mut stack = Box::pin(self.load_shortstatehash_info(parent)).await?; + let top = stack.last().expect("at least one frame"); + + let mut full_state = (*top.full_state).clone(); + full_state.extend(added.iter().copied()); + + let removed = (*removed).clone(); + for r in &removed { + full_state.remove(r); } - pub fn compress_state_events<'a, I>( - &'a self, - state: I, - ) -> impl Stream + Send + 'a - where - I: Iterator + Clone + Debug + Send + 'a, - { - let event_ids = state.clone().map(at!(1)); + stack.push(ShortStateInfo { + shortstatehash, + added, + removed: Arc::new(removed), + full_state: Arc::new(full_state), + }); - let short_event_ids = self - .services - .short - .multi_get_or_create_shorteventid(event_ids); + Ok(stack) +} - state - .stream() - .map(at!(0)) - .zip(short_event_ids) - .map(|(shortstatekey, shorteventid)| { - compress_state_event(*shortstatekey, shorteventid) - }) - } +#[implement(Service)] +pub fn compress_state_events<'a, I>( + &'a self, + state: I, +) -> impl Stream + Send + 'a +where + I: Iterator + Clone + Debug + Send + 'a, +{ + let event_ids = state.clone().map(at!(1)); - pub async fn compress_state_event( - &self, - shortstatekey: ShortStateKey, - event_id: &EventId, - ) -> CompressedStateEvent { - let shorteventid = self - .services - .short - .get_or_create_shorteventid(event_id) - .await; + let short_event_ids = self + .services + .short + .multi_get_or_create_shorteventid(event_ids); - compress_state_event(shortstatekey, shorteventid) - } + state + .stream() + .map(at!(0)) + .zip(short_event_ids) + .map(|(shortstatekey, shorteventid)| compress_state_event(*shortstatekey, shorteventid)) +} - /// Creates a new shortstatehash that often is just a diff to an already - /// existing shortstatehash and therefore very efficient. - /// - /// There are multiple layers of diffs. The bottom layer 0 always contains - /// the full state. Layer 1 contains diffs to states of layer 0, layer 2 - /// diffs to layer 1 and so on. If layer n > 0 grows too big, it will be - /// combined with layer n-1 to create a new diff on layer n-1 that's - /// based on layer n-2. If that layer is also too big, it will recursively - /// fix above layers too. - /// - /// * `shortstatehash` - Shortstatehash of this state - /// * `statediffnew` - Added to base. Each vec is shortstatekey+shorteventid - /// * `statediffremoved` - Removed from base. Each vec is - /// shortstatekey+shorteventid - /// * `diff_to_sibling` - Approximately how much the diff grows each time - /// for this layer - /// * `parent_states` - A stack with info on shortstatehash, full state, - /// added diff and removed diff for each parent layer - pub fn save_state_from_diff( - &self, - shortstatehash: ShortStateHash, - statediffnew: Arc, - statediffremoved: Arc, - diff_to_sibling: usize, - mut parent_states: ParentStatesVec, - ) -> Result { - let statediffnew_len = statediffnew.len(); - let statediffremoved_len = statediffremoved.len(); - let diffsum = checked!(statediffnew_len + statediffremoved_len)?; +#[implement(Service)] +pub async fn compress_state_event( + &self, + shortstatekey: ShortStateKey, + event_id: &EventId, +) -> CompressedStateEvent { + let shorteventid = self + .services + .short + .get_or_create_shorteventid(event_id) + .await; - if parent_states.len() > 3 { - // Number of layers - // To many layers, we have to go deeper - let parent = parent_states.pop().expect("parent must have a state"); + compress_state_event(shortstatekey, shorteventid) +} - let mut parent_new = (*parent.added).clone(); - let mut parent_removed = (*parent.removed).clone(); - - for removed in statediffremoved.iter() { - if !parent_new.remove(removed) { - // It was not added in the parent and we removed it - parent_removed.insert(*removed); - } - // Else it was added in the parent and we removed it again. We - // can forget this change - } - - for new in statediffnew.iter() { - if !parent_removed.remove(new) { - // It was not touched in the parent and we added it - parent_new.insert(*new); - } - // Else it was removed in the parent and we added it again. We - // can forget this change - } - - self.save_state_from_diff( - shortstatehash, - Arc::new(parent_new), - Arc::new(parent_removed), - diffsum, - parent_states, - )?; - - return Ok(()); - } - - if parent_states.is_empty() { - // There is no parent layer, create a new state - self.save_statediff(shortstatehash, &StateDiff { - parent: None, - added: statediffnew, - removed: statediffremoved, - }); - - return Ok(()); - } - - // Else we have two options. - // 1. We add the current diff on top of the parent layer. - // 2. We replace a layer above +/// Creates a new shortstatehash that often is just a diff to an already +/// existing shortstatehash and therefore very efficient. +/// +/// There are multiple layers of diffs. The bottom layer 0 always contains +/// the full state. Layer 1 contains diffs to states of layer 0, layer 2 +/// diffs to layer 1 and so on. If layer n > 0 grows too big, it will be +/// combined with layer n-1 to create a new diff on layer n-1 that's +/// based on layer n-2. If that layer is also too big, it will recursively +/// fix above layers too. +/// +/// * `shortstatehash` - Shortstatehash of this state +/// * `statediffnew` - Added to base. Each vec is shortstatekey+shorteventid +/// * `statediffremoved` - Removed from base. Each vec is +/// shortstatekey+shorteventid +/// * `diff_to_sibling` - Approximately how much the diff grows each time for +/// this layer +/// * `parent_states` - A stack with info on shortstatehash, full state, added +/// diff and removed diff for each parent layer +#[implement(Service)] +pub fn save_state_from_diff( + &self, + shortstatehash: ShortStateHash, + statediffnew: Arc, + statediffremoved: Arc, + diff_to_sibling: usize, + mut parent_states: ParentStatesVec, +) -> Result { + let statediffnew_len = statediffnew.len(); + let statediffremoved_len = statediffremoved.len(); + let diffsum = checked!(statediffnew_len + statediffremoved_len)?; + if parent_states.len() > 3 { + // Number of layers + // To many layers, we have to go deeper let parent = parent_states.pop().expect("parent must have a state"); - let parent_added_len = parent.added.len(); - let parent_removed_len = parent.removed.len(); - let parent_diff = checked!(parent_added_len + parent_removed_len)?; - if checked!(diffsum * diffsum)? >= checked!(2 * diff_to_sibling * parent_diff)? { - // Diff too big, we replace above layer(s) - let mut parent_new = (*parent.added).clone(); - let mut parent_removed = (*parent.removed).clone(); + let mut parent_new = (*parent.added).clone(); + let mut parent_removed = (*parent.removed).clone(); - for removed in statediffremoved.iter() { - if !parent_new.remove(removed) { - // It was not added in the parent and we removed it - parent_removed.insert(*removed); - } - // Else it was added in the parent and we removed it again. We - // can forget this change + for removed in statediffremoved.iter() { + if !parent_new.remove(removed) { + // It was not added in the parent and we removed it + parent_removed.insert(*removed); } - - for new in statediffnew.iter() { - if !parent_removed.remove(new) { - // It was not touched in the parent and we added it - parent_new.insert(*new); - } - // Else it was removed in the parent and we added it again. We - // can forget this change - } - - self.save_state_from_diff( - shortstatehash, - Arc::new(parent_new), - Arc::new(parent_removed), - diffsum, - parent_states, - )?; - } else { - // Diff small enough, we add diff as layer on top of parent - self.save_statediff(shortstatehash, &StateDiff { - parent: Some(parent.shortstatehash), - added: statediffnew, - removed: statediffremoved, - }); + // Else it was added in the parent and we removed it again. We + // can forget this change } - Ok(()) + for new in statediffnew.iter() { + if !parent_removed.remove(new) { + // It was not touched in the parent and we added it + parent_new.insert(*new); + } + // Else it was removed in the parent and we added it again. We + // can forget this change + } + + self.save_state_from_diff( + shortstatehash, + Arc::new(parent_new), + Arc::new(parent_removed), + diffsum, + parent_states, + )?; + + return Ok(()); } - /// Returns the new shortstatehash, and the state diff from the previous - /// room state - #[tracing::instrument(skip(self, new_state_ids_compressed), level = "debug")] - pub async fn save_state( - &self, - room_id: &RoomId, - new_state_ids_compressed: Arc, - ) -> Result { - let previous_shortstatehash = self - .services - .state - .get_room_shortstatehash(room_id) - .await - .ok(); - - let state_hash = - utils::calculate_hash(new_state_ids_compressed.iter().map(|bytes| &bytes[..])); - - let (new_shortstatehash, already_existed) = self - .services - .short - .get_or_create_shortstatehash(&state_hash) - .await; - - if Some(new_shortstatehash) == previous_shortstatehash { - return Ok(HashSetCompressStateEvent { - shortstatehash: new_shortstatehash, - ..Default::default() - }); - } - - let states_parents = if let Some(p) = previous_shortstatehash { - self.load_shortstatehash_info(p).await.unwrap_or_default() - } else { - ShortStateInfoVec::new() - }; - - let (statediffnew, statediffremoved) = - if let Some(parent_stateinfo) = states_parents.last() { - let statediffnew: CompressedState = new_state_ids_compressed - .difference(&parent_stateinfo.full_state) - .copied() - .collect(); - - let statediffremoved: CompressedState = parent_stateinfo - .full_state - .difference(&new_state_ids_compressed) - .copied() - .collect(); - - (Arc::new(statediffnew), Arc::new(statediffremoved)) - } else { - (new_state_ids_compressed, Arc::new(CompressedState::new())) - }; - - if !already_existed { - self.save_state_from_diff( - new_shortstatehash, - statediffnew.clone(), - statediffremoved.clone(), - 2, // every state change is 2 event changes on average - states_parents, - )?; - } - - Ok(HashSetCompressStateEvent { - shortstatehash: new_shortstatehash, + if parent_states.is_empty() { + // There is no parent layer, create a new state + self.save_statediff(shortstatehash, &StateDiff { + parent: None, added: statediffnew, removed: statediffremoved, - }) + }); + + return Ok(()); } - #[tracing::instrument(skip(self), level = "debug", name = "get")] - async fn get_statediff(&self, shortstatehash: ShortStateHash) -> Result { - const BUFSIZE: usize = size_of::(); - const STRIDE: usize = size_of::(); + // Else we have two options. + // 1. We add the current diff on top of the parent layer. + // 2. We replace a layer above - let value = self - .db - .shortstatehash_statediff - .aqry::(&shortstatehash) - .await - .map_err(|e| { - err!(Database("Failed to find StateDiff from short {shortstatehash:?}: {e}")) - })?; + let parent = parent_states.pop().expect("parent must have a state"); + let parent_added_len = parent.added.len(); + let parent_removed_len = parent.removed.len(); + let parent_diff = checked!(parent_added_len + parent_removed_len)?; - let parent = utils::u64_from_bytes(&value[0..size_of::()]) - .ok() - .take_if(|parent| *parent != 0); + if checked!(diffsum * diffsum)? >= checked!(2 * diff_to_sibling * parent_diff)? { + // Diff too big, we replace above layer(s) + let mut parent_new = (*parent.added).clone(); + let mut parent_removed = (*parent.removed).clone(); - debug_assert!(value.len() % STRIDE == 0, "value not aligned to stride"); - let _num_values = value.len() / STRIDE; - - let mut add_mode = true; - let mut added = CompressedState::new(); - let mut removed = CompressedState::new(); - - let mut i = STRIDE; - while let Some(v) = value.get(i..expected!(i + 2 * STRIDE)) { - if add_mode && v.starts_with(&0_u64.to_be_bytes()) { - add_mode = false; - i = expected!(i + STRIDE); - continue; + for removed in statediffremoved.iter() { + if !parent_new.remove(removed) { + // It was not added in the parent and we removed it + parent_removed.insert(*removed); } - if add_mode { - added.insert(v.try_into()?); - } else { - removed.insert(v.try_into()?); - } - i = expected!(i + 2 * STRIDE); + // Else it was added in the parent and we removed it again. We + // can forget this change } - Ok(StateDiff { - parent, - added: Arc::new(added), - removed: Arc::new(removed), - }) + for new in statediffnew.iter() { + if !parent_removed.remove(new) { + // It was not touched in the parent and we added it + parent_new.insert(*new); + } + // Else it was removed in the parent and we added it again. We + // can forget this change + } + + self.save_state_from_diff( + shortstatehash, + Arc::new(parent_new), + Arc::new(parent_removed), + diffsum, + parent_states, + )?; + } else { + // Diff small enough, we add diff as layer on top of parent + self.save_statediff(shortstatehash, &StateDiff { + parent: Some(parent.shortstatehash), + added: statediffnew, + removed: statediffremoved, + }); } - fn save_statediff(&self, shortstatehash: ShortStateHash, diff: &StateDiff) { - let mut value = Vec::::with_capacity( - 2_usize - .saturating_add(diff.added.len()) - .saturating_add(diff.removed.len()), - ); + Ok(()) +} - let parent = diff.parent.unwrap_or(0_u64); - value.extend_from_slice(&parent.to_be_bytes()); +/// Returns the new shortstatehash, and the state diff from the previous +/// room state +#[implement(Service)] +#[tracing::instrument(skip(self, new_state_ids_compressed), level = "debug")] +pub async fn save_state( + &self, + room_id: &RoomId, + new_state_ids_compressed: Arc, +) -> Result { + let previous_shortstatehash = self + .services + .state + .get_room_shortstatehash(room_id) + .await + .ok(); - for new in diff.added.iter() { - value.extend_from_slice(&new[..]); - } + let state_hash = + utils::calculate_hash(new_state_ids_compressed.iter().map(|bytes| &bytes[..])); - if !diff.removed.is_empty() { - value.extend_from_slice(&0_u64.to_be_bytes()); - for removed in diff.removed.iter() { - value.extend_from_slice(&removed[..]); - } - } + let (new_shortstatehash, already_existed) = self + .services + .short + .get_or_create_shortstatehash(&state_hash) + .await; - self.db - .shortstatehash_statediff - .insert(&shortstatehash.to_be_bytes(), &value); + if Some(new_shortstatehash) == previous_shortstatehash { + return Ok(HashSetCompressStateEvent { + shortstatehash: new_shortstatehash, + ..Default::default() + }); } + + let states_parents = if let Some(p) = previous_shortstatehash { + self.load_shortstatehash_info(p).await.unwrap_or_default() + } else { + ShortStateInfoVec::new() + }; + + let (statediffnew, statediffremoved) = if let Some(parent_stateinfo) = states_parents.last() { + let statediffnew: CompressedState = new_state_ids_compressed + .difference(&parent_stateinfo.full_state) + .copied() + .collect(); + + let statediffremoved: CompressedState = parent_stateinfo + .full_state + .difference(&new_state_ids_compressed) + .copied() + .collect(); + + (Arc::new(statediffnew), Arc::new(statediffremoved)) + } else { + (new_state_ids_compressed, Arc::new(CompressedState::new())) + }; + + if !already_existed { + self.save_state_from_diff( + new_shortstatehash, + statediffnew.clone(), + statediffremoved.clone(), + 2, // every state change is 2 event changes on average + states_parents, + )?; + } + + Ok(HashSetCompressStateEvent { + shortstatehash: new_shortstatehash, + added: statediffnew, + removed: statediffremoved, + }) +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug", name = "get")] +async fn get_statediff(&self, shortstatehash: ShortStateHash) -> Result { + const BUFSIZE: usize = size_of::(); + const STRIDE: usize = size_of::(); + + let value = self + .db + .shortstatehash_statediff + .aqry::(&shortstatehash) + .await + .map_err(|e| { + err!(Database("Failed to find StateDiff from short {shortstatehash:?}: {e}")) + })?; + + let parent = utils::u64_from_bytes(&value[0..size_of::()]) + .ok() + .take_if(|parent| *parent != 0); + + debug_assert!(value.len() % STRIDE == 0, "value not aligned to stride"); + let _num_values = value.len() / STRIDE; + + let mut add_mode = true; + let mut added = CompressedState::new(); + let mut removed = CompressedState::new(); + + let mut i = STRIDE; + while let Some(v) = value.get(i..expected!(i + 2 * STRIDE)) { + if add_mode && v.starts_with(&0_u64.to_be_bytes()) { + add_mode = false; + i = expected!(i + STRIDE); + continue; + } + if add_mode { + added.insert(v.try_into()?); + } else { + removed.insert(v.try_into()?); + } + i = expected!(i + 2 * STRIDE); + } + + Ok(StateDiff { + parent, + added: Arc::new(added), + removed: Arc::new(removed), + }) +} + +#[implement(Service)] +fn save_statediff(&self, shortstatehash: ShortStateHash, diff: &StateDiff) { + let mut value = Vec::::with_capacity( + 2_usize + .saturating_add(diff.added.len()) + .saturating_add(diff.removed.len()), + ); + + let parent = diff.parent.unwrap_or(0_u64); + value.extend_from_slice(&parent.to_be_bytes()); + + for new in diff.added.iter() { + value.extend_from_slice(&new[..]); + } + + if !diff.removed.is_empty() { + value.extend_from_slice(&0_u64.to_be_bytes()); + for removed in diff.removed.iter() { + value.extend_from_slice(&removed[..]); + } + } + + self.db + .shortstatehash_statediff + .insert(&shortstatehash.to_be_bytes(), &value); } #[inline] From 36e81ba185dbd17aa73f9d01417ec5c37f7da4c5 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 29 Apr 2025 07:28:05 +0000 Subject: [PATCH 2104/2291] Split state_cache service. Signed-off-by: Jason Volk --- src/service/rooms/state_cache/mod.rs | 1308 ++++++++--------------- src/service/rooms/state_cache/update.rs | 369 +++++++ src/service/rooms/state_cache/via.rs | 92 ++ 3 files changed, 882 insertions(+), 887 deletions(-) create mode 100644 src/service/rooms/state_cache/update.rs create mode 100644 src/service/rooms/state_cache/via.rs diff --git a/src/service/rooms/state_cache/mod.rs b/src/service/rooms/state_cache/mod.rs index d3dbc143..9429be79 100644 --- a/src/service/rooms/state_cache/mod.rs +++ b/src/service/rooms/state_cache/mod.rs @@ -1,30 +1,22 @@ +mod update; +mod via; + use std::{ - collections::{HashMap, HashSet}, + collections::HashMap, sync::{Arc, RwLock}, }; use conduwuit::{ - Result, is_not_empty, + Result, implement, result::LogErr, - utils::{ReadyExt, StreamTools, stream::TryIgnore}, + utils::{ReadyExt, stream::TryIgnore}, warn, }; -use database::{Deserialized, Ignore, Interfix, Json, Map, serialize_key}; -use futures::{Stream, StreamExt, future::join5, pin_mut, stream::iter}; -use itertools::Itertools; +use database::{Deserialized, Ignore, Interfix, Map}; +use futures::{Stream, StreamExt, future::join5, pin_mut}; use ruma::{ - OwnedRoomId, OwnedServerName, RoomId, ServerName, UserId, - events::{ - AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType, - RoomAccountDataEventType, StateEventType, - direct::DirectEvent, - room::{ - create::RoomCreateEventContent, - member::{MembershipState, RoomMemberEventContent}, - power_levels::RoomPowerLevelsEventContent, - }, - }, - int, + OwnedRoomId, RoomId, ServerName, UserId, + events::{AnyStrippedStateEvent, AnySyncStateEvent, room::member::MembershipState}, serde::Raw, }; @@ -101,901 +93,443 @@ impl crate::Service for Service { fn name(&self) -> &str { crate::service::make_name(std::module_path!()) } } -impl Service { - /// Update current membership data. - #[tracing::instrument( - level = "debug", - skip_all, - fields( - %room_id, - %user_id, - %sender, - ?membership_event, - ), - )] - #[allow(clippy::too_many_arguments)] - pub async fn update_membership( - &self, - room_id: &RoomId, - user_id: &UserId, - membership_event: RoomMemberEventContent, - sender: &UserId, - last_state: Option>>, - invite_via: Option>, - update_joined_count: bool, - ) -> Result<()> { - let membership = membership_event.membership; - - // Keep track what remote users exist by adding them as "deactivated" users - // - // TODO: use futures to update remote profiles without blocking the membership - // update - #[allow(clippy::collapsible_if)] - if !self.services.globals.user_is_local(user_id) { - if !self.services.users.exists(user_id).await { - self.services.users.create(user_id, None)?; - } - - /* - // Try to update our local copy of the user if ours does not match - if ((self.services.users.displayname(user_id)? != membership_event.displayname) - || (self.services.users.avatar_url(user_id)? != membership_event.avatar_url) - || (self.services.users.blurhash(user_id)? != membership_event.blurhash)) - && (membership != MembershipState::Leave) - { - let response = self.services - .sending - .send_federation_request( - user_id.server_name(), - federation::query::get_profile_information::v1::Request { - user_id: user_id.into(), - field: None, // we want the full user's profile to update locally too - }, - ) - .await; - - self.services.users.set_displayname(user_id, response.displayname.clone()).await?; - self.services.users.set_avatar_url(user_id, response.avatar_url).await?; - self.services.users.set_blurhash(user_id, response.blurhash).await?; - }; - */ - } - - match &membership { - | MembershipState::Join => { - // Check if the user never joined this room - if !self.once_joined(user_id, room_id).await { - // Add the user ID to the join list then - self.mark_as_once_joined(user_id, room_id); - - // Check if the room has a predecessor - if let Ok(Some(predecessor)) = self - .services - .state_accessor - .room_state_get_content(room_id, &StateEventType::RoomCreate, "") - .await - .map(|content: RoomCreateEventContent| content.predecessor) - { - // Copy user settings from predecessor to the current room: - // - Push rules - // - // TODO: finish this once push rules are implemented. - // - // let mut push_rules_event_content: PushRulesEvent = account_data - // .get( - // None, - // user_id, - // EventType::PushRules, - // )?; - // - // NOTE: find where `predecessor.room_id` match - // and update to `room_id`. - // - // account_data - // .update( - // None, - // user_id, - // EventType::PushRules, - // &push_rules_event_content, - // globals, - // ) - // .ok(); - - // Copy old tags to new room - if let Ok(tag_event) = self - .services - .account_data - .get_room( - &predecessor.room_id, - user_id, - RoomAccountDataEventType::Tag, - ) - .await - { - self.services - .account_data - .update( - Some(room_id), - user_id, - RoomAccountDataEventType::Tag, - &tag_event, - ) - .await - .ok(); - } - - // Copy direct chat flag - if let Ok(mut direct_event) = self - .services - .account_data - .get_global::( - user_id, - GlobalAccountDataEventType::Direct, - ) - .await - { - let mut room_ids_updated = false; - for room_ids in direct_event.content.0.values_mut() { - if room_ids.iter().any(|r| r == &predecessor.room_id) { - room_ids.push(room_id.to_owned()); - room_ids_updated = true; - } - } - - if room_ids_updated { - self.services - .account_data - .update( - None, - user_id, - GlobalAccountDataEventType::Direct.to_string().into(), - &serde_json::to_value(&direct_event) - .expect("to json always works"), - ) - .await?; - } - } - } - } - - self.mark_as_joined(user_id, room_id); - }, - | MembershipState::Invite => { - // We want to know if the sender is ignored by the receiver - if self.services.users.user_is_ignored(sender, user_id).await { - return Ok(()); - } - - self.mark_as_invited(user_id, room_id, last_state, invite_via) - .await; - }, - | MembershipState::Leave | MembershipState::Ban => { - self.mark_as_left(user_id, room_id); - - if self.services.globals.user_is_local(user_id) - && (self.services.config.forget_forced_upon_leave - || self.services.metadata.is_banned(room_id).await - || self.services.metadata.is_disabled(room_id).await) - { - self.forget(room_id, user_id); - } - }, - | _ => {}, - } - - if update_joined_count { - self.update_joined_count(room_id).await; - } - - Ok(()) +#[implement(Service)] +#[tracing::instrument(level = "trace", skip_all)] +pub async fn appservice_in_room(&self, room_id: &RoomId, appservice: &RegistrationInfo) -> bool { + if let Some(cached) = self + .appservice_in_room_cache + .read() + .expect("locked") + .get(room_id) + .and_then(|map| map.get(&appservice.registration.id)) + .copied() + { + return cached; } - #[tracing::instrument(level = "trace", skip_all)] - pub async fn appservice_in_room( - &self, - room_id: &RoomId, - appservice: &RegistrationInfo, - ) -> bool { - if let Some(cached) = self - .appservice_in_room_cache - .read() - .expect("locked") - .get(room_id) - .and_then(|map| map.get(&appservice.registration.id)) - .copied() - { - return cached; - } + let bridge_user_id = UserId::parse_with_server_name( + appservice.registration.sender_localpart.as_str(), + self.services.globals.server_name(), + ); - let bridge_user_id = UserId::parse_with_server_name( - appservice.registration.sender_localpart.as_str(), - self.services.globals.server_name(), - ); + let Ok(bridge_user_id) = bridge_user_id.log_err() else { + return false; + }; - let Ok(bridge_user_id) = bridge_user_id.log_err() else { - return false; - }; - - let in_room = self.is_joined(&bridge_user_id, room_id).await - || self - .room_members(room_id) - .ready_any(|user_id| appservice.users.is_match(user_id.as_str())) - .await; - - self.appservice_in_room_cache - .write() - .expect("locked") - .entry(room_id.into()) - .or_default() - .insert(appservice.registration.id.clone(), in_room); - - in_room - } - - /// Direct DB function to directly mark a user as joined. It is not - /// recommended to use this directly. You most likely should use - /// `update_membership` instead - #[tracing::instrument(skip(self), level = "debug")] - pub fn mark_as_joined(&self, user_id: &UserId, room_id: &RoomId) { - let userroom_id = (user_id, room_id); - let userroom_id = serialize_key(userroom_id).expect("failed to serialize userroom_id"); - - let roomuser_id = (room_id, user_id); - let roomuser_id = serialize_key(roomuser_id).expect("failed to serialize roomuser_id"); - - self.db.userroomid_joined.insert(&userroom_id, []); - self.db.roomuserid_joined.insert(&roomuser_id, []); - - self.db.userroomid_invitestate.remove(&userroom_id); - self.db.roomuserid_invitecount.remove(&roomuser_id); - - self.db.userroomid_leftstate.remove(&userroom_id); - self.db.roomuserid_leftcount.remove(&roomuser_id); - - self.db.userroomid_knockedstate.remove(&userroom_id); - self.db.roomuserid_knockedcount.remove(&roomuser_id); - - self.db.roomid_inviteviaservers.remove(room_id); - } - - /// Direct DB function to directly mark a user as left. It is not - /// recommended to use this directly. You most likely should use - /// `update_membership` instead - #[tracing::instrument(skip(self), level = "debug")] - pub fn mark_as_left(&self, user_id: &UserId, room_id: &RoomId) { - let userroom_id = (user_id, room_id); - let userroom_id = serialize_key(userroom_id).expect("failed to serialize userroom_id"); - - let roomuser_id = (room_id, user_id); - let roomuser_id = serialize_key(roomuser_id).expect("failed to serialize roomuser_id"); - - // (timo) TODO - let leftstate = Vec::>::new(); - - self.db - .userroomid_leftstate - .raw_put(&userroom_id, Json(leftstate)); - self.db - .roomuserid_leftcount - .raw_aput::<8, _, _>(&roomuser_id, self.services.globals.next_count().unwrap()); - - self.db.userroomid_joined.remove(&userroom_id); - self.db.roomuserid_joined.remove(&roomuser_id); - - self.db.userroomid_invitestate.remove(&userroom_id); - self.db.roomuserid_invitecount.remove(&roomuser_id); - - self.db.userroomid_knockedstate.remove(&userroom_id); - self.db.roomuserid_knockedcount.remove(&roomuser_id); - - self.db.roomid_inviteviaservers.remove(room_id); - } - - /// Direct DB function to directly mark a user as knocked. It is not - /// recommended to use this directly. You most likely should use - /// `update_membership` instead - #[tracing::instrument(skip(self), level = "debug")] - pub fn mark_as_knocked( - &self, - user_id: &UserId, - room_id: &RoomId, - knocked_state: Option>>, - ) { - let userroom_id = (user_id, room_id); - let userroom_id = serialize_key(userroom_id).expect("failed to serialize userroom_id"); - - let roomuser_id = (room_id, user_id); - let roomuser_id = serialize_key(roomuser_id).expect("failed to serialize roomuser_id"); - - self.db - .userroomid_knockedstate - .raw_put(&userroom_id, Json(knocked_state.unwrap_or_default())); - self.db - .roomuserid_knockedcount - .raw_aput::<8, _, _>(&roomuser_id, self.services.globals.next_count().unwrap()); - - self.db.userroomid_joined.remove(&userroom_id); - self.db.roomuserid_joined.remove(&roomuser_id); - - self.db.userroomid_invitestate.remove(&userroom_id); - self.db.roomuserid_invitecount.remove(&roomuser_id); - - self.db.userroomid_leftstate.remove(&userroom_id); - self.db.roomuserid_leftcount.remove(&roomuser_id); - - self.db.roomid_inviteviaservers.remove(room_id); - } - - /// Makes a user forget a room. - #[tracing::instrument(skip(self), level = "debug")] - pub fn forget(&self, room_id: &RoomId, user_id: &UserId) { - let userroom_id = (user_id, room_id); - let roomuser_id = (room_id, user_id); - - self.db.userroomid_leftstate.del(userroom_id); - self.db.roomuserid_leftcount.del(roomuser_id); - } - - /// Returns an iterator of all servers participating in this room. - #[tracing::instrument(skip(self), level = "debug")] - pub fn room_servers<'a>( - &'a self, - room_id: &'a RoomId, - ) -> impl Stream + Send + 'a { - let prefix = (room_id, Interfix); - self.db - .roomserverids - .keys_prefix(&prefix) - .ignore_err() - .map(|(_, server): (Ignore, &ServerName)| server) - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn server_in_room<'a>( - &'a self, - server: &'a ServerName, - room_id: &'a RoomId, - ) -> bool { - let key = (server, room_id); - self.db.serverroomids.qry(&key).await.is_ok() - } - - /// Returns an iterator of all rooms a server participates in (as far as we - /// know). - #[tracing::instrument(skip(self), level = "debug")] - pub fn server_rooms<'a>( - &'a self, - server: &'a ServerName, - ) -> impl Stream + Send + 'a { - let prefix = (server, Interfix); - self.db - .serverroomids - .keys_prefix(&prefix) - .ignore_err() - .map(|(_, room_id): (Ignore, &RoomId)| room_id) - } - - /// Returns true if server can see user by sharing at least one room. - #[tracing::instrument(skip(self), level = "trace")] - pub async fn server_sees_user(&self, server: &ServerName, user_id: &UserId) -> bool { - self.server_rooms(server) - .any(|room_id| self.is_joined(user_id, room_id)) - .await - } - - /// Returns true if user_a and user_b share at least one room. - #[tracing::instrument(skip(self), level = "trace")] - pub async fn user_sees_user(&self, user_a: &UserId, user_b: &UserId) -> bool { - let get_shared_rooms = self.get_shared_rooms(user_a, user_b); - - pin_mut!(get_shared_rooms); - get_shared_rooms.next().await.is_some() - } - - /// List the rooms common between two users - #[tracing::instrument(skip(self), level = "debug")] - pub fn get_shared_rooms<'a>( - &'a self, - user_a: &'a UserId, - user_b: &'a UserId, - ) -> impl Stream + Send + 'a { - use conduwuit::utils::set; - - let a = self.rooms_joined(user_a); - let b = self.rooms_joined(user_b); - set::intersection_sorted_stream2(a, b) - } - - /// Returns an iterator of all joined members of a room. - #[tracing::instrument(skip(self), level = "debug")] - pub fn room_members<'a>( - &'a self, - room_id: &'a RoomId, - ) -> impl Stream + Send + 'a { - let prefix = (room_id, Interfix); - self.db - .roomuserid_joined - .keys_prefix(&prefix) - .ignore_err() - .map(|(_, user_id): (Ignore, &UserId)| user_id) - } - - /// Returns the number of users which are currently in a room - #[tracing::instrument(skip(self), level = "trace")] - pub async fn room_joined_count(&self, room_id: &RoomId) -> Result { - self.db.roomid_joinedcount.get(room_id).await.deserialized() - } - - #[tracing::instrument(skip(self), level = "debug")] - /// Returns an iterator of all our local users in the room, even if they're - /// deactivated/guests - pub fn local_users_in_room<'a>( - &'a self, - room_id: &'a RoomId, - ) -> impl Stream + Send + 'a { - self.room_members(room_id) - .ready_filter(|user| self.services.globals.user_is_local(user)) - } - - /// Returns an iterator of all our local joined users in a room who are - /// active (not deactivated, not guest) - #[tracing::instrument(skip(self), level = "trace")] - pub fn active_local_users_in_room<'a>( - &'a self, - room_id: &'a RoomId, - ) -> impl Stream + Send + 'a { - self.local_users_in_room(room_id) - .filter(|user| self.services.users.is_active(user)) - } - - /// Returns the number of users which are currently invited to a room - #[tracing::instrument(skip(self), level = "trace")] - pub async fn room_invited_count(&self, room_id: &RoomId) -> Result { - self.db - .roomid_invitedcount - .get(room_id) - .await - .deserialized() - } - - /// Returns an iterator over all User IDs who ever joined a room. - #[tracing::instrument(skip(self), level = "debug")] - pub fn room_useroncejoined<'a>( - &'a self, - room_id: &'a RoomId, - ) -> impl Stream + Send + 'a { - let prefix = (room_id, Interfix); - self.db - .roomuseroncejoinedids - .keys_prefix(&prefix) - .ignore_err() - .map(|(_, user_id): (Ignore, &UserId)| user_id) - } - - /// Returns an iterator over all invited members of a room. - #[tracing::instrument(skip(self), level = "debug")] - pub fn room_members_invited<'a>( - &'a self, - room_id: &'a RoomId, - ) -> impl Stream + Send + 'a { - let prefix = (room_id, Interfix); - self.db - .roomuserid_invitecount - .keys_prefix(&prefix) - .ignore_err() - .map(|(_, user_id): (Ignore, &UserId)| user_id) - } - - /// Returns an iterator over all knocked members of a room. - #[tracing::instrument(skip(self), level = "debug")] - pub fn room_members_knocked<'a>( - &'a self, - room_id: &'a RoomId, - ) -> impl Stream + Send + 'a { - let prefix = (room_id, Interfix); - self.db - .roomuserid_knockedcount - .keys_prefix(&prefix) - .ignore_err() - .map(|(_, user_id): (Ignore, &UserId)| user_id) - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn get_invite_count(&self, room_id: &RoomId, user_id: &UserId) -> Result { - let key = (room_id, user_id); - self.db - .roomuserid_invitecount - .qry(&key) - .await - .deserialized() - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn get_knock_count(&self, room_id: &RoomId, user_id: &UserId) -> Result { - let key = (room_id, user_id); - self.db - .roomuserid_knockedcount - .qry(&key) - .await - .deserialized() - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result { - let key = (room_id, user_id); - self.db.roomuserid_leftcount.qry(&key).await.deserialized() - } - - /// Returns an iterator over all rooms this user joined. - #[tracing::instrument(skip(self), level = "debug")] - pub fn rooms_joined<'a>( - &'a self, - user_id: &'a UserId, - ) -> impl Stream + Send + 'a { - self.db - .userroomid_joined - .keys_raw_prefix(user_id) - .ignore_err() - .map(|(_, room_id): (Ignore, &RoomId)| room_id) - } - - /// Returns an iterator over all rooms a user was invited to. - #[tracing::instrument(skip(self), level = "debug")] - pub fn rooms_invited<'a>( - &'a self, - user_id: &'a UserId, - ) -> impl Stream + Send + 'a { - type KeyVal<'a> = (Key<'a>, Raw>); - type Key<'a> = (&'a UserId, &'a RoomId); - - let prefix = (user_id, Interfix); - self.db - .userroomid_invitestate - .stream_prefix(&prefix) - .ignore_err() - .map(|((_, room_id), state): KeyVal<'_>| (room_id.to_owned(), state)) - .map(|(room_id, state)| Ok((room_id, state.deserialize_as()?))) - .ignore_err() - } - - /// Returns an iterator over all rooms a user is currently knocking. - #[tracing::instrument(skip(self), level = "trace")] - pub fn rooms_knocked<'a>( - &'a self, - user_id: &'a UserId, - ) -> impl Stream + Send + 'a { - type KeyVal<'a> = (Key<'a>, Raw>); - type Key<'a> = (&'a UserId, &'a RoomId); - - let prefix = (user_id, Interfix); - self.db - .userroomid_knockedstate - .stream_prefix(&prefix) - .ignore_err() - .map(|((_, room_id), state): KeyVal<'_>| (room_id.to_owned(), state)) - .map(|(room_id, state)| Ok((room_id, state.deserialize_as()?))) - .ignore_err() - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn invite_state( - &self, - user_id: &UserId, - room_id: &RoomId, - ) -> Result>> { - let key = (user_id, room_id); - self.db - .userroomid_invitestate - .qry(&key) - .await - .deserialized() - .and_then(|val: Raw>| { - val.deserialize_as().map_err(Into::into) - }) - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn knock_state( - &self, - user_id: &UserId, - room_id: &RoomId, - ) -> Result>> { - let key = (user_id, room_id); - self.db - .userroomid_knockedstate - .qry(&key) - .await - .deserialized() - .and_then(|val: Raw>| { - val.deserialize_as().map_err(Into::into) - }) - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn left_state( - &self, - user_id: &UserId, - room_id: &RoomId, - ) -> Result>> { - let key = (user_id, room_id); - self.db - .userroomid_leftstate - .qry(&key) - .await - .deserialized() - .and_then(|val: Raw>| { - val.deserialize_as().map_err(Into::into) - }) - } - - /// Returns an iterator over all rooms a user left. - #[tracing::instrument(skip(self), level = "debug")] - pub fn rooms_left<'a>( - &'a self, - user_id: &'a UserId, - ) -> impl Stream + Send + 'a { - type KeyVal<'a> = (Key<'a>, Raw>>); - type Key<'a> = (&'a UserId, &'a RoomId); - - let prefix = (user_id, Interfix); - self.db - .userroomid_leftstate - .stream_prefix(&prefix) - .ignore_err() - .map(|((_, room_id), state): KeyVal<'_>| (room_id.to_owned(), state)) - .map(|(room_id, state)| Ok((room_id, state.deserialize_as()?))) - .ignore_err() - } - - #[tracing::instrument(skip(self), level = "debug")] - pub async fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> bool { - let key = (user_id, room_id); - self.db.roomuseroncejoinedids.qry(&key).await.is_ok() - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn is_joined<'a>(&'a self, user_id: &'a UserId, room_id: &'a RoomId) -> bool { - let key = (user_id, room_id); - self.db.userroomid_joined.qry(&key).await.is_ok() - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn is_knocked<'a>(&'a self, user_id: &'a UserId, room_id: &'a RoomId) -> bool { - let key = (user_id, room_id); - self.db.userroomid_knockedstate.qry(&key).await.is_ok() - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> bool { - let key = (user_id, room_id); - self.db.userroomid_invitestate.qry(&key).await.is_ok() - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> bool { - let key = (user_id, room_id); - self.db.userroomid_leftstate.qry(&key).await.is_ok() - } - - #[tracing::instrument(skip(self), level = "trace")] - pub async fn user_membership( - &self, - user_id: &UserId, - room_id: &RoomId, - ) -> Option { - let states = join5( - self.is_joined(user_id, room_id), - self.is_left(user_id, room_id), - self.is_knocked(user_id, room_id), - self.is_invited(user_id, room_id), - self.once_joined(user_id, room_id), - ) - .await; - - match states { - | (true, ..) => Some(MembershipState::Join), - | (_, true, ..) => Some(MembershipState::Leave), - | (_, _, true, ..) => Some(MembershipState::Knock), - | (_, _, _, true, ..) => Some(MembershipState::Invite), - | (false, false, false, false, true) => Some(MembershipState::Ban), - | _ => None, - } - } - - #[tracing::instrument(skip(self), level = "debug")] - pub fn servers_invite_via<'a>( - &'a self, - room_id: &'a RoomId, - ) -> impl Stream + Send + 'a { - type KeyVal<'a> = (Ignore, Vec<&'a ServerName>); - - self.db - .roomid_inviteviaservers - .stream_raw_prefix(room_id) - .ignore_err() - .map(|(_, servers): KeyVal<'_>| *servers.last().expect("at least one server")) - } - - /// Gets up to five servers that are likely to be in the room in the - /// distant future. - /// - /// See - #[tracing::instrument(skip(self), level = "trace")] - pub async fn servers_route_via(&self, room_id: &RoomId) -> Result> { - let most_powerful_user_server = self - .services - .state_accessor - .room_state_get_content(room_id, &StateEventType::RoomPowerLevels, "") - .await - .map(|content: RoomPowerLevelsEventContent| { - content - .users - .iter() - .max_by_key(|(_, power)| *power) - .and_then(|x| (x.1 >= &int!(50)).then_some(x)) - .map(|(user, _power)| user.server_name().to_owned()) - }); - - let mut servers: Vec = self + let in_room = self.is_joined(&bridge_user_id, room_id).await + || self .room_members(room_id) - .counts_by(|user| user.server_name().to_owned()) - .await - .into_iter() - .sorted_by_key(|(_, users)| *users) - .map(|(server, _)| server) - .rev() - .take(5) - .collect(); - - if let Ok(Some(server)) = most_powerful_user_server { - servers.insert(0, server); - servers.truncate(5); - } - - Ok(servers) - } - - pub fn get_appservice_in_room_cache_usage(&self) -> (usize, usize) { - let cache = self.appservice_in_room_cache.read().expect("locked"); - - (cache.len(), cache.capacity()) - } - - #[tracing::instrument(level = "debug", skip_all)] - pub fn clear_appservice_in_room_cache(&self) { - self.appservice_in_room_cache - .write() - .expect("locked") - .clear(); - } - - #[tracing::instrument(level = "debug", skip(self))] - pub async fn update_joined_count(&self, room_id: &RoomId) { - let mut joinedcount = 0_u64; - let mut invitedcount = 0_u64; - let mut knockedcount = 0_u64; - let mut joined_servers = HashSet::new(); - - self.room_members(room_id) - .ready_for_each(|joined| { - joined_servers.insert(joined.server_name().to_owned()); - joinedcount = joinedcount.saturating_add(1); - }) + .ready_any(|user_id| appservice.users.is_match(user_id.as_str())) .await; - invitedcount = invitedcount.saturating_add( - self.room_members_invited(room_id) - .count() - .await - .try_into() - .unwrap_or(0), - ); + self.appservice_in_room_cache + .write() + .expect("locked") + .entry(room_id.into()) + .or_default() + .insert(appservice.registration.id.clone(), in_room); - knockedcount = knockedcount.saturating_add( - self.room_members_knocked(room_id) - .count() - .await - .try_into() - .unwrap_or(0), - ); + in_room +} - self.db.roomid_joinedcount.raw_put(room_id, joinedcount); - self.db.roomid_invitedcount.raw_put(room_id, invitedcount); - self.db - .roomuserid_knockedcount - .raw_put(room_id, knockedcount); +#[implement(Service)] +pub fn get_appservice_in_room_cache_usage(&self) -> (usize, usize) { + let cache = self.appservice_in_room_cache.read().expect("locked"); - self.room_servers(room_id) - .ready_for_each(|old_joined_server| { - if joined_servers.remove(old_joined_server) { - return; - } + (cache.len(), cache.capacity()) +} - // Server not in room anymore - let roomserver_id = (room_id, old_joined_server); - let serverroom_id = (old_joined_server, room_id); +#[implement(Service)] +#[tracing::instrument(level = "debug", skip_all)] +pub fn clear_appservice_in_room_cache(&self) { + self.appservice_in_room_cache + .write() + .expect("locked") + .clear(); +} - self.db.roomserverids.del(roomserver_id); - self.db.serverroomids.del(serverroom_id); - }) - .await; +/// Returns an iterator of all servers participating in this room. +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn room_servers<'a>( + &'a self, + room_id: &'a RoomId, +) -> impl Stream + Send + 'a { + let prefix = (room_id, Interfix); + self.db + .roomserverids + .keys_prefix(&prefix) + .ignore_err() + .map(|(_, server): (Ignore, &ServerName)| server) +} - // Now only new servers are in joined_servers anymore - for server in &joined_servers { - let roomserver_id = (room_id, server); - let serverroom_id = (server, room_id); +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn server_in_room<'a>(&'a self, server: &'a ServerName, room_id: &'a RoomId) -> bool { + let key = (server, room_id); + self.db.serverroomids.qry(&key).await.is_ok() +} - self.db.roomserverids.put_raw(roomserver_id, []); - self.db.serverroomids.put_raw(serverroom_id, []); - } +/// Returns an iterator of all rooms a server participates in (as far as we +/// know). +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn server_rooms<'a>( + &'a self, + server: &'a ServerName, +) -> impl Stream + Send + 'a { + let prefix = (server, Interfix); + self.db + .serverroomids + .keys_prefix(&prefix) + .ignore_err() + .map(|(_, room_id): (Ignore, &RoomId)| room_id) +} - self.appservice_in_room_cache - .write() - .expect("locked") - .remove(room_id); - } +/// Returns true if server can see user by sharing at least one room. +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn server_sees_user(&self, server: &ServerName, user_id: &UserId) -> bool { + self.server_rooms(server) + .any(|room_id| self.is_joined(user_id, room_id)) + .await +} - #[tracing::instrument(level = "debug", skip(self))] - fn mark_as_once_joined(&self, user_id: &UserId, room_id: &RoomId) { - let key = (user_id, room_id); - self.db.roomuseroncejoinedids.put_raw(key, []); - } +/// Returns true if user_a and user_b share at least one room. +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn user_sees_user(&self, user_a: &UserId, user_b: &UserId) -> bool { + let get_shared_rooms = self.get_shared_rooms(user_a, user_b); - #[tracing::instrument(level = "debug", skip(self, last_state, invite_via))] - pub async fn mark_as_invited( - &self, - user_id: &UserId, - room_id: &RoomId, - last_state: Option>>, - invite_via: Option>, - ) { - let roomuser_id = (room_id, user_id); - let roomuser_id = serialize_key(roomuser_id).expect("failed to serialize roomuser_id"); + pin_mut!(get_shared_rooms); + get_shared_rooms.next().await.is_some() +} - let userroom_id = (user_id, room_id); - let userroom_id = serialize_key(userroom_id).expect("failed to serialize userroom_id"); +/// List the rooms common between two users +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn get_shared_rooms<'a>( + &'a self, + user_a: &'a UserId, + user_b: &'a UserId, +) -> impl Stream + Send + 'a { + use conduwuit::utils::set; - self.db - .userroomid_invitestate - .raw_put(&userroom_id, Json(last_state.unwrap_or_default())); - self.db - .roomuserid_invitecount - .raw_aput::<8, _, _>(&roomuser_id, self.services.globals.next_count().unwrap()); + let a = self.rooms_joined(user_a); + let b = self.rooms_joined(user_b); + set::intersection_sorted_stream2(a, b) +} - self.db.userroomid_joined.remove(&userroom_id); - self.db.roomuserid_joined.remove(&roomuser_id); +/// Returns an iterator of all joined members of a room. +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn room_members<'a>( + &'a self, + room_id: &'a RoomId, +) -> impl Stream + Send + 'a { + let prefix = (room_id, Interfix); + self.db + .roomuserid_joined + .keys_prefix(&prefix) + .ignore_err() + .map(|(_, user_id): (Ignore, &UserId)| user_id) +} - self.db.userroomid_leftstate.remove(&userroom_id); - self.db.roomuserid_leftcount.remove(&roomuser_id); +/// Returns the number of users which are currently in a room +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn room_joined_count(&self, room_id: &RoomId) -> Result { + self.db.roomid_joinedcount.get(room_id).await.deserialized() +} - self.db.userroomid_knockedstate.remove(&userroom_id); - self.db.roomuserid_knockedcount.remove(&roomuser_id); +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +/// Returns an iterator of all our local users in the room, even if they're +/// deactivated/guests +pub fn local_users_in_room<'a>( + &'a self, + room_id: &'a RoomId, +) -> impl Stream + Send + 'a { + self.room_members(room_id) + .ready_filter(|user| self.services.globals.user_is_local(user)) +} - if let Some(servers) = invite_via.filter(is_not_empty!()) { - self.add_servers_invite_via(room_id, servers).await; - } - } +/// Returns an iterator of all our local joined users in a room who are +/// active (not deactivated, not guest) +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub fn active_local_users_in_room<'a>( + &'a self, + room_id: &'a RoomId, +) -> impl Stream + Send + 'a { + self.local_users_in_room(room_id) + .filter(|user| self.services.users.is_active(user)) +} - #[tracing::instrument(level = "debug", skip(self, servers))] - pub async fn add_servers_invite_via(&self, room_id: &RoomId, servers: Vec) { - let mut servers: Vec<_> = self - .servers_invite_via(room_id) - .map(ToOwned::to_owned) - .chain(iter(servers.into_iter())) - .collect() - .await; +/// Returns the number of users which are currently invited to a room +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn room_invited_count(&self, room_id: &RoomId) -> Result { + self.db + .roomid_invitedcount + .get(room_id) + .await + .deserialized() +} - servers.sort_unstable(); - servers.dedup(); +/// Returns an iterator over all User IDs who ever joined a room. +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn room_useroncejoined<'a>( + &'a self, + room_id: &'a RoomId, +) -> impl Stream + Send + 'a { + let prefix = (room_id, Interfix); + self.db + .roomuseroncejoinedids + .keys_prefix(&prefix) + .ignore_err() + .map(|(_, user_id): (Ignore, &UserId)| user_id) +} - let servers = servers - .iter() - .map(|server| server.as_bytes()) - .collect_vec() - .join(&[0xFF][..]); +/// Returns an iterator over all invited members of a room. +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn room_members_invited<'a>( + &'a self, + room_id: &'a RoomId, +) -> impl Stream + Send + 'a { + let prefix = (room_id, Interfix); + self.db + .roomuserid_invitecount + .keys_prefix(&prefix) + .ignore_err() + .map(|(_, user_id): (Ignore, &UserId)| user_id) +} - self.db - .roomid_inviteviaservers - .insert(room_id.as_bytes(), &servers); +/// Returns an iterator over all knocked members of a room. +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn room_members_knocked<'a>( + &'a self, + room_id: &'a RoomId, +) -> impl Stream + Send + 'a { + let prefix = (room_id, Interfix); + self.db + .roomuserid_knockedcount + .keys_prefix(&prefix) + .ignore_err() + .map(|(_, user_id): (Ignore, &UserId)| user_id) +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn get_invite_count(&self, room_id: &RoomId, user_id: &UserId) -> Result { + let key = (room_id, user_id); + self.db + .roomuserid_invitecount + .qry(&key) + .await + .deserialized() +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn get_knock_count(&self, room_id: &RoomId, user_id: &UserId) -> Result { + let key = (room_id, user_id); + self.db + .roomuserid_knockedcount + .qry(&key) + .await + .deserialized() +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result { + let key = (room_id, user_id); + self.db.roomuserid_leftcount.qry(&key).await.deserialized() +} + +/// Returns an iterator over all rooms this user joined. +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn rooms_joined<'a>( + &'a self, + user_id: &'a UserId, +) -> impl Stream + Send + 'a { + self.db + .userroomid_joined + .keys_raw_prefix(user_id) + .ignore_err() + .map(|(_, room_id): (Ignore, &RoomId)| room_id) +} + +/// Returns an iterator over all rooms a user was invited to. +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn rooms_invited<'a>( + &'a self, + user_id: &'a UserId, +) -> impl Stream + Send + 'a { + type KeyVal<'a> = (Key<'a>, Raw>); + type Key<'a> = (&'a UserId, &'a RoomId); + + let prefix = (user_id, Interfix); + self.db + .userroomid_invitestate + .stream_prefix(&prefix) + .ignore_err() + .map(|((_, room_id), state): KeyVal<'_>| (room_id.to_owned(), state)) + .map(|(room_id, state)| Ok((room_id, state.deserialize_as()?))) + .ignore_err() +} + +/// Returns an iterator over all rooms a user is currently knocking. +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub fn rooms_knocked<'a>( + &'a self, + user_id: &'a UserId, +) -> impl Stream + Send + 'a { + type KeyVal<'a> = (Key<'a>, Raw>); + type Key<'a> = (&'a UserId, &'a RoomId); + + let prefix = (user_id, Interfix); + self.db + .userroomid_knockedstate + .stream_prefix(&prefix) + .ignore_err() + .map(|((_, room_id), state): KeyVal<'_>| (room_id.to_owned(), state)) + .map(|(room_id, state)| Ok((room_id, state.deserialize_as()?))) + .ignore_err() +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn invite_state( + &self, + user_id: &UserId, + room_id: &RoomId, +) -> Result>> { + let key = (user_id, room_id); + self.db + .userroomid_invitestate + .qry(&key) + .await + .deserialized() + .and_then(|val: Raw>| val.deserialize_as().map_err(Into::into)) +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn knock_state( + &self, + user_id: &UserId, + room_id: &RoomId, +) -> Result>> { + let key = (user_id, room_id); + self.db + .userroomid_knockedstate + .qry(&key) + .await + .deserialized() + .and_then(|val: Raw>| val.deserialize_as().map_err(Into::into)) +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn left_state( + &self, + user_id: &UserId, + room_id: &RoomId, +) -> Result>> { + let key = (user_id, room_id); + self.db + .userroomid_leftstate + .qry(&key) + .await + .deserialized() + .and_then(|val: Raw>| val.deserialize_as().map_err(Into::into)) +} + +/// Returns an iterator over all rooms a user left. +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn rooms_left<'a>( + &'a self, + user_id: &'a UserId, +) -> impl Stream + Send + 'a { + type KeyVal<'a> = (Key<'a>, Raw>>); + type Key<'a> = (&'a UserId, &'a RoomId); + + let prefix = (user_id, Interfix); + self.db + .userroomid_leftstate + .stream_prefix(&prefix) + .ignore_err() + .map(|((_, room_id), state): KeyVal<'_>| (room_id.to_owned(), state)) + .map(|(room_id, state)| Ok((room_id, state.deserialize_as()?))) + .ignore_err() +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn user_membership( + &self, + user_id: &UserId, + room_id: &RoomId, +) -> Option { + let states = join5( + self.is_joined(user_id, room_id), + self.is_left(user_id, room_id), + self.is_knocked(user_id, room_id), + self.is_invited(user_id, room_id), + self.once_joined(user_id, room_id), + ) + .await; + + match states { + | (true, ..) => Some(MembershipState::Join), + | (_, true, ..) => Some(MembershipState::Leave), + | (_, _, true, ..) => Some(MembershipState::Knock), + | (_, _, _, true, ..) => Some(MembershipState::Invite), + | (false, false, false, false, true) => Some(MembershipState::Ban), + | _ => None, } } + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub async fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> bool { + let key = (user_id, room_id); + self.db.roomuseroncejoinedids.qry(&key).await.is_ok() +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn is_joined<'a>(&'a self, user_id: &'a UserId, room_id: &'a RoomId) -> bool { + let key = (user_id, room_id); + self.db.userroomid_joined.qry(&key).await.is_ok() +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn is_knocked<'a>(&'a self, user_id: &'a UserId, room_id: &'a RoomId) -> bool { + let key = (user_id, room_id); + self.db.userroomid_knockedstate.qry(&key).await.is_ok() +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> bool { + let key = (user_id, room_id); + self.db.userroomid_invitestate.qry(&key).await.is_ok() +} + +#[implement(Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> bool { + let key = (user_id, room_id); + self.db.userroomid_leftstate.qry(&key).await.is_ok() +} diff --git a/src/service/rooms/state_cache/update.rs b/src/service/rooms/state_cache/update.rs new file mode 100644 index 00000000..02c6bec6 --- /dev/null +++ b/src/service/rooms/state_cache/update.rs @@ -0,0 +1,369 @@ +use std::collections::HashSet; + +use conduwuit::{Result, implement, is_not_empty, utils::ReadyExt, warn}; +use database::{Json, serialize_key}; +use futures::StreamExt; +use ruma::{ + OwnedServerName, RoomId, UserId, + events::{ + AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType, + RoomAccountDataEventType, StateEventType, + direct::DirectEvent, + room::{ + create::RoomCreateEventContent, + member::{MembershipState, RoomMemberEventContent}, + }, + }, + serde::Raw, +}; + +/// Update current membership data. +#[implement(super::Service)] +#[tracing::instrument( + level = "debug", + skip_all, + fields( + %room_id, + %user_id, + %sender, + ?membership_event, + ), + )] +#[allow(clippy::too_many_arguments)] +pub async fn update_membership( + &self, + room_id: &RoomId, + user_id: &UserId, + membership_event: RoomMemberEventContent, + sender: &UserId, + last_state: Option>>, + invite_via: Option>, + update_joined_count: bool, +) -> Result { + let membership = membership_event.membership; + + // Keep track what remote users exist by adding them as "deactivated" users + // + // TODO: use futures to update remote profiles without blocking the membership + // update + #[allow(clippy::collapsible_if)] + if !self.services.globals.user_is_local(user_id) { + if !self.services.users.exists(user_id).await { + self.services.users.create(user_id, None)?; + } + } + + match &membership { + | MembershipState::Join => { + // Check if the user never joined this room + if !self.once_joined(user_id, room_id).await { + // Add the user ID to the join list then + self.mark_as_once_joined(user_id, room_id); + + // Check if the room has a predecessor + if let Ok(Some(predecessor)) = self + .services + .state_accessor + .room_state_get_content(room_id, &StateEventType::RoomCreate, "") + .await + .map(|content: RoomCreateEventContent| content.predecessor) + { + // Copy old tags to new room + if let Ok(tag_event) = self + .services + .account_data + .get_room(&predecessor.room_id, user_id, RoomAccountDataEventType::Tag) + .await + { + self.services + .account_data + .update( + Some(room_id), + user_id, + RoomAccountDataEventType::Tag, + &tag_event, + ) + .await + .ok(); + } + + // Copy direct chat flag + if let Ok(mut direct_event) = self + .services + .account_data + .get_global::(user_id, GlobalAccountDataEventType::Direct) + .await + { + let mut room_ids_updated = false; + for room_ids in direct_event.content.0.values_mut() { + if room_ids.iter().any(|r| r == &predecessor.room_id) { + room_ids.push(room_id.to_owned()); + room_ids_updated = true; + } + } + + if room_ids_updated { + self.services + .account_data + .update( + None, + user_id, + GlobalAccountDataEventType::Direct.to_string().into(), + &serde_json::to_value(&direct_event) + .expect("to json always works"), + ) + .await?; + } + } + } + } + + self.mark_as_joined(user_id, room_id); + }, + | MembershipState::Invite => { + // We want to know if the sender is ignored by the receiver + if self.services.users.user_is_ignored(sender, user_id).await { + return Ok(()); + } + + self.mark_as_invited(user_id, room_id, last_state, invite_via) + .await; + }, + | MembershipState::Leave | MembershipState::Ban => { + self.mark_as_left(user_id, room_id); + + if self.services.globals.user_is_local(user_id) + && (self.services.config.forget_forced_upon_leave + || self.services.metadata.is_banned(room_id).await + || self.services.metadata.is_disabled(room_id).await) + { + self.forget(room_id, user_id); + } + }, + | _ => {}, + } + + if update_joined_count { + self.update_joined_count(room_id).await; + } + + Ok(()) +} + +#[implement(super::Service)] +#[tracing::instrument(level = "debug", skip(self))] +pub async fn update_joined_count(&self, room_id: &RoomId) { + let mut joinedcount = 0_u64; + let mut invitedcount = 0_u64; + let mut knockedcount = 0_u64; + let mut joined_servers = HashSet::new(); + + self.room_members(room_id) + .ready_for_each(|joined| { + joined_servers.insert(joined.server_name().to_owned()); + joinedcount = joinedcount.saturating_add(1); + }) + .await; + + invitedcount = invitedcount.saturating_add( + self.room_members_invited(room_id) + .count() + .await + .try_into() + .unwrap_or(0), + ); + + knockedcount = knockedcount.saturating_add( + self.room_members_knocked(room_id) + .count() + .await + .try_into() + .unwrap_or(0), + ); + + self.db.roomid_joinedcount.raw_put(room_id, joinedcount); + self.db.roomid_invitedcount.raw_put(room_id, invitedcount); + self.db + .roomuserid_knockedcount + .raw_put(room_id, knockedcount); + + self.room_servers(room_id) + .ready_for_each(|old_joined_server| { + if joined_servers.remove(old_joined_server) { + return; + } + + // Server not in room anymore + let roomserver_id = (room_id, old_joined_server); + let serverroom_id = (old_joined_server, room_id); + + self.db.roomserverids.del(roomserver_id); + self.db.serverroomids.del(serverroom_id); + }) + .await; + + // Now only new servers are in joined_servers anymore + for server in &joined_servers { + let roomserver_id = (room_id, server); + let serverroom_id = (server, room_id); + + self.db.roomserverids.put_raw(roomserver_id, []); + self.db.serverroomids.put_raw(serverroom_id, []); + } + + self.appservice_in_room_cache + .write() + .expect("locked") + .remove(room_id); +} + +/// Direct DB function to directly mark a user as joined. It is not +/// recommended to use this directly. You most likely should use +/// `update_membership` instead +#[implement(super::Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn mark_as_joined(&self, user_id: &UserId, room_id: &RoomId) { + let userroom_id = (user_id, room_id); + let userroom_id = serialize_key(userroom_id).expect("failed to serialize userroom_id"); + + let roomuser_id = (room_id, user_id); + let roomuser_id = serialize_key(roomuser_id).expect("failed to serialize roomuser_id"); + + self.db.userroomid_joined.insert(&userroom_id, []); + self.db.roomuserid_joined.insert(&roomuser_id, []); + + self.db.userroomid_invitestate.remove(&userroom_id); + self.db.roomuserid_invitecount.remove(&roomuser_id); + + self.db.userroomid_leftstate.remove(&userroom_id); + self.db.roomuserid_leftcount.remove(&roomuser_id); + + self.db.userroomid_knockedstate.remove(&userroom_id); + self.db.roomuserid_knockedcount.remove(&roomuser_id); + + self.db.roomid_inviteviaservers.remove(room_id); +} + +/// Direct DB function to directly mark a user as left. It is not +/// recommended to use this directly. You most likely should use +/// `update_membership` instead +#[implement(super::Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn mark_as_left(&self, user_id: &UserId, room_id: &RoomId) { + let userroom_id = (user_id, room_id); + let userroom_id = serialize_key(userroom_id).expect("failed to serialize userroom_id"); + + let roomuser_id = (room_id, user_id); + let roomuser_id = serialize_key(roomuser_id).expect("failed to serialize roomuser_id"); + + // (timo) TODO + let leftstate = Vec::>::new(); + + self.db + .userroomid_leftstate + .raw_put(&userroom_id, Json(leftstate)); + self.db + .roomuserid_leftcount + .raw_aput::<8, _, _>(&roomuser_id, self.services.globals.next_count().unwrap()); + + self.db.userroomid_joined.remove(&userroom_id); + self.db.roomuserid_joined.remove(&roomuser_id); + + self.db.userroomid_invitestate.remove(&userroom_id); + self.db.roomuserid_invitecount.remove(&roomuser_id); + + self.db.userroomid_knockedstate.remove(&userroom_id); + self.db.roomuserid_knockedcount.remove(&roomuser_id); + + self.db.roomid_inviteviaservers.remove(room_id); +} + +/// Direct DB function to directly mark a user as knocked. It is not +/// recommended to use this directly. You most likely should use +/// `update_membership` instead +#[implement(super::Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn mark_as_knocked( + &self, + user_id: &UserId, + room_id: &RoomId, + knocked_state: Option>>, +) { + let userroom_id = (user_id, room_id); + let userroom_id = serialize_key(userroom_id).expect("failed to serialize userroom_id"); + + let roomuser_id = (room_id, user_id); + let roomuser_id = serialize_key(roomuser_id).expect("failed to serialize roomuser_id"); + + self.db + .userroomid_knockedstate + .raw_put(&userroom_id, Json(knocked_state.unwrap_or_default())); + self.db + .roomuserid_knockedcount + .raw_aput::<8, _, _>(&roomuser_id, self.services.globals.next_count().unwrap()); + + self.db.userroomid_joined.remove(&userroom_id); + self.db.roomuserid_joined.remove(&roomuser_id); + + self.db.userroomid_invitestate.remove(&userroom_id); + self.db.roomuserid_invitecount.remove(&roomuser_id); + + self.db.userroomid_leftstate.remove(&userroom_id); + self.db.roomuserid_leftcount.remove(&roomuser_id); + + self.db.roomid_inviteviaservers.remove(room_id); +} + +/// Makes a user forget a room. +#[implement(super::Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn forget(&self, room_id: &RoomId, user_id: &UserId) { + let userroom_id = (user_id, room_id); + let roomuser_id = (room_id, user_id); + + self.db.userroomid_leftstate.del(userroom_id); + self.db.roomuserid_leftcount.del(roomuser_id); +} + +#[implement(super::Service)] +#[tracing::instrument(level = "debug", skip(self))] +fn mark_as_once_joined(&self, user_id: &UserId, room_id: &RoomId) { + let key = (user_id, room_id); + self.db.roomuseroncejoinedids.put_raw(key, []); +} + +#[implement(super::Service)] +#[tracing::instrument(level = "debug", skip(self, last_state, invite_via))] +pub async fn mark_as_invited( + &self, + user_id: &UserId, + room_id: &RoomId, + last_state: Option>>, + invite_via: Option>, +) { + let roomuser_id = (room_id, user_id); + let roomuser_id = serialize_key(roomuser_id).expect("failed to serialize roomuser_id"); + + let userroom_id = (user_id, room_id); + let userroom_id = serialize_key(userroom_id).expect("failed to serialize userroom_id"); + + self.db + .userroomid_invitestate + .raw_put(&userroom_id, Json(last_state.unwrap_or_default())); + self.db + .roomuserid_invitecount + .raw_aput::<8, _, _>(&roomuser_id, self.services.globals.next_count().unwrap()); + + self.db.userroomid_joined.remove(&userroom_id); + self.db.roomuserid_joined.remove(&roomuser_id); + + self.db.userroomid_leftstate.remove(&userroom_id); + self.db.roomuserid_leftcount.remove(&roomuser_id); + + self.db.userroomid_knockedstate.remove(&userroom_id); + self.db.roomuserid_knockedcount.remove(&roomuser_id); + + if let Some(servers) = invite_via.filter(is_not_empty!()) { + self.add_servers_invite_via(room_id, servers).await; + } +} diff --git a/src/service/rooms/state_cache/via.rs b/src/service/rooms/state_cache/via.rs new file mode 100644 index 00000000..a818cc04 --- /dev/null +++ b/src/service/rooms/state_cache/via.rs @@ -0,0 +1,92 @@ +use conduwuit::{ + Result, implement, + utils::{StreamTools, stream::TryIgnore}, + warn, +}; +use database::Ignore; +use futures::{Stream, StreamExt, stream::iter}; +use itertools::Itertools; +use ruma::{ + OwnedServerName, RoomId, ServerName, + events::{StateEventType, room::power_levels::RoomPowerLevelsEventContent}, + int, +}; + +#[implement(super::Service)] +#[tracing::instrument(level = "debug", skip(self, servers))] +pub async fn add_servers_invite_via(&self, room_id: &RoomId, servers: Vec) { + let mut servers: Vec<_> = self + .servers_invite_via(room_id) + .map(ToOwned::to_owned) + .chain(iter(servers.into_iter())) + .collect() + .await; + + servers.sort_unstable(); + servers.dedup(); + + let servers = servers + .iter() + .map(|server| server.as_bytes()) + .collect_vec() + .join(&[0xFF][..]); + + self.db + .roomid_inviteviaservers + .insert(room_id.as_bytes(), &servers); +} + +/// Gets up to five servers that are likely to be in the room in the +/// distant future. +/// +/// See +#[implement(super::Service)] +#[tracing::instrument(skip(self), level = "trace")] +pub async fn servers_route_via(&self, room_id: &RoomId) -> Result> { + let most_powerful_user_server = self + .services + .state_accessor + .room_state_get_content(room_id, &StateEventType::RoomPowerLevels, "") + .await + .map(|content: RoomPowerLevelsEventContent| { + content + .users + .iter() + .max_by_key(|(_, power)| *power) + .and_then(|x| (x.1 >= &int!(50)).then_some(x)) + .map(|(user, _power)| user.server_name().to_owned()) + }); + + let mut servers: Vec = self + .room_members(room_id) + .counts_by(|user| user.server_name().to_owned()) + .await + .into_iter() + .sorted_by_key(|(_, users)| *users) + .map(|(server, _)| server) + .rev() + .take(5) + .collect(); + + if let Ok(Some(server)) = most_powerful_user_server { + servers.insert(0, server); + servers.truncate(5); + } + + Ok(servers) +} + +#[implement(super::Service)] +#[tracing::instrument(skip(self), level = "debug")] +pub fn servers_invite_via<'a>( + &'a self, + room_id: &'a RoomId, +) -> impl Stream + Send + 'a { + type KeyVal<'a> = (Ignore, Vec<&'a ServerName>); + + self.db + .roomid_inviteviaservers + .stream_raw_prefix(room_id) + .ignore_err() + .map(|(_, servers): KeyVal<'_>| *servers.last().expect("at least one server")) +} From 3c7c641d2d5ff03cd1262675490f79c1aa5b858f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 14 May 2025 00:33:31 +0000 Subject: [PATCH 2105/2291] Add revoke_admin to service. Signed-off-by: Jason Volk --- src/service/admin/grant.rs | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/service/admin/grant.rs b/src/service/admin/grant.rs index 2d90ea52..0d0e3fc1 100644 --- a/src/service/admin/grant.rs +++ b/src/service/admin/grant.rs @@ -170,3 +170,56 @@ async fn set_room_tag(&self, room_id: &RoomId, user_id: &UserId, tag: &str) -> R ) .await } + +/// Demote an admin, removing its rights. +#[implement(super::Service)] +pub async fn revoke_admin(&self, user_id: &UserId) -> Result { + use MembershipState::{Invite, Join, Knock, Leave}; + + let Ok(room_id) = self.get_admin_room().await else { + return Err!(error!("No admin room available or created.")); + }; + + let state_lock = self.services.state.mutex.lock(&room_id).await; + + let event = match self + .services + .state_accessor + .get_member(&room_id, user_id) + .await + { + | Err(e) if e.is_not_found() => return Err!("{user_id} was never an admin."), + + | Err(e) => return Err!(error!(?e, "Failure occurred while attempting revoke.")), + + | Ok(event) if !matches!(event.membership, Invite | Knock | Join) => + return Err!("Cannot revoke {user_id} in membership state {:?}.", event.membership), + + | Ok(event) => { + assert!( + matches!(event.membership, Invite | Knock | Join), + "Incorrect membership state to remove user." + ); + + event + }, + }; + + self.services + .timeline + .build_and_append_pdu( + PduBuilder::state(user_id.to_string(), &RoomMemberEventContent { + membership: Leave, + reason: Some("Admin Revoked".into()), + is_direct: None, + join_authorized_via_users_server: None, + third_party_invite: None, + ..event + }), + self.services.globals.server_user.as_ref(), + &room_id, + &state_lock, + ) + .await + .map(|_| ()) +} From 143cb55ac86d386e7d228a8e4475ad121b906083 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 21 May 2025 23:06:27 +0000 Subject: [PATCH 2106/2291] Fix clippy::unnecessary-unwrap. Signed-off-by: Jason Volk --- src/service/migrations.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/service/migrations.rs b/src/service/migrations.rs index 512a7867..cee638ba 100644 --- a/src/service/migrations.rs +++ b/src/service/migrations.rs @@ -242,12 +242,14 @@ async fn db_lt_12(services: &Services) -> Result<()> { [".m.rules.contains_user_name", ".m.rule.contains_user_name"]; let rule = rules_list.content.get(content_rule_transformation[0]); - if rule.is_some() { - let mut rule = rule.unwrap().clone(); + + if let Some(rule) = rule { + let mut rule = rule.clone(); content_rule_transformation[1].clone_into(&mut rule.rule_id); rules_list .content .shift_remove(content_rule_transformation[0]); + rules_list.content.insert(rule); } } From 293e7243b3c08aaed71b89a16544a5e75b9105dc Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 2 Jul 2025 19:32:50 +0100 Subject: [PATCH 2107/2291] style: Fix formatting/clippy issues --- src/api/client/account.rs | 19 +++++++++++++++---- src/api/client/membership/join.rs | 2 +- src/api/client/report.rs | 1 - src/service/rooms/timeline/append.rs | 8 +++++--- src/service/rooms/timeline/create.rs | 2 +- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/api/client/account.rs b/src/api/client/account.rs index df938c17..12801e7d 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -12,14 +12,25 @@ use conduwuit_service::Services; use futures::{FutureExt, StreamExt}; use register::RegistrationKind; use ruma::{ + OwnedRoomId, UserId, api::client::{ account::{ - change_password, check_registration_token_validity, deactivate, get_3pids, get_username_availability, register::{self, LoginType}, request_3pid_management_token_via_email, request_3pid_management_token_via_msisdn, whoami, ThirdPartyIdRemovalStatus + ThirdPartyIdRemovalStatus, change_password, check_registration_token_validity, + deactivate, get_3pids, get_username_availability, + register::{self, LoginType}, + request_3pid_management_token_via_email, request_3pid_management_token_via_msisdn, + whoami, }, uiaa::{AuthFlow, AuthType, UiaaInfo}, - }, events::{ - room::{message::RoomMessageEventContent, power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent}}, GlobalAccountDataEventType, StateEventType - }, push, OwnedRoomId, UserId + }, + events::{ + GlobalAccountDataEventType, StateEventType, + room::{ + message::RoomMessageEventContent, + power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent}, + }, + }, + push, }; use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH, join_room_by_id_helper}; diff --git a/src/api/client/membership/join.rs b/src/api/client/membership/join.rs index 9d19d3bc..dc170cbf 100644 --- a/src/api/client/membership/join.rs +++ b/src/api/client/membership/join.rs @@ -139,7 +139,7 @@ pub(crate) async fn join_room_by_id_or_alias_route( let sender_user = body.sender_user(); let appservice_info = &body.appservice_info; let body = &body.body; - if services.users.is_suspended(sender_user).await? { + if services.users.is_suspended(sender_user).await? { return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); } diff --git a/src/api/client/report.rs b/src/api/client/report.rs index 052329d1..60a16e1a 100644 --- a/src/api/client/report.rs +++ b/src/api/client/report.rs @@ -8,7 +8,6 @@ use rand::Rng; use ruma::{ EventId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId, api::client::{ - error::ErrorKind, report_user, room::{report_content, report_room}, }, diff --git a/src/service/rooms/timeline/append.rs b/src/service/rooms/timeline/append.rs index a7b558c2..1d404e8a 100644 --- a/src/service/rooms/timeline/append.rs +++ b/src/service/rooms/timeline/append.rs @@ -348,9 +348,11 @@ where self.services.search.index_pdu(shortroomid, &pdu_id, &body); if self.services.admin.is_admin_command(pdu, &body).await { - self.services - .admin - .command_with_sender(body, Some((pdu.event_id()).into()), pdu.sender.clone().into())?; + self.services.admin.command_with_sender( + body, + Some((pdu.event_id()).into()), + pdu.sender.clone().into(), + )?; } } }, diff --git a/src/service/rooms/timeline/create.rs b/src/service/rooms/timeline/create.rs index d890e88e..20ccaf56 100644 --- a/src/service/rooms/timeline/create.rs +++ b/src/service/rooms/timeline/create.rs @@ -110,7 +110,7 @@ pub async fn create_hash_and_sign_event( // so any other events with that same depth are illegal. warn!( "Had unsafe depth {depth} when creating non-state event in {room_id}. Cowardly \ - aborting" + aborting" ); return Err!(Request(Unknown("Unsafe depth for non-state event."))); } From 7e406445d415f87ee3ce03fe82193fbf4e128e21 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Thu, 3 Jul 2025 22:26:02 +0100 Subject: [PATCH 2108/2291] Element Web build fixes --- .forgejo/workflows/element.yml | 35 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/.forgejo/workflows/element.yml b/.forgejo/workflows/element.yml index db771197..0199e8b6 100644 --- a/.forgejo/workflows/element.yml +++ b/.forgejo/workflows/element.yml @@ -11,16 +11,16 @@ concurrency: jobs: build-and-deploy: - name: Build and Deploy Element Web + name: 🏗️ Build and Deploy runs-on: ubuntu-latest steps: - - name: Setup Node.js - uses: https://code.forgejo.org/actions/setup-node@v4 + - name: 📦 Setup Node.js + uses: https://github.com/actions/setup-node@v4 with: - node-version: "20" + node-version: "22" - - name: Clone, setup, and build Element Web + - name: 🔨 Clone, setup, and build Element Web run: | echo "Cloning Element Web..." git clone https://github.com/maunium/element-web @@ -64,7 +64,7 @@ jobs: echo "Checking for build output..." ls -la webapp/ - - name: Create config.json + - name: ⚙️ Create config.json run: | cat < ./element-web/webapp/config.json { @@ -100,28 +100,25 @@ jobs: echo "Created ./element-web/webapp/config.json" cat ./element-web/webapp/config.json - - name: Upload Artifact + - name: 📤 Upload Artifact uses: https://code.forgejo.org/actions/upload-artifact@v3 with: name: element-web path: ./element-web/webapp/ retention-days: 14 - - name: Install Wrangler + - name: 🛠️ Install Wrangler run: npm install --save-dev wrangler@latest - - name: Deploy to Cloudflare Pages (Production) - if: github.ref == 'refs/heads/main' && vars.CLOUDFLARE_PROJECT_NAME != '' + - name: 🚀 Deploy to Cloudflare Pages + if: vars.CLOUDFLARE_PROJECT_NAME != '' + id: deploy uses: https://github.com/cloudflare/wrangler-action@v3 with: accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - command: pages deploy ./element-web/webapp --branch="main" --commit-dirty=true --project-name="${{ vars.CLOUDFLARE_PROJECT_NAME }}-element" - - - name: Deploy to Cloudflare Pages (Preview) - if: github.ref != 'refs/heads/main' && vars.CLOUDFLARE_PROJECT_NAME != '' - uses: https://github.com/cloudflare/wrangler-action@v3 - with: - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - command: pages deploy ./element-web/webapp --branch="${{ github.head_ref || github.ref_name }}" --commit-dirty=true --project-name="${{ vars.CLOUDFLARE_PROJECT_NAME }}-element" + command: >- + pages deploy ./element-web/webapp + --branch="${{ github.ref == 'refs/heads/main' && 'main' || github.head_ref || github.ref_name }}" + --commit-dirty=true + --project-name="${{ vars.CLOUDFLARE_PROJECT_NAME }}-element" From 52954c5b75f2ac4af62a30a9f44d527bd0511801 Mon Sep 17 00:00:00 2001 From: Nyx Date: Sun, 6 Jul 2025 14:00:42 -0500 Subject: [PATCH 2109/2291] Even more renaming --- src/admin/debug/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index bceee9ba..fb8a3002 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -32,13 +32,13 @@ pub(super) enum DebugCommand { /// the command. ParsePdu, - /// - Retrieve and print a PDU by EventID from the conduwuit database + /// - Retrieve and print a PDU by EventID from the Continuwuity database GetPdu { /// An event ID (a $ followed by the base64 reference hash) event_id: OwnedEventId, }, - /// - Retrieve and print a PDU by PduId from the conduwuit database + /// - Retrieve and print a PDU by PduId from the Continuwuity database GetShortPdu { /// Shortroomid integer shortroomid: ShortRoomId, @@ -182,7 +182,7 @@ pub(super) enum DebugCommand { event_id: Option, }, - /// - Runs a server name through conduwuit's true destination resolution + /// - Runs a server name through Continuwuity's true destination resolution /// process /// /// Useful for debugging well-known issues From af8783ee51e828b9af8cbe31ddeaef3cd4e9d137 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 6 Jul 2025 21:15:49 +0100 Subject: [PATCH 2110/2291] ci: Mirror registry images --- .forgejo/regsync/regsync.yml | 55 ++++++++++++++++++++++++++++ .forgejo/workflows/mirror-images.yml | 47 ++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 .forgejo/regsync/regsync.yml create mode 100644 .forgejo/workflows/mirror-images.yml diff --git a/.forgejo/regsync/regsync.yml b/.forgejo/regsync/regsync.yml new file mode 100644 index 00000000..0a14db45 --- /dev/null +++ b/.forgejo/regsync/regsync.yml @@ -0,0 +1,55 @@ +version: 1 + +x-source: &source forgejo.ellis.link/continuwuation/continuwuity + +x-tags: + releases: &tags-releases + tags: + allow: + - "latest" + - "v[0-9]+\\.[0-9]+\\.[0-9]+" + - "v[0-9]+\\.[0-9]+" + - "v[0-9]+" + main: &tags-main + tags: + allow: + - "latest" + - "v[0-9]+\\.[0-9]+\\.[0-9]+" + - "v[0-9]+\\.[0-9]+" + - "v[0-9]+" + - "main" + commits: &tags-commits + tags: + allow: + - "latest" + - "v[0-9]+\\.[0-9]+\\.[0-9]+" + - "v[0-9]+\\.[0-9]+" + - "v[0-9]+" + - "main" + - "sha-[a-f0-9]+" + all: &tags-all + tags: + allow: + - ".*" + +# Registry credentials +creds: + - registry: forgejo.ellis.link + user: "{{env \"BUILTIN_REGISTRY_USER\"}}" + pass: "{{env \"BUILTIN_REGISTRY_PASSWORD\"}}" + - registry: registry.gitlab.com + user: "{{env \"GITLAB_USERNAME\"}}" + pass: "{{env \"GITLAB_TOKEN\"}}" + +# Global defaults +defaults: + parallel: 3 + interval: 2h + digestTags: true + +# Sync configuration - each registry gets different image sets +sync: + - source: *source + target: registry.gitlab.com/continuwuity/continuwuity + type: repository + <<: *tags-main diff --git a/.forgejo/workflows/mirror-images.yml b/.forgejo/workflows/mirror-images.yml new file mode 100644 index 00000000..51f60e75 --- /dev/null +++ b/.forgejo/workflows/mirror-images.yml @@ -0,0 +1,47 @@ +name: Mirror Container Images + +on: + schedule: + # Run every 2 hours + - cron: "0 */2 * * *" + workflow_dispatch: + inputs: + dry_run: + description: 'Dry run (check only, no actual mirroring)' + required: false + default: false + type: boolean + +concurrency: + group: "mirror-images" + cancel-in-progress: true + +jobs: + mirror-images: + runs-on: ubuntu-latest + env: + BUILTIN_REGISTRY_USER: ${{ secrets.BUILTIN_REGISTRY_USER }} + BUILTIN_REGISTRY_PASSWORD: ${{ secrets.BUILTIN_REGISTRY_PASSWORD }} + GITLAB_USERNAME: ${{ secrets.GITLAB_USERNAME }} + GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Install regctl + uses: https://forgejo.ellis.link/continuwuation/regclient-actions/regctl-installer@main + with: + binary: regsync + + - name: Check what images need mirroring + run: | + echo "Checking images that need mirroring..." + regsync check -c .forgejo/regsync/regsync.yml -v info + + - name: Mirror images + if: ${{ !inputs.dry_run }} + run: | + echo "Starting image mirroring..." + regsync once -c .forgejo/regsync/regsync.yml -v info From 928b7c5e4a8d30c53941703fabf4467d17df412c Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 6 Jul 2025 22:57:33 +0100 Subject: [PATCH 2111/2291] fix: Correct vars --- .forgejo/workflows/mirror-images.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.forgejo/workflows/mirror-images.yml b/.forgejo/workflows/mirror-images.yml index 51f60e75..198832db 100644 --- a/.forgejo/workflows/mirror-images.yml +++ b/.forgejo/workflows/mirror-images.yml @@ -20,9 +20,9 @@ jobs: mirror-images: runs-on: ubuntu-latest env: - BUILTIN_REGISTRY_USER: ${{ secrets.BUILTIN_REGISTRY_USER }} + BUILTIN_REGISTRY_USER: ${{ vars.BUILTIN_REGISTRY_USER }} BUILTIN_REGISTRY_PASSWORD: ${{ secrets.BUILTIN_REGISTRY_PASSWORD }} - GITLAB_USERNAME: ${{ secrets.GITLAB_USERNAME }} + GITLAB_USERNAME: ${{ vars.GITLAB_USERNAME }} GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} steps: - name: Checkout repository From 18d12a7756620b14be48f9b37fc6e2ef6fa892ff Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 22 May 2025 13:19:30 +0100 Subject: [PATCH 2112/2291] feat: Support logging to journald with tracing-journald This stubs out on non-unix platforms. --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 2 ++ arch/conduwuit.service | 4 ++++ conduwuit-example.toml | 9 +++++++++ debian/conduwuit.service | 3 +++ src/core/config/mod.rs | 18 ++++++++++++++++++ src/main/Cargo.toml | 7 +++++++ src/main/logging.rs | 37 ++++++++++++++++++++++++++++++++++++- 8 files changed, 91 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 82e7a20d..5a65a729 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -797,6 +797,7 @@ dependencies = [ "tokio-metrics", "tracing", "tracing-flame", + "tracing-journald", "tracing-opentelemetry", "tracing-subscriber", ] @@ -5178,6 +5179,17 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-journald" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0b4143302cf1022dac868d521e36e8b27691f72c84b3311750d5188ebba657" +dependencies = [ + "libc", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "tracing-log" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index b815e2b8..75e15233 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -213,6 +213,8 @@ default-features = false version = "0.3.19" default-features = false features = ["env-filter", "std", "tracing", "tracing-log", "ansi", "fmt"] +[workspace.dependencies.tracing-journald] +version = "0.3.1" [workspace.dependencies.tracing-core] version = "0.1.33" default-features = false diff --git a/arch/conduwuit.service b/arch/conduwuit.service index d5a65e4d..b66bc1da 100644 --- a/arch/conduwuit.service +++ b/arch/conduwuit.service @@ -17,6 +17,10 @@ DeviceAllow=char-tty StandardInput=tty-force StandardOutput=tty StandardError=journal+console + +Environment="CONTINUWUITY_LOG_TO_JOURNALD=1" +Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N" + TTYReset=yes # uncomment to allow buffer to be cleared every restart TTYVTDisallocate=no diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 794ab870..1e403bba 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -671,6 +671,15 @@ # #log_thread_ids = false +# Enable journald logging on Unix platforms +# +#log_to_journald = false + +# The syslog identifier to use with journald logging +# Only used when journald logging is enabled +# +#journald_identifier = "conduwuit" + # OpenID token expiration/TTL in seconds. # # These are the OpenID tokens that are primarily used for Matrix account diff --git a/debian/conduwuit.service b/debian/conduwuit.service index be2f3dae..b95804d3 100644 --- a/debian/conduwuit.service +++ b/debian/conduwuit.service @@ -14,6 +14,9 @@ Type=notify Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml" +Environment="CONTINUWUITY_LOG_TO_JOURNALD=1" +Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N" + ExecStart=/usr/sbin/conduwuit ReadWritePaths=/var/lib/conduwuit /etc/conduwuit diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index e3db4900..6b054bd6 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -811,6 +811,24 @@ pub struct Config { #[serde(default)] pub log_thread_ids: bool, + /// Enable journald logging on Unix platforms + /// + /// When enabled, log output will be sent to the systemd journal + /// This is only supported on Unix platforms + /// + /// default: false + #[cfg(target_family = "unix")] + #[serde(default)] + pub log_to_journald: bool, + + /// The syslog identifier to use with journald logging + /// + /// Only used when journald logging is enabled + /// + /// Defaults to the binary name + #[cfg(target_family = "unix")] + pub journald_identifier: Option, + /// OpenID token expiration/TTL in seconds. /// /// These are the OpenID tokens that are primarily used for Matrix account diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 0c5e2b6f..2d8d26b5 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -43,6 +43,7 @@ default = [ "io_uring", "jemalloc", "jemalloc_conf", + "journald", "media_thumbnail", "release_max_log_level", "systemd", @@ -130,6 +131,11 @@ sentry_telemetry = [ systemd = [ "conduwuit-router/systemd", ] +journald = [ # This is a stub on non-unix platforms + "dep:tracing-journald", +] + + # enable the tokio_console server ncompatible with release_max_log_level tokio_console = [ "dep:console-subscriber", @@ -183,6 +189,7 @@ tracing-opentelemetry.optional = true tracing-opentelemetry.workspace = true tracing-subscriber.workspace = true tracing.workspace = true +tracing-journald = { workspace = true, optional = true } [target.'cfg(all(not(target_env = "msvc"), target_os = "linux"))'.dependencies] hardened_malloc-rs.workspace = true diff --git a/src/main/logging.rs b/src/main/logging.rs index 36a8896c..b7beb103 100644 --- a/src/main/logging.rs +++ b/src/main/logging.rs @@ -46,6 +46,16 @@ pub(crate) fn init( .with(console_layer.with_filter(console_reload_filter)) .with(cap_layer); + // If journald logging is enabled on Unix platforms, create a separate + // subscriber for it + #[cfg(all(target_family = "unix", feature = "journald"))] + if config.log_to_journald { + println!("Initialising journald logging"); + if let Err(e) = init_journald_logging(config) { + eprintln!("Failed to initialize journald logging: {e}"); + } + } + #[cfg(feature = "sentry_telemetry")] let subscriber = { let sentry_filter = EnvFilter::try_new(&config.sentry_filter) @@ -135,6 +145,28 @@ pub(crate) fn init( Ok(ret) } +#[cfg(all(target_family = "unix", feature = "journald"))] +fn init_journald_logging(config: &Config) -> Result<()> { + use tracing_journald::Layer as JournaldLayer; + + let journald_filter = + EnvFilter::try_new(&config.log).map_err(|e| err!(Config("log", "{e}.")))?; + + let mut journald_layer = JournaldLayer::new() + .map_err(|e| err!(Config("journald", "Failed to initialize journald layer: {e}.")))?; + + if let Some(ref identifier) = config.journald_identifier { + journald_layer = journald_layer.with_syslog_identifier(identifier.to_owned()); + } + + let journald_subscriber = + Registry::default().with(journald_layer.with_filter(journald_filter)); + + let _guard = tracing::subscriber::set_default(journald_subscriber); + + Ok(()) +} + fn tokio_console_enabled(config: &Config) -> (bool, &'static str) { if !cfg!(all(feature = "tokio_console", tokio_unstable)) { return (false, ""); @@ -154,7 +186,10 @@ fn tokio_console_enabled(config: &Config) -> (bool, &'static str) { (true, "") } -fn set_global_default(subscriber: S) { +fn set_global_default(subscriber: S) +where + S: tracing::Subscriber + Send + Sync + 'static, +{ tracing::subscriber::set_global_default(subscriber) .expect("the global default tracing subscriber failed to be initialized"); } From d98ce2c7b9ff248989bea363907ba4709743febd Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 24 May 2025 00:28:09 +0100 Subject: [PATCH 2113/2291] feat: Generate admin command documentation The first part of getting admin command docs on the website. There's also the beginnings of manpage generation here, although it's kinda sus and I'm not sure how it's supposed to work. I'll leave that to anyone who wants to package it. We introduce the beginings of the xtask pattern here - we do a lot of file generation, I thought it would be best to avoid doing that on every compilation. It also helps avoid lots of runtime deps. We'll need to document generating this stuff & probably add pre-commit hooks for it, though. --- .cargo/config.toml | 2 + Cargo.lock | 121 + Cargo.toml | 10 +- conduwuit-example.toml | 13 +- docs/SUMMARY.md | 1 + docs/admin_reference.md | 2658 ++++++++++++++++++++++ src/admin/admin.rs | 2 +- src/admin/appservice/mod.rs | 2 +- src/admin/check/mod.rs | 2 +- src/admin/debug/mod.rs | 2 +- src/admin/debug/tester.rs | 2 +- src/admin/federation/mod.rs | 2 +- src/admin/media/mod.rs | 6 +- src/admin/mod.rs | 2 + src/admin/query/account_data.rs | 2 +- src/admin/query/appservice.rs | 2 +- src/admin/query/globals.rs | 2 +- src/admin/query/mod.rs | 2 +- src/admin/query/presence.rs | 2 +- src/admin/query/pusher.rs | 2 +- src/admin/query/raw.rs | 2 +- src/admin/query/resolver.rs | 2 +- src/admin/query/room_alias.rs | 2 +- src/admin/query/room_state_cache.rs | 2 +- src/admin/query/room_timeline.rs | 2 +- src/admin/query/sending.rs | 2 +- src/admin/query/short.rs | 2 +- src/admin/query/users.rs | 2 +- src/admin/room/alias.rs | 2 +- src/admin/room/directory.rs | 2 +- src/admin/room/info.rs | 2 +- src/admin/room/mod.rs | 2 +- src/admin/room/moderation.rs | 2 +- src/admin/server/mod.rs | 2 +- src/admin/user/mod.rs | 2 +- src/main/Cargo.toml | 7 + src/main/mod.rs | 14 + xtask/generate-admin-command/Cargo.toml | 26 + xtask/generate-admin-command/src/main.rs | 63 + xtask/main/Cargo.toml | 22 + xtask/main/src/main.rs | 11 + 41 files changed, 2977 insertions(+), 33 deletions(-) create mode 100644 .cargo/config.toml create mode 100644 docs/admin_reference.md create mode 100644 src/main/mod.rs create mode 100644 xtask/generate-admin-command/Cargo.toml create mode 100644 xtask/generate-admin-command/src/main.rs create mode 100644 xtask/main/Cargo.toml create mode 100644 xtask/main/src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..35049cbc --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[alias] +xtask = "run --package xtask --" diff --git a/Cargo.lock b/Cargo.lock index 5a65a729..fe8cb16d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,12 +50,56 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + [[package]] name = "anstyle" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6680de5231bd6ee4c6191b8a1325daa282b415391ec9d3a37bd34f2060dc73fa" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.59.0", +] + [[package]] name = "anyhow" version = "1.0.98" @@ -720,14 +764,25 @@ dependencies = [ "clap_derive", ] +[[package]] +name = "clap-markdown" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2a2617956a06d4885b490697b5307ebb09fec10b088afc18c81762d848c2339" +dependencies = [ + "clap", +] + [[package]] name = "clap_builder" version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" dependencies = [ + "anstream", "anstyle", "clap_lex", + "strsim", ] [[package]] @@ -748,6 +803,16 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" +[[package]] +name = "clap_mangen" +version = "0.2.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "724842fa9b144f9b89b3f3d371a89f3455eea660361d13a554f68f8ae5d6c13a" +dependencies = [ + "clap", + "roff", +] + [[package]] name = "cmake" version = "0.1.54" @@ -763,6 +828,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -2399,6 +2470,12 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.12.1" @@ -3007,6 +3084,12 @@ dependencies = [ "portable-atomic", ] +[[package]] +name = "once_cell_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" + [[package]] name = "openssl-probe" version = "0.1.6" @@ -3796,6 +3879,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "roff" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88f8660c1ff60292143c98d08fc6e2f654d722db50410e3f3797d40baaf9d8f3" + [[package]] name = "ruma" version = "0.10.1" @@ -4637,6 +4726,12 @@ dependencies = [ "quote", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "subslice" version = "0.2.3" @@ -5367,6 +5462,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.17.0" @@ -6018,6 +6119,26 @@ dependencies = [ "markup5ever", ] +[[package]] +name = "xtask" +version = "0.5.0-rc.6" +dependencies = [ + "clap", + "serde", + "serde_json", +] + +[[package]] +name = "xtask-admin-command" +version = "0.5.0-rc.6" +dependencies = [ + "clap-markdown", + "clap_builder", + "clap_mangen", + "conduwuit", + "conduwuit_admin", +] + [[package]] name = "yansi" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index 75e15233..03c5b489 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [workspace] resolver = "2" -members = ["src/*"] +members = ["src/*", "xtask/*"] default-members = ["src/*"] [workspace.package] @@ -638,6 +638,11 @@ package = "conduwuit_build_metadata" path = "src/build_metadata" default-features = false + +[workspace.dependencies.conduwuit] +package = "conduwuit" +path = "src/main" + ############################################################################### # # Release profiles @@ -763,7 +768,8 @@ inherits = "dev" # '-Clink-arg=-Wl,-z,nodlopen', # '-Clink-arg=-Wl,-z,nodelete', #] - +[profile.dev.package.xtask-admin-command] +inherits = "dev" [profile.dev.package.conduwuit] inherits = "dev" #rustflags = [ diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 1e403bba..22ad669b 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -407,6 +407,11 @@ # invites, or create/join or otherwise modify rooms. # They are effectively read-only. # +# If you want to use this to screen people who register on your server, +# you should add a room to `auto_join_rooms` that is public, and contains +# information that new users can read (since they won't be able to DM +# anyone, or send a message, and may be confused). +# #suspend_on_register = false # Enabling this setting opens registration to anyone without restrictions. @@ -673,12 +678,18 @@ # Enable journald logging on Unix platforms # +# When enabled, log output will be sent to the systemd journal +# This is only supported on Unix platforms +# #log_to_journald = false # The syslog identifier to use with journald logging +# # Only used when journald logging is enabled # -#journald_identifier = "conduwuit" +# Defaults to the binary name +# +#journald_identifier = # OpenID token expiration/TTL in seconds. # diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index af729003..b38009a1 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -15,6 +15,7 @@ - [Appservices](appservices.md) - [Maintenance](maintenance.md) - [Troubleshooting](troubleshooting.md) +- [Admin Command Reference](admin_reference.md) - [Development](development.md) - [Contributing](contributing.md) - [Testing](development/testing.md) diff --git a/docs/admin_reference.md b/docs/admin_reference.md new file mode 100644 index 00000000..18e039e4 --- /dev/null +++ b/docs/admin_reference.md @@ -0,0 +1,2658 @@ +# Command-Line Help for `admin` + +This document contains the help content for the `admin` command-line program. + +**Command Overview:** + +* [`admin`↴](#admin) +* [`admin appservices`↴](#admin-appservices) +* [`admin appservices register`↴](#admin-appservices-register) +* [`admin appservices unregister`↴](#admin-appservices-unregister) +* [`admin appservices show-appservice-config`↴](#admin-appservices-show-appservice-config) +* [`admin appservices list-registered`↴](#admin-appservices-list-registered) +* [`admin users`↴](#admin-users) +* [`admin users create-user`↴](#admin-users-create-user) +* [`admin users reset-password`↴](#admin-users-reset-password) +* [`admin users deactivate`↴](#admin-users-deactivate) +* [`admin users deactivate-all`↴](#admin-users-deactivate-all) +* [`admin users suspend`↴](#admin-users-suspend) +* [`admin users unsuspend`↴](#admin-users-unsuspend) +* [`admin users list-users`↴](#admin-users-list-users) +* [`admin users list-joined-rooms`↴](#admin-users-list-joined-rooms) +* [`admin users force-join-room`↴](#admin-users-force-join-room) +* [`admin users force-leave-room`↴](#admin-users-force-leave-room) +* [`admin users force-demote`↴](#admin-users-force-demote) +* [`admin users make-user-admin`↴](#admin-users-make-user-admin) +* [`admin users put-room-tag`↴](#admin-users-put-room-tag) +* [`admin users delete-room-tag`↴](#admin-users-delete-room-tag) +* [`admin users get-room-tags`↴](#admin-users-get-room-tags) +* [`admin users redact-event`↴](#admin-users-redact-event) +* [`admin users force-join-list-of-local-users`↴](#admin-users-force-join-list-of-local-users) +* [`admin users force-join-all-local-users`↴](#admin-users-force-join-all-local-users) +* [`admin rooms`↴](#admin-rooms) +* [`admin rooms list-rooms`↴](#admin-rooms-list-rooms) +* [`admin rooms info`↴](#admin-rooms-info) +* [`admin rooms info list-joined-members`↴](#admin-rooms-info-list-joined-members) +* [`admin rooms info view-room-topic`↴](#admin-rooms-info-view-room-topic) +* [`admin rooms moderation`↴](#admin-rooms-moderation) +* [`admin rooms moderation ban-room`↴](#admin-rooms-moderation-ban-room) +* [`admin rooms moderation ban-list-of-rooms`↴](#admin-rooms-moderation-ban-list-of-rooms) +* [`admin rooms moderation unban-room`↴](#admin-rooms-moderation-unban-room) +* [`admin rooms moderation list-banned-rooms`↴](#admin-rooms-moderation-list-banned-rooms) +* [`admin rooms alias`↴](#admin-rooms-alias) +* [`admin rooms alias set`↴](#admin-rooms-alias-set) +* [`admin rooms alias remove`↴](#admin-rooms-alias-remove) +* [`admin rooms alias which`↴](#admin-rooms-alias-which) +* [`admin rooms alias list`↴](#admin-rooms-alias-list) +* [`admin rooms directory`↴](#admin-rooms-directory) +* [`admin rooms directory publish`↴](#admin-rooms-directory-publish) +* [`admin rooms directory unpublish`↴](#admin-rooms-directory-unpublish) +* [`admin rooms directory list`↴](#admin-rooms-directory-list) +* [`admin rooms exists`↴](#admin-rooms-exists) +* [`admin federation`↴](#admin-federation) +* [`admin federation incoming-federation`↴](#admin-federation-incoming-federation) +* [`admin federation disable-room`↴](#admin-federation-disable-room) +* [`admin federation enable-room`↴](#admin-federation-enable-room) +* [`admin federation fetch-support-well-known`↴](#admin-federation-fetch-support-well-known) +* [`admin federation remote-user-in-rooms`↴](#admin-federation-remote-user-in-rooms) +* [`admin server`↴](#admin-server) +* [`admin server uptime`↴](#admin-server-uptime) +* [`admin server show-config`↴](#admin-server-show-config) +* [`admin server reload-config`↴](#admin-server-reload-config) +* [`admin server list-features`↴](#admin-server-list-features) +* [`admin server memory-usage`↴](#admin-server-memory-usage) +* [`admin server clear-caches`↴](#admin-server-clear-caches) +* [`admin server backup-database`↴](#admin-server-backup-database) +* [`admin server list-backups`↴](#admin-server-list-backups) +* [`admin server admin-notice`↴](#admin-server-admin-notice) +* [`admin server reload-mods`↴](#admin-server-reload-mods) +* [`admin server restart`↴](#admin-server-restart) +* [`admin server shutdown`↴](#admin-server-shutdown) +* [`admin media`↴](#admin-media) +* [`admin media delete`↴](#admin-media-delete) +* [`admin media delete-list`↴](#admin-media-delete-list) +* [`admin media delete-past-remote-media`↴](#admin-media-delete-past-remote-media) +* [`admin media delete-all-from-user`↴](#admin-media-delete-all-from-user) +* [`admin media delete-all-from-server`↴](#admin-media-delete-all-from-server) +* [`admin media get-file-info`↴](#admin-media-get-file-info) +* [`admin media get-remote-file`↴](#admin-media-get-remote-file) +* [`admin media get-remote-thumbnail`↴](#admin-media-get-remote-thumbnail) +* [`admin check`↴](#admin-check) +* [`admin check check-all-users`↴](#admin-check-check-all-users) +* [`admin debug`↴](#admin-debug) +* [`admin debug echo`↴](#admin-debug-echo) +* [`admin debug get-auth-chain`↴](#admin-debug-get-auth-chain) +* [`admin debug parse-pdu`↴](#admin-debug-parse-pdu) +* [`admin debug get-pdu`↴](#admin-debug-get-pdu) +* [`admin debug get-short-pdu`↴](#admin-debug-get-short-pdu) +* [`admin debug get-remote-pdu`↴](#admin-debug-get-remote-pdu) +* [`admin debug get-remote-pdu-list`↴](#admin-debug-get-remote-pdu-list) +* [`admin debug get-room-state`↴](#admin-debug-get-room-state) +* [`admin debug get-signing-keys`↴](#admin-debug-get-signing-keys) +* [`admin debug get-verify-keys`↴](#admin-debug-get-verify-keys) +* [`admin debug ping`↴](#admin-debug-ping) +* [`admin debug force-device-list-updates`↴](#admin-debug-force-device-list-updates) +* [`admin debug change-log-level`↴](#admin-debug-change-log-level) +* [`admin debug sign-json`↴](#admin-debug-sign-json) +* [`admin debug verify-json`↴](#admin-debug-verify-json) +* [`admin debug verify-pdu`↴](#admin-debug-verify-pdu) +* [`admin debug first-pdu-in-room`↴](#admin-debug-first-pdu-in-room) +* [`admin debug latest-pdu-in-room`↴](#admin-debug-latest-pdu-in-room) +* [`admin debug force-set-room-state-from-server`↴](#admin-debug-force-set-room-state-from-server) +* [`admin debug resolve-true-destination`↴](#admin-debug-resolve-true-destination) +* [`admin debug memory-stats`↴](#admin-debug-memory-stats) +* [`admin debug runtime-metrics`↴](#admin-debug-runtime-metrics) +* [`admin debug runtime-interval`↴](#admin-debug-runtime-interval) +* [`admin debug time`↴](#admin-debug-time) +* [`admin debug list-dependencies`↴](#admin-debug-list-dependencies) +* [`admin debug database-stats`↴](#admin-debug-database-stats) +* [`admin debug trim-memory`↴](#admin-debug-trim-memory) +* [`admin debug database-files`↴](#admin-debug-database-files) +* [`admin query`↴](#admin-query) +* [`admin query account-data`↴](#admin-query-account-data) +* [`admin query account-data changes-since`↴](#admin-query-account-data-changes-since) +* [`admin query account-data account-data-get`↴](#admin-query-account-data-account-data-get) +* [`admin query appservice`↴](#admin-query-appservice) +* [`admin query appservice get-registration`↴](#admin-query-appservice-get-registration) +* [`admin query appservice all`↴](#admin-query-appservice-all) +* [`admin query presence`↴](#admin-query-presence) +* [`admin query presence get-presence`↴](#admin-query-presence-get-presence) +* [`admin query presence presence-since`↴](#admin-query-presence-presence-since) +* [`admin query room-alias`↴](#admin-query-room-alias) +* [`admin query room-alias resolve-local-alias`↴](#admin-query-room-alias-resolve-local-alias) +* [`admin query room-alias local-aliases-for-room`↴](#admin-query-room-alias-local-aliases-for-room) +* [`admin query room-alias all-local-aliases`↴](#admin-query-room-alias-all-local-aliases) +* [`admin query room-state-cache`↴](#admin-query-room-state-cache) +* [`admin query room-state-cache server-in-room`↴](#admin-query-room-state-cache-server-in-room) +* [`admin query room-state-cache room-servers`↴](#admin-query-room-state-cache-room-servers) +* [`admin query room-state-cache server-rooms`↴](#admin-query-room-state-cache-server-rooms) +* [`admin query room-state-cache room-members`↴](#admin-query-room-state-cache-room-members) +* [`admin query room-state-cache local-users-in-room`↴](#admin-query-room-state-cache-local-users-in-room) +* [`admin query room-state-cache active-local-users-in-room`↴](#admin-query-room-state-cache-active-local-users-in-room) +* [`admin query room-state-cache room-joined-count`↴](#admin-query-room-state-cache-room-joined-count) +* [`admin query room-state-cache room-invited-count`↴](#admin-query-room-state-cache-room-invited-count) +* [`admin query room-state-cache room-user-once-joined`↴](#admin-query-room-state-cache-room-user-once-joined) +* [`admin query room-state-cache room-members-invited`↴](#admin-query-room-state-cache-room-members-invited) +* [`admin query room-state-cache get-invite-count`↴](#admin-query-room-state-cache-get-invite-count) +* [`admin query room-state-cache get-left-count`↴](#admin-query-room-state-cache-get-left-count) +* [`admin query room-state-cache rooms-joined`↴](#admin-query-room-state-cache-rooms-joined) +* [`admin query room-state-cache rooms-left`↴](#admin-query-room-state-cache-rooms-left) +* [`admin query room-state-cache rooms-invited`↴](#admin-query-room-state-cache-rooms-invited) +* [`admin query room-state-cache invite-state`↴](#admin-query-room-state-cache-invite-state) +* [`admin query room-timeline`↴](#admin-query-room-timeline) +* [`admin query room-timeline pdus`↴](#admin-query-room-timeline-pdus) +* [`admin query room-timeline last`↴](#admin-query-room-timeline-last) +* [`admin query globals`↴](#admin-query-globals) +* [`admin query globals database-version`↴](#admin-query-globals-database-version) +* [`admin query globals current-count`↴](#admin-query-globals-current-count) +* [`admin query globals last-check-for-announcements-id`↴](#admin-query-globals-last-check-for-announcements-id) +* [`admin query globals signing-keys-for`↴](#admin-query-globals-signing-keys-for) +* [`admin query sending`↴](#admin-query-sending) +* [`admin query sending active-requests`↴](#admin-query-sending-active-requests) +* [`admin query sending active-requests-for`↴](#admin-query-sending-active-requests-for) +* [`admin query sending queued-requests`↴](#admin-query-sending-queued-requests) +* [`admin query sending get-latest-edu-count`↴](#admin-query-sending-get-latest-edu-count) +* [`admin query users`↴](#admin-query-users) +* [`admin query users count-users`↴](#admin-query-users-count-users) +* [`admin query users iter-users`↴](#admin-query-users-iter-users) +* [`admin query users iter-users2`↴](#admin-query-users-iter-users2) +* [`admin query users password-hash`↴](#admin-query-users-password-hash) +* [`admin query users list-devices`↴](#admin-query-users-list-devices) +* [`admin query users list-devices-metadata`↴](#admin-query-users-list-devices-metadata) +* [`admin query users get-device-metadata`↴](#admin-query-users-get-device-metadata) +* [`admin query users get-devices-version`↴](#admin-query-users-get-devices-version) +* [`admin query users count-one-time-keys`↴](#admin-query-users-count-one-time-keys) +* [`admin query users get-device-keys`↴](#admin-query-users-get-device-keys) +* [`admin query users get-user-signing-key`↴](#admin-query-users-get-user-signing-key) +* [`admin query users get-master-key`↴](#admin-query-users-get-master-key) +* [`admin query users get-to-device-events`↴](#admin-query-users-get-to-device-events) +* [`admin query users get-latest-backup`↴](#admin-query-users-get-latest-backup) +* [`admin query users get-latest-backup-version`↴](#admin-query-users-get-latest-backup-version) +* [`admin query users get-backup-algorithm`↴](#admin-query-users-get-backup-algorithm) +* [`admin query users get-all-backups`↴](#admin-query-users-get-all-backups) +* [`admin query users get-room-backups`↴](#admin-query-users-get-room-backups) +* [`admin query users get-backup-session`↴](#admin-query-users-get-backup-session) +* [`admin query users get-shared-rooms`↴](#admin-query-users-get-shared-rooms) +* [`admin query resolver`↴](#admin-query-resolver) +* [`admin query resolver destinations-cache`↴](#admin-query-resolver-destinations-cache) +* [`admin query resolver overrides-cache`↴](#admin-query-resolver-overrides-cache) +* [`admin query pusher`↴](#admin-query-pusher) +* [`admin query pusher get-pushers`↴](#admin-query-pusher-get-pushers) +* [`admin query short`↴](#admin-query-short) +* [`admin query short short-event-id`↴](#admin-query-short-short-event-id) +* [`admin query short short-room-id`↴](#admin-query-short-short-room-id) +* [`admin query raw`↴](#admin-query-raw) +* [`admin query raw raw-maps`↴](#admin-query-raw-raw-maps) +* [`admin query raw raw-get`↴](#admin-query-raw-raw-get) +* [`admin query raw raw-del`↴](#admin-query-raw-raw-del) +* [`admin query raw raw-keys`↴](#admin-query-raw-raw-keys) +* [`admin query raw raw-keys-sizes`↴](#admin-query-raw-raw-keys-sizes) +* [`admin query raw raw-keys-total`↴](#admin-query-raw-raw-keys-total) +* [`admin query raw raw-vals-sizes`↴](#admin-query-raw-raw-vals-sizes) +* [`admin query raw raw-vals-total`↴](#admin-query-raw-raw-vals-total) +* [`admin query raw raw-iter`↴](#admin-query-raw-raw-iter) +* [`admin query raw raw-keys-from`↴](#admin-query-raw-raw-keys-from) +* [`admin query raw raw-iter-from`↴](#admin-query-raw-raw-iter-from) +* [`admin query raw raw-count`↴](#admin-query-raw-raw-count) +* [`admin query raw compact`↴](#admin-query-raw-compact) + +## `admin` + +**Usage:** `admin ` + +###### **Subcommands:** + +* `appservices` — - Commands for managing appservices +* `users` — - Commands for managing local users +* `rooms` — - Commands for managing rooms +* `federation` — - Commands for managing federation +* `server` — - Commands for managing the server +* `media` — - Commands for managing media +* `check` — - Commands for checking integrity +* `debug` — - Commands for debugging things +* `query` — - Low-level queries for database getters and iterators + + + +## `admin appservices` + +- Commands for managing appservices + +**Usage:** `admin appservices ` + +###### **Subcommands:** + +* `register` — - Register an appservice using its registration YAML +* `unregister` — - Unregister an appservice using its ID +* `show-appservice-config` — - Show an appservice's config using its ID +* `list-registered` — - List all the currently registered appservices + + + +## `admin appservices register` + +- Register an appservice using its registration YAML + +This command needs a YAML generated by an appservice (such as a bridge), which must be provided in a Markdown code block below the command. + +Registering a new bridge using the ID of an existing bridge will replace the old one. + +**Usage:** `admin appservices register` + + + +## `admin appservices unregister` + +- Unregister an appservice using its ID + +You can find the ID using the `list-appservices` command. + +**Usage:** `admin appservices unregister ` + +###### **Arguments:** + +* `` — The appservice to unregister + + + +## `admin appservices show-appservice-config` + +- Show an appservice's config using its ID + +You can find the ID using the `list-appservices` command. + +**Usage:** `admin appservices show-appservice-config ` + +###### **Arguments:** + +* `` — The appservice to show + + + +## `admin appservices list-registered` + +- List all the currently registered appservices + +**Usage:** `admin appservices list-registered` + + + +## `admin users` + +- Commands for managing local users + +**Usage:** `admin users ` + +###### **Subcommands:** + +* `create-user` — - Create a new user +* `reset-password` — - Reset user password +* `deactivate` — - Deactivate a user +* `deactivate-all` — - Deactivate a list of users +* `suspend` — - Suspend a user +* `unsuspend` — - Unsuspend a user +* `list-users` — - List local users in the database +* `list-joined-rooms` — - Lists all the rooms (local and remote) that the specified user is joined in +* `force-join-room` — - Manually join a local user to a room +* `force-leave-room` — - Manually leave a local user from a room +* `force-demote` — - Forces the specified user to drop their power levels to the room default, if their permissions allow and the auth check permits +* `make-user-admin` — - Grant server-admin privileges to a user +* `put-room-tag` — - Puts a room tag for the specified user and room ID +* `delete-room-tag` — - Deletes the room tag for the specified user and room ID +* `get-room-tags` — - Gets all the room tags for the specified user and room ID +* `redact-event` — - Attempts to forcefully redact the specified event ID from the sender user +* `force-join-list-of-local-users` — - Force joins a specified list of local users to join the specified room +* `force-join-all-local-users` — - Force joins all local users to the specified room + + + +## `admin users create-user` + +- Create a new user + +**Usage:** `admin users create-user [PASSWORD]` + +###### **Arguments:** + +* `` — Username of the new user +* `` — Password of the new user, if unspecified one is generated + + + +## `admin users reset-password` + +- Reset user password + +**Usage:** `admin users reset-password [PASSWORD]` + +###### **Arguments:** + +* `` — Username of the user for whom the password should be reset +* `` — New password for the user, if unspecified one is generated + + + +## `admin users deactivate` + +- Deactivate a user + +User will be removed from all rooms by default. Use --no-leave-rooms to not leave all rooms by default. + +**Usage:** `admin users deactivate [OPTIONS] ` + +###### **Arguments:** + +* `` + +###### **Options:** + +* `-n`, `--no-leave-rooms` + + + +## `admin users deactivate-all` + +- Deactivate a list of users + +Recommended to use in conjunction with list-local-users. + +Users will be removed from joined rooms by default. + +Can be overridden with --no-leave-rooms. + +Removing a mass amount of users from a room may cause a significant amount of leave events. The time to leave rooms may depend significantly on joined rooms and servers. + +This command needs a newline separated list of users provided in a Markdown code block below the command. + +**Usage:** `admin users deactivate-all [OPTIONS]` + +###### **Options:** + +* `-n`, `--no-leave-rooms` — Does not leave any rooms the user is in on deactivation +* `-f`, `--force` — Also deactivate admin accounts and will assume leave all rooms too + + + +## `admin users suspend` + +- Suspend a user + +Suspended users are able to log in, sync, and read messages, but are not able to send events nor redact them, cannot change their profile, and are unable to join, invite to, or knock on rooms. + +Suspended users can still leave rooms and deactivate their account. Suspending them effectively makes them read-only. + +**Usage:** `admin users suspend ` + +###### **Arguments:** + +* `` — Username of the user to suspend + + + +## `admin users unsuspend` + +- Unsuspend a user + +Reverses the effects of the `suspend` command, allowing the user to send messages, change their profile, create room invites, etc. + +**Usage:** `admin users unsuspend ` + +###### **Arguments:** + +* `` — Username of the user to unsuspend + + + +## `admin users list-users` + +- List local users in the database + +**Usage:** `admin users list-users` + + + +## `admin users list-joined-rooms` + +- Lists all the rooms (local and remote) that the specified user is joined in + +**Usage:** `admin users list-joined-rooms ` + +###### **Arguments:** + +* `` + + + +## `admin users force-join-room` + +- Manually join a local user to a room + +**Usage:** `admin users force-join-room ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin users force-leave-room` + +- Manually leave a local user from a room + +**Usage:** `admin users force-leave-room ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin users force-demote` + +- Forces the specified user to drop their power levels to the room default, if their permissions allow and the auth check permits + +**Usage:** `admin users force-demote ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin users make-user-admin` + +- Grant server-admin privileges to a user + +**Usage:** `admin users make-user-admin ` + +###### **Arguments:** + +* `` + + + +## `admin users put-room-tag` + +- Puts a room tag for the specified user and room ID. + +This is primarily useful if you'd like to set your admin room to the special "System Alerts" section in Element as a way to permanently see your admin room without it being buried away in your favourites or rooms. To do this, you would pass your user, your admin room's internal ID, and the tag name `m.server_notice`. + +**Usage:** `admin users put-room-tag ` + +###### **Arguments:** + +* `` +* `` +* `` + + + +## `admin users delete-room-tag` + +- Deletes the room tag for the specified user and room ID + +**Usage:** `admin users delete-room-tag ` + +###### **Arguments:** + +* `` +* `` +* `` + + + +## `admin users get-room-tags` + +- Gets all the room tags for the specified user and room ID + +**Usage:** `admin users get-room-tags ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin users redact-event` + +- Attempts to forcefully redact the specified event ID from the sender user + +This is only valid for local users + +**Usage:** `admin users redact-event ` + +###### **Arguments:** + +* `` + + + +## `admin users force-join-list-of-local-users` + +- Force joins a specified list of local users to join the specified room. + +Specify a codeblock of usernames. + +At least 1 server admin must be in the room to reduce abuse. + +Requires the `--yes-i-want-to-do-this` flag. + +**Usage:** `admin users force-join-list-of-local-users [OPTIONS] ` + +###### **Arguments:** + +* `` + +###### **Options:** + +* `--yes-i-want-to-do-this` + + + +## `admin users force-join-all-local-users` + +- Force joins all local users to the specified room. + +At least 1 server admin must be in the room to reduce abuse. + +Requires the `--yes-i-want-to-do-this` flag. + +**Usage:** `admin users force-join-all-local-users [OPTIONS] ` + +###### **Arguments:** + +* `` + +###### **Options:** + +* `--yes-i-want-to-do-this` + + + +## `admin rooms` + +- Commands for managing rooms + +**Usage:** `admin rooms ` + +###### **Subcommands:** + +* `list-rooms` — - List all rooms the server knows about +* `info` — - View information about a room we know about +* `moderation` — - Manage moderation of remote or local rooms +* `alias` — - Manage rooms' aliases +* `directory` — - Manage the room directory +* `exists` — - Check if we know about a room + + + +## `admin rooms list-rooms` + +- List all rooms the server knows about + +**Usage:** `admin rooms list-rooms [OPTIONS] [PAGE]` + +###### **Arguments:** + +* `` + +###### **Options:** + +* `--exclude-disabled` — Excludes rooms that we have federation disabled with +* `--exclude-banned` — Excludes rooms that we have banned +* `--no-details` — Whether to only output room IDs without supplementary room information + + + +## `admin rooms info` + +- View information about a room we know about + +**Usage:** `admin rooms info ` + +###### **Subcommands:** + +* `list-joined-members` — - List joined members in a room +* `view-room-topic` — - Displays room topic + + + +## `admin rooms info list-joined-members` + +- List joined members in a room + +**Usage:** `admin rooms info list-joined-members [OPTIONS] ` + +###### **Arguments:** + +* `` + +###### **Options:** + +* `--local-only` — Lists only our local users in the specified room + + + +## `admin rooms info view-room-topic` + +- Displays room topic + +Room topics can be huge, so this is in its own separate command + +**Usage:** `admin rooms info view-room-topic ` + +###### **Arguments:** + +* `` + + + +## `admin rooms moderation` + +- Manage moderation of remote or local rooms + +**Usage:** `admin rooms moderation ` + +###### **Subcommands:** + +* `ban-room` — - Bans a room from local users joining and evicts all our local users (including server admins) from the room. Also blocks any invites (local and remote) for the banned room, and disables federation entirely with it +* `ban-list-of-rooms` — - Bans a list of rooms (room IDs and room aliases) from a newline delimited codeblock similar to `user deactivate-all`. Applies the same steps as ban-room +* `unban-room` — - Unbans a room to allow local users to join again +* `list-banned-rooms` — - List of all rooms we have banned + + + +## `admin rooms moderation ban-room` + +- Bans a room from local users joining and evicts all our local users (including server admins) from the room. Also blocks any invites (local and remote) for the banned room, and disables federation entirely with it + +**Usage:** `admin rooms moderation ban-room ` + +###### **Arguments:** + +* `` — The room in the format of `!roomid:example.com` or a room alias in the format of `#roomalias:example.com` + + + +## `admin rooms moderation ban-list-of-rooms` + +- Bans a list of rooms (room IDs and room aliases) from a newline delimited codeblock similar to `user deactivate-all`. Applies the same steps as ban-room + +**Usage:** `admin rooms moderation ban-list-of-rooms` + + + +## `admin rooms moderation unban-room` + +- Unbans a room to allow local users to join again + +**Usage:** `admin rooms moderation unban-room ` + +###### **Arguments:** + +* `` — The room in the format of `!roomid:example.com` or a room alias in the format of `#roomalias:example.com` + + + +## `admin rooms moderation list-banned-rooms` + +- List of all rooms we have banned + +**Usage:** `admin rooms moderation list-banned-rooms [OPTIONS]` + +###### **Options:** + +* `--no-details` — Whether to only output room IDs without supplementary room information + + + +## `admin rooms alias` + +- Manage rooms' aliases + +**Usage:** `admin rooms alias ` + +###### **Subcommands:** + +* `set` — - Make an alias point to a room +* `remove` — - Remove a local alias +* `which` — - Show which room is using an alias +* `list` — - List aliases currently being used + + + +## `admin rooms alias set` + +- Make an alias point to a room + +**Usage:** `admin rooms alias set [OPTIONS] ` + +###### **Arguments:** + +* `` — The room id to set the alias on +* `` — The alias localpart to use (`alias`, not `#alias:servername.tld`) + +###### **Options:** + +* `-f`, `--force` — Set the alias even if a room is already using it + + + +## `admin rooms alias remove` + +- Remove a local alias + +**Usage:** `admin rooms alias remove ` + +###### **Arguments:** + +* `` — The alias localpart to remove (`alias`, not `#alias:servername.tld`) + + + +## `admin rooms alias which` + +- Show which room is using an alias + +**Usage:** `admin rooms alias which ` + +###### **Arguments:** + +* `` — The alias localpart to look up (`alias`, not `#alias:servername.tld`) + + + +## `admin rooms alias list` + +- List aliases currently being used + +**Usage:** `admin rooms alias list [ROOM_ID]` + +###### **Arguments:** + +* `` — If set, only list the aliases for this room + + + +## `admin rooms directory` + +- Manage the room directory + +**Usage:** `admin rooms directory ` + +###### **Subcommands:** + +* `publish` — - Publish a room to the room directory +* `unpublish` — - Unpublish a room to the room directory +* `list` — - List rooms that are published + + + +## `admin rooms directory publish` + +- Publish a room to the room directory + +**Usage:** `admin rooms directory publish ` + +###### **Arguments:** + +* `` — The room id of the room to publish + + + +## `admin rooms directory unpublish` + +- Unpublish a room to the room directory + +**Usage:** `admin rooms directory unpublish ` + +###### **Arguments:** + +* `` — The room id of the room to unpublish + + + +## `admin rooms directory list` + +- List rooms that are published + +**Usage:** `admin rooms directory list [PAGE]` + +###### **Arguments:** + +* `` + + + +## `admin rooms exists` + +- Check if we know about a room + +**Usage:** `admin rooms exists ` + +###### **Arguments:** + +* `` + + + +## `admin federation` + +- Commands for managing federation + +**Usage:** `admin federation ` + +###### **Subcommands:** + +* `incoming-federation` — - List all rooms we are currently handling an incoming pdu from +* `disable-room` — - Disables incoming federation handling for a room +* `enable-room` — - Enables incoming federation handling for a room again +* `fetch-support-well-known` — - Fetch `/.well-known/matrix/support` from the specified server +* `remote-user-in-rooms` — - Lists all the rooms we share/track with the specified *remote* user + + + +## `admin federation incoming-federation` + +- List all rooms we are currently handling an incoming pdu from + +**Usage:** `admin federation incoming-federation` + + + +## `admin federation disable-room` + +- Disables incoming federation handling for a room + +**Usage:** `admin federation disable-room ` + +###### **Arguments:** + +* `` + + + +## `admin federation enable-room` + +- Enables incoming federation handling for a room again + +**Usage:** `admin federation enable-room ` + +###### **Arguments:** + +* `` + + + +## `admin federation fetch-support-well-known` + +- Fetch `/.well-known/matrix/support` from the specified server + +Despite the name, this is not a federation endpoint and does not go through the federation / server resolution process as per-spec this is supposed to be served at the server_name. + +Respecting homeservers put this file here for listing administration, moderation, and security inquiries. This command provides a way to easily fetch that information. + +**Usage:** `admin federation fetch-support-well-known ` + +###### **Arguments:** + +* `` + + + +## `admin federation remote-user-in-rooms` + +- Lists all the rooms we share/track with the specified *remote* user + +**Usage:** `admin federation remote-user-in-rooms ` + +###### **Arguments:** + +* `` + + + +## `admin server` + +- Commands for managing the server + +**Usage:** `admin server ` + +###### **Subcommands:** + +* `uptime` — - Time elapsed since startup +* `show-config` — - Show configuration values +* `reload-config` — - Reload configuration values +* `list-features` — - List the features built into the server +* `memory-usage` — - Print database memory usage statistics +* `clear-caches` — - Clears all of Continuwuity's caches +* `backup-database` — - Performs an online backup of the database (only available for RocksDB at the moment) +* `list-backups` — - List database backups +* `admin-notice` — - Send a message to the admin room +* `reload-mods` — - Hot-reload the server +* `restart` — - Restart the server +* `shutdown` — - Shutdown the server + + + +## `admin server uptime` + +- Time elapsed since startup + +**Usage:** `admin server uptime` + + + +## `admin server show-config` + +- Show configuration values + +**Usage:** `admin server show-config` + + + +## `admin server reload-config` + +- Reload configuration values + +**Usage:** `admin server reload-config [PATH]` + +###### **Arguments:** + +* `` + + + +## `admin server list-features` + +- List the features built into the server + +**Usage:** `admin server list-features [OPTIONS]` + +###### **Options:** + +* `-a`, `--available` +* `-e`, `--enabled` +* `-c`, `--comma` + + + +## `admin server memory-usage` + +- Print database memory usage statistics + +**Usage:** `admin server memory-usage` + + + +## `admin server clear-caches` + +- Clears all of Continuwuity's caches + +**Usage:** `admin server clear-caches` + + + +## `admin server backup-database` + +- Performs an online backup of the database (only available for RocksDB at the moment) + +**Usage:** `admin server backup-database` + + + +## `admin server list-backups` + +- List database backups + +**Usage:** `admin server list-backups` + + + +## `admin server admin-notice` + +- Send a message to the admin room + +**Usage:** `admin server admin-notice [MESSAGE]...` + +###### **Arguments:** + +* `` + + + +## `admin server reload-mods` + +- Hot-reload the server + +**Usage:** `admin server reload-mods` + + + +## `admin server restart` + +- Restart the server + +**Usage:** `admin server restart [OPTIONS]` + +###### **Options:** + +* `-f`, `--force` + + + +## `admin server shutdown` + +- Shutdown the server + +**Usage:** `admin server shutdown` + + + +## `admin media` + +- Commands for managing media + +**Usage:** `admin media ` + +###### **Subcommands:** + +* `delete` — - Deletes a single media file from our database and on the filesystem via a single MXC URL or event ID (not redacted) +* `delete-list` — - Deletes a codeblock list of MXC URLs from our database and on the filesystem. This will always ignore errors +* `delete-past-remote-media` — - Deletes all remote (and optionally local) media created before or after [duration] time using filesystem metadata first created at date, or fallback to last modified date. This will always ignore errors by default +* `delete-all-from-user` — - Deletes all the local media from a local user on our server. This will always ignore errors by default +* `delete-all-from-server` — - Deletes all remote media from the specified remote server. This will always ignore errors by default +* `get-file-info` — +* `get-remote-file` — +* `get-remote-thumbnail` — + + + +## `admin media delete` + +- Deletes a single media file from our database and on the filesystem via a single MXC URL or event ID (not redacted) + +**Usage:** `admin media delete [OPTIONS]` + +###### **Options:** + +* `--mxc ` — The MXC URL to delete +* `--event-id ` — - The message event ID which contains the media and thumbnail MXC URLs + + + +## `admin media delete-list` + +- Deletes a codeblock list of MXC URLs from our database and on the filesystem. This will always ignore errors + +**Usage:** `admin media delete-list` + + + +## `admin media delete-past-remote-media` + +- Deletes all remote (and optionally local) media created before or after [duration] time using filesystem metadata first created at date, or fallback to last modified date. This will always ignore errors by default + +**Usage:** `admin media delete-past-remote-media [OPTIONS] ` + +###### **Arguments:** + +* `` — - The relative time (e.g. 30s, 5m, 7d) within which to search + +###### **Options:** + +* `-b`, `--before` — - Only delete media created before [duration] ago +* `-a`, `--after` — - Only delete media created after [duration] ago +* `--yes-i-want-to-delete-local-media` — - Long argument to additionally delete local media + + + +## `admin media delete-all-from-user` + +- Deletes all the local media from a local user on our server. This will always ignore errors by default + +**Usage:** `admin media delete-all-from-user ` + +###### **Arguments:** + +* `` + + + +## `admin media delete-all-from-server` + +- Deletes all remote media from the specified remote server. This will always ignore errors by default + +**Usage:** `admin media delete-all-from-server [OPTIONS] ` + +###### **Arguments:** + +* `` + +###### **Options:** + +* `--yes-i-want-to-delete-local-media` — Long argument to delete local media + + + +## `admin media get-file-info` + +**Usage:** `admin media get-file-info ` + +###### **Arguments:** + +* `` — The MXC URL to lookup info for + + + +## `admin media get-remote-file` + +**Usage:** `admin media get-remote-file [OPTIONS] ` + +###### **Arguments:** + +* `` — The MXC URL to fetch + +###### **Options:** + +* `-s`, `--server ` +* `-t`, `--timeout ` + + Default value: `10000` + + + +## `admin media get-remote-thumbnail` + +**Usage:** `admin media get-remote-thumbnail [OPTIONS] ` + +###### **Arguments:** + +* `` — The MXC URL to fetch + +###### **Options:** + +* `-s`, `--server ` +* `-t`, `--timeout ` + + Default value: `10000` +* `--width ` + + Default value: `800` +* `--height ` + + Default value: `800` + + + +## `admin check` + +- Commands for checking integrity + +**Usage:** `admin check ` + +###### **Subcommands:** + +* `check-all-users` — + + + +## `admin check check-all-users` + +**Usage:** `admin check check-all-users` + + + +## `admin debug` + +- Commands for debugging things + +**Usage:** `admin debug ` + +###### **Subcommands:** + +* `echo` — - Echo input of admin command +* `get-auth-chain` — - Get the auth_chain of a PDU +* `parse-pdu` — - Parse and print a PDU from a JSON +* `get-pdu` — - Retrieve and print a PDU by EventID from the Continuwuity database +* `get-short-pdu` — - Retrieve and print a PDU by PduId from the Continuwuity database +* `get-remote-pdu` — - Attempts to retrieve a PDU from a remote server. Inserts it into our database/timeline if found and we do not have this PDU already (following normal event auth rules, handles it as an incoming PDU) +* `get-remote-pdu-list` — - Same as `get-remote-pdu` but accepts a codeblock newline delimited list of PDUs and a single server to fetch from +* `get-room-state` — - Gets all the room state events for the specified room +* `get-signing-keys` — - Get and display signing keys from local cache or remote server +* `get-verify-keys` — - Get and display signing keys from local cache or remote server +* `ping` — - Sends a federation request to the remote server's `/_matrix/federation/v1/version` endpoint and measures the latency it took for the server to respond +* `force-device-list-updates` — - Forces device lists for all local and remote users to be updated (as having new keys available) +* `change-log-level` — - Change tracing log level/filter on the fly +* `sign-json` — - Sign JSON blob +* `verify-json` — - Verify JSON signatures +* `verify-pdu` — - Verify PDU +* `first-pdu-in-room` — - Prints the very first PDU in the specified room (typically m.room.create) +* `latest-pdu-in-room` — - Prints the latest ("last") PDU in the specified room (typically a message) +* `force-set-room-state-from-server` — - Forcefully replaces the room state of our local copy of the specified room, with the copy (auth chain and room state events) the specified remote server says +* `resolve-true-destination` — - Runs a server name through Continuwuity's true destination resolution process +* `memory-stats` — - Print extended memory usage +* `runtime-metrics` — - Print general tokio runtime metric totals +* `runtime-interval` — - Print detailed tokio runtime metrics accumulated since last command invocation +* `time` — - Print the current time +* `list-dependencies` — - List dependencies +* `database-stats` — - Get database statistics +* `trim-memory` — - Trim memory usage +* `database-files` — - List database files + + + +## `admin debug echo` + +- Echo input of admin command + +**Usage:** `admin debug echo [MESSAGE]...` + +###### **Arguments:** + +* `` + + + +## `admin debug get-auth-chain` + +- Get the auth_chain of a PDU + +**Usage:** `admin debug get-auth-chain ` + +###### **Arguments:** + +* `` — An event ID (the $ character followed by the base64 reference hash) + + + +## `admin debug parse-pdu` + +- Parse and print a PDU from a JSON + +The PDU event is only checked for validity and is not added to the database. + +This command needs a JSON blob provided in a Markdown code block below the command. + +**Usage:** `admin debug parse-pdu` + + + +## `admin debug get-pdu` + +- Retrieve and print a PDU by EventID from the Continuwuity database + +**Usage:** `admin debug get-pdu ` + +###### **Arguments:** + +* `` — An event ID (a $ followed by the base64 reference hash) + + + +## `admin debug get-short-pdu` + +- Retrieve and print a PDU by PduId from the Continuwuity database + +**Usage:** `admin debug get-short-pdu ` + +###### **Arguments:** + +* `` — Shortroomid integer +* `` — Shorteventid integer + + + +## `admin debug get-remote-pdu` + +- Attempts to retrieve a PDU from a remote server. Inserts it into our database/timeline if found and we do not have this PDU already (following normal event auth rules, handles it as an incoming PDU) + +**Usage:** `admin debug get-remote-pdu ` + +###### **Arguments:** + +* `` — An event ID (a $ followed by the base64 reference hash) +* `` — Argument for us to attempt to fetch the event from the specified remote server + + + +## `admin debug get-remote-pdu-list` + +- Same as `get-remote-pdu` but accepts a codeblock newline delimited list of PDUs and a single server to fetch from + +**Usage:** `admin debug get-remote-pdu-list [OPTIONS] ` + +###### **Arguments:** + +* `` — Argument for us to attempt to fetch all the events from the specified remote server + +###### **Options:** + +* `-f`, `--force` — If set, ignores errors, else stops at the first error/failure + + + +## `admin debug get-room-state` + +- Gets all the room state events for the specified room. + +This is functionally equivalent to `GET /_matrix/client/v3/rooms/{roomid}/state`, except the admin command does *not* check if the sender user is allowed to see state events. This is done because it's implied that server admins here have database access and can see/get room info themselves anyways if they were malicious admins. + +Of course the check is still done on the actual client API. + +**Usage:** `admin debug get-room-state ` + +###### **Arguments:** + +* `` — Room ID + + + +## `admin debug get-signing-keys` + +- Get and display signing keys from local cache or remote server + +**Usage:** `admin debug get-signing-keys [OPTIONS] [SERVER_NAME]` + +###### **Arguments:** + +* `` + +###### **Options:** + +* `--notary ` +* `-q`, `--query` + + + +## `admin debug get-verify-keys` + +- Get and display signing keys from local cache or remote server + +**Usage:** `admin debug get-verify-keys [SERVER_NAME]` + +###### **Arguments:** + +* `` + + + +## `admin debug ping` + +- Sends a federation request to the remote server's `/_matrix/federation/v1/version` endpoint and measures the latency it took for the server to respond + +**Usage:** `admin debug ping ` + +###### **Arguments:** + +* `` + + + +## `admin debug force-device-list-updates` + +- Forces device lists for all local and remote users to be updated (as having new keys available) + +**Usage:** `admin debug force-device-list-updates` + + + +## `admin debug change-log-level` + +- Change tracing log level/filter on the fly + +This accepts the same format as the `log` config option. + +**Usage:** `admin debug change-log-level [OPTIONS] [FILTER]` + +###### **Arguments:** + +* `` — Log level/filter + +###### **Options:** + +* `-r`, `--reset` — Resets the log level/filter to the one in your config + + + +## `admin debug sign-json` + +- Sign JSON blob + +This command needs a JSON blob provided in a Markdown code block below the command. + +**Usage:** `admin debug sign-json` + + + +## `admin debug verify-json` + +- Verify JSON signatures + +This command needs a JSON blob provided in a Markdown code block below the command. + +**Usage:** `admin debug verify-json` + + + +## `admin debug verify-pdu` + +- Verify PDU + +This re-verifies a PDU existing in the database found by ID. + +**Usage:** `admin debug verify-pdu ` + +###### **Arguments:** + +* `` + + + +## `admin debug first-pdu-in-room` + +- Prints the very first PDU in the specified room (typically m.room.create) + +**Usage:** `admin debug first-pdu-in-room ` + +###### **Arguments:** + +* `` — The room ID + + + +## `admin debug latest-pdu-in-room` + +- Prints the latest ("last") PDU in the specified room (typically a message) + +**Usage:** `admin debug latest-pdu-in-room ` + +###### **Arguments:** + +* `` — The room ID + + + +## `admin debug force-set-room-state-from-server` + +- Forcefully replaces the room state of our local copy of the specified room, with the copy (auth chain and room state events) the specified remote server says. + +A common desire for room deletion is to simply "reset" our copy of the room. While this admin command is not a replacement for that, if you know you have split/broken room state and you know another server in the room that has the best/working room state, this command can let you use their room state. Such example is your server saying users are in a room, but other servers are saying they're not in the room in question. + +This command will get the latest PDU in the room we know about, and request the room state at that point in time via `/_matrix/federation/v1/state/{roomId}`. + +**Usage:** `admin debug force-set-room-state-from-server [EVENT_ID]` + +###### **Arguments:** + +* `` — The impacted room ID +* `` — The server we will use to query the room state for +* `` — The event ID of the latest known PDU in the room. Will be found automatically if not provided + + + +## `admin debug resolve-true-destination` + +- Runs a server name through Continuwuity's true destination resolution process + +Useful for debugging well-known issues + +**Usage:** `admin debug resolve-true-destination [OPTIONS] ` + +###### **Arguments:** + +* `` + +###### **Options:** + +* `-n`, `--no-cache` + + + +## `admin debug memory-stats` + +- Print extended memory usage + +Optional argument is a character mask (a sequence of characters in any order) which enable additional extended statistics. Known characters are "abdeglmx". For convenience, a '*' will enable everything. + +**Usage:** `admin debug memory-stats [OPTS]` + +###### **Arguments:** + +* `` + + + +## `admin debug runtime-metrics` + +- Print general tokio runtime metric totals + +**Usage:** `admin debug runtime-metrics` + + + +## `admin debug runtime-interval` + +- Print detailed tokio runtime metrics accumulated since last command invocation + +**Usage:** `admin debug runtime-interval` + + + +## `admin debug time` + +- Print the current time + +**Usage:** `admin debug time` + + + +## `admin debug list-dependencies` + +- List dependencies + +**Usage:** `admin debug list-dependencies [OPTIONS]` + +###### **Options:** + +* `-n`, `--names` + + + +## `admin debug database-stats` + +- Get database statistics + +**Usage:** `admin debug database-stats [OPTIONS] [PROPERTY]` + +###### **Arguments:** + +* `` + +###### **Options:** + +* `-m`, `--map ` + + + +## `admin debug trim-memory` + +- Trim memory usage + +**Usage:** `admin debug trim-memory` + + + +## `admin debug database-files` + +- List database files + +**Usage:** `admin debug database-files [OPTIONS] [MAP]` + +###### **Arguments:** + +* `` + +###### **Options:** + +* `--level ` + + + +## `admin query` + +- Low-level queries for database getters and iterators + +**Usage:** `admin query ` + +###### **Subcommands:** + +* `account-data` — - account_data.rs iterators and getters +* `appservice` — - appservice.rs iterators and getters +* `presence` — - presence.rs iterators and getters +* `room-alias` — - rooms/alias.rs iterators and getters +* `room-state-cache` — - rooms/state_cache iterators and getters +* `room-timeline` — - rooms/timeline iterators and getters +* `globals` — - globals.rs iterators and getters +* `sending` — - sending.rs iterators and getters +* `users` — - users.rs iterators and getters +* `resolver` — - resolver service +* `pusher` — - pusher service +* `short` — - short service +* `raw` — - raw service + + + +## `admin query account-data` + +- account_data.rs iterators and getters + +**Usage:** `admin query account-data ` + +###### **Subcommands:** + +* `changes-since` — - Returns all changes to the account data that happened after `since` +* `account-data-get` — - Searches the account data for a specific kind + + + +## `admin query account-data changes-since` + +- Returns all changes to the account data that happened after `since` + +**Usage:** `admin query account-data changes-since [ROOM_ID]` + +###### **Arguments:** + +* `` — Full user ID +* `` — UNIX timestamp since (u64) +* `` — Optional room ID of the account data + + + +## `admin query account-data account-data-get` + +- Searches the account data for a specific kind + +**Usage:** `admin query account-data account-data-get [ROOM_ID]` + +###### **Arguments:** + +* `` — Full user ID +* `` — Account data event type +* `` — Optional room ID of the account data + + + +## `admin query appservice` + +- appservice.rs iterators and getters + +**Usage:** `admin query appservice ` + +###### **Subcommands:** + +* `get-registration` — - Gets the appservice registration info/details from the ID as a string +* `all` — - Gets all appservice registrations with their ID and registration info + + + +## `admin query appservice get-registration` + +- Gets the appservice registration info/details from the ID as a string + +**Usage:** `admin query appservice get-registration ` + +###### **Arguments:** + +* `` — Appservice registration ID + + + +## `admin query appservice all` + +- Gets all appservice registrations with their ID and registration info + +**Usage:** `admin query appservice all` + + + +## `admin query presence` + +- presence.rs iterators and getters + +**Usage:** `admin query presence ` + +###### **Subcommands:** + +* `get-presence` — - Returns the latest presence event for the given user +* `presence-since` — - Iterator of the most recent presence updates that happened after the event with id `since` + + + +## `admin query presence get-presence` + +- Returns the latest presence event for the given user + +**Usage:** `admin query presence get-presence ` + +###### **Arguments:** + +* `` — Full user ID + + + +## `admin query presence presence-since` + +- Iterator of the most recent presence updates that happened after the event with id `since` + +**Usage:** `admin query presence presence-since ` + +###### **Arguments:** + +* `` — UNIX timestamp since (u64) + + + +## `admin query room-alias` + +- rooms/alias.rs iterators and getters + +**Usage:** `admin query room-alias ` + +###### **Subcommands:** + +* `resolve-local-alias` — +* `local-aliases-for-room` — - Iterator of all our local room aliases for the room ID +* `all-local-aliases` — - Iterator of all our local aliases in our database with their room IDs + + + +## `admin query room-alias resolve-local-alias` + +**Usage:** `admin query room-alias resolve-local-alias ` + +###### **Arguments:** + +* `` — Full room alias + + + +## `admin query room-alias local-aliases-for-room` + +- Iterator of all our local room aliases for the room ID + +**Usage:** `admin query room-alias local-aliases-for-room ` + +###### **Arguments:** + +* `` — Full room ID + + + +## `admin query room-alias all-local-aliases` + +- Iterator of all our local aliases in our database with their room IDs + +**Usage:** `admin query room-alias all-local-aliases` + + + +## `admin query room-state-cache` + +- rooms/state_cache iterators and getters + +**Usage:** `admin query room-state-cache ` + +###### **Subcommands:** + +* `server-in-room` — +* `room-servers` — +* `server-rooms` — +* `room-members` — +* `local-users-in-room` — +* `active-local-users-in-room` — +* `room-joined-count` — +* `room-invited-count` — +* `room-user-once-joined` — +* `room-members-invited` — +* `get-invite-count` — +* `get-left-count` — +* `rooms-joined` — +* `rooms-left` — +* `rooms-invited` — +* `invite-state` — + + + +## `admin query room-state-cache server-in-room` + +**Usage:** `admin query room-state-cache server-in-room ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin query room-state-cache room-servers` + +**Usage:** `admin query room-state-cache room-servers ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache server-rooms` + +**Usage:** `admin query room-state-cache server-rooms ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache room-members` + +**Usage:** `admin query room-state-cache room-members ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache local-users-in-room` + +**Usage:** `admin query room-state-cache local-users-in-room ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache active-local-users-in-room` + +**Usage:** `admin query room-state-cache active-local-users-in-room ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache room-joined-count` + +**Usage:** `admin query room-state-cache room-joined-count ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache room-invited-count` + +**Usage:** `admin query room-state-cache room-invited-count ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache room-user-once-joined` + +**Usage:** `admin query room-state-cache room-user-once-joined ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache room-members-invited` + +**Usage:** `admin query room-state-cache room-members-invited ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache get-invite-count` + +**Usage:** `admin query room-state-cache get-invite-count ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin query room-state-cache get-left-count` + +**Usage:** `admin query room-state-cache get-left-count ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin query room-state-cache rooms-joined` + +**Usage:** `admin query room-state-cache rooms-joined ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache rooms-left` + +**Usage:** `admin query room-state-cache rooms-left ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache rooms-invited` + +**Usage:** `admin query room-state-cache rooms-invited ` + +###### **Arguments:** + +* `` + + + +## `admin query room-state-cache invite-state` + +**Usage:** `admin query room-state-cache invite-state ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin query room-timeline` + +- rooms/timeline iterators and getters + +**Usage:** `admin query room-timeline ` + +###### **Subcommands:** + +* `pdus` — +* `last` — + + + +## `admin query room-timeline pdus` + +**Usage:** `admin query room-timeline pdus [OPTIONS] [FROM]` + +###### **Arguments:** + +* `` +* `` + +###### **Options:** + +* `-l`, `--limit ` + + + +## `admin query room-timeline last` + +**Usage:** `admin query room-timeline last ` + +###### **Arguments:** + +* `` + + + +## `admin query globals` + +- globals.rs iterators and getters + +**Usage:** `admin query globals ` + +###### **Subcommands:** + +* `database-version` — +* `current-count` — +* `last-check-for-announcements-id` — +* `signing-keys-for` — - This returns an empty `Ok(BTreeMap<..>)` when there are no keys found for the server + + + +## `admin query globals database-version` + +**Usage:** `admin query globals database-version` + + + +## `admin query globals current-count` + +**Usage:** `admin query globals current-count` + + + +## `admin query globals last-check-for-announcements-id` + +**Usage:** `admin query globals last-check-for-announcements-id` + + + +## `admin query globals signing-keys-for` + +- This returns an empty `Ok(BTreeMap<..>)` when there are no keys found for the server + +**Usage:** `admin query globals signing-keys-for ` + +###### **Arguments:** + +* `` + + + +## `admin query sending` + +- sending.rs iterators and getters + +**Usage:** `admin query sending ` + +###### **Subcommands:** + +* `active-requests` — - Queries database for all `servercurrentevent_data` +* `active-requests-for` — - Queries database for `servercurrentevent_data` but for a specific destination +* `queued-requests` — - Queries database for `servernameevent_data` which are the queued up requests that will eventually be sent +* `get-latest-edu-count` — + + + +## `admin query sending active-requests` + +- Queries database for all `servercurrentevent_data` + +**Usage:** `admin query sending active-requests` + + + +## `admin query sending active-requests-for` + +- Queries database for `servercurrentevent_data` but for a specific destination + +This command takes only *one* format of these arguments: + +appservice_id server_name user_id AND push_key + +See src/service/sending/mod.rs for the definition of the `Destination` enum + +**Usage:** `admin query sending active-requests-for [OPTIONS]` + +###### **Options:** + +* `-a`, `--appservice-id ` +* `-s`, `--server-name ` +* `-u`, `--user-id ` +* `-p`, `--push-key ` + + + +## `admin query sending queued-requests` + +- Queries database for `servernameevent_data` which are the queued up requests that will eventually be sent + +This command takes only *one* format of these arguments: + +appservice_id server_name user_id AND push_key + +See src/service/sending/mod.rs for the definition of the `Destination` enum + +**Usage:** `admin query sending queued-requests [OPTIONS]` + +###### **Options:** + +* `-a`, `--appservice-id ` +* `-s`, `--server-name ` +* `-u`, `--user-id ` +* `-p`, `--push-key ` + + + +## `admin query sending get-latest-edu-count` + +**Usage:** `admin query sending get-latest-edu-count ` + +###### **Arguments:** + +* `` + + + +## `admin query users` + +- users.rs iterators and getters + +**Usage:** `admin query users ` + +###### **Subcommands:** + +* `count-users` — +* `iter-users` — +* `iter-users2` — +* `password-hash` — +* `list-devices` — +* `list-devices-metadata` — +* `get-device-metadata` — +* `get-devices-version` — +* `count-one-time-keys` — +* `get-device-keys` — +* `get-user-signing-key` — +* `get-master-key` — +* `get-to-device-events` — +* `get-latest-backup` — +* `get-latest-backup-version` — +* `get-backup-algorithm` — +* `get-all-backups` — +* `get-room-backups` — +* `get-backup-session` — +* `get-shared-rooms` — + + + +## `admin query users count-users` + +**Usage:** `admin query users count-users` + + + +## `admin query users iter-users` + +**Usage:** `admin query users iter-users` + + + +## `admin query users iter-users2` + +**Usage:** `admin query users iter-users2` + + + +## `admin query users password-hash` + +**Usage:** `admin query users password-hash ` + +###### **Arguments:** + +* `` + + + +## `admin query users list-devices` + +**Usage:** `admin query users list-devices ` + +###### **Arguments:** + +* `` + + + +## `admin query users list-devices-metadata` + +**Usage:** `admin query users list-devices-metadata ` + +###### **Arguments:** + +* `` + + + +## `admin query users get-device-metadata` + +**Usage:** `admin query users get-device-metadata ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin query users get-devices-version` + +**Usage:** `admin query users get-devices-version ` + +###### **Arguments:** + +* `` + + + +## `admin query users count-one-time-keys` + +**Usage:** `admin query users count-one-time-keys ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin query users get-device-keys` + +**Usage:** `admin query users get-device-keys ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin query users get-user-signing-key` + +**Usage:** `admin query users get-user-signing-key ` + +###### **Arguments:** + +* `` + + + +## `admin query users get-master-key` + +**Usage:** `admin query users get-master-key ` + +###### **Arguments:** + +* `` + + + +## `admin query users get-to-device-events` + +**Usage:** `admin query users get-to-device-events ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin query users get-latest-backup` + +**Usage:** `admin query users get-latest-backup ` + +###### **Arguments:** + +* `` + + + +## `admin query users get-latest-backup-version` + +**Usage:** `admin query users get-latest-backup-version ` + +###### **Arguments:** + +* `` + + + +## `admin query users get-backup-algorithm` + +**Usage:** `admin query users get-backup-algorithm ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin query users get-all-backups` + +**Usage:** `admin query users get-all-backups ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin query users get-room-backups` + +**Usage:** `admin query users get-room-backups ` + +###### **Arguments:** + +* `` +* `` +* `` + + + +## `admin query users get-backup-session` + +**Usage:** `admin query users get-backup-session ` + +###### **Arguments:** + +* `` +* `` +* `` +* `` + + + +## `admin query users get-shared-rooms` + +**Usage:** `admin query users get-shared-rooms ` + +###### **Arguments:** + +* `` +* `` + + + +## `admin query resolver` + +- resolver service + +**Usage:** `admin query resolver ` + +###### **Subcommands:** + +* `destinations-cache` — Query the destinations cache +* `overrides-cache` — Query the overrides cache + + + +## `admin query resolver destinations-cache` + +Query the destinations cache + +**Usage:** `admin query resolver destinations-cache [SERVER_NAME]` + +###### **Arguments:** + +* `` + + + +## `admin query resolver overrides-cache` + +Query the overrides cache + +**Usage:** `admin query resolver overrides-cache [NAME]` + +###### **Arguments:** + +* `` + + + +## `admin query pusher` + +- pusher service + +**Usage:** `admin query pusher ` + +###### **Subcommands:** + +* `get-pushers` — - Returns all the pushers for the user + + + +## `admin query pusher get-pushers` + +- Returns all the pushers for the user + +**Usage:** `admin query pusher get-pushers ` + +###### **Arguments:** + +* `` — Full user ID + + + +## `admin query short` + +- short service + +**Usage:** `admin query short ` + +###### **Subcommands:** + +* `short-event-id` — +* `short-room-id` — + + + +## `admin query short short-event-id` + +**Usage:** `admin query short short-event-id ` + +###### **Arguments:** + +* `` + + + +## `admin query short short-room-id` + +**Usage:** `admin query short short-room-id ` + +###### **Arguments:** + +* `` + + + +## `admin query raw` + +- raw service + +**Usage:** `admin query raw ` + +###### **Subcommands:** + +* `raw-maps` — - List database maps +* `raw-get` — - Raw database query +* `raw-del` — - Raw database delete (for string keys) +* `raw-keys` — - Raw database keys iteration +* `raw-keys-sizes` — - Raw database key size breakdown +* `raw-keys-total` — - Raw database keys total bytes +* `raw-vals-sizes` — - Raw database values size breakdown +* `raw-vals-total` — - Raw database values total bytes +* `raw-iter` — - Raw database items iteration +* `raw-keys-from` — - Raw database keys iteration +* `raw-iter-from` — - Raw database items iteration +* `raw-count` — - Raw database record count +* `compact` — - Compact database + + + +## `admin query raw raw-maps` + +- List database maps + +**Usage:** `admin query raw raw-maps` + + + +## `admin query raw raw-get` + +- Raw database query + +**Usage:** `admin query raw raw-get ` + +###### **Arguments:** + +* `` — Map name +* `` — Key + + + +## `admin query raw raw-del` + +- Raw database delete (for string keys) + +**Usage:** `admin query raw raw-del ` + +###### **Arguments:** + +* `` — Map name +* `` — Key + + + +## `admin query raw raw-keys` + +- Raw database keys iteration + +**Usage:** `admin query raw raw-keys [PREFIX]` + +###### **Arguments:** + +* `` — Map name +* `` — Key prefix + + + +## `admin query raw raw-keys-sizes` + +- Raw database key size breakdown + +**Usage:** `admin query raw raw-keys-sizes [MAP] [PREFIX]` + +###### **Arguments:** + +* `` — Map name +* `` — Key prefix + + + +## `admin query raw raw-keys-total` + +- Raw database keys total bytes + +**Usage:** `admin query raw raw-keys-total [MAP] [PREFIX]` + +###### **Arguments:** + +* `` — Map name +* `` — Key prefix + + + +## `admin query raw raw-vals-sizes` + +- Raw database values size breakdown + +**Usage:** `admin query raw raw-vals-sizes [MAP] [PREFIX]` + +###### **Arguments:** + +* `` — Map name +* `` — Key prefix + + + +## `admin query raw raw-vals-total` + +- Raw database values total bytes + +**Usage:** `admin query raw raw-vals-total [MAP] [PREFIX]` + +###### **Arguments:** + +* `` — Map name +* `` — Key prefix + + + +## `admin query raw raw-iter` + +- Raw database items iteration + +**Usage:** `admin query raw raw-iter [PREFIX]` + +###### **Arguments:** + +* `` — Map name +* `` — Key prefix + + + +## `admin query raw raw-keys-from` + +- Raw database keys iteration + +**Usage:** `admin query raw raw-keys-from [OPTIONS] ` + +###### **Arguments:** + +* `` — Map name +* `` — Lower-bound + +###### **Options:** + +* `-l`, `--limit ` — Limit + + + +## `admin query raw raw-iter-from` + +- Raw database items iteration + +**Usage:** `admin query raw raw-iter-from [OPTIONS] ` + +###### **Arguments:** + +* `` — Map name +* `` — Lower-bound + +###### **Options:** + +* `-l`, `--limit ` — Limit + + + +## `admin query raw raw-count` + +- Raw database record count + +**Usage:** `admin query raw raw-count [MAP] [PREFIX]` + +###### **Arguments:** + +* `` — Map name +* `` — Key prefix + + + +## `admin query raw compact` + +- Compact database + +**Usage:** `admin query raw compact [OPTIONS]` + +###### **Options:** + +* `-m`, `--map ` +* `--start ` +* `--stop ` +* `--from ` +* `--into ` +* `--parallelism ` — There is one compaction job per column; then this controls how many columns are compacted in parallel. If zero, one compaction job is still run at a time here, but in exclusive-mode blocking any other automatic compaction jobs until complete +* `--exhaustive` + + Default value: `false` diff --git a/src/admin/admin.rs b/src/admin/admin.rs index 50b9db7c..e6479960 100644 --- a/src/admin/admin.rs +++ b/src/admin/admin.rs @@ -10,7 +10,7 @@ use crate::{ #[derive(Debug, Parser)] #[command(name = conduwuit_core::name(), version = conduwuit_core::version())] -pub(super) enum AdminCommand { +pub enum AdminCommand { #[command(subcommand)] /// - Commands for managing appservices Appservices(AppserviceCommand), diff --git a/src/admin/appservice/mod.rs b/src/admin/appservice/mod.rs index 2e0694aa..5e2712a9 100644 --- a/src/admin/appservice/mod.rs +++ b/src/admin/appservice/mod.rs @@ -7,7 +7,7 @@ use crate::admin_command_dispatch; #[derive(Debug, Subcommand)] #[admin_command_dispatch] -pub(super) enum AppserviceCommand { +pub enum AppserviceCommand { /// - Register an appservice using its registration YAML /// /// This command needs a YAML generated by an appservice (such as a bridge), diff --git a/src/admin/check/mod.rs b/src/admin/check/mod.rs index 30b335c4..a15968a7 100644 --- a/src/admin/check/mod.rs +++ b/src/admin/check/mod.rs @@ -7,6 +7,6 @@ use crate::admin_command_dispatch; #[admin_command_dispatch] #[derive(Debug, Subcommand)] -pub(super) enum CheckCommand { +pub enum CheckCommand { CheckAllUsers, } diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index fb8a3002..7a0769ab 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -11,7 +11,7 @@ use crate::admin_command_dispatch; #[admin_command_dispatch] #[derive(Debug, Subcommand)] -pub(super) enum DebugCommand { +pub enum DebugCommand { /// - Echo input of admin command Echo { message: Vec, diff --git a/src/admin/debug/tester.rs b/src/admin/debug/tester.rs index 0a2b1516..75da382b 100644 --- a/src/admin/debug/tester.rs +++ b/src/admin/debug/tester.rs @@ -4,7 +4,7 @@ use crate::{admin_command, admin_command_dispatch}; #[admin_command_dispatch] #[derive(Debug, clap::Subcommand)] -pub(crate) enum TesterCommand { +pub enum TesterCommand { Panic, Failure, Tester, diff --git a/src/admin/federation/mod.rs b/src/admin/federation/mod.rs index 2c539adc..48f79a56 100644 --- a/src/admin/federation/mod.rs +++ b/src/admin/federation/mod.rs @@ -8,7 +8,7 @@ use crate::admin_command_dispatch; #[admin_command_dispatch] #[derive(Debug, Subcommand)] -pub(super) enum FederationCommand { +pub enum FederationCommand { /// - List all rooms we are currently handling an incoming pdu from IncomingFederation, diff --git a/src/admin/media/mod.rs b/src/admin/media/mod.rs index d1e6cd3a..66d49959 100644 --- a/src/admin/media/mod.rs +++ b/src/admin/media/mod.rs @@ -9,7 +9,7 @@ use crate::admin_command_dispatch; #[admin_command_dispatch] #[derive(Debug, Subcommand)] -pub(super) enum MediaCommand { +pub enum MediaCommand { /// - Deletes a single media file from our database and on the filesystem /// via a single MXC URL or event ID (not redacted) Delete { @@ -90,10 +90,10 @@ pub(super) enum MediaCommand { #[arg(short, long, default_value("10000"))] timeout: u32, - #[arg(short, long, default_value("800"))] + #[arg(long, default_value("800"))] width: u32, - #[arg(short, long, default_value("800"))] + #[arg(long, default_value("800"))] height: u32, }, } diff --git a/src/admin/mod.rs b/src/admin/mod.rs index 1f777fa9..732b8ce0 100644 --- a/src/admin/mod.rs +++ b/src/admin/mod.rs @@ -33,6 +33,8 @@ conduwuit::mod_ctor! {} conduwuit::mod_dtor! {} conduwuit::rustc_flags_capture! {} +pub use crate::admin::AdminCommand; + /// Install the admin command processor pub async fn init(admin_service: &service::admin::Service) { _ = admin_service diff --git a/src/admin/query/account_data.rs b/src/admin/query/account_data.rs index 228d2120..2e044cef 100644 --- a/src/admin/query/account_data.rs +++ b/src/admin/query/account_data.rs @@ -8,7 +8,7 @@ use crate::{admin_command, admin_command_dispatch}; #[admin_command_dispatch] #[derive(Debug, Subcommand)] /// All the getters and iterators from src/database/key_value/account_data.rs -pub(crate) enum AccountDataCommand { +pub enum AccountDataCommand { /// - Returns all changes to the account data that happened after `since`. ChangesSince { /// Full user ID diff --git a/src/admin/query/appservice.rs b/src/admin/query/appservice.rs index 28bf6451..f9f15c25 100644 --- a/src/admin/query/appservice.rs +++ b/src/admin/query/appservice.rs @@ -6,7 +6,7 @@ use crate::Context; #[derive(Debug, Subcommand)] /// All the getters and iterators from src/database/key_value/appservice.rs -pub(crate) enum AppserviceCommand { +pub enum AppserviceCommand { /// - Gets the appservice registration info/details from the ID as a string GetRegistration { /// Appservice registration ID diff --git a/src/admin/query/globals.rs b/src/admin/query/globals.rs index c8c1f512..6e945145 100644 --- a/src/admin/query/globals.rs +++ b/src/admin/query/globals.rs @@ -6,7 +6,7 @@ use crate::Context; #[derive(Debug, Subcommand)] /// All the getters and iterators from src/database/key_value/globals.rs -pub(crate) enum GlobalsCommand { +pub enum GlobalsCommand { DatabaseVersion, CurrentCount, diff --git a/src/admin/query/mod.rs b/src/admin/query/mod.rs index da27eb1d..5b93086b 100644 --- a/src/admin/query/mod.rs +++ b/src/admin/query/mod.rs @@ -27,7 +27,7 @@ use crate::admin_command_dispatch; #[admin_command_dispatch] #[derive(Debug, Subcommand)] /// Query tables from database -pub(super) enum QueryCommand { +pub enum QueryCommand { /// - account_data.rs iterators and getters #[command(subcommand)] AccountData(AccountDataCommand), diff --git a/src/admin/query/presence.rs b/src/admin/query/presence.rs index 5b7ead4b..ccc3a431 100644 --- a/src/admin/query/presence.rs +++ b/src/admin/query/presence.rs @@ -7,7 +7,7 @@ use crate::Context; #[derive(Debug, Subcommand)] /// All the getters and iterators from src/database/key_value/presence.rs -pub(crate) enum PresenceCommand { +pub enum PresenceCommand { /// - Returns the latest presence event for the given user. GetPresence { /// Full user ID diff --git a/src/admin/query/pusher.rs b/src/admin/query/pusher.rs index 0d0e6cc9..3f294017 100644 --- a/src/admin/query/pusher.rs +++ b/src/admin/query/pusher.rs @@ -5,7 +5,7 @@ use ruma::OwnedUserId; use crate::Context; #[derive(Debug, Subcommand)] -pub(crate) enum PusherCommand { +pub enum PusherCommand { /// - Returns all the pushers for the user. GetPushers { /// Full user ID diff --git a/src/admin/query/raw.rs b/src/admin/query/raw.rs index 0e248c65..5165b61a 100644 --- a/src/admin/query/raw.rs +++ b/src/admin/query/raw.rs @@ -19,7 +19,7 @@ use crate::{admin_command, admin_command_dispatch}; #[derive(Debug, Subcommand)] #[allow(clippy::enum_variant_names)] /// Query tables from database -pub(crate) enum RawCommand { +pub enum RawCommand { /// - List database maps RawMaps, diff --git a/src/admin/query/resolver.rs b/src/admin/query/resolver.rs index 4a39a40e..5b2d8d3b 100644 --- a/src/admin/query/resolver.rs +++ b/src/admin/query/resolver.rs @@ -8,7 +8,7 @@ use crate::{admin_command, admin_command_dispatch}; #[admin_command_dispatch] #[derive(Debug, Subcommand)] /// Resolver service and caches -pub(crate) enum ResolverCommand { +pub enum ResolverCommand { /// Query the destinations cache DestinationsCache { server_name: Option, diff --git a/src/admin/query/room_alias.rs b/src/admin/query/room_alias.rs index b646beec..fac1dd0a 100644 --- a/src/admin/query/room_alias.rs +++ b/src/admin/query/room_alias.rs @@ -7,7 +7,7 @@ use crate::Context; #[derive(Debug, Subcommand)] /// All the getters and iterators from src/database/key_value/rooms/alias.rs -pub(crate) enum RoomAliasCommand { +pub enum RoomAliasCommand { ResolveLocalAlias { /// Full room alias alias: OwnedRoomAliasId, diff --git a/src/admin/query/room_state_cache.rs b/src/admin/query/room_state_cache.rs index c64cd173..798792d7 100644 --- a/src/admin/query/room_state_cache.rs +++ b/src/admin/query/room_state_cache.rs @@ -6,7 +6,7 @@ use ruma::{OwnedRoomId, OwnedServerName, OwnedUserId}; use crate::Context; #[derive(Debug, Subcommand)] -pub(crate) enum RoomStateCacheCommand { +pub enum RoomStateCacheCommand { ServerInRoom { server: OwnedServerName, room_id: OwnedRoomId, diff --git a/src/admin/query/room_timeline.rs b/src/admin/query/room_timeline.rs index 0fd22ca7..afcfec34 100644 --- a/src/admin/query/room_timeline.rs +++ b/src/admin/query/room_timeline.rs @@ -8,7 +8,7 @@ use crate::{admin_command, admin_command_dispatch}; #[admin_command_dispatch] #[derive(Debug, Subcommand)] /// Query tables from database -pub(crate) enum RoomTimelineCommand { +pub enum RoomTimelineCommand { Pdus { room_id: OwnedRoomOrAliasId, diff --git a/src/admin/query/sending.rs b/src/admin/query/sending.rs index 8b1676bc..b6350539 100644 --- a/src/admin/query/sending.rs +++ b/src/admin/query/sending.rs @@ -8,7 +8,7 @@ use crate::Context; #[derive(Debug, Subcommand)] /// All the getters and iterators from src/database/key_value/sending.rs -pub(crate) enum SendingCommand { +pub enum SendingCommand { /// - Queries database for all `servercurrentevent_data` ActiveRequests, diff --git a/src/admin/query/short.rs b/src/admin/query/short.rs index aa7c8666..3ebfbbcf 100644 --- a/src/admin/query/short.rs +++ b/src/admin/query/short.rs @@ -7,7 +7,7 @@ use crate::{admin_command, admin_command_dispatch}; #[admin_command_dispatch] #[derive(Debug, Subcommand)] /// Query tables from database -pub(crate) enum ShortCommand { +pub enum ShortCommand { ShortEventId { event_id: OwnedEventId, }, diff --git a/src/admin/query/users.rs b/src/admin/query/users.rs index 0f34d13f..2b5b3481 100644 --- a/src/admin/query/users.rs +++ b/src/admin/query/users.rs @@ -8,7 +8,7 @@ use crate::{admin_command, admin_command_dispatch}; #[admin_command_dispatch] #[derive(Debug, Subcommand)] /// All the getters and iterators from src/database/key_value/users.rs -pub(crate) enum UsersCommand { +pub enum UsersCommand { CountUsers, IterUsers, diff --git a/src/admin/room/alias.rs b/src/admin/room/alias.rs index 6b37ffe4..80e5d297 100644 --- a/src/admin/room/alias.rs +++ b/src/admin/room/alias.rs @@ -8,7 +8,7 @@ use ruma::{OwnedRoomAliasId, OwnedRoomId}; use crate::Context; #[derive(Debug, Subcommand)] -pub(crate) enum RoomAliasCommand { +pub enum RoomAliasCommand { /// - Make an alias point to a room. Set { #[arg(short, long)] diff --git a/src/admin/room/directory.rs b/src/admin/room/directory.rs index a6be9a15..cdefc99b 100644 --- a/src/admin/room/directory.rs +++ b/src/admin/room/directory.rs @@ -6,7 +6,7 @@ use ruma::OwnedRoomId; use crate::{Context, PAGE_SIZE, get_room_info}; #[derive(Debug, Subcommand)] -pub(crate) enum RoomDirectoryCommand { +pub enum RoomDirectoryCommand { /// - Publish a room to the room directory Publish { /// The room id of the room to publish diff --git a/src/admin/room/info.rs b/src/admin/room/info.rs index 1278e820..e35ddb27 100644 --- a/src/admin/room/info.rs +++ b/src/admin/room/info.rs @@ -7,7 +7,7 @@ use crate::{admin_command, admin_command_dispatch}; #[admin_command_dispatch] #[derive(Debug, Subcommand)] -pub(crate) enum RoomInfoCommand { +pub enum RoomInfoCommand { /// - List joined members in a room ListJoinedMembers { room_id: OwnedRoomId, diff --git a/src/admin/room/mod.rs b/src/admin/room/mod.rs index 26d2c2d8..00baf4c8 100644 --- a/src/admin/room/mod.rs +++ b/src/admin/room/mod.rs @@ -16,7 +16,7 @@ use crate::admin_command_dispatch; #[admin_command_dispatch] #[derive(Debug, Subcommand)] -pub(super) enum RoomCommand { +pub enum RoomCommand { /// - List all rooms the server knows about #[clap(alias = "list")] ListRooms { diff --git a/src/admin/room/moderation.rs b/src/admin/room/moderation.rs index 5fb5bb3e..4d106977 100644 --- a/src/admin/room/moderation.rs +++ b/src/admin/room/moderation.rs @@ -12,7 +12,7 @@ use crate::{admin_command, admin_command_dispatch, get_room_info}; #[admin_command_dispatch] #[derive(Debug, Subcommand)] -pub(crate) enum RoomModerationCommand { +pub enum RoomModerationCommand { /// - Bans a room from local users joining and evicts all our local users /// (including server /// admins) diff --git a/src/admin/server/mod.rs b/src/admin/server/mod.rs index 6b99e5de..cf46d034 100644 --- a/src/admin/server/mod.rs +++ b/src/admin/server/mod.rs @@ -9,7 +9,7 @@ use crate::admin_command_dispatch; #[admin_command_dispatch] #[derive(Debug, Subcommand)] -pub(super) enum ServerCommand { +pub enum ServerCommand { /// - Time elapsed since startup Uptime, diff --git a/src/admin/user/mod.rs b/src/admin/user/mod.rs index 645d3637..656cacaf 100644 --- a/src/admin/user/mod.rs +++ b/src/admin/user/mod.rs @@ -8,7 +8,7 @@ use crate::admin_command_dispatch; #[admin_command_dispatch] #[derive(Debug, Subcommand)] -pub(super) enum UserCommand { +pub enum UserCommand { /// - Create a new user #[clap(alias = "create")] CreateUser { diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 2d8d26b5..cddf4156 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -14,6 +14,13 @@ rust-version.workspace = true version.workspace = true metadata.crane.workspace = true +[lib] +path = "mod.rs" +crate-type = [ + "rlib", +# "dylib", +] + [package.metadata.deb] name = "conduwuit" maintainer = "strawberry " diff --git a/src/main/mod.rs b/src/main/mod.rs new file mode 100644 index 00000000..ce9e3b9c --- /dev/null +++ b/src/main/mod.rs @@ -0,0 +1,14 @@ +#![type_length_limit = "49152"] //TODO: reduce me + +use conduwuit_core::rustc_flags_capture; + +pub(crate) mod clap; +mod logging; +mod mods; +mod restart; +mod runtime; +mod sentry; +mod server; +mod signal; + +rustc_flags_capture! {} diff --git a/xtask/generate-admin-command/Cargo.toml b/xtask/generate-admin-command/Cargo.toml new file mode 100644 index 00000000..5f27ee0c --- /dev/null +++ b/xtask/generate-admin-command/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "xtask-admin-command" +authors.workspace = true +categories.workspace = true +description.workspace = true +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true +rust-version.workspace = true +version.workspace = true + +[dependencies] +clap-markdown = "0.1.5" +clap_builder = { version = "4.5.38", default-features = false } +clap_mangen = "0.2" + +conduwuit-admin.workspace = true + +# Hack to prevent rebuilds +conduwuit.workspace = true + +[lints] +workspace = true diff --git a/xtask/generate-admin-command/src/main.rs b/xtask/generate-admin-command/src/main.rs new file mode 100644 index 00000000..46e7dad5 --- /dev/null +++ b/xtask/generate-admin-command/src/main.rs @@ -0,0 +1,63 @@ +use std::{ + fs::{self, File}, + io::{self, Write}, + path::Path, +}; + +use clap_builder::{Command, CommandFactory}; +use conduwuit_admin::AdminCommand; + +fn main() -> Result<(), Box> { + let mut args = std::env::args().skip(1); + let task = args.next(); + match task { + | None => todo!(), + | Some(t) => match t.as_str() { + | "man" => { + let dir = Path::new("./admin-man"); + gen_manpages(dir)?; + }, + | "md" => { + let command = AdminCommand::command().name("admin"); + + let res = clap_markdown::help_markdown_command_custom( + &command, + &clap_markdown::MarkdownOptions::default().show_footer(false), + ) + .replace("\n\r", "\n") + .replace("\r\n", "\n") + .replace(" \n", "\n"); + + let mut file = File::create(Path::new("./docs/admin_reference.md"))?; + Write::write_all(&mut file, res.trim_end().as_bytes())?; + file.write(b"\n")?; + }, + | invalid => return Err(format!("Invalid task name: {invalid}").into()), + }, + } + Ok(()) +} + +fn gen_manpages(dir: &Path) -> Result<(), io::Error> { + fn r#gen(dir: &Path, c: &Command, prefix: Option<&str>) -> Result<(), io::Error> { + fs::create_dir_all(dir)?; + let sub_name = c.get_display_name().unwrap_or_else(|| c.get_name()); + let name = if let Some(prefix) = prefix { + format!("{prefix}-{sub_name}") + } else { + sub_name.to_owned() + }; + + let mut out = File::create(dir.join(format!("{name}.1")))?; + let clap_mangen = clap_mangen::Man::new(c.to_owned().disable_help_flag(true)); + clap_mangen.render(&mut out)?; + + for sub in c.get_subcommands() { + r#gen(&dir.join(sub_name), sub, Some(&name))?; + } + + Ok(()) + } + + r#gen(dir, &AdminCommand::command().name("admin"), None) +} diff --git a/xtask/main/Cargo.toml b/xtask/main/Cargo.toml new file mode 100644 index 00000000..70c0c34b --- /dev/null +++ b/xtask/main/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "xtask" +authors.workspace = true +categories.workspace = true +description.workspace = true +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true +rust-version.workspace = true +version.workspace = true + +[dependencies] +clap.workspace = true +# Required for working with JSON output from cargo metadata +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" + +[lints] +workspace = true diff --git a/xtask/main/src/main.rs b/xtask/main/src/main.rs new file mode 100644 index 00000000..0b244114 --- /dev/null +++ b/xtask/main/src/main.rs @@ -0,0 +1,11 @@ +use std::{env, process::Command}; + +fn main() -> Result<(), Box> { + let mut child = Command::new("cargo").args(["run", "--package", "xtask-admin-command", "--"].into_iter().map(ToOwned::to_owned).chain(env::args().skip(2))) + // .stdout(Stdio::piped()) + // .stderr(Stdio::piped()) + .spawn() + .expect("failed to execute child"); + child.wait()?; + Ok(()) +} From 28a29c3a7b2b01b6c26bc9e92dc4ce2d1fcf9164 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 6 Jul 2025 21:59:20 +0100 Subject: [PATCH 2114/2291] feat: Generate binary documentation Also refactors main.rs/mod.rs to silence clippy --- Cargo.lock | 2 +- Cargo.toml | 2 +- docs/server_reference.md | 21 +++ src/main/clap.rs | 36 +++--- src/main/main.rs | 121 +----------------- src/main/mod.rs | 119 ++++++++++++++++- src/main/server.rs | 7 +- xtask/generate-admin-command/src/main.rs | 63 --------- .../Cargo.toml | 2 +- xtask/generate-generate-commands/src/main.rs | 113 ++++++++++++++++ xtask/main/Cargo.toml | 2 +- xtask/main/src/main.rs | 2 +- 12 files changed, 281 insertions(+), 209 deletions(-) create mode 100644 docs/server_reference.md delete mode 100644 xtask/generate-admin-command/src/main.rs rename xtask/{generate-admin-command => generate-generate-commands}/Cargo.toml (94%) create mode 100644 xtask/generate-generate-commands/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index fe8cb16d..d950e9da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6129,7 +6129,7 @@ dependencies = [ ] [[package]] -name = "xtask-admin-command" +name = "xtask-generate-commands" version = "0.5.0-rc.6" dependencies = [ "clap-markdown", diff --git a/Cargo.toml b/Cargo.toml index 03c5b489..ef917332 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -768,7 +768,7 @@ inherits = "dev" # '-Clink-arg=-Wl,-z,nodlopen', # '-Clink-arg=-Wl,-z,nodelete', #] -[profile.dev.package.xtask-admin-command] +[profile.dev.package.xtask-generate-commands] inherits = "dev" [profile.dev.package.conduwuit] inherits = "dev" diff --git a/docs/server_reference.md b/docs/server_reference.md new file mode 100644 index 00000000..e34bc51e --- /dev/null +++ b/docs/server_reference.md @@ -0,0 +1,21 @@ +# Command-Line Help for `continuwuity` + +This document contains the help content for the `continuwuity` command-line program. + +**Command Overview:** + +* [`continuwuity`↴](#continuwuity) + +## `continuwuity` + +a very cool Matrix chat homeserver written in Rust + +**Usage:** `continuwuity [OPTIONS]` + +###### **Options:** + +* `-c`, `--config ` — Path to the config TOML file (optional) +* `-O`, `--option

To get started, you can:

From 1bc663e1c8065c6bf8c489d3c419c8696e7b0dde Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 24 Jul 2025 13:37:52 +0100 Subject: [PATCH 2193/2291] docs: Fix spacing at the top --- theme/css/chrome.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/theme/css/chrome.css b/theme/css/chrome.css index f14ffc2c..0e37be26 100644 --- a/theme/css/chrome.css +++ b/theme/css/chrome.css @@ -605,3 +605,8 @@ ul#searchresults span.teaser em { margin-inline-start: -14px; width: 14px; } + +/* HACK: Stop the keyboard shortcuts from adding a giant space at the top */ +#mdbook-help-container { + display: none; +} From b7a04422981b3eabea37bcea97c978bfc4c72b7f Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 23 Jul 2025 00:24:27 +0100 Subject: [PATCH 2194/2291] feat: Musl images in docker Not working at the moment, need to upgrade the rust-rocksdb and possibly zstd to stop them force-enabling dynamic libclang --- Cargo.lock | 1 + docker/Dockerfile | 41 +++++---- docker/musl.Dockerfile | 201 +++++++++++++++++++++++++++++++++++++++++ src/main/Cargo.toml | 9 ++ 4 files changed, 233 insertions(+), 19 deletions(-) create mode 100644 docker/musl.Dockerfile diff --git a/Cargo.lock b/Cargo.lock index 22c90e17..1866a691 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -847,6 +847,7 @@ dependencies = [ name = "conduwuit" version = "0.5.0-rc.6" dependencies = [ + "bindgen 0.71.1", "clap", "conduwuit_admin", "conduwuit_api", diff --git a/docker/Dockerfile b/docker/Dockerfile index bd6e72d1..55150902 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -78,7 +78,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ WORKDIR /app COPY ./rust-toolchain.toml . RUN rustc --version \ - && rustup target add $(xx-cargo --print-target-triple) + && xx-cargo --setup-target-triple # Build binary # We disable incremental compilation to save disk space, as it only produces a minimal speedup for this case. @@ -87,8 +87,10 @@ RUN echo "CARGO_INCREMENTAL=0" >> /etc/environment # Configure pkg-config RUN <> /etc/environment - echo "PKG_CONFIG=/usr/bin/$(xx-info)-pkg-config" >> /etc/environment + if command -v "$(xx-info)-pkg-config" >/dev/null 2>/dev/null; then + echo "PKG_CONFIG_LIBDIR=/usr/lib/$(xx-info)/pkgconfig" >> /etc/environment + echo "PKG_CONFIG=/usr/bin/$(xx-info)-pkg-config" >> /etc/environment + fi echo "PKG_CONFIG_ALLOW_CROSS=true" >> /etc/environment EOF @@ -109,16 +111,17 @@ RUN <> /etc/environment - echo "CXXFLAGS='${CXXFLAGS} -march=${TARGET_CPU}'" >> /etc/environment - echo "RUSTFLAGS='${RUSTFLAGS} -C target-cpu=${TARGET_CPU}'" >> /etc/environment - fi + set -o allexport + set -o xtrace + . /etc/environment + if [ -n "${TARGET_CPU}" ]; then + echo "CFLAGS='${CFLAGS} -march=${TARGET_CPU}'" >> /etc/environment + echo "CXXFLAGS='${CXXFLAGS} -march=${TARGET_CPU}'" >> /etc/environment + echo "RUSTFLAGS='${RUSTFLAGS} -C target-cpu=${TARGET_CPU}'" >> /etc/environment + fi EOF # Prepare output directories @@ -136,12 +139,12 @@ ARG TARGETPLATFORM RUN xx-cargo --print-target-triple # Conduwuit version info -ARG GIT_COMMIT_HASH= -ARG GIT_COMMIT_HASH_SHORT= -ARG GIT_REMOTE_URL= -ARG GIT_REMOTE_COMMIT_URL= -ARG CONDUWUIT_VERSION_EXTRA= -ARG CONTINUWUITY_VERSION_EXTRA= +ARG GIT_COMMIT_HASH +ARG GIT_COMMIT_HASH_SHORT +ARG GIT_REMOTE_URL +ARG GIT_REMOTE_COMMIT_URL +ARG CONDUWUIT_VERSION_EXTRA +ARG CONTINUWUITY_VERSION_EXTRA ENV GIT_COMMIT_HASH=$GIT_COMMIT_HASH ENV GIT_COMMIT_HASH_SHORT=$GIT_COMMIT_HASH_SHORT ENV GIT_REMOTE_URL=$GIT_REMOTE_URL @@ -169,7 +172,7 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ jq -r ".packages[] | select(.name == \"$PACKAGE\") | .targets[] | select( .kind | map(. == \"bin\") | any ) | .name")) for BINARY in "${BINARIES[@]}"; do echo $BINARY - xx-verify $TARGET_DIR/$(xx-cargo --print-target-triple)/release/$BINARY + xx-verify $TARGET_DIR/$(xx-cargo --print-target-triple)/release/$BINARY cp $TARGET_DIR/$(xx-cargo --print-target-triple)/release/$BINARY /out/sbin/$BINARY done EOF diff --git a/docker/musl.Dockerfile b/docker/musl.Dockerfile new file mode 100644 index 00000000..d5317d15 --- /dev/null +++ b/docker/musl.Dockerfile @@ -0,0 +1,201 @@ +# Why does this exist? +# Debian doesn't provide prebuilt musl packages +# rocksdb requires a prebuilt liburing, and linking fails if a gnu one is provided + +ARG RUST_VERSION=1 +ARG ALPINE_VERSION=3.22 + +FROM --platform=$BUILDPLATFORM docker.io/tonistiigi/xx AS xx +FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-alpine${ALPINE_VERSION} AS base +FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-alpine${ALPINE_VERSION} AS toolchain + +# Install repo tools and dependencies +RUN --mount=type=cache,target=/etc/apk/cache apk add \ + build-base pkgconfig make jq bash \ + curl git file \ + llvm-dev clang clang-dev lld + + +# Developer tool versions +# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall +ENV BINSTALL_VERSION=1.13.0 +# renovate: datasource=github-releases depName=psastras/sbom-rs +ENV CARGO_SBOM_VERSION=0.9.1 +# renovate: datasource=crate depName=lddtree +ENV LDDTREE_VERSION=0.3.7 + +# Install unpackaged tools +RUN <> /etc/environment + +# Configure pkg-config +RUN </dev/null 2>/dev/null; then + echo "PKG_CONFIG_LIBDIR=/usr/lib/$(xx-info)/pkgconfig" >> /etc/environment + echo "PKG_CONFIG=/usr/bin/$(xx-info)-pkg-config" >> /etc/environment + fi + echo "PKG_CONFIG_ALLOW_CROSS=true" >> /etc/environment +EOF + +# Configure cc to use clang version +RUN <> /etc/environment + echo "CXX=clang++" >> /etc/environment +EOF + +# Cross-language LTO +RUN <> /etc/environment + echo "CXXFLAGS=-flto" >> /etc/environment + # Linker is set to target-compatible clang by xx + echo "RUSTFLAGS='-Clinker-plugin-lto -Clink-arg=-fuse-ld=lld'" >> /etc/environment +EOF + +# Apply CPU-specific optimizations if TARGET_CPU is provided +ARG TARGET_CPU + +RUN <> /etc/environment + echo "CXXFLAGS='${CXXFLAGS} -march=${TARGET_CPU}'" >> /etc/environment + echo "RUSTFLAGS='${RUSTFLAGS} -C target-cpu=${TARGET_CPU}'" >> /etc/environment + fi +EOF + +# Prepare output directories +RUN mkdir /out + +FROM toolchain AS builder + + +# Get source +COPY . . + +ARG TARGETPLATFORM + +# Verify environment configuration +RUN xx-cargo --print-target-triple + +# Conduwuit version info +ARG GIT_COMMIT_HASH +ARG GIT_COMMIT_HASH_SHORT +ARG GIT_REMOTE_URL +ARG GIT_REMOTE_COMMIT_URL +ARG CONDUWUIT_VERSION_EXTRA +ARG CONTINUWUITY_VERSION_EXTRA +ENV GIT_COMMIT_HASH=$GIT_COMMIT_HASH +ENV GIT_COMMIT_HASH_SHORT=$GIT_COMMIT_HASH_SHORT +ENV GIT_REMOTE_URL=$GIT_REMOTE_URL +ENV GIT_REMOTE_COMMIT_URL=$GIT_REMOTE_COMMIT_URL +ENV CONDUWUIT_VERSION_EXTRA=$CONDUWUIT_VERSION_EXTRA +ENV CONTINUWUITY_VERSION_EXTRA=$CONTINUWUITY_VERSION_EXTRA + +ARG RUST_PROFILE=release + +# Build the binary +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git/db \ + --mount=type=cache,target=/app/target,id=cargo-target-${TARGET_CPU}-${TARGETPLATFORM}-musl-${RUST_PROFILE} \ + bash <<'EOF' + set -o allexport + set -o xtrace + . /etc/environment + TARGET_DIR=($(cargo metadata --no-deps --format-version 1 | \ + jq -r ".target_directory")) + mkdir /out/sbin + PACKAGE=conduwuit + xx-cargo build --locked --profile ${RUST_PROFILE} \ + -p $PACKAGE --features libclang_static; + BINARIES=($(cargo metadata --no-deps --format-version 1 | \ + jq -r ".packages[] | select(.name == \"$PACKAGE\") | .targets[] | select( .kind | map(. == \"bin\") | any ) | .name")) + for BINARY in "${BINARIES[@]}"; do + echo $BINARY + xx-verify $TARGET_DIR/$(xx-cargo --print-target-triple)/release/$BINARY + cp $TARGET_DIR/$(xx-cargo --print-target-triple)/release/$BINARY /out/sbin/$BINARY + done +EOF + +# Generate Software Bill of Materials (SBOM) +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/usr/local/cargo/git/db \ + bash <<'EOF' + set -o xtrace + mkdir /out/sbom + typeset -A PACKAGES + for BINARY in /out/sbin/*; do + BINARY_BASE=$(basename ${BINARY}) + package=$(cargo metadata --no-deps --format-version 1 | jq -r ".packages[] | select(.targets[] | select( .kind | map(. == \"bin\") | any ) | .name == \"$BINARY_BASE\") | .name") + if [ -z "$package" ]; then + continue + fi + PACKAGES[$package]=1 + done + for PACKAGE in $(echo ${!PACKAGES[@]}); do + echo $PACKAGE + cargo sbom --cargo-package $PACKAGE > /out/sbom/$PACKAGE.spdx.json + done +EOF + +# Extract dynamically linked dependencies +RUN < Date: Thu, 24 Jul 2025 21:51:52 +0100 Subject: [PATCH 2195/2291] chore: Update rocksdb, feature flag changes Most of the way to static musl builds, just zlib I think --- .forgejo/workflows/rust-checks.yml | 4 ++-- CONTRIBUTING.md | 6 +++--- Cargo.lock | 29 +++++++++++++++++++++++------ Cargo.toml | 2 +- docker/musl.Dockerfile | 2 +- docs/deploying/generic.md | 2 +- engage.toml | 6 +++--- src/database/Cargo.toml | 8 ++++++++ src/main/Cargo.toml | 27 +++++++++++++++++++++------ tests/cargo_smoke.sh | 2 +- 10 files changed, 64 insertions(+), 24 deletions(-) diff --git a/.forgejo/workflows/rust-checks.yml b/.forgejo/workflows/rust-checks.yml index 0595c053..c46363a0 100644 --- a/.forgejo/workflows/rust-checks.yml +++ b/.forgejo/workflows/rust-checks.yml @@ -73,7 +73,7 @@ jobs: run: | cargo clippy \ --workspace \ - --all-features \ + --features full \ --locked \ --no-deps \ --profile test \ @@ -133,7 +133,7 @@ jobs: run: | cargo test \ --workspace \ - --all-features \ + --features full \ --locked \ --profile test \ --all-targets \ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2e11cff4..b5ecf38a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,11 +65,11 @@ Tests, compilation, and linting can be run with standard Cargo commands: cargo test # Check compilation -cargo check --workspace --all-features +cargo check --workspace --features full # Run lints -cargo clippy --workspace --all-features -# Auto-fix: cargo clippy --workspace --all-features --fix --allow-staged; +cargo clippy --workspace --features full +# Auto-fix: cargo clippy --workspace --features full --fix --allow-staged; # Format code (must use nightly) cargo +nightly fmt diff --git a/Cargo.lock b/Cargo.lock index 1866a691..bfab6255 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -543,6 +543,24 @@ dependencies = [ "syn", ] +[[package]] +name = "bindgen" +version = "0.72.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f72209734318d0b619a5e0f5129918b848c416e122a3c4ce054e03cb87b726f" +dependencies = [ + "bitflags 2.9.1", + "cexpr", + "clang-sys", + "itertools 0.12.1", + "proc-macro2", + "quote", + "regex", + "rustc-hash 2.1.1", + "shlex", + "syn", +] + [[package]] name = "bit_field" version = "0.10.2" @@ -847,7 +865,6 @@ dependencies = [ name = "conduwuit" version = "0.5.0-rc.6" dependencies = [ - "bindgen 0.71.1", "clap", "conduwuit_admin", "conduwuit_api", @@ -4117,10 +4134,10 @@ dependencies = [ [[package]] name = "rust-librocksdb-sys" -version = "0.33.0+9.11.1" -source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=fc9a99ac54a54208f90fdcba33ae6ee8bc3531dd#fc9a99ac54a54208f90fdcba33ae6ee8bc3531dd" +version = "0.38.0+10.4.2" +source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=01e1128898fc4bbb776e7a6deec2aa3b675b0442#01e1128898fc4bbb776e7a6deec2aa3b675b0442" dependencies = [ - "bindgen 0.71.1", + "bindgen 0.72.0", "bzip2-sys", "cc", "glob", @@ -4134,8 +4151,8 @@ dependencies = [ [[package]] name = "rust-rocksdb" -version = "0.37.0" -source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=fc9a99ac54a54208f90fdcba33ae6ee8bc3531dd#fc9a99ac54a54208f90fdcba33ae6ee8bc3531dd" +version = "0.42.1" +source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=01e1128898fc4bbb776e7a6deec2aa3b675b0442#01e1128898fc4bbb776e7a6deec2aa3b675b0442" dependencies = [ "libc", "rust-librocksdb-sys", diff --git a/Cargo.toml b/Cargo.toml index 9cb5ff84..e95567bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -391,7 +391,7 @@ features = [ [workspace.dependencies.rust-rocksdb] git = "https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1" -rev = "fc9a99ac54a54208f90fdcba33ae6ee8bc3531dd" +rev = "01e1128898fc4bbb776e7a6deec2aa3b675b0442" default-features = false features = [ "multi-threaded-cf", diff --git a/docker/musl.Dockerfile b/docker/musl.Dockerfile index d5317d15..b55aecb0 100644 --- a/docker/musl.Dockerfile +++ b/docker/musl.Dockerfile @@ -133,7 +133,7 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ mkdir /out/sbin PACKAGE=conduwuit xx-cargo build --locked --profile ${RUST_PROFILE} \ - -p $PACKAGE --features libclang_static; + -p $PACKAGE --no-default-features --features bindgen-static,release_max_log_level,standard; BINARIES=($(cargo metadata --no-deps --format-version 1 | \ jq -r ".packages[] | select(.name == \"$PACKAGE\") | .targets[] | select( .kind | map(. == \"bin\") | any ) | .name")) for BINARY in "${BINARIES[@]}"; do diff --git a/docs/deploying/generic.md b/docs/deploying/generic.md index 3f9d1a16..9f5051f7 100644 --- a/docs/deploying/generic.md +++ b/docs/deploying/generic.md @@ -44,7 +44,7 @@ If wanting to build using standard Rust toolchains, make sure you install: - (On linux) `pkg-config` on the compiling machine to allow finding `liburing` - A C++ compiler and (on linux) `libclang` for RocksDB -You can build Continuwuity using `cargo build --release --all-features`. +You can build Continuwuity using `cargo build --release`. ### Building with Nix diff --git a/engage.toml b/engage.toml index 5048fde2..92e9d399 100644 --- a/engage.toml +++ b/engage.toml @@ -83,7 +83,7 @@ env DIRENV_DEVSHELL=all-features \ --workspace \ --locked \ --profile test \ - --all-features \ + --features full \ --no-deps \ --document-private-items \ --color always @@ -96,7 +96,7 @@ script = """ direnv exec . \ cargo clippy \ --workspace \ - --all-features \ + --features full \ --locked \ --profile test \ --color=always \ @@ -114,7 +114,7 @@ env DIRENV_DEVSHELL=all-features \ --workspace \ --locked \ --profile test \ - --all-features \ + --features full \ --color=always \ -- \ -D warnings diff --git a/src/database/Cargo.toml b/src/database/Cargo.toml index 55d4793f..9f51f366 100644 --- a/src/database/Cargo.toml +++ b/src/database/Cargo.toml @@ -44,6 +44,14 @@ zstd_compression = [ "conduwuit-core/zstd_compression", "rust-rocksdb/zstd", ] +bindgen-static = [ + # "bindgen/static" + # "clang-sys/static" + "rust-rocksdb/bindgen-static" +] +bindgen-runtime = [ + "rust-rocksdb/bindgen-runtime" +] [dependencies] async-channel.workspace = true diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 3b97f625..0d7dd844 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -43,6 +43,11 @@ assets = [ [features] default = [ + "standard", + "release_max_log_level", + "bindgen-runtime", # replace with bindgen-static on alpine +] +standard = [ "blurhashing", "brotli_compression", "element_hacks", @@ -52,10 +57,17 @@ default = [ "jemalloc_conf", "journald", "media_thumbnail", - "release_max_log_level", "systemd", "url_preview", - "zstd_compression", + "zstd_compression" +] +full = [ + "standard", + "hardened_malloc", + "jemalloc_prof", + "perf_measurements", + "tokio_console" + # sentry_telemetry ] blurhashing = [ @@ -161,14 +173,17 @@ zstd_compression = [ conduwuit_mods = [ "conduwuit-core/conduwuit_mods", ] - -libclang_static = [ - "bindgen/static" +bindgen-static = [ + # "bindgen/static" # "clang-sys/static" + "conduwuit-database/bindgen-static" +] +bindgen-runtime = [ + "conduwuit-database/bindgen-runtime" ] [build-dependencies] -bindgen = {version = "0.71.1", default-features = false} +# bindgen = {version = "0.71.1", default-features = false} # clang-sys = {version = "1", default-features = false} [dependencies] diff --git a/tests/cargo_smoke.sh b/tests/cargo_smoke.sh index 946790c3..e8bb5512 100755 --- a/tests/cargo_smoke.sh +++ b/tests/cargo_smoke.sh @@ -48,7 +48,7 @@ vector () { VECTOR_OPTS=$@ element "$TOOLCHAIN" $VECTOR_OPTS --no-default-features element "$TOOLCHAIN" $VECTOR_OPTS --features=default - element "$TOOLCHAIN" $VECTOR_OPTS --all-features + element "$TOOLCHAIN" $VECTOR_OPTS --features full } matrix () { From 205506f206fef4c5fb51141449476fab8af151ef Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 24 Jul 2025 22:18:10 +0100 Subject: [PATCH 2196/2291] chore: Update deps --- Cargo.lock | 223 ++++++++++++++++++++++++++++------------------------- 1 file changed, 118 insertions(+), 105 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bfab6255..837e033a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,9 +52,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.18" +version = "0.6.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" dependencies = [ "anstyle", "anstyle-parse", @@ -73,27 +73,27 @@ checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" [[package]] name = "anstyle-parse" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" dependencies = [ "windows-sys 0.59.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.8" +version = "3.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6680de5231bd6ee4c6191b8a1325daa282b415391ec9d3a37bd34f2060dc73fa" +checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" dependencies = [ "anstyle", "once_cell_polyfill", @@ -217,9 +217,9 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.4.25" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40f6024f3f856663b45fd0c9b6f2024034a702f453549449e0d84a305900dad4" +checksum = "ddb939d66e4ae03cee6091612804ba446b12878410cfa17f785f4dd67d4014e8" dependencies = [ "brotli", "flate2", @@ -301,18 +301,18 @@ dependencies = [ [[package]] name = "avif-serialize" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98922d6a4cfbcb08820c69d8eeccc05bb1f29bfa06b4f5b1dbfe9a868bd7608e" +checksum = "2ea8ef51aced2b9191c08197f55450d830876d9933f8f48a429b354f1d496b42" dependencies = [ "arrayvec", ] [[package]] name = "aws-lc-rs" -version = "1.13.1" +version = "1.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fcc8f365936c834db5514fc45aee5b1202d677e6b40e48468aaaa8183ca8c7" +checksum = "5c953fe1ba023e6b7730c0d4b031d06f267f23a46167dcbd40316644b10a17ba" dependencies = [ "aws-lc-sys", "zeroize", @@ -320,9 +320,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b1d86e7705efe1be1b569bab41d4fa1e14e220b60a160f78de2db687add079" +checksum = "dbfd150b5dbdb988bcc8fb1fe787eb6b7ee6180ca24da683b61ea5405f3d43ff" dependencies = [ "bindgen 0.69.5", "cc", @@ -552,7 +552,7 @@ dependencies = [ "bitflags 2.9.1", "cexpr", "clang-sys", - "itertools 0.12.1", + "itertools 0.13.0", "proc-macro2", "quote", "regex", @@ -647,9 +647,9 @@ checksum = "f4ad8f11f288f48ca24471bbd51ac257aaeaaa07adae295591266b792902ae64" [[package]] name = "bumpalo" -version = "3.18.1" +version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" [[package]] name = "bytemuck" @@ -703,9 +703,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.27" +version = "1.2.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc" +checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" dependencies = [ "jobserver", "libc", @@ -774,9 +774,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.40" +version = "4.5.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" +checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9" dependencies = [ "clap_builder", "clap_derive", @@ -793,9 +793,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.40" +version = "4.5.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" +checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d" dependencies = [ "anstream", "anstyle", @@ -805,9 +805,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.40" +version = "4.5.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" +checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" dependencies = [ "heck", "proc-macro2", @@ -823,9 +823,9 @@ checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "clap_mangen" -version = "0.2.26" +version = "0.2.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "724842fa9b144f9b89b3f3d371a89f3455eea660361d13a554f68f8ae5d6c13a" +checksum = "e2fb6d3f935bbb9819391528b0e7cf655e78a0bc7a7c3d227211a1d24fc11db1" dependencies = [ "clap", "roff", @@ -848,9 +848,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "colorchoice" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" [[package]] name = "concurrent-queue" @@ -1173,15 +1173,15 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "const-str" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e991226a70654b49d34de5ed064885f0bef0348a8e70018b8ff1ac80aa984a2" +checksum = "041fbfcf8e7054df725fb9985297e92422cdc80fcf313665f5ca3d761bb63f4c" [[package]] name = "const_panic" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2459fc9262a1aa204eb4b5764ad4f189caec88aea9634389c0a25f8be7f6265e" +checksum = "b98d1483e98c9d67f341ab4b3915cfdc54740bd6f5cccc9226ee0535d86aa8fb" [[package]] name = "convert_case" @@ -1238,9 +1238,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.4.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" dependencies = [ "cfg-if", ] @@ -1346,7 +1346,7 @@ dependencies = [ "futures-core", "mio", "parking_lot", - "rustix 1.0.7", + "rustix 1.0.8", "signal-hook", "signal-hook-mio", "winapi", @@ -1363,9 +1363,9 @@ dependencies = [ [[package]] name = "crunchy" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" [[package]] name = "crypto-common" @@ -1531,9 +1531,9 @@ dependencies = [ [[package]] name = "ed25519-dalek" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" +checksum = "70e796c081cee67dc755e1a36a0a172b897fab85fc3f6bc48307991f64e4eca9" dependencies = [ "curve25519-dalek", "ed25519", @@ -1885,9 +1885,9 @@ dependencies = [ [[package]] name = "gif" -version = "0.13.1" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2" +checksum = "4ae047235e33e2829703574b54fdec96bfbad892062d97fed2f76022287de61b" dependencies = [ "color_quant", "weezl", @@ -1907,9 +1907,9 @@ checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "h2" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9421a676d1b147b16b82c9225157dc629087ef8ec4d5e2960f9437a90dac0a5" +checksum = "17da50a276f1e01e0ba6c029e47b7100754904ee8a278f886546e98575380785" dependencies = [ "atomic-waker", "bytes", @@ -1917,7 +1917,7 @@ dependencies = [ "futures-core", "futures-sink", "http", - "indexmap 2.9.0", + "indexmap 2.10.0", "slab", "tokio", "tokio-util", @@ -2047,7 +2047,7 @@ dependencies = [ "idna", "ipnet", "once_cell", - "rand 0.9.1", + "rand 0.9.2", "ring", "serde", "thiserror 2.0.12", @@ -2091,7 +2091,7 @@ dependencies = [ "moka", "once_cell", "parking_lot", - "rand 0.9.1", + "rand 0.9.2", "resolv-conf", "serde", "smallvec", @@ -2240,7 +2240,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", - "webpki-roots 1.0.1", + "webpki-roots 1.0.2", ] [[package]] @@ -2433,9 +2433,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", "hashbrown 0.15.4", @@ -2465,6 +2465,17 @@ dependencies = [ "syn", ] +[[package]] +name = "io-uring" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d93587f37623a1a17d94ef2bc9ada592f5465fe7732084ab7beefabe5c77c0c4" +dependencies = [ + "bitflags 2.9.1", + "cfg-if", + "libc", +] + [[package]] name = "ipaddress" version = "0.1.3" @@ -2548,9 +2559,9 @@ dependencies = [ [[package]] name = "jpeg-decoder" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" +checksum = "00810f1d8b74be64b13dbf3db89ac67740615d6c891f0e7b6179326533011a07" [[package]] name = "js-sys" @@ -2649,9 +2660,9 @@ checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libfuzzer-sys" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf78f52d400cf2d84a3a973a78a592b4adc535739e0a5597a0da6f0c357adc75" +checksum = "5037190e1f70cbeef565bd267599242926f724d3b8a9f510fd7e0b540cfa4404" dependencies = [ "arbitrary", "cc", @@ -3131,7 +3142,7 @@ checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" dependencies = [ "futures-core", "futures-sink", - "indexmap 2.9.0", + "indexmap 2.10.0", "js-sys", "once_cell", "pin-project-lite", @@ -3307,7 +3318,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.9.0", + "indexmap 2.10.0", ] [[package]] @@ -3398,12 +3409,12 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "plist" -version = "1.7.2" +version = "1.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d77244ce2d584cd84f6a15f86195b8c9b2a0dfbfd817c09e0464244091a58ed" +checksum = "3af6b589e163c5a788fab00ce0c0366f6efbb9959c2f9874b224936af7fce7e1" dependencies = [ "base64 0.22.1", - "indexmap 2.9.0", + "indexmap 2.10.0", "quick-xml", "serde", "time", @@ -3460,9 +3471,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "prettyplease" -version = "0.2.35" +version = "0.2.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "061c1221631e079b26479d25bbf2275bfe5917ae8419cd7e34f13bfc2aa7539a" +checksum = "ff24dfcda44452b9816fff4cd4227e1bb73ff5a2f1bc1105aa92fb8565ce44d2" dependencies = [ "proc-macro2", "syn", @@ -3501,18 +3512,18 @@ dependencies = [ [[package]] name = "profiling" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afbdc74edc00b6f6a218ca6a5364d6226a259d4b8ea1af4a0ea063f27e179f4d" +checksum = "3eb8486b569e12e2c32ad3e204dbaba5e4b5b216e9367044f25f1dba42341773" dependencies = [ "profiling-procmacros", ] [[package]] name = "profiling-procmacros" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a65f2e60fbf1063868558d69c6beacf412dc755f9fc020f514b7955fc914fe30" +checksum = "52717f9a02b6965224f95ca2a81e2e0c5c43baacd28ca057577988930b6c3d5b" dependencies = [ "quote", "syn", @@ -3585,9 +3596,9 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quick-xml" -version = "0.37.5" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb" +checksum = "8927b0664f5c5a98265138b7e3f90aa19a6b21353182469ace36d4ac527b7b1b" dependencies = [ "memchr", ] @@ -3621,7 +3632,7 @@ dependencies = [ "bytes", "getrandom 0.3.3", "lru-slab", - "rand 0.9.1", + "rand 0.9.2", "ring", "rustc-hash 2.1.1", "rustls", @@ -3675,9 +3686,9 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ "rand_chacha 0.9.0", "rand_core 0.9.3", @@ -3758,9 +3769,9 @@ dependencies = [ [[package]] name = "ravif" -version = "0.11.12" +version = "0.11.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6a5f31fcf7500f9401fea858ea4ab5525c99f2322cfcee732c0e6c74208c0c6" +checksum = "5825c26fddd16ab9f515930d49028a630efec172e903483c94796cfe31893e6b" dependencies = [ "avif-serialize", "imgref", @@ -3804,9 +3815,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.13" +version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6" +checksum = "7e8af0dde094006011e6a740d4879319439489813bd0bcdc7d821beaeeff48ec" dependencies = [ "bitflags 2.9.1", ] @@ -3912,9 +3923,9 @@ source = "git+https://forgejo.ellis.link/continuwuation/resolv-conf?rev=56251316 [[package]] name = "rgb" -version = "0.8.50" +version = "0.8.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" +checksum = "0c6a884d2998352bb4daf0183589aec883f16a6da1f4dde84d8e2e9a5409a1ce" [[package]] name = "ring" @@ -4002,7 +4013,7 @@ dependencies = [ "form_urlencoded", "getrandom 0.2.16", "http", - "indexmap 2.9.0", + "indexmap 2.10.0", "js_int", "konst", "percent-encoding", @@ -4029,7 +4040,7 @@ version = "0.28.1" source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" dependencies = [ "as_variant", - "indexmap 2.9.0", + "indexmap 2.10.0", "js_int", "js_option", "percent-encoding", @@ -4200,22 +4211,22 @@ dependencies = [ [[package]] name = "rustix" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" +checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" dependencies = [ "bitflags 2.9.1", "errno", "libc", "linux-raw-sys 0.9.4", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "rustls" -version = "0.23.28" +version = "0.23.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7160e3e10bf4535308537f3c4e1641468cd0e485175d6163087c0393c7d46643" +checksum = "2491382039b29b9b11ff08b76ff6c97cf287671dbb74f0be44bda389fffe9bd1" dependencies = [ "aws-lc-rs", "log", @@ -4260,9 +4271,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.3" +version = "0.103.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a72fe2bcf7a6ac6fd7d0b9e5cb68aeb7d4c0a0271730218b3e92d43b4eb435" +checksum = "0a17884ae0c1b773f1ccd2bd4a8c72f16da897310a98b0e84bf349ad5ead92fc" dependencies = [ "aws-lc-rs", "ring", @@ -4526,7 +4537,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d2de91cf02bbc07cde38891769ccd5d4f073d22a40683aa4bc7a95781aaa2c4" dependencies = [ "form_urlencoded", - "indexmap 2.9.0", + "indexmap 2.10.0", "itoa", "ryu", "serde", @@ -4534,9 +4545,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3" dependencies = [ "itoa", "memchr", @@ -4591,7 +4602,7 @@ version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.9.0", + "indexmap 2.10.0", "itoa", "ryu", "serde", @@ -5069,16 +5080,18 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.45.1" +version = "1.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779" +checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" dependencies = [ "backtrace", "bytes", + "io-uring", "libc", "mio", "pin-project-lite", "signal-hook-registry", + "slab", "socket2", "tokio-macros", "tracing", @@ -5098,9 +5111,9 @@ dependencies = [ [[package]] name = "tokio-metrics" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7817b32d36c9b94744d7aa3f8fc13526aa0f5112009d7045f3c659413a6e44ac" +checksum = "23ff82f660c98e4ff60da5eb8fa864a4130f34b56d92d5cd23d6fdfcc14e95fa" dependencies = [ "futures-util", "pin-project-lite", @@ -5181,7 +5194,7 @@ version = "0.22.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ - "indexmap 2.9.0", + "indexmap 2.10.0", "serde", "serde_spanned", "toml_datetime", @@ -5405,9 +5418,9 @@ checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" [[package]] name = "typewit" -version = "1.11.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb77c29baba9e4d3a6182d51fa75e3215c7fd1dab8f4ea9d107c716878e55fc0" +checksum = "97e72ba082eeb9da9dc68ff5a2bf727ef6ce362556e8d29ec1aed3bd05e7d86a" dependencies = [ "typewit_proc_macros", ] @@ -5719,14 +5732,14 @@ version = "0.26.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" dependencies = [ - "webpki-roots 1.0.1", + "webpki-roots 1.0.2", ] [[package]] name = "webpki-roots" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8782dd5a41a24eed3a4f40b606249b3e236ca61adf1f25ea4d45c73de122b502" +checksum = "7e8983c3ab33d6fb807cfcdad2491c4ea8cbc8ed839181c7dfd9c67c83e261b2" dependencies = [ "rustls-pki-types", ] @@ -6137,9 +6150,9 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "winnow" -version = "0.7.11" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" +checksum = "f3edebf492c8125044983378ecb5766203ad3b4c2f7a922bd7dd207f6d443e95" dependencies = [ "memchr", ] @@ -6356,9 +6369,9 @@ dependencies = [ [[package]] name = "zune-jpeg" -version = "0.4.17" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6fe2e33d02a98ee64423802e16df3de99c43e5cf5ff983767e1128b394c8ac" +checksum = "2c9e525af0a6a658e031e95f14b7f889976b74a11ba0eca5a5fc9ac8a1c43a6a" dependencies = [ "zune-core", ] From 87be4d1a52d6bd1680a47153f020affc166d1a07 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 24 Jul 2025 23:22:07 +0100 Subject: [PATCH 2197/2291] feat: Almost-functional musl builds on Alpine Lots of fiddling, still can't get stuff to work Next step is a debian builder copying the static libs from alpine --- Cargo.lock | 23 ++--------------------- Cargo.toml | 2 +- docker/musl.Dockerfile | 5 ++--- 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 837e033a..e5c111d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -525,24 +525,6 @@ dependencies = [ "which", ] -[[package]] -name = "bindgen" -version = "0.71.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" -dependencies = [ - "bitflags 2.9.1", - "cexpr", - "clang-sys", - "itertools 0.13.0", - "proc-macro2", - "quote", - "regex", - "rustc-hash 2.1.1", - "shlex", - "syn", -] - [[package]] name = "bindgen" version = "0.72.0" @@ -4146,7 +4128,7 @@ dependencies = [ [[package]] name = "rust-librocksdb-sys" version = "0.38.0+10.4.2" -source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=01e1128898fc4bbb776e7a6deec2aa3b675b0442#01e1128898fc4bbb776e7a6deec2aa3b675b0442" +source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=99b0319416b64830dd6f8943e1f65e15aeef18bc#99b0319416b64830dd6f8943e1f65e15aeef18bc" dependencies = [ "bindgen 0.72.0", "bzip2-sys", @@ -4163,7 +4145,7 @@ dependencies = [ [[package]] name = "rust-rocksdb" version = "0.42.1" -source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=01e1128898fc4bbb776e7a6deec2aa3b675b0442#01e1128898fc4bbb776e7a6deec2aa3b675b0442" +source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=99b0319416b64830dd6f8943e1f65e15aeef18bc#99b0319416b64830dd6f8943e1f65e15aeef18bc" dependencies = [ "libc", "rust-librocksdb-sys", @@ -6347,7 +6329,6 @@ version = "2.0.15+zstd.1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb81183ddd97d0c74cedf1d50d85c8d08c1b8b68ee863bdee9e706eedba1a237" dependencies = [ - "bindgen 0.71.1", "cc", "pkg-config", ] diff --git a/Cargo.toml b/Cargo.toml index e95567bd..e7abca01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -391,7 +391,7 @@ features = [ [workspace.dependencies.rust-rocksdb] git = "https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1" -rev = "01e1128898fc4bbb776e7a6deec2aa3b675b0442" +rev = "99b0319416b64830dd6f8943e1f65e15aeef18bc" default-features = false features = [ "multi-threaded-cf", diff --git a/docker/musl.Dockerfile b/docker/musl.Dockerfile index b55aecb0..2221525b 100644 --- a/docker/musl.Dockerfile +++ b/docker/musl.Dockerfile @@ -13,7 +13,7 @@ FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-alpine${ALPINE_VERSION} AS t RUN --mount=type=cache,target=/etc/apk/cache apk add \ build-base pkgconfig make jq bash \ curl git file \ - llvm-dev clang clang-dev lld + llvm-dev clang clang-static lld # Developer tool versions @@ -37,8 +37,7 @@ COPY --from=xx / / ARG TARGETPLATFORM # Install libraries linked by the binary -RUN --mount=type=cache,target=/etc/apk/cache xx-apk add musl-dev liburing-dev clang-dev - +RUN --mount=type=cache,target=/etc/apk/cache xx-apk add musl-dev gcc g++ liburing-dev # Set up Rust toolchain WORKDIR /app From 00c7e220bbefaca35b44d64ec0af4d3d146a0fbd Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 25 Jul 2025 14:10:06 +0100 Subject: [PATCH 2198/2291] chore: Release --- Cargo.lock | 24 ++++++++++++------------ Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e5c111d7..5d7192b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -845,7 +845,7 @@ dependencies = [ [[package]] name = "conduwuit" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "clap", "conduwuit_admin", @@ -875,7 +875,7 @@ dependencies = [ [[package]] name = "conduwuit_admin" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "clap", "conduwuit_api", @@ -896,7 +896,7 @@ dependencies = [ [[package]] name = "conduwuit_api" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "async-trait", "axum", @@ -928,14 +928,14 @@ dependencies = [ [[package]] name = "conduwuit_build_metadata" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "built 0.8.0", ] [[package]] name = "conduwuit_core" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "argon2", "arrayvec", @@ -996,7 +996,7 @@ dependencies = [ [[package]] name = "conduwuit_database" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "async-channel", "conduwuit_core", @@ -1014,7 +1014,7 @@ dependencies = [ [[package]] name = "conduwuit_macros" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "itertools 0.14.0", "proc-macro2", @@ -1024,7 +1024,7 @@ dependencies = [ [[package]] name = "conduwuit_router" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "axum", "axum-client-ip", @@ -1058,7 +1058,7 @@ dependencies = [ [[package]] name = "conduwuit_service" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "async-trait", "base64 0.22.1", @@ -1096,7 +1096,7 @@ dependencies = [ [[package]] name = "conduwuit_web" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "askama", "axum", @@ -6177,7 +6177,7 @@ dependencies = [ [[package]] name = "xtask" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "clap", "serde", @@ -6186,7 +6186,7 @@ dependencies = [ [[package]] name = "xtask-generate-commands" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" dependencies = [ "clap-markdown", "clap_builder", diff --git a/Cargo.toml b/Cargo.toml index e7abca01..c656e183 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ license = "Apache-2.0" readme = "README.md" repository = "https://forgejo.ellis.link/continuwuation/continuwuity" rust-version = "1.86.0" -version = "0.5.0-rc.6" +version = "0.5.0-rc.7" [workspace.metadata.crane] name = "conduwuit" From aa08edc55f2f14d3c819b71fb13bc4ac89f0a540 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 25 Jul 2025 17:30:31 +0100 Subject: [PATCH 2199/2291] chore: Release announcement --- docs/static/announcements.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/static/announcements.json b/docs/static/announcements.json index 7dd2fb72..8068535c 100644 --- a/docs/static/announcements.json +++ b/docs/static/announcements.json @@ -6,8 +6,8 @@ "message": "Welcome to Continuwuity! Important announcements about the project will appear here." }, { - "id": 2, - "message": "🎉 Continuwuity v0.5.0-rc.6 is now available! This release includes improved knock-restricted room handling, automatic support contact configuration, and a new HTML landing page. Check [the release notes for full details](https://forgejo.ellis.link/continuwuation/continuwuity/releases/tag/v0.5.0-rc.6) and upgrade instructions." + "id": 3, + "message": "_taps microphone_ The Continuwuity 0.5.0-rc.7 release is now available, and it's better than ever! **177 commits**, **35 pull requests**, **11 contributors,** and a lot of new stuff!\n\nFor highlights, we've got:\n\n* 🕵️ Full Policy Server support to fight spam!\n* 🚀 Smarter room & space upgrades.\n* 🚫 User suspension tools for better moderation.\n* 🤖 reCaptcha support for safer open registration.\n* 🔍 Ability to disable read receipts & typing indicators.\n* ⚡ Sweeping performance improvements!\n\nGet the [full changelog and downloads on our Forgejo](https://forgejo.ellis.link/continuwuation/continuwuity/releases/tag/v0.5.0-rc.7) - and make sure you're in the https://matrix.to/#/!releases:continuwuity.org/$hN9z6L2_dTAlPxFLAoXVfo_g8DyYXu4cpvWsSrWhmB0 to get stuff like this sooner." } ] } From 4a83df5b57b5872a3006b93723df512ac3d51507 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 25 Jul 2025 17:35:18 +0100 Subject: [PATCH 2200/2291] chore: Fix link --- docs/static/announcements.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/static/announcements.json b/docs/static/announcements.json index 8068535c..fe27859b 100644 --- a/docs/static/announcements.json +++ b/docs/static/announcements.json @@ -7,7 +7,7 @@ }, { "id": 3, - "message": "_taps microphone_ The Continuwuity 0.5.0-rc.7 release is now available, and it's better than ever! **177 commits**, **35 pull requests**, **11 contributors,** and a lot of new stuff!\n\nFor highlights, we've got:\n\n* 🕵️ Full Policy Server support to fight spam!\n* 🚀 Smarter room & space upgrades.\n* 🚫 User suspension tools for better moderation.\n* 🤖 reCaptcha support for safer open registration.\n* 🔍 Ability to disable read receipts & typing indicators.\n* ⚡ Sweeping performance improvements!\n\nGet the [full changelog and downloads on our Forgejo](https://forgejo.ellis.link/continuwuation/continuwuity/releases/tag/v0.5.0-rc.7) - and make sure you're in the https://matrix.to/#/!releases:continuwuity.org/$hN9z6L2_dTAlPxFLAoXVfo_g8DyYXu4cpvWsSrWhmB0 to get stuff like this sooner." + "message": "_taps microphone_ The Continuwuity 0.5.0-rc.7 release is now available, and it's better than ever! **177 commits**, **35 pull requests**, **11 contributors,** and a lot of new stuff!\n\nFor highlights, we've got:\n\n* 🕵️ Full Policy Server support to fight spam!\n* 🚀 Smarter room & space upgrades.\n* 🚫 User suspension tools for better moderation.\n* 🤖 reCaptcha support for safer open registration.\n* 🔍 Ability to disable read receipts & typing indicators.\n* ⚡ Sweeping performance improvements!\n\nGet the [full changelog and downloads on our Forgejo](https://forgejo.ellis.link/continuwuation/continuwuity/releases/tag/v0.5.0-rc.7) - and make sure you're in the [Announcements room](https://matrix.to/#/!releases:continuwuity.org/$hN9z6L2_dTAlPxFLAoXVfo_g8DyYXu4cpvWsSrWhmB0) to get stuff like this sooner." } ] } From 058988410986b0ba45f19181a3113d216beebe9e Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Mon, 28 Jul 2025 19:28:34 +0100 Subject: [PATCH 2201/2291] docs: Fix documentation link in README Closes https://forgejo.ellis.link/continuwuation/continuwuity/issues/913 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e63fe80f..a5f77a5b 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Continuwuity aims to: ### Can I try it out? -Check out the [documentation](introduction) for installation instructions. +Check out the [documentation](https://continuwuity.org) for installation instructions. There are currently no open registration Continuwuity instances available. From b1516209c403f7075d11c2b33a7674ce84be96f1 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 30 Jul 2025 19:23:38 +0100 Subject: [PATCH 2202/2291] chore: Update funding file --- .github/FUNDING.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index fcfaade5..841427b7 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,5 +1,4 @@ -github: [JadedBlueEyes] -# Doesn't support an array, so we can only list nex -ko_fi: nexy7574 +github: [JadedBlueEyes, nexy7574] custom: + - https://ko-fi.com/nexy7574 - https://ko-fi.com/JadedBlueEyes From 238cc627e3622a89c22b068987b1a88b3c9b6eb1 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 30 Jul 2025 19:33:53 +0100 Subject: [PATCH 2203/2291] docs: Set traefik labels --- docs/deploying/docker-compose.for-traefik.yml | 9 +++++++++ docs/deploying/docker-compose.with-traefik.yml | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/docs/deploying/docker-compose.for-traefik.yml b/docs/deploying/docker-compose.for-traefik.yml index 547712b6..f67e603b 100644 --- a/docs/deploying/docker-compose.for-traefik.yml +++ b/docs/deploying/docker-compose.for-traefik.yml @@ -12,6 +12,15 @@ services: #- ./continuwuity.toml:/etc/continuwuity.toml networks: - proxy + labels: + - "traefik.enable=true" + - "traefik.http.routers.continuwuity.rule=(Host(`matrix.example.com`) || (Host(`example.com`) && PathPrefix(`/.well-known/matrix`)))" + - "traefik.http.routers.continuwuity.entrypoints=websecure" # your HTTPS entry point + - "traefik.http.routers.continuwuity.tls=true" + - "traefik.http.routers.continuwuity.service=continuwuity" + - "traefik.http.services.continuwuity.loadbalancer.server.port=6167" + # possibly, depending on your config: + # - "traefik.http.routers.continuwuity.tls.certresolver=letsencrypt" environment: CONTINUWUITY_SERVER_NAME: your.server.name.example # EDIT THIS CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity diff --git a/docs/deploying/docker-compose.with-traefik.yml b/docs/deploying/docker-compose.with-traefik.yml index 49b7c905..b41a6fbc 100644 --- a/docs/deploying/docker-compose.with-traefik.yml +++ b/docs/deploying/docker-compose.with-traefik.yml @@ -12,6 +12,14 @@ services: #- ./continuwuity.toml:/etc/continuwuity.toml networks: - proxy + labels: + - "traefik.enable=true" + - "traefik.http.routers.homeserver.rule=(Host(`matrix.example.com`) || (Host(`example.com`) && PathPrefix(`/.well-known/matrix`)))" + - "traefik.http.routers.homeserver.entrypoints=websecure" + - "traefik.http.routers.homeserver.tls.certresolver=letsencrypt" + - "traefik.http.services.homeserver.loadbalancer.server.port=6167" + # Uncomment and adjust the following if you want to use middleware + # - "traefik.http.routers.homeserver.middlewares=secureHeaders@file" environment: CONTINUWUITY_SERVER_NAME: your.server.name.example # EDIT THIS CONTINUWUITY_TRUSTED_SERVERS: '["matrix.org"]' From 5775e0ad9d685fc5a55ff979ee3c0bd82ee88ea1 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Wed, 30 Jul 2025 19:55:48 +0100 Subject: [PATCH 2204/2291] docs: Make traefik router names consistent --- docs/deploying/docker-compose.with-traefik.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/deploying/docker-compose.with-traefik.yml b/docs/deploying/docker-compose.with-traefik.yml index b41a6fbc..8021e034 100644 --- a/docs/deploying/docker-compose.with-traefik.yml +++ b/docs/deploying/docker-compose.with-traefik.yml @@ -14,12 +14,12 @@ services: - proxy labels: - "traefik.enable=true" - - "traefik.http.routers.homeserver.rule=(Host(`matrix.example.com`) || (Host(`example.com`) && PathPrefix(`/.well-known/matrix`)))" - - "traefik.http.routers.homeserver.entrypoints=websecure" - - "traefik.http.routers.homeserver.tls.certresolver=letsencrypt" - - "traefik.http.services.homeserver.loadbalancer.server.port=6167" + - "traefik.http.routers.continuwuity.rule=(Host(`matrix.example.com`) || (Host(`example.com`) && PathPrefix(`/.well-known/matrix`)))" + - "traefik.http.routers.continuwuity.entrypoints=websecure" + - "traefik.http.routers.continuwuity.tls.certresolver=letsencrypt" + - "traefik.http.services.continuwuity.loadbalancer.server.port=6167" # Uncomment and adjust the following if you want to use middleware - # - "traefik.http.routers.homeserver.middlewares=secureHeaders@file" + # - "traefik.http.routers.continuwuity.middlewares=secureHeaders@file" environment: CONTINUWUITY_SERVER_NAME: your.server.name.example # EDIT THIS CONTINUWUITY_TRUSTED_SERVERS: '["matrix.org"]' From e4a43b1a5b31bfe5267fafa01b177e0f992d150e Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 2 Aug 2025 00:19:33 +0100 Subject: [PATCH 2205/2291] fix(policy-server): Call the PS later in the PDU creation process This avoids accidentally sending partially built PDUs to the policy server, which may cause issues with some implementations --- src/service/rooms/timeline/create.rs | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/service/rooms/timeline/create.rs b/src/service/rooms/timeline/create.rs index 66a35eca..6732cd8e 100644 --- a/src/service/rooms/timeline/create.rs +++ b/src/service/rooms/timeline/create.rs @@ -165,25 +165,6 @@ pub async fn create_hash_and_sign_event( return Err!(Request(Forbidden("Event is not authorized."))); } - // Check with the policy server - match self - .services - .event_handler - .ask_policy_server(&pdu, room_id) - .await - { - | Ok(true) => {}, - | Ok(false) => { - return Err!(Request(Forbidden(debug_warn!( - "Policy server marked this event as spam" - )))); - }, - | Err(e) => { - // fail open - warn!("Failed to check event with policy server: {e}"); - }, - } - // Hash and sign let mut pdu_json = utils::to_canonical_object(&pdu).map_err(|e| { err!(Request(BadJson(warn!("Failed to convert PDU to canonical JSON: {e}")))) @@ -222,6 +203,25 @@ pub async fn create_hash_and_sign_event( pdu_json.insert("event_id".into(), CanonicalJsonValue::String(pdu.event_id.clone().into())); + // Check with the policy server + match self + .services + .event_handler + .ask_policy_server(&pdu, room_id) + .await + { + | Ok(true) => {}, + | Ok(false) => { + return Err!(Request(Forbidden(debug_warn!( + "Policy server marked this event as spam" + )))); + }, + | Err(e) => { + // fail open + warn!("Failed to check event with policy server: {e}"); + }, + } + // Generate short event id let _shorteventid = self .services From bd3db65cb2ec1ee00aa5ce6069bf044554b97d97 Mon Sep 17 00:00:00 2001 From: Yonatan Sidler Date: Wed, 6 Aug 2025 20:01:36 +0300 Subject: [PATCH 2206/2291] fix(arch): fix config.toml not being loaded from LoadCredentials directory --- arch/conduwuit.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/conduwuit.service b/arch/conduwuit.service index f7100179..34c3995e 100644 --- a/arch/conduwuit.service +++ b/arch/conduwuit.service @@ -64,7 +64,7 @@ StateDirectory=conduwuit RuntimeDirectory=conduwuit RuntimeDirectoryMode=0750 -Environment=CONTINUWUITY_CONFIG=${CREDENTIALS_DIRECTORY}/config.toml +Environment=CONTINUWUITY_CONFIG=%d/config.toml LoadCredential=config.toml:/etc/conduwuit/conduwuit.toml BindPaths=/var/lib/private/conduwuit:/var/lib/matrix-conduit BindPaths=/var/lib/private/conduwuit:/var/lib/private/matrix-conduit From e820551f6290bcaef46a544fe1eb6a11476df41c Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 10 Aug 2025 14:37:26 +0100 Subject: [PATCH 2207/2291] fix(appservice): create sender_localpart user during appservice startup Fixes #813: Application services were unable to work because their sender_localpart user was never created in the database, preventing authentication. This fix ensures the appservice user account is created when: - The server starts up and loads existing appservices from the database - A new appservice is registered via the admin command Additionally, if an appservice user has been accidentally deactivated, it will be automatically reactivated when the appservice starts. The solution centralises all appservice startup logic into a single `start_appservice` helper method, eliminating code duplication between the registration and startup paths. --- src/service/appservice/mod.rs | 89 +++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/src/service/appservice/mod.rs b/src/service/appservice/mod.rs index 7be8a471..de6fcfac 100644 --- a/src/service/appservice/mod.rs +++ b/src/service/appservice/mod.rs @@ -11,7 +11,7 @@ use ruma::{RoomAliasId, RoomId, UserId, api::appservice::Registration}; use tokio::sync::{RwLock, RwLockReadGuard}; pub use self::{namespace_regex::NamespaceRegex, registration_info::RegistrationInfo}; -use crate::{Dep, sending}; +use crate::{Dep, globals, sending, users}; pub struct Service { registration_info: RwLock, @@ -20,7 +20,9 @@ pub struct Service { } struct Services { + globals: Dep, sending: Dep, + users: Dep, } struct Data { @@ -35,7 +37,9 @@ impl crate::Service for Service { Ok(Arc::new(Self { registration_info: RwLock::new(BTreeMap::new()), services: Services { + globals: args.depend::("globals"), sending: args.depend::("sending"), + users: args.depend::("users"), }, db: Data { id_appserviceregistrations: args.db["id_appserviceregistrations"].clone(), @@ -44,15 +48,34 @@ impl crate::Service for Service { } async fn worker(self: Arc) -> Result { - // Inserting registrations into cache self.iter_db_ids() .try_for_each(async |appservice| { - self.registration_info - .write() - .await - .insert(appservice.0, appservice.1.try_into()?); + let (id, registration) = appservice; - Ok(()) + // During startup, resolve any token collisions in favour of appservices + // by logging out conflicting user devices + if let Ok((user_id, device_id)) = self + .services + .users + .find_from_token(®istration.as_token) + .await + { + conduwuit::warn!( + "Token collision detected during startup: Appservice '{}' token was \ + also used by user '{}' device '{}'. Logging out the user device to \ + resolve conflict.", + id, + user_id.localpart(), + device_id + ); + + self.services + .users + .remove_device(&user_id, &device_id) + .await; + } + + self.start_appservice(id, registration).await }) .await } @@ -61,6 +84,39 @@ impl crate::Service for Service { } impl Service { + /// Starts an appservice, ensuring its sender_localpart user exists and is + /// active. Creates the user if it doesn't exist, or reactivates it if it + /// was deactivated. Then registers the appservice in memory for request + /// handling. + async fn start_appservice(&self, id: String, registration: Registration) -> Result { + let appservice_user_id = UserId::parse_with_server_name( + registration.sender_localpart.as_str(), + self.services.globals.server_name(), + )?; + + if !self.services.users.exists(&appservice_user_id).await { + self.services.users.create(&appservice_user_id, None)?; + } else if self + .services + .users + .is_deactivated(&appservice_user_id) + .await + .unwrap_or(false) + { + // Reactivate the appservice user if it was accidentally deactivated + self.services + .users + .set_password(&appservice_user_id, None)?; + } + + self.registration_info + .write() + .await + .insert(id, registration.try_into()?); + + Ok(()) + } + /// Registers an appservice and returns the ID to the caller pub async fn register_appservice( &self, @@ -68,15 +124,28 @@ impl Service { appservice_config_body: &str, ) -> Result { //TODO: Check for collisions between exclusive appservice namespaces - self.registration_info - .write() + + // Prevent token collision with existing user tokens + if self + .services + .users + .find_from_token(®istration.as_token) .await - .insert(registration.id.clone(), registration.clone().try_into()?); + .is_ok() + { + return err!(Request(InvalidParam( + "Cannot register appservice: The provided token is already in use by a user \ + device. Please generate a different token for the appservice." + ))); + } self.db .id_appserviceregistrations .insert(®istration.id, appservice_config_body); + self.start_appservice(registration.id.clone(), registration.clone()) + .await?; + Ok(()) } From d1ebcfaf0bdcc039df3e484acf6eb2428d81ba26 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 10 Aug 2025 14:38:54 +0100 Subject: [PATCH 2208/2291] fix(auth): prevent token collisions and optimise lookups Ensures access tokens are unique across both user and appservice tables to prevent authentication ambiguity and potential security issues. Changes: - On startup, automatically logout any user devices using tokens that conflict with appservice tokens (resolves in favour of appservices) and log a warning with affected user/device details - When creating new user tokens, check for conflicts with appservice tokens and generate a new token if a collision would occur - When registering new appservices, reject registration if the token is already in use by a user device - Use futures::select_ok to race token lookups concurrently for better performance (adapted from tuwunel commit 066097a8) This fix-forward approach resolves existing token collisions on startup whilst preventing new ones from being created, without breaking existing valid authentications. The find_token optimisation is adapted from tuwunel (matrix-construct/tuwunel) commit 066097a8: "Optimize user and appservice token queries" by Jason Volk. --- src/api/router/auth.rs | 41 +++++++++++++++++++++++++---------- src/service/appservice/mod.rs | 7 +++--- src/service/users/mod.rs | 28 +++++++++++++++++++++--- 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/api/router/auth.rs b/src/api/router/auth.rs index 01254c32..5088e699 100644 --- a/src/api/router/auth.rs +++ b/src/api/router/auth.rs @@ -5,6 +5,14 @@ use axum_extra::{ typed_header::TypedHeaderRejectionReason, }; use conduwuit::{Err, Error, Result, debug_error, err, warn}; +use futures::{ + TryFutureExt, + future::{ + Either::{Left, Right}, + select_ok, + }, + pin_mut, +}; use ruma::{ CanonicalJsonObject, CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId, UserId, api::{ @@ -54,17 +62,7 @@ pub(super) async fn auth( | None => request.query.access_token.as_deref(), }; - let token = if let Some(token) = token { - match services.appservice.find_from_token(token).await { - | Some(reg_info) => Token::Appservice(Box::new(reg_info)), - | _ => match services.users.find_from_token(token).await { - | Ok((user_id, device_id)) => Token::User((user_id, device_id)), - | _ => Token::Invalid, - }, - } - } else { - Token::None - }; + let token = find_token(services, token).await?; if metadata.authentication == AuthScheme::None { match metadata { @@ -342,3 +340,24 @@ async fn parse_x_matrix(request: &mut Request) -> Result { Ok(x_matrix) } + +async fn find_token(services: &Services, token: Option<&str>) -> Result { + let Some(token) = token else { + return Ok(Token::None); + }; + + let user_token = services.users.find_from_token(token).map_ok(Token::User); + + let appservice_token = services + .appservice + .find_from_token(token) + .map_ok(Box::new) + .map_ok(Token::Appservice); + + pin_mut!(user_token, appservice_token); + match select_ok([Left(user_token), Right(appservice_token)]).await { + | Err(e) if !e.is_not_found() => Err(e), + | Ok((token, _)) => Ok(token), + | _ => Ok(Token::Invalid), + } +} diff --git a/src/service/appservice/mod.rs b/src/service/appservice/mod.rs index de6fcfac..ad9c4a3f 100644 --- a/src/service/appservice/mod.rs +++ b/src/service/appservice/mod.rs @@ -133,10 +133,10 @@ impl Service { .await .is_ok() { - return err!(Request(InvalidParam( + return Err(err!(Request(InvalidParam( "Cannot register appservice: The provided token is already in use by a user \ device. Please generate a different token for the appservice." - ))); + )))); } self.db @@ -182,12 +182,13 @@ impl Service { .map(|info| info.registration) } - pub async fn find_from_token(&self, token: &str) -> Option { + pub async fn find_from_token(&self, token: &str) -> Result { self.read() .await .values() .find(|info| info.registration.as_token == token) .cloned() + .ok_or_else(|| err!(Request(NotFound("Appservice token not found")))) } /// Checks if a given user id matches any exclusive appservice regex diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index d2dfccd9..0aacc0e1 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -19,7 +19,7 @@ use ruma::{ use serde::{Deserialize, Serialize}; use serde_json::json; -use crate::{Dep, account_data, admin, globals, rooms}; +use crate::{Dep, account_data, admin, appservice, globals, rooms}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct UserSuspension { @@ -40,6 +40,7 @@ struct Services { server: Arc, account_data: Dep, admin: Dep, + appservice: Dep, globals: Dep, state_accessor: Dep, state_cache: Dep, @@ -76,6 +77,7 @@ impl crate::Service for Service { server: args.server.clone(), account_data: args.depend::("account_data"), admin: args.depend::("admin"), + appservice: args.depend::("appservice"), globals: args.depend::("globals"), state_accessor: args .depend::("rooms::state_accessor"), @@ -407,6 +409,26 @@ impl Service { ))); } + // Prevent token collisions with appservice tokens + let final_token = if self + .services + .appservice + .find_from_token(token) + .await + .is_ok() + { + let new_token = utils::random_string(32); + conduwuit::debug_warn!( + "Token collision prevented: Generated new token for user '{}' device '{}' \ + (original token conflicted with an appservice)", + user_id.localpart(), + device_id + ); + new_token + } else { + token.to_owned() + }; + // Remove old token if let Ok(old_token) = self.db.userdeviceid_token.qry(&key).await { self.db.token_userdeviceid.remove(&old_token); @@ -414,8 +436,8 @@ impl Service { } // Assign token to user device combination - self.db.userdeviceid_token.put_raw(key, token); - self.db.token_userdeviceid.raw_put(token, key); + self.db.userdeviceid_token.put_raw(key, &final_token); + self.db.token_userdeviceid.raw_put(&final_token, key); Ok(()) } From 9286838d23aa5b60bb0a030d403879406732bbc9 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 10 Aug 2025 18:22:20 +0100 Subject: [PATCH 2209/2291] fix(relations): improve thread pagination and include root event Replace unreliable PduCount pagination tokens with ShortEventId throughout the relations and messages endpoints. ShortEventId provides stable, unique identifiers that persist across server restarts and database operations. Key improvements: - Add token parsing helpers that try ShortEventId first, fall back to PduCount for backwards compatibility - Include thread root event when paginating backwards to thread start - Fix off-by-one error in get_relations that was returning the starting event in results - Only return next_batch/prev_batch tokens when more events are available, preventing clients from making unnecessary requests at thread boundaries - Ensure consistent token format between /relations, /messages, and /sync endpoints for interoperability This fixes duplicate events when scrolling at thread boundaries and ensures the thread root message is visible when viewing a thread, matching expected client behaviour. --- src/api/client/message.rs | 60 +++++++++--- src/api/client/relations.rs | 129 +++++++++++++++++++++---- src/service/rooms/pdu_metadata/data.rs | 14 ++- 3 files changed, 168 insertions(+), 35 deletions(-) diff --git a/src/api/client/message.rs b/src/api/client/message.rs index f8818ebb..95a135e1 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -1,14 +1,14 @@ use axum::extract::State; use conduwuit::{ - Err, Result, at, + Err, Result, at, err, matrix::{ event::{Event, Matches}, - pdu::PduCount, + pdu::{PduCount, ShortEventId}, }, ref_at, utils::{ IterStream, ReadyExt, - result::{FlatOk, LogErr}, + result::LogErr, stream::{BroadbandExt, TryIgnore, WidebandExt}, }, }; @@ -61,6 +61,39 @@ const IGNORED_MESSAGE_TYPES: &[TimelineEventType] = &[ const LIMIT_MAX: usize = 100; const LIMIT_DEFAULT: usize = 10; +/// Parse a pagination token, trying ShortEventId first, then falling back to +/// PduCount +async fn parse_pagination_token( + _services: &Services, + _room_id: &RoomId, + token: Option<&str>, + default: PduCount, +) -> Result { + let Some(token) = token else { + return Ok(default); + }; + + // Try parsing as ShortEventId first + if let Ok(shorteventid) = token.parse::() { + // ShortEventId maps directly to a PduCount in our database + Ok(PduCount::Normal(shorteventid)) + } else if let Ok(count) = token.parse::() { + // Fallback to PduCount for backwards compatibility + Ok(PduCount::Normal(count)) + } else if let Ok(count) = token.parse::() { + // Also handle negative counts for backfilled events + Ok(PduCount::from_signed(count)) + } else { + Err(err!(Request(InvalidParam("Invalid pagination token")))) + } +} + +/// Convert a PduCount to a token string (using the underlying ShortEventId) +fn count_to_token(count: PduCount) -> String { + // The PduCount's unsigned value IS the ShortEventId + count.into_unsigned().to_string() +} + /// # `GET /_matrix/client/r0/rooms/{roomId}/messages` /// /// Allows paginating through room history. @@ -81,17 +114,18 @@ pub(crate) async fn get_message_events_route( return Err!(Request(Forbidden("Room does not exist to this server"))); } - let from: PduCount = body - .from - .as_deref() - .map(str::parse) - .transpose()? - .unwrap_or_else(|| match body.dir { + let from: PduCount = + parse_pagination_token(&services, room_id, body.from.as_deref(), match body.dir { | Direction::Forward => PduCount::min(), | Direction::Backward => PduCount::max(), - }); + }) + .await?; - let to: Option = body.to.as_deref().map(str::parse).flat_ok(); + let to: Option = if let Some(to_str) = body.to.as_deref() { + Some(parse_pagination_token(&services, room_id, Some(to_str), PduCount::min()).await?) + } else { + None + }; let limit: usize = body .limit @@ -180,8 +214,8 @@ pub(crate) async fn get_message_events_route( .collect(); Ok(get_message_events::v3::Response { - start: from.to_string(), - end: next_token.as_ref().map(ToString::to_string), + start: count_to_token(from), + end: next_token.map(count_to_token), chunk, state, }) diff --git a/src/api/client/relations.rs b/src/api/client/relations.rs index 1aa34ada..48bcde20 100644 --- a/src/api/client/relations.rs +++ b/src/api/client/relations.rs @@ -1,7 +1,11 @@ use axum::extract::State; use conduwuit::{ - Result, at, - matrix::{Event, event::RelationTypeEqual, pdu::PduCount}, + Result, at, err, + matrix::{ + Event, + event::RelationTypeEqual, + pdu::{PduCount, ShortEventId}, + }, utils::{IterStream, ReadyExt, result::FlatOk, stream::WidebandExt}, }; use conduwuit_service::Services; @@ -20,6 +24,40 @@ use ruma::{ use crate::Ruma; +/// Parse a pagination token, trying ShortEventId first, then falling back to +/// PduCount +async fn parse_pagination_token( + _services: &Services, + _room_id: &RoomId, + token: Option<&str>, + default: PduCount, +) -> Result { + let Some(token) = token else { + return Ok(default); + }; + + // Try parsing as ShortEventId first + if let Ok(shorteventid) = token.parse::() { + // ShortEventId maps directly to a PduCount in our database + // The shorteventid IS the count value, just need to wrap it + Ok(PduCount::Normal(shorteventid)) + } else if let Ok(count) = token.parse::() { + // Fallback to PduCount for backwards compatibility + Ok(PduCount::Normal(count)) + } else if let Ok(count) = token.parse::() { + // Also handle negative counts for backfilled events + Ok(PduCount::from_signed(count)) + } else { + Err(err!(Request(InvalidParam("Invalid pagination token")))) + } +} + +/// Convert a PduCount to a token string (using the underlying ShortEventId) +fn count_to_token(count: PduCount) -> String { + // The PduCount's unsigned value IS the ShortEventId + count.into_unsigned().to_string() +} + /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}` pub(crate) async fn get_relating_events_with_rel_type_and_event_type_route( State(services): State, @@ -109,15 +147,17 @@ async fn paginate_relations_with_filter( recurse: bool, dir: Direction, ) -> Result { - let start: PduCount = from - .map(str::parse) - .transpose()? - .unwrap_or_else(|| match dir { - | Direction::Forward => PduCount::min(), - | Direction::Backward => PduCount::max(), - }); + let start: PduCount = parse_pagination_token(services, room_id, from, match dir { + | Direction::Forward => PduCount::min(), + | Direction::Backward => PduCount::max(), + }) + .await?; - let to: Option = to.map(str::parse).flat_ok(); + let to: Option = if let Some(to_str) = to { + Some(parse_pagination_token(services, room_id, Some(to_str), PduCount::min()).await?) + } else { + None + }; // Use limit or else 30, with maximum 100 let limit: usize = limit @@ -129,6 +169,11 @@ async fn paginate_relations_with_filter( // Spec (v1.10) recommends depth of at least 3 let depth: u8 = if recurse { 3 } else { 1 }; + // Check if this is a thread request + let is_thread = filter_rel_type + .as_ref() + .is_some_and(|rel| *rel == RelationType::Thread); + let events: Vec<_> = services .rooms .pdu_metadata @@ -152,23 +197,65 @@ async fn paginate_relations_with_filter( .collect() .await; - let next_batch = match dir { - | Direction::Forward => events.last(), - | Direction::Backward => events.first(), + // For threads, check if we should include the root event + let mut root_event = None; + if is_thread && dir == Direction::Backward { + // Check if we've reached the beginning of the thread + // (fewer events than requested means we've exhausted the thread) + if events.len() < limit { + // Try to get the thread root event + if let Ok(root_pdu) = services.rooms.timeline.get_pdu(target).await { + // Check visibility + if services + .rooms + .state_accessor + .user_can_see_event(sender_user, room_id, target) + .await + { + // Store the root event to add to the response + root_event = Some(root_pdu); + } + } + } } - .map(at!(0)) - .as_ref() - .map(ToString::to_string); + + // Determine if there are more events to fetch + let has_more = if root_event.is_some() { + false // We've included the root, no more events + } else { + // Check if we got a full page of results (might be more) + events.len() >= limit + }; + + let next_batch = if has_more { + match dir { + | Direction::Forward => events.last(), + | Direction::Backward => events.first(), + } + .map(|(count, _)| count_to_token(*count)) + } else { + None + }; + + // Build the response chunk with thread root if needed + let chunk: Vec<_> = if let Some(root) = root_event { + // Add root event at the beginning for backward pagination + std::iter::once(root.into_format()) + .chain(events.into_iter().map(at!(1)).map(Event::into_format)) + .collect() + } else { + events + .into_iter() + .map(at!(1)) + .map(Event::into_format) + .collect() + }; Ok(get_relating_events::v1::Response { next_batch, prev_batch: from.map(Into::into), recursion_depth: recurse.then_some(depth.into()), - chunk: events - .into_iter() - .map(at!(1)) - .map(Event::into_format) - .collect(), + chunk, }) } diff --git a/src/service/rooms/pdu_metadata/data.rs b/src/service/rooms/pdu_metadata/data.rs index c1376cb0..f9cc80a0 100644 --- a/src/service/rooms/pdu_metadata/data.rs +++ b/src/service/rooms/pdu_metadata/data.rs @@ -61,9 +61,10 @@ impl Data { from: PduCount, dir: Direction, ) -> impl Stream + Send + '_ { + let from_unsigned = from.into_unsigned(); let mut current = ArrayVec::::new(); current.extend(target.to_be_bytes()); - current.extend(from.saturating_inc(dir).into_unsigned().to_be_bytes()); + current.extend(from_unsigned.to_be_bytes()); let current = current.as_slice(); match dir { | Direction::Forward => self.tofrom_relation.raw_keys_from(current).boxed(), @@ -73,6 +74,17 @@ impl Data { .ready_take_while(move |key| key.starts_with(&target.to_be_bytes())) .map(|to_from| u64_from_u8(&to_from[8..16])) .map(PduCount::from_unsigned) + .ready_filter(move |count| { + if from == PduCount::min() || from == PduCount::max() { + true + } else { + let count_unsigned = count.into_unsigned(); + match dir { + | Direction::Forward => count_unsigned > from_unsigned, + | Direction::Backward => count_unsigned < from_unsigned, + } + } + }) .wide_filter_map(move |shorteventid| async move { let pdu_id: RawPduId = PduId { shortroomid, shorteventid }.into(); From 583cb924f1510960702f626c7397cb9e87e1722a Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Mon, 11 Aug 2025 06:24:29 +0100 Subject: [PATCH 2210/2291] refactor: address code review feedback for auth and pagination improvements - Extract duplicated thread/message pagination functions to shared utils module - Refactor pagination token parsing to use Option combinators instead of defaults - Split access token generation from assignment for clearer error handling - Add appservice token collision detection at startup and registration - Allow appservice re-registration with same token (for config updates) - Simplify thread relation chunk building using iterator chaining - Fix saturating_inc edge case in relation queries with explicit filtering - Add concise comments explaining non-obvious behaviour choices --- src/api/client/message.rs | 55 ++++------------- src/api/client/mod.rs | 1 + src/api/client/relations.rs | 78 +++++------------------- src/api/client/session.rs | 4 +- src/api/client/utils.rs | 28 +++++++++ src/api/router/auth.rs | 1 + src/service/appservice/mod.rs | 83 +++++++++++++++++--------- src/service/rooms/pdu_metadata/data.rs | 2 + src/service/users/mod.rs | 48 ++++++++++----- 9 files changed, 149 insertions(+), 151 deletions(-) create mode 100644 src/api/client/utils.rs diff --git a/src/api/client/message.rs b/src/api/client/message.rs index 95a135e1..4d489c2f 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -1,9 +1,9 @@ use axum::extract::State; use conduwuit::{ - Err, Result, at, err, + Err, Result, at, matrix::{ event::{Event, Matches}, - pdu::{PduCount, ShortEventId}, + pdu::PduCount, }, ref_at, utils::{ @@ -35,6 +35,7 @@ use ruma::{ }; use tracing::warn; +use super::utils::{count_to_token, parse_pagination_token as parse_token}; use crate::Ruma; /// list of safe and common non-state events to ignore if the user is ignored @@ -61,39 +62,6 @@ const IGNORED_MESSAGE_TYPES: &[TimelineEventType] = &[ const LIMIT_MAX: usize = 100; const LIMIT_DEFAULT: usize = 10; -/// Parse a pagination token, trying ShortEventId first, then falling back to -/// PduCount -async fn parse_pagination_token( - _services: &Services, - _room_id: &RoomId, - token: Option<&str>, - default: PduCount, -) -> Result { - let Some(token) = token else { - return Ok(default); - }; - - // Try parsing as ShortEventId first - if let Ok(shorteventid) = token.parse::() { - // ShortEventId maps directly to a PduCount in our database - Ok(PduCount::Normal(shorteventid)) - } else if let Ok(count) = token.parse::() { - // Fallback to PduCount for backwards compatibility - Ok(PduCount::Normal(count)) - } else if let Ok(count) = token.parse::() { - // Also handle negative counts for backfilled events - Ok(PduCount::from_signed(count)) - } else { - Err(err!(Request(InvalidParam("Invalid pagination token")))) - } -} - -/// Convert a PduCount to a token string (using the underlying ShortEventId) -fn count_to_token(count: PduCount) -> String { - // The PduCount's unsigned value IS the ShortEventId - count.into_unsigned().to_string() -} - /// # `GET /_matrix/client/r0/rooms/{roomId}/messages` /// /// Allows paginating through room history. @@ -114,18 +82,17 @@ pub(crate) async fn get_message_events_route( return Err!(Request(Forbidden("Room does not exist to this server"))); } - let from: PduCount = - parse_pagination_token(&services, room_id, body.from.as_deref(), match body.dir { + let from: PduCount = body + .from + .as_deref() + .map(parse_token) + .transpose()? + .unwrap_or_else(|| match body.dir { | Direction::Forward => PduCount::min(), | Direction::Backward => PduCount::max(), - }) - .await?; + }); - let to: Option = if let Some(to_str) = body.to.as_deref() { - Some(parse_pagination_token(&services, room_id, Some(to_str), PduCount::min()).await?) - } else { - None - }; + let to: Option = body.to.as_deref().map(parse_token).transpose()?; let limit: usize = body .limit diff --git a/src/api/client/mod.rs b/src/api/client/mod.rs index be54e65f..e4be20b7 100644 --- a/src/api/client/mod.rs +++ b/src/api/client/mod.rs @@ -36,6 +36,7 @@ pub(super) mod typing; pub(super) mod unstable; pub(super) mod unversioned; pub(super) mod user_directory; +pub(super) mod utils; pub(super) mod voip; pub(super) mod well_known; diff --git a/src/api/client/relations.rs b/src/api/client/relations.rs index 48bcde20..f6d8fe9e 100644 --- a/src/api/client/relations.rs +++ b/src/api/client/relations.rs @@ -1,11 +1,7 @@ use axum::extract::State; use conduwuit::{ - Result, at, err, - matrix::{ - Event, - event::RelationTypeEqual, - pdu::{PduCount, ShortEventId}, - }, + Result, at, + matrix::{Event, event::RelationTypeEqual, pdu::PduCount}, utils::{IterStream, ReadyExt, result::FlatOk, stream::WidebandExt}, }; use conduwuit_service::Services; @@ -22,42 +18,9 @@ use ruma::{ events::{TimelineEventType, relation::RelationType}, }; +use super::utils::{count_to_token, parse_pagination_token as parse_token}; use crate::Ruma; -/// Parse a pagination token, trying ShortEventId first, then falling back to -/// PduCount -async fn parse_pagination_token( - _services: &Services, - _room_id: &RoomId, - token: Option<&str>, - default: PduCount, -) -> Result { - let Some(token) = token else { - return Ok(default); - }; - - // Try parsing as ShortEventId first - if let Ok(shorteventid) = token.parse::() { - // ShortEventId maps directly to a PduCount in our database - // The shorteventid IS the count value, just need to wrap it - Ok(PduCount::Normal(shorteventid)) - } else if let Ok(count) = token.parse::() { - // Fallback to PduCount for backwards compatibility - Ok(PduCount::Normal(count)) - } else if let Ok(count) = token.parse::() { - // Also handle negative counts for backfilled events - Ok(PduCount::from_signed(count)) - } else { - Err(err!(Request(InvalidParam("Invalid pagination token")))) - } -} - -/// Convert a PduCount to a token string (using the underlying ShortEventId) -fn count_to_token(count: PduCount) -> String { - // The PduCount's unsigned value IS the ShortEventId - count.into_unsigned().to_string() -} - /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}` pub(crate) async fn get_relating_events_with_rel_type_and_event_type_route( State(services): State, @@ -147,17 +110,15 @@ async fn paginate_relations_with_filter( recurse: bool, dir: Direction, ) -> Result { - let start: PduCount = parse_pagination_token(services, room_id, from, match dir { - | Direction::Forward => PduCount::min(), - | Direction::Backward => PduCount::max(), - }) - .await?; + let start: PduCount = from + .map(parse_token) + .transpose()? + .unwrap_or_else(|| match dir { + | Direction::Forward => PduCount::min(), + | Direction::Backward => PduCount::max(), + }); - let to: Option = if let Some(to_str) = to { - Some(parse_pagination_token(services, room_id, Some(to_str), PduCount::min()).await?) - } else { - None - }; + let to: Option = to.map(parse_token).transpose()?; // Use limit or else 30, with maximum 100 let limit: usize = limit @@ -238,18 +199,11 @@ async fn paginate_relations_with_filter( }; // Build the response chunk with thread root if needed - let chunk: Vec<_> = if let Some(root) = root_event { - // Add root event at the beginning for backward pagination - std::iter::once(root.into_format()) - .chain(events.into_iter().map(at!(1)).map(Event::into_format)) - .collect() - } else { - events - .into_iter() - .map(at!(1)) - .map(Event::into_format) - .collect() - }; + let chunk: Vec<_> = root_event + .into_iter() + .map(Event::into_format) + .chain(events.into_iter().map(at!(1)).map(Event::into_format)) + .collect(); Ok(get_relating_events::v1::Response { next_batch, diff --git a/src/api/client/session.rs b/src/api/client/session.rs index 992073c6..fe07e41d 100644 --- a/src/api/client/session.rs +++ b/src/api/client/session.rs @@ -198,8 +198,8 @@ pub(crate) async fn login_route( .clone() .unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH).into()); - // Generate a new token for the device - let token = utils::random_string(TOKEN_LENGTH); + // Generate a new token for the device (ensuring no collisions) + let token = services.users.generate_unique_token().await; // Determine if device_id was provided and exists in the db for this user let device_exists = if body.device_id.is_some() { diff --git a/src/api/client/utils.rs b/src/api/client/utils.rs new file mode 100644 index 00000000..cc941b95 --- /dev/null +++ b/src/api/client/utils.rs @@ -0,0 +1,28 @@ +use conduwuit::{ + Result, err, + matrix::pdu::{PduCount, ShortEventId}, +}; + +/// Parse a pagination token, trying ShortEventId first, then falling back to +/// PduCount +pub(crate) fn parse_pagination_token(token: &str) -> Result { + // Try parsing as ShortEventId first + if let Ok(shorteventid) = token.parse::() { + // ShortEventId maps directly to a PduCount in our database + Ok(PduCount::Normal(shorteventid)) + } else if let Ok(count) = token.parse::() { + // Fallback to PduCount for backwards compatibility + Ok(PduCount::Normal(count)) + } else if let Ok(count) = token.parse::() { + // Also handle negative counts for backfilled events + Ok(PduCount::from_signed(count)) + } else { + Err(err!(Request(InvalidParam("Invalid pagination token")))) + } +} + +/// Convert a PduCount to a token string (using the underlying ShortEventId) +pub(crate) fn count_to_token(count: PduCount) -> String { + // The PduCount's unsigned value IS the ShortEventId + count.into_unsigned().to_string() +} diff --git a/src/api/router/auth.rs b/src/api/router/auth.rs index 5088e699..44afc3ef 100644 --- a/src/api/router/auth.rs +++ b/src/api/router/auth.rs @@ -355,6 +355,7 @@ async fn find_token(services: &Services, token: Option<&str>) -> Result { .map_ok(Token::Appservice); pin_mut!(user_token, appservice_token); + // Returns Ok if either token type succeeds, Err only if both fail match select_ok([Left(user_token), Right(appservice_token)]).await { | Err(e) if !e.is_not_found() => Err(e), | Ok((token, _)) => Ok(token), diff --git a/src/service/appservice/mod.rs b/src/service/appservice/mod.rs index ad9c4a3f..ebd798f6 100644 --- a/src/service/appservice/mod.rs +++ b/src/service/appservice/mod.rs @@ -4,7 +4,7 @@ mod registration_info; use std::{collections::BTreeMap, iter::IntoIterator, sync::Arc}; use async_trait::async_trait; -use conduwuit::{Result, err, utils::stream::IterStream}; +use conduwuit::{Err, Result, err, utils::stream::IterStream}; use database::Map; use futures::{Future, FutureExt, Stream, TryStreamExt}; use ruma::{RoomAliasId, RoomId, UserId, api::appservice::Registration}; @@ -48,36 +48,50 @@ impl crate::Service for Service { } async fn worker(self: Arc) -> Result { - self.iter_db_ids() - .try_for_each(async |appservice| { - let (id, registration) = appservice; + // First, collect all appservices to check for token conflicts + let appservices: Vec<(String, Registration)> = self.iter_db_ids().try_collect().await?; - // During startup, resolve any token collisions in favour of appservices - // by logging out conflicting user devices - if let Ok((user_id, device_id)) = self - .services - .users - .find_from_token(®istration.as_token) - .await - { - conduwuit::warn!( - "Token collision detected during startup: Appservice '{}' token was \ - also used by user '{}' device '{}'. Logging out the user device to \ - resolve conflict.", - id, - user_id.localpart(), - device_id - ); - - self.services - .users - .remove_device(&user_id, &device_id) - .await; + // Check for appservice-to-appservice token conflicts + for i in 0..appservices.len() { + for j in i.saturating_add(1)..appservices.len() { + if appservices[i].1.as_token == appservices[j].1.as_token { + return Err!(Database(error!( + "Token collision detected: Appservices '{}' and '{}' have the same token", + appservices[i].0, appservices[j].0 + ))); } + } + } - self.start_appservice(id, registration).await - }) - .await + // Process each appservice + for (id, registration) in appservices { + // During startup, resolve any token collisions in favour of appservices + // by logging out conflicting user devices + if let Ok((user_id, device_id)) = self + .services + .users + .find_from_token(®istration.as_token) + .await + { + conduwuit::warn!( + "Token collision detected during startup: Appservice '{}' token was also \ + used by user '{}' device '{}'. Logging out the user device to resolve \ + conflict.", + id, + user_id.localpart(), + device_id + ); + + self.services + .users + .remove_device(&user_id, &device_id) + .await; + } + + self.start_appservice(id, registration).await?; + } + + Ok(()) } fn name(&self) -> &str { crate::service::make_name(std::module_path!()) } @@ -125,6 +139,18 @@ impl Service { ) -> Result { //TODO: Check for collisions between exclusive appservice namespaces + // Check for token collision with other appservices (allow re-registration of + // same appservice) + if let Ok(existing) = self.find_from_token(®istration.as_token).await { + if existing.registration.id != registration.id { + return Err(err!(Request(InvalidParam( + "Cannot register appservice: Token is already used by appservice '{}'. \ + Please generate a different token.", + existing.registration.id + )))); + } + } + // Prevent token collision with existing user tokens if self .services @@ -182,6 +208,7 @@ impl Service { .map(|info| info.registration) } + /// Returns Result to match users::find_from_token for select_ok usage pub async fn find_from_token(&self, token: &str) -> Result { self.read() .await diff --git a/src/service/rooms/pdu_metadata/data.rs b/src/service/rooms/pdu_metadata/data.rs index f9cc80a0..a746b4cc 100644 --- a/src/service/rooms/pdu_metadata/data.rs +++ b/src/service/rooms/pdu_metadata/data.rs @@ -61,6 +61,8 @@ impl Data { from: PduCount, dir: Direction, ) -> impl Stream + Send + '_ { + // Query from exact position then filter excludes it (saturating_inc could skip + // events at min/max boundaries) let from_unsigned = from.into_unsigned(); let mut current = ArrayVec::::new(); current.extend(target.to_be_bytes()); diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index 0aacc0e1..eb54660e 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -393,6 +393,31 @@ impl Service { self.db.userdeviceid_token.qry(&key).await.deserialized() } + /// Generate a unique access token that doesn't collide with existing tokens + pub async fn generate_unique_token(&self) -> String { + loop { + let token = utils::random_string(32); + + // Check for collision with appservice tokens + if self + .services + .appservice + .find_from_token(&token) + .await + .is_ok() + { + continue; + } + + // Check for collision with user tokens + if self.db.token_userdeviceid.get(&token).await.is_ok() { + continue; + } + + return token; + } + } + /// Replaces the access token of one device. pub async fn set_token( &self, @@ -409,25 +434,18 @@ impl Service { ))); } - // Prevent token collisions with appservice tokens - let final_token = if self + // Check for token collision with appservices + if self .services .appservice .find_from_token(token) .await .is_ok() { - let new_token = utils::random_string(32); - conduwuit::debug_warn!( - "Token collision prevented: Generated new token for user '{}' device '{}' \ - (original token conflicted with an appservice)", - user_id.localpart(), - device_id - ); - new_token - } else { - token.to_owned() - }; + return Err!(Request(InvalidParam( + "Token conflicts with an existing appservice token" + ))); + } // Remove old token if let Ok(old_token) = self.db.userdeviceid_token.qry(&key).await { @@ -436,8 +454,8 @@ impl Service { } // Assign token to user device combination - self.db.userdeviceid_token.put_raw(key, &final_token); - self.db.token_userdeviceid.raw_put(&final_token, key); + self.db.userdeviceid_token.put_raw(key, token); + self.db.token_userdeviceid.raw_put(token, key); Ok(()) } From 54acd07555abeff1890a02d6ece66b6c97abdc02 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 16 Aug 2025 16:22:24 +0100 Subject: [PATCH 2211/2291] fix: Drop fake room v2 support --- src/core/info/room_version.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/info/room_version.rs b/src/core/info/room_version.rs index 51d5d3c6..54ed8fdc 100644 --- a/src/core/info/room_version.rs +++ b/src/core/info/room_version.rs @@ -18,7 +18,7 @@ pub const STABLE_ROOM_VERSIONS: &[RoomVersionId] = &[ /// Experimental, partially supported room versions pub const UNSTABLE_ROOM_VERSIONS: &[RoomVersionId] = - &[RoomVersionId::V2, RoomVersionId::V3, RoomVersionId::V4, RoomVersionId::V5]; + &[RoomVersionId::V3, RoomVersionId::V4, RoomVersionId::V5]; type RoomVersion = (RoomVersionId, RoomVersionStability); From 2a183cc5a4a271514d5fe19ab2eca0fdde8495f8 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 17 Aug 2025 13:44:32 +0100 Subject: [PATCH 2212/2291] fix(build): Remove hardened_malloc from full feature set The hardened_malloc feature conflicts with jemalloc, preventing successful builds with the --features full flag. Commenting out hardened_malloc allows the full profile to build correctly while maintaining all other features. --- src/main/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 0d7dd844..8aaa3cc6 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -63,7 +63,7 @@ standard = [ ] full = [ "standard", - "hardened_malloc", + # "hardened_malloc", # Conflicts with jemalloc "jemalloc_prof", "perf_measurements", "tokio_console" From f54e59a068250e871168f6fe16b2eb1a8a458e93 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 17 Aug 2025 14:17:18 +0100 Subject: [PATCH 2213/2291] ci: Add Renovate for automated dependency management Configures Renovate bot to create PRs for outdated dependencies. Runs daily at 5am UTC with manual trigger via workflow_dispatch. Configuration: - Ignores custom forks (jemalloc, telemetry packages) - Groups: GHA minor/patch, Rust toolchain, lockfile, Rust patches - Limits: 3 concurrent PRs, 2 PRs per hour - Supports: Cargo, GitHub Actions, Nix --- .forgejo/workflows/renovate.yml | 64 +++++++++++++++++++++++++++++++++ renovate.json | 44 +++++++++++++++++++++-- 2 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 .forgejo/workflows/renovate.yml diff --git a/.forgejo/workflows/renovate.yml b/.forgejo/workflows/renovate.yml new file mode 100644 index 00000000..802f5aab --- /dev/null +++ b/.forgejo/workflows/renovate.yml @@ -0,0 +1,64 @@ +name: Maintenance / Renovate + +on: + schedule: + # Run at 5am UTC daily to avoid late-night dev + - cron: '0 5 * * *' + + workflow_dispatch: + inputs: + dryRun: + description: 'Dry run mode' + required: false + default: 'false' + type: choice + options: + - 'true' + - 'false' + logLevel: + description: 'Log level' + required: false + default: 'info' + type: choice + options: + - 'debug' + - 'info' + - 'warn' + - 'error' + + push: + branches: + - main + paths: + # Re-run when config changes + - '.forgejo/workflows/renovate.yml' + - 'renovate.json' + +jobs: + renovate: + name: Renovate + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run Renovate + uses: renovatebot/github-action@v40.1.0 + with: + token: ${{ secrets.RENOVATE_TOKEN }} + configurationFile: renovate.json + env: + # Platform configuration - Forgejo uses Gitea-compatible API + RENOVATE_PLATFORM: gitea + RENOVATE_ENDPOINT: ${{ github.server_url }}/api/v1 + RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} + + # Target repository + RENOVATE_REPOSITORIES: '["${{ github.repository }}"]' + + # Runtime behaviour + RENOVATE_DRY_RUN: ${{ inputs.dryRun || 'false' }} + LOG_LEVEL: ${{ inputs.logLevel || 'info' }} + + # Git author for commits - configured via repository variables + RENOVATE_GIT_AUTHOR: '${{ vars.RENOVATE_AUTHOR }}' diff --git a/renovate.json b/renovate.json index eecf8532..3122d0bc 100644 --- a/renovate.json +++ b/renovate.json @@ -17,10 +17,48 @@ "github_actions" ], "ignoreDeps": [ - "tikv-jemllocator", + "tikv-jemallocator", "tikv-jemalloc-sys", "tikv-jemalloc-ctl", - "opentelemetry-rust", + "opentelemetry", + "opentelemetry_sdk", + "opentelemetry-jaeger", "tracing-opentelemetry" - ] + ], + "github-actions": { + "enabled": true, + "fileMatch": [ + "(^|/)\\.forgejo/workflows/[^/]+\\.ya?ml$", + "(^|/)\\.forgejo/actions/[^/]+/action\\.ya?ml$", + "(^|/)\\.github/workflows/[^/]+\\.ya?ml$", + "(^|/)\\.github/actions/[^/]+/action\\.ya?ml$" + ] + }, + "packageRules": [ + { + "description": "Batch minor and patch GitHub Actions updates", + "matchManagers": ["github-actions"], + "matchUpdateTypes": ["minor", "patch"], + "groupName": "github-actions-non-major" + }, + { + "description": "Group Rust toolchain updates into a single PR", + "matchManagers": ["regex"], + "matchPackageNames": ["rust", "rustc", "cargo"], + "groupName": "rust-toolchain" + }, + { + "description": "Group lockfile updates into a single PR", + "matchUpdateTypes": ["lockFileMaintenance"], + "groupName": "lockfile-maintenance" + }, + { + "description": "Batch patch-level Rust dependency updates", + "matchManagers": ["cargo"], + "matchUpdateTypes": ["patch"], + "groupName": "rust-patch-updates" + } + ], + "prConcurrentLimit": 3, + "prHourlyLimit": 2 } From b447cfff56f0a0b5f580fbfe3a28fc94e2cda09e Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 17 Aug 2025 15:11:38 +0100 Subject: [PATCH 2214/2291] ci: Update prefligit to prek The prefligit project has been renamed to prek due to typosquatting concerns. This updates our CI to use the new name and recommended installation method via uv, which significantly reduces setup time compared to cargo install and includes automatic caching. - Replace outdated static prefligit action with direct prek invocation - Use uv as recommended by upstream: https://github.com/j178/prek - Update check-byte-order-marker to fix-byte-order-marker (deprecated) - Simplify workflow by removing unused ref calculations The same .pre-commit-config.yaml works unchanged. Developers can install locally with 'uvx prek install' or other methods from the repo. --- .forgejo/workflows/prefligit-checks.yml | 36 ++++++++++++++++--------- .pre-commit-config.yaml | 2 +- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.forgejo/workflows/prefligit-checks.yml b/.forgejo/workflows/prefligit-checks.yml index cc512496..18f573bb 100644 --- a/.forgejo/workflows/prefligit-checks.yml +++ b/.forgejo/workflows/prefligit-checks.yml @@ -1,22 +1,34 @@ -name: Checks / Prefligit +name: Checks / Prek on: push: pull_request: + permissions: contents: read jobs: - prefligit: + fast-checks: + name: Pre-commit & Formatting runs-on: ubuntu-latest - env: - FROM_REF: ${{ github.event.pull_request.base.sha || (!github.event.forced && ( github.event.before != '0000000000000000000000000000000000000000' && github.event.before || github.sha )) || format('{0}~', github.sha) }} - TO_REF: ${{ github.sha }} steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - persist-credentials: false - - uses: ./.forgejo/actions/prefligit - with: - extra_args: --all-files --hook-stage manual + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Install uv + uses: https://github.com/astral-sh/setup-uv@v6 + with: + enable-cache: true + ignore-nothing-to-cache: true + cache-dependency-glob: '' + + - name: Run prek + run: | + uvx prek run \ + --all-files \ + --hook-stage manual \ + --show-diff-on-failure \ + --color=always \ + -v diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 68e3a982..da594310 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: - - id: check-byte-order-marker + - id: fix-byte-order-marker - id: check-case-conflict - id: check-symlinks - id: destroyed-symlinks From 5d1f141882826dca1b8ebd8cde43a0b0531978b3 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 17 Aug 2025 15:12:05 +0100 Subject: [PATCH 2215/2291] ci: Rename prefligit-checks.yml to prek-checks.yml Rename workflow file to match the updated tool name. --- .forgejo/workflows/{prefligit-checks.yml => prek-checks.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .forgejo/workflows/{prefligit-checks.yml => prek-checks.yml} (100%) diff --git a/.forgejo/workflows/prefligit-checks.yml b/.forgejo/workflows/prek-checks.yml similarity index 100% rename from .forgejo/workflows/prefligit-checks.yml rename to .forgejo/workflows/prek-checks.yml From 9db750e97c77fe3a33ddf744715d48e3d4c7c457 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 17 Aug 2025 15:51:29 +0100 Subject: [PATCH 2216/2291] fix(ci): Add full GitHub URL to renovate action Forgejo's runner doesn't automatically assume actions are on github.com, so we need to specify the full URL. --- .forgejo/workflows/renovate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/renovate.yml b/.forgejo/workflows/renovate.yml index 802f5aab..d2891d91 100644 --- a/.forgejo/workflows/renovate.yml +++ b/.forgejo/workflows/renovate.yml @@ -43,7 +43,7 @@ jobs: uses: actions/checkout@v4 - name: Run Renovate - uses: renovatebot/github-action@v40.1.0 + uses: https://github.com/renovatebot/github-action@v40.1.0 with: token: ${{ secrets.RENOVATE_TOKEN }} configurationFile: renovate.json From 4524a00fc616e68b1c03fa5aa78908458dbe5789 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 17 Aug 2025 16:00:42 +0100 Subject: [PATCH 2217/2291] chore(ci): Remove obsolete prefligit action Now using prek directly via uvx, this custom action is no longer needed. --- .forgejo/actions/prefligit/action.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .forgejo/actions/prefligit/action.yml diff --git a/.forgejo/actions/prefligit/action.yml b/.forgejo/actions/prefligit/action.yml deleted file mode 100644 index 8cbd4500..00000000 --- a/.forgejo/actions/prefligit/action.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: prefligit -description: | - Runs prefligit, pre-commit reimplemented in Rust. -inputs: - extra_args: - description: options to pass to pre-commit run - required: false - default: '--all-files' - -runs: - using: composite - steps: - - name: Install uv - uses: https://github.com/astral-sh/setup-uv@v6 - with: - enable-cache: true - ignore-nothing-to-cache: true - - name: Install Prefligit - shell: bash - run: | - curl --proto '=https' --tlsv1.2 -LsSf https://github.com/j178/prefligit/releases/download/v0.0.10/prefligit-installer.sh | sh - - uses: actions/cache@v3 - with: - path: ~/.cache/prefligit - key: prefligit-0|${{ hashFiles('.pre-commit-config.yaml') }} - - run: prefligit run --show-diff-on-failure --color=always -v ${{ inputs.extra_args }} - shell: bash From 14a4b24fc554a688510c21d5251730a70936dca6 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 17 Aug 2025 17:23:56 +0100 Subject: [PATCH 2218/2291] fix(ci): Configure Renovate for Forgejo platform - Set platform to 'forgejo' with proper API endpoint - Use environment variables for all Renovate configuration - Add git timeout and disable GitHub token warnings - Move PR limit configuration to workflow --- .forgejo/workflows/renovate.yml | 44 ++++++++++++++++----------------- renovate.json | 4 +-- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/.forgejo/workflows/renovate.yml b/.forgejo/workflows/renovate.yml index d2891d91..e8522bec 100644 --- a/.forgejo/workflows/renovate.yml +++ b/.forgejo/workflows/renovate.yml @@ -10,21 +10,22 @@ on: dryRun: description: 'Dry run mode' required: false - default: 'false' + default: null type: choice options: - - 'true' - - 'false' + - null + - 'extract' + - 'lookup' + - 'full' logLevel: description: 'Log level' required: false default: 'info' type: choice options: - - 'debug' - 'info' - - 'warn' - - 'error' + - 'warning' + - 'critical' push: branches: @@ -42,23 +43,20 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Run Renovate + - name: Self-hosted Renovate uses: https://github.com/renovatebot/github-action@v40.1.0 - with: - token: ${{ secrets.RENOVATE_TOKEN }} - configurationFile: renovate.json env: - # Platform configuration - Forgejo uses Gitea-compatible API - RENOVATE_PLATFORM: gitea - RENOVATE_ENDPOINT: ${{ github.server_url }}/api/v1 - RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} - - # Target repository - RENOVATE_REPOSITORIES: '["${{ github.repository }}"]' - - # Runtime behaviour - RENOVATE_DRY_RUN: ${{ inputs.dryRun || 'false' }} LOG_LEVEL: ${{ inputs.logLevel || 'info' }} - - # Git author for commits - configured via repository variables - RENOVATE_GIT_AUTHOR: '${{ vars.RENOVATE_AUTHOR }}' + RENOVATE_AUTODISCOVER: 'false' + RENOVATE_BINARY_SOURCE: 'install' + RENOVATE_DRY_RUN: ${{ inputs.dryRun || 'false' }} + RENOVATE_ENDPOINT: ${{ github.server_url }}/api/v1 + RENOVATE_GIT_TIMEOUT: 60000 + RENOVATE_GIT_URL: 'endpoint' + RENOVATE_GITHUB_TOKEN_WARN: 'false' + RENOVATE_ONBOARDING: 'false' + RENOVATE_PLATFORM: 'forgejo' + RENOVATE_PR_COMMITS_PER_RUN_LIMIT: 3 + RENOVATE_REPOSITORIES: '["${{ github.repository }}"]' + RENOVATE_REQUIRE_CONFIG: 'required' + RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} diff --git a/renovate.json b/renovate.json index 3122d0bc..b48fc6dc 100644 --- a/renovate.json +++ b/renovate.json @@ -58,7 +58,5 @@ "matchUpdateTypes": ["patch"], "groupName": "rust-patch-updates" } - ], - "prConcurrentLimit": 3, - "prHourlyLimit": 2 + ] } From ecb87ccd1c18126093628b1f424c3ed7f89e8ff9 Mon Sep 17 00:00:00 2001 From: aviac Date: Thu, 21 Aug 2025 13:39:36 +0200 Subject: [PATCH 2219/2291] chore(nix): bump rocksdb version in flake.nix to 10.4.fb This works without any further changes. Multiple people in the matrix room (including myself) have reported that the built executable runs fine with this. Nevertheless, there might be room for improvements (in future commits) --- flake.lock | 12 ++++++------ flake.nix | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index 51a04c6c..4af82c75 100644 --- a/flake.lock +++ b/flake.lock @@ -516,16 +516,16 @@ "rocksdb": { "flake": false, "locked": { - "lastModified": 1741308171, - "narHash": "sha256-YdBvdQ75UJg5ffwNjxizpviCVwVDJnBkM8ZtGIduMgY=", - "ref": "v9.11.1", - "rev": "3ce04794bcfbbb0d2e6f81ae35fc4acf688b6986", - "revCount": 13177, + "lastModified": 1753385396, + "narHash": "sha256-/Hvy1yTH/0D5aa7bc+/uqFugCQq4InTdwlRw88vA5IY=", + "ref": "10.4.fb", + "rev": "28d4b7276c16ed3e28af1bd96162d6442ce25923", + "revCount": 13318, "type": "git", "url": "https://forgejo.ellis.link/continuwuation/rocksdb" }, "original": { - "ref": "v9.11.1", + "ref": "10.4.fb", "type": "git", "url": "https://forgejo.ellis.link/continuwuation/rocksdb" } diff --git a/flake.nix b/flake.nix index 564cd479..f0dcb6fb 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,7 @@ nix-filter.url = "github:numtide/nix-filter?ref=main"; nixpkgs.url = "github:NixOS/nixpkgs?ref=nixpkgs-unstable"; rocksdb = { - url = "git+https://forgejo.ellis.link/continuwuation/rocksdb?ref=v9.11.1"; + url = "git+https://forgejo.ellis.link/continuwuation/rocksdb?ref=10.4.fb"; flake = false; }; }; @@ -62,7 +62,7 @@ }).overrideAttrs (old: { src = inputs.rocksdb; - version = "v9.11.1"; + version = "v10.4.fb"; cmakeFlags = pkgs.lib.subtractLists [ # No real reason to have snappy or zlib, no one uses this From 256bed992e50a86b54dc3ff0d24b8d72ce69904d Mon Sep 17 00:00:00 2001 From: aviac Date: Thu, 21 Aug 2025 13:40:11 +0200 Subject: [PATCH 2220/2291] chore(nix): exec 'use flake' with direnv on NixOS systems --- .envrc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.envrc b/.envrc index bad73b75..172993c4 100644 --- a/.envrc +++ b/.envrc @@ -2,6 +2,8 @@ dotenv_if_exists -# use flake ".#${DIRENV_DEVSHELL:-default}" +if [ -f /etc/os-release ] && grep -q '^ID=nixos' /etc/os-release; then + use flake ".#${DIRENV_DEVSHELL:-default}" +fi PATH_add bin From aacaf5a2a031c9e44c2fb9a081a6109a39e5ddbb Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Thu, 21 Aug 2025 21:10:15 +0100 Subject: [PATCH 2221/2291] fix(ci): Downgrade setup-uv action from v6 to v5 The setup-uv@v6 action has deprecated Node 18 support mid-version by using the File API, causing workflow failures. Temporarily downgrading to v5 until we migrate to a better runner image with Node 20+ support. --- .forgejo/workflows/prek-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/prek-checks.yml b/.forgejo/workflows/prek-checks.yml index 18f573bb..ac330ca2 100644 --- a/.forgejo/workflows/prek-checks.yml +++ b/.forgejo/workflows/prek-checks.yml @@ -18,7 +18,7 @@ jobs: persist-credentials: false - name: Install uv - uses: https://github.com/astral-sh/setup-uv@v6 + uses: https://github.com/astral-sh/setup-uv@v5 with: enable-cache: true ignore-nothing-to-cache: true From 427b973b67ec256aaffc8c8c98dd49aef6fa73c5 Mon Sep 17 00:00:00 2001 From: aviac Date: Thu, 21 Aug 2025 13:51:02 +0200 Subject: [PATCH 2222/2291] chore(rust): bump version 1.87 -> 1.89 - bump version in rust-toolchain.toml - update sha in flake.nix --- flake.nix | 2 +- rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index f0dcb6fb..25629621 100644 --- a/flake.nix +++ b/flake.nix @@ -36,7 +36,7 @@ file = ./rust-toolchain.toml; # See also `rust-toolchain.toml` - sha256 = "sha256-KUm16pHj+cRedf8vxs/Hd2YWxpOrWZ7UOrwhILdSJBU="; + sha256 = "sha256-+9FmLhAOezBZCOziO0Qct1NOrfpjNsXxc/8I0c7BdKE="; }; mkScope = diff --git a/rust-toolchain.toml b/rust-toolchain.toml index bdb608aa..c44e95ef 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -9,8 +9,8 @@ # If you're having trouble making the relevant changes, bug a maintainer. [toolchain] -channel = "1.87.0" profile = "minimal" +channel = "1.89.0" components = [ # For rust-analyzer "rust-src", From ca3ee9224b19f7c2181a6db41c0de17b43317dc1 Mon Sep 17 00:00:00 2001 From: aviac Date: Thu, 21 Aug 2025 17:35:46 +0200 Subject: [PATCH 2223/2291] chore(rust): drop rustfmt from rust-toolchain.toml This just installs regular rustfmt, which is not needed in this project. One could say "It doesn't hurt", but in the NixOS dev shell it actually does since it will shadow nightly rustfmt and we don't have the `cargo +nightly fmt` synatx on NixOS that is available on other Distros. Also "It doesn't hurt" to delete it for non NixOS users. --- rust-toolchain.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c44e95ef..63e9d9ce 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -16,6 +16,9 @@ components = [ "rust-src", "rust-analyzer", # For CI and editors - "rustfmt", "clippy", + # you have to install rustfmt nightly yourself (if you're not on NixOS) + # + # The rust-toolchain.toml file doesn't provide any syntax for specifying components from different toolchains + # "rustfmt" ] From 6d1f12b22de7eb8d7af7a642cdf23a14c13d51d2 Mon Sep 17 00:00:00 2001 From: aviac Date: Thu, 21 Aug 2025 17:41:14 +0200 Subject: [PATCH 2224/2291] chore(nix): make rustfmt-nightly available to default dev shell I verified this by running `rustfmt --version` on my system. Note that I don't have a system-wide install of rust and only rely on dev shells, so this can't possibly come from somewhere else. ``` $ rustfmt --version rustfmt 1.8.0-nightly (6677875279 2025-07-02) ``` --- flake.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index 25629621..d6beb84e 100644 --- a/flake.nix +++ b/flake.nix @@ -31,13 +31,17 @@ inherit system; }; + fnx = inputs.fenix.packages.${system}; # The Rust toolchain to use - toolchain = inputs.fenix.packages.${system}.fromToolchainFile { - file = ./rust-toolchain.toml; + toolchain = fnx.combine [ + (fnx.fromToolchainFile { + file = ./rust-toolchain.toml; - # See also `rust-toolchain.toml` - sha256 = "sha256-+9FmLhAOezBZCOziO0Qct1NOrfpjNsXxc/8I0c7BdKE="; - }; + # See also `rust-toolchain.toml` + sha256 = "sha256-+9FmLhAOezBZCOziO0Qct1NOrfpjNsXxc/8I0c7BdKE="; + }) + fnx.complete.rustfmt + ]; mkScope = pkgs: From d191494f18fa60af15756fc01420b4823c6247bd Mon Sep 17 00:00:00 2001 From: aviac Date: Thu, 21 Aug 2025 17:50:08 +0200 Subject: [PATCH 2225/2291] chore(nix): update `fenix` input This is required, since now we're installing `rustfmt` from the latest state of the fenix repo. This wasn't recent enough for the latest rust version. The input was locked at (2025-07-02). Now it's up to date. --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 4af82c75..4c2bf9fb 100644 --- a/flake.lock +++ b/flake.lock @@ -153,11 +153,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1751525020, - "narHash": "sha256-oDO6lCYS5Bf4jUITChj9XV7k3TP38DE0Ckz5n5ORCME=", + "lastModified": 1755585599, + "narHash": "sha256-tl/0cnsqB/Yt7DbaGMel2RLa7QG5elA8lkaOXli6VdY=", "owner": "nix-community", "repo": "fenix", - "rev": "a1a5f92f47787e7df9f30e5e5ac13e679215aa1e", + "rev": "6ed03ef4c8ec36d193c18e06b9ecddde78fb7e42", "type": "github" }, "original": { @@ -546,11 +546,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1751433876, - "narHash": "sha256-IsdwOcvLLDDlkFNwhdD5BZy20okIQL01+UQ7Kxbqh8s=", + "lastModified": 1755504847, + "narHash": "sha256-VX0B9hwhJypCGqncVVLC+SmeMVd/GAYbJZ0MiiUn2Pk=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "11d45c881389dae90b0da5a94cde52c79d0fc7ef", + "rev": "a905e3b21b144d77e1b304e49f3264f6f8d4db75", "type": "github" }, "original": { From 8b35de6a430fae8be5d8291d8d73c9420aafff6a Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Fri, 22 Aug 2025 00:51:54 +0100 Subject: [PATCH 2226/2291] chore: Fix clippy lints with minimal diff --- Cargo.toml | 5 ++++- src/api/client/sync/v4.rs | 1 + src/core/config/mod.rs | 1 + src/core/debug.rs | 2 +- src/router/serve/unix.rs | 2 +- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c656e183..04ff4bb7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -867,7 +867,7 @@ unused-qualifications = "warn" #unused-results = "warn" # TODO ## some sadness -elided_named_lifetimes = "allow" # TODO! +mismatched_lifetime_syntaxes = "allow" # TODO! let_underscore_drop = "allow" missing_docs = "allow" # cfgs cannot be limited to expected cfgs or their de facto non-transitive/opt-in use-case e.g. @@ -1006,3 +1006,6 @@ literal_string_with_formatting_args = { level = "allow", priority = 1 } needless_raw_string_hashes = "allow" + +# TODO: Enable this lint & fix all instances +collapsible_if = "allow" diff --git a/src/api/client/sync/v4.rs b/src/api/client/sync/v4.rs index 14cd50d8..a16e4526 100644 --- a/src/api/client/sync/v4.rs +++ b/src/api/client/sync/v4.rs @@ -45,6 +45,7 @@ use crate::{ type TodoRooms = BTreeMap, usize, u64)>; const SINGLE_CONNECTION_SYNC: &str = "single_connection_sync"; +#[allow(clippy::cognitive_complexity)] /// POST `/_matrix/client/unstable/org.matrix.msc3575/sync` /// /// Sliding Sync endpoint (future endpoint: `/_matrix/client/v4/sync`) diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index aa021be7..0708196d 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -1,3 +1,4 @@ +#![allow(clippy::doc_link_with_quotes)] pub mod check; pub mod manager; pub mod proxy; diff --git a/src/core/debug.rs b/src/core/debug.rs index 21a5ada4..c728278d 100644 --- a/src/core/debug.rs +++ b/src/core/debug.rs @@ -100,7 +100,7 @@ pub fn trap() { #[must_use] pub fn panic_str(p: &Box) -> &'static str { - p.downcast_ref::<&str>().copied().unwrap_or_default() + (**p).downcast_ref::<&str>().copied().unwrap_or_default() } #[inline(always)] diff --git a/src/router/serve/unix.rs b/src/router/serve/unix.rs index 2af17274..9bb3dd6e 100644 --- a/src/router/serve/unix.rs +++ b/src/router/serve/unix.rs @@ -30,7 +30,7 @@ use tower::{Service, ServiceExt}; type MakeService = IntoMakeServiceWithConnectInfo; -const NULL_ADDR: net::SocketAddr = net::SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0); +const NULL_ADDR: net::SocketAddr = net::SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0); const FINI_POLL_INTERVAL: Duration = Duration::from_millis(750); #[tracing::instrument(skip_all, level = "debug")] From c7adbae03f72250d0fd0ab2ea6ab7911b4369467 Mon Sep 17 00:00:00 2001 From: RatCornu Date: Sat, 9 Aug 2025 15:06:48 +0200 Subject: [PATCH 2227/2291] feat: ldap login --- Cargo.lock | 413 +++++++++++++++++++----- Cargo.toml | 5 + conduwuit-example.toml | 91 ++++++ src/admin/user/commands.rs | 4 +- src/api/Cargo.toml | 3 + src/api/client/account.rs | 5 +- src/api/client/profile.rs | 6 +- src/api/client/session.rs | 211 ++++++++---- src/api/client/unstable.rs | 4 +- src/core/config/mod.rs | 108 +++++++ src/core/error/mod.rs | 2 + src/database/maps.rs | 4 + src/service/Cargo.toml | 5 + src/service/admin/create.rs | 2 +- src/service/emergency/mod.rs | 8 +- src/service/rooms/state_cache/update.rs | 2 +- src/service/users/mod.rs | 203 +++++++++++- 17 files changed, 921 insertions(+), 155 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d7192b6..2b044a1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -126,7 +126,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -183,7 +183,7 @@ dependencies = [ "rustc-hash 2.1.1", "serde", "serde_derive", - "syn", + "syn 2.0.104", ] [[package]] @@ -198,6 +198,45 @@ dependencies = [ "winnow", ] +[[package]] +name = "asn1-rs" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6fd5ddaf0351dff5b8da21b2fb4ff8e08ddd02857f0bf69c47639106c0fff0" +dependencies = [ + "asn1-rs-derive", + "asn1-rs-impl", + "displaydoc", + "nom", + "num-traits", + "rusticata-macros", + "thiserror 1.0.69", + "time", +] + +[[package]] +name = "asn1-rs-derive" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "726535892e8eae7e70657b4c8ea93d26b8553afb1ce617caee529ef96d7dee6c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "synstructure 0.12.6", +] + +[[package]] +name = "asn1-rs-impl" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2777730b2039ac0f95f093556e61b6d26cebed5393ca6f152717777cec3a42ed" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "assign" version = "1.1.1" @@ -250,7 +289,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -261,7 +300,7 @@ checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -433,11 +472,11 @@ dependencies = [ "hyper", "hyper-util", "pin-project-lite", - "rustls", - "rustls-pemfile", + "rustls 0.23.29", + "rustls-pemfile 2.2.0", "rustls-pki-types", "tokio", - "tokio-rustls", + "tokio-rustls 0.26.2", "tower-service", ] @@ -452,9 +491,9 @@ dependencies = [ "http", "http-body-util", "pin-project", - "rustls", + "rustls 0.23.29", "tokio", - "tokio-rustls", + "tokio-rustls 0.26.2", "tokio-util", "tower-layer", "tower-service", @@ -521,7 +560,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn", + "syn 2.0.104", "which", ] @@ -540,7 +579,7 @@ dependencies = [ "regex", "rustc-hash 2.1.1", "shlex", - "syn", + "syn 2.0.104", ] [[package]] @@ -794,7 +833,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -972,7 +1011,7 @@ dependencies = [ "rand 0.8.5", "regex", "reqwest", - "ring", + "ring 0.17.14", "ruma", "sanitize-filename", "serde", @@ -1019,7 +1058,7 @@ dependencies = [ "itertools 0.14.0", "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -1044,7 +1083,7 @@ dependencies = [ "hyper-util", "log", "ruma", - "rustls", + "rustls 0.23.29", "sd-notify", "sentry", "sentry-tower", @@ -1074,6 +1113,7 @@ dependencies = [ "image", "ipaddress", "itertools 0.14.0", + "ldap3", "log", "loole", "lru-cache", @@ -1183,6 +1223,16 @@ dependencies = [ "crossterm", ] +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation" version = "0.10.1" @@ -1256,7 +1306,7 @@ dependencies = [ "proc-macro2", "quote", "strict", - "syn", + "syn 2.0.104", ] [[package]] @@ -1366,7 +1416,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a2785755761f3ddc1492979ce1e48d2c00d09311c39e4466429188f3dd6501" dependencies = [ "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -1393,7 +1443,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -1434,6 +1484,20 @@ dependencies = [ "zeroize", ] +[[package]] +name = "der-parser" +version = "8.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbd676fbbab537128ef0278adb5576cf363cff6aa22a7b24effe97347cfab61e" +dependencies = [ + "asn1-rs", + "displaydoc", + "nom", + "num-bigint", + "num-traits", + "rusticata-macros", +] + [[package]] name = "deranged" version = "0.4.0" @@ -1461,7 +1525,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -1483,7 +1547,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -1544,7 +1608,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -1564,7 +1628,7 @@ checksum = "44f23cf4b44bfce11a86ace86f8a73ffdec849c9fd00a386a53d278bd9e81fb3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -1734,6 +1798,7 @@ checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", + "futures-executor", "futures-io", "futures-sink", "futures-task", @@ -1781,7 +1846,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -2030,7 +2095,7 @@ dependencies = [ "ipnet", "once_cell", "rand 0.9.2", - "ring", + "ring 0.17.14", "serde", "thiserror 2.0.12", "tinyvec", @@ -2122,7 +2187,7 @@ dependencies = [ "markup5ever", "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -2216,11 +2281,11 @@ dependencies = [ "http", "hyper", "hyper-util", - "rustls", - "rustls-native-certs", + "rustls 0.23.29", + "rustls-native-certs 0.8.1", "rustls-pki-types", "tokio", - "tokio-rustls", + "tokio-rustls 0.26.2", "tower-service", "webpki-roots 1.0.2", ] @@ -2444,7 +2509,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -2613,7 +2678,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn", + "syn 2.0.104", ] [[package]] @@ -2628,6 +2693,43 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" +[[package]] +name = "lber" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2df7f9fd9f64cf8f59e1a4a0753fe7d575a5b38d3d7ac5758dcee9357d83ef0a" +dependencies = [ + "bytes", + "nom", +] + +[[package]] +name = "ldap3" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "166199a8207874a275144c8a94ff6eed5fcbf5c52303e4d9b4d53a0c7ac76554" +dependencies = [ + "async-trait", + "bytes", + "futures", + "futures-util", + "lazy_static", + "lber", + "log", + "nom", + "percent-encoding", + "ring 0.16.20", + "rustls 0.21.12", + "rustls-native-certs 0.6.3", + "thiserror 1.0.69", + "tokio", + "tokio-rustls 0.24.1", + "tokio-stream", + "tokio-util", + "url", + "x509-parser", +] + [[package]] name = "lebe" version = "0.5.2" @@ -2866,7 +2968,7 @@ checksum = "a9882ef5c56df184b8ffc107fc6c61e33ee3a654b021961d790a78571bb9d67a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -3032,7 +3134,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -3094,6 +3196,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "oid-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bedf36ffb6ba96c2eb7144ef6270557b52e54b20c0a8e1eb2ff99a6c6959bff" +dependencies = [ + "asn1-rs", +] + [[package]] name = "once_cell" version = "1.21.3" @@ -3284,7 +3395,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -3358,7 +3469,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -3458,7 +3569,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff24dfcda44452b9816fff4cd4227e1bb73ff5a2f1bc1105aa92fb8565ce44d2" dependencies = [ "proc-macro2", - "syn", + "syn 2.0.104", ] [[package]] @@ -3487,7 +3598,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", "version_check", "yansi", ] @@ -3508,7 +3619,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52717f9a02b6965224f95ca2a81e2e0c5c43baacd28ca057577988930b6c3d5b" dependencies = [ "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -3531,7 +3642,7 @@ dependencies = [ "itertools 0.14.0", "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -3597,7 +3708,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash 2.1.1", - "rustls", + "rustls 0.23.29", "socket2", "thiserror 2.0.12", "tokio", @@ -3615,9 +3726,9 @@ dependencies = [ "getrandom 0.3.3", "lru-slab", "rand 0.9.2", - "ring", + "ring 0.17.14", "rustc-hash 2.1.1", - "rustls", + "rustls 0.23.29", "rustls-pki-types", "slab", "thiserror 2.0.12", @@ -3876,16 +3987,16 @@ dependencies = [ "percent-encoding", "pin-project-lite", "quinn", - "rustls", - "rustls-native-certs", - "rustls-pemfile", + "rustls 0.23.29", + "rustls-native-certs 0.8.1", + "rustls-pemfile 2.2.0", "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", "tokio", - "tokio-rustls", + "tokio-rustls 0.26.2", "tokio-socks", "tokio-util", "tower 0.5.2", @@ -3909,6 +4020,21 @@ version = "0.8.52" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c6a884d2998352bb4daf0183589aec883f16a6da1f4dde84d8e2e9a5409a1ce" +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted 0.7.1", + "web-sys", + "winapi", +] + [[package]] name = "ring" version = "0.17.14" @@ -3919,7 +4045,7 @@ dependencies = [ "cfg-if", "getrandom 0.2.16", "libc", - "untrusted", + "untrusted 0.9.0", "windows-sys 0.52.0", ] @@ -4093,7 +4219,7 @@ dependencies = [ "quote", "ruma-identifiers-validation", "serde", - "syn", + "syn 2.0.104", "toml", ] @@ -4178,6 +4304,15 @@ dependencies = [ "semver", ] +[[package]] +name = "rusticata-macros" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632" +dependencies = [ + "nom", +] + [[package]] name = "rustix" version = "0.38.44" @@ -4204,6 +4339,18 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "rustls" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +dependencies = [ + "log", + "ring 0.17.14", + "rustls-webpki 0.101.7", + "sct", +] + [[package]] name = "rustls" version = "0.23.29" @@ -4213,13 +4360,25 @@ dependencies = [ "aws-lc-rs", "log", "once_cell", - "ring", + "ring 0.17.14", "rustls-pki-types", - "rustls-webpki", + "rustls-webpki 0.103.4", "subtle", "zeroize", ] +[[package]] +name = "rustls-native-certs" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +dependencies = [ + "openssl-probe", + "rustls-pemfile 1.0.4", + "schannel", + "security-framework 2.11.1", +] + [[package]] name = "rustls-native-certs" version = "0.8.1" @@ -4229,7 +4388,16 @@ dependencies = [ "openssl-probe", "rustls-pki-types", "schannel", - "security-framework", + "security-framework 3.2.0", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", ] [[package]] @@ -4251,6 +4419,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring 0.17.14", + "untrusted 0.9.0", +] + [[package]] name = "rustls-webpki" version = "0.103.4" @@ -4258,9 +4436,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a17884ae0c1b773f1ccd2bd4a8c72f16da897310a98b0e84bf349ad5ead92fc" dependencies = [ "aws-lc-rs", - "ring", + "ring 0.17.14", "rustls-pki-types", - "untrusted", + "untrusted 0.9.0", ] [[package]] @@ -4319,6 +4497,16 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring 0.17.14", + "untrusted 0.9.0", +] + [[package]] name = "sd-notify" version = "0.4.5" @@ -4328,6 +4516,19 @@ dependencies = [ "libc", ] +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags 2.9.1", + "core-foundation 0.9.4", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + [[package]] name = "security-framework" version = "3.2.0" @@ -4335,7 +4536,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316" dependencies = [ "bitflags 2.9.1", - "core-foundation", + "core-foundation 0.10.1", "core-foundation-sys", "libc", "security-framework-sys", @@ -4365,7 +4566,7 @@ checksum = "255914a8e53822abd946e2ce8baa41d4cded6b8e938913b7f7b9da5b7ab44335" dependencies = [ "httpdate", "reqwest", - "rustls", + "rustls 0.23.29", "sentry-backtrace", "sentry-contexts", "sentry-core", @@ -4509,7 +4710,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -4723,6 +4924,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spki" version = "0.7.3" @@ -4791,6 +4998,17 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.104" @@ -4811,6 +5029,18 @@ dependencies = [ "futures-core", ] +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "unicode-xid", +] + [[package]] name = "synstructure" version = "0.13.2" @@ -4819,7 +5049,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -4910,7 +5140,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -4921,7 +5151,7 @@ checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -5088,7 +5318,7 @@ checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -5103,13 +5333,23 @@ dependencies = [ "tokio-stream", ] +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls 0.21.12", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e727b36a1a0e8b74c376ac2211e40c2c8af09fb4013c60d910495810f008e9b" dependencies = [ - "rustls", + "rustls 0.23.29", "tokio", ] @@ -5307,7 +5547,7 @@ source = "git+https://forgejo.ellis.link/continuwuation/tracing?rev=1e64095a8051 dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -5461,12 +5701,24 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "unsafe-libyaml" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "untrusted" version = "0.9.0" @@ -5482,7 +5734,7 @@ dependencies = [ "base64 0.22.1", "log", "once_cell", - "rustls", + "rustls 0.23.29", "rustls-pki-types", "url", "webpki-roots 0.26.11", @@ -5617,7 +5869,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn", + "syn 2.0.104", "wasm-bindgen-shared", ] @@ -5652,7 +5904,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5832,7 +6084,7 @@ checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -5843,7 +6095,7 @@ checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -6164,6 +6416,23 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" +[[package]] +name = "x509-parser" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7069fba5b66b9193bd2c5d3d4ff12b839118f6bcbef5328efafafb5395cf63da" +dependencies = [ + "asn1-rs", + "data-encoding", + "der-parser", + "lazy_static", + "nom", + "oid-registry", + "rusticata-macros", + "thiserror 1.0.69", + "time", +] + [[package]] name = "xml5ever" version = "0.18.1" @@ -6221,8 +6490,8 @@ checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" dependencies = [ "proc-macro2", "quote", - "syn", - "synstructure", + "syn 2.0.104", + "synstructure 0.13.2", ] [[package]] @@ -6242,7 +6511,7 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] @@ -6262,8 +6531,8 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn", - "synstructure", + "syn 2.0.104", + "synstructure 0.13.2", ] [[package]] @@ -6302,7 +6571,7 @@ checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.104", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 04ff4bb7..9452066c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -546,6 +546,11 @@ features = ["std"] [workspace.dependencies.maplit] version = "1.0.2" +[workspace.dependencies.ldap3] +version = "0.11.5" +default-features = false +features = ["sync", "tls-rustls"] + # # Patches # diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 541050b1..47a9da19 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -1696,6 +1696,10 @@ # #config_reload_signal = true +# This item is undocumented. Please contribute documentation for it. +# +#ldap = false + [global.tls] # Path to a valid TLS certificate file. @@ -1774,3 +1778,90 @@ # is 33.55MB. Setting it to 0 disables blurhashing. # #blurhash_max_raw_size = 33554432 + +[global.ldap] + +# Whether to enable LDAP login. +# +# example: "true" +# +#enable = false + +# URI of the LDAP server. +# +# example: "ldap://ldap.example.com:389" +# +#uri = + +# Root of the searches. +# +# example: "ou=users,dc=example,dc=org" +# +#base_dn = false + +# Bind DN if anonymous search is not enabled. +# +# You can use the variable `{username}` that will be replaced by the +# entered username. In such case, the password used to bind will be the +# one provided for the login and not the one given by +# `bind_password_file`. Beware: automatically granting admin rights will +# not work if you use this direct bind instead of a LDAP search. +# +# example: "cn=ldap-reader,dc=example,dc=org" or +# "cn={username},ou=users,dc=example,dc=org" +# +#bind_dn = false + +# Path to a file on the system that contains the password for the +# `bind_dn`. +# +# The server must be able to access the file, and it must not be empty. +# +#bind_password_file = false + +# Search filter to limit user searches. +# +# You can use the variable `{username}` that will be replaced by the +# entered username for more complex filters. +# +# example: "(&(objectClass=person)(memberOf=matrix))" +# +#filter = "(objectClass=*)" + +# Attribute to use to uniquely identify the user. +# +# example: "uid" or "cn" +# +#uid_attribute = "uid" + +# Attribute containing the mail of the user. +# +# example: "mail" +# +#mail_attribute = "mail" + +# Attribute containing the distinguished name of the user. +# +# example: "givenName" or "sn" +# +#name_attribute = "givenName" + +# Root of the searches for admin users. +# +# Defaults to `base_dn` if empty. +# +# example: "ou=admins,dc=example,dc=org" +# +#admin_base_dn = false + +# The LDAP search filter to find administrative users for conduwuit. +# +# If left blank, administrative state must be configured manually for each +# user. +# +# You can use the variable `{username}` that will be replaced by the +# entered username for more complex filters. +# +# example: "(objectClass=conduwuitAdmin)" or "(uid={username})" +# +#admin_filter = false diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 86206c2b..56864a32 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -68,7 +68,8 @@ pub(super) async fn create_user(&self, username: String, password: Option return Err!("Couldn't reset the password for user {user_id}: {e}"), | Ok(()) => { diff --git a/src/api/Cargo.toml b/src/api/Cargo.toml index 15ada812..9b4ea460 100644 --- a/src/api/Cargo.toml +++ b/src/api/Cargo.toml @@ -49,6 +49,9 @@ jemalloc_stats = [ "conduwuit-core/jemalloc_stats", "conduwuit-service/jemalloc_stats", ] +ldap = [ + "conduwuit-service/ldap" +] release_max_log_level = [ "conduwuit-core/release_max_log_level", "conduwuit-service/release_max_log_level", diff --git a/src/api/client/account.rs b/src/api/client/account.rs index 0cea7bd9..67268c9f 100644 --- a/src/api/client/account.rs +++ b/src/api/client/account.rs @@ -373,7 +373,7 @@ pub(crate) async fn register_route( let password = if is_guest { None } else { body.password.as_deref() }; // Create user - services.users.create(&user_id, password)?; + services.users.create(&user_id, password, None).await?; // Default to pretty displayname let mut displayname = user_id.localpart().to_owned(); @@ -659,7 +659,8 @@ pub(crate) async fn change_password_route( services .users - .set_password(sender_user, Some(&body.new_password))?; + .set_password(sender_user, Some(&body.new_password)) + .await?; if body.logout_devices { // Logout all devices except the current one diff --git a/src/api/client/profile.rs b/src/api/client/profile.rs index 1882495c..eaa66e70 100644 --- a/src/api/client/profile.rs +++ b/src/api/client/profile.rs @@ -90,7 +90,7 @@ pub(crate) async fn get_displayname_route( .await { if !services.users.exists(&body.user_id).await { - services.users.create(&body.user_id, None)?; + services.users.create(&body.user_id, None, None).await?; } services @@ -189,7 +189,7 @@ pub(crate) async fn get_avatar_url_route( .await { if !services.users.exists(&body.user_id).await { - services.users.create(&body.user_id, None)?; + services.users.create(&body.user_id, None, None).await?; } services @@ -248,7 +248,7 @@ pub(crate) async fn get_profile_route( .await { if !services.users.exists(&body.user_id).await { - services.users.create(&body.user_id, None)?; + services.users.create(&body.user_id, None, None).await?; } services diff --git a/src/api/client/session.rs b/src/api/client/session.rs index fe07e41d..2f066d58 100644 --- a/src/api/client/session.rs +++ b/src/api/client/session.rs @@ -6,10 +6,11 @@ use conduwuit::{ Err, Error, Result, debug, err, info, utils, utils::{ReadyExt, hash}, }; -use conduwuit_service::uiaa::SESSION_ID_LENGTH; +use conduwuit_core::debug_error; +use conduwuit_service::{Services, uiaa::SESSION_ID_LENGTH}; use futures::StreamExt; use ruma::{ - UserId, + OwnedUserId, UserId, api::client::{ session::{ get_login_token, @@ -49,6 +50,147 @@ pub(crate) async fn get_login_types_route( ])) } +/// Authenticates the given user by its ID and its password. +/// +/// Returns the user ID if successful, and an error otherwise. +#[tracing::instrument(skip_all, fields(%user_id), name = "password")] +pub(crate) async fn password_login( + services: &Services, + user_id: &UserId, + lowercased_user_id: &UserId, + password: &str, +) -> Result { + // Restrict login to accounts only of type 'password', including untyped + // legacy accounts which are equivalent to 'password'. + if services + .users + .origin(user_id) + .await + .is_ok_and(|origin| origin != "password") + { + return Err!(Request(Forbidden("Account does not permit password login."))); + } + + let (hash, user_id) = match services.users.password_hash(user_id).await { + | Ok(hash) => (hash, user_id), + | Err(_) => services + .users + .password_hash(lowercased_user_id) + .await + .map(|hash| (hash, lowercased_user_id)) + .map_err(|_| err!(Request(Forbidden("Wrong username or password."))))?, + }; + + if hash.is_empty() { + return Err!(Request(UserDeactivated("The user has been deactivated"))); + } + + hash::verify_password(password, &hash) + .inspect_err(|e| debug_error!("{e}")) + .map_err(|_| err!(Request(Forbidden("Wrong username or password."))))?; + + Ok(user_id.to_owned()) +} + +/// Authenticates the given user through the configured LDAP server. +/// +/// Creates the user if the user is found in the LDAP and do not already have an +/// account. +#[tracing::instrument(skip_all, fields(%user_id), name = "ldap")] +pub(super) async fn ldap_login( + services: &Services, + user_id: &UserId, + lowercased_user_id: &UserId, + password: &str, +) -> Result { + let (user_dn, is_ldap_admin) = match services.config.ldap.bind_dn.as_ref() { + | Some(bind_dn) if bind_dn.contains("{username}") => + (bind_dn.replace("{username}", lowercased_user_id.localpart()), false), + | _ => { + debug!("Searching user in LDAP"); + + let dns = services.users.search_ldap(user_id).await?; + if dns.len() >= 2 { + return Err!(Ldap("LDAP search returned two or more results")); + } + + let Some((user_dn, is_admin)) = dns.first() else { + return password_login(services, user_id, lowercased_user_id, password).await; + }; + + (user_dn.clone(), *is_admin) + }, + }; + + let user_id = services + .users + .auth_ldap(&user_dn, password) + .await + .map(|()| lowercased_user_id.to_owned())?; + + // LDAP users are automatically created on first login attempt. This is a very + // common feature that can be seen on many services using a LDAP provider for + // their users (synapse, Nextcloud, Jellyfin, ...). + // + // LDAP users are crated with a dummy password but non empty because an empty + // password is reserved for deactivated accounts. The conduwuit password field + // will never be read to login a LDAP user so it's not an issue. + if !services.users.exists(lowercased_user_id).await { + services + .users + .create(lowercased_user_id, Some("*"), Some("ldap")) + .await?; + } + + let is_conduwuit_admin = services.admin.user_is_admin(lowercased_user_id).await; + + if is_ldap_admin && !is_conduwuit_admin { + services.admin.make_user_admin(lowercased_user_id).await?; + } else if !is_ldap_admin && is_conduwuit_admin { + services.admin.revoke_admin(lowercased_user_id).await?; + } + + Ok(user_id) +} + +pub(crate) async fn handle_login( + services: &Services, + body: &Ruma, + identifier: &Option, + password: &str, + user: &Option, +) -> Result { + debug!("Got password login type"); + let user_id = + if let Some(uiaa::UserIdentifier::UserIdOrLocalpart(user_id)) = identifier { + UserId::parse_with_server_name(user_id, &services.config.server_name) + } else if let Some(user) = user { + UserId::parse_with_server_name(user, &services.config.server_name) + } else { + return Err!(Request(Unknown( + debug_warn!(?body.login_info, "Valid identifier or username was not provided (invalid or unsupported login type?)") + ))); + } + .map_err(|e| err!(Request(InvalidUsername(warn!("Username is invalid: {e}")))))?; + + let lowercased_user_id = UserId::parse_with_server_name( + user_id.localpart().to_lowercase(), + &services.config.server_name, + )?; + + if !services.globals.user_is_local(&user_id) + || !services.globals.user_is_local(&lowercased_user_id) + { + return Err!(Request(Unknown("User ID does not belong to this homeserver"))); + } + + if cfg!(feature = "ldap") && services.config.ldap.enable { + ldap_login(services, &user_id, &lowercased_user_id, password).await + } else { + password_login(services, &user_id, &lowercased_user_id, password).await + } +} + /// # `POST /_matrix/client/v3/login` /// /// Authenticates the user and returns an access token it can use in subsequent @@ -80,70 +222,7 @@ pub(crate) async fn login_route( password, user, .. - }) => { - debug!("Got password login type"); - let user_id = - if let Some(uiaa::UserIdentifier::UserIdOrLocalpart(user_id)) = identifier { - UserId::parse_with_server_name(user_id, &services.config.server_name) - } else if let Some(user) = user { - UserId::parse_with_server_name(user, &services.config.server_name) - } else { - return Err!(Request(Unknown( - debug_warn!(?body.login_info, "Valid identifier or username was not provided (invalid or unsupported login type?)") - ))); - } - .map_err(|e| err!(Request(InvalidUsername(warn!("Username is invalid: {e}")))))?; - - let lowercased_user_id = UserId::parse_with_server_name( - user_id.localpart().to_lowercase(), - &services.config.server_name, - )?; - - if !services.globals.user_is_local(&user_id) - || !services.globals.user_is_local(&lowercased_user_id) - { - return Err!(Request(Unknown("User ID does not belong to this homeserver"))); - } - - // first try the username as-is - let hash = services - .users - .password_hash(&user_id) - .await - .inspect_err(|e| debug!("{e}")); - - match hash { - | Ok(hash) => { - if hash.is_empty() { - return Err!(Request(UserDeactivated("The user has been deactivated"))); - } - - hash::verify_password(password, &hash) - .inspect_err(|e| debug!("{e}")) - .map_err(|_| err!(Request(Forbidden("Wrong username or password."))))?; - - user_id - }, - | Err(_e) => { - let hash_lowercased_user_id = services - .users - .password_hash(&lowercased_user_id) - .await - .inspect_err(|e| debug!("{e}")) - .map_err(|_| err!(Request(Forbidden("Wrong username or password."))))?; - - if hash_lowercased_user_id.is_empty() { - return Err!(Request(UserDeactivated("The user has been deactivated"))); - } - - hash::verify_password(password, &hash_lowercased_user_id) - .inspect_err(|e| debug!("{e}")) - .map_err(|_| err!(Request(Forbidden("Wrong username or password."))))?; - - lowercased_user_id - }, - } - }, + }) => handle_login(&services, &body, identifier, password, user).await?, | login::v3::LoginInfo::Token(login::v3::Token { token }) => { debug!("Got token login type"); if !services.server.config.login_via_existing_session { diff --git a/src/api/client/unstable.rs b/src/api/client/unstable.rs index 08f70975..f8703ff3 100644 --- a/src/api/client/unstable.rs +++ b/src/api/client/unstable.rs @@ -292,7 +292,7 @@ pub(crate) async fn get_timezone_key_route( .await { if !services.users.exists(&body.user_id).await { - services.users.create(&body.user_id, None)?; + services.users.create(&body.user_id, None, None).await?; } services @@ -352,7 +352,7 @@ pub(crate) async fn get_profile_key_route( .await { if !services.users.exists(&body.user_id).await { - services.users.create(&body.user_id, None)?; + services.users.create(&body.user_id, None, None).await?; } services diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 0708196d..a7fbc7dc 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -1948,6 +1948,10 @@ pub struct Config { pub allow_invalid_tls_certificates_yes_i_know_what_the_fuck_i_am_doing_with_this_and_i_know_this_is_insecure: bool, + // external structure; separate section + #[serde(default)] + pub ldap: LdapConfig, + // external structure; separate section #[serde(default)] pub blurhashing: BlurhashConfig, @@ -2042,6 +2046,102 @@ pub struct BlurhashConfig { pub blurhash_max_raw_size: u64, } +#[derive(Clone, Debug, Default, Deserialize)] +#[config_example_generator(filename = "conduwuit-example.toml", section = "global.ldap")] +pub struct LdapConfig { + /// Whether to enable LDAP login. + /// + /// example: "true" + #[serde(default)] + pub enable: bool, + + /// URI of the LDAP server. + /// + /// example: "ldap://ldap.example.com:389" + pub uri: Option, + + /// Root of the searches. + /// + /// example: "ou=users,dc=example,dc=org" + #[serde(default)] + pub base_dn: String, + + /// Bind DN if anonymous search is not enabled. + /// + /// You can use the variable `{username}` that will be replaced by the + /// entered username. In such case, the password used to bind will be the + /// one provided for the login and not the one given by + /// `bind_password_file`. Beware: automatically granting admin rights will + /// not work if you use this direct bind instead of a LDAP search. + /// + /// example: "cn=ldap-reader,dc=example,dc=org" or + /// "cn={username},ou=users,dc=example,dc=org" + #[serde(default)] + pub bind_dn: Option, + + /// Path to a file on the system that contains the password for the + /// `bind_dn`. + /// + /// The server must be able to access the file, and it must not be empty. + #[serde(default)] + pub bind_password_file: Option, + + /// Search filter to limit user searches. + /// + /// You can use the variable `{username}` that will be replaced by the + /// entered username for more complex filters. + /// + /// example: "(&(objectClass=person)(memberOf=matrix))" + /// + /// default: "(objectClass=*)" + #[serde(default = "default_ldap_search_filter")] + pub filter: String, + + /// Attribute to use to uniquely identify the user. + /// + /// example: "uid" or "cn" + /// + /// default: "uid" + #[serde(default = "default_ldap_uid_attribute")] + pub uid_attribute: String, + + /// Attribute containing the mail of the user. + /// + /// example: "mail" + /// + /// default: "mail" + #[serde(default = "default_ldap_mail_attribute")] + pub mail_attribute: String, + + /// Attribute containing the distinguished name of the user. + /// + /// example: "givenName" or "sn" + /// + /// default: "givenName" + #[serde(default = "default_ldap_name_attribute")] + pub name_attribute: String, + + /// Root of the searches for admin users. + /// + /// Defaults to `base_dn` if empty. + /// + /// example: "ou=admins,dc=example,dc=org" + #[serde(default)] + pub admin_base_dn: String, + + /// The LDAP search filter to find administrative users for conduwuit. + /// + /// If left blank, administrative state must be configured manually for each + /// user. + /// + /// You can use the variable `{username}` that will be replaced by the + /// entered username for more complex filters. + /// + /// example: "(objectClass=conduwuitAdmin)" or "(uid={username})" + #[serde(default)] + pub admin_filter: String, +} + #[derive(Deserialize, Clone, Debug)] #[serde(transparent)] struct ListeningPort { @@ -2431,3 +2531,11 @@ pub(super) fn default_blurhash_x_component() -> u32 { 4 } pub(super) fn default_blurhash_y_component() -> u32 { 3 } // end recommended & blurhashing defaults + +fn default_ldap_search_filter() -> String { "(objectClass=*)".to_owned() } + +fn default_ldap_uid_attribute() -> String { String::from("uid") } + +fn default_ldap_mail_attribute() -> String { String::from("mail") } + +fn default_ldap_name_attribute() -> String { String::from("givenName") } diff --git a/src/core/error/mod.rs b/src/core/error/mod.rs index e46edf09..541af793 100644 --- a/src/core/error/mod.rs +++ b/src/core/error/mod.rs @@ -110,6 +110,8 @@ pub enum Error { InconsistentRoomState(&'static str, ruma::OwnedRoomId), #[error(transparent)] IntoHttp(#[from] ruma::api::error::IntoHttpError), + #[error("{0}")] + Ldap(Cow<'static, str>), #[error(transparent)] Mxc(#[from] ruma::MxcUriError), #[error(transparent)] diff --git a/src/database/maps.rs b/src/database/maps.rs index 214dbf34..da97ef45 100644 --- a/src/database/maps.rs +++ b/src/database/maps.rs @@ -374,6 +374,10 @@ pub(super) static MAPS: &[Descriptor] = &[ name: "userid_masterkeyid", ..descriptor::RANDOM_SMALL }, + Descriptor { + name: "userid_origin", + ..descriptor::RANDOM + }, Descriptor { name: "userid_password", ..descriptor::RANDOM diff --git a/src/service/Cargo.toml b/src/service/Cargo.toml index fdebd1d7..6e538f40 100644 --- a/src/service/Cargo.toml +++ b/src/service/Cargo.toml @@ -53,6 +53,9 @@ jemalloc_stats = [ "conduwuit-core/jemalloc_stats", "conduwuit-database/jemalloc_stats", ] +ldap = [ + "dep:ldap3" +] media_thumbnail = [ "dep:image", ] @@ -89,6 +92,8 @@ image.workspace = true image.optional = true ipaddress.workspace = true itertools.workspace = true +ldap3.workspace = true +ldap3.optional = true log.workspace = true loole.workspace = true lru-cache.workspace = true diff --git a/src/service/admin/create.rs b/src/service/admin/create.rs index 157b4d65..755673fe 100644 --- a/src/service/admin/create.rs +++ b/src/service/admin/create.rs @@ -38,7 +38,7 @@ pub async fn create_admin_room(services: &Services) -> Result { // Create a user for the server let server_user = services.globals.server_user.as_ref(); - services.users.create(server_user, None)?; + services.users.create(server_user, None, None).await?; let create_content = { use RoomVersionId::*; diff --git a/src/service/emergency/mod.rs b/src/service/emergency/mod.rs index 3a61f710..f8ecbb3e 100644 --- a/src/service/emergency/mod.rs +++ b/src/service/emergency/mod.rs @@ -41,6 +41,11 @@ impl crate::Service for Service { return Ok(()); } + if self.services.config.ldap.enable { + warn!("emergency password feature not available with LDAP enabled."); + return Ok(()); + } + self.set_emergency_access().await.inspect_err(|e| { error!("Could not set the configured emergency password for the server user: {e}"); }) @@ -57,7 +62,8 @@ impl Service { self.services .users - .set_password(server_user, self.services.config.emergency_password.as_deref())?; + .set_password(server_user, self.services.config.emergency_password.as_deref()) + .await?; let (ruleset, pwd_set) = match self.services.config.emergency_password { | Some(_) => (Ruleset::server_default(server_user), true), diff --git a/src/service/rooms/state_cache/update.rs b/src/service/rooms/state_cache/update.rs index 32c67947..86c1afe7 100644 --- a/src/service/rooms/state_cache/update.rs +++ b/src/service/rooms/state_cache/update.rs @@ -49,7 +49,7 @@ pub async fn update_membership( #[allow(clippy::collapsible_if)] if !self.services.globals.user_is_local(user_id) { if !self.services.users.exists(user_id).await { - self.services.users.create(user_id, None)?; + self.services.users.create(user_id, None, None).await?; } } diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index eb54660e..35202ec7 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -1,11 +1,19 @@ -use std::{collections::BTreeMap, mem, sync::Arc}; +use std::{ + collections::{BTreeMap, HashMap}, + mem, + sync::Arc, +}; use conduwuit::{ - Err, Error, Result, Server, at, debug_warn, err, trace, + Err, Error, Result, Server, at, debug_warn, err, is_equal_to, + result::LogErr, + trace, utils::{self, ReadyExt, stream::TryIgnore, string::Unquoted}, }; +use conduwuit_core::{debug, error}; use database::{Deserialized, Ignore, Interfix, Json, Map}; use futures::{Stream, StreamExt, TryFutureExt}; +use ldap3::{LdapConnAsync, Scope, SearchEntry}; use ruma::{ DeviceId, KeyId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OneTimeKeyId, OneTimeKeyName, OwnedDeviceId, OwnedKeyId, OwnedMxcUri, OwnedUserId, RoomId, UInt, UserId, @@ -63,6 +71,7 @@ struct Data { userid_displayname: Arc, userid_lastonetimekeyupdate: Arc, userid_masterkeyid: Arc, + userid_origin: Arc, userid_password: Arc, userid_suspension: Arc, userid_selfsigningkeyid: Arc, @@ -100,6 +109,7 @@ impl crate::Service for Service { userid_displayname: args.db["userid_displayname"].clone(), userid_lastonetimekeyupdate: args.db["userid_lastonetimekeyupdate"].clone(), userid_masterkeyid: args.db["userid_masterkeyid"].clone(), + userid_origin: args.db["userid_origin"].clone(), userid_password: args.db["userid_password"].clone(), userid_suspension: args.db["userid_suspension"].clone(), userid_selfsigningkeyid: args.db["userid_selfsigningkeyid"].clone(), @@ -136,9 +146,21 @@ impl Service { } /// Create a new user account on this homeserver. + /// + /// User origin is by default "password" (meaning that it will login using + /// its user_id/password). Users with other origins (currently only "ldap" + /// is available) have special login processes. #[inline] - pub fn create(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { - self.set_password(user_id, password) + pub async fn create( + &self, + user_id: &UserId, + password: Option<&str>, + origin: Option<&str>, + ) -> Result<()> { + self.db + .userid_origin + .insert(user_id, origin.unwrap_or("password")); + self.set_password(user_id, password).await } /// Deactivate account @@ -152,7 +174,7 @@ impl Service { // result in an empty string, so the user will not be able to log in again. // Systems like changing the password without logging in should check if the // account is deactivated. - self.set_password(user_id, None)?; + self.set_password(user_id, None).await?; // TODO: Unhook 3PID Ok(()) @@ -253,13 +275,34 @@ impl Service { .ready_filter_map(|(u, p): (&UserId, &[u8])| (!p.is_empty()).then_some(u)) } + /// Returns the origin of the user (password/LDAP/...). + pub async fn origin(&self, user_id: &UserId) -> Result { + self.db.userid_origin.get(user_id).await.deserialized() + } + /// Returns the password hash for the given user. pub async fn password_hash(&self, user_id: &UserId) -> Result { self.db.userid_password.get(user_id).await.deserialized() } /// Hash and set the user's password to the Argon2 hash - pub fn set_password(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { + pub async fn set_password(&self, user_id: &UserId, password: Option<&str>) -> Result<()> { + // Cannot change the password of a LDAP user. There are two special cases : + // - a `None` password can be used to deactivate a LDAP user + // - a "*" password is used as the default password of an active LDAP user + if cfg!(feature = "ldap") + && password.is_some_and(|pwd| pwd != "*") + && self + .db + .userid_origin + .get(user_id) + .await + .deserialized::() + .is_ok_and(is_equal_to!("ldap")) + { + return Err!(Request(InvalidParam("Cannot change password of a LDAP user"))); + } + password .map(utils::hash::password) .transpose() @@ -1132,6 +1175,154 @@ impl Service { self.db.useridprofilekey_value.del(key); } } + + #[cfg(not(feature = "ldap"))] + pub async fn search_ldap(&self, _user_id: &UserId) -> Result> { + Err!(FeatureDisabled("ldap")) + } + + #[cfg(feature = "ldap")] + pub async fn search_ldap(&self, user_id: &UserId) -> Result> { + let localpart = user_id.localpart().to_owned(); + let lowercased_localpart = localpart.to_lowercase(); + + let config = &self.services.server.config.ldap; + let uri = config + .uri + .as_ref() + .ok_or_else(|| err!(Ldap(error!("LDAP URI is not configured."))))?; + + debug!(?uri, "LDAP creating connection..."); + let (conn, mut ldap) = LdapConnAsync::new(uri.as_str()) + .await + .map_err(|e| err!(Ldap(error!(?user_id, "LDAP connection setup error: {e}"))))?; + + let driver = self.services.server.runtime().spawn(async move { + match conn.drive().await { + | Err(e) => error!("LDAP connection error: {e}"), + | Ok(()) => debug!("LDAP connection completed."), + } + }); + + match (&config.bind_dn, &config.bind_password_file) { + | (Some(bind_dn), Some(bind_password_file)) => { + let bind_pw = String::from_utf8(std::fs::read(bind_password_file)?)?; + ldap.simple_bind(bind_dn, bind_pw.trim()) + .await + .and_then(ldap3::LdapResult::success) + .map_err(|e| err!(Ldap(error!("LDAP bind error: {e}"))))?; + }, + | (..) => {}, + } + + let attr = [&config.uid_attribute, &config.name_attribute]; + + let user_filter = &config.filter.replace("{username}", &lowercased_localpart); + + let (entries, _result) = ldap + .search(&config.base_dn, Scope::Subtree, user_filter, &attr) + .await + .and_then(ldap3::SearchResult::success) + .inspect(|(entries, result)| trace!(?entries, ?result, "LDAP Search")) + .map_err(|e| err!(Ldap(error!(?attr, ?user_filter, "LDAP search error: {e}"))))?; + + let mut dns: HashMap = entries + .into_iter() + .filter_map(|entry| { + let search_entry = SearchEntry::construct(entry); + debug!(?search_entry, "LDAP search entry"); + search_entry + .attrs + .get(&config.uid_attribute) + .into_iter() + .chain(search_entry.attrs.get(&config.name_attribute)) + .any(|ids| ids.contains(&localpart) || ids.contains(&lowercased_localpart)) + .then_some((search_entry.dn, false)) + }) + .collect(); + + if !config.admin_filter.is_empty() { + let admin_base_dn = if config.admin_base_dn.is_empty() { + &config.base_dn + } else { + &config.admin_base_dn + }; + + let admin_filter = &config + .admin_filter + .replace("{username}", &lowercased_localpart); + + let (admin_entries, _result) = ldap + .search(admin_base_dn, Scope::Subtree, admin_filter, &attr) + .await + .and_then(ldap3::SearchResult::success) + .inspect(|(entries, result)| trace!(?entries, ?result, "LDAP Admin Search")) + .map_err(|e| { + err!(Ldap(error!(?attr, ?admin_filter, "Ldap admin search error: {e}"))) + })?; + + dns.extend(admin_entries.into_iter().filter_map(|entry| { + let search_entry = SearchEntry::construct(entry); + debug!(?search_entry, "LDAP search entry"); + search_entry + .attrs + .get(&config.uid_attribute) + .into_iter() + .chain(search_entry.attrs.get(&config.name_attribute)) + .any(|ids| ids.contains(&localpart) || ids.contains(&lowercased_localpart)) + .then_some((search_entry.dn, true)) + })); + } + + ldap.unbind() + .await + .map_err(|e| err!(Ldap(error!("LDAP unbind error: {e}"))))?; + + driver.await.log_err().ok(); + + Ok(dns.drain().collect()) + } + + #[cfg(not(feature = "ldap"))] + pub async fn auth_ldap(&self, _user_dn: &str, _password: &str) -> Result { + Err!(FeatureDisabled("ldap")) + } + + #[cfg(feature = "ldap")] + pub async fn auth_ldap(&self, user_dn: &str, password: &str) -> Result { + let config = &self.services.server.config.ldap; + let uri = config + .uri + .as_ref() + .ok_or_else(|| err!(Ldap(error!("LDAP URI is not configured."))))?; + + debug!(?uri, "LDAP creating connection..."); + let (conn, mut ldap) = LdapConnAsync::new(uri.as_str()) + .await + .map_err(|e| err!(Ldap(error!(?user_dn, "LDAP connection setup error: {e}"))))?; + + let driver = self.services.server.runtime().spawn(async move { + match conn.drive().await { + | Err(e) => error!("LDAP connection error: {e}"), + | Ok(()) => debug!("LDAP connection completed."), + } + }); + + ldap.simple_bind(user_dn, password) + .await + .and_then(ldap3::LdapResult::success) + .map_err(|e| { + err!(Request(Forbidden(debug_error!("LDAP authentication error: {e}")))) + })?; + + ldap.unbind() + .await + .map_err(|e| err!(Ldap(error!("LDAP unbind error: {e}"))))?; + + driver.await.log_err().ok(); + + Ok(()) + } } pub fn parse_master_key( From fb7e739b72dad43211ff9b6077c33c479e2574f5 Mon Sep 17 00:00:00 2001 From: RatCornu Date: Sun, 10 Aug 2025 12:50:19 +0200 Subject: [PATCH 2228/2291] chore: remove unused LDAP mail attribute --- conduwuit-example.toml | 18 ++++++------------ src/api/client/session.rs | 8 ++++---- src/core/config/mod.rs | 26 ++++++++++---------------- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 47a9da19..68f5b965 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -1797,7 +1797,7 @@ # # example: "ou=users,dc=example,dc=org" # -#base_dn = false +#base_dn = # Bind DN if anonymous search is not enabled. # @@ -1810,7 +1810,7 @@ # example: "cn=ldap-reader,dc=example,dc=org" or # "cn={username},ou=users,dc=example,dc=org" # -#bind_dn = false +#bind_dn = # Path to a file on the system that contains the password for the # `bind_dn`. @@ -1834,13 +1834,7 @@ # #uid_attribute = "uid" -# Attribute containing the mail of the user. -# -# example: "mail" -# -#mail_attribute = "mail" - -# Attribute containing the distinguished name of the user. +# Attribute containing the display name of the user. # # example: "givenName" or "sn" # @@ -1852,9 +1846,9 @@ # # example: "ou=admins,dc=example,dc=org" # -#admin_base_dn = false +#admin_base_dn = -# The LDAP search filter to find administrative users for conduwuit. +# The LDAP search filter to find administrative users for continuwuity. # # If left blank, administrative state must be configured manually for each # user. @@ -1864,4 +1858,4 @@ # # example: "(objectClass=conduwuitAdmin)" or "(uid={username})" # -#admin_filter = false +#admin_filter = diff --git a/src/api/client/session.rs b/src/api/client/session.rs index 2f066d58..c57f5487 100644 --- a/src/api/client/session.rs +++ b/src/api/client/session.rs @@ -156,9 +156,9 @@ pub(super) async fn ldap_login( pub(crate) async fn handle_login( services: &Services, body: &Ruma, - identifier: &Option, + identifier: Option<&uiaa::UserIdentifier>, password: &str, - user: &Option, + user: Option<&String>, ) -> Result { debug!("Got password login type"); let user_id = @@ -185,7 +185,7 @@ pub(crate) async fn handle_login( } if cfg!(feature = "ldap") && services.config.ldap.enable { - ldap_login(services, &user_id, &lowercased_user_id, password).await + Box::pin(ldap_login(services, &user_id, &lowercased_user_id, password)).await } else { password_login(services, &user_id, &lowercased_user_id, password).await } @@ -222,7 +222,7 @@ pub(crate) async fn login_route( password, user, .. - }) => handle_login(&services, &body, identifier, password, user).await?, + }) => handle_login(&services, &body, identifier.as_ref(), password, user.as_ref()).await?, | login::v3::LoginInfo::Token(login::v3::Token { token }) => { debug!("Got token login type"); if !services.server.config.login_via_existing_session { diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index a7fbc7dc..e996d1fa 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -2063,7 +2063,7 @@ pub struct LdapConfig { /// Root of the searches. /// /// example: "ou=users,dc=example,dc=org" - #[serde(default)] + #[serde(default = "empty_string_fn")] pub base_dn: String, /// Bind DN if anonymous search is not enabled. @@ -2076,7 +2076,7 @@ pub struct LdapConfig { /// /// example: "cn=ldap-reader,dc=example,dc=org" or /// "cn={username},ou=users,dc=example,dc=org" - #[serde(default)] + #[serde(default = "some_empty_string_fn")] pub bind_dn: Option, /// Path to a file on the system that contains the password for the @@ -2105,15 +2105,7 @@ pub struct LdapConfig { #[serde(default = "default_ldap_uid_attribute")] pub uid_attribute: String, - /// Attribute containing the mail of the user. - /// - /// example: "mail" - /// - /// default: "mail" - #[serde(default = "default_ldap_mail_attribute")] - pub mail_attribute: String, - - /// Attribute containing the distinguished name of the user. + /// Attribute containing the display name of the user. /// /// example: "givenName" or "sn" /// @@ -2126,10 +2118,10 @@ pub struct LdapConfig { /// Defaults to `base_dn` if empty. /// /// example: "ou=admins,dc=example,dc=org" - #[serde(default)] + #[serde(default = "empty_string_fn")] pub admin_base_dn: String, - /// The LDAP search filter to find administrative users for conduwuit. + /// The LDAP search filter to find administrative users for continuwuity. /// /// If left blank, administrative state must be configured manually for each /// user. @@ -2138,7 +2130,7 @@ pub struct LdapConfig { /// entered username for more complex filters. /// /// example: "(objectClass=conduwuitAdmin)" or "(uid={username})" - #[serde(default)] + #[serde(default = "empty_string_fn")] pub admin_filter: String, } @@ -2240,6 +2232,10 @@ impl Config { fn true_fn() -> bool { true } +fn empty_string_fn() -> String { String::new() } + +fn some_empty_string_fn() -> Option { Some(String::new()) } + fn default_address() -> ListeningAddr { ListeningAddr { addrs: Right(vec![Ipv4Addr::LOCALHOST.into(), Ipv6Addr::LOCALHOST.into()]), @@ -2536,6 +2532,4 @@ fn default_ldap_search_filter() -> String { "(objectClass=*)".to_owned() } fn default_ldap_uid_attribute() -> String { String::from("uid") } -fn default_ldap_mail_attribute() -> String { String::from("mail") } - fn default_ldap_name_attribute() -> String { String::from("givenName") } From c58b9f05ed89e8a3c4d5d080afa05a3c1aa48882 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 10 Aug 2025 20:49:08 +0100 Subject: [PATCH 2229/2291] chore: Fix default attributes for config --- conduwuit-example.toml | 4 ++-- src/core/config/mod.rs | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 68f5b965..06e67a89 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -1797,7 +1797,7 @@ # # example: "ou=users,dc=example,dc=org" # -#base_dn = +#base_dn = "" # Bind DN if anonymous search is not enabled. # @@ -1846,7 +1846,7 @@ # # example: "ou=admins,dc=example,dc=org" # -#admin_base_dn = +#admin_base_dn = "" # The LDAP search filter to find administrative users for continuwuity. # diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index e996d1fa..13778b5e 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -2063,7 +2063,9 @@ pub struct LdapConfig { /// Root of the searches. /// /// example: "ou=users,dc=example,dc=org" - #[serde(default = "empty_string_fn")] + /// + /// default: "" + #[serde(default)] pub base_dn: String, /// Bind DN if anonymous search is not enabled. @@ -2076,7 +2078,9 @@ pub struct LdapConfig { /// /// example: "cn=ldap-reader,dc=example,dc=org" or /// "cn={username},ou=users,dc=example,dc=org" - #[serde(default = "some_empty_string_fn")] + /// + /// default: + #[serde(default)] pub bind_dn: Option, /// Path to a file on the system that contains the password for the @@ -2118,7 +2122,9 @@ pub struct LdapConfig { /// Defaults to `base_dn` if empty. /// /// example: "ou=admins,dc=example,dc=org" - #[serde(default = "empty_string_fn")] + /// + /// default: "" + #[serde(default)] pub admin_base_dn: String, /// The LDAP search filter to find administrative users for continuwuity. @@ -2130,7 +2136,9 @@ pub struct LdapConfig { /// entered username for more complex filters. /// /// example: "(objectClass=conduwuitAdmin)" or "(uid={username})" - #[serde(default = "empty_string_fn")] + /// + /// default: + #[serde(default)] pub admin_filter: String, } @@ -2232,10 +2240,6 @@ impl Config { fn true_fn() -> bool { true } -fn empty_string_fn() -> String { String::new() } - -fn some_empty_string_fn() -> Option { Some(String::new()) } - fn default_address() -> ListeningAddr { ListeningAddr { addrs: Right(vec![Ipv4Addr::LOCALHOST.into(), Ipv6Addr::LOCALHOST.into()]), From 0ed691edef9d95c8a2e3b54ba8b72ecb6a326e88 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 10 Aug 2025 20:54:05 +0100 Subject: [PATCH 2230/2291] fix: Make builds without LDAP work correctly --- src/service/users/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index 35202ec7..fff1661c 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -1,18 +1,18 @@ -use std::{ - collections::{BTreeMap, HashMap}, - mem, - sync::Arc, -}; +#[cfg(feature = "ldap")] +use std::collections::HashMap; +use std::{collections::BTreeMap, mem, sync::Arc}; +#[cfg(feature = "ldap")] +use conduwuit::result::LogErr; use conduwuit::{ - Err, Error, Result, Server, at, debug_warn, err, is_equal_to, - result::LogErr, - trace, + Err, Error, Result, Server, at, debug_warn, err, is_equal_to, trace, utils::{self, ReadyExt, stream::TryIgnore, string::Unquoted}, }; +#[cfg(feature = "ldap")] use conduwuit_core::{debug, error}; use database::{Deserialized, Ignore, Interfix, Json, Map}; use futures::{Stream, StreamExt, TryFutureExt}; +#[cfg(feature = "ldap")] use ldap3::{LdapConnAsync, Scope, SearchEntry}; use ruma::{ DeviceId, KeyId, MilliSecondsSinceUnixEpoch, OneTimeKeyAlgorithm, OneTimeKeyId, From cb09bfa4e7be034164f810d857fc505d692c06d7 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 10 Aug 2025 21:08:06 +0100 Subject: [PATCH 2231/2291] fix: Correctly pass ldap feature from the default crate --- src/main/Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 8aaa3cc6..eafa1e48 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -56,6 +56,7 @@ standard = [ "jemalloc", "jemalloc_conf", "journald", + "ldap", "media_thumbnail", "systemd", "url_preview", @@ -114,6 +115,9 @@ jemalloc_stats = [ jemalloc_conf = [ "conduwuit-core/jemalloc_conf", ] +ldap = [ + "conduwuit-api/ldap", +] media_thumbnail = [ "conduwuit-service/media_thumbnail", ] From 57d77430370616bbc40aac145da1b79d516431ce Mon Sep 17 00:00:00 2001 From: RatCornu Date: Thu, 14 Aug 2025 22:48:55 +0200 Subject: [PATCH 2232/2291] feat: add ldap_only config option --- conduwuit-example.toml | 14 ++++++++++---- src/api/client/session.rs | 15 +++++++++++---- src/core/config/mod.rs | 16 ++++++++++++++-- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 06e67a89..41fbfb3a 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -1787,11 +1787,17 @@ # #enable = false +# Whether to force LDAP authentication or authorize classical password login. +# +# example: "true" +# +#ldap_only = false + # URI of the LDAP server. # # example: "ldap://ldap.example.com:389" # -#uri = +#uri = "" # Root of the searches. # @@ -1810,14 +1816,14 @@ # example: "cn=ldap-reader,dc=example,dc=org" or # "cn={username},ou=users,dc=example,dc=org" # -#bind_dn = +#bind_dn = "" # Path to a file on the system that contains the password for the # `bind_dn`. # # The server must be able to access the file, and it must not be empty. # -#bind_password_file = false +#bind_password_file = "" # Search filter to limit user searches. # @@ -1858,4 +1864,4 @@ # # example: "(objectClass=conduwuitAdmin)" or "(uid={username})" # -#admin_filter = +#admin_filter = "" diff --git a/src/api/client/session.rs b/src/api/client/session.rs index c57f5487..da7bed2c 100644 --- a/src/api/client/session.rs +++ b/src/api/client/session.rs @@ -3,10 +3,10 @@ use std::time::Duration; use axum::extract::State; use axum_client_ip::InsecureClientIp; use conduwuit::{ - Err, Error, Result, debug, err, info, utils, - utils::{ReadyExt, hash}, + Err, Error, Result, debug, err, info, + utils::{self, ReadyExt, hash}, }; -use conduwuit_core::debug_error; +use conduwuit_core::{debug_error, debug_warn}; use conduwuit_service::{Services, uiaa::SESSION_ID_LENGTH}; use futures::StreamExt; use ruma::{ @@ -185,7 +185,14 @@ pub(crate) async fn handle_login( } if cfg!(feature = "ldap") && services.config.ldap.enable { - Box::pin(ldap_login(services, &user_id, &lowercased_user_id, password)).await + match Box::pin(ldap_login(services, &user_id, &lowercased_user_id, password)).await { + | Ok(user_id) => Ok(user_id), + | Err(err) if services.config.ldap.ldap_only => Err(err), + | Err(err) => { + debug_warn!("{err}"); + password_login(services, &user_id, &lowercased_user_id, password).await + }, + } } else { password_login(services, &user_id, &lowercased_user_id, password).await } diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 13778b5e..e8518ed4 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -2055,9 +2055,19 @@ pub struct LdapConfig { #[serde(default)] pub enable: bool, + /// Whether to force LDAP authentication or authorize classical password + /// login. + /// + /// example: "true" + #[serde(default)] + pub ldap_only: bool, + /// URI of the LDAP server. /// /// example: "ldap://ldap.example.com:389" + /// + /// default: "" + #[serde(default)] pub uri: Option, /// Root of the searches. @@ -2079,7 +2089,7 @@ pub struct LdapConfig { /// example: "cn=ldap-reader,dc=example,dc=org" or /// "cn={username},ou=users,dc=example,dc=org" /// - /// default: + /// default: "" #[serde(default)] pub bind_dn: Option, @@ -2087,6 +2097,8 @@ pub struct LdapConfig { /// `bind_dn`. /// /// The server must be able to access the file, and it must not be empty. + /// + /// default: "" #[serde(default)] pub bind_password_file: Option, @@ -2137,7 +2149,7 @@ pub struct LdapConfig { /// /// example: "(objectClass=conduwuitAdmin)" or "(uid={username})" /// - /// default: + /// default: "" #[serde(default)] pub admin_filter: String, } From 3183210459feb640734341a189a8437fdf7f2240 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 23 Aug 2025 21:28:31 +0100 Subject: [PATCH 2233/2291] fix: Post-merge compile issues --- conduwuit-example.toml | 3 ++- src/service/appservice/mod.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 41fbfb3a..f0e510b4 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -1787,7 +1787,8 @@ # #enable = false -# Whether to force LDAP authentication or authorize classical password login. +# Whether to force LDAP authentication or authorize classical password +# login. # # example: "true" # diff --git a/src/service/appservice/mod.rs b/src/service/appservice/mod.rs index ebd798f6..adbf3b6e 100644 --- a/src/service/appservice/mod.rs +++ b/src/service/appservice/mod.rs @@ -109,7 +109,10 @@ impl Service { )?; if !self.services.users.exists(&appservice_user_id).await { - self.services.users.create(&appservice_user_id, None)?; + self.services + .users + .create(&appservice_user_id, None, None) + .await?; } else if self .services .users @@ -120,7 +123,8 @@ impl Service { // Reactivate the appservice user if it was accidentally deactivated self.services .users - .set_password(&appservice_user_id, None)?; + .set_password(&appservice_user_id, None) + .await?; } self.registration_info From 30a56d5cb95b2545000088d38855724a5a956b40 Mon Sep 17 00:00:00 2001 From: nex Date: Thu, 28 Aug 2025 17:15:32 +0000 Subject: [PATCH 2234/2291] Update renovate.json --- renovate.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/renovate.json b/renovate.json index b48fc6dc..deb428af 100644 --- a/renovate.json +++ b/renovate.json @@ -13,8 +13,8 @@ "enabled": true }, "labels": [ - "dependencies", - "github_actions" + "Dependencies", + "Dependencies/Renovate" ], "ignoreDeps": [ "tikv-jemallocator", From dd22325ea2676c30f784c989e025e0391dbe911c Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Mon, 18 Aug 2025 20:45:30 +0100 Subject: [PATCH 2235/2291] refactor(ci): Consolidate Rust checks with optimised toolchain setup Merge rust-checks.yml into prek-checks.yml for a unified workflow that runs formatting and clippy/test checks in parallel jobs. Add reusable composite actions: - setup-rust: Smart Rust toolchain management with caching * Uses cargo-binstall for pre-built binary downloads * Integrates Mozilla sccache-action for compilation caching * Workspace-relative paths for better cache control * GitHub token support for improved rate limits - setup-llvm-with-apt: LLVM installation with native dependencies - detect-runner-os: Consistent OS detection for cache keys Key improvements: - Install prek via cargo-binstall --git (crates.io outdated at v0.0.1) - Download timelord-cli from cargo-quickinstall - Set BINSTALL_MAXIMUM_RESOLUTION_TIMEOUT=10 to avoid rate limit delays - Default Rust version 1.87.0 with override support - Remove redundant sccache stats (handled by Mozilla action) Significantly reduces CI runtime through binary downloads instead of compilation while maintaining all existing quality checks. --- .forgejo/actions/detect-runner-os/action.yml | 39 +++ .../actions/setup-llvm-with-apt/action.yml | 167 +++++++++++++ .forgejo/actions/setup-rust/action.yml | 236 ++++++++++++++++++ .forgejo/workflows/prek-checks.yml | 59 ++++- .forgejo/workflows/rust-checks.yml | 144 ----------- 5 files changed, 494 insertions(+), 151 deletions(-) create mode 100644 .forgejo/actions/detect-runner-os/action.yml create mode 100644 .forgejo/actions/setup-llvm-with-apt/action.yml create mode 100644 .forgejo/actions/setup-rust/action.yml delete mode 100644 .forgejo/workflows/rust-checks.yml diff --git a/.forgejo/actions/detect-runner-os/action.yml b/.forgejo/actions/detect-runner-os/action.yml new file mode 100644 index 00000000..6ada1d5d --- /dev/null +++ b/.forgejo/actions/detect-runner-os/action.yml @@ -0,0 +1,39 @@ +name: detect-runner-os +description: | + Detect the actual OS name and version of the runner. + Provides separate outputs for name, version, and a combined slug. + +outputs: + name: + description: 'OS name (e.g. Ubuntu, Debian)' + value: ${{ steps.detect.outputs.name }} + version: + description: 'OS version (e.g. 22.04, 11)' + value: ${{ steps.detect.outputs.version }} + slug: + description: 'Combined OS slug (e.g. Ubuntu-22.04)' + value: ${{ steps.detect.outputs.slug }} + +runs: + using: composite + steps: + - name: Detect runner OS + id: detect + shell: bash + run: | + # Detect OS version (try lsb_release first, fall back to /etc/os-release) + OS_VERSION=$(lsb_release -rs 2>/dev/null || grep VERSION_ID /etc/os-release | cut -d'"' -f2) + + # Detect OS name and capitalise (try lsb_release first, fall back to /etc/os-release) + OS_NAME=$(lsb_release -is 2>/dev/null || grep "^ID=" /etc/os-release | cut -d'=' -f2 | tr -d '"' | sed 's/\b\(.\)/\u\1/g') + + # Create combined slug + OS_SLUG="${OS_NAME}-${OS_VERSION}" + + # Set outputs + echo "name=${OS_NAME}" >> $GITHUB_OUTPUT + echo "version=${OS_VERSION}" >> $GITHUB_OUTPUT + echo "slug=${OS_SLUG}" >> $GITHUB_OUTPUT + + # Log detection results + echo "🔍 Detected Runner OS: ${OS_NAME} ${OS_VERSION}" diff --git a/.forgejo/actions/setup-llvm-with-apt/action.yml b/.forgejo/actions/setup-llvm-with-apt/action.yml new file mode 100644 index 00000000..eb421e4f --- /dev/null +++ b/.forgejo/actions/setup-llvm-with-apt/action.yml @@ -0,0 +1,167 @@ +name: setup-llvm-with-apt +description: | + Set up LLVM toolchain with APT package management and smart caching. + Supports cross-compilation architectures and additional package installation. + + Creates symlinks in /usr/bin: clang, clang++, lld, llvm-ar, llvm-ranlib + +inputs: + dpkg-arch: + description: 'Debian architecture for cross-compilation (e.g. arm64)' + required: false + default: '' + extra-packages: + description: 'Additional APT packages to install (space-separated)' + required: false + default: '' + llvm-version: + description: 'LLVM version to install' + required: false + default: '20' + +outputs: + llvm-version: + description: 'Installed LLVM version' + value: ${{ steps.configure.outputs.version }} + +runs: + using: composite + steps: + - name: Detect runner OS + id: runner-os + uses: ./.forgejo/actions/detect-runner-os + + - name: Configure cross-compilation architecture + if: inputs.dpkg-arch != '' + shell: bash + run: | + echo "🏗️ Adding ${{ inputs.dpkg-arch }} architecture" + sudo dpkg --add-architecture ${{ inputs.dpkg-arch }} + + # Restrict default sources to amd64 + sudo sed -i 's/^deb http/deb [arch=amd64] http/g' /etc/apt/sources.list + sudo sed -i 's/^deb https/deb [arch=amd64] https/g' /etc/apt/sources.list + + # Add ports sources for foreign architecture + sudo tee /etc/apt/sources.list.d/${{ inputs.dpkg-arch }}.list > /dev/null <> $GITHUB_OUTPUT + else + echo "📦 LLVM ${{ inputs.llvm-version }} not found or incomplete - installing..." + + echo "::group::🔧 Installing LLVM ${{ inputs.llvm-version }}" + wget -O - https://apt.llvm.org/llvm.sh | bash -s -- ${{ inputs.llvm-version }} + echo "::endgroup::" + + if [ ! -f "/usr/bin/clang-${{ inputs.llvm-version }}" ]; then + echo "❌ Failed to install LLVM ${{ inputs.llvm-version }}" + exit 1 + fi + + echo "✅ Installed LLVM ${{ inputs.llvm-version }}" + echo "needs-install=true" >> $GITHUB_OUTPUT + fi + + - name: Prepare for additional packages + if: inputs.extra-packages != '' + shell: bash + run: | + # Update APT if LLVM was cached (installer script already does apt-get update) + if [[ "${{ steps.llvm-setup.outputs.needs-install }}" != "true" ]]; then + echo "::group::📦 Running apt-get update (LLVM cached, extra packages needed)" + sudo apt-get update + echo "::endgroup::" + fi + echo "::group::📦 Installing additional packages" + + - name: Install additional packages + if: inputs.extra-packages != '' + uses: https://github.com/awalsh128/cache-apt-pkgs-action@latest + with: + packages: ${{ inputs.extra-packages }} + version: 1.0 + + - name: End package installation group + if: inputs.extra-packages != '' + shell: bash + run: echo "::endgroup::" + + - name: Configure LLVM environment + id: configure + shell: bash + run: | + echo "::group::🔧 Configuring LLVM ${{ inputs.llvm-version }} environment" + + # Create symlinks + sudo ln -sf "/usr/bin/clang-${{ inputs.llvm-version }}" /usr/bin/clang + sudo ln -sf "/usr/bin/clang++-${{ inputs.llvm-version }}" /usr/bin/clang++ + sudo ln -sf "/usr/bin/lld-${{ inputs.llvm-version }}" /usr/bin/lld + sudo ln -sf "/usr/bin/llvm-ar-${{ inputs.llvm-version }}" /usr/bin/llvm-ar + sudo ln -sf "/usr/bin/llvm-ranlib-${{ inputs.llvm-version }}" /usr/bin/llvm-ranlib + echo " ✓ Created symlinks" + + # Setup library paths + LLVM_LIB_PATH="/usr/lib/llvm-${{ inputs.llvm-version }}/lib" + if [ -d "$LLVM_LIB_PATH" ]; then + echo "LD_LIBRARY_PATH=${LLVM_LIB_PATH}:${LD_LIBRARY_PATH:-}" >> $GITHUB_ENV + echo "LIBCLANG_PATH=${LLVM_LIB_PATH}" >> $GITHUB_ENV + + echo "$LLVM_LIB_PATH" | sudo tee "/etc/ld.so.conf.d/llvm-${{ inputs.llvm-version }}.conf" > /dev/null + sudo ldconfig + echo " ✓ Configured library paths" + else + # Fallback to standard library location + if [ -d "/usr/lib/x86_64-linux-gnu" ]; then + echo "LIBCLANG_PATH=/usr/lib/x86_64-linux-gnu" >> $GITHUB_ENV + echo " ✓ Using fallback library path" + fi + fi + + # Set output + echo "version=${{ inputs.llvm-version }}" >> $GITHUB_OUTPUT + echo "::endgroup::" + echo "✅ LLVM ready: $(clang --version | head -1)" diff --git a/.forgejo/actions/setup-rust/action.yml b/.forgejo/actions/setup-rust/action.yml new file mode 100644 index 00000000..091da8c2 --- /dev/null +++ b/.forgejo/actions/setup-rust/action.yml @@ -0,0 +1,236 @@ +name: setup-rust +description: | + Set up Rust toolchain with sccache for compilation caching. + Respects rust-toolchain.toml by default or accepts explicit version override. + +inputs: + cache-key-suffix: + description: 'Optional suffix for cache keys (e.g. platform identifier)' + required: false + default: '' + rust-components: + description: 'Additional Rust components to install (space-separated)' + required: false + default: '' + rust-target: + description: 'Rust target triple (e.g. x86_64-unknown-linux-gnu)' + required: false + default: '' + rust-version: + description: 'Rust version to install (e.g. nightly). Defaults to 1.87.0' + required: false + default: '1.87.0' + sccache-cache-limit: + description: 'Maximum size limit for sccache local cache (e.g. 2G, 500M)' + required: false + default: '2G' + github-token: + description: 'GitHub token for downloading sccache from GitHub releases' + required: false + default: '' + +outputs: + rust-version: + description: 'Installed Rust version' + value: ${{ steps.rust-setup.outputs.version }} + +runs: + using: composite + steps: + - name: Detect runner OS + id: runner-os + uses: ./.forgejo/actions/detect-runner-os + + - name: Configure Cargo environment + shell: bash + run: | + # Use workspace-relative paths for better control and consistency + echo "CARGO_HOME=${{ github.workspace }}/.cargo" >> $GITHUB_ENV + echo "CARGO_TARGET_DIR=${{ github.workspace }}/target" >> $GITHUB_ENV + echo "SCCACHE_DIR=${{ github.workspace }}/.sccache" >> $GITHUB_ENV + echo "RUSTUP_HOME=${{ github.workspace }}/.rustup" >> $GITHUB_ENV + + # Limit binstall resolution timeout to avoid GitHub rate limit delays + echo "BINSTALL_MAXIMUM_RESOLUTION_TIMEOUT=10" >> $GITHUB_ENV + + # Ensure directories exist for first run + mkdir -p "${{ github.workspace }}/.cargo" + mkdir -p "${{ github.workspace }}/.sccache" + mkdir -p "${{ github.workspace }}/target" + mkdir -p "${{ github.workspace }}/.rustup" + + - name: Start cache restore group + shell: bash + run: echo "::group::📦 Restoring caches (registry, toolchain, build artifacts)" + + - name: Cache Cargo registry and git + id: registry-cache + uses: https://github.com/actions/cache@v4 + with: + path: | + .cargo/registry/index + .cargo/registry/cache + .cargo/git/db + # Registry cache saved per workflow, restored from any workflow's cache + # Each workflow maintains its own registry that accumulates its needed crates + key: cargo-registry-${{ steps.runner-os.outputs.slug }}-${{ github.workflow }} + restore-keys: | + cargo-registry-${{ steps.runner-os.outputs.slug }}- + + - name: Cache toolchain binaries + id: toolchain-cache + uses: https://github.com/actions/cache@v4 + with: + path: | + .cargo/bin + .rustup/toolchains + .rustup/update-hashes + # Shared toolchain cache across all Rust versions + key: toolchain-${{ steps.runner-os.outputs.slug }} + + - name: Debug GitHub token availability + shell: bash + run: | + if [ -z "${{ inputs.github-token }}" ]; then + echo "⚠️ No GitHub token provided - sccache will use fallback download method" + else + echo "✅ GitHub token provided for sccache" + fi + + - name: Setup sccache + uses: https://github.com/mozilla-actions/sccache-action@v0.0.9 + with: + token: ${{ inputs.github-token }} + + - name: Cache build artifacts + id: build-cache + uses: https://github.com/actions/cache@v4 + with: + path: | + target/**/deps + !target/**/deps/*.rlib + target/**/build + target/**/.fingerprint + target/**/incremental + target/**/*.d + /timelord/ + # Build artifacts - cache per code change, restore from deps when code changes + key: >- + build-${{ steps.runner-os.outputs.slug }}-${{ inputs.rust-version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}-${{ hashFiles('**/*.rs', '**/Cargo.toml') }} + restore-keys: | + build-${{ steps.runner-os.outputs.slug }}-${{ inputs.rust-version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}- + + - name: End cache restore group + shell: bash + run: echo "::endgroup::" + + - name: Setup Rust toolchain + shell: bash + run: | + # Install rustup if not already cached + if ! command -v rustup &> /dev/null; then + echo "::group::📦 Installing rustup" + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain none + source "$CARGO_HOME/env" + echo "::endgroup::" + else + echo "✅ rustup already available" + fi + + # Setup the appropriate Rust version + if [[ -n "${{ inputs.rust-version }}" ]]; then + echo "::group::📦 Setting up Rust ${{ inputs.rust-version }}" + # Set override first to prevent rust-toolchain.toml from auto-installing + rustup override set ${{ inputs.rust-version }} 2>/dev/null || true + + # Check if we need to install/update the toolchain + if rustup toolchain list | grep -q "^${{ inputs.rust-version }}-"; then + rustup update ${{ inputs.rust-version }} + else + rustup toolchain install ${{ inputs.rust-version }} --profile minimal -c cargo,clippy,rustfmt + fi + else + echo "::group::📦 Setting up Rust from rust-toolchain.toml" + rustup show + fi + echo "::endgroup::" + + - name: Configure PATH and install tools + shell: bash + env: + GITHUB_TOKEN: ${{ inputs.github-token }} + run: | + # Add .cargo/bin to PATH permanently for all subsequent steps + echo "${{ github.workspace }}/.cargo/bin" >> $GITHUB_PATH + + # For this step only, we need to add it to PATH since GITHUB_PATH takes effect in the next step + export PATH="${{ github.workspace }}/.cargo/bin:$PATH" + + # Install cargo-binstall for fast binary installations + if command -v cargo-binstall &> /dev/null; then + echo "✅ cargo-binstall already available" + else + echo "::group::📦 Installing cargo-binstall" + curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash + echo "::endgroup::" + fi + + if command -v prek &> /dev/null; then + echo "✅ prek already available" + else + echo "::group::📦 Installing prek" + # prek isn't regularly published to crates.io, so we use git source + cargo-binstall -y --no-symlinks --git https://github.com/j178/prek prek + echo "::endgroup::" + fi + + if command -v timelord &> /dev/null; then + echo "✅ timelord already available" + else + echo "::group::📦 Installing timelord" + cargo-binstall -y --no-symlinks timelord-cli + echo "::endgroup::" + fi + + - name: Configure sccache environment + shell: bash + run: | + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "CMAKE_C_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV + echo "CMAKE_CXX_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV + echo "CMAKE_CUDA_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + + # Configure incremental compilation GC + # If we restored from old cache (partial hit), clean up aggressively + if [[ "${{ steps.build-cache.outputs.cache-hit }}" != "true" ]]; then + echo "♻️ Partial cache hit - enabling cache cleanup" + echo "CARGO_INCREMENTAL_GC_THRESHOLD=5" >> $GITHUB_ENV + fi + + - name: Install Rust components + if: inputs.rust-components != '' + shell: bash + run: | + echo "📦 Installing components: ${{ inputs.rust-components }}" + rustup component add ${{ inputs.rust-components }} + + - name: Install Rust target + if: inputs.rust-target != '' + shell: bash + run: | + echo "📦 Installing target: ${{ inputs.rust-target }}" + rustup target add ${{ inputs.rust-target }} + + - name: Output version and summary + id: rust-setup + shell: bash + run: | + RUST_VERSION=$(rustc --version | cut -d' ' -f2) + echo "version=$RUST_VERSION" >> $GITHUB_OUTPUT + + echo "📋 Setup complete:" + echo " Rust: $(rustc --version)" + echo " Cargo: $(cargo --version)" + echo " prek: $(prek --version 2>/dev/null || echo 'installed')" + echo " timelord: $(timelord --version 2>/dev/null || echo 'installed')" diff --git a/.forgejo/workflows/prek-checks.yml b/.forgejo/workflows/prek-checks.yml index ac330ca2..c25b9c3d 100644 --- a/.forgejo/workflows/prek-checks.yml +++ b/.forgejo/workflows/prek-checks.yml @@ -2,7 +2,6 @@ name: Checks / Prek on: push: - pull_request: permissions: contents: read @@ -17,18 +16,64 @@ jobs: with: persist-credentials: false - - name: Install uv - uses: https://github.com/astral-sh/setup-uv@v5 + - name: Setup Rust nightly + uses: ./.forgejo/actions/setup-rust with: - enable-cache: true - ignore-nothing-to-cache: true - cache-dependency-glob: '' + rust-version: nightly + github-token: ${{ secrets.GH_PUBLIC_RO }} - name: Run prek run: | - uvx prek run \ + prek run \ --all-files \ --hook-stage manual \ --show-diff-on-failure \ --color=always \ -v + + - name: Check Rust formatting + run: | + cargo +nightly fmt --all -- --check && \ + echo "✅ Formatting check passed" || \ + exit 1 + + clippy-and-tests: + name: Clippy and Cargo Tests + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup LLVM + uses: ./.forgejo/actions/setup-llvm-with-apt + with: + extra-packages: liburing-dev liburing2 + + - name: Setup Rust with caching + uses: ./.forgejo/actions/setup-rust + with: + github-token: ${{ secrets.GH_PUBLIC_RO }} + + - name: Run Clippy lints + run: | + cargo clippy \ + --workspace \ + --features full \ + --locked \ + --no-deps \ + --profile test \ + -- \ + -D warnings + + - name: Run Cargo tests + run: | + cargo test \ + --workspace \ + --features full \ + --locked \ + --profile test \ + --all-targets \ + --no-fail-fast diff --git a/.forgejo/workflows/rust-checks.yml b/.forgejo/workflows/rust-checks.yml deleted file mode 100644 index c46363a0..00000000 --- a/.forgejo/workflows/rust-checks.yml +++ /dev/null @@ -1,144 +0,0 @@ -name: Checks / Rust - -on: - push: - -jobs: - format: - name: Format - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install rust - uses: ./.forgejo/actions/rust-toolchain - with: - toolchain: "nightly" - components: "rustfmt" - - - name: Check formatting - run: | - cargo +nightly fmt --all -- --check - - clippy: - name: Clippy - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install rust - uses: ./.forgejo/actions/rust-toolchain - - - uses: https://github.com/actions/create-github-app-token@v2 - id: app-token - with: - app-id: ${{ vars.GH_APP_ID }} - private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} - github-api-url: https://api.github.com - owner: ${{ vars.GH_APP_OWNER }} - repositories: "" - - name: Install sccache - uses: ./.forgejo/actions/sccache - with: - token: ${{ steps.app-token.outputs.token }} - - run: sudo apt-get update - - name: Install system dependencies - uses: https://github.com/awalsh128/cache-apt-pkgs-action@v1 - with: - packages: clang liburing-dev - version: 1 - - name: Cache Rust registry - uses: actions/cache@v3 - with: - path: | - ~/.cargo/git - !~/.cargo/git/checkouts - ~/.cargo/registry - !~/.cargo/registry/src - key: rust-registry-${{hashFiles('**/Cargo.lock') }} - - name: Timelord - uses: ./.forgejo/actions/timelord - with: - key: sccache-v0 - path: . - - name: Clippy - run: | - cargo clippy \ - --workspace \ - --features full \ - --locked \ - --no-deps \ - --profile test \ - -- \ - -D warnings - - - name: Show sccache stats - if: always() - run: sccache --show-stats - - cargo-test: - name: Cargo Test - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install rust - uses: ./.forgejo/actions/rust-toolchain - - - uses: https://github.com/actions/create-github-app-token@v2 - id: app-token - with: - app-id: ${{ vars.GH_APP_ID }} - private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} - github-api-url: https://api.github.com - owner: ${{ vars.GH_APP_OWNER }} - repositories: "" - - name: Install sccache - uses: ./.forgejo/actions/sccache - with: - token: ${{ steps.app-token.outputs.token }} - - run: sudo apt-get update - - name: Install system dependencies - uses: https://github.com/awalsh128/cache-apt-pkgs-action@v1 - with: - packages: clang liburing-dev - version: 1 - - name: Cache Rust registry - uses: actions/cache@v3 - with: - path: | - ~/.cargo/git - !~/.cargo/git/checkouts - ~/.cargo/registry - !~/.cargo/registry/src - key: rust-registry-${{hashFiles('**/Cargo.lock') }} - - name: Timelord - uses: ./.forgejo/actions/timelord - with: - key: sccache-v0 - path: . - - name: Cargo Test - run: | - cargo test \ - --workspace \ - --features full \ - --locked \ - --profile test \ - --all-targets \ - --no-fail-fast - - - name: Show sccache stats - if: always() - run: sccache --show-stats From 37248a4f6821c9271fd51e5ddc3b744d51fde969 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 28 Aug 2025 20:10:05 +0100 Subject: [PATCH 2236/2291] chore: Add reasons for test skips --- src/database/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/tests.rs b/src/database/tests.rs index c1a9f47c..30562a66 100644 --- a/src/database/tests.rs +++ b/src/database/tests.rs @@ -326,7 +326,7 @@ fn ser_array() { } #[test] -#[ignore] +#[ignore = "arrayvec deserialization is not implemented (separators)"] fn de_array() { let a: u64 = 123_456; let b: u64 = 987_654; @@ -358,7 +358,7 @@ fn de_array() { } #[test] -#[ignore] +#[ignore = "Nested sequences are not supported"] fn de_complex() { type Key<'a> = (&'a UserId, ArrayVec, &'a RoomId); From b5a2e49ae4b1b9b17f5966a8fbbfaf67a6ee7b26 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Thu, 28 Aug 2025 20:35:27 +0100 Subject: [PATCH 2237/2291] fix: Resolve Clippy CI failures from elided lifetime warnings The latest Rust nightly compiler (2025-08-27) introduced the elided-named-lifetimes lint which causes Clippy CI checks to fail when an elided lifetime ('_) resolves to a named lifetime that's already in scope. This commit fixes the Clippy warnings by: - Making lifetime relationships explicit where 'a is already in scope - Keeping elided lifetimes ('_) in functions without explicit lifetime parameters - Ensuring proper lifetime handling in the database pool module Affected files (17 total): - Database map modules: Handle, Key, and KeyVal references in get, qry, keys, and stream operations - Database pool module: into_recv_seek function This change resolves the CI build failures without changing any functionality, ensuring the codebase remains compatible with the latest nightly Clippy checks. --- src/database/map/get_batch.rs | 6 +++--- src/database/map/keys.rs | 2 +- src/database/map/keys_from.rs | 4 ++-- src/database/map/keys_prefix.rs | 6 +++--- src/database/map/qry_batch.rs | 6 +++--- src/database/map/rev_keys.rs | 2 +- src/database/map/rev_keys_from.rs | 4 ++-- src/database/map/rev_keys_prefix.rs | 6 +++--- src/database/map/rev_stream.rs | 2 +- src/database/map/rev_stream_from.rs | 4 ++-- src/database/map/rev_stream_prefix.rs | 6 +++--- src/database/map/stream.rs | 2 +- src/database/map/stream_from.rs | 4 ++-- src/database/map/stream_prefix.rs | 6 +++--- src/database/pool.rs | 2 +- src/service/migrations.rs | 8 ++++---- src/service/presence/mod.rs | 4 ++-- src/service/pusher/mod.rs | 2 +- src/service/rooms/alias/mod.rs | 6 ++++-- src/service/rooms/pdu_metadata/data.rs | 2 +- src/service/rooms/read_receipt/data.rs | 2 +- src/service/rooms/read_receipt/mod.rs | 2 +- src/service/rooms/search/mod.rs | 20 ++++++++++---------- src/service/rooms/short/mod.rs | 2 +- src/service/rooms/state/mod.rs | 2 +- src/service/rooms/state_cache/mod.rs | 20 ++++++++++---------- src/service/rooms/state_cache/via.rs | 2 +- src/service/users/mod.rs | 8 ++++---- 28 files changed, 72 insertions(+), 70 deletions(-) diff --git a/src/database/map/get_batch.rs b/src/database/map/get_batch.rs index e23a8848..539f0c39 100644 --- a/src/database/map/get_batch.rs +++ b/src/database/map/get_batch.rs @@ -19,7 +19,7 @@ where S: Stream + Send + 'a, K: AsRef<[u8]> + Send + Sync + 'a, { - fn get(self, map: &'a Arc) -> impl Stream>> + Send + 'a; + fn get(self, map: &'a Arc) -> impl Stream>> + Send + 'a; } impl<'a, K, S> Get<'a, K, S> for S @@ -29,7 +29,7 @@ where K: AsRef<[u8]> + Send + Sync + 'a, { #[inline] - fn get(self, map: &'a Arc) -> impl Stream>> + Send + 'a { + fn get(self, map: &'a Arc) -> impl Stream>> + Send + 'a { map.get_batch(self) } } @@ -39,7 +39,7 @@ where pub(crate) fn get_batch<'a, S, K>( self: &'a Arc, keys: S, -) -> impl Stream>> + Send + 'a +) -> impl Stream>> + Send + 'a where S: Stream + Send + 'a, K: AsRef<[u8]> + Send + Sync + 'a, diff --git a/src/database/map/keys.rs b/src/database/map/keys.rs index 7ca932a5..ac044e91 100644 --- a/src/database/map/keys.rs +++ b/src/database/map/keys.rs @@ -10,7 +10,7 @@ use super::stream::is_cached; use crate::{keyval, keyval::Key, stream}; #[implement(super::Map)] -pub fn keys<'a, K>(self: &'a Arc) -> impl Stream>> + Send +pub fn keys<'a, K>(self: &'a Arc) -> impl Stream>> + Send where K: Deserialize<'a> + Send, { diff --git a/src/database/map/keys_from.rs b/src/database/map/keys_from.rs index c9b1717a..11245f7b 100644 --- a/src/database/map/keys_from.rs +++ b/src/database/map/keys_from.rs @@ -15,7 +15,7 @@ use crate::{ pub fn keys_from<'a, K, P>( self: &'a Arc, from: &P, -) -> impl Stream>> + Send + use<'a, K, P> +) -> impl Stream>> + Send + use<'a, K, P> where P: Serialize + ?Sized + Debug, K: Deserialize<'a> + Send, @@ -40,7 +40,7 @@ where pub fn keys_raw_from<'a, K, P>( self: &'a Arc, from: &P, -) -> impl Stream>> + Send + use<'a, K, P> +) -> impl Stream>> + Send + use<'a, K, P> where P: AsRef<[u8]> + ?Sized + Debug + Sync, K: Deserialize<'a> + Send, diff --git a/src/database/map/keys_prefix.rs b/src/database/map/keys_prefix.rs index 09dd79ac..e6a9457f 100644 --- a/src/database/map/keys_prefix.rs +++ b/src/database/map/keys_prefix.rs @@ -10,7 +10,7 @@ use crate::keyval::{Key, result_deserialize_key, serialize_key}; pub fn keys_prefix<'a, K, P>( self: &'a Arc, prefix: &P, -) -> impl Stream>> + Send + use<'a, K, P> +) -> impl Stream>> + Send + use<'a, K, P> where P: Serialize + ?Sized + Debug, K: Deserialize<'a> + Send, @@ -37,7 +37,7 @@ where pub fn keys_raw_prefix<'a, K, P>( self: &'a Arc, prefix: &'a P, -) -> impl Stream>> + Send + 'a +) -> impl Stream>> + Send + 'a where P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a, K: Deserialize<'a> + Send + 'a, @@ -50,7 +50,7 @@ where pub fn raw_keys_prefix<'a, P>( self: &'a Arc, prefix: &'a P, -) -> impl Stream>> + Send + 'a +) -> impl Stream>> + Send + 'a where P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a, { diff --git a/src/database/map/qry_batch.rs b/src/database/map/qry_batch.rs index e42d3e63..9da546e6 100644 --- a/src/database/map/qry_batch.rs +++ b/src/database/map/qry_batch.rs @@ -17,7 +17,7 @@ where S: Stream + Send + 'a, K: Serialize + Debug, { - fn qry(self, map: &'a Arc) -> impl Stream>> + Send + 'a; + fn qry(self, map: &'a Arc) -> impl Stream>> + Send + 'a; } impl<'a, K, S> Qry<'a, K, S> for S @@ -27,7 +27,7 @@ where K: Serialize + Debug + 'a, { #[inline] - fn qry(self, map: &'a Arc) -> impl Stream>> + Send + 'a { + fn qry(self, map: &'a Arc) -> impl Stream>> + Send + 'a { map.qry_batch(self) } } @@ -37,7 +37,7 @@ where pub(crate) fn qry_batch<'a, S, K>( self: &'a Arc, keys: S, -) -> impl Stream>> + Send + 'a +) -> impl Stream>> + Send + 'a where S: Stream + Send + 'a, K: Serialize + Debug + 'a, diff --git a/src/database/map/rev_keys.rs b/src/database/map/rev_keys.rs index c00f3e55..8f48a17e 100644 --- a/src/database/map/rev_keys.rs +++ b/src/database/map/rev_keys.rs @@ -10,7 +10,7 @@ use super::rev_stream::is_cached; use crate::{keyval, keyval::Key, stream}; #[implement(super::Map)] -pub fn rev_keys<'a, K>(self: &'a Arc) -> impl Stream>> + Send +pub fn rev_keys<'a, K>(self: &'a Arc) -> impl Stream>> + Send where K: Deserialize<'a> + Send, { diff --git a/src/database/map/rev_keys_from.rs b/src/database/map/rev_keys_from.rs index 04e457dc..021e3b92 100644 --- a/src/database/map/rev_keys_from.rs +++ b/src/database/map/rev_keys_from.rs @@ -15,7 +15,7 @@ use crate::{ pub fn rev_keys_from<'a, K, P>( self: &'a Arc, from: &P, -) -> impl Stream>> + Send + use<'a, K, P> +) -> impl Stream>> + Send + use<'a, K, P> where P: Serialize + ?Sized + Debug, K: Deserialize<'a> + Send, @@ -41,7 +41,7 @@ where pub fn rev_keys_raw_from<'a, K, P>( self: &'a Arc, from: &P, -) -> impl Stream>> + Send + use<'a, K, P> +) -> impl Stream>> + Send + use<'a, K, P> where P: AsRef<[u8]> + ?Sized + Debug + Sync, K: Deserialize<'a> + Send, diff --git a/src/database/map/rev_keys_prefix.rs b/src/database/map/rev_keys_prefix.rs index fbe9f9ca..5b1459f5 100644 --- a/src/database/map/rev_keys_prefix.rs +++ b/src/database/map/rev_keys_prefix.rs @@ -10,7 +10,7 @@ use crate::keyval::{Key, result_deserialize_key, serialize_key}; pub fn rev_keys_prefix<'a, K, P>( self: &'a Arc, prefix: &P, -) -> impl Stream>> + Send + use<'a, K, P> +) -> impl Stream>> + Send + use<'a, K, P> where P: Serialize + ?Sized + Debug, K: Deserialize<'a> + Send, @@ -37,7 +37,7 @@ where pub fn rev_keys_raw_prefix<'a, K, P>( self: &'a Arc, prefix: &'a P, -) -> impl Stream>> + Send + 'a +) -> impl Stream>> + Send + 'a where P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a, K: Deserialize<'a> + Send + 'a, @@ -50,7 +50,7 @@ where pub fn rev_raw_keys_prefix<'a, P>( self: &'a Arc, prefix: &'a P, -) -> impl Stream>> + Send + 'a +) -> impl Stream>> + Send + 'a where P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a, { diff --git a/src/database/map/rev_stream.rs b/src/database/map/rev_stream.rs index 789a52e8..92d7bac8 100644 --- a/src/database/map/rev_stream.rs +++ b/src/database/map/rev_stream.rs @@ -14,7 +14,7 @@ use crate::{keyval, keyval::KeyVal, stream}; #[implement(super::Map)] pub fn rev_stream<'a, K, V>( self: &'a Arc, -) -> impl Stream>> + Send +) -> impl Stream>> + Send where K: Deserialize<'a> + Send, V: Deserialize<'a> + Send, diff --git a/src/database/map/rev_stream_from.rs b/src/database/map/rev_stream_from.rs index a612d2a2..7fef1b35 100644 --- a/src/database/map/rev_stream_from.rs +++ b/src/database/map/rev_stream_from.rs @@ -20,7 +20,7 @@ use crate::{ pub fn rev_stream_from<'a, K, V, P>( self: &'a Arc, from: &P, -) -> impl Stream>> + Send + use<'a, K, V, P> +) -> impl Stream>> + Send + use<'a, K, V, P> where P: Serialize + ?Sized + Debug, K: Deserialize<'a> + Send, @@ -55,7 +55,7 @@ where pub fn rev_stream_raw_from<'a, K, V, P>( self: &'a Arc, from: &P, -) -> impl Stream>> + Send + use<'a, K, V, P> +) -> impl Stream>> + Send + use<'a, K, V, P> where P: AsRef<[u8]> + ?Sized + Debug + Sync, K: Deserialize<'a> + Send, diff --git a/src/database/map/rev_stream_prefix.rs b/src/database/map/rev_stream_prefix.rs index 46dc9247..70d4abf7 100644 --- a/src/database/map/rev_stream_prefix.rs +++ b/src/database/map/rev_stream_prefix.rs @@ -14,7 +14,7 @@ use crate::keyval::{KeyVal, result_deserialize, serialize_key}; pub fn rev_stream_prefix<'a, K, V, P>( self: &'a Arc, prefix: &P, -) -> impl Stream>> + Send + use<'a, K, V, P> +) -> impl Stream>> + Send + use<'a, K, V, P> where P: Serialize + ?Sized + Debug, K: Deserialize<'a> + Send, @@ -50,7 +50,7 @@ where pub fn rev_stream_raw_prefix<'a, K, V, P>( self: &'a Arc, prefix: &'a P, -) -> impl Stream>> + Send + 'a +) -> impl Stream>> + Send + 'a where P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a, K: Deserialize<'a> + Send + 'a, @@ -68,7 +68,7 @@ where pub fn rev_raw_stream_prefix<'a, P>( self: &'a Arc, prefix: &'a P, -) -> impl Stream>> + Send + 'a +) -> impl Stream>> + Send + 'a where P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a, { diff --git a/src/database/map/stream.rs b/src/database/map/stream.rs index f7371b6c..736ab268 100644 --- a/src/database/map/stream.rs +++ b/src/database/map/stream.rs @@ -14,7 +14,7 @@ use crate::{keyval, keyval::KeyVal, stream}; #[implement(super::Map)] pub fn stream<'a, K, V>( self: &'a Arc, -) -> impl Stream>> + Send +) -> impl Stream>> + Send where K: Deserialize<'a> + Send, V: Deserialize<'a> + Send, diff --git a/src/database/map/stream_from.rs b/src/database/map/stream_from.rs index ccf48db6..9acec173 100644 --- a/src/database/map/stream_from.rs +++ b/src/database/map/stream_from.rs @@ -19,7 +19,7 @@ use crate::{ pub fn stream_from<'a, K, V, P>( self: &'a Arc, from: &P, -) -> impl Stream>> + Send + use<'a, K, V, P> +) -> impl Stream>> + Send + use<'a, K, V, P> where P: Serialize + ?Sized + Debug, K: Deserialize<'a> + Send, @@ -53,7 +53,7 @@ where pub fn stream_raw_from<'a, K, V, P>( self: &'a Arc, from: &P, -) -> impl Stream>> + Send + use<'a, K, V, P> +) -> impl Stream>> + Send + use<'a, K, V, P> where P: AsRef<[u8]> + ?Sized + Debug + Sync, K: Deserialize<'a> + Send, diff --git a/src/database/map/stream_prefix.rs b/src/database/map/stream_prefix.rs index a26478aa..8210e152 100644 --- a/src/database/map/stream_prefix.rs +++ b/src/database/map/stream_prefix.rs @@ -14,7 +14,7 @@ use crate::keyval::{KeyVal, result_deserialize, serialize_key}; pub fn stream_prefix<'a, K, V, P>( self: &'a Arc, prefix: &P, -) -> impl Stream>> + Send + use<'a, K, V, P> +) -> impl Stream>> + Send + use<'a, K, V, P> where P: Serialize + ?Sized + Debug, K: Deserialize<'a> + Send, @@ -50,7 +50,7 @@ where pub fn stream_raw_prefix<'a, K, V, P>( self: &'a Arc, prefix: &'a P, -) -> impl Stream>> + Send + 'a +) -> impl Stream>> + Send + 'a where P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a, K: Deserialize<'a> + Send + 'a, @@ -68,7 +68,7 @@ where pub fn raw_stream_prefix<'a, P>( self: &'a Arc, prefix: &'a P, -) -> impl Stream>> + Send + 'a +) -> impl Stream>> + Send + 'a where P: AsRef<[u8]> + ?Sized + Debug + Sync + 'a, { diff --git a/src/database/pool.rs b/src/database/pool.rs index 285aaf25..3421f779 100644 --- a/src/database/pool.rs +++ b/src/database/pool.rs @@ -443,7 +443,7 @@ pub(crate) fn into_send_seek(result: stream::State<'_>) -> stream::State<'static unsafe { std::mem::transmute(result) } } -fn into_recv_seek(result: stream::State<'static>) -> stream::State<'_> { +fn into_recv_seek(result: stream::State<'static>) -> stream::State<'static> { // SAFETY: This is to receive the State from the channel; see above. unsafe { std::mem::transmute(result) } } diff --git a/src/service/migrations.rs b/src/service/migrations.rs index cee638ba..586d6249 100644 --- a/src/service/migrations.rs +++ b/src/service/migrations.rs @@ -215,8 +215,8 @@ async fn db_lt_12(services: &Services) -> Result<()> { for username in &services .users .list_local_users() - .map(UserId::to_owned) - .collect::>() + .map(ToOwned::to_owned) + .collect::>() .await { let user = match UserId::parse_with_server_name(username.as_str(), &services.server.name) @@ -295,8 +295,8 @@ async fn db_lt_13(services: &Services) -> Result<()> { for username in &services .users .list_local_users() - .map(UserId::to_owned) - .collect::>() + .map(ToOwned::to_owned) + .collect::>() .await { let user = match UserId::parse_with_server_name(username.as_str(), &services.server.name) diff --git a/src/service/presence/mod.rs b/src/service/presence/mod.rs index 8f646be6..e7ce64bc 100644 --- a/src/service/presence/mod.rs +++ b/src/service/presence/mod.rs @@ -183,8 +183,8 @@ impl Service { .services .users .list_local_users() - .map(UserId::to_owned) - .collect::>() + .map(ToOwned::to_owned) + .collect::>() .await { let presence = self.db.get_presence(user_id).await; diff --git a/src/service/pusher/mod.rs b/src/service/pusher/mod.rs index baa7a72e..071bf822 100644 --- a/src/service/pusher/mod.rs +++ b/src/service/pusher/mod.rs @@ -178,7 +178,7 @@ impl Service { pub fn get_pushkeys<'a>( &'a self, sender: &'a UserId, - ) -> impl Stream + Send + 'a { + ) -> impl Stream + Send + 'a { let prefix = (sender, Interfix); self.db .senderkey_pusher diff --git a/src/service/rooms/alias/mod.rs b/src/service/rooms/alias/mod.rs index 7675efd4..c627092e 100644 --- a/src/service/rooms/alias/mod.rs +++ b/src/service/rooms/alias/mod.rs @@ -178,7 +178,7 @@ impl Service { pub fn local_aliases_for_room<'a>( &'a self, room_id: &'a RoomId, - ) -> impl Stream + Send + 'a { + ) -> impl Stream + Send + 'a { let prefix = (room_id, Interfix); self.db .aliasid_alias @@ -188,7 +188,9 @@ impl Service { } #[tracing::instrument(skip(self), level = "debug")] - pub fn all_local_aliases<'a>(&'a self) -> impl Stream + Send + 'a { + pub fn all_local_aliases<'a>( + &'a self, + ) -> impl Stream + Send + 'a { self.db .alias_roomid .stream() diff --git a/src/service/rooms/pdu_metadata/data.rs b/src/service/rooms/pdu_metadata/data.rs index a746b4cc..854c6ea0 100644 --- a/src/service/rooms/pdu_metadata/data.rs +++ b/src/service/rooms/pdu_metadata/data.rs @@ -60,7 +60,7 @@ impl Data { target: ShortEventId, from: PduCount, dir: Direction, - ) -> impl Stream + Send + '_ { + ) -> impl Stream + Send + 'a { // Query from exact position then filter excludes it (saturating_inc could skip // events at min/max boundaries) let from_unsigned = from.into_unsigned(); diff --git a/src/service/rooms/read_receipt/data.rs b/src/service/rooms/read_receipt/data.rs index 62f87948..9a2fa70c 100644 --- a/src/service/rooms/read_receipt/data.rs +++ b/src/service/rooms/read_receipt/data.rs @@ -65,7 +65,7 @@ impl Data { &'a self, room_id: &'a RoomId, since: u64, - ) -> impl Stream> + Send + 'a { + ) -> impl Stream> + Send + 'a { type Key<'a> = (&'a RoomId, u64, &'a UserId); type KeyVal<'a> = (Key<'a>, CanonicalJsonObject); diff --git a/src/service/rooms/read_receipt/mod.rs b/src/service/rooms/read_receipt/mod.rs index 68ce9b7f..64081a2c 100644 --- a/src/service/rooms/read_receipt/mod.rs +++ b/src/service/rooms/read_receipt/mod.rs @@ -112,7 +112,7 @@ impl Service { &'a self, room_id: &'a RoomId, since: u64, - ) -> impl Stream> + Send + 'a { + ) -> impl Stream> + Send + 'a { self.db.readreceipts_since(room_id, since) } diff --git a/src/service/rooms/search/mod.rs b/src/service/rooms/search/mod.rs index afe3061b..ea2f90af 100644 --- a/src/service/rooms/search/mod.rs +++ b/src/service/rooms/search/mod.rs @@ -104,7 +104,7 @@ pub fn deindex_pdu(&self, shortroomid: ShortRoomId, pdu_id: &RawPduId, message_b pub async fn search_pdus<'a>( &'a self, query: &'a RoomQuery<'a>, -) -> Result<(usize, impl Stream> + Send + '_)> { +) -> Result<(usize, impl Stream> + Send + 'a)> { let pdu_ids: Vec<_> = self.search_pdu_ids(query).await?.collect().await; let filter = &query.criteria.filter; @@ -137,10 +137,10 @@ pub async fn search_pdus<'a>( // result is modeled as a stream such that callers don't have to be refactored // though an additional async/wrap still exists for now #[implement(Service)] -pub async fn search_pdu_ids( - &self, - query: &RoomQuery<'_>, -) -> Result + Send + '_ + use<'_>> { +pub async fn search_pdu_ids<'a>( + &'a self, + query: &'a RoomQuery<'_>, +) -> Result + Send + 'a + use<'a>> { let shortroomid = self.services.short.get_shortroomid(query.room_id).await?; let pdu_ids = self.search_pdu_ids_query_room(query, shortroomid).await; @@ -173,7 +173,7 @@ fn search_pdu_ids_query_words<'a>( &'a self, shortroomid: ShortRoomId, word: &'a str, -) -> impl Stream + Send + '_ { +) -> impl Stream + Send + 'a { self.search_pdu_ids_query_word(shortroomid, word) .map(move |key| -> RawPduId { let key = &key[prefix_len(word)..]; @@ -183,11 +183,11 @@ fn search_pdu_ids_query_words<'a>( /// Iterate over raw database results for a word #[implement(Service)] -fn search_pdu_ids_query_word( - &self, +fn search_pdu_ids_query_word<'a>( + &'a self, shortroomid: ShortRoomId, - word: &str, -) -> impl Stream> + Send + '_ + use<'_> { + word: &'a str, +) -> impl Stream> + Send + 'a + use<'a> { // rustc says const'ing this not yet stable let end_id: RawPduId = PduId { shortroomid, diff --git a/src/service/rooms/short/mod.rs b/src/service/rooms/short/mod.rs index 06ff6493..660bb7de 100644 --- a/src/service/rooms/short/mod.rs +++ b/src/service/rooms/short/mod.rs @@ -62,7 +62,7 @@ pub async fn get_or_create_shorteventid(&self, event_id: &EventId) -> ShortEvent pub fn multi_get_or_create_shorteventid<'a, I>( &'a self, event_ids: I, -) -> impl Stream + Send + '_ +) -> impl Stream + Send + 'a where I: Iterator + Clone + Debug + Send + 'a, { diff --git a/src/service/rooms/state/mod.rs b/src/service/rooms/state/mod.rs index 641aa6a9..386adf9d 100644 --- a/src/service/rooms/state/mod.rs +++ b/src/service/rooms/state/mod.rs @@ -388,7 +388,7 @@ impl Service { pub fn get_forward_extremities<'a>( &'a self, room_id: &'a RoomId, - ) -> impl Stream + Send + '_ { + ) -> impl Stream + Send + 'a { let prefix = (room_id, Interfix); self.db diff --git a/src/service/rooms/state_cache/mod.rs b/src/service/rooms/state_cache/mod.rs index e9845fbf..2d8f5cc5 100644 --- a/src/service/rooms/state_cache/mod.rs +++ b/src/service/rooms/state_cache/mod.rs @@ -144,7 +144,7 @@ pub fn clear_appservice_in_room_cache(&self) { self.appservice_in_room_cache.wri pub fn room_servers<'a>( &'a self, room_id: &'a RoomId, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { let prefix = (room_id, Interfix); self.db .roomserverids @@ -167,7 +167,7 @@ pub async fn server_in_room<'a>(&'a self, server: &'a ServerName, room_id: &'a R pub fn server_rooms<'a>( &'a self, server: &'a ServerName, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { let prefix = (server, Interfix); self.db .serverroomids @@ -202,7 +202,7 @@ pub fn get_shared_rooms<'a>( &'a self, user_a: &'a UserId, user_b: &'a UserId, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { use conduwuit::utils::set; let a = self.rooms_joined(user_a); @@ -216,7 +216,7 @@ pub fn get_shared_rooms<'a>( pub fn room_members<'a>( &'a self, room_id: &'a RoomId, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { let prefix = (room_id, Interfix); self.db .roomuserid_joined @@ -239,7 +239,7 @@ pub async fn room_joined_count(&self, room_id: &RoomId) -> Result { pub fn local_users_in_room<'a>( &'a self, room_id: &'a RoomId, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { self.room_members(room_id) .ready_filter(|user| self.services.globals.user_is_local(user)) } @@ -251,7 +251,7 @@ pub fn local_users_in_room<'a>( pub fn active_local_users_in_room<'a>( &'a self, room_id: &'a RoomId, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { self.local_users_in_room(room_id) .filter(|user| self.services.users.is_active(user)) } @@ -273,7 +273,7 @@ pub async fn room_invited_count(&self, room_id: &RoomId) -> Result { pub fn room_useroncejoined<'a>( &'a self, room_id: &'a RoomId, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { let prefix = (room_id, Interfix); self.db .roomuseroncejoinedids @@ -288,7 +288,7 @@ pub fn room_useroncejoined<'a>( pub fn room_members_invited<'a>( &'a self, room_id: &'a RoomId, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { let prefix = (room_id, Interfix); self.db .roomuserid_invitecount @@ -303,7 +303,7 @@ pub fn room_members_invited<'a>( pub fn room_members_knocked<'a>( &'a self, room_id: &'a RoomId, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { let prefix = (room_id, Interfix); self.db .roomuserid_knockedcount @@ -347,7 +347,7 @@ pub async fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result pub fn rooms_joined<'a>( &'a self, user_id: &'a UserId, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { self.db .userroomid_joined .keys_raw_prefix(user_id) diff --git a/src/service/rooms/state_cache/via.rs b/src/service/rooms/state_cache/via.rs index a818cc04..24d92a21 100644 --- a/src/service/rooms/state_cache/via.rs +++ b/src/service/rooms/state_cache/via.rs @@ -81,7 +81,7 @@ pub async fn servers_route_via(&self, room_id: &RoomId) -> Result( &'a self, room_id: &'a RoomId, -) -> impl Stream + Send + 'a { +) -> impl Stream + Send + 'a { type KeyVal<'a> = (Ignore, Vec<&'a ServerName>); self.db diff --git a/src/service/users/mod.rs b/src/service/users/mod.rs index fff1661c..6ddd8d79 100644 --- a/src/service/users/mod.rs +++ b/src/service/users/mod.rs @@ -422,7 +422,7 @@ impl Service { pub fn all_device_ids<'a>( &'a self, user_id: &'a UserId, - ) -> impl Stream + Send + 'a { + ) -> impl Stream + Send + 'a { let prefix = (user_id, Interfix); self.db .userdeviceid_metadata @@ -770,7 +770,7 @@ impl Service { user_id: &'a UserId, from: u64, to: Option, - ) -> impl Stream + Send + 'a { + ) -> impl Stream + Send + 'a { self.keys_changed_user_or_room(user_id.as_str(), from, to) .map(|(user_id, ..)| user_id) } @@ -781,7 +781,7 @@ impl Service { room_id: &'a RoomId, from: u64, to: Option, - ) -> impl Stream + Send + 'a { + ) -> impl Stream + Send + 'a { self.keys_changed_user_or_room(room_id.as_str(), from, to) } @@ -790,7 +790,7 @@ impl Service { user_or_room_id: &'a str, from: u64, to: Option, - ) -> impl Stream + Send + 'a { + ) -> impl Stream + Send + 'a { type KeyVal<'a> = ((&'a str, u64), &'a UserId); let to = to.unwrap_or(u64::MAX); From ddbca59193ceccfacb176cf09f44dc3b44294960 Mon Sep 17 00:00:00 2001 From: Ginger Date: Thu, 28 Aug 2025 16:18:14 -0400 Subject: [PATCH 2238/2291] Add spec and service files for creating an RPM package --- fedora/conduwuit.service | 68 +++++++++++++++++++++++++++++ fedora/continuwuity.spec.rpkg | 80 +++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 fedora/conduwuit.service create mode 100644 fedora/continuwuity.spec.rpkg diff --git a/fedora/conduwuit.service b/fedora/conduwuit.service new file mode 100644 index 00000000..6ab2af46 --- /dev/null +++ b/fedora/conduwuit.service @@ -0,0 +1,68 @@ +[Unit] +Description=Continuwuity - Matrix homeserver +Documentation=https://continuwuity.org/ +Wants=network-online.target +After=network-online.target +Alias=matrix-conduwuit.service + +[Service] +DynamicUser=yes +User=conduwuit +Group=conduwuit +Type=notify + +Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml" + +Environment="CONTINUWUITY_LOG_TO_JOURNALD=true" +Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N" + +ExecStart=/usr/bin/conduwuit + +AmbientCapabilities= +CapabilityBoundingSet= + +DevicePolicy=closed +LockPersonality=yes +MemoryDenyWriteExecute=yes +NoNewPrivileges=yes +#ProcSubset=pid +ProtectClock=yes +ProtectControlGroups=yes +ProtectHome=yes +ProtectHostname=yes +ProtectKernelLogs=yes +ProtectKernelModules=yes +ProtectKernelTunables=yes +ProtectProc=invisible +ProtectSystem=strict +PrivateDevices=yes +PrivateMounts=yes +PrivateTmp=yes +PrivateUsers=yes +PrivateIPC=yes +RemoveIPC=yes +RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX +RestrictNamespaces=yes +RestrictRealtime=yes +RestrictSUIDSGID=yes +SystemCallArchitectures=native +SystemCallFilter=@system-service @resources +SystemCallFilter=~@clock @debug @module @mount @reboot @swap @cpu-emulation @obsolete @timer @chown @setuid @privileged @keyring @ipc +SystemCallErrorNumber=EPERM + +StateDirectory=conduwuit +ConfigurationDirectory=conduwuit +RuntimeDirectory=conduwuit +RuntimeDirectoryMode=0750 + +Restart=on-failure +RestartSec=5 + +TimeoutStopSec=2m +TimeoutStartSec=2m + +StartLimitInterval=1m +StartLimitBurst=5 + +[Install] +WantedBy=multi-user.target diff --git a/fedora/continuwuity.spec.rpkg b/fedora/continuwuity.spec.rpkg new file mode 100644 index 00000000..7fca30fa --- /dev/null +++ b/fedora/continuwuity.spec.rpkg @@ -0,0 +1,80 @@ +# This should be run using rpkg-util: https://docs.pagure.org/rpkg-util +# it requires Internet access and is not suitable for Fedora main repos +# TODO: rpkg-util is no longer maintained, find a replacement + +Name: continuwuity +Version: {{{ git_repo_version }}} +Release: 1%{?dist} +Summary: Very cool Matrix chat homeserver written in Rust + +License: Apache-2.0 AND MIT + +URL: https://forgejo.ellis.link/continuwuation/%{name}/ +VCS: {{{ git_repo_vcs }}} +Source: {{{ git_repo_pack }}} + +BuildRequires: cargo-rpm-macros >= 25 +BuildRequires: systemd-rpm-macros +# Needed to build rust-librocksdb-sys +BuildRequires: clang +BuildRequires: liburing-devel + +Requires: liburing +Requires: glibc +Requires: libstdc++ + +%global _description %{expand: +A very cool Matrix chat homeserver written in Rust.} + +%description %{_description} + +%prep +{{{ git_repo_setup_macro }}} +%cargo_prep -N +# Perform an online build so Git dependencies can be retrieved +sed -i 's/^offline = true$//' .cargo/config.toml + +%build +%cargo_build + +# Here's the one legally required mystery incantation in this file. +# Some of our dependencies have source files which are (for some reason) marked as excutable. +# Files in .cargo/registry/ are copied into /usr/src/ by the debuginfo machinery +# at the end of the build step, and then the BRP shebang mangling script checks +# the entire buildroot to find executable files, and fails the build because +# it thinks Rust's file attributes are shebangs because they start with `#!`. +# So we have to clear the executable bit on all of them before that happens. +find .cargo/registry/ -executable -name "*.rs" -exec chmod -x {} + + +# TODO: this fails currently because it's forced to run in offline mode +# {cargo_license -- --no-dev} > LICENSE.dependencies + +%install +install -Dpm0755 target/rpm/conduwuit -t %{buildroot}%{_bindir} +install -Dpm0644 fedora/conduwuit.service -t %{buildroot}%{_unitdir} +install -Dpm0644 conduwuit-example.toml %{buildroot}%{_sysconfdir}/conduwuit/conduwuit.toml + +%files +%license LICENSE +%license src/core/matrix/state_res/LICENSE +%doc CODE_OF_CONDUCT.md +%doc CONTRIBUTING.md +%doc README.md +%doc SECURITY.md +%config %{_sysconfdir}/conduwuit/conduwuit.toml + +%{_bindir}/conduwuit +%{_unitdir}/conduwuit.service +# Do not create /var/lib/conduwuit, systemd will create it if necessary + +%post +%systemd_post conduwuit.service + +%preun +%systemd_preun conduwuit.service + +%postun +%systemd_postun_with_restart conduwuit.service + +%changelog +{{{ git_repo_changelog }}} \ No newline at end of file From f33f281edb12c2995f637be3cce1c876fea03f44 Mon Sep 17 00:00:00 2001 From: Ginger Date: Thu, 28 Aug 2025 16:20:34 -0400 Subject: [PATCH 2239/2291] Update long description to match deb package --- fedora/continuwuity.spec.rpkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedora/continuwuity.spec.rpkg b/fedora/continuwuity.spec.rpkg index 7fca30fa..ef921ed4 100644 --- a/fedora/continuwuity.spec.rpkg +++ b/fedora/continuwuity.spec.rpkg @@ -24,7 +24,7 @@ Requires: glibc Requires: libstdc++ %global _description %{expand: -A very cool Matrix chat homeserver written in Rust.} +A cool hard fork of Conduit, a Matrix homeserver written in Rust} %description %{_description} From 34417c96ae746712a86205854cda4da9c396dea1 Mon Sep 17 00:00:00 2001 From: Ginger Date: Thu, 28 Aug 2025 16:21:35 -0400 Subject: [PATCH 2240/2291] Update URL to point at the landing page --- fedora/continuwuity.spec.rpkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedora/continuwuity.spec.rpkg b/fedora/continuwuity.spec.rpkg index ef921ed4..19edf701 100644 --- a/fedora/continuwuity.spec.rpkg +++ b/fedora/continuwuity.spec.rpkg @@ -9,7 +9,7 @@ Summary: Very cool Matrix chat homeserver written in Rust License: Apache-2.0 AND MIT -URL: https://forgejo.ellis.link/continuwuation/%{name}/ +URL: https://continuwuity.org VCS: {{{ git_repo_vcs }}} Source: {{{ git_repo_pack }}} From 609e239436096309a940c238285512bbcf6cbae4 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sat, 30 Aug 2025 16:10:41 +0100 Subject: [PATCH 2241/2291] fix(fedora): Correct linting issues in RPM spec file The Fedora RPM packaging files added in PR #950 weren't passing pre-commit checks, causing CI failures for any branches rebased after that merge. This applies prek linting fixes (typo correction, trailing whitespace removal, and EOF newline) to ensure CI passes for all contributors. --- fedora/continuwuity.spec.rpkg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fedora/continuwuity.spec.rpkg b/fedora/continuwuity.spec.rpkg index 19edf701..f2efa383 100644 --- a/fedora/continuwuity.spec.rpkg +++ b/fedora/continuwuity.spec.rpkg @@ -38,7 +38,7 @@ sed -i 's/^offline = true$//' .cargo/config.toml %cargo_build # Here's the one legally required mystery incantation in this file. -# Some of our dependencies have source files which are (for some reason) marked as excutable. +# Some of our dependencies have source files which are (for some reason) marked as executable. # Files in .cargo/registry/ are copied into /usr/src/ by the debuginfo machinery # at the end of the build step, and then the BRP shebang mangling script checks # the entire buildroot to find executable files, and fails the build because @@ -46,7 +46,7 @@ sed -i 's/^offline = true$//' .cargo/config.toml # So we have to clear the executable bit on all of them before that happens. find .cargo/registry/ -executable -name "*.rs" -exec chmod -x {} + -# TODO: this fails currently because it's forced to run in offline mode +# TODO: this fails currently because it's forced to run in offline mode # {cargo_license -- --no-dev} > LICENSE.dependencies %install @@ -77,4 +77,4 @@ install -Dpm0644 conduwuit-example.toml %{buildroot}%{_sysconfdir}/conduwuit/con %systemd_postun_with_restart conduwuit.service %changelog -{{{ git_repo_changelog }}} \ No newline at end of file +{{{ git_repo_changelog }}} From 83e3de55a493eb0508a57c9a1a3f8fe700eb81b6 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 30 Aug 2025 16:00:46 +0100 Subject: [PATCH 2242/2291] fix(sync/v2): Room leaves being omitted incorrectly Partially borrowed from https://github.com/matrix-construct/tuwunel/commit/85a84f93c7ef7184a8eee1bb17116e5f0f0faf5a --- src/api/client/sync/v3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/client/sync/v3.rs b/src/api/client/sync/v3.rs index 01428c08..298a6e4b 100644 --- a/src/api/client/sync/v3.rs +++ b/src/api/client/sync/v3.rs @@ -430,7 +430,7 @@ async fn handle_left_room( .ok(); // Left before last sync - if Some(since) >= left_count { + if (Some(since) >= left_count && !include_leave) || Some(next_batch) < left_count { return Ok(None); } From b934898f51a2d3fa80ece879ef5fc2774a7f5881 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 31 Aug 2025 00:25:41 +0100 Subject: [PATCH 2243/2291] chore: Update renovate config, limit cargo updates --- .editorconfig | 4 ++ renovate.json | 115 ++++++++++++++++++++++++-------------------------- 2 files changed, 60 insertions(+), 59 deletions(-) diff --git a/.editorconfig b/.editorconfig index 3e7fd1b8..95843e73 100644 --- a/.editorconfig +++ b/.editorconfig @@ -26,3 +26,7 @@ max_line_length = 98 [*.yml] indent_size = 2 indent_style = space + +[*.json] +indent_size = 4 +indent_style = space diff --git a/renovate.json b/renovate.json index deb428af..68d21b9d 100644 --- a/renovate.json +++ b/renovate.json @@ -1,62 +1,59 @@ { - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:recommended" - ], - "lockFileMaintenance": { - "enabled": true, - "schedule": [ - "at any time" + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["config:recommended"], + "lockFileMaintenance": { + "enabled": true, + "schedule": ["at any time"] + }, + "nix": { + "enabled": true + }, + "labels": ["Dependencies", "Dependencies/Renovate"], + "ignoreDeps": [ + "tikv-jemallocator", + "tikv-jemalloc-sys", + "tikv-jemalloc-ctl", + "opentelemetry", + "opentelemetry_sdk", + "opentelemetry-jaeger", + "tracing-opentelemetry" + ], + "github-actions": { + "enabled": true, + "managerFilePatterns": [ + "/(^|/)\\.forgejo/workflows/[^/]+\\.ya?ml$/", + "/(^|/)\\.forgejo/actions/[^/]+/action\\.ya?ml$/", + "/(^|/)\\.github/workflows/[^/]+\\.ya?ml$/", + "/(^|/)\\.github/actions/[^/]+/action\\.ya?ml$/" + ] + }, + "packageRules": [ + { + "description": "Batch minor and patch GitHub Actions updates", + "matchManagers": ["github-actions"], + "matchUpdateTypes": ["minor", "patch"], + "groupName": "github-actions-non-major" + }, + { + "description": "Group Rust toolchain updates into a single PR", + "matchManagers": ["custom.regex"], + "matchPackageNames": ["rust", "rustc", "cargo"], + "groupName": "rust-toolchain" + }, + { + "description": "Group lockfile updates into a single PR", + "matchUpdateTypes": ["lockFileMaintenance"], + "groupName": "lockfile-maintenance" + }, + { + "description": "Batch patch-level Rust dependency updates", + "matchManagers": ["cargo"], + "matchUpdateTypes": ["patch"], + "groupName": "rust-patch-updates" + }, + { + "matchManagers": ["cargo"], + "prConcurrentLimit": 5 + } ] - }, - "nix": { - "enabled": true - }, - "labels": [ - "Dependencies", - "Dependencies/Renovate" - ], - "ignoreDeps": [ - "tikv-jemallocator", - "tikv-jemalloc-sys", - "tikv-jemalloc-ctl", - "opentelemetry", - "opentelemetry_sdk", - "opentelemetry-jaeger", - "tracing-opentelemetry" - ], - "github-actions": { - "enabled": true, - "fileMatch": [ - "(^|/)\\.forgejo/workflows/[^/]+\\.ya?ml$", - "(^|/)\\.forgejo/actions/[^/]+/action\\.ya?ml$", - "(^|/)\\.github/workflows/[^/]+\\.ya?ml$", - "(^|/)\\.github/actions/[^/]+/action\\.ya?ml$" - ] - }, - "packageRules": [ - { - "description": "Batch minor and patch GitHub Actions updates", - "matchManagers": ["github-actions"], - "matchUpdateTypes": ["minor", "patch"], - "groupName": "github-actions-non-major" - }, - { - "description": "Group Rust toolchain updates into a single PR", - "matchManagers": ["regex"], - "matchPackageNames": ["rust", "rustc", "cargo"], - "groupName": "rust-toolchain" - }, - { - "description": "Group lockfile updates into a single PR", - "matchUpdateTypes": ["lockFileMaintenance"], - "groupName": "lockfile-maintenance" - }, - { - "description": "Batch patch-level Rust dependency updates", - "matchManagers": ["cargo"], - "matchUpdateTypes": ["patch"], - "groupName": "rust-patch-updates" - } - ] } From e87c461b8d1d03d9e7b7b727f9a2fe8456c7338e Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 31 Aug 2025 00:38:47 +0100 Subject: [PATCH 2244/2291] feat: Cache renovate data, RO GitHub token --- .forgejo/workflows/renovate.yml | 69 ++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/.forgejo/workflows/renovate.yml b/.forgejo/workflows/renovate.yml index e8522bec..0152b387 100644 --- a/.forgejo/workflows/renovate.yml +++ b/.forgejo/workflows/renovate.yml @@ -39,24 +39,73 @@ jobs: renovate: name: Renovate runs-on: ubuntu-latest + container: + image: ghcr.io/renovatebot/renovate:41 + options: --tmpfs /tmp:exec steps: - name: Checkout uses: actions/checkout@v4 + with: + show-progress: false + + - name: print node heap + run: /usr/local/renovate/node -e 'console.log(`node heap limit = ${require("v8").getHeapStatistics().heap_size_limit / (1024 * 1024)} Mb`)' + + - name: Restore renovate repo cache + uses: https://github.com/actions/cache@v4 + with: + path: | + /tmp/renovate/cache/renovate/repository + key: repo-cache-${{ github.run_id }} + restore-keys: | + repo-cache- + + - name: Restore renovate package cache + uses: https://github.com/actions/cache@v4 + with: + path: | + /tmp/renovate/cache/renovate/renovate-cache-sqlite + key: package-cache-${{ github.run_id }} + restore-keys: | + package-cache- - name: Self-hosted Renovate - uses: https://github.com/renovatebot/github-action@v40.1.0 + uses: https://github.com/renovatebot/github-action@v43.0.9 env: LOG_LEVEL: ${{ inputs.logLevel || 'info' }} - RENOVATE_AUTODISCOVER: 'false' - RENOVATE_BINARY_SOURCE: 'install' RENOVATE_DRY_RUN: ${{ inputs.dryRun || 'false' }} - RENOVATE_ENDPOINT: ${{ github.server_url }}/api/v1 - RENOVATE_GIT_TIMEOUT: 60000 - RENOVATE_GIT_URL: 'endpoint' - RENOVATE_GITHUB_TOKEN_WARN: 'false' - RENOVATE_ONBOARDING: 'false' - RENOVATE_PLATFORM: 'forgejo' - RENOVATE_PR_COMMITS_PER_RUN_LIMIT: 3 + + RENOVATE_PLATFORM: forgejo + RENOVATE_ENDPOINT: ${{ github.server_url }} + RENOVATE_AUTODISCOVER: 'false' RENOVATE_REPOSITORIES: '["${{ github.repository }}"]' + + RENOVATE_GIT_TIMEOUT: 60000 + RENOVATE_REQUIRE_CONFIG: 'required' + RENOVATE_ONBOARDING: 'false' + + RENOVATE_PR_COMMITS_PER_RUN_LIMIT: 3 + + RENOVATE_GITHUB_TOKEN_WARN: 'false' RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} + GITHUB_COM_TOKEN: ${{ secrets.GH_PUBLIC_RO }} + + RENOVATE_REPOSITORY_CACHE: 'enabled' + RENOVATE_X_SQLITE_PACKAGE_CACHE: true + + - name: Save renovate repo cache + if: always() && env.RENOVATE_DRY_RUN != 'full' + uses: https://github.com/actions/cache@v4 + with: + path: | + /tmp/renovate/cache/renovate/repository + key: repo-cache-${{ github.run_id }} + + - name: Save renovate package cache + if: always() && env.RENOVATE_DRY_RUN != 'full' + uses: https://github.com/actions/cache@v4 + with: + path: | + /tmp/renovate/cache/renovate/renovate-cache-sqlite + key: package-cache-${{ github.run_id }} From 5cce02484146e62b34e7228f603cb42559c76eff Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sun, 31 Aug 2025 00:44:28 +0000 Subject: [PATCH 2245/2291] chore(deps): update https://github.com/reproducible-containers/buildkit-cache-dance action to v3.3.0 --- .forgejo/workflows/release-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 04fc9de9..58d6cab2 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -161,7 +161,7 @@ jobs: var-lib-apt-${{ matrix.slug }} key: var-lib-apt-${{ matrix.slug }} - name: inject cache into docker - uses: https://github.com/reproducible-containers/buildkit-cache-dance@v3.1.0 + uses: https://github.com/reproducible-containers/buildkit-cache-dance@v3.3.0 with: cache-map: | { From 1e430f9470f37f8e59e010ac083d140b45e63367 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 31 Aug 2025 16:55:47 +0100 Subject: [PATCH 2246/2291] feat(MSC4323): Implement agnostic suspension endpoint --- Cargo.lock | 22 +++++----- Cargo.toml | 2 +- src/api/client/admin/mod.rs | 3 ++ src/api/client/admin/suspend.rs | 77 +++++++++++++++++++++++++++++++++ src/api/client/mod.rs | 2 + src/api/router.rs | 2 + 6 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 src/api/client/admin/mod.rs create mode 100644 src/api/client/admin/suspend.rs diff --git a/Cargo.lock b/Cargo.lock index 2b044a1f..a3962c31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4058,7 +4058,7 @@ checksum = "88f8660c1ff60292143c98d08fc6e2f654d722db50410e3f3797d40baaf9d8f3" [[package]] name = "ruma" version = "0.10.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "assign", "js_int", @@ -4078,7 +4078,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "js_int", "ruma-common", @@ -4090,7 +4090,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "as_variant", "assign", @@ -4113,7 +4113,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "as_variant", "base64 0.22.1", @@ -4145,7 +4145,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "as_variant", "indexmap 2.10.0", @@ -4170,7 +4170,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "bytes", "headers", @@ -4192,7 +4192,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "js_int", "thiserror 2.0.12", @@ -4201,7 +4201,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "js_int", "ruma-common", @@ -4211,7 +4211,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "cfg-if", "proc-macro-crate", @@ -4226,7 +4226,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "js_int", "ruma-common", @@ -4238,7 +4238,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=b753738047d1f443aca870896ef27ecaacf027da#b753738047d1f443aca870896ef27ecaacf027da" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "base64 0.22.1", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index 9452066c..e2af2d94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -352,7 +352,7 @@ version = "0.1.2" [workspace.dependencies.ruma] git = "https://forgejo.ellis.link/continuwuation/ruwuma" #branch = "conduwuit-changes" -rev = "b753738047d1f443aca870896ef27ecaacf027da" +rev = "8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" features = [ "compat", "rand", diff --git a/src/api/client/admin/mod.rs b/src/api/client/admin/mod.rs new file mode 100644 index 00000000..8355a600 --- /dev/null +++ b/src/api/client/admin/mod.rs @@ -0,0 +1,3 @@ +mod suspend; + +pub(crate) use self::suspend::*; diff --git a/src/api/client/admin/suspend.rs b/src/api/client/admin/suspend.rs new file mode 100644 index 00000000..29682694 --- /dev/null +++ b/src/api/client/admin/suspend.rs @@ -0,0 +1,77 @@ +use axum::extract::State; +use conduwuit::{Err, Result}; +use ruma::api::client::admin::{get_suspended, set_suspended}; + +use crate::Ruma; + +/// # `GET /_matrix/client/v1/admin/suspend/{userId}` +/// +/// Check the suspension status of a target user +pub(crate) async fn get_suspended_status( + State(services): State, + body: Ruma, +) -> Result { + let sender_user = body.sender_user(); + if !services.users.is_admin(sender_user).await { + return Err!(Request(Forbidden("Only server administrators can use this endpoint"))); + }; + if !services.globals.user_is_local(&body.user_id) { + return Err!(Request(InvalidParam("Can only check the suspended status of local users"))); + }; + if !services.users.is_active(&body.user_id).await { + return Err!(Request(NotFound("Unknown user"))); + } + Ok(get_suspended::v1::Response::new( + services.users.is_suspended(&body.user_id).await?, + )) +} + +/// # `PUT /_matrix/client/v1/admin/suspend/{userId}` +/// +/// Set the suspension status of a target user +pub(crate) async fn put_suspended_status( + State(services): State, + body: Ruma, +) -> Result { + let sender_user = body.sender_user(); + if !services.users.is_admin(sender_user).await { + return Err!(Request(Forbidden("Only server administrators can use this endpoint"))); + }; + if !services.globals.user_is_local(&body.user_id) { + return Err!(Request(InvalidParam("Can only set the suspended status of local users"))); + }; + if !services.users.is_active(&body.user_id).await { + return Err!(Request(NotFound("Unknown user"))); + } + if body.user_id == *sender_user { + return Err!(Request(Forbidden("You cannot suspend yourself"))); + } + if services.users.is_admin(&body.user_id).await { + return Err!(Request(Forbidden("You cannot suspend another admin"))); + } + if services.users.is_suspended(&body.user_id).await? == body.suspended { + // No change + return Ok(set_suspended::v1::Response::new(body.suspended)); + } + + let action = if body.suspended { + services + .users + .suspend_account(&body.user_id, sender_user) + .await; + "suspended" + } else { + services.users.unsuspend_account(&body.user_id).await; + "unsuspended" + }; + + if services.config.admin_room_notices { + // Notify the admin room that an account has been un/suspended + services + .admin + .send_text(&format!("{} has been {} by {}.", body.user_id, action, sender_user)) + .await; + } + + Ok(set_suspended::v1::Response::new(body.suspended)) +} diff --git a/src/api/client/mod.rs b/src/api/client/mod.rs index e4be20b7..e53b26d9 100644 --- a/src/api/client/mod.rs +++ b/src/api/client/mod.rs @@ -1,5 +1,6 @@ pub(super) mod account; pub(super) mod account_data; +pub(super) mod admin; pub(super) mod alias; pub(super) mod appservice; pub(super) mod backup; @@ -43,6 +44,7 @@ pub(super) mod well_known; pub use account::full_user_deactivate; pub(super) use account::*; pub(super) use account_data::*; +pub(super) use admin::*; pub(super) use alias::*; pub(super) use appservice::*; pub(super) use backup::*; diff --git a/src/api/router.rs b/src/api/router.rs index 8072fa5b..42934f70 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -184,6 +184,8 @@ pub fn build(router: Router, server: &Server) -> Router { "/_matrix/client/unstable/im.nheko.summary/rooms/:room_id_or_alias/summary", get(client::get_room_summary_legacy) ) + .ruma_route(&client::get_suspended_status) + .ruma_route(&client::put_suspended_status) .ruma_route(&client::well_known_support) .ruma_route(&client::well_known_client) .route("/_conduwuit/server_version", get(client::conduwuit_server_version)) From 9783940105b070346204b99b0cfc6a23558c63b8 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 31 Aug 2025 17:07:19 +0100 Subject: [PATCH 2247/2291] feat(MSC4323): Advertise suspension support in capabilities --- src/api/client/capabilities.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/api/client/capabilities.rs b/src/api/client/capabilities.rs index c42c6dfd..2f9d6299 100644 --- a/src/api/client/capabilities.rs +++ b/src/api/client/capabilities.rs @@ -23,6 +23,11 @@ pub(crate) async fn get_capabilities_route( ) -> Result { let available: BTreeMap = Server::available_room_versions().collect(); + let authenticated = _body.sender_user.as_ref().is_some() + && services + .users + .is_active_local(_body.sender_user.as_ref().unwrap()) + .await; let mut capabilities = Capabilities::default(); capabilities.room_versions = RoomVersionsCapability { @@ -45,5 +50,15 @@ pub(crate) async fn get_capabilities_route( json!({"enabled": services.config.forget_forced_upon_leave}), )?; + if authenticated + && services + .users + .is_admin(_body.sender_user.as_ref().unwrap()) + .await + { + // Advertise suspension API + capabilities.set("uk.timedout.msc4323", json!({"suspend":true, "lock": false}))?; + } + Ok(get_capabilities::v3::Response { capabilities }) } From 04e796176a7dd2bf33f04d49bcadbb54a3feb501 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 31 Aug 2025 17:10:56 +0100 Subject: [PATCH 2248/2291] style(MSC4323): Satisfy our linting overlords --- src/api/client/admin/suspend.rs | 8 ++++---- src/api/client/capabilities.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api/client/admin/suspend.rs b/src/api/client/admin/suspend.rs index 29682694..0d3493f6 100644 --- a/src/api/client/admin/suspend.rs +++ b/src/api/client/admin/suspend.rs @@ -14,10 +14,10 @@ pub(crate) async fn get_suspended_status( let sender_user = body.sender_user(); if !services.users.is_admin(sender_user).await { return Err!(Request(Forbidden("Only server administrators can use this endpoint"))); - }; + } if !services.globals.user_is_local(&body.user_id) { return Err!(Request(InvalidParam("Can only check the suspended status of local users"))); - }; + } if !services.users.is_active(&body.user_id).await { return Err!(Request(NotFound("Unknown user"))); } @@ -36,10 +36,10 @@ pub(crate) async fn put_suspended_status( let sender_user = body.sender_user(); if !services.users.is_admin(sender_user).await { return Err!(Request(Forbidden("Only server administrators can use this endpoint"))); - }; + } if !services.globals.user_is_local(&body.user_id) { return Err!(Request(InvalidParam("Can only set the suspended status of local users"))); - }; + } if !services.users.is_active(&body.user_id).await { return Err!(Request(NotFound("Unknown user"))); } diff --git a/src/api/client/capabilities.rs b/src/api/client/capabilities.rs index 2f9d6299..1fcb073f 100644 --- a/src/api/client/capabilities.rs +++ b/src/api/client/capabilities.rs @@ -19,14 +19,14 @@ use crate::Ruma; /// of this server. pub(crate) async fn get_capabilities_route( State(services): State, - _body: Ruma, + body: Ruma, ) -> Result { let available: BTreeMap = Server::available_room_versions().collect(); - let authenticated = _body.sender_user.as_ref().is_some() + let authenticated = body.sender_user.as_ref().is_some() && services .users - .is_active_local(_body.sender_user.as_ref().unwrap()) + .is_active_local(body.sender_user.as_ref().unwrap()) .await; let mut capabilities = Capabilities::default(); @@ -53,7 +53,7 @@ pub(crate) async fn get_capabilities_route( if authenticated && services .users - .is_admin(_body.sender_user.as_ref().unwrap()) + .is_admin(body.sender_user.as_ref().unwrap()) .await { // Advertise suspension API From 35cf9af5c8a62dd362c9ecf4980d88291a2e9994 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 31 Aug 2025 17:44:32 +0100 Subject: [PATCH 2249/2291] feat(MSC4323): Add versions flag --- src/api/client/unversioned.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/client/unversioned.rs b/src/api/client/unversioned.rs index a4136d1a..7f19bc94 100644 --- a/src/api/client/unversioned.rs +++ b/src/api/client/unversioned.rs @@ -58,6 +58,7 @@ pub(crate) async fn get_supported_versions_route( ("uk.tcpip.msc4133".to_owned(), true), /* Extending User Profile API with Key:Value Pairs (https://github.com/matrix-org/matrix-spec-proposals/pull/4133) */ ("us.cloke.msc4175".to_owned(), true), /* Profile field for user time zone (https://github.com/matrix-org/matrix-spec-proposals/pull/4175) */ ("org.matrix.simplified_msc3575".to_owned(), true), /* Simplified Sliding sync (https://github.com/matrix-org/matrix-spec-proposals/pull/4186) */ + ("uk.timedout.msc4323".to_owned(), true), /* agnostic suspend (https://github.com/matrix-org/matrix-spec-proposals/pull/4323) */ ]), }; From 4e644961f3f7c3a955618caff3b3927b8f7e8931 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 31 Aug 2025 18:32:32 +0100 Subject: [PATCH 2250/2291] perf(MSC4323): Remove redundant authorisation checks --- src/api/client/capabilities.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/api/client/capabilities.rs b/src/api/client/capabilities.rs index 1fcb073f..afa61498 100644 --- a/src/api/client/capabilities.rs +++ b/src/api/client/capabilities.rs @@ -23,11 +23,6 @@ pub(crate) async fn get_capabilities_route( ) -> Result { let available: BTreeMap = Server::available_room_versions().collect(); - let authenticated = body.sender_user.as_ref().is_some() - && services - .users - .is_active_local(body.sender_user.as_ref().unwrap()) - .await; let mut capabilities = Capabilities::default(); capabilities.room_versions = RoomVersionsCapability { @@ -50,11 +45,10 @@ pub(crate) async fn get_capabilities_route( json!({"enabled": services.config.forget_forced_upon_leave}), )?; - if authenticated - && services - .users - .is_admin(body.sender_user.as_ref().unwrap()) - .await + if services + .users + .is_admin(body.sender_user.as_ref().unwrap()) + .await { // Advertise suspension API capabilities.set("uk.timedout.msc4323", json!({"suspend":true, "lock": false}))?; From d970df5fd239239554192887c5c0a634935ee3df Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Mon, 1 Sep 2025 11:36:39 +0100 Subject: [PATCH 2251/2291] perf(MSC4323): Parallelise some check futs --- src/api/client/admin/suspend.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/api/client/admin/suspend.rs b/src/api/client/admin/suspend.rs index 0d3493f6..bab1cb5a 100644 --- a/src/api/client/admin/suspend.rs +++ b/src/api/client/admin/suspend.rs @@ -1,5 +1,6 @@ use axum::extract::State; use conduwuit::{Err, Result}; +use futures::future::{join, join3}; use ruma::api::client::admin::{get_suspended, set_suspended}; use crate::Ruma; @@ -12,13 +13,16 @@ pub(crate) async fn get_suspended_status( body: Ruma, ) -> Result { let sender_user = body.sender_user(); - if !services.users.is_admin(sender_user).await { + + let (admin, active) = + join(services.users.is_admin(sender_user), services.users.is_active(&body.user_id)).await; + if !admin { return Err!(Request(Forbidden("Only server administrators can use this endpoint"))); } if !services.globals.user_is_local(&body.user_id) { return Err!(Request(InvalidParam("Can only check the suspended status of local users"))); } - if !services.users.is_active(&body.user_id).await { + if !active { return Err!(Request(NotFound("Unknown user"))); } Ok(get_suspended::v1::Response::new( @@ -34,20 +38,28 @@ pub(crate) async fn put_suspended_status( body: Ruma, ) -> Result { let sender_user = body.sender_user(); - if !services.users.is_admin(sender_user).await { + + let (sender_admin, active, target_admin) = join3( + services.users.is_admin(sender_user), + services.users.is_active(&body.user_id), + services.users.is_admin(&body.user_id), + ) + .await; + + if !sender_admin { return Err!(Request(Forbidden("Only server administrators can use this endpoint"))); } if !services.globals.user_is_local(&body.user_id) { return Err!(Request(InvalidParam("Can only set the suspended status of local users"))); } - if !services.users.is_active(&body.user_id).await { + if !active { return Err!(Request(NotFound("Unknown user"))); } if body.user_id == *sender_user { return Err!(Request(Forbidden("You cannot suspend yourself"))); } - if services.users.is_admin(&body.user_id).await { - return Err!(Request(Forbidden("You cannot suspend another admin"))); + if target_admin { + return Err!(Request(Forbidden("You cannot suspend another server administrator"))); } if services.users.is_suspended(&body.user_id).await? == body.suspended { // No change From 241371463e108b036b596c23d4658439016e69e1 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 30 Jul 2025 19:19:32 +0100 Subject: [PATCH 2252/2291] feat: Force leave remote rooms admin command --- src/admin/user/commands.rs | 30 ++++++++++++++++++++++++++++-- src/admin/user/mod.rs | 6 ++++++ src/api/client/membership/leave.rs | 2 +- src/api/client/membership/mod.rs | 2 +- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 56864a32..37ab030c 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -1,8 +1,8 @@ use std::{collections::BTreeMap, fmt::Write as _}; use api::client::{ - full_user_deactivate, join_room_by_id_helper, leave_all_rooms, leave_room, update_avatar_url, - update_displayname, + full_user_deactivate, join_room_by_id_helper, leave_all_rooms, leave_room, remote_leave_room, + update_avatar_url, update_displayname, }; use conduwuit::{ Err, Result, debug, debug_warn, error, info, is_equal_to, @@ -926,3 +926,29 @@ pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result { )) .await } + +#[admin_command] +pub(super) async fn force_leave_remote_room( + &self, + user_id: String, + room_id: OwnedRoomOrAliasId, +) -> Result { + let user_id = parse_local_user_id(self.services, &user_id)?; + let (room_id, _) = self + .services + .rooms + .alias + .resolve_with_servers(&room_id, None) + .await?; + + assert!( + self.services.globals.user_is_local(&user_id), + "Parsed user_id must be a local user" + ); + remote_leave_room(self.services, &user_id, &room_id, None) + .boxed() + .await?; + + self.write_str(&format!("{user_id} has been joined to {room_id}.",)) + .await +} diff --git a/src/admin/user/mod.rs b/src/admin/user/mod.rs index 656cacaf..366f7dd5 100644 --- a/src/admin/user/mod.rs +++ b/src/admin/user/mod.rs @@ -103,6 +103,12 @@ pub enum UserCommand { room_id: OwnedRoomOrAliasId, }, + /// - Manually leave a remote room for a local user. + ForceLeaveRemoteRoom { + user_id: String, + room_id: OwnedRoomOrAliasId, + }, + /// - Forces the specified user to drop their power levels to the room /// default, if their permissions allow and the auth check permits ForceDemote { diff --git a/src/api/client/membership/leave.rs b/src/api/client/membership/leave.rs index f4f1666b..0aadd833 100644 --- a/src/api/client/membership/leave.rs +++ b/src/api/client/membership/leave.rs @@ -215,7 +215,7 @@ pub async fn leave_room( Ok(()) } -async fn remote_leave_room( +pub async fn remote_leave_room( services: &Services, user_id: &UserId, room_id: &RoomId, diff --git a/src/api/client/membership/mod.rs b/src/api/client/membership/mod.rs index 7a6f19ad..691419f6 100644 --- a/src/api/client/membership/mod.rs +++ b/src/api/client/membership/mod.rs @@ -29,7 +29,7 @@ pub(crate) use self::{ }; pub use self::{ join::join_room_by_id_helper, - leave::{leave_all_rooms, leave_room}, + leave::{leave_all_rooms, leave_room, remote_leave_room}, }; use crate::{Ruma, client::full_user_deactivate}; From 66d479e2eb3e25f20ac74860e82c9c33ad069c21 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 30 Jul 2025 19:29:33 +0100 Subject: [PATCH 2253/2291] fix: Make remote leave helper a public fn --- src/api/client/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/client/mod.rs b/src/api/client/mod.rs index e53b26d9..c8ca7757 100644 --- a/src/api/client/mod.rs +++ b/src/api/client/mod.rs @@ -57,7 +57,7 @@ pub(super) use keys::*; pub(super) use media::*; pub(super) use media_legacy::*; pub(super) use membership::*; -pub use membership::{join_room_by_id_helper, leave_all_rooms, leave_room}; +pub use membership::{join_room_by_id_helper, leave_all_rooms, leave_room, remote_leave_room}; pub(super) use message::*; pub(super) use openid::*; pub(super) use presence::*; From 76b93e252dc3b4c380772ad4eaad0463b458600e Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Thu, 31 Jul 2025 17:48:30 +0100 Subject: [PATCH 2254/2291] feat: Only inject vias when manual ones aren't provided during join --- src/api/client/membership/join.rs | 49 ++++++++++++++++--------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/api/client/membership/join.rs b/src/api/client/membership/join.rs index dc170cbf..f3434bf5 100644 --- a/src/api/client/membership/join.rs +++ b/src/api/client/membership/join.rs @@ -156,31 +156,34 @@ pub(crate) async fn join_room_by_id_or_alias_route( .await?; let mut servers = body.via.clone(); - servers.extend( - services - .rooms - .state_cache - .servers_invite_via(&room_id) - .map(ToOwned::to_owned) - .collect::>() - .await, - ); + if servers.is_empty() { + debug!("No via servers provided for join, injecting some."); + servers.extend( + services + .rooms + .state_cache + .servers_invite_via(&room_id) + .map(ToOwned::to_owned) + .collect::>() + .await, + ); - servers.extend( - services - .rooms - .state_cache - .invite_state(sender_user, &room_id) - .await - .unwrap_or_default() - .iter() - .filter_map(|event| event.get_field("sender").ok().flatten()) - .filter_map(|sender: &str| UserId::parse(sender).ok()) - .map(|user| user.server_name().to_owned()), - ); + servers.extend( + services + .rooms + .state_cache + .invite_state(sender_user, &room_id) + .await + .unwrap_or_default() + .iter() + .filter_map(|event| event.get_field("sender").ok().flatten()) + .filter_map(|sender: &str| UserId::parse(sender).ok()) + .map(|user| user.server_name().to_owned()), + ); - if let Some(server) = room_id.server_name() { - servers.push(server.to_owned()); + if let Some(server) = room_id.server_name() { + servers.push(server.to_owned()); + } } servers.sort_unstable(); From 9e62e66ae4a46f3e742644a86c9c699eb5625f47 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 30 Aug 2025 21:31:23 +0100 Subject: [PATCH 2255/2291] chore(PR956): Update admin docs --- docs/admin_reference.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/admin_reference.md b/docs/admin_reference.md index 18e039e4..1c9d4fb0 100644 --- a/docs/admin_reference.md +++ b/docs/admin_reference.md @@ -21,6 +21,7 @@ This document contains the help content for the `admin` command-line program. * [`admin users list-joined-rooms`↴](#admin-users-list-joined-rooms) * [`admin users force-join-room`↴](#admin-users-force-join-room) * [`admin users force-leave-room`↴](#admin-users-force-leave-room) +* [`admin users force-leave-remote-room`↴](#admin-users-force-leave-remote-room) * [`admin users force-demote`↴](#admin-users-force-demote) * [`admin users make-user-admin`↴](#admin-users-make-user-admin) * [`admin users put-room-tag`↴](#admin-users-put-room-tag) @@ -295,6 +296,7 @@ You can find the ID using the `list-appservices` command. * `list-joined-rooms` — - Lists all the rooms (local and remote) that the specified user is joined in * `force-join-room` — - Manually join a local user to a room * `force-leave-room` — - Manually leave a local user from a room +* `force-leave-remote-room` — - Manually leave a remote room for a local user * `force-demote` — - Forces the specified user to drop their power levels to the room default, if their permissions allow and the auth check permits * `make-user-admin` — - Grant server-admin privileges to a user * `put-room-tag` — - Puts a room tag for the specified user and room ID @@ -449,6 +451,19 @@ Reverses the effects of the `suspend` command, allowing the user to send message +## `admin users force-leave-remote-room` + +- Manually leave a remote room for a local user + +**Usage:** `admin users force-leave-remote-room ` + +###### **Arguments:** + +* `` +* `` + + + ## `admin users force-demote` - Forces the specified user to drop their power levels to the room default, if their permissions allow and the auth check permits From 95aeff8cdcd35cf5bcfdd08c7c28618c6d579f02 Mon Sep 17 00:00:00 2001 From: Ginger Date: Fri, 29 Aug 2025 12:16:21 -0400 Subject: [PATCH 2256/2291] Set the DB path as an env var in systemd service files to prevent footgunning --- arch/conduwuit.service | 1 + debian/conduwuit.service | 1 + fedora/conduwuit.service | 1 + src/core/config/mod.rs | 6 ++++-- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/conduwuit.service b/arch/conduwuit.service index 34c3995e..18c34f33 100644 --- a/arch/conduwuit.service +++ b/arch/conduwuit.service @@ -20,6 +20,7 @@ StandardError=journal+console Environment="CONTINUWUITY_LOG_TO_JOURNALD=true" Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N" +Environment="CONTINUWUITY_DATABASE_PATH=/var/lib/conduwuit" TTYReset=yes # uncomment to allow buffer to be cleared every restart diff --git a/debian/conduwuit.service b/debian/conduwuit.service index da78f09f..ec2505b5 100644 --- a/debian/conduwuit.service +++ b/debian/conduwuit.service @@ -16,6 +16,7 @@ Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml" Environment="CONTINUWUITY_LOG_TO_JOURNALD=true" Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N" +Environment="CONTINUWUITY_DATABASE_PATH=/var/lib/conduwuit" ExecStart=/usr/sbin/conduwuit diff --git a/fedora/conduwuit.service b/fedora/conduwuit.service index 6ab2af46..f37c7798 100644 --- a/fedora/conduwuit.service +++ b/fedora/conduwuit.service @@ -15,6 +15,7 @@ Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml" Environment="CONTINUWUITY_LOG_TO_JOURNALD=true" Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N" +Environment="CONTINUWUITY_DATABASE_PATH=/var/lib/conduwuit" ExecStart=/usr/bin/conduwuit diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index e8518ed4..58a39a75 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -126,9 +126,11 @@ pub struct Config { /// This is the only directory where continuwuity will save its data, /// including media. Note: this was previously "/var/lib/matrix-conduit". /// - /// YOU NEED TO EDIT THIS. + /// YOU NEED TO EDIT THIS, UNLESS you are running continuwuity as a `systemd` service. + /// The service file sets it to `/var/lib/conduwuit` using an environment variable + /// and also grants write access. /// - /// example: "/var/lib/continuwuity" + /// example: "/var/lib/conduwuit" pub database_path: PathBuf, /// continuwuity supports online database backups using RocksDB's Backup From 99b44bbf0946b1ad426ed0bf719674300576721c Mon Sep 17 00:00:00 2001 From: Ginger Date: Fri, 29 Aug 2025 12:30:48 -0400 Subject: [PATCH 2257/2291] Update conduwuit-example.toml --- conduwuit-example.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index f0e510b4..fa65cbf2 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -79,9 +79,11 @@ # This is the only directory where continuwuity will save its data, # including media. Note: this was previously "/var/lib/matrix-conduit". # -# YOU NEED TO EDIT THIS. +# YOU NEED TO EDIT THIS, UNLESS you are running continuwuity as a `systemd` service. +# The service file sets it to `/var/lib/conduwuit` using an environment variable +# and also grants write access. # -# example: "/var/lib/continuwuity" +# example: "/var/lib/conduwuit" # #database_path = From 467aed3028705ec89adfa8b2b58e746323595eed Mon Sep 17 00:00:00 2001 From: nex Date: Tue, 2 Sep 2025 16:36:56 +0000 Subject: [PATCH 2258/2291] chore: Add Ginger's GH noreply email to mailmap --- .mailmap | 1 + 1 file changed, 1 insertion(+) diff --git a/.mailmap b/.mailmap index fa267e13..7c25737d 100644 --- a/.mailmap +++ b/.mailmap @@ -13,3 +13,4 @@ Rudi Floren Tamara Schmitz <15906939+tamara-schmitz@users.noreply.github.com> Timo Kösters x4u <14617923-x4u@users.noreply.gitlab.com> +Ginger <75683114+gingershaped@users.noreply.github.com> From d19e0f0d97289a9e4d3c08c956ccfa2257b07bf8 Mon Sep 17 00:00:00 2001 From: Ginger Date: Tue, 2 Sep 2025 09:35:15 -0400 Subject: [PATCH 2259/2291] feat: Move packaging scripts into `dist/` and consolidate the service files --- .forgejo/workflows/release-image.yml | 2 +- arch/conduwuit.service | 84 ------------------- debian/conduwuit.service | 71 ---------------- {fedora => dist}/conduwuit.service | 7 +- {debian => dist/debian}/README.md | 0 {debian => dist/debian}/config | 0 {debian => dist/debian}/postinst | 0 {debian => dist/debian}/postrm | 0 .../fedora}/continuwuity.spec.rpkg | 2 +- .../nix}/pkgs/main/cross-compilation-env.nix | 0 {nix => dist/nix}/pkgs/main/default.nix | 0 docs/configuration/examples.md | 19 +---- docs/deploying/debian.md | 2 +- flake.nix | 2 +- src/core/config/mod.rs | 6 +- src/main/Cargo.toml | 4 +- 16 files changed, 16 insertions(+), 183 deletions(-) delete mode 100644 arch/conduwuit.service delete mode 100644 debian/conduwuit.service rename {fedora => dist}/conduwuit.service (95%) rename {debian => dist/debian}/README.md (100%) rename {debian => dist/debian}/config (100%) rename {debian => dist/debian}/postinst (100%) rename {debian => dist/debian}/postrm (100%) rename {fedora => dist/fedora}/continuwuity.spec.rpkg (97%) rename {nix => dist/nix}/pkgs/main/cross-compilation-env.nix (100%) rename {nix => dist/nix}/pkgs/main/default.nix (100%) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 58d6cab2..2055d91a 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -10,7 +10,7 @@ on: - ".gitlab-ci.yml" - ".gitignore" - "renovate.json" - - "debian/**" + - "dist/**" - "docker/**" - "docs/**" # Allows you to run this workflow manually from the Actions tab diff --git a/arch/conduwuit.service b/arch/conduwuit.service deleted file mode 100644 index 18c34f33..00000000 --- a/arch/conduwuit.service +++ /dev/null @@ -1,84 +0,0 @@ -[Unit] - -Description=Continuwuity - Matrix homeserver -Wants=network-online.target -After=network-online.target -Documentation=https://continuwuity.org/ -RequiresMountsFor=/var/lib/private/conduwuit -Alias=matrix-conduwuit.service - -[Service] -DynamicUser=yes -Type=notify-reload -ReloadSignal=SIGUSR1 - -TTYPath=/dev/tty25 -DeviceAllow=char-tty -StandardInput=tty-force -StandardOutput=tty -StandardError=journal+console - -Environment="CONTINUWUITY_LOG_TO_JOURNALD=true" -Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N" -Environment="CONTINUWUITY_DATABASE_PATH=/var/lib/conduwuit" - -TTYReset=yes -# uncomment to allow buffer to be cleared every restart -TTYVTDisallocate=no - -TTYColumns=120 -TTYRows=40 - -AmbientCapabilities= -CapabilityBoundingSet= - -DevicePolicy=closed -LockPersonality=yes -MemoryDenyWriteExecute=yes -NoNewPrivileges=yes -#ProcSubset=pid -ProtectClock=yes -ProtectControlGroups=yes -ProtectHome=yes -ProtectHostname=yes -ProtectKernelLogs=yes -ProtectKernelModules=yes -ProtectKernelTunables=yes -ProtectProc=invisible -ProtectSystem=strict -PrivateDevices=yes -PrivateMounts=yes -PrivateTmp=yes -PrivateUsers=yes -PrivateIPC=yes -RemoveIPC=yes -RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX -RestrictNamespaces=yes -RestrictRealtime=yes -RestrictSUIDSGID=yes -SystemCallArchitectures=native -SystemCallFilter=@system-service @resources -SystemCallFilter=~@clock @debug @module @mount @reboot @swap @cpu-emulation @obsolete @timer @chown @setuid @privileged @keyring @ipc -SystemCallErrorNumber=EPERM -StateDirectory=conduwuit - -RuntimeDirectory=conduwuit -RuntimeDirectoryMode=0750 - -Environment=CONTINUWUITY_CONFIG=%d/config.toml -LoadCredential=config.toml:/etc/conduwuit/conduwuit.toml -BindPaths=/var/lib/private/conduwuit:/var/lib/matrix-conduit -BindPaths=/var/lib/private/conduwuit:/var/lib/private/matrix-conduit - -ExecStart=/usr/bin/conduwuit -Restart=on-failure -RestartSec=5 - -TimeoutStopSec=4m -TimeoutStartSec=4m - -StartLimitInterval=1m -StartLimitBurst=5 - -[Install] -WantedBy=multi-user.target diff --git a/debian/conduwuit.service b/debian/conduwuit.service deleted file mode 100644 index ec2505b5..00000000 --- a/debian/conduwuit.service +++ /dev/null @@ -1,71 +0,0 @@ -[Unit] - -Description=Continuwuity - Matrix homeserver -Wants=network-online.target -After=network-online.target -Documentation=https://continuwuity.org/ -Alias=matrix-conduwuit.service - -[Service] -DynamicUser=yes -User=conduwuit -Group=conduwuit -Type=notify - -Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml" - -Environment="CONTINUWUITY_LOG_TO_JOURNALD=true" -Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N" -Environment="CONTINUWUITY_DATABASE_PATH=/var/lib/conduwuit" - -ExecStart=/usr/sbin/conduwuit - -ReadWritePaths=/var/lib/conduwuit /etc/conduwuit - -AmbientCapabilities= -CapabilityBoundingSet= - -DevicePolicy=closed -LockPersonality=yes -MemoryDenyWriteExecute=yes -NoNewPrivileges=yes -#ProcSubset=pid -ProtectClock=yes -ProtectControlGroups=yes -ProtectHome=yes -ProtectHostname=yes -ProtectKernelLogs=yes -ProtectKernelModules=yes -ProtectKernelTunables=yes -ProtectProc=invisible -ProtectSystem=strict -PrivateDevices=yes -PrivateMounts=yes -PrivateTmp=yes -PrivateUsers=yes -PrivateIPC=yes -RemoveIPC=yes -RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX -RestrictNamespaces=yes -RestrictRealtime=yes -RestrictSUIDSGID=yes -SystemCallArchitectures=native -SystemCallFilter=@system-service @resources -SystemCallFilter=~@clock @debug @module @mount @reboot @swap @cpu-emulation @obsolete @timer @chown @setuid @privileged @keyring @ipc -SystemCallErrorNumber=EPERM -#StateDirectory=conduwuit - -RuntimeDirectory=conduwuit -RuntimeDirectoryMode=0750 - -Restart=on-failure -RestartSec=5 - -TimeoutStopSec=2m -TimeoutStartSec=2m - -StartLimitInterval=1m -StartLimitBurst=5 - -[Install] -WantedBy=multi-user.target diff --git a/fedora/conduwuit.service b/dist/conduwuit.service similarity index 95% rename from fedora/conduwuit.service rename to dist/conduwuit.service index f37c7798..db9aca1a 100644 --- a/fedora/conduwuit.service +++ b/dist/conduwuit.service @@ -9,7 +9,8 @@ Alias=matrix-conduwuit.service DynamicUser=yes User=conduwuit Group=conduwuit -Type=notify +Type=notify-reload +ReloadSignal=SIGUSR1 Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml" @@ -59,8 +60,8 @@ RuntimeDirectoryMode=0750 Restart=on-failure RestartSec=5 -TimeoutStopSec=2m -TimeoutStartSec=2m +TimeoutStopSec=4m +TimeoutStartSec=4m StartLimitInterval=1m StartLimitBurst=5 diff --git a/debian/README.md b/dist/debian/README.md similarity index 100% rename from debian/README.md rename to dist/debian/README.md diff --git a/debian/config b/dist/debian/config similarity index 100% rename from debian/config rename to dist/debian/config diff --git a/debian/postinst b/dist/debian/postinst similarity index 100% rename from debian/postinst rename to dist/debian/postinst diff --git a/debian/postrm b/dist/debian/postrm similarity index 100% rename from debian/postrm rename to dist/debian/postrm diff --git a/fedora/continuwuity.spec.rpkg b/dist/fedora/continuwuity.spec.rpkg similarity index 97% rename from fedora/continuwuity.spec.rpkg rename to dist/fedora/continuwuity.spec.rpkg index f2efa383..dec4fff2 100644 --- a/fedora/continuwuity.spec.rpkg +++ b/dist/fedora/continuwuity.spec.rpkg @@ -51,7 +51,7 @@ find .cargo/registry/ -executable -name "*.rs" -exec chmod -x {} + %install install -Dpm0755 target/rpm/conduwuit -t %{buildroot}%{_bindir} -install -Dpm0644 fedora/conduwuit.service -t %{buildroot}%{_unitdir} +install -Dpm0644 dist/conduwuit.service -t %{buildroot}%{_unitdir} install -Dpm0644 conduwuit-example.toml %{buildroot}%{_sysconfdir}/conduwuit/conduwuit.toml %files diff --git a/nix/pkgs/main/cross-compilation-env.nix b/dist/nix/pkgs/main/cross-compilation-env.nix similarity index 100% rename from nix/pkgs/main/cross-compilation-env.nix rename to dist/nix/pkgs/main/cross-compilation-env.nix diff --git a/nix/pkgs/main/default.nix b/dist/nix/pkgs/main/default.nix similarity index 100% rename from nix/pkgs/main/default.nix rename to dist/nix/pkgs/main/default.nix diff --git a/docs/configuration/examples.md b/docs/configuration/examples.md index 54aa8bd7..b30661b5 100644 --- a/docs/configuration/examples.md +++ b/docs/configuration/examples.md @@ -9,24 +9,11 @@ -## Debian systemd unit file +## systemd unit file
-Debian systemd unit file +systemd unit file ``` -{{#include ../../debian/conduwuit.service}} +{{#include ../../dist/conduwuit.service}} ``` - -
- -## Arch Linux systemd unit file - -
-Arch Linux systemd unit file - -``` -{{#include ../../arch/conduwuit.service}} -``` - -
diff --git a/docs/deploying/debian.md b/docs/deploying/debian.md index 2e8a544a..527c1864 100644 --- a/docs/deploying/debian.md +++ b/docs/deploying/debian.md @@ -1 +1 @@ -{{#include ../../debian/README.md}} +{{#include ../../dist/debian/README.md}} diff --git a/flake.nix b/flake.nix index d6beb84e..4655fc01 100644 --- a/flake.nix +++ b/flake.nix @@ -48,7 +48,7 @@ pkgs.lib.makeScope pkgs.newScope (self: { inherit pkgs inputs; craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (_: toolchain); - main = self.callPackage ./nix/pkgs/main { }; + main = self.callPackage ./dist/nix/pkgs/main { }; liburing = pkgs.liburing.overrideAttrs { # Tests weren't building outputs = [ diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 58a39a75..e9e6d28d 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -126,9 +126,9 @@ pub struct Config { /// This is the only directory where continuwuity will save its data, /// including media. Note: this was previously "/var/lib/matrix-conduit". /// - /// YOU NEED TO EDIT THIS, UNLESS you are running continuwuity as a `systemd` service. - /// The service file sets it to `/var/lib/conduwuit` using an environment variable - /// and also grants write access. + /// YOU NEED TO EDIT THIS, UNLESS you are running continuwuity as a + /// `systemd` service. The service file sets it to `/var/lib/conduwuit` + /// using an environment variable and also grants write access. /// /// example: "/var/lib/conduwuit" pub database_path: PathBuf, diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index eafa1e48..cecd36e9 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -32,10 +32,10 @@ a cool hard fork of Conduit, a Matrix homeserver written in Rust""" section = "net" priority = "optional" conf-files = ["/etc/conduwuit/conduwuit.toml"] -maintainer-scripts = "../../debian/" +maintainer-scripts = "../../dist/debian/" systemd-units = { unit-name = "conduwuit", start = false } assets = [ - ["../../debian/README.md", "usr/share/doc/conduwuit/README.Debian", "644"], + ["../../dist/debian/README.md", "usr/share/doc/conduwuit/README.Debian", "644"], ["../../README.md", "usr/share/doc/conduwuit/", "644"], ["../../target/release/conduwuit", "usr/sbin/conduwuit", "755"], ["../../conduwuit-example.toml", "etc/conduwuit/conduwuit.toml", "640"], From e7124edb7391158cb9ae0fecf36ad682e75923d1 Mon Sep 17 00:00:00 2001 From: Ginger Date: Tue, 2 Sep 2025 10:37:25 -0400 Subject: [PATCH 2260/2291] fix: Update debian systemd unit path --- conduwuit-example.toml | 6 +++--- src/main/Cargo.toml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index fa65cbf2..0fc034d0 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -79,9 +79,9 @@ # This is the only directory where continuwuity will save its data, # including media. Note: this was previously "/var/lib/matrix-conduit". # -# YOU NEED TO EDIT THIS, UNLESS you are running continuwuity as a `systemd` service. -# The service file sets it to `/var/lib/conduwuit` using an environment variable -# and also grants write access. +# YOU NEED TO EDIT THIS, UNLESS you are running continuwuity as a +# `systemd` service. The service file sets it to `/var/lib/conduwuit` +# using an environment variable and also grants write access. # # example: "/var/lib/conduwuit" # diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index cecd36e9..bbb3bec4 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -33,11 +33,11 @@ section = "net" priority = "optional" conf-files = ["/etc/conduwuit/conduwuit.toml"] maintainer-scripts = "../../dist/debian/" -systemd-units = { unit-name = "conduwuit", start = false } +systemd-units = { unit-name = "conduwuit", start = false, unit-scripts = "../../dist/" } assets = [ ["../../dist/debian/README.md", "usr/share/doc/conduwuit/README.Debian", "644"], ["../../README.md", "usr/share/doc/conduwuit/", "644"], - ["../../target/release/conduwuit", "usr/sbin/conduwuit", "755"], + ["../../target/release/conduwuit", "usr/bin/conduwuit", "755"], ["../../conduwuit-example.toml", "etc/conduwuit/conduwuit.toml", "640"], ] From 0d58e660a297aa0e2864f42b131de510cc3d1f7b Mon Sep 17 00:00:00 2001 From: Ginger Date: Tue, 2 Sep 2025 10:44:47 -0400 Subject: [PATCH 2261/2291] fix: Remove unnecessary user and directory modifications systemd creates a dynamic user for continuwuity and manages directories for it automatically, so the debian postinst script no longer needs to do that. --- dist/debian/postinst | 24 ------------------------ dist/debian/postrm | 10 ++-------- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/dist/debian/postinst b/dist/debian/postinst index 4eae4573..4bc89422 100644 --- a/dist/debian/postinst +++ b/dist/debian/postinst @@ -9,30 +9,6 @@ CONDUWUIT_CONFIG_PATH=/etc/conduwuit case "$1" in configure) - # Create the `conduwuit` user if it does not exist yet. - if ! getent passwd conduwuit > /dev/null ; then - echo 'Adding system user for the conduwuit Matrix homeserver' 1>&2 - adduser --system --group --quiet \ - --home "$CONDUWUIT_DATABASE_PATH" \ - --disabled-login \ - --shell "/usr/sbin/nologin" \ - conduwuit - fi - - # Create the database path if it does not exist yet and fix up ownership - # and permissions for the config. - mkdir -v -p "$CONDUWUIT_DATABASE_PATH" - - # symlink the previous location for compatibility if it does not exist yet. - if ! test -L "/var/lib/matrix-conduit" ; then - ln -s -v "$CONDUWUIT_DATABASE_PATH" "/var/lib/matrix-conduit" - fi - - chown -v conduwuit:conduwuit -R "$CONDUWUIT_DATABASE_PATH" - chown -v conduwuit:conduwuit -R "$CONDUWUIT_CONFIG_PATH" - - chmod -v 740 "$CONDUWUIT_DATABASE_PATH" - echo '' echo 'Make sure you edit the example config at /etc/conduwuit/conduwuit.toml before starting!' echo 'To start the server, run: systemctl start conduwuit.service' diff --git a/dist/debian/postrm b/dist/debian/postrm index 3c0b1c09..d5a9e0ac 100644 --- a/dist/debian/postrm +++ b/dist/debian/postrm @@ -20,24 +20,18 @@ case $1 in if [ -d "$CONDUWUIT_CONFIG_PATH" ]; then if test -L "$CONDUWUIT_CONFIG_PATH"; then - echo "Deleting conduwuit configuration files" + echo "Deleting continuwuity configuration files" rm -v -r "$CONDUWUIT_CONFIG_PATH" fi fi if [ -d "$CONDUWUIT_DATABASE_PATH" ]; then if test -L "$CONDUWUIT_DATABASE_PATH"; then - echo "Deleting conduwuit database directory" + echo "Deleting continuwuity database directory" rm -r "$CONDUWUIT_DATABASE_PATH" fi fi - if [ -d "$CONDUWUIT_DATABASE_PATH_SYMLINK" ]; then - if test -L "$CONDUWUIT_DATABASE_SYMLINK"; then - echo "Removing matrix-conduit symlink" - rm -r "$CONDUWUIT_DATABASE_PATH_SYMLINK" - fi - fi ;; esac From 58bbc0e676bbf770904dbe01e2fa4dc1aaa94dbe Mon Sep 17 00:00:00 2001 From: Ginger Date: Tue, 2 Sep 2025 12:20:23 -0400 Subject: [PATCH 2262/2291] fix: Move packaging files from `dist/` to `pkg/` --- .forgejo/workflows/release-image.yml | 2 +- docs/configuration/examples.md | 2 +- docs/deploying/debian.md | 2 +- flake.nix | 2 +- {dist => pkg}/conduwuit.service | 0 {dist => pkg}/debian/README.md | 0 {dist => pkg}/debian/config | 0 {dist => pkg}/debian/postinst | 0 {dist => pkg}/debian/postrm | 0 {dist => pkg}/fedora/continuwuity.spec.rpkg | 2 +- {dist => pkg}/nix/pkgs/main/cross-compilation-env.nix | 0 {dist => pkg}/nix/pkgs/main/default.nix | 0 src/main/Cargo.toml | 6 +++--- 13 files changed, 8 insertions(+), 8 deletions(-) rename {dist => pkg}/conduwuit.service (100%) rename {dist => pkg}/debian/README.md (100%) rename {dist => pkg}/debian/config (100%) rename {dist => pkg}/debian/postinst (100%) rename {dist => pkg}/debian/postrm (100%) rename {dist => pkg}/fedora/continuwuity.spec.rpkg (97%) rename {dist => pkg}/nix/pkgs/main/cross-compilation-env.nix (100%) rename {dist => pkg}/nix/pkgs/main/default.nix (100%) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 2055d91a..6972c791 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -10,7 +10,7 @@ on: - ".gitlab-ci.yml" - ".gitignore" - "renovate.json" - - "dist/**" + - "pkg/**" - "docker/**" - "docs/**" # Allows you to run this workflow manually from the Actions tab diff --git a/docs/configuration/examples.md b/docs/configuration/examples.md index b30661b5..9613e252 100644 --- a/docs/configuration/examples.md +++ b/docs/configuration/examples.md @@ -15,5 +15,5 @@ systemd unit file ``` -{{#include ../../dist/conduwuit.service}} +{{#include ../../pkg/conduwuit.service}} ``` diff --git a/docs/deploying/debian.md b/docs/deploying/debian.md index 527c1864..369638a4 100644 --- a/docs/deploying/debian.md +++ b/docs/deploying/debian.md @@ -1 +1 @@ -{{#include ../../dist/debian/README.md}} +{{#include ../../pkg/debian/README.md}} diff --git a/flake.nix b/flake.nix index 4655fc01..e65fcbda 100644 --- a/flake.nix +++ b/flake.nix @@ -48,7 +48,7 @@ pkgs.lib.makeScope pkgs.newScope (self: { inherit pkgs inputs; craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (_: toolchain); - main = self.callPackage ./dist/nix/pkgs/main { }; + main = self.callPackage ./pkg/nix/pkgs/main { }; liburing = pkgs.liburing.overrideAttrs { # Tests weren't building outputs = [ diff --git a/dist/conduwuit.service b/pkg/conduwuit.service similarity index 100% rename from dist/conduwuit.service rename to pkg/conduwuit.service diff --git a/dist/debian/README.md b/pkg/debian/README.md similarity index 100% rename from dist/debian/README.md rename to pkg/debian/README.md diff --git a/dist/debian/config b/pkg/debian/config similarity index 100% rename from dist/debian/config rename to pkg/debian/config diff --git a/dist/debian/postinst b/pkg/debian/postinst similarity index 100% rename from dist/debian/postinst rename to pkg/debian/postinst diff --git a/dist/debian/postrm b/pkg/debian/postrm similarity index 100% rename from dist/debian/postrm rename to pkg/debian/postrm diff --git a/dist/fedora/continuwuity.spec.rpkg b/pkg/fedora/continuwuity.spec.rpkg similarity index 97% rename from dist/fedora/continuwuity.spec.rpkg rename to pkg/fedora/continuwuity.spec.rpkg index dec4fff2..a2b32e48 100644 --- a/dist/fedora/continuwuity.spec.rpkg +++ b/pkg/fedora/continuwuity.spec.rpkg @@ -51,7 +51,7 @@ find .cargo/registry/ -executable -name "*.rs" -exec chmod -x {} + %install install -Dpm0755 target/rpm/conduwuit -t %{buildroot}%{_bindir} -install -Dpm0644 dist/conduwuit.service -t %{buildroot}%{_unitdir} +install -Dpm0644 pkg/conduwuit.service -t %{buildroot}%{_unitdir} install -Dpm0644 conduwuit-example.toml %{buildroot}%{_sysconfdir}/conduwuit/conduwuit.toml %files diff --git a/dist/nix/pkgs/main/cross-compilation-env.nix b/pkg/nix/pkgs/main/cross-compilation-env.nix similarity index 100% rename from dist/nix/pkgs/main/cross-compilation-env.nix rename to pkg/nix/pkgs/main/cross-compilation-env.nix diff --git a/dist/nix/pkgs/main/default.nix b/pkg/nix/pkgs/main/default.nix similarity index 100% rename from dist/nix/pkgs/main/default.nix rename to pkg/nix/pkgs/main/default.nix diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index bbb3bec4..8f6f4341 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -32,10 +32,10 @@ a cool hard fork of Conduit, a Matrix homeserver written in Rust""" section = "net" priority = "optional" conf-files = ["/etc/conduwuit/conduwuit.toml"] -maintainer-scripts = "../../dist/debian/" -systemd-units = { unit-name = "conduwuit", start = false, unit-scripts = "../../dist/" } +maintainer-scripts = "../../pkg/debian/" +systemd-units = { unit-name = "conduwuit", start = false, unit-scripts = "../../pkg/" } assets = [ - ["../../dist/debian/README.md", "usr/share/doc/conduwuit/README.Debian", "644"], + ["../../pkg/debian/README.md", "usr/share/doc/conduwuit/README.Debian", "644"], ["../../README.md", "usr/share/doc/conduwuit/", "644"], ["../../target/release/conduwuit", "usr/bin/conduwuit", "755"], ["../../conduwuit-example.toml", "etc/conduwuit/conduwuit.toml", "640"], From fdf577138711786582b6c9484188a96346167f3f Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 6 Sep 2025 15:20:45 +0100 Subject: [PATCH 2263/2291] ci: Fix CI not triggering on external pull requests --- .forgejo/workflows/prek-checks.yml | 4 ++++ .forgejo/workflows/release-image.yml | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/.forgejo/workflows/prek-checks.yml b/.forgejo/workflows/prek-checks.yml index c25b9c3d..45288bef 100644 --- a/.forgejo/workflows/prek-checks.yml +++ b/.forgejo/workflows/prek-checks.yml @@ -1,7 +1,11 @@ name: Checks / Prek on: + pull_request: push: + branches: + - main + workflow_dispatch: permissions: contents: read diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 6972c791..b1a26e24 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -3,7 +3,19 @@ concurrency: group: "release-image-${{ github.ref }}" on: + pull_request: + paths-ignore: + - "*.md" + - "**/*.md" + - ".gitlab-ci.yml" + - ".gitignore" + - "renovate.json" + - "pkg/**" + - "docker/**" + - "docs/**" push: + branches: + - main: paths-ignore: - "*.md" - "**/*.md" From 2516e783ba88d54e04896e2a553fcadb547691b7 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sat, 6 Sep 2025 15:55:24 +0100 Subject: [PATCH 2264/2291] ci: Support optional persistent BuildKit endpoints in Docker builds Allows us to use runners with persistent BuildKit containers for improved caching and faster build times. Falls back to standard docker-container driver when BUILDKIT_ENDPOINT environment variable is not set. --- .forgejo/workflows/release-image.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index b1a26e24..2b3d481f 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -105,6 +105,10 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + with: + # Use persistent BuildKit if BUILDKIT_ENDPOINT is set (e.g. tcp://buildkit:8125) + driver: ${{ env.BUILDKIT_ENDPOINT != '' && 'remote' || 'docker-container' }} + endpoint: ${{ env.BUILDKIT_ENDPOINT || '' }} - name: Set up QEMU uses: docker/setup-qemu-action@v3 # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. @@ -262,6 +266,10 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + with: + # Use persistent BuildKit if BUILDKIT_ENDPOINT is set (e.g. tcp://buildkit:8125) + driver: ${{ env.BUILDKIT_ENDPOINT != '' && 'remote' || 'docker-container' }} + endpoint: ${{ env.BUILDKIT_ENDPOINT || '' }} - name: Extract metadata (tags) for Docker id: meta From 6f19931c5b25f96fae0f99fd938a0afb2da7620a Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 31 Aug 2025 01:55:12 +0100 Subject: [PATCH 2265/2291] chore(deps): Upgrade minor incompatible dependencies --- Cargo.lock | 268 +++++++++++++++++++++++++++++++++-------------------- Cargo.toml | 24 ++--- 2 files changed, 181 insertions(+), 111 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3962c31..322956a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -714,12 +714,12 @@ dependencies = [ [[package]] name = "cargo_toml" -version = "0.21.0" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fbd1fe9db3ebf71b89060adaf7b0504c2d6a425cf061313099547e382c2e472" +checksum = "374b7c592d9c00c1f4972ea58390ac6b18cbb6ab79011f3bdc90a0b82ca06b77" dependencies = [ "serde", - "toml", + "toml 0.9.5", ] [[package]] @@ -897,9 +897,9 @@ dependencies = [ "const-str", "hardened_malloc-rs", "log", - "opentelemetry", + "opentelemetry 0.30.0", "opentelemetry-jaeger", - "opentelemetry_sdk", + "opentelemetry_sdk 0.30.0", "sentry", "sentry-tower", "sentry-tracing", @@ -1026,7 +1026,7 @@ dependencies = [ "tikv-jemallocator", "tokio", "tokio-metrics", - "toml", + "toml 0.9.5", "tracing", "tracing-core", "tracing-subscriber", @@ -1285,9 +1285,9 @@ checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" [[package]] name = "crokey" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5282b45c96c5978c8723ea83385cb9a488b64b7d175733f48d07bf9da514a863" +checksum = "51360853ebbeb3df20c76c82aecf43d387a62860f1a59ba65ab51f00eea85aad" dependencies = [ "crokey-proc_macros", "crossterm", @@ -1298,9 +1298,9 @@ dependencies = [ [[package]] name = "crokey-proc_macros" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ea0218d3fedf0797fa55676f1964ef5d27103d41ed0281b4bbd2a6e6c3d8d28" +checksum = "3bf1a727caeb5ee5e0a0826a97f205a9cf84ee964b0b48239fef5214a00ae439" dependencies = [ "crossterm", "proc-macro2", @@ -1706,7 +1706,7 @@ dependencies = [ "atomic", "pear", "serde", - "toml", + "toml 0.8.23", "uncased", "version_check", ] @@ -3045,9 +3045,9 @@ checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" [[package]] name = "nix" -version = "0.29.0" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" dependencies = [ "bitflags 2.9.1", "cfg-if", @@ -3229,59 +3229,67 @@ checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" [[package]] name = "opentelemetry" -version = "0.21.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" +checksum = "1b69a91d4893e713e06f724597ad630f1fa76057a5e1026c0ca67054a9032a76" dependencies = [ "futures-core", "futures-sink", - "indexmap 2.10.0", "js-sys", "once_cell", "pin-project-lite", "thiserror 1.0.69", - "urlencoding", +] + +[[package]] +name = "opentelemetry" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf416e4cb72756655126f7dd7bb0af49c674f4c1b9903e80c009e0c37e552e6" +dependencies = [ + "futures-core", + "futures-sink", + "js-sys", + "pin-project-lite", + "thiserror 2.0.12", + "tracing", ] [[package]] name = "opentelemetry-jaeger" -version = "0.20.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e617c66fd588e40e0dbbd66932fdc87393095b125d4459b1a3a10feb1712f8a1" +checksum = "501b471b67b746d9a07d4c29f8be00f952d1a2eca356922ede0098cbaddff19f" dependencies = [ "async-trait", "futures-core", "futures-util", - "opentelemetry", + "opentelemetry 0.23.0", "opentelemetry-semantic-conventions", - "opentelemetry_sdk", + "opentelemetry_sdk 0.23.0", "thrift", "tokio", ] [[package]] name = "opentelemetry-semantic-conventions" -version = "0.13.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5774f1ef1f982ef2a447f6ee04ec383981a3ab99c8e77a1a7b30182e65bbc84" -dependencies = [ - "opentelemetry", -] +checksum = "1869fb4bb9b35c5ba8a1e40c9b128a7b4c010d07091e864a29da19e4fe2ca4d7" [[package]] name = "opentelemetry_sdk" -version = "0.21.2" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f16aec8a98a457a52664d69e0091bac3a0abd18ead9b641cb00202ba4e0efe4" +checksum = "ae312d58eaa90a82d2e627fd86e075cf5230b3f11794e2ed74199ebbe572d4fd" dependencies = [ "async-trait", - "crossbeam-channel", "futures-channel", "futures-executor", "futures-util", - "glob", + "lazy_static", "once_cell", - "opentelemetry", + "opentelemetry 0.23.0", "ordered-float 4.6.0", "percent-encoding", "rand 0.8.5", @@ -3290,6 +3298,24 @@ dependencies = [ "tokio-stream", ] +[[package]] +name = "opentelemetry_sdk" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11f644aa9e5e31d11896e024305d7e3c98a88884d9f8919dbf37a9991bc47a4b" +dependencies = [ + "futures-channel", + "futures-executor", + "futures-util", + "opentelemetry 0.30.0", + "percent-encoding", + "rand 0.9.2", + "serde_json", + "thiserror 2.0.12", + "tokio", + "tokio-stream", +] + [[package]] name = "ordered-float" version = "2.10.1" @@ -3713,7 +3739,7 @@ dependencies = [ "thiserror 2.0.12", "tokio", "tracing", - "web-time 1.1.0", + "web-time", ] [[package]] @@ -3734,7 +3760,7 @@ dependencies = [ "thiserror 2.0.12", "tinyvec", "tracing", - "web-time 1.1.0", + "web-time", ] [[package]] @@ -4072,7 +4098,7 @@ dependencies = [ "ruma-identity-service-api", "ruma-push-gateway-api", "ruma-signatures", - "web-time 1.1.0", + "web-time", ] [[package]] @@ -4107,7 +4133,7 @@ dependencies = [ "serde_json", "thiserror 2.0.12", "url", - "web-time 1.1.0", + "web-time", ] [[package]] @@ -4138,7 +4164,7 @@ dependencies = [ "tracing", "url", "uuid", - "web-time 1.1.0", + "web-time", "wildmatch", ] @@ -4163,7 +4189,7 @@ dependencies = [ "thiserror 2.0.12", "tracing", "url", - "web-time 1.1.0", + "web-time", "wildmatch", ] @@ -4220,7 +4246,7 @@ dependencies = [ "ruma-identifiers-validation", "serde", "syn 2.0.104", - "toml", + "toml 0.8.23", ] [[package]] @@ -4415,7 +4441,7 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" dependencies = [ - "web-time 1.1.0", + "web-time", "zeroize", ] @@ -4560,9 +4586,9 @@ checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" [[package]] name = "sentry" -version = "0.37.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "255914a8e53822abd946e2ce8baa41d4cded6b8e938913b7f7b9da5b7ab44335" +checksum = "989425268ab5c011e06400187eed6c298272f8ef913e49fcadc3fda788b45030" dependencies = [ "httpdate", "reqwest", @@ -4577,26 +4603,24 @@ dependencies = [ "sentry-tracing", "tokio", "ureq", - "webpki-roots 0.26.11", ] [[package]] name = "sentry-backtrace" -version = "0.37.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00293cd332a859961f24fd69258f7e92af736feaeb91020cff84dac4188a4302" +checksum = "68e299dd3f7bcf676875eee852c9941e1d08278a743c32ca528e2debf846a653" dependencies = [ "backtrace", - "once_cell", "regex", "sentry-core", ] [[package]] name = "sentry-contexts" -version = "0.37.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "961990f9caa76476c481de130ada05614cd7f5aa70fb57c2142f0e09ad3fb2aa" +checksum = "fac0c5d6892cd4c414492fc957477b620026fb3411fca9fa12774831da561c88" dependencies = [ "hostname", "libc", @@ -4608,33 +4632,32 @@ dependencies = [ [[package]] name = "sentry-core" -version = "0.37.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a6409d845707d82415c800290a5d63be5e3df3c2e417b0997c60531dfbd35ef" +checksum = "deaa38b94e70820ff3f1f9db3c8b0aef053b667be130f618e615e0ff2492cbcc" dependencies = [ - "once_cell", - "rand 0.8.5", + "rand 0.9.2", "sentry-types", "serde", "serde_json", + "url", ] [[package]] name = "sentry-debug-images" -version = "0.37.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71ab5df4f3b64760508edfe0ba4290feab5acbbda7566a79d72673065888e5cc" +checksum = "00950648aa0d371c7f57057434ad5671bd4c106390df7e7284739330786a01b6" dependencies = [ "findshlibs", - "once_cell", "sentry-core", ] [[package]] name = "sentry-log" -version = "0.37.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693841da8dfb693af29105edfbea1d91348a13d23dd0a5d03761eedb9e450c46" +checksum = "670f08baf70058926b0fa60c8f10218524ef0cb1a1634b0388a4123bdec6288c" dependencies = [ "log", "sentry-core", @@ -4642,9 +4665,9 @@ dependencies = [ [[package]] name = "sentry-panic" -version = "0.37.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "609b1a12340495ce17baeec9e08ff8ed423c337c1a84dffae36a178c783623f3" +checksum = "2b7a23b13c004873de3ce7db86eb0f59fe4adfc655a31f7bbc17fd10bacc9bfe" dependencies = [ "sentry-backtrace", "sentry-core", @@ -4652,9 +4675,9 @@ dependencies = [ [[package]] name = "sentry-tower" -version = "0.37.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b98005537e38ee3bc10e7d36e7febe9b8e573d03f2ddd85fcdf05d21f9abd6d" +checksum = "4a303d0127d95ae928a937dcc0886931d28b4186e7338eea7d5786827b69b002" dependencies = [ "http", "pin-project", @@ -4666,10 +4689,11 @@ dependencies = [ [[package]] name = "sentry-tracing" -version = "0.37.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f4e86402d5c50239dc7d8fd3f6d5e048221d5fcb4e026d8d50ab57fe4644cb" +checksum = "fac841c7050aa73fc2bec8f7d8e9cb1159af0b3095757b99820823f3e54e5080" dependencies = [ + "bitflags 2.9.1", "sentry-backtrace", "sentry-core", "tracing-core", @@ -4678,16 +4702,16 @@ dependencies = [ [[package]] name = "sentry-types" -version = "0.37.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3f117b8755dbede8260952de2aeb029e20f432e72634e8969af34324591631" +checksum = "e477f4d4db08ddb4ab553717a8d3a511bc9e81dde0c808c680feacbb8105c412" dependencies = [ "debugid", "hex", - "rand 0.8.5", + "rand 0.9.2", "serde", "serde_json", - "thiserror 1.0.69", + "thiserror 2.0.12", "time", "url", "uuid", @@ -4767,6 +4791,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40734c41988f7306bb04f0ecf60ec0f3f1caa34290e4e8ea471dcd3346483b83" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -5061,7 +5094,7 @@ dependencies = [ "cfg-expr", "heck", "pkg-config", - "toml", + "toml 0.8.23", "version-compare", ] @@ -5090,9 +5123,9 @@ dependencies = [ [[package]] name = "termimad" -version = "0.31.3" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7301d9c2c4939c97f25376b70d3c13311f8fefdee44092fc361d2a98adc2cbb6" +checksum = "68ff5ca043d65d4ea43b65cdb4e3aba119657d0d12caf44f93212ec3168a8e20" dependencies = [ "coolor", "crokey", @@ -5396,11 +5429,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" dependencies = [ "serde", - "serde_spanned", - "toml_datetime", + "serde_spanned 0.6.9", + "toml_datetime 0.6.11", "toml_edit", ] +[[package]] +name = "toml" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75129e1dc5000bfbaa9fee9d1b21f974f9fbad9daec557a521ee6e080825f6e8" +dependencies = [ + "indexmap 2.10.0", + "serde", + "serde_spanned 1.0.0", + "toml_datetime 0.7.0", + "toml_parser", + "toml_writer", + "winnow", +] + [[package]] name = "toml_datetime" version = "0.6.11" @@ -5410,6 +5458,15 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_datetime" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bade1c3e902f58d73d3f294cd7f20391c1cb2fbcb643b73566bc773971df91e3" +dependencies = [ + "serde", +] + [[package]] name = "toml_edit" version = "0.22.27" @@ -5418,18 +5475,33 @@ checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap 2.10.0", "serde", - "serde_spanned", - "toml_datetime", + "serde_spanned 0.6.9", + "toml_datetime 0.6.11", "toml_write", "winnow", ] +[[package]] +name = "toml_parser" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b551886f449aa90d4fe2bdaa9f4a2577ad2dde302c61ecf262d80b116db95c10" +dependencies = [ + "winnow", +] + [[package]] name = "toml_write" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" +[[package]] +name = "toml_writer" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc842091f2def52017664b53082ecbbeb5c7731092bad69d2c63050401dfd64" + [[package]] name = "tonic" version = "0.12.3" @@ -5593,20 +5665,20 @@ dependencies = [ [[package]] name = "tracing-opentelemetry" -version = "0.22.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c67ac25c5407e7b961fafc6f7e9aa5958fd297aada2d20fa2ae1737357e55596" +checksum = "ddcf5959f39507d0d04d6413119c04f33b623f4f951ebcbdddddfad2d0623a9c" dependencies = [ "js-sys", "once_cell", - "opentelemetry", - "opentelemetry_sdk", + "opentelemetry 0.30.0", + "opentelemetry_sdk 0.30.0", "smallvec", "tracing", "tracing-core", "tracing-log", "tracing-subscriber", - "web-time 0.2.4", + "web-time", ] [[package]] @@ -5727,17 +5799,31 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "2.12.1" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" +checksum = "00432f493971db5d8e47a65aeb3b02f8226b9b11f1450ff86bb772776ebadd70" dependencies = [ "base64 0.22.1", "log", - "once_cell", + "percent-encoding", "rustls 0.23.29", + "rustls-pemfile 2.2.0", "rustls-pki-types", - "url", - "webpki-roots 0.26.11", + "ureq-proto", + "utf-8", + "webpki-roots 1.0.2", +] + +[[package]] +name = "ureq-proto" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe120bb823a0061680e66e9075942fcdba06d46551548c2c259766b9558bc9a" +dependencies = [ + "base64 0.22.1", + "http", + "httparse", + "log", ] [[package]] @@ -5752,12 +5838,6 @@ dependencies = [ "serde", ] -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - [[package]] name = "utf-8" version = "0.7.6" @@ -5928,16 +6008,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "web-time" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa30049b1c872b72c89866d458eae9f20380ab280ffd1b1e18df2d3e2d98cfe0" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "web-time" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index e2af2d94..fe388b4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,12 +51,12 @@ version = "0.6.2" version = "0.2.9" [workspace.dependencies.cargo_toml] -version = "0.21" +version = "0.22" default-features = false features = ["features"] [workspace.dependencies.toml] -version = "0.8.14" +version = "0.9.5" default-features = false features = ["parse"] @@ -411,25 +411,25 @@ default-features = false # optional opentelemetry, performance measurements, flamegraphs, etc for performance measurements and monitoring [workspace.dependencies.opentelemetry] -version = "0.21.0" +version = "0.30.0" [workspace.dependencies.tracing-flame] version = "0.2.0" [workspace.dependencies.tracing-opentelemetry] -version = "0.22.0" +version = "0.31.0" [workspace.dependencies.opentelemetry_sdk] -version = "0.21.2" +version = "0.30.0" features = ["rt-tokio"] [workspace.dependencies.opentelemetry-jaeger] -version = "0.20.0" +version = "0.22.0" features = ["rt-tokio"] # optional sentry metrics for crash/panic reporting [workspace.dependencies.sentry] -version = "0.37.0" +version = "0.42.0" default-features = false features = [ "backtrace", @@ -445,9 +445,9 @@ features = [ ] [workspace.dependencies.sentry-tracing] -version = "0.37.0" +version = "0.42.0" [workspace.dependencies.sentry-tower] -version = "0.37.0" +version = "0.42.0" # jemalloc usage [workspace.dependencies.tikv-jemalloc-sys] @@ -476,7 +476,7 @@ features = ["use_std"] version = "0.4" [workspace.dependencies.nix] -version = "0.29.0" +version = "0.30.1" default-features = false features = ["resource"] @@ -498,7 +498,7 @@ version = "0.4.3" default-features = false [workspace.dependencies.termimad] -version = "0.31.2" +version = "0.34.0" default-features = false [workspace.dependencies.checked_ops] @@ -536,7 +536,7 @@ version = "0.2" version = "0.2" [workspace.dependencies.minicbor] -version = "0.26.3" +version = "0.26.5" features = ["std"] [workspace.dependencies.minicbor-serde] From 1d7dda6cf55c8843ea8869a1f482633b2b66fc2f Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sun, 31 Aug 2025 03:01:06 +0100 Subject: [PATCH 2266/2291] chore: Upgrade ctor, cbor --- Cargo.lock | 604 +++++++++++++++++++++----------------- Cargo.toml | 6 +- src/admin/Cargo.toml | 1 + src/admin/mod.rs | 2 + src/api/Cargo.toml | 1 + src/api/client/message.rs | 2 +- src/database/Cargo.toml | 1 + src/database/mod.rs | 2 + src/macros/rustc.rs | 4 +- src/main/Cargo.toml | 1 + src/main/mod.rs | 1 + src/router/Cargo.toml | 1 + src/router/mod.rs | 1 + src/service/Cargo.toml | 1 + src/service/mod.rs | 1 + 15 files changed, 353 insertions(+), 276 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 322956a0..3c24b178 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,9 +52,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.19" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" dependencies = [ "anstyle", "anstyle-parse", @@ -82,35 +82,35 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "anstyle-wincon" -version = "3.0.9" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "anyhow" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" +checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" [[package]] name = "arbitrary" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223" +checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" [[package]] name = "arc-swap" @@ -126,7 +126,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -183,7 +183,7 @@ dependencies = [ "rustc-hash 2.1.1", "serde", "serde_derive", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -256,11 +256,13 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.4.27" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddb939d66e4ae03cee6091612804ba446b12878410cfa17f785f4dd67d4014e8" +checksum = "5bee399cc3a623ec5a2db2c5b90ee0190a2260241fbe0c023ac8f7bab426aaf8" dependencies = [ "brotli", + "compression-codecs", + "compression-core", "flate2", "futures-core", "memchr", @@ -289,18 +291,18 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "async-trait" -version = "0.1.88" +version = "0.1.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -340,9 +342,9 @@ dependencies = [ [[package]] name = "avif-serialize" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ea8ef51aced2b9191c08197f55450d830876d9933f8f48a429b354f1d496b42" +checksum = "47c8fbc0f831f4519fe8b810b6a7a91410ec83031b8233f730a0480029f6a23f" dependencies = [ "arrayvec", ] @@ -472,7 +474,7 @@ dependencies = [ "hyper", "hyper-util", "pin-project-lite", - "rustls 0.23.29", + "rustls 0.23.31", "rustls-pemfile 2.2.0", "rustls-pki-types", "tokio", @@ -491,7 +493,7 @@ dependencies = [ "http", "http-body-util", "pin-project", - "rustls 0.23.29", + "rustls 0.23.31", "tokio", "tokio-rustls 0.26.2", "tokio-util", @@ -547,7 +549,7 @@ version = "0.69.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "cexpr", "clang-sys", "itertools 0.12.1", @@ -560,7 +562,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.104", + "syn 2.0.106", "which", ] @@ -570,7 +572,7 @@ version = "0.72.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f72209734318d0b619a5e0f5129918b848c416e122a3c4ce054e03cb87b726f" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "cexpr", "clang-sys", "itertools 0.13.0", @@ -579,14 +581,14 @@ dependencies = [ "regex", "rustc-hash 2.1.1", "shlex", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "bit_field" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" +checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6" [[package]] name = "bitflags" @@ -596,9 +598,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.1" +version = "2.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d" [[package]] name = "bitstream-io" @@ -635,9 +637,9 @@ dependencies = [ [[package]] name = "brotli" -version = "8.0.1" +version = "8.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9991eea70ea4f293524138648e41ee89b0b2b12ddef3b255effa43c8056e0e0d" +checksum = "4bd8b9603c7aa97359dbd97ecf258968c95f3adddd6db2f7e7a5bef101c84560" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -674,9 +676,9 @@ checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" [[package]] name = "bytemuck" -version = "1.23.1" +version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422" +checksum = "3995eaeebcdf32f91f980d360f78732ddc061097ab4e39991ae7a6ace9194677" [[package]] name = "byteorder" @@ -724,9 +726,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.30" +version = "1.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" +checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc" dependencies = [ "jobserver", "libc", @@ -754,9 +756,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "cfg_aliases" @@ -795,9 +797,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.41" +version = "4.5.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9" +checksum = "2c5e4fcf9c21d2e544ca1ee9d8552de13019a42aa7dbf32747fa7aaf1df76e57" dependencies = [ "clap_builder", "clap_derive", @@ -814,9 +816,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.41" +version = "4.5.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d" +checksum = "fecb53a0e6fcfb055f686001bc2e2592fa527efaf38dbe81a6a9563562e57d41" dependencies = [ "anstream", "anstyle", @@ -826,14 +828,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.41" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" +checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -844,9 +846,9 @@ checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "clap_mangen" -version = "0.2.28" +version = "0.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2fb6d3f935bbb9819391528b0e7cf655e78a0bc7a7c3d227211a1d24fc11db1" +checksum = "27b4c3c54b30f0d9adcb47f25f61fcce35c4dd8916638c6b82fbd5f4fb4179e2" dependencies = [ "clap", "roff", @@ -873,6 +875,28 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +[[package]] +name = "compression-codecs" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7eea68f0e02c2b0aa8856e9a9478444206d4b6828728e7b0697c0f8cca265cb" +dependencies = [ + "brotli", + "compression-core", + "flate2", + "futures-core", + "memchr", + "pin-project-lite", + "zstd", + "zstd-safe", +] + +[[package]] +name = "compression-core" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e47641d3deaf41fb1538ac1f54735925e275eaf3bf4d55c81b137fba797e5cbb" + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -895,6 +919,7 @@ dependencies = [ "conduwuit_service", "console-subscriber", "const-str", + "ctor", "hardened_malloc-rs", "log", "opentelemetry 0.30.0", @@ -923,6 +948,7 @@ dependencies = [ "conduwuit_macros", "conduwuit_service", "const-str", + "ctor", "futures", "log", "ruma", @@ -946,6 +972,7 @@ dependencies = [ "conduwuit_core", "conduwuit_service", "const-str", + "ctor", "futures", "hmac", "http", @@ -1020,7 +1047,7 @@ dependencies = [ "serde_yaml", "smallstr", "smallvec", - "thiserror 2.0.12", + "thiserror 2.0.16", "tikv-jemalloc-ctl", "tikv-jemalloc-sys", "tikv-jemallocator", @@ -1040,6 +1067,7 @@ dependencies = [ "async-channel", "conduwuit_core", "const-str", + "ctor", "futures", "log", "minicbor", @@ -1058,7 +1086,7 @@ dependencies = [ "itertools 0.14.0", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1076,6 +1104,7 @@ dependencies = [ "conduwuit_service", "conduwuit_web", "const-str", + "ctor", "futures", "http", "http-body-util", @@ -1083,7 +1112,7 @@ dependencies = [ "hyper-util", "log", "ruma", - "rustls 0.23.29", + "rustls 0.23.31", "sd-notify", "sentry", "sentry-tower", @@ -1106,6 +1135,7 @@ dependencies = [ "conduwuit_core", "conduwuit_database", "const-str", + "ctor", "either", "futures", "hickory-resolver 0.25.2", @@ -1144,7 +1174,7 @@ dependencies = [ "conduwuit_service", "futures", "rand 0.8.5", - "thiserror 2.0.12", + "thiserror 2.0.16", "tracing", ] @@ -1195,15 +1225,18 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "const-str" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "041fbfcf8e7054df725fb9985297e92422cdc80fcf313665f5ca3d761bb63f4c" +checksum = "451d0640545a0553814b4c646eb549343561618838e9b42495f466131fe3ad49" [[package]] name = "const_panic" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98d1483e98c9d67f341ab4b3915cfdc54740bd6f5cccc9226ee0535d86aa8fb" +checksum = "bb8a602185c3c95b52f86dc78e55a6df9a287a7a93ddbcf012509930880cf879" +dependencies = [ + "typewit", +] [[package]] name = "convert_case" @@ -1306,7 +1339,7 @@ dependencies = [ "proc-macro2", "quote", "strict", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1371,7 +1404,7 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "crossterm_winapi", "derive_more", "document-features", @@ -1411,14 +1444,20 @@ dependencies = [ [[package]] name = "ctor" -version = "0.2.9" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a2785755761f3ddc1492979ce1e48d2c00d09311c39e4466429188f3dd6501" +checksum = "67773048316103656a637612c4a62477603b777d91d9c62ff2290f9cde178fdb" dependencies = [ - "quote", - "syn 2.0.104", + "ctor-proc-macro", + "dtor", ] +[[package]] +name = "ctor-proc-macro" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2931af7e13dc045d8e9d26afccc6fa115d64e115c9c84b1166288b46f6782c2" + [[package]] name = "curve25519-dalek" version = "4.1.3" @@ -1443,7 +1482,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1525,7 +1564,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1547,7 +1586,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1559,6 +1598,21 @@ dependencies = [ "litrs", ] +[[package]] +name = "dtor" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e58a0764cddb55ab28955347b45be00ade43d4d6f3ba4bf3dc354e4ec9432934" +dependencies = [ + "dtor-proc-macro", +] + +[[package]] +name = "dtor-proc-macro" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f678cf4a922c215c63e0de95eb1ff08a958a81d47e485cf9da1e27bf6305cfa5" + [[package]] name = "dunce" version = "1.0.5" @@ -1608,7 +1662,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1628,7 +1682,7 @@ checksum = "44f23cf4b44bfce11a86ace86f8a73ffdec849c9fd00a386a53d278bd9e81fb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1747,9 +1801,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "form_urlencoded" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" dependencies = [ "percent-encoding", ] @@ -1846,7 +1900,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1881,9 +1935,9 @@ dependencies = [ [[package]] name = "generator" -version = "0.8.5" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d18470a76cb7f8ff746cf1f7470914f900252ec36bbc40b569d74b1258446827" +checksum = "605183a538e3e2a9c1038635cc5c2d194e2ee8fd0d1b66b8349fad7dbacce5a2" dependencies = [ "cc", "cfg-if", @@ -1926,7 +1980,7 @@ dependencies = [ "js-sys", "libc", "r-efi", - "wasi 0.14.2+wasi-0.2.4", + "wasi 0.14.3+wasi-0.2.4", "wasm-bindgen", ] @@ -1948,15 +2002,15 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "glob" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" [[package]] name = "h2" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17da50a276f1e01e0ba6c029e47b7100754904ee8a278f886546e98575380785" +checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386" dependencies = [ "atomic-waker", "bytes", @@ -1964,7 +2018,7 @@ dependencies = [ "futures-core", "futures-sink", "http", - "indexmap 2.10.0", + "indexmap 2.11.0", "slab", "tokio", "tokio-util", @@ -1995,9 +2049,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.15.4" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" [[package]] name = "hdrhistogram" @@ -2097,7 +2151,7 @@ dependencies = [ "rand 0.9.2", "ring 0.17.14", "serde", - "thiserror 2.0.12", + "thiserror 2.0.16", "tinyvec", "tokio", "tracing", @@ -2142,7 +2196,7 @@ dependencies = [ "resolv-conf", "serde", "smallvec", - "thiserror 2.0.12", + "thiserror 2.0.16", "tokio", "tracing", ] @@ -2187,7 +2241,7 @@ dependencies = [ "markup5ever", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -2253,13 +2307,14 @@ checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f" [[package]] name = "hyper" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" +checksum = "eb3aa54a13a0dfe7fbe3a59e0c76093041720fdc77b110cc0fc260fafb4dc51e" dependencies = [ + "atomic-waker", "bytes", "futures-channel", - "futures-util", + "futures-core", "h2", "http", "http-body", @@ -2267,6 +2322,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", + "pin-utils", "smallvec", "tokio", "want", @@ -2281,7 +2337,7 @@ dependencies = [ "http", "hyper", "hyper-util", - "rustls 0.23.29", + "rustls 0.23.31", "rustls-native-certs 0.8.1", "rustls-pki-types", "tokio", @@ -2316,7 +2372,7 @@ dependencies = [ "hyper", "libc", "pin-project-lite", - "socket2", + "socket2 0.5.10", "tokio", "tower-service", "tracing", @@ -2410,9 +2466,9 @@ dependencies = [ [[package]] name = "idna" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" dependencies = [ "idna_adapter", "smallvec", @@ -2454,9 +2510,9 @@ dependencies = [ [[package]] name = "image-webp" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6970fe7a5300b4b42e62c52efa0187540a5bef546c60edaf554ef595d2e6f0b" +checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3" dependencies = [ "byteorder-lite", "quick-error", @@ -2480,12 +2536,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" +checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" dependencies = [ "equivalent", - "hashbrown 0.15.4", + "hashbrown 0.15.5", "serde", ] @@ -2509,16 +2565,16 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "io-uring" -version = "0.7.9" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d93587f37623a1a17d94ef2bc9ada592f5465fe7732084ab7beefabe5c77c0c4" +checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "cfg-if", "libc", ] @@ -2543,7 +2599,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" dependencies = [ - "socket2", + "socket2 0.5.10", "widestring", "windows-sys 0.48.0", "winreg", @@ -2596,9 +2652,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "jobserver" -version = "0.1.33" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" dependencies = [ "getrandom 0.3.3", "libc", @@ -2678,7 +2734,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -2738,9 +2794,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.174" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libfuzzer-sys" @@ -2759,7 +2815,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if", - "windows-targets 0.53.2", + "windows-targets 0.53.3", ] [[package]] @@ -2799,9 +2855,9 @@ checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" [[package]] name = "litrs" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" +checksum = "f5e54036fe321fd421e10d732f155734c4e4afd610dd556d9a82833ab3ee0bed" [[package]] name = "lock_api" @@ -2953,29 +3009,29 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "minicbor" -version = "0.26.5" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a309f581ade7597820083bc275075c4c6986e57e53f8d26f88507cfefc8c987" +checksum = "4f182275033b808ede9427884caa8e05fa7db930801759524ca7925bd8aa7a82" dependencies = [ "minicbor-derive", ] [[package]] name = "minicbor-derive" -version = "0.16.2" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9882ef5c56df184b8ffc107fc6c61e33ee3a654b021961d790a78571bb9d67a" +checksum = "b17290c95158a760027059fe3f511970d6857e47ff5008f9e09bffe3d3e1c6af" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "minicbor-serde" -version = "0.4.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54e45e8beeefea1b8b6f52fa188a5b6ea3746c2885606af8d4d8bf31cee633fb" +checksum = "0bbf243b8cc68a7a76473b14328d3546fb002ae3d069227794520e9181003de9" dependencies = [ "minicbor", "serde", @@ -3049,7 +3105,7 @@ version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "cfg-if", "cfg_aliases", "libc", @@ -3134,7 +3190,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3251,7 +3307,7 @@ dependencies = [ "futures-sink", "js-sys", "pin-project-lite", - "thiserror 2.0.12", + "thiserror 2.0.16", "tracing", ] @@ -3311,7 +3367,7 @@ dependencies = [ "percent-encoding", "rand 0.9.2", "serde_json", - "thiserror 2.0.12", + "thiserror 2.0.16", "tokio", "tokio-stream", ] @@ -3421,14 +3477,14 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "percent-encoding" -version = "2.3.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "petgraph" @@ -3437,7 +3493,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.10.0", + "indexmap 2.11.0", ] [[package]] @@ -3495,7 +3551,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3533,7 +3589,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3af6b589e163c5a788fab00ce0c0366f6efbb9959c2f9874b224936af7fce7e1" dependencies = [ "base64 0.22.1", - "indexmap 2.10.0", + "indexmap 2.11.0", "quick-xml", "serde", "time", @@ -3560,9 +3616,9 @@ checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" [[package]] name = "potential_utf" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5a7c30837279ca13e7c867e9e40053bc68740f988cb07f7ca6df43cc734b585" +checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a" dependencies = [ "zerovec", ] @@ -3590,12 +3646,12 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "prettyplease" -version = "0.2.36" +version = "0.2.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff24dfcda44452b9816fff4cd4227e1bb73ff5a2f1bc1105aa92fb8565ce44d2" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3609,9 +3665,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] @@ -3624,7 +3680,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "version_check", "yansi", ] @@ -3645,7 +3701,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52717f9a02b6965224f95ca2a81e2e0c5c43baacd28ca057577988930b6c3d5b" dependencies = [ "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3668,7 +3724,7 @@ dependencies = [ "itertools 0.14.0", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3686,7 +3742,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e8bbe1a966bd2f362681a44f6edce3c2310ac21e4d5067a6e7ec396297a6ea0" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "memchr", "pulldown-cmark-escape", "unicase", @@ -3715,18 +3771,18 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quick-xml" -version = "0.38.0" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8927b0664f5c5a98265138b7e3f90aa19a6b21353182469ace36d4ac527b7b1b" +checksum = "42a232e7487fc2ef313d96dde7948e7a3c05101870d8985e4fd8d26aedd27b89" dependencies = [ "memchr", ] [[package]] name = "quinn" -version = "0.11.8" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626214629cda6781b6dc1d316ba307189c85ba657213ce642d9c77670f8202c8" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" dependencies = [ "bytes", "cfg_aliases", @@ -3734,9 +3790,9 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash 2.1.1", - "rustls 0.23.29", - "socket2", - "thiserror 2.0.12", + "rustls 0.23.31", + "socket2 0.6.0", + "thiserror 2.0.16", "tokio", "tracing", "web-time", @@ -3744,9 +3800,9 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.12" +version = "0.11.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49df843a9161c85bb8aae55f101bc0bac8bcafd637a620d9122fd7e0b2f7422e" +checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" dependencies = [ "bytes", "getrandom 0.3.3", @@ -3754,10 +3810,10 @@ dependencies = [ "rand 0.9.2", "ring 0.17.14", "rustc-hash 2.1.1", - "rustls 0.23.29", + "rustls 0.23.31", "rustls-pki-types", "slab", - "thiserror 2.0.12", + "thiserror 2.0.16", "tinyvec", "tracing", "web-time", @@ -3765,16 +3821,16 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.13" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcebb1209ee276352ef14ff8732e24cc2b02bbac986cd74a4c81bcb2f9881970" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" dependencies = [ "cfg_aliases", "libc", "once_cell", - "socket2", + "socket2 0.6.0", "tracing", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -3903,9 +3959,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" dependencies = [ "either", "rayon-core", @@ -3913,9 +3969,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -3923,9 +3979,9 @@ dependencies = [ [[package]] name = "recaptcha-verify" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71e3be7b2e46e24637ac96b0c9f70070f188652018573f36f4e511dcad09738a" +checksum = "0d694033c2b0abdbb8893edfb367f16270e790be4a67e618206d811dbe4efee4" dependencies = [ "reqwest", "serde", @@ -3934,23 +3990,23 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.15" +version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8af0dde094006011e6a740d4879319439489813bd0bcdc7d821beaeeff48ec" +checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", ] [[package]] name = "regex" -version = "1.11.1" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.9", - "regex-syntax 0.8.5", + "regex-automata 0.4.10", + "regex-syntax 0.8.6", ] [[package]] @@ -3964,13 +4020,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.5", + "regex-syntax 0.8.6", ] [[package]] @@ -3981,9 +4037,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" [[package]] name = "reqwest" @@ -4013,7 +4069,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "quinn", - "rustls 0.23.29", + "rustls 0.23.31", "rustls-native-certs 0.8.1", "rustls-pemfile 2.2.0", "rustls-pki-types", @@ -4131,7 +4187,7 @@ dependencies = [ "serde", "serde_html_form", "serde_json", - "thiserror 2.0.12", + "thiserror 2.0.16", "url", "web-time", ] @@ -4147,7 +4203,7 @@ dependencies = [ "form_urlencoded", "getrandom 0.2.16", "http", - "indexmap 2.10.0", + "indexmap 2.11.0", "js_int", "konst", "percent-encoding", @@ -4159,7 +4215,7 @@ dependencies = [ "serde_html_form", "serde_json", "smallvec", - "thiserror 2.0.12", + "thiserror 2.0.16", "time", "tracing", "url", @@ -4174,7 +4230,7 @@ version = "0.28.1" source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "as_variant", - "indexmap 2.10.0", + "indexmap 2.11.0", "js_int", "js_option", "percent-encoding", @@ -4186,7 +4242,7 @@ dependencies = [ "serde", "serde_json", "smallvec", - "thiserror 2.0.12", + "thiserror 2.0.16", "tracing", "url", "web-time", @@ -4211,7 +4267,7 @@ dependencies = [ "ruma-events", "serde", "serde_json", - "thiserror 2.0.12", + "thiserror 2.0.16", "tracing", ] @@ -4221,7 +4277,7 @@ version = "0.9.5" source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd#8fb268fa2771dfc3a1c8075ef1246e7c9a0a53fd" dependencies = [ "js_int", - "thiserror 2.0.12", + "thiserror 2.0.16", ] [[package]] @@ -4245,7 +4301,7 @@ dependencies = [ "quote", "ruma-identifiers-validation", "serde", - "syn 2.0.104", + "syn 2.0.106", "toml 0.8.23", ] @@ -4274,7 +4330,7 @@ dependencies = [ "serde_json", "sha2", "subslice", - "thiserror 2.0.12", + "thiserror 2.0.16", ] [[package]] @@ -4305,9 +4361,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" +checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace" [[package]] name = "rustc-hash" @@ -4345,7 +4401,7 @@ version = "0.38.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "errno", "libc", "linux-raw-sys 0.4.15", @@ -4358,7 +4414,7 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "errno", "libc", "linux-raw-sys 0.9.4", @@ -4379,9 +4435,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.29" +version = "0.23.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2491382039b29b9b11ff08b76ff6c97cf287671dbb74f0be44bda389fffe9bd1" +checksum = "c0ebcbd2f03de0fc1122ad9bb24b127a5a6cd51d72604a3f3c50ac459762b6cc" dependencies = [ "aws-lc-rs", "log", @@ -4414,7 +4470,7 @@ dependencies = [ "openssl-probe", "rustls-pki-types", "schannel", - "security-framework 3.2.0", + "security-framework 3.3.0", ] [[package]] @@ -4469,9 +4525,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "rustyline-async" @@ -4482,7 +4538,7 @@ dependencies = [ "futures-util", "pin-project", "thingbuf", - "thiserror 2.0.12", + "thiserror 2.0.16", "unicode-segmentation", "unicode-width 0.2.1", ] @@ -4548,7 +4604,7 @@ version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "core-foundation 0.9.4", "core-foundation-sys", "libc", @@ -4557,11 +4613,11 @@ dependencies = [ [[package]] name = "security-framework" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316" +checksum = "80fb1d92c5028aa318b4b8bd7302a5bfcf48be96a37fc6fc790f806b0004ee0c" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "core-foundation 0.10.1", "core-foundation-sys", "libc", @@ -4592,7 +4648,7 @@ checksum = "989425268ab5c011e06400187eed6c298272f8ef913e49fcadc3fda788b45030" dependencies = [ "httpdate", "reqwest", - "rustls 0.23.29", + "rustls 0.23.31", "sentry-backtrace", "sentry-contexts", "sentry-core", @@ -4693,7 +4749,7 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fac841c7050aa73fc2bec8f7d8e9cb1159af0b3095757b99820823f3e54e5080" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "sentry-backtrace", "sentry-core", "tracing-core", @@ -4711,7 +4767,7 @@ dependencies = [ "rand 0.9.2", "serde", "serde_json", - "thiserror 2.0.12", + "thiserror 2.0.16", "time", "url", "uuid", @@ -4734,7 +4790,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -4744,7 +4800,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d2de91cf02bbc07cde38891769ccd5d4f073d22a40683aa4bc7a95781aaa2c4" dependencies = [ "form_urlencoded", - "indexmap 2.10.0", + "indexmap 2.11.0", "itoa", "ryu", "serde", @@ -4752,9 +4808,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.141" +version = "1.0.143" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3" +checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" dependencies = [ "itoa", "memchr", @@ -4818,7 +4874,7 @@ version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.10.0", + "indexmap 2.11.0", "itoa", "ryu", "serde", @@ -4885,9 +4941,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.5" +version = "1.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" +checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" dependencies = [ "libc", ] @@ -4924,15 +4980,15 @@ checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "slab" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" [[package]] name = "smallstr" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63b1aefdf380735ff8ded0b15f31aab05daf1f70216c01c02a12926badd1df9d" +checksum = "862077b1e764f04c251fe82a2ef562fd78d7cadaeb072ca7c2bcaf7217b1ff3b" dependencies = [ "serde", "smallvec", @@ -4957,6 +5013,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "socket2" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "spin" version = "0.5.2" @@ -5044,9 +5110,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.104" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", @@ -5082,7 +5148,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -5133,7 +5199,7 @@ dependencies = [ "lazy-regex", "minimad", "serde", - "thiserror 2.0.12", + "thiserror 2.0.16", "unicode-width 0.1.14", ] @@ -5158,11 +5224,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.12" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" dependencies = [ - "thiserror-impl 2.0.12", + "thiserror-impl 2.0.16", ] [[package]] @@ -5173,18 +5239,18 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "thiserror-impl" -version = "2.0.12" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -5310,9 +5376,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b3661f17e86524eccd4371ab0429194e0d7c008abb45f7a7495b1719463c71" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" dependencies = [ "tinyvec_macros", ] @@ -5325,9 +5391,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.46.1" +version = "1.47.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" +checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" dependencies = [ "backtrace", "bytes", @@ -5337,10 +5403,10 @@ dependencies = [ "pin-project-lite", "signal-hook-registry", "slab", - "socket2", + "socket2 0.6.0", "tokio-macros", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5351,14 +5417,14 @@ checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "tokio-metrics" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ff82f660c98e4ff60da5eb8fa864a4130f34b56d92d5cd23d6fdfcc14e95fa" +checksum = "7f960dc1df82e5a0cff5a77e986a10ec7bfabf23ff2377922e012af742878e12" dependencies = [ "futures-util", "pin-project-lite", @@ -5382,7 +5448,7 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e727b36a1a0e8b74c376ac2211e40c2c8af09fb4013c60d910495810f008e9b" dependencies = [ - "rustls 0.23.29", + "rustls 0.23.31", "tokio", ] @@ -5411,9 +5477,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.15" +version = "0.7.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df" +checksum = "14307c986784f72ef81c89db7d9e28d6ac26d16213b109ea501696195e6e3ce5" dependencies = [ "bytes", "futures-core", @@ -5440,7 +5506,7 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75129e1dc5000bfbaa9fee9d1b21f974f9fbad9daec557a521ee6e080825f6e8" dependencies = [ - "indexmap 2.10.0", + "indexmap 2.11.0", "serde", "serde_spanned 1.0.0", "toml_datetime 0.7.0", @@ -5473,7 +5539,7 @@ version = "0.22.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ - "indexmap 2.10.0", + "indexmap 2.11.0", "serde", "serde_spanned 0.6.9", "toml_datetime 0.6.11", @@ -5523,7 +5589,7 @@ dependencies = [ "percent-encoding", "pin-project", "prost", - "socket2", + "socket2 0.5.10", "tokio", "tokio-stream", "tower 0.4.13", @@ -5574,7 +5640,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" dependencies = [ "async-compression", - "bitflags 2.9.1", + "bitflags 2.9.3", "bytes", "futures-core", "futures-util", @@ -5619,7 +5685,7 @@ source = "git+https://forgejo.ellis.link/continuwuation/tracing?rev=1e64095a8051 dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -5712,9 +5778,9 @@ checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" [[package]] name = "typewit" -version = "1.12.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97e72ba082eeb9da9dc68ff5a2bf727ef6ce362556e8d29ec1aed3bd05e7d86a" +checksum = "4dd91acc53c592cb800c11c83e8e7ee1d48378d05cfa33b5474f5f80c5b236bf" dependencies = [ "typewit_proc_macros", ] @@ -5806,7 +5872,7 @@ dependencies = [ "base64 0.22.1", "log", "percent-encoding", - "rustls 0.23.29", + "rustls 0.23.31", "rustls-pemfile 2.2.0", "rustls-pki-types", "ureq-proto", @@ -5828,9 +5894,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.4" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" dependencies = [ "form_urlencoded", "idna", @@ -5858,9 +5924,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" +checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" dependencies = [ "getrandom 0.3.3", "js-sys", @@ -5920,11 +5986,11 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" -version = "0.14.2+wasi-0.2.4" +version = "0.14.3+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95" dependencies = [ - "wit-bindgen-rt", + "wit-bindgen", ] [[package]] @@ -5949,7 +6015,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "wasm-bindgen-shared", ] @@ -5984,7 +6050,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6154,7 +6220,7 @@ checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -6165,7 +6231,7 @@ checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -6192,7 +6258,7 @@ checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" dependencies = [ "windows-result", "windows-strings 0.3.1", - "windows-targets 0.53.2", + "windows-targets 0.53.3", ] [[package]] @@ -6255,7 +6321,7 @@ version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ - "windows-targets 0.53.2", + "windows-targets 0.53.3", ] [[package]] @@ -6291,10 +6357,11 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.53.2" +version = "0.53.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" dependencies = [ + "windows-link", "windows_aarch64_gnullvm 0.53.0", "windows_aarch64_msvc 0.53.0", "windows_i686_gnu 0.53.0", @@ -6454,9 +6521,9 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "winnow" -version = "0.7.12" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3edebf492c8125044983378ecb5766203ad3b4c2f7a922bd7dd207f6d443e95" +checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" dependencies = [ "memchr", ] @@ -6472,13 +6539,10 @@ dependencies = [ ] [[package]] -name = "wit-bindgen-rt" -version = "0.39.0" +name = "wit-bindgen" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" -dependencies = [ - "bitflags 2.9.1", -] +checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814" [[package]] name = "writeable" @@ -6560,7 +6624,7 @@ checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "synstructure 0.13.2", ] @@ -6581,7 +6645,7 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -6601,7 +6665,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "synstructure 0.13.2", ] @@ -6624,9 +6688,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.2" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a05eb080e015ba39cc9e23bbe5e7fb04d5fb040350f99f34e338d5fdd294428" +checksum = "e7aa2bd55086f1ab526693ecbe444205da57e25f4489879da80635a46d90e73b" dependencies = [ "yoke", "zerofrom", @@ -6641,7 +6705,7 @@ checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -6689,9 +6753,9 @@ dependencies = [ [[package]] name = "zune-jpeg" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9e525af0a6a658e031e95f14b7f889976b74a11ba0eca5a5fc9ac8a1c43a6a" +checksum = "fc1f7e205ce79eb2da3cd71c5f55f3589785cb7c79f6a03d1c8d1491bda5d089" dependencies = [ "zune-core", ] diff --git a/Cargo.toml b/Cargo.toml index fe388b4d..7a06df64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ features = ["ffi", "std", "union"] version = "0.6.2" [workspace.dependencies.ctor] -version = "0.2.9" +version = "0.5.0" [workspace.dependencies.cargo_toml] version = "0.22" @@ -536,11 +536,11 @@ version = "0.2" version = "0.2" [workspace.dependencies.minicbor] -version = "0.26.5" +version = "2.1.1" features = ["std"] [workspace.dependencies.minicbor-serde] -version = "0.4.1" +version = "0.6.0" features = ["std"] [workspace.dependencies.maplit] diff --git a/src/admin/Cargo.toml b/src/admin/Cargo.toml index 7896ef97..470d3e34 100644 --- a/src/admin/Cargo.toml +++ b/src/admin/Cargo.toml @@ -89,6 +89,7 @@ serde_yaml.workspace = true tokio.workspace = true tracing-subscriber.workspace = true tracing.workspace = true +ctor.workspace = true [lints] workspace = true diff --git a/src/admin/mod.rs b/src/admin/mod.rs index 1d46590b..1e46dc7f 100644 --- a/src/admin/mod.rs +++ b/src/admin/mod.rs @@ -29,6 +29,8 @@ pub(crate) use crate::{context::Context, utils::get_room_info}; pub(crate) const PAGE_SIZE: usize = 100; +use ctor::{ctor, dtor}; + conduwuit::mod_ctor! {} conduwuit::mod_dtor! {} conduwuit::rustc_flags_capture! {} diff --git a/src/api/Cargo.toml b/src/api/Cargo.toml index 9b4ea460..18a2ddbd 100644 --- a/src/api/Cargo.toml +++ b/src/api/Cargo.toml @@ -93,6 +93,7 @@ serde.workspace = true sha1.workspace = true tokio.workspace = true tracing.workspace = true +ctor.workspace = true [lints] workspace = true diff --git a/src/api/client/message.rs b/src/api/client/message.rs index 4d489c2f..f5a951f4 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -321,7 +321,7 @@ pub(crate) fn event_filter(item: PdusIterItem, filter: &RoomEventFilter) -> Opti filter.matches(pdu).then_some(item) } -#[cfg_attr(debug_assertions, conduwuit::ctor)] +#[cfg_attr(debug_assertions, ctor::ctor)] fn _is_sorted() { debug_assert!( IGNORED_MESSAGE_TYPES.is_sorted(), diff --git a/src/database/Cargo.toml b/src/database/Cargo.toml index 9f51f366..d37ca585 100644 --- a/src/database/Cargo.toml +++ b/src/database/Cargo.toml @@ -66,6 +66,7 @@ serde.workspace = true serde_json.workspace = true tokio.workspace = true tracing.workspace = true +ctor.workspace = true [lints] workspace = true diff --git a/src/database/mod.rs b/src/database/mod.rs index ffcefee9..7932fbcb 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -3,6 +3,8 @@ extern crate conduwuit_core as conduwuit; extern crate rust_rocksdb as rocksdb; +use ctor::{ctor, dtor}; + conduwuit::mod_ctor! {} conduwuit::mod_dtor! {} conduwuit::rustc_flags_capture! {} diff --git a/src/macros/rustc.rs b/src/macros/rustc.rs index cf935fe5..f302b152 100644 --- a/src/macros/rustc.rs +++ b/src/macros/rustc.rs @@ -13,13 +13,13 @@ pub(super) fn flags_capture(args: TokenStream) -> TokenStream { let ret = quote! { pub static RUSTC_FLAGS: [&str; #flag_len] = [#( #flag ),*]; - #[conduwuit_core::ctor] + #[ctor] fn _set_rustc_flags() { conduwuit_core::info::rustc::FLAGS.lock().insert(#crate_name, &RUSTC_FLAGS); } // static strings have to be yanked on module unload - #[conduwuit_core::dtor] + #[dtor] fn _unset_rustc_flags() { conduwuit_core::info::rustc::FLAGS.lock().remove(#crate_name); } diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 8f6f4341..44b4a2ef 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -202,6 +202,7 @@ clap.workspace = true console-subscriber.optional = true console-subscriber.workspace = true const-str.workspace = true +ctor.workspace = true log.workspace = true opentelemetry-jaeger.optional = true opentelemetry-jaeger.workspace = true diff --git a/src/main/mod.rs b/src/main/mod.rs index 7097c67d..ba59549c 100644 --- a/src/main/mod.rs +++ b/src/main/mod.rs @@ -13,6 +13,7 @@ mod sentry; mod server; mod signal; +use ctor::{ctor, dtor}; use server::Server; rustc_flags_capture! {} diff --git a/src/router/Cargo.toml b/src/router/Cargo.toml index 9fcb8d6a..9545c480 100644 --- a/src/router/Cargo.toml +++ b/src/router/Cargo.toml @@ -125,6 +125,7 @@ tokio.workspace = true tower.workspace = true tower-http.workspace = true tracing.workspace = true +ctor.workspace = true [target.'cfg(all(unix, target_os = "linux"))'.dependencies] sd-notify.workspace = true diff --git a/src/router/mod.rs b/src/router/mod.rs index 7038c5df..416ceea7 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -12,6 +12,7 @@ use std::{panic::AssertUnwindSafe, pin::Pin, sync::Arc}; use conduwuit::{Error, Result, Server}; use conduwuit_service::Services; +use ctor::{ctor, dtor}; use futures::{Future, FutureExt, TryFutureExt}; conduwuit::mod_ctor! {} diff --git a/src/service/Cargo.toml b/src/service/Cargo.toml index 6e538f40..e4abb9bb 100644 --- a/src/service/Cargo.toml +++ b/src/service/Cargo.toml @@ -117,6 +117,7 @@ webpage.optional = true blurhash.workspace = true blurhash.optional = true recaptcha-verify = { version = "0.1.5", default-features = false } +ctor.workspace = true [lints] workspace = true diff --git a/src/service/mod.rs b/src/service/mod.rs index 3d7a3aa9..2ad0ecd2 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -33,6 +33,7 @@ pub mod users; extern crate conduwuit_core as conduwuit; extern crate conduwuit_database as database; +use ctor::{ctor, dtor}; pub(crate) use service::{Args, Dep, Service}; pub use crate::services::Services; From c0e3829fedc9330eaa39a9817b31bb6dbea72961 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 6 Sep 2025 16:05:13 +0100 Subject: [PATCH 2267/2291] feat: Replace Jaeger with OTLP --- Cargo.lock | 164 +++++++++++++++++------------------------ Cargo.toml | 28 ++----- conduwuit-example.toml | 14 +++- src/core/config/mod.rs | 19 +++-- src/main/Cargo.toml | 10 ++- src/main/logging.rs | 35 +++++---- 6 files changed, 125 insertions(+), 145 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3c24b178..9e56ad45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -922,9 +922,10 @@ dependencies = [ "ctor", "hardened_malloc-rs", "log", - "opentelemetry 0.30.0", - "opentelemetry-jaeger", - "opentelemetry_sdk 0.30.0", + "opentelemetry", + "opentelemetry-jaeger-propagator", + "opentelemetry-otlp", + "opentelemetry_sdk", "sentry", "sentry-tower", "sentry-tracing", @@ -1187,7 +1188,7 @@ dependencies = [ "futures-core", "prost", "prost-types", - "tonic", + "tonic 0.12.3", "tracing-core", ] @@ -1211,7 +1212,7 @@ dependencies = [ "thread_local", "tokio", "tokio-stream", - "tonic", + "tonic 0.12.3", "tracing", "tracing-core", "tracing-subscriber", @@ -2551,12 +2552,6 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb" -[[package]] -name = "integer-encoding" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bb03732005da905c88227371639bf1ad885cc712789c011c31c5fb3ab3ccf02" - [[package]] name = "interpolate_name" version = "0.2.4" @@ -3283,20 +3278,6 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" -[[package]] -name = "opentelemetry" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b69a91d4893e713e06f724597ad630f1fa76057a5e1026c0ca67054a9032a76" -dependencies = [ - "futures-core", - "futures-sink", - "js-sys", - "once_cell", - "pin-project-lite", - "thiserror 1.0.69", -] - [[package]] name = "opentelemetry" version = "0.30.0" @@ -3312,46 +3293,54 @@ dependencies = [ ] [[package]] -name = "opentelemetry-jaeger" -version = "0.22.0" +name = "opentelemetry-http" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501b471b67b746d9a07d4c29f8be00f952d1a2eca356922ede0098cbaddff19f" +checksum = "50f6639e842a97dbea8886e3439710ae463120091e2e064518ba8e716e6ac36d" dependencies = [ "async-trait", - "futures-core", - "futures-util", - "opentelemetry 0.23.0", - "opentelemetry-semantic-conventions", - "opentelemetry_sdk 0.23.0", - "thrift", - "tokio", + "bytes", + "http", + "opentelemetry", + "reqwest", ] [[package]] -name = "opentelemetry-semantic-conventions" -version = "0.15.0" +name = "opentelemetry-jaeger-propagator" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1869fb4bb9b35c5ba8a1e40c9b128a7b4c010d07091e864a29da19e4fe2ca4d7" +checksum = "090b8ec07bb2e304b529581aa1fe530d7861298c9ef549ebbf44a4a56472c539" +dependencies = [ + "opentelemetry", +] [[package]] -name = "opentelemetry_sdk" -version = "0.23.0" +name = "opentelemetry-otlp" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae312d58eaa90a82d2e627fd86e075cf5230b3f11794e2ed74199ebbe572d4fd" +checksum = "dbee664a43e07615731afc539ca60c6d9f1a9425e25ca09c57bc36c87c55852b" dependencies = [ - "async-trait", - "futures-channel", - "futures-executor", - "futures-util", - "lazy_static", - "once_cell", - "opentelemetry 0.23.0", - "ordered-float 4.6.0", - "percent-encoding", - "rand 0.8.5", - "thiserror 1.0.69", - "tokio", - "tokio-stream", + "http", + "opentelemetry", + "opentelemetry-http", + "opentelemetry-proto", + "opentelemetry_sdk", + "prost", + "reqwest", + "thiserror 2.0.16", + "tracing", +] + +[[package]] +name = "opentelemetry-proto" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e046fd7660710fe5a05e8748e70d9058dc15c94ba914e7c4faa7c728f0e8ddc" +dependencies = [ + "opentelemetry", + "opentelemetry_sdk", + "prost", + "tonic 0.13.1", ] [[package]] @@ -3363,7 +3352,7 @@ dependencies = [ "futures-channel", "futures-executor", "futures-util", - "opentelemetry 0.30.0", + "opentelemetry", "percent-encoding", "rand 0.9.2", "serde_json", @@ -3372,24 +3361,6 @@ dependencies = [ "tokio-stream", ] -[[package]] -name = "ordered-float" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" -dependencies = [ - "num-traits", -] - -[[package]] -name = "ordered-float" -version = "4.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bb71e1b3fa6ca1c61f383464aaf2bb0e2f8e772a1f01d486832464de363b951" -dependencies = [ - "num-traits", -] - [[package]] name = "os_info" version = "3.12.0" @@ -5272,28 +5243,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "threadpool" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" -dependencies = [ - "num_cpus", -] - -[[package]] -name = "thrift" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e54bc85fc7faa8bc175c4bab5b92ba8d9a3ce893d0e9f42cc455c8ab16a9e09" -dependencies = [ - "byteorder", - "integer-encoding", - "log", - "ordered-float 2.10.1", - "threadpool", -] - [[package]] name = "tiff" version = "0.9.1" @@ -5598,6 +5547,27 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e581ba15a835f4d9ea06c55ab1bd4dce26fc53752c69a04aac00703bfb49ba9" +dependencies = [ + "async-trait", + "base64 0.22.1", + "bytes", + "http", + "http-body", + "http-body-util", + "percent-encoding", + "pin-project", + "prost", + "tokio-stream", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower" version = "0.4.13" @@ -5737,8 +5707,8 @@ checksum = "ddcf5959f39507d0d04d6413119c04f33b623f4f951ebcbdddddfad2d0623a9c" dependencies = [ "js-sys", "once_cell", - "opentelemetry 0.30.0", - "opentelemetry_sdk 0.30.0", + "opentelemetry", + "opentelemetry_sdk", "smallvec", "tracing", "tracing-core", diff --git a/Cargo.toml b/Cargo.toml index 7a06df64..12ba6456 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -423,9 +423,12 @@ version = "0.31.0" version = "0.30.0" features = ["rt-tokio"] -[workspace.dependencies.opentelemetry-jaeger] -version = "0.22.0" -features = ["rt-tokio"] +[workspace.dependencies.opentelemetry-otlp] +version = "0.30.0" +features = ["http", "trace", "logs", "metrics"] + +[workspace.dependencies.opentelemetry-jaeger-propagator] +version = "0.30.0" # optional sentry metrics for crash/panic reporting [workspace.dependencies.sentry] @@ -764,25 +767,6 @@ incremental = true [profile.dev.package.conduwuit_core] inherits = "dev" -#rustflags = [ -# '--cfg', 'conduwuit_mods', -# '-Ztime-passes', -# '-Zmir-opt-level=0', -# '-Ztls-model=initial-exec', -# '-Cprefer-dynamic=true', -# '-Zstaticlib-prefer-dynamic=true', -# '-Zstaticlib-allow-rdylib-deps=true', -# '-Zpacked-bundled-libs=false', -# '-Zplt=true', -# '-Clink-arg=-Wl,--as-needed', -# '-Clink-arg=-Wl,--allow-shlib-undefined', -# '-Clink-arg=-Wl,-z,lazy', -# '-Clink-arg=-Wl,-z,unique', -# '-Clink-arg=-Wl,-z,nodlopen', -# '-Clink-arg=-Wl,-z,nodelete', -#] -[profile.dev.package.xtask-generate-commands] -inherits = "dev" [profile.dev.package.conduwuit] inherits = "dev" #rustflags = [ diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 0fc034d0..07374aae 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -591,13 +591,19 @@ # #default_room_version = 11 -# This item is undocumented. Please contribute documentation for it. +# Enable OpenTelemetry OTLP tracing export. This replaces the deprecated +# Jaeger exporter. Traces will be sent via OTLP to a collector (such as +# Jaeger) that supports the OpenTelemetry Protocol. # -#allow_jaeger = false +# Configure your OTLP endpoint using the OTEL_EXPORTER_OTLP_ENDPOINT +# environment variable (defaults to http://localhost:4318). +# +#allow_otlp = false -# This item is undocumented. Please contribute documentation for it. +# Filter for OTLP tracing spans. This controls which spans are exported +# to the OTLP collector. # -#jaeger_filter = "info" +#otlp_filter = "info" # If the 'perf_measurements' compile-time feature is enabled, enables # collecting folded stack trace profile of tracing spans using diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index e9e6d28d..b6f6ab53 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -714,12 +714,21 @@ pub struct Config { #[serde(default)] pub well_known: WellKnownConfig, - #[serde(default)] - pub allow_jaeger: bool, + /// Enable OpenTelemetry OTLP tracing export. This replaces the deprecated + /// Jaeger exporter. Traces will be sent via OTLP to a collector (such as + /// Jaeger) that supports the OpenTelemetry Protocol. + /// + /// Configure your OTLP endpoint using the OTEL_EXPORTER_OTLP_ENDPOINT + /// environment variable (defaults to http://localhost:4318). + #[serde(default, alias = "allow_jaeger")] + pub allow_otlp: bool, + /// Filter for OTLP tracing spans. This controls which spans are exported + /// to the OTLP collector. + /// /// default: "info" - #[serde(default = "default_jaeger_filter")] - pub jaeger_filter: String, + #[serde(default = "default_otlp_filter", alias = "jaeger_filter")] + pub otlp_filter: String, /// If the 'perf_measurements' compile-time feature is enabled, enables /// collecting folded stack trace profile of tracing spans using @@ -2367,7 +2376,7 @@ fn default_tracing_flame_filter() -> String { .to_owned() } -fn default_jaeger_filter() -> String { +fn default_otlp_filter() -> String { cfg!(debug_assertions) .then_some("trace,h2=off") .unwrap_or("info") diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 44b4a2ef..388ad503 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -126,7 +126,8 @@ perf_measurements = [ "dep:tracing-flame", "dep:tracing-opentelemetry", "dep:opentelemetry_sdk", - "dep:opentelemetry-jaeger", + "dep:opentelemetry-otlp", + "dep:opentelemetry-jaeger-propagator", "conduwuit-core/perf_measurements", "conduwuit-core/sentry_telemetry", ] @@ -204,10 +205,12 @@ console-subscriber.workspace = true const-str.workspace = true ctor.workspace = true log.workspace = true -opentelemetry-jaeger.optional = true -opentelemetry-jaeger.workspace = true opentelemetry.optional = true opentelemetry.workspace = true +opentelemetry-otlp.optional = true +opentelemetry-otlp.workspace = true +opentelemetry-jaeger-propagator.optional = true +opentelemetry-jaeger-propagator.workspace = true opentelemetry_sdk.optional = true opentelemetry_sdk.workspace = true sentry-tower.optional = true @@ -227,6 +230,7 @@ tracing-subscriber.workspace = true tracing.workspace = true tracing-journald = { workspace = true, optional = true } + [target.'cfg(all(not(target_env = "msvc"), target_os = "linux"))'.dependencies] hardened_malloc-rs.workspace = true hardened_malloc-rs.optional = true diff --git a/src/main/logging.rs b/src/main/logging.rs index b7beb103..57b56707 100644 --- a/src/main/logging.rs +++ b/src/main/logging.rs @@ -7,6 +7,8 @@ use conduwuit_core::{ log::{ConsoleFormat, ConsoleWriter, LogLevelReloadHandles, capture, fmt_span}, result::UnwrapOrErr, }; +#[cfg(feature = "perf_measurements")] +use opentelemetry::trace::TracerProvider; use tracing_subscriber::{EnvFilter, Layer, Registry, fmt, layer::SubscriberExt, reload}; #[cfg(feature = "perf_measurements")] @@ -87,30 +89,35 @@ pub(crate) fn init( (None, None) }; - let jaeger_filter = EnvFilter::try_new(&config.jaeger_filter) - .map_err(|e| err!(Config("jaeger_filter", "{e}.")))?; + let otlp_filter = EnvFilter::try_new(&config.otlp_filter) + .map_err(|e| err!(Config("otlp_filter", "{e}.")))?; - let jaeger_layer = config.allow_jaeger.then(|| { + let otlp_layer = config.allow_otlp.then(|| { opentelemetry::global::set_text_map_propagator( - opentelemetry_jaeger::Propagator::new(), + opentelemetry_jaeger_propagator::Propagator::new(), ); - let tracer = opentelemetry_jaeger::new_agent_pipeline() - .with_auto_split_batch(true) - .with_service_name(conduwuit_core::name()) - .install_batch(opentelemetry_sdk::runtime::Tokio) - .expect("jaeger agent pipeline"); + let exporter = opentelemetry_otlp::SpanExporter::builder() + .with_http() + .build() + .expect("Failed to create OTLP exporter"); + + let provider = opentelemetry_sdk::trace::SdkTracerProvider::builder() + .with_batch_exporter(exporter) + .build(); + + let tracer = provider.tracer(conduwuit_core::name()); let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); - let (jaeger_reload_filter, jaeger_reload_handle) = - reload::Layer::new(jaeger_filter.clone()); - reload_handles.add("jaeger", Box::new(jaeger_reload_handle)); + let (otlp_reload_filter, otlp_reload_handle) = + reload::Layer::new(otlp_filter.clone()); + reload_handles.add("otlp", Box::new(otlp_reload_handle)); - Some(telemetry.with_filter(jaeger_reload_filter)) + Some(telemetry.with_filter(otlp_reload_filter)) }); - let subscriber = subscriber.with(flame_layer).with(jaeger_layer); + let subscriber = subscriber.with(flame_layer).with(otlp_layer); (subscriber, flame_guard) }; From cd238b05dee3e1abbfc07af33a8fe0d7a2307be4 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Sat, 6 Sep 2025 16:21:21 +0100 Subject: [PATCH 2268/2291] fix: Remove bad colon in workflow --- .forgejo/workflows/release-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 2b3d481f..7b29b7ca 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -15,7 +15,7 @@ on: - "docs/**" push: branches: - - main: + - main paths-ignore: - "*.md" - "**/*.md" From 969d7cbb66bb56709e325f9cdcf8d9a4af11269c Mon Sep 17 00:00:00 2001 From: aviac Date: Tue, 26 Aug 2025 16:00:06 +0200 Subject: [PATCH 2269/2291] feat(nix): remove rocksdb from flake.nix inputs Consuming this flake is pretty annoying since the rocksdb input is fetched on every build which takes ~ 10 - 20 sec. By removing it and replacing it with a `pkgs.fetchFromGitea`, we create an intermediate derivation which is better for caching reasons. --- flake.lock | 20 +------------------- flake.nix | 12 +++++++----- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/flake.lock b/flake.lock index 4c2bf9fb..f1859b57 100644 --- a/flake.lock +++ b/flake.lock @@ -513,23 +513,6 @@ "type": "github" } }, - "rocksdb": { - "flake": false, - "locked": { - "lastModified": 1753385396, - "narHash": "sha256-/Hvy1yTH/0D5aa7bc+/uqFugCQq4InTdwlRw88vA5IY=", - "ref": "10.4.fb", - "rev": "28d4b7276c16ed3e28af1bd96162d6442ce25923", - "revCount": 13318, - "type": "git", - "url": "https://forgejo.ellis.link/continuwuation/rocksdb" - }, - "original": { - "ref": "10.4.fb", - "type": "git", - "url": "https://forgejo.ellis.link/continuwuation/rocksdb" - } - }, "root": { "inputs": { "attic": "attic", @@ -539,8 +522,7 @@ "flake-compat": "flake-compat_3", "flake-utils": "flake-utils", "nix-filter": "nix-filter", - "nixpkgs": "nixpkgs_5", - "rocksdb": "rocksdb" + "nixpkgs": "nixpkgs_5" } }, "rust-analyzer-src": { diff --git a/flake.nix b/flake.nix index e65fcbda..b8ac6029 100644 --- a/flake.nix +++ b/flake.nix @@ -16,10 +16,6 @@ flake-utils.url = "github:numtide/flake-utils?ref=main"; nix-filter.url = "github:numtide/nix-filter?ref=main"; nixpkgs.url = "github:NixOS/nixpkgs?ref=nixpkgs-unstable"; - rocksdb = { - url = "git+https://forgejo.ellis.link/continuwuation/rocksdb?ref=10.4.fb"; - flake = false; - }; }; outputs = @@ -65,7 +61,13 @@ inherit (self) liburing; }).overrideAttrs (old: { - src = inputs.rocksdb; + src = pkgsHost.fetchFromGitea { + domain = "forgejo.ellis.link"; + owner = "continuwuation"; + repo = "rocksdb"; + rev = "10.4.fb"; + sha256 = "sha256-/Hvy1yTH/0D5aa7bc+/uqFugCQq4InTdwlRw88vA5IY="; + }; version = "v10.4.fb"; cmakeFlags = pkgs.lib.subtractLists [ From 1a3107c20ad473e4f5b2cc7ac702dd1a59ce7a70 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 7 Sep 2025 09:28:59 +0100 Subject: [PATCH 2270/2291] fix(ci): Replace Mozilla sccache action with token-free alternative Replace mozilla-actions/sccache-action with a custom Forgejo-specific implementation that eliminates GitHub token dependencies and rate limiting issues for all contributors regardless of repository permissions. The new action mirrors sccache binaries to the Forgejo package registry and queries that instead of GitHub releases, maintaining identical functionality including hostedtoolcache support. --- .forgejo/actions/sccache/action.yml | 8 +------- .forgejo/actions/setup-rust/action.yml | 12 +----------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/.forgejo/actions/sccache/action.yml b/.forgejo/actions/sccache/action.yml index b5e5dcf4..b2441109 100644 --- a/.forgejo/actions/sccache/action.yml +++ b/.forgejo/actions/sccache/action.yml @@ -2,18 +2,12 @@ name: sccache description: | Install sccache for caching builds in GitHub Actions. -inputs: - token: - description: 'A Github PAT' - required: false runs: using: composite steps: - name: Install sccache - uses: https://github.com/mozilla-actions/sccache-action@v0.0.9 - with: - token: ${{ inputs.token }} + uses: https://git.tomfos.tr/tom/sccache-action@v1 - name: Configure sccache uses: https://github.com/actions/github-script@v7 with: diff --git a/.forgejo/actions/setup-rust/action.yml b/.forgejo/actions/setup-rust/action.yml index 091da8c2..a8736a75 100644 --- a/.forgejo/actions/setup-rust/action.yml +++ b/.forgejo/actions/setup-rust/action.yml @@ -88,19 +88,9 @@ runs: # Shared toolchain cache across all Rust versions key: toolchain-${{ steps.runner-os.outputs.slug }} - - name: Debug GitHub token availability - shell: bash - run: | - if [ -z "${{ inputs.github-token }}" ]; then - echo "⚠️ No GitHub token provided - sccache will use fallback download method" - else - echo "✅ GitHub token provided for sccache" - fi - name: Setup sccache - uses: https://github.com/mozilla-actions/sccache-action@v0.0.9 - with: - token: ${{ inputs.github-token }} + uses: https://git.tomfos.tr/tom/sccache-action@v1 - name: Cache build artifacts id: build-cache From fff9629b0f4d28148007f180f8c52807894b7c2b Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 7 Sep 2025 13:21:58 +0100 Subject: [PATCH 2271/2291] fix(docker): Resolve liburing.so.2 loading error for non-root users Container failed to start when running as non-root (user 1000:1000) because copied directories had restrictive 770 permissions, likely due to different umask in persistent BuildKit. Non-root users couldn't access /usr/lib to load required dynamic libraries. Introduces prepper stage using Ubuntu to organize files into layered structure with explicit 755 directory permissions before copying to scratch image. Also fixes workflow syntax error and removes docker/** from paths-ignore to ensure Docker changes trigger CI builds. --- .forgejo/workflows/release-image.yml | 4 +- docker/Dockerfile | 57 ++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 7b29b7ca..834b5602 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -11,7 +11,6 @@ on: - ".gitignore" - "renovate.json" - "pkg/**" - - "docker/**" - "docs/**" push: branches: @@ -23,7 +22,6 @@ on: - ".gitignore" - "renovate.json" - "pkg/**" - - "docker/**" - "docs/**" # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -199,7 +197,7 @@ jobs: context: . file: "docker/Dockerfile" build-args: | - GIT_COMMIT_HASH=${{ github.sha }}) + GIT_COMMIT_HASH=${{ github.sha }} GIT_COMMIT_HASH_SHORT=${{ env.COMMIT_SHORT_SHA }} GIT_REMOTE_URL=${{github.event.repository.html_url }} GIT_REMOTE_COMMIT_URL=${{github.event.head_commit.url }} diff --git a/docker/Dockerfile b/docker/Dockerfile index 55150902..17e1c6a1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -199,32 +199,57 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ EOF # Extract dynamically linked dependencies -RUN </dev/null) && [ -n "$lddtree_output" ]; then + echo "$lddtree_output" | awk '{print $(NF-0) " " $1}' | sort -u -k 1,1 | \ + awk '{dest = ($2 ~ /^\//) ? "/out/libs-root" $2 : "/out/libs/" $2; print "install -D " $1 " " dest}' | \ + while read cmd; do eval "$cmd"; done + fi done -EOF + + # Show what will be copied to runtime + echo "=== Libraries being copied to runtime image:" + find /out/libs* -type f 2>/dev/null | sort || echo "No libraries found" +DEPS_EOF + +FROM ubuntu:latest AS prepper + +# Create layer structure +RUN mkdir -p /layer1/etc/ssl/certs \ + /layer2/usr/lib \ + /layer3/sbin /layer3/sbom + +# Copy SSL certs and root-path libraries to layer1 (ultra-stable) +COPY --from=base /etc/ssl/certs /layer1/etc/ssl/certs +COPY --from=builder /out/libs-root/ /layer1/ + +# Copy application libraries to layer2 (semi-stable) +COPY --from=builder /out/libs/ /layer2/usr/lib/ + +# Copy binaries and SBOM to layer3 (volatile) +COPY --from=builder /out/sbin/ /layer3/sbin/ +COPY --from=builder /out/sbom/ /layer3/sbom/ + +# Fix permissions after copying +RUN chmod -R 755 /layer1 /layer2 /layer3 FROM scratch WORKDIR / -# Copy root certs for tls into image -# You can also mount the certs from the host -# --volume /etc/ssl/certs:/etc/ssl/certs:ro -COPY --from=base /etc/ssl/certs /etc/ssl/certs +# Copy ultra-stable layer (SSL certs, system libraries) +COPY --from=prepper /layer1/ / -# Copy our build -COPY --from=builder /out/sbin/ /sbin/ -# Copy SBOM -COPY --from=builder /out/sbom/ /sbom/ +# Copy semi-stable layer (application libraries) +COPY --from=prepper /layer2/ / -# Copy dynamic libraries to root -COPY --from=builder /out/libs-root/ / -COPY --from=builder /out/libs/ /usr/lib/ +# Copy volatile layer (binaries, SBOM) +COPY --from=prepper /layer3/ / # Inform linker where to find libraries ENV LD_LIBRARY_PATH=/usr/lib From d640853f9d3c5cd33fc14775090d634747091bdc Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 7 Sep 2025 14:32:11 +0100 Subject: [PATCH 2272/2291] ci(docs): Optimise build performance with caching and conditional Node.js Skip installing Node.js entirely if v20+ is already available, otherwise install v22. Add npm dependency caching with OS-specific cache keys using the custom detect-runner-os action for proper cache isolation between runners. Dependencies normally take just under 10s, so this should more than halve the doc build time to free up runner slots. --- .forgejo/actions/detect-runner-os/action.yml | 21 +++++++++++++++++++- .forgejo/workflows/documentation.yml | 15 +++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.forgejo/actions/detect-runner-os/action.yml b/.forgejo/actions/detect-runner-os/action.yml index 6ada1d5d..be8f9b0a 100644 --- a/.forgejo/actions/detect-runner-os/action.yml +++ b/.forgejo/actions/detect-runner-os/action.yml @@ -13,6 +13,12 @@ outputs: slug: description: 'Combined OS slug (e.g. Ubuntu-22.04)' value: ${{ steps.detect.outputs.slug }} + node_major: + description: 'Major version of Node.js if available (e.g. 22)' + value: ${{ steps.detect.outputs.node_major }} + node_version: + description: 'Full Node.js version if available (e.g. 22.19.0)' + value: ${{ steps.detect.outputs.node_version }} runs: using: composite @@ -30,7 +36,20 @@ runs: # Create combined slug OS_SLUG="${OS_NAME}-${OS_VERSION}" - # Set outputs + # Detect Node.js version if available + if command -v node >/dev/null 2>&1; then + NODE_VERSION=$(node --version | sed 's/v//') + NODE_MAJOR=$(echo $NODE_VERSION | cut -d. -f1) + echo "node_version=${NODE_VERSION}" >> $GITHUB_OUTPUT + echo "node_major=${NODE_MAJOR}" >> $GITHUB_OUTPUT + echo "🔍 Detected Node.js: v${NODE_VERSION}" + else + echo "node_version=" >> $GITHUB_OUTPUT + echo "node_major=" >> $GITHUB_OUTPUT + echo "🔍 Node.js not found" + fi + + # Set OS outputs echo "name=${OS_NAME}" >> $GITHUB_OUTPUT echo "version=${OS_VERSION}" >> $GITHUB_OUTPUT echo "slug=${OS_SLUG}" >> $GITHUB_OUTPUT diff --git a/.forgejo/workflows/documentation.yml b/.forgejo/workflows/documentation.yml index 4f3e903c..67c8a30c 100644 --- a/.forgejo/workflows/documentation.yml +++ b/.forgejo/workflows/documentation.yml @@ -49,10 +49,23 @@ jobs: cp ./docs/static/_headers ./public/_headers echo "Copied .well-known files and _headers to ./public" + - name: Detect runner environment + id: runner-env + uses: ./.forgejo/actions/detect-runner-os + - name: Setup Node.js + if: steps.runner-env.outputs.node_major == '' || steps.runner-env.outputs.node_major < '20' uses: https://github.com/actions/setup-node@v4 with: - node-version: 20 + node-version: 22 + + - name: Cache npm dependencies + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ steps.runner-env.outputs.slug }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ steps.runner-env.outputs.slug }}-node- - name: Install dependencies run: npm install --save-dev wrangler@latest From 84fdcd326a4076bad19dc62e0061a15cafe54158 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 7 Sep 2025 17:08:36 +0100 Subject: [PATCH 2273/2291] fix(ci): Resolve registry push failures for fork PRs Fork PRs now fail during Docker image build with 'tag is needed when pushing to registry' because BUILTIN_REGISTRY_ENABLED evaluates to false without proper credentials, leaving the images list empty. This appears to be due to recent Forgejo permission changes affecting fork access to repository secrets. Add fallback to official registry when credentials unavailable, skip registry login and push operations for forks, and make merge job conditional since no digests exist without push. This allows forks to test Docker builds whilst avoiding authentication failures. --- .forgejo/workflows/release-image.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 834b5602..069f1d34 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -53,6 +53,9 @@ jobs: let images = [] if (process.env.BUILTIN_REGISTRY_ENABLED === "true") { images.push(builtinImage) + } else { + // Fallback to official registry for forks/PRs without credentials + images.push('forgejo.ellis.link/continuwuation/continuwuity') } core.setOutput('images', images.join("\n")) core.setOutput('images_list', images.join(",")) @@ -111,6 +114,7 @@ jobs: uses: docker/setup-qemu-action@v3 # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. - name: Login to builtin registry + if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }} uses: docker/login-action@v3 with: registry: ${{ env.BUILTIN_REGISTRY }} @@ -207,7 +211,7 @@ jobs: cache-from: type=gha # cache-to: type=gha,mode=max sbom: true - outputs: type=image,"name=${{ needs.define-variables.outputs.images_list }}",push-by-digest=true,name-canonical=true,push=true + outputs: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' && format('type=image,"name={0}",push-by-digest=true,name-canonical=true,push=true', needs.define-variables.outputs.images_list) || 'type=docker' }} env: SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }} @@ -249,6 +253,7 @@ jobs: needs: [define-variables, build-image] steps: - name: Download digests + if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }} uses: forgejo/download-artifact@v4 with: path: /tmp/digests @@ -256,6 +261,7 @@ jobs: merge-multiple: true # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. - name: Login to builtin registry + if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }} uses: docker/login-action@v3 with: registry: ${{ env.BUILTIN_REGISTRY }} @@ -263,6 +269,7 @@ jobs: password: ${{ secrets.BUILTIN_REGISTRY_PASSWORD || secrets.GITHUB_TOKEN }} - name: Set up Docker Buildx + if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }} uses: docker/setup-buildx-action@v3 with: # Use persistent BuildKit if BUILDKIT_ENDPOINT is set (e.g. tcp://buildkit:8125) @@ -270,6 +277,7 @@ jobs: endpoint: ${{ env.BUILDKIT_ENDPOINT || '' }} - name: Extract metadata (tags) for Docker + if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }} id: meta uses: docker/metadata-action@v5 with: @@ -287,6 +295,7 @@ jobs: DOCKER_METADATA_ANNOTATIONS_LEVELS: index - name: Create manifest list and push + if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }} working-directory: /tmp/digests env: IMAGES: ${{needs.define-variables.outputs.images}} @@ -304,6 +313,7 @@ jobs: done - name: Inspect image + if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }} env: IMAGES: ${{needs.define-variables.outputs.images}} shell: bash From 2cedf0d2e1346769b023cd6e42ed3279142af5de Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 7 Sep 2025 18:32:38 +0100 Subject: [PATCH 2274/2291] fix(ci): Use image output instead of docker for fork PRs Docker exporter doesn't support manifest lists (multi-platform builds). For fork PRs without registry credentials, use 'type=image,push=false' instead of 'type=docker' to build multi-platform images locally without pushing. --- .forgejo/workflows/release-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 069f1d34..52f5e6e0 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -211,7 +211,7 @@ jobs: cache-from: type=gha # cache-to: type=gha,mode=max sbom: true - outputs: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' && format('type=image,"name={0}",push-by-digest=true,name-canonical=true,push=true', needs.define-variables.outputs.images_list) || 'type=docker' }} + outputs: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' && format('type=image,"name={0}",push-by-digest=true,name-canonical=true,push=true', needs.define-variables.outputs.images_list) || format('type=image,"name={0}",push=false', needs.define-variables.outputs.images_list) }} env: SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }} From 1e9701f379053b6f20681b48db6ede5026db4681 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 7 Sep 2025 18:59:05 +0100 Subject: [PATCH 2275/2291] ci(release-image): Skip setup steps when using persistent BuildKit When BUILDKIT_ENDPOINT is set, builds run on a persistent BuildKit instance, making runner setup steps unnecessary. Skip Rust toolchain installation, QEMU setup, caching steps, and timelord to eliminate ~7 operations per job. Also adds output to git SHA and timestamp steps for visibility. Cuts at least a minute off average build time through fewer installs, cache restores, and cache saves. --- .forgejo/workflows/release-image.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 52f5e6e0..1a0e4f4e 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -101,6 +101,7 @@ jobs: with: persist-credentials: false - name: Install rust + if: ${{ env.BUILDKIT_ENDPOINT == '' }} id: rust-toolchain uses: ./.forgejo/actions/rust-toolchain @@ -111,6 +112,7 @@ jobs: driver: ${{ env.BUILDKIT_ENDPOINT != '' && 'remote' || 'docker-container' }} endpoint: ${{ env.BUILDKIT_ENDPOINT || '' }} - name: Set up QEMU + if: ${{ env.BUILDKIT_ENDPOINT == '' }} uses: docker/setup-qemu-action@v3 # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. - name: Login to builtin registry @@ -140,15 +142,21 @@ jobs: run: | calculatedSha=$(git rev-parse --short ${{ github.sha }}) echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV + echo "Short SHA: $calculatedSha" - name: Get Git commit timestamps - run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV + run: | + timestamp=$(git log -1 --pretty=%ct) + echo "TIMESTAMP=$timestamp" >> $GITHUB_ENV + echo "Commit timestamp: $timestamp" - uses: ./.forgejo/actions/timelord + if: ${{ env.BUILDKIT_ENDPOINT == '' }} with: key: timelord-v0 path: . - name: Cache Rust registry + if: ${{ env.BUILDKIT_ENDPOINT == '' }} uses: actions/cache@v3 with: path: | @@ -158,6 +166,7 @@ jobs: .cargo/registry/src key: rust-registry-image-${{hashFiles('**/Cargo.lock') }} - name: Cache cargo target + if: ${{ env.BUILDKIT_ENDPOINT == '' }} id: cache-cargo-target uses: actions/cache@v3 with: @@ -165,6 +174,7 @@ jobs: cargo-target-${{ matrix.target_cpu }}-${{ matrix.slug }}-${{ matrix.profile }} key: cargo-target-${{ matrix.target_cpu }}-${{ matrix.slug }}-${{ matrix.profile }}-${{hashFiles('**/Cargo.lock') }}-${{steps.rust-toolchain.outputs.rustc_version}} - name: Cache apt cache + if: ${{ env.BUILDKIT_ENDPOINT == '' }} id: cache-apt uses: actions/cache@v3 with: @@ -172,6 +182,7 @@ jobs: var-cache-apt-${{ matrix.slug }} key: var-cache-apt-${{ matrix.slug }} - name: Cache apt lib + if: ${{ env.BUILDKIT_ENDPOINT == '' }} id: cache-apt-lib uses: actions/cache@v3 with: @@ -179,6 +190,7 @@ jobs: var-lib-apt-${{ matrix.slug }} key: var-lib-apt-${{ matrix.slug }} - name: inject cache into docker + if: ${{ env.BUILDKIT_ENDPOINT == '' }} uses: https://github.com/reproducible-containers/buildkit-cache-dance@v3.3.0 with: cache-map: | From 4a1091dd06e3e4518edb4a3df296e7a28fef0da9 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 7 Sep 2025 20:06:39 +0100 Subject: [PATCH 2276/2291] ci(release-image): Unify binary extraction using BuildKit local output Fork PRs currently fail binary extraction with 'invalid reference format' and 'must specify at least one container source' errors. This replaces the registry-specific docker create/copy method with BuildKit's local output feature for all builds. Uses multiple outputs in single build: image export plus local binary extraction from /sbin. Speeds up extracting binary artifacts and saves a couple of extra workflow steps in the process. --- .forgejo/workflows/release-image.yml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 1a0e4f4e..2a722edd 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -223,27 +223,23 @@ jobs: cache-from: type=gha # cache-to: type=gha,mode=max sbom: true - outputs: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' && format('type=image,"name={0}",push-by-digest=true,name-canonical=true,push=true', needs.define-variables.outputs.images_list) || format('type=image,"name={0}",push=false', needs.define-variables.outputs.images_list) }} + outputs: | + ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' && format('type=image,"name={0}",push-by-digest=true,name-canonical=true,push=true', needs.define-variables.outputs.images_list) || format('type=image,"name={0}",push=false', needs.define-variables.outputs.images_list) }} + type=local,dest=/tmp/binaries env: SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }} # For publishing multi-platform manifests - name: Export digest + if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }} run: | mkdir -p /tmp/digests digest="${{ steps.build.outputs.digest }}" touch "/tmp/digests/${digest#sha256:}" - - name: Extract binary from container (image) - id: extract-binary-image - run: | - mkdir -p /tmp/binaries - digest="${{ steps.build.outputs.digest }}" - echo "container_id=$(docker create --platform ${{ matrix.platform }} ${{ needs.define-variables.outputs.images_list }}@$digest)" >> $GITHUB_OUTPUT - - name: Extract binary from container (copy) - run: docker cp ${{ steps.extract-binary-image.outputs.container_id }}:/sbin/conduwuit /tmp/binaries/conduwuit-${{ matrix.target_cpu }}-${{ matrix.slug }}-${{ matrix.profile }} - - name: Extract binary from container (cleanup) - run: docker rm ${{ steps.extract-binary-image.outputs.container_id }} + # Binary extracted via local output for all builds + - name: Rename extracted binary + run: mv /tmp/binaries/sbin/conduwuit /tmp/binaries/conduwuit-${{ matrix.target_cpu }}-${{ matrix.slug }}-${{ matrix.profile }} - name: Upload binary artifact uses: forgejo/upload-artifact@v4 From 6cf3c839e4b2b6906f4017a3f77591937f37af6e Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Sun, 7 Sep 2025 21:27:56 +0100 Subject: [PATCH 2277/2291] ci(release-image): Skip digest upload when not pushing images After #992, builds without registry credentials skip Docker image output but still extract binary artifacts. However, we were still trying to upload digests for images that weren't created. Add conditional check to only upload digests when actually pushing to registry. --- .forgejo/workflows/release-image.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.forgejo/workflows/release-image.yml b/.forgejo/workflows/release-image.yml index 2a722edd..b7423567 100644 --- a/.forgejo/workflows/release-image.yml +++ b/.forgejo/workflows/release-image.yml @@ -249,6 +249,7 @@ jobs: if-no-files-found: error - name: Upload digest + if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }} uses: forgejo/upload-artifact@v4 with: name: digests-${{ matrix.slug }} From 2cdccbf2fe16fee50c8d93a9816c66c4ec6bf698 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 3 Sep 2025 14:20:50 +0100 Subject: [PATCH 2278/2291] feat(PR977): Support omitting members in the send_join response --- src/api/server/send_join.rs | 97 ++++++++++++++++++----- src/service/rooms/state_compressor/mod.rs | 2 +- 2 files changed, 80 insertions(+), 19 deletions(-) diff --git a/src/api/server/send_join.rs b/src/api/server/send_join.rs index 652451c7..3aebbbe7 100644 --- a/src/api/server/send_join.rs +++ b/src/api/server/send_join.rs @@ -1,12 +1,13 @@ #![allow(deprecated)] -use std::borrow::Borrow; +use std::{borrow::Borrow, time::Instant}; use axum::extract::State; use conduwuit::{ - Err, Result, at, err, + Err, Event, Result, at, debug, err, info, matrix::event::gen_event_id_canonical_json, - utils::stream::{IterStream, TryBroadbandExt}, + trace, + utils::stream::{BroadbandExt, IterStream, TryBroadbandExt}, warn, }; use conduwuit_service::Services; @@ -25,12 +26,14 @@ use serde_json::value::{RawValue as RawJsonValue, to_raw_value}; use crate::Ruma; /// helper method for /send_join v1 and v2 +#[tracing::instrument(skip(services, pdu, omit_members), fields(room_id = room_id.as_str(), origin = origin.as_str()))] async fn create_join_event( services: &Services, origin: &ServerName, room_id: &RoomId, pdu: &RawJsonValue, -) -> Result { + omit_members: bool, +) -> Result { if !services.rooms.metadata.exists(room_id).await { return Err!(Request(NotFound("Room is unknown to this server."))); } @@ -201,6 +204,7 @@ async fn create_join_event( .lock(room_id) .await; + debug!("Acquired send_join mutex, persisting join event"); let pdu_id = services .rooms .event_handler @@ -210,7 +214,7 @@ async fn create_join_event( .ok_or_else(|| err!(Request(InvalidParam("Could not accept as timeline event."))))?; drop(mutex_lock); - + debug!("Fetching current state IDs"); let state_ids: Vec = services .rooms .state_accessor @@ -219,9 +223,25 @@ async fn create_join_event( .collect() .await; + #[allow(clippy::unnecessary_unwrap)] let state = state_ids .iter() .try_stream() + .broad_filter_map(|event_id| async move { + if omit_members && event_id.is_ok() { + let pdu = services + .rooms + .timeline + .get_pdu(event_id.as_ref().unwrap()) + .await; + if pdu.is_ok_and(|p| p.kind().to_cow_str() == "m.room.member") { + trace!("omitting member event {event_id:?} from returned state"); + // skip members + return None; + } + } + Some(event_id) + }) .broad_and_then(|event_id| services.rooms.timeline.get_pdu_json(event_id)) .broad_and_then(|pdu| { services @@ -238,6 +258,17 @@ async fn create_join_event( .rooms .auth_chain .event_ids_iter(room_id, starting_events) + .broad_filter_map(|event_id| async { + if omit_members && event_id.as_ref().is_ok_and(|e| state_ids.contains(e)) { + // Don't include this event if it's already in the state + trace!( + "omitting member event {event_id:?} from returned auth chain as it is \ + already in state" + ); + return None; + } + Some(event_id) + }) .broad_and_then(|event_id| async move { services.rooms.timeline.get_pdu_json(&event_id).await }) @@ -252,11 +283,27 @@ async fn create_join_event( .await?; services.sending.send_pdu_room(room_id, &pdu_id).await?; - - Ok(create_join_event::v1::RoomState { + let servers_in_room: Option> = if omit_members { + None + } else { + debug!("Fetching list of servers in room"); + Some( + services + .rooms + .state_cache + .room_servers(room_id) + .map(|sn| sn.as_str().to_owned()) + .collect() + .await, + ) + }; + debug!("Returning send_join data"); + Ok(create_join_event::v2::RoomState { auth_chain, state, event: to_raw_value(&CanonicalJsonValue::Object(value)).ok(), + members_omitted: omit_members, + servers_in_room, }) } @@ -294,11 +341,24 @@ pub(crate) async fn create_join_event_v1_route( } } - let room_state = create_join_event(&services, body.origin(), &body.room_id, &body.pdu) + info!("Providing send_join for {} in {}", body.origin(), &body.room_id); + let now = Instant::now(); + let room_state = create_join_event(&services, body.origin(), &body.room_id, &body.pdu, false) .boxed() .await?; + let transformed = create_join_event::v1::RoomState { + auth_chain: room_state.auth_chain, + state: room_state.state, + event: room_state.event, + }; + info!( + "Finished creating the send_join payload for {} in {} in {:?}", + body.origin(), + &body.room_id, + now.elapsed() + ); - Ok(create_join_event::v1::Response { room_state }) + Ok(create_join_event::v1::Response { room_state: transformed }) } /// # `PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}` @@ -329,17 +389,18 @@ pub(crate) async fn create_join_event_v2_route( } } - let create_join_event::v1::RoomState { auth_chain, state, event } = - create_join_event(&services, body.origin(), &body.room_id, &body.pdu) + info!("Providing send_join for {} in {}", body.origin(), &body.room_id); + let now = Instant::now(); + let room_state = + create_join_event(&services, body.origin(), &body.room_id, &body.pdu, body.omit_members) .boxed() .await?; - let room_state = create_join_event::v2::RoomState { - members_omitted: false, - auth_chain, - state, - event, - servers_in_room: None, - }; + info!( + "Finished creating the send_join payload for {} in {} in {:?}", + body.origin(), + &body.room_id, + now.elapsed() + ); Ok(create_join_event::v2::Response { room_state }) } diff --git a/src/service/rooms/state_compressor/mod.rs b/src/service/rooms/state_compressor/mod.rs index f7f7d043..028c3e51 100644 --- a/src/service/rooms/state_compressor/mod.rs +++ b/src/service/rooms/state_compressor/mod.rs @@ -452,7 +452,7 @@ async fn get_statediff(&self, shortstatehash: ShortStateHash) -> Result Date: Wed, 3 Sep 2025 15:08:28 +0100 Subject: [PATCH 2279/2291] fix(PR977): Omitting redundant entries from the auth_chain caused problems --- src/api/server/send_join.rs | 49 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/api/server/send_join.rs b/src/api/server/send_join.rs index 3aebbbe7..a52b5391 100644 --- a/src/api/server/send_join.rs +++ b/src/api/server/send_join.rs @@ -1,6 +1,6 @@ #![allow(deprecated)] -use std::{borrow::Borrow, time::Instant}; +use std::{borrow::Borrow, time::Instant, vec}; use axum::extract::State; use conduwuit::{ @@ -258,17 +258,17 @@ async fn create_join_event( .rooms .auth_chain .event_ids_iter(room_id, starting_events) - .broad_filter_map(|event_id| async { - if omit_members && event_id.as_ref().is_ok_and(|e| state_ids.contains(e)) { - // Don't include this event if it's already in the state - trace!( - "omitting member event {event_id:?} from returned auth chain as it is \ - already in state" - ); - return None; - } - Some(event_id) - }) + // .broad_filter_map(|event_id| async { + // if omit_members && event_id.as_ref().is_ok_and(|e| state_ids.contains(e)) { + // // Don't include this event if it's already in the state + // trace!( + // "omitting member event {event_id:?} from returned auth chain as it is \ + // already in state" + // ); + // return None; + // } + // Some(event_id) + // }) .broad_and_then(|event_id| async move { services.rooms.timeline.get_pdu_json(&event_id).await }) @@ -283,19 +283,24 @@ async fn create_join_event( .await?; services.sending.send_pdu_room(room_id, &pdu_id).await?; - let servers_in_room: Option> = if omit_members { + let servers_in_room: Option> = if !omit_members { None } else { debug!("Fetching list of servers in room"); - Some( - services - .rooms - .state_cache - .room_servers(room_id) - .map(|sn| sn.as_str().to_owned()) - .collect() - .await, - ) + let servers: Vec = services + .rooms + .state_cache + .room_servers(room_id) + .map(|sn| sn.as_str().to_owned()) + .collect() + .await; + // If there's no servers, just add us + let servers = if servers.is_empty() { + vec![services.globals.server_name().to_string()] + } else { + servers + }; + Some(servers) }; debug!("Returning send_join data"); Ok(create_join_event::v2::RoomState { From f47474d12aa67ffad071a6fd4b6665dc46cf29bf Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 7 Sep 2025 20:23:57 +0100 Subject: [PATCH 2280/2291] fix(PR977): Adjust some log levels --- src/api/server/send_join.rs | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/api/server/send_join.rs b/src/api/server/send_join.rs index a52b5391..3145f9fa 100644 --- a/src/api/server/send_join.rs +++ b/src/api/server/send_join.rs @@ -204,7 +204,7 @@ async fn create_join_event( .lock(room_id) .await; - debug!("Acquired send_join mutex, persisting join event"); + trace!("Acquired send_join mutex, persisting join event"); let pdu_id = services .rooms .event_handler @@ -214,7 +214,7 @@ async fn create_join_event( .ok_or_else(|| err!(Request(InvalidParam("Could not accept as timeline event."))))?; drop(mutex_lock); - debug!("Fetching current state IDs"); + trace!("Fetching current state IDs"); let state_ids: Vec = services .rooms .state_accessor @@ -258,17 +258,6 @@ async fn create_join_event( .rooms .auth_chain .event_ids_iter(room_id, starting_events) - // .broad_filter_map(|event_id| async { - // if omit_members && event_id.as_ref().is_ok_and(|e| state_ids.contains(e)) { - // // Don't include this event if it's already in the state - // trace!( - // "omitting member event {event_id:?} from returned auth chain as it is \ - // already in state" - // ); - // return None; - // } - // Some(event_id) - // }) .broad_and_then(|event_id| async move { services.rooms.timeline.get_pdu_json(&event_id).await }) @@ -281,12 +270,12 @@ async fn create_join_event( .try_collect() .boxed() .await?; - + info!(fast_join = %omit_members, "Sending a join for {origin} to {room_id}"); services.sending.send_pdu_room(room_id, &pdu_id).await?; let servers_in_room: Option> = if !omit_members { None } else { - debug!("Fetching list of servers in room"); + trace!("Fetching list of servers in room"); let servers: Vec = services .rooms .state_cache @@ -296,6 +285,10 @@ async fn create_join_event( .await; // If there's no servers, just add us let servers = if servers.is_empty() { + warn!( + "Failed to find any servers in {room_id}, adding our own server name as a last \ + resort" + ); vec![services.globals.server_name().to_string()] } else { servers @@ -346,7 +339,6 @@ pub(crate) async fn create_join_event_v1_route( } } - info!("Providing send_join for {} in {}", body.origin(), &body.room_id); let now = Instant::now(); let room_state = create_join_event(&services, body.origin(), &body.room_id, &body.pdu, false) .boxed() @@ -357,7 +349,7 @@ pub(crate) async fn create_join_event_v1_route( event: room_state.event, }; info!( - "Finished creating the send_join payload for {} in {} in {:?}", + "Finished sending a join for {} in {} in {:?}", body.origin(), &body.room_id, now.elapsed() @@ -394,14 +386,13 @@ pub(crate) async fn create_join_event_v2_route( } } - info!("Providing send_join for {} in {}", body.origin(), &body.room_id); let now = Instant::now(); let room_state = create_join_event(&services, body.origin(), &body.room_id, &body.pdu, body.omit_members) .boxed() .await?; info!( - "Finished creating the send_join payload for {} in {} in {:?}", + "Finished sending a join for {} in {} in {:?}", body.origin(), &body.room_id, now.elapsed() From d1fff1d09f7343cafd92df9282ff29b3cf9e3545 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 7 Sep 2025 20:26:26 +0100 Subject: [PATCH 2281/2291] perf(pr977): Remove redundant ACL check in send_join --- src/api/server/send_join.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/api/server/send_join.rs b/src/api/server/send_join.rs index 3145f9fa..aa93047b 100644 --- a/src/api/server/send_join.rs +++ b/src/api/server/send_join.rs @@ -56,8 +56,10 @@ async fn create_join_event( // We do not add the event_id field to the pdu here because of signature and // hashes checks + trace!("Getting room version"); let room_version_id = services.rooms.state.get_room_version(room_id).await?; + trace!("Generating event ID and converting to canonical json"); let Ok((event_id, mut value)) = gen_event_id_canonical_json(pdu, &room_version_id) else { // Event could not be converted to canonical json return Err!(Request(BadJson("Could not convert event to canonical json."))); @@ -106,7 +108,6 @@ async fn create_join_event( ))); } - // ACL check sender user server name let sender: OwnedUserId = serde_json::from_value( value .get("sender") @@ -116,12 +117,6 @@ async fn create_join_event( ) .map_err(|e| err!(Request(BadJson(warn!("sender property is not a valid user ID: {e}")))))?; - services - .rooms - .event_handler - .acl_check(sender.server_name(), room_id) - .await?; - // check if origin server is trying to send for another server if sender.server_name() != origin { return Err!(Request(Forbidden("Not allowed to join on behalf of another server."))); From 09de586dc702b9adcb3298e974470066f198c43b Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 7 Sep 2025 20:32:26 +0100 Subject: [PATCH 2282/2291] feat(PR977): Log more things in the join process --- src/api/server/send_join.rs | 41 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/api/server/send_join.rs b/src/api/server/send_join.rs index aa93047b..d92581a1 100644 --- a/src/api/server/send_join.rs +++ b/src/api/server/send_join.rs @@ -178,11 +178,6 @@ async fn create_join_event( } } - services - .server_keys - .hash_and_sign_event(&mut value, &room_version_id) - .map_err(|e| err!(Request(InvalidParam(warn!("Failed to sign send_join event: {e}")))))?; - let origin: OwnedServerName = serde_json::from_value( value .get("origin") @@ -192,6 +187,12 @@ async fn create_join_event( ) .map_err(|e| err!(Request(BadJson("Event has an invalid origin server name: {e}"))))?; + trace!("Signing send_join event"); + services + .server_keys + .hash_and_sign_event(&mut value, &room_version_id) + .map_err(|e| err!(Request(InvalidParam(warn!("Failed to sign send_join event: {e}")))))?; + let mutex_lock = services .rooms .event_handler @@ -218,21 +219,19 @@ async fn create_join_event( .collect() .await; - #[allow(clippy::unnecessary_unwrap)] + trace!(%omit_members, "Constructing current state"); let state = state_ids .iter() .try_stream() .broad_filter_map(|event_id| async move { - if omit_members && event_id.is_ok() { - let pdu = services - .rooms - .timeline - .get_pdu(event_id.as_ref().unwrap()) - .await; - if pdu.is_ok_and(|p| p.kind().to_cow_str() == "m.room.member") { - trace!("omitting member event {event_id:?} from returned state"); - // skip members - return None; + if omit_members { + if let Ok(e) = event_id.as_ref() { + let pdu = services.rooms.timeline.get_pdu(e).await; + if pdu.is_ok_and(|p| p.kind().to_cow_str() == "m.room.member") { + trace!("omitting member event {e:?} from returned state"); + // skip members + return None; + } } } Some(event_id) @@ -249,6 +248,7 @@ async fn create_join_event( .await?; let starting_events = state_ids.iter().map(Borrow::borrow); + trace!("Constructing auth chain"); let auth_chain = services .rooms .auth_chain @@ -265,8 +265,9 @@ async fn create_join_event( .try_collect() .boxed() .await?; - info!(fast_join = %omit_members, "Sending a join for {origin} to {room_id}"); + info!(fast_join = %omit_members, "Sending join event to other servers"); services.sending.send_pdu_room(room_id, &pdu_id).await?; + debug!("Finished sending join event"); let servers_in_room: Option> = if !omit_members { None } else { @@ -280,12 +281,10 @@ async fn create_join_event( .await; // If there's no servers, just add us let servers = if servers.is_empty() { - warn!( - "Failed to find any servers in {room_id}, adding our own server name as a last \ - resort" - ); + warn!("Failed to find any servers, adding our own server name as a last resort"); vec![services.globals.server_name().to_string()] } else { + trace!("Found {} servers in room", servers.len()); servers }; Some(servers) From e3fbf7a143e06528d505a0357e9558944c8bd928 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 8 Jul 2025 17:07:50 +0100 Subject: [PATCH 2283/2291] feat: Ask remote servers for individual unknown events --- src/api/client/room/event.rs | 7 +- src/service/rooms/timeline/backfill.rs | 114 ++++++++++++++++++++++++- 2 files changed, 112 insertions(+), 9 deletions(-) diff --git a/src/api/client/room/event.rs b/src/api/client/room/event.rs index 47228d67..75ae0758 100644 --- a/src/api/client/room/event.rs +++ b/src/api/client/room/event.rs @@ -18,7 +18,7 @@ pub(crate) async fn get_room_event_route( let event = services .rooms .timeline - .get_pdu(event_id) + .get_remote_pdu(room_id, event_id) .map_err(|_| err!(Request(NotFound("Event {} not found.", event_id)))); let visible = services @@ -33,11 +33,6 @@ pub(crate) async fn get_room_event_route( return Err!(Request(Forbidden("You don't have permission to view this event."))); } - debug_assert!( - event.event_id() == event_id && event.room_id() == room_id, - "Fetched PDU must match requested" - ); - event.add_age().ok(); Ok(get_room_event::v3::Response { event: event.into_format() }) diff --git a/src/service/rooms/timeline/backfill.rs b/src/service/rooms/timeline/backfill.rs index e976981e..dd613afd 100644 --- a/src/service/rooms/timeline/backfill.rs +++ b/src/service/rooms/timeline/backfill.rs @@ -1,5 +1,6 @@ use std::iter::once; +use conduwuit::{Err, PduEvent}; use conduwuit_core::{ Result, debug, debug_warn, implement, info, matrix::{ @@ -11,7 +12,7 @@ use conduwuit_core::{ }; use futures::{FutureExt, StreamExt}; use ruma::{ - RoomId, ServerName, + EventId, RoomId, ServerName, api::federation, events::{ StateEventType, TimelineEventType, room::power_levels::RoomPowerLevelsEventContent, @@ -100,7 +101,7 @@ pub async fn backfill_if_required(&self, room_id: &RoomId, from: PduCount) -> Re .boxed(); while let Some(ref backfill_server) = servers.next().await { - info!("Asking {backfill_server} for backfill"); + info!("Asking {backfill_server} for backfill in {room_id}"); let response = self .services .sending @@ -128,10 +129,117 @@ pub async fn backfill_if_required(&self, room_id: &RoomId, from: PduCount) -> Re } } - info!("No servers could backfill, but backfill was needed in room {room_id}"); + warn!("No servers could backfill, but backfill was needed in room {room_id}"); Ok(()) } +#[implement(super::Service)] +#[tracing::instrument(name = "get_remote_pdu", level = "debug", skip(self))] +pub async fn get_remote_pdu(&self, room_id: &RoomId, event_id: &EventId) -> Result { + let local = self.get_pdu(event_id).await; + if local.is_ok() { + // We already have this PDU, no need to backfill + debug!("We already have {event_id} in {room_id}, no need to backfill."); + return local; + } + debug!("Preparing to fetch event {event_id} in room {room_id} from remote servers."); + // Similar to backfill_if_required, but only for a single PDU + // Fetch a list of servers to try + if self + .services + .state_cache + .room_joined_count(room_id) + .await + .is_ok_and(|count| count <= 1) + && !self + .services + .state_accessor + .is_world_readable(room_id) + .await + { + // Room is empty (1 user or none), there is no one that can backfill + return Err!(Request(NotFound("No one can backfill this PDU, room is empty."))); + } + + let power_levels: RoomPowerLevelsEventContent = self + .services + .state_accessor + .room_state_get_content(room_id, &StateEventType::RoomPowerLevels, "") + .await + .unwrap_or_default(); + + let room_mods = power_levels.users.iter().filter_map(|(user_id, level)| { + if level > &power_levels.users_default && !self.services.globals.user_is_local(user_id) { + Some(user_id.server_name()) + } else { + None + } + }); + + let canonical_room_alias_server = once( + self.services + .state_accessor + .get_canonical_alias(room_id) + .await, + ) + .filter_map(Result::ok) + .map(|alias| alias.server_name().to_owned()) + .stream(); + let mut servers = room_mods + .stream() + .map(ToOwned::to_owned) + .chain(canonical_room_alias_server) + .chain( + self.services + .server + .config + .trusted_servers + .iter() + .map(ToOwned::to_owned) + .stream(), + ) + .ready_filter(|server_name| !self.services.globals.server_is_ours(server_name)) + .filter_map(|server_name| async move { + self.services + .state_cache + .server_in_room(&server_name, room_id) + .await + .then_some(server_name) + }) + .boxed(); + + while let Some(ref backfill_server) = servers.next().await { + info!("Asking {backfill_server} for event {}", event_id); + let response = self + .services + .sending + .send_federation_request(backfill_server, federation::event::get_event::v1::Request { + event_id: event_id.to_owned(), + include_unredacted_content: Some(false), + }) + .await; + let pdu = match response { + | Ok(response) => { + self.backfill_pdu(backfill_server, response.pdu) + .boxed() + .await?; + debug!("Successfully backfilled {event_id} from {backfill_server}"); + Some(self.get_pdu(event_id).await) + }, + | Err(e) => { + warn!("{backfill_server} failed to provide backfill for room {room_id}: {e}"); + None + }, + }; + if let Some(pdu) = pdu { + debug!("Fetched {event_id} from {backfill_server}"); + return pdu; + } + } + + Err!("No servers could be used to fetch {} in {}.", room_id, event_id) +} + #[implement(super::Service)] #[tracing::instrument(skip(self, pdu), level = "debug")] pub async fn backfill_pdu(&self, origin: &ServerName, pdu: Box) -> Result<()> { From f3824ffc3d5c2ed6d5067f134850a451564c8f7a Mon Sep 17 00:00:00 2001 From: Ginger Date: Tue, 2 Sep 2025 15:12:03 -0400 Subject: [PATCH 2284/2291] fix: Use `handle_incoming_pdu` directly to keep remote PDUs as outliers --- src/service/rooms/timeline/backfill.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/service/rooms/timeline/backfill.rs b/src/service/rooms/timeline/backfill.rs index dd613afd..c0171691 100644 --- a/src/service/rooms/timeline/backfill.rs +++ b/src/service/rooms/timeline/backfill.rs @@ -2,7 +2,7 @@ use std::iter::once; use conduwuit::{Err, PduEvent}; use conduwuit_core::{ - Result, debug, debug_warn, implement, info, + Result, debug, debug_warn, err, implement, info, matrix::{ event::Event, pdu::{PduCount, PduId, RawPduId}, @@ -12,7 +12,7 @@ use conduwuit_core::{ }; use futures::{FutureExt, StreamExt}; use ruma::{ - EventId, RoomId, ServerName, + CanonicalJsonObject, EventId, RoomId, ServerName, api::federation, events::{ StateEventType, TimelineEventType, room::power_levels::RoomPowerLevelsEventContent, @@ -210,17 +210,26 @@ pub async fn get_remote_pdu(&self, room_id: &RoomId, event_id: &EventId) -> Resu while let Some(ref backfill_server) = servers.next().await { info!("Asking {backfill_server} for event {}", event_id); - let response = self + let value = self .services .sending .send_federation_request(backfill_server, federation::event::get_event::v1::Request { event_id: event_id.to_owned(), include_unredacted_content: Some(false), }) - .await; - let pdu = match response { - | Ok(response) => { - self.backfill_pdu(backfill_server, response.pdu) + .await + .and_then(|response| { + serde_json::from_str::(response.pdu.get()).map_err(|e| { + err!(BadServerResponse(debug_warn!( + "Error parsing incoming event {e:?} from {backfill_server}" + ))) + }) + }); + let pdu = match value { + | Ok(value) => { + self.services + .event_handler + .handle_incoming_pdu(backfill_server, &room_id, &event_id, value, false) .boxed() .await?; debug!("Successfully backfilled {event_id} from {backfill_server}"); From e38dec58648aefec3a289bbfb5043bd1b02e4187 Mon Sep 17 00:00:00 2001 From: Ginger Date: Thu, 4 Sep 2025 10:32:35 -0400 Subject: [PATCH 2285/2291] fix: Put the output of `!admin query room-timeline pdus` in a codeblock --- src/admin/query/room_timeline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/admin/query/room_timeline.rs b/src/admin/query/room_timeline.rs index afcfec34..0f72b58c 100644 --- a/src/admin/query/room_timeline.rs +++ b/src/admin/query/room_timeline.rs @@ -57,5 +57,5 @@ pub(super) async fn pdus( .try_collect() .await?; - self.write_str(&format!("{result:#?}")).await + self.write_str(&format!("```\n{result:#?}\n```")).await } From 16f4efa7089292d27e27e49fc5231a58d020aed3 Mon Sep 17 00:00:00 2001 From: Ginger Date: Thu, 4 Sep 2025 10:33:43 -0400 Subject: [PATCH 2286/2291] fix: Fix pagination tokens being corrupted for backfilled PDUs --- src/api/client/message.rs | 6 +++--- src/api/client/relations.rs | 4 ++-- src/api/client/threads.rs | 4 ++-- src/api/client/utils.rs | 31 +++++------------------------- src/core/matrix/pdu/count.rs | 6 +++++- src/service/rooms/timeline/data.rs | 3 +-- 6 files changed, 18 insertions(+), 36 deletions(-) diff --git a/src/api/client/message.rs b/src/api/client/message.rs index f5a951f4..0145b7fe 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -35,7 +35,7 @@ use ruma::{ }; use tracing::warn; -use super::utils::{count_to_token, parse_pagination_token as parse_token}; +use super::utils::{count_to_pagination_token, pagination_token_to_count as parse_token}; use crate::Ruma; /// list of safe and common non-state events to ignore if the user is ignored @@ -181,8 +181,8 @@ pub(crate) async fn get_message_events_route( .collect(); Ok(get_message_events::v3::Response { - start: count_to_token(from), - end: next_token.map(count_to_token), + start: count_to_pagination_token(from), + end: next_token.map(count_to_pagination_token), chunk, state, }) diff --git a/src/api/client/relations.rs b/src/api/client/relations.rs index f6d8fe9e..f2ec3f23 100644 --- a/src/api/client/relations.rs +++ b/src/api/client/relations.rs @@ -18,7 +18,7 @@ use ruma::{ events::{TimelineEventType, relation::RelationType}, }; -use super::utils::{count_to_token, parse_pagination_token as parse_token}; +use super::utils::{count_to_pagination_token, pagination_token_to_count as parse_token}; use crate::Ruma; /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}` @@ -193,7 +193,7 @@ async fn paginate_relations_with_filter( | Direction::Forward => events.last(), | Direction::Backward => events.first(), } - .map(|(count, _)| count_to_token(*count)) + .map(|(count, _)| count_to_pagination_token(*count)) } else { None }; diff --git a/src/api/client/threads.rs b/src/api/client/threads.rs index ca176eda..f0fb4a64 100644 --- a/src/api/client/threads.rs +++ b/src/api/client/threads.rs @@ -9,7 +9,7 @@ use conduwuit::{ use futures::StreamExt; use ruma::{api::client::threads::get_threads, uint}; -use crate::Ruma; +use crate::{Ruma, client::utils::pagination_token_to_count}; /// # `GET /_matrix/client/r0/rooms/{roomId}/threads` pub(crate) async fn get_threads_route( @@ -27,7 +27,7 @@ pub(crate) async fn get_threads_route( let from: PduCount = body .from .as_deref() - .map(str::parse) + .map(pagination_token_to_count) .transpose()? .unwrap_or_else(PduCount::max); diff --git a/src/api/client/utils.rs b/src/api/client/utils.rs index cc941b95..ec69388a 100644 --- a/src/api/client/utils.rs +++ b/src/api/client/utils.rs @@ -1,28 +1,7 @@ -use conduwuit::{ - Result, err, - matrix::pdu::{PduCount, ShortEventId}, -}; +use conduwuit::{Result, matrix::pdu::PduCount}; -/// Parse a pagination token, trying ShortEventId first, then falling back to -/// PduCount -pub(crate) fn parse_pagination_token(token: &str) -> Result { - // Try parsing as ShortEventId first - if let Ok(shorteventid) = token.parse::() { - // ShortEventId maps directly to a PduCount in our database - Ok(PduCount::Normal(shorteventid)) - } else if let Ok(count) = token.parse::() { - // Fallback to PduCount for backwards compatibility - Ok(PduCount::Normal(count)) - } else if let Ok(count) = token.parse::() { - // Also handle negative counts for backfilled events - Ok(PduCount::from_signed(count)) - } else { - Err(err!(Request(InvalidParam("Invalid pagination token")))) - } -} +/// Parse a pagination token +pub(crate) fn pagination_token_to_count(token: &str) -> Result { token.parse() } -/// Convert a PduCount to a token string (using the underlying ShortEventId) -pub(crate) fn count_to_token(count: PduCount) -> String { - // The PduCount's unsigned value IS the ShortEventId - count.into_unsigned().to_string() -} +/// Convert a PduCount to a token string +pub(crate) fn count_to_pagination_token(count: PduCount) -> String { count.to_string() } diff --git a/src/core/matrix/pdu/count.rs b/src/core/matrix/pdu/count.rs index b880278f..7fb12574 100644 --- a/src/core/matrix/pdu/count.rs +++ b/src/core/matrix/pdu/count.rs @@ -1,6 +1,10 @@ #![allow(clippy::cast_possible_wrap, clippy::cast_sign_loss, clippy::as_conversions)] -use std::{cmp::Ordering, fmt, fmt::Display, str::FromStr}; +use std::{ + cmp::Ordering, + fmt::{self, Display}, + str::FromStr, +}; use ruma::api::Direction; diff --git a/src/service/rooms/timeline/data.rs b/src/service/rooms/timeline/data.rs index fa10a5c0..9064df6c 100644 --- a/src/service/rooms/timeline/data.rs +++ b/src/service/rooms/timeline/data.rs @@ -3,8 +3,7 @@ use std::{borrow::Borrow, sync::Arc}; use conduwuit::{ Err, PduCount, PduEvent, Result, at, err, result::{LogErr, NotFound}, - utils, - utils::stream::TryReadyExt, + utils::{self, stream::TryReadyExt}, }; use database::{Database, Deserialized, Json, KeyVal, Map}; use futures::{FutureExt, Stream, TryFutureExt, TryStreamExt, future::select_ok, pin_mut}; From e27ef7f5ec5e95c33f06c1f5d06cd16ca266cd07 Mon Sep 17 00:00:00 2001 From: Ginger Date: Thu, 4 Sep 2025 10:46:08 -0400 Subject: [PATCH 2287/2291] feat: Do not persist remote PDUs fetched with admin commands --- src/admin/debug/commands.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index 81b0e9da..64f68330 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -281,15 +281,8 @@ pub(super) async fn get_remote_pdu( vec![(event_id, value, room_id)] }; - info!("Attempting to handle event ID {event_id} as backfilled PDU"); - self.services - .rooms - .timeline - .backfill_pdu(&server, response.pdu) - .await?; - let text = serde_json::to_string_pretty(&json)?; - let msg = "Got PDU from specified server and handled as backfilled"; + let msg = "Got PDU from specified server:"; write!(self, "{msg}. Event body:\n```json\n{text}\n```") }, } From 90fd92977e6dca4cad4625d8383eb9a42c0f4b4b Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 7 Sep 2025 22:08:37 +0100 Subject: [PATCH 2288/2291] style: Run clippy --- src/service/rooms/timeline/backfill.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/rooms/timeline/backfill.rs b/src/service/rooms/timeline/backfill.rs index c0171691..9dfe8f7a 100644 --- a/src/service/rooms/timeline/backfill.rs +++ b/src/service/rooms/timeline/backfill.rs @@ -229,7 +229,7 @@ pub async fn get_remote_pdu(&self, room_id: &RoomId, event_id: &EventId) -> Resu | Ok(value) => { self.services .event_handler - .handle_incoming_pdu(backfill_server, &room_id, &event_id, value, false) + .handle_incoming_pdu(backfill_server, room_id, event_id, value, false) .boxed() .await?; debug!("Successfully backfilled {event_id} from {backfill_server}"); From 1e541875ad94fcacca268515569c1cb32879b205 Mon Sep 17 00:00:00 2001 From: Ginger Date: Sun, 7 Sep 2025 18:06:11 -0400 Subject: [PATCH 2289/2291] fix: Nuke `src/api/client/utils.rs` --- src/api/client/message.rs | 9 ++++----- src/api/client/mod.rs | 1 - src/api/client/relations.rs | 7 +++---- src/api/client/threads.rs | 4 ++-- src/api/client/utils.rs | 7 ------- 5 files changed, 9 insertions(+), 19 deletions(-) delete mode 100644 src/api/client/utils.rs diff --git a/src/api/client/message.rs b/src/api/client/message.rs index 0145b7fe..842036f5 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -35,7 +35,6 @@ use ruma::{ }; use tracing::warn; -use super::utils::{count_to_pagination_token, pagination_token_to_count as parse_token}; use crate::Ruma; /// list of safe and common non-state events to ignore if the user is ignored @@ -85,14 +84,14 @@ pub(crate) async fn get_message_events_route( let from: PduCount = body .from .as_deref() - .map(parse_token) + .map(str::parse) .transpose()? .unwrap_or_else(|| match body.dir { | Direction::Forward => PduCount::min(), | Direction::Backward => PduCount::max(), }); - let to: Option = body.to.as_deref().map(parse_token).transpose()?; + let to: Option = body.to.as_deref().map(str::parse).transpose()?; let limit: usize = body .limit @@ -181,8 +180,8 @@ pub(crate) async fn get_message_events_route( .collect(); Ok(get_message_events::v3::Response { - start: count_to_pagination_token(from), - end: next_token.map(count_to_pagination_token), + start: from.to_string(), + end: next_token.as_ref().map(PduCount::to_string), chunk, state, }) diff --git a/src/api/client/mod.rs b/src/api/client/mod.rs index c8ca7757..0014282c 100644 --- a/src/api/client/mod.rs +++ b/src/api/client/mod.rs @@ -37,7 +37,6 @@ pub(super) mod typing; pub(super) mod unstable; pub(super) mod unversioned; pub(super) mod user_directory; -pub(super) mod utils; pub(super) mod voip; pub(super) mod well_known; diff --git a/src/api/client/relations.rs b/src/api/client/relations.rs index f2ec3f23..79fa1459 100644 --- a/src/api/client/relations.rs +++ b/src/api/client/relations.rs @@ -18,7 +18,6 @@ use ruma::{ events::{TimelineEventType, relation::RelationType}, }; -use super::utils::{count_to_pagination_token, pagination_token_to_count as parse_token}; use crate::Ruma; /// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}` @@ -111,14 +110,14 @@ async fn paginate_relations_with_filter( dir: Direction, ) -> Result { let start: PduCount = from - .map(parse_token) + .map(str::parse) .transpose()? .unwrap_or_else(|| match dir { | Direction::Forward => PduCount::min(), | Direction::Backward => PduCount::max(), }); - let to: Option = to.map(parse_token).transpose()?; + let to: Option = to.map(str::parse).transpose()?; // Use limit or else 30, with maximum 100 let limit: usize = limit @@ -193,7 +192,7 @@ async fn paginate_relations_with_filter( | Direction::Forward => events.last(), | Direction::Backward => events.first(), } - .map(|(count, _)| count_to_pagination_token(*count)) + .map(|(count, _)| count.to_string()) } else { None }; diff --git a/src/api/client/threads.rs b/src/api/client/threads.rs index f0fb4a64..ca176eda 100644 --- a/src/api/client/threads.rs +++ b/src/api/client/threads.rs @@ -9,7 +9,7 @@ use conduwuit::{ use futures::StreamExt; use ruma::{api::client::threads::get_threads, uint}; -use crate::{Ruma, client::utils::pagination_token_to_count}; +use crate::Ruma; /// # `GET /_matrix/client/r0/rooms/{roomId}/threads` pub(crate) async fn get_threads_route( @@ -27,7 +27,7 @@ pub(crate) async fn get_threads_route( let from: PduCount = body .from .as_deref() - .map(pagination_token_to_count) + .map(str::parse) .transpose()? .unwrap_or_else(PduCount::max); diff --git a/src/api/client/utils.rs b/src/api/client/utils.rs deleted file mode 100644 index ec69388a..00000000 --- a/src/api/client/utils.rs +++ /dev/null @@ -1,7 +0,0 @@ -use conduwuit::{Result, matrix::pdu::PduCount}; - -/// Parse a pagination token -pub(crate) fn pagination_token_to_count(token: &str) -> Result { token.parse() } - -/// Convert a PduCount to a token string -pub(crate) fn count_to_pagination_token(count: PduCount) -> String { count.to_string() } From 5d3e10a0481f4857cc706068c0d0c04d44ee9105 Mon Sep 17 00:00:00 2001 From: Ginger Date: Sun, 7 Sep 2025 18:07:03 -0400 Subject: [PATCH 2290/2291] fix: Make RA use the `full` feature --- .vscode/settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a4fad964..82162ff7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,6 @@ "continuwuity", "homeserver", "homeservers" - ] + ], + "rust-analyzer.cargo.features": ["full"] } From 8f186cd770ebb088aa85f0aacea7f41a046c2054 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 8 Sep 2025 05:02:33 +0000 Subject: [PATCH 2291/2291] chore(deps): update https://github.com/renovatebot/github-action action to v43.0.11 --- .forgejo/workflows/renovate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/renovate.yml b/.forgejo/workflows/renovate.yml index 0152b387..6c898657 100644 --- a/.forgejo/workflows/renovate.yml +++ b/.forgejo/workflows/renovate.yml @@ -70,7 +70,7 @@ jobs: package-cache- - name: Self-hosted Renovate - uses: https://github.com/renovatebot/github-action@v43.0.9 + uses: https://github.com/renovatebot/github-action@v43.0.11 env: LOG_LEVEL: ${{ inputs.logLevel || 'info' }} RENOVATE_DRY_RUN: ${{ inputs.dryRun || 'false' }}