Home

Awesome

Multicast DNS

Build Status

mDNS is an implementation of the mDNS discovery protocol written in Erlang/OTP and enables two or more Erlang nodes to self discover and form a mesh network.

The implementation uses the method described in DNS-Based Service Discovery to register and discover services.

A service of type _erlang._tcp will be advertised by default. The registered services can be viewed using avahi-browse as follows:

avahi-browse _erlang._tcp

Or on OSX:

dns-sd -B _erlang._tcp

mDNS will automatically advertise its presence and discover other _erlang._tcp nodes. Whether a node will advertise or discover other nodes is controlled by the MDNS_CAN_ADVERTISE and MDNS_CAN_DISCOVER boolean environment variables.

mDNS will also automatically form an Erlang/OTP mesh network of nodes if the boolean variable MDNS_CAN_MESH is true, providing they all share the same MDNS_ENVIRONMENT (default: "dev") and have the same distribution cookie.

For example, starting mDNS on two separate machines (in this example dev001.local and dev002.local) reachable on the same local network:

On dev001.local:

MDNS_CAN_MESH=true make shell

and on dev002.local:

MDNS_CAN_MESH=true make shell

After a short period both machines will have automatically formed a mesh network:

(mdns@dev001.local)2> nodes().
['mdns@dev002.local']
(mdns@dev002.local)2> nodes().
['mdns@dev001.local']

The following variables are used to control the operation of mDNS:

application nameenvironment variabledefault
can_advertiseMDNS_CAN_ADVERTISEtrue
can_discoverMDNS_CAN_DISCOVERtrue
can_meshMDNS_CAN_MESHfalse
environmentMDNS_ENVIRONMENTdev
multicast_addressMDNS_MULTICAST_ADDRESS224.0.0.251
udp_portMDNS_UDP_PORT5353
domainMDNS_DOMAIN.local
serviceMDNS_SERVICE_erlang._tcp
ttlMDNS_TTL120

mDNS uses gproc's pub/sub pattern. Consumers can subscribe to mDNS advertisements via mdns:subscribe(advertisement). The map accompanying the advertisement has the following structure:

KeyDescription
hostThe hostname of the advertised node
nodeThe node name of the advertised node
portThe advertised distribution protocol port
envThe environment of this node

Only nodes that share the same environment can be automatically meshed together.