mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 14:52:52 +02:00
allow forking of multiple assignment-clients from the main target
This commit is contained in:
parent
cbf8a2c202
commit
4905032090
4 changed files with 52 additions and 18 deletions
|
@ -18,13 +18,47 @@
|
||||||
|
|
||||||
const long long ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000;
|
const long long ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000;
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, const char* argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
|
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
|
|
||||||
|
sockaddr_in customAssignmentSocket = {};
|
||||||
|
|
||||||
|
// grab the overriden assignment-server hostname from argv, if it exists
|
||||||
|
const char* customAssignmentServer = getCmdOption(argc, argv, "-a");
|
||||||
|
if (customAssignmentServer) {
|
||||||
|
customAssignmentSocket = socketForHostnameAndHostOrderPort(customAssignmentServer, ASSIGNMENT_SERVER_PORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* NUM_FORKS_PARAMETER = "-n";
|
||||||
|
const char* numForksIncludingParentString = getCmdOption(argc, argv, NUM_FORKS_PARAMETER);
|
||||||
|
|
||||||
|
if (numForksIncludingParentString) {
|
||||||
|
int numForksIncludingParent = atoi(numForksIncludingParentString);
|
||||||
|
qDebug() << "Starting" << numForksIncludingParent << "assignment clients.";
|
||||||
|
|
||||||
|
int processID = 0;
|
||||||
|
|
||||||
|
// fire off as many children as we need (this is one less than the parent since the parent will run as well)
|
||||||
|
for (int i = 0; i < numForksIncludingParent - 1; i++) {
|
||||||
|
processID = fork();
|
||||||
|
|
||||||
|
if (processID == 0) {
|
||||||
|
// this is one of the children, break so we don't start a fork bomb
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create a NodeList as an unassigned client
|
// create a NodeList as an unassigned client
|
||||||
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_UNASSIGNED);
|
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_UNASSIGNED);
|
||||||
|
|
||||||
|
// set the custom assignment socket if we have it
|
||||||
|
if (customAssignmentSocket.sin_addr.s_addr != 0) {
|
||||||
|
nodeList->setAssignmentServerSocket((sockaddr*) &customAssignmentSocket);
|
||||||
|
}
|
||||||
|
|
||||||
// change the timeout on the nodelist socket to be as often as we want to re-request
|
// change the timeout on the nodelist socket to be as often as we want to re-request
|
||||||
nodeList->getNodeSocket()->setBlockingReceiveTimeoutInUsecs(ASSIGNMENT_REQUEST_INTERVAL_USECS);
|
nodeList->getNodeSocket()->setBlockingReceiveTimeoutInUsecs(ASSIGNMENT_REQUEST_INTERVAL_USECS);
|
||||||
|
|
||||||
|
@ -34,10 +68,8 @@ int main(int argc, const char* argv[]) {
|
||||||
ssize_t receivedBytes = 0;
|
ssize_t receivedBytes = 0;
|
||||||
|
|
||||||
// grab the assignment pool from argv, if it was passed
|
// grab the assignment pool from argv, if it was passed
|
||||||
const char* assignmentPool = getCmdOption(argc, argv, "-p");
|
const char* ASSIGNMENT_POOL_PARAMETER = "-p";
|
||||||
|
const char* assignmentPool = getCmdOption(argc, argv, ASSIGNMENT_POOL_PARAMETER);
|
||||||
// set the overriden assignment-server hostname from argv, if it exists
|
|
||||||
nodeList->setAssignmentServerHostname(getCmdOption(argc, argv, "-a"));
|
|
||||||
|
|
||||||
// create a request assignment, accept all assignments, pass the desired pool (if it exists)
|
// create a request assignment, accept all assignments, pass the desired pool (if it exists)
|
||||||
Assignment requestAssignment(Assignment::Request, Assignment::All, assignmentPool);
|
Assignment requestAssignment(Assignment::Request, Assignment::All, assignmentPool);
|
||||||
|
@ -46,7 +78,6 @@ int main(int argc, const char* argv[]) {
|
||||||
if (usecTimestampNow() - usecTimestamp(&lastRequest) >= ASSIGNMENT_REQUEST_INTERVAL_USECS) {
|
if (usecTimestampNow() - usecTimestamp(&lastRequest) >= ASSIGNMENT_REQUEST_INTERVAL_USECS) {
|
||||||
gettimeofday(&lastRequest, NULL);
|
gettimeofday(&lastRequest, NULL);
|
||||||
// if we're here we have no assignment, so send a request
|
// if we're here we have no assignment, so send a request
|
||||||
qDebug() << "Sending an assignment request -" << requestAssignment;
|
|
||||||
nodeList->sendAssignment(requestAssignment);
|
nodeList->sendAssignment(requestAssignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +100,6 @@ int main(int argc, const char* argv[]) {
|
||||||
if (deployedAssignment.getType() == Assignment::AudioMixer) {
|
if (deployedAssignment.getType() == Assignment::AudioMixer) {
|
||||||
AudioMixer::run();
|
AudioMixer::run();
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Running as an avatar mixer!";
|
|
||||||
AvatarMixer::run();
|
AvatarMixer::run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,11 @@ int main(int argc, const char* argv[]) {
|
||||||
const char* assignmentPool = getCmdOption(argc, argv, "-p");
|
const char* assignmentPool = getCmdOption(argc, argv, "-p");
|
||||||
|
|
||||||
// grab the overriden assignment-server hostname from argv, if it exists
|
// grab the overriden assignment-server hostname from argv, if it exists
|
||||||
nodeList->setAssignmentServerHostname(getCmdOption(argc, argv, "-a"));
|
const char* customAssignmentServer = getCmdOption(argc, argv, "-a");
|
||||||
|
if (customAssignmentServer) {
|
||||||
|
sockaddr_in customAssignmentSocket = socketForHostnameAndHostOrderPort(customAssignmentServer, ASSIGNMENT_SERVER_PORT);
|
||||||
|
nodeList->setAssignmentServerSocket((sockaddr*) &customAssignmentSocket);
|
||||||
|
}
|
||||||
|
|
||||||
// use a map to keep track of iterations of silence for assignment creation requests
|
// use a map to keep track of iterations of silence for assignment creation requests
|
||||||
const long long ASSIGNMENT_SILENCE_MAX_USECS = 5 * 1000 * 1000;
|
const long long ASSIGNMENT_SILENCE_MAX_USECS = 5 * 1000 * 1000;
|
||||||
|
|
|
@ -65,7 +65,8 @@ NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
|
||||||
_nodeTypesOfInterest(NULL),
|
_nodeTypesOfInterest(NULL),
|
||||||
_ownerID(UNKNOWN_NODE_ID),
|
_ownerID(UNKNOWN_NODE_ID),
|
||||||
_lastNodeID(UNKNOWN_NODE_ID + 1),
|
_lastNodeID(UNKNOWN_NODE_ID + 1),
|
||||||
_numNoReplyDomainCheckIns(0)
|
_numNoReplyDomainCheckIns(0),
|
||||||
|
_assignmentServerSocket(NULL)
|
||||||
{
|
{
|
||||||
memcpy(_domainHostname, DEFAULT_DOMAIN_HOSTNAME, sizeof(DEFAULT_DOMAIN_HOSTNAME));
|
memcpy(_domainHostname, DEFAULT_DOMAIN_HOSTNAME, sizeof(DEFAULT_DOMAIN_HOSTNAME));
|
||||||
memcpy(_domainIP, DEFAULT_DOMAIN_IP, sizeof(DEFAULT_DOMAIN_IP));
|
memcpy(_domainIP, DEFAULT_DOMAIN_IP, sizeof(DEFAULT_DOMAIN_IP));
|
||||||
|
@ -376,7 +377,8 @@ int NodeList::processDomainServerList(unsigned char* packetData, size_t dataByte
|
||||||
}
|
}
|
||||||
|
|
||||||
const char GLOBAL_ASSIGNMENT_SERVER_HOSTNAME[] = "assignment.highfidelity.io";
|
const char GLOBAL_ASSIGNMENT_SERVER_HOSTNAME[] = "assignment.highfidelity.io";
|
||||||
|
const sockaddr_in GLOBAL_ASSIGNMENT_SOCKET = socketForHostnameAndHostOrderPort(GLOBAL_ASSIGNMENT_SERVER_HOSTNAME,
|
||||||
|
ASSIGNMENT_SERVER_PORT);
|
||||||
void NodeList::sendAssignment(Assignment& assignment) {
|
void NodeList::sendAssignment(Assignment& assignment) {
|
||||||
unsigned char assignmentPacket[MAX_PACKET_SIZE];
|
unsigned char assignmentPacket[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
|
@ -387,13 +389,11 @@ void NodeList::sendAssignment(Assignment& assignment) {
|
||||||
int numHeaderBytes = populateTypeAndVersion(assignmentPacket, assignmentPacketType);
|
int numHeaderBytes = populateTypeAndVersion(assignmentPacket, assignmentPacketType);
|
||||||
int numAssignmentBytes = assignment.packToBuffer(assignmentPacket + numHeaderBytes);
|
int numAssignmentBytes = assignment.packToBuffer(assignmentPacket + numHeaderBytes);
|
||||||
|
|
||||||
// setup the assignmentServerSocket once, use a custom assignmentServerHostname if it is present
|
sockaddr* assignmentServerSocket = (_assignmentServerSocket == NULL)
|
||||||
static sockaddr_in assignmentServerSocket = socketForHostnameAndHostOrderPort((_assignmentServerHostname != NULL
|
? (sockaddr*) &GLOBAL_ASSIGNMENT_SOCKET
|
||||||
? (const char*) _assignmentServerHostname
|
: _assignmentServerSocket;
|
||||||
: GLOBAL_ASSIGNMENT_SERVER_HOSTNAME),
|
|
||||||
ASSIGNMENT_SERVER_PORT);
|
_nodeSocket.send((sockaddr*) assignmentServerSocket, assignmentPacket, numHeaderBytes + numAssignmentBytes);
|
||||||
|
|
||||||
_nodeSocket.send((sockaddr*) &assignmentServerSocket, assignmentPacket, numHeaderBytes + numAssignmentBytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* NodeList::addOrUpdateNode(sockaddr* publicSocket, sockaddr* localSocket, char nodeType, uint16_t nodeId) {
|
Node* NodeList::addOrUpdateNode(sockaddr* publicSocket, sockaddr* localSocket, char nodeType, uint16_t nodeId) {
|
||||||
|
|
|
@ -99,7 +99,7 @@ public:
|
||||||
void sendDomainServerCheckIn();
|
void sendDomainServerCheckIn();
|
||||||
int processDomainServerList(unsigned char *packetData, size_t dataBytes);
|
int processDomainServerList(unsigned char *packetData, size_t dataBytes);
|
||||||
|
|
||||||
void setAssignmentServerHostname(const char* serverHostname) { _assignmentServerHostname = serverHostname; }
|
void setAssignmentServerSocket(sockaddr* serverSocket) { _assignmentServerSocket = serverSocket; }
|
||||||
void sendAssignment(Assignment& assignment);
|
void sendAssignment(Assignment& assignment);
|
||||||
|
|
||||||
Node* nodeWithAddress(sockaddr *senderAddress);
|
Node* nodeWithAddress(sockaddr *senderAddress);
|
||||||
|
@ -152,7 +152,7 @@ private:
|
||||||
pthread_t removeSilentNodesThread;
|
pthread_t removeSilentNodesThread;
|
||||||
pthread_t checkInWithDomainServerThread;
|
pthread_t checkInWithDomainServerThread;
|
||||||
int _numNoReplyDomainCheckIns;
|
int _numNoReplyDomainCheckIns;
|
||||||
const char* _assignmentServerHostname;
|
sockaddr* _assignmentServerSocket;
|
||||||
|
|
||||||
void handlePingReply(sockaddr *nodeAddress);
|
void handlePingReply(sockaddr *nodeAddress);
|
||||||
void timePingReply(sockaddr *nodeAddress, unsigned char *packetData);
|
void timePingReply(sockaddr *nodeAddress, unsigned char *packetData);
|
||||||
|
|
Loading…
Reference in a new issue