macula_attach_identity (macula v4.3.0)

View Source

Daemon-side attachment to a host station.

PLAN_MACULA_NET_PHASE3.md §6.2. The daemon dials its host, sends a signed attach-request frame on a bidi stream, and from then on sends/receives macula-net envelopes through that same stream.

The handshake reuses the existing macula_net_transport_quic pipe — daemons share the transport's framing logic with stations even though they don't accept inbound connections themselves. The handshake frame and subsequent envelopes are length-prefixed CBOR maps.

Phase 3 MVP: no heartbeat (QUIC keepalive holds the connection), no automatic reconnect (Phase 4). Detach is explicit.

Summary

Functions

Attach to a host station. Performs the handshake and returns an opaque handle on success. The caller may then push envelopes via send/2 and register an inbound handler via set_inbound_handler/2.

Send a macula-net envelope over the attach stream.

Types

config/0

-type config() ::
          #{host_endpoint := host_endpoint(),
            realm_pubkey := <<_:256>>,
            daemon_keypair := macula_identity:key_pair(),
            inbound_handler => inbound_handler()}.

handle/0

-type handle() :: pid().

host_endpoint/0

-type host_endpoint() :: #{station_pubkey := <<_:256>>, host := binary() | string(), port := 1..65535}.

inbound_handler/0

-type inbound_handler() :: fun((Envelope :: binary()) -> any()).

Functions

attach(HostEndpoint, RealmPubkey, KeyPair, Opts)

-spec attach(host_endpoint(), RealmPubkey :: <<_:256>>, macula_identity:key_pair(), map()) ->
                {ok, handle()} | {error, term()}.

Attach to a host station. Performs the handshake and returns an opaque handle on success. The caller may then push envelopes via send/2 and register an inbound handler via set_inbound_handler/2.

code_change(OldVsn, State, Extra)

daemon_address(Handle)

-spec daemon_address(handle()) -> {ok, <<_:128>>} | {error, term()}.

detach(Handle)

-spec detach(handle()) -> ok.

handle_call(Other, From, State)

handle_cast(Msg, State)

handle_info(Msg, State)

init(Config)

send(Handle, Envelope)

-spec send(handle(), Envelope :: binary()) -> ok | {error, term()}.

Send a macula-net envelope over the attach stream.

set_inbound_handler(Handle, Fun)

-spec set_inbound_handler(handle(), inbound_handler()) -> ok.

terminate(Reason, State)