pyrlang.dist_proto.handshake

The messages of the distribution handshake, version 6 (OTP 23 and newer), as pure functions over bytes: no sockets, no state.

Layouts are from erl_dist_protocol (“Distribution Handshake”) of OTP 29. Each function takes or returns one packet without its 2-byte length prefix. Node names are Latin-1 on the wire, as in dist_util (atom_to_binary(Node, latin1) when sending, list_to_atom of the bytes when receiving): a name with other characters cannot take part in a handshake with OTP. Malformed input raises DistributionError.

pyrlang.dist_proto.handshake.new_challenge()

A 32-bit challenge from the system’s secure random source.

pyrlang.dist_proto.handshake.digest(challenge, cookie)

md5(Cookie ++ integer_to_list(Challenge)) as dist_util:gen_digest computes it: the cookie’s characters are bytes, so it must be Latin-1 (OTP fails with badarg on any other cookie).

pyrlang.dist_proto.handshake.digest_matches(received, challenge, cookie)

Whether received is the digest of challenge; the comparison takes the same time wherever the first difference is.

class pyrlang.dist_proto.handshake.Name(flags, creation, name)

Bases: object

send_name: the initiator introduces itself.

flags: int
creation: int
name: str
class pyrlang.dist_proto.handshake.Status(status)

Bases: object

recv_status/send_status: the acceptor’s verdict, or the initiator’s true/false answer to “alive”.

status: str
class pyrlang.dist_proto.handshake.Named(name, creation)

Bases: object

Status “named:”: the name and creation an acceptor gives to an initiator that asked for them with DFLAG_NAME_ME (dynamic node name, OTP 23).

name: str
creation: int
class pyrlang.dist_proto.handshake.Challenge(flags, challenge, creation, name)

Bases: object

send_challenge: the acceptor introduces itself and challenges the initiator.

flags: int
challenge: int
creation: int
name: str
class pyrlang.dist_proto.handshake.ChallengeReply(challenge, digest)

Bases: object

send_challenge_reply: the initiator’s digest and its own challenge.

challenge: int
digest: bytes
class pyrlang.dist_proto.handshake.ChallengeAck(digest)

Bases: object

send_challenge_ack: the acceptor’s digest of the initiator’s challenge.

digest: bytes
pyrlang.dist_proto.handshake.encode_name(msg)

'N', Flags:64, Creation:32, Nlen:16, Name

pyrlang.dist_proto.handshake.decode_name(data)

The initiator’s name message.

Raises:

DistributionError – malformed

pyrlang.dist_proto.handshake.encode_status(msg)

's', Status

pyrlang.dist_proto.handshake.decode_status(data)

The status text. For named: the fields after the colon are read with decode_named().

pyrlang.dist_proto.handshake.decode_named(data)

's', "named:", Nlen:16, Name, Creation:32: the acceptor’s answer to a name message with DFLAG_NAME_ME (the name is UTF-8, as dist_util:send_status writes it); bytes after it are ignored.

pyrlang.dist_proto.handshake.encode_challenge(msg)

'N', Flags:64, Challenge:32, Creation:32, Nlen:16, Name

pyrlang.dist_proto.handshake.decode_challenge(data)

The acceptor’s challenge message.

Raises:

DistributionError – malformed

pyrlang.dist_proto.handshake.encode_challenge_reply(msg)

'r', Challenge:32, Digest:16 bytes

pyrlang.dist_proto.handshake.decode_challenge_reply(data)

The initiator’s challenge reply.

Raises:

DistributionError – malformed

pyrlang.dist_proto.handshake.encode_challenge_ack(msg)

'a', Digest:16 bytes

pyrlang.dist_proto.handshake.decode_challenge_ack(data)

The acceptor’s challenge ack.

Raises:

DistributionError – malformed