aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2019-01-25 15:10:21 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2019-01-25 15:10:21 +0300
commit656ed7c84a5d8e423999457f66d8259ec8aa9a44 (patch)
tree829ab8dde1446f76b32852d3020475135497b159
parent3e9399ec0b498c0c9783ccb0fea9f682c8b9d0ca (diff)
downloadpleroma-656ed7c84a5d8e423999457f66d8259ec8aa9a44.tar.gz
[#534] Configurable outgoing federation reachability timeout.
-rw-r--r--config/config.exs1
-rw-r--r--docs/config.md1
-rw-r--r--lib/pleroma/instances.ex16
-rw-r--r--lib/pleroma/instances/instance.ex6
4 files changed, 20 insertions, 4 deletions
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
)
)