2019-07-09 23:13:23 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-07-09 23:13:23 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-01-23 08:37:25 -07:00
|
|
|
defmodule Pleroma.Instances do
|
|
|
|
@moduledoc "Instances context."
|
|
|
|
|
2021-06-08 17:03:21 -06:00
|
|
|
alias Pleroma.Instances.Instance
|
2019-01-23 08:37:25 -07:00
|
|
|
|
2021-06-08 17:03:21 -06:00
|
|
|
def filter_reachable(urls_or_hosts), do: Instance.filter_reachable(urls_or_hosts)
|
|
|
|
|
|
|
|
def reachable?(url_or_host), do: Instance.reachable?(url_or_host)
|
|
|
|
|
|
|
|
def set_reachable(url_or_host), do: Instance.set_reachable(url_or_host)
|
|
|
|
|
|
|
|
def set_unreachable(url_or_host, unreachable_since \\ nil),
|
|
|
|
do: Instance.set_unreachable(url_or_host, unreachable_since)
|
|
|
|
|
|
|
|
def get_consistently_unreachable, do: Instance.get_consistently_unreachable()
|
2019-01-28 05:25:06 -07:00
|
|
|
|
|
|
|
def set_consistently_unreachable(url_or_host),
|
|
|
|
do: set_unreachable(url_or_host, reachability_datetime_threshold())
|
2019-01-23 08:37:25 -07:00
|
|
|
|
2019-01-25 05:10:21 -07:00
|
|
|
def reachability_datetime_threshold do
|
|
|
|
federation_reachability_timeout_days =
|
2019-06-14 09:45:05 -06:00
|
|
|
Pleroma.Config.get([:instance, :federation_reachability_timeout_days], 0)
|
2019-01-25 05:10:21 -07:00
|
|
|
|
|
|
|
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
|
2019-01-24 09:15:23 -07:00
|
|
|
|
|
|
|
def host(url_or_host) when is_binary(url_or_host) do
|
|
|
|
if url_or_host =~ ~r/^http/i do
|
|
|
|
URI.parse(url_or_host).host
|
|
|
|
else
|
|
|
|
url_or_host
|
|
|
|
end
|
|
|
|
end
|
2019-01-23 08:37:25 -07:00
|
|
|
end
|