Compare commits

..

93 Commits

Author SHA1 Message Date
strawberry 42e3567153 disable overflow-checks for performance
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 02:18:24 -04:00
strawberry 75ad5cfbb7 bump conduwuit version to 0.3.1
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 02:12:34 -04:00
strawberry be5101b07c bump console-subscriber to 0.2
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 02:12:34 -04:00
strawberry c531101657 misc docs adjustments
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 761263332b ci: push to gitlab container registry too
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 5fe146aa85 docs: update differences.md
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry d7399a12fb config: split at __ for struct sections of config, add couple missing settings for show-config
this makes `CONDUWUIT_WELL_KNOWN__CLIENT` a valid env variable config
option as it would normally exist under `[well_known.client]` in toml

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 7e2a15497c use function comments for lsp here
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry e226046e15 drop default appservice_timeout to 35 seconds
AS's are generally hosted on the same machine or within the same
network

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 75b9332917 dont allow creating remote users in admin room
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry de26bf22dc adjust a couple error codes for room alias getting
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry a7c14a861b ci: output complement diff results to job summary, temp allow error
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 05b7dec482 temp(ci): comment complement results diff for now
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 38ca88da9f ci(gitlab): use --no-strip for cargo deb
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 2e5ba7ab17 ci(gitlab): use gitlab fastzip feature flag
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 35683d66dd sort the complement results by test name for consistent output
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry e1052d1829 chore: update checked-in complement test results
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 49078aa836 fix: get the presence of the requested user instead of ourselves
after getting the shared rooms with the target user, we actually only
get the presence of ourselves instead of the requested user

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry b6b739a7b7 set -vet=off to (hopefully) run all complement tests
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry fa0bdd431b add destination to X-Matrix Authorization outbound requests
we were already validating this for inbound requests

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry a6cf5cfd8b remove future deleted nix binary cache
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 37c2877cf8 chore: update checked in list of complement test results
also remove the separated passed/failed list, it's already ordered
neatly for folks to read.

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 1181a7a7a9 nix: specify explicit branches/refs for flake inputs
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry cad16b9268 ci, nix: build and cache all packages and CI dependencies
from https://or.computer.surgery/charles/matrix/-/commit/f5bd9bc45e5e5eaf76cff31f1c259ed3f39fb88a
with changes for GitHub CI and misc

Co-authored-by: Charles Hall <charles@computer.surgery>
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 3b410d0556 ci: run complement with direnv
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 28f599236a ci: compare complement results with checked-in results
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 365c85ad27 use nix-output-monitor if available
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 13f1274c35 run complement in CI (does not compare results yet)
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry c4beb7d462 dont return "Allocator" header for server memory-usage if empty
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 0f13ada300 return more user-friendly message for debug memory-stats
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry a7f8c848aa refactor and simplify room creation route a bit
removes a couple unnecessary checks, uses our room_id ruma request field

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 25bc1f069d chore: bump deps
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 0223386243 remove this unnecessary log, use debug_warn
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry a496cc4705 dedupe version getting code, rename to CONDUWUIT_VERSION_EXTRA
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 8ec9372a8e lint
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
Charles Hall a01a7e1219 improve "Leave event has no state" log
To include the user, room, and event ID.

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry db81ffb4ea nix: only set CONDUIT_VERSION_EXTRA for final build + slight cleanup
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 096c252dc2 move hierarchy via servers higher up, add some debug logging to it
this entire thing needs to be cleaned up later, but i need spaces
to work

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 1464b30433 add workaround for room creation initial_state event content as {}, slight refactor
this will simply skip over the events

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
Jason Volk 3585e8a2ef rename / simplify tester stub for now
Signed-off-by: Jason Volk <jason@zemos.net>
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
Jason Volk b19d2ad5b0 daily logging improvements
Signed-off-by: Jason Volk <jason@zemos.net>
2024-05-03 01:52:29 -04:00
Jason Volk 8ecf722abb split http serving from main.
Signed-off-by: Jason Volk <jason@zemos.net>
2024-05-03 01:52:29 -04:00
Jason Volk 5d76db8f19 add configuration for rocksdb direct-io enablement
Signed-off-by: Jason Volk <jason@zemos.net>
2024-05-03 01:52:29 -04:00
strawberry f4a2b39d55 split up alias.rs a bit (alias checks and room alias server name stuff)
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry e00b65b0e0 use ok_or_else instead of ok_or for backup.rs
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry beeacd4ef1 initialise capabilities with default constructor
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry e5735c81ed dedupe half of account/room data config.rs code
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry b17ccdadd2 dedupe some code in state.rs
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 8e3918250d rm complement test logs, rm docker healthcheck.sh, rm .vscode/ dir, move test results to tests/ dir
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 6021cb0a1f partially revert this
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 35114dde7d add query_over_tcp_only config option for hickory
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 62fd6e2c7c set AD bit to false in hickory
this is purely DNSSEC related which we don't use, and DNSSEC on matrix
is unbearable for federation (no one sets it up properly, it's extremely taxing, etc)

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 668a7645e9 add ip_lookup_strategy config option for hickory resolver
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 3f8407dd64 add hot_lib to default.nix src include
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry b8c4d6b157 bump ruma
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 0b39bb813e tiny refactoring, split out report_event_route a bit
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry d32ea6ec20 cargo doc lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 041a7a90f3 hot lib things again
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 9c0c4c292c document hot_lib for developers a bit
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry ed86a4aa9e slight misc adjustments
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry b282c1eb6d add (probably messy) support for hot lib reload via admin command
`!admin test test1`

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 76c5942b4f use user_is_local and server_is_ours more, remove few double filters
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry e7505a4b20 resolve ptr_as_ptr lint
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry a97520b0e9 bump MSRV to 1.76.0
there's really no point in trying to stay as low as possible for us,
and this makes development easier. Debian users should just use rustup,
Nix users already get the proper toolchains.

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 9931e60050 use single global function for server name local and user local checking
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 8f17d965b2 use <pre> for codeblock formatting in jemalloc stats, link to ffi func
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
Jason Volk 9f5d7b0761 fix mallctl suite lints
Signed-off-by: Jason Volk <jason@zemos.net>
2024-05-03 01:52:29 -04:00
Charles Hall 4faf690f57 run clippy on default, all, and allocator features
This way all 4 major configurations are linted.
2024-05-03 01:52:29 -04:00
Charles Hall 838550536a reflow clippy in engage file 2024-05-03 01:52:29 -04:00
Charles Hall 3b05417246 handle the case where 0 or >1 allocs are enabled
In particular this fixes `cargo build --all-features`.
2024-05-03 01:52:29 -04:00
Charles Hall e0c0d51a05 fix lints 2024-05-03 01:52:29 -04:00
Jason Volk e4b669360f start mallctl suite w/ jemalloc stats
Signed-off-by: Jason Volk <jason@zemos.net>
2024-05-03 01:52:29 -04:00
Jason Volk 56f652c12d cleanup admin worker loop
Signed-off-by: Jason Volk <jason@zemos.net>
2024-05-03 01:52:29 -04:00
Jason Volk 4b6938e0f6 add admin server uptime command
Signed-off-by: Jason Volk <jason@zemos.net>
2024-05-03 01:52:29 -04:00
Benjamin Lee 781d4b7907 document tracing_flame options in example config 2024-05-03 01:52:29 -04:00
Benjamin Lee 56f1e905de add config option tracing_flame_output_path
Hardcoding the output path to something in CWD is a pain if you're running
conduwuit through systemd or similar. Also made the error message when
it's unable to create the output file a little more friendly.
2024-05-03 01:52:29 -04:00
Benjamin Lee 646b31d2bd flush tracing-flame output file on exit
Previously we were dropping the flush guard early, possibly causing
samples to be lost on exit.
2024-05-03 01:52:29 -04:00
Benjamin Lee 7d92515b1d add tracing_flame_filter config option
The previous hardcoded filter `trace,h2=off` isn't appropriate in all
cases, it's better to have this be configurable.
2024-05-03 01:52:29 -04:00
Benjamin Lee cc578d9a67 keep stdout logs when tracing-flame/jaeger is enabled
Previously, enabling the `tracing_flame` or `allow_jaeger` options would
prevent any logs from being written to stdout. In addition, enabling the
`allow_jaeger` option would inhibit the `tracing_flame` option.

Now that we have a way to use separate tracing filters with different
layers, we can enable all three at the same time without issues.

This commit also prevents the `debug log_level` command from modifying
the `tracing-flame` filter. This was supported previously, but I don't
think it's something that you would ever want to do intentionally. Now
that we have both the normal log filter and the `tracing-flame` filter
enabled at the same time, we want to `debug log_level` to only modify the
normal filter.
2024-05-03 01:52:29 -04:00
strawberry bf713cd0ba lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 61f813c187 admin command to get rooms a remote user is in, remove unnecessary dedupe+sort
imagine this SQL query but in conduwuit:

select * from users_in_public_rooms where user_id like '%user_id%';

Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 450f15df4f admin debug command to fetch a server's true destination
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 1cbf2bdc6b update dns_cache_entries example config setting
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
Jason Volk b4035bf0da increase default dns cache entries
Signed-off-by: Jason Volk <jason@zemos.net>
2024-05-03 01:52:29 -04:00
Jason Volk 37ecb4f2b9 decrease log verbosity for potentially cached NoRecordsFound
Signed-off-by: Jason Volk <jason@zemos.net>
2024-05-03 01:52:29 -04:00
Jason Volk daf4b56435 fix inherited sequential small options
Signed-off-by: Jason Volk <jason@zemos.net>
2024-05-03 01:52:29 -04:00
strawberry 799b2909ab ci: dont run registry pushes if creds are not set
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 614ef5b3a1 raise dns_min_ttl_nxdomain back to 3 days
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry cfa89b8b64 add remaining other rocksdb compression options
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 9f245281b1 never allow only 1 tokio worker or rocksdb parallelism thread (max compare)
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry d172a6883d bump some deps
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
strawberry 04afc83043 switch to my fork of tracing
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-05-03 01:52:29 -04:00
Benjamin Lee 8a5599adf9 add optional support for tokio-console
This turned out to be quite hairy, mostly because we need to apply the
config's log level filter to the actual logs (stdout and, optionally
sentry), but do not want to filter out the tokio tracing events needed by
the console_subscriber. I hit several edge cases in tracing getting
this to work, and we now depend on a git version of tracing with a
backported patch :(
2024-05-03 01:52:29 -04:00
85 changed files with 3186 additions and 41540 deletions
+79 -11
View File
@@ -53,7 +53,7 @@ jobs:
- name: Enable Cachix binary cache
run: |
nix-env -iA cachix -f https://cachix.org/api/v1/install
nix profile install nixpkgs#cachix
cachix use crane
cachix use nix-community
@@ -63,8 +63,8 @@ jobs:
- name: Apply Nix binary cache configuration
run: |
sudo tee -a /etc/nix/nix.conf > /dev/null <<EOF
extra-substituters = https://nix.computer.surgery/conduit https://attic.kennel.juneis.dog/conduit https://attic.kennel.juneis.dog/conduwuit
extra-trusted-public-keys = conduit:ZGAf6P6LhNvnoJJ3Me3PRg7tlLSrPxcQ2RiE5LIppjo= conduit:Isq8FGyEC6FOXH6nD+BOeAA+bKp6X6UIbupSlGEPuOg= conduwuit:lYPVh7o1hLu1idH4Xt2QHaRa49WRGSAqzcfFd94aOTw=
extra-substituters = https://attic.kennel.juneis.dog/conduit https://attic.kennel.juneis.dog/conduwuit
extra-trusted-public-keys = conduit:Isq8FGyEC6FOXH6nD+BOeAA+bKp6X6UIbupSlGEPuOg= conduwuit:lYPVh7o1hLu1idH4Xt2QHaRa49WRGSAqzcfFd94aOTw=
EOF
- name: Use alternative Nix binary caches if specified
@@ -78,7 +78,7 @@ jobs:
- name: Prepare build environment
run: |
echo 'source $HOME/.nix-profile/share/nix-direnv/direnvrc' > "$HOME/.direnvrc"
nix-env -f "<nixpkgs>" -iA direnv -iA nix-direnv
nix profile install --impure --inputs-from . nixpkgs#direnv nixpkgs#nix-direnv
direnv allow
nix develop --command true
@@ -86,6 +86,43 @@ jobs:
run: |
direnv exec . engage > >(tee -a test_output.log)
- name: Sync Complement repository
uses: actions/checkout@v4
with:
repository: 'matrix-org/complement'
path: complement_src
- name: Run Complement tests
run: |
direnv exec . bin/complement 'complement_src' 'complement_test_logs.jsonl' 'complement_test_results.jsonl'
- name: Upload Complement logs
uses: actions/upload-artifact@v4
with:
name: complement_test_logs.jsonl
path: complement_test_logs.jsonl
if-no-files-found: error
- name: Upload Complement results
uses: actions/upload-artifact@v4
with:
name: complement_test_results.jsonl
path: complement_test_results.jsonl
if-no-files-found: error
- name: Diff Complement results with checked-in repo results
# TODO: figure out why our complement results are not 100% consistent so we don't need to allow failures
continue-on-error: true
run: |
diff -u --color=always complement_test_results.jsonl tests/test_results/complement/test_results.jsonl > >(tee -a complement_test_output.log)
- name: Add Complement diff result to Job Summary
run: |
echo '# Complement diff results' >> $GITHUB_STEP_SUMMARY
echo '```diff' >> $GITHUB_STEP_SUMMARY
tail -n 50 complement_test_output.log | sed 's/\x1b\[[0-9;]*m//g' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Update Job Summary
if: success() || failure()
run: |
@@ -116,9 +153,9 @@ jobs:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- name: Enable Cachix binary cache
- name: Install and enable Cachix binary cache
run: |
nix-env -iA cachix -f https://cachix.org/api/v1/install
nix profile install nixpkgs#cachix
cachix use crane
cachix use nix-community
@@ -128,8 +165,8 @@ jobs:
- name: Apply Nix binary cache configuration
run: |
sudo tee -a /etc/nix/nix.conf > /dev/null <<EOF
extra-substituters = https://nix.computer.surgery/conduit https://attic.kennel.juneis.dog/conduit https://attic.kennel.juneis.dog/conduwuit
extra-trusted-public-keys = conduit:ZGAf6P6LhNvnoJJ3Me3PRg7tlLSrPxcQ2RiE5LIppjo= conduit:Isq8FGyEC6FOXH6nD+BOeAA+bKp6X6UIbupSlGEPuOg= conduwuit:lYPVh7o1hLu1idH4Xt2QHaRa49WRGSAqzcfFd94aOTw=
extra-substituters = https://attic.kennel.juneis.dog/conduit https://attic.kennel.juneis.dog/conduwuit
extra-trusted-public-keys = conduit:Isq8FGyEC6FOXH6nD+BOeAA+bKp6X6UIbupSlGEPuOg= conduwuit:lYPVh7o1hLu1idH4Xt2QHaRa49WRGSAqzcfFd94aOTw=
EOF
- name: Use alternative Nix binary caches if specified
@@ -143,13 +180,13 @@ jobs:
- name: Prepare build environment
run: |
echo 'source $HOME/.nix-profile/share/nix-direnv/direnvrc' > "$HOME/.direnvrc"
nix-env -f "<nixpkgs>" -iA direnv -iA nix-direnv
nix profile install --impure --inputs-from . nixpkgs#direnv nixpkgs#nix-direnv
direnv allow
nix develop --command true
- name: Build static ${{ matrix.target }}
run: |
bin/nix-build-and-cache .#static-${{ matrix.target }}
bin/nix-build-and-cache just .#static-${{ matrix.target }}
mkdir -p target/release
cp -v -f result/bin/conduit target/release/
direnv exec . cargo deb --no-build --no-strip --output target/debian/${{ matrix.target }}.deb
@@ -171,7 +208,7 @@ jobs:
- name: Build OCI image ${{ matrix.target }}
run: |
bin/nix-build-and-cache .#oci-image-${{ matrix.target }}
bin/nix-build-and-cache just .#oci-image-${{ matrix.target }}
cp -v -f result oci-image-${{ matrix.target }}.tar.gz
- name: Upload OCI image ${{ matrix.target }}
@@ -196,6 +233,12 @@ jobs:
GHCR_AMD64: ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-amd64
GHCR_TAG: ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}
GHCR_BRANCH: ghcr.io/${{ github.repository }}:${{ (github.ref == 'refs/heads/main' && 'latest') || github.ref_name }}
GLCR_ARM64: registry.gitlab.com/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-arm64v8
GLCR_AMD64: registry.gitlab.com/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}-amd64
GLCR_TAG: registry.gitlab.com/${{ github.repository }}:${{ github.ref_name }}-${{ github.sha }}
GLCR_BRANCH: registry.gitlab.com/${{ github.repository }}:${{ (github.ref == 'refs/heads/main' && 'latest') || github.ref_name }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
@@ -205,12 +248,21 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
if: ${{ (vars.DOCKER_USERNAME != '') && (env.DOCKERHUB_TOKEN != '') }}
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitLab Container Registry
if: ${{ (vars.GITLAB_USERNAME != '') && (env.GITLAB_TOKEN != '') }}
uses: docker/login-action@v3
with:
registry: registry.gitlab.com
username: ${{ vars.GITLAB_USERNAME }}
password: ${{ secrets.GITLAB_TOKEN }}
- name: Download artifacts
uses: actions/download-artifact@v4
@@ -220,36 +272,52 @@ jobs:
mv oci-image-aarch64-*-jemalloc/*.tar.gz oci-image-arm64v8.tar.gz
- name: Load and push amd64 image
if: ${{ (vars.DOCKER_USERNAME != '') && (env.DOCKERHUB_TOKEN != '') }}
run: |
docker load -i oci-image-amd64.tar.gz
docker tag $(docker images -q conduit:main) ${{ env.DOCKER_AMD64 }}
docker tag $(docker images -q conduit:main) ${{ env.GHCR_AMD64 }}
docker tag $(docker images -q conduit:main) ${{ env.GLCR_AMD64 }}
docker push ${{ env.DOCKER_AMD64 }}
docker push ${{ env.GHCR_AMD64 }}
docker push ${{ env.GLCR_AMD64 }}
- name: Load and push arm64 image
if: ${{ (vars.DOCKER_USERNAME != '') && (env.DOCKERHUB_TOKEN != '') }}
run: |
docker load -i oci-image-arm64v8.tar.gz
docker tag $(docker images -q conduit:main) ${{ env.DOCKER_ARM64 }}
docker tag $(docker images -q conduit:main) ${{ env.GHCR_ARM64 }}
docker tag $(docker images -q conduit:main) ${{ env.GLCR_ARM64 }}
docker push ${{ env.DOCKER_ARM64 }}
docker push ${{ env.GHCR_ARM64 }}
docker push ${{ env.GLCR_ARM64 }}
- name: Create Docker combined manifests
run: |
# Dockerhub Container Registry
docker manifest create ${{ env.DOCKER_TAG }} --amend ${{ env.DOCKER_ARM64 }} --amend ${{ env.DOCKER_AMD64 }}
docker manifest create ${{ env.DOCKER_BRANCH }} --amend ${{ env.DOCKER_ARM64 }} --amend ${{ env.DOCKER_AMD64 }}
# GitHub Container Registry
docker manifest create ${{ env.GHCR_TAG }} --amend ${{ env.GHCR_ARM64 }} --amend ${{ env.GHCR_AMD64 }}
docker manifest create ${{ env.GHCR_BRANCH }} --amend ${{ env.GHCR_ARM64 }} --amend ${{ env.GHCR_AMD64 }}
# GitLab Container Registry
docker manifest create ${{ env.GLCR_TAG }} --amend ${{ env.GLCR_ARM64 }} --amend ${{ env.GCCR_AMD64 }}
docker manifest create ${{ env.GLCR_BRANCH }} --amend ${{ env.GLCR_ARM64 }} --amend ${{ env.GLCR_AMD64 }}
- name: Push manifests to Docker registries
if: ${{ (vars.DOCKER_USERNAME != '') && (env.DOCKERHUB_TOKEN != '') }}
run: |
docker manifest push ${{ env.DOCKER_TAG }}
docker manifest push ${{ env.DOCKER_BRANCH }}
docker manifest push ${{ env.GHCR_TAG }}
docker manifest push ${{ env.GHCR_BRANCH }}
docker manifest push ${{ env.GLCR_TAG }}
docker manifest push ${{ env.GLCR_BRANCH }}
- name: Add Image Links to Job Summary
if: ${{ (vars.DOCKER_USERNAME != '') && (env.DOCKERHUB_TOKEN != '') }}
run: |
echo "- \`docker pull ${{ env.DOCKER_TAG }}\`" >> $GITHUB_STEP_SUMMARY
echo "- \`docker pull ${{ env.GHCR_TAG }}\`" >> $GITHUB_STEP_SUMMARY
echo "- \`docker pull ${{ env.GLCR_TAG }}\`" >> $GITHUB_STEP_SUMMARY
+3 -5
View File
@@ -58,8 +58,6 @@ jobs:
extra-trusted-public-keys = nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=
extra-substituters = https://crane.cachix.org
extra-trusted-public-keys = crane.cachix.org-1:8Scfpmn9w+hGdXH/Q9tTLiYAE/2dnJYRJP7kl80GuRk=
extra-substituters = https://nix.computer.surgery/conduit
extra-trusted-public-keys = conduit:ZGAf6P6LhNvnoJJ3Me3PRg7tlLSrPxcQ2RiE5LIppjo=
extra-substituters = https://attic.kennel.juneis.dog/conduit
extra-trusted-public-keys = conduit:Isq8FGyEC6FOXH6nD+BOeAA+bKp6X6UIbupSlGEPuOg=
extra-substituters = https://attic.kennel.juneis.dog/conduwuit
@@ -88,13 +86,13 @@ jobs:
- name: Allow direnv
run: direnv allow
- name: Cache x86_64 inputs for devShell
- name: Cache CI dependencies
run: |
./bin/nix-build-and-cache .#devShells.x86_64-linux.default.inputDerivation
./bin/nix-build-and-cache ci
- name: Build documentation (book)
run: |
./bin/nix-build-and-cache .#book
./bin/nix-build-and-cache just .#book
cp -r --dereference result public
- name: Upload generated documentation (book) as normal artifact
uses: actions/upload-artifact@v4
+6
View File
@@ -81,8 +81,14 @@ public/
# macOS
.DS_Store
# VS Code
.vscode/
# Zed
.zed/
# idk where you're coming from, but i'm tired of you
rustc-ice-*
# complement test logs are huge
tests/test_results/complement/test_logs.jsonl
+12 -55
View File
@@ -6,6 +6,10 @@ stages:
variables:
# Makes some things print in color
TERM: ansi
# Faster cache and artifact compression / decompression
FF_USE_FASTZIP: true
# Print progress reports for cache and artifact transfers
TRANSFER_METER_FREQUENCY: 5s
# Avoid duplicate pipelines
# See: https://docs.gitlab.com/ee/ci/yaml/workflow.html#switch-between-branch-pipelines-and-merge-request-pipelines
@@ -27,10 +31,6 @@ before_script:
- if command -v nix > /dev/null; then echo "extra-substituters = https://attic.kennel.juneis.dog/conduit" >> /etc/nix/nix.conf; fi
- if command -v nix > /dev/null; then echo "extra-trusted-public-keys = conduit:Isq8FGyEC6FOXH6nD+BOeAA+bKp6X6UIbupSlGEPuOg=" >> /etc/nix/nix.conf; fi
# Add upstream Conduit binary cache
- if command -v nix > /dev/null; then echo "extra-substituters = https://nix.computer.surgery/conduit" >> /etc/nix/nix.conf; fi
- if command -v nix > /dev/null; then echo "extra-trusted-public-keys = conduit:ZGAf6P6LhNvnoJJ3Me3PRg7tlLSrPxcQ2RiE5LIppjo=" >> /etc/nix/nix.conf; fi
# Add alternate binary cache
- if command -v nix > /dev/null && [ -n "$ATTIC_ENDPOINT" ]; then echo "extra-substituters = $ATTIC_ENDPOINT" >> /etc/nix/nix.conf; fi
- if command -v nix > /dev/null && [ -n "$ATTIC_PUBLIC_KEY" ]; then echo "extra-trusted-public-keys = $ATTIC_PUBLIC_KEY" >> /etc/nix/nix.conf; fi
@@ -56,8 +56,8 @@ ci:
stage: ci
image: nixos/nix:2.22.0
script:
# Cache the inputs required for the devShell
- ./bin/nix-build-and-cache .#devShells.x86_64-linux.default.inputDerivation
# Cache CI dependencies
- ./bin/nix-build-and-cache ci
- direnv exec . engage
cache:
@@ -81,12 +81,12 @@ artifacts:
stage: artifacts
image: nixos/nix:2.22.0
script:
- ./bin/nix-build-and-cache .#static-x86_64-unknown-linux-musl
- ./bin/nix-build-and-cache just .#static-x86_64-unknown-linux-musl
- cp result/bin/conduit x86_64-unknown-linux-musl
- mkdir -p target/release
- cp result/bin/conduit target/release
- direnv exec . cargo deb --no-build
- direnv exec . cargo deb --no-build --no-strip
- mv target/debian/*.deb x86_64-unknown-linux-musl.deb
# Since the OCI image package is based on the binary package, this has the
@@ -97,16 +97,16 @@ artifacts:
# Note that although we have an `oci-image-x86_64-unknown-linux-musl`
# output, we don't build it because it would be largely redundant to this
# one since it's all containerized anyway.
- ./bin/nix-build-and-cache .#oci-image
- ./bin/nix-build-and-cache just .#oci-image
- cp result oci-image-amd64.tar.gz
- ./bin/nix-build-and-cache .#static-aarch64-unknown-linux-musl
- ./bin/nix-build-and-cache just .#static-aarch64-unknown-linux-musl
- cp result/bin/conduit aarch64-unknown-linux-musl
- ./bin/nix-build-and-cache .#oci-image-aarch64-unknown-linux-musl
- ./bin/nix-build-and-cache just .#oci-image-aarch64-unknown-linux-musl
- cp result oci-image-arm64v8.tar.gz
- ./bin/nix-build-and-cache .#book
- ./bin/nix-build-and-cache just .#book
# We can't just copy the symlink, we need to dereference it https://gitlab.com/gitlab-org/gitlab/-/issues/19746
- cp -r --dereference result public
artifacts:
@@ -127,49 +127,6 @@ artifacts:
- if: $CI
interruptible: true
.push-oci-image:
stage: publish
image: docker:26.0.2
services:
- docker:26.0.2-dind
variables:
IMAGE_SUFFIX_AMD64: amd64
IMAGE_SUFFIX_ARM64V8: arm64v8
script:
- docker load -i oci-image-amd64.tar.gz
- IMAGE_ID_AMD64=$(docker images -q conduit:main)
- docker load -i oci-image-arm64v8.tar.gz
- IMAGE_ID_ARM64V8=$(docker images -q conduit:main)
# Tag and push the architecture specific images
- docker tag $IMAGE_ID_AMD64 $IMAGE_NAME:$CI_COMMIT_SHA-$IMAGE_SUFFIX_AMD64
- docker tag $IMAGE_ID_ARM64V8 $IMAGE_NAME:$CI_COMMIT_SHA-$IMAGE_SUFFIX_ARM64V8
- docker push $IMAGE_NAME:$CI_COMMIT_SHA-$IMAGE_SUFFIX_AMD64
- docker push $IMAGE_NAME:$CI_COMMIT_SHA-$IMAGE_SUFFIX_ARM64V8
# Tag the multi-arch image
- docker manifest create $IMAGE_NAME:$CI_COMMIT_SHA --amend $IMAGE_NAME:$CI_COMMIT_SHA-$IMAGE_SUFFIX_AMD64 --amend $IMAGE_NAME:$CI_COMMIT_SHA-$IMAGE_SUFFIX_ARM64V8
- docker manifest push $IMAGE_NAME:$CI_COMMIT_SHA
# Tag and push the git ref
- docker manifest create $IMAGE_NAME:$CI_COMMIT_REF_NAME --amend $IMAGE_NAME:$CI_COMMIT_SHA-$IMAGE_SUFFIX_AMD64 --amend $IMAGE_NAME:$CI_COMMIT_SHA-$IMAGE_SUFFIX_ARM64V8
- docker manifest push $IMAGE_NAME:$CI_COMMIT_REF_NAME
# Tag git tags as 'latest'
- |
if [[ -n "$CI_COMMIT_TAG" ]]; then
docker manifest create $IMAGE_NAME:latest --amend $IMAGE_NAME:$CI_COMMIT_SHA-$IMAGE_SUFFIX_AMD64 --amend $IMAGE_NAME:$CI_COMMIT_SHA-$IMAGE_SUFFIX_ARM64V8
docker manifest push $IMAGE_NAME:latest
fi
dependencies:
- artifacts
only:
- main
- tags
oci-image:push-gitlab:
extends: .push-oci-image
variables:
IMAGE_NAME: $CI_REGISTRY_IMAGE/conduwuit
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
pages:
stage: publish
dependencies:
-11
View File
@@ -1,11 +0,0 @@
{
"recommendations": [
"rust-lang.rust-analyzer",
"editorconfig.editorconfig",
"ms-azuretools.vscode-docker",
"eamodio.gitlens",
"serayuzgur.crates",
"vadimcn.vscode-lldb",
"timonwong.shellcheck"
]
}
-35
View File
@@ -1,35 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug conduit",
"sourceLanguages": ["rust"],
"cargo": {
"args": [
"build",
"--bin=conduit",
"--package=conduit"
],
"filter": {
"name": "conduit",
"kind": "bin"
}
},
"args": [],
"env": {
"RUST_BACKTRACE": "1",
"CONDUIT_DATABASE_PATH": "/tmp/awawawa",
"CONDUIT_ADDRESS": "0.0.0.0",
"CONDUIT_PORT": "55551",
"CONDUIT_SERVER_NAME": "your.server.name",
"CONDUIT_LOG": "debug"
},
"cwd": "${workspaceFolder}"
}
]
}
Generated
+572 -341
View File
File diff suppressed because it is too large Load Diff
+40 -20
View File
@@ -10,15 +10,17 @@ authors = [
homepage = "https://conduwuit.puppyirl.gay/"
repository = "https://github.com/girlbossceo/conduwuit"
readme = "README.md"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
# See also `rust-toolchain.toml`
rust-version = "1.75.0"
rust-version = "1.76.0"
[dependencies]
hot-lib-reloader = { version = "^0.6", optional = true }
console-subscriber = { version = "0.2", optional = true }
# for hot lib reload
hot-lib-reloader = { version = "^0.7", optional = true }
# Used for secure identifiers
rand = "0.8.5"
@@ -27,7 +29,7 @@ rand = "0.8.5"
thiserror = "1.0.59"
# Used to encode server public key
base64 = "0.22.0"
base64 = "0.22.1"
# Used when hashing the state
ring = "0.17.8"
@@ -54,9 +56,6 @@ sha-1 = "0.10.1"
# used for checking if an IP is in specific subnets / CIDR ranges easier
ipaddress = "0.1.3"
# to encode/decode percent URIs when conduwuit is running without a reverse proxy
#urlencoding = "2.1.3"
# to get the client IP address of requests
#axum-client-ip = "0.4.2"
@@ -73,14 +72,12 @@ http-body-util = "0.1.1"
loole = "0.3.0"
# Validating urls in config, was already a transitive dependency
url = { version = "2", features = ["serde"] }
url = { version = "2.5.0", features = ["serde"] }
async-trait = "0.1.80"
lru-cache = "0.1.2"
proc-macro2 = "=1.0.79"
# standard date and time tools
[dependencies.chrono]
version = "0.4.38"
@@ -132,7 +129,7 @@ features = ["rustls-tls-native-roots", "socks", "hickory-dns"]
# all the serde stuff
# Used for pdu definition
[dependencies.serde]
version = "1.0.198"
version = "1.0.200"
features = ["rc"]
# Used for appservice registration files
[dependencies.serde_yaml]
@@ -215,11 +212,16 @@ version = "0.32.3"
optional = true
# optional jemalloc usage
[dependencies.tikv-jemalloc-sys]
version = "0.5.4"
optional = true
default-features = false
features = ["stats", "unprefixed_malloc_on_supported_platforms"]
[dependencies.tikv-jemallocator]
version = "0.5.4"
optional = true
default-features = false
features = ["unprefixed_malloc_on_supported_platforms"]
features = ["stats", "unprefixed_malloc_on_supported_platforms"]
[dependencies.tikv-jemalloc-ctl]
version = "0.5.4"
optional = true
@@ -338,6 +340,18 @@ hardened_malloc-rs = { version = "0.1.2", optional = true, features = [
#hardened_malloc-rs = { optional = true, features = ["static","clang","light"], path = "../hardened_malloc-rs", default-features = false }
# backport of [https://github.com/tokio-rs/tracing/pull/2956] to the 0.1.x branch of tracing.
# we can switch back to upstream if #2956 is merged and backported in the upstream repo.
[patch.crates-io.tracing-subscriber]
git = "https://github.com/girlbossceo/tracing"
branch = "tracing-subscriber/env-filter-clone-0.1.x-backport"
[patch.crates-io.tracing]
git = "https://github.com/girlbossceo/tracing"
branch = "tracing-subscriber/env-filter-clone-0.1.x-backport"
[patch.crates-io.tracing-core]
git = "https://github.com/girlbossceo/tracing"
branch = "tracing-subscriber/env-filter-clone-0.1.x-backport"
[features]
default = [
"backend_rocksdb",
@@ -352,7 +366,13 @@ default = [
backend_sqlite = ["sqlite"]
backend_rocksdb = ["rocksdb"]
rocksdb = ["rust-rocksdb"]
jemalloc = ["tikv-jemalloc-ctl", "tikv-jemallocator", "rust-rocksdb/jemalloc"]
jemalloc = [
"tikv-jemalloc-sys",
"tikv-jemalloc-ctl",
"tikv-jemallocator",
"rust-rocksdb/jemalloc",
]
jemalloc_prof = ["tikv-jemalloc-sys/profiling"]
sqlite = ["rusqlite", "parking_lot", "thread_local"]
systemd = ["sd-notify"]
sentry_telemetry = ["sentry", "sentry-tracing", "sentry-tower"]
@@ -373,6 +393,10 @@ perf_measurements = [
"opentelemetry-jaeger",
]
# enable the tokio_console server
# incompatible with release_max_log_level
tokio_console = ["console-subscriber", "tokio/tracing"]
hot_reload = ["dep:hot-lib-reloader"]
hardened_malloc = ["hardened_malloc-rs"]
@@ -435,10 +459,11 @@ systemd-units = { unit-name = "conduwuit" }
[profile.dev]
debug = 0
lto = 'off'
codegen-units = 512
incremental = true
#panic = "abort"
# seems to speed up continuous debug compilations
[profile.dev.build-override]
opt-level = 3
@@ -452,7 +477,6 @@ opt-level = 3
lto = 'thin'
incremental = false
opt-level = 3
overflow-checks = true
strip = "symbols"
control-flow-guard = true # Windows only
debug = 0
@@ -503,9 +527,6 @@ single_use_lifetimes = "warn"
unsafe_op_in_unsafe_fn = "warn"
unreachable_pub = "warn"
# not in rust 1.75.0 (doesn't break CI but won't check for it)
unit_bindings = "warn"
# this seems to suggest broken code and is not working correctly
unused_braces = "allow"
@@ -555,7 +576,6 @@ filetype_is_file = "warn"
float_cmp_const = "warn"
format_push_string = "warn"
impl_trait_in_params = "warn"
ref_to_mut = "warn"
lossy_float_literal = "warn"
mem_forget = "warn"
missing_assert_message = "warn"
+13 -6
View File
@@ -17,8 +17,15 @@ RESULTS_FILE="$3"
OCI_IMAGE="complement-conduit:dev"
pushd "$(git rev-parse --show-toplevel)" > /dev/null
nix build .#complement
toplevel="$(git rev-parse --show-toplevel)"
pushd "$toplevel" > /dev/null
# uses nix-output-monitor (nom) if available
if command -v nom &> /dev/null; then
nom build .#complement
else
nix build -L .#complement
fi
docker load < result
popd > /dev/null
@@ -27,13 +34,13 @@ set +o pipefail
env \
-C "$COMPLEMENT_SRC" \
COMPLEMENT_BASE_IMAGE="$OCI_IMAGE" \
go test -timeout 1h -json ./tests | tee "$LOG_FILE"
go test -vet=off -timeout 1h -json ./tests | tee "$LOG_FILE"
set -o pipefail
# Post-process the results into an easy-to-compare format
cat "$LOG_FILE" | jq -c '
# Post-process the results into an easy-to-compare format, sorted by Test name for reproducible results
cat "$LOG_FILE" | jq -s -c 'sort_by(.Test)[]' | jq -c '
select(
(.Action == "pass" or .Action == "fail" or .Action == "skip")
and .Test != null
) | {Action: .Action, Test: .Test}
' | sort > "$RESULTS_FILE"
' > "$RESULTS_FILE"
+73 -32
View File
@@ -2,40 +2,81 @@
set -eo pipefail
# The first argument must be the desired installable
INSTALLABLE="$1"
toplevel="$(git rev-parse --show-toplevel)"
# Build the installable and forward any other arguments too
nix build -L "$@"
# Build just the single installable and forward any other arguments too
just() {
# uses nix-output-monitor (nom) if available
if command -v nom &> /dev/null; then
nom build "$@"
else
nix build -L "$@"
fi
if [ ! -z "$ATTIC_TOKEN" ]; then
nix run --inputs-from . attic -- \
login \
conduit \
"${ATTIC_ENDPOINT:-https://attic.kennel.juneis.dog/conduit}" \
"$ATTIC_TOKEN"
if [ ! -z "$ATTIC_TOKEN" ]; then
# historical "conduit" store for compatibility purposes, same as conduwuit
nix run --inputs-from "$toplevel" attic -- \
login \
conduit \
"${ATTIC_ENDPOINT:-https://attic.kennel.juneis.dog/conduit}" \
"$ATTIC_TOKEN"
# Push the target installable and its build dependencies
nix run --inputs-from . attic -- \
push \
conduit \
"$(nix path-info "$INSTALLABLE" --derivation)" \
"$(nix path-info "$INSTALLABLE")"
readarray -t outputs < <(nix path-info "$@")
readarray -t derivations < <(nix path-info "$@" --derivation)
# Push the target installable and its build dependencies
nix run --inputs-from "$toplevel" attic -- \
push \
conduit \
"${outputs[@]}" \
"${derivations[@]}"
# main "conduwuit" store
nix run --inputs-from "$toplevel" attic -- \
login \
conduwuit \
"${ATTIC_ENDPOINT:-https://attic.kennel.juneis.dog/conduwuit}" \
"$ATTIC_TOKEN"
# Push the target installable and its build dependencies
nix run --inputs-from "$toplevel" attic -- \
push \
conduwuit \
"${outputs[@]}" \
"${derivations[@]}"
else
echo "\$ATTIC_TOKEN is unset, skipping uploading to the binary cache"
fi
}
# Build and cache things needed for CI
ci() {
cache=(
--inputs-from "$toplevel"
# Keep sorted
"$toplevel#devShells.x86_64-linux.default.inputDerivation"
attic#default
nixpkgs#direnv
nixpkgs#jq
nixpkgs#nix-direnv
)
just "${cache[@]}"
}
# Build and cache *all* the package outputs from the flake.nix
packages() {
declare -a cache="($(
nix flake show --json 2> /dev/null |
nix run --inputs-from "$toplevel" nixpkgs#jq -- \
-r \
'.packages."x86_64-linux" | keys | map("'"$toplevel"'#" + .) | @sh'
))"
just "${cache[@]}"
}
# push to "conduwuit" too
nix run --inputs-from . attic -- \
login \
conduwuit \
"${ATTIC_ENDPOINT:-https://attic.kennel.juneis.dog/conduwuit}" \
"$ATTIC_TOKEN"
# Push the target installable and its build dependencies
nix run --inputs-from . attic -- \
push \
conduwuit \
"$(nix path-info "$INSTALLABLE" --derivation)" \
"$(nix path-info "$INSTALLABLE")"
else
echo "\$ATTIC_TOKEN is unset, skipping uploading to the binary cache"
fi
eval "$@"
+46 -5
View File
@@ -336,6 +336,18 @@ allow_profile_lookup_federation_requests = true
# messages without any attempt at redelivery.
#startup_netburst_keep = 50
# If the 'perf_measurements' feature is enabled, enables collecting folded stack trace profile of tracing spans using
# tracing_flame. The resulting profile can be visualized with inferno[1], speedscope[2], or a number of other tools.
# [1]: https://github.com/jonhoo/inferno
# [2]: www.speedscope.app
# tracing_flame = false
# If 'tracing_flame' is enabled, sets a filter for which events will be included in the profile.
# Supported syntax is documented at https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives
# tracing_flame_filter = "trace,h2=off"
# If 'tracing_flame' is enabled, set the path to write the generated profile.
# tracing_flame_output_path = "./tracing.folded"
### Generic database options
@@ -372,6 +384,10 @@ allow_profile_lookup_federation_requests = true
# Defaults to false
#rocksdb_optimize_for_spinning_disks = false
# Enables direct-io to increase database performance. This is enabled by default. Set this option to false if the
# database resides on a filesystem which does not support direct-io.
#rocksdb_direct_io = true
# RocksDB log level. This is not the same as conduwuit's log level. This is the log level for the RocksDB engine/library
# which show up in your database folder/path as `LOG` files. Defaults to error. conduwuit will typically log RocksDB errors as normal.
#rocksdb_log_level = "error"
@@ -400,11 +416,13 @@ allow_profile_lookup_federation_requests = true
#rocksdb_max_log_files = 3
# Type of RocksDB database compression to use.
# Available options are "zstd", "zlib", "bz2" and "lz4"
# Available options are "zstd", "zlib", "bz2", "lz4", or "none"
# It is best to use ZSTD as an overall good balance between speed/performance, storage, IO amplification, and CPU usage.
# For more performance but less compression (more storage used) and less CPU usage, use LZ4.
# See https://github.com/facebook/rocksdb/wiki/Compression for more details.
#
# "none" will disable compression.
#
# Defaults to "zstd"
#rocksdb_compression_algo = "zstd"
@@ -471,7 +489,7 @@ allow_profile_lookup_federation_requests = true
# 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 systemd does *not* count as an external cache, even when configured to do so.
#dns_cache_entries = 12288
#dns_cache_entries = 32768
# Minimum time-to-live in seconds for entries in the DNS cache. The default may appear high to most
# administrators; this is by design. Only decrease this if you are using an external DNS cache.
@@ -480,7 +498,9 @@ allow_profile_lookup_federation_requests = true
# Minimum time-to-live in seconds for NXDOMAIN entries in the DNS cache. This value is critical for
# the server to federate efficiently. NXDOMAIN's are assumed to not be returning to the federation
# and aggressively cached rather than constantly rechecked.
#dns_min_ttl_nxdomain = 86400
#
# Defaults to 3 days as these are *very rarely* false negatives.
#dns_min_ttl_nxdomain = 259200
# The number of seconds to wait for a reply to a DNS query. Please note that recursive queries can
# take up to several seconds for some domains, so this value should not be too low.
@@ -498,6 +518,27 @@ allow_profile_lookup_federation_requests = true
# The default is to query one nameserver and stop (false).
#query_all_nameservers = true
# Enables using *only* TCP for querying your specified nameservers instead of UDP.
#
# You very likely do *not* want this. hickory-resolver already falls back to TCP on UDP errors.
# Defaults to false
#query_over_tcp_only = false
# DNS A/AAAA record lookup strategy
#
# Takes a number of one of the following options:
# 1 - Ipv4Only (Only query for A records, no AAAA/IPv6)
# 2 - Ipv6Only (Only query for AAAA records, no A/IPv4)
# 3 - Ipv4AndIpv6 (Query for A and AAAA records in parallel, uses whatever returns a successful response first)
# 4 - Ipv6thenIpv4 (Query for AAAA record, if that fails then query the A record)
# 5 - Ipv4thenIpv6 (Query for A record, if that fails then query the AAAA record)
#
# If you don't have IPv6 networking, then for better performance it may be suitable to set this to Ipv4Only (1) as
# you will never ever use the AAAA record contents even if the AAAA record is successful instead of the A record.
#
# Defaults to 5 - Ipv4ThenIpv6 as this is the most compatible and IPv4 networking is currently the most prevalent.
#ip_lookup_strategy = 5
### Request Timeouts, Connection Timeouts, and Connection Pooling
@@ -585,8 +626,8 @@ allow_profile_lookup_federation_requests = true
# Appservice URL request connection timeout
#
# Defaults to 120 seconds
#appservice_timeout = 120
# Defaults to 35 seconds as generally appservices are hosted within the same network
#appservice_timeout = 35
# Appservice URL idle connection pool timeout
#
-19
View File
@@ -1,19 +0,0 @@
#!/bin/sh
# If the config file does not contain a default port and the CONDUIT_PORT env is not set, create
# try to get port from process list
if [ -z "${CONDUIT_PORT}" ]; then
CONDUIT_PORT=$(ss -tlpn | grep conduit | grep -m1 -o ':[0-9]*' | grep -m1 -o '[0-9]*')
fi
# If CONDUIT_ADDRESS is not set try to get the address from the process list
if [ -z "${CONDUIT_ADDRESS}" ]; then
CONDUIT_ADDRESS=$(ss -tlpn | awk -F ' +|:' '/conduit/ { print $4 }')
fi
# The actual health check.
# We try to first get a response on HTTP and when that fails on HTTPS and when that fails, we exit with code 1.
# TODO: Change this to a single wget call. Do we have a config value that we can check for that?
wget --no-verbose --tries=1 --spider "http://${CONDUIT_ADDRESS}:${CONDUIT_PORT}/_matrix/client/versions" || \
wget --no-verbose --tries=1 --spider "https://${CONDUIT_ADDRESS}:${CONDUIT_PORT}/_matrix/client/versions" || \
exit 1
+11 -25
View File
@@ -12,15 +12,19 @@ OCI images for conduwuit are available in the registries listed below.
| Registry | Image | Size | Notes |
| --------------- | --------------------------------------------------------------- | ----------------------------- | ---------------------- |
| GitHub Registry | [ghcr.io/girlbossceo/conduwuit:latest][gh] | ![Image Size][shield-latest] | Stable tagged image. |
| GitLab Registry | [registry.gitlab.com/girlbossceo/conduwuit:latest][gl] | ![Image Size][shield-latest] | Stable tagged image. |
| Docker Hub | [docker.io/girlbossceo/conduwuit:latest][dh] | ![Image Size][shield-latest] | Stable tagged image. |
| GitHub Registry | [ghcr.io/girlbossceo/conduwuit:main][gh] | ![Image Size][shield-main] | Stable branch. |
| Docker Hub | [docker.io/girlbossceo/conduwuit:main][dh] | ![Image Size][shield-main] | Stable branch. |
| GitHub Registry | [ghcr.io/girlbossceo/conduwuit:dev][gh] | ![Image Size][shield-main] | Development version. |
| Docker Hub | [docker.io/girlbossceo/conduwuit:dev][dh] | ![Image Size][shield-dev] | Development version. |
| GitHub Registry | [ghcr.io/girlbossceo/conduwuit:main][gh] | ![Image Size][shield-main] | Stable main branch. |
| GitLab Registry | [registry.gitlab.com/girlbossceo/conduwuit:main][gl] | ![Image Size][shield-main] | Stable main branch. |
| Docker Hub | [docker.io/girlbossceo/conduwuit:main][dh] | ![Image Size][shield-main] | Stable main branch. |
| GitHub Registry | [ghcr.io/girlbossceo/conduwuit:dev][gh] | ![Image Size][shield-dev] | Development version/branch. |
| GitLab Registry | [registry.gitlab.com/girlbossceo/conduwuit:dev][gl] | ![Image Size][shield-dev] | Development version/branch. |
| Docker Hub | [docker.io/girlbossceo/conduwuit:dev][dh] | ![Image Size][shield-dev] | Development version/branch. |
[dh]: https://hub.docker.com/repository/docker/girlbossceo/conduwuit
[gh]: https://github.com/girlbossceo/conduwuit/pkgs/container/conduwuit
[gl]: https://gitlab.com/girlbossceo/conduwuit/container_registry/6351657
[shield-latest]: https://img.shields.io/docker/image-size/girlbossceo/conduwuit/latest
[shield-main]: https://img.shields.io/docker/image-size/girlbossceo/conduwuit/main
[shield-dev]: https://img.shields.io/docker/image-size/girlbossceo/conduwuit/dev
@@ -33,24 +37,6 @@ docker image pull <link>
to pull it to your machine.
### Build using a Dockerfile
The Dockerfile provided by conduwuit has two stages, each of which creates an image.
1. **Builder:** Builds the binary from local context or by cloning a git revision from the official repository.
2. **Runner:** Copies the built binary from **Builder** and sets up the runtime environment, like creating a volume to persist the database and applying the correct permissions.
To build the image you can use the following command
```bash
docker build --tag girlbossceo/conduwuit:main .
```
which also will tag the resulting image as `girlbossceo/conduwuit:main`.
### Run
When you have the image you can simply run it with
@@ -70,9 +56,9 @@ docker run -d -p 8448:6167 \
or you can use [docker compose](#docker-compose).
The `-d` flag lets the container run in detached mode. You now need to supply a `conduwuit.toml` config file, an example can be found [here](../configuration.md).
You can pass in different env vars to change config values on the fly. You can even configure conduwuit completely by using env vars, but for that you need
to pass `-e CONDUIT_CONFIG=""` into your container. For an overview of possible values, please take a look at the `docker-compose.yml` file.
The `-d` flag lets the container run in detached mode. You may supply an optional `conduwuit.toml` config file, an example can be found [here](../configuration.md).
You can pass in different env vars to change config values on the fly. You can even configure conduwuit completely by using env vars. For an overview of possible
values, please take a look at the `docker-compose.yml` file.
If you just want to test conduwuit for a short time, you can use the `--rm` flag, which will clean up everything related to your container after you stop it.
+1 -1
View File
@@ -11,7 +11,7 @@
You may simply download the binary that fits your machine. Run `uname -m` to see what you need.
Prebuilt binaries can be downloaded from the latest successful CI workflow on the main branch here: https://github.com/girlbossceo/conduwuit/actions/workflows/ci.yml?query=branch%3Amain+actor%3Agirlbossceo+is%3Asuccess+event%3Apush
Prebuilt binaries can be downloaded from the latest tagged release [here](https://github.com/girlbossceo/conduwuit/releases/latest).
Alternatively, you may compile the binary yourself. First, install any dependencies:
+18
View File
@@ -2,3 +2,21 @@
Information about developing the project. If you are only interested in using
it, you can safely ignore this section.
## Debugging with `tokio-console`
[`tokio-console`][1] can be a useful tool for debugging and profiling. To make
a `tokio-console`-enabled build of Conduwuit, enable the `tokio_console` feature,
disable the default `release_max_log_level` feature, and set the
`--cfg tokio_unstable` flag to enable experimental tokio APIs. A build might
look like this:
```bash
RUSTFLAGS="--cfg tokio_unstable" cargo build \
--release \
--no-default-features \
--features
backend_rocksdb,systemd,element_hacks,sentry_telemetry,gzip_compression,brotli_compression,zstd_compression,tokio_console
```
[1]: https://docs.rs/tokio-console/latest/tokio_console/
+11 -1
View File
@@ -17,9 +17,11 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence!
- Various config options to tweak connection pooling, request timeouts, connection timeouts, DNS timeouts and settings, etc with good defaults which also help huge with performance via reusing connections and retrying where needed
- Implement building conduwuit with jemalloc (which extends to the RocksDB jemalloc feature for maximum gains) or hardened_malloc light variant, and produce CI builds with jemalloc for performance (Nix doesn't seem to build [hardened_malloc-rs](https://github.com/girlbossceo/hardened_malloc-rs) properly)
- Add support for caching DNS results with hickory-dns / hickory-resolver in conduwuit (not a replacement for a proper resolver cache, but still far better than nothing)
- Add config option for using DNS over TCP, and config option for controlling A/AAAA record lookup strategy (e.g. don't query AAAA records if you don't have IPv6 connectivity)
- Overall significant database, Client-Server, and federation performance and latency improvements (check out the ping room leaderboards if you don't believe me :>)
- Add config options for RocksDB compression and bottommost compression, including choosing the algorithm and compression level
- Use [loole](https://github.com/mahdi-shojaee/loole) MPSC channels instead of tokio MPSC channels for huge performance boosts in sending channels (mainly relevant for federation) and presence channels
- Use `tracing`/`log`'s `release_max_level_info` feature to improve performance, build speeds, binary size, and CPU usage in release builds by avoid compiling debug/trace log level macros that users will generally never use (can be disabled with a build-time feature flag)
## General Fixes:
@@ -34,11 +36,11 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence!
- Return joined member count of rooms for push rules/conditions instead of a hardcoded value of 10
- Make `CONDUIT_CONFIG` optional, relevant for container users that configure only by environment variables and no longer need to set `CONDUIT_CONFIG` to an empty string.
- Allow HEAD HTTP requests in CORS for clients (despite not being explicity mentioned in Matrix spec, HTTP spec says all HEAD requests need to behave the same as GET requests, Synapse supports HEAD requests)
- Add missing `destination` key to all `X-Matrix` `Authorization` requests (spec compliance issue)
- Resolve and remove some "features" from upstream that result in concurrency hazards, exponential backoff issues, or arbitrary performance limiters
- Find more servers for outbound federation `/hierarchy` requests instead of just the room ID server name
- Support for suggesting servers to join through at `/_matrix/client/v3/directory/room/{roomAlias}`
- Support for suggesting servers to join through us at `/_matrix/federation/v1/query/directory`
- Add workaround for [Out Of Your Element](https://gitdab.com/cadence/out-of-your-element) appservice bridge to make it functional on conduwuit (bug has already been reported)
## Moderation:
@@ -121,6 +123,9 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence!
- Admin debug command to fetch a PDU from a remote server and inserts it into our database/timeline as backfill
- Add admin command to delete media via a specific MXC. This deletes the MXC from our database, and the file locally.
- Add admin commands for banning (blocking) room IDs from our local users joining (admins are always allowed) and evicts all our local users from that room, in addition to bulk room banning support, and blocks room invites (remote and local) to the banned room, as a moderation feature
- Add admin commands to output jemalloc memory stats and memory usage
- Add admin command to get conduwuit's uptime
- Add admin command to get rooms a *remote* user shares with us
## Misc:
@@ -138,5 +143,10 @@ Outgoing typing indicators, outgoing read receipts, **and** outgoing presence!
- Assume well-knowns are broken if they exceed past 10000 characters.
- Add support for the Matrix spec compliance test suite [Complement](https://github.com/matrix-org/complement/) via the Nix flake and various other fixes for it
- Add support for listening on both HTTP and HTTPS if using direct TLS with conduwuit for usecases such as Complement
- Implement running and diff'ing Complement results in CI
- Interest in supporting other operating systems such as macOS, BSDs, and Windows, and getting them added into CI and doing builds for them
- Add config option for disabling RocksDB Direct IO if needed
- (Developers): Add support for tokio-console
- (Developers): Add support for tracing flame graphs
- Add `release-debuginfo` Cargo build profile
- No cryptocurrency donations allowed, conduwuit is fully maintained by independent queer maintainers, and with a strong priority on inclusitivity and comfort for protected groups 🏳️‍⚧️
+48 -2
View File
@@ -78,9 +78,55 @@ RUSTDOCFLAGS="-D warnings" cargo doc \
"""
[[task]]
name = "cargo-clippy"
name = "clippy/default"
group = "lints"
script = "cargo clippy --workspace --all-targets --all-features --color=always -- -D warnings"
script = """
cargo clippy \
--workspace \
--all-targets \
--color=always \
-- \
-D warnings
"""
[[task]]
name = "clippy/all"
group = "lints"
script = """
cargo clippy \
--workspace \
--all-targets \
--all-features \
--color=always \
-- \
-D warnings
"""
[[task]]
name = "clippy/jemalloc"
group = "lints"
script = """
cargo clippy \
--workspace \
--features jemalloc \
--all-targets \
--color=always \
-- \
-D warnings
"""
[[task]]
name = "clippy/hardened_malloc"
group = "lints"
script = """
cargo clippy \
--workspace \
--features hardened_malloc \
--all-targets \
--color=always \
-- \
-D warnings
"""
[[task]]
name = "lychee"
Generated
+11 -6
View File
@@ -26,15 +26,16 @@
"complement": {
"flake": false,
"locked": {
"lastModified": 1713458251,
"narHash": "sha256-hom/Lt0gZzLWqFhUJG0X2i88CAMIILInO5w0tPj6G3s=",
"lastModified": 1714472853,
"narHash": "sha256-CNRHSZe3TE+3tFj2dHNyxTMjDqL0MKY3P/3jqUgA7YE=",
"owner": "matrix-org",
"repo": "complement",
"rev": "d73c81a091604b0fc5b6b0617dcac58c25763f57",
"rev": "891d18872c153d39a9ce63b545045efddb845738",
"type": "github"
},
"original": {
"owner": "matrix-org",
"ref": "main",
"repo": "complement",
"type": "github"
}
@@ -89,15 +90,16 @@
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1713680591,
"narHash": "sha256-3pbv7UgAgetwz9YdjzIT/lZ6Rgj6wj6MR4mphBLyDjU=",
"lastModified": 1714544767,
"narHash": "sha256-kF1bX+YFMedf1g0PAJYwGUkzh22JmULtj8Rm4IXAQKs=",
"owner": "nix-community",
"repo": "fenix",
"rev": "19aaa94a73cc670a4d87e84f0909966cd8f8cd79",
"rev": "73124e1356bde9411b163d636b39fe4804b7ca45",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "main",
"repo": "fenix",
"type": "github"
}
@@ -130,6 +132,7 @@
},
"original": {
"owner": "edolstra",
"ref": "master",
"repo": "flake-compat",
"type": "github"
}
@@ -163,6 +166,7 @@
},
"original": {
"owner": "numtide",
"ref": "main",
"repo": "flake-utils",
"type": "github"
}
@@ -178,6 +182,7 @@
},
"original": {
"owner": "numtide",
"ref": "main",
"repo": "nix-filter",
"type": "github"
}
+6 -6
View File
@@ -1,12 +1,12 @@
{
inputs = {
attic.url = "github:zhaofengli/attic?ref=main";
complement = { url = "github:matrix-org/complement"; flake = false; };
complement = { url = "github:matrix-org/complement?ref=main"; flake = false; };
crane = { url = "github:ipetkov/crane?ref=master"; inputs.nixpkgs.follows = "nixpkgs"; };
fenix = { url = "github:nix-community/fenix"; inputs.nixpkgs.follows = "nixpkgs"; };
flake-compat = { url = "github:edolstra/flake-compat"; flake = false; };
flake-utils.url = "github:numtide/flake-utils";
nix-filter.url = "github:numtide/nix-filter";
fenix = { url = "github:nix-community/fenix?ref=main"; inputs.nixpkgs.follows = "nixpkgs"; };
flake-compat = { url = "github:edolstra/flake-compat?ref=master"; flake = false; };
flake-utils.url = "github:numtide/flake-utils?ref=main";
nix-filter.url = "github:numtide/nix-filter?ref=main";
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
rocksdb = { url = "github:facebook/rocksdb?ref=v9.1.1"; flake = false; };
};
@@ -21,7 +21,7 @@
file = ./rust-toolchain.toml;
# See also `rust-toolchain.toml`
sha256 = "sha256-SXRtAuO4IqNOQq+nLbrsDFbVk+3aVA8NNpSZsKlVH/8=";
sha256 = "sha256-e4mlaJehWBymYxJGgnbuCObVlqMlQSilZ8FljG9zPHY=";
};
scope = pkgs: pkgs.lib.makeScope pkgs.newScope (self: {
+67 -46
View File
@@ -1,7 +1,6 @@
{ inputs
# Dependencies
, craneLib
# Dependencies (keep sorted)
{ craneLib
, inputs
, lib
, libiconv
, pkgsBuildHost
@@ -9,53 +8,72 @@
, rust
, stdenv
# Options
# Options (keep sorted)
, default_features ? true
, features ? []
, profile ? "release"
}:
craneLib.buildPackage rec {
src = inputs.nix-filter {
root = inputs.self;
include = [
"src"
"Cargo.toml"
"Cargo.lock"
];
};
let
buildDepsOnlyEnv =
let
rocksdb' = rocksdb.override {
enableJemalloc = builtins.elem "jemalloc" features;
};
in
{
CARGO_PROFILE = profile;
ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include";
ROCKSDB_LIB_DIR = "${rocksdb'}/lib";
}
//
(import ./cross-compilation-env.nix {
# Keep sorted
inherit
lib
pkgsBuildHost
rust
stdenv;
});
# This is redundant with CI
doCheck = false;
buildPackageEnv = {
CONDUWUIT_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev;
} // buildDepsOnlyEnv;
env =
let
rocksdb' = rocksdb.override {
enableJemalloc = builtins.elem "jemalloc" features;
};
in
{
CARGO_PROFILE = profile;
CONDUIT_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev;
ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include";
ROCKSDB_LIB_DIR = "${rocksdb'}/lib";
}
//
(import ./cross-compilation-env.nix {
inherit
lib
pkgsBuildHost
rust
stdenv;
});
commonAttrs = {
inherit
(craneLib.crateNameFromCargoToml {
cargoToml = "${inputs.self}/Cargo.toml";
})
pname
version;
nativeBuildInputs = [
# bindgen needs the build platform's libclang. Apparently due to "splicing
# weirdness", pkgs.rustPlatform.bindgenHook on its own doesn't quite do the
# right thing here.
pkgsBuildHost.rustPlatform.bindgenHook
src = let filter = inputs.nix-filter.lib; in filter {
root = inputs.self;
# Keep sorted
include = [
"Cargo.lock"
"Cargo.toml"
"hot_lib"
"src"
];
};
nativeBuildInputs = [
# bindgen needs the build platform's libclang. Apparently due to "splicing
# weirdness", pkgs.rustPlatform.bindgenHook on its own doesn't quite do the
# right thing here.
pkgsBuildHost.rustPlatform.bindgenHook
]
++ lib.optionals stdenv.isDarwin [ libiconv ];
};
in
craneLib.buildPackage ( commonAttrs // {
cargoArtifacts = craneLib.buildDepsOnly (commonAttrs // {
env = buildDepsOnlyEnv;
});
cargoExtraArgs = ""
+ lib.optionalString
@@ -65,11 +83,14 @@ craneLib.buildPackage rec {
(features != [])
"--features " + (builtins.concatStringsSep "," features);
meta.mainProgram = (craneLib.crateNameFromCargoToml {
cargoToml = "${inputs.self}/Cargo.toml";
}).pname;
# This is redundant with CI
doCheck = false;
env = buildPackageEnv;
passthru = {
inherit env;
env = buildPackageEnv;
};
}
meta.mainProgram = commonAttrs.pname;
})
+2 -2
View File
@@ -11,7 +11,7 @@
# If you're having trouble making the relevant changes, bug a maintainer.
[toolchain]
channel = "1.75.0"
channel = "1.76.0"
components = [
# For rust-analyzer
"rust-src",
@@ -20,4 +20,4 @@ targets = [
"x86_64-unknown-linux-gnu",
"x86_64-unknown-linux-musl",
"aarch64-unknown-linux-musl",
]
]
+7
View File
@@ -0,0 +1,7 @@
//! Default allocator with no special features
/// Always returns the empty string
pub(crate) fn memory_stats() -> String { Default::default() }
/// Always returns the empty string
pub(crate) fn memory_usage() -> String { Default::default() }
+8
View File
@@ -0,0 +1,8 @@
#[global_allocator]
static HMALLOC: hardened_malloc_rs::HardenedMalloc = hardened_malloc_rs::HardenedMalloc;
pub(crate) fn memory_usage() -> String {
String::default() //TODO: get usage
}
pub(crate) fn memory_stats() -> String { "Extended statistics are not available from hardened_malloc.".to_owned() }
+50
View File
@@ -0,0 +1,50 @@
use std::ffi::{c_char, c_void};
use tikv_jemalloc_ctl as mallctl;
use tikv_jemalloc_sys as ffi;
use tikv_jemallocator as jemalloc;
#[global_allocator]
static JEMALLOC: jemalloc::Jemalloc = jemalloc::Jemalloc;
pub(crate) fn memory_usage() -> String {
use mallctl::stats;
let allocated = stats::allocated::read().unwrap_or_default() as f64 / 1024.0 / 1024.0;
let active = stats::active::read().unwrap_or_default() as f64 / 1024.0 / 1024.0;
let mapped = stats::mapped::read().unwrap_or_default() as f64 / 1024.0 / 1024.0;
let metadata = stats::metadata::read().unwrap_or_default() as f64 / 1024.0 / 1024.0;
let resident = stats::resident::read().unwrap_or_default() as f64 / 1024.0 / 1024.0;
let retained = stats::retained::read().unwrap_or_default() as f64 / 1024.0 / 1024.0;
format!(
" allocated: {allocated:.2} MiB\n active: {active:.2} MiB\n mapped: {mapped:.2} MiB\n metadata: {metadata:.2} \
MiB\n resident: {resident:.2} MiB\n retained: {retained:.2} MiB\n "
)
}
pub(crate) fn memory_stats() -> String {
const MAX_LENGTH: usize = 65536 - 4096;
let opts_s = "d";
let mut str = String::new();
let opaque = std::ptr::from_mut(&mut str).cast::<c_void>();
let opts_p: *const c_char = std::ffi::CString::new(opts_s).expect("cstring").into_raw() as *const c_char;
// SAFETY: calls malloc_stats_print() with our string instance which must remain
// in this frame. https://docs.rs/tikv-jemalloc-sys/latest/tikv_jemalloc_sys/fn.malloc_stats_print.html
unsafe { ffi::malloc_stats_print(Some(malloc_stats_cb), opaque, opts_p) };
str.truncate(MAX_LENGTH);
format!("<pre><code>{str}</code></pre>")
}
extern "C" fn malloc_stats_cb(opaque: *mut c_void, msg: *const c_char) {
// SAFETY: we have to trust the opaque points to our String
let res: &mut String = unsafe { opaque.cast::<String>().as_mut().unwrap() };
// SAFETY: we have to trust the string is null terminated.
let msg = unsafe { std::ffi::CStr::from_ptr(msg) };
let msg = String::from_utf8_lossy(msg.to_bytes());
res.push_str(msg.as_ref());
}
+25
View File
@@ -0,0 +1,25 @@
//! Integration with allocators
// jemalloc
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc", not(feature = "hardened_malloc")))]
mod je;
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc", not(feature = "hardened_malloc")))]
pub(crate) use je::{memory_stats, memory_usage};
// hardened_malloc
#[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", target_os = "linux", not(feature = "jemalloc")))]
mod hardened;
#[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", target_os = "linux", not(feature = "jemalloc")))]
pub(crate) use hardened::{memory_stats, memory_usage};
// default, enabled when none or multiple of the above are enabled
#[cfg(any(
not(any(feature = "jemalloc", feature = "hardened_malloc")),
all(feature = "jemalloc", feature = "hardened_malloc"),
))]
mod default;
#[cfg(any(
not(any(feature = "jemalloc", feature = "hardened_malloc")),
all(feature = "jemalloc", feature = "hardened_malloc"),
))]
pub(crate) use default::{memory_stats, memory_usage};
+18 -12
View File
@@ -18,7 +18,9 @@ use tracing::{error, info, warn};
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
use crate::{
api::client_server::{self, join_room_by_id_helper},
service, services, utils, Error, Result, Ruma,
service, services,
utils::{self, user_id::user_is_local},
Error, Result, Ruma,
};
const RANDOM_USER_ID_LENGTH: usize = 10;
@@ -40,7 +42,7 @@ pub(crate) async fn get_register_available_route(
// Validate user id
let user_id = UserId::parse_with_server_name(body.username.to_lowercase(), services().globals.server_name())
.ok()
.filter(|user_id| !user_id.is_historical() && user_id.server_name() == services().globals.server_name())
.filter(|user_id| !user_id.is_historical() && user_is_local(user_id))
.ok_or(Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))?;
// Check if username is creative enough
@@ -125,9 +127,7 @@ pub(crate) async fn register_route(body: Ruma<register::v3::Request>) -> Result<
let proposed_user_id =
UserId::parse_with_server_name(username.to_lowercase(), services().globals.server_name())
.ok()
.filter(|user_id| {
!user_id.is_historical() && user_id.server_name() == services().globals.server_name()
})
.filter(|user_id| !user_id.is_historical() && user_is_local(user_id))
.ok_or(Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))?;
if services().users.exists(&proposed_user_id)? {
@@ -294,7 +294,8 @@ pub(crate) async fn register_route(body: Ruma<register::v3::Request>) -> Result<
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"New user \"{user_id}\" registered on this server."
)));
)))
.await;
}
// log in conduit admin channel if a guest registered
@@ -310,27 +311,30 @@ pub(crate) async fn register_route(body: Ruma<register::v3::Request>) -> Result<
.send_message(RoomMessageEventContent::notice_plain(format!(
"Guest user \"{user_id}\" with device display name `{device_display_name}` registered on this \
server."
)));
)))
.await;
} else {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"Guest user \"{user_id}\" with no device display name registered on this server.",
)));
)))
.await;
}
} else {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"Guest user \"{user_id}\" with no device display name registered on this server.",
)));
)))
.await;
}
}
// If this is the first real user, grant them admin privileges except for guest
// users Note: the server user, @conduit:servername, is generated first
if !is_guest {
if let Some(admin_room) = service::admin::Service::get_admin_room()? {
if let Some(admin_room) = service::admin::Service::get_admin_room().await? {
if services()
.rooms
.state_cache
@@ -461,7 +465,8 @@ pub(crate) async fn change_password_route(
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"User {sender_user} changed their password."
)));
)))
.await;
Ok(change_password::v3::Response {})
}
@@ -536,7 +541,8 @@ pub(crate) async fn deactivate_route(body: Ruma<deactivate::v3::Request>) -> Res
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"User {sender_user} deactivated their account."
)));
)))
.await;
Ok(deactivate::v3::Response {
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
+64 -72
View File
@@ -8,38 +8,29 @@ use ruma::{
},
federation,
},
OwnedRoomAliasId, OwnedServerName,
OwnedRoomAliasId, OwnedRoomId, OwnedServerName,
};
use tracing::debug;
use crate::{debug_info, debug_warn, services, Error, Result, Ruma};
use crate::{
debug_info, debug_warn, service::appservice::RegistrationInfo, services, utils::server_name::server_is_ours, Error,
Result, Ruma,
};
/// # `PUT /_matrix/client/v3/directory/room/{roomAlias}`
///
/// Creates a new room alias on this server.
pub(crate) async fn create_alias_route(body: Ruma<create_alias::v3::Request>) -> Result<create_alias::v3::Response> {
if body.room_alias.server_name() != services().globals.server_name() {
return Err(Error::BadRequest(ErrorKind::InvalidParam, "Alias is from another server."));
}
alias_checks(&body.room_alias, &body.appservice_info).await?;
// this isn't apart of alias_checks or delete alias route because we should
// allow removing forbidden room aliases
if services()
.globals
.forbidden_alias_names()
.is_match(body.room_alias.alias())
{
return Err(Error::BadRequest(ErrorKind::Unknown, "Room alias is forbidden."));
}
if let Some(ref info) = body.appservice_info {
if !info.aliases.is_match(body.room_alias.as_str()) {
return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias is not in namespace."));
}
} else if services()
.appservice
.is_exclusive_alias(&body.room_alias)
.await
{
return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias reserved by appservice."));
return Err(Error::BadRequest(ErrorKind::forbidden(), "Room alias is forbidden."));
}
if services()
@@ -73,9 +64,7 @@ pub(crate) async fn create_alias_route(body: Ruma<create_alias::v3::Request>) ->
/// - TODO: additional access control checks
/// - TODO: Update canonical alias event
pub(crate) async fn delete_alias_route(body: Ruma<delete_alias::v3::Request>) -> Result<delete_alias::v3::Response> {
if body.room_alias.server_name() != services().globals.server_name() {
return Err(Error::BadRequest(ErrorKind::InvalidParam, "Alias is from another server."));
}
alias_checks(&body.room_alias, &body.appservice_info).await?;
if services()
.rooms
@@ -86,18 +75,6 @@ pub(crate) async fn delete_alias_route(body: Ruma<delete_alias::v3::Request>) ->
return Err(Error::BadRequest(ErrorKind::NotFound, "Alias does not exist."));
}
if let Some(ref info) = body.appservice_info {
if !info.aliases.is_match(body.room_alias.as_str()) {
return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias is not in namespace."));
}
} else if services()
.appservice
.is_exclusive_alias(&body.room_alias)
.await
{
return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias reserved by appservice."));
}
if services()
.rooms
.alias
@@ -126,7 +103,7 @@ pub(crate) async fn get_alias_helper(
room_alias: OwnedRoomAliasId, servers: Option<Vec<OwnedServerName>>,
) -> Result<get_alias::v3::Response> {
debug!("get_alias_helper servers: {servers:?}");
if room_alias.server_name() != services().globals.server_name()
if !server_is_ours(room_alias.server_name())
&& (!servers
.as_ref()
.is_some_and(|servers| servers.contains(&services().globals.server_name().to_owned()))
@@ -180,47 +157,21 @@ pub(crate) async fn get_alias_helper(
if let Ok(response) = response {
let room_id = response.room_id;
let mut servers = response.servers;
let mut pre_servers = response.servers;
// since the room alis server responded, insert it into the list
pre_servers.push(room_alias.server_name().into());
// since the room alias server_name responded, insert it into the list
servers.push(room_alias.server_name().into());
// find active servers in room state cache to suggest
servers.extend(
services()
.rooms
.state_cache
.room_servers(&room_id)
.filter_map(Result::ok),
let servers = room_available_servers(&room_id, &room_alias, &Some(pre_servers));
debug_warn!(
"room alias servers from federation response for room ID {room_id} and room alias {room_alias}: \
{servers:?}"
);
servers.sort_unstable();
servers.dedup();
// shuffle list of servers randomly after sort and dedupe
servers.shuffle(&mut rand::thread_rng());
// prefer the very first server to be ourselves if available, else prefer the
// room alias server first
if let Some(server_index) = servers
.iter()
.position(|server| server == services().globals.server_name())
{
servers.remove(server_index);
servers.insert(0, services().globals.server_name().to_owned());
} else if let Some(alias_server_index) = servers
.iter()
.position(|server| server == room_alias.server_name())
{
servers.remove(alias_server_index);
servers.insert(0, room_alias.server_name().into());
}
return Ok(get_alias::v3::Response::new(room_id, servers));
}
return Err(Error::BadRequest(
ErrorKind::Unknown,
ErrorKind::NotFound,
"No servers could assist in resolving the room alias",
));
}
@@ -260,28 +211,69 @@ pub(crate) async fn get_alias_helper(
return Err(Error::BadRequest(ErrorKind::NotFound, "Room with alias not found."));
};
let servers = room_available_servers(&room_id, &room_alias, &None);
debug_warn!("room alias servers for room ID {room_id} and room alias {room_alias}");
Ok(get_alias::v3::Response::new(room_id, servers))
}
fn room_available_servers(
room_id: &OwnedRoomId, room_alias: &OwnedRoomAliasId, pre_servers: &Option<Vec<OwnedServerName>>,
) -> Vec<OwnedServerName> {
// find active servers in room state cache to suggest
let mut servers: Vec<OwnedServerName> = services()
.rooms
.state_cache
.room_servers(&room_id)
.room_servers(room_id)
.filter_map(Result::ok)
.collect();
// push any servers we want in the list already (e.g. responded remote alias
// servers, room alias server itself)
if let Some(pre_servers) = pre_servers {
servers.extend(pre_servers.clone());
};
servers.sort_unstable();
servers.dedup();
// shuffle list of servers randomly after sort and dedupe
servers.shuffle(&mut rand::thread_rng());
// insert our server as the very first choice if in list
// insert our server as the very first choice if in list, else check if we can
// prefer the room alias server first
if let Some(server_index) = servers
.iter()
.position(|server| server == services().globals.server_name())
.position(|server_name| server_is_ours(server_name))
{
servers.remove(server_index);
servers.insert(0, services().globals.server_name().to_owned());
} else if let Some(alias_server_index) = servers
.iter()
.position(|server| server == room_alias.server_name())
{
servers.remove(alias_server_index);
servers.insert(0, room_alias.server_name().into());
}
Ok(get_alias::v3::Response::new(room_id, servers))
servers
}
async fn alias_checks(room_alias: &OwnedRoomAliasId, appservice_info: &Option<RegistrationInfo>) -> Result<()> {
if !server_is_ours(room_alias.server_name()) {
return Err(Error::BadRequest(ErrorKind::InvalidParam, "Alias is from another server."));
}
if let Some(ref info) = appservice_info {
if !info.aliases.is_match(room_alias.as_str()) {
return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias is not in namespace."));
}
}
if services().appservice.is_exclusive_alias(room_alias).await {
return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias reserved by appservice."));
}
Ok(())
}
+4 -7
View File
@@ -52,7 +52,7 @@ pub(crate) async fn get_latest_backup_info_route(
let (version, algorithm) = services()
.key_backups
.get_latest_backup(sender_user)?
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Key backup does not exist."))?;
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Key backup does not exist."))?;
Ok(get_latest_backup_info::v3::Response {
algorithm,
@@ -62,7 +62,7 @@ pub(crate) async fn get_latest_backup_info_route(
})
}
/// # `GET /_matrix/client/r0/room_keys/version`
/// # `GET /_matrix/client/v3/room_keys/version/{version}`
///
/// Get information about an existing backup.
pub(crate) async fn get_backup_info_route(
@@ -72,7 +72,7 @@ pub(crate) async fn get_backup_info_route(
let algorithm = services()
.key_backups
.get_backup(sender_user, &body.version)?
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Key backup does not exist."))?;
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Key backup does not exist."))?;
Ok(get_backup_info::v3::Response {
algorithm,
@@ -274,10 +274,7 @@ pub(crate) async fn get_backup_keys_for_session_route(
let key_data = services()
.key_backups
.get_session(sender_user, &body.version, &body.room_id, &body.session_id)?
.ok_or(Error::BadRequest(
ErrorKind::NotFound,
"Backup key not found for this user's session.",
))?;
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Backup key not found for this user's session."))?;
Ok(get_backup_keys_for_session::v3::Response {
key_data,
+2 -15
View File
@@ -1,8 +1,7 @@
use std::collections::BTreeMap;
use ruma::api::client::discovery::get_capabilities::{
self, Capabilities, ChangePasswordCapability, RoomVersionStability, RoomVersionsCapability, SetAvatarUrlCapability,
SetDisplayNameCapability, ThirdPartyIdChangesCapability,
self, Capabilities, RoomVersionStability, RoomVersionsCapability, ThirdPartyIdChangesCapability,
};
use crate::{services, Result, Ruma};
@@ -22,24 +21,12 @@ pub(crate) async fn get_capabilities_route(
available.insert(room_version.clone(), RoomVersionStability::Stable);
}
let mut capabilities = Capabilities::new();
let mut capabilities = Capabilities::default();
capabilities.room_versions = RoomVersionsCapability {
default: services().globals.default_room_version(),
available,
};
capabilities.change_password = ChangePasswordCapability {
enabled: true,
};
capabilities.set_avatar_url = SetAvatarUrlCapability {
enabled: true,
};
capabilities.set_displayname = SetDisplayNameCapability {
enabled: true,
};
// conduit does not implement 3PID stuff
capabilities.thirdparty_id_changes = ThirdPartyIdChangesCapability {
enabled: false,
+29 -32
View File
@@ -5,6 +5,7 @@ use ruma::{
},
events::{AnyGlobalAccountDataEventContent, AnyRoomAccountDataEventContent},
serde::Raw,
OwnedUserId, RoomId,
};
use serde::Deserialize;
use serde_json::{json, value::RawValue as RawJsonValue};
@@ -17,22 +18,7 @@ use crate::{services, Error, Result, Ruma};
pub(crate) async fn set_global_account_data_route(
body: Ruma<set_global_account_data::v3::Request>,
) -> Result<set_global_account_data::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let data: serde_json::Value = serde_json::from_str(body.data.json().get())
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Data is invalid."))?;
let event_type = body.event_type.to_string();
services().account_data.update(
None,
sender_user,
event_type.clone().into(),
&json!({
"type": event_type,
"content": data,
}),
)?;
set_account_data(None, &body.sender_user, &body.event_type.to_string(), body.data.json())?;
Ok(set_global_account_data::v3::Response {})
}
@@ -43,21 +29,11 @@ pub(crate) async fn set_global_account_data_route(
pub(crate) async fn set_room_account_data_route(
body: Ruma<set_room_account_data::v3::Request>,
) -> Result<set_room_account_data::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let data: serde_json::Value = serde_json::from_str(body.data.json().get())
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Data is invalid."))?;
let event_type = body.event_type.to_string();
services().account_data.update(
set_account_data(
Some(&body.room_id),
sender_user,
event_type.clone().into(),
&json!({
"type": event_type,
"content": data,
}),
&body.sender_user,
&body.event_type.to_string(),
body.data.json(),
)?;
Ok(set_room_account_data::v3::Response {})
@@ -74,7 +50,7 @@ pub(crate) async fn get_global_account_data_route(
let event: Box<RawJsonValue> = services()
.account_data
.get(None, sender_user, body.event_type.to_string().into())?
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
let account_data = serde_json::from_str::<ExtractGlobalEventContent>(event.get())
.map_err(|_| Error::bad_database("Invalid account data event in db."))?
@@ -96,7 +72,7 @@ pub(crate) async fn get_room_account_data_route(
let event: Box<RawJsonValue> = services()
.account_data
.get(Some(&body.room_id), sender_user, body.event_type.clone())?
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
.ok_or_else(|| Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
let account_data = serde_json::from_str::<ExtractRoomEventContent>(event.get())
.map_err(|_| Error::bad_database("Invalid account data event in db."))?
@@ -107,6 +83,27 @@ pub(crate) async fn get_room_account_data_route(
})
}
fn set_account_data(
room_id: Option<&RoomId>, sender_user: &Option<OwnedUserId>, event_type: &str, data: &RawJsonValue,
) -> Result<()> {
let sender_user = sender_user.as_ref().expect("user is authenticated");
let data: serde_json::Value =
serde_json::from_str(data.get()).map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Data is invalid."))?;
services().account_data.update(
room_id,
sender_user,
event_type.into(),
&json!({
"type": event_type,
"content": data,
}),
)?;
Ok(())
}
#[derive(Deserialize)]
struct ExtractRoomEventContent {
content: Raw<AnyRoomAccountDataEventContent>,
+2 -4
View File
@@ -188,14 +188,12 @@ pub(crate) async fn get_context_route(body: Ruma<get_context::v3::Request>) -> R
}
}
let resp = get_context::v3::Response {
Ok(get_context::v3::Response {
start: Some(start_token),
end: Some(end_token),
events_before,
event: Some(base_event),
events_after,
state,
};
Ok(resp)
})
}
+2 -2
View File
@@ -24,7 +24,7 @@ use ruma::{
};
use tracing::{error, info, warn};
use crate::{services, Error, Result, Ruma};
use crate::{services, utils::server_name::server_is_ours, Error, Result, Ruma};
/// # `POST /_matrix/client/v3/publicRooms`
///
@@ -173,7 +173,7 @@ pub(crate) async fn get_room_visibility_route(
pub(crate) async fn get_public_rooms_filtered_helper(
server: Option<&ServerName>, limit: Option<UInt>, since: Option<&str>, filter: &Filter, _network: &RoomNetwork,
) -> Result<get_public_rooms_filtered::v3::Response> {
if let Some(other_server) = server.filter(|server| *server != services().globals.server_name().as_str()) {
if let Some(other_server) = server.filter(|server_name| !server_is_ours(server_name)) {
let response = services()
.sending
.send_federation_request(
+10 -10
View File
@@ -20,7 +20,11 @@ use serde_json::json;
use tracing::debug;
use super::SESSION_ID_LENGTH;
use crate::{services, utils, Error, Result, Ruma};
use crate::{
services,
utils::{self, user_id::user_is_local},
Error, Result, Ruma,
};
/// # `POST /_matrix/client/r0/keys/upload`
///
@@ -71,24 +75,20 @@ pub(crate) async fn upload_keys_route(body: Ruma<upload_keys::v3::Request>) -> R
pub(crate) async fn get_keys_route(body: Ruma<get_keys::v3::Request>) -> Result<get_keys::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let response = get_keys_helper(
get_keys_helper(
Some(sender_user),
&body.device_keys,
|u| u == sender_user,
true, // Always allow local users to see device names of other local users
)
.await?;
Ok(response)
.await
}
/// # `POST /_matrix/client/r0/keys/claim`
///
/// Claims one-time keys
pub(crate) async fn claim_keys_route(body: Ruma<claim_keys::v3::Request>) -> Result<claim_keys::v3::Response> {
let response = claim_keys_helper(&body.one_time_keys).await?;
Ok(response)
claim_keys_helper(&body.one_time_keys).await
}
/// # `POST /_matrix/client/r0/keys/device_signing/upload`
@@ -260,7 +260,7 @@ pub(crate) async fn get_keys_helper<F: Fn(&UserId) -> bool>(
for (user_id, device_ids) in device_keys_input {
let user_id: &UserId = user_id;
if user_id.server_name() != services().globals.server_name() {
if !user_is_local(user_id) {
get_over_federation
.entry(user_id.server_name())
.or_insert_with(Vec::new)
@@ -454,7 +454,7 @@ pub(crate) async fn claim_keys_helper(
let mut get_over_federation = BTreeMap::new();
for (user_id, map) in one_time_keys_input {
if user_id.server_name() != services().globals.server_name() {
if !user_is_local(user_id) {
get_over_federation
.entry(user_id.server_name())
.or_insert_with(Vec::new)
+13 -9
View File
@@ -16,7 +16,9 @@ use webpage::HTML;
use crate::{
debug_warn,
service::media::{FileMeta, UrlPreviewData},
services, utils, Error, Result, Ruma, RumaResponse,
services,
utils::{self, server_name::server_is_ours},
Error, Result, Ruma, RumaResponse,
};
/// generated MXC ID (`media-id`) length
@@ -25,6 +27,8 @@ const MXC_LENGTH: usize = 32;
/// Cache control for immutable objects
const CACHE_CONTROL_IMMUTABLE: &str = "public, max-age=31536000, immutable";
const CORP_CROSS_ORIGIN: &str = "cross-origin";
/// # `GET /_matrix/media/v3/config`
///
/// Returns max upload size.
@@ -178,10 +182,10 @@ pub(crate) async fn get_content_route(body: Ruma<get_content::v3::Request>) -> R
file,
content_type,
content_disposition,
cross_origin_resource_policy: Some("cross-origin".to_owned()),
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()),
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
})
} else if &*body.server_name != services().globals.server_name() && body.allow_remote {
} else if !server_is_ours(&body.server_name) && body.allow_remote {
get_remote_content(
&mxc,
&body.server_name,
@@ -240,10 +244,10 @@ pub(crate) async fn get_content_as_filename_route(
file,
content_type,
content_disposition: Some(format!("inline; filename={}", body.filename)),
cross_origin_resource_policy: Some("cross-origin".to_owned()),
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()),
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
})
} else if &*body.server_name != services().globals.server_name() && body.allow_remote {
} else if !server_is_ours(&body.server_name) && body.allow_remote {
match get_remote_content(
&mxc,
&body.server_name,
@@ -257,7 +261,7 @@ pub(crate) async fn get_content_as_filename_route(
content_disposition: Some(format!("inline: filename={}", body.filename)),
content_type: remote_content_response.content_type,
file: remote_content_response.file,
cross_origin_resource_policy: Some("cross-origin".to_owned()),
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()),
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
}),
Err(e) => {
@@ -321,10 +325,10 @@ pub(crate) async fn get_content_thumbnail_route(
Ok(get_content_thumbnail::v3::Response {
file,
content_type,
cross_origin_resource_policy: Some("cross-origin".to_owned()),
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()),
cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()),
})
} else if &*body.server_name != services().globals.server_name() && body.allow_remote {
} else if !server_is_ours(&body.server_name) && body.allow_remote {
if services()
.globals
.prevent_media_downloads_from()
@@ -407,7 +411,7 @@ async fn get_remote_content(
{
// we'll lie to the client and say the blocked server's media was not found and
// log. the client has no way of telling anyways so this is a security bonus.
debug_warn!("Received request for media `{}` on blocklisted server", mxc);
debug_warn!("Received request for media `{mxc}` on blocklisted server");
return Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."));
}
+7 -5
View File
@@ -34,7 +34,9 @@ use tracing::{debug, error, info, trace, warn};
use super::get_alias_helper;
use crate::{
service::pdu::{gen_event_id_canonical_json, PduBuilder},
services, utils, Error, PduEvent, Result, Ruma,
services,
utils::{self, server_name::server_is_ours, user_id::user_is_local},
Error, PduEvent, Result, Ruma,
};
/// # `POST /_matrix/client/r0/rooms/{roomId}/join`
@@ -1088,7 +1090,7 @@ pub(crate) async fn join_room_by_id_helper(
.state_cache
.room_members(room_id)
.filter_map(Result::ok)
.filter(|user| user.server_name() == services().globals.server_name())
.filter(|user| user_is_local(user))
.collect::<Vec<OwnedUserId>>();
let mut authorized_user: Option<OwnedUserId> = None;
@@ -1150,7 +1152,7 @@ pub(crate) async fn join_room_by_id_helper(
if !restriction_rooms.is_empty()
&& servers
.iter()
.any(|s| *s != services().globals.server_name())
.any(|server_name| !server_is_ours(server_name))
{
info!(
"We couldn't do the join locally, maybe federation can help to satisfy the restricted join \
@@ -1303,7 +1305,7 @@ async fn make_join_request(
let mut incompatible_room_version_count = 0;
for remote_server in servers {
if remote_server == services().globals.server_name() {
if server_is_ours(remote_server) {
continue;
}
info!("Asking {remote_server} for make_join ({make_join_counter})");
@@ -1436,7 +1438,7 @@ pub(crate) async fn invite_helper(
));
}
if user_id.server_name() != services().globals.server_name() {
if !user_is_local(user_id) {
let (pdu, pdu_json, invite_room_state) = {
let mutex_state = Arc::clone(
services()
+1 -1
View File
@@ -42,7 +42,7 @@ pub(crate) async fn get_presence_route(body: Ruma<get_presence::v3::Request>) ->
.user
.get_shared_rooms(vec![sender_user.clone(), body.user_id.clone()])?
{
if let Some(presence) = services().presence.get_presence(sender_user)? {
if let Some(presence) = services().presence.get_presence(&body.user_id)? {
presence_event = Some(presence);
break;
}
+4 -4
View File
@@ -13,7 +13,7 @@ use ruma::{
};
use serde_json::value::to_raw_value;
use crate::{service::pdu::PduBuilder, services, Error, Result, Ruma};
use crate::{service::pdu::PduBuilder, services, utils::user_id::user_is_local, Error, Result, Ruma};
/// # `PUT /_matrix/client/r0/profile/{userId}/displayname`
///
@@ -105,7 +105,7 @@ pub(crate) async fn set_displayname_route(
pub(crate) async fn get_displayname_route(
body: Ruma<get_display_name::v3::Request>,
) -> Result<get_display_name::v3::Response> {
if body.user_id.server_name() != services().globals.server_name() {
if !user_is_local(&body.user_id) {
// Create and update our local copy of the user
if let Ok(response) = services()
.sending
@@ -247,7 +247,7 @@ pub(crate) async fn set_avatar_url_route(
pub(crate) async fn get_avatar_url_route(
body: Ruma<get_avatar_url::v3::Request>,
) -> Result<get_avatar_url::v3::Response> {
if body.user_id.server_name() != services().globals.server_name() {
if !user_is_local(&body.user_id) {
// Create and update our local copy of the user
if let Ok(response) = services()
.sending
@@ -303,7 +303,7 @@ pub(crate) async fn get_avatar_url_route(
/// - If user is on another server and we do not have a local copy already,
/// fetch profile over federation.
pub(crate) async fn get_profile_route(body: Ruma<get_profile::v3::Request>) -> Result<get_profile::v3::Response> {
if body.user_id.server_name() != services().globals.server_name() {
if !user_is_local(&body.user_id) {
// Create and update our local copy of the user
if let Ok(response) = services()
.sending
+71 -51
View File
@@ -4,12 +4,12 @@ use rand::Rng;
use ruma::{
api::client::{error::ErrorKind, room::report_content},
events::room::message,
int,
int, EventId, RoomId, UserId,
};
use tokio::time::sleep;
use tracing::{debug, info};
use tracing::info;
use crate::{services, utils::HtmlEscape, Error, Result, Ruma};
use crate::{debug_info, service::pdu::PduEvent, services, utils::HtmlEscape, Error, Result, Ruma};
/// # `POST /_matrix/client/v3/rooms/{roomId}/report/{eventId}`
///
@@ -20,7 +20,10 @@ pub(crate) async fn report_event_route(
// user authentication
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
info!("Received /report request by user {}", sender_user);
info!(
"Received /report request by user {sender_user} for room {} and event ID {}",
body.room_id, body.event_id
);
// check if we know about the reported event ID or if it's invalid
let Some(pdu) = services().rooms.timeline.get_pdu(&body.event_id)? else {
@@ -30,43 +33,7 @@ pub(crate) async fn report_event_route(
));
};
// check if the room ID from the URI matches the PDU's room ID
if body.room_id != pdu.room_id {
return Err(Error::BadRequest(
ErrorKind::NotFound,
"Event ID does not belong to the reported room",
));
}
// check if reporting user is in the reporting room
if !services()
.rooms
.state_cache
.room_members(&pdu.room_id)
.filter_map(Result::ok)
.any(|user_id| user_id == *sender_user)
{
return Err(Error::BadRequest(
ErrorKind::NotFound,
"You are not in the room you are reporting.",
));
}
// check if score is in valid range
if let Some(true) = body.score.map(|s| s > int!(0) || s < int!(-100)) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Invalid score, must be within 0 to -100",
));
};
// check if report reasoning is less than or equal to 750 characters
if let Some(true) = body.reason.clone().map(|s| s.chars().count() >= 750) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Reason too long, should be 750 characters or fewer",
));
};
is_report_valid(&pdu.event_id, &body.room_id, sender_user, &body.reason, body.score, &pdu)?;
// send admin room message that we received the report with an @room ping for
// urgency
@@ -97,17 +64,70 @@ pub(crate) async fn report_event_route(
body.score.unwrap_or_else(|| ruma::Int::from(0)),
HtmlEscape(body.reason.as_deref().unwrap_or(""))
),
));
))
.await;
// even though this is kinda security by obscurity, let's still make a small
// random delay sending a successful response per spec suggestion regarding
// enumerating for potential events existing in our server.
let time_to_wait = rand::thread_rng().gen_range(8..21);
debug!(
"Got successful /report request, waiting {} seconds before sending successful response.",
time_to_wait
);
sleep(Duration::from_secs(time_to_wait)).await;
delay_response().await?;
Ok(report_content::v3::Response {})
}
/// in the following order:
///
/// check if the room ID from the URI matches the PDU's room ID
/// check if reporting user is in the reporting room
/// check if score is in valid range
/// check if report reasoning is less than or equal to 750 characters
fn is_report_valid(
event_id: &EventId, room_id: &RoomId, sender_user: &UserId, reason: &Option<String>, score: Option<ruma::Int>,
pdu: &std::sync::Arc<PduEvent>,
) -> Result<bool> {
debug_info!("Checking if report from user {sender_user} for event {event_id} in room {room_id} is valid");
if room_id != pdu.room_id {
return Err(Error::BadRequest(
ErrorKind::NotFound,
"Event ID does not belong to the reported room",
));
}
if services()
.rooms
.state_cache
.room_members(&pdu.room_id)
.filter_map(Result::ok)
.any(|user_id| user_id != *sender_user)
{
return Err(Error::BadRequest(
ErrorKind::NotFound,
"You are not in the room you are reporting.",
));
}
if let Some(true) = score.map(|s| s > int!(0) || s < int!(-100)) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Invalid score, must be within 0 to -100",
));
};
if let Some(true) = reason.clone().map(|s| s.len() >= 750) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Reason too long, should be 750 characters or fewer",
));
};
Ok(true)
}
/// even though this is kinda security by obscurity, let's still make a small
/// random delay sending a successful response per spec suggestion regarding
/// enumerating for potential events existing in our server.
async fn delay_response() -> Result<()> {
let time_to_wait = rand::thread_rng().gen_range(8..21);
debug_info!("Got successful /report request, waiting {time_to_wait} seconds before sending successful response.");
sleep(Duration::from_secs(time_to_wait)).await;
Ok(())
}
+204 -186
View File
@@ -21,13 +21,31 @@ use ruma::{
StateEventType, TimelineEventType,
},
int,
serde::JsonObject,
CanonicalJsonObject, CanonicalJsonValue, OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId, RoomVersionId,
serde::{JsonObject, Raw},
CanonicalJsonObject, Int, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, RoomVersionId,
};
use serde_json::{json, value::to_raw_value};
use tracing::{debug, error, info, warn};
use tracing::{error, info, warn};
use crate::{api::client_server::invite_helper, service::pdu::PduBuilder, services, Error, Result, Ruma};
use crate::{
api::client_server::invite_helper,
debug_info, debug_warn,
service::{appservice::RegistrationInfo, pdu::PduBuilder},
services, Error, Result, Ruma,
};
/// Recommended transferable state events list from the spec
const TRANSFERABLE_STATE_EVENTS: &[StateEventType; 9] = &[
StateEventType::RoomServerAcl,
StateEventType::RoomEncryption,
StateEventType::RoomName,
StateEventType::RoomAvatar,
StateEventType::RoomTopic,
StateEventType::RoomGuestAccess,
StateEventType::RoomHistoryVisibility,
StateEventType::RoomJoinRules,
StateEventType::RoomPowerLevels,
];
/// # `POST /_matrix/client/v3/createRoom`
///
@@ -57,55 +75,11 @@ pub(crate) async fn create_room_route(body: Ruma<create_room::v3::Request>) -> R
return Err(Error::BadRequest(ErrorKind::forbidden(), "Room creation has been disabled."));
}
let room_id: OwnedRoomId;
// checks if the user specified an explicit (custom) room_id to be created with
// in request body. falls back to normal generated room ID if not specified.
if let Some(CanonicalJsonValue::Object(json_body)) = &body.json_body {
match json_body.get("room_id") {
Some(custom_room_id) => {
let custom_room_id_s = custom_room_id.to_string();
// do some checks on the custom room ID similar to room aliases
if custom_room_id_s.contains(':') {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Custom room ID contained `:` which is not allowed. Please note that this expects a \
localpart, not the full room ID.",
));
} else if custom_room_id_s.contains(char::is_whitespace) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Custom room ID contained spaces which is not valid.",
));
} else if custom_room_id_s.len() > 255 {
return Err(Error::BadRequest(ErrorKind::InvalidParam, "Custom room ID is too long."));
}
// apply forbidden room alias checks to custom room IDs too
if services()
.globals
.forbidden_alias_names()
.is_match(&custom_room_id_s)
{
return Err(Error::BadRequest(ErrorKind::Unknown, "Custom room ID is forbidden."));
}
let full_room_id = "!".to_owned()
+ &custom_room_id_s.replace('"', "")
+ ":" + services().globals.server_name().as_ref();
debug!("Full room ID: {}", full_room_id);
room_id = RoomId::parse(full_room_id).map_err(|e| {
info!("User attempted to create room with custom room ID but failed parsing: {}", e);
Error::BadRequest(ErrorKind::InvalidParam, "Custom room ID could not be parsed")
})?;
},
None => room_id = RoomId::new(services().globals.server_name()),
}
let room_id: OwnedRoomId = if let Some(custom_room_id) = &body.room_id {
custom_room_id_check(custom_room_id)?
} else {
room_id = RoomId::new(services().globals.server_name());
}
RoomId::new(&services().globals.config.server_name)
};
// check if room ID doesn't already exist instead of erroring on auth check
if services().rooms.short.get_shortroomid(&room_id)?.is_some() {
@@ -128,74 +102,11 @@ pub(crate) async fn create_room_route(body: Ruma<create_room::v3::Request>) -> R
);
let state_lock = mutex_state.lock().await;
let alias: Option<OwnedRoomAliasId> = body
.room_alias_name
.as_ref()
.map_or(Ok(None), |localpart| {
// Basic checks on the room alias validity
if localpart.contains(':') {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room alias contained `:` which is not allowed. Please note that this expects a localpart, not \
the full room alias.",
));
} else if localpart.contains(char::is_whitespace) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room alias contained spaces which is not a valid room alias.",
));
} else if localpart.len() > 255 {
// there is nothing spec-wise saying to check the limit of this,
// however absurdly long room aliases are guaranteed to be unreadable or done
// maliciously. there is no reason a room alias should even exceed 100
// characters as is. generally in spec, 255 is matrix's fav number
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room alias is excessively long, clients may not be able to handle this. Please shorten it.",
));
} else if localpart.contains('"') {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room alias contained `\"` which is not allowed.",
));
}
// check if room alias is forbidden
if services()
.globals
.forbidden_alias_names()
.is_match(localpart)
{
return Err(Error::BadRequest(ErrorKind::Unknown, "Room alias name is forbidden."));
}
let alias =
RoomAliasId::parse(format!("#{}:{}", localpart, services().globals.server_name())).map_err(|e| {
warn!("Failed to parse room alias for room ID {}: {e}", room_id);
Error::BadRequest(ErrorKind::InvalidParam, "Invalid room alias specified.")
})?;
if services()
.rooms
.alias
.resolve_local_alias(&alias)?
.is_some()
{
Err(Error::BadRequest(ErrorKind::RoomInUse, "Room alias already exists."))
} else {
Ok(Some(alias))
}
})?;
if let Some(ref alias) = alias {
if let Some(ref info) = body.appservice_info {
if !info.aliases.is_match(alias.as_str()) {
return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias is not in namespace."));
}
} else if services().appservice.is_exclusive_alias(alias).await {
return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias reserved by appservice."));
}
}
let alias: Option<OwnedRoomAliasId> = if let Some(alias) = &body.room_alias_name {
Some(room_alias_check(alias, &body.appservice_info).await?)
} else {
None
};
let room_version = match body.room_version.clone() {
Some(room_version) => {
@@ -283,7 +194,7 @@ pub(crate) async fn create_room_route(body: Ruma<create_room::v3::Request>) -> R
};
let mut content = serde_json::from_str::<CanonicalJsonObject>(
to_raw_value(&content)
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Invalid creation content"))?
.expect("we just created this as content was None")
.get(),
)
.unwrap();
@@ -291,23 +202,12 @@ pub(crate) async fn create_room_route(body: Ruma<create_room::v3::Request>) -> R
"room_version".into(),
json!(room_version.as_str())
.try_into()
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Invalid creation content"))?,
.expect("we just created this as content was None"),
);
content
},
};
// Validate creation content
let de_result = serde_json::from_str::<CanonicalJsonObject>(
to_raw_value(&content)
.expect("Invalid creation content")
.get(),
);
if de_result.is_err() {
return Err(Error::BadRequest(ErrorKind::BadJson, "Invalid creation content"));
}
// 1. The room create event
services()
.rooms
@@ -371,39 +271,8 @@ pub(crate) async fn create_room_route(body: Ruma<create_room::v3::Request>) -> R
}
}
let mut power_levels_content = serde_json::to_value(RoomPowerLevelsEventContent {
users,
..Default::default()
})
.expect("event is valid, we just created it");
// secure proper defaults of sensitive/dangerous permissions that moderators
// (power level 50) should not have easy access to
power_levels_content["events"]["m.room.power_levels"] = serde_json::to_value(100).expect("100 is valid Value");
power_levels_content["events"]["m.room.server_acl"] = serde_json::to_value(100).expect("100 is valid Value");
power_levels_content["events"]["m.room.tombstone"] = serde_json::to_value(100).expect("100 is valid Value");
power_levels_content["events"]["m.room.encryption"] = serde_json::to_value(100).expect("100 is valid Value");
power_levels_content["events"]["m.room.history_visibility"] =
serde_json::to_value(100).expect("100 is valid Value");
// synapse does this too. clients do not expose these permissions. it prevents
// default users from calling public rooms, for obvious reasons.
if body.visibility == room::Visibility::Public {
power_levels_content["events"]["m.call.invite"] = serde_json::to_value(50).expect("50 is valid Value");
power_levels_content["events"]["org.matrix.msc3401.call"] =
serde_json::to_value(50).expect("50 is valid Value");
power_levels_content["events"]["org.matrix.msc3401.call.member"] =
serde_json::to_value(50).expect("50 is valid Value");
}
if let Some(power_level_content_override) = &body.power_level_content_override {
let json: JsonObject = serde_json::from_str(power_level_content_override.json().get())
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Invalid power_level_content_override."))?;
for (key, value) in json {
power_levels_content[key] = value;
}
}
let power_levels_content =
default_power_levels_content(&body.power_level_content_override, &body.visibility, users)?;
services()
.rooms
@@ -519,6 +388,17 @@ pub(crate) async fn create_room_route(body: Ruma<create_room::v3::Request>) -> R
Error::BadRequest(ErrorKind::InvalidParam, "Invalid initial state event.")
})?;
debug_warn!("initial state event: {event:?}");
// client/appservice workaround: if a user sends an initial_state event with a
// state event in there with the content of literally `{}` (not null or empty
// string), let's just skip it over and warn.
if pdu_builder.content.get().eq("{}") {
info!("skipping empty initial state event with content of `{{}}`: {event:?}");
debug_warn!("content: {}", pdu_builder.content.get());
continue;
}
// Implicit state key defaults to ""
pdu_builder.state_key.get_or_insert_with(String::new);
@@ -592,7 +472,7 @@ pub(crate) async fn create_room_route(body: Ruma<create_room::v3::Request>) -> R
services().rooms.directory.set_public(&room_id)?;
}
info!("{} created a room", sender_user);
info!("{sender_user} created a room with room ID {room_id}");
Ok(create_room::v3::Response::new(room_id))
}
@@ -811,13 +691,13 @@ pub(crate) async fn upgrade_room_route(body: Ruma<upgrade_room::v3::Request>) ->
);
// Validate creation event content
let de_result = serde_json::from_str::<CanonicalJsonObject>(
if serde_json::from_str::<CanonicalJsonObject>(
to_raw_value(&create_event_content)
.expect("Error forming creation event")
.get(),
);
if de_result.is_err() {
)
.is_err()
{
return Err(Error::BadRequest(ErrorKind::BadJson, "Error forming creation event"));
}
@@ -866,25 +746,12 @@ pub(crate) async fn upgrade_room_route(body: Ruma<upgrade_room::v3::Request>) ->
)
.await?;
// Recommended transferable state events list from the specs
let transferable_state_events = vec![
StateEventType::RoomServerAcl,
StateEventType::RoomEncryption,
StateEventType::RoomName,
StateEventType::RoomAvatar,
StateEventType::RoomTopic,
StateEventType::RoomGuestAccess,
StateEventType::RoomHistoryVisibility,
StateEventType::RoomJoinRules,
StateEventType::RoomPowerLevels,
];
// Replicate transferable state events to the new room
for event_type in transferable_state_events {
for event_type in TRANSFERABLE_STATE_EVENTS {
let event_content = match services()
.rooms
.state_accessor
.room_state_get(&body.room_id, &event_type, "")?
.room_state_get(&body.room_id, event_type, "")?
{
Some(v) => v.content.clone(),
None => continue, // Skipping missing events.
@@ -964,3 +831,154 @@ pub(crate) async fn upgrade_room_route(body: Ruma<upgrade_room::v3::Request>) ->
replacement_room,
})
}
/// creates the power_levels_content for the PDU builder
fn default_power_levels_content(
power_level_content_override: &Option<Raw<RoomPowerLevelsEventContent>>, visibility: &room::Visibility,
users: BTreeMap<OwnedUserId, Int>,
) -> Result<serde_json::Value> {
let mut power_levels_content = serde_json::to_value(RoomPowerLevelsEventContent {
users,
..Default::default()
})
.expect("event is valid, we just created it");
// secure proper defaults of sensitive/dangerous permissions that moderators
// (power level 50) should not have easy access to
power_levels_content["events"]["m.room.power_levels"] = serde_json::to_value(100).expect("100 is valid Value");
power_levels_content["events"]["m.room.server_acl"] = serde_json::to_value(100).expect("100 is valid Value");
power_levels_content["events"]["m.room.tombstone"] = serde_json::to_value(100).expect("100 is valid Value");
power_levels_content["events"]["m.room.encryption"] = serde_json::to_value(100).expect("100 is valid Value");
power_levels_content["events"]["m.room.history_visibility"] =
serde_json::to_value(100).expect("100 is valid Value");
// synapse does this too. clients do not expose these permissions. it prevents
// default users from calling public rooms, for obvious reasons.
if *visibility == room::Visibility::Public {
power_levels_content["events"]["m.call.invite"] = serde_json::to_value(50).expect("50 is valid Value");
power_levels_content["events"]["org.matrix.msc3401.call"] =
serde_json::to_value(50).expect("50 is valid Value");
power_levels_content["events"]["org.matrix.msc3401.call.member"] =
serde_json::to_value(50).expect("50 is valid Value");
}
if let Some(power_level_content_override) = power_level_content_override {
let json: JsonObject = serde_json::from_str(power_level_content_override.json().get())
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Invalid power_level_content_override."))?;
for (key, value) in json {
power_levels_content[key] = value;
}
}
Ok(power_levels_content)
}
/// if a room is being created with a room alias, run our checks
async fn room_alias_check(
room_alias_name: &String, appservice_info: &Option<RegistrationInfo>,
) -> Result<OwnedRoomAliasId> {
// Basic checks on the room alias validity
if room_alias_name.contains(':') {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room alias contained `:` which is not allowed. Please note that this expects a localpart, not the full \
room alias.",
));
} else if room_alias_name.contains(char::is_whitespace) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room alias contained spaces which is not a valid room alias.",
));
} else if room_alias_name.len() > 255 {
// there is nothing spec-wise saying to check the limit of this,
// however absurdly long room aliases are guaranteed to be unreadable or done
// maliciously. there is no reason a room alias should even exceed 100
// characters as is. generally in spec, 255 is matrix's fav number
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room alias is excessively long, clients may not be able to handle this. Please shorten it.",
));
} else if room_alias_name.contains('"') {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Room alias contained `\"` which is not allowed.",
));
}
// check if room alias is forbidden
if services()
.globals
.forbidden_alias_names()
.is_match(room_alias_name)
{
return Err(Error::BadRequest(ErrorKind::Unknown, "Room alias name is forbidden."));
}
let full_room_alias = RoomAliasId::parse(format!("#{}:{}", room_alias_name, services().globals.config.server_name))
.map_err(|e| {
info!("Failed to parse room alias {room_alias_name}: {e}");
Error::BadRequest(ErrorKind::InvalidParam, "Invalid room alias specified.")
})?;
if services()
.rooms
.alias
.resolve_local_alias(&full_room_alias)?
.is_some()
{
return Err(Error::BadRequest(ErrorKind::RoomInUse, "Room alias already exists."));
}
if let Some(ref info) = appservice_info {
if !info.aliases.is_match(full_room_alias.as_str()) {
return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias is not in namespace."));
}
} else if services()
.appservice
.is_exclusive_alias(&full_room_alias)
.await
{
return Err(Error::BadRequest(ErrorKind::Exclusive, "Room alias reserved by appservice."));
}
debug_info!("Full room alias: {full_room_alias}");
Ok(full_room_alias)
}
/// if a room is being created with a custom room ID, run our checks against it
fn custom_room_id_check(custom_room_id: &String) -> Result<OwnedRoomId> {
// apply forbidden room alias checks to custom room IDs too
if services()
.globals
.forbidden_alias_names()
.is_match(custom_room_id)
{
return Err(Error::BadRequest(ErrorKind::Unknown, "Custom room ID is forbidden."));
}
if custom_room_id.contains(':') {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Custom room ID contained `:` which is not allowed. Please note that this expects a localpart, not the \
full room ID.",
));
} else if custom_room_id.contains(char::is_whitespace) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Custom room ID contained spaces which is not valid.",
));
} else if custom_room_id.len() > 255 {
return Err(Error::BadRequest(ErrorKind::InvalidParam, "Custom room ID is too long."));
}
let full_room_id = format!("!{}:{}", custom_room_id, services().globals.config.server_name);
debug_info!("Full custom room ID: {full_room_id}");
RoomId::parse(full_room_id).map_err(|e| {
info!("User attempted to create room with custom room ID {custom_room_id} but failed parsing: {e}");
Error::BadRequest(ErrorKind::InvalidParam, "Custom room ID could not be parsed")
})
}
+80 -130
View File
@@ -20,7 +20,9 @@ use tracing::{error, log::warn};
use crate::{
service::{self, pdu::PduBuilder},
services, Error, Result, Ruma, RumaResponse,
services,
utils::server_name::server_is_ours,
Error, Result, Ruma, RumaResponse,
};
/// # `PUT /_matrix/client/*/rooms/{roomId}/state/{eventType}/{stateKey}`
@@ -40,7 +42,7 @@ pub(crate) async fn send_state_event_for_key_route(
sender_user,
&body.room_id,
&body.event_type,
&body.body.body, // Yes, I hate it too
&body.body.body,
body.state_key.clone(),
)
.await?;
@@ -62,22 +64,7 @@ pub(crate) async fn send_state_event_for_key_route(
pub(crate) async fn send_state_event_for_empty_key_route(
body: Ruma<send_state_event::v3::Request>,
) -> Result<RumaResponse<send_state_event::v3::Response>> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let event_id = send_state_event_for_key_helper(
sender_user,
&body.room_id,
&body.event_type.to_string().into(),
&body.body.body,
body.state_key.clone(),
)
.await?;
let event_id = (*event_id).to_owned();
Ok(send_state_event::v3::Response {
event_id,
}
.into())
send_state_event_for_key_route(body).await.map(RumaResponse)
}
/// # `GET /_matrix/client/v3/rooms/{roomid}/state`
@@ -180,123 +167,13 @@ pub(crate) async fn get_state_events_for_key_route(
pub(crate) async fn get_state_events_for_empty_key_route(
body: Ruma<get_state_events_for_key::v3::Request>,
) -> Result<RumaResponse<get_state_events_for_key::v3::Response>> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
if !services()
.rooms
.state_accessor
.user_can_see_state_events(sender_user, &body.room_id)?
{
return Err(Error::BadRequest(
ErrorKind::forbidden(),
"You don't have permission to view the room state.",
));
}
let event = services()
.rooms
.state_accessor
.room_state_get(&body.room_id, &body.event_type, "")?
.ok_or_else(|| {
warn!("State event {:?} not found in room {:?}", &body.event_type, &body.room_id);
Error::BadRequest(ErrorKind::NotFound, "State event not found.")
})?;
if body
.format
.as_ref()
.is_some_and(|f| f.to_lowercase().eq("event"))
{
Ok(get_state_events_for_key::v3::Response {
content: None,
event: serde_json::from_str(event.to_state_event().json().get()).map_err(|e| {
error!("Invalid room state event in database: {}", e);
Error::bad_database("Invalid room state event in database")
})?,
}
.into())
} else {
Ok(get_state_events_for_key::v3::Response {
content: Some(serde_json::from_str(event.content.get()).map_err(|e| {
error!("Invalid room state event content in database: {}", e);
Error::bad_database("Invalid room state event content in database")
})?),
event: None,
}
.into())
}
get_state_events_for_key_route(body).await.map(RumaResponse)
}
async fn send_state_event_for_key_helper(
sender: &UserId, room_id: &RoomId, event_type: &StateEventType, json: &Raw<AnyStateEventContent>, state_key: String,
) -> Result<Arc<EventId>> {
match *event_type {
// Forbid m.room.encryption if encryption is disabled
StateEventType::RoomEncryption => {
if !services().globals.allow_encryption() {
return Err(Error::BadRequest(ErrorKind::forbidden(), "Encryption has been disabled"));
}
},
// admin room is a sensitive room, it should not ever be made public
StateEventType::RoomJoinRules => {
if let Some(admin_room_id) = service::admin::Service::get_admin_room()? {
if admin_room_id == room_id {
if let Ok(join_rule) = serde_json::from_str::<RoomJoinRulesEventContent>(json.json().get()) {
if join_rule.join_rule == JoinRule::Public {
return Err(Error::BadRequest(
ErrorKind::forbidden(),
"Admin room is not allowed to be public.",
));
}
}
}
}
},
// admin room is a sensitive room, it should not ever be made world readable
StateEventType::RoomHistoryVisibility => {
if let Some(admin_room_id) = service::admin::Service::get_admin_room()? {
if admin_room_id == room_id {
if let Ok(visibility_content) =
serde_json::from_str::<RoomHistoryVisibilityEventContent>(json.json().get())
{
if visibility_content.history_visibility == HistoryVisibility::WorldReadable {
return Err(Error::BadRequest(
ErrorKind::forbidden(),
"Admin room is not allowed to be made world readable (public room history).",
));
}
}
}
}
},
// TODO: allow alias if it previously existed
StateEventType::RoomCanonicalAlias => {
if let Ok(canonical_alias) = serde_json::from_str::<RoomCanonicalAliasEventContent>(json.json().get()) {
let mut aliases = canonical_alias.alt_aliases.clone();
if let Some(alias) = canonical_alias.alias {
aliases.push(alias);
}
for alias in aliases {
if alias.server_name() != services().globals.server_name()
|| services()
.rooms
.alias
.resolve_local_alias(&alias)?
.filter(|room| room == room_id) // Make sure it's the right room
.is_none()
{
return Err(Error::BadRequest(
ErrorKind::forbidden(),
"You are only allowed to send canonical_alias events when its aliases already exist",
));
}
}
}
},
_ => {},
}
allowed_to_send_state_event(room_id, event_type, json).await?;
let mutex_state = Arc::clone(
services()
@@ -328,3 +205,76 @@ async fn send_state_event_for_key_helper(
Ok(event_id)
}
async fn allowed_to_send_state_event(
room_id: &RoomId, event_type: &StateEventType, json: &Raw<AnyStateEventContent>,
) -> Result<()> {
match event_type {
// Forbid m.room.encryption if encryption is disabled
StateEventType::RoomEncryption => {
if !services().globals.allow_encryption() {
return Err(Error::BadRequest(ErrorKind::forbidden(), "Encryption has been disabled"));
}
},
// admin room is a sensitive room, it should not ever be made public
StateEventType::RoomJoinRules => {
if let Some(admin_room_id) = service::admin::Service::get_admin_room().await? {
if admin_room_id == room_id {
if let Ok(join_rule) = serde_json::from_str::<RoomJoinRulesEventContent>(json.json().get()) {
if join_rule.join_rule == JoinRule::Public {
return Err(Error::BadRequest(
ErrorKind::forbidden(),
"Admin room is not allowed to be public.",
));
}
}
}
}
},
// admin room is a sensitive room, it should not ever be made world readable
StateEventType::RoomHistoryVisibility => {
if let Some(admin_room_id) = service::admin::Service::get_admin_room().await? {
if admin_room_id == room_id {
if let Ok(visibility_content) =
serde_json::from_str::<RoomHistoryVisibilityEventContent>(json.json().get())
{
if visibility_content.history_visibility == HistoryVisibility::WorldReadable {
return Err(Error::BadRequest(
ErrorKind::forbidden(),
"Admin room is not allowed to be made world readable (public room history).",
));
}
}
}
}
},
// TODO: allow alias if it previously existed
StateEventType::RoomCanonicalAlias => {
if let Ok(canonical_alias) = serde_json::from_str::<RoomCanonicalAliasEventContent>(json.json().get()) {
let mut aliases = canonical_alias.alt_aliases.clone();
if let Some(alias) = canonical_alias.alias {
aliases.push(alias);
}
for alias in aliases {
if !server_is_ours(alias.server_name())
|| services()
.rooms
.alias
.resolve_local_alias(&alias)?
.filter(|room| room == room_id) // Make sure it's the right room
.is_none()
{
return Err(Error::BadRequest(
ErrorKind::forbidden(),
"You are only allowed to send canonical_alias events when its aliases already exist",
));
}
}
}
},
_ => (),
}
Ok(())
}
+176 -159
View File
@@ -28,7 +28,7 @@ use ruma::{
uint, DeviceId, EventId, OwnedDeviceId, OwnedUserId, RoomId, UInt, UserId,
};
use tokio::sync::watch::Sender;
use tracing::{debug, error};
use tracing::{debug, error, Instrument as _, Span};
use crate::{
service::{pdu::EventHash, rooms::timeline::PduCount},
@@ -271,164 +271,17 @@ async fn sync_helper(
.rooms_left(&sender_user)
.collect();
for result in all_left_rooms {
let (room_id, _) = result?;
{
// Get and drop the lock to wait for remaining operations to finish
let mutex_insert = Arc::clone(
services()
.globals
.roomid_mutex_insert
.write()
.await
.entry(room_id.clone())
.or_default(),
);
let insert_lock = mutex_insert.lock().await;
drop(insert_lock);
};
let left_count = services()
.rooms
.state_cache
.get_left_count(&room_id, &sender_user)?;
// Left before last sync
if Some(since) >= left_count {
continue;
}
if !services().rooms.metadata.exists(&room_id)? {
// This is just a rejected invite, not a room we know
// Insert a leave event anyways
let event = PduEvent {
event_id: EventId::new(services().globals.server_name()).into(),
sender: sender_user.clone(),
origin: None,
origin_server_ts: utils::millis_since_unix_epoch()
.try_into()
.expect("Timestamp is valid js_int value"),
kind: TimelineEventType::RoomMember,
content: serde_json::from_str(r#"{"membership":"leave"}"#).expect("this is valid JSON"),
state_key: Some(sender_user.to_string()),
unsigned: None,
// The following keys are dropped on conversion
room_id: room_id.clone(),
prev_events: vec![],
depth: uint!(1),
auth_events: vec![],
redacts: None,
hashes: EventHash {
sha256: String::new(),
},
signatures: None,
};
left_rooms.insert(
room_id,
LeftRoom {
account_data: RoomAccountData {
events: Vec::new(),
},
timeline: Timeline {
limited: false,
prev_batch: Some(next_batch_string.clone()),
events: Vec::new(),
},
state: State {
events: vec![event.to_sync_state_event()],
},
},
);
continue;
}
let mut left_state_events = Vec::new();
let since_shortstatehash = services()
.rooms
.user
.get_token_shortstatehash(&room_id, since)?;
let since_state_ids = match since_shortstatehash {
Some(s) => services().rooms.state_accessor.state_full_ids(s).await?,
None => HashMap::new(),
};
let Some(left_event_id) = services().rooms.state_accessor.room_state_get_id(
&room_id,
&StateEventType::RoomMember,
sender_user.as_str(),
)?
else {
error!("Left room but no left state event");
continue;
};
let Some(left_shortstatehash) = services()
.rooms
.state_accessor
.pdu_shortstatehash(&left_event_id)?
else {
error!("Leave event has no state");
continue;
};
let mut left_state_ids = services()
.rooms
.state_accessor
.state_full_ids(left_shortstatehash)
.await?;
let leave_shortstatekey = services()
.rooms
.short
.get_or_create_shortstatekey(&StateEventType::RoomMember, sender_user.as_str())?;
left_state_ids.insert(leave_shortstatekey, left_event_id);
let mut i = 0;
for (key, id) in left_state_ids {
if full_state || since_state_ids.get(&key) != Some(&id) {
let (event_type, state_key) = services().rooms.short.get_statekey_from_short(key)?;
if !lazy_load_enabled
|| event_type != StateEventType::RoomMember
|| full_state
// TODO: Delete the following line when this is resolved: https://github.com/vector-im/element-web/issues/22565
|| (cfg!(feature = "element_hacks") && *sender_user == state_key)
{
let Some(pdu) = services().rooms.timeline.get_pdu(&id)? else {
error!("Pdu in state not found: {}", id);
continue;
};
left_state_events.push(pdu.to_sync_state_event());
i += 1;
if i % 100 == 0 {
tokio::task::yield_now().await;
}
}
}
}
left_rooms.insert(
room_id.clone(),
LeftRoom {
account_data: RoomAccountData {
events: Vec::new(),
},
timeline: Timeline {
limited: false,
prev_batch: Some(next_batch_string.clone()),
events: Vec::new(),
},
state: State {
events: left_state_events,
},
},
);
handle_left_room(
since,
&result?.0,
&sender_user,
&mut left_rooms,
&next_batch_string,
full_state,
lazy_load_enabled,
)
.instrument(Span::current())
.await?;
}
let mut invited_rooms = BTreeMap::new();
@@ -567,6 +420,170 @@ async fn sync_helper(
}
}
#[tracing::instrument(skip_all, fields(user_id = %sender_user, room_id = %room_id))]
async fn handle_left_room(
since: u64, room_id: &RoomId, sender_user: &UserId, left_rooms: &mut BTreeMap<ruma::OwnedRoomId, LeftRoom>,
next_batch_string: &str, full_state: bool, lazy_load_enabled: bool,
) -> Result<()> {
{
// Get and drop the lock to wait for remaining operations to finish
let mutex_insert = Arc::clone(
services()
.globals
.roomid_mutex_insert
.write()
.await
.entry(room_id.to_owned())
.or_default(),
);
let insert_lock = mutex_insert.lock().await;
drop(insert_lock);
};
let left_count = services()
.rooms
.state_cache
.get_left_count(room_id, sender_user)?;
// Left before last sync
if Some(since) >= left_count {
return Ok(());
}
if !services().rooms.metadata.exists(room_id)? {
// This is just a rejected invite, not a room we know
// Insert a leave event anyways
let event = PduEvent {
event_id: EventId::new(services().globals.server_name()).into(),
sender: sender_user.to_owned(),
origin: None,
origin_server_ts: utils::millis_since_unix_epoch()
.try_into()
.expect("Timestamp is valid js_int value"),
kind: TimelineEventType::RoomMember,
content: serde_json::from_str(r#"{"membership":"leave"}"#).expect("this is valid JSON"),
state_key: Some(sender_user.to_string()),
unsigned: None,
// The following keys are dropped on conversion
room_id: room_id.to_owned(),
prev_events: vec![],
depth: uint!(1),
auth_events: vec![],
redacts: None,
hashes: EventHash {
sha256: String::new(),
},
signatures: None,
};
left_rooms.insert(
room_id.to_owned(),
LeftRoom {
account_data: RoomAccountData {
events: Vec::new(),
},
timeline: Timeline {
limited: false,
prev_batch: Some(next_batch_string.to_owned()),
events: Vec::new(),
},
state: State {
events: vec![event.to_sync_state_event()],
},
},
);
return Ok(());
}
let mut left_state_events = Vec::new();
let since_shortstatehash = services()
.rooms
.user
.get_token_shortstatehash(room_id, since)?;
let since_state_ids = match since_shortstatehash {
Some(s) => services().rooms.state_accessor.state_full_ids(s).await?,
None => HashMap::new(),
};
let Some(left_event_id) = services().rooms.state_accessor.room_state_get_id(
room_id,
&StateEventType::RoomMember,
sender_user.as_str(),
)?
else {
error!("Left room but no left state event");
return Ok(());
};
let Some(left_shortstatehash) = services()
.rooms
.state_accessor
.pdu_shortstatehash(&left_event_id)?
else {
error!(event_id = %left_event_id, "Leave event has no state");
return Ok(());
};
let mut left_state_ids = services()
.rooms
.state_accessor
.state_full_ids(left_shortstatehash)
.await?;
let leave_shortstatekey = services()
.rooms
.short
.get_or_create_shortstatekey(&StateEventType::RoomMember, sender_user.as_str())?;
left_state_ids.insert(leave_shortstatekey, left_event_id);
let mut i = 0;
for (key, id) in left_state_ids {
if full_state || since_state_ids.get(&key) != Some(&id) {
let (event_type, state_key) = services().rooms.short.get_statekey_from_short(key)?;
if !lazy_load_enabled
|| event_type != StateEventType::RoomMember
|| full_state
// TODO: Delete the following line when this is resolved: https://github.com/vector-im/element-web/issues/22565
|| (cfg!(feature = "element_hacks") && *sender_user == state_key)
{
let Some(pdu) = services().rooms.timeline.get_pdu(&id)? else {
error!("Pdu in state not found: {}", id);
continue;
};
left_state_events.push(pdu.to_sync_state_event());
i += 1;
if i % 100 == 0 {
tokio::task::yield_now().await;
}
}
}
}
left_rooms.insert(
room_id.to_owned(),
LeftRoom {
account_data: RoomAccountData {
events: Vec::new(),
},
timeline: Timeline {
limited: false,
prev_batch: Some(next_batch_string.to_owned()),
events: Vec::new(),
},
state: State {
events: left_state_events,
},
},
);
Ok(())
}
async fn process_presence_updates(
presence_updates: &mut HashMap<OwnedUserId, PresenceEvent>, since: u64, syncing_user: &OwnedUserId,
) -> Result<()> {
+2 -2
View File
@@ -8,7 +8,7 @@ use ruma::{
to_device::DeviceIdOrAllDevices,
};
use crate::{services, Error, Result, Ruma};
use crate::{services, utils::user_id::user_is_local, Error, Result, Ruma};
/// # `PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}`
///
@@ -30,7 +30,7 @@ pub(crate) async fn send_event_to_device_route(
for (target_user_id, map) in &body.messages {
for (target_device_id_maybe, event) in map {
if target_user_id.server_name() != services().globals.server_name() {
if !user_is_local(target_user_id) {
let mut map = BTreeMap::new();
map.insert(target_device_id_maybe.clone(), event.clone());
let mut messages = BTreeMap::new();
+3 -13
View File
@@ -10,7 +10,7 @@ use ruma::api::client::{
error::ErrorKind,
};
use crate::{services, Error, Result, Ruma};
use crate::{services, utils::conduwuit_version, Error, Result, Ruma};
/// # `GET /_matrix/client/versions`
///
@@ -142,14 +142,9 @@ pub(crate) async fn syncv3_client_server_json() -> Result<impl IntoResponse> {
},
};
let version = match option_env!("CONDUIT_VERSION_EXTRA") {
Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra),
None => env!("CARGO_PKG_VERSION").to_owned(),
};
Ok(Json(serde_json::json!({
"server": server_url,
"version": version,
"version": conduwuit_version(),
})))
}
@@ -158,13 +153,8 @@ pub(crate) async fn syncv3_client_server_json() -> Result<impl IntoResponse> {
/// Conduwuit-specific API to get the server version, results akin to
/// `/_matrix/federation/v1/version`
pub(crate) async fn conduwuit_server_version() -> Result<impl IntoResponse> {
let version = match option_env!("CONDUIT_VERSION_EXTRA") {
Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra),
None => env!("CARGO_PKG_VERSION").to_owned(),
};
Ok(Json(serde_json::json!({
"name": "Conduwuit",
"version": version,
"version": conduwuit_version(),
})))
}
+3 -3
View File
@@ -26,7 +26,7 @@ use serde::Deserialize;
use tracing::{debug, error, trace, warn};
use super::{Ruma, RumaResponse};
use crate::{service::appservice::RegistrationInfo, services, Error, Result};
use crate::{debug_warn, service::appservice::RegistrationInfo, services, Error, Result};
enum Token {
Appservice(Box<RegistrationInfo>),
@@ -317,8 +317,8 @@ where
trace!("{:?} {:?} {:?}", http_request.method(), http_request.uri(), json_body);
let body = T::try_from_http_request(http_request, &path_params).map_err(|e| {
warn!("try_from_http_request failed: {e:?}\nPath parameters: {path_params:?}",);
debug!("JSON body: {:?}", json_body);
warn!("try_from_http_request failed: {e:?}",);
debug_warn!("JSON body: {:?}", json_body);
Error::BadRequest(ErrorKind::BadJson, "Failed to deserialize request.")
})?;
+10 -21
View File
@@ -55,7 +55,9 @@ use crate::{
api::client_server::{self, claim_keys_helper, get_keys_helper},
debug_error,
service::pdu::{gen_event_id_canonical_json, PduBuilder},
services, utils, Error, PduEvent, Result, Ruma,
services,
utils::{self, server_name::server_is_ours, user_id::user_is_local},
Error, PduEvent, Result, Ruma,
};
/// # `GET /_matrix/federation/v1/version`
@@ -64,15 +66,10 @@ use crate::{
pub(crate) async fn get_server_version_route(
_body: Ruma<get_server_version::v1::Request>,
) -> Result<get_server_version::v1::Response> {
let version = match option_env!("CONDUIT_VERSION_EXTRA") {
Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra),
None => env!("CARGO_PKG_VERSION").to_owned(),
};
Ok(get_server_version::v1::Response {
server: Some(get_server_version::v1::Server {
name: Some("Conduwuit".to_owned()),
version: Some(version),
version: Some(utils::conduwuit_version()),
}),
})
}
@@ -978,7 +975,7 @@ pub(crate) async fn create_join_event_template_route(
.state_cache
.room_members(&body.room_id)
.filter_map(Result::ok)
.filter(|user| user.server_name() == services().globals.server_name())
.filter(|user| user_is_local(user))
.collect();
let mut auth_user = None;
@@ -1454,7 +1451,7 @@ async fn create_leave_event(sender_servername: &ServerName, room_id: &RoomId, pd
.state_cache
.room_servers(room_id)
.filter_map(Result::ok)
.filter(|server| &**server != services().globals.server_name());
.filter(|server| !server_is_ours(server));
services().sending.send_pdu_servers(servers, &pdu_id)?;
@@ -1649,7 +1646,7 @@ pub(crate) async fn create_invite_route(body: Ruma<create_invite::v2::Request>)
///
/// Gets information on all devices of the user.
pub(crate) async fn get_devices_route(body: Ruma<get_devices::v1::Request>) -> Result<get_devices::v1::Response> {
if body.user_id.server_name() != services().globals.server_name() {
if !user_is_local(&body.user_id) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Tried to access user from other server.",
@@ -1755,7 +1752,7 @@ pub(crate) async fn get_profile_information_route(
));
}
if body.user_id.server_name() != services().globals.server_name() {
if !server_is_ours(body.user_id.server_name()) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"User does not belong to this server",
@@ -1794,11 +1791,7 @@ pub(crate) async fn get_profile_information_route(
///
/// Gets devices and identity keys for the given users.
pub(crate) async fn get_keys_route(body: Ruma<get_keys::v1::Request>) -> Result<get_keys::v1::Response> {
if body
.device_keys
.iter()
.any(|(u, _)| u.server_name() != services().globals.server_name())
{
if body.device_keys.iter().any(|(u, _)| !user_is_local(u)) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"User does not belong to this server.",
@@ -1824,11 +1817,7 @@ pub(crate) async fn get_keys_route(body: Ruma<get_keys::v1::Request>) -> Result<
///
/// Claims one-time keys.
pub(crate) async fn claim_keys_route(body: Ruma<claim_keys::v1::Request>) -> Result<claim_keys::v1::Response> {
if body
.one_time_keys
.iter()
.any(|(u, _)| u.server_name() != services().globals.server_name())
{
if body.one_time_keys.iter().any(|(u, _)| !user_is_local(u)) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Tried to access user from other server.",
+45 -13
View File
@@ -103,6 +103,10 @@ pub(crate) struct Config {
pub(crate) dns_tcp_fallback: bool,
#[serde(default = "true_fn")]
pub(crate) query_all_nameservers: bool,
#[serde(default)]
pub(crate) query_over_tcp_only: bool,
#[serde(default = "default_ip_lookup_strategy")]
pub(crate) ip_lookup_strategy: u8,
#[serde(default = "default_max_request_size")]
pub(crate) max_request_size: u32,
@@ -175,6 +179,12 @@ pub(crate) struct Config {
#[serde(default)]
#[cfg(feature = "perf_measurements")]
pub(crate) tracing_flame: bool,
#[serde(default = "default_tracing_flame_filter")]
#[cfg(feature = "perf_measurements")]
pub(crate) tracing_flame_filter: String,
#[serde(default = "default_tracing_flame_output_path")]
#[cfg(feature = "perf_measurements")]
pub(crate) tracing_flame_output_path: String,
#[serde(default)]
pub(crate) proxy: ProxyConfig,
pub(crate) jwt_secret: Option<String>,
@@ -208,6 +218,8 @@ pub(crate) struct Config {
pub(crate) rocksdb_log_time_to_roll: usize,
#[serde(default)]
pub(crate) rocksdb_optimize_for_spinning_disks: bool,
#[serde(default = "true_fn")]
pub(crate) rocksdb_direct_io: bool,
#[serde(default = "default_rocksdb_parallelism_threads")]
pub(crate) rocksdb_parallelism_threads: usize,
#[serde(default = "default_rocksdb_max_log_files")]
@@ -357,6 +369,7 @@ pub(crate) struct WellKnownConfig {
const DEPRECATED_KEYS: &[&str] = &[
"cache_capacity",
"max_concurrent_requests",
"well_known_client",
"well_known_server",
"well_known_support_page",
@@ -371,22 +384,22 @@ impl Config {
let raw_config = if let Some(config_file_env) = Env::var("CONDUIT_CONFIG") {
Figment::new()
.merge(Toml::file(config_file_env).nested())
.merge(Env::prefixed("CONDUIT_").global())
.merge(Env::prefixed("CONDUWUIT_").global())
.merge(Env::prefixed("CONDUIT_").global().split("__"))
.merge(Env::prefixed("CONDUWUIT_").global().split("__"))
} else if let Some(config_file_arg) = Env::var("CONDUWUIT_CONFIG") {
Figment::new()
.merge(Toml::file(config_file_arg).nested())
.merge(Env::prefixed("CONDUIT_").global())
.merge(Env::prefixed("CONDUWUIT_").global())
.merge(Env::prefixed("CONDUIT_").global().split("__"))
.merge(Env::prefixed("CONDUWUIT_").global().split("__"))
} else if let Some(config_file_arg) = path {
Figment::new()
.merge(Toml::file(config_file_arg).nested())
.merge(Env::prefixed("CONDUIT_").global())
.merge(Env::prefixed("CONDUWUIT_").global())
.merge(Env::prefixed("CONDUIT_").global().split("__"))
.merge(Env::prefixed("CONDUWUIT_").global().split("__"))
} else {
Figment::new()
.merge(Env::prefixed("CONDUIT_").global())
.merge(Env::prefixed("CONDUWUIT_").global())
.merge(Env::prefixed("CONDUIT_").global().split("__"))
.merge(Env::prefixed("CONDUWUIT_").global().split("__"))
};
let config = match raw_config.extract::<Config>() {
@@ -515,11 +528,12 @@ impl fmt::Display for Config {
),
("Cleanup interval in seconds", &self.cleanup_second_interval.to_string()),
("DNS cache entry limit", &self.dns_cache_entries.to_string()),
("DNS minimum ttl", &self.dns_min_ttl.to_string()),
("DNS minimum nxdomain ttl", &self.dns_min_ttl_nxdomain.to_string()),
("DNS minimum TTL", &self.dns_min_ttl.to_string()),
("DNS minimum NXDOMAIN TTL", &self.dns_min_ttl_nxdomain.to_string()),
("DNS attempts", &self.dns_attempts.to_string()),
("DNS timeout", &self.dns_timeout.to_string()),
("DNS fallback to TCP", &self.dns_tcp_fallback.to_string()),
("DNS query over TCP only", &self.query_over_tcp_only.to_string()),
("Query all nameservers", &self.query_all_nameservers.to_string()),
("Maximum request size (bytes)", &self.max_request_size.to_string()),
("Sender retry backoff limit", &self.sender_retry_backoff_limit.to_string()),
@@ -693,6 +707,8 @@ impl fmt::Display for Config {
&self.rocksdb_optimize_for_spinning_disks.to_string(),
),
#[cfg(feature = "rocksdb")]
("RocksDB Direct-IO", &self.rocksdb_direct_io.to_string()),
#[cfg(feature = "rocksdb")]
("RocksDB Parallelism Threads", &self.rocksdb_parallelism_threads.to_string()),
#[cfg(feature = "rocksdb")]
("RocksDB Compression Algorithm", &self.rocksdb_compression_algo),
@@ -798,6 +814,14 @@ impl fmt::Display for Config {
String::new()
},
),
(
"Well-known client URL",
&if let Some(server) = &self.well_known.client {
server.to_string()
} else {
String::new()
},
),
(
"Well-known support email",
&if let Some(support_email) = &self.well_known.support_email {
@@ -886,16 +910,18 @@ fn default_cleanup_second_interval() -> u32 {
1800 // every 30 minutes
}
fn default_dns_cache_entries() -> u32 { 12288 }
fn default_dns_cache_entries() -> u32 { 32768 }
fn default_dns_min_ttl() -> u64 { 60 * 180 }
fn default_dns_min_ttl_nxdomain() -> u64 { 60 * 60 * 24 }
fn default_dns_min_ttl_nxdomain() -> u64 { 60 * 60 * 24 * 3 }
fn default_dns_attempts() -> u16 { 10 }
fn default_dns_timeout() -> u64 { 10 }
fn default_ip_lookup_strategy() -> u8 { 5 }
fn default_max_request_size() -> u32 {
20 * 1024 * 1024 // Default to 20 MB
}
@@ -926,7 +952,7 @@ fn default_sender_idle_timeout() -> u64 { 180 }
fn default_sender_retry_backoff_limit() -> u64 { 86400 }
fn default_appservice_timeout() -> u64 { 120 }
fn default_appservice_timeout() -> u64 { 35 }
fn default_appservice_idle_timeout() -> u64 { 300 }
@@ -934,6 +960,12 @@ fn default_pusher_idle_timeout() -> u64 { 15 }
fn default_max_fetch_prev_events() -> u16 { 100_u16 }
#[cfg(feature = "perf_measurements")]
fn default_tracing_flame_filter() -> String { "trace,h2=off".to_owned() }
#[cfg(feature = "perf_measurements")]
fn default_tracing_flame_output_path() -> String { "./tracing.folded".to_owned() }
fn default_trusted_servers() -> Vec<OwnedServerName> { vec![OwnedServerName::try_from("matrix.org").unwrap()] }
fn default_log() -> String {
+4 -4
View File
@@ -11,7 +11,9 @@ use tracing::error;
use crate::{
database::KeyValueDatabase,
service::{self, appservice::RegistrationInfo},
services, utils, Error, Result,
services,
utils::{self, user_id::user_is_local},
Error, Result,
};
type StrippedStateEventIter<'a> = Box<dyn Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a>;
@@ -149,9 +151,7 @@ impl service::rooms::state_cache::Data for KeyValueDatabase {
for joined in self.room_members(room_id).filter_map(Result::ok) {
joined_servers.insert(joined.server_name().to_owned());
if joined.server_name() == services().globals.server_name()
&& !services().users.is_deactivated(&joined).unwrap_or(true)
{
if user_is_local(&joined) && !services().users.is_deactivated(&joined).unwrap_or(true) {
real_users.insert(joined);
}
joinedcount += 1;
+7 -11
View File
@@ -40,8 +40,8 @@ use tokio::time::{interval, Instant};
use tracing::{debug, error, warn};
use crate::{
database::migrations::migrations, service::rooms::timeline::PduCount, services, Config, Error, Result, Services,
SERVICES,
database::migrations::migrations, service::rooms::timeline::PduCount, services, Config, Error,
LogLevelReloadHandles, Result, Services, SERVICES,
};
pub(crate) struct KeyValueDatabase {
@@ -203,13 +203,7 @@ struct CheckForUpdatesResponse {
impl KeyValueDatabase {
/// Load an existing database or create a new one.
#[allow(clippy::too_many_lines)]
pub(crate) async fn load_or_create(
config: Config,
tracing_reload_handler: tracing_subscriber::reload::Handle<
tracing_subscriber::EnvFilter,
tracing_subscriber::Registry,
>,
) -> Result<()> {
pub(crate) async fn load_or_create(config: Config, tracing_reload_handler: LogLevelReloadHandles) -> Result<()> {
Self::check_db_setup(&config)?;
if !Path::new(&config.database_path).exists() {
@@ -378,7 +372,8 @@ impl KeyValueDatabase {
.send_message(RoomMessageEventContent::text_plain(
"The Conduit account emergency password is set! Please unset it as soon as you finish \
admin account recovery!",
));
))
.await;
}
},
Err(e) => {
@@ -479,7 +474,8 @@ impl KeyValueDatabase {
.send_message(RoomMessageEventContent::text_plain(format!(
"@room: the following is a message from the conduwuit puppy. it was sent on '{}':\n\n{}",
update.date, update.message
)));
)))
.await;
}
}
services()
+10 -5
View File
@@ -22,7 +22,7 @@ pub(crate) fn db_options(config: &Config, env: &mut Env, row_cache: &Cache, col_
// Processing
let threads = if config.rocksdb_parallelism_threads == 0 {
num_cpus::get() // max cores if user specified 0
std::cmp::max(2, num_cpus::get()) // max cores if user specified 0
} else {
config.rocksdb_parallelism_threads
};
@@ -36,8 +36,10 @@ pub(crate) fn db_options(config: &Config, env: &mut Env, row_cache: &Cache, col_
// IO
opts.set_manual_wal_flush(true);
opts.set_use_direct_reads(true);
opts.set_use_direct_io_for_flush_and_compaction(true);
if config.rocksdb_direct_io {
opts.set_use_direct_reads(true);
opts.set_use_direct_io_for_flush_and_compaction(true);
}
if config.rocksdb_optimize_for_spinning_disks {
// speeds up opening DB on hard drives
opts.set_skip_checking_sst_file_sizes_on_db_open(true);
@@ -175,9 +177,12 @@ fn set_logging_defaults(opts: &mut Options, config: &Config) {
fn set_compression_defaults(opts: &mut Options, config: &Config) {
let rocksdb_compression_algo = match config.rocksdb_compression_algo.as_ref() {
"snappy" => DBCompressionType::Snappy,
"zlib" => DBCompressionType::Zlib,
"lz4" => DBCompressionType::Lz4,
"bz2" => DBCompressionType::Bz2,
"lz4" => DBCompressionType::Lz4,
"lz4hc" => DBCompressionType::Lz4hc,
"none" => DBCompressionType::None,
_ => DBCompressionType::Zstd,
};
@@ -219,7 +224,7 @@ fn set_for_random_small(opts: &mut Options, config: &Config) {
}
fn set_for_sequential_small(opts: &mut Options, config: &Config) {
set_for_random(opts, config);
set_for_sequential(opts, config);
opts.set_write_buffer_size(1024 * 512);
opts.set_target_file_size_base(1024 * 512);
+150 -322
View File
@@ -6,53 +6,34 @@ use std::os::unix::fs::PermissionsExt as _; /* not unix specific, just only for
// Not async due to services() being used in many closures, and async closures
// are not stable as of writing This is the case for every other occurence of
// sync Mutex/RwLock, except for database related ones
use std::sync::RwLock;
use std::{any::Any, io, net::SocketAddr, sync::atomic, time::Duration};
use std::sync::{Arc, RwLock};
use std::{io, net::SocketAddr, time::Duration};
use api::ruma_wrapper::{Ruma, RumaResponse};
use axum::{
extract::{DefaultBodyLimit, MatchedPath},
response::IntoResponse,
Router,
};
use axum::Router;
use axum_server::{bind, bind_rustls, tls_rustls::RustlsConfig, Handle as ServerHandle};
#[cfg(feature = "axum_dual_protocol")]
use axum_server_dual_protocol::ServerExt;
use config::Config;
use database::KeyValueDatabase;
use http::{
header::{self, HeaderName},
Method, StatusCode, Uri,
};
#[cfg(unix)]
use ruma::api::client::{
error::{Error as RumaError, ErrorBody, ErrorKind},
uiaa::UiaaResponse,
};
use service::{pdu::PduEvent, Services};
use tokio::{
signal,
sync::oneshot::{self, Sender},
task::JoinSet,
};
use tower::ServiceBuilder;
use tower_http::{
catch_panic::CatchPanicLayer,
cors::{self, CorsLayer},
trace::{DefaultOnFailure, DefaultOnRequest, DefaultOnResponse, TraceLayer},
ServiceBuilderExt as _,
};
use tracing::{debug, error, info, trace, warn, Level};
use tracing::{debug, error, info, warn};
use tracing_subscriber::{prelude::*, reload, EnvFilter, Registry};
use utils::{
clap,
error::{Error, Result},
};
pub(crate) mod alloc;
mod api;
mod config;
mod database;
mod routes;
mod router;
mod service;
mod utils;
@@ -66,23 +47,17 @@ pub(crate) fn services() -> &'static Services<'static> {
.expect("SERVICES should be initialized when this is called")
}
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc", not(feature = "hardened_malloc")))]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
#[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", target_os = "linux", not(feature = "jemalloc")))]
#[global_allocator]
static GLOBAL: hardened_malloc_rs::HardenedMalloc = hardened_malloc_rs::HardenedMalloc;
struct Server {
pub(crate) struct Server {
config: Config,
runtime: tokio::runtime::Runtime,
tracing_reload_handle: reload::Handle<EnvFilter, Registry>,
tracing_reload_handle: LogLevelReloadHandles,
#[cfg(feature = "sentry_telemetry")]
_sentry_guard: Option<sentry::ClientInitGuard>,
_tracing_flame_guard: TracingFlameGuard,
}
fn main() -> Result<(), Error> {
@@ -114,7 +89,7 @@ async fn async_main(server: &Server) -> Result<(), Error> {
}
async fn run(server: &Server) -> io::Result<()> {
let app = build(server).await?;
let app = router::build(server).await?;
let (tx, rx) = oneshot::channel::<()>();
let handle = ServerHandle::new();
tokio::spawn(shutdown(handle.clone(), tx));
@@ -292,179 +267,6 @@ async fn start(server: &Server) -> Result<(), Error> {
Ok(())
}
async fn build(server: &Server) -> io::Result<axum::routing::IntoMakeService<Router>> {
let base_middlewares = ServiceBuilder::new();
#[cfg(feature = "sentry_telemetry")]
let base_middlewares = base_middlewares.layer(sentry_tower::NewSentryLayer::<http::Request<_>>::new_from_top());
let x_forwarded_for = HeaderName::from_static("x-forwarded-for");
let middlewares = base_middlewares
.sensitive_headers([header::AUTHORIZATION])
.sensitive_request_headers([x_forwarded_for].into())
.layer(axum::middleware::from_fn(request_spawn))
.layer(
TraceLayer::new_for_http()
.make_span_with(tracing_span::<_>)
.on_failure(DefaultOnFailure::new().level(Level::ERROR))
.on_request(DefaultOnRequest::new().level(Level::TRACE))
.on_response(DefaultOnResponse::new().level(Level::DEBUG)),
)
.layer(axum::middleware::from_fn(request_handle))
.layer(cors_layer(server))
.layer(DefaultBodyLimit::max(
server
.config
.max_request_size
.try_into()
.expect("failed to convert max request size"),
))
.layer(CatchPanicLayer::custom(catch_panic_layer));
#[cfg(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression"))]
{
Ok(routes::routes(&server.config)
.layer(compression_layer(server))
.layer(middlewares)
.into_make_service())
}
#[cfg(not(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression")))]
{
Ok(routes::routes().layer(middlewares).into_make_service())
}
}
#[tracing::instrument(skip_all, name = "spawn")]
async fn request_spawn(
req: http::Request<axum::body::Body>, next: axum::middleware::Next,
) -> Result<axum::response::Response, StatusCode> {
if services().globals.shutdown.load(atomic::Ordering::Relaxed) {
return Err(StatusCode::SERVICE_UNAVAILABLE);
}
let fut = next.run(req);
let task = tokio::spawn(fut);
task.await.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
}
#[tracing::instrument(skip_all, name = "handle")]
async fn request_handle(
req: http::Request<axum::body::Body>, next: axum::middleware::Next,
) -> Result<axum::response::Response, StatusCode> {
let method = req.method().clone();
let uri = req.uri().clone();
let result = next.run(req).await;
request_result(&method, &uri, result)
}
fn request_result(
method: &Method, uri: &Uri, result: axum::response::Response,
) -> Result<axum::response::Response, StatusCode> {
request_result_log(method, uri, &result);
match result.status() {
StatusCode::METHOD_NOT_ALLOWED => request_result_403(method, uri, &result),
_ => Ok(result),
}
}
#[allow(clippy::unnecessary_wraps)]
fn request_result_403(
_method: &Method, _uri: &Uri, result: &axum::response::Response,
) -> Result<axum::response::Response, StatusCode> {
let error = UiaaResponse::MatrixError(RumaError {
status_code: result.status(),
body: ErrorBody::Standard {
kind: ErrorKind::Unrecognized,
message: "M_UNRECOGNIZED: Method not allowed for endpoint".to_owned(),
},
});
Ok(RumaResponse(error).into_response())
}
fn request_result_log(method: &Method, uri: &Uri, result: &axum::response::Response) {
let status = result.status();
let reason = status.canonical_reason().unwrap_or("Unknown Reason");
let code = status.as_u16();
if status.is_server_error() {
error!(method = ?method, uri = ?uri, "{code} {reason}");
} else if status.is_client_error() {
debug_error!(method = ?method, uri = ?uri, "{code} {reason}");
} else if status.is_redirection() {
debug!(method = ?method, uri = ?uri, "{code} {reason}");
} else {
trace!(method = ?method, uri = ?uri, "{code} {reason}");
}
}
fn cors_layer(_server: &Server) -> CorsLayer {
const METHODS: [Method; 6] = [
Method::GET,
Method::HEAD,
Method::POST,
Method::PUT,
Method::DELETE,
Method::OPTIONS,
];
let headers: [HeaderName; 5] = [
header::ORIGIN,
HeaderName::from_lowercase(b"x-requested-with").unwrap(),
header::CONTENT_TYPE,
header::ACCEPT,
header::AUTHORIZATION,
];
CorsLayer::new()
.allow_origin(cors::Any)
.allow_methods(METHODS)
.allow_headers(headers)
.max_age(Duration::from_secs(86400))
}
#[cfg(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression"))]
fn compression_layer(server: &Server) -> tower_http::compression::CompressionLayer {
let mut compression_layer = tower_http::compression::CompressionLayer::new();
#[cfg(feature = "zstd_compression")]
{
if server.config.zstd_compression {
compression_layer = compression_layer.zstd(true);
} else {
compression_layer = compression_layer.no_zstd();
};
};
#[cfg(feature = "gzip_compression")]
{
if server.config.gzip_compression {
compression_layer = compression_layer.gzip(true);
} else {
compression_layer = compression_layer.no_gzip();
};
};
#[cfg(feature = "brotli_compression")]
{
if server.config.brotli_compression {
compression_layer = compression_layer.br(true);
} else {
compression_layer = compression_layer.no_br();
};
};
compression_layer
}
fn tracing_span<T>(request: &http::Request<T>) -> tracing::Span {
let path = if let Some(path) = request.extensions().get::<MatchedPath>() {
path.as_str()
} else {
request.uri().path()
};
tracing::info_span!("router:", %path)
}
/// Non-async initializations
fn init(args: clap::Args) -> Result<Server, Error> {
let config = Config::new(args.config)?;
@@ -476,24 +278,7 @@ fn init(args: clap::Args) -> Result<Server, Error> {
None
};
let tracing_reload_handle;
#[cfg(feature = "perf_measurements")]
{
tracing_reload_handle = if config.allow_jaeger {
init_tracing_jaeger(&config)
} else if config.tracing_flame {
#[cfg(feature = "perf_measurements")]
init_tracing_flame(&config)
} else {
init_tracing_sub(&config)
};
};
#[cfg(not(feature = "perf_measurements"))]
{
tracing_reload_handle = init_tracing_sub(&config);
};
let (tracing_reload_handle, tracing_flame_guard) = init_tracing(&config);
config.check()?;
@@ -502,7 +287,7 @@ fn init(args: clap::Args) -> Result<Server, Error> {
database_path = ?config.database_path,
log_levels = ?config.log,
"{}",
env!("CARGO_PKG_VERSION"),
utils::conduwuit_version(),
);
#[cfg(unix)]
@@ -515,7 +300,7 @@ fn init(args: clap::Args) -> Result<Server, Error> {
.enable_io()
.enable_time()
.thread_name("conduwuit:worker")
.worker_threads(num_cpus::get())
.worker_threads(std::cmp::max(2, num_cpus::get()))
.build()
.unwrap(),
@@ -523,6 +308,7 @@ fn init(args: clap::Args) -> Result<Server, Error> {
#[cfg(feature = "sentry_telemetry")]
_sentry_guard: sentry_guard,
_tracing_flame_guard: tracing_flame_guard,
})
}
@@ -547,7 +333,65 @@ fn init_sentry(config: &Config) -> sentry::ClientInitGuard {
))
}
fn init_tracing_sub(config: &Config) -> reload::Handle<EnvFilter, Registry> {
/// We need to store a reload::Handle value, but can't name it's type explicitly
/// because the S type parameter depends on the subscriber's previous layers. In
/// our case, this includes unnameable 'impl Trait' types.
///
/// This is fixed[1] in the unreleased tracing-subscriber from the master
/// branch, which removes the S parameter. Unfortunately can't use it without
/// pulling in a version of tracing that's incompatible with the rest of our
/// deps.
///
/// To work around this, we define an trait without the S paramter that forwards
/// to the reload::Handle::reload method, and then store the handle as a trait
/// object.
///
/// [1]: <https://github.com/tokio-rs/tracing/pull/1035/commits/8a87ea52425098d3ef8f56d92358c2f6c144a28f>
trait ReloadHandle<L> {
fn reload(&self, new_value: L) -> Result<(), reload::Error>;
}
impl<L, S> ReloadHandle<L> for reload::Handle<L, S> {
fn reload(&self, new_value: L) -> Result<(), reload::Error> { reload::Handle::reload(self, new_value) }
}
struct LogLevelReloadHandlesInner {
handles: Vec<Box<dyn ReloadHandle<EnvFilter> + Send + Sync>>,
}
/// Wrapper to allow reloading the filter on several several
/// [`tracing_subscriber::reload::Handle`]s at once, with the same value.
#[derive(Clone)]
struct LogLevelReloadHandles {
inner: Arc<LogLevelReloadHandlesInner>,
}
impl LogLevelReloadHandles {
fn new(handles: Vec<Box<dyn ReloadHandle<EnvFilter> + Send + Sync>>) -> LogLevelReloadHandles {
LogLevelReloadHandles {
inner: Arc::new(LogLevelReloadHandlesInner {
handles,
}),
}
}
fn reload(&self, new_value: &EnvFilter) -> Result<(), reload::Error> {
for handle in &self.inner.handles {
handle.reload(new_value.clone())?;
}
Ok(())
}
}
#[cfg(feature = "perf_measurements")]
type TracingFlameGuard = Option<tracing_flame::FlushGuard<io::BufWriter<std::fs::File>>>;
#[cfg(not(feature = "perf_measurements"))]
type TracingFlameGuard = ();
// clippy thinks the filter_layer clones are redundant if the next usage is
// behind a disabled feature.
#[allow(clippy::redundant_clone)]
fn init_tracing(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard) {
let registry = Registry::default();
let fmt_layer = tracing_subscriber::fmt::Layer::new();
let filter_layer = match EnvFilter::try_new(&config.log) {
@@ -558,84 +402,92 @@ fn init_tracing_sub(config: &Config) -> reload::Handle<EnvFilter, Registry> {
},
};
let (reload_filter, reload_handle) = reload::Layer::new(filter_layer);
let mut reload_handles = Vec::<Box<dyn ReloadHandle<EnvFilter> + Send + Sync>>::new();
let subscriber = registry;
#[cfg(feature = "tokio_console")]
let subscriber = {
let console_layer = console_subscriber::spawn();
subscriber.with(console_layer)
};
let (fmt_reload_filter, fmt_reload_handle) = reload::Layer::new(filter_layer.clone());
reload_handles.push(Box::new(fmt_reload_handle));
let subscriber = subscriber.with(fmt_layer.with_filter(fmt_reload_filter));
#[cfg(feature = "sentry_telemetry")]
let sentry_layer = sentry_tracing::layer();
let subscriber;
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
#[cfg(feature = "sentry_telemetry")]
{
subscriber = registry
.with(reload_filter)
.with(fmt_layer)
.with(sentry_layer);
let subscriber = {
let sentry_layer = sentry_tracing::layer();
let (sentry_reload_filter, sentry_reload_handle) = reload::Layer::new(filter_layer.clone());
reload_handles.push(Box::new(sentry_reload_handle));
subscriber.with(sentry_layer.with_filter(sentry_reload_filter))
};
#[allow(clippy::unnecessary_operation)] // error[E0658]: attributes on expressions are experimental
#[cfg(not(feature = "sentry_telemetry"))]
{
subscriber = registry.with(reload_filter).with(fmt_layer);
#[cfg(feature = "perf_measurements")]
let (subscriber, flame_guard) = {
let (flame_layer, flame_guard) = if config.tracing_flame {
let flame_filter = match EnvFilter::try_new(&config.tracing_flame_filter) {
Ok(flame_filter) => flame_filter,
Err(e) => panic!("tracing_flame_filter config value is invalid: {e}"),
};
let (flame_layer, flame_guard) =
match tracing_flame::FlameLayer::with_file(&config.tracing_flame_output_path) {
Ok(ok) => ok,
Err(e) => {
panic!("failed to initialize tracing-flame: {e}");
},
};
let flame_layer = flame_layer
.with_empty_samples(false)
.with_filter(flame_filter);
(Some(flame_layer), Some(flame_guard))
} else {
(None, None)
};
let jaeger_layer = if config.allow_jaeger {
opentelemetry::global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let tracer = opentelemetry_jaeger::new_agent_pipeline()
.with_auto_split_batch(true)
.with_service_name("conduwuit")
.install_batch(opentelemetry_sdk::runtime::Tokio)
.unwrap();
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
let (jaeger_reload_filter, jaeger_reload_handle) = reload::Layer::new(filter_layer);
reload_handles.push(Box::new(jaeger_reload_handle));
Some(telemetry.with_filter(jaeger_reload_filter))
} else {
None
};
let subscriber = subscriber.with(flame_layer).with(jaeger_layer);
(subscriber, flame_guard)
};
#[cfg(not(feature = "perf_measurements"))]
#[cfg_attr(not(feature = "perf_measurements"), allow(clippy::let_unit_value))]
let flame_guard = ();
tracing::subscriber::set_global_default(subscriber).unwrap();
reload_handle
#[cfg(all(feature = "tokio_console", feature = "release_max_log_level"))]
error!(
"'tokio_console' feature and 'release_max_log_level' feature are incompatible, because console-subscriber \
needs access to trace-level events. 'release_max_log_level' must be disabled to use tokio-console."
);
(LogLevelReloadHandles::new(reload_handles), flame_guard)
}
#[cfg(feature = "perf_measurements")]
fn init_tracing_jaeger(config: &Config) -> reload::Handle<EnvFilter, Registry> {
opentelemetry::global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
let tracer = opentelemetry_jaeger::new_agent_pipeline()
.with_auto_split_batch(true)
.with_service_name("conduwuit")
.install_batch(opentelemetry_sdk::runtime::Tokio)
.unwrap();
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
let filter_layer = match EnvFilter::try_new(&config.log) {
Ok(s) => s,
Err(e) => {
eprintln!("It looks like your log config is invalid. The following error occurred: {e}");
EnvFilter::try_new("warn").unwrap()
},
};
let (reload_filter, reload_handle) = reload::Layer::new(filter_layer);
let subscriber = Registry::default().with(reload_filter).with(telemetry);
tracing::subscriber::set_global_default(subscriber).unwrap();
reload_handle
}
#[cfg(feature = "perf_measurements")]
fn init_tracing_flame(_config: &Config) -> reload::Handle<EnvFilter, Registry> {
let registry = Registry::default();
let (flame_layer, _guard) = tracing_flame::FlameLayer::with_file("./tracing.folded").unwrap();
let flame_layer = flame_layer.with_empty_samples(false);
let filter_layer = EnvFilter::new("trace,h2=off");
let (reload_filter, reload_handle) = reload::Layer::new(filter_layer);
let subscriber = registry.with(reload_filter).with(flame_layer);
tracing::subscriber::set_global_default(subscriber).unwrap();
reload_handle
}
// This is needed for opening lots of file descriptors, which tends to
// happen more often when using RocksDB and making lots of federation
// connections at startup. The soft limit is usually 1024, and the hard
// limit is usually 512000; I've personally seen it hit >2000.
//
// * https://www.freedesktop.org/software/systemd/man/systemd.exec.html#id-1.12.2.1.17.6
// * https://github.com/systemd/systemd/commit/0abf94923b4a95a7d89bc526efc84e7ca2b71741
/// This is needed for opening lots of file descriptors, which tends to
/// happen more often when using RocksDB and making lots of federation
/// connections at startup. The soft limit is usually 1024, and the hard
/// limit is usually 512000; I've personally seen it hit >2000.
///
/// * <https://www.freedesktop.org/software/systemd/man/systemd.exec.html#id-1.12.2.1.17.6>
/// * <https://github.com/systemd/systemd/commit/0abf94923b4a95a7d89bc526efc84e7ca2b71741>
#[cfg(unix)]
fn maximize_fd_limit() -> Result<(), nix::errno::Errno> {
use nix::sys::resource::{getrlimit, setrlimit, Resource::RLIMIT_NOFILE as NOFILE};
@@ -649,27 +501,3 @@ fn maximize_fd_limit() -> Result<(), nix::errno::Errno> {
Ok(())
}
#[allow(clippy::needless_pass_by_value)]
fn catch_panic_layer(err: Box<dyn Any + Send + 'static>) -> http::Response<http_body_util::Full<bytes::Bytes>> {
let details = if let Some(s) = err.downcast_ref::<String>() {
s.clone()
} else if let Some(s) = err.downcast_ref::<&str>() {
s.to_string()
} else {
"Unknown internal server error occurred.".to_owned()
};
let body = serde_json::json!({
"errcode": "M_UNKNOWN",
"error": "M_UNKNOWN: Internal server error occurred",
"details": details,
})
.to_string();
http::Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.header(header::CONTENT_TYPE, "application/json")
.body(http_body_util::Full::from(body))
.expect("Failed to create response for our panic catcher?")
}
+224
View File
@@ -0,0 +1,224 @@
use std::{any::Any, io, sync::atomic, time::Duration};
use axum::{
extract::{DefaultBodyLimit, MatchedPath},
response::IntoResponse,
Router,
};
use http::{
header::{self, HeaderName},
Method, StatusCode, Uri,
};
use ruma::api::client::{
error::{Error as RumaError, ErrorBody, ErrorKind},
uiaa::UiaaResponse,
};
use tower::ServiceBuilder;
use tower_http::{
catch_panic::CatchPanicLayer,
cors::{self, CorsLayer},
trace::{DefaultOnFailure, DefaultOnRequest, DefaultOnResponse, TraceLayer},
ServiceBuilderExt as _,
};
use tracing::{debug, error, trace, Level};
use super::{api::ruma_wrapper::RumaResponse, debug_error, services, utils::error::Result, Server};
mod routes;
pub(crate) async fn build(server: &Server) -> io::Result<axum::routing::IntoMakeService<Router>> {
let base_middlewares = ServiceBuilder::new();
#[cfg(feature = "sentry_telemetry")]
let base_middlewares = base_middlewares.layer(sentry_tower::NewSentryLayer::<http::Request<_>>::new_from_top());
let x_forwarded_for = HeaderName::from_static("x-forwarded-for");
let middlewares = base_middlewares
.sensitive_headers([header::AUTHORIZATION])
.sensitive_request_headers([x_forwarded_for].into())
.layer(axum::middleware::from_fn(request_spawn))
.layer(
TraceLayer::new_for_http()
.make_span_with(tracing_span::<_>)
.on_failure(DefaultOnFailure::new().level(Level::ERROR))
.on_request(DefaultOnRequest::new().level(Level::TRACE))
.on_response(DefaultOnResponse::new().level(Level::DEBUG)),
)
.layer(axum::middleware::from_fn(request_handle))
.layer(cors_layer(server))
.layer(DefaultBodyLimit::max(
server
.config
.max_request_size
.try_into()
.expect("failed to convert max request size"),
))
.layer(CatchPanicLayer::custom(catch_panic_layer));
#[cfg(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression"))]
{
Ok(routes::routes(&server.config)
.layer(compression_layer(server))
.layer(middlewares)
.into_make_service())
}
#[cfg(not(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression")))]
{
Ok(routes::routes().layer(middlewares).into_make_service())
}
}
#[tracing::instrument(skip_all, name = "spawn")]
async fn request_spawn(
req: http::Request<axum::body::Body>, next: axum::middleware::Next,
) -> Result<axum::response::Response, StatusCode> {
if services().globals.shutdown.load(atomic::Ordering::Relaxed) {
return Err(StatusCode::SERVICE_UNAVAILABLE);
}
let fut = next.run(req);
let task = tokio::spawn(fut);
task.await.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
}
#[tracing::instrument(skip_all, name = "handle")]
async fn request_handle(
req: http::Request<axum::body::Body>, next: axum::middleware::Next,
) -> Result<axum::response::Response, StatusCode> {
let method = req.method().clone();
let uri = req.uri().clone();
let result = next.run(req).await;
request_result(&method, &uri, result)
}
fn request_result(
method: &Method, uri: &Uri, result: axum::response::Response,
) -> Result<axum::response::Response, StatusCode> {
request_result_log(method, uri, &result);
match result.status() {
StatusCode::METHOD_NOT_ALLOWED => request_result_403(method, uri, &result),
_ => Ok(result),
}
}
#[allow(clippy::unnecessary_wraps)]
fn request_result_403(
_method: &Method, _uri: &Uri, result: &axum::response::Response,
) -> Result<axum::response::Response, StatusCode> {
let error = UiaaResponse::MatrixError(RumaError {
status_code: result.status(),
body: ErrorBody::Standard {
kind: ErrorKind::Unrecognized,
message: "M_UNRECOGNIZED: Method not allowed for endpoint".to_owned(),
},
});
Ok(RumaResponse(error).into_response())
}
fn request_result_log(method: &Method, uri: &Uri, result: &axum::response::Response) {
let status = result.status();
let reason = status.canonical_reason().unwrap_or("Unknown Reason");
let code = status.as_u16();
if status.is_server_error() {
error!(method = ?method, uri = ?uri, "{code} {reason}");
} else if status.is_client_error() {
debug_error!(method = ?method, uri = ?uri, "{code} {reason}");
} else if status.is_redirection() {
debug!(method = ?method, uri = ?uri, "{code} {reason}");
} else {
trace!(method = ?method, uri = ?uri, "{code} {reason}");
}
}
fn cors_layer(_server: &Server) -> CorsLayer {
const METHODS: [Method; 6] = [
Method::GET,
Method::HEAD,
Method::POST,
Method::PUT,
Method::DELETE,
Method::OPTIONS,
];
let headers: [HeaderName; 5] = [
header::ORIGIN,
HeaderName::from_lowercase(b"x-requested-with").unwrap(),
header::CONTENT_TYPE,
header::ACCEPT,
header::AUTHORIZATION,
];
CorsLayer::new()
.allow_origin(cors::Any)
.allow_methods(METHODS)
.allow_headers(headers)
.max_age(Duration::from_secs(86400))
}
#[cfg(any(feature = "zstd_compression", feature = "gzip_compression", feature = "brotli_compression"))]
fn compression_layer(server: &Server) -> tower_http::compression::CompressionLayer {
let mut compression_layer = tower_http::compression::CompressionLayer::new();
#[cfg(feature = "zstd_compression")]
{
if server.config.zstd_compression {
compression_layer = compression_layer.zstd(true);
} else {
compression_layer = compression_layer.no_zstd();
};
};
#[cfg(feature = "gzip_compression")]
{
if server.config.gzip_compression {
compression_layer = compression_layer.gzip(true);
} else {
compression_layer = compression_layer.no_gzip();
};
};
#[cfg(feature = "brotli_compression")]
{
if server.config.brotli_compression {
compression_layer = compression_layer.br(true);
} else {
compression_layer = compression_layer.no_br();
};
};
compression_layer
}
fn tracing_span<T>(request: &http::Request<T>) -> tracing::Span {
let path = if let Some(path) = request.extensions().get::<MatchedPath>() {
path.as_str()
} else {
request.uri().path()
};
tracing::info_span!("router:", %path)
}
#[allow(clippy::needless_pass_by_value)]
fn catch_panic_layer(err: Box<dyn Any + Send + 'static>) -> http::Response<http_body_util::Full<bytes::Bytes>> {
let details = if let Some(s) = err.downcast_ref::<String>() {
s.clone()
} else if let Some(s) = err.downcast_ref::<&str>() {
s.to_string()
} else {
"Unknown internal server error occurred.".to_owned()
};
let body = serde_json::json!({
"errcode": "M_UNKNOWN",
"error": "M_UNKNOWN: Internal server error occurred",
"details": details,
})
.to_string();
http::Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.header(header::CONTENT_TYPE, "application/json")
.body(http_body_util::Full::from(body))
.expect("Failed to create response for our panic catcher?")
}
+41 -3
View File
@@ -8,7 +8,10 @@ use tokio::sync::RwLock;
use tracing::{debug, info, warn};
use tracing_subscriber::EnvFilter;
use crate::{api::server_server::parse_incoming_pdu, services, utils::HtmlEscape, Error, PduEvent, Result};
use crate::{
api::server_server::parse_incoming_pdu, service::sending::send::resolve_actual_dest, services, utils::HtmlEscape,
Error, PduEvent, Result,
};
pub(crate) async fn get_auth_chain(_body: Vec<&str>, event_id: Box<EventId>) -> Result<RoomMessageEventContent> {
let event_id = Arc::<EventId>::from(event_id);
@@ -331,7 +334,7 @@ pub(crate) async fn change_log_level(
match services()
.globals
.tracing_reload_handle
.modify(|filter| *filter = old_filter_layer)
.reload(&old_filter_layer)
{
Ok(()) => {
return Ok(RoomMessageEventContent::text_plain(format!(
@@ -360,7 +363,7 @@ pub(crate) async fn change_log_level(
match services()
.globals
.tracing_reload_handle
.modify(|filter| *filter = new_filter_layer)
.reload(&new_filter_layer)
{
Ok(()) => {
return Ok(RoomMessageEventContent::text_plain("Successfully changed log level"));
@@ -428,3 +431,38 @@ pub(crate) async fn verify_json(body: Vec<&str>) -> Result<RoomMessageEventConte
))
}
}
pub(crate) async fn resolve_true_destination(
_body: Vec<&str>, server_name: Box<ServerName>, no_cache: bool,
) -> Result<RoomMessageEventContent> {
if !services().globals.config.allow_federation {
return Ok(RoomMessageEventContent::text_plain(
"Federation is disabled on this homeserver.",
));
}
if server_name == services().globals.config.server_name {
return Ok(RoomMessageEventContent::text_plain(
"Not allowed to send federation requests to ourselves. Please use `get-pdu` for fetching local PDUs.",
));
}
let (actual_dest, hostname_uri) = resolve_actual_dest(&server_name, no_cache, true).await?;
Ok(RoomMessageEventContent::text_plain(format!(
"Actual destination: {actual_dest:?} | Hostname URI: {hostname_uri}"
)))
}
pub(crate) fn memory_stats() -> RoomMessageEventContent {
let html_body = crate::alloc::memory_stats();
if html_body.is_empty() {
return RoomMessageEventContent::text_plain("malloc stats are not supported on your compiled malloc.");
}
RoomMessageEventContent::text_html(
"This command's output can only be viewed by clients that render HTML.".to_owned(),
html_body,
)
}
+20 -1
View File
@@ -3,7 +3,7 @@ use ruma::{events::room::message::RoomMessageEventContent, EventId, RoomId, Serv
use self::debug_commands::{
change_log_level, force_device_list_updates, get_auth_chain, get_pdu, get_remote_pdu, get_remote_pdu_list,
get_room_state, parse_pdu, ping, sign_json, verify_json,
get_room_state, memory_stats, parse_pdu, ping, resolve_true_destination, sign_json, verify_json,
};
use crate::Result;
@@ -106,6 +106,20 @@ pub(crate) enum DebugCommand {
/// This command needs a JSON blob provided in a Markdown code block below
/// the command.
VerifyJson,
/// - Runs a server name through conduwuit's true destination resolution
/// process
///
/// Useful for debugging well-known issues
ResolveTrueDestination {
server_name: Box<ServerName>,
#[arg(short, long)]
no_cache: bool,
},
/// - Print extended memory usage
MemoryStats,
}
pub(crate) async fn process(command: DebugCommand, body: Vec<&str>) -> Result<RoomMessageEventContent> {
@@ -138,5 +152,10 @@ pub(crate) async fn process(command: DebugCommand, body: Vec<&str>) -> Result<Ro
server,
force,
} => get_remote_pdu_list(body, server, force).await?,
DebugCommand::ResolveTrueDestination {
server_name,
no_cache,
} => resolve_true_destination(body, server_name, no_cache).await?,
DebugCommand::MemoryStats => memory_stats(),
})
}
@@ -1,8 +1,13 @@
use std::fmt::Write as _;
use ruma::{events::room::message::RoomMessageEventContent, RoomId, ServerName};
use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, RoomId, ServerName, UserId};
use crate::{services, utils::HtmlEscape, Result};
use crate::{
service::admin::{escape_html, get_room_info},
services,
utils::HtmlEscape,
Result,
};
pub(crate) async fn disable_room(_body: Vec<&str>, room_id: Box<RoomId>) -> Result<RoomMessageEventContent> {
services().rooms.metadata.disable_room(&room_id, true)?;
@@ -70,3 +75,60 @@ pub(crate) async fn fetch_support_well_known(
),
))
}
pub(crate) async fn remote_user_in_rooms(_body: Vec<&str>, user_id: Box<UserId>) -> Result<RoomMessageEventContent> {
if user_id.server_name() == services().globals.config.server_name {
return Ok(RoomMessageEventContent::text_plain(
"User belongs to our server, please use `list-joined-rooms` user admin command instead.",
));
}
if !services().users.exists(&user_id)? {
return Ok(RoomMessageEventContent::text_plain(
"Remote user does not exist in our database.",
));
}
let mut rooms: Vec<(OwnedRoomId, u64, String)> = services()
.rooms
.state_cache
.rooms_joined(&user_id)
.filter_map(Result::ok)
.map(|room_id| get_room_info(&room_id))
.collect();
if rooms.is_empty() {
return Ok(RoomMessageEventContent::text_plain("User is not in any rooms."));
}
rooms.sort_by_key(|r| r.1);
rooms.reverse();
let output_plain = format!(
"Rooms {user_id} shares with us:\n{}",
rooms
.iter()
.map(|(id, members, name)| format!("{id}\tMembers: {members}\tName: {name}"))
.collect::<Vec<_>>()
.join("\n")
);
let output_html = format!(
"<table><caption>Rooms {user_id} shares with \
us</caption>\n<tr><th>id</th>\t<th>members</th>\t<th>name</th></tr>\n{}</table>",
rooms
.iter()
.fold(String::new(), |mut output, (id, members, name)| {
writeln!(
output,
"<tr><td>{}</td>\t<td>{}</td>\t<td>{}</td></tr>",
escape_html(id.as_ref()),
members,
escape_html(name)
)
.unwrap();
output
})
);
Ok(RoomMessageEventContent::text_html(output_plain, output_html))
}
+12 -2
View File
@@ -1,7 +1,9 @@
use clap::Subcommand;
use ruma::{events::room::message::RoomMessageEventContent, RoomId, ServerName};
use ruma::{events::room::message::RoomMessageEventContent, RoomId, ServerName, UserId};
use self::federation_commands::{disable_room, enable_room, fetch_support_well_known, incoming_federeation};
use self::federation_commands::{
disable_room, enable_room, fetch_support_well_known, incoming_federeation, remote_user_in_rooms,
};
use crate::Result;
pub(crate) mod federation_commands;
@@ -34,6 +36,11 @@ pub(crate) enum FederationCommand {
FetchSupportWellKnown {
server_name: Box<ServerName>,
},
/// - Lists all the rooms we share/track with the specified *remote* user
RemoteUserInRooms {
user_id: Box<UserId>,
},
}
pub(crate) async fn process(command: FederationCommand, body: Vec<&str>) -> Result<RoomMessageEventContent> {
@@ -48,5 +55,8 @@ pub(crate) async fn process(command: FederationCommand, body: Vec<&str>) -> Resu
FederationCommand::FetchSupportWellKnown {
server_name,
} => fetch_support_well_known(body, server_name).await?,
FederationCommand::RemoteUserInRooms {
user_id,
} => remote_user_in_rooms(body, user_id).await?,
})
}
+124 -104
View File
@@ -23,10 +23,10 @@ use ruma::{
EventId, MxcUri, OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId, RoomVersionId, ServerName, UserId,
};
use serde_json::value::to_raw_value;
use tokio::sync::Mutex;
use tokio::sync::{Mutex, MutexGuard};
use tracing::{error, warn};
use self::fsck::FsckCommand;
use self::{fsck::FsckCommand, tester::TesterCommands};
use super::pdu::PduBuilder;
use crate::{
service::admin::{
@@ -44,6 +44,7 @@ pub(crate) mod media;
pub(crate) mod query;
pub(crate) mod room;
pub(crate) mod server;
pub(crate) mod tester;
pub(crate) mod user;
const PAGE_SIZE: usize = 100;
@@ -87,6 +88,9 @@ enum AdminCommand {
#[command(subcommand)]
/// - Query all the database getters and iterators
Fsck(FsckCommand),
#[command(subcommand)]
Tester(TesterCommands),
}
#[derive(Debug)]
@@ -119,98 +123,113 @@ impl Service {
});
}
pub(crate) async fn process_message(&self, room_message: String, event_id: Arc<EventId>) {
self.send(AdminRoomEvent::ProcessMessage(room_message, event_id))
.await;
}
pub(crate) async fn send_message(&self, message_content: RoomMessageEventContent) {
self.send(AdminRoomEvent::SendMessage(message_content))
.await;
}
async fn send(&self, message: AdminRoomEvent) {
debug_assert!(!self.sender.is_full(), "channel full");
debug_assert!(!self.sender.is_closed(), "channel closed");
self.sender.send(message).expect("message sent");
}
async fn handler(&self) -> Result<()> {
let receiver = self.receiver.lock().await;
// TODO: Use futures when we have long admin commands
//let mut futures = FuturesUnordered::new();
let Ok(Some(admin_room)) = Self::get_admin_room().await else {
return Ok(());
};
let server_name = services().globals.server_name();
let server_user = UserId::parse(format!("@conduit:{server_name}")).expect("server's username is valid");
let conduit_user = UserId::parse(format!("@conduit:{}", services().globals.server_name()))
.expect("@conduit:server_name is valid");
if let Ok(Some(conduit_room)) = Self::get_admin_room() {
loop {
tokio::select! {
event = receiver.recv_async() => {
match event {
Ok(event) => {
let (mut message_content, reply) = match event {
AdminRoomEvent::SendMessage(content) => (content, None),
AdminRoomEvent::ProcessMessage(room_message, reply_id) => {
(self.process_admin_message(room_message).await, Some(reply_id))
}
};
let mutex_state = Arc::clone(
services().globals
.roomid_mutex_state
.write()
.await
.entry(conduit_room.clone())
.or_default(),
);
let state_lock = mutex_state.lock().await;
if let Some(reply) = reply {
message_content.relates_to = Some(Reply { in_reply_to: InReplyTo { event_id: reply.into() } });
}
if let Err(e) = services().rooms.timeline.build_and_append_pdu(
PduBuilder {
event_type: TimelineEventType::RoomMessage,
content: to_raw_value(&message_content)
.expect("event is valid, we just created it"),
unsigned: None,
state_key: None,
redacts: None,
},
&conduit_user,
&conduit_room,
&state_lock)
.await {
error!("Failed to build and append admin room response PDU: \"{e}\"");
let error_room_message = RoomMessageEventContent::text_plain(format!("Failed to build and append admin room PDU: \"{e}\"\n\nThe original admin command may have finished successfully, but we could not return the output."));
services().rooms.timeline.build_and_append_pdu(
PduBuilder {
event_type: TimelineEventType::RoomMessage,
content: to_raw_value(&error_room_message)
.expect("event is valid, we just created it"),
unsigned: None,
state_key: None,
redacts: None,
},
&conduit_user,
&conduit_room,
&state_lock)
.await?;
}
drop(state_lock);
}
Err(e) => {
// generally shouldn't happen
error!("Failed to receive admin room event from channel: {e}");
}
}
}
loop {
debug_assert!(!receiver.is_closed(), "channel closed");
tokio::select! {
event = receiver.recv_async() => match event {
Ok(event) => self.handle_event(event, &admin_room, &server_user).await?,
Err(e) => error!("Failed to receive admin room event from channel: {e}"),
}
}
}
}
async fn handle_event(&self, event: AdminRoomEvent, admin_room: &OwnedRoomId, server_user: &UserId) -> Result<()> {
let (mut message_content, reply) = match event {
AdminRoomEvent::SendMessage(content) => (content, None),
AdminRoomEvent::ProcessMessage(room_message, reply_id) => {
(self.process_admin_message(room_message).await, Some(reply_id))
},
};
let mutex_state = Arc::clone(
services()
.globals
.roomid_mutex_state
.write()
.await
.entry(admin_room.clone())
.or_default(),
);
let state_lock = mutex_state.lock().await;
if let Some(reply) = reply {
message_content.relates_to = Some(Reply {
in_reply_to: InReplyTo {
event_id: reply.into(),
},
});
}
let response_pdu = PduBuilder {
event_type: TimelineEventType::RoomMessage,
content: to_raw_value(&message_content).expect("event is valid, we just created it"),
unsigned: None,
state_key: None,
redacts: None,
};
if let Err(e) = services()
.rooms
.timeline
.build_and_append_pdu(response_pdu, server_user, admin_room, &state_lock)
.await
{
self.handle_response_error(&e, admin_room, server_user, &state_lock)
.await?;
}
Ok(())
}
pub(crate) fn process_message(&self, room_message: String, event_id: Arc<EventId>) {
self.sender
.send(AdminRoomEvent::ProcessMessage(room_message, event_id))
.unwrap();
}
async fn handle_response_error(
&self, e: &Error, admin_room: &OwnedRoomId, server_user: &UserId, state_lock: &MutexGuard<'_, ()>,
) -> Result<()> {
error!("Failed to build and append admin room response PDU: \"{e}\"");
let error_room_message = RoomMessageEventContent::text_plain(format!(
"Failed to build and append admin room PDU: \"{e}\"\n\nThe original admin command may have finished \
successfully, but we could not return the output."
));
pub(crate) fn send_message(&self, message_content: RoomMessageEventContent) {
self.sender
.send(AdminRoomEvent::SendMessage(message_content))
.unwrap();
let response_pdu = PduBuilder {
event_type: TimelineEventType::RoomMessage,
content: to_raw_value(&error_room_message).expect("event is valid, we just created it"),
unsigned: None,
state_key: None,
redacts: None,
};
services()
.rooms
.timeline
.build_and_append_pdu(response_pdu, server_user, admin_room, state_lock)
.await?;
Ok(())
}
// Parse and process a message from the admin room
@@ -289,6 +308,7 @@ impl Service {
AdminCommand::Debug(command) => debug::process(command, body).await?,
AdminCommand::Query(command) => query::process(command, body).await?,
AdminCommand::Fsck(command) => fsck::process(command, body).await?,
AdminCommand::Tester(command) => tester::process(command, body).await?,
};
Ok(reply_message_content)
@@ -387,10 +407,10 @@ impl Service {
let state_lock = mutex_state.lock().await;
// Create a user for the server
let conduit_user = UserId::parse_with_server_name("conduit", services().globals.server_name())
let server_user = UserId::parse_with_server_name("conduit", services().globals.server_name())
.expect("@conduit:server_name is valid");
services().users.create(&conduit_user, None)?;
services().users.create(&server_user, None)?;
let room_version = services().globals.default_room_version();
let mut content = match room_version {
@@ -403,7 +423,7 @@ impl Service {
| RoomVersionId::V7
| RoomVersionId::V8
| RoomVersionId::V9
| RoomVersionId::V10 => RoomCreateEventContent::new_v1(conduit_user.clone()),
| RoomVersionId::V10 => RoomCreateEventContent::new_v1(server_user.clone()),
RoomVersionId::V11 => RoomCreateEventContent::new_v11(),
_ => {
warn!("Unexpected or unsupported room version {}", room_version);
@@ -430,7 +450,7 @@ impl Service {
state_key: Some(String::new()),
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
)
@@ -455,10 +475,10 @@ impl Service {
})
.expect("event is valid, we just created it"),
unsigned: None,
state_key: Some(conduit_user.to_string()),
state_key: Some(server_user.to_string()),
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
)
@@ -466,7 +486,7 @@ impl Service {
// 3. Power levels
let mut users = BTreeMap::new();
users.insert(conduit_user.clone(), 100.into());
users.insert(server_user.clone(), 100.into());
services()
.rooms
@@ -483,7 +503,7 @@ impl Service {
state_key: Some(String::new()),
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
)
@@ -502,7 +522,7 @@ impl Service {
state_key: Some(String::new()),
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
)
@@ -521,7 +541,7 @@ impl Service {
state_key: Some(String::new()),
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
)
@@ -540,7 +560,7 @@ impl Service {
state_key: Some(String::new()),
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
)
@@ -560,7 +580,7 @@ impl Service {
state_key: Some(String::new()),
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
)
@@ -580,7 +600,7 @@ impl Service {
state_key: Some(String::new()),
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
)
@@ -606,7 +626,7 @@ impl Service {
state_key: Some(String::new()),
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
)
@@ -621,7 +641,7 @@ impl Service {
///
/// Errors are propagated from the database, and will have None if there is
/// no admin room
pub(crate) fn get_admin_room() -> Result<Option<OwnedRoomId>> {
pub(crate) async fn get_admin_room() -> Result<Option<OwnedRoomId>> {
let admin_room_alias: Box<RoomAliasId> = format!("#admins:{}", services().globals.server_name())
.try_into()
.expect("#admins:server_name is a valid alias name");
@@ -636,7 +656,7 @@ impl Service {
///
/// In conduit, this is equivalent to granting admin privileges.
pub(crate) async fn make_user_admin(&self, user_id: &UserId, displayname: String) -> Result<()> {
if let Some(room_id) = Self::get_admin_room()? {
if let Some(room_id) = Self::get_admin_room().await? {
let mutex_state = Arc::clone(
services()
.globals
@@ -649,7 +669,7 @@ impl Service {
let state_lock = mutex_state.lock().await;
// Use the server user to grant the new admin's power level
let conduit_user = UserId::parse_with_server_name("conduit", services().globals.server_name())
let server_user = UserId::parse_with_server_name("conduit", services().globals.server_name())
.expect("@conduit:server_name is valid");
// Invite and join the real user
@@ -674,7 +694,7 @@ impl Service {
state_key: Some(user_id.to_string()),
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
)
@@ -708,7 +728,7 @@ impl Service {
// Set power level
let mut users = BTreeMap::new();
users.insert(conduit_user.clone(), 100.into());
users.insert(server_user.clone(), 100.into());
users.insert(user_id.to_owned(), 100.into());
services()
@@ -726,7 +746,7 @@ impl Service {
state_key: Some(String::new()),
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
)
@@ -745,7 +765,7 @@ impl Service {
state_key: None,
redacts: None,
},
&conduit_user,
&server_user,
&room_id,
&state_lock,
).await?;
@@ -9,7 +9,9 @@ use super::RoomModerationCommand;
use crate::{
api::client_server::{get_alias_helper, leave_room},
service::admin::{escape_html, Service},
services, Result,
services,
utils::user_id::user_is_local,
Result,
};
pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> Result<RoomMessageEventContent> {
@@ -25,7 +27,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
.try_into()
.expect("#admins:server_name is a valid alias name");
if let Some(admin_room_id) = Service::get_admin_room()? {
if let Some(admin_room_id) = Service::get_admin_room().await? {
if room.to_string().eq(&admin_room_id) || room.to_string().eq(&admin_room_alias) {
return Ok(RoomMessageEventContent::text_plain("Not allowed to ban the admin room."));
}
@@ -102,11 +104,10 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
.room_members(&room_id)
.filter_map(|user| {
user.ok().filter(|local_user| {
local_user.server_name() == services().globals.server_name()
user_is_local(local_user)
// additional wrapped check here is to avoid adding remote users
// who are in the admin room to the list of local users (would fail auth check)
&& (local_user.server_name()
== services().globals.server_name()
&& (user_is_local(local_user)
&& services()
.users
.is_admin(local_user)
@@ -190,7 +191,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
for &room in &rooms_s {
match <&RoomOrAliasId>::try_from(room) {
Ok(room_alias_or_id) => {
if let Some(admin_room_id) = Service::get_admin_room()? {
if let Some(admin_room_id) = Service::get_admin_room().await? {
if room.to_owned().eq(&admin_room_id) || room.to_owned().eq(&admin_room_alias) {
info!("User specified admin room in bulk ban list, ignoring");
continue;
+5 -1
View File
@@ -5,13 +5,16 @@ use ruma::events::room::message::RoomMessageEventContent;
use self::server_commands::{
backup_database, clear_database_caches, clear_service_caches, list_backups, list_database_files, memory_usage,
show_config,
show_config, uptime,
};
use crate::Result;
#[cfg_attr(test, derive(Debug))]
#[derive(Subcommand)]
pub(crate) enum ServerCommand {
/// - Time elapsed since startup
Uptime,
/// - Show configuration values
ShowConfig,
@@ -43,6 +46,7 @@ pub(crate) enum ServerCommand {
pub(crate) async fn process(command: ServerCommand, body: Vec<&str>) -> Result<RoomMessageEventContent> {
Ok(match command {
ServerCommand::Uptime => uptime(body).await?,
ServerCommand::ShowConfig => show_config(body).await?,
ServerCommand::MemoryUsage => memory_usage(body).await?,
ServerCommand::ClearDatabaseCaches {
+27 -3
View File
@@ -2,17 +2,41 @@ use ruma::events::room::message::RoomMessageEventContent;
use crate::{services, Result};
pub(crate) async fn uptime(_body: Vec<&str>) -> Result<RoomMessageEventContent> {
let seconds = services()
.globals
.started
.elapsed()
.expect("standard duration")
.as_secs();
let result = format!(
"up {} days, {} hours, {} minutes, {} seconds.",
seconds / 86400,
(seconds % 86400) / 60 / 60,
(seconds % 3600) / 60,
seconds % 60,
);
Ok(RoomMessageEventContent::notice_html(String::new(), result))
}
pub(crate) async fn show_config(_body: Vec<&str>) -> Result<RoomMessageEventContent> {
// Construct and send the response
Ok(RoomMessageEventContent::text_plain(format!("{}", services().globals.config)))
}
pub(crate) async fn memory_usage(_body: Vec<&str>) -> Result<RoomMessageEventContent> {
let response1 = services().memory_usage().await;
let response2 = services().globals.db.memory_usage();
let response0 = services().memory_usage().await;
let response1 = services().globals.db.memory_usage();
let response2 = crate::alloc::memory_usage();
Ok(RoomMessageEventContent::text_plain(format!(
"Services:\n{response1}\n\nDatabase:\n{response2}"
"Services:\n{response0}\n\nDatabase:\n{response1}\n{}",
if !response2.is_empty() {
"Allocator:\n{response2}"
} else {
""
}
)))
}
+41
View File
@@ -0,0 +1,41 @@
//! test commands generally used for hot lib reloadable functions.
//! see <https://github.com/rksm/hot-lib-reloader-rs?tab=readme-ov-file#usage> for more details if you are a dev
//#[cfg(not(feature = "hot_reload"))]
//#[allow(unused_imports)]
//#[allow(clippy::wildcard_imports)]
// non hot reloadable functions (?)
//use hot_lib::*;
#[cfg(feature = "hot_reload")]
#[allow(unused_imports)]
#[allow(clippy::wildcard_imports)]
use hot_lib_funcs::*;
use ruma::events::room::message::RoomMessageEventContent;
use crate::{debug_error, Result};
#[cfg(feature = "hot_reload")]
#[hot_lib_reloader::hot_module(dylib = "lib")]
mod hot_lib_funcs {
// these will be functions from lib.rs, so `use hot_lib_funcs::test_command;`
hot_functions_from_file!("hot_lib/src/lib.rs");
}
#[cfg_attr(test, derive(Debug))]
#[derive(clap::Subcommand)]
pub(crate) enum TestCommands {
// !admin test test1
Test1,
}
pub(crate) async fn process(command: TestCommands, _body: Vec<&str>) -> Result<RoomMessageEventContent> {
Ok(match command {
TestCommands::Test1 => {
debug_error!("before calling test_command");
test_command();
debug_error!("after calling test_command");
RoomMessageEventContent::notice_plain(String::from("loaded"))
},
})
}
+14
View File
@@ -0,0 +1,14 @@
use ruma::events::room::message::RoomMessageEventContent;
use crate::Result;
#[cfg_attr(test, derive(Debug))]
#[derive(clap::Subcommand)]
pub(crate) enum TesterCommands {
Tester,
}
pub(crate) async fn process(command: TesterCommands, _body: Vec<&str>) -> Result<RoomMessageEventContent> {
Ok(match command {
TesterCommands::Tester => RoomMessageEventContent::notice_plain(String::from("complete")),
})
}
+9 -4
View File
@@ -1,13 +1,14 @@
use std::{fmt::Write as _, sync::Arc};
use itertools::Itertools;
use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, UserId};
use tracing::{error, info, warn};
use crate::{
api::client_server::{join_room_by_id_helper, leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH},
service::admin::{escape_html, get_room_info},
services, utils, Result,
services,
utils::{self, user_id::user_is_local},
Result,
};
pub(crate) async fn list(_body: Vec<&str>) -> Result<RoomMessageEventContent> {
@@ -37,6 +38,12 @@ pub(crate) async fn create(
},
};
if !user_is_local(&user_id) {
return Ok(RoomMessageEventContent::text_plain(format!(
"User {user_id} does not belong to our server."
)));
}
if user_id.is_historical() {
return Ok(RoomMessageEventContent::text_plain(format!(
"Userid {user_id} is not allowed due to historical"
@@ -318,8 +325,6 @@ pub(crate) async fn list_joined_rooms(_body: Vec<&str>, user_id: String) -> Resu
.rooms_joined(&user_id)
.filter_map(Result::ok)
.map(|room_id| get_room_info(&room_id))
.sorted_unstable()
.dedup()
.collect();
if rooms.is_empty() {
+2 -5
View File
@@ -2,7 +2,7 @@ use std::{sync::Arc, time::Duration};
use reqwest::redirect;
use crate::{service::globals::resolver, Config, Result};
use crate::{service::globals::resolver, utils::conduwuit_version, Config, Result};
pub(crate) struct Client {
pub(crate) default: reqwest::Client,
@@ -87,10 +87,7 @@ impl Client {
}
fn base(config: &Config) -> Result<reqwest::ClientBuilder> {
let version = match option_env!("CONDUIT_VERSION_EXTRA") {
Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra),
None => env!("CARGO_PKG_VERSION").to_owned(),
};
let version = conduwuit_version();
let mut builder = reqwest::Client::builder()
.hickory_dns(true)
+6 -7
View File
@@ -7,7 +7,7 @@ use std::{
atomic::{self, AtomicBool},
Arc,
},
time::Instant,
time::{Instant, SystemTime},
};
use argon2::Argon2;
@@ -27,10 +27,9 @@ use ruma::{
};
use tokio::sync::{broadcast, watch::Receiver, Mutex, RwLock};
use tracing::{error, info, trace};
use tracing_subscriber::{EnvFilter, Registry};
use url::Url;
use crate::{services, Config, Result};
use crate::{services, Config, LogLevelReloadHandles, Result};
mod client;
mod data;
@@ -45,7 +44,7 @@ type SyncHandle = (
pub(crate) struct Service<'a> {
pub(crate) db: &'static dyn Data,
pub(crate) tracing_reload_handle: tracing_subscriber::reload::Handle<EnvFilter, Registry>,
pub(crate) tracing_reload_handle: LogLevelReloadHandles,
pub(crate) config: Config,
pub(crate) cidr_range_denylist: Vec<IPAddress>,
keypair: Arc<ruma::signatures::Ed25519KeyPair>,
@@ -64,7 +63,7 @@ pub(crate) struct Service<'a> {
pub(crate) roomid_federationhandletime: RwLock<HashMap<OwnedRoomId, (OwnedEventId, Instant)>>,
pub(crate) stateres_mutex: Arc<Mutex<()>>,
pub(crate) rotate: RotationHandler,
pub(crate) started: SystemTime,
pub(crate) shutdown: AtomicBool,
pub(crate) argon: Argon2<'a>,
}
@@ -99,8 +98,7 @@ impl Default for RotationHandler {
impl Service<'_> {
pub(crate) fn load(
db: &'static dyn Data, config: &Config,
tracing_reload_handle: tracing_subscriber::reload::Handle<EnvFilter, Registry>,
db: &'static dyn Data, config: &Config, tracing_reload_handle: LogLevelReloadHandles,
) -> Result<Self> {
let keypair = db.load_keypair();
@@ -167,6 +165,7 @@ impl Service<'_> {
stateres_mutex: Arc::new(Mutex::new(())),
sync_receivers: RwLock::new(HashMap::new()),
rotate: RotationHandler::new(),
started: SystemTime::now(),
shutdown: AtomicBool::new(false),
argon,
};
+12
View File
@@ -51,6 +51,10 @@ impl Resolver {
for sys_conf in sys_conf.name_servers() {
let mut ns = sys_conf.clone();
if config.query_over_tcp_only {
ns.protocol = hickory_resolver::config::Protocol::Tcp;
}
ns.trust_negative_responses = !config.query_all_nameservers;
conf.add_name_server(ns);
@@ -67,6 +71,14 @@ impl Resolver {
opts.num_concurrent_reqs = 1;
opts.shuffle_dns_servers = true;
opts.rotate = true;
opts.ip_strategy = match config.ip_lookup_strategy {
1 => hickory_resolver::config::LookupIpStrategy::Ipv4Only,
2 => hickory_resolver::config::LookupIpStrategy::Ipv6Only,
3 => hickory_resolver::config::LookupIpStrategy::Ipv4AndIpv6,
4 => hickory_resolver::config::LookupIpStrategy::Ipv6thenIpv4,
_ => hickory_resolver::config::LookupIpStrategy::Ipv4thenIpv6,
};
opts.authentic_data = false;
let resolver = Arc::new(TokioAsyncResolver::tokio(conf, opts));
let overrides = Arc::new(StdRwLock::new(TlsNameMap::new()));
+60 -58
View File
@@ -476,66 +476,68 @@ impl Service {
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use base64::{engine::general_purpose, Engine as _};
use super::*;
struct MockedKVDatabase;
impl Data for MockedKVDatabase {
fn create_file_metadata(
&self, _sender_user: Option<&str>, mxc: String, width: u32, height: u32, content_disposition: Option<&str>,
content_type: Option<&str>,
) -> Result<Vec<u8>> {
// copied from src/database/key_value/media.rs
let mut key = mxc.as_bytes().to_vec();
key.push(0xFF);
key.extend_from_slice(&width.to_be_bytes());
key.extend_from_slice(&height.to_be_bytes());
key.push(0xFF);
key.extend_from_slice(
content_disposition
.as_ref()
.map(|f| f.as_bytes())
.unwrap_or_default(),
);
key.push(0xFF);
key.extend_from_slice(
content_type
.as_ref()
.map(|c| c.as_bytes())
.unwrap_or_default(),
);
Ok(key)
}
fn delete_file_mxc(&self, _mxc: String) -> Result<()> { todo!() }
fn search_mxc_metadata_prefix(&self, _mxc: String) -> Result<Vec<Vec<u8>>> { todo!() }
fn get_all_media_keys(&self) -> Result<Vec<Vec<u8>>> { todo!() }
fn search_file_metadata(
&self, _mxc: String, _width: u32, _height: u32,
) -> Result<(Option<String>, Option<String>, Vec<u8>)> {
todo!()
}
fn remove_url_preview(&self, _url: &str) -> Result<()> { todo!() }
fn set_url_preview(&self, _url: &str, _data: &UrlPreviewData, _timestamp: std::time::Duration) -> Result<()> {
todo!()
}
fn get_url_preview(&self, _url: &str) -> Option<UrlPreviewData> { todo!() }
}
#[tokio::test]
#[cfg(feature = "sha256_media")]
#[tokio::test]
async fn long_file_names_works() {
use std::path::PathBuf;
use base64::{engine::general_purpose, Engine as _};
use super::*;
struct MockedKVDatabase;
impl Data for MockedKVDatabase {
fn create_file_metadata(
&self, _sender_user: Option<&str>, mxc: String, width: u32, height: u32,
content_disposition: Option<&str>, content_type: Option<&str>,
) -> Result<Vec<u8>> {
// copied from src/database/key_value/media.rs
let mut key = mxc.as_bytes().to_vec();
key.push(0xFF);
key.extend_from_slice(&width.to_be_bytes());
key.extend_from_slice(&height.to_be_bytes());
key.push(0xFF);
key.extend_from_slice(
content_disposition
.as_ref()
.map(|f| f.as_bytes())
.unwrap_or_default(),
);
key.push(0xFF);
key.extend_from_slice(
content_type
.as_ref()
.map(|c| c.as_bytes())
.unwrap_or_default(),
);
Ok(key)
}
fn delete_file_mxc(&self, _mxc: String) -> Result<()> { todo!() }
fn search_mxc_metadata_prefix(&self, _mxc: String) -> Result<Vec<Vec<u8>>> { todo!() }
fn get_all_media_keys(&self) -> Result<Vec<Vec<u8>>> { todo!() }
fn search_file_metadata(
&self, _mxc: String, _width: u32, _height: u32,
) -> Result<(Option<String>, Option<String>, Vec<u8>)> {
todo!()
}
fn remove_url_preview(&self, _url: &str) -> Result<()> { todo!() }
fn set_url_preview(
&self, _url: &str, _data: &UrlPreviewData, _timestamp: std::time::Duration,
) -> Result<()> {
todo!()
}
fn get_url_preview(&self, _url: &str) -> Option<UrlPreviewData> { todo!() }
}
static DB: MockedKVDatabase = MockedKVDatabase;
let media = Service {
db: &DB,
+2 -6
View File
@@ -6,7 +6,7 @@ use std::{
use lru_cache::LruCache;
use tokio::sync::{broadcast, Mutex, RwLock};
use crate::{Config, Result};
use crate::{Config, LogLevelReloadHandles, Result};
pub(crate) mod account_data;
pub(crate) mod admin;
@@ -55,11 +55,7 @@ impl Services<'_> {
+ sending::Data
+ 'static,
>(
db: &'static D, config: &Config,
tracing_reload_handle: tracing_subscriber::reload::Handle<
tracing_subscriber::EnvFilter,
tracing_subscriber::Registry,
>,
db: &'static D, config: &Config, tracing_reload_handle: LogLevelReloadHandles,
) -> Result<Self> {
Ok(Self {
appservice: appservice::Service::build(db)?,
+6 -2
View File
@@ -13,7 +13,11 @@ use serde::{Deserialize, Serialize};
use tokio::{sync::Mutex, time::sleep};
use tracing::{debug, error};
use crate::{services, utils, Config, Error, Result};
use crate::{
services,
utils::{self, user_id::user_is_local},
Config, Error, Result,
};
/// Represents data required to be kept in order to implement the presence
/// specification.
@@ -154,7 +158,7 @@ impl Service {
self.db
.set_presence(user_id, presence_state, currently_active, last_active_ago, status_msg)?;
if self.timeout_remote_users || user_id.server_name() == services().globals.server_name() {
if self.timeout_remote_users || user_is_local(user_id) {
let timeout = match presence_state {
PresenceState::Online => services().globals.config.presence_idle_timeout_s,
_ => services().globals.config.presence_offline_timeout_s,
+1
View File
@@ -30,6 +30,7 @@ impl Service {
.filter_map(move |sid| services().rooms.short.get_eventid_from_short(sid).ok()))
}
#[tracing::instrument(skip_all)]
pub(crate) async fn get_auth_chain(&self, room_id: &RoomId, starting_events: &[&EventId]) -> Result<Vec<u64>> {
const NUM_BUCKETS: usize = 50; //TODO: change possible w/o disrupting db?
const BUCKET: BTreeSet<(u64, &EventId)> = BTreeSet::new();
+38 -38
View File
@@ -32,7 +32,7 @@ use ruma::{
use tokio::sync::Mutex;
use tracing::{debug, error, warn};
use crate::{debug_info, services, Error, Result};
use crate::{debug_info, services, utils::server_name::server_is_ours, Error, Result};
pub(crate) struct CachedSpaceHierarchySummary {
summary: SpaceHierarchyParentSummary,
@@ -427,36 +427,10 @@ impl Service {
async fn get_summary_and_children_federation(
&self, current_room: &OwnedRoomId, suggested_only: bool, user_id: &UserId, via: &[OwnedServerName],
) -> Result<Option<SummaryAccessibility>> {
// try to find more servers to fetch hierachy from if the only
// choice is the room ID's server name (usually dead)
//
// all spaces are normal rooms, so they should always have at least
// 1 admin in it which has a far higher chance of their server still
// being alive
let power_levels: ruma::events::room::power_levels::RoomPowerLevelsEventContent = services()
.rooms
.state_accessor
.room_state_get(current_room, &StateEventType::RoomPowerLevels, "")?
.map(|ev| {
serde_json::from_str(ev.content.get())
.map_err(|_| Error::bad_database("invalid m.room.power_levels event"))
})
.transpose()?
.unwrap_or_default();
// add server names of the list of admins in the room for backfill server
via.to_owned().extend(
power_levels
.users
.iter()
.filter(|(_, level)| **level > power_levels.users_default)
.map(|(user_id, _)| user_id.server_name())
.filter(|server| server != &services().globals.server_name())
.map(ToOwned::to_owned),
);
debug_info!("servers via for federation hierarchy: {via:?}");
for server in via {
debug!("Asking {server} for /hierarchy");
debug_info!("Asking {server} for /hierarchy");
if let Ok(response) = services()
.sending
.send_federation_request(
@@ -649,20 +623,46 @@ impl Service {
})
}
// TODO: make this a lot less messy
pub(crate) async fn get_client_hierarchy(
&self, sender_user: &UserId, room_id: &RoomId, limit: usize, skip: usize, max_depth: usize,
suggested_only: bool,
) -> Result<client::space::get_hierarchy::v1::Response> {
// try to find more servers to fetch hierachy from if the only
// choice is the room ID's server name (usually dead)
//
// all spaces are normal rooms, so they should always have at least
// 1 admin in it which has a far higher chance of their server still
// being alive
let power_levels: ruma::events::room::power_levels::RoomPowerLevelsEventContent = services()
.rooms
.state_accessor
.room_state_get(room_id, &StateEventType::RoomPowerLevels, "")?
.map(|ev| {
serde_json::from_str(ev.content.get())
.map_err(|_| Error::bad_database("invalid m.room.power_levels event"))
})
.transpose()?
.unwrap_or_default();
// add server names of the list of admins in the room for backfill server
let mut via = power_levels
.users
.iter()
.filter(|(_, level)| **level > power_levels.users_default)
.map(|(user_id, _)| user_id.server_name())
.filter(|server| !server_is_ours(server))
.map(ToOwned::to_owned)
.collect::<Vec<_>>();
if let Some(server_name) = room_id.server_name() {
via.push(server_name.to_owned());
}
debug_info!("servers via for hierarchy: {via:?}");
match self
.get_summary_and_children_client(
&room_id.to_owned(),
suggested_only,
sender_user,
&match room_id.server_name() {
Some(server_name) => vec![server_name.to_owned()],
None => vec![],
},
)
.get_summary_and_children_client(&room_id.to_owned(), suggested_only, sender_user, &via)
.await?
{
Some(SummaryAccessibility::Accessible(summary)) => {
+2 -2
View File
@@ -19,7 +19,7 @@ use ruma::{
};
use tracing::{error, warn};
use crate::{service::appservice::RegistrationInfo, services, Error, Result};
use crate::{service::appservice::RegistrationInfo, services, utils::user_id::user_is_local, Error, Result};
mod data;
@@ -43,7 +43,7 @@ impl Service {
// TODO: use futures to update remote profiles without blocking the membership
// update
#[allow(clippy::collapsible_if)]
if user_id.server_name() != services().globals.server_name() {
if !user_is_local(user_id) {
if !services().users.exists(user_id)? {
services().users.create(user_id, None)?;
}
+20 -16
View File
@@ -41,7 +41,9 @@ use crate::{
appservice::NamespaceRegex,
pdu::{EventHash, PduBuilder},
},
services, utils, Error, PduEvent, Result,
services,
utils::{self, server_name::server_is_ours},
Error, PduEvent, Result,
};
#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug)]
@@ -512,9 +514,12 @@ impl Service {
// the administrator can execute commands as conduit
let from_conduit = pdu.sender == server_user && services().globals.emergency_password().is_none();
if let Some(admin_room) = service::admin::Service::get_admin_room()? {
if let Some(admin_room) = service::admin::Service::get_admin_room().await? {
if to_conduit && !from_conduit && admin_room == pdu.room_id {
services().admin.process_message(body, pdu.event_id.clone());
services()
.admin
.process_message(body, pdu.event_id.clone())
.await;
}
}
}
@@ -815,7 +820,7 @@ impl Service {
) -> Result<Arc<EventId>> {
let (pdu, pdu_json) = self.create_hash_and_sign_event(pdu_builder, sender, room_id, state_lock)?;
if let Some(admin_room) = service::admin::Service::get_admin_room()? {
if let Some(admin_room) = service::admin::Service::get_admin_room().await? {
if admin_room == room_id {
match pdu.event_type() {
TimelineEventType::RoomEncryption => {
@@ -849,8 +854,7 @@ impl Service {
.state_cache
.room_members(room_id)
.filter_map(Result::ok)
.filter(|m| m.server_name() == server_name)
.filter(|m| m != target)
.filter(|m| server_is_ours(m.server_name()) && m != target)
.count();
if count < 2 {
warn!("Last admin cannot leave from admins room");
@@ -875,8 +879,7 @@ impl Service {
.state_cache
.room_members(room_id)
.filter_map(Result::ok)
.filter(|m| m.server_name() == server_name)
.filter(|m| m != target)
.filter(|m| server_is_ours(m.server_name()) && m != target)
.count();
if count < 2 {
warn!("Last admin cannot be banned in admins room");
@@ -1056,8 +1059,9 @@ impl Service {
.state_cache
.room_servers(room_id)
.filter_map(Result::ok)
.filter(|server| services().globals.trusted_servers().contains(server))
.filter(|server| server != services().globals.server_name()),
.filter(|server_name| {
services().globals.trusted_servers().contains(server_name) && !server_is_ours(server_name)
}),
);
// add server names from room aliases on the room ID
@@ -1068,16 +1072,16 @@ impl Service {
.collect::<Result<Vec<_>, _>>();
if let Ok(aliases) = &room_aliases {
for alias in aliases {
if alias.server_name() != services().globals.server_name() {
if !server_is_ours(alias.server_name()) {
servers.push(alias.server_name().to_owned());
}
}
}
// add room ID server name for backfill server
if let Some(server) = room_id.server_name() {
if server != services().globals.server_name() {
servers.push(server.to_owned());
if let Some(server_name) = room_id.server_name() {
if !server_is_ours(server_name) {
servers.push(server_name.to_owned());
}
}
@@ -1099,7 +1103,7 @@ impl Service {
.iter()
.filter(|(_, level)| **level > power_levels.users_default)
.map(|(user_id, _)| user_id.server_name())
.filter(|server| server != &services().globals.server_name())
.filter(|server_name| !server_is_ours(server_name))
.map(ToOwned::to_owned),
);
@@ -1107,7 +1111,7 @@ impl Service {
if let Some(server_index) = servers
.clone()
.into_iter()
.position(|server| server == services().globals.server_name())
.position(|server_name| server_is_ours(&server_name))
{
servers.remove(server_index);
}
+12 -12
View File
@@ -6,9 +6,12 @@ use ruma::{
OwnedRoomId, OwnedUserId, RoomId, UserId,
};
use tokio::sync::{broadcast, RwLock};
use tracing::debug;
use crate::{services, utils, Result};
use crate::{
debug_info, services,
utils::{self, user_id::user_is_local},
Result,
};
pub(crate) struct Service {
pub(crate) typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>, // u64 is unix timestamp of timeout
@@ -22,7 +25,7 @@ impl Service {
/// Sets a user as typing until the timeout timestamp is reached or
/// roomtyping_remove is called.
pub(crate) async fn typing_add(&self, user_id: &UserId, room_id: &RoomId, timeout: u64) -> Result<()> {
debug!("typing add {:?} in {:?} timeout:{:?}", user_id, room_id, timeout);
debug_info!("typing started {:?} in {:?} timeout:{:?}", user_id, room_id, timeout);
// update clients
self.typing
.write()
@@ -37,7 +40,7 @@ impl Service {
_ = self.typing_update_sender.send(room_id.to_owned());
// update federation
if user_id.server_name() == services().globals.server_name() {
if user_is_local(user_id) {
self.federation_send(room_id, user_id, true)?;
}
@@ -46,7 +49,7 @@ impl Service {
/// Removes a user from typing before the timeout is reached.
pub(crate) async fn typing_remove(&self, user_id: &UserId, room_id: &RoomId) -> Result<()> {
debug!("typing remove {:?} in {:?}", user_id, room_id);
debug_info!("typing stopped {:?} in {:?}", user_id, room_id);
// update clients
self.typing
.write()
@@ -61,7 +64,7 @@ impl Service {
_ = self.typing_update_sender.send(room_id.to_owned());
// update federation
if user_id.server_name() == services().globals.server_name() {
if user_is_local(user_id) {
self.federation_send(room_id, user_id, false)?;
}
@@ -103,7 +106,7 @@ impl Service {
let typing = &mut self.typing.write().await;
let room = typing.entry(room_id.to_owned()).or_default();
for user in &removable {
debug!("typing maintain remove {:?} in {:?}", &user, room_id);
debug_info!("typing timeout {:?} in {:?}", &user, room_id);
room.remove(user);
}
// update clients
@@ -115,7 +118,7 @@ impl Service {
// update federation
for user in removable {
if user.server_name() == services().globals.server_name() {
if user_is_local(&user) {
self.federation_send(room_id, &user, false)?;
}
}
@@ -154,10 +157,7 @@ impl Service {
}
fn federation_send(&self, room_id: &RoomId, user_id: &UserId, typing: bool) -> Result<()> {
debug_assert!(
user_id.server_name() == services().globals.server_name(),
"tried to broadcast typing status of remote user",
);
debug_assert!(user_is_local(user_id), "tried to broadcast typing status of remote user",);
if !services().globals.config.allow_outgoing_typing {
return Ok(());
}
+6 -6
View File
@@ -8,12 +8,12 @@ use ruma::{
use tokio::sync::Mutex;
use tracing::warn;
use crate::{services, Config, Error, Result};
use crate::{services, utils::server_name::server_is_ours, Config, Error, Result};
mod appservice;
mod data;
mod send;
mod sender;
pub(crate) mod send;
pub(crate) mod sender;
pub(crate) use send::FedDest;
pub(crate) struct Service {
@@ -93,7 +93,7 @@ impl Service {
.state_cache
.room_servers(room_id)
.filter_map(Result::ok)
.filter(|server| &**server != services().globals.server_name());
.filter(|server_name| !server_is_ours(server_name));
self.send_pdu_servers(servers, pdu_id)
}
@@ -144,7 +144,7 @@ impl Service {
.state_cache
.room_servers(room_id)
.filter_map(Result::ok)
.filter(|server| &**server != services().globals.server_name());
.filter(|server_name| !server_is_ours(server_name));
self.send_edu_servers(servers, serialized)
}
@@ -183,7 +183,7 @@ impl Service {
.state_cache
.room_servers(room_id)
.filter_map(Result::ok)
.filter(|server| &**server != services().globals.server_name());
.filter(|server_name| !server_is_ours(server_name));
self.flush_servers(servers)
}
+252 -17
View File
@@ -13,6 +13,7 @@ use ruma::{
client::error::Error as RumaError, EndpointError, IncomingResponse, MatrixVersion, OutgoingRequest,
SendAccessToken,
},
events::room::message::RoomMessageEventContent,
OwnedServerName, ServerName,
};
use tracing::{debug, error, trace};
@@ -194,7 +195,7 @@ async fn get_actual_dest(server_name: &ServerName) -> Result<ActualDest> {
} else {
cached = false;
validate_dest(server_name)?;
resolve_actual_dest(server_name).await?
resolve_actual_dest(server_name, false, false).await?
};
let string = dest.clone().into_https_string();
@@ -210,59 +211,220 @@ async fn get_actual_dest(server_name: &ServerName) -> Result<ActualDest> {
/// Implemented according to the specification at <https://matrix.org/docs/spec/server_server/r0.1.4#resolving-server-names>
/// Numbers in comments below refer to bullet points in linked section of
/// specification
async fn resolve_actual_dest(dest: &'_ ServerName) -> Result<(FedDest, String)> {
pub(crate) async fn resolve_actual_dest(
dest: &'_ ServerName, no_cache_dest: bool, admin_room_caller: bool,
) -> Result<(FedDest, String)> {
trace!("Finding actual destination for {dest}");
let dest_str = dest.as_str().to_owned();
let mut hostname = dest_str.clone();
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(
"Checking for 1: IP literal with provided or default port",
))
.await;
}
#[allow(clippy::single_match_else)]
let actual_dest = match get_ip_with_port(&dest_str) {
Some(host_port) => {
debug!("1: IP literal with provided or default port");
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"1: IP literal with provided or default port\n\nHost and Port: {host_port:?}"
)))
.await;
}
host_port
},
None => {
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(
"Checking for 2: Hostname with included port",
))
.await;
}
if let Some(pos) = dest_str.find(':') {
debug!("2: Hostname with included port");
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain("2: Hostname with included port"))
.await;
}
let (host, port) = dest_str.split_at(pos);
query_and_cache_override(host, host, port.parse::<u16>().unwrap_or(8448)).await?;
if !no_cache_dest {
query_and_cache_override(host, host, port.parse::<u16>().unwrap_or(8448)).await?;
}
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!("Host: {host} | Port: {port}")))
.await;
}
FedDest::Named(host.to_owned(), port.to_owned())
} else {
trace!("Requesting well known for {dest}");
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"Checking for 3: A .well-known file is available. Requesting well-known for {dest}"
)))
.await;
}
if let Some(delegated_hostname) = request_well_known(dest.as_str()).await? {
debug!("3: A .well-known file is available");
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain("3: A .well-known file is available"))
.await;
}
hostname = add_port_to_hostname(&delegated_hostname).into_uri_string();
match get_ip_with_port(&delegated_hostname) {
Some(host_and_port) => host_and_port, // 3.1: IP literal in .well-known file
Some(host_and_port) => {
debug!("3.1: IP literal in .well-known file");
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"3.1: IP literal in .well-known file\n\nHost and Port: {host_and_port:?}"
)))
.await;
}
host_and_port
},
None => {
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(
"Checking for 3.2: Hostname with port in .well-known file",
))
.await;
}
if let Some(pos) = delegated_hostname.find(':') {
debug!("3.2: Hostname with port in .well-known file");
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(
"3.2: Hostname with port in .well-known file",
))
.await;
}
let (host, port) = delegated_hostname.split_at(pos);
query_and_cache_override(host, host, port.parse::<u16>().unwrap_or(8448)).await?;
if !no_cache_dest {
query_and_cache_override(host, host, port.parse::<u16>().unwrap_or(8448)).await?;
}
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"Host: {host} | Port: {port}"
)))
.await;
}
FedDest::Named(host.to_owned(), port.to_owned())
} else {
trace!("Delegated hostname has no port in this branch");
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(
"Delegated hostname has no port specified",
))
.await;
}
if let Some(hostname_override) = query_srv_record(&delegated_hostname).await? {
debug!("3.3: SRV lookup successful");
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(
"3.3: SRV lookup successful",
))
.await;
}
let force_port = hostname_override.port();
query_and_cache_override(
&delegated_hostname,
&hostname_override.hostname(),
force_port.unwrap_or(8448),
)
.await?;
if !no_cache_dest {
query_and_cache_override(
&delegated_hostname,
&hostname_override.hostname(),
force_port.unwrap_or(8448),
)
.await?;
}
if let Some(port) = force_port {
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"Host: {delegated_hostname} | Port: {port}"
)))
.await;
}
FedDest::Named(delegated_hostname, format!(":{port}"))
} else {
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"Host: {delegated_hostname} | Port: 8448"
)))
.await;
}
add_port_to_hostname(&delegated_hostname)
}
} else {
debug!("3.4: No SRV records, just use the hostname from .well-known");
query_and_cache_override(&delegated_hostname, &delegated_hostname, 8448).await?;
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(
"3.4: No SRV records, just use the hostname from .well-known",
))
.await;
}
if !no_cache_dest {
query_and_cache_override(&delegated_hostname, &delegated_hostname, 8448)
.await?;
}
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"Host: {delegated_hostname} | Port: 8448"
)))
.await;
}
add_port_to_hostname(&delegated_hostname)
}
}
@@ -270,21 +432,84 @@ async fn resolve_actual_dest(dest: &'_ ServerName) -> Result<(FedDest, String)>
}
} else {
trace!("4: No .well-known or an error occured");
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(
"4: No .well-known or an error occured",
))
.await;
}
if let Some(hostname_override) = query_srv_record(&dest_str).await? {
debug!("4: No .well-known; SRV record found");
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(
"4: No .well-known; SRV record found",
))
.await;
}
let force_port = hostname_override.port();
query_and_cache_override(&hostname, &hostname_override.hostname(), force_port.unwrap_or(8448))
if !no_cache_dest {
query_and_cache_override(
&hostname,
&hostname_override.hostname(),
force_port.unwrap_or(8448),
)
.await?;
}
if let Some(port) = force_port {
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"Host: {hostname} | Port: {port}"
)))
.await;
}
FedDest::Named(hostname.clone(), format!(":{port}"))
} else {
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"Host: {hostname} | Port: 8448"
)))
.await;
}
add_port_to_hostname(&hostname)
}
} else {
debug!("4: No .well-known; 5: No SRV record found");
query_and_cache_override(&dest_str, &dest_str, 8448).await?;
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(
"4: No .well-known; 5: No SRV record found",
))
.await;
}
if !no_cache_dest {
query_and_cache_override(&dest_str, &dest_str, 8448).await?;
}
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"Host: {dest_str} | Port: 8448"
)))
.await;
}
add_port_to_hostname(&dest_str)
}
}
@@ -306,6 +531,14 @@ async fn resolve_actual_dest(dest: &'_ ServerName) -> Result<(FedDest, String)>
};
debug!("Actual destination: {actual_dest:?} hostname: {hostname:?}");
if admin_room_caller {
services()
.admin
.send_message(RoomMessageEventContent::notice_plain(format!(
"Actual destination: {actual_dest:?} | Hostname: {hostname:?}"
)))
.await;
}
Ok((actual_dest, hostname.into_uri_string()))
}
@@ -433,7 +666,8 @@ fn handle_resolve_error(e: &ResolveError) -> Result<()> {
ResolveErrorKind::NoRecordsFound {
..
} => {
debug_warn!("{e}");
// Raise to debug_warn if we can find out the result wasn't from cache
debug!("{e}");
Ok(())
},
_ => {
@@ -495,8 +729,9 @@ where
http_request.headers_mut().insert(
AUTHORIZATION,
HeaderValue::from_str(&format!(
"X-Matrix origin={},key=\"{}\",sig=\"{}\"",
services().globals.server_name(),
"X-Matrix origin=\"{}\",destination=\"{}\",key=\"{}\",sig=\"{}\"",
services().globals.config.server_name,
dest,
s.0,
s.1
))
+9 -4
View File
@@ -23,7 +23,12 @@ use ruma::{
use tracing::{debug, error, warn};
use super::{appservice, send, Destination, Msg, SendingEvent, Service};
use crate::{service::presence::Presence, services, utils::calculate_hash, Error, PduEvent, Result};
use crate::{
service::presence::Presence,
services,
utils::{calculate_hash, user_id::user_is_local},
Error, PduEvent, Result,
};
#[derive(Debug)]
enum TransactionStatus {
@@ -244,7 +249,7 @@ impl Service {
.users
.keys_changed(room_id.as_ref(), since, None)
.filter_map(Result::ok)
.filter(|user_id| user_id.server_name() == services().globals.server_name()),
.filter(|user_id| user_is_local(user_id)),
);
if services().globals.allow_outgoing_read_receipts()
@@ -288,7 +293,7 @@ fn select_edus_presence(
for (user_id, count, presence_bytes) in services().presence.presence_since(since) {
*max_edu_count = cmp::max(count, *max_edu_count);
if user_id.server_name() != services().globals.server_name() {
if !user_is_local(&user_id) {
continue;
}
@@ -336,7 +341,7 @@ fn select_edus_receipts(
let (user_id, count, read_receipt) = r?;
*max_edu_count = cmp::max(count, *max_edu_count);
if user_id.server_name() != services().globals.server_name() {
if !user_is_local(&user_id) {
continue;
}
+2 -15
View File
@@ -4,24 +4,11 @@ use std::path::PathBuf;
use clap::Parser;
/// Returns the current version of the crate with extra info if supplied
///
/// Set the environment variable `CONDUIT_VERSION_EXTRA` to any UTF-8 string to
/// include it in parenthesis after the SemVer version. A common value are git
/// commit hashes.
#[allow(clippy::doc_markdown)]
fn version() -> String {
let cargo_pkg_version = env!("CARGO_PKG_VERSION");
match option_env!("CONDUIT_VERSION_EXTRA") {
Some(x) => format!("{} ({})", cargo_pkg_version, x),
None => cargo_pkg_version.to_owned(),
}
}
use super::conduwuit_version;
/// Commandline arguments
#[derive(Parser, Debug)]
#[clap(version = version(), about, long_about = None)]
#[clap(version = conduwuit_version(), about, long_about = None)]
pub(crate) struct Args {
#[arg(short, long)]
/// Optional argument to the path of a conduwuit config TOML file
+18
View File
@@ -1,6 +1,8 @@
pub(crate) mod clap;
pub(crate) mod debug;
pub(crate) mod error;
pub(crate) mod server_name;
pub(crate) mod user_id;
use std::{
cmp,
@@ -185,3 +187,19 @@ impl fmt::Display for HtmlEscape<'_> {
Ok(())
}
}
/// one true function for returning the conduwuit version with the necessary
/// CONDUWUIT_VERSION_EXTRA env variables used if specified
///
/// Set the environment variable `CONDUWUIT_VERSION_EXTRA` to any UTF-8 string
/// to include it in parenthesis after the SemVer version. A common value are
/// git commit hashes.
pub(crate) fn conduwuit_version() -> String {
match option_env!("CONDUWUIT_VERSION_EXTRA") {
Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra),
None => match option_env!("CONDUIT_VERSION_EXTRA") {
Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra),
None => env!("CARGO_PKG_VERSION").to_owned(),
},
}
}
+8
View File
@@ -0,0 +1,8 @@
//! utilities for doing/checking things with ServerName's/server_name's
use ruma::ServerName;
use crate::services;
/// checks if `server_name` is ours
pub(crate) fn server_is_ours(server_name: &ServerName) -> bool { server_name == services().globals.config.server_name }
+8
View File
@@ -0,0 +1,8 @@
//! utilities for doing things with UserId's / usernames
use ruma::UserId;
use crate::services;
/// checks if `user_id` is local to us via server_name comparison
pub(crate) fn user_is_local(user_id: &UserId) -> bool { user_id.server_name() == services().globals.config.server_name }
-580
View File
@@ -1,580 +0,0 @@
{
"Action": "fail",
"Test": "TestBannedUserCannotSendJoin"
}
{
"Action": "fail",
"Test": "TestCannotSendKnockViaSendKnockInMSC3787Room"
}
{
"Action": "fail",
"Test": "TestCannotSendKnockViaSendKnockInMSC3787Room/event_with_mismatched_state_key"
}
{
"Action": "fail",
"Test": "TestCannotSendKnockViaSendKnockInMSC3787Room/invite_event"
}
{
"Action": "fail",
"Test": "TestCannotSendKnockViaSendKnockInMSC3787Room/join_event"
}
{
"Action": "fail",
"Test": "TestCannotSendKnockViaSendKnockInMSC3787Room/leave_event"
}
{
"Action": "fail",
"Test": "TestCannotSendKnockViaSendKnockInMSC3787Room/non-state_membership_event"
}
{
"Action": "fail",
"Test": "TestCannotSendKnockViaSendKnockInMSC3787Room/regular_event"
}
{
"Action": "fail",
"Test": "TestCannotSendNonJoinViaSendJoinV1"
}
{
"Action": "fail",
"Test": "TestCannotSendNonJoinViaSendJoinV1/leave_event"
}
{
"Action": "fail",
"Test": "TestCannotSendNonJoinViaSendJoinV1/regular_event"
}
{
"Action": "fail",
"Test": "TestCannotSendNonJoinViaSendJoinV2"
}
{
"Action": "fail",
"Test": "TestCannotSendNonJoinViaSendJoinV2/leave_event"
}
{
"Action": "fail",
"Test": "TestCannotSendNonJoinViaSendJoinV2/regular_event"
}
{
"Action": "fail",
"Test": "TestCannotSendNonKnockViaSendKnock"
}
{
"Action": "fail",
"Test": "TestCannotSendNonKnockViaSendKnock/event_with_mismatched_state_key"
}
{
"Action": "fail",
"Test": "TestCannotSendNonKnockViaSendKnock/invite_event"
}
{
"Action": "fail",
"Test": "TestCannotSendNonKnockViaSendKnock/join_event"
}
{
"Action": "fail",
"Test": "TestCannotSendNonKnockViaSendKnock/leave_event"
}
{
"Action": "fail",
"Test": "TestCannotSendNonKnockViaSendKnock/non-state_membership_event"
}
{
"Action": "fail",
"Test": "TestCannotSendNonKnockViaSendKnock/regular_event"
}
{
"Action": "fail",
"Test": "TestClientSpacesSummary"
}
{
"Action": "fail",
"Test": "TestClientSpacesSummaryJoinRules"
}
{
"Action": "fail",
"Test": "TestClientSpacesSummary/max_depth"
}
{
"Action": "fail",
"Test": "TestClientSpacesSummary/pagination"
}
{
"Action": "fail",
"Test": "TestClientSpacesSummary/query_whole_graph"
}
{
"Action": "fail",
"Test": "TestClientSpacesSummary/redact_link"
}
{
"Action": "fail",
"Test": "TestClientSpacesSummary/suggested_only"
}
{
"Action": "fail",
"Test": "TestDeviceListsUpdateOverFederation"
}
{
"Action": "fail",
"Test": "TestDeviceListsUpdateOverFederation/good_connectivity"
}
{
"Action": "fail",
"Test": "TestDeviceListsUpdateOverFederation/interrupted_connectivity"
}
{
"Action": "fail",
"Test": "TestDeviceListsUpdateOverFederationOnRoomJoin"
}
{
"Action": "fail",
"Test": "TestDeviceListsUpdateOverFederation/stopped_server"
}
{
"Action": "fail",
"Test": "TestEventAuth"
}
{
"Action": "fail",
"Test": "TestFederationKeyUploadQuery"
}
{
"Action": "fail",
"Test": "TestFederationKeyUploadQuery/Can_claim_remote_one_time_key_using_POST"
}
{
"Action": "fail",
"Test": "TestFederationKeyUploadQuery/Can_query_remote_device_keys_using_POST"
}
{
"Action": "fail",
"Test": "TestFederationRejectInvite"
}
{
"Action": "fail",
"Test": "TestFederationRoomsInvite"
}
{
"Action": "fail",
"Test": "TestFederationRoomsInvite/Parallel"
}
{
"Action": "fail",
"Test": "TestFederationRoomsInvite/Parallel/Invited_user_can_reject_invite_over_federation"
}
{
"Action": "fail",
"Test": "TestFederationRoomsInvite/Parallel/Invited_user_can_reject_invite_over_federation_several_times"
}
{
"Action": "fail",
"Test": "TestGetMissingEventsGapFilling"
}
{
"Action": "fail",
"Test": "TestInboundCanReturnMissingEvents"
}
{
"Action": "fail",
"Test": "TestInboundCanReturnMissingEvents/Inbound_federation_can_return_missing_events_for_invited_visibility"
}
{
"Action": "fail",
"Test": "TestInboundCanReturnMissingEvents/Inbound_federation_can_return_missing_events_for_joined_visibility"
}
{
"Action": "fail",
"Test": "TestInboundCanReturnMissingEvents/Inbound_federation_can_return_missing_events_for_shared_visibility"
}
{
"Action": "fail",
"Test": "TestInboundCanReturnMissingEvents/Inbound_federation_can_return_missing_events_for_world_readable_visibility"
}
{
"Action": "fail",
"Test": "TestInboundFederationRejectsEventsWithRejectedAuthEvents"
}
{
"Action": "fail",
"Test": "TestJoinFederatedRoomFromApplicationServiceBridgeUser"
}
{
"Action": "fail",
"Test": "TestJoinFederatedRoomFromApplicationServiceBridgeUser/join_remote_federated_room_as_application_service_user"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/federation"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/federation/can_paginate_after_getting_remote_event_from_timestamp_to_event_endpoint"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/federation/looking_backwards,_should_be_able_to_find_event_that_was_sent_before_we_joined"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/federation/looking_forwards,_should_be_able_to_find_event_that_was_sent_before_we_joined"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/federation/when_looking_backwards_before_the_room_was_created,_should_be_able_to_find_event_that_was_imported"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/should_find_event_after_given_timestmap"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/should_find_event_before_given_timestmap"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/should_find_next_event_topologically_after_given_timestmap_when_all_message_timestamps_are_the_same"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/should_find_next_event_topologically_before_given_timestamp_when_all_message_timestamps_are_the_same"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/should_find_nothing_before_the_earliest_timestmap"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/should_not_be_able_to_query_a_private_room_you_are_not_a_member_of"
}
{
"Action": "fail",
"Test": "TestJumpToDateEndpoint/parallel/should_not_be_able_to_query_a_public_room_you_are_not_a_member_of"
}
{
"Action": "fail",
"Test": "TestKnocking"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_can_knock_on_a_room_without_a_reason"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_can_knock_on_a_room_without_a_reason#01"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_cannot_knock_on_a_room_they_are_already_in"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_cannot_knock_on_a_room_they_are_already_in#01"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_cannot_knock_on_a_room_they_are_already_invited_to"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_cannot_knock_on_a_room_they_are_already_invited_to#01"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_in_the_room_can_reject_a_knock"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_in_the_room_can_reject_a_knock#01"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_that_has_already_knocked_is_allowed_to_knock_again_on_the_same_room"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_that_has_already_knocked_is_allowed_to_knock_again_on_the_same_room#01"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_that_has_knocked_on_a_local_room_can_rescind_their_knock_and_then_knock_again"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_that_is_banned_from_a_room_cannot_knock_on_it"
}
{
"Action": "fail",
"Test": "TestKnocking/A_user_that_is_banned_from_a_room_cannot_knock_on_it#01"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail#01"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_can_knock_on_a_room_without_a_reason"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_can_knock_on_a_room_without_a_reason#01"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_cannot_knock_on_a_room_they_are_already_in"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_cannot_knock_on_a_room_they_are_already_in#01"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_cannot_knock_on_a_room_they_are_already_invited_to"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_cannot_knock_on_a_room_they_are_already_invited_to#01"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_in_the_room_can_accept_a_knock"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_in_the_room_can_accept_a_knock#01"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_in_the_room_can_reject_a_knock"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_in_the_room_can_reject_a_knock#01"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_that_has_already_knocked_is_allowed_to_knock_again_on_the_same_room"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_that_has_already_knocked_is_allowed_to_knock_again_on_the_same_room#01"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_that_has_knocked_on_a_local_room_can_rescind_their_knock_and_then_knock_again"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_that_is_banned_from_a_room_cannot_knock_on_it"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/A_user_that_is_banned_from_a_room_cannot_knock_on_it#01"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/Knocking_on_a_room_with_a_join_rule_other_than_'knock'_should_fail"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/Knocking_on_a_room_with_a_join_rule_other_than_'knock'_should_fail#01"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/Knocking_on_a_room_with_join_rule_'knock'_should_succeed"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/Knocking_on_a_room_with_join_rule_'knock'_should_succeed#01"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/Users_in_the_room_see_a_user's_membership_update_when_they_knock"
}
{
"Action": "fail",
"Test": "TestKnockingInMSC3787Room/Users_in_the_room_see_a_user's_membership_update_when_they_knock#01"
}
{
"Action": "fail",
"Test": "TestKnocking/Knocking_on_a_room_with_a_join_rule_other_than_'knock'_should_fail"
}
{
"Action": "fail",
"Test": "TestKnocking/Knocking_on_a_room_with_a_join_rule_other_than_'knock'_should_fail#01"
}
{
"Action": "fail",
"Test": "TestKnocking/Knocking_on_a_room_with_join_rule_'knock'_should_succeed"
}
{
"Action": "fail",
"Test": "TestKnocking/Knocking_on_a_room_with_join_rule_'knock'_should_succeed#01"
}
{
"Action": "fail",
"Test": "TestKnocking/Users_in_the_room_see_a_user's_membership_update_when_they_knock"
}
{
"Action": "fail",
"Test": "TestKnocking/Users_in_the_room_see_a_user's_membership_update_when_they_knock#01"
}
{
"Action": "fail",
"Test": "TestKnockRoomsInPublicRoomsDirectory"
}
{
"Action": "fail",
"Test": "TestKnockRoomsInPublicRoomsDirectoryInMSC3787Room"
}
{
"Action": "fail",
"Test": "TestMediaFilenames"
}
{
"Action": "fail",
"Test": "TestMediaFilenames/Parallel"
}
{
"Action": "fail",
"Test": "TestMediaFilenames/Parallel/ASCII"
}
{
"Action": "fail",
"Test": "TestMediaFilenames/Parallel/ASCII/Can_download_file_'name;with;semicolons'"
}
{
"Action": "fail",
"Test": "TestMediaFilenames/Parallel/ASCII/Can_download_file_'name_with_spaces'"
}
{
"Action": "fail",
"Test": "TestMediaFilenames/Parallel/Unicode"
}
{
"Action": "fail",
"Test": "TestMediaFilenames/Parallel/Unicode/Can_download_specifying_a_different_Unicode_file_name"
}
{
"Action": "fail",
"Test": "TestMediaFilenames/Parallel/Unicode/Can_download_with_Unicode_file_name_locally"
}
{
"Action": "fail",
"Test": "TestMediaFilenames/Parallel/Unicode/Can_download_with_Unicode_file_name_over_federation"
}
{
"Action": "fail",
"Test": "TestNetworkPartitionOrdering"
}
{
"Action": "fail",
"Test": "TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6"
}
{
"Action": "fail",
"Test": "TestRemotePresence"
}
{
"Action": "fail",
"Test": "TestRemotePresence/Presence_changes_are_also_reported_to_remote_room_members"
}
{
"Action": "fail",
"Test": "TestRemotePresence/Presence_changes_to_UNAVAILABLE_are_reported_to_remote_room_members"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsLocalJoin"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsLocalJoinInMSC3787Room"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_succeed_when_joined_to_allowed_room"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsLocalJoin/Join_should_succeed_when_joined_to_allowed_room"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsRemoteJoin"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsRemoteJoinFailOver"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsRemoteJoinFailOverInMSC3787Room"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsRemoteJoinInMSC3787Room"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_succeed_when_joined_to_allowed_room"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsRemoteJoin/Join_should_succeed_when_joined_to_allowed_room"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsRemoteJoinLocalUser"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsRemoteJoinLocalUserInMSC3787Room"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsSpacesSummaryFederation"
}
{
"Action": "fail",
"Test": "TestRestrictedRoomsSpacesSummaryLocal"
}
{
"Action": "fail",
"Test": "TestToDeviceMessagesOverFederation"
}
{
"Action": "fail",
"Test": "TestToDeviceMessagesOverFederation/interrupted_connectivity"
}
{
"Action": "fail",
"Test": "TestUnbanViaInvite"
}
{
"Action": "fail",
"Test": "TestUnknownEndpoints"
}
{
"Action": "fail",
"Test": "TestUnknownEndpoints/Key_endpoints"
}
{
"Action": "fail",
"Test": "TestUnrejectRejectedEvents"
}
-360
View File
@@ -1,360 +0,0 @@
{
"Action": "pass",
"Test": "TestACLs"
}
{
"Action": "pass",
"Test": "TestCannotSendNonJoinViaSendJoinV1/event_with_mismatched_state_key"
}
{
"Action": "pass",
"Test": "TestCannotSendNonJoinViaSendJoinV1/invite_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonJoinViaSendJoinV1/knock_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonJoinViaSendJoinV1/non-state_membership_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonJoinViaSendJoinV2/event_with_mismatched_state_key"
}
{
"Action": "pass",
"Test": "TestCannotSendNonJoinViaSendJoinV2/invite_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonJoinViaSendJoinV2/knock_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonJoinViaSendJoinV2/non-state_membership_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV1"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV1/event_with_mismatched_state_key"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV1/invite_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV1/join_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV1/knock_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV1/non-state_membership_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV1/regular_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV2"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV2/event_with_mismatched_state_key"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV2/invite_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV2/join_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV2/knock_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV2/non-state_membership_event"
}
{
"Action": "pass",
"Test": "TestCannotSendNonLeaveViaSendLeaveV2/regular_event"
}
{
"Action": "pass",
"Test": "TestFederatedClientSpaces"
}
{
"Action": "pass",
"Test": "TestFederationRedactSendsWithoutEvent"
}
{
"Action": "pass",
"Test": "TestFederationRoomsInvite/Parallel/Invited_user_can_reject_invite_over_federation_for_empty_room"
}
{
"Action": "pass",
"Test": "TestFederationRoomsInvite/Parallel/Invited_user_has_'is_direct'_flag_in_prev_content_after_joining"
}
{
"Action": "pass",
"Test": "TestFederationRoomsInvite/Parallel/Remote_invited_user_can_see_room_metadata"
}
{
"Action": "pass",
"Test": "TestInboundFederationKeys"
}
{
"Action": "pass",
"Test": "TestInboundFederationProfile"
}
{
"Action": "pass",
"Test": "TestInboundFederationProfile/Inbound_federation_can_query_profile_data"
}
{
"Action": "pass",
"Test": "TestInboundFederationProfile/Non-numeric_ports_in_server_names_are_rejected"
}
{
"Action": "pass",
"Test": "TestIsDirectFlagFederation"
}
{
"Action": "pass",
"Test": "TestIsDirectFlagLocal"
}
{
"Action": "pass",
"Test": "TestJoinFederatedRoomFailOver"
}
{
"Action": "pass",
"Test": "TestJoinFederatedRoomWithUnverifiableEvents"
}
{
"Action": "pass",
"Test": "TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_missing_signatures_shouldn't_block_room_join"
}
{
"Action": "pass",
"Test": "TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_with_bad_signatures_shouldn't_block_room_join"
}
{
"Action": "pass",
"Test": "TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_with_state_with_unverifiable_auth_events_shouldn't_block_room_join"
}
{
"Action": "pass",
"Test": "TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_with_unobtainable_keys_shouldn't_block_room_join"
}
{
"Action": "pass",
"Test": "TestJoinViaRoomIDAndServerName"
}
{
"Action": "pass",
"Test": "TestJumpToDateEndpoint/parallel/should_find_nothing_after_the_latest_timestmap"
}
{
"Action": "pass",
"Test": "TestKnocking/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail"
}
{
"Action": "pass",
"Test": "TestKnocking/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail#01"
}
{
"Action": "pass",
"Test": "TestKnocking/A_user_in_the_room_can_accept_a_knock"
}
{
"Action": "pass",
"Test": "TestKnocking/A_user_in_the_room_can_accept_a_knock#01"
}
{
"Action": "pass",
"Test": "TestKnocking/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'"
}
{
"Action": "pass",
"Test": "TestKnocking/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'#01"
}
{
"Action": "pass",
"Test": "TestKnockingInMSC3787Room/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'"
}
{
"Action": "pass",
"Test": "TestKnockingInMSC3787Room/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'#01"
}
{
"Action": "pass",
"Test": "TestLocalPngThumbnail"
}
{
"Action": "pass",
"Test": "TestMediaFilenames/Parallel/ASCII/Can_download_file_'ascii'"
}
{
"Action": "pass",
"Test": "TestMediaFilenames/Parallel/ASCII/Can_download_specifying_a_different_ASCII_file_name"
}
{
"Action": "pass",
"Test": "TestMediaFilenames/Parallel/ASCII/Can_upload_with_ASCII_file_name"
}
{
"Action": "pass",
"Test": "TestMediaFilenames/Parallel/Unicode/Can_upload_with_Unicode_file_name"
}
{
"Action": "pass",
"Test": "TestMediaWithoutFileName"
}
{
"Action": "pass",
"Test": "TestMediaWithoutFileName/parallel"
}
{
"Action": "pass",
"Test": "TestMediaWithoutFileName/parallel/Can_download_without_a_file_name_locally"
}
{
"Action": "pass",
"Test": "TestMediaWithoutFileName/parallel/Can_download_without_a_file_name_over_federation"
}
{
"Action": "pass",
"Test": "TestMediaWithoutFileName/parallel/Can_upload_without_a_file_name"
}
{
"Action": "pass",
"Test": "TestOutboundFederationProfile"
}
{
"Action": "pass",
"Test": "TestOutboundFederationProfile/Outbound_federation_can_query_profile_data"
}
{
"Action": "pass",
"Test": "TestOutboundFederationSend"
}
{
"Action": "pass",
"Test": "TestRemoteAliasRequestsUnderstandUnicode"
}
{
"Action": "pass",
"Test": "TestRemotePngThumbnail"
}
{
"Action": "pass",
"Test": "TestRemoteTyping"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_fail_initially"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_fail_when_left_allowed_room"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_fail_with_mangled_join_rules"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_succeed_when_invited"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsLocalJoin/Join_should_fail_initially"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsLocalJoin/Join_should_fail_when_left_allowed_room"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsLocalJoin/Join_should_fail_with_mangled_join_rules"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsLocalJoin/Join_should_succeed_when_invited"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_fail_initially"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_fail_when_left_allowed_room"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_fail_with_mangled_join_rules"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_succeed_when_invited"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsRemoteJoin/Join_should_fail_initially"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsRemoteJoin/Join_should_fail_when_left_allowed_room"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsRemoteJoin/Join_should_fail_with_mangled_join_rules"
}
{
"Action": "pass",
"Test": "TestRestrictedRoomsRemoteJoin/Join_should_succeed_when_invited"
}
{
"Action": "pass",
"Test": "TestToDeviceMessagesOverFederation/good_connectivity"
}
{
"Action": "pass",
"Test": "TestToDeviceMessagesOverFederation/stopped_server"
}
{
"Action": "pass",
"Test": "TestUnknownEndpoints/Client-server_endpoints"
}
{
"Action": "pass",
"Test": "TestUnknownEndpoints/Media_endpoints"
}
{
"Action": "pass",
"Test": "TestUnknownEndpoints/Server-server_endpoints"
}
{
"Action": "pass",
"Test": "TestUnknownEndpoints/Unknown_prefix"
}
{
"Action": "pass",
"Test": "TestUserAppearsInChangedDeviceListOnJoinOverFederation"
}
{
"Action": "pass",
"Test": "TestWriteMDirectAccountData"
}
File diff suppressed because it is too large Load Diff
@@ -1,4 +1,5 @@
{"Action":"fail","Test":"TestBannedUserCannotSendJoin"}
{"Action":"pass","Test":"TestACLs"}
{"Action":"pass","Test":"TestBannedUserCannotSendJoin"}
{"Action":"fail","Test":"TestCannotSendKnockViaSendKnockInMSC3787Room"}
{"Action":"fail","Test":"TestCannotSendKnockViaSendKnockInMSC3787Room/event_with_mismatched_state_key"}
{"Action":"fail","Test":"TestCannotSendKnockViaSendKnockInMSC3787Room/invite_event"}
@@ -7,10 +8,18 @@
{"Action":"fail","Test":"TestCannotSendKnockViaSendKnockInMSC3787Room/non-state_membership_event"}
{"Action":"fail","Test":"TestCannotSendKnockViaSendKnockInMSC3787Room/regular_event"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV1"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV1/event_with_mismatched_state_key"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV1/invite_event"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV1/knock_event"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV1/leave_event"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV1/non-state_membership_event"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV1/regular_event"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV2"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV2/event_with_mismatched_state_key"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV2/invite_event"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV2/knock_event"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV2/leave_event"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV2/non-state_membership_event"}
{"Action":"fail","Test":"TestCannotSendNonJoinViaSendJoinV2/regular_event"}
{"Action":"fail","Test":"TestCannotSendNonKnockViaSendKnock"}
{"Action":"fail","Test":"TestCannotSendNonKnockViaSendKnock/event_with_mismatched_state_key"}
@@ -19,50 +28,70 @@
{"Action":"fail","Test":"TestCannotSendNonKnockViaSendKnock/leave_event"}
{"Action":"fail","Test":"TestCannotSendNonKnockViaSendKnock/non-state_membership_event"}
{"Action":"fail","Test":"TestCannotSendNonKnockViaSendKnock/regular_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/event_with_mismatched_state_key"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/invite_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/join_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/knock_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/non-state_membership_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/regular_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/event_with_mismatched_state_key"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/invite_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/join_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/knock_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/non-state_membership_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/regular_event"}
{"Action":"fail","Test":"TestClientSpacesSummary"}
{"Action":"fail","Test":"TestClientSpacesSummaryJoinRules"}
{"Action":"fail","Test":"TestClientSpacesSummary/max_depth"}
{"Action":"fail","Test":"TestClientSpacesSummary/pagination"}
{"Action":"fail","Test":"TestClientSpacesSummary/query_whole_graph"}
{"Action":"fail","Test":"TestClientSpacesSummary/redact_link"}
{"Action":"fail","Test":"TestClientSpacesSummary/suggested_only"}
{"Action":"fail","Test":"TestClientSpacesSummaryJoinRules"}
{"Action":"fail","Test":"TestDeviceListsUpdateOverFederation"}
{"Action":"fail","Test":"TestDeviceListsUpdateOverFederation/good_connectivity"}
{"Action":"fail","Test":"TestDeviceListsUpdateOverFederation/interrupted_connectivity"}
{"Action":"fail","Test":"TestDeviceListsUpdateOverFederationOnRoomJoin"}
{"Action":"fail","Test":"TestDeviceListsUpdateOverFederation/stopped_server"}
{"Action":"fail","Test":"TestDeviceListsUpdateOverFederationOnRoomJoin"}
{"Action":"fail","Test":"TestEventAuth"}
{"Action":"pass","Test":"TestFederatedClientSpaces"}
{"Action":"fail","Test":"TestFederationKeyUploadQuery"}
{"Action":"fail","Test":"TestFederationKeyUploadQuery/Can_claim_remote_one_time_key_using_POST"}
{"Action":"fail","Test":"TestFederationKeyUploadQuery/Can_query_remote_device_keys_using_POST"}
{"Action":"pass","Test":"TestFederationRedactSendsWithoutEvent"}
{"Action":"fail","Test":"TestFederationRejectInvite"}
{"Action":"fail","Test":"TestFederationRoomsInvite"}
{"Action":"fail","Test":"TestFederationRoomsInvite/Parallel"}
{"Action":"fail","Test":"TestFederationRoomsInvite/Parallel/Invited_user_can_reject_invite_over_federation"}
{"Action":"pass","Test":"TestFederationRoomsInvite/Parallel/Invited_user_can_reject_invite_over_federation_for_empty_room"}
{"Action":"fail","Test":"TestFederationRoomsInvite/Parallel/Invited_user_can_reject_invite_over_federation_several_times"}
{"Action":"pass","Test":"TestFederationRoomsInvite/Parallel/Invited_user_has_'is_direct'_flag_in_prev_content_after_joining"}
{"Action":"fail","Test":"TestFederationRoomsInvite/Parallel/Remote_invited_user_can_see_room_metadata"}
{"Action":"fail","Test":"TestGetMissingEventsGapFilling"}
{"Action":"fail","Test":"TestInboundCanReturnMissingEvents"}
{"Action":"fail","Test":"TestInboundCanReturnMissingEvents/Inbound_federation_can_return_missing_events_for_invited_visibility"}
{"Action":"fail","Test":"TestInboundCanReturnMissingEvents/Inbound_federation_can_return_missing_events_for_joined_visibility"}
{"Action":"fail","Test":"TestInboundCanReturnMissingEvents/Inbound_federation_can_return_missing_events_for_shared_visibility"}
{"Action":"fail","Test":"TestInboundCanReturnMissingEvents/Inbound_federation_can_return_missing_events_for_world_readable_visibility"}
{"Action":"pass","Test":"TestInboundFederationKeys"}
{"Action":"pass","Test":"TestInboundFederationProfile"}
{"Action":"pass","Test":"TestInboundFederationProfile/Inbound_federation_can_query_profile_data"}
{"Action":"pass","Test":"TestInboundFederationProfile/Non-numeric_ports_in_server_names_are_rejected"}
{"Action":"fail","Test":"TestInboundFederationRejectsEventsWithRejectedAuthEvents"}
{"Action":"pass","Test":"TestIsDirectFlagFederation"}
{"Action":"pass","Test":"TestIsDirectFlagLocal"}
{"Action":"pass","Test":"TestJoinFederatedRoomFailOver"}
{"Action":"fail","Test":"TestJoinFederatedRoomFromApplicationServiceBridgeUser"}
{"Action":"fail","Test":"TestJoinFederatedRoomFromApplicationServiceBridgeUser/join_remote_federated_room_as_application_service_user"}
{"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents"}
{"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_missing_signatures_shouldn't_block_room_join"}
{"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_with_bad_signatures_shouldn't_block_room_join"}
{"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_with_state_with_unverifiable_auth_events_shouldn't_block_room_join"}
{"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_with_unobtainable_keys_shouldn't_block_room_join"}
{"Action":"pass","Test":"TestJoinViaRoomIDAndServerName"}
{"Action":"fail","Test":"TestJumpToDateEndpoint"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/federation"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/federation/can_paginate_after_getting_remote_event_from_timestamp_to_event_endpoint"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/federation/looking_backwards,_should_be_able_to_find_event_that_was_sent_before_we_joined"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/federation/looking_forwards,_should_be_able_to_find_event_that_was_sent_before_we_joined"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/federation/when_looking_backwards_before_the_room_was_created,_should_be_able_to_find_event_that_was_imported"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_find_event_after_given_timestmap"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_find_event_before_given_timestmap"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_find_next_event_topologically_after_given_timestmap_when_all_message_timestamps_are_the_same"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_find_next_event_topologically_before_given_timestamp_when_all_message_timestamps_are_the_same"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_find_nothing_before_the_earliest_timestmap"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_not_be_able_to_query_a_private_room_you_are_not_a_member_of"}
{"Action":"fail","Test":"TestJumpToDateEndpoint/parallel/should_not_be_able_to_query_a_public_room_you_are_not_a_member_of"}
{"Action":"fail","Test":"TestKnockRoomsInPublicRoomsDirectory"}
{"Action":"fail","Test":"TestKnockRoomsInPublicRoomsDirectoryInMSC3787Room"}
{"Action":"fail","Test":"TestKnocking"}
{"Action":"fail","Test":"TestKnocking/A_user_can_knock_on_a_room_without_a_reason"}
{"Action":"fail","Test":"TestKnocking/A_user_can_knock_on_a_room_without_a_reason#01"}
@@ -70,6 +99,8 @@
{"Action":"fail","Test":"TestKnocking/A_user_cannot_knock_on_a_room_they_are_already_in#01"}
{"Action":"fail","Test":"TestKnocking/A_user_cannot_knock_on_a_room_they_are_already_invited_to"}
{"Action":"fail","Test":"TestKnocking/A_user_cannot_knock_on_a_room_they_are_already_invited_to#01"}
{"Action":"pass","Test":"TestKnocking/A_user_in_the_room_can_accept_a_knock"}
{"Action":"pass","Test":"TestKnocking/A_user_in_the_room_can_accept_a_knock#01"}
{"Action":"fail","Test":"TestKnocking/A_user_in_the_room_can_reject_a_knock"}
{"Action":"fail","Test":"TestKnocking/A_user_in_the_room_can_reject_a_knock#01"}
{"Action":"fail","Test":"TestKnocking/A_user_that_has_already_knocked_is_allowed_to_knock_again_on_the_same_room"}
@@ -77,9 +108,17 @@
{"Action":"fail","Test":"TestKnocking/A_user_that_has_knocked_on_a_local_room_can_rescind_their_knock_and_then_knock_again"}
{"Action":"fail","Test":"TestKnocking/A_user_that_is_banned_from_a_room_cannot_knock_on_it"}
{"Action":"fail","Test":"TestKnocking/A_user_that_is_banned_from_a_room_cannot_knock_on_it#01"}
{"Action":"pass","Test":"TestKnocking/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail"}
{"Action":"pass","Test":"TestKnocking/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail#01"}
{"Action":"pass","Test":"TestKnocking/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'"}
{"Action":"pass","Test":"TestKnocking/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'#01"}
{"Action":"fail","Test":"TestKnocking/Knocking_on_a_room_with_a_join_rule_other_than_'knock'_should_fail"}
{"Action":"fail","Test":"TestKnocking/Knocking_on_a_room_with_a_join_rule_other_than_'knock'_should_fail#01"}
{"Action":"fail","Test":"TestKnocking/Knocking_on_a_room_with_join_rule_'knock'_should_succeed"}
{"Action":"fail","Test":"TestKnocking/Knocking_on_a_room_with_join_rule_'knock'_should_succeed#01"}
{"Action":"fail","Test":"TestKnocking/Users_in_the_room_see_a_user's_membership_update_when_they_knock"}
{"Action":"fail","Test":"TestKnocking/Users_in_the_room_see_a_user's_membership_update_when_they_knock#01"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail#01"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/A_user_can_knock_on_a_room_without_a_reason"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/A_user_can_knock_on_a_room_without_a_reason#01"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/A_user_cannot_knock_on_a_room_they_are_already_in"}
@@ -95,145 +134,91 @@
{"Action":"fail","Test":"TestKnockingInMSC3787Room/A_user_that_has_knocked_on_a_local_room_can_rescind_their_knock_and_then_knock_again"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/A_user_that_is_banned_from_a_room_cannot_knock_on_it"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/A_user_that_is_banned_from_a_room_cannot_knock_on_it#01"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail#01"}
{"Action":"pass","Test":"TestKnockingInMSC3787Room/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'"}
{"Action":"pass","Test":"TestKnockingInMSC3787Room/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'#01"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/Knocking_on_a_room_with_a_join_rule_other_than_'knock'_should_fail"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/Knocking_on_a_room_with_a_join_rule_other_than_'knock'_should_fail#01"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/Knocking_on_a_room_with_join_rule_'knock'_should_succeed"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/Knocking_on_a_room_with_join_rule_'knock'_should_succeed#01"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/Users_in_the_room_see_a_user's_membership_update_when_they_knock"}
{"Action":"fail","Test":"TestKnockingInMSC3787Room/Users_in_the_room_see_a_user's_membership_update_when_they_knock#01"}
{"Action":"fail","Test":"TestKnocking/Knocking_on_a_room_with_a_join_rule_other_than_'knock'_should_fail"}
{"Action":"fail","Test":"TestKnocking/Knocking_on_a_room_with_a_join_rule_other_than_'knock'_should_fail#01"}
{"Action":"fail","Test":"TestKnocking/Knocking_on_a_room_with_join_rule_'knock'_should_succeed"}
{"Action":"fail","Test":"TestKnocking/Knocking_on_a_room_with_join_rule_'knock'_should_succeed#01"}
{"Action":"fail","Test":"TestKnocking/Users_in_the_room_see_a_user's_membership_update_when_they_knock"}
{"Action":"fail","Test":"TestKnocking/Users_in_the_room_see_a_user's_membership_update_when_they_knock#01"}
{"Action":"fail","Test":"TestKnockRoomsInPublicRoomsDirectory"}
{"Action":"fail","Test":"TestKnockRoomsInPublicRoomsDirectoryInMSC3787Room"}
{"Action":"pass","Test":"TestLocalPngThumbnail"}
{"Action":"fail","Test":"TestMediaFilenames"}
{"Action":"fail","Test":"TestMediaFilenames/Parallel"}
{"Action":"fail","Test":"TestMediaFilenames/Parallel/ASCII"}
{"Action":"pass","Test":"TestMediaFilenames/Parallel/ASCII/Can_download_file_'ascii'"}
{"Action":"fail","Test":"TestMediaFilenames/Parallel/ASCII/Can_download_file_'name;with;semicolons'"}
{"Action":"fail","Test":"TestMediaFilenames/Parallel/ASCII/Can_download_file_'name_with_spaces'"}
{"Action":"pass","Test":"TestMediaFilenames/Parallel/ASCII/Can_download_specifying_a_different_ASCII_file_name"}
{"Action":"pass","Test":"TestMediaFilenames/Parallel/ASCII/Can_upload_with_ASCII_file_name"}
{"Action":"fail","Test":"TestMediaFilenames/Parallel/Unicode"}
{"Action":"fail","Test":"TestMediaFilenames/Parallel/Unicode/Can_download_specifying_a_different_Unicode_file_name"}
{"Action":"fail","Test":"TestMediaFilenames/Parallel/Unicode/Can_download_with_Unicode_file_name_locally"}
{"Action":"fail","Test":"TestMediaFilenames/Parallel/Unicode/Can_download_with_Unicode_file_name_over_federation"}
{"Action":"fail","Test":"TestNetworkPartitionOrdering"}
{"Action":"fail","Test":"TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6"}
{"Action":"fail","Test":"TestRemotePresence"}
{"Action":"fail","Test":"TestRemotePresence/Presence_changes_are_also_reported_to_remote_room_members"}
{"Action":"fail","Test":"TestRemotePresence/Presence_changes_to_UNAVAILABLE_are_reported_to_remote_room_members"}
{"Action":"fail","Test":"TestRestrictedRoomsLocalJoin"}
{"Action":"fail","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room"}
{"Action":"fail","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_succeed_when_joined_to_allowed_room"}
{"Action":"fail","Test":"TestRestrictedRoomsLocalJoin/Join_should_succeed_when_joined_to_allowed_room"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoin"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinFailOver"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinFailOverInMSC3787Room"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_succeed_when_joined_to_allowed_room"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoin/Join_should_succeed_when_joined_to_allowed_room"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinLocalUser"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinLocalUserInMSC3787Room"}
{"Action":"fail","Test":"TestRestrictedRoomsSpacesSummaryFederation"}
{"Action":"fail","Test":"TestRestrictedRoomsSpacesSummaryLocal"}
{"Action":"fail","Test":"TestToDeviceMessagesOverFederation"}
{"Action":"fail","Test":"TestToDeviceMessagesOverFederation/interrupted_connectivity"}
{"Action":"fail","Test":"TestUnbanViaInvite"}
{"Action":"fail","Test":"TestUnknownEndpoints"}
{"Action":"fail","Test":"TestUnknownEndpoints/Key_endpoints"}
{"Action":"fail","Test":"TestUnrejectRejectedEvents"}
{"Action":"pass","Test":"TestACLs"}
{"Action":"pass","Test":"TestCannotSendNonJoinViaSendJoinV1/event_with_mismatched_state_key"}
{"Action":"pass","Test":"TestCannotSendNonJoinViaSendJoinV1/invite_event"}
{"Action":"pass","Test":"TestCannotSendNonJoinViaSendJoinV1/knock_event"}
{"Action":"pass","Test":"TestCannotSendNonJoinViaSendJoinV1/non-state_membership_event"}
{"Action":"pass","Test":"TestCannotSendNonJoinViaSendJoinV2/event_with_mismatched_state_key"}
{"Action":"pass","Test":"TestCannotSendNonJoinViaSendJoinV2/invite_event"}
{"Action":"pass","Test":"TestCannotSendNonJoinViaSendJoinV2/knock_event"}
{"Action":"pass","Test":"TestCannotSendNonJoinViaSendJoinV2/non-state_membership_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/event_with_mismatched_state_key"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/invite_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/join_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/knock_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/non-state_membership_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV1/regular_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/event_with_mismatched_state_key"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/invite_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/join_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/knock_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/non-state_membership_event"}
{"Action":"pass","Test":"TestCannotSendNonLeaveViaSendLeaveV2/regular_event"}
{"Action":"pass","Test":"TestFederatedClientSpaces"}
{"Action":"pass","Test":"TestFederationRedactSendsWithoutEvent"}
{"Action":"pass","Test":"TestFederationRoomsInvite/Parallel/Invited_user_can_reject_invite_over_federation_for_empty_room"}
{"Action":"pass","Test":"TestFederationRoomsInvite/Parallel/Invited_user_has_'is_direct'_flag_in_prev_content_after_joining"}
{"Action":"pass","Test":"TestFederationRoomsInvite/Parallel/Remote_invited_user_can_see_room_metadata"}
{"Action":"pass","Test":"TestInboundFederationKeys"}
{"Action":"pass","Test":"TestInboundFederationProfile"}
{"Action":"pass","Test":"TestInboundFederationProfile/Inbound_federation_can_query_profile_data"}
{"Action":"pass","Test":"TestInboundFederationProfile/Non-numeric_ports_in_server_names_are_rejected"}
{"Action":"pass","Test":"TestIsDirectFlagFederation"}
{"Action":"pass","Test":"TestIsDirectFlagLocal"}
{"Action":"pass","Test":"TestJoinFederatedRoomFailOver"}
{"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents"}
{"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_missing_signatures_shouldn't_block_room_join"}
{"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_with_bad_signatures_shouldn't_block_room_join"}
{"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_with_state_with_unverifiable_auth_events_shouldn't_block_room_join"}
{"Action":"pass","Test":"TestJoinFederatedRoomWithUnverifiableEvents//send_join_response_with_unobtainable_keys_shouldn't_block_room_join"}
{"Action":"pass","Test":"TestJoinViaRoomIDAndServerName"}
{"Action":"pass","Test":"TestJumpToDateEndpoint/parallel/should_find_nothing_after_the_latest_timestmap"}
{"Action":"pass","Test":"TestKnocking/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail"}
{"Action":"pass","Test":"TestKnocking/Attempting_to_join_a_room_with_join_rule_'knock'_without_an_invite_should_fail#01"}
{"Action":"pass","Test":"TestKnocking/A_user_in_the_room_can_accept_a_knock"}
{"Action":"pass","Test":"TestKnocking/A_user_in_the_room_can_accept_a_knock#01"}
{"Action":"pass","Test":"TestKnocking/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'"}
{"Action":"pass","Test":"TestKnocking/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'#01"}
{"Action":"pass","Test":"TestKnockingInMSC3787Room/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'"}
{"Action":"pass","Test":"TestKnockingInMSC3787Room/Change_the_join_rule_of_a_room_from_'invite'_to_'knock'#01"}
{"Action":"pass","Test":"TestLocalPngThumbnail"}
{"Action":"pass","Test":"TestMediaFilenames/Parallel/ASCII/Can_download_file_'ascii'"}
{"Action":"pass","Test":"TestMediaFilenames/Parallel/ASCII/Can_download_specifying_a_different_ASCII_file_name"}
{"Action":"pass","Test":"TestMediaFilenames/Parallel/ASCII/Can_upload_with_ASCII_file_name"}
{"Action":"pass","Test":"TestMediaFilenames/Parallel/Unicode/Can_upload_with_Unicode_file_name"}
{"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_safe_media_types_as_inline"}
{"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_safe_media_types_with_parameters_as_inline"}
{"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_unsafe_media_types_as_attachments"}
{"Action":"pass","Test":"TestMediaWithoutFileName"}
{"Action":"pass","Test":"TestMediaWithoutFileName/parallel"}
{"Action":"pass","Test":"TestMediaWithoutFileName/parallel/Can_download_without_a_file_name_locally"}
{"Action":"pass","Test":"TestMediaWithoutFileName/parallel/Can_download_without_a_file_name_over_federation"}
{"Action":"pass","Test":"TestMediaWithoutFileName/parallel/Can_upload_without_a_file_name"}
{"Action":"fail","Test":"TestNetworkPartitionOrdering"}
{"Action":"fail","Test":"TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6"}
{"Action":"pass","Test":"TestOutboundFederationProfile"}
{"Action":"pass","Test":"TestOutboundFederationProfile/Outbound_federation_can_query_profile_data"}
{"Action":"pass","Test":"TestOutboundFederationSend"}
{"Action":"pass","Test":"TestRemoteAliasRequestsUnderstandUnicode"}
{"Action":"pass","Test":"TestRemotePngThumbnail"}
{"Action":"fail","Test":"TestRemotePresence"}
{"Action":"fail","Test":"TestRemotePresence/Presence_changes_are_also_reported_to_remote_room_members"}
{"Action":"fail","Test":"TestRemotePresence/Presence_changes_to_UNAVAILABLE_are_reported_to_remote_room_members"}
{"Action":"pass","Test":"TestRemoteTyping"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_fail_initially"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_fail_when_left_allowed_room"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_fail_with_mangled_join_rules"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_succeed_when_invited"}
{"Action":"fail","Test":"TestRestrictedRoomsLocalJoin"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoin/Join_should_fail_initially"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoin/Join_should_fail_when_left_allowed_room"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoin/Join_should_fail_with_mangled_join_rules"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoin/Join_should_succeed_when_invited"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_fail_initially"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_fail_when_left_allowed_room"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_fail_with_mangled_join_rules"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_succeed_when_invited"}
{"Action":"fail","Test":"TestRestrictedRoomsLocalJoin/Join_should_succeed_when_joined_to_allowed_room"}
{"Action":"fail","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_fail_initially"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_fail_when_left_allowed_room"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_fail_with_mangled_join_rules"}
{"Action":"pass","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_succeed_when_invited"}
{"Action":"fail","Test":"TestRestrictedRoomsLocalJoinInMSC3787Room/Join_should_succeed_when_joined_to_allowed_room"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoin"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoin/Join_should_fail_initially"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoin/Join_should_fail_when_left_allowed_room"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoin/Join_should_fail_with_mangled_join_rules"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoin/Join_should_succeed_when_invited"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoin/Join_should_succeed_when_joined_to_allowed_room"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinFailOver"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinFailOverInMSC3787Room"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_fail_initially"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_fail_when_left_allowed_room"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_fail_with_mangled_join_rules"}
{"Action":"pass","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_succeed_when_invited"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinInMSC3787Room/Join_should_succeed_when_joined_to_allowed_room"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinLocalUser"}
{"Action":"fail","Test":"TestRestrictedRoomsRemoteJoinLocalUserInMSC3787Room"}
{"Action":"fail","Test":"TestRestrictedRoomsSpacesSummaryFederation"}
{"Action":"fail","Test":"TestRestrictedRoomsSpacesSummaryLocal"}
{"Action":"skip","Test":"TestSendJoinPartialStateResponse"}
{"Action":"fail","Test":"TestToDeviceMessagesOverFederation"}
{"Action":"pass","Test":"TestToDeviceMessagesOverFederation/good_connectivity"}
{"Action":"pass","Test":"TestToDeviceMessagesOverFederation/stopped_server"}
{"Action":"pass","Test":"TestToDeviceMessagesOverFederation/interrupted_connectivity"}
{"Action":"fail","Test":"TestToDeviceMessagesOverFederation/stopped_server"}
{"Action":"fail","Test":"TestUnbanViaInvite"}
{"Action":"fail","Test":"TestUnknownEndpoints"}
{"Action":"pass","Test":"TestUnknownEndpoints/Client-server_endpoints"}
{"Action":"fail","Test":"TestUnknownEndpoints/Key_endpoints"}
{"Action":"pass","Test":"TestUnknownEndpoints/Media_endpoints"}
{"Action":"pass","Test":"TestUnknownEndpoints/Server-server_endpoints"}
{"Action":"pass","Test":"TestUnknownEndpoints/Unknown_prefix"}
{"Action":"fail","Test":"TestUnrejectRejectedEvents"}
{"Action":"pass","Test":"TestUserAppearsInChangedDeviceListOnJoinOverFederation"}
{"Action":"pass","Test":"TestWriteMDirectAccountData"}
{"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_safe_media_types_as_inline"}
{"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_safe_media_types_with_parameters_as_inline"}
{"Action":"skip","Test":"TestMediaFilenames/Parallel/Unicode/Will_serve_unsafe_media_types_as_attachments"}
{"Action":"skip","Test":"TestSendJoinPartialStateResponse"}