pyrlang.dist_proto.distribution

Distribution class is a separate running Task which owns its TCP connection.

class pyrlang.dist_proto.distribution.ErlangDistribution(node_name, hidden=False, use_epmd=True, dist_port=0, dynamic_host=None)

Bases: object

Implements network part of the EPMD registration and Erlang dist_proto protocol.

node_name_

Node name, a string.

dynamic_

The node got, or will get, its name from another node.

name_pending_

The node has no name yet.

host_

The host part of the node name.

naming_lock_

One connection setup at a time while the node has no name.

creation_

Creation of this incarnation of the node, part of every pid and reference it makes and of its handshake messages. Chosen here, before the first process exists, and never 0; the creation EPMD hands out later is not used (as for erl_interface nodes).

in_port_: int | None
in_srv_: AbstractServer | None
serve_task_: Task[None] | None

Runs run_dist_server; cancelled when the node stops.

connecting_: dict[str, Task[bool]]

Connection setups this node started, by peer name; everyone who wants that peer awaits the same task.

pending_out_: dict[str, DistClientProtocol]

Outgoing connections whose handshake is not finished, by peer.

superseded_: set[str]

Peers whose own connection to us was preferred over our setup (simultaneous connect).

async start_server()

Start listening for incoming connections.

async start_distribution()

Start listening for other nodes and, unless the node does not use EPMD, register in the local EPMD.

Raises:
async run_dist_server()

Start listening for connections from other nodes.

disconnect_epmd()

Finish EPMD connection, this will remove the node from the list of available nodes on EPMD

destroy()

Stop listening and leave EPMD. Safe to call twice.

async connect_to_node(local_node, remote_node, address=None)

Query EPMD where is the node, connect and run the handshake. Concurrent calls for one node share one connection setup.

Parameters:
  • local_node (str) – name of the local Erlang Node object

  • remote_node (str) – String with node ‘name@ip’

  • address (tuple[str, int] | None) – host and port of the node, if known; EPMD is not asked then

Returns:

True once the connection is established; False if EPMD does not know the node

Raises:
Return type:

bool

accept_pending(peer_name)

Decide what an incoming connection from peer_name is told while this node may be connecting to that peer itself, as net_kernel does for accept_pending.

Returns:

the status to send: ok, ok_simultaneous (our own attempt is dropped) or nok (our attempt goes on, the incoming connection must be closed)

Return type:

str