diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-07 16:20:21 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-07 16:20:21 +0000 |
commit | 0663a057d7611270d5f41ae8b345125d737387f2 (patch) | |
tree | 39793c7c288dbef472c66cb1c8f12af48f6989b9 /src/transport/test_transport_api_reliability.c | |
parent | 013cf64f56c0a529f0c11597e912b39e4a0a896c (diff) | |
download | gnunet-0663a057d7611270d5f41ae8b345125d737387f2.tar.gz gnunet-0663a057d7611270d5f41ae8b345125d737387f2.zip |
transport-testing is not stateless anymore
-> fixed assertion failure transport_api.c:1348
- connecting peers is now unidirectional
- added peer_startup callback
Diffstat (limited to 'src/transport/test_transport_api_reliability.c')
-rw-r--r-- | src/transport/test_transport_api_reliability.c | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index e028c93fd..0719a9e47 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c | |||
@@ -79,6 +79,8 @@ char *cfg_file_p1; | |||
79 | 79 | ||
80 | char *cfg_file_p2; | 80 | char *cfg_file_p2; |
81 | 81 | ||
82 | struct TransportTestingHandle * tth; | ||
83 | |||
82 | /* | 84 | /* |
83 | * Testcase specific declarations | 85 | * Testcase specific declarations |
84 | */ | 86 | */ |
@@ -145,8 +147,8 @@ end () | |||
145 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 147 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
146 | th = NULL; | 148 | th = NULL; |
147 | 149 | ||
148 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | 150 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
149 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | 151 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); |
150 | } | 152 | } |
151 | 153 | ||
152 | static void | 154 | static void |
@@ -165,9 +167,11 @@ end_badly () | |||
165 | th = NULL; | 167 | th = NULL; |
166 | 168 | ||
167 | if (p1 != NULL) | 169 | if (p1 != NULL) |
168 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | 170 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
169 | if (p2 != NULL) | 171 | if (p2 != NULL) |
170 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | 172 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); |
173 | |||
174 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
171 | 175 | ||
172 | ok = GNUNET_SYSERR; | 176 | ok = GNUNET_SYSERR; |
173 | } | 177 | } |
@@ -255,8 +259,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
255 | if (n == TOTAL_MSGS) | 259 | if (n == TOTAL_MSGS) |
256 | { | 260 | { |
257 | ok = 0; | 261 | ok = 0; |
258 | fprintf (stderr, "\n"); | 262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\nAll messages received\n"); |
259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages received\n"); | ||
260 | end (); | 263 | end (); |
261 | } | 264 | } |
262 | } | 265 | } |
@@ -399,35 +402,22 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | |||
399 | p2->no, GNUNET_i2s (&p2->id)); | 402 | p2->no, GNUNET_i2s (&p2->id)); |
400 | GNUNET_free (p1_c); | 403 | GNUNET_free (p1_c); |
401 | 404 | ||
402 | // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! | 405 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); |
403 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL); | ||
404 | } | 406 | } |
405 | 407 | ||
406 | static void | 408 | void start_cb (struct PeerContext * p, |
407 | run (void *cls, char *const *args, const char *cfgfile, | 409 | void *cls) |
408 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
409 | { | 410 | { |
410 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 411 | static int started; |
412 | started++; | ||
411 | 413 | ||
412 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1, | 414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", |
413 | ¬ify_receive, | 415 | p->no, |
414 | ¬ify_connect, ¬ify_disconnect, | 416 | GNUNET_i2s (&p->id)); |
415 | NULL); | ||
416 | p1->no = 1; | ||
417 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2, | ||
418 | ¬ify_receive, | ||
419 | ¬ify_connect, ¬ify_disconnect, | ||
420 | NULL); | ||
421 | p2->no = 2; | ||
422 | 417 | ||
423 | if ((p1 == NULL) || (p2 == NULL)) | 418 | if (started != 2) |
424 | { | ||
425 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | ||
426 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
427 | GNUNET_SCHEDULER_cancel (die_task); | ||
428 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
429 | return; | 419 | return; |
430 | } | 420 | |
431 | test_connected = GNUNET_NO; | 421 | test_connected = GNUNET_NO; |
432 | 422 | ||
433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n", | 423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u: `%s' using configuration file `%s'\n", |
@@ -445,7 +435,36 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
445 | sender->no, sender_c, | 435 | sender->no, sender_c, |
446 | receiver->no, GNUNET_i2s (&receiver->id)); | 436 | receiver->no, GNUNET_i2s (&receiver->id)); |
447 | 437 | ||
448 | GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL); | 438 | GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); |
439 | |||
440 | } | ||
441 | |||
442 | |||
443 | static void | ||
444 | run (void *cls, char *const *args, const char *cfgfile, | ||
445 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
446 | { | ||
447 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
448 | |||
449 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, | ||
450 | ¬ify_receive, | ||
451 | ¬ify_connect, ¬ify_disconnect, | ||
452 | &start_cb, | ||
453 | NULL); | ||
454 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, | ||
455 | ¬ify_receive, | ||
456 | ¬ify_connect, ¬ify_disconnect, | ||
457 | &start_cb, | ||
458 | NULL); | ||
459 | |||
460 | if ((p1 == NULL) || (p2 == NULL)) | ||
461 | { | ||
462 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | ||
463 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
464 | GNUNET_SCHEDULER_cancel (die_task); | ||
465 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
466 | return; | ||
467 | } | ||
449 | } | 468 | } |
450 | 469 | ||
451 | static int | 470 | static int |
@@ -479,6 +498,8 @@ main (int argc, char *argv[]) | |||
479 | int ret; | 498 | int ret; |
480 | int nat_res; | 499 | int nat_res; |
481 | 500 | ||
501 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
502 | |||
482 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); | 503 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); |
483 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, | 504 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, |
484 | &test_plugin); | 505 | &test_plugin); |