Search documentation of macula

# macula_protocol_types (macula v4.4.9)

View Source

Protocol message type definitions and constants for Macula mesh. Defines all message types that can be sent over QUIC streams.

# Summary

## Types

bridge_data_msg/0
bridge_rpc_msg/0
call_msg/0
cast_msg/0
connect_msg/0
content_block_msg/0
content_cancel_msg/0
content_have_msg/0
content_manifest_req_msg/0
content_manifest_res_msg/0
content_want_msg/0
disconnect_msg/0
gossip_pull_msg/0
gossip_pull_reply_msg/0
gossip_push_msg/0
gossip_sync_msg/0
gossip_sync_reply_msg/0
message/0
message_type/0
ping_msg/0
pong_msg/0
publish_msg/0
pubsub_route_msg/0
registry_fetch_msg/0
registry_fetch_reply_msg/0
registry_publish_ack_msg/0
registry_publish_msg/0
registry_query_msg/0
registry_query_reply_msg/0
registry_sync_msg/0
registry_sync_reply_msg/0
registry_verify_msg/0
registry_verify_reply_msg/0
reply_msg/0
rpc_route_msg/0
stream_data_msg/0
stream_end_msg/0
stream_error_msg/0
stream_id/0

16-byte unique id

stream_mode/0
stream_open_msg/0
stream_reply_msg/0
subscribe_msg/0
unsubscribe_msg/0

## Functions

message_type_id(_)

Get numeric ID for a message type.

message_type_name(_)

Get message type name from numeric ID.

# Types

# bridge_data_msg/0

    -type bridge_data_msg() :: #{payload := term(), source_node_id => binary(), metadata => map()}.

# bridge_rpc_msg/0

    -type bridge_rpc_msg() ::
              #{procedure := binary(),
                args := map(),
                call_id := binary(),
                source_level := atom(),
                timeout => integer()}.

# call_msg/0

    -type call_msg() ::
              #{procedure := binary(),
                args := binary(),
                call_id := binary(),
                timeout => integer(),
                target => binary(),
                caller_did => binary(),
                ucan_token => binary(),
                '_trace' => [map()]}.

# cast_msg/0

    -type cast_msg() ::
              #{procedure := binary(), args := binary(), caller_did => binary(), ucan_token => binary()}.

# connect_msg/0

    -type connect_msg() ::
              #{version := binary(),
                node_id := binary(),
                realm_id := binary(),
                capabilities := [atom()],
                endpoint => binary(),
                default_ucan => binary()}.

# content_block_msg/0

    -type content_block_msg() ::
              #{request_id := binary(), mcid := binary(), data := binary(), from_node := binary()}.

# content_cancel_msg/0

    -type content_cancel_msg() :: #{request_id := binary(), from_node := binary()}.

# content_have_msg/0

    -type content_have_msg() :: #{haves := [binary()], manifest_mcid => binary(), from_node := binary()}.

# content_manifest_req_msg/0

    -type content_manifest_req_msg() :: #{request_id := binary(), mcid := binary(), from_node := binary()}.

# content_manifest_res_msg/0

    -type content_manifest_res_msg() ::
              #{request_id := binary(), mcid := binary(), manifest := binary(), from_node := binary()}.

# content_want_msg/0

    -type content_want_msg() ::
              #{request_id := binary(),
                wants := [#{mcid := binary(), priority => 1..255}],
                max_blocks => pos_integer(),
                from_node := binary()}.

# disconnect_msg/0

    -type disconnect_msg() :: #{reason := atom(), message := binary()}.

# gossip_pull_msg/0

    -type gossip_pull_msg() :: #{node_id := binary(), state_keys := [binary()]}.

# gossip_pull_reply_msg/0

    -type gossip_pull_reply_msg() ::
              #{node_id := binary(),
                states := [#{key := binary(), type := atom(), state := term(), vector_clock := map()}]}.

# gossip_push_msg/0

    -type gossip_push_msg() ::
              #{node_id := binary(),
                state_type := atom(),
                state_key := binary(),
                state := term(),
                vector_clock := map()}.

# gossip_sync_msg/0

    -type gossip_sync_msg() :: #{node_id := binary(), digest := map()}.

# gossip_sync_reply_msg/0

    -type gossip_sync_reply_msg() ::
              #{node_id := binary(),
                states := [#{key := binary(), type := atom(), state := term(), vector_clock := map()}],
                missing := [binary()]}.

# message/0

    -type message() ::
              {connect, connect_msg()} |
              {disconnect, disconnect_msg()} |
              {ping, ping_msg()} |
              {pong, pong_msg()} |
              {publish, publish_msg()} |
              {subscribe, subscribe_msg()} |
              {unsubscribe, unsubscribe_msg()} |
              {pubsub_route, pubsub_route_msg()} |
              {call, call_msg()} |
              {reply, reply_msg()} |
              {cast, cast_msg()} |
              {rpc_route, rpc_route_msg()}.

# message_type/0

    -type message_type() ::
              connect | disconnect | ping | pong | publish | subscribe | unsubscribe | pubsub_route | call |
              reply | cast | rpc_route | rpc_request | rpc_reply | register_procedure | stream_open |
              stream_data | stream_end | stream_error | stream_reply | swim_ping | swim_ack |
              swim_ping_req | find_node | find_node_reply | store | find_value | find_value_reply |
              nat_probe | nat_probe_reply | punch_request | punch_coordinate | punch_execute |
              punch_result | relay_request | relay_data | bridge_rpc | bridge_data | gossip_push |
              gossip_pull | gossip_pull_reply | gossip_sync | gossip_sync_reply | registry_publish |
              registry_publish_ack | registry_fetch | registry_fetch_reply | registry_query |
              registry_query_reply | registry_verify | registry_verify_reply | registry_sync |
              registry_sync_reply | content_want | content_have | content_block | content_manifest_req |
              content_manifest_res | content_cancel.

# ping_msg/0

    -type ping_msg() :: #{timestamp := integer()}.

# pong_msg/0

    -type pong_msg() :: #{timestamp := integer(), server_time := integer()}.

# publish_msg/0

    -type publish_msg() ::
              #{topic := binary(),
                payload := binary(),
                qos := 0 | 1 | 2,
                retain := boolean(),
                message_id := binary(),
                publisher_did => binary(),
                ucan_token => binary(),
                '_trace' => [map()]}.

# pubsub_route_msg/0

    -type pubsub_route_msg() :: #{binary() => term()}.

# registry_fetch_msg/0

    -type registry_fetch_msg() ::
              #{package_name := binary(), version => binary(), include_deps => boolean()}.

# registry_fetch_reply_msg/0

    -type registry_fetch_reply_msg() ::
              #{package_name := binary(),
                version := binary(),
                manifest := map(),
                beam_archive := binary(),
                signature := binary(),
                public_key := binary(),
                dependencies => [map()]}.

# registry_publish_ack_msg/0

    -type registry_publish_ack_msg() ::
              #{package_name := binary(),
                version := binary(),
                checksum := binary(),
                published_at := integer()}.

# registry_publish_msg/0

    -type registry_publish_msg() ::
              #{package_name := binary(),
                version := binary(),
                manifest := map(),
                beam_archive := binary(),
                signature := binary(),
                public_key := binary()}.

# registry_query_msg/0

    -type registry_query_msg() :: #{package_name := binary(), pattern => binary()}.

# registry_query_reply_msg/0

    -type registry_query_reply_msg() ::
              #{packages :=
                    [#{name := binary(),
                       versions := [binary()],
                       latest := binary(),
                       description => binary()}]}.

# registry_sync_msg/0

    -type registry_sync_msg() ::
              #{node_id := binary(),
                package_index := [#{name := binary(), version := binary(), checksum := binary()}]}.

# registry_sync_reply_msg/0

    -type registry_sync_reply_msg() ::
              #{node_id := binary(),
                missing := [#{name := binary(), version := binary()}],
                updates := [#{name := binary(), version := binary()}]}.

# registry_verify_msg/0

    -type registry_verify_msg() :: #{package_name := binary(), version := binary(), checksum := binary()}.

# registry_verify_reply_msg/0

    -type registry_verify_reply_msg() ::
              #{package_name := binary(), version := binary(), valid := boolean(), reason => binary()}.

# reply_msg/0

    -type reply_msg() ::
              #{call_id := binary(),
                result => binary(),
                error => #{code := binary(), message := binary()},
                '_trace' => [map()]}.

# rpc_route_msg/0

    -type rpc_route_msg() :: #{binary() => term()}.

# stream_data_msg/0

    -type stream_data_msg() ::
              #{stream_id := stream_id(),
                seq := non_neg_integer(),
                body := binary() | map(),
                encoding := raw | msgpack}.

# stream_end_msg/0

    -type stream_end_msg() :: #{stream_id := stream_id(), role := send | both}.

# stream_error_msg/0

    -type stream_error_msg() :: #{stream_id := stream_id(), code := binary(), message := binary()}.

# stream_id/0

    -type stream_id() :: binary().

16-byte unique id

# stream_mode/0

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

# stream_open_msg/0

    -type stream_open_msg() ::
              #{stream_id := stream_id(),
                procedure := binary(),
                mode := stream_mode(),
                args := binary() | map(),
                caller_did => binary(),
                ucan_token => binary(),
                target => binary()}.

# stream_reply_msg/0

    -type stream_reply_msg() ::
              #{stream_id := stream_id(),
                result => term(),
                error => #{code := binary(), message := binary()}}.

# subscribe_msg/0

    -type subscribe_msg() ::
              #{topics := [binary()], qos := 0 | 1 | 2, subscriber_did => binary(), ucan_token => binary()}.

# unsubscribe_msg/0

    -type unsubscribe_msg() :: #{topics := [binary()]}.

# Functions

# message_type_id(_)

    -spec message_type_id(message_type()) -> byte().

Get numeric ID for a message type.

# message_type_name(_)

    -spec message_type_name(byte()) -> {ok, message_type()} | {error, unknown_type}.

Get message type name from numeric ID.