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>
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_Host * | GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id) |
Lookup a host by ID. More... | |
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. 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_Handle * | GNUNET_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_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. More... | |
struct GNUNET_TESTBED_Host * | GNUNET_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_ControllerProc * | GNUNET_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_HostHabitableCheckHandle * | GNUNET_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_HostRegistrationHandle * | GNUNET_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... | |
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.
Definition in file testbed_api_hosts.c.
#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.
#define LOG_DEBUG | ( | ... | ) | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); |
Debug logging shorthand.
Definition at line 50 of file testbed_api_hosts.c.
#define API_VIOLATION | ( | cond, | |
errstr | |||
) |
Prints API violation message.
Definition at line 55 of file testbed_api_hosts.c.
#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).
Definition at line 68 of file testbed_api_hosts.c.
#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.
struct GNUNET_TESTBED_Host* GNUNET_TESTBED_host_lookup_by_id_ | ( | uint32_t | id | ) |
Lookup a host by ID.
id | global host ID assigned to the host; 0 is reserved to always mean 'localhost' |
Definition at line 189 of file testbed_api_hosts.c.
References host_list, host_list_size, and id.
Referenced by handle_link_controllers_result().
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.
id | global host ID assigned to the host; 0 is reserved to always mean 'localhost' |
cfg | the 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 |
Definition at line 210 of file testbed_api_hosts.c.
References cfg, and GNUNET_TESTBED_host_create_with_id().
uint32_t GNUNET_TESTBED_host_get_id_ | ( | const struct GNUNET_TESTBED_Host * | host | ) |
Obtain a host's unique global ID.
host | handle to the host, NULL means 'localhost' |
Definition at line 219 of file testbed_api_hosts.c.
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().
const char* GNUNET_TESTBED_host_get_username_ | ( | const struct GNUNET_TESTBED_Host * | host | ) |
Obtain the host's username.
host | handle to the host, NULL means 'localhost' |
Definition at line 245 of file testbed_api_hosts.c.
References GNUNET_TESTBED_Host::username.
Referenced by GNUNET_TESTBED_register_host().
uint16_t GNUNET_TESTBED_host_get_ssh_port_ | ( | const struct GNUNET_TESTBED_Host * | host | ) |
Obtain the host's ssh port.
host | handle to the host, NULL means 'localhost' |
Definition at line 258 of file testbed_api_hosts.c.
References GNUNET_TESTBED_Host::port.
Referenced by GNUNET_TESTBED_register_host().
int GNUNET_TESTBED_host_controller_started | ( | const struct GNUNET_TESTBED_Host * | host | ) |
Check whether a controller is already started on the given host.
host | the handle to the host |
Definition at line 271 of file testbed_api_hosts.c.
References GNUNET_TESTBED_Host::controller_started.
const struct GNUNET_CONFIGURATION_Handle* GNUNET_TESTBED_host_get_cfg_ | ( | const struct GNUNET_TESTBED_Host * | host | ) |
Obtain the host's configuration template.
host | handle to the host |
Definition at line 284 of file testbed_api_hosts.c.
References GNUNET_TESTBED_Host::cfg.
Referenced by GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_controller_start(), handle_slave_get_config(), and slave_event_cb().
void GNUNET_TESTBED_host_replace_cfg_ | ( | struct GNUNET_TESTBED_Host * | host, |
const struct GNUNET_CONFIGURATION_Handle * | new_cfg | ||
) |
Function to replace host's configuration.
host | the host handle |
new_cfg | the new configuration to replace the old one |
Definition at line 297 of file testbed_api_hosts.c.
References GNUNET_TESTBED_Host::cfg, GNUNET_CONFIGURATION_destroy(), and GNUNET_CONFIGURATION_dup().
Referenced by handle_link_controllers_result().
const char* simple_resolve | ( | const char * | host | ) |
Resolves a hostname using getaddrinfo.
host | the hostname |
Definition at line 517 of file testbed_api_hosts.c.
References AI_NUMERICSERV, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, LOG_DEBUG, LOG_GAI, and res.
Referenced by GNUNET_TESTBED_host_resolve_().
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.
host | the host to mark |
controller | the controller at which this host is registered |
Definition at line 605 of file testbed_api_hosts.c.
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().
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.
host | the host to unmark |
controller | the controller at which this host has to be unmarked |
Definition at line 632 of file testbed_api_hosts.c.
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().
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.
host | the host to check |
controller | the controller at which host's registration is checked |
Definition at line 659 of file testbed_api_hosts.c.
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().
|
static |
Function to copy NULL terminated list of arguments.
argv | the NULL terminated list of arguments. Cannot be NULL. |
Definition at line 725 of file testbed_api_hosts.c.
References GNUNET_assert, GNUNET_malloc, and GNUNET_strdup.
Referenced by gen_rsh_args().
|
static |
Function to join NULL terminated list of arguments.
argv1 | the NULL terminated list of arguments. Cannot be NULL. |
argv2 | the NULL terminated list of arguments. Cannot be NULL. |
Definition at line 748 of file testbed_api_hosts.c.
References GNUNET_array_append, and GNUNET_strdup.
Referenced by GNUNET_TESTBED_controller_start(), and GNUNET_TESTBED_is_host_habitable().
|
static |
Frees the given NULL terminated arguments.
argv | the NULL terminated list of arguments |
Definition at line 778 of file testbed_api_hosts.c.
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().
|
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=no'
port | the destination port number |
hostname | the hostname of the target host |
username | the username to use while connecting to target host |
Definition at line 803 of file testbed_api_hosts.c.
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().
|
static |
Generates the arguments needed for executing the given binary in a remote shell.
Builds the arguments from the environmental variable GNUNET_TESTBED_RSH_CMD_SUFFIX. If the environmental variable is not found, only the given binary name will be present in the returned arguments
append_args | the arguments to append after generating the suffix arguments. Can be NULL; if not must be NULL terminated 'char *' array |
Definition at line 883 of file testbed_api_hosts.c.
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().
|
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
cls | closure |
message | the actual message |
Definition at line 926 of file testbed_api_hosts.c.
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().
|
static |
Continuation function from GNUNET_HELPER_send()
cls | closure |
result | GNUNET_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.
References GNUNET_TESTBED_ControllerProc::cls, GNUNET_assert, GNUNET_free, GNUNET_TESTBED_ControllerProc::msg, and GNUNET_TESTBED_ControllerProc::shandle.
Referenced by GNUNET_TESTBED_controller_start().
|
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()
cls | the closure from GNUNET_HELPER_start() |
Definition at line 998 of file testbed_api_hosts.c.
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().
void GNUNET_TESTBED_controller_kill_ | ( | struct GNUNET_TESTBED_ControllerProc * | cproc | ) |
Sends termination signal to the controller's helper process.
cproc | the handle to the controller's helper process |
Definition at line 1147 of file testbed_api_hosts.c.
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().
void GNUNET_TESTBED_controller_destroy_ | ( | struct GNUNET_TESTBED_ControllerProc * | cproc | ) |
Cleans-up the controller's helper process handle.
cproc | the handle to the controller's helper process |
Definition at line 1162 of file testbed_api_hosts.c.
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().
|
static |
Task for checking whether a host is habitable or not.
cls | GNUNET_TESTBED_HostHabitableCheckHandle |
Definition at line 1243 of file testbed_api_hosts.c.
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().
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.
h | the host handle |
op | the operation to queue in the given host's parally overlay connect queue |
Definition at line 1489 of file testbed_api_hosts.c.
References GNUNET_TESTBED_operation_queue_insert_(), h, and op.
Referenced by GNUNET_TESTBED_overlay_connect().
void GNUNET_TESTBED_host_resolve_ | ( | struct GNUNET_TESTBED_Host * | host | ) |
Resolves the hostname of the host to an ip address.
host | the host whose hostname is to be resolved |
Definition at line 1504 of file testbed_api_hosts.c.
References GNUNET_break, GNUNET_free, GNUNET_strdup, hostname, GNUNET_TESTBED_Host::hostname, and simple_resolve().
Referenced by host_habitable_cb().
|
static |
Array of available hosts.
Definition at line 173 of file testbed_api_hosts.c.
Referenced by GNUNET_TESTBED_host_create_with_id(), GNUNET_TESTBED_host_destroy(), GNUNET_TESTBED_host_lookup_by_id_(), and GNUNET_TESTBED_hosts_load_from_file().
|
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_().