def encodedecode(pkt_size, key): pkt = Packet() typ = PacketType.APP if key else PacketType.CLIENT_HELLO typ = PacketType.APP pkt.msg = os.urandom(pkt_size) pkt.hdr = PacketHeader.create(False, 0, typ, SeqNum(1), SeqNum(1), 0) pkt.hdr.length = len(pkt.msg) pkt.hdr.count = 1 datagram = pkt.to_bytes(key) hdr = PacketHeader.from_bytes(True, datagram) pkt = Packet.from_bytes(hdr, key, datagram)
def test_conn_receive_datagram_1(self): key = b"0" * 16 hdr = PacketHeader.create(True, 0, PacketType.APP, SeqNum(1), SeqNum(1), 0) msgs = [ PendingMessage(SeqNum(1), PacketType.APP, b"hello world1", None, 0) ] pkt = Packet.create(hdr, msgs) datagram = pkt.to_bytes(key) conn = ConnectionBase(False, None) conn.session_key_bytes = key conn._recv_datagram(PacketHeader.from_bytes(False, datagram), datagram) self.assertEqual(SeqNum(1), conn.bitfield_pkt.current_seqnum) self.assertEqual(1, len(conn.incoming_messages)) self.assertEqual(msgs[0].payload, conn.incoming_messages[0][1])