2 This file is part of GNUnet
3 (C) 2008--2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file testbed/testbed_api_hosts.c
23 * @brief API for manipulating 'hosts' controlled by the GNUnet testing service;
24 * allows parsing hosts files, starting, stopping and communicating (via
25 * SSH/stdin/stdout) with the remote (or local) processes
26 * @author Christian Grothoff
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testbed_service.h"
31 #include "gnunet_core_service.h"
32 #include "gnunet_transport_service.h"
34 #include "testbed_api.h"
35 #include "testbed_api_hosts.h"
36 #include "testbed_helper.h"
37 #include "testbed_api_operations.h"
38 #include "testbed_api_sd.h"
43 * Generic logging shorthand
45 #define LOG(kind, ...) \
46 GNUNET_log_from (kind, "testbed-api-hosts", __VA_ARGS__);
49 * Debug logging shorthand
51 #define LOG_DEBUG(...) \
52 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
55 * Prints API violation message
57 #define API_VIOLATION(cond,errstr) \
61 LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \
66 * Log an error message at log-level 'level' that indicates a failure of the
67 * command 'cmd' with the message given by gai_strerror(rc).
69 #define LOG_GAI(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gai_strerror(rc)); } while(0)
72 * Number of extra elements we create space for when we grow host list
74 #define HOST_LIST_GROW_STEP 10
78 * A list entry for registered controllers list
80 struct RegisteredController
83 * The controller at which this host is registered
85 const struct GNUNET_TESTBED_Controller *controller;
88 * The next ptr for DLL
90 struct RegisteredController *next;
93 * The prev ptr for DLL
95 struct RegisteredController *prev;
100 * A slot to record time taken by an overlay connect operation
105 * A key to identify this timeslot
112 struct GNUNET_TIME_Relative time;
115 * Number of timing values accumulated
122 * Opaque handle to a host running experiments managed by the testing framework.
123 * The master process must be able to SSH to this host without password (via
126 struct GNUNET_TESTBED_Host
130 * The next pointer for DLL
132 struct GNUNET_TESTBED_Host *next;
135 * The prev pointer for DLL
137 struct GNUNET_TESTBED_Host *prev;
140 * The hostname of the host; NULL for localhost
142 const char *hostname;
145 * The username to be used for SSH login
147 const char *username;
150 * the configuration to use as a template while starting a controller on this
151 * host. Operation queue size specific to a host are also read from this
152 * configuration handle. After starting the controller, it points to the actual
153 * configuration with which the controller is running
155 struct GNUNET_CONFIGURATION_Handle *cfg;
158 * The head for the list of controllers where this host is registered
160 struct RegisteredController *rc_head;
163 * The tail for the list of controllers where this host is registered
165 struct RegisteredController *rc_tail;
168 * Operation queue for simultaneous overlay connect operations target at this
171 struct OperationQueue *opq_parallel_overlay_connect_operations;
174 * An array of timing slots; size should be equal to the current number of parallel
177 struct TimeSlot *tslots;
180 * Handle for SD calculations amount parallel overlay connect operation finish
183 struct SDHandle *poc_sd;
186 * The number of parallel overlay connects we do currently
188 unsigned int num_parallel_connects;
191 * Counter to indicate when all the available time slots are filled
193 unsigned int tslots_filled;
196 * Is a controller started on this host? FIXME: Is this needed?
198 int controller_started;
201 * Is this host locked by GNUNET_TESTBED_controller_start()?
206 * Global ID we use to refer to a host on the network
211 * The port which is to be used for SSH
219 * Array of available hosts
221 static struct GNUNET_TESTBED_Host **host_list;
224 * The size of the available hosts list
226 static unsigned int host_list_size;
230 * Lookup a host by ID.
232 * @param id global host ID assigned to the host; 0 is
233 * reserved to always mean 'localhost'
234 * @return handle to the host, NULL if host not found
236 struct GNUNET_TESTBED_Host *
237 GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id)
239 if (host_list_size <= id)
241 return host_list[id];
246 * Create a host by ID; given this host handle, we could not
247 * run peers at the host, but we can talk about the host
250 * @param id global host ID assigned to the host; 0 is
251 * reserved to always mean 'localhost'
252 * @param cfg the configuration to use as a template while starting a controller
253 * on this host. Operation queue sizes specific to a host are also
254 * read from this configuration handle
255 * @return handle to the host, NULL on error
257 struct GNUNET_TESTBED_Host *
258 GNUNET_TESTBED_host_create_by_id_ (uint32_t id,
259 const struct GNUNET_CONFIGURATION_Handle
262 return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0);
267 * Obtain the host's unique global ID.
269 * @param host handle to the host, NULL means 'localhost'
270 * @return id global host ID assigned to the host (0 is
271 * 'localhost', but then obviously not globally unique)
274 GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host * host)
281 * Obtain the host's hostname.
283 * @param host handle to the host, NULL means 'localhost'
284 * @return hostname of the host
287 GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host)
289 return host->hostname;
294 * Obtain the host's username
296 * @param host handle to the host, NULL means 'localhost'
297 * @return username to login to the host
300 GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host)
302 return host->username;
307 * Obtain the host's ssh port
309 * @param host handle to the host, NULL means 'localhost'
310 * @return username to login to the host
313 GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host * host)
320 * Check whether a controller is already started on the given host
322 * @param host the handle to the host
323 * @return GNUNET_YES if the controller is already started; GNUNET_NO if not
326 GNUNET_TESTBED_host_controller_started (const struct GNUNET_TESTBED_Host *host)
328 return host->controller_started;
333 * Obtain the host's configuration template
335 * @param host handle to the host
336 * @return the host's configuration template
338 const struct GNUNET_CONFIGURATION_Handle *
339 GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host)
346 * Function to replace host's configuration
348 * @param host the host handle
349 * @param new_cfg the new configuration to replace the old one
352 GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host,
353 const struct GNUNET_CONFIGURATION_Handle *new_cfg)
355 GNUNET_CONFIGURATION_destroy (host->cfg);
356 host->cfg = GNUNET_CONFIGURATION_dup (new_cfg);
361 * Create a host to run peers and controllers on.
363 * @param id global host ID assigned to the host; 0 is
364 * reserved to always mean 'localhost'
365 * @param hostname name of the host, use "NULL" for localhost
366 * @param username username to use for the login; may be NULL
367 * @param cfg the configuration to use as a template while starting a controller
368 * on this host. Operation queue sizes specific to a host are also
369 * read from this configuration handle
370 * @param port port number to use for ssh; use 0 to let ssh decide
371 * @return handle to the host, NULL on error
373 struct GNUNET_TESTBED_Host *
374 GNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname,
375 const char *username,
376 const struct GNUNET_CONFIGURATION_Handle
380 struct GNUNET_TESTBED_Host *host;
381 unsigned int new_size;
383 if ((id < host_list_size) && (NULL != host_list[id]))
385 LOG (GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id);
388 host = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host));
389 host->hostname = (NULL != hostname) ? GNUNET_strdup (hostname) : NULL;
390 host->username = (NULL != username) ? GNUNET_strdup (username) : NULL;
392 host->port = (0 == port) ? 22 : port;
393 host->cfg = GNUNET_CONFIGURATION_dup (cfg);
394 host->opq_parallel_overlay_connect_operations =
395 GNUNET_TESTBED_operation_queue_create_ (0);
396 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (host, 1);
397 host->poc_sd = GNUNET_TESTBED_SD_init_ (10);
398 new_size = host_list_size;
399 while (id >= new_size)
400 new_size += HOST_LIST_GROW_STEP;
401 if (new_size != host_list_size)
402 GNUNET_array_grow (host_list, host_list_size, new_size);
403 GNUNET_assert (id < host_list_size);
404 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id);
405 host_list[id] = host;
411 * Create a host to run peers and controllers on.
413 * @param hostname name of the host, use "NULL" for localhost
414 * @param username username to use for the login; may be NULL
415 * @param cfg the configuration to use as a template while starting a controller
416 * on this host. Operation queue sizes specific to a host are also
417 * read from this configuration handle
418 * @param port port number to use for ssh; use 0 to let ssh decide
419 * @return handle to the host, NULL on error
421 struct GNUNET_TESTBED_Host *
422 GNUNET_TESTBED_host_create (const char *hostname, const char *username,
423 const struct GNUNET_CONFIGURATION_Handle *cfg,
426 static uint32_t uid_generator;
428 if (NULL == hostname)
429 return GNUNET_TESTBED_host_create_with_id (0, hostname, username,
431 return GNUNET_TESTBED_host_create_with_id (++uid_generator, hostname,
432 username, cfg, port);
437 * Load a set of hosts from a configuration file.
439 * @param filename file with the host specification
440 * @param cfg the configuration to use as a template while starting a controller
441 * on any of the loaded hosts. Operation queue sizes specific to a host
442 * are also read from this configuration handle
443 * @param hosts set to the hosts found in the file; caller must free this if
444 * number of hosts returned is greater than 0
445 * @return number of hosts returned in 'hosts', 0 on error
448 GNUNET_TESTBED_hosts_load_from_file (const char *filename,
449 const struct GNUNET_CONFIGURATION_Handle
451 struct GNUNET_TESTBED_Host ***hosts)
453 //struct GNUNET_TESTBED_Host **host_array;
454 struct GNUNET_TESTBED_Host *starting_host;
466 GNUNET_assert (NULL != filename);
467 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
469 LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s not found\n"), filename);
473 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
477 LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s has no data\n"), filename);
480 data = GNUNET_malloc (fs);
481 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
484 LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s cannot be read\n"),
490 starting_host = NULL;
492 while (offset < (fs - 1))
495 if (((data[offset] == '\n')) && (buf != &data[offset]))
499 SSCANF (buf, "%255[a-zA-Z0-9_]@%255[a-zA-Z0-9.]:%5hd", username,
503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
504 "Successfully read host %s, port %d and user %s from file\n",
505 hostname, port, username);
506 /* We store hosts in a static list; hence we only require the starting
507 * host pointer in that list to access the newly created list of hosts */
508 if (NULL == starting_host)
509 starting_host = GNUNET_TESTBED_host_create (hostname, username, cfg,
512 (void) GNUNET_TESTBED_host_create (hostname, username, cfg, port);
516 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
517 "Error reading line `%s' in hostfile\n", buf);
518 buf = &data[offset + 1];
520 else if ((data[offset] == '\n') || (data[offset] == '\0'))
521 buf = &data[offset + 1];
524 if (NULL == starting_host)
526 *hosts = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * count);
527 memcpy (*hosts, &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)],
528 sizeof (struct GNUNET_TESTBED_Host *) * count);
534 * Resolves a hostname using getaddrinfo
536 * @param host the hostname
537 * @return the string representing the IPv4 address of the given host; NULL upon error
540 simple_resolve (const char *host)
542 struct addrinfo *res;
543 const struct sockaddr_in *in_addr;
545 struct addrinfo hint;
548 hint.ai_family = AF_INET; /* IPv4 */
549 hint.ai_socktype = 0;
550 hint.ai_protocol = 0;
553 hint.ai_canonname = NULL;
555 hint.ai_flags = AI_NUMERICSERV;
557 LOG_DEBUG ("Resolving [%s]\n", host);
558 if (0 != (rc = getaddrinfo (host, "22", &hint, &res)))
560 LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc);
563 GNUNET_assert (NULL != res);
564 GNUNET_assert (NULL != res->ai_addr);
565 GNUNET_assert (sizeof (struct sockaddr_in) == res->ai_addrlen);
566 in_addr = (const struct sockaddr_in *) res->ai_addr;
567 hostip = inet_ntoa (in_addr->sin_addr);
568 GNUNET_assert (NULL != hostip);
569 LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip);
575 * Loads the set of host allocated by the LoadLeveler Job Scheduler. This
576 * function is only available when compiled with support for LoadLeveler and is
577 * used for running on the SuperMUC
579 * @param cfg the configuration to use as a template while starting a controller
580 * on any of the loaded hosts. Operation queue sizes specific to a host
581 * are also read from this configuration handle
582 * @param hosts set to the hosts found in the file; caller must free this if
583 * number of hosts returned is greater than 0
584 * @return number of hosts returned in 'hosts', 0 on error
587 GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
588 GNUNET_CONFIGURATION_Handle *cfg,
589 struct GNUNET_TESTBED_Host ***hosts)
591 const char *hostfile;
597 struct GNUNET_TESTBED_Host **host_list;
609 unsigned int nhostaddrs;
611 if (NULL == (hostfile = getenv ("MP_SAVEHOSTFILE")))
616 if (GNUNET_SYSERR == GNUNET_DISK_file_size (hostfile, &size, GNUNET_YES,
627 buf = GNUNET_malloc (size + 1);
628 rsize = GNUNET_DISK_fn_read (hostfile, buf, (size_t) size);
629 if ( (GNUNET_SYSERR == rsize) || ((ssize_t) size != rsize) )
643 while (offset < size)
648 if ('!' == buf[offset])
654 if ('\n' == buf[offset])
658 if ('!' == buf[offset])
663 if ( (' ' == buf[offset])
664 || ('\t' == buf[offset])
665 || ('\r' == buf[offset]) )
670 hostname = &buf[offset];
674 if (isspace (buf[offset]))
677 for (host = 0; host < nhosts; host++)
678 if (0 == strcmp (hostnames[host], hostname))
682 LOG_DEBUG ("Adding host [%s]\n", hostname);
683 hostname = GNUNET_strdup (hostname);
684 GNUNET_array_append (hostnames, nhosts, hostname);
687 LOG_DEBUG ("Not adding host [%s] as it is already included\n", hostname);
695 GNUNET_free_non_null (buf);
696 if (NULL == hostnames)
698 for (host = 0; host < nhosts; host++)
700 hostip = simple_resolve (hostnames[host]);
706 GNUNET_array_append (hostaddrs, nhostaddrs, GNUNET_strdup (hostip));
708 GNUNET_assert (nhostaddrs == nhosts);
711 host_list = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * nhostaddrs);
712 for (host = 0; host < nhosts; host++)
713 host_list[host] = GNUNET_TESTBED_host_create (hostaddrs[host], NULL, cfg, 0);
717 for (host = 0; host < nhosts; host++)
718 GNUNET_free (hostnames[host]);
719 GNUNET_free(hostnames);
720 for (host = 0; (NULL != hostaddrs) && (host < nhostaddrs); host++)
721 GNUNET_free (hostaddrs[host]);
722 GNUNET_free (hostaddrs);
728 * Destroy a host handle. Must only be called once everything
729 * running on that host has been stopped.
731 * @param host handle to destroy
734 GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
736 struct RegisteredController *rc;
739 GNUNET_assert (host->id < host_list_size);
740 GNUNET_assert (host_list[host->id] == host);
741 host_list[host->id] = NULL;
742 /* clear registered controllers list */
743 for (rc = host->rc_head; NULL != rc; rc = host->rc_head)
745 GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc);
748 GNUNET_free_non_null ((char *) host->username);
749 GNUNET_free_non_null ((char *) host->hostname);
750 GNUNET_TESTBED_operation_queue_destroy_
751 (host->opq_parallel_overlay_connect_operations);
752 GNUNET_TESTBED_SD_destroy_ (host->poc_sd);
753 GNUNET_free_non_null (host->tslots);
754 GNUNET_CONFIGURATION_destroy (host->cfg);
756 while (host_list_size >= HOST_LIST_GROW_STEP)
758 for (id = host_list_size - 1; id > host_list_size - HOST_LIST_GROW_STEP;
760 if (NULL != host_list[id])
762 if (id != host_list_size - HOST_LIST_GROW_STEP)
764 if (NULL != host_list[id])
766 host_list_size -= HOST_LIST_GROW_STEP;
769 GNUNET_realloc (host_list,
770 sizeof (struct GNUNET_TESTBED_Host *) * host_list_size);
775 * Marks a host as registered with a controller
777 * @param host the host to mark
778 * @param controller the controller at which this host is registered
781 GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host,
782 const struct GNUNET_TESTBED_Controller
785 struct RegisteredController *rc;
787 for (rc = host->rc_head; NULL != rc; rc = rc->next)
789 if (controller == rc->controller) /* already registered at controller */
795 rc = GNUNET_malloc (sizeof (struct RegisteredController));
796 rc->controller = controller;
797 GNUNET_CONTAINER_DLL_insert_tail (host->rc_head, host->rc_tail, rc);
802 * Checks whether a host has been registered
804 * @param host the host to check
805 * @param controller the controller at which host's registration is checked
806 * @return GNUNET_YES if registered; GNUNET_NO if not
809 GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host,
810 const struct GNUNET_TESTBED_Controller
813 struct RegisteredController *rc;
815 for (rc = host->rc_head; NULL != rc; rc = rc->next)
817 if (controller == rc->controller) /* already registered at controller */
827 * Handle for controller process
829 struct GNUNET_TESTBED_ControllerProc
834 struct GNUNET_HELPER_Handle *helper;
837 * The arguments used to start the helper
842 * The host where the helper is run
844 struct GNUNET_TESTBED_Host *host;
847 * The controller error callback
849 GNUNET_TESTBED_ControllerStatusCallback cb;
852 * The closure for the above callback
857 * The send handle for the helper
859 struct GNUNET_HELPER_SendHandle *shandle;
862 * The message corresponding to send handle
864 struct GNUNET_MessageHeader *msg;
870 * Function to copy NULL terminated list of arguments
872 * @param argv the NULL terminated list of arguments. Cannot be NULL.
873 * @return the copied NULL terminated arguments
876 copy_argv (const char *const *argv)
881 GNUNET_assert (NULL != argv);
882 for (argp = 0; NULL != argv[argp]; argp++) ;
883 argv_dup = GNUNET_malloc (sizeof (char *) * (argp + 1));
884 for (argp = 0; NULL != argv[argp]; argp++)
885 argv_dup[argp] = strdup (argv[argp]);
891 * Function to join NULL terminated list of arguments
893 * @param argv1 the NULL terminated list of arguments. Cannot be NULL.
894 * @param argv2 the NULL terminated list of arguments. Cannot be NULL.
895 * @return the joined NULL terminated arguments
898 join_argv (const char *const *argv1, const char *const *argv2)
907 for (cnt = 0; NULL != argv1[cnt]; cnt++)
909 argv = GNUNET_strdup (argv1[cnt]);
910 GNUNET_array_append (argvj, carg, argv);
912 for (cnt = 0; NULL != argv2[cnt]; cnt++)
914 argv = GNUNET_strdup (argv2[cnt]);
915 GNUNET_array_append (argvj, carg, argv);
917 GNUNET_array_append (argvj, carg, NULL);
923 * Frees the given NULL terminated arguments
925 * @param argv the NULL terminated list of arguments
928 free_argv (char **argv)
932 for (argp = 0; NULL != argv[argp]; argp++)
933 GNUNET_free (argv[argp]);
939 * Generates arguments for opening a remote shell. Builds up the arguments
940 * from the environment variable GNUNET_TESTBED_RSH_CMD. The variable
941 * should not mention `-p' (port) option and destination address as these will
942 * be set locally in the function from its parameteres. If the environmental
943 * variable is not found then it defaults to `ssh -o BatchMode=yes -o
944 * NoHostAuthenticationForLocalhost=yes'
946 * @param port the destination port number
947 * @param dst the destination address
948 * @return NULL terminated list of arguments
951 gen_rsh_args (const char *port, const char *dst)
953 static const char *default_ssh_args[] = {
958 "NoHostAuthenticationForLocalhost=yes",
968 if (NULL != (ssh_cmd = getenv ("GNUNET_TESTBED_RSH_CMD")))
970 ssh_cmd = GNUNET_strdup (ssh_cmd);
971 ssh_cmd_cp = ssh_cmd;
972 for (cnt = 0; NULL != (arg = strtok (ssh_cmd, " ")); ssh_cmd = NULL)
973 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (arg));
974 GNUNET_free (ssh_cmd_cp);
978 ssh_args = copy_argv (default_ssh_args);
979 cnt = (sizeof (default_ssh_args)) / (sizeof (const char *));
980 GNUNET_array_grow (ssh_args, cnt, cnt - 1);
982 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup ("-p"));
983 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (port));
984 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (dst));
985 GNUNET_array_append (ssh_args, cnt, NULL);
991 * Generates the arguments needed for executing the given binary in a remote
992 * shell. Builds the arguments from the environmental variable
993 * GNUNET_TETSBED_RSH_CMD_SUFFIX. If the environmental variable is not found,
994 * only the given binary name will be present in the returned arguments
996 * @param append_args the arguments to append after generating the suffix
997 * arguments. Can be NULL; if not must be NULL terminated 'char *' array
998 * @return NULL-terminated args
1001 gen_rsh_suffix_args (const char * const *append_args)
1005 char *rshell_cmd_cp;
1008 unsigned int append_cnt;
1012 if (NULL != (rshell_cmd = getenv ("GNUNET_TESTBED_RSH_CMD_SUFFIX")))
1014 rshell_cmd = GNUNET_strdup (rshell_cmd);
1015 rshell_cmd_cp = rshell_cmd;
1016 for (; NULL != (arg = strtok (rshell_cmd, " ")); rshell_cmd = NULL)
1017 GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (arg));
1018 GNUNET_free (rshell_cmd_cp);
1020 if (NULL != append_args)
1022 for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++)
1023 GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (append_args[append_cnt]));
1025 GNUNET_array_append (rshell_args, cnt, NULL);
1031 * Functions with this signature are called whenever a
1032 * complete message is received by the tokenizer.
1034 * Do not call GNUNET_SERVER_mst_destroy in callback
1036 * @param cls closure
1037 * @param client identification of the client
1038 * @param message the actual message
1040 * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing
1043 helper_mst (void *cls, void *client, const struct GNUNET_MessageHeader *message)
1045 struct GNUNET_TESTBED_ControllerProc *cp = cls;
1046 const struct GNUNET_TESTBED_HelperReply *msg;
1047 const char *hostname;
1050 uLongf xconfig_size;
1052 msg = (const struct GNUNET_TESTBED_HelperReply *) message;
1053 GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) <
1054 ntohs (msg->header.size));
1055 GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY ==
1056 ntohs (msg->header.type));
1057 config_size = (uLongf) ntohs (msg->config_size);
1059 (uLongf) (ntohs (msg->header.size) -
1060 sizeof (struct GNUNET_TESTBED_HelperReply));
1061 config = GNUNET_malloc (config_size);
1062 GNUNET_assert (Z_OK ==
1063 uncompress ((Bytef *) config, &config_size,
1064 (const Bytef *) &msg[1], xconfig_size));
1065 /* Replace the configuration template present in the host with the
1066 controller's running configuration */
1067 GNUNET_CONFIGURATION_destroy (cp->host->cfg);
1068 cp->host->cfg = GNUNET_CONFIGURATION_create ();
1069 GNUNET_assert (GNUNET_CONFIGURATION_deserialize
1070 (cp->host->cfg, config, config_size, GNUNET_NO));
1071 GNUNET_free (config);
1072 if ((NULL == cp->host) ||
1073 (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))))
1074 hostname = "localhost";
1075 /* Change the hostname so that we can connect to it */
1076 GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, "testbed", "hostname",
1078 cp->host->locked = GNUNET_NO;
1079 cp->host->controller_started = GNUNET_YES;
1080 cp->cb (cp->cls, cp->host->cfg, GNUNET_OK);
1086 * Continuation function from GNUNET_HELPER_send()
1088 * @param cls closure
1089 * @param result GNUNET_OK on success,
1090 * GNUNET_NO if helper process died
1091 * GNUNET_SYSERR during GNUNET_HELPER_stop
1094 clear_msg (void *cls, int result)
1096 struct GNUNET_TESTBED_ControllerProc *cp = cls;
1098 GNUNET_assert (NULL != cp->shandle);
1100 GNUNET_free (cp->msg);
1105 * Callback that will be called when the helper process dies. This is not called
1106 * when the helper process is stoped using GNUNET_HELPER_stop()
1108 * @param cls the closure from GNUNET_HELPER_start()
1111 helper_exp_cb (void *cls)
1113 struct GNUNET_TESTBED_ControllerProc *cp = cls;
1114 GNUNET_TESTBED_ControllerStatusCallback cb;
1120 GNUNET_TESTBED_controller_stop (cp);
1122 cb (cb_cls, NULL, GNUNET_SYSERR);
1127 * Starts a controller process at the given host
1129 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
1130 * HOST(all connections form this ip are permitted by the testbed) when
1131 * starting testbed controller at host. This can either be a single ip
1132 * address or a network address in CIDR notation.
1133 * @param host the host where the controller has to be started; NULL for
1135 * @param cfg template configuration to use for the remote controller; the
1136 * remote controller will be started with a slightly modified
1137 * configuration (port numbers, unix domain sockets and service home
1138 * values are changed as per TESTING library on the remote host)
1139 * @param cb function called when the controller is successfully started or
1140 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
1141 * called if cb is called with GNUNET_SYSERR as status. Will never be
1142 * called in the same task as 'GNUNET_TESTBED_controller_start'
1143 * (synchronous errors will be signalled by returning NULL). This
1144 * parameter cannot be NULL.
1145 * @param cls closure for above callbacks
1146 * @return the controller process handle, NULL on errors
1148 struct GNUNET_TESTBED_ControllerProc *
1149 GNUNET_TESTBED_controller_start (const char *trusted_ip,
1150 struct GNUNET_TESTBED_Host *host,
1151 const struct GNUNET_CONFIGURATION_Handle *cfg,
1152 GNUNET_TESTBED_ControllerStatusCallback cb,
1155 struct GNUNET_TESTBED_ControllerProc *cp;
1156 struct GNUNET_TESTBED_HelperInit *msg;
1157 const char *hostname;
1159 static char *const binary_argv[] = {
1160 HELPER_TESTBED_BINARY, NULL
1164 API_VIOLATION (GNUNET_NO == host->locked,
1165 "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()");
1166 host->locked = GNUNET_YES;
1167 API_VIOLATION (GNUNET_NO == host->controller_started,
1168 "Attempting to start a controller on a host which is already started a controller");
1169 cp = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc));
1170 if ((NULL == host) || (0 == GNUNET_TESTBED_host_get_id_ (host)))
1173 GNUNET_HELPER_start (GNUNET_YES, HELPER_TESTBED_BINARY, binary_argv,
1174 &helper_mst, &helper_exp_cb, cp);
1178 char *helper_binary_path_args[2];
1180 char **rsh_suffix_args;
1181 const char *username;
1185 username = GNUNET_TESTBED_host_get_username_ (host);
1186 hostname = GNUNET_TESTBED_host_get_hostname (host);
1187 GNUNET_asprintf (&port, "%u", GNUNET_TESTBED_host_get_ssh_port_ (host));
1188 if (NULL == username)
1189 GNUNET_asprintf (&dst, "%s", hostname);
1191 GNUNET_asprintf (&dst, "%s@%s", username, hostname);
1192 LOG_DEBUG ("Starting SSH to destination %s\n", dst);
1195 GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
1196 "HELPER_BINARY_PATH",
1197 &helper_binary_path_args[0]))
1198 helper_binary_path_args[0] =
1199 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
1200 helper_binary_path_args[1] = NULL;
1201 rsh_args = gen_rsh_args (port, dst);
1202 rsh_suffix_args = gen_rsh_suffix_args ((const char **) helper_binary_path_args);
1204 join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
1205 free_argv (rsh_args);
1206 free_argv (rsh_suffix_args);
1210 GNUNET_HELPER_start (GNUNET_NO, cp->helper_argv[0], cp->helper_argv, &helper_mst,
1211 &helper_exp_cb, cp);
1212 GNUNET_free (helper_binary_path_args[0]);
1214 if (NULL == cp->helper)
1216 if (NULL != cp->helper_argv)
1217 free_argv (cp->helper_argv);
1224 msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg);
1225 cp->msg = &msg->header;
1227 GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp);
1228 if (NULL == cp->shandle)
1231 GNUNET_TESTBED_controller_stop (cp);
1239 * Stop the controller process (also will terminate all peers and controllers
1240 * dependent on this controller). This function blocks until the testbed has
1241 * been fully terminated (!). The controller status cb from
1242 * GNUNET_TESTBED_controller_start() will not be called.
1244 * @param cproc the controller process handle
1247 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc)
1249 if (NULL != cproc->shandle)
1250 GNUNET_HELPER_send_cancel (cproc->shandle);
1251 if (NULL != cproc->helper)
1252 GNUNET_HELPER_soft_stop (cproc->helper);
1253 if (NULL != cproc->helper_argv)
1254 free_argv (cproc->helper_argv);
1255 cproc->host->controller_started = GNUNET_NO;
1256 cproc->host->locked = GNUNET_NO;
1257 GNUNET_free (cproc);
1262 * The handle for whether a host is habitable or not
1264 struct GNUNET_TESTBED_HostHabitableCheckHandle
1269 const struct GNUNET_TESTBED_Host *host;
1272 * The callback to call once we have the status
1274 GNUNET_TESTBED_HostHabitableCallback cb;
1277 * The callback closure
1282 * The process handle for the SSH process
1284 struct GNUNET_OS_Process *auxp;
1287 * The arguments used to start the helper
1292 * Task id for the habitability check task
1294 GNUNET_SCHEDULER_TaskIdentifier habitability_check_task;
1297 * How long we wait before checking the process status. Should grow
1300 struct GNUNET_TIME_Relative wait_time;
1306 * Task for checking whether a host is habitable or not
1308 * @param cls GNUNET_TESTBED_HostHabitableCheckHandle
1309 * @param tc the scheduler task context
1312 habitability_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1314 struct GNUNET_TESTBED_HostHabitableCheckHandle *h = cls;
1316 GNUNET_TESTBED_HostHabitableCallback cb;
1317 const struct GNUNET_TESTBED_Host *host;
1319 enum GNUNET_OS_ProcessStatusType type;
1322 h->habitability_check_task = GNUNET_SCHEDULER_NO_TASK;
1323 ret = GNUNET_OS_process_status (h->auxp, &type, &code);
1324 if (GNUNET_SYSERR == ret)
1330 if (GNUNET_NO == ret)
1332 h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
1333 h->habitability_check_task =
1334 GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
1337 GNUNET_OS_process_destroy (h->auxp);
1339 ret = (0 != code) ? GNUNET_NO : GNUNET_YES;
1342 if (NULL != h->auxp)
1343 GNUNET_OS_process_destroy (h->auxp);
1349 cb (cb_cls, host, ret);
1354 * Checks whether a host can be used to start testbed service
1356 * @param host the host to check
1357 * @param config the configuration handle to lookup the path of the testbed
1359 * @param cb the callback to call to inform about habitability of the given host
1360 * @param cb_cls the closure for the callback
1361 * @return NULL upon any error or a handle which can be passed to
1362 * GNUNET_TESTBED_is_host_habitable_cancel()
1364 struct GNUNET_TESTBED_HostHabitableCheckHandle *
1365 GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
1366 const struct GNUNET_CONFIGURATION_Handle
1368 GNUNET_TESTBED_HostHabitableCallback cb,
1371 struct GNUNET_TESTBED_HostHabitableCheckHandle *h;
1373 char **rsh_suffix_args;
1375 const char *hostname;
1379 h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostHabitableCheckHandle));
1383 hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname;
1384 if (NULL == host->username)
1385 dst = GNUNET_strdup (hostname);
1387 GNUNET_asprintf (&dst, "%s@%s", host->username, hostname);
1389 GNUNET_CONFIGURATION_get_value_string (config, "testbed",
1390 "HELPER_BINARY_PATH",
1393 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
1394 GNUNET_asprintf (&port, "%u", host->port);
1395 rsh_args = gen_rsh_args (port, dst);
1400 stat_args[0] = "stat";
1401 stat_args[2] = NULL;
1402 rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args);
1403 h->helper_argv = join_argv ((const char **) rsh_args,
1404 (const char **) rsh_suffix_args);
1405 GNUNET_free (rsh_suffix_args);
1406 GNUNET_free (rsh_args);
1408 GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, NULL,
1409 NULL, h->helper_argv[0], h->helper_argv);
1410 if (NULL == h->auxp)
1412 GNUNET_break (0); /* Cannot exec SSH? */
1416 h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
1417 h->habitability_check_task =
1418 GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
1424 * Function to cancel a request started using GNUNET_TESTBED_is_host_habitable()
1426 * @param handle the habitability check handle
1429 GNUNET_TESTBED_is_host_habitable_cancel (struct
1430 GNUNET_TESTBED_HostHabitableCheckHandle
1433 GNUNET_SCHEDULER_cancel (handle->habitability_check_task);
1434 (void) GNUNET_OS_process_kill (handle->auxp, SIGTERM);
1435 (void) GNUNET_OS_process_wait (handle->auxp);
1436 GNUNET_OS_process_destroy (handle->auxp);
1437 free_argv (handle->helper_argv);
1438 GNUNET_free (handle);
1443 * handle for host registration
1445 struct GNUNET_TESTBED_HostRegistrationHandle
1448 * The host being registered
1450 struct GNUNET_TESTBED_Host *host;
1453 * The controller at which this host is being registered
1455 struct GNUNET_TESTBED_Controller *c;
1458 * The Registartion completion callback
1460 GNUNET_TESTBED_HostRegistrationCompletion cc;
1463 * The closure for above callback
1470 * Register a host with the controller
1472 * @param controller the controller handle
1473 * @param host the host to register
1474 * @param cc the completion callback to call to inform the status of
1475 * registration. After calling this callback the registration handle
1476 * will be invalid. Cannot be NULL.
1477 * @param cc_cls the closure for the cc
1478 * @return handle to the host registration which can be used to cancel the
1481 struct GNUNET_TESTBED_HostRegistrationHandle *
1482 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
1483 struct GNUNET_TESTBED_Host *host,
1484 GNUNET_TESTBED_HostRegistrationCompletion cc,
1487 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
1488 struct GNUNET_TESTBED_AddHostMessage *msg;
1489 const char *username;
1490 const char *hostname;
1497 uint16_t username_length;
1498 uint16_t hostname_length;
1500 if (NULL != controller->rh)
1502 hostname = GNUNET_TESTBED_host_get_hostname (host);
1503 if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller))
1505 LOG (GNUNET_ERROR_TYPE_WARNING, "Host hostname: %s already registered\n",
1506 (NULL == hostname) ? "localhost" : hostname);
1509 rh = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostRegistrationHandle));
1512 GNUNET_assert (NULL != cc);
1514 rh->cc_cls = cc_cls;
1515 controller->rh = rh;
1516 username = GNUNET_TESTBED_host_get_username_ (host);
1517 username_length = 0;
1518 if (NULL != username)
1519 username_length = strlen (username);
1520 GNUNET_assert (NULL != hostname); /* Hostname must be present */
1521 hostname_length = strlen (hostname);
1522 GNUNET_assert (NULL != host->cfg);
1523 config = GNUNET_CONFIGURATION_serialize (host->cfg, &config_size);
1524 cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig);
1525 GNUNET_free (config);
1526 msg_size = (sizeof (struct GNUNET_TESTBED_AddHostMessage));
1527 msg_size += username_length;
1528 msg_size += hostname_length;
1529 msg_size += cc_size;
1530 msg = GNUNET_malloc (msg_size);
1531 msg->header.size = htons (msg_size);
1532 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST);
1533 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
1534 msg->ssh_port = htons (GNUNET_TESTBED_host_get_ssh_port_ (host));
1536 if (NULL != username)
1538 msg->username_length = htons (username_length);
1539 ptr = memcpy (ptr, username, username_length);
1540 ptr += username_length;
1542 msg->hostname_length = htons (hostname_length);
1543 ptr = memcpy (ptr, hostname, hostname_length);
1544 ptr += hostname_length;
1545 msg->config_size = htons (config_size);
1546 ptr = memcpy (ptr, cconfig, cc_size);
1548 GNUNET_assert ((ptr - (void *) msg) == msg_size);
1549 GNUNET_free (cconfig);
1550 GNUNET_TESTBED_queue_message_ (controller,
1551 (struct GNUNET_MessageHeader *) msg);
1557 * Cancel the pending registration. Note that if the registration message is
1558 * already sent to the service the cancellation has only the effect that the
1559 * registration completion callback for the registration is never called.
1561 * @param handle the registration handle to cancel
1564 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
1567 if (handle != handle->c->rh)
1572 handle->c->rh = NULL;
1573 GNUNET_free (handle);
1578 * Initializes the operation queue for parallel overlay connects
1580 * @param h the host handle
1581 * @param npoc the number of parallel overlay connects - the queue size
1584 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (struct
1585 GNUNET_TESTBED_Host *h,
1588 //fprintf (stderr, "%d", npoc);
1589 GNUNET_free_non_null (h->tslots);
1590 h->tslots_filled = 0;
1591 h->num_parallel_connects = npoc;
1592 h->tslots = GNUNET_malloc (npoc * sizeof (struct TimeSlot));
1593 GNUNET_TESTBED_operation_queue_reset_max_active_
1594 (h->opq_parallel_overlay_connect_operations, npoc);
1599 * Returns a timing slot which will be exclusively locked
1601 * @param h the host handle
1602 * @param key a pointer which is associated to the returned slot; should not be
1603 * NULL. It serves as a key to determine the correct owner of the slot
1604 * @return the time slot index in the array of time slots in the controller
1608 GNUNET_TESTBED_get_tslot_ (struct GNUNET_TESTBED_Host *h, void *key)
1612 GNUNET_assert (NULL != h->tslots);
1613 GNUNET_assert (NULL != key);
1614 for (slot = 0; slot < h->num_parallel_connects; slot++)
1615 if (NULL == h->tslots[slot].key)
1617 h->tslots[slot].key = key;
1620 GNUNET_assert (0); /* We should always find a free tslot */
1625 * Decides whether any change in the number of parallel overlay connects is
1626 * necessary to adapt to the load on the system
1628 * @param h the host handle
1631 decide_npoc (struct GNUNET_TESTBED_Host *h)
1633 struct GNUNET_TIME_Relative avg;
1638 if (h->tslots_filled != h->num_parallel_connects)
1640 avg = GNUNET_TIME_UNIT_ZERO;
1642 for (slot = 0; slot < h->num_parallel_connects; slot++)
1644 avg = GNUNET_TIME_relative_add (avg, h->tslots[slot].time);
1645 nvals += h->tslots[slot].nvals;
1647 GNUNET_assert (nvals >= h->num_parallel_connects);
1648 avg = GNUNET_TIME_relative_divide (avg, nvals);
1649 GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value != avg.rel_value);
1650 sd = GNUNET_TESTBED_SD_deviation_factor_ (h->poc_sd, (unsigned int) avg.rel_value);
1652 (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1653 h->num_parallel_connects)) )
1654 GNUNET_TESTBED_SD_add_data_ (h->poc_sd, (unsigned int) avg.rel_value);
1655 if (GNUNET_SYSERR == sd)
1657 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1658 h->num_parallel_connects);
1661 GNUNET_assert (0 <= sd);
1664 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1665 h->num_parallel_connects
1671 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1672 h->num_parallel_connects
1676 if (1 == h->num_parallel_connects)
1678 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, 1);
1683 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1684 h->num_parallel_connects
1688 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1689 h->num_parallel_connects /
1695 * Releases a time slot thus making it available for be used again
1697 * @param h the host handle
1698 * @param index the index of the the time slot
1699 * @param key the key to prove ownership of the timeslot
1700 * @return GNUNET_YES if the time slot is successfully removed; GNUNET_NO if the
1701 * time slot cannot be removed - this could be because of the index
1702 * greater than existing number of time slots or `key' being different
1705 GNUNET_TESTBED_release_time_slot_ (struct GNUNET_TESTBED_Host *h,
1706 unsigned int index, void *key)
1708 struct TimeSlot *slot;
1710 GNUNET_assert (NULL != key);
1711 if (index >= h->num_parallel_connects)
1713 slot = &h->tslots[index];
1714 if (key != slot->key)
1722 * Function to update a time slot
1724 * @param h the host handle
1725 * @param index the index of the time slot to update
1726 * @param key the key to identify ownership of the slot
1727 * @param time the new time
1728 * @param failed should this reading be treated as coming from a fail event
1731 GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Host *h,
1732 unsigned int index, void *key,
1733 struct GNUNET_TIME_Relative time, int failed)
1735 struct TimeSlot *slot;
1737 if (GNUNET_YES == failed)
1739 if (1 == h->num_parallel_connects)
1741 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, 1);
1744 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1745 h->num_parallel_connects
1748 if (GNUNET_NO == GNUNET_TESTBED_release_time_slot_ (h, index, key))
1750 slot = &h->tslots[index];
1752 if (GNUNET_TIME_UNIT_ZERO.rel_value == slot->time.rel_value)
1759 slot->time = GNUNET_TIME_relative_add (slot->time, time);
1764 * Queues the given operation in the queue for parallel overlay connects of the
1767 * @param h the host handle
1768 * @param op the operation to queue in the given host's parally overlay connect
1772 GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h,
1773 struct GNUNET_TESTBED_Operation *op)
1775 GNUNET_TESTBED_operation_queue_insert_
1776 (h->opq_parallel_overlay_connect_operations, op);
1781 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
1782 * controller (testbed service)
1784 * @param c the controller handler
1785 * @param msg message received
1786 * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
1790 GNUNET_TESTBED_host_handle_addhostconfirm_ (struct GNUNET_TESTBED_Controller *c,
1792 GNUNET_TESTBED_HostConfirmedMessage
1795 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
1804 if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id))
1806 LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n",
1807 GNUNET_TESTBED_host_get_id_ (rh->host), ntohl (msg->host_id));
1811 msg_size = ntohs (msg->header.size);
1812 if (sizeof (struct GNUNET_TESTBED_HostConfirmedMessage) == msg_size)
1814 LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id));
1815 GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c);
1816 rh->cc (rh->cc_cls, NULL);
1820 /* We have an error message */
1821 emsg = (char *) &msg[1];
1823 emsg[msg_size - sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)])
1829 LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding host %u failed with error: %s\n"),
1830 ntohl (msg->host_id), emsg);
1831 rh->cc (rh->cc_cls, emsg);
1836 /* end of testbed_api_hosts.c */