mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 01:16:20 -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)
|
AddOnionCommand::AddOnionCommand(HiddenService *service)
|
||||||
: m_service(service)
|
: m_service(service)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_service);
|
assert(m_service);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AddOnionCommand::isSuccessful() const
|
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.
|
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 += " Port=";
|
||||||
out += QByteArray::number(target.servicePort);
|
out += RsUtil::NumberToString(target.servicePort);
|
||||||
out += ",";
|
out += ",";
|
||||||
out += target.targetAddress;
|
out += target.targetAddress;
|
||||||
out += ":";
|
out += ":";
|
||||||
out += QByteArray::number(target.targetPort);
|
out += RsUtil::NumberToString(target.targetPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
out.append("\r\n");
|
out.append("\r\n");
|
||||||
@ -82,8 +83,8 @@ void AddOnionCommand::onReply(int statusCode, const ByteArray &data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QByteArray keyPrefix("PrivateKey=");
|
const ByteArray keyPrefix("PrivateKey=");
|
||||||
const QByteArray sidPrefix("ServiceID=");
|
const ByteArray sidPrefix("ServiceID=");
|
||||||
|
|
||||||
if(data.startsWith("ServiceID=")){
|
if(data.startsWith("ServiceID=")){
|
||||||
ByteArray service_id = data.mid(sidPrefix.size());
|
ByteArray service_id = data.mid(sidPrefix.size());
|
||||||
|
@ -30,8 +30,7 @@
|
|||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ADDONIONCOMMAND_H
|
#pragma once
|
||||||
#define ADDONIONCOMMAND_H
|
|
||||||
|
|
||||||
#include "TorControlCommand.h"
|
#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.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CRYPTOKEY_H
|
#pragma once
|
||||||
#define CRYPTOKEY_H
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QSharedData>
|
|
||||||
#include <QExplicitlySharedDataPointer>
|
|
||||||
|
|
||||||
#include "bytearray.h"
|
#include "bytearray.h"
|
||||||
|
|
||||||
@ -67,5 +62,3 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
ByteArray torControlHashedPassword(const ByteArray &password);
|
ByteArray torControlHashedPassword(const ByteArray &password);
|
||||||
|
|
||||||
#endif // CRYPTOKEY_H
|
|
||||||
|
@ -83,7 +83,7 @@ void HiddenService::addTarget(const Target &target)
|
|||||||
m_targets.push_back(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 };
|
Target t = { targetAddress, servicePort, targetPort };
|
||||||
m_targets.push_back(t);
|
m_targets.push_back(t);
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
#ifndef HIDDENSERVICE_H
|
#ifndef HIDDENSERVICE_H
|
||||||
#define HIDDENSERVICE_H
|
#define HIDDENSERVICE_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include "CryptoKey.h"
|
#include "CryptoKey.h"
|
||||||
#include "bytearray.h"
|
#include "bytearray.h"
|
||||||
|
|
||||||
@ -52,18 +51,15 @@ public:
|
|||||||
virtual void hiddenServiceHostnameChanged() =0;
|
virtual void hiddenServiceHostnameChanged() =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HiddenService : public QObject
|
class HiddenService
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
friend class TorControl;
|
||||||
Q_DISABLE_COPY(HiddenService)
|
|
||||||
|
|
||||||
friend class TorControlPrivate;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Target
|
struct Target
|
||||||
{
|
{
|
||||||
std::string targetAddress;
|
std::string targetAddress;
|
||||||
quint16 servicePort, targetPort;
|
uint16_t servicePort, targetPort;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Status
|
enum Status
|
||||||
@ -89,9 +85,9 @@ public:
|
|||||||
|
|
||||||
const std::list<Target> &targets() const { return m_targets; }
|
const std::list<Target> &targets() const { return m_targets; }
|
||||||
void addTarget(const Target &target);
|
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();
|
void servicePublished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -106,6 +102,10 @@ private:
|
|||||||
void setStatus(Status newStatus);
|
void setStatus(Status newStatus);
|
||||||
|
|
||||||
HiddenServiceClient *m_client;
|
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.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include "PendingOperation.h"
|
#include "PendingOperation.h"
|
||||||
|
|
||||||
PendingOperation::PendingOperation(QObject *parent)
|
PendingOperation::PendingOperation()
|
||||||
: QObject(parent), m_finished(false)
|
: m_finished(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,20 +66,21 @@ void PendingOperation::finishWithError(const std::string &message)
|
|||||||
|
|
||||||
if (!m_finished) {
|
if (!m_finished) {
|
||||||
m_finished = true;
|
m_finished = true;
|
||||||
emit finished();
|
|
||||||
emit error(m_errorMessage);
|
finished_callback();
|
||||||
|
error_callback(m_errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PendingOperation::finishWithSuccess()
|
void PendingOperation::finishWithSuccess()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_errorMessage.empty());
|
assert(m_errorMessage.empty());
|
||||||
|
|
||||||
if (!m_finished) {
|
if (!m_finished) {
|
||||||
m_finished = true;
|
m_finished = true;
|
||||||
emit finished();
|
finished_callback();
|
||||||
if (isSuccess())
|
if (isSuccess())
|
||||||
emit success();
|
success_callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,10 +30,9 @@
|
|||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PENDINGOPERATION_H
|
#pragma once
|
||||||
#define PENDINGOPERATION_H
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <functional>
|
||||||
|
|
||||||
/* Represents an asynchronous operation for reporting status
|
/* Represents an asynchronous operation for reporting status
|
||||||
*
|
*
|
||||||
@ -48,40 +47,41 @@
|
|||||||
* PendingOperation will emit finished() and one of success() or
|
* PendingOperation will emit finished() and one of success() or
|
||||||
* error() when completed.
|
* 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 isFinished READ isFinished NOTIFY finished FINAL)
|
// Q_PROPERTY(bool isError READ isError NOTIFY error FINAL)
|
||||||
Q_PROPERTY(bool isSuccess READ isSuccess NOTIFY success FINAL)
|
// Q_PROPERTY(std::string errorMessage READ errorMessage NOTIFY finished FINAL)
|
||||||
Q_PROPERTY(bool isError READ isError NOTIFY error FINAL)
|
|
||||||
Q_PROPERTY(std::string errorMessage READ errorMessage NOTIFY finished FINAL)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PendingOperation(QObject *parent = 0);
|
PendingOperation();
|
||||||
|
|
||||||
bool isFinished() const;
|
bool isFinished() const;
|
||||||
bool isSuccess() const;
|
bool isSuccess() const;
|
||||||
bool isError() const;
|
bool isError() const;
|
||||||
std::string errorMessage() const;
|
std::string errorMessage() const;
|
||||||
|
|
||||||
signals:
|
// signals:
|
||||||
// Always emitted once when finished, regardless of status
|
// // Always emitted once when finished, regardless of status
|
||||||
void finished();
|
// 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
|
//protected slots:
|
||||||
void error(const std::string &errorMessage);
|
|
||||||
void success();
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
void finishWithError(const std::string &errorMessage);
|
void finishWithError(const std::string &errorMessage);
|
||||||
void finishWithSuccess();
|
void finishWithSuccess();
|
||||||
|
|
||||||
|
void set_finished_callback(const std::function<void(void)>& f) { finished_callback = f; }
|
||||||
private:
|
private:
|
||||||
bool m_finished;
|
bool m_finished;
|
||||||
std::string m_errorMessage;
|
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), ' ');
|
std::list<ByteArray> tokens = splitQuotedStrings(data.mid(5), ' ');
|
||||||
|
|
||||||
foreach (ByteArray token, tokens)
|
for(ByteArray token: tokens)
|
||||||
{
|
{
|
||||||
if (token.startsWith("METHODS="))
|
if (token.startsWith("METHODS="))
|
||||||
{
|
{
|
||||||
|
@ -81,7 +81,7 @@ namespace Tor {
|
|||||||
// ByteArray authPassword;
|
// ByteArray authPassword;
|
||||||
// std::string socksAddress;
|
// std::string socksAddress;
|
||||||
// QList<HiddenService*> services;
|
// QList<HiddenService*> services;
|
||||||
// quint16 controlPort, socksPort;
|
// uint16_t controlPort, socksPort;
|
||||||
// TorControl::Status status;
|
// TorControl::Status status;
|
||||||
// TorControl::TorStatus torStatus;
|
// TorControl::TorStatus torStatus;
|
||||||
// std::map<std::string,std::string> bootstrapStatus;
|
// std::map<std::string,std::string> bootstrapStatus;
|
||||||
@ -177,14 +177,12 @@ void TorControl::setStatus(TorControl::Status n)
|
|||||||
|
|
||||||
rsEvents->sendEvent(ev);
|
rsEvents->sendEvent(ev);
|
||||||
}
|
}
|
||||||
#ifdef TO_REMOVE
|
mStatusChanged_callback(mStatus, old);
|
||||||
emit statusChanged(status, old);
|
|
||||||
|
|
||||||
if (status == TorControl::Connected && old < TorControl::Connected)
|
if (mStatus == TorControl::Connected && old < TorControl::Connected)
|
||||||
emit connected();
|
socketConnected();//mConnected_callback();
|
||||||
else if (status < TorControl::Connected && old >= TorControl::Connected)
|
else if (mStatus < TorControl::Connected && old >= TorControl::Connected)
|
||||||
emit disconnected();
|
socketDisconnected();//mDisconnected_callback();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorControl::setTorStatus(TorControl::TorStatus n)
|
void TorControl::setTorStatus(TorControl::TorStatus n)
|
||||||
@ -194,10 +192,6 @@ void TorControl::setTorStatus(TorControl::TorStatus n)
|
|||||||
|
|
||||||
TorControl::TorStatus old = mTorStatus;
|
TorControl::TorStatus old = mTorStatus;
|
||||||
mTorStatus = n;
|
mTorStatus = n;
|
||||||
#ifdef TO_REMOVE
|
|
||||||
emit torStatusChanged(torStatus, old);
|
|
||||||
emit connectivityChanged();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(rsEvents)
|
if(rsEvents)
|
||||||
{
|
{
|
||||||
@ -255,7 +249,7 @@ std::string TorControl::socksAddress() const
|
|||||||
return mSocksAddress;
|
return mSocksAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint16 TorControl::socksPort() const
|
uint16_t TorControl::socksPort() const
|
||||||
{
|
{
|
||||||
return mSocksPort;
|
return mSocksPort;
|
||||||
}
|
}
|
||||||
@ -275,7 +269,7 @@ void TorControl::setAuthPassword(const ByteArray &password)
|
|||||||
mAuthPassword = 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)
|
if (status() > Connecting)
|
||||||
{
|
{
|
||||||
@ -306,9 +300,9 @@ void TorControl::reconnect()
|
|||||||
mSocket->connectToHost(mTorAddress, mControlPort);
|
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(command);
|
||||||
assert(mStatus == TorControl::Authenticating);
|
assert(mStatus == TorControl::Authenticating);
|
||||||
if (!command)
|
if (!command)
|
||||||
@ -384,17 +378,18 @@ void TorControl::protocolInfoReply(TorControlCommand *sender)
|
|||||||
if (mStatus == TorControl::Authenticating)
|
if (mStatus == TorControl::Authenticating)
|
||||||
{
|
{
|
||||||
AuthenticateCommand *auth = new AuthenticateCommand;
|
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;
|
ByteArray data;
|
||||||
ProtocolInfoCommand::AuthMethod methods = info->authMethods();
|
ProtocolInfoCommand::AuthMethod methods = info->authMethods();
|
||||||
|
|
||||||
if (methods.testFlag(ProtocolInfoCommand::AuthNull))
|
if(methods & ProtocolInfoCommand::AuthNull)
|
||||||
{
|
{
|
||||||
torCtrlDebug() << "torctrl: Using null authentication" << std::endl;
|
torCtrlDebug() << "torctrl: Using null authentication" << std::endl;
|
||||||
data = auth->build();
|
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 cookieFile = info->cookieFile();
|
||||||
std::string cookieError;
|
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.
|
/* 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,
|
* This is a strange corner case that will likely never happen in a normal configuration,
|
||||||
* but it has happened. */
|
* 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;
|
torCtrlDebug() << "torctrl: Unable to read authentication cookie file:" << cookieError << std::endl;
|
||||||
goto usePasswordAuth;
|
goto usePasswordAuth;
|
||||||
@ -436,7 +431,7 @@ void TorControl::protocolInfoReply(TorControlCommand *sender)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (methods.testFlag(ProtocolInfoCommand::AuthHashedPassword) && !mAuthPassword.empty())
|
else if ((methods & ProtocolInfoCommand::AuthHashedPassword) && !mAuthPassword.empty())
|
||||||
{
|
{
|
||||||
usePasswordAuth:
|
usePasswordAuth:
|
||||||
torCtrlDebug() << "torctrl: Using hashed password authentication" << std::endl;
|
torCtrlDebug() << "torctrl: Using hashed password authentication" << std::endl;
|
||||||
@ -444,7 +439,7 @@ void TorControl::protocolInfoReply(TorControlCommand *sender)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (methods.testFlag(ProtocolInfoCommand::AuthHashedPassword))
|
if (methods & ProtocolInfoCommand::AuthHashedPassword)
|
||||||
setError("Tor requires a control password to connect, but no password is configured.");
|
setError("Tor requires a control password to connect, but no password is configured.");
|
||||||
else
|
else
|
||||||
setError("Tor is not configured to accept any supported authentication methods.");
|
setError("Tor is not configured to accept any supported authentication methods.");
|
||||||
@ -461,7 +456,8 @@ void TorControl::getTorInfo()
|
|||||||
assert(isConnected());
|
assert(isConnected());
|
||||||
|
|
||||||
GetConfCommand *command = new GetConfCommand(GetConfCommand::GetInfo);
|
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" };
|
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. */
|
/* If these are set in the config, they override the automatic behavior. */
|
||||||
SettingsObject settings("tor");
|
SettingsObject settings("tor");
|
||||||
QHostAddress forceAddress(settings.read("socksAddress").toString());
|
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) {
|
if (!forceAddress.isNull() && port) {
|
||||||
torCtrlDebug() << "torctrl: Using manually specified SOCKS connection settings";
|
torCtrlDebug() << "torctrl: Using manually specified SOCKS connection settings";
|
||||||
@ -491,9 +487,9 @@ void TorControl::getTorInfo()
|
|||||||
mSocket->sendCommand(command, command->build(keys));
|
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())
|
if (!command || !isConnected())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -503,7 +499,7 @@ void TorControl::getTorInfoReply()
|
|||||||
ByteArray value = unquotedString(add);
|
ByteArray value = unquotedString(add);
|
||||||
int sepp = value.indexOf(':');
|
int sepp = value.indexOf(':');
|
||||||
std::string address(value.mid(0, sepp).toString());
|
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,
|
/* 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;
|
* 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
|
else
|
||||||
torCtrlDebug() << "torctrl: Publishing hidden service: " << service->hostname() << std::endl;
|
torCtrlDebug() << "torctrl: Publishing hidden service: " << service->hostname() << std::endl;
|
||||||
AddOnionCommand *onionCommand = new AddOnionCommand(service);
|
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());
|
mSocket->sendCommand(onionCommand, onionCommand->build());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -618,7 +615,8 @@ void TorControl::publishServices()
|
|||||||
torConfig.push_back(std::make_pair("HiddenServicePort", target));
|
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())
|
if (!torConfig.empty())
|
||||||
@ -650,10 +648,8 @@ void TorControl::shutdownSync()
|
|||||||
mSocket->close();
|
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(), ' ');
|
std::list<ByteArray> tokens = splitQuotedStrings(data.trimmed(), ' ');
|
||||||
if (tokens.size() < 3)
|
if (tokens.size() < 3)
|
||||||
return;
|
return;
|
||||||
@ -673,9 +669,9 @@ void TorControl::statusEvent(int code, const ByteArray &data)
|
|||||||
|
|
||||||
void TorControl::updateBootstrap(const std::list<ByteArray> &data)
|
void TorControl::updateBootstrap(const std::list<ByteArray> &data)
|
||||||
{
|
{
|
||||||
bootstrapStatus.clear();
|
mBootstrapStatus.clear();
|
||||||
// WARN or NOTICE
|
// WARN or NOTICE
|
||||||
bootstrapStatus["severity"] = (*data.begin()).toString();
|
mBootstrapStatus["severity"] = (*data.begin()).toString();
|
||||||
|
|
||||||
auto dat = data.begin();
|
auto dat = data.begin();
|
||||||
++dat;
|
++dat;
|
||||||
@ -688,7 +684,7 @@ void TorControl::updateBootstrap(const std::list<ByteArray> &data)
|
|||||||
if (equals >= 0)
|
if (equals >= 0)
|
||||||
value = unquotedString((*dat).mid(equals + 1));
|
value = unquotedString((*dat).mid(equals + 1));
|
||||||
|
|
||||||
bootstrapStatus[key.toLower().toString()] = value.toString();
|
mBootstrapStatus[key.toLower().toString()] = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
//torCtrlDebug() << bootstrapStatus << std::endl;
|
//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);
|
GetConfCommand *command = new GetConfCommand(GetConfCommand::GetConf);
|
||||||
mSocket->sendCommand(command, command->build(options));
|
mSocket->sendCommand(command, command->build(options));
|
||||||
@ -711,7 +707,7 @@ QObject *TorControl::getConfiguration(const std::string& options)
|
|||||||
return command;
|
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;
|
SetConfCommand *command = new SetConfCommand;
|
||||||
command->setResetMode(true);
|
command->setResetMode(true);
|
||||||
@ -725,27 +721,25 @@ namespace Tor {
|
|||||||
|
|
||||||
class SaveConfigOperation : public PendingOperation
|
class SaveConfigOperation : public PendingOperation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SaveConfigOperation(QObject *parent)
|
SaveConfigOperation()
|
||||||
: PendingOperation(parent), command(0)
|
: PendingOperation(), command(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void start(TorControlSocket *socket)
|
void start(TorControlSocket *socket)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!command);
|
assert(!command);
|
||||||
command = new GetConfCommand(GetConfCommand::GetInfo);
|
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" } ));
|
socket->sendCommand(command, command->build(std::list<std::string> { "config-text" , "config-file" } ));
|
||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
void configTextReply(TorControlCommand * /*sender*/)
|
||||||
void configTextReply()
|
|
||||||
{
|
{
|
||||||
Q_ASSERT(command);
|
assert(command);
|
||||||
if (!command)
|
if (!command)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -823,8 +817,10 @@ PendingOperation *TorControl::saveConfiguration()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveConfigOperation *operation = new SaveConfigOperation(this);
|
SaveConfigOperation *operation = new SaveConfigOperation();
|
||||||
QObject::connect(operation, &PendingOperation::finished, operation, &QObject::deleteLater);
|
|
||||||
|
//QObject::connect(operation, &PendingOperation::finished, operation, &QObject::deleteLater);
|
||||||
|
operation->set_finished_callback( [operation]() { delete operation; });
|
||||||
operation->start(mSocket);
|
operation->start(mSocket);
|
||||||
|
|
||||||
//QQmlEngine::setObjectOwnership(operation, QQmlEngine::CppOwnership);
|
//QQmlEngine::setObjectOwnership(operation, QQmlEngine::CppOwnership);
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
#include "bytearray.h"
|
#include "bytearray.h"
|
||||||
#include "TorControlSocket.h"
|
#include "TorControlSocket.h"
|
||||||
|
|
||||||
class QNetworkProxy;
|
|
||||||
|
|
||||||
namespace Tor
|
namespace Tor
|
||||||
{
|
{
|
||||||
@ -91,15 +90,14 @@ public:
|
|||||||
|
|
||||||
bool hasConnectivity() const;
|
bool hasConnectivity() const;
|
||||||
std::string socksAddress() const;
|
std::string socksAddress() const;
|
||||||
quint16 socksPort() const;
|
uint16_t socksPort() const;
|
||||||
QNetworkProxy connectionProxy();
|
|
||||||
|
|
||||||
/* Authentication */
|
/* Authentication */
|
||||||
void setAuthPassword(const ByteArray& password);
|
void setAuthPassword(const ByteArray& password);
|
||||||
|
|
||||||
/* Connection */
|
/* Connection */
|
||||||
bool isConnected() const { return status() == Connected; }
|
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
|
/* Ownership means that tor is managed by this socket, and we
|
||||||
* can shut it down, own its configuration, etc. */
|
* can shut it down, own its configuration, etc. */
|
||||||
@ -111,8 +109,8 @@ public:
|
|||||||
void addHiddenService(HiddenService *service);
|
void addHiddenService(HiddenService *service);
|
||||||
|
|
||||||
std::map<std::string, std::string> bootstrapStatus() const;
|
std::map<std::string, std::string> bootstrapStatus() const;
|
||||||
/*Q_INVOKABLE*/ QObject *getConfiguration(const std::string &options);
|
/*Q_INVOKABLE*/ TorControlCommand *getConfiguration(const std::string &options);
|
||||||
/*Q_INVOKABLE*/ QObject *setConfiguration(const std::list<std::pair<std::string, std::string> > &options);
|
/*Q_INVOKABLE*/ TorControlCommand *setConfiguration(const std::list<std::pair<std::string, std::string> > &options);
|
||||||
/*Q_INVOKABLE*/ PendingOperation *saveConfiguration();
|
/*Q_INVOKABLE*/ PendingOperation *saveConfiguration();
|
||||||
|
|
||||||
//signals:
|
//signals:
|
||||||
@ -124,6 +122,10 @@ public:
|
|||||||
// void bootstrapStatusChanged();
|
// void bootstrapStatusChanged();
|
||||||
// void hasOwnershipChanged();
|
// 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;
|
virtual void socketError(const std::string &s) override;
|
||||||
|
|
||||||
//public slots:
|
//public slots:
|
||||||
@ -142,14 +144,14 @@ private:
|
|||||||
ByteArray mAuthPassword;
|
ByteArray mAuthPassword;
|
||||||
std::string mSocksAddress;
|
std::string mSocksAddress;
|
||||||
std::list<HiddenService*> mServices;
|
std::list<HiddenService*> mServices;
|
||||||
quint16 mControlPort, mSocksPort;
|
uint16_t mControlPort, mSocksPort;
|
||||||
TorControl::Status mStatus;
|
TorControl::Status mStatus;
|
||||||
TorControl::TorStatus mTorStatus;
|
TorControl::TorStatus mTorStatus;
|
||||||
std::map<std::string,std::string> mBootstrapStatus;
|
std::map<std::string,std::string> mBootstrapStatus;
|
||||||
bool mHasOwnership;
|
bool mHasOwnership;
|
||||||
|
|
||||||
void getTorInfo();
|
void getTorInfo();
|
||||||
void getTorInfoReply();
|
void getTorInfoReply(TorControlCommand *sender);
|
||||||
void setStatus(TorControl::Status n);
|
void setStatus(TorControl::Status n);
|
||||||
void statusEvent(int code, const ByteArray &data);
|
void statusEvent(int code, const ByteArray &data);
|
||||||
void setTorStatus(TorControl::TorStatus n);
|
void setTorStatus(TorControl::TorStatus n);
|
||||||
@ -159,7 +161,11 @@ private:
|
|||||||
void protocolInfoReply(TorControlCommand *sender);
|
void protocolInfoReply(TorControlCommand *sender);
|
||||||
void socketDisconnected();
|
void socketDisconnected();
|
||||||
void socketConnected();
|
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 "util/rsdir.h"
|
||||||
#include "retroshare/rsinit.h"
|
#include "retroshare/rsinit.h"
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include "TorManager.h"
|
#include "TorManager.h"
|
||||||
#include "TorProcess.h"
|
#include "TorProcess.h"
|
||||||
#include "TorControl.h"
|
#include "TorControl.h"
|
||||||
#include "CryptoKey.h"
|
#include "CryptoKey.h"
|
||||||
#include "HiddenService.h"
|
#include "HiddenService.h"
|
||||||
#include "GetConfCommand.h"
|
#include "GetConfCommand.h"
|
||||||
#include <QFile>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QTcpServer>
|
|
||||||
#include <QTextStream>
|
|
||||||
|
|
||||||
using namespace Tor;
|
using namespace Tor;
|
||||||
|
|
||||||
namespace Tor
|
namespace Tor
|
||||||
{
|
{
|
||||||
|
|
||||||
class TorManagerPrivate : public QObject, public TorProcessClient
|
class TorManagerPrivate : public TorProcessClient
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TorManager *q;
|
TorManager *q;
|
||||||
TorProcess *process;
|
TorProcess *process;
|
||||||
@ -91,9 +82,9 @@ public:
|
|||||||
virtual void processErrorChanged(const std::string &errorMessage) override;
|
virtual void processErrorChanged(const std::string &errorMessage) override;
|
||||||
virtual void processLogMessage(const std::string &message) override;
|
virtual void processLogMessage(const std::string &message) override;
|
||||||
|
|
||||||
public slots:
|
//public slots:
|
||||||
void controlStatusChanged(int status);
|
void controlStatusChanged(int status);
|
||||||
void getConfFinished();
|
void getConfFinished(TorControlCommand *sender);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -104,14 +95,14 @@ TorManager::TorManager()
|
|||||||
}
|
}
|
||||||
|
|
||||||
TorManagerPrivate::TorManagerPrivate(TorManager *parent)
|
TorManagerPrivate::TorManagerPrivate(TorManager *parent)
|
||||||
: QObject(nullptr)
|
: q(parent)
|
||||||
, q(parent)
|
|
||||||
, process(0)
|
, process(0)
|
||||||
, control(new TorControl(this))
|
, control(new TorControl())
|
||||||
, configNeeded(false)
|
, configNeeded(false)
|
||||||
, hiddenService(NULL)
|
, 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()
|
TorManager *TorManager::instance()
|
||||||
@ -178,12 +169,12 @@ bool TorManager::setupHiddenService()
|
|||||||
|
|
||||||
std::cerr << "Using legacy dir: " << legacyDir << std::endl;
|
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;
|
std::cerr << "Attempting to load key from legacy filesystem format in " << legacyDir << std::endl;
|
||||||
|
|
||||||
CryptoKey key;
|
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";
|
RsWarn() << "Cannot load legacy format key from" << legacyDir << "for conversion";
|
||||||
return false;
|
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)
|
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())
|
if(hidden_services.empty())
|
||||||
return false ;
|
return false ;
|
||||||
@ -471,8 +462,8 @@ void TorManagerPrivate::controlStatusChanged(int status)
|
|||||||
if (status == TorControl::Connected) {
|
if (status == TorControl::Connected) {
|
||||||
if (!configNeeded) {
|
if (!configNeeded) {
|
||||||
// If DisableNetwork is 1, trigger configurationNeeded
|
// If DisableNetwork is 1, trigger configurationNeeded
|
||||||
connect(control->getConfiguration("DisableNetwork"),
|
auto cmd = control->getConfiguration("DisableNetwork");
|
||||||
SIGNAL(finished()), SLOT(getConfFinished()));
|
cmd->set_finished_callback( [this](TorControlCommand *sender) { getConfFinished(sender) ; });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process) {
|
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)
|
if (!command)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
bool endsWith(const ByteArray& b) const { return size() >= b.size() && !memcmp(&data()[size()-b.size()],b.data(),b.size()); }
|
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
|
bool startsWith(const char *b) const
|
||||||
{
|
{
|
||||||
for(uint32_t n=0;b[n]!=0;++n)
|
for(uint32_t n=0;b[n]!=0;++n)
|
||||||
|
Loading…
Reference in New Issue
Block a user