def explore_peer(address: str, updates: dict): logger.debug("Peer: %s", address) if address in updates: return try: peer_info = P2PApi(address).get_info() if not is_good_version(peer_info["version"]): logger.debug("Old version: %s", peer_info["version"]) updates[address] = None return peer_info.update(P2PApi(address).get_cumulative_difficulty()) except BurstException: logger.debug("Can't connect to peer: %s", address) updates[address] = None return ip = get_ip_by_domain(address) updates[address] = { "announced_address": peer_info["announcedAddress"], "country_code": get_country_by_ip(ip) if ip else "??", "application": peer_info["application"], "platform": peer_info["platform"], "version": peer_info["version"], "height": peer_info["blockchainHeight"], "cumulative_difficulty": peer_info["cumulativeDifficulty"], "last_online_at": timezone.now(), }
def explore_peer(address: str, updates: dict): logger.debug('Peer: %s', address) if address in updates: return try: peer_info = P2PApi(address).get_info() if not is_good_version(peer_info['version']): logger.debug("Old version: %s", peer_info['version']) updates[address] = None return peer_info.update(P2PApi(address).get_cumulative_difficulty()) except BurstException: logger.debug("Can't connect to peer: %s", address) updates[address] = None return ip = get_ip_by_domain(address) updates[address] = { 'announced_address': peer_info['announcedAddress'], 'country_code': get_country_by_ip(ip) if ip else '??', 'application': peer_info['application'], 'platform': peer_info['platform'], 'version': peer_info['version'], 'height': peer_info['blockchainHeight'], 'cumulative_difficulty': peer_info['cumulativeDifficulty'], 'last_online_at': timezone.now(), }
def explore_node(address: str, updates: dict): logger.debug("Node: %s", address) try: peers = P2PApi(address).get_peers() explore_peer(address, updates) except BurstException: logger.debug("Can't connect to node: %s", address) return if settings.TEST_NET: for peer in peers: explore_peer(peer, updates) else: with ThreadPoolExecutor(max_workers=10) as executor: executor.map(lambda p: explore_peer(p, updates), peers)