Nbpm (nbpm v0.2.0)

Main module for Name-Based Port Mapper (Nbpm).

This module provides the core functionality for mapping node names to port numbers in the context of Erlang distribution. It is designed to be used as a custom EPMD (Erlang Port Mapper Daemon) module, which you can specify with the -epmd_module option.

Node name to port number mapping variants

  • Last up to 5 digits: If the node name ends with digits, the last up to 5 digits from the node name are considered as the port number. For example, for a node name "my_node12345" the port number would be 12345.

  • Special Prefixes: If a node name starts with "rem-" or "rpc-," it indicates that the OS should assign a random port. This is for compatibility with Mix.Release.

  • Hash-Based Port: If none of the previous options match, the node name is hashed using the :erlang.phash2/2 function, and the resulting hash is used as the port number. The port range is from 1024 to 65535.

To determine to which port your node name translates, you can use the name_to_port/1 function provided by this module.

Compatibility

Nbpm is compatible with Mix releases. When you execute "_build/prod/rel/your_app/bin/your_app remote", it automatically generates node names in the format "rem-$(rand)-name" or "rem-$(rand)-sname". Similarly, when you execute "_build/prod/rel/your_app/bin/your_app rpc", it generates "rpc-$(rand)-name" or "rpc-$(rand)-sname". Nbpm responds to these names by offering port number 0, indicating that the OS should assign a random port.

Installation

To use Nbpm in your Elixir project, add it as a dependency in your mix.exs file:

def deps do
  [
    {:nbpm, "~> 0.2.0"}
  ]
end

References

Summary

Functions

Link to this function

address_please(name, host, address_family)

Link to this function

available_ports_count()

Link to this function

listen_port_please(name, host)

Link to this function

name_to_port(name)

Translates node name to port number.

Link to this function

names(hostname)

Link to this function

port_please(name, ip)

Link to this function

port_please(name, ip, timeout)

Link to this function

register_node(name, port)

Link to this function

register_node(name, port, driver)