Пример #1
0
 def test_ping_request_datagram(self):
     self.assertRaises(ValueError, RequestDatagram.make_ping, b'1' * 48, b'1' * 21)
     self.assertRaises(ValueError, RequestDatagram.make_ping, b'1' * 47, b'1' * 20)
     self.assertEqual(20, len(RequestDatagram.make_ping(b'1' * 48).rpc_id))
     serialized = RequestDatagram.make_ping(b'1' * 48, b'1' * 20).bencode()
     decoded = decode_datagram(serialized)
     self.assertEqual(decoded.packet_type, REQUEST_TYPE)
     self.assertEqual(decoded.rpc_id, b'1' * 20)
     self.assertEqual(decoded.node_id, b'1' * 48)
     self.assertEqual(decoded.method, b'ping')
     self.assertListEqual(decoded.args, [{b'protocolVersion': 1}])
Пример #2
0
 async def ping(self) -> bytes:
     """
     :return: b'pong'
     """
     response = await self.protocol.send_request(
         self.peer, RequestDatagram.make_ping(self.protocol.node_id))
     return response.response