X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink.c;h=cd5b5642538a97ef441995bba9dca5c26e634e99;hb=7db92fb1932065e40cd4709989e429fca2d49778;hp=c88059b1e02fe0be95777a15d10a1848d9d16ec8;hpb=33fc9a1313bdc263c47ab8939b8555e679596452;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index c88059b1..cd5b5642 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -40,6 +40,9 @@ typedef struct { #include "xalloc.h" #include "ed25519/sha512.h" +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif //TODO: this can go away completely const var_t variables[] = { @@ -426,6 +429,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; } @@ -548,7 +552,7 @@ static bool finalize_join(meshlink_handle_t *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); @@ -562,7 +566,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: @@ -793,6 +797,11 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name) { if(!read_server_config(mesh)) return meshlink_close(mesh), NULL; +#ifdef HAVE_MINGW + struct WSAData wsa_state; + WSAStartup(MAKEWORD(2, 2), &wsa_state); +#endif + // Setup up everything // TODO: we should not open listening sockets yet @@ -827,7 +836,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 @@ -843,6 +857,10 @@ void meshlink_close(meshlink_handle_t *mesh) { exit_configuration(&mesh->config); event_loop_exit(&mesh->loop); + +#ifdef HAVE_MINGW + WSACleanup(); +#endif } void meshlink_set_receive_cb(meshlink_handle_t *mesh, meshlink_receive_cb_t cb) { @@ -1242,6 +1260,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) {