mirror of
https://github.com/overte-org/overte.git
synced 2025-07-30 03:40:30 +02:00
have the domain-server generate connection secrets, closes #1837
This commit is contained in:
parent
6f638fa62c
commit
3dca04aacb
6 changed files with 72 additions and 12 deletions
|
@ -21,6 +21,8 @@
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
#include <UUID.h>
|
#include <UUID.h>
|
||||||
|
|
||||||
|
#include "DomainServerNodeData.h"
|
||||||
|
|
||||||
#include "DomainServer.h"
|
#include "DomainServer.h"
|
||||||
|
|
||||||
const int RESTART_HOLD_TIME_MSECS = 5 * 1000;
|
const int RESTART_HOLD_TIME_MSECS = 5 * 1000;
|
||||||
|
@ -58,7 +60,8 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
|
|
||||||
NodeList* nodeList = NodeList::createInstance(NodeType::DomainServer, domainServerPort);
|
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);
|
QTimer* silentNodeTimer = new QTimer(this);
|
||||||
connect(silentNodeTimer, SIGNAL(timeout()), nodeList, SLOT(removeSilentNodes()));
|
connect(silentNodeTimer, SIGNAL(timeout()), nodeList, SLOT(removeSilentNodes()));
|
||||||
|
@ -270,9 +273,7 @@ void DomainServer::readAvailableDatagrams() {
|
||||||
if (nodeUUID.isNull()) {
|
if (nodeUUID.isNull()) {
|
||||||
// this is a check in from an unidentified node
|
// this is a check in from an unidentified node
|
||||||
// we need to generate a session UUID for this node
|
// we need to generate a session UUID for this node
|
||||||
qDebug() << "received a check-in from an unidentified node";
|
|
||||||
nodeUUID = QUuid::createUuid();
|
nodeUUID = QUuid::createUuid();
|
||||||
qDebug() << "UUID set to" << nodeUUID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedNodePointer checkInNode = nodeList->addOrUpdateNode(nodeUUID,
|
SharedNodePointer checkInNode = nodeList->addOrUpdateNode(nodeUUID,
|
||||||
|
@ -303,14 +304,33 @@ void DomainServer::readAvailableDatagrams() {
|
||||||
QDataStream broadcastDataStream(&broadcastPacket, QIODevice::Append);
|
QDataStream broadcastDataStream(&broadcastPacket, QIODevice::Append);
|
||||||
broadcastDataStream << checkInNode->getUUID();
|
broadcastDataStream << checkInNode->getUUID();
|
||||||
|
|
||||||
|
DomainServerNodeData* nodeData = reinterpret_cast<DomainServerNodeData*>(checkInNode->getLinkedData());
|
||||||
|
|
||||||
if (numInterestTypes > 0) {
|
if (numInterestTypes > 0) {
|
||||||
// if the node has any interest types, send back those nodes as well
|
// if the node has any interest types, send back those nodes as well
|
||||||
foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
|
foreach (const SharedNodePointer& otherNode, nodeList->getNodeHash()) {
|
||||||
if (node->getUUID() != nodeUUID &&
|
if (otherNode->getUUID() != nodeUUID &&
|
||||||
memchr(nodeTypesOfInterest, node->getType(), numInterestTypes)) {
|
memchr(nodeTypesOfInterest, otherNode->getType(), numInterestTypes)) {
|
||||||
|
|
||||||
// don't send avatar nodes to other avatars, that will come from avatar mixer
|
// 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);
|
_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) {
|
void DomainServer::nodeKilled(SharedNodePointer node) {
|
||||||
// if this node's UUID matches a static assignment we need to throw it back in the assignment queue
|
// 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());
|
SharedAssignmentPointer matchedAssignment = _staticAssignmentHash.value(node->getUUID());
|
||||||
|
|
|
@ -30,7 +30,9 @@ public:
|
||||||
void exit(int retCode = 0);
|
void exit(int retCode = 0);
|
||||||
|
|
||||||
public slots:
|
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);
|
void nodeKilled(SharedNodePointer node);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
26
domain-server/src/DomainServerNodeData.h
Normal file
26
domain-server/src/DomainServerNodeData.h
Normal 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__) */
|
|
@ -52,6 +52,7 @@ Node::Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const
|
||||||
_publicSocket(publicSocket),
|
_publicSocket(publicSocket),
|
||||||
_localSocket(localSocket),
|
_localSocket(localSocket),
|
||||||
_activeSocket(NULL),
|
_activeSocket(NULL),
|
||||||
|
_connectionSecret(),
|
||||||
_bytesReceivedMovingAverage(NULL),
|
_bytesReceivedMovingAverage(NULL),
|
||||||
_linkedData(NULL),
|
_linkedData(NULL),
|
||||||
_isAlive(true),
|
_isAlive(true),
|
||||||
|
|
|
@ -57,7 +57,6 @@ public:
|
||||||
char getType() const { return _type; }
|
char getType() const { return _type; }
|
||||||
void setType(char type) { _type = type; }
|
void setType(char type) { _type = type; }
|
||||||
|
|
||||||
|
|
||||||
const QUuid& getUUID() const { return _uuid; }
|
const QUuid& getUUID() const { return _uuid; }
|
||||||
void setUUID(const QUuid& uuid) { _uuid = uuid; }
|
void setUUID(const QUuid& uuid) { _uuid = uuid; }
|
||||||
|
|
||||||
|
@ -77,6 +76,9 @@ public:
|
||||||
void activatePublicSocket();
|
void activatePublicSocket();
|
||||||
void activateLocalSocket();
|
void activateLocalSocket();
|
||||||
|
|
||||||
|
const QUuid& getConnectionSecret() const { return _connectionSecret; }
|
||||||
|
void setConnectionSecret(const QUuid& connectionSecret) { _connectionSecret = connectionSecret; }
|
||||||
|
|
||||||
NodeData* getLinkedData() const { return _linkedData; }
|
NodeData* getLinkedData() const { return _linkedData; }
|
||||||
void setLinkedData(NodeData* linkedData) { _linkedData = linkedData; }
|
void setLinkedData(NodeData* linkedData) { _linkedData = linkedData; }
|
||||||
|
|
||||||
|
@ -109,6 +111,7 @@ private:
|
||||||
HifiSockAddr _publicSocket;
|
HifiSockAddr _publicSocket;
|
||||||
HifiSockAddr _localSocket;
|
HifiSockAddr _localSocket;
|
||||||
HifiSockAddr* _activeSocket;
|
HifiSockAddr* _activeSocket;
|
||||||
|
QUuid _connectionSecret;
|
||||||
SimpleMovingAverage* _bytesReceivedMovingAverage;
|
SimpleMovingAverage* _bytesReceivedMovingAverage;
|
||||||
NodeData* _linkedData;
|
NodeData* _linkedData;
|
||||||
bool _isAlive;
|
bool _isAlive;
|
||||||
|
|
|
@ -511,7 +511,7 @@ int NodeList::processDomainServerList(const QByteArray& packet) {
|
||||||
// setup variables to read into from QDataStream
|
// setup variables to read into from QDataStream
|
||||||
qint8 nodeType;
|
qint8 nodeType;
|
||||||
|
|
||||||
QUuid nodeUUID;
|
QUuid nodeUUID, connectionUUID;
|
||||||
|
|
||||||
HifiSockAddr nodePublicSocket;
|
HifiSockAddr nodePublicSocket;
|
||||||
HifiSockAddr nodeLocalSocket;
|
HifiSockAddr nodeLocalSocket;
|
||||||
|
@ -534,7 +534,10 @@ int NodeList::processDomainServerList(const QByteArray& packet) {
|
||||||
nodePublicSocket.setAddress(_domainSockAddr.getAddress());
|
nodePublicSocket.setAddress(_domainSockAddr.getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
addOrUpdateNode(nodeUUID, nodeType, nodePublicSocket, nodeLocalSocket);
|
SharedNodePointer node = addOrUpdateNode(nodeUUID, nodeType, nodePublicSocket, nodeLocalSocket);
|
||||||
|
|
||||||
|
packetStream >> connectionUUID;
|
||||||
|
node->setConnectionSecret(connectionUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
return readNodes;
|
return readNodes;
|
||||||
|
|
Loading…
Reference in a new issue