Commit Graph

6356 Commits

Author SHA1 Message Date
Andy Balaam
75eb94357e Split out tests for room display names 2023-06-20 11:25:29 +02:00
Andy Balaam
d84c8d91b5 Fix typo in comment 2023-06-20 11:25:29 +02:00
Jonas Platte
5273fa6f42 sdk: Move target-specific HTTP code into new submodules 2023-06-20 11:16:13 +02:00
Jonas Platte
4c1a351ead sdk: Remove HttpSend in favor of allowing reqwest customization 2023-06-20 11:16:13 +02:00
Jonas Platte
ba9d8294b4 ffi: Make upload progress observable 2023-06-20 11:16:13 +02:00
Jonas Platte
ac140c192a Make upload progress observable 2023-06-20 11:16:13 +02:00
Jonas Platte
a668822fec Simplify HttpClient::send_request signature 2023-06-20 11:16:13 +02:00
Richard van der Hoff
6fc90609b6 Release crypto-js 0.1.0-alpha.11 (#2112) 2023-06-19 18:09:52 +00:00
Jonas Platte
93c911add3 ui: Use method syntax for shared::Observable methods 2023-06-19 16:46:43 +02:00
Benjamin Bouvier
55aad67338 Remove the sqlite-lock binary from the main repo
Will move it to a personal repository of mine.

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-06-19 15:42:58 +02:00
Kévin Commaille
6b40db4669 sdk: Keep all the discovered AuthenticationServerInfo
It has an account field besides the issuer field.
Also store it as immutable, the data used for authentication will be
stored in another variable.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-19 13:08:45 +02:00
Kévin Commaille
2b70d1c8c6 sdk: Export Invite
It's the type returned from Invited::invite_details() but it is not
available publicly.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
2023-06-19 13:02:17 +02:00
Ivan Enderlin
d105b72554 fix(sdk): Remove the Sliding Sync retry mechanism on M_UNKNOWN_POS
fix(sdk): Remove the Sliding Sync retry mechanism on `M_UNKNOWN_POS`
2023-06-19 12:37:48 +02:00
Ivan Enderlin
67ade0a2da doc(crypto): Fix a typo
doc(crypto): Fix a typo
2023-06-19 12:35:14 +02:00
Ivan Enderlin
0c85b178ac test(ui): Fix Notification test. 2023-06-19 12:16:26 +02:00
Ivan Enderlin
87a8ac7420 doc(crypto): Fix a typo. 2023-06-19 12:06:51 +02:00
Ivan Enderlin
30b7c4bd7f fix(sdk): Remove the Sliding Sync retry mechanism on M_UNKNOWN_POS.
`SlidingSync::sync` had a legacy behaviour when a `M_UNKNOWN_POS`
error was received from the server: It was resetting `pos` and sticky
parameters before re-running a sync-loop iteration, hoping to get a
valid response from the server after that. This retrying
mechanism was running up to 3 times in row (represented by the
`MAXIMUM_SLIDING_SYNC_SESSION_EXPIRATION` constant) before stopping the
`sync` for real.

While it seemed a good idea, it actually brings numerous problems:

1. Each iteration in the sync-loop generates a new request, thus making
   the `ranges` of the requests to move forwards. For `SlidingSyncList`
   that are in `Selective` sync-mode, there is no problem, but for
   `Growing` or `Paging` sync-modes, the `ranges` increased. Thus,
   when a `SlidingSync` session expires, instead of returning to
   the caller to do something clever (like what `RoomList` does: start
   again with a small range so that the “first” sync after a session
   expiration is guaranteed to be fast), it was running larger and
   larger requests, up to 3 times.
2. `M_UNKNOWN_POS` _is_ an error. Yes, `SlidingSync` must reset `pos`
   and must invalidate sticky parameters, but the `sync` must be
   stopped, and the error must be returned so that the caller can do
   something about it. Until now, this error was likely to be missed by
   the caller.
3. This legacy mechanism was forbidding `SlidingSync::sync`'s caller to
   do something with this special error. And since the caller was blind to
   this error, it disallowed more smart error management.

This patch removes this legacy retry mechanism entirely. When
`M_UNKNOWN_POS` is received from the server, `pos` is reset and sticky
parameters are invalidated as before, but the error is returned like any
other error.

This patch renames and updates an existing test that was testing sticky
parameters invalidation on `M_UNKNOWN_POS`, to include some assertions
on `pos` and to ensure that the sync-loop is stopped accordingly.
2023-06-19 11:43:27 +02:00
Benjamin Bouvier
4d3ca15be3 feat(ui): Implement Notification API (#2023)
This is the first PR for splitting the sync loop into two. This offers a new high-level API, `NotificationApi`, that makes use of a separate `SlidingSync` instance which sole role is to listen to to-device events and e2ee; it's pre-configured to do so. That means we're not force-enabling e2ee and to-device by default for every sliding sync instance, and as such we won't either generate Olm requests to the home server in general.

In the future, this new high-level API will hide some low-level dirty details so that its can be instantiated in multiple processes at the same time (lock across process, invalidate and refill crypto caches, etc.).

An embedder who would want to make use of this would need the following:

- a main sliding sync instance, without e2ee and to-device. Using the `matrix_sdk_ui::RoomList` would be the best bet, at this time.
- an instance of this `matrix_sdk_ui::NotificationApi`, with a different identifier.

Note that this is not ready to be used in an external process; or it will cause the same kind of issues that we're seeing as of today: invalid crypto caches resulting in UTD, etc.

Fixes https://github.com/matrix-org/matrix-rust-sdk/issues/1961.
2023-06-19 08:56:58 +00:00
Damir Jelić
7c393d73c4 Merge branch 'openqrnch/main' 2023-06-19 09:40:14 +02:00
Damir Jelić
75cf572968 Fix the formatting of the sync_with_result_callbac() docstring 2023-06-19 09:39:34 +02:00
Jan Danielsson
bccd3412c1 Add a missing backtick in sync_with_result_callback() documentation. 2023-06-18 15:29:58 +02:00
Ivan Enderlin
6d4874e147 doc(ui): Fix a typo. 2023-06-18 09:20:57 +02:00
Richard van der Hoff
ef0c230bd3 crypto-js: Simplify response type of Sas::confirm (#2066)
On the javascript side, everything is just an `OutgoingRequest`, so we may
as well return a single array rather than a tuple.
2023-06-16 16:19:35 +01:00
Damir Jelić
bddc88472a Clarify the comment about creating a Olm session twice
Co-authored-by: Denis Kasak <dkasak@termina.org.uk>
2023-06-16 16:56:09 +02:00
Damir Jelić
aab3d00246 Log if a session was created using a fallback key 2023-06-16 16:56:09 +02:00
Damir Jelić
a94e2f06ee Ensure that we're not creating the same session twice
Usually it's impossible to create a Olm session from a pre-key message
twice. The one-time key that should be used for the 3DH step will be
used up and we're going to throw a `MissingOneTimeKey` error.

This used to be true and unproblematic until we added fallback keys,
these keys will not get discarded immediately after they have been used
once.

This means that a pre-key message, for which we already have a Session,
but decryption for it fails, might create a new Session overwriting the
existing one which will essentially reset the ratchet.
2023-06-16 16:56:09 +02:00
Damir Jelić
817dcde4d8 Test that we're not able to decrypt replayed messages 2023-06-16 16:56:09 +02:00
Benjamin Bouvier
76ed3511b5 Add a value-based lock in the CryptoStores (#2049)
This implements a value-based lock in the crypto stores. The intent is to use that for multiple processes to be able to make writes into the store concurrently, while still cooperating on who does them. In particular, we need this for #1928, since we may have up to two different processes trying to write into the crypto store at the same time.

## New methods in the `CryptoStore` trait

The idea is to introduce two new methods touching **custom values** in the crypto store:

- one to atomically insert a value, only if it was missing (so, not following the semantics of `upsert` used in the `set_custom_value`) 
- one to atomically remove a custom value

Those two operations match the semantics we want:

- take the lock only if it ain't taken already == insert an entry only if it was missing
- release the lock = remove the entry

By looking at the number of lines affected by the query, we can infer whether the insert/remove happened or not, that is, if we managed to take the lock or not.

## High-level APIs

I've also added an high-level API, `CryptoStoreLock`, that helps managing such a lock, and adds some niceties on top of that:

- exponential backoff to retry attempts at acquiring the lock, when it was already taken
- attempt to gracefully recover when the lock has been taken by an app that's been killed by the environment
- full configuration of the key / value / backoff parameters

While it'd be nice to have something like a `CryptoStoreLockGuard`, it's hard to implement without being racy, because of the `async` statements that would happen in the `Drop` method (and async drop isn't stable yet).

## Test program

There's also a test program in which I shamelessly show my rudimentary unix skills; I've put it in the `labs/` directory but this could as well be a large integration test. A parent program initially fills a custom crypto store, then creates a `pipe()` for 1-way communication with a child created with `fork()`; then the parent sends commands to the child. These commands consist in reading and writing into the crypto store, using a lock. And while the child attempts to perform these operations, the parent tries hard to get the lock at the same time. This helps figuring out a few issues and making sure that cross-process locking would work as intended.
2023-06-16 13:05:54 +00:00
Ivan Enderlin
1660c71dfd feat(ui): Add bump_event_types for all_rooms in RoomList
feat(ui): Add `bump_event_types` for `all_rooms` in `RoomList`
2023-06-16 14:52:10 +02:00
Ivan Enderlin
646fb35b3a feat(ui): Add bump_event_types for all_rooms in RoomList.
This patch configures the `bump_event_types` paramter for the
`all_rooms` list in `RoomList`.
2023-06-16 14:49:08 +02:00
Benjamin Bouvier
bae1a71c81 feat: make OlmMachine resettable (#2091)
* feat: make `OlmMachine` resettable by making it an Arc<RwLock> instead of a OnceCell
* chore: fix e2e-encryption scoping
2023-06-16 12:39:08 +00:00
Ivan Enderlin
3d859674a8 fix(ui): Enable SS caching on RoomList
fix(ui): Enable SS caching on `RoomList`
2023-06-16 14:36:21 +02:00
Ivan Enderlin
a75808e338 fix(ui): Enable SS caching on RoomList. 2023-06-16 14:31:45 +02:00
Ivan Enderlin
dc06893130 fix(sdk): Disable the receipts extension temporarily
fix(sdk): Disable the `receipts` extension temporarily
2023-06-16 14:06:29 +02:00
Ivan Enderlin
489898fd40 fix(sdk): Disable the receipts extension temporarily.
Please see https://github.com/matrix-org/matrix-rust-sdk/issues/2037.
2023-06-16 13:40:38 +02:00
Ivan Enderlin
85b6eaa4c7 feat(ffi): Implement RoomList::invites
feat(ffi): Implement `RoomList::invites`
2023-06-16 13:31:53 +02:00
Ivan Enderlin
305d55d551 feat(base) In Sliding Sync, find out which rooms we have left from state events
In Sliding Sync, find out which rooms we have left from state events
2023-06-16 13:27:28 +02:00
Ivan Enderlin
bae6fc71d0 test(ui): Add a test specifically for RoomList::invites. 2023-06-16 13:10:36 +02:00
Ivan Enderlin
7a1d59e9a2 feat(ffi): Implement RoomList::invites. 2023-06-16 12:43:36 +02:00
Ivan Enderlin
e09a44831b feat(ui): Implement RoomList::invites. 2023-06-16 12:43:12 +02:00
Ivan Enderlin
5d82d5db89 feat(ui): Add the invites list in the RoomList.
The `invites` list is added when the first rooms are loaded, so that it
doesn't slow the first initial start up.
2023-06-16 12:28:42 +02:00
Richard van der Hoff
6199ca069c crypto-js: Add register_changes_callback methods to the verification classes (#2067) 2023-06-16 11:25:50 +01:00
Ivan Enderlin
c9a9a5c20a fix(ui): SlidingSync::subscribe_to_room marks room as having missing members
fix(ui): `SlidingSync::subscribe_to_room` marks room as having missing members
2023-06-16 11:45:37 +02:00
Ivan Enderlin
a99a7b4a5a test(sdk): Test that room subscription makes members not synced. 2023-06-16 11:23:11 +02:00
Ivan Enderlin
c515643442 doc(sdk): Fix typos. 2023-06-16 10:35:32 +02:00
Ivan Enderlin
d45f871106 doc(sdk): Fix intralink. 2023-06-16 10:34:48 +02:00
Ivan Enderlin
3a70b2e8ab fix(ui): SlidingSync::subscribe_to_room marks room as having missing members.
Fix https://github.com/matrix-org/matrix-rust-sdk/issues/2004.
2023-06-16 09:44:36 +02:00
Jonas Platte
db5c9d8c4b ffi: Add Room::get_timeline_event_content_by_event_id 2023-06-15 17:24:18 +02:00
Ivan Enderlin
ec1172c353 feat(ui+ffi): Implement RoomList::entries_loading_state
feat(ui+ffi): Implement `RoomList::entries_loading_state`
2023-06-15 17:20:42 +02:00
Ivan Enderlin
61d4850a66 chore: Make Clippy happy. 2023-06-15 16:18:08 +02:00