Skip to content

Commit

Permalink
crypto: Remove the KeysBackup variant of the OutgoingRequest enum
Browse files Browse the repository at this point in the history
Backing up room keys isn't part of the outgoing requests processing
loop, instead the user is supposed to have a separate loop calling
`BackupMachine::backup()`.
  • Loading branch information
poljar committed Mar 19, 2024
1 parent 1e35188 commit 3ccd2e9
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 35 deletions.
1 change: 0 additions & 1 deletion bindings/matrix-sdk-crypto-ffi/src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ impl From<OutgoingRequest> for Request {
},
RoomMessage(r) => Request::from(r),
KeysClaim(c) => (r.request_id().to_owned(), c.clone()).into(),
KeysBackup(b) => (r.request_id().to_owned(), b.clone()).into(),
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions crates/matrix-sdk-crypto/src/backups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ use crate::{
olm::{BackedUpRoomKey, ExportedRoomKey, InboundGroupSession, SignedJsonObject},
store::{BackupDecryptionKey, BackupKeys, Changes, RoomKeyCounts, Store},
types::{MegolmV1AuthData, RoomKeyBackupInfo, Signatures},
CryptoStoreError, Device, KeysBackupRequest, OutgoingRequest, RoomKeyImportResult,
SignatureError,
CryptoStoreError, Device, KeysBackupRequest, RoomKeyImportResult, SignatureError,
};

mod keys;
Expand Down Expand Up @@ -70,12 +69,6 @@ struct PendingBackup {
sessions: BTreeMap<OwnedRoomId, BTreeMap<SenderKey, BTreeSet<SessionId>>>,
}

impl From<PendingBackup> for OutgoingRequest {
fn from(b: PendingBackup) -> Self {
OutgoingRequest { request_id: b.request_id, request: Arc::new(b.request.into()) }
}
}

/// The result of a signature verification of a signed JSON object.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct SignatureVerification {
Expand Down
8 changes: 0 additions & 8 deletions crates/matrix-sdk-crypto/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ pub enum OutgoingRequests {
/// A room message request, usually for sending in-room interactive
/// verification events.
RoomMessage(RoomMessageRequest),
/// A request that will back up a batch of room keys to the server.
KeysBackup(KeysBackupRequest),
}

#[cfg(test)]
Expand All @@ -235,12 +233,6 @@ impl From<KeysQueryRequest> for OutgoingRequests {
}
}

impl From<KeysBackupRequest> for OutgoingRequests {
fn from(r: KeysBackupRequest) -> Self {
Self::KeysBackup(r)
}
}

impl From<KeysClaimRequest> for OutgoingRequests {
fn from(r: KeysClaimRequest) -> Self {
Self::KeysClaim(r)
Expand Down
1 change: 0 additions & 1 deletion crates/matrix-sdk-crypto/src/verification/event_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,6 @@ impl TryFrom<OutgoingRequest> for OutgoingContent {
match value.request() {
crate::OutgoingRequests::KeysUpload(_)
| crate::OutgoingRequests::KeysQuery(_)
| crate::OutgoingRequests::KeysBackup(_)
| crate::OutgoingRequests::SignatureUpload(_)
| crate::OutgoingRequests::KeysClaim(_) => Err("Invalid request type".to_owned()),
crate::OutgoingRequests::ToDeviceRequest(r) => Self::try_from(r.clone()),
Expand Down
17 changes: 0 additions & 17 deletions crates/matrix-sdk/src/encryption/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use matrix_sdk_base::crypto::{
use matrix_sdk_common::executor::spawn;
use ruma::{
api::client::{
backup::add_backup_keys::v3::Response as KeysBackupResponse,
keys::{
get_keys, upload_keys, upload_signing_keys::v3::Request as UploadSigningKeysRequest,
},
Expand Down Expand Up @@ -541,27 +540,11 @@ impl Client {
let response = self.send(request.clone(), None).await?;
self.mark_request_as_sent(r.request_id(), &response).await?;
}
OutgoingRequests::KeysBackup(request) => {
let response = self.send_backup_request(request).await?;
self.mark_request_as_sent(r.request_id(), &response).await?;
}
}

Ok(())
}

async fn send_backup_request(
&self,
request: &matrix_sdk_base::crypto::KeysBackupRequest,
) -> Result<KeysBackupResponse> {
let request = ruma::api::client::backup::add_backup_keys::v3::Request::new(
request.version.clone(),
request.rooms.clone(),
);

Ok(self.send(request, None).await?)
}

pub(crate) async fn send_outgoing_requests(&self) -> Result<()> {
const MAX_CONCURRENT_REQUESTS: usize = 20;

Expand Down

0 comments on commit 3ccd2e9

Please sign in to comment.