guix-env: some update.
[oweals/gnunet.git] / src / testbed / testbed_api_hosts.c
index 51bd632c741fa2af8d381e4b2c89e53813842cdd..5d2c1cc3773c3ef80daeed2bda7e049791a2c81d 100644 (file)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      (C) 2008--2013 Christian Grothoff (and other contributing authors)
+      Copyright (C) 2008--2013 GNUnet e.V.
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
       You should have received a copy of the GNU General Public License
       along with GNUnet; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
+      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+      Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -202,8 +202,7 @@ GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id)
  */
 struct GNUNET_TESTBED_Host *
 GNUNET_TESTBED_host_create_by_id_ (uint32_t id,
-                                   const struct GNUNET_CONFIGURATION_Handle
-                                   *cfg)
+                                   const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0);
 }
@@ -331,7 +330,7 @@ GNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname,
     LOG (GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id);
     return NULL;
   }
-  host = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host));
+  host = GNUNET_new (struct GNUNET_TESTBED_Host);
   host->hostname = (NULL != hostname) ? GNUNET_strdup (hostname) : NULL;
   host->username = (NULL != username) ? GNUNET_strdup (username) : NULL;
   host->id = id;
@@ -395,7 +394,6 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
                                      *cfg,
                                      struct GNUNET_TESTBED_Host ***hosts)
 {
-  //struct GNUNET_TESTBED_Host **host_array;
   struct GNUNET_TESTBED_Host *starting_host;
   char *data;
   char *buf;
@@ -500,8 +498,9 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
   if (NULL == starting_host)
     return 0;
   *hosts = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * count);
-  memcpy (*hosts, &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)],
-          sizeof (struct GNUNET_TESTBED_Host *) * count);
+  GNUNET_memcpy (*hosts,
+                 &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)],
+                 sizeof (struct GNUNET_TESTBED_Host *) * count);
   return count;
 }
 
@@ -565,7 +564,7 @@ GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
                                             GNUNET_CONFIGURATION_Handle *cfg,
                                             struct GNUNET_TESTBED_Host ***hosts)
 {
-#if !ENABLE_LL
+#if !ENABLE_SUPERMUC
   LOG (GNUNET_ERROR_TYPE_ERROR,
        _("The function %s is only available when compiled with (--with-ll)\n"),
        __func__);
@@ -649,7 +648,7 @@ GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host,
       return;
     }
   }
-  rc = GNUNET_malloc (sizeof (struct RegisteredController));
+  rc = GNUNET_new (struct RegisteredController);
   rc->controller = controller;
   GNUNET_CONTAINER_DLL_insert_tail (host->rc_head, host->rc_tail, rc);
 }
@@ -765,7 +764,7 @@ copy_argv (const char *const *argv)
   for (argp = 0; NULL != argv[argp]; argp++) ;
   argv_dup = GNUNET_malloc (sizeof (char *) * (argp + 1));
   for (argp = 0; NULL != argv[argp]; argp++)
-    argv_dup[argp] = strdup (argv[argp]);
+    argv_dup[argp] = GNUNET_strdup (argv[argp]);
   return argv_dup;
 }
 
@@ -824,7 +823,8 @@ free_argv (char **argv)
  * should not mention `-p' (port) option and destination address as these will
  * be set locally in the function from its parameteres. If the environmental
  * variable is not found then it defaults to `ssh -o BatchMode=yes -o
- * NoHostAuthenticationForLocalhost=yes'
+ * NoHostAuthenticationForLocalhost=yes -o StrictHostkeyChecking=no -o
+ * PasswordAuthentication=noc'
  *
  * @param port the destination port number
  * @param hostname the hostname of the target host
@@ -840,6 +840,10 @@ gen_rsh_args (const char *port, const char *hostname, const char *username)
     "BatchMode=yes",
     "-o",
     "NoHostAuthenticationForLocalhost=yes",
+    "-o",
+    "StrictHostKeyChecking=no",
+    "-o",
+    "PasswordAuthentication=no",
     "%h",
     NULL
   };
@@ -948,10 +952,11 @@ gen_rsh_suffix_args (const char * const *append_args)
  * @param client identification of the client
  * @param message the actual message
  *
- * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
  */
 static int
-helper_mst (void *cls, void *client, const struct GNUNET_MessageHeader *message)
+helper_mst (void *cls,
+            const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_TESTBED_ControllerProc *cp = cls;
   const struct GNUNET_TESTBED_HelperReply *msg;
@@ -1079,7 +1084,7 @@ GNUNET_TESTBED_controller_start (const char *trusted_ip,
   host->locked = GNUNET_YES;
   API_VIOLATION (GNUNET_NO == host->controller_started,
                  "Attempting to start a controller on a host which is already started a controller");
-  cp = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc));
+  cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc);
   if (0 == GNUNET_TESTBED_host_get_id_ (host))
   {
     cp->helper =
@@ -1102,7 +1107,7 @@ GNUNET_TESTBED_controller_start (const char *trusted_ip,
     GNUNET_asprintf (&port, "%u", host->port);
     LOG_DEBUG ("Starting remote connection to destination %s\n", hostname);
     if (GNUNET_OK !=
-        GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
+        GNUNET_CONFIGURATION_get_value_filename (cfg, "testbed",
                                                "HELPER_BINARY_PATH",
                                                &helper_binary_path_args[0]))
       helper_binary_path_args[0] =
@@ -1239,7 +1244,7 @@ struct GNUNET_TESTBED_HostHabitableCheckHandle
   /**
    * Task id for the habitability check task
    */
-  GNUNET_SCHEDULER_TaskIdentifier habitability_check_task;
+  struct GNUNET_SCHEDULER_Task * habitability_check_task;
 
   /**
    * How long we wait before checking the process status. Should grow
@@ -1254,10 +1259,9 @@ struct GNUNET_TESTBED_HostHabitableCheckHandle
  * Task for checking whether a host is habitable or not
  *
  * @param cls GNUNET_TESTBED_HostHabitableCheckHandle
- * @param tc the scheduler task context
  */
 static void
-habitability_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+habitability_check (void *cls)
 {
   struct GNUNET_TESTBED_HostHabitableCheckHandle *h = cls;
   void *cb_cls;
@@ -1267,7 +1271,7 @@ habitability_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   enum GNUNET_OS_ProcessStatusType type;
   int ret;
 
-  h->habitability_check_task = GNUNET_SCHEDULER_NO_TASK;
+  h->habitability_check_task = NULL;
   ret = GNUNET_OS_process_status (h->auxp, &type, &code);
   if (GNUNET_SYSERR == ret)
   {
@@ -1324,13 +1328,13 @@ GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
   const char *hostname;
   char *port;
 
-  h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostHabitableCheckHandle));
+  h = GNUNET_new (struct GNUNET_TESTBED_HostHabitableCheckHandle);
   h->cb = cb;
   h->cb_cls = cb_cls;
   h->host = host;
   hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname;
   if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_string (config, "testbed",
+      GNUNET_CONFIGURATION_get_value_filename (config, "testbed",
                                              "HELPER_BINARY_PATH",
                                              &stat_args[1]))
     stat_args[1] =
@@ -1349,7 +1353,7 @@ GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
   free_argv (rsh_args);
   h->auxp =
       GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, NULL,
-                                   NULL, h->helper_argv[0], h->helper_argv);
+                                   NULL, NULL, h->helper_argv[0], h->helper_argv);
   if (NULL == h->auxp)
   {
     GNUNET_break (0);           /* Cannot exec SSH? */
@@ -1374,7 +1378,7 @@ GNUNET_TESTBED_is_host_habitable_cancel (struct
                                          *handle)
 {
   GNUNET_SCHEDULER_cancel (handle->habitability_check_task);
-  (void) GNUNET_OS_process_kill (handle->auxp, SIGTERM);
+  (void) GNUNET_OS_process_kill (handle->auxp, GNUNET_TERM_SIG);
   (void) GNUNET_OS_process_wait (handle->auxp);
   GNUNET_OS_process_destroy (handle->auxp);
   free_argv (handle->helper_argv);
@@ -1382,33 +1386,6 @@ GNUNET_TESTBED_is_host_habitable_cancel (struct
 }
 
 
-/**
- * handle for host registration
- */
-struct GNUNET_TESTBED_HostRegistrationHandle
-{
-  /**
-   * The host being registered
-   */
-  struct GNUNET_TESTBED_Host *host;
-
-  /**
-   * The controller at which this host is being registered
-   */
-  struct GNUNET_TESTBED_Controller *c;
-
-  /**
-   * The Registartion completion callback
-   */
-  GNUNET_TESTBED_HostRegistrationCompletion cc;
-
-  /**
-   * The closure for above callback
-   */
-  void *cc_cls;
-};
-
-
 /**
  * Register a host with the controller
  *
@@ -1449,7 +1426,7 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
          (NULL == hostname) ? "localhost" : hostname);
     return NULL;
   }
-  rh = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostRegistrationHandle));
+  rh = GNUNET_new (struct GNUNET_TESTBED_HostRegistrationHandle);
   rh->host = host;
   rh->c = controller;
   GNUNET_assert (NULL != cc);
@@ -1479,14 +1456,14 @@ GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
   if (NULL != username)
   {
     msg->username_length = htons (username_length);
-    ptr = memcpy (ptr, username, username_length);
+    GNUNET_memcpy (ptr, username, username_length);
     ptr += username_length;
   }
   msg->hostname_length = htons (hostname_length);
-  ptr = memcpy (ptr, hostname, hostname_length);
+  GNUNET_memcpy (ptr, hostname, hostname_length);
   ptr += hostname_length;
   msg->config_size = htons (config_size);
-  ptr = memcpy (ptr, cconfig, cc_size);
+  GNUNET_memcpy (ptr, cconfig, cc_size);
   ptr += cc_size;
   GNUNET_assert ((ptr - (void *) msg) == msg_size);
   GNUNET_free (cconfig);
@@ -1534,63 +1511,6 @@ GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h,
 }
 
 
-/**
- * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
- * controller (testbed service)
- *
- * @param c the controller handler
- * @param msg message received
- * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
- *           not
- */
-int
-GNUNET_TESTBED_host_handle_addhostconfirm_ (struct GNUNET_TESTBED_Controller *c,
-                                            const struct
-                                            GNUNET_TESTBED_HostConfirmedMessage
-                                            *msg)
-{
-  struct GNUNET_TESTBED_HostRegistrationHandle *rh;
-  char *emsg;
-  uint16_t msg_size;
-
-  rh = c->rh;
-  if (NULL == rh)
-  {
-    return GNUNET_OK;
-  }
-  if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id))
-  {
-    LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n",
-               GNUNET_TESTBED_host_get_id_ (rh->host), ntohl (msg->host_id));
-    return GNUNET_OK;
-  }
-  c->rh = NULL;
-  msg_size = ntohs (msg->header.size);
-  if (sizeof (struct GNUNET_TESTBED_HostConfirmedMessage) == msg_size)
-  {
-    LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id));
-    GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c);
-    rh->cc (rh->cc_cls, NULL);
-    GNUNET_free (rh);
-    return GNUNET_OK;
-  }
-  /* We have an error message */
-  emsg = (char *) &msg[1];
-  if ('\0' !=
-      emsg[msg_size - sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)])
-  {
-    GNUNET_break (0);
-    GNUNET_free (rh);
-    return GNUNET_NO;
-  }
-  LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding host %u failed with error: %s\n"),
-       ntohl (msg->host_id), emsg);
-  rh->cc (rh->cc_cls, emsg);
-  GNUNET_free (rh);
-  return GNUNET_OK;
-}
-
-
 /**
  * Resolves the hostname of the host to an ip address
  *