Commit Graph

2824 Commits

Author SHA1 Message Date
Ivan Enderlin
bd175d9f66 test(sdk): Store the sync-mode in SlidingSyncListInner only for tests. 2023-06-01 09:48:53 +02:00
Ivan Enderlin
f89060bbe9 chore(ui): Update after the rebase. 2023-06-01 09:48:53 +02:00
Ivan Enderlin
01366a08df !foo 2023-06-01 09:48:53 +02:00
Ivan Enderlin
4e07ac1c76 test(ui): Improve testability of RoomList. 2023-06-01 09:48:53 +02:00
Ivan Enderlin
d1708ececf feat(ui): Update according to the last patch. 2023-06-01 09:48:53 +02:00
Ivan Enderlin
4fa38d23d4 feat(sdk): SlidingSync has more non-blocking API.
This patch does several things.

First, `SlidingSync::on_list` is now async, and accept async closures.

Second, `SlidingSync::lists` and `::rooms` are behind an `AsyncRwLock`
instead of a `StdRwLock`. The rest of the patch updates the consequence
of this.
2023-06-01 09:48:53 +02:00
Ivan Enderlin
5f81d829c4 feat(ui): Create an Init state, and add state observer for RoomList. 2023-06-01 09:48:52 +02:00
Ivan Enderlin
92c3003535 !baz 2023-06-01 09:48:52 +02:00
Ivan Enderlin
f47c2ba125 !bar 2023-06-01 09:48:52 +02:00
Ivan Enderlin
7706b0096b !foo 2023-06-01 09:48:52 +02:00
Ivan Enderlin
5f58438389 feat(ui): Oh, a roomlist module. 2023-06-01 09:48:51 +02:00
Ivan Enderlin
81d158889a fix(sdk): Replace a panic by a log in Sliding Sync
fix(sdk): Replace a panic by a log in Sliding Sync
2023-06-01 09:47:50 +02:00
Ivan Enderlin
29346b11f3 test(ui): Use FutureExt::now_or_never instead of .await
test(ui): Use `FutureExt::now_or_never` instead of `.await`
2023-06-01 09:41:56 +02:00
Damir Jelić
036d9bf261 Add a test to check that the backup decryption works 2023-06-01 09:31:31 +02:00
Damir Jelić
811369ba28 Fix the argument order when decoding a PkMessage 2023-06-01 09:31:31 +02:00
Ivan Enderlin
06680a284a fix(sdk): Replace a panic by a log in Sliding Sync.
This patch replaces a panic (`Option::expect`) by a `tracing::error`
log.

Imagine the Sliding Sync proxy responds with the following payload:

```json
{
    "pos": …,
    "lists": {
        …: {
            "count": …,
            "ops": [
                {
                    "op": "INSERT",
                    "index": 0,
                    "room_id": !foo:bar.org",
                }
            ]
        }
    },
    "rooms": []
}
```

It's an invalid response, as it will update the room list entry (because
it's present in `lists.$list.ops`), but the room won't be created (it's
absent in the `rooms`).

This situation creates a panic in the patched code. We don't want to
crash if the server replies with invalid data.

Ultimately, we should check that the sync operations are valid regarding
the rooms' updates.
2023-06-01 09:18:20 +02:00
Ivan Enderlin
fbe8826159 test(ui): Use FutureExt::now_or_never instead of .await.
This patch uses `FutureExt::now_or_never` so that we don't wait on the
future to be resolved to get a result. If we have a bug in our code and
the test expects a value, the test will hang forever, which is not a
desired behavior. With `now_or_never`, this situation cannot happen.
2023-06-01 08:39:44 +02:00
Ivan Enderlin
ae25ad557a Merge branch 'main' into fix-sdk-sliding-sync-drain-internal-channel 2023-05-31 17:34:48 +02:00
Ivan Enderlin
d0d23afa5c feat(sdk): Introduce SlidingSync::internal_channel_send_if_possible.
The only reason why a sender can fail to send a message is because there
is no receiver. In the current design of `SlidingSync`, there is only
one receiver active per sync-loop. Thus, calling `SlidingSync::add_list`
may fail if `sync` has not been started. Hence the need for a new
`internal_channel_send_if_possible` method which will never fail: it
will send a message is possible, otherwise it won't do anything.

This turns more functions infallible.
2023-05-31 16:53:03 +02:00
Ivan Enderlin
875f379035 feat(sdk): Change SlidingSync's internal channel to MPMC.
`tokio::sync::broadcast` is interesting as it's possible to
generate receivers per subscribers. Being able to do that allows
us to remove the new for an `AsyncLock` around the receiver in
`SlidingSync::internal_channel`, and it can even remove the need to hold
a receiver entirely!

Another improvement is that new receivers can't receive past messages,
so we no longer need to drain the internal channel.

Another improvement is that the sender' `send` method is synchronous!
Which helps to make many functions no longer `async`.
2023-05-31 16:41:50 +02:00
Ivan Enderlin
9da1a2f48b feat(sdk): Ensure SlidingSync::sync drains its internal channel.
Something weird is happening with ElementX iOS. When
`SlidingSync::stop_sync` is called, the internal message `SyncLoopStop`
has time to be sent in the internal channel, but iOS decides to suspend
the code before the sync-loop processes it. When ElementX decides to
start the sync-loop again, it immediately processes the `SyncLoopStop`
message, and… stops the sync-loop.

This patch ensures that `SlidingSync::sync` drains the internal channel
before starting the sync-loop for real. `tokio::sync::mpsc::Receiver`
type has no `drain` method, so this patch implements its
own logic by calling `try_recv` in a loop, until it returns
`Err(TryRecvError::Empty)`.
2023-05-31 15:29:13 +02:00
Ivan Enderlin
70525e4612 test(sdk): Ensure SlidingSync starts after it has been stopped manually. 2023-05-31 11:18:55 +02:00
Benjamin Bouvier
623ff6fa83 chore(sliding sync): remove useless mutex around ExtensionsConfig
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-29 17:18:42 +02:00
Benjamin Bouvier
ce9a079882 feat(sdk): use the builder pattern for the other sliding sync mode too
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-26 15:08:21 +02:00
Benjamin Bouvier
fa25e4d9fc sliding sync: Rejigger the range API (#1955)
* feat: introduce SlidingSyncSelectiveModeBuilder
* feat: get rid of `CannotModifyRanges` \o/
* chore: rustfmt
* chore: remove scope in test
* chore: move request generator update to its own mod, gets rid of `set_ranges`
* chore: add comments on the request generator methods
* chore: sink one range_end definition into the match arm that matters
* ffi: remove unused `add_range` method
* test: update incorrect test expectation
* chore: make clippy happy
* address first review comments
* review: don't reuse the ranges field for two things
* chore: use a builder pattern for sliding sync selective mode
* address review comments + CI

Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-26 13:40:46 +02:00
Damir Jelić
df6d0aaa87 Log the one-time keys we received 2023-05-26 10:34:07 +00:00
Jonas Platte
84917bb59d Fix clippy lints 2023-05-26 12:26:00 +02:00
Jonas Platte
ebe97623aa Upgrade Ruma 2023-05-26 12:26:00 +02:00
Damir Jelić
def53962e4 Make the withheld reason part of the error message 2023-05-25 16:57:58 +02:00
Damir Jelić
1b2ba33039 Record the sender key when decrypting room events
This used to be the case previously, but it seems that things got lost
when we reshuffled the code here.
2023-05-25 16:57:58 +02:00
Benjamin Bouvier
631b51f43b chore: update sliding sync's README.md too
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Benjamin Bouvier
829eb30e7e chore: get rid of SlidingSync::reset_lists as it's unused
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Benjamin Bouvier
8d1b3b5b73 chore: get rid of SlidingSyncList::set_ranges, replace with SlidingSyncList::set_range (singular) in testing
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Benjamin Bouvier
9c1919ab4c chore: get rid of SlidingSyncListBuilder::set_range and replace it with add_range in tests
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Benjamin Bouvier
dbd491383f chore: get rid of SlidingSyncListBuilder::reset_ranges
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Benjamin Bouvier
40a0459cb9 chore: get rid of SlidingSyncListBuilder::ranges(), replace with add_range
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 16:17:46 +02:00
Damir Jelić
8c9a54e6c8 Time out user/device pairs who have invalid one-time keys 2023-05-25 14:52:05 +02:00
Damir Jelić
ac816ca1c6 Fix an indentation issue 2023-05-25 14:51:25 +02:00
Damir Jelić
2c696ae210 Fix the deserialization of encrypted m.dummy events. 2023-05-25 14:51:25 +02:00
Benjamin Bouvier
992b6b604b test: address review comments + add basic tests for to-device token
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 11:26:32 +02:00
Benjamin Bouvier
9762c63dbc chore: remove Observable wrappers for the position markers
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 11:26:32 +02:00
Benjamin Bouvier
0afe616e17 feat: put the to_device_token along the other position markers in sliding sync
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 11:26:32 +02:00
Benjamin Bouvier
b4c192509b chore: remove unused FFI add_common_extensions
Signed-off-by: Benjamin Bouvier <public@benj.me>
2023-05-25 11:26:32 +02:00
Damir Jelić
5e3a114830 Log the message id when we share a room key 2023-05-24 12:29:15 +02:00
Damir Jelić
2e09bf63a6 Add a message id to our encrypted to-device events 2023-05-24 12:29:15 +02:00
Damir Jelić
19ca9478b7 Clean up some room key forwarding logs 2023-05-24 12:29:15 +02:00
Ivan Enderlin
17f4ba5c9b fix(sdk): Client::sliding_sync doesn't need to be async
fix(sdk): `Client::sliding_sync` doesn't need to be `async`
2023-05-24 12:26:33 +02:00
Ivan Enderlin
a2a1b35622 fix(sdk): Client::sliding_sync doesn't need to be async.
The `Client::sliding_sync` method was declared as async. However, it's
not necessary as everything happening here is sync.
2023-05-24 11:56:38 +02:00
Ivan Enderlin
728cd5db86 fix(sdk): Restore the size of the SS channel.
Because it doesn't solve any problem, it just postpones it, making the
whole thing more difficult to debug.
2023-05-24 11:02:06 +02:00
Ivan Enderlin
512a5e77cd feat(sdk): Log when messages are sent internally by SlidingSync. 2023-05-24 11:01:42 +02:00