From 069dff0793080734d33bb763227d7d8333637f1a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 23 Jul 2015 16:40:35 -0700 Subject: [PATCH] fix bugs from movement of type/version to NLPacket --- libraries/networking/src/NLPacket.cpp | 21 ++++++++++++++++----- libraries/networking/src/NodeList.cpp | 3 +-- libraries/networking/src/udt/BasePacket.cpp | 2 ++ libraries/networking/src/udt/Packet.cpp | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/libraries/networking/src/NLPacket.cpp b/libraries/networking/src/NLPacket.cpp index 47f36792ad..7a2b4af163 100644 --- a/libraries/networking/src/NLPacket.cpp +++ b/libraries/networking/src/NLPacket.cpp @@ -16,9 +16,9 @@ qint64 NLPacket::maxPayloadSize(PacketType type) { } qint64 NLPacket::localHeaderSize(PacketType type) { - qint64 size = ((NON_SOURCED_PACKETS.contains(type)) ? 0 : NUM_BYTES_RFC4122_UUID) + + qint64 optionalSize = ((NON_SOURCED_PACKETS.contains(type)) ? 0 : NUM_BYTES_RFC4122_UUID) + ((NON_SOURCED_PACKETS.contains(type) || NON_VERIFIED_PACKETS.contains(type)) ? 0 : NUM_BYTES_MD5_HASH); - return size; + return sizeof(PacketType) + sizeof(PacketVersion) + optionalSize; } qint64 NLPacket::maxPayloadSize() const { @@ -85,6 +85,8 @@ NLPacket::NLPacket(PacketType type, bool isReliable, bool isPartOfMessage) : _version(versionForPacketType(type)) { adjustPayloadStartAndCapacity(); + + writeTypeAndVersion(); } NLPacket::NLPacket(PacketType type, qint64 size, bool isReliable, bool isPartOfMessage) : @@ -104,10 +106,14 @@ NLPacket::NLPacket(std::unique_ptr packet) : { adjustPayloadStartAndCapacity(_payloadSize > 0); + readType(); + readVersion(); readSourceID(); } NLPacket::NLPacket(const NLPacket& other) : Packet(other) { + _type = other._type; + _version = other._version; _sourceID = other._sourceID; } @@ -125,14 +131,18 @@ NLPacket::NLPacket(std::unique_ptr data, qint64 size, const HifiSockAddr& } NLPacket::NLPacket(NLPacket&& other) : - Packet(other) + Packet(std::move(other)) { + _type = other._type; + _version = other._version; _sourceID = std::move(other._sourceID); } NLPacket& NLPacket::operator=(const NLPacket& other) { Packet::operator=(other); + _type = other._type; + _version = other._version; _sourceID = other._sourceID; return *this; @@ -142,6 +152,8 @@ NLPacket& NLPacket::operator=(NLPacket&& other) { Packet::operator=(std::move(other)); + _type = other._type; + _version = other._version; _sourceID = std::move(other._sourceID); return *this; @@ -188,8 +200,7 @@ void NLPacket::writeTypeAndVersion() { memcpy(_packet.get() + headerOffset, &_type, sizeof(PacketType)); // Pack the packet version - auto version = versionForPacketType(_type); - memcpy(_packet.get() + headerOffset + sizeof(PacketType), &version, sizeof(version)); + memcpy(_packet.get() + headerOffset + sizeof(PacketType), &_version, sizeof(_version)); } void NLPacket::setType(PacketType type) { diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 1660312e5d..0864cb9fcd 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -533,8 +533,7 @@ void NodeList::sendAssignment(Assignment& assignment) { QDataStream packetStream(assignmentPacket.get()); packetStream << assignment; - - // TODO: should this be a non sourced packet? + sendPacket(std::move(assignmentPacket), _assignmentServerSocket); } diff --git a/libraries/networking/src/udt/BasePacket.cpp b/libraries/networking/src/udt/BasePacket.cpp index d615f0cc1e..f58cd107cb 100644 --- a/libraries/networking/src/udt/BasePacket.cpp +++ b/libraries/networking/src/udt/BasePacket.cpp @@ -80,6 +80,8 @@ BasePacket& BasePacket::operator=(const BasePacket& other) { _payloadSize = other._payloadSize; + _senderSockAddr = other._senderSockAddr; + if (other.isOpen() && !isOpen()) { open(other.openMode()); } diff --git a/libraries/networking/src/udt/Packet.cpp b/libraries/networking/src/udt/Packet.cpp index 335f7e1d17..47ea6ffef3 100644 --- a/libraries/networking/src/udt/Packet.cpp +++ b/libraries/networking/src/udt/Packet.cpp @@ -97,7 +97,7 @@ Packet& Packet::operator=(const Packet& other) { } Packet::Packet(Packet&& other) : - BasePacket(other) + BasePacket(std::move(other)) { _isReliable = other._isReliable; _isPartOfMessage = other._isPartOfMessage;