mirror of
https://github.com/overte-org/overte.git
synced 2025-06-20 07:20:33 +02:00
moving to Assignment payload style implementation
This commit is contained in:
parent
ad4dea129c
commit
4932c3266f
2 changed files with 20 additions and 36 deletions
|
@ -48,7 +48,6 @@ const int NODE_COUNT_STAT_INTERVAL_MSECS = 5000;
|
||||||
|
|
||||||
QMutex assignmentQueueMutex;
|
QMutex assignmentQueueMutex;
|
||||||
std::deque<Assignment*> assignmentQueue;
|
std::deque<Assignment*> assignmentQueue;
|
||||||
QMap<QString, QString> configMap;
|
|
||||||
|
|
||||||
unsigned char* addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd) {
|
unsigned char* addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd) {
|
||||||
*currentPosition++ = nodeToAdd->getType();
|
*currentPosition++ = nodeToAdd->getType();
|
||||||
|
@ -70,37 +69,6 @@ static int mongooseRequestHandler(struct mg_connection *conn) {
|
||||||
// upload the file
|
// upload the file
|
||||||
mg_upload(conn, "/tmp");
|
mg_upload(conn, "/tmp");
|
||||||
|
|
||||||
return 1;
|
|
||||||
} else if (strncmp(ri->uri, "/config", strlen("/config")) == 0 && strcmp(ri->request_method, "GET") == 0) {
|
|
||||||
|
|
||||||
// Let's split up the URL into it's pieces so we can service it
|
|
||||||
QString uri(ri->uri);
|
|
||||||
QString delimiterPattern("/");
|
|
||||||
QStringList uriParts = uri.split(delimiterPattern);
|
|
||||||
|
|
||||||
QString configGuid = uriParts[2];
|
|
||||||
|
|
||||||
// first part should be empty
|
|
||||||
// second part should be "config"
|
|
||||||
// third part should be a guid, and therefore should not be empty
|
|
||||||
if (!uriParts[0].isEmpty() || uriParts[1] != "config" || configGuid.isEmpty()) {
|
|
||||||
mg_printf(conn, "%s", "HTTP/1.0 400 Bad Request\r\nContent-Type: text/plain\r\n\r\nInvalid parameters.");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// assuming the request format was valid, look up the guid in our configs
|
|
||||||
if (!::configMap.contains(configGuid)) {
|
|
||||||
mg_printf(conn, "%s", "HTTP/1.0 404 Not Found\r\nContent-Type: text/plain\r\n\r\nInvalid config GUID.");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char * configPayload = configMap[configGuid].toLocal8Bit().data();
|
|
||||||
|
|
||||||
// return a 200
|
|
||||||
mg_printf(conn, "%s", "HTTP/1.0 200 OK\r\n\r\n");
|
|
||||||
// return the configuration "payload"
|
|
||||||
mg_printf(conn, "%s", configPayload);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
// have mongoose process this request from the document_root
|
// have mongoose process this request from the document_root
|
||||||
|
@ -195,6 +163,15 @@ int main(int argc, const char* argv[]) {
|
||||||
Assignment::VoxelServerType,
|
Assignment::VoxelServerType,
|
||||||
Assignment::LocalLocation);
|
Assignment::LocalLocation);
|
||||||
|
|
||||||
|
// Handle Domain/Voxel Server configuration command line arguments
|
||||||
|
const char VOXEL_CONFIG_OPTION[] = "--voxelServerConfig";
|
||||||
|
const char* voxelServerConfig = getCmdOption(argc, argv, VOXEL_CONFIG_OPTION);
|
||||||
|
if (voxelServerConfig) {
|
||||||
|
qDebug("Reading Voxel Server Configuration.\n");
|
||||||
|
qDebug() << " config: " << voxelServerConfig << "\n";
|
||||||
|
voxelServerAssignment.setDataPayload((unsigned char*)voxelServerConfig, strlen(voxelServerConfig) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
// construct a local socket to send with our created assignments to the global AS
|
// construct a local socket to send with our created assignments to the global AS
|
||||||
sockaddr_in localSocket = {};
|
sockaddr_in localSocket = {};
|
||||||
localSocket.sin_family = AF_INET;
|
localSocket.sin_family = AF_INET;
|
||||||
|
@ -249,10 +226,9 @@ int main(int argc, const char* argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const int MIN_VOXEL_SERVER_CHECKS = 10;
|
const int MIN_VOXEL_SERVER_CHECKS = 10;
|
||||||
if (checkForVoxelServerAttempt > MIN_VOXEL_SERVER_CHECKS &&
|
if (checkForVoxelServerAttempt > MIN_VOXEL_SERVER_CHECKS && voxelServerCount == 0 &&
|
||||||
voxelServerCount == 0 &&
|
|
||||||
std::find(::assignmentQueue.begin(), ::assignmentQueue.end(), &voxelServerAssignment) == ::assignmentQueue.end()) {
|
std::find(::assignmentQueue.begin(), ::assignmentQueue.end(), &voxelServerAssignment) == ::assignmentQueue.end()) {
|
||||||
qDebug("Missing a Voxel Server and assignment not in queue. Adding.\n");
|
qDebug("Missing a voxel server and assignment not in queue. Adding.\n");
|
||||||
::assignmentQueue.push_front(&voxelServerAssignment);
|
::assignmentQueue.push_front(&voxelServerAssignment);
|
||||||
}
|
}
|
||||||
checkForVoxelServerAttempt++;
|
checkForVoxelServerAttempt++;
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
#include "NodeList.h"
|
#include "NodeList.h"
|
||||||
|
|
||||||
|
const int MAX_PAYLOAD_SIZE = 1024;
|
||||||
|
|
||||||
/// Holds information used for request, creation, and deployment of assignments
|
/// Holds information used for request, creation, and deployment of assignments
|
||||||
class Assignment {
|
class Assignment {
|
||||||
public:
|
public:
|
||||||
|
@ -66,6 +68,10 @@ public:
|
||||||
const sockaddr* getAttachedLocalSocket() { return _attachedLocalSocket; }
|
const sockaddr* getAttachedLocalSocket() { return _attachedLocalSocket; }
|
||||||
void setAttachedLocalSocket(const sockaddr* attachedLocalSocket);
|
void setAttachedLocalSocket(const sockaddr* attachedLocalSocket);
|
||||||
|
|
||||||
|
unsigned char* getDataPayload() { return _dataPayload; }
|
||||||
|
int getDataPayloadSize() { return _dataPayloadSize; }
|
||||||
|
void setDataPayload(unsigned char* data, int length) { memcpy(_dataPayload, data, length); _dataPayloadSize = length; }
|
||||||
|
|
||||||
/// Packs the assignment to the passed buffer
|
/// Packs the assignment to the passed buffer
|
||||||
/// \param buffer the buffer in which to pack the assignment
|
/// \param buffer the buffer in which to pack the assignment
|
||||||
/// \return number of bytes packed into buffer
|
/// \return number of bytes packed into buffer
|
||||||
|
@ -83,6 +89,8 @@ private:
|
||||||
sockaddr* _attachedLocalSocket; /// pointer to a local socket that relates to assignment, depends on direction
|
sockaddr* _attachedLocalSocket; /// pointer to a local socket that relates to assignment, depends on direction
|
||||||
timeval _time; /// time the assignment was created (set in constructor)
|
timeval _time; /// time the assignment was created (set in constructor)
|
||||||
int _numberOfInstances; /// the number of instances of this assignment
|
int _numberOfInstances; /// the number of instances of this assignment
|
||||||
|
unsigned char _dataPayload[MAX_PAYLOAD_SIZE];
|
||||||
|
int _dataPayloadSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, const Assignment &assignment);
|
QDebug operator<<(QDebug debug, const Assignment &assignment);
|
||||||
|
|
Loading…
Reference in a new issue