pyrlang.dist_proto.dist_header

Framing of the packets of an established connection, over bytes: pass-through packets, the distribution header with its atom cache, and fragmented messages (“Distribution Header” in erl_ext_dist; the checks follow erts_prepare_dist_ext in OTP 29’s external.c). A peer’s bytes are untrusted: everything wrong raises DistributionError, and the caller closes that connection.

class pyrlang.dist_proto.dist_header.Incoming(headers, fragments, max_fragmented_size=268435456)

Bases: object

The receiving side of one connection: the atom cache the peer fills and the fragmented messages it has started.

clear()

Drop unfinished messages (the connection is gone).

packet(data)

Take one packet (without its length, not a tick).

Returns:

the message it completes, or None for a fragment of a message that is not complete yet

Raises:

DistributionError – malformed, or not what was negotiated

Return type:

Message | None

class pyrlang.dist_proto.dist_header.Message(data, atoms)

Bases: object

One complete control message with its payload, as it arrived.

data: bytes
atoms: tuple[str, ...] | None
pyrlang.dist_proto.dist_header.encode_packets(control, payload, headers, fragments, sequence_id, fragment_size=65536)

The packets (without their length) that carry one control message.

Parameters:
  • control (bytes) – the encoded control message, without the 131 byte

  • payload (bytes | None) – the encoded message or exit reason, without the 131 byte; None if the control message has none

  • headers (bool) – as for Incoming; this node sends headers without atom cache references

  • fragments (bool) – a payload of more than fragment_size bytes is split (DFLAG_FRAGMENTS was negotiated)

  • sequence_id (int) – identifies the message among those being sent, if it is fragmented