コード例 #1
0
def compare_server(server, best_servers, ping_attempts, valid_protocols, valid_categories):
    supported_protocols = []
    if server['features']['openvpn_udp'] and 'udp' in valid_protocols:
        supported_protocols.append('udp')
    if server['features']['openvpn_tcp'] and 'tcp' in valid_protocols:
        supported_protocols.append('tcp')

    country_code = server['flag'].lower()
    domain = server['domain']
    score, load, latency = get_server_score(server, ping_attempts)

    # The ping benchmark failed, so return fail
    if not latency:
        return False

    for category in server['categories']:
        category_long_name = category['name']
        if category_long_name in valid_categories:
            category_short_name = nordapi.VPN_CATEGORIES[category['name']]

            for protocol in supported_protocols:
                best_score = -1

                if best_servers.get((country_code, category_short_name, protocol)):
                    best_score = best_servers[country_code, category_short_name, protocol]['score']

                if score > best_score:
                    name = nordnm.generate_connection_name(server, protocol)
                    best_servers[country_code, category_short_name, protocol] = {'name': name, 'domain': domain, 'score': score, 'load': load, 'latency': latency}

    return True
コード例 #2
0
def compare_server(server, best_servers, ping_attempts, valid_protocols):
    supported_protocols = []
    if server['features']['openvpn_udp'] and 'udp' in valid_protocols:
        supported_protocols.append('udp')
    if server['features']['openvpn_tcp'] and 'tcp' in valid_protocols:
        supported_protocols.append('tcp')

    country_code = server['flag']
    domain = server['domain']
    score = get_server_score(server, ping_attempts)

    for category in server['categories']:
        category_name = nordapi.VPN_CATEGORIES[category['name']]

        for protocol in supported_protocols:
            best_score = 0

            if best_servers.get((country_code, category_name, protocol)):
                best_score = best_servers[country_code, category_name, protocol]['score']

            if score > best_score:
                name = nordnm.generate_connection_name(server, protocol)
                best_servers[country_code, category_name, protocol] = {'name': name, 'domain': domain, 'score': score}