macula_protocol_types (macula v0.20.5)

View Source

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

Summary

Functions

Get numeric ID for a message type.

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(),
            caller_did => binary(),
            ucan_token => binary()}.

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

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

rpc_route_msg/0

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

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.