naming
[oweals/gnunet.git] / src / transport / test_transport_api_unreliability_constant.c
index f2f1038d6dd51fafd65bab2f2df376a44fb8917f..f5adeb25c6fe2b3d1a0fe890f5d3bb293c9520ac 100644 (file)
@@ -39,9 +39,9 @@
 #include "transport.h"
 #include "transport-testing.h"
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_EXTRA_LOGGING
 
-#define VERBOSE_ARM GNUNET_NO
+#define VERBOSE_ARM GNUNET_EXTRA_LOGGING
 
 #define START_ARM GNUNET_YES
 
@@ -71,6 +71,8 @@ struct PeerContext *p2;
 
 struct GNUNET_TRANSPORT_TransmitHandle *th;
 
+struct GNUNET_TRANSPORT_TESTING_handle * tth;
+
 char *cfg_file_p1;
 
 char *cfg_file_p2;
@@ -149,8 +151,10 @@ end ()
     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
   th = NULL;
 
-  GNUNET_TRANSPORT_TESTING_stop_peer (p1);
-  GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+  GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
+  GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+
+  GNUNET_TRANSPORT_TESTING_done (tth);
 
   ok = 0;
   if (test_failed == GNUNET_NO)
@@ -176,9 +180,11 @@ end_badly ()
   th = NULL;
 
   if (p1 != NULL)
-    GNUNET_TRANSPORT_TESTING_stop_peer (p1);
+    GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
   if (p2 != NULL)
-    GNUNET_TRANSPORT_TESTING_stop_peer (p2);
+    GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2);
+
+  GNUNET_TRANSPORT_TESTING_done (tth);
 
   ok = GNUNET_SYSERR;
 }
@@ -273,6 +279,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
   {
     /* because of starting with 0 */
     msg_recv++;
+    fprintf (stderr, "\n");
     end ();
   }
 }
@@ -337,6 +344,7 @@ notify_ready (void *cls, size_t size, void *buf)
   }
   else
   {
+    fprintf (stderr, "\n");
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "All messages scheduled to be sent!!\n");
     if (GNUNET_SCHEDULER_NO_TASK != die_task)
@@ -359,45 +367,19 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
                 uint32_t ats_count)
 {
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (GNUNET_TIME_UNIT_SECONDS%p)!\n",
               GNUNET_i2s (peer), cls);
 
   if (cls == p1)
   {
-    char * sec;
-    long long unsigned int l_bps;
-
-    GNUNET_asprintf(&sec, "transport-%s", test_plugin);
-    if (GNUNET_CONFIGURATION_have_value (p1->cfg, sec, "MAX_BPS"))
-    {
-      GNUNET_CONFIGURATION_get_value_number (p1->cfg, sec, "MAX_BPS",
-                                             &l_bps);
-      max_bps_p1 = l_bps;
-    }
-    else
-      max_bps_p1 = 1024 * 1024 * 1024;
-    GNUNET_free (sec);
-
+    max_bps_p1 = 1024 * 1024 * 1024;
     GNUNET_TRANSPORT_set_quota (p1->th, &p2->id,
                                 GNUNET_BANDWIDTH_value_init (max_bps_p1),
                                 GNUNET_BANDWIDTH_value_init (max_bps_p1));
   }
   else if (cls == p2)
   {
-    char * sec;
-    long long unsigned int l_bps;
-
-    GNUNET_asprintf(&sec, "transport-%s", test_plugin);
-    if (GNUNET_CONFIGURATION_have_value (p2->cfg, sec, "MAX_BPS"))
-    {
-      GNUNET_CONFIGURATION_get_value_number (p2->cfg, sec, "MAX_BPS",
-                                             &l_bps);
-      max_bps_p2 = l_bps;
-    }
-    else
-      max_bps_p2 = 1024 * 1024 * 1024;
-    GNUNET_free (sec);
-
+    max_bps_p2 = 1024 * 1024 * 1024;
     GNUNET_TRANSPORT_set_quota (p2->th, &p1->id,
                                 GNUNET_BANDWIDTH_value_init (max_bps_p2),
                                 GNUNET_BANDWIDTH_value_init (max_bps_p2));
@@ -410,6 +392,9 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n",
               GNUNET_i2s (peer), cls);
+  if (th != NULL)
+    GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
+  th = NULL;
 }
 
 static void
@@ -430,8 +415,24 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
               GNUNET_i2s (&p2->id));
   GNUNET_free (p1_c);
 
-  // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
+  GNUNET_SCHEDULER_add_now (&sendtask, NULL);
+}
+
+void start_cb (struct PeerContext * p,
+               void *cls)
+{
+  static int started;
+  started++;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n",
+       p->no,
+       GNUNET_i2s (&p->id));
+
+  if (started != 2)
+    return;
+
+  GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL);
+
 }
 
 static void
@@ -440,11 +441,15 @@ run (void *cls, char *const *args, const char *cfgfile,
 {
   die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
 
-  p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, &notify_receive,
+  p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1,
+                                            &notify_receive,
                                             &notify_connect, &notify_disconnect,
+                                            &start_cb,
                                             NULL);
-  p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, &notify_receive,
+  p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2,
+                                            &notify_receive,
                                             &notify_connect, &notify_disconnect,
+                                            &start_cb,
                                             NULL);
 
   if ((p1 == NULL) || (p2 == NULL))
@@ -455,8 +460,6 @@ run (void *cls, char *const *args, const char *cfgfile,
     die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
     return;
   }
-
-  GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
 }
 
 static int
@@ -491,6 +494,8 @@ main (int argc, char *argv[])
   int ret;
   int nat_res;
 
+  tth = GNUNET_TRANSPORT_TESTING_init ();
+
   GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
   GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
                                                  &test_plugin);