only get statistics once per running stats instance
[oweals/gnunet.git] / src / testing / testing.c
index 72716e9f1a5c413bc146df71b75e6283ea1fa8e8..f2150697fcb91e3a2570a2721acc369e46a1b3f1 100644 (file)
@@ -241,7 +241,7 @@ start_fsm (void *cls,
       /* fall-through */
     case SP_COPIED:
       /* Start create hostkey process */
-      d->pipe_stdout = GNUNET_DISK_pipe(GNUNET_NO);
+      d->pipe_stdout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES);
       if (d->pipe_stdout == NULL)
         {
           cb = d->cb;
@@ -283,14 +283,28 @@ start_fsm (void *cls,
                       "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", d->cfgfile,
                       "-sq");
 #endif
-          d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
-                                            "ssh",
+          if (d->ssh_port_str == NULL)
+            {
+              d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
+                                                "ssh",
 #if !DEBUG_TESTING
-                                            "-q",
+                                                "-q",
 #endif
-                                            dst,
-                                            "gnunet-peerinfo",
-                                            "-c", d->cfgfile, "-sq", NULL);
+                                                dst,
+                                                "gnunet-peerinfo",
+                                                "-c", d->cfgfile, "-sq", NULL);
+            }
+          else
+            {
+              d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh",
+                                                "ssh", "-p", d->ssh_port_str,
+#if !DEBUG_TESTING
+                                                "-q",
+#endif
+                                                dst,
+                                                "gnunet-peerinfo",
+                                                "-c", d->cfgfile, "-sq", NULL);
+            }
           GNUNET_DISK_pipe_close_end(d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
           GNUNET_free (dst);
         }
@@ -446,17 +460,35 @@ start_fsm (void *cls,
                       "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", d->cfgfile,
                       "-L", "DEBUG", "-s", "-q");
 #endif
-          d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
-                                            "ssh",
+          if (d->ssh_port_str == NULL)
+            {
+              d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
+                                                "ssh",
 #if !DEBUG_TESTING
-                                            "-q",
+                                                "-q",
 #endif
-                                            dst,
-                                            "gnunet-arm",
+                                                dst,
+                                                "gnunet-arm",
 #if DEBUG_TESTING
-                                            "-L", "DEBUG",
+                                                "-L", "DEBUG",
 #endif
-                                            "-c", d->cfgfile, "-s", "-q", NULL);
+                                                "-c", d->cfgfile, "-s", "-q", NULL);
+            }
+          else
+            {
+
+              d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh",
+                                                "ssh", "-p", d->ssh_port_str,
+#if !DEBUG_TESTING
+                                                "-q",
+#endif
+                                                dst,
+                                                "gnunet-arm",
+#if DEBUG_TESTING
+                                                "-L", "DEBUG",
+#endif
+                                                "-c", d->cfgfile, "-s", "-q", NULL);
+            }
           GNUNET_free (dst);
         }
       if (-1 == d->pid)
@@ -664,6 +696,25 @@ GNUNET_TESTING_daemon_continue_startup(struct GNUNET_TESTING_Daemon *daemon)
   daemon->phase = SP_TOPOLOGY_SETUP;
 }
 
+/**
+ * Check whether the given daemon is running.
+ *
+ * @param daemon the daemon to check
+ *
+ * @return GNUNET_YES if the daemon is up, GNUNET_NO if the
+ *         daemon is down, GNUNET_SYSERR on error.
+ */
+int
+GNUNET_TESTING_daemon_running (struct GNUNET_TESTING_Daemon *daemon)
+{
+  if (daemon == NULL)
+    return GNUNET_SYSERR;
+
+  if (daemon->running == GNUNET_YES)
+    return GNUNET_YES;
+  return GNUNET_NO;
+}
+
 
 /**
  * Start a peer that has previously been stopped using the daemon_stop
@@ -708,6 +759,8 @@ GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon,
  * @param timeout how long to wait starting up peers
  * @param hostname name of the machine where to run GNUnet
  *        (use NULL for localhost).
+ * @param ssh_username ssh username to use when connecting to hostname
+ * @param sshport port to pass to ssh process when connecting to hostname
  * @param hostkey_callback function to call once the hostkey has been
  *        generated for this peer, but it hasn't yet been started
  *        (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start)
@@ -721,6 +774,8 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
                              const struct GNUNET_CONFIGURATION_Handle *cfg,
                              struct GNUNET_TIME_Relative timeout,
                              const char *hostname,
+                             const char *ssh_username,
+                             uint16_t sshport,
                              GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
                              void *hostkey_cls,
                              GNUNET_TESTING_NotifyDaemonRunning cb,
@@ -733,6 +788,12 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
   ret = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Daemon));
   ret->sched = sched;
   ret->hostname = (hostname == NULL) ? NULL : GNUNET_strdup (hostname);
+  if (sshport != 0)
+    {
+      GNUNET_asprintf(&ret->ssh_port_str, "%d", sshport);
+    }
+  else
+    ret->ssh_port_str = NULL;
   ret->cfgfile = GNUNET_DISK_mktemp ("gnunet-testing-config");
 #if DEBUG_TESTING
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -766,10 +827,12 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
       GNUNET_free (ret);
       return NULL;
     }
-  if (GNUNET_OK !=
+  if (ssh_username != NULL)
+    username = GNUNET_strdup(ssh_username);
+  if ((ssh_username == NULL) && (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              "TESTING",
-                                             "USERNAME", &username))
+                                             "USERNAME", &username)))
     {
       if (NULL != getenv ("USER"))
         username = GNUNET_strdup (getenv ("USER"));
@@ -790,12 +853,25 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
         GNUNET_asprintf (&arg, "%s@%s:%s", username, hostname, ret->cfgfile);
       else
         GNUNET_asprintf (&arg, "%s:%s", hostname, ret->cfgfile);
-      ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
-                                          "scp",
+
+      if (ret->ssh_port_str == NULL)
+        {
+          ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
+                                              "scp",
+#if !DEBUG_TESTING
+                                              "-q",
+#endif
+                                              ret->cfgfile, arg, NULL);
+        }
+      else
+        {
+          ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp",
+                                              "scp", "-P", ret->ssh_port_str,
 #if !DEBUG_TESTING
-                                          "-q",
+                                              "-q",
 #endif
-                                          ret->cfgfile, arg, NULL);
+                                              ret->cfgfile, arg, NULL);
+        }
       GNUNET_free (arg);
       if (-1 == ret->pid)
         {
@@ -983,6 +1059,7 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
       GNUNET_free_non_null (d->username);
       if (NULL != d->dead_cb)
         d->dead_cb (d->dead_cb_cls, NULL);
+      GNUNET_free(d);
       return;
     }
 
@@ -1419,7 +1496,8 @@ send_hello(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
       ctx->connect_request_handle = GNUNET_CORE_peer_request_connect (ctx->d1->sched,
                                                                       ctx->d2->cfg,
-                                                                      GNUNET_TIME_relative_get_forever(),
+                                                                      GNUNET_TIME_relative_divide(ctx->relative_timeout,
+                                                                                                  ctx->max_connect_attempts + 1),
                                                                       &ctx->d1->id,
                                                                       &core_connect_request_cont,
                                                                       ctx);
@@ -1539,7 +1617,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
 
   ctx->timeout_task = GNUNET_SCHEDULER_add_delayed (d1->sched,
                                                     GNUNET_TIME_relative_divide(ctx->relative_timeout, 
-                                                                               max_connect_attempts), 
+                                                    ctx->max_connect_attempts),
                                                     &notify_connect_result, ctx);
 
   ctx->hello_send_task = GNUNET_SCHEDULER_add_now(ctx->d1->sched, &send_hello, ctx);