Per-instance registry of peer state — pubkey → {connection, last-seen address, status} — plus the auto-connect dispatcher.
Sits between PeerNet.Discovery (which emits "this pubkey is at this
address") and PeerNet.Connection.Supervisor (which spins up sockets).
When a discovery event arrives for a pubkey in the trust list, the
Registry dials the address; the resulting Connection registers itself
back here once authenticated.
State per peer
%{
pubkey: <<...>>,
status: :unknown | :discovered | :connecting | :connected | :disconnected,
last_address: %{ip: ..., port: ...} | nil,
last_seen: DateTime.t() | nil,
conn_pid: pid() | nil
}Public API
lookup_connection/2— returns{:ok, pid}or:not_connected(drop-in replacement for the previousPeerIndexbehaviour the publicPeerNet.send/4andPeerNet.call/5functions use).register_connection/3— called by Connection when its handshake completes.list/1— returns all known peers' state for UI / diagnostics.connected?/2— convenience boolean.
Discovery integration
Receives {:peer_discovered, pubkey, address} and {:peer_lost, pubkey, _} messages from any PeerNet.Discovery implementation.
Trust-checks the pubkey before acting.
Summary
Functions
Returns a specification to start this module under a supervisor.
True iff there's a live connection for pubkey.
Return all known peer entries.
Look up the live connection for pubkey.
Register pid as the live connection for pubkey. Idempotent.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec connected?(GenServer.server(), binary()) :: boolean()
True iff there's a live connection for pubkey.
@spec list(GenServer.server()) :: [map()]
Return all known peer entries.
@spec lookup_connection(GenServer.server(), binary()) :: {:ok, pid()} | :not_connected
Look up the live connection for pubkey.
@spec register_connection(GenServer.server(), binary(), pid()) :: :ok
Register pid as the live connection for pubkey. Idempotent.