Commit Graph

125 Commits

Author SHA1 Message Date
Richard van der Hoff
d60ec55e30 Crypto store: clear db before integ tests (#3644)
It's currently possible for integ test results to leak from one test run to the
next (for example, the indexeddb stores hang around in the browser), causing
bad test results.

Extend the test setup routine to clear out the store before the test starts.
2024-07-03 13:39:54 +01:00
Benjamin Bouvier
2f125e97ee send queue: make SendHandle::abort/update more precise
Using `SendHandle::abort()` after the event has been sent would look
like a successful abort of the event, while it's not the case; this
fixes this by having the state store backends return whether they've
touched an entry in the database.
2024-07-01 16:19:48 +02:00
Benjamin Bouvier
45c6efcc65 state store: add method to update the content of a send queue event
It also resets the wedged state, so that the queue will retry to send
this event later. This will show useful in the following case: when an
event is too big, we can now retry to send it, even if it was blocked,
by splitting the event instead of copy/abort/recreate it.
2024-06-27 18:53:00 +02:00
Hubert Chathi
d41af396cc Embed device keys in Olm-encrypted messages (#3517)
This patch implements MSC4147[1].

Signed-off-by: Hubert Chathi <hubertc@matrix.org>

[1]: https://github.com/matrix-org/matrix-spec-proposals/pull/4147
2024-06-27 12:18:52 +02:00
Benjamin Bouvier
29ac3e0dda fixup! state store: change schema for send_queue_events table 2024-06-26 19:42:14 +02:00
Benjamin Bouvier
62801f1a6c state store: change schema for send_queue_events table
It turns out that so as to be able to read the room ids, they need to be
*values*, not only *keys* (since keys are one-way hashed). This means we
need to duplicate the room_id field in indexeddb/sqlite, so each entry
contains both the room_id as a key (for queries) and as a value (to
return it).

Since there's no meaningful migration we can apply, the way to go is to
drop the pending events table and recreate it from the ground up. It is
assumed that no one has used the store on indexeddb; otherwise the
workaround would be to drop and recreate it.
2024-06-26 19:42:14 +02:00
Benjamin Bouvier
74b770f4d6 send queue: use state-store backed storage for remembering events to be sent 2024-06-24 13:56:10 +02:00
Mauro
d035eb1d90 feat (bindings): added APIs to save and load composer drafts (#3531)
This PR is the first piece of the breakdown of the following PR: https://github.com/matrix-org/matrix-rust-sdk/pull/3439 where only the core functionalities of the feature are implemented, without addressing the issue of editing and replying to events that have not yet been paginated.
2024-06-11 15:32:07 +00:00
Richard van der Hoff
1510f87fa0 UTD hook: stop re-reporting of UTDs on app relaunch (#3519)
Use a Bloom filter to keep track of which events we have already reported to the parent UTD hook.
We load the data from database on startup, and flush it out immediately on every update.
2024-06-10 18:56:35 +01:00
Benjamin Bouvier
5093af87b1 clippy: disallow useless asyncs (#3513)
Using async when not required will increase compile times, and propagate async-ness to the callers, transitively.

See also the [lint description](https://rust-lang.github.io/rust-clippy/master/#/unused_async).

Since we only had a few false positives, I've enabled it by default.
2024-06-05 17:13:10 +02:00
Jonas Platte
02185f7034 Configure unexpected-cfgs via Cargo.toml instead of build scripts 2024-06-04 23:34:38 +02:00
Richard van der Hoff
4cd619ccdd crypto: New method CryptoStore::save_inbound_group_sessions
When we add a batch of inbound group sessions to the store, if they came from a
backup, we need to record which backup version they came from.
`CryptoStore::save_changes` doesn't give us an easy way to set the backup
version (we could add it to the `Changes` struct, but ugh).

So, we add a new method `save_inbound_group_sessions` which takes the backup
version as a separate param. This works fine, because whenever we import
sessions there are no other changes to store.

The new method isn't used outside of tests yet -- that comes in a follow-up
commit.
2024-05-23 15:52:22 +01:00
Kévin Commaille
99ae06be68 chore: Fix cfg options
Cargo nightly now checks whether a cfg option exists.
We need to declare the custom
options we use
and fix those that are wrong.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-05-10 11:34:59 +02:00
Andy Balaam
381c02d21e crypto: Test that the sqlite store empties its session cache when asked 2024-04-18 13:47:36 +01:00
Kegan Dougal
3a99d52e84 Apply suggestions from code review
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
Signed-off-by: Kegan Dougal <7190048+kegsay@users.noreply.github.com>
2024-04-18 10:34:54 +01:00
Kegan Dougal
09955cf0db bugfix: ensure the SessionStore is cleared when regenerating the OlmMachine
This fixes https://github.com/matrix-org/matrix-rust-sdk/issues/3110
2024-04-18 10:08:15 +01:00
Andy Balaam
f11aeafd58 crypto: Add an optional backup_version param to inbound_group_session_counts 2024-04-05 16:24:55 +01:00
Andy Balaam
f51865e1ae crypto: Add a backup_version argument to group session backup methods 2024-04-04 11:00:59 +01:00
Stefan Ceriu
682c17c9d8 feat: add support for storing breacrumbs in the state store 2024-04-04 11:23:55 +02:00
Kévin Commaille
da2abccc0d chore: Disable clippy::assigning_clones lint
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2024-04-02 15:05:41 +02:00
Benjamin Bouvier
6cd655ba7c state store: add Changes::profile_to_delete field
So as to remove existing profiles from the storage.
2024-04-02 14:30:19 +02:00
Benjamin Kampmann
f14c00db82 store: Add a method to set a custom value without reading and returning the old value
This is useful if we don't care about the old value, which lets us avoid unnecessary reads.
2024-03-07 12:02:32 +01:00
Richard van der Hoff
79bb716298 Inline matrix_sdk_sqlite::make_store_config
... mostly for parity with `matrix_sdk_indexeddb::make_store_config`, but
again, simplifying the dependency graph.
2024-01-16 18:13:51 +00:00
Jonas Platte
40b09cda2f Bump all of the versions to 0.7.0 2024-01-05 12:58:54 +01:00
Jonas Platte
315e6c9d85 Use workspace dependencies for matrix-sdk-test 2024-01-05 12:58:54 +01:00
Jonas Platte
1c7bf820bf Use workspace dependencies for crates/* dependencies
… except from examples (such that they remain copy-pastable).
2024-01-04 10:02:07 +01:00
Andy Balaam
0cf99db001 Delete accidentally-copied repeat_vars function
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-15 10:47:11 +00:00
Andy Balaam
512509ce8b Switch to using chunk_large_query_over in mark_inbound_group_sessions_as_backed_up
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 16:56:13 +00:00
Andy Balaam
dfb33c9534 Move chunk_large_query_over into SqliteObjectExt so it can be reused
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 16:55:36 +00:00
Andy Balaam
03aad4e965 Move repeat_vars into utils so it can be reused
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 16:34:45 +00:00
Andy Balaam
9e67b6fcb1 Merge branch 'main' into andybalaam/mark_sessions_as_backed_up 2023-12-14 15:25:43 +00:00
Andy Balaam
3d7e1d5989 Merge branch 'main' into andybalaam/use-correct-limit-in-chunk_large_query_over 2023-12-14 13:17:06 +00:00
Ivan Enderlin
66411d7b2e Merge pull request #2946 from matrix-org/andybalaam/tests-for-repeat_vars
Unit tests for the repeat_vars function
2023-12-14 13:10:12 +01:00
Andy Balaam
a3aa55ce91 Use the limit() method to find the variable limit
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 11:31:01 +00:00
Andy Balaam
0066ae6614 Unit tests for the repeat_vars function
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 11:26:43 +00:00
Andy Balaam
17ebc23719 Provide a limit() method in sqlite to find limit values
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-14 11:21:25 +00:00
Andy Balaam
794b7ead7a Clippy fixes 2023-12-13 08:43:59 +00:00
Andy Balaam
f879f3d866 Formatting 2023-12-13 08:32:00 +00:00
Andy Balaam
4ebb8e29b4 Provide CryptoStore::mark_sessions_as_backed_up on stores and use it in BackupMachine::mark_request_as_sent
Signed-off-by: Andy Balaam <andy.balaam@matrix.org>
2023-12-12 16:09:22 +00:00
Benjamin Bouvier
5337c9d9ea refactoring: make it clear that notifications aren't stored in the state store
`notifications` were stored in the `StateChanges` struct, which made me think that they're then persisted in the database. It's not the case, they
were just stored there by convenience. This commit changes it to a parameter that's passed, as it's not too invasive and clearer that this is only
transient data.
2023-12-07 16:56:18 +01:00
Jonas Platte
64ddfd872c sqlite: Upgrade rusqlite / deadpool-sqlite 2023-11-24 15:01:17 +01:00
Jonas Platte
7be84ca71a test: Deduplicate tracing_subscriber initialization
… and set a sensible default log level.
2023-11-02 12:58:03 +01:00
Jonas Platte
afcc7022a2 Exclude remaining Debug impls from coverage reporting 2023-11-02 12:58:03 +01:00
Benjamin Bouvier
3d7a56e468 crypto: remove inner mutable shared state from Account 2023-10-20 17:04:40 +02:00
Benjamin Bouvier
c64d3b4b7a Introduce a store transaction for Account (#2660)
This adds a new `StoreTransaction` type, that wraps a `StoreCache` and a `Store`. The idea is that it will allow write access to the `Store` (and maintains the cache at the same time), while the `Store::cache` method will only give read-only access to the store's content.

Another new data type is introduced, `PendingChanges`, that reflects `Changes` but for fields that are properly maintained in the `StoreCache` and that one can write in the `StoreTransaction`. In the future, it wouldn't be possible to use `save_pending_changes` from the outside of a `StoreTransaction` context.

The layering is the following:

- `Store` wraps the `DynCryptoStore`, contains a reference to a `StoreCache`.
- When read-only access is sufficient, one can get a handle to the cache with `Store::cache()`.
- When a write happens, then one can create a `StoreTransaction` (later, only one at a time will be allowed, by putting the `StoreCache` behind a `RwLock`; this has been deferred to not make the PR grow too much).
- Any field in the `StoreCache` will get a method to get a reference to the cached thing: it will either load from the DB if not cached, or return the previously cached value. 
- Any field that can be written to will get a method to get a mutable reference in the `StoreTransaction`: it will either load from the cache into a `PendingChanges` scratch pad, or return the scratchpad temporary value.
- When a `StoreTransaction::commit()` happens, fields are backpropagated into the DB *and* the cache. 

Then, this `StoreTransaction` is used to update a `ReadOnlyAccount` in multiple places (and usage of `ReadOnlyAccount` is minimized so as not to require a transaction or cache function call as much as possible). With this, the read-only account only exists transiently, and it's only stored long-term in the cache.

Followup PRs include:

- making the `ReadOnlyAccount` not cloneable
- remove inner mutability from the `ReadOnlyAccount`
- add a `RwLock` on the `StoreTransaction`

Part of https://github.com/matrix-org/matrix-rust-sdk/issues/2624 + https://github.com/matrix-org/matrix-rust-sdk/issues/2000.

---

* crypto: Replace some uses of `ReadOnlyAccount` with `StaticAccountData` and identify tests

* crypto: introduce `StoreTransaction` to modify a `ReadOnlyAccount`

* crypto: introduce `save_pending_changes`, aka `save_changes` v2

* crypto: Start using `StoreTransaction`s to save the account, get rid of `Store::save_account` + `Account::save`

* crypto: use `StoreTransaction` to save an account in `keys_for_upload`

* crypto: use `StoreTransaction` and the cache in more places

* crypto: remove `Account` from the `Changes` \o/

* crypto: remove last (test-only) callers of `Store::account()`

* crypto: move `ReadOnlyAccount` inside the cache only

* crypto: use `ReadOnlyAccount` and `Account` in fewer places

whenever we can use `StaticAccountData` in place.

* crypto: make tests rely less on OlmMachine

* crypto: Don't put the `ReadOnlyAccount` behind a RwLock just yet

+ clippy
2023-10-09 14:16:06 +00:00
Benjamin Bouvier
57b1442e1c crypto: rename ReadOnlyAccount to Account \o/ \o/ \o/ \o/ 2023-10-09 11:00:13 +02:00
Jonas Platte
504861a532 sqlite: Upgrade deadpool, rusqlite 2023-10-04 15:43:08 +02:00
Benjamin Bouvier
3fa79ce891 chore: make the crypto stores more robust by serializing save_changes()
Stores may race when performing writes, since in `save_changes` some data is pickled, and live across await points (it could be stale after an
await point). To prevent multiple threads racing when calling into `save_changes`, a new lock is introduced there.
2023-10-02 19:05:07 +02:00
Benjamin Bouvier
8d6f414375 chore: move CryptoStore::save_account to Store::save_account
as it can be implemented in terms of other methods already present in the `CryptoStore` trait.
2023-10-02 19:05:07 +02:00
Benjamin Bouvier
650d99a875 chore: rename account_info/get_account_info to static_account/get_static_account 2023-09-28 17:21:53 +02:00