diff --git a/libretroshare/src/tor/ProtocolInfoCommand.cpp b/libretroshare/src/tor/ProtocolInfoCommand.cpp index 867541e56..cdb7d648b 100644 --- a/libretroshare/src/tor/ProtocolInfoCommand.cpp +++ b/libretroshare/src/tor/ProtocolInfoCommand.cpp @@ -37,7 +37,7 @@ using namespace Tor; ProtocolInfoCommand::ProtocolInfoCommand(TorControl *m) - : manager(m) + : manager(m),m_authMethods(0) { } diff --git a/libretroshare/src/tor/TorControl.cpp b/libretroshare/src/tor/TorControl.cpp index 579077bad..f5c9dc2f6 100644 --- a/libretroshare/src/tor/TorControl.cpp +++ b/libretroshare/src/tor/TorControl.cpp @@ -863,15 +863,14 @@ bool TorControl::torVersionAsNewAs(const std::string& match) const int split_size = split.size(); int i=0; - const auto& b_split(split.begin()); + auto b_split(split.begin()); + auto b_matchsplit(matchSplit.begin()); - for(const auto& b_matchsplit:matchSplit) + for(int i=0;;) { - if (i >= split_size) - return false; int currentVal,matchVal; bool ok1 = RsUtil::StringToInt((*b_split).toString(),currentVal); - bool ok2 = RsUtil::StringToInt(b_matchsplit.toString(),matchVal); + bool ok2 = RsUtil::StringToInt((*b_matchsplit).toString(),matchVal); if (!ok1 || !ok2) return false; @@ -881,6 +880,12 @@ bool TorControl::torVersionAsNewAs(const std::string& match) const return false; ++i; + + if(i >= split_size) + return false; + + ++b_split; + ++b_matchsplit; } // Versions are equal, up to the length of match diff --git a/libretroshare/src/tor/TorControl.h b/libretroshare/src/tor/TorControl.h index 6936e6653..8d26e20dd 100644 --- a/libretroshare/src/tor/TorControl.h +++ b/libretroshare/src/tor/TorControl.h @@ -70,7 +70,7 @@ public: SocketConnected = 0x02, Authenticating = 0x03, Authenticated = 0x04, - HiddenServiceReady = 0x05, + HiddenServiceReady = 0x05 }; enum TorStatus diff --git a/libretroshare/src/tor/TorManager.cpp b/libretroshare/src/tor/TorManager.cpp index 338db478a..d33075328 100644 --- a/libretroshare/src/tor/TorManager.cpp +++ b/libretroshare/src/tor/TorManager.cpp @@ -481,6 +481,13 @@ void TorManager::threadTick() case TorControl::SocketConnected: RsDbg() << "Connection established." ; + + if(d->hiddenService == nullptr) + { + RsDbg() << "Setting up hidden service" ; + setupHiddenService(); + } + d->control->setAuthPassword(d->process->controlPassword()); d->control->authenticate(); break; @@ -489,15 +496,12 @@ void TorManager::threadTick() RsDbg() << "Authenticating..." ; break; - case TorControl::Authenticated:; + case TorControl::Authenticated: RsDbg() << "Authenticated. Looking for hidden services."; + break; - for(auto service:d->control->hiddenServices()) - if(service->status() == HiddenService::Online) - { - - } + case TorControl::HiddenServiceReady: break; case TorControl::Error: diff --git a/retroshare-gui/src/TorControl/TorControlWindow.cpp b/retroshare-gui/src/TorControl/TorControlWindow.cpp index 7ec6f0392..31a2aa78c 100644 --- a/retroshare-gui/src/TorControl/TorControlWindow.cpp +++ b/retroshare-gui/src/TorControl/TorControlWindow.cpp @@ -36,7 +36,6 @@ TorControlDialog::TorControlDialog(QWidget *) //QTimer::singleShot(2000,this,SLOT(checkForHiddenService())) ; mIncomingServer = new QTcpServer(this) ; - mHiddenServiceStatus = HIDDEN_SERVICE_STATUS_UNKNOWN; connect(mIncomingServer, SIGNAL(QTcpServer::newConnection()), this, SLOT(onIncomingConnection())); @@ -192,63 +191,33 @@ TorControlDialog::HiddenServiceStatus TorControlDialog::checkForHiddenService() { std::cerr << "Checking for hidden services:" ; - switch(mHiddenServiceStatus) + std::string service_id; + + RsTorHiddenServiceStatus service_status = RsTor::getHiddenServiceStatus(service_id); + + if(service_id.empty()) { - default: - case HIDDEN_SERVICE_STATUS_FAIL: { - std::cerr << " Hidden service setup failed. Something's wrong." << std::endl; - return mHiddenServiceStatus; + std::cerr << "Not ready yet." << std::endl; + return HIDDEN_SERVICE_STATUS_REQUESTED ; } - case HIDDEN_SERVICE_STATUS_UNKNOWN: { + else + { + if(mHiddenService.empty()) + mHiddenService = service_id ; - std::cerr << " trying to setup. " ; + std::cerr << "New service acquired. Status is " << (int)service_status ; - if(!RsTor::setupHiddenService()) + if(service_status == RsTorHiddenServiceStatus::ONLINE) { - mHiddenServiceStatus = HIDDEN_SERVICE_STATUS_FAIL ; - std::cerr << "Failed." << std::endl; - return mHiddenServiceStatus ; - } - std::cerr << "Done." << std::endl; - mHiddenServiceStatus = HIDDEN_SERVICE_STATUS_REQUESTED ; - return mHiddenServiceStatus ; - } + std::cerr << ": published and running!" << std::endl; - case HIDDEN_SERVICE_STATUS_REQUESTED: { - - std::string service_id; - - RsTorHiddenServiceStatus service_status = RsTor::getHiddenServiceStatus(service_id); - - if(service_id.empty()) - { - std::cerr << "Not ready yet." << std::endl; - return mHiddenServiceStatus ; + return HIDDEN_SERVICE_STATUS_OK ; } else { - if(mHiddenService.empty()) - mHiddenService = service_id ; - - std::cerr << "New service acquired. Status is " << (int)service_status ; - - if(service_status == RsTorHiddenServiceStatus::ONLINE) - { - mHiddenServiceStatus = HIDDEN_SERVICE_STATUS_OK ; - std::cerr << ": published and running!" << std::endl; - - return mHiddenServiceStatus ; - } - else - { - std::cerr << ": not ready yet." << std::endl; - return mHiddenServiceStatus ; - } + std::cerr << ": not ready yet." << std::endl; + return HIDDEN_SERVICE_STATUS_REQUESTED ; } } - case HIDDEN_SERVICE_STATUS_OK : - std::cerr << "New service acquired." << std::endl; - return mHiddenServiceStatus ; - } } diff --git a/retroshare-gui/src/TorControl/TorControlWindow.h b/retroshare-gui/src/TorControl/TorControlWindow.h index 5fc23e8e9..7dc8c8bda 100644 --- a/retroshare-gui/src/TorControl/TorControlWindow.h +++ b/retroshare-gui/src/TorControl/TorControlWindow.h @@ -42,7 +42,6 @@ protected slots: void handleEvent_main_thread(std::shared_ptr event); private: QString mErrorMsg ; - HiddenServiceStatus mHiddenServiceStatus ; std::string mHiddenService; QTcpServer *mIncomingServer ;