aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_testbed.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-03-08 15:34:45 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-03-08 15:34:45 +0000
commit19b4dacf08575bd188f9010558e8299c6c8eb56e (patch)
tree1555b7c5ac0e6a4ac39028830a50086c70d19830 /src/testbed/testbed_api_testbed.c
parent6419502e4bb83f53caf9f3fd5170f8219516e38a (diff)
downloadgnunet-19b4dacf08575bd188f9010558e8299c6c8eb56e.tar.gz
gnunet-19b4dacf08575bd188f9010558e8299c6c8eb56e.zip
- fix (case where peers <= 2)
Diffstat (limited to 'src/testbed/testbed_api_testbed.c')
-rw-r--r--src/testbed/testbed_api_testbed.c107
1 files changed, 22 insertions, 85 deletions
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c
index 282e4af88..c54ef3e19 100644
--- a/src/testbed/testbed_api_testbed.c
+++ b/src/testbed/testbed_api_testbed.c
@@ -103,15 +103,20 @@ enum State
103 */ 103 */
104 RC_READY, 104 RC_READY,
105 105
106 /** 106 /* /\** */
107 * Peers are stopped 107 /* * Peers are stopped */
108 */ 108 /* *\/ */
109 RC_PEERS_STOPPED, 109 /* RC_PEERS_STOPPED, */
110
111 /* /\** */
112 /* * Peers are destroyed */
113 /* *\/ */
114 /* RC_PEERS_DESTROYED */
110 115
111 /** 116 /**
112 * Peers are destroyed 117 * All peers shutdown (stopped and destroyed)
113 */ 118 */
114 RC_PEERS_DESTROYED 119 RC_PEERS_SHUTDOWN
115}; 120};
116 121
117 122
@@ -377,7 +382,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
377 GNUNET_assert (NULL == rc->reg_handle); 382 GNUNET_assert (NULL == rc->reg_handle);
378 GNUNET_assert (NULL == rc->peers); 383 GNUNET_assert (NULL == rc->peers);
379 GNUNET_assert (NULL == rc->hc_handles); 384 GNUNET_assert (NULL == rc->hc_handles);
380 GNUNET_assert (RC_PEERS_DESTROYED == rc->state); 385 GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state);
381 if (NULL != rc->dll_op_head) 386 if (NULL != rc->dll_op_head)
382 { /* cancel our pending operations */ 387 { /* cancel our pending operations */
383 while (NULL != (dll_op = rc->dll_op_head)) 388 while (NULL != (dll_op = rc->dll_op_head))
@@ -441,8 +446,6 @@ shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
441{ 446{
442 struct RunContext *rc = cls; 447 struct RunContext *rc = cls;
443 struct DLLOperation *dll_op; 448 struct DLLOperation *dll_op;
444 int all_peers_destroyed;
445 unsigned int peer;
446 unsigned int nhost; 449 unsigned int nhost;
447 450
448 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != rc->shutdown_run_task); 451 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != rc->shutdown_run_task);
@@ -479,61 +482,17 @@ shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
479 } 482 }
480 if (RC_INIT == rc->state) 483 if (RC_INIT == rc->state)
481 rc->state = RC_READY; /* Even though we haven't called the master callback */ 484 rc->state = RC_READY; /* Even though we haven't called the master callback */
482 rc->peer_count = 0; 485 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
483 /* Check if some peers are stopped */ 486 dll_op->op = GNUNET_TESTBED_shutdown_peers (rc->c, dll_op, NULL, NULL);
484 for (peer = 0; peer < rc->num_peers; peer++) 487 DEBUG ("Shutting down peers\n");
485 {
486 if (NULL == rc->peers[peer])
487 continue;
488 if (PS_STOPPED != rc->peers[peer]->state)
489 break;
490 }
491 if (peer == rc->num_peers)
492 {
493 /* All peers are stopped */
494 rc->state = RC_PEERS_STOPPED;
495 all_peers_destroyed = GNUNET_YES;
496 for (peer = 0; peer < rc->num_peers; peer++)
497 {
498 if (NULL == rc->peers[peer])
499 continue;
500 all_peers_destroyed = GNUNET_NO;
501 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
502 dll_op->op = GNUNET_TESTBED_peer_destroy (rc->peers[peer]);
503 GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail,
504 dll_op);
505 }
506 if (all_peers_destroyed == GNUNET_NO)
507 {
508 DEBUG ("Destroying peers\n");
509 rc->pstart_time = GNUNET_TIME_absolute_get ();
510 return;
511 }
512 }
513 /* Some peers are stopped */
514 DEBUG ("Stopping peers\n");
515 rc->pstart_time = GNUNET_TIME_absolute_get (); 488 rc->pstart_time = GNUNET_TIME_absolute_get ();
516 for (peer = 0; peer < rc->num_peers; peer++) 489 GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail,
517 { 490 dll_op);
518 if ((NULL == rc->peers[peer]) || (PS_STARTED != rc->peers[peer]->state)) 491 return;
519 {
520 rc->peer_count++;
521 continue;
522 }
523 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
524 dll_op->op = GNUNET_TESTBED_peer_stop (rc->peers[peer], NULL, NULL);
525 dll_op->cls = rc->peers[peer];
526 GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail,
527 dll_op);
528 }
529 if (rc->peer_count != rc->num_peers)
530 return;
531 GNUNET_free (rc->peers);
532 rc->peers = NULL;
533 } 492 }
534 } 493 }
535 rc->state = RC_PEERS_DESTROYED; /* No peers are present so we consider the 494 rc->state = RC_PEERS_SHUTDOWN; /* No peers are present so we consider the
536 * state where all peers are destroyed */ 495 * state where all peers are SHUTDOWN */
537 GNUNET_SCHEDULER_add_now (&cleanup_task, rc); 496 GNUNET_SCHEDULER_add_now (&cleanup_task, rc);
538} 497}
539 498
@@ -625,7 +584,6 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
625{ 584{
626 struct RunContext *rc = cls; 585 struct RunContext *rc = cls;
627 struct DLLOperation *dll_op; 586 struct DLLOperation *dll_op;
628 unsigned int peer_id;
629 587
630 if (RC_INIT == rc->state) 588 if (RC_INIT == rc->state)
631 { 589 {
@@ -661,40 +619,20 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
661 if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) && 619 if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) &&
662 (event->details.operation_finished.operation == dll_op->op)) 620 (event->details.operation_finished.operation == dll_op->op))
663 break; 621 break;
664 if ((GNUNET_TESTBED_ET_PEER_STOP == event->type) &&
665 (event->details.peer_stop.peer == dll_op->cls))
666 break;
667 } 622 }
668 if (NULL == dll_op) 623 if (NULL == dll_op)
669 goto call_cc; 624 goto call_cc;
670 GNUNET_CONTAINER_DLL_remove (rc->dll_op_head, rc->dll_op_tail, dll_op); 625 GNUNET_CONTAINER_DLL_remove (rc->dll_op_head, rc->dll_op_tail, dll_op);
671 GNUNET_TESTBED_operation_done (dll_op->op); 626 GNUNET_TESTBED_operation_done (dll_op->op);
672 GNUNET_free (dll_op); 627 GNUNET_free (dll_op);
673 rc->peer_count++;
674 if (rc->peer_count < rc->num_peers)
675 return;
676 switch (rc->state) 628 switch (rc->state)
677 { 629 {
678 case RC_PEERS_CREATED: 630 case RC_PEERS_CREATED:
679 case RC_READY: 631 case RC_READY:
680 rc->state = RC_PEERS_STOPPED; 632 rc->state = RC_PEERS_SHUTDOWN;
681 DEBUG ("Peers stopped in %s\n", prof_time (rc));
682 DEBUG ("Destroying peers\n");
683 rc->pstart_time = GNUNET_TIME_absolute_get ();
684 rc->peer_count = 0;
685 for (peer_id = 0; peer_id < rc->num_peers; peer_id++)
686 {
687 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
688 dll_op->op = GNUNET_TESTBED_peer_destroy (rc->peers[peer_id]);
689 GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail,
690 dll_op);
691 }
692 break;
693 case RC_PEERS_STOPPED:
694 rc->state = RC_PEERS_DESTROYED;
695 GNUNET_free (rc->peers); 633 GNUNET_free (rc->peers);
696 rc->peers = NULL; 634 rc->peers = NULL;
697 DEBUG ("Peers destroyed in %s\n", prof_time (rc)); 635 DEBUG ("Peers shut down in %s\n", prof_time (rc));
698 GNUNET_SCHEDULER_add_now (&cleanup_task, rc); 636 GNUNET_SCHEDULER_add_now (&cleanup_task, rc);
699 break; 637 break;
700 default: 638 default:
@@ -876,7 +814,6 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
876 GNUNET_CONFIGURATION_destroy (rc->cfg); 814 GNUNET_CONFIGURATION_destroy (rc->cfg);
877 rc->cfg = GNUNET_CONFIGURATION_dup (cfg); 815 rc->cfg = GNUNET_CONFIGURATION_dup (cfg);
878 event_mask = rc->event_mask; 816 event_mask = rc->event_mask;
879 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
880 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 817 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
881 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); 818 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
882 if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE) 819 if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE)