(no commit message)
[oweals/gnunet.git] / src / transport / test_transport_api.c
index 46973e414c24ddb048e0aee7fcc7a9c44b9bc35b..e429ad7a7391ca797f2cb981197f59f4e6314b06 100644 (file)
@@ -36,7 +36,7 @@
 #include "gnunet_transport_service.h"
 #include "transport.h"
 
-#define VERBOSE GNUNET_YES
+#define VERBOSE GNUNET_NO
 
 #define VERBOSE_ARM GNUNET_NO
 
@@ -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;
@@ -104,7 +102,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 +116,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);
 }
@@ -129,6 +129,7 @@ stop_arm (struct PeerContext *p)
 static void
 end_badly ()
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
   GNUNET_break (0);
   GNUNET_TRANSPORT_disconnect (p1.th);
   GNUNET_TRANSPORT_disconnect (p2.th);
@@ -166,10 +167,11 @@ notify_ready (void *cls, size_t size, void *buf)
   struct GNUNET_MessageHeader *hdr;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Transmitting message to peer (%p) - %u!\n", cls, size);
+              "Transmitting message to peer (%p) - %u!\n", cls, sizeof (struct GNUNET_MessageHeader));
   GNUNET_assert (size >= 256);
   GNUNET_assert (ok == 4);
   OKPP;
+
   if (buf != NULL)
   {
     hdr = buf;
@@ -189,9 +191,8 @@ notify_connect (void *cls,
 {
   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,
@@ -218,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",
@@ -235,7 +236,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
                  if (GNUNET_CONFIGURATION_have_value (p->cfg,
                                                                                           "transport-https", "KEY_FILE"))
                                GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p1);
-                 else
+                 if (key_file_p1==NULL)
                          GNUNET_asprintf(&key_file_p1,"https.key");
                  if (0 == stat (key_file_p1, &sbuf ))
                  {
@@ -246,7 +247,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
                  }
                  if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
                          GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p1);
-                 else
+                 if (cert_file_p1==NULL)
                          GNUNET_asprintf(&cert_file_p1,"https.cert");
                  if (0 == stat (cert_file_p1, &sbuf ))
                  {
@@ -261,7 +262,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
                  if (GNUNET_CONFIGURATION_have_value (p->cfg,
                                                                                           "transport-https", "KEY_FILE"))
                                GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p2);
-                 else
+                 if (key_file_p2==NULL)
                          GNUNET_asprintf(&key_file_p2,"https.key");
                  if (0 == stat (key_file_p2, &sbuf ))
                  {
@@ -272,7 +273,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
                  }
                  if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
                          GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p2);
-                 else
+                 if (cert_file_p2==NULL)
                          GNUNET_asprintf(&cert_file_p2,"https.cert");
                  if (0 == stat (cert_file_p2, &sbuf ))
                  {
@@ -284,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);
@@ -337,15 +338,12 @@ 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_udp)
@@ -468,7 +466,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");
@@ -488,7 +486,7 @@ get_path_from_PATH ()
 }
 
 
-static int 
+static int
 check_gnunet_nat_server()
 {
   struct stat statbuf;
@@ -503,8 +501,8 @@ check_gnunet_nat_server()
       return GNUNET_SYSERR;
     }
   GNUNET_free (p);
-  if ( (0 != (statbuf.st_mode & S_ISUID)) && 
-       (statbuf.st_uid == 0) )    
+  if ( (0 != (statbuf.st_mode & S_ISUID)) &&
+       (statbuf.st_uid == 0) )
     return GNUNET_YES;
   return GNUNET_NO;
 }
@@ -516,6 +514,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;
@@ -549,20 +556,12 @@ main (int argc, char *argv[])
   else if (strstr(argv[0], "https") != NULL)
     {
       is_https = GNUNET_YES;
-         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTPS!!!!");
     }
   else if (strstr(argv[0], "http") != NULL)
     {
       is_http = 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");