From 4932c3266fa09b0fede12f09c5498c27aae34baf Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 17 Sep 2013 13:22:09 -0700 Subject: [PATCH] moving to Assignment payload style implementation --- domain-server/src/main.cpp | 48 ++++++++----------------------- libraries/shared/src/Assignment.h | 8 ++++++ 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index ab837a0abe..fb2869c327 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -48,7 +48,6 @@ const int NODE_COUNT_STAT_INTERVAL_MSECS = 5000; QMutex assignmentQueueMutex; std::deque assignmentQueue; -QMap configMap; unsigned char* addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd) { *currentPosition++ = nodeToAdd->getType(); @@ -70,37 +69,6 @@ static int mongooseRequestHandler(struct mg_connection *conn) { // upload the file 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; } else { // have mongoose process this request from the document_root @@ -166,7 +134,7 @@ int main(int argc, const char* argv[]) { in_addr_t serverLocalAddress = getLocalAddress(); nodeList->startSilentNodeRemovalThread(); - + timeval lastStatSendTime = {}; const char ASSIGNMENT_SERVER_OPTION[] = "-a"; @@ -194,6 +162,15 @@ int main(int argc, const char* argv[]) { Assignment voxelServerAssignment(Assignment::CreateCommand, Assignment::VoxelServerType, 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 sockaddr_in localSocket = {}; @@ -249,10 +226,9 @@ int main(int argc, const char* argv[]) { } } const int MIN_VOXEL_SERVER_CHECKS = 10; - if (checkForVoxelServerAttempt > MIN_VOXEL_SERVER_CHECKS && - voxelServerCount == 0 && + if (checkForVoxelServerAttempt > MIN_VOXEL_SERVER_CHECKS && voxelServerCount == 0 && 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); } checkForVoxelServerAttempt++; diff --git a/libraries/shared/src/Assignment.h b/libraries/shared/src/Assignment.h index 59e2c45db7..1f0431187a 100644 --- a/libraries/shared/src/Assignment.h +++ b/libraries/shared/src/Assignment.h @@ -15,6 +15,8 @@ #include "NodeList.h" +const int MAX_PAYLOAD_SIZE = 1024; + /// Holds information used for request, creation, and deployment of assignments class Assignment { public: @@ -65,6 +67,10 @@ public: const sockaddr* getAttachedLocalSocket() { return _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 /// \param buffer the buffer in which to pack the assignment @@ -83,6 +89,8 @@ private: sockaddr* _attachedLocalSocket; /// pointer to a local socket that relates to assignment, depends on direction timeval _time; /// time the assignment was created (set in constructor) int _numberOfInstances; /// the number of instances of this assignment + unsigned char _dataPayload[MAX_PAYLOAD_SIZE]; + int _dataPayloadSize; }; QDebug operator<<(QDebug debug, const Assignment &assignment);