GNUnet 0.21.0
gnunet-cmds-helper.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#include "gnunet_testing_ng_lib.h"
#include "gnunet_testing_plugin.h"
#include "gnunet_testing_netjail_lib.h"
#include "testing.h"
#include "testing_cmds.h"
#include "gnunet_testing_barrier.h"
#include <zlib.h>
Include dependency graph for gnunet-cmds-helper.c:

Go to the source code of this file.

Data Structures

struct  NodeIdentifier
 Struct with information about a specific node and the whole network namespace setup. More...
 
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 KNOWN_BASE_IP   "92.68.151."
 
#define ROUTER_BASE_IP   "92.68.150."
 

Functions

static void do_shutdown (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)
 Callback to write a message to the master loop. More...
 
static void delay_shutdown_cb ()
 
struct GNUNET_MessageHeaderGNUNET_TESTING_send_local_test_finished_msg ()
 
static void finished_cb (enum GNUNET_GenericReturnValue rv)
 
static enum GNUNET_GenericReturnValue 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

struct GNUNET_SCHEDULER_Taskfinished_task
 
struct GNUNET_TESTING_Interpreteris
 
struct TestcasePluginplugin
 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 int done_reading
 Are we done reading messages from stdin? More...
 
static int status
 Result to return in case we fail. More...
 

Macro Definition Documentation

◆ LOG

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

Generic logging shortcut.

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

◆ LOG_DEBUG

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

Debug logging shorthand.

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

◆ NODE_BASE_IP

#define NODE_BASE_IP   "192.168.15."

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

◆ KNOWN_BASE_IP

#define KNOWN_BASE_IP   "92.68.151."

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

◆ ROUTER_BASE_IP

#define ROUTER_BASE_IP   "92.68.150."

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

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Task to shut down cleanly.

Parameters
clsNULL

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

204{
205
206 LOG_DEBUG ("Shutting down.\n");
207
208 if (NULL != read_task_id)
209 {
211 read_task_id = NULL;
212 }
213 if (NULL != write_task_id)
214 {
215 struct WriteContext *wc;
216
218 write_task_id = NULL;
219 GNUNET_free (wc->data);
220 GNUNET_free (wc);
221 }
222 if (NULL != stdin_fd)
224 if (NULL != stdout_fd)
227 tokenizer = NULL;
229 NULL);
231}
struct GNUNET_MessageStreamTokenizer * tokenizer
Our message stream tokenizer.
struct TestcasePlugin * plugin
The process handle to the testbed service.
static struct GNUNET_DISK_FileHandle * stdout_fd
Disk handle for stdout.
#define LOG_DEBUG(...)
Debug logging shorthand.
static struct GNUNET_SCHEDULER_Task * read_task_id
Task identifier for the read task.
static struct GNUNET_SCHEDULER_Task * write_task_id
Task identifier for the write task.
static struct GNUNET_DISK_FileHandle * stdin_fd
Disk handle from stdin.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:242
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:404
char * library_name
Name of the shared library.
Definition: testing.h:98
Context for a single write on a chunk of memory.
void * data
The data to write.

References WriteContext::data, GNUNET_DISK_file_close(), GNUNET_free, GNUNET_MST_destroy(), GNUNET_PLUGIN_unload(), GNUNET_SCHEDULER_cancel(), TestcasePlugin::library_name, LOG_DEBUG, plugin, read_task_id, stdin_fd, stdout_fd, tokenizer, and write_task_id.

Referenced by run().

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 240 of file gnunet-cmds-helper.c.

241{
242 struct WriteContext *wc = cls;
243 ssize_t bytes_wrote;
244
245 GNUNET_assert (NULL != wc);
246 write_task_id = NULL;
247 bytes_wrote = GNUNET_DISK_file_write (stdout_fd,
248 wc->data + wc->pos,
249 wc->length - wc->pos);
251 "message send to master loop\n");
252 if (GNUNET_SYSERR == bytes_wrote)
253 {
255 "Cannot reply back successful initialization\n");
256 GNUNET_free (wc->data);
257 GNUNET_free (wc);
258 return;
259 }
260 wc->pos += bytes_wrote;
261 if (wc->pos == wc->length)
262 {
263 GNUNET_free (wc->data);
264 GNUNET_free (wc);
265 return;
266 }
268 stdout_fd,
269 &write_task,
270 wc);
271}
static void write_task(void *cls)
Task to write to the standard out.
#define LOG(kind,...)
Generic logging shortcut.
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 GNUNET_log(kind,...)
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
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:1689
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
size_t pos
The current position from where the write operation should begin.
size_t length
The length of the data.

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

Referenced by write_message(), and write_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_message()

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

Callback to write a message to the master loop.

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

281{
282 struct WriteContext *wc;
283
285 "write message to master loop\n");
286 wc = GNUNET_new (struct WriteContext);
287 wc->length = msg_length;
288 wc->data = message;
291 stdout_fd,
292 &write_task,
293 wc);
294}
#define GNUNET_new(type)
Allocate a struct or union of the given type.

References WriteContext::data, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_new, GNUNET_SCHEDULER_add_write_file(), GNUNET_TIME_UNIT_FOREVER_REL, WriteContext::length, stdout_fd, write_task(), and write_task_id.

Referenced by finished_cb(), and tokenizer_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delay_shutdown_cb()

static void delay_shutdown_cb ( )
static

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

299{
301 "doing shutdown after delay\n");
303}
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and GNUNET_SCHEDULER_shutdown().

Referenced by finished_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_send_local_test_finished_msg()

struct GNUNET_MessageHeader * GNUNET_TESTING_send_local_test_finished_msg ( )

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

308{
310 size_t msg_length;
311
312 msg_length = sizeof(struct GNUNET_TESTING_CommandLocalFinished);
315 reply->header.size = htons ((uint16_t) msg_length);
316
317 return (struct GNUNET_MessageHeader *) reply;
318}
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED.
Definition: testing_cmds.h:86

References GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED, GNUNET_new, GNUNET_TESTING_CommandLocalFinished::header, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

◆ finished_cb()

static void finished_cb ( enum GNUNET_GenericReturnValue  rv)
static

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

323{
325 size_t msg_length;
326
327 msg_length = sizeof(struct GNUNET_TESTING_CommandLocalFinished);
330 reply->header.size = htons ((uint16_t) msg_length);
331 reply->rv = rv;
332
334 "message prepared\n");
335 write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
337 "message send\n");
338 // FIXME: bad hack, do not write 1s, have continuation after write_message() is done!
340 "delaying shutdown\n");
343 NULL);
344}
static void write_message(struct GNUNET_MessageHeader *message, size_t msg_length)
Callback to write a message to the master loop.
static void delay_shutdown_cb()
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1272
#define GNUNET_TIME_UNIT_SECONDS
One second.
enum GNUNET_GenericReturnValue rv
The exit status local test return with.
Definition: testing_cmds.h:91

References delay_shutdown_cb(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED, GNUNET_new, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_UNIT_SECONDS, GNUNET_TESTING_CommandLocalFinished::header, GNUNET_TESTING_CommandLocalFinished::rv, GNUNET_MessageHeader::size, GNUNET_MessageHeader::type, and write_message().

Referenced by GDS_u_send(), GNUNET_NAMESTORE_record_set_edit_cancel(), gnunet_send(), ip_send(), and tokenizer_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tokenizer_cb()

static enum GNUNET_GenericReturnValue 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 360 of file gnunet-cmds-helper.c.

362{
363 struct NodeIdentifier *ni = cls;
366 char *binary;
367 char *plugin_name;
368 size_t plugin_name_size;
369 uint16_t msize;
370 uint16_t type;
371 size_t msg_length;
372 char *router_ip;
373 char *node_ip;
374 unsigned int namespace_n;
375
376 type = ntohs (message->type);
377 msize = ntohs (message->size);
379 "Received message type %u and size %u\n",
380 type,
381 msize);
382 switch (type)
383 {
385 {
386 msg = (const struct GNUNET_TESTING_CommandHelperInit *) message;
387 plugin_name_size = ntohs (msg->plugin_name_size);
389 msize)
390 {
391 GNUNET_break (0);
393 "Received unexpected message -- exiting\n");
394 goto error;
395 }
398 ((char *) &msg[1]),
399 plugin_name_size + 1);
400
401 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd");
402
405 NULL);
407
408 plugin->global_n = ni->global_n;
409 plugin->local_m = ni->local_m;
410 plugin->n = ni->n;
411 plugin->m = ni->m;
412
413 GNUNET_asprintf (&router_ip,
414 ROUTER_BASE_IP "%s",
415 plugin->n);
416 {
417 char dummy;
418
419 if (1 !=
420 sscanf (plugin->n,
421 "%u%c",
422 &namespace_n,
423 &dummy))
424 {
425 // FIXME: how to handle error nicely?
426 GNUNET_break (0);
427 namespace_n = 0;
428 }
429 }
430
431 if (0 == namespace_n)
432 {
434 "known node n: %s\n",
435 plugin->n);
436 GNUNET_asprintf (&node_ip,
437 KNOWN_BASE_IP "%s",
438 plugin->m);
439 }
440 else
441 {
443 "subnet node n: %s\n",
444 plugin->n);
445 GNUNET_asprintf (&node_ip,
446 NODE_BASE_IP "%s",
447 plugin->m);
448 }
449
451 router_ip,
452 node_ip,
453 plugin->m,
454 plugin->n,
456 ni->topology_data,
457 ni->read_file,
458 &finished_cb);
459 GNUNET_free (node_ip);
460 GNUNET_free (binary);
461 GNUNET_free (router_ip);
463
464 msg_length = sizeof(struct GNUNET_TESTING_CommandHelperReply);
467 reply->header.size = htons ((uint16_t) msg_length);
468 write_message (&reply->header,
469 msg_length);
470 return GNUNET_OK;
471 }
473 {
474 const char *barrier_name;
475 struct CommandBarrierCrossable *adm = (struct
476 CommandBarrierCrossable *) message;
477
478 barrier_name = (const char *) &adm[1];
480 "cross barrier %s\n",
481 barrier_name);
483 barrier_name);
484 return GNUNET_OK;
485 }
487 {
489 "all peers started\n");
491 return GNUNET_OK;
492 }
494 {
496 "all local tests prepared\n");
498 return GNUNET_OK;
499 }
500 default:
501 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n");
502 goto error;
503 }
504
505error:
508 "tokenizer shutting down!\n");
510 return GNUNET_SYSERR;
511}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static void finished_cb(enum GNUNET_GenericReturnValue rv)
static int status
Result to return in case we fail.
#define NODE_BASE_IP
#define ROUTER_BASE_IP
#define KNOWN_BASE_IP
struct GNUNET_TESTING_Interpreter * is
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static uint32_t type
Type string converted to DNS type value.
static char * plugin_name
Name of our plugin.
@ GNUNET_OK
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_malloc(size)
Wrapper around malloc.
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 ...
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:198
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY
The reply message from gnunet-cmds-helper.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT
The initialization message towards gnunet-cmds-helper.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
Definition: strings.c:138
Message send to a child loop to inform the child loop about a barrier being advanced.
Definition: testing.h:35
Initialization message for gnunet-cmds-testbed to start cmd binary.
Definition: testing_cmds.h:39
Reply message from cmds helper process.
Definition: testing_cmds.h:58
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY.
Definition: testing_cmds.h:62
GNUNET_TESTING_PLUGIN_ALL_LOCAL_TESTS_PREPARED all_local_tests_prepared
GNUNET_TESTING_PLUGIN_ALL_PEERS_STARTED all_peers_started
GNUNET_TESTING_PLUGIN_StartTestCase start_testcase
Struct with information about a specific node and the whole network namespace setup.
unsigned int * read_file
Shall we read the topology from file, or from a string.
char * topology_data
String with topology data or name of topology file.
char * m
The number of the node in the namespace.
char * n
The number of the namespace this node is in.
char * local_m
The number of local nodes per namespace.
char * global_n
The number of namespaces.
Handle for a plugin.
Definition: testing.h:94
char * global_n
The number of namespaces.
Definition: testing.h:121
char * local_m
The number of local nodes per namespace.
Definition: testing.h:127
char * n
The number of the namespace this node is in.
Definition: testing.h:133
char * m
The number of the node in the namespace.
Definition: testing.h:139
struct GNUNET_TESTING_PluginFunctions * api
Plugin API.
Definition: testing.h:103
void GNUNET_TESTING_finish_barrier_(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
Finish all "barrier reached" commands attached to this barrier.

References GNUNET_TESTING_PluginFunctions::all_local_tests_prepared, GNUNET_TESTING_PluginFunctions::all_peers_started, TestcasePlugin::api, dummy, finished_cb(), NodeIdentifier::global_n, TestcasePlugin::global_n, GNUNET_asprintf(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_malloc, GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED, GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED, GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE, 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_TESTING_finish_barrier_(), GNUNET_TESTING_CommandHelperReply::header, is, KNOWN_BASE_IP, TestcasePlugin::library_name, NodeIdentifier::local_m, TestcasePlugin::local_m, LOG, NodeIdentifier::m, TestcasePlugin::m, msg, NodeIdentifier::n, TestcasePlugin::n, NODE_BASE_IP, plugin, plugin_name, GNUNET_TESTING_CommandHelperInit::plugin_name_size, NodeIdentifier::read_file, ROUTER_BASE_IP, GNUNET_MessageHeader::size, GNUNET_TESTING_PluginFunctions::start_testcase, status, NodeIdentifier::topology_data, type, GNUNET_MessageHeader::type, and write_message().

Referenced by run().

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 520 of file gnunet-cmds-helper.c.

521{
522 char buf[GNUNET_MAX_MESSAGE_SIZE];
523 ssize_t sread;
524
525 read_task_id = NULL;
526 sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof(buf));
527 if ((GNUNET_SYSERR == sread) || (0 == sread))
528 {
529 LOG_DEBUG ("STDIN closed\n");
531 return;
532 }
534 {
535 /* didn't expect any more data! */
536 GNUNET_break_op (0);
538 "tokenizer shutting down during reading, didn't expect any more data!\n");
540 return;
541 }
542 LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread);
543 /* FIXME: could introduce a GNUNET_MST_read2 to read
544 directly from 'stdin_fd' and save a memcpy() here */
545 if (GNUNET_OK !=
547 {
548 GNUNET_break (0);
550 "tokenizer shutting down during reading, writing to buffer failed!\n");
552 return;
553 }
554 read_task_id /* No timeout while reading */
556 stdin_fd,
557 &read_task,
558 NULL);
559}
static void read_task(void *cls)
Task to read from stdin.
static int done_reading
Are we done reading messages from stdin?
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
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
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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:1656
enum GNUNET_GenericReturnValue 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:101

References 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, read_task(), read_task_id, stdin_fd, and tokenizer.

Referenced by read_task(), and run().

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 571 of file gnunet-cmds-helper.c.

575{
576 struct NodeIdentifier *ni = cls;
577
579 "Starting interpreter loop helper...\n");
580
582 ni);
586 stdin_fd,
587 &read_task,
588 NULL);
590 NULL);
592 "Interpreter loop helper started.\n");
593}
static void do_shutdown(void *cls)
Task to shut down cleanly.
static enum GNUNET_GenericReturnValue 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_DISK_FileHandle * GNUNET_DISK_get_handle_from_native(FILE *fd)
Get a handle from a native FD.
Definition: disk.c:1346
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,...
Definition: scheduler.c:1334
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:86

References do_shutdown(), GNUNET_DISK_get_handle_from_native(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MST_create(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_TIME_UNIT_FOREVER_REL, LOG, read_task(), read_task_id, stdin_fd, stdout_fd, tokenizer, and tokenizer_cb().

Referenced by main().

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 600 of file gnunet-cmds-helper.c.

601{
602 static char c;
603 int old_errno; /* back-up errno */
604
605 old_errno = errno;
607 1 ==
610 &c,
611 sizeof(c)));
612 errno = old_errno;
613}
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
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:1617
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.

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

Referenced by main().

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 624 of file gnunet-cmds-helper.c.

625{
626 struct NodeIdentifier *ni;
630 };
631 int ret;
632 unsigned int sscanf_ret;
633 int i;
634 size_t topology_data_length = 0;
635 unsigned int read_file;
636 char cr[2] = "\n\0";
637
638 GNUNET_log_setup ("gnunet-cmds-helper",
639 "DEBUG",
640 NULL);
641 ni = GNUNET_new (struct NodeIdentifier);
642 ni->global_n = argv[1];
643 ni->local_m = argv[2];
644 ni->m = argv[3];
645 ni->n = argv[4];
646
647 errno = 0;
648 sscanf_ret = sscanf (argv[5], "%u", &read_file);
649
650 if (errno != 0)
651 {
653 }
654 else if (1 == read_file)
655 ni->topology_data = argv[6];
656 else if (0 == read_file)
657 {
658 for (i = 6; i<argc; i++)
659 topology_data_length += strlen (argv[i]) + 1;
661 "topo data length %llu\n",
662 (unsigned long long) topology_data_length);
663 ni->topology_data = GNUNET_malloc (topology_data_length);
664 memset (ni->topology_data, '\0', topology_data_length);
665 for (i = 6; i<argc; i++)
666 {
667 strcat (ni->topology_data, argv[i]);
668 strcat (ni->topology_data, cr);
669 }
670 }
671 else
672 {
674 "Wrong input for the fourth argument\n");
675 }
676 GNUNET_assert (0 < sscanf_ret);
677 ni->read_file = &read_file;
678 ni->topology_data[topology_data_length - 1] = '\0';
680 "topo data %s\n",
681 ni->topology_data);
682
684 if (NULL ==
686 {
687 GNUNET_break (0);
688 return 1;
689 }
690 shc_chld =
693 ret = GNUNET_PROGRAM_run (argc,
694 argv,
695 "gnunet-cmds-helper",
696 "Helper for starting a local interpreter loop",
697 options,
698 &run,
699 ni);
700
702 "Finishing helper\n");
704 shc_chld = NULL;
706 GNUNET_free (ni);
707 if (GNUNET_OK != ret)
708 return 1;
709 return (GNUNET_OK == status) ? 0 : 1;
710}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static struct GNUNET_SIGNAL_Context * shc_chld
static int ret
Final status code.
Definition: gnunet-arm.c:94
static void sighandler_child_death()
Signal handler called for SIGCHLD.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition: disk.c:1444
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1587
@ GNUNET_DISK_PF_NONE
No special options, use non-blocking read/write operations.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
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,...
Definition: program.c:400
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:52
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal handler.
Definition: signal.c:78
enum GNUNET_GenericReturnValue read_file(char const *const filename, char **buffer)
Definition: pabc_helper.c:71
#define GNUNET_SIGCHLD
Definition: platform.h:42
Definition of a command line option.

References NodeIdentifier::global_n, GNUNET_assert, GNUNET_break, GNUNET_DISK_PF_NONE, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_log, GNUNET_log_setup(), GNUNET_log_strerror, GNUNET_malloc, 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, options, read_file(), NodeIdentifier::read_file, ret, run(), shc_chld, sighandler_child_death(), sigpipe, status, and NodeIdentifier::topology_data.

Here is the call graph for this function:

Variable Documentation

◆ finished_task

struct GNUNET_SCHEDULER_Task* finished_task

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

◆ is

◆ plugin

struct TestcasePlugin* plugin

The process handle to the testbed service.

static struct GNUNET_OS_Process *cmd_binary_process; Plugin to dynamically load a test case.

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

Referenced by __attribute__(), add_addr(), add_plugin(), core_connect_cb(), core_disconnect_cb(), core_init_cb(), create_source(), create_target(), database_connect(), database_prepare(), database_setup(), database_shutdown(), delete_by_rowid(), delete_old_block(), delete_value(), DHTU_gnunet_done(), DHTU_gnunet_init(), DHTU_ip_done(), DHTU_ip_init(), do_shutdown(), execute_get(), expire_blocks(), find_plugin(), find_source(), find_target(), free_value(), get_any(), get_records_and_call_iterator(), get_typed(), GNUNET_BLOCK_check_block(), GNUNET_BLOCK_check_query(), GNUNET_BLOCK_check_reply(), GNUNET_BLOCK_context_destroy(), GNUNET_BLOCK_get_key(), GNUNET_BLOCK_group_create(), gnunet_drop(), GNUNET_GNSRECORD_is_critical(), GNUNET_GNSRECORD_number_to_typename(), GNUNET_GNSRECORD_string_to_value(), GNUNET_GNSRECORD_typename_to_number(), GNUNET_GNSRECORD_value_to_string(), gnunet_hold(), 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(), gnunet_try_connect(), handle_core_message(), 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_replication(), heap_plugin_get_zero_anonymity(), heap_plugin_put(), heap_plugin_remove_key(), init_connection(), ip_send(), ip_try_connect(), 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_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_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_sqlite_done(), libgnunet_plugin_peerstore_sqlite_init(), libgnunet_plugin_rest_pabc_init(), libgnunet_plugin_rest_reclaim_done(), lookup_records(), namecache_cache_block(), namecache_expire_blocks(), namecache_lookup_block(), namecache_postgres_cache_block(), namecache_postgres_expire_blocks(), namecache_postgres_lookup_block(), namecache_sqlite_cache_block(), namecache_sqlite_expire_blocks(), namecache_sqlite_lookup_block(), namestore_flat_iterate_records(), namestore_flat_lookup_records(), namestore_flat_store_records(), namestore_flat_zone_to_name(), namestore_postgres_clear_editor_hint(), namestore_postgres_create_tables(), namestore_postgres_drop_tables(), namestore_postgres_edit_records(), namestore_postgres_iterate_records(), namestore_postgres_lookup_records(), namestore_postgres_store_records(), namestore_postgres_zone_to_name(), namestore_sqlite_create_tables(), namestore_sqlite_drop_tables(), namestore_sqlite_editor_hint_clear(), namestore_sqlite_iterate_records(), namestore_sqlite_store_records(), namestore_sqlite_zone_to_name(), nse_cb(), peerinfo_cb(), 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_replication(), postgres_plugin_get_zero_anonymity(), postgres_plugin_put(), postgres_plugin_remove_key(), process_ifcs(), process_result(), read_cb(), repl_proc(), REST_config_done(), REST_config_init(), REST_config_process_request(), REST_copying_done(), REST_copying_init(), REST_gns_done(), REST_gns_init(), REST_identity_done(), REST_identity_init(), REST_namestore_done(), REST_namestore_init(), REST_openid_done(), REST_openid_init(), REST_reclaim_done(), REST_reclaim_init(), run(), scan(), sqlite_plugin_del(), sqlite_plugin_drop(), sqlite_plugin_estimate_size(), sqlite_plugin_get_closest(), sqlite_plugin_get_expiration(), sqlite_plugin_get_key(), sqlite_plugin_get_keys(), sqlite_plugin_get_replication(), sqlite_plugin_get_zero_anonymity(), sqlite_plugin_put(), sqlite_plugin_remove_key(), start_helper(), and tokenizer_cb().

◆ tokenizer

struct GNUNET_MessageStreamTokenizer* tokenizer

Our message stream tokenizer.

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

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

◆ stdin_fd

struct GNUNET_DISK_FileHandle* stdin_fd
static

Disk handle from stdin.

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

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

◆ stdout_fd

struct GNUNET_DISK_FileHandle* stdout_fd
static

Disk handle for stdout.

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

Referenced by do_shutdown(), run(), write_message(), and write_task().

◆ sigpipe

struct GNUNET_DISK_PipeHandle* sigpipe
static

Pipe used to communicate shutdown via signal.

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

Referenced by main(), and sighandler_child_death().

◆ read_task_id

struct GNUNET_SCHEDULER_Task* read_task_id
static

Task identifier for the read task.

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

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

◆ write_task_id

struct GNUNET_SCHEDULER_Task* write_task_id
static

Task identifier for the write task.

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

Referenced by do_shutdown(), write_message(), and write_task().

◆ done_reading

int done_reading
static

Are we done reading messages from stdin?

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

Referenced by read_task().

◆ status

int status
static

Result to return in case we fail.

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

Referenced by main(), and tokenizer_cb().