From 2aa7b5a999b17d808c7f32e4d6a19e4beb7e0918 Mon Sep 17 00:00:00 2001 From: Niklas Hofmann Date: Sat, 25 Oct 2014 17:47:59 +0200 Subject: [PATCH] update to new catta, removal of libuuid dependency --- README.catta | 4 ++-- catta | 2 +- src/Makefile.am | 2 +- src/discovery.c | 34 ++++++++++++++++++---------------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/README.catta b/README.catta index ffef9e20..290d53c2 100644 --- a/README.catta +++ b/README.catta @@ -1,5 +1,5 @@ cd catta -autoreconf -fsi -./configure --disable-nls --disable-glib --disable-gobject --disable-qt3 --disable-qt4 --disable-gtk --disable-gtk3 --disable-dbus --disable-gdbm --disable-libdaemon --disable-python --disable-pygtk --disable-python-dbus --disable-mono --disable-monodoc --disable-autoipd --disable-doxygen-doc --disable-doxygen-dot --disable-doxygen-xml --disable-doxygen-html --disable-manpages --disable-xmltoman CFLAGS=-fPIC +autoreconf +./configure CFLAGS=-fPIC make diff --git a/catta b/catta index a4c3af85..0dff4eb6 160000 --- a/catta +++ b/catta @@ -1 +1 @@ -Subproject commit a4c3af8516b1384e2856904719e75cda5bf6d669 +Subproject commit 0dff4eb6b860070626bb4a28ac7d9d5363821fdf diff --git a/src/Makefile.am b/src/Makefile.am index 4b55f416..89ca0e8e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -111,7 +111,7 @@ libmeshlink_la_SOURCES = \ libmeshlink_la_CFLAGS = -fPIC -I../catta/include/ -libmeshlink_la_LIBADD = -lpthread -luuid ../catta/src/.libs/libcatta.a +libmeshlink_la_LIBADD = -lpthread ../catta/src/.libs/libcatta.a libmeshlink_la_SOURCES += \ ed25519/ecdh.c \ diff --git a/src/discovery.c b/src/discovery.c index 046bcc3e..08ed9aea 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -17,12 +17,20 @@ #include -#include - #define MESHLINK_MDNS_SERVICE_TYPE "_%s._tcp" #define MESHLINK_MDNS_NAME_KEY "name" #define MESHLINK_MDNS_FINGERPRINT_KEY "fingerprint" +static void generate_rand_string(char* buffer, size_t size) +{ + for(size_t i = 0; i < (size - 1); ++i) + { + buffer[i] = 'a' + (rand() % ('z' - 'a' + 1)); + } + + buffer[size-1] = '\0'; +} + static void discovery_entry_group_callback(CattaServer *server, CattaSEntryGroup *group, CattaEntryGroupState state, void *userdata) { meshlink_handle_t *mesh = userdata; @@ -160,14 +168,11 @@ static void discovery_server_callback(CattaServer *server, CattaServerState stat assert(mesh->catta_poll != NULL); /* A host name collision happened. Let's pick a new name for the server */ - uuid_t hostname; - uuid_generate(hostname); - - char hostnamestr[36+1]; - uuid_unparse_lower(hostname, hostnamestr); + char hostname[17]; + generate_rand_string(hostname, sizeof(hostname)); - logger(mesh, MESHLINK_WARNING, "Catta host name collision, retrying with '%s'\n", hostnamestr); - int result = catta_server_set_host_name(mesh->catta_server, hostnamestr); + logger(mesh, MESHLINK_WARNING, "Catta host name collision, retrying with '%s'\n", hostname); + int result = catta_server_set_host_name(mesh->catta_server, hostname); if(result < 0) { @@ -461,7 +466,7 @@ bool discovery_start(meshlink_handle_t *mesh) // handle catta logs catta_set_log_function(discovery_log_cb); - + // create service type string size_t servicetype_strlen = sizeof(MESHLINK_MDNS_SERVICE_TYPE) + strlen(mesh->appname) + 1; mesh->catta_servicetype = malloc(servicetype_strlen); @@ -482,16 +487,13 @@ bool discovery_start(meshlink_handle_t *mesh) } // generate some unique host name (we actually do not care about it) - uuid_t hostname; - uuid_generate(hostname); - - char hostnamestr[36+1]; - uuid_unparse_lower(hostname, hostnamestr); + char hostname[17]; + generate_rand_string(hostname, sizeof(hostname)); // Let's set the host name for this server. CattaServerConfig config; catta_server_config_init(&config); - config.host_name = catta_strdup(hostnamestr); + config.host_name = catta_strdup(hostname); config.publish_workstation = 0; config.disallow_other_stacks = 0; config.publish_hinfo = 0; -- 2.39.5