]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
only allow meshlink_join() when the library thread is not running
[meshlink] / src / meshlink.c
index fc8408ad1309843d9641df75a47323f0411b192d..9a53d67aefae1c7e4e238fe9c784436c843bd58c 100644 (file)
@@ -1158,7 +1158,7 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) {
                        *port++ = 0;
        }
 
-       if(!*port)
+       if(!port)
                port = "655";
 
        if(!b64decode(slash, mesh->hash, 18) || !b64decode(slash + 24, mesh->cookie, 18))
@@ -1171,6 +1171,12 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) {
 
        char *b64key = ecdsa_get_base64_public_key(key);
 
+       //Before doing meshlink_join make sure we are not connected to another mesh
+       if ( pthread_kill(mesh->thread,0) == 0){
+               printf("HELLO\n");
+               goto invalid;
+       }
+
        // Connect to the meshlink daemon mentioned in the URL.
        struct addrinfo *ai = str2addrinfo(address, port, SOCK_STREAM);
        if(!ai)
@@ -1261,7 +1267,7 @@ bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) {
        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;
 }