Merge branch 'v0.6-TorControl' of github.com:csoler/RetroShare into v0.6-TorControl

This commit is contained in:
csoler 2021-12-30 19:51:53 +01:00
commit 1e8e489cd1
9 changed files with 49 additions and 8 deletions

View File

@ -84,7 +84,7 @@ RsThreadedTcpSocket::RsThreadedTcpSocket() : RsTcpSocket()
} }
void RsThreadedTcpSocket::run() void RsThreadedTcpSocket::run()
{ {
while(connectionState() == CONNECTED) while(!shouldStop() && connectionState() == CONNECTED)
{ {
tick(); tick();
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));

View File

@ -141,6 +141,12 @@ public:
*/ */
static bool start(); static bool start();
/*!
* \brief stop
* Stop the Tor management threads.
*/
static void stop();
/*! /*!
* \brief getHiddenServiceInfo * \brief getHiddenServiceInfo
* Gets information about the hidden service setup by RS to run. * Gets information about the hidden service setup by RS to run.

View File

@ -46,8 +46,6 @@
#include "StrUtil.h" #include "StrUtil.h"
#include "PendingOperation.h" #include "PendingOperation.h"
Tor::TorControl *torControl = 0;
class nullstream: public std::ostream {}; class nullstream: public std::ostream {};
static std::ostream& torctrldebug() static std::ostream& torctrldebug()
@ -70,6 +68,11 @@ TorControl::TorControl()
mSocket = new TorControlSocket(this); mSocket = new TorControlSocket(this);
} }
TorControl::~TorControl()
{
delete(mSocket);
}
static RsTorConnectivityStatus torConnectivityStatus(Tor::TorControl::Status t) static RsTorConnectivityStatus torConnectivityStatus(Tor::TorControl::Status t)
{ {
switch(t) switch(t)

View File

@ -68,6 +68,7 @@ public:
}; };
explicit TorControl(); explicit TorControl();
virtual ~TorControl();
/* Information */ /* Information */
Status status() const; Status status() const;
@ -148,5 +149,3 @@ private:
}; };
} }
extern Tor::TorControl *torControl;

View File

@ -53,6 +53,8 @@
using namespace Tor; using namespace Tor;
static TorManager *rsTor = nullptr;
namespace Tor namespace Tor
{ {
@ -71,6 +73,7 @@ public:
HiddenService *hiddenService ; HiddenService *hiddenService ;
explicit TorManagerPrivate(TorManager *parent = 0); explicit TorManagerPrivate(TorManager *parent = 0);
virtual ~TorManagerPrivate();
std::string torExecutablePath() const; std::string torExecutablePath() const;
bool createDataDir(const std::string &path); bool createDataDir(const std::string &path);
@ -94,6 +97,11 @@ TorManager::TorManager()
{ {
} }
TorManager::~TorManager()
{
delete(d);
}
TorManagerPrivate::TorManagerPrivate(TorManager *parent) TorManagerPrivate::TorManagerPrivate(TorManager *parent)
: q(parent) : q(parent)
, process(0) , process(0)
@ -104,6 +112,11 @@ TorManagerPrivate::TorManagerPrivate(TorManager *parent)
control->set_statusChanged_callback([this](int new_status,int /*old_status*/) { controlStatusChanged(new_status); }); control->set_statusChanged_callback([this](int new_status,int /*old_status*/) { controlStatusChanged(new_status); });
} }
TorManagerPrivate::~TorManagerPrivate()
{
delete(control);
}
TorManager *TorManager::instance() TorManager *TorManager::instance()
{ {
static TorManager *p = 0; static TorManager *p = 0;
@ -450,7 +463,7 @@ void TorManager::run()
std::this_thread::sleep_for(std::chrono::milliseconds(50)); std::this_thread::sleep_for(std::chrono::milliseconds(50));
} }
d->control->shutdown(); d->control->shutdownSync();
d->process->stop(); d->process->stop();
if(rsEvents) if(rsEvents)
@ -828,6 +841,17 @@ bool RsTor::start()
return instance()->startTorManager(); return instance()->startTorManager();
} }
void RsTor::stop()
{
if (rsTor) {
if (rsTor->isRunning()) {
rsTor->fullstop();
}
delete(rsTor);
rsTor= nullptr;
}
}
void RsTor::setTorDataDirectory(const std::string& dir) void RsTor::setTorDataDirectory(const std::string& dir)
{ {
instance()->setTorDataDirectory(dir); instance()->setTorDataDirectory(dir);
@ -843,8 +867,6 @@ TorManager *RsTor::instance()
assert(getpid() == syscall(SYS_gettid));// make sure we're not in a thread assert(getpid() == syscall(SYS_gettid));// make sure we're not in a thread
#endif #endif
static TorManager *rsTor = nullptr;
if(rsTor == nullptr) if(rsTor == nullptr)
rsTor = new TorManager; rsTor = new TorManager;

View File

@ -51,6 +51,7 @@ class TorManager : public HiddenServiceClient, public RsThread, public RsTor
{ {
public: public:
static TorManager *instance(); static TorManager *instance();
virtual ~TorManager();
TorProcess *process(); TorProcess *process();
TorControl *control(); TorControl *control();

View File

@ -42,6 +42,11 @@ TorControlDialog::TorControlDialog(QWidget *)
adjustSize(); adjustSize();
} }
TorControlDialog::~TorControlDialog()
{
rsEvents->unregisterEventsHandler(mEventHandlerId);
}
void TorControlDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event) void TorControlDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{ {
if(event->mType != RsEventType::TOR_MANAGER) return; if(event->mType != RsEventType::TOR_MANAGER) return;

View File

@ -15,6 +15,7 @@ class TorControlDialog: public QWidget, public Ui::TorControlDialog
public: public:
TorControlDialog(QWidget *parent =NULL); TorControlDialog(QWidget *parent =NULL);
virtual ~TorControlDialog();
enum TorStatus { enum TorStatus {
TOR_STATUS_UNKNOWN = 0x00, TOR_STATUS_UNKNOWN = 0x00,

View File

@ -591,6 +591,10 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
RsGxsUpdateBroadcast::cleanup(); RsGxsUpdateBroadcast::cleanup();
#endif #endif
if (is_auto_tor) {
RsTor::stop();
}
RsControl::instance()->rsGlobalShutDown(); RsControl::instance()->rsGlobalShutDown();
delete(soundManager); delete(soundManager);