Helper binary that is started from a remote controller to start gnunet-service-testbed. More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#include "gnunet_testbed_service.h"
#include "testbed_helper.h"
#include "testbed_api.h"
#include <zlib.h>
Go to the source code of this file.
Data Structures | |
struct | WriteContext |
Context for a single write on a chunk of memory. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) |
Generic logging shortcut. More... | |
#define | LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
Debug logging shorthand. More... | |
Functions | |
static void | shutdown_task (void *cls) |
Task to shut down cleanly. More... | |
static void | write_task (void *cls) |
Task to write to the standard out. More... | |
static void | child_death_task (void *cls) |
Task triggered whenever we receive a SIGCHLD (child process died). More... | |
static int | tokenizer_cb (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 | read_task (void *cls) |
Task to read from stdin. More... | |
static void | run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
Main function that will be run. More... | |
static void | sighandler_child_death () |
Signal handler called for SIGCHLD. More... | |
int | main (int argc, char **argv) |
Main function. More... | |
Variables | |
static struct GNUNET_TESTING_System * | test_system |
Handle to the testing system. More... | |
struct GNUNET_MessageStreamTokenizer * | tokenizer |
Our message stream tokenizer. More... | |
static struct GNUNET_DISK_FileHandle * | stdin_fd |
Disk handle from stdin. More... | |
static struct GNUNET_DISK_FileHandle * | stdout_fd |
Disk handle for stdout. More... | |
static struct GNUNET_OS_Process * | testbed |
The process handle to the testbed service. More... | |
static struct GNUNET_DISK_PipeHandle * | sigpipe |
Pipe used to communicate shutdown via signal. More... | |
static struct GNUNET_SCHEDULER_Task * | read_task_id |
Task identifier for the read task. More... | |
static struct GNUNET_SCHEDULER_Task * | write_task_id |
Task identifier for the write task. More... | |
static struct GNUNET_SCHEDULER_Task * | child_death_task_id |
Task to kill the child. More... | |
static int | done_reading |
Are we done reading messages from stdin? More... | |
static int | status |
Result to return in case we fail. More... | |
Helper binary that is started from a remote controller to start gnunet-service-testbed.
This binary also receives configuration from the remove controller which is put in a temporary location with ports and paths fixed so that gnunet-service-testbed runs without any hurdles.
This helper monitors for three termination events. They are: (1)The stdin of the helper is closed for reading; (2)the helper received SIGTERM/SIGINT; (3)the testbed crashed. In case of events 1 and 2 the helper kills the testbed service. When testbed crashed (event 3), the helper should send a SIGTERM to its own process group; this behaviour will help terminate any child processes (peers) testbed has started and prevents them from leaking and running forever.
Definition in file gnunet-helper-testbed.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log (kind, __VA_ARGS__) |
Generic logging shortcut.
Definition at line 52 of file gnunet-helper-testbed.c.
#define LOG_DEBUG | ( | ... | ) | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
Debug logging shorthand.
Definition at line 57 of file gnunet-helper-testbed.c.
|
static |
Task to shut down cleanly.
cls | NULL |
Definition at line 144 of file gnunet-helper-testbed.c.
References child_death_task_id, WriteContext::data, GNUNET_break, GNUNET_DISK_file_close(), GNUNET_free, GNUNET_MST_destroy(), GNUNET_OK, GNUNET_OS_process_destroy(), GNUNET_OS_process_kill(), GNUNET_OS_process_wait(), GNUNET_SCHEDULER_cancel(), GNUNET_TERM_SIG, GNUNET_TESTING_system_destroy(), GNUNET_YES, LOG_DEBUG, read_task_id, stdin_fd, stdout_fd, test_system, testbed, tokenizer, and write_task_id.
Referenced by run().
|
static |
Task to write to the standard out.
cls | the WriteContext |
Definition at line 197 of file gnunet-helper-testbed.c.
References WriteContext::data, GNUNET_assert, GNUNET_DISK_file_write(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_SCHEDULER_add_write_file(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, WriteContext::length, LOG, WriteContext::pos, stdout_fd, and write_task_id.
Referenced by tokenizer_cb().
|
static |
Task triggered whenever we receive a SIGCHLD (child process died).
cls | closure, NULL if we need to self-restart |
Definition at line 235 of file gnunet-helper-testbed.c.
References child_death_task_id, GNUNET_break, GNUNET_DISK_file_read(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_pipe_handle(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log_strerror, GNUNET_NO, GNUNET_OS_process_destroy(), GNUNET_OS_process_status(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_TERM_SIG, GNUNET_TIME_UNIT_FOREVER_REL, LOG_DEBUG, ret, sigpipe, testbed, and type.
Referenced by tokenizer_cb().
|
static |
Functions with this signature are called whenever a complete message is received by the tokenizer.
Do not call #GNUNET_mst_destroy() in this callback
cls | identification of the client |
message | the actual message |
Definition at line 289 of file gnunet-helper-testbed.c.
References cfg, child_death_task(), child_death_task_id, config, GNUNET_TESTBED_HelperInit::config_size, GNUNET_TESTBED_HelperReply::config_size, WriteContext::data, done_reading, ENV_TESTBED_CONFIG, getenv(), GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_deserialize(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_serialize(), GNUNET_CONFIGURATION_write(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_pipe_handle(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_malloc, GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT, GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY, GNUNET_new, GNUNET_OK, GNUNET_OS_get_libexec_binary_path(), GNUNET_OS_INHERIT_STD_ERR, GNUNET_OS_start_process(), GNUNET_realloc, GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_add_write_file(), GNUNET_SCHEDULER_shutdown(), GNUNET_strdup, GNUNET_strlcpy(), GNUNET_SYSERR, GNUNET_TESTBED_compress_config_(), GNUNET_TESTING_configuration_create(), GNUNET_TESTING_PREFIX, GNUNET_TESTING_system_create(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, GNUNET_TESTBED_HelperReply::header, hostname, GNUNET_TESTBED_HelperInit::hostname_size, WriteContext::length, LOG, LOG_DEBUG, msg, ret, sigpipe, GNUNET_MessageHeader::size, status, stdout_fd, test_system, testbed, GNUNET_TESTBED_HelperInit::trusted_ip_size, GNUNET_MessageHeader::type, write_task(), and write_task_id.
Referenced by run().
|
static |
Task to read from stdin.
cls | NULL |
Definition at line 489 of file gnunet-helper-testbed.c.
References buf, done_reading, GNUNET_break, GNUNET_break_op, GNUNET_DISK_file_read(), GNUNET_MAX_MESSAGE_SIZE, GNUNET_MST_from_buffer(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, LOG_DEBUG, read_task_id, stdin_fd, and tokenizer.
Referenced by run().
|
static |
Main function that will be run.
cls | closure |
args | remaining command-line arguments |
cfgfile | name of the configuration file used (for saving, can be NULL!) |
cfg | configuration |
Definition at line 536 of file gnunet-helper-testbed.c.
References GNUNET_DISK_get_handle_from_native(), GNUNET_MST_create(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_TIME_UNIT_FOREVER_REL, LOG_DEBUG, read_task(), read_task_id, shutdown_task(), stdin_fd, stdout_fd, tokenizer, and tokenizer_cb().
Referenced by main().
|
static |
Signal handler called for SIGCHLD.
Definition at line 557 of file gnunet-helper-testbed.c.
References GNUNET_break, GNUNET_DISK_file_write(), GNUNET_DISK_PIPE_END_WRITE, GNUNET_DISK_pipe_handle(), and sigpipe.
Referenced by main().
int main | ( | int | argc, |
char ** | argv | ||
) |
Main function.
argc | the number of command line arguments |
argv | command line arg array |
Definition at line 581 of file gnunet-helper-testbed.c.
References GNUNET_break, GNUNET_DISK_PF_NONE, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_SIGCHLD, GNUNET_SIGNAL_handler_install(), GNUNET_SIGNAL_handler_uninstall(), options, ret, run(), shc_chld, sighandler_child_death(), sigpipe, and status.
|
static |
Handle to the testing system.
Definition at line 85 of file gnunet-helper-testbed.c.
Referenced by shutdown_task(), system_create_traits(), and tokenizer_cb().
struct GNUNET_MessageStreamTokenizer* tokenizer |
Our message stream tokenizer.
Definition at line 90 of file gnunet-helper-testbed.c.
Referenced by read_task(), run(), and shutdown_task().
|
static |
Disk handle from stdin.
Definition at line 95 of file gnunet-helper-testbed.c.
Referenced by read_task(), run(), and shutdown_task().
|
static |
Disk handle for stdout.
Definition at line 100 of file gnunet-helper-testbed.c.
Referenced by run(), shutdown_task(), tokenizer_cb(), and write_task().
|
static |
The process handle to the testbed service.
Definition at line 105 of file gnunet-helper-testbed.c.
Referenced by child_death_task(), shutdown_task(), and tokenizer_cb().
|
static |
Pipe used to communicate shutdown via signal.
Definition at line 110 of file gnunet-helper-testbed.c.
Referenced by child_death_task(), main(), sighandler_child_death(), and tokenizer_cb().
|
static |
Task identifier for the read task.
Definition at line 115 of file gnunet-helper-testbed.c.
Referenced by read_task(), run(), and shutdown_task().
|
static |
Task identifier for the write task.
Definition at line 120 of file gnunet-helper-testbed.c.
Referenced by shutdown_task(), tokenizer_cb(), and write_task().
|
static |
Task to kill the child.
Definition at line 125 of file gnunet-helper-testbed.c.
Referenced by child_death_task(), shutdown_task(), and tokenizer_cb().
|
static |
Are we done reading messages from stdin?
Definition at line 130 of file gnunet-helper-testbed.c.
Referenced by read_task(), and tokenizer_cb().
|
static |
Result to return in case we fail.
Definition at line 135 of file gnunet-helper-testbed.c.
Referenced by main(), and tokenizer_cb().