diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-10 17:42:09 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-10 17:42:09 +0000 |
commit | 64cf4ccedaffc379b253e9c08594ef520957a09f (patch) | |
tree | 13956fcd2cc7daa3e1b885d3f3be8d6be398ef55 /src/transport/test_transport_api_manipulation_cfg.c | |
parent | 611a879420bf940dff9039305314489586776896 (diff) | |
download | gnunet-64cf4ccedaffc379b253e9c08594ef520957a09f.tar.gz gnunet-64cf4ccedaffc379b253e9c08594ef520957a09f.zip |
modify manipulation_cfg test to use new transport-testing lib
Diffstat (limited to 'src/transport/test_transport_api_manipulation_cfg.c')
-rw-r--r-- | src/transport/test_transport_api_manipulation_cfg.c | 481 |
1 files changed, 135 insertions, 346 deletions
diff --git a/src/transport/test_transport_api_manipulation_cfg.c b/src/transport/test_transport_api_manipulation_cfg.c index a6dc08429..19823e0b3 100644 --- a/src/transport/test_transport_api_manipulation_cfg.c +++ b/src/transport/test_transport_api_manipulation_cfg.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2016 GNUnet e.V. |
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 |
@@ -18,7 +18,7 @@ | |||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file transport/test_transport_api_manipulation_send_tcp.c | 21 | * @file transport/test_transport_api_manipulation_cfg.c |
22 | * @brief base test case for transport traffic manipulation implementation | 22 | * @brief base test case for transport traffic manipulation implementation |
23 | * based onf cfg | 23 | * based onf cfg |
24 | * | 24 | * |
@@ -53,111 +53,31 @@ | |||
53 | */ | 53 | */ |
54 | #define TEST_DELAY 100 * 1000LL | 54 | #define TEST_DELAY 100 * 1000LL |
55 | 55 | ||
56 | static char *test_source; | ||
57 | 56 | ||
58 | static char *test_plugin; | 57 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
59 | |||
60 | static char *test_name; | ||
61 | |||
62 | static int ok; | ||
63 | |||
64 | static int s_started; | ||
65 | |||
66 | static int s_connected; | ||
67 | |||
68 | static int s_sending; | ||
69 | |||
70 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
71 | |||
72 | static struct GNUNET_SCHEDULER_Task * send_task; | ||
73 | |||
74 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | ||
75 | |||
76 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
77 | |||
78 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; | ||
79 | 58 | ||
80 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | 59 | static struct GNUNET_TRANSPORT_TransmitHandle *th; |
81 | 60 | ||
82 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; | 61 | static struct GNUNET_SCHEDULER_Task *send_task; |
83 | |||
84 | static char *cfg_file_p1; | ||
85 | |||
86 | static char *cfg_file_p2; | ||
87 | 62 | ||
88 | static struct GNUNET_TIME_Absolute start_request; | 63 | static struct GNUNET_TIME_Absolute start_request; |
89 | static struct GNUNET_TIME_Absolute start_response; | ||
90 | |||
91 | static void | ||
92 | end () | ||
93 | { | ||
94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | ||
95 | 64 | ||
96 | if (send_task != NULL) | 65 | static struct GNUNET_TIME_Absolute start_response; |
97 | GNUNET_SCHEDULER_cancel (send_task); | ||
98 | |||
99 | if (die_task != NULL) | ||
100 | GNUNET_SCHEDULER_cancel (die_task); | ||
101 | |||
102 | if (th != NULL) | ||
103 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
104 | th = NULL; | ||
105 | |||
106 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
107 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
108 | } | ||
109 | 66 | ||
110 | 67 | ||
111 | static void | 68 | static void |
112 | end_badly (void *cls) | 69 | custom_shutdown (void *cls) |
113 | { | 70 | { |
114 | die_task = NULL; | 71 | if (NULL != th) |
115 | |||
116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | ||
117 | |||
118 | |||
119 | if (send_task != NULL) | ||
120 | GNUNET_SCHEDULER_cancel (send_task); | ||
121 | |||
122 | if (cc != NULL) | ||
123 | { | 72 | { |
124 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); | ||
125 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
126 | cc = NULL; | ||
127 | } | ||
128 | |||
129 | if (th != NULL) | ||
130 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 73 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
131 | else | 74 | th = NULL; |
132 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not ready to send data\n")); | 75 | } |
133 | 76 | if (NULL != send_task) | |
134 | if (s_started == GNUNET_NO) | 77 | { |
135 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peers were not started \n")); | 78 | GNUNET_SCHEDULER_cancel (send_task); |
136 | else | 79 | send_task = NULL; |
137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peers were started \n")); | 80 | } |
138 | |||
139 | if (s_connected == GNUNET_NO) | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not connected\n")); | ||
141 | else | ||
142 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were connected\n")); | ||
143 | |||
144 | if (s_sending == GNUNET_NO) | ||
145 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not ready to send data\n")); | ||
146 | else | ||
147 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were ready to send data\n")); | ||
148 | |||
149 | th = NULL; | ||
150 | |||
151 | if (p1 != NULL) | ||
152 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
153 | else | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 1 was not started\n")); | ||
155 | if (p2 != NULL) | ||
156 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
157 | else | ||
158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 2 was not started\n")); | ||
159 | |||
160 | ok = GNUNET_SYSERR; | ||
161 | } | 81 | } |
162 | 82 | ||
163 | 83 | ||
@@ -168,15 +88,12 @@ notify_request_ready (void *cls, size_t size, void *buf) | |||
168 | struct GNUNET_MessageHeader *hdr; | 88 | struct GNUNET_MessageHeader *hdr; |
169 | 89 | ||
170 | th = NULL; | 90 | th = NULL; |
171 | 91 | if (NULL == buf) | |
172 | if (buf == NULL) | ||
173 | { | 92 | { |
174 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 93 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
175 | "Timeout occurred while waiting for transmit_ready\n"); | 94 | "Timeout occurred while waiting for transmit_ready\n"); |
176 | if (NULL != die_task) | 95 | GNUNET_SCHEDULER_shutdown (); |
177 | GNUNET_SCHEDULER_cancel (die_task); | 96 | ccc->global_ret = 42; |
178 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
179 | ok = 42; | ||
180 | return 0; | 97 | return 0; |
181 | } | 98 | } |
182 | 99 | ||
@@ -187,11 +104,11 @@ notify_request_ready (void *cls, size_t size, void *buf) | |||
187 | hdr->type = htons (TEST_REQUEST_MESSAGE_TYPE); | 104 | hdr->type = htons (TEST_REQUEST_MESSAGE_TYPE); |
188 | 105 | ||
189 | { | 106 | { |
190 | char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 107 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); |
191 | 108 | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
193 | "Sending request message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n", | 110 | "Sending request message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n", |
194 | p1->no, ps, | 111 | ccc->p[0]->no, ps, |
195 | ntohs (hdr->type), | 112 | ntohs (hdr->type), |
196 | ntohs (hdr->size), | 113 | ntohs (hdr->size), |
197 | p->no, | 114 | p->no, |
@@ -207,18 +124,25 @@ static void | |||
207 | sendtask_request_task (void *cls) | 124 | sendtask_request_task (void *cls) |
208 | { | 125 | { |
209 | send_task = NULL; | 126 | send_task = NULL; |
210 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p2->id)); | 127 | { |
211 | 128 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); | |
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 129 | |
213 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | 130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
214 | p1->no, GNUNET_i2s (&p1->id), p2->no, receiver_s); | 131 | "Sending message from peer %u (`%s') -> peer %u (`%s') !\n", |
215 | GNUNET_free (receiver_s); | 132 | ccc->p[0]->no, |
216 | 133 | GNUNET_i2s (&ccc->p[0]->id), | |
217 | s_sending = GNUNET_YES; | 134 | ccc->p[1]->no, |
218 | start_request = GNUNET_TIME_absolute_get(); | 135 | receiver_s); |
219 | th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, TEST_MESSAGE_SIZE, | 136 | GNUNET_free (receiver_s); |
220 | TIMEOUT_TRANSMIT, ¬ify_request_ready, | 137 | } |
221 | p2); | 138 | |
139 | start_request = GNUNET_TIME_absolute_get(); | ||
140 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[0]->th, | ||
141 | &ccc->p[1]->id, | ||
142 | TEST_MESSAGE_SIZE, | ||
143 | TIMEOUT_TRANSMIT, | ||
144 | ¬ify_request_ready, | ||
145 | ccc->p[1]); | ||
222 | } | 146 | } |
223 | 147 | ||
224 | 148 | ||
@@ -229,15 +153,12 @@ notify_response_ready (void *cls, size_t size, void *buf) | |||
229 | struct GNUNET_MessageHeader *hdr; | 153 | struct GNUNET_MessageHeader *hdr; |
230 | 154 | ||
231 | th = NULL; | 155 | th = NULL; |
232 | 156 | if (NULL == buf) | |
233 | if (buf == NULL) | ||
234 | { | 157 | { |
235 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
236 | "Timeout occurred while waiting for transmit_ready\n"); | 159 | "Timeout occurred while waiting for transmit_ready\n"); |
237 | if (NULL != die_task) | 160 | GNUNET_SCHEDULER_shutdown (); |
238 | GNUNET_SCHEDULER_cancel (die_task); | 161 | ccc->global_ret = 42; |
239 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
240 | ok = 42; | ||
241 | return 0; | 162 | return 0; |
242 | } | 163 | } |
243 | 164 | ||
@@ -248,10 +169,10 @@ notify_response_ready (void *cls, size_t size, void *buf) | |||
248 | hdr->type = htons (TEST_RESPONSE_MESSAGE_TYPE); | 169 | hdr->type = htons (TEST_RESPONSE_MESSAGE_TYPE); |
249 | 170 | ||
250 | { | 171 | { |
251 | char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 172 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); |
252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
253 | "Sending response message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n", | 174 | "Sending response message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n", |
254 | p1->no, | 175 | ccc->p[0]->no, |
255 | ps, | 176 | ps, |
256 | ntohs (hdr->type), | 177 | ntohs (hdr->type), |
257 | ntohs (hdr->size), | 178 | ntohs (hdr->size), |
@@ -269,265 +190,133 @@ sendtask_response_task (void *cls) | |||
269 | { | 190 | { |
270 | send_task = NULL; | 191 | send_task = NULL; |
271 | { | 192 | { |
272 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 193 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); |
273 | 194 | ||
274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
275 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | 196 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", |
276 | p2->no, | 197 | ccc->p[1]->no, |
277 | GNUNET_i2s (&p2->id), | 198 | GNUNET_i2s (&ccc->p[1]->id), |
278 | p1->no, | 199 | ccc->p[0]->no, |
279 | receiver_s); | 200 | receiver_s); |
280 | GNUNET_free (receiver_s); | 201 | GNUNET_free (receiver_s); |
281 | } | 202 | } |
282 | |||
283 | s_sending = GNUNET_YES; | ||
284 | start_response = GNUNET_TIME_absolute_get(); | 203 | start_response = GNUNET_TIME_absolute_get(); |
285 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, | 204 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, |
286 | &p1->id, | 205 | &ccc->p[0]->id, |
287 | TEST_MESSAGE_SIZE, | 206 | TEST_MESSAGE_SIZE, |
288 | TIMEOUT_TRANSMIT, | 207 | TIMEOUT_TRANSMIT, |
289 | ¬ify_response_ready, | 208 | ¬ify_response_ready, |
290 | p1); | 209 | ccc->p[0]); |
291 | } | 210 | } |
292 | 211 | ||
293 | 212 | ||
294 | |||
295 | static void | 213 | static void |
296 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 214 | notify_receive (void *cls, |
215 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | ||
216 | const struct GNUNET_PeerIdentity *sender, | ||
297 | const struct GNUNET_MessageHeader *message) | 217 | const struct GNUNET_MessageHeader *message) |
298 | { | 218 | { |
299 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
300 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | ||
301 | struct GNUNET_TIME_Relative duration; | 219 | struct GNUNET_TIME_Relative duration; |
302 | 220 | ||
303 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | 221 | { |
304 | t = p1; | 222 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
305 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
306 | t = p2; | ||
307 | GNUNET_assert (t != NULL); | ||
308 | |||
309 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
310 | 223 | ||
311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
312 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", | 225 | "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", |
313 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, | 226 | receiver->no, |
314 | GNUNET_i2s (&t->id)); | 227 | ps, |
315 | GNUNET_free (ps); | 228 | ntohs (message->type), |
229 | ntohs (message->size), | ||
230 | GNUNET_i2s (sender)); | ||
231 | GNUNET_free (ps); | ||
232 | } | ||
316 | 233 | ||
317 | switch (ntohs (message->type)) { | 234 | switch (ntohs (message->type)) { |
318 | case TEST_REQUEST_MESSAGE_TYPE: | 235 | case TEST_REQUEST_MESSAGE_TYPE: |
319 | duration = GNUNET_TIME_absolute_get_difference(start_request, | 236 | duration = GNUNET_TIME_absolute_get_difference(start_request, |
320 | GNUNET_TIME_absolute_get()); | 237 | GNUNET_TIME_absolute_get()); |
321 | if (duration.rel_value_us >= TEST_DELAY) | 238 | if (duration.rel_value_us >= TEST_DELAY) |
322 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 239 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
323 | "Request message was delayed for %s\n", | 240 | "Request message was delayed for %s\n", |
324 | GNUNET_STRINGS_relative_time_to_string (duration, | 241 | GNUNET_STRINGS_relative_time_to_string (duration, |
325 | GNUNET_YES)); | 242 | GNUNET_YES)); |
326 | else | 243 | else |
327 | { | 244 | { |
328 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 245 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
329 | "Request message was delayed for unexpected duration %s\n", | 246 | "Request message was delayed for unexpected duration %s\n", |
330 | GNUNET_STRINGS_relative_time_to_string (duration, | 247 | GNUNET_STRINGS_relative_time_to_string (duration, |
331 | GNUNET_YES)); | 248 | GNUNET_YES)); |
332 | ok = 1; | 249 | ccc->global_ret = GNUNET_SYSERR; |
333 | } | 250 | GNUNET_SCHEDULER_shutdown (); |
334 | 251 | } | |
335 | /* Send response */ | 252 | /* Send response */ |
336 | send_task = GNUNET_SCHEDULER_add_now (&sendtask_response_task, NULL); | 253 | send_task = GNUNET_SCHEDULER_add_now (&sendtask_response_task, |
337 | return; | 254 | NULL); |
338 | break; | ||
339 | case TEST_RESPONSE_MESSAGE_TYPE: | ||
340 | duration = GNUNET_TIME_absolute_get_difference(start_response, | ||
341 | GNUNET_TIME_absolute_get()); | ||
342 | if (duration.rel_value_us >= TEST_DELAY) | ||
343 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
344 | "Response message was delayed for %s\n", | ||
345 | GNUNET_STRINGS_relative_time_to_string (duration, | ||
346 | GNUNET_YES)); | ||
347 | else | ||
348 | { | ||
349 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
350 | "Response message was delayed for unexpected duration %s\n", | ||
351 | GNUNET_STRINGS_relative_time_to_string (duration, | ||
352 | GNUNET_YES)); | ||
353 | ok = 1; | ||
354 | } | ||
355 | /* Done */ | ||
356 | ok = 0; | ||
357 | end(); | ||
358 | break; | ||
359 | default: | ||
360 | break; | ||
361 | } | ||
362 | } | ||
363 | |||
364 | |||
365 | |||
366 | static void | ||
367 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
368 | { | ||
369 | static int c; | ||
370 | |||
371 | c++; | ||
372 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
373 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | ||
374 | |||
375 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | ||
376 | t = p1; | ||
377 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
378 | t = p2; | ||
379 | GNUNET_assert (t != NULL); | ||
380 | |||
381 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
382 | |||
383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
384 | "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, | ||
385 | t->no, GNUNET_i2s (peer)); | ||
386 | GNUNET_free (ps); | ||
387 | } | ||
388 | |||
389 | |||
390 | static void | ||
391 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
392 | { | ||
393 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
394 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
395 | |||
396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
397 | "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, | ||
398 | GNUNET_i2s (peer)); | ||
399 | |||
400 | GNUNET_free (ps); | ||
401 | |||
402 | if (th != NULL) | ||
403 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
404 | th = NULL; | ||
405 | } | ||
406 | |||
407 | |||
408 | static void | ||
409 | testing_connect_cb (void *cls) | ||
410 | { | ||
411 | cc = NULL; | ||
412 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
413 | |||
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", | ||
415 | p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); | ||
416 | GNUNET_free (p1_c); | ||
417 | |||
418 | s_connected = GNUNET_YES; | ||
419 | send_task = GNUNET_SCHEDULER_add_now (&sendtask_request_task, NULL); | ||
420 | } | ||
421 | |||
422 | |||
423 | static void | ||
424 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | ||
425 | { | ||
426 | static int started; | ||
427 | started++; | ||
428 | |||
429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | ||
430 | GNUNET_i2s (&p->id)); | ||
431 | |||
432 | if (started != 2) | ||
433 | return; | 255 | return; |
434 | else | 256 | case TEST_RESPONSE_MESSAGE_TYPE: |
435 | s_started = GNUNET_YES; | 257 | duration = GNUNET_TIME_absolute_get_difference(start_response, |
436 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 258 | GNUNET_TIME_absolute_get()); |
437 | 259 | if (duration.rel_value_us >= TEST_DELAY) | |
438 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 260 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
439 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | 261 | "Response message was delayed for %s\n", |
440 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | 262 | GNUNET_STRINGS_relative_time_to_string (duration, |
441 | GNUNET_free (sender_c); | 263 | GNUNET_YES)); |
442 | 264 | else | |
443 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, | 265 | { |
444 | NULL); | 266 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
445 | 267 | "Response message was delayed for unexpected duration %s\n", | |
268 | GNUNET_STRINGS_relative_time_to_string (duration, | ||
269 | GNUNET_YES)); | ||
270 | ccc->global_ret = GNUNET_SYSERR; | ||
271 | GNUNET_SCHEDULER_shutdown (); | ||
272 | break; | ||
273 | } | ||
274 | ccc->global_ret = GNUNET_OK; | ||
275 | GNUNET_SCHEDULER_shutdown (); | ||
276 | break; | ||
277 | default: | ||
278 | break; | ||
279 | } | ||
446 | } | 280 | } |
447 | 281 | ||
448 | 282 | ||
449 | static void | 283 | static void |
450 | run (void *cls, char *const *args, const char *cfgfile, | 284 | notify_disconnect (void *cls, |
451 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 285 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
286 | const struct GNUNET_PeerIdentity *other) | ||
452 | { | 287 | { |
453 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 288 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, |
454 | 289 | me, | |
455 | s_started = GNUNET_NO; | 290 | other); |
456 | s_connected = GNUNET_NO; | 291 | if (NULL != th) |
457 | s_sending = GNUNET_NO; | ||
458 | |||
459 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, | ||
460 | ¬ify_receive, ¬ify_connect, | ||
461 | ¬ify_disconnect, &start_cb, | ||
462 | NULL); | ||
463 | |||
464 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, | ||
465 | ¬ify_receive, ¬ify_connect, | ||
466 | ¬ify_disconnect, &start_cb, | ||
467 | NULL); | ||
468 | |||
469 | if ((p1 == NULL) || (p2 == NULL)) | ||
470 | { | 292 | { |
471 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | 293 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
472 | if (die_task != NULL) | 294 | th = NULL; |
473 | GNUNET_SCHEDULER_cancel (die_task); | ||
474 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
475 | return; | ||
476 | } | 295 | } |
477 | } | 296 | } |
478 | 297 | ||
479 | 298 | ||
480 | static int | ||
481 | check () | ||
482 | { | ||
483 | static char *const argv[] = { "test-transport-api-manipulation", | ||
484 | "-c", | ||
485 | "test_transport_api_data.conf", | ||
486 | NULL | ||
487 | }; | ||
488 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
489 | GNUNET_GETOPT_OPTION_END | ||
490 | }; | ||
491 | |||
492 | send_task = NULL; | ||
493 | |||
494 | ok = 1; | ||
495 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, | ||
496 | "nohelp", options, &run, &ok); | ||
497 | |||
498 | return ok; | ||
499 | } | ||
500 | |||
501 | int | 299 | int |
502 | main (int argc, char *argv[]) | 300 | main (int argc, char *argv[]) |
503 | { | 301 | { |
504 | int ret; | 302 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
505 | 303 | .connect_continuation = &sendtask_request_task, | |
506 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); | 304 | .config_file = "test_transport_api_data.conf", |
507 | test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__); | 305 | .rec = ¬ify_receive, |
508 | test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], | 306 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
509 | test_source); | 307 | .nd = ¬ify_disconnect, |
510 | 308 | .shutdown_task = &custom_shutdown, | |
511 | GNUNET_log_setup (test_name, | 309 | .timeout = TIMEOUT |
512 | "WARNING", | 310 | }; |
513 | NULL); | ||
514 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
515 | |||
516 | cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 1); | ||
517 | cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 2); | ||
518 | |||
519 | ret = check (); | ||
520 | |||
521 | GNUNET_free (cfg_file_p1); | ||
522 | GNUNET_free (cfg_file_p2); | ||
523 | |||
524 | GNUNET_free (test_source); | ||
525 | GNUNET_free (test_plugin); | ||
526 | GNUNET_free (test_name); | ||
527 | |||
528 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
529 | 311 | ||
530 | return ret; | 312 | ccc = &my_ccc; |
313 | if (GNUNET_OK != | ||
314 | GNUNET_TRANSPORT_TESTING_main (2, | ||
315 | &GNUNET_TRANSPORT_TESTING_connect_check, | ||
316 | ccc)) | ||
317 | return 1; | ||
318 | return 0; | ||
531 | } | 319 | } |
532 | 320 | ||
533 | /* end of test_transport_api.c */ | 321 | |
322 | /* end of test_transport_api_manipulation_cfg.c */ | ||