diff options
Diffstat (limited to 'src/dht/gnunet_dht_profiler.c')
-rw-r--r-- | src/dht/gnunet_dht_profiler.c | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index a884f31f8..24ec73921 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c | |||
@@ -616,10 +616,28 @@ delayed_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
616 | 616 | ||
617 | 617 | ||
618 | /** | 618 | /** |
619 | * Connect to DHT services of active peers | 619 | * Task to teardown the dht connection. We do it as a task because calling |
620 | * GNUNET_DHT_disconnect() from put_continutation_callback seems illegal (the | ||
621 | * put_continuation_callback() is getting called again synchronously). Also, | ||
622 | * only free the operation when we are not shutting down; the shutdown task will | ||
623 | * clear the operation during shutdown. | ||
624 | * | ||
625 | * @param cls the context | ||
626 | * @return tc scheduler task context. | ||
620 | */ | 627 | */ |
621 | static void | 628 | static void |
622 | start_profiling(); | 629 | teardown_dht_connection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
630 | { | ||
631 | struct Context *ctx = cls; | ||
632 | struct GNUNET_TESTBED_Operation *op; | ||
633 | |||
634 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
635 | return; | ||
636 | GNUNET_assert (NULL != ctx); | ||
637 | GNUNET_assert (NULL != (op = ctx->op)); | ||
638 | ctx->op = NULL; | ||
639 | GNUNET_TESTBED_operation_done (op); | ||
640 | } | ||
623 | 641 | ||
624 | 642 | ||
625 | /** | 643 | /** |
@@ -637,7 +655,6 @@ put_cont (void *cls, int success) | |||
637 | { | 655 | { |
638 | struct ActiveContext *ac = cls; | 656 | struct ActiveContext *ac = cls; |
639 | struct Context *ctx = ac->ctx; | 657 | struct Context *ctx = ac->ctx; |
640 | struct GNUNET_TESTBED_Operation *op; | ||
641 | 658 | ||
642 | ac->dht_put = NULL; | 659 | ac->dht_put = NULL; |
643 | if (success) | 660 | if (success) |
@@ -645,9 +662,7 @@ put_cont (void *cls, int success) | |||
645 | else | 662 | else |
646 | n_puts_fail++; | 663 | n_puts_fail++; |
647 | GNUNET_assert (NULL != ctx); | 664 | GNUNET_assert (NULL != ctx); |
648 | op = ctx->op; | 665 | (void) GNUNET_SCHEDULER_add_now (&teardown_dht_connection, ctx); |
649 | ctx->op = NULL; | ||
650 | GNUNET_TESTBED_operation_done (op); | ||
651 | } | 666 | } |
652 | 667 | ||
653 | 668 | ||
@@ -744,6 +759,13 @@ dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
744 | 759 | ||
745 | 760 | ||
746 | /** | 761 | /** |
762 | * Connect to DHT services of active peers | ||
763 | */ | ||
764 | static void | ||
765 | start_profiling(); | ||
766 | |||
767 | |||
768 | /** | ||
747 | * Adapter function called to destroy a connection to | 769 | * Adapter function called to destroy a connection to |
748 | * a service. | 770 | * a service. |
749 | * | 771 | * |
@@ -762,12 +784,20 @@ dht_disconnect (void *cls, void *op_result) | |||
762 | n_dht--; | 784 | n_dht--; |
763 | if (0 != n_dht) | 785 | if (0 != n_dht) |
764 | return; | 786 | return; |
765 | /* Start GETs if all PUTs have been made */ | 787 | switch (mode) |
766 | if (MODE_PUT == mode) | ||
767 | { | 788 | { |
789 | case MODE_PUT: | ||
790 | if ((n_puts_ok + n_puts_fail) != n_active) | ||
791 | return; | ||
792 | /* Start GETs if all PUTs have been made */ | ||
768 | mode = MODE_GET; | 793 | mode = MODE_GET; |
794 | //(void) GNUNET_SCHEDULER_add_now (&call_start_profiling, NULL); | ||
769 | start_profiling (); | 795 | start_profiling (); |
770 | return; | 796 | return; |
797 | case MODE_GET: | ||
798 | if ((n_gets_ok + n_gets_fail) != n_active) | ||
799 | return; | ||
800 | break; | ||
771 | } | 801 | } |
772 | GNUNET_SCHEDULER_shutdown (); | 802 | GNUNET_SCHEDULER_shutdown (); |
773 | } | 803 | } |
@@ -779,14 +809,18 @@ dht_disconnect (void *cls, void *op_result) | |||
779 | static void | 809 | static void |
780 | start_profiling() | 810 | start_profiling() |
781 | { | 811 | { |
812 | struct Context *ctx; | ||
782 | unsigned int i; | 813 | unsigned int i; |
814 | |||
783 | DEBUG("GNUNET_TESTBED_service_connect \n"); | 815 | DEBUG("GNUNET_TESTBED_service_connect \n"); |
784 | for(i = 0; i < n_active; i++) | 816 | for(i = 0; i < n_active; i++) |
785 | { | 817 | { |
786 | struct ActiveContext *ac = &a_ac[i]; | 818 | struct ActiveContext *ac = &a_ac[i]; |
787 | ac->ctx->op = | 819 | GNUNET_assert (NULL != (ctx = ac->ctx)); |
788 | GNUNET_TESTBED_service_connect (ac->ctx, | 820 | GNUNET_assert (NULL == ctx->op); |
789 | ac->ctx->peer, | 821 | ctx->op = |
822 | GNUNET_TESTBED_service_connect (ctx, | ||
823 | ctx->peer, | ||
790 | "dht", | 824 | "dht", |
791 | &dht_connected, ac, | 825 | &dht_connected, ac, |
792 | &dht_connect, | 826 | &dht_connect, |
@@ -1032,6 +1066,7 @@ service_started (void *cls, | |||
1032 | GNUNET_assert (NULL != ctx); | 1066 | GNUNET_assert (NULL != ctx); |
1033 | GNUNET_assert (NULL != ctx->op); | 1067 | GNUNET_assert (NULL != ctx->op); |
1034 | GNUNET_TESTBED_operation_done (ctx->op); | 1068 | GNUNET_TESTBED_operation_done (ctx->op); |
1069 | ctx->op = NULL; | ||
1035 | peers_started++; | 1070 | peers_started++; |
1036 | DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers); | 1071 | DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers); |
1037 | if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers) | 1072 | if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers) |