diff options
Diffstat (limited to 'src/dht/test_dht_topo.c')
-rw-r--r-- | src/dht/test_dht_topo.c | 190 |
1 files changed, 143 insertions, 47 deletions
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c index dfe969bb9..9f4b1b034 100644 --- a/src/dht/test_dht_topo.c +++ b/src/dht/test_dht_topo.c | |||
@@ -58,16 +58,36 @@ struct GetOperation | |||
58 | struct GetOperation *prev; | 58 | struct GetOperation *prev; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Operation to fetch @a me. | ||
62 | */ | ||
63 | struct GNUNET_TESTBED_Operation *to; | ||
64 | |||
65 | /** | ||
61 | * Handle for the operation. | 66 | * Handle for the operation. |
62 | */ | 67 | */ |
63 | struct GNUNET_DHT_GetHandle *get; | 68 | struct GNUNET_DHT_GetHandle *get; |
69 | |||
70 | /** | ||
71 | * DHT used by this operation. | ||
72 | */ | ||
73 | struct GNUNET_DHT_Handle *dht; | ||
74 | |||
75 | /** | ||
76 | * Key we are looking up. | ||
77 | */ | ||
78 | struct GNUNET_HashCode key; | ||
79 | |||
80 | /** | ||
81 | * At which peer is this operation being performed? | ||
82 | */ | ||
83 | struct GNUNET_PeerIdentity me; | ||
64 | }; | 84 | }; |
65 | 85 | ||
66 | 86 | ||
67 | /** | 87 | /** |
68 | * Result of the test. | 88 | * Result of the test. |
69 | */ | 89 | */ |
70 | static int ok = 1; | 90 | static int ok; |
71 | 91 | ||
72 | /** | 92 | /** |
73 | * Task to do DHT_puts | 93 | * Task to do DHT_puts |
@@ -154,7 +174,7 @@ static struct | |||
154 | 174 | ||
155 | 175 | ||
156 | static struct GNUNET_DHT_TEST_Context * | 176 | static struct GNUNET_DHT_TEST_Context * |
157 | stop_ops () | 177 | stop_ops (void) |
158 | { | 178 | { |
159 | struct GetOperation *get_op; | 179 | struct GetOperation *get_op; |
160 | struct GNUNET_DHT_TEST_Context *ctx = NULL; | 180 | struct GNUNET_DHT_TEST_Context *ctx = NULL; |
@@ -176,7 +196,16 @@ stop_ops () | |||
176 | } | 196 | } |
177 | while (NULL != (get_op = get_tail)) | 197 | while (NULL != (get_op = get_tail)) |
178 | { | 198 | { |
179 | GNUNET_DHT_get_stop (get_op->get); | 199 | if (NULL != get_op->to) |
200 | { | ||
201 | GNUNET_TESTBED_operation_done (get_op->to); | ||
202 | get_op->to = NULL; | ||
203 | } | ||
204 | if (NULL != get_op->get) | ||
205 | { | ||
206 | GNUNET_DHT_get_stop (get_op->get); | ||
207 | get_op->get = NULL; | ||
208 | } | ||
180 | GNUNET_CONTAINER_DLL_remove (get_head, | 209 | GNUNET_CONTAINER_DLL_remove (get_head, |
181 | get_tail, | 210 | get_tail, |
182 | get_op); | 211 | get_op); |
@@ -199,7 +228,6 @@ stats_finished (void *cls, | |||
199 | const char *emsg) | 228 | const char *emsg) |
200 | { | 229 | { |
201 | struct GNUNET_DHT_TEST_Context *ctx = cls; | 230 | struct GNUNET_DHT_TEST_Context *ctx = cls; |
202 | unsigned int i; | ||
203 | 231 | ||
204 | if (NULL != op) | 232 | if (NULL != op) |
205 | GNUNET_TESTBED_operation_done (op); | 233 | GNUNET_TESTBED_operation_done (op); |
@@ -212,7 +240,7 @@ stats_finished (void *cls, | |||
212 | GNUNET_DHT_TEST_cleanup (ctx); | 240 | GNUNET_DHT_TEST_cleanup (ctx); |
213 | return; | 241 | return; |
214 | } | 242 | } |
215 | for (i = 0; NULL != stats[i].name; i++) | 243 | for (unsigned int i = 0; NULL != stats[i].name; i++) |
216 | fprintf (stderr, | 244 | fprintf (stderr, |
217 | "%6s/%60s = %12llu\n", | 245 | "%6s/%60s = %12llu\n", |
218 | stats[i].subsystem, | 246 | stats[i].subsystem, |
@@ -234,7 +262,7 @@ stats_finished (void *cls, | |||
234 | * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not | 262 | * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not |
235 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 263 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
236 | */ | 264 | */ |
237 | static int | 265 | static enum GNUNET_GenericReturnValue |
238 | handle_stats (void *cls, | 266 | handle_stats (void *cls, |
239 | const struct GNUNET_TESTBED_Peer *peer, | 267 | const struct GNUNET_TESTBED_Peer *peer, |
240 | const char *subsystem, | 268 | const char *subsystem, |
@@ -242,9 +270,7 @@ handle_stats (void *cls, | |||
242 | uint64_t value, | 270 | uint64_t value, |
243 | int is_persistent) | 271 | int is_persistent) |
244 | { | 272 | { |
245 | unsigned int i; | 273 | for (unsigned int i = 0; NULL != stats[i].name; i++) |
246 | |||
247 | for (i = 0; NULL != stats[i].name; i++) | ||
248 | if ((0 == strcasecmp (subsystem, | 274 | if ((0 == strcasecmp (subsystem, |
249 | stats[i].subsystem)) && | 275 | stats[i].subsystem)) && |
250 | (0 == strcasecmp (name, | 276 | (0 == strcasecmp (name, |
@@ -263,7 +289,14 @@ handle_stats (void *cls, | |||
263 | static void | 289 | static void |
264 | shutdown_task (void *cls) | 290 | shutdown_task (void *cls) |
265 | { | 291 | { |
266 | (void) stop_ops (); | 292 | struct GNUNET_DHT_TEST_Context *ctx; |
293 | |||
294 | (void) cls; | ||
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
296 | "Performing shutdown\n"); | ||
297 | ctx = stop_ops (); | ||
298 | if (NULL != ctx) | ||
299 | GNUNET_DHT_TEST_cleanup (ctx); | ||
267 | } | 300 | } |
268 | 301 | ||
269 | 302 | ||
@@ -276,7 +309,11 @@ shutdown_task (void *cls) | |||
276 | static void | 309 | static void |
277 | timeout_cb (void *cls) | 310 | timeout_cb (void *cls) |
278 | { | 311 | { |
279 | timeout_task = NULL; | 312 | struct GNUNET_DHT_TEST_Context *ctx = cls; |
313 | |||
314 | timeout_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, | ||
315 | &timeout_cb, | ||
316 | ctx); | ||
280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 317 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
281 | "Timeout\n"); | 318 | "Timeout\n"); |
282 | GNUNET_SCHEDULER_shutdown (); | 319 | GNUNET_SCHEDULER_shutdown (); |
@@ -314,6 +351,13 @@ dht_get_handler (void *cls, | |||
314 | struct GNUNET_HashCode want; | 351 | struct GNUNET_HashCode want; |
315 | struct GNUNET_DHT_TEST_Context *ctx; | 352 | struct GNUNET_DHT_TEST_Context *ctx; |
316 | 353 | ||
354 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
355 | "Handling reply with GPL: %u PPL: %u!\n", | ||
356 | get_path_len, | ||
357 | put_path_len); | ||
358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
359 | "GET HANDLER called on PID %s\n", | ||
360 | GNUNET_i2s (&get_op->me)); | ||
317 | if (sizeof(struct GNUNET_HashCode) != size) | 361 | if (sizeof(struct GNUNET_HashCode) != size) |
318 | { | 362 | { |
319 | GNUNET_break (0); | 363 | GNUNET_break (0); |
@@ -329,26 +373,26 @@ dht_get_handler (void *cls, | |||
329 | GNUNET_break (0); | 373 | GNUNET_break (0); |
330 | return; | 374 | return; |
331 | } | 375 | } |
332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 376 | if (0 != |
333 | "Get successful\n"); | 377 | GNUNET_DHT_verify_path (key, |
334 | #if 0 | 378 | data, |
379 | size, | ||
380 | exp, | ||
381 | get_path, | ||
382 | get_path_length, | ||
383 | put_path, | ||
384 | put_path_length, | ||
385 | &get_op->me)) | ||
386 | { | ||
387 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
388 | "Path signature verification failed!\n"); | ||
389 | } | ||
390 | else | ||
335 | { | 391 | { |
336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
337 | "PATH: (get %u, put %u)\n", | 393 | "Get successful\n"); |
338 | get_path_length, | 394 | ok--; |
339 | put_path_length); | ||
340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
341 | " LOCAL\n"); | ||
342 | for (int i = get_path_length - 1; i >= 0; i--) | ||
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
344 | " %s\n", | ||
345 | GNUNET_i2s (&get_path[i])); | ||
346 | for (int i = put_path_length - 1; i >= 0; i--) | ||
347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
348 | " %s\n", | ||
349 | GNUNET_i2s (&put_path[i])); | ||
350 | } | 395 | } |
351 | #endif | ||
352 | GNUNET_DHT_get_stop (get_op->get); | 396 | GNUNET_DHT_get_stop (get_op->get); |
353 | GNUNET_CONTAINER_DLL_remove (get_head, | 397 | GNUNET_CONTAINER_DLL_remove (get_head, |
354 | get_tail, | 398 | get_tail, |
@@ -359,7 +403,6 @@ dht_get_handler (void *cls, | |||
359 | /* all DHT GET operations successful; get stats! */ | 403 | /* all DHT GET operations successful; get stats! */ |
360 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 404 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
361 | "All DHT operations successful. Obtaining stats!\n"); | 405 | "All DHT operations successful. Obtaining stats!\n"); |
362 | ok = 0; | ||
363 | ctx = stop_ops (); | 406 | ctx = stop_ops (); |
364 | GNUNET_assert (NULL != ctx); | 407 | GNUNET_assert (NULL != ctx); |
365 | (void) GNUNET_TESTBED_get_statistics (NUM_PEERS, | 408 | (void) GNUNET_TESTBED_get_statistics (NUM_PEERS, |
@@ -386,7 +429,8 @@ do_puts (void *cls) | |||
386 | 429 | ||
387 | put_task = NULL; | 430 | put_task = NULL; |
388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 431 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
389 | "Putting values into DHT\n"); | 432 | "Putting %u values into DHT\n", |
433 | NUM_PEERS); | ||
390 | for (unsigned int i = 0; i < NUM_PEERS; i++) | 434 | for (unsigned int i = 0; i < NUM_PEERS; i++) |
391 | { | 435 | { |
392 | GNUNET_CRYPTO_hash (&i, | 436 | GNUNET_CRYPTO_hash (&i, |
@@ -414,37 +458,86 @@ do_puts (void *cls) | |||
414 | 458 | ||
415 | 459 | ||
416 | /** | 460 | /** |
461 | * Callback to be called when the requested peer information is available | ||
462 | * The peer information in the callback is valid until the operation 'op' is canceled. | ||
463 | * | ||
464 | * @param cls a `struct GetOperation *` | ||
465 | * @param op the operation this callback corresponds to | ||
466 | * @param pinfo the result; will be NULL if the operation has failed | ||
467 | * @param emsg error message if the operation has failed; will be NULL if the | ||
468 | * operation is successful | ||
469 | */ | ||
470 | static void | ||
471 | pid_cb (void *cls, | ||
472 | struct GNUNET_TESTBED_Operation *op, | ||
473 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
474 | const char *emsg) | ||
475 | { | ||
476 | struct GetOperation *get_op = cls; | ||
477 | |||
478 | if (NULL != emsg) | ||
479 | { | ||
480 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
481 | "Testbed failure: %s\n", | ||
482 | emsg); | ||
483 | GNUNET_TESTBED_operation_done (get_op->to); | ||
484 | get_op->to = NULL; | ||
485 | GNUNET_SCHEDULER_shutdown (); | ||
486 | return; | ||
487 | } | ||
488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
489 | "Testbed provided PID %s\n", | ||
490 | GNUNET_i2s (pinfo->result.id)); | ||
491 | get_op->me = *pinfo->result.id; | ||
492 | GNUNET_TESTBED_operation_done (get_op->to); | ||
493 | get_op->to = NULL; | ||
494 | get_op->get = GNUNET_DHT_get_start (get_op->dht, | ||
495 | GNUNET_BLOCK_TYPE_TEST, | ||
496 | &get_op->key, | ||
497 | 4U, /* replication level */ | ||
498 | GNUNET_DHT_RO_RECORD_ROUTE | ||
499 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
500 | NULL, /* xquery */ | ||
501 | 0, /* xquery bits */ | ||
502 | &dht_get_handler, | ||
503 | get_op); | ||
504 | } | ||
505 | |||
506 | |||
507 | /** | ||
417 | * Start GET operations. | 508 | * Start GET operations. |
418 | */ | 509 | */ |
419 | static void | 510 | static void |
420 | start_get (void *cls) | 511 | start_get (void *cls) |
421 | { | 512 | { |
422 | struct GNUNET_DHT_Handle **dhts = cls; | 513 | struct GNUNET_DHT_Handle **dhts = cls; |
423 | unsigned int i; | ||
424 | unsigned int j; | ||
425 | struct GNUNET_HashCode key; | ||
426 | struct GetOperation *get_op; | ||
427 | 514 | ||
428 | get_task = NULL; | 515 | get_task = NULL; |
429 | for (i = 0; i < NUM_PEERS; i++) | 516 | for (unsigned int i = 0; i < NUM_PEERS; i++) |
430 | { | 517 | { |
431 | GNUNET_CRYPTO_hash (&i, sizeof(i), &key); | 518 | struct GNUNET_HashCode key; |
432 | for (j = 0; j < NUM_PEERS; j++) | 519 | |
520 | GNUNET_CRYPTO_hash (&i, | ||
521 | sizeof(i), | ||
522 | &key); | ||
523 | for (unsigned int j = 0; j < NUM_PEERS; j++) | ||
433 | { | 524 | { |
525 | struct GetOperation *get_op; | ||
526 | |||
434 | get_op = GNUNET_new (struct GetOperation); | 527 | get_op = GNUNET_new (struct GetOperation); |
528 | ok++; | ||
529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
530 | "Starting GET %p\n", | ||
531 | get_op); | ||
532 | get_op->key = key; | ||
533 | get_op->dht = dhts[j]; | ||
534 | get_op->to = GNUNET_TESTBED_peer_get_information (my_peers[j], | ||
535 | GNUNET_TESTBED_PIT_IDENTITY, | ||
536 | &pid_cb, | ||
537 | get_op); | ||
435 | GNUNET_CONTAINER_DLL_insert (get_head, | 538 | GNUNET_CONTAINER_DLL_insert (get_head, |
436 | get_tail, | 539 | get_tail, |
437 | get_op); | 540 | get_op); |
438 | get_op->get = GNUNET_DHT_get_start (dhts[j], | ||
439 | GNUNET_BLOCK_TYPE_TEST, /* type */ | ||
440 | &key, /*key to search */ | ||
441 | 4U, /* replication level */ | ||
442 | GNUNET_DHT_RO_RECORD_ROUTE | ||
443 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
444 | NULL, /* xquery */ | ||
445 | 0, /* xquery bits */ | ||
446 | &dht_get_handler, | ||
447 | get_op); | ||
448 | } | 541 | } |
449 | } | 542 | } |
450 | } | 543 | } |
@@ -492,6 +585,9 @@ main (int xargc, char *xargv[]) | |||
492 | const char *cfg_filename; | 585 | const char *cfg_filename; |
493 | const char *test_name; | 586 | const char *test_name; |
494 | 587 | ||
588 | unsetenv ("XDG_DATA_HOME"); | ||
589 | unsetenv ("XDG_CONFIG_HOME"); | ||
590 | unsetenv ("XDG_CACHE_HOME"); | ||
495 | if (NULL != strstr (xargv[0], "test_dht_2dtorus")) | 591 | if (NULL != strstr (xargv[0], "test_dht_2dtorus")) |
496 | { | 592 | { |
497 | cfg_filename = "test_dht_2dtorus.conf"; | 593 | cfg_filename = "test_dht_2dtorus.conf"; |