Compare commits

...
Author SHA1 Message Date
timedout cb9b3e65d0 chore: Add newsfrag 2026-11-21 15:21:56 +00:00
Jade Ellis d4aec6ca5c fix: Use mimalloc for c/c++ code by default 2026-11-21 15:21:56 +00:00
Jade Ellis 43cf8cccdf refactor: Unify memory stats and create feature parity 2026-11-21 15:21:56 +00:00
Jade Ellis c6b9854c49 docs(main): Clarify mimalloc feature scope and jemalloc precedence 2026-11-21 15:21:55 +00:00
Jade Ellis 6df7dda329 feat(alloc): Implement trim, memory_usage, and memory_stats for mimalloc 2026-11-21 15:21:55 +00:00
Jade Ellis 8a20a5c349 fix(config): Warn in release builds when both mimalloc and jemalloc are enabled 2026-11-21 15:21:55 +00:00
Jade Ellis a27a5bed29 fix(alloc): Restore not(target_env = "msvc") cfg gates and gate default module 2026-11-21 15:21:54 +00:00
timedout d4ac77a023 feat: Add mimalloc support, drop hardened_malloc 2026-11-21 15:21:54 +00:00
timedout 68068574d3 fix(service/admin): Gate IsTerminal and warn imports on console feature 2026-11-21 15:21:54 +00:00
Jade Ellis 61d77278f6 chore: Add changelog 2026-11-21 15:21:53 +00:00
Jade Ellis 094d24f82e docs(alloc): Fix interrupted doc comments in je.rs 2026-11-21 15:21:53 +00:00
Jade Ellis 8375eb5a36 chore(deps): Upgrade jemalloc with soundness fixes 2026-11-21 15:21:53 +00:00
Jade Ellis f2a9e1f993 test(alloc): add unit tests for jemalloc wrapper fixes 2026-11-21 15:21:52 +00:00
Jade Ellis 318a0205b0 perf(alloc): return &'static Key from mallctl! macro 2026-11-21 15:21:52 +00:00
Jade Ellis f46c87a40d fix(alloc): avoid unnecessary global epoch refreshes in mallctl get and memory_stats 2026-11-21 15:21:52 +00:00
Jade Ellis e0b9bfdb73 fix(alloc): mark raw mallctl helpers unsafe and check null in percpu_arenas 2026-11-21 15:21:52 +00:00
Jade Ellis 180869ecff fix(alloc): validate arena index bounds before arena.<i>.* mallctls 2026-11-21 15:21:51 +00:00
Jade Ellis b9ceb008ba fix(alloc): pass NULL pointers in jemalloc notify ctls 2026-11-21 15:21:51 +00:00
Jade Ellis 3118183bd8 fix(alloc): fix UB and MIB aliasing in thread::allocated/deallocated 2026-11-21 15:21:51 +00:00
Jade Ellis 45b0a30155 fix(alloc): prevent leak, panic, and FFI unwind in memory_stats 2026-11-21 15:21:50 +00:00
Jade Ellis 5169496cb6 fix(alloc): avoid TLS and panics in jemalloc ctor and key lookup 2026-11-21 15:21:50 +00:00
Jade Ellis c1b3c15034 fix(alloc): export malloc_conf as thin pointer and fix options 2026-11-21 15:21:50 +00:00
Julian Anderson bd26b2d596 chore(config): Deprecate request_ip_source 2026-11-20 18:09:40 -05:00
Julian Anderson 6cd38e4278 chore(config): Alphabetize deprecated keys 2026-11-20 18:09:40 -05:00
Julian Anderson aa077b4bec chore(config): Deprecate allow_check_for_updates
Fixes #2555
2026-11-20 18:09:36 -05:00
Ginger 58026816f2 fix: URL-escape device IDs in the web UI 2026-11-20 13:02:47 -05:00
Ginger 9d2e53af99 fix: Config wording improvement 2026-11-20 11:22:21 -05:00
Ginger 6d96936d3a fix: Correct config defaults 2026-11-20 11:22:21 -05:00
Ginger 48e83f6dfa fix: Check max rendezvous data size at the correct time 2026-11-20 11:22:21 -05:00
Ginger 4c49a20255 feat: Enable unauthenticated rendezvous by default 2026-11-20 11:22:21 -05:00
Ginger 330797f4fb fix: Properly save rendezvous sequence token 2026-11-20 11:22:21 -05:00
Ginger 580fcf2365 chore: Add doc comments 2026-11-20 11:22:21 -05:00
Ginger 3d2975209e chore: News fragment 2026-11-20 11:22:21 -05:00
Ginger 2944026572 fix: Be more lenient with allowed characters in device ID scopes 2026-11-20 11:22:21 -05:00
Ginger 8004e962c3 feat: Add support for MSC4388 2026-11-20 11:22:21 -05:00
Ginger a4ef1ecfa2 chore: Clippy fixes 2026-11-20 10:48:04 -05:00
Renovate Bot 6f6e8c4eb5 chore(deps): update node-patch-updates to v2.1.3 2026-11-20 15:04:11 +00:00
Renovate Bot 38433deba7 chore(deps): update rust-zerover-patch-updates 2026-11-20 15:03:49 +00:00
Renovate Bot 67c4111046 chore(deps): update rust-non-major 2026-11-20 15:03:00 +00:00
renovate 50665f4726 chore(Nix): Updated flake hashes 2026-11-20 15:02:37 +00:00
Renovate Bot a9728fab80 chore(deps): update rust to v1.100.0 2026-11-20 15:02:37 +00:00
timedout 49207a42f8 fix: Work around MSC4484 lockout when disabled 2026-11-19 18:44:07 +00:00
timedout 62fc507798 chore: Add changelog 2026-11-19 18:44:07 +00:00
timedout 8f10378bff chore: Regenerate config reference 2026-11-19 18:44:07 +00:00
timedout 52a6bf0003 fix: Don't unconditionally advertise MSC4174 as enabled in capabilities 2026-11-19 18:44:07 +00:00
timedout fcddfb5f35 fix: Gate MSC4406 behind an experiment 2026-11-19 18:44:07 +00:00
timedout 94ba3b2b83 fix: Add an experiment for MSC3814
This proposal is still itself a draft, not even ready for review, so we definitely shouldn't enable it by default per the policy.
2026-11-19 18:44:07 +00:00
timedout 4e7493604a fix: Actually config-gate MSC4560 support 2026-11-19 18:44:07 +00:00
timedout cebeee6bae fix: Actually config-gate MSC4484 support 2026-11-19 18:44:07 +00:00
timedout f3cbfed721 fix: Actually config-gate MSC4174 support 2026-11-19 18:44:07 +00:00
timedout 9bdbaf3300 fix: Actually config-gate MSC4155 support 2026-11-19 18:44:07 +00:00
Silversys 06c63e8de3 chore: Update resolvematrix to 1.5.0 2026-11-18 23:26:46 +01:00
timedout 8ffa3e5367 fix: Wrap parsed & raw values
Rather than passing them around separately everywhere, just unify them into a single struct that is primarily fetched via a raw.
Also stores raw data directly into the database so that signatures can be verified later rather than only at receive time.
2026-11-18 15:10:51 +00:00
hexchen cec1f85f88 fix: verify_server_keys_response fails on non-standard json fields
Previously `verify_server_keys_response` would work with re-serialized 
ServerSigningKeys, which drops any extra, non-standard fields from the
origin server response. The signature is made over the whole response
though, meaning that any response including extra fields will not pass
signature verification.
2026-11-18 15:10:51 +00:00
Jade Ellis ad50b9a3b3 fix(complement): Enable using container builds as a base 2026-11-18 12:37:40 +00:00
timedout ceafc6f58d chore: Update SECURITY.md (#2549)
Reviewed-on: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2549
Reviewed-by: Ginger <ginger@gingershaped.computer>
Reviewed-by: Jade Ellis <jade@ellis.link>
2026-11-17 23:57:45 +00:00
timedout 467e335c90 perf: Remove unnecessary clones for PDU size check 2026-11-17 10:17:15 +00:00
timedout 902e54b525 fix: Off-by-one on PDU size check
Related: https://github.com/ruma/ruma/pull/2677
2026-11-17 10:14:32 +00:00
timedout 4ef487f40e chore: Add changelog frags for quickfixes 2026-11-17 09:30:49 +00:00
timedout 32bfe5f129 fix: Allow sync v2 to be interrupted by server shutdown
Fixes #2361
2026-11-17 09:26:22 +00:00
timedout 07d4c6f304 fix: Don't default to a 30-second sync timeout
Fixes #2462
2026-11-17 09:14:37 +00:00
timedout b3d099a52a fix: Always advertise unstable feature for MSC4354
Fixes #2542
2026-11-17 09:07:42 +00:00
Renovate Bot 92f9531def chore(deps): update https://github.com/taiki-e/install-action digest to ab49d3c 2026-11-17 05:01:16 +00:00
Renovate Bot a3d23c3718 chore(deps): update ghcr.io/renovatebot/renovate docker tag to v44.241.0 2026-11-16 05:05:23 +00:00
Erwan Leboucher 055c430e77 refactor(sync): Build device list updates separately from joined rooms 2026-11-15 20:24:36 +00:00
Erwan Leboucher df5e03f3b4 fix(sync): Apply the room and account data filters in legacy sync 2026-11-15 20:24:36 +00:00
Jade Ellis 6e7ebe66c9 docs: Fix changelog 2026-11-14 23:09:44 +00:00
89 changed files with 1910 additions and 642 deletions

No files matched your search

+1 -1
View File
@@ -71,7 +71,7 @@ runs:
- name: Install timelord-cli and git-warp-time - name: Install timelord-cli and git-warp-time
if: steps.check-binaries.outputs.need-install == 'true' if: steps.check-binaries.outputs.need-install == 'true'
uses: https://github.com/taiki-e/install-action@cfdb7ed4ccc7c7dce37759eae89dc5674b469b39 # v2 uses: https://github.com/taiki-e/install-action@ab49d3c64680143e184118bed66a46419fc15519 # v2
with: with:
tool: git-warp-time,timelord-cli@3.0.1 tool: git-warp-time,timelord-cli@3.0.1
+1 -1
View File
@@ -43,7 +43,7 @@ jobs:
name: Renovate name: Renovate
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: ghcr.io/renovatebot/renovate:44.227.4@sha256:e09d40686f73d43b2c1e4667cb47d3c1d24a6ac730b74ce7aced9c84f68594f1 image: ghcr.io/renovatebot/renovate:44.241.0@sha256:22d22b4ca7d768b5b469309d34379783bf91cd94a58faecf1cd0f4528a65d21c
options: --tmpfs /tmp:exec options: --tmpfs /tmp:exec
steps: steps:
- name: Checkout - name: Checkout
+2 -1
View File
@@ -59,6 +59,7 @@
- Joining a local room the user is not allowed to join now returns `403 M_FORBIDDEN` instead of `500 M_UNKNOWN` when there are no other servers to try. - Joining a local room the user is not allowed to join now returns `403 M_FORBIDDEN` instead of `500 M_UNKNOWN` when there are no other servers to try.
- Room summary visibility checks are no longer incorrectly applied for remote rooms. Contributed by @ginger. - Room summary visibility checks are no longer incorrectly applied for remote rooms. Contributed by @ginger.
- The userinfo endpoint is now accessible even if federation is disabled, allowing LiveKit to be used on servers with federation disabled without using the server name whitelist. - The userinfo endpoint is now accessible even if federation is disabled, allowing LiveKit to be used on servers with federation disabled without using the server name whitelist.
- `!admin token issue` can no longer issue registration tokens when `allow_registration` is false. Contributed by @Clubs.
## Improved Documentation ## Improved Documentation
@@ -74,7 +75,7 @@
## Misc ## Misc
- #2423 - Updated internal Sentry integration setup to the new pattern required by the SDK. #2423
- Upgraded rocksdb from 11.1.1 to 11.12.0 and jemalloc to 5.4.0. - Upgraded rocksdb from 11.1.1 to 11.12.0 and jemalloc to 5.4.0.
Generated
+111 -83
View File
@@ -604,9 +604,9 @@ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.12.1" version = "1.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c"
[[package]] [[package]]
name = "bytesize" name = "bytesize"
@@ -624,6 +624,12 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "cache_control"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bf2a5fb3207c12b5d208ebc145f967fea5cac41a021c37417ccc31ba40f39ee"
[[package]] [[package]]
name = "camino" name = "camino"
version = "1.2.6" version = "1.2.6"
@@ -758,9 +764,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.6.7" version = "4.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946" checksum = "ac230478587d0269d8d6998b82ae69ea51509d55df66d9e92edd1f986904cd4a"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive", "clap_derive",
@@ -778,9 +784,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.6.7" version = "4.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0" checksum = "895c9d8d2ac2dd8b8a29f3724a14e72aaaa6debcf8c38c82f97305c6a172767a"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
@@ -940,7 +946,7 @@ dependencies = [
"hyper", "hyper",
"itertools 0.15.0", "itertools 0.15.0",
"lettre", "lettre",
"rand 0.10.3", "rand 0.10.4",
"reqwest 0.13.5", "reqwest 0.13.5",
"ruma", "ruma",
"ruminuwuity", "ruminuwuity",
@@ -949,6 +955,7 @@ dependencies = [
"sha1 0.11.0", "sha1 0.11.0",
"tokio", "tokio",
"tracing", "tracing",
"wildmatch",
] ]
[[package]] [[package]]
@@ -984,16 +991,17 @@ dependencies = [
"figment", "figment",
"futures", "futures",
"governor", "governor",
"hardened_malloc-rs",
"http", "http",
"http-body-util", "http-body-util",
"hyper-util", "hyper-util",
"ipaddress", "ipaddress",
"lettre", "lettre",
"libc", "libc",
"libloading 0.9.0", "libloading 0.9.1",
"libmimalloc-sys",
"lock_api 0.5.0", "lock_api 0.5.0",
"maplit", "maplit",
"mimalloc",
"nix", "nix",
"num-traits", "num-traits",
"openidconnect", "openidconnect",
@@ -1003,7 +1011,7 @@ dependencies = [
"opentelemetry_sdk", "opentelemetry_sdk",
"parking_lot", "parking_lot",
"prometheus", "prometheus",
"rand 0.10.3", "rand 0.10.4",
"regex", "regex",
"reqwest 0.13.5", "reqwest 0.13.5",
"resolvematrix", "resolvematrix",
@@ -1124,7 +1132,7 @@ dependencies = [
"openidconnect", "openidconnect",
"opentelemetry", "opentelemetry",
"p256 0.14.0", "p256 0.14.0",
"rand 0.10.3", "rand 0.10.4",
"regex", "regex",
"reqwest 0.12.28", "reqwest 0.12.28",
"reqwest 0.13.5", "reqwest 0.13.5",
@@ -1518,9 +1526,9 @@ dependencies = [
[[package]] [[package]]
name = "ctor" name = "ctor"
version = "1.0.13" version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "914a755b7c2d4af2bdcff7ce1739e2db9a1b81a9b07123d8015786ae03c0980d" checksum = "ea691ed9f36489d087419b8b2ba3ef27d89621380b4178c73e2445a379e4e0f4"
dependencies = [ dependencies = [
"link-section", "link-section",
"linktime-proc-macro", "linktime-proc-macro",
@@ -1545,6 +1553,12 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "cty"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
[[package]] [[package]]
name = "curve25519-dalek" name = "curve25519-dalek"
version = "5.0.0" version = "5.0.0"
@@ -1777,10 +1791,11 @@ dependencies = [
[[package]] [[package]]
name = "dtor" name = "dtor"
version = "1.0.6" version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd3f6c362b2bbd7063090886afd78978f5dbf1f11da7efcc40f81d32c943fac1" checksum = "915e80ae7aca23bef767ded8e4a763d0c912c2faaa8bfec1e66d505ebaceb254"
dependencies = [ dependencies = [
"link-section",
"linktime-proc-macro", "linktime-proc-macro",
] ]
@@ -1914,9 +1929,9 @@ dependencies = [
[[package]] [[package]]
name = "email-encoding" name = "email-encoding"
version = "0.4.2" version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "420b9da095f052ea597503e39073b5b3c522f7db933fbac202d91d24492693fd" checksum = "9f690ae2169f2ceb3f45b28b6fcd8fa16839f2f5c8818546774b9425f5f71004"
dependencies = [ dependencies = [
"base64 0.23.1", "base64 0.23.1",
"memchr", "memchr",
@@ -2310,9 +2325,9 @@ dependencies = [
[[package]] [[package]]
name = "granit-parser" name = "granit-parser"
version = "2.1.0" version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f05586d4d4df3d47123207826c40b252728b438a1a07bad3c01ee6bea401df" checksum = "9bd04d0d9c7079b416b458d2317aea4aa964c81938cb7c20f559758c4f422dc8"
dependencies = [ dependencies = [
"arraydeque", "arraydeque",
"smallvec", "smallvec",
@@ -2387,12 +2402,6 @@ dependencies = [
"tokio-util", "tokio-util",
] ]
[[package]]
name = "hardened_malloc-rs"
version = "0.1.2+12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "647deb1583b14d160f85f3ff626f20b6edd366e3852c9843b06077388f794cb6"
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.12.3" version = "0.12.3"
@@ -2487,7 +2496,7 @@ dependencies = [
"idna", "idna",
"ipnet", "ipnet",
"jni", "jni",
"rand 0.10.3", "rand 0.10.4",
"thiserror 2.0.21", "thiserror 2.0.21",
"tinyvec", "tinyvec",
"tokio", "tokio",
@@ -2507,7 +2516,7 @@ dependencies = [
"jni", "jni",
"once_cell", "once_cell",
"prefix-trie", "prefix-trie",
"rand 0.10.3", "rand 0.10.4",
"ring", "ring",
"serde", "serde",
"thiserror 2.0.21", "thiserror 2.0.21",
@@ -2533,7 +2542,7 @@ dependencies = [
"ndk-context", "ndk-context",
"once_cell", "once_cell",
"parking_lot", "parking_lot",
"rand 0.10.3", "rand 0.10.4",
"resolv-conf", "resolv-conf",
"serde", "serde",
"smallvec", "smallvec",
@@ -2946,9 +2955,9 @@ dependencies = [
[[package]] [[package]]
name = "ipaddress" name = "ipaddress"
version = "0.2.11" version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67a97d7409c3ade4304acbff6b33b915af4564c42bf6e383651ced09bd6a2bce" checksum = "e0ae5a9c049476ef23026df39fe92a8d83c1d8b670b975f095cb4d5a3b13d43e"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"libc", "libc",
@@ -3188,9 +3197,9 @@ dependencies = [
[[package]] [[package]]
name = "lettre" name = "lettre"
version = "0.11.23" version = "0.11.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2c646bd5cc763b1087b15493e29a64be6147ba8f19342004fa52048ee596eae" checksum = "f294f3d7cdb313e578acef7d7727d4e8d897e0fcd0d6d58c19959cec95073f19"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"base64 0.23.1", "base64 0.23.1",
@@ -3234,9 +3243,9 @@ dependencies = [
[[package]] [[package]]
name = "libloading" name = "libloading"
version = "0.9.0" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "754ca22de805bb5744484a5b151a9e1a8e837d5dc232c2d7d8c2e3492edc8b60" checksum = "a1832accd5a4ca2795ace4d05d15c4039be15b62d3b950eff99746a990e3cc10"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"windows-link", "windows-link",
@@ -3248,6 +3257,16 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
[[package]]
name = "libmimalloc-sys"
version = "0.1.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9"
dependencies = [
"cc",
"cty",
]
[[package]] [[package]]
name = "libz-sys" name = "libz-sys"
version = "1.1.32" version = "1.1.32"
@@ -3261,9 +3280,9 @@ dependencies = [
[[package]] [[package]]
name = "link-section" name = "link-section"
version = "0.19.3" version = "0.19.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39c29a617ce3df32c08497bdc1ab6e2376e0b17948ac166a2fbe5977c5954cd9" checksum = "4d9aae57673c1a235149777a74d152f3210ebd3e3b13346d2cdb6809e566bd3c"
[[package]] [[package]]
name = "linked-hash-map" name = "linked-hash-map"
@@ -3421,6 +3440,15 @@ dependencies = [
"walkdir", "walkdir",
] ]
[[package]]
name = "mimalloc"
version = "0.1.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862"
dependencies = [
"libmimalloc-sys",
]
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.3.18" version = "0.3.18"
@@ -4610,7 +4638,7 @@ dependencies = [
"bytes", "bytes",
"getrandom 0.4.3", "getrandom 0.4.3",
"lru-slab", "lru-slab",
"rand 0.10.3", "rand 0.10.4",
"rand_pcg", "rand_pcg",
"ring", "ring",
"rustc-hash", "rustc-hash",
@@ -4687,9 +4715,9 @@ dependencies = [
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.10.3" version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" checksum = "8f6fa277c67e6ea590466f04c3fe82cb509f0864fe470643e5570de9514a9b11"
dependencies = [ dependencies = [
"chacha20", "chacha20",
"getrandom 0.4.3", "getrandom 0.4.3",
@@ -4780,9 +4808,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.13.1" version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d" checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@@ -4792,9 +4820,9 @@ dependencies = [
[[package]] [[package]]
name = "regex-automata" name = "regex-automata"
version = "0.4.18" version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@@ -4803,9 +4831,9 @@ dependencies = [
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.8.11" version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
[[package]] [[package]]
name = "reqwest" name = "reqwest"
@@ -4897,10 +4925,11 @@ checksum = "1e061d1b48cb8d38042de4ae0a7a6401009d6143dc80d2e2d6f31f0bdd6470c7"
[[package]] [[package]]
name = "resolvematrix" name = "resolvematrix"
version = "1.4.2" version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6e659fe17ed82acfac43641d00d1bbfd0a9d53ec4d2f901b01f792f0e2c9e3c" checksum = "39a1efc3c55274528f8b1a916eb0edf5c40a8364b4899fbc1283a57c8d0024db"
dependencies = [ dependencies = [
"cache_control",
"hickory-resolver", "hickory-resolver",
"num-traits", "num-traits",
"parking_lot", "parking_lot",
@@ -5036,7 +5065,7 @@ dependencies = [
"js_int", "js_int",
"konst", "konst",
"percent-encoding", "percent-encoding",
"rand 0.10.3", "rand 0.10.4",
"regex", "regex",
"ruma-identifiers-validation", "ruma-identifiers-validation",
"ruma-macros", "ruma-macros",
@@ -5086,7 +5115,7 @@ dependencies = [
"js_int", "js_int",
"memchr", "memchr",
"mime", "mime",
"rand 0.10.3", "rand 0.10.4",
"ruma-common", "ruma-common",
"ruma-events", "ruma-events",
"ruma-signatures", "ruma-signatures",
@@ -5142,7 +5171,7 @@ dependencies = [
"ed25519-dalek", "ed25519-dalek",
"memchr", "memchr",
"pkcs8 0.11.0", "pkcs8 0.11.0",
"rand 0.10.3", "rand 0.10.4",
"ruma-common", "ruma-common",
"ruma-events", "ruma-events",
"serde_json", "serde_json",
@@ -5180,7 +5209,7 @@ dependencies = [
[[package]] [[package]]
name = "rust-librocksdb-sys" name = "rust-librocksdb-sys"
version = "0.49.0+11.12.0" version = "0.49.0+11.12.0"
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=6021299f3e0e9455dc3f2e39c65e1dc217be8903#6021299f3e0e9455dc3f2e39c65e1dc217be8903" source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=85ded20348e3dab902c239967075795e9c6d101b#85ded20348e3dab902c239967075795e9c6d101b"
dependencies = [ dependencies = [
"bindgen", "bindgen",
"bzip2-sys", "bzip2-sys",
@@ -5198,7 +5227,7 @@ dependencies = [
[[package]] [[package]]
name = "rust-rocksdb" name = "rust-rocksdb"
version = "0.54.0" version = "0.54.0"
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=6021299f3e0e9455dc3f2e39c65e1dc217be8903#6021299f3e0e9455dc3f2e39c65e1dc217be8903" source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=85ded20348e3dab902c239967075795e9c6d101b#85ded20348e3dab902c239967075795e9c6d101b"
dependencies = [ dependencies = [
"libc", "libc",
"parking_lot", "parking_lot",
@@ -5477,9 +5506,9 @@ dependencies = [
[[package]] [[package]]
name = "sentry" name = "sentry"
version = "0.49.5" version = "0.49.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7c2c887f17023c9462a4202176efc33ca7228f9c30c0141c765ab534ab2d36b" checksum = "d7bc7fb14982f395d53924f4feebd48c6cc136399c49ac2160dcf2b260e74b75"
dependencies = [ dependencies = [
"cfg_aliases", "cfg_aliases",
"httpdate", "httpdate",
@@ -5497,9 +5526,9 @@ dependencies = [
[[package]] [[package]]
name = "sentry-backtrace" name = "sentry-backtrace"
version = "0.49.5" version = "0.49.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c391d4330f3b37fdddf2b928151244e8c2dc0cfea1740e455cc8942af436f919" checksum = "f68328b53eb7defc20f993ed7cd1f4ce10d06feecefdf914db062ce2523e4b77"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"regex", "regex",
@@ -5508,9 +5537,9 @@ dependencies = [
[[package]] [[package]]
name = "sentry-contexts" name = "sentry-contexts"
version = "0.49.5" version = "0.49.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "654dacb94135c713e1dcbff01314a83d333f0e62f76b91fed5ab87415075530c" checksum = "1d57fb52d1e5d76cc5a7415428004699d9e6d498859a7acc8e05becc57dad81f"
dependencies = [ dependencies = [
"hostname", "hostname",
"libc", "libc",
@@ -5522,22 +5551,21 @@ dependencies = [
[[package]] [[package]]
name = "sentry-core" name = "sentry-core"
version = "0.49.5" version = "0.49.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edcb294ca821e5c5624edaf33535eb18b06ef4f8675201d3e4d81ce325741692" checksum = "8367f7f31654b35453e20c8aca06e0ecf5a4d4793e33be139c1581e475a94e6a"
dependencies = [ dependencies = [
"rand 0.10.3", "rand 0.10.4",
"sentry-types", "sentry-types",
"serde",
"serde_json", "serde_json",
"url", "url",
] ]
[[package]] [[package]]
name = "sentry-debug-images" name = "sentry-debug-images"
version = "0.49.5" version = "0.49.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74835055f6a57b78c0e13f941b460e39edc1899b05fe31dd47cd02367f70888f" checksum = "386f4ce2364e58f2ca811f388a0427fa13784bbe7aee85f302e901ef4b00fab9"
dependencies = [ dependencies = [
"findshlibs", "findshlibs",
"sentry-core", "sentry-core",
@@ -5545,9 +5573,9 @@ dependencies = [
[[package]] [[package]]
name = "sentry-log" name = "sentry-log"
version = "0.49.5" version = "0.49.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f24141aaeb20c731719b33077f1063a79e07eef63a4954530559c067ba046aad" checksum = "c938358d54c65a79fea165a447ae0eabc5717f23ba482ceee279c5645f0ccad3"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"log", "log",
@@ -5556,9 +5584,9 @@ dependencies = [
[[package]] [[package]]
name = "sentry-panic" name = "sentry-panic"
version = "0.49.5" version = "0.49.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5d28522f81ed90510ec43ed01cb1873a393b329dc719f93335b4c75fbef05d1" checksum = "2ab095af8f107e893941f857d8e204f5d25404247c34af131c7d199e3021679f"
dependencies = [ dependencies = [
"sentry-backtrace", "sentry-backtrace",
"sentry-core", "sentry-core",
@@ -5566,9 +5594,9 @@ dependencies = [
[[package]] [[package]]
name = "sentry-tower" name = "sentry-tower"
version = "0.49.5" version = "0.49.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "057730796d82b72f35f57e66fc41c2b9e334eb3edf5030dd18d3b1f88d062c78" checksum = "18f29b19179ae36e6318c71f6ee18d1e0db8bbe8e7b7f213c2aba9e721b650fb"
dependencies = [ dependencies = [
"http", "http",
"pin-project", "pin-project",
@@ -5580,9 +5608,9 @@ dependencies = [
[[package]] [[package]]
name = "sentry-tracing" name = "sentry-tracing"
version = "0.49.5" version = "0.49.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec67c296aadc41d4d41b64738908c51cacddf99edebe7a2b476f9bf40de93ff5" checksum = "a7cae82b121a812e69a1cfaaacb800112f5f261f362fbf5a08e13d1c11ef349e"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"sentry-backtrace", "sentry-backtrace",
@@ -5593,13 +5621,13 @@ dependencies = [
[[package]] [[package]]
name = "sentry-types" name = "sentry-types"
version = "0.49.5" version = "0.49.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83d84a36b6bdeeb7813976fb899fca45d94540d2e2b80eac91ba66b4c654d8f0" checksum = "03da7c1f79d001b4f18e277f8207470efb262fb94c761baa195873d2ace8eb8a"
dependencies = [ dependencies = [
"debugid", "debugid",
"hex", "hex",
"rand 0.10.3", "rand 0.10.4",
"serde", "serde",
"serde_json", "serde_json",
"thiserror 2.0.21", "thiserror 2.0.21",
@@ -5620,12 +5648,12 @@ dependencies = [
[[package]] [[package]]
name = "serde-saphyr" name = "serde-saphyr"
version = "2.1.1" version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d43fb82d550b07e6f929a58d7d0935182602f48ddead875f5ee313c41c8f07fe" checksum = "969cde0349344dbbf58b5f9badbfb8f806db13969364eb8007c057ef687007d9"
dependencies = [ dependencies = [
"annotate-snippets", "annotate-snippets",
"base64 0.23.1", "base64 0.22.1",
"encoding_rs_io", "encoding_rs_io",
"granit-parser", "granit-parser",
"nohash-hasher", "nohash-hasher",
@@ -5963,9 +5991,9 @@ dependencies = [
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.16.5" version = "1.16.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "149309498a5f7334b12ddae0cad8aba81ce785fe91755068867e017cf98fee46" checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59"
dependencies = [ dependencies = [
"serde", "serde",
] ]
@@ -6220,7 +6248,7 @@ dependencies = [
[[package]] [[package]]
name = "tikv-jemalloc-ctl" name = "tikv-jemalloc-ctl"
version = "0.7.0" version = "0.7.0"
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=ac4d4861b335b199f812807996e8c9166961041a#ac4d4861b335b199f812807996e8c9166961041a" source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=46e7821917b06636cdb5b203d312799970eaea92#46e7821917b06636cdb5b203d312799970eaea92"
dependencies = [ dependencies = [
"libc", "libc",
"tikv-jemalloc-sys", "tikv-jemalloc-sys",
@@ -6229,7 +6257,7 @@ dependencies = [
[[package]] [[package]]
name = "tikv-jemalloc-sys" name = "tikv-jemalloc-sys"
version = "0.7.0+5.4.0-0-g7a34f18502e7b222724097cdcd499b437d189acc" version = "0.7.0+5.4.0-0-g7a34f18502e7b222724097cdcd499b437d189acc"
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=ac4d4861b335b199f812807996e8c9166961041a#ac4d4861b335b199f812807996e8c9166961041a" source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=46e7821917b06636cdb5b203d312799970eaea92#46e7821917b06636cdb5b203d312799970eaea92"
dependencies = [ dependencies = [
"cc", "cc",
"libc", "libc",
@@ -6238,7 +6266,7 @@ dependencies = [
[[package]] [[package]]
name = "tikv-jemallocator" name = "tikv-jemallocator"
version = "0.7.0" version = "0.7.0"
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=ac4d4861b335b199f812807996e8c9166961041a#ac4d4861b335b199f812807996e8c9166961041a" source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=46e7821917b06636cdb5b203d312799970eaea92#46e7821917b06636cdb5b203d312799970eaea92"
dependencies = [ dependencies = [
"libc", "libc",
"tikv-jemalloc-sys", "tikv-jemalloc-sys",
+17 -14
View File
@@ -272,6 +272,9 @@ version = "0.5.2"
[workspace.dependencies.libloading] [workspace.dependencies.libloading]
version = "0.9.0" version = "0.9.0"
[workspace.dependencies.wildmatch]
version = "2.7.0"
# Validating urls in config, was already a transitive dependency # Validating urls in config, was already a transitive dependency
[workspace.dependencies.url] [workspace.dependencies.url]
version = "2.5.8" version = "2.5.8"
@@ -392,6 +395,7 @@ features = [
"unstable-msc4406", "unstable-msc4406",
"unstable-msc4439", "unstable-msc4439",
"unstable-msc4354", "unstable-msc4354",
"unstable-msc4388",
"unstable-msc4480", "unstable-msc4480",
"unstable-msc4466", "unstable-msc4466",
"unstable-msc4494", "unstable-msc4494",
@@ -403,7 +407,7 @@ features = [
[workspace.dependencies.rust-rocksdb] [workspace.dependencies.rust-rocksdb]
git = "https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1" git = "https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1"
rev = "6021299f3e0e9455dc3f2e39c65e1dc217be8903" rev = "85ded20348e3dab902c239967075795e9c6d101b"
default-features = false default-features = false
features = [ features = [
"multi-threaded-cf", "multi-threaded-cf",
@@ -486,7 +490,7 @@ version = "0.49.5"
# jemalloc usage # jemalloc usage
[workspace.dependencies.tikv-jemalloc-sys] [workspace.dependencies.tikv-jemalloc-sys]
git = "https://forgejo.ellis.link/continuwuation/jemallocator" git = "https://forgejo.ellis.link/continuwuation/jemallocator"
rev = "ac4d4861b335b199f812807996e8c9166961041a" rev = "46e7821917b06636cdb5b203d312799970eaea92"
default-features = false default-features = false
features = [ features = [
"background_threads_runtime_support", "background_threads_runtime_support",
@@ -494,7 +498,7 @@ features = [
] ]
[workspace.dependencies.tikv-jemallocator] [workspace.dependencies.tikv-jemallocator]
git = "https://forgejo.ellis.link/continuwuation/jemallocator" git = "https://forgejo.ellis.link/continuwuation/jemallocator"
rev = "ac4d4861b335b199f812807996e8c9166961041a" rev = "46e7821917b06636cdb5b203d312799970eaea92"
default-features = false default-features = false
features = [ features = [
"background_threads_runtime_support", "background_threads_runtime_support",
@@ -502,7 +506,7 @@ features = [
] ]
[workspace.dependencies.tikv-jemalloc-ctl] [workspace.dependencies.tikv-jemalloc-ctl]
git = "https://forgejo.ellis.link/continuwuation/jemallocator" git = "https://forgejo.ellis.link/continuwuation/jemallocator"
rev = "ac4d4861b335b199f812807996e8c9166961041a" rev = "46e7821917b06636cdb5b203d312799970eaea92"
default-features = false default-features = false
features = ["use_std"] features = ["use_std"]
@@ -518,15 +522,6 @@ features = ["resource"]
version = "0.5.0" version = "0.5.0"
default-features = false default-features = false
[workspace.dependencies.hardened_malloc-rs]
version = "0.1.2"
default-features = false
features = [
"static",
"gcc",
"light",
]
[workspace.dependencies.rustyline-async] [workspace.dependencies.rustyline-async]
version = "0.4.9" version = "0.4.9"
default-features = false default-features = false
@@ -600,12 +595,20 @@ features = ["std"]
version = "0.3.0" version = "0.3.0"
[workspace.dependencies.resolvematrix] [workspace.dependencies.resolvematrix]
version = "1.4.2" version = "1.5.0"
features = ["unstable-msc4188"] features = ["unstable-msc4188"]
[workspace.dependencies.serde_urlencoded] [workspace.dependencies.serde_urlencoded]
version = "0.7.1" version = "0.7.1"
[workspace.dependencies.mimalloc]
version = "0.1.52"
features = ["extended"]
[workspace.dependencies.libmimalloc-sys]
version = "0.1.49"
features = ["extended"]
# #
# Patches # Patches
# #
+8 -3
View File
@@ -23,12 +23,15 @@ to encourage users to stay up-to-date with the latest release, and we have no co
We appreciate the efforts of security researchers and the community in identifying and reporting vulnerabilities. To We appreciate the efforts of security researchers and the community in identifying and reporting vulnerabilities. To
ensure that potential vulnerabilities are addressed properly, please follow these guidelines: ensure that potential vulnerabilities are addressed properly, please follow these guidelines:
1. **Contact members of the team directly** over E2EE private message. 1. **Contact _all_ members of the team** over E2EE private message on Matrix.
Add each contact to the same encrypted room. **Do not message maintainers individually**.
If you cannot reach us from matrix.org, please try [another server][sl] (e.g. continuwuity.rocks).
- [@jade:ellis.link](https://matrix.to/#/@jade:ellis.link) - [@jade:ellis.link](https://matrix.to/#/@jade:ellis.link)
- [@nex:nexy7574.co.uk](https://matrix.to/#/@nex:nexy7574.co.uk) - [@nex:nexy7574.co.uk](https://matrix.to/#/@nex:nexy7574.co.uk)
- [@ginger:gingershaped.computer](https://matrix.to/#/@ginger:gingershaped.computer) - [@ginger:gingershaped.computer](https://matrix.to/#/@ginger:gingershaped.computer)
2. **Email the security team** at [security@continuwuity.org](mailto:security@continuwuity.org). This is not E2EE, so 2. **Email the security team** at [security@continuwuity.org](mailto:security@continuwuity.org). This is not E2EE, so
don't include sensitive details. don't include sensitive details. Do not ask where to send sensitive details either; that
information is included in this security policy. We may not respond to emails that do this.
3. **Do not disclose the vulnerability publicly** until a fix has been pushed to the main branch. 3. **Do not disclose the vulnerability publicly** until a fix has been pushed to the main branch.
4. **Provide detailed information** about the vulnerability, including: 4. **Provide detailed information** about the vulnerability, including:
- A clear description of the issue - A clear description of the issue
@@ -42,6 +45,8 @@ ensure that potential vulnerabilities are addressed properly, please follow thes
If you have any doubts about a potential security vulnerability, contact us via private channels first! We'd prefer that If you have any doubts about a potential security vulnerability, contact us via private channels first! We'd prefer that
you bother us, instead of having a vulnerability disclosed without a fix. you bother us, instead of having a vulnerability disclosed without a fix.
[sl]: https://servers.joinmatrix.org
### Terms for credit ### Terms for credit
Before reporting a vulnerability, please remember that we are a small team maintaining a large codebase depended upon by Before reporting a vulnerability, please remember that we are a small team maintaining a large codebase depended upon by
@@ -105,4 +110,4 @@ When security vulnerabilities are identified:
--- ---
This security policy was last updated on May 25, 2025. This security policy was last updated on November 17th, 2026.
+17 -3
View File
@@ -52,8 +52,10 @@ else
fi fi
# The base docker image to use for complement tests # The base docker image to use for complement tests
# You can build the default with `docker build -t continuwuity:complement -f ./docker/complement.Dockerfile .` # 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`. Only the debug binary is used. # 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 .`.
COMPLEMENT_BASE_IMAGE="${COMPLEMENT_BASE_IMAGE:-continuwuity:complement}" 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 # Complement tests that are skipped due to flakiness/reliability issues or we don't implement such features and won't for a long time
@@ -83,6 +85,13 @@ for command in docker go jq; do
fi fi
done 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 [ -n "$IMAGE_ARCHIVE" ]; then
if [ ! -f "$IMAGE_ARCHIVE" ]; then if [ ! -f "$IMAGE_ARCHIVE" ]; then
echo "Docker image archive not found: $IMAGE_ARCHIVE" echo "Docker image archive not found: $IMAGE_ARCHIVE"
@@ -99,7 +108,12 @@ fi
if ! docker image inspect "$COMPLEMENT_BASE_IMAGE" > /dev/null 2>&1; then if ! docker image inspect "$COMPLEMENT_BASE_IMAGE" > /dev/null 2>&1; then
echo "Complement base image not found: $COMPLEMENT_BASE_IMAGE" echo "Complement base image not found: $COMPLEMENT_BASE_IMAGE"
echo "Build it with: cargo build -p conduwuit --features openreg && docker build -t $COMPLEMENT_BASE_IMAGE -f docker/complement.Dockerfile ." 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
exit 1 exit 1
fi fi
+1
View File
@@ -0,0 +1 @@
Legacy `/sync` now honours the `room.rooms`, `room.not_rooms`, `account_data.types` and `account_data.not_types` filter fields instead of returning every room and all account data. Contributed by @eleboucher.
+1
View File
@@ -0,0 +1 @@
Requests waiting on `/_matrix/client/v3/sync` can now be interrupted by the server shutdown, unblocking the 30-second shutdown delay imposed on a quiet server.
+1
View File
@@ -0,0 +1 @@
Fix remote server key signature verification when extra fields exist. Contributed by @hexchen
+1
View File
@@ -0,0 +1 @@
Added support for MSC4388, allowing compatible Matrix clients to log in to Continuwuity by scanning a QR code on an already logged-in client. Contributed by @ginger.
+1
View File
@@ -0,0 +1 @@
`/_matrix/client/v3/sync` no longer waits 30 seconds if the `timeout` parameter is omitted or set to zero, correctly reflecting the specification's rule that such requests should return immediately, even if they are empty.
+1
View File
@@ -0,0 +1 @@
Fixed the experiments implementation in #2517 not properly disabling some functionality when associated experiments weren't enabled.
+1
View File
@@ -0,0 +1 @@
The sticky events feature flag is correctly advertised in `/_matrix/client/versions` again after it was accidentally removed in #2517.
+1
View File
@@ -0,0 +1 @@
The former configuration alias `allow_check_for_updates` is now explicitly deprecated in favor of `allow_announcements_check`. Additionally, `request_ip_source` is now deprecated in favor of `accepted_ip_sources`.
+1
View File
@@ -0,0 +1 @@
Dropped support for `hardened_malloc` and add support for `mimalloc` instead. Contributed by @nex and @jade.
+1
View File
@@ -0,0 +1 @@
Fix soundness and correctness issues in the jemalloc interface, improving performance. Contributed by @Jade
+63 -7
View File
@@ -412,7 +412,7 @@
# env: CONTINUWUITY_IP_LOOKUP_STRATEGY # env: CONTINUWUITY_IP_LOOKUP_STRATEGY
#ip_lookup_strategy = 5 #ip_lookup_strategy = 5
# The preferred source to use for getting the real client IP. # DEPRECATED: The preferred source to use for getting the real client IP.
# #
# Takes any of the following options: # Takes any of the following options:
# #
@@ -431,9 +431,10 @@
# to set this header" check; if the header selected is present, it is # to set this header" check; if the header selected is present, it is
# used. # used.
# #
# Ignored if `accepted_ip_sources` is set. # Ignored if `accepted_ip_sources` is set. `accepted_ip_sources` is
# the preferred alternative.
# #
# If not set set, `direct` is used. Additionally, `direct` is used # If not set, `direct` is used. Additionally, `direct` is used
# as a fallback if the chosen header is not found. # as a fallback if the chosen header is not found.
# #
# env: CONTINUWUITY_REQUEST_IP_SOURCE # env: CONTINUWUITY_REQUEST_IP_SOURCE
@@ -812,15 +813,32 @@
# env: CONTINUWUITY_FORGET_FORCED_UPON_LEAVE # env: CONTINUWUITY_FORGET_FORCED_UPON_LEAVE
#forget_forced_upon_leave = false #forget_forced_upon_leave = false
# Set this to true to require authentication on the normally # Set this to true to require authentication when looking up user profiles
# unauthenticated profile retrieval endpoints (GET) # through this server.
# "/_matrix/client/v3/profile/{userId}".
# #
# This can prevent profile scraping. # 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 # env: CONTINUWUITY_REQUIRE_AUTH_FOR_PROFILE_REQUESTS
#require_auth_for_profile_requests = false #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.
#
# For QR code login, the device that shows the QR code is the one that
# 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
# not have a camera) to show a QR code. Setting this to true will
# require logged-out devices to scan the QR code instead.
#
# env: CONTINUWUITY_REQUIRE_AUTH_FOR_RENDEZVOUS
#require_auth_for_rendezvous = false
# Set this to true to allow your server's public room directory to be # Set this to true to allow your server's public room directory to be
# federated. Set this to false to protect against /publicRooms spiders, # federated. Set this to false to protect against /publicRooms spiders,
# but will forbid external users from viewing your server's public room # but will forbid external users from viewing your server's public room
@@ -2669,6 +2687,26 @@
# and consequently know why you should enable them. # and consequently know why you should enable them.
# MSC3814: Dehydrated devices with SSSS
#
# Enables server-side support for "dehydrated devices", which are
# server-side devices (created by supporting clients) that can collect
# encryption keys when there are no online devices, which supporting
# clients can then "hydrate" to download any encryption keys that were
# sent while they were offline.
#
# Important: this is NOT required to receive encrypted messages while you
# are offline. Devices can still receive encrypted messages while they are
# offline, but to share those keys with new devices, they have to be
# online. Dehydrated devices work around this by providing a "shared"
# device new sessions can bootstrap from, to receive keys from before they
# logged in that haven't been uploaded to the server-side key backup yet.
#
# https://github.com/matrix-org/matrix-spec-proposals/pull/3814
#
# env: CONTINUWUITY_EXPERIMENTS__MSC3814
#msc3814 = false
# MSC4155: Invite filtering # MSC4155: Invite filtering
# #
# Provides advanced invite filtering rules for users, allowing complex # Provides advanced invite filtering rules for users, allowing complex
@@ -2693,6 +2731,24 @@
# env: CONTINUWUITY_EXPERIMENTS__MSC4174 # env: CONTINUWUITY_EXPERIMENTS__MSC4174
#msc4174 = false #msc4174 = false
# MSC4406: `M_SENDER_IGNORED` error code
#
# Introduces a new error code that explicitly informs clients the reason
# they cannot access an event if it is sent by an ignored user. Without
# this proposal, clients will simply get a "not found" or "forbidden"
# error when requesting events sent by users that have been ignored, which
# leads to replies being shown as "this message could not be found".
# The new error code allows clients to distinguish unknown/forbidden
# events from ignored senders, allowing them to display an error message
# like "you have blocked this sender" instead.
#
# Requires a supporting client to be useful.
#
# https://github.com/matrix-org/matrix-spec-proposals/pull/4406
#
# env: CONTINUWUITY_EXPERIMENTS__MSC4406
#msc4406 = false
# MSC4484: Server Administration OAuth Scope # MSC4484: Server Administration OAuth Scope
# #
# Adds a new OAuth2 scope that explicitly grants a token temporary # Adds a new OAuth2 scope that explicitly grants a token temporary
+21 -3
View File
@@ -1,11 +1,29 @@
FROM ubuntu:latest 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
EXPOSE 8008 EXPOSE 8008
EXPOSE 8448 EXPOSE 8448
RUN apt-get update && apt-get install -y ca-certificates liburing2 && rm -rf /var/lib/apt/lists/* 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/ 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-entrypoint.sh /usr/local/bin/complement-entrypoint.sh
COPY complement/complement.config.toml /etc/continuwuity/config.toml COPY complement/complement.config.toml /etc/continuwuity/config.toml
COPY target/debug/conduwuit /usr/local/bin/conduwuit RUN chmod +x /usr/local/bin/complement-entrypoint.sh
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 #HEALTHCHECK --interval=30s --timeout=5s CMD curl --fail http://localhost:8008/_continuwuity/server_version || exit 1
ENTRYPOINT ["/usr/local/bin/complement-entrypoint.sh"] 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}
+3 -2
View File
@@ -84,8 +84,9 @@ All forked dependencies are maintained under the
- [rocksdb][continuwuation-rocksdb] - Fork of [facebook/rocksdb][rocksdb] via - [rocksdb][continuwuation-rocksdb] - Fork of [facebook/rocksdb][rocksdb] via
[`@zaidoon1`][8] with liburing build fixes and GCC debug build fixes [`@zaidoon1`][8] with liburing build fixes and GCC debug build fixes
- [jemallocator][continuwuation-jemallocator] - Fork of - [jemallocator][continuwuation-jemallocator] - Fork of
[tikv/jemallocator][jemallocator] fixing musl builds, suspicious code, and [tikv/jemallocator][jemallocator] fixing musl builds and using jemalloc's
adding support for redzones in Valgrind `*x` APIs consistently in `GlobalAlloc` to avoid interposer/Valgrind
mismatches
- [rustyline-async][continuwuation-rustyline-async] - Fork of - [rustyline-async][continuwuation-rustyline-async] - Fork of
[zyansheep/rustyline-async][rustyline-async] with tab completion callback and [zyansheep/rustyline-async][rustyline-async] with tab completion callback and
`CTRL+\` signal quit event for Continuwuity console CLI `CTRL+\` signal quit event for Continuwuity console CLI
+14
View File
@@ -20,6 +20,20 @@ docker build -t continuwuity:complement -f docker/complement.Dockerfile .
The `openreg` feature is required: without it the server refuses the open The `openreg` feature is required: without it the server refuses the open
registrations Complement uses to create test users, and almost every test fails. 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 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 `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 summary to `tests/test_results/complement/test_results.jsonl`. It exits nonzero
+1
View File
@@ -82,6 +82,7 @@ Names below are as they appear in Prometheus. OTLP uses the dotted OpenTelemetry
| `continuwuity_database_block_cache_bytes` | gauge | `column` | RocksDB block cache usage | | `continuwuity_database_block_cache_bytes` | gauge | `column` | RocksDB block cache usage |
| `continuwuity_cache_entries` | gauge | `name` | Entries in the auth chain and state info caches | | `continuwuity_cache_entries` | gauge | `name` | Entries in the auth chain and state info caches |
| `continuwuity_jemalloc_memory_bytes` | gauge | `kind` | jemalloc statistics, only with the `jemalloc_stats` feature | | `continuwuity_jemalloc_memory_bytes` | gauge | `kind` | jemalloc statistics, only with the `jemalloc_stats` feature |
| `continuwuity_mimalloc_memory_bytes` | gauge | `kind` | mimalloc statistics, only with the `mimalloc` feature |
| `process_uptime_seconds` | gauge | | Time since the server started | | `process_uptime_seconds` | gauge | | Time since the server started |
| `process_cpu_time_seconds_total` | counter | `cpu_mode` | CPU time used by the process | | `process_cpu_time_seconds_total` | counter | `cpu_mode` | CPU time used by the process |
| `process_memory_usage_bytes` | gauge | | Resident memory (Linux) | | `process_memory_usage_bytes` | gauge | | Resident memory (Linux) |
+1 -1
View File
@@ -12,7 +12,7 @@
target: target:
target.fromToolchainName { target.fromToolchainName {
name = (lib.importTOML "${inputs.self}/rust-toolchain.toml").toolchain.channel; name = (lib.importTOML "${inputs.self}/rust-toolchain.toml").toolchain.channel;
sha256 = "sha256-+xUr6Al1wZSqX8aEsq7DpuFOK4Ve/i+qTl+K5uWQ9GM="; sha256 = "sha256-MFHoWVcPZKjFrLnQnodCXbUsfZcofGfo9tV9fTTvklg=";
}; };
in in
{ {
+13 -13
View File
@@ -431,9 +431,9 @@
} }
}, },
"node_modules/@rspress/core": { "node_modules/@rspress/core": {
"version": "2.1.2", "version": "2.1.3",
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.2.tgz", "resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.3.tgz",
"integrity": "sha512-3ghPRkZFwbuO3tr2Rb5cxi6QfSFWOcxoZ5p4pv21lbN5DxAzMduITFlfgBMTArIQbehXrfXw3OUXe1l422b0RA==", "integrity": "sha512-qKa5c7zHO8cmhxkReURd3dN/ZRfHYnEztdIQ9hMuolaNzhSYo2A36XErUvLvbMf2EUM2AxfPYRQv+4Crfeq6pw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@@ -441,7 +441,7 @@
"@mdx-js/react": "^3.1.1", "@mdx-js/react": "^3.1.1",
"@rsbuild/core": "^2.2.14", "@rsbuild/core": "^2.2.14",
"@rsbuild/plugin-react": "~2.1.1", "@rsbuild/plugin-react": "~2.1.1",
"@rspress/shared": "2.1.2", "@rspress/shared": "2.1.3",
"@shikijs/rehype": "^4.2.0", "@shikijs/rehype": "^4.2.0",
"@shikijs/transformers": "^4.2.0", "@shikijs/transformers": "^4.2.0",
"@types/mdast": "^4.0.4", "@types/mdast": "^4.0.4",
@@ -485,9 +485,9 @@
} }
}, },
"node_modules/@rspress/plugin-client-redirects": { "node_modules/@rspress/plugin-client-redirects": {
"version": "2.1.2", "version": "2.1.3",
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.1.2.tgz", "resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.1.3.tgz",
"integrity": "sha512-kNCC7fffXA277TzTDfKpP+QuCI1X218lJ5JH/2iqYR8PHnLw0Y6ZIwoFmJlE0eKaBdniYyBRGn9zgvT93mCWdg==", "integrity": "sha512-iEqJ8qEFuUxGKRVaS/WMyFi8FiJlogdcEHbGK/UjY8+8Hg8r8aSv4YihmNh3Ev/uIW21hrC8aXMEgVo0H51Q+g==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
@@ -498,9 +498,9 @@
} }
}, },
"node_modules/@rspress/plugin-sitemap": { "node_modules/@rspress/plugin-sitemap": {
"version": "2.1.2", "version": "2.1.3",
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.1.2.tgz", "resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.1.3.tgz",
"integrity": "sha512-qF9NDLLJORa7MM8QY/etgMlrXM8hlArNaK5ntiFimqtKRoF1YTJQSKPsAfMq2PvYrpQJyEqsSg6wJ+r+lyjNlw==", "integrity": "sha512-Fqo7/4PfQK1ecHUFoUDMrR/E+Hcu+kIohxSs8QabflMy3dqk+M3ZqzJDOHpVYB+HLLGwKiqkPLT4BK+W93clkw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
@@ -511,9 +511,9 @@
} }
}, },
"node_modules/@rspress/shared": { "node_modules/@rspress/shared": {
"version": "2.1.2", "version": "2.1.3",
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.2.tgz", "resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.3.tgz",
"integrity": "sha512-W34tT1fdP3PrdbXpZNKqOGZMOw+RYL70Z9vnkbT1HTTbtX4uMIDE+SU7ByihG0S0LYBsT3kPxA2cXj696253Uw==", "integrity": "sha512-VwJ7kgsTWVqHzSXQVHIUCsdMparmq9b/IDmTa3a6jMPl1zmm5Qg9M0eP4j8JXWoIS9n19XtCkQcZmMTFOPRy3A==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
+1 -1
View File
@@ -10,7 +10,7 @@
[toolchain] [toolchain]
profile = "minimal" profile = "minimal"
channel = "1.99.1" channel = "1.100.0"
components = [ components = [
# For rust-analyzer # For rust-analyzer
"rust-src", "rust-src",
+6 -2
View File
@@ -1007,7 +1007,7 @@ impl crate::Context<'_> {
pub(super) async fn memory_stats(&self, opts: Option<String>) -> Result { pub(super) async fn memory_stats(&self, opts: Option<String>) -> Result {
const OPTS: &str = "abcdefghijklmnopqrstuvwxyz"; const OPTS: &str = "abcdefghijklmnopqrstuvwxyz";
let opts: String = OPTS let mut mapped_opts: String = OPTS
.chars() .chars()
.filter(|&c| { .filter(|&c| {
let allow_any = opts.as_ref().is_some_and(|opts| opts == "*"); let allow_any = opts.as_ref().is_some_and(|opts| opts == "*");
@@ -1018,7 +1018,11 @@ impl crate::Context<'_> {
}) })
.collect(); .collect();
let stats = conduwuit::alloc::memory_stats(&opts).unwrap_or_default(); if opts.as_ref().is_some_and(|opts| opts.contains('J')) {
mapped_opts.push('J');
}
let stats = conduwuit::alloc::memory_stats(&mapped_opts).unwrap_or_default();
self.write_str("```\n").await?; self.write_str("```\n").await?;
self.write_str(&stats).await?; self.write_str(&stats).await?;
+2 -1
View File
@@ -192,7 +192,8 @@ pub enum DebugCommand {
/// ///
/// Optional argument is a character mask (a sequence of characters in any /// Optional argument is a character mask (a sequence of characters in any
/// order) which enable additional extended statistics. Known characters are /// order) which enable additional extended statistics. Known characters are
/// "abdeglmx". For convenience, a '*' will enable everything. /// "abdeglmx" and 'J' for JSON output. For convenience, a '*' will enable
/// everything.
MemoryStats { MemoryStats {
opts: Option<String>, opts: Option<String>,
}, },
+2 -2
View File
@@ -142,11 +142,11 @@ impl crate::Context<'_> {
.await?; .await?;
self.write_str("| ------ | ---------- | --------------------------- |\n") self.write_str("| ------ | ---------- | --------------------------- |\n")
.await?; .await?;
for (key_id, key) in &response.verify_keys { for (key_id, key) in &response.parsed.verify_keys {
self.write_str(&format!("| {key_id} | {} | |\n", key.key)) self.write_str(&format!("| {key_id} | {} | |\n", key.key))
.await?; .await?;
} }
for (key_id, old_key) in &response.old_verify_keys { for (key_id, old_key) in &response.parsed.old_verify_keys {
self.write_str(&format!( self.write_str(&format!(
"| {key_id} | {} | {:0<13} |\n", "| {key_id} | {} | {:0<13} |\n",
old_key.key, old_key.key,
+1
View File
@@ -2,6 +2,7 @@
#![allow(clippy::wildcard_imports)] #![allow(clippy::wildcard_imports)]
#![allow(clippy::enum_glob_use)] #![allow(clippy::enum_glob_use)]
#![allow(clippy::too_many_arguments)] #![allow(clippy::too_many_arguments)]
#![allow(clippy::large_unopt_stack_frames, reason = "very large Subcommand macro expansions")]
conduwuit_macros::introspect_crate! {} conduwuit_macros::introspect_crate! {}
+1
View File
@@ -87,6 +87,7 @@ serde.workspace = true
sha1.workspace = true sha1.workspace = true
tokio.workspace = true tokio.workspace = true
tracing.workspace = true tracing.workspace = true
wildmatch.workspace = true
[lints] [lints]
workspace = true workspace = true
+10 -4
View File
@@ -1,7 +1,7 @@
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
use axum::extract::State; use axum::extract::State;
use conduwuit::{Result, Server}; use conduwuit::{Result, Server, config::experiments::ToggledExperiment};
use ruma::{ use ruma::{
RoomVersionId, RoomVersionId,
api::{ api::{
@@ -53,8 +53,11 @@ pub(crate) async fn get_capabilities_route(
capabilities.account_moderation.lock = true; capabilities.account_moderation.lock = true;
capabilities.account_moderation.suspend = true; capabilities.account_moderation.suspend = true;
capabilities.admin = if services.config.experiments.msc4484.is_enabled() {
AdminCapability::new(BTreeSet::from_iter([OAuthClientScope::ServerAdministration])); capabilities.admin = AdminCapability::new(BTreeSet::from_iter([
OAuthClientScope::ServerAdministration,
]));
}
} }
capabilities.profile_fields = Some( capabilities.profile_fields = Some(
@@ -63,7 +66,10 @@ pub(crate) async fn get_capabilities_route(
capabilities.set( capabilities.set(
"org.matrix.msc4174.webpush", "org.matrix.msc4174.webpush",
json!({ "enabled": true, "vapid": services.pusher.webpush_vapid_public_key() }), json!({
"enabled": services.config.experiments.msc4174.is_enabled(),
"vapid": services.pusher.webpush_vapid_public_key()
}),
)?; )?;
Ok(get_capabilities::v3::Response::new(capabilities)) Ok(get_capabilities::v3::Response::new(capabilities))
+1 -2
View File
@@ -15,8 +15,7 @@ use ruma::{
OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId,
api::{ api::{
client::keys::{ client::keys::{
claim_keys, get_key_changes, get_keys, upload_keys, claim_keys, get_key_changes, get_keys, upload_keys, upload_signatures,
upload_signatures::{self},
upload_signing_keys, upload_signing_keys,
}, },
federation, federation,
+1 -4
View File
@@ -16,10 +16,7 @@ use futures::{FutureExt, StreamExt};
use ruma::{ use ruma::{
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedServerName, CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedServerName,
OwnedUserId, RoomId, UserId, OwnedUserId, RoomId, UserId,
api::{ api::{client::knock::knock_room, federation},
client::knock::knock_room,
federation::{self},
},
canonical_json::to_canonical_value, canonical_json::to_canonical_value,
events::{ events::{
StateEventType, StateEventType,
+1 -4
View File
@@ -10,10 +10,7 @@ use conduwuit::{
use futures::{FutureExt, StreamExt, pin_mut}; use futures::{FutureExt, StreamExt, pin_mut};
use ruma::{ use ruma::{
CanonicalJsonObject, CanonicalJsonValue, OwnedServerName, RoomId, UserId, CanonicalJsonObject, CanonicalJsonValue, OwnedServerName, RoomId, UserId,
api::{ api::{client::membership::leave_room, federation},
client::membership::leave_room,
federation::{self},
},
events::{ events::{
StateEventType, StateEventType,
room::member::{MembershipState, RoomMemberEventContent}, room::member::{MembershipState, RoomMemberEventContent},
+1 -1
View File
@@ -9,7 +9,7 @@ use conduwuit::{
use futures::{FutureExt, StreamExt, future::join}; use futures::{FutureExt, StreamExt, future::join};
use ruma::{ use ruma::{
api::client::membership::{ api::client::membership::{
get_member_events::{self}, get_member_events,
joined_members::{self, v3::RoomMember}, joined_members::{self, v3::RoomMember},
}, },
events::{ events::{
+21 -11
View File
@@ -1,6 +1,8 @@
use axum::extract::State; use axum::extract::State;
use conduwuit::{ use conduwuit::{
Err, Error, Result, at, debug_warn, Err, Error, Result, at,
config::experiments::ToggledExperiment,
debug_warn,
matrix::{ matrix::{
event::{Event, Matches}, event::{Event, Matches},
pdu::PduCount, pdu::PduCount,
@@ -315,21 +317,29 @@ where
if server_ignored { if server_ignored {
// the sender's server is ignored, so ignore this event // the sender's server is ignored, so ignore this event
return Err(Error::BadRequest( return if services.config.experiments.msc4406.is_enabled() {
ErrorKind::SenderIgnored(SenderIgnoredErrorData::new()), Err(Error::BadRequest(
"The sender's server is ignored by this server.", ErrorKind::SenderIgnored(SenderIgnoredErrorData::new()),
)); "The sender's server is ignored by this server.",
))
} else {
Err!(Request(NotFound("This event's sender's homeserver is ignored by this server.")))
};
} }
if user_ignored && !services.config.send_messages_from_ignored_users_to_client { if user_ignored && !services.config.send_messages_from_ignored_users_to_client {
// the recipient of this PDU has the sender ignored, and we're not // the recipient of this PDU has the sender ignored, and we're not
// configured to send ignored messages to clients // configured to send ignored messages to clients
return Err(Error::BadRequest( return if services.config.experiments.msc4406.is_enabled() {
ErrorKind::SenderIgnored(SenderIgnoredErrorData::with_sender( Err(Error::BadRequest(
event.sender().to_owned(), ErrorKind::SenderIgnored(SenderIgnoredErrorData::with_sender(
)), event.sender().to_owned(),
"You have ignored this sender.", )),
)); "You have ignored this sender.",
))
} else {
Err!(Request(NotFound("You have ignored the sender of this event.")))
};
} }
Ok(false) Ok(false)
+2
View File
@@ -23,6 +23,7 @@ pub(super) mod push;
pub(super) mod read_marker; pub(super) mod read_marker;
pub(super) mod redact; pub(super) mod redact;
pub(super) mod relations; pub(super) mod relations;
pub(super) mod rendezvous;
pub(super) mod report; pub(super) mod report;
pub(super) mod room; pub(super) mod room;
pub(super) mod search; pub(super) mod search;
@@ -69,6 +70,7 @@ pub(super) use push::*;
pub(super) use read_marker::*; pub(super) use read_marker::*;
pub(super) use redact::*; pub(super) use redact::*;
pub(super) use relations::*; pub(super) use relations::*;
pub(super) use rendezvous::*;
pub(super) use report::*; pub(super) use report::*;
pub(super) use room::*; pub(super) use room::*;
pub(super) use search::*; pub(super) use search::*;
+76
View File
@@ -0,0 +1,76 @@
use axum::extract::State;
use conduwuit::{Err, Result};
use http::HeaderMap;
use ruma::api::client::rendezvous::{
create_rendezvous_session, delete_rendezvous_session, discover_rendezvous,
get_rendezvous_session, update_rendezvous_session,
};
use service::Services;
use crate::{Ruma, router::ClientIdentity};
/// `GET /_matrix/client/msc4388/io.element.msc4388/rendezvous`
pub(crate) async fn discover_rendezvous_route(
State(services): State<crate::State>,
body: Ruma<discover_rendezvous::msc4388::Request>,
) -> Result<discover_rendezvous::msc4388::Response> {
Ok(discover_rendezvous::msc4388::Response::new(rendezvous_available(
&services,
body.identity.as_ref(),
)))
}
/// `POST /_matrix/client/msc4388/io.element.msc4388/rendezvous/`
pub(crate) async fn create_rendezvous_session_route(
State(services): State<crate::State>,
body: Ruma<create_rendezvous_session::msc4388::Request>,
) -> Result<create_rendezvous_session::msc4388::Response> {
if !rendezvous_available(&services, body.identity.as_ref()) {
return Err!(Request(Forbidden("You are not authorized to create a rendezvous session")));
}
services.rendezvous.create_session(body.data.clone())
}
/// `PUT /_matrix/client/msc4388/io.element.msc4388/rendezvous/{id}/{txn_id}`
pub(crate) async fn update_rendezvous_session_route(
State(services): State<crate::State>,
body: Ruma<update_rendezvous_session::msc4388::Request>,
) -> Result<update_rendezvous_session::msc4388::Response> {
services.rendezvous.update_session(
&body.id,
body.txn_id.clone(),
body.sequence_token.clone(),
body.data.clone(),
)
}
/// `GET /_matrix/client/msc4388/io.element.msc4388/rendezvous/{id}`
pub(crate) async fn get_rendezvous_session_route(
State(services): State<crate::State>,
headers: HeaderMap,
body: Ruma<get_rendezvous_session::msc4388::Request>,
) -> Result<get_rendezvous_session::msc4388::Response> {
if let Some(mode) = headers.get("Sec-Fetch-Mode")
&& let Ok(mode) = mode.to_str()
&& mode == "navigate"
{
return Err!(Request(Forbidden(
"Rendezvous sessions do not accept browser navigation requests."
)));
}
services.rendezvous.get_session(&body.id)
}
/// `DELETE /_matrix/client/msc4388/io.element.msc4388/rendezvous/{id}`
pub(crate) async fn delete_rendezvous_session_route(
State(services): State<crate::State>,
body: Ruma<delete_rendezvous_session::msc4388::Request>,
) -> Result<delete_rendezvous_session::msc4388::Response> {
services.rendezvous.delete_session(&body.id)
}
fn rendezvous_available(services: &Services, identity: Option<&ClientIdentity>) -> bool {
!services.config.require_auth_for_rendezvous || identity.is_some()
}
+1 -1
View File
@@ -77,7 +77,7 @@ struct FullCreationContent {
/// - Send events listed in initial state /// - Send events listed in initial state
/// - Send events implied by `name` and `topic` /// - Send events implied by `name` and `topic`
/// - Send invite events /// - Send invite events
#[allow(clippy::large_stack_frames)] #[allow(clippy::large_unopt_stack_frames)]
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
pub(crate) async fn create_room_route( pub(crate) async fn create_room_route(
State(services): State<crate::State>, State(services): State<crate::State>,
+1 -2
View File
@@ -94,8 +94,7 @@ pub(crate) async fn room_initial_sync_route(
.first() .first()
.map(at!(0)) .map(at!(0))
.as_ref() .as_ref()
.map(ToString::to_string) .map_or_default(ToString::to_string);
.unwrap_or_default();
let start = events.last().map(at!(0)).as_ref().map(ToString::to_string); let start = events.last().map(at!(0)).as_ref().map(ToString::to_string);
let chunk = events let chunk = events
+76 -54
View File
@@ -64,7 +64,7 @@ pub(super) async fn load_joined_room(
services: &Services, services: &Services,
sync_context: SyncContext<'_>, sync_context: SyncContext<'_>,
ref room_id: OwnedRoomId, ref room_id: OwnedRoomId,
) -> Result<(JoinedRoom, DeviceListUpdates)> { ) -> Result<JoinedRoom> {
/* /*
Building a sync response involves many steps which all depend on each other. Building a sync response involves many steps which all depend on each other.
To parallelize the process as much as possible, each step is divided into its own function, To parallelize the process as much as possible, each step is divided into its own function,
@@ -80,7 +80,6 @@ pub(super) async fn load_joined_room(
sticky, sticky,
summary, summary,
notification_counts, notification_counts,
device_list_updates,
}, },
) = try_join3( ) = try_join3(
build_account_data(services, sync_context, room_id), build_account_data(services, sync_context, room_id),
@@ -117,7 +116,7 @@ pub(super) async fn load_joined_room(
unread_thread_notifications: BTreeMap::new(), unread_thread_notifications: BTreeMap::new(),
}); });
Ok((joined_room, device_list_updates)) Ok(joined_room)
} }
/// Collect changes to the syncing user's account data events. /// Collect changes to the syncing user's account data events.
@@ -263,7 +262,6 @@ struct StateAndTimeline {
sticky: Sticky, sticky: Sticky,
summary: Option<RoomSummary>, summary: Option<RoomSummary>,
notification_counts: Option<UnreadNotificationsCount>, notification_counts: Option<UnreadNotificationsCount>,
device_list_updates: DeviceListUpdates,
} }
async fn build_sticky_events( async fn build_sticky_events(
@@ -377,24 +375,14 @@ async fn build_state_and_timeline(
debug_warn!("timeline for newly joined room is empty"); debug_warn!("timeline for newly joined room is empty");
} }
let (summary, device_list_updates) = try_join( let summary = build_room_summary(
build_room_summary( services,
services, sync_context,
sync_context, room_id,
room_id, shortstatehashes,
shortstatehashes, &timeline,
&timeline, &state_events,
&state_events, joined_since_last_sync,
joined_since_last_sync,
),
build_device_list_updates(
services,
sync_context,
room_id,
shortstatehashes,
&state_events,
joined_since_last_sync,
),
) )
.await?; .await?;
@@ -430,7 +418,6 @@ async fn build_state_and_timeline(
sticky, sticky,
summary, summary,
notification_counts, notification_counts,
device_list_updates,
}) })
} }
@@ -800,8 +787,7 @@ async fn build_room_summary(
Ok(Some(assign!(RoomSummary::new(), { Ok(Some(assign!(RoomSummary::new(), {
heroes: heroes heroes: heroes
.map(|heroes| heroes.into_iter().collect()) .map_or_default(|heroes| heroes.into_iter().collect()),
.unwrap_or_default(),
joined_member_count: Some(ruma_from_u64(joined_member_count)), joined_member_count: Some(ruma_from_u64(joined_member_count)),
invited_member_count: Some(ruma_from_u64(invited_member_count)), invited_member_count: Some(ruma_from_u64(invited_member_count)),
}))) })))
@@ -854,35 +840,34 @@ async fn build_heroes(
.await .await
} }
/// Collect updates to users' device lists for E2EE. /// Collect updates to users' device lists for E2EE in a joined room.
#[tracing::instrument(level = "debug", skip_all)] #[tracing::instrument(level = "debug", skip_all, fields(%room_id))]
async fn build_device_list_updates( pub(super) async fn load_device_list_updates(
services: &Services, services: &Services,
SyncContext { sync_context: SyncContext<'_>,
room_id: &RoomId,
) -> Result<DeviceListUpdates> {
let SyncContext {
syncing_user, syncing_user,
last_sync_end_count, last_sync_end_count,
current_count, current_count,
.. ..
}: SyncContext<'_>, } = sync_context;
room_id: &RoomId,
ShortStateHashes { current_shortstatehash, .. }: ShortStateHashes, let mut device_list_updates = DeviceListUpdates::new();
state_events: &Vec<PduEvent>,
joined_since_last_sync: bool,
) -> Result<DeviceListUpdates> {
let is_encrypted_room = services
.rooms
.state_accessor
.state_get(current_shortstatehash, &StateEventType::RoomEncryption, "")
.is_ok();
// initial syncs don't include device updates, and rooms which aren't // initial syncs don't include device updates, and rooms which aren't
// encrypted don't affect them, so return early in either of those cases // encrypted don't affect them, so return early in either of those cases
if last_sync_end_count.is_none() || !(is_encrypted_room.await) { if last_sync_end_count.is_none()
return Ok(DeviceListUpdates::new()); || !services
.rooms
.state_accessor
.is_encrypted_room(room_id)
.await
{
return Ok(device_list_updates);
} }
let mut device_list_updates = DeviceListUpdates::new();
// add users with changed keys to the `changed` list // add users with changed keys to the `changed` list
services services
.users .users
@@ -893,19 +878,56 @@ async fn build_device_list_updates(
}) })
.await; .await;
// add users who now share encrypted rooms to `changed` and let shortstatehashes = fetch_shortstatehashes(services, sync_context, room_id).await?;
// users who no longer share encrypted rooms to `left` let ShortStateHashes {
for state_event in state_events { current_shortstatehash,
if state_event.kind == RoomMember { last_sync_end_shortstatehash,
let Some(content): Option<RoomMemberEventContent> = state_event.get_content().ok() } = shortstatehashes;
if check_joined_since_last_sync(services, shortstatehashes, sync_context).await? {
// the syncing user now shares an encrypted room with every member
services
.rooms
.state_cache
.room_members(room_id)
.ready_for_each(|user_id| {
device_list_updates.changed.insert(user_id);
})
.await;
} else if let Some(last_sync_end_shortstatehash) = last_sync_end_shortstatehash
&& last_sync_end_shortstatehash != current_shortstatehash
{
// add users who now share encrypted rooms to `changed` and
// users who no longer share encrypted rooms to `left`
let state_added = services
.rooms
.state_accessor
.state_added((last_sync_end_shortstatehash, current_shortstatehash))
.await?;
for (shortstatekey, _) in state_added {
let Ok((StateEventType::RoomMember, state_key)) = services
.rooms
.short
.get_statekey_from_short(shortstatekey)
.await
else { else {
continue; continue;
}; };
let Some(user_id): Option<OwnedUserId> = state_event let Ok(user_id) = OwnedUserId::try_from(state_key.as_str()) else {
.state_key continue;
.as_ref() };
.and_then(|key| key.parse().ok())
let Ok(content): Result<RoomMemberEventContent> = services
.rooms
.state_accessor
.state_get_content(
current_shortstatehash,
&StateEventType::RoomMember,
user_id.as_str(),
)
.await
else { else {
continue; continue;
}; };
@@ -921,7 +943,7 @@ async fn build_device_list_updates(
| Leave if !shares_encrypted_room => { | Leave if !shares_encrypted_room => {
device_list_updates.left.insert(user_id); device_list_updates.left.insert(user_id);
}, },
| Join if joined_since_last_sync || shares_encrypted_room => { | Join if shares_encrypted_room => {
device_list_updates.changed.insert(user_id); device_list_updates.changed.insert(user_id);
}, },
| _ => (), | _ => (),
+117 -21
View File
@@ -3,7 +3,6 @@ mod left;
mod state; mod state;
use std::{ use std::{
cmp::{self},
collections::{BTreeMap, HashMap, HashSet}, collections::{BTreeMap, HashMap, HashSet},
time::Duration, time::Duration,
}; };
@@ -21,7 +20,7 @@ use futures::{FutureExt, StreamExt, TryFutureExt, future::OptionFuture};
use ruma::{ use ruma::{
DeviceId, OwnedUserId, RoomId, UserId, DeviceId, OwnedUserId, RoomId, UserId,
api::client::{ api::client::{
filter::FilterDefinition, filter::{self, FilterDefinition, RoomFilter},
sync::sync_events::{ sync::sync_events::{
self, DeviceLists, self, DeviceLists,
v3::{ v3::{
@@ -39,13 +38,17 @@ use service::{
account_data::AnyRawAccountDataEvent, account_data::AnyRawAccountDataEvent,
rooms::lazy_loading::{self, MemberSet, Options as _}, rooms::lazy_loading::{self, MemberSet, Options as _},
}; };
use wildmatch::WildMatch;
use super::{load_timeline, share_encrypted_room}; use super::{load_timeline, share_encrypted_room};
use crate::{ use crate::{
Ruma, Ruma,
client::{ client::{
is_ignored_invite, is_ignored_invite,
sync::v3::{joined::load_joined_room, left::load_left_room}, sync::v3::{
joined::{load_device_list_updates, load_joined_room},
left::load_left_room,
},
}, },
client_ip::ClientIp, client_ip::ClientIp,
}; };
@@ -203,7 +206,12 @@ pub(crate) async fn sync_events_route(
let mut wake_receiver = services.sync.subscribe_to_wake(sender_user); let mut wake_receiver = services.sync.subscribe_to_wake(sender_user);
let response = build_sync_events(&services, &body).await?; let response = build_sync_events(&services, &body).await?;
if body.body.full_state
let timeout_duration = body.body.timeout.unwrap_or_default();
// If the timeout is zero, request has full_state=true, or there's
// meaningful data to return, do so immediately.
if timeout_duration.is_zero()
|| body.body.full_state
|| !(response.rooms.is_empty() || !(response.rooms.is_empty()
&& response.presence.is_empty() && response.presence.is_empty()
&& response.account_data.is_empty() && response.account_data.is_empty()
@@ -213,11 +221,15 @@ pub(crate) async fn sync_events_route(
return Ok(response); return Ok(response);
} }
// Hang a few seconds so requests are not spammed // Otherwise, wait for a wake signal to rebuild changes. Cap timeout at 30
// Stop hanging if new info arrives // seconds (this isn't specced, but a reasonable cap since most clients have
let default = Duration::from_secs(30); // a 30-second polling interval).
let duration = cmp::min(body.body.timeout.unwrap_or(default), default); let duration = timeout_duration.min(Duration::from_secs(30));
_ = tokio::time::timeout(duration, wake_receiver.changed()).await; let mut shutdown_signal = services.server.signal.subscribe();
tokio::select! {
_ = tokio::time::timeout(duration, wake_receiver.changed()) => {},
_ = shutdown_signal.recv() => return Err!(Request(Unknown("Server is shutting down"), SERVICE_UNAVAILABLE)),
};
// Retry returning data // Retry returning data
build_sync_events(&services, &body).await build_sync_events(&services, &body).await
@@ -271,34 +283,47 @@ pub(crate) async fn build_sync_events(
.rooms .rooms
.state_cache .state_cache
.rooms_joined(syncing_user) .rooms_joined(syncing_user)
.ready_filter(|room_id| room_selected(&filter.room, room_id))
.broad_filter_map(|room_id| async { .broad_filter_map(|room_id| async {
let joined_room = load_joined_room(services, context, room_id.clone()).await; let joined_room = load_joined_room(services, context, room_id.clone()).await;
match joined_room { match joined_room {
| Ok((room, updates)) => Some((room_id, room, updates)), | Ok(room) => Some((room_id, room)),
| Err(err) => { | Err(err) => {
error!(?err, %room_id, "error loading joined room"); error!(?err, %room_id, "error loading joined room");
None None
}, },
} }
}) })
.ready_fold( .ready_fold(BTreeMap::new(), |mut joined_rooms, (room_id, joined_room)| {
(BTreeMap::new(), DeviceListUpdates::new()), if !joined_room.is_empty() {
|(mut joined_rooms, mut all_updates), (room_id, joined_room, updates)| { joined_rooms.insert(room_id, joined_room);
all_updates.merge(updates); }
if !joined_room.is_empty() { joined_rooms
joined_rooms.insert(room_id, joined_room); });
}
(joined_rooms, all_updates) // a filtered out room still contributes its device list updates
}, let device_list_updates = services
); .rooms
.state_cache
.rooms_joined(syncing_user)
.broad_filter_map(|room_id| async move {
load_device_list_updates(services, context, &room_id)
.await
.inspect_err(|err| error!(?err, %room_id, "error loading device list updates"))
.ok()
})
.ready_fold(DeviceListUpdates::new(), |mut all_updates, updates| {
all_updates.merge(updates);
all_updates
});
let left_rooms = services let left_rooms = services
.rooms .rooms
.state_cache .state_cache
.rooms_left(syncing_user) .rooms_left(syncing_user)
.ready_filter(|(room_id, _)| room_selected(&filter.room, room_id))
.broad_filter_map(|(room_id, leave_pdu)| async { .broad_filter_map(|(room_id, leave_pdu)| async {
let left_room = load_left_room(services, context, room_id.clone(), leave_pdu).await; let left_room = load_left_room(services, context, room_id.clone(), leave_pdu).await;
@@ -317,6 +342,7 @@ pub(crate) async fn build_sync_events(
.rooms .rooms
.state_cache .state_cache
.rooms_invited(syncing_user) .rooms_invited(syncing_user)
.ready_filter(|(room_id, _)| room_selected(&filter.room, room_id))
.wide_filter_map(async |(room_id, invite_state)| { .wide_filter_map(async |(room_id, invite_state)| {
if is_ignored_invite(services, syncing_user, &room_id).await { if is_ignored_invite(services, syncing_user, &room_id).await {
None None
@@ -347,6 +373,7 @@ pub(crate) async fn build_sync_events(
.rooms .rooms
.state_cache .state_cache
.rooms_knocked(syncing_user) .rooms_knocked(syncing_user)
.ready_filter(|(room_id, _)| room_selected(&filter.room, room_id))
.fold_default(|mut knocked_rooms: BTreeMap<_, _>, (room_id, knock_state)| async move { .fold_default(|mut knocked_rooms: BTreeMap<_, _>, (room_id, knock_state)| async move {
let knock_count = services let knock_count = services
.rooms .rooms
@@ -376,6 +403,13 @@ pub(crate) async fn build_sync_events(
.account_data .account_data
.changes_since(None, syncing_user, last_sync_end_count, Some(current_count)) .changes_since(None, syncing_user, last_sync_end_count, Some(current_count))
.ready_filter_map(|e| extract_variant!(e, AnyRawAccountDataEvent::Global)) .ready_filter_map(|e| extract_variant!(e, AnyRawAccountDataEvent::Global))
.ready_filter(|event| {
event
.get_field::<String>("type")
.ok()
.flatten()
.is_some_and(|event_type| type_selected(&filter.account_data, &event_type))
})
.collect(); .collect();
let to_device_events = services let to_device_events = services
@@ -404,7 +438,8 @@ pub(crate) async fn build_sync_events(
.list_unused_fallback_key_types(syncing_user, syncing_device); .list_unused_fallback_key_types(syncing_user, syncing_device);
let ( let (
(joined_rooms, mut device_list_updates), joined_rooms,
mut device_list_updates,
left_rooms, left_rooms,
invited_rooms, invited_rooms,
knocked_rooms, knocked_rooms,
@@ -417,6 +452,7 @@ pub(crate) async fn build_sync_events(
) = async { ) = async {
futures::join!( futures::join!(
joined_rooms, joined_rooms,
device_list_updates,
left_rooms, left_rooms,
invited_rooms, invited_rooms,
knocked_rooms, knocked_rooms,
@@ -465,6 +501,24 @@ pub(crate) async fn build_sync_events(
Ok(response) Ok(response)
} }
fn room_selected(filter: &RoomFilter, room_id: &RoomId) -> bool {
!filter.not_rooms.iter().any(|not_room| not_room == room_id)
&& filter
.rooms
.as_ref()
.is_none_or(|rooms| rooms.iter().any(|room| room == room_id))
}
fn type_selected(filter: &filter::Filter, event_type: &str) -> bool {
let matches = |pattern: &String| WildMatch::new(pattern).matches(event_type);
!filter.not_types.iter().any(matches)
&& filter
.types
.as_ref()
.is_none_or(|types| types.iter().any(matches))
}
#[tracing::instrument(name = "presence", level = "debug", skip_all)] #[tracing::instrument(name = "presence", level = "debug", skip_all)]
async fn process_presence_updates( async fn process_presence_updates(
services: &Services, services: &Services,
@@ -528,3 +582,45 @@ async fn prepare_lazily_loaded_members(
lazily_loaded_members lazily_loaded_members
} }
#[cfg(test)]
mod tests {
use ruma::{owned_room_id, room_id};
use super::*;
#[test]
fn rooms_filter_selects_rooms() {
let room_id = room_id!("!a:example.com");
let mut filter = RoomFilter::default();
assert!(room_selected(&filter, room_id));
filter.rooms = Some(Vec::new());
assert!(!room_selected(&filter, room_id));
filter.rooms = Some(vec![room_id.to_owned()]);
assert!(room_selected(&filter, room_id));
filter.not_rooms = vec![owned_room_id!("!a:example.com")];
assert!(!room_selected(&filter, room_id));
}
#[test]
fn types_filter_selects_account_data() {
let mut filter = filter::Filter::default();
assert!(type_selected(&filter, "m.direct"));
filter.types = Some(Vec::new());
assert!(!type_selected(&filter, "m.direct"));
filter.types = Some(vec!["m.direct".to_owned()]);
assert!(type_selected(&filter, "m.direct"));
filter.types = Some(vec!["m.*".to_owned()]);
assert!(type_selected(&filter, "m.direct"));
assert!(!type_selected(&filter, "im.ponies.user_emotes"));
filter.not_types = vec!["m.direct".to_owned()];
assert!(!type_selected(&filter, "m.direct"));
}
}
+1 -3
View File
@@ -5,9 +5,7 @@ use conduwuit::{
}; };
use futures::{FutureExt, StreamExt, pin_mut}; use futures::{FutureExt, StreamExt, pin_mut};
use ruma::{ use ruma::{
api::client::user_directory::search_users::{self}, api::client::user_directory::search_users, assign, events::room::join_rules::JoinRule,
assign,
events::room::join_rules::JoinRule,
}; };
use crate::Ruma; use crate::Ruma;
+19 -7
View File
@@ -10,7 +10,7 @@ use axum::{
response::{IntoResponse, Redirect}, response::{IntoResponse, Redirect},
routing::{any, get}, routing::{any, get},
}; };
use conduwuit::err; use conduwuit::{config::experiments::ToggledExperiment, err};
pub(super) use conduwuit_service::state::State; pub(super) use conduwuit_service::state::State;
use http::{Uri, uri}; use http::{Uri, uri};
@@ -162,10 +162,6 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
.ruma_route(&client::update_device_route) .ruma_route(&client::update_device_route)
.ruma_route(&client::delete_device_route) .ruma_route(&client::delete_device_route)
.ruma_route(&client::delete_devices_route) .ruma_route(&client::delete_devices_route)
.ruma_route(&client::put_dehydrated_device_route)
.ruma_route(&client::delete_dehydrated_device_route)
.ruma_route(&client::get_dehydrated_device_route)
.ruma_route(&client::get_dehydrated_events_route)
.ruma_route(&client::get_tags_route) .ruma_route(&client::get_tags_route)
.ruma_route(&client::update_tag_route) .ruma_route(&client::update_tag_route)
.ruma_route(&client::delete_tag_route) .ruma_route(&client::delete_tag_route)
@@ -184,7 +180,6 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
.ruma_route(&client::get_mutual_rooms_unstable_route) .ruma_route(&client::get_mutual_rooms_unstable_route)
.ruma_route(&client::get_mutual_rooms_route) .ruma_route(&client::get_mutual_rooms_route)
.ruma_route(&client::get_room_summary) .ruma_route(&client::get_room_summary)
.ruma_route(&client::get_stripped_state_route)
.ruma_route(&client::get_suspended_status) .ruma_route(&client::get_suspended_status)
.ruma_route(&client::put_suspended_status) .ruma_route(&client::put_suspended_status)
.ruma_route(&client::get_lock_status) .ruma_route(&client::get_lock_status)
@@ -194,11 +189,26 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
.ruma_route(&client::well_known_policy_server) .ruma_route(&client::well_known_policy_server)
.ruma_route(&client::get_rtc_transports) .ruma_route(&client::get_rtc_transports)
.ruma_route(&client::room_initial_sync_route) .ruma_route(&client::room_initial_sync_route)
.ruma_route(&client::discover_rendezvous_route)
.ruma_route(&client::create_rendezvous_session_route)
.ruma_route(&client::update_rendezvous_session_route)
.ruma_route(&client::get_rendezvous_session_route)
.ruma_route(&client::delete_rendezvous_session_route)
.ruma_route(&client::get_authorization_server_metadata_route) .ruma_route(&client::get_authorization_server_metadata_route)
.merge(client::oauth::router(state)) .merge(client::oauth::router(state))
.route("/_continuwuity/server_version", get(client::continuwuity_server_version)) .route("/_continuwuity/server_version", get(client::continuwuity_server_version))
.ruma_route(&admin::rooms::ban::ban_room) .ruma_route(&admin::rooms::ban::ban_room)
.ruma_route(&admin::rooms::list::list_rooms); .ruma_route(&admin::rooms::list::list_rooms);
if config.experiments.msc3814.is_enabled() {
router = router
.ruma_route(&client::put_dehydrated_device_route)
.ruma_route(&client::delete_dehydrated_device_route)
.ruma_route(&client::get_dehydrated_device_route)
.ruma_route(&client::get_dehydrated_events_route);
}
if config.experiments.msc4560.is_enabled() {
router = router.ruma_route(&client::get_stripped_state_route);
}
if config.allow_prometheus_metrics { if config.allow_prometheus_metrics {
router = router.route("/_continuwuity/metrics", get(client::continuwuity_metrics)); router = router.route("/_continuwuity/metrics", get(client::continuwuity_metrics));
@@ -230,11 +240,13 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
.ruma_route(&server::get_keys_route) .ruma_route(&server::get_keys_route)
.ruma_route(&server::claim_keys_route) .ruma_route(&server::claim_keys_route)
.ruma_route(&server::get_hierarchy_route) .ruma_route(&server::get_hierarchy_route)
.ruma_route(&server::get_stripped_state_route)
.ruma_route(&server::well_known_server) .ruma_route(&server::well_known_server)
.ruma_route(&server::get_content_route) .ruma_route(&server::get_content_route)
.ruma_route(&server::get_content_thumbnail_route) .ruma_route(&server::get_content_thumbnail_route)
.route("/_continuwuity/local_user_count", get(client::continuwuity_local_user_count)); .route("/_continuwuity/local_user_count", get(client::continuwuity_local_user_count));
if config.experiments.msc4560.is_enabled() {
router = router.ruma_route(&server::get_stripped_state_route);
}
} else { } else {
router = router router = router
.route("/_matrix/federation/{*path}", any(federation_disabled)) .route("/_matrix/federation/{*path}", any(federation_disabled))
+13 -9
View File
@@ -5,7 +5,9 @@ use std::{
}; };
use conduwuit::{ use conduwuit::{
Err, Error, Result, err, Err, Error, Result,
config::experiments::ToggledExperiment,
err,
utils::{IterStream, millis_since_unix_epoch}, utils::{IterStream, millis_since_unix_epoch},
}; };
use http::StatusCode; use http::StatusCode;
@@ -338,17 +340,19 @@ async fn check_access_token(
.map(Box::new); .map(Box::new);
// Make sure the user has the right scopes to use the route // Make sure the user has the right scopes to use the route
let user_scopes = if let Some(session_info) = &session_info { let mut user_scopes = if let Some(session_info) = &session_info {
session_info.scopes() session_info.scopes()
} else { } else {
let mut scopes = BTreeSet::from_iter([OAuthClientScope::ApiFullAccess]); BTreeSet::from_iter([OAuthClientScope::ApiFullAccess])
if services.admin.user_is_admin(&sender_user).await {
scopes.insert(OAuthClientScope::ServerAdministration);
}
scopes
}; };
if (!services.config.experiments.msc4484.is_enabled() || session_info.is_none())
&& services.admin.user_is_admin(&sender_user).await
{
// This is required to make sure admin APIs still work when msc4484
// is disabled.
// https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2533#issuecomment-40042
user_scopes.insert(OAuthClientScope::ServerAdministration);
}
if !required_scopes if !required_scopes
.iter() .iter()
+3 -3
View File
@@ -34,7 +34,7 @@ pub(crate) async fn get_server_keys_route(
// We need to verify that this response is still trusted based on // We need to verify that this response is still trusted based on
// the current configuration. It's possible we got this response // the current configuration. It's possible we got this response
// from a notary who we no longer trust. // from a notary who we no longer trust.
if resp.valid_until_ts > in_one_week() { if resp.parsed.valid_until_ts > in_one_week() {
continue; continue;
} }
let trusted = services.config.trusted_servers.iter().any(|notary| { let trusted = services.config.trusted_servers.iter().any(|notary| {
@@ -47,8 +47,8 @@ pub(crate) async fn get_server_keys_route(
if !trusted { if !trusted {
continue; continue;
} }
for (old_key_id, old_key) in resp.old_verify_keys { for (old_key_id, old_key) in resp.parsed.old_verify_keys {
if old_key.expired_ts > resp.valid_until_ts { if old_key.expired_ts > resp.parsed.valid_until_ts {
// This key expired in the future which is probably illegal // This key expired in the future which is probably illegal
continue; continue;
} }
+1 -1
View File
@@ -69,7 +69,7 @@ pub(crate) async fn create_join_event_template_route(
.get_member(&body.room_id, &body.user_id) .get_member(&body.room_id, &body.user_id)
.await .await
.ok() .ok()
.map_or_else(|| MembershipState::Leave, |content| content.membership); .map_or(MembershipState::Leave, |content| content.membership);
let join_authorized_via_users_server: Option<OwnedUserId> = { let join_authorized_via_users_server: Option<OwnedUserId> = {
if matches!( if matches!(
+12 -7
View File
@@ -26,14 +26,19 @@ conduwuit_mods = [
gzip_compression = [ gzip_compression = [
"reqwest/gzip", "reqwest/gzip",
] ]
hardened_malloc = [
"dep:hardened_malloc-rs"
]
jemalloc = [ jemalloc = [
"dep:tikv-jemalloc-sys", "dep:tikv-jemalloc-sys",
"dep:tikv-jemalloc-ctl", "dep:tikv-jemalloc-ctl",
"dep:tikv-jemallocator", "dep:tikv-jemallocator",
] ]
# Uses mimalloc for Rust allocations and, via `override`, exports
# malloc/free/etc. so C/C++ dependencies (RocksDB, zstd, lz4, ...) use it too.
# Mutually exclusive with `jemalloc` on non-MSVC targets.
mimalloc = [
"dep:libmimalloc-sys",
"dep:mimalloc",
"libmimalloc-sys/override",
]
jemalloc_conf = [] jemalloc_conf = []
jemalloc_prof = [ jemalloc_prof = [
"tikv-jemalloc-sys/profiling", "tikv-jemalloc-sys/profiling",
@@ -118,14 +123,14 @@ lock_api.workspace = true
hyper-util.workspace = true hyper-util.workspace = true
resolvematrix.workspace = true resolvematrix.workspace = true
openidconnect.workspace = true openidconnect.workspace = true
libmimalloc-sys.optional = true
libmimalloc-sys.workspace = true
mimalloc.optional = true
mimalloc.workspace = true
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
nix.workspace = true nix.workspace = true
[target.'cfg(all(not(target_env = "msvc"), target_os = "linux"))'.dependencies]
hardened_malloc-rs.workspace = true
hardened_malloc-rs.optional = true
[dev-dependencies] [dev-dependencies]
maplit.workspace = true maplit.workspace = true
opentelemetry_sdk.workspace = true opentelemetry_sdk.workspace = true
+5 -1
View File
@@ -1,5 +1,9 @@
//! Default allocator with no special features //! Default allocator with no special features
use arrayvec::ArrayVec;
pub(crate) fn metric() -> Option<(&'static str, &'static str)> { None }
/// Always returns Ok /// Always returns Ok
pub fn trim<I: Into<Option<usize>>>(_: I) -> crate::Result { Ok(()) } pub fn trim<I: Into<Option<usize>>>(_: I) -> crate::Result { Ok(()) }
@@ -12,4 +16,4 @@ pub fn memory_stats(_opts: &str) -> Option<String> { None }
pub fn memory_usage() -> Option<String> { None } pub fn memory_usage() -> Option<String> { None }
#[must_use] #[must_use]
pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> { None } pub fn memory_usage_stats() -> Option<ArrayVec<(&'static str, usize), 6>> { None }
-18
View File
@@ -1,18 +0,0 @@
//! hmalloc allocator
#[global_allocator]
static HMALLOC: hardened_malloc_rs::HardenedMalloc = hardened_malloc_rs::HardenedMalloc;
pub fn trim<I: Into<Option<usize>>>(_: I) -> crate::Result { Ok(()) }
#[must_use]
//TODO: get usage
pub fn memory_usage() -> Option<String> { None }
#[must_use]
pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> { None }
#[must_use]
pub fn memory_stats(_opts: &str) -> Option<String> {
Some("Extended statistics are not available from hardened_malloc.".to_owned())
}
+448 -148
View File
@@ -1,9 +1,12 @@
//! jemalloc allocator //! jemalloc allocator
use std::{ use std::{
cell::OnceCell, any::Any,
ffi::{CStr, c_char, c_void}, ffi::{CStr, CString, c_char, c_uint, c_void},
fmt::Debug, fmt::Debug,
panic::{self, AssertUnwindSafe},
ptr,
sync::OnceLock,
}; };
use arrayvec::ArrayVec; use arrayvec::ArrayVec;
@@ -12,26 +15,61 @@ use tikv_jemalloc_sys as ffi;
use tikv_jemallocator as jemalloc; use tikv_jemallocator as jemalloc;
use crate::{ use crate::{
Result, SyncRwLock, err, is_equal_to, is_nonzero, Result, err, is_equal_to, is_nonzero,
utils::{math, math::Tried}, utils::{math, math::Tried},
}; };
#[cfg(feature = "jemalloc_conf")] #[cfg(feature = "jemalloc_conf")]
#[unsafe(no_mangle)] #[repr(transparent)]
pub static malloc_conf: &[u8] = const_str::concat_bytes!( struct MallocConf(*const c_char);
// SAFETY: MallocConf points to static immutable NUL-terminated bytes.
#[cfg(feature = "jemalloc_conf")]
unsafe impl Sync for MallocConf {}
#[cfg(feature = "jemalloc_conf")]
const MALLOC_CONF_BYTES: &[u8] = const_str::concat_bytes!(
"lg_extent_max_active_fit:4", "lg_extent_max_active_fit:4",
",oversize_threshold:16777216", ",oversize_threshold:16777216",
",tcache_max:2097152", ",tcache_max:2097152",
",dirty_decay_ms:16000", ",dirty_decay_ms:16000",
",muzzy_decay_ms:144000", ",muzzy_decay_ms:144000",
",percpu_arena:percpu", MALLOC_CONF_PLATFORM,
",metadata_thp:always",
",background_thread:true",
",max_background_threads:-1",
MALLOC_CONF_PROF, MALLOC_CONF_PROF,
0 0
); );
#[cfg(all(feature = "jemalloc_conf", target_os = "linux"))]
const MALLOC_CONF_PLATFORM: &str =
",percpu_arena:percpu,metadata_thp:always,background_thread:true";
#[cfg(all(feature = "jemalloc_conf", not(target_os = "linux")))]
const MALLOC_CONF_PLATFORM: &str = "";
// Targets match `NO_UNPREFIXED_MALLOC_TARGETS` in `tikv-jemalloc-sys` when
// `unprefixed_malloc_on_supported_platforms` is enabled.
#[cfg(feature = "jemalloc_conf")]
#[used]
#[allow(non_upper_case_globals)]
#[cfg_attr(
any(
target_vendor = "apple",
target_env = "musl",
target_os = "android",
target_os = "dragonfly",
),
unsafe(export_name = "_rjem_malloc_conf")
)]
#[cfg_attr(
not(any(
target_vendor = "apple",
target_env = "musl",
target_os = "android",
target_os = "dragonfly",
)),
unsafe(no_mangle)
)]
static malloc_conf: MallocConf = MallocConf(MALLOC_CONF_BYTES.as_ptr().cast());
#[cfg(all(feature = "jemalloc_conf", feature = "jemalloc_prof"))] #[cfg(all(feature = "jemalloc_conf", feature = "jemalloc_prof"))]
const MALLOC_CONF_PROF: &str = ",prof_active:false"; const MALLOC_CONF_PROF: &str = ",prof_active:false";
#[cfg(all(feature = "jemalloc_conf", not(feature = "jemalloc_prof")))] #[cfg(all(feature = "jemalloc_conf", not(feature = "jemalloc_prof")))]
@@ -39,37 +77,56 @@ const MALLOC_CONF_PROF: &str = "";
#[global_allocator] #[global_allocator]
static JEMALLOC: jemalloc::Jemalloc = jemalloc::Jemalloc; static JEMALLOC: jemalloc::Jemalloc = jemalloc::Jemalloc;
static CONTROL: SyncRwLock<()> = SyncRwLock::new(());
type Name = ArrayVec<u8, NAME_MAX>; type Name = ArrayVec<u8, NAME_MAX>;
type Key = ArrayVec<usize, KEY_SEGS>; type Key = ArrayVec<usize, KEY_SEGS>;
const NAME_MAX: usize = 128; const NAME_MAX: usize = 128;
const KEY_SEGS: usize = 8; const KEY_SEGS: usize = 8;
const ARENA_LIMIT: usize = 4095;
const ARENAS_ALL: usize = 4096;
#[ctor::ctor(unsafe)] #[ctor::ctor(unsafe)]
fn _static_initialization() { fn _static_initialization() {
acq_epoch().expect("pre-initialization of jemalloc failed"); let mut epoch: u64 = 0;
acq_epoch().expect("pre-initialization of jemalloc failed"); let mut len = size_of::<u64>();
// SAFETY: Pre-initialize jemalloc before main() without touching Rust TLS
// or unwinding across the constructor boundary.
unsafe {
ffi::mallctl(
c"epoch".as_ptr(),
ptr::from_mut(&mut epoch).cast::<c_void>(),
&raw mut len,
ptr::null_mut(),
0,
);
}
}
pub(crate) fn metric() -> Option<(&'static str, &'static str)> {
Some((
"continuwuity.jemalloc.memory",
"jemalloc memory statistics, when built with jemalloc_stats",
))
} }
#[must_use] #[must_use]
#[cfg(feature = "jemalloc_stats")] #[cfg(feature = "jemalloc_stats")]
pub fn memory_usage() -> Option<String> { pub fn memory_usage() -> Option<String> {
use std::fmt::Write;
let mibs = |input: usize| { let mibs = |input: usize| {
let kibs = input / 1024; let whole = u32::try_from(input / (1024 * 1024)).unwrap_or(u32::MAX);
let kibs = u32::try_from(kibs).unwrap_or_default(); let rem_kibs = u32::try_from((input / 1024) % 1024).unwrap_or_default();
let kibs = f64::from(kibs); f64::from(whole) + f64::from(rem_kibs) / 1024.0
kibs / 1024.0
}; };
let [allocated, active, mapped, metadata, resident, retained] = let mut out = String::new();
memory_usage_stats()?.map(|(_, bytes)| mibs(bytes)); for (name, bytes) in memory_usage_stats()? {
Some(format!( writeln!(out, "{name}: {:.2} MiB", mibs(bytes)).ok()?;
"allocated: {allocated:.2} MiB\nactive: {active:.2} MiB\nmapped: {mapped:.2} \ }
MiB\nmetadata: {metadata:.2} MiB\nresident: {resident:.2} MiB\nretained: {retained:.2} \
MiB\n" Some(out)
))
} }
#[must_use] #[must_use]
@@ -78,184 +135,259 @@ pub fn memory_usage() -> Option<String> { None }
#[must_use] #[must_use]
#[cfg(feature = "jemalloc_stats")] #[cfg(feature = "jemalloc_stats")]
pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> { pub fn memory_usage_stats() -> Option<ArrayVec<(&'static str, usize), 6>> {
use mallctl::stats; use mallctl::stats;
// Acquire the epoch; ensure latest stats are pulled in // Advance the epoch; ensure latest stats are pulled in
acq_epoch().ok()?; inc_epoch().ok()?;
Some([ Some(ArrayVec::from([
("allocated", stats::allocated::read().unwrap_or_default()), ("allocated", stats::allocated::read().unwrap_or_default()),
("active", stats::active::read().unwrap_or_default()), ("active", stats::active::read().unwrap_or_default()),
("mapped", stats::mapped::read().unwrap_or_default()), ("mapped", stats::mapped::read().unwrap_or_default()),
("metadata", stats::metadata::read().unwrap_or_default()), ("metadata", stats::metadata::read().unwrap_or_default()),
("resident", stats::resident::read().unwrap_or_default()), ("resident", stats::resident::read().unwrap_or_default()),
("retained", stats::retained::read().unwrap_or_default()), ("retained", stats::retained::read().unwrap_or_default()),
]) ]))
} }
#[must_use] #[must_use]
#[cfg(not(feature = "jemalloc_stats"))] #[cfg(not(feature = "jemalloc_stats"))]
pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> { None } pub fn memory_usage_stats() -> Option<ArrayVec<(&'static str, usize), 6>> { None }
struct StatsPrintState {
buf: String,
max_len: usize,
panic: Option<Box<dyn Any + Send>>,
}
pub fn memory_stats(opts: &str) -> Option<String> { pub fn memory_stats(opts: &str) -> Option<String> {
const MAX_LENGTH: usize = 1_048_576; const MAX_LENGTH: usize = 1_048_576;
let mut str = String::new(); let opts = CString::new(opts).ok()?;
let opaque = std::ptr::from_mut(&mut str).cast::<c_void>();
let opts_p: *const c_char = std::ffi::CString::new(opts)
.expect("cstring")
.into_raw()
.cast_const();
// Acquire the epoch; ensure latest stats are pulled in let mut state = StatsPrintState {
acq_epoch().ok()?; buf: String::new(),
max_len: MAX_LENGTH,
panic: None,
};
let opaque = ptr::from_mut(&mut state).cast::<c_void>();
// SAFETY: calls malloc_stats_print() with our string instance which must // SAFETY: `state` and `opts` remain live in this frame for the duration of
// remain in this frame. https://docs.rs/tikv-jemalloc-sys/latest/tikv_jemalloc_sys/fn.malloc_stats_print.html // `malloc_stats_print()`, which invokes `malloc_stats_cb` synchronously.
unsafe { ffi::malloc_stats_print(Some(malloc_stats_cb), opaque, opts_p) }; unsafe { ffi::malloc_stats_print(Some(malloc_stats_cb), opaque, opts.as_ptr()) };
str.truncate(MAX_LENGTH); if let Some(payload) = state.panic {
panic::resume_unwind(payload);
}
Some(str) Some(state.buf)
} }
unsafe extern "C" fn malloc_stats_cb(opaque: *mut c_void, msg: *const c_char) { unsafe extern "C" fn malloc_stats_cb(opaque: *mut c_void, msg: *const c_char) {
// SAFETY: we have to trust the opaque points to our String // SAFETY: `opaque` points to `StatsPrintState` on the caller's stack.
let res: &mut String = unsafe { let Some(state) = (unsafe { opaque.cast::<StatsPrintState>().as_mut() }) else {
opaque return;
.cast::<String>()
.as_mut()
.expect("failed to cast void* to &mut String")
}; };
// SAFETY: we have to trust the string is null terminated. if state.panic.is_some() || msg.is_null() || state.buf.len() >= state.max_len {
return;
}
// SAFETY: jemalloc guarantees `msg` is a valid NUL-terminated C string.
let msg = unsafe { CStr::from_ptr(msg) }; let msg = unsafe { CStr::from_ptr(msg) };
let msg = String::from_utf8_lossy(msg.to_bytes()); if let Err(err) = panic::catch_unwind(AssertUnwindSafe(|| {
res.push_str(msg.as_ref()); let msg = String::from_utf8_lossy(msg.to_bytes());
let remaining = state.max_len.saturating_sub(state.buf.len());
if msg.len() <= remaining {
state.buf.push_str(msg.as_ref());
} else {
if let Some(prefix) = msg.get(..msg.floor_char_boundary(remaining)) {
state.buf.push_str(prefix);
}
state.max_len = state.buf.len();
}
})) {
state.panic = Some(err);
}
} }
macro_rules! mallctl { macro_rules! mallctl {
($name:expr_2021) => {{ ($name:literal) => {{
thread_local! { static KEY: OnceLock<Key> = OnceLock::new();
static KEY: OnceCell<Key> = OnceCell::default();
};
KEY.with(|once| { KEY.get_or_init(|| key($name).expect("failed to translate name into mib key"))
once.get_or_init(move || key($name).expect("failed to translate name into mib key"))
.clone()
})
}}; }};
} }
pub mod this_thread { pub mod this_thread {
use super::{Debug, Key, OnceCell, Result, is_nonzero, key, math}; use super::{Debug, Key, OnceLock, Result, c_uint, is_nonzero, key, math};
thread_local! {
static ALLOCATED_BYTES: OnceCell<&'static u64> = const { OnceCell::new() };
static DEALLOCATED_BYTES: OnceCell<&'static u64> = const { OnceCell::new() };
}
pub fn trim() -> Result { decay().and_then(|()| purge()) } pub fn trim() -> Result { decay().and_then(|()| purge()) }
pub fn purge() -> Result { notify(mallctl!("arena.0.purge")) } pub fn purge() -> Result {
// SAFETY: `arena.<i>.purge` is an `arena.<i>.*` notification ctl.
unsafe { notify(mallctl!("arena.0.purge")) }
}
pub fn decay() -> Result { notify(mallctl!("arena.0.decay")) } pub fn decay() -> Result {
// SAFETY: `arena.<i>.decay` is an `arena.<i>.*` notification ctl.
unsafe { notify(mallctl!("arena.0.decay")) }
}
pub fn idle() -> Result { super::notify(&mallctl!("thread.idle")) } pub fn idle() -> Result {
// SAFETY: `thread.idle` is a non-indexed notification ctl.
unsafe { super::notify(mallctl!("thread.idle")) }
}
pub fn flush() -> Result { super::notify(&mallctl!("thread.tcache.flush")) } pub fn flush() -> Result {
// SAFETY: `thread.tcache.flush` is a non-indexed notification ctl.
unsafe { super::notify(mallctl!("thread.tcache.flush")) }
}
pub fn set_muzzy_decay(decay_ms: isize) -> Result<isize> { pub fn set_muzzy_decay(decay_ms: isize) -> Result<isize> {
set(mallctl!("arena.0.muzzy_decay_ms"), decay_ms) // SAFETY: `arena.<i>.muzzy_decay_ms` has C type `ssize_t`.
unsafe { set(mallctl!("arena.0.muzzy_decay_ms"), decay_ms) }
} }
pub fn get_muzzy_decay() -> Result<isize> { get(mallctl!("arena.0.muzzy_decay_ms")) } pub fn get_muzzy_decay() -> Result<isize> {
// SAFETY: `arena.<i>.muzzy_decay_ms` has C type `ssize_t`.
unsafe { get(mallctl!("arena.0.muzzy_decay_ms")) }
}
pub fn set_dirty_decay(decay_ms: isize) -> Result<isize> { pub fn set_dirty_decay(decay_ms: isize) -> Result<isize> {
set(mallctl!("arena.0.dirty_decay_ms"), decay_ms) // SAFETY: `arena.<i>.dirty_decay_ms` has C type `ssize_t`.
unsafe { set(mallctl!("arena.0.dirty_decay_ms"), decay_ms) }
} }
pub fn get_dirty_decay() -> Result<isize> { get(mallctl!("arena.0.dirty_decay_ms")) } pub fn get_dirty_decay() -> Result<isize> {
// SAFETY: `arena.<i>.dirty_decay_ms` has C type `ssize_t`.
unsafe { get(mallctl!("arena.0.dirty_decay_ms")) }
}
pub fn cache_enable(enable: bool) -> Result<bool> { pub fn cache_enable(enable: bool) -> Result<bool> {
super::set::<u8>(&mallctl!("thread.tcache.enabled"), enable.into()).map(is_nonzero!()) // SAFETY: `thread.tcache.enabled` has C type `bool` (1 byte on
// non-MSVC).
unsafe { super::set::<u8>(mallctl!("thread.tcache.enabled"), enable.into()) }
.map(is_nonzero!())
} }
pub fn is_cache_enabled() -> Result<bool> { pub fn is_cache_enabled() -> Result<bool> {
super::get::<u8>(&mallctl!("thread.tcache.enabled")).map(is_nonzero!()) // SAFETY: `thread.tcache.enabled` has C type `bool` (1 byte on
// non-MSVC).
unsafe { super::get::<u8>(mallctl!("thread.tcache.enabled")) }.map(is_nonzero!())
} }
pub fn set_arena(id: usize) -> Result<usize> { pub fn set_arena(id: usize) -> Result<usize> {
super::set::<u32>(&mallctl!("thread.arena"), id.try_into()?).and_then(math::try_into) // SAFETY: `thread.arena` has C type `unsigned`.
unsafe { super::set::<c_uint>(mallctl!("thread.arena"), id.try_into()?) }
.and_then(math::try_into)
} }
pub fn arena_id() -> Result<usize> { pub fn arena_id() -> Result<usize> {
super::get::<u32>(&mallctl!("thread.arena")).and_then(math::try_into) // SAFETY: `thread.arena` has C type `unsigned`.
unsafe { super::get::<c_uint>(mallctl!("thread.arena")) }.and_then(math::try_into)
} }
pub fn prof_enable(enable: bool) -> Result<bool> { pub fn prof_enable(enable: bool) -> Result<bool> {
super::set::<u8>(&mallctl!("thread.prof.active"), enable.into()).map(is_nonzero!()) // SAFETY: `thread.prof.active` has C type `bool` (1 byte on non-MSVC).
unsafe { super::set::<u8>(mallctl!("thread.prof.active"), enable.into()) }
.map(is_nonzero!())
} }
pub fn is_prof_enabled() -> Result<bool> { pub fn is_prof_enabled() -> Result<bool> {
super::get::<u8>(&mallctl!("thread.prof.active")).map(is_nonzero!()) // SAFETY: `thread.prof.active` has C type `bool` (1 byte on non-MSVC).
unsafe { super::get::<u8>(mallctl!("thread.prof.active")) }.map(is_nonzero!())
} }
pub fn reset_peak() -> Result { super::notify(&mallctl!("thread.peak.reset")) } pub fn reset_peak() -> Result {
// SAFETY: `thread.peak.reset` is a non-indexed notification ctl.
unsafe { super::notify(mallctl!("thread.peak.reset")) }
}
pub fn peak() -> Result<u64> { super::get(&mallctl!("thread.peak.read")) } pub fn peak() -> Result<u64> {
// SAFETY: `thread.peak.read` has C type `uint64_t`.
unsafe { super::get(mallctl!("thread.peak.read")) }
}
#[inline] #[inline]
#[must_use] #[must_use]
pub fn allocated() -> u64 { pub fn allocated() -> u64 {
*ALLOCATED_BYTES.with(|once| init_tls_cell(once, "thread.allocatedp")) // SAFETY: `thread.allocated` has C type `uint64_t`.
unsafe { super::get(mallctl!("thread.allocated")) }.unwrap_or_default()
} }
#[inline] #[inline]
#[must_use] #[must_use]
pub fn deallocated() -> u64 { pub fn deallocated() -> u64 {
*DEALLOCATED_BYTES.with(|once| init_tls_cell(once, "thread.deallocatedp")) // SAFETY: `thread.deallocated` has C type `uint64_t`.
unsafe { super::get(mallctl!("thread.deallocated")) }.unwrap_or_default()
} }
fn notify(key: Key) -> Result { super::notify_by_arena(Some(arena_id()?), key) } /// # Safety
/// Caller must ensure `key` is an `arena.<i>.*` notification MIB
/// (`key.len() >= 2`).
unsafe fn notify(key: &Key) -> Result {
let mut key = key.clone();
// `arena_id()` returns this thread's own valid arena (< narenas <
// ARENA_LIMIT), so we skip `validate_arena_id()` to avoid locking
// `ctl_mtx` on hot paths like `decay()`.
key[1] = arena_id()?;
// SAFETY: Caller guarantees `key` is an `arena.<i>.*` notification MIB
// and `arena_id()` returns a valid arena index.
unsafe { super::notify(&key) }
}
fn set<T>(key: Key, val: T) -> Result<T> /// # Safety
/// Caller must ensure `key` is an `arena.<i>.*` MIB and `T` matches its
/// exact C type.
unsafe fn set<T>(key: &Key, val: T) -> Result<T>
where where
T: Copy + Debug, T: Copy + Debug,
{ {
super::set_by_arena(Some(arena_id()?), key, val) let mut key = key.clone();
// `arena_id()` is already a valid arena index; skip
// `validate_arena_id()`.
key[1] = arena_id()?;
// SAFETY: Caller guarantees `T` matches `key`.
unsafe { super::set(&key, val) }
} }
fn get<T>(key: Key) -> Result<T> /// # Safety
/// Caller must ensure `key` is an `arena.<i>.*` MIB and `T` matches its
/// exact C type.
unsafe fn get<T>(key: &Key) -> Result<T>
where where
T: Copy + Debug, T: Copy + Debug,
{ {
super::get_by_arena(Some(arena_id()?), key) let mut key = key.clone();
} // `arena_id()` is already a valid arena index; skip
// `validate_arena_id()`.
fn init_tls_cell(cell: &OnceCell<&'static u64>, name: &str) -> &'static u64 { key[1] = arena_id()?;
cell.get_or_init(|| { // SAFETY: Caller guarantees `T` matches `key`.
let ptr: *const u64 = super::get(&mallctl!(name)).expect("failed to obtain pointer"); unsafe { super::get(&key) }
// SAFETY: ptr points directly to the internal state of jemalloc for
// this thread
unsafe { ptr.as_ref() }.expect("pointer must not be null")
})
} }
} }
pub fn stats_reset() -> Result { notify(&mallctl!("stats.mutexes.reset")) } pub fn stats_reset() -> Result {
// SAFETY: `stats.mutexes.reset` is a non-indexed notification ctl.
unsafe { notify(mallctl!("stats.mutexes.reset")) }
}
pub fn prof_reset() -> Result { notify(&mallctl!("prof.reset")) } pub fn prof_reset() -> Result {
// SAFETY: `prof.reset` is a non-indexed notification ctl.
unsafe { notify(mallctl!("prof.reset")) }
}
pub fn prof_enable(enable: bool) -> Result<bool> { pub fn prof_enable(enable: bool) -> Result<bool> {
set::<u8>(&mallctl!("prof.active"), enable.into()).map(is_nonzero!()) // SAFETY: `prof.active` has C type `bool` (1 byte on non-MSVC).
unsafe { set::<u8>(mallctl!("prof.active"), enable.into()) }.map(is_nonzero!())
} }
pub fn is_prof_enabled() -> Result<bool> { pub fn is_prof_enabled() -> Result<bool> {
get::<u8>(&mallctl!("prof.active")).map(is_nonzero!()) // SAFETY: `prof.active` has C type `bool` (1 byte on non-MSVC).
unsafe { get::<u8>(mallctl!("prof.active")) }.map(is_nonzero!())
} }
pub fn trim<I: Into<Option<usize>> + Copy>(arena: I) -> Result { pub fn trim<I: Into<Option<usize>> + Copy>(arena: I) -> Result {
@@ -263,31 +395,40 @@ pub fn trim<I: Into<Option<usize>> + Copy>(arena: I) -> Result {
} }
pub fn purge<I: Into<Option<usize>>>(arena: I) -> Result { pub fn purge<I: Into<Option<usize>>>(arena: I) -> Result {
notify_by_arena(arena.into(), mallctl!("arena.4096.purge")) // SAFETY: `arena.<i>.purge` is an `arena.<i>.*` notification ctl.
unsafe { notify_by_arena(arena.into(), mallctl!("arena.4096.purge")) }
} }
pub fn decay<I: Into<Option<usize>>>(arena: I) -> Result { pub fn decay<I: Into<Option<usize>>>(arena: I) -> Result {
notify_by_arena(arena.into(), mallctl!("arena.4096.decay")) // SAFETY: `arena.<i>.decay` is an `arena.<i>.*` notification ctl.
unsafe { notify_by_arena(arena.into(), mallctl!("arena.4096.decay")) }
} }
pub fn set_muzzy_decay<I: Into<Option<usize>>>(arena: I, decay_ms: isize) -> Result<isize> { pub fn set_muzzy_decay<I: Into<Option<usize>>>(arena: I, decay_ms: isize) -> Result<isize> {
match arena.into() { match arena.into() {
| Some(arena) => // SAFETY: `arena.<i>.muzzy_decay_ms` has C type `ssize_t`.
set_by_arena(Some(arena), mallctl!("arena.4096.muzzy_decay_ms"), decay_ms), | Some(arena) => unsafe {
| _ => set(&mallctl!("arenas.muzzy_decay_ms"), decay_ms), set_by_arena(arena, mallctl!("arena.0.muzzy_decay_ms"), decay_ms)
},
// SAFETY: `arenas.muzzy_decay_ms` has C type `ssize_t`.
| _ => unsafe { set(mallctl!("arenas.muzzy_decay_ms"), decay_ms) },
} }
} }
pub fn set_dirty_decay<I: Into<Option<usize>>>(arena: I, decay_ms: isize) -> Result<isize> { pub fn set_dirty_decay<I: Into<Option<usize>>>(arena: I, decay_ms: isize) -> Result<isize> {
match arena.into() { match arena.into() {
| Some(arena) => // SAFETY: `arena.<i>.dirty_decay_ms` has C type `ssize_t`.
set_by_arena(Some(arena), mallctl!("arena.4096.dirty_decay_ms"), decay_ms), | Some(arena) => unsafe {
| _ => set(&mallctl!("arenas.dirty_decay_ms"), decay_ms), set_by_arena(arena, mallctl!("arena.0.dirty_decay_ms"), decay_ms)
},
// SAFETY: `arenas.dirty_decay_ms` has C type `ssize_t`.
| _ => unsafe { set(mallctl!("arenas.dirty_decay_ms"), decay_ms) },
} }
} }
pub fn background_thread_enable(enable: bool) -> Result<bool> { pub fn background_thread_enable(enable: bool) -> Result<bool> {
set::<u8>(&mallctl!("background_thread"), enable.into()).map(is_nonzero!()) // SAFETY: `background_thread` has C type `bool` (1 byte on non-MSVC).
unsafe { set::<u8>(mallctl!("background_thread"), enable.into()) }.map(is_nonzero!())
} }
#[inline] #[inline]
@@ -303,83 +444,138 @@ pub fn is_percpu_arena() -> bool { percpu_arenas().is_ok_and(is_equal_to!("percp
pub fn is_phycpu_arena() -> bool { percpu_arenas().is_ok_and(is_equal_to!("phycpu")) } pub fn is_phycpu_arena() -> bool { percpu_arenas().is_ok_and(is_equal_to!("phycpu")) }
pub fn percpu_arenas() -> Result<&'static str> { pub fn percpu_arenas() -> Result<&'static str> {
let ptr = get::<*const c_char>(&mallctl!("opt.percpu_arena"))?; // SAFETY: `opt.percpu_arena` has C type `const char *`.
//SAFETY: ptr points to a null-terminated string returned for let ptr = unsafe { get::<*const c_char>(mallctl!("opt.percpu_arena")) }?;
// opt.percpu_arena. if ptr.is_null() {
return Err(err!("mallctl: opt.percpu_arena returned NULL"));
}
// SAFETY: `ptr` is non-null and points to a static NUL-terminated string
// returned by jemalloc for `opt.percpu_arena`.
let cstr = unsafe { CStr::from_ptr(ptr) }; let cstr = unsafe { CStr::from_ptr(ptr) };
cstr.to_str().map_err(Into::into) cstr.to_str().map_err(Into::into)
} }
pub fn arenas() -> Result<usize> { pub fn arenas() -> Result<usize> {
get::<u32>(&mallctl!("arenas.narenas")).and_then(math::try_into) // SAFETY: `arenas.narenas` has C type `unsigned`.
unsafe { get::<c_uint>(mallctl!("arenas.narenas")) }.and_then(math::try_into)
} }
pub fn inc_epoch() -> Result<u64> { xchg(&mallctl!("epoch"), 1_u64) } pub fn inc_epoch() -> Result<u64> {
// SAFETY: `epoch` has C type `uint64_t`.
pub fn acq_epoch() -> Result<u64> { xchg(&mallctl!("epoch"), 0_u64) } unsafe { xchg(mallctl!("epoch"), 1_u64) }
fn notify_by_arena(id: Option<usize>, mut key: Key) -> Result {
key[1] = id.unwrap_or(4096);
notify(&key)
} }
fn set_by_arena<T>(id: Option<usize>, mut key: Key, val: T) -> Result<T> pub fn acq_epoch() -> Result<u64> {
// SAFETY: `epoch` has C type `uint64_t`.
unsafe { get(mallctl!("epoch")) }
}
fn validate_arena_id(id: usize, allow_all: bool) -> Result<usize> {
if allow_all && id == ARENAS_ALL {
return Ok(id);
}
let narenas = arenas()?.min(ARENA_LIMIT);
if id < narenas {
Ok(id)
} else {
Err(err!("mallctl: invalid arena index {id} (narenas: {narenas})"))
}
}
/// # Safety
/// Caller must ensure `key` is an `arena.<i>.*` notification MIB
/// (`key.len() >= 2`).
unsafe fn notify_by_arena(id: Option<usize>, key: &Key) -> Result {
let mut key = key.clone();
key[1] = match id {
| Some(id) => validate_arena_id(id, true)?,
| None => ARENAS_ALL,
};
// SAFETY: Caller guarantees `key` is an `arena.<i>.*` notification MIB and
// `key[1]` has been validated above.
unsafe { notify(&key) }
}
/// # Safety
/// Caller must ensure `key` is an `arena.<i>.*` MIB (`key.len() >= 2`) and `T`
/// matches its exact C type.
unsafe fn set_by_arena<T>(id: usize, key: &Key, val: T) -> Result<T>
where where
T: Copy + Debug, T: Copy + Debug,
{ {
key[1] = id.unwrap_or(4096); let mut key = key.clone();
set(&key, val) key[1] = validate_arena_id(id, false)?;
// SAFETY: Caller guarantees `T` matches `key`.
unsafe { set(&key, val) }
} }
fn get_by_arena<T>(id: Option<usize>, mut key: Key) -> Result<T> /// # Safety
/// Caller must ensure `key` is a valid notification MIB and any indexed arena
/// component is within bounds.
unsafe fn notify(key: &Key) -> Result {
// SAFETY: jemalloc notification ctls require `oldp`, `oldlenp`, and `newp`
// to be NULL and `newlen` to be 0 (otherwise `EPERM` is returned).
let ret = unsafe {
ffi::mallctlbymib(
key.as_ptr(),
key.len(),
ptr::null_mut(),
ptr::null_mut(),
ptr::null_mut(),
0,
)
};
if ret == 0 {
Ok(())
} else {
Err(err!("mallctl: {}", std::io::Error::from_raw_os_error(ret)))
}
}
/// Does not advance `epoch`; callers reading cached `stats.*` must call
/// `inc_epoch()` explicitly.
///
/// # Safety
/// Caller must ensure `T` matches the exact C type expected by `key`.
unsafe fn set<T>(key: &Key, val: T) -> Result<T>
where where
T: Copy + Debug, T: Copy + Debug,
{ {
key[1] = id.unwrap_or(4096); // SAFETY: Caller guarantees `T` matches `key`.
get(&key) unsafe { xchg(key, val) }
}
fn notify(key: &Key) -> Result { xchg(key, ()) }
fn set<T>(key: &Key, val: T) -> Result<T>
where
T: Copy + Debug,
{
let _lock = CONTROL.write();
let res = xchg(key, val)?;
inc_epoch()?;
Ok(res)
} }
/// # Safety
/// Caller must ensure `T` matches the exact C type expected by `key`.
#[tracing::instrument( #[tracing::instrument(
name = "get", name = "get",
level = "trace", level = "trace",
skip_all, skip_all,
fields(?key) fields(?key)
)] )]
fn get<T>(key: &Key) -> Result<T> unsafe fn get<T>(key: &Key) -> Result<T>
where where
T: Copy + Debug, T: Copy + Debug,
{ {
acq_epoch()?; // SAFETY: Caller guarantees `T` matches the C type returned for `key`.
acq_epoch()?;
// SAFETY: T must be perfectly valid to receive value.
unsafe { mallctl::raw::read_mib(key.as_slice()) }.map_err(map_err) unsafe { mallctl::raw::read_mib(key.as_slice()) }.map_err(map_err)
} }
/// # Safety
/// Caller must ensure `T` matches the exact C type expected by `key`.
#[tracing::instrument( #[tracing::instrument(
name = "xchg", name = "xchg",
level = "trace", level = "trace",
skip_all, skip_all,
fields(?key, ?val) fields(?key, ?val)
)] )]
fn xchg<T>(key: &Key, val: T) -> Result<T> unsafe fn xchg<T>(key: &Key, val: T) -> Result<T>
where where
T: Copy + Debug, T: Copy + Debug,
{ {
// SAFETY: T must be the exact expected type. // SAFETY: Caller guarantees `T` matches the C type expected by `key`.
unsafe { mallctl::raw::update_mib(key.as_slice(), val) }.map_err(map_err) unsafe { mallctl::raw::update_mib(key.as_slice(), val) }.map_err(map_err)
} }
@@ -387,6 +583,9 @@ fn key(name: &str) -> Result<Key> {
// tikv asserts the output buffer length is tight to the number of required // tikv asserts the output buffer length is tight to the number of required
// mibs so we slice that down here. // mibs so we slice that down here.
let segs = name.chars().filter(is_equal_to!(&'.')).count().try_add(1)?; let segs = name.chars().filter(is_equal_to!(&'.')).count().try_add(1)?;
if segs > KEY_SEGS {
return Err(err!("mallctl: key has too many segments ({segs} > {KEY_SEGS})"));
}
let name = self::name(name)?; let name = self::name(name)?;
let mut buf = [0_usize; KEY_SEGS]; let mut buf = [0_usize; KEY_SEGS];
@@ -396,6 +595,10 @@ fn key(name: &str) -> Result<Key> {
} }
fn name(name: &str) -> Result<Name> { fn name(name: &str) -> Result<Name> {
if name.as_bytes().contains(&0) {
return Err(err!("mallctl: key contains interior NUL byte"));
}
let mut buf = Name::new(); let mut buf = Name::new();
buf.try_extend_from_slice(name.as_bytes())?; buf.try_extend_from_slice(name.as_bytes())?;
buf.try_extend_from_slice(b"\0")?; buf.try_extend_from_slice(b"\0")?;
@@ -406,3 +609,100 @@ fn name(name: &str) -> Result<Name> {
fn map_err(error: tikv_jemalloc_ctl::Error) -> crate::Error { fn map_err(error: tikv_jemalloc_ctl::Error) -> crate::Error {
err!("mallctl: {}", error.to_string()) err!("mallctl: {}", error.to_string())
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn notify_ctls_succeed() {
this_thread::flush().expect("thread.tcache.flush");
this_thread::decay().expect("arena.<i>.decay");
this_thread::purge().expect("arena.<i>.purge");
this_thread::trim().expect("this_thread::trim");
trim(None).expect("trim(None)");
}
#[test]
#[cfg(feature = "jemalloc_stats")]
fn allocated_and_deallocated_do_not_alias() {
let a0 = this_thread::allocated();
let d0 = this_thread::deallocated();
let buf = std::hint::black_box(vec![0_u8; 64 * 1024]);
let a1 = this_thread::allocated();
assert!(a1 > a0, "expected allocated to increase: {a0} -> {a1}");
drop(buf);
let d1 = this_thread::deallocated();
assert!(d1 > d0, "expected deallocated to increase: {d0} -> {d1}");
}
#[test]
fn memory_stats_handles_valid_and_nul_opts() {
assert!(memory_stats("invalid\0opts").is_none());
let stats = memory_stats("gmal").expect("memory_stats");
assert!(!stats.is_empty());
}
#[test]
fn key_too_many_segments_returns_err() { key("a.b.c.d.e.f.g.h.i").unwrap_err(); }
#[test]
fn key_interior_nul_returns_err() { key("a.b\0.c").unwrap_err(); }
#[test]
fn arena_index_bounds_rejected() {
purge(Some(ARENAS_ALL)).expect("purge(MALLCTL_ARENAS_ALL)");
decay(Some(ARENAS_ALL)).expect("decay(MALLCTL_ARENAS_ALL)");
let narenas = arenas().expect("arenas.narenas");
purge(Some(narenas)).unwrap_err();
decay(Some(narenas)).unwrap_err();
set_dirty_decay(Some(narenas), -1).unwrap_err();
set_muzzy_decay(Some(narenas), -1).unwrap_err();
purge(Some(4097)).unwrap_err();
decay(Some(4097)).unwrap_err();
trim(Some(4097)).unwrap_err();
purge(Some(usize::MAX)).unwrap_err();
set_dirty_decay(Some(ARENAS_ALL), -1).unwrap_err();
set_muzzy_decay(Some(ARENAS_ALL), -1).unwrap_err();
set_dirty_decay(Some(4097), -1).unwrap_err();
set_muzzy_decay(Some(4097), -1).unwrap_err();
}
#[test]
#[cfg(feature = "jemalloc_conf")]
fn malloc_conf_is_applied() {
if std::env::var_os("MALLOC_CONF").is_some()
|| std::env::var_os("_RJEM_MALLOC_CONF").is_some()
{
return;
}
// SAFETY: `opt.dirty_decay_ms` and `opt.muzzy_decay_ms` have C type
// `ssize_t`.
let dirty =
unsafe { get::<isize>(mallctl!("opt.dirty_decay_ms")) }.expect("opt.dirty_decay_ms");
// SAFETY: Same as above
let muzzy =
unsafe { get::<isize>(mallctl!("opt.muzzy_decay_ms")) }.expect("opt.muzzy_decay_ms");
assert_eq!(dirty, 16_000, "expected malloc_conf dirty_decay_ms:16000");
assert_eq!(muzzy, 144_000, "expected malloc_conf muzzy_decay_ms:144000");
}
#[test]
fn percpu_arenas_returns_valid_mode() {
let mode = percpu_arenas().expect("opt.percpu_arena");
assert!(matches!(mode, "disabled" | "percpu" | "phycpu"), "unexpected mode: {mode}");
}
#[test]
fn epoch_read_and_advance() {
let e0 = acq_epoch().expect("acq_epoch");
let e1 = inc_epoch().expect("inc_epoch");
assert!(e1 > e0, "expected inc_epoch to advance epoch: {e0} -> {e1}");
}
}
+234
View File
@@ -0,0 +1,234 @@
//! mimalloc allocator
use std::{
any::Any,
ffi::{CStr, c_void},
panic::{self, AssertUnwindSafe},
ptr,
};
use arrayvec::ArrayVec;
use libmimalloc_sys as ffi;
use mimalloc::MiMalloc;
use serde::Deserialize;
#[global_allocator]
static MIMALLOC: MiMalloc = MiMalloc;
#[derive(Deserialize)]
struct StatCount {
current: i64,
peak: i64,
}
#[derive(Deserialize)]
struct Stats {
reserved: StatCount,
committed: StatCount,
purged: i64,
reset: i64,
}
trait OutputFnChar {
type Char;
}
impl<C> OutputFnChar for Option<unsafe extern "C" fn(*const C, *mut c_void)> {
type Char = C;
}
type MiChar = <ffi::mi_output_fun as OutputFnChar>::Char;
struct StatsPrintState {
buf: String,
max_len: usize,
panic: Option<Box<dyn Any + Send>>,
}
pub(crate) fn metric() -> Option<(&'static str, &'static str)> {
Some(("continuwuity.mimalloc.memory", "mimalloc memory statistics"))
}
pub fn trim<I: Into<Option<usize>>>(_: I) -> crate::Result {
// SAFETY: `mi_collect` is thread-safe and takes a single boolean flag.
unsafe { ffi::mi_collect(true) };
Ok(())
}
fn read_stats() -> Option<Stats> {
let stats = MiMalloc::stats_json().ok()?;
let json = stats.to_str().ok()?;
serde_json::from_str(json).ok()
}
fn non_neg_usize(value: i64) -> usize { usize::try_from(value.max(0)).unwrap_or(usize::MAX) }
fn mibs(input: usize) -> f64 {
let whole = u32::try_from(input / (1024 * 1024)).unwrap_or(u32::MAX);
let rem_kibs = u32::try_from((input / 1024) % 1024).unwrap_or_default();
f64::from(whole) + f64::from(rem_kibs) / 1024.0
}
#[must_use]
pub fn memory_usage() -> Option<String> {
let stats = read_stats()?;
Some(format!(
"reserved: {:.2} MiB\nreserved_peak: {:.2} MiB\ncommitted: {:.2} MiB\ncommitted_peak: \
{:.2} MiB\npurged_total: {:.2} MiB\nreset_total: {:.2} MiB\n",
mibs(non_neg_usize(stats.reserved.current)),
mibs(non_neg_usize(stats.reserved.peak)),
mibs(non_neg_usize(stats.committed.current)),
mibs(non_neg_usize(stats.committed.peak)),
mibs(non_neg_usize(stats.purged)),
mibs(non_neg_usize(stats.reset)),
))
}
#[must_use]
pub fn memory_usage_stats() -> Option<ArrayVec<(&'static str, usize), 6>> {
let stats = read_stats()?;
let mut out = ArrayVec::new();
out.extend([
("reserved", non_neg_usize(stats.reserved.current)),
("reserved_peak", non_neg_usize(stats.reserved.peak)),
("committed", non_neg_usize(stats.committed.current)),
("committed_peak", non_neg_usize(stats.committed.peak)),
]);
Some(out)
}
#[must_use]
pub fn memory_stats(opts: &str) -> Option<String> {
const MAX_LENGTH: usize = 1_048_576;
if opts.contains('\0') {
return None;
}
if opts.contains('J') {
let stats = MiMalloc::stats_json().ok()?;
let json = String::from_utf8_lossy(stats.to_bytes());
let end = json.floor_char_boundary(json.len().min(MAX_LENGTH));
return json.get(..end).map(str::to_owned);
}
let mut state = StatsPrintState {
buf: String::new(),
max_len: MAX_LENGTH,
panic: None,
};
let opaque = ptr::from_mut(&mut state).cast::<c_void>();
// SAFETY: `state` remains live in this frame for the duration of
// `mi_stats_print_out()`, which invokes `mi_stats_cb` synchronously.
unsafe { ffi::mi_stats_print_out(Some(mi_stats_cb), opaque) };
if let Some(payload) = state.panic {
panic::resume_unwind(payload);
}
Some(state.buf)
}
unsafe extern "C" fn mi_stats_cb(msg: *const MiChar, arg: *mut c_void) {
// SAFETY: `arg` points to `StatsPrintState` on the caller's stack.
let Some(state) = (unsafe { arg.cast::<StatsPrintState>().as_mut() }) else {
return;
};
if state.panic.is_some() || msg.is_null() || state.buf.len() >= state.max_len {
return;
}
// SAFETY: mimalloc guarantees `msg` is a valid NUL-terminated C string.
let msg = unsafe { CStr::from_ptr(msg.cast()) };
if let Err(err) = panic::catch_unwind(AssertUnwindSafe(|| {
let msg = String::from_utf8_lossy(msg.to_bytes());
let remaining = state.max_len.saturating_sub(state.buf.len());
if msg.len() <= remaining {
state.buf.push_str(msg.as_ref());
} else {
if let Some(prefix) = msg.get(..msg.floor_char_boundary(remaining)) {
state.buf.push_str(prefix);
}
state.max_len = state.buf.len();
}
})) {
state.panic = Some(err);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn trim_succeeds() { trim(None).expect("trim(None)"); }
#[test]
fn non_neg_usize_clamps_negative_values() {
assert_eq!(non_neg_usize(-1), 0, "expected -1 to clamp to 0");
assert_eq!(non_neg_usize(i64::MIN), 0, "expected i64::MIN to clamp to 0");
assert_eq!(non_neg_usize(0), 0, "expected 0 to remain 0");
assert_eq!(non_neg_usize(4096), 4096, "expected positive value unchanged");
}
#[test]
fn memory_usage_stats_reports_allocator_bytes() {
let buf = std::hint::black_box(vec![0_u8; 64 * 1024]);
let stats = memory_usage_stats().expect("memory_usage_stats");
drop(buf);
let keys: Vec<_> = stats.iter().map(|&(key, _)| key).collect();
assert_eq!(
keys,
["reserved", "reserved_peak", "committed", "committed_peak"],
"unexpected stat keys"
);
for (key, bytes) in stats {
assert!(bytes > 0, "expected {key} > 0, got {bytes}");
}
}
#[test]
fn memory_usage_returns_allocator_summary() {
let usage = memory_usage().expect("memory_usage");
for expected in [
"reserved:",
"reserved_peak:",
"committed:",
"committed_peak:",
"purged_total:",
"reset_total:",
"MiB",
] {
assert!(usage.contains(expected), "missing {expected:?} in usage:\n{usage}");
}
assert!(!usage.contains("current_rss:"), "unexpected current_rss in usage:\n{usage}");
assert!(!usage.contains("peak_rss:"), "unexpected peak_rss in usage:\n{usage}");
}
#[test]
fn memory_stats_supports_text_json_and_rejects_nul() {
assert!(memory_stats("invalid\0opts").is_none(), "expected NUL opts to return None");
for opts in ["", "abcdefghijklmnopqrstuvwxyz"] {
let stats = memory_stats(opts).expect("memory_stats text");
assert!(!stats.is_empty(), "expected non-empty stats for opts={opts:?}");
assert!(!stats.starts_with('{'), "expected formatted text, got JSON:\n{stats}");
assert!(stats.contains("reserved"), "missing reserved in stats:\n{stats}");
assert!(stats.contains("committed"), "missing committed in stats:\n{stats}");
}
let json = memory_stats("J").expect("memory_stats JSON");
assert!(json.starts_with('{'), "expected JSON object, got:\n{json}");
let parsed: serde_json::Value =
serde_json::from_str(&json).expect("expected valid JSON from memory_stats(\"J\")");
assert!(parsed.get("committed").is_some(), "expected committed field in JSON");
}
}
+16 -16
View File
@@ -4,24 +4,24 @@
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
pub mod je; pub mod je;
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] #[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
pub(crate) use je::metric;
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
pub use je::{memory_stats, memory_usage, memory_usage_stats, trim}; pub use je::{memory_stats, memory_usage, memory_usage_stats, trim};
#[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", not(feature = "jemalloc")))] // mimalloc
pub mod hardened; #[cfg(all(feature = "mimalloc", feature = "jemalloc", not(target_env = "msvc")))]
#[cfg(all( compile_error!("the `mimalloc` and `jemalloc` features are mutually exclusive");
not(target_env = "msvc"), #[cfg(all(feature = "mimalloc", any(target_env = "msvc", not(feature = "jemalloc"))))]
feature = "hardened_malloc", pub mod mimalloc;
not(feature = "jemalloc") #[cfg(all(feature = "mimalloc", any(target_env = "msvc", not(feature = "jemalloc"))))]
))] pub(crate) use mimalloc::metric;
pub use hardened::{memory_stats, memory_usage, memory_usage_stats, trim}; #[cfg(all(feature = "mimalloc", any(target_env = "msvc", not(feature = "jemalloc"))))]
pub use mimalloc::{memory_stats, memory_usage, memory_usage_stats, trim};
#[cfg(any( // default
target_env = "msvc", #[cfg(all(not(feature = "mimalloc"), any(target_env = "msvc", not(feature = "jemalloc"))))]
all(not(feature = "hardened_malloc"), not(feature = "jemalloc"))
))]
pub mod default; pub mod default;
#[cfg(any( #[cfg(all(not(feature = "mimalloc"), any(target_env = "msvc", not(feature = "jemalloc"))))]
target_env = "msvc", pub(crate) use default::metric;
all(not(feature = "hardened_malloc"), not(feature = "jemalloc")) #[cfg(all(not(feature = "mimalloc"), any(target_env = "msvc", not(feature = "jemalloc"))))]
))]
pub use default::{memory_stats, memory_usage, memory_usage_stats, trim}; pub use default::{memory_stats, memory_usage, memory_usage_stats, trim};
+1 -8
View File
@@ -5,7 +5,7 @@ use figment::Figment;
use ruma::{OwnedServerName, events::room::server_acl::RoomServerAclEventContent}; use ruma::{OwnedServerName, events::room::server_acl::RoomServerAclEventContent};
use super::DEPRECATED_KEYS; use super::DEPRECATED_KEYS;
use crate::{Config, Err, Result, Server, debug, debug_info, debug_warn, error, warn}; use crate::{Config, Err, Result, Server, debug, debug_info, error, warn};
/// Performs check() with additional checks specific to reloading old config /// Performs check() with additional checks specific to reloading old config
/// with new config. /// with new config.
@@ -43,13 +43,6 @@ pub fn check(config: &Config) -> Result {
)); ));
} }
if cfg!(all(feature = "hardened_malloc", feature = "jemalloc", not(target_env = "msvc"))) {
debug_warn!(
"hardened_malloc and jemalloc compile-time features are both enabled, this causes \
jemalloc to be used."
);
}
if cfg!(not(unix)) && config.unix_socket_path.is_some() { if cfg!(not(unix)) && config.unix_socket_path.is_some() {
return Err!(Config( return Err!(Config(
"unix_socket_path", "unix_socket_path",
+38
View File
@@ -24,6 +24,26 @@ pub struct Experiments {
/// display: nested /// display: nested
#[serde(default)] #[serde(default)]
pub msc2815: Option<MSC2815>, pub msc2815: Option<MSC2815>,
/// MSC3814: Dehydrated devices with SSSS
///
/// Enables server-side support for "dehydrated devices", which are
/// server-side devices (created by supporting clients) that can collect
/// encryption keys when there are no online devices, which supporting
/// clients can then "hydrate" to download any encryption keys that were
/// sent while they were offline.
///
/// Important: this is NOT required to receive encrypted messages while you
/// are offline. Devices can still receive encrypted messages while they are
/// offline, but to share those keys with new devices, they have to be
/// online. Dehydrated devices work around this by providing a "shared"
/// device new sessions can bootstrap from, to receive keys from before they
/// logged in that haven't been uploaded to the server-side key backup yet.
///
/// https://github.com/matrix-org/matrix-spec-proposals/pull/3814
///
/// default: false
#[serde(default)]
pub msc3814: SimpleExperiment,
/// MSC4155: Invite filtering /// MSC4155: Invite filtering
/// ///
/// Provides advanced invite filtering rules for users, allowing complex /// Provides advanced invite filtering rules for users, allowing complex
@@ -48,6 +68,24 @@ pub struct Experiments {
/// default: false /// default: false
#[serde(default)] #[serde(default)]
pub msc4174: SimpleExperiment, pub msc4174: SimpleExperiment,
/// MSC4406: `M_SENDER_IGNORED` error code
///
/// Introduces a new error code that explicitly informs clients the reason
/// they cannot access an event if it is sent by an ignored user. Without
/// this proposal, clients will simply get a "not found" or "forbidden"
/// error when requesting events sent by users that have been ignored, which
/// leads to replies being shown as "this message could not be found".
/// The new error code allows clients to distinguish unknown/forbidden
/// events from ignored senders, allowing them to display an error message
/// like "you have blocked this sender" instead.
///
/// Requires a supporting client to be useful.
///
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4406
///
/// default: false
#[serde(default)]
pub msc4406: SimpleExperiment,
/// MSC4484: Server Administration OAuth Scope /// MSC4484: Server Administration OAuth Scope
/// ///
/// Adds a new OAuth2 scope that explicitly grants a token temporary /// Adds a new OAuth2 scope that explicitly grants a token temporary
+34 -11
View File
@@ -195,7 +195,7 @@ pub struct Config {
/// announcements or major updates. This is not an update check endpoint. /// announcements or major updates. This is not an update check endpoint.
/// ///
/// default: true /// default: true
#[serde(alias = "allow_check_for_updates", default = "true_fn")] #[serde(default = "true_fn")]
pub allow_announcements_check: bool, pub allow_announcements_check: bool,
/// Set this to any float value to multiply continuwuity's in-memory LRU /// Set this to any float value to multiply continuwuity's in-memory LRU
@@ -490,7 +490,7 @@ pub struct Config {
#[serde(default = "default_ip_lookup_strategy")] #[serde(default = "default_ip_lookup_strategy")]
pub ip_lookup_strategy: u8, pub ip_lookup_strategy: u8,
/// The preferred source to use for getting the real client IP. /// DEPRECATED: The preferred source to use for getting the real client IP.
/// ///
/// Takes any of the following options: /// Takes any of the following options:
/// ///
@@ -509,9 +509,10 @@ pub struct Config {
/// to set this header" check; if the header selected is present, it is /// to set this header" check; if the header selected is present, it is
/// used. /// used.
/// ///
/// Ignored if `accepted_ip_sources` is set. /// Ignored if `accepted_ip_sources` is set. `accepted_ip_sources` is
/// the preferred alternative.
/// ///
/// If not set set, `direct` is used. Additionally, `direct` is used /// If not set, `direct` is used. Additionally, `direct` is used
/// as a fallback if the chosen header is not found. /// as a fallback if the chosen header is not found.
#[serde(default)] #[serde(default)]
pub request_ip_source: Option<String>, pub request_ip_source: Option<String>,
@@ -919,14 +920,34 @@ pub struct Config {
#[serde(default)] #[serde(default)]
pub forget_forced_upon_leave: bool, pub forget_forced_upon_leave: bool,
/// Set this to true to require authentication on the normally /// Set this to true to require authentication when looking up user profiles
/// unauthenticated profile retrieval endpoints (GET) /// through this server.
/// "/_matrix/client/v3/profile/{userId}".
/// ///
/// This can prevent profile scraping. /// 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)] #[serde(default)]
pub require_auth_for_profile_requests: bool, 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.
///
/// For QR code login, the device that shows the QR code is the one that
/// 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
/// not have a camera) to show a QR code. Setting this to true will
/// require logged-out devices to scan the QR code instead.
///
/// default: false
#[serde(default)]
pub require_auth_for_rendezvous: bool,
/// Set this to true to allow your server's public room directory to be /// Set this to true to allow your server's public room directory to be
/// federated. Set this to false to protect against /publicRooms spiders, /// federated. Set this to false to protect against /publicRooms spiders,
/// but will forbid external users from viewing your server's public room /// but will forbid external users from viewing your server's public room
@@ -2973,11 +2994,16 @@ impl<'de, K: Hash + Eq + Clone> Deserialize<'de> for PerMinuteRatelimiter<K> {
} }
const DEPRECATED_KEYS: &[&str] = &[ const DEPRECATED_KEYS: &[&str] = &[
"allow_check_for_updates",
"allow_moderators_to_view_redacted_content",
"allow_sticky_events",
"cache_capacity", "cache_capacity",
"conduit_cache_capacity_modifier", "conduit_cache_capacity_modifier",
"max_concurrent_requests", "max_concurrent_requests",
"otlp_protocol", "otlp_protocol",
"request_ip_source",
"roomid_spacehierarchy_cache_capacity", "roomid_spacehierarchy_cache_capacity",
"unredacted_content_max_age_secs",
"well_known_client", "well_known_client",
"well_known_server", "well_known_server",
"well_known_support_page", "well_known_support_page",
@@ -2985,9 +3011,6 @@ const DEPRECATED_KEYS: &[&str] = &[
"well_known_support_email", "well_known_support_email",
"well_known_support_mxid", "well_known_support_mxid",
"well_known.rtc_focus_server_urls", "well_known.rtc_focus_server_urls",
"allow_sticky_events",
"allow_moderators_to_view_redacted_content",
"unredacted_content_max_age_secs",
]; ];
impl Config { impl Config {
+5 -2
View File
@@ -35,10 +35,10 @@ pub fn versions() -> Vec<String> {
pub fn unstable_features(experiments: &Experiments) -> BTreeMap<String, bool> { pub fn unstable_features(experiments: &Experiments) -> BTreeMap<String, bool> {
BTreeMap::from_iter([ BTreeMap::from_iter([
// MatrixRTC (https://github.com/matrix-org/matrix-spec-proposals/pull/4143) // MatrixRTC (https://github.com/matrix-org/matrix-spec-proposals/pull/4143)
// Expected for spec v1.20 // Expected for spec v1.20/v2.0
("org.matrix.msc4143".to_owned(), true), ("org.matrix.msc4143".to_owned(), true),
// Simplified Sliding sync (https://github.com/matrix-org/matrix-spec-proposals/pull/4186) // Simplified Sliding sync (https://github.com/matrix-org/matrix-spec-proposals/pull/4186)
// Expected for spec v1.20 // Expected for spec v1.20/v2.0
("org.matrix.simplified_msc3575".to_owned(), true), ("org.matrix.simplified_msc3575".to_owned(), true),
("org.matrix.msc4155".to_owned(), experiments.msc4155.is_enabled()), ("org.matrix.msc4155".to_owned(), experiments.msc4155.is_enabled()),
// profile change propagation (https://github.com/matrix-org/matrix-spec-proposals/pull/4466) // profile change propagation (https://github.com/matrix-org/matrix-spec-proposals/pull/4466)
@@ -48,5 +48,8 @@ pub fn unstable_features(experiments: &Experiments) -> BTreeMap<String, bool> {
("org.continuwuity.msc4484.unstable".to_owned(), experiments.msc4484.is_enabled()), ("org.continuwuity.msc4484.unstable".to_owned(), experiments.msc4484.is_enabled()),
("org.continuwuity.msc4560".to_owned(), experiments.msc4560.is_enabled()), ("org.continuwuity.msc4560".to_owned(), experiments.msc4560.is_enabled()),
("fi.mau.msc2815".to_owned(), experiments.msc2815.is_enabled()), ("fi.mau.msc2815".to_owned(), experiments.msc2815.is_enabled()),
// Sticky events (https://github.com/matrix-org/matrix-spec-proposals/pull/4354)
// Proposal merged, expected for spec v1.20/v2.0
("org.matrix.msc4354".to_owned(), true),
]) ])
} }
+6 -2
View File
@@ -196,9 +196,13 @@ fn register_process(meter: &Meter) {
} }
fn register_allocator(meter: &Meter) { fn register_allocator(meter: &Meter) {
let Some((name, description)) = crate::alloc::metric() else {
return;
};
meter meter
.u64_observable_gauge("continuwuity.jemalloc.memory") .u64_observable_gauge(name)
.with_description("jemalloc memory statistics, when built with jemalloc_stats") .with_description(description)
.with_unit("By") .with_unit("By")
.with_callback(|observer| { .with_callback(|observer| {
for (kind, bytes) in crate::alloc::memory_usage_stats().into_iter().flatten() { for (kind, bytes) in crate::alloc::memory_usage_stats().into_iter().flatten() {
+20
View File
@@ -38,3 +38,23 @@ async fn renders_prometheus_names() {
} }
assert!(!body.contains("otel_scope_name")); assert!(!body.contains("otel_scope_name"));
} }
#[tokio::test]
#[cfg(all(feature = "mimalloc", any(target_env = "msvc", not(feature = "jemalloc"))))]
async fn renders_mimalloc_memory_metric() {
let (metrics, _provider) = metrics();
let body = metrics.render().unwrap();
for expected in [
"continuwuity_mimalloc_memory_bytes{kind=\"reserved\"}",
"continuwuity_mimalloc_memory_bytes{kind=\"reserved_peak\"}",
"continuwuity_mimalloc_memory_bytes{kind=\"committed\"}",
"continuwuity_mimalloc_memory_bytes{kind=\"committed_peak\"}",
] {
assert!(body.contains(expected), "missing {expected:?} in:\n{body}");
}
assert!(
!body.contains("continuwuity_jemalloc_memory_bytes"),
"unexpected jemalloc metric in mimalloc build:\n{body}"
);
}
+2 -1
View File
@@ -37,7 +37,8 @@ pub use error::Error;
pub use info::version::*; pub use info::version::*;
pub use matrix::{Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, pdu, state_res}; pub use matrix::{Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, pdu, state_res};
pub use parking_lot::{ pub use parking_lot::{
Mutex as SyncMutex, RwLock as SyncRwLock, RwLockReadGuard as SyncRwLockReadGuard, MappedMutexGuard as SyncMappedMutexGuard, Mutex as SyncMutex, MutexGuard as SyncMutexGuard,
RwLock as SyncRwLock, RwLockReadGuard as SyncRwLockReadGuard,
RwLockWriteGuard as SyncRwLockWriteGuard, RwLockWriteGuard as SyncRwLockWriteGuard,
}; };
pub use server::Server; pub use server::Server;
+1 -2
View File
@@ -76,8 +76,7 @@ impl super::Engine {
.config .config
.database_backup_path .database_backup_path
.clone() .clone()
.map(PathBuf::into_os_string) .map_or_default(PathBuf::into_os_string);
.unwrap_or_default();
if path.is_empty() { if path.is_empty() {
return Err!(Config("database_backup_path", "Configure path to enable backups")); return Err!(Config("database_backup_path", "Configure path to enable backups"));
+3 -4
View File
@@ -70,7 +70,6 @@ standard = [
] ]
full = [ full = [
"standard", "standard",
# "hardened_malloc", # Conflicts with jemalloc
"jemalloc_prof", "jemalloc_prof",
"perf_measurements", "perf_measurements",
"tokio_console", "tokio_console",
@@ -96,9 +95,6 @@ gzip_compression = [
"conduwuit-router/gzip_compression", "conduwuit-router/gzip_compression",
"conduwuit-service/gzip_compression", "conduwuit-service/gzip_compression",
] ]
hardened_malloc = [
"conduwuit-core/hardened_malloc",
]
http3 = [ http3 = [
"conduwuit-service/http3" "conduwuit-service/http3"
] ]
@@ -116,6 +112,9 @@ jemalloc = [
"conduwuit-core/jemalloc", "conduwuit-core/jemalloc",
"conduwuit-service/jemalloc", "conduwuit-service/jemalloc",
] ]
mimalloc = [
"conduwuit-core/mimalloc",
]
jemalloc_prof = [ jemalloc_prof = [
"conduwuit-core/jemalloc_prof", "conduwuit-core/jemalloc_prof",
] ]
+1 -1
View File
@@ -22,7 +22,7 @@ use hyper_util::{
use tokio::{ use tokio::{
fs, fs,
net::{UnixListener, UnixStream, unix::SocketAddr}, net::{UnixListener, UnixStream, unix::SocketAddr},
sync::broadcast::{self}, sync::broadcast,
task::JoinSet, task::JoinSet,
time::{Duration, sleep}, time::{Duration, sleep},
}; };
+1 -1
View File
@@ -25,7 +25,7 @@ http.workspace = true
ruma.workspace = true ruma.workspace = true
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
wildmatch = "2.7.0" wildmatch.workspace = true
[dev-dependencies] [dev-dependencies]
+3 -2
View File
@@ -1,6 +1,7 @@
#[cfg(feature = "console")]
use std::io::IsTerminal; use std::io::IsTerminal;
use conduwuit::{Err, Result, debug, debug_info, error, info, warn}; use conduwuit::{Err, Result, debug, debug_info, error, info};
use ruma::events::room::message::RoomMessageEventContent; use ruma::events::room::message::RoomMessageEventContent;
use tokio::time::{Duration, sleep}; use tokio::time::{Duration, sleep};
@@ -15,7 +16,7 @@ impl super::Service {
#[cfg(feature = "console")] #[cfg(feature = "console")]
if self.services.server.config.admin_console_automatic { if self.services.server.config.admin_console_automatic {
if !std::io::stdin().is_terminal() { if !std::io::stdin().is_terminal() {
warn!("Console enabled without a tty available; Not enabling console"); conduwuit::warn!("Console enabled without a tty available; Not enabling console");
return; return;
} }
+1 -1
View File
@@ -379,7 +379,7 @@ fn get_dns_resolver(server: &Arc<Server>) -> Result<Arc<TokioResolver>> {
info!(?nameservers, "Resolved nameservers for DNS client"); info!(?nameservers, "Resolved nameservers for DNS client");
for sys_conf in nameservers { for sys_conf in nameservers {
let mut ns = sys_conf.clone(); let mut ns = sys_conf;
if config.query_over_tcp_only { if config.query_over_tcp_only {
ns.connections = vec![ConnectionConfig::tcp()]; ns.connections = vec![ConnectionConfig::tcp()];
+5 -30
View File
@@ -182,26 +182,11 @@ impl Data {
let mut value = Vec::<u8>::new(); let mut value = Vec::<u8>::new();
value.extend_from_slice(&timestamp.as_secs().to_be_bytes()); value.extend_from_slice(&timestamp.as_secs().to_be_bytes());
value.push(0xFF); value.push(0xFF);
value.extend_from_slice( value.extend_from_slice(data.title.as_ref().map_or_default(String::as_bytes));
data.title
.as_ref()
.map(String::as_bytes)
.unwrap_or_default(),
);
value.push(0xFF); value.push(0xFF);
value.extend_from_slice( value.extend_from_slice(data.description.as_ref().map_or_default(String::as_bytes));
data.description
.as_ref()
.map(String::as_bytes)
.unwrap_or_default(),
);
value.push(0xFF); value.push(0xFF);
value.extend_from_slice( value.extend_from_slice(data.image.as_ref().map_or_default(String::as_bytes));
data.image
.as_ref()
.map(String::as_bytes)
.unwrap_or_default(),
);
value.push(0xFF); value.push(0xFF);
value.extend_from_slice(&data.image_size.unwrap_or(0).to_be_bytes()); value.extend_from_slice(&data.image_size.unwrap_or(0).to_be_bytes());
value.push(0xFF); value.push(0xFF);
@@ -209,12 +194,7 @@ impl Data {
value.push(0xFF); value.push(0xFF);
value.extend_from_slice(&data.image_height.unwrap_or(0).to_be_bytes()); value.extend_from_slice(&data.image_height.unwrap_or(0).to_be_bytes());
value.push(0xFF); value.push(0xFF);
value.extend_from_slice( value.extend_from_slice(data.video.as_ref().map_or_default(String::as_bytes));
data.video
.as_ref()
.map(String::as_bytes)
.unwrap_or_default(),
);
value.push(0xFF); value.push(0xFF);
value.extend_from_slice(&data.video_size.unwrap_or(0).to_be_bytes()); value.extend_from_slice(&data.video_size.unwrap_or(0).to_be_bytes());
value.push(0xFF); value.push(0xFF);
@@ -222,12 +202,7 @@ impl Data {
value.push(0xFF); value.push(0xFF);
value.extend_from_slice(&data.video_height.unwrap_or(0).to_be_bytes()); value.extend_from_slice(&data.video_height.unwrap_or(0).to_be_bytes());
value.push(0xFF); value.push(0xFF);
value.extend_from_slice( value.extend_from_slice(data.audio.as_ref().map_or_default(String::as_bytes));
data.audio
.as_ref()
.map(String::as_bytes)
.unwrap_or_default(),
);
value.push(0xFF); value.push(0xFF);
value.extend_from_slice(&data.audio_size.unwrap_or(0).to_be_bytes()); value.extend_from_slice(&data.audio_size.unwrap_or(0).to_be_bytes());
+1 -1
View File
@@ -1,7 +1,7 @@
use std::{ use std::{
collections::HashSet, collections::HashSet,
ffi::{OsStr, OsString}, ffi::{OsStr, OsString},
fs::{self}, fs,
path::PathBuf, path::PathBuf,
sync::Arc, sync::Arc,
time::Instant, time::Instant,
+2
View File
@@ -1,4 +1,5 @@
#![type_length_limit = "8192"] #![type_length_limit = "8192"]
#![recursion_limit = "256"]
#![allow(refining_impl_trait)] #![allow(refining_impl_trait)]
extern crate conduwuit_core as conduwuit; extern crate conduwuit_core as conduwuit;
@@ -33,6 +34,7 @@ pub mod oidc;
pub mod presence; pub mod presence;
pub mod pusher; pub mod pusher;
pub mod registration_tokens; pub mod registration_tokens;
pub mod rendezvous;
pub mod rooms; pub mod rooms;
pub mod sending; pub mod sending;
pub mod server_keys; pub mod server_keys;
+37 -5
View File
@@ -106,12 +106,14 @@ impl Display for RequestedScopes {
pub struct RawScopes(String); pub struct RawScopes(String);
impl RawScopes { impl RawScopes {
const MIN_DEVICE_ID_LENGTH: usize = 5;
#[allow(clippy::trivial_regex)] #[allow(clippy::trivial_regex)]
pub fn to_scopes(&self) -> Result<RequestedScopes, String> { pub fn to_scopes(&self) -> Result<RequestedScopes, String> {
let client_api_token_regex = let client_api_token_regex =
regex!(r"urn:matrix:(client|org.matrix.msc2967.client):api:\*"); regex!(r"urn:matrix:(client|org.matrix.msc2967.client):api:\*");
let device_token_regex = let device_token_regex =
regex!(r"urn:matrix:(client|org.matrix.msc2967.client):device:([a-zA-Z0-9-._~]{5,})"); regex!(r"urn:matrix:(client|org.matrix.msc2967.client):device:(.+)");
let server_administration_regex = let server_administration_regex =
regex!(r"urn:matrix:client:cc.c10y.msc4484.server_administration"); regex!(r"urn:matrix:client:cc.c10y.msc4484.server_administration");
@@ -124,10 +126,40 @@ impl RawScopes {
} else if server_administration_regex.is_match(token) { } else if server_administration_regex.is_match(token) {
scopes.scopes.insert(OAuthClientScope::ServerAdministration) scopes.scopes.insert(OAuthClientScope::ServerAdministration)
} else if let Some(captures) = device_token_regex.captures(token) { } else if let Some(captures) = device_token_regex.captures(token) {
scopes let device_id = captures.get(2).unwrap().as_str();
.device_id
.replace(captures.get(2).unwrap().as_str().into()) if device_id.len() < Self::MIN_DEVICE_ID_LENGTH {
.is_none() return Err(format!(
"Device ID is too short, it must be at least {} characters",
Self::MIN_DEVICE_ID_LENGTH
));
}
// The Matrix specification has a "suggested" set of
// characters to be used in the device
// ID scope. In the past we checked against this set, but we
// no longer do that; instead we check
// against the _required_ set of
// characters defined by the OAuth specification.
// We do this because we have observed SDKs in the wild
// (*cough* matrix-rust-sdk) that will provide device IDs
// that are just unpadded base64, which they're allowed to
// do, since the spec just says that
// clients "SHOULD" only use the suggested character set and
// servers "MAY" choose to require that they do.
// Of course this actually means that clients will do
// whatever the hell they want and
// servers can never ever be stricter
// than they absolutely have to be. What
// a stupid provision.
if device_id
.chars()
.any(|char| !matches!(char, '\x21' | '\x23'..='\x5b' | '\x5d'..='\x7e'))
{
return Err("Device ID contains disallowed characters".to_owned());
}
scopes.device_id.replace(device_id.into()).is_none()
} else { } else {
continue; continue;
} }
+4 -1
View File
@@ -6,7 +6,9 @@ use std::{
use base64::Engine; use base64::Engine;
use conduwuit::{ use conduwuit::{
Result, SyncMutex, info, Result, SyncMutex,
config::experiments::ToggledExperiment,
info,
utils::{self, hash::sha256}, utils::{self, hash::sha256},
}; };
use database::{Deserialized, Json, Map}; use database::{Deserialized, Json, Map};
@@ -762,6 +764,7 @@ impl Service {
scopes: &BTreeSet<OAuthClientScope>, scopes: &BTreeSet<OAuthClientScope>,
) -> Result<(), OAuthError> { ) -> Result<(), OAuthError> {
if scopes.contains(&OAuthClientScope::ServerAdministration) if scopes.contains(&OAuthClientScope::ServerAdministration)
&& self.services.config.experiments.msc4484.is_enabled()
&& !self.services.admin.user_is_admin(authorizing_user).await && !self.services.admin.user_is_admin(authorizing_user).await
{ {
return Err(OAuthError::new( return Err(OAuthError::new(
+9 -5
View File
@@ -3,7 +3,7 @@ mod webpush;
use std::{fmt::Debug, mem, net::IpAddr, sync::Arc}; use std::{fmt::Debug, mem, net::IpAddr, sync::Arc};
use bytes::BytesMut; use bytes::BytesMut;
use conduwuit::utils::response::LimitReadExt; use conduwuit::{config::experiments::ToggledExperiment, utils::response::LimitReadExt};
use conduwuit_core::{ use conduwuit_core::{
Err, Event, Result, Server, debug_warn, err, trace, Err, Event, Result, Server, debug_warn, err, trace,
utils::{stream::TryIgnore, string_from_bytes}, utils::{stream::TryIgnore, string_from_bytes},
@@ -133,7 +133,9 @@ impl Service {
self.validate_push_url(&http.url, PUSH_GATEWAY_SCHEMES) self.validate_push_url(&http.url, PUSH_GATEWAY_SCHEMES)
.await?; .await?;
}, },
| PusherKind::WebPush(data) => { | PusherKind::WebPush(data)
if self.services.config.experiments.msc4174.is_enabled() =>
{
self.validate_push_url(&data.url, WEBPUSH_SCHEMES).await?; self.validate_push_url(&data.url, WEBPUSH_SCHEMES).await?;
webpush::decode_pushkey(pushkey)?; webpush::decode_pushkey(pushkey)?;
webpush::decode_auth(&data.auth)?; webpush::decode_auth(&data.auth)?;
@@ -147,7 +149,7 @@ impl Service {
} }
} }
}, },
| PusherKind::Email(_) | PusherKind::Custom { .. } => (), | _ => (),
} }
let key = (sender, pushkey); let key = (sender, pushkey);
@@ -547,7 +549,9 @@ impl Service {
Ok(()) Ok(())
}, },
| PusherKind::WebPush(data) => { | PusherKind::WebPush(data)
if self.services.config.experiments.msc4174.is_enabled() =>
{
let notify = self let notify = self
.build_notification( .build_notification(
user, user,
@@ -562,7 +566,7 @@ impl Service {
self.send_webpush_notice(user, pusher, data, notify).await self.send_webpush_notice(user, pusher, data, notify).await
}, },
| PusherKind::Email(_) | PusherKind::Custom { .. } => Ok(()), | _ => Ok(()),
} }
} }
+14
View File
@@ -3,6 +3,7 @@ mod vapid;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
use conduwuit::config::experiments::ToggledExperiment;
use conduwuit_core::{ use conduwuit_core::{
Err, Result, debug, debug_warn, err, Err, Result, debug, debug_warn, err,
utils::{self, string::constant_time_eq}, utils::{self, string::constant_time_eq},
@@ -85,6 +86,9 @@ impl Service {
/// Reports whether a Web Push pusher has completed its activation /// Reports whether a Web Push pusher has completed its activation
/// handshake. /// handshake.
pub async fn is_webpush_activated(&self, sender: &UserId, pushkey: &str) -> bool { pub async fn is_webpush_activated(&self, sender: &UserId, pushkey: &str) -> bool {
if !self.services.config.experiments.msc4174.is_enabled() {
return false;
}
self.webpush_state(sender, pushkey).await.activated self.webpush_state(sender, pushkey).await.activated
} }
@@ -109,6 +113,9 @@ impl Service {
pusher: &Pusher, pusher: &Pusher,
previous: Option<&Pusher>, previous: Option<&Pusher>,
) -> bool { ) -> bool {
if !self.services.config.experiments.msc4174.is_enabled() {
return false;
}
let Some(data) = pusher.kind.as_webpush() else { let Some(data) = pusher.kind.as_webpush() else {
return false; return false;
}; };
@@ -126,6 +133,13 @@ impl Service {
} }
pub(super) fn begin_webpush_activation(&self, sender: &UserId, pusher: &Pusher) { pub(super) fn begin_webpush_activation(&self, sender: &UserId, pusher: &Pusher) {
debug_assert!(
self.services.config.experiments.msc4174.is_enabled(),
"begin_webpush_activation should not be called with MSC4174 disabled"
);
if !self.services.config.experiments.msc4174.is_enabled() {
return;
}
// Send a one-time encrypted token before allowing notification // Send a one-time encrypted token before allowing notification
// delivery. // delivery.
let token = utils::rand::string(ACK_TOKEN_LENGTH); let token = utils::rand::string(ACK_TOKEN_LENGTH);
+168
View File
@@ -0,0 +1,168 @@
use std::{
sync::Arc,
time::{Duration, SystemTime},
};
use conduwuit::{Err, Result, SyncMappedMutexGuard, SyncMutex, SyncMutexGuard, at, err, utils};
use lru_cache::LruCache;
use ruma::{
OwnedTransactionId,
api::client::rendezvous::{
create_rendezvous_session, delete_rendezvous_session, get_rendezvous_session,
update_rendezvous_session,
},
};
pub struct Service {
sessions: SyncMutex<LruCache<String, Session>>,
}
struct Session {
data: String,
created_at: SystemTime,
last_sequence_token: String,
transaction_sequences: LruCache<OwnedTransactionId, String>,
}
impl Session {
const SAVED_TRANSACTION_SEQUENCES: usize = 256;
fn new(data: String, sequence_token: String) -> Self {
Self {
data,
created_at: SystemTime::now(),
last_sequence_token: sequence_token,
transaction_sequences: LruCache::new(Self::SAVED_TRANSACTION_SEQUENCES),
}
}
}
impl crate::Service for Service {
fn build(_: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
sessions: SyncMutex::new(LruCache::new(Self::MAX_SESSIONS)),
}))
}
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
}
impl Service {
const MAX_DATA_SIZE_BYTES: usize = 4096;
const MAX_SESSIONS: usize = 256;
const SESSION_MAX_AGE: Duration = Duration::from_secs(300);
const TOKEN_LENGTH: usize = 32;
fn create_token() -> String { utils::random_string(Self::TOKEN_LENGTH) }
/// Lock and fetch an unexpired rendezvous session.
fn lock_session(&self, id: &str) -> Result<SyncMappedMutexGuard<'_, Session>> {
// We don't clear out expired sessions manually, the LRU cache will
// evict them over time
SyncMutexGuard::try_map_or_err(self.sessions.lock(), |sessions| {
sessions
.get_mut(id)
.filter(|session| {
SystemTime::now()
.duration_since(session.created_at)
.is_ok_and(|duration| duration < Self::SESSION_MAX_AGE)
})
.ok_or_else(|| err!(Request(NotFound("Unknown session"))))
})
.map_err(at!(1))
}
/// Create a fresh rendezvous session.
pub fn create_session(
&self,
data: String,
) -> Result<create_rendezvous_session::msc4388::Response> {
if data.len() > Self::MAX_DATA_SIZE_BYTES {
return Err!(Request(TooLarge("Data too large")));
}
let id = Self::create_token();
let sequence_token = Self::create_token();
self.sessions
.lock()
.insert(id.clone(), Session::new(data, sequence_token.clone()));
Ok(create_rendezvous_session::msc4388::Response::new(
id,
sequence_token,
Self::SESSION_MAX_AGE,
))
}
/// Update a rendezvous session with new data.
pub fn update_session(
&self,
id: &str,
transaction: OwnedTransactionId,
sequence_token: String,
data: String,
) -> Result<update_rendezvous_session::msc4388::Response> {
let mut session = self.lock_session(id)?;
// If the provided transaction ID was used already, we have to return
// the sequence token that we returned last time it was used.
// This makes session updates with the same transaction ID idempotent.
if let Some(sequence_token) = session.transaction_sequences.get_mut(&transaction) {
return Ok(update_rendezvous_session::msc4388::Response::new(
sequence_token.to_owned(),
));
}
if session.last_sequence_token != sequence_token {
return Err!(Request(ConcurrentWrite("Sequence token mismatch")));
}
drop(sequence_token);
let new_sequence_token = Self::create_token();
if data.len() > Self::MAX_DATA_SIZE_BYTES {
return Err!(Request(TooLarge("Data too large")));
}
session.data = data;
session.last_sequence_token.clone_from(&new_sequence_token);
session
.transaction_sequences
.insert(transaction, new_sequence_token.clone());
Ok(update_rendezvous_session::msc4388::Response::new(new_sequence_token))
}
/// Look up a rendezvous session by ID.
pub fn get_session(&self, id: &str) -> Result<get_rendezvous_session::msc4388::Response> {
let session = self.lock_session(id)?;
let session_age = SystemTime::now()
.duration_since(session.created_at)
.unwrap_or(Duration::MAX);
let session_time_remaining = Self::SESSION_MAX_AGE.saturating_sub(session_age);
Ok(get_rendezvous_session::msc4388::Response::new(
session.last_sequence_token.clone(),
session.data.clone(),
session_time_remaining,
))
}
/// Delete a rendezvous session.
pub fn delete_session(
&self,
id: &str,
) -> Result<delete_rendezvous_session::msc4388::Response> {
let mut sessions = self.sessions.lock();
if sessions.remove(id).is_some() {
Ok(delete_rendezvous_session::msc4388::Response::new())
} else {
Err!(Request(NotFound("Unknown session")))
}
}
}
+2 -2
View File
@@ -153,7 +153,7 @@ impl Service {
.get_member(room_id, sender_user) .get_member(room_id, sender_user)
.await .await
.ok() .ok()
.map_or_else(|| MembershipState::Leave, |content| content.membership) .map_or(MembershipState::Leave, |content| content.membership)
} else { } else {
MembershipState::Leave MembershipState::Leave
}; };
@@ -534,7 +534,7 @@ impl Service {
return state; return state;
}, },
}; };
if !pdu_fits(&value.clone()) { if !pdu_fits(&value) {
warn!( warn!(
"dropping incoming PDU {event_id} in room {room_id} from room join \ "dropping incoming PDU {event_id} in room {room_id} from room join \
because it exceeds 65535 bytes or is otherwise too large." because it exceeds 65535 bytes or is otherwise too large."
+1 -4
View File
@@ -8,10 +8,7 @@ use conduwuit::{
utils::{self, IterStream, ReadyExt}, utils::{self, IterStream, ReadyExt},
}; };
use database::{Deserialized, Get, Map, Qry}; use database::{Deserialized, Get, Map, Qry};
use futures::{ use futures::{Stream, StreamExt, stream};
Stream, StreamExt,
stream::{self},
};
use ruma::{EventId, OwnedEventId, RoomId, events::StateEventType}; use ruma::{EventId, OwnedEventId, RoomId, events::StateEventType};
use serde::Deserialize; use serde::Deserialize;
+5 -8
View File
@@ -264,14 +264,11 @@ impl Service {
.compress_state_event(shortstatekey, &new_pdu.event_id) .compress_state_event(shortstatekey, &new_pdu.event_id)
.await; .await;
let replaces = states_parents let replaces = states_parents.last().map_or_default(|info| {
.last() info.full_state
.map(|info| { .iter()
info.full_state .find(|bytes| bytes.starts_with(&shortstatekey.to_be_bytes()))
.iter() });
.find(|bytes| bytes.starts_with(&shortstatekey.to_be_bytes()))
})
.unwrap_or_default();
if Some(&new) == replaces { if Some(&new) == replaces {
return Ok(previous_shortstatehash.expect("must exist")); return Ok(previous_shortstatehash.expect("must exist"));
+1 -1
View File
@@ -745,7 +745,7 @@ impl Service {
.get_member(room_id, querying_user) .get_member(room_id, querying_user)
.await .await
.ok() .ok()
.map_or_else(|| MembershipState::Leave, |content| content.membership); .map_or(MembershipState::Leave, |content| content.membership);
if matches!(membership, MembershipState::Join | MembershipState::Invite) { if matches!(membership, MembershipState::Join | MembershipState::Invite) {
return true; return true;
+4 -4
View File
@@ -54,7 +54,7 @@ pub fn pdu_fits(owned_obj: &CanonicalJsonObject) -> bool {
} }
// Now check the full PDU size // Now check the full PDU size
match serde_json::to_string(owned_obj) { match serde_json::to_string(owned_obj) {
| Ok(s) => s.len() <= 65535, | Ok(s) => s.len() <= 65536,
| Err(_) => false, | Err(_) => false,
} }
} }
@@ -305,7 +305,7 @@ impl super::Service {
{ {
return match e { return match e {
| Error::SignatureJson(ruma::signatures::JsonError::PduTooLarge) => { | Error::SignatureJson(ruma::signatures::JsonError::PduTooLarge) => {
Err!(Request(TooLarge("Message/PDU is too long (exceeds 65535 bytes)"))) Err!(Request(TooLarge("Message/PDU is too long (exceeds 65536 bytes)")))
}, },
| _ => Err!(Request(Unknown(warn!("Signing event failed: {e}")))), | _ => Err!(Request(Unknown(warn!("Signing event failed: {e}")))),
}; };
@@ -330,9 +330,9 @@ impl super::Service {
pdu_json pdu_json
.insert("event_id".into(), CanonicalJsonValue::String(pdu.event_id.clone().into())); .insert("event_id".into(), CanonicalJsonValue::String(pdu.event_id.clone().into()));
// Verify that the *full* PDU isn't over 64KiB. // Verify that the *full* PDU isn't over 64KiB.
if !pdu_fits(&pdu_json.clone()) { if !pdu_fits(&pdu_json) {
// feckin huge PDU mate // feckin huge PDU mate
return Err!(Request(TooLarge("Message/PDU is too long (exceeds 65535 bytes)"))); return Err!(Request(TooLarge("Message/PDU is too long (exceeds 65536 bytes)")));
} }
// Check with the policy server // Check with the policy server
+1 -6
View File
@@ -1,10 +1,5 @@
use conduwuit::config::experiments::ToggledExperiment; use conduwuit::config::experiments::ToggledExperiment;
use conduwuit_core::{ use conduwuit_core::{Err, Result, err, matrix::event::Event, utils, warn};
Err, Result, err,
matrix::event::Event,
utils::{self},
warn,
};
use ruma::{EventId, events::room::encrypted::Relation, signatures::content_hash}; use ruma::{EventId, events::room::encrypted::Relation, signatures::content_hash};
use super::{ExtractBody, ExtractRelatesTo}; use super::{ExtractBody, ExtractRelatesTo};
+9 -9
View File
@@ -241,9 +241,9 @@ impl super::Service {
continue; continue;
} }
}; };
trace!(?origin_response, "Got signing key response from origin"); trace!(?origin_response.raw, "Got signing key response from origin");
self.add_signing_keys(&origin_response); self.add_signing_keys(&origin_response);
Self::track_result(&mut result, &mut still_missing, &origin_response); Self::track_result(&mut result, &mut still_missing, &origin_response.parsed);
if still_missing.is_empty() { if still_missing.is_empty() {
break; break;
} }
@@ -262,9 +262,9 @@ impl super::Service {
"Got signing keys response from a notary" "Got signing keys response from a notary"
); );
for server_keys in notary_response { for server_keys in notary_response {
trace!(?server_keys, "Adding response from notary"); trace!(?server_keys.raw, "Adding response from notary");
self.add_signing_keys(&server_keys); self.add_signing_keys(&server_keys);
Self::track_result(&mut result, &mut still_missing, &server_keys); Self::track_result(&mut result, &mut still_missing, &server_keys.parsed);
if still_missing.is_empty() { if still_missing.is_empty() {
break; break;
} }
@@ -285,9 +285,9 @@ impl super::Service {
continue; continue;
}; };
for server_keys in res { for server_keys in res {
trace!(?server_keys, "Adding response from notary"); trace!(?server_keys.raw, "Adding response from notary");
self.add_signing_keys(&server_keys); self.add_signing_keys(&server_keys);
Self::track_result(&mut result, &mut still_missing, &server_keys); Self::track_result(&mut result, &mut still_missing, &server_keys.parsed);
} }
if still_missing.is_empty() { if still_missing.is_empty() {
break; break;
@@ -300,9 +300,9 @@ impl super::Service {
debug_warn!(err=?res.err(), "Got error response from origin"); debug_warn!(err=?res.err(), "Got error response from origin");
continue; continue;
}; };
trace!(response=?res, "Got signing key response from origin"); trace!(response=?res.raw, "Got signing key response from origin");
self.add_signing_keys(&res); self.add_signing_keys(&res);
Self::track_result(&mut result, &mut still_missing, &res); Self::track_result(&mut result, &mut still_missing, &res.parsed);
if still_missing.is_empty() { if still_missing.is_empty() {
break; break;
} }
@@ -400,7 +400,7 @@ impl super::Service {
.inspect_err(|e| info!("Could not acquire signing key from origin server: {e:?}")) .inspect_err(|e| info!("Could not acquire signing key from origin server: {e:?}"))
.ok()?; .ok()?;
verify_key_from_response(key_id, &response, min_valid_ts) verify_key_from_response(key_id, &response.parsed, min_valid_ts)
.inspect(|_| self.add_signing_keys(&response)) .inspect(|_| self.add_signing_keys(&response))
} }
} }
+13 -7
View File
@@ -19,8 +19,10 @@ use ruma::{
ServerSigningKeyId, ServerSigningKeyId,
api::federation::discovery::{ServerSigningKeys, VerifyKey}, api::federation::discovery::{ServerSigningKeys, VerifyKey},
room_version_rules::RoomVersionRules, room_version_rules::RoomVersionRules,
serde::Raw,
signatures::{Ed25519KeyPair, PublicKeyMap, PublicKeySet}, signatures::{Ed25519KeyPair, PublicKeyMap, PublicKeySet},
}; };
use verify::IncomingServerKeys;
use crate::{Dep, globals, sending, server_keys::util::required_keys}; use crate::{Dep, globals, sending, server_keys::util::required_keys};
@@ -83,19 +85,22 @@ impl Service {
} }
/// Adds a signing key response to the database. /// Adds a signing key response to the database.
fn add_signing_keys(&self, new_keys: &ServerSigningKeys) { fn add_signing_keys(&self, new_keys: &IncomingServerKeys) {
// TODO(nex): this results in massive amounts of data duplication. // TODO(nex): this results in massive amounts of data duplication.
// Perhaps a sliding approach would be better? where we just update the // Perhaps a sliding approach would be better? where we just update the
// last known response if the only thing that changed was the // last known response if the only thing that changed was the
// valid_until_ts. This would require a more complex data structure // valid_until_ts. This would require a more complex data structure
// though. For now, just storing the duplicated data is fine. // though. For now, just storing the duplicated data is fine.
for key in new_keys for key in new_keys
.parsed
.verify_keys .verify_keys
.keys() .keys()
.chain(new_keys.old_verify_keys.keys()) .chain(new_keys.parsed.old_verify_keys.keys())
{ {
let db_key = (new_keys.server_name.as_str(), key.as_str()); let db_key = (new_keys.parsed.server_name.as_str(), key.as_str());
self.db.servernamekeyid_response.put(db_key, Json(new_keys)); self.db
.servernamekeyid_response
.put(db_key, Json(&new_keys.raw));
} }
} }
@@ -170,7 +175,7 @@ impl Service {
let mut keys = self let mut keys = self
.signing_keys_for(origin) .signing_keys_for(origin)
.ready_fold(BTreeMap::new(), |mut base, keys| { .ready_fold(BTreeMap::new(), |mut base, keys| {
base.extend(keys.verify_keys); base.extend(keys.parsed.verify_keys);
base base
}) })
.await; .await;
@@ -186,11 +191,12 @@ impl Service {
pub fn signing_keys_for<'a>( pub fn signing_keys_for<'a>(
&'a self, &'a self,
origin: &'a ServerName, origin: &'a ServerName,
) -> impl Stream<Item = ServerSigningKeys> + Send + 'a { ) -> impl Stream<Item = IncomingServerKeys> + Send + 'a {
self.db self.db
.servernamekeyid_response .servernamekeyid_response
.stream_prefix(&(origin, Interfix)) .stream_prefix(&(origin, Interfix))
.ignore_err() .ignore_err()
.map(|(_, v): (Ignore, ServerSigningKeys)| v) .map(|(_, v): (Ignore, Raw<ServerSigningKeys>)| v.try_into().map_err(Into::into))
.ignore_err()
} }
} }
+37 -30
View File
@@ -4,7 +4,6 @@ use conduwuit::{Err, Result, trace, utils::millis_since_unix_epoch, warn};
use ruma::{ use ruma::{
MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedServerSigningKeyId, ServerName, UInt, MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedServerSigningKeyId, ServerName, UInt,
api::federation::discovery::{ api::federation::discovery::{
ServerSigningKeys,
get_remote_server_keys_batch::{ get_remote_server_keys_batch::{
self, self,
v2::{QueryCriteria, Response as NotaryResponse}, v2::{QueryCriteria, Response as NotaryResponse},
@@ -15,6 +14,8 @@ use ruma::{
uint, uint,
}; };
use crate::server_keys::verify::IncomingServerKeys;
pub(crate) type ServerKeysQuery = BTreeMap<OwnedServerName, ServerKeysQuerySet>; pub(crate) type ServerKeysQuery = BTreeMap<OwnedServerName, ServerKeysQuerySet>;
pub(crate) type ServerKeysQuerySet = BTreeMap<OwnedServerSigningKeyId, QueryCriteria>; pub(crate) type ServerKeysQuerySet = BTreeMap<OwnedServerSigningKeyId, QueryCriteria>;
@@ -27,32 +28,33 @@ impl super::Service {
&self, &self,
target: OwnedServerName, target: OwnedServerName,
min_valid_ts: MilliSecondsSinceUnixEpoch, min_valid_ts: MilliSecondsSinceUnixEpoch,
) -> Result<ServerSigningKeys> { ) -> Result<IncomingServerKeys> {
use get_server_keys::v2::Request; use get_server_keys::v2::Request;
let server_signing_key = self let raw_server_key = self
.services .services
.sending .sending
.send_unauthenticated_request(&target, Request::new()) .send_unauthenticated_request(&target, Request::new())
.await .await
.map(|response| response.server_key) .map(|response| response.server_key)?;
.and_then(|key| key.deserialize().map_err(Into::into))?;
if server_signing_key.server_name != target { let server_signing_key: IncomingServerKeys = raw_server_key.try_into()?;
if server_signing_key.parsed.server_name != target {
return Err!(BadServerResponse(debug_warn!( return Err!(BadServerResponse(debug_warn!(
requested = ?target, requested = ?target,
response = ?server_signing_key.server_name, response = ?server_signing_key.parsed.server_name,
"Origin server responded with bogus server_name" "Origin server responded with bogus server_name"
))); )));
} }
if server_signing_key.valid_until_ts < min_valid_ts if server_signing_key.parsed.valid_until_ts < min_valid_ts
|| server_signing_key.valid_until_ts > in_one_week() || server_signing_key.parsed.valid_until_ts > in_one_week()
{ {
return Err!(BadServerResponse(debug_warn!( return Err!(BadServerResponse(debug_warn!(
?target, ?target,
?min_valid_ts, ?min_valid_ts,
?server_signing_key.valid_until_ts, ?server_signing_key.parsed.valid_until_ts,
"Origin server responded with server keys that are not in-date" "Origin server responded with server keys that are not in-date"
))); )));
} }
@@ -83,7 +85,7 @@ impl super::Service {
&self, &self,
notary: &ServerName, notary: &ServerName,
batch: ServerKeysQuery, batch: ServerKeysQuery,
) -> Result<Vec<ServerSigningKeys>> { ) -> Result<Vec<IncomingServerKeys>> {
use get_remote_server_keys_batch::v2::Request; use get_remote_server_keys_batch::v2::Request;
let is_empty = batch.is_empty() || batch.values().all(BTreeMap::is_empty); let is_empty = batch.is_empty() || batch.values().all(BTreeMap::is_empty);
@@ -99,8 +101,7 @@ impl super::Service {
.trusted_servers .trusted_servers
.iter() .iter()
.find(|n| n.server_name() == notary) .find(|n| n.server_name() == notary)
.map(|nk| nk.verify_keys().to_owned()) .map_or_default(|nk| nk.verify_keys().to_owned());
.unwrap_or_default();
let keys = self let keys = self
.services .services
.sending .sending
@@ -116,12 +117,12 @@ impl super::Service {
} }
/// Parses a notary response, returning a vec of server signing key /// Parses a notary response, returning a vec of server signing key
/// responses. Drops any chunks that cannot be deserialized. /// responses, each paired with its raw JSON (which is what the signatures
fn parse_notary_response(raw: &NotaryResponse) -> Vec<ServerSigningKeys> { /// were made over). Drops any chunks that cannot be deserialized.
fn parse_notary_response(raw: &NotaryResponse) -> Vec<IncomingServerKeys> {
raw.server_keys raw.server_keys
.iter() .iter()
.map(ruma::serde::Raw::deserialize) .filter_map(|chunk| chunk.try_into().ok())
.filter_map(Result::ok)
.collect() .collect()
} }
@@ -129,12 +130,15 @@ impl super::Service {
/// if the response should be dropped, true if it should be kept. /// if the response should be dropped, true if it should be kept.
fn validate_notary_chunk( fn validate_notary_chunk(
batch: &ServerKeysQuery, batch: &ServerKeysQuery,
keys: &ServerSigningKeys, incoming: &IncomingServerKeys,
notary_name: &ServerName, notary_name: &ServerName,
notary_keys: &[Base64], notary_keys: &[Base64],
) -> bool { ) -> bool {
let Some(expected_keys) = batch.get(&keys.server_name) else { let Some(expected_keys) = batch.get(&incoming.parsed.server_name) else {
trace!("Dropping signing keys chunk for unrequested server: {}", keys.server_name); trace!(
"Dropping signing keys chunk for unrequested server: {}",
incoming.parsed.server_name
);
return false; return false;
}; };
let min_valid_ts = expected_keys let min_valid_ts = expected_keys
@@ -148,13 +152,15 @@ impl super::Service {
// If this notary response is older than any of the min_valid_ts we // If this notary response is older than any of the min_valid_ts we
// requested, then we should drop it. // requested, then we should drop it.
if keys.valid_until_ts < min_valid_ts || keys.valid_until_ts > in_one_week() { if incoming.parsed.valid_until_ts < min_valid_ts
|| incoming.parsed.valid_until_ts > in_one_week()
{
trace!( trace!(
?min_valid_ts, ?min_valid_ts,
?keys.valid_until_ts, ?incoming.parsed.valid_until_ts,
"Dropping signing keys chunk for server {} because it is older than the minimum \ "Dropping signing keys chunk for server {} because it is older than the minimum \
valid timestamp we requested", valid timestamp we requested",
keys.server_name incoming.parsed.server_name
); );
return false; return false;
} }
@@ -162,38 +168,39 @@ impl super::Service {
// Does this chunk even contain any keys we asked for? // Does this chunk even contain any keys we asked for?
// Note that this enforces min_valid_ts per-key, instead of using the // Note that this enforces min_valid_ts per-key, instead of using the
// lowest denominator. // lowest denominator.
let all_key_ids = keys let all_key_ids = incoming
.parsed
.verify_keys .verify_keys
.keys() .keys()
.chain(keys.old_verify_keys.keys()) .chain(incoming.parsed.old_verify_keys.keys())
.map(ToOwned::to_owned) .map(ToOwned::to_owned)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let interesting = expected_keys.iter().any(|(k, q)| { let interesting = expected_keys.iter().any(|(k, q)| {
all_key_ids.contains(k) all_key_ids.contains(k)
&& q.minimum_valid_until_ts && q.minimum_valid_until_ts
.is_none_or(|m| m <= keys.valid_until_ts) .is_none_or(|m| m <= incoming.parsed.valid_until_ts)
}); });
if !interesting { if !interesting {
trace!( trace!(
"Dropping signing keys chunk for server {} because it does not contain any keys \ "Dropping signing keys chunk for server {} because it does not contain any keys \
we requested", we requested",
keys.server_name incoming.parsed.server_name
); );
return false; return false;
} }
Self::verify_server_keys_response(keys, Some((notary_name, notary_keys))) Self::verify_server_keys_response(incoming, Some((notary_name, notary_keys)))
.inspect_err(|e| { .inspect_err(|e| {
trace!( trace!(
?e, ?e,
?keys, ?incoming.raw,
?notary_name, ?notary_name,
?notary_keys, ?notary_keys,
"Dropping illegal server signing keys response chunk" "Dropping illegal server signing keys response chunk"
); );
warn!( warn!(
%notary_name, %notary_name,
server_name=%keys.server_name, server_name=%incoming.parsed.server_name,
"Dropping illegal server signing keys response chunk: {e:?}" "Dropping illegal server signing keys response chunk: {e:?}"
); );
}) })
+92 -29
View File
@@ -5,11 +5,36 @@ use ruma::{
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, ServerName, SigningKeyAlgorithm, CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, ServerName, SigningKeyAlgorithm,
api::federation::discovery::ServerSigningKeys, api::federation::discovery::ServerSigningKeys,
room_version_rules::RoomVersionRules, room_version_rules::RoomVersionRules,
serde::{Base64, base64::Standard}, serde::{Base64, Raw, base64::Standard},
signatures::Verified, signatures::Verified,
}; };
use serde_json::value::RawValue as RawJsonValue; 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 { impl super::Service {
/// Validates the incoming event only using locally known verification keys. /// Validates the incoming event only using locally known verification keys.
/// Inserts the calculated event ID into the event_id field upon success. /// Inserts the calculated event ID into the event_id field upon success.
@@ -58,34 +83,38 @@ impl super::Service {
/// `notary` must either be empty or have ONE entry. Extraneous notaries /// `notary` must either be empty or have ONE entry. Extraneous notaries
/// will be ignored. /// will be ignored.
pub fn verify_server_keys_response( pub fn verify_server_keys_response(
server_keys: &ServerSigningKeys, incoming: &IncomingServerKeys,
notary: Option<(&ServerName, &[Base64])>, notary: Option<(&ServerName, &[Base64])>,
) -> Result<()> { ) -> Result<()> {
if let Some((notary_name, notary_keys)) = notary { if let Some((notary_name, notary_keys)) = notary {
if !notary_keys.is_empty() { if !notary_keys.is_empty() {
Self::verify_notary_signature(server_keys, notary_name, notary_keys)?; Self::verify_notary_signature(incoming, notary_name, notary_keys)?;
} }
} }
// NOTE: old_verify_keys aren't considered here because old keys can't // NOTE: old_verify_keys aren't considered here because old keys can't
// be used to sign key responses. // be used to sign key responses.
let mut set = ruma::signatures::PublicKeySet::new(); let mut set = ruma::signatures::PublicKeySet::new();
server_keys.verify_keys.iter().for_each(|(key_id, key)| { incoming
set.insert(key_id.to_string(), key.key.clone()); .parsed
}); .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(); let mut pubkey_map = ruma::signatures::PublicKeyMap::new();
pubkey_map.insert(server_keys.server_name.to_string(), set); pubkey_map.insert(incoming.parsed.server_name.to_string(), set);
let mut canonical = to_canonical_object(server_keys)?; let mut canonical = to_canonical_object(&incoming.raw)?;
Self::strip_extraneous_signatures(&mut canonical, &server_keys.server_name, &[]); Self::strip_extraneous_signatures(&mut canonical, &incoming.parsed.server_name, &[]);
ruma::signatures::verify_json(&pubkey_map, &canonical).map_err(Into::into) ruma::signatures::verify_json(&pubkey_map, &canonical).map_err(Into::into)
} }
/// Verifies that the notary has at least one valid signature present with /// Verifies that the notary has at least one valid signature present with
/// the provided signing keys. /// the provided signing keys.
fn verify_notary_signature( fn verify_notary_signature(
server_keys: &ServerSigningKeys, incoming: &IncomingServerKeys,
notary_name: &ServerName, notary_name: &ServerName,
notary_keys: &[Base64], notary_keys: &[Base64],
) -> Result<()> { ) -> Result<()> {
@@ -94,19 +123,16 @@ impl super::Service {
// certificate has been compromised, which would otherwise allow // certificate has been compromised, which would otherwise allow
// them to produce attacker-controlled signing keys with valid // them to produce attacker-controlled signing keys with valid
// self-signatures. // self-signatures.
let Some(notary_signatures) = server_keys.signatures.get(notary_name) else { let Some(notary_signatures) = incoming.parsed.signatures.get(notary_name) else {
return Err!(Request(Forbidden( return Err!(Request(Forbidden(
"Missing notary server signature from {notary_name}" "Missing notary server signature from {notary_name}"
))); )));
}; };
let mut canonical_object = to_canonical_object(notary_signatures)?; // The notary signed the response as the origin served it, so verify
Self::strip_extraneous_signatures(&mut canonical_object, &server_keys.server_name, &[ // over the raw JSON, not a re-serialised `ServerSigningKeys`.
notary_name,
]);
let for_verify = ruma::signatures::to_canonical_json_string_for_signing( let for_verify = ruma::signatures::to_canonical_json_string_for_signing(
&to_canonical_object(server_keys).expect("server keys object must be canonical json"), &to_canonical_object(&incoming.raw)?,
) )?;
.expect("canonical JSON must be stringable");
let raw_notary_keys = notary_keys.iter().map(Base64::as_bytes).collect::<Vec<_>>(); let raw_notary_keys = notary_keys.iter().map(Base64::as_bytes).collect::<Vec<_>>();
let raw_notary_signatures = notary_signatures let raw_notary_signatures = notary_signatures
@@ -126,7 +152,7 @@ impl super::Service {
trace!( trace!(
"Valid signature from {notary_name} present on signing keys response \ "Valid signature from {notary_name} present on signing keys response \
for {}", for {}",
server_keys.server_name incoming.parsed.server_name
); );
return Ok(()); return Ok(());
} }
@@ -181,9 +207,9 @@ mod tests {
} }
} }
} }
)).map(Raw::from_json).unwrap(); )).map(Raw::from_json).unwrap().try_into().unwrap();
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None) Service::verify_server_keys_response(&response_data, None)
.expect("Self-signature of real key response is valid"); .expect("Self-signature of real key response is valid");
} }
@@ -208,9 +234,9 @@ mod tests {
} }
} }
} }
)).map(Raw::from_json).unwrap(); )).map(Raw::from_json).unwrap().try_into().unwrap();
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None) Service::verify_server_keys_response(&response_data, None)
.expect("Self-signature of real key response is valid"); .expect("Self-signature of real key response is valid");
} }
@@ -235,11 +261,11 @@ mod tests {
} }
} }
} }
)).map(Raw::from_json).unwrap(); )).map(Raw::from_json).unwrap().try_into().unwrap();
let starstruck_pubkey = let starstruck_pubkey =
Base64::<Standard>::parse("Z4oHuEjdUbtC5W/z/gzc5B8raxNk+8gGwbNwgxHqW8Y").unwrap(); Base64::<Standard>::parse("Z4oHuEjdUbtC5W/z/gzc5B8raxNk+8gGwbNwgxHqW8Y").unwrap();
Service::verify_server_keys_response( Service::verify_server_keys_response(
&response_data.deserialize().unwrap(), &response_data,
Some((server_name!("starstruck.systems"), &[starstruck_pubkey])), Some((server_name!("starstruck.systems"), &[starstruck_pubkey])),
) )
.expect("Server keys from notary are valid"); .expect("Server keys from notary are valid");
@@ -265,8 +291,8 @@ mod tests {
} }
} }
} }
)).map(Raw::from_json).unwrap(); )).map(Raw::from_json).unwrap().try_into().unwrap();
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None) Service::verify_server_keys_response(&response_data, None)
.expect_err("Tampered response should fail self-signature check"); .expect_err("Tampered response should fail self-signature check");
} }
@@ -303,8 +329,45 @@ mod tests {
} }
} }
} }
)).map(Raw::from_json).unwrap(); )).map(Raw::from_json).unwrap().try_into().unwrap();
Service::verify_server_keys_response(&response_data.deserialize().unwrap(), None) Service::verify_server_keys_response(&response_data, None)
.expect_err("Intercepted notary response should fail strict validation"); .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");
}
} }
+4 -2
View File
@@ -11,8 +11,8 @@ use crate::{
account_data, admin, announcements, antispam, appservice, client, config, emergency, account_data, admin, announcements, antispam, appservice, client, config, emergency,
federation, firstrun, globals, key_backups, mailer, federation, firstrun, globals, key_backups, mailer,
manager::Manager, manager::Manager,
media, moderation, oauth, oidc, presence, pusher, registration_tokens, rooms, sending, media, moderation, oauth, oidc, presence, pusher, registration_tokens, rendezvous, rooms,
server_keys, sending, server_keys,
service::{self, Args, Map, Service}, service::{self, Args, Map, Service},
sync, threepid, transactions, uiaa, users, sync, threepid, transactions, uiaa, users,
}; };
@@ -33,6 +33,7 @@ pub struct Services {
pub presence: Arc<presence::Service>, pub presence: Arc<presence::Service>,
pub pusher: Arc<pusher::Service>, pub pusher: Arc<pusher::Service>,
pub registration_tokens: Arc<registration_tokens::Service>, pub registration_tokens: Arc<registration_tokens::Service>,
pub rendezvous: Arc<rendezvous::Service>,
pub rooms: rooms::Service, pub rooms: rooms::Service,
pub federation: Arc<federation::Service>, pub federation: Arc<federation::Service>,
pub firstrun: Arc<firstrun::Service>, pub firstrun: Arc<firstrun::Service>,
@@ -89,6 +90,7 @@ impl Services {
presence: build!(presence::Service), presence: build!(presence::Service),
pusher: build!(pusher::Service), pusher: build!(pusher::Service),
registration_tokens: build!(registration_tokens::Service), registration_tokens: build!(registration_tokens::Service),
rendezvous: build!(rendezvous::Service),
rooms: rooms::Service { rooms: rooms::Service {
alias: build!(rooms::alias::Service), alias: build!(rooms::alias::Service),
auth_chain: build!(rooms::auth_chain::Service), auth_chain: build!(rooms::auth_chain::Service),
+1 -1
View File
@@ -143,7 +143,7 @@ impl Service {
) { ) {
let mut key = user_id.as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xFF); key.push(0xFF);
key.extend_from_slice(device_id.map(DeviceId::as_bytes).unwrap_or_default()); key.extend_from_slice(device_id.map_or_default(DeviceId::as_bytes));
key.push(0xFF); key.push(0xFF);
key.extend_from_slice(txn_id.as_bytes()); key.extend_from_slice(txn_id.as_bytes());
+26 -2
View File
@@ -4,7 +4,9 @@ use std::{
}; };
use conduwuit::{ use conduwuit::{
Err, Result, debug, debug_error, debug_warn, err, error, info, trace, Err, Result,
config::experiments::ToggledExperiment,
debug, debug_error, debug_warn, err, error, info, trace,
utils::{self, stream::TryIgnore}, utils::{self, stream::TryIgnore},
warn, warn,
}; };
@@ -107,6 +109,27 @@ impl super::Service {
if stable.is_err() && unstable.is_err() { if stable.is_err() && unstable.is_err() {
return FilterLevel::Default; return FilterLevel::Default;
} }
let msc4494_enabled = self.services.config.experiments.msc4494.is_enabled();
if !self.services.config.experiments.msc4155.is_enabled() {
// Only MSC4380 should be checked here, since it's in spec.
let Some(action) = stable.ok().and_then(|c| c.content.default_action) else {
return FilterLevel::Default;
};
return match action {
| InvitePermissionAction::Block => FilterLevel::Block,
| InvitePermissionAction::DenyPublic if msc4494_enabled => {
if !self
.check_msc4494_mutual_room(sender_user, recipient_user)
.await
{
FilterLevel::Block
} else {
FilterLevel::Default
}
},
| _ => FilterLevel::Allow,
};
}
let content = stable.unwrap_or_else(|_| unstable.unwrap()).content; let content = stable.unwrap_or_else(|_| unstable.unwrap()).content;
let verdict = content.user_filter_level(sender_user); let verdict = content.user_filter_level(sender_user);
if verdict != FilterLevel::Default { if verdict != FilterLevel::Default {
@@ -114,7 +137,8 @@ impl super::Service {
} }
// Apply other layers of invite blocking first, so that user/server // Apply other layers of invite blocking first, so that user/server
// denies take priority over implicit allows. // denies take priority over implicit allows.
if content.default_action == Some(InvitePermissionAction::DenyPublic) if msc4494_enabled
&& content.default_action == Some(InvitePermissionAction::DenyPublic)
&& !self && !self
.check_msc4494_mutual_room(sender_user, recipient_user) .check_msc4494_mutual_room(sender_user, recipient_user)
.await .await
+1 -4
View File
@@ -9,10 +9,7 @@ pub(super) mod remote;
use std::{mem, sync::Arc}; use std::{mem, sync::Arc};
pub use account::{AccessTokenStatus, AccountStatus}; pub use account::{AccessTokenStatus, AccountStatus};
use conduwuit::{ use conduwuit::{Err, Error, Result, err, utils};
Err, Error, Result, err,
utils::{self},
};
use database::Map; use database::Map;
pub use device::DeviceToken; pub use device::DeviceToken;
pub use profile::ProfileFieldChange; pub use profile::ProfileFieldChange;
@@ -23,7 +23,7 @@
</div> </div>
<div> <div>
{% if style != DeviceCardStyle::Detailed %} {% if style != DeviceCardStyle::Detailed %}
<a href="{{ crate::ROUTE_PREFIX }}/account/device/{{ device_id }}/">Details</a> <a href="{{ crate::ROUTE_PREFIX }}/account/device/{{ device_id | urlencode_strict }}/">Details</a>
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}