From 3fa785c54562acc44bbda21d9dd4015edb8d909f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 6 Jul 2015 17:03:26 -0700 Subject: [PATCH] fix domain check in packets for new API --- domain-server/src/DomainServer.cpp | 21 +++++++++++---------- libraries/networking/src/NodeList.cpp | 22 ++++++++++++---------- libraries/networking/src/PacketHeaders.cpp | 3 ++- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 35be97d610..d83c93c35c 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -573,33 +573,34 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock QDataStream packetStream(packet); packetStream.skipRawData(numBytesForPacketHeader(packet)); + QUuid connectUUID; + packetStream >> connectUUID; + parseNodeDataFromByteArray(packetStream, nodeType, publicSockAddr, localSockAddr, senderSockAddr); - QUuid packetUUID = uuidFromPacketHeader(packet); - // check if this connect request matches an assignment in the queue - bool isAssignment = _pendingAssignedNodes.contains(packetUUID); + bool isAssignment = _pendingAssignedNodes.contains(connectUUID); SharedAssignmentPointer matchingQueuedAssignment = SharedAssignmentPointer(); PendingAssignedNodeData* pendingAssigneeData = NULL; if (isAssignment) { - pendingAssigneeData = _pendingAssignedNodes.value(packetUUID); + pendingAssigneeData = _pendingAssignedNodes.value(connectUUID); if (pendingAssigneeData) { matchingQueuedAssignment = matchingQueuedAssignmentForCheckIn(pendingAssigneeData->getAssignmentUUID(), nodeType); if (matchingQueuedAssignment) { - qDebug() << "Assignment deployed with" << uuidStringWithoutCurlyBraces(packetUUID) + qDebug() << "Assignment deployed with" << uuidStringWithoutCurlyBraces(connectUUID) << "matches unfulfilled assignment" << uuidStringWithoutCurlyBraces(matchingQueuedAssignment->getUUID()); // remove this unique assignment deployment from the hash of pending assigned nodes // cleanup of the PendingAssignedNodeData happens below after the node has been added to the LimitedNodeList - _pendingAssignedNodes.remove(packetUUID); + _pendingAssignedNodes.remove(connectUUID); } else { // this is a node connecting to fulfill an assignment that doesn't exist // don't reply back to them so they cycle back and re-request an assignment - qDebug() << "No match for assignment deployed with" << uuidStringWithoutCurlyBraces(packetUUID); + qDebug() << "No match for assignment deployed with" << uuidStringWithoutCurlyBraces(connectUUID); return; } } @@ -638,18 +639,18 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock QUuid nodeUUID; HifiSockAddr discoveredSocket = senderSockAddr; - SharedNetworkPeer connectedPeer = _icePeers.value(packetUUID); + SharedNetworkPeer connectedPeer = _icePeers.value(connectUUID); if (connectedPeer) { // this user negotiated a connection with us via ICE, so re-use their ICE client ID - nodeUUID = packetUUID; + nodeUUID = connectUUID; if (connectedPeer->getActiveSocket()) { // set their discovered socket to whatever the activated socket on the network peer object was discoveredSocket = *connectedPeer->getActiveSocket(); } } else { - // we got a packetUUID we didn't recognize, just add the node + // we got a connectUUID we didn't recognize, just add the node with a new UUID nodeUUID = QUuid::createUuid(); } diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 11f04e188f..dd40927054 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -310,7 +310,7 @@ void NodeList::sendDomainServerCheckIn() { bool isUsingDTLS = false; PacketType::Value domainPacketType = !_domainHandler.isConnected() - ? PacketTypeDomainConnectRequest : PacketTypeDomainListRequest; + ? PacketType::DomainConnectRequest : PacketType::DomainListRequest; if (!_domainHandler.isConnected()) { qCDebug(networking) << "Sending connect request to domain-server at" << _domainHandler.getHostname(); @@ -329,24 +329,26 @@ void NodeList::sendDomainServerCheckIn() { } - // construct the DS check in packet - QUuid packetUUID = _sessionUUID; + auto domainPacket = NodeListPacket::create(domainPacketType); + QDataStream packetStream(&domainPacket->getPayload); + + if (domainPacketType == PacketType::DomainConnectRequest) { + QUuid connectUUID; - if (domainPacketType == PacketTypeDomainConnectRequest) { if (!_domainHandler.getAssignmentUUID().isNull()) { // this is a connect request and we're an assigned node // so set our packetUUID as the assignment UUID - packetUUID = _domainHandler.getAssignmentUUID(); + connectUUID = _domainHandler.getAssignmentUUID(); } else if (_domainHandler.requiresICE()) { // this is a connect request and we're an interface client // that used ice to discover the DS // so send our ICE client UUID with the connect request - packetUUID = _domainHandler.getICEClientID(); + connectUUID = _domainHandler.getICEClientID(); } - } - QByteArray domainServerPacket = byteArrayWithUUIDPopulatedHeader(domainPacketType, packetUUID); - QDataStream packetStream(&domainServerPacket, QIODevice::Append); + // pack the connect UUID for this connect request + packetStream << connectUUID; + } // pack our data to send to the domain-server packetStream << _ownerType << _publicSockAddr << _localSockAddr << _nodeTypesOfInterest.toList(); @@ -367,7 +369,7 @@ void NodeList::sendDomainServerCheckIn() { flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendDSCheckIn); if (!isUsingDTLS) { - writeUnverifiedDatagram(domainServerPacket, _domainHandler.getSockAddr()); + sendPacket(domainPacket, _domainHandler.getSockAddr()); } if (_numNoReplyDomainCheckIns >= MAX_SILENT_DOMAIN_SERVER_CHECK_INS) { diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index 83b424d44d..02097402c6 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -31,7 +31,8 @@ const QSet NON_VERIFIED_PACKETS = QSet() const QSet SEQUENCE_NUMBERED_PACKETS = QSet() << AvatarData; -const QSet NON_SOURCED_PACKETS = QSet() << ICEPing << ICEPingReply; +const QSet NON_SOURCED_PACKETS = QSet() + << ICEPing << ICEPingReply << DomainConnectRequest; int arithmeticCodingValueFromBuffer(const char* checkValue) { if (((uchar) *checkValue) < 255) {