mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-04-26 01:49:11 -04:00
added back read attempt for control port
This commit is contained in:
parent
b323a1635e
commit
e0812dce83
@ -43,9 +43,12 @@
|
|||||||
|
|
||||||
using namespace Tor;
|
using namespace Tor;
|
||||||
|
|
||||||
|
static const int INTERVAL_BETWEEN_CONTROL_PORT_READ_TRIES = 5; // try every 5 secs.
|
||||||
|
|
||||||
TorProcess::TorProcess(TorProcessClient *client)
|
TorProcess::TorProcess(TorProcessClient *client)
|
||||||
: m_client(client)
|
: m_client(client), mLastTryReadControlPort(0)
|
||||||
{
|
{
|
||||||
|
mControlPortReadNbTries=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TorProcess::~TorProcess()
|
TorProcess::~TorProcess()
|
||||||
@ -282,6 +285,23 @@ void TorProcess::run()
|
|||||||
RsErr() << "Tor process died. Exiting TorControl process." ;
|
RsErr() << "Tor process died. Exiting TorControl process." ;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
time_t now = time(nullptr);
|
||||||
|
|
||||||
|
if(mControlPortReadNbTries <= 10 && (mControlPort==0 || mControlHost.empty()) && mLastTryReadControlPort + INTERVAL_BETWEEN_CONTROL_PORT_READ_TRIES < now)
|
||||||
|
{
|
||||||
|
mLastTryReadControlPort = now;
|
||||||
|
|
||||||
|
if(tryReadControlPort())
|
||||||
|
{
|
||||||
|
mState = Ready;
|
||||||
|
// stateChanged(mState);
|
||||||
|
}
|
||||||
|
else if(mControlPortReadNbTries > 10)
|
||||||
|
{
|
||||||
|
//errorMessageChanged(errorMessage);
|
||||||
|
//stateChanged(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill the Tor process since we've been asked to stop.
|
// Kill the Tor process since we've been asked to stop.
|
||||||
@ -378,6 +398,29 @@ std::string TorProcess::controlPortFilePath() const
|
|||||||
return mDataDir + "/" + "control-port";
|
return mDataDir + "/" + "control-port";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TorProcess::tryReadControlPort()
|
||||||
|
{
|
||||||
|
FILE *file = RsDirUtil::rs_fopen(controlPortFilePath().c_str(),"r");
|
||||||
|
|
||||||
|
if(file)
|
||||||
|
{
|
||||||
|
char *line = nullptr;
|
||||||
|
|
||||||
|
size_t size = getline(&line,0,file);
|
||||||
|
ByteArray data = ByteArray((unsigned char*)line,size).trimmed();
|
||||||
|
free(line);
|
||||||
|
|
||||||
|
int p;
|
||||||
|
if (data.startsWith("PORT=") && (p = data.lastIndexOf(':')) > 0) {
|
||||||
|
mControlHost = data.mid(5, p - 5).toString();
|
||||||
|
mControlPort = data.mid(p+1).toInt();
|
||||||
|
|
||||||
|
if (!mControlHost.empty() && mControlPort > 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#ifdef TO_REMOVE
|
#ifdef TO_REMOVE
|
||||||
void TorProcessPrivate::processStarted()
|
void TorProcessPrivate::processStarted()
|
||||||
{
|
{
|
||||||
@ -423,39 +466,7 @@ void TorProcessPrivate::processReadable()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorProcessPrivate::tryReadControlPort()
|
|
||||||
{
|
|
||||||
FILE *file = RsDirUtil::rs_fopen(controlPortFilePath().c_str(),"r");
|
|
||||||
|
|
||||||
if(file)
|
|
||||||
{
|
|
||||||
char *line = nullptr;
|
|
||||||
|
|
||||||
size_t size = getline(&line,0,file);
|
|
||||||
ByteArray data = ByteArray((unsigned char*)line,size).trimmed();
|
|
||||||
free(line);
|
|
||||||
|
|
||||||
int p;
|
|
||||||
if (data.startsWith("PORT=") && (p = data.lastIndexOf(':')) > 0) {
|
|
||||||
controlHost = QHostAddress(data.mid(5, p - 5));
|
|
||||||
controlPort = data.mid(p+1).toUShort();
|
|
||||||
|
|
||||||
if (!controlHost.isNull() && controlPort > 0) {
|
|
||||||
controlPortTimer.stop();
|
|
||||||
state = TorProcess::Ready;
|
|
||||||
/*emit*/ q->stateChanged(state);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (++controlPortAttempts * controlPortTimer.interval() > 10000) {
|
|
||||||
errorMessage = "No control port available after launching process";
|
|
||||||
state = TorProcess::Failed;
|
|
||||||
/*emit*/ q->errorMessageChanged(errorMessage);
|
|
||||||
/*emit*/ q->stateChanged(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TorProcessPrivate::TorProcessPrivate(TorProcess *q)
|
TorProcessPrivate::TorProcessPrivate(TorProcess *q)
|
||||||
: q(q), state(TorProcess::NotStarted), controlPort(0), controlPortAttempts(0)
|
: q(q), state(TorProcess::NotStarted), controlPort(0), controlPortAttempts(0)
|
||||||
{
|
{
|
||||||
|
@ -125,12 +125,14 @@ private:
|
|||||||
bool ensureFilesExist();
|
bool ensureFilesExist();
|
||||||
|
|
||||||
pid_t mTorProcessId;
|
pid_t mTorProcessId;
|
||||||
|
time_t mLastTryReadControlPort ;
|
||||||
|
int mControlPortReadNbTries ;
|
||||||
//public slots:
|
//public slots:
|
||||||
void processStarted();
|
void processStarted();
|
||||||
void processFinished();
|
void processFinished();
|
||||||
void processError(std::string error);
|
void processError(std::string error);
|
||||||
void processReadable();
|
void processReadable();
|
||||||
void tryReadControlPort();
|
bool tryReadControlPort();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user