diff options
Diffstat (limited to 'src/transport/transport-testing.c')
-rw-r--r-- | src/transport/transport-testing.c | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 993103ac1..86c67a039 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2006, 2009 Christian Grothoff (and other contributing authors) | 3 | Copyright (C) 2006, 2009, 2015 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -48,12 +48,13 @@ find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
48 | } | 48 | } |
49 | 49 | ||
50 | 50 | ||
51 | static struct ConnectingContext * | 51 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * |
52 | find_connecting_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, | 52 | find_connecting_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, |
53 | struct PeerContext *p1, struct PeerContext *p2) | 53 | struct PeerContext *p1, |
54 | struct PeerContext *p2) | ||
54 | { | 55 | { |
55 | GNUNET_assert (tth != NULL); | 56 | GNUNET_assert (tth != NULL); |
56 | struct ConnectingContext *cc = tth->cc_head; | 57 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = tth->cc_head; |
57 | 58 | ||
58 | while (cc != NULL) | 59 | while (cc != NULL) |
59 | { | 60 | { |
@@ -69,7 +70,8 @@ find_connecting_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
69 | 70 | ||
70 | 71 | ||
71 | static void | 72 | static void |
72 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 73 | notify_connect (void *cls, |
74 | const struct GNUNET_PeerIdentity *peer) | ||
73 | { | 75 | { |
74 | struct PeerContext *p = cls; | 76 | struct PeerContext *p = cls; |
75 | char *p2_s; | 77 | char *p2_s; |
@@ -93,7 +95,7 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
93 | GNUNET_free (p2_s); | 95 | GNUNET_free (p2_s); |
94 | 96 | ||
95 | /* Find ConnectingContext */ | 97 | /* Find ConnectingContext */ |
96 | struct ConnectingContext *cc = find_connecting_context (p->tth, p, p2); | 98 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = find_connecting_context (p->tth, p, p2); |
97 | 99 | ||
98 | if (cc == NULL) | 100 | if (cc == NULL) |
99 | return; | 101 | return; |
@@ -113,7 +115,8 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
113 | 115 | ||
114 | 116 | ||
115 | static void | 117 | static void |
116 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 118 | notify_disconnect (void *cls, |
119 | const struct GNUNET_PeerIdentity *peer) | ||
117 | { | 120 | { |
118 | struct PeerContext *p = cls; | 121 | struct PeerContext *p = cls; |
119 | 122 | ||
@@ -149,7 +152,8 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
149 | 152 | ||
150 | 153 | ||
151 | static void | 154 | static void |
152 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 155 | notify_receive (void *cls, |
156 | const struct GNUNET_PeerIdentity *peer, | ||
153 | const struct GNUNET_MessageHeader *message) | 157 | const struct GNUNET_MessageHeader *message) |
154 | { | 158 | { |
155 | struct PeerContext *p = cls; | 159 | struct PeerContext *p = cls; |
@@ -162,7 +166,8 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
162 | 166 | ||
163 | 167 | ||
164 | static void | 168 | static void |
165 | get_hello (void *cb_cls, const struct GNUNET_MessageHeader *message) | 169 | get_hello (void *cb_cls, |
170 | const struct GNUNET_MessageHeader *message) | ||
166 | { | 171 | { |
167 | struct PeerContext *p = cb_cls; | 172 | struct PeerContext *p = cb_cls; |
168 | struct GNUNET_PeerIdentity hello_id; | 173 | struct GNUNET_PeerIdentity hello_id; |
@@ -187,9 +192,10 @@ get_hello (void *cb_cls, const struct GNUNET_MessageHeader *message) | |||
187 | 192 | ||
188 | 193 | ||
189 | static void | 194 | static void |
190 | try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 195 | try_connect (void *cls, |
196 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
191 | { | 197 | { |
192 | struct ConnectingContext *cc = cls; | 198 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; |
193 | struct PeerContext *p1 = cc->p1; | 199 | struct PeerContext *p1 = cc->p1; |
194 | struct PeerContext *p2 = cc->p2; | 200 | struct PeerContext *p2 = cc->p2; |
195 | 201 | ||
@@ -477,18 +483,16 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
477 | * @param cls callback cls | 483 | * @param cls callback cls |
478 | * @return a connect request handle | 484 | * @return a connect request handle |
479 | */ | 485 | */ |
480 | GNUNET_TRANSPORT_TESTING_ConnectRequest | 486 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest * |
481 | GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle *tth, | 487 | GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle *tth, |
482 | struct PeerContext *p1, | 488 | struct PeerContext *p1, |
483 | struct PeerContext *p2, | 489 | struct PeerContext *p2, |
484 | GNUNET_TRANSPORT_TESTING_connect_cb cb, | 490 | GNUNET_TRANSPORT_TESTING_connect_cb cb, |
485 | void *cls) | 491 | void *cls) |
486 | { | 492 | { |
487 | GNUNET_assert (tth != NULL); | 493 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); |
488 | |||
489 | struct ConnectingContext *cc = | ||
490 | GNUNET_new (struct ConnectingContext); | ||
491 | 494 | ||
495 | GNUNET_assert (tth != NULL); | ||
492 | GNUNET_assert (p1 != NULL); | 496 | GNUNET_assert (p1 != NULL); |
493 | GNUNET_assert (p2 != NULL); | 497 | GNUNET_assert (p2 != NULL); |
494 | cc->p1 = p1; | 498 | cc->p1 = p1; |
@@ -502,7 +506,9 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * | |||
502 | cc->th_p2 = p2->th; | 506 | cc->th_p2 = p2->th; |
503 | GNUNET_assert (cc->th_p1 != NULL); | 507 | GNUNET_assert (cc->th_p1 != NULL); |
504 | GNUNET_assert (cc->th_p2 != NULL); | 508 | GNUNET_assert (cc->th_p2 != NULL); |
505 | GNUNET_CONTAINER_DLL_insert (tth->cc_head, tth->cc_tail, cc); | 509 | GNUNET_CONTAINER_DLL_insert (tth->cc_head, |
510 | tth->cc_tail, | ||
511 | cc); | ||
506 | cc->tct = GNUNET_SCHEDULER_add_now (&try_connect, cc); | 512 | cc->tct = GNUNET_SCHEDULER_add_now (&try_connect, cc); |
507 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 513 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
508 | "New connect request %p\n", | 514 | "New connect request %p\n", |
@@ -517,17 +523,12 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * | |||
517 | * Tou MUST cancel the request if you stop the peers before the peers connected succesfully | 523 | * Tou MUST cancel the request if you stop the peers before the peers connected succesfully |
518 | * | 524 | * |
519 | * @param tth transport testing handle | 525 | * @param tth transport testing handle |
520 | * @param ccr a connect request handle | 526 | * @param cc a connect request handle |
521 | */ | 527 | */ |
522 | void | 528 | void |
523 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct | 529 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_handle *tth, |
524 | GNUNET_TRANSPORT_TESTING_handle | 530 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc) |
525 | *tth, | ||
526 | GNUNET_TRANSPORT_TESTING_ConnectRequest | ||
527 | ccr) | ||
528 | { | 531 | { |
529 | struct ConnectingContext *cc = ccr; | ||
530 | |||
531 | GNUNET_assert (tth != NULL); | 532 | GNUNET_assert (tth != NULL); |
532 | 533 | ||
533 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 534 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -550,8 +551,8 @@ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct | |||
550 | void | 551 | void |
551 | GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth) | 552 | GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth) |
552 | { | 553 | { |
553 | struct ConnectingContext *cc = tth->cc_head; | 554 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = tth->cc_head; |
554 | struct ConnectingContext *ct = NULL; | 555 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ct = NULL; |
555 | struct PeerContext *p = tth->p_head; | 556 | struct PeerContext *p = tth->p_head; |
556 | struct PeerContext *t = NULL; | 557 | struct PeerContext *t = NULL; |
557 | 558 | ||
@@ -596,11 +597,14 @@ GNUNET_TRANSPORT_TESTING_init () | |||
596 | tth = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_handle); | 597 | tth = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_handle); |
597 | 598 | ||
598 | /* Init testing the testing lib */ | 599 | /* Init testing the testing lib */ |
599 | tth->tl_system = GNUNET_TESTING_system_create ("transport-testing", NULL, | 600 | tth->tl_system = GNUNET_TESTING_system_create ("transport-testing", |
600 | NULL, NULL); | 601 | NULL, |
602 | NULL, | ||
603 | NULL); | ||
601 | if (NULL == tth->tl_system) | 604 | if (NULL == tth->tl_system) |
602 | { | 605 | { |
603 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize testing library!\n")); | 606 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
607 | _("Failed to initialize testing library!\n")); | ||
604 | GNUNET_free (tth); | 608 | GNUNET_free (tth); |
605 | return NULL; | 609 | return NULL; |
606 | } | 610 | } |
@@ -671,7 +675,8 @@ extract_filename (const char *file) | |||
671 | * @param dest where to store result | 675 | * @param dest where to store result |
672 | */ | 676 | */ |
673 | void | 677 | void |
674 | GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, char **dest) | 678 | GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, |
679 | char **dest) | ||
675 | { | 680 | { |
676 | char *filename = extract_filename (file); | 681 | char *filename = extract_filename (file); |
677 | char *backup = filename; | 682 | char *backup = filename; |
@@ -708,7 +713,8 @@ suc: | |||
708 | * @param dest where to store result | 713 | * @param dest where to store result |
709 | */ | 714 | */ |
710 | void | 715 | void |
711 | GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file, char **dest) | 716 | GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file, |
717 | char **dest) | ||
712 | { | 718 | { |
713 | char *src = extract_filename (file); | 719 | char *src = extract_filename (file); |
714 | char *split; | 720 | char *split; |
@@ -732,7 +738,8 @@ GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file, char **dest) | |||
732 | */ | 738 | */ |
733 | void | 739 | void |
734 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file, | 740 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file, |
735 | const char *test, char **dest) | 741 | const char *test, |
742 | char **dest) | ||
736 | { | 743 | { |
737 | char *filename; | 744 | char *filename; |
738 | char *dotexe; | 745 | char *dotexe; |
@@ -776,7 +783,8 @@ suc: | |||
776 | * @param count peer number | 783 | * @param count peer number |
777 | */ | 784 | */ |
778 | void | 785 | void |
779 | GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **dest, | 786 | GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, |
787 | char **dest, | ||
780 | int count) | 788 | int count) |
781 | { | 789 | { |
782 | char *filename = extract_filename (file); | 790 | char *filename = extract_filename (file); |