forked from YokaiRick/akkoma
[#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,
|
banner_upload_limit: 4_000_000,
|
||||||
registrations_open: true,
|
registrations_open: true,
|
||||||
federating: true,
|
federating: true,
|
||||||
|
federation_reachability_timeout_days: 90,
|
||||||
allow_relay: true,
|
allow_relay: true,
|
||||||
rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
|
rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
|
||||||
public: true,
|
public: true,
|
||||||
|
|
|
@ -72,6 +72,7 @@ config :pleroma, Pleroma.Mailer,
|
||||||
* `invites_enabled`: Enable user invitations for admins (depends on `registrations_open: false`).
|
* `invites_enabled`: Enable user invitations for admins (depends on `registrations_open: false`).
|
||||||
* `account_activation_required`: Require users to confirm their emails before signing in.
|
* `account_activation_required`: Require users to confirm their emails before signing in.
|
||||||
* `federating`: Enable federation with other instances
|
* `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
|
* `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:
|
* `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)
|
* `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_reachable(url), to: @adapter
|
||||||
defdelegate set_unreachable(url, unreachable_since \\ nil), to: @adapter
|
defdelegate set_unreachable(url, unreachable_since \\ nil), to: @adapter
|
||||||
|
|
||||||
def reachability_time_threshold,
|
def reachability_datetime_threshold do
|
||||||
do: NaiveDateTime.add(NaiveDateTime.utc_now(), -30 * 24 * 3600, :second)
|
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
|
def host(url_or_host) when is_binary(url_or_host) do
|
||||||
if url_or_host =~ ~r/^http/i do
|
if url_or_host =~ ~r/^http/i do
|
||||||
|
|
|
@ -39,7 +39,8 @@ def filter_reachable(urls) when is_list(urls) do
|
||||||
Repo.all(
|
Repo.all(
|
||||||
from(i in Instance,
|
from(i in Instance,
|
||||||
where:
|
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
|
select: i.host
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -51,7 +52,8 @@ def reachable?(url) when is_binary(url) do
|
||||||
!Repo.one(
|
!Repo.one(
|
||||||
from(i in Instance,
|
from(i in Instance,
|
||||||
where:
|
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
|
select: true
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue