hack: decrease ratelimit for .testrun.org subdomains

This commit is contained in:
link2xt
2023-11-01 18:47:22 +00:00
parent 89c873acd0
commit 0431ae53ca
6 changed files with 26 additions and 13 deletions

View File

@@ -489,7 +489,7 @@ pub unsafe extern "C" fn dc_start_io(context: *mut dc_context_t) {
if context.is_null() { if context.is_null() {
return; return;
} }
let ctx = &*context; let ctx = &mut *context;
block_on(ctx.start_io()) block_on(ctx.start_io())
} }
@@ -4946,8 +4946,8 @@ pub unsafe extern "C" fn dc_accounts_start_io(accounts: *mut dc_accounts_t) {
return; return;
} }
let accounts = &*accounts; let accounts = &mut *accounts;
block_on(async move { accounts.read().await.start_io().await }); block_on(async move { accounts.write().await.start_io().await });
} }
#[no_mangle] #[no_mangle]

View File

@@ -221,13 +221,13 @@ impl CommandApi {
/// Starts background tasks for all accounts. /// Starts background tasks for all accounts.
async fn start_io_for_all_accounts(&self) -> Result<()> { async fn start_io_for_all_accounts(&self) -> Result<()> {
self.accounts.read().await.start_io().await; self.accounts.write().await.start_io().await;
Ok(()) Ok(())
} }
/// Stops background tasks for all accounts. /// Stops background tasks for all accounts.
async fn stop_io_for_all_accounts(&self) -> Result<()> { async fn stop_io_for_all_accounts(&self) -> Result<()> {
self.accounts.read().await.stop_io().await; self.accounts.write().await.stop_io().await;
Ok(()) Ok(())
} }
@@ -237,7 +237,7 @@ impl CommandApi {
/// Starts background tasks for a single account. /// Starts background tasks for a single account.
async fn start_io(&self, account_id: u32) -> Result<()> { 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; ctx.start_io().await;
Ok(()) Ok(())
} }
@@ -383,7 +383,7 @@ impl CommandApi {
/// Configures this account with the currently set parameters. /// Configures this account with the currently set parameters.
/// Setup the credential config before calling this. /// Setup the credential config before calling this.
async fn configure(&self, account_id: u32) -> Result<()> { 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; ctx.stop_io().await;
let result = ctx.configure().await; let result = ctx.configure().await;
if result.is_err() { if result.is_err() {

View File

@@ -28,7 +28,7 @@ async fn main() -> Result<(), std::io::Error> {
.layer(Extension(state.clone())); .layer(Extension(state.clone()));
tokio::spawn(async move { 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)); let addr = SocketAddr::from(([127, 0, 0, 1], port));

View File

@@ -401,7 +401,7 @@ enum ExitResult {
async fn handle_cmd( async fn handle_cmd(
line: &str, line: &str,
ctx: Context, mut ctx: Context,
selected_chat: &mut ChatId, selected_chat: &mut ChatId,
) -> Result<ExitResult, Error> { ) -> Result<ExitResult, Error> {
let mut args = line.splitn(2, ' '); let mut args = line.splitn(2, ' ');

View File

@@ -258,8 +258,8 @@ impl Accounts {
} }
/// Starts background tasks such as IMAP and SMTP loops for all accounts. /// Starts background tasks such as IMAP and SMTP loops for all accounts.
pub async fn start_io(&self) { pub async fn start_io(&mut self) {
for account in self.accounts.values() { for account in self.accounts.values_mut() {
account.start_io().await; account.start_io().await;
} }
} }

View File

@@ -398,11 +398,24 @@ impl Context {
} }
/// Starts the IO scheduler. /// Starts the IO scheduler.
pub async fn start_io(&self) { pub async fn start_io(&mut self) {
if let Ok(false) = self.is_configured().await { if !self.is_configured().await.unwrap_or_default() {
warn!(self, "can not start io on a context that is not configured"); warn!(self, "can not start io on a context that is not configured");
return; 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; self.scheduler.start(self.clone()).await;
} }