X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Finstances.ex;h=80addcc52d99d2b89388ca4966009284e060b476;hb=ca1eac01ddea8cb13059592630ac5399aeac9b65;hp=25b739520ae5d6d5a2c782409cb62e56a7028049;hpb=f161a92cb1abd981e37367fcd5d315ac14510d12;p=akkoma diff --git a/lib/pleroma/instances.ex b/lib/pleroma/instances.ex index 25b739520..80addcc52 100644 --- a/lib/pleroma/instances.ex +++ b/lib/pleroma/instances.ex @@ -1,12 +1,41 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2021 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Instances do @moduledoc "Instances context." @adapter Pleroma.Instances.Instance - defdelegate reachable?(url), to: @adapter - defdelegate set_reachable(url), to: @adapter - defdelegate set_unreachable(url, unreachable_since \\ nil), to: @adapter + defdelegate filter_reachable(urls_or_hosts), to: @adapter + defdelegate reachable?(url_or_host), to: @adapter + defdelegate set_reachable(url_or_host), to: @adapter + defdelegate set_unreachable(url_or_host, unreachable_since \\ nil), to: @adapter + defdelegate get_consistently_unreachable(), to: @adapter + + def set_consistently_unreachable(url_or_host), + do: set_unreachable(url_or_host, reachability_datetime_threshold()) + + def reachability_datetime_threshold do + federation_reachability_timeout_days = + Pleroma.Config.get([:instance, :federation_reachability_timeout_days], 0) + + 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 reachability_time_threshold, - do: NaiveDateTime.add(NaiveDateTime.utc_now(), -30 * 24 * 3600, :second) + 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 end