No description
  • Erlang 80.9%
  • Python 12.5%
  • Dockerfile 4.3%
  • Shell 2.3%
Find a file
beamologist 71033cc0fd
All checks were successful
c4 model / c4-model-1 (push) Successful in 5s
c4 model / c4-model (push) Successful in 0s
Test / erlang in . (push) Has been skipped
Test / guard-1 (push) Successful in 4s
Test / guard (push) Successful in 0s
Test / erlang in . (container) (push) Successful in 12s
Test / Dependency advisories (push) Successful in 0s
Test / rebar3 lint, xref, eunit, dialyzer (OTP 28.4.3) (push) Successful in 4m33s
Test / Release (forge, v* tag) (push) Successful in 4m16s
Test / File the tested resolve for the signer (push) Has been skipped
Test / The tested lock arrives whole (push) Has been skipped
Merge PR 14: release r=2: the push/action ban spares the release job; header, REVISION label, check-job message (macula-fleet#46)
2026-11-24 08:12:50 +01:00
.github release r=2: the push/action ban spares the release job; header, REVISION label, check-job message (macula-fleet#46) 2026-11-24 06:29:26 +01:00
apps/mcl_stations release r=2: the push/action ban spares the release job; header, REVISION label, check-job message (macula-fleet#46) 2026-11-24 06:29:26 +01:00
architecture The container view says its one write is the node key, not that it writes nothing (review r=1) 2026-11-24 02:53:08 +01:00
assets The container view says its one write is the node key, not that it writes nothing (review r=1) 2026-11-24 02:53:08 +01:00
config The Erlang cookie stays on the box; distribution and epmd on loopback (PR 3 squashed) 2026-11-23 21:21:17 +01:00
deploy The Erlang cookie stays on the box; distribution and epmd on loopback (PR 3 squashed) 2026-11-23 21:21:17 +01:00
scripts The Erlang cookie stays on the box; distribution and epmd on loopback (PR 3 squashed) 2026-11-23 21:21:17 +01:00
.gitignore store: the station read model moves from barrel_docdb to an ETS table 2026-11-23 01:00:51 +01:00
.tool-versions scaffold: rebar3 new mcl_service from mcl_om 0.26.5 2026-09-23 23:06:19 +02:00
CHANGELOG.md The image pair is named on public ghcr, by dated tag and digest 2026-11-24 03:23:31 +01:00
Containerfile The image pair is named on public ghcr, by dated tag and digest 2026-11-24 03:23:31 +01:00
LICENSE scaffold: rebar3 new mcl_service from mcl_om 0.26.5 2026-09-23 23:06:19 +02:00
README.md The image pair is named on public ghcr, by dated tag and digest 2026-11-24 03:23:31 +01:00
rebar.config Merge PR 10: cowlib 2.22.0 is pinned, and the service carries its Container diagram (mcl-stations#9) 2026-11-24 02:53:07 +01:00
SECURITY.md SECURITY.md: response times, attachment and identity rules, drills (macula-io/macula#174) 2026-10-31 02:59:44 +01:00

mcl-stations

License BEAM Buy Me a Coffee

Macula

Live, filterable directory of macula stations: geo, liveness and direct-dial address, so clients never hand-maintain a station list


Status: serving list_stations

The service boots, joins the mesh and answers /health on its Unix socket (/run/mcl/health.sock). It keeps a directory of every macula station and serves it as one RPC.

What it reads. Three DHT record types, the ones every macula-station already broadcasts: node_record (0x01: hostname, city, country, lat/lng, kind, and the build the station reports), station_endpoint (0x12: QUIC port and the literal addresses to dial), and the tombstone (0x0C) a station publishes when it shuts down gracefully. A snapshot at boot (macula:find_records_by_type/2), then live subscriptions (macula:subscribe_records/3). The macula facade verifies every record under the node's crypto profile and drops what fails, so nothing unverified reaches the read model. The two records of one station are joined on the signer's key id, and a tombstone that withdraws a node_record removes that station at once.

What it serves. mcl-stations/list_stations, open to any caller, and sealed end to end: a near request carries the caller's location, so the call must be sealed to the KEM key named in the service's signed advertisement, and a clear call is refused sealed_required (0.6.0, issue #18). Every macula SDK seals by default.

Argument Effect
none, or not a map every known station
continent, country, city exact match; continent is derived from the ISO country code
near => #{lat, lng, limit} nearest first by great-circle distance, limit optional; stations without coordinates are left out
limit caps the result count of any of the above, applied last

The reply is #{stations => [Row]}. Text fields (hostname, city, country, continent, kind, version, each host_advertised entry) go out as CBOR text, so non-BEAM callers read strings, not bytes. node_id is the station's 32-byte key id and stays bytes.

Rows are self-certifying. Each row carries the station's raw signed records in node_record and station_endpoint (bytes, ~7.2 KB together), so a client verifies them itself instead of trusting this directory; the projected fields beside them are convenience. A row serves a record type's fields only while that record is unexpired AND its stored bytes verify again under the node's crypto profile: one that does not is refused, never served, and shows up in /health ({degraded, {record_verification_drops, Counts}}). Serving is per record type, so a lapsed node_record drops its fields while a live station_endpoint keeps the station listed. Because a row now carries its records, callers that do not want the whole directory pass limit.

It asks the realm for its scope, mcl-stations -- claimed in identity_spec/0 for the namespace every later resource hangs under, with no actions or resources yet -- and a provider authorization per org procedure, list_stations, info and get_limits; without that grant an advertisement never lands and /health reads degraded. The records it reads live in the DHT's own realm, and serving an RPC needs no realm-granted topic.

Stations that go dark. Each row keeps the expiry of the records it came from. A live station refreshes them well before they lapse; one that crashed or lost its link stops refreshing, and once all its records have expired it is no longer listed, with no tombstone needed. A record type's fields and raw bytes stop being served at its own expiry, before the station as a whole lapses.

The read model is an ETS table owned by the service's own station_store process, a cache rebuilt from the DHT snapshot on every boot. It writes nothing to disk, so it has no volume on purpose, and a restart starts empty and refills within one refresh. station_store drops a row once neither of its records is live, so a station that goes dark costs no memory once its TTL has passed.

Running it

No native library is needed beyond what the build image carries: the read model is ETS, and macula's NIFs build from source. Locally, with OTP 28.4.3:

rebar3 compile
rebar3 eunit
rebar3 lint
rebar3 dialyzer

scripts/health.sh                      # against a running node

or, without that toolchain on the box, in the team's build image, the one test.yml and the Containerfile pin:

podman run --rm \
    -v "$PWD:/w:Z" -w /w \
    ghcr.io/macula-io/macula-ci-otp:20261120-1240@sha256:39da314646c418ab69778dd7135663d8e2099e3d46c0fcf1318f3cb83c58d978 \
    sh -c 'rebar3 lint && rebar3 eunit && rebar3 dialyzer'

The image builds in macula-ci-otp and runs on macula-pq-runtime, both on public ghcr by dated tag and digest, Debian trixie. They are named there and not on the forge's registry because host00's image signer builds this image and refuses a git.macula.io/ base it cannot cosign-verify; ghcr is public, so no credential is needed to pull them.

podman build -t mcl-stations -f Containerfile .

Configuration

Variable Default Meaning
MCL_REALM required 64-hex realm tag, the sha256 of the realm's name. No default: a service that guesses its realm announces itself where nobody can attribute it.
MCL_REALM_KEY required The realm's public signing key, hex encoded: the trust anchor, not an identifier. Every org-namespaced advertisement is verified against it, so without it nothing resolves, the boot claim never reaches the realm, and the service stays green while unreachable. Public material, not a secret.
MACULA_STATION_SEEDS required Station hosts to dial, host[:port], comma-separated. No default: naming a realm costs nothing, dialling somebody else's live station from every dev clone does.
MACULA_STATION_NODE_IDS required The matching 64-hex station node ids, comma-separated, index-paired with the seeds. The dial is pinned (D5): mcl_om refuses to boot a pool with an unpinned seed.
MCL_SERVICE_NAME mcl-stations Label on the boot claim the realm's operator sees.
MCL_BOX from the host Label naming the box, also on the boot claim. Set it where you deploy.
(none) /run/mcl/health.sock /health is served on this Unix socket inside the container (mcl_om health_socket); no health port is bound. scripts/health.sh asks it.
MCL_NODE_NAME mcl_stations Erlang node name.
MCL_NODE_HOST 127.0.0.1 Erlang node host.
MCL_COOKIE unset Erlang cookie. Unset, the image makes a random one on first start in the secrets volume (/etc/mcl/secrets/erlang.cookie, 0600) and keeps it. Distribution and epmd listen on 127.0.0.1 only. A remote shell: docker exec -it mcl-stations /app/start.sh remote_console.

deploy/docker-compose.yml runs it, and carries what the service knows about itself. If you deploy through something else, let that carry placement: which host, which station, which realm, which secret store. Keeping the two apart is what stops a config table in a README and the real environment drifting.

Deployment

CI publishes no image and signs nothing. ghcr refuses this organisation and the fleet's move is to the forge registry, so the release is built by the SIGNER, off CI, from the resolve the tests ran on (macula-realm#3's pattern): a push to main files the tested rebar.lock on the tested-locks pre-release as <commit>.<sha256>.rebar.lock (test.yml, the hand-lock job), and the signer for a v* tag fetches exactly that name with its read-only token and refuses anything whose sha256 is not the one in it. Until P6 gives this service a signer, nothing publishes, and a box keeps the digest it already runs.

A box runs a release by digest: macula-fleet's pin-releases workflow finds the signed release, verifies it was signed on its tag and pins <version>@sha256:<digest> (macula-fleet#14, #15), so a green v* tag is the deploy. To roll back, revert the pin and hold the image there.

The service's org, the <org> prefix on its own procedure names (<org>/<name>), is this repository's name, fixed in config/sys.config.src. The realm's grant names it; without an org mcl_om refuses to boot, naming the setting.

Two things CI cannot do for you, both of which have bitten:

  1. The forge's registry package needs a credential on every puller: the org's read-only pull account (CI_IMAGE_PULL_USER / CI_IMAGE_PULL_TOKEN). A pull without one fails with a bare unauthorized that names nothing.
  2. The host needs MCL_REALM and the station seeds, each with its matching node id, supplied from somewhere they are not committed.

The service contract

Six callbacks in mcl_stations_service, all required, all resolved by name by mcl_om at startup on a live node. The -behaviour(mcl_om_service) attribute turns a missing one into a compile error rather than an undef where nobody is watching, and the eunit suite guards the attribute itself.

Adding a store later

This service has no reckon-db store, which is the right answer for most. The reckon-db applications run either way; what a store adds is a data directory, an open handle, and something written.

The cheapest way to get one is to scaffold again with store=1, which generates the callbacks, the config and the guards together.

⚠ By hand it is three things and not one, and the missing third crash-loops the node. Export store_id/0 and data_dir/0; add the evoq adapter block to config/sys.config.src, without which boot raises {not_configured, event_store_adapter} before any service code runs; and mount a volume in the compose file. A sibling service put two of three fleet nodes into a boot loop by doing the first and not the second.

Architecture

The C4 model is in architecture/README.md, with its diagrams drawn by architecture/c4_diagrams.py into assets/. Change the script, run it (python3 architecture/c4_diagrams.py), and look at the result before committing.

mcl-stations system context

Licence

Apache-2.0.