Search documentation of macula

# macula_peer_discovery (macula v0.44.2)

View Source

Peer Discovery - DHT-based gateway discovery and P2P mesh formation.

This module implements automatic peer discovery to enable true P2P mesh: 1. Gateways register themselves in the bootstrap DHT 2. Peers periodically query DHT to discover other gateways 3. Peers establish direct QUIC connections to discovered gateways 4. Cross-peer relay works automatically via these mesh connections

Architecture: Peer1 Gateway - Peer2 Gateway - Peer3 Gateway | | | Local Clients Local Clients Local Clients

DHT Storage: Key pattern: "peer.gateway." + NodeID Value: map with node_id, host, port, realm fields

# Summary

## Functions

discover_peers()

Discover other peer gateways from DHT

handle_call(Request, From, State)
handle_cast(Msg, State)
handle_info(Info, State)
init(Config)
register_gateway()

Register this gateway in the bootstrap DHT

start_link(Config)

Start the peer discovery process

terminate(Reason, State)

# Functions

# discover_peers()

    -spec discover_peers() -> {ok, [map()]} | {error, term()}.

Discover other peer gateways from DHT

# handle_call(Request, From, State)

# handle_cast(Msg, State)

# handle_info(Info, State)

# init(Config)

# register_gateway()

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

Register this gateway in the bootstrap DHT

# start_link(Config)

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

Start the peer discovery process

# terminate(Reason, State)