March Docs

NodeIdentity

NodeIdentity: a cluster node's identity, exchanged in the net-kernel handshake.

A node is named (e.g. "worker@host"), has a stable NodeId derived from its public key, and an incarnation counter that increments each time the node restarts (so peers can tell a fresh start from a stale one — SWIM-style). The identity is serialized with MessagePack and sent inside a NetFrame.

Types

typeIdentityIdentity = { name : String, node_id : String, incarnation : Int }#

Functions

fndecodedecode(bytes : List(Int)) : Result(Identity, String)#

Decode the bytes of encode. Err with Msgpack's message for bytes that are not MessagePack, or "NodeIdentity: malformed identity record" for any other value than a [Str, Str, Int] array.

fnderive_idderive_id(pubkey : String) : String#

The stable NodeId for a node: the hex SHA-256 of its public key [pubkey] (Crypto.sha256), 64 lowercase hex digits. The same key always gives the same id.

fnencodeencode(id : Identity) : List(Int)#

Serialize [id] to MessagePack bytes: the 3-element array [name, node_id, incarnation].

fnmakemake(name : String, pubkey : String, incarnation : Int) : Identity#

An identity for node [name] with public key [pubkey] at [incarnation]: its node_id is derive_id(pubkey).

NodeIdentity.make("worker@host", "pk-worker@host", 1).node_id == NodeIdentity.name_id("worker@host")
fnname_idname_id(name : String) : String do derive_id("pk-" ++ name) end#

The node id every stdlib caller gives a node named [name]: derive_id("pk-" ++ name). Real per-node keys are not what ids derive from yet; a certificate-mode handshake binds the id to the certificate through the name (Handshake.verify_peer_cert requires id == name_id(name), and the certificate to name that node).