diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-23 22:32:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-23 22:32:35 +0000 |
commit | 658c3cf583b0c09e55c41a78a9ec8dbe28cb515e (patch) | |
tree | 236759ed9a5b6a5e3493667c34f384279bc12bbe | |
parent | 1d188d2b9437f8a7685d0d139da7a6b9fb1b7c9c (diff) | |
download | gnunet-658c3cf583b0c09e55c41a78a9ec8dbe28cb515e.tar.gz gnunet-658c3cf583b0c09e55c41a78a9ec8dbe28cb515e.zip |
more refactoring of tests for new send API
-rw-r--r-- | src/transport/Makefile.am | 16 | ||||
-rw-r--r-- | src/transport/test_transport_address_switch.c | 2 | ||||
-rw-r--r-- | src/transport/test_transport_api_restart_2peers.c | 298 | ||||
-rw-r--r-- | src/transport/test_transport_api_restart_reconnect.c (renamed from src/transport/test_transport_api_restart_1peer.c) | 146 | ||||
-rw-r--r-- | src/transport/transport-testing-main.c | 7 | ||||
-rw-r--r-- | src/transport/transport-testing-send.c | 5 | ||||
-rw-r--r-- | src/transport/transport-testing.c | 61 | ||||
-rw-r--r-- | src/transport/transport-testing.h | 5 |
8 files changed, 108 insertions, 432 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index d6c4e3ccf..b201ab24a 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -431,7 +431,6 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \ | |||
431 | 431 | ||
432 | if HAVE_TESTING | 432 | if HAVE_TESTING |
433 | check_PROGRAMS = \ | 433 | check_PROGRAMS = \ |
434 | test_transport_api_restart_2peers \ | ||
435 | test_transport_address_switch_tcp \ | 434 | test_transport_address_switch_tcp \ |
436 | test_transport_address_switch_udp \ | 435 | test_transport_address_switch_udp \ |
437 | test_transport_testing_startstop \ | 436 | test_transport_testing_startstop \ |
@@ -450,6 +449,7 @@ check_PROGRAMS = \ | |||
450 | test_transport_api_disconnect_tcp \ | 449 | test_transport_api_disconnect_tcp \ |
451 | test_transport_api_tcp \ | 450 | test_transport_api_tcp \ |
452 | test_transport_api_restart_1peer \ | 451 | test_transport_api_restart_1peer \ |
452 | test_transport_api_restart_2peers \ | ||
453 | test_transport_api_timeout_tcp \ | 453 | test_transport_api_timeout_tcp \ |
454 | test_transport_api_limited_sockets_tcp \ | 454 | test_transport_api_limited_sockets_tcp \ |
455 | test_transport_api_tcp_nat \ | 455 | test_transport_api_tcp_nat \ |
@@ -508,6 +508,10 @@ endif | |||
508 | if ENABLE_TEST_RUN | 508 | if ENABLE_TEST_RUN |
509 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; | 509 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; |
510 | TESTS = \ | 510 | TESTS = \ |
511 | test_transport_address_switch_tcp \ | ||
512 | test_transport_address_switch_udp \ | ||
513 | $(HTTP_SWITCH) \ | ||
514 | $(HTTPS_SWITCH) \ | ||
511 | test_transport_testing_startstop \ | 515 | test_transport_testing_startstop \ |
512 | test_transport_testing_restart \ | 516 | test_transport_testing_restart \ |
513 | test_plugin_tcp \ | 517 | test_plugin_tcp \ |
@@ -563,11 +567,7 @@ TESTS = \ | |||
563 | $(HTTP_API_TIMEOUT_TEST) \ | 567 | $(HTTP_API_TIMEOUT_TEST) \ |
564 | $(HTTPS_API_TIMEOUT_TEST) \ | 568 | $(HTTPS_API_TIMEOUT_TEST) \ |
565 | $(WLAN_TIMEOUT_TEST) \ | 569 | $(WLAN_TIMEOUT_TEST) \ |
566 | $(BT_TIMEOUT_TEST) \ | 570 | $(BT_TIMEOUT_TEST) |
567 | test_transport_address_switch_tcp \ | ||
568 | test_transport_address_switch_udp \ | ||
569 | $(HTTP_SWITCH) \ | ||
570 | $(HTTPS_SWITCH) | ||
571 | if HAVE_GETOPT_BINARY | 571 | if HAVE_GETOPT_BINARY |
572 | TESTS += \ | 572 | TESTS += \ |
573 | test_transport_api_slow_ats | 573 | test_transport_api_slow_ats |
@@ -762,7 +762,7 @@ test_transport_api_tcp_LDADD = \ | |||
762 | libgnunettransporttesting.la | 762 | libgnunettransporttesting.la |
763 | 763 | ||
764 | test_transport_api_restart_1peer_SOURCES = \ | 764 | test_transport_api_restart_1peer_SOURCES = \ |
765 | test_transport_api_restart_1peer.c | 765 | test_transport_api_restart_reconnect.c |
766 | test_transport_api_restart_1peer_LDADD = \ | 766 | test_transport_api_restart_1peer_LDADD = \ |
767 | libgnunettransport.la \ | 767 | libgnunettransport.la \ |
768 | $(top_builddir)/src/hello/libgnunethello.la \ | 768 | $(top_builddir)/src/hello/libgnunethello.la \ |
@@ -772,7 +772,7 @@ test_transport_api_restart_1peer_LDADD = \ | |||
772 | libgnunettransporttesting.la | 772 | libgnunettransporttesting.la |
773 | 773 | ||
774 | test_transport_api_restart_2peers_SOURCES = \ | 774 | test_transport_api_restart_2peers_SOURCES = \ |
775 | test_transport_api_restart_2peers.c | 775 | test_transport_api_restart_reconnect.c |
776 | test_transport_api_restart_2peers_LDADD = \ | 776 | test_transport_api_restart_2peers_LDADD = \ |
777 | libgnunettransport.la \ | 777 | libgnunettransport.la \ |
778 | $(top_builddir)/src/hello/libgnunethello.la \ | 778 | $(top_builddir)/src/hello/libgnunethello.la \ |
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c index 23325d392..3998854da 100644 --- a/src/transport/test_transport_address_switch.c +++ b/src/transport/test_transport_address_switch.c | |||
@@ -414,7 +414,7 @@ main (int argc, | |||
414 | { | 414 | { |
415 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 415 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
416 | .connect_continuation = &connected_cb, | 416 | .connect_continuation = &connected_cb, |
417 | .config_file = "test_transport_api.conf", | 417 | .config_file = "test_transport_api_data.conf", |
418 | .rec = ¬ify_receive, | 418 | .rec = ¬ify_receive, |
419 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | 419 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
420 | .shutdown_task = &custom_shutdown, | 420 | .shutdown_task = &custom_shutdown, |
diff --git a/src/transport/test_transport_api_restart_2peers.c b/src/transport/test_transport_api_restart_2peers.c deleted file mode 100644 index 40f287623..000000000 --- a/src/transport/test_transport_api_restart_2peers.c +++ /dev/null | |||
@@ -1,298 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V. | ||
4 | |||
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 | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file transport/test_transport_api_restart_1peer.c | ||
22 | * @brief base test case for transport implementations | ||
23 | * | ||
24 | * This test case starts 2 peers, connects and exchanges a message | ||
25 | * 1 peer is restarted and tested if peers reconnect | ||
26 | * C code apparently. | ||
27 | */ | ||
28 | #include "platform.h" | ||
29 | #include "gnunet_transport_service.h" | ||
30 | #include "transport-testing.h" | ||
31 | |||
32 | /** | ||
33 | * How long until we give up on transmitting the message? | ||
34 | */ | ||
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
36 | |||
37 | /** | ||
38 | * How long until we give up on transmitting the message? | ||
39 | */ | ||
40 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
41 | |||
42 | #define MTYPE 12345 | ||
43 | |||
44 | |||
45 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | ||
46 | |||
47 | static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; | ||
48 | |||
49 | static int p1_connected; | ||
50 | |||
51 | static int p2_connected; | ||
52 | |||
53 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
54 | |||
55 | static struct GNUNET_SCHEDULER_Task *send_task; | ||
56 | |||
57 | static int restarted; | ||
58 | |||
59 | |||
60 | static void | ||
61 | custom_shutdown (void *cls) | ||
62 | { | ||
63 | if (NULL != ats_sh) | ||
64 | { | ||
65 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); | ||
66 | ats_sh = NULL; | ||
67 | } | ||
68 | if (NULL != th) | ||
69 | { | ||
70 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
71 | th = NULL; | ||
72 | } | ||
73 | if (NULL != send_task) | ||
74 | { | ||
75 | GNUNET_SCHEDULER_cancel (send_task); | ||
76 | send_task = NULL; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | |||
81 | static void | ||
82 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | ||
83 | void *cls) | ||
84 | { | ||
85 | static unsigned int c; | ||
86 | |||
87 | c++; | ||
88 | if (c != 2) | ||
89 | return; | ||
90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
91 | "Restarted peer %u (`%s'), issuing reconnect\n", | ||
92 | p->no, | ||
93 | GNUNET_i2s (&p->id)); | ||
94 | ats_sh = GNUNET_ATS_connectivity_suggest (ccc->p[0]->ats, | ||
95 | &ccc->p[1]->id, | ||
96 | 1); | ||
97 | } | ||
98 | |||
99 | |||
100 | static void | ||
101 | restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) | ||
102 | { | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
104 | "Restarting peer %u (`%s')\n", | ||
105 | p->no, | ||
106 | GNUNET_i2s (&p->id)); | ||
107 | GNUNET_assert (GNUNET_OK == | ||
108 | GNUNET_TRANSPORT_TESTING_restart_peer (p, | ||
109 | &restart_cb, | ||
110 | p)); | ||
111 | } | ||
112 | |||
113 | |||
114 | static void | ||
115 | notify_receive (void *cls, | ||
116 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | ||
117 | const struct GNUNET_PeerIdentity *sender, | ||
118 | const struct GNUNET_MessageHeader *message) | ||
119 | { | ||
120 | { | ||
121 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | ||
122 | |||
123 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
124 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", | ||
125 | receiver->no, | ||
126 | ps, | ||
127 | ntohs (message->type), | ||
128 | ntohs (message->size), | ||
129 | GNUNET_i2s (sender)); | ||
130 | GNUNET_free (ps); | ||
131 | } | ||
132 | if ((MTYPE == ntohs (message->type)) && | ||
133 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | ||
134 | { | ||
135 | if (GNUNET_NO == restarted) | ||
136 | { | ||
137 | restarted = GNUNET_YES; | ||
138 | restart (ccc->p[0]); | ||
139 | restart (ccc->p[1]); | ||
140 | return; | ||
141 | } | ||
142 | else | ||
143 | { | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
145 | "Restarted peers connected and message was sent, stopping test...\n"); | ||
146 | ccc->global_ret = GNUNET_OK; | ||
147 | GNUNET_SCHEDULER_shutdown (); | ||
148 | } | ||
149 | } | ||
150 | else | ||
151 | { | ||
152 | GNUNET_break (0); | ||
153 | ccc->global_ret = GNUNET_SYSERR; | ||
154 | GNUNET_SCHEDULER_shutdown (); | ||
155 | } | ||
156 | } | ||
157 | |||
158 | |||
159 | static size_t | ||
160 | notify_ready (void *cls, | ||
161 | size_t size, | ||
162 | void *buf) | ||
163 | { | ||
164 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
165 | struct GNUNET_MessageHeader *hdr; | ||
166 | |||
167 | th = NULL; | ||
168 | if (NULL == buf) | ||
169 | { | ||
170 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
171 | "Timeout occurred while waiting for transmit_ready\n"); | ||
172 | GNUNET_SCHEDULER_shutdown (); | ||
173 | ccc->global_ret = 42; | ||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | GNUNET_assert (size >= 256); | ||
178 | hdr = buf; | ||
179 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
180 | hdr->type = htons (MTYPE); | ||
181 | |||
182 | { | ||
183 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); | ||
184 | |||
185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
186 | "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n", | ||
187 | ccc->p[1]->no, | ||
188 | ps, | ||
189 | ntohs (hdr->type), | ||
190 | ntohs (hdr->size), | ||
191 | p->no, | ||
192 | GNUNET_i2s (&p->id)); | ||
193 | GNUNET_free (ps); | ||
194 | } | ||
195 | return sizeof (struct GNUNET_MessageHeader); | ||
196 | } | ||
197 | |||
198 | |||
199 | static void | ||
200 | sendtask (void *cls) | ||
201 | { | ||
202 | send_task = NULL; | ||
203 | { | ||
204 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); | ||
205 | |||
206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
207 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | ||
208 | ccc->p[1]->no, | ||
209 | GNUNET_i2s (&ccc->p[1]->id), | ||
210 | ccc->p[0]->no, | ||
211 | receiver_s); | ||
212 | GNUNET_free (receiver_s); | ||
213 | } | ||
214 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, | ||
215 | &ccc->p[0]->id, | ||
216 | 256, | ||
217 | TIMEOUT_TRANSMIT, | ||
218 | ¬ify_ready, | ||
219 | ccc->p[0]); | ||
220 | } | ||
221 | |||
222 | |||
223 | static void | ||
224 | notify_connect (void *cls, | ||
225 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
226 | const struct GNUNET_PeerIdentity *other) | ||
227 | { | ||
228 | GNUNET_TRANSPORT_TESTING_log_connect (cls, | ||
229 | me, | ||
230 | other); | ||
231 | if (0 == memcmp (other, | ||
232 | &ccc->p[0]->id, | ||
233 | sizeof (struct GNUNET_PeerIdentity))) | ||
234 | p1_connected = GNUNET_YES; | ||
235 | if (0 == memcmp (other, | ||
236 | &ccc->p[1]->id, | ||
237 | sizeof (struct GNUNET_PeerIdentity))) | ||
238 | p2_connected = GNUNET_YES; | ||
239 | |||
240 | if ( (GNUNET_YES == restarted) && | ||
241 | (GNUNET_YES == p1_connected) && | ||
242 | (GNUNET_YES == p2_connected) ) | ||
243 | { | ||
244 | /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ | ||
245 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, | ||
246 | NULL); | ||
247 | } | ||
248 | } | ||
249 | |||
250 | |||
251 | static void | ||
252 | notify_disconnect (void *cls, | ||
253 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
254 | const struct GNUNET_PeerIdentity *other) | ||
255 | { | ||
256 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, | ||
257 | me, | ||
258 | other); | ||
259 | if (me == ccc->p[0]) | ||
260 | p1_connected = GNUNET_NO; | ||
261 | if (me == ccc->p[1]) | ||
262 | p2_connected = GNUNET_NO; | ||
263 | if (NULL != th) | ||
264 | { | ||
265 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
266 | th = NULL; | ||
267 | } | ||
268 | if (NULL != send_task) | ||
269 | { | ||
270 | GNUNET_SCHEDULER_cancel (send_task); | ||
271 | send_task = NULL; | ||
272 | } | ||
273 | } | ||
274 | |||
275 | |||
276 | int | ||
277 | main (int argc, char *argv[]) | ||
278 | { | ||
279 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | ||
280 | .connect_continuation = &sendtask, | ||
281 | .config_file = "test_transport_api_data.conf", | ||
282 | .rec = ¬ify_receive, | ||
283 | .nc = ¬ify_connect, | ||
284 | .nd = ¬ify_disconnect, | ||
285 | .shutdown_task = &custom_shutdown, | ||
286 | .timeout = TIMEOUT | ||
287 | }; | ||
288 | |||
289 | ccc = &my_ccc; | ||
290 | if (GNUNET_OK != | ||
291 | GNUNET_TRANSPORT_TESTING_main (2, | ||
292 | &GNUNET_TRANSPORT_TESTING_connect_check, | ||
293 | ccc)) | ||
294 | return 1; | ||
295 | return 0; | ||
296 | } | ||
297 | |||
298 | /* end of test_transport_api_restart_1peer.c */ | ||
diff --git a/src/transport/test_transport_api_restart_1peer.c b/src/transport/test_transport_api_restart_reconnect.c index 7a63ed16b..6fd969918 100644 --- a/src/transport/test_transport_api_restart_1peer.c +++ b/src/transport/test_transport_api_restart_reconnect.c | |||
@@ -18,12 +18,12 @@ | |||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file transport/test_transport_api_restart_1peer.c | 21 | * @file transport/test_transport_api_restart_reconnect.c |
22 | * @brief base test case for transport implementations | 22 | * @brief base test case for transport implementations |
23 | * | 23 | * |
24 | * This test case starts 2 peers, connects and exchanges a message | 24 | * This test case starts 2 peers, connects and exchanges a message. |
25 | * 1 peer is restarted and tested if peers reconnect | 25 | * Then, 1 or 2 peers are restarted and it is tested if peers reconnect. |
26 | * C code apparently. | 26 | * How many peers are restarted is determined by the name of the binary. |
27 | */ | 27 | */ |
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_transport_service.h" | 29 | #include "gnunet_transport_service.h" |
@@ -34,13 +34,6 @@ | |||
34 | */ | 34 | */ |
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
36 | 36 | ||
37 | /** | ||
38 | * How long until we give up on transmitting the message? | ||
39 | */ | ||
40 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
41 | |||
42 | #define MTYPE 12345 | ||
43 | |||
44 | 37 | ||
45 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | 38 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
46 | 39 | ||
@@ -50,10 +43,6 @@ static int p1_connected; | |||
50 | 43 | ||
51 | static int p2_connected; | 44 | static int p2_connected; |
52 | 45 | ||
53 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
54 | |||
55 | static struct GNUNET_SCHEDULER_Task *send_task; | ||
56 | |||
57 | static int restarted; | 46 | static int restarted; |
58 | 47 | ||
59 | 48 | ||
@@ -65,16 +54,6 @@ custom_shutdown (void *cls) | |||
65 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); | 54 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); |
66 | ats_sh = NULL; | 55 | ats_sh = NULL; |
67 | } | 56 | } |
68 | if (NULL != th) | ||
69 | { | ||
70 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
71 | th = NULL; | ||
72 | } | ||
73 | if (NULL != send_task) | ||
74 | { | ||
75 | GNUNET_SCHEDULER_cancel (send_task); | ||
76 | send_task = NULL; | ||
77 | } | ||
78 | } | 57 | } |
79 | 58 | ||
80 | 59 | ||
@@ -82,6 +61,13 @@ static void | |||
82 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 61 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
83 | void *cls) | 62 | void *cls) |
84 | { | 63 | { |
64 | static unsigned int c; | ||
65 | |||
66 | c++; | ||
67 | if ( (2 != c) && | ||
68 | (NULL != strstr (ccc->test_name, | ||
69 | "2peers")) ) | ||
70 | return; | ||
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 71 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
86 | "Restarted peer %u (`%s'), issuing reconnect\n", | 72 | "Restarted peer %u (`%s'), issuing reconnect\n", |
87 | p->no, | 73 | p->no, |
@@ -124,13 +110,17 @@ notify_receive (void *cls, | |||
124 | GNUNET_i2s (sender)); | 110 | GNUNET_i2s (sender)); |
125 | GNUNET_free (ps); | 111 | GNUNET_free (ps); |
126 | } | 112 | } |
127 | if ((MTYPE == ntohs (message->type)) && | 113 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) && |
128 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | 114 | (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->size)) ) |
129 | { | 115 | { |
130 | if (GNUNET_NO == restarted) | 116 | if (GNUNET_NO == restarted) |
131 | { | 117 | { |
132 | restarted = GNUNET_YES; | 118 | restarted = GNUNET_YES; |
119 | fprintf (stderr, "TN: %s\n", ccc->test_name); | ||
133 | restart (ccc->p[0]); | 120 | restart (ccc->p[0]); |
121 | if (NULL != strstr (ccc->test_name, | ||
122 | "2peers")) | ||
123 | restart (ccc->p[1]); | ||
134 | return; | 124 | return; |
135 | } | 125 | } |
136 | else | 126 | else |
@@ -150,86 +140,22 @@ notify_receive (void *cls, | |||
150 | } | 140 | } |
151 | 141 | ||
152 | 142 | ||
153 | static size_t | ||
154 | notify_ready (void *cls, | ||
155 | size_t size, | ||
156 | void *buf) | ||
157 | { | ||
158 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
159 | struct GNUNET_MessageHeader *hdr; | ||
160 | |||
161 | th = NULL; | ||
162 | if (NULL == buf) | ||
163 | { | ||
164 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
165 | "Timeout occurred while waiting for transmit_ready\n"); | ||
166 | GNUNET_SCHEDULER_shutdown (); | ||
167 | ccc->global_ret = 42; | ||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | GNUNET_assert (size >= 256); | ||
172 | hdr = buf; | ||
173 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
174 | hdr->type = htons (MTYPE); | ||
175 | |||
176 | { | ||
177 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); | ||
178 | |||
179 | |||
180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
181 | "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n", | ||
182 | ccc->p[1]->no, | ||
183 | ps, | ||
184 | ntohs (hdr->type), | ||
185 | ntohs (hdr->size), | ||
186 | p->no, | ||
187 | GNUNET_i2s (&p->id)); | ||
188 | GNUNET_free (ps); | ||
189 | } | ||
190 | return sizeof (struct GNUNET_MessageHeader); | ||
191 | } | ||
192 | |||
193 | |||
194 | static void | ||
195 | sendtask (void *cls) | ||
196 | { | ||
197 | send_task = NULL; | ||
198 | { | ||
199 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); | ||
200 | |||
201 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
202 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | ||
203 | ccc->p[1]->no, | ||
204 | GNUNET_i2s (&ccc->p[1]->id), | ||
205 | ccc->p[0]->no, | ||
206 | receiver_s); | ||
207 | GNUNET_free (receiver_s); | ||
208 | } | ||
209 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, | ||
210 | &ccc->p[0]->id, | ||
211 | 256, | ||
212 | TIMEOUT_TRANSMIT, | ||
213 | ¬ify_ready, | ||
214 | ccc->p[0]); | ||
215 | } | ||
216 | |||
217 | |||
218 | static void | 143 | static void |
219 | notify_connect (void *cls, | 144 | notify_connect (void *cls, |
220 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | 145 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
221 | const struct GNUNET_PeerIdentity *other) | 146 | const struct GNUNET_PeerIdentity *other) |
222 | { | 147 | { |
148 | static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | ||
149 | .num_messages = 1 | ||
150 | }; | ||
151 | |||
152 | sc.ccc = ccc; | ||
223 | GNUNET_TRANSPORT_TESTING_log_connect (cls, | 153 | GNUNET_TRANSPORT_TESTING_log_connect (cls, |
224 | me, | 154 | me, |
225 | other); | 155 | other); |
226 | if (0 == memcmp (other, | 156 | if (me == ccc->p[0]) |
227 | &ccc->p[0]->id, | ||
228 | sizeof (struct GNUNET_PeerIdentity))) | ||
229 | p1_connected = GNUNET_YES; | 157 | p1_connected = GNUNET_YES; |
230 | if (0 == memcmp (other, | 158 | if (me == ccc->p[1]) |
231 | &ccc->p[1]->id, | ||
232 | sizeof (struct GNUNET_PeerIdentity))) | ||
233 | p2_connected = GNUNET_YES; | 159 | p2_connected = GNUNET_YES; |
234 | 160 | ||
235 | if ( (GNUNET_YES == restarted) && | 161 | if ( (GNUNET_YES == restarted) && |
@@ -237,8 +163,8 @@ notify_connect (void *cls, | |||
237 | (GNUNET_YES == p2_connected) ) | 163 | (GNUNET_YES == p2_connected) ) |
238 | { | 164 | { |
239 | /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ | 165 | /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ |
240 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, | 166 | GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send, |
241 | NULL); | 167 | &sc); |
242 | } | 168 | } |
243 | } | 169 | } |
244 | 170 | ||
@@ -255,24 +181,19 @@ notify_disconnect (void *cls, | |||
255 | p1_connected = GNUNET_NO; | 181 | p1_connected = GNUNET_NO; |
256 | if (me == ccc->p[1]) | 182 | if (me == ccc->p[1]) |
257 | p2_connected = GNUNET_NO; | 183 | p2_connected = GNUNET_NO; |
258 | if (NULL != th) | ||
259 | { | ||
260 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
261 | th = NULL; | ||
262 | } | ||
263 | if (NULL != send_task) | ||
264 | { | ||
265 | GNUNET_SCHEDULER_cancel (send_task); | ||
266 | send_task = NULL; | ||
267 | } | ||
268 | } | 184 | } |
269 | 185 | ||
270 | 186 | ||
271 | int | 187 | int |
272 | main (int argc, char *argv[]) | 188 | main (int argc, |
189 | char *argv[]) | ||
273 | { | 190 | { |
191 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | ||
192 | .num_messages = 1 | ||
193 | }; | ||
274 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 194 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
275 | .connect_continuation = &sendtask, | 195 | .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send, |
196 | .connect_continuation_cls = &sc, | ||
276 | .config_file = "test_transport_api_data.conf", | 197 | .config_file = "test_transport_api_data.conf", |
277 | .rec = ¬ify_receive, | 198 | .rec = ¬ify_receive, |
278 | .nc = ¬ify_connect, | 199 | .nc = ¬ify_connect, |
@@ -282,6 +203,7 @@ main (int argc, char *argv[]) | |||
282 | }; | 203 | }; |
283 | 204 | ||
284 | ccc = &my_ccc; | 205 | ccc = &my_ccc; |
206 | sc.ccc = ccc; | ||
285 | if (GNUNET_OK != | 207 | if (GNUNET_OK != |
286 | GNUNET_TRANSPORT_TESTING_main (2, | 208 | GNUNET_TRANSPORT_TESTING_main (2, |
287 | &GNUNET_TRANSPORT_TESTING_connect_check, | 209 | &GNUNET_TRANSPORT_TESTING_connect_check, |
diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c index f196d586b..79f6a0152 100644 --- a/src/transport/transport-testing-main.c +++ b/src/transport/transport-testing-main.c | |||
@@ -145,9 +145,8 @@ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext | |||
145 | 145 | ||
146 | 146 | ||
147 | /** | 147 | /** |
148 | * Function called when we connected two peers. | 148 | * Function called when we connected two peers. Once we have gotten |
149 | * Once we have gotten to the clique, launch | 149 | * to the clique, launch test-specific logic. |
150 | * test-specific logic. | ||
151 | * | 150 | * |
152 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *` | 151 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *` |
153 | */ | 152 | */ |
@@ -511,7 +510,7 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, | |||
511 | for (unsigned int i=0;i<num_peers;i++) | 510 | for (unsigned int i=0;i<num_peers;i++) |
512 | GNUNET_free (cfg_names[i]); | 511 | GNUNET_free (cfg_names[i]); |
513 | GNUNET_free (test_source); | 512 | GNUNET_free (test_source); |
514 | GNUNET_free (test_plugin); | 513 | GNUNET_free_non_null (test_plugin); |
515 | GNUNET_free (test_name); | 514 | GNUNET_free (test_name); |
516 | return ret; | 515 | return ret; |
517 | } | 516 | } |
diff --git a/src/transport/transport-testing-send.c b/src/transport/transport-testing-send.c index 60fed23a6..cbf294bcf 100644 --- a/src/transport/transport-testing-send.c +++ b/src/transport/transport-testing-send.c | |||
@@ -96,6 +96,8 @@ find_cr (void *cls, | |||
96 | { | 96 | { |
97 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls; | 97 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls; |
98 | 98 | ||
99 | if (GNUNET_NO == cx->connected) | ||
100 | return; | ||
99 | *cr = cx; | 101 | *cr = cx; |
100 | } | 102 | } |
101 | 103 | ||
@@ -144,8 +146,7 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send | |||
144 | sender, | 146 | sender, |
145 | &find_cr, | 147 | &find_cr, |
146 | &cr); | 148 | &cr); |
147 | if ( (NULL == cr) || | 149 | if (NULL == cr) |
148 | (GNUNET_YES != cr->connected) ) | ||
149 | { | 150 | { |
150 | GNUNET_break (0); | 151 | GNUNET_break (0); |
151 | return GNUNET_NO; | 152 | return GNUNET_NO; |
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 50c297389..899ef7851 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c | |||
@@ -77,6 +77,10 @@ static void | |||
77 | set_p1c (void *cls, | 77 | set_p1c (void *cls, |
78 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) | 78 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) |
79 | { | 79 | { |
80 | int *found = cls; | ||
81 | |||
82 | if (NULL != found) | ||
83 | *found = GNUNET_YES; | ||
80 | cx->p1_c = GNUNET_YES; | 84 | cx->p1_c = GNUNET_YES; |
81 | } | 85 | } |
82 | 86 | ||
@@ -85,6 +89,10 @@ static void | |||
85 | set_p2c (void *cls, | 89 | set_p2c (void *cls, |
86 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) | 90 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) |
87 | { | 91 | { |
92 | int *found = cls; | ||
93 | |||
94 | if (NULL != found) | ||
95 | *found = GNUNET_YES; | ||
88 | cx->p2_c = GNUNET_YES; | 96 | cx->p2_c = GNUNET_YES; |
89 | } | 97 | } |
90 | 98 | ||
@@ -93,6 +101,10 @@ static void | |||
93 | clear_p1c (void *cls, | 101 | clear_p1c (void *cls, |
94 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) | 102 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) |
95 | { | 103 | { |
104 | int *found = cls; | ||
105 | |||
106 | if (NULL != found) | ||
107 | *found = GNUNET_YES; | ||
96 | cx->p1_c = GNUNET_NO; | 108 | cx->p1_c = GNUNET_NO; |
97 | } | 109 | } |
98 | 110 | ||
@@ -101,6 +113,10 @@ static void | |||
101 | clear_p2c (void *cls, | 113 | clear_p2c (void *cls, |
102 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) | 114 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) |
103 | { | 115 | { |
116 | int *found = cls; | ||
117 | |||
118 | if (NULL != found) | ||
119 | *found = GNUNET_YES; | ||
104 | cx->p2_c = GNUNET_NO; | 120 | cx->p2_c = GNUNET_NO; |
105 | } | 121 | } |
106 | 122 | ||
@@ -115,6 +131,7 @@ notify_connect (void *cls, | |||
115 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | 131 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; |
116 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; | 132 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; |
117 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; | 133 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; |
134 | int found; | ||
118 | 135 | ||
119 | p2 = find_peer_context (p->tth, | 136 | p2 = find_peer_context (p->tth, |
120 | peer); | 137 | peer); |
@@ -138,14 +155,36 @@ notify_connect (void *cls, | |||
138 | GNUNET_i2s (&p->id)); | 155 | GNUNET_i2s (&p->id)); |
139 | GNUNET_free (p2_s); | 156 | GNUNET_free (p2_s); |
140 | /* update flags in connecting contexts */ | 157 | /* update flags in connecting contexts */ |
158 | found = GNUNET_NO; | ||
141 | GNUNET_TRANSPORT_TESTING_find_connecting_context (p, | 159 | GNUNET_TRANSPORT_TESTING_find_connecting_context (p, |
142 | p2, | 160 | p2, |
143 | &set_p1c, | 161 | &set_p1c, |
144 | NULL); | 162 | &found); |
163 | if (GNUNET_NO == found) | ||
164 | { | ||
165 | cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); | ||
166 | cc->p1 = p; | ||
167 | cc->p2 = p2; | ||
168 | cc->p1_c = GNUNET_YES; | ||
169 | GNUNET_CONTAINER_DLL_insert (tth->cc_head, | ||
170 | tth->cc_tail, | ||
171 | cc); | ||
172 | } | ||
173 | found = GNUNET_NO; | ||
145 | GNUNET_TRANSPORT_TESTING_find_connecting_context (p2, | 174 | GNUNET_TRANSPORT_TESTING_find_connecting_context (p2, |
146 | p, | 175 | p, |
147 | &set_p2c, | 176 | &set_p2c, |
148 | NULL); | 177 | &found); |
178 | if (GNUNET_NO == found) | ||
179 | { | ||
180 | cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); | ||
181 | cc->p1 = p2; | ||
182 | cc->p2 = p; | ||
183 | cc->p1_c = GNUNET_YES; | ||
184 | GNUNET_CONTAINER_DLL_insert (tth->cc_head, | ||
185 | tth->cc_tail, | ||
186 | cc); | ||
187 | } | ||
149 | /* update set connected flag for all requests */ | 188 | /* update set connected flag for all requests */ |
150 | for (cc = tth->cc_head; NULL != cc; cc = cc->next) | 189 | for (cc = tth->cc_head; NULL != cc; cc = cc->next) |
151 | { | 190 | { |
@@ -703,7 +742,19 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerCont | |||
703 | { | 742 | { |
704 | struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth; | 743 | struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth; |
705 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; | 744 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; |
745 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; | ||
706 | 746 | ||
747 | ccn = NULL; | ||
748 | for (cc = tth->cc_head; NULL != cc; cc = cc->next) | ||
749 | { | ||
750 | if ( (cc->p1 == p1) && | ||
751 | (cc->p2 == p2) ) | ||
752 | { | ||
753 | ccn = cc; | ||
754 | break; | ||
755 | } | ||
756 | } | ||
757 | |||
707 | cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); | 758 | cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); |
708 | cc->p1 = p1; | 759 | cc->p1 = p1; |
709 | cc->p2 = p2; | 760 | cc->p2 = p2; |
@@ -712,6 +763,12 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerCont | |||
712 | cc->cb_cls = cls; | 763 | cc->cb_cls = cls; |
713 | else | 764 | else |
714 | cc->cb_cls = cc; | 765 | cc->cb_cls = cc; |
766 | if (NULL != ccn) | ||
767 | { | ||
768 | cc->p1_c = ccn->p1_c; | ||
769 | cc->p2_c = ccn->p2_c; | ||
770 | cc->connected = ccn->connected; | ||
771 | } | ||
715 | GNUNET_CONTAINER_DLL_insert (tth->cc_head, | 772 | GNUNET_CONTAINER_DLL_insert (tth->cc_head, |
716 | tth->cc_tail, | 773 | tth->cc_tail, |
717 | cc); | 774 | cc); |
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index bfed64b70..806b8c5f9 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h | |||
@@ -769,11 +769,6 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, | |||
769 | 769 | ||
770 | /* ***************** Convenience functions for sending ********* */ | 770 | /* ***************** Convenience functions for sending ********* */ |
771 | 771 | ||
772 | // TODO: | ||
773 | // - need to have continuation after send is done! | ||
774 | // - need easy way to specify continuation in case | ||
775 | // of the scheduler tasks | ||
776 | |||
777 | /** | 772 | /** |
778 | * Send a test message of type @a mtype and size @a msize from | 773 | * Send a test message of type @a mtype and size @a msize from |
779 | * peer @a sender to peer @a receiver. The peers should be | 774 | * peer @a sender to peer @a receiver. The peers should be |