Compare commits

...
264 Commits
Author SHA1 Message Date
Jason Volk 9af15ecbba Bump 1.4.5
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-25 13:33:32 +00:00
Jason Volk f66a83763e Persist sliding-sync state; mitigate initial-sync.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-25 13:33:32 +00:00
Jason Volk 718c3adcb2 ci: Expand the rust-sdk integration matrix.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-25 08:44:16 +00:00
Jason Volk af80482c04 Add branch in room handler for left rooms.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-25 08:34:49 +00:00
Jason Volk a20ddcd586 Recency bump on own membership event.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-25 08:08:26 +00:00
Jason Volk b483306367 Fix sliding-sync invite regression.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-25 07:52:40 +00:00
Jason Volk f5e98467be Improve sliding-sync robustness to deeper replays.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-24 18:31:48 +00:00
Jason Volk d44db45f83 Adjust the order of operations during read_marker handling.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-24 18:31:48 +00:00
Jason Volk 0397bb8237 Implement specified non-blocking semantic for sliding-sync.
Simplify sliding-sync watch loop and bounds.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-23 11:00:55 +00:00
Jason Volk 4010fc62bc Use take_while rather than filter for scanning last_receipt_count.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-23 03:37:52 +00:00
Jason Volk 0d823a2822 Revert "Involve m.fully_read for resetting notification counts."
This reverts commit 0df5e5e7ac.
2025-10-23 03:37:52 +00:00
Jason Volk 9cd175b125 Additional logging/tracing tweaks around sliding-sync.
Additional spans around receipt service interface.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-23 03:37:52 +00:00
Jason Volk 050a1a350a Add dbg profile to Cargo; default to faster builds accomodating new users. 2025-10-23 03:37:52 +00:00
Jason Volk ec0f872f8f Add tracing around db watcher notify including cf name.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-22 20:23:30 +00:00
Jason Volk 024e8eae62 Implement num_live for sliding-sync room response.
Avoid using origin_server_ts for recency stamp.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-22 09:14:41 +00:00
Jason Volk 4fd60b2605 Improve sliding-sync selector and windowing logic.
Bump Ruma; eliminate premature release compat.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-22 08:15:25 +00:00
Jason Volk e53968d9eb Improve tracing spans for notif counts and sliding-sync exts.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-22 07:05:03 +00:00
Jason Volk 7cbc2ee385 Fix the accidentally dual-keyspaced cf from conduit.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-22 07:03:10 +00:00
Jason Volk 0df5e5e7ac Involve m.fully_read for resetting notification counts.
EXA is not reliably removing its unread marker any other way. Clients
wishing to move the fully_read marker in the other direction should
file an issue to make themselves known.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-22 06:52:30 +00:00
Jason Volk 312eb69450 Add tool to get sibling connections for a device.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-21 17:48:08 +00:00
Jason Volk 5b620a2c37 Add .and_is() / .and_if() to the BoolExt smalltalk.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-21 17:41:42 +00:00
Jason Volk 3b4fbb8c1a Fix inverted debug assert message.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-21 15:48:05 +00:00
Jason Volk 158d44e1a9 docs: Remove line about other reverse proxies. (#197)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-21 15:02:36 +00:00
Jason Volk d2aab468cf Fixes for sliding-sync request replays.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-21 06:46:02 +00:00
Jason Volk aa4486dfdf Simplify types, mitigate expansion; eliminate unnecessary move.
Further simplify future::BoolExt toward type expansion mitigation.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-21 05:25:11 +00:00
Jason Volk 2a662445b6 Make account_data.last_count() upper bound argument optional.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-20 23:58:38 +00:00
Jason Volk 5b3f0fde23 Add invite rooms to sync v3 watch rooms list.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-20 23:57:52 +00:00
Jason Volk 9640afebff Join the async prologue operations in sync v3.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-20 23:55:42 +00:00
Jason Volk dd5c5c7a4a Notify watchers on delete operations in addition to inserts. 2025-10-20 20:45:38 +00:00
Jason Volk fc0f04defa Optimize watcher range collection on notify.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-20 20:44:45 +00:00
Jason Volk 7d8f7cbe5d Bump 1.4.4
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-16 01:55:43 +00:00
Jason Volk 4e0249cd2f Fix sliding-sync again by resetting after interrupted requests. (fixes #190)
This solution is not elegant but appears to be correct for fixing the issue. A
a more efficient solution might be possible without resetting the connection
which should be further investigated.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-16 01:05:16 +00:00
Jason Volk d5b39aa995 Bump 1.4.3
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-11 02:12:43 +00:00
Jason Volk 46c940b863 Refactor sliding window selector. (fixes #170)
Refactor list filtering.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 15:56:08 +00:00
Jason Volk ab8536d5c3 Add query to get latest account data count.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 12:44:23 +00:00
Jason Volk 4918868632 Add query to get last read receipt for room.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 12:44:23 +00:00
Jason Volk 9e00f70197 Allow nursery clippy::tuple_array_conversions.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 08:30:08 +00:00
Jason Volk d3aaf9e4a9 Additional FutureBoolExt; attempt to reduce type-length expansion.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 07:37:40 +00:00
Jason Volk 96dc56ad07 Relax clippy::rest-pat-in-fully-bound-structs.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 07:37:40 +00:00
Jason Volk e12b0262da Fix unnecessary async for future and/or utils.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 07:37:40 +00:00
Jason Volk e5bf005eaf Simplify state_cache.user_memberships() masking for callers.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 07:37:40 +00:00
Jason Volk 02ccb1dceb Cleanup legacy config path component.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 07:37:40 +00:00
Jason Volk a450eb96eb ci: Remove default-features builds from publication to registries.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 07:37:40 +00:00
Jason Volk 155af0fda3 Add iteration of space children; simplify space child event fetcher.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 07:37:40 +00:00
Jason Volk 5c61b4d4a3 Add room state accessor iterating state_keys joined by respective event_id.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-10 07:37:40 +00:00
Jason Volk 97e709492c Add is_direct() alternative query for m.room.member.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-08 03:33:12 +00:00
Jason Volk 51fc2342a4 Add is_direct() query for account_data.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-08 03:33:12 +00:00
Jason Volk 4ca68deef8 Add better interface for getting and setting room tag account data.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-08 03:33:12 +00:00
Jason Volk 4d8d64f5c7 Add missing wildcard matching for sliding-sync required state.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-08 03:33:12 +00:00
Jason Volk dff30e5924 Additional state accessor iterations for pdus of a specific type.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-08 03:33:12 +00:00
Jason Volk 7fee459b1a Add admin diagnostic query suite for sync state.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-08 03:33:12 +00:00
Jason Volk a6127fcd1a Provide sync watch rooms as argument rather than assuming all joined rooms.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-08 03:33:12 +00:00
Jason Volk 6c724bbc2f Cleanup/optimize sliding sync types and arguments.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-08 03:33:08 +00:00
Jason Volk b1ea7b101d Split sliding-sync extensions into units.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 15:56:49 +00:00
Jason Volk 4baa25f66f Add presence ping to sliding-sync.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 15:56:49 +00:00
Jason Volk 227b77e58e Refactor sliding-sync e2ee extension.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 15:56:49 +00:00
Jason Volk 54057da84e ci: Fix artifact extraction argument for package.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 15:56:49 +00:00
Jason Volk 732825a390 ci: Publish verbose logging container builds to registries. (closes #181)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 04:11:57 +00:00
Jason Volk 6b74425f76 ci: Add integration memcheck to test matrix.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:22:02 +00:00
Jason Volk 74a576caf7 Add option to toggle compact log format.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk 2b7cf7d5d5 Add optimized iteration of all room memberships for user.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk 443248965d Add more optimized iterations for user memberships room_id's.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk ee777bc287 Rename user rooms iterations which have state vectors as values.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk aef38b1178 Rename userroomid/roomuserid table handles to reflect counter value.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk 4743a8d968 Move args and runtime back to main from core (1313eb0b64).
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk 53ab6742c8 Fix shutdown signalling on startup.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk 46193de7e8 Create appservice user on registration.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk 9253f46c80 ci: Dedup the nix package job with the other distro package jobs.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk 5c127b5abd Add is_false() to BoolExt.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk 17f6f1a5a6 Device list updates for left users was previously deduplicated.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk 75509d50ca Add shorteventid to pdu_id query; reorg related id query interface.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jason Volk 1d14426018 Fix missing Send on generic stream and result items.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-06 01:19:36 +00:00
Jimmy Brush 2b9563be67 Fix off-by-one in sync v5
Simplified sliding sync specifies ranges to be inclusive while rust ranges are
exclusive.
2025-10-05 18:28:05 -04:00
Jason Volk 68c4f60bb3 Implement stateless sync; erase all the sync tokens.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 15:07:06 +00:00
Jason Volk d95c3f126f Fix typos
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 15:07:06 +00:00
Jason Volk f1c2548807 Add PduCount value to userroomid/roomuserid_joined; move PduCount to argument for update_membership.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk eda45e445c Implement better fmt::Debug for pdu::Builder.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk 049defe977 nix: Disable doChecks due to missing /etc/resolve.conf.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk 3c073110b8 Update nix flake.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk 8d6bfde5a0 Use insta and criterion for main integration test and benches respectively.
docker/ci: Separate integration and unit tests and benches jobs.

Add directives to remove db before/after integration tests are performed.

Split start/run/stop phases; add more granular smoketests.

Split main integration tests into units for isolation.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
dasha_uwu 43f0882d83 clear destination and overrides cache on request failure. (#186) 2025-10-02 05:29:48 +00:00
Jason Volk fed52d24e4 Implement additional Matches for RoomFilter and Filter.
Apply filter for rooms/not_rooms; sender filter for presence.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk e6c85c97c6 Fix names and types misrepresenting PduCount as ShortEventId.
Add get_shorteventid_from_pdu_id() conversion.

Fix prev/next nearest-state interface (dev branch 642086ecfcfa).

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk 368ead20a6 Add then_none() to BoolExt; move unsorted then_ utils.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk a803b84b27 Add missing reverse query for shortroomid => room_id.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk 1058fbe9a7 Use specific key,val buffer sizes for append_to_state (no change to correctness).
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk ae4aad3641 Add set difference for sorted streams util.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk 95435ffe98 Fix unconnected inspect_log traits in Result utils.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk 63e2cfa21b Rename core integration test directory for state_res.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk 9383922d09 Use trace log level for multi-line table factory options on rocksdb startup.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:48 +00:00
Jason Volk ae52676e33 Add back the default database path.
Allow default server_name when testing.

Default to smoke test vector when testing.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:45 +00:00
Jason Volk 292b601755 Fix possibly dependent conditions for server shutdown in config worker.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:29:00 +00:00
Jason Volk 1313eb0b64 Reorganize main crate for testability.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:28:58 +00:00
Jason Volk ba12773a5a Optimize force_state query pattern.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk 83afe81f60 Move shortstatehash queries from state_accessor to state service.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk f2740822e2 De-indent rooms state service definitions.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk 2417764771 Fix redundant prefix in admin query raw command suite.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk 41ff81f843 Add handler_prefix to admin_command_dispatch for method dedup purposes.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk fbcf4ba4f3 ci: Support job masking directives in commit message. [ci only it]
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason VolkandHashbrown777 af3cdf9263 Add script to docs for available optimization levels.
Co-authored-by: Hashbrown777 <hashbrown777@gmail.com>
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk 9d9ace1452 Add timeline interface to get next or prev pdu nearest to a pduid.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk 83d64e0879 Implement Deserialize for RawPduId for database convenience.
Add room equality convenience on RawPduId.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk 4cae17e83d Fix missing Send bound for Future.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk 1c6992ccd4 Add option to bypass dropped column erasure.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk 89be6dc097 Switch to Criterion for benchtests.
ci: Add benches to workflow.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk a47f8f8a82 Rename complement test results file.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-10-02 05:27:48 +00:00
Jason Volk aac5006bf5 ci: Add nix build w/ smoketest. (closes #111)
docker: Add target for nix build. (#111)

Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-25 14:38:23 +00:00
Jason Volk 6d3ed09a2b ci: Add matrix-rust-sdk integration testing.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-25 14:38:23 +00:00
Jason Volk 377b7166f0 Bump Ruma.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-25 12:25:08 +00:00
Jason Volk 85b3de055d Broadcast send_join concurrent to other operations; pre-gather state concurrently.
Broadcast send_knock concurrently.

Concurrent access check for fed event.

Concurrent gather for state responses.

Populate room_version for format_pdu to elide repeated queries.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-25 02:32:45 +00:00
Jason Volk b9c790326a docker: Consolidate distro package fetches in base builder image.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-24 08:20:54 +00:00
Jason Volk 4e5910471b Require stronger ordering to sample final counter values on shutdown.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-24 08:20:54 +00:00
Jason Volk c3bc8c14f7 Make hickory system_conf error more useful. (resolves #179)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 21:02:37 +00:00
Jason Volk ac3ceb1b95 Modernize federation profile query route.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 19:48:07 +00:00
Jason Volk aa37e32471 Optimize Pdu prev_events and auth_events containers.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 18:16:24 +00:00
Jason Volk 887a22dabd Fix docs regarding optimized builds; replace haswell with v1/v2/v3 etc. (fixes #175)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 18:16:24 +00:00
Jason Volk 6dca02860c Allow clippy::needless-update.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 11:53:39 +00:00
Jason Volkanddasha_uwu 86103183b3 Remove unused utils.
Co-authored-by: dasha_uwu <dasha@linuxping.win>
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 09:02:35 +00:00
Jason Volk 8f4cc87051 Query rooms in server_sees_user() concurrently.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 08:49:09 +00:00
Jason Volk 14721c90c9 Fetch presence avatar_url and displayname concurrently.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 08:49:09 +00:00
Jason Volk 6d3b2d864f Simplify keys_changed iteration using room_keys_changed() upper-bound.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 08:49:09 +00:00
Jason Volk 7cf246eb73 Support dot paths for -O/--option command-line args. (fixes #162) (fixes #167)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:16:29 +00:00
Jason Volk bffb7f89c8 Provide better generated config defaults for ldap section.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:16:29 +00:00
Jason Volk 5467c9e486 Add option to redirect logging to stderr. (resolves #154)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:16:29 +00:00
dasha_uwu 89a67af607 pull stuff out of globals 2025-09-23 05:16:29 +00:00
dasha_uwu 6bb101ac51 add local alias check 2025-09-23 05:16:29 +00:00
dasha_uwu 1c0b4e94ac fix spec violation and slight alias resolution refactor 2025-09-23 05:16:29 +00:00
dasha_uwu 9c4d376bec pass args by ref 2025-09-23 05:16:29 +00:00
dasha_uwu d6e95c51c0 current_exe changes
remove unsafe

remove incorrect doc
2025-09-23 05:16:29 +00:00
dasha_uwu d5ce4b316f remove unnecessary as_ref 2025-09-23 05:16:29 +00:00
dasha_uwu 8f07a6c60f remove unused macros 2025-09-23 05:16:29 +00:00
dasha_uwu b882e7efdb rename db to engine 2025-09-23 05:16:29 +00:00
dasha_uwu e0169e3dca presence refactor 2025-09-23 05:16:29 +00:00
Jason Volk fe46755418 Remove declaration for Room V1 until support is confirmed complete. (#12)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:15:10 +00:00
Jason Volk bbac80d2e6 ci: Fix pages deployment. (#165)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:15:10 +00:00
Jason Volk a31c9b0c62 Fix documented examples of delegation. (fixes #165)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:15:10 +00:00
Jason Volk cf4e65c607 Fix alternative resolver minimum TTL configuration. (fixes #176)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:15:10 +00:00
Jason Volk f32b6ae17d Abstract and simplify serde_json round-trip to Ruma Raw.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:15:10 +00:00
Jason Volk 27222f23d2 Macroize several legacy errors.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:15:10 +00:00
Jason Volk ed324d5972 Update device_signing/upload UIAA (fixes #169).
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:15:10 +00:00
Jason Volk 69075b166f Add config option to toggle dns case randomization.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:15:10 +00:00
Jason Volk e3a711482a Update assertion for serde crate reorg to serde_core.
Show the deserialize_any type which fails the assertion.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-23 05:15:10 +00:00
Jason Volk 6759187b37 Bump dependencies.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-22 20:44:25 +00:00
Guido Günther 83ed29eb65 example config: Document support items
Signed-off-by: Guido Günther <agx@sigxcpu.org>
2025-09-22 20:44:25 +00:00
Guido Günther 6a685b7ee9 packaging: Move unit alias to install section
Otherwise there will be

  systemd[1]: /usr/lib/systemd/system/tuwunel.service:5: Unknown key 'Alias' in section [Unit], ignoring.

on startup. See `systemd.unit(5)`.

Signed-off-by: Guido Günther <agx@sigxcpu.org>
2025-09-15 19:53:05 +02:00
Jason Volk fb4dfafe2d Bump 1.4.2
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-12 04:13:34 +00:00
Jason Volk 8dbea51968 Slightly decrease the default OTK limit.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-12 04:13:34 +00:00
Jason Volk 7b5905bbca Remove inapposite readme sections on versioning.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-12 04:13:34 +00:00
Jason Volk 42d143c013 Allow matching for passthru resolver on all resolution paths. (#158)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-12 04:13:27 +00:00
Jason Volk 10fb1cd192 Purge room synctokens during deletion.
Purge last notification read counts.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-11 08:56:38 +00:00
Jason Volk 1322ba1b00 Send unmaintained hardened_malloc-rs to valhalla.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-11 08:56:38 +00:00
Jason Volk d73b4332bf Fix deletion of local leave state to allow sync for clients.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-11 06:20:41 +00:00
Jason Volk 11eeca7e01 Prune one time keys based on reasonable configured limit.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-11 04:27:33 +00:00
Jason Volk 19dc5fafd4 Fix missing device_one_time_keys_count in empty timeout responses.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-10 21:29:04 +00:00
Jason Volk 54b347b855 Abstract and dedup the general UIAA pattern into api::router.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-10 10:35:49 +00:00
Jason Volk 8ed61aecb0 Split api::router::auth server/appservice units.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-10 05:41:44 +00:00
Jason Volk bf8aa57d03 Add config option for dns passthru for appservices. (#158)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-10 01:17:40 +00:00
Jason Volk a9f1926654 Use dns_resolver2 per reqwest client builder deprecation notice.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-10 00:59:50 +00:00
Jason Volk 248d778290 Add alternative resolver path with passthru cache-characteristics. (resolves #158)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-10 00:01:26 +00:00
Jason Volk 2e13e87e43 docs: Update the Helm Chart link for Kubernetes.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-09 22:47:33 +00:00
Jason Volk ba19d407d0 Add config to control m.federate in room create events. (fixes #151)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-09 04:46:19 +00:00
Jason Volk de7c5dcbc8 Make iss and aud args optional to debug create-jwt command.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-09 03:03:53 +00:00
dasha_uwu adadafa88f Fix alias resolution logic; element-web v1.11.111 compat
element-hq/element-web#30641
element-hq/element-web#30611

Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-09 02:28:19 +00:00
Jason Volk deda746222 Support JWT authentication on deactivate route.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-09 02:28:19 +00:00
Jason Volk 29c2c8a333 Branch based on config to note sync for push suppression.
Minor if-let condition and scope reduction; formatting.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-08 22:25:00 +00:00
tototomate123 296018f0cc mark notification suppression as experimental 2025-09-08 22:25:00 +00:00
tototomate123 6295ca135a feature marked as experimental and executed rustfmt 2025-09-08 22:25:00 +00:00
tototomate123 b5a9884194 feat(presence,push) optionally suppress push notifications for active users 2025-09-08 22:25:00 +00:00
Jason Volk 1be7fd9247 Fix cfg condition for debug logging (996a5488be)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-08 22:25:00 +00:00
Jason Volk be1264965a Refactor sliding-sync.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-08 00:07:59 +00:00
Jason Volk f6d2ce2f22 Greenlight hydra backports.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-08 00:07:59 +00:00
Jason Volk 3cbe1e25cd Cleanup Resolver construction/configuration.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-08 00:07:59 +00:00
Jason Volk 897322964c Fix dns_min_ttl config doc.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-08 00:07:59 +00:00
Jason Volk 996a5488be ci: Add build for release-logging, optimized build with debug logging.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-08 00:07:59 +00:00
Jason Volk 0ed4bd1e07 Only ping presence for public read receipts.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-07 21:39:20 +00:00
Jason Volk da79de5381 Add cfg to preclude log elision without requiring debug_assertions.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-07 21:39:20 +00:00
Jason Volk 1bcf3ae19a Soften the Docker troubleshooting note.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-07 20:50:14 +00:00
Jason Volk 91e500efe3 Further tweak troubleshooting formatting.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 22:11:42 +00:00
Jason Volk 35b1ebaf3b Bump dependencies.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 07:45:04 +00:00
Jason Volk ea5deb7e85 Generate CoC HTML inside book directory. (closes #155)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 07:45:04 +00:00
Jason Volk 542cc51047 ci: Add docs test step.
docker: Add docs test target.

docker: Add mising color args to rustfmt.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 06:49:45 +00:00
Jason Volk 3225db0ddd Add external repair tool step to db repair troubleshooting.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk a164da8b58 Fix and extend the apply! util macro.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk 7221d466ce Ignore canonical_alias with removed alias for directory results.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk f6c88e3a16 Add query for alias existing; tweak tracing spans.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk 3deebeab78 Fix sliding-sync room_avatar conditions.
Eliminate jsOption from non-sliding-sync avatar related codepaths.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk 1d2818de58 Round upward for events_after in /context limit.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk 86781522b6 Allow state visibility for once-joined users when history_visibility=shared.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk 4b49aaad53 Fix spec compliance limiting /joined_rooms to current members only.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk 3a78ba2b16 Support v1/v2 conditions for join/leave, creation and other operations. (#12)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk 685946faed Cleanup validate/verify suite room version related; optimize event_id insert. (#12)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk 13c9385ef7 Add v1/v2 support to gen_event_id() scheme. (#12)
Add v1/v2 and improve reference and content hashing suite. (#12)

Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk 6a583a359e Support v1/v2 prev_events/auth_events outgoing federation format. (#12)
Support v1/v2 prev_events/auth_events when handling outlier pdu. (#12)

Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Jason Volk eec6e45358 Improve error messages for missing auth event and invalid join validations.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-05 05:45:41 +00:00
Alexandru Scvorțov 804257eb52 Fix broken doctest in src/core/utils/debug.rs 2025-09-04 22:21:14 +00:00
Jason Volk a1677f05d3 Bump 1.4.1
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-02 09:43:50 +00:00
Jason Volk 1f77200299 Mark MSC4297 compliance as flake.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-02 06:29:40 +00:00
Jason Volk 888b93df91 Fix /joined_members results. (regression a3666fe672) (fixes #147)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-02 05:34:37 +00:00
Jason Volk a127724eaa Bump 1.4.0
Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-01 11:34:08 +00:00
Jason Volk 00102c4276 ci: Skip unnecessary amd64 -v2 and -v3 builds in test-profile mode.
docker: Use env override for git_checkout.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-09-01 02:33:00 +00:00
dasha_uwu b59af0530c Deprioritize joins through configured servers 2025-08-31 12:30:27 +05:00
dasha_uwu 44af849ed0 Dedup base join servers 2025-08-31 11:30:10 +05:00
Jason Volk 26e7a8e962 Bump 1.4.0 Preview
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-30 20:27:39 +00:00
Jason Volk aa413ae601 Implement room purge after last local user leaves. (resolves #83)
Consume a state_lock for room delete call.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-30 11:45:32 +00:00
Jason Volk 7c19d1e1ff Fix unnecessary backfill requests after reaching m.room.create.
Cleanup condition.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-30 11:45:32 +00:00
Jason Volk 616f20f273 Fix unused lifetims.
Fix unused pub(crate).

Allow implicit hasher.

Fix unused self.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-30 11:13:14 +00:00
Jason Volk 91efcf8a8e Bump and unpatch tracing-subscriber.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-30 10:51:55 +00:00
Jason Volk 8708e98478 ci: Tweak docker cache sizes.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-30 10:16:43 +00:00
Jason Volk 4bdc260015 Update the troubleshooting for easier rocksdb recovery/repair.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-30 10:16:43 +00:00
Jason Volk 7bc47e58d0 Add state_cache iteration for local pending invitees to room.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-30 10:04:24 +00:00
Jason Volk 6172b9c8ec Replace legacy federation proto-event formatter.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-30 10:04:24 +00:00
k0tlin 9dc16eeab7 Adjust generic docs
Match readme instruction with doc
2025-08-30 00:45:41 +03:00
k0tlin 402f7a2157 Update example caddy config 2025-08-30 00:35:38 +03:00
Jason Volk 9c6e0e3350 Stabilize room version 12. (#126)
Bless complement.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 07:49:36 +00:00
Jason Volk 12bdfe3b66 Optimize backfill_if_required conditions.
Optimize backfill_pdu.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 06:49:04 +00:00
dasha_uwu 54ce221e88 Add active request assert on tls listener shutdown 2025-08-29 06:49:04 +00:00
dasha_uwu 33a16f4831 Make /sync respond early on server shutdown 2025-08-29 06:49:04 +00:00
Jason Volk d8e6d95f4b Fix device verification crutch (regression 628597c318); cleanup. (fixes #134)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 06:49:04 +00:00
Jason Volk 9c290bc513 Fix latest key backup determination.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 06:49:04 +00:00
Jason Volk a4520424bd Adjust several log levels; cleanup unformatted log call.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 06:49:04 +00:00
Jason Volk 280d7733fc Update capability for MSC4133 profile fields.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 06:49:04 +00:00
Jason Volk 79e3c898ac Fix /send_join response event format. Optimize.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 06:49:04 +00:00
Jason Volk 757d38e891 Optimize expected auth types checking.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 06:49:04 +00:00
Jason Volk 4b66911886 Eliminate redundant duplicate auth and matching room check.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 06:49:04 +00:00
Jade Ellis 9db3e35f41 Fix incorrect command descriptions. [ci skip] 2025-08-29 02:17:46 +00:00
Jason Volk 7977512d5d Fix additional cases for room_id.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 02:17:46 +00:00
Jason Volk e354be6830 Simplify Pdu from_id_val constructions.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 02:17:46 +00:00
Jason Volk f58081838e Log error for send_join auth_check failure.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-29 02:17:46 +00:00
dasha_uwu 526a138021 Force promotion (closes #136) 2025-08-29 02:17:46 +00:00
dasha_uwu 7fa6894334 Remove excessive doc on admin command 2025-08-29 02:17:46 +00:00
dasha_uwu 33d0ad1be2 Remove dead link in readme 2025-08-29 02:17:46 +00:00
Jason Volk fbc3892904 ci: Disable lychee for now due to excessive build time issue during install.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-28 23:28:20 +05:00
Jason Volk ce6212b161 Add room_version argument and reorg convert_outgoing_federation_event.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-28 23:28:20 +05:00
Jason Volk 0aea56f02a Optimize OnceServices; simplify init.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-28 23:28:20 +05:00
dasha_uwu d05d3f710f Room deletion (fixes #43) 2025-08-28 23:28:20 +05:00
Jason Volk 7a3496869b Remove associated pushers on device delete. (fixes #120)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-28 23:28:20 +05:00
dasha_uwu 146b72265d Skip serialization for appservice id 2025-08-28 23:28:20 +05:00
dasha_uwu 120a43cceb Fix joining restricted rooms with invite 2025-08-28 23:28:20 +05:00
dasha_uwu c40671bfb0 Remove api crate dependency from admin crate 2025-08-28 23:28:20 +05:00
dasha_uwu 8e9c6661b2 Membership refactor
Introduce deactivate, membership services

Move membership and user deactivation functions from api crate into those services
2025-08-28 23:28:20 +05:00
dasha_uwu 6810604629 banned_room_check: pull out common part 2025-08-28 23:28:20 +05:00
dasha_uwu 3dd984eff9 clippy: add must_use attribute 2025-08-28 23:28:20 +05:00
dasha_uwu bcd4f80149 Move server user presence handling to presence service 2025-08-28 23:28:20 +05:00
dasha_uwu f51a7b12b5 Make Service.interrupt async 2025-08-28 23:28:20 +05:00
dasha_uwu 3a1649bcaf Add config option for creating admin room non-federated (closes #118) 2025-08-28 23:28:20 +05:00
dasha_uwu d4421422b2 Remove explicit unstable thirdparty/protocols route
Already handled by the other ruma route
2025-08-28 23:28:20 +05:00
dasha_uwu 4884c55be7 Split disable_room, ban_room functions 2025-08-28 23:28:13 +05:00
Jason Volk a4f589f475 Remove unnecessary recursion_limit.
Reduce type_length_limits.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-28 23:20:44 +05:00
dasha_uwu b5890b9664 Services refactor
Replace structs of Dep<Service> with OnceServices, so each service has a Services reference

Remove service name => Service map

Flatten Services.rooms

Make reqwest Clients lazy initialized (client service)
2025-08-28 23:15:59 +05:00
Jason Volk 26b3a84b88 Fix updated serde type expected by database deserialize_any.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-27 00:41:13 +00:00
Jason Volk 3430d4ac86 Improved solution to current_shortstatehash > next_batch. (59b62b1)
`current_shortstatehash` is now calculated from timeline which is already
upper-bound by the `next_batch` snapshot. Previously `current_shortstatehash`
was truly current and had to be disallowed from exceeding `next_batch` by
ignoring the room during sync until a future pass when these values finally
met that condition.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-27 00:41:12 +00:00
Jason Volk 3e2f2fbffa Bump Ruma post-hydra.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-27 00:41:12 +00:00
Jason Volk 74deb14ca0 Bump Complement post-hydra.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-27 00:41:12 +00:00
Jason Volk acd930b9ca Replace clippy::string_to_string with clippy::implicit_clone
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-26 08:49:26 +00:00
Jason Volk e2db2029c5 Add note directing users to docker deployment docs.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-26 02:40:25 +00:00
Jason Volk 4bb83a1972 Fix version 12 outgoing federation format.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-26 02:40:25 +00:00
Jason Volk 751aa27859 Bump dependencies for yanked slab.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-14 02:25:54 +00:00
Jason Volk 628597c318 State-reset and security mitigations.
Upgrade Ruma to present.

The following are intentionally benign for activation in a later commit:

- Hydra backports not default.
- Room version 12 not default.
- Room version 12 not listed as stable.

Do not enable them manually or you can brick your database.

Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-11 18:45:28 +00:00
Jason Volk 2c6dd78502 Reduce log level on router::args returned error.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-11 11:32:53 +00:00
Jason Volk cdb0e31b21 Allow clippy::default_trait_access.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-11 11:32:53 +00:00
dasha_uwu 6a6f77a100 Simplify feature condition.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-11 10:24:40 +00:00
Jason Volk a3666fe672 Use member profile rather than global profile for joined_members (fixes #121)
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-10 23:52:03 +00:00
Jason Volk 0c8df52d18 Bump dependencies.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-07 04:52:46 +00:00
Jason Volk d7e5c0ccf3 Optimize spaces pageload; pipeline outer loop.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-08-07 03:16:32 +00:00
395 changed files with 27530 additions and 14665 deletions

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
[env]
RUMA_UNSTABLE_EXHAUSTIVE_TYPES = "true"
File renamed without changes.
+2
View File
@@ -106,6 +106,7 @@ jobs:
excludes: ${{inputs.excludes}}
includes: ${{inputs.includes}}
# disabled due to excessive build time issue installing cargo lychee
lychee:
if: >
!failure() && !cancelled()
@@ -113,6 +114,7 @@ jobs:
&& contains(fromJSON(inputs.feat_sets), fromJSON('["all"]')[0])
&& contains(fromJSON(inputs.rust_toolchains), fromJSON('["nightly"]')[0])
&& contains(fromJSON(inputs.sys_targets), fromJSON('["x86_64-v1-linux-gnu"]')[0])
&& false
name: Lychee
uses: ./.github/workflows/bake.yml
+49 -11
View File
@@ -40,12 +40,16 @@ jobs:
machines: ${{vars.MACHINES || env.default_machines}}
package: ${{vars.PACKAGE || !contains(github.ref, 'refs/pull/')}}
publish: ${{vars.PUBLISH || !contains(github.ref, 'refs/pull/')}}
build_nix: ${{vars.BUILD_NIX || !contains(github.ref, 'refs/pull/')}}
build_pkgs: ${{vars.BUILD_PKGS || github.ref == 'refs/heads/main' || contains(github.ref, 'tags/v')}}
check_pkgs: ${{vars.CHECK_PKGS || 'false'}}
complement: ${{vars.COMPLEMENT || 'true'}}
complement_runner: 'het'
docker_repo: ${{vars.DOCKER_REPO}}
release_url: ${{steps.release.outputs.upload_url}}
pages_url: 'https://matrix-construct.github.io/tuwunel/'
rust_sdk_integration: ${{vars.RUST_SDK_INTEGRATION || 'true'}}
head_msg: ${{github.event.head_commit.message || github.event.workflow_run.head_commit.message}}
strategy:
fail-fast: true
@@ -58,8 +62,8 @@ jobs:
- name: Initialize Builder
env:
runner: ${{matrix.runner}}
reserved_space: '{"het": "384GB", "aws": "48GB", "gcp": "160GB"}'
max_used_space: '{"het": "512GB", "aws": "64GB", "gcp": "192GB"}'
reserved_space: '{"het": "192GB", "aws": "48GB", "gcp": "160GB"}'
max_used_space: '{"het": "384GB", "aws": "64GB", "gcp": "192GB"}'
run: |
set +e
docker buildx inspect "${GITHUB_ACTOR}"
@@ -114,6 +118,8 @@ jobs:
if: >
!failure() && !cancelled()
&& !contains(github.ref, 'refs/tags/v')
&& !contains(needs.init.outputs.head_msg, '[ci no lint]')
&& !contains(needs.init.outputs.head_msg, '[ci only it]')
name: Lint
needs: [init] #needs: [init, deps]
@@ -129,17 +135,22 @@ jobs:
machines: ${{needs.init.outputs.machines}}
excludes: >
[
{"cargo_profile": "test", "feat_set": "logging"},
{"cargo_profile": "test", "rust_toolchain": "stable", "feat_set": "none"},
{"cargo_profile": "test", "rust_target": "aarch64-unknown-linux-gnu"},
{"cargo_profile": "bench"},
{"cargo_profile": "release", "rust_toolchain": "nightly", "feat_set": "none"},
{"cargo_profile": "release", "rust_toolchain": "nightly", "feat_set": "default"},
{"cargo_profile": "release", "rust_toolchain": "nightly", "feat_set": "logging"},
{"cargo_profile": "release-debuginfo"},
{"cargo_profile": "release-native", "rust_toolchain": "stable"},
{"cargo_profile": "release-native", "feat_set": "none"},
{"cargo_profile": "release-native", "feat_set": "default"},
{"cargo_profile": "release-native", "feat_set": "logging"},
{"cargo_profile": "release-native", "rust_toolchain": "stable"},
{"cargo_profile": "release-native", "rust_target": "aarch64-unknown-linux-gnu"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "none"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "default"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "logging"},
{"rust_target": "aarch64-unknown-linux-gnu", "rust_toolchain": "nightly"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v1-linux-gnu"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v2-linux-gnu"},
@@ -157,11 +168,15 @@ jobs:
if: >
!failure() && !cancelled()
&& !contains(github.ref, 'refs/tags/v')
&& !contains(needs.init.outputs.head_msg, '[ci no test]')
name: Test
needs: [init, lint]
uses: ./.github/workflows/test.yml
with:
head_msg: ${{needs.init.outputs.head_msg}}
build_nix: ${{fromJSON(needs.init.outputs.build_nix)}}
rust_sdk_integration: ${{fromJSON(needs.init.outputs.rust_sdk_integration)}}
complement: ${{fromJSON(needs.init.outputs.complement)}}
complement_runner: ${{needs.init.outputs.complement_runner}}
cargo_profiles: ${{needs.init.outputs.cargo_profiles}}
@@ -174,15 +189,17 @@ jobs:
machines: ${{needs.init.outputs.machines}}
excludes: >
[
{"feat_set": "logging"},
{"cargo_profile": "test", "rust_toolchain": "stable", "feat_set": "none"},
{"cargo_profile": "test", "rust_target": "aarch64-unknown-linux-gnu"},
{"cargo_profile": "release-debuginfo"},
{"cargo_profile": "release-native", "rust_toolchain": "stable"},
{"cargo_profile": "release-native", "feat_set": "default"},
{"cargo_profile": "release-native", "feat_set": "none"},
{"cargo_profile": "release-native", "feat_set": "default"},
{"cargo_profile": "release-native", "rust_toolchain": "stable"},
{"cargo_profile": "release-native", "rust_target": "aarch64-unknown-linux-gnu"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "none"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "default"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "logging"},
{"rust_target": "aarch64-unknown-linux-gnu", "rust_toolchain": "nightly"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v1-linux-gnu"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v2-linux-gnu"},
@@ -206,14 +223,18 @@ jobs:
if: >
!failure() && !cancelled()
&& needs.init.outputs.package
&& !contains(needs.init.outputs.head_msg, '[ci only it]')
&& !contains(needs.init.outputs.head_msg, '[ci no build]')
&& !contains(needs.init.outputs.head_msg, '[ci no package]')
name: Package
needs: [init, lint]
needs: [init, test]
uses: ./.github/workflows/package.yml
with:
release_url: ${{needs.init.outputs.release_url}}
check_pkgs: ${{needs.init.outputs.check_pkgs}}
build_pkgs: ${{needs.init.outputs.build_pkgs}}
build_nix: ${{fromJSON(needs.init.outputs.build_nix)}}
cargo_profiles: ${{needs.init.outputs.cargo_profiles}}
feat_sets: ${{needs.init.outputs.feat_sets}}
rust_toolchains: ${{needs.init.outputs.rust_toolchains}}
@@ -226,8 +247,10 @@ jobs:
[
{"feat_set": "none"},
{"cargo_profile": "test"},
{"cargo_profile": "bench"},
{"cargo_profile": "release-native"},
{"cargo_profile": "release-debuginfo", "feat_set": "default"},
{"cargo_profile": "release-debuginfo", "feat_set": "logging"},
{"cargo_profile": "release-debuginfo", "rust_toolchain": "nightly"},
{"cargo_profile": "release-debuginfo", "bake_target": "oci"},
{"cargo_profile": "release-debuginfo", "rust_target": "aarch64-unknown-linux-gnu"},
@@ -236,6 +259,8 @@ jobs:
{"cargo_profile": "release-debuginfo", "sys_target": "x86_64-v4-linux-gnu"},
{"cargo_profile": "release", "rust_toolchain": "nightly"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "default"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "logging"},
{"rust_target": "aarch64-unknown-linux-gnu", "bake_target": "nix"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v1-linux-gnu"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v2-linux-gnu"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v3-linux-gnu"},
@@ -245,16 +270,26 @@ jobs:
{"sys_target": "x86_64-v1-linux-gnu", "machine": "ARM64"},
{"sys_target": "x86_64-v2-linux-gnu", "machine": "ARM64"},
{"sys_target": "x86_64-v2-linux-gnu", "feat_set": "default"},
{"sys_target": "x86_64-v2-linux-gnu", "feat_set": "logging"},
{"sys_target": "x86_64-v2-linux-gnu", "bake_target": "nix"},
{"sys_target": "x86_64-v3-linux-gnu", "machine": "ARM64"},
{"sys_target": "x86_64-v3-linux-gnu", "feat_set": "default"},
{"sys_target": "x86_64-v3-linux-gnu", "feat_set": "logging"},
{"sys_target": "x86_64-v3-linux-gnu", "bake_target": "nix"},
{"sys_target": "x86_64-v4-linux-gnu", "machine": "ARM64"},
{"sys_target": "x86_64-v4-linux-gnu", "feat_set": "default"},
{"sys_target": "x86_64-v4-linux-gnu", "feat_set": "logging"},
{"sys_target": "x86_64-v4-linux-gnu", "bake_target": "nix"},
]
publish:
if: >
!failure() && !cancelled()
&& needs.init.outputs.publish
&& !contains(needs.init.outputs.head_msg, '[ci only it]')
&& !contains(needs.init.outputs.head_msg, '[ci no build]')
&& !contains(needs.init.outputs.head_msg, '[ci no package]')
&& !contains(needs.init.outputs.head_msg, '[ci no publish]')
name: Publish
needs: [init, test, package]
@@ -262,6 +297,7 @@ jobs:
with:
docker_repo: ${{needs.init.outputs.docker_repo}}
release_url: ${{needs.init.outputs.release_url}}
pages_url: ${{needs.init.outputs.pages_url}}
cargo_profiles: ${{needs.init.outputs.cargo_profiles}}
feat_sets: ${{needs.init.outputs.feat_sets}}
rust_toolchains: ${{needs.init.outputs.rust_toolchains}}
@@ -273,11 +309,13 @@ jobs:
excludes: >
[
{"feat_set": "none"},
{"feat_set": "default"},
{"cargo_profile": "test"},
{"cargo_profile": "bench"},
{"cargo_profile": "release-debuginfo"},
{"cargo_profile": "release-native"},
{"cargo_profile": "release", "rust_toolchain": "nightly"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "default"},
{"rust_toolchain": "nightly"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "logging"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v1-linux-gnu"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v2-linux-gnu"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v3-linux-gnu"},
@@ -286,11 +324,11 @@ jobs:
{"sys_target": "aarch64-v8-linux-gnu", "machine": "X64"},
{"sys_target": "x86_64-v1-linux-gnu", "machine": "ARM64"},
{"sys_target": "x86_64-v2-linux-gnu", "machine": "ARM64"},
{"sys_target": "x86_64-v2-linux-gnu", "feat_set": "default"},
{"sys_target": "x86_64-v2-linux-gnu", "feat_set": "logging"},
{"sys_target": "x86_64-v3-linux-gnu", "machine": "ARM64"},
{"sys_target": "x86_64-v3-linux-gnu", "feat_set": "default"},
{"sys_target": "x86_64-v3-linux-gnu", "feat_set": "logging"},
{"sys_target": "x86_64-v4-linux-gnu", "machine": "ARM64"},
{"sys_target": "x86_64-v4-linux-gnu", "feat_set": "default"},
{"sys_target": "x86_64-v4-linux-gnu", "feat_set": "logging"},
]
secrets:
+10 -1
View File
@@ -44,6 +44,9 @@ on:
check_pkgs:
type: string
default: 'false'
build_nix:
type: string
default: 'true'
jobs:
book:
@@ -155,7 +158,7 @@ jobs:
name: Distro Packages
uses: ./.github/workflows/bake.yml
with:
bake_targets: '["deb", "rpm"]'
bake_targets: '["deb", "rpm", "nix"]'
cargo_profiles: '["release"]'
feat_sets: '["all"]'
rust_toolchains: '["stable"]'
@@ -176,6 +179,12 @@ jobs:
"rpm": {
"dst": "tuwunel.rpm",
"mime": "application/x-rpm"
},
"nix": {
"dst": "tuwunel.drv.tar.zst",
"src": "/opt/tuwunel/tuwunel.drv",
"mime": "application/zstd",
"zstd": 6
}
}
+9 -2
View File
@@ -44,20 +44,27 @@ on:
release_url:
type: string
description: For release assets
pages_url:
type: string
description: For pages deployment
jobs:
documents:
if: >
!failure() && !cancelled()
&& contains(fromJSON(inputs.sys_targets), fromJSON('["X64"]')[0])
&& (github.ref == 'refs/heads/main' || contains(github.ref, 'refs/tags/v'))
&& !contains(github.ref, '-draft')
name: Documents
runs-on: ['X64', 'het']
permissions:
pages: write
contents: read
id-token: write
pages: write
environment:
name: github-pages
url: ${{inputs.pages_url}}
steps:
- id: book
+165 -6
View File
@@ -43,11 +43,43 @@ on:
default: '["all"]'
complement_runner:
type: string
rust_sdk_integration:
type: boolean
default: true
build_nix:
type: boolean
default: true
head_msg:
type: string
jobs:
docs:
if: >
!contains(inputs.head_msg, '[ci only it]')
&& contains(fromJSON(inputs.cargo_profiles), fromJSON('["test"]')[0])
&& contains(fromJSON(inputs.feat_sets), fromJSON('["all"]')[0])
&& contains(fromJSON(inputs.rust_toolchains), fromJSON('["nightly"]')[0])
&& contains(fromJSON(inputs.sys_targets), fromJSON('["x86_64-v1-linux-gnu"]')[0])
name: Docs
uses: ./.github/workflows/bake.yml
with:
bake_targets: '["docs"]'
cargo_profiles: '["test"]'
feat_sets: '["all"]'
rust_toolchains: '["nightly"]'
sys_names: ${{inputs.sys_names}}
sys_versions: ${{inputs.sys_versions}}
rust_targets: ${{inputs.rust_targets}}
sys_targets: '["x86_64-v1-linux-gnu"]'
machines: ${{inputs.machines}}
excludes: ${{inputs.excludes}}
includes: ${{inputs.includes}}
unit:
if: >
contains(fromJSON(inputs.cargo_profiles), fromJSON('["test"]')[0])
!contains(inputs.head_msg, '[ci only it]')
&& contains(fromJSON(inputs.cargo_profiles), fromJSON('["test"]')[0])
&& contains(fromJSON(inputs.feat_sets), fromJSON('["all"]')[0])
&& contains(fromJSON(inputs.rust_toolchains), fromJSON('["nightly"]')[0])
&& contains(fromJSON(inputs.sys_targets), fromJSON('["x86_64-v1-linux-gnu"]')[0])
@@ -55,7 +87,7 @@ jobs:
name: Unit
uses: ./.github/workflows/bake.yml
with:
bake_targets: '["unit"]'
bake_targets: '["unit", "integration"]'
cargo_profiles: '["test"]'
feat_sets: '["all"]'
rust_toolchains: ${{inputs.rust_toolchains}}
@@ -67,9 +99,57 @@ jobs:
excludes: ${{inputs.excludes}}
includes: ${{inputs.includes}}
bench:
if: >
!contains(inputs.head_msg, '[ci only it]')
&& contains(fromJSON(inputs.cargo_profiles), fromJSON('["bench"]')[0])
&& contains(fromJSON(inputs.feat_sets), fromJSON('["all"]')[0])
&& contains(fromJSON(inputs.rust_toolchains), fromJSON('["nightly"]')[0])
&& contains(fromJSON(inputs.sys_targets), fromJSON('["x86_64-v3-linux-gnu"]')[0])
name: Bench
uses: ./.github/workflows/bake.yml
with:
bake_targets: '["unit", "integration"]'
cargo_profiles: '["bench"]'
feat_sets: '["all"]'
rust_toolchains: '["nightly"]'
sys_names: ${{inputs.sys_names}}
sys_versions: ${{inputs.sys_versions}}
rust_targets: ${{inputs.rust_targets}}
sys_targets: '["x86_64-v3-linux-gnu"]'
machines: ${{inputs.machines}}
excludes: ${{inputs.excludes}}
includes: ${{inputs.includes}}
valgrind:
if: >
!contains(inputs.head_msg, '[ci only it]')
&& contains(fromJSON(inputs.cargo_profiles), fromJSON('["bench"]')[0])
&& contains(fromJSON(inputs.feat_sets), fromJSON('["all"]')[0])
&& contains(fromJSON(inputs.rust_toolchains), fromJSON('["nightly"]')[0])
&& contains(fromJSON(inputs.sys_targets), fromJSON('["x86_64-v3-linux-gnu"]')[0])
name: Memcheck
uses: ./.github/workflows/bake.yml
with:
bake_targets: '["integration-valgrind"]'
cargo_profiles: '["bench"]'
feat_sets: '["all"]'
rust_toolchains: '["nightly"]'
sys_names: ${{inputs.sys_names}}
sys_versions: ${{inputs.sys_versions}}
rust_targets: ${{inputs.rust_targets}}
sys_targets: '["x86_64-v3-linux-gnu"]'
machines: ${{inputs.machines}}
excludes: ${{inputs.excludes}}
includes: ${{inputs.includes}}
smoke:
if: >
!failure() && !cancelled()
&& !contains(inputs.head_msg, '[ci only it]')
&& !contains(inputs.head_msg, '[ci no build]')
&& inputs.cargo_profiles
&& inputs.machines
@@ -89,13 +169,18 @@ jobs:
excludes: >
[
{"cargo_profile": "test", "feat_set": "default"},
{"cargo_profile": "test", "feat_set": "logging"},
{"cargo_profile": "test", "feat_set": "none", "bake_target": "smoke-valgrind"},
{"cargo_profile": "test", "rust_toolchain": "stable"},
{"cargo_profile": "test", "rust_target": "aarch64-unknown-linux-gnu"},
{"cargo_profile": "test", "sys_target": "x86_64-v2-linux-gnu", "bake_target": "smoke-valgrind"},
{"cargo_profile": "test", "sys_target": "x86_64-v2-linux-gnu"},
{"cargo_profile": "test", "sys_target": "x86_64-v3-linux-gnu"},
{"cargo_profile": "test", "bake_target": "smoke-valgrind"},
{"cargo_profile": "bench"},
{"cargo_profile": "release", "rust_toolchain": "nightly"},
{"cargo_profile": "release", "rust_toolchain": "stable", "feat_set": "none"},
{"cargo_profile": "release", "bake_target": "smoke-valgrind"},
{"cargo_profile": "release-debuginfo", "feat_set": "logging"},
{"cargo_profile": "release-debuginfo", "rust_toolchain": "nightly"},
{"cargo_profile": "release-debuginfo", "rust_toolchain": "stable", "feat_set": "none"},
{"cargo_profile": "release-debuginfo", "bake_target": "smoke"},
@@ -103,6 +188,7 @@ jobs:
{"cargo_profile": "release-native", "rust_toolchain": "stable"},
{"cargo_profile": "release-native", "feat_set": "none"},
{"cargo_profile": "release-native", "feat_set": "default"},
{"cargo_profile": "release-native", "feat_set": "logging"},
{"cargo_profile": "release-native", "bake_target": "smoke-valgrind"},
{"cargo_profile": "release-native", "rust_target": "aarch64-unknown-linux-gnu"},
{"cargo_profile": "release-native", "sys_target": "x86_64-v2-linux-gnu"},
@@ -110,6 +196,7 @@ jobs:
{"cargo_profile": "release-native", "sys_target": "x86_64-v4-linux-gnu"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "none"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "default"},
{"rust_target": "aarch64-unknown-linux-gnu", "feat_set": "logging"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v1-linux-gnu"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v2-linux-gnu"},
{"rust_target": "aarch64-unknown-linux-gnu", "sys_target": "x86_64-v3-linux-gnu"},
@@ -120,19 +207,90 @@ jobs:
{"sys_target": "x86_64-v2-linux-gnu", "machine": "ARM64"},
{"sys_target": "x86_64-v2-linux-gnu", "feat_set": "none"},
{"sys_target": "x86_64-v2-linux-gnu", "feat_set": "default"},
{"sys_target": "x86_64-v2-linux-gnu", "feat_set": "logging"},
{"sys_target": "x86_64-v3-linux-gnu", "machine": "ARM64"},
{"sys_target": "x86_64-v3-linux-gnu", "feat_set": "none"},
{"sys_target": "x86_64-v3-linux-gnu", "feat_set": "default"},
{"sys_target": "x86_64-v3-linux-gnu", "feat_set": "logging"},
{"sys_target": "x86_64-v3-linux-gnu", "bake_target": "smoke-valgrind"},
{"sys_target": "x86_64-v4-linux-gnu", "machine": "ARM64"},
{"sys_target": "x86_64-v4-linux-gnu", "feat_set": "none"},
{"sys_target": "x86_64-v4-linux-gnu", "feat_set": "default"},
{"sys_target": "x86_64-v4-linux-gnu", "feat_set": "logging"},
{"sys_target": "x86_64-v4-linux-gnu", "bake_target": "smoke-valgrind"},
]
nix:
if: >
!failure() && !cancelled()
&& !contains(inputs.head_msg, '[ci only it]')
&& !contains(inputs.head_msg, '[ci no build]')
&& contains(fromJSON(inputs.cargo_profiles), fromJSON('["release"]')[0])
&& contains(fromJSON(inputs.feat_sets), fromJSON('["all"]')[0])
&& contains(fromJSON(inputs.rust_toolchains), fromJSON('["stable"]')[0])
&& contains(fromJSON(inputs.sys_targets), fromJSON('["x86_64-v1-linux-gnu"]')[0])
&& fromJSON(inputs.build_nix)
name: Smoke NixOS
uses: ./.github/workflows/bake.yml
with:
bake_targets: '["smoke-nix"]'
cargo_profiles: '["release"]'
feat_sets: '["all"]'
rust_toolchains: '["stable"]'
sys_names: ${{inputs.sys_names}}
sys_versions: ${{inputs.sys_versions}}
rust_targets: ${{inputs.rust_targets}}
sys_targets: '["x86_64-v1-linux-gnu"]'
machines: ${{inputs.machines}}
excludes: ${{inputs.excludes}}
includes: ${{inputs.includes}}
matrix-rust-sdk-integration:
if: >
!failure() && !cancelled()
&& !contains(inputs.head_msg, '[ci no build]')
&& inputs.rust_sdk_integration
&& contains(fromJSON(inputs.feat_sets), fromJSON('["all"]')[0])
&& contains(fromJSON(inputs.rust_toolchains), fromJSON('["nightly"]')[0])
&& contains(fromJSON(inputs.rust_targets), fromJSON('["x86_64-unknown-linux-gnu"]')[0])
&& contains(fromJSON(inputs.sys_targets), fromJSON('["x86_64-v1-linux-gnu"]')[0])
name: Matrix SDK Integration
needs: [smoke]
uses: ./.github/workflows/bake.yml
with:
bake_targets: '["matrix-rust-sdk-integration"]'
cargo_profiles: ${{inputs.cargo_profiles}}
feat_sets: '["all"]'
rust_toolchains: '["nightly"]'
sys_names: ${{inputs.sys_names}}
sys_versions: ${{inputs.sys_versions}}
rust_targets: '["x86_64-unknown-linux-gnu"]'
sys_targets: '["x86_64-v1-linux-gnu"]'
machines: '["X64"]'
runner: ${{inputs.complement_runner}}
includes: ${{inputs.includes}}
artifact: >
{
"matrix-rust-sdk-integration": {
"src": "/var/log/tuwunel.log",
"dst": "matrix-rust-sdk-integration.tuwunel.log",
}
}
excludes: >
[
{"feat_set": "none"},
{"feat_set": "logging"},
{"cargo_profile": "release"},
{"cargo_profile": "release-debuginfo"},
{"cargo_profile": "release-native"},
]
complement:
if: >
!failure() && !cancelled()
&& !contains(inputs.head_msg, '[ci no build]')
&& inputs.complement
&& contains(fromJSON(inputs.cargo_profiles), fromJSON('["test"]')[0])
&& contains(fromJSON(inputs.complement_feat_sets), fromJSON('["all"]')[0])
@@ -158,6 +316,7 @@ jobs:
compliance:
if: >
!failure() && !cancelled()
&& !contains(inputs.head_msg, '[ci no build]')
&& inputs.complement
&& inputs.machines
&& contains(fromJSON(inputs.cargo_profiles), fromJSON('["test"]')[0])
@@ -166,7 +325,7 @@ jobs:
&& contains(fromJSON(inputs.sys_targets), fromJSON('["x86_64-v1-linux-gnu"]')[0])
name: Matrix Compliance
needs: [complement]
needs: [complement, smoke]
runs-on: ["${{matrix.machine}}", "${{inputs.complement_runner}}"]
concurrency:
group: complement-cant-walk-and-chew-bubblegum
@@ -212,7 +371,7 @@ jobs:
run: |
cid=$(cat "$name")
docker cp "$cid:/usr/src/complement/new_results.jsonl" tests/test_results/complement/test_results.jsonl
docker cp "$cid:/usr/src/complement/new_results.jsonl" tests/complement/results.jsonl
- if: success() || failure() && steps.execute.outcome == 'failure'
name: Upload New Results
@@ -220,7 +379,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: complement_results-${{matrix.feat_set}}-${{matrix.sys_name}}-${{matrix.sys_target}}.jsonl
path: ./tests/test_results/complement/test_results.jsonl
path: ./tests/complement/results.jsonl
- if: failure() && steps.execute.outcome == 'failure'
name: Upload Failure Output
Generated
+882 -678
View File
File diff suppressed because it is too large. Load diff
+122 -118
View File
@@ -29,7 +29,7 @@ license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/matrix-construct/tuwunel"
rust-version = "1.88.0"
version = "1.3.0"
version = "1.4.5"
[workspace.metadata.crane]
name = "tuwunel"
@@ -39,7 +39,7 @@ name = "tuwunel"
#
[workspace.dependencies.argon2]
version = "0.5.3"
version = "0.5"
default-features = false
features = [
"alloc",
@@ -47,17 +47,17 @@ features = [
]
[workspace.dependencies.arrayvec]
version = "0.7.6"
version = "0.7"
features = ["serde"]
[workspace.dependencies.async-channel]
version = "2.3.1"
[workspace.dependencies.async-trait]
version = "0.1.88"
version = "0.1"
[workspace.dependencies.axum]
version = "0.8.4"
version = "0.8"
default-features = false
features = [
"form",
@@ -73,7 +73,7 @@ features = [
version = "0.7"
[workspace.dependencies.axum-extra]
version = "0.10.1"
version = "0.10"
default-features = false
features = [
"typed-header",
@@ -81,7 +81,7 @@ features = [
]
[workspace.dependencies.axum-server]
version = "0.7.2"
version = "0.7"
default-features = false
[workspace.dependencies.axum-server-dual-protocol]
@@ -89,11 +89,11 @@ version = "0.7"
default-features = false
[workspace.dependencies.base64]
version = "0.22.1"
version = "0.22"
default-features = false
[workspace.dependencies.blurhash]
version = "0.2.3"
version = "0.2"
default-features = false
features = [
"fast-linear-to-srgb",
@@ -101,13 +101,13 @@ features = [
]
[workspace.dependencies.bytes]
version = "1.10.1"
version = "1.10"
[workspace.dependencies.bytesize]
version = "2.0.1"
version = "2.0"
[workspace.dependencies.cargo_toml]
version = "0.22.1"
version = "0.22"
default-features = false
features = ["features"]
@@ -115,12 +115,12 @@ features = ["features"]
version = "0.1"
[workspace.dependencies.chrono]
version = "0.4.41"
version = "0.4"
features = ["alloc", "std"]
default-features = false
[workspace.dependencies.clap]
version = "4.5.39"
version = "4.5"
default-features = false
features = [
"derive",
@@ -140,40 +140,40 @@ features = [
version = "0.8.3"
[workspace.dependencies.const-str]
version = "0.6.2"
version = "0.7"
[workspace.dependencies.criterion]
version = "0.7"
default-features = false
features = [
"cargo_bench_support",
"async_futures",
"async_tokio",
]
[workspace.dependencies.ctor]
version = "0.4.2"
version = "0.5"
[workspace.dependencies.cyborgtime]
version = "2.1.1"
version = "2.1"
[workspace.dependencies.either]
version = "1.15.0"
version = "1.15"
default-features = false
features = ["serde"]
[workspace.dependencies.figment]
version = "0.10.19"
version = "0.10"
default-features = false
features = ["env", "toml"]
[workspace.dependencies.futures]
version = "0.3.31"
version = "0.3"
default-features = false
features = ["std", "async-await"]
[workspace.dependencies.hardened_malloc-rs]
version = "0.1.2"
default-features = false
features = [
"static",
"gcc",
"light",
]
[workspace.dependencies.hickory-resolver]
version = "0.25.2"
version = "0.25"
default-features = false
features = [
"serde",
@@ -182,17 +182,17 @@ features = [
]
[workspace.dependencies.hmac]
version = "0.12.1"
version = "0.12"
default-features = false
[workspace.dependencies.http]
version = "1.3.1"
version = "1.3"
[workspace.dependencies.http-body-util]
version = "0.1.3"
version = "0.1"
[workspace.dependencies.hyper]
version = "1.6.0"
version = "1.6"
default-features = false
features = [
"server",
@@ -210,7 +210,7 @@ features = [
]
[workspace.dependencies.image]
version = "0.25.6"
version = "0.25"
default-features = false
features = [
"jpeg",
@@ -219,14 +219,20 @@ features = [
"webp",
]
[workspace.dependencies.insta]
version = "1.43"
features = [
"json",
]
[workspace.dependencies.ipaddress]
version = "0.1.3"
version = "0.1"
[workspace.dependencies.itertools]
version = "0.14.0"
version = "0.14"
[workspace.dependencies.jsonwebtoken]
version = "9.3.1"
version = "9.3"
default-features = false
features = ["use_pem"]
@@ -237,39 +243,42 @@ default-features = false
features = ["sync", "tls-rustls"]
[workspace.dependencies.libc]
version = "0.2.172"
version = "0.2"
[workspace.dependencies.libloading]
version = "0.8.8"
version = "0.8"
[workspace.dependencies.log]
version = "0.4.27"
version = "0.4"
default-features = false
[workspace.dependencies.loole]
version = "0.4.1"
version = "0.4"
[workspace.dependencies.lru-cache]
version = "0.1.2"
version = "0.1"
[workspace.dependencies.maplit]
version = "1.0.2"
version = "1.0"
[workspace.dependencies.minicbor]
version = "1.0.0"
version = "2.0"
features = ["std"]
[workspace.dependencies.minicbor-serde]
version = "0.5.0"
version = "0.6"
features = ["std"]
[workspace.dependencies.nix]
version = "0.30.1"
version = "0.30"
default-features = false
features = ["resource"]
features = [
"resource",
"user",
]
[workspace.dependencies.num-traits]
version = "0.2.19"
version = "0.2"
[workspace.dependencies.opentelemetry]
version = "0.30.0"
@@ -280,23 +289,23 @@ version = "0.30.0"
#features = ["rt-tokio"]
[workspace.dependencies.opentelemetry_sdk]
version = "0.30.0"
version = "0.30"
features = ["rt-tokio"]
[workspace.dependencies.proc-macro2]
version = "1.0.95"
version = "1.0"
[workspace.dependencies.quote]
version = "1.0.40"
version = "1.0"
[workspace.dependencies.rand]
version = "0.8.5"
version = "0.8"
[workspace.dependencies.regex]
version = "1.11.1"
version = "1.11"
[workspace.dependencies.reqwest]
version = "0.12.19"
version = "0.12"
default-features = false
features = [
"rustls-tls-native-roots",
@@ -306,25 +315,24 @@ features = [
]
[workspace.dependencies.ring]
version = "0.17.14"
version = "0.17"
default-features = false
[workspace.dependencies.ruma]
git = "https://github.com/matrix-construct/ruma"
rev = "0155c2b33233bec9dece79d5134a9574b347f4c1"
rev = "b858d3478f2792a381463ef9b63f6c1469a5d81c"
features = [
"compat",
"rand",
"__compat",
"appservice-api-c",
"client-api",
"client-api-s",
"compat-upload-signatures",
"federation-api",
"identifiers-validation",
"markdown",
"push-gateway-api-c",
"unstable-exhaustive-types",
"rand",
"ring-compat",
"compat-upload-signatures",
"identifiers-validation",
"unstable-unspecified",
"unstable-msc2448",
"unstable-msc2666",
"unstable-msc2867",
@@ -332,24 +340,23 @@ features = [
"unstable-msc3026",
"unstable-msc3061",
"unstable-msc3245",
"unstable-msc3266",
"unstable-msc3381", # polls
"unstable-msc3489", # beacon / live location
"unstable-msc3575",
"unstable-msc3930", # polls push rules
"unstable-msc4075",
"unstable-msc4095",
"unstable-msc4121",
"unstable-msc4125",
"unstable-msc4133",
"unstable-msc4186",
"unstable-msc4203", # sending to-device events to appservices
"unstable-msc4210", # remove legacy mentions
"unstable-msc4310",
"unstable-msc4311",
"unstable-extensible-events",
"unstable-pdu",
]
[workspace.dependencies.rustls]
version = "0.23.27"
version = "0.23"
default-features = false
features = ["aws_lc_rs"]
@@ -370,14 +377,14 @@ features = [
]
[workspace.dependencies.sanitize-filename]
version = "0.6.0"
version = "0.6"
[workspace.dependencies.sd-notify]
version = "0.4.5"
version = "0.4"
default-features = false
[workspace.dependencies.sentry]
version = "0.38.1"
version = "0.42"
default-features = false
features = [
"backtrace",
@@ -393,48 +400,52 @@ features = [
]
[workspace.dependencies.sentry-tower]
version = "0.38.1"
version = "0.42"
[workspace.dependencies.sentry-tracing]
version = "0.38.1"
version = "0.42"
[workspace.dependencies.serde]
version = "1.0.219"
version = "1.0"
default-features = false
features = ["rc"]
[workspace.dependencies.serde_html_form]
version = "0.2.6"
version = "0.2"
[workspace.dependencies.serde_json]
version = "1.0.140"
version = "1.0"
default-features = false
features = ["raw_value"]
[workspace.dependencies.serde_regex]
version = "1.1.0"
version = "1.1"
[workspace.dependencies.serde_yaml]
version = "0.9.34"
version = "0.9"
[workspace.dependencies.sha1]
version = "0.10.6"
version = "0.10"
default-features = false
[workspace.dependencies.sha2]
version = "0.10.9"
version = "0.10"
default-features = false
[workspace.dependencies.similar]
version = "2.7"
[workspace.dependencies.smallstr]
version = "0.3"
features = [
"ffi",
"serde",
"std",
"union",
]
[workspace.dependencies.smallvec]
version = "1.15.1"
version = "1.15"
features = [
"const_generics",
"const_new",
@@ -444,7 +455,7 @@ features = [
]
[workspace.dependencies.syn]
version = "2.0.101"
version = "2.0"
default-features = false
features = [
"extra-traits",
@@ -455,11 +466,11 @@ features = [
]
[workspace.dependencies.termimad]
version = "0.33.0"
version = "0.34"
default-features = false
[workspace.dependencies.thiserror]
version = "2.0.12"
version = "2.0"
default-features = false
[workspace.dependencies.tikv-jemallocator]
@@ -487,7 +498,7 @@ features = [
]
[workspace.dependencies.tokio]
version = "1.46.0"
version = "1.47"
default-features = false
features = [
"fs",
@@ -502,20 +513,20 @@ features = [
]
[workspace.dependencies.tokio-metrics]
version = "0.4.2"
version = "0.4"
[workspace.dependencies.toml]
version = "0.8.23"
version = "0.9"
default-features = false
features = ["parse"]
[workspace.dependencies.tower]
version = "0.5.2"
version = "0.5"
default-features = false
features = ["util"]
[workspace.dependencies.tower-http]
version = "0.6.6"
version = "0.6"
default-features = false
features = [
"add-extension",
@@ -529,21 +540,21 @@ features = [
]
[workspace.dependencies.tracing]
version = "0.1.41"
version = "0.1"
default-features = false
[workspace.dependencies.tracing-core]
version = "0.1.33"
version = "0.1"
default-features = false
[workspace.dependencies.tracing-flame]
version = "0.2.0"
version = "0.2"
[workspace.dependencies.tracing-opentelemetry]
version = "0.31.0"
version = "0.31"
[workspace.dependencies.tracing-subscriber]
version = "0.3.19"
version = "0.3"
default-features = false
features = [
"ansi",
@@ -555,35 +566,18 @@ features = [
]
[workspace.dependencies.url]
version = "2.5.4"
version = "2.5"
default-features = false
features = ["serde"]
[workspace.dependencies.webpage]
version = "2.0.1"
version = "2.0"
default-features = false
#
# Patches
#
# backport of [https://github.com/tokio-rs/tracing/pull/2956] to the 0.1.x
# branch of tracing. we can switch back to upstream if #2956 is merged and
# backported in the upstream repo.
# https://github.com/girlbossceo/tracing/commit/b348dca742af641c47bc390261f60711c2af573c
[patch.crates-io.tracing-subscriber]
git = "https://github.com/matrix-construct/tracing"
rev = "1e64095a8051a1adf0d1faa307f9f030889ec2aa"
[patch.crates-io.tracing]
git = "https://github.com/matrix-construct/tracing"
rev = "1e64095a8051a1adf0d1faa307f9f030889ec2aa"
[patch.crates-io.tracing-core]
git = "https://github.com/matrix-construct/tracing"
rev = "1e64095a8051a1adf0d1faa307f9f030889ec2aa"
[patch.crates-io.tracing-log]
git = "https://github.com/matrix-construct/tracing"
rev = "1e64095a8051a1adf0d1faa307f9f030889ec2aa"
# adds a tab completion callback:
# https://github.com/girlbossceo/rustyline-async/commit/de26100b0db03e419a3d8e1dd26895d170d1fe50
# adds event for CTRL+\:
@@ -708,7 +702,7 @@ inherits = "release-native.build-override"
#]
[profile.bench]
debug = "limited"
debug = false
strip = false
#rustflags = [
# "-Cremark=all",
@@ -729,7 +723,7 @@ strip = false
# and can be raised if build times are tolerable.
[profile.dev]
debug = "full"
debug = 0
#rustflags = [
# '--cfg', 'tuwunel_mods',
# '-Ztime-passes',
@@ -789,7 +783,7 @@ inherits = "dev"
[profile.dev.package.'*']
inherits = "dev"
debug = "limited"
debug = 0
incremental = false
codegen-units = 1
opt-level = 'z'
@@ -806,6 +800,11 @@ opt-level = 'z'
# '-Clink-arg=-Wl,-z,nodelete',
#]
# same as dev but slower.
[profile.dbg]
inherits = "dev"
debug = "full"
# primarily used for CI
[profile.test]
debug = "limited"
@@ -897,6 +896,9 @@ multiple_crate_versions = { level = "allow", priority = 1 }
###################
complexity = { level = "warn", priority = -1 }
# promotes forward-compat for literal ..default() construction
needless_update = { level = "allow", priority = 1 }
###################
correctness = { level = "warn", priority = -1 }
@@ -909,12 +911,14 @@ option_if_let_else = { level = "allow", priority = 1 } # TODO
redundant_pub_crate = { level = "allow", priority = 1 } # TODO
significant_drop_in_scrutinee = { level = "allow", priority = 1 } # TODO
significant_drop_tightening = { level = "allow", priority = 1 } # TODO
tuple_array_conversions = { level = "allow", priority = 1 }
###################
pedantic = { level = "warn", priority = -1 }
## some sadness
too_long_first_doc_paragraph = { level = "allow", priority = 1 }
default_trait_access = { level = "allow", priority = 1 }
doc_markdown = { level = "allow", priority = 1 }
enum_glob_use = { level = "allow", priority = 1 }
if_not_else = { level = "allow", priority = 1 }
@@ -922,6 +926,7 @@ if_then_some_else_none = { level = "allow", priority = 1 }
inline_always = { level = "allow", priority = 1 }
map_unwrap_or = { level = "allow", priority = 1 }
match_bool = { level = "allow", priority = 1 }
match_same_arms = { level = "allow", priority = 1 }
missing_docs_in_private_items = { level = "allow", priority = 1 }
missing_errors_doc = { level = "allow", priority = 1 }
missing_panics_doc = { level = "allow", priority = 1 }
@@ -967,12 +972,11 @@ pub_without_shorthand = "warn"
rc_buffer = "warn"
rc_mutex = "warn"
redundant_type_annotations = "warn"
rest_pat_in_fully_bound_structs = "warn"
semicolon_outside_block = "warn"
str_to_string = "warn"
string_lit_chars_any = "warn"
string_slice = "warn"
string_to_string = "warn"
implicit_clone = "warn"
suspicious_xor_used_as_pow = "warn"
tests_outside_test_module = "warn"
try_err = "warn"
+8 -19
View File
@@ -21,7 +21,7 @@ with your favorite [client](https://matrix.org/ecosystem/clients/),
[bot](https://matrix.org/ecosystem/integrations/). It is written entirely in Rust to be a scalable,
lightweight, low-cost, community-driven alternative covering all but the most niche uses.
This project is the official successor to [conduwuit](https://github.com/girlbossceo/conduwuit), which
This project is the official successor to conduwuit, which
was a featureful and high-performance fork of [Conduit](https://gitlab.com/famedly/conduit), all
community-lead homeservers implementing the compatible
[Matrix Specification](https://spec.matrix.org/latest/).
@@ -57,12 +57,12 @@ using the configuration and Tuwunel can be deployed without a reverse proxy. Exa
`/etc/caddy/Caddyfile` configuration with [Element](https://github.com/element-hq/element-web/releases)
unzipped to `/var/www/element`:
```
https://tuwunel.me:8448 {
reverse_proxy http://127.0.0.1:8008
tuwunel.me, tuwunel.me:8448 {
reverse_proxy localhost:8008
}
https://tuwunel.me:443 {
root * /var/www/element/
file_server
web.tuwunel.me {
root * /var/www/element/
file_server
}
```
`caddy reload --config /etc/caddy/Caddyfile`
@@ -75,7 +75,7 @@ granted server admin.
🤗 Did you find this and other documentation helpful? We would love to hear feedback about setting
up Tuwunel.
### Migrating to Tuwunel
@@ -110,22 +110,11 @@ We strive to make moving between versions of Tuwunel safe and easy. Downgrading
safe but often prevented by a guard. An error will indicate the downgrade is not possible and a
newer version which does not error must be sought.
#### Versioning
Tuwunel uses a semantic version tag in the format of `v<major>.<minor>.<patch>`. The `patch` value will
always correspond to the number of commits from the last `minor` change with significance to developers.
The `minor` version is changed for fixes or features significant to users. The `major` value corresponds
to significant feature evolutions, and does not indicate any "breaking change" nor connote stability.
> [!IMPORTANT]
> **Users should attempt to keep up to date with the latest minor version.**
#### Branches
The main branch is always _reasonably safe_ to run. We understand the propensity for users to simply clone
the main branch to get up and running, and we're obliged to ensure it's always viable. Nevertheless, only
tagged releases are true releases. If you don't care to update often, find the latest `minor` version
change rather than `patch`. We don't recommend simply following `major` version changes at this time.
tagged releases are true releases.
#### Container Tracking
+4 -54
View File
@@ -1,59 +1,9 @@
# Tuwunel 1.3.0
# Tuwunel 1.4.5
August 4, 2025
Preparations for [Project Hydra](https://matrix.org/blog/2025/07/security-predisclosure/) have taken place. Users should be prepared to upgrade to `v1.4.0-rc` next week. Due to the comprehensive low-level changes which have taken place, and the inability to develop them in public with your feedback, the release will undergo an extended `-rc` period. Due to the time difference and scheduling conflicts our release may be published between 12 to 36 hours after the suggested time; though well before the written disclosure of the issues.
Some foundational work for `v1.4.0` was backported into this release after the announcement was made mid-July to further extend Hydra. An unexpected performance improvement drastically reduced CPU usage. As a result, integration tests began to flake, uncovering latent concurrency bugs which were addressed. These fixes primarily impact the legacy and sliding-sync systems, and further fixes improve performance and compliance, though mostly in the legacy system as sliding-sync lacks adequate test coverage.
This release fixes many bugs and improves performance but at the cost of planned features further rescheduled to either `v1.4.1` or `v1.5.0`.
### New Features
- Refresh tokens (MSC2918) have been implemented. Supporting clients can now timeout their access tokens with a soft-logout after a configured `access_token_ttl`. This feature was commissioned and made public by an enterprise sponsor.
- Typing indicators have been added to sliding-sync thanks to @tmayoff. This feature (and the whole of sliding-sync) is still experimental and the indicator may not always appear or disappear as intended, nevertheless the effort will be enhanced by foundational fixes improving sliding-sync requested soon by the project's sponsor.
### Enhancements
- @dasha_uwu maintains their streak as a serial contributor by patching the `!admin query raw` command with a base64 option allowing for low-level debugging of database records.
- @obioma has improved the documentation explaining how to use multiple configuration files with precedence.
- Upon recommendation of @grin a basic request ID has been added to the tracing logs to uniquely distinguish each request while it's interleaved among others.
- Requested by @fruzitent this and future releases are tagged by version as multi-arch docker images to be properly archived in the registry rather than simply overwriting `:latest`.
- Event processing performance has been improved by fetching and processing `prev_events` and `auth_events` concurrently. This reduces the impact of recursing large graphs while the room's mutex is locked.
- An experimental command `!admin debug resync-database` has been added for developers curious about #35
October 24, 2025
All deployments serving ElementX, Element Pro, SchildiChat Next, or any client using sliding-sync should upgrade to this patch for an improved experience.
### Bug Fixes
- Thanks to @tmayoff room avatars are properly calculated and no longer the same for all spaces (https://github.com/matrix-construct/tuwunel/pull/102).
- Courtesy of @coolGi69 our bump to Rust 1.88 was properly updated for Nix. Apologies to the Nix community for getting this wrong the first time.
- Invite rejections have been fixed, this was due to a misinterpretation of the spec in legacy sync.
- Knock rooms might have been buggy from the ambiguous overuse of the word "count" in the codebase. Database records which expected a summation of the users in a room instead received the sequence number of the server, both are called "count."
- Room knocks failed to wakeup the sync systems; some cases of account_data changes also failed to wakeup the sync systems. These have been addressed.
- The main sequence number fundamental to the entire server's operation (the "count" or counter) has been refactored after having exceeded architectural limitations. It has been replaced by a two-phase counter ensuring read-after-write consistency, and quasi-transactions grouping multiple writes.
- Sequence issues have been addressed in both legacy and sliding sync. These systems operate using a "snapshot" approach which intentionally ignores new data received by the server after the sync request has started; the snapshot approach replaced the complex of mutexes used by Conduit. The server was not originally designed for this approach and some information "from the future" continued to leak into the snapshot's window; these leaks have been sealed.
- Protocol compliance issues in legacy sync have been addressed. Additional compliance tests for device list updates now pass. The `state` and `timeline` on incremental sync provide expected results in more (if not all) cases.
- Errors requiring M_BAD_ALIAS instead of M_UNKNOWN when sending `m.room.canonical_alias` are now conforming.
### Deprecations
- Unauthenticated media fallbacks are no longer requested by default. This can still be enabled with `request_legacy_media` if desired.
- Legacy Sliding-Sync has been removed in favor of Simplified Sliding-Sync. Clients which exclusively using Sliding-Sync have already migrated around the start of this year, so this removal should have no impact now.
- Progress made for sliding-sync in 1.4.3 was effectively reverted by 1.4.4. This release puts sliding-sync back on track with further progress exceeding 1.4.3. This release is now shipping without any known issues. Please report all issues. **IMPORTANT:** Issues from prior releases (such as stuck or incorrect unread counts) benefit from clearing the app's cache to immediately resolve. Go to settings, tap the version number 7 times, then enter the menu to select `clear cache`.
+1 -1
View File
@@ -4,7 +4,6 @@ Wants=network-online.target
After=network-online.target
Documentation=https://tuwunel.chat/
RequiresMountsFor=/var/lib/private/tuwunel
Alias=matrix-tuwunel.service
[Service]
DynamicUser=yes
@@ -77,3 +76,4 @@ StartLimitBurst=5
[Install]
WantedBy=multi-user.target
Alias=matrix-tuwunel.service
+1 -1
View File
@@ -2,7 +2,6 @@
Description=Tuwunel Matrix homeserver
Wants=network-online.target
After=network-online.target
Alias=matrix-tuwunel.service
Documentation=https://tuwunel.chat/
[Service]
@@ -64,3 +63,4 @@ StartLimitBurst=5
[Install]
WantedBy=multi-user.target
Alias=matrix-tuwunel.service
+3
View File
@@ -16,6 +16,7 @@ ARG CARGO_TERM_VERBOSE=0
ARG RUST_BACKTRACE
ARG JEMALLOC_OVERRIDE
ARG ROCKSDB_LIB_DIR
ARG VALGRINDFLAGS=""
ARG CARGO_BUILD_RUSTFLAGS
ARG CARGO_PROFILE_TEST_DEBUG
ARG CARGO_PROFILE_TEST_INCREMENTAL
@@ -47,6 +48,7 @@ ENV CARGO_TERM_VERBOSE="${CARGO_TERM_VERBOSE}"
ENV RUST_BACKTRACE="${RUST_BACKTRACE}"
ENV JEMALLOC_OVERRIDE="${JEMALLOC_OVERRIDE}"
ENV ROCKSDB_LIB_DIR="${ROCKSDB_LIB_DIR}"
ENV VALGRINDFLAGS="${VALGRINDFLAGS}"
ENV CARGO_PROFILE_TEST_DEBUG="${CARGO_PROFILE_TEST_DEBUG}"
ENV CARGO_PROFILE_TEST_INCREMENTAL="${CARGO_PROFILE_TEST_INCREMENTAL}"
ENV CARGO_PROFILE_BENCH_DEBUG="${CARGO_PROFILE_BENCH_DEBUG}"
@@ -74,6 +76,7 @@ RUN \
--mount=type=cache,dst=${targ_targ_dir}/.fingerprint,id=${cargo_target_share}/fingerprint,sharing=locked \
<<EOF
set -eux
ulimit -n 65535
rustup run ${rust_toolchain} \
cargo ${cargo_cmd} \
--verbose \
+3 -31
View File
@@ -1,22 +1,6 @@
# syntax = docker/dockerfile:1.11-labs
FROM input AS key-gen-base
ARG var_cache
ARG var_lib_apt
WORKDIR /
COPY --link --from=input . .
RUN \
--mount=type=cache,dst=/var/cache,id=${var_cache},sharing=locked \
--mount=type=cache,dst=/var/lib/apt,id=${var_lib_apt},sharing=locked \
<<EOF
set -eux
apt-get -y -U install --no-install-recommends openssl gawk
EOF
FROM key-gen-base AS key-gen
FROM input AS key-gen
WORKDIR /complement
COPY <<EOF v3.ext
@@ -62,12 +46,11 @@ RUN [ -f certificate.crt ] && [ -f private_key.pem ]
FROM scratch AS complement-config
WORKDIR /complement
COPY --from=key-gen /complement/* .
COPY --from=source /usr/src/tuwunel/tests/test_results/complement/test_results.jsonl old_results.jsonl
COPY --from=source /usr/src/tuwunel/tests/complement/results.jsonl old_results.jsonl
COPY <<EOF complement.toml
[global]
address = "0.0.0.0"
admin_room_notices = false
allow_check_for_updates = false
allow_device_name_federation = true
allow_guest_registration = true
allow_invalid_tls_certificates = true
@@ -89,7 +72,6 @@ COPY <<EOF complement.toml
log_thread_ids = true
media_compat_file_link = false
media_startup_check = true
only_query_trusted_key_servers = false
port = [8008, 8448]
prune_missing_media = true
query_trusted_key_servers_first = false
@@ -156,18 +138,8 @@ ARG complement_tags="conduwuit_blacklist"
ARG complement_tests="./tests/..."
ARG complement_run=".*"
WORKDIR /
RUN \
--mount=type=cache,dst=/var/cache,id=${var_cache},sharing=locked \
--mount=type=cache,dst=/var/lib/apt,id=${var_lib_apt},sharing=locked \
--mount=type=cache,dst=/go/pkg/mod/cache,sharing=locked \
<<EOF
set -eux
apt-get -y -U install --no-install-recommends golang-go jq
EOF
WORKDIR /usr/src
ADD https://github.com/matrix-construct/complement.git#81f3b61e10ec102a36921890c81b79564ebf6f40 complement
ADD https://github.com/matrix-construct/complement.git#403840348f6bcc9cc8ed1671dc2f638c2b1ce4ac complement
WORKDIR /usr/src/complement
ENV COMPLEMENT_BASE_IMAGE="complement-testee"
+107
View File
@@ -0,0 +1,107 @@
# syntax = docker/dockerfile:1.11-labs
FROM input AS matrix-rust-sdk-integration
ARG sys_name
ARG sys_version
ARG rust_toolchain
ARG rust_target
ARG RUSTUP_HOME
ARG CARGO_HOME
ARG CARGO_TARGET
ARG MRSDK_TARGET_DIR="/usr/src/matrix-rust-sdk"
ARG mrsdk_profile="release"
ARG mrsdk_target_share="${MRSDK_TARGET_DIR}/${sys_name}/${sys_version}/${rust_target}/${rust_toolchain}/${mrsdk_profile}/_shared_cache"
ARG mrsdk_test_args=""
ARG mrsdk_test_opts=""
ARG mrsdk_skip_list=""
WORKDIR /
COPY --link --from=input . .
WORKDIR /usr/src
ADD --link https://github.com/matrix-construct/matrix-rust-sdk.git#integration matrix-rust-sdk
WORKDIR /etc
COPY <<EOF tuwunel.toml
[global]
admin_room_notices = false
allow_device_name_federation = true
allow_guest_registration = true
allow_legacy_media = true
allow_public_room_directory_over_federation = true
allow_public_room_directory_without_auth = true
allow_registration = true
create_admin_room = false
ip_range_denylist = []
log = "debug,tuwunel=trace,h2=warn,hyper=warn"
log_colors = false
log_guest_registrations = false
log_span_events = "NONE"
log_thread_ids = true
media_compat_file_link = false
media_startup_check = true
query_trusted_key_servers_first = false
query_trusted_key_servers_first_on_join = false
rocksdb_log_level = "debug"
rocksdb_max_log_files = 1
rocksdb_paranoid_file_checks = true
rocksdb_recovery_mode = 0
trusted_servers = []
url_preview_domain_contains_allowlist = ["*"]
url_preview_domain_explicit_denylist = ["*"]
yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true
EOF
WORKDIR /usr/lib
COPY --link --from=install /usr/lib .
WORKDIR /usr/bin
COPY --link --from=install /usr/bin/tuwunel .
WORKDIR /usr/src/matrix-rust-sdk
ENV targ_dir="${MRSDK_TARGET_DIR}/${mrsdk_profile}"
ENV targ_targ_dir="${MRSDK_TARGET_DIR}/${rust_target}/${mrsdk_profile}"
ENV RUST_BACKTRACE="full"
ENV TUWUNEL_CONFIG="/etc/tuwunel.toml"
ENV TUWUNEL_DATABASE_PATH="/var/db/tuwunel"
ENV TUWUNEL_SERVER_NAME="localhost:6167"
ENV TUWUNEL_PORT="[6167]"
ENV HOMESERVER_URL="http://localhost:6167"
RUN \
--mount=type=cache,dst=${RUSTUP_HOME}/downloads,sharing=shared \
--mount=type=cache,dst=${CARGO_HOME}/registry,sharing=shared \
--mount=type=cache,dst=${CARGO_HOME}/git,sharing=shared \
--mount=type=cache,dst=${targ_dir}/deps,id=${mrsdk_target_share}/deps,sharing=locked \
--mount=type=cache,dst=${targ_dir}/build,id=${mrsdk_target_share}/build,sharing=locked \
--mount=type=cache,dst=${targ_dir}/examples,id=${mrsdk_target_share}/examples,sharing=locked \
--mount=type=cache,dst=${targ_dir}/incremental,id=${mrsdk_target_share}/incremental,sharing=locked \
--mount=type=cache,dst=${targ_dir}/.fingerprint,id=${mrsdk_target_share}/fingerprint,sharing=locked \
--mount=type=cache,dst=${targ_targ_dir}/deps,id=${mrsdk_target_share}/deps,sharing=locked \
--mount=type=cache,dst=${targ_targ_dir}/build,id=${mrsdk_target_share}/build,sharing=locked \
--mount=type=cache,dst=${targ_targ_dir}/examples,id=${mrsdk_target_share}/examples,sharing=locked \
--mount=type=cache,dst=${targ_targ_dir}/incremental,id=${mrsdk_target_share}/incremental,sharing=locked \
--mount=type=cache,dst=${targ_targ_dir}/.fingerprint,id=${mrsdk_target_share}/fingerprint,sharing=locked \
<<EOF
set -eux
nohup /usr/bin/tuwunel 1> /var/log/tuwunel.log &
PID=$!; trap "sleep 10s; set +ex; kill -QUIT ${PID}; wait ${PID}" EXIT
sleep 3s
rustup run ${rust_toolchain} \
cargo test \
--locked \
--release \
--color always \
--features default \
--target "${rust_target}" \
--target-dir "${MRSDK_TARGET_DIR}" \
--package matrix-sdk-integration-testing \
${mrsdk_test_args} \
-- \
--test-threads 1 \
--color always \
${mrsdk_skip_list} \
${mrsdk_test_opts} \
;
EOF
+89
View File
@@ -0,0 +1,89 @@
# syntax = docker/dockerfile:1.11-labs
FROM input AS nix-base
ARG sys_name
ARG sys_version
ARG sys_target
WORKDIR /
COPY --link --from=input . .
RUN \
--mount=type=cache,dst=/nix,sharing=shared \
--mount=type=cache,dst=/root/.cache/nix,sharing=shared \
--mount=type=cache,dst=/root/.local/state/nix,sharing=shared \
<<EOF
set -eux
curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install > nix-install
sh ./nix-install --daemon
rm nix-install
EOF
FROM nix-base AS build-nix
ARG sys_name
ARG sys_version
ARG sys_target
WORKDIR /usr/src/tuwunel
COPY --link --from=source /usr/src/tuwunel .
RUN \
--mount=type=cache,dst=/nix,sharing=shared \
--mount=type=cache,dst=/root/.cache/nix,sharing=shared \
--mount=type=cache,dst=/root/.local/state/nix,sharing=shared \
<<EOF
set -eux
nix-build \
--verbose \
--cores 0 \
--max-jobs $(nproc) \
--log-format raw \
.
cp -afRL --copy-contents result /opt/tuwunel
EOF
FROM build-nix AS smoke-nix
ARG sys_name
ARG sys_version
ARG sys_target
WORKDIR /
COPY --link --from=build-nix . .
WORKDIR /opt/tuwunel
ENV TUWUNEL_DATABASE_PATH="/tmp/tuwunel/smoketest.db"
ENV TUWUNEL_LOG="info"
RUN \
--mount=type=cache,dst=/nix,sharing=shared \
--mount=type=cache,dst=/root/.cache/nix,sharing=shared \
--mount=type=cache,dst=/root/.local/state/nix,sharing=shared \
<<EOF
set -eux
bin/tuwunel \
-Otest='["smoke", "fresh"]' \
-Oserver_name=\"localhost\" \
EOF
FROM build-nix AS nix-pkg
ARG sys_name
ARG sys_version
ARG sys_target
WORKDIR /
COPY --link --from=build-nix . .
WORKDIR /usr/src/tuwunel
RUN \
--mount=type=cache,dst=/nix,sharing=shared \
--mount=type=cache,dst=/root/.cache/nix,sharing=shared \
--mount=type=cache,dst=/root/.local/state/nix,sharing=shared \
<<EOF
set -eux
#TODO: extract derivation?
mkdir -p /opt/tuwunel
touch /opt/tuwunel/tuwunel.drv
EOF
+5
View File
@@ -1,5 +1,10 @@
# Docker Builder
> [!NOTE]
> This directory is for building docker images. For [deploying](https://github.com/matrix-construct/tuwunel/tree/main/docs/deploying)
> [docker](https://github.com/matrix-construct/tuwunel/blob/main/docs/deploying/docker.md) visit
> the appropriate documentation instead.
All Docker images for the project are built here. All images are
[Docker Bake](https://docs.docker.com/build/bake/) targets. All targets are leaves and
branches of a unified tree leading to a single root. It is a combinatorial matrix
+215 -32
View File
@@ -29,8 +29,12 @@ variable "git_ref_name" {
cargo_feat_sets = {
none = ""
# Default features
default = "brotli_compression,element_hacks,gzip_compression,io_uring,jemalloc,jemalloc_conf,media_thumbnail,release_max_log_level,systemd,url_preview,zstd_compression"
all = "blurhashing,brotli_compression,bzip2_compression,tuwunel_mods,console,default,direct_tls,element_hacks,gzip_compression,hardened_malloc,io_uring,jemalloc,jemalloc_conf,jemalloc_prof,jemalloc_stats,ldap,lz4_compression,media_thumbnail,perf_measurements,release_max_log_level,sentry_telemetry,systemd,tokio_console,url_preview,zstd_compression"
# All features sans release_max_log_level
logging = "blurhashing,brotli_compression,bzip2_compression,console,direct_tls,element_hacks,gzip_compression,io_uring,jemalloc,jemalloc_conf,jemalloc_prof,jemalloc_stats,ldap,lz4_compression,media_thumbnail,perf_measurements,sentry_telemetry,systemd,tokio_console,tuwunel_mods,url_preview,zstd_compression"
# All features
all = "blurhashing,brotli_compression,bzip2_compression,console,direct_tls,element_hacks,gzip_compression,io_uring,jemalloc,jemalloc_conf,jemalloc_prof,jemalloc_stats,ldap,lz4_compression,media_thumbnail,perf_measurements,release_max_log_level,sentry_telemetry,systemd,tokio_console,tuwunel_mods,url_preview,zstd_compression"
}
variable "cargo_features_always" {
default = "direct_tls"
@@ -180,7 +184,6 @@ dynamic_libs = [
nightly_rustflags = [
"--cfg tokio_unstable",
"--cfg tuwunel_bench",
"--allow=unstable-features",
"-Z crate-attr=feature(test)",
"-Z enforce-type-length-limit",
@@ -233,9 +236,18 @@ group "lints" {
group "tests" {
targets = [
"docs",
"unit",
"smoke",
"integration",
"matrix-compliance",
]
}
group "matrix-compliance" {
targets = [
"complement",
"matrix-rust-sdk-integration",
]
}
@@ -403,7 +415,7 @@ target "complement-base" {
elem("complement-config", [sys_name, sys_version, sys_target])
]
contexts = {
input = elem("target:base", [sys_name, sys_version, sys_target])
input = elem("target:builder", [sys_name, sys_version, sys_target])
}
args = complement_args
}
@@ -424,6 +436,82 @@ target "complement-config" {
}
}
#
# Integration tests
#
group "integrations" {
targets = [
"matrix-rust-sdk-integration",
"integration",
]
}
target "matrix-rust-sdk-integration" {
name = elem("matrix-rust-sdk-integration", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
tags = [
elem_tag("matrix-rust-sdk-integration", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target], "latest"),
]
output = ["type=docker,compression=zstd,mode=max,compression-level=${zstd_image_compress_level}"]
cache_to = ["type=local,compression=zstd,mode=max,compression-level=${cache_compress_level}"]
target = "matrix-rust-sdk-integration"
dockerfile = "${docker_dir}/Dockerfile.matrix-rust-sdk"
matrix = cargo_rust_feat_sys
inherits = [
elem("rust", [rust_toolchain, rust_target, sys_name, sys_version, sys_target])
]
contexts = {
input = elem("target:rust", [rust_toolchain, rust_target, sys_name, sys_version, sys_target])
install = elem("target:install", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
}
args = {
mrsdk_test_args=""
mrsdk_test_opts=""
}
}
target "integration-valgrind" {
name = elem("integration-valgrind", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
tags = [
elem_tag("integration-valgrind", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target], "latest"),
]
matrix = cargo_rust_feat_sys
inherits = [
elem("integration", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target]),
]
contexts = {
input = elem("target:integration", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
}
args = {
VALGRINDFLAGS = "--error-exitcode=1 --exit-on-first-error=yes --undef-value-errors=no --leak-check=no"
cargo_cmd = "valgrind test"
cargo_args = "--test=*"
}
}
target "integration" {
name = elem("integration", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
tags = [
elem_tag("integration", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target], "latest"),
]
target = "cargo"
matrix = cargo_rust_feat_sys
inherits = [
elem("build-tests", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target]),
]
contexts = {
input = elem("target:build-tests", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
}
args = {
TUWUNEL_DATABASE_PATH = "/tmp/integration.test.db"
cargo_cmd = (cargo_profile == "bench"? "bench": "test")
cargo_args = (cargo_profile == "bench"?
"--no-fail-fast --bench=*": "--no-fail-fast --test=*"
)
}
}
#
# Smoke tests
#
@@ -432,11 +520,26 @@ group "smoke" {
targets = [
"smoke-version",
"smoke-startup",
#"smoke-nix",
#"smoke-valgrind",
#"smoke-perf",
]
}
target "smoke-nix" {
name = elem("smoke-nix", [sys_name, sys_version, sys_target])
tags = [
elem_tag("smoke-nix", [sys_name, sys_version, sys_target], "latest"),
]
output = ["type=cacheonly,compression=zstd,mode=min,compression-level=${cache_compress_level}"]
dockerfile = "${docker_dir}/Dockerfile.nix"
target = "smoke-nix"
matrix = sys
inherits = [
elem("build-nix", [sys_name, sys_version, sys_target]),
]
}
target "smoke-valgrind" {
name = elem("smoke-valgrind", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
tags = [
@@ -509,6 +612,70 @@ target "tests-smoke" {
}
}
#
# Unit tests
#
target "unit-valgrind" {
name = elem("unit-valgrind", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
tags = [
elem_tag("unit-valgrind", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target], "latest"),
]
target = "cargo"
matrix = cargo_rust_feat_sys
inherits = [
elem("unit", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target]),
]
contexts = {
input = elem("target:unit", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
}
args = {
VALGRINDFLAGS = "--error-exitcode=1 --exit-on-first-error=yes --undef-value-errors=no --leak-check=no"
cargo_cmd = "valgrind test"
cargo_args = "--lib --bins"
}
}
target "unit" {
name = elem("unit", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
tags = [
elem_tag("unit", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target], "latest"),
]
target = "cargo"
matrix = cargo_rust_feat_sys
inherits = [
elem("build-tests", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target]),
]
contexts = {
input = elem("target:build-tests", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
}
args = {
cargo_cmd = (cargo_profile == "bench"? "bench": "test")
cargo_args = (cargo_profile == "bench"?
"--no-fail-fast --lib": "--no-fail-fast --lib --bins"
)
}
}
target "docs" {
name = elem("docs", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
tags = [
elem_tag("docs", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target], "latest"),
]
target = "cargo"
matrix = cargo_rust_feat_sys
inherits = [
elem("build-tests", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target]),
]
contexts = {
input = elem("target:build-tests", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
}
args = {
cargo_cmd = "test"
cargo_args = "--doc --no-fail-fast"
}
}
#
# Installation
#
@@ -673,6 +840,7 @@ target "install" {
group "pkg" {
targets = [
"nix",
"deb",
"rpm",
"deb-install",
@@ -784,28 +952,36 @@ target "build-deb" {
}
}
#
# Unit tests
#
target "unit" {
name = elem("unit", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
target "nix" {
name = elem("nix", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
tags = [
elem_tag("unit", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target], "latest"),
elem_tag("nix", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target], "latest"),
]
target = "cargo"
output = ["type=docker,compression=zstd,mode=min,compression-level=${zstd_image_compress_level}"]
target = "nix-pkg"
matrix = cargo_rust_feat_sys
inherits = [
elem("build-tests", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target]),
elem("build-nix", [sys_name, sys_version, sys_target]),
]
}
target "build-nix" {
name = elem("build-nix", [sys_name, sys_version, sys_target])
tags = [
elem_tag("build-nix", [sys_name, sys_version, sys_target], "latest"),
]
output = ["type=cacheonly,compression=zstd,mode=min,compression-level=${cache_compress_level}"]
cache_to = ["type=local,compression=zstd,mode=max,compression-level=${cache_compress_level}"]
dockerfile = "${docker_dir}/Dockerfile.nix"
target = "build-nix"
matrix = sys
inherits = [
elem("builder", [sys_name, sys_version, sys_target]),
elem("source", [sys_name, sys_version, sys_target]),
]
contexts = {
input = elem("target:build-tests", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
}
args = {
cargo_cmd = (cargo_profile == "bench"? "bench": "test")
cargo_args = (rust_toolchain == "nightly"?
"--no-fail-fast --all-targets": "--no-fail-fast --bins --tests"
)
input = elem("target:builder", [sys_name, sys_version, sys_target]),
source = elem("target:source", [sys_name, sys_version, sys_target]),
}
}
@@ -835,10 +1011,10 @@ target "book" {
EOF
}
target "docs" {
name = elem("docs", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
target "build-docs" {
name = elem("build-docs", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
tags = [
elem_tag("docs", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target], "latest"),
elem_tag("build-docs", [cargo_profile, rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target], "latest"),
]
matrix = cargo_rust_feat_sys
inherits = [
@@ -898,7 +1074,7 @@ target "build-tests" {
}
args = {
cargo_cmd = (cargo_profile == "bench"? "bench": "test")
cargo_args = "--no-run"
cargo_args = (cargo_profile == "bench"? "--no-run --benches": "--no-run --tests")
}
}
@@ -1035,7 +1211,7 @@ target "fmt" {
input = elem("target:ingredients", [rust_toolchain, rust_target, feat_set, sys_name, sys_version, sys_target])
}
args = {
fmt_args = "-- --color always"
fmt_args = "-- --color=always"
}
}
@@ -1186,8 +1362,8 @@ target "deps-base" {
CARGO_PROFILE_TEST_DEBUG = "false"
CARGO_PROFILE_TEST_INCREMENTAL = "false"
CARGO_PROFILE_BENCH_DEBUG = "limited"
CARGO_PROFILE_BENCH_LTO = "false"
CARGO_PROFILE_BENCH_DEBUG = "false"
CARGO_PROFILE_BENCH_LTO = "thin"
CARGO_PROFILE_RELEASE_LTO = "thin"
CARGO_PROFILE_RELEASE_DEBUGINFO_DEBUG = "limited"
CARGO_PROFILE_RELEASE_DEBUGINFO_LTO = "off"
@@ -1214,7 +1390,7 @@ target "deps-base" {
"-C link-arg=-l:libgcc.a": "",
]):
cargo_profile == "release" && rust_toolchain == "nightly"?
(cargo_profile == "release" || cargo_profile == "bench") && rust_toolchain == "nightly"?
join(" ", [
join(" ", rustflags),
join(" ", nightly_rustflags),
@@ -1236,7 +1412,7 @@ target "deps-base" {
"-C link-arg=-l:libgcc.a": "",
]):
cargo_profile == "release" || cargo_profile == "release-debuginfo"?
cargo_profile == "release" || cargo_profile == "release-debuginfo" || cargo_profile == "bench"?
join(" ", [
join(" ", rustflags),
join(" ", static_rustflags),
@@ -1499,12 +1675,13 @@ rustup_components = [
]
cargo_installs = [
"cargo-chef",
"cargo-audit",
"cargo-deb",
#"cargo-arch",
"cargo-chef",
"cargo-deb",
"cargo-generate-rpm",
"lychee",
"cargo-valgrind",
#"lychee",
"mdbook",
"typos-cli",
]
@@ -1587,13 +1764,20 @@ kitchen_packages = [
"clang",
"cmake",
"curl",
"gawk",
"git",
"golang-go",
"gzip",
"jq",
"libc6-dev",
"libssl-dev",
"libsqlite3-dev",
"make",
"nix-bin",
"openssl",
"pkg-config",
"pkgconf",
"valgrind",
"xz-utils",
]
@@ -1613,7 +1797,6 @@ target "kitchen" {
args = {
packages = join(" ", [
contains(split(",", cargo_feat_sets[feat_set]), "bzip2_compression")? "libbz2-dev": "",
contains(split(",", cargo_feat_sets[feat_set]), "hardened_malloc")? "g++": "",
contains(split(",", cargo_feat_sets[feat_set]), "io_uring")? "liburing-dev": "",
contains(split(",", cargo_feat_sets[feat_set]), "jemalloc")? "libjemalloc-dev": "",
contains(split(",", cargo_feat_sets[feat_set]), "lz4_compression")? "liblz4-dev": "",
+1 -1
View File
@@ -61,7 +61,7 @@ toolchain_toml="$docker_dir/../rust-toolchain.toml"
rust_msrv=$(grep "channel = " "$toolchain_toml" | cut -d'=' -f2 | sed 's/\s"\|"$//g')
rocksdb_opt_level=3
rocksdb_portable=1
git_checkout="HEAD"
git_checkout="${git_checkout:-HEAD}"
use_chef="true"
set +a
+4 -1
View File
@@ -31,6 +31,9 @@ skip="${skip}|TestRoomCreate/Parallel/POST_/createRoom_makes_a_room_with_a_topic
skip="${skip}|TestLogin/parallel/POST_/"
skip="${skip}|TestUnbanViaInvite"
skip="${skip}|TestRoomState/Parallel/GET_/publicRooms_lists_newly-created_room"
# flakes due to timeout in debug-mode
skip="${skip}|TestMSC4297StateResolutionV2_1_starts_from_empty_set"
skip="${skip}|TestMSC4297StateResolutionV2_1_includes_conflicted_subgraph"
set -a
cargo_profile="${cargo_profile:-$default_cargo_profile}"
@@ -85,7 +88,7 @@ extract_output() {
}
result_src="$cid:/usr/src/complement/new_results.jsonl"
result_dst="tests/test_results/complement/test_results.jsonl"
result_dst="tests/complement/results.jsonl"
extract_results() {
docker cp "$result_src" "$result_dst"
}
+1
View File
@@ -0,0 +1 @@
../CODE_OF_CONDUCT.md
+1 -1
View File
@@ -20,4 +20,4 @@
- [Contributing](contributing.md)
- [Testing](development/testing.md)
- [Hot Reloading ("Live" Development)](development/hot_reload.md)
- [Tuwunel Community Code of Conduct](../CODE_OF_CONDUCT.md)
- [Tuwunel Community Code of Conduct](CODE_OF_CONDUCT.md)
+18 -19
View File
@@ -12,24 +12,23 @@
You may simply download the binary that fits your machine architecture (x86_64
or aarch64). Run `uname -m` to see what you need.
Prebuilt fully static musl binaries can be downloaded from the latest tagged
Prebuilt fully static binaries can be downloaded from the latest tagged
release [here](https://github.com/matrix-construct/tuwunel/releases/latest) or
`main` CI branch workflow artifact output. These also include Debian/Ubuntu
packages.
`main` CI branch workflow artifact output. These also include `.deb` packages
for Debian or Ubuntu and `.rpm` packages for Red Hat or Fedora.
These can be curl'd directly from. `ci-bins` are CI workflow binaries by commit
hash/revision, and `releases` are tagged releases. Sort by descending last
modified for the latest.
For the **best** performance; if using an `x86_64` CPU made in the last ~10 years,
we recommend using the `-v3-` optimised packages. See below for a command to check
what your system supports. If the server refuses to start or exits with an "Illegal
Instruction" error you will need `-v2-` or `-v1-` packages instead. The database
backend, RocksDB, benefits from `-v2-` or greater as it features performance
critical hardware accelerated CRC32 hashing/checksumming.
These binaries have jemalloc and io_uring statically linked and included with
them, so no additional dynamic dependencies need to be installed.
For the **best** performance; if using an `x86_64` CPU made in the last ~15 years,
we recommend using the `-haswell-` optimised binaries. This sets
`-march=haswell` which is the most compatible and highest performance with
optimised binaries. The database backend, RocksDB, most benefits from this as it
will then use hardware accelerated CRC32 hashing/checksumming which is critical
for performance.
Linux users can run this script to display which optimization levels they may
choose:
```
cat /proc/cpuinfo | grep -Po '(avx|sse)[235]' | sort -u | sed 's/avx5/v4/;s/avx2/v3/;s/sse3/v2/;s/sse2/v1/' | sort
```
### Compiling
@@ -153,7 +152,7 @@ and enter this (substitute for your server name).
```caddyfile
your.server.name, your.server.name:8448 {
# TCP reverse_proxy
reverse_proxy 127.0.0.1:6167
reverse_proxy localhost:8008
# UNIX socket
#reverse_proxy unix//run/tuwunel/tuwunel.sock
}
@@ -167,7 +166,7 @@ sudo systemctl enable --now caddy
### Other Reverse Proxies
As we would prefer our users to use Caddy, we will not provide configuration files for other proxys.
_Specific contributions for other proxies are welcome!_
You will need to reverse proxy everything under following routes:
- `/_matrix/` - core Matrix C-S and S-S APIs
@@ -187,8 +186,8 @@ See the following spec pages for more details on these files:
- [`/.well-known/matrix/support`](https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixsupport)
Examples of delegation:
- <https://puppygock.gay/.well-known/matrix/server>
- <https://puppygock.gay/.well-known/matrix/client>
- <https://matrix.org/.well-known/matrix/server>
- <https://matrix.org/.well-known/matrix/client>
For Apache and Nginx there are many examples available online.
+2 -1
View File
@@ -2,7 +2,8 @@
Tuwunel doesn't support horizontal scalability or distributed loading
natively, however a community maintained Helm Chart is available here to run
Tuwunel on Kubernetes: <https://gitlab.cronce.io/charts/conduwuit>
Tuwunel on Kubernetes: <https://github.com/AreYouLoco/tuwunel-helm> and the
legacy conduwuit version: <https://gitlab.cronce.io/charts/conduwuit>.
Should changes need to be made, please reach out to the maintainer in our
Matrix room as this is not maintained/controlled by the Tuwunel maintainers.
+100 -46
View File
@@ -1,17 +1,11 @@
# Troubleshooting Tuwunel
> ## Docker users ⚠️
>
> Docker is extremely UX unfriendly. Because of this, a ton of issues or support
> is actually Docker support, not tuwunel support. We also cannot document the
> ever-growing list of Docker issues here.
>
> [!IMPORTANT]
> If you intend on asking for support and you are using Docker, **PLEASE**
> triple validate your issues are **NOT** because you have a misconfiguration in
> your Docker setup.
>
> If there are things like Compose file issues or Dockerhub image issues, those
> can still be mentioned as long as they're something we can fix.
> your Docker setup. We must remain focused on supporting Tuwunel issues and
> cannot budget our time for generic Docker support. Compose file issues or
> Dockerhub image issues are okay if they are something we can fix.
## Tuwunel and Matrix issues
@@ -93,48 +87,107 @@ reliability at a slight performance cost due to TCP overhead.
#### Database corruption
If your database is corrupted *and* is failing to start (e.g. checksum
mismatch), it may be recoverable but careful steps must be taken, and there is
no guarantee it may be recoverable.
There are many causes and varieties of database corruption. There are several
methods for mitigation, each with outcomes ranging from a recovered state down
to a savage state. This guide has been simplified into a set of universal steps
which everyone can follow from the top until they have recovered or reach the
end. The details and implications will be explained within each step.
The first thing that can be done is launching Tuwunel with the
`rocksdb_repair` config option set to true. This will tell RocksDB to attempt to
repair itself at launch. If this does not work, disable the option and continue
reading.
> [!TIP]
> All command-line `-O` options can be expressed as environment variables or in
> the config file based on your deployment's requirements. Note that
> `--maintenance` is equivalent to configuring `startup_netburst = false` and
> `listening = false`.
RocksDB has the following recovery modes:
> [!IMPORTANT]
> Always create a backup of the database before running any operation. This is
> critical for steps 3 and above.
- `TolerateCorruptedTailRecords`
- `AbsoluteConsistency`
- `PointInTime`
- `SkipAnyCorruptedRecord`
**0. Start the server with the following options:**
By default, Tuwunel uses `TolerateCorruptedTailRecords` as generally these may
be due to bad federation and we can re-fetch the correct data over federation.
The RocksDB default is `PointInTime` which will attempt to restore a "snapshot"
of the data when it was last known to be good. This data can be either a few
seconds old, or multiple minutes prior. `PointInTime` may not be suitable for
default usage due to clients and servers possibly not being able to handle
sudden "backwards time travels", and `AbsoluteConsistency` may be too strict.
`tuwunel --maintenance -O rocksdb_recovery_mode=0`
`AbsoluteConsistency` will fail to start the database if any sign of corruption
is detected. `SkipAnyCorruptedRecord` will skip all forms of corruption unless
it forbids the database from opening (e.g. too severe). Usage of
`SkipAnyCorruptedRecord` voids any support as this may cause more damage and/or
leave your database in a permanently inconsistent state, but it may do something
if `PointInTime` does not work as a last ditch effort.
This is actually a "control" and not a method of recovery. If the server starts
you either do not have corruption or have deep corruption indicated by very
specific errors from rocksdb citing corruption during runtime. If you are
certain there is deep corruption skip to step 4, otherwise you are finished
without any modifications.
With this in mind:
**1. Start the server in Tolerate-Corrupted-Tail-Records mode:**
- First start Tuwunel with the `PointInTime` recovery method. See the [example
config](configuration/examples.md) for how to do this using
`rocksdb_recovery_mode`
- If your database successfully opens, clients are recommended to clear their
client cache to account for the rollback
- Leave your Tuwunel running in `PointInTime` for at least 30-60 minutes so as
much possible corruption is restored
- If all goes will, you should be able to restore back to using
`TolerateCorruptedTailRecords` and you have successfully recovered your database
`tuwunel --maintenance -O rocksdb_recovery_mode=1`
The most common corruption scenario is from a loss of power to the hardware
(not an application crash, though it is still possible). This is remediated
by dropping the most recently written record. It is highly unlikely there will
be any impact on the application from this loss. In the best-case the same data
is often re-requested over the federation or replaced by a client. In the
worst-case clients may need to clear-cache & reload to guarantee correctness.
If the server starts you are finished.
**2. Start the server in Point-In-Time mode:**
`tuwunel --maintenance -O rocksdb_recovery_mode=2`
Similar to the corruption scenario above but for more severe cases. The most
recent records are discarded back to the point where there is no corruption.
It is highly unlikely there will be any impact on the application from this
loss, but it is more likely than above that clients may need to clear-cache
& reload to correctly resynchronize with the server.
**3. Start the server in Skip-Any-Corrupted-Record mode:**
> [!WARNING]
> Salvage mode potentially impacting the application's ability to function.
> We cannot provide support for users who have entered this mode.
`tuwunel --maintenance -O rocksdb_recovery_mode=3`
Similar to the prior corruption scenarios but for the most severe cases.
The database will be inconsistent. It is theoretically possible for the
server to continue functioning without notable issue in the best case, but
it is completely uncertain what the effect of this operation will be. If
the server starts you should immediately export your messages, encryption
keys, etc, in a salvage effort and prepare to reinstall.
**4. Start the server in repair mode.**
> [!WARNING]
> Salvage mode potentially impacting the application's ability to function.
> We cannot provide support for users who have entered this mode.
> [!CAUTION]
> Always create a backup of the database before entering this mode. The repair
> is not configurable and not interactive. It may automatically remove more
> data than anticipated, preventing further salvage efforts.
`tuwunel --maintenance -O rocksdb_repair=true`
For corruption affecting the bulk database tables not covered by any journal.
This will leave the database in an inconsistent and unpredictable state. It
is theoretically possible to continue operating the server depending on which
records were dropped, such as some historical records which are no longer
essential. Nevertheless the impact of this operation is impossible to assess
and a successful recovery should be used to salvage data prior to reinstall.
Once finished, restart the server without `rocksdb_repair`. If no errors
persist, restart the server again without maintenance mode.
**5. Utilize an external repair tool.**
> [!WARNING]
> Salvage mode potentially impacting the application's ability to function.
> We cannot provide support for users who have entered this mode.
```
git clone https://github.com/facebook/rocksdb
cd rocksdb
make -j$(nproc) ldb
./ldb repair --db=/var/lib/tuwunel/ 2>./repair-log.txt
```
For situations when the repair mode in step 4 failed or produced unexpected
results.
## Debugging
@@ -147,7 +200,8 @@ Various debug commands can be found in `!admin debug`.
Tuwunel builds without debug or trace log levels at compile time by default
for substantial performance gains in CPU usage and improved compile times. If
you need to access debug/trace log levels, you will need to build without the
`release_max_log_level` feature or use our provided static debug binaries.
`release_max_log_level` feature or use our provided release-logging binaries
and images.
#### Changing log level dynamically
Generated
+88 -132
View File
@@ -10,11 +10,11 @@
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1748532342,
"narHash": "sha256-CvaKOUq8G10sghKpZhEB2UYjJoWhEkrDFggDgi7piUI=",
"lastModified": 1758711588,
"narHash": "sha256-0nZlCCDC5PfndsQJXXtcyrtrfW49I3KadGMDlutzaGU=",
"owner": "zhaofengli",
"repo": "attic",
"rev": "ce9373715fe3fac7a174a65a7e6d6baeba8cb4f9",
"rev": "12cbeca141f46e1ade76728bce8adc447f2166c6",
"type": "github"
},
"original": {
@@ -29,14 +29,14 @@
"devenv": "devenv",
"flake-compat": "flake-compat_2",
"git-hooks": "git-hooks",
"nixpkgs": "nixpkgs_4"
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1748883665,
"narHash": "sha256-R0W7uAg+BLoHjMRMQ8+oiSbTq8nkGz5RDpQ+ZfxxP3A=",
"lastModified": 1756385612,
"narHash": "sha256-+NU5MMhuPHHRyvZZWNFG7zt+leRSPsJu1MwhOUzkPUk=",
"owner": "cachix",
"repo": "cachix",
"rev": "f707778d902af4d62d8dd92c269f8e70de09acbe",
"rev": "dc24688cd67518c3711d511fa369c0f5a131063a",
"type": "github"
},
"original": {
@@ -58,16 +58,21 @@
],
"git-hooks": [
"cachix",
"devenv"
"devenv",
"git-hooks"
],
"nixpkgs": "nixpkgs_2"
"nixpkgs": [
"cachix",
"devenv",
"nixpkgs"
]
},
"locked": {
"lastModified": 1744206633,
"narHash": "sha256-pb5aYkE8FOoa4n123slgHiOf1UbNSnKe5pEZC+xXD5g=",
"lastModified": 1748883665,
"narHash": "sha256-R0W7uAg+BLoHjMRMQ8+oiSbTq8nkGz5RDpQ+ZfxxP3A=",
"owner": "cachix",
"repo": "cachix",
"rev": "8a60090640b96f9df95d1ab99e5763a586be1404",
"rev": "f707778d902af4d62d8dd92c269f8e70de09acbe",
"type": "github"
},
"original": {
@@ -80,11 +85,11 @@
"complement": {
"flake": false,
"locked": {
"lastModified": 1741891349,
"narHash": "sha256-YvrzOWcX7DH1drp5SGa+E/fc7wN3hqFtPbqPjZpOu1Q=",
"lastModified": 1756358878,
"narHash": "sha256-H/4TkbFcGsMRDZ7gNaXZ7NxeO3b1YgkVt9zPb+3ATSg=",
"owner": "matrix-construct",
"repo": "complement",
"rev": "e587b3df569cba411aeac7c20b6366d03c143745",
"rev": "403840348f6bcc9cc8ed1671dc2f638c2b1ce4ac",
"type": "github"
},
"original": {
@@ -95,18 +100,12 @@
}
},
"crane": {
"inputs": {
"nixpkgs": [
"attic",
"nixpkgs"
]
},
"locked": {
"lastModified": 1722960479,
"narHash": "sha256-NhCkJJQhD5GUib8zN9JrmYGMwt4lCRp6ZVNzIiYCl0Y=",
"lastModified": 1751562746,
"narHash": "sha256-smpugNIkmDeicNz301Ll1bD7nFOty97T79m4GUMUczA=",
"owner": "ipetkov",
"repo": "crane",
"rev": "4c6c77920b8d44cd6660c1621dea6b3fc4b4c4f4",
"rev": "aed2020fd3dc26e1e857d4107a5a67a33ab6c1fd",
"type": "github"
},
"original": {
@@ -117,11 +116,11 @@
},
"crane_2": {
"locked": {
"lastModified": 1748970125,
"narHash": "sha256-UDyigbDGv8fvs9aS95yzFfOKkEjx1LO3PL3DsKopohA=",
"lastModified": 1758758545,
"narHash": "sha256-NU5WaEdfwF6i8faJ2Yh+jcK9vVFrofLcwlD/mP65JrI=",
"owner": "ipetkov",
"repo": "crane",
"rev": "323b5746d89e04b22554b061522dfce9e4c49b18",
"rev": "95d528a5f54eaba0d12102249ce42f4d01f4e364",
"type": "github"
},
"original": {
@@ -149,11 +148,11 @@
]
},
"locked": {
"lastModified": 1748273445,
"narHash": "sha256-5V0dzpNgQM0CHDsMzh+ludYeu1S+Y+IMjbaskSSdFh0=",
"lastModified": 1754404745,
"narHash": "sha256-BdbW/iTImczgcuATgQIa9sPGuYIBxVq2xqcvICsa2AQ=",
"owner": "cachix",
"repo": "devenv",
"rev": "668a50d8b7bdb19a0131f53c9f6c25c9071e1ffb",
"rev": "6563b21105168f90394dfaf58284b078af2d7275",
"type": "github"
},
"original": {
@@ -170,11 +169,11 @@
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1749883145,
"narHash": "sha256-RlcGw3vAnbI3cfZn8aFaovNUd7312VZh+/FDWkqdA7E=",
"lastModified": 1759251341,
"narHash": "sha256-0vt4IQnTLyAhaeom3h9GOCpO2+av+wK4zP7O8BSKr6I=",
"owner": "nix-community",
"repo": "fenix",
"rev": "a804172f150bcf81262655324e583bb0cd0f28dd",
"rev": "af8a7505a1c62fab493157ea380a05c094bb63af",
"type": "github"
},
"original": {
@@ -187,11 +186,11 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"lastModified": 1747046372,
"narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
"type": "github"
},
"original": {
@@ -241,11 +240,11 @@
]
},
"locked": {
"lastModified": 1722555600,
"narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=",
"lastModified": 1751413152,
"narHash": "sha256-Tyw1RjYEsp5scoigs1384gIg6e0GoBVjms4aXFfRssQ=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "8471fe90ad337a8074e957b69ca4d0089218391d",
"rev": "77826244401ea9de6e3bac47c2db46005e1f30b5",
"type": "github"
},
"original": {
@@ -264,11 +263,11 @@
]
},
"locked": {
"lastModified": 1712014858,
"narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=",
"lastModified": 1733312601,
"narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "9126214d0a59633752a136528f5f3b9aa8565b7d",
"rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9",
"type": "github"
},
"original": {
@@ -309,11 +308,11 @@
]
},
"locked": {
"lastModified": 1747372754,
"narHash": "sha256-2Y53NGIX2vxfie1rOW0Qb86vjRZ7ngizoo+bnXU9D9k=",
"lastModified": 1750779888,
"narHash": "sha256-wibppH3g/E2lxU43ZQHC5yA/7kIKLGxVEnsnVK1BtRg=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "80479b6ec16fefd9c1db3ea13aeb038c60530f46",
"rev": "16ec914f6fb6f599ce988427d9d94efddf25fe6d",
"type": "github"
},
"original": {
@@ -344,30 +343,14 @@
"type": "github"
}
},
"libgit2": {
"flake": false,
"locked": {
"lastModified": 1697646580,
"narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=",
"owner": "libgit2",
"repo": "libgit2",
"rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5",
"type": "github"
},
"original": {
"owner": "libgit2",
"repo": "libgit2",
"type": "github"
}
},
"liburing": {
"flake": false,
"locked": {
"lastModified": 1749816983,
"narHash": "sha256-p5hXfDe53Y4MVwL2+wKZYpy4OPGvqFFnOEvkMsFAO6c=",
"lastModified": 1759268303,
"narHash": "sha256-nT3JWey0P2lPWlnwN57XHmuzkeW8Mo795+Ahf8S5TMI=",
"owner": "axboe",
"repo": "liburing",
"rev": "ad83d3ab64894c16eaf21ef869656a5bddb93ca4",
"rev": "1671cb952a8f680214b04ae9546d4f649f1b367b",
"type": "github"
},
"original": {
@@ -381,11 +364,20 @@
"inputs": {
"flake-compat": [
"cachix",
"devenv"
"devenv",
"flake-compat"
],
"flake-parts": "flake-parts_2",
"libgit2": "libgit2",
"nixpkgs": "nixpkgs_3",
"git-hooks-nix": [
"cachix",
"devenv",
"git-hooks"
],
"nixpkgs": [
"cachix",
"devenv",
"nixpkgs"
],
"nixpkgs-23-11": [
"cachix",
"devenv"
@@ -393,34 +385,30 @@
"nixpkgs-regression": [
"cachix",
"devenv"
],
"pre-commit-hooks": [
"cachix",
"devenv"
]
},
"locked": {
"lastModified": 1745930071,
"narHash": "sha256-bYyjarS3qSNqxfgc89IoVz8cAFDkF9yPE63EJr+h50s=",
"owner": "domenkozar",
"lastModified": 1752773918,
"narHash": "sha256-dOi/M6yNeuJlj88exI+7k154z+hAhFcuB8tZktiW7rg=",
"owner": "cachix",
"repo": "nix",
"rev": "b455edf3505f1bf0172b39a735caef94687d0d9c",
"rev": "031c3cf42d2e9391eee373507d8c12e0f9606779",
"type": "github"
},
"original": {
"owner": "domenkozar",
"ref": "devenv-2.24",
"owner": "cachix",
"ref": "devenv-2.30",
"repo": "nix",
"type": "github"
}
},
"nix-filter": {
"locked": {
"lastModified": 1731533336,
"narHash": "sha256-oRam5PS1vcrr5UPgALW0eo1m/5/pls27Z/pabHNy2Ms=",
"lastModified": 1757882181,
"narHash": "sha256-+cCxYIh2UNalTz364p+QYmWHs0P+6wDhiWR4jDIKQIU=",
"owner": "numtide",
"repo": "nix-filter",
"rev": "f7653272fd234696ae94229839a99b73c9ab7de0",
"rev": "59c44d1909c72441144b93cf0f054be7fe764de5",
"type": "github"
},
"original": {
@@ -438,11 +426,11 @@
]
},
"locked": {
"lastModified": 1729742964,
"narHash": "sha256-B4mzTcQ0FZHdpeWcpDYPERtyjJd/NIuaQ9+BV1h+MpA=",
"lastModified": 1737420293,
"narHash": "sha256-F1G5ifvqTpJq7fdkT34e/Jy9VCyzd5XfJ9TO8fHhJWE=",
"owner": "nix-community",
"repo": "nix-github-actions",
"rev": "e04df33f62cdcf93d73e9a04142464753a16db67",
"rev": "f4158fa080ef4503c8f4c820967d946c2af31ec9",
"type": "github"
},
"original": {
@@ -453,11 +441,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1726042813,
"narHash": "sha256-LnNKCCxnwgF+575y0pxUdlGZBO/ru1CtGHIqQVfvjlA=",
"lastModified": 1751949589,
"narHash": "sha256-mgFxAPLWw0Kq+C8P3dRrZrOYEQXOtKuYVlo9xvPntt8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "159be5db480d1df880a0135ca0bfed84c2f88353",
"rev": "9b008d60392981ad674e04016d25619281550a9d",
"type": "github"
},
"original": {
@@ -469,27 +457,27 @@
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1724316499,
"narHash": "sha256-Qb9MhKBUTCfWg/wqqaxt89Xfi6qTD3XpTzQ9eXi3JmE=",
"lastModified": 1751741127,
"narHash": "sha256-t75Shs76NgxjZSgvvZZ9qOmz5zuBE8buUaYD28BMTxg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "797f7dc49e0bc7fab4b57c021cdf68f595e47841",
"rev": "29e290002bfff26af1db6f64d070698019460302",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"ref": "nixos-25.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1733212471,
"narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=",
"lastModified": 1754214453,
"narHash": "sha256-Q/I2xJn/j1wpkGhWkQnm20nShYnG7TI99foDBpXm1SY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "55d15ad12a74eb7d4646254e13638ad0c4128776",
"rev": "5b09dc45f24cf32316283e62aec81ffee3c3e376",
"type": "github"
},
"original": {
@@ -501,43 +489,11 @@
},
"nixpkgs_3": {
"locked": {
"lastModified": 1717432640,
"narHash": "sha256-+f9c4/ZX5MWDOuB1rKoWj+lBNm0z0rs4CK47HBLxy1o=",
"lastModified": 1759070547,
"narHash": "sha256-JVZl8NaVRYb0+381nl7LvPE+A774/dRpif01FKLrYFQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "88269ab3044128b7c2f4c7d68448b2fb50456870",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "release-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_4": {
"locked": {
"lastModified": 1748190013,
"narHash": "sha256-R5HJFflOfsP5FBtk+zE8FpL8uqE7n62jqOsADvVshhE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "62b852f6c6742134ade1abdd2a21685fd617a291",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_5": {
"locked": {
"lastModified": 1749871736,
"narHash": "sha256-K9yBph93OLTNw02Q6e9CYFGrUhvEXnh45vrZqIRWfvQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6afe187897bef7933475e6af374c893f4c84a293",
"rev": "647e5c14cbd5067f44ac86b74f014962df460840",
"type": "github"
},
"original": {
@@ -575,18 +531,18 @@
"flake-utils": "flake-utils",
"liburing": "liburing",
"nix-filter": "nix-filter",
"nixpkgs": "nixpkgs_5",
"nixpkgs": "nixpkgs_3",
"rocksdb": "rocksdb"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1749829309,
"narHash": "sha256-t6x6/PKg8Shnkd3htrxf3WMgycfRLRWvN9JHAmGWf+s=",
"lastModified": 1759134797,
"narHash": "sha256-YPi+jL3tx/yC5J5l7/OB7Lnlr9BMTzYnZtm7tRJzUNg=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "a497f4114ccf24978accb56190e60d1e1659e0c7",
"rev": "062ac7a5451e8e92a32e22a60d86882d6a034f3f",
"type": "github"
},
"original": {
-54
View File
@@ -204,8 +204,6 @@
# be expected on non-debug builds.
"jemalloc_prof"
"jemalloc_stats"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
@@ -218,8 +216,6 @@
# dont include experimental features
"experimental"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
};
@@ -231,8 +227,6 @@
# dont include experimental features
"experimental"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
};
@@ -246,8 +240,6 @@
"jemalloc_prof"
"jemalloc_stats"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
};
@@ -260,12 +252,9 @@
# dont include experimental features
"experimental"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
};
hmalloc = scopeHost.main.override { features = ["hardened_malloc"]; };
oci-image = scopeHost.oci-image;
oci-image-all-features = scopeHost.oci-image.override {
@@ -278,8 +267,6 @@
# be expected on non-debug builds.
"jemalloc_prof"
"jemalloc_stats"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
@@ -294,18 +281,11 @@
disable_features = [
# dont include experimental features
"experimental"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
};
};
oci-image-hmalloc = scopeHost.oci-image.override {
main = scopeHost.main.override {
features = ["hardened_malloc"];
};
};
book = scopeHost.book;
@@ -359,8 +339,6 @@
disable_features = [
# dont include experimental features
"experimental"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
@@ -379,8 +357,6 @@
# be expected on non-debug builds.
"jemalloc_prof"
"jemalloc_stats"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
@@ -400,8 +376,6 @@
# be expected on non-debug builds.
"jemalloc_prof"
"jemalloc_stats"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
@@ -420,22 +394,12 @@
disable_features = [
# dont include experimental features
"experimental"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
};
}
# An output for a statically-linked binary with hardened_malloc
{
name = "${binaryName}-hmalloc";
value = scopeCrossStatic.main.override {
features = ["hardened_malloc"];
};
}
# An output for an OCI image based on that binary
{
name = "oci-image-${crossSystem}";
@@ -478,8 +442,6 @@
# be expected on non-debug builds.
"jemalloc_prof"
"jemalloc_stats"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
@@ -501,8 +463,6 @@
# be expected on non-debug builds.
"jemalloc_prof"
"jemalloc_stats"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
@@ -523,8 +483,6 @@
disable_features = [
# dont include experimental features
"experimental"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
@@ -532,16 +490,6 @@
};
}
# An output for an OCI image based on that binary with hardened_malloc
{
name = "oci-image-${crossSystem}-hmalloc";
value = scopeCrossStatic.oci-image.override {
main = scopeCrossStatic.main.override {
features = ["hardened_malloc"];
};
};
}
# An output for a complement OCI image for the specified platform
{
name = "complement-${crossSystem}";
@@ -571,8 +519,6 @@
# be expected on non-debug builds.
"jemalloc_prof"
"jemalloc_stats"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
];
+4 -3
View File
@@ -23,8 +23,6 @@
# be expected on non-debug builds.
"jemalloc_prof"
"jemalloc_stats"
# this is non-functional on nix for some reason
"hardened_malloc"
# tuwunel_mods is a development-only hot reload feature
"tuwunel_mods"
]
@@ -131,6 +129,7 @@ buildDepsOnlyEnv =
buildPackageEnv = {
TUWUNEL_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev or "";
TUWUNEL_DATABASE_PATH = "/var/tmp/tuwunel.db";
} // buildDepsOnlyEnv // {
# Only needed in static stdenv because these are transitive dependencies of rocksdb
CARGO_BUILD_RUSTFLAGS = buildDepsOnlyEnv.CARGO_BUILD_RUSTFLAGS
@@ -203,7 +202,9 @@ craneLib.buildPackage ( commonAttrs // {
env = buildDepsOnlyEnv;
});
doCheck = true;
# Disabled due to integration test failing to find /etc/resolv.conf
doCheck = false;
doBenchmark = false;
cargoExtraArgs = "--no-default-features --locked "
+ lib.optionalString
+1 -1
View File
@@ -2,7 +2,6 @@
Description=Tuwunel Matrix homeserver
Wants=network-online.target
After=network-online.target
Alias=matrix-tuwunel.service
Documentation=https://tuwunel.chat/
[Service]
@@ -63,3 +62,4 @@ StartLimitBurst=5
[Install]
WantedBy=multi-user.target
Alias=matrix-tuwunel.service
+1 -12
View File
@@ -11,6 +11,7 @@ version.workspace = true
[lib]
path = "mod.rs"
bench = false
crate-type = [
"rlib",
# "dylib",
@@ -18,56 +19,46 @@ crate-type = [
[features]
brotli_compression = [
"tuwunel-api/brotli_compression",
"tuwunel-core/brotli_compression",
"tuwunel-service/brotli_compression",
]
bzip2_compression = [
"tuwunel-api/bzip2_compression",
"tuwunel-database/bzip2_compression",
"tuwunel-service/bzip2_compression",
]
gzip_compression = [
"tuwunel-api/gzip_compression",
"tuwunel-core/gzip_compression",
"tuwunel-service/gzip_compression",
]
io_uring = [
"tuwunel-api/io_uring",
"tuwunel-database/io_uring",
"tuwunel-service/io_uring",
]
jemalloc = [
"tuwunel-api/jemalloc",
"tuwunel-core/jemalloc",
"tuwunel-database/jemalloc",
"tuwunel-service/jemalloc",
]
jemalloc_conf = [
"tuwunel-api/jemalloc_conf",
"tuwunel-core/jemalloc_conf",
"tuwunel-database/jemalloc_conf",
"tuwunel-service/jemalloc_conf",
]
jemalloc_prof = [
"tuwunel-api/jemalloc_prof",
"tuwunel-core/jemalloc_prof",
"tuwunel-database/jemalloc_prof",
"tuwunel-service/jemalloc_prof",
]
jemalloc_stats = [
"tuwunel-api/jemalloc_stats",
"tuwunel-core/jemalloc_stats",
"tuwunel-database/jemalloc_stats",
"tuwunel-service/jemalloc_stats",
]
lz4_compression = [
"tuwunel-api/lz4_compression",
"tuwunel-database/lz4_compression",
"tuwunel-service/lz4_compression",
]
release_max_log_level = [
"tuwunel-api/release_max_log_level",
"tuwunel-core/release_max_log_level",
"tuwunel-database/release_max_log_level",
"tuwunel-service/release_max_log_level",
@@ -77,7 +68,6 @@ release_max_log_level = [
"log/release_max_level_info",
]
zstd_compression = [
"tuwunel-api/zstd_compression",
"tuwunel-core/zstd_compression",
"tuwunel-database/zstd_compression",
"tuwunel-service/zstd_compression",
@@ -86,7 +76,6 @@ zstd_compression = [
[dependencies]
base64.workspace = true
clap.workspace = true
tuwunel-api.workspace = true
tuwunel-core.workspace = true
tuwunel-database.workspace = true
tuwunel-macros.workspace = true
+37 -69
View File
@@ -28,10 +28,7 @@ use tuwunel_core::{
},
warn,
};
use tuwunel_service::rooms::{
short::{ShortEventId, ShortRoomId},
state_compressor::HashSetCompressStateEvent,
};
use tuwunel_service::rooms::{short::ShortRoomId, state_compressor::HashSetCompressStateEvent};
use crate::admin_command;
@@ -45,7 +42,6 @@ pub(super) async fn echo(&self, message: Vec<String>) -> Result {
pub(super) async fn get_auth_chain(&self, event_id: OwnedEventId) -> Result {
let Ok(event) = self
.services
.rooms
.timeline
.get_pdu_json(&event_id)
.await
@@ -64,7 +60,6 @@ pub(super) async fn get_auth_chain(&self, event_id: OwnedEventId) -> Result {
let start = Instant::now();
let count = self
.services
.rooms
.auth_chain
.event_ids_iter(room_id, once(event_id.as_ref()))
.ready_filter_map(Result::ok)
@@ -87,9 +82,12 @@ pub(super) async fn parse_pdu(&self) -> Result {
}
let string = self.body[1..self.body.len().saturating_sub(1)].join("\n");
let rules = RoomVersionId::V6
.rules()
.expect("rules for V6 rooms");
match serde_json::from_str(&string) {
| Err(e) => return Err!("Invalid json in command body: {e}"),
| Ok(value) => match ruma::signatures::reference_hash(&value, &RoomVersionId::V6) {
| Ok(value) => match ruma::signatures::reference_hash(&value, &rules) {
| Err(e) => return Err!("Could not parse PDU JSON: {e:?}"),
| Ok(hash) => {
let event_id = OwnedEventId::parse(format!("${hash}"));
@@ -108,7 +106,6 @@ pub(super) async fn get_pdu(&self, event_id: OwnedEventId) -> Result {
let mut outlier = false;
let mut pdu_json = self
.services
.rooms
.timeline
.get_non_outlier_pdu_json(&event_id)
.await;
@@ -117,7 +114,6 @@ pub(super) async fn get_pdu(&self, event_id: OwnedEventId) -> Result {
outlier = true;
pdu_json = self
.services
.rooms
.timeline
.get_pdu_json(&event_id)
.await;
@@ -139,20 +135,11 @@ pub(super) async fn get_pdu(&self, event_id: OwnedEventId) -> Result {
}
#[admin_command]
pub(super) async fn get_short_pdu(
&self,
shortroomid: ShortRoomId,
shorteventid: ShortEventId,
) -> Result {
let pdu_id: RawPduId = PduId {
shortroomid,
shorteventid: shorteventid.into(),
}
.into();
pub(super) async fn get_short_pdu(&self, shortroomid: ShortRoomId, count: i64) -> Result {
let pdu_id: RawPduId = PduId { shortroomid, count: count.into() }.into();
let pdu_json = self
.services
.rooms
.timeline
.get_pdu_json_from_id(&pdu_id)
.await;
@@ -252,7 +239,6 @@ pub(super) async fn get_remote_pdu(
.sending
.send_federation_request(&server, ruma::api::federation::event::get_event::v1::Request {
event_id: event_id.clone(),
include_unredacted_content: None,
})
.await
{
@@ -273,32 +259,28 @@ pub(super) async fn get_remote_pdu(
})?;
trace!("Attempting to parse PDU: {:?}", &response.pdu);
let _parsed_pdu = {
let (room_id, ..) = {
let parsed_result = self
.services
.rooms
.event_handler
.parse_incoming_pdu(&response.pdu)
.boxed()
.await;
let (event_id, value, room_id) = match parsed_result {
match parsed_result {
| Ok(t) => t,
| Err(e) => {
warn!("Failed to parse PDU: {e}");
info!("Full PDU: {:?}", &response.pdu);
return Err!("Failed to parse PDU remote server {server} sent us: {e}");
},
};
vec![(event_id, value, room_id)]
}
};
info!("Attempting to handle event ID {event_id} as backfilled PDU");
self.services
.rooms
.timeline
.backfill_pdu(&server, response.pdu)
.backfill_pdu(&room_id, &server, response.pdu)
.await?;
let text = serde_json::to_string_pretty(&json)?;
@@ -311,10 +293,9 @@ pub(super) async fn get_remote_pdu(
#[admin_command]
pub(super) async fn get_room_state(&self, room: OwnedRoomOrAliasId) -> Result {
let room_id = self.services.rooms.alias.resolve(&room).await?;
let room_id = self.services.alias.maybe_resolve(&room).await?;
let room_state: Vec<Raw<AnyStateEvent>> = self
.services
.rooms
.state_accessor
.room_state_full_pdus(&room_id)
.map_ok(Event::into_format)
@@ -492,7 +473,6 @@ pub(super) async fn verify_pdu(&self, event_id: OwnedEventId) -> Result {
let mut event = self
.services
.rooms
.timeline
.get_pdu_json(&event_id)
.await?;
@@ -517,7 +497,6 @@ pub(super) async fn verify_pdu(&self, event_id: OwnedEventId) -> Result {
pub(super) async fn first_pdu_in_room(&self, room_id: OwnedRoomId) -> Result {
if !self
.services
.rooms
.state_cache
.server_in_room(&self.services.server.name, &room_id)
.await
@@ -527,7 +506,6 @@ pub(super) async fn first_pdu_in_room(&self, room_id: OwnedRoomId) -> Result {
let first_pdu = self
.services
.rooms
.timeline
.first_pdu_in_room(&room_id)
.await
@@ -542,7 +520,6 @@ pub(super) async fn first_pdu_in_room(&self, room_id: OwnedRoomId) -> Result {
pub(super) async fn latest_pdu_in_room(&self, room_id: OwnedRoomId) -> Result {
if !self
.services
.rooms
.state_cache
.server_in_room(&self.services.server.name, &room_id)
.await
@@ -552,7 +529,6 @@ pub(super) async fn latest_pdu_in_room(&self, room_id: OwnedRoomId) -> Result {
let latest_pdu = self
.services
.rooms
.timeline
.latest_pdu_in_room(&room_id)
.await
@@ -571,7 +547,6 @@ pub(super) async fn force_set_room_state_from_server(
) -> Result {
if !self
.services
.rooms
.state_cache
.server_in_room(&self.services.server.name, &room_id)
.await
@@ -581,7 +556,6 @@ pub(super) async fn force_set_room_state_from_server(
let first_pdu = self
.services
.rooms
.timeline
.latest_pdu_in_room(&room_id)
.await
@@ -589,7 +563,6 @@ pub(super) async fn force_set_room_state_from_server(
let room_version = self
.services
.rooms
.state
.get_room_version(&room_id)
.await?;
@@ -608,7 +581,6 @@ pub(super) async fn force_set_room_state_from_server(
for pdu in remote_state_response.pdus.clone() {
match self
.services
.rooms
.event_handler
.parse_incoming_pdu(&pdu)
.await
@@ -627,24 +599,33 @@ pub(super) async fn force_set_room_state_from_server(
.server_keys
.validate_and_add_event_id(pdu, &room_version)
}) {
let Ok((event_id, value)) = result.await else {
let Ok((event_id, mut value)) = result.await else {
continue;
};
let pdu = PduEvent::from_id_val(&event_id, value.clone()).map_err(|e| {
let invalid_pdu_err = |e| {
debug_error!("Invalid PDU in fetching remote room state PDUs response: {value:#?}");
err!(BadServerResponse(debug_error!("Invalid PDU in send_join response: {e:?}")))
})?;
};
let pdu = if value["type"] == "m.room.create" {
PduEvent::from_rid_val(&room_id, &event_id, value.clone()).map_err(invalid_pdu_err)?
} else {
PduEvent::from_id_val(&event_id, value.clone()).map_err(invalid_pdu_err)?
};
if !value.contains_key("room_id") {
let room_id = CanonicalJsonValue::String(room_id.as_str().into());
value.insert("room_id".into(), room_id);
}
self.services
.rooms
.timeline
.add_pdu_outlier(&event_id, &value);
if let Some(state_key) = &pdu.state_key {
let shortstatekey = self
.services
.rooms
.short
.get_or_create_shortstatekey(&pdu.kind.to_string().into(), state_key)
.await;
@@ -667,14 +648,12 @@ pub(super) async fn force_set_room_state_from_server(
};
self.services
.rooms
.timeline
.add_pdu_outlier(&event_id, &value);
}
let new_room_state = self
.services
.rooms
.event_handler
.resolve_state(&room_id, &room_version, state)
.await?;
@@ -686,21 +665,13 @@ pub(super) async fn force_set_room_state_from_server(
removed,
} = self
.services
.rooms
.state_compressor
.save_state(room_id.clone().as_ref(), new_room_state)
.await?;
let state_lock = self
.services
.rooms
.state
.mutex
.lock(&*room_id)
.await;
let state_lock = self.services.state.mutex.lock(&*room_id).await;
self.services
.rooms
.state
.force_state(room_id.clone().as_ref(), short_state_hash, added, removed, &state_lock)
.await?;
@@ -710,7 +681,6 @@ pub(super) async fn force_set_room_state_from_server(
the room's m.room.member state"
);
self.services
.rooms
.state_cache
.update_joined_count(&room_id)
.await;
@@ -937,7 +907,7 @@ pub(super) async fn database_files(&self, map: Option<String>, level: Option<i32
let mut files: Vec<_> = self
.services
.db
.db
.engine
.file_list()
.collect::<Result<_>>()?;
@@ -993,10 +963,10 @@ pub(super) async fn create_jwt(
#[derive(Serialize)]
struct Claim {
sub: String,
iss: String,
aud: String,
exp: usize,
nbf: usize,
iss: Option<String>,
aud: Option<String>,
exp: Option<usize>,
nbf: Option<usize>,
}
let config = &self.services.config.jwt;
@@ -1013,21 +983,19 @@ pub(super) async fn create_jwt(
let claim = Claim {
sub: user,
iss: issuer.unwrap_or_default(),
iss: issuer,
aud: audience.unwrap_or_default(),
aud: audience,
exp: exp_from_now
.and_then(|val| now_secs().checked_add(val))
.map(TryInto::try_into)
.and_then(Result::ok)
.unwrap_or(usize::MAX),
.and_then(Result::ok),
nbf: nbf_from_now
.and_then(|val| now_secs().checked_add(val))
.map(TryInto::try_into)
.and_then(Result::ok)
.unwrap_or(0),
.and_then(Result::ok),
};
encode(&header, &claim, &key)
@@ -1044,7 +1012,7 @@ pub(super) async fn resync_database(&self) -> Result {
self.services
.db
.db
.engine
.update()
.map_err(|e| err!("Failed to update from primary: {e:?}"))
}
+5 -14
View File
@@ -4,7 +4,7 @@ pub(crate) mod tester;
use clap::Subcommand;
use ruma::{OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName};
use tuwunel_core::Result;
use tuwunel_service::rooms::short::{ShortEventId, ShortRoomId};
use tuwunel_service::rooms::short::ShortRoomId;
use self::tester::TesterCommand;
use crate::admin_command_dispatch;
@@ -43,8 +43,8 @@ pub(super) enum DebugCommand {
/// Shortroomid integer
shortroomid: ShortRoomId,
/// Shorteventid integer
shorteventid: ShortEventId,
/// PduCount integer
count: i64,
},
/// - Attempts to retrieve a PDU from a remote server. Inserts it into our
@@ -72,15 +72,6 @@ pub(super) enum DebugCommand {
},
/// - Gets all the room state events for the specified room.
///
/// This is functionally equivalent to `GET
/// /_matrix/client/v3/rooms/{roomid}/state`, except the admin command does
/// *not* check if the sender user is allowed to see state events. This is
/// done because it's implied that server admins here have database access
/// and can see/get room info themselves anyways if they were malicious
/// admins.
///
/// Of course the check is still done on the actual client API.
GetRoomState {
/// Room ID
room_id: OwnedRoomOrAliasId,
@@ -125,13 +116,13 @@ pub(super) enum DebugCommand {
reset: bool,
},
/// - Verify json signatures
/// - Sign JSON blob
///
/// This command needs a JSON blob provided in a Markdown code block below
/// the command.
SignJson,
/// - Verify json signatures
/// - Verify JSON signatures
///
/// This command needs a JSON blob provided in a Markdown code block below
/// the command.
+2 -9
View File
@@ -6,19 +6,13 @@ use crate::{admin_command, get_room_info};
#[admin_command]
pub(super) async fn disable_room(&self, room_id: OwnedRoomId) -> Result {
self.services
.rooms
.metadata
.disable_room(&room_id, true);
self.services.metadata.disable_room(&room_id);
self.write_str("Room disabled.").await
}
#[admin_command]
pub(super) async fn enable_room(&self, room_id: OwnedRoomId) -> Result {
self.services
.rooms
.metadata
.disable_room(&room_id, false);
self.services.metadata.enable_room(&room_id);
self.write_str("Room enabled.").await
}
@@ -82,7 +76,6 @@ pub(super) async fn remote_user_in_rooms(&self, user_id: OwnedUserId) -> Result
let mut rooms: Vec<(OwnedRoomId, u64, String)> = self
.services
.rooms
.state_cache
.rooms_joined(&user_id)
.then(|room_id| get_room_info(self.services, room_id))
-1
View File
@@ -37,7 +37,6 @@ pub(super) async fn delete(
// parsing the PDU for any MXC URLs begins here
match self
.services
.rooms
.timeline
.get_pdu_json(&event_id)
.await
-1
View File
@@ -1,4 +1,3 @@
#![recursion_limit = "192"]
#![allow(clippy::wildcard_imports)]
#![allow(clippy::enum_glob_use)]
#![allow(clippy::too_many_arguments)]
+6 -1
View File
@@ -10,6 +10,7 @@ mod room_state_cache;
mod room_timeline;
mod sending;
mod short;
mod sync;
mod users;
use clap::Subcommand;
@@ -20,7 +21,7 @@ use self::{
presence::PresenceCommand, pusher::PusherCommand, raw::RawCommand, resolver::ResolverCommand,
room_alias::RoomAliasCommand, room_state_cache::RoomStateCacheCommand,
room_timeline::RoomTimelineCommand, sending::SendingCommand, short::ShortCommand,
users::UsersCommand,
sync::SyncCommand, users::UsersCommand,
};
use crate::admin_command_dispatch;
@@ -76,6 +77,10 @@ pub(super) enum QueryCommand {
#[command(subcommand)]
Short(ShortCommand),
/// - sync service
#[command(subcommand)]
Sync(SyncCommand),
/// - raw service
#[command(subcommand)]
Raw(RawCommand),
+14 -14
View File
@@ -16,16 +16,16 @@ use tuwunel_service::Services;
use crate::{admin_command, admin_command_dispatch};
#[admin_command_dispatch]
#[admin_command_dispatch(handler_prefix = "raw")]
#[derive(Debug, Subcommand)]
#[allow(clippy::enum_variant_names)]
/// Query tables from database
pub(crate) enum RawCommand {
/// - List database maps
RawMaps,
Maps,
/// - Raw database query
RawGet {
Get {
/// Map name
map: String,
@@ -38,7 +38,7 @@ pub(crate) enum RawCommand {
},
/// - Raw database delete (for string keys)
RawDel {
Del {
/// Map name
map: String,
@@ -47,7 +47,7 @@ pub(crate) enum RawCommand {
},
/// - Raw database keys iteration
RawKeys {
Keys {
/// Map name
map: String,
@@ -56,7 +56,7 @@ pub(crate) enum RawCommand {
},
/// - Raw database key size breakdown
RawKeysSizes {
KeysSizes {
/// Map name
map: Option<String>,
@@ -65,7 +65,7 @@ pub(crate) enum RawCommand {
},
/// - Raw database keys total bytes
RawKeysTotal {
KeysTotal {
/// Map name
map: Option<String>,
@@ -74,7 +74,7 @@ pub(crate) enum RawCommand {
},
/// - Raw database values size breakdown
RawValsSizes {
ValsSizes {
/// Map name
map: Option<String>,
@@ -83,7 +83,7 @@ pub(crate) enum RawCommand {
},
/// - Raw database values total bytes
RawValsTotal {
ValsTotal {
/// Map name
map: Option<String>,
@@ -92,7 +92,7 @@ pub(crate) enum RawCommand {
},
/// - Raw database items iteration
RawIter {
Iter {
/// Map name
map: String,
@@ -101,7 +101,7 @@ pub(crate) enum RawCommand {
},
/// - Raw database keys iteration
RawKeysFrom {
KeysFrom {
/// Map name
map: String,
@@ -114,7 +114,7 @@ pub(crate) enum RawCommand {
},
/// - Raw database items iteration
RawIterFrom {
IterFrom {
/// Map name
map: String,
@@ -127,7 +127,7 @@ pub(crate) enum RawCommand {
},
/// - Raw database record count
RawCount {
Count {
/// Map name
map: Option<String>,
@@ -165,7 +165,7 @@ pub(crate) enum RawCommand {
}
#[admin_command]
pub(super) async fn compact(
pub(super) async fn raw_compact(
&self,
map: Option<Vec<String>>,
start: Option<String>,
+1 -7
View File
@@ -30,11 +30,7 @@ pub(super) async fn process(subcommand: RoomAliasCommand, context: &Context<'_>)
match subcommand {
| RoomAliasCommand::ResolveLocalAlias { alias } => {
let timer = tokio::time::Instant::now();
let results = services
.rooms
.alias
.resolve_local_alias(&alias)
.await;
let results = services.alias.resolve_local_alias(&alias).await;
let query_time = timer.elapsed();
write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
@@ -42,7 +38,6 @@ pub(super) async fn process(subcommand: RoomAliasCommand, context: &Context<'_>)
| RoomAliasCommand::LocalAliasesForRoom { room_id } => {
let timer = tokio::time::Instant::now();
let aliases: Vec<_> = services
.rooms
.alias
.local_aliases_for_room(&room_id)
.map(ToOwned::to_owned)
@@ -55,7 +50,6 @@ pub(super) async fn process(subcommand: RoomAliasCommand, context: &Context<'_>)
| RoomAliasCommand::AllLocalAliases => {
let timer = tokio::time::Instant::now();
let aliases = services
.rooms
.alias
.all_local_aliases()
.map(|(room_id, alias)| (room_id.to_owned(), alias.to_owned()))
+22 -18
View File
@@ -74,6 +74,10 @@ pub(crate) enum RoomStateCacheCommand {
user_id: OwnedUserId,
room_id: OwnedRoomId,
},
UserMemberships {
user_id: OwnedUserId,
},
}
pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context<'_>) -> Result {
@@ -83,7 +87,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::ServerInRoom { server, room_id } => {
let timer = tokio::time::Instant::now();
let result = services
.rooms
.state_cache
.server_in_room(&server, &room_id)
.await;
@@ -98,7 +101,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::RoomServers { room_id } => {
let timer = tokio::time::Instant::now();
let results: Vec<_> = services
.rooms
.state_cache
.room_servers(&room_id)
.map(ToOwned::to_owned)
@@ -115,7 +117,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::ServerRooms { server } => {
let timer = tokio::time::Instant::now();
let results: Vec<_> = services
.rooms
.state_cache
.server_rooms(&server)
.map(ToOwned::to_owned)
@@ -132,7 +133,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::RoomMembers { room_id } => {
let timer = tokio::time::Instant::now();
let results: Vec<_> = services
.rooms
.state_cache
.room_members(&room_id)
.map(ToOwned::to_owned)
@@ -149,7 +149,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::LocalUsersInRoom { room_id } => {
let timer = tokio::time::Instant::now();
let results: Vec<_> = services
.rooms
.state_cache
.local_users_in_room(&room_id)
.map(ToOwned::to_owned)
@@ -166,7 +165,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::ActiveLocalUsersInRoom { room_id } => {
let timer = tokio::time::Instant::now();
let results: Vec<_> = services
.rooms
.state_cache
.active_local_users_in_room(&room_id)
.map(ToOwned::to_owned)
@@ -183,7 +181,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::RoomJoinedCount { room_id } => {
let timer = tokio::time::Instant::now();
let results = services
.rooms
.state_cache
.room_joined_count(&room_id)
.await;
@@ -198,7 +195,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::RoomInvitedCount { room_id } => {
let timer = tokio::time::Instant::now();
let results = services
.rooms
.state_cache
.room_invited_count(&room_id)
.await;
@@ -213,7 +209,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::RoomUserOnceJoined { room_id } => {
let timer = tokio::time::Instant::now();
let results: Vec<_> = services
.rooms
.state_cache
.room_useroncejoined(&room_id)
.map(ToOwned::to_owned)
@@ -230,7 +225,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::RoomMembersInvited { room_id } => {
let timer = tokio::time::Instant::now();
let results: Vec<_> = services
.rooms
.state_cache
.room_members_invited(&room_id)
.map(ToOwned::to_owned)
@@ -247,7 +241,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::GetInviteCount { room_id, user_id } => {
let timer = tokio::time::Instant::now();
let results = services
.rooms
.state_cache
.get_invite_count(&room_id, &user_id)
.await;
@@ -262,7 +255,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::GetLeftCount { room_id, user_id } => {
let timer = tokio::time::Instant::now();
let results = services
.rooms
.state_cache
.get_left_count(&room_id, &user_id)
.await;
@@ -277,7 +269,6 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::RoomsJoined { user_id } => {
let timer = tokio::time::Instant::now();
let results: Vec<_> = services
.rooms
.state_cache
.rooms_joined(&user_id)
.map(ToOwned::to_owned)
@@ -294,9 +285,8 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::RoomsInvited { user_id } => {
let timer = tokio::time::Instant::now();
let results: Vec<_> = services
.rooms
.state_cache
.rooms_invited(&user_id)
.rooms_invited_state(&user_id)
.collect()
.await;
let query_time = timer.elapsed();
@@ -310,9 +300,8 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::RoomsLeft { user_id } => {
let timer = tokio::time::Instant::now();
let results: Vec<_> = services
.rooms
.state_cache
.rooms_left(&user_id)
.rooms_left_state(&user_id)
.collect()
.await;
let query_time = timer.elapsed();
@@ -326,12 +315,27 @@ pub(super) async fn process(subcommand: RoomStateCacheCommand, context: &Context
| RoomStateCacheCommand::InviteState { user_id, room_id } => {
let timer = tokio::time::Instant::now();
let results = services
.rooms
.state_cache
.invite_state(&user_id, &room_id)
.await;
let query_time = timer.elapsed();
context
.write_str(&format!(
"Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"
))
.await
},
| RoomStateCacheCommand::UserMemberships { user_id } => {
let timer = tokio::time::Instant::now();
let results = services
.state_cache
.all_user_memberships(&user_id)
.map(|(membership, room_id)| (membership, room_id.to_owned()))
.collect::<Vec<_>>()
.await;
let query_time = timer.elapsed();
context
.write_str(&format!(
"Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```"
+3 -7
View File
@@ -27,16 +27,14 @@ pub(crate) enum RoomTimelineCommand {
pub(super) async fn last(&self, room_id: OwnedRoomOrAliasId) -> Result {
let room_id = self
.services
.rooms
.alias
.resolve(&room_id)
.maybe_resolve(&room_id)
.await?;
let result = self
.services
.rooms
.timeline
.last_timeline_count(None, &room_id)
.last_timeline_count(None, &room_id, None)
.await?;
self.write_str(&format!("{result:#?}")).await
@@ -51,16 +49,14 @@ pub(super) async fn pdus(
) -> Result {
let room_id = self
.services
.rooms
.alias
.resolve(&room_id)
.maybe_resolve(&room_id)
.await?;
let from: Option<PduCount> = from.as_deref().map(str::parse).transpose()?;
let result: Vec<_> = self
.services
.rooms
.timeline
.pdus_rev(None, &room_id, from)
.try_take(limit.unwrap_or(3))
+1 -4
View File
@@ -21,7 +21,6 @@ pub(crate) enum ShortCommand {
pub(super) async fn short_event_id(&self, event_id: OwnedEventId) -> Result {
let shortid = self
.services
.rooms
.short
.get_shorteventid(&event_id)
.await?;
@@ -33,14 +32,12 @@ pub(super) async fn short_event_id(&self, event_id: OwnedEventId) -> Result {
pub(super) async fn short_room_id(&self, room_id: OwnedRoomOrAliasId) -> Result {
let room_id = self
.services
.rooms
.alias
.resolve(&room_id)
.maybe_resolve(&room_id)
.await?;
let shortid = self
.services
.rooms
.short
.get_shortroomid(&room_id)
.await?;
+82
View File
@@ -0,0 +1,82 @@
use clap::Subcommand;
use ruma::{OwnedDeviceId, OwnedUserId};
use tuwunel_core::Result;
use tuwunel_service::sync::into_connection_key;
use crate::{admin_command, admin_command_dispatch};
#[admin_command_dispatch]
#[derive(Debug, Subcommand)]
/// Query sync service state
pub(crate) enum SyncCommand {
/// List sliding-sync connections.
ListConnections,
/// Show details of sliding sync connection by ID.
ShowConnection {
user_id: OwnedUserId,
device_id: OwnedDeviceId,
conn_id: Option<String>,
},
/// Drop connections for a user, device, or all.
DropConnections {
user_id: Option<OwnedUserId>,
device_id: Option<OwnedDeviceId>,
conn_id: Option<String>,
},
}
#[admin_command]
pub(super) async fn list_connections(&self) -> Result {
let connections = self.services.sync.list_loaded_connections().await;
for connection_key in connections {
self.write_str(&format!("{connection_key:?}\n"))
.await?;
}
Ok(())
}
#[admin_command]
pub(super) async fn show_connection(
&self,
user_id: OwnedUserId,
device_id: OwnedDeviceId,
conn_id: Option<String>,
) -> Result {
let key = into_connection_key(user_id, device_id, conn_id);
let cache = self
.services
.sync
.get_loaded_connection(&key)
.await?;
let out;
{
let cached = cache.lock().await;
out = format!("{cached:#?}");
};
self.write_str(out.as_str()).await
}
#[admin_command]
pub(super) async fn drop_connections(
&self,
user_id: Option<OwnedUserId>,
device_id: Option<OwnedDeviceId>,
conn_id: Option<String>,
) -> Result {
self.services
.sync
.clear_connections(
user_id.as_deref(),
device_id.as_deref(),
conn_id.map(Into::into).as_ref(),
)
.await;
Ok(())
}
-1
View File
@@ -134,7 +134,6 @@ async fn get_shared_rooms(&self, user_a: OwnedUserId, user_b: OwnedUserId) -> Re
let timer = tokio::time::Instant::now();
let result: Vec<_> = self
.services
.rooms
.state_cache
.get_shared_rooms(&user_a, &user_b)
.map(ToOwned::to_owned)
+8 -16
View File
@@ -63,17 +63,15 @@ pub(super) async fn process(command: RoomAliasCommand, context: &Context<'_>) ->
match (
force,
services
.rooms
.alias
.resolve_local_alias(&room_alias)
.await,
) {
| (true, Ok(id)) => {
match services.rooms.alias.set_alias(
&room_alias,
&room_id,
server_user,
) {
match services
.alias
.set_alias(&room_alias, &room_id, server_user)
{
| Err(err) => Err!("Failed to remove alias: {err}"),
| Ok(()) =>
context
@@ -88,11 +86,10 @@ pub(super) async fn process(command: RoomAliasCommand, context: &Context<'_>) ->
overwrite"
),
| (_, Err(_)) => {
match services.rooms.alias.set_alias(
&room_alias,
&room_id,
server_user,
) {
match services
.alias
.set_alias(&room_alias, &room_id, server_user)
{
| Err(err) => Err!("Failed to remove alias: {err}"),
| Ok(()) => context.write_str("Successfully set alias").await,
}
@@ -101,14 +98,12 @@ pub(super) async fn process(command: RoomAliasCommand, context: &Context<'_>) ->
},
| RoomAliasCommand::Remove { .. } => {
match services
.rooms
.alias
.resolve_local_alias(&room_alias)
.await
{
| Err(_) => Err!("Alias isn't in use."),
| Ok(id) => match services
.rooms
.alias
.remove_alias(&room_alias, server_user)
.await
@@ -123,7 +118,6 @@ pub(super) async fn process(command: RoomAliasCommand, context: &Context<'_>) ->
},
| RoomAliasCommand::Which { .. } => {
match services
.rooms
.alias
.resolve_local_alias(&room_alias)
.await
@@ -141,7 +135,6 @@ pub(super) async fn process(command: RoomAliasCommand, context: &Context<'_>) ->
| RoomAliasCommand::List { room_id } =>
if let Some(room_id) = room_id {
let aliases: Vec<OwnedRoomAliasId> = services
.rooms
.alias
.local_aliases_for_room(&room_id)
.map(Into::into)
@@ -160,7 +153,6 @@ pub(super) async fn process(command: RoomAliasCommand, context: &Context<'_>) ->
context.write_str(&plain).await
} else {
let aliases = services
.rooms
.alias
.all_local_aliases()
.map(|(room_id, localpart)| (room_id.into(), localpart.into()))
+22 -21
View File
@@ -16,27 +16,14 @@ pub(super) async fn list_rooms(
let page = page.unwrap_or(1);
let mut rooms = self
.services
.rooms
.metadata
.iter_ids()
.filter_map(async |room_id| {
(!exclude_disabled
|| !self
.services
.rooms
.metadata
.is_disabled(room_id)
.await)
(!exclude_disabled || !self.services.metadata.is_disabled(room_id).await)
.then_some(room_id)
})
.filter_map(async |room_id| {
(!exclude_banned
|| !self
.services
.rooms
.metadata
.is_banned(room_id)
.await)
(!exclude_banned || !self.services.metadata.is_banned(room_id).await)
.then_some(room_id)
})
.then(|room_id| get_room_info(self.services, room_id))
@@ -74,12 +61,26 @@ pub(super) async fn list_rooms(
#[admin_command]
pub(super) async fn exists(&self, room_id: OwnedRoomId) -> Result {
let result = self
.services
.rooms
.metadata
.exists(&room_id)
.await;
let result = self.services.metadata.exists(&room_id).await;
self.write_str(&format!("{result}")).await
}
#[admin_command]
pub(super) async fn delete_room(&self, room_id: OwnedRoomId, force: bool) -> Result {
if self.services.admin.is_admin_room(&room_id).await {
return Err!("Cannot delete admin room");
}
let state_lock = self.services.state.mutex.lock(&room_id).await;
self.services
.delete
.delete_room(&room_id, force, state_lock)
.await?;
self.write_str("Successfully deleted the room from our database.")
.await?;
Ok(())
}
+2 -3
View File
@@ -29,18 +29,17 @@ pub(super) async fn process(command: RoomDirectoryCommand, context: &Context<'_>
let services = context.services;
match command {
| RoomDirectoryCommand::Publish { room_id } => {
services.rooms.directory.set_public(&room_id);
services.directory.set_public(&room_id);
context.write_str("Room published").await
},
| RoomDirectoryCommand::Unpublish { room_id } => {
services.rooms.directory.set_not_public(&room_id);
services.directory.set_not_public(&room_id);
context.write_str("Room unpublished").await
},
| RoomDirectoryCommand::List { page } => {
// TODO: i know there's a way to do this with clap, but i can't seem to find it
let page = page.unwrap_or(1);
let mut rooms: Vec<_> = services
.rooms
.directory
.public_rooms()
.then(|room_id| get_room_info(services, room_id))
-3
View File
@@ -30,7 +30,6 @@ pub(crate) enum RoomInfoCommand {
async fn list_joined_members(&self, room_id: OwnedRoomId, local_only: bool) -> Result {
let room_name = self
.services
.rooms
.state_accessor
.get_name(&room_id)
.await
@@ -38,7 +37,6 @@ async fn list_joined_members(&self, room_id: OwnedRoomId, local_only: bool) -> R
let member_info: Vec<_> = self
.services
.rooms
.state_cache
.room_members(&room_id)
.ready_filter(|user_id| {
@@ -75,7 +73,6 @@ async fn list_joined_members(&self, room_id: OwnedRoomId, local_only: bool) -> R
async fn view_room_topic(&self, room_id: OwnedRoomId) -> Result {
let Ok(room_topic) = self
.services
.rooms
.state_accessor
.get_room_topic(&room_id)
.await
+8
View File
@@ -56,4 +56,12 @@ pub(super) enum RoomCommand {
Exists {
room_id: OwnedRoomId,
},
/// - Delete room
DeleteRoom {
room_id: OwnedRoomId,
#[arg(short, long)]
force: bool,
},
}
+31 -63
View File
@@ -1,7 +1,6 @@
use clap::Subcommand;
use futures::{FutureExt, StreamExt};
use ruma::{OwnedRoomId, OwnedRoomOrAliasId, RoomAliasId, RoomId, RoomOrAliasId};
use tuwunel_api::client::leave_room;
use tuwunel_core::{
Err, Result, debug,
utils::{IterStream, ReadyExt},
@@ -49,7 +48,7 @@ pub(crate) enum RoomModerationCommand {
async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
debug!("Got room alias or ID: {}", room);
let admin_room_alias = &self.services.globals.admin_alias;
let admin_room_alias = &self.services.admin.admin_alias;
if let Ok(admin_room_id) = self.services.admin.get_admin_room().await {
if room.to_string().eq(&admin_room_id) || room.to_string().eq(admin_room_alias) {
@@ -70,10 +69,7 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
};
debug!("Room specified is a room ID, banning room ID");
self.services
.rooms
.metadata
.ban_room(room_id, true);
self.services.metadata.ban_room(room_id);
room_id.to_owned()
} else if room.is_room_alias_id() {
@@ -95,7 +91,6 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
let room_id = match self
.services
.rooms
.alias
.resolve_local_alias(room_alias)
.await
@@ -109,9 +104,8 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
match self
.services
.rooms
.alias
.resolve_alias(room_alias, None)
.resolve_alias(room_alias)
.await
{
| Ok((room_id, servers)) => {
@@ -131,10 +125,7 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
},
};
self.services
.rooms
.metadata
.ban_room(&room_id, true);
self.services.metadata.ban_room(&room_id);
room_id
} else {
@@ -148,7 +139,6 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
debug!("Making all users leave the room {room_id} and forgetting it");
let mut users = self
.services
.rooms
.state_cache
.room_members(&room_id)
.map(ToOwned::to_owned)
@@ -161,27 +151,31 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
evicting admins too)",
);
if let Err(e) = leave_room(self.services, user_id, &room_id, None)
let state_lock = self.services.state.mutex.lock(&room_id).await;
if let Err(e) = self
.services
.membership
.leave(user_id, &room_id, None, false, &state_lock)
.boxed()
.await
{
warn!("Failed to leave room: {e}");
}
drop(state_lock);
self.services
.rooms
.state_cache
.forget(&room_id, user_id);
}
self.services
.rooms
.alias
.local_aliases_for_room(&room_id)
.map(ToOwned::to_owned)
.for_each(async |local_alias| {
self.services
.rooms
.alias
.remove_alias(&local_alias, &self.services.globals.server_user)
.await
@@ -190,15 +184,9 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
.await;
// unpublish from room directory
self.services
.rooms
.directory
.set_not_public(&room_id);
self.services.directory.set_not_public(&room_id);
self.services
.rooms
.metadata
.disable_room(&room_id, true);
self.services.metadata.disable_room(&room_id);
self.write_str(
"Room banned, removed all our local users, and disabled incoming federation with room.",
@@ -221,7 +209,7 @@ async fn ban_list_of_rooms(&self) -> Result {
.drain(1..self.body.len().saturating_sub(1))
.collect::<Vec<_>>();
let admin_room_alias = &self.services.globals.admin_alias;
let admin_room_alias = &self.services.admin.admin_alias;
let mut room_ban_count: usize = 0;
let mut room_ids: Vec<OwnedRoomId> = Vec::new();
@@ -258,7 +246,6 @@ async fn ban_list_of_rooms(&self) -> Result {
| Ok(room_alias) => {
let room_id = match self
.services
.rooms
.alias
.resolve_local_alias(room_alias)
.await
@@ -272,9 +259,8 @@ async fn ban_list_of_rooms(&self) -> Result {
match self
.services
.rooms
.alias
.resolve_alias(room_alias, None)
.resolve_alias(room_alias)
.await
{
| Ok((room_id, servers)) => {
@@ -320,10 +306,7 @@ async fn ban_list_of_rooms(&self) -> Result {
}
for room_id in room_ids {
self.services
.rooms
.metadata
.ban_room(&room_id, true);
self.services.metadata.ban_room(&room_id);
debug!("Banned {room_id} successfully");
room_ban_count = room_ban_count.saturating_add(1);
@@ -331,7 +314,6 @@ async fn ban_list_of_rooms(&self) -> Result {
debug!("Making all users leave the room {room_id} and forgetting it");
let mut users = self
.services
.rooms
.state_cache
.room_members(&room_id)
.map(ToOwned::to_owned)
@@ -344,28 +326,32 @@ async fn ban_list_of_rooms(&self) -> Result {
evicting admins too)",
);
if let Err(e) = leave_room(self.services, user_id, &room_id, None)
let state_lock = self.services.state.mutex.lock(&room_id).await;
if let Err(e) = self
.services
.membership
.leave(user_id, &room_id, None, false, &state_lock)
.boxed()
.await
{
warn!("Failed to leave room: {e}");
}
drop(state_lock);
self.services
.rooms
.state_cache
.forget(&room_id, user_id);
}
// remove any local aliases, ignore errors
self.services
.rooms
.alias
.local_aliases_for_room(&room_id)
.map(ToOwned::to_owned)
.for_each(async |local_alias| {
self.services
.rooms
.alias
.remove_alias(&local_alias, &self.services.globals.server_user)
.await
@@ -374,15 +360,9 @@ async fn ban_list_of_rooms(&self) -> Result {
.await;
// unpublish from room directory, ignore errors
self.services
.rooms
.directory
.set_not_public(&room_id);
self.services.directory.set_not_public(&room_id);
self.services
.rooms
.metadata
.disable_room(&room_id, true);
self.services.metadata.disable_room(&room_id);
}
self.write_str(&format!(
@@ -407,10 +387,7 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
};
debug!("Room specified is a room ID, unbanning room ID");
self.services
.rooms
.metadata
.ban_room(room_id, false);
self.services.metadata.unban_room(room_id);
room_id.to_owned()
} else if room.is_room_alias_id() {
@@ -432,7 +409,6 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
let room_id = match self
.services
.rooms
.alias
.resolve_local_alias(room_alias)
.await
@@ -446,9 +422,8 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
match self
.services
.rooms
.alias
.resolve_alias(room_alias, None)
.resolve_alias(room_alias)
.await
{
| Ok((room_id, servers)) => {
@@ -466,10 +441,7 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
},
};
self.services
.rooms
.metadata
.ban_room(&room_id, false);
self.services.metadata.unban_room(&room_id);
room_id
} else {
@@ -480,10 +452,7 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
);
};
self.services
.rooms
.metadata
.disable_room(&room_id, false);
self.services.metadata.enable_room(&room_id);
self.write_str("Room unbanned and federation re-enabled.")
.await
}
@@ -492,7 +461,6 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
async fn list_banned_rooms(&self, no_details: bool) -> Result {
let room_ids: Vec<OwnedRoomId> = self
.services
.rooms
.metadata
.list_banned_rooms()
.map(Into::into)
+4 -4
View File
@@ -67,7 +67,7 @@ pub(super) async fn list_features(&self, available: bool, enabled: bool, comma:
#[admin_command]
pub(super) async fn memory_usage(&self) -> Result {
let services_usage = self.services.memory_usage().await?;
let database_usage = self.services.db.db.memory_usage()?;
let database_usage = self.services.db.engine.memory_usage()?;
let allocator_usage = tuwunel_core::alloc::memory_usage()
.map_or(String::new(), |s| format!("\nAllocator:\n{s}"));
@@ -88,7 +88,7 @@ pub(super) async fn clear_caches(&self) -> Result {
pub(super) async fn list_backups(&self) -> Result {
self.services
.db
.db
.engine
.backup_list()?
.try_stream()
.try_for_each(|result| write!(self, "{result}"))
@@ -102,13 +102,13 @@ pub(super) async fn backup_database(&self) -> Result {
.services
.server
.runtime()
.spawn_blocking(move || match db.db.backup() {
.spawn_blocking(move || match db.engine.backup() {
| Ok(()) => "Done".to_owned(),
| Err(e) => format!("Failed: {e}"),
})
.await?;
let count = self.services.db.db.backup_count()?;
let count = self.services.db.engine.backup_count()?;
self.write_str(&format!("{result}. Currently have {count} backups."))
.await
}
+201 -147
View File
@@ -2,30 +2,27 @@ use std::{collections::BTreeMap, fmt::Write as _};
use futures::{FutureExt, StreamExt};
use ruma::{
OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedUserId, UserId,
Int, OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedUserId, UserId,
events::{
RoomAccountDataEventType, StateEventType,
room::{
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent, UserPowerLevel},
redaction::RoomRedactionEventContent,
},
tag::{TagEvent, TagEventContent, TagInfo},
},
};
use tuwunel_api::client::{
full_user_deactivate, join_room_by_id_helper, leave_all_rooms, leave_room, update_avatar_url,
update_displayname,
};
use tuwunel_core::{
Err, Result, debug, debug_warn, error, info, is_equal_to,
matrix::{Event, pdu::PduBuilder},
utils::{self, ReadyExt},
warn,
};
use tuwunel_service::Services;
use crate::{
admin_command, get_room_info,
utils::{parse_active_local_user_id, parse_local_user_id},
utils::{parse_active_local_user_id, parse_local_user_id, parse_user_id},
};
const AUTO_GEN_PASSWORD_LENGTH: usize = 25;
@@ -122,7 +119,7 @@ pub(super) async fn create_user(&self, username: String, password: Option<String
.is_empty()
{
for room in &self.services.server.config.auto_join_rooms {
let Ok(room_id) = self.services.rooms.alias.resolve(room).await else {
let Ok(room_id) = self.services.alias.maybe_resolve(room).await else {
error!(
%user_id,
"Failed to resolve room alias to room ID when attempting to auto join {room}, skipping"
@@ -132,7 +129,6 @@ pub(super) async fn create_user(&self, username: String, password: Option<String
if !self
.services
.rooms
.state_cache
.server_in_room(self.services.globals.server_name(), &room_id)
.await
@@ -143,20 +139,24 @@ pub(super) async fn create_user(&self, username: String, password: Option<String
continue;
}
let state_lock = self.services.state.mutex.lock(&room_id).await;
if let Some(room_server_name) = room.server_name() {
match join_room_by_id_helper(
self.services,
&user_id,
&room_id,
Some("Automatically joining this room upon registration".to_owned()),
&[
self.services.globals.server_name().to_owned(),
room_server_name.to_owned(),
],
None,
&None,
)
.await
match self
.services
.membership
.join(
&user_id,
&room_id,
Some("Automatically joining this room upon registration".to_owned()),
&[
self.services.globals.server_name().to_owned(),
room_server_name.to_owned(),
],
&None,
&state_lock,
)
.await
{
| Ok(_response) => {
info!("Automatically joined room {room} for user {user_id}");
@@ -175,6 +175,8 @@ pub(super) async fn create_user(&self, username: String, password: Option<String
.await;
},
}
drop(state_lock);
}
}
}
@@ -186,7 +188,6 @@ pub(super) async fn create_user(&self, username: String, password: Option<String
if let Ok(admin_room) = self.services.admin.get_admin_room().await {
if self
.services
.rooms
.state_cache
.room_joined_count(&admin_room)
.await
@@ -195,6 +196,7 @@ pub(super) async fn create_user(&self, username: String, password: Option<String
self.services
.admin
.make_user_admin(&user_id)
.boxed()
.await?;
warn!("Granting {user_id} admin privileges as the first user");
}
@@ -216,34 +218,7 @@ pub(super) async fn deactivate(&self, no_leave_rooms: bool, user_id: String) ->
return Err!("Not allowed to deactivate the server service account.",);
}
self.services
.users
.deactivate_account(&user_id)
.await?;
if !no_leave_rooms {
self.services
.admin
.send_text(&format!("Making {user_id} leave all rooms after deactivation..."))
.await;
let all_joined_rooms: Vec<OwnedRoomId> = self
.services
.rooms
.state_cache
.rooms_joined(&user_id)
.map(Into::into)
.collect()
.await;
full_user_deactivate(self.services, &user_id, &all_joined_rooms)
.boxed()
.await?;
update_displayname(self.services, &user_id, None, &all_joined_rooms).await;
update_avatar_url(self.services, &user_id, None, None, &all_joined_rooms).await;
leave_all_rooms(self.services, &user_id).await;
}
deactivate_user(self.services, &user_id, no_leave_rooms).await?;
self.write_str(&format!("User {user_id} has been deactivated"))
.await
@@ -336,41 +311,16 @@ pub(super) async fn deactivate_all(&self, no_leave_rooms: bool, force: bool) ->
let mut deactivation_count: usize = 0;
for user_id in user_ids {
match self
.services
.users
.deactivate_account(&user_id)
.await
{
match deactivate_user(self.services, &user_id, no_leave_rooms).await {
| Ok(()) => {
deactivation_count = deactivation_count.saturating_add(1);
},
| Err(e) => {
self.services
.admin
.send_text(&format!("Failed deactivating user: {e}"))
.await;
},
| Ok(()) => {
deactivation_count = deactivation_count.saturating_add(1);
if !no_leave_rooms {
info!("Forcing user {user_id} to leave all rooms apart of deactivate-all");
let all_joined_rooms: Vec<OwnedRoomId> = self
.services
.rooms
.state_cache
.rooms_joined(&user_id)
.map(Into::into)
.collect()
.await;
full_user_deactivate(self.services, &user_id, &all_joined_rooms)
.boxed()
.await?;
update_displayname(self.services, &user_id, None, &all_joined_rooms).await;
update_avatar_url(self.services, &user_id, None, None, &all_joined_rooms)
.await;
leave_all_rooms(self.services, &user_id).await;
}
},
}
}
@@ -387,6 +337,20 @@ pub(super) async fn deactivate_all(&self, no_leave_rooms: bool, force: bool) ->
.await
}
async fn deactivate_user(services: &Services, user_id: &UserId, no_leave_rooms: bool) -> Result {
if !no_leave_rooms {
services
.deactivate
.full_deactivate(user_id)
.boxed()
.await?;
} else {
services.users.deactivate_account(user_id).await?;
}
Ok(())
}
#[admin_command]
pub(super) async fn list_joined_rooms(&self, user_id: String) -> Result {
// Validate user id
@@ -394,7 +358,6 @@ pub(super) async fn list_joined_rooms(&self, user_id: String) -> Result {
let mut rooms: Vec<(OwnedRoomId, u64, String)> = self
.services
.rooms
.state_cache
.rooms_joined(&user_id)
.then(|room_id| get_room_info(self.services, room_id))
@@ -444,14 +407,12 @@ pub(super) async fn force_join_list_of_local_users(
let (room_id, servers) = self
.services
.rooms
.alias
.resolve_with_servers(&room_id, None)
.maybe_resolve_with_servers(&room_id, None)
.await?;
if !self
.services
.rooms
.state_cache
.server_in_room(self.services.globals.server_name(), &room_id)
.await
@@ -461,7 +422,6 @@ pub(super) async fn force_join_list_of_local_users(
let server_admins: Vec<_> = self
.services
.rooms
.state_cache
.active_local_users_in_room(&admin_room)
.map(ToOwned::to_owned)
@@ -470,7 +430,6 @@ pub(super) async fn force_join_list_of_local_users(
if !self
.services
.rooms
.state_cache
.room_members(&room_id)
.ready_any(|user_id| server_admins.contains(&user_id.to_owned()))
@@ -518,17 +477,21 @@ pub(super) async fn force_join_list_of_local_users(
let mut failed_joins: usize = 0;
let mut successful_joins: usize = 0;
let state_lock = self.services.state.mutex.lock(&room_id).await;
for user_id in user_ids {
match join_room_by_id_helper(
self.services,
&user_id,
&room_id,
Some(String::from(BULK_JOIN_REASON)),
&servers,
None,
&None,
)
.await
match self
.services
.membership
.join(
&user_id,
&room_id,
Some(String::from(BULK_JOIN_REASON)),
&servers,
&None,
&state_lock,
)
.await
{
| Ok(_res) => {
successful_joins = successful_joins.saturating_add(1);
@@ -540,6 +503,8 @@ pub(super) async fn force_join_list_of_local_users(
}
}
drop(state_lock);
self.write_str(&format!(
"{successful_joins} local users have been joined to {room_id}. {failed_joins} joins \
failed.",
@@ -566,14 +531,12 @@ pub(super) async fn force_join_all_local_users(
let (room_id, servers) = self
.services
.rooms
.alias
.resolve_with_servers(&room_id, None)
.maybe_resolve_with_servers(&room_id, None)
.await?;
if !self
.services
.rooms
.state_cache
.server_in_room(self.services.globals.server_name(), &room_id)
.await
@@ -583,7 +546,6 @@ pub(super) async fn force_join_all_local_users(
let server_admins: Vec<_> = self
.services
.rooms
.state_cache
.active_local_users_in_room(&admin_room)
.map(ToOwned::to_owned)
@@ -592,7 +554,6 @@ pub(super) async fn force_join_all_local_users(
if !self
.services
.rooms
.state_cache
.room_members(&room_id)
.ready_any(|user_id| server_admins.contains(&user_id.to_owned()))
@@ -604,6 +565,8 @@ pub(super) async fn force_join_all_local_users(
let mut failed_joins: usize = 0;
let mut successful_joins: usize = 0;
let state_lock = self.services.state.mutex.lock(&room_id).await;
for user_id in &self
.services
.users
@@ -612,16 +575,18 @@ pub(super) async fn force_join_all_local_users(
.collect::<Vec<_>>()
.await
{
match join_room_by_id_helper(
self.services,
user_id,
&room_id,
Some(String::from(BULK_JOIN_REASON)),
&servers,
None,
&None,
)
.await
match self
.services
.membership
.join(
user_id,
&room_id,
Some(String::from(BULK_JOIN_REASON)),
&servers,
&None,
&state_lock,
)
.await
{
| Ok(_res) => {
successful_joins = successful_joins.saturating_add(1);
@@ -633,6 +598,8 @@ pub(super) async fn force_join_all_local_users(
}
}
drop(state_lock);
self.write_str(&format!(
"{successful_joins} local users have been joined to {room_id}. {failed_joins} joins \
failed.",
@@ -649,18 +616,24 @@ pub(super) async fn force_join_room(
let user_id = parse_local_user_id(self.services, &user_id)?;
let (room_id, servers) = self
.services
.rooms
.alias
.resolve_with_servers(&room_id, None)
.maybe_resolve_with_servers(&room_id, None)
.await?;
assert!(
self.services.globals.user_is_local(&user_id),
"Parsed user_id must be a local user"
);
join_room_by_id_helper(self.services, &user_id, &room_id, None, &servers, None, &None)
let state_lock = self.services.state.mutex.lock(&room_id).await;
self.services
.membership
.join(&user_id, &room_id, None, &servers, &None, &state_lock)
.await?;
drop(state_lock);
self.write_str(&format!("{user_id} has been joined to {room_id}.",))
.await
}
@@ -674,9 +647,8 @@ pub(super) async fn force_leave_room(
let user_id = parse_local_user_id(self.services, &user_id)?;
let room_id = self
.services
.rooms
.alias
.resolve(&room_id)
.maybe_resolve(&room_id)
.await?;
assert!(
@@ -686,7 +658,6 @@ pub(super) async fn force_leave_room(
if !self
.services
.rooms
.state_cache
.is_joined(&user_id, &room_id)
.await
@@ -694,10 +665,16 @@ pub(super) async fn force_leave_room(
return Err!("{user_id} is not joined in the room");
}
leave_room(self.services, &user_id, &room_id, None)
let state_lock = self.services.state.mutex.lock(&room_id).await;
self.services
.membership
.leave(&user_id, &room_id, None, false, &state_lock)
.boxed()
.await?;
drop(state_lock);
self.write_str(&format!("{user_id} has left {room_id}.",))
.await
}
@@ -707,9 +684,8 @@ pub(super) async fn force_demote(&self, user_id: String, room_id: OwnedRoomOrAli
let user_id = parse_local_user_id(self.services, &user_id)?;
let room_id = self
.services
.rooms
.alias
.resolve(&room_id)
.maybe_resolve(&room_id)
.await?;
assert!(
@@ -717,45 +693,42 @@ pub(super) async fn force_demote(&self, user_id: String, room_id: OwnedRoomOrAli
"Parsed user_id must be a local user"
);
let state_lock = self
.services
.rooms
.state
.mutex
.lock(&room_id)
.await;
let state_lock = self.services.state.mutex.lock(&room_id).await;
let room_power_levels: Option<RoomPowerLevelsEventContent> = self
let room_power_levels: Option<RoomPowerLevels> = self
.services
.rooms
.state_accessor
.room_state_get_content(&room_id, &StateEventType::RoomPowerLevels, "")
.get_power_levels(&room_id)
.await
.ok();
let user_can_demote_self = room_power_levels
let user_can_change_self = room_power_levels
.as_ref()
.is_some_and(|power_levels_content| {
RoomPowerLevels::from(power_levels_content.clone())
.user_can_change_user_power_level(&user_id, &user_id)
}) || self
.services
.rooms
.state_accessor
.room_state_get(&room_id, &StateEventType::RoomCreate, "")
.await
.is_ok_and(|event| event.sender() == user_id);
.is_some_and(|power_levels| {
power_levels.user_can_change_user_power_level(&user_id, &user_id)
});
let user_can_demote_self = user_can_change_self
|| self
.services
.state_accessor
.room_state_get(&room_id, &StateEventType::RoomCreate, "")
.await
.is_ok_and(|event| event.sender() == user_id);
if !user_can_demote_self {
return Err!("User is not allowed to modify their own power levels in the room.",);
return Err!("User is not allowed to modify their own power levels in the room.");
}
let mut power_levels_content = room_power_levels.unwrap_or_default();
let mut power_levels_content: RoomPowerLevelsEventContent = room_power_levels
.map(TryInto::try_into)
.transpose()?
.unwrap_or_default();
power_levels_content.users.remove(&user_id);
let event_id = self
.services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(String::new(), &power_levels_content),
@@ -772,6 +745,89 @@ pub(super) async fn force_demote(&self, user_id: String, room_id: OwnedRoomOrAli
.await
}
#[admin_command]
pub(super) async fn force_promote(
&self,
target_id: String,
room_id: OwnedRoomOrAliasId,
) -> Result {
let target_id = parse_user_id(self.services, &target_id)?;
let room_id = self
.services
.alias
.maybe_resolve(&room_id)
.await?;
let state_lock = self.services.state.mutex.lock(&room_id).await;
let room_power_levels = self
.services
.state_accessor
.get_power_levels(&room_id)
.await?;
let privileged_member = self
.services
.state_cache
.room_members(&room_id)
.ready_filter(|member_id| {
self.services.globals.user_is_local(member_id)
&& room_power_levels.user_can_change_user_power_level(member_id, &target_id)
})
.map(ToOwned::to_owned)
.ready_fold_default(|selected_user, member_id| match selected_user {
| None => Some(member_id),
| Some(selected_user) => Some(
if room_power_levels.for_user(&selected_user)
> room_power_levels.for_user(&member_id)
{
selected_user
} else {
member_id
},
),
})
.await;
let Some(privileged_member) = privileged_member else {
return Err!("No privileged user exists in room, cannot promote.");
};
info!("Selected privileged member {privileged_member}");
let power_level: Int = match room_power_levels.for_user(&privileged_member) {
| UserPowerLevel::Infinite => Int::MAX,
| UserPowerLevel::Int(x) => x,
};
let mut power_levels_content: RoomPowerLevelsEventContent = room_power_levels.try_into()?;
power_levels_content
.users
.insert(target_id.clone(), power_level);
let event_id = self
.services
.timeline
.build_and_append_pdu(
PduBuilder::state(String::new(), &power_levels_content),
&privileged_member,
&room_id,
&state_lock,
)
.await?;
drop(state_lock);
self.write_str(&format!(
"User {privileged_member} promoted {target_id} to {power_level} power level in \
{room_id} - {event_id}"
))
.await?;
Ok(())
}
#[admin_command]
pub(super) async fn make_user_admin(&self, user_id: String) -> Result {
let user_id = parse_local_user_id(self.services, &user_id)?;
@@ -783,6 +839,7 @@ pub(super) async fn make_user_admin(&self, user_id: String) -> Result {
self.services
.admin
.make_user_admin(&user_id)
.boxed()
.await?;
self.write_str(&format!("{user_id} has been granted admin privileges.",))
@@ -889,7 +946,6 @@ pub(super) async fn get_room_tags(&self, user_id: String, room_id: OwnedRoomId)
pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result {
let Ok(event) = self
.services
.rooms
.timeline
.get_non_outlier_pdu(&event_id)
.await
@@ -917,14 +973,12 @@ pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result {
let redaction_event_id = {
let state_lock = self
.services
.rooms
.state
.mutex
.lock(event.room_id())
.await;
self.services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder {
+6
View File
@@ -88,6 +88,12 @@ pub(super) enum UserCommand {
room_id: OwnedRoomOrAliasId,
},
/// - Force promote
ForcePromote {
user_id: String,
room_id: OwnedRoomOrAliasId,
},
/// - Grant server-admin privileges to a user.
MakeUserAdmin {
user_id: String,
-2
View File
@@ -17,13 +17,11 @@ pub(crate) async fn get_room_info(
(
room_id.into(),
services
.rooms
.state_cache
.room_joined_count(room_id)
.await
.unwrap_or(0),
services
.rooms
.state_accessor
.get_name(room_id)
.await
+1
View File
@@ -11,6 +11,7 @@ version.workspace = true
[lib]
path = "mod.rs"
bench = false
crate-type = [
"rlib",
# "dylib",
+11 -236
View File
@@ -1,32 +1,13 @@
use axum::extract::State;
use axum_client_ip::InsecureClientIp;
use futures::{FutureExt, StreamExt};
use ruma::{
OwnedRoomId, UserId,
api::client::{
account::{
ThirdPartyIdRemovalStatus, change_password, deactivate, get_3pids,
request_3pid_management_token_via_email, request_3pid_management_token_via_msisdn,
whoami,
},
uiaa::{AuthFlow, AuthType, UiaaInfo},
},
events::{
StateEventType,
room::power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
},
use ruma::api::client::account::{
ThirdPartyIdRemovalStatus, change_password, deactivate, get_3pids,
request_3pid_management_token_via_email, request_3pid_management_token_via_msisdn, whoami,
};
use tuwunel_core::{
Err, Error, Result, err, info,
matrix::{Event, pdu::PduBuilder},
utils,
utils::{ReadyExt, stream::BroadbandExt},
warn,
};
use tuwunel_service::Services;
use tuwunel_core::{Err, Result, info, utils::ReadyExt};
use super::SESSION_ID_LENGTH;
use crate::Ruma;
use crate::{Ruma, router::auth_uiaa};
/// # `POST /_matrix/client/r0/account/password`
///
@@ -51,48 +32,7 @@ pub(crate) async fn change_password_route(
InsecureClientIp(client): InsecureClientIp,
body: Ruma<change_password::v3::Request>,
) -> Result<change_password::v3::Response> {
// Authentication for this endpoint was made optional, but we need
// authentication currently
let sender_user = body
.sender_user
.as_ref()
.ok_or_else(|| err!(Request(MissingToken("Missing access token."))))?;
let mut uiaainfo = UiaaInfo {
flows: vec![AuthFlow { stages: vec![AuthType::Password] }],
completed: Vec::new(),
params: Box::default(),
session: None,
auth_error: None,
};
match &body.auth {
| Some(auth) => {
let (worked, uiaainfo) = services
.uiaa
.try_auth(sender_user, body.sender_device(), auth, &uiaainfo)
.await?;
if !worked {
return Err(Error::Uiaa(uiaainfo));
}
// Success!
},
| _ => match body.json_body {
| Some(ref json) => {
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
services
.uiaa
.create(sender_user, body.sender_device(), &uiaainfo, json);
return Err(Error::Uiaa(uiaainfo));
},
| _ => {
return Err!(Request(NotJson("JSON body is not valid")));
},
},
}
let ref sender_user = auth_uiaa(&services, &body).await?;
services
.users
@@ -104,32 +44,9 @@ pub(crate) async fn change_password_route(
services
.users
.all_device_ids(sender_user)
.ready_filter(|id| *id != body.sender_device())
.ready_filter(|&id| Some(id) != body.sender_device.as_deref())
.for_each(|id| services.users.remove_device(sender_user, id))
.await;
// Remove all pushers except the ones associated with this session
services
.pusher
.get_pushkeys(sender_user)
.map(ToOwned::to_owned)
.broad_filter_map(async |pushkey| {
services
.pusher
.get_pusher_device(&pushkey)
.await
.ok()
.filter(|pusher_device| pusher_device != body.sender_device())
.is_some()
.then_some(pushkey)
})
.for_each(async |pushkey| {
services
.pusher
.delete_pusher(sender_user, &pushkey)
.await;
})
.await;
}
info!("User {sender_user} changed their password.");
@@ -180,66 +97,15 @@ pub(crate) async fn deactivate_route(
InsecureClientIp(client): InsecureClientIp,
body: Ruma<deactivate::v3::Request>,
) -> Result<deactivate::v3::Response> {
// Authentication for this endpoint was made optional, but we need
// authentication currently
let sender_user = body
.sender_user
.as_ref()
.ok_or_else(|| err!(Request(MissingToken("Missing access token."))))?;
let ref sender_user = auth_uiaa(&services, &body).await?;
let mut uiaainfo = UiaaInfo {
flows: vec![AuthFlow { stages: vec![AuthType::Password] }],
completed: Vec::new(),
params: Box::default(),
session: None,
auth_error: None,
};
match &body.auth {
| Some(auth) => {
let (worked, uiaainfo) = services
.uiaa
.try_auth(sender_user, body.sender_device(), auth, &uiaainfo)
.await?;
if !worked {
return Err(Error::Uiaa(uiaainfo));
}
// Success!
},
| _ => match body.json_body {
| Some(ref json) => {
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
services
.uiaa
.create(sender_user, body.sender_device(), &uiaainfo, json);
return Err(Error::Uiaa(uiaainfo));
},
| _ => {
return Err!(Request(NotJson("JSON body is not valid")));
},
},
}
// Remove profile pictures and display name
let all_joined_rooms: Vec<OwnedRoomId> = services
.rooms
.state_cache
.rooms_joined(sender_user)
.map(Into::into)
.collect()
.await;
super::update_displayname(&services, sender_user, None, &all_joined_rooms).await;
super::update_avatar_url(&services, sender_user, None, None, &all_joined_rooms).await;
full_user_deactivate(&services, sender_user, &all_joined_rooms)
services
.deactivate
.full_deactivate(sender_user)
.boxed()
.await?;
info!("User {sender_user} deactivated their account.");
if services.server.config.admin_room_notices {
services
.admin
@@ -293,94 +159,3 @@ pub(crate) async fn request_3pid_management_token_via_msisdn_route(
) -> Result<request_3pid_management_token_via_msisdn::v3::Response> {
Err!(Request(ThreepidDenied("Third party identifiers are not implemented")))
}
/// Runs through all the deactivation steps:
///
/// - Mark as deactivated
/// - Removing display name
/// - Removing avatar URL and blurhash
/// - Removing all profile data
/// - Leaving all rooms (and forgets all of them)
pub async fn full_user_deactivate(
services: &Services,
user_id: &UserId,
all_joined_rooms: &[OwnedRoomId],
) -> Result {
services
.users
.deactivate_account(user_id)
.await
.ok();
super::update_displayname(services, user_id, None, all_joined_rooms).await;
super::update_avatar_url(services, user_id, None, None, all_joined_rooms).await;
services
.users
.all_profile_keys(user_id)
.ready_for_each(|(profile_key, _)| {
services
.users
.set_profile_key(user_id, &profile_key, None);
})
.await;
for room_id in all_joined_rooms {
let state_lock = services.rooms.state.mutex.lock(room_id).await;
let room_power_levels = services
.rooms
.state_accessor
.room_state_get_content::<RoomPowerLevelsEventContent>(
room_id,
&StateEventType::RoomPowerLevels,
"",
)
.await
.ok();
let user_can_demote_self =
room_power_levels
.as_ref()
.is_some_and(|power_levels_content| {
RoomPowerLevels::from(power_levels_content.clone())
.user_can_change_user_power_level(user_id, user_id)
}) || services
.rooms
.state_accessor
.room_state_get(room_id, &StateEventType::RoomCreate, "")
.await
.is_ok_and(|event| event.sender() == user_id);
if user_can_demote_self {
let mut power_levels_content = room_power_levels.unwrap_or_default();
power_levels_content.users.remove(user_id);
// ignore errors so deactivation doesn't fail
match services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(String::new(), &power_levels_content),
user_id,
room_id,
&state_lock,
)
.await
{
| Err(e) => {
warn!(%room_id, %user_id, "Failed to demote user's own power level: {e}");
},
| _ => {
info!("Demoted {user_id} in {room_id} as part of account deactivation");
},
}
}
}
super::leave_all_rooms(services, user_id)
.boxed()
.await;
Ok(())
}
+6 -15
View File
@@ -5,7 +5,7 @@ use ruma::{
OwnedServerName, RoomAliasId, RoomId,
api::client::alias::{create_alias, delete_alias, get_alias},
};
use tuwunel_core::{Err, Result, debug};
use tuwunel_core::{Err, Result, debug, err};
use tuwunel_service::Services;
use crate::Ruma;
@@ -19,7 +19,6 @@ pub(crate) async fn create_alias_route(
) -> Result<create_alias::v3::Response> {
let sender_user = body.sender_user();
services
.rooms
.alias
.appservice_checks(&body.room_alias, &body.appservice_info)
.await?;
@@ -27,15 +26,14 @@ pub(crate) async fn create_alias_route(
// this isn't apart of alias_checks or delete alias route because we should
// allow removing forbidden room aliases
if services
.globals
.forbidden_alias_names()
.config
.forbidden_alias_names
.is_match(body.room_alias.alias())
{
return Err!(Request(Forbidden("Room alias is forbidden.")));
}
if services
.rooms
.alias
.resolve_local_alias(&body.room_alias)
.await
@@ -45,7 +43,6 @@ pub(crate) async fn create_alias_route(
}
services
.rooms
.alias
.set_alias(&body.room_alias, &body.room_id, sender_user)?;
@@ -63,13 +60,11 @@ pub(crate) async fn delete_alias_route(
) -> Result<delete_alias::v3::Response> {
let sender_user = body.sender_user();
services
.rooms
.alias
.appservice_checks(&body.room_alias, &body.appservice_info)
.await?;
services
.rooms
.alias
.remove_alias(&body.room_alias, sender_user)
.await?;
@@ -88,14 +83,11 @@ pub(crate) async fn get_alias_route(
) -> Result<get_alias::v3::Response> {
let room_alias = body.body.room_alias;
let Ok((room_id, servers)) = services
.rooms
let (room_id, servers) = services
.alias
.resolve_alias(&room_alias, None)
.resolve_alias(&room_alias)
.await
else {
return Err!(Request(NotFound("Room with alias not found.")));
};
.map_err(|_| err!(Request(NotFound("Room with alias not found."))))?;
let servers = room_available_servers(&services, &room_id, &room_alias, servers).await;
debug!(?room_alias, ?room_id, "available servers: {servers:?}");
@@ -111,7 +103,6 @@ async fn room_available_servers(
) -> Vec<OwnedServerName> {
// find active servers in room state cache to suggest
let mut servers: Vec<OwnedServerName> = services
.rooms
.state_cache
.room_servers(room_id)
.map(ToOwned::to_owned)
+7 -5
View File
@@ -3,9 +3,12 @@ use std::collections::BTreeMap;
use axum::extract::State;
use ruma::{
RoomVersionId,
api::client::discovery::get_capabilities::{
self, Capabilities, GetLoginTokenCapability, RoomVersionStability,
RoomVersionsCapability, ThirdPartyIdChangesCapability,
api::client::discovery::{
get_capabilities,
get_capabilities::v3::{
Capabilities, GetLoginTokenCapability, ProfileFieldsCapability, RoomVersionStability,
RoomVersionsCapability, ThirdPartyIdChangesCapability,
},
},
};
use serde_json::json;
@@ -41,8 +44,7 @@ pub(crate) async fn get_capabilities_route(
enabled: services.server.config.login_via_existing_session,
};
// MSC4133 capability
capabilities.set("uk.tcpip.msc4133.profile_fields", json!({"enabled": true}))?;
capabilities.profile_fields = ProfileFieldsCapability::new(true).into();
capabilities.set(
"org.matrix.msc4267.forget_forced_upon_leave",
+10 -23
View File
@@ -38,7 +38,7 @@ pub(crate) async fn get_context_route(
let event_id = &body.event_id;
let filter = &body.filter;
if !services.rooms.metadata.exists(room_id).await {
if !services.metadata.exists(room_id).await {
return Err!(Request(Forbidden("Room does not exist to this server")));
}
@@ -50,19 +50,16 @@ pub(crate) async fn get_context_route(
.min(LIMIT_MAX);
let base_id = services
.rooms
.timeline
.get_pdu_id(event_id)
.map_err(|_| err!(Request(NotFound("Event not found."))));
let base_pdu = services
.rooms
.timeline
.get_pdu(event_id)
.map_err(|_| err!(Request(NotFound("Base event not found."))));
let visible = services
.rooms
.state_accessor
.user_can_see_event(sender_user, room_id, event_id)
.map(Ok);
@@ -74,7 +71,11 @@ pub(crate) async fn get_context_route(
}
if !visible {
debug_warn!(req_evt = ?event_id, ?base_id, ?room_id, "Event requested by {sender_user} but is not allowed to see it, returning 404");
debug_warn!(
req_evt = ?event_id, ?base_id, ?room_id,
"Event requested by {sender_user} but is not allowed to see it."
);
return Err!(Request(NotFound("Event not found.")));
}
@@ -83,7 +84,6 @@ pub(crate) async fn get_context_route(
let base_event = ignored_filter(&services, (base_count, base_pdu), sender_user);
let events_before = services
.rooms
.timeline
.pdus_rev(Some(sender_user), room_id, Some(base_count))
.ignore_err()
@@ -94,14 +94,13 @@ pub(crate) async fn get_context_route(
.collect();
let events_after = services
.rooms
.timeline
.pdus(Some(sender_user), room_id, Some(base_count))
.ignore_err()
.ready_filter_map(|item| event_filter(item, filter))
.wide_filter_map(|item| ignored_filter(&services, item, sender_user))
.wide_filter_map(|item| visibility_filter(&services, item, sender_user))
.take(limit / 2)
.take(limit.div_ceil(2))
.collect();
let (base_event, events_before, events_after): (_, Vec<_>, Vec<_>) =
@@ -135,18 +134,11 @@ pub(crate) async fn get_context_route(
.map_or_else(|| body.event_id.as_ref(), |pdu| pdu.event_id.as_ref());
let state_ids = services
.rooms
.state_accessor
.state
.pdu_shortstatehash(state_at)
.or_else(|_| {
services
.rooms
.state
.get_room_shortstatehash(room_id)
})
.or_else(|_| services.state.get_room_shortstatehash(room_id))
.map_ok(|shortstatehash| {
services
.rooms
.state_accessor
.state_full_ids(shortstatehash)
.map(Ok)
@@ -163,7 +155,6 @@ pub(crate) async fn get_context_route(
let shorteventids = state_ids.iter().map(ref_at!(1)).stream();
let lazy_loading_witnessed = lazy_loading_witnessed.unwrap_or_default();
let state: Vec<_> = services
.rooms
.short
.multi_get_statekey_from_short(shortstatekeys)
.zip(shorteventids)
@@ -182,11 +173,7 @@ pub(crate) async fn get_context_route(
Some(event_id)
})
.broad_filter_map(|event_id: &OwnedEventId| {
services
.rooms
.timeline
.get_pdu(event_id.as_ref())
.ok()
services.timeline.get_pdu(event_id.as_ref()).ok()
})
.map(Event::into_format)
.collect()
+8 -79
View File
@@ -3,16 +3,13 @@ use axum_client_ip::InsecureClientIp;
use futures::StreamExt;
use ruma::{
MilliSecondsSinceUnixEpoch, OwnedDeviceId,
api::client::{
device::{self, delete_device, delete_devices, get_device, get_devices, update_device},
error::ErrorKind,
uiaa::{AuthFlow, AuthType, UiaaInfo},
api::client::device::{
self, delete_device, delete_devices, get_device, get_devices, update_device,
},
};
use tuwunel_core::{Err, Error, Result, debug, err, utils};
use tuwunel_core::{Err, Result, debug, err, utils};
use super::SESSION_ID_LENGTH;
use crate::{Ruma, client::DEVICE_ID_LENGTH};
use crate::{Ruma, client::DEVICE_ID_LENGTH, router::auth_uiaa};
/// # `GET /_matrix/client/r0/devices`
///
@@ -126,10 +123,10 @@ pub(crate) async fn delete_device_route(
State(services): State<crate::State>,
body: Ruma<delete_device::v3::Request>,
) -> Result<delete_device::v3::Response> {
let (sender_user, sender_device) = body.sender();
let appservice = body.appservice_info.as_ref();
if appservice.is_some_and(|appservice| appservice.registration.device_management) {
let sender_user = body.sender_user();
debug!(
"Skipping UIAA for {sender_user} as this is from an appservice and MSC4190 is \
enabled"
@@ -142,41 +139,7 @@ pub(crate) async fn delete_device_route(
return Ok(delete_device::v3::Response {});
}
// UIAA
let mut uiaainfo = UiaaInfo {
flows: vec![AuthFlow { stages: vec![AuthType::Password] }],
completed: Vec::new(),
params: Box::default(),
session: None,
auth_error: None,
};
match &body.auth {
| Some(auth) => {
let (worked, uiaainfo) = services
.uiaa
.try_auth(sender_user, sender_device, auth, &uiaainfo)
.await?;
if !worked {
return Err!(Uiaa(uiaainfo));
}
// Success!
},
| _ => match body.json_body {
| Some(ref json) => {
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
services
.uiaa
.create(sender_user, sender_device, &uiaainfo, json);
return Err!(Uiaa(uiaainfo));
},
| _ => {
return Err!(Request(NotJson("Not json.")));
},
},
}
let ref sender_user = auth_uiaa(&services, &body).await?;
services
.users
@@ -203,10 +166,10 @@ pub(crate) async fn delete_devices_route(
State(services): State<crate::State>,
body: Ruma<delete_devices::v3::Request>,
) -> Result<delete_devices::v3::Response> {
let (sender_user, sender_device) = body.sender();
let appservice = body.appservice_info.as_ref();
if appservice.is_some_and(|appservice| appservice.registration.device_management) {
let sender_user = body.sender_user();
debug!(
"Skipping UIAA for {sender_user} as this is from an appservice and MSC4190 is \
enabled"
@@ -221,41 +184,7 @@ pub(crate) async fn delete_devices_route(
return Ok(delete_devices::v3::Response {});
}
// UIAA
let mut uiaainfo = UiaaInfo {
flows: vec![AuthFlow { stages: vec![AuthType::Password] }],
completed: Vec::new(),
params: Box::default(),
session: None,
auth_error: None,
};
match &body.auth {
| Some(auth) => {
let (worked, uiaainfo) = services
.uiaa
.try_auth(sender_user, sender_device, auth, &uiaainfo)
.await?;
if !worked {
return Err(Error::Uiaa(uiaainfo));
}
// Success!
},
| _ => match body.json_body {
| Some(ref json) => {
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
services
.uiaa
.create(sender_user, sender_device, &uiaainfo, json);
return Err(Error::Uiaa(uiaainfo));
},
| _ => {
return Err(Error::BadRequest(ErrorKind::NotJson, "Not json."));
},
},
}
let ref sender_user = auth_uiaa(&services, &body).await?;
for device_id in &body.devices {
services
+50 -73
View File
@@ -16,18 +16,15 @@ use ruma::{
},
federation,
},
directory::{Filter, PublicRoomJoinRule, PublicRoomsChunk, RoomNetwork, RoomTypeFilter},
directory::{Filter, PublicRoomsChunk, RoomNetwork, RoomTypeFilter},
events::{
StateEventType,
room::{
join_rules::{JoinRule, RoomJoinRulesEventContent},
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
},
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
},
uint,
};
use tuwunel_core::{
Err, Result, err, info,
Err, Result, err, info, is_true,
matrix::Event,
utils::{
TryFutureExtExt,
@@ -51,7 +48,7 @@ pub(crate) async fn get_public_rooms_filtered_route(
InsecureClientIp(client): InsecureClientIp,
body: Ruma<get_public_rooms_filtered::v3::Request>,
) -> Result<get_public_rooms_filtered::v3::Response> {
check_banned(&services, body.server.as_deref())?;
check_server_banned(&services, body.server.as_deref())?;
let response = get_public_rooms_filtered_helper(
&services,
@@ -80,7 +77,7 @@ pub(crate) async fn get_public_rooms_route(
InsecureClientIp(client): InsecureClientIp,
body: Ruma<get_public_rooms::v3::Request>,
) -> Result<get_public_rooms::v3::Response> {
check_banned(&services, body.server.as_deref())?;
check_server_banned(&services, body.server.as_deref())?;
let response = get_public_rooms_filtered_helper(
&services,
@@ -114,12 +111,7 @@ pub(crate) async fn set_room_visibility_route(
) -> Result<set_room_visibility::v3::Response> {
let sender_user = body.sender_user();
if !services
.rooms
.metadata
.exists(&body.room_id)
.await
{
if !services.metadata.exists(&body.room_id).await {
// Return 404 if the room doesn't exist
return Err!(Request(NotFound("Room not found")));
}
@@ -169,7 +161,7 @@ pub(crate) async fn set_room_visibility_route(
)));
}
services.rooms.directory.set_public(&body.room_id);
services.directory.set_public(&body.room_id);
if services.server.config.admin_room_notices {
services
@@ -182,10 +174,7 @@ pub(crate) async fn set_room_visibility_route(
}
info!("{sender_user} made {0} public to the room directory", body.room_id);
},
| room::Visibility::Private => services
.rooms
.directory
.set_not_public(&body.room_id),
| room::Visibility::Private => services.directory.set_not_public(&body.room_id),
| _ => {
return Err!(Request(InvalidParam("Room visibility type is not supported.",)));
},
@@ -201,19 +190,13 @@ pub(crate) async fn get_room_visibility_route(
State(services): State<crate::State>,
body: Ruma<get_room_visibility::v3::Request>,
) -> Result<get_room_visibility::v3::Response> {
if !services
.rooms
.metadata
.exists(&body.room_id)
.await
{
if !services.metadata.exists(&body.room_id).await {
// Return 404 if the room doesn't exist
return Err!(Request(NotFound("Room not found")));
}
Ok(get_room_visibility::v3::Response {
visibility: if services
.rooms
.directory
.is_public_room(&body.room_id)
.await
@@ -298,13 +281,12 @@ pub(crate) async fn get_public_rooms_filtered_helper(
let meta_public_rooms = search_room_id
.filter(|_| services.config.allow_unlisted_room_search_by_id)
.map(|prefix| services.rooms.metadata.public_ids_prefix(prefix))
.map(|prefix| services.metadata.public_ids_prefix(prefix))
.into_iter()
.stream()
.flatten();
let mut all_rooms: Vec<PublicRoomsChunk> = services
.rooms
.directory
.public_rooms()
.map(ToOwned::to_owned)
@@ -391,20 +373,14 @@ async fn user_can_publish_room(
room_id: &RoomId,
) -> Result<bool> {
match services
.rooms
.state_accessor
.room_state_get(room_id, &StateEventType::RoomPowerLevels, "")
.get_power_levels(room_id)
.await
{
| Ok(event) => serde_json::from_str(event.content().get())
.map_err(|_| err!(Database("Invalid event content for m.room.power_levels")))
.map(|content: RoomPowerLevelsEventContent| {
RoomPowerLevels::from(content)
.user_can_send_state(user_id, StateEventType::RoomHistoryVisibility)
}),
| Ok(power_levels) =>
Ok(power_levels.user_can_send_state(user_id, StateEventType::RoomHistoryVisibility)),
| _ => {
match services
.rooms
.state_accessor
.room_state_get(room_id, &StateEventType::RoomCreate, "")
.await
@@ -417,57 +393,57 @@ async fn user_can_publish_room(
}
async fn public_rooms_chunk(services: &Services, room_id: OwnedRoomId) -> PublicRoomsChunk {
let name = services
.rooms
.state_accessor
.get_name(&room_id)
.ok();
let name = services.state_accessor.get_name(&room_id).ok();
let room_type = services
.rooms
.state_accessor
.get_room_type(&room_id)
.ok();
let canonical_alias = services
.rooms
.state_accessor
.get_canonical_alias(&room_id)
.ok()
.then(async |alias| {
if let Some(alias) = alias
&& services.globals.alias_is_local(&alias)
&& let Ok(alias_room_id) = services.alias.resolve_local_alias(&alias).await
&& alias_room_id == room_id
{
Some(alias)
} else {
None
}
});
let avatar_url = services
.state_accessor
.get_avatar(&room_id)
.map_ok(|content| content.url)
.ok();
let avatar_url = services.rooms.state_accessor.get_avatar(&room_id);
let topic = services
.rooms
.state_accessor
.get_room_topic(&room_id)
.ok();
let world_readable = services
.rooms
.state_accessor
.is_world_readable(&room_id);
let join_rule = services
.rooms
.state_accessor
.room_state_get_content(&room_id, &StateEventType::RoomJoinRules, "")
.map_ok(|c: RoomJoinRulesEventContent| match c.join_rule {
| JoinRule::Public => PublicRoomJoinRule::Public,
| JoinRule::Public => "public".into(),
| JoinRule::Knock => "knock".into(),
| JoinRule::KnockRestricted(_) => "knock_restricted".into(),
| _ => "invite".into(),
});
let guest_can_join = services
.rooms
.state_accessor
.guest_can_join(&room_id);
let guest_can_join = services.state_accessor.guest_can_join(&room_id);
let num_joined_members = services
.rooms
.state_cache
.room_joined_count(&room_id);
let num_joined_members = services.state_cache.room_joined_count(&room_id);
let (
(avatar_url, canonical_alias, guest_can_join, join_rule, name),
@@ -480,7 +456,7 @@ async fn public_rooms_chunk(services: &Services, room_id: OwnedRoomId) -> Public
.await;
PublicRoomsChunk {
avatar_url: avatar_url.into_option().unwrap_or_default().url,
avatar_url: avatar_url.flatten(),
canonical_alias,
guest_can_join,
join_rule: join_rule.unwrap_or_default(),
@@ -497,24 +473,25 @@ async fn public_rooms_chunk(services: &Services, room_id: OwnedRoomId) -> Public
}
}
fn check_banned(services: &Services, server: Option<&ServerName>) -> Result {
fn check_server_banned(services: &Services, server: Option<&ServerName>) -> Result {
let Some(server) = server else {
return Ok(());
};
let forbidden_remote_directory = services
.config
.forbidden_remote_room_directory_server_names
.is_match(server.host());
let conditions = [
services
.config
.forbidden_remote_room_directory_server_names
.is_match(server.host()),
services
.config
.forbidden_remote_server_names
.is_match(server.host()),
];
let forbidden_remote_server = services
.config
.forbidden_remote_server_names
.is_match(server.host());
if forbidden_remote_directory || forbidden_remote_server {
Err!(Request(Forbidden("Server is banned on this homeserver.")))
} else {
Ok(())
if conditions.iter().any(is_true!()) {
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
}
Ok(())
}
+57 -79
View File
@@ -3,16 +3,13 @@ use std::collections::{BTreeMap, HashMap, HashSet};
use axum::extract::State;
use futures::{StreamExt, stream::FuturesUnordered};
use ruma::{
OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId, UserId,
CanonicalJsonObject, CanonicalJsonValue, OneTimeKeyAlgorithm, OwnedDeviceId, OwnedUserId,
UserId,
api::{
client::{
error::ErrorKind,
keys::{
claim_keys, get_key_changes, get_keys, upload_keys,
upload_signatures::{self},
upload_signing_keys,
},
uiaa::{AuthFlow, AuthType, UiaaInfo},
client::keys::{
claim_keys, get_key_changes, get_keys, upload_keys,
upload_signatures::{self},
upload_signing_keys,
},
federation,
},
@@ -20,11 +17,12 @@ use ruma::{
serde::Raw,
};
use serde_json::json;
use tuwunel_core::{Err, Error, Result, debug, debug_warn, err, result::NotFound, utils};
use tuwunel_core::{
Err, Result, debug, debug_error, debug_warn, err, result::NotFound, utils::json,
};
use tuwunel_service::{Services, users::parse_master_key};
use super::SESSION_ID_LENGTH;
use crate::Ruma;
use crate::{Ruma, router::auth_uiaa};
/// # `POST /_matrix/client/r0/keys/upload`
///
@@ -39,7 +37,11 @@ pub(crate) async fn upload_keys_route(
) -> Result<upload_keys::v3::Response> {
let (sender_user, sender_device) = body.sender();
for (key_id, one_time_key) in &body.one_time_keys {
for (key_id, one_time_key) in body
.one_time_keys
.iter()
.take(services.config.one_time_key_limit)
{
if one_time_key
.deserialize()
.inspect_err(|e| {
@@ -157,26 +159,17 @@ pub(crate) async fn upload_signing_keys_route(
State(services): State<crate::State>,
body: Ruma<upload_signing_keys::v3::Request>,
) -> Result<upload_signing_keys::v3::Response> {
let (sender_user, sender_device) = body.sender();
// UIAA
let mut uiaainfo = UiaaInfo {
flows: vec![AuthFlow { stages: vec![AuthType::Password] }],
completed: Vec::new(),
params: Box::default(),
session: None,
auth_error: None,
};
// Access token is required for this endpoint regardless of conditional UIAA so
// we'll always have a sender_user.
match check_for_new_keys(
services,
sender_user,
body.sender_user(),
body.self_signing_key.as_ref(),
body.user_signing_key.as_ref(),
body.master_key.as_ref(),
)
.await
.inspect_err(|e| debug!(?e))
.inspect_err(|e| debug_error!(?e))
{
| Ok(exists) => {
if let Some(result) = exists {
@@ -184,45 +177,25 @@ pub(crate) async fn upload_signing_keys_route(
// (lost connection for example)
return Ok(result);
}
debug!(
"Skipping UIA in accordance with MSC3967, the user didn't have any existing keys"
);
// Some of the keys weren't found, so we let them upload
debug!("Skipping UIA in accordance with MSC3967, user had no existing keys");
},
| _ => {
match &body.auth {
| Some(auth) => {
let (worked, uiaainfo) = services
.uiaa
.try_auth(sender_user, sender_device, auth, &uiaainfo)
.await?;
if !worked {
return Err(Error::Uiaa(uiaainfo));
}
// Success!
},
| _ => match body.json_body.as_ref() {
| Some(json) => {
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
services
.uiaa
.create(sender_user, sender_device, &uiaainfo, json);
return Err(Error::Uiaa(uiaainfo));
},
| _ => {
return Err(Error::BadRequest(ErrorKind::NotJson, "Not json."));
},
},
}
let authed_user = auth_uiaa(&services, &body).await?;
assert_eq!(
body.sender_user(),
authed_user,
"Expected UIAA of {0} and not {authed_user}",
body.sender_user(),
);
},
}
services
.users
.add_cross_signing_keys(
sender_user,
body.sender_user(),
&body.master_key,
&body.self_signing_key,
&body.user_signing_key,
@@ -248,6 +221,7 @@ async fn check_for_new_keys(
.users
.get_master_key(None, user_id, &|_| true)
.await;
if result.is_not_found() {
empty = true;
} else {
@@ -260,6 +234,7 @@ async fn check_for_new_keys(
}
}
}
if let Some(user_signing_key) = user_signing_key {
let key = services.users.get_user_signing_key(user_id).await;
if key.is_not_found() && !empty {
@@ -267,6 +242,7 @@ async fn check_for_new_keys(
"Tried to update an existing user signing key, UIA required"
)));
}
if !key.is_not_found() {
let existing_signing_key = key?.deserialize()?;
if existing_signing_key != user_signing_key.deserialize()? {
@@ -276,17 +252,20 @@ async fn check_for_new_keys(
}
}
}
if let Some(self_signing_key) = self_signing_key {
let key = services
.users
.get_self_signing_key(None, user_id, &|_| true)
.await;
if key.is_not_found() && !empty {
debug!(?key);
debug_error!(?key);
return Err!(Request(Forbidden(
"Tried to add a new signing key independently from the master key"
)));
}
if !key.is_not_found() {
let existing_signing_key = key?.deserialize()?;
if existing_signing_key != self_signing_key.deserialize()? {
@@ -296,6 +275,7 @@ async fn check_for_new_keys(
}
}
}
if empty {
return Ok(None);
}
@@ -379,12 +359,12 @@ pub(crate) async fn get_key_changes_route(
let from = body
.from
.parse()
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from`."))?;
.map_err(|_| err!(Request(InvalidParam("Invalid `from`."))))?;
let to = body
.to
.parse()
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `to`."))?;
.map_err(|_| err!(Request(InvalidParam("Invalid `to`."))))?;
device_list_updates.extend(
services
@@ -396,7 +376,6 @@ pub(crate) async fn get_key_changes_route(
);
let mut rooms_joined = services
.rooms
.state_cache
.rooms_joined(sender_user)
.boxed();
@@ -560,16 +539,16 @@ where
.signatures
.append(&mut our_master_key.signatures);
}
let json = serde_json::to_value(master_key).expect("to_value always works");
let raw = serde_json::from_value(json).expect("Raw::from_value always works");
// Dont notify. A notification would trigger another key request resulting in
// an endless loop.
let notify = false;
let raw = Some(json::to_raw(master_key)?);
services
.users
.add_cross_signing_keys(
&user, &raw, &None, &None,
false, /* Dont notify. A notification would trigger another key
* request resulting in an endless loop */
)
.add_cross_signing_keys(&user, &raw, &None, &None, notify)
.await?;
if let Some(raw) = raw {
master_keys.insert(user.clone(), raw);
}
@@ -599,20 +578,19 @@ fn add_unsigned_device_display_name(
include_display_names: bool,
) -> Result {
if let Some(display_name) = metadata.display_name {
let mut object = keys.deserialize_as::<serde_json::Map<String, serde_json::Value>>()?;
let mut object = keys.deserialize_as_unchecked::<CanonicalJsonObject>()?;
let unsigned = object
.entry("unsigned")
.or_insert_with(|| json!({}));
if let serde_json::Value::Object(unsigned_object) = unsigned {
if include_display_names {
unsigned_object.insert("device_display_name".to_owned(), display_name.into());
if let CanonicalJsonValue::Object(unsigned) = object
.entry("unsigned".into())
.or_insert_with(|| CanonicalJsonObject::default().into())
{
let display_name = if include_display_names {
CanonicalJsonValue::String(display_name)
} else {
unsigned_object.insert(
"device_display_name".to_owned(),
Some(metadata.device_id.as_str().to_owned()).into(),
);
}
CanonicalJsonValue::String(metadata.device_id.into())
};
unsigned.insert("device_display_name".into(), display_name);
}
*keys = Raw::from_json(serde_json::value::to_raw_value(&object)?);
+7 -35
View File
@@ -1,9 +1,7 @@
use axum::extract::State;
use ruma::{
api::client::membership::ban_user,
events::room::member::{MembershipState, RoomMemberEventContent},
};
use tuwunel_core::{Err, Result, matrix::pdu::PduBuilder};
use futures::FutureExt;
use ruma::api::client::membership::ban_user;
use tuwunel_core::{Err, Result};
use crate::Ruma;
@@ -20,38 +18,12 @@ pub(crate) async fn ban_user_route(
return Err!(Request(Forbidden("You cannot ban yourself.")));
}
let state_lock = services
.rooms
.state
.mutex
.lock(&body.room_id)
.await;
let current_member_content = services
.rooms
.state_accessor
.get_member(&body.room_id, &body.user_id)
.await
.unwrap_or_else(|_| RoomMemberEventContent::new(MembershipState::Ban));
let state_lock = services.state.mutex.lock(&body.room_id).await;
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent {
membership: MembershipState::Ban,
reason: body.reason.clone(),
displayname: None, // display name may be offensive
avatar_url: None, // avatar may be offensive
is_direct: None,
join_authorized_via_users_server: None,
third_party_invite: None,
..current_member_content
}),
sender_user,
&body.room_id,
&state_lock,
)
.membership
.ban(&body.room_id, &body.user_id, body.reason.as_ref(), sender_user, &state_lock)
.boxed()
.await?;
drop(state_lock);
+4 -18
View File
@@ -21,18 +21,9 @@ pub(crate) async fn forget_room_route(
let user_id = body.sender_user();
let room_id = &body.room_id;
let joined = services
.rooms
.state_cache
.is_joined(user_id, room_id);
let knocked = services
.rooms
.state_cache
.is_knocked(user_id, room_id);
let invited = services
.rooms
.state_cache
.is_invited(user_id, room_id);
let joined = services.state_cache.is_joined(user_id, room_id);
let knocked = services.state_cache.is_knocked(user_id, room_id);
let invited = services.state_cache.is_invited(user_id, room_id);
pin_mut!(joined, knocked, invited);
if joined.or(knocked).or(invited).await {
@@ -40,7 +31,6 @@ pub(crate) async fn forget_room_route(
}
let membership = services
.rooms
.state_accessor
.get_member(room_id, user_id)
.await;
@@ -55,15 +45,11 @@ pub(crate) async fn forget_room_route(
if non_membership
|| services
.rooms
.state_cache
.is_left(user_id, room_id)
.await
{
services
.rooms
.state_cache
.forget(room_id, user_id);
services.state_cache.forget(room_id, user_id);
}
Ok(forget_room::v3::Response::new())
+50 -222
View File
@@ -1,19 +1,11 @@
use axum::extract::State;
use axum_client_ip::InsecureClientIp;
use futures::{FutureExt, join};
use ruma::{
OwnedServerName, RoomId, UserId,
api::{client::membership::invite_user, federation::membership::create_invite},
events::room::member::{MembershipState, RoomMemberEventContent},
};
use tuwunel_core::{
Err, Result, debug_error, err, info,
matrix::{event::gen_event_id_canonical_json, pdu::PduBuilder},
};
use tuwunel_service::Services;
use ruma::{api::client::membership::invite_user, events::room::member::MembershipState};
use tuwunel_core::{Err, Result};
use super::banned_room_check;
use crate::Ruma;
use crate::{Ruma, client::utils::invite_check};
/// # `POST /_matrix/client/r0/rooms/{roomId}/invite`
///
@@ -26,220 +18,56 @@ pub(crate) async fn invite_user_route(
) -> Result<invite_user::v3::Response> {
let sender_user = body.sender_user();
if !services.users.is_admin(sender_user).await && services.config.block_non_admin_invites {
debug_error!(
"User {sender_user} is not an admin and attempted to send an invite to room {}",
&body.room_id
);
return Err!(Request(Forbidden("Invites are not allowed on this server.")));
}
let room_id = &body.room_id;
banned_room_check(
&services,
sender_user,
Some(&body.room_id),
body.room_id.server_name(),
client,
)
.await?;
invite_check(&services, sender_user, room_id).await?;
match &body.recipient {
| invite_user::v3::InvitationRecipient::UserId { user_id } => {
let sender_ignored_recipient = services
.users
.user_is_ignored(sender_user, user_id);
let recipient_ignored_by_sender = services
.users
.user_is_ignored(user_id, sender_user);
let (sender_ignored_recipient, recipient_ignored_by_sender) =
join!(sender_ignored_recipient, recipient_ignored_by_sender);
if sender_ignored_recipient {
return Ok(invite_user::v3::Response {});
}
if let Ok(target_user_membership) = services
.rooms
.state_accessor
.get_member(&body.room_id, user_id)
.await
{
if target_user_membership.membership == MembershipState::Ban {
return Err!(Request(Forbidden("User is banned from this room.")));
}
}
if recipient_ignored_by_sender {
// silently drop the invite to the recipient if they've been ignored by the
// sender, pretend it worked
return Ok(invite_user::v3::Response {});
}
invite_helper(
&services,
sender_user,
user_id,
&body.room_id,
body.reason.clone(),
false,
)
.boxed()
.await?;
Ok(invite_user::v3::Response {})
},
| _ => {
Err!(Request(NotFound("User not found.")))
},
}
}
pub(crate) async fn invite_helper(
services: &Services,
sender_user: &UserId,
user_id: &UserId,
room_id: &RoomId,
reason: Option<String>,
is_direct: bool,
) -> Result {
if !services.users.is_admin(sender_user).await && services.config.block_non_admin_invites {
info!(
"User {sender_user} is not an admin and attempted to send an invite to room \
{room_id}"
);
return Err!(Request(Forbidden("Invites are not allowed on this server.")));
}
if !services.globals.user_is_local(user_id) {
let (pdu, pdu_json, invite_room_state) = {
let state_lock = services.rooms.state.mutex.lock(room_id).await;
let content = RoomMemberEventContent {
avatar_url: services.users.avatar_url(user_id).await.ok(),
is_direct: Some(is_direct),
reason,
..RoomMemberEventContent::new(MembershipState::Invite)
};
let (pdu, pdu_json) = services
.rooms
.timeline
.create_hash_and_sign_event(
PduBuilder::state(user_id.to_string(), &content),
sender_user,
room_id,
&state_lock,
)
.await?;
let invite_room_state = services.rooms.state.summary_stripped(&pdu).await;
drop(state_lock);
(pdu, pdu_json, invite_room_state)
};
let room_version_id = services
.rooms
.state
.get_room_version(room_id)
.await?;
let response = services
.sending
.send_federation_request(user_id.server_name(), create_invite::v2::Request {
room_id: room_id.to_owned(),
event_id: (*pdu.event_id).to_owned(),
room_version: room_version_id.clone(),
event: services
.sending
.convert_to_outgoing_federation_event(pdu_json.clone())
.await,
invite_room_state,
via: services
.rooms
.state_cache
.servers_route_via(room_id)
.await
.ok(),
})
.await?;
// We do not add the event_id field to the pdu here because of signature and
// hashes checks
let (event_id, value) = gen_event_id_canonical_json(&response.event, &room_version_id)
.map_err(|e| {
err!(Request(BadJson(warn!("Could not convert event to canonical JSON: {e}"))))
})?;
if pdu.event_id != event_id {
return Err!(Request(BadJson(warn!(
%pdu.event_id, %event_id,
"Server {} sent event with wrong event ID",
user_id.server_name()
))));
}
let origin: OwnedServerName = serde_json::from_value(serde_json::to_value(
value
.get("origin")
.ok_or_else(|| err!(Request(BadJson("Event missing origin field."))))?,
)?)
.map_err(|e| {
err!(Request(BadJson(warn!("Origin field in event is not a valid server name: {e}"))))
})?;
let pdu_id = services
.rooms
.event_handler
.handle_incoming_pdu(&origin, room_id, &event_id, value, true)
.boxed()
.await?
.ok_or_else(|| {
err!(Request(InvalidParam("Could not accept incoming PDU as timeline event.")))
})?;
return services
.sending
.send_pdu_room(room_id, &pdu_id)
.await;
}
if !services
.rooms
.state_cache
.is_joined(sender_user, room_id)
.await
{
return Err!(Request(Forbidden(
"You must be joined in the room you are trying to invite from."
)));
}
let state_lock = services.rooms.state.mutex.lock(room_id).await;
let content = RoomMemberEventContent {
displayname: services.users.displayname(user_id).await.ok(),
avatar_url: services.users.avatar_url(user_id).await.ok(),
blurhash: services.users.blurhash(user_id).await.ok(),
is_direct: Some(is_direct),
reason,
..RoomMemberEventContent::new(MembershipState::Invite)
};
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(user_id.to_string(), &content),
sender_user,
room_id,
&state_lock,
)
banned_room_check(&services, sender_user, Some(room_id), room_id.server_name(), client)
.await?;
drop(state_lock);
let invite_user::v3::InvitationRecipient::UserId { user_id } = &body.recipient else {
return Err!(Request(ThreepidDenied("Third party identifiers are not implemented")));
};
Ok(())
let sender_ignored_recipient = services
.users
.user_is_ignored(sender_user, user_id);
let recipient_ignored_by_sender = services
.users
.user_is_ignored(user_id, sender_user);
let (sender_ignored_recipient, recipient_ignored_by_sender) =
join!(sender_ignored_recipient, recipient_ignored_by_sender);
if sender_ignored_recipient {
return Ok(invite_user::v3::Response {});
}
// TODO: this should be in the service, but moving it from here would
// trigger the recipient_ignored_by_sender check before the banned check,
// revealing the ignore state to the sending user if the recipient is banned
if let Ok(target_user_membership) = services
.state_accessor
.get_member(room_id, user_id)
.await
{
if target_user_membership.membership == MembershipState::Ban {
return Err!(Request(Forbidden("User is banned from this room.")));
}
}
if recipient_ignored_by_sender {
// silently drop the invite to the recipient if they've been ignored by the
// sender, pretend it worked
return Ok(invite_user::v3::Response {});
}
services
.membership
.invite(sender_user, user_id, room_id, body.reason.as_ref(), false)
.boxed()
.await?;
Ok(invite_user::v3::Response {})
}
File diff suppressed because it is too large. Load diff
+11 -45
View File
@@ -1,9 +1,7 @@
use axum::extract::State;
use ruma::{
api::client::membership::kick_user,
events::room::member::{MembershipState, RoomMemberEventContent},
};
use tuwunel_core::{Err, Result, matrix::pdu::PduBuilder};
use futures::FutureExt;
use ruma::api::client::membership::kick_user;
use tuwunel_core::{Err, Result};
use crate::Ruma;
@@ -14,50 +12,18 @@ pub(crate) async fn kick_user_route(
State(services): State<crate::State>,
body: Ruma<kick_user::v3::Request>,
) -> Result<kick_user::v3::Response> {
let state_lock = services
.rooms
.state
.mutex
.lock(&body.room_id)
.await;
let sender_user = body.sender_user();
let Ok(event) = services
.rooms
.state_accessor
.get_member(&body.room_id, &body.user_id)
.await
else {
// copy synapse's behaviour of returning 200 without any change to the state
// instead of erroring on left users
return Ok(kick_user::v3::Response::new());
};
if !matches!(
event.membership,
MembershipState::Invite | MembershipState::Knock | MembershipState::Join,
) {
return Err!(Request(Forbidden(
"Cannot kick a user who is not apart of the room (current membership: {})",
event.membership
)));
if sender_user == body.user_id {
return Err!(Request(Forbidden("You cannot kick yourself.")));
}
let state_lock = services.state.mutex.lock(&body.room_id).await;
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent {
membership: MembershipState::Leave,
reason: body.reason.clone(),
is_direct: None,
join_authorized_via_users_server: None,
third_party_invite: None,
..event
}),
body.sender_user(),
&body.room_id,
&state_lock,
)
.membership
.kick(&body.room_id, &body.user_id, body.reason.as_ref(), sender_user, &state_lock)
.boxed()
.await?;
drop(state_lock);
+50 -136
View File
@@ -4,11 +4,14 @@ use axum::extract::State;
use axum_client_ip::InsecureClientIp;
use futures::{FutureExt, StreamExt};
use ruma::{
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedServerName, RoomId,
CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedServerName, RoomId,
RoomVersionId, UserId,
api::{
client::knock::knock_room,
federation::{self},
federation::{
membership::RawStrippedState,
{self},
},
},
canonical_json::to_canonical_value,
events::{
@@ -17,14 +20,14 @@ use ruma::{
},
};
use tuwunel_core::{
Err, Result, debug, debug_info, debug_warn, err, info,
Err, Result, debug, debug_info, debug_warn, err, extract_variant, info,
matrix::{
PduCount,
event::{Event, gen_event_id},
pdu::{PduBuilder, PduEvent},
},
result::FlatOk,
trace,
utils::{self, shuffle, stream::IterStream},
utils::{self},
warn,
};
use tuwunel_service::{
@@ -36,7 +39,7 @@ use tuwunel_service::{
};
use super::banned_room_check;
use crate::Ruma;
use crate::{Ruma, client::membership::get_join_params};
/// # `POST /_matrix/client/*/knock/{roomIdOrAlias}`
///
@@ -50,102 +53,13 @@ pub(crate) async fn knock_room_route(
let sender_user = body.sender_user();
let body = &body.body;
let (servers, room_id) = match OwnedRoomId::try_from(body.room_id_or_alias.clone()) {
| Ok(room_id) => {
banned_room_check(
&services,
sender_user,
Some(&room_id),
room_id.server_name(),
client,
)
.await?;
let (room_id, servers) =
get_join_params(&services, sender_user, &body.room_id_or_alias, &body.via).await?;
let mut servers = body.via.clone();
servers.extend(
services
.rooms
.state_cache
.servers_invite_via(&room_id)
.map(ToOwned::to_owned)
.collect::<Vec<_>>()
.await,
);
banned_room_check(&services, sender_user, Some(&room_id), room_id.server_name(), client)
.await?;
servers.extend(
services
.rooms
.state_cache
.invite_state(sender_user, &room_id)
.await
.unwrap_or_default()
.iter()
.filter_map(|event| event.get_field("sender").ok().flatten())
.filter_map(|sender: &str| UserId::parse(sender).ok())
.map(|user| user.server_name().to_owned()),
);
if let Some(server) = room_id.server_name() {
servers.push(server.to_owned());
}
servers.sort_unstable();
servers.dedup();
shuffle(&mut servers);
(servers, room_id)
},
| Err(room_alias) => {
let (room_id, mut servers) = services
.rooms
.alias
.resolve_alias(&room_alias, Some(body.via.clone()))
.await?;
banned_room_check(
&services,
sender_user,
Some(&room_id),
Some(room_alias.server_name()),
client,
)
.await?;
let addl_via_servers = services
.rooms
.state_cache
.servers_invite_via(&room_id)
.map(ToOwned::to_owned);
let addl_state_servers = services
.rooms
.state_cache
.invite_state(sender_user, &room_id)
.await
.unwrap_or_default();
let mut addl_servers: Vec<_> = addl_state_servers
.iter()
.map(|event| event.get_field("sender"))
.filter_map(FlatOk::flat_ok)
.map(|user: &UserId| user.server_name().to_owned())
.stream()
.chain(addl_via_servers)
.collect()
.await;
addl_servers.sort_unstable();
addl_servers.dedup();
shuffle(&mut addl_servers);
servers.append(&mut addl_servers);
(servers, room_id)
},
};
knock_room_by_id_helper(&services, sender_user, &room_id, body.reason.clone(), &servers)
.boxed()
.await
knock_room_by_id_helper(&services, sender_user, &room_id, body.reason.clone(), &servers).await
}
async fn knock_room_by_id_helper(
@@ -155,10 +69,9 @@ async fn knock_room_by_id_helper(
reason: Option<String>,
servers: &[OwnedServerName],
) -> Result<knock_room::v3::Response> {
let state_lock = services.rooms.state.mutex.lock(room_id).await;
let state_lock = services.state.mutex.lock(room_id).await;
if services
.rooms
.state_cache
.is_invited(sender_user, room_id)
.await
@@ -170,7 +83,6 @@ async fn knock_room_by_id_helper(
}
if services
.rooms
.state_cache
.is_joined(sender_user, room_id)
.await
@@ -180,7 +92,6 @@ async fn knock_room_by_id_helper(
}
if services
.rooms
.state_cache
.is_knocked(sender_user, room_id)
.await
@@ -190,7 +101,6 @@ async fn knock_room_by_id_helper(
}
if let Ok(membership) = services
.rooms
.state_accessor
.get_member(room_id, sender_user)
.await
@@ -202,7 +112,6 @@ async fn knock_room_by_id_helper(
}
let server_in_room = services
.rooms
.state_cache
.server_in_room(services.globals.server_name(), room_id)
.await;
@@ -234,11 +143,7 @@ async fn knock_room_helper_local(
) -> Result {
debug_info!("We can knock locally");
let room_version_id = services
.rooms
.state
.get_room_version(room_id)
.await?;
let room_version_id = services.state.get_room_version(room_id).await?;
if matches!(
room_version_id,
@@ -262,7 +167,6 @@ async fn knock_room_helper_local(
// Try normal knock first
let Err(error) = services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(sender_user.to_string(), &content),
@@ -346,12 +250,12 @@ async fn knock_room_helper_local(
let knock_event = knock_event_stub;
info!("Asking {remote_server} for send_knock in room {room_id}");
let send_knock_request = federation::knock::send_knock::v1::Request {
let send_knock_request = federation::membership::create_knock_event::v1::Request {
room_id: room_id.to_owned(),
event_id: event_id.clone(),
pdu: services
.sending
.convert_to_outgoing_federation_event(knock_event.clone())
.federation
.format_pdu_into(knock_event.clone(), Some(&room_version_id))
.await,
};
@@ -363,7 +267,6 @@ async fn knock_room_helper_local(
info!("send_knock finished");
services
.rooms
.short
.get_or_create_shortroomid(room_id)
.await;
@@ -374,8 +277,8 @@ async fn knock_room_helper_local(
.map_err(|e| err!(BadServerResponse("Invalid knock event PDU: {e:?}")))?;
info!("Updating membership locally to knock state with provided stripped state events");
let count = services.globals.next_count();
services
.rooms
.state_cache
.update_membership(
room_id,
@@ -384,15 +287,21 @@ async fn knock_room_helper_local(
.get_content::<RoomMemberEventContent>()
.expect("we just created this"),
sender_user,
Some(send_knock_response.knock_room_state),
Some(
send_knock_response
.knock_room_state
.into_iter()
.filter_map(|s| extract_variant!(s, RawStrippedState::Stripped))
.collect(),
),
None,
false,
PduCount::Normal(*count),
)
.await?;
info!("Appending room knock event locally");
services
.rooms
.timeline
.append_pdu(
&parsed_knock_pdu,
@@ -477,12 +386,12 @@ async fn knock_room_helper_remote(
let knock_event = knock_event_stub;
info!("Asking {remote_server} for send_knock in room {room_id}");
let send_knock_request = federation::knock::send_knock::v1::Request {
let send_knock_request = federation::membership::create_knock_event::v1::Request {
room_id: room_id.to_owned(),
event_id: event_id.clone(),
pdu: services
.sending
.convert_to_outgoing_federation_event(knock_event.clone())
.federation
.format_pdu_into(knock_event.clone(), Some(&room_version_id))
.await,
};
@@ -494,7 +403,6 @@ async fn knock_room_helper_remote(
info!("send_knock finished");
services
.rooms
.short
.get_or_create_shortroomid(room_id)
.await;
@@ -507,7 +415,14 @@ async fn knock_room_helper_remote(
let state = send_knock_response
.knock_room_state
.iter()
.map(|event| serde_json::from_str::<CanonicalJsonObject>(event.clone().into_json().get()))
.map(|event| {
serde_json::from_str::<CanonicalJsonObject>(
extract_variant!(event.clone(), RawStrippedState::Stripped)
.expect("Raw<AnyStrippedStateEvent>")
.json()
.get(),
)
})
.filter_map(Result::ok);
let mut state_map: HashMap<u64, OwnedEventId> = HashMap::new();
@@ -534,13 +449,11 @@ async fn knock_room_helper_remote(
let event_id = gen_event_id(&event, &room_version_id)?;
let shortstatekey = services
.rooms
.short
.get_or_create_shortstatekey(&event_type, &state_key)
.await;
services
.rooms
.timeline
.add_pdu_outlier(&event_id, &event);
@@ -549,7 +462,6 @@ async fn knock_room_helper_remote(
info!("Compressing state from send_knock");
let compressed: CompressedState = services
.rooms
.state_compressor
.compress_state_events(
state_map
@@ -565,27 +477,24 @@ async fn knock_room_helper_remote(
added,
removed,
} = services
.rooms
.state_compressor
.save_state(room_id, Arc::new(compressed))
.await?;
debug!("Forcing state for new room");
services
.rooms
.state
.force_state(room_id, statehash_before_knock, added, removed, &state_lock)
.await?;
let statehash_after_knock = services
.rooms
.state
.append_to_state(&parsed_knock_pdu)
.await?;
info!("Updating membership locally to knock state with provided stripped state events");
let count = services.globals.next_count();
services
.rooms
.state_cache
.update_membership(
room_id,
@@ -594,15 +503,21 @@ async fn knock_room_helper_remote(
.get_content::<RoomMemberEventContent>()
.expect("we just created this"),
sender_user,
Some(send_knock_response.knock_room_state),
Some(
send_knock_response
.knock_room_state
.into_iter()
.filter_map(|s| extract_variant!(s, RawStrippedState::Stripped))
.collect(),
),
None,
false,
PduCount::Normal(*count),
)
.await?;
info!("Appending room knock event locally");
services
.rooms
.timeline
.append_pdu(
&parsed_knock_pdu,
@@ -616,7 +531,6 @@ async fn knock_room_helper_remote(
// We set the room state after inserting the pdu, so that we never have a moment
// in time where events in the current room state do not exist
services
.rooms
.state
.set_room_state(room_id, statehash_after_knock, &state_lock);
@@ -628,7 +542,7 @@ async fn make_knock_request(
sender_user: &UserId,
room_id: &RoomId,
servers: &[OwnedServerName],
) -> Result<(federation::knock::create_knock_event_template::v1::Response, OwnedServerName)> {
) -> Result<(federation::membership::prepare_knock_event::v1::Response, OwnedServerName)> {
let mut make_knock_response_and_server =
Err!(BadServerResponse("No server available to assist in knocking."));
@@ -645,7 +559,7 @@ async fn make_knock_request(
.sending
.send_federation_request(
remote_server,
federation::knock::create_knock_event_template::v1::Request {
federation::membership::prepare_knock_event::v1::Request {
room_id: room_id.to_owned(),
user_id: sender_user.to_owned(),
ver: services
+17 -376
View File
@@ -1,25 +1,7 @@
use std::collections::HashSet;
use axum::extract::State;
use futures::{FutureExt, StreamExt, TryFutureExt, pin_mut};
use ruma::{
CanonicalJsonObject, CanonicalJsonValue, OwnedServerName, RoomId, RoomVersionId, UserId,
api::{
client::membership::leave_room,
federation::{self},
},
events::{
StateEventType,
room::member::{MembershipState, RoomMemberEventContent},
},
};
use tuwunel_core::{
Err, Result, debug_info, debug_warn, err,
matrix::{event::gen_event_id, pdu::PduBuilder},
utils::{self, FutureBoolExt, future::ReadyEqExt},
warn,
};
use tuwunel_service::Services;
use futures::FutureExt;
use ruma::api::client::membership::leave_room;
use tuwunel_core::Result;
use crate::Ruma;
@@ -32,362 +14,21 @@ pub(crate) async fn leave_room_route(
State(services): State<crate::State>,
body: Ruma<leave_room::v3::Request>,
) -> Result<leave_room::v3::Response> {
leave_room(&services, body.sender_user(), &body.room_id, body.reason.clone())
let state_lock = services.state.mutex.lock(&body.room_id).await;
services
.membership
.leave(body.sender_user(), &body.room_id, body.reason.clone(), false, &state_lock)
.boxed()
.await
.map(|()| leave_room::v3::Response::new())
}
// Make a user leave all their joined rooms, rescinds knocks, forgets all rooms,
// and ignores errors
pub async fn leave_all_rooms(services: &Services, user_id: &UserId) {
let rooms_joined = services
.rooms
.state_cache
.rooms_joined(user_id)
.map(ToOwned::to_owned);
let rooms_invited = services
.rooms
.state_cache
.rooms_invited(user_id)
.map(|(r, _)| r);
let rooms_knocked = services
.rooms
.state_cache
.rooms_knocked(user_id)
.map(|(r, _)| r);
let all_rooms: Vec<_> = rooms_joined
.chain(rooms_invited)
.chain(rooms_knocked)
.collect()
.await;
for room_id in all_rooms {
// ignore errors
if let Err(e) = leave_room(services, user_id, &room_id, None)
.boxed()
.await
{
warn!(%user_id, "Failed to leave {room_id} remotely: {e}");
}
services
.rooms
.state_cache
.forget(&room_id, user_id);
}
}
pub async fn leave_room(
services: &Services,
user_id: &UserId,
room_id: &RoomId,
reason: Option<String>,
) -> Result {
let default_member_content = RoomMemberEventContent {
membership: MembershipState::Leave,
reason: reason.clone(),
join_authorized_via_users_server: None,
is_direct: None,
avatar_url: None,
displayname: None,
third_party_invite: None,
blurhash: None,
};
let is_banned = services.rooms.metadata.is_banned(room_id);
let is_disabled = services.rooms.metadata.is_disabled(room_id);
pin_mut!(is_banned, is_disabled);
if is_banned.or(is_disabled).await {
// the room is banned/disabled, the room must be rejected locally since we
// cant/dont want to federate with this server
services
.rooms
.state_cache
.update_membership(
room_id,
user_id,
default_member_content,
user_id,
None,
None,
true,
)
.await?;
return Ok(());
}
let dont_have_room = services
.rooms
.state_cache
.server_in_room(services.globals.server_name(), room_id)
.eq(&false);
let not_knocked = services
.rooms
.state_cache
.is_knocked(user_id, room_id)
.eq(&false);
// Ask a remote server if we don't have this room and are not knocking on it
if dont_have_room.and(not_knocked).await {
if let Err(e) = remote_leave_room(services, user_id, room_id)
.boxed()
.await
{
warn!(%user_id, "Failed to leave room {room_id} remotely: {e}");
// Don't tell the client about this error
}
let last_state = services
.rooms
.state_cache
.invite_state(user_id, room_id)
.or_else(|_| {
services
.rooms
.state_cache
.knock_state(user_id, room_id)
})
.or_else(|_| {
services
.rooms
.state_cache
.left_state(user_id, room_id)
})
.await
.ok();
// We always drop the invite, we can't rely on other servers
services
.rooms
.state_cache
.update_membership(
room_id,
user_id,
default_member_content,
user_id,
last_state,
None,
true,
)
.await?;
} else {
let state_lock = services.rooms.state.mutex.lock(room_id).await;
let Ok(event) = services
.rooms
.state_accessor
.room_state_get_content::<RoomMemberEventContent>(
room_id,
&StateEventType::RoomMember,
user_id.as_str(),
)
.await
else {
debug_warn!(
"Trying to leave a room you are not a member of, marking room as left locally."
);
return services
.rooms
.state_cache
.update_membership(
room_id,
user_id,
default_member_content,
user_id,
None,
None,
true,
)
.await;
};
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(user_id.to_string(), &RoomMemberEventContent {
membership: MembershipState::Leave,
reason,
join_authorized_via_users_server: None,
is_direct: None,
..event
}),
user_id,
room_id,
&state_lock,
)
.await?;
}
Ok(())
}
async fn remote_leave_room(services: &Services, user_id: &UserId, room_id: &RoomId) -> Result {
let mut make_leave_response_and_server =
Err!(BadServerResponse("No remote server available to assist in leaving {room_id}."));
let mut servers: HashSet<OwnedServerName> = services
.rooms
.state_cache
.servers_invite_via(room_id)
.map(ToOwned::to_owned)
.collect()
.await;
match services
.rooms
.state_cache
.invite_state(user_id, room_id)
.await
{
| Ok(invite_state) => {
servers.extend(
invite_state
.iter()
.filter_map(|event| event.get_field("sender").ok().flatten())
.filter_map(|sender: &str| UserId::parse(sender).ok())
.map(|user| user.server_name().to_owned()),
);
},
| _ => {
match services
.rooms
.state_cache
.knock_state(user_id, room_id)
.await
{
| Ok(knock_state) => {
servers.extend(
knock_state
.iter()
.filter_map(|event| event.get_field("sender").ok().flatten())
.filter_map(|sender: &str| UserId::parse(sender).ok())
.filter_map(|sender| {
if !services.globals.user_is_local(sender) {
Some(sender.server_name().to_owned())
} else {
None
}
}),
);
},
| _ => {},
}
},
}
if let Some(room_id_server_name) = room_id.server_name() {
servers.insert(room_id_server_name.to_owned());
}
debug_info!("servers in remote_leave_room: {servers:?}");
for remote_server in servers {
let make_leave_response = services
.sending
.send_federation_request(
&remote_server,
federation::membership::prepare_leave_event::v1::Request {
room_id: room_id.to_owned(),
user_id: user_id.to_owned(),
},
)
.await;
make_leave_response_and_server = make_leave_response.map(|r| (r, remote_server));
if make_leave_response_and_server.is_ok() {
break;
}
}
let (make_leave_response, remote_server) = make_leave_response_and_server?;
let Some(room_version_id) = make_leave_response.room_version else {
return Err!(BadServerResponse(warn!(
"No room version was returned by {remote_server} for {room_id}, room version is \
likely not supported by tuwunel"
)));
};
if !services
.server
.supported_room_version(&room_version_id)
{
return Err!(BadServerResponse(warn!(
"Remote room version {room_version_id} for {room_id} is not supported by conduwuit",
)));
}
let mut leave_event_stub = serde_json::from_str::<CanonicalJsonObject>(
make_leave_response.event.get(),
)
.map_err(|e| {
err!(BadServerResponse(warn!(
"Invalid make_leave event json received from {remote_server} for {room_id}: {e:?}"
)))
})?;
// TODO: Is origin needed?
leave_event_stub.insert(
"origin".to_owned(),
CanonicalJsonValue::String(services.globals.server_name().as_str().to_owned()),
);
leave_event_stub.insert(
"origin_server_ts".to_owned(),
CanonicalJsonValue::Integer(
utils::millis_since_unix_epoch()
.try_into()
.expect("Timestamp is valid js_int value"),
),
);
// room v3 and above removed the "event_id" field from remote PDU format
match room_version_id {
| RoomVersionId::V1 | RoomVersionId::V2 => {},
| _ => {
leave_event_stub.remove("event_id");
},
}
// In order to create a compatible ref hash (EventID) the `hashes` field needs
// to be present
services
.server_keys
.hash_and_sign_event(&mut leave_event_stub, &room_version_id)?;
// Generate event id
let event_id = gen_event_id(&leave_event_stub, &room_version_id)?;
// Add event_id back
leave_event_stub
.insert("event_id".to_owned(), CanonicalJsonValue::String(event_id.clone().into()));
// It has enough fields to be called a proper event now
let leave_event = leave_event_stub;
services
.sending
.send_federation_request(
&remote_server,
federation::membership::create_leave_event::v2::Request {
room_id: room_id.to_owned(),
event_id,
pdu: services
.sending
.convert_to_outgoing_federation_event(leave_event.clone())
.await,
},
)
.await?;
Ok(())
if services.config.delete_rooms_after_leave {
services
.delete
.delete_if_empty_local(&body.room_id, state_lock)
.boxed()
.await;
}
Ok(leave_room::v3::Response {})
}
+52 -40
View File
@@ -1,21 +1,24 @@
use axum::extract::State;
use futures::{FutureExt, StreamExt, future::join};
use futures::{FutureExt, StreamExt, pin_mut};
use ruma::{
api::client::membership::{
get_member_events::{self, v3::MembershipEventFilter},
get_member_events::{self},
joined_members::{self, v3::RoomMember},
},
events::{
StateEventType,
room::member::{MembershipState, RoomMemberEventContent},
room::{
history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
member::{MembershipState, RoomMemberEventContent},
},
},
};
use tuwunel_core::{
Err, Result, at,
matrix::Event,
utils::{
future::TryExtExt,
stream::{BroadbandExt, ReadyExt},
future::{BoolExt, TryExtExt},
stream::ReadyExt,
},
};
@@ -31,22 +34,20 @@ pub(crate) async fn get_member_events_route(
State(services): State<crate::State>,
body: Ruma<get_member_events::v3::Request>,
) -> Result<get_member_events::v3::Response> {
let sender_user = body.sender_user();
let membership = body.membership.as_ref();
let not_membership = body.not_membership.as_ref();
if !services
.rooms
.state_accessor
.user_can_see_state_events(sender_user, &body.room_id)
.user_can_see_state_events(body.sender_user(), &body.room_id)
.await
{
return Err!(Request(Forbidden("You don't have permission to view this room.")));
return Err!(Request(Forbidden(
"You aren't a member of the room and weren't previously a member of the room."
)));
}
let membership = body.membership.as_ref();
let not_membership = body.not_membership.as_ref();
Ok(get_member_events::v3::Response {
chunk: services
.rooms
.state_accessor
.room_state_full(&body.room_id)
.ready_filter_map(Result::ok)
@@ -70,53 +71,64 @@ pub(crate) async fn joined_members_route(
State(services): State<crate::State>,
body: Ruma<joined_members::v3::Request>,
) -> Result<joined_members::v3::Response> {
if !services
.rooms
let is_joined = services
.state_cache
.is_joined(body.sender_user(), &body.room_id);
let is_world_readable = services
.state_accessor
.user_can_see_state_events(body.sender_user(), &body.room_id)
.await
{
return Err!(Request(Forbidden("You don't have permission to view this room.")));
.room_state_get_content(&body.room_id, &StateEventType::RoomHistoryVisibility, "")
.map_ok_or(false, |c: RoomHistoryVisibilityEventContent| {
c.history_visibility == HistoryVisibility::WorldReadable
});
pin_mut!(is_joined, is_world_readable);
if !is_joined.or(is_world_readable).await {
return Err!(Request(Forbidden("You aren't a member of the room.")));
}
Ok(joined_members::v3::Response {
joined: services
.rooms
.state_cache
.room_members(&body.room_id)
.map(ToOwned::to_owned)
.broad_then(async |user_id| {
let (display_name, avatar_url) = join(
services.users.displayname(&user_id).ok(),
services.users.avatar_url(&user_id).ok(),
)
.await;
.state_accessor
.room_state_full(&body.room_id)
.ready_filter_map(Result::ok)
.ready_filter(|((ty, _), _)| *ty == StateEventType::RoomMember)
.map(at!(1))
.ready_filter_map(|pdu| membership_filter(pdu, Some(&MembershipState::Join), None))
.ready_filter_map(|pdu| {
let content = pdu.get_content::<RoomMemberEventContent>().ok()?;
let sender = pdu.sender().to_owned();
let member = RoomMember {
display_name: content.displayname,
avatar_url: content.avatar_url,
};
(user_id, RoomMember { display_name, avatar_url })
Some((sender, member))
})
.collect()
.boxed()
.await,
})
}
fn membership_filter<Pdu: Event>(
pdu: Pdu,
for_membership: Option<&MembershipEventFilter>,
not_membership: Option<&MembershipEventFilter>,
for_membership: Option<&MembershipState>,
not_membership: Option<&MembershipState>,
) -> Option<impl Event> {
let membership_state_filter = match for_membership {
| Some(MembershipEventFilter::Ban) => MembershipState::Ban,
| Some(MembershipEventFilter::Invite) => MembershipState::Invite,
| Some(MembershipEventFilter::Knock) => MembershipState::Knock,
| Some(MembershipEventFilter::Leave) => MembershipState::Leave,
| Some(MembershipState::Ban) => MembershipState::Ban,
| Some(MembershipState::Invite) => MembershipState::Invite,
| Some(MembershipState::Knock) => MembershipState::Knock,
| Some(MembershipState::Leave) => MembershipState::Leave,
| Some(_) | None => MembershipState::Join,
};
let not_membership_state_filter = match not_membership {
| Some(MembershipEventFilter::Ban) => MembershipState::Ban,
| Some(MembershipEventFilter::Invite) => MembershipState::Invite,
| Some(MembershipEventFilter::Join) => MembershipState::Join,
| Some(MembershipEventFilter::Knock) => MembershipState::Knock,
| Some(MembershipState::Ban) => MembershipState::Ban,
| Some(MembershipState::Invite) => MembershipState::Invite,
| Some(MembershipState::Join) => MembershipState::Join,
| Some(MembershipState::Knock) => MembershipState::Knock,
| Some(_) | None => MembershipState::Leave,
};
+141 -82
View File
@@ -8,18 +8,21 @@ mod leave;
mod members;
mod unban;
use std::net::IpAddr;
use std::{cmp::Ordering, net::IpAddr};
use axum::extract::State;
use futures::{FutureExt, StreamExt};
use ruma::{OwnedRoomId, RoomId, ServerName, UserId, api::client::membership::joined_rooms};
use tuwunel_core::{Err, Result, warn};
use ruma::{
OwnedRoomId, OwnedServerName, RoomId, RoomOrAliasId, ServerName, UserId,
api::client::membership::joined_rooms,
};
use tuwunel_core::{Err, Result, result::LogErr, utils::shuffle, warn};
use tuwunel_service::Services;
pub(crate) use self::{
ban::ban_user_route,
forget::forget_room_route,
invite::{invite_helper, invite_user_route},
invite::invite_user_route,
join::{join_room_by_id_or_alias_route, join_room_by_id_route},
kick::kick_user_route,
knock::knock_room_route,
@@ -27,11 +30,7 @@ pub(crate) use self::{
members::{get_member_events_route, joined_members_route},
unban::unban_user_route,
};
pub use self::{
join::join_room_by_id_helper,
leave::{leave_all_rooms, leave_room},
};
use crate::{Ruma, client::full_user_deactivate};
use crate::Ruma;
/// # `POST /_matrix/client/r0/joined_rooms`
///
@@ -42,7 +41,6 @@ pub(crate) async fn joined_rooms_route(
) -> Result<joined_rooms::v3::Response> {
Ok(joined_rooms::v3::Response {
joined_rooms: services
.rooms
.state_cache
.rooms_joined(body.sender_user())
.map(ToOwned::to_owned)
@@ -68,53 +66,28 @@ pub(crate) async fn banned_room_check(
return Ok(());
}
// TODO: weird condition
if let Some(room_id) = room_id {
if services.rooms.metadata.is_banned(room_id).await
|| services
.config
.forbidden_remote_server_names
.is_match(
room_id
.server_name()
.expect("legacy room mxid")
.host(),
) {
if services.metadata.is_banned(room_id).await
|| (room_id.server_name().is_some()
&& services
.config
.forbidden_remote_server_names
.is_match(
room_id
.server_name()
.expect("legacy room mxid")
.host(),
)) {
warn!(
"User {user_id} who is not an admin attempted to send an invite for or \
attempted to join a banned room or banned room server name: {room_id}"
);
if services
.server
.config
.auto_deactivate_banned_room_attempts
{
warn!(
"Automatically deactivating user {user_id} due to attempted banned room join"
);
if services.server.config.admin_room_notices {
services
.admin
.send_text(&format!(
"Automatically deactivating user {user_id} due to attempted banned \
room join from IP {client_ip}"
))
.await;
}
let all_joined_rooms: Vec<OwnedRoomId> = services
.rooms
.state_cache
.rooms_joined(user_id)
.map(Into::into)
.collect()
.await;
full_user_deactivate(services, user_id, &all_joined_rooms)
.boxed()
.await?;
}
maybe_deactivate(services, user_id, client_ip)
.await
.log_err()
.ok();
return Err!(Request(Forbidden("This room is banned on this homeserver.")));
}
@@ -129,37 +102,10 @@ pub(crate) async fn banned_room_check(
name {server_name} that is globally forbidden. Rejecting.",
);
if services
.server
.config
.auto_deactivate_banned_room_attempts
{
warn!(
"Automatically deactivating user {user_id} due to attempted banned room join"
);
if services.server.config.admin_room_notices {
services
.admin
.send_text(&format!(
"Automatically deactivating user {user_id} due to attempted banned \
room join from IP {client_ip}"
))
.await;
}
let all_joined_rooms: Vec<OwnedRoomId> = services
.rooms
.state_cache
.rooms_joined(user_id)
.map(Into::into)
.collect()
.await;
full_user_deactivate(services, user_id, &all_joined_rooms)
.boxed()
.await?;
}
maybe_deactivate(services, user_id, client_ip)
.await
.log_err()
.ok();
return Err!(Request(Forbidden("This remote server is banned on this homeserver.")));
}
@@ -167,3 +113,116 @@ pub(crate) async fn banned_room_check(
Ok(())
}
async fn maybe_deactivate(services: &Services, user_id: &UserId, client_ip: IpAddr) -> Result {
if services
.server
.config
.auto_deactivate_banned_room_attempts
{
warn!("Automatically deactivating user {user_id} due to attempted banned room join");
if services.server.config.admin_room_notices {
services
.admin
.send_text(&format!(
"Automatically deactivating user {user_id} due to attempted banned room \
join from IP {client_ip}"
))
.await;
}
services
.deactivate
.full_deactivate(user_id)
.boxed()
.await?;
}
Ok(())
}
// TODO: should this be in services? banned check would have to resolve again if
// room_id is not available at callsite
async fn get_join_params(
services: &Services,
user_id: &UserId,
room_id_or_alias: &RoomOrAliasId,
via: &[OwnedServerName],
) -> Result<(OwnedRoomId, Vec<OwnedServerName>)> {
// servers tried first, additional_servers shuffled then tried after
let (room_id, mut servers, mut additional_servers) =
match OwnedRoomId::try_from(room_id_or_alias.to_owned()) {
// if room id, shuffle via + room_id server_name ...
| Ok(room_id) => {
let mut additional_servers = via.to_vec();
if let Some(server) = room_id.server_name() {
additional_servers.push(server.to_owned());
}
(room_id, Vec::new(), additional_servers)
},
// ... if room alias, resolve and don't shuffle ...
| Err(room_alias) => {
let (room_id, servers) = services.alias.resolve_alias(&room_alias).await?;
(room_id, servers, Vec::new())
},
};
// either way, add invited vias
additional_servers.extend(
services
.state_cache
.servers_invite_via(&room_id)
.map(ToOwned::to_owned)
.collect::<Vec<_>>()
.await,
);
// either way, add invite senders' servers
additional_servers.extend(
services
.state_cache
.invite_state(user_id, &room_id)
.await
.unwrap_or_default()
.iter()
.filter_map(|event| event.get_field("sender").ok().flatten())
.filter_map(|sender: &str| UserId::parse(sender).ok())
.map(|user| user.server_name().to_owned()),
);
// shuffle additionals, append to base servers
additional_servers.sort_unstable();
additional_servers.dedup();
shuffle(&mut additional_servers);
servers.sort_unstable();
servers.dedup();
servers.append(&mut additional_servers);
// sort deprioritized servers last
servers.sort_by(|a, b| {
let a_matches = services
.server
.config
.deprioritize_joins_through_servers
.is_match(a.host());
let b_matches = services
.server
.config
.deprioritize_joins_through_servers
.is_match(b.host());
if a_matches && !b_matches {
Ordering::Greater
} else if !a_matches && b_matches {
Ordering::Less
} else {
Ordering::Equal
}
});
Ok((room_id, servers))
}
+10 -37
View File
@@ -1,9 +1,7 @@
use axum::extract::State;
use ruma::{
api::client::membership::unban_user,
events::room::member::{MembershipState, RoomMemberEventContent},
};
use tuwunel_core::{Err, Result, matrix::pdu::PduBuilder};
use futures::FutureExt;
use ruma::api::client::membership::unban_user;
use tuwunel_core::Result;
use crate::Ruma;
@@ -14,43 +12,18 @@ pub(crate) async fn unban_user_route(
State(services): State<crate::State>,
body: Ruma<unban_user::v3::Request>,
) -> Result<unban_user::v3::Response> {
let state_lock = services
.rooms
.state
.mutex
.lock(&body.room_id)
.await;
let current_member_content = services
.rooms
.state_accessor
.get_member(&body.room_id, &body.user_id)
.await
.unwrap_or_else(|_| RoomMemberEventContent::new(MembershipState::Leave));
if current_member_content.membership != MembershipState::Ban {
return Err!(Request(Forbidden(
"Cannot unban a user who is not banned (current membership: {})",
current_member_content.membership
)));
}
let state_lock = services.state.mutex.lock(&body.room_id).await;
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(body.user_id.to_string(), &RoomMemberEventContent {
membership: MembershipState::Leave,
reason: body.reason.clone(),
join_authorized_via_users_server: None,
third_party_invite: None,
is_direct: None,
..current_member_content
}),
body.sender_user(),
.membership
.unban(
&body.room_id,
&body.user_id,
body.reason.as_ref(),
body.sender_user(),
&state_lock,
)
.boxed()
.await?;
drop(state_lock);
+2 -8
View File
@@ -73,7 +73,7 @@ pub(crate) async fn get_message_events_route(
let room_id = &body.room_id;
let filter = &body.filter;
if !services.rooms.metadata.exists(room_id).await {
if !services.metadata.exists(room_id).await {
return Err!(Request(Forbidden("Room does not exist to this server")));
}
@@ -97,7 +97,6 @@ pub(crate) async fn get_message_events_route(
if matches!(body.dir, Direction::Backward) {
services
.rooms
.timeline
.backfill_if_required(room_id, from)
.await
@@ -107,14 +106,12 @@ pub(crate) async fn get_message_events_route(
let it = match body.dir {
| Direction::Forward => services
.rooms
.timeline
.pdus(Some(sender_user), room_id, Some(from))
.ignore_err()
.boxed(),
| Direction::Backward => services
.rooms
.timeline
.pdus_rev(Some(sender_user), room_id, Some(from))
.ignore_err()
@@ -192,7 +189,7 @@ where
.max()
.unwrap_or_else(PduCount::max);
let receipts = services.rooms.read_receipt.readreceipts_since(
let receipts = services.read_receipt.readreceipts_since(
lazy_loading_context.room_id,
oldest.into_unsigned(),
Some(newest.into_unsigned()),
@@ -213,7 +210,6 @@ where
.await;
services
.rooms
.lazy_loading
.witness_retain(witness, lazy_loading_context)
.await
@@ -225,7 +221,6 @@ async fn get_member_event(
user_id: &UserId,
) -> Option<Raw<AnyStateEvent>> {
services
.rooms
.state_accessor
.room_state_get(room_id, &StateEventType::RoomMember, user_id.as_str())
.map_ok(Event::into_format)
@@ -293,7 +288,6 @@ pub(crate) async fn visibility_filter(
let (_, pdu) = &item;
services
.rooms
.state_accessor
.user_can_see_event(user_id, pdu.room_id(), pdu.event_id())
.await
+2 -3
View File
@@ -40,7 +40,8 @@ pub(super) mod user_directory;
pub(super) mod voip;
pub(super) mod well_known;
pub use account::full_user_deactivate;
mod utils;
pub(super) use account::*;
pub(super) use account_data::*;
pub(super) use alias::*;
@@ -55,12 +56,10 @@ pub(super) use keys::*;
pub(super) use media::*;
pub(super) use media_legacy::*;
pub(super) use membership::*;
pub use membership::{join_room_by_id_helper, leave_all_rooms, leave_room};
pub(super) use message::*;
pub(super) use openid::*;
pub(super) use presence::*;
pub(super) use profile::*;
pub use profile::{update_all_rooms, update_avatar_url, update_displayname};
pub(super) use push::*;
pub(super) use read_marker::*;
pub(super) use redact::*;
-1
View File
@@ -44,7 +44,6 @@ pub(crate) async fn get_presence_route(
let mut presence_event = None;
let has_shared_rooms = services
.rooms
.state_cache
.user_sees_user(body.sender_user(), &body.user_id)
.await;
+55 -171
View File
@@ -2,27 +2,20 @@ use std::collections::BTreeMap;
use axum::extract::State;
use futures::{
StreamExt, TryStreamExt,
future::{join, join3, join4},
StreamExt,
future::{join, join4},
};
use ruma::{
OwnedMxcUri, OwnedRoomId, UserId,
OwnedRoomId,
api::{
client::profile::{
get_avatar_url, get_display_name, get_profile, set_avatar_url, set_display_name,
},
federation,
},
events::room::member::{MembershipState, RoomMemberEventContent},
presence::PresenceState,
};
use tuwunel_core::{
Err, Result,
matrix::pdu::PduBuilder,
utils::{IterStream, future::TryExtExt, stream::TryIgnore},
warn,
};
use tuwunel_service::Services;
use tuwunel_core::{Err, Result, utils::future::TryExtExt};
use crate::Ruma;
@@ -42,23 +35,22 @@ pub(crate) async fn set_displayname_route(
}
let all_joined_rooms: Vec<OwnedRoomId> = services
.rooms
.state_cache
.rooms_joined(&body.user_id)
.map(ToOwned::to_owned)
.collect()
.await;
update_displayname(&services, &body.user_id, body.displayname.clone(), &all_joined_rooms)
services
.users
.update_displayname(&body.user_id, body.displayname.clone(), &all_joined_rooms)
.await;
if services.config.allow_local_presence {
// Presence update
services
.presence
.ping_presence(&body.user_id, &PresenceState::Online)
.await?;
}
// Presence update
services
.presence
.maybe_ping_presence(&body.user_id, &PresenceState::Online)
.await?;
Ok(set_display_name::v3::Response {})
}
@@ -138,30 +130,28 @@ pub(crate) async fn set_avatar_url_route(
}
let all_joined_rooms: Vec<OwnedRoomId> = services
.rooms
.state_cache
.rooms_joined(&body.user_id)
.map(ToOwned::to_owned)
.collect()
.await;
update_avatar_url(
&services,
&body.user_id,
body.avatar_url.clone(),
body.blurhash.clone(),
&all_joined_rooms,
)
.await;
services
.users
.update_avatar_url(
&body.user_id,
body.avatar_url.clone(),
body.blurhash.clone(),
&all_joined_rooms,
)
.await;
if services.config.allow_local_presence {
// Presence update
services
.presence
.ping_presence(&body.user_id, &PresenceState::Online)
.await
.ok();
}
// Presence update
services
.presence
.maybe_ping_presence(&body.user_id, &PresenceState::Online)
.await
.ok();
Ok(set_avatar_url::v3::Response {})
}
@@ -279,13 +269,20 @@ pub(crate) async fn get_profile_route(
);
}
return Ok(get_profile::v3::Response {
displayname: response.displayname,
avatar_url: response.avatar_url,
blurhash: response.blurhash,
tz: response.tz,
custom_profile_fields: response.custom_profile_fields,
});
let canonical_fields = [
("avatar_url", response.avatar_url.map(Into::into)),
("blurhash", response.blurhash),
("displayname", response.displayname),
("tz", response.tz),
];
let response = canonical_fields
.into_iter()
.filter_map(|(key, val)| val.map(|val| (key, val)))
.map(|(key, val)| (key.to_owned(), val.into()))
.chain(response.custom_profile_fields.into_iter());
return Ok(response.collect::<get_profile::v3::Response>());
}
}
@@ -313,131 +310,18 @@ pub(crate) async fn get_profile_route(
)
.await;
Ok(get_profile::v3::Response {
avatar_url,
blurhash,
displayname,
tz,
custom_profile_fields,
})
}
pub async fn update_displayname(
services: &Services,
user_id: &UserId,
displayname: Option<String>,
all_joined_rooms: &[OwnedRoomId],
) {
let (current_avatar_url, current_blurhash, current_displayname) = join3(
services.users.avatar_url(user_id).ok(),
services.users.blurhash(user_id).ok(),
services.users.displayname(user_id).ok(),
)
.await;
if displayname == current_displayname {
return;
}
services
.users
.set_displayname(user_id, displayname.clone());
// Send a new join membership event into all joined rooms
let avatar_url = &current_avatar_url;
let blurhash = &current_blurhash;
let displayname = &displayname;
let all_joined_rooms: Vec<_> = all_joined_rooms
.iter()
.try_stream()
.and_then(async |room_id: &OwnedRoomId| {
let pdu = PduBuilder::state(user_id.to_string(), &RoomMemberEventContent {
displayname: displayname.clone(),
membership: MembershipState::Join,
avatar_url: avatar_url.clone(),
blurhash: blurhash.clone(),
join_authorized_via_users_server: None,
reason: None,
is_direct: None,
third_party_invite: None,
});
Ok((pdu, room_id))
})
.ignore_err()
.collect()
.await;
update_all_rooms(services, all_joined_rooms, user_id).await;
}
pub async fn update_avatar_url(
services: &Services,
user_id: &UserId,
avatar_url: Option<OwnedMxcUri>,
blurhash: Option<String>,
all_joined_rooms: &[OwnedRoomId],
) {
let (current_avatar_url, current_blurhash, current_displayname) = join3(
services.users.avatar_url(user_id).ok(),
services.users.blurhash(user_id).ok(),
services.users.displayname(user_id).ok(),
)
.await;
if current_avatar_url == avatar_url && current_blurhash == blurhash {
return;
}
services
.users
.set_avatar_url(user_id, avatar_url.clone());
services
.users
.set_blurhash(user_id, blurhash.clone());
// Send a new join membership event into all joined rooms
let avatar_url = &avatar_url;
let blurhash = &blurhash;
let displayname = &current_displayname;
let all_joined_rooms: Vec<_> = all_joined_rooms
.iter()
.try_stream()
.and_then(async |room_id: &OwnedRoomId| {
let pdu = PduBuilder::state(user_id.to_string(), &RoomMemberEventContent {
avatar_url: avatar_url.clone(),
blurhash: blurhash.clone(),
membership: MembershipState::Join,
displayname: displayname.clone(),
join_authorized_via_users_server: None,
reason: None,
is_direct: None,
third_party_invite: None,
});
Ok((pdu, room_id))
})
.ignore_err()
.collect()
.await;
update_all_rooms(services, all_joined_rooms, user_id).await;
}
pub async fn update_all_rooms(
services: &Services,
all_joined_rooms: Vec<(PduBuilder, &OwnedRoomId)>,
user_id: &UserId,
) {
for (pdu_builder, room_id) in all_joined_rooms {
let state_lock = services.rooms.state.mutex.lock(room_id).await;
if let Err(e) = services
.rooms
.timeline
.build_and_append_pdu(pdu_builder, user_id, room_id, &state_lock)
.await
{
warn!(%user_id, %room_id, "Failed to update/send new profile join membership update in room: {e}");
}
}
let canonical_fields = [
("avatar_url", avatar_url.map(Into::into)),
("blurhash", blurhash),
("displayname", displayname),
("tz", tz),
];
let response = canonical_fields
.into_iter()
.filter_map(|(key, val)| val.map(|val| (key, val)))
.map(|(key, val)| (key.to_owned(), val.into()))
.chain(custom_profile_fields.into_iter());
Ok(response.collect::<get_profile::v3::Response>())
}
+32 -43
View File
@@ -26,6 +26,12 @@ pub(crate) async fn set_read_marker_route(
) -> Result<set_read_marker::v3::Response> {
let sender_user = body.sender_user();
if body.private_read_receipt.is_some() || body.read_receipt.is_some() {
services
.user
.reset_notification_counts(sender_user, &body.room_id);
}
if let Some(event) = &body.fully_read {
let fully_read_event = ruma::events::fully_read::FullyReadEvent {
content: ruma::events::fully_read::FullyReadEventContent { event_id: event.clone() },
@@ -39,22 +45,26 @@ pub(crate) async fn set_read_marker_route(
RoomAccountDataEventType::FullyRead,
&serde_json::to_value(fully_read_event)?,
)
.await?;
.await
.ok();
}
if body.private_read_receipt.is_some() || body.read_receipt.is_some() {
services
.rooms
.user
.reset_notification_counts(sender_user, &body.room_id);
}
if let Some(event) = &body.private_read_receipt {
let count = services
.timeline
.get_pdu_count(event)
.await
.map_err(|_| err!(Request(NotFound("Event not found."))))?;
let PduCount::Normal(count) = count else {
return Err!(Request(InvalidParam(
"Event is a backfilled PDU and cannot be marked as read."
)));
};
// ping presence
if services.config.allow_local_presence {
services
.presence
.ping_presence(sender_user, &ruma::presence::PresenceState::Online)
.await?;
.read_receipt
.private_read_set(&body.room_id, sender_user, count);
}
if let Some(event) = &body.read_receipt {
@@ -70,7 +80,6 @@ pub(crate) async fn set_read_marker_route(
)]);
services
.rooms
.read_receipt
.readreceipt_update(
sender_user,
@@ -81,26 +90,12 @@ pub(crate) async fn set_read_marker_route(
},
)
.await;
}
if let Some(event) = &body.private_read_receipt {
let count = services
.rooms
.timeline
.get_pdu_count(event)
.await
.map_err(|_| err!(Request(NotFound("Event not found."))))?;
let PduCount::Normal(count) = count else {
return Err!(Request(InvalidParam(
"Event is a backfilled PDU and cannot be marked as read."
)));
};
services
.rooms
.read_receipt
.private_read_set(&body.room_id, sender_user, count);
.presence
.maybe_ping_presence(sender_user, &ruma::presence::PresenceState::Online)
.await
.ok();
}
Ok(set_read_marker::v3::Response {})
@@ -120,19 +115,10 @@ pub(crate) async fn create_receipt_route(
create_receipt::v3::ReceiptType::Read | create_receipt::v3::ReceiptType::ReadPrivate
) {
services
.rooms
.user
.reset_notification_counts(sender_user, &body.room_id);
}
// ping presence
if services.config.allow_local_presence {
services
.presence
.ping_presence(sender_user, &ruma::presence::PresenceState::Online)
.await?;
}
match body.receipt_type {
| create_receipt::v3::ReceiptType::FullyRead => {
let fully_read_event = ruma::events::fully_read::FullyReadEvent {
@@ -166,7 +152,6 @@ pub(crate) async fn create_receipt_route(
)]);
services
.rooms
.read_receipt
.readreceipt_update(
sender_user,
@@ -177,10 +162,15 @@ pub(crate) async fn create_receipt_route(
},
)
.await;
services
.presence
.maybe_ping_presence(sender_user, &ruma::presence::PresenceState::Online)
.await
.ok();
},
| create_receipt::v3::ReceiptType::ReadPrivate => {
let count = services
.rooms
.timeline
.get_pdu_count(&body.event_id)
.await
@@ -193,7 +183,6 @@ pub(crate) async fn create_receipt_route(
};
services
.rooms
.read_receipt
.private_read_set(&body.room_id, sender_user, count);
},
+1 -7
View File
@@ -18,15 +18,9 @@ pub(crate) async fn redact_event_route(
let sender_user = body.sender_user();
let body = &body.body;
let state_lock = services
.rooms
.state
.mutex
.lock(&body.room_id)
.await;
let state_lock = services.state.mutex.lock(&body.room_id).await;
let event_id = services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder {
+31 -24
View File
@@ -19,7 +19,7 @@ use ruma::{
use tuwunel_core::{Err, Error, Result, debug_info, error, info, is_equal_to, utils, warn};
use tuwunel_service::users::device::generate_refresh_token;
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, join_room_by_id_helper};
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH};
use crate::Ruma;
const RANDOM_USER_ID_LENGTH: usize = 10;
@@ -58,8 +58,8 @@ pub(crate) async fn get_register_available_route(
});
if services
.globals
.forbidden_usernames()
.config
.forbidden_usernames
.is_match(&body.username)
{
return Err!(Request(Forbidden("Username is forbidden")));
@@ -228,8 +228,8 @@ pub(crate) async fn register_route(
});
if services
.globals
.forbidden_usernames()
.config
.forbidden_usernames
.is_match(username)
&& !emergency_mode_enabled
{
@@ -316,7 +316,7 @@ pub(crate) async fn register_route(
stages: vec![AuthType::RegistrationToken],
}],
completed: Vec::new(),
params: Box::default(),
params: Default::default(),
session: None,
auth_error: None,
};
@@ -326,7 +326,7 @@ pub(crate) async fn register_route(
uiaainfo = UiaaInfo {
flows: vec![AuthFlow { stages: vec![AuthType::Dummy] }],
completed: Vec::new(),
params: Box::default(),
params: Default::default(),
session: None,
auth_error: None,
};
@@ -384,8 +384,8 @@ pub(crate) async fn register_route(
// If `new_user_displayname_suffix` is set, registration will push whatever
// content is set to the user's display name with a space before it
if !services
.globals
.new_user_displayname_suffix()
.config
.new_user_displayname_suffix
.is_empty()
&& body.appservice_info.is_none()
{
@@ -517,13 +517,16 @@ pub(crate) async fn register_route(
&& services.config.grant_admin_to_first_user
&& let Ok(admin_room) = services.admin.get_admin_room().await
&& services
.rooms
.state_cache
.room_joined_count(&admin_room)
.await
.is_ok_and(is_equal_to!(1))
{
services.admin.make_user_admin(&user_id).await?;
services
.admin
.make_user_admin(&user_id)
.boxed()
.await?;
warn!("Granting {user_id} admin privileges as the first user");
}
@@ -532,7 +535,7 @@ pub(crate) async fn register_route(
&& (services.config.allow_guests_auto_join_rooms || !is_guest)
{
for room in &services.server.config.auto_join_rooms {
let Ok(room_id) = services.rooms.alias.resolve(room).await else {
let Ok(room_id) = services.alias.maybe_resolve(room).await else {
error!(
"Failed to resolve room alias to room ID when attempting to auto join \
{room}, skipping"
@@ -541,7 +544,6 @@ pub(crate) async fn register_route(
};
if !services
.rooms
.state_cache
.server_in_room(services.globals.server_name(), &room_id)
.await
@@ -553,17 +555,20 @@ pub(crate) async fn register_route(
}
if let Some(room_server_name) = room.server_name() {
match join_room_by_id_helper(
&services,
&user_id,
&room_id,
Some("Automatically joining this room upon registration".to_owned()),
&[services.globals.server_name().to_owned(), room_server_name.to_owned()],
None,
&body.appservice_info,
)
.boxed()
.await
let state_lock = services.state.mutex.lock(&room_id).await;
match services
.membership
.join(
&user_id,
&room_id,
Some("Automatically joining this room upon registration".to_owned()),
&[services.globals.server_name().to_owned(), room_server_name.to_owned()],
&body.appservice_info,
&state_lock,
)
.boxed()
.await
{
| Err(e) => {
// don't return this error so we don't fail registrations
@@ -575,6 +580,8 @@ pub(crate) async fn register_route(
info!("Automatically joined room {room} for user {user_id}");
},
}
drop(state_lock);
}
}
}
-2
View File
@@ -133,7 +133,6 @@ async fn paginate_relations_with_filter(
let depth: u8 = if recurse { 3 } else { 1 };
let events: Vec<_> = services
.rooms
.pdu_metadata
.get_relations(sender_user, room_id, target, start, limit, depth, dir)
.await
@@ -183,7 +182,6 @@ async fn visibility_filter<Pdu: Event>(
let (_, pdu) = &item;
services
.rooms
.state_accessor
.user_can_see_event(sender_user, pdu.room_id(), pdu.event_id())
.await
+9 -19
View File
@@ -15,6 +15,8 @@ use tuwunel_service::Services;
use crate::Ruma;
const REASON_MAX_LEN: usize = 750;
/// # `POST /_matrix/client/v3/rooms/{roomId}/report`
///
/// Reports an abusive room to homeserver admins
@@ -29,24 +31,18 @@ pub(crate) async fn report_room_route(
info!(
"Received room report by user {sender_user} for room {} with reason: \"{}\"",
body.room_id,
body.reason.as_deref().unwrap_or("")
body.room_id, body.reason,
);
if body
.reason
.as_ref()
.is_some_and(|s| s.len() > 750)
{
return Err!(Request(
InvalidParam("Reason too long, should be 750 characters or fewer",)
));
if body.reason.len().gt(&REASON_MAX_LEN) {
return Err!(Request(InvalidParam(
"Reason too long, should be {REASON_MAX_LEN} characters or fewer"
)));
}
delay_response().await;
if !services
.rooms
.state_cache
.server_in_room(&services.server.name, &body.room_id)
.await
@@ -64,7 +60,7 @@ pub(crate) async fn report_room_route(
"@room Room report received from {} -\n\nRoom ID: {}\n\nReport Reason: {}",
sender_user.to_owned(),
body.room_id,
body.reason.as_deref().unwrap_or("")
body.reason,
)))
.await
.ok();
@@ -95,12 +91,7 @@ pub(crate) async fn report_event_route(
delay_response().await;
// check if we know about the reported event ID or if it's invalid
let Ok(pdu) = services
.rooms
.timeline
.get_pdu(&body.event_id)
.await
else {
let Ok(pdu) = services.timeline.get_pdu(&body.event_id).await else {
return Err!(Request(NotFound("Event ID is not known to us or Event ID is invalid")));
};
@@ -170,7 +161,6 @@ async fn is_event_report_valid(
}
if !services
.rooms
.state_cache
.room_members(room_id)
.ready_any(|user_id| user_id == sender_user)
-2
View File
@@ -18,7 +18,6 @@ pub(crate) async fn get_room_aliases_route(
let sender_user = body.sender_user();
if !services
.rooms
.state_accessor
.user_can_see_state_events(sender_user, &body.room_id)
.await
@@ -28,7 +27,6 @@ pub(crate) async fn get_room_aliases_route(
Ok(aliases::v3::Response {
aliases: services
.rooms
.alias
.local_aliases_for_room(&body.room_id)
.map(ToOwned::to_owned)
+387 -208
View File
@@ -1,10 +1,13 @@
use std::collections::BTreeMap;
use axum::extract::State;
use futures::FutureExt;
use futures::{FutureExt, future::OptionFuture};
use ruma::{
CanonicalJsonObject, Int, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, RoomId, RoomVersionId,
api::client::room::{self, create_room},
api::client::room::{
self, create_room,
create_room::v3::{CreationContent, RoomPreset},
},
events::{
TimelineEventType,
room::{
@@ -16,21 +19,23 @@ use ruma::{
member::{MembershipState, RoomMemberEventContent},
name::RoomNameEventContent,
power_levels::RoomPowerLevelsEventContent,
topic::RoomTopicEventContent,
topic::{RoomTopicEventContent, TopicContentBlock},
},
},
int,
room_version_rules::{RoomIdFormatVersion, RoomVersionRules},
serde::{JsonObject, Raw},
};
use serde_json::{json, value::to_raw_value};
use tuwunel_core::{
Err, Result, debug_info, debug_warn, err, info,
matrix::{StateKey, pdu::PduBuilder},
matrix::{StateKey, pdu::PduBuilder, room_version},
utils::BoolExt,
warn,
};
use tuwunel_service::{Services, appservice::RegistrationInfo};
use tuwunel_service::{Services, appservice::RegistrationInfo, rooms::state::RoomMutexGuard};
use crate::{Ruma, client::invite_helper};
use crate::{Ruma, client::utils::invite_check};
/// # `POST /_matrix/client/v3/createRoom`
///
@@ -53,166 +58,62 @@ pub(crate) async fn create_room_route(
State(services): State<crate::State>,
body: Ruma<create_room::v3::Request>,
) -> Result<create_room::v3::Response> {
use create_room::v3::RoomPreset;
can_create_room_check(&services, &body).await?;
can_publish_directory_check(&services, &body).await?;
let sender_user = body.sender_user();
// Figure out preset. We need it for preset specific events
let preset = body
.preset
.clone()
.unwrap_or(match &body.visibility {
| room::Visibility::Public => RoomPreset::PublicChat,
| _ => RoomPreset::PrivateChat, // Room visibility should not be custom
});
if !services.globals.allow_room_creation()
&& body.appservice_info.is_none()
&& !services.users.is_admin(sender_user).await
{
return Err!(Request(Forbidden("Room creation has been disabled.",)));
}
let alias: OptionFuture<_> = body
.room_alias_name
.as_ref()
.map(|alias| room_alias_check(&services, alias, body.appservice_info.as_ref()))
.into();
let room_id: OwnedRoomId = match &body.room_id {
| Some(custom_room_id) => custom_room_id_check(&services, custom_room_id)?,
| _ => RoomId::new(&services.server.name),
};
// check if room ID doesn't already exist instead of erroring on auth check
if services
.rooms
.short
.get_shortroomid(&room_id)
.await
.is_ok()
{
return Err!(Request(RoomInUse("Room with that custom room ID already exists",)));
}
if body.visibility == room::Visibility::Public
&& services
.server
.config
.lockdown_public_room_directory
&& !services.users.is_admin(sender_user).await
&& body.appservice_info.is_none()
{
warn!(
"Non-admin user {sender_user} tried to publish {room_id} to the room directory \
while \"lockdown_public_room_directory\" is enabled"
);
if services.server.config.admin_room_notices {
// Determine room version
let (room_version, version_rules) = body
.room_version
.as_ref()
.map_or(Ok(&services.server.config.default_room_version), |version| {
services
.admin
.notice(&format!(
"Non-admin user {sender_user} tried to publish {room_id} to the room \
directory while \"lockdown_public_room_directory\" is enabled"
))
.await;
}
return Err!(Request(Forbidden("Publishing rooms to the room directory is not allowed")));
}
let _short_id = services
.rooms
.short
.get_or_create_shortroomid(&room_id)
.await;
let state_lock = services.rooms.state.mutex.lock(&room_id).await;
let alias: Option<OwnedRoomAliasId> = match body.room_alias_name.as_ref() {
| Some(alias) =>
Some(room_alias_check(&services, alias, body.appservice_info.as_ref()).await?),
| _ => None,
};
let room_version = match body.room_version.clone() {
| Some(room_version) =>
if services
.server
.supported_room_version(&room_version)
{
room_version
} else {
return Err!(Request(UnsupportedRoomVersion(
"This server does not support that room version."
)));
},
| None => services
.server
.config
.default_room_version
.clone(),
};
.supported_room_version(version)
.then_ok_or_else(version, || {
err!(Request(UnsupportedRoomVersion(
"This server does not support room version {version:?}"
)))
})
})
.and_then(|version| Ok((version, room_version::rules(version)?)))?;
let create_content = match &body.creation_content {
| Some(content) => {
use RoomVersionId::*;
let mut content = content
.deserialize_as::<CanonicalJsonObject>()
.map_err(|e| {
err!(Request(BadJson(error!(
"Failed to deserialise content as canonical JSON: {e}"
))))
})?;
match room_version {
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => {
content.insert(
"creator".into(),
json!(&sender_user).try_into().map_err(|e| {
err!(Request(BadJson(debug_error!("Invalid creation content: {e}"))))
})?,
);
},
| _ => {
// V11+ removed the "creator" key
},
}
content.insert(
"room_version".into(),
json!(room_version.as_str())
.try_into()
.map_err(|e| err!(Request(BadJson("Invalid creation content: {e}"))))?,
);
content
},
| None => {
use RoomVersionId::*;
let content = match room_version {
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 =>
RoomCreateEventContent::new_v1(sender_user.to_owned()),
| _ => RoomCreateEventContent::new_v11(),
};
let mut content =
serde_json::from_str::<CanonicalJsonObject>(to_raw_value(&content)?.get())
.unwrap();
content.insert("room_version".into(), json!(room_version.as_str()).try_into()?);
content
},
};
// Error on existing alias before committing to creation.
let alias = alias.await.transpose()?;
// Increment and hold the counter; the room will sync atomically to clients
// which is preferable.
let next_count = services.globals.next_count();
// 1. The room create event
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder {
event_type: TimelineEventType::RoomCreate,
content: to_raw_value(&create_content)?,
state_key: Some(StateKey::new()),
..Default::default()
},
sender_user,
&room_id,
&state_lock,
)
.boxed()
.await?;
// 1. Create the create event.
let (room_id, state_lock) = match version_rules.room_id_format {
| RoomIdFormatVersion::V1 =>
create_create_event_legacy(&services, &body, room_version, &version_rules).await?,
| RoomIdFormatVersion::V2 =>
create_create_event(&services, &body, &preset, room_version, &version_rules)
.await
.map_err(|e| {
err!(Request(InvalidParam("Error while creating m.room.create event: {e}")))
})?,
};
// 2. Let the room creator join
let sender_user = body.sender_user();
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(sender_user.to_string(), &RoomMemberEventContent {
@@ -230,17 +131,14 @@ pub(crate) async fn create_room_route(
.await?;
// 3. Power levels
// Figure out preset. We need it for preset specific events
let preset = body
.preset
.clone()
.unwrap_or(match &body.visibility {
| room::Visibility::Public => RoomPreset::PublicChat,
| _ => RoomPreset::PrivateChat, // Room visibility should not be custom
});
let mut users = BTreeMap::from_iter([(sender_user.to_owned(), int!(100))]);
let mut users = if !version_rules
.authorization
.explicitly_privilege_room_creators
{
BTreeMap::from_iter([(sender_user.to_owned(), int!(100))])
} else {
BTreeMap::new()
};
if preset == RoomPreset::TrustedPrivateChat {
for invite in &body.invite {
@@ -260,18 +158,23 @@ pub(crate) async fn create_room_route(
continue;
}
users.insert(invite.clone(), int!(100));
if !version_rules
.authorization
.additional_room_creators
{
users.insert(invite.clone(), int!(100));
}
}
}
let power_levels_content = default_power_levels_content(
&version_rules,
body.power_level_content_override.as_ref(),
&body.visibility,
users,
)?;
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder {
@@ -290,7 +193,6 @@ pub(crate) async fn create_room_route(
// 4. Canonical room alias
if let Some(room_alias_id) = &alias {
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(String::new(), &RoomCanonicalAliasEventContent {
@@ -309,7 +211,6 @@ pub(crate) async fn create_room_route(
// 5.1 Join Rules
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(
@@ -329,7 +230,6 @@ pub(crate) async fn create_room_route(
// 5.2 History Visibility
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(
@@ -345,7 +245,6 @@ pub(crate) async fn create_room_route(
// 5.3 Guest Access
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(
@@ -365,7 +264,7 @@ pub(crate) async fn create_room_route(
// 6. Events listed in initial_state
for event in &body.initial_state {
let mut pdu_builder = event
.deserialize_as::<PduBuilder>()
.deserialize_as_unchecked::<PduBuilder>()
.map_err(|e| {
err!(Request(InvalidParam(warn!("Invalid initial state event: {e:?}"))))
})?;
@@ -394,7 +293,6 @@ pub(crate) async fn create_room_route(
}
services
.rooms
.timeline
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &state_lock)
.boxed()
@@ -404,7 +302,6 @@ pub(crate) async fn create_room_route(
// 7. Events implied by name and topic
if let Some(name) = &body.name {
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(String::new(), &RoomNameEventContent::new(name.clone())),
@@ -418,10 +315,12 @@ pub(crate) async fn create_room_route(
if let Some(topic) = &body.topic {
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(String::new(), &RoomTopicEventContent { topic: topic.clone() }),
PduBuilder::state(String::new(), &RoomTopicEventContent {
topic: topic.clone(),
topic_block: TopicContentBlock::default(),
}),
sender_user,
&room_id,
&state_lock,
@@ -433,43 +332,50 @@ pub(crate) async fn create_room_route(
drop(next_count);
drop(state_lock);
// 8. Events implied by invite (and TODO: invite_3pid)
for user_id in &body.invite {
if services
.users
.user_is_ignored(sender_user, user_id)
// if inviting anyone with room creation and invite check passes
if (!body.invite.is_empty() || !body.invite_3pid.is_empty())
&& invite_check(&services, sender_user, &room_id)
.await
{
continue;
} else if services
.users
.user_is_ignored(user_id, sender_user)
.await
{
// silently drop the invite to the recipient if they've been ignored by the
// sender, pretend it worked
continue;
}
.is_ok()
{
// 8. Events implied by invite (and TODO: invite_3pid)
for user_id in &body.invite {
if services
.users
.user_is_ignored(sender_user, user_id)
.await
{
continue;
} else if services
.users
.user_is_ignored(user_id, sender_user)
.await
{
// silently drop the invite to the recipient if they've been ignored by the
// sender, pretend it worked
continue;
}
if let Err(e) =
invite_helper(&services, sender_user, user_id, &room_id, None, body.is_direct)
if let Err(e) = services
.membership
.invite(sender_user, user_id, &room_id, None, body.is_direct)
.boxed()
.await
{
warn!(%e, "Failed to send invite");
{
warn!(%e, "Failed to send invite");
}
}
}
// Homeserver specific stuff
if let Some(alias) = alias {
services
.rooms
.alias
.set_alias(&alias, &room_id, sender_user)?;
}
if body.visibility == room::Visibility::Public {
services.rooms.directory.set_public(&room_id);
services.directory.set_public(&room_id);
if services.server.config.admin_room_notices {
services
@@ -488,25 +394,243 @@ pub(crate) async fn create_room_route(
Ok(create_room::v3::Response::new(room_id))
}
async fn create_create_event(
services: &Services,
body: &Ruma<create_room::v3::Request>,
preset: &RoomPreset,
room_version: &RoomVersionId,
version_rules: &RoomVersionRules,
) -> Result<(OwnedRoomId, RoomMutexGuard)> {
let _sender_user = body.sender_user();
let mut create_content = match &body.creation_content {
| Some(content) => {
let mut content = content
.deserialize_as_unchecked::<CanonicalJsonObject>()
.map_err(|e| {
err!(Request(BadJson(error!(
"Failed to deserialise content as canonical JSON: {e}"
))))
})?;
if !services.config.federate_created_rooms {
if !services.config.allow_federation || !content.contains_key("m.federate") {
content.insert("m.federate".into(), json!(false).try_into()?);
}
}
content.insert(
"room_version".into(),
json!(room_version.as_str())
.try_into()
.map_err(|e| err!(Request(BadJson("Invalid creation content: {e}"))))?,
);
content
},
| None => {
let content = RoomCreateEventContent::new_v11();
let mut content =
serde_json::from_str::<CanonicalJsonObject>(to_raw_value(&content)?.get())?;
if !services.config.federate_created_rooms {
content.insert("m.federate".into(), json!(false).try_into()?);
}
content.insert("room_version".into(), json!(room_version.as_str()).try_into()?);
content
},
};
if version_rules
.authorization
.additional_room_creators
{
let mut additional_creators = body
.creation_content
.as_ref()
.and_then(|c| {
c.deserialize_as_unchecked::<CreationContent>()
.ok()
})
.unwrap_or_default()
.additional_creators;
if *preset == RoomPreset::TrustedPrivateChat {
additional_creators.extend(body.invite.clone());
}
additional_creators.sort();
additional_creators.dedup();
if !additional_creators.is_empty() {
create_content
.insert("additional_creators".into(), json!(additional_creators).try_into()?);
}
}
// 1. The room create event, using a placeholder room_id
let room_id = ruma::room_id!("!thiswillbereplaced").to_owned();
let state_lock = services.state.mutex.lock(&room_id).await;
let create_event_id = services
.timeline
.build_and_append_pdu(
PduBuilder {
event_type: TimelineEventType::RoomCreate,
content: to_raw_value(&create_content)?,
state_key: Some(StateKey::new()),
..Default::default()
},
body.sender_user(),
&room_id,
&state_lock,
)
.boxed()
.await?;
drop(state_lock);
// The real room_id is now the event_id.
let room_id = OwnedRoomId::from_parts('!', create_event_id.localpart(), None)?;
let state_lock = services.state.mutex.lock(&room_id).await;
Ok((room_id, state_lock))
}
async fn create_create_event_legacy(
services: &Services,
body: &Ruma<create_room::v3::Request>,
room_version: &RoomVersionId,
_version_rules: &RoomVersionRules,
) -> Result<(OwnedRoomId, RoomMutexGuard)> {
let room_id: OwnedRoomId = match &body.room_id {
| None => RoomId::new_v1(&services.server.name),
| Some(custom_id) => custom_room_id_check(services, custom_id).await?,
};
let state_lock = services.state.mutex.lock(&room_id).await;
let _short_id = services
.short
.get_or_create_shortroomid(&room_id)
.await;
let create_content = match &body.creation_content {
| Some(content) => {
use RoomVersionId::*;
let mut content = content
.deserialize_as_unchecked::<CanonicalJsonObject>()
.map_err(|e| {
err!(Request(BadJson(error!(
"Failed to deserialise content as canonical JSON: {e}"
))))
})?;
match room_version {
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 => {
content.insert(
"creator".into(),
json!(body.sender_user())
.try_into()
.map_err(|e| {
err!(Request(BadJson(debug_error!(
"Invalid creation content: {e}"
))))
})?,
);
},
| _ => {
// V11+ removed the "creator" key
},
}
if !services.config.federate_created_rooms {
if !services.config.allow_federation || !content.contains_key("m.federate") {
content.insert("m.federate".into(), json!(false).try_into()?);
}
}
content.insert(
"room_version".into(),
json!(room_version.as_str())
.try_into()
.map_err(|e| err!(Request(BadJson("Invalid creation content: {e}"))))?,
);
content
},
| None => {
use RoomVersionId::*;
let content = match room_version {
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 =>
RoomCreateEventContent::new_v1(body.sender_user().to_owned()),
| _ => RoomCreateEventContent::new_v11(),
};
let mut content =
serde_json::from_str::<CanonicalJsonObject>(to_raw_value(&content)?.get())?;
if !services.config.federate_created_rooms {
content.insert("m.federate".into(), json!(false).try_into()?);
}
content.insert("room_version".into(), json!(room_version.as_str()).try_into()?);
content
},
};
// 1. The room create event
services
.timeline
.build_and_append_pdu(
PduBuilder {
event_type: TimelineEventType::RoomCreate,
content: to_raw_value(&create_content)?,
state_key: Some(StateKey::new()),
..Default::default()
},
body.sender_user(),
&room_id,
&state_lock,
)
.boxed()
.await?;
Ok((room_id, state_lock))
}
/// creates the power_levels_content for the PDU builder
fn default_power_levels_content(
version_rules: &RoomVersionRules,
power_level_content_override: Option<&Raw<RoomPowerLevelsEventContent>>,
visibility: &room::Visibility,
users: BTreeMap<OwnedUserId, Int>,
) -> Result<serde_json::Value> {
use serde_json::to_value;
let mut power_levels_content =
to_value(RoomPowerLevelsEventContent { users, ..Default::default() })?;
let mut power_levels_content = RoomPowerLevelsEventContent::new(&version_rules.authorization);
power_levels_content.users = users;
let mut power_levels_content = to_value(power_levels_content)?;
// secure proper defaults of sensitive/dangerous permissions that moderators
// (power level 50) should not have easy access to
power_levels_content["events"]["m.room.power_levels"] = to_value(100)?;
power_levels_content["events"]["m.room.server_acl"] = to_value(100)?;
power_levels_content["events"]["m.room.tombstone"] = to_value(100)?;
power_levels_content["events"]["m.room.encryption"] = to_value(100)?;
power_levels_content["events"]["m.room.history_visibility"] = to_value(100)?;
if version_rules
.authorization
.explicitly_privilege_room_creators
{
power_levels_content["events"]["m.room.tombstone"] = to_value(150)?;
} else {
power_levels_content["events"]["m.room.tombstone"] = to_value(100)?;
}
// always allow users to respond (not post new) to polls. this is primarily
// useful in read-only announcement rooms that post a public poll.
power_levels_content["events"]["org.matrix.msc3381.poll.response"] = to_value(0)?;
@@ -554,8 +678,8 @@ async fn room_alias_check(
// check if room alias is forbidden
if services
.globals
.forbidden_alias_names()
.config
.forbidden_alias_names
.is_match(room_alias_name)
{
return Err!(Request(Unknown("Room alias name is forbidden.")));
@@ -572,7 +696,6 @@ async fn room_alias_check(
})?;
if services
.rooms
.alias
.resolve_local_alias(&full_room_alias)
.await
@@ -599,11 +722,11 @@ async fn room_alias_check(
}
/// if a room is being created with a custom room ID, run our checks against it
fn custom_room_id_check(services: &Services, custom_room_id: &str) -> Result<OwnedRoomId> {
async fn custom_room_id_check(services: &Services, custom_room_id: &str) -> Result<OwnedRoomId> {
// apply forbidden room alias checks to custom room IDs too
if services
.globals
.forbidden_alias_names()
.config
.forbidden_alias_names
.is_match(custom_room_id)
{
return Err!(Request(Unknown("Custom room ID is forbidden.")));
@@ -623,8 +746,64 @@ fn custom_room_id_check(services: &Services, custom_room_id: &str) -> Result<Own
let server_name = services.globals.server_name();
let full_room_id = format!("!{custom_room_id}:{server_name}");
OwnedRoomId::parse(full_room_id)
.map_err(Into::into)
let room_id = OwnedRoomId::parse(full_room_id)
.inspect(|full_room_id| debug_info!(?full_room_id, "Full custom room ID"))
.inspect_err(|e| warn!(?e, ?custom_room_id, "Failed to create room with custom room ID",))
.inspect_err(|e| {
warn!(?e, ?custom_room_id, "Failed to create room with custom room ID");
})?;
// check if room ID doesn't already exist instead of erroring on auth check
if services
.short
.get_shortroomid(&room_id)
.await
.is_ok()
{
return Err!(Request(RoomInUse("Room with that custom room ID already exists",)));
}
Ok(room_id)
}
async fn can_publish_directory_check(
services: &Services,
body: &Ruma<create_room::v3::Request>,
) -> Result {
if !services
.server
.config
.lockdown_public_room_directory
|| body.appservice_info.is_some()
|| body.visibility != room::Visibility::Public
|| services.users.is_admin(body.sender_user()).await
{
return Ok(());
}
let msg = format!(
"Non-admin user {} tried to publish new to the directory while \
lockdown_public_room_directory is enabled",
body.sender_user(),
);
warn!("{msg}");
if services.server.config.admin_room_notices {
services.admin.notice(&msg).await;
}
Err!(Request(Forbidden("Publishing rooms to the room directory is not allowed")))
}
async fn can_create_room_check(
services: &Services,
body: &Ruma<create_room::v3::Request>,
) -> Result {
if !services.config.allow_room_creation
&& body.appservice_info.is_none()
&& !services.users.is_admin(body.sender_user()).await
{
return Err!(Request(Forbidden("Room creation has been disabled.",)));
}
Ok(())
}
-2
View File
@@ -16,13 +16,11 @@ pub(crate) async fn get_room_event_route(
let room_id = &body.room_id;
let event = services
.rooms
.timeline
.get_pdu(event_id)
.map_err(|_| err!(Request(NotFound("Event {} not found.", event_id))));
let visible = services
.rooms
.state_accessor
.user_can_see_event(body.sender_user(), room_id, event_id)
.map(Ok);
+1 -9
View File
@@ -17,7 +17,6 @@ pub(crate) async fn room_initial_sync_route(
let room_id = &body.room_id;
if !services
.rooms
.state_accessor
.user_can_see_state_events(body.sender_user(), room_id)
.await
@@ -26,19 +25,13 @@ pub(crate) async fn room_initial_sync_route(
}
let membership = services
.rooms
.state_cache
.user_membership(body.sender_user(), room_id)
.map(Ok);
let visibility = services
.rooms
.directory
.visibility(room_id)
.map(Ok);
let visibility = services.directory.visibility(room_id).map(Ok);
let state = services
.rooms
.state_accessor
.room_state_full_pdus(room_id)
.map_ok(Event::into_format)
@@ -46,7 +39,6 @@ pub(crate) async fn room_initial_sync_route(
let limit = LIMIT_MAX;
let events = services
.rooms
.timeline
.pdus_rev(None, room_id, None)
.try_take(limit)
+58 -92
View File
@@ -1,7 +1,7 @@
use axum::extract::State;
use axum_client_ip::InsecureClientIp;
use futures::{
FutureExt, StreamExt,
FutureExt, StreamExt, TryFutureExt,
future::{OptionFuture, join3},
stream::FuturesUnordered,
};
@@ -12,7 +12,7 @@ use ruma::{
federation::space::{SpaceHierarchyParentSummary, get_hierarchy},
},
events::room::member::MembershipState,
space::SpaceRoomJoinRule::{self, *},
room::{JoinRuleSummary, RoomSummary},
};
use tuwunel_core::{
Err, Result, debug_warn, trace,
@@ -34,8 +34,8 @@ use crate::{Ruma, RumaResponse};
pub(crate) async fn get_room_summary_legacy(
State(services): State<crate::State>,
InsecureClientIp(client): InsecureClientIp,
body: Ruma<get_summary::msc3266::Request>,
) -> Result<RumaResponse<get_summary::msc3266::Response>> {
body: Ruma<get_summary::v1::Request>,
) -> Result<RumaResponse<get_summary::v1::Response>> {
get_room_summary(State(services), InsecureClientIp(client), body)
.boxed()
.await
@@ -51,15 +51,14 @@ pub(crate) async fn get_room_summary_legacy(
pub(crate) async fn get_room_summary(
State(services): State<crate::State>,
InsecureClientIp(client): InsecureClientIp,
body: Ruma<get_summary::msc3266::Request>,
) -> Result<get_summary::msc3266::Response> {
body: Ruma<get_summary::v1::Request>,
) -> Result<get_summary::v1::Response> {
let (room_id, servers) = services
.rooms
.alias
.resolve_with_servers(&body.room_id_or_alias, Some(body.via.clone()))
.maybe_resolve_with_servers(&body.room_id_or_alias, Some(body.via.clone()))
.await?;
if services.rooms.metadata.is_banned(&room_id).await {
if services.metadata.is_banned(&room_id).await {
return Err!(Request(Forbidden("This room is banned on this homeserver.")));
}
@@ -73,9 +72,8 @@ async fn room_summary_response(
room_id: &RoomId,
servers: &[OwnedServerName],
sender_user: Option<&UserId>,
) -> Result<get_summary::msc3266::Response> {
) -> Result<get_summary::v1::Response> {
if services
.rooms
.state_cache
.server_in_room(services.globals.server_name(), room_id)
.await
@@ -85,23 +83,12 @@ async fn room_summary_response(
.await;
}
let room =
remote_room_summary_hierarchy_response(services, room_id, servers, sender_user).await?;
let summary = remote_room_summary_hierarchy_response(services, room_id, servers, sender_user)
.await?
.summary;
Ok(get_summary::msc3266::Response {
room_id: room_id.to_owned(),
canonical_alias: room.canonical_alias,
avatar_url: room.avatar_url,
guest_can_join: room.guest_can_join,
name: room.name,
num_joined_members: room.num_joined_members,
topic: room.topic,
world_readable: room.world_readable,
join_rule: room.join_rule,
room_type: room.room_type,
room_version: room.room_version,
encryption: room.encryption,
allowed_room_ids: room.allowed_room_ids,
Ok(get_summary::v1::Response {
summary,
membership: sender_user
.is_some()
.then_some(MembershipState::Leave),
@@ -112,22 +99,13 @@ async fn local_room_summary_response(
services: &Services,
room_id: &RoomId,
sender_user: Option<&UserId>,
) -> Result<get_summary::msc3266::Response> {
) -> Result<get_summary::v1::Response> {
trace!(?sender_user, "Sending local room summary response for {room_id:?}");
let join_rule = services
.rooms
.state_accessor
.get_join_rules(room_id);
let join_rule = services.state_accessor.get_join_rules(room_id);
let world_readable = services
.rooms
.state_accessor
.is_world_readable(room_id);
let world_readable = services.state_accessor.is_world_readable(room_id);
let guest_can_join = services
.rooms
.state_accessor
.guest_can_join(room_id);
let guest_can_join = services.state_accessor.guest_can_join(room_id);
let (join_rule, world_readable, guest_can_join) =
join3(join_rule, world_readable, guest_can_join).await;
@@ -139,55 +117,43 @@ async fn local_room_summary_response(
&join_rule.clone().into(),
guest_can_join,
world_readable,
join_rule.allowed_rooms(),
join_rule.allowed_room_ids(),
sender_user,
)
.await?;
let canonical_alias = services
.rooms
.state_accessor
.get_canonical_alias(room_id)
.ok();
let name = services
.rooms
.state_accessor
.get_name(room_id)
.ok();
let name = services.state_accessor.get_name(room_id).ok();
let topic = services
.rooms
.state_accessor
.get_room_topic(room_id)
.ok();
let room_type = services
.rooms
.state_accessor
.get_room_type(room_id)
.ok();
let avatar_url = services
.rooms
.state_accessor
.get_avatar(room_id)
.map(|res| res.into_option().unwrap_or_default().url);
.map_ok(|content| content.url)
.ok()
.map(Option::flatten);
let room_version = services
.rooms
.state
.get_room_version(room_id)
.ok();
let room_version = services.state.get_room_version(room_id).ok();
let encryption = services
.rooms
.state_accessor
.get_room_encryption(room_id)
.ok();
let num_joined_members = services
.rooms
.state_cache
.room_joined_count(room_id)
.unwrap_or(0);
@@ -195,7 +161,6 @@ async fn local_room_summary_response(
let membership: OptionFuture<_> = sender_user
.map(|sender_user| {
services
.rooms
.state_accessor
.get_member(room_id, sender_user)
.map_ok_or(MembershipState::Leave, |content| content.membership)
@@ -224,24 +189,22 @@ async fn local_room_summary_response(
membership,
);
Ok(get_summary::msc3266::Response {
room_id: room_id.to_owned(),
canonical_alias,
avatar_url,
guest_can_join,
name,
num_joined_members: num_joined_members.try_into().unwrap_or_default(),
topic,
world_readable,
room_type,
room_version,
encryption,
Ok(get_summary::v1::Response {
summary: RoomSummary {
room_id: room_id.to_owned(),
canonical_alias,
avatar_url,
guest_can_join,
name,
num_joined_members: num_joined_members.try_into().unwrap_or_default(),
topic,
world_readable,
room_type,
room_version,
encryption,
join_rule: join_rule.into(),
},
membership,
allowed_room_ids: join_rule
.allowed_rooms()
.map(Into::into)
.collect(),
join_rule: join_rule.into(),
})
}
@@ -257,7 +220,7 @@ async fn remote_room_summary_hierarchy_response(
return Err!(Request(Forbidden("Federation is disabled.")));
}
if services.rooms.metadata.is_disabled(room_id).await {
if services.metadata.is_disabled(room_id).await {
return Err!(Request(Forbidden(
"Federaton of room {room_id} is currently disabled on this server."
)));
@@ -277,10 +240,11 @@ async fn remote_room_summary_hierarchy_response(
while let Some(Ok(response)) = requests.next().await {
trace!("{response:?}");
let room = response.room.clone();
if room.room_id != room_id {
let summary = &room.summary;
if summary.room_id != room_id {
debug_warn!(
"Room ID {} returned does not belong to the requested room ID {}",
room.room_id,
summary.room_id,
room_id
);
continue;
@@ -289,10 +253,10 @@ async fn remote_room_summary_hierarchy_response(
return user_can_see_summary(
services,
room_id,
&room.join_rule,
room.guest_can_join,
room.world_readable,
room.allowed_room_ids.iter().map(AsRef::as_ref),
&summary.join_rule,
summary.guest_can_join,
summary.world_readable,
summary.join_rule.allowed_room_ids(),
sender_user,
)
.await
@@ -308,7 +272,7 @@ async fn remote_room_summary_hierarchy_response(
async fn user_can_see_summary<'a, I>(
services: &Services,
room_id: &RoomId,
join_rule: &SpaceRoomJoinRule,
join_rule: &JoinRuleSummary,
guest_can_join: bool,
world_readable: bool,
allowed_room_ids: I,
@@ -317,23 +281,25 @@ async fn user_can_see_summary<'a, I>(
where
I: Iterator<Item = &'a RoomId> + Send,
{
let is_public_room = matches!(join_rule, Public | Knock | KnockRestricted);
let is_public_room = matches!(
join_rule,
JoinRuleSummary::Public | JoinRuleSummary::Knock | JoinRuleSummary::KnockRestricted(_)
);
match sender_user {
| Some(sender_user) => {
let user_can_see_state_events = services
.rooms
.state_accessor
.user_can_see_state_events(sender_user, room_id);
let is_guest = services
.users
.is_deactivated(sender_user)
.unwrap_or(false);
let user_in_allowed_restricted_room = allowed_room_ids.stream().any(|room| {
services
.rooms
.state_cache
.is_joined(sender_user, room)
});
let user_in_allowed_restricted_room = allowed_room_ids
.stream()
.any(|room| services.state_cache.is_joined(sender_user, room));
let (user_can_see_state_events, is_guest, user_in_allowed_restricted_room) =
join3(user_can_see_state_events, is_guest, user_in_allowed_restricted_room)
+19 -31
View File
@@ -4,7 +4,7 @@ use axum::extract::State;
use futures::StreamExt;
use ruma::{
CanonicalJsonObject, RoomId, RoomVersionId,
api::client::{error::ErrorKind, room::upgrade_room},
api::client::room::upgrade_room,
events::{
StateEventType, TimelineEventType,
room::{
@@ -14,11 +14,12 @@ use ruma::{
},
},
int,
room_version_rules::RoomIdFormatVersion,
};
use serde_json::{json, value::to_raw_value};
use tuwunel_core::{
Err, Error, Result, err,
matrix::{Event, StateKey, pdu::PduBuilder},
Err, Result, err,
matrix::{Event, StateKey, pdu::PduBuilder, room_version},
};
use crate::Ruma;
@@ -61,33 +62,35 @@ pub(crate) async fn upgrade_room_route(
.server
.supported_room_version(&body.new_version)
{
return Err(Error::BadRequest(
ErrorKind::UnsupportedRoomVersion,
return Err!(Request(UnsupportedRoomVersion(
"This server does not support that room version.",
));
)));
}
if matches!(body.new_version, RoomVersionId::V12) {
return Err!(Request(UnsupportedRoomVersion(
"Upgrading to version 12 is still under development.",
)));
}
let room_version_rules = room_version::rules(&body.new_version)?;
let room_id_format = &room_version_rules.room_id_format;
assert!(*room_id_format == RoomIdFormatVersion::V1, "TODO");
// Create a replacement room
let replacement_room = RoomId::new(services.globals.server_name());
let replacement_room = RoomId::new_v1(services.globals.server_name());
let _short_id = services
.rooms
.short
.get_or_create_shortroomid(&replacement_room)
.await;
let state_lock = services
.rooms
.state
.mutex
.lock(&body.room_id)
.await;
let state_lock = services.state.mutex.lock(&body.room_id).await;
// Send a m.room.tombstone event to the old room to indicate that it is not
// intended to be used any further Fail if the sender does not have the required
// permissions
let tombstone_event_id = services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(StateKey::new(), &RoomTombstoneEventContent {
@@ -102,16 +105,10 @@ pub(crate) async fn upgrade_room_route(
// Change lock to replacement room
drop(state_lock);
let state_lock = services
.rooms
.state
.mutex
.lock(&replacement_room)
.await;
let state_lock = services.state.mutex.lock(&replacement_room).await;
// Get the old room creation event
let mut create_event_content: CanonicalJsonObject = services
.rooms
.state_accessor
.room_state_get_content(&body.room_id, &StateEventType::RoomCreate, "")
.await
@@ -164,7 +161,6 @@ pub(crate) async fn upgrade_room_route(
}
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder {
@@ -183,7 +179,6 @@ pub(crate) async fn upgrade_room_route(
// Join the new room
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder {
@@ -212,7 +207,6 @@ pub(crate) async fn upgrade_room_route(
// Replicate transferable state events to the new room
for event_type in TRANSFERABLE_STATE_EVENTS {
let event_content = match services
.rooms
.state_accessor
.room_state_get(&body.room_id, event_type, "")
.await
@@ -222,7 +216,6 @@ pub(crate) async fn upgrade_room_route(
};
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder {
@@ -240,27 +233,23 @@ pub(crate) async fn upgrade_room_route(
// Moves any local aliases to the new room
let mut local_aliases = services
.rooms
.alias
.local_aliases_for_room(&body.room_id)
.boxed();
while let Some(alias) = local_aliases.next().await {
services
.rooms
.alias
.remove_alias(alias, sender_user)
.await?;
services
.rooms
.alias
.set_alias(alias, &replacement_room, sender_user)?;
}
// Get the old room power levels
let power_levels_event_content: RoomPowerLevelsEventContent = services
.rooms
.state_accessor
.room_state_get_content(&body.room_id, &StateEventType::RoomPowerLevels, "")
.await
@@ -280,7 +269,6 @@ pub(crate) async fn upgrade_room_route(
// Modify the power levels in the old room to prevent sending of events and
// inviting new users
services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder::state(StateKey::new(), &RoomPowerLevelsEventContent {
+1 -10
View File
@@ -87,7 +87,6 @@ async fn category_room_events(
.map(StreamExt::boxed)
.unwrap_or_else(|| {
services
.rooms
.state_cache
.rooms_joined(sender_user)
.map(ToOwned::to_owned)
@@ -110,12 +109,7 @@ async fn category_room_events(
limit,
};
let (count, results) = services
.rooms
.search
.search_pdus(&query)
.await
.ok()?;
let (count, results) = services.search.search_pdus(&query).await.ok()?;
results
.collect::<Vec<_>>()
@@ -187,7 +181,6 @@ async fn category_room_events(
async fn procure_room_state(services: &Services, room_id: &RoomId) -> Result<RoomState> {
let state = services
.rooms
.state_accessor
.room_state_full_pdus(room_id)
.map_ok(Event::into_format)
@@ -208,14 +201,12 @@ async fn check_room_visible(
let is_joined = !check_visible
|| services
.rooms
.state_cache
.is_joined(user_id, room_id)
.await;
let state_visible = !check_state
|| services
.rooms
.state_accessor
.user_can_see_state_events(user_id, room_id)
.await;
+1 -8
View File
@@ -30,16 +30,10 @@ pub(crate) async fn send_message_event_route(
return Err!(Request(Forbidden("Encryption has been disabled")));
}
let state_lock = services
.rooms
.state
.mutex
.lock(&body.room_id)
.await;
let state_lock = services.state.mutex.lock(&body.room_id).await;
if body.event_type == MessageLikeEventType::CallInvite
&& services
.rooms
.directory
.is_public_room(&body.room_id)
.await
@@ -75,7 +69,6 @@ pub(crate) async fn send_message_event_route(
.map_err(|e| err!(Request(BadJson("Invalid JSON body: {e}"))))?;
let event_id = services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder {
+18 -13
View File
@@ -22,20 +22,9 @@ pub(super) async fn handle_login(
_body: &Ruma<Request>,
info: &Token,
) -> Result<OwnedUserId> {
let config = &services.config.jwt;
if !config.enable {
return Err!(Request(Unknown("JWT login is not enabled.")));
}
let claim = validate(config, &info.token)?;
let local = claim.sub.to_lowercase();
let server = &services.server.name;
let user_id = UserId::parse_with_server_name(local, server).map_err(|e| {
err!(Request(InvalidUsername("JWT subject is not a valid user MXID: {e}")))
})?;
let user_id = validate_user(services, &info.token)?;
if !services.users.exists(&user_id).await {
let config = &services.config.jwt;
if !config.register_user {
return Err!(Request(NotFound("User {user_id} is not registered on this server.")));
}
@@ -49,6 +38,22 @@ pub(super) async fn handle_login(
Ok(user_id)
}
pub(crate) fn validate_user(services: &Services, token: &str) -> Result<OwnedUserId> {
let config = &services.config.jwt;
if !config.enable {
return Err!(Request(Unauthorized("JWT login is not enabled.")));
}
let claim = validate(config, token)?;
let local = claim.sub.to_lowercase();
let server = &services.server.name;
let user_id = UserId::parse_with_server_name(local, server).map_err(|e| {
err!(Request(InvalidUsername("JWT subject is not a valid user MXID: {e}")))
})?;
Ok(user_id)
}
fn validate(config: &JwtConfig, token: &str) -> Result<Claim> {
let verifier = init_verifier(config)?;
let validator = init_validator(config)?;
+2
View File
@@ -1,3 +1,4 @@
use futures::FutureExt;
use ruma::{OwnedUserId, UserId};
use tuwunel_core::{Err, Result, debug};
use tuwunel_service::Services;
@@ -63,6 +64,7 @@ pub(super) async fn ldap_login(
services
.admin
.make_user_admin(lowercased_user_id)
.boxed()
.await?;
} else if !is_ldap_admin && is_tuwunel_admin {
services
+1 -1
View File
@@ -1,5 +1,5 @@
mod appservice;
mod jwt;
pub(crate) mod jwt;
mod ldap;
mod logout;
mod password;
+1 -4
View File
@@ -56,10 +56,7 @@ pub(crate) async fn login_token_route(
let mut uiaainfo = uiaa::UiaaInfo {
flows: vec![password_flow],
completed: Vec::new(),
params: Box::default(),
session: None,
auth_error: None,
..Default::default()
};
match &body.auth {
+53 -29
View File
@@ -1,21 +1,21 @@
use std::{
collections::{BTreeSet, VecDeque},
str::FromStr,
};
use std::{collections::BTreeSet, iter::once, str::FromStr};
use axum::extract::State;
use futures::{StreamExt, TryFutureExt, future::OptionFuture};
use futures::{FutureExt, StreamExt, TryFutureExt, future::OptionFuture, stream::FuturesOrdered};
use ruma::{
OwnedRoomId, OwnedServerName, RoomId, UInt, UserId, api::client::space::get_hierarchy,
};
use tuwunel_core::{
Err, Result,
Err, Result, debug_error,
utils::{future::TryExtExt, stream::IterStream},
};
use tuwunel_service::{
Services,
rooms::spaces::{
PaginationToken, SummaryAccessibility, get_parent_children_via, summary_to_chunk,
rooms::{
short::ShortRoomId,
spaces::{
PaginationToken, SummaryAccessibility, get_parent_children_via, summary_to_chunk,
},
},
};
@@ -44,7 +44,7 @@ pub(crate) async fn get_hierarchy_route(
.as_ref()
.and_then(|s| PaginationToken::from_str(s).ok());
// Should prevent unexpeded behaviour in (bad) clients
// Should prevent unexpected behaviour in (bad) clients
if let Some(ref token) = key {
if token.suggested_only != body.suggested_only || token.max_depth != max_depth {
return Err!(Request(InvalidParam(
@@ -77,30 +77,38 @@ async fn get_client_hierarchy<'a, ShortRoomIds>(
short_room_ids: ShortRoomIds,
) -> Result<get_hierarchy::v1::Response>
where
ShortRoomIds: Iterator<Item = &'a u64> + Clone + Send + Sync + 'a,
ShortRoomIds: Iterator<Item = &'a ShortRoomId> + Clone + Send + Sync + 'a,
{
type Via = Vec<OwnedServerName>;
type Entry = (OwnedRoomId, Via);
type Rooms = VecDeque<Entry>;
type Via = Vec<OwnedServerName>;
let mut queue: Rooms = [(
room_id.to_owned(),
room_id
let initial = async move {
let via = room_id
.server_name()
.map(ToOwned::to_owned)
.into_iter()
.collect(),
)]
.into();
.collect::<Vec<_>>();
let mut rooms = Vec::with_capacity(limit);
let mut parents = BTreeSet::new();
while let Some((current_room, via)) = queue.pop_front() {
let summary = services
.rooms
.spaces
.get_summary_and_children_client(&current_room, suggested_only, sender_user, &via)
.await?;
.get_summary_and_children_client(room_id, suggested_only, sender_user, &via)
.await;
(room_id.to_owned(), via, summary)
};
let mut parents = BTreeSet::new();
let mut rooms = Vec::with_capacity(limit);
let mut queue: FuturesOrdered<_> = once(initial.boxed()).collect();
while let Some((current_room, via, summary)) = queue.next().await {
let summary = match summary {
| Ok(summary) => summary,
| Err(e) => {
debug_error!(?current_room, ?via, ?e, "error getting summary");
continue;
},
};
match (summary, current_room == room_id) {
| (None | Some(SummaryAccessibility::Inaccessible), false) => {
@@ -130,7 +138,6 @@ where
.stream()
.skip_while(|(room, _)| {
services
.rooms
.short
.get_shortroomid(room)
.map_ok(|short| {
@@ -159,20 +166,37 @@ where
continue;
}
queue.extend(children);
children
.into_iter()
.map(|(room_id, via)| async move {
let summary = services
.spaces
.get_summary_and_children_client(
&room_id,
suggested_only,
sender_user,
&via,
)
.await;
(room_id, via, summary)
})
.map(FutureExt::boxed)
.for_each(|entry| queue.push_back(entry));
},
}
}
let next_batch: OptionFuture<_> = queue
.pop_front()
.map(async |(room, _)| {
.next()
.await
.map(async |(room, ..)| {
parents.insert(room);
let next_short_room_ids: Vec<_> = parents
.iter()
.stream()
.filter_map(|room_id| services.rooms.short.get_shortroomid(room_id).ok())
.filter_map(|room_id| services.short.get_shortroomid(room_id).ok())
.collect()
.await;
+54 -59
View File
@@ -2,7 +2,7 @@ use axum::extract::State;
use futures::{FutureExt, TryFutureExt, TryStreamExt};
use ruma::{
OwnedEventId, RoomId, UserId,
api::client::state::{get_state_events, get_state_events_for_key, send_state_event},
api::client::state::{get_state_event_for_key, get_state_events, send_state_event},
events::{
AnyStateEventContent, StateEventType,
room::{
@@ -78,7 +78,6 @@ pub(crate) async fn get_state_events_route(
let sender_user = body.sender_user();
if !services
.rooms
.state_accessor
.user_can_see_state_events(sender_user, &body.room_id)
.await
@@ -88,7 +87,6 @@ pub(crate) async fn get_state_events_route(
Ok(get_state_events::v3::Response {
room_state: services
.rooms
.state_accessor
.room_state_full_pdus(&body.room_id)
.map_ok(Event::into_format)
@@ -107,12 +105,11 @@ pub(crate) async fn get_state_events_route(
/// readable
pub(crate) async fn get_state_events_for_key_route(
State(services): State<crate::State>,
body: Ruma<get_state_events_for_key::v3::Request>,
) -> Result<get_state_events_for_key::v3::Response> {
body: Ruma<get_state_event_for_key::v3::Request>,
) -> Result<get_state_event_for_key::v3::Response> {
let sender_user = body.sender_user();
if !services
.rooms
.state_accessor
.user_can_see_state_events(sender_user, &body.room_id)
.await
@@ -123,7 +120,6 @@ pub(crate) async fn get_state_events_for_key_route(
}
let event = services
.rooms
.state_accessor
.room_state_get(&body.room_id, &body.event_type, &body.state_key)
.await
@@ -140,7 +136,7 @@ pub(crate) async fn get_state_events_for_key_route(
.as_ref()
.is_some_and(|f| f.to_lowercase().eq("event"));
Ok(get_state_events_for_key::v3::Response {
Ok(get_state_event_for_key::v3::Response {
content: event_format.or(|| event.get_content_as_value()),
event: event_format.then(|| {
json!({
@@ -167,8 +163,8 @@ pub(crate) async fn get_state_events_for_key_route(
/// readable
pub(crate) async fn get_state_events_for_empty_key_route(
State(services): State<crate::State>,
body: Ruma<get_state_events_for_key::v3::Request>,
) -> Result<RumaResponse<get_state_events_for_key::v3::Response>> {
body: Ruma<get_state_event_for_key::v3::Request>,
) -> Result<RumaResponse<get_state_event_for_key::v3::Response>> {
get_state_events_for_key_route(State(services), body)
.await
.map(RumaResponse)
@@ -184,9 +180,8 @@ async fn send_state_event_for_key_helper(
timestamp: Option<ruma::MilliSecondsSinceUnixEpoch>,
) -> Result<OwnedEventId> {
allowed_to_send_state_event(services, room_id, event_type, state_key, json).await?;
let state_lock = services.rooms.state.mutex.lock(room_id).await;
let state_lock = services.state.mutex.lock(room_id).await;
let event_id = services
.rooms
.timeline
.build_and_append_pdu(
PduBuilder {
@@ -200,6 +195,7 @@ async fn send_state_event_for_key_helper(
room_id,
&state_lock,
)
.boxed()
.await?;
Ok(event_id)
@@ -222,7 +218,7 @@ async fn allowed_to_send_state_event(
| StateEventType::RoomServerAcl => {
// prevents common ACL paw-guns as ACL management is difficult and prone to
// irreversible mistakes
match json.deserialize_as::<RoomServerAclEventContent>() {
match json.deserialize_as_unchecked::<RoomServerAclEventContent>() {
| Ok(acl_content) => {
if acl_content.allow_is_empty() {
return Err!(Request(BadJson(debug_warn!(
@@ -282,7 +278,7 @@ async fn allowed_to_send_state_event(
// admin room is a sensitive room, it should not ever be made public
if let Ok(admin_room_id) = services.admin.get_admin_room().await {
if admin_room_id == room_id {
match json.deserialize_as::<RoomJoinRulesEventContent>() {
match json.deserialize_as_unchecked::<RoomJoinRulesEventContent>() {
| Ok(join_rule) =>
if join_rule.join_rule == JoinRule::Public {
return Err!(Request(Forbidden(
@@ -301,7 +297,7 @@ async fn allowed_to_send_state_event(
| StateEventType::RoomHistoryVisibility => {
// admin room is a sensitive room, it should not ever be made world readable
if let Ok(admin_room_id) = services.admin.get_admin_room().await {
match json.deserialize_as::<RoomHistoryVisibilityEventContent>() {
match json.deserialize_as_unchecked::<RoomHistoryVisibilityEventContent>() {
| Ok(visibility_content) => {
if admin_room_id == room_id
&& visibility_content.history_visibility
@@ -322,7 +318,7 @@ async fn allowed_to_send_state_event(
}
},
| StateEventType::RoomCanonicalAlias => {
match json.deserialize_as::<RoomCanonicalAliasEventContent>() {
match json.deserialize_as_unchecked::<RoomCanonicalAliasEventContent>() {
| Ok(canonical_alias_content) => {
let mut aliases = canonical_alias_content.alt_aliases.clone();
@@ -332,9 +328,8 @@ async fn allowed_to_send_state_event(
for alias in aliases {
let (alias_room_id, _servers) = services
.rooms
.alias
.resolve_alias(&alias, None)
.resolve_alias(&alias)
.await
.map_err(|e| {
err!(Request(BadAlias("Failed resolving alias \"{alias}\": {e}")))
@@ -354,52 +349,52 @@ async fn allowed_to_send_state_event(
},
}
},
| StateEventType::RoomMember => match json.deserialize_as::<RoomMemberEventContent>() {
| Ok(membership_content) => {
let Ok(_state_key) = UserId::parse(state_key) else {
return Err!(Request(BadJson(
"Membership event has invalid or non-existent state key"
)));
};
if let Some(authorising_user) =
membership_content.join_authorized_via_users_server
{
if membership_content.membership != MembershipState::Join {
| StateEventType::RoomMember =>
match json.deserialize_as_unchecked::<RoomMemberEventContent>() {
| Ok(membership_content) => {
let Ok(_state_key) = UserId::parse(state_key) else {
return Err!(Request(BadJson(
"join_authorised_via_users_server is only for member joins"
"Membership event has invalid or non-existent state key"
)));
}
};
if !services.globals.user_is_local(&authorising_user) {
return Err!(Request(InvalidParam(
"Authorising user {authorising_user} does not belong to this \
homeserver"
)));
}
if let Some(authorising_user) =
membership_content.join_authorized_via_users_server
{
if membership_content.membership != MembershipState::Join {
return Err!(Request(BadJson(
"join_authorised_via_users_server is only for member joins"
)));
}
services
.rooms
.state_cache
.is_joined(&authorising_user, room_id)
.map(is_false!())
.map(BoolExt::into_result)
.map_err(|()| {
err!(Request(InvalidParam(
"Authorising user {authorising_user} is not in the room. They \
cannot authorise the join."
)))
})
.await?;
}
if !services.globals.user_is_local(&authorising_user) {
return Err!(Request(InvalidParam(
"Authorising user {authorising_user} does not belong to this \
homeserver"
)));
}
services
.state_cache
.is_joined(&authorising_user, room_id)
.map(is_false!())
.map(BoolExt::into_result)
.map_err(|()| {
err!(Request(InvalidParam(
"Authorising user {authorising_user} is not in the room. \
They cannot authorise the join."
)))
})
.await?;
}
},
| Err(e) => {
return Err!(Request(BadJson(
"Membership content must have a valid JSON body with at least a valid \
membership state: {e}"
)));
},
},
| Err(e) => {
return Err!(Request(BadJson(
"Membership content must have a valid JSON body with at least a valid \
membership state: {e}"
)));
},
},
| _ => (),
}
+12 -22
View File
@@ -1,25 +1,17 @@
mod v3;
mod v5;
use futures::{StreamExt, pin_mut};
use ruma::{
RoomId, UserId,
events::TimelineEventType::{
self, Beacon, CallInvite, PollStart, RoomEncrypted, RoomMessage, Sticker,
},
};
use futures::{FutureExt, StreamExt, pin_mut};
use ruma::{RoomId, UserId};
use tuwunel_core::{
Error, PduCount, Result,
matrix::pdu::PduEvent,
utils::stream::{BroadbandExt, ReadyExt, TryIgnore},
utils::stream::{BroadbandExt, ReadyExt},
};
use tuwunel_service::Services;
pub(crate) use self::{v3::sync_events_route, v5::sync_events_v5_route};
pub(crate) const DEFAULT_BUMP_TYPES: &[TimelineEventType; 6] =
&[CallInvite, PollStart, Beacon, RoomEncrypted, RoomMessage, Sticker];
async fn load_timeline(
services: &Services,
sender_user: &UserId,
@@ -27,22 +19,20 @@ async fn load_timeline(
roomsincecount: PduCount,
next_batch: Option<PduCount>,
limit: usize,
) -> Result<(Vec<(PduCount, PduEvent)>, bool), Error> {
) -> Result<(Vec<(PduCount, PduEvent)>, bool, PduCount), Error> {
let last_timeline_count = services
.rooms
.timeline
.last_timeline_count(Some(sender_user), room_id)
.last_timeline_count(Some(sender_user), room_id, next_batch)
.await?;
if last_timeline_count <= roomsincecount {
return Ok((Vec::new(), false));
return Ok((Vec::new(), false, last_timeline_count));
}
let non_timeline_pdus = services
.rooms
.timeline
.pdus_rev(Some(sender_user), room_id, None)
.ignore_err()
.ready_filter_map(Result::ok)
.ready_skip_while(|&(pducount, _)| pducount > next_batch.unwrap_or_else(PduCount::max))
.ready_take_while(|&(pducount, _)| pducount > roomsincecount);
@@ -52,15 +42,17 @@ async fn load_timeline(
.by_ref()
.take(limit)
.collect()
.map(|mut pdus: Vec<_>| {
pdus.reverse();
pdus
})
.await;
let timeline_pdus: Vec<_> = timeline_pdus.into_iter().rev().collect();
// They /sync response doesn't always return all messages, so we say the output
// is limited unless there are events in non_timeline_pdus
let limited = non_timeline_pdus.next().await.is_some();
Ok((timeline_pdus, limited))
Ok((timeline_pdus, limited, last_timeline_count))
}
async fn share_encrypted_room(
@@ -70,14 +62,12 @@ async fn share_encrypted_room(
ignore_room: Option<&RoomId>,
) -> bool {
services
.rooms
.state_cache
.get_shared_rooms(sender_user, user_id)
.ready_filter(|&room_id| Some(room_id) != ignore_room)
.map(ToOwned::to_owned)
.broad_any(async |other_room_id| {
services
.rooms
.state_accessor
.is_encrypted_room(&other_room_id)
.await
+230 -267
View File
@@ -5,8 +5,8 @@ use std::{
use axum::extract::State;
use futures::{
FutureExt, StreamExt, TryFutureExt, TryStreamExt,
future::{OptionFuture, join, join3, join4, join5, try_join4},
FutureExt, StreamExt, TryFutureExt,
future::{OptionFuture, join, join3, join4, join5},
pin_mut,
};
use ruma::{
@@ -18,7 +18,7 @@ use ruma::{
v3::{
Ephemeral, Filter, GlobalAccountData, InviteState, InvitedRoom, JoinedRoom,
KnockState, KnockedRoom, LeftRoom, Presence, RoomAccountData, RoomSummary, Rooms,
State as RoomState, Timeline, ToDevice,
State as RoomState, StateEvents, Timeline, ToDevice,
},
},
uiaa::UiaaResponse,
@@ -36,7 +36,11 @@ use ruma::{
};
use tokio::time;
use tuwunel_core::{
Result, at, err, error, extract_variant, is_equal_to,
Error, Result, at,
debug::INFO_SPAN_LEVEL,
err, error,
error::{inspect_debug_log, inspect_log},
extract_variant, is_equal_to,
matrix::{
Event,
event::Matches,
@@ -49,7 +53,6 @@ use tuwunel_core::{
self, BoolExt, FutureBoolExt, IterStream, ReadyExt, TryFutureExtExt,
future::{OptionStream, ReadyEqExt},
math::ruma_from_u64,
result::LogErr,
stream::{BroadbandExt, Tools, TryExpect, WidebandExt},
},
warn,
@@ -125,15 +128,16 @@ pub(crate) async fn sync_events_route(
) -> Result<sync_events::v3::Response, RumaResponse<UiaaResponse>> {
let (sender_user, sender_device) = body.sender();
// Presence update
if services.config.allow_local_presence {
services
.presence
.ping_presence(sender_user, &body.body.set_presence)
.await
.log_err()
.ok();
}
let ping_presence = services
.presence
.maybe_ping_presence(sender_user, &body.body.set_presence)
.inspect_err(inspect_log)
.ok();
// Record user as actively syncing for push suppression heuristic.
let note_sync = services.presence.note_sync(sender_user);
join(ping_presence, note_sync).await;
let mut since = body
.body
@@ -159,10 +163,18 @@ pub(crate) async fn sync_events_route(
.expect("configuration must limit maximum timeout");
loop {
let watchers = services.sync.watch(sender_user, sender_device);
let next_batch = services.globals.wait_pending().await?;
let watch_rooms = services
.state_cache
.rooms_joined(sender_user)
.chain(services.state_cache.rooms_invited(sender_user));
let watchers = services
.sync
.watch(sender_user, sender_device, watch_rooms);
let next_batch = services.globals.wait_pending().await?;
debug_assert!(since <= next_batch, "next_batch is monotonic");
if since < next_batch || body.body.full_state {
let response = build_sync_events(&services, &body, since, next_batch).await?;
let empty = response.rooms.is_empty()
@@ -177,9 +189,10 @@ pub(crate) async fn sync_events_route(
}
// Wait for activity
if time::timeout_at(stop_at, watchers).await.is_err() {
if time::timeout_at(stop_at, watchers).await.is_err() || services.server.is_stopping() {
let response = build_empty_response(&services, &body, next_batch).await;
trace!(since, next_batch, "empty response");
return Ok(sync_events::v3::Response::new(next_batch.to_string()));
return Ok(response);
}
trace!(
@@ -194,9 +207,24 @@ pub(crate) async fn sync_events_route(
}
}
async fn build_empty_response(
services: &Services,
body: &Ruma<sync_events::v3::Request>,
next_batch: u64,
) -> sync_events::v3::Response {
sync_events::v3::Response {
device_one_time_keys_count: services
.users
.count_one_time_keys(body.sender_user(), body.sender_device())
.await,
..sync_events::v3::Response::new(next_batch.to_string())
}
}
#[tracing::instrument(
name = "build",
level = "debug",
level = INFO_SPAN_LEVEL,
ret(level = "trace"),
skip_all,
fields(
@@ -225,9 +253,9 @@ async fn build_sync_events(
};
let joined_rooms = services
.rooms
.state_cache
.rooms_joined(sender_user)
.ready_filter(|&room_id| filter.room.matches(room_id))
.map(ToOwned::to_owned)
.broad_filter_map(|room_id| {
load_joined_room(
@@ -258,9 +286,9 @@ async fn build_sync_events(
);
let left_rooms = services
.rooms
.state_cache
.rooms_left(sender_user)
.rooms_left_state(sender_user)
.ready_filter(|(room_id, _)| filter.room.matches(room_id))
.broad_filter_map(|(room_id, _)| {
handle_left_room(
services,
@@ -278,12 +306,11 @@ async fn build_sync_events(
.collect();
let invited_rooms = services
.rooms
.state_cache
.rooms_invited(sender_user)
.rooms_invited_state(sender_user)
.ready_filter(|(room_id, _)| filter.room.matches(room_id))
.fold_default(async |mut invited_rooms: BTreeMap<_, _>, (room_id, invite_state)| {
let invite_count = services
.rooms
.state_cache
.get_invite_count(&room_id, sender_user)
.await
@@ -303,12 +330,11 @@ async fn build_sync_events(
});
let knocked_rooms = services
.rooms
.state_cache
.rooms_knocked(sender_user)
.rooms_knocked_state(sender_user)
.ready_filter(|(room_id, _)| filter.room.matches(room_id))
.fold_default(async |mut knocked_rooms: BTreeMap<_, _>, (room_id, knock_state)| {
let knock_count = services
.rooms
.state_cache
.get_knock_count(&room_id, sender_user)
.await
@@ -330,7 +356,7 @@ async fn build_sync_events(
let presence_updates: OptionFuture<_> = services
.config
.allow_local_presence
.then(|| process_presence_updates(services, since, next_batch, sender_user))
.then(|| process_presence_updates(services, since, next_batch, sender_user, &filter))
.into();
let account_data = services
@@ -386,7 +412,7 @@ async fn build_sync_events(
// If the user doesn't share an encrypted room with the target anymore, we need
// to tell them
let device_list_left: HashSet<_> = left_encrypted_users
let device_list_left = left_encrypted_users
.into_iter()
.stream()
.broad_filter_map(async |user_id: OwnedUserId| {
@@ -409,8 +435,8 @@ async fn build_sync_events(
Ok(sync_events::v3::Response {
account_data: GlobalAccountData { events: account_data },
device_lists: DeviceLists {
left: device_list_left,
changed: device_list_updates.into_iter().collect(),
left: device_list_left.into_iter().collect(),
},
device_one_time_keys_count,
// Fallback keys are not yet supported
@@ -433,13 +459,14 @@ async fn process_presence_updates(
since: u64,
next_batch: u64,
syncing_user: &UserId,
filter: &FilterDefinition,
) -> PresenceUpdates {
services
.presence
.presence_since(since, Some(next_batch))
.ready_filter(|(user_id, ..)| filter.presence.matches(user_id))
.filter(|(user_id, ..)| {
services
.rooms
.state_cache
.user_sees_user(syncing_user, user_id)
})
@@ -452,6 +479,7 @@ async fn process_presence_updates(
})
.map(|(user_id, event)| (user_id.to_owned(), event.content))
.collect()
.boxed()
.await
}
@@ -475,7 +503,6 @@ async fn handle_left_room(
filter: &FilterDefinition,
) -> Result<Option<LeftRoom>> {
let left_count = services
.rooms
.state_cache
.get_left_count(room_id, sender_user)
.await
@@ -504,11 +531,11 @@ async fn handle_left_room(
return Ok(None);
}
let is_not_found = services.rooms.metadata.exists(room_id).eq(&false);
let is_not_found = services.metadata.exists(room_id).eq(&false);
let is_disabled = services.rooms.metadata.is_disabled(room_id);
let is_disabled = services.metadata.is_disabled(room_id);
let is_banned = services.rooms.metadata.is_banned(room_id);
let is_banned = services.metadata.is_banned(room_id);
pin_mut!(is_not_found, is_disabled, is_banned);
if is_not_found.or(is_disabled).or(is_banned).await {
@@ -525,9 +552,9 @@ async fn handle_left_room(
unsigned: None,
// The following keys are dropped on conversion
room_id: room_id.clone(),
prev_events: vec![],
prev_events: Default::default(),
auth_events: Default::default(),
depth: uint!(1),
auth_events: vec![],
redacts: None,
hashes: EventHash::default(),
signatures: None,
@@ -540,32 +567,31 @@ async fn handle_left_room(
prev_batch: Some(next_batch.to_string()),
events: Vec::new(),
},
state: RoomState { events: vec![event.into_format()] },
state: RoomState::Before(StateEvents { events: vec![event.into_format()] }),
}));
}
let mut left_state_events = Vec::new();
let since_shortstatehash = services
.rooms
.user
.get_token_shortstatehash(room_id, since);
.timeline
.prev_shortstatehash(room_id, PduCount::Normal(since).saturating_add(1))
.await
.ok();
let since_state_ids: HashMap<_, OwnedEventId> = since_shortstatehash
.map_ok(|since_shortstatehash| {
.map(|since_shortstatehash| {
services
.rooms
.state_accessor
.state_full_ids(since_shortstatehash)
.map(Ok)
})
.try_flatten_stream()
.try_collect()
.await
.unwrap_or_default();
.into_iter()
.stream()
.flatten()
.collect()
.await;
let Ok(left_event_id): Result<OwnedEventId> = services
.rooms
.state_accessor
.room_state_get_id(room_id, &StateEventType::RoomMember, sender_user.as_str())
.await
@@ -575,8 +601,7 @@ async fn handle_left_room(
};
let Ok(left_shortstatehash) = services
.rooms
.state_accessor
.state
.pdu_shortstatehash(&left_event_id)
.await
else {
@@ -585,14 +610,12 @@ async fn handle_left_room(
};
let mut left_state_ids: HashMap<_, _> = services
.rooms
.state_accessor
.state_full_ids(left_shortstatehash)
.collect()
.await;
let leave_shortstatekey = services
.rooms
.short
.get_or_create_shortstatekey(&StateEventType::RoomMember, sender_user.as_str())
.await;
@@ -602,7 +625,6 @@ async fn handle_left_room(
for (shortstatekey, event_id) in left_state_ids {
if full_state || since_state_ids.get(&shortstatekey) != Some(&event_id) {
let (event_type, state_key) = services
.rooms
.short
.get_statekey_from_short(shortstatekey)
.await?;
@@ -618,7 +640,7 @@ async fn handle_left_room(
continue;
}
let Ok(pdu) = services.rooms.timeline.get_pdu(&event_id).await else {
let Ok(pdu) = services.timeline.get_pdu(&event_id).await else {
error!("Pdu in state not found: {event_id}");
continue;
};
@@ -635,7 +657,7 @@ async fn handle_left_room(
prev_batch: Some(next_batch.to_string()),
events: Vec::new(), // and so we dont need to set this to empty vec
},
state: RoomState { events: left_state_events },
state: RoomState::Before(StateEvents { events: left_state_events }),
}))
}
@@ -658,22 +680,7 @@ async fn load_joined_room(
full_state: bool,
filter: &FilterDefinition,
) -> Result<(JoinedRoom, HashSet<OwnedUserId>, HashSet<OwnedUserId>)> {
let sincecount = PduCount::Normal(since);
let next_batchcount = PduCount::Normal(next_batch);
let current_shortstatehash = services
.rooms
.state
.get_room_shortstatehash(room_id)
.map_err(|_| err!(Database(error!("Room {room_id} has no state"))));
let since_shortstatehash = services
.rooms
.user
.get_token_shortstatehash(room_id, since)
.ok()
.map(Ok);
let initial = since == 0;
let timeline_limit: usize = filter
.room
.timeline
@@ -681,17 +688,40 @@ async fn load_joined_room(
.unwrap_or_else(|| uint!(10))
.try_into()?;
let timeline = load_timeline(
let (timeline_pdus, limited, last_timeline_count) = load_timeline(
services,
sender_user,
room_id,
sincecount,
Some(next_batchcount),
PduCount::Normal(since),
Some(PduCount::Normal(next_batch)),
timeline_limit,
);
)
.await?;
let since_shortstatehash = services
.timeline
.prev_shortstatehash(room_id, PduCount::Normal(since).saturating_add(1))
.ok();
let horizon_shortstatehash: OptionFuture<_> = timeline_pdus
.first()
.map(at!(0))
.map(|count| {
services
.timeline
.get_shortstatehash(room_id, count)
.inspect_err(inspect_debug_log)
})
.into();
let current_shortstatehash = services
.timeline
.get_shortstatehash(room_id, last_timeline_count)
.inspect_err(inspect_debug_log)
.or_else(|_| services.state.get_room_shortstatehash(room_id))
.map_err(|_| err!(Database(error!("Room {room_id} has no state"))));
let receipt_events = services
.rooms
.read_receipt
.readreceipts_since(room_id, since, Some(next_batch))
.filter_map(async |(read_user, _, edu)| {
@@ -701,39 +731,32 @@ async fn load_joined_room(
.await
.or_some((read_user.to_owned(), edu))
})
.collect::<HashMap<OwnedUserId, Raw<AnySyncEphemeralRoomEvent>>>()
.map(Ok);
.collect::<HashMap<OwnedUserId, Raw<AnySyncEphemeralRoomEvent>>>();
let (current_shortstatehash, since_shortstatehash, (timeline_pdus, limited), receipt_events) =
try_join4(current_shortstatehash, since_shortstatehash, timeline, receipt_events)
.boxed()
.await?;
let encrypted_room = services.state_accessor.is_encrypted_room(room_id);
// State was changed after the cutoff for this sync; similar to other handlers.
if current_shortstatehash > next_batch {
// Transfer the since_shortstatehash not the current over to the next sync.
if let Some(since_shortstatehash) = since_shortstatehash {
services
.rooms
.user
.associate_token_shortstatehash(room_id, next_batch, since_shortstatehash)
.await;
}
let (
(since_shortstatehash, horizon_shortstatehash, current_shortstatehash),
receipt_events,
encrypted_room,
) = join3(
join3(since_shortstatehash, horizon_shortstatehash, current_shortstatehash),
receipt_events,
encrypted_room,
)
.map(|((since, horizon, current), receipt, encrypted_room)| {
Ok::<_, Error>(((since, horizon.flat_ok(), current?), receipt, encrypted_room))
})
.boxed()
.await?;
return Ok((JoinedRoom::default(), HashSet::new(), HashSet::new()));
}
let lazy_load_options =
[&filter.room.state.lazy_load_options, &filter.room.timeline.lazy_load_options];
let associate_token = services
.rooms
.user
.associate_token_shortstatehash(room_id, next_batch, current_shortstatehash);
let lazy_loading_enabled = filter.room.state.lazy_load_options.is_enabled()
|| filter
.room
.timeline
.lazy_load_options
.is_enabled();
let lazy_loading_enabled = !encrypted_room
&& lazy_load_options
.iter()
.any(|opts| opts.is_enabled());
let lazy_loading_context = &lazy_loading::Context {
user_id: sender_user,
@@ -743,16 +766,9 @@ async fn load_joined_room(
options: Some(&filter.room.state.lazy_load_options),
};
let initial = since == 0 || since_shortstatehash.is_none();
// Reset lazy loading because this is an initial sync
let lazy_load_reset: OptionFuture<_> = initial
.then(|| {
services
.rooms
.lazy_loading
.reset(lazy_loading_context)
})
.then(|| services.lazy_loading.reset(lazy_loading_context))
.into();
lazy_load_reset.await;
@@ -767,74 +783,50 @@ async fn load_joined_room(
.collect();
services
.rooms
.lazy_loading
.witness_retain(witness, lazy_loading_context)
})
.into();
let horizon_shortstatehash: OptionFuture<_> = timeline_pdus
.iter()
.map(at!(0))
.map(PduCount::into_unsigned)
.map(|shorteventid| {
let sender_joined_count = services
.state_cache
.get_joined_count(room_id, sender_user);
let since_encryption: OptionFuture<_> = since_shortstatehash
.map(|shortstatehash| {
services
.rooms
.state_accessor
.get_shortstatehash(shorteventid)
.state_get(shortstatehash, &StateEventType::RoomEncryption, "")
})
.next()
.into();
let last_privateread_update = services
.read_receipt
.last_privateread_update(sender_user, room_id);
let last_notification_read: OptionFuture<_> = timeline_pdus
.is_empty()
.then(|| {
services
.rooms
.user
.last_notification_read(sender_user, room_id)
})
.into();
let since_sender_member: OptionFuture<_> = since_shortstatehash
.map(|short| {
services
.rooms
.state_accessor
.state_get_content(short, &StateEventType::RoomMember, sender_user.as_str())
.ok()
})
.into();
let encrypted_room = services
.rooms
.state_accessor
.state_get(current_shortstatehash, &StateEventType::RoomEncryption, "")
.is_ok();
let last_privateread_update = services
.rooms
.read_receipt
.last_privateread_update(sender_user, room_id);
let (
(last_privateread_update, last_notification_read),
(sender_joined_count, since_encryption),
witness,
(encrypted_room, last_privateread_update, last_notification_read),
(since_sender_member, horizon_shortstatehash, ()),
) = join3(
join(last_privateread_update, last_notification_read),
join(sender_joined_count, since_encryption),
witness,
join3(encrypted_room, last_privateread_update, last_notification_read),
join3(since_sender_member, horizon_shortstatehash, associate_token),
)
.boxed()
.await;
let joined_since_last_sync =
since_sender_member
.flatten()
.is_none_or(|content: RoomMemberEventContent| {
content.membership != MembershipState::Join
});
let _encrypted_since_last_sync = !initial && encrypted_room && since_encryption.is_none();
let joined_since_last_sync = sender_joined_count.is_ok_and(|count| count > since);
let StateChanges {
heroes,
@@ -845,19 +837,15 @@ async fn load_joined_room(
services,
sender_user,
room_id,
full_state,
encrypted_room,
full_state || initial,
since_shortstatehash,
horizon_shortstatehash.flat_ok(),
horizon_shortstatehash,
current_shortstatehash,
joined_since_last_sync,
witness.as_ref(),
)
.await?;
let send_notification_counts =
last_notification_read.is_none_or(|last_count| last_count.gt(&since));
let is_sender_membership = |event: &PduEvent| {
*event.event_type() == StateEventType::RoomMember.into()
&& event
@@ -865,19 +853,29 @@ async fn load_joined_room(
.is_some_and(is_equal_to!(sender_user.as_str()))
};
let joined_sender_member: Option<_> = (joined_since_last_sync && timeline_pdus.is_empty())
.then(|| {
state_events
.iter()
.position(is_sender_membership)
.map(|pos| state_events.swap_remove(pos))
})
.flatten();
let joined_sender_member: Option<_> =
(joined_since_last_sync && timeline_pdus.is_empty() && !initial)
.then(|| {
state_events
.iter()
.position(is_sender_membership)
.map(|pos| state_events.swap_remove(pos))
})
.flatten();
let prev_batch = timeline_pdus.first().map(at!(0)).or_else(|| {
joined_sender_member
.is_some()
.then_some(since)
.map(Into::into)
});
let send_notification_counts =
last_notification_read.is_none_or(|last_count| last_count.gt(&since));
let notification_count: OptionFuture<_> = send_notification_counts
.then(|| {
services
.rooms
.user
.notification_count(sender_user, room_id)
.map(TryInto::try_into)
@@ -888,7 +886,6 @@ async fn load_joined_room(
let highlight_count: OptionFuture<_> = send_notification_counts
.then(|| {
services
.rooms
.user
.highlight_count(sender_user, room_id)
.map(TryInto::try_into)
@@ -900,7 +897,6 @@ async fn load_joined_room(
.gt(&since)
.then(|| {
services
.rooms
.read_receipt
.private_read_get(room_id, sender_user)
.map(Result::ok)
@@ -908,7 +904,6 @@ async fn load_joined_room(
.into();
let typing_events = services
.rooms
.typing
.last_typing_update(room_id)
.and_then(async |count| {
@@ -922,19 +917,26 @@ async fn load_joined_room(
})
.unwrap_or(Vec::new());
let keys_changed = services
.users
.room_keys_changed(room_id, since, Some(next_batch))
.map(|(user_id, _)| user_id)
.map(ToOwned::to_owned)
.collect::<Vec<_>>();
let extract_membership = |event: &PduEvent| {
let content: RoomMemberEventContent = event.get_content().ok()?;
let user_id: OwnedUserId = event.state_key()?.parse().ok()?;
Some((content, user_id))
Some((content.membership, user_id))
};
let timeline_membership_changes: Vec<_> = timeline_pdus
let timeline_membership_changes = timeline_pdus
.iter()
.map(ref_at!(1))
.filter(|_| !initial)
.map(ref_at!(1))
.filter_map(extract_membership)
.collect();
.collect::<Vec<_>>();
let device_list_updates = state_events
.iter()
@@ -942,31 +944,27 @@ async fn load_joined_room(
.ready_filter(|_| !initial)
.ready_filter(|state_event| *state_event.event_type() == RoomMember)
.ready_filter_map(extract_membership)
.chain(timeline_membership_changes.into_iter().stream())
.fold_default(async |(mut dlu, mut leu): pair_of!(HashSet<_>), (content, user_id)| {
.chain(timeline_membership_changes.stream())
.fold_default(async |(mut dlu, mut leu): pair_of!(HashSet<_>), (membership, user_id)| {
use MembershipState::*;
let shares_encrypted_room = async |user_id| {
share_encrypted_room(services, sender_user, user_id, Some(room_id)).await
let requires_update = async |user_id| {
!share_encrypted_room(services, sender_user, user_id, Some(room_id)).await
};
match content.membership {
match membership {
| Join if requires_update(&user_id).await => dlu.insert(user_id),
| Leave => leu.insert(user_id),
| Join if joined_since_last_sync || !shares_encrypted_room(&user_id).await =>
dlu.insert(user_id),
| _ => false,
};
(dlu, leu)
})
.then(async |(mut dlu, leu)| {
dlu.extend(keys_changed.await);
(dlu, leu)
});
let prev_batch = timeline_pdus.first().map(at!(0)).or_else(|| {
joined_sender_member
.is_some()
.then_some(since)
.map(Into::into)
});
let include_in_timeline = |event: &PduEvent| {
let filter = &filter.room.timeline;
filter.matches(event)
@@ -981,33 +979,26 @@ async fn load_joined_room(
.ready_filter(include_in_timeline)
.collect::<Vec<_>>();
let device_updates = services
.users
.room_keys_changed(room_id, since, Some(next_batch))
.map(|(user_id, _)| user_id)
.map(ToOwned::to_owned)
.collect::<Vec<_>>();
let account_data_events = services
.account_data
.changes_since(Some(room_id), sender_user, since, Some(next_batch))
.changes_since(Some(room_id), sender_user, since, None)
.ready_filter_map(|e| extract_variant!(e, AnyRawAccountDataEvent::Room))
.collect();
let (
(room_events, account_data_events),
(typing_events, private_read_event),
(notification_count, highlight_count),
((mut device_list_updates, left_encrypted_users), device_updates),
(room_events, account_data_events, typing_events, private_read_event),
) = join3(
(device_list_updates, left_encrypted_users),
) = join4(
join(room_events, account_data_events),
join(typing_events, private_read_event),
join(notification_count, highlight_count),
join(device_list_updates, device_updates),
join4(room_events, account_data_events, typing_events, private_read_event),
device_list_updates,
)
.boxed()
.await;
device_list_updates.extend(device_updates);
let is_in_timeline = |event: &PduEvent| {
room_events
.iter()
@@ -1042,7 +1033,7 @@ async fn load_joined_room(
let joined_room = JoinedRoom {
account_data: RoomAccountData { events: account_data_events },
ephemeral: Ephemeral { events: edus },
state: RoomState { events: state_events },
state: RoomState::Before(StateEvents { events: state_events }),
summary: RoomSummary {
joined_member_count: joined_member_count.map(ruma_from_u64),
invited_member_count: invited_member_count.map(ruma_from_u64),
@@ -1069,8 +1060,9 @@ async fn load_joined_room(
skip_all,
fields(
full = %full_state,
cs = %current_shortstatehash,
ss = ?since_shortstatehash,
hs = ?horizon_shortstatehash,
cs = %current_shortstatehash,
)
)]
#[allow(clippy::too_many_arguments)]
@@ -1079,16 +1071,13 @@ async fn calculate_state_changes<'a>(
sender_user: &UserId,
room_id: &RoomId,
full_state: bool,
encrypted_room: bool,
since_shortstatehash: Option<ShortStateHash>,
horizon_shortstatehash: Option<ShortStateHash>,
current_shortstatehash: ShortStateHash,
joined_since_last_sync: bool,
witness: Option<&'a Witness>,
) -> Result<StateChanges> {
let initial = full_state || since_shortstatehash.is_none() || joined_since_last_sync;
let incremental = !initial && since_shortstatehash != Some(current_shortstatehash);
let incremental = !full_state && !joined_since_last_sync && since_shortstatehash.is_some();
let horizon_shortstatehash = horizon_shortstatehash.unwrap_or(current_shortstatehash);
@@ -1096,7 +1085,6 @@ async fn calculate_state_changes<'a>(
let state_get_shorteventid = |user_id: &'a UserId| {
services
.rooms
.state_accessor
.state_get_shortid(
horizon_shortstatehash,
@@ -1107,38 +1095,33 @@ async fn calculate_state_changes<'a>(
};
let lazy_state_ids: OptionFuture<_> = witness
.filter(|_| !encrypted_room)
.map(|witness| {
StreamExt::into_future(
witness
.iter()
.stream()
.broad_filter_map(|user_id| state_get_shorteventid(user_id)),
)
witness
.iter()
.stream()
.ready_filter(|&user_id| user_id != sender_user)
.broad_filter_map(|user_id| state_get_shorteventid(user_id))
.into_future()
})
.into();
let state_diff_ids: OptionFuture<_> = incremental
.then(|| {
StreamExt::into_future(
services
.rooms
.state_accessor
.state_added((since_shortstatehash, horizon_shortstatehash))
.boxed(),
)
services
.state_accessor
.state_added((since_shortstatehash, horizon_shortstatehash))
.boxed()
.into_future()
})
.into();
let current_state_ids: OptionFuture<_> = initial
let current_state_ids: OptionFuture<_> = (!incremental)
.then(|| {
StreamExt::into_future(
services
.rooms
.state_accessor
.state_full_shortids(horizon_shortstatehash)
.expect_ok(),
)
services
.state_accessor
.state_full_shortids(horizon_shortstatehash)
.expect_ok()
.into_future()
})
.into();
@@ -1146,35 +1129,21 @@ async fn calculate_state_changes<'a>(
.stream()
.chain(state_diff_ids.stream())
.broad_filter_map(async |(shortstatekey, shorteventid)| {
if witness.is_none() || encrypted_room {
return Some(shorteventid);
}
lazy_filter(services, sender_user, shortstatekey, shorteventid).await
lazy_filter(services, sender_user, witness, shortstatekey, shorteventid).await
})
.chain(lazy_state_ids.stream())
.broad_filter_map(|shorteventid| {
services
.rooms
.short
.get_eventid_from_short(shorteventid)
.ok()
})
.broad_filter_map(async |event_id: OwnedEventId| {
services
.rooms
.timeline
.get_pdu(&event_id)
.get_pdu_from_shorteventid(shorteventid)
.ok()
.await
})
.collect::<Vec<_>>()
.boxed()
.await;
let send_member_counts = state_events
.iter()
.any(|event| event.kind == RoomMember);
.any(|event| *event.kind() == RoomMember);
let member_counts: OptionFuture<_> = send_member_counts
.then(|| calculate_counts(services, room_id, sender_user))
@@ -1194,11 +1163,15 @@ async fn calculate_state_changes<'a>(
async fn lazy_filter(
services: &Services,
sender_user: &UserId,
witness: Option<&Witness>,
shortstatekey: ShortStateKey,
shorteventid: ShortEventId,
) -> Option<ShortEventId> {
if witness.is_none() {
return Some(shorteventid);
}
let (event_type, state_key) = services
.rooms
.short
.get_statekey_from_short(shortstatekey)
.await
@@ -1214,13 +1187,11 @@ async fn calculate_counts(
sender_user: &UserId,
) -> (Option<u64>, Option<u64>, Option<Vec<OwnedUserId>>) {
let joined_member_count = services
.rooms
.state_cache
.room_joined_count(room_id)
.unwrap_or(0);
let invited_member_count = services
.rooms
.state_cache
.room_invited_count(room_id)
.unwrap_or(0);
@@ -1243,7 +1214,6 @@ async fn calculate_heroes(
sender_user: &UserId,
) -> Vec<OwnedUserId> {
services
.rooms
.timeline
.all_pdus(sender_user, room_id)
.ready_filter(|(_, pdu)| pdu.kind == RoomMember)
@@ -1287,14 +1257,8 @@ async fn fold_hero(
}
let (is_invited, is_joined) = join(
services
.rooms
.state_cache
.is_invited(user_id, room_id),
services
.rooms
.state_cache
.is_joined(user_id, room_id),
services.state_cache.is_invited(user_id, room_id),
services.state_cache.is_joined(user_id, room_id),
)
.await;
@@ -1314,7 +1278,6 @@ async fn typings_event_for_user(
Ok(SyncEphemeralRoomEvent {
content: TypingEventContent {
user_ids: services
.rooms
.typing
.typing_users_for_user(room_id, sender_user)
.await?,
+335 -999
View File
File diff suppressed because it is too large. Load diff
+60
View File
@@ -0,0 +1,60 @@
use futures::{StreamExt, future::join};
use ruma::{api::client::sync::sync_events::v5::response, events::AnyRawAccountDataEvent};
use tuwunel_core::{
Result, extract_variant,
utils::{IterStream, ReadyExt, stream::BroadbandExt},
};
use tuwunel_service::sync::Room;
use super::{Connection, SyncInfo, Window, extension_rooms_selector};
#[tracing::instrument(name = "account_data", level = "trace", skip_all)]
pub(super) async fn collect(
sync_info: SyncInfo<'_>,
conn: &Connection,
window: &Window,
) -> Result<response::AccountData> {
let SyncInfo { services, sender_user, .. } = sync_info;
let implicit = conn
.extensions
.account_data
.lists
.as_deref()
.map(<[_]>::iter);
let explicit = conn
.extensions
.account_data
.rooms
.as_deref()
.map(<[_]>::iter);
let rooms = extension_rooms_selector(sync_info, conn, window, implicit, explicit)
.stream()
.broad_filter_map(async |room_id| {
let &Room { roomsince, .. } = conn.rooms.get(room_id)?;
let changes: Vec<_> = services
.account_data
.changes_since(Some(room_id), sender_user, roomsince, Some(conn.next_batch))
.ready_filter_map(|e| extract_variant!(e, AnyRawAccountDataEvent::Room))
.collect()
.await;
changes
.is_empty()
.eq(&false)
.then(move || (room_id.to_owned(), changes))
})
.collect();
let global = services
.account_data
.changes_since(None, sender_user, conn.globalsince, Some(conn.next_batch))
.ready_filter_map(|e| extract_variant!(e, AnyRawAccountDataEvent::Global))
.collect();
let (global, rooms) = join(global, rooms).await;
Ok(response::AccountData { global, rooms })
}
+218
View File
@@ -0,0 +1,218 @@
use std::collections::HashSet;
use futures::{
FutureExt, StreamExt, TryFutureExt,
future::{OptionFuture, join, join3},
stream::once,
};
use ruma::{
OwnedUserId, RoomId,
api::client::sync::sync_events::{DeviceLists, v5::response},
events::{
StateEventType, TimelineEventType,
room::member::{MembershipState, RoomMemberEventContent},
},
};
use tuwunel_core::{
Result, error,
matrix::{Event, pdu::PduCount},
pair_of,
utils::{
BoolExt, IterStream, ReadyExt, TryFutureExtExt, future::OptionStream,
stream::BroadbandExt,
},
};
use tuwunel_service::sync::Connection;
use super::{SyncInfo, share_encrypted_room};
#[tracing::instrument(name = "e2ee", level = "trace", skip_all)]
pub(super) async fn collect(
sync_info: SyncInfo<'_>,
conn: &Connection,
) -> Result<response::E2EE> {
let SyncInfo { services, sender_user, sender_device, .. } = sync_info;
let keys_changed = services
.users
.keys_changed(sender_user, conn.globalsince, Some(conn.next_batch))
.map(ToOwned::to_owned)
.collect::<HashSet<_>>()
.map(|changed| (changed, HashSet::new()));
let (changed, left) = (HashSet::new(), HashSet::new());
let (changed, left) = services
.state_cache
.rooms_joined(sender_user)
.map(ToOwned::to_owned)
.broad_filter_map(async |room_id| collect_room(sync_info, conn, &room_id).await.ok())
.chain(once(keys_changed))
.ready_fold((changed, left), |(mut changed, mut left), room| {
changed.extend(room.0);
left.extend(room.1);
(changed, left)
})
.await;
let left = left
.into_iter()
.stream()
.filter_map(async |user_id| {
share_encrypted_room(services, sender_user, &user_id, None)
.await
.is_false()
.then_some(user_id)
})
.collect();
let device_one_time_keys_count = services
.users
.last_one_time_keys_update(sender_user)
.then(|since| -> OptionFuture<_> {
since
.gt(&conn.globalsince)
.then(|| {
services
.users
.count_one_time_keys(sender_user, sender_device)
})
.into()
})
.map(Option::unwrap_or_default);
let (left, device_one_time_keys_count) = join(left, device_one_time_keys_count)
.boxed()
.await;
Ok(response::E2EE {
device_one_time_keys_count,
device_unused_fallback_key_types: None,
device_lists: DeviceLists {
changed: changed.into_iter().collect(),
left,
},
})
}
#[tracing::instrument(level = "trace", skip_all, fields(room_id), ret)]
async fn collect_room(
SyncInfo { services, sender_user, .. }: SyncInfo<'_>,
conn: &Connection,
room_id: &RoomId,
) -> Result<pair_of!(HashSet<OwnedUserId>)> {
let current_shortstatehash = services
.state
.get_room_shortstatehash(room_id)
.inspect_err(|e| error!("Room {room_id} has no state: {e}"));
let room_keys_changed = services
.users
.room_keys_changed(room_id, conn.globalsince, Some(conn.next_batch))
.map(|(user_id, _)| user_id)
.map(ToOwned::to_owned)
.collect::<HashSet<_>>();
let (current_shortstatehash, device_list_changed) =
join(current_shortstatehash, room_keys_changed)
.boxed()
.await;
let lists = (device_list_changed, HashSet::new());
let Ok(current_shortstatehash) = current_shortstatehash else {
return Ok(lists);
};
if current_shortstatehash <= conn.globalsince {
return Ok(lists);
}
let Ok(since_shortstatehash) = services
.timeline
.prev_shortstatehash(room_id, PduCount::Normal(conn.globalsince).saturating_add(1))
.await
else {
return Ok(lists);
};
if since_shortstatehash == current_shortstatehash {
return Ok(lists);
}
let encrypted_room = services
.state_accessor
.state_get(current_shortstatehash, &StateEventType::RoomEncryption, "")
.is_ok();
let since_encryption = services
.state_accessor
.state_get(since_shortstatehash, &StateEventType::RoomEncryption, "")
.is_ok();
let sender_joined_count = services
.state_cache
.get_joined_count(room_id, sender_user);
let (encrypted_room, since_encryption, sender_joined_count) =
join3(encrypted_room, since_encryption, sender_joined_count).await;
if !encrypted_room {
return Ok(lists);
}
let encrypted_since_last_sync = !since_encryption;
let joined_since_last_sync = sender_joined_count.is_ok_and(|count| count > conn.globalsince);
let joined_members_burst: OptionFuture<_> = (joined_since_last_sync
|| encrypted_since_last_sync)
.then(|| {
services
.state_cache
.room_members(room_id)
.ready_filter(|&user_id| user_id != sender_user)
.map(ToOwned::to_owned)
.map(|user_id| (MembershipState::Join, user_id))
.into_future()
})
.into();
services
.state_accessor
.state_added((since_shortstatehash, current_shortstatehash))
.broad_filter_map(async |(_shortstatekey, shorteventid)| {
services
.timeline
.get_pdu_from_shorteventid(shorteventid)
.ok()
.await
})
.ready_filter(|event| *event.kind() == TimelineEventType::RoomMember)
.ready_filter(|event| {
event
.state_key()
.is_some_and(|state_key| state_key != sender_user)
})
.ready_filter_map(|event| {
let content: RoomMemberEventContent = event.get_content().ok()?;
let user_id: OwnedUserId = event.state_key()?.parse().ok()?;
Some((content.membership, user_id))
})
.chain(joined_members_burst.stream())
.fold(lists, async |(mut changed, mut left), (membership, user_id)| {
use MembershipState::*;
let should_add = async |user_id| {
!share_encrypted_room(services, sender_user, user_id, Some(room_id)).await
};
match membership {
| Join if should_add(&user_id).await => changed.insert(user_id),
| Leave => left.insert(user_id),
| _ => false,
};
(changed, left)
})
.map(Ok)
.boxed()
.await
}
Loaded 100 of 395 files, more files were not shown because too many files have changed in this diff. Show more