X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fdevtools.c;h=fb6ab257a0f3eae901ff869c53a774aeb48c413d;hb=5d583af29b3ba76f9acaeb77c0e0457268776dcb;hp=47f18bc61f670f00a69d06cfc1b289ef5d514bfa;hpb=55e87af06f93daa497c389be8cd2acfefa70aa13;p=meshlink diff --git a/src/devtools.c b/src/devtools.c index 47f18bc6..fb6ab257 100644 --- a/src/devtools.c +++ b/src/devtools.c @@ -30,7 +30,7 @@ #include "devtools.h" -static void trybind_nop_probe(void) { +static void nop_probe(void) { return; } @@ -39,8 +39,21 @@ static void keyrotate_nop_probe(int stage) { return; } -void (*devtool_trybind_probe)(void) = trybind_nop_probe; +static void inviter_commits_first_nop_probe(bool stage) { + (void)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. @@ -52,7 +65,7 @@ devtool_edge_t *devtool_get_all_edges(meshlink_handle_t *mesh, devtool_edge_t *e return NULL; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); devtool_edge_t *result = NULL; unsigned int result_size = 0; @@ -72,7 +85,7 @@ devtool_edge_t *devtool_get_all_edges(meshlink_handle_t *mesh, devtool_edge_t *e for splay_each(edge_t, e, mesh->edges) { // skip edges that do not represent a two-directional connection - if((!e->reverse) || (e->reverse->to != e->from)) { + if(!e->reverse || e->reverse->to != e->from) { continue; } @@ -100,12 +113,14 @@ devtool_edge_t *devtool_get_all_edges(meshlink_handle_t *mesh, devtool_edge_t *e meshlink_errno = MESHLINK_ENOMEM; } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return result; } static bool fstrwrite(const char *str, FILE *stream) { + assert(stream); + size_t len = strlen(str); if(fwrite((void *)str, 1, len, stream) != len) { @@ -116,9 +131,11 @@ static bool fstrwrite(const char *str, FILE *stream) { } bool devtool_export_json_all_edges_state(meshlink_handle_t *mesh, FILE *stream) { + assert(stream); + bool result = true; - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); // export edges and nodes size_t node_count = 0; @@ -233,7 +250,7 @@ done: free(nodes); free(edges); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return result; } @@ -246,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->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); memcpy(&status->status, &internal->status, sizeof status->status); memcpy(&status->address, &internal->address, sizeof status->address); @@ -276,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->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); } meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, meshlink_submesh_t **submeshes, size_t *nmemb) { @@ -288,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->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); *nmemb = mesh->submeshes->count; result = realloc(submeshes, *nmemb * sizeof(*submeshes)); @@ -305,10 +322,11 @@ meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, meshlink meshlink_errno = MESHLINK_ENOMEM; } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return result; } + meshlink_handle_t *devtool_open_in_netns(const char *confbase, const char *name, const char *appname, dev_class_t devclass, int netns) { meshlink_open_params_t *params = meshlink_open_params_init(confbase, name, appname, devclass); params->netns = dup(netns); @@ -325,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 = 0; + + if(c) { + c->last_key_renewal = 0; + } +}