From 7e6156566ad32dc618f765eca337ae2fd8872a12 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 18 Dec 2021 18:14:49 +0100 Subject: [PATCH] fixed display of tor bootstrap status --- libretroshare/src/tor/TorControl.cpp | 11 +++--- libretroshare/src/tor/TorManager.cpp | 5 ++- .../src/TorControl/TorControlWindow.cpp | 32 +++++++++++------ .../src/TorControl/TorControlWindow.ui | 34 +++++++++++++++++-- 4 files changed, 62 insertions(+), 20 deletions(-) diff --git a/libretroshare/src/tor/TorControl.cpp b/libretroshare/src/tor/TorControl.cpp index 1baa0ac5c..14443568b 100644 --- a/libretroshare/src/tor/TorControl.cpp +++ b/libretroshare/src/tor/TorControl.cpp @@ -191,7 +191,6 @@ void TorControl::setTorStatus(TorControl::TorStatus n) if (n == mTorStatus) return; - TorControl::TorStatus old = mTorStatus; mTorStatus = n; if(rsEvents) @@ -316,10 +315,7 @@ void TorControl::authenticateReply(TorControlCommand *sender) setTorStatus(TorControl::TorUnknown); TorControlCommand *clientEvents = new TorControlCommand; - clientEvents->set_replyLine_callback([this](int code, const ByteArray &data) - { - statusEvent(code,data); // no async needed here. - }); + clientEvents->set_replyLine_callback([this](int code, const ByteArray &data) { statusEvent(code,data);}); mSocket->registerEvent(ByteArray("STATUS_CLIENT"), clientEvents); @@ -343,6 +339,7 @@ void TorControl::authenticate() ProtocolInfoCommand *command = new ProtocolInfoCommand(this); command->set_finished_callback( [this](TorControlCommand *sender) { protocolInfoReply(sender); }); + command->set_replyLine_callback([this](int code, const ByteArray &data) { statusEvent(code,data); }); //connect(command, &TorControlCommand::finished, this, &protocolInfoReply); mSocket->sendCommand(command, command->build()); } @@ -455,6 +452,7 @@ void TorControl::getTorInfo() GetConfCommand *command = new GetConfCommand(GetConfCommand::GetInfo); //connect(command, &TorControlCommand::finished, this, &TorControl::getTorInfoReply); command->set_finished_callback( [this](TorControlCommand *sender) { getTorInfoReply(sender); }); + command->set_replyLine_callback([this](int code, const ByteArray &data) { statusEvent(code,data); }); std::list keys{ "status/circuit-established","status/bootstrap-phase" }; @@ -680,6 +678,7 @@ void TorControl::statusEvent(int /* code */, const ByteArray &data) void TorControl::updateBootstrap(const std::list &data) { + std::cerr << "********** Updating bootstrap status ************" << std::endl; mBootstrapStatus.clear(); // WARN or NOTICE mBootstrapStatus["severity"] = (*data.begin()).toString(); @@ -714,6 +713,7 @@ void TorControl::updateBootstrap(const std::list &data) TorControlCommand *TorControl::getConfiguration(const std::string& options) { GetConfCommand *command = new GetConfCommand(GetConfCommand::GetConf); + command->set_replyLine_callback([this](int code, const ByteArray &data) { statusEvent(code,data); }); mSocket->sendCommand(command, command->build(options)); //QQmlEngine::setObjectOwnership(command, QQmlEngine::CppOwnership); @@ -862,7 +862,6 @@ bool TorControl::torVersionAsNewAs(const std::string& match) const auto matchSplit = ByteArray(match).split(ByteArray(".-")); int split_size = split.size(); - int i=0; auto b_split(split.begin()); auto b_matchsplit(matchSplit.begin()); diff --git a/libretroshare/src/tor/TorManager.cpp b/libretroshare/src/tor/TorManager.cpp index dd1c1f810..32ee79322 100644 --- a/libretroshare/src/tor/TorManager.cpp +++ b/libretroshare/src/tor/TorManager.cpp @@ -577,7 +577,10 @@ void TorManagerPrivate::processLogMessage(const std::string &message) std::cerr << "tor:" << message << std::endl; if (logMessages.size() >= 50) logMessages.pop_front(); - logMessages.push_back(message); + + auto p = message.find_first_of('\n'); + + logMessages.push_back((p==std::string::npos)?message:message.substr(0,p)); } void TorManagerPrivate::controlStatusChanged(int status) diff --git a/retroshare-gui/src/TorControl/TorControlWindow.cpp b/retroshare-gui/src/TorControl/TorControlWindow.cpp index 135a467fc..c0dab3442 100644 --- a/retroshare-gui/src/TorControl/TorControlWindow.cpp +++ b/retroshare-gui/src/TorControl/TorControlWindow.cpp @@ -42,7 +42,7 @@ TorControlDialog::TorControlDialog(QWidget *) QTimer *timer = new QTimer ; QObject::connect(timer,SIGNAL(timeout()),this,SLOT(showLog())) ; - timer->start(500) ; + timer->start(300) ; // Hide some debug output for the released version @@ -143,23 +143,33 @@ void TorControlDialog::showLog() std::string s ; std::list logmsgs = RsTor::logMessages() ; - bool can_print = false ; + bool can_print = false ; for(auto it(logmsgs.begin());it!=logmsgs.end();++it) - { + { s += *it + "\n" ; - if(already_seen.find(*it) == already_seen.end()) - { - can_print = true ; - already_seen.insert(*it); - } + if(already_seen.find(*it) == already_seen.end()) + { + can_print = true ; + already_seen.insert(*it); + } - if(can_print) + if(can_print) + { std::cerr << "[TOR DEBUG LOG] " << *it << std::endl; - } - std::cerr << "Connexion Proxy: " << RsTor::socksAddress() << ":" << QString::number(RsTor::socksPort()).toStdString() << std::endl; + QString s = QString::fromStdString(*it); + int n = s.indexOf(QString("Bootstrapped")); + + if(n >= 0) + { + torBootstrapStatus_LB->setText(s.mid(n+QString("Bootstrapped").length())); + QCoreApplication::processEvents(); // forces update + } + } + } + //std::cerr << "Connexion Proxy: " << RsTor::socksAddress() << ":" << QString::number(RsTor::socksPort()).toStdString() << std::endl; } TorControlDialog::TorStatus TorControlDialog::checkForTor(QString& error_msg) diff --git a/retroshare-gui/src/TorControl/TorControlWindow.ui b/retroshare-gui/src/TorControl/TorControlWindow.ui index 602146641..6077485e5 100644 --- a/retroshare-gui/src/TorControl/TorControlWindow.ui +++ b/retroshare-gui/src/TorControl/TorControlWindow.ui @@ -40,6 +40,12 @@ + + + 0 + 0 + + @@ -55,6 +61,12 @@ + + + 0 + 0 + + Tor status: @@ -79,8 +91,14 @@ + + + 0 + 0 + + - Hidden service address: + Hidden address: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -89,8 +107,14 @@ + + + 0 + 0 + + - Tor bootstrap status: + Tor status: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -106,6 +130,12 @@ + + + 0 + 0 + + Onion address: