Add support for spawning peers, and monitoring the processes

This commit is contained in:
bluepython508
2024-09-24 21:50:21 +01:00
parent 5e65fad33d
commit 23d3a97643
6 changed files with 94 additions and 17 deletions

View File

@@ -56,9 +56,8 @@ defmodule Frajtano.Agent do
end
@impl true
def handle_call({:add_peer, path}, _from, state) do
# TODO: deduplicate peers by socket path
case Peer.start(path) do
def handle_call({:add_peer, spec}, _from, state) do
case Peer.start(spec) do
{:ok, _} -> {:reply, :ok, state}
{:error, error} -> {:reply, {:error, error}, state}
end
@@ -73,7 +72,11 @@ defmodule Frajtano.Agent do
GenServer.call(__MODULE__, {:sign, request}, :infinity)
end
def add_peer(path) do
GenServer.call(__MODULE__, {:add_peer, path})
def assimilate(path) do
GenServer.call(__MODULE__, {:add_peer, {:socket, path}})
end
def spawn_peer(spec) do
GenServer.call(__MODULE__, {:add_peer, {:spawn, spec}})
end
end