use abstracted DS check in method from AgentList

This commit is contained in:
Stephen Birarda 2013-03-25 16:24:14 -07:00
parent c8190b95aa
commit 507b6e0064
4 changed files with 19 additions and 169 deletions

View file

@ -45,7 +45,7 @@ const int LOGOFF_CHECK_INTERVAL = 5000;
#define DEBUG_TO_SELF 0
int lastActiveCount = 0;
AgentList agentList(DOMAIN_LISTEN_PORT);
AgentList agentList('D', DOMAIN_LISTEN_PORT);
unsigned char * addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) {
*currentPosition++ = agentToAdd->getType();
@ -74,6 +74,8 @@ int main(int argc, const char * argv[])
sockaddr_in agentPublicAddress, agentLocalAddress;
agentLocalAddress.sin_family = AF_INET;
in_addr_t serverLocalAddress = getLocalAddress();
agentList.startSilentAgentRemovalThread();
while (true) {
@ -83,6 +85,13 @@ int main(int argc, const char * argv[])
agentType = packetData[0];
unpackSocket(&packetData[1], (sockaddr *)&agentLocalAddress);
// check the agent public address
// if it matches our local address we're on the same box
// so hardcode the EC2 public address for now
if (agentPublicAddress.sin_addr.s_addr == serverLocalAddress) {
agentPublicAddress.sin_addr.s_addr = 895283510;
}
agentList.addOrUpdateAgent((sockaddr *)&agentPublicAddress, (sockaddr *)&agentLocalAddress, agentType);
currentBufferPos = broadcastPacket + 1;

View file

@ -46,7 +46,7 @@
#include "Particle.h"
#include "Texture.h"
#include "Cloud.h"
#include "AgentList.h"
#include <AgentList.h>
#include "VoxelSystem.h"
#include "Lattice.h"
#include "Finger.h"
@ -64,11 +64,7 @@ int simulate_on = 1;
// Network Socket and network constants
//
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
char DOMAIN_IP[100] = ""; // IP Address will be used first if not empty string
const int DOMAINSERVER_PORT = 40102;
AgentList agentList;
AgentList agentList('I');
pthread_t networkReceiveThread;
bool stopNetworkReceiveThread = false;
@ -89,14 +85,11 @@ int WIDTH = 1200;
int HEIGHT = 800;
int fullscreen = 0;
in_addr_t localAddress;
Oscilloscope audioScope(256,200,true);
#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you
Head myHead; // The rendered head of oneself
glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE);
ParticleSystem balls(0,
box,
@ -227,15 +220,6 @@ void Timer(int extra)
glutTimerFunc(1000,Timer,0);
gettimeofday(&timer_start, NULL);
//
// Send a message to the domainserver telling it we are ALIVE
//
unsigned char output[7];
output[0] = 'I';
packSocket(output + 1, localAddress, htons(AGENT_SOCKET_LISTEN_PORT));
agentList.getAgentSocket().send(DOMAIN_IP, DOMAINSERVER_PORT, output, 7);
// Ping the agents we can see
agentList.pingAgents();
@ -948,43 +932,17 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) {
int main(int argc, char** argv)
{
#ifndef _WIN32
struct ifaddrs * ifAddrStruct=NULL;
struct ifaddrs * ifa=NULL;
getifaddrs(&ifAddrStruct);
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa ->ifa_addr->sa_family==AF_INET) { // check it is IP4
// is a valid IP4 Address
localAddress = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
}
}
#endif
// Lookup the IP address of things we have hostnames
if (atoi(DOMAIN_IP) == 0) {
struct hostent* pHostInfo;
if ((pHostInfo = gethostbyname(DOMAIN_HOSTNAME)) != NULL) {
sockaddr_in tempAddress;
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr));
printf("Domain server %s: %s\n", DOMAIN_HOSTNAME, DOMAIN_IP);
} else {
printf("Failed lookup domainserver\n");
}
} else printf("Using static domainserver IP: %s\n", DOMAIN_IP);
// the callback for our instance of AgentList is attachNewHeadToAgent
agentList.linkedDataCreateCallback = &attachNewHeadToAgent;
#ifndef _WIN32
agentList.audioMixerSocketUpdate = &audioMixerUpdate;
#endif
// start the thread which checks for silent agents
agentList.startSilentAgentRemovalThread();
agentList.startDomainServerCheckInThread();
#ifdef _WIN32
WSADATA WsaData;
int wsaresult = WSAStartup( MAKEWORD(2,2), &WsaData );

View file

@ -53,11 +53,7 @@ const int AGENT_LOOPBACK_MODIFIER = 307;
const int LOOPBACK_SANITY_CHECK = 0;
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup
const int DOMAINSERVER_PORT = 40102;
AgentList agentList(MIXER_LISTEN_PORT);
AgentList agentList('M', MIXER_LISTEN_PORT);
StDev stdev;
void plateauAdditionOfSamples(int16_t &mixSample, int16_t sampleToAdd) {
@ -235,29 +231,6 @@ void *sendBuffer(void *args)
pthread_exit(0);
}
void *reportAliveToDS(void *args) {
timeval lastSend;
unsigned char output[7];
while (true) {
gettimeofday(&lastSend, NULL);
*output = 'M';
packSocket(output + 1, 895283510, htons(MIXER_LISTEN_PORT));
// packSocket(output + 1, 788637888, htons(MIXER_LISTEN_PORT));
agentList.getAgentSocket().send(DOMAIN_IP, DOMAINSERVER_PORT, output, 7);
double usecToSleep = 1000000 - (usecTimestampNow() - usecTimestamp(&lastSend));
if (usecToSleep > 0) {
usleep(usecToSleep);
} else {
std::cout << "No sleep required!";
}
}
}
void attachNewBufferToAgent(Agent *newAgent) {
if (newAgent->getLinkedData() == NULL) {
newAgent->setLinkedData(new AudioRingBuffer(RING_BUFFER_SAMPLES, BUFFER_LENGTH_SAMPLES_PER_CHANNEL));
@ -273,26 +246,7 @@ int main(int argc, const char * argv[])
agentList.linkedDataCreateCallback = attachNewBufferToAgent;
agentList.startSilentAgentRemovalThread();
// Lookup the IP address of things we have hostnames
if (atoi(DOMAIN_IP) == 0) {
struct hostent* pHostInfo;
if ((pHostInfo = gethostbyname(DOMAIN_HOSTNAME)) != NULL) {
sockaddr_in tempAddress;
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr));
printf("Domain server %s: %s\n", DOMAIN_HOSTNAME, DOMAIN_IP);
} else {
printf("Failed lookup domainserver\n");
}
} else {
printf("Using static domainserver IP: %s\n", DOMAIN_IP);
}
// setup the agentSocket to report to domain server
pthread_t reportAliveThread;
pthread_create(&reportAliveThread, NULL, reportAliveToDS, NULL);
agentList.startDomainServerCheckInThread();
unsigned char *packetData = new unsigned char[MAX_PACKET_SIZE];
@ -342,8 +296,6 @@ int main(int argc, const char * argv[])
}
}
agentList.stopSilentAgentRemovalThread();
pthread_join(reportAliveThread, NULL);
pthread_join(sendBufferThread, NULL);
return 0;

View file

@ -39,41 +39,9 @@ const int MIN_BRIGHTNESS = 64;
const float DEATH_STAR_RADIUS = 4.0;
const float MAX_CUBE = 0.05f;
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup
const int DOMAINSERVER_PORT = 40102;
const int MAX_VOXEL_TREE_DEPTH_LEVELS = 10;
AgentList agentList(VOXEL_LISTEN_PORT);
in_addr_t localAddress;
void *reportAliveToDS(void *args) {
timeval lastSend;
unsigned char output[7];
while (true) {
gettimeofday(&lastSend, NULL);
*output = 'V';
packSocket(output + 1, 895283510, htons(VOXEL_LISTEN_PORT));
// packSocket(output + 1, 788637888, htons(VOXEL_LISTEN_PORT));
agentList.getAgentSocket().send(DOMAIN_IP, DOMAINSERVER_PORT, output, 7);
double usecToSleep = 1000000 - (usecTimestampNow() - usecTimestamp(&lastSend));
if (usecToSleep > 0) {
#ifdef _WIN32
Sleep( static_cast<int>(1000.0f*usecToSleep) );
#else
usleep(usecToSleep);
#endif
} else {
std::cout << "No sleep required!";
}
}
}
AgentList agentList('V', VOXEL_LISTEN_PORT);
int randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
// randomly generate children for this node
@ -142,43 +110,9 @@ int main(int argc, const char * argv[])
{
setvbuf(stdout, NULL, _IOLBF, 0);
#ifndef _WIN32
// get the local address of the voxel server
struct ifaddrs * ifAddrStruct=NULL;
struct ifaddrs * ifa=NULL;
getifaddrs(&ifAddrStruct);
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa ->ifa_addr->sa_family==AF_INET) { // check it is IP4
// is a valid IP4 Address
localAddress = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
}
}
#endif
// Lookup the IP address of things we have hostnames
if (atoi(DOMAIN_IP) == 0) {
struct hostent* pHostInfo;
if ((pHostInfo = gethostbyname(DOMAIN_HOSTNAME)) != NULL) {
sockaddr_in tempAddress;
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr));
printf("Domain server %s: %s\n", DOMAIN_HOSTNAME, DOMAIN_IP);
} else {
printf("Failed lookup domainserver\n");
}
} else {
printf("Using static domainserver IP: %s\n", DOMAIN_IP);
}
// setup the agentSocket to report to domain server
pthread_t reportAliveThread;
pthread_create(&reportAliveThread, NULL, reportAliveToDS, NULL);
agentList.linkedDataCreateCallback = &attachVoxelAgentDataToAgent;
agentList.startSilentAgentRemovalThread();
agentList.startDomainServerCheckInThread();
srand((unsigned)time(0));
@ -245,8 +179,5 @@ int main(int argc, const char * argv[])
}
}
pthread_join(reportAliveThread, NULL);
agentList.stopSilentAgentRemovalThread();
return 0;
}