mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
implement pingAgents method in AgentList
This commit is contained in:
parent
9a514f56e5
commit
42927ec602
4 changed files with 31 additions and 5 deletions
|
@ -229,7 +229,7 @@ void Timer(int extra)
|
|||
agentList.getAgentSocket()->send(DOMAIN_IP, DOMAINSERVER_PORT, output, packet_size);
|
||||
|
||||
// Ping the agents we can see
|
||||
// pingAgents(&agentSocket);
|
||||
agentList.pingAgents();
|
||||
|
||||
if (0) {
|
||||
// Massive send packet speed test
|
||||
|
|
|
@ -34,18 +34,19 @@ int AgentList::updateList(char *packetData) {
|
|||
&agentLocalSocket.port
|
||||
))) {
|
||||
|
||||
std::vector<Agent>::iterator it;
|
||||
std::vector<Agent>::iterator agent;
|
||||
|
||||
for(it = agents.begin(); it != agents.end(); ++it) {
|
||||
if (it->matches(&agentPublicSocket, &agentLocalSocket, agentType)) {
|
||||
for(agent = agents.begin(); agent != agents.end(); agent++) {
|
||||
if (agent->matches(&agentPublicSocket, &agentLocalSocket, agentType)) {
|
||||
// we already have this agent, stop checking
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (it == agents.end()) {
|
||||
if (agent == agents.end()) {
|
||||
// we didn't have this agent, so add them
|
||||
newAgent = Agent(&agentPublicSocket, &agentLocalSocket, agentType);
|
||||
std::cout << "Added new agent - PS: " << agentPublicSocket << " LS: " << agentLocalSocket << " AT: " << agentType << "\n";
|
||||
agents.push_back(newAgent);
|
||||
} else {
|
||||
// we had this agent already, don't do anything
|
||||
|
@ -55,4 +56,20 @@ int AgentList::updateList(char *packetData) {
|
|||
}
|
||||
|
||||
return readAgents;
|
||||
}
|
||||
|
||||
void AgentList::pingAgents() {
|
||||
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
||||
char payload[] = "P";
|
||||
|
||||
if (agent->activeSocket != NULL) {
|
||||
// we know which socket is good for this agent, send there
|
||||
agentSocket.send(agent->activeSocket, payload, 1);
|
||||
} else {
|
||||
// ping both of the sockets for the agent so we can figure out
|
||||
// which socket we can use
|
||||
agentSocket.send(agent->publicSocket, payload, 1);
|
||||
agentSocket.send(agent->localSocket, payload, 1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -84,3 +84,10 @@ int UDPSocket::send(char * destAddress, int destPort, const void *data, size_t b
|
|||
|
||||
return send(&destSockaddr, data, byteLength);
|
||||
}
|
||||
|
||||
int UDPSocket::send(AgentSocket *destAgentSocket, const void *data, size_t byteLength) {
|
||||
destSockaddr.sin_addr.s_addr = inet_addr(destAgentSocket->address);
|
||||
destSockaddr.sin_port = htons(destAgentSocket->port);
|
||||
|
||||
return send(&destSockaddr, data, byteLength);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <iostream>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include "AgentSocket.h"
|
||||
|
||||
#define MAX_BUFFER_LENGTH_BYTES 1024
|
||||
|
||||
|
@ -21,6 +22,7 @@ class UDPSocket {
|
|||
~UDPSocket();
|
||||
int send(sockaddr_in *destAddress, const void *data, size_t byteLength);
|
||||
int send(char *destAddress, int destPort, const void *data, size_t byteLength);
|
||||
int send(AgentSocket *destAgentSocket, const void *data, size_t byteLength);
|
||||
bool receive(void *receivedData, ssize_t *receivedBytes);
|
||||
bool receive(sockaddr_in *recvAddress, void *receivedData, ssize_t *receivedBytes);
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue