erlang/otp — pull request #121 by saleyn (2013-11-01 04:05:00+00:00)
Title: Add net_kernel and epmd support for multiple simultaneous distributed transport protocols

This patch addresses the limitation of registering only one Erlang
distributed transport with Erlang Port Mapping Daemon, and therefore
enabling a node to listen for distributed node connections on multiple
port using different protocols, and selectively choose the protocol
to use when connecting to a node from different secure and unsecure
networks.

The legacy implementation of Erlang distributed transport allows to
start a node with more than one transport via the
"-proto_dist mod1 mod2 ..." command-line option. But epmd didn't support
registration of multiple protocols. And net_kernel doesn't implement a
way of figuring out which transports are supported on a remote node and
doesn't allow to select a desired transport protocol of choice to use it
for connecting to the node.

The current patch extends epmd by having it store the name of the protocol
handling module passed to the -proto_dist startup option during node
registration. Multiple registrations are allowed, and they can be
registered to different ports. This way a node can start distributed
transport listeners (e.g. TCP, SSL, UDS), and register them with epmd.

When another node does epmd lookup in order to connect to node X, it
now gives to epmd a list of transport names it supports (i.e. the ones
that were passed to it via -proto_dist option at startup) together with
the node name it queries. The epmd filters out only the transports
supported by the calling client node, and gives back only those along
with the corresponding port numbers.

net_kernel now supports a new command-line option
"-proto_dist_mf Mod Fun" which is a user-define callback function that
can be used to resolve which transport protocol to use to connect to
a node. This function is called after the epmd query returned a list
of protocols supported by the target node. By default the first
transport in the list is used. An example implementation of this
function is included in
`lib/kernel/examples/uds_dist/src/dist_selector.erl`.

In order to support backward compatibility the EPMD protocol was
extended with new commands documented in erl_dist_rotocol.xml. Old
nodes can query the new EPMD version, but new nodes (using this patch)
require new version of EPMD.