The LAN transport

View Source

Services on one LAN cluster over distributed Erlang, and call and publish to each other with no station (docs/DESIGN.md §2).

DECIDED 2026-12-02 "trust on sight. mcl-martha services should auto-cluster over LAN, no mcl-station required. Distributed Erlang offers us all we need." (Raf) DECIDED 2026-12-02 "Shared cookie + secret (Recommended)" (Raf) DECIDED 2026-12-02 "Three for failover (Recommended)" (Raf)

Turning it on

The lan app env is off by default; a node with it off behaves as mcl_om 1.9.0 did. A release that clusters sets it in sys.config:

{mcl_core, [
    %% The node's own identity key: its node id is the `caller' it writes.
    %% Every node has its own; two nodes never share one.
    {identity_key_path, "/data/identity.key"},
    {lan, #{data_dir => "/data/lan",
            %% Only on the cluster's first node.
            first => true,
            %% Optional: macula_cluster_gossip's own options.
            gossip => #{port => 45892}}}
]}

mcl_core refuses to start, naming the reason, when the node is not distributed (not_distributed), has no identity key (no_identity_key), or lacks a secret ({secrets_missing, Dir}).

The two secrets

data_dir holds .erlang.cookie (mode 0400) and gossip.secret (0600).

  • The first node (first => true) generates both when neither exists: 32 random bytes each, written hex.
  • Every other node gets the same two files copied into its own data_dir at install. That copy is the factory's install step, not a person's.
  • Nothing overwrites a secret. A data_dir with one file and not the other is refused; so is a file shorter than 32 bytes or readable by group or others.

mcl_core sets the node's cookie from the file, so the VM's own cookie (from -setcookie or $HOME/.erlang.cookie) does not matter. data_dir should not be the node's $HOME: the VM makes a cookie file there at start when none exists, which would leave the first node a cookie and no secret.

The harm to name. A device holding both files owns the cluster: distributed Erlang runs any code on any node. The secrets are the guard, not the LAN.

The release

The node must be distributed and reachable on the LAN before mcl_core starts. In vm.args:

## A long name on the node's LAN address.
-name mcl@${LAN_ADDRESS}
## One fixed distribution port, so the firewall opens one port.
-kernel inet_dist_listen_min ${LAN_DIST_PORT} inet_dist_listen_max ${LAN_DIST_PORT}

Open on the LAN interface only: epmd (4369/tcp), the distribution port, and the gossip port (45892/udp by default, multicast group 230.1.1.251). A standalone single-service release keeps its loopback binding and leaves lan off (mcl-rag#32).

What runs on the LAN

on the LANmesh only
capabilitiesauth open, {callers, members}, {callers, {nodes, Ids}}{callers, role}, handler_authorizes, {ucan_required, _}, {realm_member_required, _, _}; streamers
subscriptionsevery declared oneone under a sealed group (group)
  • A call prefers a provider on this node, else a random one, and tries a second if the first is gone. With none on the LAN it goes to the mesh.
  • The caller. The handler reads the calling node's id under caller (the payload's own caller is overwritten) and from macula_response:caller/0. It is a cluster member's own claim: no weaker than distributed Erlang, where a member can already run code on the callee.
  • A publish goes to every LAN subscriber, at most once, when there is one; else to the mesh. A realm option always means the mesh.
  • The event meta is #{publisher, publisher_verified => true, published_at, delivered_via => lan}. {nodes, Ids} sources are checked against publisher.

The bridge

One node of a cluster is the mesh bridge (docs/DESIGN.md §3, macula-services/mcl-core#7). It is the node with {bridge, true} in its sys.config, beside its lan map and its station seeds:

{mcl_core, [
    {bridge, true},
    %% The station's own 32-byte node id goes in `expected_node_id'.
    {station_seeds, [#{host => <<"station.example">>, port => 4433,
                       expected_node_id => <<0:256>>}]}
    %% realm, realm_key, identity_key_path, lan: as on any node
]}
bridgeevery other node (member)
mesh poolyes, with seedsnone, whatever its seeds
D25 claimonce per org it exportsnone
advertisesthe cluster's export => mesh capabilitiesnothing
{mesh, required}asks for realm, realm key and seedsasks nothing
a call or publish nobody on the LAN takesgoes to the meshgoes to the bridge node, which sends it on the mesh
  • Exporting. A capability marked export => mesh is advertised on the mesh by the bridge, under <org>/<name> with its own auth, from whichever cluster node hosts it. Unmarked, it stays on the LAN.
  • A mesh call to an exported capability the LAN serves is forwarded into the LAN. The member that serves it finds the mesh caller's node id under caller and in macula_response:caller/0, decides {callers, {nodes, Ids}} against it, and runs the guard pipeline for it. The guard runs once, there. The bridge's own advertisement is unguarded.
  • Exported but not on the LAN. A realm-bound auth, a streamer or a record with no handler is advertised with its own handler, and only from a service the bridge node itself hosts.
  • Outbound. A member's mesh call or publish reaches the mesh under the bridge's identity. With no bridge in the cluster, it gets the answer a node with no pool gives.
  • Not carried: a mesh event reaches only the bridge's own subscribers. It is not republished onto the LAN.
  • The lan app env off: the node is its own bridge and advertises everything it hosts, as mcl_om 1.9.0 did. bridge and export change nothing there.

The entry point

Clients that are not BEAM nodes reach the cluster's capabilities and topics over HTTP, as a member named by its own key (docs/DESIGN.md §4.2). Every node can serve it; it is off unless the lan map names it:

{lan, #{data_dir => "/data/lan",
        entry => #{address => "192.168.1.20", port => 8471}}}

address is the LAN address distribution uses. It must be private (10/8, 172.16/12, 192.168/16, 169.254/16, fc00::/7, fe80::/10) or loopback. Any other address, 0.0.0.0 and :: included, starts no listener, and /health is {degraded, {lan_entry, {not_private, Address}}}.

The member list. data_dir/lan_members names the keys that may take a token, one per line: the node id as 64 hex characters, a space, then owner or member. The install step that copies the two secrets writes it on every node; taking a line out removes that member at its next request, whatever token it holds. A list that group or others may write names nobody.

A token. The member asks for a challenge, signs it, and redeems it once:

  1. POST /lan/v1/challenge {"node_id": "<hex>"} answers {"challenge": "<base64url>", "expires_in_ms": 60000}. An id not on the list gets 403 not_a_member.
  2. POST /lan/v1/token {"node_id", "public_key", "profile", "challenge", "signature"}. profile is pq_pure or pq_hybrid, the key and the signature are base64url, and the signature is over "mcl-lan token request v1", a zero byte, the 32-byte node id and the challenge (mcl_core_lan_entry:signed_message/2). The key must be the node id's (macula_node_keys:node_id/2). The answer is {"token", "expires_at"}, valid 15 minutes on every node of the cluster.

Bytes travel as base64url without padding.

A call. POST /lan/v1/call with Authorization: Bearer <token> and {"org", "procedure", "args", "timeout_ms"}; args defaults to {} and timeout_ms to 5000 (at most 60000). The call is made on the LAN as the member, so the handler finds its node id under caller and the capability's auth is decided against it. The answer is {"ok": Reply}, where a binary that is not UTF-8 is {"$bytes": "<base64url>"}. A refusal is {"error": Reason}: 401 for a missing, forged or expired token, 403 not_a_member or caller_refused, 404 no_lan_provider, 504 timeout. A call needs a token whatever the capability's auth, open included.

Events. GET /lan/v1/events?topic=T with the bearer token streams the topic's LAN events as server-sent events, one data: {"topic", "payload", "meta"} each, the publisher as a hex node id. The stream ends when the token expires or the member leaves the list.

What the entry point does not guard. There is no TLS under trust on sight: a device that sniffs the LAN can replay a member's token until it expires or the member is removed. It cannot reuse a signed challenge. Whoever holds the gossip secret can mint tokens, but that device already owns the cluster through the cookie.

Failover

Two nodes give copies of the data and no failover: once the stores run clustered, losing either node blocks writes on both. Three nodes survive one going down.