GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-helper-testbed.c File Reference

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>
Include dependency graph for gnunet-helper-testbed.c:

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...
 
#define PIPE_CONTROL   GNUNET_NO
 We need pipe control only on WINDOWS. 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_Systemtest_system
 Handle to the testing system. More...
 
struct GNUNET_MessageStreamTokenizertokenizer
 Our message stream tokenizer. More...
 
static struct GNUNET_DISK_FileHandlestdin_fd
 Disk handle from stdin. More...
 
static struct GNUNET_DISK_FileHandlestdout_fd
 Disk handle for stdout. More...
 
static struct GNUNET_OS_Processtestbed
 The process handle to the testbed service. More...
 
static struct GNUNET_DISK_PipeHandlesigpipe
 Pipe used to communicate shutdown via signal. More...
 
static struct GNUNET_SCHEDULER_Taskread_task_id
 Task identifier for the read task. More...
 
static struct GNUNET_SCHEDULER_Taskwrite_task_id
 Task identifier for the write task. More...
 
static struct GNUNET_SCHEDULER_Taskchild_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...
 

Detailed Description

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.

Author
Sree Harsha Totakura sreeh.nosp@m.arsh.nosp@m.a@tot.nosp@m.akur.nosp@m.a.in

Definition in file gnunet-helper-testbed.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log (kind, __VA_ARGS__)

Generic logging shortcut.

Definition at line 52 of file gnunet-helper-testbed.c.

Referenced by tokenizer_cb(), and write_task().

◆ LOG_DEBUG

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

Debug logging shorthand.

Definition at line 58 of file gnunet-helper-testbed.c.

Referenced by child_death_task(), read_task(), run(), shutdown_task(), and tokenizer_cb().

◆ PIPE_CONTROL

#define PIPE_CONTROL   GNUNET_NO

We need pipe control only on WINDOWS.

Definition at line 68 of file gnunet-helper-testbed.c.

Referenced by tokenizer_cb().

Function Documentation

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task to shut down cleanly.

Parameters
clsNULL

Definition at line 156 of file gnunet-helper-testbed.c.

References 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, and LOG_DEBUG.

Referenced by run().

157 {
158  LOG_DEBUG ("Shutting down\n");
159  if (NULL != testbed)
160  {
161  LOG_DEBUG ("Killing testbed\n");
163  }
164  if (NULL != read_task_id)
165  {
167  read_task_id = NULL;
168  }
169  if (NULL != write_task_id)
170  {
171  struct WriteContext *wc;
172 
174  write_task_id = NULL;
175  GNUNET_free (wc->data);
176  GNUNET_free (wc);
177  }
178  if (NULL != child_death_task_id)
179  {
181  child_death_task_id = NULL;
182  }
183  if (NULL != stdin_fd)
185  if (NULL != stdout_fd)
188  tokenizer = NULL;
189  if (NULL != testbed)
190  {
193  testbed = NULL;
194  }
195  if (NULL != test_system)
196  {
198  test_system = NULL;
199  }
200 }
static struct GNUNET_OS_Process * testbed
The process handle to the testbed service.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:364
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_DISK_FileHandle * stdout_fd
Disk handle for stdout.
static struct GNUNET_DISK_FileHandle * stdin_fd
Disk handle from stdin.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:413
static struct GNUNET_TESTING_System * test_system
Handle to the testing system.
static struct GNUNET_SCHEDULER_Task * write_task_id
Task identifier for the write task.
#define LOG_DEBUG(...)
Debug logging shorthand.
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:527
static struct GNUNET_SCHEDULER_Task * read_task_id
Task identifier for the read task.
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:1762
struct GNUNET_MessageStreamTokenizer * tokenizer
Our message stream tokenizer.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:282
#define GNUNET_free(ptr)
Wrapper around free.
void * data
The data to write.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:251
static struct GNUNET_SCHEDULER_Task * child_death_task_id
Task to kill the child.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Context for a single write on a chunk of memory.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_task()

static void write_task ( void *  cls)
static

Task to write to the standard out.

Parameters
clsthe WriteContext

Definition at line 209 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, and WriteContext::pos.

Referenced by tokenizer_cb().

210 {
211  struct WriteContext *wc = cls;
212  ssize_t bytes_wrote;
213 
214  GNUNET_assert (NULL != wc);
215  write_task_id = NULL;
216  bytes_wrote =
218  wc->length - wc->pos);
219  if (GNUNET_SYSERR == bytes_wrote)
220  {
222  "Cannot reply back configuration\n");
223  GNUNET_free (wc->data);
224  GNUNET_free (wc);
225  return;
226  }
227  wc->pos += bytes_wrote;
228  if (wc->pos == wc->length)
229  {
230  GNUNET_free (wc->data);
231  GNUNET_free (wc);
232  return;
233  }
234  write_task_id =
236  stdout_fd,
237  &write_task, wc);
238 }
size_t pos
The current position from where the write operation should begin.
#define LOG(kind,...)
Generic logging shortcut.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1675
static struct GNUNET_DISK_FileHandle * stdout_fd
Disk handle for stdout.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:1049
static void write_task(void *cls)
Task to write to the standard out.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static struct GNUNET_SCHEDULER_Task * write_task_id
Task identifier for the write task.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
size_t length
The length of the data.
#define GNUNET_free(ptr)
Wrapper around free.
void * data
The data to write.
Context for a single write on a chunk of memory.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ child_death_task()

static void child_death_task ( void *  cls)
static

Task triggered whenever we receive a SIGCHLD (child process died).

Parameters
clsclosure, NULL if we need to self-restart

Definition at line 248 of file gnunet-helper-testbed.c.

References 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, PLIBC_KILL, ret, and type.

Referenced by tokenizer_cb().

249 {
250  const struct GNUNET_DISK_FileHandle *pr;
251  char c[16];
253  unsigned long code;
254  int ret;
255 
257  child_death_task_id = NULL;
258  /* consume the signal */
259  GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
260  LOG_DEBUG ("Got SIGCHLD\n");
261  if (NULL == testbed)
262  {
263  GNUNET_break (0);
264  return;
265  }
267  (ret = GNUNET_OS_process_status (testbed, &type, &code)));
268  if (GNUNET_NO != ret)
269  {
271  testbed = NULL;
272  /* Send SIGTERM to our process group */
273  if (0 != PLIBC_KILL (0, GNUNET_TERM_SIG))
274  {
276  GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */
277  }
278  return;
279  }
280  LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n");
283  pr, &child_death_task, NULL);
284 }
static struct GNUNET_OS_Process * testbed
The process handle to the testbed service.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:364
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:881
int GNUNET_OS_process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Retrieve the status of a process, waiting on it if dead.
Definition: os_priority.c:1719
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1643
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:2641
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
GNUNET_OS_ProcessStatusType
Process status types.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
The reading-end of a pipe.
#define LOG_DEBUG(...)
Debug logging shorthand.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define PLIBC_KILL(p, s)
Definition: plibc.h:659
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
static void child_death_task(void *cls)
Task triggered whenever we receive a SIGCHLD (child process died).
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:282
Handle used to access files (and pipes).
static struct GNUNET_SCHEDULER_Task * child_death_task_id
Task to kill the child.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tokenizer_cb()

static int tokenizer_cb ( 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_mst_destroy() in this callback

Parameters
clsidentification of the client
messagethe actual message
Returns
GNUNET_OK on success, GNUNET_NO to stop further processing (no error) GNUNET_SYSERR to stop further processing with error

Definition at line 300 of file gnunet-helper-testbed.c.

References cfg, child_death_task(), 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_WARNING, GNUNET_free, GNUNET_free_non_null, 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, PIPE_CONTROL, GNUNET_MessageHeader::size, status, GNUNET_TESTBED_HelperInit::trusted_ip_size, GNUNET_MessageHeader::type, and write_task().

Referenced by run().

302 {
303  const struct GNUNET_TESTBED_HelperInit *msg;
304  struct GNUNET_TESTBED_HelperReply *reply;
306  struct WriteContext *wc;
307  char *binary;
308  char *trusted_ip;
309  char *hostname;
310  char *config;
311  char *xconfig;
312  char *evstr;
313  //char *str;
314  size_t config_size;
315  uLongf ul_config_size;
316  size_t xconfig_size;
317  uint16_t trusted_ip_size;
318  uint16_t hostname_size;
319  uint16_t msize;
320 
321  msize = ntohs (message->size);
322  if ((sizeof (struct GNUNET_TESTBED_HelperInit) >= msize) ||
323  (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs (message->type)))
324  {
326  "Received unexpected message -- exiting\n");
327  goto error;
328  }
329  msg = (const struct GNUNET_TESTBED_HelperInit *) message;
330  trusted_ip_size = ntohs (msg->trusted_ip_size);
331  trusted_ip = (char *) &msg[1];
332  if ('\0' != trusted_ip[trusted_ip_size])
333  {
334  LOG (GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n");
335  goto error;
336  }
337  hostname_size = ntohs (msg->hostname_size);
338  if ((sizeof (struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1 +
339  hostname_size) >= msize)
340  {
341  GNUNET_break (0);
342  LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n");
343  goto error;
344  }
345  ul_config_size = (uLongf) ntohs (msg->config_size);
346  config = GNUNET_malloc (ul_config_size);
347  xconfig_size =
348  ntohs (message->size) - (trusted_ip_size + 1 +
349  sizeof (struct GNUNET_TESTBED_HelperInit));
350  if (Z_OK !=
351  uncompress ((Bytef *) config, &ul_config_size,
352  (const Bytef *) (trusted_ip + trusted_ip_size + 1 +
353  hostname_size), (uLongf) xconfig_size))
354  {
356  "Error while uncompressing config -- exiting\n");
357  GNUNET_free (config);
358  goto error;
359  }
361  if (GNUNET_OK !=
363  config,
364  ul_config_size,
365  NULL))
366  {
368  "Unable to deserialize config -- exiting\n");
369  GNUNET_free (config);
370  goto error;
371  }
372  GNUNET_free (config);
373  hostname = NULL;
374  if (0 != hostname_size)
375  {
376  hostname = GNUNET_malloc (hostname_size + 1);
377  GNUNET_strlcpy (hostname,
378  ((char *) &msg[1]) + trusted_ip_size + 1,
379  hostname_size + 1);
380  }
381  /* unset GNUNET_TESTING_PREFIX if present as it is more relevant for testbed */
382  evstr = getenv (GNUNET_TESTING_PREFIX);
383  if (NULL != evstr)
384  {
385  /* unsetting the variable will invalidate the pointer! */
386  evstr = GNUNET_strdup (evstr);
387 #ifdef WINDOWS
388  GNUNET_break (0 != SetEnvironmentVariable (GNUNET_TESTING_PREFIX, NULL));
389 #else
390  GNUNET_break (0 == unsetenv (GNUNET_TESTING_PREFIX));
391 #endif
392  }
393  test_system =
394  GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostname,
395  NULL);
396  if (NULL != evstr)
397  {
398 #ifdef WINDOWS
399  GNUNET_assert (0 != SetEnvironmentVariable (GNUNET_TESTING_PREFIX,
400  evstr));
401 #else
402  char *evar;
403 
404  GNUNET_asprintf (&evar,
405  GNUNET_TESTING_PREFIX "=%s",
406  evstr);
407  GNUNET_assert (0 == putenv (evar)); /* consumes 'evar',
408  see putenv(): becomes part of envrionment! */
409 #endif
410  GNUNET_free (evstr);
411  evstr = NULL;
412  }
413  GNUNET_free_non_null (hostname);
414  hostname = NULL;
415  GNUNET_assert (NULL != test_system);
420  "DEFAULTCONFIG",
421  &config));
422  if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config))
423  {
425  "Unable to write config file: %s -- exiting\n", config);
427  GNUNET_free (config);
428  goto error;
429  }
430  LOG_DEBUG ("Staring testbed with config: %s\n", config);
431  binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-testbed");
432  {
433  char *evar;
434 
435  /* expose testbed configuration through env variable */
436  GNUNET_asprintf (&evar,
437  "%s=%s",
439  config);
440  GNUNET_assert (0 == putenv (evar)); /* consumes 'evar',
441  see putenv(): becomes part of envrionment! */
442  evstr = NULL;
443  }
444  testbed =
446  GNUNET_OS_INHERIT_STD_ERR /*verbose? */ ,
447  NULL, NULL, NULL,
448  binary,
449  "gnunet-service-testbed",
450  "-c", config,
451  NULL);
452  GNUNET_free (binary);
453  GNUNET_free (config);
454  if (NULL == testbed)
455  {
457  "Error starting gnunet-service-testbed -- exiting\n");
459  goto error;
460  }
462  config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
464  cfg = NULL;
465  xconfig_size =
466  GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig);
467  GNUNET_free (config);
468  wc = GNUNET_new (struct WriteContext);
469  wc->length = xconfig_size + sizeof (struct GNUNET_TESTBED_HelperReply);
470  reply = GNUNET_realloc (xconfig, wc->length);
471  memmove (&reply[1], reply, xconfig_size);
473  reply->header.size = htons ((uint16_t) wc->length);
474  reply->config_size = htons ((uint16_t) config_size);
475  wc->data = reply;
476  write_task_id =
478  stdout_fd,
479  &write_task, wc);
484  &child_death_task, NULL);
485  return GNUNET_OK;
486 
487 error:
490  return GNUNET_SYSERR;
491 }
When this flag is set, the child process will inherit stderr of the parent.
Definition: gnunet_os_lib.h:92
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct GNUNET_OS_Process * testbed
The process handle to the testbed service.
int GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
#define LOG(kind,...)
Generic logging shortcut.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_OS_Process * GNUNET_OS_start_process(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
Start a process.
Definition: os_priority.c:1400
#define GNUNET_TESTING_PREFIX
The environmental variable, if set, that dictates where testing should place generated peer configura...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1675
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1643
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_DISK_FileHandle * stdout_fd
Disk handle for stdout.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
Initialization message for gnunet-helper-testbed to start testbed service.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_TESTING_configuration_create(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new configuration using the given configuration as a template; ports and paths will be modif...
Definition: testing.c:1113
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:2641
static int status
Result to return in case we fail.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
static void write_task(void *cls)
Task to write to the standard out.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static const struct GNUNET_CONFIGURATION_Handle * config
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
The reading-end of a pipe.
static struct GNUNET_TESTING_System * test_system
Handle to the testing system.
uint16_t hostname_size
The hostname size excluding the NULL termination character - strlen (hostname); cannot be zero...
Reply message from helper process.
static struct GNUNET_SCHEDULER_Task * write_task_id
Task identifier for the write task.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
#define GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT
The initialization message towards gnunet-testbed-helper.
#define LOG_DEBUG(...)
Debug logging shorthand.
struct GNUNET_TESTING_System * GNUNET_TESTING_system_create(const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services)
Create a system handle.
Definition: testing.c:449
#define GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY
The reply message from gnunet-testbed-helper.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY.
char * getenv()
#define PIPE_CONTROL
We need pipe control only on WINDOWS.
size_t GNUNET_TESTBED_compress_config_(const char *config, size_t size, char **xconfig)
Compresses given configuration using zlib compress.
Definition: testbed_api.c:1761
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
static char * hostname
Our hostname; we give this to all the peers we start.
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
configuration data
Definition: configuration.c:85
uint16_t trusted_ip_size
The controller hostname size excluding the NULL termination character - strlen (hostname); cannot be ...
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
static void child_death_task(void *cls)
Task triggered whenever we receive a SIGCHLD (child process died).
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *basedir)
De-serializes configuration.
size_t length
The length of the data.
static int done_reading
Are we done reading messages from stdin?
uint16_t config_size
The size of the uncompressed configuration.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
uint16_t config_size
Size of the uncompressed configuration.
#define ENV_TESTBED_CONFIG
The environmental variable which when available refers to the configuration file the local testbed co...
Definition: testbed.h:817
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
void * data
The data to write.
static struct GNUNET_SCHEDULER_Task * child_death_task_id
Task to kill the child.
Context for a single write on a chunk of memory.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_task()

static void read_task ( void *  cls)
static

Task to read from stdin.

Parameters
clsNULL

Definition at line 500 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, and LOG_DEBUG.

Referenced by run().

501 {
503  ssize_t sread;
504 
505  read_task_id = NULL;
507  buf,
508  sizeof (buf));
509  if ( (GNUNET_SYSERR == sread) ||
510  (0 == sread) )
511  {
512  LOG_DEBUG ("STDIN closed\n");
514  return;
515  }
516  if (GNUNET_YES == done_reading)
517  {
518  /* didn't expect any more data! */
519  GNUNET_break_op (0);
521  return;
522  }
523  LOG_DEBUG ("Read %u bytes\n",
524  (unsigned int) sread);
525  /* FIXME: could introduce a GNUNET_MST_read2 to read
526  directly from 'stdin_fd' and save a memcpy() here */
527  if (GNUNET_OK !=
529  buf,
530  sread,
531  GNUNET_NO,
532  GNUNET_NO))
533  {
534  GNUNET_break (0);
536  return;
537  }
538  read_task_id /* No timeout while reading */
540  stdin_fd,
541  &read_task,
542  NULL);
543 }
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:881
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1643
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_DISK_FileHandle * stdin_fd
Disk handle from stdin.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static char buf[2048]
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
int GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
Definition: mst.c:116
#define LOG_DEBUG(...)
Debug logging shorthand.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static struct GNUNET_SCHEDULER_Task * read_task_id
Task identifier for the read task.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GNUNET_MessageStreamTokenizer * tokenizer
Our message stream tokenizer.
#define GNUNET_YES
Definition: gnunet_common.h:80
static int done_reading
Are we done reading messages from stdin?
static void read_task(void *cls)
Task to read from stdin.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 555 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(), shutdown_task(), and tokenizer_cb().

Referenced by main().

559 {
560  LOG_DEBUG ("Starting testbed helper...\n");
564  read_task_id =
566  stdin_fd,
567  &read_task, NULL);
569  NULL);
570 }
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1643
static struct GNUNET_DISK_FileHandle * stdout_fd
Disk handle for stdout.
static struct GNUNET_DISK_FileHandle * stdin_fd
Disk handle from stdin.
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...
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:87
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void shutdown_task(void *cls)
Task to shut down cleanly.
#define LOG_DEBUG(...)
Debug logging shorthand.
static struct GNUNET_SCHEDULER_Task * read_task_id
Task identifier for the read task.
struct GNUNET_MessageStreamTokenizer * tokenizer
Our message stream tokenizer.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_native(FILE *fd)
Get a handle from a native FD.
Definition: disk.c:1970
static void read_task(void *cls)
Task to read from stdin.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sighandler_child_death()

static void sighandler_child_death ( )
static

Signal handler called for SIGCHLD.

Definition at line 577 of file gnunet-helper-testbed.c.

References GNUNET_break, GNUNET_DISK_file_write(), GNUNET_DISK_PIPE_END_WRITE, and GNUNET_DISK_pipe_handle().

Referenced by main().

578 {
579  static char c;
580  int old_errno; /* back-up errno */
581 
582  old_errno = errno;
583  GNUNET_break (1 ==
586  &c, sizeof (c)));
587  errno = old_errno;
588 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:2641
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:1049
The writing-end of a pipe.
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Main function.

Parameters
argcthe number of command line arguments
argvcommand line arg array
Returns
return code

Definition at line 599 of file gnunet-helper-testbed.c.

References GNUNET_break, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_GETOPT_OPTION_END, GNUNET_NO, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_SIGCHLD, GNUNET_SIGNAL_handler_install(), GNUNET_SIGNAL_handler_uninstall(), ret, run(), sighandler_child_death(), and status.

601 {
602  struct GNUNET_SIGNAL_Context *shc_chld;
605  };
606  int ret;
607 
608  status = GNUNET_OK;
609  if (NULL == (sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO,
610  GNUNET_NO, GNUNET_NO)))
611  {
612  GNUNET_break (0);
613  return 1;
614  }
617  ret = GNUNET_PROGRAM_run (argc, argv,
618  "gnunet-helper-testbed",
619  "Helper for starting gnunet-service-testbed",
620  options,
621  &run,
622  NULL);
624  shc_chld = NULL;
626  if (GNUNET_OK != ret)
627  return 1;
628  return (GNUNET_OK == status) ? 0 : 1;
629 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define GNUNET_SIGCHLD
Definition: platform.h:46
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal hander.
Definition: signal.c:99
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static int status
Result to return in case we fail.
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(int blocking_read, int blocking_write, int inherit_read, int inherit_write)
Creates an interprocess channel.
Definition: disk.c:2289
struct GNUNET_SIGNAL_Context * GNUNET_SIGNAL_handler_install(int signal, GNUNET_SIGNAL_Handler handler)
Install a signal handler that will be run if the given signal is received.
Definition: signal.c:59
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:2603
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
int GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:361
static void sighandler_child_death()
Signal handler called for SIGCHLD.
Here is the call graph for this function:

Variable Documentation

◆ test_system

struct GNUNET_TESTING_System* test_system
static

Handle to the testing system.

Definition at line 97 of file gnunet-helper-testbed.c.

◆ tokenizer

struct GNUNET_MessageStreamTokenizer* tokenizer

Our message stream tokenizer.

Definition at line 102 of file gnunet-helper-testbed.c.

◆ stdin_fd

struct GNUNET_DISK_FileHandle* stdin_fd
static

Disk handle from stdin.

Definition at line 107 of file gnunet-helper-testbed.c.

◆ stdout_fd

struct GNUNET_DISK_FileHandle* stdout_fd
static

Disk handle for stdout.

Definition at line 112 of file gnunet-helper-testbed.c.

◆ testbed

struct GNUNET_OS_Process* testbed
static

The process handle to the testbed service.

Definition at line 117 of file gnunet-helper-testbed.c.

◆ sigpipe

struct GNUNET_DISK_PipeHandle* sigpipe
static

Pipe used to communicate shutdown via signal.

Definition at line 122 of file gnunet-helper-testbed.c.

◆ read_task_id

struct GNUNET_SCHEDULER_Task* read_task_id
static

Task identifier for the read task.

Definition at line 127 of file gnunet-helper-testbed.c.

◆ write_task_id

struct GNUNET_SCHEDULER_Task* write_task_id
static

Task identifier for the write task.

Definition at line 132 of file gnunet-helper-testbed.c.

◆ child_death_task_id

struct GNUNET_SCHEDULER_Task* child_death_task_id
static

Task to kill the child.

Definition at line 137 of file gnunet-helper-testbed.c.

◆ done_reading

int done_reading
static

Are we done reading messages from stdin?

Definition at line 142 of file gnunet-helper-testbed.c.

Referenced by read_task(), and tokenizer_cb().

◆ status

int status
static

Result to return in case we fail.

Definition at line 147 of file gnunet-helper-testbed.c.

Referenced by main(), and tokenizer_cb().