namestore api change: include block expiration time in record create
authorMatthias Wachs <wachs@net.in.tum.de>
Wed, 7 Mar 2012 12:45:04 +0000 (12:45 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Wed, 7 Mar 2012 12:45:04 +0000 (12:45 +0000)
16 files changed:
src/gns/gnunet-gns-fcfsd.c
src/gns/namestore_stub_api.c
src/gns/test_gns_dht_delegated_lookup.c
src/gns/test_gns_simple_delegated_lookup.c
src/gns/test_gns_simple_lookup.c
src/gns/test_gns_twopeer.c
src/include/gnunet_namestore_service.h
src/namestore/gnunet-namestore.c
src/namestore/gnunet-service-namestore.c
src/namestore/namestore_api.c
src/namestore/test_namestore_api.conf
src/namestore/test_namestore_api_create.c
src/namestore/test_namestore_api_create_update.c
src/namestore/test_namestore_api_zone_iteration.c
src/namestore/test_namestore_api_zone_iteration_specific_zone.c
src/namestore/test_namestore_api_zone_iteration_stop.c

index f931a368038c3726264331a120c21674bb0283df..c93e3c2853bcf4163fcc495d9b2df0e3ce2ec173 100644 (file)
@@ -392,6 +392,7 @@ lookup_result_processor (void *cls,
   r.flags = htonl (GNUNET_NAMESTORE_RF_AUTHORITY);
   request->qe = GNUNET_NAMESTORE_record_create (ns,
                                                fcfs_zone_pkey,
+                                               GNUNET_TIME_absolute_get_forever(),
                                                request->domain_name,
                                                &r,
                                                &put_continuation,
index d067bca5438c77b87c3314a5a14e394cb087e6ae..d17c5bdca50929253b42a4792d6652b3af13cb25 100644 (file)
@@ -227,6 +227,7 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinary
 struct GNUNET_NAMESTORE_QueueEntry *
 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
                             const struct GNUNET_CRYPTO_RsaPrivateKey *key,
+                            const struct GNUNET_TIME_Absolute expire,
                             const char *name,
            const struct GNUNET_NAMESTORE_RecordData *rd,
            GNUNET_NAMESTORE_ContinuationWithStatus cont,
index 83fdf18730b0de924d32a3d11c3133a06e3430fa..493cb73112a06e0b730fce866fd9a76ed607f1b9 100644 (file)
@@ -302,6 +302,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
 
   GNUNET_NAMESTORE_record_create (namestore_handle,
                                   alice_key,
+                                  GNUNET_TIME_absolute_get_forever(),
                                   TEST_AUTHORITY_NAME,
                                   &rd,
                                   &put_dht,
index 059d08c067f09138c12004ad63c24acce7446c8a..0ccf872edb3513c028f7019b7787161bddc12fc5 100644 (file)
@@ -226,6 +226,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
 
   GNUNET_NAMESTORE_record_create (namestore_handle,
                                   alice_key,
+                                  GNUNET_TIME_absolute_get_forever(),
                                   TEST_AUTHORITY_NAME,
                                   &rd,
                                   NULL,
index d75ff2d28f4aeac56bb0ae4d257106eedb14661c..2b8e0ae883135462a32d5dcee8f5bbf625a51ded 100644 (file)
@@ -214,6 +214,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
 
   GNUNET_NAMESTORE_record_create (namestore_handle,
                                   alice_key,
+                                  GNUNET_TIME_absolute_get_forever(),
                                   TEST_RECORD_NAME,
                                   &rd,
                                   &finish_testing,
index 8ebb9611b31ac8b10b9daa51daacc709313b055e..d8988f34c11235e1383ed7c95a4a67cae80fb5b8 100644 (file)
@@ -437,6 +437,7 @@ run (void *cls, char *const *args, const char *cfgfile,
 
   GNUNET_NAMESTORE_record_create (namestore_handle,
                                   alice_key,
+                                  GNUNET_TIME_absolute_get_forever(),
                                   "bob",
                                   &rd,
                                   NULL,
@@ -445,6 +446,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   rd.data = &alice_pkey;
   GNUNET_NAMESTORE_record_create (namestore_handle,
                                   bob_key,
+                                  GNUNET_TIME_absolute_get_forever(),
                                   "alice",
                                   &rd,
                                   NULL,
@@ -460,6 +462,7 @@ run (void *cls, char *const *args, const char *cfgfile,
 
   GNUNET_NAMESTORE_record_create (namestore_handle,
                                   bob_key,
+                                  GNUNET_TIME_absolute_get_forever(),
                                   "www",
                                   &rd,
                                   NULL,
index f2f314bfc25a0ed871d252700781a228335afeaa..497d57136060e4bc606c54374846c59997d0fb7c 100644 (file)
@@ -227,6 +227,7 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinary
  *
  * @param h handle to the namestore
  * @param pkey private key of the zone
+ * @param expire block expiration time
  * @param name name that is being mapped (at most 255 characters long)
  * @param rd record data to store
  * @param cont continuation to call when done
@@ -235,11 +236,12 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinary
  */
 struct GNUNET_NAMESTORE_QueueEntry *
 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
-                               const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
-                               const char *name,
-                               const struct GNUNET_NAMESTORE_RecordData *rd,
-                               GNUNET_NAMESTORE_ContinuationWithStatus cont,
-                               void *cont_cls);
+                                const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
+                                const struct GNUNET_TIME_Absolute expire,
+                                const char *name,
+                                const struct GNUNET_NAMESTORE_RecordData *rd,
+                                GNUNET_NAMESTORE_ContinuationWithStatus cont,
+                                void *cont_cls);
 
 
 /**
index f48d1c23dc96e77e13db0f0210e7cfa42c4386e8..9829eaaa41d3c13bd934887a9e3da6fb8eeced83 100644 (file)
@@ -103,7 +103,11 @@ static char *typestring;
  * Desired expiration time.
  */
 static char *expirationstring;
-               
+
+/**
+ * Desired block expiration time.
+ */
+static char *blockexpirationstring;
 
 /**
  * Task run on shutdown.  Cleans up everything.
@@ -257,6 +261,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   void *data = NULL;
   size_t data_size = 0;
   struct GNUNET_TIME_Relative etime;
+  struct GNUNET_TIME_Relative btime;
   struct GNUNET_NAMESTORE_RecordData rd;
 
   if (NULL == keyfile)
@@ -354,6 +359,27 @@ run (void *cls, char *const *args, const char *cfgfile,
     GNUNET_SCHEDULER_shutdown ();
     return;     
   }
+  if (NULL != blockexpirationstring)
+  {
+    if (GNUNET_OK !=
+        GNUNET_STRINGS_fancy_time_to_relative (blockexpirationstring,
+                                               &btime))
+    {
+      fprintf (stderr,
+               _("Invalid time format `%s'\n"),
+               blockexpirationstring);
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+  } else if (add | del)
+  {
+    fprintf (stderr,
+             _("Missing option `%s' for operation `%s'\n"),
+             "-b", _("add/del"));
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+
   if (add)
   {
     if (NULL == name)
@@ -371,6 +397,7 @@ run (void *cls, char *const *args, const char *cfgfile,
     rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; // FIXME: not always...
     add_qe = GNUNET_NAMESTORE_record_create (ns,
                                             zone_pkey,
+                                             GNUNET_TIME_relative_to_absolute (btime),
                                             name,
                                             &rd,
                                             &add_continuation,
@@ -391,7 +418,7 @@ run (void *cls, char *const *args, const char *cfgfile,
     rd.record_type = type;
     rd.expiration = GNUNET_TIME_relative_to_absolute (etime);
     rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; // FIXME: not always...
-    del_qe = GNUNET_NAMESTORE_record_create (ns,
+    del_qe = GNUNET_NAMESTORE_record_remove (ns,
                                             zone_pkey,
                                             name,
                                             &rd,
@@ -423,7 +450,10 @@ main (int argc, char *const *argv)
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
     {'a', "add", NULL,
      gettext_noop ("add record"), 0,
-     &GNUNET_GETOPT_set_one, &add},   
+     &GNUNET_GETOPT_set_one, &add},
+    {'b', "name-expiration", "TIME",
+     gettext_noop ("expiration time for name to use (for adding only)"), 1,
+     &GNUNET_GETOPT_set_string, &blockexpirationstring},
     {'d', "delete", NULL,
      gettext_noop ("delete record"), 0,
      &GNUNET_GETOPT_set_one, &del},   
@@ -431,7 +461,7 @@ main (int argc, char *const *argv)
      gettext_noop ("display records"), 0,
      &GNUNET_GETOPT_set_one, &list},   
     {'e', "expiration", "TIME",
-     gettext_noop ("expiration time to use (for adding only)"), 1,
+     gettext_noop ("expiration time for record to use (for adding only)"), 1,
      &GNUNET_GETOPT_set_string, &expirationstring},   
     {'n', "name", "NAME",
      gettext_noop ("name of the record to add/delete/display"), 1,
index c92f39a595ac8c1152b48788c585bf9cde5a16ce..67c7e6e57d0847f273b5a76531214072ee87ccc6 100644 (file)
@@ -170,6 +170,7 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
     GNUNET_free (no);
   }
 
+
   GNUNET_SERVER_client_drop(nc->client);
   GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
   GNUNET_free (nc);
@@ -543,6 +544,7 @@ handle_create_record_it (void *cls,
   struct CreateRecordContext * crc = cls;
   struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL;
   struct GNUNET_NAMESTORE_RecordData *rd_new = NULL;
+  struct GNUNET_TIME_Absolute block_expiration;
   int res;
   int exist = GNUNET_SYSERR;
   int update = GNUNET_NO;
@@ -609,11 +611,16 @@ handle_create_record_it (void *cls,
     }
   }
 
+  block_expiration = GNUNET_TIME_absolute_max(crc->expire, expire);
+  if (block_expiration.abs_value != expire.abs_value)
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updated block expiration time\n");
+
+
   /* Database operation */
   GNUNET_assert ((rd_new != NULL) && (rd_count_new > 0));
   res = GSN_database->put_records(GSN_database->cls,
                                 (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) crc->pubkey,
-                                crc->expire,
+                                block_expiration,
                                 crc->name,
                                 rd_count_new, rd_new,
                                 signature_new);
@@ -729,6 +736,7 @@ static void handle_record_create (void *cls,
   }
 
   struct GNUNET_NAMESTORE_RecordData rd[rd_count];
+
   res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd);
   if ((res != GNUNET_OK) || (rd_count != 1))
   {
@@ -742,6 +750,8 @@ static void handle_record_create (void *cls,
   GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub);
   GNUNET_CRYPTO_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash);
 
+  crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
+  crc.res = GNUNET_SYSERR;
   crc.pkey = pkey;
   crc.pubkey = &pub;
   crc.rd = rd;
@@ -1289,7 +1299,6 @@ static void handle_iteration_start (void *cls,
 
   GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
 
-
   res = GSN_database->iterate_records (GSN_database->cls, zone_tmp , NULL, zi->offset , &zone_iteration_proc, zi);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
index 87894cee3ef4a5ef01370e49a2c211890635c059..9cdc70454be0e8400eaaa2d0f148dedd030880b0 100644 (file)
@@ -1095,6 +1095,7 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinary
  *
  * @param h handle to the namestore
  * @param pkey private key of the zone
+ * @param expire block expiration time
  * @param name name that is being mapped (at most 255 characters long)
  * @param rd record data to store
  * @param cont continuation to call when done
@@ -1104,6 +1105,7 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinary
 struct GNUNET_NAMESTORE_QueueEntry *
 GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
                                const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
+                               const struct GNUNET_TIME_Absolute expire,
                                const char *name,
                                const struct GNUNET_NAMESTORE_RecordData *rd,
                                GNUNET_NAMESTORE_ContinuationWithStatus cont,
@@ -1169,6 +1171,7 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
   msg->rd_count = htons (1);
   msg->rd_len = htons (rd_ser_len);
   msg->pkey_len = htons (key_len);
+  msg->expire = GNUNET_TIME_absolute_hton(expire);
   memcpy (pkey_tmp, pkey_enc, key_len);
   memcpy (name_tmp, name, name_len);
   memcpy (rd_tmp, rd_ser, rd_ser_len);
index f4cd32dbdc0292d498f10b6b4c78aeaac11a5c7c..a1ddd10e4a30c73e749db3fe87acbeb1f61343be 100644 (file)
@@ -4,7 +4,7 @@ DEFAULTSERVICES = namestore
 UNIXPATH = /tmp/gnunet-p1-service-arm.sock
 
 [namestore]
-#PREFIX = valgrind --leak-check=full
+#PREFIX = valgrind --leak-check=full --track-origins=yes 
 AUTOSTART = YES
 UNIXPATH = /tmp/gnunet-service-namestore.sock
 UNIX_MATCH_UID = YES
index a2e1366c840f2caeb515f5f3ee3069254fe60a3f..6cbf617cf49ef332356e9474f9d0a99e6ca69f27 100644 (file)
@@ -301,7 +301,7 @@ void name_lookup_initial_proc (void *cls,
     s_second_record->data_size = TEST_CREATE_RECORD_DATALEN;
     memset ((char *) s_second_record->data, TEST_CREATE_RECORD_DATA, TEST_CREATE_RECORD_DATALEN);
 
-    GNUNET_NAMESTORE_record_create (nsh, privkey, name, s_second_record, &create_second_cont, name);
+    GNUNET_NAMESTORE_record_create (nsh, privkey, GNUNET_TIME_absolute_get_forever(), name, s_second_record, &create_second_cont, name);
 
   }
   else
@@ -430,7 +430,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   GNUNET_break (s_name != NULL);
 
   /* create initial record */
-  GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record, &create_first_cont, s_name);
+  GNUNET_NAMESTORE_record_create (nsh, privkey, GNUNET_TIME_absolute_get_forever(), s_name, s_first_record, &create_first_cont, s_name);
 }
 
 static int
index ca2cde10c4ac33776f8b566ab6a79453acb8181a..f209b22c258ebeb5ab42c65bd4bd7b80aa1c35d9 100644 (file)
@@ -301,7 +301,7 @@ void name_lookup_initial_proc (void *cls,
     s_second_record->data_size = TEST_CREATE_RECORD_DATALEN;
     memset ((char *) s_second_record->data, TEST_CREATE_RECORD_DATA, TEST_CREATE_RECORD_DATALEN);
 
-    GNUNET_NAMESTORE_record_create (nsh, privkey, name, s_second_record, &create_second_cont, name);
+    GNUNET_NAMESTORE_record_create (nsh, privkey, GNUNET_TIME_absolute_get_forever(), name, s_second_record, &create_second_cont, name);
 
   }
   else
@@ -349,7 +349,7 @@ create_identical_cont (void *cls, int32_t success, const char *emsg)
   {
     res = 0;
     s_first_record->expiration = GNUNET_TIME_absolute_get ();
-    GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record, &create_updated_cont, s_name);
+    GNUNET_NAMESTORE_record_create (nsh, privkey, GNUNET_TIME_absolute_get_forever(), s_name, s_first_record, &create_updated_cont, s_name);
   }
   else
   {
@@ -369,7 +369,7 @@ create_first_cont (void *cls, int32_t success, const char *emsg)
   {
     res = 0;
     /* check if record was created correct */
-    GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record, &create_identical_cont, s_name);
+    GNUNET_NAMESTORE_record_create (nsh, privkey, GNUNET_TIME_absolute_get_forever(), s_name, s_first_record, &create_identical_cont, s_name);
   }
   else
   {
@@ -474,7 +474,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   GNUNET_break (s_name != NULL);
 
   /* create initial record */
-  GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record, &create_first_cont, s_name);
+  GNUNET_NAMESTORE_record_create (nsh, privkey, GNUNET_TIME_absolute_get_forever(), s_name, s_first_record, &create_first_cont, s_name);
 }
 
 static int
index 92e8e7988a89762766081e072ba2a76c42dc346f..ed4424210f3944941e4aad816541e9af347e29dd 100644 (file)
@@ -409,7 +409,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   GNUNET_asprintf(&s_name_1, "dummy1");
   s_rd_1 = create_record(1);
   sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1);
-  GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL);
+  GNUNET_NAMESTORE_record_create(nsh, privkey, GNUNET_TIME_absolute_get_forever(), s_name_1, s_rd_1, &put_cont, NULL);
 
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
@@ -417,7 +417,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   s_rd_2 = create_record(1);
 
   sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_name_2, s_rd_2, 1);
-  GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL);
+  GNUNET_NAMESTORE_record_create(nsh, privkey, GNUNET_TIME_absolute_get_forever(), s_name_2, s_rd_2, &put_cont, NULL);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
   /* name in different zone */
index 7cdcea42a08cc7d4094e777e8506fec49e74e4df..74a607335112045b143c4472d2f4726bba485722 100644 (file)
@@ -390,7 +390,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   GNUNET_asprintf(&s_name_1, "dummy1");
   s_rd_1 = create_record(1);
   sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1);
-  GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL);
+  GNUNET_NAMESTORE_record_create(nsh, privkey, GNUNET_TIME_absolute_get_forever(), s_name_1, s_rd_1, &put_cont, NULL);
 
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
@@ -398,7 +398,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   s_rd_2 = create_record(1);
 
   sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_name_2, s_rd_2, 1);
-  GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL);
+  GNUNET_NAMESTORE_record_create(nsh, privkey, GNUNET_TIME_absolute_get_forever(), s_name_2, s_rd_2, &put_cont, NULL);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
   /* name in different zone */
index 36a08d7db3cc14d242f1ba06ca8137252188f9a6..0b4917855b86b1bc6ffaeb8495fadb9cb822cc5c 100644 (file)
@@ -28,7 +28,7 @@
 
 #define VERBOSE GNUNET_NO
 
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
 
 static struct GNUNET_NAMESTORE_Handle * nsh;
 
@@ -430,7 +430,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   GNUNET_asprintf(&s_name_1, "dummy1");
   s_rd_1 = create_record(1);
   sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1);
-  GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL);
+  GNUNET_NAMESTORE_record_create(nsh, privkey, GNUNET_TIME_absolute_get_forever(), s_name_1, s_rd_1, &put_cont, NULL);
 
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
@@ -438,7 +438,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   s_rd_2 = create_record(1);
 
   sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_name_2, s_rd_2, 1);
-  GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL);
+  GNUNET_NAMESTORE_record_create(nsh, privkey,GNUNET_TIME_absolute_get_forever(),  s_name_2, s_rd_2, &put_cont, NULL);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
   /* name in different zone */