From fb27e37607f7133933d1e6d5c28e14e490afdca8 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 30 Sep 2013 14:09:46 -0700 Subject: [PATCH] have AC making create request use its own UUID --- domain-server/src/DomainServer.cpp | 44 ++++++++++++++----- libraries/shared/src/Assignment.h | 1 + .../voxel-server-library/src/VoxelServer.cpp | 3 ++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 63a821dc78..e322513f74 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -83,7 +83,7 @@ void DomainServer::nodeKilled(Node* node) { if (node->getLinkedData()) { Assignment* nodeAssignment = (Assignment*) node->getLinkedData(); - qDebug() << "Adding assignment" << *nodeAssignment << "back to queue.\n"; + qDebug() << "Adding assignment" << *nodeAssignment << " back to queue.\n"; // find this assignment in the static file for (int i = 0; i < MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS; i++) { @@ -494,17 +494,41 @@ int DomainServer::run() { qDebug() << "Received a create assignment -" << *createAssignment << "\n"; - // add the assignment at the back of the queue - _assignmentQueueMutex.lock(); - _assignmentQueue.push_back(createAssignment); - _assignmentQueueMutex.unlock(); + // check the node public address + // if it matches our local address + // or if it's the loopback address we're on the same box + if (nodePublicAddress.sin_addr.s_addr == serverLocalAddress || + nodePublicAddress.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) { + + nodePublicAddress.sin_addr.s_addr = 0; + } - // find the first available spot in the static assignments and put this assignment there - for (int i = 0; i < MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS; i++) { - if (_staticAssignments[i].getUUID().isNull()) { - _staticAssignments[i] = *createAssignment; + // make sure we have a matching node with the UUID packed with the assignment + // if the node has sent no types of interest, assume they want nothing but their own ID back + for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { + if (node->getLinkedData() + && socketMatch((sockaddr*) &nodePublicAddress, node->getPublicSocket()) + && ((Assignment*) node->getLinkedData())->getUUID() == createAssignment->getUUID()) { - // we've stuck the assignment in, break out + // give the create assignment a new UUID + createAssignment->resetUUID(); + + // add the assignment at the back of the queue + _assignmentQueueMutex.lock(); + _assignmentQueue.push_back(createAssignment); + _assignmentQueueMutex.unlock(); + + // find the first available spot in the static assignments and put this assignment there + for (int i = 0; i < MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS; i++) { + if (_staticAssignments[i].getUUID().isNull()) { + _staticAssignments[i] = *createAssignment; + + // we've stuck the assignment in, break out + break; + } + } + + // we found the matching node that asked for create assignment, break out break; } } diff --git a/libraries/shared/src/Assignment.h b/libraries/shared/src/Assignment.h index 4f2ec5e0f3..55e9f2816b 100644 --- a/libraries/shared/src/Assignment.h +++ b/libraries/shared/src/Assignment.h @@ -58,6 +58,7 @@ public: /// \param numBytes the number of bytes left to read in the source buffer Assignment(const unsigned char* dataBuffer, int numBytes); + void setUUID(const QUuid& uuid) { _uuid = uuid; } const QUuid& getUUID() const { return _uuid; } QString getUUIDStringWithoutCurlyBraces() const; void resetUUID() { _uuid = QUuid::createUuid(); } diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index a30668928a..c53d63f770 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -160,6 +160,9 @@ void VoxelServer::parseOtherServerConfigs() { Assignment::VoxelServerType, getLocation()); // use same location as we were created in. + // match this create request with our UUID so the DS knows who the create request is from + voxelServerAssignment.setUUID(_uuid); + int payloadLength = config.length() + sizeof(char); voxelServerAssignment.setPayload((uchar*)config.toLocal8Bit().constData(), payloadLength);