GNUnet  0.20.0
testing_api_cmd_netjail_start_cmds_helper.c File Reference
Include dependency graph for testing_api_cmd_netjail_start_cmds_helper.c:

Go to the source code of this file.

Data Structures

struct  HelperMessage
 Struct to store messages send/received by the helper into a DLL. More...
 
struct  NetJailState
 Struct to hold information for callbacks. More...
 
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 NETJAIL_EXEC_SCRIPT   "netjail_exec.sh"
 
#define TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
 
#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 Generic logging shortcut. More...
 

Functions

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...
 
static void clear_msg (void *cls, int result)
 Continuation function from GNUNET_HELPER_send() More...
 
static void send_message_to_locals (unsigned int i, unsigned int j, struct NetJailState *ns, struct GNUNET_MessageHeader *header)
 
static void send_all_local_tests_prepared (unsigned int i, unsigned int j, struct NetJailState *ns)
 
static void send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
 
void barrier_attached (struct NetJailState *ns, const struct GNUNET_MessageHeader *message)
 
void barrier_reached (struct NetJailState *ns, const struct GNUNET_MessageHeader *message)
 
static int 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 struct GNUNET_TESTING_CommandHelperInitcreate_helper_init_msg_ (const char *plugin_name)
 Function to initialize a init message for the helper. More...
 
static void start_helper (struct NetJailState *ns, unsigned int m, unsigned int n)
 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 void netjail_exec_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 This function starts a helper process for each node. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_start_cmds_helper (const char *label, struct GNUNET_TESTING_NetjailTopology *topology, unsigned int *read_file, char *topology_data, struct GNUNET_TIME_Relative timeout)
 Create command. More...
 

Macro Definition Documentation

◆ NETJAIL_EXEC_SCRIPT

#define NETJAIL_EXEC_SCRIPT   "netjail_exec.sh"

Definition at line 34 of file testing_api_cmd_netjail_start_cmds_helper.c.

◆ TIMEOUT

◆ LOG

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

Generic logging shortcut.

Definition at line 41 of file testing_api_cmd_netjail_start_cmds_helper.c.

Function Documentation

◆ netjail_exec_cleanup()

static void netjail_exec_cleanup ( void *  cls)
static

Code to clean up resource this cmd used.

Parameters
clsclosure

Definition at line 217 of file testing_api_cmd_netjail_start_cmds_helper.c.

218 {
219  struct NetJailState *ns = cls;
220  GNUNET_free (ns);
221 }
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
Definition: gnunet-abd.c:41
#define GNUNET_free(ptr)
Wrapper around free.
Struct to hold information for callbacks.

References GNUNET_free, and ns.

◆ 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 217 of file testing_api_cmd_netjail_start_cmds_helper.c.

233 {
234  struct NetJailState *ns = cls;
235  const struct GNUNET_HELPER_Handle **helper = ns->helper;
236 
237 
238  struct GNUNET_TESTING_Trait traits[] = {
241  };
242 
243  return GNUNET_TESTING_get_trait (traits,
244  ret,
245  trait,
246  index);
247 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_TESTING_Trait GNUNET_TESTING_make_trait_helper_handles(const struct GNUNET_HELPER_Handle **value)
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" trait.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Extract a trait.
The handle to a helper process.
Definition: helper.c:79
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.

◆ clear_msg()

static void clear_msg ( void *  cls,
int  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 259 of file testing_api_cmd_netjail_start_cmds_helper.c.

260 {
261  struct TestingSystemCount *tbc = cls;
262 
263  GNUNET_assert (NULL != tbc->shandle);
264  // GNUNET_free (tbc->shandle);
265  GNUNET_free (tbc->plugin);
266  tbc->shandle = NULL;
267  GNUNET_free (tbc);
268 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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 TestcasePlugin * plugin
The plugin correlated to this netjail node.

References GNUNET_assert, GNUNET_free, TestingSystemCount::plugin, and TestingSystemCount::shandle.

Referenced by send_message_to_locals(), and start_helper().

Here is the caller graph for this function:

◆ send_message_to_locals()

static void send_message_to_locals ( unsigned int  i,
unsigned int  j,
struct NetJailState ns,
struct GNUNET_MessageHeader header 
)
static

Definition at line 272 of file testing_api_cmd_netjail_start_cmds_helper.c.

278 {
279  const struct GNUNET_HELPER_Handle *helper;
280  struct TestingSystemCount *tbc;
281  unsigned int count;
282 
284  "send message of type %u to locals\n",
285  header->type);
286  tbc = GNUNET_new (struct TestingSystemCount);
287  tbc->ns = ns;
288  if (0 == i)
289  count = j;
290  else
291  count = (i - 1) * ns->local_m + j + ns->known;
292 
293  helper = ns->helper[count - 1];
294 
295 
297  (struct GNUNET_HELPER_Handle *) helper,
298  header,
299  GNUNET_NO,
300  &clear_msg,
301  tbc);
302 
303  tbc->shandle = sh;
304 }
static struct SolverHandle * sh
struct GNUNET_HELPER_SendHandle * GNUNET_HELPER_send(struct GNUNET_HELPER_Handle *h, const struct GNUNET_MessageHeader *msg, int can_drop, GNUNET_HELPER_Continuation cont, void *cont_cls)
Send an message to the helper.
Definition: helper.c:615
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Entry in the queue of messages we need to transmit to the helper.
Definition: helper.c:37
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct NetJailState * ns
Struct to store information handed over to callbacks.
static void clear_msg(void *cls, int result)
Continuation function from GNUNET_HELPER_send()
#define LOG(kind,...)
Generic logging shortcut.

References clear_msg(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELPER_send(), GNUNET_new, GNUNET_NO, LOG, ns, TestingSystemCount::ns, sh, TestingSystemCount::shandle, and GNUNET_MessageHeader::type.

Referenced by send_all_local_tests_prepared(), and send_all_peers_started().

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

◆ send_all_local_tests_prepared()

static void send_all_local_tests_prepared ( unsigned int  i,
unsigned int  j,
struct NetJailState ns 
)
static

Definition at line 308 of file testing_api_cmd_netjail_start_cmds_helper.c.

310 {
312  size_t msg_length;
313 
314 
315  msg_length = sizeof(struct GNUNET_TESTING_CommandAllLocalTestsPrepared);
317  reply->header.type = htons (
319  reply->header.size = htons ((uint16_t) msg_length);
320 
321  send_message_to_locals (i, j, ns, &reply->header);
322  GNUNET_free (reply);
323 }
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED
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_ALL_LOCAL_TESTS_PREPARED.
Definition: testing_cmds.h:108
static void send_message_to_locals(unsigned int i, unsigned int j, struct NetJailState *ns, struct GNUNET_MessageHeader *header)

References GNUNET_free, GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED, GNUNET_new, GNUNET_TESTING_CommandAllLocalTestsPrepared::header, ns, send_message_to_locals(), GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by helper_mst().

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

◆ send_all_peers_started()

static void send_all_peers_started ( unsigned int  i,
unsigned int  j,
struct NetJailState ns 
)
static

Definition at line 327 of file testing_api_cmd_netjail_start_cmds_helper.c.

328 {
330  size_t msg_length;
331 
332  msg_length = sizeof(struct GNUNET_TESTING_CommandAllPeersStarted);
334  reply->header.type = htons (
336  reply->header.size = htons ((uint16_t) msg_length);
337 
338  send_message_to_locals (i, j, ns, &reply->header);
339  GNUNET_free (reply);
340 }
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED.
Definition: testing_cmds.h:78

References GNUNET_free, GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED, GNUNET_new, GNUNET_TESTING_CommandAllPeersStarted::header, ns, send_message_to_locals(), GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by helper_mst().

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

◆ barrier_attached()

void barrier_attached ( struct NetJailState ns,
const struct GNUNET_MessageHeader message 
)

Definition at line 344 of file testing_api_cmd_netjail_start_cmds_helper.c.

346 {
347  struct CommandBarrierAttached *am;
348  struct GNUNET_TESTING_NetjailNode *node;
349  struct GNUNET_TESTING_Barrier *barrier;
350  struct GNUNET_ShortHashCode key;
351  struct GNUNET_HashCode hc;
352  const char *barrier_name;
353 
354  am = (struct CommandBarrierAttached *) message;
355  barrier_name = (const char *) &am[1];
356  barrier = TST_interpreter_get_barrier (ns->is, barrier_name);
357  GNUNET_assert (NULL != barrier);
358  node = GNUNET_TESTING_barrier_get_node (barrier, am->node_number);
359  if (NULL == node)
360  {
361  node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
362  node->node_number = am->node_number;
363 
364  GNUNET_CRYPTO_hash (&(node->node_number), sizeof(node->node_number), &hc);
365  memcpy (&key, &hc, sizeof (key));
367  &key,
368  node,
370  }
372  barrier->expected_reaches = barrier->expected_reaches + am->expected_reaches;
373 }
struct GNUNET_HashCode key
The key used in the DHT.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
Message send by a child loop to inform the master loop how much GNUNET_CMDS_BARRIER_REACHED messages ...
Definition: testing.h:49
uint32_t expected_reaches
How often the child loop will reach the barrier.
Definition: testing.h:58
uint32_t node_number
The number of the node the barrier is running on.
Definition: testing.h:63
A 512-bit hashcode.
A 256-bit hashcode.
struct GNUNET_CONTAINER_MultiShortmap * nodes
Hash map containing the global known nodes which are not natted.
Definition: testing.h:177
unsigned int expected_reaches
Number of commands attached to this barrier.
Definition: testing.h:192
Node in the netjail topology.
unsigned int node_number
The overall number of the node in the whole test system.
unsigned int expected_reaches
The number of cmds waiting for a specific barrier.
struct GNUNET_TESTING_NetjailNode * GNUNET_TESTING_barrier_get_node(struct GNUNET_TESTING_Barrier *barrier, unsigned int node_number)
Getting a node from a map by global node number.
struct GNUNET_TESTING_Barrier * TST_interpreter_get_barrier(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
Getting a barrier from the interpreter.

References GNUNET_TESTING_NetjailNode::expected_reaches, CommandBarrierAttached::expected_reaches, GNUNET_TESTING_Barrier::expected_reaches, GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multishortmap_put(), GNUNET_CRYPTO_hash(), GNUNET_new, GNUNET_TESTING_barrier_get_node(), key, GNUNET_TESTING_NetjailNode::node_number, CommandBarrierAttached::node_number, GNUNET_TESTING_Barrier::nodes, ns, and TST_interpreter_get_barrier().

Referenced by helper_mst().

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

◆ barrier_reached()

void barrier_reached ( struct NetJailState ns,
const struct GNUNET_MessageHeader message 
)

Definition at line 377 of file testing_api_cmd_netjail_start_cmds_helper.c.

379 {
380  struct GNUNET_TESTING_Barrier *barrier;
381  const char *barrier_name;
382  struct GNUNET_TESTING_CommandBarrierReached *rm = (struct
384  *) message;
385 
386  barrier_name = (const char *) &rm[1];
387 
388  barrier = TST_interpreter_get_barrier (ns->is, barrier_name);
389  GNUNET_assert (NULL != barrier);
391  "barrier %s reached %p %u\n",
392  barrier_name,
393  barrier,
394  barrier->reached);
395  barrier->reached++;
397  "%u %p\n",
398  barrier->reached,
399  barrier);
400  if (GNUNET_TESTING_barrier_crossable (barrier))
401  {
403  "%s can be crossed\n",
404  barrier_name);
406  }
408  "barrier %s reached finished\n",
409  barrier_name);
410 }
const char * name
Name of the barrier.
Definition: testing.h:182
unsigned int reached
Number of commands which reached this barrier.
Definition: testing.h:197
void TST_interpreter_finish_attached_cmds(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
Finish all "barrier reached" comands attached to this barrier.
unsigned int GNUNET_TESTING_barrier_crossable(struct GNUNET_TESTING_Barrier *barrier)
This function checks, if a barrier can be crossed, which actually means that the cmd representing the...

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_TESTING_barrier_crossable(), LOG, GNUNET_TESTING_Barrier::name, ns, GNUNET_TESTING_Barrier::reached, TST_interpreter_finish_attached_cmds(), and TST_interpreter_get_barrier().

Referenced by helper_mst().

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

◆ helper_mst()

static int 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
clientidentification of the client
messagethe actual message
Returns
GNUNET_OK on success, GNUNET_SYSERR to stop further processing

Definition at line 426 of file testing_api_cmd_netjail_start_cmds_helper.c.

427 {
428  struct NetJailState *ns = cls;
429  unsigned int total_number = ns->local_m * ns->global_n + ns->known;
430  uint16_t message_type = ntohs (message->type);
432 
433  switch (message_type)
434  {
436  barrier_attached (ns, message);
437  break;
439  barrier_reached (ns, message);
440  break;
442  ns->number_of_testsystems_started++;
443  break;
445  ns->number_of_peers_started++;
446  if (ns->number_of_peers_started == total_number)
447  {
448  for (int i = 1; i <= ns->known; i++)
449  {
450  send_all_peers_started (0,i, ns);
451  }
452  for (int i = 1; i <= ns->global_n; i++)
453  {
454  for (int j = 1; j <= ns->local_m; j++)
455  {
456  send_all_peers_started (i,j, ns);
457  }
458  }
459  ns->number_of_peers_started = 0;
460  }
461  break;
463  ns->number_of_local_tests_prepared++;
464  if (ns->number_of_local_tests_prepared == total_number)
465  {
466  for (int i = 1; i <= ns->known; i++)
467  {
469  }
470 
471  for (int i = 1; i <= ns->global_n; i++)
472  {
473  for (int j = 1; j <= ns->local_m; j++)
474  {
476  }
477  }
478  }
479  break;
481  lf = (struct GNUNET_TESTING_CommandLocalFinished *) message;
482 
483  ns->number_of_local_tests_finished++;
484  if (GNUNET_OK != lf->rv)
485  {
486  GNUNET_TESTING_async_fail (&(ns->ac));
487  }
488  else if (ns->number_of_local_tests_finished == total_number)
489  {
490  GNUNET_SCHEDULER_cancel (ns->timeout_task);
491  ns->timeout_task = NULL;
493  }
494  break;
495  default:
496  // We received a message we can not handle.
497  GNUNET_assert (0);
498  }
499 
501  "total %u sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n",
502  total_number,
503  ns->number_of_testsystems_started,
504  ns->number_of_peers_started,
505  ns->number_of_local_tests_prepared,
506  ns->number_of_local_tests_finished,
507  ns->local_m,
508  ns->global_n,
509  ns->known);
510 
511 
512  return GNUNET_OK;
513 }
void lf(char *msg)
Definition: gnunet_gst.c:587
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.
@ GNUNET_OK
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY
The reply message from gnunet-cmds-helper.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
void barrier_attached(struct NetJailState *ns, const struct GNUNET_MessageHeader *message)
static void send_all_peers_started(unsigned int i, unsigned int j, struct NetJailState *ns)
static void send_all_local_tests_prepared(unsigned int i, unsigned int j, struct NetJailState *ns)
void barrier_reached(struct NetJailState *ns, const struct GNUNET_MessageHeader *message)

References barrier_attached(), barrier_reached(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED, GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED, GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED, GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED, GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED, GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_TESTING_async_fail(), GNUNET_TESTING_async_finish(), lf(), LOG, ns, send_all_local_tests_prepared(), send_all_peers_started(), and GNUNET_MessageHeader::type.

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 521 of file testing_api_cmd_netjail_start_cmds_helper.c.

522 {
523  struct NetJailState *ns = cls;
524 
525  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
526  if (NULL != ns->timeout_task)
527  GNUNET_SCHEDULER_cancel (ns->timeout_task);
528  GNUNET_TESTING_async_fail (&(ns->ac));
529 }
#define GNUNET_log(kind,...)

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_TESTING_async_fail(), and 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:

◆ create_helper_init_msg_()

static struct GNUNET_TESTING_CommandHelperInit* create_helper_init_msg_ ( const char *  plugin_name)
static

Function to initialize a init message for the helper.

Parameters
plugin_nameName of the test case plugin the helper will load.

Definition at line 539 of file testing_api_cmd_netjail_start_cmds_helper.c.

540 {
542  uint16_t plugin_name_len;
543  uint16_t msg_size;
544 
545  GNUNET_assert (NULL != plugin_name);
546  plugin_name_len = strlen (plugin_name);
547  msg_size = sizeof(struct GNUNET_TESTING_CommandHelperInit) + plugin_name_len;
548  msg = GNUNET_malloc (msg_size);
549  msg->header.size = htons (msg_size);
551  msg->plugin_name_size = htons (plugin_name_len);
552  GNUNET_memcpy ((char *) &msg[1],
553  plugin_name,
554  plugin_name_len);
555  return msg;
556 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static char * plugin_name
Name of our plugin.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT
The initialization message towards gnunet-cmds-helper.
Initialization message for gnunet-cmds-testbed to start cmd binary.
Definition: testing_cmds.h:39

References GNUNET_assert, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT, msg, plugin_name, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by start_helper().

Here is the caller graph for this function:

◆ start_helper()

static void start_helper ( struct NetJailState ns,
unsigned int  m,
unsigned int  n 
)
static

Function which start a single helper process.

Definition at line 564 of file testing_api_cmd_netjail_start_cmds_helper.c.

567 {
568  struct TestcasePlugin *plugin;
569  struct GNUNET_HELPER_Handle *helper;
571  struct TestingSystemCount *tbc;
572  char *m_char;
573  char *n_char;
574  char *global_n_char;
575  char *local_m_char;
576  char *known_char;
577  char *node_id;
578  char *plugin_name;
579  char *read_file;
580  pid_t pid;
581  unsigned int script_num;
582  struct GNUNET_ShortHashCode *hkey;
583  struct GNUNET_ShortHashCode key;
584  struct GNUNET_HashCode hc;
585  struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
586  struct GNUNET_TESTING_NetjailNode *node;
587  struct GNUNET_TESTING_NetjailNode *barrier_node;
588  struct GNUNET_TESTING_NetjailNamespace *namespace;
589  char *data_dir;
590  char *script_name;
592  struct GNUNET_TESTING_Barrier *barrier;
593  struct GNUNET_TESTING_BarrierList *barriers;
594  unsigned int node_num;
595  char *binary_path;
596 
597  if (0 == n)
598  {
599  node_num = m;
600  script_num = m - 1;
601  }
602  else
603  {
604  node_num = (n - 1) * ns->local_m + m + ns->known;
605  script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known;
606  }
607  pid = getpid ();
608 
609  GNUNET_asprintf (&m_char, "%u", m);
610  GNUNET_asprintf (&n_char, "%u", n);
611  GNUNET_asprintf (&local_m_char, "%u", ns->local_m);
612  GNUNET_asprintf (&global_n_char, "%u",ns->global_n);
613  GNUNET_asprintf (&known_char, "%u",ns->known);
614  GNUNET_asprintf (&node_id, "%s%06x-%06x\n",
615  "if",
616  pid,
617  script_num);
618  // GNUNET_asprintf (&topology_data, "'%s'", ns->topology_data);
619  GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
620 
622  GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_EXEC_SCRIPT);
623  unsigned int helper_check = GNUNET_OS_check_helper_binary (
624  script_name,
625  GNUNET_YES,
626  NULL);
627 
628  tbc = GNUNET_new (struct TestingSystemCount);
629  tbc->ns = ns;
630 
631  if (GNUNET_NO == helper_check)
632  {
634  "No SUID for %s!\n",
635  script_name);
637  }
638  else if (GNUNET_NO == helper_check)
639  {
641  "%s not found!\n",
642  script_name);
644  }
645 
647 
649  "sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n",
650  ns->number_of_testsystems_started,
651  ns->number_of_peers_started,
652  ns->number_of_local_tests_prepared,
653  ns->number_of_local_tests_finished,
654  ns->local_m,
655  ns->global_n,
656  ns->known);
657  {
658  char *const script_argv[] = {script_name,
659  m_char,
660  n_char,
661  binary_path,
662  global_n_char,
663  local_m_char,
664  node_id,
665  read_file,
666  ns->topology_data,
667  NULL};
668  helper = GNUNET_HELPER_start (
669  GNUNET_YES,
670  script_name,
671  script_argv,
672  &helper_mst,
673  &exp_cb,
674  ns);
675  GNUNET_array_append (ns->helper, ns->n_helper, helper);
676  }
678  helper);
679  plugin_name = topology->plugin;
680 
681  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
682  if (0 == n)
683  {
684  GNUNET_CRYPTO_hash (&m, sizeof(m), &hc);
685  memcpy (hkey,
686  &hc,
687  sizeof (*hkey));
688  if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_globals,
689  hkey))
690  {
691  node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
692  hkey);
693  if (NULL != node->plugin)
694  plugin_name = node->plugin;
695  }
696  }
697  else
698  {
699  GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
700  memcpy (hkey,
701  &hc,
702  sizeof (*hkey));
703  if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_namespaces,
704  hkey))
705  {
706  namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
707  hkey);
708  GNUNET_CRYPTO_hash (&m, sizeof(m), &hc);
709  memcpy (hkey,
710  &hc,
711  sizeof (*hkey));
712  if (1 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes,
713  hkey))
714  {
715  node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
716  hkey);
717  if (NULL != node->plugin)
718  plugin_name = node->plugin;
719  }
720  }
721 
722 
723  }
724  GNUNET_assert (NULL != node);
725  node->node_number = node_num;
726  plugin = GNUNET_new (struct TestcasePlugin);
728  NULL);
729  barriers = plugin->api->get_waiting_for_barriers ();
730 
731 
732  for (pos = barriers->head; NULL != pos; pos = pos->next)
733  {
734  barrier = TST_interpreter_get_barrier (ns->is, pos->barrier_name);
735  if (NULL == barrier)
736  {
738  "barrier %s added\n",
739  pos->barrier_name);
740  barrier = GNUNET_new (struct GNUNET_TESTING_Barrier);
741  barrier->name = pos->barrier_name;
742  barrier->shadow = GNUNET_YES;
743  TST_interpreter_add_barrier (ns->is, barrier);
744 
746  "%u %p\n",
747  barrier->reached,
748  barrier);
749 
751  }
753  "barrier %p %s node %u added \n",
754  barrier,
755  pos->barrier_name,
756  node->node_number);
757  barrier_node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
758  barrier_node->node_number = node->node_number;
759  barrier_node->expected_reaches = pos->expected_reaches;
760  barrier->expected_reaches = barrier->expected_reaches
761  + pos->expected_reaches;
763  "number_to_be_reached %u\n",
764  barrier->number_to_be_reached);
765  if (GNUNET_YES == barrier->shadow)
766  barrier->number_to_be_reached++;
768  "number_to_be_reached %u\n",
769  barrier->number_to_be_reached);
770  GNUNET_CRYPTO_hash (&(node->node_number), sizeof(node->node_number), &hc);
771  memcpy (&key, &hc, sizeof (key));
773  &key,
774  barrier_node,
776  }
777 
778  tbc->plugin = plugin;
779 
781 
782  tbc->shandle = GNUNET_HELPER_send (
783  helper,
784  &msg->header,
785  GNUNET_NO,
786  &clear_msg,
787  tbc);
788 
789  if (NULL == tbc->shandle)
790  {
792  "Send handle is NULL!\n");
794  }
795  GNUNET_free (pos);
796  GNUNET_free (binary_path);
797  GNUNET_free (hkey);
798  GNUNET_free (msg);
799  GNUNET_free (m_char);
800  GNUNET_free (n_char);
801  GNUNET_free (local_m_char);
802  GNUNET_free (global_n_char);
803  GNUNET_free (known_char);
804  GNUNET_free (node_id);
806  GNUNET_free (data_dir);
807  GNUNET_free (script_name);
808  GNUNET_free (barriers);
809 }
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
struct TestcasePlugin * plugin
The process handle to the testbed service.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
int GNUNET_CONTAINER_multishortmap_contains(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
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:462
@ GNUNET_YES
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
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 ...
enum GNUNET_GenericReturnValue GNUNET_OS_check_helper_binary(const char *binary, bool check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
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,...
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
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
enum GNUNET_GenericReturnValue read_file(char const *const filename, char **buffer)
Definition: pabc_helper.c:71
An entry for a barrier list.
unsigned int expected_reaches
Number of commands attached to the barrier.
struct GNUNET_TESTING_BarrierListEntry * next
A list to hold barriers provided by plugins.
struct GNUNET_TESTING_BarrierListEntry * head
List head.
unsigned int shadow
Definition: testing.h:214
unsigned int number_to_be_reached
Number of commands which need to reach the barrier to change state.
Definition: testing.h:209
char * plugin
Plugin for the test case to be run on this node.
GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS get_waiting_for_barriers
Handle for a plugin.
Definition: testing.h:94
struct GNUNET_TESTING_PluginFunctions * api
Plugin API.
Definition: testing.h:103
void TST_interpreter_add_barrier(struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier)
Add a barrier to the loop.
static struct GNUNET_TESTING_CommandHelperInit * create_helper_init_msg_(const char *plugin_name)
Function to initialize a init message for the helper.
static void exp_cb(void *cls)
Callback called if there was an exception during execution of the helper.
static int helper_mst(void *cls, const struct GNUNET_MessageHeader *message)
Functions with this signature are called whenever a complete message is received by the tokenizer.
void GNUNET_TESTING_add_netjail_helper(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_HELPER_Handle *helper)
Adding a helper handle to the interpreter.
#define HELPER_CMDS_BINARY
Definition: testing_cmds.h:30

References TestcasePlugin::api, GNUNET_TESTING_BarrierListEntry::barrier_name, clear_msg(), create_helper_init_msg_(), exp_cb(), GNUNET_TESTING_BarrierListEntry::expected_reaches, GNUNET_TESTING_NetjailNode::expected_reaches, GNUNET_TESTING_Barrier::expected_reaches, GNUNET_TESTING_PluginFunctions::get_waiting_for_barriers, GNUNET_array_append, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multishortmap_contains(), GNUNET_CONTAINER_multishortmap_create(), GNUNET_CONTAINER_multishortmap_get(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_HELPER_send(), GNUNET_HELPER_start(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OS_check_helper_binary(), GNUNET_OS_get_libexec_binary_path(), GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_DATADIR, GNUNET_PLUGIN_load(), GNUNET_TESTING_add_netjail_helper(), GNUNET_TESTING_interpreter_fail(), GNUNET_YES, GNUNET_TESTING_BarrierList::head, HELPER_CMDS_BINARY, helper_mst(), key, LOG, m, msg, GNUNET_TESTING_Barrier::name, NETJAIL_EXEC_SCRIPT, GNUNET_TESTING_BarrierListEntry::next, GNUNET_TESTING_NetjailNode::node_number, GNUNET_TESTING_Barrier::nodes, ns, TestingSystemCount::ns, GNUNET_TESTING_Barrier::number_to_be_reached, pid, GNUNET_TESTING_NetjailNode::plugin, plugin, TestingSystemCount::plugin, plugin_name, GNUNET_TESTING_Barrier::reached, read_file(), GNUNET_TESTING_Barrier::shadow, TestingSystemCount::shandle, topology, TST_interpreter_add_barrier(), and TST_interpreter_get_barrier().

Referenced by netjail_exec_run().

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 818 of file testing_api_cmd_netjail_start_cmds_helper.c.

819 {
820  struct NetJailState *ns = cls;
821  struct GNUNET_TESTING_Command *cmd;
822 
823  ns->timeout_task = NULL;
825  "Terminating cmd due to global timeout\n");
828 }
A command to be run by the interpreter.
struct GNUNET_TESTING_AsyncContext * ac
Pointer to the asynchronous context in the command's closure.
struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_get_current_command(struct GNUNET_TESTING_Interpreter *is)
Returns the actual running command.

References GNUNET_TESTING_Command::ac, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_TESTING_async_finish(), GNUNET_TESTING_interpreter_get_current_command(), and ns.

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 839 of file testing_api_cmd_netjail_start_cmds_helper.c.

841 {
842  struct NetJailState *ns = cls;
843 
844  ns->is = is;
845  for (int i = 1; i <= ns->known; i++)
846  {
848  "i %u\n",
849  i);
850  start_helper (ns,
851  i,
852  0);
853  }
854 
855  for (int i = 1; i <= ns->global_n; i++)
856  {
857  for (int j = 1; j <= ns->local_m; j++)
858  {
860  "i %u j %u\n",
861  i,
862  j);
863  start_helper (ns,
864  j,
865  i);
866  }
867  }
869  "Adding timeout %s\n",
871  ns->timeout_task
872  = GNUNET_SCHEDULER_add_delayed (ns->timeout,
873  &do_timeout,
874  ns);
875 }
struct GNUNET_TESTING_Interpreter * is
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
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:569
static void do_timeout(void *cls)
Function run when the cmd terminates (good or bad) with timeout.
static void start_helper(struct NetJailState *ns, unsigned int m, unsigned int n)
Function which start a single helper process.

References do_timeout(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), is, ns, and start_helper().

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_netjail_start_cmds_helper()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_start_cmds_helper ( const char *  label,
struct GNUNET_TESTING_NetjailTopology topology,
unsigned int *  read_file,
char *  topology_data,
struct GNUNET_TIME_Relative  timeout 
)

Create command.

This command executes a shell script which starts a helper process.

Parameters
labelName for the command.
topologyThe complete topology information.
read_fileFlag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
topology_dataIf read_file is GNUNET_NO, topology_data holds the string with the topology.
timeoutBefore this timeout is reached this cmd MUST finish.
Returns
command.

Definition at line 839 of file testing_api_cmd_netjail_start_cmds_helper.c.

895 {
896  struct NetJailState *ns;
897 
898  ns = GNUNET_new (struct NetJailState);
899  ns->local_m = topology->nodes_m;
900  ns->global_n = topology->namespaces_n;
901  ns->known = topology->nodes_x;
902  ns->plugin_name = topology->plugin;
903  ns->topology = topology;
904  ns->read_file = read_file;
905  ns->topology_data = topology_data;
907 
908  return GNUNET_TESTING_command_new (ns, label,
912  &ns->ac);
913 }
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new(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.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Subtract relative timestamp from the other.
Definition: time.c:603
char * topology_data
String with topology data or name of topology file.
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.