예제 #1
0
def test_print_map_good(capsys):
    from connord.printer import Printer

    printer = Printer()
    printer.print_map("50.116667", "8.683333")

    captured = capsys.readouterr()

    map_frankfurt = get_stub("de_frankfurt.map")
    assert captured.out == map_frankfurt
예제 #2
0
def test_print_map_location_does_not_exist(capsys):
    from connord.printer import Printer

    printer = Printer()

    printer.print_map("0", "0")

    captured = capsys.readouterr()
    assert not captured.out
    assert not captured.err
예제 #3
0
파일: connect.py 프로젝트: MaelStor/connord
def connect(
    domain,
    countries_,
    areas_,
    features_,
    categories_,
    netflix,
    load_,
    match,
    daemon,
    openvpn,
    protocol,
):
    """High-level function to connect to a openvpn server. Filters servers and
    tries to connect to an openvpn server 'max_retries' times or else raise an
    exception.

    :param domain: list of domains. defaults to one value 'best'.
    :param countries_: list of countries
    :param areas_: list of areas
    :param features_: list of features
    :param categories_: list of categories
    :param netflix: True to filter netflix optimized servers
    :param load_: depending on match, filter by max, min or equal load servers
    :param match: may be 'max', 'min' or 'equal'
    :param daemon: True if openvpn shall run in daemon mode
    :param config_: the path to the openvpn configuration file
    :param openvpn: options to pass-through to openvpn as string
    :param protocol: may be 'udp' or 'tcp'
    :returns: True if running openvpn was successful
    :raises: ConnectError
    """

    if "best" not in domain:
        return connect_to_specific_server(domain, openvpn, daemon, protocol)

    servers_ = servers.get_servers()
    servers_ = filter_servers(
        servers_, netflix, countries_, areas_, features_, categories_, load_, match
    )

    best_servers = filter_best_servers(servers_)
    max_retries = 3
    printer = Printer()
    for i, server in enumerate(best_servers):
        if i == max_retries:
            raise ConnectError("Maximum retries reached.")

        if categories.has_category(server, "Obfuscated Servers"):
            if not printer.yes_no(
                (
                    "WARNING: {} is an obfuscated server.\n"
                    "This may fail if not configured properly.\n"
                    "Are you sure you want to continue?"
                ).format(server["domain"])
            ):
                continue

        if server["ping"] != inf:
            printer.info(
                "Trying to connect to {}: {} ms".format(
                    server["domain"], server["ping"]
                )
            )
            printer.print_map(server["location"]["lat"], server["location"]["long"])
            if run_openvpn(server, openvpn, daemon, protocol):
                return True

            # else give the next server a try
        else:
            raise ConnectError("No server left with a valid ping.")

    raise ConnectError("No server found to establish a connection.")