mesh->confbase = xstrdup(confbase);
mesh->name = xstrdup(name);
pthread_mutex_init ( &(mesh->outpacketqueue_mutex), NULL);
+ pthread_mutex_init ( &(mesh->nodes_mutex), NULL);
+ mesh->threadstarted = false;
event_loop_init(&mesh->loop);
mesh->loop.data = mesh;
return false;
}
+ mesh->threadstarted=true;
+
return true;
}
size_t meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_t **nodes, size_t nmemb) {
size_t i = 0;
+ //lock mesh->nodes
+ pthread_mutex_lock(&(mesh->nodes_mutex));
+
for splay_each(node_t, n, mesh->nodes) {
if(i < nmemb)
nodes[i] = (meshlink_node_t *)n;
i++;
}
+ pthread_mutex_unlock(&(mesh->nodes_mutex));
+
return i;
}
*port++ = 0;
}
- if(!*port)
+ if(!port)
port = "655";
if(!b64decode(slash, mesh->hash, 18) || !b64decode(slash + 24, mesh->cookie, 18))
char *b64key = ecdsa_get_base64_public_key(key);
+ //Before doing meshlink_join make sure we are not connected to another mesh
+ if ( mesh->threadstarted ){
+ goto invalid;
+ }
+
// Connect to the meshlink daemon mentioned in the URL.
struct addrinfo *ai = str2addrinfo(address, port, SOCK_STREAM);
if(!ai)
return true;
invalid:
- fprintf(stderr, "Invalid invitation URL.\n");
+ fprintf(stderr, "Invalid invitation URL or you are already connected to a Mesh ?\n");
return false;
}