Nbpm (nbpm v0.3.1)
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
function, and the resulting hash is used as the port number. The port range is from 1024 to 65535.:erlang.phash2
is a portable hash function that gives the same hash for the same Erlang term regardless of machine architecture and ERTS version, thia ensures consistent name-to-port mappings across different machine architectures and ERTS versions.
To determine to which port your node name translates, you can use the
mix nbpm.get_port_number
(Mix.Tasks.Nbpm.GetPortNumber
) task helper.
Compatibility
Nbpm is compatible with Mix releases.
When you execute "_build/prod/rel/your_app/bin/your_app remote"
,
Mix.Release
script 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"
,
Mix.Release
script generates node names
as "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.
References
Summary
Functions
Translates node name to port number.
Functions
address_please(name, host, address_family)
available_ports_count()
listen_port_please(name, host)
name_to_port(name)
Translates node name to port number.