Search documentation of macula

# macula_ping_pong (macula v0.44.2)

View Source

Macula Ping/Pong - Async RPC Health Check Demo

A mesh communication module that demonstrates bidirectional messaging across NAT boundaries using Macula's async RPC with direct P2P delivery (NATS-style request/reply).

Each node: - Registers local "ping.handler" RPC handler - Periodically sends PING RPCs to random peers (direct P2P) - Receives PONGs via callback - Measures Round-Trip Time (RTT) for each exchange - Tracks statistics per peer and per NAT type

Architecture: - Bootstrap: DHT only (no pub/sub routing) - Communication: Direct P2P via QUIC - Discovery: DHT for service registration

Flow: 1. fc01 registers local "ping.handler" (handles incoming PINGs) 2. fc01 calls macula_rpc_handler:request_to/5 to ping rc05 directly 3. Request goes directly to rc05 via QUIC (NAT-aware, no DHT lookup) 4. rc05's "ping.handler" executes, returns PONG 5. fc01 receives PONG via callback, measures RTT

# Summary

## Functions

get_peer_stats(PeerId)

Get statistics for a specific peer

get_stats()

Get all statistics

handle_call(Request, From, State)
handle_cast(Msg, State)
handle_info(Info, State)
init(Opts)
ping(PeerId)

Send a PING to a specific peer

reset_stats()

Reset all statistics

start_link()

Start with default settings

start_link(Opts)

Start with options Options: - interval: milliseconds between PINGs (default: 5000) - timeout: milliseconds to wait for PONG (default: 3000) - node_id: custom node identifier (default: NODE_ID env var)

terminate(Reason, State)

# Functions

# get_peer_stats(PeerId)

    -spec get_peer_stats(binary()) -> map() | not_found.

Get statistics for a specific peer

# get_stats()

    -spec get_stats() -> map().

Get all statistics

# handle_call(Request, From, State)

# handle_cast(Msg, State)

# handle_info(Info, State)

# init(Opts)

# ping(PeerId)

    -spec ping(binary()) -> {ok, integer()} | {error, term()}.

Send a PING to a specific peer

# reset_stats()

    -spec reset_stats() -> ok.

Reset all statistics

# start_link()

    -spec start_link() -> {ok, pid()} | {error, term()}.

Start with default settings

# start_link(Opts)

    -spec start_link(map()) -> {ok, pid()} | {error, term()}.

Start with options Options: - interval: milliseconds between PINGs (default: 5000) - timeout: milliseconds to wait for PONG (default: 3000) - node_id: custom node identifier (default: NODE_ID env var)

# terminate(Reason, State)