diff --git a/retroshare-gui/src/TorControl/TorControlWindow.cpp b/retroshare-gui/src/TorControl/TorControlWindow.cpp index 835c04f9f..7ec3f547f 100644 --- a/retroshare-gui/src/TorControl/TorControlWindow.cpp +++ b/retroshare-gui/src/TorControl/TorControlWindow.cpp @@ -91,28 +91,21 @@ void TorControlDialog::statusChanged() torBootstrapStatus_LB->setText(bootstrapstatus_str) ; - QList hidden_services = mTorManager->control()->hiddenServices(); + QString service_id ; + QString onion_address ; + QHostAddress service_target_address ; + uint16_t service_port ; + uint16_t target_port ; - if(hidden_services.empty()) + if(mTorManager->getHiddenServiceInfo(service_id,onion_address,service_port, service_target_address,target_port)) { - hiddenServiceAddress_LB->setText(QString("[Not ready]")) ; - onionAddress_LB->setText(QString("[Not ready]")) ; + hiddenServiceAddress_LB->setText(QString::number(service_port) + ":" + service_target_address.toString() + ":" + QString::number(target_port)); + onionAddress_LB->setText(onion_address); } else { - QString hiddenservices_str ; - - for(auto it(hidden_services.begin());it!=hidden_services.end();++it) - { - onionAddress_LB->setText((*it)->hostname()); - - for(auto it2((*it)->targets().begin());it2!=(*it)->targets().end();++it2) - { - hiddenServiceAddress_LB->setText(QString::number((*it2).servicePort) + ":" + (*it2).targetAddress.toString() + ":" + QString::number((*it2).targetPort)); - break ; - } - break ; - } + hiddenServiceAddress_LB->setText(QString("[Not ready]")) ; + onionAddress_LB->setText(QString("[Not ready]")) ; } showLog(); diff --git a/retroshare-gui/src/TorControl/TorManager.cpp b/retroshare-gui/src/TorControl/TorManager.cpp index 8db6c205e..a6a6f0ab4 100644 --- a/retroshare-gui/src/TorControl/TorManager.cpp +++ b/retroshare-gui/src/TorControl/TorManager.cpp @@ -372,6 +372,32 @@ void TorManager::start() } } +bool TorManager::getHiddenServiceInfo(QString& service_id,QString& service_onion_address,uint16_t& service_port, QHostAddress& service_target_address,uint16_t& target_port) +{ + QList hidden_services = control()->hiddenServices(); + + if(hidden_services.empty()) + return false ; + + // Only return the first one. + + for(auto it(hidden_services.begin());it!=hidden_services.end();++it) + { + service_onion_address = (*it)->hostname(); + service_id = (*it)->privateKey().torServiceID(); + + for(auto it2((*it)->targets().begin());it2!=(*it)->targets().end();++it2) + { + service_port = (*it2).servicePort ; + service_target_address = (*it2).targetAddress ; + target_port = (*it2).targetPort; + break ; + } + break ; + } + return true ; +} + void TorManagerPrivate::processStateChanged(int state) { std::cerr << Q_FUNC_INFO << "state: " << state << " passwd=\"" << QString(process->controlPassword()).toStdString() << "\" " << process->controlHost().toString().toStdString() diff --git a/retroshare-gui/src/TorControl/TorManager.h b/retroshare-gui/src/TorControl/TorManager.h index 883159efb..4c5ffeb44 100644 --- a/retroshare-gui/src/TorControl/TorManager.h +++ b/retroshare-gui/src/TorControl/TorManager.h @@ -37,6 +37,7 @@ #include #include +#include namespace Tor { @@ -84,6 +85,8 @@ public: bool hasError() const; QString errorMessage() const; + bool getHiddenServiceInfo(QString& service_id,QString& service_onion_address,uint16_t& service_port, QHostAddress& service_target_address,uint16_t& target_port); + public slots: void start(); diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 3ce7ec2ec..5cc752b10 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -53,6 +53,7 @@ #endif #include "retroshare/rsidentity.h" +#include "retroshare/rspeers.h" #ifdef SIGFPE_DEBUG #include @@ -282,36 +283,6 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO); /* Setup The GUI Stuff */ Rshare rshare(args, argc, argv, QString::fromUtf8(RsAccounts::ConfigDirectory().c_str())); -// #ifdef RETROTOR -// // First check that we can start the Tor engine, if not, quit. -// -// /* Tor control manager */ -// Tor::TorManager *torManager = Tor::TorManager::instance(); -// torManager->setDataDirectory(Rshare::dataDirectory() + QString("/tor/")); -// torManager->start(); -// -// // We do not need to show this dialog. If too much of a pain, we may hide it and only show when it reports an error. -// TorControlDialog tcd(torManager) ; -// -// { -// tcd.show(); -// -// while(tcd.checkForTor() == TorControlDialog::TOR_STATUS_UNKNOWN) // runs until some status is reached: either tor works, or it fails. -// { -// QCoreApplication::processEvents(); -// usleep(1000) ; -// } -// -// tcd.hide(); -// -// if(tcd.checkForTor() != TorControlDialog::TOR_STATUS_OK) -// { -// QMessageBox::critical(NULL,QObject::tr("Tor not found!"),QObject::tr("Tor wasn't found on your system. Please install it and re-start Retroshare.")) ; -// return 1 ; -// } -// } -// #endif - /* Start RetroShare */ QString sDefaultGXSIdToCreate = ""; switch (initResult) { @@ -425,10 +396,34 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO); return 1; } +#ifdef RETROTOR + // Tor works with viable hidden service. Let's use it! + + QString service_id ; + QString onion_address ; + uint16_t service_port ; + uint16_t service_target_port ; + QHostAddress service_target_address ; + + torManager->getHiddenServiceInfo(service_id,onion_address,service_port,service_target_address,service_target_port); + + std::cerr << "Got hidden service info: " << std::endl; + std::cerr << " onion address : " << onion_address.toStdString() << std::endl; + std::cerr << " service_id : " << service_id.toStdString() << std::endl; + std::cerr << " service port : " << service_port << std::endl; + std::cerr << " target port : " << service_target_port << std::endl; + std::cerr << " target address : " << service_target_address.toString().toStdString() << std::endl; + + std::cerr << "Setting proxy server to " << service_target_address.toString().toStdString() << ":" << service_target_port << std::endl; + + rsPeers->setLocalAddress(rsPeers->getOwnId(), service_target_address.toString().toStdString(), service_target_port); + rsPeers->setHiddenNode(rsPeers->getOwnId(), onion_address.toStdString(), service_port); +#endif Rshare::initPlugins(); splashScreen.showMessage(rshare.translate("SplashScreen", "Create interface"), Qt::AlignHCenter | Qt::AlignBottom); + QCoreApplication::processEvents(); // forces splashscreen to show up RsharePeerSettings::Create();