Compare commits

..
Author SHA1 Message Date
timedout 716161f2b1 fix: Resolve cherry-pick conflicts 2026-10-16 19:41:36 +01:00
timedout 13e01a6dc9 feat: Always run mutex assertion outside maxperf
Also makes it not a panic
2026-10-16 19:26:30 +01:00
timedout 3ebd068013 perf: Don't hold state lock when unnecessary 2026-10-16 19:26:27 +01:00
146 changed files with 1245 additions and 1846 deletions

No files matched your search

@@ -44,7 +44,7 @@ runs:
- name: Login to builtin registry - name: Login to builtin registry
if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }} if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }}
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4 uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
with: with:
registry: ${{ env.BUILTIN_REGISTRY }} registry: ${{ env.BUILTIN_REGISTRY }}
username: ${{ inputs.registry_user }} username: ${{ inputs.registry_user }}
@@ -79,7 +79,7 @@ runs:
- name: Login to builtin registry - name: Login to builtin registry
if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }} if: ${{ env.BUILTIN_REGISTRY_ENABLED == 'true' }}
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4 uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
with: with:
registry: ${{ env.BUILTIN_REGISTRY }} registry: ${{ env.BUILTIN_REGISTRY }}
username: ${{ inputs.registry_user }} username: ${{ inputs.registry_user }}
+1 -1
View File
@@ -7,7 +7,7 @@ runs:
using: composite using: composite
steps: steps:
- name: Install sccache - name: Install sccache
uses: https://forgejo.ellis.link/continuwuation/sccache-action@v1 uses: https://git.tomfos.tr/tom/sccache-action@v1
- name: Configure sccache - name: Configure sccache
uses: https://github.com/actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 uses: https://github.com/actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with: with:
@@ -29,7 +29,7 @@ runs:
steps: steps:
- name: Detect runner OS - name: Detect runner OS
id: runner-os id: runner-os
uses: https://forgejo.ellis.link/continuwuation/detect-versions@v1 uses: https://git.tomfos.tr/actions/detect-versions@v1
- name: Configure cross-compilation architecture - name: Configure cross-compilation architecture
if: inputs.dpkg-arch != '' if: inputs.dpkg-arch != ''
+2 -2
View File
@@ -39,7 +39,7 @@ runs:
steps: steps:
- name: Detect runner OS - name: Detect runner OS
id: runner-os id: runner-os
uses: https://forgejo.ellis.link/continuwuation/detect-versions@v1 uses: https://git.tomfos.tr/actions/detect-versions@v1
- name: Configure Cargo environment - name: Configure Cargo environment
shell: bash shell: bash
@@ -147,7 +147,7 @@ runs:
run: echo "::group::📦 Restoring build cache" run: echo "::group::📦 Restoring build cache"
- name: Setup sccache - name: Setup sccache
uses: https://forgejo.ellis.link/continuwuation/sccache-action@v1 uses: https://git.tomfos.tr/tom/sccache-action@v1
- name: End build cache restore group - name: End build cache restore group
shell: bash shell: bash
+1 -1
View File
@@ -71,7 +71,7 @@ runs:
- name: Install timelord-cli and git-warp-time - name: Install timelord-cli and git-warp-time
if: steps.check-binaries.outputs.need-install == 'true' if: steps.check-binaries.outputs.need-install == 'true'
uses: https://github.com/taiki-e/install-action@682ce6c3c696a4cd5168a05f98e51aa02b877941 # v2 uses: https://github.com/taiki-e/install-action@1168f6810a3cb30a3514bf5756a3b7f0422c6df8 # v2
with: with:
tool: git-warp-time,timelord-cli@3.0.1 tool: git-warp-time,timelord-cli@3.0.1
+1 -1
View File
@@ -60,7 +60,7 @@ jobs:
cargo-debian-${{ steps.debian-version.outputs.distribution }}-${{ matrix.arch }}- cargo-debian-${{ steps.debian-version.outputs.distribution }}-${{ matrix.arch }}-
- name: Setup sccache - name: Setup sccache
uses: https://forgejo.ellis.link/continuwuation/sccache-action@v1 uses: https://git.tomfos.tr/tom/sccache-action@v1
- name: Configure sccache environment - name: Configure sccache environment
run: | run: |
+2 -2
View File
@@ -28,13 +28,13 @@ jobs:
- name: Detect runner environment - name: Detect runner environment
id: runner-env id: runner-env
uses: https://forgejo.ellis.link/continuwuation/detect-versions@v1 uses: https://git.tomfos.tr/actions/detect-versions@v1
- name: Setup Node.js - name: Setup Node.js
if: steps.runner-env.outputs.node_major == '' || steps.runner-env.outputs.node_major < '20' if: steps.runner-env.outputs.node_major == '' || steps.runner-env.outputs.node_major < '20'
uses: https://github.com/actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7 uses: https://github.com/actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with: with:
node-version: 26 node-version: 24
- name: Cache npm dependencies - name: Cache npm dependencies
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
+1 -1
View File
@@ -43,7 +43,7 @@ jobs:
name: Renovate name: Renovate
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: ghcr.io/renovatebot/renovate:44.210.1@sha256:45cc73346c44a9afe037f2d19766f2b545b59b2ed31b937b5b09017d2958e45f image: ghcr.io/renovatebot/renovate:44.151.2@sha256:29b3bf193f855c6f4b7027395a9c66c3417ad8bb6f30458090e1c2363d04eef7
options: --tmpfs /tmp:exec options: --tmpfs /tmp:exec
steps: steps:
- name: Checkout - name: Checkout
+1 -2
View File
@@ -7,7 +7,6 @@ f419c64aca300a338096b4e0db4c73ace54f23d0
5998a0d883d31b866f7c8c46433a8857eae51a89 5998a0d883d31b866f7c8c46433a8857eae51a89
# trailing whitespace and newlines # trailing whitespace and newlines
46c193e74b2ce86c48ce802333a0aabce37fd6e9 46c193e74b2ce86c48ce802333a0aabce37fd6e9
# rustfmt updates that rewrapped tons of comments # rustfmt update that rewrapped tons of comments
9fbabe221051e6956a05d8824142092ede68971e 9fbabe221051e6956a05d8824142092ede68971e
b0c0905472b882ff0cc79232e73d307fd0b5035b b0c0905472b882ff0cc79232e73d307fd0b5035b
9c27441acf2e65f85c106ccff5c6b6c37030ddca
-1
View File
@@ -1,4 +1,3 @@
open_collective: continuwuity
github: [JadedBlueEyes, timedoutuk, gingershaped] github: [JadedBlueEyes, timedoutuk, gingershaped]
custom: custom:
- https://timedout.uk/donate.html - https://timedout.uk/donate.html
Generated
+209 -190
View File
File diff suppressed because it is too large. Load diff
+6 -7
View File
@@ -104,7 +104,6 @@ version = "0.8.8"
default-features = false default-features = false
features = [ features = [
"form", "form",
"query",
"http1", "http1",
"http2", "http2",
"json", "json",
@@ -331,7 +330,7 @@ version = "2.1.1"
# used for MPSC channels # used for MPSC channels
[workspace.dependencies.loole] [workspace.dependencies.loole]
version = "0.6.0" version = "0.4.0"
# used for MPMC channels # used for MPMC channels
[workspace.dependencies.async-channel] [workspace.dependencies.async-channel]
@@ -349,7 +348,7 @@ version = "1.1.1"
# Used for matrix spec type definitions and helpers # Used for matrix spec type definitions and helpers
[workspace.dependencies.ruma] [workspace.dependencies.ruma]
git = "https://github.com/ruma/ruma.git" git = "https://github.com/ruma/ruma.git"
rev = "0ed7fba34213f18a628a56f527c6cc795cd7eef5" rev = "62659d64f712adf3cad126df6b8969f785414bd5"
features = [ features = [
"appservice-api-c", "appservice-api-c",
"client-api", "client-api",
@@ -454,7 +453,7 @@ features = ["http", "grpc-tonic", "trace", "logs", "metrics"]
# optional sentry metrics for crash/panic reporting # optional sentry metrics for crash/panic reporting
[workspace.dependencies.sentry] [workspace.dependencies.sentry]
version = "0.49.0" version = "0.48.0"
default-features = false default-features = false
features = [ features = [
"backtrace", "backtrace",
@@ -469,9 +468,9 @@ features = [
] ]
[workspace.dependencies.sentry-tracing] [workspace.dependencies.sentry-tracing]
version = "0.49.0" version = "0.48.0"
[workspace.dependencies.sentry-tower] [workspace.dependencies.sentry-tower]
version = "0.49.0" version = "0.48.0"
# jemalloc usage # jemalloc usage
[workspace.dependencies.tikv-jemalloc-sys] [workspace.dependencies.tikv-jemalloc-sys]
@@ -545,7 +544,7 @@ features = ["hardware-lock-elision", "deadlock_detection"] # TODO: Check if dead
# Use this when extending with_lock::WithLock to parking_lot # Use this when extending with_lock::WithLock to parking_lot
[workspace.dependencies.lock_api] [workspace.dependencies.lock_api]
version = "0.5.0" version = "0.4.13"
[workspace.dependencies.bytesize] [workspace.dependencies.bytesize]
version = "2.0" version = "2.0"
-1
View File
@@ -1 +0,0 @@
The first-run version of the web UI now includes a link to the registration page. Contributed by @ginger
-1
View File
@@ -1 +0,0 @@
Continuwuity now supports the OAuth 2.0 client credentials grant type, allowing secure automated access to the Matrix homeserver admin API, as well as future administrative functionality. Contributed by @ginger.
-1
View File
@@ -1 +0,0 @@
Room summary visibility checks are no longer incorrectly applied for remote rooms. Contributed by @ginger.
@@ -1 +0,0 @@
Fix new devices sometimes never reaching other users' device lists. Contributed by @eleboucher.
@@ -1 +0,0 @@
Fix gap filling skipping outlier events that are missing their previous events. Contributed by @eleboucher.
@@ -1 +0,0 @@
Fix state resolution applying events out of order, which could undo room joins. Contributed by @eleboucher.
@@ -1 +0,0 @@
Fix to-device messages, including room keys, sometimes being lost before delivery. Contributed by @eleboucher.
-1
View File
@@ -1 +0,0 @@
Add a section on [troubleshooting Docker issues](https://continuwuity.org/troubleshooting#docker-issues). Contributed by @stratself.
-1
View File
@@ -1 +0,0 @@
Instructions for Authelia added to the [OIDC guide](https://continuwuity.org/authentication/oidc.html). Contributed by @fhoekstra
-1
View File
@@ -1 +0,0 @@
Fix some possible deadlocks/freezes and reduce lock contention (improving performance). Contributed by @Jade
-1
View File
@@ -1 +0,0 @@
Docker compose examples now use bind mounts by default, instead of Docker volumes, as they are easier to work with esp. for backup/restore. Contributed by @stratself.
-1
View File
@@ -1 +0,0 @@
Once again fixed how room extremities are handled, fixing a problem that made continuwuity gradually make rooms needlessly complex, which also caused more frequent state resets.
-1
View File
@@ -1 +0,0 @@
The OAuth identity reset page is no longer linked from the account management UI to reduce confusion. Contributed by @ginger.
-1
View File
@@ -1 +0,0 @@
Fixed a worker panic when knocking on a room over federation. Contributed by @eleboucher.
-1
View File
@@ -1 +0,0 @@
Perform more validation on events received during atomic gapfill from remote servers, fixing a panic if bad data was persisted by another server and later lazily fetched by us.
-1
View File
@@ -1 +0,0 @@
Redirect URIs in OAuth clients' metadata are now properly validated to be on a subdomain of the OAuth issuer URL domain. Contributed by @ginger.
-1
View File
@@ -1 +0,0 @@
Updated internal Sentry integration setup to the new pattern required by the SDK.
-1
View File
@@ -1 +0,0 @@
Fix v12 rooms created by the same user in the same millisecond ending up as the same room. Contributed by @eleboucher.
-1
View File
@@ -1 +0,0 @@
Setting a profile key longer than 255 bytes now returns 400 `M_KEY_TOO_LARGE` as required by the spec, instead of 413 `M_TOO_LARGE`.
-1
View File
@@ -1 +0,0 @@
Setting profile data that would make the profile exceed 64 KiB now returns 400 `M_PROFILE_TOO_LARGE` as required by the spec, instead of a 500 error.
-1
View File
@@ -1 +0,0 @@
Appservices masquerading as a device that does not exist now receive 400 `M_UNKNOWN_DEVICE` as required by the spec, instead of 403 `M_FORBIDDEN`.
-1
View File
@@ -1 +0,0 @@
Setting `m.fully_read` via the account data endpoints now returns 405 `M_BAD_JSON` as required by the spec, instead of 400.
-1
View File
@@ -1 +0,0 @@
The `m.forget_forced_upon_leave` capability now reflects the `forget_forced_upon_leave` config option instead of always being advertised as enabled.
-1
View File
@@ -1 +0,0 @@
Fixed push notifications for membership events setting `user_is_target` based on the sender rather than the user being notified.
-42
View File
@@ -2680,45 +2680,3 @@
# #
# env: CONTINUWUITY_OAUTH__OIDC__PROFILE_KEY_IMPORT_MODE # env: CONTINUWUITY_OAUTH__OIDC__PROFILE_KEY_IMPORT_MODE
#profile_key_import_mode = "on_registration" #profile_key_import_mode = "on_registration"
#[global.oauth.clients."$id"]
# Use this section to add static OAuth clients for bots and automation.
# Clients added here may use the client credentials OAuth grant to authorize
# themselves with Continuwuity.
#
# Make sure to replace `$id` in the header with your client ID of choice! You can
# add more copies of this section with different IDs to add multiple clients.
#
# Because the client credentials grant authorizes the client as itself, without
# an attached user, clients that use it will not be able to access most of the Matrix
# client-server API. Administrative functionality that does not require a user
# will still be available.
# The client's client secret.
#
# This must be supplied as the `client_secret` parameter when requesting
# an access token with the OAuth 2.0 token endpoint. Continuwuity does
# not check the `Authorization` header for requests to this endpoint.
#
#client_secret =
# A list of scopes that the client may request. Continuwuity allows static
# clients to request the following scopes:
#
# - "urn:matrix:client:cc.c10y.msc4484.server_administration" (MSC4484):
# This scope grants access to the Matrix server administration APIs, as
# well as Continuwuity's internal admin API (currently a work in
# progress).
# - "urn:matrix:client:api:*": This scope grants access to the Matrix
# client-server API. Most endpoints require an authenticated Matrix user
# and thus will not be usable by static clients.
#
# The `urn:matrix:client:device:<id>` scope may not be requested by static
# clients.
#
# Scopes listed here are not granted by default. The client must
# explicitly include them in the `scope` parameter of its access token
# request.
#
#scopes = []
+1 -1
View File
@@ -50,7 +50,7 @@ EOF
# Developer tool versions # Developer tool versions
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall # renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
ENV BINSTALL_VERSION=1.26.1 ENV BINSTALL_VERSION=1.25.3
# renovate: datasource=github-releases depName=psastras/sbom-rs # renovate: datasource=github-releases depName=psastras/sbom-rs
ENV CARGO_SBOM_VERSION=0.9.1 ENV CARGO_SBOM_VERSION=0.9.1
# renovate: datasource=crate depName=lddtree # renovate: datasource=crate depName=lddtree
+1 -1
View File
@@ -18,7 +18,7 @@ RUN --mount=type=cache,target=/etc/apk/cache apk add \
# Developer tool versions # Developer tool versions
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall # renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
ENV BINSTALL_VERSION=1.26.1 ENV BINSTALL_VERSION=1.25.3
# renovate: datasource=github-releases depName=psastras/sbom-rs # renovate: datasource=github-releases depName=psastras/sbom-rs
ENV CARGO_SBOM_VERSION=0.9.1 ENV CARGO_SBOM_VERSION=0.9.1
# renovate: datasource=crate depName=lddtree # renovate: datasource=crate depName=lddtree
+18 -74
View File
@@ -1,5 +1,3 @@
import { Tab, Tabs } from '@rspress/core/theme';
# Delegated authentication with OIDC # Delegated authentication with OIDC
Continuwuity supports delegating user authentication to an external identity provider that implements the OpenID Connect (OIDC) specification, such as Authentik, Kanidm, or Keycloak. Continuwuity supports delegating user authentication to an external identity provider that implements the OpenID Connect (OIDC) specification, such as Authentik, Kanidm, or Keycloak.
@@ -14,110 +12,56 @@ An account on the homeserver can only be associated with one OIDC subject claim
A simple OIDC configuration is as easy as creating a new OIDC application in your identity provider's settings and supplying Continuwuity with the client ID and client secret. A simple OIDC configuration is as easy as creating a new OIDC application in your identity provider's settings and supplying Continuwuity with the client ID and client secret.
The instructions below make the following assumptions:
- Continuwuity's base URL: `https://matrix.example.com`. Note that if you employ [well-known delegation](../guides/delegation), this must match the client well-known domain rather than your server name.
- OIDC provider's base URL: `https://idm.example.com`
### Configuring the OIDC provider ### Configuring the OIDC provider
This guide will cover [**Kanidm**][kanidm] and [**Authelia**][authelia], but the basic concepts apply to most identity providers. Contributions for them are welcome. This guide will use [**Kanidm**][kanidm] as an example, but the described steps are broadly applicable to other identity providers. Contributions for them are welcome.
<Tabs groupId="idp"> First, create a new application for Continuwuity in your identity provider.
<Tab label="KanIDM">
Create a new application for continuwuity in kanidm. We will use `c10y` as the client ID.
```sh ```sh
kanidm system oauth2 create c10y Continuwuity https://matrix.example.com # Here, `c10y` is the client ID that Kanidm will use, and `Continuwuity` is the display name.
# Other identity providers may generate a client ID for you.
# Use the domain that clients can reach Continuwuity at, which may not be the same as your server name
# if you have configured well-known delegation.
kanidm system oauth2 create c10y Continuwuity https://matrix.yourdomain.com
``` ```
Configure the redirect URL that Continuwuity uses. Configure the redirect URL that Continuwuity uses.
```sh ```sh
kanidm system oauth2 add-redirect-url c10y https://matrix.example.com/_continuwuity/oidc/complete kanidm system oauth2 add-redirect-url c10y https://matrix.yourdomain.com/_continuwuity/oidc/complete
``` ```
Allow Continuwuity to request the `openid` scope. Allow Continuwuity to request the `openid` scope. Other identity providers may not require this step.
```sh ```sh
kanidm system oauth2 update-scope-map c10y idm_all_persons openid kanidm system oauth2 update-scope-map c10y idm_all_persons openid
``` ```
Find the client secret that was generated. Find the client secret that was generated. Other identity providers may show this information in their web UI.
```sh ```sh
kanidm system oauth2 show-basic-secret c10y kanidm system oauth2 show-basic-secret c10y
d1qgx352kkuvs1j70b6w293d65x68jve1f7b27fyk90gjhpr d1qgx352kkuvs1j70b6w293d65x68jve1f7b27fyk90gjhpr
``` ```
Now the discovery URL for KanIDM is: `https://idm.example.com/oauth2/openid/c10y`
</Tab>
<Tab label="Authelia">
To create a new client in Authelia, it is [recommended][authelia-faq-client-secret] to randomly generate both the client id and client secret. The commands below should get you those:
<Tabs groupId="authelia-generate-client-details">
<Tab label="Bare Binary">
```sh
# Generate random value for Client ID
authelia crypto rand --length 72 --charset rfc3986
# Generate Client Secret (labeled Random Password) and its Digest
authelia crypto hash generate pbkdf2 --variant sha512 --random --random.length 72 --random.charset rfc3986
```
</Tab>
<Tab label="Docker">
```sh
# Generate random value for Client ID
docker run --rm authelia/authelia:latest authelia crypto rand --length 72 --charset rfc3986
# Generate Client Secret (labeled Random Password) and its Digest
docker run --rm authelia/authelia:latest authelia crypto hash generate pbkdf2 --variant sha512 --random --random.length 72 --random.charset rfc3986
```
</Tab>
</Tabs>
Authelia only needs to know the digest of the secret, whereas Continuwuity requires the secret itself.
Go to your Authelia configuration file, find the `identity_provers` block, and add a block for Continuwuity to the `clients` list:
```yaml
identity_providers:
oidc:
jwks:
# This part has the JWKs and is what you configured previously
# ...
clients:
# Add this block below to the clients list
- client_name: continuwuity
client_id: "client-id-goes-here"
# Use the client secret's DIGEST, not the client secret itself
client_secret: "client-secret-DIGEST-goes-here"
redirect_uris: ["https://matrix.example.com/_continuwuity/oidc/complete"]
scopes: [openid]
```
Then restart Authelia to load the new configuration.
The discovery URL is simply the root domain of your Authelia, where it can be reached by clients, i.e. `https://idm.example.com`.
</Tab>
</Tabs>
[kanidm]: https://kanidm.com [kanidm]: https://kanidm.com
[authelia]: https://www.authelia.com
[authelia-faq-client-secret]: https://www.authelia.com/integration/openid-connect/frequently-asked-questions/#how-do-i-generate-a-client-identifier-or-client-secret
### Configuring Continuwuity ### Configuring Continuwuity
Configure Continuwuity with the client ID, client secret, and discovery URL provided from the steps above. Configure Continuwuity with the client ID, client secret, and discovery URL provided from the steps above. Kanidm has a different discovery URL for each client, but other identity providers may have a single discovery URL at the root of their domain.
```toml ```toml
[global.oauth.oidc] [global.oauth.oidc]
# `/.well-known/openid-configuration` will be appended automatically # `/.well-known/openid-configuration` will be appended automatically
discovery_url = "https://your-discovery-url" discovery_url = "https://idm.example.com/oauth2/openid/c10y"
client_id = "your-client-id" # This may be randomly generated by your identity provider. Kanidm requires
client_secret = "your-client-secret" # you to set it manually when you create the application.
client_id = "c10y"
# From the previous step
client_secret = "d1qgx352kkuvs1j70b6w293d65x68jve1f7b27fyk90gjhpr"
``` ```
### Testing that it works ### Testing that it works
+21 -2
View File
@@ -303,14 +303,33 @@ For browser-based clients, you can also inspect connections using DevTools' Netw
### Docker loopback networking issues ### Docker loopback networking issues
Some distros do not allow Docker containers to connect to the host's public IP, and this breaks connections from `lk-jwt-service` towards `livekit` and `continuwuity` if they're on the same host. This can be tested by the following command: Some distros do not allow Docker containers in bridge networks to connect to their host's public IP by default. This makes `lk-jwt-service` fail connecting to `livekit` or `continuwuity` on the same host, causing refused and timed out connections to appear in the log entries of the JWT service, even when `LIVEKIT_URL` has been configured correctly.
You can also test that this is the case by cURLing from a sidecar container:
```bash ```bash
docker run --rm --net container:lk-jwt-service docker.io/curlimages/curl https://livekit.example.com docker run --rm --net container:lk-jwt-service docker.io/curlimages/curl https://livekit.example.com
# --- some errors --- # --- some errors ---
``` ```
To resolve this, follow the steps in [Docker loopback networking issues](../troubleshooting.mdx#docker-loopback-networking-issues) of the Troubleshooting page. To resolve this, configure an `extra_hosts` file mapping LiveKit's and Continuwuity's domain names to Docker's custom host loopback address, represented here by `host-gateway`:
```diff
# in docker-compose.yaml
services:
lk-jwt-service:
...
+ extra_hosts:
+ - "livekit.example.com:host-gateway"
+ - "matrix.example.com:host-gateway"
```
After implementing the changes and restarting your compose, `lk-jwt-service` should now connect to your other services. The sidecar container test above should now return an `OK` from LiveKit.
For more information about the `host-gateway` parameter, kindly refer to the `--add-host` documentation for [Docker][docker-add-host] and [Podman][podman-add-host]. Should you have further difficulties, feel free to enquire in the support rooms.
[docker-add-host]: https://docs.docker.com/reference/cli/docker/container/run/#add-host
[podman-add-host]: https://docs.podman.io/en/latest/markdown/podman-run.1.html#add-host-hostname-hostname-ip
### Incorrect IP address for LiveKit ### Incorrect IP address for LiveKit
+17 -58
View File
@@ -53,7 +53,7 @@ For more setups with `.well-known` delegation and split-domain deployments, cons
Docker Compose is the recommended deployment method for Continuwuity containers. The following environment variables will be set: Docker Compose is the recommended deployment method for Continuwuity containers. The following environment variables will be set:
- `CONTINUWUITY_SERVER_NAME` - Your Matrix server's domain name. **This CANNOT be changed later without a data wipe.** - `CONTINUWUITY_SERVER_NAME` - Your Matrix server's domain name. **This CANNOT be changed later without a data wipe.**
- `CONTINUWUITY_DATABASE_PATH` - Where to store your database. This must match the docker bind mount. - `CONTINUWUITY_DATABASE_PATH` - Where to store your database. This must match the docker volume mount.
- `CONTINUWUITY_ADDRESS` - Bind address (for Docker, use `0.0.0.0` to listen on all interfaces). - `CONTINUWUITY_ADDRESS` - Bind address (for Docker, use `0.0.0.0` to listen on all interfaces).
Alternatively, you can specify a path to mount the configuration file using the `CONTINUWUITY_CONFIG` environment variable. Alternatively, you can specify a path to mount the configuration file using the `CONTINUWUITY_CONFIG` environment variable.
@@ -89,9 +89,7 @@ Consult the [**DNS tuning guide (recommended)**](../guides/dns.mdx) for full sol
<summary>docker-compose.with-caddy.yml ([view raw](/deploying/docker-compose.with-caddy.yml))</summary> <summary>docker-compose.with-caddy.yml ([view raw](/deploying/docker-compose.with-caddy.yml))</summary>
Create a directory called `caddy-data`, which will store TLS certs obtained by Caddy. Create a Caddyfile with the following content:
Then, create a Caddyfile with the following content:
``` ```
https://example.com:443, https://example.com:8448 { https://example.com:443, https://example.com:8448 {
@@ -99,7 +97,7 @@ https://example.com:443, https://example.com:8448 {
} }
``` ```
Then, for the docker compose file: Then, for the docker-compose:
```yaml file="../public/deploying/docker-compose.with-caddy.yml" ```yaml file="../public/deploying/docker-compose.with-caddy.yml"
@@ -112,10 +110,6 @@ Then, for the docker compose file:
<details> <details>
<summary>docker-compose.with-caddy-labels.yml ([view raw](/deploying/docker-compose.with-caddy-labels.yml))</summary> <summary>docker-compose.with-caddy-labels.yml ([view raw](/deploying/docker-compose.with-caddy-labels.yml))</summary>
Create a directory called `caddy-data`, which will store TLS certs obtained by Caddy.
Then, for the docker compose file:
```yaml file="../public/deploying/docker-compose.with-caddy-labels.yml" ```yaml file="../public/deploying/docker-compose.with-caddy-labels.yml"
``` ```
@@ -138,10 +132,6 @@ Then, for the docker compose file:
<details> <details>
<summary>docker-compose.with-traefik.yml ([view raw](/deploying/docker-compose.with-traefik.yml))</summary> <summary>docker-compose.with-traefik.yml ([view raw](/deploying/docker-compose.with-traefik.yml))</summary>
Create a directory called `traefik-acme-data`, which will store TLS certs obtained by Caddy.
Then, for the docker compose file:
```yaml file="../public/deploying/docker-compose.with-traefik.yml" ```yaml file="../public/deploying/docker-compose.with-traefik.yml"
``` ```
@@ -174,15 +164,10 @@ See the [Other reverse proxies](generic.mdx#setting-up-the-reverse-proxy) sectio
### Starting Your Server ### Starting Your Server
1. Create a directory named `continuwuity-data`. This will be where your server's database lives. 1. Choose your compose file from the above, and rename it to `docker-compose.yml`. Replace `example.com` with your homeserver's domain name, and edit other values as you see fit.
2. If using the override file, rename it to `docker-compose.override.yml` and
2. Choose your compose file from the above, and rename it to `docker-compose.yml`. Replace `example.com` with your homeserver's domain name, and edit other values as you see fit. edit your values.
3. Start the server:
- Follow all extra instructions as needed.
- If using the override file, rename it to `docker-compose.override.yml` and edit your values.
3. Start the server with the following command:
```bash ```bash
docker compose up -d docker compose up -d
@@ -204,7 +189,9 @@ See the [Other reverse proxies](generic.mdx#setting-up-the-reverse-proxy) sectio
Pick your own username and password! Pick your own username and password!
``` ```
5. Log in to your server with any Matrix client, and register for an account with the registration token from the previous step. You'll automatically be invited to the admin room where you can [manage your server](../reference/admin). 5. Log in to your server with any Matrix client, and register for an account with the registration token from step 4. You'll automatically be invited to the admin room where you can [manage your server](../reference/admin).
See the [generic deployment guide](generic.mdx) for more deployment options.
## Testing ## Testing
@@ -212,9 +199,7 @@ Test that your setup works by following these [instructions](./generic.mdx#how-d
Check your container logs using `docker-compose logs --follow` to debug any issues. See the [Troubleshooting](../troubleshooting.mdx) page for common errors and how to fix them. Check your container logs using `docker-compose logs --follow` to debug any issues. See the [Troubleshooting](../troubleshooting.mdx) page for common errors and how to fix them.
## Maintenance ## Updating
### Updating
To update to a new version of Continuwuity, use the following commands: To update to a new version of Continuwuity, use the following commands:
@@ -227,10 +212,6 @@ docker compose pull
docker compose up -d docker compose up -d
``` ```
### Backups
The database in `./continuwuity-data` is present on the host system as a regular directory, and therefore can be backed up using normal mechanisms. See the [Backup](../maintenance.mdx#backups) section of the Maintenance page for more details.
## What's next? ## What's next?
Navigate to [Post-installation](../deploying.mdx#post-installation) for next steps. Navigate to [Post-installation](../deploying.mdx#post-installation) for next steps.
@@ -289,6 +270,12 @@ Get a working Continuwuity server with an admin user in four steps:
Once configured, log in to your server with any Matrix client, and register for an account with the registration token from step 3. If you did not configure step 4., log in via the `http://<your_server_ip>:8008` address. You will be automatically invited to the admin room where you can [manage your server](../reference/admin). Once configured, log in to your server with any Matrix client, and register for an account with the registration token from step 3. If you did not configure step 4., log in via the `http://<your_server_ip>:8008` address. You will be automatically invited to the admin room where you can [manage your server](../reference/admin).
### (Optional) Building Custom Images
For information on building your own Continuwuity Docker images, see the
[Building Docker Images](../development/index.mdx#building-docker-images)
section in the development documentation.
### Accessing the Server's Console ### Accessing the Server's Console
Before you can access the server's console and [send admin commands](../reference/admin/index.md) from the CLI, you will need to make the container interactive and allocate a pseudo-tty. Make sure you set `admin_console_automatic` to `true` in [the config](../reference/config.mdx) as well for Continuwuity to activate the CLI on startup. Before you can access the server's console and [send admin commands](../reference/admin/index.md) from the CLI, you will need to make the container interactive and allocate a pseudo-tty. Make sure you set `admin_console_automatic` to `true` in [the config](../reference/config.mdx) as well for Continuwuity to activate the CLI on startup.
@@ -310,31 +297,3 @@ From there you can access the server's console by running `docker attach <contai
Note that using `CTRL+c` within `docker attach`'s context will forward the signal to the server, stopping it. See [Docker's reference][docker-attach-reference] for more information. Note that using `CTRL+c` within `docker attach`'s context will forward the signal to the server, stopping it. See [Docker's reference][docker-attach-reference] for more information.
[docker-attach-reference]: https://docs.docker.com/reference/cli/docker/container/attach/ [docker-attach-reference]: https://docs.docker.com/reference/cli/docker/container/attach/
### Using Docker volumes
The example compose files above utilizes [bind mounts][docker-bind-mounts]. If you want to use [Docker volumes][docker-volumes] instead, apply these changes to your compose file:
```diff
services:
continuwuity:
# ...
volumes:
- - ./continuwuity-data:/var/lib/continuwuity
+ - continuwuity-data:/var/lib/continuwuity
+volumes:
+ continuwuity-data:
```
Consult the [Docker docs][docker-volumes-backup-restore] for details on backing up and restoring Docker volumes
[docker-bind-mounts]: https://docs.docker.com/engine/storage/bind-mounts/
[docker-volumes]: https://docs.docker.com/engine/storage/volumes/
[docker-volumes-backup-restore]: https://docs.docker.com/engine/storage/volumes/#back-up-restore-or-migrate-data-volumes
### Building Custom Images
For information on building your own Continuwuity Docker images, see the
[Building Docker Images](../development/index.mdx#building-docker-images)
section in the development documentation.
-5
View File
@@ -199,11 +199,6 @@ header, making federation non-functional. If you find a workaround, please share
Furthermore, Nginx users need to increase the `client_max_body_size` setting (default is 1M) to match the `max_request_size` defined in conduwuit.toml. Furthermore, Nginx users need to increase the `client_max_body_size` setting (default is 1M) to match the `max_request_size` defined in conduwuit.toml.
- For HAProxy, ensure that the ACL for the `Host` header matches both the domain and the domain with the port, as federation requests are often sent with the port included. This can be done by using the `host_only` directive:
```
acl matrix-host hdr(host),host_only -i example.com
```
## Starting Your Server ## Starting Your Server
Now you can start Continuwuity with: Now you can start Continuwuity with:
+2 -2
View File
@@ -113,7 +113,7 @@ https://matrix.example.com {
### Tuning your trusted servers ### Tuning your trusted servers
:::important Important: Vet your trusted servers! :::info Vet your trusted servers!
Trusted servers are your first point of contact when obtaining public keys from other servers, and they could theoretically impersonate other servers and cause significant harm to your deployment. Please thoroughly verify your trusted servers' credibility before adding them to your configuration. Trusted servers are your first point of contact when obtaining public keys from other servers, and they could theoretically impersonate other servers and cause significant harm to your deployment. Please thoroughly verify your trusted servers' credibility before adding them to your configuration.
If you need suggestions for trusted servers, ask in the Continuwuity main room. If you need suggestions for trusted servers, ask in the Continuwuity main room.
@@ -128,7 +128,7 @@ trusted_servers = ["codestorm.net","starstruck.systems","unredacted.org","matrix
Avoid prioritising `matrix.org` as your primary trusted server, as it tends to be quite slow. Avoid prioritising `matrix.org` as your primary trusted server, as it tends to be quite slow.
Some users have also reported that increasing `trusted_server_batch_size` helps with faster joins for huge rooms. Start with doubling the default to `2048` until you find a suitable value. Some users have also reported that increasing `trusted_server_batch_size` has helped with faster joins for huge rooms. Start with doubling the default to `2048` until you find a suitable value.
### Enable HTTP/3 on your reverse proxy ### Enable HTTP/3 on your reverse proxy
@@ -6,7 +6,7 @@ services:
restart: unless-stopped restart: unless-stopped
command: /sbin/conduwuit command: /sbin/conduwuit
volumes: volumes:
- ./continuwuity-data:/var/lib/continuwuity - db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's - ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
#- ./continuwuity.toml:/etc/continuwuity.toml #- ./continuwuity.toml:/etc/continuwuity.toml
networks: networks:
@@ -12,7 +12,7 @@ services:
- proxy - proxy
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
- ./caddy-data:/data - ./data:/data
restart: unless-stopped restart: unless-stopped
labels: labels:
caddy: example.com caddy: example.com
@@ -23,7 +23,7 @@ services:
restart: unless-stopped restart: unless-stopped
command: /sbin/conduwuit command: /sbin/conduwuit
volumes: volumes:
- ./continuwuity-data:/var/lib/continuwuity - db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's - ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
# - ./continuwuity.toml:/etc/continuwuity.toml # - ./continuwuity.toml:/etc/continuwuity.toml
environment: environment:
@@ -46,5 +46,8 @@ services:
caddy: matrix.example.com caddy: matrix.example.com
caddy.reverse_proxy: "{{upstreams 8008}}" caddy.reverse_proxy: "{{upstreams 8008}}"
volumes:
db:
networks: networks:
proxy: proxy:
@@ -9,7 +9,7 @@ services:
networks: networks:
- caddy - caddy
volumes: volumes:
- ./caddy-data:/data - ./data:/data
# mount your created Caddyfile into the container # mount your created Caddyfile into the container
- ./Caddyfile:/etc/caddy/Caddyfile - ./Caddyfile:/etc/caddy/Caddyfile
restart: unless-stopped restart: unless-stopped
@@ -19,7 +19,7 @@ services:
restart: unless-stopped restart: unless-stopped
command: /sbin/conduwuit command: /sbin/conduwuit
volumes: volumes:
- ./continuwuity-data:/var/lib/continuwuity - db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's - ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
# - ./continuwuity.toml:/etc/continuwuity.toml # - ./continuwuity.toml:/etc/continuwuity.toml
environment: environment:
@@ -41,3 +41,6 @@ services:
networks: networks:
proxy: proxy:
volumes:
db:
@@ -6,7 +6,7 @@ services:
restart: unless-stopped restart: unless-stopped
command: /sbin/conduwuit command: /sbin/conduwuit
volumes: volumes:
- ./continuwuity-data:/var/lib/continuwuity - db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's - ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
#- ./continuwuity.toml:/etc/continuwuity.toml #- ./continuwuity.toml:/etc/continuwuity.toml
networks: networks:
@@ -40,7 +40,7 @@ services:
- "443:443" - "443:443"
volumes: volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro" - "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik-acme-data:/etc/traefik/acme" - "acme:/etc/traefik/acme"
labels: labels:
- "traefik.enable=true" - "traefik.enable=true"
@@ -77,5 +77,9 @@ services:
TRAEFIK_PROVIDERS_DOCKER_ENDPOINT: "unix:///var/run/docker.sock" TRAEFIK_PROVIDERS_DOCKER_ENDPOINT: "unix:///var/run/docker.sock"
TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT: false TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT: false
volumes:
db:
acme:
networks: networks:
proxy: proxy:
@@ -6,7 +6,7 @@ services:
restart: unless-stopped restart: unless-stopped
command: /sbin/conduwuit command: /sbin/conduwuit
volumes: volumes:
- ./continuwuity-data:/var/lib/continuwuity - db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's - ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
#- ./continuwuity.toml:/etc/continuwuity.toml #- ./continuwuity.toml:/etc/continuwuity.toml
networks: networks:
@@ -18,7 +18,7 @@ services:
- "traefik.http.routers.continuwuity.tls=true" - "traefik.http.routers.continuwuity.tls=true"
- "traefik.http.routers.continuwuity.service=continuwuity" - "traefik.http.routers.continuwuity.service=continuwuity"
- "traefik.http.services.continuwuity.loadbalancer.server.port=8008" - "traefik.http.services.continuwuity.loadbalancer.server.port=8008"
# enable tls with the `letsencrypt` certificate resolver (actual name dependant on your static config) # possibly, depending on your config:
# - "traefik.http.routers.continuwuity.tls.certresolver=letsencrypt" # - "traefik.http.routers.continuwuity.tls.certresolver=letsencrypt"
environment: environment:
CONTINUWUITY_SERVER_NAME: example.com CONTINUWUITY_SERVER_NAME: example.com
@@ -34,6 +34,9 @@ services:
server=example.com:443 server=example.com:443
} }
volumes:
db:
networks: networks:
# This must match the network name that Traefik listens on # This must match the network name that Traefik listens on
proxy: proxy:
@@ -12,7 +12,7 @@ services:
- proxy - proxy
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
- ./caddy-data:/data - ./data:/data
restart: unless-stopped restart: unless-stopped
homeserver: homeserver:
@@ -20,7 +20,7 @@ services:
restart: unless-stopped restart: unless-stopped
command: /sbin/conduwuit command: /sbin/conduwuit
volumes: volumes:
- ./continuwuity-data:/var/lib/continuwuity - db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's - ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
# - ./continuwuity.toml:/etc/continuwuity.toml # - ./continuwuity.toml:/etc/continuwuity.toml
environment: environment:
@@ -10,7 +10,7 @@ services:
networks: networks:
- proxy - proxy
volumes: volumes:
- ./caddy-data:/data - ./data:/data
# mount your created Caddyfile into the container # mount your created Caddyfile into the container
- ./Caddyfile:/etc/caddy/Caddyfile - ./Caddyfile:/etc/caddy/Caddyfile
restart: unless-stopped restart: unless-stopped
@@ -20,7 +20,7 @@ services:
restart: unless-stopped restart: unless-stopped
command: /sbin/conduwuit command: /sbin/conduwuit
volumes: volumes:
- ./continuwuity-data:/var/lib/continuwuity - db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's - ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
# - ./continuwuity.toml:/etc/continuwuity.toml # - ./continuwuity.toml:/etc/continuwuity.toml
environment: environment:
@@ -43,3 +43,6 @@ services:
networks: networks:
proxy: proxy:
volumes:
db:
@@ -6,7 +6,7 @@ services:
restart: unless-stopped restart: unless-stopped
command: /sbin/conduwuit command: /sbin/conduwuit
volumes: volumes:
- ./continuwuity-data:/var/lib/continuwuity - db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's - ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
#- ./continuwuity.toml:/etc/continuwuity.toml #- ./continuwuity.toml:/etc/continuwuity.toml
networks: networks:
@@ -40,7 +40,7 @@ services:
- "443:443" - "443:443"
volumes: volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro" - "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik-acme-data:/etc/traefik/acme" - "acme:/etc/traefik/acme"
labels: labels:
- "traefik.enable=true" - "traefik.enable=true"
@@ -77,5 +77,9 @@ services:
TRAEFIK_PROVIDERS_DOCKER_ENDPOINT: "unix:///var/run/docker.sock" TRAEFIK_PROVIDERS_DOCKER_ENDPOINT: "unix:///var/run/docker.sock"
TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT: false TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT: false
volumes:
db:
acme:
networks: networks:
proxy: proxy:
+33 -30
View File
@@ -1,38 +1,41 @@
# Continuwuity - Bare Configuration (for other reverse proxies) # Continuwuity - Bare Configuration (for other reverse proxies)
services: services:
homeserver: homeserver:
image: "forgejo.ellis.link/continuwuation/continuwuity:latest" image: "forgejo.ellis.link/continuwuation/continuwuity:latest"
restart: unless-stopped restart: unless-stopped
command: /sbin/conduwuit command: /sbin/conduwuit
ports: ports:
# If your reverse proxy is on the host, use this # If your reverse proxy is on the host, use this
# and configure it to connect to `127.0.0.1:8008` # and configure it to connect to `127.0.0.1:8008`
- 127.0.0.1:8008:8008 - 127.0.0.1:8008:8008
# If your reverse proxy is on another machine, use this # If your reverse proxy is on another machine, use this
# and configure it to connect to <this-machine-ip>:8008 # and configure it to connect to <this-machine-ip>:8008
# - 8008:8008 # - 8008:8008
# If your reverse proxy is a docker container on the same network, # If your reverse proxy is a docker container on the same network,
# comment out the entire `ports` section, and configure it to connect to `continuwuity:8008` # comment out the entire `ports` section, and configure it to connect to `continuwuity:8008`
volumes: volumes:
- ./continuwuity-data:/var/lib/continuwuity - db:/var/lib/continuwuity
- ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's - ./continuwuity-resolv.conf:/etc/resolv.conf # use custom resolvers rather than Docker's
#- ./continuwuity.toml:/etc/continuwuity.toml #- ./continuwuity.toml:/etc/continuwuity.toml
environment: environment:
CONTINUWUITY_SERVER_NAME: example.com # EDIT THIS CONTINUWUITY_SERVER_NAME: example.com # EDIT THIS
CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity CONTINUWUITY_DATABASE_PATH: /var/lib/continuwuity
CONTINUWUITY_ADDRESS: 0.0.0.0 CONTINUWUITY_ADDRESS: 0.0.0.0
CONTINUWUITY_PORT: 8008 CONTINUWUITY_PORT: 8008
#CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above #CONTINUWUITY_CONFIG: '/etc/continuwuity.toml' # Uncomment if you mapped config toml above
## (Optional) Serve .well-known files to tell others to reach Continuwuity on port :443 ## (Optional) Serve .well-known files to tell others to reach Continuwuity on port :443
## If you do this, remove all routes to port :8448 on your reverse proxy ## If you do this, remove all routes to port :8448 on your reverse proxy
# CONTINUWUITY_WELL_KNOWN: | # CONTINUWUITY_WELL_KNOWN: |
# { # {
# client=https://example.com, # client=https://example.com,
# server=example.com:443 # server=example.com:443
# } # }
volumes:
db:
+17 -87
View File
@@ -1,9 +1,9 @@
# Troubleshooting Continuwuity # Troubleshooting Continuwuity
:::warning{title="For Docker users"} :::warning{title="Docker users:"}
It's common for Docker misconfigurations to cause issues, particularly with networking and Docker can be difficult to use and debug. It's common for Docker
permissions. Before continuing, please first check that your issues are notdue Docker misconfigurations to cause issues, particularly with networking and permissions.
problems. See the dedicated [**Docker issues**](#docker-issues) section for more details. Please check that your issues are not due to problems with your Docker setup.
::: :::
## Continuwuity issues ## Continuwuity issues
@@ -13,9 +13,9 @@ problems. See the dedicated [**Docker issues**](#docker-issues) section for more
Some slowness is to be expected if you're the first person on your homeserver to join a room (which will Some slowness is to be expected if you're the first person on your homeserver to join a room (which will
always be the case for single-user homeservers). In this situation, your homeserver has to verify the signatures of always be the case for single-user homeservers). In this situation, your homeserver has to verify the signatures of
all of the state events sent by other servers before your join. To make this process as fast as possible, make sure you have all of the state events sent by other servers before your join. To make this process as fast as possible, make sure you have
multiple fast, trusted servers listed in `trusted_servers` in your configuration, and ensure [multiple fast, trusted servers](./guides/performance.mdx#tuning-your-trusted-servers) listed in `trusted_servers` in your configuration, and ensure
`query_trusted_key_servers_first_on_join` is set to true (the default). Read the `query_trusted_key_servers_first_on_join` is set to true (the default).
[Tuning your trusted servers](./guides/performance.mdx#tuning-your-trusted-servers) section for more details on doing so. If you need suggestions for trusted servers, ask in the Continuwuity main room.
However, _very_ slow joins, especially to rooms with only a few users in them or rooms created by another user However, _very_ slow joins, especially to rooms with only a few users in them or rooms created by another user
on your homeserver, may be caused by [issue !779](https://forgejo.ellis.link/continuwuation/continuwuity/issues/779), on your homeserver, may be caused by [issue !779](https://forgejo.ellis.link/continuwuation/continuwuity/issues/779),
@@ -119,63 +119,11 @@ much possible corruption is restored
- If all goes will, you should be able to restore back to using - If all goes will, you should be able to restore back to using
`TolerateCorruptedTailRecords` and you have successfully recovered your database `TolerateCorruptedTailRecords` and you have successfully recovered your database
## Docker issues
### Debugging Docker networking
The Continuwuity image does not ship with any shell or internal debugging utilities. To debug network conditions for Continuwuity, run another sidecar container that is attached to its network namespace. For example, using the `curl` container:
```bash
docker run --rm -it \
--network container:continuwuity \
docker.io/curlimages/curl \
curl https://continuwuity.org/.well-known/matrix/server
```
### Docker loopback networking issues
Some distros disallow Docker containers in bridge networks to reach out to their host's public IP by default. This can cause connectivity issues between Continuwuity and other services that are on the same host machine, such as LiveKit or a push server.
One can test if this is the case by cURLing those services with a sidecar container:
```bash
docker run --rm -it --network container:continuwuity docker.io/curlimages/curl curl https://push.example.com
# --- some timeout or refused connection errors ---
```
To fix this, use the `extra_hosts` parameter to map local service domains to `host-gateway` - a special Docker value that resolves to the internal IP address of the host.
```diff title="docker-compose.yaml"
services:
continuwuity:
...
# allow Continuwuity to reach out to the push server and livekit
# via the host gateway loopback address
+ extra_hosts:
+ - "push.example.com:host-gateway"
+ - "livekit.example.com:host-gateway"
lk-jwt-service:
...
# allow jwt service to reach out to Continuwuity and livekit
# via the host gateway loopback address
+ extra_hosts:
+ - "livekit.example.com:host-gateway"
+ - "matrix.example.com:host-gateway"
```
Reload the compose file, and connections between these services (as well as the sidecar container test above) should now work.
For more information about the `host-gateway` parameter, kindly consult the Docker docs on [custom DNS with `extra_hosts`][docker-custom-dns] and the [`--add-host` option][docker-add-host].
[docker-custom-dns]: https://docs.docker.com/compose/how-tos/networking/#custom-dns-with-extra_hosts
[docker-add-host]: https://docs.docker.com/reference/cli/docker/container/run/#add-host
## Debugging ## Debugging
Note that users should not really need to debug things. If you find yourself Note that users should not really need to debug things. If you find yourself
debugging and find the issue, please let us know and/or how we can fix it. debugging and find the issue, please let us know and/or how we can fix it.
Various debug commands can be found in [`!admin debug`](./reference/admin/debug). Various debug commands can be [found in `!admin debug`](./reference/admin/debug).
### Debug/Trace log level ### Debug/Trace log level
@@ -188,34 +136,23 @@ you need to access debug/trace log levels, you will need to build without the
Continuwuity supports changing the tracing log environment filter on-the-fly using Continuwuity supports changing the tracing log environment filter on-the-fly using
the admin command `!admin debug change-log-level <log env filter>`. This accepts the admin command `!admin debug change-log-level <log env filter>`. This accepts
a string **without quotes** in the same format as the `log` config option. Complex a string **without quotes** the same format as the `log` config option.
filters are also supported as well.
```bash Example: `!admin debug change-log-level debug`
# set log level to debug
!admin debug change-log-level debug
# trace logs for all outgoing federation to `example.com` This can also accept complex filters such as:
!admin debug change-log-level info,conduwuit_service::federation[{dest="example.com"}]=trace `!admin debug change-log-level info,conduit_service[{dest="example.com"}]=trace,ruma_state_res=trace`
`!admin debug change-log-level info,conduit_service[{dest="example.com"}]=trace,conduit_service[send{dest="example.org"}]=trace`
# trace logs for client syncs And to reset the log level to the one that was set at startup / last config
!admin debug change-log-level info,conduwuit_api::client=trace load, simply pass the `--reset` flag.
# debug logs for everything except h2 and presence `!admin debug change-log-level --reset`
!admin debug change-log-level trace,h2=off,conduwuit_service::presence=off
```
To reset the log level to the one that was set at last config
load, simply do:
```bash
!admin debug change-log-level --reset
```
### Pinging servers ### Pinging servers
Continuwuity can ping other servers using `!admin debug ping <server>`. This takes Continuwuity can ping other servers using `!admin debug ping <server>`. This takes
a server name, goes through the server discovery process, and queries a server name and goes through the server discovery process and queries
`/_matrix/federation/v1/version`. Errors are outputted. `/_matrix/federation/v1/version`. Errors are outputted.
While it does measure the latency of the request, it is not indicative of While it does measure the latency of the request, it is not indicative of
@@ -261,10 +198,3 @@ and is not easy for non-developers to understand.
[unbound-tuning]: https://unbound.docs.nlnetlabs.nl/en/latest/topics/core/performance.html [unbound-tuning]: https://unbound.docs.nlnetlabs.nl/en/latest/topics/core/performance.html
[unbound-arch]: https://wiki.archlinux.org/title/Unbound [unbound-arch]: https://wiki.archlinux.org/title/Unbound
## Other troubleshooting topics
- [LiveKit troubleshooting](./calls/livekit.mdx#troubleshooting)
- [TURN server troubleshooting](./calls/turn.mdx#troubleshooting)
- [Delegation/split-domain troubleshooting](./guides/delegation.mdx#troubleshooting)
- [Push notifications troubleshooting](./guides/push.mdx#troubleshooting)
+8 -6
View File
@@ -1,4 +1,4 @@
use conduwuit::{Err, Result, checked, utils::ReadyExt}; use conduwuit::{Err, Result, checked};
use futures::{FutureExt, StreamExt, TryFutureExt}; use futures::{FutureExt, StreamExt, TryFutureExt};
impl crate::Context<'_> { impl crate::Context<'_> {
@@ -49,6 +49,7 @@ impl crate::Context<'_> {
.services .services
.appservice .appservice
.get_registration(&appservice_identifier) .get_registration(&appservice_identifier)
.await
{ {
| None => return Err!("Appservice does not exist."), | None => return Err!("Appservice does not exist."),
| Some(config) => { | Some(config) => {
@@ -77,11 +78,12 @@ impl crate::Context<'_> {
self.services self.services
.users .users
.stream_local_users() .stream_local_users()
.ready_filter_map(|user_id| { .filter_map(async |user_id| {
self.services if self.services.appservice.is_user_id(&user_id).await {
.appservice Some(user_id)
.is_user_id(&user_id) } else {
.then_some(user_id) None
}
}) })
.for_each(async |user_id| { .for_each(async |user_id| {
self.services self.services
+3 -44
View File
@@ -14,7 +14,7 @@ use conduwuit::{
state_res::EventTypeExt, state_res::EventTypeExt,
trace, utils, trace, utils,
utils::{ utils::{
stream::{BroadbandExt, IterStream, ReadyExt}, stream::{IterStream, ReadyExt},
string::EMPTY, string::EMPTY,
to_canonical_object, to_canonical_object,
}, },
@@ -849,6 +849,7 @@ impl crate::Context<'_> {
get_room_state::v1::Request::new(at_event_id, room_id.clone()), get_room_state::v1::Request::new(at_event_id, room_id.clone()),
) )
.await?; .await?;
let _state_lock = self.services.rooms.state.mutex.lock(&*room_id).await;
for pdu in remote_state_response.pdus.clone() { for pdu in remote_state_response.pdus.clone() {
match self match self
@@ -944,13 +945,11 @@ impl crate::Context<'_> {
.save_state(room_id.clone().as_ref(), new_room_state) .save_state(room_id.clone().as_ref(), new_room_state)
.await?; .await?;
let state_lock = self.services.rooms.state.mutex.lock(&*room_id).await;
info!("Forcing new room state"); info!("Forcing new room state");
self.services self.services
.rooms .rooms
.state .state
.force_state(room_id.clone().as_ref(), short_state_hash, added, removed, &state_lock) .force_state(room_id.clone().as_ref(), short_state_hash, added, removed)
.await?; .await?;
info!("Updating joined counts for room"); info!("Updating joined counts for room");
@@ -1207,46 +1206,6 @@ impl crate::Context<'_> {
.await .await
} }
pub(super) async fn room_extremities(&self, room_id: OwnedRoomId) -> Result {
let mut extremities = self
.services
.rooms
.state
.get_forward_extremities(&room_id)
.broad_filter_map(|event_id| async move {
self.services.rooms.timeline.get_pdu(&event_id).await.ok()
})
.collect::<Vec<_>>()
.await;
extremities.sort_by_key(|pdu| (pdu.depth, pdu.origin_server_ts));
if extremities.is_empty() {
return Err!("No room extremities.");
}
self.write_str("| Event ID | Kind | Sender | Timestamp | Depth |\n")
.await?;
self.write_str("| -------- | ---- | ------ | --------- | ----- |\n")
.await?;
for pdu in extremities {
let url = format!(
"https://matrix.to/#/{}/{}?via={}",
room_id,
pdu.event_id(),
self.services.server.name
);
self.write_str(&format!(
"| [`{}`]({url}) | `{}` | `{}` | `{}` | `{}` |\n",
pdu.event_id(),
pdu.kind(),
pdu.sender(),
pdu.origin_server_ts,
pdu.depth
))
.await?;
}
Ok(())
}
pub(super) async fn servers_in_backoff( pub(super) async fn servers_in_backoff(
&self, &self,
room_id: Option<OwnedRoomId>, room_id: Option<OwnedRoomId>,
-4
View File
@@ -234,10 +234,6 @@ pub enum DebugCommand {
page: Option<usize>, page: Option<usize>,
}, },
RoomExtremities {
room_id: OwnedRoomId,
},
/// Lists remote servers that are currently in a "backoff" state. /// Lists remote servers that are currently in a "backoff" state.
/// ///
/// Servers in this list will not be contacted until the retry time elapses, /// Servers in this list will not be contacted until the retry time elapses,
+8 -4
View File
@@ -39,13 +39,17 @@ conduwuit::mod_dtor! {}
pub use crate::admin::AdminCommand; pub use crate::admin::AdminCommand;
/// Install the admin command processor /// Install the admin command processor
pub fn init(admin_service: &service::admin::Service) { pub async fn init(admin_service: &service::admin::Service) {
_ = admin_service.complete.write().insert(processor::complete); _ = admin_service.complete.write().insert(processor::complete);
_ = admin_service.handle.write().insert(processor::dispatch); _ = admin_service
.handle
.write()
.await
.insert(processor::dispatch);
} }
/// Uninstall the admin command handler /// Uninstall the admin command handler
pub fn fini(admin_service: &service::admin::Service) { pub async fn fini(admin_service: &service::admin::Service) {
_ = admin_service.handle.write().take(); _ = admin_service.handle.write().await.take();
_ = admin_service.complete.write().take(); _ = admin_service.complete.write().take();
} }
+1 -1
View File
@@ -24,7 +24,7 @@ pub(super) async fn process(subcommand: AppserviceCommand, context: &Context<'_>
match subcommand { match subcommand {
| AppserviceCommand::GetRegistration { appservice_id } => { | AppserviceCommand::GetRegistration { appservice_id } => {
let timer = tokio::time::Instant::now(); let timer = tokio::time::Instant::now();
let results = services.appservice.get_registration(&appservice_id); let results = services.appservice.get_registration(&appservice_id).await;
let query_time = timer.elapsed(); let query_time = timer.elapsed();
+2 -10
View File
@@ -773,7 +773,7 @@ impl crate::Context<'_> {
), ),
&user_id, &user_id,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
@@ -911,14 +911,6 @@ impl crate::Context<'_> {
); );
let redaction_event_id = { let redaction_event_id = {
let state_lock = self
.services
.rooms
.state
.mutex
.lock(event.room_id_or_hash().as_str())
.await;
self.services self.services
.rooms .rooms
.timeline .timeline
@@ -932,7 +924,7 @@ impl crate::Context<'_> {
}, },
event.sender(), event.sender(),
Some(&event.room_id_or_hash()), Some(&event.room_id_or_hash()),
&state_lock, None,
) )
.await? .await?
}; };
+1 -1
View File
@@ -383,7 +383,7 @@ pub async fn full_user_deactivate(
let _ = services let _ = services
.rooms .rooms
.timeline .timeline
.build_and_append_pdu(pdu, user_id, Some(room_id.as_ref()), &state_lock) .build_and_append_pdu(pdu, user_id, Some(room_id.as_ref()), Some(&state_lock))
.await; .await;
} }
+1
View File
@@ -135,6 +135,7 @@ pub(crate) async fn add_3pid_route(
let email = services let email = services
.threepid .threepid
.get_valid_session(&body.sid, &body.client_secret) .get_valid_session(&body.sid, &body.client_secret)
.await
.map_err(|message| err!(Request(ThreepidAuthFailed("{message}"))))? .map_err(|message| err!(Request(ThreepidAuthFailed("{message}"))))?
.consume(); .consume();
+4 -7
View File
@@ -117,13 +117,10 @@ async fn set_account_data(
data: &RawJsonValue, data: &RawJsonValue,
) -> Result { ) -> Result {
if event_type_s == "m.fully_read" { if event_type_s == "m.fully_read" {
return Err!(Request( return Err!(Request(BadJson(
BadJson( "This endpoint cannot be used for marking a room as fully read (setting \
"This endpoint cannot be used for marking a room as fully read (setting \ m.fully_read)"
m.fully_read)" )));
),
METHOD_NOT_ALLOWED
));
} }
let data: serde_json::Value = serde_json::from_str(data.get()) let data: serde_json::Value = serde_json::from_str(data.get())
+4 -2
View File
@@ -20,7 +20,8 @@ pub(crate) async fn create_alias_route(
services services
.rooms .rooms
.alias .alias
.appservice_checks(&body.room_alias, body.identity.appservice_info())?; .appservice_checks(&body.room_alias, body.identity.appservice_info())
.await?;
// this isn't apart of alias_checks or delete alias route because we should // this isn't apart of alias_checks or delete alias route because we should
// allow removing forbidden room aliases // allow removing forbidden room aliases
@@ -68,7 +69,8 @@ pub(crate) async fn delete_alias_route(
services services
.rooms .rooms
.alias .alias
.appservice_checks(&body.room_alias, body.identity.appservice_info())?; .appservice_checks(&body.room_alias, body.identity.appservice_info())
.await?;
services services
.rooms .rooms
+1 -2
View File
@@ -46,8 +46,7 @@ pub(crate) async fn get_capabilities_route(
capabilities.get_login_token = capabilities.get_login_token =
GetLoginTokenCapability::new(services.server.config.login_via_existing_session); GetLoginTokenCapability::new(services.server.config.login_via_existing_session);
capabilities.forget_forced_upon_leave.enabled = capabilities.forget_forced_upon_leave.enabled = true;
services.server.config.forget_forced_upon_leave;
if services.users.is_admin(sender_user).await { if services.users.is_admin(sender_user).await {
capabilities.account_moderation.lock = true; capabilities.account_moderation.lock = true;
+1 -1
View File
@@ -40,7 +40,7 @@ pub(crate) async fn ban_user_route(
), ),
sender_user, sender_user,
Some(&body.room_id), Some(&body.room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
+2 -2
View File
@@ -177,7 +177,7 @@ async fn send_invite(
PartialPdu::state(recipient_user.to_string(), &content), PartialPdu::state(recipient_user.to_string(), &content),
sender_user, sender_user,
Some(room_id), Some(room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
@@ -276,7 +276,7 @@ async fn send_invite(
PartialPdu::state(recipient_user.to_string(), &content), PartialPdu::state(recipient_user.to_string(), &content),
sender_user, sender_user,
Some(room_id), Some(room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
+1 -1
View File
@@ -48,7 +48,7 @@ pub(crate) async fn kick_user_route(
), ),
sender_user, sender_user,
Some(&body.room_id), Some(&body.room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
+21 -30
View File
@@ -1,4 +1,4 @@
use std::{borrow::Borrow, collections::HashMap, sync::Arc}; use std::{borrow::Borrow, collections::HashMap, iter::once, sync::Arc};
use axum::extract::State; use axum::extract::State;
use conduwuit::{ use conduwuit::{
@@ -266,16 +266,9 @@ async fn knock_room_by_id_helper(
.boxed() .boxed()
.await?; .await?;
} else { } else {
knock_room_helper_remote( knock_room_helper_remote(services, sender_user, room_id, reason, servers)
services, .boxed()
sender_user, .await?;
room_id,
reason,
servers,
new_state_lock,
)
.boxed()
.await?;
} }
return Ok(knock_room::v3::Response::new(room_id.to_owned())); return Ok(knock_room::v3::Response::new(room_id.to_owned()));
@@ -304,7 +297,7 @@ async fn knock_room_by_id_helper(
.boxed() .boxed()
.await?; .await?;
} else { } else {
knock_room_helper_remote(services, sender_user, room_id, reason, servers, state_lock) knock_room_helper_remote(services, sender_user, room_id, reason, servers)
.boxed() .boxed()
.await?; .await?;
} }
@@ -344,7 +337,7 @@ async fn knock_room_helper_local(
PartialPdu::state(sender_user.to_string(), &content), PartialPdu::state(sender_user.to_string(), &content),
sender_user, sender_user,
Some(room_id), Some(room_id),
&state_lock, Some(&state_lock),
) )
.await .await
else { else {
@@ -461,13 +454,13 @@ async fn knock_room_helper_local(
services services
.rooms .rooms
.timeline .timeline
.progress_extremities(&parsed_knock_pdu) .append_pdu(
&parsed_knock_pdu,
knock_event,
once(parsed_knock_pdu.event_id.borrow()),
room_id,
)
.await?; .await?;
services
.rooms
.timeline
.append_pdu(&parsed_knock_pdu, knock_event, room_id)
.await;
Ok(()) Ok(())
} }
@@ -478,7 +471,6 @@ async fn knock_room_helper_remote(
room_id: &RoomId, room_id: &RoomId,
reason: Option<String>, reason: Option<String>,
servers: &[OwnedServerName], servers: &[OwnedServerName],
state_lock: RoomMutexGuard,
) -> Result { ) -> Result {
info!("Knocking {room_id} over federation."); info!("Knocking {room_id} over federation.");
@@ -586,7 +578,7 @@ async fn knock_room_helper_remote(
let mut state_map: HashMap<u64, OwnedEventId> = HashMap::new(); let mut state_map: HashMap<u64, OwnedEventId> = HashMap::new();
for mut event in state { for event in state {
let Some(state_key) = event.get("state_key") else { let Some(state_key) = event.get("state_key") else {
debug_warn!("send_knock stripped state event missing state_key: {event:?}"); debug_warn!("send_knock stripped state event missing state_key: {event:?}");
continue; continue;
@@ -613,7 +605,6 @@ async fn knock_room_helper_remote(
.get_or_create_shortstatekey(&event_type, &state_key) .get_or_create_shortstatekey(&event_type, &state_key)
.await; .await;
event.insert("event_id".into(), CanonicalJsonValue::String(event_id.to_string()));
services.rooms.outlier.add_pdu_outlier(&event_id, &event); services.rooms.outlier.add_pdu_outlier(&event_id, &event);
state_map.insert(shortstatekey, event_id.clone()); state_map.insert(shortstatekey, event_id.clone());
} }
@@ -641,7 +632,7 @@ async fn knock_room_helper_remote(
services services
.rooms .rooms
.state .state
.force_state(room_id, statehash_before_knock, added, removed, &state_lock) .force_state(room_id, statehash_before_knock, added, removed)
.await?; .await?;
let statehash_after_knock = services let statehash_after_knock = services
@@ -662,13 +653,13 @@ async fn knock_room_helper_remote(
services services
.rooms .rooms
.timeline .timeline
.progress_extremities(&parsed_knock_pdu) .append_pdu(
&parsed_knock_pdu,
knock_event,
once(parsed_knock_pdu.event_id.borrow()),
room_id,
)
.await?; .await?;
services
.rooms
.timeline
.append_pdu(&parsed_knock_pdu, knock_event, room_id)
.await;
info!("Setting final room state for new room"); info!("Setting final room state for new room");
// We set the room state after inserting the pdu, so that we never have a // We set the room state after inserting the pdu, so that we never have a
@@ -676,7 +667,7 @@ async fn knock_room_helper_remote(
services services
.rooms .rooms
.state .state
.set_room_state(room_id, statehash_after_knock, &state_lock); .set_room_state(room_id, statehash_after_knock);
Ok(()) Ok(())
} }
+1 -1
View File
@@ -155,7 +155,7 @@ pub async fn leave_room(
PartialPdu::state(user_id.to_string(), &content), PartialPdu::state(user_id.to_string(), &content),
user_id, user_id,
Some(room_id), Some(room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
+1 -1
View File
@@ -47,7 +47,7 @@ pub(crate) async fn unban_user_route(
PartialPdu::state(body.user_id.to_string(), &current_member_content), PartialPdu::state(body.user_id.to_string(), &current_member_content),
sender_user, sender_user,
Some(&body.room_id), Some(&body.room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
+1 -1
View File
@@ -61,7 +61,7 @@ pub(crate) async fn authorization_server_metadata(services: &Services) -> Value
"authorization_endpoint": endpoint_base.join(AUTH_CODE_PATH).unwrap(), "authorization_endpoint": endpoint_base.join(AUTH_CODE_PATH).unwrap(),
"code_challenge_methods_supported": ["S256"], "code_challenge_methods_supported": ["S256"],
"device_authorization_endpoint": endpoint_base.join(DEVICE_AUTHORIZATION_PATH).unwrap(), "device_authorization_endpoint": endpoint_base.join(DEVICE_AUTHORIZATION_PATH).unwrap(),
"grant_types_supported": ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code", "client_credentials"], "grant_types_supported": ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code"],
"issuer": services.config.get_client_domain(), "issuer": services.config.get_client_domain(),
"jwks_uri": endpoint_base.join(JWKS_URI_PATH).unwrap(), "jwks_uri": endpoint_base.join(JWKS_URI_PATH).unwrap(),
"prompt_values_supported": prompt_values_supported, "prompt_values_supported": prompt_values_supported,
+1 -5
View File
@@ -27,8 +27,6 @@ pub(crate) async fn redact_event_route(
return Err!(Request(UserSuspended("You cannot perform this action while suspended."))); return Err!(Request(UserSuspended("You cannot perform this action while suspended.")));
} }
let state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
let event_id = services let event_id = services
.rooms .rooms
.timeline .timeline
@@ -43,11 +41,9 @@ pub(crate) async fn redact_event_route(
}, },
sender_user, sender_user,
Some(&body.room_id), Some(&body.room_id),
&state_lock, None,
) )
.await?; .await?;
drop(state_lock);
Ok(redact_event::v3::Response::new(event_id)) Ok(redact_event::v3::Response::new(event_id))
} }
+19 -31
View File
@@ -1,21 +1,18 @@
use std::{ use std::collections::{BTreeMap, BTreeSet, HashSet};
collections::{BTreeMap, BTreeSet, HashSet},
sync::atomic::{AtomicU64, Ordering::SeqCst},
};
use axum::extract::State; use axum::extract::State;
use conduwuit::{ use conduwuit::{
Err, Error, Result, debug, debug_info, err, info, Err, Error, Result, debug, debug_info, err, info,
matrix::{StateKey, pdu::PartialPdu}, matrix::{StateKey, pdu::PartialPdu},
trace, trace,
utils::{self, to_canonical_object}, utils::to_canonical_object,
warn, warn,
}; };
use conduwuit_service::{Services, appservice::RegistrationInfo}; use conduwuit_service::{Services, appservice::RegistrationInfo};
use futures::FutureExt; use futures::FutureExt;
use ruma::{ use ruma::{
CanonicalJsonObject, CanonicalJsonValue, Int, MilliSecondsSinceUnixEpoch, OwnedRoomAliasId, CanonicalJsonObject, CanonicalJsonValue, Int, MilliSecondsSinceUnixEpoch, OwnedRoomAliasId,
OwnedUserId, RoomAliasId, RoomId, UInt, OwnedUserId, RoomAliasId, RoomId,
api::{ api::{
client::room::{ client::room::{
self, self,
@@ -49,8 +46,6 @@ use serde_json::value::to_raw_value;
use crate::{Ruma, client::invite_helper}; use crate::{Ruma, client::invite_helper};
static LAST_CREATE_TS: AtomicU64 = AtomicU64::new(0);
// We use this to keep around extra data in the `creation_content` // We use this to keep around extra data in the `creation_content`
// while still parsing and validating keys that we care about. // while still parsing and validating keys that we care about.
#[derive(Deserialize, Default)] #[derive(Deserialize, Default)]
@@ -312,17 +307,6 @@ pub(crate) async fn create_room_route(
.map(MilliSecondsSinceUnixEpoch) .map(MilliSecondsSinceUnixEpoch)
}; };
// v12+ room IDs are the create event's hash, so give each create event a
// unique timestamp to avoid collisions.
let create_timestamp = custom_origin_server_ts.or_else(|| {
room_id.is_none().then(|| {
let now = utils::millis_since_unix_epoch();
let next = |last: u64| now.max(last.saturating_add(1));
let prev = LAST_CREATE_TS.update(SeqCst, SeqCst, next);
MilliSecondsSinceUnixEpoch(UInt::new_saturating(next(prev)))
})
});
let mut create_event_content = to_canonical_object(create_event_content) let mut create_event_content = to_canonical_object(create_event_content)
.expect("should be able to serialize create event content"); .expect("should be able to serialize create event content");
@@ -338,12 +322,12 @@ pub(crate) async fn create_room_route(
event_type: TimelineEventType::RoomCreate, event_type: TimelineEventType::RoomCreate,
content: to_raw_value(&create_event_content)?, content: to_raw_value(&create_event_content)?,
state_key: Some(StateKey::new()), state_key: Some(StateKey::new()),
timestamp: create_timestamp, timestamp: custom_origin_server_ts,
..Default::default() ..Default::default()
}, },
sender_user, sender_user,
tmp_id, tmp_id,
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -383,7 +367,7 @@ pub(crate) async fn create_room_route(
PartialPdu::state(sender_user.to_string(), &join_event), PartialPdu::state(sender_user.to_string(), &join_event),
sender_user, sender_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -425,7 +409,7 @@ pub(crate) async fn create_room_route(
}, },
sender_user, sender_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -445,7 +429,7 @@ pub(crate) async fn create_room_route(
), ),
sender_user, sender_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -468,7 +452,7 @@ pub(crate) async fn create_room_route(
), ),
sender_user, sender_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -484,7 +468,7 @@ pub(crate) async fn create_room_route(
), ),
sender_user, sender_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -503,7 +487,7 @@ pub(crate) async fn create_room_route(
), ),
sender_user, sender_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -528,7 +512,7 @@ pub(crate) async fn create_room_route(
services services
.rooms .rooms
.timeline .timeline
.build_and_append_pdu(pdu, sender_user, Some(&room_id), &state_lock) .build_and_append_pdu(pdu, sender_user, Some(&room_id), Some(&state_lock))
.boxed() .boxed()
.await?; .await?;
} }
@@ -583,7 +567,7 @@ pub(crate) async fn create_room_route(
PartialPdu::state(String::new(), &RoomNameEventContent::new(name.clone())), PartialPdu::state(String::new(), &RoomNameEventContent::new(name.clone())),
sender_user, sender_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -597,7 +581,7 @@ pub(crate) async fn create_room_route(
PartialPdu::state(String::new(), &RoomTopicEventContent::new(topic.clone())), PartialPdu::state(String::new(), &RoomTopicEventContent::new(topic.clone())),
sender_user, sender_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -774,7 +758,11 @@ async fn room_alias_check(
if !info.aliases.is_match(full_room_alias.as_str()) { if !info.aliases.is_match(full_room_alias.as_str()) {
return Err!(Request(Exclusive("Room alias is not in namespace."))); return Err!(Request(Exclusive("Room alias is not in namespace.")));
} }
} else if services.appservice.is_exclusive_alias(&full_room_alias) { } else if services
.appservice
.is_exclusive_alias(&full_room_alias)
.await
{
return Err!(Request(Exclusive("Room alias reserved by appservice.",))); return Err!(Request(Exclusive("Room alias reserved by appservice.",)));
} }
+9 -9
View File
@@ -123,7 +123,7 @@ async fn update_parents(
), ),
sender, sender,
Some(&parent_id), Some(&parent_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await .await
@@ -218,7 +218,7 @@ async fn update_children(
), ),
sender, sender,
Some(&child_id), Some(&child_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await .await
@@ -246,7 +246,7 @@ async fn update_children(
), ),
sender, sender,
Some(&child_id), Some(&child_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await .await
@@ -324,7 +324,7 @@ pub(crate) async fn upgrade_room_route(
), ),
sender_user, sender_user,
Some(&body.room_id), Some(&body.room_id),
&old_room_state_lock, Some(&old_room_state_lock),
) )
.await .await
.map_err(|_| { .map_err(|_| {
@@ -407,7 +407,7 @@ pub(crate) async fn upgrade_room_route(
PartialPdu::state(StateKey::new(), &create_event_content), PartialPdu::state(StateKey::new(), &create_event_content),
sender_user, sender_user,
replacement_room_id.as_deref(), replacement_room_id.as_deref(),
&new_room_state_lock, Some(&new_room_state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -453,7 +453,7 @@ pub(crate) async fn upgrade_room_route(
), ),
sender_user, sender_user,
replacement_room_id.as_deref(), replacement_room_id.as_deref(),
&new_room_state_lock, Some(&new_room_state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -527,7 +527,7 @@ pub(crate) async fn upgrade_room_route(
}, },
sender_user, sender_user,
replacement_room_id.as_deref(), replacement_room_id.as_deref(),
&new_room_state_lock, Some(&new_room_state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -572,7 +572,7 @@ pub(crate) async fn upgrade_room_route(
), ),
sender_user, sender_user,
Some(&body.room_id), Some(&body.room_id),
&old_room_state_lock, Some(&old_room_state_lock),
) )
.await?; .await?;
@@ -613,7 +613,7 @@ pub(crate) async fn upgrade_room_route(
), ),
sender_user, sender_user,
Some(&body.room_id), Some(&body.room_id),
&old_room_state_lock, Some(&old_room_state_lock),
) )
.boxed() .boxed()
.await .await
+1 -5
View File
@@ -46,8 +46,6 @@ pub(crate) async fn send_message_event_route(
return Err!(Request(Forbidden("Encryption has been disabled"))); return Err!(Request(Forbidden("Encryption has been disabled")));
} }
let state_lock = services.rooms.state.mutex.lock(body.room_id.as_str()).await;
if body.event_type == MessageLikeEventType::CallInvite if body.event_type == MessageLikeEventType::CallInvite
&& services.rooms.directory.is_public_room(&body.room_id).await && services.rooms.directory.is_public_room(&body.room_id).await
{ {
@@ -114,7 +112,7 @@ pub(crate) async fn send_message_event_route(
}, },
sender_user, sender_user,
Some(&body.room_id), Some(&body.room_id),
&state_lock, None,
) )
.await?; .await?;
@@ -125,8 +123,6 @@ pub(crate) async fn send_message_event_route(
event_id.as_bytes(), event_id.as_bytes(),
); );
drop(state_lock);
Ok(send_message_event::v3::Response::new(event_id)) Ok(send_message_event::v3::Response::new(event_id))
} }
+1 -1
View File
@@ -201,7 +201,7 @@ pub(crate) async fn sync_events_route(
.update_device_last_seen(sender_user, Some(sender_device), client_ip) .update_device_last_seen(sender_user, Some(sender_device), client_ip)
.await; .await;
let mut wake_receiver = services.sync.subscribe_to_wake(sender_user); let mut wake_receiver = services.sync.subscribe_to_wake(sender_user).await;
let response = build_sync_events(&services, &body).await?; let response = build_sync_events(&services, &body).await?;
if body.body.full_state if body.body.full_state
|| !(response.rooms.is_empty() || !(response.rooms.is_empty()
+1 -1
View File
@@ -147,7 +147,7 @@ pub(crate) async fn sync_events_v5_route(
.sync .sync
.update_snake_sync_request_with_cache(&snake_key, globalsince, &mut body); .update_snake_sync_request_with_cache(&snake_key, globalsince, &mut body);
let mut wake_receiver = services.sync.subscribe_to_wake(sender_user); let mut wake_receiver = services.sync.subscribe_to_wake(sender_user).await;
let mut collection = collect_sync_response( let mut collection = collect_sync_response(
services, services,
sender_user, sender_user,
+1 -1
View File
@@ -64,7 +64,7 @@ pub(crate) async fn continuwuity_local_user_count(
.stream_local_users() .stream_local_users()
.filter_map(async |user_id| { .filter_map(async |user_id| {
if !services.users.status(&user_id).await.is_active() if !services.users.status(&user_id).await.is_active()
|| services.appservice.is_exclusive_user_id(&user_id) || services.appservice.is_exclusive_user_id(&user_id).await
{ {
None None
} else { } else {
+7 -28
View File
@@ -41,7 +41,6 @@ pub(crate) enum ClientIdentity {
sender_device: Option<OwnedDeviceId>, sender_device: Option<OwnedDeviceId>,
appservice_info: Box<RegistrationInfo>, appservice_info: Box<RegistrationInfo>,
}, },
StaticClient,
} }
impl ClientIdentity { impl ClientIdentity {
@@ -49,7 +48,6 @@ impl ClientIdentity {
match self { match self {
| Self::User { sender_user, .. } | Self::Appservice { sender_user, .. } => | Self::User { sender_user, .. } | Self::Appservice { sender_user, .. } =>
Some(sender_user), Some(sender_user),
| Self::StaticClient => None,
} }
} }
@@ -57,8 +55,6 @@ impl ClientIdentity {
match self { match self {
| Self::User { sender_user, .. } | Self::Appservice { sender_user, .. } => | Self::User { sender_user, .. } | Self::Appservice { sender_user, .. } =>
Ok(sender_user), Ok(sender_user),
| Self::StaticClient =>
Err!(Request(Forbidden("Static clients cannot use this endpoint."))),
} }
} }
@@ -66,7 +62,6 @@ impl ClientIdentity {
match self { match self {
| Self::User { sender_device, .. } => Some(sender_device), | Self::User { sender_device, .. } => Some(sender_device),
| Self::Appservice { sender_device, .. } => sender_device.as_deref(), | Self::Appservice { sender_device, .. } => sender_device.as_deref(),
| Self::StaticClient => None,
} }
} }
@@ -76,14 +71,12 @@ impl ClientIdentity {
| Self::Appservice { sender_device: Some(sender_device), .. } => Ok(sender_device), | Self::Appservice { sender_device: Some(sender_device), .. } => Ok(sender_device),
| Self::Appservice { sender_device: None, .. } => | Self::Appservice { sender_device: None, .. } =>
Err!(Request(Forbidden("Appservices must masquerade to use this endpoint."))), Err!(Request(Forbidden("Appservices must masquerade to use this endpoint."))),
| Self::StaticClient =>
Err!(Request(Forbidden("Static clients cannot use this endpoint."))),
} }
} }
pub(crate) fn appservice_info(&self) -> Option<&RegistrationInfo> { pub(crate) fn appservice_info(&self) -> Option<&RegistrationInfo> {
match self { match self {
| Self::User { .. } | Self::StaticClient => None, | Self::User { .. } => None,
| Self::Appservice { appservice_info, .. } => Some(appservice_info), | Self::Appservice { appservice_info, .. } => Some(appservice_info),
} }
} }
@@ -353,7 +346,7 @@ async fn check_access_token(
} }
Ok(ClientIdentity::User { sender_user, sender_device }) Ok(ClientIdentity::User { sender_user, sender_device })
} else if let Ok(appservice_info) = services.appservice.find_from_token(token) { } else if let Ok(appservice_info) = services.appservice.find_from_token(token).await {
let Ok(sender_user) = query.user_id.clone().map_or_else( let Ok(sender_user) = query.user_id.clone().map_or_else(
|| { || {
UserId::parse_with_server_name( UserId::parse_with_server_name(
@@ -386,7 +379,10 @@ async fn check_access_token(
.await .await
.is_err() .is_err()
{ {
return Err!(Request(UnknownDevice("Device does not exist for this user."))); return Err!(Request(Forbidden(
"Device does not exist for user or appservice cannot masquerade as this \
device."
)));
} }
Some(device_id.to_owned()) Some(device_id.to_owned())
@@ -399,23 +395,6 @@ async fn check_access_token(
sender_device, sender_device,
appservice_info: Box::new(appservice_info), appservice_info: Box::new(appservice_info),
}) })
} else if let Some(session) = services.oauth.get_client_credentials_session(token).await {
if !required_scopes
.iter()
.any(|scope| session.scopes.contains(scope))
{
return Err(Error::Request(
ErrorKind::InsufficientUserAuthentication(Box::new(
assign!(InsufficientUserAuthenticationErrorData::new(), {
scope: required_scopes.iter().cloned().collect()
}),
)),
"You do not have permission to access this endpoint.".into(),
StatusCode::UNAUTHORIZED,
));
}
Ok(ClientIdentity::StaticClient)
} else { } else {
Err(Error::Request( Err(Error::Request(
ErrorKind::UnknownToken(UnknownTokenErrorData::new()), ErrorKind::UnknownToken(UnknownTokenErrorData::new()),
@@ -426,7 +405,7 @@ async fn check_access_token(
} }
async fn check_appservice_token(services: &Services, token: &str) -> Result<RegistrationInfo> { async fn check_appservice_token(services: &Services, token: &str) -> Result<RegistrationInfo> {
let Ok(appservice_info) = services.appservice.find_from_token(token) else { let Ok(appservice_info) = services.appservice.find_from_token(token).await else {
return Err!(Request(Unauthorized("Invalid appservice token."))); return Err!(Request(Unauthorized("Invalid appservice token.")));
}; };
+23 -27
View File
@@ -209,35 +209,31 @@ async fn create_invite(
services.sync.wake(&recipient_user).await; services.sync.wake(&recipient_user).await;
let matching_appservices: Vec<_> = services for appservice in services.appservice.read().await.values() {
.appservice if appservice.is_user_match(&recipient_user) {
.read() let transaction_id = general_purpose::URL_SAFE_NO_PAD
.values() .encode(sha256::hash(pdu.event_id.as_bytes()))
.filter(|appservice| appservice.is_user_match(&recipient_user)) .into();
.cloned()
.collect();
for appservice in matching_appservices { let request = ruma::api::appservice::event::push_events::v1::Request::new(
let transaction_id = general_purpose::URL_SAFE_NO_PAD transaction_id,
.encode(sha256::hash(pdu.event_id.as_bytes())) vec![pdu.to_format()],
.into(); );
let request = ruma::api::appservice::event::push_events::v1::Request::new( services
transaction_id, .sending
vec![pdu.to_format()], .send_appservice_request(appservice.registration.clone(), request)
); .await
.map_err(|e| {
services error!(
.sending "failed to notify appservice {} about incoming invite: {e}",
.send_appservice_request(appservice.registration.clone(), request) appservice.registration.id
.await );
.map_err(|e| { err!(BadServerResponse(
error!( "Failed to notify appservice about incoming invite."
"failed to notify appservice {} about incoming invite: {e}", ))
appservice.registration.id })?;
); }
err!(BadServerResponse("Failed to notify appservice about incoming invite."))
})?;
} }
} }
+1 -1
View File
@@ -151,7 +151,7 @@ pub(crate) async fn create_join_event_template_route(
), ),
&body.user_id, &body.user_id,
Some(&body.room_id), Some(&body.room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
drop(state_lock); drop(state_lock);
+1 -1
View File
@@ -107,7 +107,7 @@ pub(crate) async fn create_knock_event_template_route(
), ),
&body.user_id, &body.user_id,
Some(&body.room_id), Some(&body.room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
+1 -1
View File
@@ -59,7 +59,7 @@ pub(crate) async fn create_leave_event_template_route(
), ),
&body.user_id, &body.user_id,
Some(&body.room_id), Some(&body.room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
-9
View File
@@ -353,15 +353,6 @@ pub fn check(config: &Config) -> Result {
} }
})?; })?;
for (id, client) in &config.oauth.clients {
if client.scopes.is_empty() {
warn!(
"The static OAuth client `{id}` has no scopes configured. It will not be able \
to access any API endpoints."
);
}
}
Ok(()) Ok(())
} }
+2 -56
View File
@@ -24,7 +24,6 @@ use ruma::{
OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId,
RoomVersionId, ServerName, RoomVersionId, ServerName,
api::{ api::{
OAuthClientScope,
client::{discovery::discover_support::ContactRole, rtc::RtcTransport}, client::{discovery::discover_support::ContactRole, rtc::RtcTransport},
federation::discovery::OldVerifyKey, federation::discovery::OldVerifyKey,
}, },
@@ -66,8 +65,8 @@ use crate::{Result, err, error::Error, utils::sys};
ignore = "config_paths catchall" ignore = "config_paths catchall"
)] )]
pub struct Config { pub struct Config {
// Paths to config file(s). Not supposed to be set manually in the config // Paths to config file(s). Not supposed to be set manually in the config file,
// file, only updated dynamically from the --config option given at runtime. // only updated dynamically from the --config option given at runtime.
pub config_paths: Option<Vec<PathBuf>>, pub config_paths: Option<Vec<PathBuf>>,
/// The server_name is the pretty name of this server. It is used as a /// The server_name is the pretty name of this server. It is used as a
@@ -2747,12 +2746,7 @@ pub struct OauthConfig {
compatibility_mode: OAuthMode, compatibility_mode: OAuthMode,
/// display: hidden /// display: hidden
#[serde(default)]
pub oidc: Option<OidcConfig>, pub oidc: Option<OidcConfig>,
/// display: hidden
#[serde(default)]
pub clients: HashMap<String, OAuthClient>,
} }
impl OauthConfig { impl OauthConfig {
@@ -2966,54 +2960,6 @@ impl TrustedServerConfig {
} }
} }
#[derive(Clone, Debug, Deserialize)]
#[config_example_generator(
filename = "conduwuit-example.toml",
section = "global.oauth.clients.\"$id\"",
optional = "true",
subheader = "\
# Use this section to add static OAuth clients for bots and automation.
# Clients added here may use the client credentials OAuth grant to authorize
# themselves with Continuwuity.
#
# Make sure to replace `$id` in the header with your client ID of choice! You can
# add more copies of this section with different IDs to add multiple clients.
#
# Because the client credentials grant authorizes the client as itself, without
# an attached user, clients that use it will not be able to access most of the Matrix
# client-server API. Administrative functionality that does not require a user
# will still be available."
)]
pub struct OAuthClient {
/// The client's client secret.
///
/// This must be supplied as the `client_secret` parameter when requesting
/// an access token with the OAuth 2.0 token endpoint. Continuwuity does
/// not check the `Authorization` header for requests to this endpoint.
pub client_secret: String,
/// A list of scopes that the client may request. Continuwuity allows static
/// clients to request the following scopes:
///
/// - "urn:matrix:client:cc.c10y.msc4484.server_administration" (MSC4484):
/// This scope grants access to the Matrix server administration APIs, as
/// well as Continuwuity's internal admin API (currently a work in
/// progress).
/// - "urn:matrix:client:api:*": This scope grants access to the Matrix
/// client-server API. Most endpoints require an authenticated Matrix user
/// and thus will not be usable by static clients.
///
/// The `urn:matrix:client:device:<id>` scope may not be requested by static
/// clients.
///
/// Scopes listed here are not granted by default. The client must
/// explicitly include them in the `scope` parameter of its access token
/// request.
///
/// default: []
pub scopes: BTreeSet<OAuthClientScope>,
}
const DEPRECATED_KEYS: &[&str] = &[ const DEPRECATED_KEYS: &[&str] = &[
"cache_capacity", "cache_capacity",
"conduit_cache_capacity_modifier", "conduit_cache_capacity_modifier",
+4 -66
View File
@@ -39,7 +39,7 @@ use crate::{
debug, debug_error, err, debug, debug_error, err,
matrix::{Event, StateKey}, matrix::{Event, StateKey},
trace, trace,
utils::stream::{BroadbandExt, IterStream, ReadyExt, TryWidebandExt, WidebandExt}, utils::stream::{BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, WidebandExt},
warn, warn,
}; };
@@ -590,8 +590,8 @@ where
.find(|aev| is_type_and_key(*aev, &TimelineEventType::RoomPowerLevels, "")); .find(|aev| is_type_and_key(*aev, &TimelineEventType::RoomPowerLevels, ""));
let content: PowerLevelsContentFields = match pl { let content: PowerLevelsContentFields = match pl {
// With no m.room.power_levels in scope the create event's defaults // With no m.room.power_levels in scope the create event's defaults apply,
// apply, under which the room creator holds 100 and everyone else 0. // under which the room creator holds 100 and everyone else 0.
| None => return Ok(if sender_is_creator { int!(100) } else { int!(0) }), | None => return Ok(if sender_is_creator { int!(100) } else { int!(0) }),
| Some(ev) => from_json_str(ev.content().get())?, | Some(ev) => from_json_str(ev.content().get())?,
}; };
@@ -706,7 +706,7 @@ where
let events_to_check: Vec<_> = events_to_check let events_to_check: Vec<_> = events_to_check
.map(Result::Ok) .map(Result::Ok)
.wide_and_then(async |event_id| { .broad_and_then(async |event_id| {
fetch_event(event_id.to_owned()) fetch_event(event_id.to_owned())
.await .await
.ok_or_else(|| Error::NotFound(format!("Failed to find {event_id}"))) .ok_or_else(|| Error::NotFound(format!("Failed to find {event_id}")))
@@ -1123,68 +1123,6 @@ mod tests {
utils::stream::IterStream, utils::stream::IterStream,
}; };
#[tokio::test]
async fn iterative_auth_check_keeps_event_order() {
let mut events = INITIAL_EVENTS();
let initial_state = ["CREATE", "IPOWER", "IJR", "IMB"]
.into_iter()
.map(|id| {
let event = &events[&event_id(id)];
(
event
.event_type()
.with_state_key(event.state_key().unwrap()),
event.event_id.clone(),
)
})
.collect();
let leave = to_pdu_event(
"LEAVE",
bob(),
TimelineEventType::RoomMember,
Some(bob().as_str()),
to_raw_json_value(&json!({ "membership": "leave" })).unwrap(),
&["CREATE", "IPOWER", "IMB"],
&["IMB"],
);
let rejoin = to_pdu_event(
"REJOIN",
bob(),
TimelineEventType::RoomMember,
Some(bob().as_str()),
member_content_join(),
&["CREATE", "IPOWER", "IJR", "LEAVE"],
&["LEAVE"],
);
let ordered_events = [leave.event_id.clone(), rejoin.event_id.clone()];
for event in [leave, rejoin] {
events.insert(event.event_id.clone(), event);
}
let fetcher = |id: OwnedEventId| {
let events = &events;
async move {
// Let the rejoin fetch finish before the leave.
if id == event_id("LEAVE") {
tokio::task::yield_now().await;
}
events.get(&id).cloned()
}
};
let resolved = super::iterative_auth_check(
&RoomVersionRules::V6,
ordered_events.iter().map(AsRef::as_ref).stream(),
initial_state,
&fetcher,
)
.await
.unwrap();
assert_eq!(
resolved[&StateEventType::RoomMember.with_state_key(bob().as_str())],
event_id("REJOIN"),
);
}
/// Events at the start of a room have no `m.room.power_levels` in their /// Events at the start of a room have no `m.room.power_levels` in their
/// auth events, so the sender's power for sort ordering comes from the /// auth events, so the sender's power for sort ordering comes from the
/// create event instead. /// create event instead.
+3 -4
View File
@@ -14,8 +14,6 @@ use tokio_metrics::TaskMonitor;
use tokio_metrics::{RuntimeIntervals, RuntimeMonitor}; use tokio_metrics::{RuntimeIntervals, RuntimeMonitor};
pub use self::instruments::{Instruments, duration_buckets}; pub use self::instruments::{Instruments, duration_buckets};
#[cfg(tokio_unstable)]
use crate::SyncMutex;
use crate::{Err, Result}; use crate::{Err, Result};
pub struct Metrics { pub struct Metrics {
@@ -29,7 +27,7 @@ pub struct Metrics {
_runtime_monitor: Option<RuntimeMonitor>, _runtime_monitor: Option<RuntimeMonitor>,
#[cfg(tokio_unstable)] #[cfg(tokio_unstable)]
runtime_intervals: SyncMutex<Option<RuntimeIntervals>>, runtime_intervals: std::sync::Mutex<Option<RuntimeIntervals>>,
// TODO: move stats // TODO: move stats
pub requests_handle_active: AtomicU32, pub requests_handle_active: AtomicU32,
@@ -71,7 +69,7 @@ impl Metrics {
_runtime_monitor: runtime_monitor, _runtime_monitor: runtime_monitor,
#[cfg(tokio_unstable)] #[cfg(tokio_unstable)]
runtime_intervals: SyncMutex::new(runtime_intervals), runtime_intervals: std::sync::Mutex::new(runtime_intervals),
requests_handle_active: AtomicU32::new(0), requests_handle_active: AtomicU32::new(0),
requests_handle_finished: AtomicU32::new(0), requests_handle_finished: AtomicU32::new(0),
@@ -83,6 +81,7 @@ impl Metrics {
pub fn runtime_interval(&self) -> Option<tokio_metrics::RuntimeMetrics> { pub fn runtime_interval(&self) -> Option<tokio_metrics::RuntimeMetrics> {
self.runtime_intervals self.runtime_intervals
.lock() .lock()
.expect("locked")
.as_mut() .as_mut()
.map(Iterator::next) .map(Iterator::next)
.expect("next interval") .expect("next interval")
+1 -4
View File
@@ -36,10 +36,7 @@ pub use config::Config;
pub use error::Error; pub use error::Error;
pub use info::version::*; pub use info::version::*;
pub use matrix::{Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, pdu, state_res}; pub use matrix::{Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, pdu, state_res};
pub use parking_lot::{ pub use parking_lot::{Mutex as SyncMutex, RwLock as SyncRwLock};
Mutex as SyncMutex, RwLock as SyncRwLock, RwLockReadGuard as SyncRwLockReadGuard,
RwLockWriteGuard as SyncRwLockWriteGuard,
};
pub use server::Server; pub use server::Server;
pub use utils::{result, result::Result}; pub use utils::{result, result::Result};
+1 -1
View File
@@ -171,7 +171,7 @@ pub(super) static MAPS: &[Descriptor] = &[
}, },
Descriptor { Descriptor {
name: "referencedevents", name: "referencedevents",
..descriptor::DROPPED ..descriptor::RANDOM
}, },
Descriptor { Descriptor {
name: "refreshtoken_refreshtokeninfo", name: "refreshtoken_refreshtokeninfo",
+2 -5
View File
@@ -69,7 +69,7 @@ pub(crate) async fn run(server: &Arc<Server>, starts: bool) -> Result<(bool, boo
let reloads = server.server.reloading.swap(false, Ordering::AcqRel); let reloads = server.server.reloading.swap(false, Ordering::AcqRel);
let stops = !reloads || stale_from_mods(&main_lock)? <= restart_thresh(); let stops = !reloads || stale(server).await? <= restart_thresh();
let starts = reloads && stops; let starts = reloads && stops;
if stops { if stops {
let stop = main_mod.get::<StopFuncProto>("stop")?; let stop = main_mod.get::<StopFuncProto>("stop")?;
@@ -140,10 +140,7 @@ async fn stale_count(server: &Arc<Server>) -> usize {
async fn stale(server: &Arc<Server>) -> Result<usize, Error> { async fn stale(server: &Arc<Server>) -> Result<usize, Error> {
let mods_lock = server.mods.read().await; let mods_lock = server.mods.read().await;
stale_from_mods(&mods_lock) let mods: &Vec<mods::Module> = &mods_lock;
}
fn stale_from_mods(mods: &[mods::Module]) -> Result<usize, Error> {
for (i, module) in mods.iter().enumerate() { for (i, module) in mods.iter().enumerate() {
if module.deleted()? { if module.deleted()? {
return Ok(i); return Ok(i);
+24 -16
View File
@@ -1,12 +1,19 @@
#![cfg(feature = "sentry_telemetry")] #![cfg(feature = "sentry_telemetry")]
use std::{borrow::Cow, sync::OnceLock}; use std::{
borrow::Cow,
str::FromStr,
sync::{Arc, OnceLock},
};
use conduwuit_build_metadata as build; use conduwuit_build_metadata as build;
use conduwuit_core::{config::Config, debug, trace}; use conduwuit_core::{config::Config, debug, trace};
use sentry::{ use sentry::{
Breadcrumb, ClientOptions, Level, Breadcrumb, ClientOptions, Level,
types::protocol::v7::{Context, Event}, types::{
Dsn,
protocol::v7::{Context, Event},
},
}; };
static SEND_PANIC: OnceLock<bool> = OnceLock::new(); static SEND_PANIC: OnceLock<bool> = OnceLock::new();
@@ -30,21 +37,22 @@ fn options(config: &Config) -> ClientOptions {
.expect("init_sentry should only be called if sentry is enabled and this is not None") .expect("init_sentry should only be called if sentry is enabled and this is not None")
.as_str(); .as_str();
let options = ClientOptions::new() let server_name = config
.dsn(dsn)
.traces_sample_rate(config.sentry_traces_sample_rate)
.debug(cfg!(debug_assertions))
.maybe_release(release_name())
.user_agent(conduwuit_core::user_agent())
.attach_stacktrace(config.sentry_attach_stacktrace)
.before_send(before_send)
.before_breadcrumb(before_breadcrumb);
config
.sentry_send_server_name .sentry_send_server_name
.then(|| config.server_name.to_string()) .then(|| config.server_name.to_string().into());
.into_iter()
.fold(options, ClientOptions::server_name) ClientOptions {
dsn: Some(Dsn::from_str(dsn).expect("sentry_endpoint must be a valid URL")),
server_name,
traces_sample_rate: config.sentry_traces_sample_rate,
debug: cfg!(debug_assertions),
release: release_name(),
user_agent: conduwuit_core::user_agent().into(),
attach_stacktrace: config.sentry_attach_stacktrace,
before_send: Some(Arc::new(before_send)),
before_breadcrumb: Some(Arc::new(before_breadcrumb)),
..Default::default()
}
} }
fn before_send(event: Event<'static>) -> Option<Event<'static>> { fn before_send(event: Event<'static>) -> Option<Event<'static>> {
+2 -2
View File
@@ -25,7 +25,7 @@ pub(crate) async fn run(services: Arc<Services>) -> Result<()> {
debug!("Start"); debug!("Start");
// Install the admin room callback here for now // Install the admin room callback here for now
admin::init(&services.admin); admin::init(&services.admin).await;
// Setup shutdown/signal handling // Setup shutdown/signal handling
let handle = ServerHandle::new(); let handle = ServerHandle::new();
@@ -60,7 +60,7 @@ pub(crate) async fn run(services: Arc<Services>) -> Result<()> {
_ = sigs.await; _ = sigs.await;
// Remove the admin room callback // Remove the admin room callback
admin::fini(&services.admin); admin::fini(&services.admin).await;
debug_info!("Finish"); debug_info!("Finish");
res res
+9 -9
View File
@@ -75,7 +75,7 @@ pub async fn create_admin_room(services: &Services) -> Result {
PartialPdu::state(String::new(), &create_content), PartialPdu::state(String::new(), &create_content),
server_user, server_user,
room_id.as_deref(), room_id.as_deref(),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -100,7 +100,7 @@ pub async fn create_admin_room(services: &Services) -> Result {
), ),
server_user, server_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -135,7 +135,7 @@ pub async fn create_admin_room(services: &Services) -> Result {
PartialPdu::state(String::new(), &power_levels_content), PartialPdu::state(String::new(), &power_levels_content),
server_user, server_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -148,7 +148,7 @@ pub async fn create_admin_room(services: &Services) -> Result {
PartialPdu::state(String::new(), &RoomJoinRulesEventContent::new(JoinRule::Invite)), PartialPdu::state(String::new(), &RoomJoinRulesEventContent::new(JoinRule::Invite)),
server_user, server_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -164,7 +164,7 @@ pub async fn create_admin_room(services: &Services) -> Result {
), ),
server_user, server_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -180,7 +180,7 @@ pub async fn create_admin_room(services: &Services) -> Result {
), ),
server_user, server_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -194,7 +194,7 @@ pub async fn create_admin_room(services: &Services) -> Result {
PartialPdu::state(String::new(), &RoomNameEventContent::new(room_name)), PartialPdu::state(String::new(), &RoomNameEventContent::new(room_name)),
server_user, server_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -207,7 +207,7 @@ pub async fn create_admin_room(services: &Services) -> Result {
PartialPdu::state(String::new(), &RoomTopicEventContent::markdown(room_topic)), PartialPdu::state(String::new(), &RoomTopicEventContent::markdown(room_topic)),
server_user, server_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
@@ -223,7 +223,7 @@ pub async fn create_admin_room(services: &Services) -> Result {
PartialPdu::state(String::new(), &alias_content), PartialPdu::state(String::new(), &alias_content),
server_user, server_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.boxed() .boxed()
.await?; .await?;
+6 -6
View File
@@ -56,7 +56,7 @@ impl super::Service {
), ),
server_user, server_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
@@ -70,7 +70,7 @@ impl super::Service {
), ),
user_id, user_id,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
} else { } else {
@@ -84,7 +84,7 @@ impl super::Service {
), ),
server_user, server_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
} }
@@ -116,7 +116,7 @@ impl super::Service {
PartialPdu::state(String::new(), &room_power_levels), PartialPdu::state(String::new(), &room_power_levels),
server_user, server_user,
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.await?; .await?;
@@ -196,7 +196,7 @@ impl super::Service {
PartialPdu::state(String::new(), &room_power_levels), PartialPdu::state(String::new(), &room_power_levels),
self.services.globals.server_user.as_ref(), self.services.globals.server_user.as_ref(),
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.await .await
.inspect_err(|e| { .inspect_err(|e| {
@@ -243,7 +243,7 @@ impl super::Service {
PartialPdu::state(user_id.to_string(), &member_content), PartialPdu::state(user_id.to_string(), &member_content),
self.services.globals.server_user.as_ref(), self.services.globals.server_user.as_ref(),
Some(&room_id), Some(&room_id),
&state_lock, Some(&state_lock),
) )
.await .await
.map(|_| ()) .map(|_| ())
+9 -18
View File
@@ -27,17 +27,18 @@ use ruma::{
}, },
}, },
}; };
use tokio::sync::RwLock;
use crate::{ use crate::{
Dep, account_data, config, globals, Dep, account_data, config, globals,
media::{MXC_LENGTH, mxc::Mxc}, media::{MXC_LENGTH, mxc::Mxc},
rooms::{self, state::RoomMutexGuard}, rooms,
}; };
pub struct Service { pub struct Service {
services: Services, services: Services,
channel: (Sender<CommandInput>, Receiver<CommandInput>), channel: (Sender<CommandInput>, Receiver<CommandInput>),
pub handle: SyncRwLock<Option<Processor>>, pub handle: RwLock<Option<Processor>>,
pub complete: SyncRwLock<Option<Completer>>, pub complete: SyncRwLock<Option<Completer>>,
#[cfg(feature = "console")] #[cfg(feature = "console")]
pub console: Arc<console::Console>, pub console: Arc<console::Console>,
@@ -130,7 +131,7 @@ impl crate::Service for Service {
media: args.depend::<crate::media::Service>("media"), media: args.depend::<crate::media::Service>("media"),
}, },
channel: loole::bounded(COMMAND_QUEUE_LIMIT), channel: loole::bounded(COMMAND_QUEUE_LIMIT),
handle: SyncRwLock::new(None), handle: RwLock::new(None),
complete: SyncRwLock::new(None), complete: SyncRwLock::new(None),
#[cfg(feature = "console")] #[cfg(feature = "console")]
console: console::Console::new(&args), console: console::Console::new(&args),
@@ -371,11 +372,8 @@ impl Service {
} }
async fn process_command(&self, command: CommandInput) -> ProcessorResult { async fn process_command(&self, command: CommandInput) -> ProcessorResult {
let handle = *self let handle_guard = self.handle.read().await;
.handle let handle = handle_guard.as_ref().expect("Admin module is not loaded");
.read()
.as_ref()
.expect("Admin module is not loaded");
let services = self let services = self
.services .services
@@ -494,7 +492,6 @@ impl Service {
) -> Result<()> { ) -> Result<()> {
assert!(self.user_is_admin(user_id).await, "sender is not admin"); assert!(self.user_is_admin(user_id).await, "sender is not admin");
let state_lock = self.services.state.mutex.lock(room_id).await;
if let Err(e) = self if let Err(e) = self
.services .services
.timeline .timeline
@@ -502,11 +499,11 @@ impl Service {
PartialPdu::timeline(&self.text_or_file(content).await), PartialPdu::timeline(&self.text_or_file(content).await),
user_id, user_id,
Some(room_id), Some(room_id),
&state_lock, None,
) )
.await .await
{ {
self.handle_response_error(e, room_id, user_id, &state_lock) self.handle_response_error(e, room_id, user_id)
.boxed() .boxed()
.await .await
.unwrap_or_else(default_log); .unwrap_or_else(default_log);
@@ -520,7 +517,6 @@ impl Service {
e: Error, e: Error,
room_id: &RoomId, room_id: &RoomId,
user_id: &UserId, user_id: &UserId,
state_lock: &RoomMutexGuard,
) -> Result<()> { ) -> Result<()> {
error!("Failed to build and append admin room response PDU: \"{e}\""); error!("Failed to build and append admin room response PDU: \"{e}\"");
let content = RoomMessageEventContent::text_plain(format!( let content = RoomMessageEventContent::text_plain(format!(
@@ -530,12 +526,7 @@ impl Service {
self.services self.services
.timeline .timeline
.build_and_append_pdu( .build_and_append_pdu(PartialPdu::timeline(&content), user_id, Some(room_id), None)
PartialPdu::timeline(&content),
user_id,
Some(room_id),
state_lock,
)
.await?; .await?;
Ok(()) Ok(())
+32 -16
View File
@@ -1,19 +1,20 @@
mod namespace_regex; mod namespace_regex;
mod registration_info; mod registration_info;
use std::{collections::BTreeMap, sync::Arc}; use std::{collections::BTreeMap, iter::IntoIterator, sync::Arc};
use async_trait::async_trait; use async_trait::async_trait;
use conduwuit::{Err, Result, SyncRwLock, SyncRwLockReadGuard, err, utils::stream::IterStream}; use conduwuit::{Err, Result, err, utils::stream::IterStream};
use database::Map; use database::Map;
use futures::{Stream, TryStreamExt}; use futures::{Future, FutureExt, Stream, TryStreamExt};
use ruma::{RoomAliasId, RoomId, UserId, api::appservice::Registration}; use ruma::{RoomAliasId, RoomId, UserId, api::appservice::Registration};
use tokio::sync::{RwLock, RwLockReadGuard};
pub use self::{namespace_regex::NamespaceRegex, registration_info::RegistrationInfo}; pub use self::{namespace_regex::NamespaceRegex, registration_info::RegistrationInfo};
use crate::{Dep, globals, sending, users}; use crate::{Dep, globals, sending, users};
pub struct Service { pub struct Service {
registration_info: SyncRwLock<Registrations>, registration_info: RwLock<Registrations>,
services: Services, services: Services,
db: Data, db: Data,
} }
@@ -34,7 +35,7 @@ type Registrations = BTreeMap<String, RegistrationInfo>;
impl crate::Service for Service { impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> { fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self { Ok(Arc::new(Self {
registration_info: SyncRwLock::new(BTreeMap::new()), registration_info: RwLock::new(BTreeMap::new()),
services: Services { services: Services {
globals: args.depend::<globals::Service>("globals"), globals: args.depend::<globals::Service>("globals"),
sending: args.depend::<sending::Service>("sending"), sending: args.depend::<sending::Service>("sending"),
@@ -122,6 +123,7 @@ impl Service {
self.registration_info self.registration_info
.write() .write()
.await
.insert(id, registration.try_into()?); .insert(id, registration.try_into()?);
Ok(()) Ok(())
@@ -137,7 +139,7 @@ impl Service {
// Check for token collision with other appservices (allow // Check for token collision with other appservices (allow
// re-registration of same appservice) // re-registration of same appservice)
if let Ok(existing) = self.find_from_token(&registration.as_token) { if let Ok(existing) = self.find_from_token(&registration.as_token).await {
if existing.registration.id != registration.id { if existing.registration.id != registration.id {
return Err(err!(Request(InvalidParam( return Err(err!(Request(InvalidParam(
"Cannot register appservice: Token is already used by appservice '{}'. \ "Cannot register appservice: Token is already used by appservice '{}'. \
@@ -180,6 +182,7 @@ impl Service {
// removes the appservice registration info // removes the appservice registration info
self.registration_info self.registration_info
.write() .write()
.await
.remove(appservice_id) .remove(appservice_id)
.ok_or_else(|| err!("Appservice not found"))?; .ok_or_else(|| err!("Appservice not found"))?;
@@ -194,17 +197,19 @@ impl Service {
.await .await
} }
pub fn get_registration(&self, id: &str) -> Option<Registration> { pub async fn get_registration(&self, id: &str) -> Option<Registration> {
self.registration_info self.registration_info
.read() .read()
.await
.get(id) .get(id)
.cloned() .cloned()
.map(|info| info.registration) .map(|info| info.registration)
} }
/// Returns Result to match users::find_from_token for select_ok usage /// Returns Result to match users::find_from_token for select_ok usage
pub fn find_from_token(&self, token: &str) -> Result<RegistrationInfo> { pub async fn find_from_token(&self, token: &str) -> Result<RegistrationInfo> {
self.read() self.read()
.await
.values() .values()
.find(|info| info.registration.as_token == token) .find(|info| info.registration.as_token == token)
.cloned() .cloned()
@@ -212,21 +217,26 @@ impl Service {
} }
/// Checks if a given user id matches any exclusive appservice regex /// Checks if a given user id matches any exclusive appservice regex
pub fn is_exclusive_user_id(&self, user_id: &UserId) -> bool { pub async fn is_exclusive_user_id(&self, user_id: &UserId) -> bool {
self.read() self.read()
.await
.values() .values()
.any(|info| info.is_exclusive_user_match(user_id)) .any(|info| info.is_exclusive_user_match(user_id))
} }
/// Checks if a given user id matches any appservice regex, exclusive or /// Checks if a given user id matches any appservice regex, exclusive or
/// otherwise /// otherwise
pub fn is_user_id(&self, user_id: &UserId) -> bool { pub async fn is_user_id(&self, user_id: &UserId) -> bool {
self.read().values().any(|info| info.is_user_match(user_id)) self.read()
.await
.values()
.any(|info| info.is_user_match(user_id))
} }
/// Checks if a given room alias matches any exclusive appservice regex /// Checks if a given room alias matches any exclusive appservice regex
pub fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool { pub async fn is_exclusive_alias(&self, alias: &RoomAliasId) -> bool {
self.read() self.read()
.await
.values() .values()
.any(|info| info.aliases.is_exclusive_match(alias.as_str())) .any(|info| info.aliases.is_exclusive_match(alias.as_str()))
} }
@@ -235,15 +245,19 @@ impl Service {
/// ///
/// TODO: use this? /// TODO: use this?
#[allow(dead_code)] #[allow(dead_code)]
pub fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool { pub async fn is_exclusive_room_id(&self, room_id: &RoomId) -> bool {
self.read() self.read()
.await
.values() .values()
.any(|info| info.rooms.is_exclusive_match(room_id.as_str())) .any(|info| info.rooms.is_exclusive_match(room_id.as_str()))
} }
pub fn iter_ids(&self) -> impl Stream<Item = String> + Send { pub fn iter_ids(&self) -> impl Stream<Item = String> + Send {
let ids: Vec<String> = self.read().keys().cloned().collect(); self.read()
ids.stream() .map(|info| info.keys().cloned().collect::<Vec<_>>())
.map(IntoIterator::into_iter)
.map(IterStream::stream)
.flatten_stream()
} }
pub fn iter_db_ids(&self) -> impl Stream<Item = Result<(String, Registration)>> + Send { pub fn iter_db_ids(&self) -> impl Stream<Item = Result<(String, Registration)>> + Send {
@@ -267,5 +281,7 @@ impl Service {
}) })
} }
pub fn read(&self) -> SyncRwLockReadGuard<'_, Registrations> { self.registration_info.read() } pub fn read(&self) -> impl Future<Output = RwLockReadGuard<'_, Registrations>> + Send {
self.registration_info.read()
}
} }
+2 -2
View File
@@ -146,8 +146,8 @@ impl crate::Service for Service {
.redirect(redirect::Policy::limited(2)) .redirect(redirect::Policy::limited(2))
.build()?, .build()?,
// MSC4174 recommends against following redirects, since the // MSC4174 recommends against following redirects, since the destination
// destination is only checked before the request is sent. // is only checked before the request is sent.
webpush: base(config)? webpush: base(config)?
.connect_timeout(Duration::from_secs(config.pusher_conn_timeout)) .connect_timeout(Duration::from_secs(config.pusher_conn_timeout))
.timeout(Duration::from_secs(config.pusher_timeout)) .timeout(Duration::from_secs(config.pusher_timeout))
+2 -6
View File
@@ -21,9 +21,7 @@ impl Data {
} }
} }
pub fn next_count(&self) -> Result<u64> { self.next_count_with(|_| ()) } pub fn next_count(&self) -> Result<u64> {
pub fn next_count_with(&self, write: impl FnOnce(u64)) -> Result<u64> {
let _cork = self.db.cork(); let _cork = self.db.cork();
let mut lock = self.counter.write(); let mut lock = self.counter.write();
let counter: &mut u64 = &mut lock; let counter: &mut u64 = &mut lock;
@@ -32,9 +30,7 @@ impl Data {
"counter mismatch" "counter mismatch"
); );
let next = counter.checked_add(1).unwrap_or(*counter); *counter = counter.checked_add(1).unwrap_or(*counter);
write(next);
*counter = next;
self.global.insert(COUNTER, counter.to_be_bytes()); self.global.insert(COUNTER, counter.to_be_bytes());
Loaded 100 of 146 files, more files were not shown because too many files have changed in this diff. Show more