macula_advertise_station (macula v4.2.0)

View Source

Periodic DHT advertisement of a macula-net station.

Mirrors the shape of macula_dist_discovery: build a signed record once, publish it via a caller-supplied put_fn, refresh on a timer at well below the record's TTL.

Phase 2 publishes two record kinds per call:

  • One macula_record:station_endpoint/3 — keyed under sha256("station_endpoint" || pubkey) — telling resolvers how to reach the station's QUIC port.
  • One macula_record:address_pubkey_map/3 per macula-net address the station hosts — keyed under sha256("address_pubkey_map" || addr) — letting resolvers turn a bare IPv6 into a station pubkey.

The put_fn decoupling lets the same code drive co-located deployments (where the relay's internal API is reachable) and client-only deployments (where a V2 macula_client:pool() is the right primitive). PLAN_MACULA_NET_PHASE2.md §4.1 / §5.

Summary

Types

config/0

-type config() ::
          #{realm_pubkey := <<_:256>>,
            identity_pubkey := <<_:256>>,
            identity_privkey := macula_identity:key_pair() | macula_identity:privkey(),
            quic_port := 1..65535,
            addresses := [<<_:128>>],
            put_fn := put_fn(),
            advertised_ips => [binary()],
            alpn => binary(),
            refresh_ms => pos_integer()}.

put_fn/0

-type put_fn() :: fun((macula_record:record()) -> ok | {error, term()}).

Functions

code_change(OldVsn, State, Extra)

current_records()

-spec current_records() -> [macula_record:record()].

Return the most recently published record set.

handle_call(Other, From, State)

handle_cast(Msg, State)

handle_info(Other, State)

init(Config)

refresh_now()

-spec refresh_now() -> ok.

Force an immediate re-advertise. Useful from tests.

start_link(Config)

-spec start_link(config()) -> {ok, pid()} | {error, term()}.

stop()

-spec stop() -> ok.

terminate(Reason, State)