mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-08 06:08:12 -05:00
removed signals in HiddenService class
This commit is contained in:
parent
a43a158750
commit
8505544294
@ -42,13 +42,13 @@
|
|||||||
|
|
||||||
using namespace Tor;
|
using namespace Tor;
|
||||||
|
|
||||||
HiddenService::HiddenService(QObject *parent)
|
HiddenService::HiddenService(HiddenServiceClient *client)
|
||||||
: QObject(parent), m_status(NotCreated)
|
: m_status(NotCreated), m_client(client)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HiddenService::HiddenService(const QString &path, QObject *parent)
|
HiddenService::HiddenService(HiddenServiceClient *client,const QString &path)
|
||||||
: QObject(parent), m_dataPath(path), m_status(NotCreated)
|
: m_dataPath(path), m_status(NotCreated), m_client(client)
|
||||||
{
|
{
|
||||||
/* Set the initial status and, if possible, load the hostname */
|
/* Set the initial status and, if possible, load the hostname */
|
||||||
if (QDir(m_dataPath).exists(QLatin1String("private_key"))) {
|
if (QDir(m_dataPath).exists(QLatin1String("private_key"))) {
|
||||||
@ -58,8 +58,8 @@ HiddenService::HiddenService(const QString &path, QObject *parent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HiddenService::HiddenService(const CryptoKey &privateKey, const QString &path, QObject *parent)
|
HiddenService::HiddenService(HiddenServiceClient *client,const CryptoKey &privateKey, const QString &path)
|
||||||
: QObject(parent), m_dataPath(path), m_status(NotCreated)
|
: m_dataPath(path), m_status(NotCreated), m_client(client)
|
||||||
{
|
{
|
||||||
setPrivateKey(privateKey);
|
setPrivateKey(privateKey);
|
||||||
m_status = Offline;
|
m_status = Offline;
|
||||||
@ -73,10 +73,12 @@ void HiddenService::setStatus(Status newStatus)
|
|||||||
Status old = m_status;
|
Status old = m_status;
|
||||||
m_status = newStatus;
|
m_status = newStatus;
|
||||||
|
|
||||||
emit statusChanged(m_status, old);
|
if(m_client)
|
||||||
|
m_client->hiddenServiceStatusChanged(m_status,old); //emit statusChanged(m_status, old);
|
||||||
|
|
||||||
if (m_status == Online)
|
if (m_status == Online)
|
||||||
emit serviceOnline();
|
if(m_client)
|
||||||
|
m_client->hiddenServiceOnline(); //emit serviceOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HiddenService::addTarget(const Target &target)
|
void HiddenService::addTarget(const Target &target)
|
||||||
@ -95,7 +97,8 @@ void HiddenService::setServiceId(const QByteArray& sid)
|
|||||||
m_service_id = sid;
|
m_service_id = sid;
|
||||||
m_hostname = sid + ".onion";
|
m_hostname = sid + ".onion";
|
||||||
|
|
||||||
emit hostnameChanged();
|
if(m_client)
|
||||||
|
m_client->hiddenServiceHostnameChanged(); // emit hostnameChanged();
|
||||||
}
|
}
|
||||||
void HiddenService::setPrivateKey(const CryptoKey &key)
|
void HiddenService::setPrivateKey(const CryptoKey &key)
|
||||||
{
|
{
|
||||||
@ -113,7 +116,8 @@ void HiddenService::setPrivateKey(const CryptoKey &key)
|
|||||||
|
|
||||||
m_privateKey = key;
|
m_privateKey = key;
|
||||||
|
|
||||||
emit privateKeyChanged();
|
if(m_client)
|
||||||
|
m_client->hiddenServicePrivateKeyChanged(); //emit privateKeyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HiddenService::loadPrivateKey()
|
void HiddenService::loadPrivateKey()
|
||||||
@ -128,7 +132,8 @@ void HiddenService::loadPrivateKey()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit privateKeyChanged();
|
if(m_client)
|
||||||
|
m_client->hiddenServicePrivateKeyChanged(); // emit privateKeyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HiddenService::servicePublished()
|
void HiddenService::servicePublished()
|
||||||
|
@ -43,6 +43,18 @@ namespace Tor
|
|||||||
|
|
||||||
class TorSocket;
|
class TorSocket;
|
||||||
|
|
||||||
|
// This class is used to receive synchroneous notifications from the hidden service.
|
||||||
|
// Each client should implement its own notification handling.
|
||||||
|
|
||||||
|
class HiddenServiceClient
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void hiddenServiceStatusChanged(int /* newStatus */, int /* oldStatus */) =0;
|
||||||
|
virtual void hiddenServiceOnline() =0;
|
||||||
|
virtual void hiddenServicePrivateKeyChanged() =0;
|
||||||
|
virtual void hiddenServiceHostnameChanged() =0;
|
||||||
|
};
|
||||||
|
|
||||||
class HiddenService : public QObject
|
class HiddenService : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -64,9 +76,9 @@ public:
|
|||||||
Online /* Published */
|
Online /* Published */
|
||||||
};
|
};
|
||||||
|
|
||||||
HiddenService(QObject *parent = 0);
|
HiddenService(HiddenServiceClient *client);
|
||||||
HiddenService(const QString &dataPath, QObject *parent = 0);
|
HiddenService(HiddenServiceClient *client,const QString &dataPath);
|
||||||
HiddenService(const CryptoKey &privateKey, const QString &dataPath = QString(), QObject *parent = 0);
|
HiddenService(HiddenServiceClient *client,const CryptoKey &privateKey, const QString &dataPath = QString());
|
||||||
|
|
||||||
Status status() const { return m_status; }
|
Status status() const { return m_status; }
|
||||||
|
|
||||||
@ -82,12 +94,6 @@ public:
|
|||||||
void addTarget(const Target &target);
|
void addTarget(const Target &target);
|
||||||
void addTarget(quint16 servicePort, QHostAddress targetAddress, quint16 targetPort);
|
void addTarget(quint16 servicePort, QHostAddress targetAddress, quint16 targetPort);
|
||||||
|
|
||||||
signals:
|
|
||||||
void statusChanged(int newStatus, int oldStatus);
|
|
||||||
void serviceOnline();
|
|
||||||
void privateKeyChanged();
|
|
||||||
void hostnameChanged();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void servicePublished();
|
void servicePublished();
|
||||||
|
|
||||||
@ -101,6 +107,8 @@ private:
|
|||||||
|
|
||||||
void loadPrivateKey();
|
void loadPrivateKey();
|
||||||
void setStatus(Status newStatus);
|
void setStatus(Status newStatus);
|
||||||
|
|
||||||
|
HiddenServiceClient *m_client;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -175,23 +175,24 @@ bool TorManager::setupHiddenService()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->hiddenService = new Tor::HiddenService(key, legacyDir, this);
|
d->hiddenService = new Tor::HiddenService(this,key, legacyDir);
|
||||||
|
|
||||||
std::cerr << "Got key from legacy dir: " << std::endl;
|
std::cerr << "Got key from legacy dir: " << std::endl;
|
||||||
std::cerr << key.bytes().toStdString() << std::endl;
|
std::cerr << key.bytes().toStdString() << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
d->hiddenService = new Tor::HiddenService(legacyDir, this);
|
d->hiddenService = new Tor::HiddenService(this,legacyDir);
|
||||||
|
|
||||||
std::cerr << "Creating new hidden service." << std::endl;
|
std::cerr << "Creating new hidden service." << std::endl;
|
||||||
|
|
||||||
connect(d->hiddenService, SIGNAL(privateKeyChanged()), this, SLOT(hiddenServicePrivateKeyChanged())) ;
|
// connect(d->hiddenService, SIGNAL(privateKeyChanged()), this, SLOT(hiddenServicePrivateKeyChanged())) ;
|
||||||
connect(d->hiddenService, SIGNAL(hostnameChanged()), this, SLOT(hiddenServiceHostnameChanged())) ;
|
// connect(d->hiddenService, SIGNAL(hostnameChanged()), this, SLOT(hiddenServiceHostnameChanged())) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT(d->hiddenService);
|
assert(d->hiddenService);
|
||||||
connect(d->hiddenService, SIGNAL(statusChanged(int,int)), this, SLOT(hiddenServiceStatusChanged(int,int)));
|
|
||||||
|
// connect(d->hiddenService, SIGNAL(statusChanged(int,int)), this, SLOT(hiddenServiceStatusChanged(int,int)));
|
||||||
|
|
||||||
// Generally, these are not used, and we bind to localhost and port 0
|
// Generally, these are not used, and we bind to localhost and port 0
|
||||||
// for an automatic (and portable) selection.
|
// for an automatic (and portable) selection.
|
||||||
@ -225,6 +226,9 @@ void TorManager::hiddenServiceStatusChanged(int old_status,int new_status)
|
|||||||
|
|
||||||
void TorManager::hiddenServicePrivateKeyChanged()
|
void TorManager::hiddenServicePrivateKeyChanged()
|
||||||
{
|
{
|
||||||
|
if(!d->hiddenService)
|
||||||
|
return ;
|
||||||
|
|
||||||
QString key = QString::fromLatin1(d->hiddenService->privateKey().bytes());
|
QString key = QString::fromLatin1(d->hiddenService->privateKey().bytes());
|
||||||
|
|
||||||
QFile outfile(d->hiddenServiceDir + QLatin1String("/private_key")) ;
|
QFile outfile(d->hiddenServiceDir + QLatin1String("/private_key")) ;
|
||||||
@ -249,6 +253,9 @@ void TorManager::hiddenServicePrivateKeyChanged()
|
|||||||
|
|
||||||
void TorManager::hiddenServiceHostnameChanged()
|
void TorManager::hiddenServiceHostnameChanged()
|
||||||
{
|
{
|
||||||
|
if(!d->hiddenService)
|
||||||
|
return ;
|
||||||
|
|
||||||
QFile outfile2(d->hiddenServiceDir + QLatin1String("/hostname")) ;
|
QFile outfile2(d->hiddenServiceDir + QLatin1String("/hostname")) ;
|
||||||
outfile2.open( QIODevice::WriteOnly | QIODevice::Text );
|
outfile2.open( QIODevice::WriteOnly | QIODevice::Text );
|
||||||
QTextStream t(&outfile2);
|
QTextStream t(&outfile2);
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#define TORMANAGER_H
|
#define TORMANAGER_H
|
||||||
|
|
||||||
#include "retroshare/rstor.h"
|
#include "retroshare/rstor.h"
|
||||||
|
#include "HiddenService.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
@ -51,7 +52,7 @@ class TorManagerPrivate;
|
|||||||
/* Run/connect to an instance of Tor according to configuration, and manage
|
/* Run/connect to an instance of Tor according to configuration, and manage
|
||||||
* UI interaction, first time configuration, etc. */
|
* UI interaction, first time configuration, etc. */
|
||||||
|
|
||||||
class TorManager : public QObject, public RsTor
|
class TorManager : public QObject, public HiddenServiceClient, public RsTor
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -90,13 +91,14 @@ public:
|
|||||||
bool getHiddenServiceInfo(QString& service_id,QString& service_onion_address,uint16_t& service_port, QHostAddress& service_target_address,uint16_t& target_port);
|
bool getHiddenServiceInfo(QString& service_id,QString& service_onion_address,uint16_t& service_port, QHostAddress& service_target_address,uint16_t& target_port);
|
||||||
bool getProxyServerInfo(QHostAddress& proxy_server_adress,uint16_t& proxy_server_port);
|
bool getProxyServerInfo(QHostAddress& proxy_server_adress,uint16_t& proxy_server_port);
|
||||||
|
|
||||||
public slots:
|
//public slots:
|
||||||
bool start();
|
bool start();
|
||||||
|
|
||||||
private slots:
|
//private slots:
|
||||||
void hiddenServicePrivateKeyChanged();
|
virtual void hiddenServiceOnline() override {} // do nothing here.
|
||||||
void hiddenServiceHostnameChanged();
|
virtual void hiddenServicePrivateKeyChanged() override;
|
||||||
void hiddenServiceStatusChanged(int old_status,int new_status);
|
virtual void hiddenServiceHostnameChanged() override;
|
||||||
|
virtual void hiddenServiceStatusChanged(int old_status,int new_status) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void configurationNeededChanged();
|
void configurationNeededChanged();
|
||||||
|
Loading…
Reference in New Issue
Block a user