From 9684b2ed94122d4977753226beecb0ae48e734a7 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 19 Dec 2021 18:40:44 +0100 Subject: [PATCH] code cleaning --- libretroshare/src/libretroshare.pro | 3 +- libretroshare/src/tor/AddOnionCommand.h | 4 - libretroshare/src/tor/CryptoKey.cpp | 1 - libretroshare/src/tor/GetConfCommand.h | 7 +- libretroshare/src/tor/HiddenService.cpp | 3 +- libretroshare/src/tor/HiddenService.h | 1 - libretroshare/src/tor/PendingOperation.h | 14 --- libretroshare/src/tor/ProtocolInfoCommand.h | 2 - libretroshare/src/tor/SetConfCommand.cpp | 19 --- libretroshare/src/tor/SetConfCommand.h | 4 - libretroshare/src/tor/TorControl.cpp | 122 +------------------- libretroshare/src/tor/TorControl.h | 29 +---- libretroshare/src/tor/TorControlCommand.cpp | 2 - libretroshare/src/tor/TorControlCommand.h | 1 - libretroshare/src/tor/TorControlSocket.cpp | 4 - libretroshare/src/tor/TorControlSocket.h | 3 - libretroshare/src/tor/TorManager.cpp | 7 -- libretroshare/src/tor/TorManager.h | 12 -- libretroshare/src/tor/TorProcess.cpp | 71 +----------- libretroshare/src/tor/bytearray.h | 2 + 20 files changed, 14 insertions(+), 297 deletions(-) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 4811fa2d6..e3bc28006 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -737,8 +737,7 @@ HEADERS += tor/AddOnionCommand.h \ tor/TorControlCommand.h \ tor/TorControlSocket.h \ tor/TorManager.h \ - tor/TorProcess.h \ - tor/Useful.h + tor/TorProcess.h SOURCES += tor/AddOnionCommand.cpp \ tor/AuthenticateCommand.cpp \ diff --git a/libretroshare/src/tor/AddOnionCommand.h b/libretroshare/src/tor/AddOnionCommand.h index fddab89af..4b20de986 100644 --- a/libretroshare/src/tor/AddOnionCommand.h +++ b/libretroshare/src/tor/AddOnionCommand.h @@ -41,9 +41,6 @@ class HiddenService; class AddOnionCommand : public TorControlCommand { - // Q_PROPERTY(std::string errorMessage READ errorMessage CONSTANT) - // Q_PROPERTY(bool successful READ isSuccessful CONSTANT) - public: AddOnionCommand(HiddenService *service); @@ -52,7 +49,6 @@ public: std::string errorMessage() const { return m_errorMessage; } bool isSuccessful() const; -// signals: void set_succeeded_callback(const std::function& f) { mSucceeded=f;} void set_failed_callback(const std::function& f) { mFailed=f;} diff --git a/libretroshare/src/tor/CryptoKey.cpp b/libretroshare/src/tor/CryptoKey.cpp index 95fdab016..802caaf0c 100644 --- a/libretroshare/src/tor/CryptoKey.cpp +++ b/libretroshare/src/tor/CryptoKey.cpp @@ -33,7 +33,6 @@ #include #include "CryptoKey.h" -#include "Useful.h" #include #include diff --git a/libretroshare/src/tor/GetConfCommand.h b/libretroshare/src/tor/GetConfCommand.h index b6595fbf3..d3ca3bfc3 100644 --- a/libretroshare/src/tor/GetConfCommand.h +++ b/libretroshare/src/tor/GetConfCommand.h @@ -30,8 +30,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef GETCONFCOMMAND_H -#define GETCONFCOMMAND_H +#pragma once #include #include "TorControlCommand.h" @@ -41,8 +40,6 @@ namespace Tor class GetConfCommand : public TorControlCommand { - // Q_PROPERTY(QVariantMap results READ results CONSTANT) - public: enum Type { GetConf, @@ -69,5 +66,3 @@ private: }; } - -#endif // GETCONFCOMMAND_H diff --git a/libretroshare/src/tor/HiddenService.cpp b/libretroshare/src/tor/HiddenService.cpp index 4cf3325dc..a6b083eae 100644 --- a/libretroshare/src/tor/HiddenService.cpp +++ b/libretroshare/src/tor/HiddenService.cpp @@ -33,7 +33,6 @@ #include "HiddenService.h" #include "TorControl.h" #include "CryptoKey.h" -#include "Useful.h" #include "util/rsdir.h" #include @@ -102,7 +101,7 @@ void HiddenService::setServiceId(const ByteArray& sid) void HiddenService::setPrivateKey(const CryptoKey &key) { if (m_privateKey.isLoaded()) { - BUG() << "Cannot change the private key on an existing HiddenService"; + RsErr() << "Cannot change the private key on an existing HiddenService"; return; } diff --git a/libretroshare/src/tor/HiddenService.h b/libretroshare/src/tor/HiddenService.h index b924a767a..0e50e93b9 100644 --- a/libretroshare/src/tor/HiddenService.h +++ b/libretroshare/src/tor/HiddenService.h @@ -86,7 +86,6 @@ public: void addTarget(const Target &target); void addTarget(uint16_t servicePort, std::string targetAddress, uint16_t targetPort); -//private slots: void servicePublished(); private: diff --git a/libretroshare/src/tor/PendingOperation.h b/libretroshare/src/tor/PendingOperation.h index 4a75b1c9e..5115f3252 100644 --- a/libretroshare/src/tor/PendingOperation.h +++ b/libretroshare/src/tor/PendingOperation.h @@ -49,11 +49,6 @@ */ class PendingOperation { -// Q_PROPERTY(bool isFinished READ isFinished NOTIFY finished FINAL) -// Q_PROPERTY(bool isSuccess READ isSuccess NOTIFY success FINAL) -// Q_PROPERTY(bool isError READ isError NOTIFY error FINAL) -// Q_PROPERTY(std::string errorMessage READ errorMessage NOTIFY finished FINAL) - public: PendingOperation(); @@ -62,15 +57,6 @@ public: bool isError() const; std::string errorMessage() const; -// signals: -// // Always emitted once when finished, regardless of status -// void finished(); -// -// // One of error() or success() is emitted once -// void error(const std::string &errorMessage); -// void success(); - -//protected slots: void finishWithError(const std::string &errorMessage); void finishWithSuccess(); diff --git a/libretroshare/src/tor/ProtocolInfoCommand.h b/libretroshare/src/tor/ProtocolInfoCommand.h index 3d4f8baf2..b90e2fe7c 100644 --- a/libretroshare/src/tor/ProtocolInfoCommand.h +++ b/libretroshare/src/tor/ProtocolInfoCommand.h @@ -52,8 +52,6 @@ public: }; typedef uint8_t AuthMethod; - // RS_REGISTER_FLAGS_TYPE(AuthMethod); // not usable here because we're inside a class (and worse, inside a namespace) - ProtocolInfoCommand(TorControl *manager); ByteArray build(); diff --git a/libretroshare/src/tor/SetConfCommand.cpp b/libretroshare/src/tor/SetConfCommand.cpp index 0285c8c8b..463305731 100644 --- a/libretroshare/src/tor/SetConfCommand.cpp +++ b/libretroshare/src/tor/SetConfCommand.cpp @@ -55,25 +55,6 @@ ByteArray SetConfCommand::build(const std::string &key, const std::string &value return build(std::list > { std::make_pair(key, value) } ); } -// ByteArray SetConfCommand::build(const std::list > &data) -// { -// QList > out; -// -// for (QVariantMap::ConstIterator it = data.begin(); it != data.end(); it++) { -// QByteArray key = it.key().toLatin1(); -// -// if (static_cast(it.value().type()) == QMetaType::QVariantList) { -// QVariantList values = it.value().value(); -// foreach (const QVariant &value, values) -// out.append(qMakePair(key, value.toString().toLatin1())); -// } else { -// out.append(qMakePair(key, it.value().toString().toLatin1())); -// } -// } -// -// return build(out); -// } - ByteArray SetConfCommand::build(const std::list >& data) { ByteArray out(m_resetMode ? "RESETCONF" : "SETCONF"); diff --git a/libretroshare/src/tor/SetConfCommand.h b/libretroshare/src/tor/SetConfCommand.h index 8fb247e84..bf7713038 100644 --- a/libretroshare/src/tor/SetConfCommand.h +++ b/libretroshare/src/tor/SetConfCommand.h @@ -40,9 +40,6 @@ namespace Tor class SetConfCommand : public TorControlCommand { - //Q_PROPERTY(QString errorMessage READ errorMessage CONSTANT) - //Q_PROPERTY(bool successful READ isSuccessful CONSTANT) - public: SetConfCommand(); @@ -54,7 +51,6 @@ public: std::string errorMessage() const { return m_errorMessage; } bool isSuccessful() const; -//signals: void set_ConfSucceeded_callback(const std::function& f) { mConfSucceeded=f; } void set_ConfFailed_callback (const std::function& f){ mConfFailed=f; } diff --git a/libretroshare/src/tor/TorControl.cpp b/libretroshare/src/tor/TorControl.cpp index 14443568b..b1803dd4e 100644 --- a/libretroshare/src/tor/TorControl.cpp +++ b/libretroshare/src/tor/TorControl.cpp @@ -62,78 +62,13 @@ static std::ostream& torctrldebug() #define torCtrlDebug torctrldebug - using namespace Tor; -namespace Tor { - -// class TorControlPrivate : public QObject -// { -// Q_OBJECT -// -// public: -// TorControl *q; -// -// TorControlSocket *socket; -// std::string torAddress; -// std::string errorMessage; -// std::string torVersion; -// ByteArray authPassword; -// std::string socksAddress; -// QList services; -// uint16_t controlPort, socksPort; -// TorControl::Status status; -// TorControl::TorStatus torStatus; -// std::map bootstrapStatus; -// bool hasOwnership; -// -// TorControlPrivate(TorControl *parent); -// -// void setStatus(TorControl::Status status); -// void setTorStatus(TorControl::TorStatus status); -// -// void getTorInfo(); -// void publishServices(); -// -// public slots: -// void socketConnected(); -// void socketDisconnected(); -// void socketError(); -// -// void authenticateReply(); -// void protocolInfoReply(); -// void getTorInfoReply(); -// void setError(const std::string &message); -// -// void statusEvent(int code, const ByteArray &data); -// void updateBootstrap(const std::list &data); -// }; - -} - TorControl::TorControl() { mSocket = new TorControlSocket(this); } -// TorControlPrivate::TorControlPrivate(TorControl *parent) -// : QObject(parent), q(parent), controlPort(0), socksPort(0), -// status(TorControl::NotConnected), torStatus(TorControl::TorUnknown), -// hasOwnership(false) -// { -// socket = new TorControlSocket(); -// -// // QObject::connect(socket, SIGNAL(connected()), this, SLOT(socketConnected())); -// // QObject::connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); -// // QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError())); -// // QObject::connect(socket, SIGNAL(error(QString)), this, SLOT(setError(QString))); -// } - -// QNetworkProxy TorControl::connectionProxy() -// { -// return QNetworkProxy(QNetworkProxy::Socks5Proxy, d->socksAddress.toString(), d->socksPort); -// } - static RsTorConnectivityStatus torConnectivityStatus(Tor::TorControl::Status t) { switch(t) @@ -179,11 +114,6 @@ void TorControl::setStatus(TorControl::Status n) rsEvents->sendEvent(ev); } mStatusChanged_callback(mStatus, old); - -// if (mStatus == TorControl::Connected && old < TorControl::Connected) -// socketConnected();//mConnected_callback(); -// else if (mStatus < TorControl::Connected && old >= TorControl::Connected) -// socketDisconnected();//mDisconnected_callback(); } void TorControl::setTorStatus(TorControl::TorStatus n) @@ -274,10 +204,8 @@ void TorControl::connect(const std::string &address, uint16_t port) mControlPort = port; setTorStatus(TorUnknown); - //bool b = d->socket->blockSignals(true); if(mSocket->isRunning()) mSocket->fullstop(); - //d->socket->blockSignals(b); setStatus(Connecting); @@ -340,7 +268,7 @@ void TorControl::authenticate() 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()); } @@ -372,7 +300,7 @@ void TorControl::protocolInfoReply(TorControlCommand *sender) if (mStatus == TorControl::Authenticating) { AuthenticateCommand *auth = new AuthenticateCommand; - //connect(auth, &TorControlCommand::finished, this, &TorControl::authenticateReply); + auth->set_finished_callback( [this](TorControlCommand *sender) { authenticateReply(sender); }); ByteArray data; @@ -456,28 +384,7 @@ void TorControl::getTorInfo() std::list keys{ "status/circuit-established","status/bootstrap-phase" }; -#ifdef TODO - /* If these are set in the config, they override the automatic behavior. */ - SettingsObject settings("tor"); - QHostAddress forceAddress(settings.read("socksAddress").toString()); - uint16_t port = (uint16_t)settings.read("socksPort").toInt(); - - if (!forceAddress.isNull() && port) { - torCtrlDebug() << "torctrl: Using manually specified SOCKS connection settings"; - socksAddress = forceAddress; - socksPort = port; - - if(rsEvents) - { - auto ev = std::make_shared(); - - ev->mTorManagerEventType = RsTorManagerEventCode::TOR_CONNECTIVITY_CHANGED; - rsEvents->sendEvent(ev); - } - } - else -#endif - keys .push_back("net/listeners/socks"); + keys.push_back("net/listeners/socks"); mSocket->sendCommand(command, command->build(keys)); } @@ -485,7 +392,7 @@ void TorControl::getTorInfo() void TorControl::getTorInfoReply(TorControlCommand *sender) { GetConfCommand *command = dynamic_cast(sender); - if (!command)// || !isConnected()) + if (!command) return; std::list listenAddresses = splitQuotedStrings(command->get("net/listeners/socks").front(), ' '); @@ -557,20 +464,6 @@ void TorControl::publishServices() } std::cerr << std::endl; -#ifdef TODO - SettingsObject settings("tor"); - if (settings.read("neverPublishServices").toBool()) - { - torCtrlDebug() << "torctrl: Skipping service publication because neverPublishService is enabled" << std::endl; - - /* Call servicePublished under the assumption that they're published externally. */ - for (QList::Iterator it = services.begin(); it != services.end(); ++it) - (*it)->servicePublished(); - - return; - } -#endif - if (torVersionAsNewAs("0.2.7")) { for(HiddenService *service: mServices) { @@ -697,8 +590,6 @@ void TorControl::updateBootstrap(const std::list &data) mBootstrapStatus[key.toLower().toString()] = value.toString(); } - //torCtrlDebug() << bootstrapStatus << std::endl; - if(rsEvents) { auto ev = std::make_shared(); @@ -716,7 +607,6 @@ TorControlCommand *TorControl::getConfiguration(const std::string& options) command->set_replyLine_callback([this](int code, const ByteArray &data) { statusEvent(code,data); }); mSocket->sendCommand(command, command->build(options)); - //QQmlEngine::setObjectOwnership(command, QQmlEngine::CppOwnership); return command; } @@ -726,7 +616,6 @@ TorControlCommand *TorControl::setConfiguration(const std::listsetResetMode(true); mSocket->sendCommand(command, command->build(options)); - //QQmlEngine::setObjectOwnership(command, QQmlEngine::CppOwnership); return command; } @@ -744,7 +633,6 @@ public: { assert(!command); command = new GetConfCommand(GetConfCommand::GetInfo); - //QObject::connect(command, &TorControlCommand::finished, this, &SaveConfigOperation::configTextReply); command->set_finished_callback([this](TorControlCommand *sender){ configTextReply(sender); }); socket->sendCommand(command, command->build(std::list { "config-text" , "config-file" } )); @@ -832,11 +720,9 @@ PendingOperation *TorControl::saveConfiguration() SaveConfigOperation *operation = new SaveConfigOperation(); - //QObject::connect(operation, &PendingOperation::finished, operation, &QObject::deleteLater); operation->set_finished_callback( [operation]() { delete operation; }); operation->start(mSocket); - //QQmlEngine::setObjectOwnership(operation, QQmlEngine::CppOwnership); return operation; } diff --git a/libretroshare/src/tor/TorControl.h b/libretroshare/src/tor/TorControl.h index d9f550f6b..941c088d2 100644 --- a/libretroshare/src/tor/TorControl.h +++ b/libretroshare/src/tor/TorControl.h @@ -48,19 +48,6 @@ class TorControlCommand; class TorControl : public TorControlSocketClient { -// Q_ENUMS(Status TorStatus) -// -// // Status of the control connection -// Q_PROPERTY(Status status READ status NOTIFY statusChanged) -// // Status of Tor (and whether it believes it can connect) -// Q_PROPERTY(TorStatus torStatus READ torStatus NOTIFY torStatusChanged) -// // Whether it's possible to make a SOCKS connection and connect -// Q_PROPERTY(bool hasConnectivity READ hasConnectivity NOTIFY connectivityChanged) -// Q_PROPERTY(QString torVersion READ torVersion NOTIFY connected) -// Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY statusChanged) -// Q_PROPERTY(QVariantMap bootstrapStatus READ bootstrapStatus NOTIFY bootstrapStatusChanged) -// Q_PROPERTY(bool hasOwnership READ hasOwnership NOTIFY hasOwnershipChanged) - public: enum Status { @@ -111,18 +98,9 @@ public: void addHiddenService(HiddenService *service); std::map bootstrapStatus() const; - /*Q_INVOKABLE*/ TorControlCommand *getConfiguration(const std::string &options); - /*Q_INVOKABLE*/ TorControlCommand *setConfiguration(const std::list > &options); - /*Q_INVOKABLE*/ PendingOperation *saveConfiguration(); - -//signals: -// void statusChanged(int newStatus, int oldStatus); -// void torStatusChanged(int newStatus, int oldStatus); -// void connected(); -// void disconnected(); -// void connectivityChanged(); -// void bootstrapStatusChanged(); -// void hasOwnershipChanged(); + TorControlCommand *getConfiguration(const std::string &options); + TorControlCommand *setConfiguration(const std::list > &options); + PendingOperation *saveConfiguration(); void set_statusChanged_callback(const std::function& f) { mStatusChanged_callback = f ;} void set_connected_callback(const std::function& f) { mConnected_callback = f ;} @@ -130,7 +108,6 @@ public: virtual void socketError(const std::string &s) override; -//public slots: /* Instruct Tor to shutdown */ void shutdown(); /* Call shutdown(), and wait synchronously for the command to be written */ diff --git a/libretroshare/src/tor/TorControlCommand.cpp b/libretroshare/src/tor/TorControlCommand.cpp index 2bfc17a71..127b6a04a 100644 --- a/libretroshare/src/tor/TorControlCommand.cpp +++ b/libretroshare/src/tor/TorControlCommand.cpp @@ -43,14 +43,12 @@ TorControlCommand::TorControlCommand() void TorControlCommand::onReply(int statusCode, const ByteArray &data) { - //emit replyLine(statusCode, data); mReplyLine(statusCode, data); } void TorControlCommand::onFinished(int statusCode) { m_finalStatus = statusCode; - //emit finished(); mFinished(this); } diff --git a/libretroshare/src/tor/TorControlCommand.h b/libretroshare/src/tor/TorControlCommand.h index 6e0a2a176..8dee6aadb 100644 --- a/libretroshare/src/tor/TorControlCommand.h +++ b/libretroshare/src/tor/TorControlCommand.h @@ -50,7 +50,6 @@ public: int statusCode() const { return m_finalStatus; } -//signals: void set_replyLine_callback( const std::function& f) { mReplyLine=f ; } void set_finished_callback( const std::function& f) { mFinished=f; }; diff --git a/libretroshare/src/tor/TorControlSocket.cpp b/libretroshare/src/tor/TorControlSocket.cpp index 5d69dc7de..e9740515a 100644 --- a/libretroshare/src/tor/TorControlSocket.cpp +++ b/libretroshare/src/tor/TorControlSocket.cpp @@ -40,8 +40,6 @@ using namespace Tor; TorControlSocket::TorControlSocket(TorControlSocketClient *client) : RsThreadedTcpSocket(),currentCommand(0), inDataReply(false),mClient(client) { - //connect(this, SIGNAL(readyRead()), this, SLOT(process())); - //connect(this, SIGNAL(disconnected()), this, SLOT(clear())); } TorControlSocket::~TorControlSocket() @@ -84,8 +82,6 @@ void TorControlSocket::registerEvent(const ByteArray &event, TorControlCommand * ByteArray data("SETEVENTS"); for(auto it:eventCommands) { - //const ByteArray &key, eventCommands.keys()) { - //data += key; data += ' '; data += it.first; } diff --git a/libretroshare/src/tor/TorControlSocket.h b/libretroshare/src/tor/TorControlSocket.h index b5ba4181c..40437ed76 100644 --- a/libretroshare/src/tor/TorControlSocket.h +++ b/libretroshare/src/tor/TorControlSocket.h @@ -67,12 +67,9 @@ public: virtual int tick() override; std::string peerAddress() const; -//signals: -// void error(const std::string& message); const std::string& errorString() const { return m_errorMessage ;} -//private slots: void process(); void clear(); diff --git a/libretroshare/src/tor/TorManager.cpp b/libretroshare/src/tor/TorManager.cpp index c4e2d8789..d2baa128b 100644 --- a/libretroshare/src/tor/TorManager.cpp +++ b/libretroshare/src/tor/TorManager.cpp @@ -101,7 +101,6 @@ TorManagerPrivate::TorManagerPrivate(TorManager *parent) , configNeeded(false) , hiddenService(NULL) { - //connect(control, SIGNAL(statusChanged(int,int)), SLOT(controlStatusChanged(int))); control->set_statusChanged_callback([this](int new_status,int /*old_status*/) { controlStatusChanged(new_status); }); } @@ -150,9 +149,6 @@ void TorManager::setHiddenServiceDirectory(const std::string &path) static bool test_listening_port(const std::string& /*address*/,uint16_t port) { -// sockaddr_storage addr; -// sockaddr_storage_fromString(address,addr); -// int sockfd; struct sockaddr_in serv_addr ; @@ -227,9 +223,6 @@ bool TorManager::setupHiddenService() d->hiddenService = new Tor::HiddenService(this,legacyDir); RsDbg() << "Creating new hidden service." << std::endl; - - // connect(d->hiddenService, SIGNAL(privateKeyChanged()), this, SLOT(hiddenServicePrivateKeyChanged())) ; - // connect(d->hiddenService, SIGNAL(hostnameChanged()), this, SLOT(hiddenServiceHostnameChanged())) ; } assert(d->hiddenService); diff --git a/libretroshare/src/tor/TorManager.h b/libretroshare/src/tor/TorManager.h index c9a5e3769..5a62f6d00 100644 --- a/libretroshare/src/tor/TorManager.h +++ b/libretroshare/src/tor/TorManager.h @@ -49,16 +49,6 @@ class TorManagerPrivate; class TorManager : public HiddenServiceClient, public RsThread, public RsTor { - // Q_OBJECT - - // Q_PROPERTY(bool configurationNeeded READ configurationNeeded NOTIFY configurationNeededChanged) - // Q_PROPERTY(QStringList logMessages READ logMessages CONSTANT) - // Q_PROPERTY(Tor::TorProcess* process READ process CONSTANT) - // Q_PROPERTY(Tor::TorControl* control READ control CONSTANT) - // Q_PROPERTY(bool hasError READ hasError NOTIFY errorChanged) - // Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorChanged) - // Q_PROPERTY(QString torDataDirectory READ torDataDirectory WRITE setTorDataDirectory) - public: static TorManager *instance(); @@ -85,10 +75,8 @@ public: bool getHiddenServiceInfo(std::string& service_id,std::string& service_onion_address,uint16_t& service_port, std::string& service_target_address,uint16_t& target_port); bool getProxyServerInfo(std::string &proxy_server_adress, uint16_t& proxy_server_port); -//public slots: bool startTorManager(); -//private slots: virtual void hiddenServiceOnline() override {} // do nothing here. virtual void hiddenServicePrivateKeyChanged() override; virtual void hiddenServiceHostnameChanged() override; diff --git a/libretroshare/src/tor/TorProcess.cpp b/libretroshare/src/tor/TorProcess.cpp index 92a4958e9..06ceb413f 100644 --- a/libretroshare/src/tor/TorProcess.cpp +++ b/libretroshare/src/tor/TorProcess.cpp @@ -271,7 +271,6 @@ void TorProcess::start() return; // stop the control thread } - int flags ; unix_fcntl_nonblock(fd[STDOUT_FILENO]); unix_fcntl_nonblock(fd[STDERR_FILENO]); @@ -309,8 +308,6 @@ void TorProcess::tick() } else if(mControlPortReadNbTries > 10) { - //errorMessageChanged(errorMessage); - //stateChanged(state); mState = Failed; m_client->processStateChanged(mState);// stateChanged(mState); } @@ -394,20 +391,18 @@ bool TorProcess::ensureFilesExist() std::string TorProcess::torrcPath() const { - //return QDir::toNativeSeparators(dataDir) + QDir::separator() + QStringLiteral("torrc"); return RsDirUtil::makePath(mDataDir,"torrc"); } std::string TorProcess::controlPortFilePath() const { - //return QDir::toNativeSeparators(dataDir) + QDir::separator() + QStringLiteral("control-port"); return RsDirUtil::makePath(mDataDir,"control-port"); } bool TorProcess::tryReadControlPort() { FILE *file = RsDirUtil::rs_fopen(controlPortFilePath().c_str(),"r"); - std::cerr << "Trying to read control port" << std::endl; + RsDbg() << "Trying to read control port" ; if(file) { @@ -425,72 +420,10 @@ bool TorProcess::tryReadControlPort() if (!mControlHost.empty() && mControlPort > 0) { - std::cerr << "Got control host/port = " << mControlHost << ":" << mControlPort << std::endl; + RsDbg() << "Got control host/port = " << mControlHost << ":" << mControlPort ; return true; } } } return false; } -#ifdef TO_REMOVE -void TorProcessPrivate::processStarted() -{ - state = TorProcess::Connecting; - - /*emit*/ q->stateChanged(state); - /*emit*/ q->stateChanged(state); - - controlPortAttempts = 0; - controlPortTimer.start(); -} - -void TorProcessPrivate::processFinished() -{ - if (state < TorProcess::Starting) - return; - - controlPortTimer.stop(); - errorMessage = process.errorString().toStdString(); - - if (errorMessage.empty()) - errorMessage = "Process exited unexpectedly (code " + RsUtil::NumberToString(process.exitCode()) + ")"; - - state = TorProcess::Failed; - /*emit*/ q->errorMessageChanged(errorMessage); - /*emit*/ q->stateChanged(state); -} - -void TorProcessPrivate::processError(QProcess::ProcessError error) -{ - if (error == QProcess::FailedToStart || error == QProcess::Crashed) - processFinished(); -} - -void TorProcessPrivate::processReadable() -{ - while (process.bytesAvailable() > 0) - { - ByteArray line = process.readLine(2048).trimmed(); - - if (!line.empty()) - /*emit*/ q->logMessage(line.toString())); - } -} - - -TorProcessPrivate::TorProcessPrivate(TorProcess *q) - : q(q), state(TorProcess::NotStarted), controlPort(0), controlPortAttempts(0) -{ - connect(&process, &QProcess::started, this, &TorProcessPrivate::processStarted); - connect(&process, (void (QProcess::*)(int, QProcess::ExitStatus))&QProcess::finished, - this, &TorProcessPrivate::processFinished); - connect(&process, (void (QProcess::*)(QProcess::ProcessError))&QProcess::error, - this, &TorProcessPrivate::processError); - connect(&process, &QProcess::readyRead, this, &TorProcessPrivate::processReadable); - - controlPortTimer.setInterval(500); - connect(&controlPortTimer, &QTimer::timeout, this, &TorProcessPrivate::tryReadControlPort); -} - - -#endif diff --git a/libretroshare/src/tor/bytearray.h b/libretroshare/src/tor/bytearray.h index f2c1903cf..e81db0a17 100644 --- a/libretroshare/src/tor/bytearray.h +++ b/libretroshare/src/tor/bytearray.h @@ -11,6 +11,8 @@ #include "util/rsprint.h" #include "util/rsdebug.h" +// This class re-implements QByteArray from Qt library. + class ByteArray: public std::vector { public: