mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 06:49:41 +02:00
add a DELETE method to civetweb to delete assignment by UUID
This commit is contained in:
parent
fc36e38d1c
commit
d85c0bb88a
4 changed files with 74 additions and 25 deletions
|
@ -46,6 +46,9 @@ int DomainServer::civetwebRequestHandler(struct mg_connection *connection) {
|
||||||
const struct mg_request_info* ri = mg_get_request_info(connection);
|
const struct mg_request_info* ri = mg_get_request_info(connection);
|
||||||
|
|
||||||
const char RESPONSE_200[] = "HTTP/1.0 200 OK\r\n\r\n";
|
const char RESPONSE_200[] = "HTTP/1.0 200 OK\r\n\r\n";
|
||||||
|
const char RESPONSE_400[] = "HTTP/1.0 400 Bad Request\r\n\r\n";
|
||||||
|
|
||||||
|
const char ASSIGNMENT_URI[] = "/assignment";
|
||||||
|
|
||||||
if (strcmp(ri->uri, "/assignment") == 0 && strcmp(ri->request_method, "POST") == 0) {
|
if (strcmp(ri->uri, "/assignment") == 0 && strcmp(ri->request_method, "POST") == 0) {
|
||||||
// return a 200
|
// return a 200
|
||||||
|
@ -120,6 +123,35 @@ int DomainServer::civetwebRequestHandler(struct mg_connection *connection) {
|
||||||
|
|
||||||
// we've processed this request
|
// we've processed this request
|
||||||
return 1;
|
return 1;
|
||||||
|
} else if (strcmp(ri->request_method, "DELETE") == 0) {
|
||||||
|
// this is a DELETE request
|
||||||
|
|
||||||
|
// check if it is for an assignment
|
||||||
|
if (memcmp(ri->uri, ASSIGNMENT_URI, sizeof(ASSIGNMENT_URI) - sizeof('\0')) == 0) {
|
||||||
|
// pull the UUID from the url
|
||||||
|
QUuid deleteUUID = QUuid(QString(ri->uri + strlen(ASSIGNMENT_URI) + sizeof('/')));
|
||||||
|
|
||||||
|
if (!deleteUUID.isNull()) {
|
||||||
|
Node *nodeToKill = NodeList::getInstance()->nodeWithUUID(deleteUUID);
|
||||||
|
|
||||||
|
if (nodeToKill) {
|
||||||
|
// start with a 200 response
|
||||||
|
mg_printf(connection, "%s", RESPONSE_200);
|
||||||
|
|
||||||
|
// we have a valid UUID and node - kill the node that has this assignment
|
||||||
|
NodeList::getInstance()->killNode(nodeToKill);
|
||||||
|
|
||||||
|
// successfully processed request
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// request not processed - bad request
|
||||||
|
mg_printf(connection, "%s", RESPONSE_400);
|
||||||
|
|
||||||
|
// this was processed by civetweb
|
||||||
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
// have mongoose process this request from the document_root
|
// have mongoose process this request from the document_root
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -160,20 +192,12 @@ void DomainServer::civetwebUploadHandler(struct mg_connection *connection, const
|
||||||
domainServerInstance->_assignmentQueueMutex.unlock();
|
domainServerInstance->_assignmentQueueMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainServer::nodeAdded(Node* node) {
|
void DomainServer::addDeletedAssignmentBackToQueue(Assignment* deletedAssignment) {
|
||||||
|
qDebug() << "Adding assignment" << *deletedAssignment << " back to queue.\n";
|
||||||
}
|
|
||||||
|
|
||||||
void DomainServer::nodeKilled(Node* node) {
|
|
||||||
// if this node has linked data it was from an assignment
|
|
||||||
if (node->getLinkedData()) {
|
|
||||||
Assignment* nodeAssignment = (Assignment*) node->getLinkedData();
|
|
||||||
|
|
||||||
qDebug() << "Adding assignment" << *nodeAssignment << " back to queue.\n";
|
|
||||||
|
|
||||||
// find this assignment in the static file
|
// find this assignment in the static file
|
||||||
for (int i = 0; i < MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS; i++) {
|
for (int i = 0; i < MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS; i++) {
|
||||||
if (_staticAssignments[i].getUUID() == nodeAssignment->getUUID()) {
|
if (_staticAssignments[i].getUUID() == deletedAssignment->getUUID()) {
|
||||||
// reset the UUID on the static assignment
|
// reset the UUID on the static assignment
|
||||||
_staticAssignments[i].resetUUID();
|
_staticAssignments[i].resetUUID();
|
||||||
|
|
||||||
|
@ -187,8 +211,19 @@ void DomainServer::nodeKilled(Node* node) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DomainServer::nodeAdded(Node* node) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DomainServer::nodeKilled(Node* node) {
|
||||||
|
// if this node has linked data it was from an assignment
|
||||||
|
if (node->getLinkedData()) {
|
||||||
|
Assignment* nodeAssignment = (Assignment*) node->getLinkedData();
|
||||||
|
|
||||||
|
addDeletedAssignmentBackToQueue(nodeAssignment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* DomainServer::addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd) {
|
unsigned char* DomainServer::addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd) {
|
||||||
|
|
|
@ -47,6 +47,7 @@ private:
|
||||||
void removeAssignmentFromQueue(Assignment* removableAssignment);
|
void removeAssignmentFromQueue(Assignment* removableAssignment);
|
||||||
bool checkInWithUUIDMatchesExistingNode(sockaddr* nodePublicSocket, sockaddr* nodeLocalSocket, const QUuid& checkInUUI);
|
bool checkInWithUUIDMatchesExistingNode(sockaddr* nodePublicSocket, sockaddr* nodeLocalSocket, const QUuid& checkInUUI);
|
||||||
void possiblyAddStaticAssignmentsBackToQueueAfterRestart(timeval* startTime);
|
void possiblyAddStaticAssignmentsBackToQueueAfterRestart(timeval* startTime);
|
||||||
|
void addDeletedAssignmentBackToQueue(Assignment* deletedAssignment);
|
||||||
|
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
|
|
|
@ -715,6 +715,22 @@ Node* NodeList::soloNodeOfType(char nodeType) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NodeList::killNode(Node* node, bool mustLockNode) {
|
||||||
|
if (mustLockNode) {
|
||||||
|
node->lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Killed " << *node << "\n";
|
||||||
|
|
||||||
|
notifyHooksOfKilledNode(&*node);
|
||||||
|
|
||||||
|
node->setAlive(false);
|
||||||
|
|
||||||
|
if (mustLockNode) {
|
||||||
|
node->unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void* removeSilentNodes(void *args) {
|
void* removeSilentNodes(void *args) {
|
||||||
NodeList* nodeList = (NodeList*) args;
|
NodeList* nodeList = (NodeList*) args;
|
||||||
uint64_t checkTimeUsecs = 0;
|
uint64_t checkTimeUsecs = 0;
|
||||||
|
@ -728,12 +744,8 @@ void* removeSilentNodes(void *args) {
|
||||||
node->lock();
|
node->lock();
|
||||||
|
|
||||||
if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) {
|
if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) {
|
||||||
|
// kill this node, don't lock - we already did it
|
||||||
qDebug() << "Killed " << *node << "\n";
|
nodeList->killNode(&(*node), false);
|
||||||
|
|
||||||
nodeList->notifyHooksOfKilledNode(&*node);
|
|
||||||
|
|
||||||
node->setAlive(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node->unlock();
|
node->unlock();
|
||||||
|
|
|
@ -113,6 +113,7 @@ public:
|
||||||
Node* nodeWithUUID(const QUuid& nodeUUID);
|
Node* nodeWithUUID(const QUuid& nodeUUID);
|
||||||
|
|
||||||
Node* addOrUpdateNode(const QUuid& uuid, char nodeType, sockaddr* publicSocket, sockaddr* localSocket);
|
Node* addOrUpdateNode(const QUuid& uuid, char nodeType, sockaddr* publicSocket, sockaddr* localSocket);
|
||||||
|
void killNode(Node* node, bool mustLockNode = true);
|
||||||
|
|
||||||
void processNodeData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
|
void processNodeData(sockaddr *senderAddress, unsigned char *packetData, size_t dataBytes);
|
||||||
void processBulkNodeData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes);
|
void processBulkNodeData(sockaddr *senderAddress, unsigned char *packetData, int numTotalBytes);
|
||||||
|
|
Loading…
Reference in a new issue