macula_ping_pong (macula v0.20.5)
View SourceMacula Ping/Pong - Direct P2P Async RPC Demo
A peer-to-peer 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 statistics for a specific peer
Get all statistics
Send a PING to a specific peer
Reset all statistics
Start with default settings
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)
Functions
Get statistics for a specific peer
-spec get_stats() -> map().
Get all statistics
Send a PING to a specific peer
-spec reset_stats() -> ok.
Reset all statistics
Start with default settings
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)