GNUnet  0.20.0
testing_api_cmd_barrier.c File Reference

Barrier functionality. More...

Include dependency graph for testing_api_cmd_barrier.c:

Go to the source code of this file.

Data Structures

struct  BarrierState
 

Macros

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

Functions

void GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is, char *barrier_name, unsigned int global_node_number, unsigned int expected_reaches, GNUNET_TESTING_cmd_helper_write_cb write_message)
 Send Message to master loop that cmds being attached to a barrier. More...
 
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 barrier is finished. More...
 
static enum GNUNET_GenericReturnValue barrier_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 Offer internal data from a "barrier" CMD, to other commands. More...
 
static void barrier_cleanup (void *cls)
 Cleanup the state from a "barrier" CMD, and possibly cancel a pending operation thereof. More...
 
static void barrier_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 Run the command. More...
 
struct GNUNET_TESTING_NetjailNodeGNUNET_TESTING_barrier_get_node (struct GNUNET_TESTING_Barrier *barrier, unsigned int node_number)
 Getting a node from a map by global node number. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_create (const char *label, double percentage_to_be_reached, unsigned int number_to_be_reached)
 Command to create a barrier. More...
 

Detailed Description

Barrier functionality.

Author
t3sserakt

Definition in file testing_api_cmd_barrier.c.

Macro Definition Documentation

◆ LOG

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

Generic logging shortcut.

Definition at line 36 of file testing_api_cmd_barrier.c.

Function Documentation

◆ GNUNET_TESTING_send_barrier_attach()

void GNUNET_TESTING_send_barrier_attach ( struct GNUNET_TESTING_Interpreter is,
char *  barrier_name,
unsigned int  global_node_number,
unsigned int  expected_reaches,
GNUNET_TESTING_cmd_helper_write_cb  write_message 
)

Send Message to master loop that cmds being attached to a barrier.

FIXME: Unused function

Parameters
isThe interpreter loop.
barrier_nameThe name of the barrier to attach to.
subnet_numberThe number of the subnet.
node_numberThe node to inform.
write_messageCallback to write messages to the master loop.

Definition at line 53 of file testing_api_cmd_barrier.c.

59 {
60  struct CommandBarrierAttached *atm = GNUNET_new (struct
62  size_t msg_length = sizeof(struct CommandBarrierAttached);
63  size_t name_len;
64 
65  name_len = strlen (barrier_name) + 1;
67  atm->header.size = htons ((uint16_t) msg_length);
69  atm->node_number = global_node_number;
70  memcpy (&atm[1], barrier_name, name_len);
71  write_message ((struct GNUNET_MessageHeader *) atm, msg_length);
72 
73  GNUNET_free (atm);
74 }
static int write_message(uint16_t message_type, const char *data, size_t data_length)
Write message to the master process.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED
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
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED.
Definition: testing.h:53
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

References CommandBarrierAttached::expected_reaches, GNUNET_free, GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED, GNUNET_new, CommandBarrierAttached::header, CommandBarrierAttached::node_number, GNUNET_MessageHeader::size, GNUNET_MessageHeader::type, and write_message().

Here is the call graph for this function:

◆ GNUNET_TESTING_barrier_crossable()

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 barrier is finished.

Parameters
barrierThe barrier in question.
Returns
GNUNET_YES if we can cross the barrier, GNUNET_NO if not.

Definition at line 78 of file testing_api_cmd_barrier.c.

79 {
80  unsigned int expected_reaches = barrier->expected_reaches;
81  unsigned int reached = barrier->reached;
82  double percentage_to_be_reached = barrier->percentage_to_be_reached;
83  unsigned int number_to_be_reached = barrier->number_to_be_reached;
84  double percentage_reached = (double) reached / expected_reaches * 100;
85 
87  "%u %f %f %u %u\n",
88  expected_reaches,
89  percentage_to_be_reached,
90  percentage_reached,
91  number_to_be_reached,
92  reached);
93 
94  if (((0 < percentage_to_be_reached) &&
95  (percentage_reached >= percentage_to_be_reached)) ||
96  ((0 < number_to_be_reached) && (reached >= number_to_be_reached)))
97  {
98  return GNUNET_YES;
99  }
100  else
101  {
102  return GNUNET_NO;
103  }
104 }
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_DEBUG
unsigned int number_to_be_reached
Number of commands which need to reach the barrier to change state.
Definition: testing.h:209
double percentage_to_be_reached
Percentage of of commands which need to reach the barrier to change state.
Definition: testing.h:203
unsigned int reached
Number of commands which reached this barrier.
Definition: testing.h:197
unsigned int expected_reaches
Number of commands attached to this barrier.
Definition: testing.h:192
#define LOG(kind,...)
Generic logging shortcut.

Referenced by barrier_reached(), and barrier_reached_run().

Here is the caller graph for this function:

◆ barrier_traits()

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

Offer internal data from a "barrier" CMD, to other commands.

Parameters
clsclosure.
[out]retresult.
traitname of the trait.
indexindex number of the object to offer.
Returns
GNUNET_OK on success.

Definition at line 78 of file testing_api_cmd_barrier.c.

121 {
122  struct GNUNET_TESTING_Trait traits[] = {
124  };
125 
126  /* Always return current command. */
127  return GNUNET_TESTING_get_trait (traits,
128  ret,
129  trait,
130  index);
131 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.

References CommandBarrierAttached::expected_reaches, GNUNET_TESTING_Barrier::expected_reaches, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_YES, LOG, GNUNET_TESTING_Barrier::number_to_be_reached, GNUNET_TESTING_Barrier::percentage_to_be_reached, and GNUNET_TESTING_Barrier::reached.

◆ barrier_cleanup()

static void barrier_cleanup ( void *  cls)
static

Cleanup the state from a "barrier" CMD, and possibly cancel a pending operation thereof.

Parameters
clsclosure.

Definition at line 141 of file testing_api_cmd_barrier.c.

142 {
143  struct BarrierState *brs = cls;
144 
145  GNUNET_free (brs);
146 }

References GNUNET_free.

◆ barrier_run()

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

Run the command.

Parameters
clsclosure.
isthe interpreter state.

Definition at line 156 of file testing_api_cmd_barrier.c.

158 {
159  struct BarrierState *brs = cls;
160 
162 }
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_TESTING_Barrier * barrier
void TST_interpreter_add_barrier(struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier)
Add a barrier to the loop.

References BarrierState::barrier, is, and TST_interpreter_add_barrier().

Here is the call graph for this function:

◆ GNUNET_TESTING_barrier_get_node()

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.

FIXME: This is a barrier helper function not related to a command but it is implemented in the *_cmd_barrier.c file. Maybe move into a separate file like testing_barrier.c; see also can barrier advance above

Parameters
nodesThe map.
node_numberThe global node number.
Returns
The node.

Definition at line 166 of file testing_api_cmd_barrier.c.

168 {
169  struct GNUNET_HashCode hc;
170  struct GNUNET_ShortHashCode key;
171 
172  GNUNET_CRYPTO_hash (&(node_number), sizeof(node_number), &hc);
173  memcpy (&key,
174  &hc,
175  sizeof (key));
176  return GNUNET_CONTAINER_multishortmap_get (barrier->nodes, &key);
177 }
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
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.
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

References GNUNET_CONTAINER_multishortmap_get(), GNUNET_CRYPTO_hash(), key, and GNUNET_TESTING_Barrier::nodes.

Referenced by barrier_attached().

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

◆ GNUNET_TESTING_cmd_barrier_create()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_create ( const char *  label,
double  percentage_to_be_reached,
unsigned int  number_to_be_reached 
)

Command to create a barrier.

FIXME: high-level it is baffling how we need both the GNUNET_TESTING_Barrier and the Command that creates barriers. Conceptually this seems to be very much separate. Can we move _Barrier completely into testing as private?

Parameters
labelThe label of this command.
percentage_to_be_reachedIf this percentage of processes reached this barrier, all processes waiting at this barrier can pass it. Must not be used together with number_to_be_reached.
number_to_be_reachedIf this number of processes reached this barrier, all processes waiting at this barrier can pass it. Must not be used together with percentage_to_be_reached.

Definition at line 166 of file testing_api_cmd_barrier.c.

184 {
185  struct GNUNET_TESTING_Barrier *barrier;
186  struct BarrierState *bs;
187 
188  bs = GNUNET_new (struct BarrierState);
189  bs->label = label;
191  barrier->name = label;
192  barrier->percentage_to_be_reached = percentage_to_be_reached;
193  barrier->number_to_be_reached = number_to_be_reached;
194  GNUNET_assert ((0 < percentage_to_be_reached && 0 == number_to_be_reached) ||
195  (0 == percentage_to_be_reached && 0 < number_to_be_reached));
196  bs->barrier = barrier;
197  return GNUNET_TESTING_command_new (bs, label,
198  &barrier_run,
201  NULL);
202 }
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * name
Name of the barrier.
Definition: testing.h:182
static enum GNUNET_GenericReturnValue barrier_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Offer internal data from a "barrier" CMD, to other commands.
static void barrier_cleanup(void *cls)
Cleanup the state from a "barrier" CMD, and possibly cancel a pending operation thereof.
static void barrier_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.