diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 689acacddb..3ef424b5c0 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -167,68 +167,71 @@ int main(int argc, char* const argv[]) { nodeType, nodeList->getLastNodeID()); - if (newNode->getNodeID() == nodeList->getLastNodeID()) { - nodeList->increaseNodeID(); - } - - currentBufferPos = broadcastPacket + numHeaderBytes; - startPointer = currentBufferPos; - - unsigned char* nodeTypesOfInterest = packetData + numBytesSenderHeader + sizeof(NODE_TYPE) + // if addOrUpdateNode returns NULL this was a solo node we already have, don't talk back to it + if (newNode) { + if (newNode->getNodeID() == nodeList->getLastNodeID()) { + nodeList->increaseNodeID(); + } + + currentBufferPos = broadcastPacket + numHeaderBytes; + startPointer = currentBufferPos; + + unsigned char* nodeTypesOfInterest = packetData + numBytesSenderHeader + sizeof(NODE_TYPE) + numBytesSocket + sizeof(unsigned char); - int numInterestTypes = *(nodeTypesOfInterest - 1); - - if (numInterestTypes > 0) { - // if the node has sent no types of interest, assume they want nothing but their own ID back - for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { - if (!node->matches((sockaddr*) &nodePublicAddress, (sockaddr*) &nodeLocalAddress, nodeType) && + int numInterestTypes = *(nodeTypesOfInterest - 1); + + if (numInterestTypes > 0) { + // if the node has sent no types of interest, assume they want nothing but their own ID back + for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { + if (!node->matches((sockaddr*) &nodePublicAddress, (sockaddr*) &nodeLocalAddress, nodeType) && memchr(nodeTypesOfInterest, node->getType(), numInterestTypes)) { - // this is not the node themselves - // and this is an node of a type in the passed node types of interest - // or the node did not pass us any specific types they are interested in - - if (memchr(SOLO_NODE_TYPES, node->getType(), sizeof(SOLO_NODE_TYPES)) == NULL) { - // this is an node of which there can be multiple, just add them to the packet - // don't send avatar nodes to other avatars, that will come from avatar mixer - if (nodeType != NODE_TYPE_AGENT || node->getType() != NODE_TYPE_AGENT) { - currentBufferPos = addNodeToBroadcastPacket(currentBufferPos, &(*node)); - } - - } else { - // solo node, we need to only send newest - if (newestSoloNodes[node->getType()] == NULL || - newestSoloNodes[node->getType()]->getWakeMicrostamp() < node->getWakeMicrostamp()) { - // we have to set the newer solo node to add it to the broadcast later - newestSoloNodes[node->getType()] = &(*node); + // this is not the node themselves + // and this is an node of a type in the passed node types of interest + // or the node did not pass us any specific types they are interested in + + if (memchr(SOLO_NODE_TYPES, node->getType(), sizeof(SOLO_NODE_TYPES)) == NULL) { + // this is an node of which there can be multiple, just add them to the packet + // don't send avatar nodes to other avatars, that will come from avatar mixer + if (nodeType != NODE_TYPE_AGENT || node->getType() != NODE_TYPE_AGENT) { + currentBufferPos = addNodeToBroadcastPacket(currentBufferPos, &(*node)); + } + + } else { + // solo node, we need to only send newest + if (newestSoloNodes[node->getType()] == NULL || + newestSoloNodes[node->getType()]->getWakeMicrostamp() < node->getWakeMicrostamp()) { + // we have to set the newer solo node to add it to the broadcast later + newestSoloNodes[node->getType()] = &(*node); + } } } } + + for (std::map::iterator soloNode = newestSoloNodes.begin(); + soloNode != newestSoloNodes.end(); + soloNode++) { + // this is the newest alive solo node, add them to the packet + currentBufferPos = addNodeToBroadcastPacket(currentBufferPos, soloNode->second); + } } - for (std::map::iterator soloNode = newestSoloNodes.begin(); - soloNode != newestSoloNodes.end(); - soloNode++) { - // this is the newest alive solo node, add them to the packet - currentBufferPos = addNodeToBroadcastPacket(currentBufferPos, soloNode->second); + // update last receive to now + uint64_t timeNow = usecTimestampNow(); + newNode->setLastHeardMicrostamp(timeNow); + + if (packetData[0] == PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY + && memchr(SOLO_NODE_TYPES, nodeType, sizeof(SOLO_NODE_TYPES))) { + newNode->setWakeMicrostamp(timeNow); } + + // add the node ID to the end of the pointer + currentBufferPos += packNodeId(currentBufferPos, newNode->getNodeID()); + + // send the constructed list back to this node + nodeList->getNodeSocket()->send(destinationSocket, + broadcastPacket, + (currentBufferPos - startPointer) + numHeaderBytes); } - - // update last receive to now - uint64_t timeNow = usecTimestampNow(); - newNode->setLastHeardMicrostamp(timeNow); - - if (packetData[0] == PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY - && memchr(SOLO_NODE_TYPES, nodeType, sizeof(SOLO_NODE_TYPES))) { - newNode->setWakeMicrostamp(timeNow); - } - - // add the node ID to the end of the pointer - currentBufferPos += packNodeId(currentBufferPos, newNode->getNodeID()); - - // send the constructed list back to this node - nodeList->getNodeSocket()->send(destinationSocket, - broadcastPacket, - (currentBufferPos - startPointer) + numHeaderBytes); } if (Logstash::shouldSendStats()) { diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index aed979c8ec..7565873bc5 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -394,9 +394,14 @@ Node* NodeList::addOrUpdateNode(sockaddr* publicSocket, sockaddr* localSocket, c break; } } - } + } if (node == end()) { + // if we already had this node AND it's a solo type then bust out of here + if (soloNodeOfType(nodeType)) { + return NULL; + } + // we didn't have this node, so add them Node* newNode = new Node(publicSocket, localSocket, nodeType, nodeId);