From 375e1b742172911b41b1dd04c8c4efdb65caf408 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Wed, 7 Mar 2012 15:50:44 +0000 Subject: [PATCH] -shortening in cli app (in progress) --- src/gns/Makefile.am | 19 ++++++++++--------- src/gns/gns_api.c | 19 ++++++++++++------- src/gns/gnunet-gns.c | 18 +++++++++++++----- src/gns/gnunet-service-gns.c | 13 ++++++++----- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 10d3cd1cf..bff08d33f 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am @@ -20,7 +20,8 @@ lib_LTLIBRARIES = \ bin_PROGRAMS = \ gnunet-service-gns \ - gnunet-gns-fcfsd + gnunet-gns-fcfsd \ + gnunet-gns #noinst_PROGRAMS = \ # gnunet-gns-lookup @@ -80,14 +81,14 @@ test_gns_dht_delegated_lookup_DEPENDENCIES = \ $(top_builddir)/src/dht/libgnunetdht.la \ $(top_builddir)/src/testing/libgnunettesting.la -#gnunet_gns_lookup_SOURCES = \ -# gnunet-gns-lookup.c -#gnunet_gns_lookup_LDADD = \ -# $(top_builddir)/src/gns/libgnunetgns.la \ -# $(top_builddir)/src/util/libgnunetutil.la \ -# $(GN_LIBINTL) -#gnunet_dns_lookup_DEPENDENCIES = \ -# libgnunetgns.la +gnunet_gns_SOURCES = \ + gnunet-gns.c +gnunet_gns_LDADD = \ + $(top_builddir)/src/gns/libgnunetgns.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(GN_LIBINTL) +gnunet_gns_DEPENDENCIES = \ + libgnunetgns.la gnunet_service_gns_SOURCES = \ gnunet-service-gns.c diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index a1cd190de..104423c32 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c @@ -496,7 +496,7 @@ process_shorten_reply (void *cls, const GNUNET_HashCode * key, void *value) { const struct GNUNET_GNS_ClientShortenResultMessage *gns_msg = cls; struct GNUNET_GNS_ShortenHandle *shorten_handle = value; - const char *name = (const char*) &shorten_handle[1]; + const char *name = (const char*)&((struct GNUNET_GNS_ClientShortenMessage *) &((shorten_handle->message)[1]))[1]; //FIXME const char *short_name; if (ntohs (((struct GNUNET_MessageHeader*)gns_msg)->size) < @@ -599,7 +599,9 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) struct GNUNET_GNS_Handle *handle = cls; const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg; const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg; - + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got message\n"); if (msg == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -610,6 +612,8 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got lookup msg\n"); lookup_msg = (const struct GNUNET_GNS_ClientLookupResultMessage *) msg; GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_lookup_requests, &lookup_msg->key, @@ -618,6 +622,8 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) } else if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got shorten msg\n"); shorten_msg = (const struct GNUNET_GNS_ClientShortenResultMessage *) msg; GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_shorten_requests, &shorten_msg->key, @@ -642,8 +648,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) * @return handle to the GNS service, or NULL on error */ struct GNUNET_GNS_Handle * -GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned int ht_len) +GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_GNS_Handle *handle; @@ -652,9 +657,9 @@ GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, handle->uid_gen = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); handle->active_lookup_requests = - GNUNET_CONTAINER_multihashmap_create (ht_len); + GNUNET_CONTAINER_multihashmap_create (5); handle->active_shorten_requests = - GNUNET_CONTAINER_multihashmap_create (ht_len); + GNUNET_CONTAINER_multihashmap_create (5); if (GNUNET_NO == try_connect (handle)) { GNUNET_GNS_disconnect (handle); @@ -790,7 +795,7 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, pending); pending->in_pending_queue = GNUNET_YES; - shorten_handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_LookupHandle)); + shorten_handle = GNUNET_malloc (sizeof (struct GNUNET_GNS_ShortenHandle)); shorten_handle->proc = proc; shorten_handle->proc_cls = proc_cls; shorten_handle->message = pending; diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index 3fdd8d29f..6a9241897 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c @@ -39,7 +39,7 @@ static struct GNUNET_GNS_Handle *gns; /** * GNS name to shorten. (-s option) */ -static struct char *name; +static char *name; /** * Task run on shutdown. Cleans up everything. @@ -59,6 +59,12 @@ do_shutdown (void *cls, } +static void +process_shorten_result(void* cls, const char* nlong, const char* nshort) +{ + printf("%s shortened to %s\n", nlong, nshort); +} + /** * Main function that will be run. * @@ -78,11 +84,13 @@ run (void *cls, char *const *args, const char *cfgfile, _("Failed to connect to GNS\n")); return; } - if (NULL == s) + + if (name != NULL) { - GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - return; + /** shorten name */ + GNUNET_GNS_shorten(gns, name, &process_shorten_result, NULL); } + // FIXME: do work here... GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); } @@ -100,7 +108,7 @@ main (int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { {'s', "shorten", NULL, - gettext_noop ("try to shorten a given GNS name"), 0, + gettext_noop ("try to shorten a given GNS name"), 1, &GNUNET_GETOPT_set_string, &name}, GNUNET_GETOPT_OPTION_END }; diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 18bcc5c3e..5bd64c484 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -1969,19 +1969,19 @@ send_shorten_response(const char* name, struct ClientShortenHandle *csh) rmsg->key = csh->key; rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT); rmsg->header.size = - htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage *) + + htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) + strlen(name)); strcpy((char*)&rmsg[1], name); GNUNET_SERVER_notification_context_unicast (nc, csh->client, - (const struct GNUNET_MessageHeader *) &rmsg, + (const struct GNUNET_MessageHeader *) rmsg, GNUNET_NO); GNUNET_SERVER_receive_done (csh->client, GNUNET_OK); - GNUNET_free(csh); - GNUNET_free(rmsg); + //GNUNET_free(csh); + //GNUNET_free(rmsg); } @@ -2001,13 +2001,16 @@ static void handle_shorten(void *cls, size_t msg_size = 0; struct ClientShortenHandle *csh; - if (ntohs (message->size) != sizeof (struct GNUNET_GNS_ClientShortenMessage)) + if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage)) { GNUNET_break_op (0); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } + GNUNET_SERVER_notification_context_add (nc, client); + GNUNET_SERVER_client_keep (client); + struct GNUNET_GNS_ClientShortenMessage *sh_msg = (struct GNUNET_GNS_ClientShortenMessage *) message; -- 2.25.1