Flake: HM module

This commit is contained in:
bluepython508
2024-09-20 15:08:27 +01:00
parent 6aaf8ff8e5
commit c3c80b716c
10 changed files with 138 additions and 38 deletions

View File

@@ -8,10 +8,19 @@ defmodule Frajtano.Agent do
@impl true
def init(_) do
{:ok,
%{
keys: %{}
}}
{
:ok,
%{
keys: %{}
},
{:continue, :init_peers}
}
end
@impl true
def handle_continue(:init_peers, state) do
for peer <- Application.fetch_env!(:frajtano, :initial_peers), do: {:ok, _} = Peer.start(peer)
{:noreply, state}
end
@impl true
@@ -26,10 +35,9 @@ defmodule Frajtano.Agent do
with {:ok, idents} <- Peer.identities(peer),
do: {:ok, {idents, peer}}
end)
# Double :ok-wrapping because of Task.async_stream
idents = (for {:ok, {:ok, {idents, peer}}} <- idents, do: {idents, peer})
idents = for {:ok, {:ok, {idents, peer}}} <- idents, do: {idents, peer}
{
:reply,
@@ -61,7 +69,8 @@ defmodule Frajtano.Agent do
end
def sign(agent \\ __MODULE__, request) do
GenServer.call(agent, {:sign, request})
# Signing can take some time, as a password may need to be entered or similar
GenServer.call(agent, {:sign, request}, :infinity)
end
def add_peer(agent \\ __MODULE__, path) do