From 0f5f71f07a1eec78376e37956aa5030af52afec2 Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 24 May 2024 14:59:35 +0200 Subject: [PATCH 1/5] FFI Bindings: Expose CryptoStore clear caches --- bindings/matrix-sdk-crypto-ffi/src/machine.rs | 6 ++++++ crates/matrix-sdk-crypto/src/machine.rs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/bindings/matrix-sdk-crypto-ffi/src/machine.rs b/bindings/matrix-sdk-crypto-ffi/src/machine.rs index 1cdace317da..5b0b7a68c53 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/machine.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/machine.rs @@ -1534,6 +1534,12 @@ impl OlmMachine { } .into() } + + /// Clear any in-memory caches because they may be out of sync with the + /// underlying data store. + pub async fn clear_crypto_cache(&self) { + self.runtime.block_on(self.inner.clear_crypto_cache()) + } } impl OlmMachine { diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index 02180c307f7..9fecf91ca6a 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -2150,6 +2150,13 @@ impl OlmMachine { let account = cache.account().await?; Ok(account.uploaded_key_count()) } + + /// Clear any in-memory caches because they may be out of sync with the + /// underlying data store. + pub async fn clear_crypto_cache(&self) { + let crypto_store = self.store().crypto_store(); + crypto_store.as_ref().clear_caches().await; + } } /// A set of requests to be executed when bootstrapping cross-signing using From 1985eede8fdd2c011ea1b8ca829d8f96d566653f Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 24 May 2024 15:09:31 +0200 Subject: [PATCH 2/5] Changelog: Update crypto crate changelog --- crates/matrix-sdk-crypto/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/matrix-sdk-crypto/CHANGELOG.md b/crates/matrix-sdk-crypto/CHANGELOG.md index 4090d2c12a8..941e46f3fa8 100644 --- a/crates/matrix-sdk-crypto/CHANGELOG.md +++ b/crates/matrix-sdk-crypto/CHANGELOG.md @@ -54,6 +54,10 @@ Deprecations: Additions: + +- Expose new method `OlmMachine::clear_crypto_cache()`, with FFI bindings + ([#3462](https://github.com/matrix-org/matrix-rust-sdk/pull/3462)) + - Expose new method `OlmMachine::upload_device_keys()`. ([#3457](https://github.com/matrix-org/matrix-rust-sdk/pull/3457)) From 8cf52972bb59f38448015fcff2a952e00bf8904b Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 24 May 2024 16:13:31 +0200 Subject: [PATCH 3/5] ffi-crypto-bindings: Improve comments --- bindings/matrix-sdk-crypto-ffi/src/machine.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bindings/matrix-sdk-crypto-ffi/src/machine.rs b/bindings/matrix-sdk-crypto-ffi/src/machine.rs index 5b0b7a68c53..a0cfdd75781 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/machine.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/machine.rs @@ -1537,6 +1537,11 @@ impl OlmMachine { /// Clear any in-memory caches because they may be out of sync with the /// underlying data store. + /// + /// The crypto store layer is caching olm sessions for a given device. + /// When used in a multi-process context this cache will get outdated. + /// If the machine is used by another process, the cache must be invalidating when the + /// main process is resumed. pub async fn clear_crypto_cache(&self) { self.runtime.block_on(self.inner.clear_crypto_cache()) } From a042b3d409fe415f766bb071e22e9dc438c5d3d0 Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 27 May 2024 12:49:59 +0200 Subject: [PATCH 4/5] FFI Bindings: Review, remove runtime block_on, use await Co-authored-by: Ivan Enderlin Signed-off-by: Valere --- bindings/matrix-sdk-crypto-ffi/src/machine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-crypto-ffi/src/machine.rs b/bindings/matrix-sdk-crypto-ffi/src/machine.rs index a0cfdd75781..793ae5f9f70 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/machine.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/machine.rs @@ -1543,7 +1543,7 @@ impl OlmMachine { /// If the machine is used by another process, the cache must be invalidating when the /// main process is resumed. pub async fn clear_crypto_cache(&self) { - self.runtime.block_on(self.inner.clear_crypto_cache()) + self.inner.clear_crypto_cache().await } } From 0e456cded24ae040573e374f7adbe440a2e7911a Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 27 May 2024 16:14:49 +0200 Subject: [PATCH 5/5] review: cargo fmt --- bindings/matrix-sdk-crypto-ffi/src/machine.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/matrix-sdk-crypto-ffi/src/machine.rs b/bindings/matrix-sdk-crypto-ffi/src/machine.rs index 793ae5f9f70..c5daafd1a0b 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/machine.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/machine.rs @@ -1537,11 +1537,11 @@ impl OlmMachine { /// Clear any in-memory caches because they may be out of sync with the /// underlying data store. - /// + /// /// The crypto store layer is caching olm sessions for a given device. /// When used in a multi-process context this cache will get outdated. - /// If the machine is used by another process, the cache must be invalidating when the - /// main process is resumed. + /// If the machine is used by another process, the cache must be + /// invalidating when the main process is resumed. pub async fn clear_crypto_cache(&self) { self.inner.clear_crypto_cache().await }