def _pack_pid(val) -> bytes: data = bytes([TAG_PID_EXT]) + \ term_to_binary_2(val.node_) + \ util.to_u32(val.id_) + \ util.to_u32(val.serial_) + \ bytes([val.creation_]) return data
def _send_name(self): """ Create and send first welcome packet. """ pkt = b'n' + \ bytes([dist_protocol.DIST_VSN, dist_protocol.DIST_VSN]) + \ util.to_u32(self.node_.node_opts_.dflags_) + \ bytes(str(self.node_.name_), "latin-1") LOG("Dist-out: Send_name", pkt) self._send_packet2(pkt)
def _pack_tuple(val): if len(val) < 256: data = bytes([TAG_SMALL_TUPLE_EXT, len(val)]) else: data = bytes([TAG_LARGE_TUPLE_EXT]) + util.to_u32(len(val)) for item in val: data += term_to_binary_2(item) return data
def _pack_list(lst, tail): if len(lst) == 0: return bytes([TAG_NIL_EXT]) data = b'' for item in lst: data += term_to_binary_2(item) tail = term_to_binary_2(tail) return bytes([TAG_LIST_EXT]) + util.to_u32(len(lst)) + data + tail
def _send_challenge_reply(self, challenge: int): digest = self.make_digest(challenge, self.node_.get_cookie()) self.my_challenge_ = int(random.random() * 0x7fffffff) pkt = b'r' + util.to_u32(self.my_challenge_) + digest return self._send_packet2(pkt)
def _pack_binary(data, last_byte_bits): if last_byte_bits == 8: return bytes([TAG_BINARY_EXT]) + util.to_u32(len(data)) + data return bytes([TAG_BIT_BINARY_EXT]) + util.to_u32(len(data)) + \ bytes([last_byte_bits]) + data
def _pack_dict(val: dict) -> bytes: data = bytes([TAG_MAP_EXT]) + util.to_u32(len(val)) for k in val.keys(): data += term_to_binary_2(k) data += term_to_binary_2(val[k]) return data