ensure UUID pulled from packet header is exactly 16 bytes

This commit is contained in:
Stephen Birarda 2014-01-28 11:53:09 -08:00
parent 75e2fa491a
commit ffefc529f3
3 changed files with 6 additions and 5 deletions

View file

@ -127,6 +127,7 @@ void DomainServer::readAvailableDatagrams() {
packetStream.skipRawData(numBytesForPacketHeader(receivedPacket));
deconstructPacketHeader(receivedPacket, nodeUUID);
packetStream >> nodeType;
packetStream >> nodePublicAddress >> nodeLocalAddress;

View file

@ -474,7 +474,7 @@ void NodeList::sendDomainServerCheckIn() {
foreach (NODE_TYPE nodeTypeOfInterest, _nodeTypesOfInterest) {
packetStream << nodeTypeOfInterest;
}
_nodeSocket.writeDatagram(domainServerPacket, _domainSockAddr.getAddress(), _domainSockAddr.getPort());
const int NUM_DOMAIN_SERVER_CHECKINS_PER_STUN_REQUEST = 5;
static unsigned int numDomainCheckins = 0;

View file

@ -59,7 +59,7 @@ QByteArray byteArrayWithPopluatedHeader(PacketType type, const QUuid& connection
}
int populatePacketHeader(QByteArray& packet, PacketType type, const QUuid& connectionUUID) {
if (packet.size() < MAX_HEADER_BYTES) {
if (packet.size() < numBytesForPacketHeaderGivenPacketType(type)) {
packet.resize(numBytesForPacketHeaderGivenPacketType(type));
}
@ -77,7 +77,6 @@ int populatePacketHeader(char* packet, PacketType type, const QUuid& connectionU
// return the number of bytes written for pointer pushing
return numTypeBytes + sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID;
}
bool packetVersionMatch(const QByteArray& packet) {
@ -112,11 +111,12 @@ int numBytesForPacketHeader(const char* packet) {
}
int numBytesForPacketHeaderGivenPacketType(PacketType type) {
return (int) ceilf((float)type) + sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID;
return (int) ceilf((float)type / 255) + sizeof(PacketVersion) + NUM_BYTES_RFC4122_UUID;
}
void deconstructPacketHeader(const QByteArray& packet, QUuid& senderUUID) {
senderUUID = QUuid::fromRfc4122(packet.mid(numBytesArithmeticCodingFromBuffer(packet.data()) + sizeof(PacketVersion)));
senderUUID = QUuid::fromRfc4122(packet.mid(numBytesArithmeticCodingFromBuffer(packet.data()) + sizeof(PacketVersion),
NUM_BYTES_RFC4122_UUID));
}
PacketType packetTypeForPacket(const QByteArray& packet) {