GNUnet 0.21.1
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, const 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...
 
bool 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,
const 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 55 of file testing_api_cmd_barrier.c.

61{
62 // FIXME: avoid useless malloc!
63 struct CommandBarrierAttached *atm = GNUNET_new (struct
65 size_t msg_length = sizeof(struct CommandBarrierAttached);
66 size_t name_len;
67
68 name_len = strlen (barrier_name) + 1;
70 atm->header.size = htons ((uint16_t) msg_length);
72 atm->node_number = global_node_number;
73 memcpy (&atm[1], barrier_name, name_len);
74 write_message ((struct GNUNET_MessageHeader *) atm, msg_length);
75
76 GNUNET_free (atm);
77}
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_()

bool 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
true if we can cross the barrier, false if not.

Definition at line 81 of file testing_api_cmd_barrier.c.

82{
83 unsigned int expected_reaches = barrier->expected_reaches;
84 unsigned int reached = barrier->reached;
85 double percentage_to_be_reached = barrier->percentage_to_be_reached;
86 unsigned int number_to_be_reached = barrier->number_to_be_reached;
87 double percentage_reached = (double) reached / expected_reaches * 100;
88
90 "%u %f %f %u %u\n",
91 expected_reaches,
92 percentage_to_be_reached,
93 percentage_reached,
94 number_to_be_reached,
95 reached);
96
97 return ( ( (0 < percentage_to_be_reached) &&
98 (percentage_reached >= percentage_to_be_reached) ) ||
99 ( (0 < number_to_be_reached) &&
100 (reached >= number_to_be_reached) ) );
101}
@ 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.

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

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 114 of file testing_api_cmd_barrier.c.

118{
119 struct GNUNET_TESTING_Trait traits[] = {
121 };
122
123 return GNUNET_TESTING_get_trait (traits,
124 ret,
125 trait,
126 index);
127}
static int ret
Final status code.
Definition: gnunet-arm.c:94
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.

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

Referenced by GNUNET_TESTING_cmd_barrier_create().

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

◆ 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 137 of file testing_api_cmd_barrier.c.

138{
139 struct BarrierState *brs = cls;
140
141 GNUNET_free (brs->barrier);
142 GNUNET_free (brs);
143}
struct GNUNET_TESTING_Barrier * barrier
Our barrier, set to NULL once the barrier is active.

References BarrierState::barrier, and GNUNET_free.

Referenced by GNUNET_TESTING_cmd_barrier_create().

Here is the caller graph for this function:

◆ 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 153 of file testing_api_cmd_barrier.c.

155{
156 struct BarrierState *brs = cls;
157
159 brs->barrier);
160 brs->barrier = NULL;
161}
struct GNUNET_TESTING_Interpreter * is
void GNUNET_TESTING_add_barrier_(struct GNUNET_TESTING_Interpreter *is, struct GNUNET_TESTING_Barrier *barrier)
Add a barrier to the loop.

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

Referenced by GNUNET_TESTING_cmd_barrier_create().

Here is the call graph for this function:
Here is the caller 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 165 of file testing_api_cmd_barrier.c.

167{
168 struct GNUNET_HashCode hc;
170
171 GNUNET_CRYPTO_hash (&node_number,
172 sizeof(node_number),
173 &hc);
174 memcpy (&key,
175 &hc,
176 sizeof (key));
178 &key);
179}
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 183 of file testing_api_cmd_barrier.c.

186{
187 struct GNUNET_TESTING_Barrier *barrier;
188 struct BarrierState *bs;
189
190 bs = GNUNET_new (struct BarrierState);
191 bs->label = label;
193 barrier->name = label;
194 barrier->percentage_to_be_reached = percentage_to_be_reached;
195 barrier->number_to_be_reached = number_to_be_reached;
196 GNUNET_assert ((0 < percentage_to_be_reached &&
197 0 == number_to_be_reached) ||
198 (0 == percentage_to_be_reached &&
199 0 < number_to_be_reached));
200 bs->barrier = barrier;
205 NULL);
206}
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 * label
Our label.
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.

References BarrierState::barrier, barrier_cleanup(), barrier_run(), barrier_traits(), GNUNET_assert, GNUNET_new, GNUNET_TESTING_command_new(), BarrierState::label, GNUNET_TESTING_Barrier::name, GNUNET_TESTING_Barrier::number_to_be_reached, and GNUNET_TESTING_Barrier::percentage_to_be_reached.

Here is the call graph for this function: