Esempio n. 1
0
 async def _monitor_node_height(self) -> None:
     now = datetime.utcnow().timestamp()
     for node in self.nodes:
         if now - node.best_height_last_update > self.MAX_HEIGHT_UPDATE_DURATION:
             logger.debug(
                 f"Disconnecting node {node.nodeid} Reason: max height update threshold exceeded."
             )
             asyncio.create_task(
                 node.disconnect(
                     reason=payloads.DisconnectReason.POOR_PERFORMANCE))
         else:
             logger.debug(
                 f"Asking node {node.nodeid_human} to send us a height update (PING)"
             )
             # Request latest height from node
             if settings.database:
                 height = max(0, blockchain.Blockchain().height)
             else:
                 height = 0
             m = message.Message(
                 msg_type=message.MessageType.PING,
                 payload=payloads.PingPayload(height=height))
             task = asyncio.create_task(node.send_message(m))
             self.tasks.append(task)
             task.add_done_callback(lambda fut: self.tasks.remove(fut))
Esempio n. 2
0
    def increase_node_timeout_count(self, nodeid: int) -> None:
        """
        Utility function to increase a node's `timeout_count` param by 1 and disconnect the node if it exceeds the
        threshold set by :attr:`~neo3.network.convenience.nodemanager.MAX_NODE_ERROR_COUNT`.

        Args:
            nodeid (:attr:`~neo3.network.node.NeoNode.nodeid`): the specific node to update.
        """
        node = self.get_node_by_nodeid(nodeid)
        if node:
            node.nodeweight.timeout_count += 1

            if node.nodeweight.timeout_count > self.MAX_NODE_TIMEOUT_COUNT:
                logger.debug(f"Disconnecting node {node.nodeid_human} Reason: max timeout count threshold exceeded.")
                asyncio.create_task(node.disconnect(reason=payloads.DisconnectReason.POOR_PERFORMANCE))