From: Nutomic Date: Mon, 21 Nov 2022 16:44:34 +0000 (+0000) Subject: Remove federation settings, rely on sensible defaults instead (#2574) X-Git-Url: http://these/git/readmes/%24%7B%60data:application/%7BpictrsAvatarThumbnail%28this.props.site.site.icon%29%7D?a=commitdiff_plain;h=872c60a01358e1469926c1ffcb69f49f9666a392;p=lemmy.git Remove federation settings, rely on sensible defaults instead (#2574) This affects federation_strict_allowlist and federation_http_fetch_retry_limit --- diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index c25d58e6..94e0ce7e 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -145,8 +145,6 @@ pub struct CreateSite { pub rate_limit_search_per_second: Option, pub federation_enabled: Option, pub federation_debug: Option, - pub federation_strict_allowlist: Option, - pub federation_http_fetch_retry_limit: Option, pub federation_worker_count: Option, pub captcha_enabled: Option, pub captcha_difficulty: Option, @@ -192,8 +190,6 @@ pub struct EditSite { pub rate_limit_search_per_second: Option, pub federation_enabled: Option, pub federation_debug: Option, - pub federation_strict_allowlist: Option, - pub federation_http_fetch_retry_limit: Option, pub federation_worker_count: Option, pub captcha_enabled: Option, pub captcha_difficulty: Option, diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index bb1bca6e..8b2b9c18 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -112,8 +112,6 @@ impl PerformCrud for CreateSite { .actor_name_max_length(data.actor_name_max_length) .federation_enabled(data.federation_enabled) .federation_debug(data.federation_debug) - .federation_strict_allowlist(data.federation_strict_allowlist) - .federation_http_fetch_retry_limit(data.federation_http_fetch_retry_limit) .federation_worker_count(data.federation_worker_count) .captcha_enabled(data.captcha_enabled) .captcha_difficulty(data.captcha_difficulty.clone()) diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index 632c55f3..07e96582 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -115,8 +115,6 @@ impl PerformCrud for EditSite { .actor_name_max_length(data.actor_name_max_length) .federation_enabled(data.federation_enabled) .federation_debug(data.federation_debug) - .federation_strict_allowlist(data.federation_strict_allowlist) - .federation_http_fetch_retry_limit(data.federation_http_fetch_retry_limit) .federation_worker_count(data.federation_worker_count) .captcha_enabled(data.captcha_enabled) .captcha_difficulty(data.captcha_difficulty.clone()) diff --git a/crates/apub/src/fetcher/webfinger.rs b/crates/apub/src/fetcher/webfinger.rs index 30ac0e0a..8e97d7d0 100644 --- a/crates/apub/src/fetcher/webfinger.rs +++ b/crates/apub/src/fetcher/webfinger.rs @@ -1,8 +1,8 @@ -use crate::{local_instance, ActorType}; +use crate::{local_instance, ActorType, FEDERATION_HTTP_FETCH_LIMIT}; use activitypub_federation::{core::object_id::ObjectId, traits::ApubObject}; use anyhow::anyhow; use itertools::Itertools; -use lemmy_db_schema::{newtypes::DbUrl, source::local_site::LocalSite}; +use lemmy_db_schema::newtypes::DbUrl; use lemmy_utils::error::LemmyError; use lemmy_websocket::LemmyContext; use serde::{Deserialize, Serialize}; @@ -47,14 +47,8 @@ where ); debug!("Fetching webfinger url: {}", &fetch_url); - let local_site = LocalSite::read(context.pool()).await; - let http_fetch_retry_limit = local_site - .as_ref() - .map(|l| l.federation_http_fetch_retry_limit) - .unwrap_or(25); - *request_counter += 1; - if *request_counter > http_fetch_retry_limit { + if *request_counter > FEDERATION_HTTP_FETCH_LIMIT { return Err(LemmyError::from_message("Request retry limit reached")); } diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index da8c2244..f5d8d356 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -28,6 +28,8 @@ pub(crate) mod mentions; pub mod objects; pub mod protocol; +const FEDERATION_HTTP_FETCH_LIMIT: i32 = 25; + static CONTEXT: Lazy> = Lazy::new(|| { serde_json::from_str(include_str!("../assets/lemmy/context.json")).expect("parse context") }); @@ -44,17 +46,13 @@ async fn local_instance(context: &LemmyContext) -> &'static LocalInstance { .as_ref() .map(|l| l.federation_worker_count) .unwrap_or(64) as u64; - let http_fetch_retry_limit = local_site - .as_ref() - .map(|l| l.federation_http_fetch_retry_limit) - .unwrap_or(25); let federation_debug = local_site .as_ref() .map(|l| l.federation_debug) .unwrap_or(true); let settings = InstanceSettings::builder() - .http_fetch_retry_limit(http_fetch_retry_limit) + .http_fetch_retry_limit(FEDERATION_HTTP_FETCH_LIMIT) .worker_count(worker_count) .debug(federation_debug) .http_signature_compat(true) @@ -178,13 +176,8 @@ pub(crate) fn check_apub_id_valid_with_strictness( } if let Some(allowed) = local_site_data.allowed_instances.as_ref() { - // Only check allowlist if this is a community, or strict allowlist is enabled. - let strict_allowlist = local_site_data - .local_site - .as_ref() - .map(|l| l.federation_strict_allowlist) - .unwrap_or(true); - if is_strict || strict_allowlist { + // Only check allowlist if this is a community + if is_strict { // need to allow this explicitly because apub receive might contain objects from our local // instance. let mut allowed_and_local = allowed.clone(); diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 850b7843..c9bd7545 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -690,8 +690,6 @@ table! { actor_name_max_length -> Int4, federation_enabled -> Bool, federation_debug -> Bool, - federation_strict_allowlist -> Bool, - federation_http_fetch_retry_limit -> Int4, federation_worker_count -> Int4, captcha_enabled -> Bool, captcha_difficulty -> Text, diff --git a/crates/db_schema/src/source/local_site.rs b/crates/db_schema/src/source/local_site.rs index 79cd3852..4ae68ec1 100644 --- a/crates/db_schema/src/source/local_site.rs +++ b/crates/db_schema/src/source/local_site.rs @@ -29,8 +29,6 @@ pub struct LocalSite { pub actor_name_max_length: i32, pub federation_enabled: bool, pub federation_debug: bool, - pub federation_strict_allowlist: bool, - pub federation_http_fetch_retry_limit: i32, pub federation_worker_count: i32, pub captcha_enabled: bool, pub captcha_difficulty: String, @@ -63,8 +61,6 @@ pub struct LocalSiteInsertForm { pub actor_name_max_length: Option, pub federation_enabled: Option, pub federation_debug: Option, - pub federation_strict_allowlist: Option, - pub federation_http_fetch_retry_limit: Option, pub federation_worker_count: Option, pub captcha_enabled: Option, pub captcha_difficulty: Option, @@ -93,8 +89,6 @@ pub struct LocalSiteUpdateForm { pub actor_name_max_length: Option, pub federation_enabled: Option, pub federation_debug: Option, - pub federation_strict_allowlist: Option, - pub federation_http_fetch_retry_limit: Option, pub federation_worker_count: Option, pub captcha_enabled: Option, pub captcha_difficulty: Option, diff --git a/migrations/2022-11-21-143249_remove-federation-settings/down.sql b/migrations/2022-11-21-143249_remove-federation-settings/down.sql new file mode 100644 index 00000000..51452e19 --- /dev/null +++ b/migrations/2022-11-21-143249_remove-federation-settings/down.sql @@ -0,0 +1,2 @@ +alter table local_site add column federation_strict_allowlist bool default true not null; +alter table local_site add column federation_http_fetch_retry_limit int not null default 25; diff --git a/migrations/2022-11-21-143249_remove-federation-settings/up.sql b/migrations/2022-11-21-143249_remove-federation-settings/up.sql new file mode 100644 index 00000000..e1756304 --- /dev/null +++ b/migrations/2022-11-21-143249_remove-federation-settings/up.sql @@ -0,0 +1,2 @@ +alter table local_site drop column federation_strict_allowlist; +alter table local_site drop column federation_http_fetch_retry_limit;