]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/lib.rs
Remove federation settings, rely on sensible defaults instead (#2574)
[lemmy.git] / crates / apub / src / lib.rs
index d8394a6e9e6fc0d9f4a101f868e9bc1395e5396e..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)
@@ -62,7 +60,7 @@ async fn local_instance(context: &LemmyContext) -> &'static LocalInstance {
         .build()
         .expect("configure federation");
       LocalInstance::new(
-        context.settings().hostname.to_owned(),
+        context.settings().hostname.clone(),
         context.client().clone(),
         settings,
       )
@@ -151,8 +149,8 @@ pub(crate) async fn fetch_local_site_data(
   let blocked = Instance::blocklist(pool).await?;
 
   // These can return empty vectors, so convert them to options
-  let allowed_instances = (!allowed.is_empty()).then(|| allowed);
-  let blocked_instances = (!blocked.is_empty()).then(|| blocked);
+  let allowed_instances = (!allowed.is_empty()).then_some(allowed);
+  let blocked_instances = (!blocked.is_empty()).then_some(blocked);
 
   Ok(LocalSiteData {
     local_site,
@@ -178,16 +176,11 @@ 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.to_owned();
+      let mut allowed_and_local = allowed.clone();
       allowed_and_local.push(local_instance);
 
       if !allowed_and_local.contains(&domain) {
@@ -248,7 +241,7 @@ pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, LemmyError>
     if let Some(port) = actor_id.port() {
       format!(":{}", port)
     } else {
-      "".to_string()
+      String::new()
     },
   );
   Ok(Url::parse(&url)?.into())
@@ -272,7 +265,7 @@ async fn insert_activity(
   sensitive: bool,
   pool: &DbPool,
 ) -> Result<bool, LemmyError> {
-  let ap_id = ap_id.to_owned().into();
+  let ap_id = ap_id.clone().into();
   Ok(Activity::insert(pool, ap_id, activity, local, Some(sensitive)).await?)
 }