[#534] Configurable outgoing federation reachability timeout.
authorIvan Tashkinov <ivantashkinov@gmail.com>
Fri, 25 Jan 2019 12:10:21 +0000 (15:10 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Fri, 25 Jan 2019 12:10:21 +0000 (15:10 +0300)
config/config.exs
docs/config.md
lib/pleroma/instances.ex
lib/pleroma/instances/instance.ex

index d30b0aad003232e021f67c513bf8fcb6ac45af19..7a1a875c981c46ec2754ac865721160eb68faa27 100644 (file)
@@ -125,6 +125,7 @@ config :pleroma, :instance,
   banner_upload_limit: 4_000_000,
   registrations_open: true,
   federating: true,
+  federation_reachability_timeout_days: 90,
   allow_relay: true,
   rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
   public: true,
index 6bf7b9ea7da76e9b568f84dd9bcf7a8e88c7a73d..3f458829962729d53be4bd4952daaca5b8e31623 100644 (file)
@@ -72,6 +72,7 @@ config :pleroma, Pleroma.Mailer,
 * `invites_enabled`: Enable user invitations for admins (depends on `registrations_open: false`).
 * `account_activation_required`: Require users to confirm their emails before signing in.
 * `federating`: Enable federation with other instances
+* `federation_reachability_timeout_days`: Timeout (in days) of each external federation target being unreachable prior to pausing federating to it.
 * `allow_relay`: Enable Pleroma’s Relay, which makes it possible to follow a whole instance
 * `rewrite_policy`: Message Rewrite Policy, either one or a list. Here are the ones available by default:
   * `Pleroma.Web.ActivityPub.MRF.NoOpPolicy`: Doesn’t modify activities (default)
index 6d445d6b3a075eb600d5a3f25ccba4fee184628a..0b08f0eb89c09fe279c75582fcbd61a6f09f5f6f 100644 (file)
@@ -8,8 +8,20 @@ defmodule Pleroma.Instances do
   defdelegate set_reachable(url), to: @adapter
   defdelegate set_unreachable(url, unreachable_since \\ nil), to: @adapter
 
-  def reachability_time_threshold,
-    do: NaiveDateTime.add(NaiveDateTime.utc_now(), -30 * 24 * 3600, :second)
+  def reachability_datetime_threshold do
+    federation_reachability_timeout_days =
+      Pleroma.Config.get(:instance)[:federation_reachability_timeout_days] || 90
+
+    if federation_reachability_timeout_days > 0 do
+      NaiveDateTime.add(
+        NaiveDateTime.utc_now(),
+        -federation_reachability_timeout_days * 24 * 3600,
+        :second
+      )
+    else
+      ~N[0000-01-01 00:00:00]
+    end
+  end
 
   def host(url_or_host) when is_binary(url_or_host) do
     if url_or_host =~ ~r/^http/i do
index a17c8dab10ffa139500bbcb36d75564b3ffcfb5d..60e8d0e21facc6bee96134f7b0a115d64c58dddf 100644 (file)
@@ -39,7 +39,8 @@ defmodule Pleroma.Instances.Instance do
       Repo.all(
         from(i in Instance,
           where:
-            i.host in ^hosts and i.unreachable_since <= ^Instances.reachability_time_threshold(),
+            i.host in ^hosts and
+              i.unreachable_since <= ^Instances.reachability_datetime_threshold(),
           select: i.host
         )
       )
@@ -51,7 +52,8 @@ defmodule Pleroma.Instances.Instance do
     !Repo.one(
       from(i in Instance,
         where:
-          i.host == ^host(url) and i.unreachable_since <= ^Instances.reachability_time_threshold(),
+          i.host == ^host(url) and
+            i.unreachable_since <= ^Instances.reachability_datetime_threshold(),
         select: true
       )
     )