fixed auto-configuraiton of socks proxy

This commit is contained in:
csoler 2017-12-28 17:01:56 +01:00
parent 77d0337ae9
commit 475b6a4a62
5 changed files with 42 additions and 14 deletions

View File

@ -57,7 +57,7 @@ void TorControlSocket::sendCommand(TorControlCommand *command, const QByteArray
commandQueue.append(command);
write(data);
std::cerr << "torctrl: Sent: \"" << QString(data.trimmed()).toStdString() << "\"" << std::endl;
std::cerr << "[TOR CTRL] Sent: \"" << QString(data.trimmed()).toStdString() << "\"" << std::endl;
}
void TorControlSocket::registerEvent(const QByteArray &event, TorControlCommand *command)

View File

@ -1,4 +1,5 @@
#include <unistd.h>
#include <set>
#include <QTimer>
#include <QFile>
@ -37,17 +38,10 @@ TorControlDialog::TorControlDialog(Tor::TorManager *tm,QWidget *parent)
timer->start(500) ;
// Hide some debug output for the released version
// torLog_TB->hide();
torBootstrapStatus_LB->hide();
label_2->hide();
setWindowFlags( Qt::Dialog | Qt::FramelessWindowHint );
adjustSize();
// QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect(this);
// effect->setBlurRadius(30.0);
// setGraphicsEffect(effect);
}
void TorControlDialog::onIncomingConnection()
@ -86,10 +80,15 @@ void TorControlDialog::statusChanged()
QVariantMap qvm = mTorManager->control()->bootstrapStatus();
QString bootstrapstatus_str ;
for(auto it(qvm.begin());it!=qvm.end();++it)
bootstrapstatus_str += it.key() + ":" + it.value().toString();
std::cerr << "Bootstrap status map: " << std::endl;
torBootstrapStatus_LB->setText(bootstrapstatus_str) ;
for(auto it(qvm.begin());it!=qvm.end();++it)
std::cerr << " " << it.key().toStdString() << " : " << it.value().toString().toStdString() << std::endl;
if(!qvm["progress"].toString().isNull())
torBootstrapStatus_LB->setText(qvm["progress"].toString() + " % (" + qvm["summary"].toString() + ")") ;
else
torBootstrapStatus_LB->setText(tr("[Waiting for Tor...]")) ;
QString service_id ;
QString onion_address ;
@ -110,19 +109,35 @@ void TorControlDialog::statusChanged()
showLog();
adjustSize();
QCoreApplication::processEvents(); // forces update
}
void TorControlDialog::showLog()
{
static std::set<QString> already_seen ;
QString s ;
QStringList logmsgs = mTorManager->logMessages() ;
bool can_print = false ;
for(QStringList::const_iterator it(logmsgs.begin());it!=logmsgs.end();++it)
{
s += *it + "\n" ;
// torLog_TB->setText(s) ;
if(already_seen.find(*it) == already_seen.end())
{
can_print = true ;
already_seen.insert(*it);
}
std::cerr << s.toStdString() << std::endl;
if(can_print)
std::cerr << "[TOR DEBUG LOG] " << (*it).toStdString() << std::endl;
}
// torLog_TB->setText(s) ;:
std::cerr << "Connexion Proxy: " << mTorManager->control()->socksAddress().toString().toStdString() << ":" << mTorManager->control()->socksPort() << std::endl;
}
TorControlDialog::TorStatus TorControlDialog::checkForTor()

View File

@ -372,6 +372,14 @@ void TorManager::start()
}
}
bool TorManager::getProxyServerInfo(QHostAddress& proxy_server_adress,uint16_t& proxy_server_port)
{
proxy_server_adress = control()->socksAddress();
proxy_server_port = control()->socksPort();
return proxy_server_port > 1023 ;
}
bool TorManager::getHiddenServiceInfo(QString& service_id,QString& service_onion_address,uint16_t& service_port, QHostAddress& service_target_address,uint16_t& target_port)
{
QList<Tor::HiddenService*> hidden_services = control()->hiddenServices();
@ -488,7 +496,7 @@ bool TorManagerPrivate::createDefaultTorrc(const QString &path)
static const char defaultTorrcContent[] =
"SocksPort auto\n"
"AvoidDiskWrites 1\n"
"DisableNetwork 1\n"
// "DisableNetwork 1\n" // (cyril) I removed this because it prevents Tor to bootstrap.
"__ReloadTorrcOnSIGHUP 0\n";
QFile file(path);

View File

@ -86,6 +86,7 @@ public:
QString errorMessage() const;
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:
void start();

View File

@ -403,9 +403,12 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
QString onion_address ;
uint16_t service_port ;
uint16_t service_target_port ;
uint16_t proxy_server_port ;
QHostAddress service_target_address ;
QHostAddress proxy_server_address ;
torManager->getHiddenServiceInfo(service_id,onion_address,service_port,service_target_address,service_target_port);
torManager->getProxyServerInfo(proxy_server_address,proxy_server_port) ;
std::cerr << "Got hidden service info: " << std::endl;
std::cerr << " onion address : " << onion_address.toStdString() << std::endl;
@ -418,6 +421,7 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
rsPeers->setLocalAddress(rsPeers->getOwnId(), service_target_address.toString().toStdString(), service_target_port);
rsPeers->setHiddenNode(rsPeers->getOwnId(), onion_address.toStdString(), service_port);
rsPeers->setProxyServer(RS_HIDDEN_TYPE_TOR, proxy_server_address.toString().toStdString(),proxy_server_port) ;
#endif
Rshare::initPlugins();