From 100eda6960bb8ed2ed2c4291daf1b8008a9fdab0 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 16 Sep 2013 19:56:34 -0700 Subject: [PATCH] allow voxel servers in standalone mode to work with new domain server and assignment client --- domain-server/src/main.cpp | 18 +++++++++++++----- .../voxel-server-library/src/VoxelServer.cpp | 7 ++++++- .../voxel-server-library/src/VoxelServer.h | 1 + 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index bfd0d3da21..a829b417ab 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -167,6 +167,9 @@ int main(int argc, const char* argv[]) { // Start the web server. ctx = mg_start(&callbacks, NULL, options); + // wait to check on voxel-servers till we've given our NodeList a chance to get a good list + int checkForVoxelServerAttempt = 0; + while (true) { ::assignmentQueueMutex.lock(); @@ -184,20 +187,25 @@ int main(int argc, const char* argv[]) { ::assignmentQueue.push_front(&audioMixerAssignment); } - // Now handle voxel servers, since there could be more than one, we look for any of them + // Now handle voxel servers. Couple of things are special about voxel servers. + // 1) They can run standalone, and so we want to wait to ask for an assignment until we've given them sufficient + // time to check in with us. So we will look for them, but we want actually add assignments unless we haven't + // seen one after a few tries. + // 2) They aren't soloNodeOfType() so we have to count them. int voxelServerCount = 0; for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { if (node->getType() == NODE_TYPE_VOXEL_SERVER) { voxelServerCount++; } } - - if (voxelServerCount == 0 && + const int MIN_VOXEL_SERVER_CHECKS = 10; + if (checkForVoxelServerAttempt > MIN_VOXEL_SERVER_CHECKS && + voxelServerCount == 0 && std::find(::assignmentQueue.begin(), ::assignmentQueue.end(), &voxelServerAssignment) == ::assignmentQueue.end()) { - qDebug("Missing an Voxel Server and assignment not in queue. Adding.\n"); + qDebug("Missing a Voxel Server and assignment not in queue. Adding.\n"); ::assignmentQueue.push_front(&voxelServerAssignment); } - + checkForVoxelServerAttempt++; ::assignmentQueueMutex.unlock(); diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index f56232264f..b239a180d9 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -65,6 +65,7 @@ NodeWatcher nodeWatcher; // used to cleanup AGENT data when agents are killed int VoxelServer::_argc = 0; const char** VoxelServer::_argv = NULL; +bool VoxelServer::_dontKillOnMissingDomain = false; void attachVoxelNodeDataToNode(Node* newNode) { if (newNode->getLinkedData() == NULL) { @@ -91,6 +92,9 @@ void VoxelServer::setupDomainAndPort(const char* domain, int port) { NodeList::getInstance()->setDomainHostname(domain); } } + + // If we're running in standalone mode, we don't want to kill ourselves when we haven't heard from a domain + _dontKillOnMissingDomain = true; } //int main(int argc, const char * argv[]) { @@ -273,7 +277,8 @@ void VoxelServer::run() { // loop to send to nodes requesting data while (true) { - if (NodeList::getInstance()->getNumNoReplyDomainCheckIns() == MAX_SILENT_DOMAIN_SERVER_CHECK_INS) { + if (!_dontKillOnMissingDomain && + NodeList::getInstance()->getNumNoReplyDomainCheckIns() == MAX_SILENT_DOMAIN_SERVER_CHECK_INS) { break; } diff --git a/libraries/voxel-server-library/src/VoxelServer.h b/libraries/voxel-server-library/src/VoxelServer.h index bf9d3c798b..d51870dbb1 100644 --- a/libraries/voxel-server-library/src/VoxelServer.h +++ b/libraries/voxel-server-library/src/VoxelServer.h @@ -28,6 +28,7 @@ public: private: static int _argc; static const char** _argv; + static bool _dontKillOnMissingDomain; };