aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/test_cadet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/test_cadet.c')
-rw-r--r--src/cadet/test_cadet.c123
1 files changed, 88 insertions, 35 deletions
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index 31c2094de..2b69579a5 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -177,6 +177,17 @@ static struct GNUNET_CADET_Channel *ch;
177static struct GNUNET_CADET_Channel *incoming_ch; 177static struct GNUNET_CADET_Channel *incoming_ch;
178 178
179/** 179/**
180 * Transmit handle for root data calls
181 */
182static struct GNUNET_CADET_TransmitHandle *th;
183
184/**
185 * Transmit handle for root data calls
186 */
187static struct GNUNET_CADET_TransmitHandle *incoming_th;
188
189
190/**
180 * Time we started the data transmission (after channel has been established 191 * Time we started the data transmission (after channel has been established
181 * and initilized). 192 * and initilized).
182 */ 193 */
@@ -286,11 +297,21 @@ disconnect_cadet_peers (void *cls,
286 } 297 }
287 if (NULL != ch) 298 if (NULL != ch)
288 { 299 {
300 if (NULL != th)
301 {
302 GNUNET_CADET_notify_transmit_ready_cancel (th);
303 th = NULL;
304 }
289 GNUNET_CADET_channel_destroy (ch); 305 GNUNET_CADET_channel_destroy (ch);
290 ch = NULL; 306 ch = NULL;
291 } 307 }
292 if (NULL != incoming_ch) 308 if (NULL != incoming_ch)
293 { 309 {
310 if (NULL != incoming_th)
311 {
312 GNUNET_CADET_notify_transmit_ready_cancel (incoming_th);
313 incoming_th = NULL;
314 }
294 GNUNET_CADET_channel_destroy (incoming_ch); 315 GNUNET_CADET_channel_destroy (incoming_ch);
295 incoming_ch = NULL; 316 incoming_ch = NULL;
296 } 317 }
@@ -372,8 +393,9 @@ static void
372gather_stats_and_exit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 393gather_stats_and_exit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
373{ 394{
374 disconnect_task = NULL; 395 disconnect_task = NULL;
396 long l = (long) cls;
375 397
376 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gathering statistics\n"); 398 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gathering statistics from line %d\n", l);
377 399
378 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) 400 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
379 { 401 {
@@ -385,6 +407,11 @@ gather_stats_and_exit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
385 407
386 if (NULL != ch) 408 if (NULL != ch)
387 { 409 {
410 if (NULL != th)
411 {
412 GNUNET_CADET_notify_transmit_ready_cancel (th);
413 th = NULL;
414 }
388 GNUNET_CADET_channel_destroy (ch); 415 GNUNET_CADET_channel_destroy (ch);
389 ch = NULL; 416 ch = NULL;
390 } 417 }
@@ -426,7 +453,7 @@ tmt_rdy (void *cls, size_t size, void *buf);
426 453
427 454
428/** 455/**
429 * Task to schedule a new data transmission. 456 * Task to request a new data transmission.
430 * 457 *
431 * @param cls Closure (peer #). 458 * @param cls Closure (peer #).
432 * @param tc Task Context. 459 * @param tc Task Context.
@@ -434,8 +461,9 @@ tmt_rdy (void *cls, size_t size, void *buf);
434static void 461static void
435data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 462data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
436{ 463{
437 struct GNUNET_CADET_TransmitHandle *th;
438 struct GNUNET_CADET_Channel *channel; 464 struct GNUNET_CADET_Channel *channel;
465 static struct GNUNET_CADET_TransmitHandle **pth;
466
439 long src; 467 long src;
440 468
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n"); 469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n");
@@ -446,24 +474,24 @@ data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
446 if (GNUNET_YES == test_backwards) 474 if (GNUNET_YES == test_backwards)
447 { 475 {
448 channel = incoming_ch; 476 channel = incoming_ch;
477 pth = &incoming_th;
449 src = peers_requested - 1; 478 src = peers_requested - 1;
450 } 479 }
451 else 480 else
452 { 481 {
453 channel = ch; 482 channel = ch;
483 pth = &th;
454 src = 0; 484 src = 0;
455 } 485 }
456 486
457 if (NULL == channel) 487 GNUNET_assert (NULL != channel);
458 { 488 GNUNET_assert (NULL == *pth);
459 GNUNET_break (0); 489
460 return; 490 *pth = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
461 } 491 GNUNET_TIME_UNIT_FOREVER_REL,
462 th = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, 492 size_payload + data_sent,
463 GNUNET_TIME_UNIT_FOREVER_REL, 493 &tmt_rdy, (void *) src);
464 size_payload + data_sent, 494 if (NULL == *pth)
465 &tmt_rdy, (void *) src);
466 if (NULL == th)
467 { 495 {
468 unsigned long i = (unsigned long) cls; 496 unsigned long i = (unsigned long) cls;
469 497
@@ -478,9 +506,9 @@ data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
478 { 506 {
479 i++; 507 i++;
480 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "in %u ms\n", i); 508 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "in %u ms\n", i);
481 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( 509 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
482 GNUNET_TIME_UNIT_MILLISECONDS, 510 GNUNET_TIME_UNIT_MILLISECONDS,
483 i), 511 i),
484 &data_task, (void *) i); 512 &data_task, (void *) i);
485 } 513 }
486 } 514 }
@@ -504,6 +532,12 @@ tmt_rdy (void *cls, size_t size, void *buf)
504 unsigned int counter; 532 unsigned int counter;
505 533
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy on %ld, filling buffer\n", id); 534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy on %ld, filling buffer\n", id);
535 if (0 == id)
536 th = NULL;
537 else if ((peers_requested - 1) == id)
538 incoming_th = NULL;
539 else
540 GNUNET_assert (0);
507 counter = get_expected_target () == id ? ack_sent : data_sent; 541 counter = get_expected_target () == id ? ack_sent : data_sent;
508 msg_size = size_payload + counter; 542 msg_size = size_payload + counter;
509 if (size < msg_size || NULL == buf) 543 if (size < msg_size || NULL == buf)
@@ -551,7 +585,7 @@ tmt_rdy (void *cls, size_t size, void *buf)
551/** 585/**
552 * Function is called whenever a message is received. 586 * Function is called whenever a message is received.
553 * 587 *
554 * @param cls closure (set from GNUNET_CADET_connect) 588 * @param cls closure (set from GNUNET_CADET_connect, peer number)
555 * @param channel connection to the other end 589 * @param channel connection to the other end
556 * @param channel_ctx place to store local state associated with the channel 590 * @param channel_ctx place to store local state associated with the channel
557 * @param message the actual message 591 * @param message the actual message
@@ -563,6 +597,7 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
563 void **channel_ctx, 597 void **channel_ctx,
564 const struct GNUNET_MessageHeader *message) 598 const struct GNUNET_MessageHeader *message)
565{ 599{
600 struct GNUNET_CADET_TransmitHandle **pth;
566 long client = (long) cls; 601 long client = (long) cls;
567 long expected_target_client; 602 long expected_target_client;
568 uint32_t *data; 603 uint32_t *data;
@@ -590,15 +625,19 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
590 { 625 {
591 case 0L: 626 case 0L:
592 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message!\n"); 627 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message!\n");
628 GNUNET_assert (channel == ch);
629 pth = &th;
593 break; 630 break;
594 case 1L: 631 case 1L:
595 case 4L: 632 case 4L:
596 GNUNET_assert (client == peers_requested - 1); 633 GNUNET_assert (client == peers_requested - 1);
597 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Leaf client %li got a message.\n", 634 GNUNET_assert (channel == incoming_ch);
635 pth = &incoming_th;
636 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Leaf client %ld got a message.\n",
598 client); 637 client);
599 break; 638 break;
600 default: 639 default:
601 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Client %li not valid.\n", client); 640 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Client %ld not valid.\n", client);
602 GNUNET_assert (0); 641 GNUNET_assert (0);
603 } 642 }
604 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: (%d/%d)\n", ok, ok_goal); 643 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: (%d/%d)\n", ok, ok_goal);
@@ -635,10 +674,11 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
635 if (SPEED != test || (ok_goal - 2) == ok) 674 if (SPEED != test || (ok_goal - 2) == ok)
636 { 675 {
637 /* Send ACK */ 676 /* Send ACK */
638 GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, 677 GNUNET_assert (NULL == *pth);
639 GNUNET_TIME_UNIT_FOREVER_REL, 678 *pth = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
640 size_payload + ack_sent, &tmt_rdy, 679 GNUNET_TIME_UNIT_FOREVER_REL,
641 (void *) client); 680 size_payload + ack_sent,
681 &tmt_rdy, (void *) client);
642 return GNUNET_OK; 682 return GNUNET_OK;
643 } 683 }
644 else 684 else
@@ -653,10 +693,12 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
653 { 693 {
654 ack_received++; 694 ack_received++;
655 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received); 695 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received);
656 GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, 696 /* send more data */
657 GNUNET_TIME_UNIT_FOREVER_REL, 697 GNUNET_assert (NULL == *pth);
658 size_payload + data_sent, &tmt_rdy, 698 *pth = GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
659 (void *) client); 699 GNUNET_TIME_UNIT_FOREVER_REL,
700 size_payload + data_sent,
701 &tmt_rdy, (void *) client);
660 if (ack_received < TOTAL_PACKETS && SPEED != test) 702 if (ack_received < TOTAL_PACKETS && SPEED != test)
661 return GNUNET_OK; 703 return GNUNET_OK;
662 if (ok == 2 && SPEED == test) 704 if (ok == 2 && SPEED == test)
@@ -665,11 +707,21 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
665 } 707 }
666 if (test == P2P_SIGNAL) 708 if (test == P2P_SIGNAL)
667 { 709 {
710 if (NULL != incoming_th)
711 {
712 GNUNET_CADET_notify_transmit_ready_cancel (incoming_th);
713 incoming_th = NULL;
714 }
668 GNUNET_CADET_channel_destroy (incoming_ch); 715 GNUNET_CADET_channel_destroy (incoming_ch);
669 incoming_ch = NULL; 716 incoming_ch = NULL;
670 } 717 }
671 else 718 else
672 { 719 {
720 if (NULL != th)
721 {
722 GNUNET_CADET_notify_transmit_ready_cancel (th);
723 th = NULL;
724 }
673 GNUNET_CADET_channel_destroy (ch); 725 GNUNET_CADET_channel_destroy (ch);
674 ch = NULL; 726 ch = NULL;
675 } 727 }
@@ -680,7 +732,8 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
680 732
681 733
682/** 734/**
683 * Handlers, for diverse services 735 * Data handlers for every message type of CADET's payload.
736 * {callback_function, message_type, size_expected}
684 */ 737 */
685static struct GNUNET_CADET_MessageHandler handlers[] = { 738static struct GNUNET_CADET_MessageHandler handlers[] = {
686 {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)}, 739 {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
@@ -733,7 +786,7 @@ incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
733 * Function called whenever an inbound channel is destroyed. Should clean up 786 * Function called whenever an inbound channel is destroyed. Should clean up
734 * any associated state. 787 * any associated state.
735 * 788 *
736 * @param cls closure (set from GNUNET_CADET_connect) 789 * @param cls closure (set from GNUNET_CADET_connect, peer number)
737 * @param channel connection to the other end (henceforth invalid) 790 * @param channel connection to the other end (henceforth invalid)
738 * @param channel_ctx place where local state associated 791 * @param channel_ctx place where local state associated
739 * with the channel is stored 792 * with the channel is stored
@@ -781,7 +834,7 @@ channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel,
781 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES. 834 * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
782 * 835 *
783 * Testcase continues when the root receives confirmation of connected peers, 836 * Testcase continues when the root receives confirmation of connected peers,
784 * on callback funtion ch. 837 * on callback function ch.
785 * 838 *
786 * @param cls Closure (unused). 839 * @param cls Closure (unused).
787 * @param tc Task Context. 840 * @param tc Task Context.
@@ -794,7 +847,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
794 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) 847 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
795 return; 848 return;
796 849
797 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n"); 850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "do_test\n");
798 851
799 if (NULL != disconnect_task) 852 if (NULL != disconnect_task)
800 { 853 {
@@ -820,10 +873,10 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
820 data_sent = 0; 873 data_sent = 0;
821 ack_received = 0; 874 ack_received = 0;
822 ack_sent = 0; 875 ack_sent = 0;
823 GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO, 876 th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
824 GNUNET_TIME_UNIT_FOREVER_REL, 877 GNUNET_TIME_UNIT_FOREVER_REL,
825 size_payload + 1000, 878 size_payload + 1000,
826 &tmt_rdy, (void *) 0L); 879 &tmt_rdy, (void *) 0L);
827} 880}
828 881
829/** 882/**