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

This commit is contained in:
Stephen Birarda 2015-07-30 17:20:27 -07:00
commit 91355a5396
5 changed files with 12 additions and 36 deletions

View file

@ -150,11 +150,9 @@ QDataStream& operator<<(QDataStream &out, const Assignment& assignment) {
QDataStream& operator>>(QDataStream &in, Assignment& assignment) {
quint8 packedType;
in >> packedType;
in >> packedType >> assignment._uuid >> assignment._pool >> assignment._payload;
assignment._type = (Assignment::Type) packedType;
in >> assignment._uuid >> assignment._pool >> assignment._payload;
if (assignment._command == Assignment::RequestCommand) {
in >> assignment._walletUUID;
}

View file

@ -247,13 +247,13 @@ void LimitedNodeList::collectPacketStats(const NLPacket& packet) {
void LimitedNodeList::fillPacketHeader(const NLPacket& packet, const QUuid& connectionSecret) {
if (!NON_SOURCED_PACKETS.contains(packet.getType())) {
const_cast<NLPacket&>(packet).writeSourceID(getSessionUUID());
packet.writeSourceID(getSessionUUID());
}
if (!connectionSecret.isNull()
&& !NON_SOURCED_PACKETS.contains(packet.getType())
&& !NON_VERIFIED_PACKETS.contains(packet.getType())) {
const_cast<NLPacket&>(packet).writeVerificationHashGivenSecret(connectionSecret);
packet.writeVerificationHashGivenSecret(connectionSecret);
}
}

View file

@ -25,16 +25,7 @@ int NLPacket::maxPayloadSize(PacketType type, bool isPartOfMessage) {
}
std::unique_ptr<NLPacket> NLPacket::create(PacketType type, qint64 size, bool isReliable, bool isPartOfMessage) {
std::unique_ptr<NLPacket> packet;
if (size == -1) {
packet = std::unique_ptr<NLPacket>(new NLPacket(type, isReliable, isPartOfMessage));
} else {
// Fail with invalid size
Q_ASSERT(size >= 0);
packet = std::unique_ptr<NLPacket>(new NLPacket(type, size, isReliable, isPartOfMessage));
}
auto packet = std::unique_ptr<NLPacket>(new NLPacket(type, size, isReliable, isPartOfMessage));
packet->open(QIODevice::ReadWrite);
@ -70,23 +61,11 @@ std::unique_ptr<NLPacket> NLPacket::createCopy(const NLPacket& other) {
return std::unique_ptr<NLPacket>(new NLPacket(other));
}
NLPacket::NLPacket(PacketType type, bool isReliable, bool isPartOfMessage) :
Packet(-1, isReliable, isPartOfMessage),
_type(type),
_version(versionForPacketType(type))
{
adjustPayloadStartAndCapacity(NLPacket::localHeaderSize(_type));
writeTypeAndVersion();
}
NLPacket::NLPacket(PacketType type, qint64 size, bool isReliable, bool isPartOfMessage) :
Packet(NLPacket::localHeaderSize(type) + size, isReliable, isPartOfMessage),
Packet((size == -1) ? -1 : NLPacket::localHeaderSize(type) + size, isReliable, isPartOfMessage),
_type(type),
_version(versionForPacketType(type))
{
Q_ASSERT(size >= 0);
adjustPayloadStartAndCapacity(NLPacket::localHeaderSize(_type));
writeTypeAndVersion();
@ -219,7 +198,7 @@ void NLPacket::readSourceID() {
}
}
void NLPacket::writeSourceID(const QUuid& sourceID) {
void NLPacket::writeSourceID(const QUuid& sourceID) const {
Q_ASSERT(!NON_SOURCED_PACKETS.contains(_type));
auto offset = Packet::totalHeaderSize(isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion);
@ -228,7 +207,7 @@ void NLPacket::writeSourceID(const QUuid& sourceID) {
_sourceID = sourceID;
}
void NLPacket::writeVerificationHashGivenSecret(const QUuid& connectionSecret) {
void NLPacket::writeVerificationHashGivenSecret(const QUuid& connectionSecret) const {
Q_ASSERT(!NON_SOURCED_PACKETS.contains(_type) && !NON_VERIFIED_PACKETS.contains(_type));
auto offset = Packet::totalHeaderSize(isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion)

View file

@ -57,13 +57,12 @@ public:
const QUuid& getSourceID() const { return _sourceID; }
void writeSourceID(const QUuid& sourceID);
void writeVerificationHashGivenSecret(const QUuid& connectionSecret);
void writeSourceID(const QUuid& sourceID) const;
void writeVerificationHashGivenSecret(const QUuid& connectionSecret) const;
protected:
NLPacket(PacketType type, bool forceReliable = false, bool isPartOfMessage = false);
NLPacket(PacketType type, qint64 size, bool forceReliable = false, bool isPartOfMessage = false);
NLPacket(PacketType type, qint64 size = -1, bool forceReliable = false, bool isPartOfMessage = false);
NLPacket(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& senderSockAddr);
NLPacket(std::unique_ptr<Packet> packet);
NLPacket(const NLPacket& other);
@ -82,7 +81,7 @@ protected:
PacketType _type;
PacketVersion _version;
QUuid _sourceID;
mutable QUuid _sourceID;
};
#endif // hifi_NLPacket_h

View file

@ -52,7 +52,7 @@ std::unique_ptr<Packet> Packet::createCopy(const Packet& other) {
}
Packet::Packet(qint64 size, bool isReliable, bool isPartOfMessage) :
BasePacket(Packet::localHeaderSize() + size),
BasePacket((size == -1) ? -1 : (Packet::localHeaderSize() + size)),
_isReliable(isReliable),
_isPartOfMessage(isPartOfMessage)
{