voxel-server packet version handling

This commit is contained in:
Stephen Birarda 2013-07-08 11:54:00 -07:00
parent 5062ae8965
commit 693463ae5b
4 changed files with 15 additions and 12 deletions

View file

@ -97,7 +97,7 @@ void NodeList::processNodeData(sockaddr *senderAddress, unsigned char *packetDat
case PACKET_TYPE_PING: {
char pingPacket[dataBytes];
memcpy(pingPacket, packetData, dataBytes);
pingPacket[0] = PACKET_TYPE_PING_REPLY;
populateTypeAndVersion((unsigned char*) pingPacket, PACKET_TYPE_PING_REPLY);
_nodeSocket.send(senderAddress, pingPacket, dataBytes);
break;
}

View file

@ -35,8 +35,10 @@ const PACKET_TYPE PACKET_TYPE_DOMAIN_LIST_REQUEST = 'L';
const PACKET_TYPE PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY = 'C';
typedef char PACKET_VERSION;
PACKET_VERSION versionForPacketType(PACKET_TYPE header);
int populateTypeAndVersion(unsigned char* destination, PACKET_TYPE header);
PACKET_VERSION versionForPacketType(PACKET_TYPE type);
int populateTypeAndVersion(unsigned char* destination, PACKET_TYPE type);
const int MAX_PACKET_HEADER_BYTES = sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION);

View file

@ -535,7 +535,7 @@ void VoxelTree::readCodeColorBufferToTreeRecursion(VoxelNode* node, void* extraD
void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int bufferSizeBytes) {
//unsigned short int itemNumber = (*((unsigned short int*)&bitstream[sizeof(PACKET_HEADER)]));
int atByte = sizeof(short int) + sizeof(PACKET_TYPE);
int atByte = sizeof(short int) + sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION);
unsigned char* voxelCode = (unsigned char*)&bitstream[atByte];
while (atByte < bufferSizeBytes) {
int codeLength = numberOfThreeBitSectionsInCode(voxelCode);

View file

@ -636,19 +636,20 @@ int main(int argc, const char * argv[]) {
// check to see if we need to persist our voxel state
persistVoxelsWhenDirty();
if (nodeList->getNodeSocket()->receive(&nodePublicAddress, packetData, &receivedBytes)) {
if (nodeList->getNodeSocket()->receive(&nodePublicAddress, packetData, &receivedBytes) &&
versionForPacketType(packetData[0]) == packetData[1]) {
if (packetData[0] == PACKET_TYPE_SET_VOXEL || packetData[0] == PACKET_TYPE_SET_VOXEL_DESTRUCTIVE) {
bool destructive = (packetData[0] == PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
PerformanceWarning warn(::shouldShowAnimationDebug,
destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL",
::shouldShowAnimationDebug);
unsigned short int itemNumber = (*((unsigned short int*)&packetData[1]));
unsigned short int itemNumber = (*((unsigned short int*)&packetData[2]));
if (::shouldShowAnimationDebug) {
printf("got %s - command from client receivedBytes=%ld itemNumber=%d\n",
destructive ? "PACKET_TYPE_SET_VOXEL_DESTRUCTIVE" : "PACKET_TYPE_SET_VOXEL",
receivedBytes,itemNumber);
}
int atByte = sizeof(PACKET_TYPE) + sizeof(itemNumber);
int atByte = sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION) + sizeof(itemNumber);
unsigned char* voxelData = (unsigned char*)&packetData[atByte];
while (atByte < receivedBytes) {
unsigned char octets = (unsigned char)*voxelData;
@ -702,7 +703,7 @@ int main(int argc, const char * argv[]) {
// the Z command is a special command that allows the sender to send the voxel server high level semantic
// requests, like erase all, or add sphere scene
char* command = (char*) &packetData[1]; // start of the command
char* command = (char*) &packetData[2]; // start of the command
int commandLength = strlen(command); // commands are null terminated strings
int totalLength = sizeof(PACKET_TYPE_Z_COMMAND) + commandLength + 1; // 1 for null termination
printf("got Z message len(%ld)= %s\n", receivedBytes, command);
@ -735,11 +736,11 @@ int main(int argc, const char * argv[]) {
// need to make sure we have it in our nodeList.
if (packetData[0] == PACKET_TYPE_HEAD_DATA) {
uint16_t nodeID = 0;
unpackNodeId(packetData + sizeof(PACKET_TYPE_HEAD_DATA), &nodeID);
unpackNodeId(packetData + sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION), &nodeID);
Node* node = nodeList->addOrUpdateNode(&nodePublicAddress,
&nodePublicAddress,
NODE_TYPE_AGENT,
nodeID);
&nodePublicAddress,
NODE_TYPE_AGENT,
nodeID);
nodeList->updateNodeWithData(node, packetData, receivedBytes);
}