aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_multipeer.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-11-05 18:21:50 +0000
committerNathan S. Evans <evans@in.tum.de>2010-11-05 18:21:50 +0000
commit75a33a1499cf60ea4364c9aa673816629a6c1413 (patch)
tree0620da4312bb04de4d7b65074fdd3b0c3dd6cc0e /src/dht/test_dht_multipeer.c
parent7217c601ad30760872823193d62307e7a335d226 (diff)
downloadgnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.tar.gz
gnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.zip
big scheduler refactoring, expect some issues
Diffstat (limited to 'src/dht/test_dht_multipeer.c')
-rw-r--r--src/dht/test_dht_multipeer.c96
1 files changed, 41 insertions, 55 deletions
diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c
index dc877c28b..9c18c4f2e 100644
--- a/src/dht/test_dht_multipeer.c
+++ b/src/dht/test_dht_multipeer.c
@@ -153,11 +153,6 @@ static struct GNUNET_TESTING_PeerGroup *pg;
153 153
154 154
155/** 155/**
156 * Global scheduler, used for all GNUNET_SCHEDULER_* functions.
157 */
158static struct GNUNET_SCHEDULER_Handle *sched;
159
160/**
161 * Total number of peers to run, set based on config file. 156 * Total number of peers to run, set based on config file.
162 */ 157 */
163static unsigned long long num_peers; 158static unsigned long long num_peers;
@@ -269,7 +264,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
269 while (test_put != NULL) 264 while (test_put != NULL)
270 { 265 {
271 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 266 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
272 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task); 267 GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
273 if (test_put->dht_handle != NULL) 268 if (test_put->dht_handle != NULL)
274 GNUNET_DHT_disconnect(test_put->dht_handle); 269 GNUNET_DHT_disconnect(test_put->dht_handle);
275 test_put = test_put->next; 270 test_put = test_put->next;
@@ -278,7 +273,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
278 while (test_get != NULL) 273 while (test_get != NULL)
279 { 274 {
280 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 275 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
281 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task); 276 GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
282 if (test_get->get_handle != NULL) 277 if (test_get->get_handle != NULL)
283 GNUNET_DHT_get_stop(test_get->get_handle); 278 GNUNET_DHT_get_stop(test_get->get_handle);
284 if (test_get->dht_handle != NULL) 279 if (test_get->dht_handle != NULL)
@@ -307,7 +302,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
307 while (test_put != NULL) 302 while (test_put != NULL)
308 { 303 {
309 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 304 if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
310 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task); 305 GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
311 if (test_put->dht_handle != NULL) 306 if (test_put->dht_handle != NULL)
312 GNUNET_DHT_disconnect(test_put->dht_handle); 307 GNUNET_DHT_disconnect(test_put->dht_handle);
313 test_put = test_put->next; 308 test_put = test_put->next;
@@ -316,7 +311,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
316 while (test_get != NULL) 311 while (test_get != NULL)
317 { 312 {
318 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) 313 if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
319 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task); 314 GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
320 if (test_get->get_handle != NULL) 315 if (test_get->get_handle != NULL)
321 GNUNET_DHT_get_stop(test_get->get_handle); 316 GNUNET_DHT_get_stop(test_get->get_handle);
322 if (test_get->dht_handle != NULL) 317 if (test_get->dht_handle != NULL)
@@ -342,14 +337,14 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed); 337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed);
343 if ((gets_completed == num_gets) && (outstanding_gets == 0))/* All gets successful */ 338 if ((gets_completed == num_gets) && (outstanding_gets == 0))/* All gets successful */
344 { 339 {
345 GNUNET_SCHEDULER_cancel (sched, die_task); 340 GNUNET_SCHEDULER_cancel (die_task);
346 //GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, NULL); 341 //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, NULL);
347 GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL); 342 GNUNET_SCHEDULER_add_now(&finish_testing, NULL);
348 } 343 }
349 else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */ 344 else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */
350 { 345 {
351 GNUNET_SCHEDULER_cancel(sched, die_task); 346 GNUNET_SCHEDULER_cancel(die_task);
352 GNUNET_SCHEDULER_add_now(sched, &end_badly, "not all gets succeeded!\n"); 347 GNUNET_SCHEDULER_add_now(&end_badly, "not all gets succeeded!\n");
353 } 348 }
354} 349}
355 350
@@ -373,7 +368,7 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
373 } 368 }
374 GNUNET_assert(test_get->get_handle != NULL); 369 GNUNET_assert(test_get->get_handle != NULL);
375 GNUNET_DHT_get_stop(test_get->get_handle); 370 GNUNET_DHT_get_stop(test_get->get_handle);
376 GNUNET_SCHEDULER_add_now (sched, &get_stop_finished, test_get); 371 GNUNET_SCHEDULER_add_now (&get_stop_finished, test_get);
377 test_get->get_handle = NULL; 372 test_get->get_handle = NULL;
378 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK; 373 test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
379} 374}
@@ -418,8 +413,8 @@ void get_result_iterator (void *cls,
418 } 413 }
419 414
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n"); 415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
421 GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task); 416 GNUNET_SCHEDULER_cancel(test_get->disconnect_task);
422 GNUNET_SCHEDULER_add_continuation(sched, &get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 417 GNUNET_SCHEDULER_add_continuation(&get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
423} 418}
424 419
425 420
@@ -440,11 +435,11 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
440 435
441 if (outstanding_gets > MAX_OUTSTANDING_GETS) 436 if (outstanding_gets > MAX_OUTSTANDING_GETS)
442 { 437 {
443 GNUNET_SCHEDULER_add_delayed (sched, GET_DELAY, &do_get, test_get); 438 GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get);
444 return; 439 return;
445 } 440 }
446 441
447 test_get->dht_handle = GNUNET_DHT_connect(sched, test_get->daemon->cfg, 10); 442 test_get->dht_handle = GNUNET_DHT_connect(test_get->daemon->cfg, 10);
448 /* Insert the data at the first peer */ 443 /* Insert the data at the first peer */
449 GNUNET_assert(test_get->dht_handle != NULL); 444 GNUNET_assert(test_get->dht_handle != NULL);
450 outstanding_gets++; 445 outstanding_gets++;
@@ -462,8 +457,8 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
462 test_get->uid, 457 test_get->uid,
463 test_get->daemon->shortname); 458 test_get->daemon->shortname);
464#endif 459#endif
465 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GET_TIMEOUT, &get_stop_task, test_get); 460 test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, &get_stop_task, test_get);
466 GNUNET_SCHEDULER_add_now (sched, &do_get, test_get->next); 461 GNUNET_SCHEDULER_add_now (&do_get, test_get->next);
467} 462}
468 463
469/** 464/**
@@ -477,12 +472,12 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
477 outstanding_puts--; 472 outstanding_puts--;
478 puts_completed++; 473 puts_completed++;
479 474
480 GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task); 475 GNUNET_SCHEDULER_cancel(test_put->disconnect_task);
481 test_put->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &put_disconnect_task, test_put); 476 test_put->disconnect_task = GNUNET_SCHEDULER_add_now(&put_disconnect_task, test_put);
482 if (puts_completed == num_puts) 477 if (puts_completed == num_puts)
483 { 478 {
484 GNUNET_assert(outstanding_puts == 0); 479 GNUNET_assert(outstanding_puts == 0);
485 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, all_gets); 480 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &do_get, all_gets);
486 return; 481 return;
487 } 482 }
488} 483}
@@ -505,7 +500,7 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
505 500
506 if (outstanding_puts > MAX_OUTSTANDING_PUTS) 501 if (outstanding_puts > MAX_OUTSTANDING_PUTS)
507 { 502 {
508 GNUNET_SCHEDULER_add_delayed (sched, PUT_DELAY, &do_put, test_put); 503 GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put);
509 return; 504 return;
510 } 505 }
511 506
@@ -514,7 +509,7 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
514 test_put->uid, 509 test_put->uid,
515 test_put->daemon->shortname); 510 test_put->daemon->shortname);
516#endif 511#endif
517 test_put->dht_handle = GNUNET_DHT_connect(sched, test_put->daemon->cfg, 10); 512 test_put->dht_handle = GNUNET_DHT_connect(test_put->daemon->cfg, 10);
518 513
519 GNUNET_assert(test_put->dht_handle != NULL); 514 GNUNET_assert(test_put->dht_handle != NULL);
520 outstanding_puts++; 515 outstanding_puts++;
@@ -526,8 +521,8 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
526 GNUNET_TIME_UNIT_FOREVER_ABS, 521 GNUNET_TIME_UNIT_FOREVER_ABS,
527 GNUNET_TIME_UNIT_FOREVER_REL, 522 GNUNET_TIME_UNIT_FOREVER_REL,
528 &put_finished, test_put); 523 &put_finished, test_put);
529 test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put); 524 test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put);
530 GNUNET_SCHEDULER_add_now(sched, &do_put, test_put->next); 525 GNUNET_SCHEDULER_add_now(&do_put, test_put->next);
531} 526}
532 527
533 528
@@ -568,7 +563,7 @@ setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
568 all_gets = test_get; 563 all_gets = test_get;
569 } 564 }
570 565
571 GNUNET_SCHEDULER_add_now (sched, &do_put, all_puts); 566 GNUNET_SCHEDULER_add_now (&do_put, all_puts);
572} 567}
573 568
574 569
@@ -619,17 +614,16 @@ topology_callback (void *cls,
619 "Created %d total connections, which is our target number! Starting next phase of testing.\n", 614 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
620 total_connections); 615 total_connections);
621#endif 616#endif
622 GNUNET_SCHEDULER_cancel (sched, die_task); 617 GNUNET_SCHEDULER_cancel (die_task);
623 die_task = GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT, 618 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
624 &end_badly, "from setup puts/gets"); 619 &end_badly, "from setup puts/gets");
625 620
626 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &setup_puts_and_gets, NULL); 621 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &setup_puts_and_gets, NULL);
627 } 622 }
628 else if (total_connections + failed_connections == expected_connections) 623 else if (total_connections + failed_connections == expected_connections)
629 { 624 {
630 GNUNET_SCHEDULER_cancel (sched, die_task); 625 GNUNET_SCHEDULER_cancel (die_task);
631 die_task = GNUNET_SCHEDULER_add_now (sched, 626 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from topology_callback (too many failed connections)");
632 &end_badly, "from topology_callback (too many failed connections)");
633 } 627 }
634} 628}
635 629
@@ -661,7 +655,7 @@ peers_started_callback (void *cls,
661 "All %d daemons started, now connecting peers!\n", 655 "All %d daemons started, now connecting peers!\n",
662 num_peers); 656 num_peers);
663#endif 657#endif
664 GNUNET_SCHEDULER_cancel (sched, die_task); 658 GNUNET_SCHEDULER_cancel (die_task);
665 659
666 expected_connections = -1; 660 expected_connections = -1;
667 if ((pg != NULL) && (peers_left == 0)) 661 if ((pg != NULL) && (peers_left == 0))
@@ -675,12 +669,10 @@ peers_started_callback (void *cls,
675 669
676 if (expected_connections == GNUNET_SYSERR) 670 if (expected_connections == GNUNET_SYSERR)
677 { 671 {
678 die_task = GNUNET_SCHEDULER_add_now (sched, 672 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)");
679 &end_badly, "from connect topology (bad return)");
680 } 673 }
681 674
682 die_task = GNUNET_SCHEDULER_add_delayed (sched, 675 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
683 TIMEOUT,
684 &end_badly, "from connect topology (timeout)"); 676 &end_badly, "from connect topology (timeout)");
685 677
686 ok = 0; 678 ok = 0;
@@ -701,13 +693,11 @@ create_topology ()
701 } 693 }
702 else 694 else
703 { 695 {
704 GNUNET_SCHEDULER_cancel (sched, die_task); 696 GNUNET_SCHEDULER_cancel (die_task);
705 die_task = GNUNET_SCHEDULER_add_now (sched, 697 die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from create topology (bad return)");
706 &end_badly, "from create topology (bad return)");
707 } 698 }
708 GNUNET_SCHEDULER_cancel (sched, die_task); 699 GNUNET_SCHEDULER_cancel (die_task);
709 die_task = GNUNET_SCHEDULER_add_delayed (sched, 700 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
710 TIMEOUT,
711 &end_badly, "from continue startup (timeout)"); 701 &end_badly, "from continue startup (timeout)");
712} 702}
713 703
@@ -744,13 +734,12 @@ void hostkey_callback (void *cls,
744 "All %d hostkeys created, now creating topology!\n", 734 "All %d hostkeys created, now creating topology!\n",
745 num_peers); 735 num_peers);
746#endif 736#endif
747 GNUNET_SCHEDULER_cancel (sched, die_task); 737 GNUNET_SCHEDULER_cancel (die_task);
748 /* Set up task in case topology creation doesn't finish 738 /* Set up task in case topology creation doesn't finish
749 * within a reasonable amount of time */ 739 * within a reasonable amount of time */
750 die_task = GNUNET_SCHEDULER_add_delayed (sched, 740 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
751 TIMEOUT,
752 &end_badly, "from create_topology"); 741 &end_badly, "from create_topology");
753 GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL); 742 GNUNET_SCHEDULER_add_now(&create_topology, NULL);
754 ok = 0; 743 ok = 0;
755 } 744 }
756} 745}
@@ -758,7 +747,6 @@ void hostkey_callback (void *cls,
758 747
759static void 748static void
760run (void *cls, 749run (void *cls,
761 struct GNUNET_SCHEDULER_Handle *s,
762 char *const *args, 750 char *const *args,
763 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 751 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
764{ 752{
@@ -767,7 +755,6 @@ run (void *cls,
767 char * blacklist_topology_str; 755 char * blacklist_topology_str;
768 char * connect_topology_option_str; 756 char * connect_topology_option_str;
769 char * connect_topology_option_modifier_string; 757 char * connect_topology_option_modifier_string;
770 sched = s;
771 758
772 /* Get path from configuration file */ 759 /* Get path from configuration file */
773 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) 760 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
@@ -851,11 +838,10 @@ run (void *cls,
851 peers_left = num_peers; 838 peers_left = num_peers;
852 839
853 /* Set up a task to end testing if peer start fails */ 840 /* Set up a task to end testing if peer start fails */
854 die_task = GNUNET_SCHEDULER_add_delayed (sched, 841 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers),
855 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers),
856 &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!"); 842 &end_badly, "didn't generate all hostkeys within a reasonable amount of time!!!");
857 843
858 pg = GNUNET_TESTING_daemons_start (sched, cfg, 844 pg = GNUNET_TESTING_daemons_start (cfg,
859 peers_left, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &hostkey_callback, NULL, &peers_started_callback, NULL, 845 peers_left, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, SECONDS_PER_PEER_START * num_peers), &hostkey_callback, NULL, &peers_started_callback, NULL,
860 &topology_callback, NULL, NULL); 846 &topology_callback, NULL, NULL);
861 847