-allow registering one name per zone key in fcfsd
authorChristian Grothoff <christian@grothoff.org>
Mon, 19 Mar 2012 19:27:05 +0000 (19:27 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 19 Mar 2012 19:27:05 +0000 (19:27 +0000)
src/gns/gnunet-gns-fcfsd.c

index 0d400011dbf50cc1754b310320a9768016f2b7b3..8d6a58302b4b4d752d0d55faee80cbacf3ef27c8 100644 (file)
@@ -342,7 +342,66 @@ put_continuation (void *cls,
 
 
 /**
- * Process a record that was stored in the namestore.
+ * Test if a name mapping was found, if so, refuse.  If not, initiate storing of the record.
+ *
+ * @param cls closure
+ * @param zone_key public key of the zone
+ * @param expire when does the corresponding block in the DHT expire (until
+ *               when should we never do a DHT lookup for the same name again)?; 
+ *               GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
+ *               or the expiration time of the block in the namestore (even if there are zero
+ *               records matching the desired record type)
+ * @param name name that is being mapped (at most 255 characters long)
+ * @param rd_count number of entries in 'rd' array
+ * @param rd array of records with data to store
+ * @param signature signature of the record block, NULL if signature is unavailable (i.e. 
+ *        because the user queried for a particular record type only)
+ */
+static void 
+zone_to_name_cb (void *cls,
+                const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                struct GNUNET_TIME_Absolute expire,                        
+                const char *name,
+                unsigned int rd_count,
+                const struct GNUNET_NAMESTORE_RecordData *rd,
+                const struct GNUNET_CRYPTO_RsaSignature *signature)
+{
+  struct Request *request = cls;
+  struct GNUNET_NAMESTORE_RecordData r;
+  struct GNUNET_CRYPTO_ShortHashCode pub;
+  
+  request->qe = NULL;
+  if (NULL != name)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+               _("Found existing name `%s' for the given key\n"),
+               name);
+    request->phase = RP_FAIL;
+    run_httpd_now ();
+    return;
+  }
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_CRYPTO_short_hash_from_string2 (request->public_key,
+                                                       strlen (request->public_key),
+                                                       &pub));
+  r.data = &pub;
+  r.data_size = sizeof (pub);
+  r.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
+  r.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
+  r.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
+  request->qe = GNUNET_NAMESTORE_record_create (ns,
+                                               fcfs_zone_pkey,
+                                               request->domain_name,
+                                               &r,
+                                               &put_continuation,
+                                               request);
+}
+
+
+/**
+ * Process a record that was stored in the namestore.  Used to check if
+ * the requested name already exists in the namestore.  If not,
+ * proceed to check if the requested key already exists.
  *
  * @param cls closure
  * @param zone_key public key of the zone
@@ -367,14 +426,13 @@ lookup_result_processor (void *cls,
                         const struct GNUNET_CRYPTO_RsaSignature *signature)
 {
   struct Request *request = cls;
-  struct GNUNET_NAMESTORE_RecordData r;
   struct GNUNET_CRYPTO_ShortHashCode pub;
   
+  request->qe = NULL;
   GNUNET_assert (GNUNET_OK ==
                 GNUNET_CRYPTO_short_hash_from_string2 (request->public_key,
                                                        strlen (request->public_key),
                                                        &pub));
-  request->qe = NULL;
   if (0 != rd_count)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -385,17 +443,11 @@ lookup_result_processor (void *cls,
     run_httpd_now ();
     return;
   }
-  r.data = &pub;
-  r.data_size = sizeof (pub);
-  r.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
-  r.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
-  r.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
-  request->qe = GNUNET_NAMESTORE_record_create (ns,
-                                               fcfs_zone_pkey,
-                                               request->domain_name,
-                                               &r,
-                                               &put_continuation,
-                                               request);
+  request->qe = GNUNET_NAMESTORE_zone_to_name (ns,
+                                              &fcfsd_zone,
+                                              &pub,
+                                              &zone_to_name_cb,
+                                              request);
 }