X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fdiscovery.c;h=6b98a2768f178de342533e2574c060bb55b880a4;hb=1e2076334fd067db863956c7bda77fcbcc9a52fc;hp=2af4702365e6b652c543bb9279371f12f19b83ad;hpb=9cde0d32cf209388cc59b06b7dcb0c3432f97da5;p=meshlink diff --git a/src/discovery.c b/src/discovery.c index 2af47023..6b98a276 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -21,11 +21,11 @@ #define MESHLINK_MDNS_NAME_KEY "name" #define MESHLINK_MDNS_FINGERPRINT_KEY "fingerprint" -static void generate_rand_string(char *buffer, size_t size) { +static void generate_rand_string(meshlink_handle_t *mesh, char *buffer, size_t size) { assert(size); for(size_t i = 0; i < (size - 1); ++i) { - buffer[i] = 'a' + (rand() % ('z' - 'a' + 1)); + buffer[i] = 'a' + prng(mesh, 'z' - 'a' + 1); } buffer[size - 1] = '\0'; @@ -114,8 +114,6 @@ done: free(fingerprint); free(txt_name); free(txt_fingerprint); - - pthread_mutex_unlock(&(mesh->mesh_mutex)); } static void discovery_server_callback(CattaServer *server, CattaServerState state, void *userdata) { @@ -141,7 +139,7 @@ static void discovery_server_callback(CattaServer *server, CattaServerState stat case CATTA_SERVER_COLLISION: { /* A host name collision happened. Let's pick a new name for the server */ char hostname[17]; - generate_rand_string(hostname, sizeof(hostname)); + generate_rand_string(mesh, hostname, sizeof(hostname)); pthread_mutex_lock(&(mesh->mesh_mutex)); @@ -379,7 +377,7 @@ static void *discovery_loop(void *userdata) { // generate some unique host name (we actually do not care about it) char hostname[17]; - generate_rand_string(hostname, sizeof(hostname)); + generate_rand_string(mesh, hostname, sizeof(hostname)); // Let's set the host name for this server. CattaServerConfig config;