Merge branch 'protocol' of https://github.com/Atlante45/hifi into atp

This commit is contained in:
Stephen Birarda 2015-07-30 15:23:40 -07:00
commit 4529eea5f8
9 changed files with 103 additions and 104 deletions

View file

@ -128,7 +128,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
} }
if (debugProcessPacket) { if (debugProcessPacket) {
qDebug() << " numBytesPacketHeader=" << packet->totalHeadersSize(); qDebug() << " numBytesPacketHeader=" << NLPacket::totalHeaderSize(packetType);
qDebug() << " sizeof(sequence)=" << sizeof(sequence); qDebug() << " sizeof(sequence)=" << sizeof(sequence);
qDebug() << " sizeof(sentAt)=" << sizeof(sentAt); qDebug() << " sizeof(sentAt)=" << sizeof(sentAt);
} }

View file

@ -11,26 +11,17 @@
#include "NLPacket.h" #include "NLPacket.h"
qint64 NLPacket::maxPayloadSize(PacketType type) { int NLPacket::localHeaderSize(PacketType type) {
return Packet::maxPayloadSize(false) - localHeaderSize(type); bool sourced = NON_SOURCED_PACKETS.contains(type);
} bool verified = NON_VERIFIED_PACKETS.contains(type);
qint64 optionalSize = (sourced ? 0 : NUM_BYTES_RFC4122_UUID) + ((sourced || verified) ? 0 : NUM_BYTES_MD5_HASH);
qint64 NLPacket::localHeaderSize(PacketType type) {
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 sizeof(PacketType) + sizeof(PacketVersion) + optionalSize; return sizeof(PacketType) + sizeof(PacketVersion) + optionalSize;
} }
int NLPacket::totalHeaderSize(PacketType type, bool isPartOfMessage) {
qint64 NLPacket::maxPayloadSize() const { return Packet::totalHeaderSize(isPartOfMessage) + NLPacket::localHeaderSize(type);
return Packet::maxPayloadSize() - localHeaderSize();
} }
int NLPacket::maxPayloadSize(PacketType type, bool isPartOfMessage) {
qint64 NLPacket::totalHeadersSize() const { return Packet::maxPayloadSize(isPartOfMessage) - NLPacket::localHeaderSize(type);
return Packet::totalHeadersSize() + localHeaderSize();
}
qint64 NLPacket::localHeaderSize() const {
return localHeaderSize(_type);
} }
std::unique_ptr<NLPacket> NLPacket::create(PacketType type, qint64 size, bool isReliable, bool isPartOfMessage) { std::unique_ptr<NLPacket> NLPacket::create(PacketType type, qint64 size, bool isReliable, bool isPartOfMessage) {
@ -84,19 +75,19 @@ NLPacket::NLPacket(PacketType type, bool isReliable, bool isPartOfMessage) :
_type(type), _type(type),
_version(versionForPacketType(type)) _version(versionForPacketType(type))
{ {
adjustPayloadStartAndCapacity(localHeaderSize()); adjustPayloadStartAndCapacity(NLPacket::localHeaderSize(_type));
writeTypeAndVersion(); writeTypeAndVersion();
} }
NLPacket::NLPacket(PacketType type, qint64 size, bool isReliable, bool isPartOfMessage) : NLPacket::NLPacket(PacketType type, qint64 size, bool isReliable, bool isPartOfMessage) :
Packet(localHeaderSize(type) + size, isReliable, isPartOfMessage), Packet(NLPacket::localHeaderSize(type) + size, isReliable, isPartOfMessage),
_type(type), _type(type),
_version(versionForPacketType(type)) _version(versionForPacketType(type))
{ {
Q_ASSERT(size >= 0); Q_ASSERT(size >= 0);
adjustPayloadStartAndCapacity(localHeaderSize()); adjustPayloadStartAndCapacity(NLPacket::localHeaderSize(_type));
writeTypeAndVersion(); writeTypeAndVersion();
} }
@ -108,7 +99,7 @@ NLPacket::NLPacket(std::unique_ptr<Packet> packet) :
readVersion(); readVersion();
readSourceID(); readSourceID();
adjustPayloadStartAndCapacity(localHeaderSize(), _payloadSize > 0); adjustPayloadStartAndCapacity(NLPacket::localHeaderSize(_type), _payloadSize > 0);
} }
NLPacket::NLPacket(const NLPacket& other) : Packet(other) { NLPacket::NLPacket(const NLPacket& other) : Packet(other) {
@ -123,11 +114,11 @@ NLPacket::NLPacket(std::unique_ptr<char> data, qint64 size, const HifiSockAddr&
// sanity check before we decrease the payloadSize with the payloadCapacity // sanity check before we decrease the payloadSize with the payloadCapacity
Q_ASSERT(_payloadSize == _payloadCapacity); Q_ASSERT(_payloadSize == _payloadCapacity);
adjustPayloadStartAndCapacity(localHeaderSize(), _payloadSize > 0);
readType(); readType();
readVersion(); readVersion();
readSourceID(); readSourceID();
adjustPayloadStartAndCapacity(NLPacket::localHeaderSize(_type), _payloadSize > 0);
} }
NLPacket::NLPacket(NLPacket&& other) : NLPacket::NLPacket(NLPacket&& other) :
@ -160,29 +151,29 @@ NLPacket& NLPacket::operator=(NLPacket&& other) {
} }
PacketType NLPacket::typeInHeader(const udt::Packet& packet) { PacketType NLPacket::typeInHeader(const udt::Packet& packet) {
auto headerOffset = packet.Packet::totalHeadersSize(); auto headerOffset = Packet::totalHeaderSize(packet.isPartOfMessage());
return *reinterpret_cast<const PacketType*>(packet.getData() + headerOffset); return *reinterpret_cast<const PacketType*>(packet.getData() + headerOffset);
} }
PacketVersion NLPacket::versionInHeader(const udt::Packet& packet) { PacketVersion NLPacket::versionInHeader(const udt::Packet& packet) {
auto headerOffset = packet.Packet::totalHeadersSize(); auto headerOffset = Packet::totalHeaderSize(packet.isPartOfMessage());
return *reinterpret_cast<const PacketVersion*>(packet.getData() + headerOffset + sizeof(PacketType)); return *reinterpret_cast<const PacketVersion*>(packet.getData() + headerOffset + sizeof(PacketType));
} }
QUuid NLPacket::sourceIDInHeader(const udt::Packet& packet) { QUuid NLPacket::sourceIDInHeader(const udt::Packet& packet) {
int offset = packet.Packet::totalHeadersSize() + sizeof(PacketType) + sizeof(PacketVersion); int offset = Packet::totalHeaderSize(packet.isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion);
return QUuid::fromRfc4122(QByteArray::fromRawData(packet.getData() + offset, NUM_BYTES_RFC4122_UUID)); return QUuid::fromRfc4122(QByteArray::fromRawData(packet.getData() + offset, NUM_BYTES_RFC4122_UUID));
} }
QByteArray NLPacket::verificationHashInHeader(const udt::Packet& packet) { QByteArray NLPacket::verificationHashInHeader(const udt::Packet& packet) {
int offset = packet.Packet::totalHeadersSize() + sizeof(PacketType) + sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID; int offset = Packet::totalHeaderSize(packet.isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID;
return QByteArray(packet.getData() + offset, NUM_BYTES_MD5_HASH); return QByteArray(packet.getData() + offset, NUM_BYTES_MD5_HASH);
} }
QByteArray NLPacket::hashForPacketAndSecret(const udt::Packet& packet, const QUuid& connectionSecret) { QByteArray NLPacket::hashForPacketAndSecret(const udt::Packet& packet, const QUuid& connectionSecret) {
QCryptographicHash hash(QCryptographicHash::Md5); QCryptographicHash hash(QCryptographicHash::Md5);
int offset = packet.Packet::totalHeadersSize() + sizeof(PacketType) + sizeof(PacketVersion) int offset = Packet::totalHeaderSize(packet.isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion)
+ NUM_BYTES_RFC4122_UUID + NUM_BYTES_MD5_HASH; + NUM_BYTES_RFC4122_UUID + NUM_BYTES_MD5_HASH;
// add the packet payload and the connection UUID // add the packet payload and the connection UUID
@ -194,7 +185,7 @@ QByteArray NLPacket::hashForPacketAndSecret(const udt::Packet& packet, const QUu
} }
void NLPacket::writeTypeAndVersion() { void NLPacket::writeTypeAndVersion() {
auto headerOffset = Packet::localHeaderSize(); auto headerOffset = Packet::localHeaderSize(isPartOfMessage());
// Pack the packet type // Pack the packet type
memcpy(_packet.get() + headerOffset, &_type, sizeof(PacketType)); memcpy(_packet.get() + headerOffset, &_type, sizeof(PacketType));
@ -204,16 +195,14 @@ void NLPacket::writeTypeAndVersion() {
} }
void NLPacket::setType(PacketType type) { void NLPacket::setType(PacketType type) {
auto currentHeaderSize = totalHeadersSize(); // Setting new packet type with a different header size not currently supported
Q_ASSERT(NLPacket::totalHeaderSize(_type, isPartOfMessage()) ==
NLPacket::totalHeaderSize(type, isPartOfMessage()));
_type = type; _type = type;
_version = versionForPacketType(_type); _version = versionForPacketType(_type);
writeTypeAndVersion(); writeTypeAndVersion();
// Setting new packet type with a different header size not currently supported
Q_ASSERT(currentHeaderSize == totalHeadersSize());
Q_UNUSED(currentHeaderSize);
} }
void NLPacket::readType() { void NLPacket::readType() {
@ -233,7 +222,7 @@ void NLPacket::readSourceID() {
void NLPacket::writeSourceID(const QUuid& sourceID) { void NLPacket::writeSourceID(const QUuid& sourceID) {
Q_ASSERT(!NON_SOURCED_PACKETS.contains(_type)); Q_ASSERT(!NON_SOURCED_PACKETS.contains(_type));
auto offset = Packet::totalHeadersSize() + sizeof(PacketType) + sizeof(PacketVersion); auto offset = Packet::totalHeaderSize(isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion);
memcpy(_packet.get() + offset, sourceID.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID); memcpy(_packet.get() + offset, sourceID.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID);
_sourceID = sourceID; _sourceID = sourceID;
@ -242,7 +231,8 @@ void NLPacket::writeSourceID(const QUuid& sourceID) {
void NLPacket::writeVerificationHashGivenSecret(const QUuid& connectionSecret) { void NLPacket::writeVerificationHashGivenSecret(const QUuid& connectionSecret) {
Q_ASSERT(!NON_SOURCED_PACKETS.contains(_type) && !NON_VERIFIED_PACKETS.contains(_type)); Q_ASSERT(!NON_SOURCED_PACKETS.contains(_type) && !NON_VERIFIED_PACKETS.contains(_type));
auto offset = Packet::totalHeadersSize() + sizeof(PacketType) + sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID; auto offset = Packet::totalHeaderSize(isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion)
+ NUM_BYTES_RFC4122_UUID;
QByteArray verificationHash = hashForPacketAndSecret(*this, connectionSecret); QByteArray verificationHash = hashForPacketAndSecret(*this, connectionSecret);
memcpy(_packet.get() + offset, verificationHash.data(), verificationHash.size()); memcpy(_packet.get() + offset, verificationHash.data(), verificationHash.size());

View file

@ -35,6 +35,13 @@ public:
// Provided for convenience, try to limit use // Provided for convenience, try to limit use
static std::unique_ptr<NLPacket> createCopy(const NLPacket& other); static std::unique_ptr<NLPacket> createCopy(const NLPacket& other);
// Current level's header size
static int localHeaderSize(PacketType type);
// Cumulated size of all the headers
static int totalHeaderSize(PacketType type, bool isPartOfMessage = false);
// The maximum payload size this packet can use to fit in MTU
static int maxPayloadSize(PacketType type, bool isPartOfMessage = false);
static PacketType typeInHeader(const udt::Packet& packet); static PacketType typeInHeader(const udt::Packet& packet);
static PacketVersion versionInHeader(const udt::Packet& packet); static PacketVersion versionInHeader(const udt::Packet& packet);
@ -42,13 +49,6 @@ public:
static QByteArray verificationHashInHeader(const udt::Packet& packet); static QByteArray verificationHashInHeader(const udt::Packet& packet);
static QByteArray hashForPacketAndSecret(const udt::Packet& packet, const QUuid& connectionSecret); static QByteArray hashForPacketAndSecret(const udt::Packet& packet, const QUuid& connectionSecret);
static qint64 maxPayloadSize(PacketType type);
static qint64 localHeaderSize(PacketType type);
virtual qint64 maxPayloadSize() const; // The maximum payload size this packet can use to fit in MTU
virtual qint64 totalHeadersSize() const; // Cumulated size of all the headers
virtual qint64 localHeaderSize() const; // Current level's header size
PacketType getType() const { return _type; } PacketType getType() const { return _type; }
void setType(PacketType type); void setType(PacketType type);

View file

@ -15,6 +15,16 @@ using namespace udt;
const qint64 BasePacket::PACKET_WRITE_ERROR = -1; const qint64 BasePacket::PACKET_WRITE_ERROR = -1;
int BasePacket::localHeaderSize() {
return 0;
}
int BasePacket::totalHeaderSize() {
return 0;
}
int BasePacket::maxPayloadSize() {
return MAX_PACKET_SIZE;
}
std::unique_ptr<BasePacket> BasePacket::create(qint64 size) { std::unique_ptr<BasePacket> BasePacket::create(qint64 size) {
auto packet = std::unique_ptr<BasePacket>(new BasePacket(size)); auto packet = std::unique_ptr<BasePacket>(new BasePacket(size));
@ -37,7 +47,7 @@ std::unique_ptr<BasePacket> BasePacket::fromReceivedPacket(std::unique_ptr<char>
} }
BasePacket::BasePacket(qint64 size) { BasePacket::BasePacket(qint64 size) {
auto maxPayload = maxPayloadSize(); auto maxPayload = BasePacket::maxPayloadSize();
if (size == -1) { if (size == -1) {
// default size of -1, means biggest packet possible // default size of -1, means biggest packet possible
@ -116,6 +126,10 @@ BasePacket& BasePacket::operator=(BasePacket&& other) {
return *this; return *this;
} }
qint64 BasePacket::getDataSize() const {
return (_payloadStart - _packet.get()) + _payloadSize;
}
void BasePacket::setPayloadSize(qint64 payloadSize) { void BasePacket::setPayloadSize(qint64 payloadSize) {
if (isWritable()) { if (isWritable()) {
Q_ASSERT(payloadSize <= _payloadCapacity); Q_ASSERT(payloadSize <= _payloadCapacity);

View file

@ -30,10 +30,12 @@ public:
static std::unique_ptr<BasePacket> fromReceivedPacket(std::unique_ptr<char> data, qint64 size, static std::unique_ptr<BasePacket> fromReceivedPacket(std::unique_ptr<char> data, qint64 size,
const HifiSockAddr& senderSockAddr); const HifiSockAddr& senderSockAddr);
static qint64 maxPayloadSize() { return MAX_PACKET_SIZE; } // The maximum payload size this packet can use to fit in MTU // Current level's header size
static qint64 localHeaderSize() { return 0; } // Current level's header size static int localHeaderSize();
// Cumulated size of all the headers
virtual qint64 totalHeadersSize() const { return 0; } // Cumulated size of all the headers static int totalHeaderSize();
// The maximum payload size this packet can use to fit in MTU
static int maxPayloadSize();
// Payload direct access to the payload, use responsibly! // Payload direct access to the payload, use responsibly!
char* getPayload() { return _payloadStart; } char* getPayload() { return _payloadStart; }
@ -44,7 +46,7 @@ public:
const char* getData() const { return _packet.get(); } const char* getData() const { return _packet.get(); }
// Returns the size of the packet, including the header // Returns the size of the packet, including the header
qint64 getDataSize() const { return totalHeadersSize() + _payloadSize; } qint64 getDataSize() const;
// Returns the size of the payload only // Returns the size of the payload only
qint64 getPayloadSize() const { return _payloadSize; } qint64 getPayloadSize() const { return _payloadSize; }
@ -86,7 +88,7 @@ protected:
virtual qint64 writeData(const char* data, qint64 maxSize); virtual qint64 writeData(const char* data, qint64 maxSize);
virtual qint64 readData(char* data, qint64 maxSize); virtual qint64 readData(char* data, qint64 maxSize);
virtual void adjustPayloadStartAndCapacity(qint64 headerSize, bool shouldDecreasePayloadSize = false); void adjustPayloadStartAndCapacity(qint64 headerSize, bool shouldDecreasePayloadSize = false);
qint64 _packetSize = 0; // Total size of the allocated memory qint64 _packetSize = 0; // Total size of the allocated memory
std::unique_ptr<char> _packet; // Allocated memory std::unique_ptr<char> _packet; // Allocated memory

View file

@ -15,6 +15,16 @@
using namespace udt; using namespace udt;
int ControlPacket::localHeaderSize() {
return sizeof(ControlPacket::ControlBitAndType);
}
int ControlPacket::totalHeaderSize() {
return BasePacket::totalHeaderSize() + ControlPacket::localHeaderSize();
}
int ControlPacket::maxPayloadSize() {
return BasePacket::maxPayloadSize() - ControlPacket::localHeaderSize();
}
std::unique_ptr<ControlPacket> ControlPacket::fromReceivedPacket(std::unique_ptr<char> data, qint64 size, std::unique_ptr<ControlPacket> ControlPacket::fromReceivedPacket(std::unique_ptr<char> data, qint64 size,
const HifiSockAddr &senderSockAddr) { const HifiSockAddr &senderSockAddr) {
// Fail with null data // Fail with null data
@ -45,19 +55,11 @@ std::unique_ptr<ControlPacket> ControlPacket::create(Type type, qint64 size) {
} }
} }
qint64 ControlPacket::localHeaderSize() {
return sizeof(ControlBitAndType);
}
qint64 ControlPacket::totalHeadersSize() const {
return BasePacket::totalHeadersSize() + localHeaderSize();
}
ControlPacket::ControlPacket(Type type) : ControlPacket::ControlPacket(Type type) :
BasePacket(-1), BasePacket(-1),
_type(type) _type(type)
{ {
adjustPayloadStartAndCapacity(localHeaderSize()); adjustPayloadStartAndCapacity(ControlPacket::localHeaderSize());
open(QIODevice::ReadWrite); open(QIODevice::ReadWrite);
@ -65,10 +67,10 @@ ControlPacket::ControlPacket(Type type) :
} }
ControlPacket::ControlPacket(Type type, qint64 size) : ControlPacket::ControlPacket(Type type, qint64 size) :
BasePacket(localHeaderSize() + size), BasePacket(ControlPacket::localHeaderSize() + size),
_type(type) _type(type)
{ {
adjustPayloadStartAndCapacity(localHeaderSize()); adjustPayloadStartAndCapacity(ControlPacket::localHeaderSize());
open(QIODevice::ReadWrite); open(QIODevice::ReadWrite);
@ -81,7 +83,7 @@ ControlPacket::ControlPacket(std::unique_ptr<char> data, qint64 size, const Hifi
// sanity check before we decrease the payloadSize with the payloadCapacity // sanity check before we decrease the payloadSize with the payloadCapacity
Q_ASSERT(_payloadSize == _payloadCapacity); Q_ASSERT(_payloadSize == _payloadCapacity);
adjustPayloadStartAndCapacity(localHeaderSize(), _payloadSize > 0); adjustPayloadStartAndCapacity(ControlPacket::localHeaderSize(), _payloadSize > 0);
readType(); readType();
} }

View file

@ -33,12 +33,15 @@ public:
TimeoutNAK TimeoutNAK
}; };
static std::unique_ptr<ControlPacket> create(Type type, qint64 size = -1);
static std::unique_ptr<ControlPacket> fromReceivedPacket(std::unique_ptr<char> data, qint64 size, static std::unique_ptr<ControlPacket> fromReceivedPacket(std::unique_ptr<char> data, qint64 size,
const HifiSockAddr& senderSockAddr); const HifiSockAddr& senderSockAddr);
static std::unique_ptr<ControlPacket> create(Type type, qint64 size = -1); // Current level's header size
static int localHeaderSize();
static qint64 localHeaderSize(); // Current level's header size // Cumulated size of all the headers
virtual qint64 totalHeadersSize() const; // Cumulated size of all the headers static int totalHeaderSize();
// The maximum payload size this packet can use to fit in MTU
static int maxPayloadSize();
Type getType() const { return _type; } Type getType() const { return _type; }
void setType(Type type); void setType(Type type);
@ -53,16 +56,13 @@ private:
ControlPacket& operator=(ControlPacket&& other); ControlPacket& operator=(ControlPacket&& other);
ControlPacket& operator=(const ControlPacket& other) = delete; ControlPacket& operator=(const ControlPacket& other) = delete;
// Header writers // Header read/write
void writeControlBitAndType();
void writeType();
// Header readers
void readType(); void readType();
void writeType();
Type _type; Type _type;
}; };
} // namespace udt } // namespace udt

View file

@ -13,6 +13,20 @@
using namespace udt; using namespace udt;
int Packet::localHeaderSize(bool isPartOfMessage) {
return sizeof(Packet::SequenceNumberAndBitField) +
(isPartOfMessage ? sizeof(Packet::MessageNumberAndBitField) : 0);
}
int Packet::totalHeaderSize(bool isPartOfMessage) {
return BasePacket::totalHeaderSize() + Packet::localHeaderSize(isPartOfMessage);
}
int Packet::maxPayloadSize(bool isPartOfMessage) {
return BasePacket::maxPayloadSize() - Packet::localHeaderSize(isPartOfMessage);
}
std::unique_ptr<Packet> Packet::create(qint64 size, bool isReliable, bool isPartOfMessage) { std::unique_ptr<Packet> Packet::create(qint64 size, bool isReliable, bool isPartOfMessage) {
auto packet = std::unique_ptr<Packet>(new Packet(size, isReliable, isPartOfMessage)); auto packet = std::unique_ptr<Packet>(new Packet(size, isReliable, isPartOfMessage));
@ -37,32 +51,12 @@ std::unique_ptr<Packet> Packet::createCopy(const Packet& other) {
return std::unique_ptr<Packet>(new Packet(other)); return std::unique_ptr<Packet>(new Packet(other));
} }
qint64 Packet::maxPayloadSize(bool isPartOfMessage) {
return MAX_PACKET_SIZE - localHeaderSize(isPartOfMessage);
}
qint64 Packet::localHeaderSize(bool isPartOfMessage) {
return sizeof(SequenceNumberAndBitField) + (isPartOfMessage ? sizeof(MessageNumberAndBitField) : 0);
}
qint64 Packet::maxPayloadSize() const {
return MAX_PACKET_SIZE - localHeaderSize();
}
qint64 Packet::totalHeadersSize() const {
return BasePacket::totalHeadersSize() + Packet::localHeaderSize();
}
qint64 Packet::localHeaderSize() const {
return localHeaderSize(_isPartOfMessage);
}
Packet::Packet(qint64 size, bool isReliable, bool isPartOfMessage) : Packet::Packet(qint64 size, bool isReliable, bool isPartOfMessage) :
BasePacket(size), BasePacket(Packet::localHeaderSize() + size),
_isReliable(isReliable), _isReliable(isReliable),
_isPartOfMessage(isPartOfMessage) _isPartOfMessage(isPartOfMessage)
{ {
adjustPayloadStartAndCapacity(localHeaderSize()); adjustPayloadStartAndCapacity(Packet::localHeaderSize(_isPartOfMessage));
// set the UDT header to default values // set the UDT header to default values
writeHeader(); writeHeader();
@ -73,7 +67,7 @@ Packet::Packet(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& send
{ {
readHeader(); readHeader();
adjustPayloadStartAndCapacity(localHeaderSize(), _payloadSize > 0); adjustPayloadStartAndCapacity(Packet::localHeaderSize(_isPartOfMessage), _payloadSize > 0);
} }
Packet::Packet(const Packet& other) : Packet::Packet(const Packet& other) :

View file

@ -38,15 +38,12 @@ public:
// Provided for convenience, try to limit use // Provided for convenience, try to limit use
static std::unique_ptr<Packet> createCopy(const Packet& other); static std::unique_ptr<Packet> createCopy(const Packet& other);
// The maximum payload size this packet can use to fit in MTU
static qint64 maxPayloadSize(bool isPartOfMessage);
virtual qint64 maxPayloadSize() const;
// Current level's header size // Current level's header size
static qint64 localHeaderSize(bool isPartOfMessage); static int localHeaderSize(bool isPartOfMessage = false);
virtual qint64 localHeaderSize() const; // Cumulated size of all the headers
static int totalHeaderSize(bool isPartOfMessage = false);
virtual qint64 totalHeadersSize() const; // Cumulated size of all the headers // The maximum payload size this packet can use to fit in MTU
static int maxPayloadSize(bool isPartOfMessage = false);
bool isPartOfMessage() const { return _isPartOfMessage; } bool isPartOfMessage() const { return _isPartOfMessage; }
bool isReliable() const { return _isReliable; } bool isReliable() const { return _isReliable; }