[#534] Configurable outgoing federation reachability timeout.
This commit is contained in:
parent
3e9399ec0b
commit
656ed7c84a
4 changed files with 20 additions and 4 deletions
|
@ -125,6 +125,7 @@
|
|||
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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -39,7 +39,8 @@ def filter_reachable(urls) when is_list(urls) 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 @@ def reachable?(url) when is_binary(url) 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
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue