From 996c76c723f4dd591707be56da8ad74ecbce06fb Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 6 Nov 2014 16:05:01 -0800 Subject: [PATCH] repairs for node teardown on domain dissappear or node disconnect --- domain-server/src/DomainServer.cpp | 4 +-- libraries/networking/src/LimitedNodeList.cpp | 34 ++++++++++++++++---- libraries/networking/src/LimitedNodeList.h | 2 ++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index cb4b1c8026..153fbae0c9 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -2019,9 +2019,9 @@ void DomainServer::addStaticAssignmentsToQueue() { QHash::iterator staticAssignment = staticHashCopy.begin(); while (staticAssignment != staticHashCopy.end()) { // add any of the un-matched static assignments to the queue - + // enumerate the nodes and check if there is one with an attached assignment with matching UUID - if (NodeList::getInstance()->nodeWithUUID(staticAssignment->data()->getUUID())) { + if (!NodeList::getInstance()->nodeWithUUID(staticAssignment->data()->getUUID())) { // this assignment has not been fulfilled - reset the UUID and add it to the assignment queue refreshStaticAssignmentAndAddToQueue(*staticAssignment); } diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index ac63941882..767935bf3d 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -359,11 +359,18 @@ SharedNodePointer LimitedNodeList::sendingNodeForPacket(const QByteArray& packet void LimitedNodeList::eraseAllNodes() { qDebug() << "Clearing the NodeList. Deleting all nodes in list."; + QSet killedNodes; + eachNode([&killedNodes](const SharedNodePointer& node){ + killedNodes.insert(node); + }); + // iterate the current nodes, emit that they are dying and remove them from the hash - QWriteLocker writeLock(&_nodeMutex); - for (NodeHash::iterator it = _nodeHash.begin(); it != _nodeHash.end(); ++it) { - emit nodeKilled(it->second); - it = _nodeHash.unsafe_erase(it); + _nodeMutex.lockForWrite(); + _nodeHash.clear(); + _nodeMutex.unlock(); + + foreach(const SharedNodePointer& killedNode, killedNodes) { + handleNodeKill(killedNode); } } @@ -378,7 +385,8 @@ void LimitedNodeList::killNodeWithUUID(const QUuid& nodeUUID) { QWriteLocker writeLocker(&_nodeMutex); _nodeHash.unsafe_erase(it); - emit nodeKilled(matchingNode); + + handleNodeKill(matchingNode); } } @@ -390,6 +398,11 @@ void LimitedNodeList::processKillNode(const QByteArray& dataByteArray) { killNodeWithUUID(nodeUUID); } +void LimitedNodeList::handleNodeKill(const SharedNodePointer& node) { + qDebug() << "Killed" << *node; + emit nodeKilled(node); +} + SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) { try { @@ -478,14 +491,17 @@ void LimitedNodeList::resetPacketStats() { } void LimitedNodeList::removeSilentNodes() { - eachNodeHashIterator([this](NodeHash::iterator& it){ + QSet killedNodes; + + eachNodeHashIterator([&](NodeHash::iterator& it){ SharedNodePointer node = it->second; node->getMutex().lock(); if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > (NODE_SILENCE_THRESHOLD_MSECS * 1000)) { // call the NodeHash erase to get rid of this node it = _nodeHash.unsafe_erase(it); - emit nodeKilled(node); + + killedNodes.insert(node); } else { // we didn't erase this node, push the iterator forwards ++it; @@ -493,6 +509,10 @@ void LimitedNodeList::removeSilentNodes() { node->getMutex().unlock(); }); + + foreach(const SharedNodePointer& killedNode, killedNodes) { + handleNodeKill(killedNode); + } } const uint32_t RFC_5389_MAGIC_COOKIE = 0x2112A442; diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index a29902a7c9..d713f69d29 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -187,6 +187,8 @@ protected: const QUuid& connectionSecret); void changeSocketBufferSizes(int numBytes); + + void handleNodeKill(const SharedNodePointer& node); QUuid _sessionUUID; NodeHash _nodeHash;