GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
testbed_api_hosts.c File Reference

API for manipulating 'hosts' controlled by the GNUnet testing service; allows parsing hosts files, starting, stopping and communicating (via SSH/stdin/stdout) with the remote (or local) processes. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testbed_service.h"
#include "gnunet_core_service.h"
#include "gnunet_transport_service.h"
#include "testbed_api.h"
#include "testbed_api_hosts.h"
#include "testbed_helper.h"
#include "testbed_api_operations.h"
#include <zlib.h>
#include <regex.h>
Include dependency graph for testbed_api_hosts.c:

Go to the source code of this file.

Data Structures

struct  RegisteredController
 A list entry for registered controllers list. More...
 
struct  GNUNET_TESTBED_Host
 Opaque handle to a host running experiments managed by the testing framework. More...
 
struct  GNUNET_TESTBED_ControllerProc
 Handle for controller process. More...
 
struct  GNUNET_TESTBED_HostHabitableCheckHandle
 The handle for whether a host is habitable or not. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "testbed-api-hosts", __VA_ARGS__);
 Generic logging shorthand. More...
 
#define LOG_DEBUG(...)   LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
 Debug logging shorthand. More...
 
#define API_VIOLATION(cond, errstr)
 Prints API violation message. More...
 
#define LOG_GAI(level, cmd, rc)
 Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the message given by gai_strerror(rc). More...
 
#define HOST_LIST_GROW_STEP   10
 Number of extra elements we create space for when we grow host list. More...
 

Functions

struct GNUNET_TESTBED_HostGNUNET_TESTBED_host_lookup_by_id_ (uint32_t id)
 Lookup a host by ID. More...
 
struct GNUNET_TESTBED_HostGNUNET_TESTBED_host_create_by_id_ (uint32_t id, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Create a host by ID; given this host handle, we could not run peers at the host, but we can talk about the host internally. More...
 
uint32_t GNUNET_TESTBED_host_get_id_ (const struct GNUNET_TESTBED_Host *host)
 Obtain the host's unique global ID. More...
 
const char * GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host)
 Obtain the host's hostname. More...
 
const char * GNUNET_TESTBED_host_get_username_ (const struct GNUNET_TESTBED_Host *host)
 Obtain the host's username. More...
 
uint16_t GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host)
 Obtain the host's ssh port. More...
 
int GNUNET_TESTBED_host_controller_started (const struct GNUNET_TESTBED_Host *host)
 Check whether a controller is already started on the given host. More...
 
const struct GNUNET_CONFIGURATION_HandleGNUNET_TESTBED_host_get_cfg_ (const struct GNUNET_TESTBED_Host *host)
 Obtain the host's configuration template. More...
 
void GNUNET_TESTBED_host_replace_cfg_ (struct GNUNET_TESTBED_Host *host, const struct GNUNET_CONFIGURATION_Handle *new_cfg)
 Function to replace host's configuration. More...
 
struct GNUNET_TESTBED_HostGNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname, const char *username, const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t port)
 Create a host to run peers and controllers on. More...
 
struct GNUNET_TESTBED_HostGNUNET_TESTBED_host_create (const char *hostname, const char *username, const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t port)
 Create a host to run peers and controllers on. More...
 
unsigned int GNUNET_TESTBED_hosts_load_from_file (const char *filename, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTBED_Host ***hosts)
 Load a set of hosts from a configuration file. More...
 
const char * simple_resolve (const char *host)
 Resolves a hostname using getaddrinfo. More...
 
void GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host)
 Destroy a host handle. More...
 
void GNUNET_TESTBED_mark_host_registered_at_ (struct GNUNET_TESTBED_Host *host, const struct GNUNET_TESTBED_Controller *const controller)
 Marks a host as registered with a controller. More...
 
void GNUNET_TESTBED_deregister_host_at_ (struct GNUNET_TESTBED_Host *host, const struct GNUNET_TESTBED_Controller *const controller)
 Unmarks a host registered at a controller. More...
 
int GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host, const struct GNUNET_TESTBED_Controller *const controller)
 Checks whether a host has been registered. More...
 
static char ** copy_argv (const char *const *argv)
 Function to copy NULL terminated list of arguments. More...
 
static char ** join_argv (const char *const *argv1, const char *const *argv2)
 Function to join NULL terminated list of arguments. More...
 
static void free_argv (char **argv)
 Frees the given NULL terminated arguments. More...
 
static char ** gen_rsh_args (const char *port, const char *hostname, const char *username)
 Generates arguments for opening a remote shell. More...
 
static char ** gen_rsh_suffix_args (const char *const *append_args)
 Generates the arguments needed for executing the given binary in a remote shell. More...
 
static int helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
 Functions with this signature are called whenever a complete message is received by the tokenizer. More...
 
static void clear_msg (void *cls, int result)
 Continuation function from GNUNET_HELPER_send() More...
 
static void helper_exp_cb (void *cls)
 Callback that will be called when the helper process dies. More...
 
struct GNUNET_TESTBED_ControllerProcGNUNET_TESTBED_controller_start (const char *trusted_ip, struct GNUNET_TESTBED_Host *host, GNUNET_TESTBED_ControllerStatusCallback cb, void *cls)
 Starts a controller process at the given host. More...
 
void GNUNET_TESTBED_controller_kill_ (struct GNUNET_TESTBED_ControllerProc *cproc)
 Sends termination signal to the controller's helper process. More...
 
void GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc *cproc)
 Cleans-up the controller's helper process handle. More...
 
void GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc)
 Stop the controller process (also will terminate all peers and controllers dependent on this controller). More...
 
static void habitability_check (void *cls)
 Task for checking whether a host is habitable or not. More...
 
struct GNUNET_TESTBED_HostHabitableCheckHandleGNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host, const struct GNUNET_CONFIGURATION_Handle *config, GNUNET_TESTBED_HostHabitableCallback cb, void *cb_cls)
 Checks whether a host can be used to start testbed service. More...
 
void GNUNET_TESTBED_is_host_habitable_cancel (struct GNUNET_TESTBED_HostHabitableCheckHandle *handle)
 Function to cancel a request started using GNUNET_TESTBED_is_host_habitable() More...
 
struct GNUNET_TESTBED_HostRegistrationHandleGNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, struct GNUNET_TESTBED_Host *host, GNUNET_TESTBED_HostRegistrationCompletion cc, void *cc_cls)
 Register a host with the controller. More...
 
void GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle *handle)
 Cancel the pending registration. More...
 
void GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, struct GNUNET_TESTBED_Operation *op)
 Queues the given operation in the queue for parallel overlay connects of the given host. More...
 
void GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host)
 Resolves the hostname of the host to an ip address. More...
 

Variables

static struct GNUNET_TESTBED_Host ** host_list
 Array of available hosts. More...
 
static unsigned int host_list_size
 The size of the available hosts list. More...
 

Detailed Description

API for manipulating 'hosts' controlled by the GNUnet testing service; allows parsing hosts files, starting, stopping and communicating (via SSH/stdin/stdout) with the remote (or local) processes.

Author
Christian Grothoff

Definition in file testbed_api_hosts.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "testbed-api-hosts", __VA_ARGS__);

Generic logging shorthand.

Definition at line 45 of file testbed_api_hosts.c.

◆ LOG_DEBUG

#define LOG_DEBUG (   ...)    LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);

Debug logging shorthand.

Definition at line 50 of file testbed_api_hosts.c.

◆ API_VIOLATION

#define API_VIOLATION (   cond,
  errstr 
)
Value:
do \
{ \
if (cond) \
break; \
LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \
GNUNET_assert (0); \
} while (0)
@ GNUNET_ERROR_TYPE_ERROR

Prints API violation message.

Definition at line 55 of file testbed_api_hosts.c.

◆ LOG_GAI

#define LOG_GAI (   level,
  cmd,
  rc 
)
Value:
do \
{ \
LOG (level, \
_ ("`%s' failed at %s:%d with error: %s\n"), \
cmd, \
__FILE__, \
__LINE__, \
gai_strerror (rc)); \
} while (0)
#define _(String)
GNU gettext support macro.
Definition: platform.h:177

Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the message given by gai_strerror(rc).

Definition at line 68 of file testbed_api_hosts.c.

◆ HOST_LIST_GROW_STEP

#define HOST_LIST_GROW_STEP   10

Number of extra elements we create space for when we grow host list.

Definition at line 82 of file testbed_api_hosts.c.

Function Documentation

◆ GNUNET_TESTBED_host_lookup_by_id_()

struct GNUNET_TESTBED_Host* GNUNET_TESTBED_host_lookup_by_id_ ( uint32_t  id)

Lookup a host by ID.

Parameters
idglobal host ID assigned to the host; 0 is reserved to always mean 'localhost'
Returns
handle to the host, NULL if host not found

Definition at line 189 of file testbed_api_hosts.c.

190 {
191  if (host_list_size <= id)
192  return NULL;
193  return host_list[id];
194 }
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
static unsigned int host_list_size
The size of the available hosts list.
static struct GNUNET_TESTBED_Host ** host_list
Array of available hosts.

References host_list, host_list_size, and id.

Referenced by handle_link_controllers_result().

Here is the caller graph for this function:

◆ GNUNET_TESTBED_host_create_by_id_()

struct GNUNET_TESTBED_Host* GNUNET_TESTBED_host_create_by_id_ ( uint32_t  id,
const struct GNUNET_CONFIGURATION_Handle cfg 
)

Create a host by ID; given this host handle, we could not run peers at the host, but we can talk about the host internally.

Parameters
idglobal host ID assigned to the host; 0 is reserved to always mean 'localhost'
cfgthe configuration to use as a template while starting a controller on this host. Operation queue sizes specific to a host are also read from this configuration handle
Returns
handle to the host, NULL on error

Definition at line 210 of file testbed_api_hosts.c.

213 {
214  return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0);
215 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_TESTBED_Host * GNUNET_TESTBED_host_create_with_id(uint32_t id, const char *hostname, const char *username, const struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t port)
Create a host to run peers and controllers on.

References cfg, and GNUNET_TESTBED_host_create_with_id().

Here is the call graph for this function:

◆ GNUNET_TESTBED_host_get_id_()

uint32_t GNUNET_TESTBED_host_get_id_ ( const struct GNUNET_TESTBED_Host host)

Obtain the host's unique global ID.

Obtain a host's unique global ID.

Parameters
hosthandle to the host, NULL means 'localhost'
Returns
id global host ID assigned to the host (0 is 'localhost', but then obviously not globally unique)

Definition at line 226 of file testbed_api_hosts.c.

227 {
228  return host->id;
229 }
uint32_t id
Global ID we use to refer to a host on the network.

References GNUNET_TESTBED_Host::id.

Referenced by GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_controller_link(), GNUNET_TESTBED_controller_start(), GNUNET_TESTBED_get_next_op_id(), GNUNET_TESTBED_get_slave_config(), GNUNET_TESTBED_hosts_load_from_file(), GNUNET_TESTBED_register_host(), GST_create_neighbour(), GST_queue_host_registration(), handle_add_host_confirm(), host_list_add(), hr_completion(), opstart_overlay_connect(), opstart_peer_create(), and register_next_host().

Here is the caller graph for this function:

◆ GNUNET_TESTBED_host_get_username_()

const char* GNUNET_TESTBED_host_get_username_ ( const struct GNUNET_TESTBED_Host host)

Obtain the host's username.

Parameters
hosthandle to the host, NULL means 'localhost'
Returns
username to login to the host

Definition at line 252 of file testbed_api_hosts.c.

253 {
254  return host->username;
255 }
const char * username
The username to be used for SSH login.

References GNUNET_TESTBED_Host::username.

Referenced by GNUNET_TESTBED_register_host().

Here is the caller graph for this function:

◆ GNUNET_TESTBED_host_get_ssh_port_()

uint16_t GNUNET_TESTBED_host_get_ssh_port_ ( const struct GNUNET_TESTBED_Host host)

Obtain the host's ssh port.

Parameters
hosthandle to the host, NULL means 'localhost'
Returns
username to login to the host

Definition at line 265 of file testbed_api_hosts.c.

266 {
267  return host->port;
268 }
uint16_t port
The port which is to be used for SSH.

References GNUNET_TESTBED_Host::port.

Referenced by GNUNET_TESTBED_register_host().

Here is the caller graph for this function:

◆ GNUNET_TESTBED_host_controller_started()

int GNUNET_TESTBED_host_controller_started ( const struct GNUNET_TESTBED_Host host)

Check whether a controller is already started on the given host.

Parameters
hostthe handle to the host
Returns
GNUNET_YES if the controller is already started; GNUNET_NO if not

Definition at line 278 of file testbed_api_hosts.c.

279 {
280  return host->controller_started;
281 }
int controller_started
Is a controller started on this host? FIXME: Is this needed?

References GNUNET_TESTBED_Host::controller_started.

◆ GNUNET_TESTBED_host_get_cfg_()

const struct GNUNET_CONFIGURATION_Handle* GNUNET_TESTBED_host_get_cfg_ ( const struct GNUNET_TESTBED_Host host)

Obtain the host's configuration template.

Parameters
hosthandle to the host
Returns
the host's configuration template

Definition at line 291 of file testbed_api_hosts.c.

292 {
293  return host->cfg;
294 }
struct GNUNET_CONFIGURATION_Handle * cfg
the configuration to use as a template while starting a controller on this host.

References GNUNET_TESTBED_Host::cfg.

Referenced by GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_controller_start(), handle_slave_get_config(), and slave_event_cb().

Here is the caller graph for this function:

◆ GNUNET_TESTBED_host_replace_cfg_()

void GNUNET_TESTBED_host_replace_cfg_ ( struct GNUNET_TESTBED_Host host,
const struct GNUNET_CONFIGURATION_Handle new_cfg 
)

Function to replace host's configuration.

Parameters
hostthe host handle
new_cfgthe new configuration to replace the old one

Definition at line 304 of file testbed_api_hosts.c.

307 {
309  host->cfg = GNUNET_CONFIGURATION_dup (new_cfg);
310 }
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.

References GNUNET_TESTBED_Host::cfg, GNUNET_CONFIGURATION_destroy(), and GNUNET_CONFIGURATION_dup().

Referenced by handle_link_controllers_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ simple_resolve()

const char* simple_resolve ( const char *  host)

Resolves a hostname using getaddrinfo.

Parameters
hostthe hostname
Returns
the string representing the IPv4 address of the given host; NULL upon error

Definition at line 535 of file testbed_api_hosts.c.

536 {
537  struct addrinfo *res;
538  const struct sockaddr_in *in_addr;
539  char *hostip;
540  struct addrinfo hint;
541  unsigned int rc;
542 
543  hint.ai_family = AF_INET; /* IPv4 */
544  hint.ai_socktype = 0;
545  hint.ai_protocol = 0;
546  hint.ai_addrlen = 0;
547  hint.ai_addr = NULL;
548  hint.ai_canonname = NULL;
549  hint.ai_next = NULL;
550  hint.ai_flags = AI_NUMERICSERV;
551  res = NULL;
552  LOG_DEBUG ("Resolving [%s]\n", host);
553  if (0 != (rc = getaddrinfo (host, "22", &hint, &res)))
554  {
555  LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc);
556  return NULL;
557  }
558  GNUNET_assert (NULL != res);
559  GNUNET_assert (NULL != res->ai_addr);
560  GNUNET_assert (sizeof(struct sockaddr_in) == res->ai_addrlen);
561  in_addr = (const struct sockaddr_in *) res->ai_addr;
562  hostip = inet_ntoa (in_addr->sin_addr);
563  GNUNET_assert (NULL != hostip);
564  freeaddrinfo (res);
565  LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip);
566  return hostip;
567 }
static int res
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define AI_NUMERICSERV
AI_NUMERICSERV not defined in windows.
Definition: platform.h:218
#define LOG_DEBUG(...)
Debug logging shorthand.
#define LOG_GAI(level, cmd, rc)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...

References AI_NUMERICSERV, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, LOG_DEBUG, LOG_GAI, and res.

Referenced by GNUNET_TESTBED_host_resolve_().

Here is the caller graph for this function:

◆ GNUNET_TESTBED_mark_host_registered_at_()

void GNUNET_TESTBED_mark_host_registered_at_ ( struct GNUNET_TESTBED_Host host,
const struct GNUNET_TESTBED_Controller *const  controller 
)

Marks a host as registered with a controller.

Parameters
hostthe host to mark
controllerthe controller at which this host is registered

Definition at line 623 of file testbed_api_hosts.c.

626 {
627  struct RegisteredController *rc;
628 
629  for (rc = host->rc_head; NULL != rc; rc = rc->next)
630  {
631  if (controller == rc->controller) /* already registered at controller */
632  {
633  GNUNET_break (0);
634  return;
635  }
636  }
637  rc = GNUNET_new (struct RegisteredController);
638  rc->controller = controller;
640 }
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct RegisteredController * rc_head
The head for the list of controllers where this host is registered.
struct RegisteredController * rc_tail
The tail for the list of controllers where this host is registered.
A list entry for registered controllers list.
const struct GNUNET_TESTBED_Controller * controller
The controller at which this host is registered.
struct RegisteredController * next
The next ptr for DLL.

References RegisteredController::controller, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_new, RegisteredController::next, GNUNET_TESTBED_Host::rc_head, and GNUNET_TESTBED_Host::rc_tail.

Referenced by GNUNET_TESTBED_controller_connect(), and handle_add_host_confirm().

Here is the caller graph for this function:

◆ GNUNET_TESTBED_deregister_host_at_()

void GNUNET_TESTBED_deregister_host_at_ ( struct GNUNET_TESTBED_Host host,
const struct GNUNET_TESTBED_Controller *const  controller 
)

Unmarks a host registered at a controller.

Parameters
hostthe host to unmark
controllerthe controller at which this host has to be unmarked

Definition at line 650 of file testbed_api_hosts.c.

653 {
654  struct RegisteredController *rc;
655 
656  for (rc = host->rc_head; NULL != rc; rc = rc->next)
657  if (controller == rc->controller)
658  break;
659  if (NULL == rc)
660  {
661  GNUNET_break (0);
662  return;
663  }
664  GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc);
665  GNUNET_free (rc);
666 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.

References RegisteredController::controller, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, RegisteredController::next, GNUNET_TESTBED_Host::rc_head, and GNUNET_TESTBED_Host::rc_tail.

Referenced by GNUNET_TESTBED_controller_disconnect().

Here is the caller graph for this function:

◆ GNUNET_TESTBED_is_host_registered_()

int GNUNET_TESTBED_is_host_registered_ ( const struct GNUNET_TESTBED_Host host,
const struct GNUNET_TESTBED_Controller *const  controller 
)

Checks whether a host has been registered.

Checks whether a host has been registered with the given controller.

Parameters
hostthe host to check
controllerthe controller at which host's registration is checked
Returns
GNUNET_YES if registered; GNUNET_NO if not

Definition at line 677 of file testbed_api_hosts.c.

680 {
681  struct RegisteredController *rc;
682 
683  for (rc = host->rc_head; NULL != rc; rc = rc->next)
684  {
685  if (controller == rc->controller) /* already registered at controller */
686  {
687  return GNUNET_YES;
688  }
689  }
690  return GNUNET_NO;
691 }
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94

References RegisteredController::controller, GNUNET_NO, GNUNET_YES, RegisteredController::next, and GNUNET_TESTBED_Host::rc_head.

Referenced by GNUNET_TESTBED_controller_link(), GNUNET_TESTBED_get_slave_config(), GNUNET_TESTBED_register_host(), and lcf_proc_task().

Here is the caller graph for this function:

◆ copy_argv()

static char** copy_argv ( const char *const *  argv)
static

Function to copy NULL terminated list of arguments.

Parameters
argvthe NULL terminated list of arguments. Cannot be NULL.
Returns
the copied NULL terminated arguments

Definition at line 743 of file testbed_api_hosts.c.

744 {
745  char **argv_dup;
746  unsigned int argp;
747 
748  GNUNET_assert (NULL != argv);
749  for (argp = 0; NULL != argv[argp]; argp++)
750  ;
751  argv_dup = GNUNET_malloc (sizeof(char *) * (argp + 1));
752  for (argp = 0; NULL != argv[argp]; argp++)
753  argv_dup[argp] = GNUNET_strdup (argv[argp]);
754  return argv_dup;
755 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_malloc(size)
Wrapper around malloc.

References GNUNET_assert, GNUNET_malloc, and GNUNET_strdup.

Referenced by gen_rsh_args().

Here is the caller graph for this function:

◆ join_argv()

static char** join_argv ( const char *const *  argv1,
const char *const *  argv2 
)
static

Function to join NULL terminated list of arguments.

Parameters
argv1the NULL terminated list of arguments. Cannot be NULL.
argv2the NULL terminated list of arguments. Cannot be NULL.
Returns
the joined NULL terminated arguments

Definition at line 766 of file testbed_api_hosts.c.

767 {
768  char **argvj;
769  char *argv;
770  unsigned int carg;
771  unsigned int cnt;
772 
773  carg = 0;
774  argvj = NULL;
775  for (cnt = 0; NULL != argv1[cnt]; cnt++)
776  {
777  argv = GNUNET_strdup (argv1[cnt]);
778  GNUNET_array_append (argvj, carg, argv);
779  }
780  for (cnt = 0; NULL != argv2[cnt]; cnt++)
781  {
782  argv = GNUNET_strdup (argv2[cnt]);
783  GNUNET_array_append (argvj, carg, argv);
784  }
785  GNUNET_array_append (argvj, carg, NULL);
786  return argvj;
787 }
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).

References GNUNET_array_append, and GNUNET_strdup.

Referenced by GNUNET_TESTBED_controller_start(), and GNUNET_TESTBED_is_host_habitable().

Here is the caller graph for this function:

◆ free_argv()

static void free_argv ( char **  argv)
static

Frees the given NULL terminated arguments.

Parameters
argvthe NULL terminated list of arguments

Definition at line 796 of file testbed_api_hosts.c.

797 {
798  unsigned int argp;
799 
800  for (argp = 0; NULL != argv[argp]; argp++)
801  GNUNET_free (argv[argp]);
802  GNUNET_free (argv);
803 }

References GNUNET_free.

Referenced by GNUNET_TESTBED_controller_destroy_(), GNUNET_TESTBED_controller_start(), GNUNET_TESTBED_is_host_habitable(), GNUNET_TESTBED_is_host_habitable_cancel(), and habitability_check().

Here is the caller graph for this function:

◆ gen_rsh_args()

static char** gen_rsh_args ( const char *  port,
const char *  hostname,
const char *  username 
)
static

Generates arguments for opening a remote shell.

Builds up the arguments from the environment variable GNUNET_TESTBED_RSH_CMD. The variable 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 -o StrictHostkeyChecking=no -o PasswordAuthentication=noc'

Parameters
portthe destination port number
hostnamethe hostname of the target host
usernamethe username to use while connecting to target host
Returns
NULL terminated list of arguments

Definition at line 821 of file testbed_api_hosts.c.

822 {
823  static const char *default_ssh_args[] =
824  { "ssh",
825  "-o",
826  "BatchMode=yes",
827  "-o",
828  "NoHostAuthenticationForLocalhost=yes",
829  "-o",
830  "StrictHostKeyChecking=no",
831  "-o",
832  "PasswordAuthentication=no",
833  "%h",
834  NULL };
835  char **ssh_args;
836  char *ssh_cmd;
837  char *ssh_cmd_cp;
838  char *arg;
839  const char *new_arg;
840  unsigned int size;
841  unsigned int cnt;
842 
843  ssh_args = NULL;
844  if (NULL != (ssh_cmd = getenv ("GNUNET_TESTBED_RSH_CMD")))
845  {
846  ssh_cmd = GNUNET_strdup (ssh_cmd);
847  ssh_cmd_cp = ssh_cmd;
848  for (size = 0; NULL != (arg = strtok (ssh_cmd, " ")); ssh_cmd = NULL)
849  GNUNET_array_append (ssh_args, size, GNUNET_strdup (arg));
850  GNUNET_free (ssh_cmd_cp);
851  }
852  else
853  {
854  ssh_args = copy_argv (default_ssh_args);
855  size = (sizeof(default_ssh_args)) / (sizeof(const char *));
856  GNUNET_array_grow (ssh_args, size, size - 1);
857  }
858  for (cnt = 0; cnt < size; cnt++)
859  {
860  arg = ssh_args[cnt];
861  if ('%' != arg[0])
862  continue;
863  switch (arg[1])
864  {
865  case 'p':
866  new_arg = port;
867  break;
868 
869  case 'u':
870  new_arg = username;
871  break;
872 
873  case 'h':
874  new_arg = hostname;
875  break;
876 
877  default:
878  continue;
879  }
880  if (NULL == new_arg)
881  continue;
882  GNUNET_free (arg);
883  ssh_args[cnt] = GNUNET_strdup (new_arg);
884  }
885  GNUNET_array_append (ssh_args, size, NULL);
886  return ssh_args;
887 }
char * getenv()
static uint16_t port
Port number.
Definition: gnunet-bcd.c:83
static char * hostname
Our hostname; we give this to all the peers we start.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
static unsigned int size
Size of the "table".
Definition: peer.c:67
static char ** copy_argv(const char *const *argv)
Function to copy NULL terminated list of arguments.

References find_typedefs::arg, copy_argv(), getenv(), GNUNET_array_append, GNUNET_array_grow, GNUNET_free, GNUNET_strdup, hostname, port, and size.

Referenced by GNUNET_TESTBED_controller_start(), and GNUNET_TESTBED_is_host_habitable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_rsh_suffix_args()

static char** gen_rsh_suffix_args ( const char *const *  append_args)
static

Generates the arguments needed for executing the given binary in a remote shell.

Builds the arguments from the environmental variable GNUNET_TETSBED_RSH_CMD_SUFFIX. If the environmental variable is not found, only the given binary name will be present in the returned arguments

Parameters
append_argsthe arguments to append after generating the suffix arguments. Can be NULL; if not must be NULL terminated 'char *' array
Returns
NULL-terminated args

Definition at line 901 of file testbed_api_hosts.c.

902 {
903  char **rshell_args;
904  char *rshell_cmd;
905  char *rshell_cmd_cp;
906  char *arg;
907  unsigned int cnt;
908  unsigned int append_cnt;
909 
910  rshell_args = NULL;
911  cnt = 0;
912  if (NULL != (rshell_cmd = getenv ("GNUNET_TESTBED_RSH_CMD_SUFFIX")))
913  {
914  rshell_cmd = GNUNET_strdup (rshell_cmd);
915  rshell_cmd_cp = rshell_cmd;
916  for (; NULL != (arg = strtok (rshell_cmd, " ")); rshell_cmd = NULL)
917  GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (arg));
918  GNUNET_free (rshell_cmd_cp);
919  }
920  if (NULL != append_args)
921  {
922  for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++)
923  GNUNET_array_append (rshell_args,
924  cnt,
925  GNUNET_strdup (append_args[append_cnt]));
926  }
927  GNUNET_array_append (rshell_args, cnt, NULL);
928  return rshell_args;
929 }

References find_typedefs::arg, getenv(), GNUNET_array_append, GNUNET_free, and GNUNET_strdup.

Referenced by GNUNET_TESTBED_controller_start(), and GNUNET_TESTBED_is_host_habitable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ helper_mst()

static int helper_mst ( void *  cls,
const struct GNUNET_MessageHeader message 
)
static

Functions with this signature are called whenever a complete message is received by the tokenizer.

Do not call GNUNET_SERVER_mst_destroy in callback

Parameters
clsclosure
clientidentification of the client
messagethe actual message
Returns
GNUNET_OK on success, GNUNET_SYSERR to stop further processing

Definition at line 945 of file testbed_api_hosts.c.

946 {
947  struct GNUNET_TESTBED_ControllerProc *cp = cls;
948  const struct GNUNET_TESTBED_HelperReply *msg;
949  const char *hostname;
950  char *config;
951  uLongf config_size;
952  uLongf xconfig_size;
953 
954  msg = (const struct GNUNET_TESTBED_HelperReply *) message;
955  GNUNET_assert (sizeof(struct GNUNET_TESTBED_HelperReply) <
956  ntohs (msg->header.size));
958  ntohs (msg->header.type));
959  config_size = (uLongf) ntohs (msg->config_size);
960  xconfig_size = (uLongf) (ntohs (msg->header.size)
961  - sizeof(struct GNUNET_TESTBED_HelperReply));
963  GNUNET_assert (Z_OK == uncompress ((Bytef *) config,
964  &config_size,
965  (const Bytef *) &msg[1],
966  xconfig_size));
967  /* Replace the configuration template present in the host with the
968  controller's running configuration */
972  config,
973  config_size,
974  NULL));
976  if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host)))
977  hostname = "localhost";
978  /* Change the hostname so that we can connect to it */
980  "testbed",
981  "hostname",
982  hostname);
983  cp->host->locked = GNUNET_NO;
985  cp->cb (cp->cls, cp->host->cfg, GNUNET_OK);
986  return GNUNET_OK;
987 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static const struct GNUNET_CONFIGURATION_Handle * config
@ GNUNET_OK
Definition: gnunet_common.h:95
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
#define GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY
The reply message from gnunet-testbed-helper.
const char * GNUNET_TESTBED_host_get_hostname(const struct GNUNET_TESTBED_Host *host)
Obtain the host's hostname.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Handle for controller process.
GNUNET_TESTBED_ControllerStatusCallback cb
The controller error callback.
struct GNUNET_TESTBED_Host * host
The host where the helper is run.
void * cls
The closure for the above callback.
Reply message from helper process.
uint16_t config_size
Size of the uncompressed configuration.
int locked
Is this host locked by GNUNET_TESTBED_controller_start()?

References GNUNET_TESTBED_ControllerProc::cb, GNUNET_TESTBED_Host::cfg, GNUNET_TESTBED_ControllerProc::cls, config, GNUNET_TESTBED_HelperReply::config_size, GNUNET_TESTBED_Host::controller_started, GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_deserialize(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_free, GNUNET_malloc, GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY, GNUNET_NO, GNUNET_OK, GNUNET_TESTBED_host_get_hostname(), GNUNET_YES, GNUNET_TESTBED_ControllerProc::host, hostname, GNUNET_TESTBED_Host::locked, msg, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by GNUNET_TESTBED_controller_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear_msg()

static void clear_msg ( void *  cls,
int  result 
)
static

Continuation function from GNUNET_HELPER_send()

Parameters
clsclosure
resultGNUNET_OK on success, GNUNET_NO if helper process died GNUNET_SYSERR during GNUNET_HELPER_stop

Definition at line 999 of file testbed_api_hosts.c.

1000 {
1001  struct GNUNET_TESTBED_ControllerProc *cp = cls;
1002 
1003  GNUNET_assert (NULL != cp->shandle);
1004  cp->shandle = NULL;
1005  GNUNET_free (cp->msg);
1006  cp->msg = NULL;
1007 }
struct GNUNET_HELPER_SendHandle * shandle
The send handle for the helper.
struct GNUNET_MessageHeader * msg
The message corresponding to send handle.

References GNUNET_TESTBED_ControllerProc::cls, GNUNET_assert, GNUNET_free, GNUNET_TESTBED_ControllerProc::msg, and GNUNET_TESTBED_ControllerProc::shandle.

Referenced by GNUNET_TESTBED_controller_start().

Here is the caller graph for this function:

◆ helper_exp_cb()

static void helper_exp_cb ( void *  cls)
static

Callback that will be called when the helper process dies.

This is not called when the helper process is stopped using GNUNET_HELPER_stop()

Parameters
clsthe closure from GNUNET_HELPER_start()

Definition at line 1017 of file testbed_api_hosts.c.

1018 {
1019  struct GNUNET_TESTBED_ControllerProc *cp = cls;
1021  void *cb_cls;
1022 
1023  cb = cp->cb;
1024  cb_cls = cp->cls;
1025  cp->helper = NULL;
1027  if (NULL != cb)
1028  cb (cb_cls, NULL, GNUNET_SYSERR);
1029 }
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
void(* GNUNET_TESTBED_ControllerStatusCallback)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, int status)
Callback to signal successful startup of the controller process.
void GNUNET_TESTBED_controller_stop(struct GNUNET_TESTBED_ControllerProc *cproc)
Stop the controller process (also will terminate all peers and controllers dependent on this controll...
struct GNUNET_HELPER_Handle * helper
The process handle.

References GNUNET_TESTBED_ControllerProc::cb, GNUNET_TESTBED_ControllerProc::cls, GNUNET_SYSERR, GNUNET_TESTBED_controller_stop(), and GNUNET_TESTBED_ControllerProc::helper.

Referenced by GNUNET_TESTBED_controller_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_controller_kill_()

void GNUNET_TESTBED_controller_kill_ ( struct GNUNET_TESTBED_ControllerProc cproc)

Sends termination signal to the controller's helper process.

Parameters
cprocthe handle to the controller's helper process

Definition at line 1166 of file testbed_api_hosts.c.

1167 {
1168  if (NULL != cproc->shandle)
1170  if (NULL != cproc->helper)
1172 }
void GNUNET_HELPER_send_cancel(struct GNUNET_HELPER_SendHandle *sh)
Cancel a GNUNET_HELPER_send operation.
Definition: helper.c:697
int GNUNET_HELPER_kill(struct GNUNET_HELPER_Handle *h, int soft_kill)
Sends termination signal to the helper process.
Definition: helper.c:177

References GNUNET_HELPER_kill(), GNUNET_HELPER_send_cancel(), GNUNET_YES, GNUNET_TESTBED_ControllerProc::helper, and GNUNET_TESTBED_ControllerProc::shandle.

Referenced by GNUNET_TESTBED_controller_stop(), and kill_slave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_controller_destroy_()

void GNUNET_TESTBED_controller_destroy_ ( struct GNUNET_TESTBED_ControllerProc cproc)

Cleans-up the controller's helper process handle.

Parameters
cprocthe handle to the controller's helper process

Definition at line 1181 of file testbed_api_hosts.c.

1182 {
1183  if (NULL != cproc->helper)
1184  {
1186  GNUNET_HELPER_destroy (cproc->helper);
1187  }
1188  if (NULL != cproc->helper_argv)
1189  free_argv (cproc->helper_argv);
1190  cproc->host->controller_started = GNUNET_NO;
1191  cproc->host->locked = GNUNET_NO;
1192  GNUNET_free (cproc->msg);
1193  GNUNET_free (cproc);
1194 }
int GNUNET_HELPER_wait(struct GNUNET_HELPER_Handle *h)
Reap the helper process.
Definition: helper.c:225
void GNUNET_HELPER_destroy(struct GNUNET_HELPER_Handle *h)
Free's the resources occupied by the helper handle.
Definition: helper.c:530
char ** helper_argv
The arguments used to start the helper.
static void free_argv(char **argv)
Frees the given NULL terminated arguments.

References GNUNET_TESTBED_Host::controller_started, free_argv(), GNUNET_break, GNUNET_free, GNUNET_HELPER_destroy(), GNUNET_HELPER_wait(), GNUNET_NO, GNUNET_OK, GNUNET_TESTBED_ControllerProc::helper, GNUNET_TESTBED_ControllerProc::helper_argv, GNUNET_TESTBED_ControllerProc::host, GNUNET_TESTBED_Host::locked, and GNUNET_TESTBED_ControllerProc::msg.

Referenced by destroy_slave(), and GNUNET_TESTBED_controller_stop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ habitability_check()

static void habitability_check ( void *  cls)
static

Task for checking whether a host is habitable or not.

Parameters
clsGNUNET_TESTBED_HostHabitableCheckHandle

Definition at line 1262 of file testbed_api_hosts.c.

1263 {
1265  void *cb_cls;
1267  const struct GNUNET_TESTBED_Host *host;
1268  unsigned long code;
1270  int ret;
1271 
1272  h->habitability_check_task = NULL;
1273  ret = GNUNET_OS_process_status (h->auxp, &type, &code);
1274  if (GNUNET_SYSERR == ret)
1275  {
1276  GNUNET_break (0);
1277  ret = GNUNET_NO;
1278  goto call_cb;
1279  }
1280  if (GNUNET_NO == ret)
1281  {
1282  h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
1283  h->habitability_check_task =
1285  return;
1286  }
1287  GNUNET_OS_process_destroy (h->auxp);
1288  h->auxp = NULL;
1289  ret = (0 != code) ? GNUNET_NO : GNUNET_YES;
1290 
1291  call_cb:
1292  if (NULL != h->auxp)
1293  GNUNET_OS_process_destroy (h->auxp);
1294  cb = h->cb;
1295  cb_cls = h->cb_cls;
1296  host = h->host;
1297  free_argv (h->helper_argv);
1298  GNUNET_free (h);
1299  if (NULL != cb)
1300  cb (cb_cls, host, ret);
1301 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
int GNUNET_OS_process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Retrieve the status of a process.
Definition: os_priority.c:946
GNUNET_OS_ProcessStatusType
Process status types.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:286
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
void(* GNUNET_TESTBED_HostHabitableCallback)(void *cls, const struct GNUNET_TESTBED_Host *host, int status)
Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to inform whether the given hos...
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
The handle for whether a host is habitable or not.
GNUNET_TESTBED_HostHabitableCallback cb
The callback to call once we have the status.
Opaque handle to a host running experiments managed by the testing framework.
static void habitability_check(void *cls)
Task for checking whether a host is habitable or not.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References GNUNET_TESTBED_HostHabitableCheckHandle::cb, GNUNET_TESTBED_HostHabitableCheckHandle::cb_cls, free_argv(), GNUNET_break, GNUNET_free, GNUNET_NO, GNUNET_OS_process_destroy(), GNUNET_OS_process_status(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_TIME_STD_BACKOFF, GNUNET_YES, h, ret, and type.

Referenced by GNUNET_TESTBED_is_host_habitable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_host_queue_oc_()

void GNUNET_TESTBED_host_queue_oc_ ( struct GNUNET_TESTBED_Host h,
struct GNUNET_TESTBED_Operation op 
)

Queues the given operation in the queue for parallel overlay connects of the given host.

Parameters
hthe host handle
opthe operation to queue in the given host's parally overlay connect queue

Definition at line 1507 of file testbed_api_hosts.c.

1509 {
1511  h->opq_parallel_overlay_connect_operations,
1512  op);
1513 }
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
void GNUNET_TESTBED_operation_queue_insert_(struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op)
Add an operation to a queue.

References GNUNET_TESTBED_operation_queue_insert_(), h, and op.

Referenced by GNUNET_TESTBED_overlay_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_host_resolve_()

void GNUNET_TESTBED_host_resolve_ ( struct GNUNET_TESTBED_Host host)

Resolves the hostname of the host to an ip address.

Parameters
hostthe host whose hostname is to be resolved

Definition at line 1522 of file testbed_api_hosts.c.

1523 {
1524  char *hostname;
1525 
1526  hostname = (char *) host->hostname;
1527  host->hostname = simple_resolve (hostname);
1528  if (NULL == host->hostname)
1529  {
1530  GNUNET_break (0);
1531  host->hostname = hostname;
1532  return;
1533  }
1535  host->hostname = GNUNET_strdup (host->hostname);
1536 }
const char * hostname
The hostname of the host; NULL for localhost.
const char * simple_resolve(const char *host)
Resolves a hostname using getaddrinfo.

References GNUNET_break, GNUNET_free, GNUNET_strdup, hostname, GNUNET_TESTBED_Host::hostname, and simple_resolve().

Referenced by host_habitable_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ host_list

struct GNUNET_TESTBED_Host** host_list
static

◆ host_list_size

unsigned int host_list_size
static

The size of the available hosts list.

Definition at line 178 of file testbed_api_hosts.c.

Referenced by GNUNET_TESTBED_host_create_with_id(), GNUNET_TESTBED_host_destroy(), and GNUNET_TESTBED_host_lookup_by_id_().