Search documentation of macula

# macula_dist_relay_protocol (macula v4.4.1)

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

## Types

control_msg/0
identified_msg/0
identify_msg/0
tunnel_close_msg/0
tunnel_error_msg/0
tunnel_notify_msg/0
tunnel_ok_msg/0
tunnel_request_msg/0

## Functions

decode(PayloadBin)
decode_buffer(Buffer)

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

encode(Msg)

# Types

# control_msg/0

    -type control_msg() ::
              identify_msg() |
              identified_msg() |
              tunnel_request_msg() |
              tunnel_ok_msg() |
              tunnel_error_msg() |
              tunnel_close_msg() |
              tunnel_notify_msg().

# 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().