mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-11 07:29:38 -05:00
fixed a few bugs that may cause the bootstrap process to hang
This commit is contained in:
parent
a37802ca96
commit
efe2ec03ff
@ -65,14 +65,9 @@ static std::ostream& torctrldebug()
|
||||
using namespace Tor;
|
||||
|
||||
TorControl::TorControl()
|
||||
: mControlPort(0),mSocksPort(0),mStatus(NotConnected), mTorStatus(TorOffline),mHasOwnership(false)
|
||||
: mControlPort(0),mSocksPort(0),mStatus(NotConnected), mTorStatus(TorUnknown),mHasOwnership(false)
|
||||
{
|
||||
mSocket = new TorControlSocket(this);
|
||||
mControlPort = 0;
|
||||
mSocksPort = 0;
|
||||
mStatus = NotConnected;
|
||||
mTorStatus = TorUnknown;
|
||||
mHasOwnership = false;
|
||||
}
|
||||
|
||||
static RsTorConnectivityStatus torConnectivityStatus(Tor::TorControl::Status t)
|
||||
@ -127,6 +122,7 @@ void TorControl::setTorStatus(TorControl::TorStatus n)
|
||||
if (n == mTorStatus)
|
||||
return;
|
||||
|
||||
RsDbg() << "Setting TorStatus=" << n ;
|
||||
mTorStatus = n;
|
||||
|
||||
if(rsEvents)
|
||||
@ -216,7 +212,10 @@ void TorControl::connect(const std::string &address, uint16_t port)
|
||||
setStatus(Connecting);
|
||||
|
||||
if(mSocket->connectToHost(address, port))
|
||||
{
|
||||
setStatus(SocketConnected);
|
||||
setTorStatus(TorOffline); // connected and running, but not yet ready
|
||||
}
|
||||
}
|
||||
|
||||
void TorControl::reconnect()
|
||||
@ -246,8 +245,6 @@ void TorControl::authenticateReply(TorControlCommand *sender)
|
||||
torCtrlDebug() << "torctrl: Authentication successful" << std::endl;
|
||||
setStatus(TorControl::Authenticated);
|
||||
|
||||
setTorStatus(TorControl::TorUnknown);
|
||||
|
||||
TorControlCommand *clientEvents = new TorControlCommand;
|
||||
clientEvents->set_replyLine_callback([this](int code, const ByteArray &data) { statusEvent(code,data);});
|
||||
|
||||
@ -442,8 +439,8 @@ void TorControl::getTorInfoReply(TorControlCommand *sender)
|
||||
torCtrlDebug() << "torctrl: Tor indicates that circuits have been established; state is TorReady" << std::endl;
|
||||
setTorStatus(TorControl::TorReady);
|
||||
}
|
||||
else
|
||||
setTorStatus(TorControl::TorOffline);
|
||||
// else
|
||||
// setTorStatus(TorControl::TorOffline);
|
||||
|
||||
auto bootstrap = command->get("status/bootstrap-phase");
|
||||
if (!bootstrap.empty())
|
||||
@ -562,14 +559,15 @@ void TorControl::statusEvent(int /* code */, const ByteArray &data)
|
||||
if (tokens.size() < 3)
|
||||
return;
|
||||
|
||||
torCtrlDebug() << "torctrl: status event:" << data.trimmed().toString() << std::endl;
|
||||
const ByteArray& tok2 = *(++tokens.begin());
|
||||
const ByteArray& tok2 = *(++(++tokens.begin()));
|
||||
torCtrlDebug() << "torctrl: status event:" << data.trimmed().toString() << " tok2=\"" << tok2.toString() << "\"" << std::endl;
|
||||
|
||||
if (tok2 == "CIRCUIT_ESTABLISHED") {
|
||||
if (tok2 == "CIRCUIT_ESTABLISHED")
|
||||
setTorStatus(TorControl::TorReady);
|
||||
} else if (tok2 == "CIRCUIT_NOT_ESTABLISHED") {
|
||||
else if (tok2 == "CIRCUIT_NOT_ESTABLISHED")
|
||||
setTorStatus(TorControl::TorOffline);
|
||||
} else if (tok2 == "BOOTSTRAP") {
|
||||
else if (tok2 == "BOOTSTRAP")
|
||||
{
|
||||
tokens.pop_front();
|
||||
updateBootstrap(tokens);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ bool TorControlSocket::connectToHost(const std::string& tcp_address,uint16_t tcp
|
||||
{
|
||||
if(RsTcpSocket::connect(tcp_address,tcp_port))
|
||||
{
|
||||
start();
|
||||
start("TorControlSocket");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -131,6 +131,12 @@ void TorControlSocket::process()
|
||||
|
||||
ByteArray line = readline(5120);
|
||||
|
||||
if(line.empty()) // This happens when the incoming buffer isn't empty yet doesn't have a full line already.
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!line.endsWith(ByteArray("\r\n"))) {
|
||||
setError("Invalid control message syntax");
|
||||
return;
|
||||
|
@ -502,6 +502,11 @@ void TorManager::threadTick()
|
||||
break;
|
||||
|
||||
case TorControl::HiddenServiceReady:
|
||||
if(d->control->torStatus() < TorControl::TorReady)
|
||||
{
|
||||
d->control->getTorInfo(); // forces TorControl to check its state.
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
break;
|
||||
|
||||
case TorControl::Error:
|
||||
|
Loading…
Reference in New Issue
Block a user