X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink.c;h=816f77abe630540d7f3f2724be887d505c0cd4e0;hb=12fd793a46d1695bedb96a5d9531dfd9f3efd7be;hp=8b731900a36f7bbab7e5e49393c99409a2d86589;hpb=09bf4a7943f52639cbed7bd85f262f4d29634e35;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index 8b731900..816f77ab 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -426,6 +426,7 @@ static bool finalize_join(meshlink_handle_t *mesh) { FILE *fh = fopen(filename, "w"); if(!fh) { fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno)); + fclose(f); return false; } @@ -536,12 +537,19 @@ static bool finalize_join(meshlink_handle_t *mesh) { sptps_send_record(&(mesh->sptps), 1, b64key, strlen(b64key)); free(b64key); + free(mesh->self->name); + free(mesh->self->connection->name); + mesh->self->name = xstrdup(name); + mesh->self->connection->name = xstrdup(name); + fprintf(stderr, "Configuration stored in: %s\n", mesh->confbase); + load_all_nodes(mesh); + return true; } -static bool invitation_send(void *handle, uint8_t type, const char *data, size_t len) { +static bool invitation_send(void *handle, uint8_t type, const void *data, size_t len) { meshlink_handle_t* mesh = handle; while(len) { int result = send(mesh->sock, data, len, 0); @@ -555,7 +563,7 @@ static bool invitation_send(void *handle, uint8_t type, const char *data, size_t return true; } -static bool invitation_receive(void *handle, uint8_t type, const char *msg, uint16_t len) { +static bool invitation_receive(void *handle, uint8_t type, const void *msg, uint16_t len) { meshlink_handle_t* mesh = handle; switch(type) { case SPTPS_HANDSHAKE: @@ -820,7 +828,12 @@ bool meshlink_start(meshlink_handle_t *mesh) { } void meshlink_stop(meshlink_handle_t *mesh) { - // TODO: close the listening sockets to signal the main thread to shut down + // Shut down the listening sockets to signal the main thread to shut down + + for(int i = 0; i < mesh->listen_sockets; i++) { + shutdown(mesh->listen_socket[i].tcp.fd, SHUT_RDWR); + shutdown(mesh->listen_socket[i].udp.fd, SHUT_RDWR); + } // Wait for the main thread to finish @@ -878,7 +891,15 @@ meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name) { } size_t meshlink_get_all_nodes(meshlink_handle_t *mesh, meshlink_node_t **nodes, size_t nmemb) { - return 0; + size_t i = 0; + + for splay_each(node_t, n, mesh->nodes) { + if(i < nmemb) + nodes[i] = (meshlink_node_t *)n; + i++; + } + + return i; } char *meshlink_sign(meshlink_handle_t *mesh, const char *data, size_t len) { @@ -1227,6 +1248,15 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) { } void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) { + node_t *n; + n = (node_t*)node; + n->status.blacklisted=true; + fprintf(stderr, "Blacklisted %s.\n",node->name); + + //Make blacklisting persistent in the config file + append_config_file(mesh, n->name, "blacklisted", "yes"); + return; + } static void __attribute__((constructor)) meshlink_init(void) {