Search documentation of macula

# macula_connection_dispatch (macula v0.44.2)

View Source

Message dispatch logic extracted from macula_connection.

Contains all process_message/2 clauses and their helper functions for routing incoming protocol messages to the appropriate handlers.

# Summary

## Functions

add_discovered_peers(Nodes, MyNodeId)

Add discovered peers from a FIND_NODE reply to our routing table.

normalize_peer_node_id(Bin)
notify_mesh_lifecycle_observers(EventType, PeerInfo)

Notify external observers of mesh peer lifecycle events via pg group. Any process can join the macula_mesh_lifecycle pg group to receive these.

process_message(_, State)

Process a received message - route to appropriate handler.

remove_peer_from_routing_table(NodeId)

Remove a peer from the local routing table on disconnect notification.

send_message_raw(Type, Msg, Stream)

Send a protocol message through a stream (raw). Crashes if message is invalid - this indicates a bug in the caller.

# Functions

# add_discovered_peers(Nodes, MyNodeId)

    -spec add_discovered_peers([map()], binary()) -> ok.

Add discovered peers from a FIND_NODE reply to our routing table.

# normalize_peer_node_id(Bin)

    -spec normalize_peer_node_id(binary()) -> binary().

# notify_mesh_lifecycle_observers(EventType, PeerInfo)

    -spec notify_mesh_lifecycle_observers(atom(), map()) -> ok.

Notify external observers of mesh peer lifecycle events via pg group. Any process can join the macula_mesh_lifecycle pg group to receive these.

# process_message(_, State)

    -spec process_message({atom(), map()},
                          #state{url :: binary(),
                                 opts :: map(),
                                 node_id :: binary(),
                                 realm :: binary(),
                                 peer_id :: integer(),
                                 connection :: pid() | undefined,
                                 stream :: pid() | undefined,
                                 status :: connecting | connected | disconnected | error,
                                 recv_buffer :: binary(),
                                 keepalive_timer :: reference() | undefined,
                                 connect_in_flight :: boolean(),
                                 retry_delay_ms :: pos_integer()}) ->
                             #state{url :: binary(),
                                    opts :: map(),
                                    node_id :: binary(),
                                    realm :: binary(),
                                    peer_id :: integer(),
                                    connection :: pid() | undefined,
                                    stream :: pid() | undefined,
                                    status :: connecting | connected | disconnected | error,
                                    recv_buffer :: binary(),
                                    keepalive_timer :: reference() | undefined,
                                    connect_in_flight :: boolean(),
                                    retry_delay_ms :: pos_integer()}.

Process a received message - route to appropriate handler.

# remove_peer_from_routing_table(NodeId)

    -spec remove_peer_from_routing_table(undefined | binary()) -> ok.

Remove a peer from the local routing table on disconnect notification.

# send_message_raw(Type, Msg, Stream)

    -spec send_message_raw(atom(), map(), reference()) -> ok | {error, term()}.

Send a protocol message through a stream (raw). Crashes if message is invalid - this indicates a bug in the caller.