GNUnet  0.11.x
Data Structures | Macros | Functions
testing_messenger_setup.c File Reference
#include "testing_messenger_setup.h"
#include <stdio.h>
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testbed_logger_service.h"
#include "gnunet_testbed_service.h"
#include "gnunet_testing_lib.h"
#include "gnunet_messenger_service.h"
#include "testing_messenger_barrier.h"
Include dependency graph for testing_messenger_setup.c:

Go to the source code of this file.

Data Structures

struct  test_peer
 
struct  test_properties
 

Macros

#define TEST_ROOM   "test"
 
#define TEST_NAME   "tester"
 

Functions

static void shutdown_cb (void *cls)
 
static void end_cb (void *cls)
 
static void end_badly_cb (void *cls)
 
static void end_operation_cb (void *cls)
 
static void end_error_cb (void *cls)
 
static void barrier2_wait_cb (void *cls, struct GNUNET_BarrierWaitHandle *waiting, int status)
 
static void barrier_wait_cb (void *cls, struct GNUNET_BarrierWaitHandle *waiting, int status)
 
static void on_message (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_MessageFlags flags)
 Function called whenever a message is received or sent. More...
 
static void second_stage (void *cls)
 
static void on_peer (void *cb_cls, struct GNUNET_TESTBED_Operation *op, const struct GNUNET_TESTBED_PeerInformation *pinfo, const char *emsg)
 
static void run (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
 Main function for a peer of the testcase. More...
 
static void barrier2_cb (void *cls, struct GNUNET_BarrierHandle *barrier, int status)
 
static void barrier_cb (void *cls, struct GNUNET_BarrierHandle *barrier, int status)
 
static void init (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, unsigned int links_succeeded, unsigned int links_failed)
 
int GNUNET_run_messenger_setup (const char *test_name, const struct test_configuration *cfg)
 

Macro Definition Documentation

◆ TEST_ROOM

#define TEST_ROOM   "test"

Definition at line 37 of file testing_messenger_setup.c.

Referenced by barrier_wait_cb(), on_peer(), and second_stage().

◆ TEST_NAME

#define TEST_NAME   "tester"

Definition at line 38 of file testing_messenger_setup.c.

Referenced by on_peer().

Function Documentation

◆ shutdown_cb()

static void shutdown_cb ( void *  cls)
static

Definition at line 78 of file testing_messenger_setup.c.

References test_properties::barrier, test_properties::die_task, test_properties::end_task, GNUNET_assert, GNUNET_cancel_barrier(), GNUNET_cancel_wait_barrier(), GNUNET_MESSENGER_close_room(), GNUNET_MESSENGER_disconnect(), GNUNET_SCHEDULER_cancel(), GNUNET_TESTBED_operation_done(), test_peer::handle, test_properties::num_peer, test_peer::op, test_peer::op_task, test_peer::peer, test_properties::peers, test_peer::room, and test_peer::wait.

Referenced by init().

79 {
80  struct test_properties *properties = cls;
81 
82 
83  for (unsigned int i = 0; i < properties->num_peer; i++)
84  {
85  struct test_peer *peer = &properties->peers[i];
86 
87  GNUNET_assert(peer != NULL);
88 
89  if (peer->op_task)
91 
92  peer->op_task = NULL;
93 
94  if (peer->op)
96 
97  peer->op = NULL;
98 
99  if (peer->wait)
101 
102  peer->wait = NULL;
103 
104  if (peer->room)
106 
107  peer->room = NULL;
108 
109  if (peer->handle)
111 
112  peer->handle = NULL;
113  }
114 
115  if (properties->die_task)
116  GNUNET_SCHEDULER_cancel(properties->die_task);
117 
118  properties->die_task = NULL;
119  properties->end_task = NULL;
120 
121  if (properties->barrier)
122  GNUNET_cancel_barrier(properties->barrier);
123 
124  properties->barrier = NULL;
125 }
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_BarrierWaitHandle * wait
void GNUNET_MESSENGER_close_room(struct GNUNET_MESSENGER_Room *room)
Close a room which was entered, opened or both in various order and variety.
struct GNUNET_SCHEDULER_Task * end_task
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct test_peer * peers
struct GNUNET_SCHEDULER_Task * op_task
struct GNUNET_BarrierHandle * barrier
struct GNUNET_SCHEDULER_Task * die_task
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2045
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_TESTBED_Operation * op
void GNUNET_cancel_wait_barrier(struct GNUNET_BarrierWaitHandle *waiting)
Cancel a pseudo-barrier wait handle.
void GNUNET_MESSENGER_disconnect(struct GNUNET_MESSENGER_Handle *handle)
Disconnect all of the messengers used services and clears up its used memory.
struct GNUNET_MESSENGER_Room * room
void GNUNET_cancel_barrier(struct GNUNET_BarrierHandle *barrier)
Cancel a pseudo-barrier.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end_cb()

static void end_cb ( void *  cls)
static

Definition at line 130 of file testing_messenger_setup.c.

References test_properties::die_task, GNUNET_assert, GNUNET_MESSENGER_iterate_members(), GNUNET_SCHEDULER_shutdown(), test_properties::num_peer, test_peer::peer, test_properties::peers, test_peer::props, test_peer::room, test_properties::status, and status.

Referenced by barrier2_cb(), and end_badly_cb().

131 {
132  struct test_properties *properties = cls;
133 
134  GNUNET_assert(properties != NULL);
135 
136  properties->die_task = NULL;
137 
138  int status = 0;
139 
140  for (unsigned int i = 0; i < properties->num_peer; i++)
141  {
142  struct test_peer *peer = &properties->peers[i];
143 
144  GNUNET_assert(peer != NULL);
145 
146  const int members = GNUNET_MESSENGER_iterate_members(peer->room, NULL, NULL);
147 
148  GNUNET_assert (members >= 0);
149 
150  if (peer->props->num_peer != (unsigned int) members)
151  {
152  fprintf (stderr, "Testcase failed (members: %d/%u).\n", members, peer->props->num_peer);
153  status = 1;
154  break;
155  }
156  }
157 
159 
160  properties->status = status;
161 }
struct test_properties * props
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct test_peer * peers
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
uint16_t status
See PRISM_STATUS_*-constants.
struct GNUNET_SCHEDULER_Task * die_task
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
int GNUNET_MESSENGER_iterate_members(struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, void *cls)
Iterates through all members of a given room and calls a selected callback for each of them with a pr...
struct GNUNET_MESSENGER_Room * room
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end_badly_cb()

static void end_badly_cb ( void *  cls)
static

Definition at line 164 of file testing_messenger_setup.c.

References end_cb(), GNUNET_assert, and test_properties::status.

Referenced by init().

165 {
166  struct test_properties *properties = cls;
167 
168  GNUNET_assert(properties != NULL);
169 
170  fprintf (stderr, "Testcase failed (timeout).\n");
171 
172  end_cb (properties);
173 
174  properties->status = 1;
175 }
static void end_cb(void *cls)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end_operation_cb()

static void end_operation_cb ( void *  cls)
static

Definition at line 178 of file testing_messenger_setup.c.

References GNUNET_assert, GNUNET_SCHEDULER_shutdown(), test_peer::message, test_peer::op_task, and test_peer::peer.

Referenced by on_message(), and on_peer().

179 {
180  struct test_peer *peer = cls;
181 
182  GNUNET_assert(peer != NULL);
183 
184  peer->op_task = NULL;
185 
186  fprintf (stderr, "Testcase failed (operation: '%s').\n", peer->message);
187 
189 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * op_task
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
const char * message
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ end_error_cb()

static void end_error_cb ( void *  cls)
static

Definition at line 192 of file testing_messenger_setup.c.

References GNUNET_assert, GNUNET_free, GNUNET_SCHEDULER_shutdown(), test_peer::message, test_peer::op_task, and test_peer::peer.

Referenced by on_peer().

193 {
194  struct test_peer *peer = cls;
195 
196  GNUNET_assert(peer != NULL);
197 
198  peer->op_task = NULL;
199 
200  fprintf (stderr, "Testcase failed (error: '%s').\n", peer->message);
201  GNUNET_free (peer);
202 
204 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * op_task
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
const char * message
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ barrier2_wait_cb()

static void barrier2_wait_cb ( void *  cls,
struct GNUNET_BarrierWaitHandle waiting,
int  status 
)
static

Definition at line 207 of file testing_messenger_setup.c.

References GNUNET_assert, test_peer::peer, and test_peer::wait.

Referenced by on_message().

208 {
209  struct test_peer *peer = cls;
210 
211  GNUNET_assert(peer != NULL);
212 
213  if (peer->wait == waiting)
214  peer->wait = NULL;
215 }
struct GNUNET_BarrierWaitHandle * wait
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
Here is the caller graph for this function:

◆ barrier_wait_cb()

static void barrier_wait_cb ( void *  cls,
struct GNUNET_BarrierWaitHandle waiting,
int  status 
)
static

Definition at line 218 of file testing_messenger_setup.c.

References test_properties::cfg, test_configuration::count, test_configuration::doors, GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_MESSENGER_enter_room(), test_peer::handle, test_peer::num, test_peer::peer, test_peer::peer_id, test_properties::peers, test_peer::props, test_peer::room, test_configuration::stages, TEST_ROOM, and test_peer::wait.

Referenced by on_peer().

219 {
220  struct test_peer *peer = cls;
221 
222  GNUNET_assert(peer != NULL);
223 
224  if (peer->wait == waiting)
225  peer->wait = NULL;
226 
227  if (0 != (peer->props->cfg->stages[peer->num - 1] & 0x02))
228  {
229  unsigned int door = peer->props->cfg->doors[peer->num - 1];
230 
231  if (door == 0)
233  else
234  door = door - 1;
235 
236  struct GNUNET_HashCode hash;
237  GNUNET_CRYPTO_hash (TEST_ROOM, sizeof(TEST_ROOM), &hash);
238 
239  struct GNUNET_MESSENGER_Room *room;
240  room = GNUNET_MESSENGER_enter_room(peer->handle, &(peer->props->peers[door].peer_id), &hash);
241 
242  if (peer->room)
243  GNUNET_assert(room == peer->room);
244  else
245  GNUNET_assert(room != NULL);
246 
247  peer->room = room;
248  }
249 }
struct test_properties * props
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_BarrierWaitHandle * wait
#define TEST_ROOM
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_enter_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Enter a room to send and receive messages through a door opened using GNUNET_MESSENGER_open_room.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct test_peer * peers
const struct test_configuration * cfg
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
A 512-bit hashcode.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_PeerIdentity peer_id
unsigned int num
struct GNUNET_MESSENGER_Room * room
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_message()

static void on_message ( void *  cls,
struct GNUNET_MESSENGER_Room room,
const struct GNUNET_MESSENGER_Contact sender,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash,
enum GNUNET_MESSENGER_MessageFlags  flags 
)
static

Function called whenever a message is received or sent.

Parameters
clsClosure
roomRoom
senderSender
messageMessage
hashHash of message
flagsFlags of message

Definition at line 262 of file testing_messenger_setup.c.

References test_properties::barrier, barrier2_wait_cb(), end_operation_cb(), GNUNET_assert, GNUNET_cancel_wait_barrier(), GNUNET_h2s(), GNUNET_i2s(), GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_name_of_kind(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_sh2s(), GNUNET_wait_barrier(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, test_peer::message, test_properties::num_hosts, test_peer::op_task, test_peer::peer, test_peer::peer_id, test_peer::peer_messages, test_peer::props, GNUNET_MESSENGER_MessageHeader::sender_id, and test_peer::wait.

Referenced by on_peer().

265 {
266  struct test_peer *peer = cls;
267 
268  GNUNET_assert(peer != NULL);
269 
270  fprintf (stderr, "Peer: %s; [%s] Message: %s (%s)\n",
271  GNUNET_i2s(&(peer->peer_id)),
272  GNUNET_sh2s(&(message->header.sender_id)),
274  GNUNET_h2s(hash));
275 
276  if (GNUNET_MESSENGER_KIND_PEER == message->header.kind)
277  peer->peer_messages++;
278 
279  if (peer->props->num_hosts == peer->peer_messages)
280  peer->wait = GNUNET_wait_barrier (peer->props->barrier, &barrier2_wait_cb, peer);
281  else if (peer->props->num_hosts < peer->peer_messages)
282  {
283  if (peer->wait)
285 
286  peer->wait = NULL;
287 
288  if (peer->op_task)
290 
291  peer->message = "peer";
293  }
294 }
static void end_operation_cb(void *cls)
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct test_properties * props
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
struct GNUNET_BarrierWaitHandle * wait
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
static void barrier2_wait_cb(void *cls, struct GNUNET_BarrierWaitHandle *waiting, int status)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_SCHEDULER_Task * op_task
struct GNUNET_BarrierHandle * barrier
const char * message
unsigned int peer_messages
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:35
struct GNUNET_BarrierWaitHandle * GNUNET_wait_barrier(struct GNUNET_BarrierHandle *barrier, GNUNET_BarrierWaitStatusCallback cb, void *cb_cls)
Wait for a pseudo-barrier to be crossed.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_PeerIdentity peer_id
void GNUNET_cancel_wait_barrier(struct GNUNET_BarrierWaitHandle *waiting)
Cancel a pseudo-barrier wait handle.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ second_stage()

static void second_stage ( void *  cls)
static

Definition at line 297 of file testing_messenger_setup.c.

References test_properties::cfg, test_configuration::count, test_configuration::doors, GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_MESSENGER_enter_room(), GNUNET_MESSENGER_open_room(), test_peer::handle, test_peer::num, test_peer::op_task, test_peer::peer, test_peer::peer_id, test_properties::peers, test_peer::props, test_peer::room, test_configuration::stages, and TEST_ROOM.

Referenced by barrier_cb().

298 {
299  struct test_peer *peer = cls;
300 
301  GNUNET_assert(peer != NULL);
302 
303  peer->op_task = NULL;
304 
305  struct GNUNET_HashCode hash;
306  GNUNET_CRYPTO_hash (TEST_ROOM, sizeof(TEST_ROOM), &hash);
307 
308  if (0 != (peer->props->cfg->stages[peer->num - 1] & 0x10))
309  {
310  struct GNUNET_MESSENGER_Room *room;
311  room = GNUNET_MESSENGER_open_room (peer->handle, &hash);
312 
313  if (peer->room)
314  GNUNET_assert(room == peer->room);
315  else
316  GNUNET_assert(room != NULL);
317 
318  peer->room = room;
319  }
320 
321  if (0 != (peer->props->cfg->stages[peer->num - 1] & 0x20))
322  {
323  unsigned int door = peer->props->cfg->doors[peer->num - 1];
324 
325  if (door == 0)
327  else
328  door = door - 1;
329 
330  struct GNUNET_MESSENGER_Room *room;
331  room = GNUNET_MESSENGER_enter_room(peer->handle, &(peer->props->peers[door].peer_id), &hash);
332 
333  if (peer->room)
334  GNUNET_assert(room == peer->room);
335  else
336  GNUNET_assert(room != NULL);
337 
338  peer->room = room;
339  }
340 }
struct test_properties * props
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_open_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Open a room to send and receive messages.
#define TEST_ROOM
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_enter_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Enter a room to send and receive messages through a door opened using GNUNET_MESSENGER_open_room.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct test_peer * peers
struct GNUNET_SCHEDULER_Task * op_task
const struct test_configuration * cfg
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
A 512-bit hashcode.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_PeerIdentity peer_id
unsigned int num
struct GNUNET_MESSENGER_Room * room
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_peer()

static void on_peer ( void *  cb_cls,
struct GNUNET_TESTBED_Operation op,
const struct GNUNET_TESTBED_PeerInformation pinfo,
const char *  emsg 
)
static

Definition at line 343 of file testing_messenger_setup.c.

References test_properties::barrier, barrier_wait_cb(), test_properties::cfg, GNUNET_TESTBED_PeerInformation::cfg, end_error_cb(), end_operation_cb(), GNUNET_assert, GNUNET_CRYPTO_get_peer_identity(), GNUNET_CRYPTO_hash(), GNUNET_MESSENGER_connect(), GNUNET_MESSENGER_open_room(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_TESTBED_PIT_CONFIGURATION, GNUNET_wait_barrier(), test_peer::handle, test_peer::message, test_peer::num, on_message(), test_peer::op_task, test_peer::peer, test_peer::peer_id, GNUNET_TESTBED_PeerInformation::pit, test_peer::props, GNUNET_TESTBED_PeerInformation::result, test_peer::room, test_configuration::stages, TEST_NAME, TEST_ROOM, and test_peer::wait.

Referenced by run().

345 {
346  struct test_peer *peer = cb_cls;
347 
348  GNUNET_assert(peer != NULL);
349 
350  if (emsg)
351  {
352  peer->message = GNUNET_strdup(emsg);
354  return;
355  }
356 
357  if (!pinfo)
358  {
359  peer->message = "info";
361  return;
362  }
363 
365  {
366  peer->message = "config";
368  return;
369  }
370 
371  peer->handle = GNUNET_MESSENGER_connect (pinfo->result.cfg, TEST_NAME, NULL, NULL, &on_message, peer);
372 
374  pinfo->result.cfg, &(peer->peer_id)
375  ));
376 
377  if (0 != (peer->props->cfg->stages[peer->num - 1] & 0x01))
378  {
379  struct GNUNET_HashCode hash;
380  GNUNET_CRYPTO_hash (TEST_ROOM, sizeof(TEST_ROOM), &hash);
381 
382  peer->room = GNUNET_MESSENGER_open_room (peer->handle, &hash);
383 
384  GNUNET_assert(peer->room != NULL);
385  }
386  else
387  peer->room = NULL;
388 
389  peer->wait = GNUNET_wait_barrier (peer->props->barrier, &barrier_wait_cb, peer);
390 }
static void end_operation_cb(void *cls)
struct test_properties * props
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_BarrierWaitHandle * wait
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_open_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Open a room to send and receive messages.
#define TEST_ROOM
enum GNUNET_TESTBED_PeerInformationType pit
Peer information type; captures which of the types in the &#39;op_result&#39; is actually in use...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void barrier_wait_cb(void *cls, struct GNUNET_BarrierWaitHandle *waiting, int status)
struct GNUNET_SCHEDULER_Task * op_task
struct GNUNET_BarrierHandle * barrier
static void end_error_cb(void *cls)
const struct test_configuration * cfg
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static void on_message(void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_MessageFlags flags)
Function called whenever a message is received or sent.
const char * message
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
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
What configuration is the peer using? Returns a &#39;const struct GNUNET_CONFIGURATION_Handle *&#39;...
struct GNUNET_BarrierWaitHandle * GNUNET_wait_barrier(struct GNUNET_BarrierHandle *barrier, GNUNET_BarrierWaitStatusCallback cb, void *cb_cls)
Wait for a pseudo-barrier to be crossed.
A 512-bit hashcode.
struct GNUNET_CONFIGURATION_Handle * cfg
The configuration of the peer.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_PeerIdentity peer_id
struct GNUNET_MESSENGER_Handle * GNUNET_MESSENGER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, GNUNET_MESSENGER_IdentityCallback identity_callback, void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls)
Set up a handle for the messenger related functions and connects to all necessary services...
unsigned int num
int GNUNET_CRYPTO_get_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *dst)
Retrieve the identity of the host&#39;s peer.
#define TEST_NAME
union GNUNET_TESTBED_PeerInformation::@49 result
The result of the get information operation; Choose according to the pit.
struct GNUNET_MESSENGER_Room * room
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
const struct GNUNET_TESTBED_EventInformation event 
)
static

Main function for a peer of the testcase.

Parameters
clsClosure
eventInformation about the event

Definition at line 399 of file testing_messenger_setup.c.

References GNUNET_assert, GNUNET_SCHEDULER_shutdown(), GNUNET_TESTBED_ET_PEER_START, GNUNET_TESTBED_peer_get_information(), GNUNET_TESTBED_PIT_CONFIGURATION, test_peer::num, test_properties::num_peer, on_peer(), test_peer::op, test_peer::peer, test_properties::peers, test_peer::props, and GNUNET_TESTBED_EventInformation::type.

Referenced by GNUNET_run_messenger_setup().

400 {
401  struct test_properties *properties = cls;
402 
403  GNUNET_assert(properties != NULL);
404 
405  if (GNUNET_TESTBED_ET_PEER_START != event->type)
406  {
407  fprintf (stderr, "Testcase failed (operation: 'start').\n");
408 
410  return;
411  }
412 
413  struct test_peer *peer = &(properties->peers[properties->num_peer++]);
414 
415  peer->props = properties;
416  peer->num = properties->num_peer;
417 
418  peer->peer = event->details.peer_start.peer;
420 }
struct test_properties * props
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct test_peer * peers
struct GNUNET_TESTBED_Peer * peer
enum GNUNET_TESTBED_EventType type
Type of the event.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
static void on_peer(void *cb_cls, struct GNUNET_TESTBED_Operation *op, const struct GNUNET_TESTBED_PeerInformation *pinfo, const char *emsg)
What configuration is the peer using? Returns a &#39;const struct GNUNET_CONFIGURATION_Handle *&#39;...
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_get_information(struct GNUNET_TESTBED_Peer *peer, enum GNUNET_TESTBED_PeerInformationType pit, GNUNET_TESTBED_PeerInfoCallback cb, void *cb_cls)
Request information about a peer.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_TESTBED_Operation * op
unsigned int num
Here is the call graph for this function:
Here is the caller graph for this function:

◆ barrier2_cb()

static void barrier2_cb ( void *  cls,
struct GNUNET_BarrierHandle barrier,
int  status 
)
static

Definition at line 423 of file testing_messenger_setup.c.

References test_properties::barrier, test_properties::cfg, test_configuration::count, test_properties::die_task, end_cb(), GNUNET_assert, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_TIME_relative_multiply(), and GNUNET_TIME_UNIT_SECONDS.

Referenced by barrier_cb().

424 {
425  struct test_properties *properties = cls;
426 
427  GNUNET_assert(properties != NULL);
428 
429  if (properties->barrier == barrier)
430  properties->barrier = NULL;
431 
432  if (GNUNET_SYSERR == status)
433  {
434  fprintf (stderr, "Testcase failed (operation: 'barrier2').\n");
435 
437  return;
438  }
439  else if (GNUNET_OK == status)
440  {
441  if (properties->die_task)
442  GNUNET_SCHEDULER_cancel(properties->die_task);
443 
444  properties->die_task = GNUNET_SCHEDULER_add_delayed (
446  &end_cb, properties
447  );
448  }
449 }
static void end_cb(void *cls)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_BarrierHandle * barrier
const struct test_configuration * cfg
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
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
uint16_t status
See PRISM_STATUS_*-constants.
struct GNUNET_SCHEDULER_Task * die_task
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:311
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ barrier_cb()

static void barrier_cb ( void *  cls,
struct GNUNET_BarrierHandle barrier,
int  status 
)
static

Definition at line 452 of file testing_messenger_setup.c.

References test_properties::barrier, barrier2_cb(), test_properties::cfg, test_configuration::count, GNUNET_assert, GNUNET_init_barrier(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, test_properties::num_peer, test_peer::op_task, test_properties::peers, and second_stage().

Referenced by GNUNET_run_messenger_setup().

453 {
454  struct test_properties *properties = cls;
455 
456  GNUNET_assert(properties != NULL);
457 
458  if (properties->barrier == barrier)
459  properties->barrier = NULL;
460  else if (!properties->barrier)
461  return;
462 
463  if (properties->num_peer != properties->cfg->count)
464  {
465  fprintf (stderr, "Testcase failed (operation: 'process').\n");
466 
468  return;
469  }
470 
471  if (GNUNET_SYSERR == status)
472  {
473  fprintf (stderr, "Testcase failed (operation: 'barrier').\n");
474 
476  return;
477  }
478  else if (GNUNET_OK == status)
479  {
480  properties->barrier = GNUNET_init_barrier (properties->num_peer, &barrier2_cb, properties);
481 
482  for (unsigned int i = 0; i < properties->num_peer; i++)
483  properties->peers[i].op_task = GNUNET_SCHEDULER_add_now (&second_stage, &(properties->peers[i]));
484  }
485 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct test_peer * peers
struct GNUNET_SCHEDULER_Task * op_task
struct GNUNET_BarrierHandle * barrier
const struct test_configuration * cfg
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
static void second_stage(void *cls)
uint16_t status
See PRISM_STATUS_*-constants.
static void barrier2_cb(void *cls, struct GNUNET_BarrierHandle *barrier, int status)
struct GNUNET_BarrierHandle * GNUNET_init_barrier(unsigned int requirement, GNUNET_BarrierStatusCallback cb, void *cb_cls)
Initialise a pseudo-barrier and call the given callback when the required amount of peers (requiremen...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

static void init ( void *  cls,
struct GNUNET_TESTBED_RunHandle h,
unsigned int  num_peers,
struct GNUNET_TESTBED_Peer **  peers,
unsigned int  links_succeeded,
unsigned int  links_failed 
)
static

Definition at line 488 of file testing_messenger_setup.c.

References test_properties::cfg, test_configuration::count, test_properties::die_task, end_badly_cb(), test_properties::end_task, GNUNET_assert, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_SECONDS, and shutdown_cb().

Referenced by GNUNET_run_messenger_setup().

490 {
491  struct test_properties *properties = cls;
492 
493  GNUNET_assert(properties != NULL);
494 
495  properties->end_task = GNUNET_SCHEDULER_add_shutdown(&shutdown_cb, properties);
496  properties->die_task = GNUNET_SCHEDULER_add_delayed (
498  &end_badly_cb, properties
499  );
500 }
static void shutdown_cb(void *cls)
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1331
struct GNUNET_SCHEDULER_Task * end_task
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_TIME_UNIT_SECONDS
One second.
const struct test_configuration * cfg
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
struct GNUNET_SCHEDULER_Task * die_task
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:311
static void end_badly_cb(void *cls)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_run_messenger_setup()

int GNUNET_run_messenger_setup ( const char *  test_name,
const struct test_configuration cfg 
)

Definition at line 503 of file testing_messenger_setup.c.

References test_properties::barrier, barrier_cb(), cfg, test_properties::cfg, test_configuration::count, GNUNET_free, GNUNET_init_barrier(), GNUNET_new_array, GNUNET_OK, GNUNET_TESTBED_ET_PEER_START, GNUNET_TESTBED_test_run(), init(), test_properties::num_hosts, test_properties::peers, run(), test_configuration::stages, and test_properties::status.

504 {
505  struct test_properties properties;
506  memset(&properties, 0, sizeof(properties));
507 
508  properties.cfg = cfg;
509  properties.peers = GNUNET_new_array(cfg->count, struct test_peer);
510 
511  for (unsigned int i = 0; i < cfg->count; i++)
512  if (0 != (cfg->stages[i] & 0x11))
513  properties.num_hosts++;
514 
515  properties.status = 1;
516  properties.barrier = GNUNET_init_barrier (cfg->count, &barrier_cb, &properties);
517 
518  if (GNUNET_OK != GNUNET_TESTBED_test_run (test_name, "test_messenger_api.conf",
519  cfg->count,
521  &run, &properties,
522  &init, &properties))
523  return 1;
524 
525  GNUNET_free(properties.peers);
526 
527  return properties.status;
528 }
static void run(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
Main function for a peer of the testcase.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
int GNUNET_TESTBED_test_run(const char *testname, const char *cfg_filename, unsigned int num_peers, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, GNUNET_TESTBED_TestMaster test_master, void *test_master_cls)
Convenience method for running a "simple" test on the local system with a single call from &#39;main&#39;...
static void barrier_cb(void *cls, struct GNUNET_BarrierHandle *barrier, int status)
static void init(void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, unsigned int links_succeeded, unsigned int links_failed)
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
struct GNUNET_BarrierHandle * GNUNET_init_barrier(unsigned int requirement, GNUNET_BarrierStatusCallback cb, void *cb_cls)
Initialise a pseudo-barrier and call the given callback when the required amount of peers (requiremen...
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: