stuff
[oweals/gnunet.git] / src / transport / test_transport_api_unreliability.c
index 0bc85b174854853410620a1b4b6401d30b48f25d..e7cb00274aa642fb1fb665b5a409e7fd95a0b010 100644 (file)
@@ -50,7 +50,7 @@
  * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
  * messages may be dropped even for a reliable transport.
  */
-#define TOTAL_MSGS (80000 * 3) /* Total messages should be divisible by 8, so we can make a nice bitmap */
+#define TOTAL_MSGS (1024 * 3) /* Total messages should be divisible by 8, so we can make a nice bitmap */
 
 /**
  * How long until we give up on transmitting the message?
@@ -257,6 +257,45 @@ stop_arm (struct PeerContext *p)
 }
 
 
+
+static void
+exchange_hello_last (void *cls,
+                     const struct GNUNET_MessageHeader *message)
+{
+  struct PeerContext *me = cls;
+
+  GNUNET_assert (message != NULL);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Exchanging HELLO of size %d with peer (%s)!\n", 
+             (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
+             GNUNET_i2s (&me->id));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
+                                      message, &me->id));
+  GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
+}
+
+
+
+static void
+exchange_hello (void *cls,
+                const struct GNUNET_MessageHeader *message)
+{
+  struct PeerContext *me = cls;
+
+  GNUNET_assert (message != NULL);
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
+                                      message, &me->id));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Exchanging HELLO of size %d from peer %s!\n", 
+             (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
+             GNUNET_i2s (&me->id));
+  GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
+}
+
+
+
 static void
 end_badly (void *cls,
            const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -264,18 +303,30 @@ end_badly (void *cls,
   if (test_failed == GNUNET_NO)
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Testcase timeout\n");
-    else
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n",
-              msg_sent,
-              msg_scheduled,
-              msg_recv,
-              msg_recv_expected);
-  if (th_p2 != NULL)
-    GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
-  th_p2 = NULL;
-
+  else
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n",
+               msg_sent,
+               msg_scheduled,
+               msg_recv,
+               msg_recv_expected);
+  
   GNUNET_break (0);
+  if (th_p2 != NULL)
+    {
+      GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
+      th_p2 = NULL;
+    }
+  if (p2_hello_canceled == GNUNET_NO)
+    {
+      GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
+      p2_hello_canceled = GNUNET_YES;
+    }
+  if (p1_hello_canceled == GNUNET_NO)
+    {
+      GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
+      p1_hello_canceled = GNUNET_YES;
+    }
   GNUNET_TRANSPORT_disconnect (p1.th);
   GNUNET_TRANSPORT_disconnect (p2.th);
   if (GNUNET_SCHEDULER_NO_TASK != tct)
@@ -300,8 +351,6 @@ get_size (unsigned int iter)
 {
   unsigned int ret;
 
-  if (iter < 60000)
-    return iter + sizeof (struct TestMessage);
   ret = (iter * iter * iter);
   return sizeof (struct TestMessage) + (ret % 60000);
 }
@@ -366,7 +415,7 @@ notify_receive (void *cls,
 #endif
   n++;
   set_bit(ntohl(hdr->num));
-  if (0 == (n % (5000)))
+  if (0 == (n % (TOTAL_MSGS / 100)))
     {
       fprintf (stderr, ".");
       if (GNUNET_SCHEDULER_NO_TASK != die_task)
@@ -466,48 +515,14 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
              GNUNET_i2s (peer), cls);
 #endif
   if (th_p2 != NULL)
-    GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2);
-}
-
-
-
-static void
-exchange_hello_last (void *cls,
-                     const struct GNUNET_MessageHeader *message)
-{
-  struct PeerContext *me = cls;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Exchanging HELLO of size %d with peer (%s)!\n", 
-             (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
-             GNUNET_i2s (&me->id));
-  GNUNET_assert (message != NULL);
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
-                                      message, &me->id));
-  GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
+    {
+      GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
+      th_p2 = NULL;
+    }
 }
 
 
 
-static void
-exchange_hello (void *cls,
-                const struct GNUNET_MessageHeader *message)
-{
-  struct PeerContext *me = cls;
-
-  GNUNET_assert (message != NULL);
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
-                                      message, &me->id));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Exchanging HELLO of size %d from peer %s!\n", 
-             (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
-             GNUNET_i2s (&me->id));
-  GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
-}
-
-
 static void
 notify_connect (void *cls,
                 const struct GNUNET_PeerIdentity *peer,
@@ -572,12 +587,18 @@ notify_connect (void *cls,
 static void
 setup_peer (struct PeerContext *p, const char *cfgname)
 {
+  memset (p, 0, sizeof (*p));
   p->cfg = GNUNET_CONFIGURATION_create ();
 
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
   if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
-      GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome);
-  GNUNET_DISK_directory_remove (p->servicehome);
+    {
+      GNUNET_assert (GNUNET_OK ==
+                    GNUNET_CONFIGURATION_get_value_string (p->cfg,
+                                                           "PATHS", "SERVICEHOME", 
+                                                           &p->servicehome));
+      GNUNET_DISK_directory_remove (p->servicehome);
+    }
 
 
 #if START_ARM
@@ -855,15 +876,16 @@ check ()
     GNUNET_free(cert_file_p2);
   }
 
-  if ((p1.servicehome != NULL) && (p2.servicehome != NULL))
-  {
-    GNUNET_DISK_directory_remove (p1.servicehome);
-    GNUNET_DISK_directory_remove (p2.servicehome);
-    GNUNET_free(p1.servicehome);
-    GNUNET_free(p2.servicehome);
-  }
-  return ok;
-
+  if (p1.servicehome != NULL) 
+    {
+      GNUNET_DISK_directory_remove (p1.servicehome);
+      GNUNET_free(p1.servicehome);
+    }
+  if (p2.servicehome != NULL)
+    {
+      GNUNET_DISK_directory_remove (p2.servicehome); 
+      GNUNET_free(p2.servicehome);
+    }
   return ok;
 }
 
@@ -872,9 +894,6 @@ int
 main (int argc, char *argv[])
 {
   int ret;
-#ifdef MINGW
-  return GNUNET_SYSERR;
-#endif
 
   test_failed = GNUNET_NO;