GNUnet  0.11.x
Data Structures | Macros | Functions
testing_api_cmd_netjail_start_testsystem.c File Reference
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
Include dependency graph for testing_api_cmd_netjail_start_testsystem.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 test environment 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)
 
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_CMDS_HelperInitcreate_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_testing_system (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 31 of file testing_api_cmd_netjail_start_testsystem.c.

◆ TIMEOUT

Definition at line 33 of file testing_api_cmd_netjail_start_testsystem.c.

◆ LOG

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

Generic logging shortcut.

Definition at line 38 of file testing_api_cmd_netjail_start_testsystem.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 214 of file testing_api_cmd_netjail_start_testsystem.c.

215 {
216  struct NetJailState *ns = cls;
217 
218  GNUNET_free (ns);
219 }
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 214 of file testing_api_cmd_netjail_start_testsystem.c.

231 {
232  struct NetJailState *ns = cls;
233  const struct GNUNET_HELPER_Handle **helper = ns->helper;
234 
235 
236  struct GNUNET_TESTING_Trait traits[] = {
239  };
240 
241  return GNUNET_TESTING_get_trait (traits,
242  ret,
243  trait,
244  index);
245 }
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
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 257 of file testing_api_cmd_netjail_start_testsystem.c.

258 {
259  struct TestingSystemCount *tbc = cls;
260 
261  GNUNET_assert (NULL != tbc->shandle);
262  /*GNUNET_free (tbc->shandle);
263  tbc->shandle = NULL;*/
264  GNUNET_free (tbc->msg);
265  tbc->msg = NULL;
266 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Struct containing the number of the test environment and the NetJailState which will be handed to cal...
struct GNUNET_HELPER_SendHandle * shandle
The send handle for the helper.
struct GNUNET_MessageHeader * msg
The messages send to the helper.

References GNUNET_assert, GNUNET_free, TestingSystemCount::msg, 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 270 of file testing_api_cmd_netjail_start_testsystem.c.

276 {
277  const struct GNUNET_HELPER_Handle *helper;
278  struct TestingSystemCount *tbc;
279 
281  "send message of type %u to locals\n",
282  header->type);
283  tbc = GNUNET_new (struct TestingSystemCount);
284  tbc->ns = ns;
285  // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
286  if (0 == i)
287  tbc->count = j; // + total_number;
288  else
289  tbc->count = (i - 1) * ns->local_m + j + ns->known; // + total_number ;
290 
291  helper = ns->helper[tbc->count - 1];// - total_number];
292 
293 
294 
296  (struct GNUNET_HELPER_Handle *) helper,
297  header,
298  GNUNET_NO,
299  &clear_msg,
300  tbc);
301 
302  tbc->shandle = sh;
303  // GNUNET_array_append (tbc->shandle, tbc->n_shandle, sh);
304 }
static struct SolverHandle * sh
@ GNUNET_NO
Definition: gnunet_common.h:94
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:661
@ 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.
unsigned int count
The number of the test environment.
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(), TestingSystemCount::count, 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_testsystem.c.

310 {
312  size_t msg_length;
313 
314 
315  msg_length = sizeof(struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED);
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 }
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED.
Definition: testing_cmds.h:103
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
static void send_message_to_locals(unsigned int i, unsigned int j, struct NetJailState *ns, struct GNUNET_MessageHeader *header)

References GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED, GNUNET_new, GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED::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 326 of file testing_api_cmd_netjail_start_testsystem.c.

327 {
328 
329  struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
330  size_t msg_length;
331 
332 
333  msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
334  reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
335  reply->header.type = htons (
337  reply->header.size = htons ((uint16_t) msg_length);
338 
339  send_message_to_locals (i, j, ns, &reply->header);
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:77

References GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED, GNUNET_new, GNUNET_CMDS_ALL_PEERS_STARTED::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:

◆ 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 356 of file testing_api_cmd_netjail_start_testsystem.c.

357 {
358  // struct TestingSystemCount *tbc = cls;
359  struct NetJailState *ns = cls;
360  unsigned int total_number = ns->local_m * ns->global_n + ns->known;
361  uint16_t message_type = ntohs (message->type);
362 
363  switch (message_type)
364  {
366  ns->number_of_testsystems_started++;
367  break;
369  ns->number_of_peers_started++;
370  if (ns->number_of_peers_started == total_number)
371  {
372  for (int i = 1; i <= ns->known; i++)
373  {
374  send_all_peers_started (0,i, ns);
375  }
376  for (int i = 1; i <= ns->global_n; i++)
377  {
378  for (int j = 1; j <= ns->local_m; j++)
379  {
380  send_all_peers_started (i,j, ns);
381  }
382  }
383  ns->number_of_peers_started = 0;
384  }
385  break;
387  ns->number_of_local_tests_prepared++;
388  if (ns->number_of_local_tests_prepared == total_number)
389  {
390  for (int i = 1; i <= ns->known; i++)
391  {
393  }
394 
395  for (int i = 1; i <= ns->global_n; i++)
396  {
397  for (int j = 1; j <= ns->local_m; j++)
398  {
400  }
401  }
402  }
403  break;
405  ns->number_of_local_tests_finished++;
406  if (ns->number_of_local_tests_finished == total_number)
407  {
408  GNUNET_SCHEDULER_cancel (ns->timeout_task);
410  }
411  break;
412  default:
413  // We received a message we can not handle.
414  GNUNET_assert (0);
415  }
416  /*if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
417  {
418  ns->number_of_testsystems_started++;
419  }
420  else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs (
421  message->type))
422  {
423  ns->number_of_peers_started++;
424  if (ns->number_of_peers_started == total_number)
425  {
426  for (int i = 1; i <= ns->known; i++)
427  {
428  send_all_peers_started (0,i, ns);
429  }
430 
431  for (int i = 1; i <= ns->global_n; i++)
432  {
433  for (int j = 1; j <= ns->local_m; j++)
434  {
435  send_all_peers_started (i,j, ns);
436  }
437  }
438  ns->number_of_peers_started = 0;
439  }
440  }
441  else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED == ntohs (
442  message->type))
443  {
444  ns->number_of_local_tests_prepared++;
445  if (ns->number_of_local_tests_prepared == total_number)
446  {
447  for (int i = 1; i <= ns->known; i++)
448  {
449  send_all_local_tests_prepared (0,i, ns);
450  }
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_local_tests_prepared (i,j, ns);
457  }
458  }
459  }
460  }
461  else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
462  message->type))
463  {
464  ns->number_of_local_tests_finished++;
465  if (ns->number_of_local_tests_finished == total_number)
466  {
467  GNUNET_TESTING_async_finish (&ns->ac);
468  }
469  }
470  else
471  {
472  // We received a message we can not handle.
473  GNUNET_assert (0);
474  }*/
475 
476 
478  "total %u sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n",
479  total_number,
480  ns->number_of_testsystems_started,
481  ns->number_of_peers_started,
482  ns->number_of_local_tests_prepared,
483  ns->number_of_local_tests_finished,
484  ns->local_m,
485  ns->global_n,
486  ns->known);
487 
488 
489 
490 
491  return GNUNET_OK;
492 }
@ GNUNET_OK
Definition: gnunet_common.h:95
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED
#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:972
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)

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, 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_finish(), 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 500 of file testing_api_cmd_netjail_start_testsystem.c.

501 {
502  struct TestingSystemCount *tbc = cls;
503 
504  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
506  GNUNET_TESTING_async_fail (&(tbc->ns->ac));
507 }
#define GNUNET_log(kind,...)
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
struct GNUNET_SCHEDULER_Task * timeout_task
Timeout task.

References NetJailState::ac, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_TESTING_async_fail(), TestingSystemCount::ns, and NetJailState::timeout_task.

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_CMDS_HelperInit* 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 517 of file testing_api_cmd_netjail_start_testsystem.c.

518 {
519  struct GNUNET_CMDS_HelperInit *msg;
520  uint16_t plugin_name_len;
521  uint16_t msg_size;
522 
523  GNUNET_assert (NULL != plugin_name);
524  plugin_name_len = strlen (plugin_name);
525  msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len;
526  msg = GNUNET_malloc (msg_size);
527  msg->header.size = htons (msg_size);
529  msg->plugin_name_size = htons (plugin_name_len);
530  GNUNET_memcpy ((char *) &msg[1],
531  plugin_name,
532  plugin_name_len);
533  return msg;
534 }
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:38

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 542 of file testing_api_cmd_netjail_start_testsystem.c.

545 {
546  struct GNUNET_HELPER_Handle *helper;
547  struct GNUNET_CMDS_HelperInit *msg;
548  struct TestingSystemCount *tbc;
549  char *m_char;
550  char *n_char;
551  char *global_n_char;
552  char *local_m_char;
553  char *known_char;
554  char *node_id;
555  char *plugin;
556  char *read_file;
557  pid_t pid;
558  unsigned int script_num;
559  struct GNUNET_ShortHashCode *hkey;
560  struct GNUNET_HashCode hc;
561  struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
562  struct GNUNET_TESTING_NetjailNode *node;
563  struct GNUNET_TESTING_NetjailNamespace *namespace;
564  char *data_dir;
565  char *script_name;
566 
567 
568  if (0 == n)
569  script_num = m - 1;
570  else
571  script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known;
572  pid = getpid ();
573 
574  GNUNET_asprintf (&m_char, "%u", m);
575  GNUNET_asprintf (&n_char, "%u", n);
576  GNUNET_asprintf (&local_m_char, "%u", ns->local_m);
577  GNUNET_asprintf (&global_n_char, "%u",ns->global_n);
578  GNUNET_asprintf (&known_char, "%u",ns->known);
579  GNUNET_asprintf (&node_id, "%06x-%08x\n",
580  pid,
581  script_num);
582  // GNUNET_asprintf (&topology_data, "'%s'", ns->topology_data);
583  GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
584 
586  GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_EXEC_SCRIPT);
587  unsigned int helper_check = GNUNET_OS_check_helper_binary (
588  script_name,
589  GNUNET_YES,
590  NULL);
591 
592  tbc = GNUNET_new (struct TestingSystemCount);
593  tbc->ns = ns;
594 
595  if (GNUNET_NO == helper_check)
596  {
598  "No SUID for %s!\n",
599  script_name);
601  }
602  else if (GNUNET_NO == helper_check)
603  {
605  "%s not found!\n",
606  script_name);
608  }
609 
611  "sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n",
612  ns->number_of_testsystems_started,
613  ns->number_of_peers_started,
614  ns->number_of_local_tests_prepared,
615  ns->number_of_local_tests_finished,
616  ns->local_m,
617  ns->global_n,
618  ns->known);
619  {
620  char *const script_argv[] = {script_name,
621  m_char,
622  n_char,
625  global_n_char,
626  local_m_char,
627  node_id,
628  read_file,
629  ns->topology_data,
630  NULL};
631  helper = GNUNET_HELPER_start (
632  GNUNET_YES,
633  script_name,
634  script_argv,
635  &helper_mst,
636  &exp_cb,
637  ns);
638  GNUNET_array_append (ns->helper, ns->n_helper, helper);
639  }
640 
641  tbc->count = ns->n_helper;
642  hkey = GNUNET_new (struct GNUNET_ShortHashCode);
643 
644  plugin = topology->plugin;
645 
646  if (0 == m)
647  {
648 
649  GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
650  memcpy (hkey,
651  &hc,
652  sizeof (*hkey));
653  if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_globals,
654  hkey))
655  {
656  node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
657  hkey);
658  if (NULL != node->plugin)
659  plugin = node->plugin;
660  }
661 
662  }
663  else
664  {
665  GNUNET_CRYPTO_hash (&m, sizeof(m), &hc);
666  memcpy (hkey,
667  &hc,
668  sizeof (*hkey));
669  if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_namespaces,
670  hkey))
671  {
672  namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
673  hkey);
674  GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
675  memcpy (hkey,
676  &hc,
677  sizeof (*hkey));
678  if (1 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes,
679  hkey))
680  {
681  node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
682  hkey);
683  if (NULL != node->plugin)
684  plugin = node->plugin;
685  }
686  }
687 
688 
689  }
690 
692 
693  // GNUNET_array_append (tbc->shandle, tbc->n_shandle,
694  tbc->shandle = GNUNET_HELPER_send (
695  helper,
696  &msg->header,
697  GNUNET_NO,
698  &clear_msg,
699  tbc); // );
700 
701  if (NULL == tbc->shandle)// [tbc->count - 1])
702  {
704  "Send handle is NULL!\n");
705  GNUNET_free (msg);
707  }
708  GNUNET_free (hkey);
709 }
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 Plugin * plugin
The process handle to the testbed service.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
@ GNUNET_YES
Definition: gnunet_common.h:97
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
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
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:495
@ 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/)
enum GNUNET_GenericReturnValue read_file(char const *const filename, char **buffer)
Definition: pabc_helper.c:70
A 512-bit hashcode.
A 256-bit hashcode.
Node in the netjail topology.
char * plugin
Plugin for the test case to be run on this node.
static void exp_cb(void *cls)
Callback called if there was an exception during execution of the helper.
static struct GNUNET_CMDS_HelperInit * create_helper_init_msg_(const char *plugin_name)
Function to initialize a init message for 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.
#define HELPER_CMDS_BINARY
Definition: testing_cmds.h:30

References clear_msg(), TestingSystemCount::count, create_helper_init_msg_(), exp_cb(), GNUNET_array_append, GNUNET_asprintf(), GNUNET_CONTAINER_multishortmap_contains(), GNUNET_CONTAINER_multishortmap_get(), 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_TESTING_interpreter_fail(), GNUNET_YES, HELPER_CMDS_BINARY, helper_mst(), LOG, m, msg, NETJAIL_EXEC_SCRIPT, ns, TestingSystemCount::ns, pid, GNUNET_TESTING_NetjailNode::plugin, plugin, read_file(), TestingSystemCount::shandle, and topology.

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 718 of file testing_api_cmd_netjail_start_testsystem.c.

719 {
720  struct NetJailState *ns = cls;
721  struct GNUNET_TESTING_Command *cmd;
722 
723  ns->timeout_task = NULL;
725  "Terminating cmd due to global timeout\n");
728 }
struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_get_current_command(struct GNUNET_TESTING_Interpreter *is)
Returns the actual running command.
A command to be run by the interpreter.
struct GNUNET_TESTING_AsyncContext * ac
Pointer to the asynchronous context in the command's closure.

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 739 of file testing_api_cmd_netjail_start_testsystem.c.

741 {
742  struct NetJailState *ns = cls;
743 
744  ns->is = is;
745  for (int i = 1; i <= ns->known; i++)
746  {
747  start_helper (ns,
748  i,
749  0);
750  }
751 
752  for (int i = 1; i <= ns->global_n; i++)
753  {
754  for (int j = 1; j <= ns->local_m; j++)
755  {
756  start_helper (ns,
757  j,
758  i);
759  }
760  }
762  "Adding timeout %s\n",
764  ns->timeout_task
765  = GNUNET_SCHEDULER_add_delayed (ns->timeout,
766  &do_timeout,
767  ns);
768 }
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
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:1269
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:543
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_testing_system()

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

Create command.

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 739 of file testing_api_cmd_netjail_start_testsystem.c.

788 {
789  struct NetJailState *ns;
790 
791  ns = GNUNET_new (struct NetJailState);
792  ns->local_m = topology->nodes_m;
793  ns->global_n = topology->namespaces_n;
794  ns->known = topology->nodes_x;
795  ns->plugin_name = topology->plugin;
796  ns->topology = topology;
797  ns->read_file = read_file;
798  ns->topology_data = topology_data;
800 
801  struct GNUNET_TESTING_Command cmd = {
802  .cls = ns,
803  .label = label,
804  .run = &netjail_exec_run,
805  .ac = &ns->ac,
806  .cleanup = &netjail_exec_cleanup,
807  .traits = &netjail_exec_traits
808  };
809 
810  return cmd;
811 }
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
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:572
const char * label
Label for the command.
void * cls
Closure for all commands with command-specific context information.
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.