コード例 #1
0
ファイル: status_log.py プロジェクト: CSeanXu/bxgateway
def initialize(use_ext: bool, src_ver: str, ip_address: str, continent: str,
               country: str, update_required: bool, account_id: Optional[str],
               quota_level: Optional[int]) -> Diagnostics:
    current_time = _get_current_time()
    summary = Summary(
        gateway_status=GatewayStatus.OFFLINE,
        ip_address=ip_address,
        continent=continent,
        country=country,
        update_required=update_required,
        account_info=summary_status.gateway_status_get_account_info(
            account_id),
        quota_level=summary_status.gateway_status_get_quota_level(quota_level),
    )
    assert summary.gateway_status is not None
    # pyre-fixme[16]: `Optional` has no attribute `value`.
    gateway_status.state(summary.gateway_status.value)
    environment = Environment(_get_installation_type(), OS_VERSION,
                              platform.python_version(), sys.executable)
    network = Network([], [], [], [])
    analysis = Analysis(current_time, _get_startup_param(), src_ver,
                        _check_extensions_validity(use_ext, src_ver),
                        environment, network, _get_installed_python_modules())
    diagnostics = Diagnostics(summary, analysis)

    _save_status_to_file(diagnostics)
    return diagnostics
コード例 #2
0
ファイル: test_status_log.py プロジェクト: mxito3/bxgateway
 def test_on_network_update_connection(self):
     new_desc3 = "1.1.1.1 80"
     new_ip3 = new_desc3.split()[0]
     new_port3 = new_desc3.split()[1]
     new_fileno3 = "10"
     self._add_connections()
     update(self.conn_pool, True, self.source_version, self.ip_address,
            self.continent, self.country, False, self.account_id,
            self.quota_level)
     summary_loaded, _, _, network_loaded = self._load_status_file()
     network_loaded.blockchain_nodes.clear()
     network_loaded.add_connection(ConnectionType.BLOCKCHAIN_NODE,
                                   new_desc3, new_fileno3)
     blockchain_node_loaded = network_loaded.blockchain_nodes[0]
     self.assertEqual(
         summary_loaded,
         network_loaded.get_summary(self.ip_address, self.continent,
                                    self.country, False, self.account_id,
                                    self.quota_level))
     self.assertEqual(summary_loaded.gateway_status, GatewayStatus.ONLINE)
     self.assertEqual(summary_loaded.account_info,
                      summary.gateway_status_get_account_info(None))
     self.assertEqual(
         summary_loaded.quota_level,
         summary.gateway_status_get_quota_level(self.quota_level))
     self.assertEqual(summary_loaded.blockchain_node_connection_state,
                      ConnectionState.ESTABLISHED)
     self.assertEqual(blockchain_node_loaded.ip_address, new_ip3)
     self.assertEqual(blockchain_node_loaded.port, new_port3)
     self.assertEqual(blockchain_node_loaded.fileno, new_fileno3)
コード例 #3
0
    def test_remove_blockchain_connection_and_add_new(self):
        self._add_connections()

        new_desc6 = "1.1.1.1 80"
        new_ip6 = new_desc6.split()[0]
        new_port6 = new_desc6.split()[1]
        new_fileno6 = "10"
        new_node6 = MockNode(helpers.get_common_opts(1004, external_ip="214.215.216.217"))
        new_conn6 = MockConnection(
            MockSocketConnection(new_fileno6, new_node6, ip_address=new_ip6, port=int(new_port6)), new_node6
        )
        self.conn_pool.delete(self.conn3)
        self.blockchain_peers.add(BlockchainPeerInfo(new_ip6, int(new_port6)))
        self.conn_pool.add(int(new_fileno6), new_ip6, int(new_port6), new_conn6)

        update(self.conn_pool, True, self.source_version, self.ip_address, self.continent, self.country, False,
               self.blockchain_peers, self.account_id, self.quota_level)
        summary_loaded, _, _, network_loaded = self._load_status_file()
        self.assertEqual(summary_loaded,
                         network_loaded.get_summary(self.ip_address, self.continent, self.country,
                                                    False, self.account_id, self.quota_level))
        self.assertEqual(summary_loaded.gateway_status, GatewayStatus.WITH_ERRORS)
        self.assertEqual(summary_loaded.account_info, summary.gateway_status_get_account_info(None))
        self.assertEqual(summary_loaded.quota_level, summary.gateway_status_get_quota_level(self.quota_level))
        self.assertEqual(
            summary_loaded.blockchain_node_connection_states,
            {
                f"{new_ip6} {new_port6}": ConnectionState.ESTABLISHED,
                f"{self.ip3} {self.port3}": ConnectionState.DISCONNECTED,
                f"{self.ip5} {self.port5}": ConnectionState.ESTABLISHED,
            }
        )
コード例 #4
0
 def test_on_network_update_connection(self):
     new_desc4 = "1.1.1.1 80"
     new_ip4 = new_desc4.split()[0]
     new_port4 = new_desc4.split()[1]
     new_fileno4 = "10"
     self._add_connections()
     update(self.conn_pool, True, self.source_version, self.ip_address, self.continent, self.country, False,
            self.blockchain_peers, self.account_id, self.quota_level)
     summary_loaded, _, _, network_loaded = self._load_status_file()
     network_loaded.remote_blockchain_nodes.clear()
     network_loaded.add_connection(ConnectionType.REMOTE_BLOCKCHAIN_NODE, new_desc4, new_fileno4)
     remote_blockchain_node_loaded = network_loaded.remote_blockchain_nodes[0]
     self.assertEqual(summary_loaded,
                      network_loaded.get_summary(self.ip_address, self.continent, self.country,
                                                 False, self.account_id, self.quota_level))
     self.assertEqual(summary_loaded.gateway_status, GatewayStatus.ONLINE)
     self.assertEqual(summary_loaded.account_info, summary.gateway_status_get_account_info(None))
     self.assertEqual(summary_loaded.quota_level, summary.gateway_status_get_quota_level(self.quota_level))
     self.assertEqual(
         summary_loaded.blockchain_node_connection_states,
         {
             f"{self.ip3} {self.port3}": ConnectionState.ESTABLISHED,
             f"{self.ip5} {self.port5}": ConnectionState.ESTABLISHED,
         }
     )
     self.assertEqual(remote_blockchain_node_loaded.ip_address, new_ip4)
     self.assertEqual(remote_blockchain_node_loaded.port, new_port4)
     self.assertEqual(remote_blockchain_node_loaded.fileno, new_fileno4)
コード例 #5
0
 def test_on_update_one_connection(self):
     self.conn_pool.add(self.fileno1, self.ip1, self.port1, self.conn1)
     update(self.conn_pool, False, self.source_version, self.ip_address, self.continent, self.country, True,
            self.blockchain_peers, self.account_id, self.quota_level)
     summary_loaded, analysis_loaded, environment_loaded, network_loaded = self._load_status_file()
     block_relay_loaded = network_loaded.block_relays[0]
     self.assertEqual(0, len(network_loaded.transaction_relays))
     self.assertEqual(1, len(network_loaded.blockchain_nodes))
     self.assertEqual(0, len(network_loaded.remote_blockchain_nodes))
     self.assertEqual(summary_loaded,
                      network_loaded.get_summary(self.ip_address, self.continent, self.country, True,
                                                 self.account_id, self.quota_level))
     self.assertEqual(summary_loaded.gateway_status, GatewayStatus.WITH_ERRORS)
     self.assertEqual(summary_loaded.account_info, summary.gateway_status_get_account_info(None))
     self.assertEqual(summary_loaded.block_relay_connection_state, ConnectionState.ESTABLISHED)
     self.assertEqual(summary_loaded.transaction_relay_connection_state, ConnectionState.DISCONNECTED)
     self.assertEqual(
         summary_loaded.blockchain_node_connection_states,
         {f"{self.ip3} {self.port3}": ConnectionState.DISCONNECTED}
     )
     self.assertEqual(summary_loaded.remote_blockchain_node_connection_state, ConnectionState.DISCONNECTED)
     self.assertEqual(summary_loaded.quota_level, summary.gateway_status_get_quota_level(self.quota_level))
     self.assertEqual(summary_loaded.update_required, True)
     self.assertEqual(block_relay_loaded.ip_address, self.ip1)
     self.assertEqual(block_relay_loaded.port, str(self.port1))
     self.assertEqual(block_relay_loaded.fileno, str(self.fileno1))
コード例 #6
0
ファイル: test_status_log.py プロジェクト: mxito3/bxgateway
 def test_on_update_all_connections(self):
     self._add_connections()
     update(self.conn_pool, False, self.source_version, self.ip_address,
            self.continent, self.country, False, self.account_id,
            self.quota_level)
     summary_loaded, analysis_loaded, environment_loaded, network_loaded = self._load_status_file(
     )
     block_relay_loaded = network_loaded.block_relays[0]
     transaction_relay_loaded = network_loaded.transaction_relays[0]
     blockchain_node_loaded = network_loaded.blockchain_nodes[0]
     remote_blockchain_node_loaded = network_loaded.remote_blockchain_nodes[
         0]
     self.assertEqual(
         summary_loaded,
         network_loaded.get_summary(self.ip_address, self.continent,
                                    self.country, False, self.account_id,
                                    self.quota_level))
     self.assertEqual(summary_loaded.gateway_status, GatewayStatus.ONLINE)
     self.assertEqual(summary_loaded.account_info,
                      summary.gateway_status_get_account_info(None))
     self.assertEqual(summary_loaded.block_relay_connection_state,
                      ConnectionState.ESTABLISHED)
     self.assertEqual(summary_loaded.transaction_relay_connection_state,
                      ConnectionState.ESTABLISHED)
     self.assertEqual(summary_loaded.blockchain_node_connection_state,
                      ConnectionState.ESTABLISHED)
     self.assertEqual(
         summary_loaded.remote_blockchain_node_connection_state,
         ConnectionState.ESTABLISHED)
     self.assertEqual(
         summary_loaded.quota_level,
         summary.gateway_status_get_quota_level(self.quota_level))
     self.assertEqual(block_relay_loaded.ip_address, self.ip1)
     self.assertEqual(block_relay_loaded.port, str(self.port1))
     self.assertEqual(block_relay_loaded.fileno, str(self.fileno1))
     self.assertEqual(transaction_relay_loaded.ip_address, self.ip2)
     self.assertEqual(transaction_relay_loaded.port, str(self.port2))
     self.assertEqual(transaction_relay_loaded.fileno, str(self.fileno2))
     self.assertEqual(blockchain_node_loaded.ip_address, self.ip3)
     self.assertEqual(blockchain_node_loaded.port, str(self.port3))
     self.assertEqual(blockchain_node_loaded.fileno, str(self.fileno3))
     self.assertEqual(remote_blockchain_node_loaded.ip_address, self.ip4)
     self.assertEqual(remote_blockchain_node_loaded.port, str(self.port4))
     self.assertEqual(remote_blockchain_node_loaded.fileno,
                      str(self.fileno4))
コード例 #7
0
ファイル: network.py プロジェクト: CSeanXu/bxgateway
    def get_summary(self, ip_address: str, continent: str, country: str,
                    update_required: bool, account_id: Optional[str],
                    quota_level: Optional[int]) -> Summary:
        block_relay_connections_state = _connections_states_info(
            self.block_relays)
        transaction_relay_connections_state = _connections_states_info(
            self.transaction_relays)
        blockchain_node_connections_state = _blockchain_connections_state_info(
            self.blockchain_nodes)
        remote_blockchain_node_connections_state = _connections_states_info(
            self.remote_blockchain_nodes)
        gateway_status = self._get_gateway_status()

        return Summary(gateway_status,
                       summary.gateway_status_get_account_info(account_id),
                       block_relay_connections_state,
                       transaction_relay_connections_state,
                       blockchain_node_connections_state,
                       remote_blockchain_node_connections_state, ip_address,
                       continent, country, update_required,
                       summary.gateway_status_get_quota_level(quota_level))