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;
int s = socket_in_netns(aip->ai_family, aip->ai_socktype, aip->ai_protocol, mesh->netns);
+#ifdef SO_NOSIGPIPE
+ int nosigpipe = 1;
+ setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe));
+#endif
+
if(s >= 0) {
set_timeout(s, 5000);
}
}
+#ifdef HAVE_GETIFADDRS
+struct getifaddrs_in_netns_params {
+ struct ifaddrs **ifa;
+ int netns;
+};
+
+#ifdef HAVE_SETNS
+static void *getifaddrs_in_netns_thread(void *arg) {
+ struct getifaddrs_in_netns_params *params = arg;
+
+ if(setns(params->netns, CLONE_NEWNET) == -1) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ }
+
+ if(getifaddrs(params->ifa) != 0) {
+ *params->ifa = NULL;
+ }
+
+ return NULL;
+}
+#endif // HAVE_SETNS
+
+static int getifaddrs_in_netns(struct ifaddrs **ifa, int netns) {
+ if(netns == -1) {
+ return getifaddrs(ifa);
+ }
+
+#ifdef HAVE_SETNS
+ struct getifaddrs_in_netns_params params = {ifa, netns};
+ pthread_t thr;
+
+ if(pthread_create(&thr, NULL, getifaddrs_in_netns_thread, ¶ms) == 0) {
+ if(pthread_join(thr, NULL) != 0) {
+ abort();
+ }
+ }
+
+ return *params.ifa ? 0 : -1;
+#else
+ return -1;
+#endif // HAVE_SETNS
+
+}
+#endif
+
char *meshlink_get_local_address_for_family(meshlink_handle_t *mesh, int family) {
(void)mesh;
if(!success) {
struct ifaddrs *ifa = NULL;
- getifaddrs(&ifa);
+ getifaddrs_in_netns(&ifa, mesh->netns);
for(struct ifaddrs *ifap = ifa; ifap; ifap = ifap->ifa_next) {
sockaddr_t *sa = (sockaddr_t *)ifap->ifa_addr;
- if(sa->sa.sa_family != family) {
+ if(!sa || sa->sa.sa_family != family) {
continue;
}
}
/* Ensure the configuration directory metadata is on disk */
- if(!config_sync(mesh, "current") || !sync_path(mesh->confbase)) {
+ if(!config_sync(mesh, "current") || (mesh->confbase && !sync_path(mesh->confbase))) {
return false;
}
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;
}
/// Device class traits
static const dev_class_traits_t default_class_traits[DEV_CLASS_COUNT] = {
- { .pingtimeout = 5, .pinginterval = 60, .min_connects = 3, .max_connects = 10000, .edge_weight = 1 }, // DEV_CLASS_BACKBONE
- { .pingtimeout = 5, .pinginterval = 60, .min_connects = 3, .max_connects = 100, .edge_weight = 3 }, // DEV_CLASS_STATIONARY
- { .pingtimeout = 5, .pinginterval = 60, .min_connects = 3, .max_connects = 3, .edge_weight = 6 }, // DEV_CLASS_PORTABLE
- { .pingtimeout = 5, .pinginterval = 60, .min_connects = 1, .max_connects = 1, .edge_weight = 9 }, // DEV_CLASS_UNKNOWN
+ { .pingtimeout = 5, .pinginterval = 60, .maxtimeout = 900, .min_connects = 3, .max_connects = 10000, .edge_weight = 1 }, // DEV_CLASS_BACKBONE
+ { .pingtimeout = 5, .pinginterval = 60, .maxtimeout = 900, .min_connects = 3, .max_connects = 100, .edge_weight = 3 }, // DEV_CLASS_STATIONARY
+ { .pingtimeout = 5, .pinginterval = 60, .maxtimeout = 900, .min_connects = 3, .max_connects = 3, .edge_weight = 6 }, // DEV_CLASS_PORTABLE
+ { .pingtimeout = 5, .pinginterval = 60, .maxtimeout = 900, .min_connects = 1, .max_connects = 1, .edge_weight = 9 }, // DEV_CLASS_UNKNOWN
};
meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const char *appname, dev_class_t devclass) {
// 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);
+ pthread_mutexattr_init(&attr);
+
+ if(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) {
+ abort();
+ }
- assert(pthread_mutex_init(&mesh->discovery_mutex, NULL) == 0);
- assert(pthread_cond_init(&mesh->discovery_cond, NULL) == 0);
+ pthread_mutex_init(&mesh->mutex, &attr);
+ pthread_cond_init(&mesh->cond, NULL);
- assert(pthread_cond_init(&mesh->adns_cond, NULL) == 0);
+ pthread_mutex_init(&mesh->discovery_mutex, NULL);
+ pthread_cond_init(&mesh->discovery_cond, NULL);
+
+ 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;
}
return false;
}
+ // Reset node connection timers
+ for splay_each(node_t, n, mesh->nodes) {
+ n->last_connect_try = 0;
+ }
+
// TODO: open listening sockets first
//Check that a valid name is set
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);
+}
+
+void meshlink_set_blacklisted_cb(struct meshlink_handle *mesh, meshlink_blacklisted_cb_t cb) {
+ if(!mesh) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return;
+ }
+
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
+ mesh->blacklisted_cb = cb;
+ 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;
}
return false;
}
+static bool search_node_by_blacklisted(const node_t *node, const void *condition) {
+ return *(bool *)condition == node->status.blacklisted;
+}
+
static bool search_node_by_submesh(const node_t *node, const void *condition) {
if(condition == node->submesh) {
return true;
return meshlink_get_all_nodes_by_condition(mesh, &range, nodes, nmemb, search_node_by_last_reachable);
}
+meshlink_node_t **meshlink_get_all_nodes_by_blacklisted(meshlink_handle_t *mesh, bool blacklisted, meshlink_node_t **nodes, size_t *nmemb) {
+ if(!mesh || !nmemb) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ }
+
+ return meshlink_get_all_nodes_by_condition(mesh, &blacklisted, nodes, nmemb, search_node_by_blacklisted);
+}
+
dev_class_t meshlink_get_node_dev_class(meshlink_handle_t *mesh, meshlink_node_t *node) {
if(!mesh || !node) {
meshlink_errno = MESHLINK_EINVAL;
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;
}
+bool meshlink_get_node_blacklisted(meshlink_handle_t *mesh, meshlink_node_t *node) {
+ if(!mesh) {
+ meshlink_errno = MESHLINK_EINVAL;
+ }
+
+ if(!node) {
+ return mesh->default_blacklist;
+ }
+
+ bool blacklisted;
+
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
+ blacklisted = ((node_t *)node)->status.blacklisted;
+
+ pthread_mutex_unlock(&mesh->mutex);
+
+ return blacklisted;
+}
+
meshlink_submesh_t *meshlink_get_node_submesh(meshlink_handle_t *mesh, meshlink_node_t *node) {
if(!mesh || !node) {
meshlink_errno = MESHLINK_EINVAL;
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;
}
char *canonical_address;
- if(port) {
- xasprintf(&canonical_address, "%s %s", address, port);
- } else {
- canonical_address = xstrdup(address);
- }
+ xasprintf(&canonical_address, "%s %s", address, port ? port : mesh->myport);
- 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");
+}
+
+bool meshlink_clear_canonical_address(meshlink_handle_t *mesh, meshlink_node_t *node) {
+ if(!mesh || !node) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return false;
+ }
+
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
+ node_t *n = (node_t *)node;
+ free(n->canonical_address);
+ n->canonical_address = NULL;
+
+ if(!node_write_config(mesh, n)) {
+ pthread_mutex_unlock(&mesh->mutex);
+ return false;
+ }
+
+ 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) {
continue;
}
+#ifdef SO_NOSIGPIPE
+ int nosigpipe = 1;
+ setsockopt(state.sock, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe));
+#endif
+
set_timeout(state.sock, 5000);
if(connect(state.sock, aip->ai_addr, aip->ai_addrlen)) {
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);
*/
for list_each(connection_t, c, mesh->connections) {
if(c->node == n) {
+ if(c->status.active) {
+ send_error(mesh, c, BLACKLISTED, "blacklisted");
+ }
+
shutdown(c->socket, SHUT_RDWR);
}
}
mesh->node_status_cb(mesh, (meshlink_node_t *)n, false);
}
+ /* Remove any outstanding invitations */
+ invitation_purge_node(mesh, n->name);
+
return node_write_config(mesh, n) && config_sync(mesh, "current");
}
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 any pending invitations */
+ invitation_purge_node(mesh, n->name);
+
/* 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?
}
(void)port;
node_t *n = utcp->priv;
meshlink_handle_t *mesh = n->mesh;
- return mesh->channel_accept_cb;
+
+ if(mesh->channel_accept_cb && mesh->channel_listen_cb) {
+ return mesh->channel_listen_cb(mesh, (meshlink_node_t *)n, port);
+ } else {
+ return mesh->channel_accept_cb;
+ }
}
/* Finish one AIO buffer, return true if the channel is still open. */
}
if(sent != (ssize_t)todo) {
- /* We should never get a partial send at this point */
- assert(sent <= 0);
-
/* Sending failed, abort all outstanding AIO buffers and send a poll callback. */
if(!aio_abort(mesh, channel, &channel->aio_send)) {
return;
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_listen_cb(meshlink_handle_t *mesh, meshlink_channel_listen_cb_t cb) {
+ if(!mesh) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return;
+ }
+
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
+ mesh->channel_listen_cb = cb;
+
+ 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);
}
-extern void meshlink_set_inviter_commits_first(struct meshlink_handle *mesh, bool inviter_commits_first) {
+void meshlink_set_dev_class_maxtimeout(struct meshlink_handle *mesh, dev_class_t devclass, int maxtimeout) {
+ if(!mesh || devclass < 0 || devclass >= DEV_CLASS_COUNT) {
+ meshlink_errno = EINVAL;
+ return;
+ }
+
+ if(maxtimeout < 0) {
+ meshlink_errno = EINVAL;
+ return;
+ }
+
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
+ mesh->dev_class_traits[devclass].maxtimeout = maxtimeout;
+ pthread_mutex_unlock(&mesh->mutex);
+}
+
+void meshlink_reset_timers(struct meshlink_handle *mesh) {
+ if(!mesh) {
+ return;
+ }
+
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
+ handle_network_change(mesh, true);
+ pthread_mutex_unlock(&mesh->mutex);
+}
+
+void meshlink_set_inviter_commits_first(struct meshlink_handle *mesh, bool inviter_commits_first) {
if(!mesh) {
meshlink_errno = EINVAL;
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) {
}
retry(mesh);
+ signal_trigger(&mesh->loop, &mesh->datafromapp);
}
void call_error_cb(meshlink_handle_t *mesh, meshlink_errno_t cb_errno) {