GNUnet  0.19.2
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 a 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 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 219 of file testbed_api_hosts.c.

220 {
221  return host->id;
222 }
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 245 of file testbed_api_hosts.c.

246 {
247  return host->username;
248 }
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 258 of file testbed_api_hosts.c.

259 {
260  return host->port;
261 }
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 271 of file testbed_api_hosts.c.

272 {
273  return host->controller_started;
274 }
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 284 of file testbed_api_hosts.c.

285 {
286  return host->cfg;
287 }
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 297 of file testbed_api_hosts.c.

300 {
302  host->cfg = GNUNET_CONFIGURATION_dup (new_cfg);
303 }
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 517 of file testbed_api_hosts.c.

518 {
519  struct addrinfo *res;
520  const struct sockaddr_in *in_addr;
521  char *hostip;
522  struct addrinfo hint;
523  unsigned int rc;
524 
525  hint.ai_family = AF_INET; /* IPv4 */
526  hint.ai_socktype = 0;
527  hint.ai_protocol = 0;
528  hint.ai_addrlen = 0;
529  hint.ai_addr = NULL;
530  hint.ai_canonname = NULL;
531  hint.ai_next = NULL;
532  hint.ai_flags = AI_NUMERICSERV;
533  res = NULL;
534  LOG_DEBUG ("Resolving [%s]\n", host);
535  if (0 != (rc = getaddrinfo (host, "22", &hint, &res)))
536  {
537  LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc);
538  return NULL;
539  }
540  GNUNET_assert (NULL != res);
541  GNUNET_assert (NULL != res->ai_addr);
542  GNUNET_assert (sizeof(struct sockaddr_in) == res->ai_addrlen);
543  in_addr = (const struct sockaddr_in *) res->ai_addr;
544  hostip = inet_ntoa (in_addr->sin_addr);
545  GNUNET_assert (NULL != hostip);
546  freeaddrinfo (res);
547  LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip);
548  return hostip;
549 }
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 605 of file testbed_api_hosts.c.

608 {
609  struct RegisteredController *rc;
610 
611  for (rc = host->rc_head; NULL != rc; rc = rc->next)
612  {
613  if (controller == rc->controller) /* already registered at controller */
614  {
615  GNUNET_break (0);
616  return;
617  }
618  }
619  rc = GNUNET_new (struct RegisteredController);
620  rc->controller = controller;
622 }
#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 632 of file testbed_api_hosts.c.

635 {
636  struct RegisteredController *rc;
637 
638  for (rc = host->rc_head; NULL != rc; rc = rc->next)
639  if (controller == rc->controller)
640  break;
641  if (NULL == rc)
642  {
643  GNUNET_break (0);
644  return;
645  }
646  GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc);
647  GNUNET_free (rc);
648 }
#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 659 of file testbed_api_hosts.c.

662 {
663  struct RegisteredController *rc;
664 
665  for (rc = host->rc_head; NULL != rc; rc = rc->next)
666  {
667  if (controller == rc->controller) /* already registered at controller */
668  {
669  return GNUNET_YES;
670  }
671  }
672  return GNUNET_NO;
673 }
@ GNUNET_YES
@ GNUNET_NO

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 725 of file testbed_api_hosts.c.

726 {
727  char **argv_dup;
728  unsigned int argp;
729 
730  GNUNET_assert (NULL != argv);
731  for (argp = 0; NULL != argv[argp]; argp++)
732  ;
733  argv_dup = GNUNET_malloc (sizeof(char *) * (argp + 1));
734  for (argp = 0; NULL != argv[argp]; argp++)
735  argv_dup[argp] = GNUNET_strdup (argv[argp]);
736  return argv_dup;
737 }
#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 748 of file testbed_api_hosts.c.

749 {
750  char **argvj;
751  char *argv;
752  unsigned int carg;
753  unsigned int cnt;
754 
755  carg = 0;
756  argvj = NULL;
757  for (cnt = 0; NULL != argv1[cnt]; cnt++)
758  {
759  argv = GNUNET_strdup (argv1[cnt]);
760  GNUNET_array_append (argvj, carg, argv);
761  }
762  for (cnt = 0; NULL != argv2[cnt]; cnt++)
763  {
764  argv = GNUNET_strdup (argv2[cnt]);
765  GNUNET_array_append (argvj, carg, argv);
766  }
767  GNUNET_array_append (argvj, carg, NULL);
768  return argvj;
769 }
#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 778 of file testbed_api_hosts.c.

779 {
780  unsigned int argp;
781 
782  for (argp = 0; NULL != argv[argp]; argp++)
783  GNUNET_free (argv[argp]);
784  GNUNET_free (argv);
785 }

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 803 of file testbed_api_hosts.c.

804 {
805  static const char *default_ssh_args[] =
806  { "ssh",
807  "-o",
808  "BatchMode=yes",
809  "-o",
810  "NoHostAuthenticationForLocalhost=yes",
811  "-o",
812  "StrictHostKeyChecking=no",
813  "-o",
814  "PasswordAuthentication=no",
815  "%h",
816  NULL };
817  char **ssh_args;
818  char *ssh_cmd;
819  char *ssh_cmd_cp;
820  char *arg;
821  const char *new_arg;
822  unsigned int size;
823  unsigned int cnt;
824 
825  ssh_args = NULL;
826  if (NULL != (ssh_cmd = getenv ("GNUNET_TESTBED_RSH_CMD")))
827  {
828  ssh_cmd = GNUNET_strdup (ssh_cmd);
829  ssh_cmd_cp = ssh_cmd;
830  for (size = 0; NULL != (arg = strtok (ssh_cmd, " ")); ssh_cmd = NULL)
831  GNUNET_array_append (ssh_args, size, GNUNET_strdup (arg));
832  GNUNET_free (ssh_cmd_cp);
833  }
834  else
835  {
836  ssh_args = copy_argv (default_ssh_args);
837  size = (sizeof(default_ssh_args)) / (sizeof(const char *));
838  GNUNET_array_grow (ssh_args, size, size - 1);
839  }
840  for (cnt = 0; cnt < size; cnt++)
841  {
842  arg = ssh_args[cnt];
843  if ('%' != arg[0])
844  continue;
845  switch (arg[1])
846  {
847  case 'p':
848  new_arg = port;
849  break;
850 
851  case 'u':
852  new_arg = username;
853  break;
854 
855  case 'h':
856  new_arg = hostname;
857  break;
858 
859  default:
860  continue;
861  }
862  if (NULL == new_arg)
863  continue;
864  GNUNET_free (arg);
865  ssh_args[cnt] = GNUNET_strdup (new_arg);
866  }
867  GNUNET_array_append (ssh_args, size, NULL);
868  return ssh_args;
869 }
char * getenv()
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
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:68
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 883 of file testbed_api_hosts.c.

884 {
885  char **rshell_args;
886  char *rshell_cmd;
887  char *rshell_cmd_cp;
888  char *arg;
889  unsigned int cnt;
890  unsigned int append_cnt;
891 
892  rshell_args = NULL;
893  cnt = 0;
894  if (NULL != (rshell_cmd = getenv ("GNUNET_TESTBED_RSH_CMD_SUFFIX")))
895  {
896  rshell_cmd = GNUNET_strdup (rshell_cmd);
897  rshell_cmd_cp = rshell_cmd;
898  for (; NULL != (arg = strtok (rshell_cmd, " ")); rshell_cmd = NULL)
899  GNUNET_array_append (rshell_args, cnt, GNUNET_strdup (arg));
900  GNUNET_free (rshell_cmd_cp);
901  }
902  if (NULL != append_args)
903  {
904  for (append_cnt = 0; NULL != append_args[append_cnt]; append_cnt++)
905  GNUNET_array_append (rshell_args,
906  cnt,
907  GNUNET_strdup (append_args[append_cnt]));
908  }
909  GNUNET_array_append (rshell_args, cnt, NULL);
910  return rshell_args;
911 }

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
messagethe actual message
Returns
GNUNET_OK on success, GNUNET_SYSERR to stop further processing

Definition at line 926 of file testbed_api_hosts.c.

927 {
928  struct GNUNET_TESTBED_ControllerProc *cp = cls;
929  const struct GNUNET_TESTBED_HelperReply *msg;
930  const char *hostname;
931  char *config;
932  uLongf config_size;
933  uLongf xconfig_size;
934 
935  msg = (const struct GNUNET_TESTBED_HelperReply *) message;
936  GNUNET_assert (sizeof(struct GNUNET_TESTBED_HelperReply) <
937  ntohs (msg->header.size));
939  ntohs (msg->header.type));
940  config_size = (uLongf) ntohs (msg->config_size);
941  xconfig_size = (uLongf) (ntohs (msg->header.size)
942  - sizeof(struct GNUNET_TESTBED_HelperReply));
944  GNUNET_assert (Z_OK == uncompress ((Bytef *) config,
945  &config_size,
946  (const Bytef *) &msg[1],
947  xconfig_size));
948  /* Replace the configuration template present in the host with the
949  controller's running configuration */
953  config,
954  config_size,
955  NULL));
957  if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host)))
958  hostname = "localhost";
959  /* Change the hostname so that we can connect to it */
961  "testbed",
962  "hostname",
963  hostname);
964  cp->host->locked = GNUNET_NO;
966  cp->cb (cp->cls, cp->host->cfg, GNUNET_OK);
967  return GNUNET_OK;
968 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static const struct GNUNET_CONFIGURATION_Handle * config
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.
@ GNUNET_OK
#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 980 of file testbed_api_hosts.c.

981 {
982  struct GNUNET_TESTBED_ControllerProc *cp = cls;
983 
984  GNUNET_assert (NULL != cp->shandle);
985  cp->shandle = NULL;
986  GNUNET_free (cp->msg);
987  cp->msg = NULL;
988 }
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 998 of file testbed_api_hosts.c.

999 {
1000  struct GNUNET_TESTBED_ControllerProc *cp = cls;
1002  void *cb_cls;
1003 
1004  cb = cp->cb;
1005  cb_cls = cp->cls;
1006  cp->helper = NULL;
1008  if (NULL != cb)
1009  cb (cb_cls, NULL, GNUNET_SYSERR);
1010 }
@ GNUNET_SYSERR
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 1147 of file testbed_api_hosts.c.

1148 {
1149  if (NULL != cproc->shandle)
1151  if (NULL != cproc->helper)
1153 }
void GNUNET_HELPER_send_cancel(struct GNUNET_HELPER_SendHandle *sh)
Cancel a GNUNET_HELPER_send operation.
Definition: helper.c:654
int GNUNET_HELPER_kill(struct GNUNET_HELPER_Handle *h, int soft_kill)
Sends termination signal to the helper process.
Definition: helper.c:167

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 1162 of file testbed_api_hosts.c.

1163 {
1164  if (NULL != cproc->helper)
1165  {
1167  GNUNET_HELPER_destroy (cproc->helper);
1168  }
1169  if (NULL != cproc->helper_argv)
1170  free_argv (cproc->helper_argv);
1171  cproc->host->controller_started = GNUNET_NO;
1172  cproc->host->locked = GNUNET_NO;
1173  GNUNET_free (cproc->msg);
1174  GNUNET_free (cproc);
1175 }
int GNUNET_HELPER_wait(struct GNUNET_HELPER_Handle *h)
Reap the helper process.
Definition: helper.c:207
void GNUNET_HELPER_destroy(struct GNUNET_HELPER_Handle *h)
Free's the resources occupied by the helper handle.
Definition: helper.c:500
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 1243 of file testbed_api_hosts.c.

1244 {
1246  void *cb_cls;
1248  const struct GNUNET_TESTBED_Host *host;
1249  unsigned long code;
1251  int ret;
1252 
1253  h->habitability_check_task = NULL;
1254  ret = GNUNET_OS_process_status (h->auxp, &type, &code);
1255  if (GNUNET_SYSERR == ret)
1256  {
1257  GNUNET_break (0);
1258  ret = GNUNET_NO;
1259  goto call_cb;
1260  }
1261  if (GNUNET_NO == ret)
1262  {
1263  h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time);
1264  h->habitability_check_task =
1266  return;
1267  }
1268  GNUNET_OS_process_destroy (h->auxp);
1269  h->auxp = NULL;
1270  ret = (0 != code) ? GNUNET_NO : GNUNET_YES;
1271 
1272  call_cb:
1273  if (NULL != h->auxp)
1274  GNUNET_OS_process_destroy (h->auxp);
1275  cb = h->cb;
1276  cb_cls = h->cb_cls;
1277  host = h->host;
1278  free_argv (h->helper_argv);
1279  GNUNET_free (h);
1280  if (NULL != cb)
1281  cb (cb_cls, host, ret);
1282 }
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:905
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:273
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:1241
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 1488 of file testbed_api_hosts.c.

1490 {
1492  h->opq_parallel_overlay_connect_operations,
1493  op);
1494 }
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 1503 of file testbed_api_hosts.c.

1504 {
1505  char *hostname;
1506 
1507  hostname = (char *) host->hostname;
1508  host->hostname = simple_resolve (hostname);
1509  if (NULL == host->hostname)
1510  {
1511  GNUNET_break (0);
1512  host->hostname = hostname;
1513  return;
1514  }
1516  host->hostname = GNUNET_strdup (host->hostname);
1517 }
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

◆ 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_().