-shortening in cli app (in progress)
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Wed, 7 Mar 2012 15:50:44 +0000 (15:50 +0000)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Wed, 7 Mar 2012 15:50:44 +0000 (15:50 +0000)
src/gns/Makefile.am
src/gns/gns_api.c
src/gns/gnunet-gns.c
src/gns/gnunet-service-gns.c

index 10d3cd1cffe6e80dba10ed4084c5fe3288cf3d9f..bff08d33f9e1e5dfad76cce44315484e445654dc 100644 (file)
@@ -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 
index a1cd190de40d212a153a33261d9c0da9d444f095..104423c321babb13f40e6237d0917aee7d24c32e 100644 (file)
@@ -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;
index 3fdd8d29fb6b67e6bf9f59cc644b803f41a070b0..6a9241897133051eeea17e7ce8f519f817b288dd 100644 (file)
@@ -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
   };
index 18bcc5c3e250c910adfc239a0f4624178a0d5792..5bd64c484cc9fb70d269b07fddd703ca565bd257 100644 (file)
@@ -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;