mcl_core_lan (mcl_core v1.0.0)

View Source

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

OFF UNLESS CONFIGURED. The lan app env is off by default, and then nothing of this transport runs: every call and publish goes to the mesh bridge exactly as in mcl_om 1.9.0. Configured, it is a map:

data_dir (required) -- where the cluster's two secrets live: the Erlang cookie (.erlang.cookie) and the gossip secret (gossip.secret). Both owner-only. first (default false) -- this node is the cluster's first: it generates both secrets when neither exists. Every other node gets them copied into its own data_dir at install, and refuses to start without them (mcl_core_lan_secrets). gossip (default #{}) -- options for macula's macula_cluster_gossip (multicast_addr, port, multicast_ttl, broadcast_interval); the secret is added here.

The node must already be distributed (-name in vm.args): this transport sets the cookie and starts the gossip that finds the other nodes, and gossip dials each one it hears with the right secret. Trust is on sight (DECIDED 2026-12-02): a node holding both secrets is a member.

CALLS. A capability served here is a process in the pg group {capability, Org, Name} (mcl_core_lan_capability). A call prefers a member on this node, else picks one at random, and tries the next member once if the first is gone. The callee writes the CALLER's node id under caller, over anything the payload carried, as macula does on the mesh. Served on the LAN: response capabilities whose auth is open, {callers, members} or {callers, {nodes, Ids}}. A realm role, a UCAN or a handler that checks its own token needs the realm, so such a capability is served only through the bridge.

PUBSUB. A subscription is a process in {topic, Topic} (mcl_core_lan_subscriber); a publish sends the event to each, at most once. The event's meta names the publisher's node id. A subscription under a sealed group (group) is the mesh's, and stays there.

Both answer {error, no_lan_provider} / {error, no_lan_subscriber} when the LAN has nobody to take them; mcl_core_transport then hands them to the bridge.

Summary

Functions

Whether a capability with Auth answers Caller (design §2.2). Every cluster node is a member (trust on sight).

As call_capability/5, made as Caller rather than as this node: the member writes Caller as the call's caller and decides its auth against it. For a caller from outside the cluster that this node has authenticated itself: the mesh caller at the bridge (mcl_core_bridge_inbound, mcl-core#7).

Call CapName in Org on the LAN. advertiser => NodeId in Opts calls only that node's member, as on the mesh.

The lan app env: off, or {ok, Config}. A value of any other shape raises, naming it, so a typo is not silently a node with no LAN.

Whether the LAN transport runs on this node.

The pg group a served capability joins beside its own when it is exported to the mesh (mcl_core_bridge:exported/1), or none. The group carries the capability without its handler, so the bridge can advertise it from the group alone (mcl-core#7).

Every exported capability served anywhere in the cluster, as {Org, Cap} without its handler; one per Org/Name (the lowest, so every node picks the same one), [] with the LAN off.

Serve on the LAN those of Caps it can serve (served/1), for the hosted service Key, replacing what Key served before. A no-op with the LAN off.

This node's own node id, the one it writes as caller and publisher (mcl_core_lan_node sets it at start).

Publish Payload on Topic to every LAN subscriber. A publish naming another realm is the mesh's.

The pg scope of every LAN group.

Whether the LAN serves Cap: a response handler whose auth a LAN can decide.

Whether a subscription with Sources takes an event from Publisher (design §2.3).

Subscribe on the LAN those of Subs it can carry (subscribed/1), for the hosted service Key, replacing its earlier ones.

Whether the LAN carries Sub: anything but a sealed group's.

Types

config/0

-type config() :: #{data_dir := file:filename_all(), first => boolean(), gossip => map()}.

Functions

admits(Auth, Caller)

-spec admits(term(), <<_:256>>) -> boolean().

Whether a capability with Auth answers Caller (design §2.2). Every cluster node is a member (trust on sight).

call_as(Org, CapName, Caller, Payload, TimeoutMs, Opts)

-spec call_as(binary(), binary(), <<_:256>>, term(), pos_integer(), map()) ->
                 {ok, term()} | {error, term()}.

As call_capability/5, made as Caller rather than as this node: the member writes Caller as the call's caller and decides its auth against it. For a caller from outside the cluster that this node has authenticated itself: the mesh caller at the bridge (mcl_core_bridge_inbound, mcl-core#7).

call_capability(Org, CapName, Payload, TimeoutMs, Opts)

-spec call_capability(binary(), binary(), term(), pos_integer(), map()) ->
                         {ok, term()} | {error, term()}.

Call CapName in Org on the LAN. advertiser => NodeId in Opts calls only that node's member, as on the mesh.

configured()

-spec configured() -> off | {ok, config()}.

The lan app env: off, or {ok, Config}. A value of any other shape raises, naming it, so a typo is not silently a node with no LAN.

enabled()

-spec enabled() -> boolean().

Whether the LAN transport runs on this node.

export_group(Org, Cap)

-spec export_group(binary(), mcl_core_service:capability()) -> none | tuple().

The pg group a served capability joins beside its own when it is exported to the mesh (mcl_core_bridge:exported/1), or none. The group carries the capability without its handler, so the bridge can advertise it from the group alone (mcl-core#7).

exports()

-spec exports() -> [{binary(), mcl_core_service:capability()}].

Every exported capability served anywhere in the cluster, as {Org, Cap} without its handler; one per Org/Name (the lowest, so every node picks the same one), [] with the LAN off.

host(Key, Org, Caps)

-spec host(term(), binary(), [mcl_core_service:capability()]) -> ok | {error, term()}.

Serve on the LAN those of Caps it can serve (served/1), for the hosted service Key, replacing what Key served before. A no-op with the LAN off.

node_id()

-spec node_id() -> <<_:256>>.

This node's own node id, the one it writes as caller and publisher (mcl_core_lan_node sets it at start).

publish(Topic, Payload, Opts)

-spec publish(binary(), term(), map()) -> ok | {error, no_lan_subscriber}.

Publish Payload on Topic to every LAN subscriber. A publish naming another realm is the mesh's.

scope()

-spec scope() -> atom().

The pg scope of every LAN group.

served(Cap)

-spec served(mcl_core_service:capability()) -> boolean().

Whether the LAN serves Cap: a response handler whose auth a LAN can decide.

sourced(Sources, Publisher)

-spec sourced(mcl_core_service:sources(), <<_:256>>) -> boolean().

Whether a subscription with Sources takes an event from Publisher (design §2.3).

subscribe(Key, Subs)

-spec subscribe(term(), [mcl_core_service:subscription()]) -> ok | {error, term()}.

Subscribe on the LAN those of Subs it can carry (subscribed/1), for the hosted service Key, replacing its earlier ones.

subscribed(Sub)

-spec subscribed(mcl_core_service:subscription()) -> boolean().

Whether the LAN carries Sub: anything but a sealed group's.