mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-19 10:18:43 +02:00
Add unique id to agents and broadcast back
This commit is contained in:
parent
158270f20d
commit
9e0df2dbd1
5 changed files with 20 additions and 4 deletions
|
@ -44,6 +44,7 @@ AgentList agentList(DOMAIN_LISTEN_PORT);
|
|||
unsigned char * addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) {
|
||||
*currentPosition++ = agentToAdd->getType();
|
||||
|
||||
currentPosition += agentToAdd->getAgentId();
|
||||
currentPosition += packSocket(currentPosition, agentToAdd->getPublicSocket());
|
||||
currentPosition += packSocket(currentPosition, agentToAdd->getLocalSocket());
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
Agent::Agent() {}
|
||||
|
||||
Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType) {
|
||||
Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, int16_t thisAgentId) {
|
||||
publicSocket = new sockaddr;
|
||||
memcpy(publicSocket, agentPublicSocket, sizeof(sockaddr));
|
||||
|
||||
|
@ -22,6 +22,7 @@ Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agent
|
|||
memcpy(localSocket, agentLocalSocket, sizeof(sockaddr));
|
||||
|
||||
type = agentType;
|
||||
agentId = thisAgentId;
|
||||
|
||||
firstRecvTimeUsecs = usecTimestampNow();
|
||||
lastRecvTimeUsecs = usecTimestampNow();
|
||||
|
@ -75,6 +76,14 @@ void Agent::setType(char newType) {
|
|||
type = newType;
|
||||
}
|
||||
|
||||
int16_t Agent::getAgentId() {
|
||||
return agentId;
|
||||
}
|
||||
|
||||
void Agent::setAgentId(int16_t thisAgentId) {
|
||||
agentId = thisAgentId;
|
||||
}
|
||||
|
||||
double Agent::getFirstRecvTimeUsecs() {
|
||||
return firstRecvTimeUsecs;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
class Agent {
|
||||
public:
|
||||
Agent();
|
||||
Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType);
|
||||
Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, int16_t thisAgentId);
|
||||
Agent(const Agent &otherAgent);
|
||||
~Agent();
|
||||
Agent& operator=(Agent otherAgent);
|
||||
|
@ -25,6 +25,8 @@ class Agent {
|
|||
bool matches(sockaddr *otherPublicSocket, sockaddr *otherLocalSocket, char otherAgentType);
|
||||
char getType();
|
||||
void setType(char newType);
|
||||
int16_t getAgentId();
|
||||
void setAgentId(int16_t thisAgentId);
|
||||
double getFirstRecvTimeUsecs();
|
||||
void setFirstRecvTimeUsecs(double newTimeUsecs);
|
||||
double getLastRecvTimeUsecs();
|
||||
|
@ -44,6 +46,7 @@ class Agent {
|
|||
void swap(Agent &first, Agent &second);
|
||||
sockaddr *publicSocket, *localSocket, *activeSocket;
|
||||
char type;
|
||||
int16_t agentId;
|
||||
double firstRecvTimeUsecs;
|
||||
double lastRecvTimeUsecs;
|
||||
AgentData *linkedData;
|
||||
|
|
|
@ -20,12 +20,14 @@ AgentList::AgentList() : agentSocket(AGENT_SOCKET_LISTEN_PORT) {
|
|||
linkedDataCreateCallback = NULL;
|
||||
audioMixerSocketUpdate = NULL;
|
||||
voxelServerAddCallback = NULL;
|
||||
lastAgentId = 0;
|
||||
}
|
||||
|
||||
AgentList::AgentList(int socketListenPort) : agentSocket(socketListenPort) {
|
||||
linkedDataCreateCallback = NULL;
|
||||
audioMixerSocketUpdate = NULL;
|
||||
voxelServerAddCallback = NULL;
|
||||
lastAgentId = 0;
|
||||
}
|
||||
|
||||
AgentList::~AgentList() {
|
||||
|
@ -139,7 +141,8 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
|||
|
||||
if (agent == agents.end()) {
|
||||
// we didn't have this agent, so add them
|
||||
Agent newAgent = Agent(publicSocket, localSocket, agentType);
|
||||
Agent newAgent = Agent(publicSocket, localSocket, agentType, this->lastAgentId);
|
||||
++this->lastAgentId;
|
||||
|
||||
if (socketMatch(publicSocket, localSocket)) {
|
||||
// likely debugging scenario with DS + agent on local network
|
||||
|
|
|
@ -45,7 +45,7 @@ class AgentList {
|
|||
UDPSocket agentSocket;
|
||||
std::vector<Agent> agents;
|
||||
pthread_t removeSilentAgentsThread;
|
||||
|
||||
int16_t lastAgentId;
|
||||
int indexOfMatchingAgent(sockaddr *senderAddress);
|
||||
void handlePingReply(sockaddr *agentAddress);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue