13 #ifndef hifi_NodeList_h
14 #define hifi_NodeList_h
24 #include <TBBHelpers.h>
26 #include <QtCore/QElapsedTimer>
27 #include <QtCore/QMutex>
28 #include <QtCore/QSet>
29 #include <QtCore/QSharedPointer>
30 #include <QtNetwork/QHostAddress>
31 #include <QtNetwork/QUdpSocket>
33 #include <DependencyManager.h>
34 #include <SettingHandle.h>
36 #include "DomainHandler.h"
37 #include "LimitedNodeList.h"
40 const quint64 DOMAIN_SERVER_CHECK_IN_MSECS = 1 * 1000;
42 using PacketOrPacketList = std::pair<std::unique_ptr<NLPacket>, std::unique_ptr<NLPacketList>>;
43 using NodePacketOrPacketListPair = std::pair<SharedNodePointer, PacketOrPacketList>;
45 using NodePacketPair = std::pair<SharedNodePointer, std::unique_ptr<NLPacket>>;
46 using NodeSharedPacketPair = std::pair<SharedNodePointer, QSharedPointer<NLPacket>>;
47 using NodeSharedReceivedMessagePair = std::pair<SharedNodePointer, QSharedPointer<ReceivedMessage>>;
52 class NodeList :
public LimitedNodeList {
58 NodeType_t getOwnerType()
const {
return _ownerType.load(); }
59 void setOwnerType(
NodeType_t ownerType) { _ownerType.store(ownerType); }
61 Q_INVOKABLE qint64 sendStats(QJsonObject statsObject, SockAddr destination);
62 Q_INVOKABLE qint64 sendStatsToDomainServer(QJsonObject statsObject);
64 DomainHandler& getDomainHandler() {
return _domainHandler; }
66 const NodeSet& getNodeInterestSet()
const {
return _nodeTypesOfInterest; }
67 void addNodeTypeToInterestSet(
NodeType_t nodeTypeToAdd);
68 void addSetOfNodeTypesToNodeInterestSet(
const NodeSet& setOfNodeTypes);
69 void resetNodeInterestSet() { _nodeTypesOfInterest.clear(); }
71 void setAssignmentServerSocket(
const SockAddr& serverSocket) { _assignmentServerSocket = serverSocket; }
74 void disableDomainPortAutoDiscovery(
bool disabled =
false) { _domainPortAutoDiscovery = !disabled; };
76 void setIsShuttingDown(
bool isShuttingDown) { _isShuttingDown = isShuttingDown; }
78 void ignoreNodesInRadius(
bool enabled =
true);
79 bool getIgnoreRadiusEnabled()
const {
return _ignoreRadiusEnabled.get(); }
80 void toggleIgnoreRadius() { ignoreNodesInRadius(!getIgnoreRadiusEnabled()); }
81 void enableIgnoreRadius() { ignoreNodesInRadius(
true); }
82 void disableIgnoreRadius() { ignoreNodesInRadius(
false); }
83 void ignoreNodeBySessionID(
const QUuid& nodeID,
bool ignoreEnabled);
84 bool isIgnoringNode(
const QUuid& nodeID)
const;
85 void personalMuteNodeBySessionID(
const QUuid& nodeID,
bool muteEnabled);
86 bool isPersonalMutingNode(
const QUuid& nodeID)
const;
87 void setAvatarGain(
const QUuid& nodeID,
float gain);
88 float getAvatarGain(
const QUuid& nodeID);
89 void setInjectorGain(
float gain);
90 float getInjectorGain();
92 void kickNodeBySessionID(
const QUuid& nodeID,
unsigned int banFlags);
93 void muteNodeBySessionID(
const QUuid& nodeID);
94 void requestUsernameFromSessionID(
const QUuid& nodeID);
95 bool getRequestsDomainListData() {
return _requestsDomainListData; }
96 void setRequestsDomainListData(
bool isRequesting);
98 bool getSendDomainServerCheckInEnabled() {
return _sendDomainServerCheckInEnabled; }
99 void setSendDomainServerCheckInEnabled(
bool enabled) { _sendDomainServerCheckInEnabled = enabled; }
101 void removeFromIgnoreMuteSets(
const QUuid& nodeID);
103 virtual bool isDomainServer()
const override {
return false; }
104 virtual QUuid getDomainUUID()
const override {
return _domainHandler.getUUID(); }
105 virtual Node::LocalID getDomainLocalID()
const override {
return _domainHandler.getLocalID(); }
106 virtual SockAddr getDomainSockAddr()
const override {
return _domainHandler.getSockAddr(); }
109 void reset(QString reason,
bool skipDomainHandlerReset =
false);
110 void resetFromDomainHandler() { reset(
"Reset from Domain Handler",
true); }
112 void sendDomainServerCheckIn();
113 void handleDSPathQuery(
const QString& newPath);
115 void processDomainList(QSharedPointer<ReceivedMessage> message);
116 void processDomainServerAddedNode(QSharedPointer<ReceivedMessage> message);
117 void processDomainServerRemovedNode(QSharedPointer<ReceivedMessage> message);
118 void processDomainServerPathResponse(QSharedPointer<ReceivedMessage> message);
120 void processDomainServerConnectionTokenPacket(QSharedPointer<ReceivedMessage> message);
122 void processPingPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer sendingNode);
123 void processPingReplyPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer sendingNode);
125 void processICEPingPacket(QSharedPointer<ReceivedMessage> message);
127 void processUsernameFromIDReply(QSharedPointer<ReceivedMessage> message);
130 bool adjustCanRezAvatarEntitiesPermissions(
const QJsonObject& domainSettingsObject, NodePermissions& permissions,
132 void adjustCanRezAvatarEntitiesPerSettings(
const QJsonObject& domainSettingsObject);
134 #if (PR_BUILD || DEV_BUILD)
135 void toggleSendNewerDSConnectVersion(
bool shouldSendNewerVersion) { _shouldSendNewerVersion = shouldSendNewerVersion; }
139 void receivedDomainServerList();
140 void ignoredNode(
const QUuid& nodeID,
bool enabled);
141 void ignoreRadiusEnabledChanged(
bool isIgnored);
142 void usernameFromIDReply(
const QString& nodeID,
const QString& username,
const QString& machineFingerprint,
bool isAdmin);
145 void stopKeepalivePingTimer();
146 void sendPendingDSPathQuery();
147 void handleICEConnectionToDomainServer();
149 void startNodeHolePunch(
const SharedNodePointer& node);
150 void handleNodePingTimeout();
152 void pingPunchForDomainServer();
154 void sendKeepAlivePings();
156 void maybeSendIgnoreSetToNode(SharedNodePointer node);
159 Q_DISABLE_COPY(NodeList)
160 NodeList() : LimitedNodeList(INVALID_PORT, INVALID_PORT) {
163 NodeList(
char ownerType,
int socketListenPort = INVALID_PORT,
int dtlsListenPort = INVALID_PORT);
165 void processDomainServerAuthRequest(
const QByteArray& packet);
166 void requestAuthForDomainServer();
167 void activateSocketFromNodeCommunication(ReceivedMessage& message,
const SharedNodePointer& sendingNode);
168 void timePingReply(ReceivedMessage& message,
const SharedNodePointer& sendingNode);
170 void sendDSPathQuery(
const QString& newPath);
172 void parseNodeFromPacketStream(QDataStream& packetStream);
174 void pingPunchForInactiveNode(
const SharedNodePointer& node);
176 bool sockAddrBelongsToDomainOrNode(
const SockAddr& sockAddr);
178 std::atomic<NodeType_t> _ownerType;
179 NodeSet _nodeTypesOfInterest;
180 DomainHandler _domainHandler;
181 SockAddr _assignmentServerSocket;
182 bool _isShuttingDown {
false };
183 QTimer _keepAlivePingTimer;
184 bool _requestsDomainListData {
false };
186 bool _sendDomainServerCheckInEnabled {
true };
187 bool _domainPortAutoDiscovery {
true };
189 mutable QReadWriteLock _ignoredSetLock;
190 tbb::concurrent_unordered_set<QUuid, UUIDHasher> _ignoredNodeIDs;
191 mutable QReadWriteLock _personalMutedSetLock;
192 tbb::concurrent_unordered_set<QUuid, UUIDHasher> _personalMutedNodeIDs;
193 mutable QReadWriteLock _avatarGainMapLock;
194 tbb::concurrent_unordered_map<QUuid, float, UUIDHasher> _avatarGainMap;
196 std::atomic<float> _avatarGain { 0.0f };
197 std::atomic<float> _injectorGain { 0.0f };
199 void sendIgnoreRadiusStateToNode(
const SharedNodePointer& destinationNode);
200 #if defined(Q_OS_ANDROID)
206 #if (PR_BUILD || DEV_BUILD)
207 bool _shouldSendNewerVersion {
false };
210 bool _hasDomainAccountManager {
false };
quint8 NodeType_t
An 8-bit value identifying the type of a node - domain server, audio mixer, etc.
Definition: NodeType.h:22
Holds information used for request, creation, and deployment of assignments.
Definition: Assignment.h:28