Search documentation of macula

# macula_dist_discovery (macula v4.4.1)

View Source

EPMD 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_nodes()

List all known nodes.

lookup_node(NodeName)

Look up a node by name. This replaces EPMD lookup.

lookup_node(NodeName, Timeout)

Look up a node by name with timeout.

register_node(NodeName, Port)

Register this node in the distributed registry. This replaces EPMD registration.

start_link()

Start the discovery server with default options.

start_link(Opts)

Start the discovery server with options.

subscribe(Pid)

Subscribe to node discovery events. Subscriber will receive: {node_discovered, NodeName, IP, Port} {node_lost, NodeName}

unregister_node(NodeName)

Unregister this node from the distributed registry.

unsubscribe(Pid)

Unsubscribe from node discovery events.

# Functions

# list_nodes()

    -spec list_nodes() -> [atom()].

List all known nodes.

# lookup_node(NodeName)

    -spec lookup_node(atom()) -> {ok, map()} | {error, not_found}.

Look up a node by name. This replaces EPMD lookup.

# lookup_node(NodeName, Timeout)

    -spec lookup_node(atom(), timeout()) -> {ok, map()} | {error, not_found}.

Look up a node by name with timeout.

# register_node(NodeName, Port)

    -spec register_node(atom(), integer()) -> ok | {error, term()}.

Register this node in the distributed registry. This replaces EPMD registration.

# start_link()

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

Start the discovery server with default options.

# start_link(Opts)

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

Start the discovery server with options.

# subscribe(Pid)

    -spec subscribe(pid()) -> ok.

Subscribe to node discovery events. Subscriber will receive: {node_discovered, NodeName, IP, Port} {node_lost, NodeName}

# unregister_node(NodeName)

    -spec unregister_node(atom()) -> ok.

Unregister this node from the distributed registry.

# unsubscribe(Pid)

    -spec unsubscribe(pid()) -> ok.

Unsubscribe from node discovery events.