macula_dist_relay_protocol (macula v3.13.0)

View Source

Control protocol encoder/decoder for dist relay.

Stream 0 carries MessagePack-framed control messages. Each frame:

+----------+---------+ | Len (4B) | MsgPack | +----------+---------+

Len is big-endian uint32 of the msgpack payload size.

Message types: identify → identified tunnel_request → tunnel_ok | tunnel_error tunnel_close → (no reply) tunnel_notify → (relay → target, informs of incoming tunnel)

Summary

Functions

Extract zero or more complete frames from a buffer. Returns {Messages, Remaining} where Remaining is the leftover bytes.

Types

control_msg/0

identified_msg/0

-type identified_msg() :: #{type := identified, status := ok}.

identify_msg/0

-type identify_msg() :: #{type := identify, node_name := binary()}.

tunnel_close_msg/0

-type tunnel_close_msg() :: #{type := tunnel_close, tunnel_id := binary()}.

tunnel_error_msg/0

-type tunnel_error_msg() :: #{type := tunnel_error, reason := binary()}.

tunnel_notify_msg/0

-type tunnel_notify_msg() :: #{type := tunnel_notify, tunnel_id := binary(), source := binary()}.

tunnel_ok_msg/0

-type tunnel_ok_msg() :: #{type := tunnel_ok, tunnel_id := binary()}.

tunnel_request_msg/0

-type tunnel_request_msg() :: #{type := tunnel_request, target := binary()}.

Functions

decode(PayloadBin)

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

decode_buffer(Buffer)

-spec decode_buffer(binary()) -> {[control_msg()], binary()}.

Extract zero or more complete frames from a buffer. Returns {Messages, Remaining} where Remaining is the leftover bytes.

encode(Msg)

-spec encode(control_msg()) -> binary().