removing remenants of abstract unix domain socket handling, this finishes addressing...
[oweals/gnunet.git] / src / gns / gnunet-service-gns_shorten.c
index 6f27a72345b7fb676bee4dc81dd2499d29634da9..ff2cab09739fcfd754de47bdca8675fe76a18e35 100644 (file)
@@ -80,15 +80,15 @@ struct GetPseuAuthorityHandle
   /**
    * The zone for which we are trying to find the PSEU record.
    */
-  struct GNUNET_CRYPTO_EccPublicKey target_zone;
+  struct GNUNET_CRYPTO_EccPublicSignKey target_zone;
 
   /**
-   * Handle for DHT lookups. Should be NULL if no lookups are in progress 
+   * Handle for DHT lookups. Should be NULL if no lookups are in progress
    */
   struct GNUNET_DHT_GetHandle *get_handle;
 
   /**
-   * Handle to namestore request 
+   * Handle to namestore request
    */
   struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
 
@@ -158,8 +158,8 @@ free_get_pseu_authority_handle (struct GetPseuAuthorityHandle *gph)
  * @param emsg unused
  */
 static void
-create_pkey_cont (void* cls, 
-                 int32_t success, 
+create_pkey_cont (void* cls,
+                 int32_t success,
                  const char *emsg)
 {
   struct GetPseuAuthorityHandle* gph = cls;
@@ -195,7 +195,7 @@ process_pseu_block_ns (void *cls,
                       const struct GNUNET_NAMESTORE_Block *block)
 {
   struct GetPseuAuthorityHandle *gph = cls;
-  struct GNUNET_CRYPTO_EccPublicKey pub;
+  struct GNUNET_CRYPTO_EccPublicSignKey pub;
 
   gph->namestore_task = NULL;
   if (NULL == block)
@@ -203,9 +203,9 @@ process_pseu_block_ns (void *cls,
     process_pseu_lookup_ns (gph, 0, NULL);
     return;
   }
-  GNUNET_CRYPTO_ecc_key_get_public (&gph->shorten_zone_key,
+  GNUNET_CRYPTO_ecc_key_get_public_for_signature (&gph->shorten_zone_key,
                                    &pub);
-  if (GNUNET_OK != 
+  if (GNUNET_OK !=
       GNUNET_NAMESTORE_block_decrypt (block,
                                      &pub,
                                      gph->current_label,
@@ -225,14 +225,14 @@ process_pseu_block_ns (void *cls,
  * @param gph the handle to our shorten operation
  * @param label the label to lookup
  */
-static void 
+static void
 perform_pseu_lookup (struct GetPseuAuthorityHandle *gph,
                     const char *label)
-{ 
-  struct GNUNET_CRYPTO_EccPublicKey pub;
+{
+  struct GNUNET_CRYPTO_EccPublicSignKey pub;
   struct GNUNET_HashCode query;
 
-  GNUNET_CRYPTO_ecc_key_get_public (&gph->shorten_zone_key,
+  GNUNET_CRYPTO_ecc_key_get_public_for_signature (&gph->shorten_zone_key,
                                    &pub);
   GNUNET_free_non_null (gph->current_label);
   gph->current_label = GNUNET_strdup (label);
@@ -266,7 +266,7 @@ process_pseu_lookup_ns (void *cls,
   if (rd_count > 0)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-               "Name `%s' already taken, cannot shorten.\n", 
+               "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 */
@@ -283,17 +283,17 @@ process_pseu_lookup_ns (void *cls,
   }
   /* name is available */
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Shortening `%s' to `%s'\n", 
+             "Shortening `%s' to `%s'\n",
              GNUNET_NAMESTORE_z2s (&gph->target_zone),
              gph->current_label);
   new_pkey.expiration_time = UINT64_MAX;
-  new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_EccPublicKey);
+  new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_EccPublicSignKey);
   new_pkey.data = &gph->target_zone;
   new_pkey.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
-  new_pkey.flags = GNUNET_NAMESTORE_RF_AUTHORITY
+  new_pkey.flags = GNUNET_NAMESTORE_RF_NONE
                  | GNUNET_NAMESTORE_RF_PRIVATE
                  | GNUNET_NAMESTORE_RF_PENDING;
-  gph->namestore_task 
+  gph->namestore_task
     = GNUNET_NAMESTORE_records_store (namestore_handle,
                                      &gph->shorten_zone_key,
                                      gph->current_label,
@@ -309,7 +309,7 @@ process_pseu_lookup_ns (void *cls,
  * @param pseu the pseu result or NULL
  */
 static void
-process_pseu_result (struct GetPseuAuthorityHandle* gph, 
+process_pseu_result (struct GetPseuAuthorityHandle* gph,
                     const char *pseu)
 {
   if (NULL == pseu)
@@ -320,7 +320,7 @@ process_pseu_result (struct GetPseuAuthorityHandle* gph,
                gph->label);
     perform_pseu_lookup (gph, gph->label);
     return;
-  }  
+  }
   /* check if 'pseu' is taken */
   perform_pseu_lookup (gph, pseu);
 }
@@ -366,9 +366,15 @@ process_auth_records (void *cls,
   {
     if (GNUNET_NAMESTORE_TYPE_PSEU == rd[i].record_type)
     {
+      char pseu[rd[i].data_size + 1];
+
       /* found pseu */
-      process_pseu_result (gph, 
-                          (const char *) rd[i].data);
+      memcpy (pseu,
+             rd[i].data,
+             rd[i].data_size);
+      pseu[rd[i].data_size] = '\0';
+      process_pseu_result (gph,
+                          pseu);
       return;
     }
   }
@@ -426,18 +432,18 @@ process_auth_discovery_dht_result (void* cls,
     /* how did this pass DHT block validation!? */
     GNUNET_break (0);
     process_pseu_result (gph, NULL);
-    return;   
+    return;
   }
   block = data;
   if (size !=
-      ntohs (block->purpose.size) + 
-      sizeof (struct GNUNET_CRYPTO_EccPublicKey) +
+      ntohl (block->purpose.size) +
+      sizeof (struct GNUNET_CRYPTO_EccPublicSignKey) +
       sizeof (struct GNUNET_CRYPTO_EccSignature))
   {
     /* how did this pass DHT block validation!? */
     GNUNET_break (0);
     process_pseu_result (gph, NULL);
-    return;   
+    return;
   }
   if (GNUNET_OK !=
       GNUNET_NAMESTORE_block_decrypt (block,
@@ -449,7 +455,7 @@ process_auth_discovery_dht_result (void* cls,
     /* other peer encrypted invalid block, complain */
     GNUNET_break_op (0);
     process_pseu_result (gph, NULL);
-    return;   
+    return;
   }
 }
 
@@ -473,7 +479,7 @@ process_zone_to_name_discover (void *cls,
 {
   struct GetPseuAuthorityHandle* gph = cls;
   struct GNUNET_HashCode lookup_key;
-  
+
   gph->namestore_task = NULL;
   if (0 != rd_len)
   {
@@ -486,10 +492,10 @@ process_zone_to_name_discover (void *cls,
   }
   /* record does not yet exist, go into DHT to find PSEU record */
   GNUNET_NAMESTORE_query_from_public_key (&gph->target_zone,
-                                         GNUNET_GNS_TLD_PLUS,                                    
+                                         GNUNET_GNS_TLD_PLUS,                                  
                                          &lookup_key);
   gph->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT,
-                                                   &handle_auth_discovery_timeout, 
+                                                   &handle_auth_discovery_timeout,
                                                    gph);
   gph->get_handle = GNUNET_DHT_get_start (dht_handle,
                                          GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
@@ -513,16 +519,21 @@ process_zone_to_name_discover (void *cls,
  */
 void
 GNS_shorten_start (const char *original_label,
-                  const struct GNUNET_CRYPTO_EccPublicKey *pub,
+                  const struct GNUNET_CRYPTO_EccPublicSignKey *pub,
                   const struct GNUNET_CRYPTO_EccPrivateKey *shorten_zone)
 {
   struct GetPseuAuthorityHandle *gph;
-  
+
+  // if (1) return;
   if (strlen (original_label) > GNUNET_DNSPARSER_MAX_LABEL_LENGTH)
   {
     GNUNET_break (0);
     return;
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Starting shortening process for `%s' with old label `%s'\n",
+             GNUNET_NAMESTORE_z2s (pub),
+             original_label);
   gph = GNUNET_new (struct GetPseuAuthorityHandle);
   gph->shorten_zone_key = *shorten_zone;
   gph->target_zone = *pub;