pthread_t thr;
if(pthread_create(&thr, NULL, socket_in_netns_thread, ¶ms) == 0) {
- assert(pthread_join(thr, NULL) == 0);
+ if(pthread_join(thr, NULL) != 0) {
+ abort();
+ }
}
return params.fd;
return false;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
// Create hash for the new key
void *new_config_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;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
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;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
if(!config_rename(mesh, "current", "old")) {
logger(mesh, MESHLINK_ERROR, "Cannot rename %s/current to %s/old\n", mesh->confbase, mesh->confbase);
meshlink_errno = MESHLINK_ESTORAGE;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
if(!config_rename(mesh, "new", "current")) {
logger(mesh, MESHLINK_ERROR, "Cannot rename %s/new to %s/current\n", mesh->confbase, mesh->confbase);
meshlink_errno = MESHLINK_ESTORAGE;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
// Cleanup the "old" confbase sub-directory
if(!config_destroy(mesh->confbase, "old")) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
free(mesh->config_key);
mesh->config_key = new_config_key;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return true;
}
// initialize mutexes and conds
pthread_mutexattr_t attr;
- assert(pthread_mutexattr_init(&attr) == 0);
- assert(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) == 0);
- assert(pthread_mutex_init(&mesh->mutex, &attr) == 0);
- assert(pthread_cond_init(&mesh->cond, NULL) == 0);
+ pthread_mutexattr_init(&attr);
+
+ if(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) {
+ abort();
+ }
+
+ pthread_mutex_init(&mesh->mutex, &attr);
+ pthread_cond_init(&mesh->cond, NULL);
- assert(pthread_mutex_init(&mesh->discovery_mutex, NULL) == 0);
- assert(pthread_cond_init(&mesh->discovery_cond, NULL) == 0);
+ pthread_mutex_init(&mesh->discovery_mutex, NULL);
+ pthread_cond_init(&mesh->discovery_cond, NULL);
- assert(pthread_cond_init(&mesh->adns_cond, NULL) == 0);
+ pthread_cond_init(&mesh->adns_cond, NULL);
mesh->threadstarted = false;
event_loop_init(&mesh->loop);
}
//lock mesh->nodes
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
s = (meshlink_submesh_t *)create_submesh(mesh, submesh);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return s;
}
#ifdef HAVE_SETNS
if(setns(mesh->netns, CLONE_NEWNET) != 0) {
- assert(pthread_cond_signal(&mesh->cond) == 0);
+ pthread_cond_signal(&mesh->cond);
return NULL;
}
#else
- assert(pthread_cond_signal(&mesh->cond) == 0);
+ pthread_cond_signal(&mesh->cond);
return NULL;
#endif // HAVE_SETNS
}
#endif
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
logger(mesh, MESHLINK_DEBUG, "Starting main_loop...\n");
- assert(pthread_cond_broadcast(&mesh->cond) == 0);
+ pthread_cond_broadcast(&mesh->cond);
main_loop(mesh);
logger(mesh, MESHLINK_DEBUG, "main_loop returned.\n");
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
#if HAVE_CATTA
logger(mesh, MESHLINK_DEBUG, "meshlink_start called\n");
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
assert(mesh->self);
assert(mesh->private_key);
if(mesh->threadstarted) {
logger(mesh, MESHLINK_DEBUG, "thread was already running\n");
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return true;
}
if(!mesh->name) {
logger(mesh, MESHLINK_DEBUG, "No name given!\n");
meshlink_errno = MESHLINK_EINVAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
// Ensure we have a decent amount of stack space. Musl's default of 80 kB is too small.
pthread_attr_t attr;
- assert(pthread_attr_init(&attr) == 0);
- assert(pthread_attr_setstacksize(&attr, 1024 * 1024) == 0);
+ pthread_attr_init(&attr);
+ pthread_attr_setstacksize(&attr, 1024 * 1024);
if(pthread_create(&mesh->thread, &attr, meshlink_main_loop, mesh) != 0) {
logger(mesh, MESHLINK_DEBUG, "Could not start thread: %s\n", strerror(errno));
memset(&mesh->thread, 0, sizeof(mesh)->thread);
meshlink_errno = MESHLINK_EINTERNAL;
event_loop_stop(&mesh->loop);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
- assert(pthread_cond_wait(&mesh->cond, &mesh->mutex) == 0);
+ pthread_cond_wait(&mesh->cond, &mesh->mutex);
mesh->threadstarted = true;
// Ensure we are considered reachable
graph(mesh);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return true;
}
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
logger(mesh, MESHLINK_DEBUG, "meshlink_stop called\n");
// Shut down the main thread
if(mesh->threadstarted) {
// Wait for the main thread to finish
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
- assert(pthread_join(mesh->thread, NULL) == 0);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
+
+ if(pthread_join(mesh->thread, NULL) != 0) {
+ abort();
+ }
+
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
mesh->threadstarted = false;
}
}
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_close(meshlink_handle_t *mesh) {
meshlink_stop(mesh);
// lock is not released after this
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
// Close and free all resources used.
main_config_unlock(mesh);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
- assert(pthread_mutex_destroy(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
+ pthread_mutex_destroy(&mesh->mutex);
memset(mesh, 0, sizeof(*mesh));
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->receive_cb = cb;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_connection_try_cb(meshlink_handle_t *mesh, meshlink_connection_try_cb_t cb) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->connection_try_cb = cb;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_node_status_cb(meshlink_handle_t *mesh, meshlink_node_status_cb_t cb) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->node_status_cb = cb;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_node_pmtu_cb(meshlink_handle_t *mesh, meshlink_node_pmtu_cb_t cb) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->node_pmtu_cb = cb;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_node_duplicate_cb(meshlink_handle_t *mesh, meshlink_node_duplicate_cb_t cb) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->node_duplicate_cb = cb;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ 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) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->log_cb = cb;
mesh->log_level = cb ? level : 0;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
} else {
global_log_cb = cb;
global_log_level = cb ? level : 0;
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->error_cb = cb;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
static bool prepare_packet(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len, vpn_packet_t *packet) {
return -1;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = (node_t *)destination;
if(!n->status.reachable) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return 0;
} else if(n->mtuprobes > 30 && n->minmtu) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return n->minmtu;
} else {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return MTU;
}
}
return NULL;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = (node_t *)node;
if(!node_read_public_key(mesh, n) || !n->ecdsa) {
meshlink_errno = MESHLINK_EINTERNAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
meshlink_errno = MESHLINK_EINTERNAL;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return fingerprint;
}
node_t *n = NULL;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
n = lookup_node(mesh, (char *)name); // TODO: make lookup_node() use const
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!n) {
meshlink_errno = MESHLINK_ENOENT;
meshlink_submesh_t *submesh = NULL;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
submesh = (meshlink_submesh_t *)lookup_submesh(mesh, name);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!submesh) {
meshlink_errno = MESHLINK_ENOENT;
meshlink_node_t **result;
//lock mesh->nodes
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
*nmemb = mesh->nodes->count;
result = realloc(nodes, *nmemb * sizeof(*nodes));
meshlink_errno = MESHLINK_ENOMEM;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return result;
}
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;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
*nmemb = 0;
if(*nmemb == 0) {
free(nodes);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return NULL;
}
meshlink_errno = MESHLINK_ENOMEM;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return result;
}
dev_class_t devclass;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
devclass = ((node_t *)node)->devclass;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return devclass;
}
node_t *n = (node_t *)node;
bool reachable;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
reachable = n->status.reachable && !n->status.blacklisted;
if(last_reachable) {
*last_unreachable = n->last_unreachable;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return reachable;
}
return false;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(!ecdsa_sign(mesh->private_key, data, len, signature)) {
meshlink_errno = MESHLINK_EINTERNAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
*siglen = MESHLINK_SIGLEN;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return true;
}
return false;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
bool rval = false;
rval = ecdsa_verify(((struct node_t *)source)->ecdsa, data, len, signature);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return rval;
}
static bool refresh_invitation_key(meshlink_handle_t *mesh) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
size_t count = invitation_purge_old(mesh, time(NULL) - mesh->invitation_timeout);
// TODO: Update invitation key if necessary?
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return mesh->invitation_key;
}
canonical_address = xstrdup(address);
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = (node_t *)node;
free(n->canonical_address);
n->canonical_address = canonical_address;
if(!node_write_config(mesh, n)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return config_sync(mesh, "current");
}
combo = xstrdup(address);
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(!mesh->invitation_addresses) {
mesh->invitation_addresses = list_alloc((list_action_t)free);
}
list_insert_tail(mesh->invitation_addresses, combo);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return true;
}
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(mesh->invitation_addresses) {
list_delete_list(mesh->invitation_addresses);
mesh->invitation_addresses = NULL;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
bool meshlink_add_address(meshlink_handle_t *mesh, const char *address) {
int port;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
port = atoi(mesh->myport);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return port;
}
bool rval = false;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(mesh->threadstarted) {
meshlink_errno = MESHLINK_EINVAL;
rval = config_sync(mesh, "current");
done:
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return rval && meshlink_get_port(mesh) == port;
}
s = (meshlink_submesh_t *)mesh->self->submesh;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
// Check validity of the new node's name
if(!check_id(name)) {
logger(mesh, MESHLINK_ERROR, "Invalid name for node.\n");
meshlink_errno = MESHLINK_EINVAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return NULL;
}
if(config_exists(mesh, "current", name)) {
logger(mesh, MESHLINK_ERROR, "A host config file for %s already exists!\n", name);
meshlink_errno = MESHLINK_EEXIST;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return NULL;
}
if(lookup_node(mesh, name)) {
logger(mesh, MESHLINK_ERROR, "A node with name %s is already known!\n", name);
meshlink_errno = MESHLINK_EEXIST;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return NULL;
}
if(!address) {
logger(mesh, MESHLINK_ERROR, "No Address known for ourselves!\n");
meshlink_errno = MESHLINK_ERESOLV;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return NULL;
}
if(!refresh_invitation_key(mesh)) {
meshlink_errno = MESHLINK_EINTERNAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return NULL;
}
if(mesh->self->status.dirty) {
if(!node_write_config(mesh, mesh->self)) {
logger(mesh, MESHLINK_ERROR, "Could not write our own host config file!\n");
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return NULL;
}
}
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;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return NULL;
}
xasprintf(&url, "%s/%s%s", address, hash, cookie);
free(address);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return url;
}
//TODO: think of a better name for this variable, or of a different way to tokenize the invitation URL.
char copy[strlen(invitation) + 1];
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
//Before doing meshlink_join make sure we are not connected to another mesh
if(mesh->threadstarted) {
ecdsa_free(key);
closesocket(state.sock);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return true;
invalid:
closesocket(state.sock);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
packmsg_add_str(&out, mesh->name);
packmsg_add_str(&out, CORE_MESH);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
packmsg_add_int32(&out, mesh->self->devclass);
packmsg_add_bool(&out, mesh->self->status.blacklisted);
packmsg_add_int64(&out, 0);
packmsg_add_int64(&out, 0);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!packmsg_output_ok(&out)) {
logger(mesh, MESHLINK_DEBUG, "Error creating export data\n");
return false;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
while(count--) {
const void *data2;
node_add(mesh, n);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
free(buf);
return false;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(!blacklist(mesh, (node_t *)node)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name);
return true;
return false;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = lookup_node(mesh, (char *)name);
}
if(!blacklist(mesh, (node_t *)n)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", name);
return true;
return false;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(!whitelist(mesh, (node_t *)node)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_DEBUG, "Whitelisted %s.\n", node->name);
return true;
return false;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = lookup_node(mesh, (char *)name);
}
if(!whitelist(mesh, (node_t *)n)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_DEBUG, "Whitelisted %s.\n", name);
return true;
node_t *n = (node_t *)node;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Check that the node is not reachable */
if(n->status.reachable || n->connection) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_WARNING, "Could not forget %s: still reachable", n->name);
return false;
}
/* Check that we don't have any active UTCP connections */
if(n->utcp && utcp_is_active(n->utcp)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_WARNING, "Could not forget %s: active UTCP connections", n->name);
return false;
}
/* Check that we have no active connections to this node */
for list_each(connection_t, c, mesh->connections) {
if(c->node == n) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_WARNING, "Could not forget %s: active connection", n->name);
return false;
}
/* Delete the config file for this node */
if(!config_delete(mesh, "current", n->name)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
/* Delete the node struct and any remaining edges referencing this node */
node_del(mesh, n);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return config_sync(mesh, "current");
}
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = (node_t *)node;
}
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
// @TODO do we want to fire off a connection attempt right away?
}
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
channel->poll_cb = cb;
utcp_set_poll_cb(channel->c, (cb || channel->aio_send) ? channel_poll : NULL);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_accept_cb_t cb) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->channel_accept_cb = cb;
mesh->receive_cb = channel_receive;
}
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_channel_sndbuf(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t size) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
utcp_set_sndbuf(channel->c, size);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_channel_rcvbuf(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t size) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
utcp_set_rcvbuf(channel->c, size);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ 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) {
return NULL;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = (node_t *)node;
if(!n->utcp) {
meshlink_errno = errno == ENOMEM ? MESHLINK_ENOMEM : MESHLINK_EINTERNAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return NULL;
}
}
if(n->status.blacklisted) {
logger(mesh, MESHLINK_ERROR, "Cannot open a channel with blacklisted node\n");
meshlink_errno = MESHLINK_EBLACKLISTED;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return NULL;
}
channel->c = utcp_connect_ex(n->utcp, port, channel_recv, channel, flags);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!channel->c) {
meshlink_errno = errno == ENOMEM ? MESHLINK_ENOMEM : MESHLINK_EINTERNAL;
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
utcp_shutdown(channel->c, direction);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *channel) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(channel->c) {
utcp_close(channel->c);
free(channel);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
ssize_t meshlink_channel_send(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) {
ssize_t retval;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Disallow direct calls to utcp_send() while we still have AIO active. */
if(channel->aio_send) {
retval = utcp_send(channel->c, data, len);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(retval < 0) {
meshlink_errno = MESHLINK_ENETWORK;
aio->cb.buffer = cb;
aio->priv = priv;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_send;
channel_poll(channel->c, todo);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return true;
}
aio->cb.fd = cb;
aio->priv = priv;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_send;
channel_poll(channel->c, left);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return true;
}
aio->cb.buffer = cb;
aio->priv = priv;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_receive;
*p = aio;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return true;
}
aio->cb.fd = cb;
aio->priv = priv;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_receive;
*p = aio;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return true;
}
node_t *n = (node_t *)node;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(!n->utcp) {
n->utcp = utcp_init(channel_accept, channel_pre_accept, channel_send, n);
utcp_set_user_timeout(n->utcp, timeout);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void update_node_status(meshlink_handle_t *mesh, node_t *n) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(mesh->discovery == enable) {
goto end;
mesh->discovery = enable;
end:
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
#else
(void)mesh;
(void)enable;
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->dev_class_traits[devclass].pinginterval = pinginterval;
mesh->dev_class_traits[devclass].pingtimeout = pingtimeout;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_dev_class_fast_retry_period(meshlink_handle_t *mesh, dev_class_t devclass, int fast_retry_period) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->dev_class_traits[devclass].fast_retry_period = fast_retry_period;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_dev_class_maxtimeout(struct meshlink_handle *mesh, dev_class_t devclass, int maxtimeout) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->dev_class_traits[devclass].maxtimeout = maxtimeout;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
extern void meshlink_set_inviter_commits_first(struct meshlink_handle *mesh, bool inviter_commits_first) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->inviter_commits_first = inviter_commits_first;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_external_address_discovery_url(struct meshlink_handle *mesh, const char *url) {
return;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
free(mesh->external_address_url);
mesh->external_address_url = url ? xstrdup(url) : NULL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_scheduling_granularity(struct meshlink_handle *mesh, long granularity) {