-revocation
[oweals/gnunet.git] / src / gns / gnunet-service-gns_shorten.c
index 3d3ac009485b0d3c764bbc1ba10a1e7f8de077b7..4e7f9a91d9ddd0cf7b354b49c969a2c33411168c 100644 (file)
@@ -93,6 +93,11 @@ struct GetPseuAuthorityHandle
    */
   struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
 
+  /**
+   * Handle to namecache request
+   */
+  struct GNUNET_NAMECACHE_QueueEntry *namecache_task;
+
   /**
    * Task to abort DHT lookup operation.
    */
@@ -116,6 +121,11 @@ static struct GetPseuAuthorityHandle *gph_tail;
  */
 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
 
+/**
+ * Our handle to the namecache service
+ */
+static struct GNUNET_NAMECACHE_Handle *namecache_handle;
+
 /**
  * Resolver handle to the dht
  */
@@ -140,6 +150,11 @@ free_get_pseu_authority_handle (struct GetPseuAuthorityHandle *gph)
     GNUNET_NAMESTORE_cancel (gph->namestore_task);
     gph->namestore_task = NULL;
   }
+  if (NULL != gph->namecache_task)
+  {
+    GNUNET_NAMECACHE_cancel (gph->namecache_task);
+    gph->namecache_task = NULL;
+  }
   if (GNUNET_SCHEDULER_NO_TASK != gph->timeout_task)
   {
     GNUNET_SCHEDULER_cancel (gph->timeout_task);
@@ -181,7 +196,7 @@ create_pkey_cont (void* cls,
 static void
 process_pseu_lookup_ns (void *cls,
                        unsigned int rd_count,
-                       const struct GNUNET_NAMESTORE_RecordData *rd);
+                       const struct GNUNET_GNSRECORD_Data *rd);
 
 
 /**
@@ -193,12 +208,12 @@ process_pseu_lookup_ns (void *cls,
  */
 static void
 process_pseu_block_ns (void *cls,
-                      const struct GNUNET_NAMESTORE_Block *block)
+                      const struct GNUNET_GNSRECORD_Block *block)
 {
   struct GetPseuAuthorityHandle *gph = cls;
   struct GNUNET_CRYPTO_EcdsaPublicKey pub;
 
-  gph->namestore_task = NULL;
+  gph->namecache_task = NULL;
   if (NULL == block)
   {
     process_pseu_lookup_ns (gph, 0, NULL);
@@ -207,7 +222,7 @@ process_pseu_block_ns (void *cls,
   GNUNET_CRYPTO_ecdsa_key_get_public (&gph->shorten_zone_key,
                                    &pub);
   if (GNUNET_OK !=
-      GNUNET_NAMESTORE_block_decrypt (block,
+      GNUNET_GNSRECORD_block_decrypt (block,
                                      &pub,
                                      gph->current_label,
                                      &process_pseu_lookup_ns,
@@ -237,10 +252,10 @@ perform_pseu_lookup (struct GetPseuAuthorityHandle *gph,
                                    &pub);
   GNUNET_free_non_null (gph->current_label);
   gph->current_label = GNUNET_strdup (label);
-  GNUNET_NAMESTORE_query_from_public_key (&pub,
+  GNUNET_GNSRECORD_query_from_public_key (&pub,
                                          label,
                                          &query);
-  gph->namestore_task = GNUNET_NAMESTORE_lookup_block (namestore_handle,
+  gph->namecache_task = GNUNET_NAMECACHE_lookup_block (namecache_handle,
                                                       &query,
                                                       &process_pseu_block_ns,
                                                       gph);
@@ -258,17 +273,17 @@ perform_pseu_lookup (struct GetPseuAuthorityHandle *gph,
 static void
 process_pseu_lookup_ns (void *cls,
                        unsigned int rd_count,
-                       const struct GNUNET_NAMESTORE_RecordData *rd)
+                       const struct GNUNET_GNSRECORD_Data *rd)
 {
   struct GetPseuAuthorityHandle *gph = cls;
-  struct GNUNET_NAMESTORE_RecordData new_pkey;
+  struct GNUNET_GNSRECORD_Data new_pkey;
 
   gph->namestore_task = NULL;
   if (rd_count > 0)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "Name `%s' already taken, cannot shorten.\n",
-              gph->current_label);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Name `%s' already taken, cannot shorten.\n",
+                gph->current_label);
     /* if this was not yet the original label, try one more
        time, this time not using PSEU but the original label */
     if (0 == strcmp (gph->current_label,
@@ -285,15 +300,15 @@ process_pseu_lookup_ns (void *cls,
   /* name is available */
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Shortening `%s' to `%s'\n",
-             GNUNET_NAMESTORE_z2s (&gph->target_zone),
+             GNUNET_GNSRECORD_z2s (&gph->target_zone),
              gph->current_label);
   new_pkey.expiration_time = UINT64_MAX;
   new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
   new_pkey.data = &gph->target_zone;
-  new_pkey.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
-  new_pkey.flags = GNUNET_NAMESTORE_RF_NONE
-                 | GNUNET_NAMESTORE_RF_PRIVATE
-                 | GNUNET_NAMESTORE_RF_PENDING;
+  new_pkey.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
+  new_pkey.flags = GNUNET_GNSRECORD_RF_NONE
+                 | GNUNET_GNSRECORD_RF_PRIVATE
+                 | GNUNET_GNSRECORD_RF_PENDING;
   gph->namestore_task
     = GNUNET_NAMESTORE_records_store (namestore_handle,
                                      &gph->shorten_zone_key,
@@ -341,7 +356,8 @@ handle_auth_discovery_timeout (void *cls,
 
   gph->timeout_task = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "DHT lookup for PSEU query timed out.\n");
+              "DHT lookup for PSEU query in zone `%s' timed out.\n",
+              GNUNET_GNSRECORD_z2s (&gph->target_zone));
   GNUNET_DHT_get_stop (gph->get_handle);
   gph->get_handle = NULL;
   process_pseu_result (gph, NULL);
@@ -358,14 +374,14 @@ handle_auth_discovery_timeout (void *cls,
 static void
 process_auth_records (void *cls,
                      unsigned int rd_count,
-                     const struct GNUNET_NAMESTORE_RecordData *rd)
+                     const struct GNUNET_GNSRECORD_Data *rd)
 {
   struct GetPseuAuthorityHandle *gph = cls;
   unsigned int i;
 
   for (i=0; i < rd_count; i++)
   {
-    if (GNUNET_NAMESTORE_TYPE_PSEU == rd[i].record_type)
+    if (GNUNET_GNSRECORD_TYPE_PSEU == rd[i].record_type)
     {
       char pseu[rd[i].data_size + 1];
 
@@ -380,7 +396,8 @@ process_auth_records (void *cls,
     }
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "No PSEU record found in DHT reply.\n");
+              "No PSEU record found in DHT reply with %u records.\n",
+              rd_count);
   process_pseu_result (gph, NULL);
 }
 
@@ -392,11 +409,11 @@ process_auth_records (void *cls,
  * @param exp lifetime
  * @param key the key the record was stored under
  * @param get_path get path
- * @param get_path_length get path length
+ * @param get_path_length @a get_path length
  * @param put_path put path
- * @param put_path_length put path length
+ * @param put_path_length @a put_path length
  * @param type the block type
- * @param size the size of the record
+ * @param size number of bytes in @a data
  * @param data the record data
  */
 static void
@@ -412,7 +429,7 @@ process_auth_discovery_dht_result (void* cls,
                                    const void *data)
 {
   struct GetPseuAuthorityHandle *gph = cls;
-  const struct GNUNET_NAMESTORE_Block *block;
+  const struct GNUNET_GNSRECORD_Block *block;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Got DHT result for PSEU request\n");
@@ -428,7 +445,7 @@ process_auth_discovery_dht_result (void* cls,
     process_pseu_result (gph, NULL);
     return;
   }
-  if (size < sizeof (struct GNUNET_NAMESTORE_Block))
+  if (size < sizeof (struct GNUNET_GNSRECORD_Block))
   {
     /* how did this pass DHT block validation!? */
     GNUNET_break (0);
@@ -447,7 +464,7 @@ process_auth_discovery_dht_result (void* cls,
     return;
   }
   if (GNUNET_OK !=
-      GNUNET_NAMESTORE_block_decrypt (block,
+      GNUNET_GNSRECORD_block_decrypt (block,
                                      &gph->target_zone,
                                      GNUNET_GNS_TLD_PLUS,
                                      &process_auth_records,
@@ -476,7 +493,7 @@ process_zone_to_name_discover (void *cls,
                               const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
                               const char *name,
                               unsigned int rd_len,
-                              const struct GNUNET_NAMESTORE_RecordData *rd)
+                              const struct GNUNET_GNSRECORD_Data *rd)
 {
   struct GetPseuAuthorityHandle* gph = cls;
   struct GNUNET_HashCode lookup_key;
@@ -492,9 +509,14 @@ process_zone_to_name_discover (void *cls,
     return;
   }
   /* record does not yet exist, go into DHT to find PSEU record */
-  GNUNET_NAMESTORE_query_from_public_key (&gph->target_zone,
+  GNUNET_GNSRECORD_query_from_public_key (&gph->target_zone,
                                          GNUNET_GNS_TLD_PLUS,
                                          &lookup_key);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Shortening searches in DHT for PSEU record under `%s' in zone `%s'\n",
+              GNUNET_h2s (&lookup_key),
+              GNUNET_GNSRECORD_z2s (&gph->target_zone));
+
   gph->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT,
                                                    &handle_auth_discovery_timeout,
                                                    gph);
@@ -525,7 +547,6 @@ GNS_shorten_start (const char *original_label,
 {
   struct GetPseuAuthorityHandle *gph;
 
-  // if (1) return;
   if (strlen (original_label) > GNUNET_DNSPARSER_MAX_LABEL_LENGTH)
   {
     GNUNET_break (0);
@@ -533,7 +554,7 @@ GNS_shorten_start (const char *original_label,
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Starting shortening process for `%s' with old label `%s'\n",
-             GNUNET_NAMESTORE_z2s (pub),
+             GNUNET_GNSRECORD_z2s (pub),
              original_label);
   gph = GNUNET_new (struct GetPseuAuthorityHandle);
   gph->shorten_zone_key = *shorten_zone;
@@ -553,13 +574,16 @@ GNS_shorten_start (const char *original_label,
  * Initialize the shortening subsystem
  *
  * @param nh the namestore handle
+ * @param nc the namecache handle
  * @param dht the dht handle
  */
 void
 GNS_shorten_init (struct GNUNET_NAMESTORE_Handle *nh,
+                  struct GNUNET_NAMECACHE_Handle *nc,
                  struct GNUNET_DHT_Handle *dht)
 {
   namestore_handle = nh;
+  namecache_handle = nc;
   dht_handle = dht;
 }
 
@@ -575,6 +599,7 @@ GNS_shorten_done ()
     free_get_pseu_authority_handle (gph_head);
   dht_handle = NULL;
   namestore_handle = NULL;
+  namecache_handle = NULL;
 }
 
 /* end of gnunet-service-gns_shorten.c */