mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 07:37:31 +02:00
domain server only returns newest of types in SOLO_AGENT_TYPES_STRING
This commit is contained in:
parent
d272a7de31
commit
72ddc78ad6
5 changed files with 38 additions and 5 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <map>
|
||||||
#include "AgentList.h"
|
#include "AgentList.h"
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
|
||||||
|
@ -42,6 +43,15 @@ const int LOGOFF_CHECK_INTERVAL = 5000;
|
||||||
int lastActiveCount = 0;
|
int lastActiveCount = 0;
|
||||||
AgentList agentList(DOMAIN_LISTEN_PORT);
|
AgentList agentList(DOMAIN_LISTEN_PORT);
|
||||||
|
|
||||||
|
unsigned char * addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) {
|
||||||
|
*currentPosition++ = agentToAdd->type;
|
||||||
|
|
||||||
|
currentPosition += packSocket(currentPosition, agentToAdd->publicSocket);
|
||||||
|
currentPosition += packSocket(currentPosition, agentToAdd->localSocket);
|
||||||
|
|
||||||
|
// return the new unsigned char * for broadcast packet
|
||||||
|
return currentPosition;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, const char * argv[])
|
int main(int argc, const char * argv[])
|
||||||
{
|
{
|
||||||
|
@ -60,6 +70,8 @@ int main(int argc, const char * argv[])
|
||||||
|
|
||||||
agentList.startSilentAgentRemovalThread();
|
agentList.startSilentAgentRemovalThread();
|
||||||
|
|
||||||
|
std::map<char, Agent *> newestSoloAgents;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (agentList.getAgentSocket()->receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes)) {
|
if (agentList.getAgentSocket()->receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes)) {
|
||||||
agentType = packetData[0];
|
agentType = packetData[0];
|
||||||
|
@ -73,17 +85,31 @@ int main(int argc, const char * argv[])
|
||||||
for(std::vector<Agent>::iterator agent = agentList.agents.begin(); agent != agentList.agents.end(); agent++) {
|
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)) {
|
if (DEBUG_TO_SELF || !agent->matches((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType)) {
|
||||||
*currentBufferPos++ = agent->type;
|
if (strchr(SOLO_AGENT_TYPES_STRING, (int) agent->type) == NULL) {
|
||||||
|
// this is an agent of which there can be multiple, just add them to the packet
|
||||||
currentBufferPos += packSocket(currentBufferPos, agent->publicSocket);
|
currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent));
|
||||||
currentBufferPos += packSocket(currentBufferPos, agent->localSocket);
|
} else {
|
||||||
|
std::cout << "We have a solo agent: " << &(*agent) << "\n";
|
||||||
|
// solo agent, we need to only send newest
|
||||||
|
if (newestSoloAgents[agent->type] == NULL ||
|
||||||
|
newestSoloAgents[agent->type]->firstRecvTimeUsecs < agent->firstRecvTimeUsecs) {
|
||||||
|
// we have to set the newer solo agent to add it to the broadcast later
|
||||||
|
newestSoloAgents[agent->type] = &(*agent);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// this is the agent, just update last receive to now
|
// this is the agent, just update last receive to now
|
||||||
agent->lastRecvTimeUsecs = usecTimestampNow();
|
agent->lastRecvTimeUsecs = usecTimestampNow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
for (std::map<char, Agent *>::iterator agentIterator = newestSoloAgents.begin();
|
||||||
|
agentIterator != newestSoloAgents.end();
|
||||||
|
agentIterator++) {
|
||||||
|
std::cout << "Newest agent: " << agentIterator->second << "\n";
|
||||||
|
// this is the newest alive solo agent, add them to the packet
|
||||||
|
currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, agentIterator->second);
|
||||||
|
}
|
||||||
|
|
||||||
if ((packetBytesWithoutLeadingChar = (currentBufferPos - startPointer))) {
|
if ((packetBytesWithoutLeadingChar = (currentBufferPos - startPointer))) {
|
||||||
agentList.getAgentSocket()->send((sockaddr *)&agentPublicAddress, broadcastPacket, packetBytesWithoutLeadingChar + 1);
|
agentList.getAgentSocket()->send((sockaddr *)&agentPublicAddress, broadcastPacket, packetBytesWithoutLeadingChar + 1);
|
||||||
|
|
|
@ -22,6 +22,8 @@ Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agent
|
||||||
memcpy(localSocket, agentLocalSocket, sizeof(sockaddr));
|
memcpy(localSocket, agentLocalSocket, sizeof(sockaddr));
|
||||||
|
|
||||||
type = agentType;
|
type = agentType;
|
||||||
|
|
||||||
|
firstRecvTimeUsecs = usecTimestampNow();
|
||||||
lastRecvTimeUsecs = usecTimestampNow();
|
lastRecvTimeUsecs = usecTimestampNow();
|
||||||
|
|
||||||
activeSocket = NULL;
|
activeSocket = NULL;
|
||||||
|
@ -43,6 +45,7 @@ Agent::Agent(const Agent &otherAgent) {
|
||||||
activeSocket = NULL;
|
activeSocket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
firstRecvTimeUsecs = otherAgent.firstRecvTimeUsecs;
|
||||||
lastRecvTimeUsecs = otherAgent.lastRecvTimeUsecs;
|
lastRecvTimeUsecs = otherAgent.lastRecvTimeUsecs;
|
||||||
type = otherAgent.type;
|
type = otherAgent.type;
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ class Agent {
|
||||||
char type;
|
char type;
|
||||||
timeval pingStarted;
|
timeval pingStarted;
|
||||||
int pingMsecs;
|
int pingMsecs;
|
||||||
|
double firstRecvTimeUsecs;
|
||||||
double lastRecvTimeUsecs;
|
double lastRecvTimeUsecs;
|
||||||
bool isSelf;
|
bool isSelf;
|
||||||
AgentData *linkedData;
|
AgentData *linkedData;
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
|
||||||
|
const char * SOLO_AGENT_TYPES_STRING = "M";
|
||||||
|
|
||||||
bool stopAgentRemovalThread = false;
|
bool stopAgentRemovalThread = false;
|
||||||
pthread_mutex_t vectorChangeMutex = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t vectorChangeMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
const unsigned short AGENT_SOCKET_LISTEN_PORT = 40103;
|
const unsigned short AGENT_SOCKET_LISTEN_PORT = 40103;
|
||||||
const int AGENT_SILENCE_THRESHOLD_USECS = 2 * 1000000;
|
const int AGENT_SILENCE_THRESHOLD_USECS = 2 * 1000000;
|
||||||
|
extern const char *SOLO_AGENT_TYPES_STRINGg;
|
||||||
|
|
||||||
class AgentList {
|
class AgentList {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue