X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fgun%2Fgun.ex;h=4043e488047a0716db3fa6f1b2250e529fe30106;hb=7f692343c80ddf353712490edfbcdb14866f5685;hp=da82983b1eed79db5c31f163956b4365e9e4571a;hpb=509c81e4b10bd8ba6d3a93889cd6fbbbfbcbab21;p=akkoma diff --git a/lib/pleroma/gun/gun.ex b/lib/pleroma/gun/gun.ex index da82983b1..4043e4880 100644 --- a/lib/pleroma/gun/gun.ex +++ b/lib/pleroma/gun/gun.ex @@ -1,48 +1,31 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Gun do - @behaviour Pleroma.Gun.API + @callback open(charlist(), pos_integer(), map()) :: {:ok, pid()} + @callback info(pid()) :: map() + @callback close(pid()) :: :ok + @callback await_up(pid, pos_integer()) :: {:ok, atom()} | {:error, atom()} + @callback connect(pid(), map()) :: reference() + @callback await(pid(), reference()) :: {:response, :fin, 200, []} + @callback set_owner(pid(), pid()) :: :ok - alias Pleroma.Gun.API + @api Pleroma.Config.get([Pleroma.Gun], Pleroma.Gun.API) - @gun_keys [ - :connect_timeout, - :http_opts, - :http2_opts, - :protocols, - :retry, - :retry_timeout, - :trace, - :transport, - :tls_opts, - :tcp_opts, - :socks_opts, - :ws_opts - ] + defp api, do: @api - @impl API - def open(host, port, opts \\ %{}), do: :gun.open(host, port, Map.take(opts, @gun_keys)) + def open(host, port, opts), do: api().open(host, port, opts) - @impl API - defdelegate info(pid), to: :gun + def info(pid), do: api().info(pid) - @impl API - defdelegate close(pid), to: :gun + def close(pid), do: api().close(pid) - @impl API - defdelegate await_up(pid, timeout \\ 5_000), to: :gun + def await_up(pid, timeout \\ 5_000), do: api().await_up(pid, timeout) - @impl API - defdelegate connect(pid, opts), to: :gun + def connect(pid, opts), do: api().connect(pid, opts) - @impl API - defdelegate await(pid, ref), to: :gun + def await(pid, ref), do: api().await(pid, ref) - @spec flush(pid() | reference()) :: :ok - defdelegate flush(pid), to: :gun - - @impl API - defdelegate set_owner(pid, owner), to: :gun + def set_owner(pid, owner), do: api().set_owner(pid, owner) end