macula_mesh_client (macula v3.13.0)

View Source

Macula Mesh Client — connects a node to the relay mesh via QUIC.

Single gen_server managing ONE persistent QUIC connection to a relay with automatic failover across multiple relays. On disconnect, cycles to the next relay in the list with exponential backoff + jitter. Replays all subscriptions and procedure registrations on reconnect.

This is the SDK client module. It speaks the node role only — it cannot identify as a relay, cannot subscribe to _swim/_dht/_relay.*, and has no loop-prevention concerns. For relay-to-relay peering connections, see macula_peer_client in the macula-relay repository.

Usage:

   {ok, Client} = macula_mesh_client:start_link(#{
       relays => [<<"quic://boot.macula.io:443">>],
       realm => <<"io.macula">>
   }).

Summary

Functions

Advertise a streaming procedure (default mode: server_stream). Registers locally in this client's stream_procedures map AND sends a register_procedure frame upstream so the relay routes incoming STREAM_OPEN frames for Procedure back to this client.

Open a server-stream call against a connected mesh client.

Open a client-stream or bidi call (mode from opts; default bidi).

Send a STREAM_* frame out the QUIC stream (called by macula_stream_v1 processes when their peer shape is {remote, ...}).

Types

stream_handler/0

-type stream_handler() :: fun((pid(), term()) -> any()).

stream_mode/0

-type stream_mode() :: server_stream | client_stream | bidi.

Functions

advertise(Pid, Procedure, Handler)

-spec advertise(pid(), binary(), fun((map()) -> {ok, term()} | {error, term()})) -> {ok, reference()}.

call(Pid, Procedure, Args, Timeout)

-spec call(pid(), binary(), map(), timeout()) -> {ok, term()} | {error, term()}.

call(Pid, Procedure, Args, Timeout, Opts)

-spec call(pid(), binary(), map(), timeout(), map()) -> {ok, term()} | {error, term()}.

call_stream(Pid, Procedure, Args, Opts)

-spec call_stream(pid(), binary(), term(), map()) -> {ok, pid()} | {error, term()}.

Open a server-stream call against a connected mesh client.

call_stream(Pid, Procedure, Args, Opts, Timeout)

-spec call_stream(pid(), binary(), term(), map(), timeout()) -> {ok, pid()} | {error, term()}.

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(Opts)

is_connected(Pid)

-spec is_connected(pid()) -> boolean().

open_stream(Pid, Procedure, Args, Opts)

-spec open_stream(pid(), binary(), term(), map()) -> {ok, pid()} | {error, term()}.

Open a client-stream or bidi call (mode from opts; default bidi).

open_stream(Pid, Procedure, Args, Opts, Timeout)

-spec open_stream(pid(), binary(), term(), map(), timeout()) -> {ok, pid()} | {error, term()}.

publish(Pid, Topic, Payload)

-spec publish(pid(), binary(), binary() | map()) -> ok.

send_stream_frame(Pid, Type, Msg)

-spec send_stream_frame(pid(), atom(), map()) -> ok.

Send a STREAM_* frame out the QUIC stream (called by macula_stream_v1 processes when their peer shape is {remote, ...}).

start_link(Opts)

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

stop(Pid)

-spec stop(pid()) -> ok.

subscribe(Pid, Topic, Callback)

-spec subscribe(pid(), binary(), fun((map()) -> ok)) -> {ok, reference()}.

terminate(Reason, State)

unadvertise(Pid, Procedure)

-spec unadvertise(pid(), binary()) -> ok.

unsubscribe(Pid, Ref)

-spec unsubscribe(pid(), reference()) -> ok.