From: Guus Sliepen Date: Sun, 13 Oct 2019 12:16:52 +0000 (+0200) Subject: Rename mesh_mutex to mutex. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=a5a8005b2d89712e124ab7295165a3e229abdad5;p=meshlink Rename mesh_mutex to mutex. --- diff --git a/src/devtools.c b/src/devtools.c index 0284dcd5..fab0c720 100644 --- a/src/devtools.c +++ b/src/devtools.c @@ -52,7 +52,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; @@ -100,7 +100,7 @@ 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; } @@ -122,7 +122,7 @@ bool devtool_export_json_all_edges_state(meshlink_handle_t *mesh, FILE *stream) bool result = true; - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); // export edges and nodes size_t node_count = 0; @@ -237,7 +237,7 @@ done: free(nodes); free(edges); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return result; } @@ -250,7 +250,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); @@ -280,7 +280,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) { @@ -292,7 +292,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)); @@ -309,7 +309,7 @@ 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; } diff --git a/src/discovery.c b/src/discovery.c index 6b98a276..a64e9e2e 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -126,13 +126,13 @@ static void discovery_server_callback(CattaServer *server, CattaServerState stat case CATTA_SERVER_RUNNING: /* The serve has startup successfully and registered its host * name on the network, so it's time to create our services */ - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); if(!mesh->catta_group) { discovery_create_services(mesh); } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); break; @@ -141,7 +141,7 @@ static void discovery_server_callback(CattaServer *server, CattaServerState stat char hostname[17]; generate_rand_string(mesh, hostname, sizeof(hostname)); - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); assert(mesh->catta_server); assert(mesh->catta_poll); @@ -152,12 +152,12 @@ static void discovery_server_callback(CattaServer *server, CattaServerState stat catta_simple_poll_quit(mesh->catta_poll); } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); } break; case CATTA_SERVER_REGISTERING: - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); /* Let's drop our registered services. When the server is back * in CATTA_SERVER_RUNNING state we will register them @@ -167,12 +167,12 @@ static void discovery_server_callback(CattaServer *server, CattaServerState stat mesh->catta_group = NULL; } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); break; case CATTA_SERVER_FAILURE: - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); assert(mesh->catta_server); assert(mesh->catta_poll); @@ -180,7 +180,7 @@ static void discovery_server_callback(CattaServer *server, CattaServerState stat /* Terminate on failure */ catta_simple_poll_quit(mesh->catta_poll); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); break; case CATTA_SERVER_INVALID: @@ -215,7 +215,7 @@ static void discovery_resolve_callback(CattaSServiceResolver *resolver, CattaIfI char *node_fp = (char *)catta_string_list_get_text(node_fp_li) + strlen(MESHLINK_MDNS_FINGERPRINT_KEY); if(node_name[0] == '=' && node_fp[0] == '=') { - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); node_name += 1; @@ -271,7 +271,7 @@ static void discovery_resolve_callback(CattaSServiceResolver *resolver, CattaIfI logger(mesh, MESHLINK_WARNING, "Node %s is not part of the mesh network.\n", node_name); } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); } } @@ -286,22 +286,22 @@ static void discovery_browse_callback(CattaSServiceBrowser *browser, CattaIfInde /* Called whenever a new services becomes available on the LAN or is removed from the LAN */ switch(event) { case CATTA_BROWSER_FAILURE: - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); catta_simple_poll_quit(mesh->catta_poll); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); break; case CATTA_BROWSER_NEW: - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); catta_s_service_resolver_new(mesh->catta_server, interface_, protocol, name, type, domain, CATTA_PROTO_UNSPEC, 0, discovery_resolve_callback, mesh); handle_network_change(mesh, ++mesh->catta_interfaces); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); break; case CATTA_BROWSER_REMOVE: - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); handle_network_change(mesh, --mesh->catta_interfaces); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); break; case CATTA_BROWSER_ALL_FOR_NOW: diff --git a/src/meshlink.c b/src/meshlink.c index 2db62ea1..54187a59 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1077,7 +1077,7 @@ bool meshlink_encrypted_key_rotate(meshlink_handle_t *mesh, const void *new_key, return false; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); // Create hash for the new key void *new_config_key; @@ -1086,7 +1086,7 @@ bool meshlink_encrypted_key_rotate(meshlink_handle_t *mesh, const void *new_key, if(!prf(new_key, new_keylen, "MeshLink configuration key", 26, new_config_key, CHACHA_POLY1305_KEYLEN)) { logger(mesh, MESHLINK_ERROR, "Error creating new configuration key!\n"); meshlink_errno = MESHLINK_EINTERNAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -1095,7 +1095,7 @@ bool meshlink_encrypted_key_rotate(meshlink_handle_t *mesh, const void *new_key, if(!config_copy(mesh, "current", mesh->config_key, "new", new_config_key)) { logger(mesh, MESHLINK_ERROR, "Could not set up configuration in %s/old: %s\n", mesh->confbase, strerror(errno)); meshlink_errno = MESHLINK_ESTORAGE; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -1109,7 +1109,7 @@ bool meshlink_encrypted_key_rotate(meshlink_handle_t *mesh, const void *new_key, logger(mesh, MESHLINK_ERROR, "Cannot rename %s/current to %s/old\n", mesh->confbase, mesh->confbase); meshlink_errno = MESHLINK_ESTORAGE; main_config_lock(mesh); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -1121,21 +1121,21 @@ bool meshlink_encrypted_key_rotate(meshlink_handle_t *mesh, const void *new_key, logger(mesh, MESHLINK_ERROR, "Cannot rename %s/new to %s/current\n", mesh->confbase, mesh->confbase); meshlink_errno = MESHLINK_ESTORAGE; main_config_lock(mesh); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } devtool_keyrotate_probe(3); if(!main_config_lock(mesh)) { - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } // Cleanup the "old" confbase sub-directory if(!config_destroy(mesh->confbase, "old")) { - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -1144,7 +1144,7 @@ bool meshlink_encrypted_key_rotate(meshlink_handle_t *mesh, const void *new_key, free(mesh->config_key); mesh->config_key = new_config_key; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return true; } @@ -1310,7 +1310,7 @@ meshlink_handle_t *meshlink_open_ex(const meshlink_open_params_t *params) { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&(mesh->mesh_mutex), &attr); + pthread_mutex_init(&mesh->mutex, &attr); mesh->threadstarted = false; event_loop_init(&mesh->loop); @@ -1394,11 +1394,11 @@ meshlink_submesh_t *meshlink_submesh_open(meshlink_handle_t *mesh, const char * } //lock mesh->nodes - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); s = (meshlink_submesh_t *)create_submesh(mesh, submesh); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return s; } @@ -1428,14 +1428,14 @@ static void *meshlink_main_loop(void *arg) { #endif - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); logger(mesh, MESHLINK_DEBUG, "Starting main_loop...\n"); pthread_cond_broadcast(&mesh->cond); main_loop(mesh); logger(mesh, MESHLINK_DEBUG, "main_loop returned.\n"); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); #if HAVE_CATTA @@ -1460,14 +1460,14 @@ bool meshlink_start(meshlink_handle_t *mesh) { logger(mesh, MESHLINK_DEBUG, "meshlink_start called\n"); - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); assert(mesh->self->ecdsa); assert(!memcmp((uint8_t *)mesh->self->ecdsa + 64, (uint8_t *)mesh->private_key + 64, 32)); if(mesh->threadstarted) { logger(mesh, MESHLINK_DEBUG, "thread was already running\n"); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return true; } @@ -1485,7 +1485,7 @@ bool meshlink_start(meshlink_handle_t *mesh) { if(!mesh->name) { logger(mesh, MESHLINK_DEBUG, "No name given!\n"); meshlink_errno = MESHLINK_EINVAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -1500,14 +1500,14 @@ bool meshlink_start(meshlink_handle_t *mesh) { memset(&mesh->thread, 0, sizeof(mesh)->thread); meshlink_errno = MESHLINK_EINTERNAL; event_loop_stop(&mesh->loop); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } - pthread_cond_wait(&mesh->cond, &mesh->mesh_mutex); + pthread_cond_wait(&mesh->cond, &mesh->mutex); mesh->threadstarted = true; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return true; } @@ -1517,7 +1517,7 @@ void meshlink_stop(meshlink_handle_t *mesh) { return; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); logger(mesh, MESHLINK_DEBUG, "meshlink_stop called\n"); // Shut down the main thread @@ -1540,9 +1540,9 @@ void meshlink_stop(meshlink_handle_t *mesh) { if(mesh->threadstarted) { // Wait for the main thread to finish - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); pthread_join(mesh->thread, NULL); - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); mesh->threadstarted = false; } @@ -1569,7 +1569,7 @@ void meshlink_stop(meshlink_handle_t *mesh) { } } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); } void meshlink_close(meshlink_handle_t *mesh) { @@ -1582,7 +1582,7 @@ void meshlink_close(meshlink_handle_t *mesh) { meshlink_stop(mesh); // lock is not released after this - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); // Close and free all resources used. @@ -1620,8 +1620,8 @@ void meshlink_close(meshlink_handle_t *mesh) { main_config_unlock(mesh); - pthread_mutex_unlock(&mesh->mesh_mutex); - pthread_mutex_destroy(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); + pthread_mutex_destroy(&mesh->mutex); memset(mesh, 0, sizeof(*mesh)); @@ -1657,9 +1657,9 @@ void meshlink_set_receive_cb(meshlink_handle_t *mesh, meshlink_receive_cb_t cb) return; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); mesh->receive_cb = cb; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); } void meshlink_set_connection_try_cb(meshlink_handle_t *mesh, meshlink_connection_try_cb_t cb) { @@ -1668,9 +1668,9 @@ void meshlink_set_connection_try_cb(meshlink_handle_t *mesh, meshlink_connection return; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); mesh->connection_try_cb = cb; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); } void meshlink_set_node_status_cb(meshlink_handle_t *mesh, meshlink_node_status_cb_t cb) { @@ -1679,9 +1679,9 @@ void meshlink_set_node_status_cb(meshlink_handle_t *mesh, meshlink_node_status_c return; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); mesh->node_status_cb = cb; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); } void meshlink_set_node_pmtu_cb(meshlink_handle_t *mesh, meshlink_node_pmtu_cb_t cb) { @@ -1690,9 +1690,9 @@ void meshlink_set_node_pmtu_cb(meshlink_handle_t *mesh, meshlink_node_pmtu_cb_t return; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); mesh->node_pmtu_cb = cb; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); } void meshlink_set_node_duplicate_cb(meshlink_handle_t *mesh, meshlink_node_duplicate_cb_t cb) { @@ -1701,17 +1701,17 @@ void meshlink_set_node_duplicate_cb(meshlink_handle_t *mesh, meshlink_node_dupli return; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); mesh->node_duplicate_cb = cb; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); } void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, meshlink_log_cb_t cb) { if(mesh) { - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); mesh->log_cb = cb; mesh->log_level = cb ? level : 0; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); } else { global_log_cb = cb; global_log_level = cb ? level : 0; @@ -1724,9 +1724,9 @@ void meshlink_set_error_cb(struct meshlink_handle *mesh, meshlink_error_cb_t cb) return; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); mesh->error_cb = cb; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); } bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len) { @@ -1810,19 +1810,19 @@ ssize_t meshlink_get_pmtu(meshlink_handle_t *mesh, meshlink_node_t *destination) return -1; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); node_t *n = (node_t *)destination; if(!n->status.reachable) { - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return 0; } else if(n->mtuprobes > 30 && n->minmtu) { - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return n->minmtu; } else { - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return MTU; } } @@ -1833,13 +1833,13 @@ char *meshlink_get_fingerprint(meshlink_handle_t *mesh, meshlink_node_t *node) { return NULL; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); node_t *n = (node_t *)node; if(!node_read_public_key(mesh, n) || !n->ecdsa) { meshlink_errno = MESHLINK_EINTERNAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -1849,7 +1849,7 @@ char *meshlink_get_fingerprint(meshlink_handle_t *mesh, meshlink_node_t *node) { meshlink_errno = MESHLINK_EINTERNAL; } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return fingerprint; } @@ -1870,9 +1870,9 @@ meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name) { meshlink_node_t *node = NULL; - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); node = (meshlink_node_t *)lookup_node(mesh, (char *)name); // TODO: make lookup_node() use const - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); if(!node) { meshlink_errno = MESHLINK_ENOENT; @@ -1889,9 +1889,9 @@ meshlink_submesh_t *meshlink_get_submesh(meshlink_handle_t *mesh, const char *na meshlink_submesh_t *submesh = NULL; - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); submesh = (meshlink_submesh_t *)lookup_submesh(mesh, name); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); if(!submesh) { meshlink_errno = MESHLINK_ENOENT; @@ -1909,7 +1909,7 @@ meshlink_node_t **meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_ meshlink_node_t **result; //lock mesh->nodes - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); *nmemb = mesh->nodes->count; result = realloc(nodes, *nmemb * sizeof(*nodes)); @@ -1926,7 +1926,7 @@ meshlink_node_t **meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_ meshlink_errno = MESHLINK_ENOMEM; } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return result; } @@ -1934,7 +1934,7 @@ meshlink_node_t **meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_ static meshlink_node_t **meshlink_get_all_nodes_by_condition(meshlink_handle_t *mesh, const void *condition, meshlink_node_t **nodes, size_t *nmemb, search_node_by_condition_t search_node) { meshlink_node_t **result; - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); *nmemb = 0; @@ -1946,7 +1946,7 @@ static meshlink_node_t **meshlink_get_all_nodes_by_condition(meshlink_handle_t * if(*nmemb == 0) { free(nodes); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return NULL; } @@ -1966,7 +1966,7 @@ static meshlink_node_t **meshlink_get_all_nodes_by_condition(meshlink_handle_t * meshlink_errno = MESHLINK_ENOMEM; } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return result; } @@ -2015,11 +2015,11 @@ dev_class_t meshlink_get_node_dev_class(meshlink_handle_t *mesh, meshlink_node_t dev_class_t devclass; - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); devclass = ((node_t *)node)->devclass; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return devclass; } @@ -2050,16 +2050,16 @@ bool meshlink_sign(meshlink_handle_t *mesh, const void *data, size_t len, void * return false; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); if(!ecdsa_sign(mesh->private_key, data, len, signature)) { meshlink_errno = MESHLINK_EINTERNAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } *siglen = MESHLINK_SIGLEN; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return true; } @@ -2074,7 +2074,7 @@ bool meshlink_verify(meshlink_handle_t *mesh, meshlink_node_t *source, const voi return false; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); bool rval = false; @@ -2087,12 +2087,12 @@ bool meshlink_verify(meshlink_handle_t *mesh, meshlink_node_t *source, const voi rval = ecdsa_verify(((struct node_t *)source)->ecdsa, data, len, signature); } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return rval; } static bool refresh_invitation_key(meshlink_handle_t *mesh) { - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); size_t count = invitation_purge_old(mesh, time(NULL) - mesh->invitation_timeout); @@ -2100,7 +2100,7 @@ static bool refresh_invitation_key(meshlink_handle_t *mesh) { // TODO: Update invitation key if necessary? } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return mesh->invitation_key; } @@ -2131,14 +2131,14 @@ bool meshlink_set_canonical_address(meshlink_handle_t *mesh, meshlink_node_t *no canonical_address = xstrdup(address); } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); node_t *n = (node_t *)node; free(n->canonical_address); n->canonical_address = canonical_address; node_write_config(mesh, n); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return true; } @@ -2178,9 +2178,9 @@ int meshlink_get_port(meshlink_handle_t *mesh) { int port; - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); port = atoi(mesh->myport); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return port; } @@ -2204,7 +2204,7 @@ bool meshlink_set_port(meshlink_handle_t *mesh, int port) { bool rval = false; - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); if(mesh->threadstarted) { meshlink_errno = MESHLINK_EINVAL; @@ -2244,7 +2244,7 @@ bool meshlink_set_port(meshlink_handle_t *mesh, int port) { rval = config_sync(mesh, "current"); done: - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return rval && meshlink_get_port(mesh) == port; } @@ -2273,13 +2273,13 @@ char *meshlink_invite_ex(meshlink_handle_t *mesh, meshlink_submesh_t *submesh, c s = (meshlink_submesh_t *)mesh->self->submesh; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); // Check validity of the new node's name if(!check_id(name)) { logger(mesh, MESHLINK_DEBUG, "Invalid name for node.\n"); meshlink_errno = MESHLINK_EINVAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return NULL; } @@ -2287,7 +2287,7 @@ char *meshlink_invite_ex(meshlink_handle_t *mesh, meshlink_submesh_t *submesh, c if(config_exists(mesh, "current", name)) { logger(mesh, MESHLINK_DEBUG, "A host config file for %s already exists!\n", name); meshlink_errno = MESHLINK_EEXIST; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return NULL; } @@ -2295,7 +2295,7 @@ char *meshlink_invite_ex(meshlink_handle_t *mesh, meshlink_submesh_t *submesh, c if(meshlink_get_node(mesh, name)) { logger(mesh, MESHLINK_DEBUG, "A node with name %s is already known!\n", name); meshlink_errno = MESHLINK_EEXIST; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return NULL; } @@ -2305,13 +2305,13 @@ char *meshlink_invite_ex(meshlink_handle_t *mesh, meshlink_submesh_t *submesh, c if(!address) { logger(mesh, MESHLINK_DEBUG, "No Address known for ourselves!\n"); meshlink_errno = MESHLINK_ERESOLV; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return NULL; } if(!refresh_invitation_key(mesh)) { meshlink_errno = MESHLINK_EINTERNAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return NULL; } @@ -2372,7 +2372,7 @@ char *meshlink_invite_ex(meshlink_handle_t *mesh, meshlink_submesh_t *submesh, c if(!invitation_write(mesh, "current", cookiehash, &config, mesh->config_key)) { logger(mesh, MESHLINK_DEBUG, "Could not create invitation file %s: %s\n", cookiehash, strerror(errno)); meshlink_errno = MESHLINK_ESTORAGE; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return NULL; } @@ -2381,7 +2381,7 @@ char *meshlink_invite_ex(meshlink_handle_t *mesh, meshlink_submesh_t *submesh, c xasprintf(&url, "%s/%s%s", address, hash, cookie); free(address); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return url; } @@ -2395,13 +2395,13 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { return false; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); //Before doing meshlink_join make sure we are not connected to another mesh if(mesh->threadstarted) { logger(mesh, MESHLINK_ERROR, "Cannot join while started\n"); meshlink_errno = MESHLINK_EINVAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -2409,7 +2409,7 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { if(mesh->nodes->count > 1) { logger(mesh, MESHLINK_ERROR, "Already part of an existing mesh\n"); meshlink_errno = MESHLINK_EINVAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -2443,7 +2443,7 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { if(!key) { meshlink_errno = MESHLINK_EINTERNAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -2521,7 +2521,7 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { } if(mesh->sock == -1) { - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -2535,7 +2535,7 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { logger(mesh, MESHLINK_DEBUG, "Error sending request to %s port %s: %s\n", address, port, strerror(errno)); closesocket(mesh->sock); meshlink_errno = MESHLINK_ENETWORK; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -2548,7 +2548,7 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { logger(mesh, MESHLINK_DEBUG, "Cannot read greeting from peer\n"); closesocket(mesh->sock); meshlink_errno = MESHLINK_ENETWORK; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -2559,14 +2559,14 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { if(sha512(fingerprint, strlen(fingerprint), hishash)) { logger(mesh, MESHLINK_DEBUG, "Could not create hash\n%s\n", mesh->line + 2); meshlink_errno = MESHLINK_EINTERNAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } if(memcmp(hishash, mesh->hash, 18)) { logger(mesh, MESHLINK_DEBUG, "Peer has an invalid key!\n%s\n", mesh->line + 2); meshlink_errno = MESHLINK_EPEER; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -2575,21 +2575,21 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { if(!hiskey) { meshlink_errno = MESHLINK_EINTERNAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } // Start an SPTPS session if(!sptps_start(&mesh->sptps, mesh, true, false, key, hiskey, meshlink_invitation_label, sizeof(meshlink_invitation_label), invitation_send, invitation_receive)) { meshlink_errno = MESHLINK_EINTERNAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } // Feed rest of input buffer to SPTPS if(!sptps_receive_data(&mesh->sptps, mesh->buffer, mesh->blen)) { meshlink_errno = MESHLINK_EPEER; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -2603,13 +2603,13 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { logger(mesh, MESHLINK_DEBUG, "Error reading data from %s port %s: %s\n", address, port, strerror(errno)); meshlink_errno = MESHLINK_ENETWORK; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } if(!sptps_receive_data(&mesh->sptps, mesh->line, len)) { meshlink_errno = MESHLINK_EPEER; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } } @@ -2622,17 +2622,17 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { if(!mesh->success) { logger(mesh, MESHLINK_DEBUG, "Connection closed by peer, invitation cancelled.\n"); meshlink_errno = MESHLINK_EPEER; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return true; invalid: logger(mesh, MESHLINK_DEBUG, "Invalid invitation URL\n"); meshlink_errno = MESHLINK_EINVAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return false; } @@ -2650,7 +2650,7 @@ char *meshlink_export(meshlink_handle_t *mesh) { packmsg_add_str(&out, mesh->name); packmsg_add_str(&out, CORE_MESH); - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); packmsg_add_int32(&out, mesh->self->devclass); packmsg_add_bool(&out, mesh->self->status.blacklisted); @@ -2673,7 +2673,7 @@ char *meshlink_export(meshlink_handle_t *mesh) { packmsg_add_sockaddr(&out, &mesh->self->recent[i]); } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); if(!packmsg_output_ok(&out)) { logger(mesh, MESHLINK_DEBUG, "Error creating export data\n"); @@ -2727,7 +2727,7 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) { return false; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); while(count--) { const void *data; @@ -2775,7 +2775,7 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) { node_add(mesh, n); } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); free(buf); @@ -2798,7 +2798,7 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) { return; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); node_t *n; n = (node_t *)node; @@ -2806,13 +2806,13 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) { if(n == mesh->self) { logger(mesh, MESHLINK_ERROR, "%s blacklisting itself?\n", node->name); meshlink_errno = MESHLINK_EINVAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return; } if(n->status.blacklisted) { logger(mesh, MESHLINK_DEBUG, "Node %s already blacklisted\n", node->name); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return; } @@ -2841,7 +2841,7 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) { update_node_status(mesh, n); } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); } void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) { @@ -2850,14 +2850,14 @@ void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) { return; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); node_t *n = (node_t *)node; if(!n->status.blacklisted) { logger(mesh, MESHLINK_DEBUG, "Node %s was already whitelisted\n", node->name); meshlink_errno = MESHLINK_EINVAL; - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return; } @@ -2869,7 +2869,7 @@ void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) { update_node_status(mesh, n); } - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); return; } @@ -2886,14 +2886,14 @@ void meshlink_hint_address(meshlink_handle_t *mesh, meshlink_node_t *node, const return; } - pthread_mutex_lock(&(mesh->mesh_mutex)); + pthread_mutex_lock(&mesh->mutex); node_t *n = (node_t *)node; memmove(n->recent + 1, n->recent, 4 * sizeof(*n->recent)); memcpy(n->recent, addr, SALEN(*addr)); node_write_config(mesh, n); - pthread_mutex_unlock(&(mesh->mesh_mutex)); + pthread_mutex_unlock(&mesh->mutex); // @TODO do we want to fire off a connection attempt right away? } @@ -3098,10 +3098,10 @@ void meshlink_set_channel_poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *c return; } - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); channel->poll_cb = cb; utcp_set_poll_cb(channel->c, (cb || channel->aio_send) ? channel_poll : NULL); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); } void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_accept_cb_t cb) { @@ -3110,7 +3110,7 @@ void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_ac return; } - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); mesh->channel_accept_cb = cb; mesh->receive_cb = channel_receive; @@ -3120,7 +3120,7 @@ void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_ac } } - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); } void meshlink_set_channel_sndbuf(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t size) { @@ -3131,9 +3131,9 @@ void meshlink_set_channel_sndbuf(meshlink_handle_t *mesh, meshlink_channel_t *ch return; } - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); utcp_set_sndbuf(channel->c, size); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); } void meshlink_set_channel_rcvbuf(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t size) { @@ -3144,9 +3144,9 @@ void meshlink_set_channel_rcvbuf(meshlink_handle_t *mesh, meshlink_channel_t *ch return; } - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); utcp_set_rcvbuf(channel->c, size); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); } meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags) { @@ -3159,7 +3159,7 @@ meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_n return NULL; } - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); node_t *n = (node_t *)node; @@ -3169,14 +3169,14 @@ meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_n if(!n->utcp) { meshlink_errno = errno == ENOMEM ? MESHLINK_ENOMEM : MESHLINK_EINTERNAL; - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); return NULL; } } if(n->status.blacklisted) { logger(mesh, MESHLINK_ERROR, "Cannot open a channel with blacklisted node\n"); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); return NULL; } @@ -3185,7 +3185,7 @@ meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_n channel->receive_cb = cb; channel->c = utcp_connect_ex(n->utcp, port, channel_recv, channel, flags); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); if(!channel->c) { meshlink_errno = errno == ENOMEM ? MESHLINK_ENOMEM : MESHLINK_EINTERNAL; @@ -3206,9 +3206,9 @@ void meshlink_channel_shutdown(meshlink_handle_t *mesh, meshlink_channel_t *chan return; } - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); utcp_shutdown(channel->c, direction); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); } void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *channel) { @@ -3217,7 +3217,7 @@ void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *channel return; } - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); utcp_close(channel->c); @@ -3234,7 +3234,7 @@ void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *channel free(aio); } - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); free(channel); } @@ -3261,7 +3261,7 @@ ssize_t meshlink_channel_send(meshlink_handle_t *mesh, meshlink_channel_t *chann ssize_t retval; - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); /* Disallow direct calls to utcp_send() while we still have AIO active. */ if(channel->aio_send) { @@ -3270,7 +3270,7 @@ ssize_t meshlink_channel_send(meshlink_handle_t *mesh, meshlink_channel_t *chann retval = utcp_send(channel->c, data, len); } - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); if(retval < 0) { meshlink_errno = MESHLINK_ENETWORK; @@ -3296,7 +3296,7 @@ bool meshlink_channel_aio_send(meshlink_handle_t *mesh, meshlink_channel_t *chan aio->cb.buffer = cb; aio->priv = priv; - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); /* Append the AIO buffer descriptor to the end of the chain */ meshlink_aio_buffer_t **p = &channel->aio_send; @@ -3311,7 +3311,7 @@ bool meshlink_channel_aio_send(meshlink_handle_t *mesh, meshlink_channel_t *chan utcp_set_poll_cb(channel->c, channel_poll); channel_poll(channel->c, len); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); return true; } @@ -3333,7 +3333,7 @@ bool meshlink_channel_aio_fd_send(meshlink_handle_t *mesh, meshlink_channel_t *c aio->cb.fd = cb; aio->priv = priv; - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); /* Append the AIO buffer descriptor to the end of the chain */ meshlink_aio_buffer_t **p = &channel->aio_send; @@ -3348,7 +3348,7 @@ bool meshlink_channel_aio_fd_send(meshlink_handle_t *mesh, meshlink_channel_t *c utcp_set_poll_cb(channel->c, channel_poll); channel_poll(channel->c, len); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); return true; } @@ -3370,7 +3370,7 @@ bool meshlink_channel_aio_receive(meshlink_handle_t *mesh, meshlink_channel_t *c aio->cb.buffer = cb; aio->priv = priv; - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); /* Append the AIO buffer descriptor to the end of the chain */ meshlink_aio_buffer_t **p = &channel->aio_receive; @@ -3381,7 +3381,7 @@ bool meshlink_channel_aio_receive(meshlink_handle_t *mesh, meshlink_channel_t *c *p = aio; - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); return true; } @@ -3403,7 +3403,7 @@ bool meshlink_channel_aio_fd_receive(meshlink_handle_t *mesh, meshlink_channel_t aio->cb.fd = cb; aio->priv = priv; - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); /* Append the AIO buffer descriptor to the end of the chain */ meshlink_aio_buffer_t **p = &channel->aio_receive; @@ -3414,7 +3414,7 @@ bool meshlink_channel_aio_fd_receive(meshlink_handle_t *mesh, meshlink_channel_t *p = aio; - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); return true; } @@ -3454,7 +3454,7 @@ void meshlink_set_node_channel_timeout(meshlink_handle_t *mesh, meshlink_node_t node_t *n = (node_t *)node; - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); if(!n->utcp) { n->utcp = utcp_init(channel_accept, channel_pre_accept, channel_send, n); @@ -3462,7 +3462,7 @@ void meshlink_set_node_channel_timeout(meshlink_handle_t *mesh, meshlink_node_t utcp_set_user_timeout(n->utcp, timeout); - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); } void update_node_status(meshlink_handle_t *mesh, node_t *n) { @@ -3502,7 +3502,7 @@ void meshlink_enable_discovery(meshlink_handle_t *mesh, bool enable) { return; } - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); if(mesh->discovery == enable) { goto end; @@ -3519,7 +3519,7 @@ void meshlink_enable_discovery(meshlink_handle_t *mesh, bool enable) { mesh->discovery = enable; end: - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); #else (void)mesh; (void)enable; @@ -3538,10 +3538,10 @@ void meshlink_set_dev_class_timeouts(meshlink_handle_t *mesh, dev_class_t devcla return; } - pthread_mutex_lock(&mesh->mesh_mutex); + pthread_mutex_lock(&mesh->mutex); mesh->dev_class_traits[devclass].pinginterval = pinginterval; mesh->dev_class_traits[devclass].pingtimeout = pingtimeout; - pthread_mutex_unlock(&mesh->mesh_mutex); + pthread_mutex_unlock(&mesh->mutex); } void handle_network_change(meshlink_handle_t *mesh, bool online) { diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index e7b184e4..dd8c7d32 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -94,7 +94,7 @@ struct meshlink_handle { void *priv; // private members - pthread_mutex_t mesh_mutex; + pthread_mutex_t mutex; event_loop_t loop; struct node_t *self; meshlink_log_cb_t log_cb; diff --git a/src/net.c b/src/net.c index 76f88475..80490efa 100644 --- a/src/net.c +++ b/src/net.c @@ -708,7 +708,7 @@ int main_loop(meshlink_handle_t *mesh) { mesh->datafromapp.signum = 0; signal_add(&mesh->loop, &mesh->datafromapp, meshlink_send_from_queue, mesh, mesh->datafromapp.signum); - if(!event_loop_run(&mesh->loop, &mesh->mesh_mutex)) { + if(!event_loop_run(&mesh->loop, &mesh->mutex)) { logger(mesh, MESHLINK_ERROR, "Error while waiting for input: %s", strerror(errno)); abort(); signal_del(&mesh->loop, &mesh->datafromapp);