fix simple bugs in persistence

This commit is contained in:
Alain Zscheile 2022-11-26 15:42:15 +01:00
parent dc7db318e8
commit 1f056a298c
4 changed files with 4 additions and 43 deletions

View file

@ -34,7 +34,7 @@ defmodule Floof.Application do
pubkey_mgr: pubkey_mgr,
pubkey_config: pubkey_config
)},
{Floof.SessionManager, {sessions_file, []}}
{Floof.SessionManager, {:sessions, [file: to_charlist(sessions_file)]}}
] ++
if listen_port != nil do
[{Task, fn -> Floof.accept(listen_port, listen_opts) end}]

View file

@ -6,7 +6,7 @@ defmodule Floof.SessionManager do
# structure of data := %{dets file, subscription Map}
# dets data := {sesskey, hash} (via bag)
defstruct dets_file: "/var/spool/floof/sess.dets", subs: %{}
defstruct dets_file: :sessions, subs: %{}
def start_link({file, opts}) do
Agent.start_link(fn ->

View file

@ -40,8 +40,8 @@ defmodule Floof.MixProject do
pubkey_config: %{:keydb => "mock_keydb"},
# the spool dir saves messages in-transit, and is used to prevent RAM OOM
spool_dir: "mock_spool",
# the session file is used for persistence of session data across restarts
session_file: "mock_sessions.dets",
# the sessions file is used for persistence of session data across restarts
sessions_file: "mock_sessions.dets",
]
]
end

View file

@ -2,45 +2,6 @@ defmodule FloofTest do
use ExUnit.Case
doctest Floof
test "SessionManager basic" do
cur = self()
spawn_link(fn ->
Floof.SessionManager.set(:a, 0, 8)
Floof.SessionManager.set(:a, 2, 16)
Floof.SessionManager.set(:a, 3, 32)
assert Floof.SessionManager.peek(:a) == MapSet.new([0, 2, 3])
assert Floof.SessionManager.get(:a, 0) == 8
assert Floof.SessionManager.get(:a, 1) == nil
assert Floof.SessionManager.get(:a, 2) == 16
assert Floof.SessionManager.get(:a, 3) == 32
Floof.SessionManager.drop(:a, [0, 2, 3])
assert Floof.SessionManager.peek(:a) == MapSet.new()
send(cur, :done)
end)
spawn_link(fn ->
Floof.SessionManager.set(:b, 50, 128)
Floof.SessionManager.set(:b, 12, 256)
Floof.SessionManager.set(:b, 1, 512)
assert Floof.SessionManager.peek(:b) == MapSet.new([1, 12, 50])
assert Floof.SessionManager.get(:b, 1) == 512
assert Floof.SessionManager.get(:b, 12) == 256
assert Floof.SessionManager.get(:b, 50) == 128
Floof.SessionManager.drop(:b, [1, 12, 50])
assert Floof.SessionManager.peek(:b) == MapSet.new()
send(cur, :done)
end)
for _ <- [1, 2] do
receive do
:done -> nil
end
end
end
test "Simple usage" do
# kp = :enacl.sign_keypair()
# :ok = File.write("mock_keydb/test01.secret", kp.secret)