attempt to improve the tor statusbar widget

This commit is contained in:
csoler 2018-01-20 16:43:38 +01:00
parent 6179d22ad5
commit 15decacc0d
4 changed files with 35 additions and 26 deletions

View File

@ -161,18 +161,6 @@ bool TorManager::setupHiddenService()
std::cerr << "legacy dir not set! Cannot proceed." << std::endl;
return false ;
}
// if (!keyData.isEmpty())
// {
// CryptoKey key;
// if (!key.loadFromData(QByteArray::fromBase64(keyData.toLatin1()), CryptoKey::PrivateKey, CryptoKey::DER))
// {
// qWarning() << "Cannot load service key from configuration";
// return;
// }
//
// mHiddenService = new Tor::HiddenService(key, legacyDir, this);
// }
// else
std::cerr << "Using legacy dir: " << legacyDir.toStdString() << std::endl;
@ -193,11 +181,6 @@ bool TorManager::setupHiddenService()
std::cerr << "Got key from legacy dir: " << std::endl;
std::cerr << keyData.toStdString() << std::endl;
}
// else if (!m_settings->read("initializing").toBool())
// {
// qWarning() << "Missing private key for initialized identity";
// return;
// }
else
{
d->hiddenService = new Tor::HiddenService(legacyDir, this);
@ -235,7 +218,7 @@ bool TorManager::setupHiddenService()
return true ;
}
void hiddenServiceStatusChanged(int old_status,int new_status)
void TorManager::hiddenServiceStatusChanged(int old_status,int new_status)
{
std::cerr << "Hidden service status changed from " << old_status << " to " << new_status << std::endl;
}

View File

@ -93,6 +93,7 @@ public slots:
private slots:
void hiddenServicePrivateKeyChanged();
void hiddenServiceStatusChanged(int old_status,int new_status);
signals:
void configurationNeededChanged();

View File

@ -275,7 +275,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)
statusBar()->addWidget(dhtstatus);
dhtstatus->getDHTStatus();
}
hashingstatus = new HashingStatus();
hashingstatus->setVisible(Settings->valueFromGroup("StatusBar", "ShowHashing", QVariant(true)).toBool());
statusBar()->addPermanentWidget(hashingstatus, 1);

View File

@ -60,6 +60,28 @@ void TorStatus::getTorStatus()
statusTor->setVisible(!_compactMode);
QString text = _compactMode?statusTor->text():"";
/* check local network state. We cannot make sure that Tor is running yet. */
uint32_t netState = rsConfig -> getNetState();
bool online ;
switch(netState)
{
default:
case RSNET_NETSTATE_BAD_UNKNOWN:
case RSNET_NETSTATE_BAD_OFFLINE: online = false ;
break ;
case RSNET_NETSTATE_WARNING_RESTART:
case RSNET_NETSTATE_BAD_NATSYM:
case RSNET_NETSTATE_BAD_NODHT_NAT:
case RSNET_NETSTATE_WARNING_NATTED:
case RSNET_NETSTATE_WARNING_NODHT:
case RSNET_NETSTATE_GOOD:
case RSNET_NETSTATE_ADV_FORWARD: online = true ;
break ;
}
/* now the extra bit .... switch on check boxes */
int S = QFontMetricsF(torstatusLabel->font()).height();
@ -70,15 +92,16 @@ void TorStatus::getTorStatus()
int torstatus = Tor::TorManager::instance()->control()->torStatus();
QString tor_control_status_str,torstatus_str ;
bool tor_control_ok ;
switch(tor_control_status)
{
default:
case Tor::TorControl::Error : tor_control_status_str = "Error" ; break ;
case Tor::TorControl::NotConnected: tor_control_status_str = "Not connected" ; break ;
case Tor::TorControl::Connecting: tor_control_status_str = "Connecting" ; break ;
case Tor::TorControl::Authenticating: tor_control_status_str = "Authenticating" ; break ;
case Tor::TorControl::Connected: tor_control_status_str = "Connected" ; break ;
case Tor::TorControl::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 Tor::TorControl::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 Tor::TorControl::Connected: tor_control_ok = true ; tor_control_status_str = "Connected" ; break ;
}
switch(torstatus)
@ -91,13 +114,15 @@ void TorStatus::getTorStatus()
#define MIN_RS_NET_SIZE 10
if(torstatus == Tor::TorControl::TorOffline)
std::cerr << "(II) tor status: net=" << netState << " tor_control= " << tor_control_status << " tor_status=" << torstatus << std::endl;
if(torstatus == Tor::TorControl::TorOffline || !online || !tor_control_ok)
{
// RED - some issue.
torstatusLabel->setPixmap(QPixmap(":/icons/tor-stopping.png").scaledToHeight(1.5*S,Qt::SmoothTransformation));
torstatusLabel->setToolTip( text + tr("Tor is currently offline"));
}
else if(torstatus == Tor::TorControl::TorReady)
else if(torstatus == Tor::TorControl::TorReady && online && tor_control_ok)
{
torstatusLabel->setPixmap(QPixmap(":/icons/tor-on.png").scaledToHeight(1.5*S,Qt::SmoothTransformation));
torstatusLabel->setToolTip( text + tr("Tor is OK"));