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