From b2a772525198768d93100aacaf00376ef0d17404 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Mon, 5 Mar 2012 09:09:52 +0000 Subject: [PATCH] - expiration update --- src/namestore/gnunet-service-namestore.c | 29 ++++++++++++++++--- .../test_namestore_api_create_update.c | 28 ++++++++++-------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 8734ee34a..b7bd129e5 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -622,11 +622,9 @@ handle_create_record_it (void *cls, (crc->rd->data_size == rd[c].data_size) && (0 == memcmp (crc->rd->data, rd[c].data, rd[c].data_size))) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found existing records for `%s' to update!\n", crc->name); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found existing records for `%s' to update expiration date!\n", crc->name); exist = c; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "exp %llu %llu!\n", rd[c].expiration.abs_value, crc->rd->expiration.abs_value); if (crc->rd->expiration.abs_value != rd[c].expiration.abs_value) - update = GNUNET_YES; break; } @@ -664,6 +662,7 @@ handle_create_record_it (void *cls, rd_new = GNUNET_malloc ((rd_count) * sizeof (struct GNUNET_NAMESTORE_RecordData)); memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); rd_count_new = rd_count; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating expiration from %llu to %llu!\n", rd_new[exist].expiration.abs_value, crc->rd->expiration.abs_value); rd_new[exist].expiration = crc->rd->expiration; signature_new = GNUNET_NAMESTORE_create_signature (crc->pkey, crc->name, rd_new, rd_count_new); if (NULL == signature_new) @@ -689,8 +688,30 @@ end: GNUNET_free_non_null (rd_new); GNUNET_free_non_null (signature_new); + switch (res) { + case GNUNET_SYSERR: + /* failed to create the record */ + crc->res = GNUNET_SYSERR; + break; + case GNUNET_YES: + /* database operations OK */ + if (GNUNET_YES == update) + /* we updated an existing record */ + crc->res = GNUNET_NO; + else + /* we created a new record */ + crc->res = GNUNET_YES; + break; + case GNUNET_NO: + /* identical entry existed, so we did nothing */ + crc->res = GNUNET_NO; + break; + default: + break; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Update result for name `%s' %u\n", crc->name, res); - crc->res = res; + } static void handle_record_create (void *cls, diff --git a/src/namestore/test_namestore_api_create_update.c b/src/namestore/test_namestore_api_create_update.c index 2c91a00f4..22313aca9 100644 --- a/src/namestore/test_namestore_api_create_update.c +++ b/src/namestore/test_namestore_api_create_update.c @@ -19,7 +19,7 @@ */ /** * @file namestore/test_namestore_api.c - * @brief testcase for namestore_api.c + * @brief testcase for namestore_api.c for updating an existing record */ #include "platform.h" #include "gnunet_common.h" @@ -321,36 +321,40 @@ void create_updated_cont (void *cls, int32_t success, const char *emsg) { char *name = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg); - if (success == GNUNET_OK) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating expiration for record `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg); + if (success == GNUNET_NO) { res = 0; - GNUNET_SCHEDULER_add_now(&end, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updated record for name `%s'\n", name); + } + if (success == GNUNET_OK) + { + res = 1; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "FAIL, Create new record for name `%s'\n", name); } else { res = 1; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name); - GNUNET_SCHEDULER_add_now(&end, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create records for name `%s'\n", name); } - + GNUNET_SCHEDULER_add_now(&end, NULL); } void create_identical_cont (void *cls, int32_t success, const char *emsg) { char *name = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create updated record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg); - if (success == GNUNET_OK) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating identical record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg); + if (success == GNUNET_NO) { res = 0; - s_first_record->expiration = GNUNET_TIME_absolute_get_zero(); + s_first_record->expiration = GNUNET_TIME_absolute_get (); GNUNET_NAMESTORE_record_create (nsh, privkey, s_name, s_first_record, &create_updated_cont, s_name); } else { res = 1; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating identical record for `%s': %s `%s'\n", name, ((success == GNUNET_YES) || (success == GNUNET_NO)) ? "SUCCESS" : "FAIL", emsg); GNUNET_SCHEDULER_add_now(&end, NULL); } @@ -402,7 +406,7 @@ create_record (int count) for (c = 0; c < count; c++) { - rd[c].expiration = GNUNET_TIME_absolute_get(); + rd[c].expiration = GNUNET_TIME_absolute_get_zero(); rd[c].record_type = TEST_RECORD_TYPE; rd[c].data_size = TEST_RECORD_DATALEN; rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); -- 2.25.1