Exemplo n.º 1
0
 def test_create_message_failure(self):
     message = HelloMessage(protocol_version=1, network_num=2)
     with self.assertRaises(PayloadLenError):
         bloxroute_message_factory.create_message_from_buffer(
             message.rawbytes()[:-1])
         bloxroute_message_factory.create_message_from_buffer(
             message.rawbytes()[:-1])
 def compare_hello_old_to_current(
     self,
     converted_current_message: HelloMessage,
     original_current_message: HelloMessage,
 ):
     self.assertEqual(
         original_current_message.rawbytes(),
         converted_current_message.rawbytes(),
     )
Exemplo n.º 3
0
    def test_message_preview_incomplete(self):
        message = HelloMessage(protocol_version=1, network_num=2)
        is_full_message, command, payload_length = bloxroute_message_factory.get_message_header_preview_from_input_buffer(
            create_input_buffer_with_bytes(message.rawbytes()[:-1]))
        self.assertFalse(is_full_message)
        self.assertEqual(b"hello", command)
        self.assertEqual(
            VersionMessage.VERSION_MESSAGE_LENGTH + UL_INT_SIZE_IN_BYTES +
            NODE_ID_SIZE_IN_BYTES - UL_INT_SIZE_IN_BYTES, payload_length)

        is_full_message, command, payload_length = bloxroute_message_factory.get_message_header_preview_from_input_buffer(
            create_input_buffer_with_bytes(message.rawbytes()[:1]))
        self.assertFalse(is_full_message)
        self.assertIsNone(command)
        self.assertIsNone(payload_length)
Exemplo n.º 4
0
    def test_ping_pong(self):
        hello_msg = HelloMessage(protocol_version=protocol_version.PROTOCOL_VERSION, network_num=1)
        self.connection.add_received_bytes(hello_msg.rawbytes())
        self.connection.process_message()

        hello_msg_bytes = self.connection.get_bytes_to_send()
        self.assertTrue(len(hello_msg_bytes) > 0)
        self.connection.advance_sent_bytes(len(hello_msg_bytes))

        ack_msg = AckMessage()
        self.connection.add_received_bytes(ack_msg.rawbytes())
        self.connection.process_message()

        ack_msg_bytes = self.connection.get_bytes_to_send()
        self.assertTrue(len(ack_msg_bytes) > 0)
        self.connection.advance_sent_bytes(len(ack_msg_bytes))

        ping_msg = PingMessage(nonce=12345)
        self.connection.add_received_bytes(ping_msg.rawbytes())
        self.connection.process_message()

        pong_msg_bytes = self.connection.get_bytes_to_send()
        self.assertTrue(len(pong_msg_bytes) > 0)

        msg_type, payload_len = AbstractBloxrouteMessage.unpack(pong_msg_bytes[:AbstractBloxrouteMessage.HEADER_LENGTH])
        self.assertEqual(BloxrouteMessageType.PONG, msg_type)
        self.connection.advance_sent_bytes(len(pong_msg_bytes))

        time.time = MagicMock(return_value=time.time() + constants.PING_INTERVAL_S)
        self.node.alarm_queue.fire_alarms()

        ping_msg_bytes = self.connection.get_bytes_to_send()
        self.assertTrue(len(ping_msg_bytes) > 0)
        msg_type, payload_len = AbstractBloxrouteMessage.unpack(ping_msg_bytes[:AbstractBloxrouteMessage.HEADER_LENGTH])
        self.assertEqual(BloxrouteMessageType.PING, msg_type)
Exemplo n.º 5
0
    def _test_version_over_v4(self, version):
        hello_msg = HelloMessage(protocol_version=version, network_num=1)
        input_buffer = InputBuffer()
        input_buffer.add_bytes(hello_msg.rawbytes())

        self.assertEqual(
            version,
            self.version_manager.get_connection_protocol_version(input_buffer))
    def test_get_connection_protocol_version__v4(self):
        hello_msg = HelloMessage(protocol_version=4,
                                 network_num=constants.DEFAULT_NETWORK_NUM)
        input_buffer = InputBuffer()
        input_buffer.add_bytes(hello_msg.rawbytes())

        self.assertEqual(
            4,
            self.version_manager.get_connection_protocol_version(input_buffer))