From dd0c53c5e99f9d3bcbb8c53356048cda6c339a96 Mon Sep 17 00:00:00 2001 From: silverpill Date: Wed, 22 Feb 2023 22:14:42 +0000 Subject: [PATCH] Add federation.fetcher_timeout and federation.deliverer_timeout configuration parameters --- CHANGELOG.md | 1 + mitra-config/src/config.rs | 10 ++++++++++ mitra-config/src/federation.rs | 9 +++++++++ src/activitypub/deliverer.rs | 4 +--- src/activitypub/fetcher/fetchers.rs | 4 +--- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d362236..d6b589e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added `prune-remote-emojis` command. - Prune remote emojis in background. - Added `limits.media.emoji_size_limit` configuration parameter. +- Added `federation.fetcher_timeout` and `federation.deliverer_timeout` configuration parameters. ### Changed diff --git a/mitra-config/src/config.rs b/mitra-config/src/config.rs index 77b660a..aa05269 100644 --- a/mitra-config/src/config.rs +++ b/mitra-config/src/config.rs @@ -104,6 +104,8 @@ impl Config { is_private: !self.federation.enabled || matches!(self.environment, Environment::Development), + fetcher_timeout: self.federation.fetcher_timeout, + deliverer_timeout: self.federation.deliverer_timeout, } } @@ -138,6 +140,8 @@ pub struct Instance { pub onion_proxy_url: Option, // Private instance won't send signed HTTP requests pub is_private: bool, + pub fetcher_timeout: u64, + pub deliverer_timeout: u64, } impl Instance { @@ -168,6 +172,8 @@ impl Instance { proxy_url: None, onion_proxy_url: None, is_private: true, + fetcher_timeout: 0, + deliverer_timeout: 0, } } } @@ -187,6 +193,8 @@ mod tests { proxy_url: None, onion_proxy_url: None, is_private: true, + fetcher_timeout: 0, + deliverer_timeout: 0, }; assert_eq!(instance.url(), "https://example.com"); @@ -207,6 +215,8 @@ mod tests { proxy_url: None, onion_proxy_url: None, is_private: true, + fetcher_timeout: 0, + deliverer_timeout: 0, }; assert_eq!(instance.url(), "http://1.2.3.4:3777"); diff --git a/mitra-config/src/federation.rs b/mitra-config/src/federation.rs index dbc47c5..1bfe423 100644 --- a/mitra-config/src/federation.rs +++ b/mitra-config/src/federation.rs @@ -2,10 +2,17 @@ use serde::Deserialize; fn default_federation_enabled() -> bool { true } +const fn default_fetcher_timeout() -> u64 { 300 } +const fn default_deliverer_timeout() -> u64 { 30 } + #[derive(Clone, Deserialize)] pub struct FederationConfig { #[serde(default = "default_federation_enabled")] pub enabled: bool, + #[serde(default = "default_fetcher_timeout")] + pub(super) fetcher_timeout: u64, + #[serde(default = "default_deliverer_timeout")] + pub(super) deliverer_timeout: u64, pub(super) proxy_url: Option, pub(super) onion_proxy_url: Option, } @@ -14,6 +21,8 @@ impl Default for FederationConfig { fn default() -> Self { Self { enabled: default_federation_enabled(), + fetcher_timeout: default_fetcher_timeout(), + deliverer_timeout: default_deliverer_timeout(), proxy_url: None, onion_proxy_url: None, } diff --git a/src/activitypub/deliverer.rs b/src/activitypub/deliverer.rs index 3517ccc..60647d7 100644 --- a/src/activitypub/deliverer.rs +++ b/src/activitypub/deliverer.rs @@ -36,8 +36,6 @@ use super::{ queues::OutgoingActivityJobData, }; -const DELIVERER_TIMEOUT: u64 = 30; - #[derive(thiserror::Error, Debug)] pub enum DelivererError { #[error("key error")] @@ -71,7 +69,7 @@ fn build_client( let client = build_federation_client( instance, is_onion, - DELIVERER_TIMEOUT, + instance.deliverer_timeout, )?; Ok(client) } diff --git a/src/activitypub/fetcher/fetchers.rs b/src/activitypub/fetcher/fetchers.rs index 437c3ab..61445d2 100644 --- a/src/activitypub/fetcher/fetchers.rs +++ b/src/activitypub/fetcher/fetchers.rs @@ -24,8 +24,6 @@ use crate::http_signatures::create::{ use crate::media::{save_file, SUPPORTED_MEDIA_TYPES}; use crate::webfinger::types::{ActorAddress, JsonResourceDescriptor}; -const FETCHER_TIMEOUT: u64 = 180; - #[derive(thiserror::Error, Debug)] pub enum FetchError { #[error(transparent)] @@ -62,7 +60,7 @@ fn build_client( let client = build_federation_client( instance, is_onion, - FETCHER_TIMEOUT, + instance.fetcher_timeout, )?; Ok(client) }