]> Untitled Git - lemmy.git/commitdiff
Remove federation settings, rely on sensible defaults instead (#2574)
authorNutomic <me@nutomic.com>
Mon, 21 Nov 2022 16:44:34 +0000 (16:44 +0000)
committerGitHub <noreply@github.com>
Mon, 21 Nov 2022 16:44:34 +0000 (11:44 -0500)
This affects federation_strict_allowlist and federation_http_fetch_retry_limit

crates/api_common/src/site.rs
crates/api_crud/src/site/create.rs
crates/api_crud/src/site/update.rs
crates/apub/src/fetcher/webfinger.rs
crates/apub/src/lib.rs
crates/db_schema/src/schema.rs
crates/db_schema/src/source/local_site.rs
migrations/2022-11-21-143249_remove-federation-settings/down.sql [new file with mode: 0644]
migrations/2022-11-21-143249_remove-federation-settings/up.sql [new file with mode: 0644]

index c25d58e62ab1d420eaccbf409230f56920364ff5..94e0ce7e701fabdc7bf9cef337890e33fc7de3ae 100644 (file)
@@ -145,8 +145,6 @@ pub struct CreateSite {
   pub rate_limit_search_per_second: Option<i32>,
   pub federation_enabled: Option<bool>,
   pub federation_debug: Option<bool>,
-  pub federation_strict_allowlist: Option<bool>,
-  pub federation_http_fetch_retry_limit: Option<i32>,
   pub federation_worker_count: Option<i32>,
   pub captcha_enabled: Option<bool>,
   pub captcha_difficulty: Option<String>,
@@ -192,8 +190,6 @@ pub struct EditSite {
   pub rate_limit_search_per_second: Option<i32>,
   pub federation_enabled: Option<bool>,
   pub federation_debug: Option<bool>,
-  pub federation_strict_allowlist: Option<bool>,
-  pub federation_http_fetch_retry_limit: Option<i32>,
   pub federation_worker_count: Option<i32>,
   pub captcha_enabled: Option<bool>,
   pub captcha_difficulty: Option<String>,
index bb1bca6e4bd4f0b0e9d66c412df5c3dee8651579..8b2b9c18bf7a0d2024faff469d2a11a039470d2b 100644 (file)
@@ -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())
index 632c55f3d27b029b5e3afcf1a2143a04a9de22d6..07e96582352085b16a2b534c301c829d86533b01 100644 (file)
@@ -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())
index 30ac0e0a01361a7d97ecd02855c4e17fd553984f..8e97d7d07f9d595d0ac9ee74eb694599657abef4 100644 (file)
@@ -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"));
   }
 
index da8c224485a6ac921ed7bc661d2000c45eb19960..f5d8d3565d84d74a8d1bd2dc005bebbb130467d7 100644 (file)
@@ -28,6 +28,8 @@ pub(crate) mod mentions;
 pub mod objects;
 pub mod protocol;
 
+const FEDERATION_HTTP_FETCH_LIMIT: i32 = 25;
+
 static CONTEXT: Lazy<Vec<serde_json::Value>> = 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();
index 850b784338b828e14becf75ff074950276e57078..c9bd7545923e300883b08a01ae6dcc400fa7622a 100644 (file)
@@ -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,
index 79cd3852f00f948b77382eb2a972d44113628255..4ae68ec1d39477597a78519715299253a24be9c1 100644 (file)
@@ -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<i32>,
   pub federation_enabled: Option<bool>,
   pub federation_debug: Option<bool>,
-  pub federation_strict_allowlist: Option<bool>,
-  pub federation_http_fetch_retry_limit: Option<i32>,
   pub federation_worker_count: Option<i32>,
   pub captcha_enabled: Option<bool>,
   pub captcha_difficulty: Option<String>,
@@ -93,8 +89,6 @@ pub struct LocalSiteUpdateForm {
   pub actor_name_max_length: Option<i32>,
   pub federation_enabled: Option<bool>,
   pub federation_debug: Option<bool>,
-  pub federation_strict_allowlist: Option<bool>,
-  pub federation_http_fetch_retry_limit: Option<i32>,
   pub federation_worker_count: Option<i32>,
   pub captcha_enabled: Option<bool>,
   pub captcha_difficulty: Option<String>,
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 (file)
index 0000000..51452e1
--- /dev/null
@@ -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 (file)
index 0000000..e175630
--- /dev/null
@@ -0,0 +1,2 @@
+alter table local_site drop column federation_strict_allowlist;
+alter table local_site drop column federation_http_fetch_retry_limit;