From: Christian Grothoff Date: Tue, 3 Jul 2012 19:15:15 +0000 (+0000) Subject: -fix gns record deletion X-Git-Tag: initial-import-from-subversion-38251~12669 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b2bf074b07c7c18795e4b2fabb7cb9780960ab1c;p=oweals%2Fgnunet.git -fix gns record deletion --- diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index b00967c00..ee8654948 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h @@ -170,6 +170,18 @@ enum GNUNET_NAMESTORE_RecordFlags */ GNUNET_NAMESTORE_RF_SHADOW_RECORD = 16 + /** + * When comparing flags for record equality for removal, + * which flags should must match (in addition to the type, + * name, expiration value and data of the record)? All flags + * that are not listed here will be ignored for this purpose. + * (for example, we don't expect that users will remember to + * pass the '--private' option when removing a record from + * the namestore, hence we don't require this particular option + * to match upon removal). See also + * 'GNUNET_NAMESTORE_records_cmp'. + */ +#define GNUNET_NAMESTORE_RF_RCMP_FLAGS (GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION) }; diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 95ee989d1..7609c73a3 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -1280,15 +1280,13 @@ handle_record_remove_it (void *cls, rrc->op_res = RECORD_REMOVE_RESULT_NO_RECORDS; return; } - /* Find record to remove */ found = -1; for (c = 0; c < rd_count; c++) { - if ( (rd[c].flags != rrc->rd->flags) || - (rd[c].record_type != rrc->rd->record_type) || - (rd[c].data_size != rrc->rd->data_size) || - (0 != memcmp (rd[c].data, rrc->rd->data, rrc->rd->data_size)) ) + if (GNUNET_YES != + GNUNET_NAMESTORE_records_cmp (&rd[c], + rrc->rd)) continue; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found record to remove!\n", rd_count); found = c; @@ -1379,6 +1377,7 @@ handle_record_remove (void *cls, uint32_t rid; struct RemoveRecordContext rrc; int res; + uint64_t off; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", @@ -1465,18 +1464,28 @@ handle_record_remove (void *cls, "Removing record for name `%s' in zone `%s'\n", name_tmp, GNUNET_short_h2s (&pubkey_hash)); rrc.rd = &rd; - res = GSN_database->iterate_records (GSN_database->cls, - &pubkey_hash, - name_tmp, - 0, - handle_record_remove_it, &rrc); + rrc.op_res = RECORD_REMOVE_RESULT_RECORD_NOT_FOUND; + off = 0; + res = GNUNET_OK; + while ( (RECORD_REMOVE_RESULT_RECORD_NOT_FOUND == rrc.op_res) && + (GNUNET_OK == res) ) + { + res = GSN_database->iterate_records (GSN_database->cls, + &pubkey_hash, + name_tmp, + off++, + &handle_record_remove_it, &rrc); + } switch (res) { case GNUNET_OK: res = rrc.op_res; break; case GNUNET_NO: + GNUNET_break (RECORD_REMOVE_RESULT_NO_RECORDS == rrc.op_res); res = RECORD_REMOVE_RESULT_NO_RECORDS; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Failed to find record to remove\n")); break; case GNUNET_SYSERR: res = RECORD_REMOVE_RESULT_FAILED_ACCESS_DATABASE; diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c index 8a2e15e2a..eead6e492 100644 --- a/src/namestore/namestore_common.c +++ b/src/namestore/namestore_common.c @@ -172,8 +172,8 @@ GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a, { if ((a->record_type == b->record_type) && (a->expiration_time == b->expiration_time) && - ((a->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION) - == (b->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION) ) && + ((a->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS) + == (b->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS) ) && (a->data_size == b->data_size) && (0 == memcmp (a->data, b->data, a->data_size))) return GNUNET_YES;