diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index e7fdcd32c7..9dd3c0377f 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -388,7 +388,7 @@ void Audio::handleAudioInput() { NodeList* nodeList = NodeList::getInstance(); SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer); - if (audioMixer && nodeList->getNodeActiveSocketOrPing(audioMixer)) { + if (audioMixer && audioMixer->getActiveSocket()) { MyAvatar* interfaceAvatar = Application::getInstance()->getAvatar(); glm::vec3 headPosition = interfaceAvatar->getHead().getPosition(); glm::quat headOrientation = interfaceAvatar->getHead().getOrientation(); diff --git a/interface/src/ui/VoxelStatsDialog.cpp b/interface/src/ui/VoxelStatsDialog.cpp index 1d94705504..0ac0a2b933 100644 --- a/interface/src/ui/VoxelStatsDialog.cpp +++ b/interface/src/ui/VoxelStatsDialog.cpp @@ -265,7 +265,7 @@ void VoxelStatsDialog::showOctreeServersOfType(int& serverCount, NodeType_t serv std::stringstream extraDetails(""); std::stringstream linkDetails(""); - if (nodeList->getNodeActiveSocketOrPing(node)) { + if (node->getActiveSocket()) { serverDetails << "active "; } else { serverDetails << "inactive "; diff --git a/libraries/octree/src/JurisdictionListener.cpp b/libraries/octree/src/JurisdictionListener.cpp index a15c72cc5e..20e5af012f 100644 --- a/libraries/octree/src/JurisdictionListener.cpp +++ b/libraries/octree/src/JurisdictionListener.cpp @@ -45,7 +45,7 @@ bool JurisdictionListener::queueJurisdictionRequest() { NodeList* nodeList = NodeList::getInstance(); foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { - if (nodeList->getNodeActiveSocketOrPing(node) && node->getType() == getNodeType()) { + if (node->getType() == getNodeType() && node->getActiveSocket()) { _packetSender.queuePacketForSending(node, QByteArray(reinterpret_cast(bufferOut), sizeOut)); nodeCount++; } diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index ca3ffc707f..1c1ed13f8d 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -60,19 +60,17 @@ bool OctreeEditPacketSender::serversExist() const { foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { // only send to the NodeTypes that are getMyNodeType() - if (node->getType() == getMyNodeType()) { - if (nodeList->getNodeActiveSocketOrPing(node)) { - QUuid nodeUUID = node->getUUID(); - // If we've got Jurisdictions set, then check to see if we know the jurisdiction for this server - if (_serverJurisdictions) { - // lookup our nodeUUID in the jurisdiction map, if it's missing then we're - // missing at least one jurisdiction - if ((*_serverJurisdictions).find(nodeUUID) == (*_serverJurisdictions).end()) { - atLeastOnJurisdictionMissing = true; - } + 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) { + // lookup our nodeUUID in the jurisdiction map, if it's missing then we're + // missing at least one jurisdiction + if ((*_serverJurisdictions).find(nodeUUID) == (*_serverJurisdictions).end()) { + atLeastOnJurisdictionMissing = true; } - hasServers = true; } + hasServers = true; } if (atLeastOnJurisdictionMissing) { break; // no point in looking further... @@ -91,7 +89,7 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, unsigned c // only send to the NodeTypes that are getMyNodeType() if (node->getType() == getMyNodeType() && ((node->getUUID() == nodeUUID) || (nodeUUID.isNull()))) { - if (nodeList->getNodeActiveSocketOrPing(node)) { + if (node->getActiveSocket()) { queuePacketForSending(node, QByteArray(reinterpret_cast(buffer), length)); // debugging output... diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 43f3240b12..0dc94a20b3 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -127,7 +127,7 @@ qint64 NodeList::writeDatagram(const QByteArray& datagram, const SharedNodePoint // if we don't have an ovveriden address, assume they want to send to the node's active socket const HifiSockAddr* destinationSockAddr = &overridenSockAddr; if (overridenSockAddr.isNull()) { - if (getNodeActiveSocketOrPing(destinationNode)) { + if (destinationNode->getActiveSocket()) { // use the node's active socket as the destination socket destinationSockAddr = destinationNode->getActiveSocket(); } else { @@ -140,6 +140,8 @@ qint64 NodeList::writeDatagram(const QByteArray& datagram, const SharedNodePoint // setup the MD5 hash for source verification in the header replaceHashInPacketGivenConnectionUUID(datagramCopy, destinationNode->getConnectionSecret()); + qDebug() << "Sending a packet of type" << packetTypeForPacket(datagram); + return _nodeSocket.writeDatagram(datagramCopy, destinationSockAddr->getAddress(), destinationSockAddr->getPort()); } @@ -680,8 +682,11 @@ SharedNodePointer NodeList::addOrUpdateNode(const QUuid& uuid, char nodeType, Node* newNode = new Node(uuid, nodeType, publicSocket, localSocket); SharedNodePointer newNodeSharedPointer(newNode, &QObject::deleteLater); + // try and ping the new node right away to open a connection + pingPublicAndLocalSocketsForInactiveNode(newNodeSharedPointer); + _nodeHash.insert(newNode->getUUID(), newNodeSharedPointer); - + _nodeHashMutex.unlock(); qDebug() << "Added" << *newNode; @@ -740,16 +745,6 @@ void NodeList::pingInactiveNodes() { } } -const HifiSockAddr* NodeList::getNodeActiveSocketOrPing(const SharedNodePointer& node) { - if (node && node->getActiveSocket()) { - return node->getActiveSocket(); - } else if (node) { - pingPublicAndLocalSocketsForInactiveNode(node); - } - - return NULL; -} - void NodeList::activateSocketFromNodeCommunication(const QByteArray& packet, const SharedNodePointer& sendingNode) { // deconstruct this ping packet to see if it is a public or local reply QDataStream packetStream(packet); diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index 408459e51f..b6afd21451 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -129,8 +129,6 @@ public: void loadData(QSettings* settings); void saveData(QSettings* settings); - - const HifiSockAddr* getNodeActiveSocketOrPing(const SharedNodePointer& node); public slots: void sendDomainServerCheckIn(); void pingInactiveNodes(); diff --git a/libraries/shared/src/PacketHeaders.cpp b/libraries/shared/src/PacketHeaders.cpp index 7193b6f648..d4049e7310 100644 --- a/libraries/shared/src/PacketHeaders.cpp +++ b/libraries/shared/src/PacketHeaders.cpp @@ -105,12 +105,12 @@ QUuid uuidFromPacketHeader(const QByteArray& packet) { } QByteArray hashFromPacketHeader(const QByteArray& packet) { - return packet.mid(NUM_STATIC_HEADER_BYTES - NUM_BYTES_MD5_HASH, NUM_BYTES_MD5_HASH); + return packet.mid(numBytesForPacketHeader(packet) - NUM_BYTES_MD5_HASH, NUM_BYTES_MD5_HASH); } QByteArray hashForPacketAndConnectionUUID(const QByteArray& packet, const QUuid& connectionUUID) { - return QCryptographicHash::hash(packet.mid(numBytesForPacketHeader(packet)) - + connectionUUID.toRfc4122(), QCryptographicHash::Md5); + return QCryptographicHash::hash(packet.mid(numBytesForPacketHeader(packet)) + connectionUUID.toRfc4122(), + QCryptographicHash::Md5); } void replaceHashInPacketGivenConnectionUUID(QByteArray& packet, const QUuid& connectionUUID) {