chore: run mix format

This commit is contained in:
Alain Zscheile 2022-11-26 16:04:37 +01:00
parent 35a393c7fa
commit fab022df18
4 changed files with 51 additions and 29 deletions

View file

@ -141,6 +141,7 @@ defmodule Floof.Distributor do
defp check_filters(fconf, {:XferBlob, _, _, markers, _, xfinner}) do
try do
{:ok, {:XferInner, _, attrs, _, _}} = :FloofProtocol.decode(:XferInner, xfinner)
cond do
not check_filters_markers2(fconfig(fconf, :markers), markers) -> false
not check_filters_markers2(fconfig(fconf, :attrs), attrs) -> false

View file

@ -48,6 +48,7 @@ defmodule Floof.PacketSpool do
@impl true
def handle_call({:store, hash, packet, overwrite}, _, state) do
path = hash_to_path(hash, state)
echain(
state,
fn ->
@ -76,6 +77,7 @@ defmodule Floof.PacketSpool do
:ok -> nil
{:error, e} -> Logger.error("spool: unable to remove #{inspect(hash)}: #{inspect(e)}")
end
{:noreply, state}
end
@ -83,19 +85,28 @@ defmodule Floof.PacketSpool do
def handle_cast({:keep_only, hashes}, state) do
case File.ls(state) do
{:error, e} ->
Logger.error("spool: unable to browse spool directory for garbage collection: #{inspect(e)}")
Logger.error(
"spool: unable to browse spool directory for garbage collection: #{inspect(e)}"
)
{:ok, items} ->
present = MapSet.new(Enum.flat_map(items, fn x ->
case Base.url_decode64(x) do
{:ok, y} -> [y]
{:error, e} ->
Logger.warn("spool: unable to decode entry name #{x}: #{inspect(e)}")
[]
end
end))
present =
MapSet.new(
Enum.flat_map(items, fn x ->
case Base.url_decode64(x) do
{:ok, y} ->
[y]
{:error, e} ->
Logger.warn("spool: unable to decode entry name #{x}: #{inspect(e)}")
[]
end
end)
)
hashes = MapSet.new(hashes)
Logger.debug("spool: present #{inspect(present)} vs. to_keep #{inspect(hashes)}")
for hash <- MapSet.difference(present, hashes) do
case File.rm(hash_to_path(hash, state)) do
:ok -> nil
@ -103,6 +114,7 @@ defmodule Floof.PacketSpool do
end
end
end
{:noreply, state}
end
@ -113,14 +125,16 @@ defmodule Floof.PacketSpool do
end
defp echain(state, handler1, handler2) do
retval = try do
case handler1.() do
{:ok, encd} -> handler2.(encd)
x -> x
retval =
try do
case handler1.() do
{:ok, encd} -> handler2.(encd)
x -> x
end
catch
y, z -> {:error, y, z}
end
catch
y, z -> {:error, y, z}
end
{:reply, retval, state}
end
end

View file

@ -9,10 +9,13 @@ defmodule Floof.SessionManager do
defstruct dets_file: :sessions, subs: %{}
def start_link({file, opts}) do
Agent.start_link(fn ->
{:ok, file} = :dets.open_file(file, opts ++ [type: :bag])
%Floof.SessionManager{dets_file: file}
end, name: __MODULE__)
Agent.start_link(
fn ->
{:ok, file} = :dets.open_file(file, opts ++ [type: :bag])
%Floof.SessionManager{dets_file: file}
end,
name: __MODULE__
)
end
def attach(key, pid) do
@ -60,16 +63,20 @@ defmodule Floof.SessionManager do
def set_for_all(subkey, value, origin) do
Agent.cast(__MODULE__, fn state ->
filter_keys = MapSet.new(for {key, sub} <- state.subs do
if origin != sub and sub != nil do
send(sub, {:SessionPushed, key, subkey})
key
else
nil
end
end)
filter_keys =
MapSet.new(
for {key, sub} <- state.subs do
if origin != sub and sub != nil do
send(sub, {:SessionPushed, key, subkey})
key
else
nil
end
end
)
{:ok, all_keys} = all_session_keys(state)
if not Enum.empty?(all_keys) do
# only store packets when we have any sessions
:ok = Floof.PacketSpool.store(subkey, value)

View file

@ -41,7 +41,7 @@ defmodule Floof.MixProject do
# the spool dir saves messages in-transit, and is used to prevent RAM OOM
spool_dir: "mock_spool",
# the sessions file is used for persistence of session data across restarts
sessions_file: "mock_sessions.dets",
sessions_file: "mock_sessions.dets"
]
]
end