diff options
Diffstat (limited to 'src/messenger/testing_messenger_setup.c')
-rw-r--r-- | src/messenger/testing_messenger_setup.c | 185 |
1 files changed, 113 insertions, 72 deletions
diff --git a/src/messenger/testing_messenger_setup.c b/src/messenger/testing_messenger_setup.c index 29db25bd8..e4dfa203f 100644 --- a/src/messenger/testing_messenger_setup.c +++ b/src/messenger/testing_messenger_setup.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2021 GNUnet e.V. | 3 | Copyright (C) 2020--2023 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -39,7 +39,8 @@ | |||
39 | 39 | ||
40 | struct test_properties; | 40 | struct test_properties; |
41 | 41 | ||
42 | struct test_peer { | 42 | struct test_peer |
43 | { | ||
43 | struct test_properties *props; | 44 | struct test_properties *props; |
44 | unsigned int num; | 45 | unsigned int num; |
45 | 46 | ||
@@ -58,7 +59,8 @@ struct test_peer { | |||
58 | const char *message; | 59 | const char *message; |
59 | }; | 60 | }; |
60 | 61 | ||
61 | struct test_properties { | 62 | struct test_properties |
63 | { | ||
62 | const struct test_configuration *cfg; | 64 | const struct test_configuration *cfg; |
63 | 65 | ||
64 | unsigned int num_hosts; | 66 | unsigned int num_hosts; |
@@ -83,10 +85,10 @@ shutdown_cb (void *cls) | |||
83 | { | 85 | { |
84 | struct test_peer *peer = &properties->peers[i]; | 86 | struct test_peer *peer = &properties->peers[i]; |
85 | 87 | ||
86 | GNUNET_assert(peer != NULL); | 88 | GNUNET_assert (peer != NULL); |
87 | 89 | ||
88 | if (peer->op_task) | 90 | if (peer->op_task) |
89 | GNUNET_SCHEDULER_cancel(peer->op_task); | 91 | GNUNET_SCHEDULER_cancel (peer->op_task); |
90 | 92 | ||
91 | peer->op_task = NULL; | 93 | peer->op_task = NULL; |
92 | 94 | ||
@@ -96,7 +98,7 @@ shutdown_cb (void *cls) | |||
96 | peer->op = NULL; | 98 | peer->op = NULL; |
97 | 99 | ||
98 | if (peer->wait) | 100 | if (peer->wait) |
99 | GNUNET_cancel_wait_barrier(peer->wait); | 101 | GNUNET_cancel_wait_barrier (peer->wait); |
100 | 102 | ||
101 | peer->wait = NULL; | 103 | peer->wait = NULL; |
102 | 104 | ||
@@ -115,23 +117,24 @@ shutdown_cb (void *cls) | |||
115 | } | 117 | } |
116 | 118 | ||
117 | if (properties->die_task) | 119 | if (properties->die_task) |
118 | GNUNET_SCHEDULER_cancel(properties->die_task); | 120 | GNUNET_SCHEDULER_cancel (properties->die_task); |
119 | 121 | ||
120 | properties->die_task = NULL; | 122 | properties->die_task = NULL; |
121 | properties->end_task = NULL; | 123 | properties->end_task = NULL; |
122 | 124 | ||
123 | if (properties->barrier) | 125 | if (properties->barrier) |
124 | GNUNET_cancel_barrier(properties->barrier); | 126 | GNUNET_cancel_barrier (properties->barrier); |
125 | 127 | ||
126 | properties->barrier = NULL; | 128 | properties->barrier = NULL; |
127 | } | 129 | } |
128 | 130 | ||
131 | |||
129 | static void | 132 | static void |
130 | end_cb (void *cls) | 133 | end_cb (void *cls) |
131 | { | 134 | { |
132 | struct test_properties *properties = cls; | 135 | struct test_properties *properties = cls; |
133 | 136 | ||
134 | GNUNET_assert(properties != NULL); | 137 | GNUNET_assert (properties != NULL); |
135 | 138 | ||
136 | properties->die_task = NULL; | 139 | properties->die_task = NULL; |
137 | 140 | ||
@@ -141,15 +144,17 @@ end_cb (void *cls) | |||
141 | { | 144 | { |
142 | struct test_peer *peer = &properties->peers[i]; | 145 | struct test_peer *peer = &properties->peers[i]; |
143 | 146 | ||
144 | GNUNET_assert(peer != NULL); | 147 | GNUNET_assert (peer != NULL); |
145 | 148 | ||
146 | const int members = GNUNET_MESSENGER_iterate_members(peer->room, NULL, NULL); | 149 | const int members = GNUNET_MESSENGER_iterate_members (peer->room, NULL, |
150 | NULL); | ||
147 | 151 | ||
148 | GNUNET_assert (members >= 0); | 152 | GNUNET_assert (members >= 0); |
149 | 153 | ||
150 | if (peer->props->num_peer != (unsigned int) members) | 154 | if (peer->props->num_peer != (unsigned int) members) |
151 | { | 155 | { |
152 | fprintf (stderr, "Testcase failed (members: %d/%u).\n", members, peer->props->num_peer); | 156 | fprintf (stderr, "Testcase failed (members: %d/%u).\n", members, |
157 | peer->props->num_peer); | ||
153 | status = 1; | 158 | status = 1; |
154 | break; | 159 | break; |
155 | } | 160 | } |
@@ -160,12 +165,13 @@ end_cb (void *cls) | |||
160 | properties->status = status; | 165 | properties->status = status; |
161 | } | 166 | } |
162 | 167 | ||
168 | |||
163 | static void | 169 | static void |
164 | end_badly_cb (void *cls) | 170 | end_badly_cb (void *cls) |
165 | { | 171 | { |
166 | struct test_properties *properties = cls; | 172 | struct test_properties *properties = cls; |
167 | 173 | ||
168 | GNUNET_assert(properties != NULL); | 174 | GNUNET_assert (properties != NULL); |
169 | 175 | ||
170 | fprintf (stderr, "Testcase failed (timeout).\n"); | 176 | fprintf (stderr, "Testcase failed (timeout).\n"); |
171 | 177 | ||
@@ -174,12 +180,13 @@ end_badly_cb (void *cls) | |||
174 | properties->status = 1; | 180 | properties->status = 1; |
175 | } | 181 | } |
176 | 182 | ||
183 | |||
177 | static void | 184 | static void |
178 | end_operation_cb (void *cls) | 185 | end_operation_cb (void *cls) |
179 | { | 186 | { |
180 | struct test_peer *peer = cls; | 187 | struct test_peer *peer = cls; |
181 | 188 | ||
182 | GNUNET_assert(peer != NULL); | 189 | GNUNET_assert (peer != NULL); |
183 | 190 | ||
184 | peer->op_task = NULL; | 191 | peer->op_task = NULL; |
185 | 192 | ||
@@ -188,12 +195,13 @@ end_operation_cb (void *cls) | |||
188 | GNUNET_SCHEDULER_shutdown (); | 195 | GNUNET_SCHEDULER_shutdown (); |
189 | } | 196 | } |
190 | 197 | ||
198 | |||
191 | static void | 199 | static void |
192 | end_error_cb (void *cls) | 200 | end_error_cb (void *cls) |
193 | { | 201 | { |
194 | struct test_peer *peer = cls; | 202 | struct test_peer *peer = cls; |
195 | 203 | ||
196 | GNUNET_assert(peer != NULL); | 204 | GNUNET_assert (peer != NULL); |
197 | 205 | ||
198 | peer->op_task = NULL; | 206 | peer->op_task = NULL; |
199 | 207 | ||
@@ -203,6 +211,7 @@ end_error_cb (void *cls) | |||
203 | GNUNET_SCHEDULER_shutdown (); | 211 | GNUNET_SCHEDULER_shutdown (); |
204 | } | 212 | } |
205 | 213 | ||
214 | |||
206 | static void | 215 | static void |
207 | barrier2_wait_cb (void *cls, | 216 | barrier2_wait_cb (void *cls, |
208 | struct GNUNET_BarrierWaitHandle *waiting, | 217 | struct GNUNET_BarrierWaitHandle *waiting, |
@@ -210,12 +219,13 @@ barrier2_wait_cb (void *cls, | |||
210 | { | 219 | { |
211 | struct test_peer *peer = cls; | 220 | struct test_peer *peer = cls; |
212 | 221 | ||
213 | GNUNET_assert(peer != NULL); | 222 | GNUNET_assert (peer != NULL); |
214 | 223 | ||
215 | if (peer->wait == waiting) | 224 | if (peer->wait == waiting) |
216 | peer->wait = NULL; | 225 | peer->wait = NULL; |
217 | } | 226 | } |
218 | 227 | ||
228 | |||
219 | static void | 229 | static void |
220 | barrier_wait_cb (void *cls, | 230 | barrier_wait_cb (void *cls, |
221 | struct GNUNET_BarrierWaitHandle *waiting, | 231 | struct GNUNET_BarrierWaitHandle *waiting, |
@@ -223,7 +233,7 @@ barrier_wait_cb (void *cls, | |||
223 | { | 233 | { |
224 | struct test_peer *peer = cls; | 234 | struct test_peer *peer = cls; |
225 | 235 | ||
226 | GNUNET_assert(peer != NULL); | 236 | GNUNET_assert (peer != NULL); |
227 | 237 | ||
228 | if (peer->wait == waiting) | 238 | if (peer->wait == waiting) |
229 | peer->wait = NULL; | 239 | peer->wait = NULL; |
@@ -233,7 +243,8 @@ barrier_wait_cb (void *cls, | |||
233 | unsigned int door = peer->props->cfg->doors[peer->num - 1]; | 243 | unsigned int door = peer->props->cfg->doors[peer->num - 1]; |
234 | 244 | ||
235 | if (door == 0) | 245 | if (door == 0) |
236 | door = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, peer->props->cfg->count); | 246 | door = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
247 | peer->props->cfg->count); | ||
237 | else | 248 | else |
238 | door = door - 1; | 249 | door = door - 1; |
239 | 250 | ||
@@ -241,17 +252,20 @@ barrier_wait_cb (void *cls, | |||
241 | GNUNET_CRYPTO_hash (TEST_ROOM, sizeof(TEST_ROOM), &hash); | 252 | GNUNET_CRYPTO_hash (TEST_ROOM, sizeof(TEST_ROOM), &hash); |
242 | 253 | ||
243 | struct GNUNET_MESSENGER_Room *room; | 254 | struct GNUNET_MESSENGER_Room *room; |
244 | room = GNUNET_MESSENGER_enter_room(peer->handle, &(peer->props->peers[door].peer_id), &hash); | 255 | room = GNUNET_MESSENGER_enter_room (peer->handle, |
256 | &(peer->props->peers[door].peer_id), | ||
257 | &hash); | ||
245 | 258 | ||
246 | if (peer->room) | 259 | if (peer->room) |
247 | GNUNET_assert(room == peer->room); | 260 | GNUNET_assert (room == peer->room); |
248 | else | 261 | else |
249 | GNUNET_assert(room != NULL); | 262 | GNUNET_assert (room != NULL); |
250 | 263 | ||
251 | peer->room = room; | 264 | peer->room = room; |
252 | } | 265 | } |
253 | } | 266 | } |
254 | 267 | ||
268 | |||
255 | /** | 269 | /** |
256 | * Function called whenever a message is received or sent. | 270 | * Function called whenever a message is received or sent. |
257 | * | 271 | * |
@@ -272,44 +286,48 @@ on_message (void *cls, | |||
272 | { | 286 | { |
273 | struct test_peer *peer = cls; | 287 | struct test_peer *peer = cls; |
274 | 288 | ||
275 | GNUNET_assert(peer != NULL); | 289 | GNUNET_assert (peer != NULL); |
276 | 290 | ||
277 | fprintf (stderr, "Peer: %s; [%s] Message: %s (%s)\n", | 291 | fprintf (stderr, "Peer: %s; [%s] Message: %s (%s)\n", |
278 | GNUNET_i2s(&(peer->peer_id)), | 292 | GNUNET_i2s (&(peer->peer_id)), |
279 | GNUNET_sh2s(&(message->header.sender_id)), | 293 | GNUNET_sh2s (&(message->header.sender_id)), |
280 | GNUNET_MESSENGER_name_of_kind(message->header.kind), | 294 | GNUNET_MESSENGER_name_of_kind (message->header.kind), |
281 | GNUNET_h2s(hash)); | 295 | GNUNET_h2s (hash)); |
282 | 296 | ||
283 | if (GNUNET_MESSENGER_KIND_PEER == message->header.kind) | 297 | if (GNUNET_MESSENGER_KIND_PEER == message->header.kind) |
284 | GNUNET_CONTAINER_multipeermap_put (peer->map, &(message->body.peer.peer), NULL, | 298 | GNUNET_CONTAINER_multipeermap_put (peer->map, &(message->body.peer.peer), |
299 | NULL, | ||
285 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 300 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
286 | 301 | ||
287 | const int members = GNUNET_MESSENGER_iterate_members(peer->room, NULL, NULL); | 302 | const int members = GNUNET_MESSENGER_iterate_members (peer->room, NULL, NULL); |
288 | 303 | ||
289 | const uint32_t num_peers = GNUNET_CONTAINER_multipeermap_size (peer->map); | 304 | const uint32_t num_peers = GNUNET_CONTAINER_multipeermap_size (peer->map); |
290 | if ((members == peer->props->num_peer) && (peer->props->num_hosts == num_peers)) | 305 | if ((members == peer->props->num_peer) && (peer->props->num_hosts == |
291 | peer->wait = GNUNET_wait_barrier (peer->props->barrier, &barrier2_wait_cb, peer); | 306 | num_peers)) |
307 | peer->wait = GNUNET_wait_barrier (peer->props->barrier, &barrier2_wait_cb, | ||
308 | peer); | ||
292 | else if (peer->props->num_hosts < num_peers) | 309 | else if (peer->props->num_hosts < num_peers) |
293 | { | 310 | { |
294 | if (peer->wait) | 311 | if (peer->wait) |
295 | GNUNET_cancel_wait_barrier(peer->wait); | 312 | GNUNET_cancel_wait_barrier (peer->wait); |
296 | 313 | ||
297 | peer->wait = NULL; | 314 | peer->wait = NULL; |
298 | 315 | ||
299 | if (peer->op_task) | 316 | if (peer->op_task) |
300 | GNUNET_SCHEDULER_cancel(peer->op_task); | 317 | GNUNET_SCHEDULER_cancel (peer->op_task); |
301 | 318 | ||
302 | peer->message = "peer"; | 319 | peer->message = "peer"; |
303 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_operation_cb, peer); | 320 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_operation_cb, peer); |
304 | } | 321 | } |
305 | } | 322 | } |
306 | 323 | ||
324 | |||
307 | static void | 325 | static void |
308 | second_stage (void *cls) | 326 | second_stage (void *cls) |
309 | { | 327 | { |
310 | struct test_peer *peer = cls; | 328 | struct test_peer *peer = cls; |
311 | 329 | ||
312 | GNUNET_assert(peer != NULL); | 330 | GNUNET_assert (peer != NULL); |
313 | 331 | ||
314 | peer->op_task = NULL; | 332 | peer->op_task = NULL; |
315 | 333 | ||
@@ -322,9 +340,9 @@ second_stage (void *cls) | |||
322 | room = GNUNET_MESSENGER_open_room (peer->handle, &hash); | 340 | room = GNUNET_MESSENGER_open_room (peer->handle, &hash); |
323 | 341 | ||
324 | if (peer->room) | 342 | if (peer->room) |
325 | GNUNET_assert(room == peer->room); | 343 | GNUNET_assert (room == peer->room); |
326 | else | 344 | else |
327 | GNUNET_assert(room != NULL); | 345 | GNUNET_assert (room != NULL); |
328 | 346 | ||
329 | peer->room = room; | 347 | peer->room = room; |
330 | } | 348 | } |
@@ -334,22 +352,26 @@ second_stage (void *cls) | |||
334 | unsigned int door = peer->props->cfg->doors[peer->num - 1]; | 352 | unsigned int door = peer->props->cfg->doors[peer->num - 1]; |
335 | 353 | ||
336 | if (door == 0) | 354 | if (door == 0) |
337 | door = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, peer->props->cfg->count); | 355 | door = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
356 | peer->props->cfg->count); | ||
338 | else | 357 | else |
339 | door = door - 1; | 358 | door = door - 1; |
340 | 359 | ||
341 | struct GNUNET_MESSENGER_Room *room; | 360 | struct GNUNET_MESSENGER_Room *room; |
342 | room = GNUNET_MESSENGER_enter_room(peer->handle, &(peer->props->peers[door].peer_id), &hash); | 361 | room = GNUNET_MESSENGER_enter_room (peer->handle, |
362 | &(peer->props->peers[door].peer_id), | ||
363 | &hash); | ||
343 | 364 | ||
344 | if (peer->room) | 365 | if (peer->room) |
345 | GNUNET_assert(room == peer->room); | 366 | GNUNET_assert (room == peer->room); |
346 | else | 367 | else |
347 | GNUNET_assert(room != NULL); | 368 | GNUNET_assert (room != NULL); |
348 | 369 | ||
349 | peer->room = room; | 370 | peer->room = room; |
350 | } | 371 | } |
351 | } | 372 | } |
352 | 373 | ||
374 | |||
353 | static void | 375 | static void |
354 | on_peer (void *cb_cls, | 376 | on_peer (void *cb_cls, |
355 | struct GNUNET_TESTBED_Operation *op, | 377 | struct GNUNET_TESTBED_Operation *op, |
@@ -358,16 +380,16 @@ on_peer (void *cb_cls, | |||
358 | { | 380 | { |
359 | struct test_peer *peer = cb_cls; | 381 | struct test_peer *peer = cb_cls; |
360 | 382 | ||
361 | GNUNET_assert(peer != NULL); | 383 | GNUNET_assert (peer != NULL); |
362 | 384 | ||
363 | if (emsg) | 385 | if (emsg) |
364 | { | 386 | { |
365 | peer->message = GNUNET_strdup(emsg); | 387 | peer->message = GNUNET_strdup (emsg); |
366 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_error_cb, peer); | 388 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_error_cb, peer); |
367 | return; | 389 | return; |
368 | } | 390 | } |
369 | 391 | ||
370 | if (!pinfo) | 392 | if (! pinfo) |
371 | { | 393 | { |
372 | peer->message = "info"; | 394 | peer->message = "info"; |
373 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_operation_cb, peer); | 395 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_operation_cb, peer); |
@@ -381,11 +403,12 @@ on_peer (void *cb_cls, | |||
381 | return; | 403 | return; |
382 | } | 404 | } |
383 | 405 | ||
384 | peer->handle = GNUNET_MESSENGER_connect (pinfo->result.cfg, TEST_NAME, NULL, &on_message, peer); | 406 | peer->handle = GNUNET_MESSENGER_connect (pinfo->result.cfg, TEST_NAME, NULL, |
407 | &on_message, peer); | ||
385 | 408 | ||
386 | GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_get_peer_identity( | 409 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_get_peer_identity ( |
387 | pinfo->result.cfg, &(peer->peer_id) | 410 | pinfo->result.cfg, &(peer->peer_id) |
388 | )); | 411 | )); |
389 | 412 | ||
390 | if (0 != (peer->props->cfg->stages[peer->num - 1] & 0x01)) | 413 | if (0 != (peer->props->cfg->stages[peer->num - 1] & 0x01)) |
391 | { | 414 | { |
@@ -394,14 +417,16 @@ on_peer (void *cb_cls, | |||
394 | 417 | ||
395 | peer->room = GNUNET_MESSENGER_open_room (peer->handle, &hash); | 418 | peer->room = GNUNET_MESSENGER_open_room (peer->handle, &hash); |
396 | 419 | ||
397 | GNUNET_assert(peer->room != NULL); | 420 | GNUNET_assert (peer->room != NULL); |
398 | } | 421 | } |
399 | else | 422 | else |
400 | peer->room = NULL; | 423 | peer->room = NULL; |
401 | 424 | ||
402 | peer->wait = GNUNET_wait_barrier (peer->props->barrier, &barrier_wait_cb, peer); | 425 | peer->wait = GNUNET_wait_barrier (peer->props->barrier, &barrier_wait_cb, |
426 | peer); | ||
403 | } | 427 | } |
404 | 428 | ||
429 | |||
405 | /** | 430 | /** |
406 | * Main function for a peer of the testcase. | 431 | * Main function for a peer of the testcase. |
407 | * | 432 | * |
@@ -414,7 +439,7 @@ run (void *cls, | |||
414 | { | 439 | { |
415 | struct test_properties *properties = cls; | 440 | struct test_properties *properties = cls; |
416 | 441 | ||
417 | GNUNET_assert(properties != NULL); | 442 | GNUNET_assert (properties != NULL); |
418 | 443 | ||
419 | if (GNUNET_TESTBED_ET_PEER_START != event->type) | 444 | if (GNUNET_TESTBED_ET_PEER_START != event->type) |
420 | { | 445 | { |
@@ -430,11 +455,15 @@ run (void *cls, | |||
430 | peer->num = properties->num_peer; | 455 | peer->num = properties->num_peer; |
431 | 456 | ||
432 | peer->peer = event->details.peer_start.peer; | 457 | peer->peer = event->details.peer_start.peer; |
433 | peer->op = GNUNET_TESTBED_peer_get_information (peer->peer, GNUNET_TESTBED_PIT_CONFIGURATION, on_peer, peer); | 458 | peer->op = GNUNET_TESTBED_peer_get_information (peer->peer, |
459 | GNUNET_TESTBED_PIT_CONFIGURATION, | ||
460 | on_peer, peer); | ||
434 | 461 | ||
435 | peer->map = GNUNET_CONTAINER_multipeermap_create(peer->props->num_hosts, GNUNET_NO); | 462 | peer->map = GNUNET_CONTAINER_multipeermap_create (peer->props->num_hosts, |
463 | GNUNET_NO); | ||
436 | } | 464 | } |
437 | 465 | ||
466 | |||
438 | static void | 467 | static void |
439 | barrier2_cb (void *cls, | 468 | barrier2_cb (void *cls, |
440 | struct GNUNET_BarrierHandle *barrier, | 469 | struct GNUNET_BarrierHandle *barrier, |
@@ -442,7 +471,7 @@ barrier2_cb (void *cls, | |||
442 | { | 471 | { |
443 | struct test_properties *properties = cls; | 472 | struct test_properties *properties = cls; |
444 | 473 | ||
445 | GNUNET_assert(properties != NULL); | 474 | GNUNET_assert (properties != NULL); |
446 | 475 | ||
447 | if (properties->barrier == barrier) | 476 | if (properties->barrier == barrier) |
448 | properties->barrier = NULL; | 477 | properties->barrier = NULL; |
@@ -457,15 +486,17 @@ barrier2_cb (void *cls, | |||
457 | else if (GNUNET_OK == status) | 486 | else if (GNUNET_OK == status) |
458 | { | 487 | { |
459 | if (properties->die_task) | 488 | if (properties->die_task) |
460 | GNUNET_SCHEDULER_cancel(properties->die_task); | 489 | GNUNET_SCHEDULER_cancel (properties->die_task); |
461 | 490 | ||
462 | properties->die_task = GNUNET_SCHEDULER_add_delayed ( | 491 | properties->die_task = GNUNET_SCHEDULER_add_delayed ( |
463 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, properties->cfg->count), | 492 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
464 | &end_cb, properties | 493 | properties->cfg->count), |
465 | ); | 494 | &end_cb, properties |
495 | ); | ||
466 | } | 496 | } |
467 | } | 497 | } |
468 | 498 | ||
499 | |||
469 | static void | 500 | static void |
470 | barrier_cb (void *cls, | 501 | barrier_cb (void *cls, |
471 | struct GNUNET_BarrierHandle *barrier, | 502 | struct GNUNET_BarrierHandle *barrier, |
@@ -473,11 +504,11 @@ barrier_cb (void *cls, | |||
473 | { | 504 | { |
474 | struct test_properties *properties = cls; | 505 | struct test_properties *properties = cls; |
475 | 506 | ||
476 | GNUNET_assert(properties != NULL); | 507 | GNUNET_assert (properties != NULL); |
477 | 508 | ||
478 | if (properties->barrier == barrier) | 509 | if (properties->barrier == barrier) |
479 | properties->barrier = NULL; | 510 | properties->barrier = NULL; |
480 | else if (!properties->barrier) | 511 | else if (! properties->barrier) |
481 | return; | 512 | return; |
482 | 513 | ||
483 | if (properties->num_peer != properties->cfg->count) | 514 | if (properties->num_peer != properties->cfg->count) |
@@ -497,13 +528,17 @@ barrier_cb (void *cls, | |||
497 | } | 528 | } |
498 | else if (GNUNET_OK == status) | 529 | else if (GNUNET_OK == status) |
499 | { | 530 | { |
500 | properties->barrier = GNUNET_init_barrier (properties->num_peer, &barrier2_cb, properties); | 531 | properties->barrier = GNUNET_init_barrier (properties->num_peer, |
532 | &barrier2_cb, properties); | ||
501 | 533 | ||
502 | for (unsigned int i = 0; i < properties->num_peer; i++) | 534 | for (unsigned int i = 0; i < properties->num_peer; i++) |
503 | properties->peers[i].op_task = GNUNET_SCHEDULER_add_now (&second_stage, &(properties->peers[i])); | 535 | properties->peers[i].op_task = GNUNET_SCHEDULER_add_now (&second_stage, |
536 | &(properties-> | ||
537 | peers[i])); | ||
504 | } | 538 | } |
505 | } | 539 | } |
506 | 540 | ||
541 | |||
507 | static void | 542 | static void |
508 | init (void *cls, | 543 | init (void *cls, |
509 | struct GNUNET_TESTBED_RunHandle *h, | 544 | struct GNUNET_TESTBED_RunHandle *h, |
@@ -514,40 +549,46 @@ init (void *cls, | |||
514 | { | 549 | { |
515 | struct test_properties *properties = cls; | 550 | struct test_properties *properties = cls; |
516 | 551 | ||
517 | GNUNET_assert(properties != NULL); | 552 | GNUNET_assert (properties != NULL); |
518 | 553 | ||
519 | properties->end_task = GNUNET_SCHEDULER_add_shutdown(&shutdown_cb, properties); | 554 | properties->end_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_cb, |
555 | properties); | ||
520 | properties->die_task = GNUNET_SCHEDULER_add_delayed ( | 556 | properties->die_task = GNUNET_SCHEDULER_add_delayed ( |
521 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, properties->cfg->count * 5), | 557 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
522 | &end_badly_cb, properties | 558 | properties->cfg->count * 5), |
523 | ); | 559 | &end_badly_cb, properties |
560 | ); | ||
524 | } | 561 | } |
525 | 562 | ||
563 | |||
526 | int | 564 | int |
527 | GNUNET_run_messenger_setup (const char* test_name, | 565 | GNUNET_run_messenger_setup (const char *test_name, |
528 | const struct test_configuration *cfg) | 566 | const struct test_configuration *cfg) |
529 | { | 567 | { |
530 | struct test_properties properties; | 568 | struct test_properties properties; |
531 | memset(&properties, 0, sizeof(properties)); | 569 | memset (&properties, 0, sizeof(properties)); |
532 | 570 | ||
533 | properties.cfg = cfg; | 571 | properties.cfg = cfg; |
534 | properties.peers = GNUNET_new_array(cfg->count, struct test_peer); | 572 | properties.peers = GNUNET_new_array (cfg->count, struct test_peer); |
535 | 573 | ||
536 | for (unsigned int i = 0; i < cfg->count; i++) | 574 | for (unsigned int i = 0; i < cfg->count; i++) |
537 | if (0 != (cfg->stages[i] & 0x11)) | 575 | if (0 != (cfg->stages[i] & 0x11)) |
538 | properties.num_hosts++; | 576 | properties.num_hosts++; |
539 | 577 | ||
540 | properties.status = 1; | 578 | properties.status = 1; |
541 | properties.barrier = GNUNET_init_barrier (cfg->count, &barrier_cb, &properties); | 579 | properties.barrier = GNUNET_init_barrier (cfg->count, &barrier_cb, |
580 | &properties); | ||
542 | 581 | ||
543 | if (GNUNET_OK != GNUNET_TESTBED_test_run (test_name, "test_messenger_api.conf", | 582 | if (GNUNET_OK != GNUNET_TESTBED_test_run (test_name, |
583 | "test_messenger_api.conf", | ||
544 | cfg->count, | 584 | cfg->count, |
545 | (1LL << GNUNET_TESTBED_ET_PEER_START), | 585 | (1LL << |
586 | GNUNET_TESTBED_ET_PEER_START), | ||
546 | &run, &properties, | 587 | &run, &properties, |
547 | &init, &properties)) | 588 | &init, &properties)) |
548 | return 1; | 589 | return 1; |
549 | 590 | ||
550 | GNUNET_free(properties.peers); | 591 | GNUNET_free (properties.peers); |
551 | 592 | ||
552 | return properties.status; | 593 | return properties.status; |
553 | } | 594 | } |