From 4e197315d20566ab099c299ec0750d2becc0ce07 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 11 May 2024 03:27:43 -0400 Subject: [PATCH 0001/1964] experiment with coroutines/folly https://github.com/girlbossceo/rust-rocksdb-zaidoon1/commit/9ecb597d966efb37ed96f4cfe3f09165013fd14a Signed-off-by: strawberry --- Cargo.lock | 223 ++++++++++++++++++--------------- Cargo.toml | 4 +- src/database/rocksdb/kvtree.rs | 9 ++ 3 files changed, 130 insertions(+), 106 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 20352010..7c2a91fd 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]] @@ -951,6 +951,17 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "find-folly" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d8bf7ad55e1e290ef089eaaa62c5ac3b86c5c6279c37fa67943937d108b01ef" +dependencies = [ + "pkg-config", + "shlex", + "thiserror", +] + [[package]] name = "findshlibs" version = "0.10.2" @@ -1048,7 +1059,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -1092,9 +1103,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", @@ -1368,7 +1379,7 @@ dependencies = [ "markup5ever", "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -2051,9 +2062,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 +2076,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 +2111,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 +2122,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 +2134,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 +2306,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 +2330,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -2410,7 +2423,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -2489,9 +2502,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 +2517,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", "version_check", "yansi", ] @@ -2521,15 +2534,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 +2735,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 +2755,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 +2767,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 +2789,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 +2819,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 +2841,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 +2853,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 +2862,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 +2872,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 +2881,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 +2899,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 +2915,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", @@ -2931,11 +2944,12 @@ 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/girlbossceo/rust-rocksdb-zaidoon1?rev=9ecb597d966efb37ed96f4cfe3f09165013fd14a#9ecb597d966efb37ed96f4cfe3f09165013fd14a" dependencies = [ "bindgen", "bzip2-sys", "cc", + "find-folly", "glob", "libc", "libz-sys", @@ -2948,7 +2962,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/girlbossceo/rust-rocksdb-zaidoon1?rev=9ecb597d966efb37ed96f4cfe3f09165013fd14a#9ecb597d966efb37ed96f4cfe3f09165013fd14a" dependencies = [ "libc", "rust-librocksdb-sys", @@ -2956,9 +2970,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 +3040,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 +3067,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 +3129,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 +3142,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 +3152,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" @@ -3294,7 +3308,7 @@ checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -3560,9 +3574,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", @@ -3609,7 +3623,7 @@ checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -3758,7 +3772,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", ] [[package]] @@ -3807,15 +3821,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 +3875,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.8", + "winnow 0.6.7", ] [[package]] @@ -3963,7 +3978,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 +4249,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", "wasm-bindgen-shared", ] @@ -4268,7 +4283,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 2.0.60", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4554,9 +4569,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", ] @@ -4600,22 +4615,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..aed047e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -298,8 +298,8 @@ version = "0.24.1" default-features = false [dependencies.rust-rocksdb] -git = "https://github.com/zaidoon1/rust-rocksdb" -rev = "c5cd6bd25152ef1f8a488761351da0c3d29ed93a" +git = "https://github.com/girlbossceo/rust-rocksdb-zaidoon1" +rev = "9ecb597d966efb37ed96f4cfe3f09165013fd14a" #branch = "master" optional = true default-features = true 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 fe637f481d3dab691f1a755ce590d4b21b688041 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sat, 11 May 2024 03:41:47 -0400 Subject: [PATCH 0002/1964] 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 0003/1964] 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 0004/1964] 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 0005/1964] 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 0006/1964] 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 0007/1964] 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 0008/1964] 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 0009/1964] 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 0010/1964] 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 0011/1964] 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 0012/1964] 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 0013/1964] 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 0014/1964] 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 0015/1964] 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 0016/1964] 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 0017/1964] 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 0018/1964] 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 0019/1964] 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 0020/1964] 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 0021/1964] 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 0022/1964] 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 0023/1964] 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 0024/1964] 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 0025/1964] 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 0026/1964] 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 0027/1964] 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 0028/1964] 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 0029/1964] 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 0030/1964] 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 0031/1964] 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 0032/1964] 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 0033/1964] 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 0034/1964] 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 0035/1964] 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 0036/1964] 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 0037/1964] 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 0038/1964] 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 0039/1964] 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 0040/1964] 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 0041/1964] 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 0042/1964] 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 0043/1964] 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 0044/1964] 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 0045/1964] 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 0046/1964] 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 0047/1964] 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 0048/1964] 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 0049/1964] 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 0050/1964] 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 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 z 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

From e3ae024ed37ce869e66a45f1d567b54600a90cf7 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Thu, 1 May 2025 21:21:28 +0100 Subject: [PATCH 1913/1964] 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 1914/1964] 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 1915/1964] 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 1916/1964] 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 1917/1964] 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 1918/1964] 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 1919/1964] 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 1920/1964] 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 1921/1964] 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 1922/1964] 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 1923/1964] 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 1924/1964] 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 1925/1964] 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 1926/1964] 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 1927/1964] 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 1928/1964] 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 1929/1964] 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 1930/1964] 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 1931/1964] 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 1932/1964] 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 1933/1964] 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 1934/1964] 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 1935/1964] 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 1936/1964] 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 1937/1964] 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 1938/1964] 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 1939/1964] 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 1940/1964] 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 ~%}