epmd

An Erlang Port Mapper Daemon (EPMD) server on asyncio.

Epmd is the server; EpmdProtocol handles one client connection.

class epmd.Epmd(host=None, port=4369, *, addresses=None, packet_timeout=60.0, relaxed_command_check=False, max_connections=1024)

Bases: object

Listens on the EPMD protocol port and handles discovery of running Erlang nodes on this host.

EPMD_DEFAULT_PORT = 4369
DEFAULT_PACKET_TIMEOUT = 60.0
DEFAULT_MAX_CONNECTIONS = 1024
async start()

Start listening and return once the socket listens.

Afterwards self.port is the bound port (useful with port=0; every address then gets the port the first one got).

Raises:
  • OSError – the port is in use, typically by another EPMD, or a required address cannot be bound.

  • EpmdError – an entry of addresses is not an IP address, or there are more than 13.

async stop()

Stop listening and close every client connection. Registered nodes are forgotten. Calling it again, or before start, is safe.

async start_server()

Start listening and serve until cancelled or stopped (stop() or a KILL_REQ); then stop.

Raises:

OSError – the port is in use, typically by another EPMD.

register(node_name, data)

Attempts to register a node. Returns True if successful, False if the node is already registered.

Sets data.cr_counter: one more than at the name’s previous registration if it is remembered, else a random start.

unregister(node_name)

Called from EpmdProtocol when a client disconnects or when a STOP command arrives (documentation claims this is not used but still implemented). Removes the node from the list of nodes.

class epmd.EpmdProtocol(parent)

Bases: Protocol

One client connection of the EPMD server.

As in OTP’s epmd, a connection carries exactly one request. It is closed after the reply, except after a successful ALIVE2_REQ: then it stays open, and the node is unregistered when it closes or sends anything more. Malformed requests close the connection without a reply.

EPMD_ALIVE2_REQ = 120
EPMD_PORT2_REQ = 122
EPMD_PORT_PLEASE2_REQ = 122
EPMD_NAMES_REQ = 110
EPMD_KILL_REQ = 107
EPMD_DUMP_REQ = 100
EPMD_STOP_REQ = 115
ALIVE_NORMAL_NODE_TYPE = 77
ALIVE_HIDDEN_NODE_TYPE = 72
connection_lost(exc)

The client closed the connection: a node registered on it is unregistered.

connection_made(transport)

Connection has been accepted and established (callback).

data_received(data)

Collect the client’s bytes; answer once the one request of the connection is complete.

on_packet(packet)

Answer one request body (without the length prefix).

Raises:

EpmdRequestError – the request is malformed.

Modules

epmd_node

A node as the server knows it.

epmd_proto

One client connection of the server.

epmd_proto_packets

EPMD requests and replies as pure functions over bytes.

epmd_server

The EPMD server and its table of registered nodes.

errors

Exceptions of the epmd package.