aboutsummaryrefslogtreecommitdiff
path: root/src/nse/gnunet-nse-profiler.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-03-20 09:01:15 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-03-20 09:01:15 +0000
commit10c3f79a9c8e9aa777329874cff6d9ef15d41751 (patch)
tree5424ba89b9ddd950796a46f20595dec4b43ec81e /src/nse/gnunet-nse-profiler.c
parent55a936b8e6ce4eaaba2fe9077e438875cab7209c (diff)
downloadgnunet-10c3f79a9c8e9aa777329874cff6d9ef15d41751.tar.gz
gnunet-10c3f79a9c8e9aa777329874cff6d9ef15d41751.zip
- fix crashes upon shutdown
Diffstat (limited to 'src/nse/gnunet-nse-profiler.c')
-rw-r--r--src/nse/gnunet-nse-profiler.c47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index 1ec720564..6f5f6f206 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -196,6 +196,11 @@ static struct GNUNET_TESTBED_Peer **daemons;
196static struct GNUNET_CONFIGURATION_Handle *testing_cfg; 196static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
197 197
198/** 198/**
199 * The shutdown task
200 */
201static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
202
203/**
199 * Maximum number of connections to NSE services. 204 * Maximum number of connections to NSE services.
200 */ 205 */
201static unsigned int connection_limit; 206static unsigned int connection_limit;
@@ -246,6 +251,11 @@ static struct OpListEntry *oplist_tail;
246 */ 251 */
247static struct GNUNET_TESTBED_Operation *get_stats_op; 252static struct GNUNET_TESTBED_Operation *get_stats_op;
248 253
254/**
255 * Are we shutting down
256 */
257static int shutting_down;
258
249 259
250/** 260/**
251 * Clean up all of the monitoring connections to NSE and 261 * Clean up all of the monitoring connections to NSE and
@@ -282,6 +292,10 @@ close_monitor_connections ()
282static void 292static void
283shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 293shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
284{ 294{
295 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
296 if (GNUNET_YES == shutting_down)
297 return;
298 shutting_down = GNUNET_YES;
285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); 299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
286 close_monitor_connections (); 300 close_monitor_connections ();
287 if (NULL != get_stats_op) 301 if (NULL != get_stats_op)
@@ -299,6 +313,18 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
299 313
300 314
301/** 315/**
316 * Schedules shutdown task to be run now
317 */
318static void
319shutdown_now ()
320{
321 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task_id)
322 GNUNET_SCHEDULER_cancel (shutdown_task_id);
323 shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
324}
325
326
327/**
302 * Callback to call when network size estimate is updated. 328 * Callback to call when network size estimate is updated.
303 * 329 *
304 * @param cls closure with the 'struct NSEPeer' providing the update 330 * @param cls closure with the 'struct NSEPeer' providing the update
@@ -594,6 +620,8 @@ finish_round (void *cls,
594 char buf[1024]; 620 char buf[1024];
595 size_t buf_len; 621 size_t buf_len;
596 622
623 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN && tc->reason))
624 return;
597 LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections); 625 LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections);
598 if (NULL != data_file) 626 if (NULL != data_file)
599 { 627 {
@@ -683,7 +711,6 @@ adjust_running_peers ()
683 entry->op = GNUNET_TESTBED_peer_start (NULL, daemons[i], 711 entry->op = GNUNET_TESTBED_peer_start (NULL, daemons[i],
684 &peer_churn_cb, entry); 712 &peer_churn_cb, entry);
685 } 713 }
686
687 /* stop peers if we have too many */ 714 /* stop peers if we have too many */
688 for (i=num_peers_in_round[current_round];i<peers_running;i++) 715 for (i=num_peers_in_round[current_round];i<peers_running;i++)
689 { 716 {
@@ -705,10 +732,10 @@ static void
705next_round (void *cls, 732next_round (void *cls,
706 const struct GNUNET_SCHEDULER_TaskContext *tc) 733 const struct GNUNET_SCHEDULER_TaskContext *tc)
707{ 734{
708 735 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN && tc->reason))
736 return;
709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting nse service of peers\n"); 737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting nse service of peers\n");
710 current_round++; 738 current_round++;
711
712 if (current_round == num_rounds) 739 if (current_round == num_rounds)
713 { 740 {
714 /* this was the last round, terminate */ 741 /* this was the last round, terminate */
@@ -770,12 +797,17 @@ test_master (void *cls,
770 unsigned int num_peers_, 797 unsigned int num_peers_,
771 struct GNUNET_TESTBED_Peer **peers) 798 struct GNUNET_TESTBED_Peer **peers)
772{ 799{
800 if (NULL == peers)
801 {
802 shutdown_now ();
803 return;
804 }
773 daemons = peers; 805 daemons = peers;
774 GNUNET_break (num_peers_ == num_peers); 806 GNUNET_break (num_peers_ == num_peers);
775 peers_running = num_peers; 807 peers_running = num_peers;
776 if (num_peers_in_round[current_round] == peers_running) 808 if (num_peers_in_round[current_round] == peers_running)
777 { 809 {
778 /* no need to churn, just run next round */ 810 /* no need to churn, just run the starting round */
779 run_round (); 811 run_round ();
780 return; 812 return;
781 } 813 }
@@ -861,8 +893,9 @@ run (void *cls, char *const *args, const char *cfgfile,
861 NULL, /* master_controller_cb cls */ 893 NULL, /* master_controller_cb cls */
862 &test_master, 894 &test_master,
863 NULL); /* test_master cls */ 895 NULL); /* test_master cls */
864 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 896 shutdown_task_id =
865 &shutdown_task, NULL); 897 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
898 &shutdown_task, NULL);
866} 899}
867 900
868 901