X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink.c;h=b1f5c918fa68dd9d1d29e09a710c60d73b3bd51e;hb=230b5907e242aa48bb8c8d09450fbd3767e9c24a;hp=9b13dca1652d22658f282be6cfbfbce02c81357e;hpb=5f3e39a3b08c7d42d23a18a3e5e950e099bc8c57;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index 9b13dca1..b1f5c918 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -2310,7 +2310,15 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) { //Before doing meshlink_join make sure we are not connected to another mesh if(mesh->threadstarted) { - logger(mesh, MESHLINK_DEBUG, "Already connected to a mesh\n"); + logger(mesh, MESHLINK_ERROR, "Cannot join while started\n"); + meshlink_errno = MESHLINK_EINVAL; + pthread_mutex_unlock(&(mesh->mesh_mutex)); + return false; + } + + // Refuse to join a mesh if we are already part of one. We are part of one if we know at least one other node. + 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)); return false; @@ -3082,6 +3090,21 @@ end: #endif } +void handle_network_change(meshlink_handle_t *mesh, bool online) { + if(!mesh->connections) { + return; + } + + if(online) { + retry(mesh); + } else { + // We are off-line. Terminate all active connections. + for list_each(connection_t, c, mesh->connections) { + terminate_connection(mesh, c, false); + } + } +} + static void __attribute__((constructor)) meshlink_init(void) { crypto_init(); unsigned int seed;