GNUnet 0.22.0
testing_api_cmd_netjail_start_cmds_helper.c File Reference

Command to start the netjail peers. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#include "testing_api_barrier.h"
#include "testing_api_loop.h"
#include "testing_cmds.h"
#include "testing_api_topology.h"
Include dependency graph for testing_api_cmd_netjail_start_cmds_helper.c:

Go to the source code of this file.

Data Structures

struct  NetJailState
 Struct to hold information for callbacks. More...
 
struct  HelperState
 
struct  TestingSystemCount
 Struct containing the number of the netjail node and the NetJailState which will be handed to callbacks specific to a test environment. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 Generic logging shortcut. More...
 

Functions

static void clear_msg (void *cls, enum GNUNET_GenericReturnValue result)
 Continuation function from GNUNET_HELPER_send() More...
 
static void handle_helper_barrier_reached (void *cls, const struct GNUNET_TESTING_CommandBarrierReached *rm)
 
static void handle_helper_local_finished (void *cls, const struct GNUNET_TESTING_CommandLocalFinished *lf)
 
static enum GNUNET_GenericReturnValue helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
 Functions with this signature are called whenever a complete message is received by the tokenizer. More...
 
static void exp_cb (void *cls)
 Callback called if there was an exception during execution of the helper. More...
 
static enum GNUNET_GenericReturnValue add_barrier (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
static bool send_start_messages (struct NetJailState *ns, struct GNUNET_HELPER_Handle *helper)
 
static bool start_helper (struct NetJailState *ns, unsigned int script_num)
 Function which start a single helper process. More...
 
static void do_timeout (void *cls)
 Function run when the cmd terminates (good or bad) with timeout. More...
 
static int start_peer (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
static int start_subnets (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
static int start_carriers (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
static void netjail_exec_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 This function starts a helper process for each node. More...
 
static void netjail_exec_cleanup (void *cls)
 Code to clean up resource this cmd used. More...
 
static enum GNUNET_GenericReturnValue netjail_exec_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 This function prepares an array with traits. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_start_helpers (const char *label, const char *topology_cmd_label, struct GNUNET_TIME_Relative timeout)
 Create command. More...
 

Variables

unsigned int node_number
 The network namespace number of a node. More...
 

Detailed Description

Command to start the netjail peers.

Author
t3sserakt

Definition in file testing_api_cmd_netjail_start_cmds_helper.c.

Macro Definition Documentation

◆ LOG

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

Generic logging shortcut.

Definition at line 37 of file testing_api_cmd_netjail_start_cmds_helper.c.

Function Documentation

◆ clear_msg()

static void clear_msg ( void *  cls,
enum GNUNET_GenericReturnValue  result 
)
static

Continuation function from GNUNET_HELPER_send()

Parameters
clsclosure
resultGNUNET_OK on success, GNUNET_NO if helper process died GNUNET_SYSERR during GNUNET_HELPER_stop

Definition at line 178 of file testing_api_cmd_netjail_start_cmds_helper.c.

180{
181 struct TestingSystemCount *tbc = cls;
182 struct NetJailState *ns = tbc->ns;
183
184 GNUNET_assert (NULL != tbc->shandle);
185 tbc->shandle = NULL;
187 ns->tbc_tail,
188 tbc);
189 GNUNET_free (tbc);
190 if ( (! ns->failed) &&
191 (GNUNET_OK != result) )
192 {
193 ns->failed = true;
195 "Failed sending message to helper!\n");
197 }
198}
static struct GNUNET_NAMECACHE_Handle * ns
Handle to the namecache.
static int result
Global testing status.
#define GNUNET_TESTING_FAIL(is)
Print failing line number and trigger shutdown.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_log(kind,...)
@ GNUNET_OK
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_free(ptr)
Wrapper around free.
Struct to hold information for callbacks.
Struct containing the number of the netjail node and the NetJailState which will be handed to callbac...
struct GNUNET_HELPER_SendHandle * shandle
The send handle for the helper.
struct NetJailState * ns
Struct to store information handed over to callbacks.

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_TESTING_FAIL, ns, TestingSystemCount::ns, result, and TestingSystemCount::shandle.

Referenced by send_start_messages().

Here is the caller graph for this function:

◆ handle_helper_barrier_reached()

static void handle_helper_barrier_reached ( void *  cls,
const struct GNUNET_TESTING_CommandBarrierReached rm 
)
static

Definition at line 202 of file testing_api_cmd_netjail_start_cmds_helper.c.

205{
206 struct HelperState *hs = cls;
207 struct NetJailState *ns = hs->ns;
208 struct GNUNET_TESTING_Barrier *barrier;
209
210 barrier = GNUNET_TESTING_get_barrier2_ (ns->is,
211 &rm->barrier_key);
212 if (NULL == barrier)
213 {
214 if (! ns->failed)
215 {
216 ns->failed = true;
218 "We did not found the barrier that was supposedly reached.!\n");
220 }
221 return;
222 }
223 if (barrier->inherited)
224 {
225 /* pass on to parent */
227 &rm->header);
228 }
229 else
230 {
231 barrier->reached++;
232 if (barrier->reached == barrier->expected_reaches)
233 {
235 .header.size
236 = htons (sizeof (cbs)),
237 .header.type
239 .barrier_key
240 = rm->barrier_key
241 };
242
243 GNUNET_assert (! barrier->satisfied);
244 barrier->satisfied = true;
245 /* unblock children */
247 &cbs.header);
248 /* unblock self */
249 for (unsigned int i = 0; i<barrier->cnt_waiting; i++)
251 GNUNET_array_grow (barrier->waiting,
252 barrier->cnt_waiting,
253 0);
254 }
255 }
256}
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE
An entry for a barrier list.
bool inherited
Did we inherit the barrier from our parent loop?
unsigned int reached
Number of times the barrier has been reached.
unsigned int expected_reaches
Number of total commands expected to be reached by the barrier.
struct GNUNET_TESTING_AsyncContext ** waiting
Context of barrier reached commands of our local interpreter that are currently blocked on this barri...
unsigned int cnt_waiting
Length of the waiting array.
bool satisfied
Did we reach expected_reaches? Used in particular if inherited is true and we cannot compute locally.
struct GNUNET_ShortHashCode barrier_key
Definition: testing_cmds.h:80
struct GNUNET_MessageHeader header
Definition: testing_cmds.h:79
Parent to child: this barrier was satisfied.
Definition: testing_cmds.h:100
struct GNUNET_MessageHeader header
Definition: testing_cmds.h:101
struct NetJailState * ns
The state of this command.
struct GNUNET_TESTING_Barrier * GNUNET_TESTING_get_barrier2_(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_ShortHashCode *create_key)
void GNUNET_TESTING_loop_notify_parent_(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_MessageHeader *hdr)
Send message to our parent.
void GNUNET_TESTING_loop_notify_children_(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_MessageHeader *hdr)
Send message to all netjail children (if there are any).

References GNUNET_TESTING_CommandBarrierReached::barrier_key, GNUNET_TESTING_Barrier::cnt_waiting, GNUNET_TESTING_Barrier::expected_reaches, GNUNET_array_grow, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE, GNUNET_TESTING_async_fail(), GNUNET_TESTING_async_finish(), GNUNET_TESTING_get_barrier2_(), GNUNET_TESTING_loop_notify_children_(), GNUNET_TESTING_loop_notify_parent_(), GNUNET_TESTING_CommandBarrierReached::header, GNUNET_TESTING_CommandBarrierSatisfied::header, GNUNET_TESTING_Barrier::inherited, ns, HelperState::ns, GNUNET_TESTING_Barrier::reached, GNUNET_TESTING_Barrier::satisfied, GNUNET_MessageHeader::size, and GNUNET_TESTING_Barrier::waiting.

Here is the call graph for this function:

◆ handle_helper_local_finished()

static void handle_helper_local_finished ( void *  cls,
const struct GNUNET_TESTING_CommandLocalFinished lf 
)
static

Definition at line 260 of file testing_api_cmd_netjail_start_cmds_helper.c.

263{
264 struct HelperState *hs = cls;
265 struct NetJailState *ns = hs->ns;
266
268 hs->finished = GNUNET_YES;
269 ns->n_finished++;
270 if ( (! ns->failed) &&
271 (GNUNET_OK != ntohl (lf->rv)) )
272 {
273 ns->failed = true;
275 "Helper finished with error!\n");
277 return;
278 }
279 if (ns->n_finished == ns->n_helpers)
280 {
281 GNUNET_SCHEDULER_cancel (ns->timeout_task);
282 ns->timeout_task = NULL;
284 }
285}
void lf(char *msg)
Definition: gnunet_gst.c:587
void GNUNET_HELPER_stop(struct GNUNET_HELPER_Handle *h, int soft_kill)
Kills the helper, closes the pipe, frees the handle and calls wait() on the helper process.
Definition: helper.c:536
@ GNUNET_YES
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:979
struct GNUNET_HELPER_Handle * helper
The helper handle for this state.
enum GNUNET_GenericReturnValue finished
Did we got a GNUNET_TESTING_CommandLocalFinished message?

References HelperState::finished, GNUNET_ERROR_TYPE_ERROR, GNUNET_HELPER_stop(), GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_TESTING_async_fail(), GNUNET_TESTING_async_finish(), GNUNET_YES, HelperState::helper, lf(), ns, and HelperState::ns.

Here is the call graph for this function:

◆ helper_mst()

static enum GNUNET_GenericReturnValue helper_mst ( 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_SERVER_mst_destroy in callback

Parameters
clsclosure
messagethe actual message
Returns
GNUNET_OK on success, GNUNET_SYSERR to stop further processing

Definition at line 299 of file testing_api_cmd_netjail_start_cmds_helper.c.

301{
302 struct HelperState *hs = cls;
303 struct NetJailState *ns = hs->ns;
306 helper_barrier_reached,
309 hs),
311 helper_local_finished,
314 hs),
316 };
318
320 message);
321 if (GNUNET_OK != ret)
322 {
323 GNUNET_break (0);
324 if (! ns->failed)
325 {
326 ns->failed = true;
328 "We got an unknown message from the helper process!\n");
330 }
331 }
332 return ret;
333}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static int ret
Final status code.
Definition: gnunet-arm.c:93
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
enum GNUNET_GenericReturnValue GNUNET_MQ_handle_message(const struct GNUNET_MQ_MessageHandler *handlers, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given h...
Definition: mq.c:205
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED
Message handler for a specific message type.
Child to parent: I reached the given barrier, increment the counter (or pass to grandparent).
Definition: testing_cmds.h:78

References GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED, GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED, GNUNET_MQ_handle_message(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_OK, GNUNET_TESTING_async_fail(), handlers, ns, HelperState::ns, and ret.

Referenced by start_helper().

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

◆ exp_cb()

static void exp_cb ( void *  cls)
static

Callback called if there was an exception during execution of the helper.

Definition at line 340 of file testing_api_cmd_netjail_start_cmds_helper.c.

341{
342 struct HelperState *hs = cls;
343 struct NetJailState *ns = hs->ns;
344
346 "Called exp_cb.\n");
347 if (NULL != ns->timeout_task)
348 {
349 GNUNET_SCHEDULER_cancel (ns->timeout_task);
350 ns->timeout_task = NULL;
351 }
352 if (! ns->failed)
354}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_TESTING_async_fail(), ns, and HelperState::ns.

Referenced by GNUNET_HELPER_start(), and start_helper().

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

◆ add_barrier()

static enum GNUNET_GenericReturnValue add_barrier ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 358 of file testing_api_cmd_netjail_start_cmds_helper.c.

361{
362 struct GNUNET_ShortHashCode **bar_posp = cls;
363 struct GNUNET_ShortHashCode *bar_pos = *bar_posp;
364
365 *bar_pos = *key;
366 *bar_posp = bar_pos + 1;
367 return GNUNET_OK;
368}
struct GNUNET_HashCode key
The key used in the DHT.
A 256-bit hashcode.

References GNUNET_OK, and key.

Referenced by send_start_messages().

Here is the caller graph for this function:

◆ send_start_messages()

static bool send_start_messages ( struct NetJailState ns,
struct GNUNET_HELPER_Handle helper 
)
static
Returns
true on success

Definition at line 375 of file testing_api_cmd_netjail_start_cmds_helper.c.

377{
379 struct TestingSystemCount *tbc;
380 struct GNUNET_ShortHashCode *bar;
381 struct GNUNET_ShortHashCode *bar_pos;
382 unsigned int num_barriers = GNUNET_TESTING_barrier_count_ (ns->is);
383 size_t topo_length;
384 size_t msg_len;
385
386 topo_length = strlen (ns->topology_data) + 1;
387 GNUNET_assert (topo_length < SIZE_MAX - sizeof (*msg));
388 GNUNET_assert (SIZE_MAX / sizeof (struct GNUNET_ShortHashCode) >
389 num_barriers);
390 GNUNET_assert (sizeof (*msg) + topo_length <
392 - num_barriers * sizeof (struct GNUNET_ShortHashCode));
393 msg_len = sizeof (*msg) + topo_length
394 + num_barriers * sizeof (struct GNUNET_ShortHashCode);
395 if (msg_len > UINT16_MAX)
396 {
397 /* ask a wizard to enhance the protocol;
398 start with gzip topology_data? multiple
399 init messages for barriers + topo data,
400 etc.*/
401 GNUNET_break (0);
402 return false;
403 }
404 msg = GNUNET_malloc (msg_len);
405 msg->header.size = htons ((uint16_t) msg_len);
407 msg->barrier_count = htonl (num_barriers);
408 bar = (struct GNUNET_ShortHashCode *) &msg[1];
409 bar_pos = bar;
412 &bar_pos);
413 GNUNET_assert (bar_pos == &bar[num_barriers]);
414 memcpy (&bar[num_barriers],
415 ns->topology_data,
416 topo_length);
417 tbc = GNUNET_new (struct TestingSystemCount);
418 tbc->ns = ns;
420 helper,
421 &msg->header,
422 GNUNET_NO,
423 &clear_msg,
424 tbc);
426 if (NULL == tbc->shandle)
427 {
429 "Send handle is NULL!\n");
430 GNUNET_free (tbc);
431 return false;
432 }
434 ns->tbc_tail,
435 tbc);
436 return true;
437}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_HELPER_SendHandle * GNUNET_HELPER_send(struct GNUNET_HELPER_Handle *h, const struct GNUNET_MessageHeader *msg, bool can_drop, GNUNET_HELPER_Continuation cont, void *cont_cls)
Send an message to the helper.
Definition: helper.c:613
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
@ GNUNET_NO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT
The initialization message towards gnunet-cmds-helper.
#define SIZE_MAX
Definition: platform.h:208
Initialization message for gnunet-cmds-testbed to start cmd binary.
Definition: testing_cmds.h:42
static enum GNUNET_GenericReturnValue add_barrier(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
static void clear_msg(void *cls, enum GNUNET_GenericReturnValue result)
Continuation function from GNUNET_HELPER_send()
unsigned int GNUNET_TESTING_barrier_count_(struct GNUNET_TESTING_Interpreter *is)
void GNUNET_TESTING_barrier_iterate_(struct GNUNET_TESTING_Interpreter *is, GNUNET_CONTAINER_ShortmapIterator cb, void *cb_cls)

References add_barrier(), clear_msg(), GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_HELPER_send(), GNUNET_log, GNUNET_malloc, GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT, GNUNET_new, GNUNET_NO, GNUNET_TESTING_barrier_count_(), GNUNET_TESTING_barrier_iterate_(), msg, ns, TestingSystemCount::ns, TestingSystemCount::shandle, GNUNET_MessageHeader::size, SIZE_MAX, and GNUNET_MessageHeader::type.

Referenced by start_helper().

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

◆ start_helper()

static bool start_helper ( struct NetJailState ns,
unsigned int  script_num 
)
static

Function which start a single helper process.

Returns
true on success

Definition at line 445 of file testing_api_cmd_netjail_start_cmds_helper.c.

447{
448 char *gnunet_cmds_helper
450 char node_id[32];
451 char *data_dir;
452 char *script_name;
453 struct GNUNET_HELPER_Handle *helper;
454 struct HelperState *hs = GNUNET_new (struct HelperState);
455
457 GNUNET_asprintf (&script_name,
458 "%s%s",
459 data_dir,
461 GNUNET_snprintf (node_id,
462 sizeof (node_id),
463 "if%06x-%06x\n",
464 (unsigned int) getpid (),
465 script_num);
466 {
467 char *const script_argv[] = {
468 script_name,
469 node_id,
470 gnunet_cmds_helper,
471 node_id,
472 NULL
473 };
474 hs->ns = ns;
476 GNUNET_YES, /* with control pipe */
477 script_argv[0],
478 script_argv,
479 &helper_mst,
480 &exp_cb,
481 hs);
482 hs->helper = helper;
483 }
484 GNUNET_free (gnunet_cmds_helper);
485 if (NULL == helper)
486 {
488 "Starting helper failed. Is NULL.\n");
489 GNUNET_break (0);
490 GNUNET_free (hs);
491 return false;
492 }
493 GNUNET_array_append (ns->helpers,
494 ns->n_helpers,
495 hs);
497 helper);
498 GNUNET_free (data_dir);
499 GNUNET_free (script_name);
500 return send_start_messages (ns,
501 helper);
502}
struct GNUNET_HELPER_Handle * GNUNET_HELPER_start(int with_control_pipe, const char *binary_name, char *const binary_argv[], GNUNET_MessageTokenizerCallback cb, GNUNET_HELPER_ExceptionCallback exp_cb, void *cb_cls)
Starts a helper and begins reading from it.
Definition: helper.c:460
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
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 ...
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
The handle to a helper process.
Definition: helper.c:77
static enum GNUNET_GenericReturnValue helper_mst(void *cls, const struct GNUNET_MessageHeader *message)
Functions with this signature are called whenever a complete message is received by the tokenizer.
static void exp_cb(void *cls)
Callback called if there was an exception during execution of the helper.
static bool send_start_messages(struct NetJailState *ns, struct GNUNET_HELPER_Handle *helper)
void GNUNET_TESTING_add_netjail_helper_(struct GNUNET_TESTING_Interpreter *is, struct GNUNET_HELPER_Handle *helper)
Adding a helper handle to the interpreter.
#define HELPER_CMDS_BINARY
Definition: testing_cmds.h:32
#define NETJAIL_EXEC_SCRIPT
Definition: testing_cmds.h:34

References exp_cb(), GNUNET_array_append, GNUNET_asprintf(), GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_HELPER_start(), GNUNET_log, GNUNET_new, GNUNET_OS_get_libexec_binary_path(), GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_DATADIR, GNUNET_snprintf(), GNUNET_TESTING_add_netjail_helper_(), GNUNET_YES, HelperState::helper, HELPER_CMDS_BINARY, helper_mst(), NETJAIL_EXEC_SCRIPT, ns, HelperState::ns, and send_start_messages().

Referenced by start_peer().

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

◆ do_timeout()

static void do_timeout ( void *  cls)
static

Function run when the cmd terminates (good or bad) with timeout.

Parameters
clsthe interpreter state

Definition at line 511 of file testing_api_cmd_netjail_start_cmds_helper.c.

512{
513 struct NetJailState *ns = cls;
514
515 ns->timeout_task = NULL;
517 "Terminating cmd due to global timeout\n");
519}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_TESTING_async_finish(), and ns.

Referenced by netjail_exec_run().

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

◆ start_peer()

static int start_peer ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 523 of file testing_api_cmd_netjail_start_cmds_helper.c.

526{
527 struct NetJailState *ns = cls;
528
529 if (! start_helper (ns, node_number))
530 {
531 return GNUNET_SYSERR;
532 }
533 node_number++;
534
536 "Peer helper %u started.\n",
538 return GNUNET_OK;
539}
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_DEBUG
static bool start_helper(struct NetJailState *ns, unsigned int script_num)
Function which start a single helper process.
unsigned int node_number
The network namespace number of a node.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, node_number, ns, and start_helper().

Referenced by netjail_exec_run(), start_carriers(), and start_subnets().

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

◆ start_subnets()

static int start_subnets ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 543 of file testing_api_cmd_netjail_start_cmds_helper.c.

546{
547 struct NetJailState *ns = cls;
548 struct GNUNET_TESTING_NetjailSubnet *subnet = value;
549
550 node_number++;
552 "Starting subnet %u.\n",
555 &start_peer,
556 ns))
557 return GNUNET_SYSERR;
559 "Subnet started.\n");
560 return GNUNET_OK;
561}
static char * value
Value of the record to add/remove.
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_MultiShortmap * peers
Hash map containing peers.
static int start_peer(void *cls, const struct GNUNET_ShortHashCode *key, void *value)

References GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, node_number, ns, GNUNET_TESTING_NetjailSubnet::peers, start_peer(), and value.

Referenced by start_carriers().

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

◆ start_carriers()

static int start_carriers ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 565 of file testing_api_cmd_netjail_start_cmds_helper.c.

568{
569 struct NetJailState *ns = cls;
570 struct GNUNET_TESTING_NetjailCarrier *carrier = value;
571
572 node_number++;
574 "Starting carrier %u.\n",
577 &start_peer,
578 ns))
579 return GNUNET_SYSERR;
582 ns))
583 return GNUNET_SYSERR;
584
586 "Carrier started.\n");
587 return GNUNET_OK;
588}
struct GNUNET_CONTAINER_MultiShortmap * subnets
Hash map containing subnets.
struct GNUNET_CONTAINER_MultiShortmap * peers
Hash map containing peers.
static int start_subnets(void *cls, const struct GNUNET_ShortHashCode *key, void *value)

References GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, node_number, ns, GNUNET_TESTING_NetjailCarrier::peers, start_peer(), start_subnets(), GNUNET_TESTING_NetjailCarrier::subnets, and value.

Referenced by netjail_exec_run().

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

◆ netjail_exec_run()

static void netjail_exec_run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 
)
static

This function starts a helper process for each node.

Parameters
clsclosure.
cmdCMD being run.
isinterpreter state.

Definition at line 599 of file testing_api_cmd_netjail_start_cmds_helper.c.

601{
602 struct NetJailState *ns = cls;
603 struct GNUNET_TESTING_NetjailTopology *topology;
604 bool failed = false;
605 const struct GNUNET_TESTING_Command *topo_cmd;
606
607 ns->is = is;
609 ns->topology_cmd_label);
610 if (NULL == topo_cmd)
612 if (GNUNET_OK !=
613 GNUNET_TESTING_get_trait_topology_string (topo_cmd,
614 &ns->topology_data))
616 topology
617 = GNUNET_TESTING_get_topo_from_string_ (ns->topology_data);
619 "Number of nodes: %u\n",
620 topology->total);
622 &start_peer,
623 ns))
624 failed = true;
625 if (true == failed || GNUNET_SYSERR == GNUNET_CONTAINER_multishortmap_iterate (topology->carriers,
627 ns))
628 failed = true;
629
631 if (failed)
632 {
633 ns->failed = true;
635 "Failed to start helpers!\n");
637 }
638 else
639 ns->timeout_task
641 &do_timeout,
642 ns);
643}
static struct GNUNET_TESTING_Interpreter * is
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
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:1276
A command to be run by the interpreter.
Toplogy of our netjail setup.
struct GNUNET_CONTAINER_MultiShortmap * carriers
Hash map containing the carriers.
unsigned int total
Total number of namespaces in the topology.
struct GNUNET_CONTAINER_MultiShortmap * backbone_peers
Hash map containing the carriers.
static void do_timeout(void *cls)
Function run when the cmd terminates (good or bad) with timeout.
static int start_carriers(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
#define LOG(kind,...)
Generic logging shortcut.
void GNUNET_TESTING_free_topology(struct GNUNET_TESTING_NetjailTopology *topology)
Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
struct GNUNET_TESTING_NetjailTopology * GNUNET_TESTING_get_topo_from_string_(const char *input)
Parse the topology data.

References GNUNET_TESTING_NetjailTopology::backbone_peers, GNUNET_TESTING_NetjailTopology::carriers, do_timeout(), GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_TESTING_FAIL, GNUNET_TESTING_free_topology(), GNUNET_TESTING_get_topo_from_string_(), GNUNET_TESTING_interpreter_lookup_command(), is, LOG, ns, start_carriers(), start_peer(), and GNUNET_TESTING_NetjailTopology::total.

Referenced by GNUNET_TESTING_cmd_netjail_start_helpers().

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

◆ netjail_exec_cleanup()

static void netjail_exec_cleanup ( void *  cls)
static

Code to clean up resource this cmd used.

Parameters
clsclosure

Definition at line 652 of file testing_api_cmd_netjail_start_cmds_helper.c.

653{
654 struct NetJailState *ns = cls;
655
656 if (NULL != ns->timeout_task)
657 {
658 GNUNET_SCHEDULER_cancel (ns->timeout_task);
659 ns->timeout_task = NULL;
660 }
661 for (unsigned int i = 0; i<ns->n_helpers; i++)
662 {
663 if (GNUNET_NO == ns->helpers[i]->finished)
664 GNUNET_HELPER_stop (ns->helpers[i]->helper,
665 GNUNET_YES);
666 GNUNET_free (ns->helpers[i]);
667 }
668 GNUNET_free (ns);
669}

References GNUNET_free, GNUNET_HELPER_stop(), GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_YES, and ns.

Referenced by GNUNET_TESTING_cmd_netjail_start_helpers().

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

◆ netjail_exec_traits()

static enum GNUNET_GenericReturnValue netjail_exec_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static

This function prepares an array with traits.

Definition at line 676 of file testing_api_cmd_netjail_start_cmds_helper.c.

680{
681 struct NetJailState *ns = cls;
682 struct GNUNET_TESTING_Trait traits[] = {
684 };
685
686 (void) ns;
688 ret,
689 trait,
690 index);
691}
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

References GNUNET_TESTING_get_trait(), GNUNET_TESTING_trait_end(), GNUNET_TESTING_Trait::index, ns, ret, and traits().

Referenced by GNUNET_TESTING_cmd_netjail_start_helpers().

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

◆ GNUNET_TESTING_cmd_netjail_start_helpers()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_start_helpers ( const char *  label,
const char *  topology_cmd_label,
struct GNUNET_TIME_Relative  timeout 
)

Create command.

Parameters
labelName for the command.
topology_datatopology data
timeoutBefore this timeout is reached this cmd MUST finish.
Returns
command.

Definition at line 703 of file testing_api_cmd_netjail_start_cmds_helper.c.

707{
708 struct NetJailState *ns;
709
710 ns = GNUNET_new (struct NetJailState);
711 ns->topology_cmd_label = topology_cmd_label;
712 ns->timeout = timeout;
714 label,
718 &ns->ac);
719}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:118
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command that may be asynchronous.
const char * topology_cmd_label
Configuration file for the test topology.
static void netjail_exec_cleanup(void *cls)
Code to clean up resource this cmd used.
static void netjail_exec_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
This function starts a helper process for each node.
static enum GNUNET_GenericReturnValue netjail_exec_traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

References GNUNET_new, GNUNET_TESTING_command_new_ac(), netjail_exec_cleanup(), netjail_exec_run(), netjail_exec_traits(), ns, timeout, and NetJailState::topology_cmd_label.

Referenced by main().

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

Variable Documentation

◆ node_number

unsigned int node_number

The network namespace number of a node.

Definition at line 166 of file testing_api_cmd_netjail_start_cmds_helper.c.

Referenced by start_carriers(), start_peer(), and start_subnets().