From 97e45e8fe5b675b4425b0b1d0f4ad97e71b7fa7d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 16 Apr 2014 10:56:27 -0700 Subject: [PATCH 1/7] re-instate connect behavior in DS so killed nodes re-connect, amend #2675 --- domain-server/src/DomainServer.cpp | 35 +++++--------------- domain-server/src/DomainServer.h | 5 ++- libraries/networking/src/LimitedNodeList.cpp | 2 +- libraries/networking/src/LimitedNodeList.h | 2 +- libraries/networking/src/Node.cpp | 3 +- libraries/networking/src/Node.h | 2 +- libraries/networking/src/NodeList.cpp | 10 ++++-- libraries/networking/src/PacketHeaders.h | 5 +-- 8 files changed, 25 insertions(+), 39 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 1bda2aa75c..6634dde5b7 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -311,8 +311,7 @@ const NodeSet STATICALLY_ASSIGNED_NODES = NodeSet() << NodeType::AudioMixer << NodeType::MetavoxelServer; -void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr, - const QJsonObject& authJsonObject) { +void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr) { NodeType_t nodeType; HifiSockAddr publicSockAddr, localSockAddr; @@ -336,7 +335,8 @@ void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packe // create a new session UUID for this node 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 // 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->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 sendDomainListToNode(newNode, senderSockAddr, nodeInterestListFromPacket(packet, numPreInterestBytes)); } @@ -361,18 +355,6 @@ int DomainServer::parseNodeDataFromByteArray(NodeType_t& nodeType, HifiSockAddr& QDataStream packetStream(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 >> publicSockAddr >> localSockAddr; @@ -648,7 +630,11 @@ void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiS if (nodeList->packetVersionAndHashMatch(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); if (!nodeUUID.isNull() && nodeList->nodeWithUUID(nodeUUID)) { @@ -665,12 +651,7 @@ void DomainServer::processDatagram(const QByteArray& receivedPacket, const HifiS checkInNode->setLastHeardMicrostamp(timeNow); 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) { SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket); if (matchingNode) { diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 1400fadee3..0153fac49d 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include "DTLSServerSession.h" @@ -57,8 +57,7 @@ private: void processDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr); - void addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr, - const QJsonObject& authJsonObject = QJsonObject()); + void addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr); int parseNodeDataFromByteArray(NodeType_t& nodeType, HifiSockAddr& publicSockAddr, HifiSockAddr& localSockAddr, const QByteArray& packet, const HifiSockAddr& senderSockAddr); NodeSet nodeInterestListFromPacket(const QByteArray& packet, int numPreceedingBytes); diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index b0b048dde4..60fbe9b3a6 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -331,7 +331,7 @@ void LimitedNodeList::processKillNode(const QByteArray& dataByteArray) { 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) { _nodeHashMutex.lock(); diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index f941a8aa5d..ea9cb42436 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -78,7 +78,7 @@ public: SharedNodePointer nodeWithUUID(const QUuid& nodeUUID, bool blockingLock = true); 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); SharedNodePointer updateSocketsForNode(const QUuid& uuid, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket); diff --git a/libraries/networking/src/Node.cpp b/libraries/networking/src/Node.cpp index 9e6ea0dfec..15ee443e1f 100644 --- a/libraries/networking/src/Node.cpp +++ b/libraries/networking/src/Node.cpp @@ -42,7 +42,7 @@ const QString& NodeType::getNodeTypeName(NodeType_t nodeType) { 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), _uuid(uuid), _wakeTimestamp(QDateTime::currentMSecsSinceEpoch()), @@ -58,6 +58,7 @@ Node::Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const _clockSkewUsec(0), _mutex() { + } Node::~Node() { diff --git a/libraries/networking/src/Node.h b/libraries/networking/src/Node.h index 3b3237cf6e..0f63d01525 100644 --- a/libraries/networking/src/Node.h +++ b/libraries/networking/src/Node.h @@ -45,7 +45,7 @@ namespace NodeType { class Node : public QObject { Q_OBJECT 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(); bool operator==(const Node& otherNode) const { return _uuid == otherNode._uuid; } diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 93377c7763..006d5e0509 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -376,10 +376,14 @@ void NodeList::sendDomainServerCheckIn() { } } - // construct the DS check in packet - QUuid packetUUID = (!_sessionUUID.isNull() ? _sessionUUID : _domainHandler.getAssignmentUUID()); + PacketType domainPacketType = _sessionUUID.isNull() + ? 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); // pack our data to send to the domain-server diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index 3e2ff3d8b0..0f52f90962 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -58,7 +58,7 @@ enum PacketType { PacketTypeMetavoxelData, PacketTypeAvatarIdentity, PacketTypeAvatarBillboard, - PacketTypeDomainConnectRequest, // reusable + PacketTypeDomainConnectRequest, PacketTypeDomainServerRequireDTLS, PacketTypeNodeJsonStats, }; @@ -66,7 +66,8 @@ enum PacketType { typedef char PacketVersion; const QSet NON_VERIFIED_PACKETS = QSet() - << PacketTypeDomainServerRequireDTLS << PacketTypeDomainList << PacketTypeDomainListRequest + << PacketTypeDomainServerRequireDTLS << PacketTypeDomainConnectRequest + << PacketTypeDomainList << PacketTypeDomainListRequest << PacketTypeCreateAssignment << PacketTypeRequestAssignment << PacketTypeStunResponse << PacketTypeNodeJsonStats; From 57567becc8776048f0765459c26d55a5aaf6a287 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 16 Apr 2014 11:02:08 -0700 Subject: [PATCH 2/7] fix unexpected null parameter to disconnect, closes, #2663 --- libraries/networking/src/NodeList.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 006d5e0509..fbf2655269 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -209,8 +209,10 @@ void NodeList::reset() { // clear the domain connection information _domainHandler.clearConnectionInfo(); - // also disconnect from the DTLS socket readyRead() so it can handle handshaking - disconnect(_dtlsSocket, 0, this, 0); + // if we setup the DTLS socket, also disconnect from the DTLS socket readyRead() so it can handle handshaking + if (_dtlsSocket) { + disconnect(_dtlsSocket, 0, this, 0); + } } void NodeList::addNodeTypeToInterestSet(NodeType_t nodeTypeToAdd) { From 55d540a0eb6947192f51607fcf313ce4f387091b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 16 Apr 2014 11:24:26 -0700 Subject: [PATCH 3/7] fix a typo in DomainServer.cpp --- domain-server/src/DomainServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 6634dde5b7..1268ae739e 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -71,7 +71,7 @@ DomainServer::DomainServer(int argc, char* argv[]) : int socketHandle = LimitedNodeList::getInstance()->getDTLSSocket().socketDescriptor(); #if defined(IP_DONTFRAG) - int optValue = 1;yea + int optValue = 1; setsockopt(socketHandle, IPPROTO_IP, IP_DONTFRAG, (const void*) optValue, sizeof(optValue)); #elif defined(IP_MTU_DISCOVER) int optValue = 1; From a25ef5824707d9de5707ea11153d19cb36e15006 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 16 Apr 2014 11:25:35 -0700 Subject: [PATCH 4/7] move DTLS socket changes to LimitedNodeList --- domain-server/src/DomainServer.cpp | 12 ------------ libraries/networking/src/LimitedNodeList.cpp | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 1268ae739e..969b83f64f 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -66,18 +66,6 @@ DomainServer::DomainServer(int argc, char* argv[]) : LimitedNodeList* nodeList = LimitedNodeList::getInstance(); -#if defined(IP_DONTFRAG) || defined(IP_MTU_DISCOVER) - qDebug() << "Making required DTLS changes to NodeList DTLS socket."; - - int socketHandle = LimitedNodeList::getInstance()->getDTLSSocket().socketDescriptor(); -#if defined(IP_DONTFRAG) - int optValue = 1; - setsockopt(socketHandle, IPPROTO_IP, IP_DONTFRAG, (const void*) optValue, sizeof(optValue)); -#elif defined(IP_MTU_DISCOVER) - int optValue = 1; - setsockopt(socketHandle, IPPROTO_IP, IP_MTU_DISCOVER, (const void*) optValue, sizeof(optValue)); -#endif -#endif // connect our socket to read datagrams received on the DTLS socket connect(&nodeList->getDTLSSocket(), &QUdpSocket::readyRead, this, &DomainServer::readAvailableDTLSDatagrams); } diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 60fbe9b3a6..d85c01a9eb 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -105,6 +105,20 @@ QUdpSocket& LimitedNodeList::getDTLSSocket() { _dtlsSocket = new QUdpSocket(this); _dtlsSocket->bind(QHostAddress::AnyIPv4, 0, QAbstractSocket::DontShareAddress); + +#if defined(IP_DONTFRAG) || defined(IP_MTU_DISCOVER) + qDebug() << "Making required DTLS changes to LimitedNodeList DTLS socket."; + + int socketHandle = _dtlsSocket->socketDescriptor(); +#if defined(IP_DONTFRAG) + int optValue = 1; + setsockopt(socketHandle, IPPROTO_IP, IP_DONTFRAG, (const void*) optValue, sizeof(optValue)); +#elif defined(IP_MTU_DISCOVER) + int optValue = 1; + setsockopt(socketHandle, IPPROTO_IP, IP_MTU_DISCOVER, (const void*) optValue, sizeof(optValue)); +#endif +#endif + qDebug() << "NodeList DTLS socket is listening on" << _dtlsSocket->localPort(); } From 06a976041b507c8aa1c215e69176029aa89e9532 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 16 Apr 2014 11:27:30 -0700 Subject: [PATCH 5/7] take pointer of optValue and not actual optValue --- libraries/networking/src/LimitedNodeList.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index d85c01a9eb..223ab3c306 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -112,10 +112,10 @@ QUdpSocket& LimitedNodeList::getDTLSSocket() { int socketHandle = _dtlsSocket->socketDescriptor(); #if defined(IP_DONTFRAG) int optValue = 1; - setsockopt(socketHandle, IPPROTO_IP, IP_DONTFRAG, (const void*) optValue, sizeof(optValue)); + setsockopt(socketHandle, IPPROTO_IP, IP_DONTFRAG, reinterpret_cast(&optValue), sizeof(optValue)); #elif defined(IP_MTU_DISCOVER) int optValue = 1; - setsockopt(socketHandle, IPPROTO_IP, IP_MTU_DISCOVER, (const void*) optValue, sizeof(optValue)); + setsockopt(socketHandle, IPPROTO_IP, IP_MTU_DISCOVER, reinterpret_cast(&optValue), sizeof(optValue)); #endif #endif From afcb542bbec5e3a0e879b9bcf167c7625b8ae910 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 16 Apr 2014 11:28:34 -0700 Subject: [PATCH 6/7] fix a debug line in LimitedNodeList --- libraries/networking/src/LimitedNodeList.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 223ab3c306..9b19e9d921 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -112,14 +112,14 @@ QUdpSocket& LimitedNodeList::getDTLSSocket() { int socketHandle = _dtlsSocket->socketDescriptor(); #if defined(IP_DONTFRAG) int optValue = 1; - setsockopt(socketHandle, IPPROTO_IP, IP_DONTFRAG, reinterpret_cast(&optValue), sizeof(optValue)); + setsockopt(socketHandle, IPPROTO_IP, IP_DONTFRAG, reinterpret_cast(&optValue, sizeof(optValue)); #elif defined(IP_MTU_DISCOVER) int optValue = 1; setsockopt(socketHandle, IPPROTO_IP, IP_MTU_DISCOVER, reinterpret_cast(&optValue), sizeof(optValue)); #endif #endif - qDebug() << "NodeList DTLS socket is listening on" << _dtlsSocket->localPort(); + qDebug() << "LimitedNodeList DTLS socket is listening on" << _dtlsSocket->localPort(); } return *_dtlsSocket; From 505145f6934a702ebd5a9289d7f8198b2ae312ba Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 16 Apr 2014 12:02:02 -0700 Subject: [PATCH 7/7] add a missing bracket to IP_DONTFRAG --- libraries/networking/src/LimitedNodeList.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 9b19e9d921..db8a689001 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -112,7 +112,7 @@ QUdpSocket& LimitedNodeList::getDTLSSocket() { int socketHandle = _dtlsSocket->socketDescriptor(); #if defined(IP_DONTFRAG) int optValue = 1; - setsockopt(socketHandle, IPPROTO_IP, IP_DONTFRAG, reinterpret_cast(&optValue, sizeof(optValue)); + setsockopt(socketHandle, IPPROTO_IP, IP_DONTFRAG, reinterpret_cast(&optValue), sizeof(optValue)); #elif defined(IP_MTU_DISCOVER) int optValue = 1; setsockopt(socketHandle, IPPROTO_IP, IP_MTU_DISCOVER, reinterpret_cast(&optValue), sizeof(optValue));