Skip to content

Commit

Permalink
fix start/stop state
Browse files Browse the repository at this point in the history
  • Loading branch information
8bitgeek committed May 7, 2022
1 parent 8d25232 commit b06c4b6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"typeinfo": "cpp",
"type_traits": "cpp",
"*.tcc": "cpp",
"fstream": "cpp"
"fstream": "cpp",
"chrono": "cpp",
"ratio": "cpp",
"functional": "cpp",
"tuple": "cpp",
"utility": "cpp"
}
}
33 changes: 25 additions & 8 deletions server/opennicserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,9 @@ void OpenNICServer::dataReady(OpenNICNet* net)
}
else if (key == OpenNICPacket::opennic_enabled)
{
if ( value.toBool() != mSystem->enabled() )
mAsyncMessage = mSystem->enabled() ? tr("OpenNIC Disabled") : tr("OpenNIC Enabled");
mSystem->setEnabled(value.toBool());
mAsyncMessage = mSystem->enabled() ? tr("OpenNIC Enabled") : tr("OpenNIC Disabled");
}
}
}
Expand Down Expand Up @@ -713,6 +714,9 @@ void OpenNICServer::delay(int seconds)
*/
void OpenNICServer::timerEvent(QTimerEvent* e)
{
/* are we anabled? */
bool enabled = mSystem?mSystem->enabled():true;

if ( GlobalShutdown )
{
mSystem->shutdown();
Expand All @@ -722,24 +726,37 @@ void OpenNICServer::timerEvent(QTimerEvent* e)

if ( e->timerId() == mFastTimer )
{
runOnce(); /* don't let the log get out of hand */
if ( enabled )
{
runOnce(); /* don't let the log get out of hand */
}
else
{
readSettings(); /* even disabled, we want to keep settings current */
}
}
else if ( e->timerId() == mBootstrapTimer ) /* higher frequency bootstrap timer to assist in stabalizing */
else if ( e->timerId() == mBootstrapTimer ) /* higher frequency bootstrap timer to assist in stabalizing */
{
refreshResolvers(true);
if(mBootstrapTicks ++ > BOOTSTRAP_TICKS) /* kill off this timer after a little bit... */
if ( enabled )
{
refreshResolvers(true);
}
if(mBootstrapTicks ++ > BOOTSTRAP_TICKS) /* kill off this timer after a little bit... */
{
killTimer(mBootstrapTimer);
mBootstrapTimer=(-1);
}
}
else if ( e->timerId() == mRefreshTimer ) /* get here once in a while, a slow timer... */
else if ( e->timerId() == mRefreshTimer ) /* get here once in a while, a slow timer... */
{
refreshResolvers(true); /* force a resolver cache refresh */
if ( enabled )
{
refreshResolvers(true); /* force a resolver cache refresh */
}
}
else if ( e->timerId() == mSecondTimer )
{
++mSeconds;
++mSeconds; /* keep track of elapsed time */
}
else
{
Expand Down
9 changes: 5 additions & 4 deletions server/opennicsystem_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool OpenNICSystem_Win::updateResolver(QHostAddress& resolver)
}
else
{
arguments << "interface" << "ip" << "add" << "dns" << interfaceName() << resolver.toString() << "index="+QString::number(index);
arguments << "interface" << "ip" << "add" << "dns" << interfaceName() << resolver.toString() << "index="+QString::number(mResolverIndex);
}
QProcess* process = new QProcess();
process->start(program, arguments);
Expand All @@ -104,7 +104,7 @@ bool OpenNICSystem_Win::updateResolver(QHostAddress& resolver)
return rc;
}

bool OpenNICSystem_Win::endUpdateResolvers(QString& output)
bool OpenNICSystem_Win::endUpdateResolvers()
{
return true;
}
Expand Down Expand Up @@ -193,16 +193,17 @@ bool OpenNICSystem_Win::restoreResolverCache()
QFile file(RESOLVE_CONF);
if (file.open(QIODevice::ReadOnly))
{
int index=0;
beginUpdateResolvers();
while(!file.atEnd())
{
QString buffer = file.readLine().simplified().trimmed();
if ( !buffer.isEmpty() )
{
QHostAddress address(buffer);
updateResolver(address,index++);
updateResolver(address);
}
}
endUpdateResolvers();
file.close();
}
else
Expand Down

0 comments on commit b06c4b6

Please sign in to comment.