mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-15 21:18:06 +02:00
clean up agent killing/re-adding for interface and domain
This commit is contained in:
parent
9c60ac9918
commit
6a16d6e3bb
4 changed files with 35 additions and 22 deletions
|
@ -28,6 +28,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <sys/time.h>
|
||||
#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<Agent>::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<Agent>::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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue