March Docs

PeerRegistry

PeerRegistry: the net-kernel's one-connection-per-peer table.

After a successful handshake, a peer is registered under its NodeId along with the socket fd of its connection. Re-registering the same NodeId replaces the prior entry (the newer connection wins) — so there is at most one live connection per peer, the invariant the L2 net-kernel maintains.

Types

typePeerPeer = { node_id : String, identity : NodeIdentity.Identity, fd : Int, data_fd : Int }#

fd is the CONTROL connection; data_fd the data one, -1 until it is up (a pre-split peer never opens one). See the control/data split in specs/progress/2026-09-14-distributed-plane-flow-control-and-control-channel.md.

typeRegistryRegistry = Registry(Map(String, Peer))#

Functions

fnaddadd(reg : Registry, peer : Peer) : Registry#

Register [peer] under its node_id, replacing any existing entry for that node (the newer connection wins).

fnadd_dataadd_data(reg : Registry, node_id : String, data_fd : Int) : Result(Registry, String)#

Attach the data connection [data_fd] to the already-registered peer [node_id], replacing any previous data fd. Returns Err if [node_id] is not registered.

fncontainscontains(reg : Registry, node_id : String) : Bool#

Whether a peer is registered under [node_id].

fnemptyempty() : Registry do Registry(Map.empty()) end#

An empty peer table.

fnhas_datahas_data(p : Peer) : Bool do p.data_fd != no_fd() end#

Whether [p] has a data connection (its data_fd is not no_fd()).

fnlookuplookup(reg : Registry, node_id : String) : Option(Peer)#

The peer registered under [node_id], or None.

fnno_fdno_fd() : Int do -1 end#

The sentinel fd (-1) meaning "no connection", used for data_fd until a peer's data connection is up.

fnpeerspeers(reg : Registry) : List(Peer)#

Every registered peer, in unspecified order.

fnremoveremove(reg : Registry, node_id : String) : Registry#

Drop the entry for [node_id]; the table is unchanged if it has none. The connections are not closed.

fnsizesize(reg : Registry) : Int#

The number of registered peers.