diff options
Diffstat (limited to 'src/cadet/test_cadet_flow.c')
-rw-r--r-- | src/cadet/test_cadet_flow.c | 741 |
1 files changed, 372 insertions, 369 deletions
diff --git a/src/cadet/test_cadet_flow.c b/src/cadet/test_cadet_flow.c index 5278dc00f..94e1f1c85 100644 --- a/src/cadet/test_cadet_flow.c +++ b/src/cadet/test_cadet_flow.c | |||
@@ -34,7 +34,8 @@ | |||
34 | /** | 34 | /** |
35 | * Ugly workaround to unify data handlers on incoming and outgoing channels. | 35 | * Ugly workaround to unify data handlers on incoming and outgoing channels. |
36 | */ | 36 | */ |
37 | struct CadetTestChannelWrapper { | 37 | struct CadetTestChannelWrapper |
38 | { | ||
38 | /** | 39 | /** |
39 | * Channel pointer. | 40 | * Channel pointer. |
40 | */ | 41 | */ |
@@ -49,17 +50,18 @@ struct CadetTestChannelWrapper { | |||
49 | /** | 50 | /** |
50 | * How long until we give up on connecting the peers? | 51 | * How long until we give up on connecting the peers? |
51 | */ | 52 | */ |
52 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) | 53 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
53 | 54 | ||
54 | /** | 55 | /** |
55 | * Time to wait by default for stuff that should be rather fast. | 56 | * Time to wait by default for stuff that should be rather fast. |
56 | */ | 57 | */ |
57 | #define SHORT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) | 58 | #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) |
58 | 59 | ||
59 | /** | 60 | /** |
60 | * How fast do we send messages? | 61 | * How fast do we send messages? |
61 | */ | 62 | */ |
62 | #define SEND_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 10) | 63 | #define SEND_INTERVAL GNUNET_TIME_relative_multiply ( \ |
64 | GNUNET_TIME_UNIT_MILLISECONDS, 10) | ||
63 | 65 | ||
64 | 66 | ||
65 | /** | 67 | /** |
@@ -208,29 +210,29 @@ static unsigned int msg_dropped; | |||
208 | * Show the results of the test (banwidth acheived) and log them to GAUGER | 210 | * Show the results of the test (banwidth acheived) and log them to GAUGER |
209 | */ | 211 | */ |
210 | static void | 212 | static void |
211 | show_end_data(void) | 213 | show_end_data (void) |
212 | { | 214 | { |
213 | static struct GNUNET_TIME_Absolute end_time; | 215 | static struct GNUNET_TIME_Absolute end_time; |
214 | static struct GNUNET_TIME_Relative total_time; | 216 | static struct GNUNET_TIME_Relative total_time; |
215 | 217 | ||
216 | end_time = GNUNET_TIME_absolute_get(); | 218 | end_time = GNUNET_TIME_absolute_get (); |
217 | total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time); | 219 | total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time); |
218 | fprintf(stderr, | 220 | fprintf (stderr, |
219 | "\nResults of test \"%s\"\n", | 221 | "\nResults of test \"%s\"\n", |
220 | test_name); | 222 | test_name); |
221 | fprintf(stderr, | 223 | fprintf (stderr, |
222 | "Test time %s\n", | 224 | "Test time %s\n", |
223 | GNUNET_STRINGS_relative_time_to_string(total_time, GNUNET_YES)); | 225 | GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); |
224 | fprintf(stderr, | 226 | fprintf (stderr, |
225 | "Test bandwidth: %f kb/s\n", | 227 | "Test bandwidth: %f kb/s\n", |
226 | 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms | 228 | 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms |
227 | fprintf(stderr, | 229 | fprintf (stderr, |
228 | "Test throughput: %f packets/s\n\n", | 230 | "Test throughput: %f packets/s\n\n", |
229 | total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms | 231 | total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms |
230 | GAUGER("CADET", | 232 | GAUGER ("CADET", |
231 | test_name, | 233 | test_name, |
232 | total_packets * 1000.0 / (total_time.rel_value_us / 1000), | 234 | total_packets * 1000.0 / (total_time.rel_value_us / 1000), |
233 | "packets/s"); | 235 | "packets/s"); |
234 | } | 236 | } |
235 | 237 | ||
236 | 238 | ||
@@ -241,33 +243,33 @@ show_end_data(void) | |||
241 | * @param tc Task Context. | 243 | * @param tc Task Context. |
242 | */ | 244 | */ |
243 | static void | 245 | static void |
244 | shutdown_task(void *cls) | 246 | shutdown_task (void *cls) |
245 | { | 247 | { |
246 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
247 | "Ending test.\n"); | 249 | "Ending test.\n"); |
248 | if (NULL != send_next_msg_task) | 250 | if (NULL != send_next_msg_task) |
249 | { | 251 | { |
250 | GNUNET_SCHEDULER_cancel(send_next_msg_task); | 252 | GNUNET_SCHEDULER_cancel (send_next_msg_task); |
251 | send_next_msg_task = NULL; | 253 | send_next_msg_task = NULL; |
252 | } | 254 | } |
253 | if (NULL != test_task) | 255 | if (NULL != test_task) |
254 | { | 256 | { |
255 | GNUNET_SCHEDULER_cancel(test_task); | 257 | GNUNET_SCHEDULER_cancel (test_task); |
256 | test_task = NULL; | 258 | test_task = NULL; |
257 | } | 259 | } |
258 | for (unsigned int i = 0; i < 2; i++) | 260 | for (unsigned int i = 0; i < 2; i++) |
259 | GNUNET_TESTBED_operation_done(t_op[i]); | 261 | GNUNET_TESTBED_operation_done (t_op[i]); |
260 | if (NULL != outgoing_ch) | 262 | if (NULL != outgoing_ch) |
261 | { | 263 | { |
262 | GNUNET_CADET_channel_destroy(outgoing_ch); | 264 | GNUNET_CADET_channel_destroy (outgoing_ch); |
263 | outgoing_ch = NULL; | 265 | outgoing_ch = NULL; |
264 | } | 266 | } |
265 | if (NULL != incoming_ch) | 267 | if (NULL != incoming_ch) |
266 | { | 268 | { |
267 | GNUNET_CADET_channel_destroy(incoming_ch); | 269 | GNUNET_CADET_channel_destroy (incoming_ch); |
268 | incoming_ch = NULL; | 270 | incoming_ch = NULL; |
269 | } | 271 | } |
270 | GNUNET_CADET_TEST_cleanup(test_ctx); | 272 | GNUNET_CADET_TEST_cleanup (test_ctx); |
271 | } | 273 | } |
272 | 274 | ||
273 | 275 | ||
@@ -281,25 +283,25 @@ shutdown_task(void *cls) | |||
281 | * operation has executed successfully. | 283 | * operation has executed successfully. |
282 | */ | 284 | */ |
283 | static void | 285 | static void |
284 | stats_cont(void *cls, | 286 | stats_cont (void *cls, |
285 | struct GNUNET_TESTBED_Operation *op, | 287 | struct GNUNET_TESTBED_Operation *op, |
286 | const char *emsg) | 288 | const char *emsg) |
287 | { | 289 | { |
288 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 290 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
289 | "KA sent: %u, KA received: %u\n", | 291 | "KA sent: %u, KA received: %u\n", |
290 | ka_sent, | 292 | ka_sent, |
291 | ka_received); | 293 | ka_received); |
292 | if ((KEEPALIVE == test) && ((ka_sent < 2) || (ka_sent > ka_received + 1))) | 294 | if ((KEEPALIVE == test) && ((ka_sent < 2) || (ka_sent > ka_received + 1))) |
293 | { | 295 | { |
294 | GNUNET_break(0); | 296 | GNUNET_break (0); |
295 | ok--; | 297 | ok--; |
296 | } | 298 | } |
297 | GNUNET_TESTBED_operation_done(stats_op); | 299 | GNUNET_TESTBED_operation_done (stats_op); |
298 | 300 | ||
299 | if (NULL != disconnect_task) | 301 | if (NULL != disconnect_task) |
300 | GNUNET_SCHEDULER_cancel(disconnect_task); | 302 | GNUNET_SCHEDULER_cancel (disconnect_task); |
301 | disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, | 303 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, |
302 | cls); | 304 | cls); |
303 | } | 305 | } |
304 | 306 | ||
305 | 307 | ||
@@ -315,12 +317,12 @@ stats_cont(void *cls, | |||
315 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 317 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
316 | */ | 318 | */ |
317 | static int | 319 | static int |
318 | stats_iterator(void *cls, | 320 | stats_iterator (void *cls, |
319 | const struct GNUNET_TESTBED_Peer *peer, | 321 | const struct GNUNET_TESTBED_Peer *peer, |
320 | const char *subsystem, | 322 | const char *subsystem, |
321 | const char *name, | 323 | const char *name, |
322 | uint64_t value, | 324 | uint64_t value, |
323 | int is_persistent) | 325 | int is_persistent) |
324 | { | 326 | { |
325 | static const char *s_sent = "# keepalives sent"; | 327 | static const char *s_sent = "# keepalives sent"; |
326 | static const char *s_recv = "# keepalives received"; | 328 | static const char *s_recv = "# keepalives received"; |
@@ -328,16 +330,17 @@ stats_iterator(void *cls, | |||
328 | static const char *cdrops = "# messages dropped due to slow client"; | 330 | static const char *cdrops = "# messages dropped due to slow client"; |
329 | uint32_t i; | 331 | uint32_t i; |
330 | 332 | ||
331 | i = GNUNET_TESTBED_get_index(peer); | 333 | i = GNUNET_TESTBED_get_index (peer); |
332 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "STATS PEER %u - %s [%s]: %llu\n", i, | 334 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "STATS PEER %u - %s [%s]: %llu\n", i, |
333 | subsystem, name, (unsigned long long)value); | 335 | subsystem, name, (unsigned long long) value); |
334 | if (0 == strncmp(s_sent, name, strlen(s_sent)) && 0 == i) | 336 | if ((0 == strncmp (s_sent, name, strlen (s_sent)))&&(0 == i)) |
335 | ka_sent = value; | 337 | ka_sent = value; |
336 | if (0 == strncmp(s_recv, name, strlen(s_recv)) && peers_requested - 1 == i) | 338 | if ((0 == strncmp (s_recv, name, strlen (s_recv)))&&(peers_requested - 1 == |
339 | i) ) | ||
337 | ka_received = value; | 340 | ka_received = value; |
338 | if (0 == strncmp(rdrops, name, strlen(rdrops))) | 341 | if (0 == strncmp (rdrops, name, strlen (rdrops))) |
339 | msg_dropped += value; | 342 | msg_dropped += value; |
340 | if (0 == strncmp(cdrops, name, strlen(cdrops))) | 343 | if (0 == strncmp (cdrops, name, strlen (cdrops))) |
341 | msg_dropped += value; | 344 | msg_dropped += value; |
342 | 345 | ||
343 | return GNUNET_OK; | 346 | return GNUNET_OK; |
@@ -350,26 +353,26 @@ stats_iterator(void *cls, | |||
350 | * @param cls Closure (line from which the task was scheduled). | 353 | * @param cls Closure (line from which the task was scheduled). |
351 | */ | 354 | */ |
352 | static void | 355 | static void |
353 | gather_stats_and_exit(void *cls) | 356 | gather_stats_and_exit (void *cls) |
354 | { | 357 | { |
355 | long l = (long)cls; | 358 | long l = (long) cls; |
356 | 359 | ||
357 | disconnect_task = NULL; | 360 | disconnect_task = NULL; |
358 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 361 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
359 | "gathering statistics from line %ld\n", | 362 | "gathering statistics from line %ld\n", |
360 | l); | 363 | l); |
361 | if (NULL != outgoing_ch) | 364 | if (NULL != outgoing_ch) |
362 | { | 365 | { |
363 | GNUNET_CADET_channel_destroy(outgoing_ch); | 366 | GNUNET_CADET_channel_destroy (outgoing_ch); |
364 | outgoing_ch = NULL; | 367 | outgoing_ch = NULL; |
365 | } | 368 | } |
366 | stats_op = GNUNET_TESTBED_get_statistics(peers_running, | 369 | stats_op = GNUNET_TESTBED_get_statistics (peers_running, |
367 | testbed_peers, | 370 | testbed_peers, |
368 | "cadet", | 371 | "cadet", |
369 | NULL, | 372 | NULL, |
370 | &stats_iterator, | 373 | &stats_iterator, |
371 | stats_cont, | 374 | stats_cont, |
372 | cls); | 375 | cls); |
373 | } | 376 | } |
374 | 377 | ||
375 | 378 | ||
@@ -379,18 +382,18 @@ gather_stats_and_exit(void *cls) | |||
379 | * @param line Line in the code the abort is requested from (__LINE__). | 382 | * @param line Line in the code the abort is requested from (__LINE__). |
380 | */ | 383 | */ |
381 | static void | 384 | static void |
382 | abort_test(long line) | 385 | abort_test (long line) |
383 | { | 386 | { |
384 | if (NULL != disconnect_task) | 387 | if (NULL != disconnect_task) |
385 | { | 388 | { |
386 | GNUNET_SCHEDULER_cancel(disconnect_task); | 389 | GNUNET_SCHEDULER_cancel (disconnect_task); |
387 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 390 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
388 | "Aborting test from %ld\n", | 391 | "Aborting test from %ld\n", |
389 | line); | 392 | line); |
390 | disconnect_task = | 393 | disconnect_task = |
391 | GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers, | 394 | GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, |
392 | (void *)line); | 395 | (void *) line); |
393 | } | 396 | } |
394 | } | 397 | } |
395 | 398 | ||
396 | 399 | ||
@@ -402,7 +405,7 @@ abort_test(long line) | |||
402 | * @param channel Channel to send the message on. | 405 | * @param channel Channel to send the message on. |
403 | */ | 406 | */ |
404 | static void | 407 | static void |
405 | send_test_message(struct GNUNET_CADET_Channel *channel) | 408 | send_test_message (struct GNUNET_CADET_Channel *channel) |
406 | { | 409 | { |
407 | struct GNUNET_MQ_Envelope *env; | 410 | struct GNUNET_MQ_Envelope *env; |
408 | struct GNUNET_MessageHeader *msg; | 411 | struct GNUNET_MessageHeader *msg; |
@@ -410,56 +413,56 @@ send_test_message(struct GNUNET_CADET_Channel *channel) | |||
410 | int payload; | 413 | int payload; |
411 | int size; | 414 | int size; |
412 | 415 | ||
413 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
414 | "Sending test message on channel %p\n", | 417 | "Sending test message on channel %p\n", |
415 | channel); | 418 | channel); |
416 | size = size_payload; | 419 | size = size_payload; |
417 | if (GNUNET_NO == initialized) | 420 | if (GNUNET_NO == initialized) |
418 | { | 421 | { |
419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n"); | 422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n"); |
420 | size += 1000; | 423 | size += 1000; |
421 | payload = data_sent; | 424 | payload = data_sent; |
422 | if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer | 425 | if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer |
423 | data_sent++; | 426 | data_sent++; |
424 | } | 427 | } |
425 | else if (SPEED == test || SPEED_ACK == test) | 428 | else if ((SPEED == test)||(SPEED_ACK == test)) |
426 | { | 429 | { |
427 | if (get_target_channel() == channel) | 430 | if (get_target_channel () == channel) |
428 | { | ||
429 | payload = ack_sent; | ||
430 | size += ack_sent; | ||
431 | ack_sent++; | ||
432 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
433 | "Sending ACK %u [%d bytes]\n", | ||
434 | payload, size); | ||
435 | } | ||
436 | else | ||
437 | { | ||
438 | payload = data_sent; | ||
439 | size += data_sent; | ||
440 | data_sent++; | ||
441 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
442 | "Sending DATA %u [%d bytes]\n", | ||
443 | data_sent, size); | ||
444 | } | ||
445 | } | ||
446 | else if (FORWARD == test) | ||
447 | { | 431 | { |
448 | payload = ack_sent; | 432 | payload = ack_sent; |
433 | size += ack_sent; | ||
434 | ack_sent++; | ||
435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
436 | "Sending ACK %u [%d bytes]\n", | ||
437 | payload, size); | ||
449 | } | 438 | } |
450 | else if (P2P_SIGNAL == test) | 439 | else |
451 | { | 440 | { |
452 | payload = data_sent; | 441 | payload = data_sent; |
442 | size += data_sent; | ||
443 | data_sent++; | ||
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
445 | "Sending DATA %u [%d bytes]\n", | ||
446 | data_sent, size); | ||
453 | } | 447 | } |
448 | } | ||
449 | else if (FORWARD == test) | ||
450 | { | ||
451 | payload = ack_sent; | ||
452 | } | ||
453 | else if (P2P_SIGNAL == test) | ||
454 | { | ||
455 | payload = data_sent; | ||
456 | } | ||
454 | else | 457 | else |
455 | { | 458 | { |
456 | GNUNET_assert(0); | 459 | GNUNET_assert (0); |
457 | } | 460 | } |
458 | env = GNUNET_MQ_msg_extra(msg, size, GNUNET_MESSAGE_TYPE_DUMMY); | 461 | env = GNUNET_MQ_msg_extra (msg, size, GNUNET_MESSAGE_TYPE_DUMMY); |
459 | 462 | ||
460 | data = (uint32_t *)&msg[1]; | 463 | data = (uint32_t *) &msg[1]; |
461 | *data = htonl(payload); | 464 | *data = htonl (payload); |
462 | GNUNET_MQ_send(GNUNET_CADET_get_mq(channel), env); | 465 | GNUNET_MQ_send (GNUNET_CADET_get_mq (channel), env); |
463 | } | 466 | } |
464 | 467 | ||
465 | 468 | ||
@@ -470,30 +473,30 @@ send_test_message(struct GNUNET_CADET_Channel *channel) | |||
470 | * @param cls Closure (unused). | 473 | * @param cls Closure (unused). |
471 | */ | 474 | */ |
472 | static void | 475 | static void |
473 | send_next_msg(void *cls) | 476 | send_next_msg (void *cls) |
474 | { | 477 | { |
475 | struct GNUNET_CADET_Channel *channel; | 478 | struct GNUNET_CADET_Channel *channel; |
476 | 479 | ||
477 | send_next_msg_task = NULL; | 480 | send_next_msg_task = NULL; |
478 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
479 | "Sending next message: %d\n", | 482 | "Sending next message: %d\n", |
480 | data_sent); | 483 | data_sent); |
481 | 484 | ||
482 | channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch; | 485 | channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch; |
483 | GNUNET_assert(NULL != channel); | 486 | GNUNET_assert (NULL != channel); |
484 | GNUNET_assert(SPEED == test); | 487 | GNUNET_assert (SPEED == test); |
485 | send_test_message(channel); | 488 | send_test_message (channel); |
486 | if (data_sent < total_packets) | 489 | if (data_sent < total_packets) |
487 | { | 490 | { |
488 | /* SPEED test: Send all messages as soon as possible */ | 491 | /* SPEED test: Send all messages as soon as possible */ |
489 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
490 | "Scheduling message %d\n", | 493 | "Scheduling message %d\n", |
491 | data_sent + 1); | 494 | data_sent + 1); |
492 | send_next_msg_task = | 495 | send_next_msg_task = |
493 | GNUNET_SCHEDULER_add_delayed(SEND_INTERVAL, | 496 | GNUNET_SCHEDULER_add_delayed (SEND_INTERVAL, |
494 | &send_next_msg, | 497 | &send_next_msg, |
495 | NULL); | 498 | NULL); |
496 | } | 499 | } |
497 | } | 500 | } |
498 | 501 | ||
499 | 502 | ||
@@ -506,8 +509,8 @@ send_next_msg(void *cls) | |||
506 | * #GNUNET_SYSERR to close it (signal serious error). | 509 | * #GNUNET_SYSERR to close it (signal serious error). |
507 | */ | 510 | */ |
508 | static int | 511 | static int |
509 | check_data(void *cls, | 512 | check_data (void *cls, |
510 | const struct GNUNET_MessageHeader *message) | 513 | const struct GNUNET_MessageHeader *message) |
511 | { | 514 | { |
512 | return GNUNET_OK; /* all is well-formed */ | 515 | return GNUNET_OK; /* all is well-formed */ |
513 | } | 516 | } |
@@ -520,8 +523,8 @@ check_data(void *cls, | |||
520 | * @param message the actual message | 523 | * @param message the actual message |
521 | */ | 524 | */ |
522 | static void | 525 | static void |
523 | handle_data(void *cls, | 526 | handle_data (void *cls, |
524 | const struct GNUNET_MessageHeader *message) | 527 | const struct GNUNET_MessageHeader *message) |
525 | { | 528 | { |
526 | struct CadetTestChannelWrapper *ch = cls; | 529 | struct CadetTestChannelWrapper *ch = cls; |
527 | struct GNUNET_CADET_Channel *channel = ch->ch; | 530 | struct GNUNET_CADET_Channel *channel = ch->ch; |
@@ -529,73 +532,73 @@ handle_data(void *cls, | |||
529 | uint32_t payload; | 532 | uint32_t payload; |
530 | int *counter; | 533 | int *counter; |
531 | 534 | ||
532 | GNUNET_CADET_receive_done(channel); | 535 | GNUNET_CADET_receive_done (channel); |
533 | counter = get_target_channel() == channel ? &data_received : &ack_received; | 536 | counter = get_target_channel () == channel ? &data_received : &ack_received; |
534 | if (channel == outgoing_ch) | 537 | if (channel == outgoing_ch) |
535 | { | 538 | { |
536 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 539 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
537 | "Root client got a message.\n"); | 540 | "Root client got a message.\n"); |
538 | } | 541 | } |
539 | else if (channel == incoming_ch) | 542 | else if (channel == incoming_ch) |
540 | { | 543 | { |
541 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 544 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
542 | "Leaf client got a message.\n"); | 545 | "Leaf client got a message.\n"); |
543 | } | 546 | } |
544 | else | 547 | else |
545 | { | 548 | { |
546 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 549 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
547 | "Unknown channel %p.\n", | 550 | "Unknown channel %p.\n", |
548 | channel); | 551 | channel); |
549 | GNUNET_assert(0); | 552 | GNUNET_assert (0); |
550 | } | 553 | } |
551 | 554 | ||
552 | data = (uint32_t *)&message[1]; | 555 | data = (uint32_t *) &message[1]; |
553 | payload = ntohl(*data); | 556 | payload = ntohl (*data); |
554 | if (payload == *counter) | 557 | if (payload == *counter) |
555 | { | 558 | { |
556 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 559 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
557 | "Payload as expected: %u\n", | 560 | "Payload as expected: %u\n", |
558 | payload); | 561 | payload); |
559 | } | 562 | } |
560 | else | 563 | else |
561 | { | 564 | { |
562 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 565 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
563 | "Received payload %u, expected: %u\n", | 566 | "Received payload %u, expected: %u\n", |
564 | payload, *counter); | 567 | payload, *counter); |
565 | } | 568 | } |
566 | (*counter)++; | 569 | (*counter)++; |
567 | if (get_target_channel() == channel) /* Got "data" */ | 570 | if (get_target_channel () == channel) /* Got "data" */ |
571 | { | ||
572 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
573 | " received data %u\n", | ||
574 | data_received); | ||
575 | if (data_received < total_packets) | ||
576 | return; | ||
577 | } | ||
578 | else /* Got "ack" */ | ||
579 | { | ||
580 | if ((SPEED_ACK == test) ||(SPEED == test) ) | ||
568 | { | 581 | { |
569 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 582 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received); |
570 | " received data %u\n", | 583 | /* Send more data */ |
571 | data_received); | 584 | send_test_message (channel); |
572 | if (data_received < total_packets) | 585 | if ((ack_received < total_packets) &&(SPEED != test) ) |
586 | return; | ||
587 | if ((ok == 2) &&(SPEED == test) ) | ||
573 | return; | 588 | return; |
589 | show_end_data (); | ||
574 | } | 590 | } |
575 | else /* Got "ack" */ | 591 | if (test == P2P_SIGNAL) |
592 | { | ||
593 | GNUNET_CADET_channel_destroy (incoming_ch); | ||
594 | incoming_ch = NULL; | ||
595 | } | ||
596 | else | ||
576 | { | 597 | { |
577 | if (SPEED_ACK == test || SPEED == test) | 598 | GNUNET_CADET_channel_destroy (outgoing_ch); |
578 | { | 599 | outgoing_ch = NULL; |
579 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received); | ||
580 | /* Send more data */ | ||
581 | send_test_message(channel); | ||
582 | if (ack_received < total_packets && SPEED != test) | ||
583 | return; | ||
584 | if (ok == 2 && SPEED == test) | ||
585 | return; | ||
586 | show_end_data(); | ||
587 | } | ||
588 | if (test == P2P_SIGNAL) | ||
589 | { | ||
590 | GNUNET_CADET_channel_destroy(incoming_ch); | ||
591 | incoming_ch = NULL; | ||
592 | } | ||
593 | else | ||
594 | { | ||
595 | GNUNET_CADET_channel_destroy(outgoing_ch); | ||
596 | outgoing_ch = NULL; | ||
597 | } | ||
598 | } | 600 | } |
601 | } | ||
599 | } | 602 | } |
600 | 603 | ||
601 | 604 | ||
@@ -612,37 +615,37 @@ handle_data(void *cls, | |||
612 | * received on the @a channel. | 615 | * received on the @a channel. |
613 | */ | 616 | */ |
614 | static void * | 617 | static void * |
615 | connect_handler(void *cls, | 618 | connect_handler (void *cls, |
616 | struct GNUNET_CADET_Channel *channel, | 619 | struct GNUNET_CADET_Channel *channel, |
617 | const struct GNUNET_PeerIdentity *source) | 620 | const struct GNUNET_PeerIdentity *source) |
618 | { | 621 | { |
619 | struct CadetTestChannelWrapper *ch; | 622 | struct CadetTestChannelWrapper *ch; |
620 | long peer = (long)cls; | 623 | long peer = (long) cls; |
621 | 624 | ||
622 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 625 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
623 | "Incoming channel from %s to %ld: %p\n", | 626 | "Incoming channel from %s to %ld: %p\n", |
624 | GNUNET_i2s(source), | 627 | GNUNET_i2s (source), |
625 | peer, | 628 | peer, |
626 | channel); | 629 | channel); |
627 | if (peer == peers_requested - 1) | 630 | if (peer == peers_requested - 1) |
631 | { | ||
632 | if (NULL != incoming_ch) | ||
628 | { | 633 | { |
629 | if (NULL != incoming_ch) | 634 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
630 | { | 635 | "Duplicate incoming channel for client %lu\n", |
631 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 636 | (long) cls); |
632 | "Duplicate incoming channel for client %lu\n", | 637 | GNUNET_assert (0); |
633 | (long)cls); | ||
634 | GNUNET_assert(0); | ||
635 | } | ||
636 | incoming_ch = channel; | ||
637 | } | 638 | } |
639 | incoming_ch = channel; | ||
640 | } | ||
638 | else | 641 | else |
639 | { | 642 | { |
640 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 643 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
641 | "Incoming channel for unexpected peer #%lu\n", | 644 | "Incoming channel for unexpected peer #%lu\n", |
642 | (long)cls); | 645 | (long) cls); |
643 | GNUNET_assert(0); | 646 | GNUNET_assert (0); |
644 | } | 647 | } |
645 | ch = GNUNET_new(struct CadetTestChannelWrapper); | 648 | ch = GNUNET_new (struct CadetTestChannelWrapper); |
646 | ch->ch = channel; | 649 | ch->ch = channel; |
647 | 650 | ||
648 | return ch; | 651 | return ch; |
@@ -661,28 +664,28 @@ connect_handler(void *cls, | |||
661 | * @param channel Connection to the other end (henceforth invalid). | 664 | * @param channel Connection to the other end (henceforth invalid). |
662 | */ | 665 | */ |
663 | static void | 666 | static void |
664 | disconnect_handler(void *cls, | 667 | disconnect_handler (void *cls, |
665 | const struct GNUNET_CADET_Channel *channel) | 668 | const struct GNUNET_CADET_Channel *channel) |
666 | { | 669 | { |
667 | struct CadetTestChannelWrapper *ch_w = cls; | 670 | struct CadetTestChannelWrapper *ch_w = cls; |
668 | 671 | ||
669 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 672 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
670 | "Channel disconnected at %d\n", | 673 | "Channel disconnected at %d\n", |
671 | ok); | 674 | ok); |
672 | GNUNET_assert(ch_w->ch == channel); | 675 | GNUNET_assert (ch_w->ch == channel); |
673 | if (channel == incoming_ch) | 676 | if (channel == incoming_ch) |
674 | incoming_ch = NULL; | 677 | incoming_ch = NULL; |
675 | else if (outgoing_ch == channel) | 678 | else if (outgoing_ch == channel) |
676 | outgoing_ch = NULL; | 679 | outgoing_ch = NULL; |
677 | else | 680 | else |
678 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 681 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
679 | "Disconnect on unknown channel %p\n", | 682 | "Disconnect on unknown channel %p\n", |
680 | channel); | 683 | channel); |
681 | if (NULL != disconnect_task) | 684 | if (NULL != disconnect_task) |
682 | GNUNET_SCHEDULER_cancel(disconnect_task); | 685 | GNUNET_SCHEDULER_cancel (disconnect_task); |
683 | disconnect_task = GNUNET_SCHEDULER_add_now(&gather_stats_and_exit, | 686 | disconnect_task = GNUNET_SCHEDULER_add_now (&gather_stats_and_exit, |
684 | (void *)__LINE__); | 687 | (void *) __LINE__); |
685 | GNUNET_free(ch_w); | 688 | GNUNET_free (ch_w); |
686 | } | 689 | } |
687 | 690 | ||
688 | 691 | ||
@@ -695,41 +698,41 @@ disconnect_handler(void *cls, | |||
695 | * @param cls Closure (unused). | 698 | * @param cls Closure (unused). |
696 | */ | 699 | */ |
697 | static void | 700 | static void |
698 | start_test(void *cls) | 701 | start_test (void *cls) |
699 | { | 702 | { |
700 | struct GNUNET_MQ_MessageHandler handlers[] = { | 703 | struct GNUNET_MQ_MessageHandler handlers[] = { |
701 | GNUNET_MQ_hd_var_size(data, | 704 | GNUNET_MQ_hd_var_size (data, |
702 | GNUNET_MESSAGE_TYPE_DUMMY, | 705 | GNUNET_MESSAGE_TYPE_DUMMY, |
703 | struct GNUNET_MessageHeader, | 706 | struct GNUNET_MessageHeader, |
704 | NULL), | 707 | NULL), |
705 | GNUNET_MQ_handler_end() | 708 | GNUNET_MQ_handler_end () |
706 | }; | 709 | }; |
707 | struct CadetTestChannelWrapper *ch; | 710 | struct CadetTestChannelWrapper *ch; |
708 | enum GNUNET_CADET_ChannelOption flags; | 711 | enum GNUNET_CADET_ChannelOption flags; |
709 | 712 | ||
710 | test_task = NULL; | 713 | test_task = NULL; |
711 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 714 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
712 | "In start_test\n"); | 715 | "In start_test\n"); |
713 | start_time = GNUNET_TIME_absolute_get(); | 716 | start_time = GNUNET_TIME_absolute_get (); |
714 | ch = GNUNET_new(struct CadetTestChannelWrapper); | 717 | ch = GNUNET_new (struct CadetTestChannelWrapper); |
715 | outgoing_ch = GNUNET_CADET_channel_create(h1, | 718 | outgoing_ch = GNUNET_CADET_channel_create (h1, |
716 | ch, | 719 | ch, |
717 | p_id[1], | 720 | p_id[1], |
718 | &port, | 721 | &port, |
719 | flags, | 722 | flags, |
720 | NULL, | 723 | NULL, |
721 | &disconnect_handler, | 724 | &disconnect_handler, |
722 | handlers); | 725 | handlers); |
723 | ch->ch = outgoing_ch; | 726 | ch->ch = outgoing_ch; |
724 | GNUNET_assert(NULL == disconnect_task); | 727 | GNUNET_assert (NULL == disconnect_task); |
725 | disconnect_task | 728 | disconnect_task |
726 | = GNUNET_SCHEDULER_add_delayed(short_time, | 729 | = GNUNET_SCHEDULER_add_delayed (short_time, |
727 | &gather_stats_and_exit, | 730 | &gather_stats_and_exit, |
728 | (void *)__LINE__); | 731 | (void *) __LINE__); |
729 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 732 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
730 | "Sending data initializer on channel %p...\n", | 733 | "Sending data initializer on channel %p...\n", |
731 | outgoing_ch); | 734 | outgoing_ch); |
732 | send_test_message(outgoing_ch); | 735 | send_test_message (outgoing_ch); |
733 | } | 736 | } |
734 | 737 | ||
735 | 738 | ||
@@ -743,36 +746,36 @@ start_test(void *cls) | |||
743 | * NULL if the operation is successfull | 746 | * NULL if the operation is successfull |
744 | */ | 747 | */ |
745 | static void | 748 | static void |
746 | pi_cb(void *cls, | 749 | pi_cb (void *cls, |
747 | struct GNUNET_TESTBED_Operation *op, | 750 | struct GNUNET_TESTBED_Operation *op, |
748 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 751 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
749 | const char *emsg) | 752 | const char *emsg) |
750 | { | 753 | { |
751 | long i = (long)cls; | 754 | long i = (long) cls; |
752 | 755 | ||
753 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
754 | "ID callback for %ld\n", | 757 | "ID callback for %ld\n", |
755 | i); | 758 | i); |
756 | if ((NULL == pinfo) || | 759 | if ((NULL == pinfo) || |
757 | (NULL != emsg)) | 760 | (NULL != emsg)) |
758 | { | 761 | { |
759 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 762 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
760 | "pi_cb: %s\n", | 763 | "pi_cb: %s\n", |
761 | emsg); | 764 | emsg); |
762 | abort_test(__LINE__); | 765 | abort_test (__LINE__); |
763 | return; | 766 | return; |
764 | } | 767 | } |
765 | p_id[i] = pinfo->result.id; | 768 | p_id[i] = pinfo->result.id; |
766 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
767 | "id: %s\n", | 770 | "id: %s\n", |
768 | GNUNET_i2s(p_id[i])); | 771 | GNUNET_i2s (p_id[i])); |
769 | p_ids++; | 772 | p_ids++; |
770 | if (p_ids < 2) | 773 | if (p_ids < 2) |
771 | return; | 774 | return; |
772 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 775 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
773 | "Got all IDs, starting test\n"); | 776 | "Got all IDs, starting test\n"); |
774 | test_task = GNUNET_SCHEDULER_add_now(&start_test, | 777 | test_task = GNUNET_SCHEDULER_add_now (&start_test, |
775 | NULL); | 778 | NULL); |
776 | } | 779 | } |
777 | 780 | ||
778 | 781 | ||
@@ -786,33 +789,33 @@ pi_cb(void *cls, | |||
786 | * @param cadets Handle to each of the CADETs of the peers. | 789 | * @param cadets Handle to each of the CADETs of the peers. |
787 | */ | 790 | */ |
788 | static void | 791 | static void |
789 | tmain(void *cls, | 792 | tmain (void *cls, |
790 | struct GNUNET_CADET_TEST_Context *ctx, | 793 | struct GNUNET_CADET_TEST_Context *ctx, |
791 | unsigned int num_peers, | 794 | unsigned int num_peers, |
792 | struct GNUNET_TESTBED_Peer **peers, | 795 | struct GNUNET_TESTBED_Peer **peers, |
793 | struct GNUNET_CADET_Handle **cadets) | 796 | struct GNUNET_CADET_Handle **cadets) |
794 | { | 797 | { |
795 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
796 | "test main\n"); | 799 | "test main\n"); |
797 | test_ctx = ctx; | 800 | test_ctx = ctx; |
798 | peers_running = num_peers; | 801 | peers_running = num_peers; |
799 | GNUNET_assert(peers_running == peers_requested); | 802 | GNUNET_assert (peers_running == peers_requested); |
800 | testbed_peers = peers; | 803 | testbed_peers = peers; |
801 | h1 = cadets[0]; | 804 | h1 = cadets[0]; |
802 | h2 = cadets[num_peers - 1]; | 805 | h2 = cadets[num_peers - 1]; |
803 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, | 806 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
804 | NULL); | 807 | NULL); |
805 | p_ids = 0; | 808 | p_ids = 0; |
806 | t_op[0] = GNUNET_TESTBED_peer_get_information(peers[0], | 809 | t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0], |
807 | GNUNET_TESTBED_PIT_IDENTITY, | 810 | GNUNET_TESTBED_PIT_IDENTITY, |
808 | &pi_cb, | 811 | &pi_cb, |
809 | (void *)0L); | 812 | (void *) 0L); |
810 | t_op[1] = GNUNET_TESTBED_peer_get_information(peers[num_peers - 1], | 813 | t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1], |
811 | GNUNET_TESTBED_PIT_IDENTITY, | 814 | GNUNET_TESTBED_PIT_IDENTITY, |
812 | &pi_cb, | 815 | &pi_cb, |
813 | (void *)1L); | 816 | (void *) 1L); |
814 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 817 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
815 | "requested peer ids\n"); | 818 | "requested peer ids\n"); |
816 | } | 819 | } |
817 | 820 | ||
818 | 821 | ||
@@ -820,67 +823,67 @@ tmain(void *cls, | |||
820 | * Main: start test | 823 | * Main: start test |
821 | */ | 824 | */ |
822 | int | 825 | int |
823 | main(int argc, | 826 | main (int argc, |
824 | char *argv[]) | 827 | char *argv[]) |
825 | { | 828 | { |
826 | static const struct GNUNET_HashCode *ports[2]; | 829 | static const struct GNUNET_HashCode *ports[2]; |
827 | struct GNUNET_MQ_MessageHandler handlers[] = { | 830 | struct GNUNET_MQ_MessageHandler handlers[] = { |
828 | GNUNET_MQ_hd_var_size(data, | 831 | GNUNET_MQ_hd_var_size (data, |
829 | GNUNET_MESSAGE_TYPE_DUMMY, | 832 | GNUNET_MESSAGE_TYPE_DUMMY, |
830 | struct GNUNET_MessageHeader, | 833 | struct GNUNET_MessageHeader, |
831 | NULL), | 834 | NULL), |
832 | GNUNET_MQ_handler_end() | 835 | GNUNET_MQ_handler_end () |
833 | }; | 836 | }; |
834 | const char *config_file = "test_cadet.conf"; | 837 | const char *config_file = "test_cadet.conf"; |
835 | char port_id[] = "test port"; | 838 | char port_id[] = "test port"; |
836 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 839 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
837 | GNUNET_GETOPT_option_relative_time('t', | 840 | GNUNET_GETOPT_option_relative_time ('t', |
838 | "time", | 841 | "time", |
839 | "short_time", | 842 | "short_time", |
840 | gettext_noop("set short timeout"), | 843 | gettext_noop ("set short timeout"), |
841 | &short_time), | 844 | &short_time), |
842 | GNUNET_GETOPT_option_uint('m', | 845 | GNUNET_GETOPT_option_uint ('m', |
843 | "messages", | 846 | "messages", |
844 | "NUM_MESSAGES", | 847 | "NUM_MESSAGES", |
845 | gettext_noop("set number of messages to send"), | 848 | gettext_noop ("set number of messages to send"), |
846 | &total_packets), | 849 | &total_packets), |
847 | GNUNET_GETOPT_option_uint('p', | 850 | GNUNET_GETOPT_option_uint ('p', |
848 | "peers", | 851 | "peers", |
849 | "NUM_PEERS", | 852 | "NUM_PEERS", |
850 | gettext_noop("number of peers to launch"), | 853 | gettext_noop ("number of peers to launch"), |
851 | &peers_requested), | 854 | &peers_requested), |
852 | GNUNET_GETOPT_OPTION_END | 855 | GNUNET_GETOPT_OPTION_END |
853 | }; | 856 | }; |
854 | 857 | ||
855 | GNUNET_log_setup("test-cadet-flow", | 858 | GNUNET_log_setup ("test-cadet-flow", |
856 | "DEBUG", | 859 | "DEBUG", |
857 | NULL); | 860 | NULL); |
858 | total_packets = TOTAL_PACKETS; | 861 | total_packets = TOTAL_PACKETS; |
859 | short_time = SHORT_TIME; | 862 | short_time = SHORT_TIME; |
860 | if (-1 == GNUNET_GETOPT_run(argv[0], | 863 | if (-1 == GNUNET_GETOPT_run (argv[0], |
861 | options, | 864 | options, |
862 | argc, | 865 | argc, |
863 | argv)) | 866 | argv)) |
864 | { | 867 | { |
865 | fprintf(stderr, | 868 | fprintf (stderr, |
866 | "test failed: problem with CLI parameters\n"); | 869 | "test failed: problem with CLI parameters\n"); |
867 | return 1; | 870 | return 1; |
868 | } | 871 | } |
869 | GNUNET_CRYPTO_hash(port_id, | 872 | GNUNET_CRYPTO_hash (port_id, |
870 | sizeof(port_id), | 873 | sizeof(port_id), |
871 | &port); | 874 | &port); |
872 | ports[0] = &port; | 875 | ports[0] = &port; |
873 | ports[1] = NULL; | 876 | ports[1] = NULL; |
874 | GNUNET_CADET_TEST_ruN("test_cadet_flow", | 877 | GNUNET_CADET_TEST_ruN ("test_cadet_flow", |
875 | config_file, | 878 | config_file, |
876 | peers_requested, | 879 | peers_requested, |
877 | &tmain, | 880 | &tmain, |
878 | NULL, /* tmain cls */ | 881 | NULL, /* tmain cls */ |
879 | &connect_handler, | 882 | &connect_handler, |
880 | NULL, | 883 | NULL, |
881 | &disconnect_handler, | 884 | &disconnect_handler, |
882 | handlers, | 885 | handlers, |
883 | ports); | 886 | ports); |
884 | return 0; | 887 | return 0; |
885 | } | 888 | } |
886 | 889 | ||