mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-18 14:37:32 +00:00
Compare commits
56
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad50b9a3b3 | ||
|
|
ceafc6f58d | ||
|
|
467e335c90 | ||
|
|
902e54b525 | ||
|
|
4ef487f40e | ||
|
|
32bfe5f129 | ||
|
|
07d4c6f304 | ||
|
|
b3d099a52a | ||
|
|
92f9531def | ||
|
|
a3d23c3718 | ||
|
|
055c430e77 | ||
|
|
df5e03f3b4 | ||
|
|
6e7ebe66c9 | ||
|
|
24e962a656 | ||
|
|
c5cd82a6a3 | ||
|
|
add66bd0b7 | ||
|
|
700c11d758 | ||
|
|
559f76908e | ||
|
|
7ade8c4899 | ||
|
|
20943c6210 | ||
|
|
4811ad831d | ||
|
|
bfb611d9e4 | ||
|
|
d4c6decdd6 | ||
|
|
82e42696aa | ||
|
|
f6c9b53e17 | ||
|
|
39035d735e | ||
|
|
b34dfe343a | ||
|
|
26ec038418 | ||
|
|
7afe5885e9 | ||
|
|
77e8a6b41b | ||
|
|
4ebcf299e2 | ||
|
|
c72156cb04 | ||
|
|
b5594c3061 | ||
|
|
ae0a2d1797 | ||
|
|
5d0dc8b137 | ||
|
|
4d271a5621 | ||
|
|
23a51bcf96 | ||
|
|
326348ec1a | ||
|
|
4f63edac33 | ||
|
|
79a2cbc7be | ||
|
|
c8d87b3a0d | ||
|
|
49171ec1ed | ||
|
|
ea3beb628a | ||
|
|
8603ae21cc | ||
|
|
f154ecb542 | ||
|
|
98fe280de4 | ||
|
|
2c605151eb | ||
|
|
4bd09a6d88 | ||
|
|
cb37a9cf0b | ||
|
|
aefededfc8 | ||
|
|
9be45212f1 | ||
|
|
fca19a983d | ||
|
|
4ebf44412c | ||
|
|
cacf6ff912 | ||
|
|
aef031c9d7 | ||
|
|
7b927196a2 |
No files matched your search
@@ -71,7 +71,7 @@ runs:
|
||||
|
||||
- name: Install timelord-cli and git-warp-time
|
||||
if: steps.check-binaries.outputs.need-install == 'true'
|
||||
uses: https://github.com/taiki-e/install-action@cfdb7ed4ccc7c7dce37759eae89dc5674b469b39 # v2
|
||||
uses: https://github.com/taiki-e/install-action@ab49d3c64680143e184118bed66a46419fc15519 # v2
|
||||
with:
|
||||
tool: git-warp-time,timelord-cli@3.0.1
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ jobs:
|
||||
name: Renovate
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/renovatebot/renovate:44.210.1@sha256:45cc73346c44a9afe037f2d19766f2b545b59b2ed31b937b5b09017d2958e45f
|
||||
image: ghcr.io/renovatebot/renovate:44.241.0@sha256:22d22b4ca7d768b5b469309d34379783bf91cd94a58faecf1cd0f4528a65d21c
|
||||
options: --tmpfs /tmp:exec
|
||||
steps:
|
||||
- name: Checkout
|
||||
|
||||
@@ -1,3 +1,84 @@
|
||||
# Continuwuity v26.11.0-alpha.2 (2026-11-14)
|
||||
|
||||
## Features
|
||||
|
||||
- Added opt-in OpenTelemetry metrics, exported over OTLP or scraped by Prometheus from `/_continuwuity/metrics`, and a Grafana dashboard. Contributed by @eleboucher. (prometheus-metrics)
|
||||
- Add support for using custom DNS servers instead of using /etc/resolv.conf. Contributed by @s1lv3r. ([#2056](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2056))
|
||||
- Continuwuity now supports configuring additional trusted audience values for deployments using OIDC with an IDP that sends them. Contributed by @ginger ([#2226](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2226))
|
||||
- "!admin users list" now hides deactivated users by default, but can display them with the optional "--show-deactivated" flag. "--hide-suspended" and "--hide-locked" have been added as well, which stop suspended and locked users from being displayed respectively. Contributed by @Clubs. ([#2292](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2292))
|
||||
- Added support for [MSC4494: Membership-based invite blocking](https://github.com/matrix-org/matrix-spec-proposals/pull/4494) ([#2297](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2297))
|
||||
- Appservices now receive typing indicators and read receipts. Contributed by @Jade ([#2327](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2327))
|
||||
- Added support for servers returning 410 gone to indicate they are no longer serving a Matrix server ([MSC4188](https://github.com/matrix-org/matrix-spec-proposals/pull/4188)). Contributed by @nex and @silversys ([#2355](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2355))
|
||||
- Changed the policy on unstable features, disabling most by default and making them configurable in a tidy little `experiments` configuration. See also: #1884. ([#2517](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2517))
|
||||
- Added support for [MSC4363](https://github.com/matrix-org/matrix-spec-proposals/pull/4363) (OAuth step-up authentication). Contributed by @ginger.
|
||||
- Added support for [MSC2815](https://github.com/matrix-org/matrix-spec-proposals/pull/2815), allowing room moderators to fetch the original content of redacted events, behind the `allow_moderators_to_view_redacted_content` config option. Contributed by @eleboucher.
|
||||
- Added support for [MSC4484](https://github.com/matrix-org/matrix-spec-proposals/pull/4484). Clients which use the built-in Matrix server administration APIs will need to ask for the appropriate scope when signing in with OAuth. Contributed by @ginger.
|
||||
- Check content-type header on federation responses, ignoring any that don't match (spec compliance)
|
||||
- Implemented unstable support for [MSC4560] (Stripped state requests over federation). Contributed by @ginger.
|
||||
|
||||
[MSC4560]: https://github.com/matrix-org/matrix-spec-proposals/pull/4560
|
||||
- Profile banners are now treated as images when imported from OIDC claims, like avatars already were.
|
||||
- Remove support for legacy, unauthenticated media, including the `allow_legacy_media` and `freeze_legacy_media` options.
|
||||
- The first-run version of the web UI now includes a link to the registration page. Contributed by @ginger
|
||||
|
||||
## Bugfixes
|
||||
|
||||
- Fixed `/get_missing_events` rejecting requests with more `earliest_events` than the `limit`. Contributed by @eleboucher. (get-missing-events-earliest-limit)
|
||||
- Invitees are now added as room creators when creating a v12+ trusted private chat. Contributed by @ginger. ([#2162](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2162))
|
||||
- Fixed push gateway URLs containing the configured notification path outside of their suffix. Contributed by @eleboucher. ([#2261](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2261))
|
||||
- "!admin users change-email" now verifies a user exists before attempting to change their email. Contributed by @Clubs. ([#2298](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2298))
|
||||
- Fixed URL preview image MIME types and rejected failed downloads. Contributed by @eleboucher. ([#2308](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2308))
|
||||
- Correctly set RocksDB column options, including enabling block caches. Contributed by @Jade ([#2345](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2345))
|
||||
- Fix some possible deadlocks/freezes and reduce lock contention (improving performance). Contributed by @Jade ([#2351](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2351))
|
||||
- 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. ([#2356](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2356))
|
||||
- The OAuth identity reset page is no longer linked from the account management UI to reduce confusion. Contributed by @ginger. ([#2383](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2383))
|
||||
- Fixed a worker panic when knocking on a room over federation. Contributed by @eleboucher. ([#2387](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2387))
|
||||
- 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. ([#2400](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2400))
|
||||
- Redirect URIs in OAuth clients' metadata are now properly validated to be on a subdomain of the OAuth issuer URL domain. Contributed by @ginger. ([#2421](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2421))
|
||||
- Fix v12 rooms created by the same user in the same millisecond ending up as the same room. Contributed by @eleboucher. ([#2424](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2424))
|
||||
- Client-server API endpoints are now properly ratelimited for unauthenticated requests. Contributed by @ginger. ([#2444](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2444))
|
||||
- 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`. ([#2451](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2451))
|
||||
- Setting `m.fully_read` via the account data endpoints now returns 405 `M_BAD_JSON` as required by the spec, instead of 400. ([#2451](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2451))
|
||||
- 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`. ([#2451](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2451))
|
||||
- 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. ([#2451](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2451))
|
||||
- The `m.forget_forced_upon_leave` capability now reflects the `forget_forced_upon_leave` config option instead of always being advertised as enabled. ([#2452](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2452))
|
||||
- Fixed push notifications for membership events setting `user_is_target` based on the sender rather than the user being notified. ([#2454](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2454))
|
||||
- Ensure HTTP clients actually follow the `dns_servers` config option. Contributed by @silversys ([#2460](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2460))
|
||||
- Reworked event relations to follow the spec more closely. Pagination of `/relations` now returns the correct pages and `next_batch` tokens, recursive relations are returned in the right order without duplicates, and bundled `m.reference` aggregations now include every reference. Contributed by @Henry-Hiles (QuadRadical). ([#2465](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2465))
|
||||
- Read receipts are now more spec compliant, will work better in threads and are less likely to end up causing loops with other software. Contributed by @Jade ([#2481](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2481))
|
||||
- Fix the DNS resolver failing to start without `/etc/resolv.conf` when `dns_servers` is configured. Contributed by @eleboucher. ([#2495](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2495))
|
||||
- Fixed OIDC logins failing after the identity provider rotates its signing keys. Contributed by @eleboucher. ([#2497](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2497))
|
||||
- Creating a room with valid but non-canonical JSON now returns `400 M_BAD_JSON` instead of panicking the worker and returning `500 M_UNKNOWN`.
|
||||
- Fix account data updates sent at the same time leaving old copies behind, which every initial sync then returned. Existing copies are removed on startup. Contributed by @eleboucher.
|
||||
- Fix gap filling skipping outlier events that are missing their previous events. Contributed by @eleboucher.
|
||||
- Fix incoming federation events losing state changes when predecessors share the same state-before snapshot. Contributed by @eleboucher.
|
||||
- Fix new devices sometimes never reaching other users' device lists. Contributed by @eleboucher.
|
||||
- Fix state resolution applying events out of order, which could undo room joins. Contributed by @eleboucher.
|
||||
- Fix to-device messages, including room keys, sometimes being lost before delivery. Contributed by @eleboucher.
|
||||
- For deployments using OIDC with `profile_key_import_mode` set to `on_login`, users' avatars will no longer be clobbered if they didn't change their avatar since their last login.
|
||||
- Joining a local room the user is not allowed to join now returns `403 M_FORBIDDEN` instead of `500 M_UNKNOWN` when there are no other servers to try.
|
||||
- Room summary visibility checks are no longer incorrectly applied for remote rooms. Contributed by @ginger.
|
||||
- The userinfo endpoint is now accessible even if federation is disabled, allowing LiveKit to be used on servers with federation disabled without using the server name whitelist.
|
||||
- `!admin token issue` can no longer issue registration tokens when `allow_registration` is false. Contributed by @Clubs.
|
||||
|
||||
## Improved Documentation
|
||||
|
||||
- Add the Authentication section to document available auth methods for Continuwuity. The "delegated authentication" guide has also been migrated to here. Contributed by @stratself. ([#2234](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2234))
|
||||
- Add a guide for push notifications, detailing how it works, push gateway specifics, troubleshooting common issues, and pointing to external guides for UnifiedPush backends. Contributed by @stratself ([#2244](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2244))
|
||||
- The deploying page now includes vital general information about installing Continuwuity: release tracks, update steps, and post-installation recommendations. Contributed by @stratself ([#2252](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2252))
|
||||
- Add some missing instructions on configuring Continuwuity on the RPM page. Users are encouraged to use the [generic deploying docs](https://continuwuity.org/deploying/generic) for the bulk of guidance anyhow. Contributed by @stratself ([#2275](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2275))
|
||||
- Better, more succinct [introduction page](https://continuwuity.org/introduction.html). Contributed by @stratself ([#2279](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2279))
|
||||
- Add a section on [troubleshooting Docker issues](https://continuwuity.org/troubleshooting#docker-issues). Contributed by @stratself. ([#2324](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2324))
|
||||
- Instructions for Authelia added to the [OIDC guide](https://continuwuity.org/authentication/oidc.html). Contributed by @fhoekstra ([#2341](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2341))
|
||||
- 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. ([#2353](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2353))
|
||||
- The documentation now refers to the Continuwuity Docker service as `continuwuity` instead of `homeserver`.
|
||||
|
||||
## Misc
|
||||
|
||||
- Updated internal Sentry integration setup to the new pattern required by the SDK. #2423
|
||||
- Upgraded rocksdb from 11.1.1 to 11.12.0 and jemalloc to 5.4.0.
|
||||
|
||||
|
||||
# Continuwuity v26.11.0-alpha.1 (2026-11-10)
|
||||
|
||||
## Features
|
||||
|
||||
Generated
+51
-50
@@ -193,7 +193,7 @@ dependencies = [
|
||||
"rustc-hash",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -255,7 +255,7 @@ checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -497,7 +497,7 @@ dependencies = [
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -785,7 +785,7 @@ dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -865,7 +865,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"conduwuit_build_metadata",
|
||||
@@ -897,7 +897,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_admin"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"conduwuit_api",
|
||||
@@ -921,7 +921,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_api"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"base64 0.23.1",
|
||||
@@ -949,11 +949,12 @@ dependencies = [
|
||||
"sha1 0.11.0",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"wildmatch",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_build_metadata"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"built",
|
||||
"cargo_metadata",
|
||||
@@ -961,7 +962,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_core"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"argon2",
|
||||
"arrayvec",
|
||||
@@ -1031,7 +1032,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_database"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"conduwuit_core",
|
||||
@@ -1051,17 +1052,17 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_macros"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"itertools 0.15.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_router"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-server",
|
||||
@@ -1094,7 +1095,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_service"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"assign",
|
||||
@@ -1150,7 +1151,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_web"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"async-trait",
|
||||
@@ -1379,7 +1380,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strict",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1621,7 +1622,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1643,7 +1644,7 @@ checksum = "2ac7135c3ef02b2f7833bbeb1be5ba7f966dcde8a87c6b87f65a778d71a02785"
|
||||
dependencies = [
|
||||
"darling_core 0.24.1",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1763,7 +1764,7 @@ checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2169,7 +2170,7 @@ checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3174,7 +3175,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4478,7 +4479,7 @@ dependencies = [
|
||||
"proc-macro-error-attr3",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4775,7 +4776,7 @@ checksum = "92ecd8964f8453721699a1ed72037b0db49ce2f5a5138486ee89bed6f67cdf3a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4897,9 +4898,9 @@ checksum = "1e061d1b48cb8d38042de4ae0a7a6401009d6143dc80d2e2d6f31f0bdd6470c7"
|
||||
|
||||
[[package]]
|
||||
name = "resolvematrix"
|
||||
version = "1.4.0"
|
||||
version = "1.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e7767f4eb1d58880d6b33135a6c098cc8fbccecb259a833b44448c0de144dac"
|
||||
checksum = "d6e659fe17ed82acfac43641d00d1bbfd0a9d53ec4d2f901b01f792f0e2c9e3c"
|
||||
dependencies = [
|
||||
"hickory-resolver",
|
||||
"num-traits",
|
||||
@@ -4969,7 +4970,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma"
|
||||
version = "0.17.2"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=0ed7fba34213f18a628a56f527c6cc795cd7eef5#0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=472a23ef86bc0bb40a22d856fc0af539eb9d71b7#472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"js_int",
|
||||
@@ -4988,7 +4989,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-appservice-api"
|
||||
version = "0.17.1"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=0ed7fba34213f18a628a56f527c6cc795cd7eef5#0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=472a23ef86bc0bb40a22d856fc0af539eb9d71b7#472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
dependencies = [
|
||||
"http",
|
||||
"js_int",
|
||||
@@ -5001,7 +5002,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-client-api"
|
||||
version = "0.25.2"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=0ed7fba34213f18a628a56f527c6cc795cd7eef5#0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=472a23ef86bc0bb40a22d856fc0af539eb9d71b7#472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"assign",
|
||||
@@ -5023,7 +5024,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-common"
|
||||
version = "0.20.2"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=0ed7fba34213f18a628a56f527c6cc795cd7eef5#0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=472a23ef86bc0bb40a22d856fc0af539eb9d71b7#472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"base64 0.23.1",
|
||||
@@ -5056,7 +5057,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-events"
|
||||
version = "0.35.2"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=0ed7fba34213f18a628a56f527c6cc795cd7eef5#0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=472a23ef86bc0bb40a22d856fc0af539eb9d71b7#472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"indexmap 2.14.2",
|
||||
@@ -5077,7 +5078,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
version = "0.16.1"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=0ed7fba34213f18a628a56f527c6cc795cd7eef5#0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=472a23ef86bc0bb40a22d856fc0af539eb9d71b7#472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http",
|
||||
@@ -5099,7 +5100,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-identifiers-validation"
|
||||
version = "0.14.0"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=0ed7fba34213f18a628a56f527c6cc795cd7eef5#0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=472a23ef86bc0bb40a22d856fc0af539eb9d71b7#472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"thiserror 2.0.21",
|
||||
@@ -5108,7 +5109,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-macros"
|
||||
version = "0.20.2"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=0ed7fba34213f18a628a56f527c6cc795cd7eef5#0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=472a23ef86bc0bb40a22d856fc0af539eb9d71b7#472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"cfg-if",
|
||||
@@ -5117,14 +5118,14 @@ dependencies = [
|
||||
"quote",
|
||||
"ruma-identifiers-validation",
|
||||
"serde",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
"toml 1.2.1+spec-1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruma-push-gateway-api"
|
||||
version = "0.16.0"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=0ed7fba34213f18a628a56f527c6cc795cd7eef5#0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=472a23ef86bc0bb40a22d856fc0af539eb9d71b7#472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
@@ -5136,7 +5137,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-signatures"
|
||||
version = "0.22.1"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=0ed7fba34213f18a628a56f527c6cc795cd7eef5#0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=472a23ef86bc0bb40a22d856fc0af539eb9d71b7#472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"ed25519-dalek",
|
||||
@@ -5153,7 +5154,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-state-res"
|
||||
version = "0.18.0"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=0ed7fba34213f18a628a56f527c6cc795cd7eef5#0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
source = "git+https://github.com/ruma/ruma.git?rev=472a23ef86bc0bb40a22d856fc0af539eb9d71b7#472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"ruma-common",
|
||||
@@ -5167,7 +5168,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ruminuwuity"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"http",
|
||||
@@ -5662,7 +5663,7 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5781,7 +5782,7 @@ dependencies = [
|
||||
"darling 0.24.1",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6077,9 +6078,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.9"
|
||||
version = "3.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
|
||||
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -6103,7 +6104,7 @@ checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6205,7 +6206,7 @@ checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6315,7 +6316,7 @@ checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7003,7 +7004,7 @@ dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
@@ -7351,7 +7352,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "xtask"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"cargo_metadata",
|
||||
@@ -7384,7 +7385,7 @@ checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
@@ -7425,7 +7426,7 @@ checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
@@ -7465,7 +7466,7 @@ checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
+7
-3
@@ -12,7 +12,7 @@ license = "Apache-2.0"
|
||||
# See also `rust-toolchain.toml`
|
||||
readme = "README.md"
|
||||
repository = "https://forgejo.ellis.link/continuwuation/continuwuity"
|
||||
version = "26.11.0-alpha.1"
|
||||
version = "26.11.0-alpha.2"
|
||||
|
||||
[workspace.metadata.crane]
|
||||
name = "conduwuit"
|
||||
@@ -272,6 +272,9 @@ version = "0.5.2"
|
||||
[workspace.dependencies.libloading]
|
||||
version = "0.9.0"
|
||||
|
||||
[workspace.dependencies.wildmatch]
|
||||
version = "2.7.0"
|
||||
|
||||
# Validating urls in config, was already a transitive dependency
|
||||
[workspace.dependencies.url]
|
||||
version = "2.5.8"
|
||||
@@ -357,7 +360,7 @@ version = "1.1.1"
|
||||
# Used for matrix spec type definitions and helpers
|
||||
[workspace.dependencies.ruma]
|
||||
git = "https://github.com/ruma/ruma.git"
|
||||
rev = "0ed7fba34213f18a628a56f527c6cc795cd7eef5"
|
||||
rev = "472a23ef86bc0bb40a22d856fc0af539eb9d71b7"
|
||||
features = [
|
||||
"appservice-api-c",
|
||||
"client-api",
|
||||
@@ -600,7 +603,8 @@ features = ["std"]
|
||||
version = "0.3.0"
|
||||
|
||||
[workspace.dependencies.resolvematrix]
|
||||
version = "1.4.0"
|
||||
version = "1.4.2"
|
||||
features = ["unstable-msc4188"]
|
||||
|
||||
[workspace.dependencies.serde_urlencoded]
|
||||
version = "0.7.1"
|
||||
|
||||
+8
-3
@@ -23,12 +23,15 @@ to encourage users to stay up-to-date with the latest release, and we have no co
|
||||
We appreciate the efforts of security researchers and the community in identifying and reporting vulnerabilities. To
|
||||
ensure that potential vulnerabilities are addressed properly, please follow these guidelines:
|
||||
|
||||
1. **Contact members of the team directly** over E2EE private message.
|
||||
1. **Contact _all_ members of the team** over E2EE private message on Matrix.
|
||||
Add each contact to the same encrypted room. **Do not message maintainers individually**.
|
||||
If you cannot reach us from matrix.org, please try [another server][sl] (e.g. continuwuity.rocks).
|
||||
- [@jade:ellis.link](https://matrix.to/#/@jade:ellis.link)
|
||||
- [@nex:nexy7574.co.uk](https://matrix.to/#/@nex:nexy7574.co.uk)
|
||||
- [@ginger:gingershaped.computer](https://matrix.to/#/@ginger:gingershaped.computer)
|
||||
2. **Email the security team** at [security@continuwuity.org](mailto:security@continuwuity.org). This is not E2EE, so
|
||||
don't include sensitive details.
|
||||
don't include sensitive details. Do not ask where to send sensitive details either; that
|
||||
information is included in this security policy. We may not respond to emails that do this.
|
||||
3. **Do not disclose the vulnerability publicly** until a fix has been pushed to the main branch.
|
||||
4. **Provide detailed information** about the vulnerability, including:
|
||||
- A clear description of the issue
|
||||
@@ -42,6 +45,8 @@ ensure that potential vulnerabilities are addressed properly, please follow thes
|
||||
If you have any doubts about a potential security vulnerability, contact us via private channels first! We'd prefer that
|
||||
you bother us, instead of having a vulnerability disclosed without a fix.
|
||||
|
||||
[sl]: https://servers.joinmatrix.org
|
||||
|
||||
### Terms for credit
|
||||
|
||||
Before reporting a vulnerability, please remember that we are a small team maintaining a large codebase depended upon by
|
||||
@@ -105,4 +110,4 @@ When security vulnerabilities are identified:
|
||||
|
||||
---
|
||||
|
||||
This security policy was last updated on May 25, 2025.
|
||||
This security policy was last updated on November 17th, 2026.
|
||||
+17
-3
@@ -52,8 +52,10 @@ else
|
||||
fi
|
||||
|
||||
# The base docker image to use for complement tests
|
||||
# You can build the default with `docker build -t continuwuity:complement -f ./docker/complement.Dockerfile .`
|
||||
# after running `cargo build -p conduwuit --features openreg`. Only the debug binary is used.
|
||||
# On Linux, you can build the default with `docker build -t continuwuity:complement -f ./docker/complement.Dockerfile .`
|
||||
# after running `cargo build -p conduwuit --features openreg`.
|
||||
# On non-Linux platforms (or to use a container build), build `docker/Dockerfile` with debuginfo and openreg `--build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg`
|
||||
# and then run `docker build -t continuwuity:complement --target container -f ./docker/complement.Dockerfile .`.
|
||||
COMPLEMENT_BASE_IMAGE="${COMPLEMENT_BASE_IMAGE:-continuwuity:complement}"
|
||||
|
||||
# Complement tests that are skipped due to flakiness/reliability issues or we don't implement such features and won't for a long time
|
||||
@@ -83,6 +85,13 @@ for command in docker go jq; do
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "${DOCKER_HOST:-}" ]; then
|
||||
DOCKER_HOST="$(docker context inspect --format '{{.Endpoints.docker.Host}}' 2>/dev/null || true)"
|
||||
if [ -n "$DOCKER_HOST" ]; then
|
||||
export DOCKER_HOST
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$IMAGE_ARCHIVE" ]; then
|
||||
if [ ! -f "$IMAGE_ARCHIVE" ]; then
|
||||
echo "Docker image archive not found: $IMAGE_ARCHIVE"
|
||||
@@ -99,7 +108,12 @@ fi
|
||||
|
||||
if ! docker image inspect "$COMPLEMENT_BASE_IMAGE" > /dev/null 2>&1; then
|
||||
echo "Complement base image not found: $COMPLEMENT_BASE_IMAGE"
|
||||
echo "Build it with: cargo build -p conduwuit --features openreg && docker build -t $COMPLEMENT_BASE_IMAGE -f docker/complement.Dockerfile ."
|
||||
if [ "$(uname -s)" != "Linux" ]; then
|
||||
echo "Build it with: docker buildx build --load -t continuwuity:latest-openreg --build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg -f docker/Dockerfile . && docker build -t $COMPLEMENT_BASE_IMAGE --target container -f docker/complement.Dockerfile ."
|
||||
else
|
||||
echo "Build it with: cargo build -p conduwuit --features openreg && docker build -t $COMPLEMENT_BASE_IMAGE -f docker/complement.Dockerfile ."
|
||||
echo "Or from a container build: docker buildx build --load -t continuwuity:latest-openreg --build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg -f docker/Dockerfile . && docker build -t $COMPLEMENT_BASE_IMAGE --target container -f docker/complement.Dockerfile ."
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Check content-type header on federation responses, ignoring any that don't match (spec compliance)
|
||||
@@ -0,0 +1 @@
|
||||
Fix account data updates sent at the same time leaving old copies behind, which every initial sync then returned. Existing copies are removed on startup. Contributed by @eleboucher.
|
||||
@@ -0,0 +1 @@
|
||||
Creating a room with valid but non-canonical JSON now returns `400 M_BAD_JSON` instead of panicking the worker and returning `500 M_UNKNOWN`.
|
||||
@@ -0,0 +1 @@
|
||||
Joining a local room the user is not allowed to join now returns `403 M_FORBIDDEN` instead of `500 M_UNKNOWN` when there are no other servers to try.
|
||||
@@ -0,0 +1 @@
|
||||
Added support for [MSC2815](https://github.com/matrix-org/matrix-spec-proposals/pull/2815), allowing room moderators to fetch the original content of redacted events, behind the `allow_moderators_to_view_redacted_content` config option. Contributed by @eleboucher.
|
||||
@@ -0,0 +1 @@
|
||||
Remove support for legacy, unauthenticated media, including the `allow_legacy_media` and `freeze_legacy_media` options.
|
||||
@@ -0,0 +1 @@
|
||||
Legacy `/sync` now honours the `room.rooms`, `room.not_rooms`, `account_data.types` and `account_data.not_types` filter fields instead of returning every room and all account data. Contributed by @eleboucher.
|
||||
@@ -0,0 +1 @@
|
||||
Added support for servers returning 410 gone to indicate they are no longer serving a Matrix server (MSC4188). Contributed by @nex and @silversys
|
||||
@@ -0,0 +1 @@
|
||||
Requests waiting on `/_matrix/client/v3/sync` can now be interrupted by the server shutdown, unblocking the 30-second shutdown delay imposed on a quiet server.
|
||||
@@ -0,0 +1 @@
|
||||
`/_matrix/client/v3/sync` no longer waits 30 seconds if the `timeout` parameter is omitted or set to zero, correctly reflecting the specification's rule that such requests should return immediately, even if they are empty.
|
||||
@@ -0,0 +1 @@
|
||||
Fix the DNS resolver failing to start without `/etc/resolv.conf` when `dns_servers` is configured. Contributed by @eleboucher.
|
||||
@@ -0,0 +1 @@
|
||||
Fixed OIDC logins failing after the identity provider rotates its signing keys. Contributed by @eleboucher.
|
||||
@@ -0,0 +1 @@
|
||||
Changed the policy on unstable features, disabling most by default and making them configurable in a tidy little `experiments` configuration. See also: #1884.
|
||||
@@ -0,0 +1 @@
|
||||
The sticky events feature flag is correctly advertised in `/_matrix/client/versions` again after it was accidentally removed in #2517.
|
||||
@@ -0,0 +1 @@
|
||||
Fixed `/get_missing_events` rejecting requests with more `earliest_events` than the `limit`. Contributed by @eleboucher.
|
||||
@@ -31,7 +31,6 @@ rocksdb_log_level = "info"
|
||||
rocksdb_max_log_files = 1
|
||||
rocksdb_recovery_mode = 0
|
||||
rocksdb_paranoid_file_checks = true
|
||||
allow_legacy_media = true
|
||||
startup_netburst = true
|
||||
startup_netburst_keep = -1
|
||||
allow_invalid_tls_certificates_yes_i_know_what_the_fuck_i_am_doing_with_this_and_i_know_this_is_insecure = true
|
||||
|
||||
+103
-30
@@ -1657,13 +1657,6 @@
|
||||
# env: CONTINUWUITY_ALLOW_INCOMING_TYPING
|
||||
#allow_incoming_typing = true
|
||||
|
||||
# Allow the use of unstable persistent "sticky events" ([MSC4354])
|
||||
#
|
||||
# MSC4354: https://c10y.cc/MSC4354
|
||||
#
|
||||
# env: CONTINUWUITY_ALLOW_STICKY_EVENTS
|
||||
#allow_sticky_events = false
|
||||
|
||||
# Maximum time federation user can indicate typing.
|
||||
#
|
||||
# env: CONTINUWUITY_TYPING_FEDERATION_TIMEOUT_S
|
||||
@@ -1714,29 +1707,6 @@
|
||||
# env: CONTINUWUITY_BROTLI_COMPRESSION
|
||||
#brotli_compression = false
|
||||
|
||||
# Enable the legacy unauthenticated Matrix media repository endpoints.
|
||||
# These endpoints consist of:
|
||||
# - /_matrix/media/*/config
|
||||
# - /_matrix/media/*/upload
|
||||
# - /_matrix/media/*/preview_url
|
||||
# - /_matrix/media/*/download/*
|
||||
# - /_matrix/media/*/thumbnail/*
|
||||
#
|
||||
# The authenticated equivalent endpoints are always enabled.
|
||||
#
|
||||
# Defaults to false, as unauthenticated media has been sunsetted.
|
||||
#
|
||||
# env: CONTINUWUITY_ALLOW_LEGACY_MEDIA
|
||||
#allow_legacy_media = false
|
||||
|
||||
# If set to true, prevents fetching new legacy remote media.
|
||||
#
|
||||
# Legacy media may still be accessible if it was already fetched
|
||||
# previously and allow_legacy_media is true.
|
||||
#
|
||||
# env: CONTINUWUITY_FREEZE_LEGACY_MEDIA
|
||||
#freeze_legacy_media = true
|
||||
|
||||
# Check consistency of the media directory at startup:
|
||||
# 1. When `media_compat_file_link` is enabled, this check will upgrade
|
||||
# media when switching back and forth between Conduit and conduwuit.
|
||||
@@ -2687,3 +2657,106 @@
|
||||
#
|
||||
# env: CONTINUWUITY_OAUTH__OIDC__PROFILE_KEY_IMPORT_MODE
|
||||
#profile_key_import_mode = "on_registration"
|
||||
|
||||
[global.experiments]
|
||||
# Continuwuity's experimental features are frequently updated.
|
||||
# If you got this configuration via a package manager, chances are it's outdated.
|
||||
# Check out the configuration reference online to see a fresh version:
|
||||
# https://continuwuity.org/reference/config.html#:~:text=global.experiments
|
||||
#
|
||||
# Please keep in mind that experiments are used to enable unstable features.
|
||||
# You probably don't need to enable any of these unless you know what they are,
|
||||
# and consequently know why you should enable them.
|
||||
|
||||
|
||||
# MSC4155: Invite filtering
|
||||
#
|
||||
# Provides advanced invite filtering rules for users, allowing complex
|
||||
# configurations that can allow, ignore, and reject invites from users and
|
||||
# servers broadly.
|
||||
#
|
||||
# Requires a supporting client to set up on an account.
|
||||
#
|
||||
# https://github.com/matrix-org/matrix-spec-proposals/pull/4155
|
||||
#
|
||||
# env: CONTINUWUITY_EXPERIMENTS__MSC4155
|
||||
#msc4155 = false
|
||||
|
||||
# MSC4174: Web push
|
||||
#
|
||||
# Adds server-side support for web push, allowing web clients to receive
|
||||
# push notifications directly without the need for an intermediary push
|
||||
# gateway like Sygnal.
|
||||
#
|
||||
# https://github.com/matrix-org/matrix-spec-proposals/pull/4174
|
||||
#
|
||||
# env: CONTINUWUITY_EXPERIMENTS__MSC4174
|
||||
#msc4174 = false
|
||||
|
||||
# MSC4484: Server Administration OAuth Scope
|
||||
#
|
||||
# Adds a new OAuth2 scope that explicitly grants a token temporary
|
||||
# homeserver administrator privileges, granting temporary token access
|
||||
# to administrator endpoints like locking & suspension.
|
||||
#
|
||||
# https://github.com/matrix-org/matrix-spec-proposals/pull/4484
|
||||
#
|
||||
# env: CONTINUWUITY_EXPERIMENTS__MSC4484
|
||||
#msc4484 = false
|
||||
|
||||
# MSC4494: Membership-based invite blocking
|
||||
#
|
||||
# Adds a new invite blocking action that will reject all invites coming
|
||||
# from users who do not share a room with the invitee that is not `public`
|
||||
# (the join rule).
|
||||
#
|
||||
# This is not related to MSC4155, this proposal instead builds on the
|
||||
# "invite blocking" proposal that landed in the specification in v1.17,
|
||||
# which simply allows enabling or disabling invites altogether.
|
||||
#
|
||||
# MSC4494 is a good middle-ground between the allowlisting possible with
|
||||
# MSC4155, and the general desire to block invites from users you may not
|
||||
# know.
|
||||
#
|
||||
# Requires a supporting client to enable on an account.
|
||||
#
|
||||
# https://github.com/matrix-org/matrix-spec-proposals/pull/4494
|
||||
#
|
||||
# env: CONTINUWUITY_EXPERIMENTS__MSC4494
|
||||
#msc4494 = false
|
||||
|
||||
# MSC4560: Stripped state requests over federation
|
||||
#
|
||||
# Implements a more efficient way for servers to acquire and serve
|
||||
# "stripped state" to clients, which is typically only used for displaying
|
||||
# rooms. The display of space hierarchies and room summaries is
|
||||
# significantly faster when this proposal is enabled and used.
|
||||
#
|
||||
# https://github.com/matrix-org/matrix-spec-proposals/pull/4560
|
||||
#
|
||||
# env: CONTINUWUITY_EXPERIMENTS__MSC4560
|
||||
#msc4560 = false
|
||||
|
||||
#[global.experiments.msc2815]
|
||||
# MSC2815: Proposal to allow room moderators to view redacted event content
|
||||
#
|
||||
# Allows the server to retain unredacted copies of events that have been
|
||||
# redacted for a limited period of time, which allows room moderators and
|
||||
# server administrators to reveal redacted contents. Useful for moderation
|
||||
# and investigating reports.
|
||||
#
|
||||
# Requires a supporting client to use.
|
||||
#
|
||||
# https://github.com/matrix-org/matrix-spec-proposals/pull/2815
|
||||
|
||||
|
||||
# Whether to enable MSC2815.
|
||||
#
|
||||
# env: CONTINUWUITY_EXPERIMENTS__MSC2815__ENABLED
|
||||
#enabled = false
|
||||
|
||||
# How long, in seconds, to retain the original content of redacted
|
||||
# events before it is permanently erased. Defaults to 90 days.
|
||||
#
|
||||
# env: CONTINUWUITY_EXPERIMENTS__MSC2815__UNREDACTED_CONTENT_MAX_AGE_SECS
|
||||
#unredacted_content_max_age_secs = 7776000
|
||||
+1
-1
@@ -50,7 +50,7 @@ EOF
|
||||
|
||||
# Developer tool versions
|
||||
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
|
||||
ENV BINSTALL_VERSION=1.26.2
|
||||
ENV BINSTALL_VERSION=1.27.0
|
||||
# renovate: datasource=github-releases depName=psastras/sbom-rs
|
||||
ENV CARGO_SBOM_VERSION=0.9.1
|
||||
# renovate: datasource=crate depName=lddtree
|
||||
|
||||
@@ -1,11 +1,29 @@
|
||||
FROM ubuntu:latest
|
||||
ARG CONTINUWUITY_IMAGE=continuwuity:latest-openreg
|
||||
ARG BINARY_SOURCE=host
|
||||
|
||||
FROM ${CONTINUWUITY_IMAGE} AS container-binary
|
||||
|
||||
FROM scratch AS host-binary
|
||||
ARG BINARY_PATH=target/debug/conduwuit
|
||||
COPY ${BINARY_PATH} /sbin/conduwuit
|
||||
|
||||
FROM ubuntu:latest AS base
|
||||
EXPOSE 8008
|
||||
EXPOSE 8448
|
||||
RUN apt-get update && apt-get install -y ca-certificates liburing2 && rm -rf /var/lib/apt/lists/*
|
||||
RUN mkdir -p /etc/continuwuity /var/lib/continuwuity /usr/local/bin/
|
||||
COPY complement/complement-entrypoint.sh /usr/local/bin/complement-entrypoint.sh
|
||||
COPY complement/complement.config.toml /etc/continuwuity/config.toml
|
||||
COPY target/debug/conduwuit /usr/local/bin/conduwuit
|
||||
RUN chmod +x /usr/local/bin/conduwuit /usr/local/bin/complement-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/complement-entrypoint.sh
|
||||
#HEALTHCHECK --interval=30s --timeout=5s CMD curl --fail http://localhost:8008/_continuwuity/server_version || exit 1
|
||||
ENTRYPOINT ["/usr/local/bin/complement-entrypoint.sh"]
|
||||
|
||||
FROM base AS container
|
||||
COPY --from=container-binary /sbin/conduwuit /usr/local/bin/conduwuit
|
||||
RUN chmod +x /usr/local/bin/conduwuit
|
||||
|
||||
FROM base AS host
|
||||
COPY --from=host-binary /sbin/conduwuit /usr/local/bin/conduwuit
|
||||
RUN chmod +x /usr/local/bin/conduwuit
|
||||
|
||||
FROM ${BINARY_SOURCE}
|
||||
@@ -18,7 +18,7 @@ RUN --mount=type=cache,target=/etc/apk/cache apk add \
|
||||
|
||||
# Developer tool versions
|
||||
# renovate: datasource=github-releases depName=cargo-bins/cargo-binstall
|
||||
ENV BINSTALL_VERSION=1.26.2
|
||||
ENV BINSTALL_VERSION=1.27.0
|
||||
# renovate: datasource=github-releases depName=psastras/sbom-rs
|
||||
ENV CARGO_SBOM_VERSION=0.9.1
|
||||
# renovate: datasource=crate depName=lddtree
|
||||
|
||||
@@ -20,6 +20,20 @@ docker build -t continuwuity:complement -f docker/complement.Dockerfile .
|
||||
The `openreg` feature is required: without it the server refuses the open
|
||||
registrations Complement uses to create test users, and almost every test fails.
|
||||
|
||||
On non-Linux (or to build inside a container instead of on the host), build the Continuwuity image with the `openreg` feature and `RUST_PROFILE=dev` first (open
|
||||
registration is only enabled when `debug_assertions` are active), then build
|
||||
the Complement image using the `container` target:
|
||||
|
||||
```bash
|
||||
docker buildx build --load -t continuwuity:latest-openreg --build-arg RUST_PROFILE=dev --build-arg CARGO_FEATURES=default,openreg -f docker/Dockerfile .
|
||||
docker build -t continuwuity:complement --target container -f docker/complement.Dockerfile .
|
||||
./bin/complement
|
||||
```
|
||||
|
||||
Pass `--build-arg CONTINUWUITY_IMAGE=your-image:tag` when building
|
||||
`docker/complement.Dockerfile` if your Continuwuity container image uses a
|
||||
different tag.
|
||||
|
||||
The run can take up to an hour. The runner writes the full Go test stream to
|
||||
`tests/test_results/complement/test_logs.jsonl` and a sorted pass/fail/skip
|
||||
summary to `tests/test_results/complement/test_results.jsonl`. It exits nonzero
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
# Unstable features policy
|
||||
|
||||
Like several other homeservers in the Matrix ecosystem, Continuwuity adopts a "disable by default"
|
||||
approach to experimental features. This ensures every deployment gets the same baseline stability,
|
||||
allowing users to opt in to potentially unstable features.
|
||||
|
||||
Historically, Continuwuity used maintainer discretion to decide whether an unstable feature should
|
||||
be enabled by default. However, as the project has grown, and the pace of spec development has
|
||||
increased, keeping up with unstable proposals becomes less and less feasible by the day, and this
|
||||
causes the implementation of unstable proposals to gradually drift. This can lead to implementations
|
||||
becoming so stale they're incompatible, with no bandwidth to get them fixed up.
|
||||
|
||||
Continuwuity is already selective about which unstable features it implements: the maintainer team
|
||||
typically only accept implementations of proposals that seem like they are a net positive for a
|
||||
large portion of the Matrix ecosystem, rather than aiming to "implement everything". As such, the
|
||||
unstable feature list should typically be small and manageable.
|
||||
|
||||
**All** unstable proposals require an experiment before their implementation can be accepted.
|
||||
Likewise, all experiments should default to being disabled, requiring explicit configuration to
|
||||
enable.
|
||||
|
||||
**Draft proposals** will not be merged until their proposal is undrafted. Likewise, the pull request
|
||||
that implements the draft proposal should itself be marked "WIP", to avoid being merged or
|
||||
prioritised for review. Review is still possible for WIP PRs, so feel free to request a round of
|
||||
feedback.
|
||||
|
||||
## Adding an unstable feature
|
||||
|
||||
First, navigate to `src/core/config/experiments.rs`. There, you have two options for adding an
|
||||
experiment to the `Experiments` struct:
|
||||
|
||||
1. Use `SimpleExperiment` if the experiment only requires enabling with no further configuration.
|
||||
2. Define a new struct that implements the `ToggledExperiment` trait.
|
||||
|
||||
All experiments must be optional and default to off (i.e. `is_enabled()` returns `false`).
|
||||
`SimpleExperiment` is actually a wrapper around `Option<bool>`, and the omission of the
|
||||
configuration OR setting it to `false` disables the experiment. `ToggledExperiment` impls should
|
||||
copy similar behaviour.
|
||||
|
||||
Then, add a public field to the `Experiments` struct that is named the MSC's ID in lowercase.
|
||||
Add a docstring to it, starting with the proposal title (including ID), then a brief paragraph or
|
||||
so explaining what the proposal does in simple terms, and then finally end the docstring with a link
|
||||
to the proposal.
|
||||
|
||||
### Advertising support for unstable features
|
||||
|
||||
If the proposal requires advertising an unstable feature flag, that flag must be added to
|
||||
`unstable_features` in `src/core/matrix/versions.rs`. For example:
|
||||
|
||||
```diff
|
||||
pub fn unstable_features(experiments: &Experiments) -> BTreeMap<String, bool> {
|
||||
BTreeMap::from_iter([
|
||||
// Always enabled feature (https://github.com/matrix-org/matrix-spec-proposals/pull/0000)
|
||||
// Expected for spec v1.20
|
||||
("org.matrix.msc0000".to_owned(), true),
|
||||
+ // MSC9999: My Cool Feature (https://github.com/matrix-org/matrix-spec-proposals/pull/9999)
|
||||
+ ("example.matrix.msc9999".to_owned(), experiments.msc9999.is_enabled())
|
||||
])
|
||||
}
|
||||
```
|
||||
|
||||
This will allow the `/_matrix/client/versions` endpoint to dynamically advertise whether the unstable
|
||||
feature is enabled on the current server.
|
||||
|
||||
## Removing unstable features
|
||||
|
||||
If a proposal is abandoned, becomes obsolete, or is accepted into the specification, the unstable
|
||||
configuration should be removed (and possibly migrated) as soon as possible.
|
||||
|
||||
After removing a field from `experiments`, the key should be added to the `DEPRECATED_KEYS` slice in
|
||||
`src/core/config/mod.rs` (really far down). This will ensure that a warning is printed on startup
|
||||
when a configuration is using a now-removed config key. For example:
|
||||
|
||||
```diff
|
||||
pub struct Experiments {
|
||||
- pub msc9999: SimpleExperiment,
|
||||
}
|
||||
```
|
||||
```diff
|
||||
const DEPRECATED_KEYS: &[&str] = [
|
||||
"foo",
|
||||
+ "experiments.msc9999",
|
||||
];
|
||||
```
|
||||
|
||||
## Always-on experiments
|
||||
|
||||
Some experiments can be forcefully enabled (i.e. always-on), or enabled by default. This should only
|
||||
be the case in exceptional circumstances, and must be adequately well documented. Some examples of
|
||||
situations that may warrant an experiment being always-enabled:
|
||||
|
||||
* A proposal was implemented AFTER it was merged, but BEFORE it had a merged spec PR.
|
||||
These proposals are typically as stable as they'll get, as major changes post-factum of an MSC
|
||||
merge requires another MSC, so only minor changes can be made in the spec PR phase.
|
||||
* The daily experience of users would be at a great detriment without the experiment being enabled.
|
||||
* A proposal is so simple that making it opt-in would be pointless. This is *incredibly* rare.
|
||||
|
||||
The latter two require explicit maintainer approval, so discuss those with the maintainer team
|
||||
first. You can exercise your own judgement for the first.
|
||||
|
||||
Always-on or enabled-by-default experiments must explain in detail why they're exempt from the
|
||||
standard experiments policy via comments in surrounding areas, like
|
||||
`src/core/config/experiments.rs` and `src/core/matrix/versions.rs`. Ideally, these features are not
|
||||
unstable for too long, so explaining a timescale for how long before the feature is stabilised is
|
||||
also helpful.
|
||||
Generated
+16
-16
@@ -431,9 +431,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/core": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.1.tgz",
|
||||
"integrity": "sha512-GArybZxyifQ/wC8N2SzVyFi5JCJpUXgajITV4if8ylOImjZr8j9Cgy+6o55tXEtq85r6XYYE5fbcEz2nxxCpnA==",
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/core/-/core-2.1.2.tgz",
|
||||
"integrity": "sha512-3ghPRkZFwbuO3tr2Rb5cxi6QfSFWOcxoZ5p4pv21lbN5DxAzMduITFlfgBMTArIQbehXrfXw3OUXe1l422b0RA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -441,7 +441,7 @@
|
||||
"@mdx-js/react": "^3.1.1",
|
||||
"@rsbuild/core": "^2.2.14",
|
||||
"@rsbuild/plugin-react": "~2.1.1",
|
||||
"@rspress/shared": "2.1.1",
|
||||
"@rspress/shared": "2.1.2",
|
||||
"@shikijs/rehype": "^4.2.0",
|
||||
"@shikijs/transformers": "^4.2.0",
|
||||
"@types/mdast": "^4.0.4",
|
||||
@@ -464,8 +464,8 @@
|
||||
"react-router-dom": "^7.18.5",
|
||||
"rehype-external-links": "^3.0.0",
|
||||
"rehype-raw": "^7.0.0",
|
||||
"remark-cjk-friendly": "^2.3.3",
|
||||
"remark-cjk-friendly-gfm-strikethrough": "^2.3.2",
|
||||
"remark-cjk-friendly": "^2.3.4",
|
||||
"remark-cjk-friendly-gfm-strikethrough": "^2.3.3",
|
||||
"remark-gfm": "^4.0.1",
|
||||
"remark-mdx": "^3.1.1",
|
||||
"remark-parse": "^11.0.0",
|
||||
@@ -485,9 +485,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/plugin-client-redirects": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.1.1.tgz",
|
||||
"integrity": "sha512-jrnh0UTczcTAk+xeJH6b2/LFLF2W7UzPYP992GxnW0mWJxPnvKQIk9v051bezD3gDuiGGRv8puFU7PMmwLOaHg==",
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-client-redirects/-/plugin-client-redirects-2.1.2.tgz",
|
||||
"integrity": "sha512-kNCC7fffXA277TzTDfKpP+QuCI1X218lJ5JH/2iqYR8PHnLw0Y6ZIwoFmJlE0eKaBdniYyBRGn9zgvT93mCWdg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -498,9 +498,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/plugin-sitemap": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.1.1.tgz",
|
||||
"integrity": "sha512-3Zk+dmitcx5QxiSPi1Wh4exexRnKa09Yyj3710x6UM4sW2cl72SctMZapO7X9ETNrgVt9fW52eQsFzW1y38gSg==",
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/plugin-sitemap/-/plugin-sitemap-2.1.2.tgz",
|
||||
"integrity": "sha512-qF9NDLLJORa7MM8QY/etgMlrXM8hlArNaK5ntiFimqtKRoF1YTJQSKPsAfMq2PvYrpQJyEqsSg6wJ+r+lyjNlw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
@@ -511,16 +511,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rspress/shared": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.1.tgz",
|
||||
"integrity": "sha512-U+OEPt/Ze+ryJdLHvpJJv9hxiRp03rknn5pvhh6v0enjib9SuUrsku/cPzneal3EsNyDZB5kncghpH1iwVKxnA==",
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@rspress/shared/-/shared-2.1.2.tgz",
|
||||
"integrity": "sha512-W34tT1fdP3PrdbXpZNKqOGZMOw+RYL70Z9vnkbT1HTTbtX4uMIDE+SU7ByihG0S0LYBsT3kPxA2cXj696253Uw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rsbuild/core": "^2.2.14",
|
||||
"@shikijs/rehype": "^4.2.0",
|
||||
"@types/react": "^19.3.0",
|
||||
"mdast-util-mdx-jsx": "^3.2.0",
|
||||
"mdast-util-mdx-jsx": "^3.2.1",
|
||||
"unified": "^11.0.5"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -11,6 +11,7 @@ export default defineConfig({
|
||||
light: '/assets/logo.svg',
|
||||
dark: '/assets/logo.svg',
|
||||
},
|
||||
llms: false,
|
||||
// Use `.no-zoom` class to disable image zooms
|
||||
mediumZoom: {
|
||||
selector: '.rspress-doc :not(.no-zoom *) > img',
|
||||
@@ -40,7 +41,9 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
},
|
||||
webMcp: false,
|
||||
themeConfig: {
|
||||
llmsUI: false,
|
||||
socialLinks: [
|
||||
{
|
||||
icon: {
|
||||
|
||||
@@ -87,6 +87,7 @@ serde.workspace = true
|
||||
sha1.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
wildmatch.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -3,10 +3,10 @@ use conduwuit::{Err, Result, at};
|
||||
use futures::StreamExt;
|
||||
use ruma::{
|
||||
api::client::dehydrated_device::{
|
||||
delete_dehydrated_device::unstable as delete_dehydrated_device,
|
||||
get_dehydrated_device::unstable as get_dehydrated_device,
|
||||
get_events::unstable as get_events,
|
||||
put_dehydrated_device::unstable as put_dehydrated_device,
|
||||
delete_dehydrated_device::msc3814 as delete_dehydrated_device,
|
||||
get_dehydrated_device::msc3814 as get_dehydrated_device,
|
||||
get_events::msc3814 as get_events,
|
||||
put_dehydrated_device::msc3814 as put_dehydrated_device,
|
||||
},
|
||||
assign,
|
||||
};
|
||||
|
||||
@@ -30,9 +30,9 @@ pub(crate) async fn get_media_config_route(
|
||||
State(services): State<crate::State>,
|
||||
_body: Ruma<get_media_config::v1::Request>,
|
||||
) -> Result<get_media_config::v1::Response> {
|
||||
Ok(get_media_config::v1::Response::new(ruma_from_usize(
|
||||
Ok(get_media_config::v1::Response::new(Some(ruma_from_usize(
|
||||
services.server.config.max_request_size,
|
||||
)))
|
||||
))))
|
||||
}
|
||||
|
||||
/// # `POST /_matrix/media/v3/upload`
|
||||
|
||||
@@ -1,398 +0,0 @@
|
||||
#![allow(deprecated)]
|
||||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err, Result, err,
|
||||
utils::{content_disposition::make_content_disposition, math::ruma_from_usize},
|
||||
};
|
||||
use conduwuit_service::media::{CORP_CROSS_ORIGIN, Dim, FileMeta};
|
||||
use reqwest::Url;
|
||||
use ruma::{
|
||||
api::client::media::{
|
||||
create_content, get_content, get_content_as_filename, get_content_thumbnail,
|
||||
get_media_config, get_media_preview,
|
||||
},
|
||||
assign,
|
||||
};
|
||||
use service::media::mxc::Mxc;
|
||||
|
||||
use crate::{Ruma, RumaResponse, client::create_content_route};
|
||||
|
||||
/// # `GET /_matrix/media/v3/config`
|
||||
///
|
||||
/// Returns max upload size.
|
||||
pub(crate) async fn get_media_config_legacy_route(
|
||||
State(services): State<crate::State>,
|
||||
_body: Ruma<get_media_config::v3::Request>,
|
||||
) -> Result<get_media_config::v3::Response> {
|
||||
Ok(get_media_config::v3::Response::new(ruma_from_usize(
|
||||
services.server.config.max_request_size,
|
||||
)))
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/media/v1/config`
|
||||
///
|
||||
/// This is a legacy endpoint ("/v1/") that some very old homeservers and/or
|
||||
/// clients may call. conduwuit adds these for compatibility purposes.
|
||||
/// See <https://spec.matrix.org/legacy/legacy/#id27>
|
||||
///
|
||||
/// Returns max upload size.
|
||||
pub(crate) async fn get_media_config_legacy_legacy_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_media_config::v3::Request>,
|
||||
) -> Result<RumaResponse<get_media_config::v3::Response>> {
|
||||
get_media_config_legacy_route(State(services), body)
|
||||
.await
|
||||
.map(RumaResponse)
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/media/v3/preview_url`
|
||||
///
|
||||
/// Returns URL preview.
|
||||
pub(crate) async fn get_media_preview_legacy_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_media_preview::v3::Request>,
|
||||
) -> Result<get_media_preview::v3::Response> {
|
||||
let sender_user = body.identity.expect_sender_user()?;
|
||||
|
||||
let url = &body.url;
|
||||
let url = Url::parse(&body.url).map_err(|e| {
|
||||
err!(Request(InvalidParam(
|
||||
debug_warn!(%sender_user, %url, "Requested URL is not valid: {e}")
|
||||
)))
|
||||
})?;
|
||||
|
||||
if !services.media.url_preview_allowed(&url) {
|
||||
return Err!(Request(Forbidden(
|
||||
debug_warn!(%sender_user, %url, "URL is not allowed to be previewed")
|
||||
)));
|
||||
}
|
||||
|
||||
let preview = services.media.get_url_preview(&url).await.map_err(|e| {
|
||||
err!(Request(Unknown(
|
||||
debug_error!(%sender_user, %url, "Failed to fetch a URL preview: {e}")
|
||||
)))
|
||||
})?;
|
||||
|
||||
serde_json::value::to_raw_value(&preview)
|
||||
.map(get_media_preview::v3::Response::from_raw_value)
|
||||
.map_err(|error| {
|
||||
err!(Request(Unknown(
|
||||
debug_error!(%sender_user, %url, "Failed to parse URL preview: {error}")
|
||||
)))
|
||||
})
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/media/v1/preview_url`
|
||||
///
|
||||
/// This is a legacy endpoint ("/v1/") that some very old homeservers and/or
|
||||
/// clients may call. conduwuit adds these for compatibility purposes.
|
||||
/// See <https://spec.matrix.org/legacy/legacy/#id27>
|
||||
///
|
||||
/// Returns URL preview.
|
||||
pub(crate) async fn get_media_preview_legacy_legacy_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_media_preview::v3::Request>,
|
||||
) -> Result<RumaResponse<get_media_preview::v3::Response>> {
|
||||
get_media_preview_legacy_route(State(services), body)
|
||||
.await
|
||||
.map(RumaResponse)
|
||||
}
|
||||
|
||||
/// # `POST /_matrix/media/v1/upload`
|
||||
///
|
||||
/// Permanently save media in the server.
|
||||
///
|
||||
/// This is a legacy endpoint ("/v1/") that some very old homeservers and/or
|
||||
/// clients may call. conduwuit adds these for compatibility purposes.
|
||||
/// See <https://spec.matrix.org/legacy/legacy/#id27>
|
||||
///
|
||||
/// - Some metadata will be saved in the database
|
||||
/// - Media will be saved in the media/ directory
|
||||
pub(crate) async fn create_content_legacy_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<create_content::v3::Request>,
|
||||
) -> Result<RumaResponse<create_content::v3::Response>> {
|
||||
create_content_route(State(services), body)
|
||||
.await
|
||||
.map(RumaResponse)
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/media/v3/download/{serverName}/{mediaId}`
|
||||
///
|
||||
/// Load media from our server or over federation.
|
||||
///
|
||||
/// - Only allows federation if `allow_remote` is true
|
||||
/// - Only redirects if `allow_redirect` is true
|
||||
/// - Uses client-provided `timeout_ms` if available, else defaults to 20
|
||||
/// seconds
|
||||
pub(crate) async fn get_content_legacy_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_content::v3::Request>,
|
||||
) -> Result<get_content::v3::Response> {
|
||||
let mxc = Mxc {
|
||||
server_name: &body.server_name,
|
||||
media_id: &body.media_id,
|
||||
};
|
||||
|
||||
match services.media.get(&mxc).await? {
|
||||
| Some(FileMeta {
|
||||
content,
|
||||
content_type,
|
||||
content_disposition,
|
||||
}) => {
|
||||
let content_disposition = make_content_disposition(
|
||||
content_disposition.as_ref(),
|
||||
content_type.as_deref(),
|
||||
None,
|
||||
);
|
||||
|
||||
Ok(assign!(
|
||||
get_content::v3::Response::new(
|
||||
content.expect("entire file contents"),
|
||||
content_type.unwrap_or_default(),
|
||||
content_disposition,
|
||||
),
|
||||
{
|
||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||
}
|
||||
))
|
||||
},
|
||||
| _ =>
|
||||
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
||||
let response = services
|
||||
.media
|
||||
.fetch_remote_content_legacy(&mxc, body.allow_redirect, body.timeout_ms)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
err!(Request(NotFound(debug_warn!(%mxc, "Fetching media failed: {e:?}"))))
|
||||
})?;
|
||||
|
||||
let content_disposition = make_content_disposition(
|
||||
response.content_disposition.as_ref(),
|
||||
response.content_type.as_deref(),
|
||||
None,
|
||||
);
|
||||
|
||||
Ok(assign!(
|
||||
get_content::v3::Response::new(
|
||||
response.file,
|
||||
response.content_type.unwrap_or_default(),
|
||||
content_disposition,
|
||||
),
|
||||
{
|
||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||
}
|
||||
))
|
||||
} else {
|
||||
Err!(Request(NotFound("Media not found.")))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/media/v1/download/{serverName}/{mediaId}`
|
||||
///
|
||||
/// Load media from our server or over federation.
|
||||
///
|
||||
/// This is a legacy endpoint ("/v1/") that some very old homeservers and/or
|
||||
/// clients may call. conduwuit adds these for compatibility purposes.
|
||||
/// See <https://spec.matrix.org/legacy/legacy/#id27>
|
||||
///
|
||||
/// - Only allows federation if `allow_remote` is true
|
||||
/// - Only redirects if `allow_redirect` is true
|
||||
/// - Uses client-provided `timeout_ms` if available, else defaults to 20
|
||||
/// seconds
|
||||
pub(crate) async fn get_content_legacy_legacy_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_content::v3::Request>,
|
||||
) -> Result<RumaResponse<get_content::v3::Response>> {
|
||||
get_content_legacy_route(State(services), body)
|
||||
.await
|
||||
.map(RumaResponse)
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/media/v3/download/{serverName}/{mediaId}/{fileName}`
|
||||
///
|
||||
/// Load media from our server or over federation, permitting desired filename.
|
||||
///
|
||||
/// - Only allows federation if `allow_remote` is true
|
||||
/// - Only redirects if `allow_redirect` is true
|
||||
/// - Uses client-provided `timeout_ms` if available, else defaults to 20
|
||||
/// seconds
|
||||
pub(crate) async fn get_content_as_filename_legacy_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_content_as_filename::v3::Request>,
|
||||
) -> Result<get_content_as_filename::v3::Response> {
|
||||
let mxc = Mxc {
|
||||
server_name: &body.server_name,
|
||||
media_id: &body.media_id,
|
||||
};
|
||||
|
||||
match services.media.get(&mxc).await? {
|
||||
| Some(FileMeta {
|
||||
content,
|
||||
content_type,
|
||||
content_disposition,
|
||||
}) => {
|
||||
let content_disposition = make_content_disposition(
|
||||
content_disposition.as_ref(),
|
||||
content_type.as_deref(),
|
||||
Some(&body.filename),
|
||||
);
|
||||
|
||||
Ok(assign!(get_content_as_filename::v3::Response::new(
|
||||
content.expect("entire file contents"),
|
||||
content_type.unwrap_or_default(),
|
||||
content_disposition,
|
||||
),
|
||||
{
|
||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||
}
|
||||
))
|
||||
},
|
||||
| _ =>
|
||||
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
||||
let response = services
|
||||
.media
|
||||
.fetch_remote_content_legacy(&mxc, body.allow_redirect, body.timeout_ms)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
err!(Request(NotFound(debug_warn!(%mxc, "Fetching media failed: {e:?}"))))
|
||||
})?;
|
||||
|
||||
let content_disposition = make_content_disposition(
|
||||
response.content_disposition.as_ref(),
|
||||
response.content_type.as_deref(),
|
||||
None,
|
||||
);
|
||||
|
||||
Ok(assign!(
|
||||
get_content_as_filename::v3::Response::new(
|
||||
response.file,
|
||||
response.content_type.unwrap_or_default(),
|
||||
content_disposition,
|
||||
),
|
||||
{
|
||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.into()),
|
||||
}
|
||||
))
|
||||
} else {
|
||||
Err!(Request(NotFound("Media not found.")))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/media/v1/download/{serverName}/{mediaId}/{fileName}`
|
||||
///
|
||||
/// Load media from our server or over federation, permitting desired filename.
|
||||
///
|
||||
/// This is a legacy endpoint ("/v1/") that some very old homeservers and/or
|
||||
/// clients may call. conduwuit adds these for compatibility purposes.
|
||||
/// See <https://spec.matrix.org/legacy/legacy/#id27>
|
||||
///
|
||||
/// - Only allows federation if `allow_remote` is true
|
||||
/// - Only redirects if `allow_redirect` is true
|
||||
/// - Uses client-provided `timeout_ms` if available, else defaults to 20
|
||||
/// seconds
|
||||
pub(crate) async fn get_content_as_filename_legacy_legacy_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_content_as_filename::v3::Request>,
|
||||
) -> Result<RumaResponse<get_content_as_filename::v3::Response>> {
|
||||
get_content_as_filename_legacy_route(State(services), body)
|
||||
.await
|
||||
.map(RumaResponse)
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/media/v3/thumbnail/{serverName}/{mediaId}`
|
||||
///
|
||||
/// Load media thumbnail from our server or over federation.
|
||||
///
|
||||
/// - Only allows federation if `allow_remote` is true
|
||||
/// - Only redirects if `allow_redirect` is true
|
||||
/// - Uses client-provided `timeout_ms` if available, else defaults to 20
|
||||
/// seconds
|
||||
pub(crate) async fn get_content_thumbnail_legacy_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_content_thumbnail::v3::Request>,
|
||||
) -> Result<get_content_thumbnail::v3::Response> {
|
||||
let mxc = Mxc {
|
||||
server_name: &body.server_name,
|
||||
media_id: &body.media_id,
|
||||
};
|
||||
|
||||
let dim = Dim::from_ruma(body.width, body.height, body.method.clone())?;
|
||||
match services.media.get_thumbnail(&mxc, &dim).await? {
|
||||
| Some(FileMeta {
|
||||
content,
|
||||
content_type,
|
||||
content_disposition,
|
||||
}) => {
|
||||
let content_disposition = make_content_disposition(
|
||||
content_disposition.as_ref(),
|
||||
content_type.as_deref(),
|
||||
None,
|
||||
);
|
||||
|
||||
Ok(assign!(
|
||||
get_content_thumbnail::v3::Response::new(
|
||||
content.expect("entire file contents"),
|
||||
content_type.unwrap_or_default(),
|
||||
content_disposition,
|
||||
),
|
||||
{
|
||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()),
|
||||
}
|
||||
))
|
||||
},
|
||||
| _ =>
|
||||
if !services.globals.server_is_ours(&body.server_name) && body.allow_remote {
|
||||
let response = services
|
||||
.media
|
||||
.fetch_remote_thumbnail_legacy(&body)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
err!(Request(NotFound(debug_warn!(%mxc, "Fetching media failed: {e:?}"))))
|
||||
})?;
|
||||
|
||||
let content_disposition = make_content_disposition(
|
||||
response.content_disposition.as_ref(),
|
||||
response.content_type.as_deref(),
|
||||
None,
|
||||
);
|
||||
|
||||
Ok(assign!(
|
||||
get_content_thumbnail::v3::Response::new(
|
||||
response.file,
|
||||
response.content_type.unwrap_or_default(),
|
||||
content_disposition,
|
||||
),
|
||||
{
|
||||
cross_origin_resource_policy: Some(CORP_CROSS_ORIGIN.to_owned()),
|
||||
}
|
||||
))
|
||||
} else {
|
||||
Err!(Request(NotFound("Media not found.")))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/media/v1/thumbnail/{serverName}/{mediaId}`
|
||||
///
|
||||
/// Load media thumbnail from our server or over federation.
|
||||
///
|
||||
/// This is a legacy endpoint ("/v1/") that some very old homeservers and/or
|
||||
/// clients may call. conduwuit adds these for compatibility purposes.
|
||||
/// See <https://spec.matrix.org/legacy/legacy/#id27>
|
||||
///
|
||||
/// - Only allows federation if `allow_remote` is true
|
||||
/// - Only redirects if `allow_redirect` is true
|
||||
/// - Uses client-provided `timeout_ms` if available, else defaults to 20
|
||||
/// seconds
|
||||
pub(crate) async fn get_content_thumbnail_legacy_legacy_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_content_thumbnail::v3::Request>,
|
||||
) -> Result<RumaResponse<get_content_thumbnail::v3::Response>> {
|
||||
get_content_thumbnail_legacy_route(State(services), body)
|
||||
.await
|
||||
.map(RumaResponse)
|
||||
}
|
||||
@@ -12,7 +12,6 @@ pub(super) mod directory;
|
||||
pub(super) mod filter;
|
||||
pub(super) mod keys;
|
||||
pub(super) mod media;
|
||||
pub(super) mod media_legacy;
|
||||
pub(super) mod membership;
|
||||
pub(super) mod message;
|
||||
pub(super) mod mutual_rooms;
|
||||
@@ -57,7 +56,6 @@ pub(super) use directory::*;
|
||||
pub(super) use filter::*;
|
||||
pub(super) use keys::*;
|
||||
pub(super) use media::*;
|
||||
pub(super) use media_legacy::*;
|
||||
pub(super) use membership::*;
|
||||
pub use membership::{leave_all_rooms, leave_room, remote_leave_room};
|
||||
pub(super) use message::*;
|
||||
|
||||
@@ -13,8 +13,8 @@ use crate::Ruma;
|
||||
#[tracing::instrument(skip_all, name = "mutual_rooms", level = "info")]
|
||||
pub(crate) async fn get_mutual_rooms_unstable_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_mutual_rooms::unstable::Request>,
|
||||
) -> Result<get_mutual_rooms::unstable::Response> {
|
||||
body: Ruma<get_mutual_rooms::msc2666::Request>,
|
||||
) -> Result<get_mutual_rooms::msc2666::Response> {
|
||||
let sender_user = body.identity.expect_sender_user()?;
|
||||
|
||||
if sender_user == body.user_id {
|
||||
@@ -28,7 +28,7 @@ pub(crate) async fn get_mutual_rooms_unstable_route(
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
Ok(get_mutual_rooms::unstable::Response::new(mutual_rooms))
|
||||
Ok(get_mutual_rooms::msc2666::Response::new(mutual_rooms))
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/client/v1/mutual_rooms`
|
||||
|
||||
@@ -121,7 +121,10 @@ pub(crate) async fn create_room_route(
|
||||
// ID exactly matches this, and abort if it doesn't. Otherwise, we use it
|
||||
// as the room ID itself.
|
||||
let expect_room_id = {
|
||||
let body_ref = body.json_body.as_ref().unwrap();
|
||||
let body_ref = body
|
||||
.json_body
|
||||
.as_ref()
|
||||
.ok_or_else(|| err!(Request(BadJson("Invalid JSON body"))))?;
|
||||
if let Some(CanonicalJsonValue::String(room_id)) = body_ref
|
||||
.get("fi.mau.room_id")
|
||||
.or_else(|| body_ref.get("room_id"))
|
||||
@@ -302,7 +305,10 @@ pub(crate) async fn create_room_route(
|
||||
// Allow requesters to override the `origin_server_ts` to customize room ids
|
||||
// from v12 onwards
|
||||
let custom_origin_server_ts = {
|
||||
let body_ref = body.json_body.as_ref().unwrap();
|
||||
let body_ref = body
|
||||
.json_body
|
||||
.as_ref()
|
||||
.ok_or_else(|| err!(Request(BadJson("Invalid JSON body"))))?;
|
||||
body_ref
|
||||
.get("origin_server_ts")
|
||||
.or_else(|| body_ref.get("fi.mau.origin_server_ts"))
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
use axum::extract::State;
|
||||
use conduwuit::{Err, Event, Result, debug_warn, err};
|
||||
use ruma::api::client::room::get_room_event;
|
||||
use axum::extract::{Query, State};
|
||||
use conduwuit::{
|
||||
Err, Error, Event, PduEvent, Result, config::experiments::ToggledExperiment, debug_warn, err,
|
||||
};
|
||||
use futures::TryFutureExt;
|
||||
use http::StatusCode;
|
||||
use ruma::{
|
||||
UserId,
|
||||
api::{client::room::get_room_event, error::ErrorKind},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{Ruma, client::is_ignored_pdu};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub(crate) struct Msc2815Params {
|
||||
#[serde(rename = "fi.mau.msc2815.include_unredacted_content", default)]
|
||||
include_unredacted_content: Option<bool>,
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/event/{eventId}`
|
||||
///
|
||||
/// Gets a single event.
|
||||
pub(crate) async fn get_room_event_route(
|
||||
State(ref services): State<crate::State>,
|
||||
Query(params): Query<Msc2815Params>,
|
||||
ref body: Ruma<get_room_event::v3::Request>,
|
||||
) -> Result<get_room_event::v3::Response> {
|
||||
let sender_user = body.identity.expect_sender_user()?;
|
||||
@@ -54,6 +70,13 @@ pub(crate) async fn get_room_event_route(
|
||||
return Err!(Request(Forbidden("You don't have permission to view this event.")));
|
||||
}
|
||||
|
||||
if services.config.experiments.msc2815.is_enabled()
|
||||
&& params.include_unredacted_content.unwrap_or(false)
|
||||
&& event.is_redacted()
|
||||
{
|
||||
unredact(services, sender_user, &mut event).await?;
|
||||
}
|
||||
|
||||
if let Err(e) = services
|
||||
.rooms
|
||||
.pdu_metadata
|
||||
@@ -72,3 +95,59 @@ pub(crate) async fn get_room_event_route(
|
||||
|
||||
Ok(get_room_event::v3::Response::new(event.into_format()))
|
||||
}
|
||||
|
||||
async fn unredact(services: &crate::State, sender_user: &UserId, event: &mut PduEvent) -> Result {
|
||||
if !services.users.is_admin(sender_user).await {
|
||||
let power_levels = services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.get_room_power_levels(&event.room_id_or_hash())
|
||||
.await;
|
||||
|
||||
if power_levels.for_user(sender_user) < power_levels.redact {
|
||||
return Err!(Request(Forbidden(
|
||||
"You don't have permission to view redacted content in this room."
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
let content = services
|
||||
.rooms
|
||||
.timeline
|
||||
.get_pdu_id(event.event_id())
|
||||
.and_then(async |pdu_id| {
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
.get_unredacted_content(&pdu_id)
|
||||
.await
|
||||
})
|
||||
.await;
|
||||
|
||||
let Ok(content) = content else {
|
||||
// CustomErrorKind has private fields; only serde can build one.
|
||||
let keep_ms = services
|
||||
.config
|
||||
.experiments
|
||||
.msc2815
|
||||
.expect("msc2815 config is disabled but unredact() attempted to access it anyway")
|
||||
.unredacted_content_max_age_secs
|
||||
.saturating_mul(1000);
|
||||
|
||||
let kind = serde_json::from_value::<ErrorKind>(json!({
|
||||
"errcode": "FI.MAU.MSC2815_UNREDACTED_CONTENT_DELETED",
|
||||
"fi.mau.msc2815.content_keep_ms": keep_ms,
|
||||
}))
|
||||
.expect("errcode is a valid custom error kind");
|
||||
|
||||
return Err(Error::Request(
|
||||
kind,
|
||||
"The unredacted content of this event is not available.".into(),
|
||||
StatusCode::NOT_FOUND,
|
||||
));
|
||||
};
|
||||
|
||||
event.content = content;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -15,11 +15,11 @@ use crate::{Ruma, router::ClientIdentity};
|
||||
#[tracing::instrument(skip_all, name = "stripped_state", level = "info")]
|
||||
pub(crate) async fn get_stripped_state_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_stripped_state::unstable::Request>,
|
||||
) -> Result<get_stripped_state::unstable::Response> {
|
||||
body: Ruma<get_stripped_state::msc4560::Request>,
|
||||
) -> Result<get_stripped_state::msc4560::Response> {
|
||||
let user_id = body.identity.as_ref().and_then(ClientIdentity::sender_user);
|
||||
|
||||
if body.via.len() > get_stripped_state::unstable::MAX_VIAS {
|
||||
if body.via.len() > get_stripped_state::msc4560::MAX_VIAS {
|
||||
return Err!(Request(TooLarge("Too many vias, please be less indecisive.")));
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ pub(crate) async fn get_stripped_state_route(
|
||||
via,
|
||||
RoomStrippedState { state, num_joined_members, .. },
|
||||
)) => Ok(
|
||||
assign!(get_stripped_state::unstable::Response::new(via), { state, num_joined_members }),
|
||||
assign!(get_stripped_state::msc4560::Response::new(via), { state, num_joined_members }),
|
||||
),
|
||||
| Accessibility::Inaccessible => {
|
||||
Err!(Request(Forbidden("You may not request this room's stripped state.")))
|
||||
|
||||
@@ -39,7 +39,7 @@ pub(crate) async fn get_room_summary(
|
||||
Err!(Request(Forbidden("You may not preview this room."), FORBIDDEN))
|
||||
},
|
||||
| Accessibility::NotFound => {
|
||||
Err!(Request(Forbidden("This room does not exist."), FORBIDDEN))
|
||||
Err!(Request(NotFound("This room does not exist.")))
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -95,12 +95,7 @@ pub(crate) async fn send_message_event_route(
|
||||
PartialPdu {
|
||||
event_type: body.event_type.clone().into(),
|
||||
content,
|
||||
sticky: services
|
||||
.config
|
||||
.allow_sticky_events
|
||||
.then_some(body.sticky_duration_ms)
|
||||
.flatten()
|
||||
.map(sticky::object),
|
||||
sticky: body.sticky_duration_ms.map(sticky::object),
|
||||
unsigned: Some(unsigned),
|
||||
timestamp: if body.identity.is_appservice()
|
||||
|| services.admin.user_is_admin(sender_user).await
|
||||
|
||||
@@ -64,7 +64,7 @@ pub(super) async fn load_joined_room(
|
||||
services: &Services,
|
||||
sync_context: SyncContext<'_>,
|
||||
ref room_id: OwnedRoomId,
|
||||
) -> Result<(JoinedRoom, DeviceListUpdates)> {
|
||||
) -> Result<JoinedRoom> {
|
||||
/*
|
||||
Building a sync response involves many steps which all depend on each other.
|
||||
To parallelize the process as much as possible, each step is divided into its own function,
|
||||
@@ -80,7 +80,6 @@ pub(super) async fn load_joined_room(
|
||||
sticky,
|
||||
summary,
|
||||
notification_counts,
|
||||
device_list_updates,
|
||||
},
|
||||
) = try_join3(
|
||||
build_account_data(services, sync_context, room_id),
|
||||
@@ -117,7 +116,7 @@ pub(super) async fn load_joined_room(
|
||||
unread_thread_notifications: BTreeMap::new(),
|
||||
});
|
||||
|
||||
Ok((joined_room, device_list_updates))
|
||||
Ok(joined_room)
|
||||
}
|
||||
|
||||
/// Collect changes to the syncing user's account data events.
|
||||
@@ -263,7 +262,6 @@ struct StateAndTimeline {
|
||||
sticky: Sticky,
|
||||
summary: Option<RoomSummary>,
|
||||
notification_counts: Option<UnreadNotificationsCount>,
|
||||
device_list_updates: DeviceListUpdates,
|
||||
}
|
||||
|
||||
async fn build_sticky_events(
|
||||
@@ -273,10 +271,6 @@ async fn build_sticky_events(
|
||||
timeline: &TimelinePdus,
|
||||
joined_since_last_sync: bool,
|
||||
) -> Sticky {
|
||||
if !services.config.allow_sticky_events {
|
||||
return Sticky::new();
|
||||
}
|
||||
|
||||
let SyncContext {
|
||||
syncing_user,
|
||||
last_sync_end_count,
|
||||
@@ -381,24 +375,14 @@ async fn build_state_and_timeline(
|
||||
debug_warn!("timeline for newly joined room is empty");
|
||||
}
|
||||
|
||||
let (summary, device_list_updates) = try_join(
|
||||
build_room_summary(
|
||||
services,
|
||||
sync_context,
|
||||
room_id,
|
||||
shortstatehashes,
|
||||
&timeline,
|
||||
&state_events,
|
||||
joined_since_last_sync,
|
||||
),
|
||||
build_device_list_updates(
|
||||
services,
|
||||
sync_context,
|
||||
room_id,
|
||||
shortstatehashes,
|
||||
&state_events,
|
||||
joined_since_last_sync,
|
||||
),
|
||||
let summary = build_room_summary(
|
||||
services,
|
||||
sync_context,
|
||||
room_id,
|
||||
shortstatehashes,
|
||||
&timeline,
|
||||
&state_events,
|
||||
joined_since_last_sync,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -434,7 +418,6 @@ async fn build_state_and_timeline(
|
||||
sticky,
|
||||
summary,
|
||||
notification_counts,
|
||||
device_list_updates,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -858,35 +841,34 @@ async fn build_heroes(
|
||||
.await
|
||||
}
|
||||
|
||||
/// Collect updates to users' device lists for E2EE.
|
||||
#[tracing::instrument(level = "debug", skip_all)]
|
||||
async fn build_device_list_updates(
|
||||
/// Collect updates to users' device lists for E2EE in a joined room.
|
||||
#[tracing::instrument(level = "debug", skip_all, fields(%room_id))]
|
||||
pub(super) async fn load_device_list_updates(
|
||||
services: &Services,
|
||||
SyncContext {
|
||||
sync_context: SyncContext<'_>,
|
||||
room_id: &RoomId,
|
||||
) -> Result<DeviceListUpdates> {
|
||||
let SyncContext {
|
||||
syncing_user,
|
||||
last_sync_end_count,
|
||||
current_count,
|
||||
..
|
||||
}: SyncContext<'_>,
|
||||
room_id: &RoomId,
|
||||
ShortStateHashes { current_shortstatehash, .. }: ShortStateHashes,
|
||||
state_events: &Vec<PduEvent>,
|
||||
joined_since_last_sync: bool,
|
||||
) -> Result<DeviceListUpdates> {
|
||||
let is_encrypted_room = services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.state_get(current_shortstatehash, &StateEventType::RoomEncryption, "")
|
||||
.is_ok();
|
||||
} = sync_context;
|
||||
|
||||
let mut device_list_updates = DeviceListUpdates::new();
|
||||
|
||||
// initial syncs don't include device updates, and rooms which aren't
|
||||
// encrypted don't affect them, so return early in either of those cases
|
||||
if last_sync_end_count.is_none() || !(is_encrypted_room.await) {
|
||||
return Ok(DeviceListUpdates::new());
|
||||
if last_sync_end_count.is_none()
|
||||
|| !services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.is_encrypted_room(room_id)
|
||||
.await
|
||||
{
|
||||
return Ok(device_list_updates);
|
||||
}
|
||||
|
||||
let mut device_list_updates = DeviceListUpdates::new();
|
||||
|
||||
// add users with changed keys to the `changed` list
|
||||
services
|
||||
.users
|
||||
@@ -897,19 +879,56 @@ async fn build_device_list_updates(
|
||||
})
|
||||
.await;
|
||||
|
||||
// add users who now share encrypted rooms to `changed` and
|
||||
// users who no longer share encrypted rooms to `left`
|
||||
for state_event in state_events {
|
||||
if state_event.kind == RoomMember {
|
||||
let Some(content): Option<RoomMemberEventContent> = state_event.get_content().ok()
|
||||
let shortstatehashes = fetch_shortstatehashes(services, sync_context, room_id).await?;
|
||||
let ShortStateHashes {
|
||||
current_shortstatehash,
|
||||
last_sync_end_shortstatehash,
|
||||
} = shortstatehashes;
|
||||
|
||||
if check_joined_since_last_sync(services, shortstatehashes, sync_context).await? {
|
||||
// the syncing user now shares an encrypted room with every member
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.room_members(room_id)
|
||||
.ready_for_each(|user_id| {
|
||||
device_list_updates.changed.insert(user_id);
|
||||
})
|
||||
.await;
|
||||
} else if let Some(last_sync_end_shortstatehash) = last_sync_end_shortstatehash
|
||||
&& last_sync_end_shortstatehash != current_shortstatehash
|
||||
{
|
||||
// add users who now share encrypted rooms to `changed` and
|
||||
// users who no longer share encrypted rooms to `left`
|
||||
let state_added = services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.state_added((last_sync_end_shortstatehash, current_shortstatehash))
|
||||
.await?;
|
||||
|
||||
for (shortstatekey, _) in state_added {
|
||||
let Ok((StateEventType::RoomMember, state_key)) = services
|
||||
.rooms
|
||||
.short
|
||||
.get_statekey_from_short(shortstatekey)
|
||||
.await
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let Some(user_id): Option<OwnedUserId> = state_event
|
||||
.state_key
|
||||
.as_ref()
|
||||
.and_then(|key| key.parse().ok())
|
||||
let Ok(user_id) = OwnedUserId::try_from(state_key.as_str()) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let Ok(content): Result<RoomMemberEventContent> = services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.state_get_content(
|
||||
current_shortstatehash,
|
||||
&StateEventType::RoomMember,
|
||||
user_id.as_str(),
|
||||
)
|
||||
.await
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
@@ -925,7 +944,7 @@ async fn build_device_list_updates(
|
||||
| Leave if !shares_encrypted_room => {
|
||||
device_list_updates.left.insert(user_id);
|
||||
},
|
||||
| Join if joined_since_last_sync || shares_encrypted_room => {
|
||||
| Join if shares_encrypted_room => {
|
||||
device_list_updates.changed.insert(user_id);
|
||||
},
|
||||
| _ => (),
|
||||
|
||||
+117
-21
@@ -3,7 +3,6 @@ mod left;
|
||||
mod state;
|
||||
|
||||
use std::{
|
||||
cmp::{self},
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
time::Duration,
|
||||
};
|
||||
@@ -21,7 +20,7 @@ use futures::{FutureExt, StreamExt, TryFutureExt, future::OptionFuture};
|
||||
use ruma::{
|
||||
DeviceId, OwnedUserId, RoomId, UserId,
|
||||
api::client::{
|
||||
filter::FilterDefinition,
|
||||
filter::{self, FilterDefinition, RoomFilter},
|
||||
sync::sync_events::{
|
||||
self, DeviceLists,
|
||||
v3::{
|
||||
@@ -39,13 +38,17 @@ use service::{
|
||||
account_data::AnyRawAccountDataEvent,
|
||||
rooms::lazy_loading::{self, MemberSet, Options as _},
|
||||
};
|
||||
use wildmatch::WildMatch;
|
||||
|
||||
use super::{load_timeline, share_encrypted_room};
|
||||
use crate::{
|
||||
Ruma,
|
||||
client::{
|
||||
is_ignored_invite,
|
||||
sync::v3::{joined::load_joined_room, left::load_left_room},
|
||||
sync::v3::{
|
||||
joined::{load_device_list_updates, load_joined_room},
|
||||
left::load_left_room,
|
||||
},
|
||||
},
|
||||
client_ip::ClientIp,
|
||||
};
|
||||
@@ -203,7 +206,12 @@ pub(crate) async fn sync_events_route(
|
||||
|
||||
let mut wake_receiver = services.sync.subscribe_to_wake(sender_user);
|
||||
let response = build_sync_events(&services, &body).await?;
|
||||
if body.body.full_state
|
||||
|
||||
let timeout_duration = body.body.timeout.unwrap_or_default();
|
||||
// If the timeout is zero, request has full_state=true, or there's
|
||||
// meaningful data to return, do so immediately.
|
||||
if timeout_duration.is_zero()
|
||||
|| body.body.full_state
|
||||
|| !(response.rooms.is_empty()
|
||||
&& response.presence.is_empty()
|
||||
&& response.account_data.is_empty()
|
||||
@@ -213,11 +221,15 @@ pub(crate) async fn sync_events_route(
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
// Hang a few seconds so requests are not spammed
|
||||
// Stop hanging if new info arrives
|
||||
let default = Duration::from_secs(30);
|
||||
let duration = cmp::min(body.body.timeout.unwrap_or(default), default);
|
||||
_ = tokio::time::timeout(duration, wake_receiver.changed()).await;
|
||||
// Otherwise, wait for a wake signal to rebuild changes. Cap timeout at 30
|
||||
// seconds (this isn't specced, but a reasonable cap since most clients have
|
||||
// a 30-second polling interval).
|
||||
let duration = timeout_duration.min(Duration::from_secs(30));
|
||||
let mut shutdown_signal = services.server.signal.subscribe();
|
||||
tokio::select! {
|
||||
_ = tokio::time::timeout(duration, wake_receiver.changed()) => {},
|
||||
_ = shutdown_signal.recv() => return Err!(Request(Unknown("Server is shutting down"), SERVICE_UNAVAILABLE)),
|
||||
};
|
||||
|
||||
// Retry returning data
|
||||
build_sync_events(&services, &body).await
|
||||
@@ -271,34 +283,47 @@ pub(crate) async fn build_sync_events(
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_joined(syncing_user)
|
||||
.ready_filter(|room_id| room_selected(&filter.room, room_id))
|
||||
.broad_filter_map(|room_id| async {
|
||||
let joined_room = load_joined_room(services, context, room_id.clone()).await;
|
||||
|
||||
match joined_room {
|
||||
| Ok((room, updates)) => Some((room_id, room, updates)),
|
||||
| Ok(room) => Some((room_id, room)),
|
||||
| Err(err) => {
|
||||
error!(?err, %room_id, "error loading joined room");
|
||||
None
|
||||
},
|
||||
}
|
||||
})
|
||||
.ready_fold(
|
||||
(BTreeMap::new(), DeviceListUpdates::new()),
|
||||
|(mut joined_rooms, mut all_updates), (room_id, joined_room, updates)| {
|
||||
all_updates.merge(updates);
|
||||
.ready_fold(BTreeMap::new(), |mut joined_rooms, (room_id, joined_room)| {
|
||||
if !joined_room.is_empty() {
|
||||
joined_rooms.insert(room_id, joined_room);
|
||||
}
|
||||
|
||||
if !joined_room.is_empty() {
|
||||
joined_rooms.insert(room_id, joined_room);
|
||||
}
|
||||
joined_rooms
|
||||
});
|
||||
|
||||
(joined_rooms, all_updates)
|
||||
},
|
||||
);
|
||||
// a filtered out room still contributes its device list updates
|
||||
let device_list_updates = services
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_joined(syncing_user)
|
||||
.broad_filter_map(|room_id| async move {
|
||||
load_device_list_updates(services, context, &room_id)
|
||||
.await
|
||||
.inspect_err(|err| error!(?err, %room_id, "error loading device list updates"))
|
||||
.ok()
|
||||
})
|
||||
.ready_fold(DeviceListUpdates::new(), |mut all_updates, updates| {
|
||||
all_updates.merge(updates);
|
||||
all_updates
|
||||
});
|
||||
|
||||
let left_rooms = services
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_left(syncing_user)
|
||||
.ready_filter(|(room_id, _)| room_selected(&filter.room, room_id))
|
||||
.broad_filter_map(|(room_id, leave_pdu)| async {
|
||||
let left_room = load_left_room(services, context, room_id.clone(), leave_pdu).await;
|
||||
|
||||
@@ -317,6 +342,7 @@ pub(crate) async fn build_sync_events(
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_invited(syncing_user)
|
||||
.ready_filter(|(room_id, _)| room_selected(&filter.room, room_id))
|
||||
.wide_filter_map(async |(room_id, invite_state)| {
|
||||
if is_ignored_invite(services, syncing_user, &room_id).await {
|
||||
None
|
||||
@@ -347,6 +373,7 @@ pub(crate) async fn build_sync_events(
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_knocked(syncing_user)
|
||||
.ready_filter(|(room_id, _)| room_selected(&filter.room, room_id))
|
||||
.fold_default(|mut knocked_rooms: BTreeMap<_, _>, (room_id, knock_state)| async move {
|
||||
let knock_count = services
|
||||
.rooms
|
||||
@@ -376,6 +403,13 @@ pub(crate) async fn build_sync_events(
|
||||
.account_data
|
||||
.changes_since(None, syncing_user, last_sync_end_count, Some(current_count))
|
||||
.ready_filter_map(|e| extract_variant!(e, AnyRawAccountDataEvent::Global))
|
||||
.ready_filter(|event| {
|
||||
event
|
||||
.get_field::<String>("type")
|
||||
.ok()
|
||||
.flatten()
|
||||
.is_some_and(|event_type| type_selected(&filter.account_data, &event_type))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let to_device_events = services
|
||||
@@ -404,7 +438,8 @@ pub(crate) async fn build_sync_events(
|
||||
.list_unused_fallback_key_types(syncing_user, syncing_device);
|
||||
|
||||
let (
|
||||
(joined_rooms, mut device_list_updates),
|
||||
joined_rooms,
|
||||
mut device_list_updates,
|
||||
left_rooms,
|
||||
invited_rooms,
|
||||
knocked_rooms,
|
||||
@@ -417,6 +452,7 @@ pub(crate) async fn build_sync_events(
|
||||
) = async {
|
||||
futures::join!(
|
||||
joined_rooms,
|
||||
device_list_updates,
|
||||
left_rooms,
|
||||
invited_rooms,
|
||||
knocked_rooms,
|
||||
@@ -465,6 +501,24 @@ pub(crate) async fn build_sync_events(
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
fn room_selected(filter: &RoomFilter, room_id: &RoomId) -> bool {
|
||||
!filter.not_rooms.iter().any(|not_room| not_room == room_id)
|
||||
&& filter
|
||||
.rooms
|
||||
.as_ref()
|
||||
.is_none_or(|rooms| rooms.iter().any(|room| room == room_id))
|
||||
}
|
||||
|
||||
fn type_selected(filter: &filter::Filter, event_type: &str) -> bool {
|
||||
let matches = |pattern: &String| WildMatch::new(pattern).matches(event_type);
|
||||
|
||||
!filter.not_types.iter().any(matches)
|
||||
&& filter
|
||||
.types
|
||||
.as_ref()
|
||||
.is_none_or(|types| types.iter().any(matches))
|
||||
}
|
||||
|
||||
#[tracing::instrument(name = "presence", level = "debug", skip_all)]
|
||||
async fn process_presence_updates(
|
||||
services: &Services,
|
||||
@@ -528,3 +582,45 @@ async fn prepare_lazily_loaded_members(
|
||||
|
||||
lazily_loaded_members
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ruma::{owned_room_id, room_id};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn rooms_filter_selects_rooms() {
|
||||
let room_id = room_id!("!a:example.com");
|
||||
let mut filter = RoomFilter::default();
|
||||
assert!(room_selected(&filter, room_id));
|
||||
|
||||
filter.rooms = Some(Vec::new());
|
||||
assert!(!room_selected(&filter, room_id));
|
||||
|
||||
filter.rooms = Some(vec![room_id.to_owned()]);
|
||||
assert!(room_selected(&filter, room_id));
|
||||
|
||||
filter.not_rooms = vec![owned_room_id!("!a:example.com")];
|
||||
assert!(!room_selected(&filter, room_id));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn types_filter_selects_account_data() {
|
||||
let mut filter = filter::Filter::default();
|
||||
assert!(type_selected(&filter, "m.direct"));
|
||||
|
||||
filter.types = Some(Vec::new());
|
||||
assert!(!type_selected(&filter, "m.direct"));
|
||||
|
||||
filter.types = Some(vec!["m.direct".to_owned()]);
|
||||
assert!(type_selected(&filter, "m.direct"));
|
||||
|
||||
filter.types = Some(vec!["m.*".to_owned()]);
|
||||
assert!(type_selected(&filter, "m.direct"));
|
||||
assert!(!type_selected(&filter, "im.ponies.user_emotes"));
|
||||
|
||||
filter.not_types = vec!["m.direct".to_owned()];
|
||||
assert!(!type_selected(&filter, "m.direct"));
|
||||
}
|
||||
}
|
||||
+127
-129
@@ -24,7 +24,7 @@ use conduwuit::{
|
||||
use conduwuit_service::{
|
||||
Services,
|
||||
rooms::read_receipt::pack_receipts,
|
||||
sync::{SnakeConnectionsKey, into_snake_key},
|
||||
sync::{SnakeConnectionsKey, StickyDelivered, into_snake_key},
|
||||
};
|
||||
use futures::{
|
||||
FutureExt, StreamExt, TryFutureExt,
|
||||
@@ -34,7 +34,7 @@ use futures::{
|
||||
use ruma::{
|
||||
DeviceId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, RoomId, UInt, UserId,
|
||||
api::client::sync::sync_events::{
|
||||
self, DeviceLists, UnreadNotificationsCount, v5::request::ExtensionRoomConfig,
|
||||
self, DeviceLists, UnreadNotificationsCount, msc4186::request::ExtensionRoomConfig,
|
||||
},
|
||||
assign,
|
||||
directory::RoomTypeFilter,
|
||||
@@ -63,7 +63,7 @@ use crate::{
|
||||
client_ip::ClientIp,
|
||||
};
|
||||
|
||||
type SyncInfo<'a> = (&'a UserId, &'a DeviceId, u64, &'a sync_events::v5::Request);
|
||||
type SyncInfo<'a> = (&'a UserId, &'a DeviceId, u64, &'a sync_events::msc4186::Request);
|
||||
type TodoRooms = BTreeMap<OwnedRoomId, (BTreeSet<TypeStateKey>, usize, u64)>;
|
||||
type KnownRooms = BTreeMap<String, BTreeMap<OwnedRoomId, u64>>;
|
||||
type KnownRoomUpdates = BTreeMap<String, BTreeSet<OwnedRoomId>>;
|
||||
@@ -86,8 +86,9 @@ fn num_live_events<'a>(
|
||||
}
|
||||
|
||||
struct SyncCollection {
|
||||
response: sync_events::v5::Response,
|
||||
response: sync_events::msc4186::Response,
|
||||
known_room_updates: KnownRoomUpdates,
|
||||
sticky_delivered: StickyDelivered,
|
||||
}
|
||||
|
||||
/// `POST /_matrix/client/unstable/org.matrix.simplified_msc3575/sync`
|
||||
@@ -103,8 +104,8 @@ struct SyncCollection {
|
||||
pub(crate) async fn sync_events_v5_route(
|
||||
State(ref services): State<crate::State>,
|
||||
ClientIp(client_ip): ClientIp, // NOTE: Required for updating device metadata
|
||||
body: Ruma<sync_events::v5::Request>,
|
||||
) -> Result<sync_events::v5::Response> {
|
||||
body: Ruma<sync_events::msc4186::Request>,
|
||||
) -> Result<sync_events::msc4186::Response> {
|
||||
let sender_user = body.identity.expect_sender_user()?;
|
||||
let sender_device = body.identity.expect_sender_device()?;
|
||||
|
||||
@@ -142,7 +143,7 @@ pub(crate) async fn sync_events_v5_route(
|
||||
}
|
||||
|
||||
// Get sticky parameters from cache
|
||||
let known_rooms =
|
||||
let (known_rooms, sticky_delivered) =
|
||||
services
|
||||
.sync
|
||||
.update_snake_sync_request_with_cache(&snake_key, globalsince, &mut body);
|
||||
@@ -155,6 +156,7 @@ pub(crate) async fn sync_events_v5_route(
|
||||
&body,
|
||||
globalsince,
|
||||
&known_rooms,
|
||||
&sticky_delivered,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -173,6 +175,7 @@ pub(crate) async fn sync_events_v5_route(
|
||||
&body,
|
||||
globalsince,
|
||||
&known_rooms,
|
||||
&sticky_delivered,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
@@ -202,13 +205,13 @@ async fn collect_sync_response(
|
||||
services: &Services,
|
||||
sender_user: &UserId,
|
||||
sender_device: &DeviceId,
|
||||
body: &sync_events::v5::Request,
|
||||
body: &sync_events::msc4186::Request,
|
||||
globalsince: u64,
|
||||
known_rooms: &KnownRooms,
|
||||
sticky_delivered: &StickyDelivered,
|
||||
) -> Result<SyncCollection> {
|
||||
// Bounds every read below and becomes the `pos` returned to the client.
|
||||
// Zero would be echoed back as a request for an initial sync.
|
||||
let next_batch = services.globals.current_count()?.max(1);
|
||||
let next_batch = services.globals.next_count()?;
|
||||
|
||||
let all_joined_rooms = services
|
||||
.rooms
|
||||
@@ -262,7 +265,6 @@ async fn collect_sync_response(
|
||||
let pos = next_batch.to_string();
|
||||
|
||||
let mut todo_rooms: TodoRooms = BTreeMap::new();
|
||||
let mut sticky_rooms = BTreeSet::new();
|
||||
|
||||
let sync_info: SyncInfo<'_> = (sender_user, sender_device, globalsince, body);
|
||||
|
||||
@@ -277,16 +279,16 @@ async fn collect_sync_response(
|
||||
let (account_data, e2ee, to_device, receipts) =
|
||||
try_join4(account_data, e2ee, to_device, receipts).await?;
|
||||
|
||||
let extensions = assign!(sync_events::v5::response::Extensions::default(), {
|
||||
let extensions = assign!(sync_events::msc4186::response::Extensions::default(), {
|
||||
account_data,
|
||||
e2ee,
|
||||
to_device,
|
||||
receipts,
|
||||
typing: sync_events::v5::response::Typing::default(),
|
||||
sticky_events: sync_events::v5::response::StickyEvents::default(),
|
||||
typing: sync_events::msc4186::response::Typing::default(),
|
||||
sticky_events: sync_events::msc4186::response::StickyEvents::default(),
|
||||
});
|
||||
|
||||
let mut response = assign!(sync_events::v5::Response::new(pos), {
|
||||
let mut response = assign!(sync_events::msc4186::Response::new(pos), {
|
||||
txn_id: body.txn_id.clone(),
|
||||
lists: BTreeMap::new(),
|
||||
rooms: BTreeMap::new(),
|
||||
@@ -319,7 +321,6 @@ async fn collect_sync_response(
|
||||
all_rooms,
|
||||
&direct_rooms,
|
||||
&mut todo_rooms,
|
||||
&mut sticky_rooms,
|
||||
known_rooms,
|
||||
&mut response,
|
||||
)
|
||||
@@ -329,7 +330,6 @@ async fn collect_sync_response(
|
||||
"subscriptions".to_owned(),
|
||||
fetch_subscriptions(services, body, known_rooms, &allowed_rooms, &mut todo_rooms).await,
|
||||
);
|
||||
sticky_rooms.extend(body.room_subscriptions.keys().cloned());
|
||||
|
||||
let mut timeline_event_ids = BTreeSet::new();
|
||||
response.rooms = process_rooms(
|
||||
@@ -346,25 +346,31 @@ async fn collect_sync_response(
|
||||
)
|
||||
.await?;
|
||||
|
||||
response.extensions.sticky_events = collect_sticky_events(
|
||||
let (sticky_events, sticky_delivered) = collect_sticky_events(
|
||||
services,
|
||||
sender_user,
|
||||
body,
|
||||
&sticky_rooms,
|
||||
next_batch,
|
||||
sticky_delivered,
|
||||
&known_room_updates,
|
||||
&joined_room_ids,
|
||||
&todo_rooms,
|
||||
&timeline_event_ids,
|
||||
)
|
||||
.await?;
|
||||
.await;
|
||||
response.extensions.sticky_events = sticky_events;
|
||||
|
||||
response.extensions.typing =
|
||||
collect_typing_events(services, sender_user, body, &todo_rooms, &known_room_updates)
|
||||
.await?;
|
||||
|
||||
Ok(SyncCollection { response, known_room_updates })
|
||||
Ok(SyncCollection {
|
||||
response,
|
||||
known_room_updates,
|
||||
sticky_delivered,
|
||||
})
|
||||
}
|
||||
|
||||
fn response_is_empty(response: &sync_events::v5::Response) -> bool {
|
||||
fn response_is_empty(response: &sync_events::msc4186::Response) -> bool {
|
||||
let no_account_data = response.extensions.account_data.global.is_empty()
|
||||
&& response
|
||||
.extensions
|
||||
@@ -395,7 +401,7 @@ async fn commit_sync_collection(
|
||||
services: &Services,
|
||||
sender_user: &UserId,
|
||||
sender_device: &DeviceId,
|
||||
body: &sync_events::v5::Request,
|
||||
body: &sync_events::msc4186::Request,
|
||||
globalsince: u64,
|
||||
snake_key: &SnakeConnectionsKey,
|
||||
collection: &SyncCollection,
|
||||
@@ -408,9 +414,10 @@ async fn commit_sync_collection(
|
||||
.parse()
|
||||
.expect("generated sync position"),
|
||||
collection.known_room_updates.clone(),
|
||||
collection.sticky_delivered.clone(),
|
||||
);
|
||||
|
||||
if body.extensions.to_device.enabled.unwrap_or(false) {
|
||||
if body.extensions.to_device.enabled {
|
||||
services
|
||||
.users
|
||||
.remove_to_device_events(sender_user, sender_device, globalsince)
|
||||
@@ -420,7 +427,7 @@ async fn commit_sync_collection(
|
||||
|
||||
async fn fetch_subscriptions(
|
||||
services: &Services,
|
||||
body: &sync_events::v5::Request,
|
||||
body: &sync_events::msc4186::Request,
|
||||
known_rooms: &KnownRooms,
|
||||
allowed_rooms: &BTreeSet<OwnedRoomId>,
|
||||
todo_rooms: &mut TodoRooms,
|
||||
@@ -480,15 +487,14 @@ async fn fetch_subscriptions(
|
||||
async fn handle_lists<'a, Rooms, AllRooms>(
|
||||
services: &Services,
|
||||
sender_user: &UserId,
|
||||
body: &sync_events::v5::Request,
|
||||
body: &sync_events::msc4186::Request,
|
||||
all_invited_rooms: Rooms,
|
||||
all_joined_rooms: Rooms,
|
||||
all_rooms: AllRooms,
|
||||
direct_rooms: &HashSet<OwnedRoomId>,
|
||||
todo_rooms: &'a mut TodoRooms,
|
||||
sticky_rooms: &mut BTreeSet<OwnedRoomId>,
|
||||
known_rooms: &'a KnownRooms,
|
||||
response: &'_ mut sync_events::v5::Response,
|
||||
response: &'_ mut sync_events::msc4186::Response,
|
||||
) -> KnownRoomUpdates
|
||||
where
|
||||
Rooms: Iterator<Item = &'a RoomId> + Clone + Send + 'a,
|
||||
@@ -579,7 +585,6 @@ where
|
||||
.await;
|
||||
sort_rooms_by_activity(&mut active_rooms);
|
||||
let active_rooms: Vec<_> = active_rooms.into_iter().map(at!(0)).collect();
|
||||
sticky_rooms.extend(active_rooms.iter().map(|room_id| (*room_id).to_owned()));
|
||||
|
||||
let mut new_known_rooms: BTreeSet<OwnedRoomId> = BTreeSet::new();
|
||||
|
||||
@@ -631,7 +636,7 @@ where
|
||||
}
|
||||
response.lists.insert(
|
||||
list_id.clone(),
|
||||
assign!(sync_events::v5::response::List::default(), {
|
||||
assign!(sync_events::msc4186::response::List::default(), {
|
||||
count: ruma_from_usize(active_rooms.len()),
|
||||
}),
|
||||
);
|
||||
@@ -749,10 +754,10 @@ async fn process_rooms<'a, Rooms>(
|
||||
all_invited_rooms: Rooms,
|
||||
all_knocked_rooms: Rooms,
|
||||
todo_rooms: &TodoRooms,
|
||||
response: &mut sync_events::v5::Response,
|
||||
body: &sync_events::v5::Request,
|
||||
response: &mut sync_events::msc4186::Response,
|
||||
body: &sync_events::msc4186::Request,
|
||||
timeline_event_ids: &mut BTreeSet<OwnedEventId>,
|
||||
) -> Result<BTreeMap<OwnedRoomId, sync_events::v5::response::Room>>
|
||||
) -> Result<BTreeMap<OwnedRoomId, sync_events::msc4186::response::Room>>
|
||||
where
|
||||
Rooms: Iterator<Item = &'a RoomId> + Clone + Send + 'a,
|
||||
{
|
||||
@@ -787,7 +792,7 @@ where
|
||||
|
||||
rooms.insert(
|
||||
room_id.clone(),
|
||||
assign!(sync_events::v5::response::Room::new(), {
|
||||
assign!(sync_events::msc4186::response::Room::new(), {
|
||||
initial: Some(roomsince == &0),
|
||||
invite_state,
|
||||
limited: true,
|
||||
@@ -821,7 +826,7 @@ where
|
||||
|
||||
rooms.insert(
|
||||
room_id.clone(),
|
||||
assign!(sync_events::v5::response::Room::new(), {
|
||||
assign!(sync_events::msc4186::response::Room::new(), {
|
||||
initial: Some(roomsince == &0),
|
||||
invite_state: Some(knock_state),
|
||||
limited: true,
|
||||
@@ -988,7 +993,7 @@ where
|
||||
.state_accessor
|
||||
.get_member(room_id, &user_id)
|
||||
.map_ok(|member_event| {
|
||||
assign!(sync_events::v5::response::Hero::new(user_id.clone()), {
|
||||
assign!(sync_events::msc4186::response::Hero::new(user_id.clone()), {
|
||||
name: member_event.displayname,
|
||||
avatar: member_event.avatar_url,
|
||||
})
|
||||
@@ -1032,7 +1037,7 @@ where
|
||||
|
||||
rooms.insert(
|
||||
room_id.clone(),
|
||||
assign!(sync_events::v5::response::Room::new(), {
|
||||
assign!(sync_events::msc4186::response::Room::new(), {
|
||||
name: services
|
||||
.rooms
|
||||
.state_accessor
|
||||
@@ -1103,64 +1108,61 @@ where
|
||||
Ok(rooms)
|
||||
}
|
||||
|
||||
#[expect(clippy::too_many_arguments)]
|
||||
async fn collect_sticky_events(
|
||||
services: &Services,
|
||||
sender_user: &UserId,
|
||||
body: &sync_events::v5::Request,
|
||||
sticky_rooms: &BTreeSet<OwnedRoomId>,
|
||||
body: &sync_events::msc4186::Request,
|
||||
next_batch: u64,
|
||||
sticky_delivered: &StickyDelivered,
|
||||
known_room_updates: &KnownRoomUpdates,
|
||||
joined_room_ids: &BTreeSet<OwnedRoomId>,
|
||||
todo_rooms: &TodoRooms,
|
||||
timeline_event_ids: &BTreeSet<OwnedEventId>,
|
||||
) -> Result<sync_events::v5::response::StickyEvents> {
|
||||
if !services.config.allow_sticky_events
|
||||
|| !body.extensions.sticky_events.enabled.unwrap_or(false)
|
||||
{
|
||||
return Ok(sync_events::v5::response::StickyEvents::default());
|
||||
) -> (sync_events::msc4186::response::StickyEvents, StickyDelivered) {
|
||||
let mut response = sync_events::msc4186::response::StickyEvents::default();
|
||||
let mut delivered = StickyDelivered::new();
|
||||
|
||||
let sticky_events = &body.extensions.sticky_events;
|
||||
if !sticky_events.enabled.unwrap_or(false) {
|
||||
return (response, delivered);
|
||||
}
|
||||
|
||||
let since = body
|
||||
.extensions
|
||||
.sticky_events
|
||||
.since
|
||||
.as_deref()
|
||||
.and_then(|token| token.parse::<u64>().ok())
|
||||
.unwrap_or(0);
|
||||
let limit = body
|
||||
.extensions
|
||||
.sticky_events
|
||||
let scope = extension_scope(
|
||||
sticky_events.lists.as_deref(),
|
||||
sticky_events.rooms.as_deref(),
|
||||
body.lists.keys().map(String::as_str),
|
||||
known_room_updates,
|
||||
);
|
||||
let limit = sticky_events
|
||||
.limit
|
||||
.map_or(DEFAULT_STICKY_LIMIT, usize_from_ruma)
|
||||
.clamp(1, DEFAULT_STICKY_LIMIT);
|
||||
let now = u64::from(MilliSecondsSinceUnixEpoch::now().get());
|
||||
let oldest_sticky_ts = now.saturating_sub(sticky::MAX_DURATION_MS);
|
||||
|
||||
let mut backlog = Vec::new();
|
||||
let mut stream = Vec::new();
|
||||
for room_id in sticky_rooms
|
||||
.iter()
|
||||
.filter(|room_id| joined_room_ids.contains(*room_id))
|
||||
{
|
||||
// a room the client has not seen before needs its whole backlog, which
|
||||
// a single stream position cannot express
|
||||
let initial = todo_rooms
|
||||
.get(room_id)
|
||||
.is_some_and(|&(_, _, roomsince)| roomsince == 0);
|
||||
for room_id in scope.intersection(joined_room_ids) {
|
||||
let since = sticky_delivered.get(room_id).copied();
|
||||
|
||||
let mut pending = Vec::new();
|
||||
let pdus = services.rooms.timeline.pdus_rev(room_id, None).ignore_err();
|
||||
pin_mut!(pdus);
|
||||
while let Some((count, pdu)) = pdus.next().await {
|
||||
// nothing older than this can still be sticky, and on the stream we
|
||||
// have already delivered everything up to `since`
|
||||
if u64::from(pdu.origin_server_ts) < oldest_sticky_ts
|
||||
|| (!initial && count <= PduCount::Normal(since))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
let PduCount::Normal(count) = count else {
|
||||
continue;
|
||||
};
|
||||
|
||||
if count > next_batch {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Nothing older than this can still be sticky, and everything up to
|
||||
// `since` has already been delivered
|
||||
if u64::from(pdu.origin_server_ts) < oldest_sticky_ts
|
||||
|| since.is_some_and(|since| count <= since)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
let is_sticky = pdu
|
||||
.sticky
|
||||
.as_deref()
|
||||
@@ -1177,38 +1179,26 @@ async fn collect_sticky_events(
|
||||
continue;
|
||||
}
|
||||
|
||||
if count > since {
|
||||
stream.push((count, room_id.clone(), pdu));
|
||||
} else {
|
||||
backlog.push((room_id.clone(), pdu));
|
||||
}
|
||||
pending.push((count, pdu));
|
||||
}
|
||||
}
|
||||
stream.sort_by_key(|(count, ..)| *count);
|
||||
|
||||
let mut response = sync_events::v5::response::StickyEvents::default();
|
||||
pending.reverse();
|
||||
let truncated = pending.len() > limit;
|
||||
let mut last_count = next_batch;
|
||||
for (count, pdu) in pending.into_iter().take(limit) {
|
||||
push_sticky_event(services, &mut response, sender_user, room_id.clone(), pdu).await;
|
||||
last_count = count;
|
||||
}
|
||||
|
||||
// MSC4480 lets us ignore the limit for a newly visible room's backlog
|
||||
for (room_id, pdu) in backlog {
|
||||
push_sticky_event(services, &mut response, sender_user, room_id, pdu).await;
|
||||
delivered.insert(room_id.clone(), if truncated { last_count } else { next_batch });
|
||||
}
|
||||
|
||||
let mut next_batch = None;
|
||||
for (count, room_id, pdu) in stream.into_iter().take(limit) {
|
||||
push_sticky_event(services, &mut response, sender_user, room_id, pdu).await;
|
||||
next_batch = Some(count);
|
||||
}
|
||||
|
||||
if !response.rooms.is_empty() {
|
||||
response.next_batch = Some(next_batch.unwrap_or(since).to_string());
|
||||
}
|
||||
|
||||
Ok(response)
|
||||
(response, delivered)
|
||||
}
|
||||
|
||||
async fn push_sticky_event(
|
||||
services: &Services,
|
||||
response: &mut sync_events::v5::response::StickyEvents,
|
||||
response: &mut sync_events::msc4186::response::StickyEvents,
|
||||
sender_user: &UserId,
|
||||
room_id: OwnedRoomId,
|
||||
mut pdu: PduEvent,
|
||||
@@ -1275,12 +1265,12 @@ async fn collect_required_state(
|
||||
async fn collect_typing_events(
|
||||
services: &Services,
|
||||
sender_user: &UserId,
|
||||
body: &sync_events::v5::Request,
|
||||
body: &sync_events::msc4186::Request,
|
||||
todo_rooms: &TodoRooms,
|
||||
known_room_updates: &KnownRoomUpdates,
|
||||
) -> Result<sync_events::v5::response::Typing> {
|
||||
) -> Result<sync_events::msc4186::response::Typing> {
|
||||
if !body.extensions.typing.enabled.unwrap_or(false) {
|
||||
return Ok(sync_events::v5::response::Typing::default());
|
||||
return Ok(sync_events::msc4186::response::Typing::default());
|
||||
}
|
||||
let typing = &body.extensions.typing;
|
||||
let scope = extension_scope(
|
||||
@@ -1290,10 +1280,10 @@ async fn collect_typing_events(
|
||||
known_room_updates,
|
||||
);
|
||||
if scope.is_empty() {
|
||||
return Ok(sync_events::v5::response::Typing::default());
|
||||
return Ok(sync_events::msc4186::response::Typing::default());
|
||||
}
|
||||
|
||||
let mut typing_response = sync_events::v5::response::Typing::default();
|
||||
let mut typing_response = sync_events::msc4186::response::Typing::default();
|
||||
for (room_id, (_, _, roomsince)) in todo_rooms {
|
||||
if !scope.contains(room_id) {
|
||||
continue;
|
||||
@@ -1373,12 +1363,17 @@ fn extension_scope<'a>(
|
||||
|
||||
async fn collect_account_data(
|
||||
services: &Services,
|
||||
(sender_user, _, globalsince, body): (&UserId, &DeviceId, u64, &sync_events::v5::Request),
|
||||
) -> sync_events::v5::response::AccountData {
|
||||
let mut account_data = sync_events::v5::response::AccountData::default();
|
||||
(sender_user, _, globalsince, body): (
|
||||
&UserId,
|
||||
&DeviceId,
|
||||
u64,
|
||||
&sync_events::msc4186::Request,
|
||||
),
|
||||
) -> sync_events::msc4186::response::AccountData {
|
||||
let mut account_data = sync_events::msc4186::response::AccountData::default();
|
||||
|
||||
if !body.extensions.account_data.enabled.unwrap_or(false) {
|
||||
return sync_events::v5::response::AccountData::default();
|
||||
return sync_events::msc4186::response::AccountData::default();
|
||||
}
|
||||
|
||||
account_data.global = services
|
||||
@@ -1413,15 +1408,15 @@ async fn collect_e2ee<'a, Rooms>(
|
||||
&UserId,
|
||||
&DeviceId,
|
||||
u64,
|
||||
&sync_events::v5::Request,
|
||||
&sync_events::msc4186::Request,
|
||||
),
|
||||
all_joined_rooms: Rooms,
|
||||
) -> Result<sync_events::v5::response::E2EE>
|
||||
) -> Result<sync_events::msc4186::response::E2EE>
|
||||
where
|
||||
Rooms: Iterator<Item = &'a RoomId> + Send + 'a,
|
||||
{
|
||||
if !body.extensions.e2ee.enabled.unwrap_or(false) {
|
||||
return Ok(sync_events::v5::response::E2EE::default());
|
||||
if !body.extensions.e2ee.enabled {
|
||||
return Ok(sync_events::msc4186::response::E2EE::default());
|
||||
}
|
||||
let mut left_encrypted_users = HashSet::new(); // Users that have left any encrypted rooms the sender was in
|
||||
let mut device_list_changes = HashSet::new();
|
||||
@@ -1608,7 +1603,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
Ok(assign!(sync_events::v5::response::E2EE::default(), {
|
||||
Ok(assign!(sync_events::msc4186::response::E2EE::default(), {
|
||||
device_unused_fallback_key_types: None,
|
||||
|
||||
device_one_time_keys_count: services
|
||||
@@ -1627,12 +1622,12 @@ async fn collect_to_device(
|
||||
services: &Services,
|
||||
(sender_user, sender_device, globalsince, body): SyncInfo<'_>,
|
||||
next_batch: u64,
|
||||
) -> Option<sync_events::v5::response::ToDevice> {
|
||||
if !body.extensions.to_device.enabled.unwrap_or(false) {
|
||||
) -> Option<sync_events::msc4186::response::ToDevice> {
|
||||
if !body.extensions.to_device.enabled {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(assign!(sync_events::v5::response::ToDevice::default(), {
|
||||
Some(assign!(sync_events::msc4186::response::ToDevice::default(), {
|
||||
next_batch: next_batch.to_string(),
|
||||
events: services
|
||||
.users
|
||||
@@ -1643,9 +1638,9 @@ async fn collect_to_device(
|
||||
}))
|
||||
}
|
||||
|
||||
async fn collect_receipts(_services: &Services) -> sync_events::v5::response::Receipts {
|
||||
async fn collect_receipts(_services: &Services) -> sync_events::msc4186::response::Receipts {
|
||||
// TODO: get explicitly requested read receipts
|
||||
sync_events::v5::response::Receipts::default()
|
||||
sync_events::msc4186::response::Receipts::default()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -1658,23 +1653,25 @@ mod tests {
|
||||
|
||||
fn custom_room_type() -> RoomTypeFilter { RoomTypeFilter::from(Some("com.example")) }
|
||||
|
||||
fn response() -> sync_events::v5::Response { sync_events::v5::Response::new("1".to_owned()) }
|
||||
fn response() -> sync_events::msc4186::Response {
|
||||
sync_events::msc4186::Response::new("1".to_owned())
|
||||
}
|
||||
|
||||
fn typing_scope_request() -> sync_events::v5::Request {
|
||||
let mut request = sync_events::v5::Request::new();
|
||||
fn typing_scope_request() -> sync_events::msc4186::Request {
|
||||
let mut request = sync_events::msc4186::Request::new();
|
||||
request
|
||||
.lists
|
||||
.insert("first".to_owned(), sync_events::v5::request::List::default());
|
||||
.insert("first".to_owned(), sync_events::msc4186::request::List::default());
|
||||
request
|
||||
.lists
|
||||
.insert("second".to_owned(), sync_events::v5::request::List::default());
|
||||
.insert("second".to_owned(), sync_events::msc4186::request::List::default());
|
||||
request.room_subscriptions.insert(
|
||||
owned_room_id!("!subscription-a:example.com"),
|
||||
sync_events::v5::request::RoomSubscription::default(),
|
||||
sync_events::msc4186::request::RoomSubscription::default(),
|
||||
);
|
||||
request.room_subscriptions.insert(
|
||||
owned_room_id!("!subscription-b:example.com"),
|
||||
sync_events::v5::request::RoomSubscription::default(),
|
||||
sync_events::msc4186::request::RoomSubscription::default(),
|
||||
);
|
||||
request
|
||||
}
|
||||
@@ -1768,9 +1765,10 @@ mod tests {
|
||||
#[test]
|
||||
fn a_room_with_no_events_is_still_empty() {
|
||||
let mut response = response();
|
||||
response
|
||||
.rooms
|
||||
.insert(owned_room_id!("!a:example.com"), sync_events::v5::response::Room::default());
|
||||
response.rooms.insert(
|
||||
owned_room_id!("!a:example.com"),
|
||||
sync_events::msc4186::response::Room::default(),
|
||||
);
|
||||
|
||||
assert!(response_is_empty(&response));
|
||||
}
|
||||
@@ -1781,7 +1779,7 @@ mod tests {
|
||||
let mut response = response();
|
||||
response
|
||||
.rooms
|
||||
.insert(room_id.to_owned(), sync_events::v5::response::Room::default());
|
||||
.insert(room_id.to_owned(), sync_events::msc4186::response::Room::default());
|
||||
response
|
||||
.extensions
|
||||
.receipts
|
||||
@@ -1846,7 +1844,7 @@ mod tests {
|
||||
#[test]
|
||||
fn to_device_without_events_is_empty() {
|
||||
let mut response = response();
|
||||
response.extensions.to_device = Some(sync_events::v5::response::ToDevice::default());
|
||||
response.extensions.to_device = Some(sync_events::msc4186::response::ToDevice::default());
|
||||
|
||||
assert!(response_is_empty(&response));
|
||||
}
|
||||
|
||||
@@ -27,12 +27,7 @@ pub(crate) async fn get_supported_versions_route(
|
||||
State(services): State<crate::State>,
|
||||
_body: Ruma<get_supported_versions::Request>,
|
||||
) -> Result<get_supported_versions::Response> {
|
||||
let mut unstable_features = unstable_features();
|
||||
|
||||
if services.config.allow_sticky_events {
|
||||
// sticky events (https://github.com/matrix-org/matrix-spec-proposals/pull/4354)
|
||||
unstable_features.insert("org.matrix.msc4354".to_owned(), true);
|
||||
}
|
||||
let unstable_features = unstable_features(&services.config.experiments);
|
||||
|
||||
Ok(assign!(get_supported_versions::Response::new(versions()), {
|
||||
unstable_features
|
||||
|
||||
@@ -43,9 +43,9 @@ pub(crate) async fn well_known_client(
|
||||
/// homeserver, implementing MSC4143.
|
||||
pub(crate) async fn get_rtc_transports(
|
||||
State(services): State<crate::State>,
|
||||
_body: Ruma<ruma::api::client::rtc::transports::v1::Request>,
|
||||
) -> Result<ruma::api::client::rtc::transports::v1::Response> {
|
||||
Ok(ruma::api::client::rtc::transports::v1::Response::new(
|
||||
_body: Ruma<ruma::api::client::rtc::transports::msc4143::Request>,
|
||||
) -> Result<ruma::api::client::rtc::transports::msc4143::Response> {
|
||||
Ok(ruma::api::client::rtc::transports::msc4143::Response::new(
|
||||
services.config.matrix_rtc.foci.clone(),
|
||||
))
|
||||
}
|
||||
|
||||
+11
-40
@@ -8,7 +8,7 @@ use std::str::FromStr;
|
||||
use axum::{
|
||||
Router,
|
||||
response::{IntoResponse, Redirect},
|
||||
routing::{any, get, post},
|
||||
routing::{any, get},
|
||||
};
|
||||
use conduwuit::err;
|
||||
pub(super) use conduwuit_service::state::State;
|
||||
@@ -247,45 +247,16 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
// and other functionality will continue to work
|
||||
router = router.ruma_route(&server::get_openid_userinfo_route);
|
||||
|
||||
if config.allow_legacy_media {
|
||||
router = router
|
||||
.ruma_route(&client::get_media_config_legacy_route)
|
||||
.ruma_route(&client::get_media_preview_legacy_route)
|
||||
.ruma_route(&client::get_content_legacy_route)
|
||||
.ruma_route(&client::get_content_as_filename_legacy_route)
|
||||
.ruma_route(&client::get_content_thumbnail_legacy_route)
|
||||
.route("/_matrix/media/v1/config", get(client::get_media_config_legacy_legacy_route))
|
||||
.route("/_matrix/media/v1/upload", post(client::create_content_legacy_route))
|
||||
.route(
|
||||
"/_matrix/media/v1/preview_url",
|
||||
get(client::get_media_preview_legacy_legacy_route),
|
||||
)
|
||||
.route(
|
||||
"/_matrix/media/v1/download/{server_name}/{media_id}",
|
||||
get(client::get_content_legacy_legacy_route),
|
||||
)
|
||||
.route(
|
||||
"/_matrix/media/v1/download/{server_name}/{media_id}/{file_name}",
|
||||
get(client::get_content_as_filename_legacy_legacy_route),
|
||||
)
|
||||
.route(
|
||||
"/_matrix/media/v1/thumbnail/{server_name}/{media_id}",
|
||||
get(client::get_content_thumbnail_legacy_legacy_route),
|
||||
);
|
||||
} else {
|
||||
router = router
|
||||
.route("/_matrix/media/v1/{*path}", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/v3/config", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/v3/download/{*path}", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/v3/thumbnail/{*path}", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/v3/preview_url", any(redirect_legacy_preview))
|
||||
.route("/_matrix/media/r0/config", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/r0/download/{*path}", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/r0/thumbnail/{*path}", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/r0/preview_url", any(redirect_legacy_preview));
|
||||
}
|
||||
|
||||
router
|
||||
.route("/_matrix/media/v1/{*path}", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/v3/config", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/v3/download/{*path}", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/v3/thumbnail/{*path}", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/v3/preview_url", any(redirect_legacy_preview))
|
||||
.route("/_matrix/media/r0/config", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/r0/download/{*path}", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/r0/thumbnail/{*path}", any(legacy_media_disabled))
|
||||
.route("/_matrix/media/r0/preview_url", any(redirect_legacy_preview))
|
||||
}
|
||||
|
||||
async fn redirect_legacy_preview(uri: Uri) -> impl IntoResponse {
|
||||
@@ -306,7 +277,7 @@ async fn redirect_legacy_preview(uri: Uri) -> impl IntoResponse {
|
||||
}
|
||||
|
||||
async fn legacy_media_disabled() -> impl IntoResponse {
|
||||
err!(Request(Forbidden("Unauthenticated media is disabled.")))
|
||||
err!(Request(NotFound("Unauthenticated media is disabled.")))
|
||||
}
|
||||
|
||||
async fn federation_disabled() -> impl IntoResponse {
|
||||
|
||||
@@ -47,9 +47,6 @@ pub(crate) async fn get_missing_events_route(
|
||||
if body.latest_events.len() > limit {
|
||||
return Err!(Request(InvalidParam("Too many latest_events")));
|
||||
}
|
||||
if body.earliest_events.len() > limit {
|
||||
return Err!(Request(InvalidParam("Too many earliest_events")));
|
||||
}
|
||||
|
||||
let room_version = services.rooms.state.get_room_version(&body.room_id).await?;
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ use crate::Ruma;
|
||||
/// [MSC4560]: https://github.com/matrix-org/matrix-spec-proposals/pull/4560
|
||||
pub(crate) async fn get_stripped_state_route(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_stripped_state::unstable::Request>,
|
||||
) -> Result<get_stripped_state::unstable::Response> {
|
||||
body: Ruma<get_stripped_state::msc4560::Request>,
|
||||
) -> Result<get_stripped_state::msc4560::Response> {
|
||||
if let Some(forbidden_type) = body
|
||||
.state
|
||||
.iter()
|
||||
@@ -42,7 +42,7 @@ pub(crate) async fn get_stripped_state_route(
|
||||
.await
|
||||
{
|
||||
| Accessibility::Accessible(RoomStrippedState { state, num_joined_members, .. }) => Ok(
|
||||
assign!(get_stripped_state::unstable::Response::default(), { state, num_joined_members }),
|
||||
assign!(get_stripped_state::msc4560::Response::default(), { state, num_joined_members }),
|
||||
),
|
||||
| Accessibility::Inaccessible => {
|
||||
Err!(Request(Forbidden("You may not access this room's stripped state.")))
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
use conduwuit_macros::config_example_generator;
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Configuration for experimental features.
|
||||
#[derive(Debug, Deserialize, Default, Clone)]
|
||||
#[config_example_generator(
|
||||
filename = "conduwuit-example.toml",
|
||||
section = "global.experiments",
|
||||
subheader = r##"# Continuwuity's experimental features are frequently updated.
|
||||
# If you got this configuration via a package manager, chances are it's outdated.
|
||||
# Check out the configuration reference online to see a fresh version:
|
||||
# https://continuwuity.org/reference/config.html#:~:text=global.experiments
|
||||
#
|
||||
# Please keep in mind that experiments are used to enable unstable features.
|
||||
# You probably don't need to enable any of these unless you know what they are,
|
||||
# and consequently know why you should enable them."##
|
||||
)]
|
||||
pub struct Experiments {
|
||||
/// MSC2815: Proposal to allow room moderators to view redacted event
|
||||
/// content
|
||||
///
|
||||
/// See [`MSC2815`] for details.
|
||||
///
|
||||
/// display: nested
|
||||
#[serde(default)]
|
||||
pub msc2815: Option<MSC2815>,
|
||||
/// MSC4155: Invite filtering
|
||||
///
|
||||
/// Provides advanced invite filtering rules for users, allowing complex
|
||||
/// configurations that can allow, ignore, and reject invites from users and
|
||||
/// servers broadly.
|
||||
///
|
||||
/// Requires a supporting client to set up on an account.
|
||||
///
|
||||
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4155
|
||||
///
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub msc4155: SimpleExperiment,
|
||||
/// MSC4174: Web push
|
||||
///
|
||||
/// Adds server-side support for web push, allowing web clients to receive
|
||||
/// push notifications directly without the need for an intermediary push
|
||||
/// gateway like Sygnal.
|
||||
///
|
||||
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4174
|
||||
///
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub msc4174: SimpleExperiment,
|
||||
/// MSC4484: Server Administration OAuth Scope
|
||||
///
|
||||
/// Adds a new OAuth2 scope that explicitly grants a token temporary
|
||||
/// homeserver administrator privileges, granting temporary token access
|
||||
/// to administrator endpoints like locking & suspension.
|
||||
///
|
||||
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4484
|
||||
///
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub msc4484: SimpleExperiment,
|
||||
/// MSC4494: Membership-based invite blocking
|
||||
///
|
||||
/// Adds a new invite blocking action that will reject all invites coming
|
||||
/// from users who do not share a room with the invitee that is not `public`
|
||||
/// (the join rule).
|
||||
///
|
||||
/// This is not related to MSC4155, this proposal instead builds on the
|
||||
/// "invite blocking" proposal that landed in the specification in v1.17,
|
||||
/// which simply allows enabling or disabling invites altogether.
|
||||
///
|
||||
/// MSC4494 is a good middle-ground between the allowlisting possible with
|
||||
/// MSC4155, and the general desire to block invites from users you may not
|
||||
/// know.
|
||||
///
|
||||
/// Requires a supporting client to enable on an account.
|
||||
///
|
||||
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4494
|
||||
///
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub msc4494: SimpleExperiment,
|
||||
/// MSC4560: Stripped state requests over federation
|
||||
///
|
||||
/// Implements a more efficient way for servers to acquire and serve
|
||||
/// "stripped state" to clients, which is typically only used for displaying
|
||||
/// rooms. The display of space hierarchies and room summaries is
|
||||
/// significantly faster when this proposal is enabled and used.
|
||||
///
|
||||
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4560
|
||||
///
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub msc4560: SimpleExperiment,
|
||||
}
|
||||
|
||||
/// Represents a "simple" experiment, which is either disabled or enabled.
|
||||
///
|
||||
/// More complex experiments that require configuration should define their own
|
||||
/// type and implement `ToggledExperiment` instead.
|
||||
#[derive(Debug, Deserialize, Default, Clone, Copy)]
|
||||
pub struct SimpleExperiment(Option<bool>);
|
||||
|
||||
pub trait ToggledExperiment {
|
||||
/// Returns true if this experiment is explicitly enabled.
|
||||
#[must_use]
|
||||
fn is_enabled(&self) -> bool;
|
||||
}
|
||||
|
||||
impl ToggledExperiment for SimpleExperiment {
|
||||
#[inline]
|
||||
fn is_enabled(&self) -> bool { self.0.is_some_and(crate::is_true!()) }
|
||||
}
|
||||
|
||||
/// Configuration for [MSC2815]: Proposal to allow room moderators to view
|
||||
/// redacted event content
|
||||
///
|
||||
/// MSC2815: https://github.com/matrix-org/matrix-spec-proposals/pull/2815
|
||||
#[derive(Debug, Deserialize, Default, Clone, Copy)]
|
||||
#[config_example_generator(
|
||||
filename = "conduwuit-example.toml",
|
||||
section = "global.experiments.msc2815",
|
||||
optional = "true",
|
||||
subheader = r#"# MSC2815: Proposal to allow room moderators to view redacted event content
|
||||
#
|
||||
# Allows the server to retain unredacted copies of events that have been
|
||||
# redacted for a limited period of time, which allows room moderators and
|
||||
# server administrators to reveal redacted contents. Useful for moderation
|
||||
# and investigating reports.
|
||||
#
|
||||
# Requires a supporting client to use.
|
||||
#
|
||||
# https://github.com/matrix-org/matrix-spec-proposals/pull/2815"#
|
||||
)]
|
||||
pub struct MSC2815 {
|
||||
/// Whether to enable MSC2815.
|
||||
///
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub enabled: bool,
|
||||
|
||||
/// How long, in seconds, to retain the original content of redacted
|
||||
/// events before it is permanently erased. Defaults to 90 days.
|
||||
///
|
||||
/// default: 7776000
|
||||
#[serde(default = "default_unredacted_content_max_age_secs")]
|
||||
pub unredacted_content_max_age_secs: u64,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn default_unredacted_content_max_age_secs() -> u64 { 7_776_000 }
|
||||
|
||||
impl ToggledExperiment for Option<MSC2815> {
|
||||
#[inline]
|
||||
fn is_enabled(&self) -> bool { self.is_some_and(|config| config.enabled) }
|
||||
}
|
||||
+16
-33
@@ -18,6 +18,7 @@ use either::{
|
||||
Either,
|
||||
Either::{Left, Right},
|
||||
};
|
||||
pub use experiments::Experiments;
|
||||
use figment::providers::{Env, Format, Toml};
|
||||
pub use figment::{Figment, value::Value as FigmentValue};
|
||||
use governor::{DefaultKeyedRateLimiter, Quota, RateLimiter};
|
||||
@@ -1768,14 +1769,6 @@ pub struct Config {
|
||||
#[serde(default = "true_fn")]
|
||||
pub allow_incoming_typing: bool,
|
||||
|
||||
/// Allow the use of unstable persistent "sticky events" ([MSC4354])
|
||||
///
|
||||
/// MSC4354: https://c10y.cc/MSC4354
|
||||
///
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub allow_sticky_events: bool,
|
||||
|
||||
/// Maximum time federation user can indicate typing.
|
||||
///
|
||||
/// default: 30
|
||||
@@ -1826,31 +1819,6 @@ pub struct Config {
|
||||
#[serde(default)]
|
||||
pub brotli_compression: bool,
|
||||
|
||||
/// Enable the legacy unauthenticated Matrix media repository endpoints.
|
||||
/// These endpoints consist of:
|
||||
/// - /_matrix/media/*/config
|
||||
/// - /_matrix/media/*/upload
|
||||
/// - /_matrix/media/*/preview_url
|
||||
/// - /_matrix/media/*/download/*
|
||||
/// - /_matrix/media/*/thumbnail/*
|
||||
///
|
||||
/// The authenticated equivalent endpoints are always enabled.
|
||||
///
|
||||
/// Defaults to false, as unauthenticated media has been sunsetted.
|
||||
///
|
||||
/// default: false
|
||||
#[serde(default)]
|
||||
pub allow_legacy_media: bool,
|
||||
|
||||
/// If set to true, prevents fetching new legacy remote media.
|
||||
///
|
||||
/// Legacy media may still be accessible if it was already fetched
|
||||
/// previously and allow_legacy_media is true.
|
||||
///
|
||||
/// default: true
|
||||
#[serde(default = "true_fn")]
|
||||
pub freeze_legacy_media: bool,
|
||||
|
||||
/// Check consistency of the media directory at startup:
|
||||
/// 1. When `media_compat_file_link` is enabled, this check will upgrade
|
||||
/// media when switching back and forth between Conduit and conduwuit.
|
||||
@@ -2478,6 +2446,12 @@ pub struct Config {
|
||||
#[serde(default)]
|
||||
pub matrix_rtc: MatrixRtcConfig,
|
||||
|
||||
/// Configuration for unstable features.
|
||||
///
|
||||
/// display: nested
|
||||
#[serde(default)]
|
||||
pub experiments: Experiments,
|
||||
|
||||
#[serde(flatten)]
|
||||
#[allow(clippy::zero_sized_map_values)]
|
||||
// this is a catchall, the map shouldn't be zero at runtime
|
||||
@@ -3011,6 +2985,9 @@ const DEPRECATED_KEYS: &[&str] = &[
|
||||
"well_known_support_email",
|
||||
"well_known_support_mxid",
|
||||
"well_known.rtc_focus_server_urls",
|
||||
"allow_sticky_events",
|
||||
"allow_moderators_to_view_redacted_content",
|
||||
"unredacted_content_max_age_secs",
|
||||
];
|
||||
|
||||
impl Config {
|
||||
@@ -3445,3 +3422,9 @@ fn default_profile_key_map() -> HashMap<String, String> {
|
||||
fn default_unauthenticated_request_ratelimit<K: Hash + Eq + Clone>() -> PerMinuteRatelimiter<K> {
|
||||
PerMinuteRatelimiter::new(Quota::per_minute(30.try_into().unwrap()))
|
||||
}
|
||||
|
||||
// NOTE: This must be declared *after* every config struct in this file. The
|
||||
// example config generator writes sections in macro expansion order, and the
|
||||
// `global` section truncates the file, so declaring this module any earlier
|
||||
// causes its sections to be wiped from the generated example config.
|
||||
pub mod experiments;
|
||||
@@ -130,7 +130,7 @@ pub enum Error {
|
||||
#[error(transparent)]
|
||||
SignatureVerification(#[from] ruma::signatures::VerificationError),
|
||||
#[error(transparent)]
|
||||
StateRes(#[from] ruma::state_res::Error),
|
||||
StateRes(#[from] crate::state_res::Error),
|
||||
#[error("uiaa")]
|
||||
Uiaa(ruma::api::client::uiaa::UiaaInfo),
|
||||
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
pub mod event;
|
||||
pub mod pdu;
|
||||
pub mod state_key;
|
||||
pub mod state_res;
|
||||
pub mod versions;
|
||||
|
||||
pub use event::{Event, TypeExt as EventTypeExt};
|
||||
pub use pdu::{PartialPdu, Pdu, PduCount, PduEvent, PduId, RawPduId, ShortId};
|
||||
pub use state_key::StateKey;
|
||||
pub use state_res::{StateMap, TypeStateKey};
|
||||
@@ -73,9 +73,6 @@ pub struct Pdu {
|
||||
// BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub signatures: Option<Box<RawJsonValue>>,
|
||||
|
||||
#[serde(default)]
|
||||
pub rejected: bool,
|
||||
}
|
||||
|
||||
/// Content hashes of a PDU.
|
||||
@@ -257,35 +254,3 @@ impl Ord for Pdu {
|
||||
impl PartialOrd for Pdu {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
|
||||
}
|
||||
|
||||
impl ruma::state_res::Event for Pdu {
|
||||
type Id = OwnedEventId;
|
||||
|
||||
fn event_id(&self) -> &Self::Id { &self.event_id }
|
||||
|
||||
fn room_id(&self) -> Option<&RoomId> { self.room_id.as_deref() }
|
||||
|
||||
fn sender(&self) -> &UserId { self.sender.as_ref() }
|
||||
|
||||
fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch {
|
||||
MilliSecondsSinceUnixEpoch(self.origin_server_ts)
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &TimelineEventType { &self.kind }
|
||||
|
||||
fn content(&self) -> &RawJsonValue { &self.content }
|
||||
|
||||
fn state_key(&self) -> Option<&str> { self.state_key.as_deref() }
|
||||
|
||||
fn prev_events(&self) -> Box<dyn DoubleEndedIterator<Item = &Self::Id> + '_> {
|
||||
Box::new(self.prev_events.iter())
|
||||
}
|
||||
|
||||
fn auth_events(&self) -> Box<dyn DoubleEndedIterator<Item = &Self::Id> + '_> {
|
||||
Box::new(self.auth_events.iter())
|
||||
}
|
||||
|
||||
fn redacts(&self) -> Option<&Self::Id> { self.redacts.as_ref() }
|
||||
|
||||
fn rejected(&self) -> bool { self.rejected }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
//! Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
//! of this software and associated documentation files (the "Software"), to
|
||||
//! deal in the Software without restriction, including without limitation the
|
||||
//! rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
//! sell copies of the Software, and to permit persons to whom the Software is
|
||||
//! furnished to do so, subject to the following conditions:
|
||||
|
||||
//! The above copyright notice and this permission notice shall be included in
|
||||
//! all copies or substantial portions of the Software.
|
||||
|
||||
//! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
//! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
//! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
//! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
//! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
//! FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
//! IN THE SOFTWARE.
|
||||
@@ -0,0 +1,554 @@
|
||||
#[cfg(conduwuit_bench)]
|
||||
extern crate test;
|
||||
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
collections::{HashMap, HashSet},
|
||||
sync::atomic::{AtomicU64, Ordering::SeqCst},
|
||||
};
|
||||
|
||||
use futures::{future, future::ready};
|
||||
use maplit::{btreemap, hashmap, hashset};
|
||||
use ruma::{
|
||||
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, RoomVersionId, Signatures, UserId,
|
||||
events::{
|
||||
StateEventType, TimelineEventType,
|
||||
room::{
|
||||
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
},
|
||||
int, room_id, uint, user_id,
|
||||
};
|
||||
use serde_json::{
|
||||
json,
|
||||
value::{RawValue as RawJsonValue, to_raw_value as to_raw_json_value},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
matrix::{Event, Pdu, pdu::EventHash},
|
||||
state_res::{self as state_res, Error, Result, StateMap},
|
||||
};
|
||||
|
||||
static SERVER_TIMESTAMP: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
#[cfg(conduwuit_bench)]
|
||||
#[cfg_attr(conduwuit_bench, bench)]
|
||||
fn lexico_topo_sort(c: &mut test::Bencher) {
|
||||
let graph = hashmap! {
|
||||
event_id("l") => hashset![event_id("o")],
|
||||
event_id("m") => hashset![event_id("n"), event_id("o")],
|
||||
event_id("n") => hashset![event_id("o")],
|
||||
event_id("o") => hashset![], // "o" has zero outgoing edges but 4 incoming edges
|
||||
event_id("p") => hashset![event_id("o")],
|
||||
};
|
||||
|
||||
c.iter(|| {
|
||||
let _ = state_res::lexicographical_topological_sort(&graph, &|_| {
|
||||
future::ok((int!(0), MilliSecondsSinceUnixEpoch(uint!(0))))
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(conduwuit_bench)]
|
||||
#[cfg_attr(conduwuit_bench, bench)]
|
||||
fn resolution_shallow_auth_chain(c: &mut test::Bencher) {
|
||||
let mut store = TestStore(hashmap! {});
|
||||
|
||||
// build up the DAG
|
||||
let (state_at_bob, state_at_charlie, _) = store.set_up();
|
||||
|
||||
c.iter(|| async {
|
||||
let ev_map = store.0.clone();
|
||||
let state_sets = [&state_at_bob, &state_at_charlie];
|
||||
let fetch = |id: OwnedEventId| ready(ev_map.get(&id).map(ToOwned::to_owned));
|
||||
let exists = |id: OwnedEventId| ready(ev_map.get(&id).is_some());
|
||||
let auth_chain_sets: Vec<HashSet<_>> = state_sets
|
||||
.iter()
|
||||
.map(|map| {
|
||||
store
|
||||
.auth_event_ids(room_id(), map.values().cloned().collect())
|
||||
.unwrap()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let _ = match state_res::resolve(
|
||||
&RoomVersionId::V6,
|
||||
state_sets.into_iter(),
|
||||
&auth_chain_sets,
|
||||
&fetch,
|
||||
&exists,
|
||||
)
|
||||
.await
|
||||
{
|
||||
| Ok(state) => state,
|
||||
| Err(e) => panic!("{e}"),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(conduwuit_bench)]
|
||||
#[cfg_attr(conduwuit_bench, bench)]
|
||||
fn resolve_deeper_event_set(c: &mut test::Bencher) {
|
||||
let mut inner = INITIAL_EVENTS();
|
||||
let ban = BAN_STATE_SET();
|
||||
|
||||
inner.extend(ban);
|
||||
let store = TestStore(inner.clone());
|
||||
|
||||
let state_set_a = [
|
||||
inner.get(&event_id("CREATE")).unwrap(),
|
||||
inner.get(&event_id("IJR")).unwrap(),
|
||||
inner.get(&event_id("IMA")).unwrap(),
|
||||
inner.get(&event_id("IMB")).unwrap(),
|
||||
inner.get(&event_id("IMC")).unwrap(),
|
||||
inner.get(&event_id("MB")).unwrap(),
|
||||
inner.get(&event_id("PA")).unwrap(),
|
||||
]
|
||||
.iter()
|
||||
.map(|ev| {
|
||||
(
|
||||
(ev.event_type().clone().into(), ev.state_key().unwrap().into()),
|
||||
ev.event_id().to_owned(),
|
||||
)
|
||||
})
|
||||
.collect::<StateMap<_>>();
|
||||
|
||||
let state_set_b = [
|
||||
inner.get(&event_id("CREATE")).unwrap(),
|
||||
inner.get(&event_id("IJR")).unwrap(),
|
||||
inner.get(&event_id("IMA")).unwrap(),
|
||||
inner.get(&event_id("IMB")).unwrap(),
|
||||
inner.get(&event_id("IMC")).unwrap(),
|
||||
inner.get(&event_id("IME")).unwrap(),
|
||||
inner.get(&event_id("PA")).unwrap(),
|
||||
]
|
||||
.iter()
|
||||
.map(|ev| {
|
||||
(
|
||||
(ev.event_type().clone().into(), ev.state_key().unwrap().into()),
|
||||
ev.event_id().to_owned(),
|
||||
)
|
||||
})
|
||||
.collect::<StateMap<_>>();
|
||||
|
||||
c.iter(|| async {
|
||||
let state_sets = [&state_set_a, &state_set_b];
|
||||
let auth_chain_sets: Vec<HashSet<_>> = state_sets
|
||||
.iter()
|
||||
.map(|map| {
|
||||
store
|
||||
.auth_event_ids(room_id(), map.values().cloned().collect())
|
||||
.unwrap()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let fetch = |id: OwnedEventId| ready(inner.get(&id).map(ToOwned::to_owned));
|
||||
let exists = |id: OwnedEventId| ready(inner.get(&id).is_some());
|
||||
let _ = match state_res::resolve(
|
||||
&RoomVersionId::V6,
|
||||
state_sets.into_iter(),
|
||||
&auth_chain_sets,
|
||||
&fetch,
|
||||
&exists,
|
||||
)
|
||||
.await
|
||||
{
|
||||
| Ok(state) => state,
|
||||
| Err(_) => panic!("resolution failed during benchmarking"),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
//*/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPLEMENTATION DETAILS AHEAD
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////*/
|
||||
struct TestStore<E: Event>(HashMap<OwnedEventId, E>);
|
||||
|
||||
#[allow(unused)]
|
||||
impl<E: Event + Clone> TestStore<E> {
|
||||
fn get_event(&self, room_id: &RoomId, event_id: &EventId) -> Result<E> {
|
||||
self.0
|
||||
.get(event_id)
|
||||
.cloned()
|
||||
.ok_or_else(|| Error::NotFound(format!("{} not found", event_id)))
|
||||
}
|
||||
|
||||
/// Returns the events that correspond to the `event_ids` sorted in the same
|
||||
/// order.
|
||||
fn get_events(&self, room_id: &RoomId, event_ids: &[OwnedEventId]) -> Result<Vec<E>> {
|
||||
let mut events = vec![];
|
||||
for id in event_ids {
|
||||
events.push(self.get_event(room_id, id)?);
|
||||
}
|
||||
Ok(events)
|
||||
}
|
||||
|
||||
/// Returns a Vec of the related auth events to the given `event`.
|
||||
fn auth_event_ids(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
event_ids: Vec<OwnedEventId>,
|
||||
) -> Result<HashSet<OwnedEventId>> {
|
||||
let mut result = HashSet::new();
|
||||
let mut stack = event_ids;
|
||||
|
||||
// DFS for auth event chain
|
||||
while !stack.is_empty() {
|
||||
let ev_id = stack.pop().unwrap();
|
||||
if result.contains(&ev_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.insert(ev_id.clone());
|
||||
|
||||
let event = self.get_event(room_id, ev_id.borrow())?;
|
||||
|
||||
stack.extend(event.auth_events().map(ToOwned::to_owned));
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Returns a vector representing the difference in auth chains of the given
|
||||
/// `events`.
|
||||
fn auth_chain_diff(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
event_ids: Vec<Vec<OwnedEventId>>,
|
||||
) -> Result<Vec<OwnedEventId>> {
|
||||
let mut auth_chain_sets = vec![];
|
||||
for ids in event_ids {
|
||||
// TODO state store `auth_event_ids` returns self in the event ids
|
||||
// list when an event returns `auth_event_ids` self is not
|
||||
// contained
|
||||
let chain = self
|
||||
.auth_event_ids(room_id, ids)?
|
||||
.into_iter()
|
||||
.collect::<HashSet<_>>();
|
||||
auth_chain_sets.push(chain);
|
||||
}
|
||||
|
||||
if let Some(first) = auth_chain_sets.first().cloned() {
|
||||
let common = auth_chain_sets
|
||||
.iter()
|
||||
.skip(1)
|
||||
.fold(first, |a, b| a.intersection(b).cloned().collect::<HashSet<_>>());
|
||||
|
||||
Ok(auth_chain_sets
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter(|id| !common.contains(id))
|
||||
.collect())
|
||||
} else {
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TestStore<Pdu> {
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn set_up(
|
||||
&mut self,
|
||||
) -> (StateMap<OwnedEventId>, StateMap<OwnedEventId>, StateMap<OwnedEventId>) {
|
||||
let create_event = to_pdu_event::<&EventId>(
|
||||
"CREATE",
|
||||
alice(),
|
||||
TimelineEventType::RoomCreate,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "creator": alice() })).unwrap(),
|
||||
&[],
|
||||
&[],
|
||||
);
|
||||
let cre = create_event.event_id().to_owned();
|
||||
self.0.insert(cre.clone(), create_event.clone());
|
||||
|
||||
let alice_mem = to_pdu_event(
|
||||
"IMA",
|
||||
alice(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(alice().to_string().as_str()),
|
||||
member_content_join(),
|
||||
&[cre.clone()],
|
||||
&[cre.clone()],
|
||||
);
|
||||
self.0
|
||||
.insert(alice_mem.event_id().to_owned(), alice_mem.clone());
|
||||
|
||||
let join_rules = to_pdu_event(
|
||||
"IJR",
|
||||
alice(),
|
||||
TimelineEventType::RoomJoinRules,
|
||||
Some(""),
|
||||
to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
||||
&[cre.clone(), alice_mem.event_id().to_owned()],
|
||||
&[alice_mem.event_id().to_owned()],
|
||||
);
|
||||
self.0
|
||||
.insert(join_rules.event_id().to_owned(), join_rules.clone());
|
||||
|
||||
// Bob and Charlie join at the same time, so there is a fork
|
||||
// this will be represented in the state_sets when we resolve
|
||||
let bob_mem = to_pdu_event(
|
||||
"IMB",
|
||||
bob(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(bob().to_string().as_str()),
|
||||
member_content_join(),
|
||||
&[cre.clone(), join_rules.event_id().to_owned()],
|
||||
&[join_rules.event_id().to_owned()],
|
||||
);
|
||||
self.0
|
||||
.insert(bob_mem.event_id().to_owned(), bob_mem.clone());
|
||||
|
||||
let charlie_mem = to_pdu_event(
|
||||
"IMC",
|
||||
charlie(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(charlie().to_string().as_str()),
|
||||
member_content_join(),
|
||||
&[cre, join_rules.event_id().to_owned()],
|
||||
&[join_rules.event_id().to_owned()],
|
||||
);
|
||||
self.0
|
||||
.insert(charlie_mem.event_id().to_owned(), charlie_mem.clone());
|
||||
|
||||
let state_at_bob = [&create_event, &alice_mem, &join_rules, &bob_mem]
|
||||
.iter()
|
||||
.map(|ev| {
|
||||
(
|
||||
(ev.event_type().to_string().into(), ev.state_key().unwrap().into()),
|
||||
ev.event_id().to_owned(),
|
||||
)
|
||||
})
|
||||
.collect::<StateMap<_>>();
|
||||
|
||||
let state_at_charlie = [&create_event, &alice_mem, &join_rules, &charlie_mem]
|
||||
.iter()
|
||||
.map(|ev| {
|
||||
(
|
||||
(ev.event_type().to_string().into(), ev.state_key().unwrap().into()),
|
||||
ev.event_id().to_owned(),
|
||||
)
|
||||
})
|
||||
.collect::<StateMap<_>>();
|
||||
|
||||
let expected = [&create_event, &alice_mem, &join_rules, &bob_mem, &charlie_mem]
|
||||
.iter()
|
||||
.map(|ev| {
|
||||
(
|
||||
(ev.event_type().to_string().into(), ev.state_key().unwrap().into()),
|
||||
ev.event_id().to_owned(),
|
||||
)
|
||||
})
|
||||
.collect::<StateMap<_>>();
|
||||
|
||||
(state_at_bob, state_at_charlie, expected)
|
||||
}
|
||||
}
|
||||
|
||||
fn event_id(id: &str) -> OwnedEventId {
|
||||
if id.contains('$') {
|
||||
return id.try_into().unwrap();
|
||||
}
|
||||
format!("${}:foo", id).try_into().unwrap()
|
||||
}
|
||||
|
||||
fn alice() -> &'static UserId { user_id!("@alice:foo") }
|
||||
|
||||
fn bob() -> &'static UserId { user_id!("@bob:foo") }
|
||||
|
||||
fn charlie() -> &'static UserId { user_id!("@charlie:foo") }
|
||||
|
||||
fn ella() -> &'static UserId { user_id!("@ella:foo") }
|
||||
|
||||
fn room_id() -> &'static RoomId { room_id!("!test:foo") }
|
||||
|
||||
fn member_content_ban() -> Box<RawJsonValue> {
|
||||
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Ban)).unwrap()
|
||||
}
|
||||
|
||||
fn member_content_join() -> Box<RawJsonValue> {
|
||||
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Join)).unwrap()
|
||||
}
|
||||
|
||||
fn to_pdu_event<S>(
|
||||
id: &str,
|
||||
sender: &UserId,
|
||||
ev_type: TimelineEventType,
|
||||
state_key: Option<&str>,
|
||||
content: Box<RawJsonValue>,
|
||||
auth_events: &[S],
|
||||
prev_events: &[S],
|
||||
) -> Pdu
|
||||
where
|
||||
S: AsRef<str>,
|
||||
{
|
||||
// We don't care if the addition happens in order just that it is atomic
|
||||
// (each event has its own value)
|
||||
let ts = SERVER_TIMESTAMP.fetch_add(1, SeqCst);
|
||||
let id = if id.contains('$') {
|
||||
id.to_owned()
|
||||
} else {
|
||||
format!("${}:foo", id)
|
||||
};
|
||||
let auth_events = auth_events
|
||||
.iter()
|
||||
.map(AsRef::as_ref)
|
||||
.map(event_id)
|
||||
.collect::<Vec<_>>();
|
||||
let prev_events = prev_events
|
||||
.iter()
|
||||
.map(AsRef::as_ref)
|
||||
.map(event_id)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Pdu {
|
||||
event_id: id.try_into().unwrap(),
|
||||
room_id: Some(room_id().to_owned()),
|
||||
sender: sender.to_owned(),
|
||||
origin_server_ts: ts.try_into().unwrap(),
|
||||
state_key: state_key.map(Into::into),
|
||||
kind: ev_type,
|
||||
content,
|
||||
origin: None,
|
||||
redacts: None,
|
||||
sticky: None,
|
||||
unsigned: None,
|
||||
auth_events,
|
||||
prev_events,
|
||||
depth: uint!(0),
|
||||
hashes: EventHash { sha256: String::new() },
|
||||
signatures: None,
|
||||
}
|
||||
}
|
||||
|
||||
// all graphs start with these input events
|
||||
#[allow(non_snake_case)]
|
||||
fn INITIAL_EVENTS() -> HashMap<OwnedEventId, Pdu> {
|
||||
vec![
|
||||
to_pdu_event::<&EventId>(
|
||||
"CREATE",
|
||||
alice(),
|
||||
TimelineEventType::RoomCreate,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "creator": alice() })).unwrap(),
|
||||
&[],
|
||||
&[],
|
||||
),
|
||||
to_pdu_event(
|
||||
"IMA",
|
||||
alice(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(alice().as_str()),
|
||||
member_content_join(),
|
||||
&["CREATE"],
|
||||
&["CREATE"],
|
||||
),
|
||||
to_pdu_event(
|
||||
"IPOWER",
|
||||
alice(),
|
||||
TimelineEventType::RoomPowerLevels,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "users": { alice(): 100 } })).unwrap(),
|
||||
&["CREATE", "IMA"],
|
||||
&["IMA"],
|
||||
),
|
||||
to_pdu_event(
|
||||
"IJR",
|
||||
alice(),
|
||||
TimelineEventType::RoomJoinRules,
|
||||
Some(""),
|
||||
to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
||||
&["CREATE", "IMA", "IPOWER"],
|
||||
&["IPOWER"],
|
||||
),
|
||||
to_pdu_event(
|
||||
"IMB",
|
||||
bob(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(bob().to_string().as_str()),
|
||||
member_content_join(),
|
||||
&["CREATE", "IJR", "IPOWER"],
|
||||
&["IJR"],
|
||||
),
|
||||
to_pdu_event(
|
||||
"IMC",
|
||||
charlie(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(charlie().to_string().as_str()),
|
||||
member_content_join(),
|
||||
&["CREATE", "IJR", "IPOWER"],
|
||||
&["IMB"],
|
||||
),
|
||||
to_pdu_event::<&EventId>(
|
||||
"START",
|
||||
charlie(),
|
||||
TimelineEventType::RoomTopic,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({})).unwrap(),
|
||||
&[],
|
||||
&[],
|
||||
),
|
||||
to_pdu_event::<&EventId>(
|
||||
"END",
|
||||
charlie(),
|
||||
TimelineEventType::RoomTopic,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({})).unwrap(),
|
||||
&[],
|
||||
&[],
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|ev| (ev.event_id().to_owned(), ev))
|
||||
.collect()
|
||||
}
|
||||
|
||||
// all graphs start with these input events
|
||||
#[allow(non_snake_case)]
|
||||
fn BAN_STATE_SET() -> HashMap<OwnedEventId, Pdu> {
|
||||
vec![
|
||||
to_pdu_event(
|
||||
"PA",
|
||||
alice(),
|
||||
TimelineEventType::RoomPowerLevels,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "users": { alice(): 100, bob(): 50 } })).unwrap(),
|
||||
&["CREATE", "IMA", "IPOWER"], // auth_events
|
||||
&["START"], // prev_events
|
||||
),
|
||||
to_pdu_event(
|
||||
"PB",
|
||||
alice(),
|
||||
TimelineEventType::RoomPowerLevels,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "users": { alice(): 100, bob(): 50 } })).unwrap(),
|
||||
&["CREATE", "IMA", "IPOWER"],
|
||||
&["END"],
|
||||
),
|
||||
to_pdu_event(
|
||||
"MB",
|
||||
alice(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(ella().as_str()),
|
||||
member_content_ban(),
|
||||
&["CREATE", "IMA", "PB"],
|
||||
&["PA"],
|
||||
),
|
||||
to_pdu_event(
|
||||
"IME",
|
||||
ella(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(ella().as_str()),
|
||||
member_content_join(),
|
||||
&["CREATE", "IJR", "PA"],
|
||||
&["MB"],
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|ev| (ev.event_id().to_owned(), ev))
|
||||
.collect()
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
use serde_json::Error as JsonError;
|
||||
use thiserror::Error;
|
||||
|
||||
/// Represents the various errors that arise when resolving state.
|
||||
#[derive(Error, Debug)]
|
||||
#[non_exhaustive]
|
||||
pub enum Error {
|
||||
/// A deserialization error.
|
||||
#[error(transparent)]
|
||||
SerdeJson(#[from] JsonError),
|
||||
|
||||
/// The given option or version is unsupported.
|
||||
#[error("Unsupported room version: {0}")]
|
||||
Unsupported(String),
|
||||
|
||||
/// The given event was not found.
|
||||
#[error("Not found error: {0}")]
|
||||
NotFound(String),
|
||||
|
||||
/// Invalid fields in the given PDU.
|
||||
#[error("Invalid PDU: {0}")]
|
||||
InvalidPdu(String),
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,104 @@
|
||||
11/29/2020 BRANCH: timo-spec-comp REV: d2a85669cc6056679ce6ca0fde4658a879ad2b08
|
||||
lexicographical topological sort
|
||||
time: [1.7123 us 1.7157 us 1.7199 us]
|
||||
change: [-1.7584% -1.5433% -1.3205%] (p = 0.00 < 0.05)
|
||||
Performance has improved.
|
||||
Found 8 outliers among 100 measurements (8.00%)
|
||||
2 (2.00%) low mild
|
||||
5 (5.00%) high mild
|
||||
1 (1.00%) high severe
|
||||
|
||||
resolve state of 5 events one fork
|
||||
time: [10.981 us 10.998 us 11.020 us]
|
||||
Found 3 outliers among 100 measurements (3.00%)
|
||||
3 (3.00%) high mild
|
||||
|
||||
resolve state of 10 events 3 conflicting
|
||||
time: [26.858 us 26.946 us 27.037 us]
|
||||
|
||||
11/29/2020 BRANCH: event-trait REV: f0eb1310efd49d722979f57f20bd1ac3592b0479
|
||||
lexicographical topological sort
|
||||
time: [1.7686 us 1.7738 us 1.7810 us]
|
||||
change: [-3.2752% -2.4634% -1.7635%] (p = 0.00 < 0.05)
|
||||
Performance has improved.
|
||||
Found 1 outliers among 100 measurements (1.00%)
|
||||
1 (1.00%) high severe
|
||||
|
||||
resolve state of 5 events one fork
|
||||
time: [10.643 us 10.656 us 10.669 us]
|
||||
change: [-4.9990% -3.8078% -2.8319%] (p = 0.00 < 0.05)
|
||||
Performance has improved.
|
||||
Found 1 outliers among 100 measurements (1.00%)
|
||||
1 (1.00%) high severe
|
||||
|
||||
resolve state of 10 events 3 conflicting
|
||||
time: [29.149 us 29.252 us 29.375 us]
|
||||
change: [-0.8433% -0.3270% +0.2656%] (p = 0.25 > 0.05)
|
||||
No change in performance detected.
|
||||
Found 1 outliers among 100 measurements (1.00%)
|
||||
1 (1.00%) high mild
|
||||
|
||||
4/26/2020 BRANCH: fix-test-serde REV:
|
||||
lexicographical topological sort
|
||||
time: [1.6793 us 1.6823 us 1.6857 us]
|
||||
Found 9 outliers among 100 measurements (9.00%)
|
||||
1 (1.00%) low mild
|
||||
4 (4.00%) high mild
|
||||
4 (4.00%) high severe
|
||||
|
||||
resolve state of 5 events one fork
|
||||
time: [9.9993 us 10.062 us 10.159 us]
|
||||
Found 9 outliers among 100 measurements (9.00%)
|
||||
7 (7.00%) high mild
|
||||
2 (2.00%) high severe
|
||||
|
||||
resolve state of 10 events 3 conflicting
|
||||
time: [26.004 us 26.092 us 26.195 us]
|
||||
Found 16 outliers among 100 measurements (16.00%)
|
||||
11 (11.00%) high mild
|
||||
5 (5.00%) high severe
|
||||
|
||||
6/30/2021 BRANCH: state-closure REV: 174c3e2a72232ad75b3fb14b3551f5f746f4fe84
|
||||
lexicographical topological sort
|
||||
time: [1.5496 us 1.5536 us 1.5586 us]
|
||||
Found 9 outliers among 100 measurements (9.00%)
|
||||
1 (1.00%) low mild
|
||||
1 (1.00%) high mild
|
||||
7 (7.00%) high severe
|
||||
|
||||
resolve state of 5 events one fork
|
||||
time: [10.319 us 10.333 us 10.347 us]
|
||||
Found 2 outliers among 100 measurements (2.00%)
|
||||
2 (2.00%) high severe
|
||||
|
||||
resolve state of 10 events 3 conflicting
|
||||
time: [25.770 us 25.805 us 25.839 us]
|
||||
Found 7 outliers among 100 measurements (7.00%)
|
||||
5 (5.00%) high mild
|
||||
2 (2.00%) high severe
|
||||
|
||||
7/20/2021 BRANCH stateres-result REV:
|
||||
This marks the switch to HashSet/Map
|
||||
lexicographical topological sort
|
||||
time: [1.8122 us 1.8177 us 1.8233 us]
|
||||
change: [+15.205% +15.919% +16.502%] (p = 0.00 < 0.05)
|
||||
Performance has regressed.
|
||||
Found 7 outliers among 100 measurements (7.00%)
|
||||
5 (5.00%) high mild
|
||||
2 (2.00%) high severe
|
||||
|
||||
resolve state of 5 events one fork
|
||||
time: [11.966 us 12.010 us 12.059 us]
|
||||
change: [+16.089% +16.730% +17.469%] (p = 0.00 < 0.05)
|
||||
Performance has regressed.
|
||||
Found 7 outliers among 100 measurements (7.00%)
|
||||
3 (3.00%) high mild
|
||||
4 (4.00%) high severe
|
||||
|
||||
resolve state of 10 events 3 conflicting
|
||||
time: [29.092 us 29.201 us 29.311 us]
|
||||
change: [+12.447% +12.847% +13.280%] (p = 0.00 < 0.05)
|
||||
Performance has regressed.
|
||||
Found 9 outliers among 100 measurements (9.00%)
|
||||
6 (6.00%) high mild
|
||||
3 (3.00%) high severe
|
||||
@@ -0,0 +1,241 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma::{
|
||||
Int, OwnedUserId, UserId,
|
||||
events::{TimelineEventType, room::power_levels::RoomPowerLevelsEventContent},
|
||||
power_levels::{NotificationPowerLevels, default_power_level},
|
||||
room_version_rules::{AuthorizationRules, RoomVersionRules},
|
||||
serde::deserialize_v1_powerlevel,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Error, from_str as from_json_str};
|
||||
|
||||
use super::{
|
||||
Result,
|
||||
serde_backports::{
|
||||
vec_deserialize_int_powerlevel_values, vec_deserialize_v1_powerlevel_values,
|
||||
},
|
||||
};
|
||||
use crate::error;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct IntRoomPowerLevelsEventContent {
|
||||
#[serde(default = "default_power_level")]
|
||||
ban: Int,
|
||||
|
||||
#[serde(default)]
|
||||
events: BTreeMap<TimelineEventType, Int>,
|
||||
|
||||
#[serde(default)]
|
||||
events_default: Int,
|
||||
|
||||
#[serde(default)]
|
||||
invite: Int,
|
||||
|
||||
#[serde(default = "default_power_level")]
|
||||
kick: Int,
|
||||
|
||||
#[serde(default = "default_power_level")]
|
||||
redact: Int,
|
||||
|
||||
#[serde(default = "default_power_level")]
|
||||
state_default: Int,
|
||||
|
||||
#[serde(default)]
|
||||
users: BTreeMap<OwnedUserId, Int>,
|
||||
|
||||
#[serde(default)]
|
||||
users_default: Int,
|
||||
|
||||
#[serde(default)]
|
||||
notifications: IntNotificationPowerLevels,
|
||||
}
|
||||
|
||||
impl IntRoomPowerLevelsEventContent {
|
||||
fn into_room_power_levels_content(
|
||||
self,
|
||||
auth_rules: &AuthorizationRules,
|
||||
) -> RoomPowerLevelsEventContent {
|
||||
let Self {
|
||||
ban,
|
||||
events,
|
||||
events_default,
|
||||
invite,
|
||||
kick,
|
||||
redact,
|
||||
state_default,
|
||||
users,
|
||||
users_default,
|
||||
notifications,
|
||||
} = self;
|
||||
|
||||
let mut pl = RoomPowerLevelsEventContent::new(auth_rules);
|
||||
pl.ban = ban;
|
||||
pl.events = events;
|
||||
pl.events_default = events_default;
|
||||
pl.invite = invite;
|
||||
pl.kick = kick;
|
||||
pl.redact = redact;
|
||||
pl.state_default = state_default;
|
||||
pl.users = users;
|
||||
pl.users_default = users_default;
|
||||
pl.notifications = notifications.into();
|
||||
|
||||
pl
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct IntNotificationPowerLevels {
|
||||
#[serde(default = "default_power_level")]
|
||||
room: Int,
|
||||
}
|
||||
|
||||
impl Default for IntNotificationPowerLevels {
|
||||
fn default() -> Self { Self { room: default_power_level() } }
|
||||
}
|
||||
|
||||
impl From<IntNotificationPowerLevels> for NotificationPowerLevels {
|
||||
fn from(int_notif: IntNotificationPowerLevels) -> Self {
|
||||
let mut notif = Self::new();
|
||||
notif.room = int_notif.room;
|
||||
|
||||
notif
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn deserialize_power_levels(
|
||||
content: &str,
|
||||
room_version: &RoomVersionRules,
|
||||
) -> Option<RoomPowerLevelsEventContent> {
|
||||
if room_version.authorization.integer_power_levels {
|
||||
deserialize_integer_power_levels(content, &room_version.authorization)
|
||||
} else {
|
||||
deserialize_legacy_power_levels(content)
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_integer_power_levels(
|
||||
content: &str,
|
||||
auth_rules: &AuthorizationRules,
|
||||
) -> Option<RoomPowerLevelsEventContent> {
|
||||
match from_json_str::<IntRoomPowerLevelsEventContent>(content) {
|
||||
| Ok(content) => Some(content.into_room_power_levels_content(auth_rules)),
|
||||
| Err(_) => {
|
||||
error!("m.room.power_levels event is not valid with integer values");
|
||||
None
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_legacy_power_levels(content: &str) -> Option<RoomPowerLevelsEventContent> {
|
||||
match from_json_str(content) {
|
||||
| Ok(content) => Some(content),
|
||||
| Err(_) => {
|
||||
error!(
|
||||
"m.room.power_levels event is not valid with integer or string integer values"
|
||||
);
|
||||
None
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub(crate) struct PowerLevelsContentFields {
|
||||
#[serde(default, deserialize_with = "vec_deserialize_v1_powerlevel_values")]
|
||||
pub(crate) users: Vec<(OwnedUserId, Int)>,
|
||||
|
||||
#[serde(default, deserialize_with = "deserialize_v1_powerlevel")]
|
||||
pub(crate) users_default: Int,
|
||||
}
|
||||
|
||||
impl PowerLevelsContentFields {
|
||||
pub(crate) fn get_user_power(&self, user_id: &UserId) -> Option<&Int> {
|
||||
let comparator = |item: &(OwnedUserId, Int)| {
|
||||
let item: &UserId = &item.0;
|
||||
item.cmp(user_id)
|
||||
};
|
||||
|
||||
self.users
|
||||
.binary_search_by(comparator)
|
||||
.ok()
|
||||
.and_then(|idx| self.users.get(idx).map(|item| &item.1))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct IntPowerLevelsContentFields {
|
||||
#[serde(default, deserialize_with = "vec_deserialize_int_powerlevel_values")]
|
||||
users: Vec<(OwnedUserId, Int)>,
|
||||
|
||||
#[serde(default)]
|
||||
users_default: Int,
|
||||
}
|
||||
|
||||
impl From<IntPowerLevelsContentFields> for PowerLevelsContentFields {
|
||||
fn from(pl: IntPowerLevelsContentFields) -> Self {
|
||||
let IntPowerLevelsContentFields { users, users_default } = pl;
|
||||
Self { users, users_default }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub(crate) struct PowerLevelsContentInvite {
|
||||
#[serde(default, deserialize_with = "deserialize_v1_powerlevel")]
|
||||
pub(crate) invite: Int,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct IntPowerLevelsContentInvite {
|
||||
#[serde(default)]
|
||||
invite: Int,
|
||||
}
|
||||
|
||||
impl From<IntPowerLevelsContentInvite> for PowerLevelsContentInvite {
|
||||
fn from(pl: IntPowerLevelsContentInvite) -> Self {
|
||||
let IntPowerLevelsContentInvite { invite } = pl;
|
||||
Self { invite }
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn deserialize_power_levels_content_invite(
|
||||
content: &str,
|
||||
room_version: &RoomVersionRules,
|
||||
) -> Result<PowerLevelsContentInvite, Error> {
|
||||
if room_version.authorization.integer_power_levels {
|
||||
from_json_str::<IntPowerLevelsContentInvite>(content).map(Into::into)
|
||||
} else {
|
||||
from_json_str(content)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub(crate) struct PowerLevelsContentRedact {
|
||||
#[serde(default = "default_power_level", deserialize_with = "deserialize_v1_powerlevel")]
|
||||
pub(crate) redact: Int,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub(crate) struct IntPowerLevelsContentRedact {
|
||||
#[serde(default = "default_power_level")]
|
||||
redact: Int,
|
||||
}
|
||||
|
||||
impl From<IntPowerLevelsContentRedact> for PowerLevelsContentRedact {
|
||||
fn from(pl: IntPowerLevelsContentRedact) -> Self {
|
||||
let IntPowerLevelsContentRedact { redact } = pl;
|
||||
Self { redact }
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn deserialize_power_levels_content_redact(
|
||||
content: &str,
|
||||
room_version: &RoomVersionRules,
|
||||
) -> Result<PowerLevelsContentRedact, Error> {
|
||||
if room_version.authorization.integer_power_levels {
|
||||
from_json_str::<IntPowerLevelsContentRedact>(content).map(Into::into)
|
||||
} else {
|
||||
from_json_str(content)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
//! These functions are copied from an old version of Ruma. power_levels.rs uses
|
||||
//! them to lazily deserialize power level events. Upstream Ruma uses a much
|
||||
//! more elegant approach in its state resolution code, which we may want
|
||||
//! to look into at some point.
|
||||
|
||||
use std::{fmt, marker::PhantomData};
|
||||
|
||||
use ruma::{Int, serde::deserialize_v1_powerlevel};
|
||||
use serde::{
|
||||
Deserialize, Deserializer,
|
||||
de::{MapAccess, Visitor},
|
||||
};
|
||||
|
||||
/// Take a Map with values of either an integer number or a string and
|
||||
/// deserialize those to integer numbers in a Vec of sorted pairs.
|
||||
///
|
||||
/// To be used like this:
|
||||
/// `#[serde(deserialize_with = "vec_deserialize_v1_powerlevel_values")]`
|
||||
pub(super) fn vec_deserialize_v1_powerlevel_values<'de, D, T>(
|
||||
de: D,
|
||||
) -> Result<Vec<(T, Int)>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
T: Deserialize<'de> + Ord,
|
||||
{
|
||||
#[repr(transparent)]
|
||||
struct IntWrap(Int);
|
||||
|
||||
impl<'de> Deserialize<'de> for IntWrap {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserialize_v1_powerlevel(deserializer).map(IntWrap)
|
||||
}
|
||||
}
|
||||
|
||||
struct IntMapVisitor<T> {
|
||||
_phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> IntMapVisitor<T> {
|
||||
fn new() -> Self { Self { _phantom: PhantomData } }
|
||||
}
|
||||
|
||||
impl<'de, T> Visitor<'de> for IntMapVisitor<T>
|
||||
where
|
||||
T: Deserialize<'de> + Ord,
|
||||
{
|
||||
type Value = Vec<(T, Int)>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter.write_str("a map with integers or strings as values")
|
||||
}
|
||||
|
||||
fn visit_map<A: MapAccess<'de>>(self, mut map: A) -> Result<Self::Value, A::Error> {
|
||||
let mut res = Vec::new();
|
||||
if let Some(hint) = map.size_hint() {
|
||||
res.reserve(hint);
|
||||
}
|
||||
|
||||
while let Some((k, IntWrap(v))) = map.next_entry()? {
|
||||
res.push((k, v));
|
||||
}
|
||||
|
||||
res.sort_unstable();
|
||||
res.dedup_by(|a, b| a.0 == b.0);
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
de.deserialize_map(IntMapVisitor::new())
|
||||
}
|
||||
|
||||
/// Take a Map with integer values and deserialize those to a Vec of sorted
|
||||
/// pairs
|
||||
///
|
||||
/// To be used like this:
|
||||
/// `#[serde(deserialize_with = "vec_deserialize_int_powerlevel_values")]`
|
||||
pub(super) fn vec_deserialize_int_powerlevel_values<'de, D, T>(
|
||||
de: D,
|
||||
) -> Result<Vec<(T, Int)>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
T: Deserialize<'de> + Ord,
|
||||
{
|
||||
struct IntMapVisitor<T> {
|
||||
_phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> IntMapVisitor<T> {
|
||||
fn new() -> Self { Self { _phantom: PhantomData } }
|
||||
}
|
||||
|
||||
impl<'de, T> Visitor<'de> for IntMapVisitor<T>
|
||||
where
|
||||
T: Deserialize<'de> + Ord,
|
||||
{
|
||||
type Value = Vec<(T, Int)>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter.write_str("a map with integers as values")
|
||||
}
|
||||
|
||||
fn visit_map<A: MapAccess<'de>>(self, mut map: A) -> Result<Self::Value, A::Error> {
|
||||
let mut res = Vec::new();
|
||||
if let Some(hint) = map.size_hint() {
|
||||
res.reserve(hint);
|
||||
}
|
||||
|
||||
while let Some(item) = map.next_entry()? {
|
||||
res.push(item);
|
||||
}
|
||||
|
||||
res.sort_unstable();
|
||||
res.dedup_by(|a, b| a.0 == b.0);
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
de.deserialize_map(IntMapVisitor::new())
|
||||
}
|
||||
@@ -0,0 +1,582 @@
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
collections::{BTreeMap, HashMap, HashSet},
|
||||
sync::atomic::{AtomicU64, Ordering::SeqCst},
|
||||
};
|
||||
|
||||
use futures::future::ready;
|
||||
use ruma::{
|
||||
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, RoomVersionId, ServerSignatures,
|
||||
UserId, event_id,
|
||||
events::{
|
||||
TimelineEventType,
|
||||
room::{
|
||||
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
},
|
||||
int, room_id,
|
||||
room_version_rules::RoomVersionRules,
|
||||
uint, user_id,
|
||||
};
|
||||
use serde_json::{
|
||||
json,
|
||||
value::{RawValue as RawJsonValue, to_raw_value as to_raw_json_value},
|
||||
};
|
||||
|
||||
use super::auth_types_for_event;
|
||||
use crate::{
|
||||
Result, info,
|
||||
matrix::{Event, EventTypeExt, Pdu, StateMap, pdu::EventHash},
|
||||
};
|
||||
|
||||
static SERVER_TIMESTAMP: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
pub(crate) async fn do_check(
|
||||
events: &[Pdu],
|
||||
edges: Vec<Vec<OwnedEventId>>,
|
||||
expected_state_ids: Vec<OwnedEventId>,
|
||||
) {
|
||||
// To activate logging use `RUST_LOG=debug cargo t`
|
||||
|
||||
let init_events = INITIAL_EVENTS();
|
||||
|
||||
let mut store = TestStore(
|
||||
init_events
|
||||
.values()
|
||||
.chain(events)
|
||||
.map(|ev| (ev.event_id().to_owned(), ev.clone()))
|
||||
.collect(),
|
||||
);
|
||||
|
||||
// This will be lexi_topo_sorted for resolution
|
||||
let mut graph = HashMap::new();
|
||||
// This is the same as in `resolve` event_id -> OriginalStateEvent
|
||||
let mut fake_event_map = HashMap::new();
|
||||
|
||||
// Create the DB of events that led up to this point
|
||||
// TODO maybe clean up some of these clones it is just tests but...
|
||||
for ev in init_events.values().chain(events) {
|
||||
graph.insert(ev.event_id().to_owned(), HashSet::new());
|
||||
fake_event_map.insert(ev.event_id().to_owned(), ev.clone());
|
||||
}
|
||||
|
||||
for pair in INITIAL_EDGES().windows(2) {
|
||||
if let [a, b] = &pair {
|
||||
graph
|
||||
.entry(a.to_owned())
|
||||
.or_insert_with(HashSet::new)
|
||||
.insert(b.clone());
|
||||
}
|
||||
}
|
||||
|
||||
for edge_list in edges {
|
||||
for pair in edge_list.windows(2) {
|
||||
if let [a, b] = &pair {
|
||||
graph
|
||||
.entry(a.to_owned())
|
||||
.or_insert_with(HashSet::new)
|
||||
.insert(b.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// event_id -> Pdu
|
||||
let mut event_map: HashMap<OwnedEventId, Pdu> = HashMap::new();
|
||||
// event_id -> StateMap<OwnedEventId>
|
||||
let mut state_at_event: HashMap<OwnedEventId, StateMap<OwnedEventId>> = HashMap::new();
|
||||
|
||||
// Resolve the current state and add it to the state_at_event map then
|
||||
// continue on in "time"
|
||||
for node in super::lexicographical_topological_sort(&graph, &|_id| async {
|
||||
Ok((int!(0), MilliSecondsSinceUnixEpoch(uint!(0))))
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
let fake_event = fake_event_map.get(&node).unwrap();
|
||||
let event_id = fake_event.event_id().to_owned();
|
||||
|
||||
let prev_events = graph.get(&node).unwrap();
|
||||
|
||||
let state_before: StateMap<OwnedEventId> = if prev_events.is_empty() {
|
||||
HashMap::new()
|
||||
} else if prev_events.len() == 1 {
|
||||
state_at_event
|
||||
.get(prev_events.iter().next().unwrap())
|
||||
.unwrap()
|
||||
.clone()
|
||||
} else {
|
||||
let state_sets = prev_events
|
||||
.iter()
|
||||
.filter_map(|k| state_at_event.get(k))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
info!(
|
||||
"{:#?}",
|
||||
state_sets
|
||||
.iter()
|
||||
.map(|map| map
|
||||
.iter()
|
||||
.map(|((ty, key), id)| format!("(({ty}{key:?}), {id})"))
|
||||
.collect::<Vec<_>>())
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
|
||||
let auth_chain_sets: Vec<_> = state_sets
|
||||
.iter()
|
||||
.map(|map| {
|
||||
store
|
||||
.auth_event_ids(room_id(), map.values().cloned().collect())
|
||||
.unwrap()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let event_map = &event_map;
|
||||
let fetch = |id: OwnedEventId| ready(event_map.get(&id).cloned());
|
||||
let exists = |id: OwnedEventId| ready(event_map.get(&id).is_some());
|
||||
let resolved = super::resolve(
|
||||
&RoomVersionRules::V6,
|
||||
state_sets,
|
||||
&auth_chain_sets,
|
||||
&fetch,
|
||||
&exists,
|
||||
)
|
||||
.await;
|
||||
|
||||
match resolved {
|
||||
| Ok(state) => state,
|
||||
| Err(e) => panic!("resolution for {node} failed: {e}"),
|
||||
}
|
||||
};
|
||||
|
||||
let mut state_after = state_before.clone();
|
||||
|
||||
let ty = fake_event.event_type();
|
||||
let key = fake_event.state_key().unwrap();
|
||||
state_after.insert(ty.with_state_key(key), event_id.to_owned());
|
||||
|
||||
let auth_types = auth_types_for_event(
|
||||
fake_event.event_type(),
|
||||
fake_event.sender(),
|
||||
fake_event.state_key(),
|
||||
fake_event.content(),
|
||||
&RoomVersionRules::V6,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut auth_events = vec![];
|
||||
for key in auth_types {
|
||||
if state_before.contains_key(&key) {
|
||||
auth_events.push(state_before[&key].clone());
|
||||
}
|
||||
}
|
||||
|
||||
// TODO The event is just remade, adding the auth_events and prev_events
|
||||
// here the `to_pdu_event` was split into `init` and the fn below,
|
||||
// could be better
|
||||
let e = fake_event;
|
||||
let ev_id = e.event_id();
|
||||
let event = to_pdu_event(
|
||||
e.event_id().as_str(),
|
||||
e.sender(),
|
||||
e.event_type().clone(),
|
||||
e.state_key(),
|
||||
e.content().to_owned(),
|
||||
&auth_events,
|
||||
&prev_events.iter().cloned().collect::<Vec<_>>(),
|
||||
);
|
||||
|
||||
// We have to update our store, an actual user of this lib would
|
||||
// be giving us state from a DB.
|
||||
store.0.insert(ev_id.to_owned(), event.clone());
|
||||
|
||||
state_at_event.insert(node, state_after);
|
||||
event_map.insert(event_id.to_owned(), store.0.get(ev_id).unwrap().clone());
|
||||
}
|
||||
|
||||
let mut expected_state = StateMap::new();
|
||||
for node in expected_state_ids {
|
||||
let ev = event_map.get(&node).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"{node} not found in {:?}",
|
||||
event_map
|
||||
.keys()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
)
|
||||
});
|
||||
|
||||
let key = ev.event_type().with_state_key(ev.state_key().unwrap());
|
||||
|
||||
expected_state.insert(key, node);
|
||||
}
|
||||
|
||||
let start_state = state_at_event.get(event_id!("$START:foo")).unwrap();
|
||||
|
||||
let end_state = state_at_event
|
||||
.get(event_id!("$END:foo"))
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|(k, v)| {
|
||||
expected_state.contains_key(k)
|
||||
|| start_state.get(k) != Some(*v)
|
||||
// Filter out the dummy messages events.
|
||||
// These act as points in time where there should be a known state to
|
||||
// test against.
|
||||
&& **k != ("m.room.message".into(), "dummy".into())
|
||||
})
|
||||
.map(|(k, v)| (k.clone(), v.clone()))
|
||||
.collect::<StateMap<OwnedEventId>>();
|
||||
|
||||
assert_eq!(expected_state, end_state);
|
||||
}
|
||||
|
||||
#[allow(clippy::exhaustive_structs)]
|
||||
pub(crate) struct TestStore<E: Event>(pub(crate) HashMap<OwnedEventId, E>);
|
||||
|
||||
impl<E: Event + Clone> TestStore<E> {
|
||||
pub(crate) fn get_event(&self, _: &RoomId, event_id: &EventId) -> Result<E> {
|
||||
self.0
|
||||
.get(event_id)
|
||||
.cloned()
|
||||
.ok_or_else(|| super::Error::NotFound(format!("{event_id} not found")))
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Returns a Vec of the related auth events to the given `event`.
|
||||
pub(crate) fn auth_event_ids(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
event_ids: Vec<OwnedEventId>,
|
||||
) -> Result<HashSet<OwnedEventId>> {
|
||||
let mut result = HashSet::new();
|
||||
let mut stack = event_ids;
|
||||
|
||||
// DFS for auth event chain
|
||||
while let Some(ev_id) = stack.pop() {
|
||||
if result.contains(&ev_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.insert(ev_id.clone());
|
||||
|
||||
let event = self.get_event(room_id, ev_id.borrow())?;
|
||||
|
||||
stack.extend(event.auth_events().map(ToOwned::to_owned));
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
// A StateStore implementation for testing
|
||||
#[allow(clippy::type_complexity)]
|
||||
impl TestStore<Pdu> {
|
||||
pub(crate) fn set_up(
|
||||
&mut self,
|
||||
) -> (StateMap<OwnedEventId>, StateMap<OwnedEventId>, StateMap<OwnedEventId>) {
|
||||
let create_event = to_pdu_event::<&EventId>(
|
||||
"CREATE",
|
||||
alice(),
|
||||
TimelineEventType::RoomCreate,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "creator": alice() })).unwrap(),
|
||||
&[],
|
||||
&[],
|
||||
);
|
||||
let cre = create_event.event_id().to_owned();
|
||||
self.0.insert(cre.clone(), create_event.clone());
|
||||
|
||||
let alice_mem = to_pdu_event(
|
||||
"IMA",
|
||||
alice(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(alice().as_str()),
|
||||
member_content_join(),
|
||||
&[cre.clone()],
|
||||
&[cre.clone()],
|
||||
);
|
||||
self.0
|
||||
.insert(alice_mem.event_id().to_owned(), alice_mem.clone());
|
||||
|
||||
let join_rules = to_pdu_event(
|
||||
"IJR",
|
||||
alice(),
|
||||
TimelineEventType::RoomJoinRules,
|
||||
Some(""),
|
||||
to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
||||
&[cre.clone(), alice_mem.event_id().to_owned()],
|
||||
&[alice_mem.event_id().to_owned()],
|
||||
);
|
||||
self.0
|
||||
.insert(join_rules.event_id().to_owned(), join_rules.clone());
|
||||
|
||||
// Bob and Charlie join at the same time, so there is a fork
|
||||
// this will be represented in the state_sets when we resolve
|
||||
let bob_mem = to_pdu_event(
|
||||
"IMB",
|
||||
bob(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(bob().as_str()),
|
||||
member_content_join(),
|
||||
&[cre.clone(), join_rules.event_id().to_owned()],
|
||||
&[join_rules.event_id().to_owned()],
|
||||
);
|
||||
self.0
|
||||
.insert(bob_mem.event_id().to_owned(), bob_mem.clone());
|
||||
|
||||
let charlie_mem = to_pdu_event(
|
||||
"IMC",
|
||||
charlie(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(charlie().as_str()),
|
||||
member_content_join(),
|
||||
&[cre, join_rules.event_id().to_owned()],
|
||||
&[join_rules.event_id().to_owned()],
|
||||
);
|
||||
self.0
|
||||
.insert(charlie_mem.event_id().to_owned(), charlie_mem.clone());
|
||||
|
||||
let state_at_bob = [&create_event, &alice_mem, &join_rules, &bob_mem]
|
||||
.iter()
|
||||
.map(|e| {
|
||||
(e.event_type().with_state_key(e.state_key().unwrap()), e.event_id().to_owned())
|
||||
})
|
||||
.collect::<StateMap<_>>();
|
||||
|
||||
let state_at_charlie = [&create_event, &alice_mem, &join_rules, &charlie_mem]
|
||||
.iter()
|
||||
.map(|e| {
|
||||
(e.event_type().with_state_key(e.state_key().unwrap()), e.event_id().to_owned())
|
||||
})
|
||||
.collect::<StateMap<_>>();
|
||||
|
||||
let expected = [&create_event, &alice_mem, &join_rules, &bob_mem, &charlie_mem]
|
||||
.iter()
|
||||
.map(|e| {
|
||||
(e.event_type().with_state_key(e.state_key().unwrap()), e.event_id().to_owned())
|
||||
})
|
||||
.collect::<StateMap<_>>();
|
||||
|
||||
(state_at_bob, state_at_charlie, expected)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn event_id(id: &str) -> OwnedEventId {
|
||||
if id.contains('$') {
|
||||
return id.try_into().unwrap();
|
||||
}
|
||||
|
||||
format!("${id}:foo").try_into().unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn alice() -> &'static UserId { user_id!("@alice:foo") }
|
||||
|
||||
pub(crate) fn bob() -> &'static UserId { user_id!("@bob:foo") }
|
||||
|
||||
pub(crate) fn charlie() -> &'static UserId { user_id!("@charlie:foo") }
|
||||
|
||||
pub(crate) fn ella() -> &'static UserId { user_id!("@ella:foo") }
|
||||
|
||||
pub(crate) fn zara() -> &'static UserId { user_id!("@zara:foo") }
|
||||
|
||||
pub(crate) fn room_id() -> &'static RoomId { room_id!("!test:foo") }
|
||||
|
||||
pub(crate) fn member_content_ban() -> Box<RawJsonValue> {
|
||||
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Ban)).unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn member_content_join() -> Box<RawJsonValue> {
|
||||
to_raw_json_value(&RoomMemberEventContent::new(MembershipState::Join)).unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn to_init_pdu_event(
|
||||
id: &str,
|
||||
sender: &UserId,
|
||||
ev_type: TimelineEventType,
|
||||
state_key: Option<&str>,
|
||||
content: Box<RawJsonValue>,
|
||||
) -> Pdu {
|
||||
let ts = SERVER_TIMESTAMP.fetch_add(1, SeqCst);
|
||||
let id = if id.contains('$') {
|
||||
id.to_owned()
|
||||
} else {
|
||||
format!("${id}:foo")
|
||||
};
|
||||
|
||||
Pdu {
|
||||
event_id: id.try_into().unwrap(),
|
||||
room_id: Some(room_id().to_owned()),
|
||||
sender: sender.to_owned(),
|
||||
origin_server_ts: ts.try_into().unwrap(),
|
||||
state_key: state_key.map(Into::into),
|
||||
kind: ev_type,
|
||||
content,
|
||||
origin: None,
|
||||
redacts: None,
|
||||
sticky: None,
|
||||
unsigned: None,
|
||||
auth_events: vec![],
|
||||
prev_events: vec![],
|
||||
depth: uint!(0),
|
||||
hashes: EventHash { sha256: "".to_owned() },
|
||||
signatures: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn to_pdu_event<S>(
|
||||
id: &str,
|
||||
sender: &UserId,
|
||||
ev_type: TimelineEventType,
|
||||
state_key: Option<&str>,
|
||||
content: Box<RawJsonValue>,
|
||||
auth_events: &[S],
|
||||
prev_events: &[S],
|
||||
) -> Pdu
|
||||
where
|
||||
S: AsRef<str>,
|
||||
{
|
||||
let ts = SERVER_TIMESTAMP.fetch_add(1, SeqCst);
|
||||
let id = if id.contains('$') {
|
||||
id.to_owned()
|
||||
} else {
|
||||
format!("${id}:foo")
|
||||
};
|
||||
let auth_events = auth_events
|
||||
.iter()
|
||||
.map(AsRef::as_ref)
|
||||
.map(event_id)
|
||||
.collect::<Vec<_>>();
|
||||
let prev_events = prev_events
|
||||
.iter()
|
||||
.map(AsRef::as_ref)
|
||||
.map(event_id)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Pdu {
|
||||
event_id: id.try_into().unwrap(),
|
||||
room_id: Some(room_id().to_owned()),
|
||||
sender: sender.to_owned(),
|
||||
origin_server_ts: ts.try_into().unwrap(),
|
||||
state_key: state_key.map(Into::into),
|
||||
kind: ev_type,
|
||||
content,
|
||||
origin: None,
|
||||
redacts: None,
|
||||
sticky: None,
|
||||
unsigned: None,
|
||||
auth_events,
|
||||
prev_events,
|
||||
depth: uint!(0),
|
||||
hashes: EventHash { sha256: "".to_owned() },
|
||||
signatures: None,
|
||||
}
|
||||
}
|
||||
|
||||
// all graphs start with these input events
|
||||
#[allow(non_snake_case)]
|
||||
pub(crate) fn INITIAL_EVENTS() -> HashMap<OwnedEventId, Pdu> {
|
||||
vec![
|
||||
to_pdu_event::<&EventId>(
|
||||
"CREATE",
|
||||
alice(),
|
||||
TimelineEventType::RoomCreate,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "creator": alice() })).unwrap(),
|
||||
&[],
|
||||
&[],
|
||||
),
|
||||
to_pdu_event(
|
||||
"IMA",
|
||||
alice(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(alice().as_str()),
|
||||
member_content_join(),
|
||||
&["CREATE"],
|
||||
&["CREATE"],
|
||||
),
|
||||
to_pdu_event(
|
||||
"IPOWER",
|
||||
alice(),
|
||||
TimelineEventType::RoomPowerLevels,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "users": { alice(): 100 } })).unwrap(),
|
||||
&["CREATE", "IMA"],
|
||||
&["IMA"],
|
||||
),
|
||||
to_pdu_event(
|
||||
"IJR",
|
||||
alice(),
|
||||
TimelineEventType::RoomJoinRules,
|
||||
Some(""),
|
||||
to_raw_json_value(&RoomJoinRulesEventContent::new(JoinRule::Public)).unwrap(),
|
||||
&["CREATE", "IMA", "IPOWER"],
|
||||
&["IPOWER"],
|
||||
),
|
||||
to_pdu_event(
|
||||
"IMB",
|
||||
bob(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(bob().as_str()),
|
||||
member_content_join(),
|
||||
&["CREATE", "IJR", "IPOWER"],
|
||||
&["IJR"],
|
||||
),
|
||||
to_pdu_event(
|
||||
"IMC",
|
||||
charlie(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(charlie().as_str()),
|
||||
member_content_join(),
|
||||
&["CREATE", "IJR", "IPOWER"],
|
||||
&["IMB"],
|
||||
),
|
||||
to_pdu_event::<&EventId>(
|
||||
"START",
|
||||
charlie(),
|
||||
TimelineEventType::RoomMessage,
|
||||
Some("dummy"),
|
||||
to_raw_json_value(&json!({})).unwrap(),
|
||||
&[],
|
||||
&[],
|
||||
),
|
||||
to_pdu_event::<&EventId>(
|
||||
"END",
|
||||
charlie(),
|
||||
TimelineEventType::RoomMessage,
|
||||
Some("dummy"),
|
||||
to_raw_json_value(&json!({})).unwrap(),
|
||||
&[],
|
||||
&[],
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|ev| (ev.event_id().to_owned(), ev))
|
||||
.collect()
|
||||
}
|
||||
|
||||
// all graphs start with these input events
|
||||
#[allow(non_snake_case)]
|
||||
pub(crate) fn INITIAL_EVENTS_CREATE_ROOM() -> HashMap<OwnedEventId, Pdu> {
|
||||
vec![to_pdu_event::<&EventId>(
|
||||
"CREATE",
|
||||
alice(),
|
||||
TimelineEventType::RoomCreate,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "creator": alice() })).unwrap(),
|
||||
&[],
|
||||
&[],
|
||||
)]
|
||||
.into_iter()
|
||||
.map(|ev| (ev.event_id().to_owned(), ev))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub(crate) fn INITIAL_EDGES() -> Vec<OwnedEventId> {
|
||||
vec!["START", "IMC", "IMB", "IJR", "IPOWER", "IMA", "CREATE"]
|
||||
.into_iter()
|
||||
.map(event_id)
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
+15
-16
@@ -1,5 +1,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::config::{Experiments, experiments::ToggledExperiment};
|
||||
|
||||
#[must_use]
|
||||
pub fn versions() -> Vec<String> {
|
||||
vec![
|
||||
@@ -25,32 +27,29 @@ pub fn versions() -> Vec<String> {
|
||||
"v1.16".to_owned(),
|
||||
"v1.17".to_owned(),
|
||||
"v1.18".to_owned(),
|
||||
"v1.19".to_owned(),
|
||||
]
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn unstable_features() -> BTreeMap<String, bool> {
|
||||
pub fn unstable_features(experiments: &Experiments) -> BTreeMap<String, bool> {
|
||||
BTreeMap::from_iter([
|
||||
// MatrixRTC (https://github.com/matrix-org/matrix-spec-proposals/pull/4143)
|
||||
// Expected for spec v1.20/v2.0
|
||||
("org.matrix.msc4143".to_owned(), true),
|
||||
// query mutual rooms (https://github.com/matrix-org/matrix-spec-proposals/pull/2666)
|
||||
// Expected for spec v1.19
|
||||
("uk.half-shot.msc2666.query_mutual_rooms".to_owned(), true),
|
||||
("uk.half-shot.msc2666.query_mutual_rooms.stable".to_owned(), true),
|
||||
// Simplified Sliding sync (https://github.com/matrix-org/matrix-spec-proposals/pull/4186)
|
||||
// Expected for spec v1.19
|
||||
// Expected for spec v1.20/v2.0
|
||||
("org.matrix.simplified_msc3575".to_owned(), true),
|
||||
// invite filtering (https://github.com/matrix-org/matrix-spec-proposals/pull/4155)
|
||||
("org.matrix.msc4155".to_owned(), true),
|
||||
("org.matrix.msc4155".to_owned(), experiments.msc4155.is_enabled()),
|
||||
// profile change propagation (https://github.com/matrix-org/matrix-spec-proposals/pull/4466)
|
||||
("computer.gingershaped.msc4466".to_owned(), true),
|
||||
// web push (https://github.com/matrix-org/matrix-spec-proposals/pull/4174)
|
||||
("org.matrix.msc4174".to_owned(), true),
|
||||
// Membership-based invite blocking (https://github.com/matrix-org/matrix-spec-proposals/pull/4494)
|
||||
("uk.timedout.msc4494".to_owned(), true),
|
||||
// server administration OAuth scope (https://github.com/matrix-org/matrix-spec-proposals/pull/4484)
|
||||
("org.continuwuity.msc4484.unstable".to_owned(), true),
|
||||
// stripped state over federation (https://github.com/matrix-org/matrix-spec-proposals/pull/4560)
|
||||
("org.continuwuity.msc4560".to_owned(), true),
|
||||
("org.matrix.msc4174".to_owned(), experiments.msc4174.is_enabled()),
|
||||
("uk.timedout.msc4494".to_owned(), experiments.msc4494.is_enabled()),
|
||||
("org.continuwuity.msc4484.unstable".to_owned(), experiments.msc4484.is_enabled()),
|
||||
("org.continuwuity.msc4560".to_owned(), experiments.msc4560.is_enabled()),
|
||||
("fi.mau.msc2815".to_owned(), experiments.msc2815.is_enabled()),
|
||||
// Sticky events (https://github.com/matrix-org/matrix-spec-proposals/pull/4354)
|
||||
// Proposal merged, expected for spec v1.20/v2.0
|
||||
("org.matrix.msc4354".to_owned(), true),
|
||||
])
|
||||
}
|
||||
+1
-1
@@ -35,7 +35,7 @@ pub use conduwuit_build_metadata as build_metadata;
|
||||
pub use config::Config;
|
||||
pub use error::Error;
|
||||
pub use info::version::*;
|
||||
pub use matrix::{Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, pdu};
|
||||
pub use matrix::{Event, EventTypeExt, Pdu, PduCount, PduEvent, PduId, pdu, state_res};
|
||||
pub use parking_lot::{
|
||||
Mutex as SyncMutex, RwLock as SyncRwLock, RwLockReadGuard as SyncRwLockReadGuard,
|
||||
RwLockWriteGuard as SyncRwLockWriteGuard,
|
||||
|
||||
@@ -53,21 +53,4 @@ impl super::Map {
|
||||
let key = ser::serialize(buf, key).expect("failed to serialize query key");
|
||||
self.get(key)
|
||||
}
|
||||
|
||||
pub fn qry_blocking<K>(self: &Arc<Self>, key: &K) -> Result<Handle<'_>>
|
||||
where
|
||||
K: Serialize + ?Sized + Debug,
|
||||
{
|
||||
let mut buf = KeyBuf::new();
|
||||
self.bqry_blocking(key, &mut buf)
|
||||
}
|
||||
|
||||
pub fn bqry_blocking<K, B>(self: &Arc<Self>, key: &K, buf: &mut B) -> Result<Handle<'_>>
|
||||
where
|
||||
K: Serialize + ?Sized + Debug,
|
||||
B: Write + AsRef<[u8]>,
|
||||
{
|
||||
let key = ser::serialize(buf, key).expect("failed to serialize query key");
|
||||
self.get_blocking(key)
|
||||
}
|
||||
}
|
||||
@@ -153,6 +153,11 @@ pub(super) static MAPS: &[Descriptor] = &[
|
||||
index_size: 512,
|
||||
..descriptor::SEQUENTIAL
|
||||
},
|
||||
Descriptor {
|
||||
name: "pduid_unredactedcontent",
|
||||
key_size_hint: Some(16),
|
||||
..descriptor::SEQUENTIAL
|
||||
},
|
||||
Descriptor {
|
||||
name: "publicroomids",
|
||||
..descriptor::RANDOM_SMALL
|
||||
|
||||
@@ -25,7 +25,7 @@ http.workspace = true
|
||||
ruma.workspace = true
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
wildmatch = "2.7.0"
|
||||
wildmatch.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use conduwuit::{
|
||||
Err, Result, err,
|
||||
utils::{ReadyExt, result::LogErr, stream::TryIgnore},
|
||||
utils::{MutexMap, ReadyExt, result::LogErr, stream::TryIgnore},
|
||||
};
|
||||
use database::{Deserialized, Handle, Ignore, Json, Map};
|
||||
use futures::{Stream, StreamExt, TryFutureExt};
|
||||
@@ -27,6 +27,7 @@ pub enum AnyRawAccountDataEvent {
|
||||
pub struct Service {
|
||||
services: Services,
|
||||
db: Data,
|
||||
update_mutex: MutexMap<OwnedUserId, ()>,
|
||||
}
|
||||
|
||||
struct Data {
|
||||
@@ -50,6 +51,7 @@ impl crate::Service for Service {
|
||||
roomuserdataid_accountdata: args.db["roomuserdataid_accountdata"].clone(),
|
||||
roomusertype_roomuserdataid: args.db["roomusertype_roomuserdataid"].clone(),
|
||||
},
|
||||
update_mutex: MutexMap::new(),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -71,6 +73,10 @@ impl Service {
|
||||
return Err!(Request(InvalidParam("Account data doesn't have all required fields.")));
|
||||
}
|
||||
|
||||
// Two updates reading the same previous entry would both remove it,
|
||||
// and the entry of the one that lost the index would stay forever.
|
||||
let _lock = self.update_mutex.lock(user_id).await;
|
||||
|
||||
let count = self.services.globals.next_count().unwrap();
|
||||
let roomuserdataid = (room_id, user_id, count, &event_type);
|
||||
self.db
|
||||
|
||||
@@ -338,8 +338,16 @@ fn builder_interface(
|
||||
fn get_dns_resolver(server: &Arc<Server>) -> Result<Arc<TokioResolver>> {
|
||||
let config = &server.config;
|
||||
|
||||
let (system_resolver_config, mut opts) = hickory_resolver::system_conf::read_system_conf()
|
||||
.map_err(|e| err!(error!("Failed to configure DNS resolver from system: {e}")))?;
|
||||
let (system_resolver_config, mut opts) =
|
||||
match hickory_resolver::system_conf::read_system_conf() {
|
||||
| Ok(system_conf) => system_conf,
|
||||
| Err(e) if config.dns_servers.is_empty() =>
|
||||
return Err(err!(error!("Failed to configure DNS resolver from system: {e}"))),
|
||||
| Err(e) => {
|
||||
warn!("Failed to read system DNS configuration, using dns_servers: {e}");
|
||||
Default::default()
|
||||
},
|
||||
};
|
||||
|
||||
let mut conf = ResolverConfig::from_name_servers(vec![]);
|
||||
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
use std::{borrow::Cow, fmt::Debug, mem, time::Instant};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
fmt::Debug,
|
||||
mem,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use conduwuit::{
|
||||
Err, Error, Result, debug, debug_error, debug_info, debug_warn, err, metrics::KeyValue,
|
||||
@@ -133,12 +138,19 @@ impl super::Service {
|
||||
|
||||
self.ensure_remote_is_healthy(dest)?;
|
||||
|
||||
/// How long to wait with re-resolution if a server fails to resolve
|
||||
const UNRESOLVABLE_RETRY_AFTER: Duration = Duration::from_hours(24 * 90);
|
||||
|
||||
let actual = self
|
||||
.services
|
||||
.client
|
||||
.matrix_resolver
|
||||
.resolve_server(dest.as_str())
|
||||
.await?;
|
||||
.await
|
||||
.inspect_err(|_| {
|
||||
self.hit_unhealthy(dest.to_owned(), Some(UNRESOLVABLE_RETRY_AFTER));
|
||||
self.mark_destination_stale(dest);
|
||||
})?;
|
||||
|
||||
let request = Request::try_from(request.try_into_http_request::<Vec<u8>>(
|
||||
actual.base_url().as_str(),
|
||||
@@ -210,7 +222,7 @@ impl super::Service {
|
||||
if self.should_mark_stale(&wrapped) {
|
||||
debug_info!("{dest} is unhealthy & stale due to a connect error");
|
||||
self.mark_destination_stale(dest);
|
||||
self.hit_unhealthy(dest.to_owned());
|
||||
self.hit_unhealthy(dest.to_owned(), None);
|
||||
}
|
||||
let Error::Reqwest(unwrapped) = wrapped else {
|
||||
unreachable!("wrapped reqwest error must unwrap to a reqwest error");
|
||||
@@ -300,6 +312,26 @@ async fn into_http_response(
|
||||
actual.base_url(),
|
||||
);
|
||||
|
||||
if url.path() != "/.well-known/matrix/server" {
|
||||
// For some reason, the spec starts off saying federation responses MUST
|
||||
// include a `Content-Type` header of `application/json` on all
|
||||
// responses. Then, the definition for the well-known server endpoint
|
||||
// says that it's a SHOULD and that servers SHOULD just assume that the
|
||||
// response is JSON regardless... And then there's media wayyyy down in
|
||||
// the spec doc that just throws a `multipart/mixed` in there.
|
||||
//
|
||||
// Media has a special case regarding status codes. Only 200 OK
|
||||
// responses should have the multipart assertion, as errors are JSON.
|
||||
let ct = if url.path().starts_with("/_matrix/federation/v1/media/")
|
||||
&& response.status().is_success()
|
||||
{
|
||||
"multipart/mixed"
|
||||
} else {
|
||||
"application/json"
|
||||
};
|
||||
enforce_content_type(&response, ct)?;
|
||||
}
|
||||
|
||||
let mut http_response_builder = http::Response::builder()
|
||||
.status(status)
|
||||
.version(response.version());
|
||||
@@ -353,6 +385,42 @@ fn handle_error(
|
||||
Err(e.into())
|
||||
}
|
||||
|
||||
/// Enforces that the `Content-Type` response header is present, and that the
|
||||
/// first part matches the expected header. This does not enforce that multipart
|
||||
/// responses have a boundary as only the text left of a semicolon, if present,
|
||||
/// is compared.
|
||||
///
|
||||
/// Returns `M_UNKNOWN` with HTTP 415 (Unsupported Media Type) if the response
|
||||
/// header is missing or mismatched.
|
||||
fn enforce_content_type(response: &Response, expected: &str) -> Result<()> {
|
||||
// N.B. Content type's value is case-insensitive per RFC 9110. The Matrix
|
||||
// spec explicitly prescribes `application/json` and `multipart/mixed` etc,
|
||||
// but it's assumed they're intended to be case-insensitive.
|
||||
debug_assert_eq!(
|
||||
expected,
|
||||
expected.to_lowercase(),
|
||||
"Content type checks should use the lowercase content type"
|
||||
); // ^ Saves us double-folding
|
||||
match response
|
||||
.headers()
|
||||
.get(&http::header::CONTENT_TYPE)
|
||||
.and_then(|h| h.to_str().ok())
|
||||
.map(|h| h.split_once(';').unwrap_or((h, "")).0.to_lowercase())
|
||||
{
|
||||
| Some(ct) if ct == expected => Ok(()),
|
||||
| Some(ct) => Err!(Request(
|
||||
Unknown(
|
||||
"Remote server returned the wrong Content-Type: expected {expected}, got {ct:?}"
|
||||
),
|
||||
UNSUPPORTED_MEDIA_TYPE
|
||||
)),
|
||||
| None => Err!(Request(
|
||||
Unknown("Remote server did not return a Content-Type header"),
|
||||
UNSUPPORTED_MEDIA_TYPE
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// A trait for the input types of acceptable path builders for outgoing
|
||||
/// federation requests.
|
||||
///
|
||||
|
||||
@@ -92,7 +92,7 @@ impl Service {
|
||||
/// retry count is incremented and next retry window is updated.
|
||||
///
|
||||
/// Does not update the marker if the backoff period is already in effect.
|
||||
pub fn hit_unhealthy(&self, server_name: OwnedServerName) {
|
||||
pub fn hit_unhealthy(&self, server_name: OwnedServerName, next_attempt: Option<Duration>) {
|
||||
if server_name == self.services.server.name {
|
||||
return;
|
||||
}
|
||||
@@ -109,7 +109,8 @@ impl Service {
|
||||
}
|
||||
|
||||
*retries = retries.saturating_add(1);
|
||||
let next_interval = self.services.server.config.sender_retry_backoff(*retries);
|
||||
let next_interval = next_attempt
|
||||
.unwrap_or_else(|| self.services.server.config.sender_retry_backoff(*retries));
|
||||
*next_retry = millis_from_now(next_interval);
|
||||
debug!(
|
||||
"{} is (now) unhealthy ({} retries, blocked until: {})",
|
||||
@@ -200,14 +201,14 @@ impl Service {
|
||||
}
|
||||
|
||||
match error.status_code() {
|
||||
// Some special servers account for this specifically
|
||||
| StatusCode::MISDIRECTED_REQUEST
|
||||
// Common error codes observed for misdirected requests
|
||||
// | StatusCode::NOT_FOUND This one can be encountered naturally
|
||||
| StatusCode::METHOD_NOT_ALLOWED
|
||||
| StatusCode::IM_A_TEAPOT => true,
|
||||
_ => false,
|
||||
}
|
||||
// Some special servers account for this specifically
|
||||
| StatusCode::MISDIRECTED_REQUEST
|
||||
// Common error codes observed for misdirected requests
|
||||
// | StatusCode::NOT_FOUND This one can be encountered naturally
|
||||
| StatusCode::METHOD_NOT_ALLOWED
|
||||
| StatusCode::IM_A_TEAPOT => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a clone of the internal remote health tracking map.
|
||||
|
||||
+5
-197
@@ -1,7 +1,7 @@
|
||||
use std::{fmt::Debug, time::Duration};
|
||||
|
||||
use conduwuit::{
|
||||
Err, Error, Result, debug_warn, err,
|
||||
Err, Result, debug_warn, err,
|
||||
utils::{content_disposition::make_content_disposition, response::LimitReadExt},
|
||||
};
|
||||
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE, HeaderValue};
|
||||
@@ -9,9 +9,6 @@ use ruma::{
|
||||
ServerName, UserId,
|
||||
api::{
|
||||
OutgoingRequest,
|
||||
auth_scheme::NoAccessToken,
|
||||
client::media,
|
||||
error::ErrorKind::{NotFound, Unrecognized},
|
||||
federation::{
|
||||
self,
|
||||
authenticated_media::{Content, FileOrLocation},
|
||||
@@ -35,17 +32,8 @@ impl super::Service {
|
||||
) -> Result<FileMeta> {
|
||||
self.check_fetch_authorized(mxc)?;
|
||||
|
||||
let result = self
|
||||
.fetch_thumbnail_authenticated(mxc, user, server, timeout_ms, dim)
|
||||
.await;
|
||||
|
||||
if let Err(Error::Request(NotFound, ..)) = &result {
|
||||
return self
|
||||
.fetch_thumbnail_unauthenticated(mxc, user, server, timeout_ms, dim)
|
||||
.await;
|
||||
}
|
||||
|
||||
result
|
||||
self.fetch_thumbnail_authenticated(mxc, user, server, timeout_ms, dim)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn fetch_remote_content(
|
||||
@@ -57,8 +45,7 @@ impl super::Service {
|
||||
) -> Result<FileMeta> {
|
||||
self.check_fetch_authorized(mxc)?;
|
||||
|
||||
let result = self
|
||||
.fetch_content_authenticated(mxc, user, server, timeout_ms)
|
||||
self.fetch_content_authenticated(mxc, user, server, timeout_ms)
|
||||
.await
|
||||
.inspect_err(|error| {
|
||||
debug_warn!(
|
||||
@@ -68,15 +55,7 @@ impl super::Service {
|
||||
?error,
|
||||
"Authenticated fetch of remote content failed"
|
||||
);
|
||||
});
|
||||
|
||||
if let Err(Error::Request(Unrecognized, ..)) = &result {
|
||||
return self
|
||||
.fetch_content_unauthenticated(mxc, user, server, timeout_ms)
|
||||
.await;
|
||||
}
|
||||
|
||||
result
|
||||
})
|
||||
}
|
||||
|
||||
async fn fetch_thumbnail_authenticated(
|
||||
@@ -127,66 +106,6 @@ impl super::Service {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
async fn fetch_thumbnail_unauthenticated(
|
||||
&self,
|
||||
mxc: &Mxc<'_>,
|
||||
user: Option<&UserId>,
|
||||
server: Option<&ServerName>,
|
||||
timeout_ms: Duration,
|
||||
dim: &Dim,
|
||||
) -> Result<FileMeta> {
|
||||
use media::get_content_thumbnail::v3::{Request, Response};
|
||||
|
||||
let mut request = Request::new(
|
||||
mxc.media_id.into(),
|
||||
mxc.server_name.into(),
|
||||
dim.width.into(),
|
||||
dim.height.into(),
|
||||
);
|
||||
request.allow_redirect = true;
|
||||
request.allow_remote = true;
|
||||
request.animated = Some(true);
|
||||
request.method = Some(dim.method.clone());
|
||||
request.timeout_ms = timeout_ms;
|
||||
|
||||
let Response {
|
||||
file, content_type, content_disposition, ..
|
||||
} = self
|
||||
.federation_request_legacy_media(mxc, server, request)
|
||||
.await?;
|
||||
|
||||
let content = Content::new(file, content_type.unwrap(), content_disposition.unwrap());
|
||||
|
||||
self.handle_thumbnail_file(mxc, user, dim, content).await
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
async fn fetch_content_unauthenticated(
|
||||
&self,
|
||||
mxc: &Mxc<'_>,
|
||||
user: Option<&UserId>,
|
||||
server: Option<&ServerName>,
|
||||
timeout_ms: Duration,
|
||||
) -> Result<FileMeta> {
|
||||
use media::get_content::v3::{Request, Response};
|
||||
|
||||
let mut request = Request::new(mxc.media_id.into(), mxc.server_name.into());
|
||||
request.allow_remote = true;
|
||||
request.allow_redirect = true;
|
||||
request.timeout_ms = timeout_ms;
|
||||
|
||||
let Response {
|
||||
file, content_type, content_disposition, ..
|
||||
} = self
|
||||
.federation_request_legacy_media(mxc, server, request)
|
||||
.await?;
|
||||
|
||||
let content = Content::new(file, content_type.unwrap(), content_disposition.unwrap());
|
||||
|
||||
self.handle_content_file(mxc, user, content).await
|
||||
}
|
||||
|
||||
async fn handle_thumbnail_file(
|
||||
&self,
|
||||
mxc: &Mxc<'_>,
|
||||
@@ -319,108 +238,6 @@ impl super::Service {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn federation_request_legacy_media<'i, Request>(
|
||||
&self,
|
||||
mxc: &Mxc<'_>,
|
||||
server: Option<&ServerName>,
|
||||
request: Request,
|
||||
) -> Result<Request::IncomingResponse>
|
||||
where
|
||||
Request: OutgoingRequest<
|
||||
Authentication = NoAccessToken,
|
||||
PathBuilder: PathBuilder<Input<'i>: FederationPathBuilderInput>,
|
||||
> + Debug
|
||||
+ Send,
|
||||
{
|
||||
self.services
|
||||
.sending
|
||||
.send_legacy_media_request(server.unwrap_or(mxc.server_name), request)
|
||||
.await
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub async fn fetch_remote_thumbnail_legacy(
|
||||
&self,
|
||||
body: &media::get_content_thumbnail::v3::Request,
|
||||
) -> Result<media::get_content_thumbnail::v3::Response> {
|
||||
let mxc = Mxc {
|
||||
server_name: &body.server_name,
|
||||
media_id: &body.media_id,
|
||||
};
|
||||
|
||||
let mut request = media::get_content_thumbnail::v3::Request::new(
|
||||
body.media_id.clone(),
|
||||
body.server_name.clone(),
|
||||
body.width,
|
||||
body.height,
|
||||
);
|
||||
request.method.clone_from(&body.method);
|
||||
request.allow_remote = body.allow_remote;
|
||||
request.allow_redirect = body.allow_redirect;
|
||||
request.animated = body.animated;
|
||||
request.timeout_ms = body.timeout_ms;
|
||||
|
||||
self.check_legacy_freeze()?;
|
||||
self.check_fetch_authorized(&mxc)?;
|
||||
let response = self
|
||||
.services
|
||||
.sending
|
||||
.send_legacy_media_request(mxc.server_name, request)
|
||||
.await?;
|
||||
|
||||
let dim = Dim::from_ruma(body.width, body.height, body.method.clone())?;
|
||||
self.upload_thumbnail(
|
||||
&mxc,
|
||||
None,
|
||||
None,
|
||||
response.content_type.as_deref(),
|
||||
&dim,
|
||||
&response.file,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub async fn fetch_remote_content_legacy(
|
||||
&self,
|
||||
mxc: &Mxc<'_>,
|
||||
allow_redirect: bool,
|
||||
timeout_ms: Duration,
|
||||
) -> Result<media::get_content::v3::Response, Error> {
|
||||
let mut request =
|
||||
media::get_content::v3::Request::new(mxc.media_id.into(), mxc.server_name.into());
|
||||
request.allow_remote = true;
|
||||
request.allow_redirect = allow_redirect;
|
||||
request.timeout_ms = timeout_ms;
|
||||
|
||||
self.check_legacy_freeze()?;
|
||||
self.check_fetch_authorized(mxc)?;
|
||||
let response = self
|
||||
.services
|
||||
.sending
|
||||
.send_legacy_media_request(mxc.server_name, request)
|
||||
.await?;
|
||||
|
||||
let content_disposition = make_content_disposition(
|
||||
response.content_disposition.as_ref(),
|
||||
response.content_type.as_deref(),
|
||||
None,
|
||||
);
|
||||
|
||||
self.create(
|
||||
mxc,
|
||||
None,
|
||||
Some(&content_disposition),
|
||||
response.content_type.as_deref(),
|
||||
&response.file,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
fn check_fetch_authorized(&self, mxc: &Mxc<'_>) -> Result<()> {
|
||||
if self
|
||||
.services
|
||||
@@ -436,13 +253,4 @@ impl super::Service {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_legacy_freeze(&self) -> Result<()> {
|
||||
self.services
|
||||
.server
|
||||
.config
|
||||
.freeze_legacy_media
|
||||
.then_some(())
|
||||
.ok_or(err!(Request(NotFound("Remote media is frozen."))))
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ use conduwuit::{
|
||||
},
|
||||
warn,
|
||||
};
|
||||
use database::Json;
|
||||
use database::{Deserialized, Ignore, Json};
|
||||
use futures::{FutureExt, StreamExt, TryStreamExt};
|
||||
use itertools::Itertools;
|
||||
use ruma::{
|
||||
@@ -173,6 +173,9 @@ migration!(stringify!($name) => $name)
|
||||
// Re-calculates extremities for any rooms that actually lack any
|
||||
// extremities at all.
|
||||
migration!(consistency_check_extremity_tracker),
|
||||
// This is backwards compatible because old versions never read the
|
||||
// account data entries it removes.
|
||||
migration!(remove_replaced_account_data),
|
||||
]
|
||||
};
|
||||
|
||||
@@ -1018,6 +1021,35 @@ async fn remove_unknown_extremities(services: &Services) -> Result {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_replaced_account_data(services: &Services) -> Result {
|
||||
type Key = (Option<OwnedRoomId>, OwnedUserId, u64, String);
|
||||
type Latest = (Ignore, Ignore, u64, Ignore);
|
||||
|
||||
let entries = services.db["roomuserdataid_accountdata"].clone();
|
||||
let latest_of_type = services.db["roomusertype_roomuserdataid"].clone();
|
||||
|
||||
let keys: Vec<Key> = entries.keys().ignore_err().collect().await;
|
||||
let mut removed: usize = 0;
|
||||
for (room_id, user_id, count, event_type) in &keys {
|
||||
let latest = latest_of_type
|
||||
.qry(&(room_id, user_id, event_type))
|
||||
.await
|
||||
.deserialized::<Latest>();
|
||||
|
||||
if latest.is_ok_and(|(_, _, latest, _)| latest != *count) {
|
||||
entries.del((room_id, user_id, count, event_type));
|
||||
removed = removed.saturating_add(1);
|
||||
}
|
||||
}
|
||||
|
||||
info!(
|
||||
total = keys.len(),
|
||||
?removed,
|
||||
"Removed replaced entries in 'roomuserdataid_accountdata'."
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn consistency_check_extremity_tracker(services: &Services) -> Result {
|
||||
let mut rooms = services.rooms.metadata.iter_ids();
|
||||
|
||||
+4
-2
@@ -42,6 +42,8 @@ pub mod transactions;
|
||||
pub mod uiaa;
|
||||
pub mod users;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
pub(crate) use service::{Args, Dep, Service};
|
||||
|
||||
pub use crate::services::Services;
|
||||
@@ -51,8 +53,8 @@ conduwuit::mod_dtor! {}
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use conduwuit::matrix::versions::{unstable_features, versions};
|
||||
use conduwuit::matrix::versions::versions;
|
||||
use ruma::api::SupportedVersions;
|
||||
|
||||
pub static SUPPORTED_VERSIONS: LazyLock<SupportedVersions> =
|
||||
LazyLock::new(|| SupportedVersions::from_parts(&versions(), &unstable_features()));
|
||||
LazyLock::new(|| SupportedVersions::from_parts(&versions(), &BTreeMap::new()));
|
||||
+73
-45
@@ -2,17 +2,17 @@ use std::{collections::HashMap, str::FromStr, sync::Arc, time::Duration};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{
|
||||
Result,
|
||||
Result, SyncRwLock,
|
||||
config::{OidcConfig, OidcProfileKeyImportMode},
|
||||
debug, err, error, info, warn,
|
||||
};
|
||||
use database::{Deserialized, Map};
|
||||
use lettre::Address;
|
||||
use openidconnect::{
|
||||
AdditionalClaims, AuthorizationCode, ClientSecret, CsrfToken, EmptyExtraTokenFields,
|
||||
EndpointMaybeSet, EndpointNotSet, EndpointSet, IdTokenClaims, IdTokenFields, IssuerUrl,
|
||||
Nonce, PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, StandardErrorResponse,
|
||||
StandardTokenResponse, TokenResponse,
|
||||
AdditionalClaims, AuthorizationCode, ClaimsVerificationError, ClientSecret, CsrfToken,
|
||||
EmptyExtraTokenFields, EndpointMaybeSet, EndpointNotSet, EndpointSet, IdTokenClaims,
|
||||
IdTokenFields, IssuerUrl, Nonce, PkceCodeChallenge, PkceCodeVerifier, RedirectUrl,
|
||||
SignatureVerificationError, StandardErrorResponse, StandardTokenResponse, TokenResponse,
|
||||
core::{
|
||||
CoreAuthDisplay, CoreAuthPrompt, CoreAuthenticationFlow, CoreErrorResponseType,
|
||||
CoreGenderClaim, CoreJsonWebKey, CoreJweContentEncryptionAlgorithm,
|
||||
@@ -60,7 +60,7 @@ struct Services {
|
||||
struct OidcClient {
|
||||
config: OidcConfig,
|
||||
client_secret: ClientSecret,
|
||||
machine: SetOnce<OidcClientMachine>,
|
||||
machine: SetOnce<SyncRwLock<Arc<OidcClientMachine>>>,
|
||||
client: reqwest::Client,
|
||||
}
|
||||
|
||||
@@ -180,31 +180,10 @@ impl crate::Service for Service {
|
||||
}
|
||||
|
||||
async fn worker(self: Arc<Self>) -> Result {
|
||||
if let Some(OidcClient { config, client_secret, machine, client }) = &self.client {
|
||||
let redirect_url = self
|
||||
.services
|
||||
.config
|
||||
.get_client_domain()
|
||||
.join(&format!("{}/oidc/complete", conduwuit::ROUTE_PREFIX))
|
||||
.expect("redirect url should be valid");
|
||||
|
||||
let provider_metadata = CoreProviderMetadata::discover_async(
|
||||
IssuerUrl::new(config.discovery_url.clone())
|
||||
.map_err(|err| err!("Failed to parse OIDC discovery URL: {err}"))?,
|
||||
client,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| err!("Failed to discover OIDC provider metadata: {err}"))?;
|
||||
|
||||
if let Some(OidcClient { machine, .. }) = &self.client {
|
||||
let discovered = self.discover().await?;
|
||||
machine
|
||||
.set(
|
||||
OidcClientMachine::from_provider_metadata(
|
||||
provider_metadata,
|
||||
config.client_id.clone(),
|
||||
Some(client_secret.clone()),
|
||||
)
|
||||
.set_redirect_uri(RedirectUrl::from_url(redirect_url)),
|
||||
)
|
||||
.set(SyncRwLock::new(Arc::new(discovered)))
|
||||
.expect("machine should be empty");
|
||||
}
|
||||
|
||||
@@ -224,6 +203,33 @@ impl Service {
|
||||
|
||||
pub fn enabled(&self) -> bool { self.client.is_some() }
|
||||
|
||||
async fn discover(&self) -> Result<OidcClientMachine> {
|
||||
let OidcClient { config, client_secret, client, .. } =
|
||||
self.client.as_ref().expect("oidc should be configured");
|
||||
|
||||
let redirect_url = self
|
||||
.services
|
||||
.config
|
||||
.get_client_domain()
|
||||
.join(&format!("{}/oidc/complete", conduwuit::ROUTE_PREFIX))
|
||||
.expect("redirect url should be valid");
|
||||
|
||||
let provider_metadata = CoreProviderMetadata::discover_async(
|
||||
IssuerUrl::new(config.discovery_url.clone())
|
||||
.map_err(|err| err!("Failed to parse OIDC discovery URL: {err}"))?,
|
||||
client,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| err!("Failed to discover OIDC provider metadata: {err}"))?;
|
||||
|
||||
Ok(OidcClientMachine::from_provider_metadata(
|
||||
provider_metadata,
|
||||
config.client_id.clone(),
|
||||
Some(client_secret.clone()),
|
||||
)
|
||||
.set_redirect_uri(RedirectUrl::from_url(redirect_url)))
|
||||
}
|
||||
|
||||
pub fn provider_name(&self) -> Option<String> {
|
||||
let OidcClient { config, .. } = self.client.as_ref().expect("oidc should be configured");
|
||||
|
||||
@@ -253,7 +259,7 @@ impl Service {
|
||||
pub async fn begin_session(&self, prompt: Option<CoreAuthPrompt>) -> (PendingSession, Url) {
|
||||
let OidcClient { machine, config, .. } =
|
||||
self.client.as_ref().expect("oidc should be configured");
|
||||
let machine = machine.wait().await;
|
||||
let machine = machine.wait().await.read().clone();
|
||||
|
||||
let (pkce_challenge, pkce_verifier) = PkceCodeChallenge::new_random_sha256();
|
||||
|
||||
@@ -284,13 +290,13 @@ impl Service {
|
||||
return Err("Delegated authentication is not enabled on this server.");
|
||||
};
|
||||
|
||||
let machine = machine.wait().await;
|
||||
let current = machine.wait().await.read().clone();
|
||||
|
||||
if session.csrf_token.into_secret() != response.state {
|
||||
return Err("State mismatch.");
|
||||
}
|
||||
|
||||
let token_response = machine
|
||||
let token_response = current
|
||||
.exchange_code(AuthorizationCode::new(response.code))
|
||||
.expect("machine should be configured correctly")
|
||||
.set_pkce_verifier(session.pkce_verifier)
|
||||
@@ -307,19 +313,41 @@ impl Service {
|
||||
return Err(Self::SERVER_MISCONFIGURED);
|
||||
};
|
||||
|
||||
let verifier = machine
|
||||
.id_token_verifier()
|
||||
.set_other_audience_verifier_fn(|audience| {
|
||||
config.additional_trusted_audiences.contains(audience)
|
||||
});
|
||||
let verify = |machine: &OidcClientMachine| {
|
||||
let verifier =
|
||||
machine
|
||||
.id_token_verifier()
|
||||
.set_other_audience_verifier_fn(|audience| {
|
||||
config.additional_trusted_audiences.contains(audience)
|
||||
});
|
||||
|
||||
let claims = id_token
|
||||
.claims(&verifier, &session.nonce)
|
||||
.map_err(|err| {
|
||||
error!("Failed to verify id token claims: {err}");
|
||||
Self::SERVER_MISCONFIGURED
|
||||
})?
|
||||
.to_owned();
|
||||
id_token
|
||||
.claims(&verifier, &session.nonce)
|
||||
.map(ToOwned::to_owned)
|
||||
};
|
||||
|
||||
let mut result = verify(¤t);
|
||||
|
||||
if matches!(
|
||||
result,
|
||||
Err(ClaimsVerificationError::SignatureVerification(
|
||||
SignatureVerificationError::NoMatchingKey
|
||||
))
|
||||
) {
|
||||
match self.discover().await {
|
||||
| Ok(discovered) => {
|
||||
info!("Refreshed OIDC provider metadata after an unknown signing key");
|
||||
result = verify(&discovered);
|
||||
*machine.wait().await.write() = Arc::new(discovered);
|
||||
},
|
||||
| Err(err) => warn!("Failed to refresh OIDC provider metadata: {err}"),
|
||||
}
|
||||
}
|
||||
|
||||
let claims = result.map_err(|err| {
|
||||
error!("Failed to verify id token claims: {err}");
|
||||
Self::SERVER_MISCONFIGURED
|
||||
})?;
|
||||
|
||||
info!(subject = claims.subject().as_str(), "Authenticated subject");
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ use conduwuit::error;
|
||||
use conduwuit::{
|
||||
Err, Event, PduEvent, Result, debug, debug_info, debug_warn, err,
|
||||
result::{FlatOk, LogErr},
|
||||
state_res::lexicographical_topological_sort,
|
||||
trace,
|
||||
utils::{IterStream, math::Expected, stream::BroadbandExt},
|
||||
warn,
|
||||
@@ -22,9 +23,7 @@ use ruma::{
|
||||
int,
|
||||
room_version_rules::RoomVersionRules,
|
||||
};
|
||||
use ruma::events::room::power_levels::UserPowerLevel;
|
||||
use ruma::state_res::utils::event_id_map::EventIdMap;
|
||||
use conduwuit::debug::DebugInspect;
|
||||
|
||||
use super::get_room_version_rules;
|
||||
use crate::rooms::event_handler::parse_incoming_pdu::expect_event_id_array;
|
||||
|
||||
@@ -65,7 +64,8 @@ pub async fn build_local_dag(
|
||||
return Ok(pdu_map.keys().cloned().collect());
|
||||
}
|
||||
|
||||
let mut dag = EventIdMap::with_capacity(pdu_map.len());
|
||||
let mut dag: HashMap<OwnedEventId, HashSet<OwnedEventId>> =
|
||||
HashMap::with_capacity(pdu_map.len());
|
||||
let mut id_origin_ts: HashMap<OwnedEventId, _> = HashMap::with_capacity(pdu_map.len());
|
||||
|
||||
for (event_id, value) in pdu_map {
|
||||
@@ -94,16 +94,17 @@ pub async fn build_local_dag(
|
||||
}
|
||||
|
||||
debug!(count = dag.len(), "Sorting incoming events with partial graph");
|
||||
ruma::state_res::reverse_topological_power_sort(&dag, |node_id| {
|
||||
lexicographical_topological_sort(&dag, &async |node_id| {
|
||||
// Note: we don't bother fetching power levels because that would
|
||||
// massively slow this function down. This is a best-effort attempt to
|
||||
// order events correctly for processing, however ultimately that
|
||||
// should be the sender's job.
|
||||
let ts = id_origin_ts.get(node_id).copied().unwrap_or_default();
|
||||
Ok((UserPowerLevel::Infinite, MilliSecondsSinceUnixEpoch(ts)))
|
||||
let ts = id_origin_ts.get(&node_id).copied().unwrap_or_default();
|
||||
Ok((int!(0), MilliSecondsSinceUnixEpoch(ts)))
|
||||
})
|
||||
.debug_inspect(|sorted| {
|
||||
assert_eq!(
|
||||
.await
|
||||
.inspect(|sorted| {
|
||||
debug_assert_eq!(
|
||||
sorted.len(),
|
||||
pdu_map.len(),
|
||||
"Sorted graph was not the same size as the input graph"
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use std::collections::{HashMap, hash_map};
|
||||
|
||||
use conduwuit::{
|
||||
Err, Event, EventTypeExt, PduEvent, Result, debug_info, err, warn,
|
||||
};
|
||||
use conduwuit::{Err, Event, EventTypeExt, PduEvent, Result, err, warn};
|
||||
use ruma::{
|
||||
OwnedEventId, ServerName, api::federation::authorization::get_event_authorization,
|
||||
room_version_rules::RoomVersionRules,
|
||||
@@ -193,8 +191,15 @@ impl super::Service {
|
||||
},
|
||||
}
|
||||
}
|
||||
if let Some(msg) = self.auth_state_check_4(&pdu, room_version_rules) {
|
||||
debug_info!("Rejecting auth chain event {event_id}: {msg}");
|
||||
if !self
|
||||
.auth_state_check_4(
|
||||
&pdu,
|
||||
room_version_rules,
|
||||
create_event.as_pdu(),
|
||||
&auth_events_by_key,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
self.reject_and_persist(&event_id, &pdu.to_canonical_object());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,10 +195,18 @@ impl super::Service {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(msg) = self.auth_state_check_4(&pdu_event, &room_version_rules) {
|
||||
if !self
|
||||
.auth_state_check_4(
|
||||
&pdu_event,
|
||||
&room_version_rules,
|
||||
create_event.as_pdu(),
|
||||
&auth_events_by_key,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
self.reject_and_persist(event_id, &incoming_pdu);
|
||||
return Err!(Request(Forbidden(debug_warn!(
|
||||
"Event authorisation fails based on event's claimed auth events: {msg}"
|
||||
"Event authorisation fails based on event's claimed auth events"
|
||||
))));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,14 +17,10 @@ use std::{collections::HashMap, fmt::Write, sync::Arc, time::Instant};
|
||||
|
||||
use assign::assign;
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{
|
||||
Err, Error, Event, PduEvent, Result, Server, SyncRwLock,
|
||||
utils::{MutexMap, TryFutureExtExt},
|
||||
};
|
||||
use conduwuit::{Err, Error, Event, PduEvent, Result, Server, SyncRwLock, utils::MutexMap};
|
||||
pub use fetch_and_handle_outliers::{
|
||||
DagBuilderTree, GET_MISSING_EVENTS_MAX_BATCH_SIZE, build_local_dag,
|
||||
};
|
||||
use futures::future::ok;
|
||||
use http::StatusCode;
|
||||
use ruma::{
|
||||
EventId, OwnedEventId, OwnedRoomId, OwnedServerName,
|
||||
@@ -135,8 +131,8 @@ impl Service {
|
||||
}
|
||||
|
||||
/// Fetches a single PDU, returning None if there is an error.
|
||||
fn event_fetch(&self, event_id: &EventId) -> Option<PduEvent> {
|
||||
self.services.timeline.get_pdu_blocking(event_id).ok()
|
||||
async fn event_fetch(&self, event_id: OwnedEventId) -> Option<PduEvent> {
|
||||
self.services.timeline.get_pdu(&event_id).await.ok()
|
||||
}
|
||||
|
||||
/// Returns a rate-limit error if the requested event had a recent failed
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||
use base64::Engine;
|
||||
use conduwuit::{
|
||||
Err, Event, EventTypeExt, PduEvent, Result, debug, debug::DebugInspect, debug_error,
|
||||
debug_info, err, info, matrix::StateKey, trace,
|
||||
debug_info, err, info, matrix::StateKey, state_res, trace,
|
||||
};
|
||||
use futures::future::ready;
|
||||
use ruma::{
|
||||
@@ -12,8 +12,6 @@ use ruma::{
|
||||
canonical_json::redact,
|
||||
events::StateEventType,
|
||||
room_version_rules::{EventIdFormatVersion, RoomVersionRules},
|
||||
state_res,
|
||||
state_res::check_state_independent_auth_rules,
|
||||
};
|
||||
|
||||
use crate::rooms::{
|
||||
@@ -146,21 +144,24 @@ impl super::Service {
|
||||
/// Checks PDU check 4: Passes authorisation rules based on the event's auth
|
||||
/// events ([spec]).
|
||||
///
|
||||
/// If the auth check fails, the error message is returned, otherwise
|
||||
/// `None`.
|
||||
/// If the auth check fails, false is returned, otherwise true.
|
||||
///
|
||||
/// [spec]: https://spec.matrix.org/v1.19/server-server-api/#checks-performed-on-receipt-of-a-pdu
|
||||
pub fn auth_state_check_4(
|
||||
pub async fn auth_state_check_4(
|
||||
&self,
|
||||
pdu: &PduEvent,
|
||||
room_version_rules: &RoomVersionRules,
|
||||
) -> Option<String> {
|
||||
match check_state_independent_auth_rules(&room_version_rules.authorization, pdu, |e| {
|
||||
self.event_fetch(e)
|
||||
}) {
|
||||
| Ok(_) => None,
|
||||
| Err(msg) => Some(msg),
|
||||
}
|
||||
create_event: &PduEvent,
|
||||
auth_events_by_key: &HashMap<(StateEventType, StateKey), PduEvent>,
|
||||
) -> Result<bool> {
|
||||
let state_fetch = |ty: &StateEventType, sk: &str| {
|
||||
let key = (ty.to_owned(), sk.into());
|
||||
ready(auth_events_by_key.get(&key).map(ToOwned::to_owned))
|
||||
};
|
||||
|
||||
state_res::event_auth::auth_check(room_version_rules, pdu, state_fetch, create_event)
|
||||
.await
|
||||
.map_err(|e| err!("Event self-authentication failed: {e:?}"))
|
||||
}
|
||||
|
||||
/// Checks that the event passes PDU check 5, which ensures that the event
|
||||
@@ -176,7 +177,7 @@ impl super::Service {
|
||||
room_version_rules: &RoomVersionRules,
|
||||
create_event: &PduEvent,
|
||||
origin: &ServerName,
|
||||
) -> Result<(Option<String>, HashMap<u64, OwnedEventId>)> {
|
||||
) -> Result<(bool, HashMap<u64, OwnedEventId>)> {
|
||||
debug!(
|
||||
event_id = %incoming_pdu.event_id,
|
||||
"Resolving state at event"
|
||||
@@ -217,27 +218,29 @@ impl super::Service {
|
||||
}
|
||||
trace!(state_events = state_before.len(), "Calculated incoming state");
|
||||
|
||||
let state_fetch_state = &state_before;
|
||||
let state_fetch = |k: StateEventType, s: StateKey| async move {
|
||||
let shortstatekey = self.services.short.get_shortstatekey(&k, &s).await.ok()?;
|
||||
|
||||
let event_id = state_fetch_state.get(&shortstatekey)?;
|
||||
self.services.timeline.get_pdu(event_id).await.ok()
|
||||
};
|
||||
|
||||
debug!(
|
||||
event_id = %incoming_pdu.event_id,
|
||||
"Running state-before auth check"
|
||||
);
|
||||
|
||||
// PDU check: 5
|
||||
let state_fetch_state = &state_before;
|
||||
let auth_result = state_res::check_state_dependent_auth_rules(
|
||||
&room_version_rules.authorization,
|
||||
let auth_check = state_res::event_auth::auth_check(
|
||||
room_version_rules,
|
||||
incoming_pdu,
|
||||
|event_type, state_key| {
|
||||
let ssk = self
|
||||
.services
|
||||
.short
|
||||
.get_shortstatekey_blocking(event_type, state_key)
|
||||
.ok()?;
|
||||
let event_id = state_fetch_state.get(&ssk)?;
|
||||
self.services.timeline.get_pdu_blocking(event_id).ok()
|
||||
},
|
||||
);
|
||||
Ok((auth_result.err(), state_before))
|
||||
|ty, sk| state_fetch(ty.clone(), sk.into()),
|
||||
create_event.as_pdu(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| err!(Request(Forbidden("Auth check failed: {e:?}"))))?;
|
||||
Ok((auth_check, state_before))
|
||||
}
|
||||
|
||||
/// Checks that the event passes PDU check 6, which ensures that the event
|
||||
@@ -250,7 +253,8 @@ impl super::Service {
|
||||
&self,
|
||||
incoming_pdu: &PduEvent,
|
||||
room_version_rules: &RoomVersionRules,
|
||||
) -> Result<(), String> {
|
||||
create_event: &PduEvent,
|
||||
) -> Result<bool> {
|
||||
debug!(
|
||||
event_id = %incoming_pdu.event_id,
|
||||
"Gathering auth events"
|
||||
@@ -266,22 +270,25 @@ impl super::Service {
|
||||
incoming_pdu.content(),
|
||||
room_version_rules,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.await?;
|
||||
|
||||
let state_fetch = |k: &StateEventType, s: &str| {
|
||||
let key = k.with_state_key(s);
|
||||
ready(auth_events.get(&key).map(ToOwned::to_owned))
|
||||
};
|
||||
|
||||
debug!(
|
||||
event_id = %incoming_pdu.event_id,
|
||||
"Running current state auth check"
|
||||
);
|
||||
state_res::check_state_dependent_auth_rules(
|
||||
&room_version_rules.authorization,
|
||||
state_res::event_auth::auth_check(
|
||||
room_version_rules,
|
||||
incoming_pdu,
|
||||
|t, s| {
|
||||
auth_events
|
||||
.get(&(t.to_owned(), s.to_owned()))
|
||||
.map(ToOwned::to_owned)
|
||||
},
|
||||
state_fetch,
|
||||
create_event.as_pdu(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| err!(Request(Forbidden("Auth check failed: {e:?}"))))
|
||||
}
|
||||
|
||||
/// Performs PDU check 7 - does the policy server allow this event.
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
|
||||
use std::{collections::BTreeMap, time::Duration};
|
||||
|
||||
use conduwuit::{debug, debug_error, debug_info, debug_warn, err, error,
|
||||
info, trace, utils::to_canonical_object, warn, Err, Error, Event, EventTypeExt, PduEvent, Result};
|
||||
use conduwuit::{
|
||||
Err, Error, Event, PduEvent, Result, debug, debug_error, debug_info, debug_warn, err, error,
|
||||
info, state_res::EventTypeExt, trace, utils::to_canonical_object, warn,
|
||||
};
|
||||
use http::StatusCode;
|
||||
use ruma::{
|
||||
CanonicalJsonObject, CanonicalJsonValue, KeyId, RoomId, ServerName, SigningKeyAlgorithm,
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
collections::{HashMap, HashSet, VecDeque},
|
||||
collections::{HashMap, HashSet},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use conduwuit::{
|
||||
Error, Result, err,
|
||||
state_res::{self, StateMap},
|
||||
trace,
|
||||
utils::stream::{IterStream, ReadyExt, TryWidebandExt, WidebandExt},
|
||||
warn,
|
||||
};
|
||||
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, future::try_join};
|
||||
use itertools::cloned;
|
||||
use ruma::{
|
||||
EventId, OwnedEventId, RoomId,
|
||||
room_version_rules::RoomVersionRules,
|
||||
state_res::{Event, utils::event_id_set::EventIdSet},
|
||||
};
|
||||
use ruma::{OwnedEventId, RoomId, room_version_rules::RoomVersionRules};
|
||||
|
||||
use crate::rooms::state_compressor::CompressedState;
|
||||
|
||||
impl super::Service {
|
||||
/// Resolves the state based on the incoming fork states with the given room
|
||||
/// version rules.
|
||||
pub async fn resolve_state(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
@@ -55,7 +48,7 @@ impl super::Service {
|
||||
.event_ids_iter(room_id, state.values().map(Borrow::borrow))
|
||||
.try_collect()
|
||||
})
|
||||
.try_collect::<Vec<EventIdSet<OwnedEventId>>>();
|
||||
.try_collect::<Vec<HashSet<OwnedEventId>>>();
|
||||
|
||||
let fork_states = fork_states
|
||||
.iter()
|
||||
@@ -67,19 +60,19 @@ impl super::Service {
|
||||
.short
|
||||
.multi_get_statekey_from_short(shortstatekeys)
|
||||
.zip(event_ids)
|
||||
.ready_filter_map(|(ty_sk, id)| {
|
||||
Some((ty_sk.ok().map(|(k, s)| (k, s.to_string()))?, id))
|
||||
})
|
||||
.ready_filter_map(|(ty_sk, id)| Some((ty_sk.ok()?, id)))
|
||||
.collect()
|
||||
})
|
||||
.map(Ok::<_, Error>)
|
||||
.try_collect::<Vec<ruma::state_res::StateMap<OwnedEventId>>>();
|
||||
.try_collect::<Vec<StateMap<OwnedEventId>>>();
|
||||
|
||||
let (fork_states, auth_chain_sets) = try_join(fork_states, auth_chain_sets).await?;
|
||||
|
||||
trace!("Resolving state");
|
||||
let state =
|
||||
self.state_resolution(room_version_rules, fork_states.as_slice(), auth_chain_sets)?;
|
||||
let state = self
|
||||
.state_resolution(room_version_rules, fork_states.iter(), &auth_chain_sets)
|
||||
.boxed()
|
||||
.await?;
|
||||
|
||||
trace!("State resolution done.");
|
||||
let state_events: Vec<_> = state
|
||||
@@ -105,72 +98,25 @@ impl super::Service {
|
||||
Ok(Arc::new(new_room_state))
|
||||
}
|
||||
|
||||
/// Actually performs state resolution from the given state sets, auth chain
|
||||
/// sets, and room version rules.
|
||||
pub fn state_resolution<'a>(
|
||||
pub async fn state_resolution<'a, StateSets>(
|
||||
&'a self,
|
||||
room_version_rules: &'a RoomVersionRules,
|
||||
state_sets: &[ruma::state_res::StateMap<OwnedEventId>],
|
||||
auth_chain_sets: Vec<EventIdSet<OwnedEventId>>,
|
||||
) -> Result<ruma::state_res::StateMap<OwnedEventId>> {
|
||||
state_sets: StateSets,
|
||||
auth_chain_sets: &'a [HashSet<OwnedEventId>],
|
||||
) -> Result<StateMap<OwnedEventId>>
|
||||
where
|
||||
StateSets: Iterator<Item = &'a StateMap<OwnedEventId>> + Clone + Send,
|
||||
{
|
||||
let event_fetch = |event_id| self.event_fetch(event_id);
|
||||
let calc_subgraph = |ss| self.calculate_conflicted_state_subgraph(ss).ok();
|
||||
ruma::state_res::resolve(
|
||||
&room_version_rules.authorization,
|
||||
&room_version_rules
|
||||
.state_res
|
||||
.v2_rules()
|
||||
.expect("can only use state resolution v2 rules"),
|
||||
let event_exists = |event_id| self.event_exists(event_id);
|
||||
state_res::resolve(
|
||||
room_version_rules,
|
||||
state_sets,
|
||||
auth_chain_sets,
|
||||
event_fetch,
|
||||
calc_subgraph,
|
||||
&event_fetch,
|
||||
&event_exists,
|
||||
)
|
||||
.map_err(|e| err!(error!("state resolution failed: {e:?}")))
|
||||
}
|
||||
|
||||
/// Calculates the conflicted state subgraph for state resolution.
|
||||
fn calculate_conflicted_state_subgraph<'a>(
|
||||
&self,
|
||||
state_set: &ruma::state_res::StateMap<&'a EventId>,
|
||||
) -> Result<HashSet<&'a EventId>> {
|
||||
let conflicted_events: HashSet<_> = state_set.values().cloned().collect();
|
||||
let mut subgraph: HashSet<_> = HashSet::new();
|
||||
let mut stack: Vec<Vec<_>> = vec![conflicted_events.iter().cloned().collect::<Vec<_>>()];
|
||||
let mut path: Vec<_> = Vec::new();
|
||||
let mut seen: HashSet<_> = HashSet::new();
|
||||
let next_event = |stack: &mut Vec<Vec<_>>, path: &mut Vec<_>| {
|
||||
while stack.last().is_some_and(Vec::is_empty) {
|
||||
stack.pop();
|
||||
path.pop();
|
||||
}
|
||||
stack.last_mut().and_then(Vec::pop)
|
||||
};
|
||||
while let Some(event_id) = next_event(&mut stack, &mut path) {
|
||||
path.push(event_id.clone());
|
||||
if subgraph.contains(&event_id) {
|
||||
if path.len() > 1 {
|
||||
subgraph.extend(path.iter().cloned());
|
||||
}
|
||||
path.pop();
|
||||
continue;
|
||||
}
|
||||
if conflicted_events.contains(&event_id) && path.len() > 1 {
|
||||
subgraph.extend(path.iter().cloned());
|
||||
}
|
||||
if seen.contains(&event_id) {
|
||||
path.pop();
|
||||
continue;
|
||||
}
|
||||
trace!(event_id = event_id.as_str(), "fetching event for its auth events");
|
||||
let Some(evt) = self.event_fetch(event_id.clone()) else {
|
||||
warn!("could not fetch event {} to calculate conflicted subgraph", event_id);
|
||||
path.pop();
|
||||
continue;
|
||||
};
|
||||
stack.push(evt.auth_events().collect());
|
||||
seen.insert(event_id);
|
||||
}
|
||||
Ok(subgraph)
|
||||
.map_err(|e| err!(error!("State resolution failed: {e:?}")))
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,13 @@ use std::{
|
||||
|
||||
use conduwuit::{
|
||||
Result, debug, debug_error, err, error,
|
||||
matrix::{Event, StateMap},
|
||||
trace,
|
||||
utils::stream::{BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, TryWidebandExt},
|
||||
};
|
||||
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, future::try_join};
|
||||
use ruma::{room_version_rules::RoomVersionRules, EventId, OwnedEventId, RoomId};
|
||||
use ruma::state_res::{Event, StateMap};
|
||||
use ruma::state_res::utils::event_id_set::EventIdSet;
|
||||
use ruma::{OwnedEventId, RoomId, room_version_rules::RoomVersionRules};
|
||||
|
||||
use crate::rooms::short::ShortStateHash;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -30,7 +30,7 @@ impl super::Service {
|
||||
room_version_rules: &RoomVersionRules,
|
||||
) -> Result<Option<HashMap<u64, OwnedEventId>>>
|
||||
where
|
||||
Pdu: Event<Id = EventId> + Send + Sync,
|
||||
Pdu: Event + Send + Sync,
|
||||
{
|
||||
if incoming_pdu.prev_events().count() == 1 {
|
||||
self.state_before_incoming_degree_one(incoming_pdu).await
|
||||
@@ -48,7 +48,7 @@ impl super::Service {
|
||||
incoming_pdu: &Pdu,
|
||||
) -> Result<Option<HashMap<u64, OwnedEventId>>>
|
||||
where
|
||||
Pdu: Event<Id = EventId> + Send + Sync,
|
||||
Pdu: Event + Send + Sync,
|
||||
{
|
||||
let prev_event = incoming_pdu
|
||||
.prev_events()
|
||||
@@ -109,11 +109,8 @@ impl super::Service {
|
||||
room_version_rules: &RoomVersionRules,
|
||||
) -> Result<Option<HashMap<u64, OwnedEventId>>>
|
||||
where
|
||||
Pdu: Event<Id = EventId> + Send + Sync,
|
||||
Pdu: Event + Send + Sync,
|
||||
{
|
||||
if incoming_pdu.prev_events().count() == 0 {
|
||||
return Ok(None);
|
||||
}
|
||||
trace!("Calculating extremity statehashes...");
|
||||
let Ok(extremity_sstatehashes) = incoming_pdu
|
||||
.prev_events()
|
||||
@@ -138,8 +135,8 @@ impl super::Service {
|
||||
};
|
||||
|
||||
trace!("Calculating fork states...");
|
||||
let room_id = incoming_pdu.room_id().unwrap();
|
||||
let (fork_states, auth_chain_sets): (Vec<StateMap<_>>, Vec<EventIdSet<_>>) =
|
||||
let room_id = &incoming_pdu.room_id_or_hash();
|
||||
let (fork_states, auth_chain_sets): (Vec<StateMap<_>>, Vec<HashSet<_>>) =
|
||||
extremity_sstatehashes
|
||||
.into_iter()
|
||||
.try_stream()
|
||||
@@ -152,7 +149,9 @@ impl super::Service {
|
||||
.await?;
|
||||
|
||||
let Ok(new_state) = self
|
||||
.state_resolution(room_version_rules, fork_states.as_slice(), auth_chain_sets)
|
||||
.state_resolution(room_version_rules, fork_states.iter(), &auth_chain_sets)
|
||||
.boxed()
|
||||
.await
|
||||
.inspect_err(|e| error!("State resolution failed: {e:?}"))
|
||||
else {
|
||||
return Ok(None);
|
||||
@@ -183,7 +182,7 @@ impl super::Service {
|
||||
prev_event: Pdu,
|
||||
) -> Result<(StateMap<OwnedEventId>, HashSet<OwnedEventId>)>
|
||||
where
|
||||
Pdu: Event<Id = OwnedEventId>,
|
||||
Pdu: Event,
|
||||
{
|
||||
let mut leaf_state: HashMap<_, _> = self
|
||||
.services
|
||||
@@ -196,7 +195,7 @@ impl super::Service {
|
||||
let shortstatekey = self
|
||||
.services
|
||||
.short
|
||||
.get_or_create_shortstatekey(&prev_event.event_type().to_string().into(), state_key)
|
||||
.get_or_create_shortstatekey(&prev_event.kind().to_string().into(), state_key)
|
||||
.await;
|
||||
|
||||
let event_id = prev_event.event_id();
|
||||
@@ -217,10 +216,11 @@ impl super::Service {
|
||||
self.services
|
||||
.short
|
||||
.get_statekey_from_short(*k)
|
||||
.map_ok(|(ty, sk)| ((ty, sk.to_string()), id.clone()))
|
||||
.map_ok(|(ty, sk)| ((ty, sk), id.clone()))
|
||||
})
|
||||
.ready_filter_map(Result::ok)
|
||||
.collect();
|
||||
.collect()
|
||||
.map(Ok);
|
||||
|
||||
try_join(fork_state, auth_chain).await
|
||||
}
|
||||
|
||||
@@ -222,7 +222,9 @@ async fn test_services() -> (Arc<crate::Services>, std::path::PathBuf) {
|
||||
"database_path": path,
|
||||
"db_cache_capacity_mb": 16.0,
|
||||
"rocksdb_write_buffer_capacity_mb": 4.0,
|
||||
"allow_local_presence": false
|
||||
"allow_local_presence": false,
|
||||
"dns_servers": ["127.0.0.1"],
|
||||
"allow_invalid_tls_certificates_yes_i_know_what_the_fuck_i_am_doing_with_this_and_i_know_this_is_insecure": true
|
||||
}))
|
||||
.unwrap();
|
||||
let runtime = tokio::runtime::Handle::current();
|
||||
|
||||
@@ -65,14 +65,14 @@ impl super::Service {
|
||||
// perform PDU check 5 (event auth passes based on state before the
|
||||
// event). To do this, we either need to have all the prev events
|
||||
// locally, or ask a remote server for the state at the event.
|
||||
let (state_before_failure_reason, state_before) = self
|
||||
let (passes_state_before, state_before) = self
|
||||
.state_before_check_5(&incoming_pdu, &room_version_rules, create_event, origin)
|
||||
.await?;
|
||||
|
||||
if let Some(msg) = state_before_failure_reason {
|
||||
if !passes_state_before {
|
||||
self.reject_and_persist(incoming_pdu.event_id(), &val);
|
||||
return Err!(Request(Forbidden(debug_warn!(
|
||||
"Event authorisation fails based on the state before the event: {msg}"
|
||||
"Event authorisation fails based on the state before the event"
|
||||
))));
|
||||
}
|
||||
|
||||
@@ -90,16 +90,16 @@ impl super::Service {
|
||||
);
|
||||
let state_lock = self.services.state.mutex.lock(room_id).await;
|
||||
let passes_current_state = self
|
||||
.current_state_check_6(&incoming_pdu, &room_version_rules)
|
||||
.current_state_check_6(&incoming_pdu, &room_version_rules, create_event)
|
||||
.await
|
||||
.inspect_err(|reason| {
|
||||
debug_warn!(
|
||||
%reason,
|
||||
"Event authorisation fails based on the current room state - will be \
|
||||
soft-failed"
|
||||
);
|
||||
})
|
||||
.is_ok();
|
||||
.inspect(|passes| {
|
||||
if !*passes {
|
||||
debug_warn!(
|
||||
"Event authorisation fails based on the current room state - will be \
|
||||
soft-failed"
|
||||
);
|
||||
}
|
||||
})?;
|
||||
|
||||
// Determine whether this PDU should be soft-failed.
|
||||
// If the auth check failed, invariably yes. Otherwise, only if the user
|
||||
|
||||
@@ -7,7 +7,7 @@ use conduwuit::{
|
||||
event::{gen_event_id, gen_event_id_canonical_json},
|
||||
},
|
||||
pdu::PartialPdu,
|
||||
trace,
|
||||
state_res, trace,
|
||||
utils::{self, IterStream, ReadyExt, to_canonical_object},
|
||||
warn,
|
||||
};
|
||||
@@ -25,7 +25,7 @@ use ruma::{
|
||||
StateEventType, StaticEventContent,
|
||||
room::member::{MembershipState, RoomMemberEventContent},
|
||||
},
|
||||
room::{AllowRule, JoinRule, RoomMembership},
|
||||
room::{AllowRule, JoinRule, Restricted, RoomMembership},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -221,6 +221,9 @@ impl Service {
|
||||
// We couldn't authorize a local join, probably because it's
|
||||
// restricted and we couldn't satisfy
|
||||
// the join rules ourselves.
|
||||
if servers.is_empty() {
|
||||
return Err(err);
|
||||
}
|
||||
info!(?err, "Failed to join room locally, trying over federation instead");
|
||||
},
|
||||
}
|
||||
@@ -531,7 +534,7 @@ impl Service {
|
||||
return state;
|
||||
},
|
||||
};
|
||||
if !pdu_fits(&value.clone()) {
|
||||
if !pdu_fits(&value) {
|
||||
warn!(
|
||||
"dropping incoming PDU {event_id} in room {room_id} from room join \
|
||||
because it exceeds 65535 bytes or is otherwise too large."
|
||||
@@ -591,17 +594,13 @@ impl Service {
|
||||
|
||||
debug!("Running send_join auth check");
|
||||
let fetch_state = &state;
|
||||
let state_fetch = |k: StateEventType, s: StateKey| {
|
||||
let shortstatekey = self
|
||||
.services
|
||||
.short
|
||||
.get_shortstatekey_blocking(&k, &s)
|
||||
.ok()?;
|
||||
let state_fetch = |k: StateEventType, s: StateKey| async move {
|
||||
let shortstatekey = self.services.short.get_shortstatekey(&k, &s).await.ok()?;
|
||||
|
||||
let event_id = fetch_state.get(&shortstatekey)?;
|
||||
self.services.timeline.get_pdu_blocking(event_id).ok()
|
||||
self.services.timeline.get_pdu(event_id).await.ok()
|
||||
};
|
||||
if state_fetch(StateEventType::RoomCreate, "".into()).is_none() {
|
||||
let Some(create_event) = state_fetch(StateEventType::RoomCreate, "".into()).await else {
|
||||
let in_auth_chain = send_join_auth_chain
|
||||
.iter()
|
||||
.any(|(t, s)| t == "m.room.create" && s.is_empty());
|
||||
@@ -618,29 +617,20 @@ impl Service {
|
||||
};
|
||||
drop(send_join_auth_chain);
|
||||
|
||||
// TODO: These calls should be in a thread to avoid blocking the main
|
||||
// event loop.
|
||||
ruma::state_res::check_state_independent_auth_rules(
|
||||
&room_version.rules().unwrap().authorization,
|
||||
&parsed_join_pdu,
|
||||
|event_id| self.services.timeline.get_pdu_blocking(event_id).ok(),
|
||||
)
|
||||
.map_err(|e| {
|
||||
err!(Request(Forbidden(
|
||||
"Join event returned by {remote_server} is not self-authorised (try again?): {e}"
|
||||
)))
|
||||
})?;
|
||||
ruma::state_res::check_state_dependent_auth_rules(
|
||||
&room_version.rules().unwrap().authorization,
|
||||
let auth_check = state_res::event_auth::auth_check(
|
||||
&room_version.rules().unwrap(),
|
||||
&parsed_join_pdu,
|
||||
|k, s| state_fetch(k.clone(), s.into()),
|
||||
&create_event,
|
||||
)
|
||||
.map_err(|e| {
|
||||
err!(Request(Forbidden(
|
||||
"Join event returned by {remote_server} is not self-authorised (try again?): {e}"
|
||||
)))
|
||||
})?;
|
||||
.await
|
||||
.map_err(|e| err!(Request(Forbidden(warn!("Auth check failed: {e:?}")))))?;
|
||||
|
||||
if !auth_check {
|
||||
return Err!(Request(Forbidden(
|
||||
"Join event returned by {remote_server} is not self-authorised (try again?)"
|
||||
)));
|
||||
}
|
||||
let resident_before = self
|
||||
.services
|
||||
.state_cache
|
||||
@@ -858,7 +848,7 @@ impl Service {
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
entity: JoinConditionEntity<'_>,
|
||||
conditions: &ruma::room::Restricted,
|
||||
conditions: &Restricted,
|
||||
) -> JoinConditionResult {
|
||||
if conditions.allow.is_empty() {
|
||||
// This will never be authorisable, return forbidden.
|
||||
|
||||
@@ -154,15 +154,6 @@ impl Service {
|
||||
.deserialized()
|
||||
}
|
||||
|
||||
pub fn get_shortstatekey_blocking(
|
||||
&self,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<ShortStateKey> {
|
||||
let key = (event_type, state_key);
|
||||
self.db.shortstatekey_statekey.qry_blocking(&key).deserialized()
|
||||
}
|
||||
|
||||
/// Gets a full event ID from a short event ID.
|
||||
pub async fn get_eventid_from_short<Id>(&self, shorteventid: ShortEventId) -> Result<Id>
|
||||
where
|
||||
|
||||
@@ -5,6 +5,7 @@ use conduwuit::{debug, utils::stream::WidebandExt};
|
||||
use conduwuit_core::{
|
||||
Event, PduEvent, Result, err,
|
||||
result::FlatOk,
|
||||
state_res::{self, StateMap},
|
||||
utils::{
|
||||
IterStream, MutexMap, MutexMapGuard, ReadyExt, calculate_hash,
|
||||
stream::{BroadbandExt, TryIgnore},
|
||||
@@ -20,7 +21,6 @@ use ruma::{
|
||||
api::federation::membership::RawStrippedState,
|
||||
events::{StateEventType, TimelineEventType, room::create::RoomCreateEventContent},
|
||||
room_version_rules::RoomVersionRules,
|
||||
state_res,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -472,7 +472,7 @@ impl Service {
|
||||
state_key: Option<&str>,
|
||||
content: &serde_json::value::RawValue,
|
||||
room_version_rules: &RoomVersionRules,
|
||||
) -> Result<HashMap<(StateEventType, String), PduEvent>> {
|
||||
) -> Result<StateMap<PduEvent>> {
|
||||
let Ok(shortstatehash) = self.get_room_shortstatehash(room_id).await else {
|
||||
return Ok(HashMap::new());
|
||||
};
|
||||
@@ -482,9 +482,8 @@ impl Service {
|
||||
sender,
|
||||
state_key,
|
||||
content,
|
||||
&room_version_rules.authorization,
|
||||
)
|
||||
.map_err(|e| err!("failed to select auth types for event: {e:?}"))?;
|
||||
room_version_rules,
|
||||
)?;
|
||||
debug!(?auth_types, "Auth types for event");
|
||||
let sauthevents: HashMap<_, _> = auth_types
|
||||
.iter()
|
||||
|
||||
@@ -33,6 +33,16 @@ impl super::Service {
|
||||
return Err!(Request(Forbidden("Redacting m.room.create is not safe, forbidding.")));
|
||||
}
|
||||
|
||||
// Defense in depth, shouldn't be reachable
|
||||
if redacting_event
|
||||
.as_ref()
|
||||
.is_ok_and(|pdu| pdu.room_id() != Some(room_id))
|
||||
{
|
||||
return Err!(Request(Forbidden(
|
||||
"Cannot redact an event that belongs to a different room."
|
||||
)));
|
||||
}
|
||||
|
||||
if redacting_event
|
||||
.as_ref()
|
||||
.is_ok_and(|pdu| *pdu.kind() == TimelineEventType::RoomServerAcl)
|
||||
|
||||
@@ -666,7 +666,7 @@ impl Service {
|
||||
return Accessibility::NotFound;
|
||||
}
|
||||
|
||||
let request = assign!(get_stripped_state::unstable::Request::new(room_id.to_owned()), {
|
||||
let request = assign!(get_stripped_state::msc4560::Request::new(room_id.to_owned()), {
|
||||
state: state.to_owned(),
|
||||
num_joined_members
|
||||
});
|
||||
|
||||
@@ -591,9 +591,7 @@ impl super::Service {
|
||||
room_id: &RoomId,
|
||||
) -> Option<OwnedServerName> {
|
||||
let server = target_user_id.server_name();
|
||||
if !self.services.config.allow_sticky_events
|
||||
|| self.services.globals.server_is_ours(server)
|
||||
{
|
||||
if self.services.globals.server_is_ours(server) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,18 @@ use conduwuit_core::{
|
||||
matrix::{
|
||||
event::{Event, gen_event_id},
|
||||
pdu::{EventHash, PartialPdu, PduEvent},
|
||||
state_res,
|
||||
},
|
||||
utils::{self, IterStream, ReadyExt, stream::TryIgnore},
|
||||
};
|
||||
use futures::{StreamExt, TryStreamExt, future, future::ready};
|
||||
use ruma::{events::{StateEventType, TimelineEventType, room::create::RoomCreateEventContent}, room_version_rules::RoomVersionRules, state_res, uint, CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, RoomId, RoomVersionId, UserId};
|
||||
use ruma::{
|
||||
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, RoomId, RoomVersionId,
|
||||
UserId,
|
||||
events::{StateEventType, TimelineEventType, room::create::RoomCreateEventContent},
|
||||
room_version_rules::RoomVersionRules,
|
||||
uint,
|
||||
};
|
||||
use serde_json::value::{RawValue, to_raw_value};
|
||||
|
||||
use super::RoomMutexGuard;
|
||||
@@ -47,7 +54,7 @@ pub fn pdu_fits(owned_obj: &CanonicalJsonObject) -> bool {
|
||||
}
|
||||
// Now check the full PDU size
|
||||
match serde_json::to_string(owned_obj) {
|
||||
| Ok(s) => s.len() <= 65535,
|
||||
| Ok(s) => s.len() <= 65536,
|
||||
| Err(_) => false,
|
||||
}
|
||||
}
|
||||
@@ -135,7 +142,7 @@ impl super::Service {
|
||||
| None => Vec::new(),
|
||||
};
|
||||
|
||||
let auth_events: HashMap<(StateEventType, String), PduEvent> =
|
||||
let auth_events: HashMap<(StateEventType, SmallString<[u8; 48]>), PduEvent> =
|
||||
match room_id {
|
||||
| Some(room_id) =>
|
||||
self.services
|
||||
@@ -224,27 +231,39 @@ impl super::Service {
|
||||
},
|
||||
hashes: EventHash { sha256: String::new() },
|
||||
signatures: None,
|
||||
rejected: false,
|
||||
};
|
||||
|
||||
let auth_fetch = |k: &StateEventType, s: &str| {
|
||||
let key = (k.clone(), s.into());
|
||||
auth_events.get(&key).map(ToOwned::to_owned)
|
||||
ready(auth_events.get(&key).map(ToOwned::to_owned))
|
||||
};
|
||||
|
||||
let room_id_or_hash = pdu.room_id_or_hash();
|
||||
let create_pdu = match &pdu.kind {
|
||||
| TimelineEventType::RoomCreate => None,
|
||||
| _ => Some(
|
||||
self.services
|
||||
.state_accessor
|
||||
.room_state_get(&room_id_or_hash, &StateEventType::RoomCreate, "")
|
||||
.await
|
||||
.map_err(|e| {
|
||||
err!(Request(Forbidden(warn!("Failed to fetch room create event: {e}"))))
|
||||
})?,
|
||||
),
|
||||
};
|
||||
let create_event = match &pdu.kind {
|
||||
| TimelineEventType::RoomCreate => &pdu,
|
||||
| _ => create_pdu.as_ref().unwrap().as_pdu(),
|
||||
};
|
||||
|
||||
state_res::check_state_independent_auth_rules(
|
||||
&room_version_rules.authorization,
|
||||
&pdu,
|
||||
|event_id| self.get_pdu_blocking(event_id).ok(),
|
||||
)
|
||||
.map_err(|e| err!(Request(Forbidden("{e}"))))?;
|
||||
state_res::check_state_dependent_auth_rules(
|
||||
&room_version_rules.authorization,
|
||||
&pdu,
|
||||
auth_fetch
|
||||
).map_err(|e| err!(Request(Forbidden("{e}"))))?;
|
||||
let auth_check =
|
||||
state_res::auth_check(&room_version_rules, &pdu, auth_fetch, create_event)
|
||||
.await
|
||||
.map_err(|e| err!(Request(Forbidden(warn!("Auth check failed: {e:?}")))))?;
|
||||
|
||||
if !auth_check {
|
||||
return Err!(Request(Forbidden("Event is not authorized.")));
|
||||
}
|
||||
trace!(
|
||||
"Event {} in room {} is authorized",
|
||||
pdu.event_id,
|
||||
@@ -286,7 +305,7 @@ impl super::Service {
|
||||
{
|
||||
return match e {
|
||||
| Error::SignatureJson(ruma::signatures::JsonError::PduTooLarge) => {
|
||||
Err!(Request(TooLarge("Message/PDU is too long (exceeds 65535 bytes)")))
|
||||
Err!(Request(TooLarge("Message/PDU is too long (exceeds 65536 bytes)")))
|
||||
},
|
||||
| _ => Err!(Request(Unknown(warn!("Signing event failed: {e}")))),
|
||||
};
|
||||
@@ -311,9 +330,9 @@ impl super::Service {
|
||||
pdu_json
|
||||
.insert("event_id".into(), CanonicalJsonValue::String(pdu.event_id.clone().into()));
|
||||
// Verify that the *full* PDU isn't over 64KiB.
|
||||
if !pdu_fits(&pdu_json.clone()) {
|
||||
if !pdu_fits(&pdu_json) {
|
||||
// feckin huge PDU mate
|
||||
return Err!(Request(TooLarge("Message/PDU is too long (exceeds 65535 bytes)")));
|
||||
return Err!(Request(TooLarge("Message/PDU is too long (exceeds 65536 bytes)")));
|
||||
}
|
||||
|
||||
// Check with the policy server
|
||||
|
||||
@@ -3,11 +3,18 @@ use std::sync::Arc;
|
||||
use conduwuit::{
|
||||
Err, PduCount, PduEvent, Result, at, err,
|
||||
result::NotFound,
|
||||
utils::{self, stream::TryReadyExt},
|
||||
utils::{
|
||||
self,
|
||||
stream::{ReadyExt, TryReadyExt},
|
||||
},
|
||||
};
|
||||
use database::{Database, Deserialized, Json, KeyVal, Map};
|
||||
use futures::{FutureExt, Stream, TryFutureExt, TryStreamExt, future::select_ok, pin_mut};
|
||||
use futures::{
|
||||
FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt, future::select_ok, pin_mut,
|
||||
};
|
||||
use ruma::{CanonicalJsonObject, EventId, OwnedUserId, RoomId, api::Direction};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
use super::{PduId, RawPduId};
|
||||
use crate::{Dep, rooms, rooms::short::ShortRoomId};
|
||||
@@ -16,6 +23,7 @@ pub(super) struct Data {
|
||||
eventid_outlierpdu: Arc<Map>,
|
||||
eventid_pduid: Arc<Map>,
|
||||
pduid_pdu: Arc<Map>,
|
||||
pduid_unredactedcontent: Arc<Map>,
|
||||
roomid_lasttimelinecount: Arc<Map>,
|
||||
userroomid_highlightcount: Arc<Map>,
|
||||
userroomid_notificationcount: Arc<Map>,
|
||||
@@ -29,6 +37,12 @@ struct Services {
|
||||
|
||||
pub type PdusIterItem = (PduCount, PduEvent);
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub(super) struct UnredactedContent {
|
||||
pub(super) created: u64,
|
||||
pub(super) content: Box<RawJsonValue>,
|
||||
}
|
||||
|
||||
impl Data {
|
||||
pub(super) fn new(args: &crate::Args<'_>) -> Self {
|
||||
let db = &args.db;
|
||||
@@ -36,6 +50,7 @@ impl Data {
|
||||
eventid_outlierpdu: db["eventid_outlierpdu"].clone(),
|
||||
eventid_pduid: db["eventid_pduid"].clone(),
|
||||
pduid_pdu: db["pduid_pdu"].clone(),
|
||||
pduid_unredactedcontent: db["pduid_unredactedcontent"].clone(),
|
||||
roomid_lasttimelinecount: db["roomid_lasttimelinecount"].clone(),
|
||||
userroomid_highlightcount: db["userroomid_highlightcount"].clone(),
|
||||
userroomid_notificationcount: db["userroomid_notificationcount"].clone(),
|
||||
@@ -161,22 +176,6 @@ impl Data {
|
||||
select_ok([accepted, outlier]).await.map(at!(0))
|
||||
}
|
||||
|
||||
pub(super) fn get_pdu_blocking(&self, event_id: &EventId) -> Result<PduEvent> {
|
||||
if let Ok(outlier) = self
|
||||
.eventid_outlierpdu
|
||||
.get_blocking(event_id)?
|
||||
.deserialized()
|
||||
{
|
||||
return Ok(outlier);
|
||||
};
|
||||
|
||||
let pdu_id = self
|
||||
.eventid_pduid
|
||||
.get_blocking(event_id)
|
||||
.map(|h| RawPduId::from(&*h))?;
|
||||
self.pduid_pdu.get_blocking(&pdu_id)?.deserialized()
|
||||
}
|
||||
|
||||
/// Like get_non_outlier_pdu(), but without the expense of fetching and
|
||||
/// parsing the PduEvent
|
||||
#[inline]
|
||||
@@ -250,6 +249,44 @@ impl Data {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn save_unredacted_content(&self, pdu_id: &RawPduId, content: &RawJsonValue) {
|
||||
let entry = UnredactedContent {
|
||||
created: utils::millis_since_unix_epoch(),
|
||||
content: content.to_owned(),
|
||||
};
|
||||
|
||||
self.pduid_unredactedcontent.raw_put(pdu_id, Json(&entry));
|
||||
}
|
||||
|
||||
pub(super) async fn get_unredacted_content(
|
||||
&self,
|
||||
pdu_id: &RawPduId,
|
||||
) -> Result<UnredactedContent> {
|
||||
self.pduid_unredactedcontent
|
||||
.get(pdu_id)
|
||||
.await
|
||||
.deserialized()
|
||||
}
|
||||
|
||||
pub(super) async fn purge_unredacted_content(&self, cutoff: u64) -> usize {
|
||||
let expired: Vec<_> = self
|
||||
.pduid_unredactedcontent
|
||||
.raw_stream()
|
||||
.ready_filter_map(Result::ok)
|
||||
.ready_filter_map(|(key, val)| {
|
||||
let entry: UnredactedContent = serde_json::from_slice(val).ok()?;
|
||||
(entry.created < cutoff).then(|| key.to_vec())
|
||||
})
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
for key in &expired {
|
||||
self.pduid_unredactedcontent.remove(key);
|
||||
}
|
||||
|
||||
expired.len()
|
||||
}
|
||||
|
||||
/// Returns an iterator over all events and their tokens in a room that
|
||||
/// happened before the event with id `until` in reverse-chronological
|
||||
/// order.
|
||||
|
||||
@@ -48,13 +48,7 @@ impl super::Service {
|
||||
PartialPdu {
|
||||
event_type: event_type.to_string().into(),
|
||||
content,
|
||||
sticky: self
|
||||
.services
|
||||
.config
|
||||
.allow_sticky_events
|
||||
.then_some(sticky_duration_ms)
|
||||
.flatten()
|
||||
.map(sticky::object),
|
||||
sticky: sticky_duration_ms.map(sticky::object),
|
||||
state_key: Some(state_key.into()),
|
||||
timestamp,
|
||||
..Default::default()
|
||||
|
||||
@@ -6,17 +6,17 @@ mod data;
|
||||
mod helpers;
|
||||
mod redact;
|
||||
|
||||
use std::{fmt::Write, sync::Arc};
|
||||
use std::{fmt::Write, sync::Arc, time::Duration};
|
||||
|
||||
use async_trait::async_trait;
|
||||
pub use conduwuit_core::matrix::pdu::{PduId, RawPduId};
|
||||
use conduwuit_core::{
|
||||
Result, Server, at, err,
|
||||
Err, Result, Server, at, debug, err,
|
||||
matrix::{
|
||||
event::Event,
|
||||
pdu::{PduCount, PduEvent},
|
||||
},
|
||||
utils::{MutexMap, MutexMapGuard, future::TryExtExt, stream::TryIgnore},
|
||||
utils::{self, MutexMap, MutexMapGuard, future::TryExtExt, stream::TryIgnore},
|
||||
warn,
|
||||
};
|
||||
use futures::{Future, Stream, TryStreamExt, pin_mut};
|
||||
@@ -25,6 +25,11 @@ use ruma::{
|
||||
events::room::encrypted::Relation,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
use tokio::{
|
||||
sync::Notify,
|
||||
time::{MissedTickBehavior, interval},
|
||||
};
|
||||
|
||||
use self::data::Data;
|
||||
pub use self::{create::pdu_fits, data::PdusIterItem};
|
||||
@@ -56,6 +61,7 @@ struct ExtractBody {
|
||||
}
|
||||
|
||||
pub struct Service {
|
||||
interrupt: Notify,
|
||||
services: Services,
|
||||
db: Data,
|
||||
pub mutex_insert: RoomMutexMap,
|
||||
@@ -87,6 +93,8 @@ struct Services {
|
||||
users: Dep<users::Service>,
|
||||
}
|
||||
|
||||
const PURGE_INTERVAL_SECS: u64 = 3600;
|
||||
|
||||
type RoomMutexMap = MutexMap<OwnedRoomId, ()>;
|
||||
pub type RoomMutexGuard = MutexMapGuard<OwnedRoomId, ()>;
|
||||
|
||||
@@ -124,9 +132,35 @@ impl crate::Service for Service {
|
||||
},
|
||||
db: Data::new(&args),
|
||||
mutex_insert: RoomMutexMap::new(),
|
||||
interrupt: Notify::new(),
|
||||
}))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, name = "unredacted_content_purge", level = "debug")]
|
||||
async fn worker(self: Arc<Self>) -> Result<()> {
|
||||
// Runs while disabled too, so old retained content still ages out.
|
||||
let mut i = interval(Duration::from_secs(PURGE_INTERVAL_SECS));
|
||||
i.set_missed_tick_behavior(MissedTickBehavior::Delay);
|
||||
loop {
|
||||
tokio::select! {
|
||||
() = self.interrupt.notified() => break,
|
||||
_ = i.tick() => (),
|
||||
}
|
||||
|
||||
let purged = self
|
||||
.db
|
||||
.purge_unredacted_content(self.unredacted_content_cutoff())
|
||||
.await;
|
||||
if purged > 0 {
|
||||
debug!("Purged {purged} expired unredacted event contents");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn interrupt(&self) { self.interrupt.notify_waiters(); }
|
||||
|
||||
async fn memory_usage(&self, out: &mut (dyn Write + Send)) -> Result {
|
||||
let mutex_insert = self.mutex_insert.len();
|
||||
writeln!(out, "insert_mutex: {mutex_insert}")?;
|
||||
@@ -211,12 +245,6 @@ impl Service {
|
||||
self.db.get_pdu(event_id).await
|
||||
}
|
||||
|
||||
/// Returns the PDU. Checks the outlier tree BEFORE the timeline tree, as
|
||||
/// this operation is synchronous.
|
||||
pub fn get_pdu_blocking(&self, event_id: &EventId) -> Result<PduEvent> {
|
||||
self.db.get_pdu_blocking(event_id)
|
||||
}
|
||||
|
||||
/// Returns the pdu.
|
||||
///
|
||||
/// This does __NOT__ check the outliers `Tree`.
|
||||
@@ -248,6 +276,27 @@ impl Service {
|
||||
self.db.replace_pdu(pdu_id, pdu_json).await
|
||||
}
|
||||
|
||||
pub async fn get_unredacted_content(&self, pdu_id: &RawPduId) -> Result<Box<RawJsonValue>> {
|
||||
let entry = self.db.get_unredacted_content(pdu_id).await?;
|
||||
|
||||
if entry.created < self.unredacted_content_cutoff() {
|
||||
return Err!(Request(NotFound("Unredacted content has expired.")));
|
||||
}
|
||||
|
||||
Ok(entry.content)
|
||||
}
|
||||
|
||||
fn unredacted_content_cutoff(&self) -> u64 {
|
||||
let max_age = self
|
||||
.services
|
||||
.config
|
||||
.experiments
|
||||
.msc2815
|
||||
.map_or_default(|c| c.unredacted_content_max_age_secs);
|
||||
|
||||
utils::millis_since_unix_epoch().saturating_sub(max_age.saturating_mul(1000))
|
||||
}
|
||||
|
||||
/// Returns an iterator over all PDUs in a room. Unknown rooms produce no
|
||||
/// items.
|
||||
#[inline]
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use conduwuit::config::experiments::ToggledExperiment;
|
||||
use conduwuit_core::{
|
||||
Result, err,
|
||||
Err, Result, err,
|
||||
matrix::event::Event,
|
||||
utils::{self},
|
||||
warn,
|
||||
};
|
||||
use ruma::{EventId, events::room::encrypted::Relation};
|
||||
use ruma::{EventId, events::room::encrypted::Relation, signatures::content_hash};
|
||||
|
||||
use super::{ExtractBody, ExtractRelatesTo};
|
||||
use crate::rooms::short::ShortRoomId;
|
||||
@@ -32,6 +33,12 @@ impl super::Service {
|
||||
err!(Database(error!(?pdu_id, %event_id, ?e, "PDU ID points to invalid PDU.")))
|
||||
})?;
|
||||
|
||||
if pdu.room_id() != reason.room_id() {
|
||||
return Err!(Request(Forbidden(
|
||||
"Cannot redact an event that belongs to a different room."
|
||||
)));
|
||||
}
|
||||
|
||||
let thread_root = match pdu.get_content::<ExtractRelatesTo>() {
|
||||
| Ok(ExtractRelatesTo { relates_to: Relation::Thread(thread) }) =>
|
||||
Some(thread.event_id),
|
||||
@@ -52,6 +59,16 @@ impl super::Service {
|
||||
.get_room_version(&pdu.room_id_or_hash())
|
||||
.await?;
|
||||
|
||||
if self.services.config.experiments.msc2815.is_enabled() {
|
||||
let mut pdu_json = self.get_pdu_json_from_id(&pdu_id).await?;
|
||||
pdu_json.remove("event_id");
|
||||
if content_hash(&pdu_json)
|
||||
.is_ok_and(|hash| hash.encode() == pdu.hashes.sha256.trim_end_matches('='))
|
||||
{
|
||||
self.db.save_unredacted_content(&pdu_id, &pdu.content);
|
||||
}
|
||||
}
|
||||
|
||||
pdu.redact(&room_version_id, Some(reason.event_id()))?;
|
||||
|
||||
let obj = utils::to_canonical_object(&pdu).map_err(|e| {
|
||||
|
||||
@@ -23,10 +23,8 @@ use futures::{FutureExt, Stream, StreamExt};
|
||||
use ruma::{
|
||||
OwnedServerName, RoomId, ServerName, UserId,
|
||||
api::{
|
||||
OutgoingRequest,
|
||||
auth_scheme::{NoAccessToken, NoAuthentication, SendAccessToken},
|
||||
federation::authentication::ServerSignatures,
|
||||
path_builder::PathBuilder,
|
||||
OutgoingRequest, auth_scheme::NoAuthentication,
|
||||
federation::authentication::ServerSignatures, path_builder::PathBuilder,
|
||||
},
|
||||
};
|
||||
use tokio::{task, task::JoinSet};
|
||||
@@ -420,26 +418,6 @@ impl Service {
|
||||
.await
|
||||
}
|
||||
|
||||
/// Send an unauthenticated federation request with no X-Matrix header.
|
||||
#[inline]
|
||||
pub async fn send_legacy_media_request<'i, T>(
|
||||
&self,
|
||||
dest: &ServerName,
|
||||
request: T,
|
||||
) -> Result<T::IncomingResponse>
|
||||
where
|
||||
T: OutgoingRequest<
|
||||
Authentication = NoAccessToken,
|
||||
PathBuilder: PathBuilder<Input<'i>: FederationPathBuilderInput>,
|
||||
> + Debug
|
||||
+ Send,
|
||||
{
|
||||
self.services
|
||||
.federation
|
||||
.execute_on(&self.services.client.federation, dest, request, SendAccessToken::None)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Clean up queued sending event data
|
||||
///
|
||||
/// Used after we remove an appservice registration or a user deletes a push
|
||||
|
||||
@@ -149,10 +149,10 @@ impl Service {
|
||||
{
|
||||
debug!("{dest} is now unhealthy & stale due to a connect error: {e:?}");
|
||||
self.services.federation.mark_destination_stale(dest);
|
||||
self.services.federation.hit_unhealthy(dest.clone());
|
||||
self.services.federation.hit_unhealthy(dest.clone(), None);
|
||||
} else if e.status_code() != StatusCode::OK {
|
||||
debug!("{dest} is now unhealthy due to error response: {e:?}");
|
||||
self.services.federation.hit_unhealthy(dest.clone());
|
||||
self.services.federation.hit_unhealthy(dest.clone(), None);
|
||||
}
|
||||
}
|
||||
Self::handle_response_err(dest, statuses, &e);
|
||||
@@ -327,7 +327,7 @@ impl Service {
|
||||
/// still-sticky events. Only netburst delivers this queue, so with it
|
||||
/// disabled there is nothing to keep the event for.
|
||||
async fn survives_netburst_trim(&self, event: &SendingEvent) -> bool {
|
||||
if !self.server.config.allow_sticky_events || !self.server.config.startup_netburst {
|
||||
if !self.server.config.startup_netburst {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Loaded 100 of 102 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user