fix child assignment UUID, adjust for NLPacket after unpack

This commit is contained in:
Stephen Birarda 2015-07-15 12:37:30 -07:00
parent c4a97de985
commit e90ace6231
6 changed files with 19 additions and 14 deletions

View file

@ -73,11 +73,6 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri
// put the NodeList on the node thread // put the NodeList on the node thread
nodeList->moveToThread(nodeThread); nodeList->moveToThread(nodeThread);
// make up a uuid for this child so the parent can tell us apart. This id will be changed
// when the domain server hands over an assignment.
QUuid nodeUUID = QUuid::createUuid();
nodeList->setSessionUUID(nodeUUID);
// set the logging target to the the CHILD_TARGET_NAME // set the logging target to the the CHILD_TARGET_NAME
LogHandler::getInstance().setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME); LogHandler::getInstance().setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
@ -197,7 +192,7 @@ void AssignmentClient::sendStatusPacketToACM() {
auto statusPacket = NLPacket::create(PacketType::AssignmentClientStatus, sizeof(assignmentType) + NUM_BYTES_RFC4122_UUID); auto statusPacket = NLPacket::create(PacketType::AssignmentClientStatus, sizeof(assignmentType) + NUM_BYTES_RFC4122_UUID);
statusPacket->write(nodeList->getSessionUUID().toRfc4122()); statusPacket->write(_childAssignmentUUID.toRfc4122());
statusPacket->writePrimitive(assignmentType); statusPacket->writePrimitive(assignmentType);
nodeList->sendPacket(std::move(statusPacket), _assignmentClientMonitorSocket); nodeList->sendPacket(std::move(statusPacket), _assignmentClientMonitorSocket);

View file

@ -51,6 +51,7 @@ private:
HifiSockAddr _assignmentServerSocket; HifiSockAddr _assignmentServerSocket;
QTimer _requestTimer; // timer for requesting and assignment QTimer _requestTimer; // timer for requesting and assignment
QTimer _statsTimerACM; // timer for sending stats to assignment client monitor QTimer _statsTimerACM; // timer for sending stats to assignment client monitor
QUuid _childAssignmentUUID = QUuid::createUuid();
protected: protected:
HifiSockAddr _assignmentClientMonitorSocket; HifiSockAddr _assignmentClientMonitorSocket;

View file

@ -940,7 +940,7 @@ int DomainServer::parseNodeData(QDataStream& packetStream, NodeType_t& nodeType,
const HifiSockAddr& senderSockAddr) { const HifiSockAddr& senderSockAddr) {
packetStream >> nodeType; packetStream >> nodeType;
packetStream >> publicSockAddr >> localSockAddr; packetStream >> publicSockAddr >> localSockAddr;
if (publicSockAddr.getAddress().isNull()) { if (publicSockAddr.getAddress().isNull()) {
// this node wants to use us its STUN server // this node wants to use us its STUN server
// so set the node public address to whatever we perceive the public address to be // so set the node public address to whatever we perceive the public address to be

View file

@ -78,29 +78,35 @@ NLPacket::NLPacket(PacketType::Value type, qint64 size) :
{ {
Q_ASSERT(size >= 0); Q_ASSERT(size >= 0);
qint64 headerSize = localHeaderSize(type); adjustPayloadStartAndCapacity();
_payloadStart += headerSize;
_payloadCapacity -= headerSize;
} }
NLPacket::NLPacket(PacketType::Value type) : NLPacket::NLPacket(PacketType::Value type) :
Packet(type, -1) Packet(type, -1)
{ {
qint64 headerSize = localHeaderSize(type); adjustPayloadStartAndCapacity();
_payloadStart += headerSize;
_payloadCapacity -= headerSize;
} }
NLPacket::NLPacket(const NLPacket& other) : Packet(other) { NLPacket::NLPacket(const NLPacket& other) : Packet(other) {
} }
NLPacket::NLPacket(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& senderSockAddr) : NLPacket::NLPacket(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& senderSockAddr) :
Packet(std::move(data), size, senderSockAddr) Packet(std::move(data), size, senderSockAddr)
{ {
adjustPayloadStartAndCapacity();
_payloadSize = _payloadCapacity;
readSourceID(); readSourceID();
readVerificationHash(); readVerificationHash();
} }
void NLPacket::adjustPayloadStartAndCapacity() {
qint64 headerSize = localHeaderSize(_type);
_payloadStart += headerSize;
_payloadCapacity -= headerSize;
}
void NLPacket::readSourceID() { void NLPacket::readSourceID() {
if (!NON_SOURCED_PACKETS.contains(_type)) { if (!NON_SOURCED_PACKETS.contains(_type)) {
auto offset = Packet::totalHeadersSize(); auto offset = Packet::totalHeadersSize();

View file

@ -40,6 +40,9 @@ public:
QByteArray payloadHashWithConnectionUUID(const QUuid& connectionUUID) const; QByteArray payloadHashWithConnectionUUID(const QUuid& connectionUUID) const;
protected: protected:
void adjustPayloadStartAndCapacity();
NLPacket(PacketType::Value type); NLPacket(PacketType::Value type);
NLPacket(PacketType::Value type, qint64 size); NLPacket(PacketType::Value type, qint64 size);
NLPacket(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& senderSockAddr); NLPacket(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& senderSockAddr);

View file

@ -50,7 +50,7 @@ public:
PacketVersion getVersion() const { return _version; } PacketVersion getVersion() const { return _version; }
// Returns the size of the packet, including the header // Returns the size of the packet, including the header
qint64 getDataSize() const { return totalHeadersSize() + getPayloadSize(); } qint64 getDataSize() const { return totalHeadersSize() + _payloadSize; }
// Returns the size of the payload only // Returns the size of the payload only
qint64 getPayloadSize() const { return _payloadSize; } qint64 getPayloadSize() const { return _payloadSize; }