From 6f638fa62cf19116767e6b0e9bfd56b7f5f7d6a5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 6 Feb 2014 10:34:34 -0800 Subject: [PATCH] have domain-server create a UUID for unidentified nodes, closes #1840 --- domain-server/src/DomainServer.cpp | 28 +++++++++++++++++++--------- interface/src/Application.cpp | 1 + interface/src/Application.h | 3 +-- interface/src/avatar/Profile.cpp | 14 -------------- interface/src/avatar/Profile.h | 2 +- libraries/shared/src/NodeList.cpp | 20 ++++++++++++++++++-- libraries/shared/src/NodeList.h | 3 ++- 7 files changed, 42 insertions(+), 29 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 37626e8a43..8c4c9348c0 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -209,6 +209,10 @@ void DomainServer::populateDefaultStaticAssignmentsExcludingTypes(const QSetgetInstance()->nodeWithUUID(nodeUUID)) - { + || nodeList->getInstance()->nodeWithUUID(nodeUUID)) { + + if (nodeUUID.isNull()) { + // this is a check in from an unidentified node + // we need to generate a session UUID for this node + qDebug() << "received a check-in from an unidentified node"; + nodeUUID = QUuid::createUuid(); + qDebug() << "UUID set to" << nodeUUID; + } + SharedNodePointer checkInNode = nodeList->addOrUpdateNode(nodeUUID, nodeType, nodePublicAddress, @@ -291,10 +299,12 @@ void DomainServer::readAvailableDatagrams() { NodeType_t* nodeTypesOfInterest = reinterpret_cast(receivedPacket.data() + packetStream.device()->pos()); + // always send the node their own UUID back + QDataStream broadcastDataStream(&broadcastPacket, QIODevice::Append); + broadcastDataStream << checkInNode->getUUID(); + if (numInterestTypes > 0) { - QDataStream broadcastDataStream(&broadcastPacket, QIODevice::Append); - - // if the node has sent no types of interest, assume they want nothing but their own ID back + // if the node has any interest types, send back those nodes as well foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { if (node->getUUID() != nodeUUID && memchr(nodeTypesOfInterest, node->getType(), numInterestTypes)) { diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 868a6fedb1..43a4b61f02 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -205,6 +205,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer))); connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), &_voxels, SLOT(nodeAdded(SharedNodePointer))); connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), &_voxels, SLOT(nodeKilled(SharedNodePointer))); + connect(nodeList, &NodeList::uuidChanged, this, &Application::updateWindowTitle); // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo("resources/info/ApplicationInfo.ini", QSettings::IniFormat); diff --git a/interface/src/Application.h b/interface/src/Application.h index ac93c3f3da..d66bb8143e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -126,8 +126,6 @@ public: void touchEndEvent(QTouchEvent* event); void touchUpdateEvent(QTouchEvent* event); - void updateWindowTitle(); - void wheelEvent(QWheelEvent* event); void makeVoxel(glm::vec3 position, @@ -213,6 +211,7 @@ signals: public slots: void domainChanged(const QString& domainHostname); + void updateWindowTitle(); void nodeAdded(SharedNodePointer node); void nodeKilled(SharedNodePointer node); void packetSent(quint64 length); diff --git a/interface/src/avatar/Profile.cpp b/interface/src/avatar/Profile.cpp index 7f9ae123dc..a2a412199e 100644 --- a/interface/src/avatar/Profile.cpp +++ b/interface/src/avatar/Profile.cpp @@ -41,20 +41,6 @@ QString Profile::getUserString() const { } } -void Profile::setUUID(const QUuid& uuid) { - _uuid = uuid; - - if (!_uuid.isNull()) { - qDebug() << "Changing NodeList owner UUID to" << uuid; - - // when the UUID is changed we need set it appropriately on the NodeList instance - NodeList::getInstance()->setOwnerUUID(uuid); - - // ask for a window title update so the new UUID is presented - Application::getInstance()->updateWindowTitle(); - } -} - void Profile::updateDomain(const QString& domain) { if (_lastDomain != domain) { _lastDomain = domain; diff --git a/interface/src/avatar/Profile.h b/interface/src/avatar/Profile.h index 8a0c021ed6..c32d89cfea 100644 --- a/interface/src/avatar/Profile.h +++ b/interface/src/avatar/Profile.h @@ -28,7 +28,7 @@ public: const QString& getUsername() const { return _username; } - void setUUID(const QUuid& uuid); + void setUUID(const QUuid& uuid) { _uuid = uuid; } const QUuid& getUUID() { return _uuid; } void updateDomain(const QString& domain); diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index d6b8005263..c83a908a7f 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -64,7 +64,7 @@ NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) : _nodeSocket(this), _ownerType(newOwnerType), _nodeTypesOfInterest(), - _ownerUUID(QUuid::createUuid()), + _ownerUUID(), _numNoReplyDomainCheckIns(0), _assignmentServerSocket(), _publicSockAddr(), @@ -492,6 +492,16 @@ void NodeList::sendDomainServerCheckIn() { } } +void NodeList::setOwnerUUID(const QUuid& ownerUUID) { + QUuid oldUUID = _ownerUUID; + _ownerUUID = ownerUUID; + + if (ownerUUID != oldUUID) { + qDebug() << "NodeList UUID changed from" << oldUUID << "to" << _ownerUUID; + emit uuidChanged(ownerUUID); + } +} + int NodeList::processDomainServerList(const QByteArray& packet) { // this is a packet from the domain server, reset the count of un-replied check-ins _numNoReplyDomainCheckIns = 0; @@ -508,7 +518,13 @@ int NodeList::processDomainServerList(const QByteArray& packet) { QDataStream packetStream(packet); packetStream.skipRawData(numBytesForPacketHeader(packet)); - + + // pull our owner UUID from the packet, it's always the first thing + QUuid newUUID; + packetStream >> newUUID; + setOwnerUUID(newUUID); + + // pull each node in the packet while(packetStream.device()->pos() < packet.size()) { packetStream >> nodeType >> nodeUUID >> nodePublicSocket >> nodeLocalSocket; diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index 6b8acd6e99..90215a27b5 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -73,7 +73,7 @@ public: unsigned short getDomainPort() const { return _domainSockAddr.getPort(); } const QUuid& getOwnerUUID() const { return _ownerUUID; } - void setOwnerUUID(const QUuid& ownerUUID) { _ownerUUID = ownerUUID; } + void setOwnerUUID(const QUuid& ownerUUID); QUdpSocket& getNodeSocket() { return _nodeSocket; } @@ -124,6 +124,7 @@ public slots: void killNodeWithUUID(const QUuid& nodeUUID); signals: void domainChanged(const QString& domainHostname); + void uuidChanged(const QUuid& ownerUUID); void nodeAdded(SharedNodePointer); void nodeKilled(SharedNodePointer); private: