improved Tor startup phase integration in TorControlDialog

This commit is contained in:
csoler 2017-12-28 21:39:35 +01:00
parent 475b6a4a62
commit a591001cec
4 changed files with 61 additions and 30 deletions

View File

@ -29,6 +29,7 @@ TorControlDialog::TorControlDialog(Tor::TorManager *tm,QWidget *parent)
mIncomingServer = new QTcpServer(this) ;
mHiddenService = NULL ;
mHiddenServiceStatus = HIDDEN_SERVICE_STATUS_UNKNOWN;
//mBootstrapPhaseFinished = false ;
connect(mIncomingServer, SIGNAL(QTcpServer::newConnection()), this, SLOT(onIncomingConnection()));
@ -51,19 +52,19 @@ void TorControlDialog::onIncomingConnection()
void TorControlDialog::statusChanged()
{
int status = mTorManager->control()->status();
int tor_control_status = mTorManager->control()->status();
int torstatus = mTorManager->control()->torStatus();
QString status_str,torstatus_str ;
QString tor_control_status_str,torstatus_str ;
switch(status)
switch(tor_control_status)
{
default:
case Tor::TorControl::Error : status_str = "Error" ; break ;
case Tor::TorControl::NotConnected: status_str = "Not connected" ; break ;
case Tor::TorControl::Connecting: status_str = "Connecting" ; break ;
case Tor::TorControl::Authenticating: status_str = "Authenticating" ; break ;
case Tor::TorControl::Connected: status_str = "Connected" ; break ;
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 ;
}
switch(torstatus)
@ -74,12 +75,15 @@ void TorControlDialog::statusChanged()
case Tor::TorControl::TorReady: torstatus_str = "Tor ready" ; break ;
}
//torStatus_LB->setText(torstatus_str + "(" + status_str + ")") ;
torStatus_LB->setText(status_str) ;
torStatus_LB->setText(torstatus_str) ;
//torStatus_LB->setText(tor_control_status_str) ;
QVariantMap qvm = mTorManager->control()->bootstrapStatus();
QString bootstrapstatus_str ;
std::cerr << "Tor control status: " << tor_control_status_str.toStdString() << std::endl;
std::cerr << "Tor status: " << torstatus_str.toStdString() << std::endl;
std::cerr << "Bootstrap status map: " << std::endl;
for(auto it(qvm.begin());it!=qvm.end();++it)
@ -142,11 +146,9 @@ void TorControlDialog::showLog()
TorControlDialog::TorStatus TorControlDialog::checkForTor()
{
switch(mTorManager->control()->status())
switch(mTorManager->control()->torStatus())
{
case Tor::TorControl::Connected: usleep(1*1000*1000);return TOR_STATUS_OK ;
case Tor::TorControl::Error: return TOR_STATUS_FAIL ;
case Tor::TorControl::TorReady: usleep(1*1000*1000);return TOR_STATUS_OK ;
default:
return TOR_STATUS_UNKNOWN ;
}

View File

@ -59,7 +59,17 @@
///
/// \brief hiddenServiceIncomingTab index of hidden serice incoming tab
///
const static uint32_t hiddenServiceIncomingTab = 2;
///
#ifdef RETROTOR
const static uint32_t TAB_HIDDEN_SERVICE_INCOMING = 1;
const static uint32_t TAB_IP_FILTERS = 99; // This is a trick: these tabs do not exist, so enabling/disabling them has no effect
const static uint32_t TAB_RELAYS = 99;
#else
const static uint32_t TAB_IP_FILTERS = 1;
const static uint32_t TAB_HIDDEN_SERVICE_INCOMING = 2;
const static uint32_t TAB_RELAYS = 3;
#endif
//#define SERVER_DEBUG 1
@ -71,6 +81,24 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags)
manager = NULL ;
#ifdef RETROTOR
ui.tabWidget->removeTab(3) ; // remove relays. Not useful in Tor mode.
ui.tabWidget->removeTab(1) ; // remove IP filters. Not useful in Tor mode.
ui.hiddenServiceTab->removeTab(1) ; // remove the Automatic I2P/BOB tab
ui.hiddenpage_proxyAddress_i2p->hide() ;
ui.hiddenpage_proxyLabel_i2p->hide() ;
ui.hiddenpage_proxyPort_i2p->hide() ;
ui.label_i2p_outgoing->hide() ;
ui.iconlabel_i2p_outgoing->hide() ;
ui.plainTextEdit->hide() ;
ui.hiddenpage_configuration->hide() ;
ui.l_hiddenpage_configuration->hide() ;
ui.hiddenpageInHelpPlainTextEdit->hide() ;
ui.hiddenpage_outHeader->setText(tr("Tor has been automatically configured by Retroshare. You shouldn't need to change anything here.")) ;
ui.hiddenpage_inHeader->setText(tr("Tor has been automatically configured by Retroshare. You shouldn't need to change anything here.")) ;
#endif
ui.filteredIpsTable->setHorizontalHeaderItem(COLUMN_RANGE,new QTableWidgetItem(tr("IP Range"))) ;
ui.filteredIpsTable->setHorizontalHeaderItem(COLUMN_STATUS,new QTableWidgetItem(tr("Status"))) ;
ui.filteredIpsTable->setHorizontalHeaderItem(COLUMN_ORIGIN,new QTableWidgetItem(tr("Origin"))) ;
@ -98,7 +126,7 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags)
for(std::list<std::string>::const_iterator it(ip_servers.begin());it!=ip_servers.end();++it)
ui.IPServersLV->addItem(QString::fromStdString(*it)) ;
ui.hiddenServiceTab->setTabEnabled(hiddenServiceIncomingTab, false);
ui.hiddenServiceTab->setTabEnabled(TAB_HIDDEN_SERVICE_INCOMING, false);
ui.gbBob->setEnabled(false);
ui.swBobAdvanced->setCurrentIndex(0);
@ -195,7 +223,6 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags)
QObject::connect(ui.enableCheckBox,SIGNAL(toggled(bool)),this,SLOT(updateRelayMode()));
QObject::connect(ui.serverCheckBox,SIGNAL(toggled(bool)),this,SLOT(updateRelayMode()));
}
void ServerPage::saveAndTestInProxy()
@ -299,8 +326,8 @@ void ServerPage::load()
if (mIsHiddenNode)
{
mHiddenType = detail.hiddenType;
ui.tabWidget->setTabEnabled(1,false) ; // ip filter
ui.tabWidget->setTabEnabled(3,false) ; // relay
ui.tabWidget->setTabEnabled(TAB_IP_FILTERS,false) ; // ip filter
ui.tabWidget->setTabEnabled(TAB_RELAYS,false) ; // relay
loadHiddenNode();
return;
}
@ -856,6 +883,8 @@ void ServerPage::toggleUPnP()
settingChangeable = true;
}
// Shouldn't we use readOnly instead of enabled??
if (settingChangeable)
{
ui.localAddress->setEnabled(false);
@ -1048,7 +1077,7 @@ void ServerPage::loadHiddenNode()
ui.label_dynDNS->setVisible(false);
ui.dynDNS ->setVisible(false);
ui.hiddenServiceTab->setTabEnabled(hiddenServiceIncomingTab, true);
ui.hiddenServiceTab->setTabEnabled(TAB_HIDDEN_SERVICE_INCOMING, true);
/* Addresses must be set here - otherwise can't edit it */
/* set local address */

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1220</width>
<height>896</height>
<width>1283</width>
<height>917</height>
</rect>
</property>
<layout class="QVBoxLayout" name="ServerPageVLayout">
@ -26,7 +26,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tabNetConf">
<attribute name="title">
@ -810,7 +810,7 @@ behind a firewall or a VPN.</string>
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="hiddenServiceTabManual">
<attribute name="title">

View File

@ -363,16 +363,16 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
TorControlDialog tcd(torManager) ;
tcd.show();
while(tcd.checkForHiddenService() != TorControlDialog::HIDDEN_SERVICE_STATUS_OK) // runs until some status is reached: either tor works, or it fails.
{
QCoreApplication::processEvents();
usleep(0.2*1000*1000) ;
}
for(uint32_t i=0;i<10;++i) // give some time (2 secs) to see what's going on
while(tcd.checkForTor() != TorControlDialog::TOR_STATUS_OK || tcd.checkForHiddenService() != TorControlDialog::HIDDEN_SERVICE_STATUS_OK) // runs until some status is reached: either tor works, or it fails.
{
QCoreApplication::processEvents();
usleep(0.2*1000*1000) ;
}
// for(uint32_t i=0;i<10;++i) // give some time (2 secs) to see what's going on
// {
// QCoreApplication::processEvents();
// usleep(0.2*1000*1000) ;
// }
tcd.hide();