macula_dist_discovery (macula v10.25.0)
View SourceNode 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
-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. 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}}.
-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.