Commit Graph

11152 Commits

Author SHA1 Message Date
Benjamin Bouvier
74bc3dfb6e refactor(event cache): don't hold onto a live instance of the paginator in RoomEventCache
Instead of keeping state for the `Paginator` instance, we create one
when needs be, in the `run_backwards_impl` method, and initialize it
with a previous-batch token. This is simpler than keeping one alive, and
making sure that we reset it in the right places.
2025-02-26 14:09:08 +01:00
Benjamin Bouvier
7841ed8637 refactor(event cache): remove RoomPagination::hit_timeline_end()
The event cache doesn't use the paginator for forwards pagination, so it
doesn't make sense to expose this method. Moreover, the event cache
always listens to sync in real-time, so technically it's always hit the
timeline end.

As a proof of this, this method wasn't even tested.
2025-02-26 14:09:08 +01:00
Doug
19df945155 fix(ffi): Correctly indicate OIDC support when fetching metadata fails. matrix-sdk-ffi/20250225 2025-02-25 19:24:07 +02:00
Damir Jelić
3e3bff76de fixup! feat(crypto): Add support for the shared_history flag defined in MSC3061 2025-02-25 16:52:23 +01:00
Damir Jelić
ea073f55f0 doc(crypto): Document all the arguments of the InboundGroupSession::new method 2025-02-25 16:52:23 +01:00
Damir Jelić
c1e28aa156 test(crypto): Add a snapshot test for the inbound group session pickle 2025-02-25 16:52:23 +01:00
Damir Jelić
af62f09e37 test(crypto): Test that the shared history flag gets set when we ourselves crate a session 2025-02-25 16:52:23 +01:00
Damir Jelić
9a33385697 test(crypto): Test that the shared history flag gets set when creating sessions 2025-02-25 16:52:23 +01:00
Damir Jelić
bfa89bc73f feat(crypto): Add support for the shared_history flag defined in MSC3061
This patch adds support for the `shared_history` flag from MSC3061 to
the `m.room_key` content, exported room keys, and backed-up room keys.

The flag is now persisted in our `InboundGroupSession`. Additionally,
when creating a new `InboundGroupSession`, we ensure the
`shared_history`  flag is set appropriately.

MSC3061: https://github.com/matrix-org/matrix-spec-proposals/pull/3061
2025-02-25 16:52:23 +01:00
Damir Jelić
e1d05fa53c refactor(crypto): Use struct destructuring instead of separate field access in some places
In several places, we access almost all the fields of a struct to
create an `InboundGroupSession` from a pure data struct.

When new fields are added to these data structs, it's easy to
overlook updating the `InboundGroupSession` accordingly.

By using struct destructuring, we ensure that newly added fields  are
explicitly considered, making it harder to forget one of the newly added
fields.
2025-02-25 16:52:23 +01:00
Damir Jelić
b0ccc94b26 refactor(crypto): Simplify some tests by using a session created from a helper function 2025-02-25 16:52:23 +01:00
Damir Jelić
b2356a0232 doc(crypto): Improve the documentation for the encrypted Content serialization
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Signed-off-by: Damir Jelić <poljar@termina.org.uk>
2025-02-25 15:58:42 +01:00
Damir Jelić
3bb883387e refactor(crypto): Use the DecryptedOlmV1Event type when encrypting to-device events
This ensures that new fields that are added to the
`m.olm.v1.curve25519-aes-sha` content need to be added in a single
place.
2025-02-25 15:58:42 +01:00
Damir Jelić
506a36b210 fix(crypto): Fix the serialization of DecryptedOlmV1Event 2025-02-25 15:58:42 +01:00
Damir Jelić
8c1966a237 refactor(crypto): Don't require event_type to return a static string 2025-02-25 15:58:42 +01:00
Kévin Commaille
09513eaa5e refactor(oidc): Only support authorization URL parameters defined in MSCs
`prompt=create` is defined in MSC2964, and
`login_hint=mxid:@user:server.name` is defined in MSC4198.
The other parameters came from OpenID Connect.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-25 15:34:36 +01:00
Kévin Commaille
fda9177a70 refactor(oidc): Remove support for Pushed Authorization Requests
It is a small optimization which makes the URL smaller, but it is not
part of the next-gen auth MSCs and is not supported by the oauth2 crate,
so let's drop it.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-25 15:34:36 +01:00
Benjamin Bouvier
21960a5ba2 chore(event cache): add more logs to the auto-shrinking mechanism 2025-02-25 14:13:33 +01:00
Benjamin Bouvier
0819ab1dad refactor(event cache): apply review comments of #4708 2025-02-25 12:28:28 +01:00
Ivan Enderlin
475ad79360 fix(sdk): RoomEventCache::event looks inside the store.
This patch fixes `RoomEventCache::event` to look inside `RoomEvents` but
also inside the `EventCacheStore` to look for an event. It ultimately
fallbacks to `AllEventsCache` because we can't get rid of it for the
moment.
2025-02-25 12:07:17 +01:00
Ivan Enderlin
7b52306ff2 feat(base): Add EventCacheStore::find_event.
This patch adds the method `find_event` on the `EventCacheStore` trait.
It helps to find a single event from the store.
2025-02-25 12:07:17 +01:00
Benjamin Bouvier
e5f6d026ff ci: use an hardcoded version of cargo-machete in CI (#4710)
Should resolve the CI issues around cargo-machete.

See also:
https://github.com/bnjbvr/cargo-machete/issues/156#issuecomment-2681308436
2025-02-25 11:35:18 +01:00
Benjamin Bouvier
5dd5710758 feat(event cache): auto-shrink a room event cache's chunk after all listeners are left matrix-sdk-ffi/20252502 2025-02-24 17:40:50 +01:00
Ivan Enderlin
37b62dfed1 test(sdk): Add a big test for a deduplication + event removals.
This patch adds a test for deduplication that covers unloaded and loaded
chunk with event removals in both, with a finaly backwards pagination.
Yummy.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
d21a4152de chore(sdk): Code cleanup.
This patch puts the `Ok` outside the `match` for a better ergonomics.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
8c2dcd7b5d task(sdk): Make the code more robust around event removals.
This patch makes the code more robust around event removals. Sorting
events by their position is no longer done in the `Deduplicator` but in
a new `RoomEventCacheState::remove_events` method, which removes events
in the store and in the `RoomEvents`. This method is responsible to sort
events, this stuff is less fragile like so.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
019b4a20f6 chore(common): Rename EmptyChunk to EmptyChunkRule.
This patch renames `EmptyChunk` into `EmptyChunkRule`. Name suggested by
@stefanceriu, it makes a lot more sense, thanks!
2025-02-24 17:37:47 +01:00
Ivan Enderlin
30a9a972ce tes(sdk): Deduplicator dispatches duplicated events in memory vs in store.
This patch tests that `Deduplicator` dispatches duplicated events in the
correct field of `DeduplicationOutcome`.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
22ba1684b2 chore(sdk): Rename a test helper and some variables.
Nothing fancy here. Just regular chore tasks.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
0b12ec2b38 test(sdk): Deduplicator excludes invalid events.
This patch adds a test ensuring that `Deduplicator` excludes invalid
events, i.e. event with no ID.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
a71f5bf21f test(sdk): Test Deduplicator filters events in the input.
This patch adds a test ensuring that `Deduplicator` is able to find
duplicates in its own inputs.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
9bd7cfda5f test(sdk): Rename a test. 2025-02-24 17:37:47 +01:00
Ivan Enderlin
c1a13f7f98 test(sdk): Test sort_events_by_position_descending.
This patch adds a test for `sort_events_by_position_descending`. It
also updates this function so that events are sorted by their chunk
identifier from newest to oldest, it makes no difference but it matches
the order of the position indices too. Everything “dimension” is
descending.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
a362584bb3 task(sdk): Use DeduplicationOutcome to remove events in their correct place.
This patch uses `DeduplicationOutcome` to remove events either in
memory, or in the store, when required. The `remove_events_by_id` method
has been renamed `remove_events_by_position`.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
f9ce7628ff task(sdk): Redesign Deduplicator::filter_duplicate_events.
This patch redesigns `Deduplicator::filter_duplicate_events`.

First off, `filter_duplicate_events` does remove events with no valid
ID. At the same time, it removes duplicate events within the new events
(`events`). This check was done in the `BloomFilterDeduplicator` but
not in the `StoreDeduplicator`. Now it's done at the front of these
implementations, directly inside `Deduplicator`.

Second, this patch introduces `DeduplicationOutcome` to replace the
return type `(Vec<Event>, Vec<OwnedEventId>)`, especially because
now it would have become `(Vec<Event>, Vec<(OwnedEventId, Position)>,
Vec<(OwnedEventId, Position)>)`. Why?

1. Because the positions of the duplicated events are returned,
2. We differentiate between in-memory vs. in-store duplicated events.

Third, now there are positions associated to duplicated events, events
must be sorted. It's the role of `sort_events_by_position_descending`.

This way, `DeduplicatorOutcome` brings guarantees and less checks are
required.
2025-02-24 17:37:47 +01:00
Ivan Enderlin
43c066e837 task(base): EventCacheStore::filter_duplicated_events returns Position.
This patch changes `EventCacheStore::filter_duplicated_events` to return
the `Position` of the duplicated event.
2025-02-24 17:37:47 +01:00
Benjamin Bouvier
f3f37a33fd fix(event cache): override reached_start when there's a mismatch between network and disk
It could be that we have a mismatch between network and disk, after
running a back-pagination:

- network indicates start of the timeline, aka there's no previous-batch
token
- but in the persisted storage, we do have an initial empty events chunk

Because of this, we could have weird transitions from "I've reached the
start of the room" to "I haven't actually reached it", if calling the
`run_backwards()` method manually.

This patch rewrites the logic when returning `reached_start`, so that
it's more precise:

- when reloading an events chunk from disk, rely on the previous chunk
property to indicate whether we've reached the start of the timeline,
thus avoiding unnecessary calls to back-paginations.
- after resolving a gap via the network, override the result of
`reached_start` with a boolean that indicates 1. there are no more gaps
and 2. there's no previous chunk (actual previous or lazily-loaded).

In the future, we should consider NOT having empty events chunks, if we
can.
2025-02-24 14:47:21 +01:00
Benjamin Bouvier
39c6481f96 feat(event cache): include the lazy previous chunk in the debug string, if available 2025-02-24 14:47:21 +01:00
Benjamin Bouvier
66b9d334ef feat(event cache): shrink the linked chunk upon gappy syncs 2025-02-24 14:47:21 +01:00
Benjamin Bouvier
e64cb2c4f1 feat(event cache): implement RoomEventCacheState::shrink_to_last_chunk 2025-02-24 14:47:21 +01:00
Benjamin Bouvier
4f47868930 feat(linked chunk): allow replacing a linked chunk's content with a raw chunk 2025-02-24 14:47:21 +01:00
Benjamin Bouvier
4c115b6ad5 feat(event cache): don't store a gap if we've deduplicated all events during sync 2025-02-24 14:47:21 +01:00
Benjamin Bouvier
242a1047bd doc(event cache): clarify that RoomEvents::updates() is only for storage updates
And rename it accordingly to `RoomEvents::store_updates`.

Note: no changelog, because this is an internal API only.
2025-02-24 14:47:21 +01:00
Kévin Commaille
2f3cab431f chore: Add changelog for Oidc::logout
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 14:19:48 +01:00
Kévin Commaille
55f514897b refactor(oidc): Only revoke one token for logout
The server is supposed to revoke any token associated with the token that we revoke.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 14:19:48 +01:00
Kévin Commaille
d4b92de8e4 refactor(oidc): Remove support for OIDC RP-Initiated logout
Token revocation was split out from MSC2964 to MSC4254, and RP-Initiated
logout is now mentioned only as an alternative.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 14:19:48 +01:00
Kévin Commaille
25d39997a4 chore: Add changelog for moving qrcode module
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 13:39:23 +01:00
Kévin Commaille
254ce8923b refactor(oidc): Use OidcBackend with LoginWithQrCode
Will allow to share code when the backend is switched to the oauth2 crate too.

It will also allow to expose the device authorization grant directly in Oidc, if necessary.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 13:39:23 +01:00
Kévin Commaille
0a4db305b9 refactor(oidc): Move qrcode module inside oidc
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2025-02-24 13:39:23 +01:00
Benjamin Bouvier
90ac2181e9 test: rename some MatrixMockServer helpers functions to make it clear they're matchers
The `.from()`, `.with_delay()` and `.limit()` functions are not very
explicit about what they did, and the `with_delay` one in particular led
me to think that it would introduce a delay *in the response*, while it
indicated a delay was expected as part of the matched URL.

Instead, this patch proposes to prefix all matchers with `match_`, to
make it clearer that… they will match the incoming query: match_from,
match_delay, match_limit.

Thanks to this change, the `RoomMessagesResponseTemplate` can be renamed
from `delayed` to `with_delay`, which was my original intent, before I
noticed another `with_delay` with totally different semantics.
2025-02-24 11:09:25 +01:00