- fix coverity
[oweals/gnunet.git] / src / cadet / test_cadet.c
index d1b1b8212c503fead4fcbf46b779eb1c48e4f157..8c8d7223eddb8e305d16ff4dec57a3ee8c687194 100644 (file)
@@ -144,17 +144,17 @@ struct GNUNET_CADET_TEST_Context *test_ctx;
 /**
  * Task called to disconnect peers.
  */
-static struct GNUNET_SCHEDULER_Task * disconnect_task;
+static struct GNUNET_SCHEDULER_Task *disconnect_task;
 
 /**
  * Task To perform tests
  */
-static struct GNUNET_SCHEDULER_Task * test_task;
+static struct GNUNET_SCHEDULER_Task *test_task;
 
 /**
- * Task called to shutdown test.
+ * Task runnining #data_task().
  */
-static struct GNUNET_SCHEDULER_Task * shutdown_handle;
+static struct GNUNET_SCHEDULER_Task *data_job;
 
 /**
  * Cadet handle for the root peer
@@ -230,6 +230,7 @@ get_expected_target ()
     return peers_requested - 1;
 }
 
+
 /**
  * Show the results of the test (banwidth acheived) and log them to GAUGER
  */
@@ -255,20 +256,6 @@ show_end_data (void)
 }
 
 
-/**
- * Shut down peergroup, clean up.
- *
- * @param cls Closure (unused).
- * @param tc Task Context.
- */
-static void
-shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
-  shutdown_handle = NULL;
-}
-
-
 /**
  * Disconnect from cadet services af all peers, call shutdown.
  *
@@ -276,21 +263,15 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param tc Task Context.
  */
 static void
-disconnect_cadet_peers (void *cls,
-                        const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_cadet_peers (void *cls)
 {
   long line = (long) cls;
   unsigned int i;
 
-  if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "disconnecting cadet peers due to SHUTDOWN! called from %ld\n",
-                line);
-  else
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "disconnecting cadet service of peers, called from line %ld\n",
-                line);
   disconnect_task = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+             "disconnecting cadet service of peers, called from line %ld\n",
+             line);
   for (i = 0; i < 2; i++)
   {
     GNUNET_TESTBED_operation_done (t_op[i]);
@@ -316,15 +297,39 @@ disconnect_cadet_peers (void *cls,
     incoming_ch = NULL;
   }
   GNUNET_CADET_TEST_cleanup (test_ctx);
-  if (NULL != shutdown_handle)
+  GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Shut down peergroup, clean up.
+ *
+ * @param cls Closure (unused).
+ * @param tc Task Context.
+ */
+static void
+shutdown_task (void *cls)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
+  if (NULL != data_job)
+  {
+    GNUNET_SCHEDULER_cancel (data_job);
+    data_job = NULL;
+  }
+  if (NULL != test_task)
   {
-    GNUNET_SCHEDULER_cancel (shutdown_handle);
+    GNUNET_SCHEDULER_cancel (test_task);
+    test_task = NULL;
+  }
+  if (NULL != disconnect_task)
+  {
+    GNUNET_SCHEDULER_cancel (disconnect_task);
+    disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+                                               (void *) __LINE__);
   }
-  shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
 }
 
 
-
 /**
  * Stats callback. Finish the stats testbed operation and when all stats have
  * been iterated, shutdown the test.
@@ -345,8 +350,8 @@ stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
 
   if (NULL != disconnect_task)
     GNUNET_SCHEDULER_cancel (disconnect_task);
-  disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, cls);
-
+  disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+                                             cls);
 }
 
 
@@ -358,21 +363,28 @@ stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
  * @param subsystem name of subsystem that created the statistic
  * @param name the name of the datum
  * @param value the current value
- * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
- * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
+ * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
+ * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
  */
 static int
-stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
-                const char *subsystem, const char *name,
-                uint64_t value, int is_persistent)
+stats_iterator (void *cls,
+                const struct GNUNET_TESTBED_Peer *peer,
+                const char *subsystem,
+                const char *name,
+                uint64_t value,
+                int is_persistent)
 {
   static const char *s_sent = "# keepalives sent";
   static const char *s_recv = "# keepalives received";
   uint32_t i;
 
   i = GNUNET_TESTBED_get_index (peer);
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "STATS PEER %u - %s [%s]: %llu\n",
-              i, subsystem, name, value);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "STATS PEER %u - %s [%s]: %llu\n",
+              i,
+              subsystem,
+              name,
+              (unsigned long long) value);
   if (0 == strncmp (s_sent, name, strlen (s_sent)) && 0 == i)
     ka_sent = value;
 
@@ -387,24 +399,16 @@ stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
  * Task to gather all statistics.
  *
  * @param cls Closure (NULL).
- * @param tc Task Context.
  */
 static void
-gather_stats_and_exit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+gather_stats_and_exit (void *cls)
 {
-  disconnect_task = NULL;
   long l = (long) cls;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gathering statistics from line %d\n", l);
-
-  if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
-  {
-    disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
-                                                (void *) __LINE__);
-    return;
-  }
-
-
+  disconnect_task = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+             "gathering statistics from line %d\n",
+             (int) l);
   if (NULL != ch)
   {
     if (NULL != th)
@@ -456,21 +460,16 @@ tmt_rdy (void *cls, size_t size, void *buf);
  * Task to request a new data transmission.
  *
  * @param cls Closure (peer #).
- * @param tc Task Context.
  */
 static void
-data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+data_task (void *cls)
 {
   struct GNUNET_CADET_Channel *channel;
   static struct GNUNET_CADET_TransmitHandle **pth;
-
   long src;
 
+  data_job = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n");
-
-  if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
-    return;
-
   if (GNUNET_YES == test_backwards)
   {
     channel = incoming_ch;
@@ -499,17 +498,18 @@ data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     if (0 == i)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "  in 1 ms\n");
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
-                                    &data_task, (void *) 1L);
+      data_job = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+                                              &data_task, (void *) 1L);
     }
     else
     {
       i++;
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "in %u ms\n", i);
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
-                                        GNUNET_TIME_UNIT_MILLISECONDS,
-                                        i),
-                                    &data_task, (void *) i);
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "in %llu ms\n",
+                  (unsigned long long) i);
+      data_job = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+                                                                             i),
+                                              &data_task, (void *) i);
     }
   }
 }
@@ -544,7 +544,10 @@ tmt_rdy (void *cls, size_t size, void *buf)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "size %u, buf %p, data_sent %u, ack_received %u\n",
-                size, buf, data_sent, ack_received);
+                (unsigned int) size,
+                buf,
+                data_sent,
+                ack_received);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok %u, ok goal %u\n", ok, ok_goal);
     GNUNET_break (ok >= ok_goal - 2);
 
@@ -568,13 +571,15 @@ tmt_rdy (void *cls, size_t size, void *buf)
     else
       data_sent++;
     counter++;
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, " Sent message %d size %u\n",
-                counter, msg_size);
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                " Sent message %u size %u\n",
+                counter,
+                (unsigned int) msg_size);
     if (data_sent < TOTAL_PACKETS && SPEED == test)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Scheduling message %d\n",
                   counter + 1);
-      GNUNET_SCHEDULER_add_now (&data_task, NULL);
+      data_job = GNUNET_SCHEDULER_add_now (&data_task, NULL);
     }
   }
 
@@ -661,7 +666,7 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
     if (SPEED == test)
     {
       GNUNET_assert (peers_requested - 1 == client);
-      GNUNET_SCHEDULER_add_now (&data_task, NULL);
+      data_job = GNUNET_SCHEDULER_add_now (&data_task, NULL);
       return GNUNET_OK;
     }
   }
@@ -760,7 +765,8 @@ incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Incoming channel from %s to peer %d\n",
-              GNUNET_i2s (initiator), (long) cls);
+              GNUNET_i2s (initiator),
+              (int) (long) cls);
   ok++;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
   if ((long) cls == peers_requested - 1)
@@ -816,7 +822,8 @@ channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel,
   }
   else
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Unknown peer! %d\n", i);
+                "Unknown peer! %d\n",
+                (int) i);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
 
   if (NULL != disconnect_task)
@@ -837,21 +844,19 @@ channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel,
  * on callback function ch.
  *
  * @param cls Closure (unused).
- * @param tc Task Context.
  */
 static void
-do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_test (void *cls)
 {
   enum GNUNET_CADET_ChannelOption flags;
 
-  if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
-    return;
-
+  test_task = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "do_test\n");
 
   if (NULL != disconnect_task)
   {
     GNUNET_SCHEDULER_cancel (disconnect_task);
+    disconnect_task = NULL;
   }
 
   flags = GNUNET_CADET_OPTION_DEFAULT;
@@ -879,6 +884,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                                            &tmt_rdy, (void *) 0L);
 }
 
+
 /**
  * Callback to be called when the requested peer information is available
  *
@@ -941,8 +947,7 @@ tmain (void *cls,
   disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
                                                   &disconnect_cadet_peers,
                                                   (void *) __LINE__);
-  shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                                  &shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
   t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
                                                  GNUNET_TESTBED_PIT_IDENTITY,
                                                  &pi_cb, (void *) 0L);
@@ -1084,4 +1089,3 @@ main (int argc, char *argv[])
 }
 
 /* end of test_cadet.c */
-