don’t have AvatarMixer ask DS for agents

This commit is contained in:
Stephen Birarda 2013-10-08 11:07:46 -07:00
parent 2013f9f051
commit 6fe0b0b124
4 changed files with 20 additions and 11 deletions

View file

@ -98,7 +98,7 @@ void AvatarMixer::run() {
nodeList->startSilentNodeRemovalThread(); nodeList->startSilentNodeRemovalThread();
sockaddr* nodeAddress = new sockaddr; sockaddr nodeAddress = {};
ssize_t receivedBytes = 0; ssize_t receivedBytes = 0;
unsigned char* packetData = new unsigned char[MAX_PACKET_SIZE]; unsigned char* packetData = new unsigned char[MAX_PACKET_SIZE];
@ -107,8 +107,6 @@ void AvatarMixer::run() {
Node* avatarNode = NULL; Node* avatarNode = NULL;
timeval lastDomainServerCheckIn = {}; timeval lastDomainServerCheckIn = {};
// we only need to hear back about avatar nodes from the DS
nodeList->setNodeTypesOfInterest(&NODE_TYPE_AGENT, 1);
while (true) { while (true) {
@ -122,7 +120,7 @@ void AvatarMixer::run() {
NodeList::getInstance()->sendDomainServerCheckIn(_uuid.toRfc4122().constData()); NodeList::getInstance()->sendDomainServerCheckIn(_uuid.toRfc4122().constData());
} }
if (nodeList->getNodeSocket()->receive(nodeAddress, packetData, &receivedBytes) && if (nodeList->getNodeSocket()->receive(&nodeAddress, packetData, &receivedBytes) &&
packetVersionMatch(packetData)) { packetVersionMatch(packetData)) {
switch (packetData[0]) { switch (packetData[0]) {
case PACKET_TYPE_HEAD_DATA: case PACKET_TYPE_HEAD_DATA:
@ -130,12 +128,12 @@ void AvatarMixer::run() {
unpackNodeId(packetData + numBytesForPacketHeader(packetData), &nodeID); unpackNodeId(packetData + numBytesForPacketHeader(packetData), &nodeID);
// add or update the node in our list // add or update the node in our list
avatarNode = nodeList->addOrUpdateNode(nodeAddress, nodeAddress, NODE_TYPE_AGENT, nodeID); avatarNode = nodeList->addOrUpdateNode(&nodeAddress, &nodeAddress, NODE_TYPE_AGENT, nodeID);
// parse positional data from an node // parse positional data from an node
nodeList->updateNodeWithData(avatarNode, packetData, receivedBytes); nodeList->updateNodeWithData(avatarNode, packetData, receivedBytes);
case PACKET_TYPE_INJECT_AUDIO: case PACKET_TYPE_INJECT_AUDIO:
broadcastAvatarData(nodeList, nodeAddress); broadcastAvatarData(nodeList, &nodeAddress);
break; break;
case PACKET_TYPE_AVATAR_URLS: case PACKET_TYPE_AVATAR_URLS:
case PACKET_TYPE_AVATAR_FACE_VIDEO: case PACKET_TYPE_AVATAR_FACE_VIDEO:
@ -151,7 +149,7 @@ void AvatarMixer::run() {
break; break;
default: default:
// hand this off to the NodeList // hand this off to the NodeList
nodeList->processNodeData(nodeAddress, packetData, receivedBytes); nodeList->processNodeData(&nodeAddress, packetData, receivedBytes);
break; break;
} }
} }

View file

@ -428,18 +428,23 @@ void NodeList::sendAssignment(Assignment& assignment) {
} }
Node* NodeList::addOrUpdateNode(sockaddr* publicSocket, sockaddr* localSocket, char nodeType, uint16_t nodeId) { Node* NodeList::addOrUpdateNode(sockaddr* publicSocket, sockaddr* localSocket, char nodeType, uint16_t nodeId) {
qDebug() << "BEGIN:" << publicSocket << "and" << localSocket << "\n";
NodeList::iterator node = end(); NodeList::iterator node = end();
if (publicSocket) { if (publicSocket) {
for (node = begin(); node != end(); node++) { for (node = begin(); node != end(); node++) {
qDebug() << "comparing to node with ID " << node->getNodeID() << "\n";
if (node->matches(publicSocket, localSocket, nodeType)) { if (node->matches(publicSocket, localSocket, nodeType)) {
// we already have this node, stop checking // we already have this node, stop checking
qDebug() << "Matched node to existing\n";
break; break;
} }
} }
} }
if (node == end()) { if (node == end()) {
qDebug() << "We're considering this a new node!\n";
qDebug() << publicSocket << "and" << localSocket << "\n";
// we didn't have this node, so add them // we didn't have this node, so add them
Node* newNode = new Node(publicSocket, localSocket, nodeType, nodeId); Node* newNode = new Node(publicSocket, localSocket, nodeType, nodeId);
@ -540,6 +545,10 @@ void* removeSilentNodes(void *args) {
for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) { for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) {
node->lock();
qDebug() << "This node's LHMS is" << node->getLastHeardMicrostamp() << "\n";
if ((checkTimeUSecs - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) { if ((checkTimeUSecs - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) {
qDebug() << "Killed " << *node << "\n"; qDebug() << "Killed " << *node << "\n";
@ -548,6 +557,8 @@ void* removeSilentNodes(void *args) {
node->setAlive(false); node->setAlive(false);
} }
node->unlock();
} }
sleepTime = NODE_SILENCE_THRESHOLD_USECS - (usecTimestampNow() - checkTimeUSecs); sleepTime = NODE_SILENCE_THRESHOLD_USECS - (usecTimestampNow() - checkTimeUSecs);

View file

@ -30,7 +30,7 @@ const int NODES_PER_BUCKET = 100;
const int MAX_PACKET_SIZE = 1500; const int MAX_PACKET_SIZE = 1500;
const int NODE_SILENCE_THRESHOLD_USECS = 2 * 1000000; const uint64_t NODE_SILENCE_THRESHOLD_USECS = 2 * 1000000;
const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000; const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000;
extern const char SOLO_NODE_TYPES[2]; extern const char SOLO_NODE_TYPES[2];

View file

@ -254,7 +254,7 @@ bool UDPSocket::receive(sockaddr* recvAddress, void* receivedData, ssize_t* rece
#ifdef _WIN32 #ifdef _WIN32
int addressSize = sizeof(*recvAddress); int addressSize = sizeof(*recvAddress);
#else #else
socklen_t addressSize = sizeof(&recvAddress); socklen_t addressSize = sizeof(*recvAddress);
#endif #endif
*receivedBytes = recvfrom(handle, static_cast<char*>(receivedData), MAX_BUFFER_LENGTH_BYTES, *receivedBytes = recvfrom(handle, static_cast<char*>(receivedData), MAX_BUFFER_LENGTH_BYTES,
0, recvAddress, &addressSize); 0, recvAddress, &addressSize);