packet versioning for HEAD_DATA packets

This commit is contained in:
Stephen Birarda 2013-07-08 12:53:07 -07:00
parent 5faad80e12
commit 8a684244cc
5 changed files with 23 additions and 18 deletions

View file

@ -92,7 +92,8 @@ int main(int argc, const char* argv[]) {
NodeList::getInstance()->sendDomainServerCheckIn();
}
if (nodeList->getNodeSocket()->receive(nodeAddress, packetData, &receivedBytes)) {
if (nodeList->getNodeSocket()->receive(nodeAddress, packetData, &receivedBytes) &&
versionForPacketType(packetData[0]) == packetData[1]) {
switch (packetData[0]) {
case PACKET_TYPE_HEAD_DATA:
// grab the node ID from the packet
@ -118,7 +119,7 @@ int main(int argc, const char* argv[]) {
break;
case PACKET_TYPE_AVATAR_VOXEL_URL:
// grab the node ID from the packet
unpackNodeId(packetData + 1, &nodeID);
unpackNodeId(packetData + sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION), &nodeID);
// let everyone else know about the update
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {

View file

@ -122,7 +122,7 @@ int main(int argc, const char* argv[]) {
nodeList->linkedDataCreateCallback = createAvatarDataForNode;
unsigned char broadcastPacket[MAX_PACKET_SIZE];
broadcastPacket[0] = PACKET_TYPE_HEAD_DATA;
int numHeaderBytes = populateTypeAndVersion(broadcastPacket, PACKET_TYPE_HEAD_DATA);
timeval thisSend;
long long numMicrosecondsSleep = 0;
@ -150,7 +150,7 @@ int main(int argc, const char* argv[]) {
// make sure we actually have an avatar mixer with an active socket
if (nodeList->getOwnerID() != UNKNOWN_NODE_ID && avatarMixer && avatarMixer->getActiveSocket() != NULL) {
unsigned char* packetPosition = broadcastPacket + sizeof(PACKET_TYPE);
unsigned char* packetPosition = broadcastPacket + numHeaderBytes;
packetPosition += packNodeId(packetPosition, nodeList->getOwnerID());
// use the getBroadcastData method in the AvatarData class to populate the broadcastPacket buffer

View file

@ -1988,7 +1988,8 @@ void Application::updateAvatar(float deltaTime) {
unsigned char broadcastString[200];
unsigned char* endOfBroadcastStringWrite = broadcastString;
*(endOfBroadcastStringWrite++) = PACKET_TYPE_HEAD_DATA;
endOfBroadcastStringWrite += populateTypeAndVersion(endOfBroadcastStringWrite, PACKET_TYPE_HEAD_DATA);
endOfBroadcastStringWrite += packNodeId(endOfBroadcastStringWrite, nodeList->getOwnerID());
endOfBroadcastStringWrite += _myAvatar.getBroadcastData(endOfBroadcastStringWrite);

View file

@ -169,7 +169,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
}
// increment to push past the packet header
sourceBuffer += sizeof(PACKET_TYPE_HEAD_DATA);
sourceBuffer += sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION);
unsigned char* startPosition = sourceBuffer;

View file

@ -119,16 +119,19 @@ void NodeList::processBulkNodeData(sockaddr *senderAddress, unsigned char *packe
}
unsigned char *startPosition = packetData;
unsigned char *currentPosition = startPosition + 1;
unsigned char *currentPosition = startPosition + sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION);
unsigned char packetHolder[numTotalBytes];
packetHolder[0] = PACKET_TYPE_HEAD_DATA;
// we've already verified packet version for the bulk packet, so all head data in the packet is also up to date
populateTypeAndVersion(packetHolder, PACKET_TYPE_HEAD_DATA);
uint16_t nodeID = -1;
while ((currentPosition - startPosition) < numTotalBytes) {
unpackNodeId(currentPosition, &nodeID);
memcpy(packetHolder + 1, currentPosition, numTotalBytes - (currentPosition - startPosition));
memcpy(packetHolder + sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION),
currentPosition,
numTotalBytes - (currentPosition - startPosition));
Node* matchingNode = nodeWithID(nodeID);
@ -138,8 +141,8 @@ void NodeList::processBulkNodeData(sockaddr *senderAddress, unsigned char *packe
}
currentPosition += updateNodeWithData(matchingNode,
packetHolder,
numTotalBytes - (currentPosition - startPosition));
packetHolder,
numTotalBytes - (currentPosition - startPosition));
}
unlock();
@ -272,7 +275,7 @@ void NodeList::sendDomainServerCheckIn() {
_nodeSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, checkInPacket, checkInPacketSize);
}
int NodeList::processDomainServerList(unsigned char *packetData, size_t dataBytes) {
int NodeList::processDomainServerList(unsigned char* packetData, size_t dataBytes) {
int readNodes = 0;
char nodeType;
@ -284,16 +287,16 @@ int NodeList::processDomainServerList(unsigned char *packetData, size_t dataByte
sockaddr_in nodeLocalSocket;
nodeLocalSocket.sin_family = AF_INET;
unsigned char *readPtr = packetData + 1;
unsigned char *startPtr = packetData;
unsigned char* readPtr = packetData + sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION);
unsigned char* startPtr = packetData;
while((readPtr - startPtr) < dataBytes - sizeof(uint16_t)) {
nodeType = *readPtr++;
readPtr += unpackNodeId(readPtr, (uint16_t *)&nodeId);
readPtr += unpackSocket(readPtr, (sockaddr *)&nodePublicSocket);
readPtr += unpackSocket(readPtr, (sockaddr *)&nodeLocalSocket);
readPtr += unpackNodeId(readPtr, (uint16_t*) &nodeId);
readPtr += unpackSocket(readPtr, (sockaddr*) &nodePublicSocket);
readPtr += unpackSocket(readPtr, (sockaddr*) &nodeLocalSocket);
addOrUpdateNode((sockaddr *)&nodePublicSocket, (sockaddr *)&nodeLocalSocket, nodeType, nodeId);
addOrUpdateNode((sockaddr*) &nodePublicSocket, (sockaddr*) &nodeLocalSocket, nodeType, nodeId);
}
// read out our ID from the packet