diff options
Diffstat (limited to 'src/namestore/test_namestore_api_zone_iteration.c')
-rw-r--r-- | src/namestore/test_namestore_api_zone_iteration.c | 119 |
1 files changed, 98 insertions, 21 deletions
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index e70a3baf0..92e8e7988 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file namestore/test_namestore_api_zone_iteration.c | 21 | * @file namestore/test_namestore_api_zone_iteration.c |
22 | * @brief testcase for namestore_api.c zone iteration functionality | 22 | * @brief testcase for zone iteration functionality: iterate of a specific zone |
23 | */ | 23 | */ |
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_common.h" | 25 | #include "gnunet_common.h" |
@@ -40,8 +40,13 @@ static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | |||
40 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 40 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
41 | static GNUNET_HashCode zone; | 41 | static GNUNET_HashCode zone; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey2; | ||
44 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey2; | ||
45 | static GNUNET_HashCode zone2; | ||
46 | |||
43 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 47 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
44 | static int res; | 48 | static int res; |
49 | static int returned_records; | ||
45 | 50 | ||
46 | struct GNUNET_CRYPTO_RsaSignature *sig_1; | 51 | struct GNUNET_CRYPTO_RsaSignature *sig_1; |
47 | char * s_name_1; | 52 | char * s_name_1; |
@@ -51,6 +56,10 @@ struct GNUNET_CRYPTO_RsaSignature *sig_2; | |||
51 | char * s_name_2; | 56 | char * s_name_2; |
52 | struct GNUNET_NAMESTORE_RecordData *s_rd_2; | 57 | struct GNUNET_NAMESTORE_RecordData *s_rd_2; |
53 | 58 | ||
59 | struct GNUNET_CRYPTO_RsaSignature *sig_3; | ||
60 | char * s_name_3; | ||
61 | struct GNUNET_NAMESTORE_RecordData *s_rd_3; | ||
62 | |||
54 | static void | 63 | static void |
55 | start_arm (const char *cfgname) | 64 | start_arm (const char *cfgname) |
56 | { | 65 | { |
@@ -98,8 +107,11 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
98 | 107 | ||
99 | GNUNET_free_non_null(sig_1); | 108 | GNUNET_free_non_null(sig_1); |
100 | GNUNET_free_non_null(sig_2); | 109 | GNUNET_free_non_null(sig_2); |
110 | GNUNET_free_non_null(sig_3); | ||
101 | GNUNET_free_non_null(s_name_1); | 111 | GNUNET_free_non_null(s_name_1); |
102 | GNUNET_free_non_null(s_name_2); | 112 | GNUNET_free_non_null(s_name_2); |
113 | GNUNET_free_non_null(s_name_3); | ||
114 | |||
103 | if (s_rd_1 != NULL) | 115 | if (s_rd_1 != NULL) |
104 | { | 116 | { |
105 | GNUNET_free ((void *)s_rd_1->data); | 117 | GNUNET_free ((void *)s_rd_1->data); |
@@ -110,11 +122,20 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
110 | GNUNET_free ((void *)s_rd_2->data); | 122 | GNUNET_free ((void *)s_rd_2->data); |
111 | GNUNET_free (s_rd_2); | 123 | GNUNET_free (s_rd_2); |
112 | } | 124 | } |
125 | if (s_rd_3 != NULL) | ||
126 | { | ||
127 | GNUNET_free ((void *)s_rd_3->data); | ||
128 | GNUNET_free (s_rd_3); | ||
129 | } | ||
113 | 130 | ||
114 | if (privkey != NULL) | 131 | if (privkey != NULL) |
115 | GNUNET_CRYPTO_rsa_key_free (privkey); | 132 | GNUNET_CRYPTO_rsa_key_free (privkey); |
116 | privkey = NULL; | 133 | privkey = NULL; |
117 | 134 | ||
135 | if (privkey2 != NULL) | ||
136 | GNUNET_CRYPTO_rsa_key_free (privkey2); | ||
137 | privkey2 = NULL; | ||
138 | |||
118 | if (NULL != arm) | 139 | if (NULL != arm) |
119 | stop_arm(); | 140 | stop_arm(); |
120 | 141 | ||
@@ -137,15 +158,20 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
137 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | 158 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; |
138 | } | 159 | } |
139 | 160 | ||
140 | |||
141 | if (privkey != NULL) | 161 | if (privkey != NULL) |
142 | GNUNET_CRYPTO_rsa_key_free (privkey); | 162 | GNUNET_CRYPTO_rsa_key_free (privkey); |
143 | privkey = NULL; | 163 | privkey = NULL; |
144 | 164 | ||
145 | GNUNET_free_non_null(sig_1); | 165 | if (privkey2 != NULL) |
146 | GNUNET_free_non_null(sig_2); | 166 | GNUNET_CRYPTO_rsa_key_free (privkey2); |
147 | GNUNET_free_non_null(s_name_1); | 167 | privkey2 = NULL; |
148 | GNUNET_free_non_null(s_name_2); | 168 | |
169 | GNUNET_free (sig_1); | ||
170 | GNUNET_free (sig_2); | ||
171 | GNUNET_free (sig_3); | ||
172 | GNUNET_free (s_name_1); | ||
173 | GNUNET_free (s_name_2); | ||
174 | GNUNET_free (s_name_3); | ||
149 | if (s_rd_1 != NULL) | 175 | if (s_rd_1 != NULL) |
150 | { | 176 | { |
151 | GNUNET_free ((void *)s_rd_1->data); | 177 | GNUNET_free ((void *)s_rd_1->data); |
@@ -156,6 +182,11 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
156 | GNUNET_free ((void *)s_rd_2->data); | 182 | GNUNET_free ((void *)s_rd_2->data); |
157 | GNUNET_free (s_rd_2); | 183 | GNUNET_free (s_rd_2); |
158 | } | 184 | } |
185 | if (s_rd_3 != NULL) | ||
186 | { | ||
187 | GNUNET_free ((void *)s_rd_3->data); | ||
188 | GNUNET_free (s_rd_3); | ||
189 | } | ||
159 | 190 | ||
160 | if (nsh != NULL) | 191 | if (nsh != NULL) |
161 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 192 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
@@ -164,8 +195,6 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
164 | 195 | ||
165 | if (NULL != arm) | 196 | if (NULL != arm) |
166 | stop_arm(); | 197 | stop_arm(); |
167 | |||
168 | res = 0; | ||
169 | } | 198 | } |
170 | 199 | ||
171 | void zone_proc (void *cls, | 200 | void zone_proc (void *cls, |
@@ -177,10 +206,15 @@ void zone_proc (void *cls, | |||
177 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 206 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
178 | { | 207 | { |
179 | int failed = GNUNET_NO; | 208 | int failed = GNUNET_NO; |
180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for zone `%s'\n", GNUNET_h2s (&zone)); | ||
181 | if ((zone_key == NULL) && (name == NULL)) | 209 | if ((zone_key == NULL) && (name == NULL)) |
182 | { | 210 | { |
183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done\n"); | 211 | GNUNET_break (3 == returned_records); |
212 | if (3 == returned_records) | ||
213 | res = 0; | ||
214 | else | ||
215 | res = 1; | ||
216 | |||
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received last result, iteration done after receing %u results\n",returned_records ); | ||
184 | GNUNET_SCHEDULER_add_now (&end, NULL); | 218 | GNUNET_SCHEDULER_add_now (&end, NULL); |
185 | } | 219 | } |
186 | else | 220 | else |
@@ -227,17 +261,39 @@ void zone_proc (void *cls, | |||
227 | failed = GNUNET_YES; | 261 | failed = GNUNET_YES; |
228 | GNUNET_break (0); | 262 | GNUNET_break (0); |
229 | } | 263 | } |
230 | 264 | } | |
265 | else if (0 == strcmp (name, s_name_3)) | ||
266 | { | ||
267 | if (rd_count == 1) | ||
268 | { | ||
269 | if (GNUNET_YES != GNUNET_NAMESTORE_records_cmp(rd, s_rd_3)) | ||
270 | { | ||
271 | failed = GNUNET_YES; | ||
272 | GNUNET_break (0); | ||
273 | } | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | failed = GNUNET_YES; | ||
278 | GNUNET_break (0); | ||
279 | } | ||
280 | if (0 != memcmp (signature, sig_3, sizeof (struct GNUNET_CRYPTO_RsaSignature))) | ||
281 | { | ||
282 | failed = GNUNET_YES; | ||
283 | GNUNET_break (0); | ||
284 | } | ||
231 | } | 285 | } |
232 | else | 286 | else |
233 | { | 287 | { |
234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result `%s'\n", name); | 288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Comparing result failed: got name `%s'\n", name); |
289 | res = 1; | ||
235 | GNUNET_break (0); | 290 | GNUNET_break (0); |
236 | GNUNET_SCHEDULER_add_now (&end, NULL); | 291 | GNUNET_SCHEDULER_add_now (&end, NULL); |
237 | } | 292 | } |
238 | 293 | ||
239 | if (failed == GNUNET_NO) | 294 | if (failed == GNUNET_NO) |
240 | { | 295 | { |
296 | returned_records ++; | ||
241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n"); | 297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Telling namestore to send the next result\n"); |
242 | GNUNET_NAMESTORE_zone_iterator_next (zi); | 298 | GNUNET_NAMESTORE_zone_iterator_next (zi); |
243 | } | 299 | } |
@@ -276,11 +332,20 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
276 | { | 332 | { |
277 | c++; | 333 | c++; |
278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); | 334 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); |
279 | 335 | } | |
336 | else | ||
337 | { | ||
338 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records\n"); | ||
339 | GNUNET_break (0); | ||
340 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
341 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
280 | } | 342 | } |
281 | 343 | ||
282 | if (c == 2) | 344 | if (c == 3) |
283 | { | 345 | { |
346 | res = 1; | ||
347 | returned_records = 0; | ||
348 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); | ||
284 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, | 349 | zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, |
285 | NULL, | 350 | NULL, |
286 | GNUNET_NAMESTORE_RF_NONE, | 351 | GNUNET_NAMESTORE_RF_NONE, |
@@ -289,6 +354,7 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
289 | &zone); | 354 | &zone); |
290 | if (zi == NULL) | 355 | if (zi == NULL) |
291 | { | 356 | { |
357 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); | ||
292 | GNUNET_break (0); | 358 | GNUNET_break (0); |
293 | GNUNET_SCHEDULER_cancel (endbadly_task); | 359 | GNUNET_SCHEDULER_cancel (endbadly_task); |
294 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | 360 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); |
@@ -305,11 +371,11 @@ create_record (int count) | |||
305 | 371 | ||
306 | for (c = 0; c < count; c++) | 372 | for (c = 0; c < count; c++) |
307 | { | 373 | { |
308 | rd[c].expiration = GNUNET_TIME_absolute_get(); | 374 | rd[c].expiration = GNUNET_TIME_absolute_get(); |
309 | rd[c].record_type = 1111; | 375 | rd[c].record_type = 1111; |
310 | rd[c].data_size = 50; | 376 | rd[c].data_size = 50; |
311 | rd[c].data = GNUNET_malloc(50); | 377 | rd[c].data = GNUNET_malloc(50); |
312 | memset ((char *) rd[c].data, 'a', 50); | 378 | memset ((char *) rd[c].data, 'a', 50); |
313 | } | 379 | } |
314 | return rd; | 380 | return rd; |
315 | } | 381 | } |
@@ -326,6 +392,12 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
326 | GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); | 392 | GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); |
327 | GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone); | 393 | GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone); |
328 | 394 | ||
395 | privkey2 = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey2"); | ||
396 | GNUNET_assert (privkey2 != NULL); | ||
397 | GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2); | ||
398 | GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2); | ||
399 | |||
400 | |||
329 | start_arm (cfgfile); | 401 | start_arm (cfgfile); |
330 | GNUNET_assert (arm != NULL); | 402 | GNUNET_assert (arm != NULL); |
331 | 403 | ||
@@ -334,8 +406,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
334 | 406 | ||
335 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); | 407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); |
336 | 408 | ||
337 | |||
338 | |||
339 | GNUNET_asprintf(&s_name_1, "dummy1"); | 409 | GNUNET_asprintf(&s_name_1, "dummy1"); |
340 | s_rd_1 = create_record(1); | 410 | s_rd_1 = create_record(1); |
341 | sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1); | 411 | sig_1 = GNUNET_NAMESTORE_create_signature(privkey, s_name_1, s_rd_1, 1); |
@@ -348,6 +418,13 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
348 | 418 | ||
349 | sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_name_2, s_rd_2, 1); | 419 | sig_2 = GNUNET_NAMESTORE_create_signature(privkey, s_name_2, s_rd_2, 1); |
350 | GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL); | 420 | GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL); |
421 | |||
422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); | ||
423 | /* name in different zone */ | ||
424 | GNUNET_asprintf(&s_name_3, "dummy3"); | ||
425 | s_rd_3 = create_record(1); | ||
426 | sig_3 = GNUNET_NAMESTORE_create_signature(privkey, s_name_3, s_rd_3, 1); | ||
427 | GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_absolute_get_forever(), 1, s_rd_3, sig_3, &put_cont, NULL); | ||
351 | } | 428 | } |
352 | 429 | ||
353 | static int | 430 | static int |