π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Sleep via the runtime timers, default the retry profile
Manav Rathi4851427188cc
diff --git a/rust/Cargo.lock b/rust/Cargo.lockindex 77621254de..0a843d0b5e 100644--- a/rust/Cargo.lock+++ b/rust/Cargo.lock@@ -175,7 +175,7 @@ version = "1.1.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"dependencies = [- "windows-sys 0.60.2",+ "windows-sys 0.61.2",][[package]]@@ -186,7 +186,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"dependencies = ["anstyle","once_cell_polyfill",- "windows-sys 0.60.2",+ "windows-sys 0.61.2",][[package]]@@ -1275,7 +1275,7 @@ version = "3.1.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34"dependencies = [- "windows-sys 0.48.0",+ "windows-sys 0.61.2",][[package]]@@ -2011,7 +2011,7 @@ dependencies = ["libc","option-ext","redox_users 0.5.2",- "windows-sys 0.59.0",+ "windows-sys 0.61.2",][[package]]@@ -2282,8 +2282,6 @@ version = "0.0.0"dependencies = ["base64 0.22.1","ente-core",- "futures-timer",- "log","mockito","serde","serde_json",@@ -2331,9 +2329,10 @@ dependencies = ["bytes","crypto_secretstream","futures-core",- "futures-timer","getrandom 0.2.17",+ "gloo-timers","hex",+ "log","md-5 0.11.0","mockito","rand_core 0.6.4",@@ -2673,7 +2672,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"dependencies = ["libc",- "windows-sys 0.52.0",+ "windows-sys 0.61.2",][[package]]@@ -3130,16 +3129,6 @@ version = "0.3.32"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"-[[package]]-name = "futures-timer"-version = "3.0.3"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24"-dependencies = [- "gloo-timers",- "send_wrapper",-]-[[package]]name = "futures-util"version = "0.3.32"@@ -3410,9 +3399,9 @@ checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"[[package]]name = "gloo-timers"-version = "0.2.6"+version = "0.3.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c"+checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994"dependencies = ["futures-channel","futures-core",@@ -4566,7 +4555,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"dependencies = ["hermit-abi","libc",- "windows-sys 0.52.0",+ "windows-sys 0.61.2",][[package]]@@ -5458,7 +5447,7 @@ dependencies = ["png 0.18.1","serde","thiserror 2.0.18",- "windows-sys 0.60.2",+ "windows-sys 0.61.2",][[package]]@@ -7396,7 +7385,7 @@ dependencies = ["errno","libc","linux-raw-sys",- "windows-sys 0.52.0",+ "windows-sys 0.61.2",][[package]]@@ -7454,7 +7443,7 @@ dependencies = ["security-framework 3.7.0","security-framework-sys","webpki-root-certs",- "windows-sys 0.52.0",+ "windows-sys 0.61.2",][[package]]@@ -7745,12 +7734,6 @@ dependencies = ["serde_core",]-[[package]]-name = "send_wrapper"-version = "0.4.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0"-[[package]]name = "serde"version = "1.0.228"@@ -8143,7 +8126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e"dependencies = ["libc",- "windows-sys 0.60.2",+ "windows-sys 0.61.2",][[package]]@@ -8959,7 +8942,7 @@ dependencies = ["getrandom 0.4.2","once_cell","rustix",- "windows-sys 0.52.0",+ "windows-sys 0.61.2",][[package]]@@ -9492,7 +9475,7 @@ dependencies = ["png 0.18.1","serde","thiserror 2.0.18",- "windows-sys 0.60.2",+ "windows-sys 0.61.2",][[package]]@@ -9527,7 +9510,7 @@ checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e"dependencies = ["memoffset","tempfile",- "windows-sys 0.60.2",+ "windows-sys 0.61.2",][[package]]@@ -10302,7 +10285,7 @@ version = "0.1.11"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"dependencies = [- "windows-sys 0.48.0",+ "windows-sys 0.61.2",][[package]]diff --git a/rust/crates/accounts/Cargo.toml b/rust/crates/accounts/Cargo.tomlindex 067ee3bcb4..ac682c5907 100644--- a/rust/crates/accounts/Cargo.toml+++ b/rust/crates/accounts/Cargo.toml@@ -8,10 +8,8 @@ serde.workspace = trueserde_json = "1"thiserror.workspace = truebase64 = "0.22"-futures-timer = "3"uuid = { version = "1.11", features = ["js", "serde", "v4"] }zeroize = { version = "1.8", features = ["derive"] }-log = "0.4"urlencoding = "2.1"[dev-dependencies]diff --git a/rust/crates/accounts/src/client.rs b/rust/crates/accounts/src/client.rsindex db514f7442..11a6c04e31 100644--- a/rust/crates/accounts/src/client.rs+++ b/rust/crates/accounts/src/client.rs@@ -4,9 +4,8 @@ use base64::{Engine, engine::general_purpose::STANDARD};use ente_core::{auth::{SrpAttributes as CoreSrpAttributes, SrpSession},crypto::SecretVec,- http::{self, Api, ApiConfig, Auth, Http, RetryProfile},+ http::{self, Api, ApiConfig, Auth, Http},};-use std::time::Duration;use crate::{error::{Error, Result},@@ -81,7 +80,7 @@ impl AccountsClient {/// Get SRP attributes for a user by email.pub async fn get_srp_attributes(&self, email: &str) -> Result<SrpAttributes> {let query = [("email", email.to_string())];- let response: GetSrpAttributesResponse = http::retry(RetryProfile::Interactive, || async {+ let response: GetSrpAttributesResponse = http::retry(|| async {self.api.get("/users/srp/attributes").query(&query)@@ -122,8 +121,6 @@ impl AccountsClient {.create_srp_session(&srp_attrs.srp_user_id, &a_pub).await?;- futures_timer::Delay::new(Duration::from_millis(100)).await;-let server_b = STANDARD.decode(&session.srp_b)?;let proof = srp_session.compute_m1(&server_b)?;let auth_response = self@@ -149,7 +146,7 @@ impl AccountsClient {srp_user_id: srp_user_id.to_string(),srp_a: STANDARD.encode(client_public),};- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.post("/users/srp/create-session").json(&request)@@ -193,7 +190,7 @@ impl AccountsClient {email: email.to_string(),purpose: purpose.to_string(),};- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.post("/users/ott").json(&request)@@ -233,7 +230,7 @@ impl AccountsClient {/// Upload user key attributes.pub async fn set_user_key_attributes(&self, key_attributes: KeyAttributes) -> Result<()> {let request = SetUserAttributesRequest { key_attributes };- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.put("/users/attributes").json(&request)@@ -248,7 +245,7 @@ impl AccountsClient {/// Upload recovery-key attributes.pub async fn set_recovery_key_attributes(&self, request: SetRecoveryKeyRequest) -> Result<()> {- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.put("/users/recovery-key").json(&request)@@ -263,7 +260,7 @@ impl AccountsClient {/// Start SRP setup for an authenticated user.pub async fn setup_srp(&self, request: &SetupSrpRequest) -> Result<SetupSrpResponse> {- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.post("/users/srp/setup").json(request)@@ -318,7 +315,7 @@ impl AccountsClient {/// Get session validity and optional remote key attributes.pub async fn get_session_validity(&self) -> Result<SessionValidityResponse> {- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.get("/users/session-validity/v2").send()@@ -347,7 +344,7 @@ impl AccountsClient {/// Logout the current authenticated session.pub async fn logout(&self) -> Result<()> {let body = serde_json::json!({});- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.post("/users/logout").json(&body)@@ -362,7 +359,7 @@ impl AccountsClient {/// Return whether two-factor is enabled.pub async fn get_two_factor_status(&self) -> Result<bool> {- let response: TwoFactorStatusResponse = http::retry(RetryProfile::Interactive, || async {+ let response: TwoFactorStatusResponse = http::retry(|| async {self.api.get("/users/two-factor/status").send()@@ -406,7 +403,7 @@ impl AccountsClient {/// Disable TOTP two-factor.pub async fn disable_two_factor(&self) -> Result<()> {let body = serde_json::json!({});- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.post("/users/two-factor/disable").json(&body)@@ -453,7 +450,7 @@ impl AccountsClient {},),];- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.get("/users/two-factor/recover").query(&query)@@ -486,7 +483,7 @@ impl AccountsClient {/// Get passkey recovery status.pub async fn get_two_factor_recovery_status(&self) -> Result<TwoFactorRecoveryStatusResponse> {- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.get("/users/two-factor/recovery-status").send()@@ -504,7 +501,7 @@ impl AccountsClient {&self,request: &ConfigurePasskeyRecoveryRequest,) -> Result<()> {- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.post("/users/two-factor/passkeys/configure-recovery").json(request)@@ -520,7 +517,7 @@ impl AccountsClient {/// Poll passkey verification completion.pub async fn check_passkey_status(&self, session_id: &str) -> Result<AuthResponse> {let query = [("sessionID", session_id.to_string())];- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.get("/users/two-factor/passkeys/get-token").query(&query)@@ -536,7 +533,7 @@ impl AccountsClient {/// Fetch accounts-app broker token and URL.pub async fn get_accounts_token(&self) -> Result<AccountsTokenResponse> {- Ok(http::retry(RetryProfile::Interactive, || async {+ Ok(http::retry(|| async {self.api.get("/users/accounts-token").send()diff --git a/rust/crates/core/Cargo.toml b/rust/crates/core/Cargo.tomlindex bf3affcbfc..dbe513e366 100644--- a/rust/crates/core/Cargo.toml+++ b/rust/crates/core/Cargo.toml@@ -35,18 +35,18 @@ getrandom = { version = "0.2", features = ["js"] }# Common dependenciesbase64 = "0.22"hex = "0.4"+log = "0.4"bip39 = { version = "2", default-features = false, features = ["std"] }zeroize = { version = "1.8.2", features = ["derive"] }-futures-timer = "3.0.3"[target.'cfg(not(target_arch = "wasm32"))'.dependencies]reqwest = { version = "0.12", default-features = false, features = ["stream"] }bytes = "1.11.1"futures-core = "0.3.32"+tokio = { version = "1", features = ["time"] }-# futures-timer's `Delay` needs the browser's setTimeout on wasm.[target.'cfg(target_arch = "wasm32")'.dependencies]-futures-timer = { version = "3.0.3", features = ["wasm-bindgen"] }+gloo-timers = { version = "0.3.0", features = ["futures"] }[dev-dependencies]tokio = { version = "1", features = ["rt-multi-thread", "macros"] }diff --git a/rust/crates/core/src/http.rs b/rust/crates/core/src/http.rsindex 525068fad8..5fa71ff662 100644--- a/rust/crates/core/src/http.rs+++ b/rust/crates/core/src/http.rs@@ -13,6 +13,11 @@ use std::future::Future;use std::sync::{PoisonError, RwLock};use std::time::Duration;+#[cfg(target_arch = "wasm32")]+use gloo_timers::future::sleep;+#[cfg(not(target_arch = "wasm32"))]+use tokio::time::sleep;+use reqwest::header::{HeaderName, HeaderValue};use reqwest::{Method, Url};use serde::de::DeserializeOwned;@@ -530,7 +535,7 @@ impl RetryProfile {}}-/// Run `operation`, retrying failures per `profile`.+/// Run `operation`, retrying failures per [`RetryProfile::Interactive`].////// A failure is retried when [`Error::is_retryable`] says so: the request/// failed in transit, or the server answered with a 429 or a 5xx status.@@ -538,7 +543,16 @@ impl RetryProfile {////// Each retry runs the whole closure again, so wrap only operations that/// are safe to repeat.-pub async fn retry<T, F, Fut>(profile: RetryProfile, operation: F) -> Result<T, Error>+pub async fn retry<T, F, Fut>(operation: F) -> Result<T, Error>+where+ F: FnMut() -> Fut,+ Fut: Future<Output = Result<T, Error>>,+{+ retry_with_profile(RetryProfile::Interactive, operation).await+}++/// Like [`retry`](retry()), but with an explicitly chosen profile.+pub async fn retry_with_profile<T, F, Fut>(profile: RetryProfile, operation: F) -> Result<T, Error>whereF: FnMut() -> Fut,Fut: Future<Output = Result<T, Error>>,@@ -556,7 +570,10 @@ wherematch operation().await {Ok(value) => return Ok(value),Err(error) if error.is_retryable() => match delays.next() {- Some(delay) => futures_timer::Delay::new(*delay).await,+ Some(delay) => {+ log::warn!("retrying in {delay:?}: {error}");+ sleep(*delay).await;+ }None => return Err(error),},Err(error) => return Err(error),