def msg_get_headers(self, msg: GetHeadersOntMessage):
     block_queuing_service = self.node.block_queueing_service_manager.get_block_queuing_service(self.connection)
     send_successful = False
     if block_queuing_service is not None:
         send_successful = block_queuing_service.try_send_header_to_node(msg.hash_stop())
     if not send_successful:
         self.msg_proxy_request(msg, self.connection)
    def test_peek_message_success_all_types(self):
        self.get_message_preview_successfully(self.VERSION_ONT_MESSAGE,
                                              VersionOntMessage.MESSAGE_TYPE,
                                              83)
        self.get_message_preview_successfully(
            VerAckOntMessage(self.MAGIC, True), VerAckOntMessage.MESSAGE_TYPE,
            1)
        self.get_message_preview_successfully(PingOntMessage(self.MAGIC),
                                              PingOntMessage.MESSAGE_TYPE, 8)
        self.get_message_preview_successfully(PongOntMessage(self.MAGIC, 123),
                                              PongOntMessage.MESSAGE_TYPE, 8)
        self.get_message_preview_successfully(GetAddrOntMessage(self.MAGIC),
                                              GetAddrOntMessage.MESSAGE_TYPE,
                                              0)
        self.get_message_preview_successfully(
            AddrOntMessage(
                self.MAGIC,
                [(int(time.time()), 123, "127.0.0.1", 20300, 20200, 1234)]),
            AddrOntMessage.MESSAGE_TYPE, 52)
        self.get_message_preview_successfully(
            OntConsensusMessage(self.MAGIC, self.VERSION, bytes(20)),
            OntConsensusMessage.MESSAGE_TYPE, 24)

        self.get_message_preview_successfully(
            InvOntMessage(self.MAGIC, InventoryOntType.MSG_TX,
                          [self.HASH, self.HASH]), InvOntMessage.MESSAGE_TYPE,
            69)
        self.get_message_preview_successfully(
            GetDataOntMessage(self.MAGIC, 1, self.HASH),
            GetDataOntMessage.MESSAGE_TYPE, 33)
        self.get_message_preview_successfully(
            GetHeadersOntMessage(self.MAGIC, 1, self.HASH, self.HASH),
            GetHeadersOntMessage.MESSAGE_TYPE, 65)
        self.get_message_preview_successfully(
            GetBlocksOntMessage(self.MAGIC, 1, self.HASH, self.HASH),
            GetBlocksOntMessage.MESSAGE_TYPE, 65)
        self.get_message_preview_successfully(
            TxOntMessage(self.MAGIC, self.VERSION, bytes(20)),
            TxOntMessage.MESSAGE_TYPE, 21)
        self.get_message_preview_successfully(
            BlockOntMessage(self.MAGIC, self.VERSION, self.HASH, self.HASH,
                            self.HASH, 0, 0, 0, bytes(10), bytes(20),
                            [bytes(33)] * 5, [bytes(2)] * 3, [bytes(32)] * 5,
                            self.HASH), BlockOntMessage.MESSAGE_TYPE, 524)
        self.get_message_preview_successfully(
            HeadersOntMessage(self.MAGIC, [bytes(1)] * 2),
            HeadersOntMessage.MESSAGE_TYPE, 6)
        self.get_message_preview_successfully(
            NotFoundOntMessage(self.MAGIC, self.HASH),
            NotFoundOntMessage.MESSAGE_TYPE, 32)
 def test_parse_message_success_all_types(self):
     self.create_message_successfully(self.VERSION_ONT_MESSAGE,
                                      VersionOntMessage)
     self.create_message_successfully(VerAckOntMessage(self.MAGIC, False),
                                      VerAckOntMessage)
     self.create_message_successfully(PingOntMessage(self.MAGIC),
                                      PingOntMessage)
     self.create_message_successfully(PongOntMessage(self.MAGIC, 123),
                                      PongOntMessage)
     self.create_message_successfully(GetAddrOntMessage(self.MAGIC),
                                      GetAddrOntMessage)
     self.create_message_successfully(
         AddrOntMessage(
             self.MAGIC,
             [(int(time.time()), 123, "127.0.0.1", 20300, 20200, 1234)]),
         AddrOntMessage)
     self.create_message_successfully(
         OntConsensusMessage(self.MAGIC, self.VERSION, bytes(20)),
         OntConsensusMessage)
     self.create_message_successfully(
         InvOntMessage(self.MAGIC, InventoryOntType.MSG_TX,
                       [self.HASH, self.HASH]), InvOntMessage)
     self.create_message_successfully(
         GetDataOntMessage(self.MAGIC, 1, self.HASH), GetDataOntMessage)
     self.create_message_successfully(
         GetHeadersOntMessage(self.MAGIC, 1, self.HASH, self.HASH),
         GetHeadersOntMessage)
     self.create_message_successfully(
         GetBlocksOntMessage(self.MAGIC, 1, self.HASH, self.HASH),
         GetBlocksOntMessage)
     self.create_message_successfully(
         TxOntMessage(self.MAGIC, self.VERSION, bytes(20)), TxOntMessage)
     self.create_message_successfully(
         BlockOntMessage(self.MAGIC, self.VERSION, self.HASH, self.HASH,
                         self.HASH, 0, 0, 0, bytes(10), bytes(20),
                         [bytes(33)] * 5, [bytes(2)] * 3, [bytes(32)] * 5,
                         self.HASH), BlockOntMessage)
     self.create_message_successfully(
         HeadersOntMessage(self.MAGIC, [bytes(1)] * 2), HeadersOntMessage)
     self.create_message_successfully(
         NotFoundOntMessage(self.MAGIC, self.HASH), NotFoundOntMessage)
 def msg_pong(self, msg: PongOntMessage):
     if msg.height() > self.node.current_block_height:
         reply = GetHeadersOntMessage(self.magic, 1, NULL_ONT_BLOCK_HASH, self.node.current_block_hash)
         self.connection.enqueue_msg(reply)
 def msg_get_headers(self, msg: GetHeadersOntMessage):
     send_successful = self.node.block_queuing_service.try_send_header_to_node(msg.hash_stop())
     if not send_successful:
         self.msg_proxy_request(msg)