Skip to content

Commit 53e3a7c

Browse files
committed
sdk: BackupDownloadTask: use a new struct for the mpsc queue
We'll need to add more data here soon.
1 parent dc2111f commit 53e3a7c

File tree

1 file changed

+30
-5
lines changed
  • crates/matrix-sdk/src/encryption

1 file changed

+30
-5
lines changed

crates/matrix-sdk/src/encryption/tasks.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use matrix_sdk_common::failures_cache::FailuresCache;
1919
use ruma::{
2020
events::room::encrypted::{EncryptedEventScheme, OriginalSyncRoomEncryptedEvent},
2121
serde::Raw,
22-
OwnedRoomId,
22+
OwnedEventId, OwnedRoomId,
2323
};
2424
use tokio::sync::mpsc::{self, UnboundedReceiver};
2525
use tracing::{trace, warn};
@@ -93,11 +93,31 @@ impl BackupUploadingTask {
9393
}
9494
}
9595

96+
/// Information about a request for a backup download for an undecryptable
97+
/// event.
98+
#[derive(Debug)]
99+
struct RoomKeyDownloadRequest {
100+
/// The room in which the event was sent.
101+
room_id: OwnedRoomId,
102+
103+
/// The ID of the event we could not decrypt.
104+
event_id: OwnedEventId,
105+
106+
/// The megolm session that the event was encrypted with.
107+
megolm_session_id: String,
108+
}
109+
110+
impl RoomKeyDownloadRequest {
111+
pub fn to_room_key_info(&self) -> RoomKeyInfo {
112+
(self.room_id.clone(), self.megolm_session_id.clone())
113+
}
114+
}
115+
96116
pub type RoomKeyInfo = (OwnedRoomId, String);
97117
pub type TaskQueue = BTreeMap<RoomKeyInfo, JoinHandle<()>>;
98118

99119
pub(crate) struct BackupDownloadTask {
100-
sender: mpsc::UnboundedSender<RoomKeyInfo>,
120+
sender: mpsc::UnboundedSender<RoomKeyDownloadRequest>,
101121
#[allow(dead_code)]
102122
join_handle: JoinHandle<()>,
103123
}
@@ -140,7 +160,11 @@ impl BackupDownloadTask {
140160
) {
141161
if let Ok(deserialized_event) = event.deserialize() {
142162
if let EncryptedEventScheme::MegolmV1AesSha2(c) = deserialized_event.content.scheme {
143-
let _ = self.sender.send((room_id, c.session_id));
163+
let _ = self.sender.send(RoomKeyDownloadRequest {
164+
room_id,
165+
event_id: deserialized_event.event_id,
166+
megolm_session_id: c.session_id,
167+
});
144168
}
145169
}
146170
}
@@ -177,12 +201,13 @@ impl BackupDownloadTask {
177201

178202
pub(crate) async fn listen(
179203
client: WeakClient,
180-
mut receiver: UnboundedReceiver<RoomKeyInfo>,
204+
mut receiver: UnboundedReceiver<RoomKeyDownloadRequest>,
181205
failures_cache: FailuresCache<RoomKeyInfo>,
182206
) {
183207
let mut task_queue = TaskQueue::new();
184208

185-
while let Some(room_key_info) = receiver.recv().await {
209+
while let Some(room_key_download_request) = receiver.recv().await {
210+
let room_key_info = room_key_download_request.to_room_key_info();
186211
trace!(?room_key_info, "Got a request to download a room key from the backup");
187212

188213
if task_queue.len() >= 10 {

0 commit comments

Comments
 (0)