mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 17:09:34 -05:00
finished removing latest Qt bits
This commit is contained in:
parent
e75d312724
commit
7dc5c90d63
@ -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());
|
||||
|
@ -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
|
||||
|
||||
|
@ -30,12 +30,7 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CRYPTOKEY_H
|
||||
#define CRYPTOKEY_H
|
||||
|
||||
#include <QString>
|
||||
#include <QSharedData>
|
||||
#include <QExplicitlySharedDataPointer>
|
||||
#pragma once
|
||||
|
||||
#include "bytearray.h"
|
||||
|
||||
@ -67,5 +62,3 @@ private:
|
||||
};
|
||||
|
||||
ByteArray torControlHashedPassword(const ByteArray &password);
|
||||
|
||||
#endif // CRYPTOKEY_H
|
||||
|
@ -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);
|
||||
|
@ -33,7 +33,6 @@
|
||||
#ifndef HIDDENSERVICE_H
|
||||
#define HIDDENSERVICE_H
|
||||
|
||||
#include <QObject>
|
||||
#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<Target> &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 ; }
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -30,10 +30,11 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 <QObject>
|
||||
#include <functional>
|
||||
|
||||
/* 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<void(void)>& f) { finished_callback = f; }
|
||||
private:
|
||||
bool m_finished;
|
||||
std::string m_errorMessage;
|
||||
|
||||
std::function<void(void)> finished_callback;
|
||||
std::function<void(void)> success_callback;
|
||||
std::function<void(const std::string&)> error_callback;
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(PendingOperation*)
|
||||
|
||||
#endif
|
||||
|
@ -56,7 +56,7 @@ void ProtocolInfoCommand::onReply(int statusCode, const ByteArray &data)
|
||||
{
|
||||
std::list<ByteArray> tokens = splitQuotedStrings(data.mid(5), ' ');
|
||||
|
||||
foreach (ByteArray token, tokens)
|
||||
for(ByteArray token: tokens)
|
||||
{
|
||||
if (token.startsWith("METHODS="))
|
||||
{
|
||||
|
@ -81,7 +81,7 @@ namespace Tor {
|
||||
// ByteArray authPassword;
|
||||
// std::string socksAddress;
|
||||
// QList<HiddenService*> services;
|
||||
// quint16 controlPort, socksPort;
|
||||
// uint16_t controlPort, socksPort;
|
||||
// TorControl::Status status;
|
||||
// TorControl::TorStatus torStatus;
|
||||
// std::map<std::string,std::string> 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<AuthenticateCommand*>(sender());
|
||||
AuthenticateCommand *command = dynamic_cast<AuthenticateCommand*>(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<std::string> 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<GetConfCommand*>(sender());
|
||||
GetConfCommand *command = dynamic_cast<GetConfCommand*>(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<ByteArray> 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<ByteArray> &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<ByteArray> &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<ByteArray> &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<std::pair<std::string,std::string> >& options)
|
||||
TorControlCommand *TorControl::setConfiguration(const std::list<std::pair<std::string,std::string> >& 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<std::string> { "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);
|
||||
|
@ -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<std::string, std::string> bootstrapStatus() const;
|
||||
/*Q_INVOKABLE*/ QObject *getConfiguration(const std::string &options);
|
||||
/*Q_INVOKABLE*/ QObject *setConfiguration(const std::list<std::pair<std::string, std::string> > &options);
|
||||
/*Q_INVOKABLE*/ TorControlCommand *getConfiguration(const std::string &options);
|
||||
/*Q_INVOKABLE*/ TorControlCommand *setConfiguration(const std::list<std::pair<std::string, std::string> > &options);
|
||||
/*Q_INVOKABLE*/ PendingOperation *saveConfiguration();
|
||||
|
||||
//signals:
|
||||
@ -124,6 +122,10 @@ public:
|
||||
// void bootstrapStatusChanged();
|
||||
// void hasOwnershipChanged();
|
||||
|
||||
void set_statusChanged_callback(const std::function<void(int,int)>& f) { mStatusChanged_callback = f ;}
|
||||
void set_connected_callback(const std::function<void(void)>& f) { mConnected_callback = f ;}
|
||||
void set_disconnected_callback(const std::function<void(void)>& 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<HiddenService*> mServices;
|
||||
quint16 mControlPort, mSocksPort;
|
||||
uint16_t mControlPort, mSocksPort;
|
||||
TorControl::Status mStatus;
|
||||
TorControl::TorStatus mTorStatus;
|
||||
std::map<std::string,std::string> 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<void(int,int)> mStatusChanged_callback;
|
||||
std::function<void(void)> mConnected_callback;
|
||||
std::function<void(void)> mDisconnected_callback;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -44,29 +44,20 @@
|
||||
#include "util/rsdir.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "TorManager.h"
|
||||
#include "TorProcess.h"
|
||||
#include "TorControl.h"
|
||||
#include "CryptoKey.h"
|
||||
#include "HiddenService.h"
|
||||
#include "GetConfCommand.h"
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QCoreApplication>
|
||||
#include <QTcpServer>
|
||||
#include <QTextStream>
|
||||
|
||||
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<Tor::HiddenService*> 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<GetConfCommand*>(sender());
|
||||
GetConfCommand *command = dynamic_cast<GetConfCommand*>(sender);
|
||||
if (!command)
|
||||
return;
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user