diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index 6ca93a7b11..39011b8083 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -437,7 +437,12 @@ int AudioMixer::prepareMixForListeningNode(Node* node) { // loop through all other nodes that have sufficient audio to mix int streamsMixed = 0; - foreach (const SharedNodePointer& otherNode, NodeList::getInstance()->getNodeHash()) { + + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer otherNode = it->second; + if (otherNode->getLinkedData()) { AudioMixerClientData* otherNodeClientData = (AudioMixerClientData*) otherNode->getLinkedData(); @@ -480,7 +485,11 @@ void AudioMixer::readPendingDatagram(const QByteArray& receivedPacket, const Hif QByteArray packet = receivedPacket; populatePacketHeader(packet, PacketTypeMuteEnvironment); - foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { + NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; + if (node->getType() == NodeType::Agent && node->getActiveSocket() && node->getLinkedData() && node != nodeList->sendingNodeForPacket(receivedPacket)) { nodeList->writeDatagram(packet, packet.size(), node); } @@ -548,8 +557,10 @@ void AudioMixer::sendStatsPacket() { NodeList* nodeList = NodeList::getInstance(); int clientNumber = 0; - foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { - + + NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { // if we're too large, send the packet if (sizeOfStats > TOO_BIG_FOR_MTU) { nodeList->sendStatsToDomainServer(statsObject2); @@ -559,9 +570,9 @@ void AudioMixer::sendStatsPacket() { } clientNumber++; - AudioMixerClientData* clientData = static_cast(node->getLinkedData()); + AudioMixerClientData* clientData = static_cast(it->second->getLinkedData()); if (clientData) { - QString property = "jitterStats." + node->getUUID().toString(); + QString property = "jitterStats." + it->first.toString(); QString value = clientData->getAudioStreamStatsString(); statsObject2[qPrintable(property)] = value; somethingToSend = true; @@ -706,7 +717,11 @@ void AudioMixer::run() { _lastPerSecondCallbackTime = now; } - foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { + NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; + if (node->getLinkedData()) { AudioMixerClientData* nodeData = (AudioMixerClientData*)node->getLinkedData(); @@ -873,7 +888,11 @@ void AudioMixer::perSecondActions() { _timeSpentPerHashMatchCallStats.getWindowSum() / WINDOW_LENGTH_USECS * 100.0, _timeSpentPerHashMatchCallStats.getCurrentIntervalSum() / USECS_PER_SECOND * 100.0); - foreach(const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; + if (node->getLinkedData()) { AudioMixerClientData* nodeData = (AudioMixerClientData*)node->getLinkedData(); diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 3ec7c5cfbf..3c2fa92c7c 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -122,7 +122,9 @@ void AvatarMixer::broadcastAvatarData() { AvatarMixerClientData* nodeData = NULL; AvatarMixerClientData* otherNodeData = NULL; - foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { + NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; if (node->getLinkedData() && node->getType() == NodeType::Agent && node->getActiveSocket() && (nodeData = reinterpret_cast(node->getLinkedData()))->getMutex().tryLock()) { ++_sumListeners; @@ -135,7 +137,9 @@ void AvatarMixer::broadcastAvatarData() { // this is an AGENT we have received head data from // send back a packet with other active node data to this node - foreach (const SharedNodePointer& otherNode, nodeList->getNodeHash()) { + NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer otherNode = it->second; if (otherNode->getLinkedData() && otherNode->getUUID() != node->getUUID() && (otherNodeData = reinterpret_cast(otherNode->getLinkedData()))->getMutex().tryLock()) { diff --git a/assignment-client/src/entities/EntityServer.cpp b/assignment-client/src/entities/EntityServer.cpp index 2b7d6873cc..31999f91f7 100644 --- a/assignment-client/src/entities/EntityServer.cpp +++ b/assignment-client/src/entities/EntityServer.cpp @@ -123,9 +123,14 @@ void EntityServer::pruneDeletedEntities() { if (tree->hasAnyDeletedEntities()) { quint64 earliestLastDeletedEntitiesSent = usecTimestampNow() + 1; // in the future - foreach (const SharedNodePointer& otherNode, NodeList::getInstance()->getNodeHash()) { - if (otherNode->getLinkedData()) { - EntityNodeData* nodeData = static_cast(otherNode->getLinkedData()); + + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; + + if (node->getLinkedData()) { + EntityNodeData* nodeData = static_cast(node->getLinkedData()); quint64 nodeLastDeletedEntitiesSentAt = nodeData->getLastDeletedEntitiesSentAt(); if (nodeLastDeletedEntitiesSentAt < earliestLastDeletedEntitiesSent) { earliestLastDeletedEntitiesSent = nodeLastDeletedEntitiesSentAt; diff --git a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp index bd3a7ceee5..b85eb46ebc 100644 --- a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp +++ b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp @@ -248,7 +248,7 @@ int OctreeInboundPacketProcessor::sendNackPackets() { continue; } - const SharedNodePointer& destinationNode = NodeList::getInstance()->getNodeHash().value(nodeUUID); + const SharedNodePointer& destinationNode = NodeList::getInstance()->nodeWithUUID(nodeUUID); // retrieve sequence number stats of node, prune its missing set SequenceNumberStats& sequenceNumberStats = nodeStats.getIncomingEditSequenceNumberStats(); diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index 121cac0273..2b38ce3cdd 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -1137,9 +1137,12 @@ void OctreeServer::aboutToFinish() { qDebug() << qPrintable(_safeServerName) << "server STARTING about to finish..."; qDebug() << qPrintable(_safeServerName) << "inform Octree Inbound Packet Processor that we are shutting down..."; _octreeInboundPacketProcessor->shuttingDown(); - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { - qDebug() << qPrintable(_safeServerName) << "server about to finish while node still connected node:" << *node; - forceNodeShutdown(node); + + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + qDebug() << qPrintable(_safeServerName) << "server about to finish while node still connected node:" << *it->second; + forceNodeShutdown(it->second); } qDebug() << qPrintable(_safeServerName) << "server ENDING about to finish..."; } diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index dbaaca43fa..5dddfd70dd 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -821,7 +821,10 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif if (nodeData->isAuthenticated()) { // if this authenticated node has any interest types, send back those nodes as well - foreach (const SharedNodePointer& otherNode, nodeList->getNodeHash()) { + NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer otherNode = it->second; // reset our nodeByteArray and nodeDataStream QByteArray nodeByteArray; @@ -960,7 +963,10 @@ void DomainServer::readAvailableDatagrams() { void DomainServer::setupPendingAssignmentCredits() { // enumerate the NodeList to find the assigned nodes - foreach (const SharedNodePointer& node, LimitedNodeList::getInstance()->getNodeHash()) { + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; DomainServerNodeData* nodeData = reinterpret_cast(node->getLinkedData()); if (!nodeData->getAssignmentUUID().isNull() && !nodeData->getWalletUUID().isNull()) { @@ -1119,7 +1125,13 @@ void DomainServer::sendHeartbeatToDataServer(const QString& networkAddress) { // add the number of currently connected agent users int numConnectedAuthedUsers = 0; - foreach(const SharedNodePointer& node, LimitedNodeList::getInstance()->getNodeHash()) { + + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + + SharedNodePointer node = it->second; + if (node->getLinkedData() && !static_cast(node->getLinkedData())->getUsername().isEmpty()) { ++numConnectedAuthedUsers; } @@ -1242,8 +1254,9 @@ void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiS parseNodeDataFromByteArray(packetStream, throwawayNodeType, nodePublicAddress, nodeLocalAddress, senderSockAddr); - SharedNodePointer checkInNode = nodeList->updateSocketsForNode(nodeUUID, - nodePublicAddress, nodeLocalAddress); + SharedNodePointer checkInNode = nodeList->nodeWithUUID(nodeUUID); + checkInNode->setPublicSocket(nodePublicAddress); + checkInNode->setLocalSocket(nodeLocalAddress); // update last receive to now quint64 timeNow = usecTimestampNow(); @@ -1425,7 +1438,12 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url QJsonObject assignedNodesJSON; // enumerate the NodeList to find the assigned nodes - foreach (const SharedNodePointer& node, LimitedNodeList::getInstance()->getNodeHash()) { + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + + SharedNodePointer node = it->second; + DomainServerNodeData* nodeData = reinterpret_cast(node->getLinkedData()); if (!nodeData->getAssignmentUUID().isNull()) { @@ -1489,9 +1507,11 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url // enumerate the NodeList to find the assigned nodes LimitedNodeList* nodeList = LimitedNodeList::getInstance(); - foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { + NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { // add the node using the UUID as the key - nodesJSONArray.append(jsonObjectForNode(node)); + nodesJSONArray.append(jsonObjectForNode(it->second)); } rootJSON["nodes"] = nodesJSONArray; @@ -2023,8 +2043,10 @@ void DomainServer::addStaticAssignmentsToQueue() { bool foundMatchingAssignment = false; // enumerate the nodes and check if there is one with an attached assignment with matching UUID - foreach (const SharedNodePointer& node, LimitedNodeList::getInstance()->getNodeHash()) { - if (node->getUUID() == staticAssignment->data()->getUUID()) { + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + if (it->first == staticAssignment->data()->getUUID()) { foundMatchingAssignment = true; } } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6d8b612bc3..f5842ed4c3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2405,7 +2405,10 @@ int Application::sendNackPackets() { char packet[MAX_PACKET_SIZE]; // iterates thru all nodes in NodeList - foreach(const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; if (node->getActiveSocket() && ( node->getType() == NodeType::VoxelServer @@ -2503,7 +2506,13 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node int inViewServers = 0; int unknownJurisdictionServers = 0; - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { + NodeList* nodeList = NodeList::getInstance(); + NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + + SharedNodePointer node = it->second; + // only send to the NodeTypes that are serverType if (node->getActiveSocket() && node->getType() == serverType) { totalServers++; @@ -2560,10 +2569,9 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node if (wantExtraDebugging) { qDebug("perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer); } - - NodeList* nodeList = NodeList::getInstance(); - - foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; // only send to the NodeTypes that are serverType if (node->getActiveSocket() && node->getType() == serverType) { diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 4c0acc553a..20a7bc906f 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -163,7 +163,12 @@ void MetavoxelSystem::render() { } void MetavoxelSystem::refreshVoxelData() { - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + + SharedNodePointer node = it->second; + if (node->getType() == NodeType::MetavoxelServer) { QMutexLocker locker(&node->getMutex()); MetavoxelSystemClient* client = static_cast(node->getLinkedData()); @@ -685,7 +690,11 @@ MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) { } void MetavoxelSystem::guideToAugmented(MetavoxelVisitor& visitor, bool render) { - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; + if (node->getType() == NodeType::MetavoxelServer) { QMutexLocker locker(&node->getMutex()); MetavoxelSystemClient* client = static_cast(node->getLinkedData()); diff --git a/libraries/metavoxels/src/MetavoxelClientManager.cpp b/libraries/metavoxels/src/MetavoxelClientManager.cpp index f1c086da67..7765b8cda2 100644 --- a/libraries/metavoxels/src/MetavoxelClientManager.cpp +++ b/libraries/metavoxels/src/MetavoxelClientManager.cpp @@ -42,7 +42,11 @@ SharedObjectPointer MetavoxelClientManager::findFirstRaySpannerIntersection(cons const glm::vec3& direction, const AttributePointer& attribute, float& distance) { SharedObjectPointer closestSpanner; float closestDistance = FLT_MAX; - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { + + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; + if (node->getType() == NodeType::MetavoxelServer) { QMutexLocker locker(&node->getMutex()); MetavoxelClient* client = static_cast(node->getLinkedData()); @@ -115,7 +119,11 @@ MetavoxelClient* MetavoxelClientManager::createClient(const SharedNodePointer& n } void MetavoxelClientManager::guide(MetavoxelVisitor& visitor) { - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; + if (node->getType() == NodeType::MetavoxelServer) { QMutexLocker locker(&node->getMutex()); MetavoxelClient* client = static_cast(node->getLinkedData()); diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 0f86719761..5a103076b6 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -392,7 +392,10 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) { try { SharedNodePointer matchingNode = _nodeHash[uuid]; - matchingNode->updateSockets(publicSocket, localSocket); + + matchingNode->setPublicSocket(publicSocket); + matchingNode->setLocalSocket(localSocket); + return matchingNode; } catch (std::out_of_range) { // we didn't have this node, so add them @@ -412,7 +415,7 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t unsigned LimitedNodeList::broadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes) { unsigned n = 0; - SnapshotNodeHash snapshotHash = _nodeHash.snapshot_table(); + NodeHashSnapshot snapshotHash = _nodeHash.snapshot_table(); for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { if (destinationNodeTypes.contains(it->second->getType())) { writeDatagram(packet, it->second); @@ -459,7 +462,7 @@ QByteArray LimitedNodeList::constructPingReplyPacket(const QByteArray& pingPacke SharedNodePointer LimitedNodeList::soloNodeOfType(char nodeType) { if (memchr(SOLO_NODE_TYPES, nodeType, sizeof(SOLO_NODE_TYPES))) { - SnapshotNodeHash snapshotHash = _nodeHash.snapshot_table(); + NodeHashSnapshot snapshotHash = _nodeHash.snapshot_table(); for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { if (it->second->getType() == nodeType) { @@ -483,7 +486,7 @@ void LimitedNodeList::resetPacketStats() { void LimitedNodeList::removeSilentNodes() { - SnapshotNodeHash snapshotHash = _nodeHash.snapshot_table(); + NodeHashSnapshot snapshotHash = _nodeHash.snapshot_table(); for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { SharedNodePointer node = it->second; diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 81daa7ace8..63f93458f3 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -55,7 +55,7 @@ typedef QSharedPointer SharedNodePointer; Q_DECLARE_METATYPE(SharedNodePointer) typedef cuckoohash_map NodeHash; -typedef std::vector > SnapshotNodeHash; +typedef std::vector > NodeHashSnapshot; typedef quint8 PingType_t; namespace PingType { @@ -104,8 +104,6 @@ public: SharedNodePointer addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket); - SharedNodePointer updateSocketsForNode(const QUuid& uuid, - const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket); const HifiSockAddr& getLocalSockAddr() const { return _localSockAddr; } diff --git a/libraries/networking/src/Node.h b/libraries/networking/src/Node.h index 05b32d0528..acb6c6f453 100644 --- a/libraries/networking/src/Node.h +++ b/libraries/networking/src/Node.h @@ -81,8 +81,6 @@ public: const HifiSockAddr& getSymmetricSocket() const { return _symmetricSocket; } virtual void setSymmetricSocket(const HifiSockAddr& symmetricSocket); - void updateSockets(const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket); - const HifiSockAddr* getActiveSocket() const { return _activeSocket; } void activatePublicSocket(); diff --git a/libraries/octree/src/JurisdictionListener.cpp b/libraries/octree/src/JurisdictionListener.cpp index f3d9e31acc..606a6c13f2 100644 --- a/libraries/octree/src/JurisdictionListener.cpp +++ b/libraries/octree/src/JurisdictionListener.cpp @@ -40,9 +40,11 @@ bool JurisdictionListener::queueJurisdictionRequest() { NodeList* nodeList = NodeList::getInstance(); - foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { - if (node->getType() == getNodeType() && node->getActiveSocket()) { - _packetSender.queuePacketForSending(node, QByteArray(reinterpret_cast(bufferOut), sizeOut)); + NodeHashSnapshot nodeHashSnapshot = nodeList->getNodeHash().snapshot_table(); + + for (auto it = nodeHashSnapshot.begin(); it != nodeHashSnapshot.end(); it++) { + if (it->second->getType() == getNodeType() && it->second->getActiveSocket()) { + _packetSender.queuePacketForSending(it->second, QByteArray(reinterpret_cast(bufferOut), sizeOut)); nodeCount++; } } diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index 65308f906f..19de2e37e9 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -52,12 +52,13 @@ bool OctreeEditPacketSender::serversExist() const { bool hasServers = false; bool atLeastOneJurisdictionMissing = false; // assume the best NodeList* nodeList = NodeList::getInstance(); - - foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { - + + NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { // only send to the NodeTypes that are getMyNodeType() + SharedNodePointer node = it->second; if (node->getType() == getMyNodeType() && node->getActiveSocket()) { - + QUuid nodeUUID = node->getUUID(); // If we've got Jurisdictions set, then check to see if we know the jurisdiction for this server if (_serverJurisdictions) { @@ -86,8 +87,11 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, unsigned c bool wantDebug = false; NodeList* nodeList = NodeList::getInstance(); - - foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { + + NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; + // only send to the NodeTypes that are getMyNodeType() if (node->getType() == getMyNodeType() && ((node->getUUID() == nodeUUID) || (nodeUUID.isNull()))) { @@ -194,8 +198,10 @@ void OctreeEditPacketSender::queuePacketToNodes(unsigned char* buffer, size_t le // But we can't really do that with a packed message, since each edit message could be destined // for a different server... So we need to actually manage multiple queued packets... one // for each server - - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { + + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; // only send to the NodeTypes that are getMyNodeType() if (node->getActiveSocket() && node->getType() == getMyNodeType()) { QUuid nodeUUID = node->getUUID(); @@ -249,7 +255,9 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType type, unsigned ch _packetsQueueLock.lock(); - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; // only send to the NodeTypes that are getMyNodeType() if (node->getActiveSocket() && node->getType() == getMyNodeType()) { QUuid nodeUUID = node->getUUID(); @@ -384,7 +392,7 @@ void OctreeEditPacketSender::processNackPacket(const QByteArray& packet) { // retrieve packet from history const QByteArray* packet = sentPacketHistory.getPacket(sequenceNumber); if (packet) { - const SharedNodePointer& node = NodeList::getInstance()->getNodeHash().value(sendingNodeUUID); + const SharedNodePointer& node = NodeList::getInstance()->nodeWithUUID(sendingNodeUUID); queuePacketForSending(node, *packet); } } diff --git a/libraries/octree/src/OctreeHeadlessViewer.cpp b/libraries/octree/src/OctreeHeadlessViewer.cpp index 2f21c7a899..b363c654c1 100644 --- a/libraries/octree/src/OctreeHeadlessViewer.cpp +++ b/libraries/octree/src/OctreeHeadlessViewer.cpp @@ -76,8 +76,10 @@ void OctreeHeadlessViewer::queryOctree() { int totalServers = 0; int inViewServers = 0; int unknownJurisdictionServers = 0; - - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { + + NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; // only send to the NodeTypes that are serverType if (node->getActiveSocket() && node->getType() == serverType) { totalServers++; @@ -142,11 +144,11 @@ void OctreeHeadlessViewer::queryOctree() { NodeList* nodeList = NodeList::getInstance(); - foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; // only send to the NodeTypes that are serverType if (node->getActiveSocket() && node->getType() == serverType) { - // get the server bounds for this server QUuid nodeUUID = node->getUUID(); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index fb98124fc9..340d5b3e20 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -520,7 +520,11 @@ void ScriptEngine::run() { // write audio packet to AudioMixer nodes NodeList* nodeList = NodeList::getInstance(); - foreach(const SharedNodePointer& node, nodeList->getNodeHash()) { + NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); + + for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { + SharedNodePointer node = it->second; + // only send to nodes of type AudioMixer if (node->getType() == NodeType::AudioMixer) { // pack sequence number