diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 025c3f7ce..fe8a9f553 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -489,7 +489,7 @@ pub unsafe extern "C" fn dc_start_io(context: *mut dc_context_t) { if context.is_null() { return; } - let ctx = &*context; + let ctx = &mut *context; block_on(ctx.start_io()) } @@ -4946,8 +4946,8 @@ pub unsafe extern "C" fn dc_accounts_start_io(accounts: *mut dc_accounts_t) { return; } - let accounts = &*accounts; - block_on(async move { accounts.read().await.start_io().await }); + let accounts = &mut *accounts; + block_on(async move { accounts.write().await.start_io().await }); } #[no_mangle] diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index d91ed8f68..9745c42d0 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -221,13 +221,13 @@ impl CommandApi { /// Starts background tasks for all accounts. async fn start_io_for_all_accounts(&self) -> Result<()> { - self.accounts.read().await.start_io().await; + self.accounts.write().await.start_io().await; Ok(()) } /// Stops background tasks for all accounts. async fn stop_io_for_all_accounts(&self) -> Result<()> { - self.accounts.read().await.stop_io().await; + self.accounts.write().await.stop_io().await; Ok(()) } @@ -237,7 +237,7 @@ impl CommandApi { /// Starts background tasks for a single account. async fn start_io(&self, account_id: u32) -> Result<()> { - let ctx = self.get_context(account_id).await?; + let mut ctx = self.get_context(account_id).await?; ctx.start_io().await; Ok(()) } @@ -383,7 +383,7 @@ impl CommandApi { /// Configures this account with the currently set parameters. /// Setup the credential config before calling this. async fn configure(&self, account_id: u32) -> Result<()> { - let ctx = self.get_context(account_id).await?; + let mut ctx = self.get_context(account_id).await?; ctx.stop_io().await; let result = ctx.configure().await; if result.is_err() { diff --git a/deltachat-jsonrpc/src/webserver.rs b/deltachat-jsonrpc/src/webserver.rs index f4b6f38af..c180b829a 100644 --- a/deltachat-jsonrpc/src/webserver.rs +++ b/deltachat-jsonrpc/src/webserver.rs @@ -28,7 +28,7 @@ async fn main() -> Result<(), std::io::Error> { .layer(Extension(state.clone())); tokio::spawn(async move { - state.accounts.read().await.start_io().await; + state.accounts.write().await.start_io().await; }); let addr = SocketAddr::from(([127, 0, 0, 1], port)); diff --git a/deltachat-repl/src/main.rs b/deltachat-repl/src/main.rs index 2670b311f..7617c5783 100644 --- a/deltachat-repl/src/main.rs +++ b/deltachat-repl/src/main.rs @@ -401,7 +401,7 @@ enum ExitResult { async fn handle_cmd( line: &str, - ctx: Context, + mut ctx: Context, selected_chat: &mut ChatId, ) -> Result { let mut args = line.splitn(2, ' '); diff --git a/src/accounts.rs b/src/accounts.rs index 82c748955..9f533b8ce 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -258,8 +258,8 @@ impl Accounts { } /// Starts background tasks such as IMAP and SMTP loops for all accounts. - pub async fn start_io(&self) { - for account in self.accounts.values() { + pub async fn start_io(&mut self) { + for account in self.accounts.values_mut() { account.start_io().await; } } diff --git a/src/context.rs b/src/context.rs index a0f78f267..58d43b374 100644 --- a/src/context.rs +++ b/src/context.rs @@ -398,11 +398,24 @@ impl Context { } /// Starts the IO scheduler. - pub async fn start_io(&self) { - if let Ok(false) = self.is_configured().await { + pub async fn start_io(&mut self) { + if !self.is_configured().await.unwrap_or_default() { warn!(self, "can not start io on a context that is not configured"); return; } + + { + if self + .get_config(Config::ConfiguredAddr) + .await + .unwrap_or_default() + .filter(|s| s.ends_with(".testrun.org")) + .is_some() + { + let mut lock = self.ratelimit.write().await; + *lock = Ratelimit::new(Duration::new(40, 0), 6.0); + } + } self.scheduler.start(self.clone()).await; }