have domain-server create a UUID for unidentified nodes, closes #1840

This commit is contained in:
Stephen Birarda 2014-02-06 10:34:34 -08:00
parent f92f9ec0c2
commit 6f638fa62c
7 changed files with 42 additions and 29 deletions

View file

@ -209,6 +209,10 @@ void DomainServer::populateDefaultStaticAssignmentsExcludingTypes(const QSet<Ass
}
}
const NodeSet STATICALLY_ASSIGNED_NODES = NodeSet() << NodeType::AudioMixer
<< NodeType::AvatarMixer << NodeType::VoxelServer << NodeType::ParticleServer
<< NodeType::MetavoxelServer;
void DomainServer::readAvailableDatagrams() {
NodeList* nodeList = NodeList::getInstance();
@ -255,18 +259,22 @@ void DomainServer::readAvailableDatagrams() {
}
}
const NodeSet STATICALLY_ASSIGNED_NODES = NodeSet() << NodeType::AudioMixer
<< NodeType::AvatarMixer << NodeType::VoxelServer << NodeType::ParticleServer
<< NodeType::MetavoxelServer;
SharedAssignmentPointer matchingStaticAssignment;
// check if this is a non-statically assigned node, a node that is assigned and checking in for the first time
// or a node that has already checked in and is continuing to report for duty
if (!STATICALLY_ASSIGNED_NODES.contains(nodeType)
|| (matchingStaticAssignment = matchingStaticAssignmentForCheckIn(nodeUUID, nodeType))
|| nodeList->getInstance()->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<NodeType_t*>(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)) {

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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: