gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22388 - in gnunet/src: gns include


From: gnunet
Subject: [GNUnet-SVN] r22388 - in gnunet/src: gns include
Date: Fri, 29 Jun 2012 16:36:19 +0200

Author: schanzen
Date: 2012-06-29 16:36:19 +0200 (Fri, 29 Jun 2012)
New Revision: 22388

Modified:
   gnunet/src/gns/gns.conf.in
   gnunet/src/gns/gns.h
   gnunet/src/gns/gns_api.c
   gnunet/src/gns/gnunet-gns-proxy.c
   gnunet/src/gns/gnunet-gns.c
   gnunet/src/gns/gnunet-service-gns.c
   gnunet/src/gns/gnunet-service-gns_resolver.c
   gnunet/src/gns/test_gns_pseu_shorten.c
   gnunet/src/include/gnunet_gns_service.h
Log:
-fix 2447

Modified: gnunet/src/gns/gns.conf.in
===================================================================
--- gnunet/src/gns/gns.conf.in  2012-06-29 14:21:46 UTC (rev 22387)
+++ gnunet/src/gns/gns.conf.in  2012-06-29 14:36:19 UTC (rev 22388)
@@ -6,13 +6,10 @@
 BINARY = gnunet-service-gns
 UNIXPATH = /tmp/gnunet-service-gns.sock
 ZONEKEY = $SERVICEHOME/gns/zonekey.zkey
-PRIVATE_ZONE = private
 PRIVATE_ZONEKEY = $SERVICEHOME/gns/zonekey_priv.zkey
-SHORTEN_ZONE = short
 SHORTEN_ZONEKEY = $SERVICEHOME/gns/zonekey_short.zkey
 HIJACK_DNS = NO
 AUTO_IMPORT_PKEY = YES
-AUTO_IMPORT_ZONEKEY = $SERVICEHOME/gns/shorten_zonekey.zkey
 AUTO_IMPORT_CONFIRMATION_REQ = NO
 MAX_PARALLEL_BACKGROUND_QUERIES = 25
 DEFAULT_LOOKUP_TIMEOUT = 10

Modified: gnunet/src/gns/gns.h
===================================================================
--- gnunet/src/gns/gns.h        2012-06-29 14:21:46 UTC (rev 22387)
+++ gnunet/src/gns/gns.h        2012-06-29 14:36:19 UTC (rev 22388)
@@ -133,6 +133,16 @@
    * If use_default_zone is empty this zone is used for lookup
    */
   struct GNUNET_CRYPTO_ShortHashCode zone;
+
+  /**
+   * Shorten zone
+   */
+  struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
+
+  /**
+   * Private zone
+   */
+  struct GNUNET_CRYPTO_ShortHashCode private_zone;
   
   /* Followed by the name to shorten up */
 };

Modified: gnunet/src/gns/gns_api.c
===================================================================
--- gnunet/src/gns/gns_api.c    2012-06-29 14:21:46 UTC (rev 22387)
+++ gnunet/src/gns/gns_api.c    2012-06-29 14:36:19 UTC (rev 22388)
@@ -766,6 +766,8 @@
  *
  * @param handle handle to the GNS service
  * @param name the name to look up
+ * @param private_zone the public zone of the private zone
+ * @param shorten_zone the public zone of the shorten zone
  * @param zone the zone to start the resolution in
  * @param proc function to call on result
  * @param proc_cls closure for processor
@@ -773,10 +775,12 @@
  */
 struct GNUNET_GNS_QueueEntry *
 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
-                    const char * name,
-                    struct GNUNET_CRYPTO_ShortHashCode *zone,
-                    GNUNET_GNS_ShortenResultProcessor proc,
-                    void *proc_cls)
+                         const char * name,
+                         struct GNUNET_CRYPTO_ShortHashCode *private_zone,
+                         struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
+                         struct GNUNET_CRYPTO_ShortHashCode *zone,
+                         GNUNET_GNS_ShortenResultProcessor proc,
+                         void *proc_cls)
 {
   /* IPC to shorten gns names, return shorten_handle */
   struct GNUNET_GNS_ClientShortenMessage *shorten_msg;
@@ -809,6 +813,8 @@
   shorten_msg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_SHORTEN);
   shorten_msg->header.size = htons (msize);
   shorten_msg->id = htonl(qe->r_id);
+  shorten_msg->private_zone = *private_zone;
+  shorten_msg->shorten_zone = *shorten_zone;
   
   if (NULL != zone)
   {
@@ -836,6 +842,8 @@
  *
  * @param handle handle to the GNS service
  * @param name the name to look up
+ * @param private_zone the public zone of the private zone
+ * @param shorten_zone the public zone of the shorten zone
  * @param proc function to call on result
  * @param proc_cls closure for processor
  * @return handle to the operation
@@ -843,10 +851,14 @@
 struct GNUNET_GNS_QueueEntry *
 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
                     const char * name,
+                    struct GNUNET_CRYPTO_ShortHashCode *private_zone,
+                    struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
                     GNUNET_GNS_ShortenResultProcessor proc,
                     void *proc_cls)
 {
-  return GNUNET_GNS_shorten_zone (handle, name, NULL, proc, proc_cls);
+  return GNUNET_GNS_shorten_zone (handle, name,
+                                  private_zone, shorten_zone,
+                                  NULL, proc, proc_cls);
 }
 /**
  * Perform an authority lookup for a given name.

Modified: gnunet/src/gns/gnunet-gns-proxy.c
===================================================================
--- gnunet/src/gns/gnunet-gns-proxy.c   2012-06-29 14:21:46 UTC (rev 22387)
+++ gnunet/src/gns/gnunet-gns-proxy.c   2012-06-29 14:36:19 UTC (rev 22388)
@@ -292,6 +292,12 @@
 /* The users local GNS zone hash */
 static struct GNUNET_CRYPTO_ShortHashCode local_gns_zone;
 
+/* The users local private zone */
+static struct GNUNET_CRYPTO_ShortHashCode local_private_zone;
+
+/* The users local shorten zone */
+static struct GNUNET_CRYPTO_ShortHashCode local_shorten_zone;
+
 /* The CA for SSL certificate generation */
 static struct ProxyCA proxy_ca;
 
@@ -687,10 +693,13 @@
         ctask->is_postprocessing = GNUNET_YES;
         ctask->pp_finished = GNUNET_NO;
         
-        GNUNET_GNS_shorten (gns_handle,
-                           ctask->pp_buf,
-                           &process_shorten,
-                           ctask);
+        GNUNET_GNS_shorten_zone (gns_handle,
+                                 ctask->pp_buf,
+                                 &local_private_zone,
+                                 &local_shorten_zone,
+                                 &local_gns_zone,
+                                 &process_shorten,
+                                 ctask);
 
         return 0;
       }
@@ -2358,7 +2367,61 @@
               "Using zone: %s!\n", &zonename);
   GNUNET_CRYPTO_rsa_key_free(key);
   GNUNET_free(keyfile);
+  
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
+                                                   "PRIVATE_ZONEKEY", 
&keyfile))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unable to load private zone key config value!\n");
+    return GNUNET_NO;
+  }
 
+  if (GNUNET_NO == GNUNET_DISK_file_test (keyfile))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unable to load private zone key %s!\n", keyfile);
+    GNUNET_free(keyfile);
+    return GNUNET_NO;
+  }
+
+  key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+  GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
+  GNUNET_CRYPTO_short_hash(&pkey,
+                           sizeof(struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                           &local_private_zone);
+  GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Using private zone: %s!\n", &zonename);
+  GNUNET_CRYPTO_rsa_key_free(key);
+  GNUNET_free(keyfile);
+
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
+                                                   "SHORTEN_ZONEKEY", 
&keyfile))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unable to load shorten zone key config value!\n");
+    return GNUNET_NO;
+  }
+
+  if (GNUNET_NO == GNUNET_DISK_file_test (keyfile))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unable to load shorten zone key %s!\n", keyfile);
+    GNUNET_free(keyfile);
+    return GNUNET_NO;
+  }
+
+  key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+  GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
+  GNUNET_CRYPTO_short_hash(&pkey,
+                           sizeof(struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                           &local_shorten_zone);
+  GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Using shorten zone: %s!\n", &zonename);
+  GNUNET_CRYPTO_rsa_key_free(key);
+  GNUNET_free(keyfile);
+
   return GNUNET_YES;
 }
 

Modified: gnunet/src/gns/gnunet-gns.c
===================================================================
--- gnunet/src/gns/gnunet-gns.c 2012-06-29 14:21:46 UTC (rev 22387)
+++ gnunet/src/gns/gnunet-gns.c 2012-06-29 14:36:19 UTC (rev 22388)
@@ -152,6 +152,9 @@
   struct GNUNET_CRYPTO_ShortHashCode user_zone;
   struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
   struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key = NULL;
+  struct GNUNET_CRYPTO_RsaPrivateKey *private_key = NULL;
+  struct GNUNET_CRYPTO_ShortHashCode private_zone;
+  struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
 
   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
                                                            "ZONEKEY", 
&keyfile))
@@ -193,10 +196,48 @@
     if (GNUNET_YES == GNUNET_DISK_file_test (keyfile))
     {
       shorten_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+      GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
+      GNUNET_CRYPTO_short_hash(&pkey,
+                         sizeof(struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                         &shorten_zone);
+      GNUNET_CRYPTO_short_hash_to_enc (&shorten_zone, &zonename);
+      if (!raw)
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "Using shorten zone: %s!\n", &zonename);
+
     }
     GNUNET_free(keyfile);
   }
   
+  
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
+                                                   "PRIVATE_ZONEKEY", 
&keyfile))
+  {
+    if (!raw)
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "No private zone key found!\n");
+    shorten_key = NULL;
+  }
+  else
+  {
+    if (GNUNET_YES == GNUNET_DISK_file_test (keyfile))
+    {
+      private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+      GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
+      GNUNET_CRYPTO_short_hash(&pkey,
+                         sizeof(struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                         &private_zone);
+      GNUNET_CRYPTO_short_hash_to_enc (&private_zone, &zonename);
+      if (!raw)
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "Using private zone: %s!\n", &zonename);
+
+    }
+    GNUNET_free(keyfile);
+    GNUNET_CRYPTO_rsa_key_free (private_key);
+  }
+  
+  
   gns = GNUNET_GNS_connect (cfg);
   if (lookup_type != NULL)
     rtype = GNUNET_NAMESTORE_typename_to_number(lookup_type);
@@ -214,6 +255,8 @@
   {
     /** shorten name */
     GNUNET_GNS_shorten_zone (gns, shorten_name,
+                             &private_zone,
+                             &shorten_zone,
                              zone,
                              &process_shorten_result,
                              shorten_name);

Modified: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c 2012-06-29 14:21:46 UTC (rev 22387)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-06-29 14:36:19 UTC (rev 22388)
@@ -51,6 +51,13 @@
  */
 struct ClientShortenHandle
 {
+
+  /* DLL */
+  struct ClientShortenHandle *next;
+
+  /* DLL */
+  struct ClientShortenHandle *prev;
+
   /* the requesting client that */
   struct GNUNET_SERVER_Client *client;
 
@@ -60,12 +67,15 @@
   /* request type */
   enum GNUNET_GNS_RecordType type;
 
-  /* optional zone private key used for shorten */
-  struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key;
-  
   /* name to shorten */
   char name[MAX_DNS_NAME_LENGTH];
 
+  /* name of private zone (relative to root) */
+  char private_zone_id[MAX_DNS_NAME_LENGTH];
+  
+  /* name of shorten zone (relative to root) */
+  char shorten_zone_id[MAX_DNS_NAME_LENGTH];
+  
   /* root zone */
   struct GNUNET_CRYPTO_ShortHashCode root_zone;
 
@@ -74,6 +84,10 @@
   
   /* shorten zone */
   struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
+
+  /* Namestore lookup task */
+  struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
+
 };
 
 
@@ -99,6 +113,7 @@
  */
 struct ClientLookupHandle
 {
+
   /* the requesting client that */
   struct GNUNET_SERVER_Client *client;
 
@@ -181,19 +196,29 @@
 /* lookup timeout */
 static struct GNUNET_TIME_Relative default_lookup_timeout;
 
-/* name of the private zone */
-static char *private_zone_id;
-
-/* name of the public zone */
-static char *shorten_zone_id;
-
 /* ipv6 support */
 static int v6_enabled;
 
 /* ipv4 support */
 static int v4_enabled;
 
+/* Shorten DLL for cancelling NS requests */
+static struct ClientShortenHandle *csh_head;
+
+/* Shorten DLL for cancelling NS requests */
+static struct ClientShortenHandle *csh_tail;
+
 /**
+ * Send shorten response back to client
+ * 
+ * @param cls the closure containing a client shorten handle
+ * @param name the shortened name result or NULL if cannot be shortened
+ */
+static void
+send_shorten_response(void* cls, const char* name);
+
+
+/**
  * Continue shutdown
  */
 static void
@@ -214,10 +239,16 @@
 static void
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  struct ClientShortenHandle *csh_tmp = csh_head;
 
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
              "Shutting down!");
   
+  while (csh_tmp != NULL)
+  {
+    GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh_tmp);
+    send_shorten_response (csh_tmp, csh_tmp->name);
+  }
   
   GNUNET_SERVER_notification_context_destroy (nc);
   
@@ -489,16 +520,24 @@
                               (const struct GNUNET_MessageHeader *) rmsg,
                               GNUNET_NO);
   GNUNET_SERVER_receive_done (csh->client, GNUNET_OK);
+
+  if (NULL != csh->namestore_task)
+    GNUNET_NAMESTORE_cancel (csh->namestore_task);
   
   GNUNET_free(rmsg);
-  GNUNET_free_non_null(csh->shorten_key);
   GNUNET_free(csh);
 
 }
 
 
+/**
+ * Lookup the zone infos and shorten name
+ *
+ * @param csh the shorten handle
+ *
+ */
 static void
-process_shorten_zone_shorten (void *cls,
+process_shorten_in_private_zone_lookup (void *cls,
                       const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 
*key,
                       struct GNUNET_TIME_Absolute expiration,
                       const char *name,
@@ -507,36 +546,55 @@
                       const struct GNUNET_CRYPTO_RsaSignature *signature)
 {
   struct ClientShortenHandle *csh = cls;
-  struct GNUNET_TIME_Relative remaining_time;
-  struct GNUNET_TIME_Absolute et;
+  csh->namestore_task = NULL;
+  struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone;
+  struct GNUNET_CRYPTO_ShortHashCode *pzone = &csh->private_zone;
 
-  remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
+  if (0 == strcmp (csh->private_zone_id, ""))
+    pzone = NULL;
+  
+  if (rd_count == 0)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "No shorten zone in private zone!\n");
 
-  if ((rd_count == 1) &&
-      (remaining_time.rel_value != 0))
+    strcpy (csh->shorten_zone_id, "");
+    szone = NULL;
+
+  }
+  else
   {
-    GNUNET_break (0 == (rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION));
-    et.abs_value = rd->expiration_time;
-    remaining_time = GNUNET_TIME_absolute_get_remaining (et);
-    if ((rd->record_type == GNUNET_GNS_RECORD_PKEY) &&
-        (remaining_time.rel_value != 0))
-    {
-      csh->shorten_zone = *((struct GNUNET_CRYPTO_ShortHashCode*)rd->data);
-    }
+
+    GNUNET_assert (rd_count == 1);
+
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Shorten zone %s found in private zone %s\n",
+                name, csh->private_zone_id);
+
+    sprintf (csh->shorten_zone_id, "%s.%s", name, csh->private_zone_id);
   }
+  
+  GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
+
   gns_resolver_shorten_name (&csh->root_zone,
-                             &csh->private_zone,
-                             &csh->shorten_zone,
+                             pzone,
+                             szone,
                              csh->name,
-                             private_zone_id,
-                             shorten_zone_id,
+                             csh->private_zone_id,
+                             csh->shorten_zone_id,
                              &send_shorten_response, csh);
 
 }
 
 
+/**
+ * Lookup the zone infos and shorten name
+ *
+ * @param csh the shorten handle
+ *
+ */
 static void
-process_private_zone_shorten (void *cls,
+process_shorten_in_root_zone_lookup (void *cls,
                       const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 
*key,
                       struct GNUNET_TIME_Absolute expiration,
                       const char *name,
@@ -544,48 +602,49 @@
                       const struct GNUNET_NAMESTORE_RecordData *rd,
                       const struct GNUNET_CRYPTO_RsaSignature *signature)
 {
-  struct GNUNET_TIME_Relative remaining_time;
   struct ClientShortenHandle *csh = cls;
-  struct GNUNET_TIME_Absolute et;
+  csh->namestore_task = NULL;
+  struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone;
+  struct GNUNET_CRYPTO_ShortHashCode *pzone = &csh->private_zone;
+  
+  if (0 == strcmp (csh->private_zone_id, ""))
+    pzone = NULL;
 
-  remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
-
-  if ((rd_count == 1) &&
-      (remaining_time.rel_value != 0))
+  if (rd_count == 0)
   {
-    GNUNET_break (0 == (rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION));
-    et.abs_value = rd->expiration_time;
-    remaining_time = GNUNET_TIME_absolute_get_remaining (et);
-    if ((rd->record_type == GNUNET_GNS_RECORD_PKEY) &&
-        (remaining_time.rel_value != 0))
-    {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "No shorten zone in zone and no private zone!\n");
 
+    strcpy (csh->shorten_zone_id, "");
 
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  "Looking for shorten zone in private zone\n");
-      csh->private_zone = *((struct GNUNET_CRYPTO_ShortHashCode*)rd->data);
-      GNUNET_NAMESTORE_lookup_record (namestore_handle,
-                                      &csh->private_zone,
-                                      shorten_zone_id,
-                                      GNUNET_GNS_RECORD_ANY,
-                                      &process_shorten_zone_shorten,
-                                      cls);
-    }
+    GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
+    szone = NULL;
+
+    gns_resolver_shorten_name (&csh->root_zone,
+                               pzone,
+                               szone,
+                               csh->name,
+                               csh->private_zone_id,
+                               csh->shorten_zone_id,
+                               &send_shorten_response, csh);
     return;
   }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "No private zone found!\n");
-  gns_resolver_shorten_name (&csh->root_zone,
-                             &csh->private_zone,
-                             &csh->shorten_zone,
-                             csh->name,
-                             private_zone_id,
-                             shorten_zone_id,
-                             &send_shorten_response, csh);
+  GNUNET_assert (rd_count == 1);
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Private zone %s found in root zone\n", name);
+
+  strcpy (csh->private_zone_id, name);
+
+  csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
+                                  pzone,
+                                  szone,
+                                  &process_shorten_in_private_zone_lookup,
+                                  csh);
 }
 
+
 /**
  * Lookup the zone infos and shorten name
  *
@@ -593,16 +652,62 @@
  *
  */
 static void
+process_private_in_root_zone_lookup (void *cls,
+                      const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 
*key,
+                      struct GNUNET_TIME_Absolute expiration,
+                      const char *name,
+                      unsigned int rd_count,
+                      const struct GNUNET_NAMESTORE_RecordData *rd,
+                      const struct GNUNET_CRYPTO_RsaSignature *signature)
+{
+  struct ClientShortenHandle *csh = cls;
+  csh->namestore_task = NULL;
+
+  if (rd_count == 0)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "No private zone in root zone\n");
+
+    strcpy (csh->private_zone_id, "");
+  
+    csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
+                                  &csh->root_zone,
+                                  &csh->shorten_zone,
+                                  &process_shorten_in_root_zone_lookup,
+                                  csh);
+    return;
+  }
+
+  GNUNET_assert (rd_count == 1);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Private zone %s found in root zone\n", name);
+
+  strcpy (csh->private_zone_id, name);
+
+  csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
+                                  &csh->private_zone,
+                                  &csh->shorten_zone,
+                                  &process_shorten_in_private_zone_lookup,
+                                  csh);
+}
+
+/**
+ * Lookup the zone infos and shorten name
+ *
+ * @param csh the shorten handle
+ *
+ */
+static void
 start_shorten_name (struct ClientShortenHandle *csh)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Looking for private zone in root zone\n");
+              "Looking for private zone name in root zone\n");
 
-  GNUNET_NAMESTORE_lookup_record (namestore_handle,
+  csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
                                   &csh->root_zone,
-                                  private_zone_id,
-                                  GNUNET_GNS_RECORD_ANY,
-                                  &process_private_zone_shorten,
+                                  &csh->private_zone,
+                                  &process_private_in_root_zone_lookup,
                                   csh);
 }
 
@@ -648,7 +753,8 @@
   csh = GNUNET_malloc(sizeof(struct ClientShortenHandle));
   csh->client = client;
   csh->unique_id = sh_msg->id;
-  csh->shorten_key = NULL;
+
+  GNUNET_CONTAINER_DLL_insert (csh_head, csh_tail, csh);
   
   GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
 
@@ -674,6 +780,9 @@
     return;
   }
 
+  csh->shorten_zone = sh_msg->shorten_zone;
+  csh->private_zone = sh_msg->private_zone;
+
   strcpy (csh->name, name);
   
   GNUNET_SERVER_notification_context_add (nc, client);
@@ -1099,22 +1208,6 @@
 
   }
 
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (c, "gns",
-                                                          "PRIVATE_ZONE",
-                                                          &private_zone_id))
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-               "Private zone id: %s\n", private_zone_id);
-  }
-
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (c, "gns",
-                                                          "SHORTEN_ZONE",
-                                                          &shorten_zone_id))
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-               "Shorten zone id: %s\n", shorten_zone_id);
-  }
-
   dht_max_update_interval = GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL;
 
   if (GNUNET_OK ==

Modified: gnunet/src/gns/gnunet-service-gns_resolver.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns_resolver.c        2012-06-29 14:21:46 UTC 
(rev 22387)
+++ gnunet/src/gns/gnunet-service-gns_resolver.c        2012-06-29 14:36:19 UTC 
(rev 22388)
@@ -3726,22 +3726,20 @@
   /* we found a match in our own root zone */
   if (rd_len != 0)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "result strlen %d\n", strlen(name));
     answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3;
     memset(result, 0, answer_len);
 
     if (strlen(rh->name) > 0)
     {
-      sprintf (result, "%s.%s.%s.%s.%s",
+      sprintf (result, "%s.%s.%s.%s",
                rh->name, name,
-               nsh->shorten_zone_name, nsh->private_zone_name,
+               nsh->shorten_zone_name,
                GNUNET_GNS_TLD);
     }
     else
     {
-      sprintf (result, "%s.%s.%s.%s", name,
-               nsh->shorten_zone_name, nsh->private_zone_name,
+      sprintf (result, "%s.%s.%s", name,
+               nsh->shorten_zone_name,
                GNUNET_GNS_TLD);
     }
     
@@ -3759,9 +3757,9 @@
      * shorten to our zone to a "" record??)
      */
     
-    sprintf (result, "%s.%s.%s.%s",
+    sprintf (result, "%s.%s.%s",
              rh->name,
-             nsh->shorten_zone_name, nsh->private_zone_name,
+             nsh->shorten_zone_name,
              GNUNET_GNS_TLD);
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
                "Our zone: Found %s as shorten result\n", result);
@@ -3840,8 +3838,6 @@
   /* we found a match in our own root zone */
   if (rd_len != 0)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "result strlen %d\n", strlen(name));
     answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3;
     memset(result, 0, answer_len);
 
@@ -3876,7 +3872,7 @@
       strcpy (nsh->result, result);
   }
   
-  if (nsh->shorten_zone != NULL)
+  if (0 != strcmp (nsh->shorten_zone_name, ""))
   {
     /* backtrack authorities for names in priv zone */
     rh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
@@ -3953,8 +3949,6 @@
   /* we found a match in our own root zone */
   if (rd_len != 0)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "result strlen %d\n", strlen(name));
     answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3;
     memset(result, 0, answer_len);
 
@@ -3988,7 +3982,7 @@
       strcpy (nsh->result, result);
   }
   
-  if (nsh->private_zone != NULL)
+  if (0 != strcmp (nsh->private_zone_name, ""))
   {
     /* backtrack authorities for names in priv zone */
     rh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
@@ -3997,6 +3991,15 @@
                                    &process_zone_to_name_shorten_private,
                                    rh);
   }
+  else if (0 != strcmp (nsh->shorten_zone_name, ""))
+  {
+    /* backtrack authorities for names in shorten zone */
+    rh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
+                                          nsh->shorten_zone,
+                                          &rh->authority_chain_head->zone,
+                                          
&process_zone_to_name_shorten_shorten,
+                                          rh);
+  }
   else
   {
     /**
@@ -4089,14 +4092,18 @@
      * (it shouldn't be, usually FIXME what happens if we
      * shorten to our zone to a "" record??)
      */
+    if (0 != strcmp (nsh->private_zone_name, ""))
+    {
     
-    sprintf (result, "%s.%s.%s",
-             rh->name, nsh->private_zone_name, GNUNET_GNS_TLD);
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "Our zone: Found %s as shorten result %s\n", result);
+      sprintf (result, "%s.%s.%s",
+               rh->name, nsh->private_zone_name, GNUNET_GNS_TLD);
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Our zone: Found %s as shorten result in private zone %s\n",
+                 result);
     
-    if (strlen (nsh->result) > strlen (result))
-      strcpy (nsh->result, result);
+      if (strlen (nsh->result) > strlen (result))
+        strcpy (nsh->result, result);
+    }
   }
   else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
                                         nsh->shorten_zone) == 0)
@@ -4106,14 +4113,17 @@
      * (it shouldn't be, usually FIXME what happens if we
      * shorten to our zone to a "" record??)
      */
+    if (0 != strcmp (nsh->shorten_zone_name, ""))
+    {
+      sprintf (result, "%s.%s.%s",
+               rh->name, nsh->private_zone_name, GNUNET_GNS_TLD);
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                 "Our zone: Found %s as shorten result in shorten zone\n",
+                 result);
     
-    sprintf (result, "%s.%s.%s",
-             rh->name, nsh->private_zone_name, GNUNET_GNS_TLD);
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "Our zone: Found %s as shorten result\n", result);
-    
-    if (strlen (nsh->result) > strlen (result))
-      strcpy (nsh->result, result);
+      if (strlen (nsh->result) > strlen (result))
+        strcpy (nsh->result, result);
+    }
   }
   
   

Modified: gnunet/src/gns/test_gns_pseu_shorten.c
===================================================================
--- gnunet/src/gns/test_gns_pseu_shorten.c      2012-06-29 14:21:46 UTC (rev 
22387)
+++ gnunet/src/gns/test_gns_pseu_shorten.c      2012-06-29 14:36:19 UTC (rev 
22388)
@@ -173,9 +173,11 @@
 do_shorten(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GNUNET_GNS_shorten_zone (gns_handle, TEST_DOMAIN,
-                     &our_zone,
-                     &process_shorten_result,
-                     TEST_DOMAIN);
+                           &priv_zone,
+                           &short_zone,
+                           &our_zone,
+                           &process_shorten_result,
+                           TEST_DOMAIN);
 }
 
 static void

Modified: gnunet/src/include/gnunet_gns_service.h
===================================================================
--- gnunet/src/include/gnunet_gns_service.h     2012-06-29 14:21:46 UTC (rev 
22387)
+++ gnunet/src/include/gnunet_gns_service.h     2012-06-29 14:36:19 UTC (rev 
22388)
@@ -190,6 +190,8 @@
  *
  * @param handle handle to the GNS service
  * @param name the name to look up
+ * @param private_zone the public zone of the private zone
+ * @param shorten_zone the public zone of the shorten zone
  * @param proc function to call on result
  * @param proc_cls closure for processor
  * @return handle to the operation
@@ -197,6 +199,8 @@
 struct GNUNET_GNS_QueueEntry *
 GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle,
                     const char * name,
+                    struct GNUNET_CRYPTO_ShortHashCode *private_zone,
+                    struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
                     GNUNET_GNS_ShortenResultProcessor proc,
                     void *proc_cls);
 
@@ -206,6 +210,8 @@
  *
  * @param handle handle to the GNS service
  * @param name the name to look up
+ * @param private_zone the public zone of the private zone
+ * @param shorten_zone the public zone of the shorten zone
  * @param zone the zone to start the resolution in
  * @param proc function to call on result
  * @param proc_cls closure for processor
@@ -213,10 +219,12 @@
  */
 struct GNUNET_GNS_QueueEntry *
 GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
-                    const char * name,
-                    struct GNUNET_CRYPTO_ShortHashCode *zone,
-                    GNUNET_GNS_ShortenResultProcessor proc,
-                    void *proc_cls);
+                         const char * name,
+                         struct GNUNET_CRYPTO_ShortHashCode *private_zone,
+                         struct GNUNET_CRYPTO_ShortHashCode *shorten_zone,
+                         struct GNUNET_CRYPTO_ShortHashCode *zone,
+                         GNUNET_GNS_ShortenResultProcessor proc,
+                         void *proc_cls);
 
 /* *************** Standard API: get authority ******************* */
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]