-simplify logic
[oweals/gnunet.git] / src / transport / test_transport_api_reliability.c
index 07213722e73c32688e57c9b4f91d18e57f01f78e..91ef818689c7f40127a8cf16390aaac6e5137ab5 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009, 2010 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -48,7 +48,7 @@
 /**
  * Testcase timeout
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
 
 /**
  * How long until we give up on transmitting the message?
@@ -87,37 +87,37 @@ static int ok;
 /**
  * Context of peer 1
  */
-struct PeerContext *p1;
+static struct PeerContext *p1;
 
 /**
  * Configuration file of peer 1
  */
-char *cfg_file_p1;
+static char *cfg_file_p1;
 
 /**
  * Context of peer 2
  */
-struct PeerContext *p2;
+static struct PeerContext *p2;
 
 /**
  * Configuration file of peer 1
  */
-char *cfg_file_p2;
+static char *cfg_file_p2;
 
 /**
  * Timeout task
  */
-static GNUNET_SCHEDULER_TaskIdentifier die_task;
+static struct GNUNET_SCHEDULER_Task * die_task;
 
 /**
  * Transport transmit handle used
  */
-struct GNUNET_TRANSPORT_TransmitHandle *th;
+static struct GNUNET_TRANSPORT_TransmitHandle *th;
 
 /**
  * Transport testing handle
  */
-struct GNUNET_TRANSPORT_TESTING_handle *tth;
+static struct GNUNET_TRANSPORT_TESTING_handle *tth;
 
 /*
  * Total amount of bytes sent
@@ -145,7 +145,9 @@ static int msg_sent;
 static int msg_recv;
 
 static int test_connected;
+
 static int test_sending;
+
 static int test_send_timeout;
 
 
@@ -167,9 +169,11 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
 #define OKPP do { ok++; } while (0)
 #endif
 
+
 static int
 get_bit (const char *map, unsigned int bit);
 
+
 static void
 end ()
 {
@@ -190,7 +194,7 @@ end ()
           "kb/s");
   GNUNET_free (value_name);
 
-  if (die_task != GNUNET_SCHEDULER_NO_TASK)
+  if (die_task != NULL)
     GNUNET_SCHEDULER_cancel (die_task);
 
   if (th != NULL)
@@ -223,14 +227,17 @@ end ()
 static void
 end_badly ()
 {
-  int i;
-  die_task = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
+  unsigned int i;
 
+  die_task = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Fail! Stopping peers\n");
   if (test_connected == GNUNET_YES)
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got connected\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Peers got connected\n");
   else
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Peers got NOT connected\n");
 
   if (test_sending == GNUNET_NO)
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -242,7 +249,9 @@ end_badly ()
   {
     if (get_bit (bitmap, i) == 0)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i);
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Did not receive message %u\n",
+                  i);
       ok = -1;
     }
   }
@@ -347,7 +356,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Expected message %u of size %u, got %u bytes of message %u\n",
                 ntohl (hdr->num), s, ntohs (message->size), ntohl (hdr->num));
-    if (GNUNET_SCHEDULER_NO_TASK != die_task)
+    if (NULL != die_task)
       GNUNET_SCHEDULER_cancel (die_task);
     test_sending = GNUNET_YES;
     die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
@@ -360,7 +369,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Expected message %u with bits %u, but body did not match\n",
                 ntohl (hdr->num), (unsigned char) n);
-    if (GNUNET_SCHEDULER_NO_TASK != die_task)
+    if (NULL != die_task)
       GNUNET_SCHEDULER_cancel (die_task);
     test_sending = GNUNET_YES;
     die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
@@ -384,7 +393,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
   if (0 == (n % (TOTAL_MSGS / 100)))
   {
     FPRINTF (stderr, "%s",  ".");
-    if (GNUNET_SCHEDULER_NO_TASK != die_task)
+    if (NULL != die_task)
       GNUNET_SCHEDULER_cancel (die_task);
     die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
   }
@@ -412,7 +421,7 @@ notify_ready (void *cls, size_t size, void *buf)
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Timeout occurred while waiting for transmit_ready for msg %u of %u\n",
                 msg_scheduled, TOTAL_MSGS);
-    if (GNUNET_SCHEDULER_NO_TASK != die_task)
+    if (NULL != die_task)
       GNUNET_SCHEDULER_cancel (die_task);
     die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
     ok = 42;
@@ -460,7 +469,7 @@ notify_ready (void *cls, size_t size, void *buf)
   {
     FPRINTF (stderr, "%s",  "\n");
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent\n");
-    if (GNUNET_SCHEDULER_NO_TASK != die_task)
+    if (NULL != die_task)
       GNUNET_SCHEDULER_cancel (die_task);
     die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
   }
@@ -554,7 +563,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   if ((p1 == NULL) || (p2 == NULL))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
-    if (die_task != GNUNET_SCHEDULER_NO_TASK)
+    if (die_task != NULL)
       GNUNET_SCHEDULER_cancel (die_task);
     //die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
     return;