macula_dist_discovery (macula v10.25.0)

View Source

Node discovery for Erlang distribution over mDNS.

A registry of distribution nodes that subscribers can query and watch, fed by this node's own registration and by mDNS announcements.

Availability

Only mDNS discovery runs, in a server started with discovery_type => mdns; announcing this node needs the macula_mdns application to be running. DHT discovery is not available: it needs a DHT module that no macula release provides, so a server started with discovery_type => dht, or with both (the default), does not start, and start_link/1 returns {error, {strategy_unavailable, dht}}. The macula application does not start this server, and this module is removed in 11.0.0.

Usage

Start the server: {ok, _} = macula_dist_discovery:start_link(#{discovery_type => mdns}).

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. The default discovery type is both, which includes DHT discovery, so this returns {error, {strategy_unavailable, dht}}. Use start_link/1 with discovery_type => mdns.

Start the discovery server with options. discovery_type is mdns, dht or both (the default); only mdns starts, and the other two return {error, {strategy_unavailable, dht}}.

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

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. The default discovery type is both, which includes DHT discovery, so this returns {error, {strategy_unavailable, dht}}. Use start_link/1 with discovery_type => mdns.

start_link(Opts)

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

Start the discovery server with options. discovery_type is mdns, dht or both (the default); only mdns starts, and the other two return {error, {strategy_unavailable, dht}}.

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.