13 #ifndef hifi_NLPacket_h
14 #define hifi_NLPacket_h
18 #include "udt/Packet.h"
22 class NLPacket :
public udt::Packet {
41 using LocalID = NetworkLocalID;
42 static const LocalID NULL_LOCAL_ID = 0;
44 static const int NUM_BYTES_LOCALID =
sizeof(LocalID);
46 static const int MAX_PACKET_HEADER_SIZE =
47 sizeof(udt::Packet::SequenceNumberAndBitField) +
sizeof(udt::Packet::MessageNumberAndBitField) +
48 sizeof(PacketType) +
sizeof(PacketVersion) + NUM_BYTES_LOCALID + NUM_BYTES_MD5_HASH;
50 static std::unique_ptr<NLPacket> create(PacketType type, qint64 size = -1,
51 bool isReliable =
false,
bool isPartOfMessage =
false, PacketVersion version = 0);
53 static std::unique_ptr<NLPacket> fromReceivedPacket(std::unique_ptr<
char[]> data, qint64 size,
54 const SockAddr& senderSockAddr);
56 static std::unique_ptr<NLPacket> fromBase(std::unique_ptr<Packet> packet);
59 static std::unique_ptr<NLPacket> createCopy(
const NLPacket& other);
62 static int localHeaderSize(PacketType type);
64 static int totalHeaderSize(PacketType type,
bool isPartOfMessage =
false);
66 static int maxPayloadSize(PacketType type,
bool isPartOfMessage =
false);
68 static PacketType typeInHeader(
const udt::Packet& packet);
69 static PacketVersion versionInHeader(
const udt::Packet& packet);
71 static LocalID sourceIDInHeader(
const udt::Packet& packet);
72 static QByteArray verificationHashInHeader(
const udt::Packet& packet);
73 static QByteArray hashForPacketAndHMAC(
const udt::Packet& packet, HMACAuth& hash);
75 PacketType getType()
const {
return _type; }
76 void setType(PacketType type);
78 PacketVersion getVersion()
const {
return _version; }
79 void setVersion(PacketVersion version);
81 LocalID getSourceID()
const {
return _sourceID; }
83 void writeSourceID(LocalID sourceID)
const;
84 void writeVerificationHash(HMACAuth& hmacAuth)
const;
88 NLPacket(PacketType type, qint64 size = -1,
bool forceReliable =
false,
bool isPartOfMessage =
false, PacketVersion version = 0);
89 NLPacket(std::unique_ptr<
char[]> data, qint64 size,
const SockAddr& senderSockAddr);
91 NLPacket(
const NLPacket& other);
92 NLPacket(NLPacket&& other);
93 NLPacket(Packet&& other);
95 NLPacket& operator=(
const NLPacket& other);
96 NLPacket& operator=(NLPacket&& other);
99 void writeTypeAndVersion();
107 PacketVersion _version;
108 mutable LocalID _sourceID;