mcl_core (mcl_core v1.0.0)

View Source

Public facade for mcl_core — the PQ-only over-mesh substrate.

Services typically only need a handful of these:

mcl_core:boot(MyServiceMod) %% one-call lifecycle wiring mcl_core:advertise_capabilities() %% (re-)publish my caps mcl_core:health() %% snapshot for /health mcl_core:identity_key() %% my node key, or {error, ...} mcl_core:macula_client() %% returns the SDK client handle

Summary

Functions

(Re-)publish this service's capabilities onto the mesh. Typically called once at boot; call again when the capability set changes.

Wire a service module into mcl_core and start it.

Call a capability by name, through the transport (mcl_core_transport). On the mesh bridge, the direct-dial data path: resolve a provider from the DHT, dial its serving station directly, and issue the CALL there (failing over to the next provider on error). The CALL uses CapName as the procedure, realm-scoped.

As call_capability/4, with Opts. One caller-facing option so far, and it is the one the many-provider contract model needs

Forget every hosted service: mcl_core's supervisor starts with none, so a restarted mcl_core does not carry the last run's services.

Snapshot of this service's health. Used by /health handler.

This service's stable signing node key, or {error, no_identity_key} when running on an ephemeral identity. Needed by every provider advertisement, which signs its own DHT record with it.

The store callbacks ServiceMod still exports from the contract before 0.35.0, when boot/1 opened a reckon-db store for a service exporting store_id/0 and data_dir/0. It does not any more (mcl-om#10): each service chooses its own persistence and opens its own store.

The {Pool, Realm} pair every PubSub/RPC-consumer/Content call needs together. Replaces the hand-rolled case {macula_client(), realm()} of {{ok,P},{ok,R}} -> ... pairing four independent service repos each wrote for themselves (among them tom_ocean_mesh.erl, tom_wire_macula.erl, tom_crier.erl) because mcl_core gave them nothing to build on. Degrades to {error, mesh_unavailable} rather than crashing when either half is missing (mesh unreachable, or no client attached yet).

Whether NodeId is an admitted member of Org in this service's realm, cached (mcl_core_org_member). macula verifies who signed a publication, not who may publish on a topic: a subscriber that must hear only an org's own nodes asks this about the delivery's publisher. {error, {not_a_member, _}} is the realm's refusal; {error, {unavailable, _}} means it could not find out, and is not a refusal.

This service's realm tag (32-byte binary). Previously reachable only by calling mcl_core_identity:realm/0 directly, past the public facade -- every service wanting to publish/subscribe/advertise on the mesh needs this alongside macula_client/0, so it belongs here.

The services this node hosts, in boot order.

A service's org: the org key of its own info/0, else mcl_core's org app env (mcl_core_identity:org/0), which is what every service used before a release could host more than one.

A service built for the old contract boots WITHOUT the store it expects, and would fail later, where nobody connects it to this release. So boot says so at once, as a warning naming the callbacks and the way out.

Functions

boot(Services)

-spec boot(module() | [module() | {module(), map()}]) ->
              {ok, pid()} | {ok, [{module(), pid()}]} | {error, term()}.

Wire a service module into mcl_core and start it.

Typical call from the hosting service's _app:start/2:

start(_, _) -> mcl_core:boot(my_service).

ONE NODE, SEVERAL SERVICES (mcl-om#8). Each boot ADDS its service to the ones this node hosts; a second boot of the same module replaces only its own entry. A release that bundles several services boots them with a list, mcl_core:boot([kanban_service, {mail_service, Opts}]), and they share the one identity key, mesh pool and health socket, each advertising under its own org (see service_org/1). A standalone release calls boot/1 once, as it always has.

boot(ServiceMod, Opts)

-spec boot(module(), map()) -> {ok, pid()} | {error, term()}.

call_capability(Org, CapName, Payload, TimeoutMs)

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

Call a capability by name, through the transport (mcl_core_transport). On the mesh bridge, the direct-dial data path: resolve a provider from the DHT, dial its serving station directly, and issue the CALL there (failing over to the next provider on error). The CALL uses CapName as the procedure, realm-scoped.

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

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

As call_capability/4, with Opts. One caller-facing option so far, and it is the one the many-provider contract model needs:

advertiser => <<_:256>> call ONLY the provider whose signed advertisement was published by this node id. One org procedure with many providers -- a thousand book clubs, one get_bookclub_by_id -- resolves to whoever the DHT lists first; a club that does not own the asked id answers not_found, which is a valid answer and NOT a failover signal, so the wrong club wins by order. The fix is not a smarter retry, it is a pin: the caller that holds the club's node id (the publisher of the facts it consumed) names it here, and only that club is dialed. An absent or stale pin resolves to nothing and fails closed with {error, no_provider}.

{error, no_provider} means exactly "nothing was dialed": nothing resolved, or the pin matched no resolved provider. A provider that WAS dialed reports its own failure instead ({error, timeout}, {error, {station_endpoint, Reason}}, ...), so a dead provider and a stale pin are never the same answer (0.29.0).

forget_services()

-spec forget_services() -> ok.

Forget every hosted service: mcl_core's supervisor starts with none, so a restarted mcl_core does not carry the last run's services.

health()

-spec health() -> mcl_core_service:health().

Snapshot of this service's health. Used by /health handler.

identity_key()

-spec identity_key() -> {ok, macula_node_keys:node_key()} | {error, term()}.

This service's stable signing node key, or {error, no_identity_key} when running on an ephemeral identity. Needed by every provider advertisement, which signs its own DHT record with it.

leftover_store_callbacks(ServiceMod)

-spec leftover_store_callbacks(module()) -> [atom()].

The store callbacks ServiceMod still exports from the contract before 0.35.0, when boot/1 opened a reckon-db store for a service exporting store_id/0 and data_dir/0. It does not any more (mcl-om#10): each service chooses its own persistence and opens its own store.

Only the old contract's ACTIVATION counts, store_id/0 and data_dir/0 together, which is what made 0.34 open a store: a storeless service with a data_dir/0 of its own never had one. Then every old store callback it still exports is named.

macula_client()

-spec macula_client() -> {ok, term()} | {error, term()}.

mesh_handles()

-spec mesh_handles() -> {ok, term(), binary()} | {error, mesh_unavailable}.

The {Pool, Realm} pair every PubSub/RPC-consumer/Content call needs together. Replaces the hand-rolled case {macula_client(), realm()} of {{ok,P},{ok,R}} -> ... pairing four independent service repos each wrote for themselves (among them tom_ocean_mesh.erl, tom_wire_macula.erl, tom_crier.erl) because mcl_core gave them nothing to build on. Degrades to {error, mesh_unavailable} rather than crashing when either half is missing (mesh unreachable, or no client attached yet).

org_member(Org, NodeId)

-spec org_member(binary(), <<_:256>>) -> mcl_core_org_member:answer().

Whether NodeId is an admitted member of Org in this service's realm, cached (mcl_core_org_member). macula verifies who signed a publication, not who may publish on a topic: a subscriber that must hear only an org's own nodes asks this about the delivery's publisher. {error, {not_a_member, _}} is the realm's refusal; {error, {unavailable, _}} means it could not find out, and is not a refusal.

realm()

-spec realm() -> {ok, binary()} | {error, term()}.

This service's realm tag (32-byte binary). Previously reachable only by calling mcl_core_identity:realm/0 directly, past the public facade -- every service wanting to publish/subscribe/advertise on the mesh needs this alongside macula_client/0, so it belongs here.

service_module()

-spec service_module() -> module() | undefined.

service_modules()

-spec service_modules() -> [module()].

The services this node hosts, in boot order.

service_org(ServiceMod)

-spec service_org(module()) -> binary().

A service's org: the org key of its own info/0, else mcl_core's org app env (mcl_core_identity:org/0), which is what every service used before a release could host more than one.

warn_leftover_store(ServiceMod)

-spec warn_leftover_store(module()) -> ok | {warned, [atom()]}.

A service built for the old contract boots WITHOUT the store it expects, and would fail later, where nobody connects it to this release. So boot says so at once, as a warning naming the callbacks and the way out.