From: Ivan Tashkinov Date: Fri, 25 Jan 2019 12:10:21 +0000 (+0300) Subject: [#534] Configurable outgoing federation reachability timeout. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=656ed7c84a5d8e423999457f66d8259ec8aa9a44;p=akkoma [#534] Configurable outgoing federation reachability timeout. --- diff --git a/config/config.exs b/config/config.exs index d30b0aad0..7a1a875c9 100644 --- a/config/config.exs +++ b/config/config.exs @@ -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, diff --git a/docs/config.md b/docs/config.md index 6bf7b9ea7..3f4588299 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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) diff --git a/lib/pleroma/instances.ex b/lib/pleroma/instances.ex index 6d445d6b3..0b08f0eb8 100644 --- a/lib/pleroma/instances.ex +++ b/lib/pleroma/instances.ex @@ -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 diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index a17c8dab1..60e8d0e21 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -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 ) )