GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
gnunet-cmds-helper.c File Reference

Helper binary that is started from a remote interpreter loop to start a local interpreter loop. 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 "gnunet_testing_plugin.h"
#include <zlib.h>
Include dependency graph for gnunet-cmds-helper.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 
struct  NodeIdentifier
 
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 NODE_BASE_IP   "192.168.15."
 
#define ROUTER_BASE_IP   "92.68.150."
 

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 write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
 Task triggered whenever we receive a SIGCHLD (child process died). More...
 
static int tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
 Function to run the test cases. 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

struct Pluginplugin
 
static struct GNUNET_TESTING_Systemtest_system
 The process handle to the testbed service. 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_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 interpreter loop to start a local interpreter loop.

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 local loop crashed. In case of events 1 and 2 the helper kills the interpreter loop. When the interpreter loop crashed (event 3), the helper should send a SIGTERM to its own process group; this behaviour will help terminate any child processes the loop has started and prevents them from leaking and running forever.

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

Definition in file gnunet-cmds-helper.c.

Macro Definition Documentation

◆ LOG

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

Generic logging shortcut.

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

Referenced by main(), read_task(), shutdown_task(), tokenizer_cb(), write_message(), and write_task().

◆ LOG_DEBUG

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

Debug logging shorthand.

Definition at line 57 of file gnunet-cmds-helper.c.

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

◆ NODE_BASE_IP

#define NODE_BASE_IP   "192.168.15."

Definition at line 59 of file gnunet-cmds-helper.c.

Referenced by tokenizer_cb().

◆ ROUTER_BASE_IP

#define ROUTER_BASE_IP   "92.68.150."

Definition at line 61 of file gnunet-cmds-helper.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 187 of file gnunet-cmds-helper.c.

References WriteContext::data, GNUNET_DISK_file_close(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_MST_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_TESTING_system_destroy(), GNUNET_YES, LOG, and LOG_DEBUG.

Referenced by run().

188 {
189 
190  LOG_DEBUG ("Shutting down.\n");
192  "Shutting down tokenizer!\n");
193 
194  if (NULL != read_task_id)
195  {
197  read_task_id = NULL;
198  }
199  if (NULL != write_task_id)
200  {
201  struct WriteContext *wc;
202 
204  write_task_id = NULL;
205  GNUNET_free (wc->data);
206  GNUNET_free (wc);
207  }
208  if (NULL != child_death_task_id)
209  {
211  child_death_task_id = NULL;
212  }
213  if (NULL != stdin_fd)
215  if (NULL != stdout_fd)
218  tokenizer = NULL;
219 
220  if (NULL != test_system)
221  {
223  test_system = NULL;
224  }
225 }
void * data
The data to write.
static struct GNUNET_SCHEDULER_Task * read_task_id
Task identifier for the read task.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1305
static struct GNUNET_SCHEDULER_Task * child_death_task_id
Task to kill the child.
static struct GNUNET_TESTING_System * test_system
The process handle to the testbed service.
static struct GNUNET_SCHEDULER_Task * write_task_id
Task identifier for the write task.
static struct GNUNET_DISK_FileHandle * stdout_fd
Disk handle for stdout.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:411
#define LOG_DEBUG(...)
Debug logging shorthand.
#define LOG(kind,...)
Generic logging shortcut.
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:527
static struct GNUNET_DISK_FileHandle * stdin_fd
Disk handle from stdin.
struct GNUNET_MessageStreamTokenizer * tokenizer
Our message stream tokenizer.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
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 234 of file gnunet-cmds-helper.c.

References WriteContext::data, GNUNET_assert, GNUNET_DISK_file_write(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_SCHEDULER_add_write_file(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, WriteContext::length, LOG, WriteContext::pos, and Plugin::write_task.

235 {
236  struct WriteContext *wc = cls;
237  ssize_t bytes_wrote;
238 
240  "Writing data!\n");
241 
242  GNUNET_assert (NULL != wc);
243  write_task_id = NULL;
244  bytes_wrote = GNUNET_DISK_file_write (stdout_fd,
245  wc->data + wc->pos,
246  wc->length - wc->pos);
247  if (GNUNET_SYSERR == bytes_wrote)
248  {
250  "Cannot reply back successful initialization\n");
251  GNUNET_free (wc->data);
252  GNUNET_free (wc);
253  return;
254  }
255  wc->pos += bytes_wrote;
256  if (wc->pos == wc->length)
257  {
258  GNUNET_free (wc->data);
259  GNUNET_free (wc);
261  "Written successfully!\n");
262  return;
263  }
265  "Written data!\n");
267  stdout_fd,
268  &write_task,
269  wc);
270 }
void * data
The data to write.
size_t pos
The current position from where the write operation should begin.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void write_task(void *cls)
Task to write to the standard out.
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:1700
static struct GNUNET_SCHEDULER_Task * write_task_id
Task identifier for the write task.
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:686
#define LOG(kind,...)
Generic logging shortcut.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
size_t length
The length of the data.
#define GNUNET_free(ptr)
Wrapper around free.
Context for a single write on a chunk of memory.
Here is the call graph for this function:

◆ write_message()

static void write_message ( struct GNUNET_MessageHeader message,
size_t  msg_length 
)
static

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

Parameters
clsclosure, NULL if we need to self-restart

Definition at line 301 of file gnunet-cmds-helper.c.

References WriteContext::data, GNUNET_ERROR_TYPE_ERROR, GNUNET_new, GNUNET_SCHEDULER_add_write_file(), GNUNET_TIME_UNIT_FOREVER_REL, WriteContext::length, LOG, and Plugin::write_task.

Referenced by tokenizer_cb().

302 {
303  struct WriteContext *wc;
304 
306  "enter write_message!\n");
307  wc = GNUNET_new (struct WriteContext);
308  wc->length = msg_length;
309  wc->data = message;
312  stdout_fd,
313  &write_task,
314  wc);
316  "leave write_message!\n");
317 }
void * data
The data to write.
static void write_task(void *cls)
Task to write to the standard out.
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:1700
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_SCHEDULER_Task * write_task_id
Task identifier for the write task.
static struct GNUNET_DISK_FileHandle * stdout_fd
Disk handle for stdout.
#define LOG(kind,...)
Generic logging shortcut.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
size_t length
The length of the data.
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:

◆ tokenizer_cb()

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

Function to run the test cases.

Parameters
clsplugin to use. 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 359 of file gnunet-cmds-helper.c.

References Plugin::api, Plugin::global_n, NodeIdentifier::global_n, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_malloc, GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED, GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT, GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY, GNUNET_new, GNUNET_OK, GNUNET_OS_get_libexec_binary_path(), GNUNET_PLUGIN_load(), GNUNET_SCHEDULER_shutdown(), GNUNET_strdup, GNUNET_strlcpy(), GNUNET_SYSERR, GNUNET_CMDS_HelperReply::header, Plugin::library_name, Plugin::local_m, NodeIdentifier::local_m, LOG, Plugin::m, NodeIdentifier::m, msg, Plugin::n, NodeIdentifier::n, NODE_BASE_IP, Plugin::node_ip, Plugin::plugin_name, GNUNET_CMDS_HelperInit::plugin_name_size, ROUTER_BASE_IP, GNUNET_MessageHeader::size, status, GNUNET_MessageHeader::type, and write_message().

Referenced by run().

360 {
361  struct NodeIdentifier *ni = cls;
362  const struct GNUNET_CMDS_HelperInit *msg;
363  struct GNUNET_CMDS_HelperReply *reply;
364  char *binary;
365  char *plugin_name;
366  size_t plugin_name_size;
367  uint16_t msize;
368  size_t msg_length;
369  char *router_ip;
370  char *node_ip;
371 
373  "tokenizer \n");
374 
375  msize = ntohs (message->size);
376  if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type))
377  {
378  msg = (const struct GNUNET_CMDS_HelperInit *) message;
379  plugin_name_size = ntohs (msg->plugin_name_size);
380  if ((sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_size) > msize)
381  {
382  GNUNET_break (0);
384  "Received unexpected message -- exiting\n");
385  goto error;
386  }
387  plugin_name = GNUNET_malloc (plugin_name_size + 1);
388  GNUNET_strlcpy (plugin_name,
389  ((char *) &msg[1]),
390  plugin_name_size + 1);
391 
392  binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd");
393 
395  "plugin_name: %s \n",
396  plugin_name);
397 
398  // cmd_binary_process = GNUNET_OS_start_process (
399  /*GNUNET_OS_INHERIT_STD_ERR verbose? ,
400  NULL,
401  NULL,
402  NULL,
403  binary,
404  plugin_name,
405  ni->global_n,
406  ni->local_m,
407  ni->n,
408  ni->m,
409  NULL);*/
410 
411  plugin = GNUNET_new (struct Plugin);
412  plugin->api = GNUNET_PLUGIN_load (plugin_name,
413  NULL);
414  plugin->library_name = GNUNET_strdup (basename(plugin_name));
415 
416  plugin->global_n = ni->global_n;
417  plugin->local_m = ni->local_m;
418  plugin->n = ni->n;
419  plugin->m = ni->m;
420 
421  router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m)
422  + 1);
423  strcpy (router_ip, ROUTER_BASE_IP);
424  strcat (router_ip, plugin->m);
425 
426  node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1);
427  strcat (node_ip, NODE_BASE_IP);
428  strcat (node_ip, plugin->n);
429 
430  plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
431  plugin->n, plugin->local_m);
432 
434  "We got here!\n");
435 
436  /*if (NULL == cmd_binary_process)
437  {
438  LOG (GNUNET_ERROR_TYPE_ERROR,
439  "Starting plugin failed!\n");
440  return GNUNET_SYSERR;
441  }*/
442 
444  "We got here 2!\n");
445 
447  "global_n: %s local_n: %s n: %s m: %s.\n",
448  ni->global_n,
449  ni->local_m,
450  ni->n,
451  ni->m);
452 
454  "We got here 3!\n");
455 
456  GNUNET_free (binary);
457 
458  // done_reading = GNUNET_YES;
459 
460  msg_length = sizeof(struct GNUNET_CMDS_HelperReply);
461  reply = GNUNET_new (struct GNUNET_CMDS_HelperReply);
463  reply->header.size = htons ((uint16_t) msg_length);
464 
466  "We got here 4!\n");
467 
468  write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
469 
471  "We got here 5!\n");
472 
473  /*child_death_task_id = GNUNET_SCHEDULER_add_read_file (
474  GNUNET_TIME_UNIT_FOREVER_REL,
475  GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
476  &child_death_task,
477  NULL);*/
478  return GNUNET_OK;
479  }
481  message->type))
482  {
483  plugin->api->all_peers_started ();
484  return GNUNET_OK;
485  }
486  else
487  {
488  LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n");
489  goto error;
490  }
491 
492 
493  error:
496  "tokenizer shutting down!\n");
498  return GNUNET_SYSERR;
499 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
char * m
Definition: gnunet-cmd.c:68
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY
The reply message from gnunet-cmds-helper.
char * library_name
Name of the shared library.
Definition: block.c:42
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Initialization message for gnunet-cmds-testbed to start cmd binary.
static void write_message(struct GNUNET_MessageHeader *message, size_t msg_length)
Task triggered whenever we receive a SIGCHLD (child process died).
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define LOG(kind,...)
Generic logging shortcut.
char * global_n
Definition: gnunet-cmd.c:62
Reply message from cmds helper process.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT
The initialization message towards gnunet-cmds-helper.
#define ROUTER_BASE_IP
char * n
Definition: gnunet-cmd.c:66
char * local_m
Definition: gnunet-cmd.c:64
Handle for a plugin.
Definition: block.c:37
static int status
Result to return in case we fail.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED
#define NODE_BASE_IP
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 ...
struct Plugin * plugin
Header for all communications.
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:217
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
Definition: strings.c:162
static char * plugin_name
Name of our plugin.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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 508 of file gnunet-cmds-helper.c.

References buf, done_reading, GNUNET_break, GNUNET_break_op, GNUNET_DISK_file_read(), GNUNET_ERROR_TYPE_ERROR, 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, LOG_DEBUG, and Plugin::read_task.

509 {
511  ssize_t sread;
512 
513  read_task_id = NULL;
514  sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof(buf));
515  if ((GNUNET_SYSERR == sread) || (0 == sread))
516  {
517  LOG_DEBUG ("STDIN closed\n");
519  "tokenizer shutting down during reading!\n");
521  return;
522  }
523  if (GNUNET_YES == done_reading)
524  {
525  /* didn't expect any more data! */
526  GNUNET_break_op (0);
528  "tokenizer shutting down during reading, didn't expect any more data!\n");
530  return;
531  }
532  LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread);
534  "Read %u bytes\n", (unsigned int) sread);
535  /* FIXME: could introduce a GNUNET_MST_read2 to read
536  directly from 'stdin_fd' and save a memcpy() here */
537  if (GNUNET_OK !=
539  {
540  GNUNET_break (0);
542  "tokenizer shutting down during reading, writing to buffer failed!\n");
544  return;
545  }
546  read_task_id /* No timeout while reading */
548  stdin_fd,
549  &read_task,
550  NULL);
551 }
static struct GNUNET_SCHEDULER_Task * read_task_id
Task identifier for the read task.
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:622
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:1667
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define LOG_DEBUG(...)
Debug logging shorthand.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static char buf[2048]
#define LOG(kind,...)
Generic logging shortcut.
#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:114
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
static struct GNUNET_DISK_FileHandle * stdin_fd
Disk handle from stdin.
struct GNUNET_MessageStreamTokenizer * tokenizer
Our message stream tokenizer.
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:

◆ 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 563 of file gnunet-cmds-helper.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, Plugin::read_task, shutdown_task(), and tokenizer_cb().

Referenced by main().

567 {
568  struct NodeIdentifier *ni = cls;
569 
570  LOG_DEBUG ("Starting interpreter loop helper...\n");
571 
576  stdin_fd,
577  &read_task,
578  NULL);
580 }
static struct GNUNET_SCHEDULER_Task * read_task_id
Task identifier for the read task.
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:1331
static int tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message)
Function to run the test cases.
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:1667
static struct GNUNET_DISK_FileHandle * stdout_fd
Disk handle for stdout.
#define LOG_DEBUG(...)
Debug logging shorthand.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:85
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static struct GNUNET_DISK_FileHandle * stdin_fd
Disk handle from stdin.
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:1343
static void shutdown_task(void *cls)
Task to shut down cleanly.
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 ( void  )
static

Signal handler called for SIGCHLD.

Definition at line 587 of file gnunet-cmds-helper.c.

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

Referenced by main().

588 {
589  static char c;
590  int old_errno; /* back-up errno */
591 
592  old_errno = errno;
593  GNUNET_break (
594  1 ==
597  &c,
598  sizeof(c)));
599  errno = old_errno;
600 }
#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:1615
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:686
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
The writing-end of a pipe.
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 611 of file gnunet-cmds-helper.c.

References NodeIdentifier::global_n, GNUNET_break, GNUNET_DISK_PF_NONE, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_log_setup(), GNUNET_new, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_SIGCHLD, GNUNET_SIGNAL_handler_install(), GNUNET_SIGNAL_handler_uninstall(), NodeIdentifier::local_m, LOG, NodeIdentifier::m, NodeIdentifier::n, ret, run(), shc_chld, sighandler_child_death(), and status.

612 {
613  struct NodeIdentifier *ni;
617  int ret;
618 
619  GNUNET_log_setup ("gnunet-cmds-helper",
620  "DEBUG",
621  NULL);
622  ni = GNUNET_new (struct NodeIdentifier);
623  ni->global_n = argv[1];
624  ni->local_m = argv[2];
625  ni->n = argv[3];
626  ni->m = argv[4];
627 
629  "global_n: %s local_n: %s n: %s m: %s.\n",
630  ni->global_n,
631  ni->local_m,
632  ni->n,
633  ni->m);
634 
635  status = GNUNET_OK;
636  if (NULL ==
638  {
639  GNUNET_break (0);
640  return 1;
641  }
642  shc_chld =
644  ret = GNUNET_PROGRAM_run (argc,
645  argv,
646  "gnunet-cmds-helper",
647  "Helper for starting a local interpreter loop",
648  options,
649  &run,
650  ni);
652  "run finished\n");
654  shc_chld = NULL;
656  GNUNET_free (ni);
657  if (GNUNET_OK != ret)
658  return 1;
659  return (GNUNET_OK == status) ? 0 : 1;
660 }
static struct GNUNET_SIGNAL_Context * shc_chld
No special options, use non-blocking read/write operations.
enum GNUNET_GenericReturnValue 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:360
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define GNUNET_SIGCHLD
Definition: platform.h:42
static void sighandler_child_death()
Signal handler called for SIGCHLD.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal handler.
Definition: signal.c:77
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Definition of a command line option.
#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
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1584
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
#define LOG(kind,...)
Generic logging shortcut.
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition: disk.c:1441
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:51
static int status
Result to return in case we fail.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

Variable Documentation

◆ plugin

struct Plugin* plugin

Definition at line 123 of file gnunet-cmds-helper.c.

Referenced by __attribute__(), ack_message_sent(), ack_proc(), add_plugin(), address_notification(), append_port(), broadcast_mst_cb(), client_connect(), client_delete_session(), client_receive_mst_cb(), client_run(), client_send_cb(), connect_notify(), create_macendpoint(), create_session(), delete_entries(), destroy_session_cb(), disconnect_and_free_it(), disconnect_notify(), do_transmit(), enqueue_fragment(), expi_proc(), expire_blocks(), expire_entries(), find_plugin(), fragmented_message_done(), free_macendpoint(), free_value(), get_session_delete_it(), GNUNET_BLOCK_context_destroy(), GNUNET_BLOCK_evaluate(), GNUNET_BLOCK_get_key(), GNUNET_BLOCK_group_create(), GNUNET_GNSRECORD_number_to_typename(), GNUNET_GNSRECORD_string_to_value(), GNUNET_GNSRECORD_typename_to_number(), GNUNET_GNSRECORD_value_to_string(), GNUNET_RECLAIM_attribute_number_to_typename(), GNUNET_RECLAIM_attribute_string_to_value(), GNUNET_RECLAIM_attribute_typename_to_number(), GNUNET_RECLAIM_attribute_value_to_string(), GNUNET_RECLAIM_credential_get_attributes(), GNUNET_RECLAIM_credential_get_expiration(), GNUNET_RECLAIM_credential_get_issuer(), GNUNET_RECLAIM_credential_get_presentation(), GNUNET_RECLAIM_credential_number_to_typename(), GNUNET_RECLAIM_credential_string_to_value(), GNUNET_RECLAIM_credential_typename_to_number(), GNUNET_RECLAIM_credential_value_to_string(), GNUNET_RECLAIM_presentation_get_attributes(), GNUNET_RECLAIM_presentation_get_expiration(), GNUNET_RECLAIM_presentation_get_issuer(), GNUNET_RECLAIM_presentation_number_to_typename(), GNUNET_RECLAIM_presentation_string_to_value(), GNUNET_RECLAIM_presentation_typename_to_number(), GNUNET_RECLAIM_presentation_value_to_string(), handle_helper_message(), handle_tcp_data(), handle_tcp_nat_probe(), handle_tcp_welcome(), heap_get_keys(), heap_plugin_del(), heap_plugin_estimate_size(), heap_plugin_get(), heap_plugin_get_closest(), heap_plugin_get_expiration(), heap_plugin_get_key(), heap_plugin_get_random(), heap_plugin_get_replication(), heap_plugin_get_zero_anonymity(), heap_plugin_put(), heap_plugin_remove_key(), http_client_plugin_get_network_for_address(), http_client_plugin_get_session(), http_client_plugin_peer_disconnect(), http_client_plugin_send(), http_client_plugin_session_disconnect(), http_client_plugin_setup_monitor(), iface_proc(), ip_send(), ip_try_connect(), iterate_entries(), libgnunet_plugin_datacache_heap_done(), libgnunet_plugin_datacache_heap_init(), libgnunet_plugin_datacache_postgres_done(), libgnunet_plugin_datacache_postgres_init(), libgnunet_plugin_datacache_sqlite_done(), libgnunet_plugin_datacache_sqlite_init(), libgnunet_plugin_datacache_template_done(), libgnunet_plugin_datacache_template_init(), libgnunet_plugin_datastore_heap_done(), libgnunet_plugin_datastore_heap_init(), libgnunet_plugin_datastore_mysql_done(), libgnunet_plugin_datastore_mysql_init(), libgnunet_plugin_datastore_postgres_done(), libgnunet_plugin_datastore_postgres_init(), libgnunet_plugin_datastore_sqlite_done(), libgnunet_plugin_datastore_sqlite_init(), libgnunet_plugin_datastore_template_done(), libgnunet_plugin_datastore_template_init(), libgnunet_plugin_dhtu_gnunet_done(), libgnunet_plugin_dhtu_ip_done(), libgnunet_plugin_dhtu_ip_init(), libgnunet_plugin_namecache_flat_done(), libgnunet_plugin_namecache_flat_init(), libgnunet_plugin_namecache_postgres_done(), libgnunet_plugin_namecache_postgres_init(), libgnunet_plugin_namecache_sqlite_done(), libgnunet_plugin_namecache_sqlite_init(), libgnunet_plugin_namestore_flat_done(), libgnunet_plugin_namestore_flat_init(), libgnunet_plugin_namestore_postgres_done(), libgnunet_plugin_namestore_postgres_init(), libgnunet_plugin_namestore_sqlite_done(), libgnunet_plugin_namestore_sqlite_init(), libgnunet_plugin_peerstore_flat_done(), libgnunet_plugin_peerstore_flat_init(), libgnunet_plugin_peerstore_sqlite_done(), libgnunet_plugin_peerstore_sqlite_init(), libgnunet_plugin_rest_config_done(), libgnunet_plugin_rest_config_init(), libgnunet_plugin_rest_copying_done(), libgnunet_plugin_rest_copying_init(), libgnunet_plugin_rest_gns_done(), libgnunet_plugin_rest_gns_init(), libgnunet_plugin_rest_identity_done(), libgnunet_plugin_rest_identity_init(), libgnunet_plugin_rest_namestore_done(), libgnunet_plugin_rest_namestore_init(), libgnunet_plugin_rest_openid_connect_done(), libgnunet_plugin_rest_openid_connect_init(), libgnunet_plugin_rest_pabc_init(), libgnunet_plugin_rest_peerinfo_done(), libgnunet_plugin_rest_peerinfo_init(), libgnunet_plugin_rest_reclaim_done(), libgnunet_plugin_rest_reclaim_init(), LIBGNUNET_PLUGIN_TRANSPORT_DONE(), libgnunet_plugin_transport_http_client_done(), libgnunet_plugin_transport_http_client_init(), libgnunet_plugin_transport_http_server_init(), LIBGNUNET_PLUGIN_TRANSPORT_INIT(), libgnunet_plugin_transport_tcp_done(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_udp_done(), libgnunet_plugin_transport_unix_done(), libgnunet_plugin_transport_unix_init(), main(), mysql_plugin_drop(), mysql_plugin_estimate_size(), mysql_plugin_get_expiration(), mysql_plugin_get_key(), mysql_plugin_get_keys(), mysql_plugin_get_replication(), mysql_plugin_get_zero_anonymity(), mysql_plugin_put(), mysql_plugin_remove_key(), namecache_cache_block(), namecache_lookup_block(), namecache_postgres_cache_block(), namecache_postgres_lookup_block(), namecache_sqlite_cache_block(), namecache_sqlite_lookup_block(), namestore_flat_iterate_records(), namestore_flat_lookup_records(), namestore_flat_store_records(), namestore_flat_zone_to_name(), namestore_postgres_iterate_records(), namestore_postgres_lookup_records(), namestore_postgres_store_records(), namestore_postgres_zone_to_name(), namestore_sqlite_iterate_records(), namestore_sqlite_lookup_records(), namestore_sqlite_store_records(), namestore_sqlite_zone_to_name(), notify_send_probe(), peerstore_flat_delete_records(), peerstore_flat_expire_records(), peerstore_flat_iterate_records(), peerstore_flat_store_record(), peerstore_sqlite_delete_records(), peerstore_sqlite_expire_records(), peerstore_sqlite_iterate_records(), peerstore_sqlite_store_record(), postgres_plugin_del(), postgres_plugin_drop(), postgres_plugin_estimate_size(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_expiration(), postgres_plugin_get_key(), postgres_plugin_get_keys(), postgres_plugin_get_random(), postgres_plugin_get_replication(), postgres_plugin_get_zero_anonymity(), postgres_plugin_put(), postgres_plugin_remove_key(), process_data(), process_ifcs(), process_inbound_tokenized_messages(), process_result(), qc_fragment_sent(), qc_message_sent(), read_cb(), read_process_fragment(), repl_proc(), run(), scan(), send_hello_beacon(), send_session_info_iter(), send_with_fragmentation(), server_lookup_connection(), server_wake_up(), session_disconnect_it(), session_timeout(), sqlite_plugin_del(), sqlite_plugin_drop(), sqlite_plugin_estimate_size(), sqlite_plugin_get(), sqlite_plugin_get_closest(), sqlite_plugin_get_expiration(), sqlite_plugin_get_key(), sqlite_plugin_get_keys(), sqlite_plugin_get_random(), sqlite_plugin_get_replication(), sqlite_plugin_get_zero_anonymity(), sqlite_plugin_put(), sqlite_plugin_remove_key(), tcp_nat_port_map_callback(), tcp_plugin_address_pretty_printer(), tcp_plugin_check_address(), tcp_plugin_disconnect(), tcp_plugin_disconnect_session(), tcp_plugin_get_network_for_address(), tcp_plugin_get_session(), tcp_plugin_send(), tcp_plugin_setup_monitor(), tcp_plugin_string_to_address(), try_connection_reversal(), udp_broadcast_receive(), udp_disconnect(), udp_disconnect_session(), udp_ipv4_broadcast_send(), udp_ipv6_broadcast_send(), udp_nat_port_map_callback(), udp_plugin_address_pretty_printer(), udp_plugin_check_address(), udp_plugin_create_session(), udp_plugin_get_network_for_address(), udp_plugin_get_session(), udp_plugin_lookup_session(), udp_plugin_select_v4(), udp_plugin_select_v6(), udp_plugin_send(), udp_plugin_setup_monitor(), udp_plugin_update_session_timeout(), udp_string_to_address(), unix_plugin_check_address(), unix_plugin_get_session(), unix_plugin_peer_disconnect(), unix_plugin_select_read(), unix_plugin_select_write(), unix_plugin_send(), unix_plugin_session_disconnect(), unix_plugin_setup_monitor(), unix_plugin_string_to_address(), unix_plugin_update_session_timeout(), unix_real_send(), unix_transport_server_start(), wlan_data_message_handler(), wlan_plugin_address_suggested(), wlan_plugin_disconnect_peer(), wlan_plugin_disconnect_session(), wlan_plugin_get_session(), wlan_plugin_send(), wlan_plugin_setup_monitor(), and wlan_plugin_string_to_address().

◆ test_system

struct GNUNET_TESTING_System* test_system
static

The process handle to the testbed service.

static struct GNUNET_OS_Process *cmd_binary_process; Handle to the testing system

Definition at line 133 of file gnunet-cmds-helper.c.

◆ tokenizer

struct GNUNET_MessageStreamTokenizer* tokenizer

Our message stream tokenizer.

Definition at line 138 of file gnunet-cmds-helper.c.

◆ stdin_fd

struct GNUNET_DISK_FileHandle* stdin_fd
static

Disk handle from stdin.

Definition at line 143 of file gnunet-cmds-helper.c.

◆ stdout_fd

struct GNUNET_DISK_FileHandle* stdout_fd
static

Disk handle for stdout.

Definition at line 148 of file gnunet-cmds-helper.c.

◆ sigpipe

struct GNUNET_DISK_PipeHandle* sigpipe
static

Pipe used to communicate shutdown via signal.

Definition at line 153 of file gnunet-cmds-helper.c.

◆ read_task_id

struct GNUNET_SCHEDULER_Task* read_task_id
static

Task identifier for the read task.

Definition at line 158 of file gnunet-cmds-helper.c.

◆ write_task_id

struct GNUNET_SCHEDULER_Task* write_task_id
static

Task identifier for the write task.

Definition at line 163 of file gnunet-cmds-helper.c.

◆ child_death_task_id

struct GNUNET_SCHEDULER_Task* child_death_task_id
static

Task to kill the child.

Definition at line 168 of file gnunet-cmds-helper.c.

◆ done_reading

int done_reading
static

Are we done reading messages from stdin?

Definition at line 173 of file gnunet-cmds-helper.c.

Referenced by read_task().

◆ status

int status
static

Result to return in case we fail.

Definition at line 178 of file gnunet-cmds-helper.c.

Referenced by main(), and tokenizer_cb().