fixed compilation

This commit is contained in:
csoler 2021-06-26 17:12:17 +02:00
parent f13b0cbe9f
commit 43e8ed3d98
4 changed files with 142 additions and 38 deletions

View File

@ -563,3 +563,110 @@ uint16_t RsTor::socksPort()
{ {
return instance()->control()->socksPort(); return instance()->control()->socksPort();
} }
RsTorStatus RsTor::torStatus()
{
TorControl::TorStatus ts = instance()->control()->torStatus();
switch(ts)
{
case TorControl::TorOffline: return RsTorStatus::OFFLINE;
case TorControl::TorReady: return RsTorStatus::READY;
default:
case TorControl::TorUnknown: return RsTorStatus::UNKNOWN;
}
}
RsTorControlStatus RsTor::torControlStatus()
{
TorControl::Status ts = instance()->control()->status();
switch(ts)
{
default:
case Tor::TorControl::Error : return RsTorControlStatus::ERROR;
case Tor::TorControl::NotConnected : return RsTorControlStatus::NOT_CONNECTED;
case Tor::TorControl::Authenticating: return RsTorControlStatus::AUTHENTICATING;
case Tor::TorControl::Connecting: return RsTorControlStatus::CONNECTING;
case Tor::TorControl::Connected : return RsTorControlStatus::CONNECTED;
}
}
bool RsTor::setupHiddenService()
{
return instance()->setupHiddenService();
}
RsTorHiddenServiceStatus RsTor::getHiddenServiceStatus(std::string& service_id)
{
service_id.clear();
auto list = instance()->control()->hiddenServices();
if(list.empty())
return RsTorHiddenServiceStatus::NOT_CREATRED;
service_id = (*list.begin())->serviceId().toStdString();
switch((*list.begin())->status())
{
default:
case Tor::HiddenService::NotCreated: return RsTorHiddenServiceStatus::NOT_CREATRED;
case Tor::HiddenService::Offline : return RsTorHiddenServiceStatus::OFFLINE;
case Tor::HiddenService::Online : return RsTorHiddenServiceStatus::ONLINE;
}
}
std::map<std::string,std::string> RsTor::bootstrapStatus()
{
QVariantMap m = instance()->control()->bootstrapStatus();
std::map<std::string,std::string> res;
for(auto it(m.begin());it!=m.end();++it)
res.insert(std::make_pair(it.key().toStdString(),it.value().toString().toStdString()));
return res;
}
bool RsTor::hasError()
{
return instance()->hasError();
}
std::string RsTor::errorMessage()
{
return instance()->errorMessage().toStdString();
}
void RsTor::getProxyServerInfo(std::string& server_address, uint16_t& server_port)
{
QHostAddress qserver_address;
instance()->getProxyServerInfo(qserver_address,server_port);
server_address = qserver_address.toString().toStdString();
}
bool RsTor::start()
{
return instance()->start();
}
void RsTor::setTorDataDirectory(const std::string& dir)
{
instance()->setTorDataDirectory(QString::fromStdString(dir));
}
void RsTor::setHiddenServiceDirectory(const std::string& dir)
{
instance()->setHiddenServiceDirectory(QString::fromStdString(dir));
}
TorManager *RsTor::instance()
{
assert(getpid() == gettid()); // make sure we're not in a thread
static TorManager *rsTor = nullptr;
if(rsTor == nullptr)
rsTor = new TorManager;
return rsTor;
}

View File

@ -528,7 +528,7 @@ void GenCertDialog::genPerson()
bool isHiddenLoc = (ui.nodeType_CB->currentIndex()>0); bool isHiddenLoc = (ui.nodeType_CB->currentIndex()>0);
bool isAutoTor = (ui.nodeType_CB->currentIndex()==1); bool isAutoTor = (ui.nodeType_CB->currentIndex()==1);
if(isAutoTor && !Tor::TorManager::isTorAvailable()) if(isAutoTor && !RsTor::isTorAvailable())
{ {
QMessageBox::critical(this,tr("Tor is not available"),tr("No Tor executable has been found on your system. You need to install Tor before creating a hidden identity.")) ; QMessageBox::critical(this,tr("Tor is not available"),tr("No Tor executable has been found on your system. You need to install Tor before creating a hidden identity.")) ;
return ; return ;

View File

@ -28,11 +28,10 @@
#include "retroshare/rsconfig.h" #include "retroshare/rsconfig.h"
#include "retroshare/rsinit.h" #include "retroshare/rsinit.h"
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
#include "retroshare/rstor.h"
#include <QTcpSocket> #include <QTcpSocket>
#include "util/misc.h" #include "util/misc.h"
#include "TorControl/TorManager.h"
#include "TorControl/TorControl.h"
#include "gui/common/FilesDefs.h" #include "gui/common/FilesDefs.h"
#include <iomanip> #include <iomanip>
@ -92,8 +91,8 @@ void TorStatus::getTorStatus()
if(RsAccounts::isTorAuto()) if(RsAccounts::isTorAuto())
{ {
// get Tor status // get Tor status
int tor_control_status = Tor::TorManager::instance()->control()->status(); RsTorControlStatus tor_control_status = RsTor::torControlStatus();
int torstatus = Tor::TorManager::instance()->control()->torStatus(); RsTorStatus torstatus = RsTor::torStatus();
QString tor_control_status_str,torstatus_str ; QString tor_control_status_str,torstatus_str ;
bool tor_control_ok ; bool tor_control_ok ;
@ -101,30 +100,30 @@ void TorStatus::getTorStatus()
switch(tor_control_status) switch(tor_control_status)
{ {
default: default:
case Tor::TorControl::Error : tor_control_ok = false ; tor_control_status_str = "Error" ; break ; case RsTorControlStatus::ERROR : tor_control_ok = false ; tor_control_status_str = "Error" ; break ;
case Tor::TorControl::NotConnected: tor_control_ok = false ; tor_control_status_str = "Not connected" ; break ; case RsTorControlStatus::NOT_CONNECTED: tor_control_ok = false ; tor_control_status_str = "Not connected" ; break ;
case Tor::TorControl::Connecting: tor_control_ok = false ; tor_control_status_str = "Connecting" ; break ; case RsTorControlStatus::CONNECTING: tor_control_ok = false ; tor_control_status_str = "Connecting" ; break ;
case Tor::TorControl::Authenticating: tor_control_ok = false ; tor_control_status_str = "Authenticating" ; break ; case RsTorControlStatus::AUTHENTICATING: tor_control_ok = false ; tor_control_status_str = "Authenticating" ; break ;
case Tor::TorControl::Connected: tor_control_ok = true ; tor_control_status_str = "Connected" ; break ; case RsTorControlStatus::CONNECTED: tor_control_ok = true ; tor_control_status_str = "Connected" ; break ;
} }
switch(torstatus) switch(torstatus)
{ {
default: default:
case Tor::TorControl::TorUnknown: torstatus_str = "Unknown" ; break ; case RsTorStatus::UNKNOWN: torstatus_str = "Unknown" ; break ;
case Tor::TorControl::TorOffline: torstatus_str = "Tor offline" ; break ; case RsTorStatus::OFFLINE: torstatus_str = "Tor offline" ; break ;
case Tor::TorControl::TorReady: torstatus_str = "Tor ready" ; break ; case RsTorStatus::READY: torstatus_str = "Tor ready" ; break ;
} }
#define MIN_RS_NET_SIZE 10 #define MIN_RS_NET_SIZE 10
if(torstatus == Tor::TorControl::TorOffline || !online || !tor_control_ok) if(torstatus == RsTorStatus::OFFLINE || !online || !tor_control_ok)
{ {
// RED - some issue. // RED - some issue.
torstatusLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/tor-stopping.png").scaledToHeight(1.5*S,Qt::SmoothTransformation)); torstatusLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/tor-stopping.png").scaledToHeight(1.5*S,Qt::SmoothTransformation));
torstatusLabel->setToolTip( text + tr("Tor is currently offline")); torstatusLabel->setToolTip( text + tr("Tor is currently offline"));
} }
else if(torstatus == Tor::TorControl::TorReady && online && tor_control_ok) else if(torstatus == RsTorStatus::READY && online && tor_control_ok)
{ {
torstatusLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/tor-on.png").scaledToHeight(1.5*S,Qt::SmoothTransformation)); torstatusLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/tor-on.png").scaledToHeight(1.5*S,Qt::SmoothTransformation));
torstatusLabel->setToolTip( text + tr("Tor is OK")); torstatusLabel->setToolTip( text + tr("Tor is OK"));

View File

@ -399,24 +399,23 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
{ {
// Now that we know the Tor service running, and we know the SSL id, we can make sure it provides a viable hidden service // Now that we know the Tor service running, and we know the SSL id, we can make sure it provides a viable hidden service
QString tor_hidden_service_dir = QString::fromStdString(RsAccounts::AccountDirectory()) + QString("/hidden_service/") ; std::string tor_hidden_service_dir = RsAccounts::AccountDirectory() + "/hidden_service/" ;
Tor::TorManager *torManager = Tor::TorManager::instance(); RsTor::setTorDataDirectory(Rshare::dataDirectory().toStdString() + "/tor/");
torManager->setTorDataDirectory(Rshare::dataDirectory() + QString("/tor/")); RsTor::setHiddenServiceDirectory(tor_hidden_service_dir); // re-set it, because now it's changed to the specific location that is run
torManager->setHiddenServiceDirectory(tor_hidden_service_dir); // re-set it, because now it's changed to the specific location that is run
RsDirUtil::checkCreateDirectory(std::string(tor_hidden_service_dir.toUtf8())) ; RsDirUtil::checkCreateDirectory(std::string(tor_hidden_service_dir)) ;
torManager->setupHiddenService(); RsTor::setupHiddenService();
if(! torManager->start() || torManager->hasError()) if(! RsTor::start() || RsTor::hasError())
{ {
QMessageBox::critical(NULL,QObject::tr("Cannot start Tor Manager!"),QObject::tr("Tor cannot be started on your system: \n\n")+torManager->errorMessage()) ; QMessageBox::critical(NULL,QObject::tr("Cannot start Tor Manager!"),QObject::tr("Tor cannot be started on your system: \n\n")+QString::fromStdString(RsTor::errorMessage())) ;
return 1 ; return 1 ;
} }
{ {
TorControlDialog tcd(torManager) ; TorControlDialog tcd;
QString error_msg ; QString error_msg ;
tcd.show(); tcd.show();
@ -460,30 +459,29 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
{ {
// Tor works with viable hidden service. Let's use it! // Tor works with viable hidden service. Let's use it!
QString service_id ; std::string service_id ;
QString onion_address ; std::string onion_address ;
uint16_t service_port ; uint16_t service_port ;
uint16_t service_target_port ; uint16_t service_target_port ;
uint16_t proxy_server_port ; uint16_t proxy_server_port ;
QHostAddress service_target_address ; std::string service_target_address ;
QHostAddress proxy_server_address ; std::string proxy_server_address ;
Tor::TorManager *torManager = Tor::TorManager::instance(); RsTor::getHiddenServiceInfo(service_id,onion_address,service_port,service_target_address,service_target_port);
torManager->getHiddenServiceInfo(service_id,onion_address,service_port,service_target_address,service_target_port); RsTor::getProxyServerInfo(proxy_server_address,proxy_server_port) ;
torManager->getProxyServerInfo(proxy_server_address,proxy_server_port) ;
std::cerr << "Got hidden service info: " << std::endl; std::cerr << "Got hidden service info: " << std::endl;
std::cerr << " onion address : " << onion_address.toStdString() << std::endl; std::cerr << " onion address : " << onion_address << std::endl;
std::cerr << " service_id : " << service_id.toStdString() << std::endl; std::cerr << " service_id : " << service_id << std::endl;
std::cerr << " service port : " << service_port << std::endl; std::cerr << " service port : " << service_port << std::endl;
std::cerr << " target port : " << service_target_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 << " target address : " << service_target_address << std::endl;
std::cerr << "Setting proxy server to " << service_target_address.toString().toStdString() << ":" << service_target_port << std::endl; std::cerr << "Setting proxy server to " << service_target_address << ":" << service_target_port << std::endl;
rsPeers->setLocalAddress(rsPeers->getOwnId(), service_target_address.toString().toStdString(), service_target_port); rsPeers->setLocalAddress(rsPeers->getOwnId(), service_target_address, service_target_port);
rsPeers->setHiddenNode(rsPeers->getOwnId(), onion_address.toStdString(), service_port); rsPeers->setHiddenNode(rsPeers->getOwnId(), onion_address, service_port);
rsPeers->setProxyServer(RS_HIDDEN_TYPE_TOR, proxy_server_address.toString().toStdString(),proxy_server_port) ; rsPeers->setProxyServer(RS_HIDDEN_TYPE_TOR, proxy_server_address,proxy_server_port) ;
} }
Rshare::initPlugins(); Rshare::initPlugins();