removing fprintfs -- with bad %fmt statements giving warnings
[oweals/gnunet.git] / src / transport / test_transport_api.c
index 671e28bfcdf045e9ad600325911be26e6412b444..1f9c56974984f11daa0facfae5ee61d9954001df 100644 (file)
@@ -60,7 +60,7 @@ struct PeerContext
   struct GNUNET_TRANSPORT_Handle *th;
   struct GNUNET_PeerIdentity id;
 #if START_ARM
-  pid_t arm_pid;
+  struct GNUNET_OS_Process *arm_proc;
 #endif
 };
 
@@ -68,8 +68,6 @@ static struct PeerContext p1;
 
 static struct PeerContext p2;
 
-static struct GNUNET_SCHEDULER_Handle *sched;
-
 static int ok;
 
 static int is_tcp;
@@ -84,6 +82,8 @@ static int is_http;
 
 static int is_https;
 
+static int is_multi_protocol;
+
 static  GNUNET_SCHEDULER_TaskIdentifier die_task;
 
 static char * key_file_p1;
@@ -104,7 +104,7 @@ end ()
 {
   /* do work here */
   GNUNET_assert (ok == 6);
-  GNUNET_SCHEDULER_cancel (sched, die_task);
+  GNUNET_SCHEDULER_cancel (die_task);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
   GNUNET_TRANSPORT_disconnect (p1.th);
   GNUNET_TRANSPORT_disconnect (p2.th);
@@ -118,9 +118,11 @@ static void
 stop_arm (struct PeerContext *p)
 {
 #if START_ARM
-  if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
+  if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-  GNUNET_OS_process_wait (p->arm_pid);
+  GNUNET_OS_process_wait (p->arm_proc);
+  GNUNET_OS_process_close (p->arm_proc);
+  p->arm_proc = NULL;
 #endif
   GNUNET_CONFIGURATION_destroy (p->cfg);
 }
@@ -140,8 +142,7 @@ static void
 notify_receive (void *cls,
                 const struct GNUNET_PeerIdentity *peer,
                 const struct GNUNET_MessageHeader *message,
-                struct GNUNET_TIME_Relative latency,
-               uint32_t distance)
+                const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok is (%d)!\n",
               ok);
@@ -186,14 +187,12 @@ notify_ready (void *cls, size_t size, void *buf)
 static void
 notify_connect (void *cls,
                 const struct GNUNET_PeerIdentity *peer,
-                struct GNUNET_TIME_Relative latency,
-               uint32_t distance)
+                const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count)
 {
   if (cls == &p1)
     {
-      GNUNET_SCHEDULER_cancel (sched, die_task);
-      die_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                              TIMEOUT_TRANSMIT,
+      GNUNET_SCHEDULER_cancel (die_task);
+      die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
                                               &end_badly, NULL);
 
       GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
@@ -220,7 +219,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
 {
   p->cfg = GNUNET_CONFIGURATION_create ();
 #if START_ARM
-  p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+  p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
                                         "gnunet-service-arm",
 #if VERBOSE_ARM
                                         "-L", "DEBUG",
@@ -286,7 +285,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
          }
   }
 
-  p->th = GNUNET_TRANSPORT_connect (sched, p->cfg,
+  p->th = GNUNET_TRANSPORT_connect (p->cfg,
                                     NULL, p,
                                     &notify_receive,
                                     &notify_connect, &notify_disconnect);
@@ -339,17 +338,20 @@ exchange_hello (void *cls,
 
 static void
 run (void *cls,
-     struct GNUNET_SCHEDULER_Handle *s,
      char *const *args,
      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   GNUNET_assert (ok == 1);
   OKPP;
-  sched = s;
-  die_task = GNUNET_SCHEDULER_add_delayed (sched,
-                                          TIMEOUT,
+  die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                           &end_badly, NULL);
 
+  if (is_multi_protocol)
+    {
+      setup_peer (&p1, "test_transport_api_multi_peer1.conf");
+      setup_peer (&p2, "test_transport_api_multi_peer2.conf");
+    }
+
   if (is_udp)
     {
       setup_peer (&p1, "test_transport_api_udp_peer1.conf");
@@ -470,7 +472,7 @@ get_path_from_PATH ()
   buf = GNUNET_malloc (strlen (path) + 20);
   pos = path;
 
-  while (NULL != (end = strchr (pos, ':')))
+  while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
     {
       *end = '\0';
       sprintf (buf, "%s/%s", pos, "gnunet-nat-server");
@@ -518,6 +520,15 @@ main (int argc, char *argv[])
 #ifdef MINGW
   return GNUNET_SYSERR;
 #endif
+
+  GNUNET_log_setup ("test-transport-api",
+#if VERBOSE
+                    "DEBUG",
+#else
+                    "WARNING",
+#endif
+                    NULL);
+
   if (strstr(argv[0], "tcp_nat") != NULL)
     {
       is_tcp_nat = GNUNET_YES;
@@ -556,17 +567,22 @@ main (int argc, char *argv[])
     {
       is_http = GNUNET_YES;
     }
+  else if (strstr(argv[0], "multi") != NULL)
+    {
+         is_multi_protocol = GNUNET_YES;
+    }
 
-  GNUNET_log_setup ("test-transport-api",
-#if VERBOSE
-                    "DEBUG",
-#else
-                    "WARNING",
-#endif
-                    NULL);
   ret = check ();
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
+  if (is_multi_protocol)
+  {
+         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-multi-peer-1/");
+         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-multi-peer-2/");
+  }
+  else
+  {
+         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
+         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
+  }
   return ret;
 }