aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-09-21 23:34:33 +0300
committerrinpatch <rinpatch@sdf.org>2020-09-21 23:34:33 +0300
commit66d8d670e0f52c684e68ab556059c0bf409e727e (patch)
treedac376b9affa9427b28e4d895fe802d40f2d2ada /lib
parentd2eb48d97e1a10603f1a1894a17098478b1ef0d1 (diff)
downloadpleroma-66d8d670e0f52c684e68ab556059c0bf409e727e.tar.gz
tmp
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/object/fetcher.ex19
-rw-r--r--lib/pleroma/web/fed_sockets/socket_info.ex52
2 files changed, 11 insertions, 60 deletions
diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex
index 9468087cb..e5e5f8db7 100644
--- a/lib/pleroma/object/fetcher.ex
+++ b/lib/pleroma/object/fetcher.ex
@@ -211,14 +211,17 @@ defmodule Pleroma.Object.Fetcher do
do: {:error, "id must be a string"}
defp get_object(id, opts) do
- with false <- Keyword.get(opts, :force_http, false) do
- Logger.debug("fetching via fedsocket - #{inspect(id)}")
- FedSockets.fetch(id)
- else
- _other ->
- Logger.debug("fetching via http - #{inspect(id)}")
- get_object_http(id)
- end
+ with false <- Keyword.get(opts, :force_http, false),
+ _ <- Logger.debug("fetching via fedsocket - #{inspect(id)}")
+
+ {:ok, data} <-
+ FedSockets.fetch id do
+ {:ok, data}
+ else
+ _other ->
+ Logger.debug("fetching via http - #{inspect(id)}")
+ get_object_http(id)
+ end
end
defp get_object_http(id) do
diff --git a/lib/pleroma/web/fed_sockets/socket_info.ex b/lib/pleroma/web/fed_sockets/socket_info.ex
deleted file mode 100644
index d6fdffe1a..000000000
--- a/lib/pleroma/web/fed_sockets/socket_info.ex
+++ /dev/null
@@ -1,52 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.FedSockets.SocketInfo do
- defstruct origin: nil,
- pid: nil,
- conn_pid: nil,
- state: :default,
- connected_until: nil
-
- alias Pleroma.Web.FedSockets.SocketInfo
- @default_connection_duration 15 * 60 * 1000
-
- def build(uri, conn_pid \\ nil) do
- uri
- |> build_origin()
- |> build_pids(conn_pid)
- |> touch()
- end
-
- def touch(%SocketInfo{} = socket_info),
- do: %{socket_info | connected_until: new_ttl()}
-
- def connect(%SocketInfo{} = socket_info),
- do: %{socket_info | state: :connected}
-
- def expired?(%{connected_until: connected_until}),
- do: connected_until < :erlang.monotonic_time(:millisecond)
-
- def origin(uri),
- do: build_origin(uri).origin
-
- defp build_pids(socket_info, conn_pid),
- do: struct(socket_info, pid: self(), conn_pid: conn_pid)
-
- defp build_origin(uri) when is_binary(uri),
- do: uri |> URI.parse() |> build_origin
-
- defp build_origin(%{host: host, port: nil, scheme: scheme}),
- do: build_origin(%{host: host, port: URI.default_port(scheme)})
-
- defp build_origin(%{host: host, port: port}),
- do: %SocketInfo{origin: "#{host}:#{port}"}
-
- defp new_ttl do
- connection_duration =
- Pleroma.Config.get([:fed_sockets, :connection_duration], @default_connection_duration)
-
- :erlang.monotonic_time(:millisecond) + connection_duration
- end
-end