diff --git a/libretroshare/src/tor/AddOnionCommand.cpp b/libretroshare/src/tor/AddOnionCommand.cpp index 667dfd57b..8b0f488fa 100644 --- a/libretroshare/src/tor/AddOnionCommand.cpp +++ b/libretroshare/src/tor/AddOnionCommand.cpp @@ -40,7 +40,7 @@ using namespace Tor; AddOnionCommand::AddOnionCommand(HiddenService *service) : m_service(service) { - Q_ASSERT(m_service); + assert(m_service); } bool AddOnionCommand::isSuccessful() const @@ -61,13 +61,14 @@ ByteArray AddOnionCommand::build() out += " NEW:BEST"; // this is v3, but without control of key type. Generates a RSA1024 key on older Tor versions. } - foreach (const HiddenService::Target &target, m_service->targets()) { + for(const HiddenService::Target& target: m_service->targets()) + { out += " Port="; - out += QByteArray::number(target.servicePort); + out += RsUtil::NumberToString(target.servicePort); out += ","; out += target.targetAddress; out += ":"; - out += QByteArray::number(target.targetPort); + out += RsUtil::NumberToString(target.targetPort); } out.append("\r\n"); @@ -82,8 +83,8 @@ void AddOnionCommand::onReply(int statusCode, const ByteArray &data) return; } - const QByteArray keyPrefix("PrivateKey="); - const QByteArray sidPrefix("ServiceID="); + const ByteArray keyPrefix("PrivateKey="); + const ByteArray sidPrefix("ServiceID="); if(data.startsWith("ServiceID=")){ ByteArray service_id = data.mid(sidPrefix.size()); diff --git a/libretroshare/src/tor/AddOnionCommand.h b/libretroshare/src/tor/AddOnionCommand.h index 1e8389cde..fddab89af 100644 --- a/libretroshare/src/tor/AddOnionCommand.h +++ b/libretroshare/src/tor/AddOnionCommand.h @@ -30,8 +30,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ADDONIONCOMMAND_H -#define ADDONIONCOMMAND_H +#pragma once #include "TorControlCommand.h" @@ -69,6 +68,3 @@ protected: }; } - -#endif // ADDONIONCOMMAND_H - diff --git a/libretroshare/src/tor/CryptoKey.h b/libretroshare/src/tor/CryptoKey.h index 7cb1d6562..ab6fb320f 100644 --- a/libretroshare/src/tor/CryptoKey.h +++ b/libretroshare/src/tor/CryptoKey.h @@ -30,12 +30,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CRYPTOKEY_H -#define CRYPTOKEY_H - -#include -#include -#include +#pragma once #include "bytearray.h" @@ -67,5 +62,3 @@ private: }; ByteArray torControlHashedPassword(const ByteArray &password); - -#endif // CRYPTOKEY_H diff --git a/libretroshare/src/tor/HiddenService.cpp b/libretroshare/src/tor/HiddenService.cpp index cb9adfa8a..cb991828a 100644 --- a/libretroshare/src/tor/HiddenService.cpp +++ b/libretroshare/src/tor/HiddenService.cpp @@ -83,7 +83,7 @@ void HiddenService::addTarget(const Target &target) m_targets.push_back(target); } -void HiddenService::addTarget(quint16 servicePort, std::string targetAddress, quint16 targetPort) +void HiddenService::addTarget(uint16_t servicePort, std::string targetAddress, uint16_t targetPort) { Target t = { targetAddress, servicePort, targetPort }; m_targets.push_back(t); diff --git a/libretroshare/src/tor/HiddenService.h b/libretroshare/src/tor/HiddenService.h index 2b69915f6..ae77d51ed 100644 --- a/libretroshare/src/tor/HiddenService.h +++ b/libretroshare/src/tor/HiddenService.h @@ -33,7 +33,6 @@ #ifndef HIDDENSERVICE_H #define HIDDENSERVICE_H -#include #include "CryptoKey.h" #include "bytearray.h" @@ -52,18 +51,15 @@ public: virtual void hiddenServiceHostnameChanged() =0; }; -class HiddenService : public QObject +class HiddenService { - Q_OBJECT - Q_DISABLE_COPY(HiddenService) - - friend class TorControlPrivate; + friend class TorControl; public: struct Target { std::string targetAddress; - quint16 servicePort, targetPort; + uint16_t servicePort, targetPort; }; enum Status @@ -89,9 +85,9 @@ public: const std::list &targets() const { return m_targets; } void addTarget(const Target &target); - void addTarget(quint16 servicePort, std::string targetAddress, quint16 targetPort); + void addTarget(uint16_t servicePort, std::string targetAddress, uint16_t targetPort); -private slots: +//private slots: void servicePublished(); private: @@ -106,6 +102,10 @@ private: void setStatus(Status newStatus); HiddenServiceClient *m_client; + + // make the object non copyable + HiddenService(const HiddenService& s) {} + HiddenService& operator=(const HiddenService& s) { return *this ; } }; } diff --git a/libretroshare/src/tor/PendingOperation.cpp b/libretroshare/src/tor/PendingOperation.cpp index adc4792a5..e22f63852 100644 --- a/libretroshare/src/tor/PendingOperation.cpp +++ b/libretroshare/src/tor/PendingOperation.cpp @@ -30,10 +30,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include "PendingOperation.h" -PendingOperation::PendingOperation(QObject *parent) - : QObject(parent), m_finished(false) +PendingOperation::PendingOperation() + : m_finished(false) { } @@ -65,20 +66,21 @@ void PendingOperation::finishWithError(const std::string &message) if (!m_finished) { m_finished = true; - emit finished(); - emit error(m_errorMessage); + + finished_callback(); + error_callback(m_errorMessage); } } void PendingOperation::finishWithSuccess() { - Q_ASSERT(m_errorMessage.empty()); + assert(m_errorMessage.empty()); if (!m_finished) { m_finished = true; - emit finished(); + finished_callback(); if (isSuccess()) - emit success(); + success_callback(); } } diff --git a/libretroshare/src/tor/PendingOperation.h b/libretroshare/src/tor/PendingOperation.h index e3a1716df..5965bfd26 100644 --- a/libretroshare/src/tor/PendingOperation.h +++ b/libretroshare/src/tor/PendingOperation.h @@ -30,10 +30,9 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef PENDINGOPERATION_H -#define PENDINGOPERATION_H +#pragma once -#include +#include /* Represents an asynchronous operation for reporting status * @@ -48,40 +47,41 @@ * PendingOperation will emit finished() and one of success() or * error() when completed. */ -class PendingOperation : public QObject +class PendingOperation { - Q_OBJECT - - 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) +// 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(QObject *parent = 0); + PendingOperation(); bool isFinished() const; bool isSuccess() const; bool isError() const; std::string errorMessage() const; -signals: - // Always emitted once when finished, regardless of status - void finished(); +// 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(); - // One of error() or success() is emitted once - void error(const std::string &errorMessage); - void success(); - -protected slots: +//protected slots: void finishWithError(const std::string &errorMessage); void finishWithSuccess(); + void set_finished_callback(const std::function& f) { finished_callback = f; } private: bool m_finished; std::string m_errorMessage; + + std::function finished_callback; + std::function success_callback; + std::function error_callback; + }; -Q_DECLARE_METATYPE(PendingOperation*) - -#endif diff --git a/libretroshare/src/tor/ProtocolInfoCommand.cpp b/libretroshare/src/tor/ProtocolInfoCommand.cpp index b1f773d96..867541e56 100644 --- a/libretroshare/src/tor/ProtocolInfoCommand.cpp +++ b/libretroshare/src/tor/ProtocolInfoCommand.cpp @@ -56,7 +56,7 @@ void ProtocolInfoCommand::onReply(int statusCode, const ByteArray &data) { std::list tokens = splitQuotedStrings(data.mid(5), ' '); - foreach (ByteArray token, tokens) + for(ByteArray token: tokens) { if (token.startsWith("METHODS=")) { diff --git a/libretroshare/src/tor/TorControl.cpp b/libretroshare/src/tor/TorControl.cpp index d9aeddc8e..1051a0abe 100644 --- a/libretroshare/src/tor/TorControl.cpp +++ b/libretroshare/src/tor/TorControl.cpp @@ -81,7 +81,7 @@ namespace Tor { // ByteArray authPassword; // std::string socksAddress; // QList services; -// quint16 controlPort, socksPort; +// uint16_t controlPort, socksPort; // TorControl::Status status; // TorControl::TorStatus torStatus; // std::map bootstrapStatus; @@ -177,14 +177,12 @@ void TorControl::setStatus(TorControl::Status n) rsEvents->sendEvent(ev); } -#ifdef TO_REMOVE - emit statusChanged(status, old); + mStatusChanged_callback(mStatus, old); - if (status == TorControl::Connected && old < TorControl::Connected) - emit connected(); - else if (status < TorControl::Connected && old >= TorControl::Connected) - emit disconnected(); -#endif + 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) @@ -194,10 +192,6 @@ void TorControl::setTorStatus(TorControl::TorStatus n) TorControl::TorStatus old = mTorStatus; mTorStatus = n; -#ifdef TO_REMOVE - emit torStatusChanged(torStatus, old); - emit connectivityChanged(); -#endif if(rsEvents) { @@ -255,7 +249,7 @@ std::string TorControl::socksAddress() const return mSocksAddress; } -quint16 TorControl::socksPort() const +uint16_t TorControl::socksPort() const { return mSocksPort; } @@ -275,7 +269,7 @@ void TorControl::setAuthPassword(const ByteArray &password) mAuthPassword = password; } -void TorControl::connect(const std::string &address, quint16 port) +void TorControl::connect(const std::string &address, uint16_t port) { if (status() > Connecting) { @@ -306,9 +300,9 @@ void TorControl::reconnect() mSocket->connectToHost(mTorAddress, mControlPort); } -void TorControl::authenticateReply() +void TorControl::authenticateReply(TorControlCommand *sender) { - AuthenticateCommand *command = qobject_cast(sender()); + AuthenticateCommand *command = dynamic_cast(sender); assert(command); assert(mStatus == TorControl::Authenticating); if (!command) @@ -384,17 +378,18 @@ void TorControl::protocolInfoReply(TorControlCommand *sender) if (mStatus == TorControl::Authenticating) { AuthenticateCommand *auth = new AuthenticateCommand; - connect(auth, &TorControlCommand::finished, this, &TorControl::authenticateReply); + //connect(auth, &TorControlCommand::finished, this, &TorControl::authenticateReply); + auth->set_finished_callback( [this](TorControlCommand *sender) { authenticateReply(sender); }); ByteArray data; ProtocolInfoCommand::AuthMethod methods = info->authMethods(); - if (methods.testFlag(ProtocolInfoCommand::AuthNull)) + if(methods & ProtocolInfoCommand::AuthNull) { torCtrlDebug() << "torctrl: Using null authentication" << std::endl; data = auth->build(); } - else if (methods.testFlag(ProtocolInfoCommand::AuthCookie) && !info->cookieFile().empty()) + else if ((methods & ProtocolInfoCommand::AuthCookie) && !info->cookieFile().empty()) { std::string cookieFile = info->cookieFile(); std::string cookieError; @@ -425,7 +420,7 @@ void TorControl::protocolInfoReply(TorControlCommand *sender) /* If we know a password and password authentication is allowed, try using that instead. * This is a strange corner case that will likely never happen in a normal configuration, * but it has happened. */ - if (methods.testFlag(ProtocolInfoCommand::AuthHashedPassword) && !mAuthPassword.empty()) + if ((methods & ProtocolInfoCommand::AuthHashedPassword) && !mAuthPassword.empty()) { torCtrlDebug() << "torctrl: Unable to read authentication cookie file:" << cookieError << std::endl; goto usePasswordAuth; @@ -436,7 +431,7 @@ void TorControl::protocolInfoReply(TorControlCommand *sender) return; } } - else if (methods.testFlag(ProtocolInfoCommand::AuthHashedPassword) && !mAuthPassword.empty()) + else if ((methods & ProtocolInfoCommand::AuthHashedPassword) && !mAuthPassword.empty()) { usePasswordAuth: torCtrlDebug() << "torctrl: Using hashed password authentication" << std::endl; @@ -444,7 +439,7 @@ void TorControl::protocolInfoReply(TorControlCommand *sender) } else { - if (methods.testFlag(ProtocolInfoCommand::AuthHashedPassword)) + if (methods & ProtocolInfoCommand::AuthHashedPassword) setError("Tor requires a control password to connect, but no password is configured."); else setError("Tor is not configured to accept any supported authentication methods."); @@ -461,7 +456,8 @@ void TorControl::getTorInfo() assert(isConnected()); GetConfCommand *command = new GetConfCommand(GetConfCommand::GetInfo); - connect(command, &TorControlCommand::finished, this, &TorControl::getTorInfoReply); + //connect(command, &TorControlCommand::finished, this, &TorControl::getTorInfoReply); + command->set_finished_callback( [this](TorControlCommand *sender) { getTorInfoReply(sender); }); std::list keys{ "status/circuit-established","status/bootstrap-phase" }; @@ -469,7 +465,7 @@ void TorControl::getTorInfo() /* If these are set in the config, they override the automatic behavior. */ SettingsObject settings("tor"); QHostAddress forceAddress(settings.read("socksAddress").toString()); - quint16 port = (quint16)settings.read("socksPort").toInt(); + uint16_t port = (uint16_t)settings.read("socksPort").toInt(); if (!forceAddress.isNull() && port) { torCtrlDebug() << "torctrl: Using manually specified SOCKS connection settings"; @@ -491,9 +487,9 @@ void TorControl::getTorInfo() mSocket->sendCommand(command, command->build(keys)); } -void TorControl::getTorInfoReply() +void TorControl::getTorInfoReply(TorControlCommand *sender) { - GetConfCommand *command = qobject_cast(sender()); + GetConfCommand *command = dynamic_cast(sender); if (!command || !isConnected()) return; @@ -503,7 +499,7 @@ void TorControl::getTorInfoReply() ByteArray value = unquotedString(add); int sepp = value.indexOf(':'); std::string address(value.mid(0, sepp).toString()); - quint16 port = (quint16)value.mid(sepp+1).toInt(); + uint16_t port = (uint16_t)value.mid(sepp+1).toInt(); /* Use the first address that matches the one used for this control connection. If none do, * just use the first address and rely on the user to reconfigure if necessary (not a problem; @@ -586,7 +582,8 @@ void TorControl::publishServices() else torCtrlDebug() << "torctrl: Publishing hidden service: " << service->hostname() << std::endl; AddOnionCommand *onionCommand = new AddOnionCommand(service); - QObject::connect(onionCommand, &AddOnionCommand::succeeded, service, &HiddenService::servicePublished); + //protocolInfoReplyQObject::connect(onionCommand, &AddOnionCommand::succeeded, service, &HiddenService::servicePublished); + onionCommand->set_succeeded_callback( [service]() { service->servicePublished(); }); mSocket->sendCommand(onionCommand, onionCommand->build()); } } else { @@ -618,7 +615,8 @@ void TorControl::publishServices() torConfig.push_back(std::make_pair("HiddenServicePort", target)); } - QObject::connect(command, &SetConfCommand::setConfSucceeded, service, &HiddenService::servicePublished); + command->set_ConfSucceeded_callback( [service]() { service->servicePublished(); }); + //QObject::connect(command, &SetConfCommand::setConfSucceeded, service, &HiddenService::servicePublished); } if (!torConfig.empty()) @@ -650,10 +648,8 @@ void TorControl::shutdownSync() mSocket->close(); } -void TorControl::statusEvent(int code, const ByteArray &data) +void TorControl::statusEvent(int /* code */, const ByteArray &data) { - Q_UNUSED(code); - std::list tokens = splitQuotedStrings(data.trimmed(), ' '); if (tokens.size() < 3) return; @@ -673,9 +669,9 @@ void TorControl::statusEvent(int code, const ByteArray &data) void TorControl::updateBootstrap(const std::list &data) { - bootstrapStatus.clear(); + mBootstrapStatus.clear(); // WARN or NOTICE - bootstrapStatus["severity"] = (*data.begin()).toString(); + mBootstrapStatus["severity"] = (*data.begin()).toString(); auto dat = data.begin(); ++dat; @@ -688,7 +684,7 @@ void TorControl::updateBootstrap(const std::list &data) if (equals >= 0) value = unquotedString((*dat).mid(equals + 1)); - bootstrapStatus[key.toLower().toString()] = value.toString(); + mBootstrapStatus[key.toLower().toString()] = value.toString(); } //torCtrlDebug() << bootstrapStatus << std::endl; @@ -702,7 +698,7 @@ void TorControl::updateBootstrap(const std::list &data) } } -QObject *TorControl::getConfiguration(const std::string& options) +TorControlCommand *TorControl::getConfiguration(const std::string& options) { GetConfCommand *command = new GetConfCommand(GetConfCommand::GetConf); mSocket->sendCommand(command, command->build(options)); @@ -711,7 +707,7 @@ QObject *TorControl::getConfiguration(const std::string& options) return command; } -QObject *TorControl::setConfiguration(const std::list >& options) +TorControlCommand *TorControl::setConfiguration(const std::list >& options) { SetConfCommand *command = new SetConfCommand; command->setResetMode(true); @@ -725,27 +721,25 @@ namespace Tor { class SaveConfigOperation : public PendingOperation { - Q_OBJECT - public: - SaveConfigOperation(QObject *parent) - : PendingOperation(parent), command(0) + SaveConfigOperation() + : PendingOperation(), command(0) { } void start(TorControlSocket *socket) { - Q_ASSERT(!command); + assert(!command); command = new GetConfCommand(GetConfCommand::GetInfo); - QObject::connect(command, &TorControlCommand::finished, this, &SaveConfigOperation::configTextReply); + //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" } )); } -private slots: - void configTextReply() + void configTextReply(TorControlCommand * /*sender*/) { - Q_ASSERT(command); + assert(command); if (!command) return; @@ -823,8 +817,10 @@ PendingOperation *TorControl::saveConfiguration() return 0; } - SaveConfigOperation *operation = new SaveConfigOperation(this); - QObject::connect(operation, &PendingOperation::finished, operation, &QObject::deleteLater); + 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); diff --git a/libretroshare/src/tor/TorControl.h b/libretroshare/src/tor/TorControl.h index bb21fba95..5ffc1174f 100644 --- a/libretroshare/src/tor/TorControl.h +++ b/libretroshare/src/tor/TorControl.h @@ -39,7 +39,6 @@ #include "bytearray.h" #include "TorControlSocket.h" -class QNetworkProxy; namespace Tor { @@ -91,15 +90,14 @@ public: bool hasConnectivity() const; std::string socksAddress() const; - quint16 socksPort() const; - QNetworkProxy connectionProxy(); + uint16_t socksPort() const; /* Authentication */ void setAuthPassword(const ByteArray& password); /* Connection */ bool isConnected() const { return status() == Connected; } - void connect(const std::string &address, quint16 port); + void connect(const std::string &address, uint16_t port); /* Ownership means that tor is managed by this socket, and we * can shut it down, own its configuration, etc. */ @@ -111,8 +109,8 @@ public: void addHiddenService(HiddenService *service); std::map bootstrapStatus() const; - /*Q_INVOKABLE*/ QObject *getConfiguration(const std::string &options); - /*Q_INVOKABLE*/ QObject *setConfiguration(const std::list > &options); + /*Q_INVOKABLE*/ TorControlCommand *getConfiguration(const std::string &options); + /*Q_INVOKABLE*/ TorControlCommand *setConfiguration(const std::list > &options); /*Q_INVOKABLE*/ PendingOperation *saveConfiguration(); //signals: @@ -124,6 +122,10 @@ public: // void bootstrapStatusChanged(); // void hasOwnershipChanged(); + void set_statusChanged_callback(const std::function& f) { mStatusChanged_callback = f ;} + void set_connected_callback(const std::function& f) { mConnected_callback = f ;} + void set_disconnected_callback(const std::function& f) { mDisconnected_callback = f ;} + virtual void socketError(const std::string &s) override; //public slots: @@ -142,14 +144,14 @@ private: ByteArray mAuthPassword; std::string mSocksAddress; std::list mServices; - quint16 mControlPort, mSocksPort; + uint16_t mControlPort, mSocksPort; TorControl::Status mStatus; TorControl::TorStatus mTorStatus; std::map mBootstrapStatus; bool mHasOwnership; void getTorInfo(); - void getTorInfoReply(); + void getTorInfoReply(TorControlCommand *sender); void setStatus(TorControl::Status n); void statusEvent(int code, const ByteArray &data); void setTorStatus(TorControl::TorStatus n); @@ -159,7 +161,11 @@ private: void protocolInfoReply(TorControlCommand *sender); void socketDisconnected(); void socketConnected(); - void authenticateReply(); + void authenticateReply(TorControlCommand *sender); + + std::function mStatusChanged_callback; + std::function mConnected_callback; + std::function mDisconnected_callback; }; } diff --git a/libretroshare/src/tor/TorManager.cpp b/libretroshare/src/tor/TorManager.cpp index ec198beb6..289e8ec0c 100644 --- a/libretroshare/src/tor/TorManager.cpp +++ b/libretroshare/src/tor/TorManager.cpp @@ -44,29 +44,20 @@ #include "util/rsdir.h" #include "retroshare/rsinit.h" -#include - #include "TorManager.h" #include "TorProcess.h" #include "TorControl.h" #include "CryptoKey.h" #include "HiddenService.h" #include "GetConfCommand.h" -#include -#include -#include -#include -#include using namespace Tor; namespace Tor { -class TorManagerPrivate : public QObject, public TorProcessClient +class TorManagerPrivate : public TorProcessClient { - Q_OBJECT - public: TorManager *q; TorProcess *process; @@ -91,9 +82,9 @@ public: virtual void processErrorChanged(const std::string &errorMessage) override; virtual void processLogMessage(const std::string &message) override; -public slots: +//public slots: void controlStatusChanged(int status); - void getConfFinished(); + void getConfFinished(TorControlCommand *sender); }; } @@ -104,14 +95,14 @@ TorManager::TorManager() } TorManagerPrivate::TorManagerPrivate(TorManager *parent) - : QObject(nullptr) - , q(parent) + : q(parent) , process(0) - , control(new TorControl(this)) + , control(new TorControl()) , configNeeded(false) , hiddenService(NULL) { - connect(control, SIGNAL(statusChanged(int,int)), SLOT(controlStatusChanged(int))); + //connect(control, SIGNAL(statusChanged(int,int)), SLOT(controlStatusChanged(int))); + control->set_statusChanged_callback([this](int new_status,int /*old_status*/) { controlStatusChanged(new_status); }); } TorManager *TorManager::instance() @@ -178,12 +169,12 @@ bool TorManager::setupHiddenService() std::cerr << "Using legacy dir: " << legacyDir << std::endl; - if (!legacyDir.empty() && QFile::exists(legacyDir.c_str() + QLatin1String("/private_key"))) + if (!legacyDir.empty() && RsDirUtil::fileExists(RsDirUtil::makePath(legacyDir,"/private_key"))) { std::cerr << "Attempting to load key from legacy filesystem format in " << legacyDir << std::endl; CryptoKey key; - if (!key.loadFromFile(legacyDir + "/private_key")) + if (!key.loadFromFile(RsDirUtil::makePath(legacyDir , "/private_key"))) { RsWarn() << "Cannot load legacy format key from" << legacyDir << "for conversion"; return false; @@ -417,7 +408,7 @@ bool TorManager::getProxyServerInfo(std::string& proxy_server_adress,uint16_t& p bool TorManager::getHiddenServiceInfo(std::string& service_id,std::string& service_onion_address,uint16_t& service_port, std::string& service_target_address,uint16_t& target_port) { - QList hidden_services = control()->hiddenServices(); + auto hidden_services = control()->hiddenServices(); if(hidden_services.empty()) return false ; @@ -471,8 +462,8 @@ void TorManagerPrivate::controlStatusChanged(int status) if (status == TorControl::Connected) { if (!configNeeded) { // If DisableNetwork is 1, trigger configurationNeeded - connect(control->getConfiguration("DisableNetwork"), - SIGNAL(finished()), SLOT(getConfFinished())); + auto cmd = control->getConfiguration("DisableNetwork"); + cmd->set_finished_callback( [this](TorControlCommand *sender) { getConfFinished(sender) ; }); } if (process) { @@ -482,9 +473,9 @@ void TorManagerPrivate::controlStatusChanged(int status) } } -void TorManagerPrivate::getConfFinished() +void TorManagerPrivate::getConfFinished(TorControlCommand *sender) { - GetConfCommand *command = qobject_cast(sender()); + GetConfCommand *command = dynamic_cast(sender); if (!command) return; diff --git a/libretroshare/src/tor/bytearray.h b/libretroshare/src/tor/bytearray.h index b237a333a..ebf2b9f85 100644 --- a/libretroshare/src/tor/bytearray.h +++ b/libretroshare/src/tor/bytearray.h @@ -49,6 +49,7 @@ public: return res; } bool endsWith(const ByteArray& b) const { return size() >= b.size() && !memcmp(&data()[size()-b.size()],b.data(),b.size()); } + bool startsWith(const ByteArray& b) const { return b.size() <= size() && !strncmp((char*)b.data(),(char*)data(),std::min(size(),b.size())); } bool startsWith(const char *b) const { for(uint32_t n=0;b[n]!=0;++n)