mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-20 23:47:33 +00:00
Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24d515a9a1 | ||
|
|
db68679a23 | ||
|
|
e06bb0f2e0 | ||
|
|
342ea6994b | ||
|
|
cf38eb74bf | ||
|
|
e1449ff6c0 | ||
|
|
a1e89eb04d | ||
|
|
8db6f7a2e2 | ||
|
|
2a66d3b39f | ||
|
|
3b55b750cb | ||
|
|
0228de55bd | ||
|
|
57a0104ad0 | ||
|
|
79dd7737a8 | ||
|
|
95e75f8363 | ||
|
|
331c7c1b5d | ||
|
|
b4479456fc | ||
|
|
c0e54218c8 | ||
|
|
a085212e71 | ||
|
|
7bf59e1dc0 | ||
|
|
3d66198699 | ||
|
|
3082063026 |
No files matched your search
@@ -51,7 +51,7 @@ repos:
|
||||
hooks:
|
||||
- id: cargo-clippy
|
||||
name: cargo clippy
|
||||
entry: cargo clippy -- -D warnings
|
||||
entry: cargo clippy --
|
||||
language: system
|
||||
pass_filenames: false
|
||||
types: [ rust ]
|
||||
|
||||
Generated
+129
-95
@@ -485,18 +485,19 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.73.2"
|
||||
version = "0.72.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "787ef8ef523575546b106a58213d6e6b06198a05c2f757258c68a74273670cfa"
|
||||
checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"itertools 0.13.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"shlex 1.3.0",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
@@ -604,9 +605,9 @@ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.12.2"
|
||||
version = "1.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c"
|
||||
checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
|
||||
|
||||
[[package]]
|
||||
name = "bytesize"
|
||||
@@ -683,7 +684,7 @@ dependencies = [
|
||||
"find-msvc-tools",
|
||||
"jobserver",
|
||||
"libc",
|
||||
"shlex",
|
||||
"shlex 2.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -764,9 +765,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.6.8"
|
||||
version = "4.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac230478587d0269d8d6998b82ae69ea51509d55df66d9e92edd1f986904cd4a"
|
||||
checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@@ -784,9 +785,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.6.8"
|
||||
version = "4.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "895c9d8d2ac2dd8b8a29f3724a14e72aaaa6debcf8c38c82f97305c6a172767a"
|
||||
checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
@@ -873,9 +874,13 @@ dependencies = [
|
||||
name = "conduwuit"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"clap",
|
||||
"conduwuit_admin",
|
||||
"conduwuit_api",
|
||||
"conduwuit_build_metadata",
|
||||
"conduwuit_core",
|
||||
"conduwuit_database",
|
||||
"conduwuit_macros",
|
||||
"conduwuit_router",
|
||||
"conduwuit_service",
|
||||
@@ -883,6 +888,8 @@ dependencies = [
|
||||
"const-str",
|
||||
"ctor",
|
||||
"dtor",
|
||||
"hardened_malloc-rs",
|
||||
"log",
|
||||
"opentelemetry",
|
||||
"opentelemetry-otlp",
|
||||
"opentelemetry-prometheus",
|
||||
@@ -890,10 +897,13 @@ dependencies = [
|
||||
"opentelemetry_sdk",
|
||||
"parking_lot",
|
||||
"prometheus",
|
||||
"reqwest 0.13.5",
|
||||
"rustls",
|
||||
"sentry",
|
||||
"sentry-tower",
|
||||
"sentry-tracing",
|
||||
"tokio",
|
||||
"tokio-metrics",
|
||||
"tracing",
|
||||
"tracing-flame",
|
||||
"tracing-journald",
|
||||
@@ -946,7 +956,7 @@ dependencies = [
|
||||
"hyper",
|
||||
"itertools 0.15.0",
|
||||
"lettre",
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"reqwest 0.13.5",
|
||||
"ruma",
|
||||
"ruminuwuity",
|
||||
@@ -998,7 +1008,7 @@ dependencies = [
|
||||
"ipaddress",
|
||||
"lettre",
|
||||
"libc",
|
||||
"libloading 0.9.1",
|
||||
"libloading 0.9.0",
|
||||
"lock_api 0.5.0",
|
||||
"maplit",
|
||||
"nix",
|
||||
@@ -1010,7 +1020,7 @@ dependencies = [
|
||||
"opentelemetry_sdk",
|
||||
"parking_lot",
|
||||
"prometheus",
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"regex",
|
||||
"reqwest 0.13.5",
|
||||
"resolvematrix",
|
||||
@@ -1131,9 +1141,8 @@ dependencies = [
|
||||
"openidconnect",
|
||||
"opentelemetry",
|
||||
"p256 0.14.0",
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"regex",
|
||||
"reqwest 0.12.28",
|
||||
"reqwest 0.13.5",
|
||||
"resolvematrix",
|
||||
"ruma",
|
||||
@@ -1525,9 +1534,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ctor"
|
||||
version = "1.0.14"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea691ed9f36489d087419b8b2ba3ef27d89621380b4178c73e2445a379e4e0f4"
|
||||
checksum = "914a755b7c2d4af2bdcff7ce1739e2db9a1b81a9b07123d8015786ae03c0980d"
|
||||
dependencies = [
|
||||
"link-section",
|
||||
"linktime-proc-macro",
|
||||
@@ -1784,11 +1793,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "dtor"
|
||||
version = "1.0.7"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "915e80ae7aca23bef767ded8e4a763d0c912c2faaa8bfec1e66d505ebaceb254"
|
||||
checksum = "cd3f6c362b2bbd7063090886afd78978f5dbf1f11da7efcc40f81d32c943fac1"
|
||||
dependencies = [
|
||||
"link-section",
|
||||
"linktime-proc-macro",
|
||||
]
|
||||
|
||||
@@ -1922,9 +1930,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "email-encoding"
|
||||
version = "0.4.3"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f690ae2169f2ceb3f45b28b6fcd8fa16839f2f5c8818546774b9425f5f71004"
|
||||
checksum = "420b9da095f052ea597503e39073b5b3c522f7db933fbac202d91d24492693fd"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"memchr",
|
||||
@@ -2318,9 +2326,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "granit-parser"
|
||||
version = "2.2.0"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9bd04d0d9c7079b416b458d2317aea4aa964c81938cb7c20f559758c4f422dc8"
|
||||
checksum = "05f05586d4d4df3d47123207826c40b252728b438a1a07bad3c01ee6bea401df"
|
||||
dependencies = [
|
||||
"arraydeque",
|
||||
"smallvec",
|
||||
@@ -2495,7 +2503,7 @@ dependencies = [
|
||||
"idna",
|
||||
"ipnet",
|
||||
"jni",
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"thiserror 2.0.21",
|
||||
"tinyvec",
|
||||
"tokio",
|
||||
@@ -2515,7 +2523,7 @@ dependencies = [
|
||||
"jni",
|
||||
"once_cell",
|
||||
"prefix-trie",
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"ring",
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2541,7 +2549,7 @@ dependencies = [
|
||||
"ndk-context",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"resolv-conf",
|
||||
"serde",
|
||||
"smallvec",
|
||||
@@ -2711,10 +2719,10 @@ dependencies = [
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"rustls",
|
||||
"rustls-native-certs",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tower-service",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2954,9 +2962,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ipaddress"
|
||||
version = "0.2.13"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0ae5a9c049476ef23026df39fe92a8d83c1d8b670b975f095cb4d5a3b13d43e"
|
||||
checksum = "67a97d7409c3ade4304acbff6b33b915af4564c42bf6e383651ced09bd6a2bce"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"libc",
|
||||
@@ -2988,6 +2996,15 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.14.0"
|
||||
@@ -3196,9 +3213,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lettre"
|
||||
version = "0.11.24"
|
||||
version = "0.11.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f294f3d7cdb313e578acef7d7727d4e8d897e0fcd0d6d58c19959cec95073f19"
|
||||
checksum = "f2c646bd5cc763b1087b15493e29a64be6147ba8f19342004fa52048ee596eae"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.23.1",
|
||||
@@ -3242,9 +3259,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.9.1"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1832accd5a4ca2795ace4d05d15c4039be15b62d3b950eff99746a990e3cc10"
|
||||
checksum = "754ca22de805bb5744484a5b151a9e1a8e837d5dc232c2d7d8c2e3492edc8b60"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-link",
|
||||
@@ -3258,9 +3275,9 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
||||
|
||||
[[package]]
|
||||
name = "libz-sys"
|
||||
version = "1.1.32"
|
||||
version = "1.1.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69965d2409bff8c8cea3829009fff66a86f05a0570656552ef70f616e8e4bd85"
|
||||
checksum = "85bc9657773828b90eeb625adff10eeac83cc21bbfd8e23a03eaa8a33c9e28d9"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
@@ -3269,9 +3286,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "link-section"
|
||||
version = "0.19.4"
|
||||
version = "0.19.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d9aae57673c1a235149777a74d152f3210ebd3e3b13346d2cdb6809e566bd3c"
|
||||
checksum = "39c29a617ce3df32c08497bdc1ab6e2376e0b17948ac166a2fbe5977c5954cd9"
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
@@ -4171,6 +4188,12 @@ dependencies = [
|
||||
"phc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "pear"
|
||||
version = "0.2.9"
|
||||
@@ -4618,7 +4641,7 @@ dependencies = [
|
||||
"bytes",
|
||||
"getrandom 0.4.3",
|
||||
"lru-slab",
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"rand_pcg",
|
||||
"ring",
|
||||
"rustc-hash",
|
||||
@@ -4695,9 +4718,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.10.4"
|
||||
version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f6fa277c67e6ea590466f04c3fe82cb509f0864fe470643e5570de9514a9b11"
|
||||
checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af"
|
||||
dependencies = [
|
||||
"chacha20",
|
||||
"getrandom 0.4.3",
|
||||
@@ -4788,9 +4811,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.13.2"
|
||||
version = "1.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
|
||||
checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -4800,9 +4823,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.19"
|
||||
version = "0.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
|
||||
checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -4811,9 +4834,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.12"
|
||||
version = "0.8.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
|
||||
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
@@ -4834,8 +4857,8 @@ dependencies = [
|
||||
"log",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"quinn",
|
||||
"rustls",
|
||||
"rustls-native-certs",
|
||||
"rustls-pki-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -4850,6 +4873,7 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5045,7 +5069,7 @@ dependencies = [
|
||||
"js_int",
|
||||
"konst",
|
||||
"percent-encoding",
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"regex",
|
||||
"ruma-identifiers-validation",
|
||||
"ruma-macros",
|
||||
@@ -5095,7 +5119,7 @@ dependencies = [
|
||||
"js_int",
|
||||
"memchr",
|
||||
"mime",
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"ruma-common",
|
||||
"ruma-events",
|
||||
"ruma-signatures",
|
||||
@@ -5151,7 +5175,7 @@ dependencies = [
|
||||
"ed25519-dalek",
|
||||
"memchr",
|
||||
"pkcs8 0.11.0",
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"ruma-common",
|
||||
"ruma-events",
|
||||
"serde_json",
|
||||
@@ -5188,8 +5212,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rust-librocksdb-sys"
|
||||
version = "0.49.0+11.12.0"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=6021299f3e0e9455dc3f2e39c65e1dc217be8903#6021299f3e0e9455dc3f2e39c65e1dc217be8903"
|
||||
version = "0.45.1+11.1.1"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=0a25ff92f7c09b55eec496b9c192c7d5136ab2b8#0a25ff92f7c09b55eec496b9c192c7d5136ab2b8"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"bzip2-sys",
|
||||
@@ -5199,15 +5223,14 @@ dependencies = [
|
||||
"libz-sys",
|
||||
"lz4-sys",
|
||||
"pkg-config",
|
||||
"rustflags",
|
||||
"tikv-jemalloc-sys",
|
||||
"zstd-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-rocksdb"
|
||||
version = "0.54.0"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=6021299f3e0e9455dc3f2e39c65e1dc217be8903#6021299f3e0e9455dc3f2e39c65e1dc217be8903"
|
||||
version = "0.49.1"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=0a25ff92f7c09b55eec496b9c192c7d5136ab2b8#0a25ff92f7c09b55eec496b9c192c7d5136ab2b8"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"parking_lot",
|
||||
@@ -5235,12 +5258,6 @@ dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustflags"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a39e0e9135d7a7208ee80aa4e3e4b88f0f5ad7be92153ed70686c38a03db2e63"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "1.1.6"
|
||||
@@ -5486,9 +5503,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sentry"
|
||||
version = "0.49.6"
|
||||
version = "0.49.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7bc7fb14982f395d53924f4feebd48c6cc136399c49ac2160dcf2b260e74b75"
|
||||
checksum = "e7c2c887f17023c9462a4202176efc33ca7228f9c30c0141c765ab534ab2d36b"
|
||||
dependencies = [
|
||||
"cfg_aliases",
|
||||
"httpdate",
|
||||
@@ -5506,9 +5523,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sentry-backtrace"
|
||||
version = "0.49.6"
|
||||
version = "0.49.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f68328b53eb7defc20f993ed7cd1f4ce10d06feecefdf914db062ce2523e4b77"
|
||||
checksum = "c391d4330f3b37fdddf2b928151244e8c2dc0cfea1740e455cc8942af436f919"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"regex",
|
||||
@@ -5517,9 +5534,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sentry-contexts"
|
||||
version = "0.49.6"
|
||||
version = "0.49.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d57fb52d1e5d76cc5a7415428004699d9e6d498859a7acc8e05becc57dad81f"
|
||||
checksum = "654dacb94135c713e1dcbff01314a83d333f0e62f76b91fed5ab87415075530c"
|
||||
dependencies = [
|
||||
"hostname",
|
||||
"libc",
|
||||
@@ -5531,21 +5548,22 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sentry-core"
|
||||
version = "0.49.6"
|
||||
version = "0.49.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8367f7f31654b35453e20c8aca06e0ecf5a4d4793e33be139c1581e475a94e6a"
|
||||
checksum = "edcb294ca821e5c5624edaf33535eb18b06ef4f8675201d3e4d81ce325741692"
|
||||
dependencies = [
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"sentry-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sentry-debug-images"
|
||||
version = "0.49.6"
|
||||
version = "0.49.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "386f4ce2364e58f2ca811f388a0427fa13784bbe7aee85f302e901ef4b00fab9"
|
||||
checksum = "74835055f6a57b78c0e13f941b460e39edc1899b05fe31dd47cd02367f70888f"
|
||||
dependencies = [
|
||||
"findshlibs",
|
||||
"sentry-core",
|
||||
@@ -5553,9 +5571,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sentry-log"
|
||||
version = "0.49.6"
|
||||
version = "0.49.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c938358d54c65a79fea165a447ae0eabc5717f23ba482ceee279c5645f0ccad3"
|
||||
checksum = "f24141aaeb20c731719b33077f1063a79e07eef63a4954530559c067ba046aad"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"log",
|
||||
@@ -5564,9 +5582,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sentry-panic"
|
||||
version = "0.49.6"
|
||||
version = "0.49.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ab095af8f107e893941f857d8e204f5d25404247c34af131c7d199e3021679f"
|
||||
checksum = "f5d28522f81ed90510ec43ed01cb1873a393b329dc719f93335b4c75fbef05d1"
|
||||
dependencies = [
|
||||
"sentry-backtrace",
|
||||
"sentry-core",
|
||||
@@ -5574,9 +5592,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sentry-tower"
|
||||
version = "0.49.6"
|
||||
version = "0.49.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18f29b19179ae36e6318c71f6ee18d1e0db8bbe8e7b7f213c2aba9e721b650fb"
|
||||
checksum = "057730796d82b72f35f57e66fc41c2b9e334eb3edf5030dd18d3b1f88d062c78"
|
||||
dependencies = [
|
||||
"http",
|
||||
"pin-project",
|
||||
@@ -5588,9 +5606,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sentry-tracing"
|
||||
version = "0.49.6"
|
||||
version = "0.49.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7cae82b121a812e69a1cfaaacb800112f5f261f362fbf5a08e13d1c11ef349e"
|
||||
checksum = "ec67c296aadc41d4d41b64738908c51cacddf99edebe7a2b476f9bf40de93ff5"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"sentry-backtrace",
|
||||
@@ -5601,13 +5619,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sentry-types"
|
||||
version = "0.49.6"
|
||||
version = "0.49.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03da7c1f79d001b4f18e277f8207470efb262fb94c761baa195873d2ace8eb8a"
|
||||
checksum = "83d84a36b6bdeeb7813976fb899fca45d94540d2e2b80eac91ba66b4c654d8f0"
|
||||
dependencies = [
|
||||
"debugid",
|
||||
"hex",
|
||||
"rand 0.10.4",
|
||||
"rand 0.10.3",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
@@ -5628,12 +5646,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde-saphyr"
|
||||
version = "2.2.0"
|
||||
version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "969cde0349344dbbf58b5f9badbfb8f806db13969364eb8007c057ef687007d9"
|
||||
checksum = "d43fb82d550b07e6f929a58d7d0935182602f48ddead875f5ee313c41c8f07fe"
|
||||
dependencies = [
|
||||
"annotate-snippets",
|
||||
"base64 0.22.1",
|
||||
"base64 0.23.1",
|
||||
"encoding_rs_io",
|
||||
"granit-parser",
|
||||
"nohash-hasher",
|
||||
@@ -5868,6 +5886,12 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "2.0.1"
|
||||
@@ -5971,9 +5995,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.16.6"
|
||||
version = "1.16.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59"
|
||||
checksum = "149309498a5f7334b12ddae0cad8aba81ce785fe91755068867e017cf98fee46"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
@@ -6227,17 +6251,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tikv-jemalloc-ctl"
|
||||
version = "0.7.0"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=ac4d4861b335b199f812807996e8c9166961041a#ac4d4861b335b199f812807996e8c9166961041a"
|
||||
version = "0.6.1"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554#df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"paste",
|
||||
"tikv-jemalloc-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tikv-jemalloc-sys"
|
||||
version = "0.7.0+5.4.0-0-g7a34f18502e7b222724097cdcd499b437d189acc"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=ac4d4861b335b199f812807996e8c9166961041a#ac4d4861b335b199f812807996e8c9166961041a"
|
||||
version = "0.6.1+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554#df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
@@ -6245,8 +6270,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tikv-jemallocator"
|
||||
version = "0.7.0"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=ac4d4861b335b199f812807996e8c9166961041a#ac4d4861b335b199f812807996e8c9166961041a"
|
||||
version = "0.6.1"
|
||||
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554#df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"tikv-jemalloc-sys",
|
||||
@@ -7104,6 +7129,15 @@ dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5f280bbb2b287bc8e7de7e3852945a0ff50d1bbcb5ed42b6c7a568c546df171"
|
||||
dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "weezl"
|
||||
version = "0.1.12"
|
||||
|
||||
+4
-15
@@ -166,15 +166,6 @@ features = [
|
||||
"form",
|
||||
]
|
||||
|
||||
# Needed for as long as openidconnect is on an outdated reqwest
|
||||
[workspace.dependencies.reqwest_0_12]
|
||||
package = "reqwest"
|
||||
version = "0.12"
|
||||
default-features = false
|
||||
features = [
|
||||
"rustls-tls-native-roots-no-provider",
|
||||
]
|
||||
|
||||
[workspace.dependencies.serde]
|
||||
version = "1.0.229"
|
||||
default-features = false
|
||||
@@ -407,7 +398,7 @@ features = [
|
||||
|
||||
[workspace.dependencies.rust-rocksdb]
|
||||
git = "https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1"
|
||||
rev = "6021299f3e0e9455dc3f2e39c65e1dc217be8903"
|
||||
rev = "0a25ff92f7c09b55eec496b9c192c7d5136ab2b8"
|
||||
default-features = false
|
||||
features = [
|
||||
"multi-threaded-cf",
|
||||
@@ -427,8 +418,6 @@ default-features = false
|
||||
|
||||
[workspace.dependencies.openidconnect]
|
||||
version = "4.1.0"
|
||||
default-features = false
|
||||
features = ["reqwest"]
|
||||
|
||||
# optional opentelemetry, performance measurements, flamegraphs, etc for performance measurements and monitoring
|
||||
[workspace.dependencies.opentelemetry]
|
||||
@@ -490,7 +479,7 @@ version = "0.49.5"
|
||||
# jemalloc usage
|
||||
[workspace.dependencies.tikv-jemalloc-sys]
|
||||
git = "https://forgejo.ellis.link/continuwuation/jemallocator"
|
||||
rev = "ac4d4861b335b199f812807996e8c9166961041a"
|
||||
rev = "df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
|
||||
default-features = false
|
||||
features = [
|
||||
"background_threads_runtime_support",
|
||||
@@ -498,7 +487,7 @@ features = [
|
||||
]
|
||||
[workspace.dependencies.tikv-jemallocator]
|
||||
git = "https://forgejo.ellis.link/continuwuation/jemallocator"
|
||||
rev = "ac4d4861b335b199f812807996e8c9166961041a"
|
||||
rev = "df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
|
||||
default-features = false
|
||||
features = [
|
||||
"background_threads_runtime_support",
|
||||
@@ -506,7 +495,7 @@ features = [
|
||||
]
|
||||
[workspace.dependencies.tikv-jemalloc-ctl]
|
||||
git = "https://forgejo.ellis.link/continuwuation/jemallocator"
|
||||
rev = "ac4d4861b335b199f812807996e8c9166961041a"
|
||||
rev = "df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
|
||||
default-features = false
|
||||
features = ["use_std"]
|
||||
|
||||
|
||||
+3
-17
@@ -52,10 +52,8 @@ else
|
||||
fi
|
||||
|
||||
# The base docker image to use for complement tests
|
||||
# On Linux, you can build the default with `docker build -t continuwuity:complement -f ./docker/complement.Dockerfile .`
|
||||
# after running `cargo build -p conduwuit --features openreg`.
|
||||
# On non-Linux platforms (or to use a container build), build `docker/Dockerfile` with debuginfo and openreg `--build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg`
|
||||
# and then run `docker build -t continuwuity:complement --target container -f ./docker/complement.Dockerfile .`.
|
||||
# You can build the default with `docker build -t continuwuity:complement -f ./docker/complement.Dockerfile .`
|
||||
# after running `cargo build -p conduwuit --features openreg`. Only the debug binary is used.
|
||||
COMPLEMENT_BASE_IMAGE="${COMPLEMENT_BASE_IMAGE:-continuwuity:complement}"
|
||||
|
||||
# Complement tests that are skipped due to flakiness/reliability issues or we don't implement such features and won't for a long time
|
||||
@@ -85,13 +83,6 @@ for command in docker go jq; do
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "${DOCKER_HOST:-}" ]; then
|
||||
DOCKER_HOST="$(docker context inspect --format '{{.Endpoints.docker.Host}}' 2>/dev/null || true)"
|
||||
if [ -n "$DOCKER_HOST" ]; then
|
||||
export DOCKER_HOST
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$IMAGE_ARCHIVE" ]; then
|
||||
if [ ! -f "$IMAGE_ARCHIVE" ]; then
|
||||
echo "Docker image archive not found: $IMAGE_ARCHIVE"
|
||||
@@ -108,12 +99,7 @@ fi
|
||||
|
||||
if ! docker image inspect "$COMPLEMENT_BASE_IMAGE" > /dev/null 2>&1; then
|
||||
echo "Complement base image not found: $COMPLEMENT_BASE_IMAGE"
|
||||
if [ "$(uname -s)" != "Linux" ]; then
|
||||
echo "Build it with: docker buildx build --load -t continuwuity:latest-openreg --build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg -f docker/Dockerfile . && docker build -t $COMPLEMENT_BASE_IMAGE --target container -f docker/complement.Dockerfile ."
|
||||
else
|
||||
echo "Build it with: cargo build -p conduwuit --features openreg && docker build -t $COMPLEMENT_BASE_IMAGE -f docker/complement.Dockerfile ."
|
||||
echo "Or from a container build: docker buildx build --load -t continuwuity:latest-openreg --build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg -f docker/Dockerfile . && docker build -t $COMPLEMENT_BASE_IMAGE --target container -f docker/complement.Dockerfile ."
|
||||
fi
|
||||
echo "Build it with: cargo build -p conduwuit --features openreg && docker build -t $COMPLEMENT_BASE_IMAGE -f docker/complement.Dockerfile ."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Added the `GET /_matrix/client/v1/rooms/{roomId}/timestamp_to_event` endpoint as per MSC3030, letting clients find the event closest to a given timestamp. Contributed by @eleboucher.
|
||||
@@ -0,0 +1 @@
|
||||
Added support for acting as a trusted server, meaning the `trusted_servers` list can consist of servers that are either Synapse OR continuwuity.
|
||||
@@ -1 +0,0 @@
|
||||
Fix remote server key signature verification when extra fields exist. Contributed by @hexchen
|
||||
@@ -0,0 +1 @@
|
||||
URL previews no longer completely fail if downloading auxiliary content (images/videos/audio) fails. Contributed by @nex.
|
||||
@@ -0,0 +1 @@
|
||||
Fix outgoing federation stalling after a sender worker panics. Contributed by @eleboucher.
|
||||
+3
-18
@@ -812,18 +812,6 @@
|
||||
# env: CONTINUWUITY_FORGET_FORCED_UPON_LEAVE
|
||||
#forget_forced_upon_leave = false
|
||||
|
||||
# Set this to true to require authentication when looking up user profiles
|
||||
# through this server.
|
||||
#
|
||||
# By default this is false, allowing tools such as matrix.to to access
|
||||
# profiles of users on this server and on other servers.
|
||||
# Setting this to true will block those tools, and may block automated
|
||||
# crawlers from scraping users' profiles, although it will not block
|
||||
# other homeservers from accessing users' profiles.
|
||||
#
|
||||
# env: CONTINUWUITY_REQUIRE_AUTH_FOR_PROFILE_REQUESTS
|
||||
#require_auth_for_profile_requests = false
|
||||
|
||||
# Set this to true to require authentication to create a rendezvous
|
||||
# session. Rendezvous sessions are used for QR code login.
|
||||
#
|
||||
@@ -831,7 +819,7 @@
|
||||
# creates the rendezvous session. Therefore, this must be false to let
|
||||
# a logged-out device show a QR code.
|
||||
#
|
||||
# By default this is false to allow logged-out desktop devices (which may
|
||||
# By default this is false, allowing logged-out desktop devices (which may
|
||||
# not have a camera) to show a QR code. Setting this to true will
|
||||
# require logged-out devices to scan the QR code instead.
|
||||
#
|
||||
@@ -1042,10 +1030,7 @@
|
||||
# (trusted key notary servers), as well as serve as trusted servers for
|
||||
# other operations like backfill and event fetching.
|
||||
#
|
||||
# Currently, continuwuity doesn't support inbound key requests, so
|
||||
# this list should only contain other Synapse servers.
|
||||
#
|
||||
# example: ["matrix.org", "starstruck.systems"]
|
||||
# example: ["continuwuity.org", "matrix.org"]
|
||||
#
|
||||
# It is possible to restrict which signing keys trusted servers are
|
||||
# allowed to sign responses with. Without configuring this, all responses
|
||||
@@ -1083,7 +1068,7 @@
|
||||
# is discouraged for performance and reliability reasons.
|
||||
#
|
||||
# env: CONTINUWUITY_TRUSTED_SERVERS
|
||||
#trusted_servers = ["matrix.org"]
|
||||
#trusted_servers = ["continuwuity.org", "continuwuity.rocks", "matrix.org"]
|
||||
|
||||
# Whether to prioritise trusted server lookups over origin server lookups.
|
||||
#
|
||||
|
||||
@@ -1,29 +1,11 @@
|
||||
ARG CONTINUWUITY_IMAGE=continuwuity:latest-openreg
|
||||
ARG BINARY_SOURCE=host
|
||||
|
||||
FROM ${CONTINUWUITY_IMAGE} AS container-binary
|
||||
|
||||
FROM scratch AS host-binary
|
||||
ARG BINARY_PATH=target/debug/conduwuit
|
||||
COPY ${BINARY_PATH} /sbin/conduwuit
|
||||
|
||||
FROM ubuntu:latest AS base
|
||||
FROM ubuntu:latest
|
||||
EXPOSE 8008
|
||||
EXPOSE 8448
|
||||
RUN apt-get update && apt-get install -y ca-certificates liburing2 && rm -rf /var/lib/apt/lists/*
|
||||
RUN mkdir -p /etc/continuwuity /var/lib/continuwuity /usr/local/bin/
|
||||
COPY complement/complement-entrypoint.sh /usr/local/bin/complement-entrypoint.sh
|
||||
COPY complement/complement.config.toml /etc/continuwuity/config.toml
|
||||
RUN chmod +x /usr/local/bin/complement-entrypoint.sh
|
||||
COPY target/debug/conduwuit /usr/local/bin/conduwuit
|
||||
RUN chmod +x /usr/local/bin/conduwuit /usr/local/bin/complement-entrypoint.sh
|
||||
#HEALTHCHECK --interval=30s --timeout=5s CMD curl --fail http://localhost:8008/_continuwuity/server_version || exit 1
|
||||
ENTRYPOINT ["/usr/local/bin/complement-entrypoint.sh"]
|
||||
|
||||
FROM base AS container
|
||||
COPY --from=container-binary /sbin/conduwuit /usr/local/bin/conduwuit
|
||||
RUN chmod +x /usr/local/bin/conduwuit
|
||||
|
||||
FROM base AS host
|
||||
COPY --from=host-binary /sbin/conduwuit /usr/local/bin/conduwuit
|
||||
RUN chmod +x /usr/local/bin/conduwuit
|
||||
|
||||
FROM ${BINARY_SOURCE}
|
||||
@@ -20,20 +20,6 @@ docker build -t continuwuity:complement -f docker/complement.Dockerfile .
|
||||
The `openreg` feature is required: without it the server refuses the open
|
||||
registrations Complement uses to create test users, and almost every test fails.
|
||||
|
||||
On non-Linux (or to build inside a container instead of on the host), build the Continuwuity image with the `openreg` feature and `RUST_PROFILE=dev` first (open
|
||||
registration is only enabled when `debug_assertions` are active), then build
|
||||
the Complement image using the `container` target:
|
||||
|
||||
```bash
|
||||
docker buildx build --load -t continuwuity:latest-openreg --build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg -f docker/Dockerfile .
|
||||
docker build -t continuwuity:complement --target container -f docker/complement.Dockerfile .
|
||||
./bin/complement
|
||||
```
|
||||
|
||||
Pass `--build-arg CONTINUWUITY_IMAGE=your-image:tag` when building
|
||||
`docker/complement.Dockerfile` if your Continuwuity container image uses a
|
||||
different tag.
|
||||
|
||||
The run can take up to an hour. The runner writes the full Go test stream to
|
||||
`tests/test_results/complement/test_logs.jsonl` and a sorted pass/fail/skip
|
||||
summary to `tests/test_results/complement/test_results.jsonl`. It exits nonzero
|
||||
|
||||
@@ -71,6 +71,9 @@ Names below are as they appear in Prometheus. OTLP uses the dotted OpenTelemetry
|
||||
| `continuwuity_sender_events_total` | counter | `destination`, `kind`, `outcome` | PDUs and EDUs sent in outgoing transactions |
|
||||
| `continuwuity_sender_events_queued_total` | counter | `destination`, `kind` | PDUs and EDUs queued for sending |
|
||||
| `continuwuity_sender_queue_depth` | gauge | | Messages waiting for the sender workers |
|
||||
| `continuwuity_sender_requests` | gauge | `state` | Estimated outgoing requests stored as `queued` or `active` (in flight) |
|
||||
| `continuwuity_sender_workers` | gauge | | Running sender workers; below the configured count means a worker is restarting |
|
||||
| `continuwuity_sender_panics_total` | counter | `scope` | Panics caught in a single outgoing `transaction` or a whole sender `worker` |
|
||||
| `continuwuity_users` | gauge | `origin` | Known `local` users, including deactivated, and `remote` users |
|
||||
| `continuwuity_invites_total` | counter | `direction`, `destination`, `outcome` | Invites sent by local users or received over federation |
|
||||
| `continuwuity_media_write_size_bytes` | histogram | `origin` | Media files written, from local uploads or cached remote media |
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
target:
|
||||
target.fromToolchainName {
|
||||
name = (lib.importTOML "${inputs.self}/rust-toolchain.toml").toolchain.channel;
|
||||
sha256 = "sha256-MFHoWVcPZKjFrLnQnodCXbUsfZcofGfo9tV9fTTvklg=";
|
||||
sha256 = "sha256-+xUr6Al1wZSqX8aEsq7DpuFOK4Ve/i+qTl+K5uWQ9GM=";
|
||||
};
|
||||
in
|
||||
{
|
||||
|
||||
Generated
+13
-13
@@ -431,9 +431,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/core": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.3.tgz",
|
||||
"integrity": "sha512-qKa5c7zHO8cmhxkReURd3dN/ZRfHYnEztdIQ9hMuolaNzhSYo2A36XErUvLvbMf2EUM2AxfPYRQv+4Crfeq6pw==",
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.2.tgz",
|
||||
"integrity": "sha512-3ghPRkZFwbuO3tr2Rb5cxi6QfSFWOcxoZ5p4pv21lbN5DxAzMduITFlfgBMTArIQbehXrfXw3OUXe1l422b0RA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -441,7 +441,7 @@
|
||||
"@mdx-js/react": "^3.1.1",
|
||||
"@rsbuild/core": "^2.2.14",
|
||||
"@rsbuild/plugin-react": "~2.1.1",
|
||||
"@rspress/shared": "2.1.3",
|
||||
"@rspress/shared": "2.1.2",
|
||||
"@shikijs/rehype": "^4.2.0",
|
||||
"@shikijs/transformers": "^4.2.0",
|
||||
"@types/mdast": "^4.0.4",
|
||||
@@ -485,9 +485,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/plugin-client-redirects": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.1.3.tgz",
|
||||
"integrity": "sha512-iEqJ8qEFuUxGKRVaS/WMyFi8FiJlogdcEHbGK/UjY8+8Hg8r8aSv4YihmNh3Ev/uIW21hrC8aXMEgVo0H51Q+g==",
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.1.2.tgz",
|
||||
"integrity": "sha512-kNCC7fffXA277TzTDfKpP+QuCI1X218lJ5JH/2iqYR8PHnLw0Y6ZIwoFmJlE0eKaBdniYyBRGn9zgvT93mCWdg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -498,9 +498,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/plugin-sitemap": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.1.3.tgz",
|
||||
"integrity": "sha512-Fqo7/4PfQK1ecHUFoUDMrR/E+Hcu+kIohxSs8QabflMy3dqk+M3ZqzJDOHpVYB+HLLGwKiqkPLT4BK+W93clkw==",
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.1.2.tgz",
|
||||
"integrity": "sha512-qF9NDLLJORa7MM8QY/etgMlrXM8hlArNaK5ntiFimqtKRoF1YTJQSKPsAfMq2PvYrpQJyEqsSg6wJ+r+lyjNlw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -511,9 +511,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/shared": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.3.tgz",
|
||||
"integrity": "sha512-VwJ7kgsTWVqHzSXQVHIUCsdMparmq9b/IDmTa3a6jMPl1zmm5Qg9M0eP4j8JXWoIS9n19XtCkQcZmMTFOPRy3A==",
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.2.tgz",
|
||||
"integrity": "sha512-W34tT1fdP3PrdbXpZNKqOGZMOw+RYL70Z9vnkbT1HTTbtX4uMIDE+SU7ByihG0S0LYBsT3kPxA2cXj696253Uw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#-------------------------------------------------------------------------------#
|
||||
# Qodana analysis is configured by qodana.yaml file #
|
||||
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
|
||||
#-------------------------------------------------------------------------------#
|
||||
|
||||
#################################################################################
|
||||
# WARNING: Do not store sensitive information in this file, #
|
||||
# as its contents will be included in the Qodana report. #
|
||||
#################################################################################
|
||||
version: "1.0"
|
||||
|
||||
#Specify inspection profile for code analysis
|
||||
profile:
|
||||
name: qodana.starter
|
||||
|
||||
#Enable inspections
|
||||
#include:
|
||||
# - name: <SomeEnabledInspectionId>
|
||||
|
||||
#Disable inspections
|
||||
#exclude:
|
||||
# - name: <SomeDisabledInspectionId>
|
||||
# paths:
|
||||
# - <path/where/not/run/inspection>
|
||||
|
||||
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
|
||||
#bootstrap: sh ./prepare-qodana.sh
|
||||
|
||||
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
|
||||
#plugins:
|
||||
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
|
||||
|
||||
# Quality gate. Will fail the CI/CD pipeline if any condition is not met
|
||||
# severityThresholds - configures maximum thresholds for different problem severities
|
||||
# testCoverageThresholds - configures minimum code coverage on a whole project and newly added code
|
||||
# Code Coverage is available in Ultimate and Ultimate Plus plans
|
||||
#failureConditions:
|
||||
# severityThresholds:
|
||||
# any: 15
|
||||
# critical: 5
|
||||
# testCoverageThresholds:
|
||||
# fresh: 70
|
||||
# total: 50
|
||||
|
||||
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
|
||||
linter: jetbrains/qodana-<linter>:2026.2
|
||||
@@ -142,11 +142,11 @@ impl crate::Context<'_> {
|
||||
.await?;
|
||||
self.write_str("| ------ | ---------- | --------------------------- |\n")
|
||||
.await?;
|
||||
for (key_id, key) in &response.parsed.verify_keys {
|
||||
for (key_id, key) in &response.verify_keys {
|
||||
self.write_str(&format!("| {key_id} | {} | |\n", key.key))
|
||||
.await?;
|
||||
}
|
||||
for (key_id, old_key) in &response.parsed.old_verify_keys {
|
||||
for (key_id, old_key) in &response.old_verify_keys {
|
||||
self.write_str(&format!(
|
||||
"| {key_id} | {} | {:0<13} |\n",
|
||||
old_key.key,
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::time::Duration;
|
||||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err, Result, err,
|
||||
Err, Result, err, info,
|
||||
utils::{self, content_disposition::make_content_disposition, math::ruma_from_usize},
|
||||
};
|
||||
use conduwuit_core::error;
|
||||
@@ -219,10 +219,15 @@ pub(crate) async fn get_media_preview_route(
|
||||
)));
|
||||
}
|
||||
|
||||
info!("Fetching a URL preview for {url} on behalf of {sender_user}");
|
||||
let preview = services
|
||||
.media
|
||||
.get_url_preview(&url)
|
||||
.await
|
||||
.inspect(|_| info!(user=%sender_user, %url, "Finished fetching a URL preview"))
|
||||
.inspect_err(
|
||||
|e| info!(user=%sender_user, %url, error=?e, "Failed to fetch a URL preview"),
|
||||
)
|
||||
.map_err(|error| {
|
||||
err!(Request(Unknown(
|
||||
debug_error!(%sender_user, %url, "Failed to fetch URL preview: {error}")
|
||||
|
||||
@@ -29,7 +29,7 @@ pub(crate) async fn get_profile_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_profile::v3::Request>,
|
||||
) -> Result<get_profile::v3::Response> {
|
||||
if services.config.require_auth_for_profile_requests && body.identity.is_none() {
|
||||
if body.identity.is_none() {
|
||||
return Err!(Request(Unauthorized(
|
||||
"This server requires authentication to access user profiles."
|
||||
)));
|
||||
@@ -46,7 +46,7 @@ pub(crate) async fn get_profile_field_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_profile_field::v3::Request>,
|
||||
) -> Result<get_profile_field::v3::Response> {
|
||||
if services.config.require_auth_for_profile_requests && body.identity.is_none() {
|
||||
if body.identity.is_none() {
|
||||
return Err!(Request(Unauthorized(
|
||||
"This server requires authentication to access user profiles."
|
||||
)));
|
||||
|
||||
@@ -4,10 +4,12 @@ mod event;
|
||||
mod initial_sync;
|
||||
mod stripped_state;
|
||||
mod summary;
|
||||
mod timestamp_to_event;
|
||||
mod upgrade;
|
||||
|
||||
pub(crate) use self::{
|
||||
aliases::get_room_aliases_route, create::create_room_route, event::get_room_event_route,
|
||||
initial_sync::room_initial_sync_route, stripped_state::get_stripped_state_route,
|
||||
summary::get_room_summary, upgrade::upgrade_room_route,
|
||||
summary::get_room_summary, timestamp_to_event::get_event_by_timestamp_route,
|
||||
upgrade::upgrade_room_route,
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
use axum::extract::State;
|
||||
use conduwuit::{Err, Event, Result, utils::stream::TryIgnore};
|
||||
use futures::{StreamExt, pin_mut};
|
||||
use ruma::api::client::room::get_event_by_timestamp;
|
||||
|
||||
use crate::Ruma;
|
||||
|
||||
const MAX_CANDIDATES: usize = 20;
|
||||
|
||||
/// # `GET /_matrix/client/v1/rooms/{roomId}/timestamp_to_event`
|
||||
///
|
||||
/// Gets the ID of the event closest to the given timestamp, in the direction
|
||||
/// specified by `dir`.
|
||||
pub(crate) async fn get_event_by_timestamp_route(
|
||||
State(ref services): State<crate::State>,
|
||||
body: Ruma<get_event_by_timestamp::v1::Request>,
|
||||
) -> Result<get_event_by_timestamp::v1::Response> {
|
||||
let sender_user = body.identity.expect_sender_user()?;
|
||||
let room_id = &body.room_id;
|
||||
|
||||
if !services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.user_can_see_state_events(sender_user, room_id)
|
||||
.await
|
||||
{
|
||||
return Err!(Request(Forbidden("You don't have permission to view this room.")));
|
||||
}
|
||||
|
||||
if !services.rooms.timeline.timestamp_index_ready().await {
|
||||
return Err!(FeatureDisabled("timestamp_to_event"));
|
||||
}
|
||||
|
||||
let candidates = services
|
||||
.rooms
|
||||
.timeline
|
||||
.pdus_by_timestamp(room_id, body.ts, body.dir)
|
||||
.ignore_err()
|
||||
.take(MAX_CANDIDATES);
|
||||
|
||||
pin_mut!(candidates);
|
||||
while let Some((_, pdu)) = candidates.next().await {
|
||||
if services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.user_can_see_event(sender_user, room_id, pdu.event_id())
|
||||
.await
|
||||
{
|
||||
return Ok(get_event_by_timestamp::v1::Response::new(
|
||||
pdu.event_id().to_owned(),
|
||||
pdu.origin_server_ts(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Err!(Request(NotFound(
|
||||
"Unable to find event from {} in direction {:?}",
|
||||
body.ts.get(),
|
||||
body.dir
|
||||
)))
|
||||
}
|
||||
+5
-1
@@ -52,6 +52,7 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
.ruma_route(&client::set_pushrule_actions_route)
|
||||
.ruma_route(&client::delete_pushrule_route)
|
||||
.ruma_route(&client::get_room_event_route)
|
||||
.ruma_route(&client::get_event_by_timestamp_route)
|
||||
.ruma_route(&client::get_room_aliases_route)
|
||||
.ruma_route(&client::get_filter_route)
|
||||
.ruma_route(&client::create_filter_route)
|
||||
@@ -217,7 +218,10 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
if config.allow_federation {
|
||||
router = router
|
||||
.ruma_route(&server::get_server_version_route)
|
||||
.route("/_matrix/key/v2/server", get(server::get_server_keys_route))
|
||||
.ruma_route(&server::get_server_keys_route)
|
||||
.ruma_route(&server::get_remote_server_keys_batch_route)
|
||||
.ruma_route(&server::get_remote_server_keys_batch_v3_unstable_route)
|
||||
.ruma_route(&server::get_remote_server_keys_route)
|
||||
.ruma_route(&server::get_public_rooms_route)
|
||||
.ruma_route(&server::get_public_rooms_filtered_route)
|
||||
.ruma_route(&server::send_transaction_message_route)
|
||||
|
||||
+360
-69
@@ -1,89 +1,380 @@
|
||||
use std::{collections::BTreeMap, mem::take, time::Duration};
|
||||
|
||||
use axum::{Json, extract::State, response::IntoResponse};
|
||||
use conduwuit::{Result, utils::timepoint_from_now};
|
||||
use futures::StreamExt;
|
||||
use ruma::{
|
||||
MilliSecondsSinceUnixEpoch,
|
||||
api::{
|
||||
OutgoingResponseExt,
|
||||
federation::discovery::{OldVerifyKey, ServerSigningKeys, get_server_keys},
|
||||
},
|
||||
assign,
|
||||
serde::Raw,
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
ops::Index,
|
||||
sync::Arc,
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err, Result, debug, debug_info, error,
|
||||
utils::{
|
||||
ReadyExt,
|
||||
stream::{BroadbandExt, automatic_width},
|
||||
to_canonical_object,
|
||||
},
|
||||
};
|
||||
use futures::{StreamExt, stream::FuturesUnordered};
|
||||
use ruma::{
|
||||
MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedServerSigningKeyId, ServerName,
|
||||
api::federation::discovery::{
|
||||
ServerSigningKeys, get_remote_server_keys, get_remote_server_keys_batch,
|
||||
get_remote_server_keys_batch::v2::QueryCriteria, get_server_keys,
|
||||
},
|
||||
serde::Raw,
|
||||
uint,
|
||||
};
|
||||
use serde_json::value::to_raw_value;
|
||||
use service::{server_keys, server_keys::in_one_week};
|
||||
|
||||
use crate::router::Ruma;
|
||||
|
||||
/// # `GET /_matrix/key/v2/server`
|
||||
///
|
||||
/// Gets the public signing keys of this server.
|
||||
pub(crate) async fn get_server_keys_route(
|
||||
State(services): State<crate::State>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
let server_name = services.globals.server_name();
|
||||
let verify_keys = BTreeMap::from([services.server_keys.active_verify_key()]);
|
||||
_body: Ruma<get_server_keys::v2::Request>,
|
||||
) -> Result<get_server_keys::v2::Response> {
|
||||
services
|
||||
.server_keys
|
||||
.build_server_keys_response()
|
||||
.await
|
||||
.map(get_server_keys::v2::Response::new)
|
||||
}
|
||||
|
||||
let old_verify_keys = if let Some(k) = &services.config.old_verify_keys {
|
||||
k.to_owned()
|
||||
const MAX_KEYS_PER_QUERY: usize = 16384;
|
||||
const MAX_SERVERS_PER_QUERY: usize = 4096;
|
||||
|
||||
/// # `POST /_matrix/key/v2/query`
|
||||
///
|
||||
/// Fetches remote server signing keys in bulk, seeding from the local server's
|
||||
/// database.
|
||||
///
|
||||
/// This route applies a semaphore to slow down requests that query more signing
|
||||
/// keys than is allowed by [MSC4556].
|
||||
///
|
||||
/// [MSC4556]: https://github.com/matrix-org/matrix-spec-proposals/pull/4556
|
||||
pub(crate) async fn get_remote_server_keys_batch_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_remote_server_keys_batch::v2::Request>,
|
||||
) -> Result<get_remote_server_keys_batch::v2::Response> {
|
||||
query_inner(&services, &body.server_keys, false)
|
||||
.await
|
||||
.map(get_remote_server_keys_batch::v2::Response::new)
|
||||
}
|
||||
|
||||
/// # `POST /_matrix/key/unstable/org.continuwuity.msc4556/query`
|
||||
/// ## `POST /_matrix/key/v3/query`
|
||||
///
|
||||
/// Fetches remote server signing keys in bulk, seeding from the local server's
|
||||
/// database.
|
||||
///
|
||||
/// MSC4556: https://github.com/matrix-org/matrix-spec-proposals/pull/4556
|
||||
pub(crate) async fn get_remote_server_keys_batch_v3_unstable_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<ruminuwuity::federation::notary::unstable::Request>,
|
||||
) -> Result<ruminuwuity::federation::notary::unstable::Response> {
|
||||
query_inner(&services, &body.server_keys, false)
|
||||
.await
|
||||
.map(ruminuwuity::federation::notary::unstable::Response::new)
|
||||
}
|
||||
|
||||
/// Handles querying the server keys for `/_matrix/key/*/query`.
|
||||
///
|
||||
/// `v2` should be `true` if the request path is `/_matrix/key/v2/query` - this
|
||||
/// will potentially apply a rate-limit to the request.
|
||||
async fn query_inner(
|
||||
services: &crate::State,
|
||||
body: &BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, QueryCriteria>>,
|
||||
v2: bool,
|
||||
) -> Result<Vec<Raw<ServerSigningKeys>>> {
|
||||
let start = (Instant::now(), MilliSecondsSinceUnixEpoch::now());
|
||||
// If the remote server isn't asking for any keys, we can return an empty
|
||||
// array immediately.
|
||||
if body.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
// Count how many keys are being requested.
|
||||
// Each server incurs a cost of at least one, and then the count of each key
|
||||
// being queried per-server.
|
||||
let total_queried_servers = body.len();
|
||||
let total_queried_keys = body
|
||||
.values()
|
||||
.fold(body.len(), |acc, q| acc.saturating_add(q.len()));
|
||||
|
||||
if !v2 {
|
||||
// If we're on the v3 endpoint, we can apply these limits explicitly.
|
||||
if total_queried_servers > MAX_SERVERS_PER_QUERY {
|
||||
return Err!(Request(TooLarge(
|
||||
"Too many server keys requested ({total_queried_servers} > \
|
||||
{MAX_SERVERS_PER_QUERY}",
|
||||
)));
|
||||
}
|
||||
if total_queried_keys > MAX_KEYS_PER_QUERY {
|
||||
return Err!(Request(TooLarge(
|
||||
"Too many keys requested ({total_queried_keys} > {MAX_KEYS_PER_QUERY})"
|
||||
)));
|
||||
}
|
||||
}
|
||||
let penalise =
|
||||
total_queried_servers > MAX_SERVERS_PER_QUERY || total_queried_keys > MAX_KEYS_PER_QUERY;
|
||||
|
||||
debug_info!("Fetching {total_queried_keys} keys across {} servers", body.len());
|
||||
let mut futs: FuturesUnordered<_> = FuturesUnordered::new();
|
||||
|
||||
// If we're on the v2 endpoint, we aren't allowed to reject the request.
|
||||
// To avoid overloading the server, we'll apply a semaphore to limit how
|
||||
// many futures can be active at a time.
|
||||
let width = automatic_width();
|
||||
let sem = if v2 && penalise {
|
||||
Some(Arc::new(tokio::sync::Semaphore::new(width)))
|
||||
} else {
|
||||
// We need to figure out any old signing keys we've acquired from
|
||||
// notaries.
|
||||
let mut keys = services.server_keys.signing_keys_for(server_name);
|
||||
let mut old_keys = BTreeMap::new();
|
||||
while let Some(resp) = keys.next().await {
|
||||
// We need to verify that this response is still trusted based on
|
||||
// the current configuration. It's possible we got this response
|
||||
// from a notary who we no longer trust.
|
||||
if resp.parsed.valid_until_ts > in_one_week() {
|
||||
continue;
|
||||
}
|
||||
let trusted = services.config.trusted_servers.iter().any(|notary| {
|
||||
server_keys::Service::verify_server_keys_response(
|
||||
&resp,
|
||||
Some((notary.server_name(), notary.verify_keys())),
|
||||
)
|
||||
.is_ok()
|
||||
});
|
||||
if !trusted {
|
||||
continue;
|
||||
}
|
||||
for (old_key_id, old_key) in resp.parsed.old_verify_keys {
|
||||
if old_key.expired_ts > resp.parsed.valid_until_ts {
|
||||
// This key expired in the future which is probably illegal
|
||||
continue;
|
||||
None
|
||||
};
|
||||
for (server_name, queries) in body.clone() {
|
||||
futs.push(acquire_keys_as_notary(
|
||||
services.server_keys.clone(),
|
||||
services.globals.server_name().to_owned(),
|
||||
server_name,
|
||||
queries,
|
||||
start.1,
|
||||
sem.clone(),
|
||||
));
|
||||
}
|
||||
let mut response = Vec::with_capacity(total_queried_keys);
|
||||
while let Some(v) = futs.next().await {
|
||||
response.extend(v);
|
||||
}
|
||||
|
||||
debug_info!(
|
||||
elapsed=?start.0.elapsed(),
|
||||
%total_queried_servers,
|
||||
%total_queried_keys,
|
||||
"Fetched {} key responses",
|
||||
response.len()
|
||||
);
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
async fn sign_ssk(
|
||||
server_keys: &server_keys::Service,
|
||||
ssk: ServerSigningKeys,
|
||||
server_name: &ServerName,
|
||||
our_name: &ServerName,
|
||||
) -> Result<Raw<ServerSigningKeys>> {
|
||||
if server_name == our_name {
|
||||
// Should already be signed by us if we got this far.
|
||||
debug_info!(
|
||||
object=?ssk,
|
||||
%server_name,
|
||||
%our_name,
|
||||
"Refusing to sign our own signing keys response (should already be signed)"
|
||||
);
|
||||
return to_raw_value(&ssk)
|
||||
.map(Raw::<ServerSigningKeys>::from_json)
|
||||
.map_err(Into::into);
|
||||
}
|
||||
let mut canonical = to_canonical_object(&ssk)?;
|
||||
server_keys.sign_json(&mut canonical)?;
|
||||
server_keys::strip_extraneous_signatures(&mut canonical, server_name, &[our_name]);
|
||||
to_raw_value(&canonical)
|
||||
.map(Raw::<ServerSigningKeys>::from_json)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(server_keys, my_name, queries, start, semaphore))]
|
||||
async fn acquire_keys_as_notary(
|
||||
server_keys: Arc<server_keys::Service>,
|
||||
my_name: OwnedServerName,
|
||||
remote: OwnedServerName,
|
||||
mut queries: BTreeMap<OwnedServerSigningKeyId, QueryCriteria>,
|
||||
start: MilliSecondsSinceUnixEpoch,
|
||||
semaphore: Option<Arc<tokio::sync::Semaphore>>,
|
||||
) -> Vec<Raw<ServerSigningKeys>> {
|
||||
let cost = queries
|
||||
.len()
|
||||
.saturating_add(1)
|
||||
.min(automatic_width())
|
||||
.try_into()
|
||||
.unwrap_or(u32::MAX);
|
||||
let _permit = if let Some(sem) = semaphore {
|
||||
sem.acquire_many_owned(cost).await.ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let fetch_all = queries.is_empty();
|
||||
let mut results = Vec::with_capacity(queries.len().max(1));
|
||||
let mut keymap = HashMap::with_capacity(queries.len().max(1));
|
||||
|
||||
// First contact the origin (if we're allowed to)
|
||||
if server_keys.notary_may_contact_origin(&remote) {
|
||||
debug_info!("Asking remote directly for verify keys");
|
||||
if let Ok(res) = server_keys.origin_request(remote.clone(), start).await
|
||||
&& let Ok(ssk) = sign_ssk(&server_keys, res.clone(), &remote, &my_name).await
|
||||
{
|
||||
let index = results.len();
|
||||
results.push(ssk);
|
||||
for key_id in res.verify_keys.keys().chain(res.old_verify_keys.keys()) {
|
||||
if fetch_all
|
||||
|| queries.get(key_id).is_some_and(|c| {
|
||||
c.minimum_valid_until_ts
|
||||
.is_none_or(|m| res.valid_until_ts >= m)
|
||||
}) {
|
||||
queries.remove(key_id);
|
||||
keymap.insert(key_id.to_owned(), index);
|
||||
}
|
||||
old_keys
|
||||
.entry(old_key_id)
|
||||
.and_modify(|current_old_key: &mut OldVerifyKey| {
|
||||
// Use the lowest expiry timestamp
|
||||
if current_old_key.expired_ts > old_key.expired_ts {
|
||||
*current_old_key = old_key.clone();
|
||||
}
|
||||
})
|
||||
.or_insert(old_key);
|
||||
}
|
||||
}
|
||||
old_keys
|
||||
};
|
||||
} else {
|
||||
debug!("Not asking remote for keys (already asked recently)");
|
||||
}
|
||||
debug!(keys=?keymap.keys(), "Live verify keys");
|
||||
if fetch_all && keymap.is_empty() {
|
||||
// If the server asked for all keys, AND we didn't get anything from the
|
||||
// origin, just fetch any fresh responses we have.
|
||||
server_keys
|
||||
.signing_keys_for(&remote)
|
||||
.broad_filter_map(|ssk| {
|
||||
let server_name = &remote;
|
||||
let my_name = &my_name;
|
||||
let server_keys = &server_keys;
|
||||
async move {
|
||||
if ssk.valid_until_ts > in_one_week() || ssk.valid_until_ts < start {
|
||||
return None;
|
||||
}
|
||||
|
||||
let server_key = assign!(ServerSigningKeys::new(server_name.to_owned(), valid_until_ts()), {
|
||||
verify_keys,
|
||||
old_verify_keys,
|
||||
});
|
||||
sign_ssk(server_keys, ssk.clone(), server_name, my_name)
|
||||
.await
|
||||
.map(|signed_ssk| (ssk, signed_ssk))
|
||||
.ok()
|
||||
}
|
||||
})
|
||||
.ready_for_each(|(ssk, signed_ssk)| {
|
||||
let idx = results.len();
|
||||
results.push(signed_ssk);
|
||||
for key_id in ssk.verify_keys.keys().chain(ssk.old_verify_keys.keys()) {
|
||||
keymap.insert(key_id.to_owned(), idx);
|
||||
}
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
let server_key = Raw::new(&server_key)?;
|
||||
let mut response = get_server_keys::v2::Response::new(server_key)
|
||||
.try_into_http_response::<Vec<u8>>()
|
||||
.map(|mut response| take(response.body_mut()))
|
||||
.and_then(|body| serde_json::from_slice(&body).map_err(Into::into))?;
|
||||
// If we're still missing some keys, fetch them from the local cache
|
||||
for (key_id, criteria) in queries {
|
||||
debug!(%key_id, "Fetching verify key from local repository");
|
||||
|
||||
services.server_keys.sign_json(&mut response)?;
|
||||
if keymap.contains_key(&key_id) {
|
||||
debug!(%key_id, "Already found key");
|
||||
continue;
|
||||
}
|
||||
|
||||
Ok(Json(response))
|
||||
let minimum_valid_until_ts = criteria
|
||||
.clone()
|
||||
.minimum_valid_until_ts
|
||||
.unwrap_or_else(|| MilliSecondsSinceUnixEpoch(uint!(0)));
|
||||
|
||||
let Some(ssk) = server_keys.get_signing_key(&remote, &key_id).await else {
|
||||
debug!(%remote, %key_id, "Could not find a matching signing key locally.");
|
||||
continue;
|
||||
};
|
||||
|
||||
if ssk.valid_until_ts < minimum_valid_until_ts || ssk.valid_until_ts > in_one_week() {
|
||||
debug!(
|
||||
%key_id,
|
||||
valid_until_ts=?ssk.valid_until_ts,
|
||||
?minimum_valid_until_ts,
|
||||
"Stored verify key does not satisfy query criteria"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if let Some(old_verify_key) = ssk.old_verify_keys.get(&key_id) {
|
||||
if old_verify_key.expired_ts < minimum_valid_until_ts {
|
||||
debug!(
|
||||
%key_id,
|
||||
expired_ts=?old_verify_key.expired_ts,
|
||||
?minimum_valid_until_ts,
|
||||
"Stored old verify key does not satisfy query criteria"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
debug!(%key_id, ?ssk, "Found key locally");
|
||||
let rep_key_ids = ssk.verify_keys.keys().cloned().collect::<Vec<_>>();
|
||||
let Ok(signed_ssk) = sign_ssk(&server_keys, ssk.clone(), &remote, &my_name)
|
||||
.await
|
||||
.inspect_err(
|
||||
|e| error!(%key_id, %remote, "Failed to sign signing keys chunk: {e:?}"),
|
||||
)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let idx = results.len();
|
||||
results.push(signed_ssk);
|
||||
keymap.insert(key_id, idx);
|
||||
for key_id in rep_key_ids {
|
||||
keymap.insert(key_id, idx);
|
||||
}
|
||||
}
|
||||
|
||||
keymap
|
||||
.into_values()
|
||||
.collect::<HashSet<_>>()
|
||||
.into_iter()
|
||||
.map(|idx| results.index(idx).to_owned())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn valid_until_ts() -> MilliSecondsSinceUnixEpoch {
|
||||
let dur = Duration::from_hours(12);
|
||||
let timepoint = timepoint_from_now(dur).expect("SystemTime should not overflow");
|
||||
MilliSecondsSinceUnixEpoch::from_system_time(timepoint).expect("UInt should not overflow")
|
||||
/// `GET /_matrix/key/v2/query/{serverName}`
|
||||
///
|
||||
/// Fetches the latest keys for a specific server name.
|
||||
pub(crate) async fn get_remote_server_keys_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_remote_server_keys::v2::Request>,
|
||||
) -> Result<get_remote_server_keys::v2::Response> {
|
||||
let min_valid_ts = body.minimum_valid_until_ts;
|
||||
if services
|
||||
.server_keys
|
||||
.notary_may_contact_origin(&body.server_name)
|
||||
&& let Ok(response) = services
|
||||
.server_keys
|
||||
.origin_request(body.server_name.clone(), min_valid_ts)
|
||||
.await
|
||||
{
|
||||
return sign_ssk(
|
||||
&services.server_keys,
|
||||
response,
|
||||
&body.server_name,
|
||||
services.globals.server_name(),
|
||||
)
|
||||
.await
|
||||
.map(|r| Ok(get_remote_server_keys::v2::Response::new(vec![r])))?;
|
||||
}
|
||||
|
||||
let response = services
|
||||
.server_keys
|
||||
.signing_keys_for(&body.server_name)
|
||||
.broad_filter_map(|ssk| {
|
||||
let server_name = body.server_name.clone();
|
||||
async move {
|
||||
if ssk.valid_until_ts > in_one_week() || ssk.valid_until_ts < min_valid_ts {
|
||||
return None;
|
||||
}
|
||||
|
||||
sign_ssk(
|
||||
&services.server_keys,
|
||||
ssk,
|
||||
server_name.as_ref(),
|
||||
services.globals.server_name(),
|
||||
)
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
Ok(get_remote_server_keys::v2::Response::new(response))
|
||||
}
|
||||
+31
-42
@@ -919,19 +919,6 @@ pub struct Config {
|
||||
#[serde(default)]
|
||||
pub forget_forced_upon_leave: bool,
|
||||
|
||||
/// Set this to true to require authentication when looking up user profiles
|
||||
/// through this server.
|
||||
///
|
||||
/// By default this is false, allowing tools such as matrix.to to access
|
||||
/// profiles of users on this server and on other servers.
|
||||
/// Setting this to true will block those tools, and may block automated
|
||||
/// crawlers from scraping users' profiles, although it will not block
|
||||
/// other homeservers from accessing users' profiles.
|
||||
///
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub require_auth_for_profile_requests: bool,
|
||||
|
||||
/// Set this to true to require authentication to create a rendezvous
|
||||
/// session. Rendezvous sessions are used for QR code login.
|
||||
///
|
||||
@@ -939,7 +926,7 @@ pub struct Config {
|
||||
/// creates the rendezvous session. Therefore, this must be false to let
|
||||
/// a logged-out device show a QR code.
|
||||
///
|
||||
/// By default this is false to allow logged-out desktop devices (which may
|
||||
/// By default this is false, allowing logged-out desktop devices (which may
|
||||
/// not have a camera) to show a QR code. Setting this to true will
|
||||
/// require logged-out devices to scan the QR code instead.
|
||||
///
|
||||
@@ -1153,10 +1140,7 @@ pub struct Config {
|
||||
/// (trusted key notary servers), as well as serve as trusted servers for
|
||||
/// other operations like backfill and event fetching.
|
||||
///
|
||||
/// Currently, continuwuity doesn't support inbound key requests, so
|
||||
/// this list should only contain other Synapse servers.
|
||||
///
|
||||
/// example: ["matrix.org", "starstruck.systems"]
|
||||
/// example: ["continuwuity.org", "matrix.org"]
|
||||
///
|
||||
/// It is possible to restrict which signing keys trusted servers are
|
||||
/// allowed to sign responses with. Without configuring this, all responses
|
||||
@@ -1193,7 +1177,7 @@ pub struct Config {
|
||||
/// empty list (`[]`) to operate without trusted server assistance, but this
|
||||
/// is discouraged for performance and reliability reasons.
|
||||
///
|
||||
/// default: ["matrix.org"]
|
||||
/// default: ["continuwuity.org", "continuwuity.rocks", "matrix.org"]
|
||||
#[serde(default = "default_trusted_servers")]
|
||||
pub trusted_servers: Vec<TrustedServer>,
|
||||
|
||||
@@ -2997,6 +2981,7 @@ const DEPRECATED_KEYS: &[&str] = &[
|
||||
"conduit_cache_capacity_modifier",
|
||||
"max_concurrent_requests",
|
||||
"otlp_protocol",
|
||||
"require_auth_for_profile_requests",
|
||||
"roomid_spacehierarchy_cache_capacity",
|
||||
"well_known_client",
|
||||
"well_known_server",
|
||||
@@ -3138,41 +3123,41 @@ fn default_database_backups_to_keep() -> i16 { 1 }
|
||||
|
||||
fn default_db_write_buffer_capacity_mb() -> f64 { 48.0 + parallelism_scaled_f64(4.0) }
|
||||
|
||||
fn default_db_cache_capacity_mb() -> f64 { 128.0 + parallelism_scaled_f64(64.0) }
|
||||
fn default_db_cache_capacity_mb() -> f64 { 512.0 + parallelism_scaled_f64(512.0) }
|
||||
|
||||
fn default_pdu_cache_capacity() -> u32 { parallelism_scaled_u32(10_000).saturating_add(100_000) }
|
||||
fn default_pdu_cache_capacity() -> u32 { parallelism_scaled_u32(50_000).saturating_add(100_000) }
|
||||
|
||||
fn default_cache_capacity_modifier() -> f64 { 1.0 }
|
||||
|
||||
fn default_auth_chain_cache_capacity() -> u32 {
|
||||
parallelism_scaled_u32(10_000).saturating_add(100_000)
|
||||
}
|
||||
|
||||
fn default_shorteventid_cache_capacity() -> u32 {
|
||||
parallelism_scaled_u32(50_000).saturating_add(100_000)
|
||||
}
|
||||
|
||||
fn default_shorteventid_cache_capacity() -> u32 {
|
||||
parallelism_scaled_u32(100_000).saturating_add(100_000)
|
||||
}
|
||||
|
||||
fn default_eventidshort_cache_capacity() -> u32 {
|
||||
parallelism_scaled_u32(25_000).saturating_add(100_000)
|
||||
parallelism_scaled_u32(50_000).saturating_add(100_000)
|
||||
}
|
||||
|
||||
fn default_eventid_pdu_cache_capacity() -> u32 {
|
||||
parallelism_scaled_u32(25_000).saturating_add(100_000)
|
||||
parallelism_scaled_u32(50_000).saturating_add(100_000)
|
||||
}
|
||||
|
||||
fn default_shortstatekey_cache_capacity() -> u32 {
|
||||
parallelism_scaled_u32(10_000).saturating_add(100_000)
|
||||
parallelism_scaled_u32(100_000).saturating_add(100_000)
|
||||
}
|
||||
|
||||
fn default_statekeyshort_cache_capacity() -> u32 {
|
||||
parallelism_scaled_u32(10_000).saturating_add(100_000)
|
||||
parallelism_scaled_u32(50_000).saturating_add(100_000)
|
||||
}
|
||||
|
||||
fn default_servernameevent_data_cache_capacity() -> u32 {
|
||||
parallelism_scaled_u32(100_000).saturating_add(500_000)
|
||||
parallelism_scaled_u32(100_000).saturating_add(100_000)
|
||||
}
|
||||
|
||||
fn default_stateinfo_cache_capacity() -> u32 { parallelism_scaled_u32(100) }
|
||||
fn default_stateinfo_cache_capacity() -> u32 { parallelism_scaled_u32(500).clamp(100, 12000) }
|
||||
|
||||
fn default_dns_cache_entries() -> u32 { 32768 }
|
||||
|
||||
@@ -3259,12 +3244,11 @@ fn default_otlp_filter() -> String {
|
||||
fn default_tracing_flame_output_path() -> String { "./tracing.folded".to_owned() }
|
||||
|
||||
fn default_trusted_servers() -> Vec<TrustedServer> {
|
||||
// TODO(nex): Once we can be a notary, add maintainer(?) homeservers here.
|
||||
// Rationale: Users are already running our code, arguably that's a higher
|
||||
// level of trust than is assigned to notaries in the first place.
|
||||
// We should still remind everyone that notaries are evil and out to get you
|
||||
// and to replace this list with servers they actually trust.
|
||||
let trusted_servers = vec![ruma::owned_server_name!("matrix.org")];
|
||||
let trusted_servers = vec![
|
||||
ruma::owned_server_name!("continuwuity.org"),
|
||||
ruma::owned_server_name!("continuwuity.rocks"),
|
||||
ruma::owned_server_name!("matrix.org"),
|
||||
];
|
||||
trusted_servers
|
||||
.into_iter()
|
||||
.map(TrustedServer::Name)
|
||||
@@ -3395,15 +3379,20 @@ fn default_admin_log_capture() -> String {
|
||||
|
||||
fn default_admin_room_tag() -> String { "m.server_notice".to_owned() }
|
||||
|
||||
#[must_use]
|
||||
#[allow(clippy::as_conversions, clippy::cast_precision_loss)]
|
||||
fn parallelism_scaled_f64(val: f64) -> f64 { val * (sys::available_parallelism() as f64) }
|
||||
pub fn parallelism_scaled_f64(val: f64) -> f64 { val * (sys::available_parallelism() as f64) }
|
||||
|
||||
fn parallelism_scaled_u32(val: u32) -> u32 {
|
||||
let val = val.try_into().expect("failed to cast u32 to usize");
|
||||
parallelism_scaled(val).try_into().unwrap_or(u32::MAX)
|
||||
#[must_use]
|
||||
#[allow(clippy::as_conversions, clippy::cast_possible_truncation)]
|
||||
pub fn parallelism_scaled_u32(val: u32) -> u32 {
|
||||
val.saturating_mul(sys::available_parallelism() as u32)
|
||||
}
|
||||
|
||||
fn parallelism_scaled(val: usize) -> usize { val.saturating_mul(sys::available_parallelism()) }
|
||||
#[must_use]
|
||||
pub fn parallelism_scaled(val: usize) -> usize {
|
||||
val.saturating_mul(sys::available_parallelism())
|
||||
}
|
||||
|
||||
fn default_db_pool_workers() -> usize {
|
||||
sys::available_parallelism()
|
||||
|
||||
@@ -21,6 +21,7 @@ pub struct Instruments {
|
||||
pub sender_transaction_duration: Histogram<f64>,
|
||||
pub sender_events: Counter<u64>,
|
||||
pub sender_events_queued: Counter<u64>,
|
||||
pub sender_panics: Counter<u64>,
|
||||
|
||||
pub media_write_size: Histogram<u64>,
|
||||
pub media_read_size: Histogram<u64>,
|
||||
@@ -106,6 +107,11 @@ impl Instruments {
|
||||
.with_description("PDUs and EDUs queued for sending")
|
||||
.with_unit("{event}")
|
||||
.build(),
|
||||
sender_panics: meter
|
||||
.u64_counter("continuwuity.sender.panics")
|
||||
.with_description("Panics caught in outgoing transactions and sender workers")
|
||||
.with_unit("{panic}")
|
||||
.build(),
|
||||
|
||||
media_write_size: size(
|
||||
"continuwuity.media.write.size",
|
||||
|
||||
@@ -5,6 +5,7 @@ pub type DigestOut = [u8; 256 / 8];
|
||||
/// Sha256 hash (input gather joined by 0xFF bytes)
|
||||
#[must_use]
|
||||
#[tracing::instrument(skip(inputs), level = "trace")]
|
||||
#[allow(clippy::unnecessary_fallible_conversions)]
|
||||
pub fn delimited<'a, T, I>(mut inputs: I) -> DigestOut
|
||||
where
|
||||
I: Iterator<Item = T> + 'a,
|
||||
@@ -25,6 +26,7 @@ where
|
||||
/// Sha256 hash (input gather)
|
||||
#[must_use]
|
||||
#[tracing::instrument(skip(inputs), level = "trace")]
|
||||
#[allow(clippy::unnecessary_fallible_conversions)]
|
||||
pub fn concat<'a, T, I>(inputs: I) -> DigestOut
|
||||
where
|
||||
I: Iterator<Item = T> + 'a,
|
||||
@@ -43,6 +45,7 @@ where
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[tracing::instrument(skip(input), level = "trace")]
|
||||
#[allow(clippy::unnecessary_fallible_conversions)]
|
||||
pub fn hash<T>(input: T) -> DigestOut
|
||||
where
|
||||
T: AsRef<[u8]>,
|
||||
|
||||
@@ -29,7 +29,7 @@ fn descriptor_cf_options(
|
||||
let mut opts = set_table_options(opts, &desc, cache)?;
|
||||
|
||||
opts.set_min_write_buffer_number(1);
|
||||
opts.set_max_write_buffer_number(2);
|
||||
opts.set_max_write_buffer_number(3);
|
||||
opts.set_write_buffer_size(desc.write_size);
|
||||
|
||||
opts.set_target_file_size_base(desc.file_size);
|
||||
|
||||
@@ -232,6 +232,10 @@ pub(super) static MAPS: &[Descriptor] = &[
|
||||
name: "roomsynctoken_shortstatehash",
|
||||
..descriptor::DROPPED
|
||||
},
|
||||
Descriptor {
|
||||
name: "roomts_pduid",
|
||||
..descriptor::SEQUENTIAL_SMALL
|
||||
},
|
||||
Descriptor {
|
||||
name: "roomuserdataid_accountdata",
|
||||
..descriptor::RANDOM_SMALL
|
||||
|
||||
+33
-8
@@ -77,6 +77,7 @@ full = [
|
||||
]
|
||||
|
||||
brotli_compression = [
|
||||
"conduwuit-api/brotli_compression",
|
||||
"conduwuit-core/brotli_compression",
|
||||
"conduwuit-router/brotli_compression",
|
||||
"conduwuit-service/brotli_compression",
|
||||
@@ -88,10 +89,11 @@ direct_tls = [
|
||||
"conduwuit-router/direct_tls"
|
||||
]
|
||||
element_hacks = [
|
||||
"conduwuit-api/element_hacks",
|
||||
"conduwuit-service/element_hacks",
|
||||
"conduwuit-router/element_hacks",
|
||||
]
|
||||
gzip_compression = [
|
||||
"conduwuit-api/gzip_compression",
|
||||
"conduwuit-core/gzip_compression",
|
||||
"conduwuit-router/gzip_compression",
|
||||
"conduwuit-service/gzip_compression",
|
||||
@@ -100,21 +102,21 @@ hardened_malloc = [
|
||||
"conduwuit-core/hardened_malloc",
|
||||
]
|
||||
http3 = [
|
||||
"conduwuit-service/http3"
|
||||
"reqwest/http3"
|
||||
]
|
||||
ring = [
|
||||
"rustls/ring",
|
||||
"rustls/ring"
|
||||
]
|
||||
|
||||
aws_lc_rs = [
|
||||
"rustls/aws_lc_rs",
|
||||
"dep:aws-lc-rs"
|
||||
]
|
||||
io_uring = [
|
||||
"conduwuit-service/io_uring",
|
||||
"conduwuit-database/io_uring",
|
||||
]
|
||||
jemalloc = [
|
||||
"conduwuit-core/jemalloc",
|
||||
"conduwuit-service/jemalloc",
|
||||
"conduwuit-database/jemalloc",
|
||||
]
|
||||
jemalloc_prof = [
|
||||
"conduwuit-core/jemalloc_prof",
|
||||
@@ -143,13 +145,19 @@ perf_measurements = [
|
||||
release_max_log_level = [
|
||||
"tracing/max_level_trace",
|
||||
"tracing/release_max_level_info",
|
||||
"log/max_level_trace",
|
||||
"log/release_max_level_info",
|
||||
"conduwuit-admin/release_max_log_level",
|
||||
"conduwuit-api/release_max_log_level",
|
||||
"conduwuit-core/release_max_log_level",
|
||||
"conduwuit-database/release_max_log_level",
|
||||
"conduwuit-router/release_max_log_level",
|
||||
"conduwuit-service/release_max_log_level",
|
||||
]
|
||||
sentry_telemetry = [
|
||||
"dep:sentry",
|
||||
"dep:sentry-tracing",
|
||||
"dep:sentry-tower",
|
||||
"conduwuit-core/sentry_telemetry",
|
||||
"conduwuit-router/sentry_telemetry",
|
||||
]
|
||||
@@ -172,7 +180,9 @@ url_preview = [
|
||||
"conduwuit-service/url_preview",
|
||||
]
|
||||
zstd_compression = [
|
||||
"conduwuit-api/zstd_compression",
|
||||
"conduwuit-core/zstd_compression",
|
||||
"conduwuit-database/zstd_compression",
|
||||
"conduwuit-router/zstd_compression",
|
||||
"conduwuit-service/zstd_compression",
|
||||
]
|
||||
@@ -182,10 +192,10 @@ conduwuit_mods = [
|
||||
bindgen-static = [
|
||||
# "bindgen/static"
|
||||
# "clang-sys/static"
|
||||
"conduwuit-service/bindgen-static"
|
||||
"conduwuit-database/bindgen-static"
|
||||
]
|
||||
bindgen-runtime = [
|
||||
"conduwuit-service/bindgen-runtime"
|
||||
"conduwuit-database/bindgen-runtime"
|
||||
]
|
||||
|
||||
[build-dependencies]
|
||||
@@ -193,7 +203,10 @@ bindgen-runtime = [
|
||||
# clang-sys = {version = "1", default-features = false}
|
||||
|
||||
[dependencies]
|
||||
conduwuit-admin.workspace = true
|
||||
conduwuit-api.workspace = true
|
||||
conduwuit-core.workspace = true
|
||||
conduwuit-database.workspace = true
|
||||
conduwuit-router.workspace = true
|
||||
conduwuit-service.workspace = true
|
||||
conduwuit-build-metadata.workspace = true
|
||||
@@ -205,6 +218,7 @@ dtor.workspace = true
|
||||
console-subscriber.optional = true
|
||||
console-subscriber.workspace = true
|
||||
const-str.workspace = true
|
||||
log.workspace = true
|
||||
opentelemetry.workspace = true
|
||||
opentelemetry-otlp.optional = true
|
||||
opentelemetry-otlp.workspace = true
|
||||
@@ -212,10 +226,14 @@ opentelemetry-prometheus.workspace = true
|
||||
opentelemetry-semantic-conventions.workspace = true
|
||||
opentelemetry_sdk.workspace = true
|
||||
prometheus.workspace = true
|
||||
sentry-tower.optional = true
|
||||
sentry-tower.workspace = true
|
||||
sentry-tracing.optional = true
|
||||
sentry-tracing.workspace = true
|
||||
sentry.optional = true
|
||||
sentry.workspace = true
|
||||
tokio-metrics.optional = true
|
||||
tokio-metrics.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing-flame.optional = true
|
||||
tracing-flame.workspace = true
|
||||
@@ -225,7 +243,14 @@ tracing-subscriber.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-journald = { workspace = true, optional = true }
|
||||
parking_lot.workspace = true
|
||||
reqwest = { workspace = true, default-features = false }
|
||||
rustls = { workspace = true, default-features = false }
|
||||
aws-lc-rs = { version = "1.19.0", default-features = false, 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
|
||||
|
||||
@@ -8,7 +8,7 @@ use axum::{
|
||||
extract::State,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use conduwuit::{Result, debug, debug_error, debug_warn, err, error, trace};
|
||||
use conduwuit::{Result, debug_warn, err, error, info, trace};
|
||||
use conduwuit_service::Services;
|
||||
use futures::FutureExt;
|
||||
use http::{Method, StatusCode, Uri};
|
||||
@@ -102,11 +102,11 @@ fn handle_result(method: &Method, uri: &Uri, result: Response) -> Result<Respons
|
||||
let reason = status.canonical_reason().unwrap_or("Unknown Reason");
|
||||
|
||||
if status.is_server_error() {
|
||||
error!(%method, %uri, "{code} {reason}");
|
||||
info!(%method, %uri, "{code} {reason}");
|
||||
} else if status.is_client_error() {
|
||||
debug_error!(%method, %uri, "{code} {reason}");
|
||||
info!(%method, %uri, "{code} {reason}");
|
||||
} else if status.is_redirection() {
|
||||
debug!(%method, %uri, "{code} {reason}");
|
||||
trace!(%method, %uri, "{code} {reason}");
|
||||
} else {
|
||||
trace!(%method, %uri, "{code} {reason}");
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
pub mod notary;
|
||||
@@ -0,0 +1,58 @@
|
||||
//! `POST /_matrix/key/*/query`
|
||||
//!
|
||||
//! Endpoint to query signing keys through other (notary) servers.
|
||||
|
||||
pub mod unstable {
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma::{
|
||||
OwnedServerName, OwnedServerSigningKeyId,
|
||||
api::{
|
||||
federation::{
|
||||
authentication::ServerSignatures,
|
||||
discovery::{ServerSigningKeys, get_remote_server_keys_batch::v2::QueryCriteria},
|
||||
},
|
||||
request, response,
|
||||
},
|
||||
metadata,
|
||||
serde::Raw,
|
||||
};
|
||||
|
||||
metadata! {
|
||||
method: POST,
|
||||
rate_limited: true,
|
||||
authentication: ServerSignatures,
|
||||
history: {
|
||||
unstable("org.continuwuity.msc4553") => "/_matrix/key/unstable/org.continuwuity.msc4556/query",
|
||||
}
|
||||
}
|
||||
|
||||
#[request]
|
||||
pub struct Request {
|
||||
pub server_keys:
|
||||
BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, QueryCriteria>>,
|
||||
}
|
||||
|
||||
#[response]
|
||||
pub struct Response {
|
||||
pub server_keys: Vec<Raw<ServerSigningKeys>>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
server_keys: BTreeMap<
|
||||
OwnedServerName,
|
||||
BTreeMap<OwnedServerSigningKeyId, QueryCriteria>,
|
||||
>,
|
||||
) -> Self {
|
||||
Self { server_keys }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Creates a new `Response` with the given keys.
|
||||
#[must_use]
|
||||
pub fn new(server_keys: Vec<Raw<ServerSigningKeys>>) -> Self { Self { server_keys } }
|
||||
}
|
||||
}
|
||||
@@ -6,3 +6,5 @@ pub mod invite_permission_config;
|
||||
pub mod meowlnir_antispam;
|
||||
pub mod policy;
|
||||
pub mod pushers;
|
||||
|
||||
pub mod federation;
|
||||
@@ -16,12 +16,6 @@ crate-type = [
|
||||
]
|
||||
|
||||
[features]
|
||||
bindgen-runtime = [
|
||||
"conduwuit-database/bindgen-runtime"
|
||||
]
|
||||
bindgen-static = [
|
||||
"conduwuit-database/bindgen-static"
|
||||
]
|
||||
brotli_compression = [
|
||||
"conduwuit-core/brotli_compression",
|
||||
"reqwest/brotli",
|
||||
@@ -35,9 +29,6 @@ gzip_compression = [
|
||||
"conduwuit-core/gzip_compression",
|
||||
"reqwest/gzip",
|
||||
]
|
||||
http3 = [
|
||||
"reqwest/http3"
|
||||
]
|
||||
io_uring = [
|
||||
"conduwuit-database/io_uring",
|
||||
]
|
||||
@@ -131,9 +122,6 @@ lettre.workspace = true
|
||||
resolvematrix.workspace = true
|
||||
serde_urlencoded.workspace = true
|
||||
openidconnect.workspace = true
|
||||
# We use this to set TLS backend features on the outdated reqwest bundled by openidconnect,
|
||||
# which is necessary to call `danger_accept_invalid_certs`.
|
||||
reqwest_0_12.workspace = true
|
||||
rand.workspace = true
|
||||
|
||||
[target.'cfg(all(unix, target_os = "linux"))'.dependencies]
|
||||
|
||||
@@ -111,7 +111,7 @@ impl crate::Service for Service {
|
||||
.local_address(url_preview_bind_addr)
|
||||
.timeout(Duration::from_secs(config.url_preview_timeout))
|
||||
.redirect(redirect::Policy::limited(3))
|
||||
.user_agent(url_preview_user_agent)
|
||||
.user_agent(url_preview_user_agent.replace("<version>", conduwuit::version_ua()))
|
||||
.build()?,
|
||||
|
||||
external_resource: base(config, reqwest_dns_resolver.clone())?
|
||||
|
||||
@@ -223,6 +223,8 @@ impl Data {
|
||||
x => x,
|
||||
};*/
|
||||
|
||||
// TODO(nex): Oh my god this is awful when can we kill it
|
||||
|
||||
let title = match values
|
||||
.next()
|
||||
.and_then(|b| String::from_utf8(b.to_vec()).ok())
|
||||
@@ -321,6 +323,11 @@ impl Data {
|
||||
video_height,
|
||||
audio,
|
||||
audio_size,
|
||||
..Default::default() /* TODO(nex,silversys): This weird manual field
|
||||
* de/serialisation just needs replacing with JSON storage to
|
||||
* avoid this mess. This is consequently intentionally
|
||||
* dropping information added later (like image alt text).
|
||||
* I'll do it later. */
|
||||
})
|
||||
}
|
||||
}
|
||||
+231
-46
@@ -7,8 +7,9 @@
|
||||
|
||||
use std::time::SystemTime;
|
||||
|
||||
use conduwuit::{Err, Result, debug, err, utils::response::LimitReadExt};
|
||||
use conduwuit::{Err, Result, debug, err, info, utils::response::LimitReadExt};
|
||||
use ipaddress::IPAddress;
|
||||
use lettre::message::header::ContentType;
|
||||
use ruma::OwnedMxcUri;
|
||||
use serde::Serialize;
|
||||
use url::Url;
|
||||
@@ -16,20 +17,54 @@ use url::Url;
|
||||
use super::Service;
|
||||
use crate::media::mxc::Mxc;
|
||||
|
||||
#[derive(Serialize, Default)]
|
||||
#[derive(Serialize, Default, Debug)]
|
||||
pub struct UrlPreviewData {
|
||||
// From https://ogp.me/
|
||||
/// The title of your object as it should appear within the graph
|
||||
/// "The Rock".
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:title"))]
|
||||
pub title: Option<String>,
|
||||
|
||||
/// The type of your object, e.g., "video.movie".
|
||||
#[serde(skip_serializing_if = "String::is_empty", rename(serialize = "og:type"))]
|
||||
pub site_type: String,
|
||||
/// The canonical URL of your object that will be used as its permanent ID
|
||||
/// in the graph.
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:url"))]
|
||||
pub url: Option<String>,
|
||||
/// A one to two sentence description of your object.
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:description"))]
|
||||
pub description: Option<String>,
|
||||
/// The word that appears before this object's title in a sentence.
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:determiner"))]
|
||||
pub determiner: Option<String>,
|
||||
/// The locale these tags are marked up in
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:locale"))]
|
||||
pub locale: Option<String>,
|
||||
/// If your object is part of a larger web site, the name which should be
|
||||
/// displayed for the overall site.
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:site_name"))]
|
||||
pub site_name: Option<String>,
|
||||
|
||||
/// An image URL which should represent your object within the graph.
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:image"))]
|
||||
pub image: Option<String>,
|
||||
/// A MIME type for this image.
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:image:type"))]
|
||||
pub image_type: Option<ContentType>,
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "matrix:image:size"))]
|
||||
pub image_size: Option<usize>,
|
||||
/// The number of pixels wide.
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:image:width"))]
|
||||
pub image_width: Option<u32>,
|
||||
/// The number of pixels high.
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:image:height"))]
|
||||
pub image_height: Option<u32>,
|
||||
/// A description of what is in the image (not a caption).
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:image:alt"))]
|
||||
pub image_alt: Option<String>,
|
||||
|
||||
/// A URL to a video file that complements this object.
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:video"))]
|
||||
pub video: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "matrix:video:size"))]
|
||||
@@ -38,6 +73,11 @@ pub struct UrlPreviewData {
|
||||
pub video_width: Option<u32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:video:height"))]
|
||||
pub video_height: Option<u32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:video:type"))]
|
||||
pub video_type: Option<ContentType>,
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:video:alt"))]
|
||||
pub video_alt: Option<String>,
|
||||
/// A URL to an audio file to accompany this object.
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "og:audio"))]
|
||||
pub audio: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename(serialize = "matrix:audio:size"))]
|
||||
@@ -100,7 +140,9 @@ impl Service {
|
||||
}
|
||||
|
||||
let Some(content_type) = response.headers().get(reqwest::header::CONTENT_TYPE) else {
|
||||
return Err!(Request(Unknown("Unknown or invalid Content-Type header")));
|
||||
return Err!(Request(Unknown(
|
||||
"Response contains unknown, invalid, or missing Content-Type header"
|
||||
)));
|
||||
};
|
||||
|
||||
let content_type = content_type
|
||||
@@ -109,12 +151,10 @@ impl Service {
|
||||
|
||||
let data = match content_type {
|
||||
| html if html.starts_with("text/html") => self.download_html(url.as_str()).await?,
|
||||
| img if img.starts_with("image/") => self.download_image(url.as_str(), None).await?,
|
||||
| video if video.starts_with("video/") =>
|
||||
self.download_video(url.as_str(), None).await?,
|
||||
| audio if audio.starts_with("audio/") =>
|
||||
self.download_audio(url.as_str(), None).await?,
|
||||
| _ => return Err!(Request(Unknown("Unsupported Content-Type"))),
|
||||
| img if img.starts_with("image/") => self.download_image(url.as_str()).await?,
|
||||
| video if video.starts_with("video/") => self.download_video(url.as_str()).await?,
|
||||
| audio if audio.starts_with("audio/") => self.download_audio(url.as_str()).await?,
|
||||
| other => return Err!(Request(Unknown("Unsupported Content-Type: {other}"))),
|
||||
};
|
||||
|
||||
self.set_url_preview(url.as_str(), &data).await?;
|
||||
@@ -123,17 +163,13 @@ impl Service {
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
pub async fn download_image(
|
||||
&self,
|
||||
url: &str,
|
||||
preview_data: Option<UrlPreviewData>,
|
||||
) -> Result<UrlPreviewData> {
|
||||
pub async fn download_image(&self, url: &str) -> Result<UrlPreviewData> {
|
||||
use conduwuit::utils::random_string;
|
||||
use image::ImageReader;
|
||||
|
||||
use crate::media::mxc::Mxc;
|
||||
|
||||
let mut preview_data = preview_data.unwrap_or_default();
|
||||
let mut preview_data = UrlPreviewData::default();
|
||||
|
||||
let response = self.services.client.url_preview.get(url).send().await?;
|
||||
if !response.status().is_success() {
|
||||
@@ -157,13 +193,12 @@ impl Service {
|
||||
.ok_or_else(|| err!(Request(Unknown("Downloaded file is not a supported image"))))?
|
||||
.to_mime_type();
|
||||
|
||||
if preview_data.image_height.is_none() || preview_data.image_width.is_none() {
|
||||
let (width, height) = reader.into_dimensions().map_err(|error| {
|
||||
err!(Request(Unknown("Failed to read preview image dimensions: {error}")))
|
||||
})?;
|
||||
preview_data.image_width.get_or_insert(width);
|
||||
preview_data.image_height.get_or_insert(height);
|
||||
}
|
||||
let (width, height) = reader.into_dimensions().map_err(|error| {
|
||||
err!(Request(Unknown("Failed to read preview image dimensions: {error}")))
|
||||
})?;
|
||||
preview_data.image_width.get_or_insert(width);
|
||||
preview_data.image_height.get_or_insert(height);
|
||||
preview_data.image_type = content_type.parse().ok();
|
||||
|
||||
let mxc = Mxc {
|
||||
server_name: self.services.globals.server_name(),
|
||||
@@ -179,12 +214,9 @@ impl Service {
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
pub async fn download_video(
|
||||
&self,
|
||||
url: &str,
|
||||
preview_data: Option<UrlPreviewData>,
|
||||
) -> Result<UrlPreviewData> {
|
||||
let mut preview_data = preview_data.unwrap_or_default();
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub async fn download_video(&self, url: &str) -> Result<UrlPreviewData> {
|
||||
let mut preview_data = UrlPreviewData::default();
|
||||
|
||||
if self.services.globals.url_preview_allow_audio_video() {
|
||||
let (url, size) = self.download_media(url).await?;
|
||||
@@ -196,12 +228,9 @@ impl Service {
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
pub async fn download_audio(
|
||||
&self,
|
||||
url: &str,
|
||||
preview_data: Option<UrlPreviewData>,
|
||||
) -> Result<UrlPreviewData> {
|
||||
let mut preview_data = preview_data.unwrap_or_default();
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub async fn download_audio(&self, url: &str) -> Result<UrlPreviewData> {
|
||||
let mut preview_data = UrlPreviewData::default();
|
||||
|
||||
if self.services.globals.url_preview_allow_audio_video() {
|
||||
let (url, size) = self.download_media(url).await?;
|
||||
@@ -212,6 +241,7 @@ impl Service {
|
||||
Ok(preview_data)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub async fn download_media(&self, url: &str) -> Result<(OwnedMxcUri, usize)> {
|
||||
use conduwuit::utils::random_string;
|
||||
use http::header::CONTENT_TYPE;
|
||||
@@ -269,6 +299,7 @@ impl Service {
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
#[tracing::instrument(skip(self))]
|
||||
async fn download_html(&self, url: &str) -> Result<UrlPreviewData> {
|
||||
use webpage::HTML;
|
||||
|
||||
@@ -286,32 +317,75 @@ impl Service {
|
||||
.expect("u64 should fit in usize"),
|
||||
)
|
||||
.await?;
|
||||
let Ok(html) = HTML::from_string(body.clone(), Some(url.to_owned())) else {
|
||||
let Ok(html) = HTML::from_string(body.clone(), Some(url.to_owned()))
|
||||
.inspect_err(|e| debug!(error=?e, "Failed to parse HTML data"))
|
||||
else {
|
||||
return Err!(Request(Unknown("Failed to parse HTML")));
|
||||
};
|
||||
|
||||
let mut preview_data = UrlPreviewData::default();
|
||||
let mut preview_data = UrlPreviewData::from(&html.opengraph);
|
||||
debug!(parsed=?preview_data, deserialised=?html.opengraph, "Parsed opengraph data");
|
||||
|
||||
if let Some(obj) = html.opengraph.images.first() {
|
||||
preview_data = self.download_image(&obj.url, Some(preview_data)).await?;
|
||||
info!(asset_url=%obj.url, "Downloading preview image");
|
||||
if let Ok(image_data) = self.download_image(&obj.url).await.inspect_err(
|
||||
|e| info!(error=?e, asset_url=%obj.url, "Could not download URL preview image"),
|
||||
) {
|
||||
preview_data.image = image_data.image;
|
||||
preview_data.image_size = image_data.image_size;
|
||||
// Prioritise what the top-level site specified, falling back to
|
||||
// detected params.
|
||||
preview_data.image_width = preview_data.image_width.or(image_data.image_width);
|
||||
preview_data.image_height = preview_data.image_height.or(image_data.image_height);
|
||||
preview_data.image_type = preview_data.image_type.or(image_data.image_type);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(obj) = html.opengraph.videos.first() {
|
||||
preview_data = self.download_video(&obj.url, Some(preview_data)).await?;
|
||||
preview_data.video_width = obj.properties.get("width").and_then(|v| v.parse().ok());
|
||||
preview_data.video_height = obj.properties.get("height").and_then(|v| v.parse().ok());
|
||||
info!(asset_url=%obj.url, "Downloading preview video");
|
||||
if let Ok(video_data) = self.download_video(&obj.url).await.inspect_err(
|
||||
|e| info!(error=?e, asset_url=%obj.url, "Could not download URL preview video"),
|
||||
) {
|
||||
preview_data.video = video_data.video;
|
||||
preview_data.video_size = video_data.video_size;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(obj) = html.opengraph.audios.first() {
|
||||
preview_data = self.download_audio(&obj.url, Some(preview_data)).await?;
|
||||
info!(asset_url=%obj.url, "Downloading URL preview audio");
|
||||
if let Ok(audio_data) = self.download_audio(&obj.url).await.inspect_err(
|
||||
|e| info!(error=?e, asset_url=%obj.url, "Could not download URL preview audio"),
|
||||
) {
|
||||
preview_data.audio = audio_data.audio;
|
||||
preview_data.audio_size = audio_data.audio_size;
|
||||
}
|
||||
}
|
||||
|
||||
let props = html.opengraph.properties;
|
||||
// Provide defaults for some params
|
||||
preview_data.title = preview_data.title.or(html.title);
|
||||
preview_data.description = preview_data.description.or(html.description);
|
||||
preview_data.url = preview_data.url.or_else(|| Some(url.to_owned()));
|
||||
|
||||
/* use OpenGraph title/description, but fall back to HTML if not
|
||||
* available */
|
||||
preview_data.title = props.get("title").cloned().or(html.title);
|
||||
preview_data.description = props.get("description").cloned().or(html.description);
|
||||
// We remove og:image:*, og:video:*, and og:audio:* if their respective
|
||||
// prior-level properties are not present.
|
||||
// We do this here instead of in the From<> impl because we can't know
|
||||
// if we'll be able to fetch the media to convert it to an mxc that
|
||||
// point.
|
||||
if preview_data.image.is_none() {
|
||||
preview_data.image_type = None;
|
||||
preview_data.image_alt = None;
|
||||
preview_data.image_height = None;
|
||||
preview_data.image_width = None;
|
||||
}
|
||||
if preview_data.video.is_none() {
|
||||
preview_data.video_type = None;
|
||||
preview_data.video_alt = None;
|
||||
preview_data.video_height = None;
|
||||
preview_data.video_width = None;
|
||||
}
|
||||
if preview_data.audio.is_none() {
|
||||
preview_data.audio_size = None;
|
||||
}
|
||||
|
||||
Ok(preview_data)
|
||||
}
|
||||
@@ -443,3 +517,114 @@ impl Service {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&webpage::Opengraph> for UrlPreviewData {
|
||||
fn from(og: &webpage::Opengraph) -> Self {
|
||||
Self {
|
||||
title: og.properties.get("title").cloned(),
|
||||
description: og.properties.get("description").cloned(),
|
||||
site_type: og.og_type.clone(),
|
||||
url: og.properties.get("url").cloned(),
|
||||
determiner: og.properties.get("determiner").cloned(),
|
||||
locale: og.properties.get("locale").cloned(),
|
||||
site_name: og.properties.get("site_name").cloned(),
|
||||
image_type: og
|
||||
.images
|
||||
.first()
|
||||
.and_then(|img| img.properties.get("type").and_then(|t| t.parse().ok())),
|
||||
image_width: og
|
||||
.images
|
||||
.first()
|
||||
.and_then(|img| img.properties.get("width").and_then(|w| w.parse().ok())),
|
||||
image_height: og
|
||||
.images
|
||||
.first()
|
||||
.and_then(|img| img.properties.get("height").and_then(|h| h.parse().ok())),
|
||||
image_alt: og
|
||||
.images
|
||||
.first()
|
||||
.and_then(|img| img.properties.get("alt").cloned()),
|
||||
video_type: og
|
||||
.videos
|
||||
.first()
|
||||
.and_then(|vid| vid.properties.get("type"))
|
||||
.and_then(|t| t.parse().ok()),
|
||||
video_width: og
|
||||
.videos
|
||||
.first()
|
||||
.and_then(|vid| vid.properties.get("width"))
|
||||
.and_then(|w| w.parse().ok()),
|
||||
video_height: og
|
||||
.videos
|
||||
.first()
|
||||
.and_then(|vid| vid.properties.get("height"))
|
||||
.and_then(|h| h.parse().ok()),
|
||||
video_alt: og
|
||||
.videos
|
||||
.first()
|
||||
.and_then(|vid| vid.properties.get("alt").cloned()),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use webpage::HTML;
|
||||
|
||||
use super::UrlPreviewData;
|
||||
|
||||
#[test]
|
||||
fn test_urlpreviewdata_parses_correctly() {
|
||||
let html = r#"
|
||||
<html>
|
||||
<head>
|
||||
<meta property="og:title" content="Test Title" />
|
||||
<meta property="og:description" content="Test Description" />
|
||||
<meta property="og:image" content="https://example.com/image.png" />
|
||||
<meta property="og:url" content="https://example.com/index.html" />
|
||||
<meta property="og:type" content="org.continuwuity.other" />
|
||||
<meta property="og:site_name" content="Example Site" />
|
||||
<meta property="og:image:alt" content="An example image" />
|
||||
<meta property="og:image:type" content="image/png" />
|
||||
<meta property="og:image:height" content="69" />
|
||||
<meta property="og:image:width" content="420" />
|
||||
<meta property="og:video" content="https://example.com/video.mp4" />
|
||||
<meta property="og:audio" content="https://example.com/audio.ogg" />
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
"#;
|
||||
|
||||
let parsed_html =
|
||||
HTML::from_string(html.to_owned(), Some("https://example.com".to_owned()))
|
||||
.expect("Failed to parse HTML");
|
||||
|
||||
let data = UrlPreviewData::from(&parsed_html.opengraph);
|
||||
|
||||
assert_eq!(data.title, Some("Test Title".to_owned()));
|
||||
assert_eq!(data.description, Some("Test Description".to_owned()));
|
||||
assert_eq!(
|
||||
data.image, None,
|
||||
"UrlPreviewData should not inherit HTTP/S URL from URL preview"
|
||||
);
|
||||
assert_eq!(
|
||||
data.video, None,
|
||||
"UrlPreviewData should not inherit HTTP/S URL from URL preview"
|
||||
);
|
||||
assert_eq!(
|
||||
data.audio, None,
|
||||
"UrlPreviewData should not inherit HTTP/S URL from URL preview"
|
||||
);
|
||||
assert_eq!(data.url, Some("https://example.com/index.html".to_owned()));
|
||||
assert_eq!(data.site_type, "org.continuwuity.other".to_owned());
|
||||
assert_eq!(data.site_name, Some("Example Site".to_owned()));
|
||||
assert_eq!(data.image_alt, Some("An example image".to_owned()));
|
||||
assert_eq!(data.image_type, Some("image/png".parse().unwrap()));
|
||||
assert_eq!(data.image_height, Some(69));
|
||||
assert_eq!(data.image_width, Some(420));
|
||||
assert_eq!(data.image_size, None, "*_size must be None when pulling from opengraph");
|
||||
assert_eq!(data.video_size, None, "*_size must be None when pulling from opengraph");
|
||||
assert_eq!(data.audio_size, None, "*_size must be None when pulling from opengraph");
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,28 @@ impl Services {
|
||||
},
|
||||
);
|
||||
|
||||
self.gauge(
|
||||
"continuwuity.sender.requests",
|
||||
"Estimated outgoing requests stored as queued or in flight",
|
||||
"{request}",
|
||||
|services, observer| {
|
||||
for (state, count) in services.sending.db.request_counts() {
|
||||
if let Some(count) = count {
|
||||
observer.observe(count, &[KeyValue::new("state", state)]);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
self.gauge(
|
||||
"continuwuity.sender.workers",
|
||||
"Running sender workers",
|
||||
"{worker}",
|
||||
|services, observer| {
|
||||
observe(observer, services.sending.workers_alive(), &[]);
|
||||
},
|
||||
);
|
||||
|
||||
self.gauge(
|
||||
"continuwuity.federation.incoming.transactions.active",
|
||||
"Incoming federation transactions currently being processed",
|
||||
|
||||
@@ -18,11 +18,11 @@ use conduwuit::{
|
||||
},
|
||||
warn,
|
||||
};
|
||||
use database::{Deserialized, Ignore, Json};
|
||||
use database::{Database, Deserialized, Ignore, Json};
|
||||
use futures::{FutureExt, StreamExt, TryStreamExt};
|
||||
use itertools::Itertools;
|
||||
use ruma::{
|
||||
OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedUserId, UserId,
|
||||
MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedUserId, UserId,
|
||||
api::OAuthClientScope,
|
||||
events::{
|
||||
AnyStrippedStateEvent, GlobalAccountDataEventType, StateEventType,
|
||||
@@ -32,9 +32,13 @@ use ruma::{
|
||||
push::Ruleset,
|
||||
serde::{Raw, from_raw_json_value},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, value::to_raw_value};
|
||||
|
||||
use crate::{Services, media, rooms, rooms::short::ShortStateHash};
|
||||
use crate::{
|
||||
Services, media, rooms,
|
||||
rooms::{short::ShortStateHash, timeline::RawPduId},
|
||||
};
|
||||
|
||||
type MigrationFn =
|
||||
for<'a> fn(&'a Services) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
|
||||
@@ -176,6 +180,36 @@ migration!(stringify!($name) => $name)
|
||||
// This is backwards compatible because old versions never read the
|
||||
// account data entries it removes.
|
||||
migration!(remove_replaced_account_data),
|
||||
// This is backwards compatible because old versions ignore the
|
||||
// `roomts_pduid` keyspace.
|
||||
Migration(rooms::timeline::TIMESTAMP_INDEX_MIGRATION, |services| {
|
||||
Box::pin(async {
|
||||
let global = &services.db["global"];
|
||||
if global
|
||||
.exists(rooms::timeline::TIMESTAMP_INDEX_MIGRATION)
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let until = match global.get(ROOMTS_UNTIL).await.deserialized::<u64>() {
|
||||
| Ok(until) => until,
|
||||
| Err(_) => {
|
||||
let until = services.globals.current_count()?;
|
||||
global.insert(ROOMTS_UNTIL, until.to_be_bytes());
|
||||
until
|
||||
},
|
||||
};
|
||||
|
||||
services
|
||||
.server
|
||||
.runtime()
|
||||
.spawn(populate_roomts_pduid(services.db.clone(), until));
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}),
|
||||
]
|
||||
};
|
||||
|
||||
@@ -961,6 +995,38 @@ async fn drop_server_signingkeys(services: &Services) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const ROOMTS_UNTIL: &str = "populate_roomts_pduid_until";
|
||||
|
||||
async fn populate_roomts_pduid(db: Arc<Database>, until: u64) {
|
||||
#[derive(Deserialize)]
|
||||
struct ExtractTs {
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
}
|
||||
|
||||
info!("Starting background migration to index PDUs by timestamp.");
|
||||
let start = Instant::now();
|
||||
let roomts_pduid = db["roomts_pduid"].clone();
|
||||
|
||||
db["pduid_pdu"]
|
||||
.raw_stream()
|
||||
.ignore_err()
|
||||
.ready_for_each(|(key, val)| {
|
||||
let pdu_id = RawPduId::from(key);
|
||||
if matches!(pdu_id.pdu_count(), PduCount::Normal(count) if count > until) {
|
||||
return;
|
||||
}
|
||||
if let Ok(pdu) = serde_json::from_slice::<ExtractTs>(val) {
|
||||
roomts_pduid
|
||||
.insert(&rooms::timeline::roomts_key(&pdu_id, pdu.origin_server_ts), []);
|
||||
}
|
||||
})
|
||||
.await;
|
||||
|
||||
db["global"].insert(rooms::timeline::TIMESTAMP_INDEX_MIGRATION, []);
|
||||
db["global"].remove(ROOMTS_UNTIL);
|
||||
info!(elapsed = ?start.elapsed(), "Finished indexing PDUs by timestamp.");
|
||||
}
|
||||
|
||||
async fn fix_oauth_scope_names(services: &Services) -> Result {
|
||||
let db = &services.db;
|
||||
let userdeviceid_oauthsessioninfo = db["userdeviceid_oauthsessioninfo"].clone();
|
||||
|
||||
@@ -13,6 +13,8 @@ mod migrations;
|
||||
mod service;
|
||||
pub mod services;
|
||||
pub mod state;
|
||||
#[cfg(test)]
|
||||
mod test_utils;
|
||||
|
||||
pub mod account_data;
|
||||
pub mod admin;
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use conduwuit::{
|
||||
Config, PduEvent, Server,
|
||||
log::{Log, LogLevelReloadHandles},
|
||||
metrics::Metrics,
|
||||
};
|
||||
use conduwuit::PduEvent;
|
||||
use futures::StreamExt;
|
||||
use ruma::{RoomId, RoomVersionId, events::StateEventType};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::test_utils::test_services;
|
||||
|
||||
#[tokio::test]
|
||||
async fn admitted_joins_do_not_disappear_after_a_merge() {
|
||||
use conduwuit::matrix::PartialPdu;
|
||||
@@ -20,7 +16,7 @@ async fn admitted_joins_do_not_disappear_after_a_merge() {
|
||||
},
|
||||
};
|
||||
|
||||
let (services, path) = test_services().await;
|
||||
let (services, path, _database) = test_services().await;
|
||||
let alice = UserId::parse("@alice:test.example").unwrap();
|
||||
let bob = UserId::parse("@bob:bob.example").unwrap();
|
||||
let charlie = UserId::parse("@charlie:charlie.example").unwrap();
|
||||
@@ -212,35 +208,6 @@ async fn admitted_joins_do_not_disappear_after_a_merge() {
|
||||
assert_eq!(results, [true, true], "both joined users must be able to send messages");
|
||||
}
|
||||
|
||||
async fn test_services() -> (Arc<crate::Services>, std::path::PathBuf) {
|
||||
let _ = rustls::crypto::ring::default_provider().install_default();
|
||||
let path = std::env::temp_dir()
|
||||
.join(format!("continuwuity-shared-state-{:016x}", rand::random::<u64>()));
|
||||
std::fs::create_dir(&path).unwrap();
|
||||
let config: Config = serde_json::from_value(json!({
|
||||
"server_name": "test.example",
|
||||
"database_path": path,
|
||||
"db_cache_capacity_mb": 16.0,
|
||||
"rocksdb_write_buffer_capacity_mb": 4.0,
|
||||
"allow_local_presence": false,
|
||||
"dns_servers": ["127.0.0.1"],
|
||||
"allow_invalid_tls_certificates_yes_i_know_what_the_fuck_i_am_doing_with_this_and_i_know_this_is_insecure": true
|
||||
}))
|
||||
.unwrap();
|
||||
let runtime = tokio::runtime::Handle::current();
|
||||
let server = Arc::new(Server::new(
|
||||
config,
|
||||
Some(runtime.clone()),
|
||||
Log {
|
||||
reload: LogLevelReloadHandles::default(),
|
||||
capture: Arc::default(),
|
||||
},
|
||||
Metrics::new(Some(runtime), opentelemetry::global::meter("test"), None),
|
||||
));
|
||||
let services = crate::Services::build(server).await.unwrap();
|
||||
(services, path)
|
||||
}
|
||||
|
||||
fn cache_key(
|
||||
services: &crate::Services,
|
||||
server: &ruma::ServerName,
|
||||
|
||||
@@ -349,7 +349,7 @@ impl super::Service {
|
||||
|
||||
// Insert pdu
|
||||
self.db
|
||||
.append_pdu(&pdu_id, pdu, room_id, &pdu_json, count2)
|
||||
.append_pdu(&pdu_id, pdu, room_id, &pdu_json, count2, pdu.origin_server_ts())
|
||||
.await;
|
||||
self.progress_extremities(pdu)
|
||||
.await
|
||||
|
||||
@@ -225,7 +225,8 @@ impl super::Service {
|
||||
.into();
|
||||
|
||||
// Insert pdu
|
||||
self.db.prepend_backfill_pdu(&pdu_id, &event_id, &value);
|
||||
self.db
|
||||
.prepend_backfill_pdu(&pdu_id, &event_id, &value, pdu.origin_server_ts());
|
||||
|
||||
drop(insert_lock);
|
||||
if pdu.kind == TimelineEventType::RoomMessage {
|
||||
|
||||
@@ -12,7 +12,9 @@ use database::{Database, Deserialized, Json, KeyVal, Map};
|
||||
use futures::{
|
||||
FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt, future::select_ok, pin_mut,
|
||||
};
|
||||
use ruma::{CanonicalJsonObject, EventId, OwnedUserId, RoomId, api::Direction};
|
||||
use ruma::{
|
||||
CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedUserId, RoomId, api::Direction,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
@@ -25,6 +27,7 @@ pub(super) struct Data {
|
||||
pduid_pdu: Arc<Map>,
|
||||
pduid_unredactedcontent: Arc<Map>,
|
||||
roomid_lasttimelinecount: Arc<Map>,
|
||||
roomts_pduid: Arc<Map>,
|
||||
userroomid_highlightcount: Arc<Map>,
|
||||
userroomid_notificationcount: Arc<Map>,
|
||||
pub(super) db: Arc<Database>,
|
||||
@@ -52,6 +55,7 @@ impl Data {
|
||||
pduid_pdu: db["pduid_pdu"].clone(),
|
||||
pduid_unredactedcontent: db["pduid_unredactedcontent"].clone(),
|
||||
roomid_lasttimelinecount: db["roomid_lasttimelinecount"].clone(),
|
||||
roomts_pduid: db["roomts_pduid"].clone(),
|
||||
userroomid_highlightcount: db["userroomid_highlightcount"].clone(),
|
||||
userroomid_notificationcount: db["userroomid_notificationcount"].clone(),
|
||||
db: args.db.clone(),
|
||||
@@ -213,10 +217,12 @@ impl Data {
|
||||
room_id: &RoomId,
|
||||
json: &CanonicalJsonObject,
|
||||
count: PduCount,
|
||||
index_ts: MilliSecondsSinceUnixEpoch,
|
||||
) {
|
||||
debug_assert!(matches!(count, PduCount::Normal(_)), "PduCount not Normal");
|
||||
|
||||
self.pduid_pdu.raw_put(pdu_id, Json(json));
|
||||
self.roomts_pduid.insert(&roomts_key(pdu_id, index_ts), []);
|
||||
self.eventid_pduid.insert(pdu.event_id.as_bytes(), pdu_id);
|
||||
self.eventid_outlierpdu.remove(pdu.event_id.as_bytes());
|
||||
self.roomid_lasttimelinecount
|
||||
@@ -228,8 +234,10 @@ impl Data {
|
||||
pdu_id: &RawPduId,
|
||||
event_id: &EventId,
|
||||
json: &CanonicalJsonObject,
|
||||
index_ts: MilliSecondsSinceUnixEpoch,
|
||||
) {
|
||||
self.pduid_pdu.raw_put(pdu_id, Json(json));
|
||||
self.roomts_pduid.insert(&roomts_key(pdu_id, index_ts), []);
|
||||
self.eventid_pduid.insert(event_id, pdu_id);
|
||||
self.eventid_outlierpdu.remove(event_id);
|
||||
}
|
||||
@@ -322,6 +330,49 @@ impl Data {
|
||||
.try_flatten_stream()
|
||||
}
|
||||
|
||||
pub(super) fn pdus_by_timestamp<'a>(
|
||||
&'a self,
|
||||
room_id: &'a RoomId,
|
||||
timestamp: MilliSecondsSinceUnixEpoch,
|
||||
dir: Direction,
|
||||
) -> impl Stream<Item = Result<PdusIterItem>> + Send + 'a {
|
||||
self.services
|
||||
.short
|
||||
.get_shortroomid(room_id)
|
||||
.map_err(move |e| err!(Request(NotFound("Room {room_id:?} not found: {e:?}"))))
|
||||
.map_ok(move |shortroomid| {
|
||||
let seek = |shorteventid| {
|
||||
roomts_key(&PduId { shortroomid, shorteventid }.into(), timestamp)
|
||||
};
|
||||
let keys = match dir {
|
||||
| Direction::Forward => self
|
||||
.roomts_pduid
|
||||
.raw_keys_from(&seek(PduCount::min()))
|
||||
.left_stream(),
|
||||
| Direction::Backward => self
|
||||
.roomts_pduid
|
||||
.rev_raw_keys_from(&seek(PduCount::max()))
|
||||
.right_stream(),
|
||||
};
|
||||
|
||||
keys.ready_try_take_while(move |key| {
|
||||
Ok(key.starts_with(&shortroomid.to_be_bytes()))
|
||||
})
|
||||
.map_ok(roomts_key_to_pdu_id)
|
||||
.and_then(async move |pdu_id| {
|
||||
Ok((pdu_id.pdu_count(), self.get_pdu_from_id(&pdu_id).await?))
|
||||
})
|
||||
})
|
||||
.try_flatten_stream()
|
||||
}
|
||||
|
||||
pub(super) async fn timestamp_index_ready(&self) -> bool {
|
||||
self.db["global"]
|
||||
.exists(TIMESTAMP_INDEX_MIGRATION)
|
||||
.await
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
fn from_json_slice((pdu_id, pdu): KeyVal<'_>) -> Result<PdusIterItem> {
|
||||
let pdu_id: RawPduId = pdu_id.into();
|
||||
|
||||
@@ -376,9 +427,52 @@ impl Data {
|
||||
}
|
||||
}
|
||||
|
||||
pub const TIMESTAMP_INDEX_MIGRATION: &str = "populate_roomts_pduid";
|
||||
|
||||
#[must_use]
|
||||
pub fn roomts_key(pdu_id: &RawPduId, ts: MilliSecondsSinceUnixEpoch) -> Vec<u8> {
|
||||
let count = pdu_id.pdu_count().into_signed().cast_unsigned() ^ (1 << 63);
|
||||
[pdu_id.shortroomid(), u64::from(ts.get()).to_be_bytes(), count.to_be_bytes()].concat()
|
||||
}
|
||||
|
||||
fn roomts_key_to_pdu_id(key: &[u8]) -> RawPduId {
|
||||
let shortroomid = u64::from_be_bytes(key[0..8].try_into().expect("roomts key shortroomid"));
|
||||
let count = u64::from_be_bytes(key[16..24].try_into().expect("roomts key count")) ^ (1 << 63);
|
||||
|
||||
PduId {
|
||||
shortroomid,
|
||||
shorteventid: PduCount::from_signed(count.cast_signed()),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
//TODO: this is an ABA
|
||||
fn increment(db: &Arc<Map>, key: &[u8]) {
|
||||
let old = db.get_blocking(key);
|
||||
let new = utils::increment(old.ok().as_deref());
|
||||
db.insert(key, new);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ruma::uint;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn roomts_key_orders_by_ts_then_count() {
|
||||
let ids = [
|
||||
(PduCount::Normal(9), uint!(1)),
|
||||
(PduCount::Backfilled(-5), uint!(2)),
|
||||
(PduCount::Normal(3), uint!(2)),
|
||||
(PduCount::Normal(1), uint!(3)),
|
||||
]
|
||||
.map(|(count, ts)| (RawPduId::from(PduId { shortroomid: 7, shorteventid: count }), ts));
|
||||
let keys = ids.map(|(id, ts)| roomts_key(&id, MilliSecondsSinceUnixEpoch(ts)));
|
||||
|
||||
assert!(keys.is_sorted());
|
||||
for ((id, _), key) in ids.iter().zip(&keys) {
|
||||
assert_eq!(roomts_key_to_pdu_id(key), *id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,8 @@ use conduwuit_core::{
|
||||
};
|
||||
use futures::{Future, Stream, TryStreamExt, pin_mut};
|
||||
use ruma::{
|
||||
CanonicalJsonObject, EventId, OwnedEventId, OwnedRoomId, RoomId,
|
||||
events::room::encrypted::Relation,
|
||||
CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, RoomId,
|
||||
api::Direction, events::room::encrypted::Relation,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
@@ -32,7 +32,10 @@ use tokio::{
|
||||
};
|
||||
|
||||
use self::data::Data;
|
||||
pub use self::{create::pdu_fits, data::PdusIterItem};
|
||||
pub use self::{
|
||||
create::pdu_fits,
|
||||
data::{PdusIterItem, TIMESTAMP_INDEX_MIGRATION, roomts_key},
|
||||
};
|
||||
use crate::{
|
||||
Dep, account_data, admin, appservice, config, globals, pusher, rooms, sending, server_keys,
|
||||
sync, users,
|
||||
@@ -307,6 +310,17 @@ impl Service {
|
||||
self.pdus(room_id, None).ignore_err()
|
||||
}
|
||||
|
||||
pub fn pdus_by_timestamp<'a>(
|
||||
&'a self,
|
||||
room_id: &'a RoomId,
|
||||
timestamp: MilliSecondsSinceUnixEpoch,
|
||||
dir: Direction,
|
||||
) -> impl Stream<Item = Result<PdusIterItem>> + Send + 'a {
|
||||
self.db.pdus_by_timestamp(room_id, timestamp, dir)
|
||||
}
|
||||
|
||||
pub async fn timestamp_index_ready(&self) -> bool { self.db.timestamp_index_ready().await }
|
||||
|
||||
/// Reverse iteration starting after `until`.
|
||||
#[tracing::instrument(skip(self), level = "debug")]
|
||||
pub fn pdus_rev<'a>(
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::{fmt::Debug, sync::Arc};
|
||||
use conduwuit::{
|
||||
Error, Result, at, utils,
|
||||
utils::{ReadyExt, stream::TryIgnore},
|
||||
warn,
|
||||
};
|
||||
use database::{Database, Deserialized, Map};
|
||||
use futures::{Stream, StreamExt};
|
||||
@@ -169,6 +170,33 @@ impl Data {
|
||||
})
|
||||
}
|
||||
|
||||
/// The oldest queued request of each destination, not yet in flight.
|
||||
pub(super) async fn queued_heads(&self) -> Vec<(Destination, QueueItem)> {
|
||||
let mut heads: Vec<(Destination, QueueItem)> = Vec::new();
|
||||
self.servernameevent_data
|
||||
.raw_stream()
|
||||
.ignore_err()
|
||||
.ready_for_each(|(key, val)| match parse_servercurrentevent(key, val) {
|
||||
| Ok((dest, event)) =>
|
||||
if heads.last().is_none_or(|(last, _)| *last != dest) {
|
||||
heads.push((dest, (key.to_vec(), event)));
|
||||
},
|
||||
| Err(e) => warn!(?key, "invalid queued request key: {e}"),
|
||||
})
|
||||
.await;
|
||||
|
||||
heads
|
||||
}
|
||||
|
||||
/// Estimated number of requests waiting to be sent and in flight.
|
||||
pub(crate) fn request_counts(&self) -> [(&'static str, Option<u64>); 2] {
|
||||
[
|
||||
("queued", &self.servernameevent_data),
|
||||
("active", &self.servercurrentevent_data),
|
||||
]
|
||||
.map(|(state, map)| (state, map.property_integer(c"rocksdb.estimate-num-keys").ok()))
|
||||
}
|
||||
|
||||
pub(super) fn set_latest_educount(&self, server_name: &ServerName, last_count: u64) {
|
||||
self.servername_educount.raw_put(server_name, last_count);
|
||||
}
|
||||
|
||||
+106
-24
@@ -3,12 +3,19 @@ mod appservice;
|
||||
mod data;
|
||||
mod dest;
|
||||
mod sender;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::Debug,
|
||||
hash::{DefaultHasher, Hash, Hasher},
|
||||
iter::once,
|
||||
sync::Arc,
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
@@ -19,7 +26,7 @@ use conduwuit::{
|
||||
utils::{ReadyExt, TryReadyExt, available_parallelism, math::usize_from_u64_truncated},
|
||||
warn,
|
||||
};
|
||||
use futures::{FutureExt, Stream, StreamExt};
|
||||
use futures::{FutureExt, Stream, StreamExt, stream::FuturesUnordered};
|
||||
use ruma::{
|
||||
OwnedServerName, RoomId, ServerName, UserId,
|
||||
api::{
|
||||
@@ -27,7 +34,7 @@ use ruma::{
|
||||
federation::authentication::ServerSignatures, path_builder::PathBuilder,
|
||||
},
|
||||
};
|
||||
use tokio::{task, task::JoinSet};
|
||||
use tokio::{task, task::JoinSet, time::sleep};
|
||||
|
||||
use self::data::Data;
|
||||
pub use self::{
|
||||
@@ -49,6 +56,7 @@ pub struct Service {
|
||||
server: Arc<Server>,
|
||||
services: Services,
|
||||
channels: Vec<(loole::Sender<Msg>, loole::Receiver<Msg>)>,
|
||||
workers_alive: AtomicUsize,
|
||||
}
|
||||
|
||||
struct Services {
|
||||
@@ -87,6 +95,8 @@ pub type EduVec = SmallVec<[EduBuf; EDU_VEC_CAP]>;
|
||||
|
||||
const EDU_BUF_CAP: usize = 128;
|
||||
const EDU_VEC_CAP: usize = 1;
|
||||
const WORKER_RESTART_DELAY: Duration = Duration::from_millis(2500);
|
||||
const WORKER_RESTART_DELAY_MAX: Duration = Duration::from_secs(30);
|
||||
|
||||
#[async_trait]
|
||||
impl crate::Service for Service {
|
||||
@@ -111,36 +121,67 @@ impl crate::Service for Service {
|
||||
federation: args.depend::<federation::Service>("federation"),
|
||||
},
|
||||
channels: (0..num_senders).map(|_| loole::unbounded()).collect(),
|
||||
workers_alive: AtomicUsize::new(0),
|
||||
}))
|
||||
}
|
||||
|
||||
async fn worker(self: Arc<Self>) -> Result {
|
||||
let mut senders =
|
||||
self.channels
|
||||
.iter()
|
||||
.enumerate()
|
||||
.fold(JoinSet::new(), |mut joinset, (id, _)| {
|
||||
let self_ = self.clone();
|
||||
let worker = self_.sender(id);
|
||||
let worker = if self.unconstrained() {
|
||||
task::unconstrained(worker).boxed()
|
||||
} else {
|
||||
worker.boxed()
|
||||
if self.server.config.startup_netburst {
|
||||
self.dispatch_queued(None).await;
|
||||
}
|
||||
|
||||
let num_senders = self.channels.len();
|
||||
let mut senders = JoinSet::new();
|
||||
let mut shards = HashMap::new();
|
||||
let mut started = vec![Instant::now(); num_senders];
|
||||
let mut failures = vec![0_u32; num_senders];
|
||||
let mut restarts = FuturesUnordered::new();
|
||||
for id in 0..num_senders {
|
||||
self.spawn_sender(&mut senders, &mut shards, id, false);
|
||||
}
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
Some(ret) = senders.join_next_with_id() => {
|
||||
self.workers_alive.fetch_sub(1, Ordering::Relaxed);
|
||||
let (task_id, panicked) = match &ret {
|
||||
| Ok((task_id, _)) => (*task_id, false),
|
||||
| Err(error) => (error.id(), error.is_panic()),
|
||||
};
|
||||
let shard = shards.remove(&task_id).expect("sender worker has a shard");
|
||||
|
||||
let runtime = self.server.runtime();
|
||||
let _abort = joinset.spawn_on(worker, runtime);
|
||||
joinset
|
||||
});
|
||||
if panicked {
|
||||
self.server
|
||||
.metrics
|
||||
.instruments
|
||||
.sender_panics
|
||||
.add(1, &[KeyValue::new("scope", "worker")]);
|
||||
}
|
||||
|
||||
while let Some(ret) = senders.join_next_with_id().await {
|
||||
match ret {
|
||||
| Ok((id, error)) => {
|
||||
debug!(?id, ?error, "sender worker finished");
|
||||
if self.channels[shard].1.is_closed() || !self.server.running() {
|
||||
debug!(shard, ?ret, "sender worker finished");
|
||||
continue;
|
||||
}
|
||||
|
||||
// A worker that ran a while before failing starts over from
|
||||
// the shortest delay.
|
||||
failures[shard] = if started[shard].elapsed() > WORKER_RESTART_DELAY_MAX {
|
||||
1
|
||||
} else {
|
||||
failures[shard].saturating_add(1)
|
||||
};
|
||||
let delay = restart_delay(failures[shard]);
|
||||
error!(shard, ?ret, ?delay, "sender worker unexpectedly finished, restarting");
|
||||
restarts.push(sleep(delay).map(move |()| shard));
|
||||
},
|
||||
| Err(error) => {
|
||||
error!(id = ?error.id(), ?error, "sender worker failed");
|
||||
Some(shard) = restarts.next() => {
|
||||
if !self.channels[shard].1.is_closed() {
|
||||
started[shard] = Instant::now();
|
||||
self.spawn_sender(&mut senders, &mut shards, shard, true);
|
||||
}
|
||||
},
|
||||
() = self.server.until_shutdown(), if !restarts.is_empty() => restarts.clear(),
|
||||
else => break,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +202,25 @@ impl crate::Service for Service {
|
||||
}
|
||||
|
||||
impl Service {
|
||||
fn spawn_sender(
|
||||
self: &Arc<Self>,
|
||||
senders: &mut JoinSet<Result>,
|
||||
shards: &mut HashMap<task::Id, usize>,
|
||||
id: usize,
|
||||
restarted: bool,
|
||||
) {
|
||||
let worker = self.clone().sender(id, restarted);
|
||||
let worker = if crate::Service::unconstrained(&**self) {
|
||||
task::unconstrained(worker).boxed()
|
||||
} else {
|
||||
worker.boxed()
|
||||
};
|
||||
|
||||
let handle = senders.spawn_on(worker, self.server.runtime());
|
||||
shards.insert(handle.id(), id);
|
||||
self.workers_alive.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, pdu_id, user, pushkey), level = "debug")]
|
||||
pub fn send_pdu_push(&self, pdu_id: &RawPduId, user: &UserId, pushkey: String) -> Result {
|
||||
let dest = Destination::Push(user.to_owned(), pushkey);
|
||||
@@ -480,10 +540,24 @@ impl Service {
|
||||
sender.send(msg).map_err(|e| err!("{e}"))
|
||||
}
|
||||
|
||||
/// Hands the oldest unsent request of each destination to its worker, so
|
||||
/// a backlog with nothing in flight is sent without waiting for a new
|
||||
/// event. Bypasses `dispatch` as these requests were already counted.
|
||||
async fn dispatch_queued(&self, shard: Option<usize>) {
|
||||
for (dest, (queue_id, event)) in self.db.queued_heads().await {
|
||||
let id = self.shard_id(&dest);
|
||||
if shard.is_none_or(|shard| shard == id) {
|
||||
self.channels[id].0.send(Msg { dest, event, queue_id }).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn queue_depth(&self) -> usize {
|
||||
self.channels.iter().map(|(sender, _)| sender.len()).sum()
|
||||
}
|
||||
|
||||
pub fn workers_alive(&self) -> usize { self.workers_alive.load(Ordering::Relaxed) }
|
||||
|
||||
pub(super) fn shard_id(&self, dest: &Destination) -> usize {
|
||||
if self.channels.len() <= 1 {
|
||||
return 0;
|
||||
@@ -519,3 +593,11 @@ fn num_senders(args: &crate::Args<'_>) -> usize {
|
||||
worker_count.clamp(MIN_SENDERS, max_senders)
|
||||
}
|
||||
}
|
||||
|
||||
/// Delay before restarting a worker after its `failures`-th consecutive
|
||||
/// failure, doubling each time.
|
||||
fn restart_delay(failures: u32) -> Duration {
|
||||
WORKER_RESTART_DELAY
|
||||
.saturating_mul(2_u32.saturating_pow(failures.saturating_sub(1)))
|
||||
.min(WORKER_RESTART_DELAY_MAX)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
fmt::Debug,
|
||||
panic::AssertUnwindSafe,
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicU64, AtomicUsize, Ordering},
|
||||
@@ -55,6 +56,9 @@ use serde_json::value::{RawValue as RawJsonValue, to_raw_value};
|
||||
|
||||
use super::{Destination, EduBuf, EduVec, Msg, SendingEvent, Service, data::QueueItem};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum TransactionStatus {
|
||||
Running,
|
||||
@@ -78,12 +82,18 @@ pub const EDU_LIMIT: usize = 100;
|
||||
|
||||
impl Service {
|
||||
#[tracing::instrument(skip(self), level = "debug")]
|
||||
pub(super) async fn sender(self: Arc<Self>, id: usize) -> Result {
|
||||
pub(super) async fn sender(self: Arc<Self>, id: usize, restarted: bool) -> Result {
|
||||
let mut statuses: CurTransactionStatus = CurTransactionStatus::new();
|
||||
let mut futures: SendingFutures<'_> = FuturesUnordered::new();
|
||||
|
||||
// The previous worker of this shard may have dropped requests it had
|
||||
// taken from the channel.
|
||||
if restarted {
|
||||
self.dispatch_queued(Some(id)).await;
|
||||
}
|
||||
|
||||
info!(shard = id, "Running startup netburst");
|
||||
self.startup_netburst(id, &mut futures, &mut statuses)
|
||||
self.startup_netburst(id, restarted, &mut futures, &mut statuses)
|
||||
.boxed()
|
||||
.await;
|
||||
info!(shard = id, "Finished startup netburst");
|
||||
@@ -142,6 +152,9 @@ impl Service {
|
||||
) {
|
||||
match response {
|
||||
| Ok(dest) => self.handle_response_ok(&dest, futures, statuses).await,
|
||||
// A bug on our side, not the remote's fault: retry with backoff
|
||||
// without marking the remote unhealthy.
|
||||
| Err((dest, e)) if e.is_panic() => Self::handle_response_err(dest, statuses, &e),
|
||||
| Err((dest, e)) => {
|
||||
if let Destination::Federation(dest) = &dest {
|
||||
if self.services.federation.should_mark_stale(&e)
|
||||
@@ -274,7 +287,8 @@ impl Service {
|
||||
}
|
||||
|
||||
/// Performs startup netburst, which sends any previously queued up but not
|
||||
/// yet sent requests immediately.
|
||||
/// yet sent requests immediately. A restarted worker always resends its
|
||||
/// shard's requests in flight.
|
||||
#[tracing::instrument(
|
||||
name = "netburst",
|
||||
level = "debug",
|
||||
@@ -285,6 +299,7 @@ impl Service {
|
||||
async fn startup_netburst<'a>(
|
||||
&'a self,
|
||||
id: usize,
|
||||
restarted: bool,
|
||||
futures: &mut SendingFutures<'a>,
|
||||
statuses: &mut CurTransactionStatus,
|
||||
) {
|
||||
@@ -315,8 +330,12 @@ impl Service {
|
||||
}
|
||||
}
|
||||
|
||||
if !restarted && !self.server.config.startup_netburst {
|
||||
return;
|
||||
}
|
||||
|
||||
for (dest, events) in txns {
|
||||
if self.server.config.startup_netburst && !events.is_empty() {
|
||||
if !events.is_empty() {
|
||||
statuses.insert(dest.clone(), TransactionStatus::Running);
|
||||
futures.push(self.send_events(dest, events));
|
||||
}
|
||||
@@ -772,6 +791,7 @@ impl Service {
|
||||
});
|
||||
|
||||
let start = Instant::now();
|
||||
let panic_dest = dest.clone();
|
||||
let send = match dest {
|
||||
| Destination::Federation(server) =>
|
||||
self.send_events_dest_federation(server, events).boxed(),
|
||||
@@ -780,24 +800,42 @@ impl Service {
|
||||
self.send_events_dest_push(user_id, pushkey, events).boxed(),
|
||||
};
|
||||
|
||||
send.inspect(move |result| {
|
||||
let instruments = &self.server.metrics.instruments;
|
||||
let outcome =
|
||||
KeyValue::new("outcome", if result.is_ok() { "success" } else { "failure" });
|
||||
instruments
|
||||
.sender_transaction_duration
|
||||
.record(start.elapsed().as_secs_f64(), &[destination.clone(), outcome.clone()]);
|
||||
for (kind, count) in [("pdu", pdus), ("edu", edus)] {
|
||||
if count > 0 {
|
||||
instruments.sender_events.add(count, &[
|
||||
AssertUnwindSafe(send)
|
||||
.catch_unwind()
|
||||
.map(move |result| {
|
||||
result.unwrap_or_else(|panic| {
|
||||
let error = Error::from_panic(panic);
|
||||
error!(dest = ?panic_dest, ?error, "Panicked while sending transaction");
|
||||
self.server
|
||||
.metrics
|
||||
.instruments
|
||||
.sender_panics
|
||||
.add(1, &[KeyValue::new("scope", "transaction")]);
|
||||
|
||||
Err((panic_dest, Box::new(error)))
|
||||
})
|
||||
})
|
||||
.inspect(move |result| {
|
||||
let instruments = &self.server.metrics.instruments;
|
||||
let outcome =
|
||||
KeyValue::new("outcome", if result.is_ok() { "success" } else { "failure" });
|
||||
instruments
|
||||
.sender_transaction_duration
|
||||
.record(start.elapsed().as_secs_f64(), &[
|
||||
destination.clone(),
|
||||
KeyValue::new("kind", kind),
|
||||
outcome.clone(),
|
||||
]);
|
||||
for (kind, count) in [("pdu", pdus), ("edu", edus)] {
|
||||
if count > 0 {
|
||||
instruments.sender_events.add(count, &[
|
||||
destination.clone(),
|
||||
KeyValue::new("kind", kind),
|
||||
outcome.clone(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.boxed()
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
|
||||
#[tracing::instrument(
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
use std::iter::once;
|
||||
|
||||
use conduwuit::Error;
|
||||
use futures::{StreamExt, stream::FuturesUnordered};
|
||||
use ruma::server_name;
|
||||
use serde_json::json;
|
||||
|
||||
use super::{CurTransactionStatus, TransactionStatus};
|
||||
use crate::{
|
||||
sending::{Destination, EduBuf, SendingEvent},
|
||||
test_utils::{test_services, test_services_with},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn panicked_transaction_is_kept_for_retry_without_blaming_the_remote() {
|
||||
let (services, path, _database) = test_services().await;
|
||||
let sending = &services.sending;
|
||||
let server = server_name!("remote.example");
|
||||
let dest = Destination::Federation(server.to_owned());
|
||||
let event = SendingEvent::Edu(EduBuf::from_slice(br#"{"edu_type":"m.typing"}"#));
|
||||
|
||||
sending.db.queue_requests(once((&event, &dest)));
|
||||
let in_flight: Vec<_> = sending.db.queued_requests(&dest).collect().await;
|
||||
sending.db.mark_as_active(in_flight.iter());
|
||||
|
||||
let mut futures = FuturesUnordered::new();
|
||||
let mut statuses = CurTransactionStatus::from([(dest.clone(), TransactionStatus::Running)]);
|
||||
let panic = Error::from_panic(Box::new("boom"));
|
||||
sending
|
||||
.handle_response(Err((dest.clone(), Box::new(panic))), &mut futures, &mut statuses)
|
||||
.await;
|
||||
|
||||
let active: Vec<_> = sending
|
||||
.db
|
||||
.active_requests_for(&dest)
|
||||
.map(|(key, _)| key)
|
||||
.collect()
|
||||
.await;
|
||||
let retry_after = sending.services.federation.retry_after(server);
|
||||
let sending_next = futures.len();
|
||||
let failed = matches!(statuses.get(&dest), Some(TransactionStatus::Failed(1, _)));
|
||||
|
||||
drop(futures);
|
||||
drop(services);
|
||||
std::fs::remove_dir_all(path).unwrap();
|
||||
assert_eq!(
|
||||
active,
|
||||
in_flight
|
||||
.into_iter()
|
||||
.map(|(key, _)| key)
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
assert_eq!(sending_next, 0);
|
||||
assert!(failed);
|
||||
assert_eq!(retry_after, None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn restarted_worker_resends_trimmed_in_flight_requests() {
|
||||
let (services, path, _database) =
|
||||
test_services_with(json!({ "startup_netburst_keep": 1 })).await;
|
||||
let sending = &services.sending;
|
||||
let dest = Destination::Federation(server_name!("remote.example").to_owned());
|
||||
let event = SendingEvent::Edu(EduBuf::from_slice(br#"{"edu_type":"m.typing"}"#));
|
||||
|
||||
for _ in 0..3 {
|
||||
sending.db.queue_requests(once((&event, &dest)));
|
||||
}
|
||||
let queued: Vec<_> = sending.db.queued_requests(&dest).collect().await;
|
||||
sending.db.mark_as_active(queued.iter());
|
||||
|
||||
let id = sending.shard_id(&dest);
|
||||
let mut futures = FuturesUnordered::new();
|
||||
let mut statuses = CurTransactionStatus::new();
|
||||
sending
|
||||
.startup_netburst(id, true, &mut futures, &mut statuses)
|
||||
.await;
|
||||
let active = sending.db.active_requests_for(&dest).count().await;
|
||||
let sending_now = futures.len();
|
||||
|
||||
drop(futures);
|
||||
drop(services);
|
||||
std::fs::remove_dir_all(path).unwrap();
|
||||
assert_eq!(active, 1);
|
||||
assert_eq!(sending_now, 1);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
use std::{iter::once, time::Duration};
|
||||
|
||||
use futures::StreamExt;
|
||||
use ruma::server_name;
|
||||
|
||||
use super::{Destination, EduBuf, SendingEvent, restart_delay};
|
||||
use crate::test_utils::test_services;
|
||||
|
||||
#[tokio::test]
|
||||
async fn queued_heads_lists_the_oldest_unsent_request_per_destination() {
|
||||
let (services, path, _database) = test_services().await;
|
||||
let db = &services.sending.db;
|
||||
let queued = Destination::Federation(server_name!("queued.example").to_owned());
|
||||
let active = Destination::Federation(server_name!("active.example").to_owned());
|
||||
let event = SendingEvent::Edu(EduBuf::from_slice(br#"{"edu_type":"m.typing"}"#));
|
||||
|
||||
let first = db.queue_requests(once((&event, &queued)));
|
||||
db.queue_requests(once((&event, &queued)));
|
||||
db.queue_requests(once((&event, &active)));
|
||||
let in_flight: Vec<_> = db.queued_requests(&active).collect().await;
|
||||
db.mark_as_active(in_flight.iter());
|
||||
|
||||
let heads: Vec<_> = db
|
||||
.queued_heads()
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|(dest, (key, _))| (dest, key))
|
||||
.collect();
|
||||
|
||||
drop(services);
|
||||
std::fs::remove_dir_all(path).unwrap();
|
||||
assert_eq!(heads, [(queued, first[0].clone())]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restart_delay_doubles_up_to_the_cap() {
|
||||
assert_eq!(restart_delay(1), Duration::from_millis(2500));
|
||||
assert_eq!(restart_delay(2), Duration::from_secs(5));
|
||||
assert_eq!(restart_delay(4), Duration::from_secs(20));
|
||||
assert_eq!(restart_delay(5), Duration::from_secs(30));
|
||||
assert_eq!(restart_delay(u32::MAX), Duration::from_secs(30));
|
||||
}
|
||||
@@ -241,9 +241,9 @@ impl super::Service {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
trace!(?origin_response.raw, "Got signing key response from origin");
|
||||
trace!(?origin_response, "Got signing key response from origin");
|
||||
self.add_signing_keys(&origin_response);
|
||||
Self::track_result(&mut result, &mut still_missing, &origin_response.parsed);
|
||||
Self::track_result(&mut result, &mut still_missing, &origin_response);
|
||||
if still_missing.is_empty() {
|
||||
break;
|
||||
}
|
||||
@@ -262,9 +262,9 @@ impl super::Service {
|
||||
"Got signing keys response from a notary"
|
||||
);
|
||||
for server_keys in notary_response {
|
||||
trace!(?server_keys.raw, "Adding response from notary");
|
||||
trace!(?server_keys, "Adding response from notary");
|
||||
self.add_signing_keys(&server_keys);
|
||||
Self::track_result(&mut result, &mut still_missing, &server_keys.parsed);
|
||||
Self::track_result(&mut result, &mut still_missing, &server_keys);
|
||||
if still_missing.is_empty() {
|
||||
break;
|
||||
}
|
||||
@@ -285,9 +285,9 @@ impl super::Service {
|
||||
continue;
|
||||
};
|
||||
for server_keys in res {
|
||||
trace!(?server_keys.raw, "Adding response from notary");
|
||||
trace!(?server_keys, "Adding response from notary");
|
||||
self.add_signing_keys(&server_keys);
|
||||
Self::track_result(&mut result, &mut still_missing, &server_keys.parsed);
|
||||
Self::track_result(&mut result, &mut still_missing, &server_keys);
|
||||
}
|
||||
if still_missing.is_empty() {
|
||||
break;
|
||||
@@ -300,9 +300,9 @@ impl super::Service {
|
||||
debug_warn!(err=?res.err(), "Got error response from origin");
|
||||
continue;
|
||||
};
|
||||
trace!(response=?res.raw, "Got signing key response from origin");
|
||||
trace!(response=?res, "Got signing key response from origin");
|
||||
self.add_signing_keys(&res);
|
||||
Self::track_result(&mut result, &mut still_missing, &res.parsed);
|
||||
Self::track_result(&mut result, &mut still_missing, &res);
|
||||
if still_missing.is_empty() {
|
||||
break;
|
||||
}
|
||||
@@ -400,7 +400,7 @@ impl super::Service {
|
||||
.inspect_err(|e| info!("Could not acquire signing key from origin server: {e:?}"))
|
||||
.ok()?;
|
||||
|
||||
verify_key_from_response(key_id, &response.parsed, min_valid_ts)
|
||||
verify_key_from_response(key_id, &response, min_valid_ts)
|
||||
.inspect(|_| self.add_signing_keys(&response))
|
||||
}
|
||||
}
|
||||
|
||||
+117
-18
@@ -5,32 +5,42 @@ mod sign;
|
||||
mod util;
|
||||
mod verify;
|
||||
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use assign::assign;
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{
|
||||
Result, Server,
|
||||
utils::{IterStream, ReadyExt, stream::TryIgnore},
|
||||
Result, Server, SyncRwLock,
|
||||
utils::{IterStream, ReadyExt, stream::TryIgnore, timepoint_from_now, to_canonical_object},
|
||||
};
|
||||
use database::{Deserialized, Ignore, Interfix, Json, Map};
|
||||
use futures::{Stream, StreamExt};
|
||||
pub use request::in_one_week;
|
||||
use ruma::{
|
||||
CanonicalJsonObject, MilliSecondsSinceUnixEpoch, OwnedServerSigningKeyId, ServerName,
|
||||
ServerSigningKeyId,
|
||||
api::federation::discovery::{ServerSigningKeys, VerifyKey},
|
||||
CanonicalJsonObject, MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedServerSigningKeyId,
|
||||
ServerName, ServerSigningKeyId,
|
||||
api::federation::discovery::{OldVerifyKey, ServerSigningKeys, VerifyKey},
|
||||
room_version_rules::RoomVersionRules,
|
||||
serde::Raw,
|
||||
signatures::{Ed25519KeyPair, PublicKeyMap, PublicKeySet},
|
||||
};
|
||||
use verify::IncomingServerKeys;
|
||||
use serde_json::value::to_raw_value;
|
||||
pub use verify::strip_extraneous_signatures;
|
||||
|
||||
use crate::{Dep, globals, sending, server_keys::util::required_keys};
|
||||
|
||||
const VALID_UNTIL_TS_DURATION: Duration = Duration::from_hours(12);
|
||||
|
||||
pub struct Service {
|
||||
keypair: Box<Ed25519KeyPair>,
|
||||
verify_keys: VerifyKeys,
|
||||
services: Services,
|
||||
db: Data,
|
||||
last_lookup: SyncRwLock<HashMap<OwnedServerName, Instant>>,
|
||||
}
|
||||
|
||||
struct Services {
|
||||
@@ -47,6 +57,7 @@ pub type VerifyKeys = BTreeMap<OwnedServerSigningKeyId, VerifyKey>;
|
||||
pub type PubKeyMap = PublicKeyMap;
|
||||
pub type PubKeys = PublicKeySet;
|
||||
|
||||
#[async_trait]
|
||||
impl crate::Service for Service {
|
||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
let (keypair, verify_keys) = keypair::init(args.db)?;
|
||||
@@ -63,9 +74,12 @@ impl crate::Service for Service {
|
||||
db: Data {
|
||||
servernamekeyid_response: args.db["servernamekeyid_response"].clone(),
|
||||
},
|
||||
last_lookup: SyncRwLock::new(HashMap::new()),
|
||||
}))
|
||||
}
|
||||
|
||||
async fn clear_cache(&self) { self.last_lookup.write().clear(); }
|
||||
|
||||
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
|
||||
}
|
||||
|
||||
@@ -85,22 +99,19 @@ impl Service {
|
||||
}
|
||||
|
||||
/// Adds a signing key response to the database.
|
||||
fn add_signing_keys(&self, new_keys: &IncomingServerKeys) {
|
||||
fn add_signing_keys(&self, new_keys: &ServerSigningKeys) {
|
||||
// TODO(nex): this results in massive amounts of data duplication.
|
||||
// Perhaps a sliding approach would be better? where we just update the
|
||||
// last known response if the only thing that changed was the
|
||||
// valid_until_ts. This would require a more complex data structure
|
||||
// though. For now, just storing the duplicated data is fine.
|
||||
for key in new_keys
|
||||
.parsed
|
||||
.verify_keys
|
||||
.keys()
|
||||
.chain(new_keys.parsed.old_verify_keys.keys())
|
||||
.chain(new_keys.old_verify_keys.keys())
|
||||
{
|
||||
let db_key = (new_keys.parsed.server_name.as_str(), key.as_str());
|
||||
self.db
|
||||
.servernamekeyid_response
|
||||
.put(db_key, Json(&new_keys.raw));
|
||||
let db_key = (new_keys.server_name.as_str(), key.as_str());
|
||||
self.db.servernamekeyid_response.put(db_key, Json(new_keys));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +186,7 @@ impl Service {
|
||||
let mut keys = self
|
||||
.signing_keys_for(origin)
|
||||
.ready_fold(BTreeMap::new(), |mut base, keys| {
|
||||
base.extend(keys.parsed.verify_keys);
|
||||
base.extend(keys.verify_keys);
|
||||
base
|
||||
})
|
||||
.await;
|
||||
@@ -188,15 +199,103 @@ impl Service {
|
||||
}
|
||||
|
||||
/// Returns the stored server signing keys responses for the origin.
|
||||
///
|
||||
/// Does not imply that the stored responses are still in-date.
|
||||
pub fn signing_keys_for<'a>(
|
||||
&'a self,
|
||||
origin: &'a ServerName,
|
||||
) -> impl Stream<Item = IncomingServerKeys> + Send + 'a {
|
||||
) -> impl Stream<Item = ServerSigningKeys> + Send + 'a {
|
||||
self.db
|
||||
.servernamekeyid_response
|
||||
.stream_prefix(&(origin, Interfix))
|
||||
.ignore_err()
|
||||
.map(|(_, v): (Ignore, Raw<ServerSigningKeys>)| v.try_into().map_err(Into::into))
|
||||
.ignore_err()
|
||||
.map(|(_, v): (Ignore, ServerSigningKeys)| v)
|
||||
}
|
||||
|
||||
/// Determines if the server may contact the origin server to fetch keys
|
||||
/// when acting as a notary server. This limits origin lookups to once per
|
||||
/// minute, which prevents amplification attacks.
|
||||
#[must_use]
|
||||
pub fn notary_may_contact_origin(&self, server_name: &ServerName) -> bool {
|
||||
if server_name == self.services.server.name {
|
||||
// We always intercept origin requests to us with
|
||||
// build_server_keys_response, so this is equivalent to
|
||||
// calling `/_matrix/key/v2/server`.
|
||||
return true;
|
||||
}
|
||||
self.last_lookup
|
||||
.read()
|
||||
.get(server_name)
|
||||
.is_none_or(|last| last.elapsed() >= Duration::from_mins(1))
|
||||
}
|
||||
|
||||
/// Generates a signing key response to serve to `/_matrix/key/v2/server`.
|
||||
pub async fn build_server_keys_response(&self) -> Result<Raw<ServerSigningKeys>> {
|
||||
let verify_keys = BTreeMap::from([self.active_verify_key()]);
|
||||
let old_verify_keys = match &self.services.server.config.old_verify_keys {
|
||||
| Some(old_verify_keys) => old_verify_keys.to_owned(),
|
||||
| None => self.discover_old_signing_keys().await,
|
||||
};
|
||||
let valid_until_ts = timepoint_from_now(VALID_UNTIL_TS_DURATION)
|
||||
.map(|tp| {
|
||||
MilliSecondsSinceUnixEpoch::from_system_time(tp)
|
||||
.expect("key validity period must be before the heat death of the universe")
|
||||
})
|
||||
.expect("key validity period must be before the heat death of the universe");
|
||||
let server_keys = assign!(
|
||||
ServerSigningKeys::new(self.services.server.name.clone(), valid_until_ts),
|
||||
{verify_keys, old_verify_keys}
|
||||
);
|
||||
let mut canonical_obj = to_canonical_object(&server_keys)?;
|
||||
self.sign_json(&mut canonical_obj)
|
||||
.and_then(|()| to_raw_value(&canonical_obj).map_err(Into::into))
|
||||
.map(Raw::from_json)
|
||||
}
|
||||
|
||||
async fn discover_old_signing_keys(&self) -> BTreeMap<OwnedServerSigningKeyId, OldVerifyKey> {
|
||||
let now = MilliSecondsSinceUnixEpoch::now();
|
||||
let mut keys = self.signing_keys_for(&self.services.server.name);
|
||||
let mut old_keys = BTreeMap::new();
|
||||
while let Some(resp) = keys.next().await {
|
||||
// We need to verify that this response is still trusted based on
|
||||
// the current configuration. It's possible we got this response
|
||||
// from a notary who we no longer trust.
|
||||
if resp.valid_until_ts > in_one_week() || resp.valid_until_ts < now {
|
||||
continue;
|
||||
}
|
||||
let trusted = self
|
||||
.services
|
||||
.server
|
||||
.config
|
||||
.trusted_servers
|
||||
.iter()
|
||||
.any(|notary| {
|
||||
Self::verify_server_keys_response(
|
||||
&resp,
|
||||
Some((notary.server_name(), notary.verify_keys())),
|
||||
)
|
||||
.is_ok()
|
||||
});
|
||||
if !trusted {
|
||||
continue;
|
||||
}
|
||||
for (old_key_id, old_key) in resp.old_verify_keys {
|
||||
if old_key.expired_ts > resp.valid_until_ts {
|
||||
// This key expired in the future which is probably illegal
|
||||
continue;
|
||||
}
|
||||
old_keys
|
||||
.entry(old_key_id)
|
||||
.and_modify(|current_old_key: &mut OldVerifyKey| {
|
||||
// Use the lowest expiry timestamp
|
||||
if current_old_key.expired_ts < old_key.expired_ts {
|
||||
*current_old_key = old_key.clone();
|
||||
}
|
||||
})
|
||||
.or_insert(old_key);
|
||||
}
|
||||
}
|
||||
|
||||
old_keys
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::{collections::BTreeMap, time::Instant};
|
||||
|
||||
use conduwuit::{Err, Result, trace, utils::millis_since_unix_epoch, warn};
|
||||
use ruma::{
|
||||
MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedServerSigningKeyId, ServerName, UInt,
|
||||
api::federation::discovery::{
|
||||
ServerSigningKeys,
|
||||
get_remote_server_keys_batch::{
|
||||
self,
|
||||
v2::{QueryCriteria, Response as NotaryResponse},
|
||||
@@ -14,8 +15,6 @@ use ruma::{
|
||||
uint,
|
||||
};
|
||||
|
||||
use crate::server_keys::verify::IncomingServerKeys;
|
||||
|
||||
pub(crate) type ServerKeysQuery = BTreeMap<OwnedServerName, ServerKeysQuerySet>;
|
||||
pub(crate) type ServerKeysQuerySet = BTreeMap<OwnedServerSigningKeyId, QueryCriteria>;
|
||||
|
||||
@@ -28,33 +27,49 @@ impl super::Service {
|
||||
&self,
|
||||
target: OwnedServerName,
|
||||
min_valid_ts: MilliSecondsSinceUnixEpoch,
|
||||
) -> Result<IncomingServerKeys> {
|
||||
) -> Result<ServerSigningKeys> {
|
||||
use get_server_keys::v2::Request;
|
||||
|
||||
let raw_server_key = self
|
||||
if target == self.services.server.name {
|
||||
return self
|
||||
.build_server_keys_response()
|
||||
.await
|
||||
.and_then(|r| r.deserialize().map_err(Into::into));
|
||||
}
|
||||
|
||||
// N.B. The "last lookup" is written before the request is actually made
|
||||
// to prevent concurrent notary requests from spawning... concurrent
|
||||
// origin requests, especially if the origin is slow.
|
||||
// This has the downside that, if the origin is temporarily unreachable
|
||||
// (including if we're backing off from it), the notary might take an
|
||||
// additional minute to recover compared to the rest of the server. This
|
||||
// is deemed acceptable.
|
||||
self.last_lookup
|
||||
.write()
|
||||
.insert(target.clone(), Instant::now());
|
||||
let server_signing_key = self
|
||||
.services
|
||||
.sending
|
||||
.send_unauthenticated_request(&target, Request::new())
|
||||
.await
|
||||
.map(|response| response.server_key)?;
|
||||
.map(|response| response.server_key)
|
||||
.and_then(|key| key.deserialize().map_err(Into::into))?;
|
||||
|
||||
let server_signing_key: IncomingServerKeys = raw_server_key.try_into()?;
|
||||
|
||||
if server_signing_key.parsed.server_name != target {
|
||||
if server_signing_key.server_name != target {
|
||||
return Err!(BadServerResponse(debug_warn!(
|
||||
requested = ?target,
|
||||
response = ?server_signing_key.parsed.server_name,
|
||||
response = ?server_signing_key.server_name,
|
||||
"Origin server responded with bogus server_name"
|
||||
)));
|
||||
}
|
||||
|
||||
if server_signing_key.parsed.valid_until_ts < min_valid_ts
|
||||
|| server_signing_key.parsed.valid_until_ts > in_one_week()
|
||||
if server_signing_key.valid_until_ts < min_valid_ts
|
||||
|| server_signing_key.valid_until_ts > in_one_week()
|
||||
{
|
||||
return Err!(BadServerResponse(debug_warn!(
|
||||
?target,
|
||||
?min_valid_ts,
|
||||
?server_signing_key.parsed.valid_until_ts,
|
||||
?server_signing_key.valid_until_ts,
|
||||
"Origin server responded with server keys that are not in-date"
|
||||
)));
|
||||
}
|
||||
@@ -85,7 +100,7 @@ impl super::Service {
|
||||
&self,
|
||||
notary: &ServerName,
|
||||
batch: ServerKeysQuery,
|
||||
) -> Result<Vec<IncomingServerKeys>> {
|
||||
) -> Result<Vec<ServerSigningKeys>> {
|
||||
use get_remote_server_keys_batch::v2::Request;
|
||||
|
||||
let is_empty = batch.is_empty() || batch.values().all(BTreeMap::is_empty);
|
||||
@@ -117,12 +132,12 @@ impl super::Service {
|
||||
}
|
||||
|
||||
/// Parses a notary response, returning a vec of server signing key
|
||||
/// responses, each paired with its raw JSON (which is what the signatures
|
||||
/// were made over). Drops any chunks that cannot be deserialized.
|
||||
fn parse_notary_response(raw: &NotaryResponse) -> Vec<IncomingServerKeys> {
|
||||
/// responses. Drops any chunks that cannot be deserialized.
|
||||
fn parse_notary_response(raw: &NotaryResponse) -> Vec<ServerSigningKeys> {
|
||||
raw.server_keys
|
||||
.iter()
|
||||
.filter_map(|chunk| chunk.try_into().ok())
|
||||
.map(ruma::serde::Raw::deserialize)
|
||||
.filter_map(Result::ok)
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -130,15 +145,12 @@ impl super::Service {
|
||||
/// if the response should be dropped, true if it should be kept.
|
||||
fn validate_notary_chunk(
|
||||
batch: &ServerKeysQuery,
|
||||
incoming: &IncomingServerKeys,
|
||||
keys: &ServerSigningKeys,
|
||||
notary_name: &ServerName,
|
||||
notary_keys: &[Base64],
|
||||
) -> bool {
|
||||
let Some(expected_keys) = batch.get(&incoming.parsed.server_name) else {
|
||||
trace!(
|
||||
"Dropping signing keys chunk for unrequested server: {}",
|
||||
incoming.parsed.server_name
|
||||
);
|
||||
let Some(expected_keys) = batch.get(&keys.server_name) else {
|
||||
trace!("Dropping signing keys chunk for unrequested server: {}", keys.server_name);
|
||||
return false;
|
||||
};
|
||||
let min_valid_ts = expected_keys
|
||||
@@ -152,15 +164,13 @@ impl super::Service {
|
||||
|
||||
// If this notary response is older than any of the min_valid_ts we
|
||||
// requested, then we should drop it.
|
||||
if incoming.parsed.valid_until_ts < min_valid_ts
|
||||
|| incoming.parsed.valid_until_ts > in_one_week()
|
||||
{
|
||||
if keys.valid_until_ts < min_valid_ts || keys.valid_until_ts > in_one_week() {
|
||||
trace!(
|
||||
?min_valid_ts,
|
||||
?incoming.parsed.valid_until_ts,
|
||||
?keys.valid_until_ts,
|
||||
"Dropping signing keys chunk for server {} because it is older than the minimum \
|
||||
valid timestamp we requested",
|
||||
incoming.parsed.server_name
|
||||
keys.server_name
|
||||
);
|
||||
return false;
|
||||
}
|
||||
@@ -168,39 +178,38 @@ impl super::Service {
|
||||
// Does this chunk even contain any keys we asked for?
|
||||
// Note that this enforces min_valid_ts per-key, instead of using the
|
||||
// lowest denominator.
|
||||
let all_key_ids = incoming
|
||||
.parsed
|
||||
let all_key_ids = keys
|
||||
.verify_keys
|
||||
.keys()
|
||||
.chain(incoming.parsed.old_verify_keys.keys())
|
||||
.chain(keys.old_verify_keys.keys())
|
||||
.map(ToOwned::to_owned)
|
||||
.collect::<Vec<_>>();
|
||||
let interesting = expected_keys.iter().any(|(k, q)| {
|
||||
all_key_ids.contains(k)
|
||||
&& q.minimum_valid_until_ts
|
||||
.is_none_or(|m| m <= incoming.parsed.valid_until_ts)
|
||||
.is_none_or(|m| m <= keys.valid_until_ts)
|
||||
});
|
||||
if !interesting {
|
||||
trace!(
|
||||
"Dropping signing keys chunk for server {} because it does not contain any keys \
|
||||
we requested",
|
||||
incoming.parsed.server_name
|
||||
keys.server_name
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
Self::verify_server_keys_response(incoming, Some((notary_name, notary_keys)))
|
||||
Self::verify_server_keys_response(keys, Some((notary_name, notary_keys)))
|
||||
.inspect_err(|e| {
|
||||
trace!(
|
||||
?e,
|
||||
?incoming.raw,
|
||||
?keys,
|
||||
?notary_name,
|
||||
?notary_keys,
|
||||
"Dropping illegal server signing keys response chunk"
|
||||
);
|
||||
warn!(
|
||||
%notary_name,
|
||||
server_name=%incoming.parsed.server_name,
|
||||
server_name=%keys.server_name,
|
||||
"Dropping illegal server signing keys response chunk: {e:?}"
|
||||
);
|
||||
})
|
||||
|
||||
@@ -5,36 +5,11 @@ use ruma::{
|
||||
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, ServerName, SigningKeyAlgorithm,
|
||||
api::federation::discovery::ServerSigningKeys,
|
||||
room_version_rules::RoomVersionRules,
|
||||
serde::{Base64, Raw, base64::Standard},
|
||||
serde::{Base64, base64::Standard},
|
||||
signatures::Verified,
|
||||
};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
pub struct IncomingServerKeys {
|
||||
pub raw: Raw<ServerSigningKeys>,
|
||||
pub parsed: ServerSigningKeys,
|
||||
}
|
||||
|
||||
impl TryFrom<Raw<ServerSigningKeys>> for IncomingServerKeys {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from(value: Raw<ServerSigningKeys>) -> std::result::Result<Self, Self::Error> {
|
||||
value
|
||||
.deserialize()
|
||||
.map(|parsed| Self { raw: value, parsed })
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&Raw<ServerSigningKeys>> for IncomingServerKeys {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from(value: &Raw<ServerSigningKeys>) -> std::result::Result<Self, Self::Error> {
|
||||
value
|
||||
.deserialize()
|
||||
.map(|parsed| Self { raw: value.to_owned(), parsed })
|
||||
}
|
||||
}
|
||||
|
||||
impl super::Service {
|
||||
/// Validates the incoming event only using locally known verification keys.
|
||||
/// Inserts the calculated event ID into the event_id field upon success.
|
||||
@@ -83,38 +58,34 @@ impl super::Service {
|
||||
/// `notary` must either be empty or have ONE entry. Extraneous notaries
|
||||
/// will be ignored.
|
||||
pub fn verify_server_keys_response(
|
||||
incoming: &IncomingServerKeys,
|
||||
server_keys: &ServerSigningKeys,
|
||||
notary: Option<(&ServerName, &[Base64])>,
|
||||
) -> Result<()> {
|
||||
if let Some((notary_name, notary_keys)) = notary {
|
||||
if !notary_keys.is_empty() {
|
||||
Self::verify_notary_signature(incoming, notary_name, notary_keys)?;
|
||||
Self::verify_notary_signature(server_keys, notary_name, notary_keys)?;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: old_verify_keys aren't considered here because old keys can't
|
||||
// be used to sign key responses.
|
||||
let mut set = ruma::signatures::PublicKeySet::new();
|
||||
incoming
|
||||
.parsed
|
||||
.verify_keys
|
||||
.iter()
|
||||
.for_each(|(key_id, key)| {
|
||||
set.insert(key_id.to_string(), key.key.clone());
|
||||
});
|
||||
server_keys.verify_keys.iter().for_each(|(key_id, key)| {
|
||||
set.insert(key_id.to_string(), key.key.clone());
|
||||
});
|
||||
|
||||
let mut pubkey_map = ruma::signatures::PublicKeyMap::new();
|
||||
pubkey_map.insert(incoming.parsed.server_name.to_string(), set);
|
||||
pubkey_map.insert(server_keys.server_name.to_string(), set);
|
||||
|
||||
let mut canonical = to_canonical_object(&incoming.raw)?;
|
||||
Self::strip_extraneous_signatures(&mut canonical, &incoming.parsed.server_name, &[]);
|
||||
let mut canonical = to_canonical_object(server_keys)?;
|
||||
strip_extraneous_signatures(&mut canonical, &server_keys.server_name, &[]);
|
||||
ruma::signatures::verify_json(&pubkey_map, &canonical).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Verifies that the notary has at least one valid signature present with
|
||||
/// the provided signing keys.
|
||||
fn verify_notary_signature(
|
||||
incoming: &IncomingServerKeys,
|
||||
server_keys: &ServerSigningKeys,
|
||||
notary_name: &ServerName,
|
||||
notary_keys: &[Base64],
|
||||
) -> Result<()> {
|
||||
@@ -123,16 +94,18 @@ impl super::Service {
|
||||
// certificate has been compromised, which would otherwise allow
|
||||
// them to produce attacker-controlled signing keys with valid
|
||||
// self-signatures.
|
||||
let Some(notary_signatures) = incoming.parsed.signatures.get(notary_name) else {
|
||||
let Some(notary_signatures) = server_keys.signatures.get(notary_name) else {
|
||||
return Err!(Request(Forbidden(
|
||||
"Missing notary server signature from {notary_name}"
|
||||
)));
|
||||
};
|
||||
// The notary signed the response as the origin served it, so verify
|
||||
// over the raw JSON, not a re-serialised `ServerSigningKeys`.
|
||||
let for_verify = ruma::signatures::to_canonical_json_string_for_signing(
|
||||
&to_canonical_object(&incoming.raw)?,
|
||||
)?;
|
||||
let mut canonical_object = to_canonical_object(notary_signatures)?;
|
||||
strip_extraneous_signatures(&mut canonical_object, &server_keys.server_name, &[
|
||||
notary_name,
|
||||
]);
|
||||
let for_verify =
|
||||
ruma::signatures::to_canonical_json_string_for_signing(&canonical_object)
|
||||
.expect("canonical JSON must be stringable");
|
||||
|
||||
let raw_notary_keys = notary_keys.iter().map(Base64::as_bytes).collect::<Vec<_>>();
|
||||
let raw_notary_signatures = notary_signatures
|
||||
@@ -152,7 +125,7 @@ impl super::Service {
|
||||
trace!(
|
||||
"Valid signature from {notary_name} present on signing keys response \
|
||||
for {}",
|
||||
incoming.parsed.server_name
|
||||
server_keys.server_name
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
@@ -163,22 +136,22 @@ impl super::Service {
|
||||
"No valid signature from {notary_name} present on signing keys response"
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
fn strip_extraneous_signatures(
|
||||
canonical: &mut CanonicalJsonObject,
|
||||
origin: &ServerName,
|
||||
notaries: &[&ServerName],
|
||||
) {
|
||||
canonical.entry("signatures".to_owned()).and_modify(|sigs| {
|
||||
sigs.as_object_mut().map(|s| {
|
||||
s.retain(|server_name, _| {
|
||||
let Ok(server_name) = ServerName::parse(server_name) else { return false };
|
||||
origin == server_name || notaries.iter().any(|ns| *ns == server_name)
|
||||
});
|
||||
Some(s)
|
||||
pub fn strip_extraneous_signatures(
|
||||
canonical: &mut CanonicalJsonObject,
|
||||
origin: &ServerName,
|
||||
notaries: &[&ServerName],
|
||||
) {
|
||||
canonical.entry("signatures".to_owned()).and_modify(|sigs| {
|
||||
sigs.as_object_mut().map(|s| {
|
||||
s.retain(|server_name, _| {
|
||||
let Ok(server_name) = ServerName::parse(server_name) else { return false };
|
||||
origin == server_name || notaries.iter().any(|ns| *ns == server_name)
|
||||
});
|
||||
Some(s)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -207,9 +180,9 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
)).map(Raw::from_json).unwrap();
|
||||
|
||||
Service::verify_server_keys_response(&response_data, None)
|
||||
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None)
|
||||
.expect("Self-signature of real key response is valid");
|
||||
}
|
||||
|
||||
@@ -234,9 +207,9 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
)).map(Raw::from_json).unwrap();
|
||||
|
||||
Service::verify_server_keys_response(&response_data, None)
|
||||
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None)
|
||||
.expect("Self-signature of real key response is valid");
|
||||
}
|
||||
|
||||
@@ -261,11 +234,11 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
)).map(Raw::from_json).unwrap();
|
||||
let starstruck_pubkey =
|
||||
Base64::<Standard>::parse("Z4oHuEjdUbtC5W/z/gzc5B8raxNk+8gGwbNwgxHqW8Y").unwrap();
|
||||
Service::verify_server_keys_response(
|
||||
&response_data,
|
||||
&response_data.deserialize().unwrap(),
|
||||
Some((server_name!("starstruck.systems"), &[starstruck_pubkey])),
|
||||
)
|
||||
.expect("Server keys from notary are valid");
|
||||
@@ -291,8 +264,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
Service::verify_server_keys_response(&response_data, None)
|
||||
)).map(Raw::from_json).unwrap();
|
||||
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None)
|
||||
.expect_err("Tampered response should fail self-signature check");
|
||||
}
|
||||
|
||||
@@ -329,45 +302,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
Service::verify_server_keys_response(&response_data, None)
|
||||
)).map(Raw::from_json).unwrap();
|
||||
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None)
|
||||
.expect_err("Intercepted notary response should fail strict validation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_response_with_extra_fields() {
|
||||
let response_data = serde_json::from_value(serde_json::json!(
|
||||
{
|
||||
"old_verify_keys": {},
|
||||
"server_name": "origin.example",
|
||||
"signatures": {
|
||||
"notary.example": {
|
||||
"ed25519:a_RBdc": "ozlc2T5TlUa9XAsmeam+ESr20573vqFJvYHonj3nG8x+m6v7K5TSlEKTAlTRrJYiC6T/aWB+yxMae6FYR6nqCA"
|
||||
},
|
||||
"origin.example": {
|
||||
"ed25519:a_jUhC": "+8xKspAfqI8SfrioOVliQ/jCPRDZEuag6JfkN5dXx9gsCX2rSnbvVTJlTJXFiDYUSyIJZg8ilq1QaPsT85ltBA"
|
||||
}
|
||||
},
|
||||
"tls_fingerprints": [],
|
||||
"valid_until_ts": 1900000000000_i64,
|
||||
"verify_keys": {
|
||||
"ed25519:a_jUhC": {
|
||||
"key": "idcPtcSpRB5Chnlv1azhL3rMlcTawgQhoGNZWKaNFGI"
|
||||
}
|
||||
}
|
||||
}
|
||||
)).map(Raw::from_json).unwrap().try_into().unwrap();
|
||||
|
||||
let notary_pubkey =
|
||||
Base64::<Standard>::parse("0ocHGigwa/ap6gSZzzspDQhhOkVkloaf9apolOvwqo8").unwrap();
|
||||
|
||||
Service::verify_server_keys_response(&response_data, None)
|
||||
.expect("Self-signature must verify over the raw response");
|
||||
|
||||
Service::verify_server_keys_response(
|
||||
&response_data,
|
||||
Some((server_name!("notary.example"), &[notary_pubkey])),
|
||||
)
|
||||
.expect("Notary signature must verify over the raw response");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use conduwuit::{
|
||||
Config, Server,
|
||||
log::{Log, LogLevelReloadHandles},
|
||||
metrics::Metrics,
|
||||
};
|
||||
use serde_json::json;
|
||||
use tokio::sync::{Mutex, MutexGuard};
|
||||
|
||||
/// RocksDB's default `Env` is shared by the whole process and closing a
|
||||
/// database stops its background threads, so tests must not keep databases
|
||||
/// open in parallel. Hold the returned guard until the services are dropped.
|
||||
static DATABASE: Mutex<()> = Mutex::const_new(());
|
||||
|
||||
type TestServices = (Arc<crate::Services>, PathBuf, MutexGuard<'static, ()>);
|
||||
|
||||
pub(crate) async fn test_services() -> TestServices { test_services_with(json!({})).await }
|
||||
|
||||
pub(crate) async fn test_services_with(overrides: serde_json::Value) -> TestServices {
|
||||
let guard = DATABASE.lock().await;
|
||||
let _ = rustls::crypto::ring::default_provider().install_default();
|
||||
let path = std::env::temp_dir()
|
||||
.join(format!("continuwuity-shared-state-{:016x}", rand::random::<u64>()));
|
||||
std::fs::create_dir(&path).unwrap();
|
||||
let mut config = json!({
|
||||
"server_name": "test.example",
|
||||
"database_path": path,
|
||||
"db_cache_capacity_mb": 16.0,
|
||||
"rocksdb_write_buffer_capacity_mb": 4.0,
|
||||
"allow_local_presence": false,
|
||||
"dns_servers": ["127.0.0.1"],
|
||||
"allow_invalid_tls_certificates_yes_i_know_what_the_fuck_i_am_doing_with_this_and_i_know_this_is_insecure": true
|
||||
});
|
||||
config
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.extend(overrides.as_object().unwrap().clone());
|
||||
let config: Config = serde_json::from_value(config).unwrap();
|
||||
let runtime = tokio::runtime::Handle::current();
|
||||
let server = Arc::new(Server::new(
|
||||
config,
|
||||
Some(runtime.clone()),
|
||||
Log {
|
||||
reload: LogLevelReloadHandles::default(),
|
||||
capture: Arc::default(),
|
||||
},
|
||||
Metrics::new(Some(runtime), opentelemetry::global::meter("test"), None),
|
||||
));
|
||||
let services = crate::Services::build(server).await.unwrap();
|
||||
(services, path, guard)
|
||||
}
|
||||
Reference in new issue
Block a user