From db553b2040c4320ce7d8cded3c97ecb7506b1800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 13:38:20 +0200 Subject: [PATCH 01/12] crypto: Fix some clippy warnings. --- matrix_sdk_crypto/src/machine.rs | 3 +-- matrix_sdk_crypto/src/memory_stores.rs | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 340af00f..4b160c78 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -969,7 +969,7 @@ impl OlmMachine { panic!("Session is already shared"); } - // TODO don't mark the session as shared automatically only, when all + // TODO don't mark the session as shared automatically, only when all // the requests are done, failure to send these requests will likely end // up in wedged sessions. We'll need to store the requests and let the // caller mark them as sent using an UUID. @@ -986,7 +986,6 @@ impl OlmMachine { .await? .devices() { - // TODO abort if the device isn't verified devices.push(device.clone()); } } diff --git a/matrix_sdk_crypto/src/memory_stores.rs b/matrix_sdk_crypto/src/memory_stores.rs index c6828a78..7fb78b0e 100644 --- a/matrix_sdk_crypto/src/memory_stores.rs +++ b/matrix_sdk_crypto/src/memory_stores.rs @@ -62,6 +62,7 @@ impl SessionStore { /// Get all the sessions that belong to the given sender key. pub fn get(&self, sender_key: &str) -> Option>>> { + #[allow(clippy::map_clone)] self.entries.get(sender_key).map(|s| s.clone()) } @@ -75,6 +76,7 @@ impl SessionStore { #[derive(Debug, Default, Clone)] /// In-memory store that holds inbound group sessions. pub struct GroupSessionStore { + #[allow(clippy::type_complexity)] entries: Arc>>>, } From ac2469d27006179d917de6ae89ab321d684f117e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 13:45:32 +0200 Subject: [PATCH 02/12] crypto: Change the way we check if an user is already tracked. --- matrix_sdk_crypto/src/machine.rs | 4 ++-- matrix_sdk_crypto/src/store/memorystore.rs | 12 +++++------- matrix_sdk_crypto/src/store/mod.rs | 4 ++-- matrix_sdk_crypto/src/store/sqlite.rs | 11 ++++------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 4b160c78..3c8765df 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -1219,7 +1219,7 @@ impl OlmMachine { /// /// Returns true if the user was queued up for a key query, false otherwise. pub async fn mark_user_as_changed(&self, user_id: &UserId) -> StoreResult { - if self.store.read().await.tracked_users().contains(user_id) { + if self.store.read().await.is_user_tracked(user_id) { self.store .write() .await @@ -1250,7 +1250,7 @@ impl OlmMachine { I: IntoIterator, { for user in users { - if self.store.read().await.tracked_users().contains(user) { + if self.store.read().await.is_user_tracked(user) { continue; } diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index 1149766d..c8a9b7be 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -83,14 +83,14 @@ impl CryptoStore for MemoryStore { .get(room_id, sender_key, session_id)) } - fn tracked_users(&self) -> &HashSet { - &self.tracked_users - } - fn users_for_key_query(&self) -> &HashSet { &self.users_for_key_query } + fn is_user_tracked(&self, user_id: &UserId) -> bool { + self.tracked_users.contains(user_id) + } + async fn update_tracked_user(&mut self, user: &UserId, dirty: bool) -> Result { if dirty { self.users_for_key_query.insert(user.clone()); @@ -228,8 +228,6 @@ mod test { .await .unwrap()); - let tracked_users = store.tracked_users(); - - let _ = tracked_users.contains(device.user_id()); + assert!(store.is_user_tracked(device.user_id())); } } diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index 0f2dca0d..2a1814c2 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -143,8 +143,8 @@ pub trait CryptoStore: Debug { session_id: &str, ) -> Result>; - /// Get the set of tracked users. - fn tracked_users(&self) -> &HashSet; + /// Is the given user already tracked. + fn is_user_tracked(&self, user_id: &UserId) -> bool; /// Set of users that we need to query keys for. This is a subset of /// the tracked users. diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index b0cbdd0f..65c10a99 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -818,8 +818,8 @@ impl CryptoStore for SqliteStore { .get(room_id, sender_key, session_id)) } - fn tracked_users(&self) -> &HashSet { - &self.tracked_users + fn is_user_tracked(&self, user_id: &UserId) -> bool { + self.tracked_users.contains(user_id) } fn users_for_key_query(&self) -> &HashSet { @@ -1200,9 +1200,7 @@ mod test { .await .unwrap()); - let tracked_users = store.tracked_users(); - - assert!(tracked_users.contains(device.user_id())); + assert!(store.is_user_tracked(device.user_id())); assert!(!store.users_for_key_query().contains(device.user_id())); assert!(!store .update_tracked_user(device.user_id(), true) @@ -1217,8 +1215,7 @@ mod test { store.load_account().await.unwrap(); - let tracked_users = store.tracked_users(); - assert!(tracked_users.contains(device.user_id())); + assert!(store.is_user_tracked(device.user_id())); assert!(store.users_for_key_query().contains(device.user_id())); store From 01bcbaf0631cdfbb6b450ba119a6f0838220c34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 14:34:42 +0200 Subject: [PATCH 03/12] crypto: Remove most mutable self borrows from the crypto-store trait. --- matrix_sdk_crypto/src/machine.rs | 4 +- matrix_sdk_crypto/src/memory_stores.rs | 12 ++--- matrix_sdk_crypto/src/store/memorystore.rs | 31 +++++++----- matrix_sdk_crypto/src/store/mod.rs | 15 +++--- matrix_sdk_crypto/src/store/sqlite.rs | 57 ++++++++++------------ 5 files changed, 62 insertions(+), 57 deletions(-) diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 3c8765df..97c21629 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -1268,14 +1268,14 @@ impl OlmMachine { /// Should the client perform a key query request. pub async fn should_query_keys(&self) -> bool { - !self.store.read().await.users_for_key_query().is_empty() + self.store.read().await.has_users_for_key_query() } /// Get the set of users that we need to query keys for. /// /// Returns a hash set of users that need to be queried for keys. pub async fn users_for_key_query(&self) -> HashSet { - self.store.read().await.users_for_key_query().clone() + self.store.read().await.users_for_key_query() } } diff --git a/matrix_sdk_crypto/src/memory_stores.rs b/matrix_sdk_crypto/src/memory_stores.rs index 7fb78b0e..1e1f94fa 100644 --- a/matrix_sdk_crypto/src/memory_stores.rs +++ b/matrix_sdk_crypto/src/memory_stores.rs @@ -43,7 +43,7 @@ impl SessionStore { /// /// Returns true if the the session was added, false if the session was /// already in the store. - pub async fn add(&mut self, session: Session) -> bool { + pub async fn add(&self, session: Session) -> bool { if !self.entries.contains_key(&*session.sender_key) { self.entries.insert( session.sender_key.to_string(), @@ -67,7 +67,7 @@ impl SessionStore { } /// Add a list of sessions belonging to the sender key. - pub fn set_for_sender(&mut self, sender_key: &str, sessions: Vec) { + pub fn set_for_sender(&self, sender_key: &str, sessions: Vec) { self.entries .insert(sender_key.to_owned(), Arc::new(Mutex::new(sessions))); } @@ -92,7 +92,7 @@ impl GroupSessionStore { /// /// Returns true if the the session was added, false if the session was /// already in the store. - pub fn add(&mut self, session: InboundGroupSession) -> bool { + pub fn add(&self, session: InboundGroupSession) -> bool { if !self.entries.contains_key(&session.room_id) { let room_id = &*session.room_id; self.entries.insert(room_id.clone(), HashMap::new()); @@ -225,7 +225,7 @@ mod test { async fn test_session_store() { let (_, session) = get_account_and_session().await; - let mut store = SessionStore::new(); + let store = SessionStore::new(); assert!(store.add(session.clone()).await); assert!(!store.add(session.clone()).await); @@ -242,7 +242,7 @@ mod test { async fn test_session_store_bulk_storing() { let (_, session) = get_account_and_session().await; - let mut store = SessionStore::new(); + let store = SessionStore::new(); store.set_for_sender(&session.sender_key, vec![session.clone()]); let sessions = store.get(&session.sender_key).unwrap(); @@ -273,7 +273,7 @@ mod test { ) .unwrap(); - let mut store = GroupSessionStore::new(); + let store = GroupSessionStore::new(); store.add(inbound.clone()); let loaded_session = store diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index c8a9b7be..92d81314 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -15,6 +15,7 @@ use std::{collections::HashSet, sync::Arc}; use async_trait::async_trait; +use dashmap::DashSet; use matrix_sdk_common::{ identifiers::{DeviceId, RoomId, UserId}, locks::Mutex, @@ -29,8 +30,8 @@ use crate::{ pub struct MemoryStore { sessions: SessionStore, inbound_group_sessions: GroupSessionStore, - tracked_users: HashSet, - users_for_key_query: HashSet, + tracked_users: DashSet, + users_for_key_query: DashSet, devices: DeviceStore, } @@ -39,8 +40,8 @@ impl MemoryStore { MemoryStore { sessions: SessionStore::new(), inbound_group_sessions: GroupSessionStore::new(), - tracked_users: HashSet::new(), - users_for_key_query: HashSet::new(), + tracked_users: DashSet::new(), + users_for_key_query: DashSet::new(), devices: DeviceStore::new(), } } @@ -56,7 +57,7 @@ impl CryptoStore for MemoryStore { Ok(()) } - async fn save_sessions(&mut self, sessions: &[Session]) -> Result<()> { + async fn save_sessions(&self, sessions: &[Session]) -> Result<()> { for session in sessions { let _ = self.sessions.add(session.clone()).await; } @@ -64,16 +65,16 @@ impl CryptoStore for MemoryStore { Ok(()) } - async fn get_sessions(&mut self, sender_key: &str) -> Result>>>> { + async fn get_sessions(&self, sender_key: &str) -> Result>>>> { Ok(self.sessions.get(sender_key)) } - async fn save_inbound_group_session(&mut self, session: InboundGroupSession) -> Result { + async fn save_inbound_group_session(&self, session: InboundGroupSession) -> Result { Ok(self.inbound_group_sessions.add(session)) } async fn get_inbound_group_session( - &mut self, + &self, room_id: &RoomId, sender_key: &str, session_id: &str, @@ -83,15 +84,19 @@ impl CryptoStore for MemoryStore { .get(room_id, sender_key, session_id)) } - fn users_for_key_query(&self) -> &HashSet { - &self.users_for_key_query + fn users_for_key_query(&self) -> HashSet { + self.users_for_key_query.iter().map(|u| u.clone()).collect() } fn is_user_tracked(&self, user_id: &UserId) -> bool { self.tracked_users.contains(user_id) } - async fn update_tracked_user(&mut self, user: &UserId, dirty: bool) -> Result { + fn has_users_for_key_query(&self) -> bool { + !self.users_for_key_query.is_empty() + } + + async fn update_tracked_user(&self, user: &UserId, dirty: bool) -> Result { if dirty { self.users_for_key_query.insert(user.clone()); } else { @@ -168,7 +173,7 @@ mod test { ) .unwrap(); - let mut store = MemoryStore::new(); + let store = MemoryStore::new(); let _ = store .save_inbound_group_session(inbound.clone()) .await @@ -217,7 +222,7 @@ mod test { #[tokio::test] async fn test_tracked_users() { let device = get_device(); - let mut store = MemoryStore::new(); + let store = MemoryStore::new(); assert!(store .update_tracked_user(device.user_id(), false) diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index 2a1814c2..f58ca246 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -109,14 +109,14 @@ pub trait CryptoStore: Debug { /// # Arguments /// /// * `session` - The sessions that should be stored. - async fn save_sessions(&mut self, session: &[Session]) -> Result<()>; + async fn save_sessions(&self, session: &[Session]) -> Result<()>; /// Get all the sessions that belong to the given sender key. /// /// # Arguments /// /// * `sender_key` - The sender key that was used to establish the sessions. - async fn get_sessions(&mut self, sender_key: &str) -> Result>>>>; + async fn get_sessions(&self, sender_key: &str) -> Result>>>>; /// Save the given inbound group session in the store. /// @@ -126,7 +126,7 @@ pub trait CryptoStore: Debug { /// # Arguments /// /// * `session` - The session that should be stored. - async fn save_inbound_group_session(&mut self, session: InboundGroupSession) -> Result; + async fn save_inbound_group_session(&self, session: InboundGroupSession) -> Result; /// Get the inbound group session from our store. /// @@ -137,7 +137,7 @@ pub trait CryptoStore: Debug { /// /// * `session_id` - The unique id of the session. async fn get_inbound_group_session( - &mut self, + &self, room_id: &RoomId, sender_key: &str, session_id: &str, @@ -146,9 +146,12 @@ pub trait CryptoStore: Debug { /// Is the given user already tracked. fn is_user_tracked(&self, user_id: &UserId) -> bool; + /// Are there any tracked users that are marked as dirty. + fn has_users_for_key_query(&self) -> bool; + /// Set of users that we need to query keys for. This is a subset of /// the tracked users. - fn users_for_key_query(&self) -> &HashSet; + fn users_for_key_query(&self) -> HashSet; /// Add an user for tracking. /// @@ -159,7 +162,7 @@ pub trait CryptoStore: Debug { /// * `user` - The user that should be marked as tracked. /// /// * `dirty` - Should the user be also marked for a key query. - async fn update_tracked_user(&mut self, user: &UserId, dirty: bool) -> Result; + async fn update_tracked_user(&self, user: &UserId, dirty: bool) -> Result; /// Save the given devices in the store. /// diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index 65c10a99..a15269fe 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -21,6 +21,7 @@ use std::{ }; use async_trait::async_trait; +use dashmap::DashSet; use matrix_sdk_common::{ events::Algorithm, identifiers::{DeviceId, DeviceKeyAlgorithm, DeviceKeyId, RoomId, UserId}, @@ -49,8 +50,8 @@ pub struct SqliteStore { sessions: SessionStore, inbound_group_sessions: GroupSessionStore, devices: DeviceStore, - tracked_users: HashSet, - users_for_key_query: HashSet, + tracked_users: DashSet, + users_for_key_query: DashSet, connection: Arc>, pickle_passphrase: Option>, @@ -137,8 +138,8 @@ impl SqliteStore { path: path.as_ref().to_owned(), connection: Arc::new(Mutex::new(connection)), pickle_passphrase: passphrase, - tracked_users: HashSet::new(), - users_for_key_query: HashSet::new(), + tracked_users: DashSet::new(), + users_for_key_query: DashSet::new(), }; store.create_tables().await?; Ok(store) @@ -299,7 +300,7 @@ impl SqliteStore { Ok(()) } - async fn lazy_load_sessions(&mut self, sender_key: &str) -> Result<()> { + async fn lazy_load_sessions(&self, sender_key: &str) -> Result<()> { let loaded_sessions = self.sessions.get(sender_key).is_some(); if !loaded_sessions { @@ -313,15 +314,12 @@ impl SqliteStore { Ok(()) } - async fn get_sessions_for( - &mut self, - sender_key: &str, - ) -> Result>>>> { + async fn get_sessions_for(&self, sender_key: &str) -> Result>>>> { self.lazy_load_sessions(sender_key).await?; Ok(self.sessions.get(sender_key)) } - async fn load_sessions_for(&mut self, sender_key: &str) -> Result> { + async fn load_sessions_for(&self, sender_key: &str) -> Result> { let account_info = self .account_info .as_ref() @@ -417,7 +415,7 @@ impl SqliteStore { Ok(()) } - async fn load_tracked_users(&self) -> Result<(HashSet, HashSet)> { + async fn load_tracked_users(&self) -> Result<()> { let account_id = self.account_id().ok_or(CryptoStoreError::AccountUnset)?; let mut connection = self.connection.lock().await; @@ -429,24 +427,21 @@ impl SqliteStore { .fetch_all(&mut *connection) .await?; - let mut users = HashSet::new(); - let mut users_for_query = HashSet::new(); - for row in rows { let user_id: &str = &row.0; let dirty: bool = row.1; if let Ok(u) = UserId::try_from(user_id) { - users.insert(u.clone()); + self.tracked_users.insert(u.clone()); if dirty { - users_for_query.insert(u); + self.users_for_key_query.insert(u); } } else { continue; }; } - Ok((users, users_for_query)) + Ok(()) } async fn load_devices(&self) -> Result { @@ -700,9 +695,7 @@ impl CryptoStore for SqliteStore { let devices = self.load_devices().await?; self.devices = devices; - let (tracked_users, users_for_query) = self.load_tracked_users().await?; - self.tracked_users = tracked_users; - self.users_for_key_query = users_for_query; + self.load_tracked_users().await?; Ok(result) } @@ -743,7 +736,7 @@ impl CryptoStore for SqliteStore { Ok(()) } - async fn save_sessions(&mut self, sessions: &[Session]) -> Result<()> { + async fn save_sessions(&self, sessions: &[Session]) -> Result<()> { let account_id = self.account_id().ok_or(CryptoStoreError::AccountUnset)?; // TODO turn this into a transaction @@ -776,11 +769,11 @@ impl CryptoStore for SqliteStore { Ok(()) } - async fn get_sessions(&mut self, sender_key: &str) -> Result>>>> { + async fn get_sessions(&self, sender_key: &str) -> Result>>>> { Ok(self.get_sessions_for(sender_key).await?) } - async fn save_inbound_group_session(&mut self, session: InboundGroupSession) -> Result { + async fn save_inbound_group_session(&self, session: InboundGroupSession) -> Result { let account_id = self.account_id().ok_or(CryptoStoreError::AccountUnset)?; let pickle = session.pickle(self.get_pickle_mode()).await; let mut connection = self.connection.lock().await; @@ -808,7 +801,7 @@ impl CryptoStore for SqliteStore { } async fn get_inbound_group_session( - &mut self, + &self, room_id: &RoomId, sender_key: &str, session_id: &str, @@ -822,11 +815,15 @@ impl CryptoStore for SqliteStore { self.tracked_users.contains(user_id) } - fn users_for_key_query(&self) -> &HashSet { - &self.users_for_key_query + fn has_users_for_key_query(&self) -> bool { + !self.users_for_key_query.is_empty() } - async fn update_tracked_user(&mut self, user: &UserId, dirty: bool) -> Result { + fn users_for_key_query(&self) -> HashSet { + self.users_for_key_query.iter().map(|u| u.clone()).collect() + } + + async fn update_tracked_user(&self, user: &UserId, dirty: bool) -> Result { let already_added = self.tracked_users.insert(user.clone()); if dirty { @@ -1135,7 +1132,7 @@ mod test { #[tokio::test] async fn save_inbound_group_session() { - let (account, mut store, _dir) = get_loaded_store().await; + let (account, store, _dir) = get_loaded_store().await; let identity_keys = account.identity_keys(); let outbound_session = OlmOutboundGroupSession::new(); @@ -1155,7 +1152,7 @@ mod test { #[tokio::test] async fn load_inbound_group_session() { - let (account, mut store, _dir) = get_loaded_store().await; + let (account, store, _dir) = get_loaded_store().await; let identity_keys = account.identity_keys(); let outbound_session = OlmOutboundGroupSession::new(); @@ -1188,7 +1185,7 @@ mod test { #[tokio::test] async fn test_tracked_users() { - let (_account, mut store, dir) = get_loaded_store().await; + let (_account, store, dir) = get_loaded_store().await; let device = get_device(); assert!(store From 8f4ac3da7fef049ce84ccbb713ece497af9a17cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 14:43:18 +0200 Subject: [PATCH 04/12] crypto: Change the way we load the devices/sessions in the SqliteStore. --- matrix_sdk_crypto/src/store/sqlite.rs | 43 +++++++++++---------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index a15269fe..9c781e3d 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -363,7 +363,7 @@ impl SqliteStore { .collect::>>()?) } - async fn load_inbound_group_sessions(&self) -> Result> { + async fn load_inbound_group_sessions(&self) -> Result<()> { let account_id = self.account_id().ok_or(CryptoStoreError::AccountUnset)?; let mut connection = self.connection.lock().await; @@ -375,7 +375,7 @@ impl SqliteStore { .fetch_all(&mut *connection) .await?; - Ok(rows + let mut group_sessions = rows .iter() .map(|row| { let pickle = &row.0; @@ -391,7 +391,16 @@ impl SqliteStore { RoomId::try_from(room_id.as_str()).unwrap(), )?) }) - .collect::>>()?) + .collect::>>()?; + + group_sessions + .drain(..) + .map(|s| { + self.inbound_group_sessions.add(s); + }) + .for_each(drop); + + Ok(()) } async fn save_tracked_user(&self, user: &UserId, dirty: bool) -> Result<()> { @@ -444,7 +453,7 @@ impl SqliteStore { Ok(()) } - async fn load_devices(&self) -> Result { + async fn load_devices(&self) -> Result<()> { let account_id = self.account_id().ok_or(CryptoStoreError::AccountUnset)?; let mut connection = self.connection.lock().await; @@ -456,8 +465,6 @@ impl SqliteStore { .fetch_all(&mut *connection) .await?; - let store = DeviceStore::new(); - for row in rows { let device_row_id = row.0; let user_id: &str = &row.1; @@ -550,10 +557,10 @@ impl SqliteStore { signatures, ); - store.add(device); + self.devices.add(device); } - Ok(store) + Ok(()) } async fn save_device_helper(&self, device: Device) -> Result<()> { @@ -683,18 +690,8 @@ impl CryptoStore for SqliteStore { drop(connection); - let mut group_sessions = self.load_inbound_group_sessions().await?; - - group_sessions - .drain(..) - .map(|s| { - self.inbound_group_sessions.add(s); - }) - .for_each(drop); - - let devices = self.load_devices().await?; - self.devices = devices; - + self.load_inbound_group_sessions().await?; + self.load_devices().await?; self.load_tracked_users().await?; Ok(result) @@ -1164,16 +1161,12 @@ mod test { ) .expect("Can't create session"); - let session_id = session.session_id().to_owned(); - store .save_inbound_group_session(session.clone()) .await .expect("Can't save group session"); - let sessions = store.load_inbound_group_sessions().await.unwrap(); - - assert_eq!(session_id, sessions[0].session_id()); + store.load_inbound_group_sessions().await.unwrap(); let loaded_session = store .get_inbound_group_session(&session.room_id, &session.sender_key, session.session_id()) From 947fa08daee75efc58eff485b34adb7d9d7ca975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 15:08:07 +0200 Subject: [PATCH 05/12] crypto: Don't require the load_account to mutably borrow self. --- matrix_sdk_crypto/src/machine.rs | 2 +- matrix_sdk_crypto/src/store/memorystore.rs | 2 +- matrix_sdk_crypto/src/store/mod.rs | 2 +- matrix_sdk_crypto/src/store/sqlite.rs | 33 +++++++++++++--------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 97c21629..7cf3e449 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -147,7 +147,7 @@ impl OlmMachine { pub async fn new_with_store( user_id: UserId, device_id: Box, - mut store: Box, + store: Box, ) -> StoreResult { let account = match store.load_account().await? { Some(a) => { diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index 92d81314..3653905e 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -49,7 +49,7 @@ impl MemoryStore { #[async_trait] impl CryptoStore for MemoryStore { - async fn load_account(&mut self) -> Result> { + async fn load_account(&self) -> Result> { Ok(None) } diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index f58ca246..f7784db7 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -95,7 +95,7 @@ pub type Result = std::result::Result; /// keys. pub trait CryptoStore: Debug { /// Load an account that was previously stored. - async fn load_account(&mut self) -> Result>; + async fn load_account(&self) -> Result>; /// Save the given account in the store. /// diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index 9c781e3d..6beefa1a 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -17,7 +17,7 @@ use std::{ convert::TryFrom, path::{Path, PathBuf}, result::Result as StdResult, - sync::Arc, + sync::{Arc, Mutex as SyncMutex}, }; use async_trait::async_trait; @@ -44,7 +44,7 @@ use crate::{ pub struct SqliteStore { user_id: Arc, device_id: Arc>, - account_info: Option, + account_info: Arc>>, path: PathBuf, sessions: SessionStore, @@ -57,6 +57,7 @@ pub struct SqliteStore { pickle_passphrase: Option>, } +#[derive(Clone)] struct AccountInfo { account_id: i64, identity_keys: Arc, @@ -131,7 +132,7 @@ impl SqliteStore { let store = SqliteStore { user_id: Arc::new(user_id.to_owned()), device_id: Arc::new(device_id.into()), - account_info: None, + account_info: Arc::new(SyncMutex::new(None)), sessions: SessionStore::new(), inbound_group_sessions: GroupSessionStore::new(), devices: DeviceStore::new(), @@ -146,7 +147,11 @@ impl SqliteStore { } fn account_id(&self) -> Option { - self.account_info.as_ref().map(|i| i.account_id) + self.account_info + .lock() + .unwrap() + .as_ref() + .map(|i| i.account_id) } async fn create_tables(&self) -> Result<()> { @@ -322,7 +327,9 @@ impl SqliteStore { async fn load_sessions_for(&self, sender_key: &str) -> Result> { let account_info = self .account_info - .as_ref() + .lock() + .unwrap() + .clone() .ok_or(CryptoStoreError::AccountUnset)?; let mut connection = self.connection.lock().await; @@ -656,7 +663,7 @@ impl SqliteStore { #[async_trait] impl CryptoStore for SqliteStore { - async fn load_account(&mut self) -> Result> { + async fn load_account(&self) -> Result> { let mut connection = self.connection.lock().await; let row: Option<(i64, String, bool, i64)> = query_as( @@ -678,7 +685,7 @@ impl CryptoStore for SqliteStore { &self.device_id, )?; - self.account_info = Some(AccountInfo { + *self.account_info.lock().unwrap() = Some(AccountInfo { account_id: id, identity_keys: account.identity_keys.clone(), }); @@ -725,7 +732,7 @@ impl CryptoStore for SqliteStore { .fetch_one(&mut *connection) .await?; - self.account_info = Some(AccountInfo { + *self.account_info.lock().unwrap() = Some(AccountInfo { account_id: account_id.0, identity_keys: account.identity_keys.clone(), }); @@ -1113,7 +1120,7 @@ mod test { drop(store); - let mut store = SqliteStore::open(&example_user_id(), example_device_id(), dir.path()) + let store = SqliteStore::open(&example_user_id(), example_device_id(), dir.path()) .await .expect("Can't create store"); @@ -1199,7 +1206,7 @@ mod test { assert!(store.users_for_key_query().contains(device.user_id())); drop(store); - let mut store = SqliteStore::open(&example_user_id(), example_device_id(), dir.path()) + let store = SqliteStore::open(&example_user_id(), example_device_id(), dir.path()) .await .expect("Can't create store"); @@ -1214,7 +1221,7 @@ mod test { .unwrap(); assert!(!store.users_for_key_query().contains(device.user_id())); - let mut store = SqliteStore::open(&example_user_id(), example_device_id(), dir.path()) + let store = SqliteStore::open(&example_user_id(), example_device_id(), dir.path()) .await .expect("Can't create store"); @@ -1232,7 +1239,7 @@ mod test { drop(store); - let mut store = SqliteStore::open(&example_user_id(), example_device_id(), dir.path()) + let store = SqliteStore::open(&example_user_id(), example_device_id(), dir.path()) .await .expect("Can't create store"); @@ -1265,7 +1272,7 @@ mod test { store.save_devices(&[device.clone()]).await.unwrap(); store.delete_device(device.clone()).await.unwrap(); - let mut store = SqliteStore::open(&example_user_id(), example_device_id(), dir.path()) + let store = SqliteStore::open(&example_user_id(), example_device_id(), dir.path()) .await .expect("Can't create store"); From 2437a92998734508a309cf107f12103c683f7610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 15:12:15 +0200 Subject: [PATCH 06/12] crypto: Don't require the account loading method to borrow self mutably. --- matrix_sdk_crypto/src/store/memorystore.rs | 4 ++-- matrix_sdk_crypto/src/store/mod.rs | 2 +- matrix_sdk_crypto/src/store/sqlite.rs | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index 3653905e..bcfffe8f 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -53,7 +53,7 @@ impl CryptoStore for MemoryStore { Ok(None) } - async fn save_account(&mut self, _: Account) -> Result<()> { + async fn save_account(&self, _: Account) -> Result<()> { Ok(()) } @@ -140,7 +140,7 @@ mod test { #[tokio::test] async fn test_session_store() { let (account, session) = get_account_and_session().await; - let mut store = MemoryStore::new(); + let store = MemoryStore::new(); assert!(store.load_account().await.unwrap().is_none()); store.save_account(account).await.unwrap(); diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index f7784db7..9b035450 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -102,7 +102,7 @@ pub trait CryptoStore: Debug { /// # Arguments /// /// * `account` - The account that should be stored. - async fn save_account(&mut self, account: Account) -> Result<()>; + async fn save_account(&self, account: Account) -> Result<()>; /// Save the given sessions in the store. /// diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index 6beefa1a..c36d7420 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -704,7 +704,7 @@ impl CryptoStore for SqliteStore { Ok(result) } - async fn save_account(&mut self, account: Account) -> Result<()> { + async fn save_account(&self, account: Account) -> Result<()> { let pickle = account.pickle(self.get_pickle_mode()).await; let mut connection = self.connection.lock().await; @@ -932,7 +932,7 @@ mod test { } async fn get_loaded_store() -> (Account, SqliteStore, tempfile::TempDir) { - let (mut store, dir) = get_store(None).await; + let (store, dir) = get_store(None).await; let account = get_account(); store .save_account(account.clone()) @@ -1000,7 +1000,7 @@ mod test { #[tokio::test] async fn save_account() { - let (mut store, _dir) = get_store(None).await; + let (store, _dir) = get_store(None).await; assert!(store.load_account().await.unwrap().is_none()); let account = get_account(); @@ -1012,7 +1012,7 @@ mod test { #[tokio::test] async fn load_account() { - let (mut store, _dir) = get_store(None).await; + let (store, _dir) = get_store(None).await; let account = get_account(); store @@ -1028,7 +1028,7 @@ mod test { #[tokio::test] async fn load_account_with_passphrase() { - let (mut store, _dir) = get_store(Some("secret_passphrase")).await; + let (store, _dir) = get_store(Some("secret_passphrase")).await; let account = get_account(); store @@ -1044,7 +1044,7 @@ mod test { #[tokio::test] async fn save_and_share_account() { - let (mut store, _dir) = get_store(None).await; + let (store, _dir) = get_store(None).await; let account = get_account(); store @@ -1067,7 +1067,7 @@ mod test { #[tokio::test] async fn save_session() { - let (mut store, _dir) = get_store(None).await; + let (store, _dir) = get_store(None).await; let (account, session) = get_account_and_session().await; assert!(store.save_sessions(&[session.clone()]).await.is_err()); @@ -1082,7 +1082,7 @@ mod test { #[tokio::test] async fn load_sessions() { - let (mut store, _dir) = get_store(None).await; + let (store, _dir) = get_store(None).await; let (account, session) = get_account_and_session().await; store .save_account(account.clone()) @@ -1101,7 +1101,7 @@ mod test { #[tokio::test] async fn add_and_save_session() { - let (mut store, dir) = get_store(None).await; + let (store, dir) = get_store(None).await; let (account, session) = get_account_and_session().await; let sender_key = session.sender_key.to_owned(); let session_id = session.session_id().to_owned(); From 707b4c11858d664fe1c1da5bb4d0e636581028fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 15:17:33 +0200 Subject: [PATCH 07/12] crypto: Put a bunch of crypto store stuff behind atomic references. --- matrix_sdk_crypto/src/store/memorystore.rs | 8 ++++---- matrix_sdk_crypto/src/store/sqlite.rs | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index bcfffe8f..f94b0a8b 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -30,8 +30,8 @@ use crate::{ pub struct MemoryStore { sessions: SessionStore, inbound_group_sessions: GroupSessionStore, - tracked_users: DashSet, - users_for_key_query: DashSet, + tracked_users: Arc>, + users_for_key_query: Arc>, devices: DeviceStore, } @@ -40,8 +40,8 @@ impl MemoryStore { MemoryStore { sessions: SessionStore::new(), inbound_group_sessions: GroupSessionStore::new(), - tracked_users: DashSet::new(), - users_for_key_query: DashSet::new(), + tracked_users: Arc::new(DashSet::new()), + users_for_key_query: Arc::new(DashSet::new()), devices: DeviceStore::new(), } } diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index c36d7420..17d67be5 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -45,16 +45,16 @@ pub struct SqliteStore { user_id: Arc, device_id: Arc>, account_info: Arc>>, - path: PathBuf, + path: Arc, sessions: SessionStore, inbound_group_sessions: GroupSessionStore, devices: DeviceStore, - tracked_users: DashSet, - users_for_key_query: DashSet, + tracked_users: Arc>, + users_for_key_query: Arc>, connection: Arc>, - pickle_passphrase: Option>, + pickle_passphrase: Arc>>, } #[derive(Clone)] @@ -136,11 +136,11 @@ impl SqliteStore { sessions: SessionStore::new(), inbound_group_sessions: GroupSessionStore::new(), devices: DeviceStore::new(), - path: path.as_ref().to_owned(), + path: Arc::new(path.as_ref().to_owned()), connection: Arc::new(Mutex::new(connection)), - pickle_passphrase: passphrase, - tracked_users: DashSet::new(), - users_for_key_query: DashSet::new(), + pickle_passphrase: Arc::new(passphrase), + tracked_users: Arc::new(DashSet::new()), + users_for_key_query: Arc::new(DashSet::new()), }; store.create_tables().await?; Ok(store) @@ -652,7 +652,7 @@ impl SqliteStore { } fn get_pickle_mode(&self) -> PicklingMode { - match &self.pickle_passphrase { + match &*self.pickle_passphrase { Some(p) => PicklingMode::Encrypted { key: p.as_bytes().to_vec(), }, From d0a5b86ff3bb8ffea5508c34e4695f39b25ce166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 15:39:50 +0200 Subject: [PATCH 08/12] crypto: Remove our lock around the cryptostore. --- matrix_sdk_crypto/src/machine.rs | 154 ++++-------------- matrix_sdk_crypto/src/store/memorystore.rs | 2 +- matrix_sdk_crypto/src/store/sqlite.rs | 1 + matrix_sdk_crypto/src/verification/machine.rs | 17 +- .../src/verification/sas/helpers.rs | 2 - matrix_sdk_crypto/src/verification/sas/mod.rs | 20 +-- 6 files changed, 44 insertions(+), 152 deletions(-) diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 7cf3e449..e7332096 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -41,7 +41,6 @@ use matrix_sdk_common::{ Algorithm, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent, ToDeviceEvent, }, identifiers::{DeviceId, DeviceKeyAlgorithm, DeviceKeyId, RoomId, UserId}, - locks::RwLock, uuid::Uuid, Raw, }; @@ -80,7 +79,7 @@ pub struct OlmMachine { /// Store for the encryption keys. /// Persists all the encryption keys so a client can resume the session /// without the need to create new keys. - store: Arc>>, + store: Arc>, /// The currently active outbound group sessions. outbound_group_sessions: Arc>, /// A state machine that is responsible to handle and keep track of SAS @@ -111,10 +110,9 @@ impl OlmMachine { /// * `user_id` - The unique id of the user that owns this machine. /// /// * `device_id` - The unique id of the device that owns this machine. - #[allow(clippy::ptr_arg)] pub fn new(user_id: &UserId, device_id: &DeviceId) -> Self { let store: Box = Box::new(MemoryStore::new()); - let store = Arc::new(RwLock::new(store)); + let store = Arc::new(store); let account = Account::new(user_id, device_id); OlmMachine { @@ -160,7 +158,7 @@ impl OlmMachine { } }; - let store = Arc::new(RwLock::new(store)); + let store = Arc::new(store); let verification_machine = VerificationMachine::new(account.clone(), store.clone()); Ok(OlmMachine { @@ -250,11 +248,7 @@ impl OlmMachine { self.update_key_count(count); self.account.mark_keys_as_published().await; - self.store - .write() - .await - .save_account(self.account.clone()) - .await?; + self.store.save_account(self.account.clone()).await?; Ok(()) } @@ -285,7 +279,7 @@ impl OlmMachine { let mut missing = BTreeMap::new(); for user_id in users { - let user_devices = self.store.read().await.get_user_devices(user_id).await?; + let user_devices = self.store.get_user_devices(user_id).await?; for device in user_devices.devices() { let sender_key = if let Some(k) = device.get_key(DeviceKeyAlgorithm::Curve25519) { @@ -294,7 +288,7 @@ impl OlmMachine { continue; }; - let sessions = self.store.write().await.get_sessions(sender_key).await?; + let sessions = self.store.get_sessions(sender_key).await?; let is_missing = if let Some(sessions) = sessions { sessions.lock().await.is_empty() @@ -333,13 +327,7 @@ impl OlmMachine { for (user_id, user_devices) in &response.one_time_keys { for (device_id, key_map) in user_devices { - let device: Device = match self - .store - .read() - .await - .get_device(&user_id, device_id) - .await - { + let device: Device = match self.store.get_device(&user_id, device_id).await { Ok(Some(d)) => d, Ok(None) => { warn!( @@ -368,7 +356,7 @@ impl OlmMachine { } }; - if let Err(e) = self.store.write().await.save_sessions(&[session]).await { + if let Err(e) = self.store.save_sessions(&[session]).await { error!("Failed to store newly created Olm session {}", e); continue; } @@ -389,11 +377,7 @@ impl OlmMachine { let mut changed_devices = Vec::new(); for (user_id, device_map) in device_keys_map { - self.store - .write() - .await - .update_tracked_user(user_id, false) - .await?; + self.store.update_tracked_user(user_id, false).await?; for (device_id, device_keys) in device_map.iter() { // We don't need our own device in the device store. @@ -409,12 +393,7 @@ impl OlmMachine { continue; } - let device = self - .store - .read() - .await - .get_device(&user_id, device_id) - .await?; + let device = self.store.get_device(&user_id, device_id).await?; let device = if let Some(mut device) = device { if let Err(e) = device.update_device(device_keys) { @@ -445,13 +424,7 @@ impl OlmMachine { let current_devices: HashSet<&DeviceId> = device_map.keys().map(|id| id.as_ref()).collect(); - let stored_devices = self - .store - .read() - .await - .get_user_devices(&user_id) - .await - .unwrap(); + let stored_devices = self.store.get_user_devices(&user_id).await.unwrap(); let stored_devices_set: HashSet<&DeviceId> = stored_devices.keys().collect(); let deleted_devices = stored_devices_set.difference(¤t_devices); @@ -459,7 +432,7 @@ impl OlmMachine { for device_id in deleted_devices { if let Some(device) = stored_devices.get(device_id) { device.mark_as_deleted(); - self.store.write().await.delete_device(device).await?; + self.store.delete_device(device).await?; } } } @@ -483,11 +456,7 @@ impl OlmMachine { let changed_devices = self .handle_devices_from_key_query(&response.device_keys) .await?; - self.store - .write() - .await - .save_devices(&changed_devices) - .await?; + self.store.save_devices(&changed_devices).await?; Ok(changed_devices) } @@ -511,7 +480,7 @@ impl OlmMachine { sender_key: &str, message: &OlmMessage, ) -> OlmResult> { - let s = self.store.write().await.get_sessions(sender_key).await?; + let s = self.store.get_sessions(sender_key).await?; // We don't have any existing sessions, return early. let sessions = if let Some(s) = s { @@ -561,7 +530,7 @@ impl OlmMachine { // Decryption was successful, save the new ratchet state of the // session that was used to decrypt the message. trace!("Saved the new session state for {}", sender); - self.store.write().await.save_sessions(&[session]).await?; + self.store.save_sessions(&[session]).await?; } Ok(plaintext) @@ -616,11 +585,7 @@ impl OlmMachine { // Save the account since we remove the one-time key that // was used to create this session. - self.store - .write() - .await - .save_account(self.account.clone()) - .await?; + self.store.save_account(self.account.clone()).await?; session } }; @@ -630,7 +595,7 @@ impl OlmMachine { let plaintext = session.decrypt(message).await?; // Save the new ratcheted state of the session. - self.store.write().await.save_sessions(&[session]).await?; + self.store.save_sessions(&[session]).await?; plaintext }; @@ -781,12 +746,7 @@ impl OlmMachine { &event.content.room_id, session_key, )?; - let _ = self - .store - .write() - .await - .save_inbound_group_session(session) - .await?; + let _ = self.store.save_inbound_group_session(session).await?; let event = Raw::from(AnyToDeviceEvent::RoomKey(event.clone())); Ok(Some(event)) @@ -808,12 +768,7 @@ impl OlmMachine { async fn create_outbound_group_session(&self, room_id: &RoomId) -> OlmResult<()> { let (outbound, inbound) = self.account.create_group_session_pair(room_id).await; - let _ = self - .store - .write() - .await - .save_inbound_group_session(inbound) - .await?; + let _ = self.store.save_inbound_group_session(inbound).await?; let _ = self .outbound_group_sessions @@ -899,8 +854,7 @@ impl OlmMachine { return Err(EventError::MissingSenderKey.into()); }; - let mut session = if let Some(s) = self.store.write().await.get_sessions(sender_key).await? - { + let mut session = if let Some(s) = self.store.get_sessions(sender_key).await? { let session = &s.lock().await[0]; session.clone() } else { @@ -914,7 +868,7 @@ impl OlmMachine { }; let message = session.encrypt(recipient_device, event_type, content).await; - self.store.write().await.save_sessions(&[session]).await?; + self.store.save_sessions(&[session]).await?; message } @@ -978,14 +932,7 @@ impl OlmMachine { let mut devices = Vec::new(); for user_id in users { - for device in self - .store - .read() - .await - .get_user_devices(user_id) - .await? - .devices() - { + for device in self.store.get_user_devices(user_id).await?.devices() { devices.push(device.clone()); } } @@ -1192,8 +1139,6 @@ impl OlmMachine { let session = self .store - .write() - .await .get_inbound_group_session(room_id, &content.sender_key, &content.session_id) .await?; // TODO check if the Olm session is wedged and re-request the key. @@ -1219,12 +1164,8 @@ impl OlmMachine { /// /// Returns true if the user was queued up for a key query, false otherwise. pub async fn mark_user_as_changed(&self, user_id: &UserId) -> StoreResult { - if self.store.read().await.is_user_tracked(user_id) { - self.store - .write() - .await - .update_tracked_user(user_id, true) - .await?; + if self.store.is_user_tracked(user_id) { + self.store.update_tracked_user(user_id, true).await?; Ok(true) } else { Ok(false) @@ -1250,17 +1191,11 @@ impl OlmMachine { I: IntoIterator, { for user in users { - if self.store.read().await.is_user_tracked(user) { + if self.store.is_user_tracked(user) { continue; } - if let Err(e) = self - .store - .write() - .await - .update_tracked_user(user, true) - .await - { + if let Err(e) = self.store.update_tracked_user(user, true).await { warn!("Error storing users for tracking {}", e); } } @@ -1268,14 +1203,14 @@ impl OlmMachine { /// Should the client perform a key query request. pub async fn should_query_keys(&self) -> bool { - self.store.read().await.has_users_for_key_query() + self.store.has_users_for_key_query() } /// Get the set of users that we need to query keys for. /// /// Returns a hash set of users that need to be queried for keys. pub async fn users_for_key_query(&self) -> HashSet { - self.store.read().await.users_for_key_query() + self.store.users_for_key_query() } } @@ -1398,19 +1333,8 @@ mod test { let alice_deivce = Device::from_machine(&alice).await; let bob_device = Device::from_machine(&bob).await; - alice - .store - .write() - .await - .save_devices(&[bob_device]) - .await - .unwrap(); - bob.store - .write() - .await - .save_devices(&[alice_deivce]) - .await - .unwrap(); + alice.store.save_devices(&[bob_device]).await.unwrap(); + bob.store.save_devices(&[alice_deivce]).await.unwrap(); (alice, bob, otk) } @@ -1443,8 +1367,6 @@ mod test { let bob_device = alice .store - .read() - .await .get_device(&bob.user_id, &bob.device_id) .await .unwrap() @@ -1649,13 +1571,7 @@ mod test { let alice_id = user_id!("@alice:example.org"); let alice_device_id: &DeviceId = "JLAFKJWSCS".into(); - let alice_devices = machine - .store - .read() - .await - .get_user_devices(&alice_id) - .await - .unwrap(); + let alice_devices = machine.store.get_user_devices(&alice_id).await.unwrap(); assert!(alice_devices.devices().peekable().peek().is_none()); machine @@ -1665,8 +1581,6 @@ mod test { let device = machine .store - .read() - .await .get_device(&alice_id, alice_device_id) .await .unwrap() @@ -1718,8 +1632,6 @@ mod test { let session = alice_machine .store - .write() - .await .get_sessions(bob_machine.account.identity_keys().curve25519()) .await .unwrap() @@ -1734,8 +1646,6 @@ mod test { let bob_device = alice .store - .read() - .await .get_device(&bob.user_id, &bob.device_id) .await .unwrap() @@ -1797,8 +1707,6 @@ mod test { let session = bob .store - .write() - .await .get_inbound_group_session( &room_id, alice.account.identity_keys().curve25519(), diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index f94b0a8b..4ad08cc0 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -26,7 +26,7 @@ use crate::{ device::Device, memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}, }; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct MemoryStore { sessions: SessionStore, inbound_group_sessions: GroupSessionStore, diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index 17d67be5..1800a463 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -41,6 +41,7 @@ use crate::{ }; /// SQLite based implementation of a `CryptoStore`. +#[derive(Clone)] pub struct SqliteStore { user_id: Arc, device_id: Arc>, diff --git a/matrix_sdk_crypto/src/verification/machine.rs b/matrix_sdk_crypto/src/verification/machine.rs index ca3fc2f4..cea74359 100644 --- a/matrix_sdk_crypto/src/verification/machine.rs +++ b/matrix_sdk_crypto/src/verification/machine.rs @@ -22,7 +22,6 @@ use matrix_sdk_common::{ api::r0::to_device::send_event_to_device::IncomingRequest as OwnedToDeviceRequest, events::{AnyToDeviceEvent, AnyToDeviceEventContent}, identifiers::{DeviceId, UserId}, - locks::RwLock, }; use super::sas::{content_to_request, Sas}; @@ -31,13 +30,13 @@ use crate::{Account, CryptoStore, CryptoStoreError}; #[derive(Clone, Debug)] pub struct VerificationMachine { account: Account, - store: Arc>>, + store: Arc>, verifications: Arc>, outgoing_to_device_messages: Arc>, } impl VerificationMachine { - pub(crate) fn new(account: Account, store: Arc>>) -> Self { + pub(crate) fn new(account: Account, store: Arc>) -> Self { Self { account, store, @@ -112,8 +111,6 @@ impl VerificationMachine { if let Some(d) = self .store - .read() - .await .get_device(&e.sender, &e.content.from_device) .await? { @@ -179,7 +176,6 @@ mod test { use matrix_sdk_common::{ events::AnyToDeviceEventContent, identifiers::{DeviceId, UserId}, - locks::RwLock, }; use super::{Sas, VerificationMachine}; @@ -209,21 +205,18 @@ mod test { let alice = Account::new(&alice_id(), &alice_device_id()); let bob = Account::new(&bob_id(), &bob_device_id()); let store = MemoryStore::new(); - let bob_store: Arc>> = - Arc::new(RwLock::new(Box::new(MemoryStore::new()))); + let bob_store: Arc> = Arc::new(Box::new(MemoryStore::new())); let bob_device = Device::from_account(&bob).await; let alice_device = Device::from_account(&alice).await; store.save_devices(&[bob_device]).await.unwrap(); bob_store - .read() - .await .save_devices(&[alice_device.clone()]) .await .unwrap(); - let machine = VerificationMachine::new(alice, Arc::new(RwLock::new(Box::new(store)))); + let machine = VerificationMachine::new(alice, Arc::new(Box::new(store))); let (bob_sas, start_content) = Sas::start(bob, alice_device, bob_store); machine .receive_event(&mut wrap_any_to_device_content( @@ -240,7 +233,7 @@ mod test { fn create() { let alice = Account::new(&alice_id(), &alice_device_id()); let store = MemoryStore::new(); - let _ = VerificationMachine::new(alice, Arc::new(RwLock::new(Box::new(store)))); + let _ = VerificationMachine::new(alice, Arc::new(Box::new(store))); } #[tokio::test] diff --git a/matrix_sdk_crypto/src/verification/sas/helpers.rs b/matrix_sdk_crypto/src/verification/sas/helpers.rs index 1715db9b..3e0fb143 100644 --- a/matrix_sdk_crypto/src/verification/sas/helpers.rs +++ b/matrix_sdk_crypto/src/verification/sas/helpers.rs @@ -212,8 +212,6 @@ fn extra_mac_info_send(ids: &SasIds, flow_id: &str) -> String { /// /// * `flow_id` - The unique id that identifies this SAS verification process. /// -/// * `we_started` - Flag signaling if the SAS process was started on our side. -/// /// # Panics /// /// This will panic if the public key of the other side wasn't set. diff --git a/matrix_sdk_crypto/src/verification/sas/mod.rs b/matrix_sdk_crypto/src/verification/sas/mod.rs index 49c86cbf..a3d2d40e 100644 --- a/matrix_sdk_crypto/src/verification/sas/mod.rs +++ b/matrix_sdk_crypto/src/verification/sas/mod.rs @@ -31,7 +31,6 @@ use matrix_sdk_common::{ AnyToDeviceEvent, AnyToDeviceEventContent, ToDeviceEvent, }, identifiers::{DeviceId, UserId}, - locks::RwLock, }; use crate::{Account, CryptoStore, CryptoStoreError, Device, TrustState}; @@ -45,7 +44,7 @@ use sas_state::{ /// Short authentication string object. pub struct Sas { inner: Arc>, - store: Arc>>, + store: Arc>, account: Account, other_device: Device, flow_id: Arc, @@ -100,7 +99,7 @@ impl Sas { pub(crate) fn start( account: Account, other_device: Device, - store: Arc>>, + store: Arc>, ) -> (Sas, StartEventContent) { let (inner, content) = InnerSas::start(account.clone(), other_device.clone()); let flow_id = inner.verification_flow_id(); @@ -129,7 +128,7 @@ impl Sas { pub(crate) fn from_start_event( account: Account, other_device: Device, - store: Arc>>, + store: Arc>, event: &ToDeviceEvent, ) -> Result { let inner = InnerSas::from_start_event(account.clone(), other_device.clone(), event)?; @@ -184,8 +183,6 @@ impl Sas { pub(crate) async fn mark_device_as_verified(&self) -> Result { let device = self .store - .read() - .await .get_device(self.other_user_id(), self.other_device_id()) .await?; @@ -202,7 +199,7 @@ impl Sas { ); device.set_trust_state(TrustState::Verified); - self.store.read().await.save_devices(&[device]).await?; + self.store.save_devices(&[device]).await?; Ok(true) } else { @@ -560,7 +557,6 @@ mod test { use matrix_sdk_common::{ events::{EventContent, ToDeviceEvent}, identifiers::{DeviceId, UserId}, - locks::RwLock, }; use crate::{ @@ -685,14 +681,10 @@ mod test { let bob = Account::new(&bob_id(), &bob_device_id()); let bob_device = Device::from_account(&bob).await; - let alice_store: Arc>> = - Arc::new(RwLock::new(Box::new(MemoryStore::new()))); - let bob_store: Arc>> = - Arc::new(RwLock::new(Box::new(MemoryStore::new()))); + let alice_store: Arc> = Arc::new(Box::new(MemoryStore::new())); + let bob_store: Arc> = Arc::new(Box::new(MemoryStore::new())); bob_store - .read() - .await .save_devices(&[alice_device.clone()]) .await .unwrap(); From 7637e79f2c8e0d70c753237116b492ed52aa2860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 15:49:04 +0200 Subject: [PATCH 09/12] matrix-sdk: Fix the tarpaulin skip directives. --- matrix_sdk/src/client.rs | 4 ++-- matrix_sdk_base/src/client.rs | 4 ++-- matrix_sdk_crypto/src/device.rs | 2 +- matrix_sdk_crypto/src/machine.rs | 10 ++++++++-- matrix_sdk_crypto/src/olm/account.rs | 2 +- matrix_sdk_crypto/src/olm/group_sessions.rs | 4 ++-- matrix_sdk_crypto/src/olm/session.rs | 2 +- matrix_sdk_crypto/src/store/sqlite.rs | 2 +- matrix_sdk_crypto/src/verification/sas/sas_state.rs | 2 ++ 9 files changed, 20 insertions(+), 12 deletions(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 74f47a2f..548f3a4c 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -74,7 +74,7 @@ pub struct Client { pub(crate) base_client: BaseClient, } -// #[cfg_attr(tarpaulin, skip)] +#[cfg(not(tarpaulin_include))] impl Debug for Client { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> StdResult<(), fmt::Error> { write!(fmt, "Client {{ homeserver: {} }}", self.homeserver) @@ -115,7 +115,7 @@ pub struct ClientConfig { timeout: Option, } -// #[cfg_attr(tarpaulin, skip)] +#[cfg(not(tarpaulin_include))] impl Debug for ClientConfig { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { let mut res = fmt.debug_struct("ClientConfig"); diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index 21168bf0..fc26e0a7 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -212,7 +212,7 @@ pub struct BaseClient { store_passphrase: Arc>, } -// #[cfg_attr(tarpaulin, skip)] +#[cfg(not(tarpaulin_include))] impl fmt::Debug for BaseClient { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Client") @@ -246,7 +246,7 @@ pub struct BaseClientConfig { passphrase: Option>, } -// #[cfg_attr(tarpaulin, skip)] +#[cfg(not(tarpaulin_include))] impl std::fmt::Debug for BaseClientConfig { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> StdResult<(), std::fmt::Error> { fmt.debug_struct("BaseClientConfig").finish() diff --git a/matrix_sdk_crypto/src/device.rs b/matrix_sdk_crypto/src/device.rs index 62a54bb8..eafb193b 100644 --- a/matrix_sdk_crypto/src/device.rs +++ b/matrix_sdk_crypto/src/device.rs @@ -198,7 +198,7 @@ impl Device { #[cfg(test)] pub async fn from_machine(machine: &OlmMachine) -> Device { - Device::from_account(&machine.account).await + Device::from_account(machine.account()).await } #[cfg(test)] diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index e7332096..73adde35 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -75,7 +75,7 @@ pub struct OlmMachine { /// The unique device id of the device that holds this account. device_id: Box, /// Our underlying Olm Account holding our identity keys. - pub(crate) account: Account, + account: Account, /// Store for the encryption keys. /// Persists all the encryption keys so a client can resume the session /// without the need to create new keys. @@ -87,7 +87,7 @@ pub struct OlmMachine { verification_machine: VerificationMachine, } -// #[cfg_attr(tarpaulin, skip)] +#[cfg(not(tarpaulin_include))] impl std::fmt::Debug for OlmMachine { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("OlmMachine") @@ -214,6 +214,12 @@ impl OlmMachine { self.account.should_upload_keys().await } + /// Get the underlying Olm account of the machine. + #[cfg(test)] + pub(crate) fn account(&self) -> &Account { + &self.account + } + /// Update the count of one-time keys that are currently on the server. fn update_key_count(&self, count: u64) { self.account.update_uploaded_key_count(count); diff --git a/matrix_sdk_crypto/src/olm/account.rs b/matrix_sdk_crypto/src/olm/account.rs index a8cd18ee..5ee89216 100644 --- a/matrix_sdk_crypto/src/olm/account.rs +++ b/matrix_sdk_crypto/src/olm/account.rs @@ -63,7 +63,7 @@ pub struct Account { uploaded_signed_key_count: Arc, } -// #[cfg_attr(tarpaulin, skip)] +#[cfg(not(tarpaulin_include))] impl fmt::Debug for Account { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Account") diff --git a/matrix_sdk_crypto/src/olm/group_sessions.rs b/matrix_sdk_crypto/src/olm/group_sessions.rs index bbb36227..717877b6 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions.rs @@ -222,7 +222,7 @@ impl InboundGroupSession { } } -// #[cfg_attr(tarpaulin, skip)] +#[cfg(not(tarpaulin_include))] impl fmt::Debug for InboundGroupSession { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("InboundGroupSession") @@ -401,7 +401,7 @@ impl OutboundGroupSession { } } -// #[cfg_attr(tarpaulin, skip)] +#[cfg(not(tarpaulin_include))] impl std::fmt::Debug for OutboundGroupSession { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("OutboundGroupSession") diff --git a/matrix_sdk_crypto/src/olm/session.rs b/matrix_sdk_crypto/src/olm/session.rs index 07a3339a..a4f31a32 100644 --- a/matrix_sdk_crypto/src/olm/session.rs +++ b/matrix_sdk_crypto/src/olm/session.rs @@ -51,7 +51,7 @@ pub struct Session { pub(crate) last_use_time: Arc, } -// #[cfg_attr(tarpaulin, skip)] +#[cfg(not(tarpaulin_include))] impl fmt::Debug for Session { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Session") diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index 1800a463..5fd4e3be 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -880,7 +880,7 @@ impl CryptoStore for SqliteStore { } } -// #[cfg_attr(tarpaulin, skip)] +#[cfg(not(tarpaulin_include))] impl std::fmt::Debug for SqliteStore { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> StdResult<(), std::fmt::Error> { fmt.debug_struct("SqliteStore") diff --git a/matrix_sdk_crypto/src/verification/sas/sas_state.rs b/matrix_sdk_crypto/src/verification/sas/sas_state.rs index eaeb6bf3..80f3032e 100644 --- a/matrix_sdk_crypto/src/verification/sas/sas_state.rs +++ b/matrix_sdk_crypto/src/verification/sas/sas_state.rs @@ -98,6 +98,7 @@ impl TryFrom for AcceptedProtocols { } } +#[cfg(not(tarpaulin_include))] impl Default for AcceptedProtocols { fn default() -> Self { AcceptedProtocols { @@ -146,6 +147,7 @@ pub struct SasState { state: Arc, } +#[cfg(not(tarpaulin_include))] impl std::fmt::Debug for SasState { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("SasState") From fa1a40543c19f082dd84f3b7cc2e5f25aeae94b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 15:55:13 +0200 Subject: [PATCH 10/12] crypto: Add a missing license header to the sas helpers file. --- matrix_sdk_crypto/src/verification/sas/helpers.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/matrix_sdk_crypto/src/verification/sas/helpers.rs b/matrix_sdk_crypto/src/verification/sas/helpers.rs index 3e0fb143..f5dfa24f 100644 --- a/matrix_sdk_crypto/src/verification/sas/helpers.rs +++ b/matrix_sdk_crypto/src/verification/sas/helpers.rs @@ -1,3 +1,17 @@ +// Copyright 2020 The Matrix.org Foundation C.I.C. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use std::{collections::BTreeMap, convert::TryInto}; use tracing::trace; From 0d2f8c6d0f5494a35901b7e72fce9191525b010b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 16:01:48 +0200 Subject: [PATCH 11/12] crypto: Fix some clippy warnings. --- matrix_sdk_crypto/src/store/memorystore.rs | 1 + matrix_sdk_crypto/src/store/sqlite.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index 4ad08cc0..d901e0b5 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -85,6 +85,7 @@ impl CryptoStore for MemoryStore { } fn users_for_key_query(&self) -> HashSet { + #[allow(clippy::map_clone)] self.users_for_key_query.iter().map(|u| u.clone()).collect() } diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index 5fd4e3be..ede11f5c 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -825,6 +825,7 @@ impl CryptoStore for SqliteStore { } fn users_for_key_query(&self) -> HashSet { + #[allow(clippy::map_clone)] self.users_for_key_query.iter().map(|u| u.clone()).collect() } From c4ed5b6cda1ec49aa1daadc97ac1653e9b7baa17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 11 Aug 2020 16:54:58 +0200 Subject: [PATCH 12/12] matrix-sdk: Upgrade our deps. --- Cargo.toml | 4 ---- matrix_sdk/Cargo.toml | 12 ++++++------ matrix_sdk_base/Cargo.toml | 16 ++++++++-------- matrix_sdk_common/Cargo.toml | 4 ++-- matrix_sdk_common_macros/Cargo.toml | 2 +- matrix_sdk_crypto/Cargo.toml | 12 ++++++------ matrix_sdk_crypto/src/verification/mod.rs | 1 - matrix_sdk_test/Cargo.toml | 4 ++-- 8 files changed, 25 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c4925020..fc993d0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,3 @@ members = [ "matrix_sdk_common", "matrix_sdk_common_macros", ] - -[patch.crates-io] -olm-rs = { git = 'https://gitlab.gnome.org/jhaye/olm-rs/'} -olm-sys = { git = 'https://gitlab.gnome.org/BrainBlasted/olm-sys' } diff --git a/matrix_sdk/Cargo.toml b/matrix_sdk/Cargo.toml index ac819118..fe62a9b9 100644 --- a/matrix_sdk/Cargo.toml +++ b/matrix_sdk/Cargo.toml @@ -20,9 +20,9 @@ sqlite-cryptostore = ["matrix-sdk-base/sqlite-cryptostore"] http = "0.2.1" # FIXME: Revert to regular dependency once 0.10.8 or 0.11.0 is released reqwest = { git = "https://github.com/seanmonstar/reqwest", rev = "dd8441fd23dae6ffb79b4cea2862e5bca0c59743" } -serde_json = "1.0.56" +serde_json = "1.0.57" thiserror = "1.0.20" -tracing = "0.1.16" +tracing = "0.1.19" url = "2.1.1" matrix-sdk-common-macros = { version = "0.1.0", path = "../matrix_sdk_common_macros" } @@ -49,11 +49,11 @@ features = ["wasm-bindgen"] async-trait = "0.1.36" dirs = "3.0.1" matrix-sdk-test = { version = "0.1.0", path = "../matrix_sdk_test" } -tokio = { version = "0.2.21", features = ["rt-threaded", "macros"] } -serde_json = "1.0.56" -tracing-subscriber = "0.2.7" +tokio = { version = "0.2.22", features = ["rt-threaded", "macros"] } +serde_json = "1.0.57" +tracing-subscriber = "0.2.11" tempfile = "3.1.0" -mockito = "0.26.0" +mockito = "0.27.0" lazy_static = "1.4.0" futures = "0.3.5" diff --git a/matrix_sdk_base/Cargo.toml b/matrix_sdk_base/Cargo.toml index 5c16e448..b1e919d4 100644 --- a/matrix_sdk_base/Cargo.toml +++ b/matrix_sdk_base/Cargo.toml @@ -18,10 +18,10 @@ sqlite-cryptostore = ["matrix-sdk-crypto/sqlite-cryptostore"] [dependencies] async-trait = "0.1.36" -serde = "1.0.114" -serde_json = "1.0.56" +serde = "1.0.115" +serde_json = "1.0.57" zeroize = "1.1.0" -tracing = "0.1.16" +tracing = "0.1.19" matrix-sdk-common-macros = { version = "0.1.0", path = "../matrix_sdk_common_macros" } matrix-sdk-common = { version = "0.1.0", path = "../matrix_sdk_common" } @@ -31,19 +31,19 @@ matrix-sdk-crypto = { version = "0.1.0", path = "../matrix_sdk_crypto", optional thiserror = "1.0.20" [target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio] -version = "0.2.21" +version = "0.2.22" default-features = false features = ["sync", "fs"] [dev-dependencies] matrix-sdk-test = { version = "0.1.0", path = "../matrix_sdk_test" } http = "0.2.1" -tracing-subscriber = "0.2.7" +tracing-subscriber = "0.2.11" tempfile = "3.1.0" -mockito = "0.26.0" +mockito = "0.27.0" [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] -tokio = { version = "0.2.21", features = ["rt-threaded", "macros"] } +tokio = { version = "0.2.22", features = ["rt-threaded", "macros"] } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] -wasm-bindgen-test = "0.3.15" +wasm-bindgen-test = "0.3.17" diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index 71f5ac16..bb8aff84 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -12,7 +12,7 @@ version = "0.1.0" [dependencies] instant = { version = "0.1.6", features = ["wasm-bindgen", "now"] } -js_int = "0.1.8" +js_int = "0.1.9" [dependencies.ruma] version = "0.0.1" @@ -24,7 +24,7 @@ features = ["client-api"] uuid = { version = "0.8.1", features = ["v4"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio] -version = "0.2.21" +version = "0.2.22" default-features = false features = ["sync", "time", "fs"] diff --git a/matrix_sdk_common_macros/Cargo.toml b/matrix_sdk_common_macros/Cargo.toml index 959d5805..6648570f 100644 --- a/matrix_sdk_common_macros/Cargo.toml +++ b/matrix_sdk_common_macros/Cargo.toml @@ -14,5 +14,5 @@ version = "0.1.0" proc-macro = true [dependencies] -syn = "1.0.34" +syn = "1.0.38" quote = "1.0.7" diff --git a/matrix_sdk_crypto/Cargo.toml b/matrix_sdk_crypto/Cargo.toml index 509a3ee3..64f2d2f3 100644 --- a/matrix_sdk_crypto/Cargo.toml +++ b/matrix_sdk_crypto/Cargo.toml @@ -20,18 +20,18 @@ async-trait = "0.1.36" matrix-sdk-common-macros = { version = "0.1.0", path = "../matrix_sdk_common_macros" } matrix-sdk-common = { version = "0.1.0", path = "../matrix_sdk_common" } -olm-rs = { version = "0.5.0", features = ["serde"] } -serde = { version = "1.0.114", features = ["derive"] } -serde_json = "1.0.56" +olm-rs = { git = 'https://gitlab.gnome.org/jhaye/olm-rs/', features = ["serde"]} +serde = { version = "1.0.115", features = ["derive"] } +serde_json = "1.0.57" cjson = "0.1.1" zeroize = { version = "1.1.0", features = ["zeroize_derive"] } url = "2.1.1" # Misc dependencies thiserror = "1.0.20" -tracing = "0.1.16" -atomic = "0.4.6" -dashmap = "3.11.7" +tracing = "0.1.19" +atomic = "0.5.0" +dashmap = "3.11.10" [dependencies.tracing-futures] version = "0.2.4" diff --git a/matrix_sdk_crypto/src/verification/mod.rs b/matrix_sdk_crypto/src/verification/mod.rs index 2f2f23a2..db955382 100644 --- a/matrix_sdk_crypto/src/verification/mod.rs +++ b/matrix_sdk_crypto/src/verification/mod.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[allow(dead_code)] mod machine; #[allow(dead_code)] mod sas; diff --git a/matrix_sdk_test/Cargo.toml b/matrix_sdk_test/Cargo.toml index 17ca6f84..4c58f638 100644 --- a/matrix_sdk_test/Cargo.toml +++ b/matrix_sdk_test/Cargo.toml @@ -11,9 +11,9 @@ repository = "https://github.com/matrix-org/matrix-rust-sdk" version = "0.1.0" [dependencies] -serde_json = "1.0.56" +serde_json = "1.0.57" http = "0.2.1" matrix-sdk-common = { version = "0.1.0", path = "../matrix_sdk_common" } matrix-sdk-test-macros = { version = "0.1.0", path = "../matrix_sdk_test_macros" } lazy_static = "1.4.0" -serde = "1.0.114" +serde = "1.0.115"