fix domain check in packets for new API

This commit is contained in:
Stephen Birarda 2015-07-06 17:03:26 -07:00
parent 9a521fee47
commit 3fa785c545
3 changed files with 25 additions and 21 deletions

View file

@ -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();
}

View file

@ -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) {

View file

@ -31,7 +31,8 @@ const QSet<PacketType::Value> NON_VERIFIED_PACKETS = QSet<PacketType::Value>()
const QSet<PacketType::Value> SEQUENCE_NUMBERED_PACKETS = QSet<PacketType::Value>() << AvatarData;
const QSet<PacketType::Value> NON_SOURCED_PACKETS = QSet<PacketType::Value>() << ICEPing << ICEPingReply;
const QSet<PacketType::Value> NON_SOURCED_PACKETS = QSet<PacketType::Value>()
<< ICEPing << ICEPingReply << DomainConnectRequest;
int arithmeticCodingValueFromBuffer(const char* checkValue) {
if (((uchar) *checkValue) < 255) {