Rename Peer to 'Backing Agent'

This commit is contained in:
bluepython508
2024-09-26 13:06:58 +01:00
parent 85bf788307
commit bdacd9905e
6 changed files with 39 additions and 39 deletions

View File

@@ -1,4 +1,4 @@
defmodule Frajtano.Peer do
defmodule Frajtano.BackingAgent do
alias Frajtano.Proto
require Logger
use GenServer, restart: :temporary
@@ -17,7 +17,7 @@ defmodule Frajtano.Peer do
children = [
Supervisor.child_spec({MuonTrap.Daemon, [executable, args ++ [path]]}, restart: :temporary, significant: true),
Supervisor.child_spec({Frajtano.Peer, {path, :spawned, {executable, args}}}, restart: :permanent)
Supervisor.child_spec({Frajtano.BackingAgent, {path, :spawned, {executable, args}}}, restart: :permanent)
]
Supervisor.init(children, strategy: :one_for_all, auto_shutdown: :any_significant)
@@ -25,19 +25,19 @@ defmodule Frajtano.Peer do
end
def start({:socket, path}) do
DynamicSupervisor.start_child(Frajtano.PeerSupervisor, {__MODULE__, {path}})
DynamicSupervisor.start_child(Frajtano.BackingAgentSupervisor, {__MODULE__, {path}})
end
def start({:spawn, spec}) do
Logger.info("Spawning #{inspect spec}")
DynamicSupervisor.start_child(Frajtano.PeerSupervisor, {Spawner, spec})
DynamicSupervisor.start_child(Frajtano.BackingAgentSupervisor, {Spawner, spec})
end
def start_link({path}) do
GenServer.start_link(__MODULE__, {path}, name: {:via, Registry, {Frajtano.Peers, path}})
GenServer.start_link(__MODULE__, {path}, name: {:via, Registry, {Frajtano.BackingAgents, path}})
end
def start_link({_, _, _} = spec) do
GenServer.start_link(__MODULE__, spec, name: {:via, Registry, {Frajtano.Peers, spec}})
GenServer.start_link(__MODULE__, spec, name: {:via, Registry, {Frajtano.BackingAgents, spec}})
end
@impl true
@@ -112,12 +112,12 @@ defmodule Frajtano.Peer do
{:stop, {:error, e}, %{}}
end
def identities(peer) do
def identities(backing_agent) do
ref = make_ref()
send(peer, {:send, {:agentc_request_identities, nil}, {self(), ref}})
send(backing_agent, {:send, {:agentc_request_identities, nil}, {self(), ref}})
# Needs to be less than the timeout in Frajtano.Agent.identities on the Task.async_stream call
# That's 5000 by default
timer = Process.send_after(peer, :timeout, 4500)
timer = Process.send_after(backing_agent, :timeout, 4500)
receive do
{^ref, msg} ->
@@ -132,13 +132,13 @@ defmodule Frajtano.Peer do
end
end
def sign(peer, request) do
def sign(backing_agent, request) do
# Signing may take some time, as a password may need to be entered or similar
# There is therefore no timeout
# If something requests identities afterwards, it will timeout, which also kills this signature request
# The SSH agent protocol strict ordering leaves fun problems with timeouts, as it turns out
ref = make_ref()
send(peer, {:send, {:agentc_sign_request, request}, {self(), ref}})
send(backing_agent, {:send, {:agentc_sign_request, request}, {self(), ref}})
receive do
{^ref, msg} -> msg