fixed event handling in Tor bootstrap process

This commit is contained in:
csoler 2021-06-26 23:13:17 +02:00
parent 607c1896e5
commit a23ad41b11

View File

@ -178,10 +178,10 @@ void TorControlPrivate::setStatus(TorControl::Status n)
{ {
auto ev = std::make_shared<RsTorManagerEvent>(); auto ev = std::make_shared<RsTorManagerEvent>();
ev->mTorManagerEventType = RsTorManagerEventCode::TOR_CONTROL_STATUS_CHANGED; ev->mTorManagerEventType = RsTorManagerEventCode::TOR_STATUS_CHANGED;
ev->mTorConnectivityStatus = torConnectivityStatus(status); ev->mTorConnectivityStatus = torConnectivityStatus(status);
rsEvents->postEvent(ev); rsEvents->sendEvent(ev);
} }
#ifdef TO_REMOVE #ifdef TO_REMOVE
emit q->statusChanged(status, old); emit q->statusChanged(status, old);
@ -200,9 +200,19 @@ void TorControlPrivate::setTorStatus(TorControl::TorStatus n)
TorControl::TorStatus old = torStatus; TorControl::TorStatus old = torStatus;
torStatus = n; torStatus = n;
#ifdef TO_REMOVE
emit q->torStatusChanged(torStatus, old); emit q->torStatusChanged(torStatus, old);
emit q->connectivityChanged(); emit q->connectivityChanged();
#endif
if(rsEvents)
{
auto ev = std::make_shared<RsTorManagerEvent>();
ev->mTorManagerEventType = RsTorManagerEventCode::TOR_STATUS_CHANGED;
ev->mTorStatus = ::torStatus(torStatus);
rsEvents->sendEvent(ev);
}
if (torStatus == TorControl::TorReady && socksAddress.isNull()) { if (torStatus == TorControl::TorReady && socksAddress.isNull()) {
// Request info again to read the SOCKS port // Request info again to read the SOCKS port
getTorInfo(); getTorInfo();
@ -460,7 +470,14 @@ void TorControlPrivate::getTorInfo()
torCtrlDebug() << "torctrl: Using manually specified SOCKS connection settings"; torCtrlDebug() << "torctrl: Using manually specified SOCKS connection settings";
socksAddress = forceAddress; socksAddress = forceAddress;
socksPort = port; socksPort = port;
emit q->connectivityChanged();
if(rsEvents)
{
auto ev = std::make_shared<RsTorManagerEvent>();
ev->mTorManagerEventType = RsTorManagerEventCode::TOR_CONNECTIVITY_CHANGED;
rsEvents->sendEvent(ev);
}
} else } else
keys << QByteArray("net/listeners/socks"); keys << QByteArray("net/listeners/socks");
@ -496,7 +513,14 @@ void TorControlPrivate::getTorInfoReply()
* is reached. */ * is reached. */
if (!socksAddress.isNull()) { if (!socksAddress.isNull()) {
torCtrlDebug() << "torctrl: SOCKS address is " << socksAddress.toString().toStdString() << ":" << socksPort << std::endl; torCtrlDebug() << "torctrl: SOCKS address is " << socksAddress.toString().toStdString() << ":" << socksPort << std::endl;
emit q->connectivityChanged();
if(rsEvents)
{
auto ev = std::make_shared<RsTorManagerEvent>();
ev->mTorManagerEventType = RsTorManagerEventCode::TOR_CONNECTIVITY_CHANGED;
rsEvents->sendEvent(ev);
}
} }
if (command->get(QByteArray("status/circuit-established")).toInt() == 1) { if (command->get(QByteArray("status/circuit-established")).toInt() == 1) {
@ -657,7 +681,7 @@ void TorControlPrivate::updateBootstrap(const QList<QByteArray> &data)
auto ev = std::make_shared<RsTorManagerEvent>(); auto ev = std::make_shared<RsTorManagerEvent>();
ev->mTorManagerEventType = RsTorManagerEventCode::BOOTSTRAP_STATUS_CHANGED; ev->mTorManagerEventType = RsTorManagerEventCode::BOOTSTRAP_STATUS_CHANGED;
rsEvents->postEvent(ev); rsEvents->sendEvent(ev);
} }
} }