Compare commits

..
Author SHA1 Message Date
timedout 298113c0a6 feat: Update MSC4456 implementation, new route 2026-10-14 10:34:52 +01:00
timedout 62de19970e fix: Address review comments 2026-10-14 10:34:51 +01:00
timedout 6b532eb7d0 perf: Yield ssk instead of doing a serialization roundtrip 2026-10-14 10:34:51 +01:00
timedout b541aadc2b feat: Don't double-sign our own keys 2026-10-14 10:34:51 +01:00
timedout c1f6a7c082 fix: Don't do weird wire signing for server keys route 2026-10-14 10:34:51 +01:00
timedout 3508b1a5e3 fix: Don't make origin key requests to ourself
Intercepting the request and serving it locally seems like a pretty good blanket solution
2026-10-14 10:34:51 +01:00
timedout 9867e99bb2 fix: Typo (MSC4456 -> MSC4556) 2026-10-14 10:34:50 +01:00
timedout 7b180667e8 style: Reformat 2026-10-14 10:34:50 +01:00
timedout e001e4a68a fix: Pass correct object for signing 2026-10-14 10:34:50 +01:00
timedout 75383af35c chore: Update trusted_servers docs 2026-10-14 10:34:50 +01:00
timedout c486eeac06 fix: Don't serve expired responses in the criterialess path 2026-10-14 10:34:49 +01:00
timedout 1ded0b4e97 fix: Enforce specific notary limits per MSC4556 2026-10-14 10:34:49 +01:00
timedout cd94a0d3ab fix: Refuse to process >4096 servers and/or >8192 keys
pending msc
2026-10-14 10:34:49 +01:00
timedout 08307970a1 fix: Deduplicate signing key responses if we already satisfied them 2026-10-14 10:34:49 +01:00
timedout ebf7c9920a fix: Don't short circuit if all requested servers have no query criteria
Also adds some traces
2026-10-14 10:34:48 +01:00
timedout a15905e8c9 chore: Rebuild example config 2026-10-14 10:34:47 +01:00
timedout 19bc5d2016 feat: Correctly ask origin for keys before seeding from local cache 2026-10-14 10:32:36 +01:00
timedout 6bbebd8b54 chore: Add newsfrag 2026-10-14 10:32:36 +01:00
timedout 4e1fb09bfb fix: Maybe query origin when fetching latest keys 2026-10-14 10:32:36 +01:00
timedout 39cd151ca3 fix: Don't attempt to contact origins as a notary more than once a minute 2026-10-14 10:32:36 +01:00
timedout a5a7905494 fix: Actually contact origins in notary key fetching 2026-10-14 10:32:35 +01:00
timedout a05d7a8cf3 style: Condense repeated code into a reusable function 2026-10-14 10:32:35 +01:00
timedout af8ca8580e fix: Correctly sum total_queried_keys 2026-10-14 10:32:35 +01:00
timedout 7050ea84e3 feat: Strip extraneous signatures to avoid leaking our own notaries 2026-10-14 10:32:35 +01:00
timedout 441ab78c4e feat: Notary server 2026-10-14 10:32:34 +01:00
Renovate Bot a17a805293 chore(deps): update github-actions-digest 2026-10-13 05:17:44 +00:00
timedout 090203c2ea style: Remove import 2026-10-12 22:28:50 +01:00
timedout ff63d9f203 fix: Don't unconditionally mark gapfilled events as referenced
This is pointless and fallible
2026-10-12 22:28:50 +01:00
timedout 511e791b9f fix: Mark state and auth chain events as referenced after joining a room
It's generally safe to assume that all of these events have been referenced by the time we get to joining.
2026-10-12 22:28:50 +01:00
timedout bc70c4eaff fix: Mark PDUs as referenced during gapfill immediately 2026-10-12 22:28:50 +01:00
timedout bbbc9bc7d8 fix: Never add unknown events to the extremity tracker 2026-10-12 22:28:46 +01:00
Erwan Leboucher 7da0ef6e2b docs: Document environment variables for config options 2026-10-12 11:32:45 +01:00
Erwan Leboucher 24e289113b fix(pusher): Only strip notification_push_path as a URL suffix 2026-10-12 11:14:02 +01:00
Erwan Leboucher 805d4d9416 fix(pusher): Enforce ip_range_denylist on resolved pusher hosts 2026-10-12 11:14:02 +01:00
Erwan Leboucher fe0ab62124 refactor: Unify retry backoff helpers 2026-10-12 11:14:01 +01:00
stratself bd005edd59 fix(docs): Remove dead link in guides' _meta.json 2026-10-12 09:48:08 +00:00
stratself c66fb684f0 docs: Add guide for push notifications (#2244)
Adds a page for push notifications under /guides. The main thing it covers are how push works in Matrix, UnifiedPush usage and selfhosting, and some troubleshooting of common push issues.

I took the liberty to include various aspects of push not pertaining to the server itself, because it was commonly asked in our chatrooms and are quite important for all matrix users. Kind of like livekit.

Closes #2136

Reviewed-on: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2244
Reviewed-by: Jade Ellis <jade@ellis.link>
Reviewed-by: Henry-Hiles <henry@henryhiles.com>
Reviewed-by: lveneris <tyler@kludgecs.com>
2026-10-12 09:23:45 +00:00
theS1LV3R 0773cd1f78 chore: Update chanagelog to be more descript 2026-10-12 10:14:53 +01:00
theS1LV3R 929ef60780 chore: Add changelog 2026-10-12 10:14:53 +01:00
theS1LV3R 39bb4fefa1 feat: Add support for custom DNS servers
Adds an option `dns_servers` which takes IPs for custom servers.
Does not allow for custom DNS ports as this is largely not supported in
tokio and hickory, and would otherwise be a pain to implement properly.

Fixes: #1866
See-Also: https://matrix.to/#/!ksTlboXVgcyWjv5GrlEeKyQuJ8ZCprnwQx2b6-BQ44Q/%24qrBGOzosK4BdRbF5jhf5ehrxQUTaIr-U-UpqTmPhkPY?via=wolfgirl.pet&via=matrix.org
2026-10-12 10:14:53 +01:00
Sebastian Spaeth b4a2a457a1 debian: Change weekly versioning scheme
Right now our weekly Debian versioning scheme is VERSION="$BASE_VERSION~git$DATE.$SHA-$CLEAN_COMPONENT".
This sorts weekly releases AFTER the BASE_VERSION, so when both stable
and unstable are enabled, we never get weekly versions installed.
https://wiki.debian.org/Versioning proposes {upcoming_version}~git{date}.{hash}-{revision} for nightly releases, which means we would have to know the release number of the upcoming version in advance. I don't think that is useful for us.

By switching from a tilde to a dash, our weekly versions are not sorted
above the stable base version and we will install the weekly versions
over the base version, which I believe is closer to what we intend.

Fixes:  https://forgejo.ellis.link/continuwuation/continuwuity/issues/2081
2026-10-12 09:13:24 +00:00
Clubs dac940784d docs: Added the changelog for 2292 2026-10-12 10:10:17 +01:00
Clubs 8200487787 feat: add optional flags for filtering !admin user list, hide deactivated users by default 2026-10-12 10:10:14 +01:00
Renovate Bot b5c3da3f52 chore(deps): update dependency cargo-bins/cargo-binstall to v1.25.3 2026-10-12 09:05:37 +00:00
Jade Ellis 3975d31b91 refactor: Delegate otlp_protocol to standard OTLP env variables 2026-10-12 10:03:16 +01:00
Erwan Leboucher fd4cb4a306 fix(runtime): Log final runtime metrics at debug 2026-10-12 10:03:16 +01:00
Erwan Leboucher c79e9e29a3 fix(metrics): Skip instruments when no exporter is enabled 2026-10-12 10:03:16 +01:00
Erwan Leboucher 698edda6bd fix(metrics): Read database memory gauges without a cache 2026-10-12 10:03:15 +01:00
Erwan Leboucher ea3ec965ed fix(metrics): Address review feedback 2026-10-12 10:03:15 +01:00
Erwan Leboucher 9d454fd883 refactor(metrics): Use Tower HTTP instrumentation 2026-10-12 10:03:15 +01:00
Erwan Leboucher 4996471878 docs(metrics): Document OTLP export and update the dashboard 2026-10-12 10:03:14 +01:00
Erwan Leboucher 5185045cb6 feat(metrics): Record metrics with OpenTelemetry and export over OTLP 2026-10-12 10:03:14 +01:00
Erwan Leboucher e96b6e6665 chore(deps): Bump OpenTelemetry to 0.33 2026-10-12 10:03:14 +01:00
Erwan Leboucher e584e1a572 feat: Add Grafana dashboard for Prometheus metrics 2026-10-12 10:03:13 +01:00
Erwan Leboucher 31bce80524 fix(metrics): Start latency histogram buckets at 1ms 2026-10-12 10:03:13 +01:00
Erwan Leboucher f14c401f39 feat: Add Prometheus metrics endpoint 2026-10-12 10:03:12 +01:00
Jade Ellis ea96858c4a docs: Changelog 2026-10-12 10:01:06 +01:00
Jade Ellis 75c439a9d0 fix: Correctly set rocksdb descriptor_cf_options 2026-10-12 10:01:06 +01:00
Renovate Bot d3b9aee3ab chore(deps): update ghcr.io/renovatebot/renovate docker tag to v44.151.2 2026-10-12 05:03:12 +00:00
timedout 3af5302dd8 feat: Add more useful errors to send_join
See also: #2340
2026-10-10 02:23:39 +01:00
timedout 0415a35fa8 perf: Always treat self as healthy 2026-10-08 20:29:51 +01:00
timedout b76dc816a4 fix: Handle policy server errors better 2026-10-08 20:26:30 +01:00
timedout 536d96abb4 fix: Apply ignore filtering to peeking route
Reviewed-By: Jade Ellis <jade@ellis.link>
2026-10-08 19:02:59 +01:00
Renovate Bot 2fad908f27 chore(deps): update pre-commit hook crate-ci/typos to v1.51.1 2026-10-07 05:03:34 +00:00
Jade Ellis b081ac36ff chore: Replace deprecated kebab-case lints with snake_case 2026-10-07 00:23:28 +01:00
Jade Ellis c3ba97adb6 style: Resolve clippy warnings in database and service 2026-10-07 00:17:35 +01:00
Jade Ellis 30508ea353 chore: Ignore clippy lint assert_is_empty in workspace 2026-10-07 00:14:44 +01:00
Jade Ellis df3466e68d chore: Changelog 2026-10-06 23:56:32 +01:00
Jade Ellis 5d55b413a2 feat: Send private read receipts to appservices 2026-10-06 23:56:30 +01:00
Jade Ellis 7ce47be4de feat: Send read receipts and typing indicators to appservices 2026-10-06 23:56:28 +01:00
Ginger 7cedf9f322 fix: Always route userinfo endpoint 2026-10-06 22:22:56 +00:00
Jade Ellis 17f5ce10f4 chore: Update LLVM version 2026-10-06 23:18:49 +01:00
Renovate Bot 5f13bab52f chore(deps): update github-actions-digest 2026-10-06 05:01:46 +00:00
timedout c1e4f926c8 feat: Allow server admins to do timestamp massaging too 2026-10-06 02:34:10 +00:00
timedout 63578eba8c fix: Properly move /send redaction fields 2026-10-06 02:34:10 +00:00
timedout 20fe43d200 fix: Don't insert top-level redacts in v11+ rooms 2026-10-06 02:34:10 +00:00
timedout 1ffb1d637e fix: Don't invert redaction target helper 2026-10-06 02:34:10 +00:00
timedout 0224a558b3 fix: Stop embedding prev_content during event creation 2026-10-06 02:34:10 +00:00
Renovate Bot ae2e71ff45 chore(deps): update dependency cargo-bins/cargo-binstall to v1.25.1 2026-10-05 21:04:26 +00:00
renovate 52435fa02d chore(Nix): Updated flake hashes 2026-10-05 21:04:00 +00:00
Renovate Bot c0d8f5ab8b chore(deps): update rust to v1.99.0 2026-10-05 21:04:00 +00:00
Renovate Bot 80851bba06 chore(deps): update node-patch-updates to v2.0.23 2026-10-05 21:03:42 +00:00
Ginger 4d7341c32d fix: Check for client ID mismatch in step-up auth 2026-10-05 14:22:53 +00:00
Ginger 18f2118c42 fix: Make missing scope descriptions very obvious 2026-10-05 14:22:53 +00:00
Ginger 240c806d70 fix: Small cosmetic fixes 2026-10-05 14:22:53 +00:00
Ginger 2fdd59ae54 fix: Use ApiFullAccess as required scope for NoAccessToken endpoints 2026-10-05 14:22:53 +00:00
Ginger a8a6ab9e3d chore: Update news fragments 2026-10-05 14:22:53 +00:00
Ginger f55a5bd1c3 chore: Switch back to upstream Ruma 2026-10-05 14:22:53 +00:00
Ginger 7ab415c4b6 fix: Make require_auth_for_profile_requests work again 2026-10-05 14:22:53 +00:00
Ginger c9b0fbaeac chore: Update MSC4540 support 2026-10-05 14:22:53 +00:00
Ginger bc9b97e97f feat: Add support for MSC4540 2026-10-05 14:22:53 +00:00
Ginger 0d48c9681d feat: Give scope lists and device cards a fresh coat of paint 2026-10-05 14:22:53 +00:00
Ginger 38f8011b95 chore: Update ruma 2026-10-05 14:22:53 +00:00
Ginger e963adf524 feat: Add support for MSC4363 2026-10-05 14:22:53 +00:00
Ginger af84202ba4 fix: Don't bail on unrecognized OAuth scopes 2026-10-05 14:22:53 +00:00
Ginger 08b6ab4af7 chore: News fragment 2026-10-05 14:22:53 +00:00
Ginger 823ee9f6e1 feat: Add support for MSC4484 2026-10-05 14:22:53 +00:00
Ginger 3a20ad7ff2 refactor: Adjust auth check logic structure 2026-10-05 14:22:53 +00:00
Renovate Bot 4d4693494b chore(deps): update ghcr.io/renovatebot/renovate docker tag to v44.133.0 2026-10-05 05:03:04 +00:00
Jade Ellis 1e34bd2ed9 style: Run formatting 2026-10-05 00:27:12 +01:00
136 changed files with 11676 additions and 1308 deletions

No files matched your search

-149
View File
@@ -1,149 +0,0 @@
name: build-native
description: |
Compile the binary on the runner host rather than inside Docker, then assemble the
artefact tree the Docker packaging stages expect.
Intended for runners whose architecture matches the target, where a persistent local
sccache is available. Produces out/{sbin,sbom,libs,libs-root} for consumption as a
named build context.
inputs:
package:
description: Cargo package to build
required: false
default: conduwuit
profile:
description: Cargo build profile (release or release-max-perf)
required: true
features:
description: Comma-separated cargo features
required: false
default: default
march:
description: Value for -march passed to the C and C++ compilers
required: false
default: ''
rust-cpu-flags:
description: Architecture flags appended to RUSTFLAGS
required: false
default: ''
llvm-version:
description: LLVM major version the host toolchain must provide
required: false
default: '22'
target-dir:
description: Cargo target directory, defaults to one outside the per-run workspace
required: false
default: ''
out-dir:
description: Directory to assemble the artefact tree in
required: false
default: out
outputs:
out-dir:
description: Directory containing sbin/, sbom/, libs/ and libs-root/
value: ${{ steps.assemble.outputs.dir }}
runs:
using: composite
steps:
- name: Add cargo binaries to PATH
shell: bash
run: echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> "$GITHUB_PATH"
- name: Verify host toolchain
shell: bash
run: |
set -euo pipefail
fail=0
for tool in clang clang++ ld.lld cargo sccache cargo-sbom lddtree; do
if ! command -v "$tool" >/dev/null; then
echo "missing: $tool"
fail=1
fi
done
[ "$fail" -eq 0 ] || { echo "host is not provisioned for native builds"; exit 1; }
# Must match the container's ARG LLVM_VERSION or the two paths diverge.
got=$(clang --version | sed -n 's/.*clang version \([0-9]*\).*/\1/p' | head -1)
if [ "$got" != "${{ inputs.llvm-version }}" ]; then
echo "clang major version is $got, expected ${{ inputs.llvm-version }}"
exit 1
fi
echo "clang $got, $(cargo --version), $(sccache --version)"
- name: Configure build environment
shell: bash
run: |
set -euo pipefail
# Mirrors the values docker/Dockerfile writes into /etc/environment.
cflags="-flto"
if [ -n "${{ inputs.march }}" ]; then
cflags="$cflags -march=${{ inputs.march }}"
fi
{
echo "CARGO_INCREMENTAL=0"
echo "CC=clang"
echo "CXX=clang++"
echo "CFLAGS=$cflags"
echo "CXXFLAGS=$cflags"
echo "RUSTC_WRAPPER=sccache"
} >> "$GITHUB_ENV"
# Outside the per-run workspace, so cargo can reuse artefacts between runs.
target_dir="${{ inputs.target-dir }}"
[ -n "$target_dir" ] || target_dir="$HOME/.cache/continuwuity-target"
echo "CARGO_TARGET_DIR=$target_dir" >> "$GITHUB_ENV"
# A fat LTO link runs for minutes without compiling, which would otherwise
# idle the sccache server out and lose the statistics with it.
echo "SCCACHE_IDLE_TIMEOUT=1800" >> "$GITHUB_ENV"
rustflags='-Clinker-plugin-lto -Clink-arg=-fuse-ld=lld'
if [ -n "${{ inputs.rust-cpu-flags }}" ]; then
rustflags="$rustflags ${{ inputs.rust-cpu-flags }}"
fi
echo "RUSTFLAGS=$rustflags" >> "$GITHUB_ENV"
- name: Build
shell: bash
run: |
set -euo pipefail
sccache --zero-stats >/dev/null 2>&1 || true
cargo build --locked \
--profile ${{ inputs.profile }} \
--no-default-features --features ${{ inputs.features }} \
-p ${{ inputs.package }}
- name: Assemble artefact tree
id: assemble
shell: bash
run: |
set -euo pipefail
out="${{ inputs.out-dir }}"
rm -rf "$out"
mkdir -p "$out/sbin" "$out/sbom" "$out/libs" "$out/libs-root"
profile_dir="${{ inputs.profile }}"
[ "$profile_dir" = "dev" ] && profile_dir=debug
target_dir=$(cargo metadata --no-deps --format-version 1 | jq -r '.target_directory')
cp "$target_dir/$profile_dir/${{ inputs.package }}" "$out/sbin/${{ inputs.package }}"
cargo sbom --cargo-package ${{ inputs.package }} > "$out/sbom/${{ inputs.package }}.spdx.json"
# Resolved here, not in the container: these are the libraries linked against.
for binary in "$out"/sbin/*; do
resolved=$(lddtree "$binary" 2>/dev/null) || continue
[ -n "$resolved" ] || continue
echo "$resolved" | awk '{print $(NF-0) " " $1}' | sort -u -k 1,1 | \
awk -v out="$out" '{dest = ($2 ~ /^\//) ? out "/libs-root" $2 : out "/libs/" $2; print $1 " " dest}' | \
while read -r src dest; do install -D "$src" "$dest"; done
done
echo "dir=$out" >> "$GITHUB_OUTPUT"
find "$out" -type f -printf '%10s %P\n' | sort -k2
- name: Report cache statistics
shell: bash
run: sccache --show-stats || true
+1 -1
View File
@@ -71,7 +71,7 @@ runs:
- name: Install timelord-cli and git-warp-time
if: steps.check-binaries.outputs.need-install == 'true'
uses: https://github.com/taiki-e/install-action@4cef1412cce204788f482e778a0b9187f9626a29 # v2
uses: https://github.com/taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2
with:
tool: git-warp-time,timelord-cli@3.0.1
+1 -1
View File
@@ -144,7 +144,7 @@ jobs:
COMPONENT="dev-$(echo '${{ forge.ref_name }}' | sed 's/[^a-zA-Z0-9.+]/-/g' | tr '[:upper:]' '[:lower:]' | cut -c1-30)"
fi
CLEAN_COMPONENT=$(echo $COMPONENT | sed 's/[^a-zA-Z0-9.+]/~/g')
VERSION="$BASE_VERSION~git$DATE.$SHA-$CLEAN_COMPONENT"
VERSION="$BASE_VERSION-git$DATE.$SHA-$CLEAN_COMPONENT"
fi
echo "component=$COMPONENT" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
+1 -1
View File
@@ -32,7 +32,7 @@ jobs:
- name: Setup Node.js
if: steps.runner-env.outputs.node_major == '' || steps.runner-env.outputs.node_major < '20'
uses: https://github.com/actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
uses: https://github.com/actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: 24
+1 -1
View File
@@ -55,7 +55,7 @@ jobs:
# repositories: continuwuity
- name: Install regsync
uses: https://github.com/regclient/actions/regsync-installer@bb562fac724b7b37c17f19671df07fe34fabc376 # main
uses: https://github.com/regclient/actions/regsync-installer@dd58ad94f76adb73d8ac1bf75ed25f01545d5b32 # main
- name: Check what images need mirroring
run: |
+2 -38
View File
@@ -30,7 +30,7 @@ env:
jobs:
build-release:
name: "Build ${{ matrix.slug }} (release)"
runs-on: ${{ matrix.runner }}
runs-on: dind
permissions:
contents: read
packages: write
@@ -41,29 +41,14 @@ jobs:
include:
- platform: "linux/amd64"
slug: "linux-amd64"
runner: "dind"
march: ""
rust_cpu_flags: ""
- platform: "linux/arm64"
slug: "linux-arm64"
runner: "ubuntu-arm64"
native: true
march: "armv8-a+crc"
rust_cpu_flags: "-C target-feature=+crc"
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Compile on the runner host
if: matrix.native
uses: ./.forgejo/actions/build-native
with:
profile: "release"
features: "default"
march: ${{ matrix.march }}
rust-cpu-flags: ${{ matrix.rust_cpu_flags }}
- name: Prepare Docker build environment
id: prepare
uses: ./.forgejo/actions/prepare-docker-build
@@ -88,11 +73,8 @@ jobs:
GIT_REMOTE_COMMIT_URL=${{github.event.head_commit.url }}
CARGO_INCREMENTAL=${{ env.BUILDKIT_ENDPOINT != '' && '1' || '0' }}
TARGET_CPU=
TARGET_MARCH=${{ matrix.march }}
TARGET_RUSTFLAGS=${{ matrix.rust_cpu_flags }}
RUST_PROFILE=release
CARGO_FEATURES=default
ARTIFACTS=${{ matrix.native && 'artifacts-prebuilt' || 'artifacts-builder' }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.prepare.outputs.metadata_labels }}
annotations: ${{ steps.prepare.outputs.metadata_annotations }}
@@ -133,7 +115,7 @@ jobs:
build-maxperf:
name: "Build ${{ matrix.slug }} (max-perf)"
runs-on: ${{ matrix.runner }}
runs-on: dind
needs: build-release
permissions:
contents: read
@@ -146,30 +128,15 @@ jobs:
- platform: "linux/amd64"
slug: "linux-amd64"
target_cpu: "haswell"
runner: "dind"
march: "haswell"
rust_cpu_flags: "-C target-cpu=haswell"
- platform: "linux/arm64"
slug: "linux-arm64"
target_cpu: ""
runner: "ubuntu-arm64"
native: true
march: "armv8-a+crc"
rust_cpu_flags: "-C target-feature=+crc"
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Compile on the runner host
if: matrix.native
uses: ./.forgejo/actions/build-native
with:
profile: "release-max-perf"
features: "default,release_max_log_level"
march: ${{ matrix.march }}
rust-cpu-flags: ${{ matrix.rust_cpu_flags }}
- name: Prepare max-perf Docker build environment
id: prepare
uses: ./.forgejo/actions/prepare-docker-build
@@ -194,11 +161,8 @@ jobs:
GIT_REMOTE_COMMIT_URL=${{github.event.head_commit.url }}
CARGO_INCREMENTAL=${{ env.BUILDKIT_ENDPOINT != '' && '1' || '0' }}
TARGET_CPU=${{ matrix.target_cpu }}
TARGET_MARCH=${{ matrix.march }}
TARGET_RUSTFLAGS=${{ matrix.rust_cpu_flags }}
RUST_PROFILE=release-max-perf
CARGO_FEATURES=default,release_max_log_level
ARTIFACTS=${{ matrix.native && 'artifacts-prebuilt' || 'artifacts-builder' }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.prepare.outputs.metadata_labels }}
annotations: ${{ steps.prepare.outputs.metadata_annotations }}
+1 -1
View File
@@ -43,7 +43,7 @@ jobs:
name: Renovate
runs-on: ubuntu-latest
container:
image: ghcr.io/renovatebot/renovate:44.115.13@sha256:c19ab7a16ed7cbe8f7f11e2435e67c727ba90107930d3324c8d1cdec808f0055
image: ghcr.io/renovatebot/renovate:44.151.2@sha256:29b3bf193f855c6f4b7027395a9c66c3417ad8bb6f30458090e1c2363d04eef7
options: --tmpfs /tmp:exec
steps:
- name: Checkout
+1 -1
View File
@@ -24,7 +24,7 @@ repos:
- id: check-added-large-files
- repo: https://github.com/crate-ci/typos
rev: v1.50.3
rev: v1.51.1
hooks:
- id: typos
- id: typos
Generated
+104 -32
View File
@@ -324,6 +324,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90"
dependencies = [
"axum-core",
"axum-macros",
"bytes",
"form_urlencoded",
"futures-util",
@@ -392,6 +393,17 @@ dependencies = [
"tracing",
]
[[package]]
name = "axum-macros"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7aa268c23bfbbd2c4363b9cd302a4f504fb2a9dfe7e3451d66f35dd392e20aca"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "axum-server"
version = "0.8.0"
@@ -916,8 +928,11 @@ dependencies = [
"log",
"opentelemetry",
"opentelemetry-otlp",
"opentelemetry-prometheus",
"opentelemetry-semantic-conventions",
"opentelemetry_sdk",
"parking_lot",
"prometheus",
"reqwest 0.13.5",
"rustls",
"sentry",
@@ -1036,7 +1051,12 @@ dependencies = [
"nix",
"num-traits",
"openidconnect",
"opentelemetry",
"opentelemetry-prometheus",
"opentelemetry-semantic-conventions",
"opentelemetry_sdk",
"parking_lot",
"prometheus",
"rand 0.10.3",
"regex",
"reqwest 0.13.5",
@@ -1117,6 +1137,7 @@ dependencies = [
"hyper",
"hyper-util",
"log",
"opentelemetry-instrumentation-tower",
"ruma",
"rustls",
"sd-notify",
@@ -3791,7 +3812,7 @@ version = "5.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51e219e79014df21a225b1860a479e2dcd7cbd9130f4defd4bd0e191ea31d67d"
dependencies = [
"base64 0.21.7",
"base64 0.22.1",
"chrono",
"getrandom 0.2.17",
"http",
@@ -4028,9 +4049,9 @@ checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"
[[package]]
name = "opentelemetry"
version = "0.32.0"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0142c63252a9e054e68a4c61a5778f7b14f576274d593f8ce883d191a099682"
checksum = "6cdb0b1b267eb9db3331b434ed9ddab10d50e280a9adf9d13e5233e2002b61b5"
dependencies = [
"futures-core",
"futures-sink",
@@ -4042,9 +4063,9 @@ dependencies = [
[[package]]
name = "opentelemetry-http"
version = "0.32.0"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5683015d09e2df236ef005b17f6f196f0d5f6313c4fa43a7b6a53b52776e4331"
checksum = "ee2c3625b8aa04209f7e01e513bc8044da9687fa38a9eacf59628ca5f3b87300"
dependencies = [
"async-trait",
"bytes",
@@ -4054,12 +4075,30 @@ dependencies = [
]
[[package]]
name = "opentelemetry-otlp"
version = "0.32.0"
name = "opentelemetry-instrumentation-tower"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9966929966d17620d7c316c643ba62631826e10021409357772d5eea84f62c35"
checksum = "1e7006f3b1853d315462a7237c81eec3d7adfa5b70975a02b19e92d045bc22d7"
dependencies = [
"axum",
"http",
"http-body",
"opentelemetry",
"opentelemetry-http",
"opentelemetry-semantic-conventions",
"pin-project-lite",
"tower-layer",
"tower-service",
]
[[package]]
name = "opentelemetry-otlp"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "699a67345e21962a231955b9059a157e428b219fa5df8efe11f08346fb23a344"
dependencies = [
"http",
"httpdate",
"opentelemetry",
"opentelemetry-http",
"opentelemetry-proto",
@@ -4073,10 +4112,23 @@ dependencies = [
]
[[package]]
name = "opentelemetry-proto"
version = "0.32.0"
name = "opentelemetry-prometheus"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56d658ba1faf63f7b9c492cfbe6e0ec365440a16132d3270c1065f7b33f1b638"
checksum = "274c2e3a2ad55524484500d5a78dffbfee23e4a1e4c3d3fcbd881b61b033e6df"
dependencies = [
"once_cell",
"opentelemetry",
"opentelemetry_sdk",
"prometheus",
"tracing",
]
[[package]]
name = "opentelemetry-proto"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25da1ac11a0aeccf38d7f77ee0348715adaf8340f65ad46c94a02c6b20e2f65d"
dependencies = [
"opentelemetry",
"opentelemetry_sdk",
@@ -4086,10 +4138,16 @@ dependencies = [
]
[[package]]
name = "opentelemetry_sdk"
version = "0.32.1"
name = "opentelemetry-semantic-conventions"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b59f80e1ac4d5ff7a2db8fb6c80badb7f0f3f858211fba08dd9aaec750894f9"
checksum = "d288b1e1bc3590052fbb8f0f635ef248dd9022cf1fbaeb6582b7ad6081a17b87"
[[package]]
name = "opentelemetry_sdk"
version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb39533d9d1c912123efd7d41d7e0c29d16917b60ce15b4c8d87cb1af7f67520"
dependencies = [
"futures-channel",
"futures-executor",
@@ -4502,6 +4560,20 @@ dependencies = [
"yansi",
]
[[package]]
name = "prometheus"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ca5326d8d0b950a9acd87e6a3f94745394f62e4dae1b1ee22b2bc0c394af43a"
dependencies = [
"cfg-if",
"fnv",
"lazy_static",
"memchr",
"parking_lot",
"thiserror 2.0.21",
]
[[package]]
name = "prost"
version = "0.14.4"
@@ -4947,7 +5019,7 @@ dependencies = [
[[package]]
name = "ruma"
version = "0.17.0"
source = "git+https://github.com/ruma/ruma.git?rev=e7384f01eacd454c593683de50491201e2160fd1#e7384f01eacd454c593683de50491201e2160fd1"
source = "git+https://github.com/ruma/ruma.git?rev=f5e5e1c885f598036fd4326c566e9d1928027d5d#f5e5e1c885f598036fd4326c566e9d1928027d5d"
dependencies = [
"assign",
"js_int",
@@ -4966,7 +5038,7 @@ dependencies = [
[[package]]
name = "ruma-appservice-api"
version = "0.17.0"
source = "git+https://github.com/ruma/ruma.git?rev=e7384f01eacd454c593683de50491201e2160fd1#e7384f01eacd454c593683de50491201e2160fd1"
source = "git+https://github.com/ruma/ruma.git?rev=f5e5e1c885f598036fd4326c566e9d1928027d5d#f5e5e1c885f598036fd4326c566e9d1928027d5d"
dependencies = [
"http",
"js_int",
@@ -4979,7 +5051,7 @@ dependencies = [
[[package]]
name = "ruma-client-api"
version = "0.25.0"
source = "git+https://github.com/ruma/ruma.git?rev=e7384f01eacd454c593683de50491201e2160fd1#e7384f01eacd454c593683de50491201e2160fd1"
source = "git+https://github.com/ruma/ruma.git?rev=f5e5e1c885f598036fd4326c566e9d1928027d5d#f5e5e1c885f598036fd4326c566e9d1928027d5d"
dependencies = [
"as_variant",
"assign",
@@ -5001,7 +5073,7 @@ dependencies = [
[[package]]
name = "ruma-common"
version = "0.20.0"
source = "git+https://github.com/ruma/ruma.git?rev=e7384f01eacd454c593683de50491201e2160fd1#e7384f01eacd454c593683de50491201e2160fd1"
source = "git+https://github.com/ruma/ruma.git?rev=f5e5e1c885f598036fd4326c566e9d1928027d5d#f5e5e1c885f598036fd4326c566e9d1928027d5d"
dependencies = [
"as_variant",
"base64 0.23.1",
@@ -5034,7 +5106,7 @@ dependencies = [
[[package]]
name = "ruma-events"
version = "0.35.0"
source = "git+https://github.com/ruma/ruma.git?rev=e7384f01eacd454c593683de50491201e2160fd1#e7384f01eacd454c593683de50491201e2160fd1"
source = "git+https://github.com/ruma/ruma.git?rev=f5e5e1c885f598036fd4326c566e9d1928027d5d#f5e5e1c885f598036fd4326c566e9d1928027d5d"
dependencies = [
"as_variant",
"indexmap 2.14.2",
@@ -5055,7 +5127,7 @@ dependencies = [
[[package]]
name = "ruma-federation-api"
version = "0.16.0"
source = "git+https://github.com/ruma/ruma.git?rev=e7384f01eacd454c593683de50491201e2160fd1#e7384f01eacd454c593683de50491201e2160fd1"
source = "git+https://github.com/ruma/ruma.git?rev=f5e5e1c885f598036fd4326c566e9d1928027d5d#f5e5e1c885f598036fd4326c566e9d1928027d5d"
dependencies = [
"bytes",
"http",
@@ -5077,7 +5149,7 @@ dependencies = [
[[package]]
name = "ruma-identifiers-validation"
version = "0.12.1"
source = "git+https://github.com/ruma/ruma.git?rev=e7384f01eacd454c593683de50491201e2160fd1#e7384f01eacd454c593683de50491201e2160fd1"
source = "git+https://github.com/ruma/ruma.git?rev=f5e5e1c885f598036fd4326c566e9d1928027d5d#f5e5e1c885f598036fd4326c566e9d1928027d5d"
dependencies = [
"js_int",
"thiserror 2.0.21",
@@ -5086,7 +5158,7 @@ dependencies = [
[[package]]
name = "ruma-macros"
version = "0.20.0"
source = "git+https://github.com/ruma/ruma.git?rev=e7384f01eacd454c593683de50491201e2160fd1#e7384f01eacd454c593683de50491201e2160fd1"
source = "git+https://github.com/ruma/ruma.git?rev=f5e5e1c885f598036fd4326c566e9d1928027d5d#f5e5e1c885f598036fd4326c566e9d1928027d5d"
dependencies = [
"as_variant",
"cfg-if",
@@ -5102,7 +5174,7 @@ dependencies = [
[[package]]
name = "ruma-push-gateway-api"
version = "0.16.0"
source = "git+https://github.com/ruma/ruma.git?rev=e7384f01eacd454c593683de50491201e2160fd1#e7384f01eacd454c593683de50491201e2160fd1"
source = "git+https://github.com/ruma/ruma.git?rev=f5e5e1c885f598036fd4326c566e9d1928027d5d#f5e5e1c885f598036fd4326c566e9d1928027d5d"
dependencies = [
"js_int",
"ruma-common",
@@ -5114,7 +5186,7 @@ dependencies = [
[[package]]
name = "ruma-signatures"
version = "0.22.0"
source = "git+https://github.com/ruma/ruma.git?rev=e7384f01eacd454c593683de50491201e2160fd1#e7384f01eacd454c593683de50491201e2160fd1"
source = "git+https://github.com/ruma/ruma.git?rev=f5e5e1c885f598036fd4326c566e9d1928027d5d#f5e5e1c885f598036fd4326c566e9d1928027d5d"
dependencies = [
"base64 0.23.1",
"ed25519-dalek 3.0.0",
@@ -5131,7 +5203,7 @@ dependencies = [
[[package]]
name = "ruma-state-res"
version = "0.18.0"
source = "git+https://github.com/ruma/ruma.git?rev=e7384f01eacd454c593683de50491201e2160fd1#e7384f01eacd454c593683de50491201e2160fd1"
source = "git+https://github.com/ruma/ruma.git?rev=f5e5e1c885f598036fd4326c566e9d1928027d5d#f5e5e1c885f598036fd4326c566e9d1928027d5d"
dependencies = [
"js_int",
"ruma-common",
@@ -5582,7 +5654,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8050abb251097357e24aff63ba2c52a6309ecb7d23a5474023df960a02694d8"
dependencies = [
"annotate-snippets",
"base64 0.21.7",
"base64 0.23.1",
"encoding_rs_io",
"granit-parser",
"nohash-hasher",
@@ -5912,9 +5984,9 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.16.2"
version = "1.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9395f0f0eee849a9b707b2f06bb92a6a422090e2123bb2ef8e87a0e61892a8e"
checksum = "ba467056f1b547ed52077911161fc86985becbc60e8e1857c8a144dab0def891"
dependencies = [
"serde",
]
@@ -6095,9 +6167,9 @@ dependencies = [
[[package]]
name = "termimad"
version = "0.35.5"
version = "0.35.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "092b11fb38404fa873f019f8e5f300fa5787f381b7a58b923546d94b5a9065fd"
checksum = "2374179aac8b77011a1aefe2f44d0c34eb680c9b4bd1c369a88991262c60c85a"
dependencies = [
"coolor",
"crokey",
@@ -6672,9 +6744,9 @@ dependencies = [
[[package]]
name = "tracing-opentelemetry"
version = "0.33.0"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adbc64cba7137545b8044cb1fe9814f7aacf3c6b5f9b45be8bb5db538befdb26"
checksum = "0a904802a1b902f43638b677ff2a650847e3b4404101b6c586d648e8c1e3e8fe"
dependencies = [
"js-sys",
"opentelemetry",
+57 -38
View File
@@ -348,7 +348,7 @@ version = "1.1.1"
# Used for matrix spec type definitions and helpers
[workspace.dependencies.ruma]
git = "https://github.com/ruma/ruma.git"
rev = "e7384f01eacd454c593683de50491201e2160fd1"
rev = "f5e5e1c885f598036fd4326c566e9d1928027d5d"
features = [
"appservice-api-c",
"client-api",
@@ -379,12 +379,15 @@ features = [
"unstable-msc4380",
"unstable-msc4143",
"unstable-msc4293",
"unstable-msc4363",
"unstable-msc4406",
"unstable-msc4439",
"unstable-msc4354",
"unstable-msc4480",
"unstable-msc4466",
"unstable-msc4494",
"unstable-msc4484",
"unstable-msc4540",
"unstable-extensible-events",
]
@@ -413,20 +416,36 @@ version = "4.0.1"
# optional opentelemetry, performance measurements, flamegraphs, etc for performance measurements and monitoring
[workspace.dependencies.opentelemetry]
version = "0.32.0"
version = "0.33.0"
[workspace.dependencies.opentelemetry-instrumentation-tower]
version = "0.19.0"
default-features = false
features = ["axum"]
[workspace.dependencies.opentelemetry-semantic-conventions]
version = "0.33.0"
features = ["semconv_experimental"]
[workspace.dependencies.tracing-flame]
version = "0.2.0"
[workspace.dependencies.tracing-opentelemetry]
version = "0.33.0"
version = "0.34.0"
[workspace.dependencies.opentelemetry_sdk]
version = "0.32.0"
version = "0.33.0"
features = ["rt-tokio"]
[workspace.dependencies.opentelemetry-prometheus]
version = "0.33.0"
[workspace.dependencies.prometheus]
version = "0.14.0"
default-features = false
[workspace.dependencies.opentelemetry-otlp]
version = "0.32.0"
version = "0.33.0"
features = ["http", "grpc-tonic", "trace", "logs", "metrics"]
@@ -806,37 +825,37 @@ codegen-units = 16
#
[workspace.lints.rust]
absolute-paths-not-starting-with-crate = "warn"
#box-pointers = "warn"
deprecated-in-future = "warn"
elided-lifetimes-in-paths = "warn"
explicit-outlives-requirements = "warn"
ffi-unwind-calls = "warn"
keyword-idents = "warn"
macro-use-extern-crate = "warn"
meta-variable-misuse = "warn"
missing-abi = "warn"
#missing-copy-implementations = "warn" # TODO
#missing-debug-implementations = "warn" # TODO
non-ascii-idents = "warn"
rust-2021-incompatible-closure-captures = "warn"
rust-2021-incompatible-or-patterns = "warn"
rust-2021-prefixes-incompatible-syntax = "warn"
rust-2021-prelude-collisions = "warn"
single-use-lifetimes = "warn"
trivial-casts = "warn"
trivial-numeric-casts = "warn"
unit-bindings = "warn"
#unnameable-types = "warn" # TODO
unreachable-pub = "warn"
unsafe-op-in-unsafe-fn = "warn"
unstable-features = "warn"
unused-extern-crates = "warn"
unused-import-braces = "warn"
unused-lifetimes = "warn"
unused-macro-rules = "warn"
unused-qualifications = "warn"
#unused-results = "warn" # TODO
absolute_paths_not_starting_with_crate = "warn"
#box_pointers = "warn"
deprecated_in_future = "warn"
elided_lifetimes_in_paths = "warn"
explicit_outlives_requirements = "warn"
ffi_unwind_calls = "warn"
keyword_idents = { level = "warn", priority = -1 }
macro_use_extern_crate = "warn"
meta_variable_misuse = "warn"
missing_abi = "warn"
#missing_copy_implementations = "warn" # TODO
#missing_debug_implementations = "warn" # TODO
non_ascii_idents = "warn"
rust_2021_incompatible_closure_captures = "warn"
rust_2021_incompatible_or_patterns = "warn"
rust_2021_prefixes_incompatible_syntax = "warn"
rust_2021_prelude_collisions = "warn"
single_use_lifetimes = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unit_bindings = "warn"
#unnameable_types = "warn" # TODO
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"
unstable_features = "warn"
unused_extern_crates = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
unused_qualifications = "warn"
#unused_results = "warn" # TODO
## some sadness
mismatched_lifetime_syntaxes = "allow" # TODO!
@@ -890,6 +909,7 @@ significant_drop_tightening = { level = "allow", priority = 1 } # TODO
pedantic = { level = "warn", priority = -1 }
## some sadness
assert_is_empty = { level = "allow", priority = 1 }
too_long_first_doc_paragraph = { level = "allow", priority = 1 }
doc_markdown = { level = "allow", priority = 1 }
enum_glob_use = { level = "allow", priority = 1 }
@@ -932,7 +952,6 @@ float_cmp_const = "warn"
fn_to_numeric_cast_any = "warn"
format_push_string = "warn"
get_unwrap = "warn"
impl_trait_in_params = "warn"
lossy_float_literal = "warn"
mem_forget = "warn"
missing_assert_message = "warn"
@@ -978,7 +997,7 @@ let_underscore_future = { level = "allow", priority = 1 }
literal_string_with_formatting_args = { level = "allow", priority = 1 }
# This lint is stupid, there's no point defining generics for simple trait params
impl-trait-in-params = { level = "allow", priority = 1 }
impl_trait_in_params = { level = "allow", priority = 1 }
needless_raw_string_hashes = "allow"
+1
View File
@@ -0,0 +1 @@
Added support for [MSC4484](https://github.com/matrix-org/matrix-spec-proposals/pull/4484). Clients which use the built-in Matrix server administration APIs will need to ask for the appropriate scope when signing in with OAuth. Contributed by @ginger.
+1
View File
@@ -0,0 +1 @@
Added support for MSC4363 (OAuth step-up authentication). Contributed by @ginger.
+1
View File
@@ -0,0 +1 @@
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.
+1
View File
@@ -0,0 +1 @@
Add support for using custom DNS servers instead of using /etc/resolv.conf. Contributed by @s1lv3r.
+1
View File
@@ -0,0 +1 @@
Add a guide for push notifications, detailing how it works, push gateway specifics, troubleshooting common issues, and pointing to external guides for UnifiedPush backends. Contributed by @stratself
+1
View File
@@ -0,0 +1 @@
Fixed push gateway URLs containing the configured notification path outside of their suffix. Contributed by @eleboucher.
+1
View File
@@ -0,0 +1 @@
"!admin users list" now hides deactivated users by default, but can display them with the optional "--show-deactivated" flag. "--hide-suspended" and "--hide-locked" have been added as well, which stop suspended and locked users from being displayed respectively. Contributed by @Clubs.
+1
View File
@@ -0,0 +1 @@
Added support for acting as a trusted server, meaning the `trusted_servers` list can consist of servers that are either Synapse OR continuwuity.
+1
View File
@@ -0,0 +1 @@
Appservices now receive typing indicators and read receipts. Contributed by @Jade
+1
View File
@@ -0,0 +1 @@
Correctly set RocksDB column options, including enabling block caches. Contributed by @Jade
@@ -0,0 +1 @@
Added opt-in OpenTelemetry metrics, exported over OTLP or scraped by Prometheus from `/_continuwuity/metrics`, and a Grafana dashboard. Contributed by @eleboucher.
+296 -18
View File
File diff suppressed because it is too large. Load diff
+10 -25
View File
@@ -1,10 +1,6 @@
ARG RUST_VERSION=1
ARG DEBIAN_VERSION=trixie
# Source of compiled artefacts: the builder stage, or out/ from the build context
# when the runner compiled natively.
ARG ARTIFACTS=artifacts-builder
FROM --platform=$BUILDPLATFORM docker.io/tonistiigi/xx AS xx
FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-slim-${DEBIAN_VERSION} AS base
FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-slim-${DEBIAN_VERSION} AS toolchain
@@ -14,7 +10,7 @@ RUN rm -f /etc/apt/apt.conf.d/docker-clean
# Match Rustc version as close as possible
# rustc -vV
ARG LLVM_VERSION=22
ARG LLVM_VERSION=23
# ENV RUSTUP_TOOLCHAIN=${RUST_VERSION}
# Install repo tools
@@ -54,7 +50,7 @@ EOF
# Developer tool versions
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
ENV BINSTALL_VERSION=1.24.0
ENV BINSTALL_VERSION=1.25.3
# renovate: datasource=github-releases depName=psastras/sbom-rs
ENV CARGO_SBOM_VERSION=0.9.1
# renovate: datasource=crate depName=lddtree
@@ -122,19 +118,15 @@ EOF
# Apply CPU-specific optimizations if TARGET_CPU is provided
ARG TARGET_CPU
ARG TARGET_MARCH
ARG TARGET_RUSTFLAGS
RUN <<EOF
set -o allexport
set -o xtrace
. /etc/environment
if [ -n "${TARGET_MARCH}" ]; then
echo "CFLAGS='${CFLAGS} -march=${TARGET_MARCH}'" >> /etc/environment
echo "CXXFLAGS='${CXXFLAGS} -march=${TARGET_MARCH}'" >> /etc/environment
fi
if [ -n "${TARGET_RUSTFLAGS}" ]; then
echo "RUSTFLAGS='${RUSTFLAGS} ${TARGET_RUSTFLAGS}'" >> /etc/environment
if [ -n "${TARGET_CPU}" ]; then
echo "CFLAGS='${CFLAGS} -march=${TARGET_CPU}'" >> /etc/environment
echo "CXXFLAGS='${CXXFLAGS} -march=${TARGET_CPU}'" >> /etc/environment
echo "RUSTFLAGS='${RUSTFLAGS} -C target-cpu=${TARGET_CPU}'" >> /etc/environment
fi
EOF
@@ -253,13 +245,6 @@ RUN <<'DEPS_EOF'
find /out/libs* -type f 2>/dev/null | sort || echo "No libraries found"
DEPS_EOF
FROM scratch AS artifacts-prebuilt
COPY out/ /out/
FROM builder AS artifacts-builder
FROM ${ARTIFACTS} AS artifacts
FROM ubuntu:latest AS prepper
# Create layer structure
@@ -269,14 +254,14 @@ RUN mkdir -p /layer1/etc/ssl/certs \
# Copy SSL certs and root-path libraries to layer1 (ultra-stable)
COPY --from=base /etc/ssl/certs /layer1/etc/ssl/certs
COPY --from=artifacts /out/libs-root/ /layer1/
COPY --from=builder /out/libs-root/ /layer1/
# Copy application libraries to layer2 (semi-stable)
COPY --from=artifacts /out/libs/ /layer2/usr/lib/
COPY --from=builder /out/libs/ /layer2/usr/lib/
# Copy binaries and SBOM to layer3 (volatile)
COPY --from=artifacts /out/sbin/ /layer3/sbin/
COPY --from=artifacts /out/sbom/ /layer3/sbom/
COPY --from=builder /out/sbin/ /layer3/sbin/
COPY --from=builder /out/sbom/ /layer3/sbom/
# Fix permissions after copying
RUN chmod -R 755 /layer1 /layer2 /layer3
+1 -1
View File
@@ -18,7 +18,7 @@ RUN --mount=type=cache,target=/etc/apk/cache apk add \
# Developer tool versions
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
ENV BINSTALL_VERSION=1.24.0
ENV BINSTALL_VERSION=1.25.3
# renovate: datasource=github-releases depName=psastras/sbom-rs
ENV CARGO_SBOM_VERSION=0.9.1
# renovate: datasource=crate depName=lddtree
+4
View File
@@ -37,6 +37,10 @@ CONTINUWUITY_ANTISPAM__DRAUPNIR__BASE_URL="https://draupnir.example.com"
# Alternatively, you can pass a (quoted) struct to define an entire section
# This maps to the [global.well_known] section
CONTINUWUITY_WELL_KNOWN="{ client=https://example.com,server=example.com:443 }"
# Options that take a list are written as a (quoted) array
CONTINUWUITY_TRUSTED_SERVERS='["matrix.org"]'
CONTINUWUITY_PORT='[8008, 8448]'
```
### Alternative prefixes
+1 -1
View File
@@ -99,7 +99,7 @@ After Continuwuity is up and running, consider the following:
- To set up Audio/Video communication, see the [**Calls**](./calls.mdx) page.
- See the [**Authentication chapter**] for various ways to access to your homeserver, such as logging in with an external OIDC provider.
- See the [**Authentication chapter**](./authentication.mdx) for various ways to access to your homeserver, such as logging in with an external OIDC provider.
- Consult the [**Maintenance**](./maintenance.mdx) page for guidance on maintaining your homeserver.
+1 -1
View File
@@ -79,7 +79,7 @@ spec:
value: "https://matrix.example.com"
- name: CONTINUWUITY_ALLOW_REGISTRATION
value: "false"
- name: RUST_LOG
- name: CONTINUWUITY_LOG
value: info
readinessProbe:
httpGet:
+10
View File
@@ -13,5 +13,15 @@
"type": "file",
"name": "performance",
"label": "Performance tuning"
},
{
"type": "file",
"name": "metrics",
"label": "Metrics"
},
{
"type": "file",
"name": "push",
"label": "Push notifications"
}
]
+100
View File
@@ -0,0 +1,100 @@
# Metrics
Continuwuity records metrics with OpenTelemetry and can export them in two ways, both disabled by default:
- **Prometheus scraping** from `/_continuwuity/metrics`
- **OTLP push**, alongside traces
## Prometheus
```toml
[global]
allow_prometheus_metrics = true
prometheus_metrics_token = "a-long-random-secret"
```
The endpoint is served on the same listener as the rest of the server. Either set `prometheus_metrics_token` or block `/_continuwuity/metrics` at your reverse proxy so it is not publicly readable.
```yaml
scrape_configs:
- job_name: continuwuity
scheme: https
metrics_path: /_continuwuity/metrics
authorization:
credentials: a-long-random-secret
static_configs:
- targets: ["matrix.example.com"]
```
## OTLP
Requires the `otlp_telemetry` feature, enabled in default builds.
```toml
[global]
allow_otlp_metrics = true
```
Configure the exporter with standard OpenTelemetry environment variables:
```sh
OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318
OTEL_EXPORTER_OTLP_METRICS_PROTOCOL=http/protobuf # or "grpc"
OTEL_METRIC_EXPORT_INTERVAL=15000
```
`service.instance.id` defaults to the server name, and `OTEL_RESOURCE_ATTRIBUTES` or `OTEL_SERVICE_NAME` override the defaults.
Prometheus can receive OTLP directly when started with `--web.enable-otlp-receiver`, using `http://prometheus:9090/api/v1/otlp` as the endpoint.
## Exported metrics
Names below are as they appear in Prometheus. OTLP uses the dotted OpenTelemetry names, such as `continuwuity.sender.events`. HTTP and process metrics follow the OpenTelemetry semantic conventions.
| Metric | Type | Labels | Description |
| --- | --- | --- | --- |
| `target_info` | gauge | `service_version`, `service_instance_id` | Running server version and name |
| `http_server_request_duration_seconds` | histogram | `http_request_method`, `http_route`, `http_response_status_code`, `network_protocol_name`, `network_protocol_version`, `url_scheme` | Handled HTTP requests, by route template |
| `http_server_active_requests` | gauge | `http_request_method`, `url_scheme` | Requests currently being handled |
| `http_server_request_body_size_bytes` | histogram | HTTP request duration labels | Request body sizes, when `Content-Length` is supplied |
| `http_server_response_body_size_bytes` | histogram | HTTP request duration labels | Response body sizes, when known |
| `continuwuity_federation_incoming_transaction_duration_seconds` | histogram | `outcome` | Processing time of incoming transactions |
| `continuwuity_federation_incoming_transactions_active` | gauge | | Incoming transactions currently being processed |
| `continuwuity_federation_incoming_pdus_total` | counter | `type`, `outcome` | Incoming PDUs by event type and outcome: `accepted`, `forbidden`, `invalid`, `error` or `unparsable` |
| `continuwuity_federation_incoming_pdu_duration_seconds` | histogram | `outcome` | Time to handle an incoming PDU |
| `continuwuity_federation_incoming_pdu_lag_seconds` | histogram | | Time between an accepted PDU's `origin_server_ts` and its arrival |
| `continuwuity_federation_incoming_edus_total` | counter | `type` | Incoming EDUs by type |
| `continuwuity_federation_incoming_edu_duration_seconds` | histogram | `type` | Time to handle an incoming EDU |
| `continuwuity_federation_outgoing_request_duration_seconds` | histogram | `outcome` | Outgoing federation requests |
| `continuwuity_federation_destinations` | gauge | `state` | Remote servers in retry `backoff` or with a `stale` destination cache entry |
| `continuwuity_sender_transaction_duration_seconds` | histogram | `destination`, `outcome` | Outgoing federation, appservice and push transactions |
| `continuwuity_sender_events_total` | counter | `destination`, `kind`, `outcome` | PDUs and EDUs sent in outgoing transactions |
| `continuwuity_sender_events_queued_total` | counter | `destination`, `kind` | PDUs and EDUs queued for sending |
| `continuwuity_sender_queue_depth` | gauge | | Messages waiting for the sender workers |
| `continuwuity_users` | gauge | `origin` | Known `local` users, including deactivated, and `remote` users |
| `continuwuity_invites_total` | counter | `direction`, `destination`, `outcome` | Invites sent by local users or received over federation |
| `continuwuity_media_write_size_bytes` | histogram | `origin` | Media files written, from local uploads or cached remote media |
| `continuwuity_media_read_size_bytes` | histogram | `origin` | Media files served |
| `continuwuity_media_files` | gauge | | Stored media files, including thumbnails |
| `continuwuity_antispam_checks_total` | counter | `check`, `outcome` | Antispam service checks; denials include the service being unreachable |
| `continuwuity_database_size_bytes` | gauge | | Total size of RocksDB SST files |
| `continuwuity_database_memory_bytes` | gauge | `name` | RocksDB memtable, table reader and row 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_jemalloc_memory_bytes` | gauge | `kind` | jemalloc statistics, only with the `jemalloc_stats` feature |
| `process_uptime_seconds` | gauge | | Time since the server started |
| `process_cpu_time_seconds_total` | counter | `cpu_mode` | CPU time used by the process |
| `process_memory_usage_bytes` | gauge | | Resident memory (Linux) |
| `process_memory_virtual_bytes` | gauge | | Virtual memory (Linux) |
| `process_unix_file_descriptor_count` | gauge | | Open file descriptors (Linux) |
| `continuwuity_tokio_workers` | gauge | | Tokio runtime worker threads |
| `continuwuity_tokio_alive_tasks` | gauge | | Alive tokio tasks |
| `continuwuity_tokio_global_queue_depth` | gauge | | Tasks in the tokio global queue |
| `continuwuity_tokio_worker_busy_time_seconds_total` | counter | | Time worker threads spent busy |
| `continuwuity_tokio_worker_parks_total` | counter | | Number of times worker threads parked |
User and media file counts are estimates taken from RocksDB (`rocksdb.estimate-num-keys`), so they may lag slightly or drift after deletions.
## Grafana dashboard
Import [grafana-dashboard.json](/guides/grafana-dashboard.json) under **Dashboards → New → Import**, or provision it from a file.
Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

+215
View File
@@ -0,0 +1,215 @@
import { Tab, Tabs } from '@rspress/core/theme';
# Push notifications
Matrix clients receive notifications in the following ways:
- **In-band notifications**, which are shown when the client actively syncs with the server.
- **Push notifications**, which are posted to the client by the server through an external push service. This is typically used to send out-of-band notifications to mobile devices, and it is the focus of this page.
Generally, your mobile device is preconfigured for push notifications out of the box. The details below are for advanced use cases, such as using an alternative push backend (like UnifiedPush) or hosting your own.
## Overview
Continuwuity supports two push methods: the legacy **Matrix Push Gateway** and the new **Web Push** protocol. The former is currently supported by more clients, but the latter enables end-to-end-encrypted push notifications. They work as follows:
<Tabs groupId="push-ops">
<Tab label="Registration">
<img src="./push-registration.webp"
alt="Diagram showing the push registration flow, described in the text below."
style= {{"max-height":300,display:"flex",margin:"1rem auto","border-radius":"5px"}}
/>
1. A client app obtains a _push key_ from the push app that it hooks up to.
2. Then, it registers a _pusher_ with Continuwuity, bringing along the _push key_ and the following additional information:
- For the Push Gateway method: The _push gateway_ URL, which is [provided by the client](#unifiedpush-and-push-gateways).
- For the Web Push method: Some _encryption details_ generated by the client, so the server knows how to encrypt its push payloads.
</Tab>
<Tab label="Operation (Push Gateway)">
<img src="./push-operation-gateway.webp"
alt="Diagram showing the push operation with the Push Gateway method, described in the text below."
style={{"max-height":300,display:"flex",margin:"1rem auto","border-radius":"5px"}}
/>
1. Continuwuity pushes messages to the push gateway
2. The push gateway converts the messages to a suitable format and forwards them to the push provider server.
3. The push provider server passes them along to the push app.
4. The push app wakes the client, prompting it to fetch new messages from Continuwuity.
5. Finally, the client calculates against a set of _push rules_ to determine whether the fetched message(s) should be notified to users.
</Tab>
<Tab label="Operation (Web Push)">
<img src="./push-operation-webpush.webp"
alt="Diagram showing the push operation with the Web Push method, described in the text below."
style={{"max-height":300,display:"flex",margin:"1rem auto","border-radius":"5px"}}
/>
1. Continuwuity pushes encrypted messages to the push provider server.
2. The push provider server passes them along to the push app.
3. The push app wakes the client, which decrypts the payload, and if needed, fetches new messages from Continuwuity.
4. Finally, the client calculates against a set of _push rules_ to determine whether the pushed message(s) should be notified to users.
Note that this mechanism does not require a push gateway component.
[MSC4174]: https://github.com/matrix-org/matrix-spec-proposals/pull/4174
</Tab>
</Tabs>
_([excalidraw file of the diagrams](/guides/push-notifications.excalidraw))_
Therefore, Continuwuity's role within this system is to keep track of client-registered _pushers_ and send relevant payloads to them. To view and manage these pushers, use the [`!admin query pusher`](../reference/admin/query.md#admin-query-pusher) set of commands.
## UnifiedPush
[UnifiedPush][unifiedpush] is an open and self-hostable notifications system that is supported by many Matrix clients on Android and Linux. It is compatible with both the Web Push and Push Gateway mechanisms, and therefore requires no additional setup from the homeserver.
:::info Debugging UnifiedPush
To debug and test your UnifiedPush installation, use the [UP-Example] app for Android and the [UnifiedPush Troubleshooter] app for Linux distributions.
:::
[unifiedpush]: https://unifiedpush.org
[UP-Example]: https://codeberg.org/UnifiedPush/android-example
[UnifiedPush Troubleshooter]: https://flathub.org/en/apps/org.unifiedpush.Troubleshooter
### UnifiedPush and push gateways
The push gateway URL is usually pre-configured by the client app. However, some clients (such as Element X) implement UnifiedPush's [Gateway Discovery] mechanism, and attempt to detect a push gateway _on the same domain as the push provider_, before falling back to a hardcoded one.
Per the [spec][spec-push-gateway-api], these push gateways must be available on the `/_matrix/push/v1/notify` path of said domain. To test that a push gateway is accessible to the homeserver, make a request for it from the homeserver's IP:
```txt
curl https://push.example.com/_matrix/push/v1/notify
{"unifiedpush":{"gateway":"matrix"}}
```
[Gateway Discovery]: https://unifiedpush.org/users/gateway/#discovery--hosting
### ntfy
[ntfy][ntfy] is a widely supported UnifiedPush implementation, with an easy-to-install push app and plenty of publicly available instances. Its server includes an embedded Matrix push gateway and can be self-hosted.
Some tutorials on self-hosting ntfy can be found below:
- [Official ntfy self-hosting tutorial][official-ntfy-selfhosting]
- [Element's tutorial on Unified Push and ntfy][element-ntfy]
:::warning Avoid ntfy.sh
Avoid using the `https://ntfy.sh` push server, which is configured as the default in the ntfy app. This server is known to ratelimit requests aggressively.
:::
[ntfy]: https://ntfy.sh
[element-ntfy]: https://docs.element.io/latest/element-support/element-androidios-client-settings/using-unified-push-and-ntfy-for-push-notifications/
[official-ntfy-selfhosting]: https://docs.ntfy.sh/install/
### Other UnifiedPush distributors
To find a list of other UnifiedPush distributors, visit this [page][unifiedpush-distributors].
[unifiedpush-distributors]: https://unifiedpush.org/users/distributors/
Community tutorials for selfhosting some of these stacks are listed below. Unless stated otherwise, they are all tested against Element X Android and the push gateway mechanism, but they should work with Web Push as well.
- [Self-hosting Sunup for Matrix and UnifiedPush][kimiblock-selfhosting-sunup], by Kimiblock.
- Push gateway: [common-proxies]
- Push server: [autopush-rs]
- Push app: [Sunup][sunup]
- [Matrix notifications on Android, powered by XMPP][stratself-xmpp], by stratself.
- Push gateway: [common-proxies]
- Push server: [ejabberd's mod_unified_push]
- Push app: [Conversations] (and forks)
- [Element X push notifications via Conversations][alfredolin-xmpp], by Alfredo Lin.
- Push gateway: [common-proxies]
- Push server: [Prosody's mod_unified_push]
- Push app: [Conversations]
- Nextcloud's NextPush flow, which uses the following stack:
- Push server + push gateway: [uppush] (selfhosting tutorial included)
- Push app: [NextPush Android]
[kimiblock-selfhosting-sunup]: https://blog.kimiblock.top/2025/09/11/selfhosting-sunup/
[stratself-xmpp]: https://muoi.me/~stratself/articles/matrix-notifs-xmpp
[alfredolin-xmpp]: https://alfredolin.eu/blog/2026/07/24/element-x-push-notifications-via-conversations/
[common-proxies]: https://codeberg.org/UnifiedPush/common-proxies/
[sunup]: https://codeberg.org/Sunup/android
[autopush-rs]: https://github.com/mozilla-services/autopush-rs
[ejabberd's mod_unified_push]: https://github.com/processone/ejabberd-contrib/tree/master/mod_unified_push
[Prosody's mod_unified_push]: https://modules.prosody.im/mod_unified_push
[Conversations]: https://conversations.im
[uppush]: https://codeberg.org/NextPush/uppush
[NextPush Android]: https://codeberg.org/NextPush/nextpush-android
## Troubleshooting
Issues with push notifications can arise from the components of the system beyond your homeserver (for example, if the connection fails between the gateway and the push server). Make sure you check the logs of these components for debugging as well.
### Locally hosted push gateways / push providers
Outbound requests, including push notifications, follows the `ip_range_denylist` config option which refuses loopback and private-range destinations by default. This would break against push components that are self-hosted on a LAN address, and will result in these log entries at push creation time:
```txt
WARN conduwuit_service::pusher: Pusher URL is a forbidden remote address url=https://push.example.com/_matrix/push/v1/notify
```
To fix this, remove your push gateway or push server's address from `ip_range_denylist`, and restart Continuwuity to apply the changes.
### Push notifications not audible/not displaying
This is likely an issue with your account's _push rules_, which determines which events are shown to to the user as notifications. Check these push rules in the client's notifications settings and tweak accordingly. Continuwuity also provides an [`!admin users reset-push-rules`](../reference/admin/users#admin-users-reset-push-rules) command, which restores the rules to the default of notifying for every message.
Another reason may be that push background services are frequently being terminated by your operating system, which is a [well-known problem][dontkillmyapp] with many Android-based systems. To fix this, follow your operating system's instructions to exempt your push app from background restrictions.
Otherwise, if you find Continuwuity not sending push notifications according to the spec, feel free to discuss in our [support room][support-room] or open an issue.
[dontkillmyapp]: https://dontkillmyapp.com
[support-room]: https://matrix.to/#/#continuwuity:continuwuity.org?via=continuwuity.org&via=ellis.link&via=explodie.org&via=matrix.org
### Various "Could not send request to pusher" log entries
If you find spurious log entries like this in your Continuwuity deployment:
```txt
WARN push{user_id="@user:example.com" pushkey="very-long-string-of-letters" events=1}:send_push_notice:send_notice:send_request: conduwuit_service::pusher: Could not send request to pusher https//push.example.com: error sending request for url (https://push.example.com/_matrix/push/v1/notify)
```
Then, your server is most likely sending push requests to too many invalid targets. This could be due to one of the following reasons:
#### Connection issues between the server and the push gateway
Verify that the connection to the push gateway is working correctly. This includes checking firewall rules, DNS, and that the push gateway is online. The section on [locally-hosted gateways/push providers](#locally-hosted-push-gateways--push-providers) may also apply to you.
#### Expired push endpoints
Active Matrix clients periodically renew their pushkeys as the old ones expire, and consequently register them against Continuwuity. As these pushers build up over time, the homeserver will keep sending more requests to an increasing number of "dead" push endpoints. This results in the errors seen above, and can heavily impact performance if not mitigated.
To work around this issue, the following actions can be taken:
- Delete all of a user's pushers with the [`!admin query pusher delete-all-user`](../reference/admin/query##admin-query-pusher-delete-all-user) command. This command is not typically disruptive, as active clients will re-register new pushers the next time they log on.
- Alternatively, delete one's own pushers from a client that supports doing so. Currently this only includes FluffyChat and Element Classic/SchildiChat Legacy.
While clients are supposed to automatically delete old pushers under their own control, this behaviour has been inconsistent. A further discussion of this issue can be found in [#2242][issue-2242].
[issue-2242]: https://forgejo.ellis.link/continuwuation/continuwuity/issues/2242
## Related Documentation
Specifications:
- [Matrix specification for the Push Gateway API][spec-push-gateway-api]
- [Matrix Client-Server API for push notifications][spec-c-s-push-notifications]
- [UnifiedPush specifications][unifiedpush-spec]
- [MSC4174: Web push][MSC4174]
- [Web Push RFCs][webpush-rfcs]
Other:
- [Matrix Push Rules and Notifications][clokep-push] - blogpost on push rules in Matrix
[webpush-rfcs]: https://datatracker.ietf.org/wg/webpush/documents/
[spec-push-gateway-api]: https://spec.matrix.org/latest/push-gateway-api/
[spec-c-s-push-notifications]: https://spec.matrix.org/latest/client-server-api/#push-notifications
[unifiedpush-spec]: https://unifiedpush.org/developers/spec/definitions/
[clokep-push]: https://patrick.cloke.us/posts/2023/05/08/matrix-push-rules-notifications/
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -12,7 +12,7 @@
target:
target.fromToolchainName {
name = (lib.importTOML "${inputs.self}/rust-toolchain.toml").toolchain.channel;
sha256 = "sha256-p8h3Sl/YRByZfZTAKXdsvF6xEenXKrXSVvpphmZENH4=";
sha256 = "sha256-zm3dyIY2T414ZRR3EhLOvptzG6gta4WZUcawzMUWtqI=";
};
in
{
+90 -90
View File
@@ -125,13 +125,13 @@
}
},
"node_modules/@rsbuild/core": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/@rsbuild/core/-/core-2.2.5.tgz",
"integrity": "sha512-nf34ri1iZduYhHUr5Vc79L7Eml+IlN0nFIaF/g3OW4WR/gShxuf5wVXS69/H8FTHJYN4SdYlNcefSZQluEMKgA==",
"version": "2.2.11",
"resolved": "https://registry.npmjs.org/@rsbuild/core/-/core-2.2.11.tgz",
"integrity": "sha512-avPW0j6RaEbtV2mfl0AzTAJEimPX4Xj0pCcZyxNCrE9vkS91HmweM5V7XQj3kI5iTYfHRp9Y6To8RRHYLEvG7A==",
"dev": true,
"license": "MIT",
"dependencies": {
"@rspack/core": "~2.2.3",
"@rspack/core": "~2.2.8",
"@swc/helpers": "^0.5.23"
},
"bin": {
@@ -169,32 +169,32 @@
}
},
"node_modules/@rspack/binding": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding/-/binding-2.2.3.tgz",
"integrity": "sha512-532+T5N6yIdukChiL85H4NFN2vn9oi8wlLa1ByPNtpNYriE9s24fUhn0RiK7w/xACqnNpYmXCqLYCvjOzyCy+w==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding/-/binding-2.2.8.tgz",
"integrity": "sha512-c9flkSua3khHnOKBCRk8BkHGOwU9YB7niv+5JfQXiLZIvJmgKsZ7PD8QrFklMhsJT3oVAc6c9GN7/wy1YkACjA==",
"dev": true,
"license": "MIT",
"optionalDependencies": {
"@rspack/binding-darwin-arm64": "2.2.3",
"@rspack/binding-darwin-x64": "2.2.3",
"@rspack/binding-linux-arm64-gnu": "2.2.3",
"@rspack/binding-linux-arm64-musl": "2.2.3",
"@rspack/binding-linux-ppc64-gnu": "2.2.3",
"@rspack/binding-linux-riscv64-gnu": "2.2.3",
"@rspack/binding-linux-riscv64-musl": "2.2.3",
"@rspack/binding-linux-s390x-gnu": "2.2.3",
"@rspack/binding-linux-x64-gnu": "2.2.3",
"@rspack/binding-linux-x64-musl": "2.2.3",
"@rspack/binding-wasm32-wasi": "2.2.3",
"@rspack/binding-win32-arm64-msvc": "2.2.3",
"@rspack/binding-win32-ia32-msvc": "2.2.3",
"@rspack/binding-win32-x64-msvc": "2.2.3"
"@rspack/binding-darwin-arm64": "2.2.8",
"@rspack/binding-darwin-x64": "2.2.8",
"@rspack/binding-linux-arm64-gnu": "2.2.8",
"@rspack/binding-linux-arm64-musl": "2.2.8",
"@rspack/binding-linux-ppc64-gnu": "2.2.8",
"@rspack/binding-linux-riscv64-gnu": "2.2.8",
"@rspack/binding-linux-riscv64-musl": "2.2.8",
"@rspack/binding-linux-s390x-gnu": "2.2.8",
"@rspack/binding-linux-x64-gnu": "2.2.8",
"@rspack/binding-linux-x64-musl": "2.2.8",
"@rspack/binding-wasm32-wasi": "2.2.8",
"@rspack/binding-win32-arm64-msvc": "2.2.8",
"@rspack/binding-win32-ia32-msvc": "2.2.8",
"@rspack/binding-win32-x64-msvc": "2.2.8"
}
},
"node_modules/@rspack/binding-darwin-arm64": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-darwin-arm64/-/binding-darwin-arm64-2.2.3.tgz",
"integrity": "sha512-MGLx4lMTY6XEtJi55S+fk83+683GeUDuoqzjixbq6ehHdr/l6nGiHhgvMtV5DYt9sCytUDzyrCkcJ0AWqJxnTA==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-darwin-arm64/-/binding-darwin-arm64-2.2.8.tgz",
"integrity": "sha512-d6GuY/k7kJk7SOXmruIz0m+2fIXaLv2SnBHEYsbvBzE7ZO6QXq7fSABWFWNnSnNu+brYHA5Dr/skV81bXgTTCw==",
"cpu": [
"arm64"
],
@@ -206,9 +206,9 @@
]
},
"node_modules/@rspack/binding-darwin-x64": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-darwin-x64/-/binding-darwin-x64-2.2.3.tgz",
"integrity": "sha512-5B/c1YTYEz9m7TyqtGQgTmXMr9PoPewyqsyHB4N0AB7nxDhtgmki0GniP2Lqtx3LJzOvQMjwet+I2lmWxvxwCg==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-darwin-x64/-/binding-darwin-x64-2.2.8.tgz",
"integrity": "sha512-xCVou/jJASjEAjwy1T3hPJcJqA5QZASJfUwHqEk+nA0v44MagwH8tM8lsOvRfhzR7N2+YFac1rfZOUT8uM3awg==",
"cpu": [
"x64"
],
@@ -220,9 +220,9 @@
]
},
"node_modules/@rspack/binding-linux-arm64-gnu": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-2.2.3.tgz",
"integrity": "sha512-sU+jPGD2xz3BxFvsdBQVGce538YHqrSKMB4ZSfKhj6RSKjeGzpJ1BVl8+IndiQsfTgaUxi7N+r5cs/ezGy1TVQ==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-2.2.8.tgz",
"integrity": "sha512-Zy/ss6YAQTjOWKDkcWrbKtu+pySltqT22wn68nlrWKygPWLNmMdU5anlsnwRTIuQ3MF0YJRS42ARauVtlqvRQw==",
"cpu": [
"arm64"
],
@@ -237,9 +237,9 @@
]
},
"node_modules/@rspack/binding-linux-arm64-musl": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-musl/-/binding-linux-arm64-musl-2.2.3.tgz",
"integrity": "sha512-EQuADbqWbVgNAh5ep/u/B7Z/8UUkZjMLzHAOKZJklBpe4Y8mnhFNjieX0xc9NadR+drj9tqmEANxzTOkFtVPyQ==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-arm64-musl/-/binding-linux-arm64-musl-2.2.8.tgz",
"integrity": "sha512-lxgp5O8PhL3St9p82llHoNoeWzp9jltW5S9F00p00XPJZHUIuxbwfLSzn/6Wg86USEmafLoBkyD9CM8rBd3SNQ==",
"cpu": [
"arm64"
],
@@ -254,9 +254,9 @@
]
},
"node_modules/@rspack/binding-linux-ppc64-gnu": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-2.2.3.tgz",
"integrity": "sha512-kyXROzr519a5juBII9ysuc5ZD2apEZ0DJqL5PPCAOVHjzMfThEIBwnX3gicNCmp+kY0CCIOl2LagwbtFaOzoiA==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-2.2.8.tgz",
"integrity": "sha512-MY+YqpT02tcDCMgHy+IewQsaz7ql4mbJaAqqMlTIqvQwAUl9dXEP7BL352OgCxm9VRebTldE5lK99A3wVd3zqA==",
"cpu": [
"ppc64"
],
@@ -271,9 +271,9 @@
]
},
"node_modules/@rspack/binding-linux-riscv64-gnu": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-gnu/-/binding-linux-riscv64-gnu-2.2.3.tgz",
"integrity": "sha512-F3x6Nu0RUSoLtiaMse3hYQ3Nf5A2de6vTWWDXj14Ll6BpGWXGn+U/eXT/nB199fFnDEYf+CJEa7d6fzcYdwdjA==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-gnu/-/binding-linux-riscv64-gnu-2.2.8.tgz",
"integrity": "sha512-wmN9OigSGNGCKY+AOYaWI8LJcIi8qvs5KjueBueCKOnTV6MPIEujA75QZH1pehTTYKvdGv7r2EtUXUmWpn7/SQ==",
"cpu": [
"riscv64"
],
@@ -288,9 +288,9 @@
]
},
"node_modules/@rspack/binding-linux-riscv64-musl": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-musl/-/binding-linux-riscv64-musl-2.2.3.tgz",
"integrity": "sha512-O3HK7OnPvoBxZu4MX2j+t3gk4qiUsFYqj/29L3WgU1iQsdUSIN6PInW2JvbiLqyuzt09VltIEXTKayY8EysCpQ==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-riscv64-musl/-/binding-linux-riscv64-musl-2.2.8.tgz",
"integrity": "sha512-ZcQMYR10hLh581zs9MFnFFn0F7wyt5fkDffyukeMHJEoPJrbkfl6cQtsUdpQnZ+mYGYS5KydD1DT9/eMH65jjw==",
"cpu": [
"riscv64"
],
@@ -305,9 +305,9 @@
]
},
"node_modules/@rspack/binding-linux-s390x-gnu": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-2.2.3.tgz",
"integrity": "sha512-SIxfGdwBdAjwJ8pDlPTb8MPIZIv/i2lKHn4/ywuDpFOxlUA4Bo/OKqQOenHx2MFD2mN8jigBZQTF0KVe5YP1uQ==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-2.2.8.tgz",
"integrity": "sha512-ahBiE+Ir1FMYvStYicihhSJlS2YRagxtry0jWH8zW287o7C0eiHJ+pteJHHC15T5RJqm0j6w5TuwYe+F9AYxxg==",
"cpu": [
"s390x"
],
@@ -322,9 +322,9 @@
]
},
"node_modules/@rspack/binding-linux-x64-gnu": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-gnu/-/binding-linux-x64-gnu-2.2.3.tgz",
"integrity": "sha512-IzQGcw09WYn/IzwB1SQpg7FQ211MBr+fJB2/WoRrPS6CNdtlkDHZaI8z2oq+2Oc5Su21jgX75VlWFajirUx5Dw==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-gnu/-/binding-linux-x64-gnu-2.2.8.tgz",
"integrity": "sha512-dncEI515NoPXh3zzWk06Rb3mhSV76myiFKqXiJ8K4fVAe5x/RlweMhvPhHhm7RnIMeBld7BeStzOqj38XFsWGA==",
"cpu": [
"x64"
],
@@ -339,9 +339,9 @@
]
},
"node_modules/@rspack/binding-linux-x64-musl": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-musl/-/binding-linux-x64-musl-2.2.3.tgz",
"integrity": "sha512-9OKSx2ickrR+PFal94XE6Hkj49AQ2HI3KuR9XeRkKOwSxjwrskV/Pn1wc2itDOHkm/QHP7k+MttsYb4FGuNIqw==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-linux-x64-musl/-/binding-linux-x64-musl-2.2.8.tgz",
"integrity": "sha512-pfFyU03PjD0GaQG8zOQOHwq51rrJZetXjTGpMmz7iA1hq/f9lChJsDWrC8/7VXeQLwBofLZlOODqe8OM8OBzgA==",
"cpu": [
"x64"
],
@@ -356,9 +356,9 @@
]
},
"node_modules/@rspack/binding-wasm32-wasi": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-wasm32-wasi/-/binding-wasm32-wasi-2.2.3.tgz",
"integrity": "sha512-gici3jWJi0GDy9kbYh57LoA57H8A2EAD9cV2jFKp1YoJ2aX2U9lANh4L+xoKPTvVQYpRvleoA5jkAvyfeLQ5bw==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-wasm32-wasi/-/binding-wasm32-wasi-2.2.8.tgz",
"integrity": "sha512-3mOJuZTrF56jOh/GD9chLMJKbzPZ6Ty2OIML7+lLz0Yk2XS/xWRfLn85Dmnkb/O6UF65x7+p8VPAIZlBtLTclw==",
"cpu": [
"wasm32"
],
@@ -372,9 +372,9 @@
}
},
"node_modules/@rspack/binding-win32-arm64-msvc": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-2.2.3.tgz",
"integrity": "sha512-1MG66kcuqAGFs9ewiBc+/NJSTQr1jHrkZ2nCVMyhukl1o8embmFZa3BCibYgBYs5P7FRc6Sa+CDXcrfDZOLInQ==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-2.2.8.tgz",
"integrity": "sha512-Cu/RMZT/16s+67xhl6X1pswetL3GLSQl+LnugKRh08Ul21A/tR7vxC4g4aih4u9k5SXCAngxFUt8zAjKnHIBqA==",
"cpu": [
"arm64"
],
@@ -386,9 +386,9 @@
]
},
"node_modules/@rspack/binding-win32-ia32-msvc": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-ia32-msvc/-/binding-win32-ia32-msvc-2.2.3.tgz",
"integrity": "sha512-CAigxxh9DYJmEwH9f6FRkSsmt0GhKVqKaFRVFFrF9WDL7gXP3hyE/h/cCeMdmlTzRt8Mht87AvnDX7PG3neMrA==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-ia32-msvc/-/binding-win32-ia32-msvc-2.2.8.tgz",
"integrity": "sha512-H/erd6di8OapZhhM0raA/7XduPn9jusfLMeO1XF+AmF9WF3HzHgMjha1j+KwtPgQnaH69w6AhY+G2472VIwQmw==",
"cpu": [
"ia32"
],
@@ -400,9 +400,9 @@
]
},
"node_modules/@rspack/binding-win32-x64-msvc": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-x64-msvc/-/binding-win32-x64-msvc-2.2.3.tgz",
"integrity": "sha512-qa5Wc34a+Uux5foZ1Z+9fPQceVRbgTunaIulHezVF/ZxvqKO4DkAC7tFl53shB0YRVBAPg8R78MGd8cByfoxLQ==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/binding-win32-x64-msvc/-/binding-win32-x64-msvc-2.2.8.tgz",
"integrity": "sha512-BziHSUlIQM0MliCqdcHuBXSkQGtPoHQTXJce7fsgnTAzQFgPeog92qTNezYI4IrQ7pQouyiVJ2HPieUbVPRKQQ==",
"cpu": [
"x64"
],
@@ -414,13 +414,13 @@
]
},
"node_modules/@rspack/core": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@rspack/core/-/core-2.2.3.tgz",
"integrity": "sha512-VHejw+PDd5B5v6VduFyjLSTIFaHBMNGPMKw+Y0zjkMqjYhDD1hjLOBC5frRKjTWcfYdk+Q73auWPp9k/H9PfIQ==",
"version": "2.2.8",
"resolved": "https://registry.npmjs.org/@rspack/core/-/core-2.2.8.tgz",
"integrity": "sha512-JugsVrnbMGNYzMH++7gR9enygpP/lAo9PbVRq3XmJg0ryIvCpST0XJjBcccaSjYaaPamsjrddihmgVLMFp+yXw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@rspack/binding": "2.2.3"
"@rspack/binding": "2.2.8"
},
"engines": {
"node": "^20.19.0 || >=22.12.0"
@@ -455,17 +455,17 @@
}
},
"node_modules/@rspress/core": {
"version": "2.0.22",
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.0.22.tgz",
"integrity": "sha512-mS/+xJYxVSR72GAjTz8GIGcJwwb2NSbbduq1fQOSv7k73EJ2aa0Q/o14nnnI4DRmRSEmK0t81vkVGcKHWQzPcA==",
"version": "2.0.23",
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.0.23.tgz",
"integrity": "sha512-two8zdTxN9iJBSyiFXwRLLDXz/yLY2+4ycz8wHjJYzeeuFi/EN2eqsKw1nSpY7sxEGIssY1X74c6017JJUBTyA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@mdx-js/mdx": "^3.1.1",
"@mdx-js/react": "^3.1.1",
"@rsbuild/core": "^2.2.5",
"@rsbuild/core": "^2.2.10",
"@rsbuild/plugin-react": "~2.1.0",
"@rspress/shared": "2.0.22",
"@rspress/shared": "2.0.23",
"@shikijs/rehype": "^4.2.0",
"@types/mdast": "^4.0.4",
"@types/react": "^19.2.18",
@@ -484,7 +484,7 @@
"react-dom": "^19.2.8",
"react-lazy-with-preload": "^2.2.1",
"react-render-to-markdown": "19.1.0",
"react-router-dom": "^7.18.3",
"react-router-dom": "^7.18.4",
"rehype-external-links": "^3.0.0",
"rehype-raw": "^7.0.0",
"remark-cjk-friendly": "^2.3.1",
@@ -508,9 +508,9 @@
}
},
"node_modules/@rspress/plugin-client-redirects": {
"version": "2.0.22",
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.0.22.tgz",
"integrity": "sha512-pyOLIfxji1xbh//H0egdmhXVdO5hfp9dLXCTnZKcet9K3FJpre21/syuhRbRwWviMpcKtE73PZVcSaNVTYQYZw==",
"version": "2.0.23",
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.0.23.tgz",
"integrity": "sha512-TdpvO3TREv6s2mE32ztFvG3P232qUwjyQCKKsb9g0XT0q7rzcStZFRE7XT/L8i0XTzH/mfli1tVl4guTea/J3Q==",
"dev": true,
"license": "MIT",
"engines": {
@@ -521,9 +521,9 @@
}
},
"node_modules/@rspress/plugin-sitemap": {
"version": "2.0.22",
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.0.22.tgz",
"integrity": "sha512-2SNLW8Oh4osCyqnzea1WDVA9469Luwu0piNuh5HNjlzcgjguzynA3447WRFpqBL1Z/B7H5IB5SMcwYaMsgFhvQ==",
"version": "2.0.23",
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.0.23.tgz",
"integrity": "sha512-r37TvCP2wuQX8JbA7hHti8JXhVx4HiaJPn702NgFhGyolGJYIUTRQCO2/ixiP1FZJuxZ4c0yb4ZyNeDa9ZPMlw==",
"dev": true,
"license": "MIT",
"engines": {
@@ -534,13 +534,13 @@
}
},
"node_modules/@rspress/shared": {
"version": "2.0.22",
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.0.22.tgz",
"integrity": "sha512-1UXwG6gAhWBw5vClv3wb2Oy8hPXYNgQwQ5zWXEG8auY5ZcMywvHCBi6pFJtYNOgXe5327lNgiOG0S1R8l0OLeg==",
"version": "2.0.23",
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.0.23.tgz",
"integrity": "sha512-kE2GXRCQ7GAl2wll1JBWRHEkZICKcWv3V86m8TkjiWb0eEdjACl3kns7j00KTq4UbE35kUPOs+0Lx8vGqK7q9w==",
"dev": true,
"license": "MIT",
"dependencies": {
"@rsbuild/core": "^2.2.5",
"@rsbuild/core": "^2.2.10",
"@shikijs/rehype": "^4.2.0",
"@types/react": "^19.2.18",
"mdast-util-mdx-jsx": "^3.2.0",
@@ -3288,9 +3288,9 @@
}
},
"node_modules/react-router": {
"version": "7.18.3",
"resolved": "https://registry.npmjs.org/react-router/-/react-router-7.18.3.tgz",
"integrity": "sha512-gyXgtdr5uACJ5b1Q4udzjVV+tb/rlHIMJKuJ0e89R4Kzgz47z/rgP0dIKxktqIEUhDHluGTPJJH/wRha7CyqsA==",
"version": "7.18.4",
"resolved": "https://registry.npmjs.org/react-router/-/react-router-7.18.4.tgz",
"integrity": "sha512-PUPQcMhMGRAslLcvtlPz/kmzBEWPhLdgLFrL7pLNepBL6dX0lWj4WD2cUYVgYCuT3jxvghYFg81cDTj44DhetQ==",
"dev": true,
"license": "MIT",
"dependencies": {
@@ -3311,13 +3311,13 @@
}
},
"node_modules/react-router-dom": {
"version": "7.18.3",
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-7.18.3.tgz",
"integrity": "sha512-ytVbyBBM7vMfRCam25r0WMhSVSom909A8p+8m0/f1w853dz/xfFu6etAT2SEbVoSnI+ZoPRDqIsQXVT89gp7kg==",
"version": "7.18.4",
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-7.18.4.tgz",
"integrity": "sha512-yrfmJHIpDG7taCpqKjT1G5B6q3O2K+RN8/fgNf0lTjCwiPbQ0ei6vXX9ZjQR+7ld8Tr7Z5xmyMnZ8YJrphWQUw==",
"dev": true,
"license": "MIT",
"dependencies": {
"react-router": "7.18.3"
"react-router": "7.18.4"
},
"engines": {
"node": ">=20.0.0"
+4
View File
@@ -18,6 +18,8 @@ export default defineConfig({
markdown: {
link: {
checkDeadLinks: {
// exclude files in the `docs/public` folder from dead link checking
// (they are linked to without the `/public` prefix)
excludes: [
'/deploying/docker-compose.with-caddy.yml',
'/deploying/docker-compose.with-caddy-labels.yml',
@@ -31,6 +33,8 @@ export default defineConfig({
'/advanced/delegated.docker-compose.with-traefik.yml',
'/calls/livekit.docker-compose.with-caddy-labels.yml',
'/calls/livekit.nginx.conf',
'/guides/grafana-dashboard.json',
'/guides/push-notifications.excalidraw',
'CONTRIBUTING.md'
]
},
+1 -1
View File
@@ -10,7 +10,7 @@
[toolchain]
profile = "minimal"
channel = "1.98.1"
channel = "1.99.0"
components = [
# For rust-analyzer
"rust-src",
+30 -8
View File
@@ -31,14 +31,36 @@ const AUTO_GEN_PASSWORD_LENGTH: usize = 25;
const BULK_JOIN_REASON: &str = "Bulk force joining this room as initiated by the server admin.";
impl crate::Context<'_> {
pub(super) async fn list_users(&self) -> Result {
let users: Vec<_> = self
.services
.users
.stream_local_users()
.map(|id| id.as_str().to_owned())
.collect()
.await;
pub(super) async fn list_users(
&self,
show_deactivated: bool,
hide_suspended: bool,
hide_locked: bool,
) -> Result {
let mut users: Vec<String> = Vec::new();
let mut user_stream = self.services.users.stream_local_users();
while let Some(id) = user_stream.next().await {
if !show_deactivated {
if matches!(self.services.users.status(&id).await, AccountStatus::Deactivated) {
continue;
}
}
let suspended = match self.services.users.is_suspended(&id).await {
| Err(_) => continue,
| Ok(suspended) => suspended,
};
if hide_suspended && suspended {
continue;
}
let locked = match self.services.users.is_locked(&id).await {
| Err(_) => continue,
| Ok(locked) => locked,
};
if hide_locked && locked {
continue;
}
users.push(id.as_str().to_owned());
}
let mut plain_msg = format!("Found {} local user account(s):\n```\n", users.len());
plain_msg += users.join("\n").as_str();
+11 -1
View File
@@ -164,7 +164,17 @@ pub enum UserCommand {
/// List local users in the database
#[command(name = "list", alias = "list-users")]
ListUsers,
ListUsers {
// Include deactivated users in the user list
#[arg(long)]
show_deactivated: bool,
// Hide suspended accounts from the user list
#[arg(long)]
hide_suspended: bool,
// Hide locked accounts from the user list
#[arg(long)]
hide_locked: bool,
},
/// Lists all the rooms (local and remote) that the specified user is
/// invited to
+15 -11
View File
@@ -1,14 +1,17 @@
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};
use axum::extract::State;
use conduwuit::{Result, Server};
use ruma::{
RoomVersionId,
api::client::discovery::get_capabilities::{
self,
v3::{
Capabilities, GetLoginTokenCapability, ProfileFieldsCapability, RoomVersionStability,
RoomVersionsCapability, ThirdPartyIdChangesCapability,
api::{
OAuthClientScope,
client::discovery::get_capabilities::{
self,
v3::{
AdminCapability, Capabilities, GetLoginTokenCapability, ProfileFieldsCapability,
RoomVersionStability, RoomVersionsCapability, ThirdPartyIdChangesCapability,
},
},
},
assign,
@@ -25,6 +28,8 @@ pub(crate) async fn get_capabilities_route(
State(services): State<crate::State>,
body: Ruma<get_capabilities::v3::Request>,
) -> Result<get_capabilities::v3::Response> {
let sender_user = body.identity.expect_sender_user()?;
let available: BTreeMap<RoomVersionId, RoomVersionStability> =
Server::available_room_versions().collect();
@@ -43,13 +48,12 @@ pub(crate) async fn get_capabilities_route(
capabilities.forget_forced_upon_leave.enabled = true;
if services
.users
.is_admin(body.identity.expect_sender_user()?)
.await
{
if services.users.is_admin(sender_user).await {
capabilities.account_moderation.lock = true;
capabilities.account_moderation.suspend = true;
capabilities.admin =
AdminCapability::new(BTreeSet::from_iter([OAuthClientScope::ServerAdministration]));
}
capabilities.profile_fields = Some(
+10 -2
View File
@@ -267,11 +267,19 @@ pub(crate) async fn get_public_rooms_filtered_helper(
summary.into()
})
.ready_filter_map(|chunk: PublicRoomsChunk| {
if !filter.room_types.is_empty() && !filter.room_types.contains(&RoomTypeFilter::from(chunk.room_type.clone())) {
if !filter.room_types.is_empty()
&& !filter
.room_types
.contains(&RoomTypeFilter::from(chunk.room_type.clone()))
{
return None;
}
if let Some(query) = filter.generic_search_term.as_ref().map(|q| q.to_lowercase()) {
if let Some(query) = filter
.generic_search_term
.as_ref()
.map(|q| q.to_lowercase())
{
if let Some(name) = &chunk.name {
if name.to_lowercase().contains(&query) {
return Some(chunk);
+26
View File
@@ -2,6 +2,7 @@ use axum::extract::State;
use conduwuit::{
Err, Result, debug_error, err, info,
matrix::{event::gen_event_id_canonical_json, pdu::PartialPdu},
metrics::KeyValue,
trace, warn,
};
use futures::FutureExt;
@@ -113,6 +114,31 @@ pub(crate) async fn invite_helper(
room_id: &RoomId,
reason: Option<String>,
is_direct: bool,
) -> Result {
let result =
send_invite(services, sender_user, recipient_user, room_id, reason, is_direct).await;
let destination = if services.globals.user_is_local(recipient_user) {
"local"
} else {
"remote"
};
services.server.metrics.instruments.invites.add(1, &[
KeyValue::new("direction", "outgoing"),
KeyValue::new("destination", destination),
KeyValue::new("outcome", if result.is_ok() { "success" } else { "failure" }),
]);
result
}
async fn send_invite(
services: &Services,
sender_user: &UserId,
recipient_user: &UserId,
room_id: &RoomId,
reason: Option<String>,
is_direct: bool,
) -> Result {
if !services.users.is_admin(sender_user).await && services.config.block_non_admin_invites {
info!(
+4 -1
View File
@@ -55,5 +55,8 @@ fn oauth_router() -> Router<crate::State> {
.route(concat!("/", JWKS_URI_PATH), get(async || Json(json!({"keys": []}))))
.route(concat!("/", TOKEN_PATH), post(token::token_route))
.route(concat!("/", TOKEN_REVOKE_PATH), post(token::revoke_token_route))
.route(concat!("/", DEVICE_AUTHORIZATION_PATH), post(device::device_authorization_route))
.route(
concat!("/", DEVICE_AUTHORIZATION_PATH),
post(device::device_authorization_route),
)
}
+12
View File
@@ -29,6 +29,12 @@ pub(crate) async fn get_profile_route(
State(services): State<crate::State>,
body: Ruma<get_profile::v3::Request>,
) -> Result<get_profile::v3::Response> {
if services.config.require_auth_for_profile_requests && body.identity.is_none() {
return Err!(Request(Unauthorized(
"This server requires authentication to access user profiles."
)));
}
let Some(profile) = fetch_full_profile(&services, &body.user_id).await else {
return Err!(Request(NotFound("This user's profile could not be fetched.")));
};
@@ -40,6 +46,12 @@ pub(crate) async fn get_profile_field_route(
State(services): State<crate::State>,
body: Ruma<get_profile_field::v3::Request>,
) -> Result<get_profile_field::v3::Response> {
if services.config.require_auth_for_profile_requests && body.identity.is_none() {
return Err!(Request(Unauthorized(
"This server requires authentication to access user profiles."
)));
}
let value = fetch_profile_field(&services, &body.user_id, body.field.clone()).await?;
Ok(assign!(get_profile_field::v3::Response::default(), { value }))
+6 -4
View File
@@ -77,7 +77,7 @@ pub(crate) async fn set_read_marker_route(
.readreceipt_update(
sender_user,
&body.room_id,
&ReceiptEvent::new(
ReceiptEvent::new(
body.room_id.clone(),
ReceiptEventContent::from_iter(receipt_content),
),
@@ -103,7 +103,8 @@ pub(crate) async fn set_read_marker_route(
services
.rooms
.read_receipt
.private_read_set(&body.room_id, sender_user, count);
.private_read_set(&body.room_id, sender_user, event, count)
.await;
}
services.sync.wake(sender_user).await;
@@ -176,7 +177,7 @@ pub(crate) async fn create_receipt_route(
.readreceipt_update(
sender_user,
&body.room_id,
&ReceiptEvent::new(
ReceiptEvent::new(
body.room_id.clone(),
ReceiptEventContent::from_iter(receipt_content),
),
@@ -200,7 +201,8 @@ pub(crate) async fn create_receipt_route(
services
.rooms
.read_receipt
.private_read_set(&body.room_id, sender_user, count);
.private_read_set(&body.room_id, sender_user, &body.event_id, count)
.await;
},
| _ => {
return Err!(Request(InvalidParam(warn!(
+18 -5
View File
@@ -2,15 +2,21 @@ use axum::extract::State;
use conduwuit::{
Err, Event, Result, at, debug_warn,
result::LogErr,
utils::{BoolExt, stream::TryTools},
utils::{
BoolExt,
stream::{TryIgnore, WidebandExt},
},
};
use futures::{FutureExt, TryStreamExt, future::try_join4};
use futures::{FutureExt, StreamExt, TryStreamExt, future::try_join4};
use ruma::{
api::client::peeking::get_current_state::v3::{PaginationChunk, Request, Response},
assign,
};
use crate::Ruma;
use crate::{
Ruma,
client::{ignored_filter, visibility_filter},
};
const LIMIT_MAX: usize = 100;
@@ -52,8 +58,11 @@ pub(crate) async fn room_initial_sync_route(
.rooms
.timeline
.pdus_rev(room_id, None)
.try_take(limit)
.and_then(async |mut pdu| {
.ignore_err()
.wide_filter_map(|item| ignored_filter(&services, item, sender_user))
.wide_filter_map(|item| visibility_filter(&services, item, sender_user))
.take(limit)
.wide_then(async |mut pdu| {
let ctx = services
.rooms
.timeline
@@ -77,6 +86,10 @@ pub(crate) async fn room_initial_sync_route(
.boxed()
.await?;
if events.is_empty() {
return Ok(Response::new(room_id.to_owned()));
}
let end = events
.first()
.map(at!(0))
+23 -2
View File
@@ -6,7 +6,10 @@ use conduwuit::{
matrix::pdu::{PartialPdu, sticky},
utils,
};
use ruma::{api::client::message::send_message_event, events::MessageLikeEventType};
use ruma::{
OwnedEventId, api::client::message::send_message_event, events::MessageLikeEventType,
};
use serde::Deserialize;
use serde_json::from_str;
use crate::{Ruma, client_ip::ClientIp};
@@ -77,6 +80,13 @@ pub(crate) async fn send_message_event_route(
let content = from_str(body.body.body.json().get())
.map_err(|e| err!(Request(BadJson("Invalid JSON body: {e}"))))?;
let redacts = if body.body.event_type == MessageLikeEventType::RoomRedaction {
from_str::<MaybeRedaction>(body.body.body.json().get())
.ok()
.and_then(|r| r.redacts)
} else {
None
};
let event_id = services
.rooms
@@ -92,11 +102,14 @@ pub(crate) async fn send_message_event_route(
.flatten()
.map(sticky::object),
unsigned: Some(unsigned),
timestamp: if body.identity.is_appservice() {
timestamp: if body.identity.is_appservice()
|| services.admin.user_is_admin(sender_user).await
{
body.timestamp
} else {
None
},
redacts,
..Default::default()
},
sender_user,
@@ -116,3 +129,11 @@ pub(crate) async fn send_message_event_route(
Ok(send_message_event::v3::Response::new(event_id))
}
/// Struct containing exclusively the `redacts` field for MSC4169 compatible
/// redaction moving.
#[derive(Deserialize)]
struct MaybeRedaction {
#[serde(default)]
redacts: Option<OwnedEventId>,
}
+17 -12
View File
@@ -1563,20 +1563,25 @@ where
// joined users
device_list_changes.extend(
services
.rooms
.state_cache
.room_members(room_id)
// Don't send key updates from the sender to the sender
.ready_filter(|user_id| sender_user != *user_id)
// Only send keys if the sender doesn't share an encrypted room with the target
// already
.filter_map(async |user_id| {
share_encrypted_room(services, sender_user, &user_id, Some(room_id))
.rooms
.state_cache
.room_members(room_id)
// Don't send key updates from the sender to the sender
.ready_filter(|user_id| sender_user != *user_id)
// Only send keys if the sender doesn't share an encrypted room with
// the target already
.filter_map(async |user_id| {
share_encrypted_room(
services,
sender_user,
&user_id,
Some(room_id),
)
.map(|res| res.or_some(user_id.clone()))
.await
})
.collect::<Vec<_>>()
.await,
})
.collect::<Vec<_>>()
.await,
);
}
}
+31 -1
View File
@@ -1,9 +1,12 @@
use axum::{Json, extract::State, response::IntoResponse};
use conduwuit::{
Result,
Err, Result,
matrix::versions::{unstable_features, versions},
metrics::PROMETHEUS_CONTENT_TYPE,
utils::string::constant_time_eq,
};
use futures::StreamExt;
use http::{HeaderMap, header};
use ruma::{api::client::discovery::get_supported_versions, assign};
use crate::Ruma;
@@ -75,3 +78,30 @@ pub(crate) async fn continuwuity_local_user_count(
"count": user_count
})))
}
/// # `GET /_continuwuity/metrics`
///
/// Prometheus metrics in the text exposition format. Only routed when
/// `allow_prometheus_metrics` is enabled.
pub(crate) async fn continuwuity_metrics(
State(services): State<crate::State>,
headers: HeaderMap,
) -> Result<impl IntoResponse> {
if let Some(token) = &services.config.prometheus_metrics_token {
let authorized = headers
.get(header::AUTHORIZATION)
.and_then(|value| value.to_str().ok())
.and_then(|value| value.split_once(' '))
.is_some_and(|(scheme, provided)| {
scheme.eq_ignore_ascii_case("bearer") && constant_time_eq(provided, token)
});
if !authorized {
return Err!(Request(Unauthorized("Invalid metrics token")));
}
}
let body = services.server.metrics.render()?;
Ok(([(header::CONTENT_TYPE, PROMETHEUS_CONTENT_TYPE)], body))
}
+22 -9
View File
@@ -21,7 +21,7 @@ use crate::{admin, client, server};
pub fn build(router: Router<State>, state: State) -> Router<State> {
let config = &state.server.config;
let mut router = router
.ruma_route(&client::appservice_ping)
.ruma_route(&client::appservice_ping)
.ruma_route(&client::get_supported_versions_route)
.ruma_route(&client::get_register_available_route)
.ruma_route(&client::register::register_route)
@@ -61,8 +61,8 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
.ruma_route(&client::get_global_account_data_route)
.ruma_route(&client::get_room_account_data_route)
.ruma_route(&client::get_profile_field_route)
.ruma_route(&client::set_profile_field_route)
.ruma_route(&client::delete_profile_field_route)
.ruma_route(&client::set_profile_field_route)
.ruma_route(&client::delete_profile_field_route)
.ruma_route(&client::get_profile_route)
.ruma_route(&client::set_presence_route)
.ruma_route(&client::get_presence_route)
@@ -112,14 +112,17 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
.ruma_route(&client::search_users_route)
.ruma_route(&client::get_member_events_route)
.ruma_route(&client::get_protocols_route)
.route("/_matrix/client/unstable/thirdparty/protocols",
get(client::get_protocols_route_unstable))
.route(
"/_matrix/client/unstable/thirdparty/protocols",
get(client::get_protocols_route_unstable),
)
.ruma_route(&client::send_message_event_route)
.ruma_route(&client::send_state_event_for_key_route)
.ruma_route(&client::get_state_events_route)
.ruma_route(&client::get_state_event_for_key_route)
// Ruma doesn't have support for multiple paths for a single endpoint yet, and these routes
// share one Ruma request / response type pair with {get,send}_state_event_for_key_route
// Ruma doesn't have support for multiple paths for a single endpoint yet, and these
// routes share one Ruma request / response type pair with
// {get,send}_state_event_for_key_route
.route(
"/_matrix/client/r0/rooms/{room_id}/state/{event_type}",
get(client::get_state_events_for_empty_key_route)
@@ -196,10 +199,17 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
.ruma_route(&admin::rooms::ban::ban_room)
.ruma_route(&admin::rooms::list::list_rooms);
if config.allow_prometheus_metrics {
router = router.route("/_continuwuity/metrics", get(client::continuwuity_metrics));
}
if config.allow_federation {
router = router
.ruma_route(&server::get_server_version_route)
.route("/_matrix/key/v2/server", get(server::get_server_keys_route))
.ruma_route(&server::get_server_keys_route)
.ruma_route(&server::get_remote_server_keys_batch_route)
.ruma_route(&server::get_remote_server_keys_batch_v3_unstable_route)
.ruma_route(&server::get_remote_server_keys_route)
.ruma_route(&server::get_public_rooms_route)
.ruma_route(&server::get_public_rooms_filtered_route)
.ruma_route(&server::send_transaction_message_route)
@@ -221,7 +231,6 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
.ruma_route(&server::get_profile_information_route)
.ruma_route(&server::get_keys_route)
.ruma_route(&server::claim_keys_route)
.ruma_route(&server::get_openid_userinfo_route)
.ruma_route(&server::get_hierarchy_route)
.ruma_route(&server::well_known_server)
.ruma_route(&server::get_content_route)
@@ -235,6 +244,10 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
.route("/_continuwuity/local_user_count", any(federation_disabled));
}
// Always add userinfo endpoint, even if federation is disabled, so livekit
// and other functionality will continue to work
router = router.ruma_route(&server::get_openid_userinfo_route);
if config.allow_legacy_media {
router = router
.ruma_route(&client::get_media_config_legacy_route)
+13 -4
View File
@@ -8,7 +8,7 @@ use axum::{
use conduwuit::{Error, Result, err};
use ruma::{
CanonicalJsonObject,
api::{IncomingRequest, IncomingRequestExt},
api::{IncomingRequest, IncomingRequestExt, auth_scheme::AuthScheme},
};
use serde::Deserialize;
@@ -92,13 +92,22 @@ where
let request = hyper::Request::from_parts(parts, body.as_ref());
// Check authentication
let auth =
R::Authentication::authenticate::<R, &[u8]>(services, &request, auth_query).await?;
let authentication =
R::Authentication::extract_authentication(&request).map_err(|err| {
err!(Request(Unauthorized(warn!(
path = request.uri().path(),
err = err.into(),
"Failed to extract authentication"
))))
})?;
let identity =
R::Authentication::check::<R>(services, &request, authentication, auth_query).await?;
// Deserialize the body
let body = R::try_from_http_request(request, &borrowed_path)
.map_err(|e| err!(Request(BadJson(debug_warn!("{e}")))))?;
Ok(Self { body, json_body, identity: auth })
Ok(Self { body, json_body, identity })
}
}
+226 -199
View File
@@ -1,4 +1,7 @@
use std::any::{Any, TypeId};
use std::{
any::{Any, TypeId},
collections::BTreeSet,
};
use conduwuit::{
Err, Error, Result, err,
@@ -9,13 +12,13 @@ use ruma::{
DeviceId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedServerName, OwnedUserId, UInt,
UserId,
api::{
IncomingRequest,
IncomingRequest, OAuthClientScope,
auth_scheme::{
AccessToken, AccessTokenOptional, AppserviceToken, AppserviceTokenOptional,
AuthScheme, NoAccessToken, NoAuthentication,
},
client,
error::{ErrorKind, UnknownTokenErrorData},
error::{ErrorKind, InsufficientUserAuthenticationErrorData, UnknownTokenErrorData},
federation::authentication::ServerSignatures,
},
assign,
@@ -84,75 +87,50 @@ impl ClientIdentity {
pub(crate) trait CheckAuth: AuthScheme {
type Identity: Send;
fn authenticate<R: IncomingRequest + Any, B: AsRef<[u8]> + Sync>(
fn check<R: IncomingRequest<Authentication = Self> + Any>(
services: &Services,
incoming_request: &hyper::Request<B>,
incoming_request: &hyper::Request<&[u8]>,
authentication: Self::Output,
query: AuthQueryParams,
) -> impl Future<Output = Result<Self::Identity>> + Send {
async move {
let route = TypeId::of::<R>();
let output = Self::extract_authentication(incoming_request).map_err(|err| {
err!(Request(Unauthorized(warn!(
"Failed to extract authorization: {}",
err.into()
))))
})?;
Self::verify(services, output, incoming_request, query, route).await
}
}
fn verify<B: AsRef<[u8]> + Sync>(
services: &Services,
output: Self::Output,
request: &hyper::Request<B>,
query: AuthQueryParams,
route: TypeId,
) -> impl Future<Output = Result<Self::Identity>> + Send;
}
impl CheckAuth for ServerSignatures {
type Identity = OwnedServerName;
async fn verify<B: AsRef<[u8]> + Sync>(
async fn check<R: IncomingRequest<Authentication = Self> + Any>(
services: &Services,
output: Self::Output,
request: &hyper::Request<B>,
incoming_request: &hyper::Request<&[u8]>,
authentication: Self::Output,
_query: AuthQueryParams,
_route: TypeId,
) -> Result<Self::Identity> {
let destination = services.globals.server_name();
if output
.destination
.as_ref()
.is_some_and(|supplied_destination| supplied_destination != destination)
{
return Err!(Request(Unauthorized("Destination mismatch.")));
}
let min_valid_ts =
MilliSecondsSinceUnixEpoch(UInt::new_saturating(millis_since_unix_epoch()));
let key = services
.server_keys
.get_single_verify_key(&output.origin, &output.key, min_valid_ts)
.get_single_verify_key(&authentication.origin, &authentication.key, min_valid_ts)
.await
.ok_or_else(|| {
err!(Request(Unauthorized(debug_warn!(
origin=%output.origin,
origin=%authentication.origin,
"Unable to acquire your signing key (ID: {})",
output.key
authentication.key
))))
})?;
let keys: PubKeys = [(output.key.to_string(), key.key)].into();
let keys: PubKeyMap = [(output.origin.as_str().into(), keys)].into();
let keys: PubKeys = [(authentication.key.to_string(), key.key)].into();
let keys: PubKeyMap = [(authentication.origin.as_str().into(), keys)].into();
match output.verify_http_request(request, destination, &keys) {
match authentication.verify_http_request(
incoming_request,
services.globals.server_name(),
&keys,
) {
| Ok(()) => {
if services
.moderation
.is_remote_server_forbidden(&output.origin)
.is_remote_server_forbidden(&authentication.origin)
{
return Err!(Request(Forbidden(
"You are blocked from federating with this server."
@@ -160,15 +138,15 @@ impl CheckAuth for ServerSignatures {
}
// Ping the server as healthy
if services.federation.mark_healthy(&output.origin) {
if services.federation.mark_healthy(&authentication.origin) {
services
.sending
.flush_servers([output.origin.clone()].stream())
.flush_servers([authentication.origin.clone()].stream())
.await
.ok();
}
Ok(output.origin)
Ok(authentication.origin)
},
| Err(err) => Err!(Request(Unauthorized(debug_warn!(
"Failed to verify X-Matrix header: {err}"
@@ -180,120 +158,44 @@ impl CheckAuth for ServerSignatures {
impl CheckAuth for AccessToken {
type Identity = ClientIdentity;
async fn verify<B: AsRef<[u8]> + Sync>(
async fn check<R: IncomingRequest<Authentication = Self> + Any>(
services: &Services,
output: Self::Output,
_request: &hyper::Request<B>,
_incoming_request: &hyper::Request<&[u8]>,
authentication: Self::Output,
query: AuthQueryParams,
route: TypeId,
) -> Result<Self::Identity> {
if output.is_empty() {
return Err!(Request(Unauthorized("Missing access token.")));
}
if let Some((sender_user, sender_device, status)) =
services.users.find_from_token(&output).await
{
// If the token is expired we return a soft logout
if matches!(status, AccessTokenStatus::Expired) {
return Err(Error::Request(
ErrorKind::UnknownToken(
assign!(UnknownTokenErrorData::new(), { soft_logout: true }),
),
"This token has expired".into(),
StatusCode::UNAUTHORIZED,
));
}
// Locked users can only use /logout and /logout/all
if services
.users
.is_locked(&sender_user)
.await
.is_ok_and(std::convert::identity)
{
if !(route == TypeId::of::<client::session::logout::v3::Request>()
|| route == TypeId::of::<client::session::logout_all::v3::Request>())
{
return Err!(Request(UserLocked("Your account is locked.")));
}
}
Ok(ClientIdentity::User { sender_user, sender_device })
} else if let Ok(appservice_info) = services.appservice.find_from_token(&output).await {
let Ok(sender_user) = query.user_id.clone().map_or_else(
|| {
UserId::parse_with_server_name(
appservice_info.registration.sender_localpart.as_str(),
services.globals.server_name(),
)
},
UserId::parse,
) else {
return Err!(Request(InvalidUsername("Username is invalid.")));
};
if !appservice_info.is_user_match(&sender_user) {
return Err!(Request(Exclusive("User is not in namespace.")));
}
// MSC3202/MSC4190: Handle device_id masquerading for appservices.
// The device_id can be provided via `device_id` or
// `org.matrix.msc3202.device_id` query parameter.
let sender_device = if let Some(device_id) = query
.device_id
.or(query.legacy_device_id)
.as_deref()
.map(Into::into)
{
// Verify the device exists for this user
if services
.users
.get_device_metadata(&sender_user, device_id)
.await
.is_err()
{
return Err!(Request(Forbidden(
"Device does not exist for user or appservice cannot masquerade as this \
device."
)));
}
Some(device_id.to_owned())
} else {
None
};
Ok(ClientIdentity::Appservice {
sender_user,
sender_device,
appservice_info: Box::new(appservice_info),
})
} else {
Err(Error::Request(
ErrorKind::UnknownToken(UnknownTokenErrorData::new()),
"Invalid token".into(),
StatusCode::UNAUTHORIZED,
))
}
check_access_token(
services,
&authentication,
query,
TypeId::of::<R>(),
R::required_client_scopes(),
)
.await
}
}
impl CheckAuth for AccessTokenOptional {
type Identity = Option<ClientIdentity>;
async fn verify<B: AsRef<[u8]> + Sync>(
async fn check<R: IncomingRequest<Authentication = Self> + Any>(
services: &Services,
output: Self::Output,
request: &hyper::Request<B>,
_incoming_request: &hyper::Request<&[u8]>,
authentication: Self::Output,
query: AuthQueryParams,
route: TypeId,
) -> Result<Self::Identity> {
match output {
| Some(token) =>
<AccessToken as CheckAuth>::verify(services, token, request, query, route)
.await
.map(Some),
| None => Ok(None),
if let Some(authentication) = authentication {
check_access_token(
services,
&authentication,
query,
TypeId::of::<R>(),
R::required_client_scopes(),
)
.await
.map(Some)
} else {
Ok(None)
}
}
}
@@ -301,40 +203,31 @@ impl CheckAuth for AccessTokenOptional {
impl CheckAuth for AppserviceToken {
type Identity = RegistrationInfo;
async fn verify<B: AsRef<[u8]> + Sync>(
async fn check<R: IncomingRequest + Any>(
services: &Services,
output: Self::Output,
_request: &hyper::Request<B>,
_incoming_request: &hyper::Request<&[u8]>,
authentication: Self::Output,
_query: AuthQueryParams,
_route: TypeId,
) -> Result<Self::Identity> {
if output.is_empty() {
return Err!(Request(Unauthorized("Missing access token.")));
}
let Ok(appservice_info) = services.appservice.find_from_token(&output).await else {
return Err!(Request(Unauthorized("Invalid appservice token.")));
};
Ok(appservice_info)
check_appservice_token(services, &authentication).await
}
}
impl CheckAuth for AppserviceTokenOptional {
type Identity = Option<RegistrationInfo>;
async fn verify<B: AsRef<[u8]> + Sync>(
async fn check<R: IncomingRequest<Authentication = Self> + Any>(
services: &Services,
output: Self::Output,
request: &hyper::Request<B>,
query: AuthQueryParams,
route: TypeId,
_incoming_request: &hyper::Request<&[u8]>,
authentication: Self::Output,
_query: AuthQueryParams,
) -> Result<Self::Identity> {
match output {
| Some(token) =>
<AppserviceToken as CheckAuth>::verify(services, token, request, query, route)
.await
.map(Some),
| None => Ok(None),
if let Some(authentication) = authentication {
check_appservice_token(services, &authentication)
.await
.map(Some)
} else {
Ok(None)
}
}
}
@@ -342,13 +235,12 @@ impl CheckAuth for AppserviceTokenOptional {
impl CheckAuth for NoAuthentication {
type Identity = ();
fn verify<B: AsRef<[u8]> + Sync>(
fn check<R: IncomingRequest<Authentication = Self> + Any>(
_services: &Services,
_output: Self::Output,
_request: &hyper::Request<B>,
_incoming_request: &hyper::Request<&[u8]>,
_authentication: Self::Output,
_query: AuthQueryParams,
_route: TypeId,
) -> impl Future<Output = Result<Self::Identity>> {
) -> impl Future<Output = Result<Self::Identity>> + Send {
std::future::ready(Ok(()))
}
}
@@ -356,31 +248,166 @@ impl CheckAuth for NoAuthentication {
impl CheckAuth for NoAccessToken {
type Identity = Option<ClientIdentity>;
async fn verify<B: AsRef<[u8]> + Sync>(
async fn check<R: IncomingRequest<Authentication = Self> + Any>(
services: &Services,
_output: Self::Output,
request: &hyper::Request<B>,
incoming_request: &hyper::Request<&[u8]>,
_authentication: Self::Output,
query: AuthQueryParams,
route: TypeId,
) -> Result<Self::Identity> {
// We handle these the same as AccessTokenOptional
let token = AccessTokenOptional::extract_authentication(request).map_err(|err| {
err!(Request(Unauthorized(warn!("Failed to extract authorization: {}", err))))
})?;
let authentication = AccessTokenOptional::extract_authentication(incoming_request)
.map_err(|err| {
err!(Request(Unauthorized(warn!("Failed to extract authorization: {}", err))))
})?;
// Check special access restrictions
if (route == TypeId::of::<client::profile::get_avatar_url::v3::Request>()
|| route == TypeId::of::<client::profile::get_display_name::v3::Request>()
|| route == TypeId::of::<client::profile::get_profile_field::v3::Request>()
|| route == TypeId::of::<client::profile::get_profile::v3::Request>())
&& services.config.require_auth_for_profile_requests
&& token.is_none()
{
return Err!(Request(Unauthorized(
"This server requires authentication to access user profiles."
)));
if let Some(authentication) = authentication {
check_access_token(services, &authentication, query, TypeId::of::<R>(), &[
OAuthClientScope::ApiFullAccess,
])
.await
.map(Some)
} else {
Ok(None)
}
<AccessTokenOptional as CheckAuth>::verify(services, token, request, query, route).await
}
}
async fn check_access_token(
services: &Services,
token: &str,
query: AuthQueryParams,
route: TypeId,
required_scopes: &[OAuthClientScope],
) -> Result<ClientIdentity> {
if token.is_empty() {
return Err!(Request(Unauthorized("Empty access token.")));
}
if let Some((sender_user, sender_device, status)) =
services.users.find_from_token(token).await
{
// If the token is expired we return a soft logout
if matches!(status, AccessTokenStatus::Expired) {
return Err(Error::Request(
ErrorKind::UnknownToken(
assign!(UnknownTokenErrorData::new(), { soft_logout: true }),
),
"This token has expired".into(),
StatusCode::UNAUTHORIZED,
));
}
// Locked users can only use /logout and /logout/all
if services
.users
.is_locked(&sender_user)
.await
.is_ok_and(std::convert::identity)
{
if !(route == TypeId::of::<client::session::logout::v3::Request>()
|| route == TypeId::of::<client::session::logout_all::v3::Request>())
{
return Err!(Request(UserLocked("Your account is locked.")));
}
}
let session_info = services
.oauth
.get_session_info_for_device(&sender_user, &sender_device)
.await
.map(Box::new);
// Make sure the user has the right scopes to use the route
let user_scopes = if let Some(session_info) = &session_info {
session_info.scopes()
} else {
let mut scopes = BTreeSet::from_iter([OAuthClientScope::ApiFullAccess]);
if services.admin.user_is_admin(&sender_user).await {
scopes.insert(OAuthClientScope::ServerAdministration);
}
scopes
};
if !required_scopes
.iter()
.any(|scope| user_scopes.contains(scope))
{
return Err(Error::Request(
ErrorKind::InsufficientUserAuthentication(Box::new(
assign!(InsufficientUserAuthenticationErrorData::new(), {
scope: required_scopes.iter().cloned().collect()
}),
)),
"You do not have permission to access this endpoint.".into(),
StatusCode::UNAUTHORIZED,
));
}
Ok(ClientIdentity::User { sender_user, sender_device })
} else if let Ok(appservice_info) = services.appservice.find_from_token(token).await {
let Ok(sender_user) = query.user_id.clone().map_or_else(
|| {
UserId::parse_with_server_name(
appservice_info.registration.sender_localpart.as_str(),
services.globals.server_name(),
)
},
UserId::parse,
) else {
return Err!(Request(InvalidUsername("Username is invalid.")));
};
if !appservice_info.is_user_match(&sender_user) {
return Err!(Request(Exclusive("User is not in namespace.")));
}
// MSC3202/MSC4190: Handle device_id masquerading for appservices.
// The device_id can be provided via `device_id` or
// `org.matrix.msc3202.device_id` query parameter.
let sender_device = if let Some(device_id) = query
.device_id
.or(query.legacy_device_id)
.as_deref()
.map(Into::into)
{
// Verify the device exists for this user
if services
.users
.get_device_metadata(&sender_user, device_id)
.await
.is_err()
{
return Err!(Request(Forbidden(
"Device does not exist for user or appservice cannot masquerade as this \
device."
)));
}
Some(device_id.to_owned())
} else {
None
};
Ok(ClientIdentity::Appservice {
sender_user,
sender_device,
appservice_info: Box::new(appservice_info),
})
} else {
Err(Error::Request(
ErrorKind::UnknownToken(UnknownTokenErrorData::new()),
"Invalid token".into(),
StatusCode::UNAUTHORIZED,
))
}
}
async fn check_appservice_token(services: &Services, token: &str) -> Result<RegistrationInfo> {
let Ok(appservice_info) = services.appservice.find_from_token(token).await else {
return Err!(Request(Unauthorized("Invalid appservice token.")));
};
Ok(appservice_info)
}
+18 -2
View File
@@ -5,6 +5,7 @@ use base64::{Engine as _, engine::general_purpose};
use conduwuit::{
Err, Error, EventTypeExt, PduEvent, Result, debug, err, error,
matrix::{Event, StateKey},
metrics::KeyValue,
result::FlatOk,
state_res, trace,
utils::hash::sha256,
@@ -31,6 +32,21 @@ use crate::{Ruma, server::utils::validate_any_membership_event};
pub(crate) async fn create_invite_route(
State(services): State<crate::State>,
body: Ruma<create_invite::v2::Request>,
) -> Result<create_invite::v2::Response> {
let result = create_invite(&services, body).await;
services.server.metrics.instruments.invites.add(1, &[
KeyValue::new("direction", "incoming"),
KeyValue::new("destination", "local"),
KeyValue::new("outcome", if result.is_ok() { "success" } else { "failure" }),
]);
result
}
async fn create_invite(
services: &crate::State,
body: Ruma<create_invite::v2::Request>,
) -> Result<create_invite::v2::Response> {
if !services.server.supported_room_version(&body.room_version) {
return Err(Error::BadRequest(
@@ -64,7 +80,7 @@ pub(crate) async fn create_invite_route(
"Validating invite room state for invite request"
);
let (create_event_id, state) = validate_invite_state(
&services,
services,
&body.invite_room_state,
&room_version_rules,
body.room_id.clone(),
@@ -92,7 +108,7 @@ pub(crate) async fn create_invite_route(
// And then we can validate the member event itself
let (mut signed_event, sender_user, recipient_user) = validate_invite_membership_event(
&services,
services,
&body.event,
&room_version_rules,
&body.identity,
+360 -69
View File
@@ -1,89 +1,380 @@
use std::{collections::BTreeMap, mem::take, time::Duration};
use axum::{Json, extract::State, response::IntoResponse};
use conduwuit::{Result, utils::timepoint_from_now};
use futures::StreamExt;
use ruma::{
MilliSecondsSinceUnixEpoch,
api::{
OutgoingResponseExt,
federation::discovery::{OldVerifyKey, ServerSigningKeys, get_server_keys},
},
assign,
serde::Raw,
use std::{
collections::{BTreeMap, HashMap, HashSet},
ops::Index,
sync::Arc,
time::Instant,
};
use axum::extract::State;
use conduwuit::{
Err, Result, debug, debug_info, error,
utils::{
ReadyExt,
stream::{BroadbandExt, automatic_width},
to_canonical_object,
},
};
use futures::{StreamExt, stream::FuturesUnordered};
use ruma::{
MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedServerSigningKeyId, ServerName,
api::federation::discovery::{
ServerSigningKeys, get_remote_server_keys, get_remote_server_keys_batch,
get_remote_server_keys_batch::v2::QueryCriteria, get_server_keys,
},
serde::Raw,
uint,
};
use serde_json::value::to_raw_value;
use service::{server_keys, server_keys::in_one_week};
use crate::router::Ruma;
/// # `GET /_matrix/key/v2/server`
///
/// Gets the public signing keys of this server.
pub(crate) async fn get_server_keys_route(
State(services): State<crate::State>,
) -> Result<impl IntoResponse> {
let server_name = services.globals.server_name();
let verify_keys = BTreeMap::from([services.server_keys.active_verify_key()]);
_body: Ruma<get_server_keys::v2::Request>,
) -> Result<get_server_keys::v2::Response> {
services
.server_keys
.build_server_keys_response()
.await
.map(get_server_keys::v2::Response::new)
}
let old_verify_keys = if let Some(k) = &services.config.old_verify_keys {
k.to_owned()
const MAX_KEYS_PER_QUERY: usize = 16384;
const MAX_SERVERS_PER_QUERY: usize = 4096;
/// # `POST /_matrix/key/v2/query`
///
/// Fetches remote server signing keys in bulk, seeding from the local server's
/// database.
///
/// This route applies a semaphore to slow down requests that query more signing
/// keys than is allowed by [MSC4556].
///
/// [MSC4556]: https://github.com/matrix-org/matrix-spec-proposals/pull/4556
pub(crate) async fn get_remote_server_keys_batch_route(
State(services): State<crate::State>,
body: Ruma<get_remote_server_keys_batch::v2::Request>,
) -> Result<get_remote_server_keys_batch::v2::Response> {
query_inner(&services, &body.server_keys, false)
.await
.map(get_remote_server_keys_batch::v2::Response::new)
}
/// # `POST /_matrix/key/unstable/org.continuwuity.msc4556/query`
/// ## `POST /_matrix/key/v3/query`
///
/// Fetches remote server signing keys in bulk, seeding from the local server's
/// database.
///
/// MSC4556: https://github.com/matrix-org/matrix-spec-proposals/pull/4556
pub(crate) async fn get_remote_server_keys_batch_v3_unstable_route(
State(services): State<crate::State>,
body: Ruma<ruminuwuity::federation::notary::unstable::Request>,
) -> Result<ruminuwuity::federation::notary::unstable::Response> {
query_inner(&services, &body.server_keys, false)
.await
.map(ruminuwuity::federation::notary::unstable::Response::new)
}
/// Handles querying the server keys for `/_matrix/key/*/query`.
///
/// `v2` should be `true` if the request path is `/_matrix/key/v2/query` - this
/// will potentially apply a rate-limit to the request.
async fn query_inner(
services: &crate::State,
body: &BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, QueryCriteria>>,
v2: bool,
) -> Result<Vec<Raw<ServerSigningKeys>>> {
let start = (Instant::now(), MilliSecondsSinceUnixEpoch::now());
// If the remote server isn't asking for any keys, we can return an empty
// array immediately.
if body.is_empty() {
return Ok(Vec::new());
}
// Count how many keys are being requested.
// Each server incurs a cost of at least one, and then the count of each key
// being queried per-server.
let total_queried_servers = body.len();
let total_queried_keys = body
.values()
.fold(body.len(), |acc, q| acc.saturating_add(q.len()));
if !v2 {
// If we're on the v3 endpoint, we can apply these limits explicitly.
if total_queried_servers > MAX_SERVERS_PER_QUERY {
return Err!(Request(TooLarge(
"Too many server keys requested ({total_queried_servers} > \
{MAX_SERVERS_PER_QUERY}",
)));
}
if total_queried_keys > MAX_KEYS_PER_QUERY {
return Err!(Request(TooLarge(
"Too many keys requested ({total_queried_keys} > {MAX_KEYS_PER_QUERY})"
)));
}
}
let penalise =
total_queried_servers > MAX_SERVERS_PER_QUERY || total_queried_keys > MAX_KEYS_PER_QUERY;
debug_info!("Fetching {total_queried_keys} keys across {} servers", body.len());
let mut futs: FuturesUnordered<_> = FuturesUnordered::new();
// If we're on the v2 endpoint, we aren't allowed to reject the request.
// To avoid overloading the server, we'll apply a semaphore to limit how
// many futures can be active at a time.
let width = automatic_width();
let sem = if v2 && penalise {
Some(Arc::new(tokio::sync::Semaphore::new(width)))
} else {
// We need to figure out any old signing keys we've acquired from
// notaries.
let mut keys = services.server_keys.signing_keys_for(server_name);
let mut old_keys = BTreeMap::new();
while let Some(resp) = keys.next().await {
// We need to verify that this response is still trusted based on
// the current configuration. It's possible we got this response
// from a notary who we no longer trust.
if resp.valid_until_ts > in_one_week() {
continue;
}
let trusted = services.config.trusted_servers.iter().any(|notary| {
server_keys::Service::verify_server_keys_response(
&resp,
Some((notary.server_name(), notary.verify_keys())),
)
.is_ok()
});
if !trusted {
continue;
}
for (old_key_id, old_key) in resp.old_verify_keys {
if old_key.expired_ts > resp.valid_until_ts {
// This key expired in the future which is probably illegal
continue;
None
};
for (server_name, queries) in body.clone() {
futs.push(acquire_keys_as_notary(
services.server_keys.clone(),
services.globals.server_name().to_owned(),
server_name,
queries,
start.1,
sem.clone(),
));
}
let mut response = Vec::with_capacity(total_queried_keys);
while let Some(v) = futs.next().await {
response.extend(v);
}
debug_info!(
elapsed=?start.0.elapsed(),
%total_queried_servers,
%total_queried_keys,
"Fetched {} key responses",
response.len()
);
Ok(response)
}
async fn sign_ssk(
server_keys: &server_keys::Service,
ssk: ServerSigningKeys,
server_name: &ServerName,
our_name: &ServerName,
) -> Result<Raw<ServerSigningKeys>> {
if server_name == our_name {
// Should already be signed by us if we got this far.
debug_info!(
object=?ssk,
%server_name,
%our_name,
"Refusing to sign our own signing keys response (should already be signed)"
);
return to_raw_value(&ssk)
.map(Raw::<ServerSigningKeys>::from_json)
.map_err(Into::into);
}
let mut canonical = to_canonical_object(&ssk)?;
server_keys.sign_json(&mut canonical)?;
server_keys::strip_extraneous_signatures(&mut canonical, server_name, &[our_name]);
to_raw_value(&canonical)
.map(Raw::<ServerSigningKeys>::from_json)
.map_err(Into::into)
}
#[tracing::instrument(skip(server_keys, my_name, queries, start, semaphore))]
async fn acquire_keys_as_notary(
server_keys: Arc<server_keys::Service>,
my_name: OwnedServerName,
remote: OwnedServerName,
mut queries: BTreeMap<OwnedServerSigningKeyId, QueryCriteria>,
start: MilliSecondsSinceUnixEpoch,
semaphore: Option<Arc<tokio::sync::Semaphore>>,
) -> Vec<Raw<ServerSigningKeys>> {
let cost = queries
.len()
.saturating_add(1)
.min(automatic_width())
.try_into()
.unwrap_or(u32::MAX);
let _permit = if let Some(sem) = semaphore {
sem.acquire_many_owned(cost).await.ok()
} else {
None
};
let fetch_all = queries.is_empty();
let mut results = Vec::with_capacity(queries.len().max(1));
let mut keymap = HashMap::with_capacity(queries.len().max(1));
// First contact the origin (if we're allowed to)
if server_keys.notary_may_contact_origin(&remote) {
debug_info!("Asking remote directly for verify keys");
if let Ok(res) = server_keys.origin_request(remote.clone(), start).await
&& let Ok(ssk) = sign_ssk(&server_keys, res.clone(), &remote, &my_name).await
{
let index = results.len();
results.push(ssk);
for key_id in res.verify_keys.keys().chain(res.old_verify_keys.keys()) {
if fetch_all
|| queries.get(key_id).is_some_and(|c| {
c.minimum_valid_until_ts
.is_none_or(|m| res.valid_until_ts >= m)
}) {
queries.remove(key_id);
keymap.insert(key_id.to_owned(), index);
}
old_keys
.entry(old_key_id)
.and_modify(|current_old_key: &mut OldVerifyKey| {
// Use the lowest expiry timestamp
if current_old_key.expired_ts > old_key.expired_ts {
*current_old_key = old_key.clone();
}
})
.or_insert(old_key);
}
}
old_keys
};
} else {
debug!("Not asking remote for keys (already asked recently)");
}
debug!(keys=?keymap.keys(), "Live verify keys");
if fetch_all && keymap.is_empty() {
// If the server asked for all keys, AND we didn't get anything from the
// origin, just fetch any fresh responses we have.
server_keys
.signing_keys_for(&remote)
.broad_filter_map(|ssk| {
let server_name = &remote;
let my_name = &my_name;
let server_keys = &server_keys;
async move {
if ssk.valid_until_ts > in_one_week() || ssk.valid_until_ts < start {
return None;
}
let server_key = assign!(ServerSigningKeys::new(server_name.to_owned(), valid_until_ts()), {
verify_keys,
old_verify_keys,
});
sign_ssk(server_keys, ssk.clone(), server_name, my_name)
.await
.map(|signed_ssk| (ssk, signed_ssk))
.ok()
}
})
.ready_for_each(|(ssk, signed_ssk)| {
let idx = results.len();
results.push(signed_ssk);
for key_id in ssk.verify_keys.keys().chain(ssk.old_verify_keys.keys()) {
keymap.insert(key_id.to_owned(), idx);
}
})
.await;
}
let server_key = Raw::new(&server_key)?;
let mut response = get_server_keys::v2::Response::new(server_key)
.try_into_http_response::<Vec<u8>>()
.map(|mut response| take(response.body_mut()))
.and_then(|body| serde_json::from_slice(&body).map_err(Into::into))?;
// If we're still missing some keys, fetch them from the local cache
for (key_id, criteria) in queries {
debug!(%key_id, "Fetching verify key from local repository");
services.server_keys.sign_json(&mut response)?;
if keymap.contains_key(&key_id) {
debug!(%key_id, "Already found key");
continue;
}
Ok(Json(response))
let minimum_valid_until_ts = criteria
.clone()
.minimum_valid_until_ts
.unwrap_or_else(|| MilliSecondsSinceUnixEpoch(uint!(0)));
let Some(ssk) = server_keys.get_signing_key(&remote, &key_id).await else {
debug!(%remote, %key_id, "Could not find a matching signing key locally.");
continue;
};
if ssk.valid_until_ts < minimum_valid_until_ts || ssk.valid_until_ts > in_one_week() {
debug!(
%key_id,
valid_until_ts=?ssk.valid_until_ts,
?minimum_valid_until_ts,
"Stored verify key does not satisfy query criteria"
);
continue;
}
if let Some(old_verify_key) = ssk.old_verify_keys.get(&key_id) {
if old_verify_key.expired_ts < minimum_valid_until_ts {
debug!(
%key_id,
expired_ts=?old_verify_key.expired_ts,
?minimum_valid_until_ts,
"Stored old verify key does not satisfy query criteria"
);
continue;
}
}
debug!(%key_id, ?ssk, "Found key locally");
let rep_key_ids = ssk.verify_keys.keys().cloned().collect::<Vec<_>>();
let Ok(signed_ssk) = sign_ssk(&server_keys, ssk.clone(), &remote, &my_name)
.await
.inspect_err(
|e| error!(%key_id, %remote, "Failed to sign signing keys chunk: {e:?}"),
)
else {
continue;
};
let idx = results.len();
results.push(signed_ssk);
keymap.insert(key_id, idx);
for key_id in rep_key_ids {
keymap.insert(key_id, idx);
}
}
keymap
.into_values()
.collect::<HashSet<_>>()
.into_iter()
.map(|idx| results.index(idx).to_owned())
.collect()
}
fn valid_until_ts() -> MilliSecondsSinceUnixEpoch {
let dur = Duration::from_hours(12);
let timepoint = timepoint_from_now(dur).expect("SystemTime should not overflow");
MilliSecondsSinceUnixEpoch::from_system_time(timepoint).expect("UInt should not overflow")
/// `GET /_matrix/key/v2/query/{serverName}`
///
/// Fetches the latest keys for a specific server name.
pub(crate) async fn get_remote_server_keys_route(
State(services): State<crate::State>,
body: Ruma<get_remote_server_keys::v2::Request>,
) -> Result<get_remote_server_keys::v2::Response> {
let min_valid_ts = body.minimum_valid_until_ts;
if services
.server_keys
.notary_may_contact_origin(&body.server_name)
&& let Ok(response) = services
.server_keys
.origin_request(body.server_name.clone(), min_valid_ts)
.await
{
return sign_ssk(
&services.server_keys,
response,
&body.server_name,
services.globals.server_name(),
)
.await
.map(|r| Ok(get_remote_server_keys::v2::Response::new(vec![r])))?;
}
let response = services
.server_keys
.signing_keys_for(&body.server_name)
.broad_filter_map(|ssk| {
let server_name = body.server_name.clone();
async move {
if ssk.valid_until_ts > in_one_week() || ssk.valid_until_ts < min_valid_ts {
return None;
}
sign_ssk(
&services.server_keys,
ssk,
server_name.as_ref(),
services.globals.server_name(),
)
.await
.ok()
}
})
.collect::<Vec<_>>()
.await;
Ok(get_remote_server_keys::v2::Response::new(response))
}
+96 -3
View File
@@ -6,6 +6,7 @@ use std::{
use axum::extract::State;
use conduwuit::{
Err, Error, Result, debug, debug_error, debug_warn, err, error,
metrics::KeyValue,
result::LogErr,
trace,
utils::{
@@ -22,7 +23,8 @@ use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
use http::StatusCode;
use itertools::Itertools;
use ruma::{
CanonicalJsonObject, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, ServerName, UserId,
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId,
ServerName, UserId,
api::{
error::{ErrorKind, LimitExceededErrorData},
federation::transactions::{
@@ -34,7 +36,10 @@ use ruma::{
send_transaction_message,
},
},
events::receipt::{ReceiptEvent, ReceiptEventContent, ReceiptType},
events::{
TimelineEventType,
receipt::{ReceiptEvent, ReceiptEventContent, ReceiptType},
},
serde::Raw,
to_device::DeviceIdOrAllDevices,
};
@@ -151,6 +156,15 @@ async fn process_inbound_transaction(
{
| Ok(pdu) => Some(pdu),
| Err(error) => {
services
.server
.metrics
.instruments
.federation_incoming_pdus
.add(1, &[
KeyValue::new("type", pdu_type_label(raw_pdu_type(pdu).as_deref())),
KeyValue::new("outcome", "unparsable"),
]);
let queued = services
.rooms
.event_handler
@@ -181,6 +195,17 @@ async fn process_inbound_transaction(
.catch_unwind()
.map_err(Error::from_panic)
.await;
let outcome = if matches!(handle_result, Ok(Ok(_))) {
"success"
} else {
"failure"
};
services
.server
.metrics
.instruments
.federation_incoming_transaction_duration
.record(txn_start_time.elapsed().as_secs_f64(), &[KeyValue::new("outcome", outcome)]);
let results = match handle_result {
| Ok(Ok(results)) => results,
| Ok(Err(err)) => {
@@ -337,6 +362,16 @@ async fn handle_room(
.server
.check_running()
.map_err(|_| TransactionError::ShuttingDown)?;
let event_type = KeyValue::new(
"type",
pdu_type_label(value.get("type").and_then(CanonicalJsonValue::as_str)),
);
let origin_server_ts = value
.get("origin_server_ts")
.and_then(CanonicalJsonValue::as_integer)
.and_then(|ts| u64::try_from(i64::from(ts)).ok());
let start = Instant::now();
let result = services
.rooms
.event_handler
@@ -344,12 +379,44 @@ async fn handle_room(
.boxed()
.await
.map(|_| ());
let outcome = KeyValue::new("outcome", match &result {
| Ok(()) => "accepted",
| Err(Error::BadRequest(ErrorKind::Forbidden, ..)) => "forbidden",
| Err(Error::BadRequest(ErrorKind::InvalidParam | ErrorKind::BadJson, ..)) =>
"invalid",
| Err(_) => "error",
});
let instruments = &services.server.metrics.instruments;
instruments
.federation_incoming_pdu_duration
.record(start.elapsed().as_secs_f64(), std::slice::from_ref(&outcome));
if let (Ok(()), Some(ts)) = (&result, origin_server_ts) {
let lag = millis_since_unix_epoch().saturating_sub(ts);
instruments
.federation_incoming_pdu_lag
.record(Duration::from_millis(lag).as_secs_f64(), &[]);
}
instruments
.federation_incoming_pdus
.add(1, &[event_type, outcome]);
results.push((event_id, result));
}
Ok(results)
}
async fn handle_edu(services: &Services, origin: &ServerName, edu: Edu) {
let edu_type = match &edu {
| Edu::Presence(_) => "m.presence",
| Edu::Receipt(_) => "m.receipt",
| Edu::Typing(_) => "m.typing",
| Edu::DeviceListUpdate(_) => "m.device_list_update",
| Edu::DirectToDevice(_) => "m.direct_to_device",
| Edu::SigningKeyUpdate(_) => "m.signing_key_update",
| _ => "other",
};
let start = Instant::now();
match edu {
| Edu::Presence(presence) if services.server.config.allow_incoming_presence =>
handle_edu_presence(services, origin, presence).await,
@@ -373,6 +440,32 @@ async fn handle_edu(services: &Services, origin: &ServerName, edu: Edu) {
| _ => trace!(?edu, "skipped"),
}
let edu_type = [KeyValue::new("type", edu_type)];
let instruments = &services.server.metrics.instruments;
instruments
.federation_incoming_edu_duration
.record(start.elapsed().as_secs_f64(), &edu_type);
instruments.federation_incoming_edus.add(1, &edu_type);
}
/// Known event types, or `other`, so remote servers cannot create new
/// attribute values.
fn pdu_type_label(event_type: Option<&str>) -> String {
match event_type.map(TimelineEventType::from) {
| Some(TimelineEventType::_Custom(_)) | None => "other".to_owned(),
| Some(event_type) => event_type.to_string(),
}
}
fn raw_pdu_type(pdu: &serde_json::value::RawValue) -> Option<String> {
#[derive(serde::Deserialize)]
struct Typed {
#[serde(rename = "type")]
kind: Option<String>,
}
serde_json::from_str::<Typed>(pdu.get()).ok()?.kind
}
async fn handle_edu_presence(
@@ -502,7 +595,7 @@ async fn handle_edu_receipt_room_user(
.readreceipt_update(
user_id,
room_id,
&ReceiptEvent::new(
ReceiptEvent::new(
room_id.to_owned(),
ReceiptEventContent::from_iter(content),
),
+26 -4
View File
@@ -163,7 +163,14 @@ async fn create_join_event(
}
Some(event_id)
})
.broad_and_then(|event_id| services.rooms.timeline.get_pdu_json(event_id))
.broad_and_then(|event_id| async move {
services
.rooms
.timeline
.get_pdu_json(event_id)
.await
.map_err(|e| err!(Database("Could not fetch state event {event_id}: {e:?}")))
})
.broad_and_then(|pdu| {
services
.sending
@@ -172,7 +179,12 @@ async fn create_join_event(
})
.try_collect()
.boxed()
.await?;
.await
.map_err(|e| {
err!(BadServerResponse(
error!(err=?e, "Failed to build room state at new join event")
))
})?;
let starting_events = state_ids.iter().map(Borrow::borrow);
trace!("Constructing auth chain");
@@ -181,7 +193,12 @@ async fn create_join_event(
.auth_chain
.event_ids_iter(room_id, starting_events)
.broad_and_then(|event_id| async move {
services.rooms.timeline.get_pdu_json(&event_id).await
services
.rooms
.timeline
.get_pdu_json(&event_id)
.await
.map_err(|e| err!(Database("Could not fetch state event {event_id}: {e:?}")))
})
.broad_and_then(|pdu| {
services
@@ -191,7 +208,12 @@ async fn create_join_event(
})
.try_collect()
.boxed()
.await?;
.await
.map_err(|e| {
err!(BadServerResponse(
error!(err=?e, "Failed to build auth chain for new join event")
))
})?;
info!(fast_join = %omit_members, "Sending join event to other servers");
services.sending.send_pdu_room(room_id, &pdu_id).await?;
debug!("Finished sending join event");
+5
View File
@@ -113,6 +113,9 @@ tracing-subscriber.workspace = true
tracing.workspace = true
url.workspace = true
parking_lot.workspace = true
opentelemetry.workspace = true
opentelemetry-semantic-conventions.workspace = true
prometheus.workspace = true
lock_api.workspace = true
hyper-util.workspace = true
resolvematrix.workspace = true
@@ -127,6 +130,8 @@ hardened_malloc-rs.optional = true
[dev-dependencies]
maplit.workspace = true
opentelemetry_sdk.workspace = true
opentelemetry-prometheus.workspace = true
[lints]
workspace = true
+3
View File
@@ -10,3 +10,6 @@ pub fn memory_stats(_opts: &str) -> Option<String> { None }
/// Always returns None
#[must_use]
pub fn memory_usage() -> Option<String> { None }
#[must_use]
pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> { None }
+3
View File
@@ -9,6 +9,9 @@ pub fn trim<I: Into<Option<usize>>>(_: I) -> crate::Result { Ok(()) }
//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())
+25 -13
View File
@@ -56,25 +56,15 @@ fn _static_initialization() {
#[must_use]
#[cfg(feature = "jemalloc_stats")]
pub fn memory_usage() -> Option<String> {
use mallctl::stats;
let mibs = |input: Result<usize, mallctl::Error>| {
let input = input.unwrap_or_default();
let mibs = |input: usize| {
let kibs = input / 1024;
let kibs = u32::try_from(kibs).unwrap_or_default();
let kibs = f64::from(kibs);
kibs / 1024.0
};
// Acquire the epoch; ensure latest stats are pulled in
acq_epoch().ok()?;
let allocated = mibs(stats::allocated::read());
let active = mibs(stats::active::read());
let mapped = mibs(stats::mapped::read());
let metadata = mibs(stats::metadata::read());
let resident = mibs(stats::resident::read());
let retained = mibs(stats::retained::read());
let [allocated, active, mapped, metadata, resident, retained] =
memory_usage_stats()?.map(|(_, bytes)| mibs(bytes));
Some(format!(
"allocated: {allocated:.2} MiB\nactive: {active:.2} MiB\nmapped: {mapped:.2} \
MiB\nmetadata: {metadata:.2} MiB\nresident: {resident:.2} MiB\nretained: {retained:.2} \
@@ -86,6 +76,28 @@ pub fn memory_usage() -> Option<String> {
#[cfg(not(feature = "jemalloc_stats"))]
pub fn memory_usage() -> Option<String> { None }
#[must_use]
#[cfg(feature = "jemalloc_stats")]
pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> {
use mallctl::stats;
// Acquire the epoch; ensure latest stats are pulled in
acq_epoch().ok()?;
Some([
("allocated", stats::allocated::read().unwrap_or_default()),
("active", stats::active::read().unwrap_or_default()),
("mapped", stats::mapped::read().unwrap_or_default()),
("metadata", stats::metadata::read().unwrap_or_default()),
("resident", stats::resident::read().unwrap_or_default()),
("retained", stats::retained::read().unwrap_or_default()),
])
}
#[must_use]
#[cfg(not(feature = "jemalloc_stats"))]
pub fn memory_usage_stats() -> Option<[(&'static str, usize); 6]> { None }
pub fn memory_stats(opts: &str) -> Option<String> {
const MAX_LENGTH: usize = 1_048_576;
+3 -3
View File
@@ -4,7 +4,7 @@
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
pub mod je;
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
pub use je::{memory_stats, memory_usage, trim};
pub use je::{memory_stats, memory_usage, memory_usage_stats, trim};
#[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", not(feature = "jemalloc")))]
pub mod hardened;
@@ -13,7 +13,7 @@ pub mod hardened;
feature = "hardened_malloc",
not(feature = "jemalloc")
))]
pub use hardened::{memory_stats, memory_usage, trim};
pub use hardened::{memory_stats, memory_usage, memory_usage_stats, trim};
#[cfg(any(
target_env = "msvc",
@@ -24,4 +24,4 @@ pub mod default;
target_env = "msvc",
all(not(feature = "hardened_malloc"), not(feature = "jemalloc"))
))]
pub use default::{memory_stats, memory_usage, trim};
pub use default::{memory_stats, memory_usage, memory_usage_stats, trim};
+8
View File
@@ -194,6 +194,14 @@ pub fn check(config: &Config) -> Result {
);
}
if config.allow_prometheus_metrics && config.prometheus_metrics_token.is_none() {
warn!(
"The Prometheus metrics endpoint is enabled without `prometheus_metrics_token`. \
Anyone who can reach /_continuwuity/metrics can read server metrics unless access \
is restricted at your reverse proxy."
);
}
if config.allow_outgoing_presence && !config.allow_local_presence {
return Err!(Config(
"allow_local_presence",
+55 -28
View File
@@ -7,6 +7,7 @@ use std::{
collections::{BTreeMap, BTreeSet, HashMap},
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
path::PathBuf,
time::Duration,
};
use conduwuit_macros::config_example_generator;
@@ -383,6 +384,15 @@ pub struct Config {
#[serde(default = "default_stateinfo_cache_capacity")]
pub stateinfo_cache_capacity: u32,
/// DNS servers to use instead of system defaults. Does NOT accept IP:Port
/// pairs, only plain IPs. IPv6 addresses should be without brackets.
///
/// Uses system configuration (/etc/resolv.conf) if empty.
///
/// default: []
#[serde(default)]
pub dns_servers: Vec<String>,
/// Maximum entries stored in DNS memory-cache. The size of an entry may
/// vary so please take care if raising this value excessively. Only
/// decrease this when using an external DNS cache. Please note that
@@ -1008,7 +1018,7 @@ pub struct Config {
/// Jaeger) that supports the OpenTelemetry Protocol.
///
/// Configure your OTLP endpoint using the OTEL_EXPORTER_OTLP_ENDPOINT
/// environment variable (defaults to http://localhost:4318).
/// environment variable, or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT (defaults to http://localhost:4318), and OTEL_EXPORTER_OTLP_PROTOCOL for the protocol.
#[serde(default, alias = "allow_jaeger")]
pub allow_otlp: bool,
@@ -1019,12 +1029,30 @@ pub struct Config {
#[serde(default = "default_otlp_filter", alias = "jaeger_filter")]
pub otlp_filter: String,
/// Protocol to use for OTLP tracing export. Options are "http" or "grpc".
/// The HTTP protocol uses port 4318 by default, while gRPC uses port 4317.
/// Enable OpenTelemetry OTLP metrics export. Configure your OTLP endpoint
/// and protocol using standard OpenTelemetry environment variables
/// (such as OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL and
/// OTEL_EXPORTER_OTLP_METRICS_PROTOCOL).
///
/// default: "http"
#[serde(default = "default_otlp_protocol")]
pub otlp_protocol: String,
/// The export interval can be changed with the
/// OTEL_METRIC_EXPORT_INTERVAL environment variable (milliseconds,
/// defaults to 60000).
#[serde(default)]
pub allow_otlp_metrics: bool,
/// Enable the Prometheus metrics endpoint at `/_continuwuity/metrics`.
///
/// The endpoint is served on the same listener as the rest of the server.
/// Set `prometheus_metrics_token` or restrict access at your reverse proxy
/// to avoid exposing it publicly.
#[serde(default)]
pub allow_prometheus_metrics: bool,
/// Bearer token required to scrape the Prometheus metrics endpoint. When
/// set, requests must include an `Authorization: Bearer <token>` header.
///
/// display: sensitive
pub prometheus_metrics_token: Option<String>,
/// If the 'perf_measurements' compile-time feature is enabled, enables
/// collecting folded stack trace profile of tracing spans using
@@ -1092,10 +1120,7 @@ pub struct Config {
/// (trusted key notary servers), as well as serve as trusted servers for
/// other operations like backfill and event fetching.
///
/// Currently, continuwuity doesn't support inbound key requests, so
/// this list should only contain other Synapse servers.
///
/// example: ["matrix.org", "starstruck.systems"]
/// example: ["continuwuity.org", "matrix.org"]
///
/// It is possible to restrict which signing keys trusted servers are
/// allowed to sign responses with. Without configuring this, all responses
@@ -1132,7 +1157,7 @@ pub struct Config {
/// empty list (`[]`) to operate without trusted server assistance, but this
/// is discouraged for performance and reliability reasons.
///
/// default: ["matrix.org"]
/// default: ["continuwuity.org", "continuwuity.rocks", "matrix.org"]
#[serde(default = "default_trusted_servers")]
pub trusted_servers: Vec<TrustedServer>,
@@ -1626,15 +1651,9 @@ pub struct Config {
/// display: sensitive
pub emergency_password: Option<String>,
/// Specifies the path where push notifications will be sent to a
/// push gateway.
///
/// When a Matrix client registers for push notifications, it will specify
/// a push gateway url where notification events will be sent.
/// According to the current spec for Matrix Push Gateways, the path should
/// always be "/_matrix/push/v1/notify".
/// You should only change this if you have configured your own push gateway
/// that requires a different path.
/// Suffix stripped from the end of a pusher URL before appending
/// "/_matrix/push/v1/notify". Only change this if your pushers register
/// URLs ending in a different path.
///
/// For more information on Push Gateways: https://spec.matrix.org/latest/push-gateway-api/
///
@@ -2942,6 +2961,7 @@ const DEPRECATED_KEYS: &[&str] = &[
"cache_capacity",
"conduit_cache_capacity_modifier",
"max_concurrent_requests",
"otlp_protocol",
"roomid_spacehierarchy_cache_capacity",
"well_known_client",
"well_known_server",
@@ -2953,6 +2973,16 @@ const DEPRECATED_KEYS: &[&str] = &[
];
impl Config {
/// Returns the capped linear retry delay for a federation send attempt.
#[must_use]
pub fn sender_retry_backoff(&self, attempt: u32) -> Duration {
crate::utils::linear_backoff(
Duration::from_secs(self.sender_retry_backoff_base),
Duration::from_secs(self.sender_retry_backoff_limit),
attempt,
)
}
/// Get the base domain to use for user-facing URLs.
#[must_use]
pub fn get_client_domain(&self) -> Url {
@@ -3188,17 +3218,14 @@ fn default_otlp_filter() -> String {
.to_owned()
}
fn default_otlp_protocol() -> String { "http".to_owned() }
fn default_tracing_flame_output_path() -> String { "./tracing.folded".to_owned() }
fn default_trusted_servers() -> Vec<TrustedServer> {
// TODO(nex): Once we can be a notary, add maintainer(?) homeservers here.
// Rationale: Users are already running our code, arguably that's a higher
// level of trust than is assigned to notaries in the first place.
// We should still remind everyone that notaries are evil and out to get you
// and to replace this list with servers they actually trust.
let trusted_servers = vec![ruma::owned_server_name!("matrix.org")];
let trusted_servers = vec![
ruma::owned_server_name!("continuwuity.org"),
ruma::owned_server_name!("continuwuity.rocks"),
ruma::owned_server_name!("matrix.org"),
];
trusted_servers
.into_iter()
.map(TrustedServer::Name)
+9
View File
@@ -50,6 +50,15 @@ impl ProxyConfig {
})),
})
}
#[must_use]
pub fn url_for(&self, url: &Url) -> Option<&Url> {
match self {
| Self::None => None,
| Self::Global { url } => Some(url),
| Self::ByDomain(proxies) => proxies.iter().find_map(|proxy| proxy.for_url(url)),
}
}
}
#[derive(Clone, Debug, Deserialize)]
+100 -7
View File
@@ -56,7 +56,12 @@ pub(super) fn is_redacted<E: Event>(event: &E) -> bool {
return false;
};
unsigned.redacted_because.is_some()
unsigned.redacted_by.is_some()
}
#[derive(Deserialize)]
struct RedactionField {
redacts: OwnedEventId,
}
#[must_use]
@@ -69,16 +74,104 @@ pub(super) fn redacts_id<E: Event>(
}
if room_version_rules.redaction.content_field_redacts {
event.redacts().map(ToOwned::to_owned)
} else {
event
.get_content::<RoomRedactionEventContent>()
.ok()?
.redacts
.get_content::<RedactionField>()
.map(|r| r.redacts)
.ok()
} else {
event.redacts().map(ToOwned::to_owned)
}
}
#[derive(Deserialize)]
struct ExtractRedactedBecause {
redacted_because: Option<serde::de::IgnoredAny>,
#[serde(rename = "org.continuwuity.redacted_by")]
redacted_by: Option<serde::de::IgnoredAny>,
}
#[cfg(test)]
mod tests {
use ruma::{UInt, events::TimelineEventType, room_version_rules::RoomVersionRules};
use serde_json::json;
use crate::{Event, Pdu, pdu::EventHash};
#[test]
fn v11_redacts_from_content() {
let p = Pdu {
event_id: ruma::owned_event_id!("$v11"),
room_id: Some(ruma::owned_room_id!("!v11:example.com")),
sender: ruma::owned_user_id!("@user:example.com"),
origin: None,
origin_server_ts: UInt::default(),
kind: TimelineEventType::RoomRedaction,
content: serde_json::value::to_raw_value(&json!({"redacts": "$content_redacts"}))
.unwrap(),
sticky: None,
state_key: None,
prev_events: vec![],
depth: UInt::default(),
auth_events: vec![],
redacts: Some(ruma::owned_event_id!("$apex_redacts")),
unsigned: None,
hashes: EventHash { sha256: String::new() },
signatures: None,
};
assert_eq!(
p.redacts_id(&RoomVersionRules::V11),
Some(ruma::owned_event_id!("$content_redacts"))
);
}
#[test]
fn v10_redacts_from_apex() {
let p = Pdu {
event_id: ruma::owned_event_id!("$v11"),
room_id: Some(ruma::owned_room_id!("!v11:example.com")),
sender: ruma::owned_user_id!("@user:example.com"),
origin: None,
origin_server_ts: UInt::default(),
kind: TimelineEventType::RoomRedaction,
content: serde_json::value::to_raw_value(&json!({"redacts": "$content_redacts"}))
.unwrap(),
sticky: None,
state_key: None,
prev_events: vec![],
depth: UInt::default(),
auth_events: vec![],
redacts: Some(ruma::owned_event_id!("$apex_redacts")),
unsigned: None,
hashes: EventHash { sha256: String::new() },
signatures: None,
};
assert_eq!(
p.redacts_id(&RoomVersionRules::V10),
Some(ruma::owned_event_id!("$apex_redacts"))
);
}
#[test]
fn redacts_ignores_non_redaction_event() {
let p = Pdu {
event_id: ruma::owned_event_id!("$v11"),
room_id: Some(ruma::owned_room_id!("!v11:example.com")),
sender: ruma::owned_user_id!("@user:example.com"),
origin: None,
origin_server_ts: UInt::default(),
kind: TimelineEventType::RoomMessage,
content: serde_json::value::to_raw_value(&json!({"redacts": "$content_redacts"}))
.unwrap(),
sticky: None,
state_key: None,
prev_events: vec![],
depth: UInt::default(),
auth_events: vec![],
redacts: Some(ruma::owned_event_id!("$apex_redacts")),
unsigned: None,
hashes: EventHash { sha256: String::new() },
signatures: None,
};
assert_eq!(p.redacts_id(&RoomVersionRules::V11), None);
assert_eq!(p.redacts_id(&RoomVersionRules::V10), None);
}
}
+2
View File
@@ -48,5 +48,7 @@ pub fn unstable_features() -> BTreeMap<String, bool> {
("org.matrix.msc4174".to_owned(), true),
// Membership-based invite blocking (https://github.com/matrix-org/matrix-spec-proposals/pull/4494)
("uk.timedout.msc4494".to_owned(), true),
// server administration OAuth scope (https://github.com/matrix-org/matrix-spec-proposals/pull/4484)
("org.continuwuity.msc4484.unstable".to_owned(), true),
])
}
+269
View File
@@ -0,0 +1,269 @@
use std::time::{Duration, Instant};
use opentelemetry::{
KeyValue,
metrics::{Counter, Histogram, Meter},
};
use opentelemetry_semantic_conventions::{attribute, metric};
use tokio::runtime;
use super::process;
pub struct Instruments {
pub federation_outgoing_request_duration: Histogram<f64>,
pub federation_incoming_transaction_duration: Histogram<f64>,
pub federation_incoming_pdus: Counter<u64>,
pub federation_incoming_pdu_duration: Histogram<f64>,
pub federation_incoming_pdu_lag: Histogram<f64>,
pub federation_incoming_edus: Counter<u64>,
pub federation_incoming_edu_duration: Histogram<f64>,
pub sender_transaction_duration: Histogram<f64>,
pub sender_events: Counter<u64>,
pub sender_events_queued: Counter<u64>,
pub media_write_size: Histogram<u64>,
pub media_read_size: Histogram<u64>,
pub antispam_checks: Counter<u64>,
pub invites: Counter<u64>,
}
impl Instruments {
pub(super) fn new(meter: &Meter, runtime_metrics: Option<runtime::RuntimeMetrics>) -> Self {
register_process(meter);
register_allocator(meter);
if let Some(runtime_metrics) = runtime_metrics {
register_runtime(meter, runtime_metrics);
}
let duration = |name: &'static str, description: &'static str| {
meter
.f64_histogram(name)
.with_description(description)
.with_unit("s")
.with_boundaries(duration_buckets())
.build()
};
let size = |name: &'static str, description: &'static str| {
meter
.u64_histogram(name)
.with_description(description)
.with_unit("By")
.with_boundaries(size_buckets())
.build()
};
Self {
federation_outgoing_request_duration: duration(
"continuwuity.federation.outgoing.request.duration",
"Duration of outgoing federation requests",
),
federation_incoming_transaction_duration: duration(
"continuwuity.federation.incoming.transaction.duration",
"Time taken to process incoming federation transactions",
),
federation_incoming_pdus: meter
.u64_counter("continuwuity.federation.incoming.pdus")
.with_description("Incoming federation PDUs by event type and outcome")
.with_unit("{pdu}")
.build(),
federation_incoming_pdu_duration: duration(
"continuwuity.federation.incoming.pdu.duration",
"Time taken to handle an incoming federation PDU",
),
federation_incoming_pdu_lag: meter
.f64_histogram("continuwuity.federation.incoming.pdu.lag")
.with_description(
"Time between an accepted incoming PDU's origin_server_ts and its arrival",
)
.with_unit("s")
.with_boundaries(vec![
0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0, 30.0, 60.0, 300.0, 900.0, 3600.0,
])
.build(),
federation_incoming_edus: meter
.u64_counter("continuwuity.federation.incoming.edus")
.with_description("Incoming federation EDUs by type")
.with_unit("{edu}")
.build(),
federation_incoming_edu_duration: duration(
"continuwuity.federation.incoming.edu.duration",
"Time taken to handle an incoming federation EDU",
),
sender_transaction_duration: duration(
"continuwuity.sender.transaction.duration",
"Duration of outgoing transactions by destination type and outcome",
),
sender_events: meter
.u64_counter("continuwuity.sender.events")
.with_description("PDUs and EDUs sent in outgoing transactions by outcome")
.with_unit("{event}")
.build(),
sender_events_queued: meter
.u64_counter("continuwuity.sender.events.queued")
.with_description("PDUs and EDUs queued for sending")
.with_unit("{event}")
.build(),
media_write_size: size(
"continuwuity.media.write.size",
"Size of media files written, from local uploads or cached remote media",
),
media_read_size: size("continuwuity.media.read.size", "Size of media files served"),
antispam_checks: meter
.u64_counter("continuwuity.antispam.checks")
.with_description("Antispam service checks by check and outcome")
.with_unit("{check}")
.build(),
invites: meter
.u64_counter("continuwuity.invites")
.with_description("Invites sent by local users or received over federation")
.with_unit("{invite}")
.build(),
}
}
}
#[must_use]
pub fn duration_buckets() -> Vec<f64> { (0..16).map(|i| 0.001 * f64::from(1_u32 << i)).collect() }
fn size_buckets() -> Vec<f64> { (0..11).map(|i| 1024.0 * f64::from(4_u32.pow(i))).collect() }
fn register_process(meter: &Meter) {
let started = Instant::now();
meter
.f64_observable_gauge(metric::PROCESS_UPTIME)
.with_description("Time since the server started")
.with_unit("s")
.with_callback(move |observer| {
observer.observe(started.elapsed().as_secs_f64(), &[]);
})
.build();
meter
.f64_observable_counter(metric::PROCESS_CPU_TIME)
.with_description("Total CPU time spent by the process")
.with_unit("s")
.with_callback(|observer| {
if let Some((user, system)) = process::cpu_time() {
observer
.observe(user.as_secs_f64(), &[KeyValue::new(attribute::CPU_MODE, "user")]);
observer.observe(system.as_secs_f64(), &[KeyValue::new(
attribute::CPU_MODE,
"system",
)]);
}
})
.build();
meter
.i64_observable_up_down_counter(metric::PROCESS_MEMORY_USAGE)
.with_description("Resident memory of the process")
.with_unit("By")
.with_callback(|observer| {
if let Some(resident) =
process::memory().and_then(|(resident, _)| resident.try_into().ok())
{
observer.observe(resident, &[]);
}
})
.build();
meter
.i64_observable_up_down_counter(metric::PROCESS_MEMORY_VIRTUAL)
.with_description("Virtual memory of the process")
.with_unit("By")
.with_callback(|observer| {
if let Some(virt) = process::memory().and_then(|(_, virt)| virt.try_into().ok()) {
observer.observe(virt, &[]);
}
})
.build();
meter
.i64_observable_up_down_counter(metric::PROCESS_UNIX_FILE_DESCRIPTOR_COUNT)
.with_description("Number of file descriptors in use by the process")
.with_unit("{file_descriptor}")
.with_callback(|observer| {
if let Some(fds) = process::open_fds().and_then(|fds| fds.try_into().ok()) {
observer.observe(fds, &[]);
}
})
.build();
}
fn register_allocator(meter: &Meter) {
meter
.u64_observable_gauge("continuwuity.jemalloc.memory")
.with_description("jemalloc memory statistics, when built with jemalloc_stats")
.with_unit("By")
.with_callback(|observer| {
for (kind, bytes) in crate::alloc::memory_usage_stats().into_iter().flatten() {
if let Ok(bytes) = bytes.try_into() {
observer.observe(bytes, &[KeyValue::new("kind", kind)]);
}
}
})
.build();
}
fn register_runtime(meter: &Meter, metrics: runtime::RuntimeMetrics) {
let gauge = |name: &'static str,
description: &'static str,
read: fn(&runtime::RuntimeMetrics) -> usize| {
let metrics = metrics.clone();
meter
.u64_observable_gauge(name)
.with_description(description)
.with_callback(move |observer| {
if let Ok(value) = read(&metrics).try_into() {
observer.observe(value, &[]);
}
})
.build();
};
gauge(
"continuwuity.tokio.workers",
"Number of tokio runtime worker threads",
runtime::RuntimeMetrics::num_workers,
);
gauge(
"continuwuity.tokio.alive_tasks",
"Number of alive tasks in the tokio runtime",
runtime::RuntimeMetrics::num_alive_tasks,
);
gauge(
"continuwuity.tokio.global_queue_depth",
"Number of tasks in the tokio runtime global queue",
runtime::RuntimeMetrics::global_queue_depth,
);
let busy_metrics = metrics.clone();
meter
.f64_observable_counter("continuwuity.tokio.worker.busy_time")
.with_description("Total time tokio worker threads spent busy")
.with_unit("s")
.with_callback(move |observer| {
let busy: Duration = (0..busy_metrics.num_workers())
.map(|worker| busy_metrics.worker_total_busy_duration(worker))
.sum();
observer.observe(busy.as_secs_f64(), &[]);
})
.build();
meter
.u64_observable_counter("continuwuity.tokio.worker.parks")
.with_description("Total number of times tokio worker threads parked")
.with_unit("{park}")
.with_callback(move |observer| {
let parks = (0..metrics.num_workers())
.map(|worker| metrics.worker_park_count(worker))
.sum();
observer.observe(parks, &[]);
})
.build();
}
+40 -2
View File
@@ -1,10 +1,21 @@
mod instruments;
mod process;
mod tests;
use std::sync::atomic::AtomicU32;
use opentelemetry::metrics::Meter;
pub use opentelemetry::{KeyValue, metrics::AsyncInstrument};
pub use prometheus::TEXT_FORMAT as PROMETHEUS_CONTENT_TYPE;
use prometheus::{Encoder, TextEncoder};
use tokio::runtime;
use tokio_metrics::TaskMonitor;
#[cfg(tokio_unstable)]
use tokio_metrics::{RuntimeIntervals, RuntimeMonitor};
pub use self::instruments::{Instruments, duration_buckets};
use crate::{Err, Result};
pub struct Metrics {
_runtime: Option<runtime::Handle>,
@@ -22,21 +33,35 @@ pub struct Metrics {
pub requests_handle_active: AtomicU32,
pub requests_handle_finished: AtomicU32,
pub requests_panic: AtomicU32,
pub meter: Meter,
pub instruments: Instruments,
registry: Option<prometheus::Registry>,
}
impl Metrics {
#[must_use]
pub fn new(runtime: Option<runtime::Handle>) -> Self {
pub fn new(
runtime: Option<runtime::Handle>,
meter: Meter,
registry: Option<prometheus::Registry>,
) -> Self {
#[cfg(tokio_unstable)]
let runtime_monitor = runtime.as_ref().map(RuntimeMonitor::new);
#[cfg(tokio_unstable)]
let runtime_intervals = runtime_monitor.as_ref().map(RuntimeMonitor::intervals);
let runtime_metrics = runtime.as_ref().map(runtime::Handle::metrics);
Self {
_runtime: runtime.clone(),
runtime_metrics: runtime.as_ref().map(runtime::Handle::metrics),
instruments: Instruments::new(&meter, runtime_metrics.clone()),
meter,
registry,
runtime_metrics,
task_monitor: runtime.map(|_| TaskMonitor::new()),
@@ -62,6 +87,19 @@ impl Metrics {
.expect("next interval")
}
pub fn render(&self) -> Result<String> {
let Some(registry) = &self.registry else {
return Err!("Prometheus metrics are not enabled");
};
let mut buf = Vec::new();
TextEncoder::new()
.encode(&registry.gather(), &mut buf)
.map_err(|e| crate::err!("{e}"))?;
Ok(String::from_utf8(buf)?)
}
#[inline]
pub fn task_root(&self) -> Option<&TaskMonitor> { self.task_monitor.as_ref() }
+47
View File
@@ -0,0 +1,47 @@
use std::time::Duration;
/// User and system CPU time.
#[cfg(unix)]
pub(super) fn cpu_time() -> Option<(Duration, Duration)> {
use nix::sys::resource::{UsageWho, getrusage};
let usage = getrusage(UsageWho::RUSAGE_SELF).ok()?;
let to_duration = |tv: nix::sys::time::TimeVal| {
Duration::from_secs(tv.tv_sec().try_into().ok()?)
.checked_add(Duration::from_micros(tv.tv_usec().try_into().ok()?))
};
Some((to_duration(usage.user_time())?, to_duration(usage.system_time())?))
}
#[cfg(not(unix))]
pub(super) fn cpu_time() -> Option<(Duration, Duration)> { None }
/// Resident and virtual memory in bytes, read from `/proc/self/status`.
#[cfg(target_os = "linux")]
pub(super) fn memory() -> Option<(u64, u64)> {
let status = std::fs::read_to_string("/proc/self/status").ok()?;
let field = |name: &str| -> Option<u64> {
let value = status.lines().find_map(|line| line.strip_prefix(name))?;
let kib: u64 = value.trim().trim_end_matches(" kB").parse().ok()?;
kib.checked_mul(1024)
};
Some((field("VmRSS:")?, field("VmSize:")?))
}
#[cfg(not(target_os = "linux"))]
pub(super) fn memory() -> Option<(u64, u64)> { None }
#[cfg(target_os = "linux")]
pub(super) fn open_fds() -> Option<u64> {
// The directory handle used for the listing is itself an open descriptor.
let count = std::fs::read_dir("/proc/self/fd")
.ok()?
.count()
.checked_sub(1)?;
count.try_into().ok()
}
#[cfg(not(target_os = "linux"))]
pub(super) fn open_fds() -> Option<u64> { None }
+40
View File
@@ -0,0 +1,40 @@
#![cfg(test)]
use opentelemetry::metrics::MeterProvider;
use opentelemetry_sdk::metrics::SdkMeterProvider;
use super::{KeyValue, Metrics};
fn metrics() -> (Metrics, SdkMeterProvider) {
let registry = prometheus::Registry::new();
let exporter = opentelemetry_prometheus::exporter()
.with_registry(registry.clone())
.scope_info_enabled(false)
.build()
.unwrap();
let provider = SdkMeterProvider::builder().with_reader(exporter).build();
let meter = provider.meter("continuwuity");
let handle = tokio::runtime::Handle::current();
(Metrics::new(Some(handle), meter, Some(registry)), provider)
}
#[tokio::test]
async fn renders_prometheus_names() {
let (metrics, _provider) = metrics();
metrics
.instruments
.sender_events
.add(3, &[KeyValue::new("destination", "federation"), KeyValue::new("kind", "pdu")]);
let body = metrics.render().unwrap();
for expected in [
"continuwuity_sender_events_total{destination=\"federation\",kind=\"pdu\"} 3",
"# TYPE process_uptime_seconds gauge",
"process_cpu_time_seconds_total{cpu_mode=\"user\"}",
"# TYPE continuwuity_tokio_worker_busy_time_seconds_total counter",
] {
assert!(body.contains(expected), "missing {expected:?} in:\n{body}");
}
assert!(!body.contains("otel_scope_name"));
}
+8 -3
View File
@@ -49,7 +49,12 @@ pub struct Server {
impl Server {
#[must_use]
pub fn new(config: Config, runtime: Option<runtime::Handle>, log: Log) -> Self {
pub fn new(
config: Config,
runtime: Option<runtime::Handle>,
log: Log,
metrics: Metrics,
) -> Self {
Self {
name: config.server_name.clone(),
config: config::Manager::new(config),
@@ -57,10 +62,10 @@ impl Server {
stopping: AtomicBool::new(false),
reloading: AtomicBool::new(false),
restarting: AtomicBool::new(false),
runtime: runtime.clone(),
runtime,
signal: broadcast::channel::<&'static str>(1).0,
log,
metrics: Metrics::new(runtime),
metrics,
}
}
+4 -1
View File
@@ -37,7 +37,10 @@ pub use self::{
stream::{IterStream, ReadyExt, Tools as StreamTools, TryReadyExt},
string::{str_from_bytes, string_from_bytes},
sys::compute::available_parallelism,
time::{now_millis as millis_since_unix_epoch, timepoint_ago, timepoint_from_now},
time::{
linear_backoff, millis_from_now, now_millis as millis_since_unix_epoch, timepoint_ago,
timepoint_from_now,
},
};
#[inline]
+11
View File
@@ -49,6 +49,17 @@ where
Ok(out)
}
/// Compare two strings without short-circuiting on the first mismatch, for
/// checking secrets.
#[must_use]
pub fn constant_time_eq(a: &str, b: &str) -> bool {
a.len() == b.len()
&& a.bytes()
.zip(b.bytes())
.fold(0_u8, |acc, (x, y)| acc | (x ^ y))
== 0
}
#[inline]
#[must_use]
pub fn camel_to_snake_string(s: &str) -> String {
+7
View File
@@ -68,3 +68,10 @@ fn between_infallible() {
assert_eq!("\"foo".between_infallible(("\"", "\"")), "\"foo");
assert_eq!("foo".between_infallible(("\"", "\"")), "foo");
}
#[test]
fn constant_time_eq() {
assert!(super::constant_time_eq("abc", "abc"));
assert!(!super::constant_time_eq("abc", "abz"));
assert!(!super::constant_time_eq("abc", "abcd"));
}
+40
View File
@@ -16,6 +16,20 @@ pub fn now_millis() -> u64 {
.as_millis() as u64
}
/// Returns a capped linear retry delay for a failed attempt.
#[must_use]
pub fn linear_backoff(base: Duration, limit: Duration, attempt: u32) -> Duration {
base.saturating_mul(attempt).min(limit)
}
/// Returns a saturated Unix-millisecond deadline after `duration`.
#[must_use]
pub fn millis_from_now(duration: Duration) -> u64 { add_millis(now_millis(), duration) }
fn add_millis(now: u64, duration: Duration) -> u64 {
now.saturating_add(u64::try_from(duration.as_millis()).unwrap_or(u64::MAX))
}
#[inline]
pub fn parse_timepoint_ago(ago: &str) -> Result<SystemTime> {
timepoint_ago(parse_duration(ago)?)
@@ -155,3 +169,29 @@ pub fn is_within_bounds(
| TimeDirection::After => item_time >= time_boundary,
}
}
#[cfg(test)]
mod tests {
use std::time::Duration;
use super::{add_millis, linear_backoff};
#[test]
fn linear_backoff_scales_and_caps() {
let base = Duration::from_secs(10);
let limit = Duration::from_secs(25);
assert_eq!(linear_backoff(base, limit, 0), Duration::ZERO);
assert_eq!(linear_backoff(base, limit, 1), Duration::from_secs(10));
assert_eq!(linear_backoff(base, limit, 2), Duration::from_secs(20));
assert_eq!(linear_backoff(base, limit, 3), limit);
assert_eq!(linear_backoff(base, limit, u32::MAX), limit);
}
#[test]
fn millis_deadline_saturates() {
assert_eq!(add_millis(10, Duration::from_millis(20)), 30);
assert_eq!(add_millis(u64::MAX, Duration::from_millis(1)), u64::MAX);
assert_eq!(add_millis(0, Duration::from_secs(u64::MAX)), u64::MAX);
}
}
+8 -4
View File
@@ -20,13 +20,13 @@ pub(crate) fn cf_options(ctx: &Context, opts: Options, desc: &Descriptor) -> Res
}
fn descriptor_cf_options(
mut opts: Options,
opts: Options,
mut desc: Descriptor,
config: &Config,
cache: Option<&Cache>,
) -> Result<Options> {
set_compression(&mut desc, config);
set_table_options(&mut opts, &desc, cache)?;
let mut opts = set_table_options(opts, &desc, cache)?;
opts.set_min_write_buffer_number(1);
opts.set_max_write_buffer_number(2);
@@ -87,7 +87,11 @@ fn descriptor_cf_options(
Ok(opts)
}
fn set_table_options(opts: &mut Options, desc: &Descriptor, cache: Option<&Cache>) -> Result {
fn set_table_options(
mut opts: Options,
desc: &Descriptor,
cache: Option<&Cache>,
) -> Result<Options> {
let mut table = table_options(desc, cache.is_some());
if let Some(cache) = cache {
@@ -113,7 +117,7 @@ fn set_table_options(opts: &mut Options, desc: &Descriptor, cache: Option<&Cache
opts.set_block_based_table_factory(&table);
Ok(())
Ok(opts)
}
fn set_compression(desc: &mut Descriptor, config: &Config) {
+34 -6
View File
@@ -5,12 +5,18 @@ use rocksdb::perf::get_memory_usage_stats;
use crate::or_else;
pub struct MemoryUsage {
pub mem_table_total: u64,
pub mem_table_unflushed: u64,
pub mem_table_readers_total: u64,
pub row_cache: u64,
}
impl super::Engine {
pub fn memory_usage(&self) -> Result<String> {
let mut res = String::new();
let stats =
get_memory_usage_stats(Some(&[&self.db]), Some(&[&*self.ctx.row_cache.lock()]))
.or_else(or_else)?;
let stats = self.memory_usage_stats()?;
let col_caches = self.col_cache_usage()?;
let mibs = |input| f64::from(u32::try_from(input / 1024).unwrap_or(0)) / 1024.0;
writeln!(
res,
@@ -19,13 +25,35 @@ impl super::Engine {
mibs(stats.mem_table_total),
mibs(stats.mem_table_unflushed),
mibs(stats.mem_table_readers_total),
mibs(u64::try_from(self.ctx.row_cache.lock().get_usage())?),
mibs(stats.row_cache),
)?;
for (name, cache) in &*self.ctx.col_cache.lock() {
writeln!(res, "{name} cache: {:.2} MiB", mibs(u64::try_from(cache.get_usage())?))?;
for (name, usage) in col_caches {
writeln!(res, "{name} cache: {:.2} MiB", mibs(usage))?;
}
Ok(res)
}
pub fn memory_usage_stats(&self) -> Result<MemoryUsage> {
let stats =
get_memory_usage_stats(Some(&[&self.db]), Some(&[&*self.ctx.row_cache.lock()]))
.or_else(or_else)?;
Ok(MemoryUsage {
mem_table_total: stats.mem_table_total,
mem_table_unflushed: stats.mem_table_unflushed,
mem_table_readers_total: stats.mem_table_readers_total,
row_cache: u64::try_from(self.ctx.row_cache.lock().get_usage())?,
})
}
pub fn col_cache_usage(&self) -> Result<Vec<(String, u64)>> {
self.ctx
.col_cache
.lock()
.iter()
.map(|(name, cache)| Ok((name.clone(), u64::try_from(cache.get_usage())?)))
.collect()
}
}
+2 -2
View File
@@ -192,13 +192,13 @@ impl<W: Write> ser::Serializer for &mut Serializer<'_, W> {
);
match name {
| "Json" => serde_json::to_writer(&mut self.out, value).map_err(Into::into),
| "Json" => serde_json::to_writer(&mut *self.out, value).map_err(Into::into),
| "Cbor" => {
use minicbor::encode::write::Writer;
use minicbor_serde::Serializer;
value
.serialize(&mut Serializer::new(&mut Writer::new(&mut self.out)))
.serialize(&mut Serializer::new(&mut Writer::new(&mut *self.out)))
.map_err(|e| Self::Error::SerdeSer(e.to_string().into()))
},
| _ => unhandled!("Unrecognized serialization Newtype {name:?}"),
+21
View File
@@ -89,6 +89,8 @@ fn generate_example(input: &ItemStruct, args: &[Meta], write: bool) -> Result<To
}
}
let env_prefix = env_prefix(section);
let mut summary: Vec<TokenStream2> = Vec::new();
let mut nested_displays: Vec<TokenStream2> = Vec::new();
@@ -144,6 +146,12 @@ fn generate_example(input: &ItemStruct, args: &[Meta], write: bool) -> Result<To
file.write_fmt(format_args!("\n{doc}"))
.expect("written to config file");
file.write_fmt(format_args!(
"# env: {env_prefix}{}\n",
ident.to_string().to_uppercase()
))
.expect("written to config file");
file.write_fmt(format_args!("#{ident} ={default}\n"))
.expect("written to config file");
}
@@ -213,6 +221,19 @@ fn generate_example(input: &ItemStruct, args: &[Meta], write: bool) -> Result<To
Ok(display)
}
fn env_prefix(section: &str) -> String {
let nested = section
.strip_prefix("global")
.unwrap_or(section)
.trim_start_matches('.');
if nested.is_empty() {
"CONTINUWUITY_".to_owned()
} else {
format!("CONTINUWUITY_{}__", nested.replace('.', "__").to_uppercase())
}
}
fn get_default(field: &Field) -> Option<String> {
for attr in &field.attrs {
let Meta::List(MetaList { path, tokens, .. }) = &attr.meta else {
+3 -4
View File
@@ -131,9 +131,7 @@ media_thumbnail = [
"conduwuit-service/media_thumbnail",
]
otlp_telemetry = [
"dep:opentelemetry",
"dep:tracing-opentelemetry",
"dep:opentelemetry_sdk",
"dep:opentelemetry-otlp",
]
perf_measurements = [
@@ -221,12 +219,13 @@ console-subscriber.optional = true
console-subscriber.workspace = true
const-str.workspace = true
log.workspace = true
opentelemetry.optional = true
opentelemetry.workspace = true
opentelemetry-otlp.optional = true
opentelemetry-otlp.workspace = true
opentelemetry_sdk.optional = true
opentelemetry-prometheus.workspace = true
opentelemetry-semantic-conventions.workspace = true
opentelemetry_sdk.workspace = true
prometheus.workspace = true
sentry-tower.optional = true
sentry-tower.workspace = true
sentry-tracing.optional = true
+5 -25
View File
@@ -6,12 +6,9 @@ use conduwuit_core::{
debug_warn, err,
log::{ConsoleFormat, ConsoleWriter, LogLevelReloadHandles, capture, fmt_span},
result::UnwrapOrErr,
warn,
};
#[cfg(feature = "otlp_telemetry")]
use opentelemetry::trace::TracerProvider;
#[cfg(feature = "otlp_telemetry")]
use opentelemetry_otlp::WithExportConfig;
use tracing_subscriber::{EnvFilter, Layer, Registry, fmt, layer::SubscriberExt, reload};
#[cfg(feature = "perf_measurements")]
@@ -83,32 +80,15 @@ pub(crate) fn init(
opentelemetry_sdk::propagation::TraceContextPropagator::new(),
);
let exporter = match config.otlp_protocol.as_str() {
| "grpc" => opentelemetry_otlp::SpanExporter::builder()
.with_tonic()
.with_protocol(opentelemetry_otlp::Protocol::Grpc) // TODO: build from env when 0.32 is released
.build()
.expect("Failed to create OTLP gRPC exporter"),
| "http" => opentelemetry_otlp::SpanExporter::builder()
.with_http()
.build()
.expect("Failed to create OTLP HTTP exporter"),
| protocol => {
warn!(
"Invalid OTLP protocol '{}', falling back to HTTP. Valid options are \
'http' or 'grpc'.",
protocol
);
opentelemetry_otlp::SpanExporter::builder()
.with_http()
.build()
.expect("Failed to create OTLP HTTP exporter")
},
};
let exporter = opentelemetry_otlp::SpanExporter::builder()
.build()
.expect("Failed to create OTLP span exporter");
let provider = opentelemetry_sdk::trace::SdkTracerProvider::builder()
.with_resource(crate::metrics::resource(config))
.with_batch_exporter(exporter)
.build();
opentelemetry::global::set_tracer_provider(provider.clone());
let tracer = provider.tracer(conduwuit_core::BRANDING);
+112
View File
@@ -0,0 +1,112 @@
use conduwuit_core::{
Result,
config::Config,
err,
metrics::{Metrics, duration_buckets},
};
use opentelemetry::{
InstrumentationScope, KeyValue, global,
metrics::{MeterProvider, noop::NoopMeterProvider},
};
use opentelemetry_sdk::{
Resource,
metrics::{Aggregation, Instrument, SdkMeterProvider, Stream},
resource::{EnvResourceDetector, TelemetryResourceDetector},
};
use opentelemetry_semantic_conventions::{SCHEMA_URL, attribute, metric};
use tokio::runtime;
/// The returned provider must be shut down before the runtime stops so pending
/// OTLP exports are flushed.
pub(crate) fn init(
config: &Config,
runtime: Option<&runtime::Handle>,
) -> Result<(Metrics, SdkMeterProvider)> {
let resource = resource(config);
let mut builder = SdkMeterProvider::builder()
.with_resource(resource)
.with_view(|instrument: &Instrument| {
(instrument.name() == metric::HTTP_SERVER_REQUEST_DURATION)
.then(|| {
Stream::builder()
.with_aggregation(Aggregation::ExplicitBucketHistogram {
boundaries: duration_buckets(),
record_min_max: true,
})
.build()
.ok()
})
.flatten()
});
let registry = config
.allow_prometheus_metrics
.then(prometheus::Registry::new);
let mut readers = registry.is_some();
if let Some(registry) = &registry {
let exporter = opentelemetry_prometheus::exporter()
.with_registry(registry.clone())
.scope_info_enabled(false)
.build()
.map_err(|e| err!(Config("allow_prometheus_metrics", "{e}")))?;
builder = builder.with_reader(exporter);
}
#[cfg(feature = "otlp_telemetry")]
if config.allow_otlp_metrics {
use opentelemetry_otlp::MetricExporter;
let exporter = MetricExporter::builder()
.build()
.map_err(|e| err!(Config("allow_otlp_metrics", "{e}")))?;
builder = builder.with_periodic_exporter(exporter);
readers = true;
}
#[cfg(not(feature = "otlp_telemetry"))]
if config.allow_otlp_metrics {
conduwuit_core::warn!(
"allow_otlp_metrics is set but this build does not include the otlp_telemetry \
feature"
);
}
let provider = builder.build();
let scope = InstrumentationScope::builder(conduwuit_core::BRANDING)
.with_version(conduwuit_core::version())
.with_schema_url(SCHEMA_URL)
.build();
// Without a reader the SDK rejects every instrument and logs an error for
// each, so nothing is recorded.
let meter = if readers {
global::set_meter_provider(provider.clone());
provider.meter_with_scope(scope)
} else {
NoopMeterProvider::new().meter_with_scope(scope)
};
Ok((Metrics::new(runtime.cloned(), meter, registry), provider))
}
pub(crate) fn resource(config: &Config) -> Resource {
// Defaults first so OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME win.
let mut resource = Resource::builder_empty()
.with_detector(Box::new(TelemetryResourceDetector))
.with_service_name(conduwuit_core::BRANDING)
.with_attributes([
KeyValue::new(attribute::SERVICE_VERSION, conduwuit_core::version()),
KeyValue::new(attribute::SERVICE_INSTANCE_ID, config.server_name.to_string()),
])
.with_detector(Box::new(EnvResourceDetector::new()));
if let Some(name) = std::env::var("OTEL_SERVICE_NAME")
.ok()
.filter(|name| !name.is_empty())
{
resource = resource.with_service_name(name);
}
resource.build()
}
+2
View File
@@ -9,6 +9,7 @@ conduwuit_macros::introspect_crate! {}
mod clap;
mod deadlock;
mod logging;
mod metrics;
mod mods;
mod panic;
mod restart;
@@ -50,6 +51,7 @@ pub fn run_with_args(args: &Args) -> Result<()> {
runtime.spawn(signal::signal(server.clone()));
runtime.block_on(async_main(&server))?;
server.shutdown_metrics();
runtime::shutdown(&server, runtime);
#[cfg(unix)]
+1 -12
View File
@@ -87,21 +87,10 @@ fn enable_histogram(builder: &mut Builder, args: &Args) {
#[cfg(tokio_unstable)]
#[tracing::instrument(name = "stop", level = "info", skip_all)]
pub(super) fn shutdown(server: &Arc<Server>, runtime: tokio::runtime::Runtime) {
use conduwuit_core::event;
use tracing::Level;
// The final metrics output is promoted to INFO when tokio_unstable is
// active in a release/bench mode and DEBUG is likely optimized out
const LEVEL: Level = if cfg!(debug_assertions) {
Level::DEBUG
} else {
Level::INFO
};
wait_shutdown(server, runtime);
let runtime_metrics = server.server.metrics.runtime_interval().unwrap_or_default();
event!(LEVEL, ?runtime_metrics, "Final runtime metrics");
conduwuit_core::debug!(?runtime_metrics, "Final runtime metrics");
}
#[cfg(not(tokio_unstable))]
+19 -5
View File
@@ -3,7 +3,7 @@ use std::sync::Arc;
use conduwuit_core::{
Error, Result,
config::Config,
info,
error, info,
log::Log,
utils::{stream, sys},
};
@@ -23,6 +23,8 @@ pub(crate) struct Server {
_tracing_flame_guard: TracingFlameGuard,
meter_provider: opentelemetry_sdk::metrics::SdkMeterProvider,
#[cfg(feature = "sentry_telemetry")]
_sentry_guard: Option<::sentry::ClientInitGuard>,
@@ -56,6 +58,8 @@ impl Server {
sys::maximize_fd_limit()
.expect("Unable to increase maximum soft and hard file descriptor limit");
let (metrics, meter_provider) = crate::metrics::init(&config, runtime)?;
let (_old_width, _new_width) = stream::set_width(config.stream_width_default);
let (_old_amp, _new_amp) = stream::set_amplification(config.stream_amplification);
@@ -68,15 +72,19 @@ impl Server {
);
Ok(Arc::new(Self {
server: Arc::new(conduwuit_core::Server::new(config, runtime.cloned(), Log {
reload: tracing_reload_handle,
capture,
})),
server: Arc::new(conduwuit_core::Server::new(
config,
runtime.cloned(),
Log { reload: tracing_reload_handle, capture },
metrics,
)),
services: None.into(),
_tracing_flame_guard: tracing_flame_guard,
meter_provider,
#[cfg(feature = "sentry_telemetry")]
_sentry_guard: sentry_guard,
@@ -84,4 +92,10 @@ impl Server {
mods: tokio::sync::RwLock::new(Vec::new()),
}))
}
pub(crate) fn shutdown_metrics(&self) {
if let Err(e) = self.meter_provider.shutdown() {
error!("Failed to shut down metrics: {e}");
}
}
}
+1
View File
@@ -111,6 +111,7 @@ http-body-util.workspace = true
hyper.workspace = true
hyper-util.workspace = true
log.workspace = true
opentelemetry-instrumentation-tower.workspace = true
ruma.workspace = true
rustls.workspace = true
rustls.optional = true
+51 -5
View File
@@ -11,6 +11,7 @@ use http::{
HeaderValue, Method, StatusCode,
header::{self, HeaderName},
};
use opentelemetry_instrumentation_tower::http::server::LayerBuilder as OtelHttpLayerBuilder;
use tower::ServiceBuilder;
use tower_http::{
catch_panic::CatchPanicLayer,
@@ -49,6 +50,13 @@ pub(crate) fn build(services: &Arc<Services>) -> Result<(Router, Guard)> {
let services_ = services.clone();
let layers = layers
.map_request(bound_method)
.layer(
OtelHttpLayerBuilder::builder()
.with_tracing(false)
.build()
.expect("valid HTTP metrics layer"),
)
.layer(SetSensitiveHeadersLayer::new([header::AUTHORIZATION]))
.layer(
TraceLayer::new_for_http()
@@ -165,6 +173,30 @@ fn cors_layer(_server: &Server) -> CorsLayer {
.max_age(Duration::from_hours(24))
}
/// Methods outside the standard set can never match a route; record them as
/// `_OTHER`, as the semantic conventions ask, so clients cannot create new
/// metric attribute values.
fn bound_method<B>(mut request: http::Request<B>) -> http::Request<B> {
const KNOWN: [Method; 9] = [
Method::GET,
Method::HEAD,
Method::POST,
Method::PUT,
Method::DELETE,
Method::CONNECT,
Method::OPTIONS,
Method::TRACE,
Method::PATCH,
];
if !KNOWN.contains(request.method()) {
*request.method_mut() =
Method::from_bytes(b"_OTHER").expect("_OTHER is a valid method token");
}
request
}
fn body_limit_layer(server: &Server) -> DefaultBodyLimit {
DefaultBodyLimit::max(server.config.max_request_size)
}
@@ -207,7 +239,7 @@ fn tracing_span<T>(request: &http::Request<T>) -> tracing::Span {
let path = request
.extensions()
.get::<MatchedPath>()
.map_or_else(|| request_path_str(request), truncated_matched_path);
.map_or_else(|| request_path_str(request), MatchedPath::as_str);
tracing::span! {
parent: None,
@@ -241,8 +273,22 @@ fn request_path_str<T>(request: &http::Request<T>) -> &str {
.as_str()
}
fn truncated_matched_path(path: &MatchedPath) -> &str {
path.as_str()
.rsplit_once(':')
.map_or(path.as_str(), |path| path.0.strip_suffix('/').unwrap_or(path.0))
#[cfg(test)]
mod tests {
use http::{Method, Request};
use super::bound_method;
#[test]
fn bound_method_collapses_unknown_methods() {
let request = |method: &[u8]| {
Request::builder()
.method(Method::from_bytes(method).unwrap())
.body(())
.unwrap()
};
assert_eq!(bound_method(request(b"GET")).method(), Method::GET);
assert_eq!(bound_method(request(b"BREW")).method().as_str(), "_OTHER");
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ pub(crate) async fn handle(
task.await
.map_err(unhandled)
.and_then(move |result| handle_result(&method, &uri, result))
.and_then(|result| handle_result(&method, &uri, result))
}
#[tracing::instrument(
+1
View File
@@ -0,0 +1 @@
pub mod notary;
+58
View File
@@ -0,0 +1,58 @@
//! `POST /_matrix/key/*/query`
//!
//! Endpoint to query signing keys through other (notary) servers.
pub mod unstable {
use std::collections::BTreeMap;
use ruma::{
OwnedServerName, OwnedServerSigningKeyId,
api::{
federation::{
authentication::ServerSignatures,
discovery::{ServerSigningKeys, get_remote_server_keys_batch::v2::QueryCriteria},
},
request, response,
},
metadata,
serde::Raw,
};
metadata! {
method: POST,
rate_limited: true,
authentication: ServerSignatures,
history: {
unstable("org.continuwuity.msc4553") => "/_matrix/key/unstable/org.continuwuity.msc4556/query",
}
}
#[request]
pub struct Request {
pub server_keys:
BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, QueryCriteria>>,
}
#[response]
pub struct Response {
pub server_keys: Vec<Raw<ServerSigningKeys>>,
}
impl Request {
#[must_use]
pub fn new(
server_keys: BTreeMap<
OwnedServerName,
BTreeMap<OwnedServerSigningKeyId, QueryCriteria>,
>,
) -> Self {
Self { server_keys }
}
}
impl Response {
/// Creates a new `Response` with the given keys.
#[must_use]
pub fn new(server_keys: Vec<Raw<ServerSigningKeys>>) -> Self { Self { server_keys } }
}
}
+2
View File
@@ -6,3 +6,5 @@ pub mod invite_permission_config;
pub mod meowlnir_antispam;
pub mod policy;
pub mod pushers;
pub mod federation;
+31 -14
View File
@@ -1,7 +1,7 @@
use std::{fmt::Debug, sync::Arc};
use async_trait::async_trait;
use conduwuit::{Result, config::Antispam, debug};
use conduwuit::{Result, Server, config::Antispam, debug, metrics::KeyValue};
use ruma::{
OwnedRoomId, OwnedUserId,
api::{auth_scheme::AppserviceToken, path_builder::VersionHistory},
@@ -11,6 +11,7 @@ use ruminuwuity::{draupnir_antispam, meowlnir_antispam};
use crate::{client, config, sending, service::Dep};
struct Services {
server: Arc<Server>,
config: Dep<config::Service>,
client: Dep<client::Service>,
}
@@ -24,6 +25,7 @@ impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: Services {
server: args.server.clone(),
client: args.depend::<client::Service>("client"),
config: args.depend::<config::Service>("config"),
},
@@ -101,6 +103,7 @@ impl Service {
} else {
Ok(())
};
self.record("user_may_invite", &result);
return result;
}
Ok(())
@@ -146,6 +149,7 @@ impl Service {
} else {
Ok(())
};
self.record("user_may_join_room", &result);
return result;
}
Ok(())
@@ -160,24 +164,37 @@ impl Service {
) -> Result<()> {
if let Some(Antispam { meowlnir: Some(meowlnir), .. }) = &self.services.config.antispam {
debug!(?room_id, ?user_id, "Asking meowlnir for accept_make_join");
self.send_antispam_request(
meowlnir.base_url.as_str(),
&meowlnir.secret,
meowlnir_antispam::accept_make_join::v1::Request::new(
meowlnir.management_room.clone(),
user_id,
room_id,
),
)
.await
.inspect(|_| debug!("meowlnir allowed the make_join"))
.inspect_err(|e| debug!("meowlnir denied the make_join: {e:?}"))
.map(|_| ())
let result = self
.send_antispam_request(
meowlnir.base_url.as_str(),
&meowlnir.secret,
meowlnir_antispam::accept_make_join::v1::Request::new(
meowlnir.management_room.clone(),
user_id,
room_id,
),
)
.await
.inspect(|_| debug!("meowlnir allowed the make_join"))
.inspect_err(|e| debug!("meowlnir denied the make_join: {e:?}"))
.map(|_| ());
self.record("accept_make_join", &result);
result
} else {
Ok(())
}
}
fn record(&self, check: &'static str, result: &Result) {
let outcome = if result.is_ok() { "allowed" } else { "denied" };
self.services
.server
.metrics
.instruments
.antispam_checks
.add(1, &[KeyValue::new("check", check), KeyValue::new("outcome", outcome)]);
}
/// Returns whether all joins should be checked with Meowlnir.
/// Is always false if Meowlnir is not configured.
pub fn check_all_joins(&self) -> bool {
+18 -2
View File
@@ -4,7 +4,10 @@ use async_trait::async_trait;
use conduwuit::{Config, Result, Server, err, trace, utils::response::LimitReadExt, warn};
use either::Either;
use hickory_resolver::{
TokioResolver, config::ConnectionConfig, net::runtime::TokioRuntimeProvider,
TokioResolver,
config::{ConnectionConfig, NameServerConfig},
net::runtime::TokioRuntimeProvider,
proto::rr::IntoName,
};
use ipaddress::IPAddress;
use reqwest::redirect;
@@ -320,7 +323,20 @@ fn get_dns_resolver(server: &Arc<Server>) -> Result<Arc<TokioResolver>> {
conf.add_search(sys_conf.clone());
}
for sys_conf in sys_conf.name_servers() {
let config_nameservers: Vec<NameServerConfig> = server
.config
.dns_servers
.iter()
.filter_map(IntoName::to_ip)
.map(NameServerConfig::udp_and_tcp)
.collect();
let nameservers = if !config_nameservers.is_empty() {
config_nameservers
} else {
sys_conf.name_servers().to_vec()
};
for sys_conf in nameservers {
let mut ns = sys_conf.clone();
if config.query_over_tcp_only {
+17 -4
View File
@@ -1,8 +1,8 @@
use std::{borrow::Cow, fmt::Debug, mem, time::Instant};
use conduwuit::{
Err, Error, Result, debug, debug_error, debug_info, debug_warn, err, trace,
utils::response::LimitReadExt,
Err, Error, Result, debug, debug_error, debug_info, debug_warn, err, metrics::KeyValue,
trace, utils::response::LimitReadExt,
};
use ipaddress::IPAddress;
use reqwest::{Client, Method, Request, Response, Url};
@@ -175,12 +175,25 @@ impl super::Service {
);
let start = Instant::now();
let response = client.execute(request).await;
let elapsed = start.elapsed();
debug_info!(
"Request finished in {:?}: {} matrix-federation://{dest}{}",
start.elapsed(),
"Request finished in {elapsed:?}: {} matrix-federation://{dest}{}",
method.as_str(),
url.path(),
);
let outcome = match &response {
| Ok(response) if response.status().is_success() => "success",
| Ok(response) if response.status().is_client_error() => "client_error",
| Ok(response) if response.status().is_server_error() => "server_error",
| Ok(_) => "other",
| Err(_) => "network_error",
};
self.services
.server
.metrics
.instruments
.federation_outgoing_request_duration
.record(elapsed.as_secs_f64(), &[KeyValue::new("outcome", outcome)]);
match response {
| Ok(response) =>
self.handle_response::<T>(dest, actual, &method, &url, response)
+21 -9
View File
@@ -8,7 +8,10 @@ use std::{
use assign::assign;
use async_trait::async_trait;
use conduwuit::{Error, Result, Server, SyncRwLock, debug, utils::millis_since_unix_epoch};
use conduwuit::{
Error, Result, Server, SyncRwLock, debug,
utils::{millis_from_now, millis_since_unix_epoch},
};
pub(crate) use execute::FederationPathBuilderInput;
use http::StatusCode;
use ruma::{
@@ -60,6 +63,9 @@ impl Service {
/// * The remote has not been marked as having a failed request, OR
/// * The next retry timestamp is in the past
pub fn is_healthy(&self, server_name: &ServerName) -> bool {
if server_name == self.services.server.name {
return true;
}
let map = self.remote_health.read();
let unix_now = millis_since_unix_epoch();
if let Some((_, next_retry)) = map.get(server_name) {
@@ -72,6 +78,9 @@ impl Service {
/// Returns how long the server should wait before attempting to contact the
/// remote again.
pub fn retry_after(&self, server_name: &ServerName) -> Option<Duration> {
if server_name == self.services.server.name {
return None;
}
let map = self.remote_health.read();
let unix_now = millis_since_unix_epoch();
map.get(server_name)
@@ -84,6 +93,9 @@ impl Service {
///
/// Does not update the marker if the backoff period is already in effect.
pub fn hit_unhealthy(&self, server_name: OwnedServerName) {
if server_name == self.services.server.name {
return;
}
let unix_now = millis_since_unix_epoch();
let mut map = self.remote_health.write();
let sn2 = server_name.clone(); // for logging since map.entry() moves
@@ -96,15 +108,9 @@ impl Service {
return;
}
let min = Duration::from_secs(self.services.server.config.sender_retry_backoff_base);
let max = Duration::from_secs(self.services.server.config.sender_retry_backoff_limit);
*retries = retries.saturating_add(1);
let next_interval = min.saturating_mul(*retries).min(max);
*next_retry = unix_now.saturating_add(
u64::try_from(next_interval.as_millis())
.expect("backoff milliseconds should not exceed u64::MAX"),
);
let next_interval = self.services.server.config.sender_retry_backoff(*retries);
*next_retry = millis_from_now(next_interval);
debug!(
"{} is (now) unhealthy ({} retries, blocked until: {})",
sn2, *retries, *next_retry
@@ -116,6 +122,9 @@ impl Service {
/// Returns true if the server was previously marked as unhealthy, false
/// otherwise.
pub fn mark_healthy(&self, server_name: &ServerName) -> bool {
if server_name == self.services.server.name {
return false;
}
let mut health_map = self.remote_health.write();
let was_unhealthy = health_map.remove(server_name).is_some();
if was_unhealthy {
@@ -142,6 +151,9 @@ impl Service {
/// Returns a rate-limited error if the remote is unhealthy.
fn ensure_remote_is_healthy(&self, server_name: &ServerName) -> Result<()> {
if server_name == self.services.server.name {
return Ok(());
}
// Read the backoff window once. The remote can be marked healthy
// between two lookups.
let Some(retry_after) = self
+27 -1
View File
@@ -10,7 +10,9 @@ use std::{path::PathBuf, sync::Arc, time::SystemTime};
use async_trait::async_trait;
use base64::{Engine as _, engine::general_purpose};
use conduwuit::{
Err, Result, Server, debug, debug_error, debug_info, debug_warn, err, error, trace,
Err, Result, Server, debug, debug_error, debug_info, debug_warn, err, error,
metrics::KeyValue,
trace,
utils::{
self, MutexMap,
time::{self, TimeDirection},
@@ -110,9 +112,26 @@ impl Service {
err!(Database(error!("Failed to write media file for MXC {mxc} at key {key:?}: {e}")))
})?;
self.services
.server
.metrics
.instruments
.media_write_size
.record(file.len().try_into().unwrap_or(u64::MAX), &[self.origin(mxc)]);
Ok(())
}
fn origin(&self, mxc: &Mxc<'_>) -> KeyValue {
let origin = if self.services.globals.server_is_ours(mxc.server_name) {
"local"
} else {
"remote"
};
KeyValue::new("origin", origin)
}
/// Deletes a file in the database and from the media directory via an MXC
pub async fn delete(&self, mxc: &Mxc<'_>) -> Result<()> {
match self.db.search_mxc_metadata_prefix(mxc).await {
@@ -177,6 +196,13 @@ impl Service {
.read_to_end(&mut content)
.await?;
self.services
.server
.metrics
.instruments
.media_read_size
.record(content.len().try_into().unwrap_or(u64::MAX), &[self.origin(mxc)]);
Ok(Some(FileMeta {
content: Some(content),
content_type,
+180
View File
@@ -0,0 +1,180 @@
use std::sync::Arc;
use conduwuit::{
metrics::{AsyncInstrument, KeyValue},
utils::millis_since_unix_epoch,
};
use crate::Services;
impl Services {
pub(crate) fn register_metrics(self: &Arc<Self>) {
self.gauge(
"continuwuity.sender.queue.depth",
"Messages waiting in the sender worker channels",
"{message}",
|services, observer| {
observe(observer, services.sending.queue_depth(), &[]);
},
);
self.gauge(
"continuwuity.federation.incoming.transactions.active",
"Incoming federation transactions currently being processed",
"{transaction}",
|services, observer| {
observe(observer, services.transactions.txn_active_handle_count(), &[]);
},
);
self.gauge(
"continuwuity.users",
"Estimated known users, local including deactivated",
"{user}",
|services, observer| {
for (map, origin) in
[("userid_password", "local"), ("remoteuserid_remoteuser", "remote")]
{
if let Some(keys) = estimate_keys(services, map) {
observer.observe(keys, &[KeyValue::new("origin", origin)]);
}
}
},
);
self.gauge(
"continuwuity.media.files",
"Estimated stored media files including thumbnails",
"{file}",
|services, observer| {
if let Some(keys) = estimate_keys(services, "mediaid_file") {
observer.observe(keys, &[]);
}
},
);
self.gauge(
"continuwuity.federation.destinations",
"Remote servers in retry backoff or with a stale destination cache entry",
"{server}",
|services, observer| {
let now = millis_since_unix_epoch();
let backoff = services
.federation
.remote_health
.read()
.values()
.filter(|&&(_, next_retry)| now < next_retry)
.count();
let stale = services.federation.stale_destinations.read().len();
observe(observer, backoff, &[KeyValue::new("state", "backoff")]);
observe(observer, stale, &[KeyValue::new("state", "stale")]);
},
);
self.gauge(
"continuwuity.database.memory",
"RocksDB memory usage by component",
"By",
|services, observer| {
let Ok(usage) = services.db.db.memory_usage_stats() else {
return;
};
for (name, bytes) in [
("mem_tables", usage.mem_table_total),
("mem_tables_unflushed", usage.mem_table_unflushed),
("table_readers", usage.mem_table_readers_total),
("row_cache", usage.row_cache),
] {
observer.observe(bytes, &[KeyValue::new("name", name)]);
}
},
);
self.gauge(
"continuwuity.database.block_cache",
"RocksDB block cache usage by column family",
"By",
|services, observer| {
let Ok(col_caches) = services.db.db.col_cache_usage() else {
return;
};
for (column, bytes) in col_caches {
observer.observe(bytes, &[KeyValue::new("column", column)]);
}
},
);
self.gauge(
"continuwuity.database.size",
"Total size of RocksDB SST files",
"By",
|services, observer| {
let size = services
.db
.iter()
.filter_map(|(_, map)| {
map.property_integer(c"rocksdb.total-sst-files-size").ok()
})
.fold(0_u64, u64::saturating_add);
observer.observe(size, &[]);
},
);
self.gauge(
"continuwuity.cache.entries",
"Entries held in in-memory caches",
"{entry}",
|services, observer| {
let (auth_chain, _) = services.rooms.auth_chain.get_cache_usage();
let stateinfo = services.rooms.state_compressor.stateinfo_cache.lock().len();
observe(observer, auth_chain, &[KeyValue::new("name", "auth_chain")]);
observe(observer, stateinfo, &[KeyValue::new("name", "stateinfo")]);
},
);
}
fn gauge<F>(
self: &Arc<Self>,
name: &'static str,
description: &'static str,
unit: &'static str,
callback: F,
) where
F: Fn(&Self, &dyn AsyncInstrument<u64>) + Send + Sync + 'static,
{
let services = Arc::downgrade(self);
self.server
.metrics
.meter
.u64_observable_gauge(name)
.with_description(description)
.with_unit(unit)
.with_callback(move |observer| {
if let Some(services) = services.upgrade() {
callback(&services, observer);
}
})
.build();
}
}
/// Cheap estimate from RocksDB properties, unlike iterating the column.
fn estimate_keys(services: &Services, map: &'static str) -> Option<u64> {
services
.db
.get(map)
.ok()?
.property_integer(c"rocksdb.estimate-num-keys")
.ok()
}
fn observe(observer: &dyn AsyncInstrument<u64>, value: usize, attributes: &[KeyValue]) {
if let Ok(value) = value.try_into() {
observer.observe(value, attributes);
}
}
+35 -2
View File
@@ -22,7 +22,8 @@ use database::Json;
use futures::{FutureExt, StreamExt, TryStreamExt};
use itertools::Itertools;
use ruma::{
OwnedEventId, OwnedRoomId, OwnedUserId, UserId,
OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedUserId, UserId,
api::OAuthClientScope,
events::{
AnyStrippedStateEvent, GlobalAccountDataEventType, StateEventType,
push_rules::PushRulesEvent,
@@ -31,7 +32,7 @@ use ruma::{
push::Ruleset,
serde::{Raw, from_raw_json_value},
};
use serde_json::value::to_raw_value;
use serde_json::{Value, value::to_raw_value};
use crate::{Services, media, rooms, rooms::short::ShortStateHash};
@@ -160,6 +161,10 @@ migration!(stringify!($name) => $name)
// This is backwards compatible because old versions will recreate the keyspace if it's
// missing.
migration!(drop_server_signingkeys),
// v22: Old versions will fail to deserialize the fixed OAuth scope names,
// preventing users from signing in.
VersionBump(22),
migration!(fix_oauth_scope_names),
]
};
@@ -944,3 +949,31 @@ async fn drop_server_signingkeys(services: &Services) -> Result<()> {
Ok(())
}
async fn fix_oauth_scope_names(services: &Services) -> Result {
let db = &services.db;
let userdeviceid_oauthsessioninfo = db["userdeviceid_oauthsessioninfo"].clone();
userdeviceid_oauthsessioninfo
.stream::<(OwnedUserId, OwnedDeviceId), Value>()
.ignore_err()
.for_each(async |((user_id, device_id), mut session_info)| {
let map = session_info.as_object_mut().unwrap();
let scopes = map.get_mut("scopes").unwrap().as_array_mut().unwrap();
if let Some(old_scope_index) = scopes
.iter()
.position(|value| *value == Value::String("ClientApi".to_owned()))
{
scopes[old_scope_index] =
Value::String(OAuthClientScope::ApiFullAccess.to_string());
}
userdeviceid_oauthsessioninfo.put((user_id, device_id), Json(session_info));
})
.await;
info!("Fixed OAuth session scope names");
Ok(())
}
Loaded 100 of 136 files, more files were not shown because too many files have changed in this diff. Show more