diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 57d687f307..034b98e8db 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -918,26 +918,8 @@ int DomainServer::parseNodeDataFromByteArray(QDataStream& packetStream, NodeType return packetStream.device()->pos(); } -NodeSet DomainServer::nodeInterestListFromPacket(const QByteArray& packet, int numPreceedingBytes) { - QDataStream packetStream(packet); - packetStream.skipRawData(numPreceedingBytes); - - quint8 numInterestTypes = 0; - packetStream >> numInterestTypes; - - quint8 nodeType; - NodeSet nodeInterestSet; - - for (int i = 0; i < numInterestTypes; i++) { - packetStream >> nodeType; - nodeInterestSet.insert((NodeType_t) nodeType); - } - - return nodeInterestSet; -} - void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const HifiSockAddr &senderSockAddr, - const NodeSet& nodeInterestList) { + const NodeSet& nodeInterestSet) { auto limitedNodeList = DependencyManager::get(); QByteArray broadcastPacket = limitedNodeList->byteArrayWithPopulatedHeader(PacketTypeDomainList); @@ -951,7 +933,10 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif DomainServerNodeData* nodeData = reinterpret_cast(node->getLinkedData()); - if (nodeInterestList.size() > 0) { + // store the nodeInterestSet on this DomainServerNodeData, in case it has changed + nodeData->setNodeInterestSet(nodeInterestSet); + + if (nodeInterestSet.size() > 0) { // DTLSServerSession* dtlsSession = _isUsingDTLS ? _dtlsSessions[senderSockAddr] : NULL; int dataMTU = MAX_PACKET_SIZE; @@ -963,7 +948,7 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif QByteArray nodeByteArray; QDataStream nodeDataStream(&nodeByteArray, QIODevice::Append); - if (otherNode->getUUID() != node->getUUID() && nodeInterestList.contains(otherNode->getType())) { + if (otherNode->getUUID() != node->getUUID() && nodeInterestSet.contains(otherNode->getType())) { // don't send avatar nodes to other avatars, that will come from avatar mixer nodeDataStream << *otherNode.data(); @@ -1028,7 +1013,13 @@ void DomainServer::broadcastNewNode(const SharedNodePointer& addedNode) { limitedNodeList->eachMatchingNode( [&](const SharedNodePointer& node)->bool { - return (node->getLinkedData() && node->getActiveSocket() && node != addedNode); + if (node->getLinkedData() && node->getActiveSocket() && node != addedNode) { + // is the added Node in this node's interest list? + DomainServerNodeData* nodeData = dynamic_cast(node->getLinkedData()); + return nodeData->getNodeInterestSet().contains(addedNode->getType()); + } else { + return false; + } }, [&](const SharedNodePointer& node) { QByteArray rfcConnectionSecret = connectionSecretForNodes(node, addedNode).toRfc4122(); diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 74dbde8b4b..f62ba89871 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -58,7 +58,7 @@ public slots: private slots: void aboutToQuit(); - + void loginFailed(); void readAvailableDatagrams(); void setupPendingAssignmentCredits(); @@ -100,9 +100,8 @@ private: HifiSockAddr& publicSockAddr, HifiSockAddr& localSockAddr, const HifiSockAddr& senderSockAddr); - NodeSet nodeInterestListFromPacket(const QByteArray& packet, int numPreceedingBytes); void sendDomainListToNode(const SharedNodePointer& node, const HifiSockAddr& senderSockAddr, - const NodeSet& nodeInterestList); + const NodeSet& nodeInterestSet); QUuid connectionSecretForNodes(const SharedNodePointer& nodeA, const SharedNodePointer& nodeB); void broadcastNewNode(const SharedNodePointer& node); diff --git a/domain-server/src/DomainServerNodeData.h b/domain-server/src/DomainServerNodeData.h index 366ee8c730..a91a7e0b9c 100644 --- a/domain-server/src/DomainServerNodeData.h +++ b/domain-server/src/DomainServerNodeData.h @@ -12,44 +12,47 @@ #ifndef hifi_DomainServerNodeData_h #define hifi_DomainServerNodeData_h - #include #include #include #include #include +#include class DomainServerNodeData : public NodeData { public: DomainServerNodeData(); int parseData(const QByteArray& packet) { return 0; } - + const QJsonObject& getStatsJSONObject() const { return _statsJSONObject; } - + void parseJSONStatsPacket(const QByteArray& statsPacket); - + void setAssignmentUUID(const QUuid& assignmentUUID) { _assignmentUUID = assignmentUUID; } const QUuid& getAssignmentUUID() const { return _assignmentUUID; } - + void setWalletUUID(const QUuid& walletUUID) { _walletUUID = walletUUID; } const QUuid& getWalletUUID() const { return _walletUUID; } - + void setUsername(const QString& username) { _username = username; } const QString& getUsername() const { return _username; } - + QElapsedTimer& getPaymentIntervalTimer() { return _paymentIntervalTimer; } - + void setSendingSockAddr(const HifiSockAddr& sendingSockAddr) { _sendingSockAddr = sendingSockAddr; } const HifiSockAddr& getSendingSockAddr() { return _sendingSockAddr; } - + void setIsAuthenticated(bool isAuthenticated) { _isAuthenticated = isAuthenticated; } bool isAuthenticated() const { return _isAuthenticated; } - + QHash& getSessionSecretHash() { return _sessionSecretHash; } + + const NodeSet& getNodeInterestSet() const { return _nodeInterestSet; } + void setNodeInterestSet(const NodeSet& nodeInterestSet) { _nodeInterestSet = nodeInterestSet; } private: QJsonObject mergeJSONStatsFromNewObject(const QJsonObject& newObject, QJsonObject destinationObject); - + QHash _sessionSecretHash; QUuid _assignmentUUID; QUuid _walletUUID; @@ -58,6 +61,7 @@ private: QJsonObject _statsJSONObject; HifiSockAddr _sendingSockAddr; bool _isAuthenticated; + NodeSet _nodeInterestSet; }; #endif // hifi_DomainServerNodeData_h diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index ec4b7546f0..94063f49b1 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -60,8 +60,6 @@ const QString USERNAME_UUID_REPLACEMENT_STATS_KEY = "$username"; class HifiSockAddr; -typedef QSet NodeSet; - typedef QSharedPointer SharedNodePointer; Q_DECLARE_METATYPE(SharedNodePointer) diff --git a/libraries/networking/src/Node.h b/libraries/networking/src/Node.h index b1f5d8b037..4c1b6e9d18 100644 --- a/libraries/networking/src/Node.h +++ b/libraries/networking/src/Node.h @@ -23,25 +23,11 @@ #include "HifiSockAddr.h" #include "NetworkPeer.h" #include "NodeData.h" +#include "NodeType.h" #include "PacketHeaders.h" #include "SimpleMovingAverage.h" #include "MovingPercentile.h" -typedef quint8 NodeType_t; - -namespace NodeType { - const NodeType_t DomainServer = 'D'; - const NodeType_t EntityServer = 'o'; // was ModelServer - const NodeType_t EnvironmentServer = 'E'; - const NodeType_t Agent = 'I'; - const NodeType_t AudioMixer = 'M'; - const NodeType_t AvatarMixer = 'W'; - const NodeType_t Unassigned = 1; - - void init(); - const QString& getNodeTypeName(NodeType_t nodeType); -} - class Node : public NetworkPeer { Q_OBJECT public: diff --git a/libraries/networking/src/NodeType.h b/libraries/networking/src/NodeType.h new file mode 100644 index 0000000000..4427b87158 --- /dev/null +++ b/libraries/networking/src/NodeType.h @@ -0,0 +1,34 @@ +// +// NodeType.h +// libraries/networking/src +// +// Created by Stephen Birarda on 05/29/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_NodeType_h +#define hifi_NodeType_h + +#pragma once + +typedef quint8 NodeType_t; + +namespace NodeType { + const NodeType_t DomainServer = 'D'; + const NodeType_t EntityServer = 'o'; // was ModelServer + const NodeType_t EnvironmentServer = 'E'; + const NodeType_t Agent = 'I'; + const NodeType_t AudioMixer = 'M'; + const NodeType_t AvatarMixer = 'W'; + const NodeType_t Unassigned = 1; + + void init(); + const QString& getNodeTypeName(NodeType_t nodeType); +} + +typedef QSet NodeSet; + +#endif // hifi_NodeType_h