have the domain-server generate connection secrets, closes

This commit is contained in:
Stephen Birarda 2014-02-06 11:30:53 -08:00
parent 6f638fa62c
commit 3dca04aacb
6 changed files with 72 additions and 12 deletions

View file

@ -21,6 +21,8 @@
#include <SharedUtil.h>
#include <UUID.h>
#include "DomainServerNodeData.h"
#include "DomainServer.h"
const int RESTART_HOLD_TIME_MSECS = 5 * 1000;
@ -57,8 +59,9 @@ DomainServer::DomainServer(int argc, char* argv[]) :
populateDefaultStaticAssignmentsExcludingTypes(parsedTypes);
NodeList* nodeList = NodeList::createInstance(NodeType::DomainServer, domainServerPort);
connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), this, SLOT(nodeKilled(SharedNodePointer)));
connect(nodeList, &NodeList::nodeAdded, this, &DomainServer::nodeAdded);
connect(nodeList, &NodeList::nodeKilled, this, &DomainServer::nodeKilled);
QTimer* silentNodeTimer = new QTimer(this);
connect(silentNodeTimer, SIGNAL(timeout()), nodeList, SLOT(removeSilentNodes()));
@ -270,9 +273,7 @@ void DomainServer::readAvailableDatagrams() {
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,
@ -303,14 +304,33 @@ void DomainServer::readAvailableDatagrams() {
QDataStream broadcastDataStream(&broadcastPacket, QIODevice::Append);
broadcastDataStream << checkInNode->getUUID();
DomainServerNodeData* nodeData = reinterpret_cast<DomainServerNodeData*>(checkInNode->getLinkedData());
if (numInterestTypes > 0) {
// 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)) {
foreach (const SharedNodePointer& otherNode, nodeList->getNodeHash()) {
if (otherNode->getUUID() != nodeUUID &&
memchr(nodeTypesOfInterest, otherNode->getType(), numInterestTypes)) {
// don't send avatar nodes to other avatars, that will come from avatar mixer
broadcastDataStream << *node.data();
broadcastDataStream << *otherNode.data();
// pack the secret that these two nodes will use to communicate with each other
QUuid secretUUID = nodeData->getSessionSecretHash().value(otherNode->getUUID());
if (secretUUID.isNull()) {
// generate a new secret UUID these two nodes can use
secretUUID = QUuid::createUuid();
// set that on the current Node's sessionSecretHash
nodeData->getSessionSecretHash().insert(otherNode->getUUID(), secretUUID);
// set it on the other Node's sessionSecretHash
reinterpret_cast<DomainServerNodeData*>(otherNode->getLinkedData())
->getSessionSecretHash().insert(nodeUUID, secretUUID);
}
broadcastDataStream << secretUUID;
}
}
}
@ -556,6 +576,11 @@ void DomainServer::refreshStaticAssignmentAndAddToQueue(SharedAssignmentPointer&
_staticAssignmentHash.remove(oldUUID);
}
void DomainServer::nodeAdded(SharedNodePointer node) {
// we don't use updateNodeWithData, so add the DomainServerNodeData to the node here
node->setLinkedData(new DomainServerNodeData());
}
void DomainServer::nodeKilled(SharedNodePointer node) {
// if this node's UUID matches a static assignment we need to throw it back in the assignment queue
SharedAssignmentPointer matchedAssignment = _staticAssignmentHash.value(node->getUUID());

View file

@ -30,7 +30,9 @@ public:
void exit(int retCode = 0);
public slots:
/// Called by NodeList to inform us that a node has been killed.
/// Called by NodeList to inform us a node has been added
void nodeAdded(SharedNodePointer node);
/// Called by NodeList to inform us a node has been killed
void nodeKilled(SharedNodePointer node);
private:

View file

@ -0,0 +1,26 @@
//
// DomainServerNodeData.h
// hifi
//
// Created by Stephen Birarda on 2/6/2014.
// Copyright (c) 2014 HighFidelity, Inc. All rights reserved.
//
#ifndef __hifi__DomainServerNodeData__
#define __hifi__DomainServerNodeData__
#include <QtCore/QHash>
#include <NodeData.h>
class DomainServerNodeData : public NodeData {
public:
DomainServerNodeData() : _sessionSecretHash() {};
int parseData(const QByteArray& packet) { return 0; }
QHash<QUuid, QUuid>& getSessionSecretHash() { return _sessionSecretHash; }
private:
QHash<QUuid, QUuid> _sessionSecretHash;
};
#endif /* defined(__hifi__DomainServerNodeData__) */

View file

@ -52,6 +52,7 @@ Node::Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const
_publicSocket(publicSocket),
_localSocket(localSocket),
_activeSocket(NULL),
_connectionSecret(),
_bytesReceivedMovingAverage(NULL),
_linkedData(NULL),
_isAlive(true),

View file

@ -56,7 +56,6 @@ public:
char getType() const { return _type; }
void setType(char type) { _type = type; }
const QUuid& getUUID() const { return _uuid; }
void setUUID(const QUuid& uuid) { _uuid = uuid; }
@ -76,6 +75,9 @@ public:
void activatePublicSocket();
void activateLocalSocket();
const QUuid& getConnectionSecret() const { return _connectionSecret; }
void setConnectionSecret(const QUuid& connectionSecret) { _connectionSecret = connectionSecret; }
NodeData* getLinkedData() const { return _linkedData; }
void setLinkedData(NodeData* linkedData) { _linkedData = linkedData; }
@ -109,6 +111,7 @@ private:
HifiSockAddr _publicSocket;
HifiSockAddr _localSocket;
HifiSockAddr* _activeSocket;
QUuid _connectionSecret;
SimpleMovingAverage* _bytesReceivedMovingAverage;
NodeData* _linkedData;
bool _isAlive;

View file

@ -511,7 +511,7 @@ int NodeList::processDomainServerList(const QByteArray& packet) {
// setup variables to read into from QDataStream
qint8 nodeType;
QUuid nodeUUID;
QUuid nodeUUID, connectionUUID;
HifiSockAddr nodePublicSocket;
HifiSockAddr nodeLocalSocket;
@ -534,7 +534,10 @@ int NodeList::processDomainServerList(const QByteArray& packet) {
nodePublicSocket.setAddress(_domainSockAddr.getAddress());
}
addOrUpdateNode(nodeUUID, nodeType, nodePublicSocket, nodeLocalSocket);
SharedNodePointer node = addOrUpdateNode(nodeUUID, nodeType, nodePublicSocket, nodeLocalSocket);
packetStream >> connectionUUID;
node->setConnectionSecret(connectionUUID);
}
return readNodes;