macula_dist_relay_protocol (macula v3.13.0)
View SourceControl 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
-type control_msg() :: identify_msg() | identified_msg() | tunnel_request_msg() | tunnel_ok_msg() | tunnel_error_msg() | tunnel_close_msg() | tunnel_notify_msg().
-type identified_msg() :: #{type := identified, status := ok}.
-type identify_msg() :: #{type := identify, node_name := binary()}.
-type tunnel_close_msg() :: #{type := tunnel_close, tunnel_id := binary()}.
-type tunnel_error_msg() :: #{type := tunnel_error, reason := binary()}.
-type tunnel_ok_msg() :: #{type := tunnel_ok, tunnel_id := binary()}.
-type tunnel_request_msg() :: #{type := tunnel_request, target := binary()}.
Functions
-spec decode(binary()) -> {ok, control_msg()} | {error, term()}.
-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.
-spec encode(control_msg()) -> binary().