gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r26505 - gnunet/src/nse


From: gnunet
Subject: [GNUnet-SVN] r26505 - gnunet/src/nse
Date: Wed, 20 Mar 2013 10:01:16 +0100

Author: harsha
Date: 2013-03-20 10:01:15 +0100 (Wed, 20 Mar 2013)
New Revision: 26505

Modified:
   gnunet/src/nse/gnunet-nse-profiler.c
Log:
- fix crashes upon shutdown

Modified: gnunet/src/nse/gnunet-nse-profiler.c
===================================================================
--- gnunet/src/nse/gnunet-nse-profiler.c        2013-03-20 08:17:38 UTC (rev 
26504)
+++ gnunet/src/nse/gnunet-nse-profiler.c        2013-03-20 09:01:15 UTC (rev 
26505)
@@ -196,6 +196,11 @@
 static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
 
 /**
+ * The shutdown task
+ */
+static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
+
+/**
  * Maximum number of connections to NSE services.
  */
 static unsigned int connection_limit;
@@ -246,7 +251,12 @@
  */
 static struct GNUNET_TESTBED_Operation *get_stats_op;
 
+/**
+ * Are we shutting down
+ */
+static int shutting_down;
 
+
 /**
  * Clean up all of the monitoring connections to NSE and
  * STATISTICS that we keep to selected peers.
@@ -282,6 +292,10 @@
 static void
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
+  if (GNUNET_YES == shutting_down)
+    return;
+  shutting_down = GNUNET_YES;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");    
   close_monitor_connections ();
   if (NULL != get_stats_op)
@@ -299,6 +313,18 @@
 
 
 /**
+ * Schedules shutdown task to be run now
+ */
+static void
+shutdown_now ()
+{
+  if (GNUNET_SCHEDULER_NO_TASK != shutdown_task_id)
+    GNUNET_SCHEDULER_cancel (shutdown_task_id);
+  shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+}
+
+
+/**
  * Callback to call when network size estimate is updated.
  *
  * @param cls closure with the 'struct NSEPeer' providing the update
@@ -594,6 +620,8 @@
   char buf[1024];
   size_t buf_len;
 
+  if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN && tc->reason))
+    return;
   LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections);
   if (NULL != data_file)
     {
@@ -683,7 +711,6 @@
     entry->op = GNUNET_TESTBED_peer_start (NULL, daemons[i], 
                                            &peer_churn_cb, entry);
   }
-
   /* stop peers if we have too many */
   for (i=num_peers_in_round[current_round];i<peers_running;i++)
   {
@@ -705,10 +732,10 @@
 next_round (void *cls, 
            const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-
+  if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN && tc->reason))
+    return;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting nse service of peers\n");
-  current_round++;
-  
+  current_round++;  
   if (current_round == num_rounds)
     {
       /* this was the last round, terminate */
@@ -770,12 +797,17 @@
              unsigned int num_peers_,
              struct GNUNET_TESTBED_Peer **peers)
 {
+  if (NULL == peers)
+  {
+    shutdown_now ();
+    return;
+  }
   daemons = peers;
   GNUNET_break (num_peers_ == num_peers);
   peers_running = num_peers;
   if (num_peers_in_round[current_round] == peers_running)
   {
-    /* no need to churn, just run next round */
+    /* no need to churn, just run the starting round */
     run_round ();
     return;
   }
@@ -861,8 +893,9 @@
                       NULL,     /* master_controller_cb cls */
                       &test_master,
                       NULL);    /* test_master cls */
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                               &shutdown_task, NULL);
+  shutdown_task_id = 
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                                    &shutdown_task, NULL);
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]