re-instate connect behavior in DS so killed nodes re-connect, amend #2675

This commit is contained in:
Stephen Birarda 2014-04-16 10:56:27 -07:00
parent fbafbf4a9b
commit 97e45e8fe5
8 changed files with 25 additions and 39 deletions

View file

@ -311,8 +311,7 @@ const NodeSet STATICALLY_ASSIGNED_NODES = NodeSet() << NodeType::AudioMixer
<< NodeType::MetavoxelServer; << NodeType::MetavoxelServer;
void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr, void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr) {
const QJsonObject& authJsonObject) {
NodeType_t nodeType; NodeType_t nodeType;
HifiSockAddr publicSockAddr, localSockAddr; HifiSockAddr publicSockAddr, localSockAddr;
@ -336,7 +335,8 @@ void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packe
// create a new session UUID for this node // create a new session UUID for this node
QUuid nodeUUID = QUuid::createUuid(); QUuid nodeUUID = QUuid::createUuid();
SharedNodePointer newNode = LimitedNodeList::getInstance()->addOrUpdateNode(nodeUUID, nodeType, publicSockAddr, localSockAddr); SharedNodePointer newNode = LimitedNodeList::getInstance()->addOrUpdateNode(nodeUUID, nodeType,
publicSockAddr, localSockAddr);
// when the newNode is created the linked data is also created // when the newNode is created the linked data is also created
// if this was a static assignment set the UUID, set the sendingSockAddr // if this was a static assignment set the UUID, set the sendingSockAddr
@ -345,12 +345,6 @@ void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packe
nodeData->setStaticAssignmentUUID(assignmentUUID); nodeData->setStaticAssignmentUUID(assignmentUUID);
nodeData->setSendingSockAddr(senderSockAddr); nodeData->setSendingSockAddr(senderSockAddr);
if (!authJsonObject.isEmpty()) {
// pull the connection secret from the authJsonObject and set it as the connection secret for this node
QUuid connectionSecret(authJsonObject["data"].toObject()["connection_secret"].toString());
newNode->setConnectionSecret(connectionSecret);
}
// reply back to the user with a PacketTypeDomainList // reply back to the user with a PacketTypeDomainList
sendDomainListToNode(newNode, senderSockAddr, nodeInterestListFromPacket(packet, numPreInterestBytes)); sendDomainListToNode(newNode, senderSockAddr, nodeInterestListFromPacket(packet, numPreInterestBytes));
} }
@ -361,18 +355,6 @@ int DomainServer::parseNodeDataFromByteArray(NodeType_t& nodeType, HifiSockAddr&
QDataStream packetStream(packet); QDataStream packetStream(packet);
packetStream.skipRawData(numBytesForPacketHeader(packet)); packetStream.skipRawData(numBytesForPacketHeader(packet));
if (packetTypeForPacket(packet) == PacketTypeDomainConnectRequest) {
// we need to skip a quint8 that indicates if there is a registration token
// and potentially the registration token itself
quint8 hasRegistrationToken;
packetStream >> hasRegistrationToken;
if (hasRegistrationToken) {
QByteArray registrationToken;
packetStream >> registrationToken;
}
}
packetStream >> nodeType; packetStream >> nodeType;
packetStream >> publicSockAddr >> localSockAddr; packetStream >> publicSockAddr >> localSockAddr;
@ -648,7 +630,11 @@ void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiS
if (nodeList->packetVersionAndHashMatch(receivedPacket)) { if (nodeList->packetVersionAndHashMatch(receivedPacket)) {
PacketType requestType = packetTypeForPacket(receivedPacket); PacketType requestType = packetTypeForPacket(receivedPacket);
if (requestType == PacketTypeDomainListRequest) { if (requestType == PacketTypeDomainConnectRequest) {
// add this node to our NodeList
// and send back session UUID right away
addNodeToNodeListAndConfirmConnection(receivedPacket, senderSockAddr);
} else if (requestType == PacketTypeDomainListRequest) {
QUuid nodeUUID = uuidFromPacketHeader(receivedPacket); QUuid nodeUUID = uuidFromPacketHeader(receivedPacket);
if (!nodeUUID.isNull() && nodeList->nodeWithUUID(nodeUUID)) { if (!nodeUUID.isNull() && nodeList->nodeWithUUID(nodeUUID)) {
@ -665,12 +651,7 @@ void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiS
checkInNode->setLastHeardMicrostamp(timeNow); checkInNode->setLastHeardMicrostamp(timeNow);
sendDomainListToNode(checkInNode, senderSockAddr, nodeInterestListFromPacket(receivedPacket, numNodeInfoBytes)); sendDomainListToNode(checkInNode, senderSockAddr, nodeInterestListFromPacket(receivedPacket, numNodeInfoBytes));
} else {
// new node - add this node to our NodeList
// and send back session UUID right away
addNodeToNodeListAndConfirmConnection(receivedPacket, senderSockAddr);
} }
} else if (requestType == PacketTypeNodeJsonStats) { } else if (requestType == PacketTypeNodeJsonStats) {
SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket); SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket);
if (matchingNode) { if (matchingNode) {

View file

@ -24,7 +24,7 @@
#include <Assignment.h> #include <Assignment.h>
#include <HTTPManager.h> #include <HTTPManager.h>
#include <NodeList.h> #include <LimitedNodeList.h>
#include "DTLSServerSession.h" #include "DTLSServerSession.h"
@ -57,8 +57,7 @@ private:
void processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr); void processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr);
void addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr, void addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr);
const QJsonObject& authJsonObject = QJsonObject());
int parseNodeDataFromByteArray(NodeType_t& nodeType, HifiSockAddr& publicSockAddr, int parseNodeDataFromByteArray(NodeType_t& nodeType, HifiSockAddr& publicSockAddr,
HifiSockAddr& localSockAddr, const QByteArray& packet, const HifiSockAddr& senderSockAddr); HifiSockAddr& localSockAddr, const QByteArray& packet, const HifiSockAddr& senderSockAddr);
NodeSet nodeInterestListFromPacket(const QByteArray& packet, int numPreceedingBytes); NodeSet nodeInterestListFromPacket(const QByteArray& packet, int numPreceedingBytes);

View file

@ -331,7 +331,7 @@ void LimitedNodeList::processKillNode(const QByteArray& dataByteArray) {
killNodeWithUUID(nodeUUID); killNodeWithUUID(nodeUUID);
} }
SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, char nodeType, SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType,
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) { const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) {
_nodeHashMutex.lock(); _nodeHashMutex.lock();

View file

@ -78,7 +78,7 @@ public:
SharedNodePointer nodeWithUUID(const QUuid& nodeUUID, bool blockingLock = true); SharedNodePointer nodeWithUUID(const QUuid& nodeUUID, bool blockingLock = true);
SharedNodePointer sendingNodeForPacket(const QByteArray& packet); SharedNodePointer sendingNodeForPacket(const QByteArray& packet);
SharedNodePointer addOrUpdateNode(const QUuid& uuid, char nodeType, SharedNodePointer addOrUpdateNode(const QUuid& uuid, NodeType_t nodeType,
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket); const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);
SharedNodePointer updateSocketsForNode(const QUuid& uuid, SharedNodePointer updateSocketsForNode(const QUuid& uuid,
const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket); const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);

View file

@ -42,7 +42,7 @@ const QString& NodeType::getNodeTypeName(NodeType_t nodeType) {
return matchedTypeName != TypeNameHash.end() ? matchedTypeName.value() : UNKNOWN_NodeType_t_NAME; return matchedTypeName != TypeNameHash.end() ? matchedTypeName.value() : UNKNOWN_NodeType_t_NAME;
} }
Node::Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) : Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) :
_type(type), _type(type),
_uuid(uuid), _uuid(uuid),
_wakeTimestamp(QDateTime::currentMSecsSinceEpoch()), _wakeTimestamp(QDateTime::currentMSecsSinceEpoch()),
@ -58,6 +58,7 @@ Node::Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const
_clockSkewUsec(0), _clockSkewUsec(0),
_mutex() _mutex()
{ {
} }
Node::~Node() { Node::~Node() {

View file

@ -45,7 +45,7 @@ namespace NodeType {
class Node : public QObject { class Node : public QObject {
Q_OBJECT Q_OBJECT
public: public:
Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket); Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket);
~Node(); ~Node();
bool operator==(const Node& otherNode) const { return _uuid == otherNode._uuid; } bool operator==(const Node& otherNode) const { return _uuid == otherNode._uuid; }

View file

@ -376,10 +376,14 @@ void NodeList::sendDomainServerCheckIn() {
} }
} }
// construct the DS check in packet PacketType domainPacketType = _sessionUUID.isNull()
QUuid packetUUID = (!_sessionUUID.isNull() ? _sessionUUID : _domainHandler.getAssignmentUUID()); ? PacketTypeDomainConnectRequest : PacketTypeDomainListRequest;
QByteArray domainServerPacket = byteArrayWithPopulatedHeader(PacketTypeDomainListRequest, packetUUID); // construct the DS check in packet
QUuid packetUUID = (domainPacketType == PacketTypeDomainListRequest
? _sessionUUID : _domainHandler.getAssignmentUUID());
QByteArray domainServerPacket = byteArrayWithPopulatedHeader(domainPacketType, packetUUID);
QDataStream packetStream(&domainServerPacket, QIODevice::Append); QDataStream packetStream(&domainServerPacket, QIODevice::Append);
// pack our data to send to the domain-server // pack our data to send to the domain-server

View file

@ -58,7 +58,7 @@ enum PacketType {
PacketTypeMetavoxelData, PacketTypeMetavoxelData,
PacketTypeAvatarIdentity, PacketTypeAvatarIdentity,
PacketTypeAvatarBillboard, PacketTypeAvatarBillboard,
PacketTypeDomainConnectRequest, // reusable PacketTypeDomainConnectRequest,
PacketTypeDomainServerRequireDTLS, PacketTypeDomainServerRequireDTLS,
PacketTypeNodeJsonStats, PacketTypeNodeJsonStats,
}; };
@ -66,7 +66,8 @@ enum PacketType {
typedef char PacketVersion; typedef char PacketVersion;
const QSet<PacketType> NON_VERIFIED_PACKETS = QSet<PacketType>() const QSet<PacketType> NON_VERIFIED_PACKETS = QSet<PacketType>()
<< PacketTypeDomainServerRequireDTLS << PacketTypeDomainList << PacketTypeDomainListRequest << PacketTypeDomainServerRequireDTLS << PacketTypeDomainConnectRequest
<< PacketTypeDomainList << PacketTypeDomainListRequest
<< PacketTypeCreateAssignment << PacketTypeRequestAssignment << PacketTypeStunResponse << PacketTypeCreateAssignment << PacketTypeRequestAssignment << PacketTypeStunResponse
<< PacketTypeNodeJsonStats; << PacketTypeNodeJsonStats;