From ab3c2a6c36e4f0f78ccd082b731262d637d819d3 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 7 Mar 2012 12:45:04 +0000 Subject: namestore api change: include block expiration time in record create --- src/gns/gnunet-gns-fcfsd.c | 1 + src/gns/namestore_stub_api.c | 1 + src/gns/test_gns_dht_delegated_lookup.c | 1 + src/gns/test_gns_simple_delegated_lookup.c | 1 + src/gns/test_gns_simple_lookup.c | 1 + src/gns/test_gns_twopeer.c | 3 ++ src/include/gnunet_namestore_service.h | 12 ++++--- src/namestore/gnunet-namestore.c | 38 +++++++++++++++++++--- src/namestore/gnunet-service-namestore.c | 13 ++++++-- src/namestore/namestore_api.c | 3 ++ src/namestore/test_namestore_api.conf | 2 +- src/namestore/test_namestore_api_create.c | 4 +-- src/namestore/test_namestore_api_create_update.c | 8 ++--- src/namestore/test_namestore_api_zone_iteration.c | 4 +-- ...st_namestore_api_zone_iteration_specific_zone.c | 4 +-- .../test_namestore_api_zone_iteration_stop.c | 6 ++-- 16 files changed, 77 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/gns/gnunet-gns-fcfsd.c b/src/gns/gnunet-gns-fcfsd.c index f931a3680..c93e3c285 100644 --- a/src/gns/gnunet-gns-fcfsd.c +++ b/src/gns/gnunet-gns-fcfsd.c @@ -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, diff --git a/src/gns/namestore_stub_api.c b/src/gns/namestore_stub_api.c index d067bca54..d17c5bdca 100644 --- a/src/gns/namestore_stub_api.c +++ b/src/gns/namestore_stub_api.c @@ -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, diff --git a/src/gns/test_gns_dht_delegated_lookup.c b/src/gns/test_gns_dht_delegated_lookup.c index 83fdf1873..493cb7311 100644 --- a/src/gns/test_gns_dht_delegated_lookup.c +++ b/src/gns/test_gns_dht_delegated_lookup.c @@ -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, diff --git a/src/gns/test_gns_simple_delegated_lookup.c b/src/gns/test_gns_simple_delegated_lookup.c index 059d08c06..0ccf872ed 100644 --- a/src/gns/test_gns_simple_delegated_lookup.c +++ b/src/gns/test_gns_simple_delegated_lookup.c @@ -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, diff --git a/src/gns/test_gns_simple_lookup.c b/src/gns/test_gns_simple_lookup.c index d75ff2d28..2b8e0ae88 100644 --- a/src/gns/test_gns_simple_lookup.c +++ b/src/gns/test_gns_simple_lookup.c @@ -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, diff --git a/src/gns/test_gns_twopeer.c b/src/gns/test_gns_twopeer.c index 8ebb9611b..d8988f34c 100644 --- a/src/gns/test_gns_twopeer.c +++ b/src/gns/test_gns_twopeer.c @@ -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, diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index f2f314bfc..497d57136 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h @@ -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); /** diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index f48d1c23d..9829eaaa4 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c @@ -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, diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index c92f39a59..67c7e6e57 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -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); } diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 87894cee3..9cdc70454 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c @@ -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); diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf index f4cd32dbd..a1ddd10e4 100644 --- a/src/namestore/test_namestore_api.conf +++ b/src/namestore/test_namestore_api.conf @@ -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 diff --git a/src/namestore/test_namestore_api_create.c b/src/namestore/test_namestore_api_create.c index a2e1366c8..6cbf617cf 100644 --- a/src/namestore/test_namestore_api_create.c +++ b/src/namestore/test_namestore_api_create.c @@ -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 diff --git a/src/namestore/test_namestore_api_create_update.c b/src/namestore/test_namestore_api_create_update.c index ca2cde10c..f209b22c2 100644 --- a/src/namestore/test_namestore_api_create_update.c +++ b/src/namestore/test_namestore_api_create_update.c @@ -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 diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index 92e8e7988..ed4424210 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c @@ -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 */ diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c index 7cdcea42a..74a607335 100644 --- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c +++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c @@ -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 */ diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c index 36a08d7db..0b4917855 100644 --- a/src/namestore/test_namestore_api_zone_iteration_stop.c +++ b/src/namestore/test_namestore_api_zone_iteration_stop.c @@ -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 */ -- cgit v1.2.3