diff options
Diffstat (limited to 'src/transport/test_transport_address_switch.c')
-rw-r--r-- | src/transport/test_transport_address_switch.c | 176 |
1 files changed, 86 insertions, 90 deletions
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c index fa977a364..98f1170ff 100644 --- a/src/transport/test_transport_address_switch.c +++ b/src/transport/test_transport_address_switch.c | |||
@@ -93,9 +93,7 @@ stat_start_attempt_cb (void *cls, | |||
93 | struct PeerStats *stat = cls; | 93 | struct PeerStats *stat = cls; |
94 | 94 | ||
95 | stat->switch_attempts++; | 95 | stat->switch_attempts++; |
96 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 96 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch attempted (%p)", stat); |
97 | "Switch attempted (%p)", | ||
98 | stat); | ||
99 | bytes_recv_after_switch = 0; | 97 | bytes_recv_after_switch = 0; |
100 | bytes_sent_after_switch = 0; | 98 | bytes_sent_after_switch = 0; |
101 | 99 | ||
@@ -113,9 +111,7 @@ stat_success_attempt_cb (void *cls, | |||
113 | struct PeerStats *stat = cls; | 111 | struct PeerStats *stat = cls; |
114 | 112 | ||
115 | stat->switch_success++; | 113 | stat->switch_success++; |
116 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 114 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch succeeded (%p)", stat); |
117 | "Switch succeeded (%p)", | ||
118 | stat); | ||
119 | return GNUNET_OK; | 115 | return GNUNET_OK; |
120 | } | 116 | } |
121 | 117 | ||
@@ -133,9 +129,7 @@ stat_fail_attempt_cb (void *cls, | |||
133 | return GNUNET_OK; | 129 | return GNUNET_OK; |
134 | 130 | ||
135 | stat->switch_fail++; | 131 | stat->switch_fail++; |
136 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 132 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Switch failed (%p)", stat); |
137 | "Switch failed (%p)", | ||
138 | stat); | ||
139 | return GNUNET_OK; | 133 | return GNUNET_OK; |
140 | } | 134 | } |
141 | 135 | ||
@@ -157,7 +151,8 @@ stat_addresses_available (void *cls, | |||
157 | /** | 151 | /** |
158 | * List of statistics entries we care about. | 152 | * List of statistics entries we care about. |
159 | */ | 153 | */ |
160 | static struct WatchEntry { | 154 | static struct WatchEntry |
155 | { | ||
161 | 156 | ||
162 | /** | 157 | /** |
163 | * Name of the statistic we watch. | 158 | * Name of the statistic we watch. |
@@ -168,15 +163,17 @@ static struct WatchEntry { | |||
168 | * Handler to register; | 163 | * Handler to register; |
169 | */ | 164 | */ |
170 | GNUNET_STATISTICS_Iterator stat_handler; | 165 | GNUNET_STATISTICS_Iterator stat_handler; |
171 | } watches[] = { | 166 | } watches[] = |
172 | { "# Attempts to switch addresses", &stat_start_attempt_cb }, | 167 | {{"# Attempts to switch addresses", &stat_start_attempt_cb}, |
173 | { "# Successful attempts to switch addresses", &stat_success_attempt_cb }, | 168 | {"# Successful attempts to switch addresses", &stat_success_attempt_cb}, |
174 | { "# Failed attempts to switch addresses (failed to send CONNECT CONT)", &stat_fail_attempt_cb }, | 169 | {"# Failed attempts to switch addresses (failed to send CONNECT CONT)", |
175 | { "# Failed attempts to switch addresses (failed to send CONNECT)", &stat_fail_attempt_cb }, | 170 | &stat_fail_attempt_cb}, |
176 | { "# Failed attempts to switch addresses (no response)", &stat_fail_attempt_cb }, | 171 | {"# Failed attempts to switch addresses (failed to send CONNECT)", |
177 | { "# transport addresses", &stat_addresses_available }, | 172 | &stat_fail_attempt_cb}, |
178 | { NULL, NULL } | 173 | {"# Failed attempts to switch addresses (no response)", |
179 | }; | 174 | &stat_fail_attempt_cb}, |
175 | {"# transport addresses", &stat_addresses_available}, | ||
176 | {NULL, NULL}}; | ||
180 | 177 | ||
181 | 178 | ||
182 | static void | 179 | static void |
@@ -203,19 +200,18 @@ custom_shutdown (void *cls) | |||
203 | } | 200 | } |
204 | 201 | ||
205 | /* stop statistics */ | 202 | /* stop statistics */ |
206 | for (unsigned int i=0;i<2;i++) | 203 | for (unsigned int i = 0; i < 2; i++) |
207 | { | 204 | { |
208 | if (NULL != stats[i].stat) | 205 | if (NULL != stats[i].stat) |
209 | { | 206 | { |
210 | for (unsigned int j=0;NULL != watches[j].stat_name; j++) | 207 | for (unsigned int j = 0; NULL != watches[j].stat_name; j++) |
211 | GNUNET_STATISTICS_watch_cancel (stats[i].stat, | 208 | GNUNET_assert (GNUNET_OK == |
212 | "transport", | 209 | GNUNET_STATISTICS_watch_cancel (stats[i].stat, |
213 | watches[j].stat_name, | 210 | "transport", |
214 | watches[j].stat_handler, | 211 | watches[j].stat_name, |
215 | &stats[i]); | 212 | watches[j].stat_handler, |
216 | 213 | &stats[i])); | |
217 | GNUNET_STATISTICS_destroy (stats[i].stat, | 214 | GNUNET_STATISTICS_destroy (stats[i].stat, GNUNET_NO); |
218 | GNUNET_NO); | ||
219 | stats[i].stat = NULL; | 215 | stats[i].stat = NULL; |
220 | } | 216 | } |
221 | } | 217 | } |
@@ -224,15 +220,16 @@ custom_shutdown (void *cls) | |||
224 | FPRINTF (stderr, "\n"); | 220 | FPRINTF (stderr, "\n"); |
225 | if (stats[0].switch_attempts > 0) | 221 | if (stats[0].switch_attempts > 0) |
226 | { | 222 | { |
227 | FPRINTF (stderr, | 223 | FPRINTF ( |
228 | "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", | 224 | stderr, |
229 | stats[0].switch_attempts, | 225 | "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", |
230 | stats[0].switch_success, | 226 | stats[0].switch_attempts, |
231 | stats[0].switch_fail); | 227 | stats[0].switch_success, |
228 | stats[0].switch_fail); | ||
232 | if (stats[0].switch_success != stats[0].switch_attempts) | 229 | if (stats[0].switch_success != stats[0].switch_attempts) |
233 | { | 230 | { |
234 | GNUNET_break (0); | 231 | GNUNET_break (0); |
235 | result ++; | 232 | result++; |
236 | } | 233 | } |
237 | } | 234 | } |
238 | else if (stats[0].addresses_avail > 1) | 235 | else if (stats[0].addresses_avail > 1) |
@@ -243,11 +240,12 @@ custom_shutdown (void *cls) | |||
243 | } | 240 | } |
244 | if (stats[1].switch_attempts > 0) | 241 | if (stats[1].switch_attempts > 0) |
245 | { | 242 | { |
246 | FPRINTF (stderr, | 243 | FPRINTF ( |
247 | "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", | 244 | stderr, |
248 | stats[1].switch_attempts, | 245 | "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", |
249 | stats[1].switch_success, | 246 | stats[1].switch_attempts, |
250 | stats[1].switch_fail); | 247 | stats[1].switch_success, |
248 | stats[1].switch_fail); | ||
251 | if (stats[1].switch_success != stats[1].switch_attempts) | 249 | if (stats[1].switch_success != stats[1].switch_attempts) |
252 | { | 250 | { |
253 | GNUNET_break (0); | 251 | GNUNET_break (0); |
@@ -261,19 +259,17 @@ custom_shutdown (void *cls) | |||
261 | stats[1].addresses_avail); | 259 | stats[1].addresses_avail); |
262 | } | 260 | } |
263 | 261 | ||
264 | if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && | 262 | if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && |
265 | (bytes_sent_after_switch == 0) ) | 263 | (bytes_sent_after_switch == 0)) |
266 | { | 264 | { |
267 | FPRINTF (stderr, | 265 | FPRINTF (stderr, "No data sent after switching!\n"); |
268 | "No data sent after switching!\n"); | ||
269 | GNUNET_break (0); | 266 | GNUNET_break (0); |
270 | result++; | 267 | result++; |
271 | } | 268 | } |
272 | if ( ((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && | 269 | if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && |
273 | (bytes_recv_after_switch == 0) ) | 270 | (bytes_recv_after_switch == 0)) |
274 | { | 271 | { |
275 | FPRINTF (stderr, | 272 | FPRINTF (stderr, "No data received after switching!\n"); |
276 | "No data received after switching!\n"); | ||
277 | GNUNET_break (0); | 273 | GNUNET_break (0); |
278 | result++; | 274 | result++; |
279 | } | 275 | } |
@@ -306,13 +302,14 @@ notify_receive (void *cls, | |||
306 | GNUNET_i2s (sender)); | 302 | GNUNET_i2s (sender)); |
307 | GNUNET_free (ps); | 303 | GNUNET_free (ps); |
308 | } | 304 | } |
309 | if ( ((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && | 305 | if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && |
310 | (stats[0].switch_attempts == stats[0].switch_fail + stats[0].switch_success) && | 306 | (stats[0].switch_attempts == |
311 | (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success) ) | 307 | stats[0].switch_fail + stats[0].switch_success) && |
308 | (stats[1].switch_attempts == | ||
309 | stats[1].switch_fail + stats[1].switch_success)) | ||
312 | { | 310 | { |
313 | bytes_recv_after_switch += ntohs(hdr->header.size); | 311 | bytes_recv_after_switch += ntohs (hdr->header.size); |
314 | if ( (bytes_sent_after_switch > 0) && | 312 | if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0)) |
315 | (bytes_recv_after_switch > 0) ) | ||
316 | { | 313 | { |
317 | /* A peer switched addresses and sent and received data after the | 314 | /* A peer switched addresses and sent and received data after the |
318 | * switch operations */ | 315 | * switch operations */ |
@@ -327,21 +324,22 @@ notify_send (void *cls) | |||
327 | { | 324 | { |
328 | static uint32_t cnt; | 325 | static uint32_t cnt; |
329 | 326 | ||
330 | GNUNET_assert (GNUNET_OK == | 327 | GNUNET_assert ( |
331 | GNUNET_TRANSPORT_TESTING_send (ccc->p[1], | 328 | GNUNET_OK == |
332 | ccc->p[0], | 329 | GNUNET_TRANSPORT_TESTING_send (ccc->p[1], |
333 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | 330 | ccc->p[0], |
334 | GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, | 331 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, |
335 | ++cnt, | 332 | GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, |
336 | ¬ify_send, | 333 | ++cnt, |
337 | NULL)); | 334 | ¬ify_send, |
338 | if ( ( (stats[0].switch_attempts >= 1) || | 335 | NULL)); |
339 | (stats[1].switch_attempts >= 1) ) && | 336 | if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && |
340 | (stats[0].switch_attempts == stats[0].switch_fail + stats[0].switch_success) && | 337 | (stats[0].switch_attempts == |
341 | (stats[1].switch_attempts == stats[1].switch_fail + stats[1].switch_success) ) | 338 | stats[0].switch_fail + stats[0].switch_success) && |
339 | (stats[1].switch_attempts == | ||
340 | stats[1].switch_fail + stats[1].switch_success)) | ||
342 | { | 341 | { |
343 | bytes_sent_after_switch | 342 | bytes_sent_after_switch += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE; |
344 | += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE; | ||
345 | } | 343 | } |
346 | } | 344 | } |
347 | 345 | ||
@@ -370,10 +368,9 @@ progress_indicator (void *cls) | |||
370 | static void | 368 | static void |
371 | connected_cb (void *cls) | 369 | connected_cb (void *cls) |
372 | { | 370 | { |
373 | for (unsigned int i=0;i<2;i++) | 371 | for (unsigned int i = 0; i < 2; i++) |
374 | { | 372 | { |
375 | stats[i].stat = GNUNET_STATISTICS_create ("transport", | 373 | stats[i].stat = GNUNET_STATISTICS_create ("transport", ccc->p[i]->cfg); |
376 | ccc->p[i]->cfg); | ||
377 | if (NULL == stats[i].stat) | 374 | if (NULL == stats[i].stat) |
378 | { | 375 | { |
379 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 376 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -382,7 +379,7 @@ connected_cb (void *cls) | |||
382 | GNUNET_SCHEDULER_shutdown (); | 379 | GNUNET_SCHEDULER_shutdown (); |
383 | return; | 380 | return; |
384 | } | 381 | } |
385 | for (unsigned int j=0;NULL != watches[j].stat_name; j++) | 382 | for (unsigned int j = 0; NULL != watches[j].stat_name; j++) |
386 | { | 383 | { |
387 | GNUNET_STATISTICS_watch (stats[i].stat, | 384 | GNUNET_STATISTICS_watch (stats[i].stat, |
388 | "transport", | 385 | "transport", |
@@ -397,29 +394,28 @@ connected_cb (void *cls) | |||
397 | &progress_indicator, | 394 | &progress_indicator, |
398 | NULL); | 395 | NULL); |
399 | /* Peers are connected, start transmit test messages */ | 396 | /* Peers are connected, start transmit test messages */ |
400 | GNUNET_assert (GNUNET_OK == | 397 | GNUNET_assert ( |
401 | GNUNET_TRANSPORT_TESTING_send (ccc->p[1], | 398 | GNUNET_OK == |
402 | ccc->p[0], | 399 | GNUNET_TRANSPORT_TESTING_send (ccc->p[1], |
403 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | 400 | ccc->p[0], |
404 | GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, | 401 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, |
405 | 0, | 402 | GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, |
406 | ¬ify_send, | 403 | 0, |
407 | NULL)); | 404 | ¬ify_send, |
405 | NULL)); | ||
408 | } | 406 | } |
409 | 407 | ||
410 | 408 | ||
411 | int | 409 | int |
412 | main (int argc, | 410 | main (int argc, char *argv[]) |
413 | char *argv[]) | ||
414 | { | 411 | { |
415 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 412 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = |
416 | .connect_continuation = &connected_cb, | 413 | {.connect_continuation = &connected_cb, |
417 | .config_file = "test_transport_api_data.conf", | 414 | .config_file = "test_transport_api_data.conf", |
418 | .rec = ¬ify_receive, | 415 | .rec = ¬ify_receive, |
419 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | 416 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
420 | .shutdown_task = &custom_shutdown, | 417 | .shutdown_task = &custom_shutdown, |
421 | .timeout = TIMEOUT | 418 | .timeout = TIMEOUT}; |
422 | }; | ||
423 | ccc = &my_ccc; | 419 | ccc = &my_ccc; |
424 | int ret; | 420 | int ret; |
425 | 421 | ||