X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fnamestore%2Ftest_namestore_api_zone_iteration.c;h=08224c1d86a075ee9f580f5bfb0345307271fadc;hb=0f8f8219d92f8f000aa662aa6beb3749f71f3486;hp=4e4ff88bcb748b93c78581466a243e07445449cd;hpb=808ef8ab410b486c5cca7515389f608e965d53b1;p=oweals%2Fgnunet.git diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index 4e4ff88bc..08224c1d8 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c @@ -28,7 +28,7 @@ #include "namestore.h" -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) static struct GNUNET_NAMESTORE_Handle * nsh; @@ -90,7 +90,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } if (nsh != NULL) - GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); + GNUNET_NAMESTORE_disconnect (nsh); nsh = NULL; GNUNET_free_non_null(sig_1); @@ -172,7 +172,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free (s_rd_3); } if (nsh != NULL) - GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); + GNUNET_NAMESTORE_disconnect (nsh); nsh = NULL; } @@ -187,7 +187,7 @@ zone_proc (void *cls, const struct GNUNET_CRYPTO_RsaSignature *signature) { int failed = GNUNET_NO; - if ((zone_key == NULL) && (name == NULL)) + if ((zone_key == NULL) && (name == NULL)) { GNUNET_break (3 == returned_records); if (3 == returned_records) @@ -328,11 +328,11 @@ put_cont (void *cls, int32_t success, const char *emsg) returned_records = 0; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, - NULL, - GNUNET_NAMESTORE_RF_NONE, - GNUNET_NAMESTORE_RF_NONE, - zone_proc, - &zone); + NULL, + GNUNET_NAMESTORE_RF_NONE, + GNUNET_NAMESTORE_RF_NONE, + &zone_proc, + &zone); if (zi == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); @@ -353,7 +353,7 @@ create_record (unsigned int count) rd = GNUNET_malloc (count * sizeof (struct GNUNET_NAMESTORE_RecordData)); for (c = 0; c < count; c++) { - rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value; + rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value; rd[c].record_type = 1111; rd[c].data_size = 50; rd[c].data = GNUNET_malloc(50); @@ -363,14 +363,27 @@ create_record (unsigned int count) } +/** + * Callback called from the zone iterator when we iterate over + * the empty zone. Check that we got no records and then + * start the actual tests by filling the zone. + */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +empty_zone_proc (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) { char *hostkey_file; struct GNUNET_TIME_Absolute et; - endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL); + GNUNET_assert (nsh == cls); + GNUNET_assert (NULL == name); + GNUNET_assert (NULL == zone_key); + zi = NULL; GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); @@ -390,8 +403,6 @@ run (void *cls, GNUNET_assert (privkey2 != NULL); GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2); GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2); - nsh = GNUNET_NAMESTORE_connect (cfg); - GNUNET_break (NULL != nsh); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); @@ -420,6 +431,31 @@ run (void *cls, } +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); + nsh = GNUNET_NAMESTORE_connect (cfg); + GNUNET_break (NULL != nsh); + /* first, iterate over empty namestore */ + zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, + NULL, + GNUNET_NAMESTORE_RF_NONE, + GNUNET_NAMESTORE_RF_NONE, + &empty_zone_proc, + nsh); + if (NULL == zi) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); + GNUNET_break (0); + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); + } +} + + int main (int argc, char *argv[]) {