From 6a16d6e3bb6bec237308c167ff1fd174181bb7a7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 22 Feb 2013 14:54:19 -0800 Subject: [PATCH] clean up agent killing/re-adding for interface and domain --- domain/src/main.cpp | 44 +++++++++++++++++++++++----------------- interface/src/main.cpp | 2 +- shared/src/Agent.cpp | 1 + shared/src/AgentList.cpp | 10 +++++++-- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/domain/src/main.cpp b/domain/src/main.cpp index 4784a72ac0..faa15bd095 100644 --- a/domain/src/main.cpp +++ b/domain/src/main.cpp @@ -28,6 +28,7 @@ #include #include #include "AgentList.h" +#include "SharedUtil.h" const int DOMAIN_LISTEN_PORT = 40102; @@ -41,30 +42,19 @@ const int LOGOFF_CHECK_INTERVAL = 5000; int lastActiveCount = 0; AgentList agentList(DOMAIN_LISTEN_PORT); -int listForBroadcast(unsigned char *listBuffer, sockaddr *agentPublicAddress, sockaddr *agentLocalAddress, char agentType) { - unsigned char *currentBufferPos = listBuffer + 1; - unsigned char *startPointer = currentBufferPos; - - for(std::vector::iterator agent = agentList.agents.begin(); agent != agentList.agents.end(); agent++) { - - if (DEBUG_TO_SELF || !agent->matches(agentPublicAddress, agentLocalAddress, agentType)) { - *currentBufferPos++ = agent->type; - - currentBufferPos += packSocket(currentBufferPos, agent->publicSocket); - currentBufferPos += packSocket(currentBufferPos, agent->localSocket); - } - } - - return 1 + (currentBufferPos - startPointer); // 1 is added for the leading 'D' -} int main(int argc, const char * argv[]) { ssize_t receivedBytes = 0; char agentType; + unsigned char *broadcastPacket = new unsigned char[MAX_PACKET_SIZE]; *broadcastPacket = 'D'; + unsigned char *currentBufferPos; + unsigned char *startPointer; + int packetBytesWithoutLeadingChar; + sockaddr_in agentPublicAddress, agentLocalAddress; agentLocalAddress.sin_family = AF_INET; @@ -77,10 +67,26 @@ int main(int argc, const char * argv[]) agentList.addOrUpdateAgent((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType); - int listBytes = listForBroadcast(broadcastPacket, (sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType); + currentBufferPos = broadcastPacket + 1; + startPointer = currentBufferPos; - if (listBytes > 0) { - agentList.getAgentSocket()->send((sockaddr *)&agentPublicAddress, broadcastPacket, listBytes); + for(std::vector::iterator agent = agentList.agents.begin(); agent != agentList.agents.end(); agent++) { + + if (DEBUG_TO_SELF || !agent->matches((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType)) { + *currentBufferPos++ = agent->type; + + currentBufferPos += packSocket(currentBufferPos, agent->publicSocket); + currentBufferPos += packSocket(currentBufferPos, agent->localSocket); + } else { + // this is the agent, just update last receive to now + agent->lastRecvTimeUsecs = usecTimestampNow(); + } + } + + ; + + if ((packetBytesWithoutLeadingChar = (currentBufferPos - startPointer))) { + agentList.getAgentSocket()->send((sockaddr *)&agentPublicAddress, broadcastPacket, packetBytesWithoutLeadingChar); } } } diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 7ff9b91301..9d7b4a2853 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -55,7 +55,7 @@ int simulate_on = 1; const int MAX_PACKET_SIZE = 1500; char DOMAIN_HOSTNAME[] = "highfidelity.below92.com"; -char DOMAIN_IP[100] = ""; // IP Address will be used first if not empty string +char DOMAIN_IP[100] = "192.168.1.47"; // IP Address will be used first if not empty string const int DOMAINSERVER_PORT = 40102; AgentList agentList; diff --git a/shared/src/Agent.cpp b/shared/src/Agent.cpp index a8a6984a09..5b48033225 100644 --- a/shared/src/Agent.cpp +++ b/shared/src/Agent.cpp @@ -43,6 +43,7 @@ Agent::Agent(const Agent &otherAgent) { activeSocket = NULL; } + lastRecvTimeUsecs = otherAgent.lastRecvTimeUsecs; type = otherAgent.type; // linked data is transient, gets re-assigned on next packet receive diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index d743353820..d068ab15fc 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -153,8 +153,14 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, return true; } else { - // we had this agent already, just update receive timestamp - agent->lastRecvTimeUsecs = usecTimestampNow(); + + if (agent->type == 'M') { + // until the Audio class also uses our agentList, we need to update + // the lastRecvTimeUsecs for the audio mixer so it doesn't get killed and re-added continously + agent->lastRecvTimeUsecs = usecTimestampNow(); + } + + // we had this agent already, do nothing for now return false; } }