summaryrefslogtreecommitdiff
path: root/src/api.c
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2025-07-18 11:08:44 +0200
committerJesper Jensen <jesper@jnsn.dev>2025-07-18 11:08:44 +0200
commit70f7f2ec889c82a38328ea22b3d0bb60ce58410f (patch)
tree7583bdc5642afa4c3529994b8daa1226c73bc509 /src/api.c
parent84ba09387e3305aaef1ccb63db5207ae5ad6b936 (diff)
Test that we can't cancel a lookup
Diffstat (limited to 'src/api.c')
-rw-r--r--src/api.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/api.c b/src/api.c
index 16cde8c..720c9b4 100644
--- a/src/api.c
+++ b/src/api.c
@@ -185,8 +185,6 @@ static enum MHD_Result handler(
return MHD_YES;
} else {
- pthread_mutex_lock(&api->dht->mutex);
-
if(conn->state == OP_PENDING) {
if(!conn->target_set) {
response = MHD_create_response_from_buffer_static(0, NULL);
@@ -194,12 +192,16 @@ static enum MHD_Result handler(
goto end;
}
+ pthread_mutex_lock(&api->dht->mutex);
+
if(api->dht->lookup.state != OP_EMPTY) {
+ pthread_mutex_unlock(&api->dht->mutex);
response = MHD_create_response_from_buffer_static(0, NULL);
ret = MHD_queue_response(connection, MHD_HTTP_CONFLICT, response);
goto end;
}
+
// Start a lookup
memcpy(&api->dht->lookup.target, &conn->target, sizeof(struct nodeid));
api->dht->lookup.state = OP_PENDING;
@@ -211,7 +213,10 @@ static enum MHD_Result handler(
goto end;
}
- if(api->dht->lookup.state != OP_COMPLETED) {
+ pthread_mutex_lock(&api->dht->mutex);
+
+ if(api->dht->lookup.state != OP_COMPLETED && api->dht->lookup.state != OP_EMPTY) {
+ pthread_mutex_unlock(&api->dht->mutex);
response = MHD_create_response_from_buffer_static(0, NULL);
ret = MHD_queue_response(connection, MHD_HTTP_CONFLICT, response);
goto end;