From 4eb25be14c0097ee52124a541c65b6fa2c5aeb5d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Jul 2013 12:09:42 -0700 Subject: [PATCH 1/7] fix node ID return from domain server --- domain-server/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 23c2ebdced..5d41efdc67 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -177,7 +177,7 @@ int main(int argc, const char * argv[]) // send the constructed list back to this node nodeList->getNodeSocket()->send(destinationSocket, broadcastPacket, - (currentBufferPos - startPointer) + 1); + (currentBufferPos - startPointer) + numHeaderBytes); } if (Logstash::shouldSendStats()) { From 769205253f509167d67179baea7b72d4df0510f3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Jul 2013 12:27:48 -0700 Subject: [PATCH 2/7] remove extra plus in AvatarData parseData --- libraries/avatars/src/AvatarData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 09c133989e..a64aa64178 100755 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -180,7 +180,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { unsigned char* startPosition = sourceBuffer; // push past the node ID - sourceBuffer += + sizeof(uint16_t); + sourceBuffer += sizeof(uint16_t); // Body world position memcpy(&_position, sourceBuffer, sizeof(float) * 3); From a1747725d35c9091637700d42e6bec189c314a4d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Jul 2013 12:28:29 -0700 Subject: [PATCH 3/7] sensible default for checkInPacketSize --- libraries/shared/src/NodeList.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 35632d4511..0f3eda6078 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -237,7 +237,7 @@ void NodeList::sendDomainServerCheckIn() { // construct the DS check in packet if we need to static unsigned char* checkInPacket = NULL; - static int checkInPacketSize; + static int checkInPacketSize = 0; const int IP_ADDRESS_BYTES = 4; From 94b25a18aab64c1df720d7a12bc4ba04641cf563 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Jul 2013 12:39:33 -0700 Subject: [PATCH 4/7] add a missing letter, use else-if in voxel-server --- voxel-server/src/main.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index a691ec3d29..875626991d 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -2,7 +2,7 @@ // main.cpp // Voxel Server // -// Created by Stephen Birara on 03/06/13. +// Created by Stephen Birarda on 03/06/13. // Copyright (c) 2012 High Fidelity, Inc. All rights reserved. // @@ -571,15 +571,13 @@ int main(int argc, const char * argv[]) { voxelData += voxelDataSize; atByte += voxelDataSize; } - } - if (packetData[0] == PACKET_TYPE_ERASE_VOXEL) { + } else if (packetData[0] == PACKET_TYPE_ERASE_VOXEL) { // Send these bits off to the VoxelTree class to process them pthread_mutex_lock(&::treeLock); serverTree.processRemoveVoxelBitstream((unsigned char*)packetData, receivedBytes); pthread_mutex_unlock(&::treeLock); - } - if (packetData[0] == PACKET_TYPE_Z_COMMAND) { + } else if (packetData[0] == PACKET_TYPE_Z_COMMAND) { // 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 @@ -612,10 +610,10 @@ int main(int argc, const char * argv[]) { printf("rebroadcasting Z message to connected nodes... nodeList.broadcastToNodes()\n"); nodeList->broadcastToNodes(packetData, receivedBytes, &NODE_TYPE_AGENT, 1); } - } - // If we got a PACKET_TYPE_HEAD_DATA, then we're talking to an NODE_TYPE_AVATAR, and we - // need to make sure we have it in our nodeList. - if (packetData[0] == PACKET_TYPE_HEAD_DATA) { + } else if (packetData[0] == PACKET_TYPE_HEAD_DATA) { + // If we got a PACKET_TYPE_HEAD_DATA, then we're talking to an NODE_TYPE_AVATAR, and we + // need to make sure we have it in our nodeList. + uint16_t nodeID = 0; unpackNodeId(packetData + numBytesPacketHeader, &nodeID); Node* node = nodeList->addOrUpdateNode(&nodePublicAddress, @@ -624,9 +622,8 @@ int main(int argc, const char * argv[]) { nodeID); nodeList->updateNodeWithData(node, packetData, receivedBytes); - } - // If the packet is a ping, let processNodeData handle it. - if (packetData[0] == PACKET_TYPE_PING) { + } else if (packetData[0] == PACKET_TYPE_PING) { + // If the packet is a ping, let processNodeData handle it. nodeList->processNodeData(&nodePublicAddress, packetData, receivedBytes); } } From b201d13e31ccb1ede0733bf0d8cab37436e2f30b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Jul 2013 12:42:45 -0700 Subject: [PATCH 5/7] refactor ping packet sending to push past version byte --- interface/src/Application.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index cd74b9c6ab..eb2fd77a55 100755 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -904,15 +904,15 @@ void Application::wheelEvent(QWheelEvent* event) { void Application::sendPingPackets() { - char nodeTypesOfInterest[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER}; + const char nodesToPing[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER}; uint64_t currentTime = usecTimestampNow(); unsigned char pingPacket[numBytesForPacketHeader((unsigned char*) &PACKET_TYPE_PING) + sizeof(currentTime)]; int numHeaderBytes = populateTypeAndVersion(pingPacket, PACKET_TYPE_PING); - memcpy(&pingPacket[1], ¤tTime, sizeof(currentTime)); - getInstance()->controlledBroadcastToNodes(pingPacket, numHeaderBytes + sizeof(currentTime), - nodeTypesOfInterest, sizeof(nodeTypesOfInterest)); + memcpy(pingPacket + numHeaderBytes, ¤tTime, sizeof(currentTime)); + getInstance()->controlledBroadcastToNodes(pingPacket, sizeof(pingPacket), + nodesToPing, sizeof(nodesToPing)); } // Every second, check the frame rates and other stuff From a0226b254841ea8801bae80081448cc785a9c894 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Jul 2013 13:02:25 -0700 Subject: [PATCH 6/7] avoid static variable thread issue by switching to member variables --- libraries/shared/src/NodeList.cpp | 29 ++++++++++++++--------------- libraries/shared/src/NodeList.h | 4 ++++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 0f3eda6078..ee5e44596e 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -63,7 +63,10 @@ NodeList::NodeList(char newOwnerType, unsigned int newSocketListenPort) : _ownerType(newOwnerType), _nodeTypesOfInterest(NULL), _ownerID(UNKNOWN_NODE_ID), - _lastNodeID(0) { + _lastNodeID(0), + _printedDomainServerIP(false), + _checkInPacket(NULL), + _checkInPacketSize(0) { pthread_mutex_init(&mutex, 0); } @@ -218,7 +221,6 @@ void NodeList::setNodeTypesOfInterest(const char* nodeTypesOfInterest, int numNo } void NodeList::sendDomainServerCheckIn() { - static bool printedDomainServerIP = false; // Lookup the IP address of the domain server if we need to if (atoi(DOMAIN_IP) == 0) { struct hostent* pHostInfo; @@ -230,26 +232,23 @@ void NodeList::sendDomainServerCheckIn() { } else { printLog("Failed domain server lookup\n"); } - } else if (!printedDomainServerIP) { + } else if (!_printedDomainServerIP) { printLog("Domain Server IP: %s\n", DOMAIN_IP); - printedDomainServerIP = true; + _printedDomainServerIP = true; } - // construct the DS check in packet if we need to - static unsigned char* checkInPacket = NULL; - static int checkInPacketSize = 0; - - const int IP_ADDRESS_BYTES = 4; - - if (!checkInPacket) { + // construct the DS check in packet if we need to + if (!_checkInPacket) { int numBytesNodesOfInterest = _nodeTypesOfInterest ? strlen((char*) _nodeTypesOfInterest) : 0; + const int IP_ADDRESS_BYTES = 4; + // check in packet has header, node type, port, IP, node types of interest, null termination int numPacketBytes = sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION) + sizeof(NODE_TYPE) + sizeof(uint16_t) + IP_ADDRESS_BYTES + numBytesNodesOfInterest + sizeof(unsigned char); - checkInPacket = new unsigned char[numPacketBytes]; - unsigned char* packetPosition = checkInPacket; + _checkInPacket = new unsigned char[numPacketBytes]; + unsigned char* packetPosition = _checkInPacket; PACKET_TYPE nodePacketType = (memchr(SOLO_NODE_TYPES, _ownerType, sizeof(SOLO_NODE_TYPES))) ? PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY @@ -260,7 +259,7 @@ void NodeList::sendDomainServerCheckIn() { *(packetPosition++) = _ownerType; - packetPosition += packSocket(checkInPacket + numHeaderBytes + sizeof(NODE_TYPE), + packetPosition += packSocket(_checkInPacket + numHeaderBytes + sizeof(NODE_TYPE), getLocalAddress(), htons(_nodeSocket.getListeningPort())); @@ -275,7 +274,7 @@ void NodeList::sendDomainServerCheckIn() { packetPosition += numBytesNodesOfInterest; } - checkInPacketSize = packetPosition - checkInPacket; + _checkInPacketSize = packetPosition - _checkInPacket; } _nodeSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, checkInPacket, checkInPacketSize); diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index da9c4a556a..6f4249f33b 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -113,6 +113,10 @@ private: pthread_t checkInWithDomainServerThread; pthread_mutex_t mutex; + bool _printedDomainServerIP; + unsigned char* _checkInPacket; + int _checkInPacketSize; + void handlePingReply(sockaddr *nodeAddress); void timePingReply(sockaddr *nodeAddress, unsigned char *packetData); }; From 66a998e75224dd619dcc2d2059501cb7f597d73d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Jul 2013 13:05:15 -0700 Subject: [PATCH 7/7] correct use of member variables for DS check in --- libraries/shared/src/NodeList.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index ee5e44596e..445b1f7699 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -277,7 +277,7 @@ void NodeList::sendDomainServerCheckIn() { _checkInPacketSize = packetPosition - _checkInPacket; } - _nodeSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, checkInPacket, checkInPacketSize); + _nodeSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, _checkInPacket, _checkInPacketSize); } int NodeList::processDomainServerList(unsigned char* packetData, size_t dataBytes) {