macula_dist_discovery (macula v0.20.5)
View SourceEPMD Replacement using Macula DHT Discovery.
This module provides decentralized node discovery for Erlang distribution, replacing the centralized EPMD (Erlang Port Mapper Daemon).
How it Works
Instead of registering with a local EPMD daemon on port 4369, nodes announce themselves via Macula's DHT (Distributed Hash Table):
1. On startup, nodes call register_node/2 to announce themselves 2. Other nodes find peers via lookup_node/1 which queries the DHT 3. Subscribers get notified of node join/leave events
Discovery Mechanisms
- **mDNS**: For local network discovery (no bootstrap required) - **DHT**: For internet-scale discovery (requires bootstrap nodes) - **Bootstrap**: Initial DHT seeds from known nodes
Usage
Register this node: ok = macula_dist_discovery:register_node('4433@192.168.1.100', 4433).
Look up a node: {ok, #{host := Host, port := Port}} = macula_dist_discovery:lookup_node('4433@192.168.1.100').
Subscribe to node events: ok = macula_dist_discovery:subscribe(self()). %% Receive: {node_discovered, Node, IP, Port} %% Receive: {node_lost, Node}
Summary
Functions
List all known nodes.
Look up a node by name. This replaces EPMD lookup.
Look up a node by name with timeout.
Register this node in the distributed registry. This replaces EPMD registration.
Start the discovery server with default options.
Start the discovery server with options.
Subscribe to node discovery events. Subscriber will receive: {node_discovered, NodeName, IP, Port} {node_lost, NodeName}
Unregister this node from the distributed registry.
Unsubscribe from node discovery events.
Functions
-spec list_nodes() -> [atom()].
List all known nodes.
Look up a node by name. This replaces EPMD lookup.
Look up a node by name with timeout.
Register this node in the distributed registry. This replaces EPMD registration.
Start the discovery server with default options.
Start the discovery server with options.
-spec subscribe(pid()) -> ok.
Subscribe to node discovery events. Subscriber will receive: {node_discovered, NodeName, IP, Port} {node_lost, NodeName}
-spec unregister_node(atom()) -> ok.
Unregister this node from the distributed registry.
-spec unsubscribe(pid()) -> ok.
Unsubscribe from node discovery events.