progress in event handling in RsTor

This commit is contained in:
csoler 2021-06-26 18:52:48 +02:00
parent 43e8ed3d98
commit 607c1896e5
3 changed files with 54 additions and 13 deletions

View File

@ -32,6 +32,7 @@
#include <time.h> #include <time.h>
#include "retroshare/rstor.h"
#include "TorControl.h" #include "TorControl.h"
#include "TorControlSocket.h" #include "TorControlSocket.h"
#include "HiddenService.h" #include "HiddenService.h"
@ -139,6 +140,29 @@ QNetworkProxy TorControl::connectionProxy()
return QNetworkProxy(QNetworkProxy::Socks5Proxy, d->socksAddress.toString(), d->socksPort); return QNetworkProxy(QNetworkProxy::Socks5Proxy, d->socksAddress.toString(), d->socksPort);
} }
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::Connected: return RsTorConnectivityStatus::CONNECTED;
}
}
static RsTorStatus torStatus(Tor::TorControl::TorStatus t)
{
switch(t)
{
default:
case TorControl::TorUnknown: return RsTorStatus::UNKNOWN;
case TorControl::TorOffline: return RsTorStatus::OFFLINE;
case TorControl::TorReady: return RsTorStatus::READY;
}
}
void TorControlPrivate::setStatus(TorControl::Status n) void TorControlPrivate::setStatus(TorControl::Status n)
{ {
if (n == status) if (n == status)
@ -150,12 +174,23 @@ void TorControlPrivate::setStatus(TorControl::Status n)
if (old == TorControl::Error) if (old == TorControl::Error)
errorMessage.clear(); errorMessage.clear();
if(rsEvents)
{
auto ev = std::make_shared<RsTorManagerEvent>();
ev->mTorManagerEventType = RsTorManagerEventCode::TOR_CONTROL_STATUS_CHANGED;
ev->mTorConnectivityStatus = torConnectivityStatus(status);
rsEvents->postEvent(ev);
}
#ifdef TO_REMOVE
emit q->statusChanged(status, old); emit q->statusChanged(status, old);
if (status == TorControl::Connected && old < TorControl::Connected) if (status == TorControl::Connected && old < TorControl::Connected)
emit q->connected(); emit q->connected();
else if (status < TorControl::Connected && old >= TorControl::Connected) else if (status < TorControl::Connected && old >= TorControl::Connected)
emit q->disconnected(); emit q->disconnected();
#endif
} }
void TorControlPrivate::setTorStatus(TorControl::TorStatus n) void TorControlPrivate::setTorStatus(TorControl::TorStatus n)
@ -617,7 +652,13 @@ void TorControlPrivate::updateBootstrap(const QList<QByteArray> &data)
//torCtrlDebug() << bootstrapStatus << std::endl; //torCtrlDebug() << bootstrapStatus << std::endl;
emit q->bootstrapStatusChanged(); if(rsEvents)
{
auto ev = std::make_shared<RsTorManagerEvent>();
ev->mTorManagerEventType = RsTorManagerEventCode::BOOTSTRAP_STATUS_CHANGED;
rsEvents->postEvent(ev);
}
} }
QObject *TorControl::getConfiguration(const QString &options) QObject *TorControl::getConfiguration(const QString &options)

View File

@ -578,18 +578,18 @@ RsTorStatus RsTor::torStatus()
} }
} }
RsTorControlStatus RsTor::torControlStatus() RsTorConnectivityStatus RsTor::torConnectivityStatus()
{ {
TorControl::Status ts = instance()->control()->status(); TorControl::Status ts = instance()->control()->status();
switch(ts) switch(ts)
{ {
default: default:
case Tor::TorControl::Error : return RsTorControlStatus::ERROR; case Tor::TorControl::Error : return RsTorConnectivityStatus::ERROR;
case Tor::TorControl::NotConnected : return RsTorControlStatus::NOT_CONNECTED; case Tor::TorControl::NotConnected : return RsTorConnectivityStatus::NOT_CONNECTED;
case Tor::TorControl::Authenticating: return RsTorControlStatus::AUTHENTICATING; case Tor::TorControl::Authenticating: return RsTorConnectivityStatus::AUTHENTICATING;
case Tor::TorControl::Connecting: return RsTorControlStatus::CONNECTING; case Tor::TorControl::Connecting: return RsTorConnectivityStatus::CONNECTING;
case Tor::TorControl::Connected : return RsTorControlStatus::CONNECTED; case Tor::TorControl::Connected : return RsTorConnectivityStatus::CONNECTED;
} }
} }

View File

@ -91,7 +91,7 @@ void TorStatus::getTorStatus()
if(RsAccounts::isTorAuto()) if(RsAccounts::isTorAuto())
{ {
// get Tor status // get Tor status
RsTorControlStatus tor_control_status = RsTor::torControlStatus(); RsTorConnectivityStatus tor_control_status = RsTor::torConnectivityStatus();
RsTorStatus torstatus = RsTor::torStatus(); RsTorStatus torstatus = RsTor::torStatus();
QString tor_control_status_str,torstatus_str ; QString tor_control_status_str,torstatus_str ;
@ -100,11 +100,11 @@ void TorStatus::getTorStatus()
switch(tor_control_status) switch(tor_control_status)
{ {
default: default:
case RsTorControlStatus::ERROR : tor_control_ok = false ; tor_control_status_str = "Error" ; break ; case RsTorConnectivityStatus::ERROR : tor_control_ok = false ; tor_control_status_str = "Error" ; break ;
case RsTorControlStatus::NOT_CONNECTED: tor_control_ok = false ; tor_control_status_str = "Not connected" ; break ; case RsTorConnectivityStatus::NOT_CONNECTED: tor_control_ok = false ; tor_control_status_str = "Not connected" ; break ;
case RsTorControlStatus::CONNECTING: tor_control_ok = false ; tor_control_status_str = "Connecting" ; break ; case RsTorConnectivityStatus::CONNECTING: tor_control_ok = false ; tor_control_status_str = "Connecting" ; break ;
case RsTorControlStatus::AUTHENTICATING: tor_control_ok = false ; tor_control_status_str = "Authenticating" ; break ; case RsTorConnectivityStatus::AUTHENTICATING: tor_control_ok = false ; tor_control_status_str = "Authenticating" ; break ;
case RsTorControlStatus::CONNECTED: tor_control_ok = true ; tor_control_status_str = "Connected" ; break ; case RsTorConnectivityStatus::CONNECTED: tor_control_ok = true ; tor_control_status_str = "Connected" ; break ;
} }
switch(torstatus) switch(torstatus)