]> git.meshlink.io Git - meshlink/blobdiff - src/devtools.c
Add asserts() to all pthread related function calls.
[meshlink] / src / devtools.c
index 5bd061800a0c72f7445cab68cb344d6570470f8c..e6ba56171c5dabc7aa727b0d989235121d693a41 100644 (file)
@@ -44,10 +44,16 @@ static void inviter_commits_first_nop_probe(bool stage) {
        return;
 }
 
+static void sptps_renewal_nop_probe(meshlink_node_t *node) {
+       (void)node;
+       return;
+}
+
 void (*devtool_trybind_probe)(void) = nop_probe;
 void (*devtool_keyrotate_probe)(int stage) = keyrotate_nop_probe;
 void (*devtool_set_inviter_commits_first)(bool inviter_commited_first) = inviter_commits_first_nop_probe;
 void (*devtool_adns_resolve_probe)(void) = nop_probe;
+void (*devtool_sptps_renewal_probe)(meshlink_node_t *node) = sptps_renewal_nop_probe;
 
 /* Return an array of edges in the current network graph.
  * Data captures the current state and will not be updated.
@@ -59,7 +65,7 @@ devtool_edge_t *devtool_get_all_edges(meshlink_handle_t *mesh, devtool_edge_t *e
                return NULL;
        }
 
-       pthread_mutex_lock(&mesh->mutex);
+       assert(pthread_mutex_lock(&mesh->mutex) == 0);
 
        devtool_edge_t *result = NULL;
        unsigned int result_size = 0;
@@ -107,7 +113,7 @@ devtool_edge_t *devtool_get_all_edges(meshlink_handle_t *mesh, devtool_edge_t *e
                meshlink_errno = MESHLINK_ENOMEM;
        }
 
-       pthread_mutex_unlock(&mesh->mutex);
+       assert(pthread_mutex_unlock(&mesh->mutex) == 0);
 
        return result;
 }
@@ -129,7 +135,7 @@ bool devtool_export_json_all_edges_state(meshlink_handle_t *mesh, FILE *stream)
 
        bool result = true;
 
-       pthread_mutex_lock(&mesh->mutex);
+       assert(pthread_mutex_lock(&mesh->mutex) == 0);
 
        // export edges and nodes
        size_t node_count = 0;
@@ -244,7 +250,7 @@ done:
        free(nodes);
        free(edges);
 
-       pthread_mutex_unlock(&mesh->mutex);
+       assert(pthread_mutex_unlock(&mesh->mutex) == 0);
 
        return result;
 }
@@ -257,7 +263,7 @@ void devtool_get_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, dev
 
        node_t *internal = (node_t *)node;
 
-       pthread_mutex_lock(&mesh->mutex);
+       assert(pthread_mutex_lock(&mesh->mutex) == 0);
 
        memcpy(&status->status, &internal->status, sizeof status->status);
        memcpy(&status->address, &internal->address, sizeof status->address);
@@ -287,7 +293,7 @@ void devtool_get_node_status(meshlink_handle_t *mesh, meshlink_node_t *node, dev
                status->udp_status = DEVTOOL_UDP_UNKNOWN;
        }
 
-       pthread_mutex_unlock(&mesh->mutex);
+       assert(pthread_mutex_unlock(&mesh->mutex) == 0);
 }
 
 meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, meshlink_submesh_t **submeshes, size_t *nmemb) {
@@ -299,7 +305,7 @@ meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, meshlink
        meshlink_submesh_t **result;
 
        //lock mesh->nodes
-       pthread_mutex_lock(&mesh->mutex);
+       assert(pthread_mutex_lock(&mesh->mutex) == 0);
 
        *nmemb = mesh->submeshes->count;
        result = realloc(submeshes, *nmemb * sizeof(*submeshes));
@@ -316,7 +322,7 @@ meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, meshlink
                meshlink_errno = MESHLINK_ENOMEM;
        }
 
-       pthread_mutex_unlock(&mesh->mutex);
+       assert(pthread_mutex_unlock(&mesh->mutex) == 0);
 
        return result;
 }
@@ -337,3 +343,19 @@ meshlink_handle_t *devtool_open_in_netns(const char *confbase, const char *name,
 
        return handle;
 }
+
+void devtool_force_sptps_renewal(meshlink_handle_t *mesh, meshlink_node_t *node) {
+       if(!mesh || !node) {
+               meshlink_errno = MESHLINK_EINVAL;
+               return;
+       }
+
+       node_t *n = (node_t *)node;
+       connection_t *c = n->connection;
+
+       n->last_req_key = -3600;
+
+       if(c) {
+               c->last_key_renewal = -3600;
+       }
+}