diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 80823dd56..9a53ab833 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -107,7 +107,7 @@ enum class RsEventType : uint32_t FILE_HASHING_COMPLETED = 20, /// @see rspeers.h - TOR_MANAGER = 17, + TOR_MANAGER = 21, __MAX /// Used internally, keep last }; diff --git a/libretroshare/src/retroshare/rstor.h b/libretroshare/src/retroshare/rstor.h index 8eaa4a352..654b79938 100644 --- a/libretroshare/src/retroshare/rstor.h +++ b/libretroshare/src/retroshare/rstor.h @@ -56,10 +56,11 @@ enum class RsTorConnectivityStatus: uint8_t { ERROR = 0x00, NOT_CONNECTED = 0x01, CONNECTING = 0x02, - AUTHENTICATING = 0x03, - AUTHENTICATED = 0x04, - HIDDEN_SERVICE_READY = 0x05, - UNKNOWN = 0x06 + SOCKET_CONNECTED = 0x03, + AUTHENTICATING = 0x04, + AUTHENTICATED = 0x05, + HIDDEN_SERVICE_READY = 0x06, + UNKNOWN = 0x07 }; // Status of the Tor service with which RS is talking. diff --git a/libretroshare/src/tor/TorControl.cpp b/libretroshare/src/tor/TorControl.cpp index caf4576fa..9b456036b 100644 --- a/libretroshare/src/tor/TorControl.cpp +++ b/libretroshare/src/tor/TorControl.cpp @@ -78,11 +78,14 @@ static RsTorConnectivityStatus torConnectivityStatus(Tor::TorControl::Status t) switch(t) { default: - case TorControl::Error: return RsTorConnectivityStatus::ERROR; - case TorControl::NotConnected: return RsTorConnectivityStatus::NOT_CONNECTED; - case TorControl::Connecting: return RsTorConnectivityStatus::CONNECTING; - case TorControl::Authenticating: return RsTorConnectivityStatus::AUTHENTICATING; + case TorControl::Error: return RsTorConnectivityStatus::ERROR; + case TorControl::NotConnected: return RsTorConnectivityStatus::NOT_CONNECTED; + case TorControl::Connecting: return RsTorConnectivityStatus::CONNECTING; + case TorControl::SocketConnected: return RsTorConnectivityStatus::SOCKET_CONNECTED; + case TorControl::Authenticating: return RsTorConnectivityStatus::AUTHENTICATING; case TorControl::Authenticated: return RsTorConnectivityStatus::AUTHENTICATED; + case TorControl::HiddenServiceReady: return RsTorConnectivityStatus::HIDDEN_SERVICE_READY; + case TorControl::Unknown: return RsTorConnectivityStatus::UNKNOWN; } } static RsTorStatus torStatus(Tor::TorControl::TorStatus t) @@ -107,6 +110,8 @@ void TorControl::setStatus(TorControl::Status n) if (old == TorControl::Error) mErrorMessage.clear(); + std::cerr << "Setting status to s=" << mStatus << " val=" << (int)torConnectivityStatus(mStatus) << std::endl; + if(rsEvents) { auto ev = std::make_shared(); @@ -133,8 +138,9 @@ void TorControl::setTorStatus(TorControl::TorStatus n) auto ev = std::make_shared(); ev->mTorManagerEventType = RsTorManagerEventCode::TOR_STATUS_CHANGED; - ev->mTorConnectivityStatus = torConnectivityStatus(mStatus); ev->mTorStatus = ::torStatus(mTorStatus); + ev->mTorConnectivityStatus = torConnectivityStatus(mStatus); + rsEvents->sendEvent(ev); } } diff --git a/libretroshare/src/tor/TorControl.h b/libretroshare/src/tor/TorControl.h index 568a1aaf2..be73aa3f4 100644 --- a/libretroshare/src/tor/TorControl.h +++ b/libretroshare/src/tor/TorControl.h @@ -51,13 +51,14 @@ class TorControl : public TorControlSocketClient public: enum Status { - Error = -1, - NotConnected = 0x00, - Connecting = 0x01, - SocketConnected = 0x02, - Authenticating = 0x03, - Authenticated = 0x04, - HiddenServiceReady = 0x05 + Error = 0x00, + NotConnected = 0x01, + Connecting = 0x02, + SocketConnected = 0x03, + Authenticating = 0x04, + Authenticated = 0x05, + HiddenServiceReady = 0x06, + Unknown = 0x07 }; enum TorStatus diff --git a/libretroshare/src/tor/TorManager.cpp b/libretroshare/src/tor/TorManager.cpp index 4f3cf19c2..0b0f59cef 100644 --- a/libretroshare/src/tor/TorManager.cpp +++ b/libretroshare/src/tor/TorManager.cpp @@ -239,8 +239,6 @@ bool TorManager::setupHiddenService() assert(d->hiddenService); - // connect(d->hiddenService, SIGNAL(statusChanged(int,int)), this, SLOT(hiddenServiceStatusChanged(int,int))); - // Generally, these are not used, and we bind to localhost and port 0 // for an automatic (and portable) selection. @@ -258,6 +256,9 @@ bool TorManager::setupHiddenService() std::cerr << ": OK - Adding hidden service to TorControl." << std::endl; + // Note: 9878 is quite arbitrary, but since each RS node generates its own hidden service, all of them + // can use the same port without any conflict. + d->hiddenService->addTarget(9878, "127.0.0.1",hidden_service_port); control()->addHiddenService(d->hiddenService); @@ -483,6 +484,7 @@ void TorManager::threadTick() switch(d->control->status()) { + case TorControl::Unknown: case TorControl::Connecting: break; @@ -618,12 +620,13 @@ void TorManagerPrivate::getConfFinished(TorControlCommand *sender) if(RsUtil::StringToInt(str,n) && n==1 && !configNeeded) { configNeeded = true; - //emit q->configurationNeededChanged(); if(rsEvents) { auto ev = std::make_shared(); ev->mTorManagerEventType = RsTorManagerEventCode::CONFIGURATION_NEEDED; + ev->mTorConnectivityStatus = RsTorConnectivityStatus::UNKNOWN; + ev->mTorStatus = RsTorStatus::UNKNOWN; rsEvents->sendEvent(ev); } } diff --git a/retroshare-gui/src/TorControl/TorControlWindow.cpp b/retroshare-gui/src/TorControl/TorControlWindow.cpp index 2330c555b..ddab3f281 100644 --- a/retroshare-gui/src/TorControl/TorControlWindow.cpp +++ b/retroshare-gui/src/TorControl/TorControlWindow.cpp @@ -55,7 +55,13 @@ void TorControlDialog::handleEvent_main_thread(std::shared_ptr ev if(!fe) return; - statusChanged(fe->mTorStatus,fe->mTorConnectivityStatus); + switch(fe->mTorManagerEventType) + { + case RsTorManagerEventCode::TOR_STATUS_CHANGED: + case RsTorManagerEventCode::TOR_CONNECTIVITY_CHANGED: statusChanged(fe->mTorStatus,fe->mTorConnectivityStatus); + break; + default: ; + } } void TorControlDialog::onIncomingConnection() @@ -73,12 +79,15 @@ void TorControlDialog::statusChanged(RsTorStatus torstatus, RsTorConnectivitySta switch(tor_control_status) { default: - case RsTorConnectivityStatus::ERROR : tor_control_status_str = tr("Error") ; break ; + case RsTorConnectivityStatus::ERROR: tor_control_status_str = tr("Error") ; break ; case RsTorConnectivityStatus::NOT_CONNECTED: tor_control_status_str = tr("Not connected") ; break ; case RsTorConnectivityStatus::CONNECTING: tor_control_status_str = tr("Connecting") ; break ; + case RsTorConnectivityStatus::SOCKET_CONNECTED: tor_control_status_str = tr("Socket connected") ; break ; case RsTorConnectivityStatus::AUTHENTICATING: tor_control_status_str = tr("Authenticating") ; break ; case RsTorConnectivityStatus::AUTHENTICATED: tor_control_status_str = tr("Authenticated") ; break ; - } + case RsTorConnectivityStatus::HIDDEN_SERVICE_READY: tor_control_status_str = tr("Hidden service ready") ; break ; + case RsTorConnectivityStatus::UNKNOWN: tor_control_status_str = tr("Unknown") ; break ; + } switch(torstatus) {