fix assignment packing and unpacking from DS to AC

This commit is contained in:
Stephen Birarda 2014-01-30 14:54:52 -08:00
parent 356222ba15
commit 55049eeb6b
3 changed files with 28 additions and 44 deletions

View file

@ -19,10 +19,11 @@
#include "metavoxels/MetavoxelServer.h" #include "metavoxels/MetavoxelServer.h"
ThreadedAssignment* AssignmentFactory::unpackAssignment(const QByteArray& packet) { ThreadedAssignment* AssignmentFactory::unpackAssignment(const QByteArray& packet) {
int headerBytes = numBytesForPacketHeader(packet); QDataStream packetStream(packet);
packetStream.skipRawData(numBytesForPacketHeader(packet));
quint8 packedType; quint8 packedType;
memcpy(&packedType, packet.data() + headerBytes, sizeof(packedType)); packetStream >> packedType;
Assignment::Type unpackedType = (Assignment::Type) packedType; Assignment::Type unpackedType = (Assignment::Type) packedType;

View file

@ -261,9 +261,11 @@ void DomainServer::readAvailableDatagrams() {
SharedAssignmentPointer matchingStaticAssignment; SharedAssignmentPointer matchingStaticAssignment;
// check if this is a non-statically assigned node, a node that is assigned and checking in for the first time
// or a node that has already checked in and is continuing to report for duty
if (!STATICALLY_ASSIGNED_NODES.contains(nodeType) if (!STATICALLY_ASSIGNED_NODES.contains(nodeType)
|| (matchingStaticAssignment = matchingStaticAssignmentForCheckIn(nodeUUID, nodeType)) || (matchingStaticAssignment = matchingStaticAssignmentForCheckIn(nodeUUID, nodeType))
|| checkInWithUUIDMatchesExistingNode(nodePublicAddress, nodeLocalAddress, nodeUUID)) || nodeList->getInstance()->nodeWithUUID(nodeUUID))
{ {
SharedNodePointer checkInNode = nodeList->addOrUpdateNode(nodeUUID, SharedNodePointer checkInNode = nodeList->addOrUpdateNode(nodeUUID,
nodeType, nodeType,
@ -313,29 +315,29 @@ void DomainServer::readAvailableDatagrams() {
} }
} else if (requestType == PacketTypeRequestAssignment) { } else if (requestType == PacketTypeRequestAssignment) {
if (_assignmentQueue.size() > 0) {
// construct the requested assignment from the packet data // construct the requested assignment from the packet data
Assignment requestAssignment(receivedPacket); Assignment requestAssignment(receivedPacket);
qDebug("Received a request for assignment type %i from %s.", qDebug() << "Received a request for assignment type" << requestAssignment.getType()
requestAssignment.getType(), qPrintable(senderSockAddr.getAddress().toString())); << "from" << senderSockAddr;
SharedAssignmentPointer assignmentToDeploy = deployableAssignmentForRequest(requestAssignment); SharedAssignmentPointer assignmentToDeploy = deployableAssignmentForRequest(requestAssignment);
if (assignmentToDeploy) { if (assignmentToDeploy) {
qDebug() << "Deploying assignment -" << *assignmentToDeploy.data() << "- to" << senderSockAddr;
// give this assignment out, either the type matches or the requestor said they will take any // give this assignment out, either the type matches or the requestor said they will take any
assignmentPacket.resize(numAssignmentPacketHeaderBytes); assignmentPacket.resize(numAssignmentPacketHeaderBytes);
QDataStream assignmentStream(&assignmentPacket, QIODevice::Append); QDataStream assignmentStream(&assignmentPacket, QIODevice::Append);
assignmentStream << assignmentToDeploy; assignmentStream << *assignmentToDeploy.data();
nodeList->getNodeSocket().writeDatagram(assignmentPacket, nodeList->getNodeSocket().writeDatagram(assignmentPacket,
senderSockAddr.getAddress(), senderSockAddr.getPort()); senderSockAddr.getAddress(), senderSockAddr.getPort());
}
} else { } else {
qDebug() << "Received an invalid assignment request from" << senderSockAddr.getAddress(); qDebug() << "Unable to fulfill assignment request of type" << requestAssignment.getType()
<< "from" << senderSockAddr;
} }
} }
} }
@ -551,8 +553,10 @@ SharedAssignmentPointer DomainServer::matchingStaticAssignmentForCheckIn(const Q
QQueue<SharedAssignmentPointer>::iterator i = _assignmentQueue.begin(); QQueue<SharedAssignmentPointer>::iterator i = _assignmentQueue.begin();
while (i != _assignmentQueue.end()) { while (i != _assignmentQueue.end()) {
if (i->data()->getType() == nodeType && i->data()->getUUID() == checkInUUID) { if (i->data()->getType() == Assignment::typeForNodeType(nodeType) && i->data()->getUUID() == checkInUUID) {
return _assignmentQueue.takeAt(i - _assignmentQueue.begin()); return _assignmentQueue.takeAt(i - _assignmentQueue.begin());
} else {
++i;
} }
} }
} else { } else {
@ -624,24 +628,6 @@ void DomainServer::removeMatchingAssignmentFromQueue(const SharedAssignmentPoint
} }
} }
bool DomainServer::checkInWithUUIDMatchesExistingNode(const HifiSockAddr& nodePublicSocket,
const HifiSockAddr& nodeLocalSocket,
const QUuid& checkInUUID) {
NodeList* nodeList = NodeList::getInstance();
foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
if (node->getLinkedData()
&& nodePublicSocket == node->getPublicSocket()
&& nodeLocalSocket == node->getLocalSocket()
&& node->getUUID() == checkInUUID) {
// this is a matching existing node if the public socket, local socket, and UUID match
return true;
}
}
return false;
}
void DomainServer::addStaticAssignmentsBackToQueueAfterRestart() { void DomainServer::addStaticAssignmentsBackToQueueAfterRestart() {
_hasCompletedRestartHold = true; _hasCompletedRestartHold = true;

View file

@ -44,9 +44,6 @@ private:
SharedAssignmentPointer matchingStaticAssignmentForCheckIn(const QUuid& checkInUUID, NodeType_t nodeType); SharedAssignmentPointer matchingStaticAssignmentForCheckIn(const QUuid& checkInUUID, NodeType_t nodeType);
SharedAssignmentPointer deployableAssignmentForRequest(const Assignment& requestAssignment); SharedAssignmentPointer deployableAssignmentForRequest(const Assignment& requestAssignment);
void removeMatchingAssignmentFromQueue(const SharedAssignmentPointer& removableAssignment); void removeMatchingAssignmentFromQueue(const SharedAssignmentPointer& removableAssignment);
bool checkInWithUUIDMatchesExistingNode(const HifiSockAddr& nodePublicSocket,
const HifiSockAddr& nodeLocalSocket,
const QUuid& checkInUUI);
void refreshStaticAssignmentAndAddToQueue(SharedAssignmentPointer& assignment); void refreshStaticAssignmentAndAddToQueue(SharedAssignmentPointer& assignment);
HTTPManager _HTTPManager; HTTPManager _HTTPManager;