2 This file is part of GNUnet
3 (C) 2008--2013 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 hostname of the host; NULL for localhost
132 const char *hostname;
135 * The username to be used for SSH login
137 const char *username;
140 * the configuration to use as a template while starting a controller on this
141 * host. Operation queue size specific to a host are also read from this
142 * configuration handle. After starting the controller, it points to the actual
143 * configuration with which the controller is running
145 struct GNUNET_CONFIGURATION_Handle *cfg;
148 * The head for the list of controllers where this host is registered
150 struct RegisteredController *rc_head;
153 * The tail for the list of controllers where this host is registered
155 struct RegisteredController *rc_tail;
158 * Operation queue for simultaneous overlay connect operations target at this
161 struct OperationQueue *opq_parallel_overlay_connect_operations;
164 * An array of timing slots; size should be equal to the current number of parallel
167 struct TimeSlot *tslots;
170 * Handle for SD calculations amount parallel overlay connect operation finish
173 struct SDHandle *poc_sd;
176 * The number of parallel overlay connects we do currently
178 unsigned int num_parallel_connects;
181 * Counter to indicate when all the available time slots are filled
183 unsigned int tslots_filled;
186 * Is a controller started on this host? FIXME: Is this needed?
188 int controller_started;
191 * Is this host locked by GNUNET_TESTBED_controller_start()?
196 * Global ID we use to refer to a host on the network
201 * The port which is to be used for SSH
209 * Array of available hosts
211 static struct GNUNET_TESTBED_Host **host_list;
214 * The size of the available hosts list
216 static unsigned int host_list_size;
220 * Lookup a host by ID.
222 * @param id global host ID assigned to the host; 0 is
223 * reserved to always mean 'localhost'
224 * @return handle to the host, NULL if host not found
226 struct GNUNET_TESTBED_Host *
227 GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id)
229 if (host_list_size <= id)
231 return host_list[id];
236 * Create a host by ID; given this host handle, we could not
237 * run peers at the host, but we can talk about the host
240 * @param id global host ID assigned to the host; 0 is
241 * reserved to always mean 'localhost'
242 * @param cfg the configuration to use as a template while starting a controller
243 * on this host. Operation queue sizes specific to a host are also
244 * read from this configuration handle
245 * @return handle to the host, NULL on error
247 struct GNUNET_TESTBED_Host *
248 GNUNET_TESTBED_host_create_by_id_ (uint32_t id,
249 const struct GNUNET_CONFIGURATION_Handle
252 return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0);
257 * Obtain the host's unique global ID.
259 * @param host handle to the host, NULL means 'localhost'
260 * @return id global host ID assigned to the host (0 is
261 * 'localhost', but then obviously not globally unique)
264 GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host * host)
271 * Obtain the host's hostname.
273 * @param host handle to the host, NULL means 'localhost'
274 * @return hostname of the host
277 GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host)
279 return host->hostname;
284 * Obtain the host's username
286 * @param host handle to the host, NULL means 'localhost'
287 * @return username to login to the host
290 GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host)
292 return host->username;
297 * Obtain the host's ssh port
299 * @param host handle to the host, NULL means 'localhost'
300 * @return username to login to the host
303 GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host * host)
310 * Check whether a controller is already started on the given host
312 * @param host the handle to the host
313 * @return GNUNET_YES if the controller is already started; GNUNET_NO if not
316 GNUNET_TESTBED_host_controller_started (const struct GNUNET_TESTBED_Host *host)
318 return host->controller_started;
323 * Obtain the host's configuration template
325 * @param host handle to the host
326 * @return the host's configuration template
328 const struct GNUNET_CONFIGURATION_Handle *
329 GNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host)
336 * Function to replace host's configuration
338 * @param host the host handle
339 * @param new_cfg the new configuration to replace the old one
342 GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host,
343 const struct GNUNET_CONFIGURATION_Handle *new_cfg)
345 GNUNET_CONFIGURATION_destroy (host->cfg);
346 host->cfg = GNUNET_CONFIGURATION_dup (new_cfg);
351 * Create a host to run peers and controllers on.
353 * @param id global host ID assigned to the host; 0 is
354 * reserved to always mean 'localhost'
355 * @param hostname name of the host, use "NULL" for localhost
356 * @param username username to use for the login; may be NULL
357 * @param cfg the configuration to use as a template while starting a controller
358 * on this host. Operation queue sizes specific to a host are also
359 * read from this configuration handle
360 * @param port port number to use for ssh; use 0 to let ssh decide
361 * @return handle to the host, NULL on error
363 struct GNUNET_TESTBED_Host *
364 GNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname,
365 const char *username,
366 const struct GNUNET_CONFIGURATION_Handle
370 struct GNUNET_TESTBED_Host *host;
371 unsigned int new_size;
373 if ((id < host_list_size) && (NULL != host_list[id]))
375 LOG (GNUNET_ERROR_TYPE_WARNING, "Host with id: %u already created\n", id);
378 host = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host));
379 host->hostname = (NULL != hostname) ? GNUNET_strdup (hostname) : NULL;
380 host->username = (NULL != username) ? GNUNET_strdup (username) : NULL;
382 host->port = (0 == port) ? 22 : port;
383 host->cfg = GNUNET_CONFIGURATION_dup (cfg);
384 host->opq_parallel_overlay_connect_operations =
385 GNUNET_TESTBED_operation_queue_create_ (0);
386 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (host, 1);
387 host->poc_sd = GNUNET_TESTBED_SD_init_ (10);
388 new_size = host_list_size;
389 while (id >= new_size)
390 new_size += HOST_LIST_GROW_STEP;
391 if (new_size != host_list_size)
392 GNUNET_array_grow (host_list, host_list_size, new_size);
393 GNUNET_assert (id < host_list_size);
394 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id);
395 host_list[id] = host;
401 * Create a host to run peers and controllers on.
403 * @param hostname name of the host, use "NULL" for localhost
404 * @param username username to use for the login; may be NULL
405 * @param cfg the configuration to use as a template while starting a controller
406 * on this host. Operation queue sizes specific to a host are also
407 * read from this configuration handle
408 * @param port port number to use for ssh; use 0 to let ssh decide
409 * @return handle to the host, NULL on error
411 struct GNUNET_TESTBED_Host *
412 GNUNET_TESTBED_host_create (const char *hostname, const char *username,
413 const struct GNUNET_CONFIGURATION_Handle *cfg,
416 static uint32_t uid_generator;
418 if (NULL == hostname)
419 return GNUNET_TESTBED_host_create_with_id (0, hostname, username,
421 return GNUNET_TESTBED_host_create_with_id (++uid_generator, hostname,
422 username, cfg, port);
427 * Load a set of hosts from a configuration file.
429 * @param filename file with the host specification
430 * @param cfg the configuration to use as a template while starting a controller
431 * on any of the loaded hosts. Operation queue sizes specific to a host
432 * are also read from this configuration handle
433 * @param hosts set to the hosts found in the file; caller must free this if
434 * number of hosts returned is greater than 0
435 * @return number of hosts returned in 'hosts', 0 on error
438 GNUNET_TESTBED_hosts_load_from_file (const char *filename,
439 const struct GNUNET_CONFIGURATION_Handle
441 struct GNUNET_TESTBED_Host ***hosts)
443 //struct GNUNET_TESTBED_Host **host_array;
444 struct GNUNET_TESTBED_Host *starting_host;
456 GNUNET_assert (NULL != filename);
457 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
459 LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s not found\n"), filename);
463 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
467 LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s has no data\n"), filename);
470 data = GNUNET_malloc (fs);
471 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
474 LOG (GNUNET_ERROR_TYPE_WARNING, _("Hosts file %s cannot be read\n"),
480 starting_host = NULL;
482 while (offset < (fs - 1))
485 if (((data[offset] == '\n')) && (buf != &data[offset]))
489 SSCANF (buf, "%255[a-zA-Z0-9_]@%255[a-zA-Z0-9.-]:%5hd", username,
493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
494 "Successfully read host %s, port %d and user %s from file\n",
495 hostname, port, username);
496 /* We store hosts in a static list; hence we only require the starting
497 * host pointer in that list to access the newly created list of hosts */
498 if (NULL == starting_host)
499 starting_host = GNUNET_TESTBED_host_create (hostname, username, cfg,
502 (void) GNUNET_TESTBED_host_create (hostname, username, cfg, port);
506 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
507 "Error reading line `%s' in hostfile\n", buf);
508 buf = &data[offset + 1];
510 else if ((data[offset] == '\n') || (data[offset] == '\0'))
511 buf = &data[offset + 1];
514 if (NULL == starting_host)
516 *hosts = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * count);
517 memcpy (*hosts, &host_list[GNUNET_TESTBED_host_get_id_ (starting_host)],
518 sizeof (struct GNUNET_TESTBED_Host *) * count);
524 * Resolves a hostname using getaddrinfo
526 * @param host the hostname
527 * @return the string representing the IPv4 address of the given host; NULL upon error
530 simple_resolve (const char *host)
532 struct addrinfo *res;
533 const struct sockaddr_in *in_addr;
535 struct addrinfo hint;
538 hint.ai_family = AF_INET; /* IPv4 */
539 hint.ai_socktype = 0;
540 hint.ai_protocol = 0;
543 hint.ai_canonname = NULL;
545 hint.ai_flags = AI_NUMERICSERV;
547 LOG_DEBUG ("Resolving [%s]\n", host);
548 if (0 != (rc = getaddrinfo (host, "22", &hint, &res)))
550 LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc);
553 GNUNET_assert (NULL != res);
554 GNUNET_assert (NULL != res->ai_addr);
555 GNUNET_assert (sizeof (struct sockaddr_in) == res->ai_addrlen);
556 in_addr = (const struct sockaddr_in *) res->ai_addr;
557 hostip = inet_ntoa (in_addr->sin_addr);
558 GNUNET_assert (NULL != hostip);
560 LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip);
566 cmpstringp(const void *p1, const void *p2)
568 /* The actual arguments to this function are "pointers to
569 pointers to char", but strcmp(3) arguments are "pointers
570 to char", hence the following cast plus dereference */
572 return strcmp(* (char * const *) p1, * (char * const *) p2);
577 * Loads the set of host allocated by the LoadLeveler Job Scheduler. This
578 * function is only available when compiled with support for LoadLeveler and is
579 * used for running on the SuperMUC
581 * @param cfg the configuration to use as a template while starting a controller
582 * on any of the loaded hosts. Operation queue sizes specific to a host
583 * are also read from this configuration handle
584 * @param hosts set to the hosts found in the file; caller must free this if
585 * number of hosts returned is greater than 0
586 * @return number of hosts returned in 'hosts', 0 on error
589 GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
590 GNUNET_CONFIGURATION_Handle *cfg,
591 struct GNUNET_TESTBED_Host ***hosts)
594 LOG (GNUNET_ERROR_TYPE_ERROR,
595 _("The function %s is only available when compiled with (--with-ll)\n"),
599 const char *hostfile;
603 struct GNUNET_TESTBED_Host **host_list;
616 if (NULL == (hostfile = getenv ("MP_SAVEHOSTFILE")))
621 if (GNUNET_SYSERR == GNUNET_DISK_file_size (hostfile, &size, GNUNET_YES,
632 buf = GNUNET_malloc (size + 1);
633 rsize = GNUNET_DISK_fn_read (hostfile, buf, (size_t) size);
634 if ( (GNUNET_SYSERR == rsize) || ((ssize_t) size != rsize) )
646 while (offset < size)
651 if ('!' == buf[offset])
657 if ('\n' == buf[offset])
661 if ('!' == buf[offset])
666 if ( (' ' == buf[offset])
667 || ('\t' == buf[offset])
668 || ('\r' == buf[offset]) )
673 hostname = &buf[offset];
677 if (isspace (buf[offset]))
680 for (host = 0; host < nhosts; host++)
681 if (0 == strcmp (hostnames[host], hostname))
685 LOG_DEBUG ("Adding host [%s]\n", hostname);
686 hostname = GNUNET_strdup (hostname);
687 GNUNET_array_append (hostnames, nhosts, hostname);
690 LOG_DEBUG ("Not adding host [%s] as it is already included\n", hostname);
698 GNUNET_free_non_null (buf);
699 if (NULL == hostnames)
703 qsort (hostnames, nhosts, sizeof (hostnames[0]), cmpstringp);
704 host_list = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) * nhosts);
705 for (host = 0; host < nhosts; host++)
706 host_list[host] = GNUNET_TESTBED_host_create (hostnames[host], NULL, cfg, 0);
710 for (host = 0; host < nhosts; host++)
711 GNUNET_free (hostnames[host]);
712 GNUNET_free(hostnames);
719 * Destroy a host handle. Must only be called once everything
720 * running on that host has been stopped.
722 * @param host handle to destroy
725 GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
727 struct RegisteredController *rc;
730 GNUNET_assert (host->id < host_list_size);
731 GNUNET_assert (host_list[host->id] == host);
732 host_list[host->id] = NULL;
733 /* clear registered controllers list */
734 for (rc = host->rc_head; NULL != rc; rc = host->rc_head)
736 GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc);
739 GNUNET_free_non_null ((char *) host->username);
740 GNUNET_free_non_null ((char *) host->hostname);
741 GNUNET_TESTBED_operation_queue_destroy_
742 (host->opq_parallel_overlay_connect_operations);
743 GNUNET_TESTBED_SD_destroy_ (host->poc_sd);
744 GNUNET_free_non_null (host->tslots);
745 GNUNET_CONFIGURATION_destroy (host->cfg);
747 while (host_list_size >= HOST_LIST_GROW_STEP)
749 for (id = host_list_size - 1; id > host_list_size - HOST_LIST_GROW_STEP;
751 if (NULL != host_list[id])
753 if (id != host_list_size - HOST_LIST_GROW_STEP)
755 if (NULL != host_list[id])
757 host_list_size -= HOST_LIST_GROW_STEP;
760 GNUNET_realloc (host_list,
761 sizeof (struct GNUNET_TESTBED_Host *) * host_list_size);
766 * Marks a host as registered with a controller
768 * @param host the host to mark
769 * @param controller the controller at which this host is registered
772 GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host,
773 const struct GNUNET_TESTBED_Controller
776 struct RegisteredController *rc;
778 for (rc = host->rc_head; NULL != rc; rc = rc->next)
780 if (controller == rc->controller) /* already registered at controller */
786 rc = GNUNET_malloc (sizeof (struct RegisteredController));
787 rc->controller = controller;
788 GNUNET_CONTAINER_DLL_insert_tail (host->rc_head, host->rc_tail, rc);
793 * Unmarks a host registered at a controller
795 * @param host the host to unmark
796 * @param controller the controller at which this host has to be unmarked
799 GNUNET_TESTBED_deregister_host_at_ (struct GNUNET_TESTBED_Host *host,
800 const struct GNUNET_TESTBED_Controller
803 struct RegisteredController *rc;
805 for (rc = host->rc_head; NULL != rc; rc=rc->next)
806 if (controller == rc->controller)
813 GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc);
819 * Checks whether a host has been registered
821 * @param host the host to check
822 * @param controller the controller at which host's registration is checked
823 * @return GNUNET_YES if registered; GNUNET_NO if not
826 GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host,
827 const struct GNUNET_TESTBED_Controller
830 struct RegisteredController *rc;
832 for (rc = host->rc_head; NULL != rc; rc = rc->next)
834 if (controller == rc->controller) /* already registered at controller */
844 * Handle for controller process
846 struct GNUNET_TESTBED_ControllerProc
851 struct GNUNET_HELPER_Handle *helper;
854 * The arguments used to start the helper
859 * The host where the helper is run
861 struct GNUNET_TESTBED_Host *host;
864 * The controller error callback
866 GNUNET_TESTBED_ControllerStatusCallback cb;
869 * The closure for the above callback
874 * The send handle for the helper
876 struct GNUNET_HELPER_SendHandle *shandle;
879 * The message corresponding to send handle
881 struct GNUNET_MessageHeader *msg;
887 * Function to copy NULL terminated list of arguments
889 * @param argv the NULL terminated list of arguments. Cannot be NULL.
890 * @return the copied NULL terminated arguments
893 copy_argv (const char *const *argv)
898 GNUNET_assert (NULL != argv);
899 for (argp = 0; NULL != argv[argp]; argp++) ;
900 argv_dup = GNUNET_malloc (sizeof (char *) * (argp + 1));
901 for (argp = 0; NULL != argv[argp]; argp++)
902 argv_dup[argp] = strdup (argv[argp]);
908 * Function to join NULL terminated list of arguments
910 * @param argv1 the NULL terminated list of arguments. Cannot be NULL.
911 * @param argv2 the NULL terminated list of arguments. Cannot be NULL.
912 * @return the joined NULL terminated arguments
915 join_argv (const char *const *argv1, const char *const *argv2)
924 for (cnt = 0; NULL != argv1[cnt]; cnt++)
926 argv = GNUNET_strdup (argv1[cnt]);
927 GNUNET_array_append (argvj, carg, argv);
929 for (cnt = 0; NULL != argv2[cnt]; cnt++)
931 argv = GNUNET_strdup (argv2[cnt]);
932 GNUNET_array_append (argvj, carg, argv);
934 GNUNET_array_append (argvj, carg, NULL);
940 * Frees the given NULL terminated arguments
942 * @param argv the NULL terminated list of arguments
945 free_argv (char **argv)
949 for (argp = 0; NULL != argv[argp]; argp++)
950 GNUNET_free (argv[argp]);
956 * Generates arguments for opening a remote shell. Builds up the arguments
957 * from the environment variable GNUNET_TESTBED_RSH_CMD. The variable
958 * should not mention `-p' (port) option and destination address as these will
959 * be set locally in the function from its parameteres. If the environmental
960 * variable is not found then it defaults to `ssh -o BatchMode=yes -o
961 * NoHostAuthenticationForLocalhost=yes'
963 * @param port the destination port number
964 * @param dst the destination address
965 * @return NULL terminated list of arguments
968 gen_rsh_args (const char *port, const char *dst)
970 static const char *default_ssh_args[] = {
975 "NoHostAuthenticationForLocalhost=yes",
985 if (NULL != (ssh_cmd = getenv ("GNUNET_TESTBED_RSH_CMD")))
987 ssh_cmd = GNUNET_strdup (ssh_cmd);
988 ssh_cmd_cp = ssh_cmd;
989 for (cnt = 0; NULL != (arg = strtok (ssh_cmd, " ")); ssh_cmd = NULL)
990 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (arg));
991 GNUNET_free (ssh_cmd_cp);
995 ssh_args = copy_argv (default_ssh_args);
996 cnt = (sizeof (default_ssh_args)) / (sizeof (const char *));
997 GNUNET_array_grow (ssh_args, cnt, cnt - 1);
999 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup ("-p"));
1000 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (port));
1001 GNUNET_array_append (ssh_args, cnt, GNUNET_strdup (dst));
1002 GNUNET_array_append (ssh_args, cnt, NULL);
1008 * Generates the arguments needed for executing the given binary in a remote
1009 * shell. Builds the arguments from the environmental variable
1010 * GNUNET_TETSBED_RSH_CMD_SUFFIX. If the environmental variable is not found,
1011 * only the given binary name will be present in the returned arguments
1013 * @param append_args the arguments to append after generating the suffix
1014 * arguments. Can be NULL; if not must be NULL terminated 'char *' array
1015 * @return NULL-terminated args
1018 gen_rsh_suffix_args (const char * const *append_args)
1022 char *rshell_cmd_cp;
1025 unsigned int append_cnt;
1029 if (NULL != (rshell_cmd = getenv ("GNUNET_TESTBED_RSH_CMD_SUFFIX")))
1031 rshell_cmd = GNUNET_strdup (rshell_cmd);
1032 rshell_cmd_cp = rshell_cmd;
1033 for (; NULL != (arg = strtok (rshell_cmd, " ")); rshell_cmd = NULL)
1034 GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (arg));
1035 GNUNET_free (rshell_cmd_cp);
1037 if (NULL != append_args)
1039 for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++)
1040 GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (append_args[append_cnt]));
1042 GNUNET_array_append (rshell_args, cnt, NULL);
1048 * Functions with this signature are called whenever a
1049 * complete message is received by the tokenizer.
1051 * Do not call GNUNET_SERVER_mst_destroy in callback
1053 * @param cls closure
1054 * @param client identification of the client
1055 * @param message the actual message
1057 * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing
1060 helper_mst (void *cls, void *client, const struct GNUNET_MessageHeader *message)
1062 struct GNUNET_TESTBED_ControllerProc *cp = cls;
1063 const struct GNUNET_TESTBED_HelperReply *msg;
1064 const char *hostname;
1067 uLongf xconfig_size;
1069 msg = (const struct GNUNET_TESTBED_HelperReply *) message;
1070 GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) <
1071 ntohs (msg->header.size));
1072 GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY ==
1073 ntohs (msg->header.type));
1074 config_size = (uLongf) ntohs (msg->config_size);
1076 (uLongf) (ntohs (msg->header.size) -
1077 sizeof (struct GNUNET_TESTBED_HelperReply));
1078 config = GNUNET_malloc (config_size);
1079 GNUNET_assert (Z_OK ==
1080 uncompress ((Bytef *) config, &config_size,
1081 (const Bytef *) &msg[1], xconfig_size));
1082 /* Replace the configuration template present in the host with the
1083 controller's running configuration */
1084 GNUNET_CONFIGURATION_destroy (cp->host->cfg);
1085 cp->host->cfg = GNUNET_CONFIGURATION_create ();
1086 GNUNET_assert (GNUNET_CONFIGURATION_deserialize
1087 (cp->host->cfg, config, config_size, GNUNET_NO));
1088 GNUNET_free (config);
1089 if ((NULL == cp->host) ||
1090 (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))))
1091 hostname = "localhost";
1092 /* Change the hostname so that we can connect to it */
1093 GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, "testbed", "hostname",
1095 cp->host->locked = GNUNET_NO;
1096 cp->host->controller_started = GNUNET_YES;
1097 cp->cb (cp->cls, cp->host->cfg, GNUNET_OK);
1103 * Continuation function from GNUNET_HELPER_send()
1105 * @param cls closure
1106 * @param result GNUNET_OK on success,
1107 * GNUNET_NO if helper process died
1108 * GNUNET_SYSERR during GNUNET_HELPER_stop
1111 clear_msg (void *cls, int result)
1113 struct GNUNET_TESTBED_ControllerProc *cp = cls;
1115 GNUNET_assert (NULL != cp->shandle);
1117 GNUNET_free (cp->msg);
1122 * Callback that will be called when the helper process dies. This is not called
1123 * when the helper process is stoped using GNUNET_HELPER_stop()
1125 * @param cls the closure from GNUNET_HELPER_start()
1128 helper_exp_cb (void *cls)
1130 struct GNUNET_TESTBED_ControllerProc *cp = cls;
1131 GNUNET_TESTBED_ControllerStatusCallback cb;
1137 GNUNET_TESTBED_controller_stop (cp);
1139 cb (cb_cls, NULL, GNUNET_SYSERR);
1144 * Starts a controller process at the given host. The given host's configration
1145 * is used as a Template configuration to use for the remote controller; the
1146 * remote controller will be started with a slightly modified configuration
1147 * (port numbers, unix domain sockets and service home values are changed as per
1148 * TESTING library on the remote host). The modified configuration replaces the
1149 * host's existing configuration before signalling success through the
1150 * GNUNET_TESTBED_ControllerStatusCallback()
1152 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
1153 * HOST(all connections form this ip are permitted by the testbed) when
1154 * starting testbed controller at host. This can either be a single ip
1155 * address or a network address in CIDR notation.
1156 * @param host the host where the controller has to be started. CANNOT be NULL.
1157 * @param cb function called when the controller is successfully started or
1158 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
1159 * called if cb is called with GNUNET_SYSERR as status. Will never be
1160 * called in the same task as 'GNUNET_TESTBED_controller_start'
1161 * (synchronous errors will be signalled by returning NULL). This
1162 * parameter cannot be NULL.
1163 * @param cls closure for above callbacks
1164 * @return the controller process handle, NULL on errors
1166 struct GNUNET_TESTBED_ControllerProc *
1167 GNUNET_TESTBED_controller_start (const char *trusted_ip,
1168 struct GNUNET_TESTBED_Host *host,
1169 GNUNET_TESTBED_ControllerStatusCallback cb,
1172 struct GNUNET_TESTBED_ControllerProc *cp;
1173 struct GNUNET_TESTBED_HelperInit *msg;
1174 const struct GNUNET_CONFIGURATION_Handle *cfg;
1175 const char *hostname;
1176 static char *const binary_argv[] = {
1177 HELPER_TESTBED_BINARY, NULL
1180 GNUNET_assert (NULL != host);
1181 GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host)));
1183 API_VIOLATION (GNUNET_NO == host->locked,
1184 "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()");
1185 host->locked = GNUNET_YES;
1186 API_VIOLATION (GNUNET_NO == host->controller_started,
1187 "Attempting to start a controller on a host which is already started a controller");
1188 cp = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ControllerProc));
1189 if (0 == GNUNET_TESTBED_host_get_id_ (host))
1192 GNUNET_HELPER_start (GNUNET_YES, HELPER_TESTBED_BINARY, binary_argv,
1193 &helper_mst, &helper_exp_cb, cp);
1197 char *helper_binary_path_args[2];
1199 char **rsh_suffix_args;
1200 const char *username;
1204 username = GNUNET_TESTBED_host_get_username_ (host);
1205 hostname = GNUNET_TESTBED_host_get_hostname (host);
1206 GNUNET_asprintf (&port, "%u", GNUNET_TESTBED_host_get_ssh_port_ (host));
1207 if (NULL == username)
1208 GNUNET_asprintf (&dst, "%s", hostname);
1210 GNUNET_asprintf (&dst, "%s@%s", username, hostname);
1211 LOG_DEBUG ("Starting SSH to destination %s\n", dst);
1214 GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
1215 "HELPER_BINARY_PATH",
1216 &helper_binary_path_args[0]))
1217 helper_binary_path_args[0] =
1218 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
1219 helper_binary_path_args[1] = NULL;
1220 rsh_args = gen_rsh_args (port, dst);
1221 rsh_suffix_args = gen_rsh_suffix_args ((const char **) helper_binary_path_args);
1223 join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args);
1224 free_argv (rsh_args);
1225 free_argv (rsh_suffix_args);
1229 GNUNET_HELPER_start (GNUNET_NO, cp->helper_argv[0], cp->helper_argv, &helper_mst,
1230 &helper_exp_cb, cp);
1231 GNUNET_free (helper_binary_path_args[0]);
1233 if (NULL == cp->helper)
1235 if (NULL != cp->helper_argv)
1236 free_argv (cp->helper_argv);
1243 msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg);
1244 cp->msg = &msg->header;
1246 GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp);
1247 if (NULL == cp->shandle)
1250 GNUNET_TESTBED_controller_stop (cp);
1258 * Sends termination signal to the controller's helper process
1260 * @param cproc the handle to the controller's helper process
1263 GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc)
1265 if (NULL != cproc->shandle)
1266 GNUNET_HELPER_send_cancel (cproc->shandle);
1267 if (NULL != cproc->helper)
1268 GNUNET_HELPER_kill (cproc->helper, GNUNET_YES);
1273 * Cleans-up the controller's helper process handle
1275 * @param cproc the handle to the controller's helper process
1278 GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc *cproc)
1280 if (NULL != cproc->helper)
1282 GNUNET_break (GNUNET_OK == GNUNET_HELPER_wait (cproc->helper));
1283 GNUNET_HELPER_destroy (cproc->helper);
1285 if (NULL != cproc->helper_argv)
1286 free_argv (cproc->helper_argv);
1287 cproc->host->controller_started = GNUNET_NO;
1288 cproc->host->locked = GNUNET_NO;
1289 GNUNET_free (cproc);
1294 * Stop the controller process (also will terminate all peers and controllers
1295 * dependent on this controller). This function blocks until the testbed has
1296 * been fully terminated (!). The controller status cb from
1297 * GNUNET_TESTBED_controller_start() will not be called.
1299 * @param cproc the controller process handle
1302 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc)
1304 GNUNET_TESTBED_controller_kill_ (cproc);
1305 GNUNET_TESTBED_controller_destroy_ (cproc);
1310 * The handle for whether a host is habitable or not
1312 struct GNUNET_TESTBED_HostHabitableCheckHandle
1317 const struct GNUNET_TESTBED_Host *host;
1320 * The callback to call once we have the status
1322 GNUNET_TESTBED_HostHabitableCallback cb;
1325 * The callback closure
1330 * The process handle for the SSH process
1332 struct GNUNET_OS_Process *auxp;
1335 * The arguments used to start the helper
1340 * Task id for the habitability check task
1342 GNUNET_SCHEDULER_TaskIdentifier habitability_check_task;
1345 * How long we wait before checking the process status. Should grow
1348 struct GNUNET_TIME_Relative wait_time;
1354 * Task for checking whether a host is habitable or not
1356 * @param cls GNUNET_TESTBED_HostHabitableCheckHandle
1357 * @param tc the scheduler task context
1360 habitability_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1362 struct GNUNET_TESTBED_HostHabitableCheckHandle *h = cls;
1364 GNUNET_TESTBED_HostHabitableCallback cb;
1365 const struct GNUNET_TESTBED_Host *host;
1367 enum GNUNET_OS_ProcessStatusType type;
1370 h->habitability_check_task = GNUNET_SCHEDULER_NO_TASK;
1371 ret = GNUNET_OS_process_status (h->auxp, &type, &code);
1372 if (GNUNET_SYSERR == ret)
1378 if (GNUNET_NO == ret)
1380 h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
1381 h->habitability_check_task =
1382 GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
1385 GNUNET_OS_process_destroy (h->auxp);
1387 ret = (0 != code) ? GNUNET_NO : GNUNET_YES;
1390 if (NULL != h->auxp)
1391 GNUNET_OS_process_destroy (h->auxp);
1395 free_argv (h->helper_argv);
1398 cb (cb_cls, host, ret);
1403 * Checks whether a host can be used to start testbed service
1405 * @param host the host to check
1406 * @param config the configuration handle to lookup the path of the testbed
1408 * @param cb the callback to call to inform about habitability of the given host
1409 * @param cb_cls the closure for the callback
1410 * @return NULL upon any error or a handle which can be passed to
1411 * GNUNET_TESTBED_is_host_habitable_cancel()
1413 struct GNUNET_TESTBED_HostHabitableCheckHandle *
1414 GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
1415 const struct GNUNET_CONFIGURATION_Handle
1417 GNUNET_TESTBED_HostHabitableCallback cb,
1420 struct GNUNET_TESTBED_HostHabitableCheckHandle *h;
1422 char **rsh_suffix_args;
1424 const char *hostname;
1428 h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostHabitableCheckHandle));
1432 hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname;
1433 if (NULL == host->username)
1434 dst = GNUNET_strdup (hostname);
1436 GNUNET_asprintf (&dst, "%s@%s", host->username, hostname);
1438 GNUNET_CONFIGURATION_get_value_string (config, "testbed",
1439 "HELPER_BINARY_PATH",
1442 GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY);
1443 GNUNET_asprintf (&port, "%u", host->port);
1444 rsh_args = gen_rsh_args (port, dst);
1449 stat_args[0] = "stat";
1450 stat_args[2] = NULL;
1451 rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args);
1452 GNUNET_free (stat_args[1]);
1453 h->helper_argv = join_argv ((const char **) rsh_args,
1454 (const char **) rsh_suffix_args);
1455 free_argv (rsh_suffix_args);
1456 free_argv (rsh_args);
1458 GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, NULL,
1459 NULL, h->helper_argv[0], h->helper_argv);
1460 if (NULL == h->auxp)
1462 GNUNET_break (0); /* Cannot exec SSH? */
1466 h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
1467 h->habitability_check_task =
1468 GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h);
1474 * Function to cancel a request started using GNUNET_TESTBED_is_host_habitable()
1476 * @param handle the habitability check handle
1479 GNUNET_TESTBED_is_host_habitable_cancel (struct
1480 GNUNET_TESTBED_HostHabitableCheckHandle
1483 GNUNET_SCHEDULER_cancel (handle->habitability_check_task);
1484 (void) GNUNET_OS_process_kill (handle->auxp, SIGTERM);
1485 (void) GNUNET_OS_process_wait (handle->auxp);
1486 GNUNET_OS_process_destroy (handle->auxp);
1487 free_argv (handle->helper_argv);
1488 GNUNET_free (handle);
1493 * handle for host registration
1495 struct GNUNET_TESTBED_HostRegistrationHandle
1498 * The host being registered
1500 struct GNUNET_TESTBED_Host *host;
1503 * The controller at which this host is being registered
1505 struct GNUNET_TESTBED_Controller *c;
1508 * The Registartion completion callback
1510 GNUNET_TESTBED_HostRegistrationCompletion cc;
1513 * The closure for above callback
1520 * Register a host with the controller
1522 * @param controller the controller handle
1523 * @param host the host to register
1524 * @param cc the completion callback to call to inform the status of
1525 * registration. After calling this callback the registration handle
1526 * will be invalid. Cannot be NULL.
1527 * @param cc_cls the closure for the cc
1528 * @return handle to the host registration which can be used to cancel the
1531 struct GNUNET_TESTBED_HostRegistrationHandle *
1532 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
1533 struct GNUNET_TESTBED_Host *host,
1534 GNUNET_TESTBED_HostRegistrationCompletion cc,
1537 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
1538 struct GNUNET_TESTBED_AddHostMessage *msg;
1539 const char *username;
1540 const char *hostname;
1547 uint16_t username_length;
1548 uint16_t hostname_length;
1550 if (NULL != controller->rh)
1552 hostname = GNUNET_TESTBED_host_get_hostname (host);
1553 if (GNUNET_YES == GNUNET_TESTBED_is_host_registered_ (host, controller))
1555 LOG (GNUNET_ERROR_TYPE_WARNING, "Host hostname: %s already registered\n",
1556 (NULL == hostname) ? "localhost" : hostname);
1559 rh = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_HostRegistrationHandle));
1562 GNUNET_assert (NULL != cc);
1564 rh->cc_cls = cc_cls;
1565 controller->rh = rh;
1566 username = GNUNET_TESTBED_host_get_username_ (host);
1567 username_length = 0;
1568 if (NULL != username)
1569 username_length = strlen (username);
1570 GNUNET_assert (NULL != hostname); /* Hostname must be present */
1571 hostname_length = strlen (hostname);
1572 GNUNET_assert (NULL != host->cfg);
1573 config = GNUNET_CONFIGURATION_serialize (host->cfg, &config_size);
1574 cc_size = GNUNET_TESTBED_compress_config_ (config, config_size, &cconfig);
1575 GNUNET_free (config);
1576 msg_size = (sizeof (struct GNUNET_TESTBED_AddHostMessage));
1577 msg_size += username_length;
1578 msg_size += hostname_length;
1579 msg_size += cc_size;
1580 msg = GNUNET_malloc (msg_size);
1581 msg->header.size = htons (msg_size);
1582 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST);
1583 msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
1584 msg->ssh_port = htons (GNUNET_TESTBED_host_get_ssh_port_ (host));
1586 if (NULL != username)
1588 msg->username_length = htons (username_length);
1589 ptr = memcpy (ptr, username, username_length);
1590 ptr += username_length;
1592 msg->hostname_length = htons (hostname_length);
1593 ptr = memcpy (ptr, hostname, hostname_length);
1594 ptr += hostname_length;
1595 msg->config_size = htons (config_size);
1596 ptr = memcpy (ptr, cconfig, cc_size);
1598 GNUNET_assert ((ptr - (void *) msg) == msg_size);
1599 GNUNET_free (cconfig);
1600 GNUNET_TESTBED_queue_message_ (controller,
1601 (struct GNUNET_MessageHeader *) msg);
1607 * Cancel the pending registration. Note that if the registration message is
1608 * already sent to the service the cancellation has only the effect that the
1609 * registration completion callback for the registration is never called.
1611 * @param handle the registration handle to cancel
1614 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
1617 if (handle != handle->c->rh)
1622 handle->c->rh = NULL;
1623 GNUNET_free (handle);
1628 * Initializes the operation queue for parallel overlay connects
1630 * @param h the host handle
1631 * @param npoc the number of parallel overlay connects - the queue size
1634 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (struct
1635 GNUNET_TESTBED_Host *h,
1638 //fprintf (stderr, "%d", npoc);
1639 GNUNET_free_non_null (h->tslots);
1640 h->tslots_filled = 0;
1641 h->num_parallel_connects = npoc;
1642 h->tslots = GNUNET_malloc (npoc * sizeof (struct TimeSlot));
1643 GNUNET_TESTBED_operation_queue_reset_max_active_
1644 (h->opq_parallel_overlay_connect_operations, npoc);
1649 * Returns a timing slot which will be exclusively locked
1651 * @param h the host handle
1652 * @param key a pointer which is associated to the returned slot; should not be
1653 * NULL. It serves as a key to determine the correct owner of the slot
1654 * @return the time slot index in the array of time slots in the controller
1658 GNUNET_TESTBED_get_tslot_ (struct GNUNET_TESTBED_Host *h, void *key)
1662 GNUNET_assert (NULL != h->tslots);
1663 GNUNET_assert (NULL != key);
1664 for (slot = 0; slot < h->num_parallel_connects; slot++)
1665 if (NULL == h->tslots[slot].key)
1667 h->tslots[slot].key = key;
1670 GNUNET_assert (0); /* We should always find a free tslot */
1675 * Decides whether any change in the number of parallel overlay connects is
1676 * necessary to adapt to the load on the system
1678 * @param h the host handle
1681 decide_npoc (struct GNUNET_TESTBED_Host *h)
1683 struct GNUNET_TIME_Relative avg;
1688 if (h->tslots_filled != h->num_parallel_connects)
1690 avg = GNUNET_TIME_UNIT_ZERO;
1692 for (slot = 0; slot < h->num_parallel_connects; slot++)
1694 avg = GNUNET_TIME_relative_add (avg, h->tslots[slot].time);
1695 nvals += h->tslots[slot].nvals;
1697 GNUNET_assert (nvals >= h->num_parallel_connects);
1698 avg = GNUNET_TIME_relative_divide (avg, nvals);
1699 GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value != avg.rel_value);
1700 sd = GNUNET_TESTBED_SD_deviation_factor_ (h->poc_sd, (unsigned int) avg.rel_value);
1702 (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1703 h->num_parallel_connects)) )
1704 GNUNET_TESTBED_SD_add_data_ (h->poc_sd, (unsigned int) avg.rel_value);
1705 if (GNUNET_SYSERR == sd)
1707 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1708 h->num_parallel_connects);
1711 GNUNET_assert (0 <= sd);
1714 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1715 h->num_parallel_connects
1721 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1722 h->num_parallel_connects
1726 if (1 == h->num_parallel_connects)
1728 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, 1);
1733 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1734 h->num_parallel_connects
1738 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1739 h->num_parallel_connects /
1745 * Releases a time slot thus making it available for be used again
1747 * @param h the host handle
1748 * @param index the index of the the time slot
1749 * @param key the key to prove ownership of the timeslot
1750 * @return GNUNET_YES if the time slot is successfully removed; GNUNET_NO if the
1751 * time slot cannot be removed - this could be because of the index
1752 * greater than existing number of time slots or `key' being different
1755 GNUNET_TESTBED_release_time_slot_ (struct GNUNET_TESTBED_Host *h,
1756 unsigned int index, void *key)
1758 struct TimeSlot *slot;
1760 GNUNET_assert (NULL != key);
1761 if (index >= h->num_parallel_connects)
1763 slot = &h->tslots[index];
1764 if (key != slot->key)
1772 * Function to update a time slot
1774 * @param h the host handle
1775 * @param index the index of the time slot to update
1776 * @param key the key to identify ownership of the slot
1777 * @param time the new time
1778 * @param failed should this reading be treated as coming from a fail event
1781 GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Host *h,
1782 unsigned int index, void *key,
1783 struct GNUNET_TIME_Relative time, int failed)
1785 struct TimeSlot *slot;
1787 if (GNUNET_YES == failed)
1789 if (1 == h->num_parallel_connects)
1791 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, 1);
1794 GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
1795 h->num_parallel_connects
1798 if (GNUNET_NO == GNUNET_TESTBED_release_time_slot_ (h, index, key))
1800 slot = &h->tslots[index];
1802 if (GNUNET_TIME_UNIT_ZERO.rel_value == slot->time.rel_value)
1809 slot->time = GNUNET_TIME_relative_add (slot->time, time);
1814 * Queues the given operation in the queue for parallel overlay connects of the
1817 * @param h the host handle
1818 * @param op the operation to queue in the given host's parally overlay connect
1822 GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h,
1823 struct GNUNET_TESTBED_Operation *op)
1825 GNUNET_TESTBED_operation_queue_insert_
1826 (h->opq_parallel_overlay_connect_operations, op);
1831 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
1832 * controller (testbed service)
1834 * @param c the controller handler
1835 * @param msg message received
1836 * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if
1840 GNUNET_TESTBED_host_handle_addhostconfirm_ (struct GNUNET_TESTBED_Controller *c,
1842 GNUNET_TESTBED_HostConfirmedMessage
1845 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
1854 if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id))
1856 LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n",
1857 GNUNET_TESTBED_host_get_id_ (rh->host), ntohl (msg->host_id));
1861 msg_size = ntohs (msg->header.size);
1862 if (sizeof (struct GNUNET_TESTBED_HostConfirmedMessage) == msg_size)
1864 LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id));
1865 GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c);
1866 rh->cc (rh->cc_cls, NULL);
1870 /* We have an error message */
1871 emsg = (char *) &msg[1];
1873 emsg[msg_size - sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)])
1879 LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding host %u failed with error: %s\n"),
1880 ntohl (msg->host_id), emsg);
1881 rh->cc (rh->cc_cls, emsg);
1888 * Resolves the hostname of the host to an ip address
1890 * @param host the host whose hostname is to be resolved
1893 GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host)
1897 hostname = (char *) host->hostname;
1898 host->hostname = simple_resolve (hostname);
1899 if (NULL == host->hostname)
1902 host->hostname = hostname;
1905 GNUNET_free (hostname);
1906 host->hostname = GNUNET_strdup (hostname);
1909 /* end of testbed_api_hosts.c */