예제 #1
0
bool Client::start(bool _server)
{
    if (profile.debug()) {
        if (!headerTest()) {
            QDebug(QtMsgType::QtCriticalMsg) << "Header test failed.";
            return false;
        }
    }

    if (!profile.isValid()) {
        qCritical() << "The profile is invalid. Improper setup?";
        return false;
    }

    controller.reset(new QSS::Controller(profile, !_server, autoBan));

    if (!_server) {
        QSS::Address server(profile.serverAddress(), profile.serverPort());
        server.blockingLookUp();
        tester.reset(new QSS::AddressTester(server.getFirstIP(), server.getPort()));
        QObject::connect(tester.get(), &QSS::AddressTester::connectivityTestFinished,
                [] (bool c) {
            if (c) {
                QDebug(QtMsgType::QtInfoMsg) << "The shadowsocks connection is okay.";
            } else {
                QDebug(QtMsgType::QtWarningMsg)
                        << "Destination is not reachable. "
                           "Please check your network and firewall settings. "
                           "And make sure the profile is correct.";
            }
        });
        QObject::connect(tester.get(), &QSS::AddressTester::testErrorString,
                [] (const QString& error) {
            QDebug(QtMsgType::QtWarningMsg).noquote() << "Connectivity testing error:" << error;
        });
        tester->startConnectivityTest(profile.method(),
                                      profile.password());
    }

    return controller->start();
}
예제 #2
0
bool Client::start(bool _server)
{
    if (profile.debug) {
        if (!headerTest()) {
            QSS::Common::qOut << "Header test failed" << endl;
            return false;
        }
    }

    if (lc) {
        lc->deleteLater();
    }
    lc = new QSS::Controller(!_server, autoBan, this);
    connect (lc, &QSS::Controller::info, this, &Client::logHandler);
    if (profile.debug) {
        connect(lc, &QSS::Controller::debug, this, &Client::logHandler);
    }
    lc->setup(profile);

    if (!_server) {
        QSS::Address server(profile.server, profile.server_port);
        server.blockingLookUp();
        QSS::AddressTester *tester =
                new QSS::AddressTester(server.getFirstIP(),
                                       server.getPort(),
                                       this);
        connect(tester, &QSS::AddressTester::connectivityTestFinished,
                this, &Client::onConnectivityResultArrived);
        connect(tester, &QSS::AddressTester::testErrorString,
                [] (const QString& error) {
            QSS::Common::qOut << "Connectivity testing error: " << error << endl;
        });
        tester->startConnectivityTest(profile.method,
                                      profile.password,
                                      profile.auth);
    }

    return lc->start();
}