diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-11 15:45:38 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-11 15:45:38 +0000 |
commit | 9404025ec2ea2d44468c072a299a4d1e8f229ebb (patch) | |
tree | 9ddabdfcacb27fc9fdd0a9897051c2374a0138fa /src/integration-tests | |
parent | 33c2e452d34d3334cf6b189e41b4487b85a01b50 (diff) | |
download | gnunet-9404025ec2ea2d44468c072a299a4d1e8f229ebb.tar.gz gnunet-9404025ec2ea2d44468c072a299a4d1e8f229ebb.zip |
- send recv test
Diffstat (limited to 'src/integration-tests')
-rw-r--r-- | src/integration-tests/connection_watchdog.c | 277 |
1 files changed, 274 insertions, 3 deletions
diff --git a/src/integration-tests/connection_watchdog.c b/src/integration-tests/connection_watchdog.c index fc0d27f3e..89ec25c7d 100644 --- a/src/integration-tests/connection_watchdog.c +++ b/src/integration-tests/connection_watchdog.c | |||
@@ -78,6 +78,11 @@ struct PeerContainer | |||
78 | struct GNUNET_PeerIdentity id; | 78 | struct GNUNET_PeerIdentity id; |
79 | int transport_connected; | 79 | int transport_connected; |
80 | int core_connected; | 80 | int core_connected; |
81 | struct GNUNET_TRANSPORT_TransmitHandle *th_ping; | ||
82 | struct GNUNET_CORE_TransmitHandle *ch_ping; | ||
83 | |||
84 | struct GNUNET_TRANSPORT_TransmitHandle *th_pong; | ||
85 | struct GNUNET_CORE_TransmitHandle *ch_pong; | ||
81 | }; | 86 | }; |
82 | 87 | ||
83 | 88 | ||
@@ -122,7 +127,7 @@ int map_check_it (void *cls, | |||
122 | if (pc->core_connected != pc->transport_connected) | 127 | if (pc->core_connected != pc->transport_connected) |
123 | { | 128 | { |
124 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 129 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
125 | "Inconsistend peer `%s': TRANSPORT %s <-> CORE %s\n", | 130 | "Inconsistent peer `%s': TRANSPORT %s <-> CORE %s\n", |
126 | GNUNET_i2s (&pc->id), | 131 | GNUNET_i2s (&pc->id), |
127 | (GNUNET_YES == pc->transport_connected) ? "YES" : "NO", | 132 | (GNUNET_YES == pc->transport_connected) ? "YES" : "NO", |
128 | (GNUNET_YES == pc->core_connected) ? "YES" : "NO"); | 133 | (GNUNET_YES == pc->core_connected) ? "YES" : "NO"); |
@@ -139,6 +144,26 @@ int map_cleanup_it (void *cls, | |||
139 | { | 144 | { |
140 | struct PeerContainer *pc = value; | 145 | struct PeerContainer *pc = value; |
141 | GNUNET_CONTAINER_multihashmap_remove(peers, key, value); | 146 | GNUNET_CONTAINER_multihashmap_remove(peers, key, value); |
147 | if (NULL != pc->th_ping) | ||
148 | { | ||
149 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_ping); | ||
150 | pc->th_ping = NULL; | ||
151 | } | ||
152 | if (NULL != pc->th_pong) | ||
153 | { | ||
154 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_pong); | ||
155 | pc->th_pong = NULL; | ||
156 | } | ||
157 | if (NULL != pc->ch_ping) | ||
158 | { | ||
159 | GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_ping); | ||
160 | pc->ch_ping = NULL; | ||
161 | } | ||
162 | if (NULL != pc->ch_pong) | ||
163 | { | ||
164 | GNUNET_CORE_notify_transmit_ready_cancel(pc->ch_pong); | ||
165 | pc->ch_pong = NULL; | ||
166 | } | ||
142 | GNUNET_free (pc); | 167 | GNUNET_free (pc); |
143 | return GNUNET_OK; | 168 | return GNUNET_OK; |
144 | } | 169 | } |
@@ -381,6 +406,121 @@ stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
381 | 406 | ||
382 | } | 407 | } |
383 | 408 | ||
409 | GNUNET_NETWORK_STRUCT_BEGIN | ||
410 | |||
411 | struct PING | ||
412 | { | ||
413 | struct GNUNET_MessageHeader header; | ||
414 | |||
415 | uint16_t src; | ||
416 | }; | ||
417 | |||
418 | struct PONG | ||
419 | { | ||
420 | struct GNUNET_MessageHeader header; | ||
421 | |||
422 | uint16_t src; | ||
423 | }; | ||
424 | GNUNET_NETWORK_STRUCT_END | ||
425 | |||
426 | |||
427 | size_t send_transport_ping_cb (void *cls, size_t size, void *buf) | ||
428 | { | ||
429 | struct PeerContainer * pc = cls; | ||
430 | struct PING ping; | ||
431 | size_t mlen = sizeof (struct PING); | ||
432 | |||
433 | if (size < mlen) | ||
434 | { | ||
435 | GNUNET_break (0); | ||
436 | return 0; | ||
437 | } | ||
438 | |||
439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
440 | "Sending transport ping to `%s'\n", GNUNET_i2s (&pc->id)); | ||
441 | ping.header.size = htons (mlen); | ||
442 | ping.header.type = htons (1234); | ||
443 | ping.src = htons (0); | ||
444 | |||
445 | pc->th_ping = NULL; | ||
446 | |||
447 | memcpy (buf, &ping, mlen); | ||
448 | return mlen; | ||
449 | } | ||
450 | |||
451 | size_t send_core_ping_cb (void *cls, size_t size, void *buf) | ||
452 | { | ||
453 | struct PeerContainer * pc = cls; | ||
454 | struct PING ping; | ||
455 | size_t mlen = sizeof (struct PING); | ||
456 | |||
457 | if (size < mlen) | ||
458 | { | ||
459 | GNUNET_break (0); | ||
460 | return 0; | ||
461 | } | ||
462 | |||
463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
464 | "Sending core ping to `%s'\n", GNUNET_i2s (&pc->id)); | ||
465 | ping.header.size = htons (mlen); | ||
466 | ping.header.type = htons (1234); | ||
467 | ping.src = htons (1); | ||
468 | |||
469 | pc->ch_ping = NULL; | ||
470 | |||
471 | memcpy (buf, &ping, mlen); | ||
472 | return mlen; | ||
473 | } | ||
474 | |||
475 | |||
476 | size_t send_transport_pong_cb (void *cls, size_t size, void *buf) | ||
477 | { | ||
478 | struct PeerContainer * pc = cls; | ||
479 | struct PING ping; | ||
480 | size_t mlen = sizeof (struct PING); | ||
481 | |||
482 | if (size < mlen) | ||
483 | { | ||
484 | GNUNET_break (0); | ||
485 | return 0; | ||
486 | } | ||
487 | |||
488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
489 | "Sending transport pong to `%s'\n", GNUNET_i2s (&pc->id)); | ||
490 | ping.header.size = htons (mlen); | ||
491 | ping.header.type = htons (4321); | ||
492 | ping.src = htons (0); | ||
493 | |||
494 | pc->th_pong = NULL; | ||
495 | |||
496 | memcpy (buf, &ping, mlen); | ||
497 | return mlen; | ||
498 | } | ||
499 | |||
500 | size_t send_core_pong_cb (void *cls, size_t size, void *buf) | ||
501 | { | ||
502 | struct PeerContainer * pc = cls; | ||
503 | struct PING ping; | ||
504 | size_t mlen = sizeof (struct PING); | ||
505 | |||
506 | if (size < mlen) | ||
507 | { | ||
508 | GNUNET_break (0); | ||
509 | return 0; | ||
510 | } | ||
511 | |||
512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
513 | "Sending core pong to `%s'\n", GNUNET_i2s (&pc->id)); | ||
514 | ping.header.size = htons (mlen); | ||
515 | ping.header.type = htons (4321); | ||
516 | ping.src = htons (1); | ||
517 | |||
518 | pc->ch_pong = NULL; | ||
519 | |||
520 | memcpy (buf, &ping, mlen); | ||
521 | return mlen; | ||
522 | } | ||
523 | |||
384 | 524 | ||
385 | static void | 525 | static void |
386 | map_connect (const struct GNUNET_PeerIdentity *peer, void * source) | 526 | map_connect (const struct GNUNET_PeerIdentity *peer, void * source) |
@@ -401,6 +541,10 @@ map_connect (const struct GNUNET_PeerIdentity *peer, void * source) | |||
401 | if (GNUNET_NO == pc->transport_connected) | 541 | if (GNUNET_NO == pc->transport_connected) |
402 | { | 542 | { |
403 | pc->transport_connected = GNUNET_YES; | 543 | pc->transport_connected = GNUNET_YES; |
544 | if (NULL == pc->th_ping) | ||
545 | pc->th_ping = GNUNET_TRANSPORT_notify_transmit_ready(th, peer, sizeof (struct PING), UINT_MAX, GNUNET_TIME_relative_get_forever(), &send_transport_ping_cb, pc); | ||
546 | else | ||
547 | GNUNET_break(0); | ||
404 | } | 548 | } |
405 | else | 549 | else |
406 | { | 550 | { |
@@ -417,6 +561,15 @@ map_connect (const struct GNUNET_PeerIdentity *peer, void * source) | |||
417 | if (GNUNET_NO == pc->core_connected) | 561 | if (GNUNET_NO == pc->core_connected) |
418 | { | 562 | { |
419 | pc->core_connected = GNUNET_YES; | 563 | pc->core_connected = GNUNET_YES; |
564 | if (NULL == pc->ch_ping) | ||
565 | pc->ch_ping = GNUNET_CORE_notify_transmit_ready(ch, | ||
566 | GNUNET_NO, UINT_MAX, | ||
567 | GNUNET_TIME_relative_get_forever(), | ||
568 | peer, | ||
569 | sizeof (struct PING), | ||
570 | send_core_ping_cb, pc); | ||
571 | else | ||
572 | GNUNET_break (0); | ||
420 | } | 573 | } |
421 | else | 574 | else |
422 | { | 575 | { |
@@ -465,6 +618,17 @@ map_disconnect (const struct GNUNET_PeerIdentity * peer, void * source) | |||
465 | pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey); | 618 | pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey); |
466 | if (source == th) | 619 | if (source == th) |
467 | { | 620 | { |
621 | if (NULL != pc->th_ping) | ||
622 | { | ||
623 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_ping); | ||
624 | pc->th_ping = NULL; | ||
625 | } | ||
626 | if (NULL != pc->th_pong) | ||
627 | { | ||
628 | GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_pong); | ||
629 | pc->th_pong = NULL; | ||
630 | } | ||
631 | |||
468 | if (GNUNET_YES == pc->transport_connected) | 632 | if (GNUNET_YES == pc->transport_connected) |
469 | { | 633 | { |
470 | pc->transport_connected = GNUNET_NO; | 634 | pc->transport_connected = GNUNET_NO; |
@@ -481,6 +645,17 @@ map_disconnect (const struct GNUNET_PeerIdentity * peer, void * source) | |||
481 | } | 645 | } |
482 | if (source == ch) | 646 | if (source == ch) |
483 | { | 647 | { |
648 | if (NULL != pc->ch_ping) | ||
649 | { | ||
650 | GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_ping); | ||
651 | pc->ch_ping = NULL; | ||
652 | } | ||
653 | if (NULL != pc->ch_pong) | ||
654 | { | ||
655 | GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_pong); | ||
656 | pc->ch_pong = NULL; | ||
657 | } | ||
658 | |||
484 | if (GNUNET_YES == pc->core_connected) | 659 | if (GNUNET_YES == pc->core_connected) |
485 | { | 660 | { |
486 | pc->core_connected = GNUNET_NO; | 661 | pc->core_connected = GNUNET_NO; |
@@ -500,6 +675,8 @@ map_disconnect (const struct GNUNET_PeerIdentity * peer, void * source) | |||
500 | { | 675 | { |
501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing peer `%s'\n", GNUNET_i2s (&pc->id)); | 676 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing peer `%s'\n", GNUNET_i2s (&pc->id)); |
502 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (peers, &peer->hashPubKey, pc)); | 677 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (peers, &peer->hashPubKey, pc)); |
678 | |||
679 | |||
503 | GNUNET_free (pc); | 680 | GNUNET_free (pc); |
504 | } | 681 | } |
505 | 682 | ||
@@ -524,6 +701,8 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
524 | GNUNET_TRANSPORT_disconnect (th); | 701 | GNUNET_TRANSPORT_disconnect (th); |
525 | th = NULL; | 702 | th = NULL; |
526 | } | 703 | } |
704 | |||
705 | |||
527 | if (NULL != ch) | 706 | if (NULL != ch) |
528 | { | 707 | { |
529 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disconnecting from core service\n"); | 708 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disconnecting from core service\n"); |
@@ -587,6 +766,97 @@ transport_notify_disconnect_cb (void *cls, | |||
587 | 766 | ||
588 | } | 767 | } |
589 | 768 | ||
769 | static void | ||
770 | transport_notify_receive_cb (void *cls, | ||
771 | const struct | ||
772 | GNUNET_PeerIdentity * peer, | ||
773 | const struct | ||
774 | GNUNET_MessageHeader * | ||
775 | message, | ||
776 | const struct | ||
777 | GNUNET_ATS_Information * ats, | ||
778 | uint32_t ats_count) | ||
779 | { | ||
780 | |||
781 | |||
782 | struct PeerContainer *pc = NULL; | ||
783 | |||
784 | pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey); | ||
785 | |||
786 | if (NULL == pc) | ||
787 | { | ||
788 | GNUNET_break (0); | ||
789 | return; | ||
790 | } | ||
791 | |||
792 | if ((message->size == ntohs (sizeof (struct PING))) && (message->type == ntohs (1234))) | ||
793 | { | ||
794 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s %s from peer `%s'\n", | ||
795 | "TRANSPORT", | ||
796 | "PING", | ||
797 | GNUNET_i2s (peer)) ; | ||
798 | if (NULL == pc->th_pong) | ||
799 | pc->th_pong = GNUNET_TRANSPORT_notify_transmit_ready(th, | ||
800 | peer, sizeof (struct PONG), | ||
801 | UINT_MAX, GNUNET_TIME_relative_get_forever(), | ||
802 | &send_transport_pong_cb, pc); | ||
803 | else | ||
804 | GNUNET_break (0); | ||
805 | |||
806 | } | ||
807 | if ((message->size == ntohs (sizeof (struct PONG))) && (message->type == ntohs (4321))) | ||
808 | { | ||
809 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received %s %s from peer `%s'\n", | ||
810 | "TRANSPORT", | ||
811 | "PONG", | ||
812 | GNUNET_i2s (peer)); | ||
813 | } | ||
814 | } | ||
815 | |||
816 | int core_notify_receive_cb (void *cls, | ||
817 | const struct GNUNET_PeerIdentity * peer, | ||
818 | const struct GNUNET_MessageHeader * message, | ||
819 | const struct GNUNET_ATS_Information* atsi, | ||
820 | unsigned int atsi_count) | ||
821 | { | ||
822 | struct PeerContainer *pc = NULL; | ||
823 | |||
824 | pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey); | ||
825 | |||
826 | if (NULL == pc) | ||
827 | { | ||
828 | GNUNET_break (0); | ||
829 | return GNUNET_OK; | ||
830 | } | ||
831 | |||
832 | if ((message->size == ntohs (sizeof (struct PING))) && (message->type == ntohs (1234))) | ||
833 | { | ||
834 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received %s %s from peer `%s'\n", | ||
835 | "CORE", | ||
836 | "PING", | ||
837 | GNUNET_i2s (peer)); | ||
838 | if (NULL == pc->ch_pong) | ||
839 | pc->ch_pong = GNUNET_CORE_notify_transmit_ready(ch, | ||
840 | GNUNET_NO, UINT_MAX, | ||
841 | GNUNET_TIME_relative_get_forever(), | ||
842 | peer, | ||
843 | sizeof (struct PONG), | ||
844 | send_core_pong_cb, pc); | ||
845 | else | ||
846 | GNUNET_break (0); | ||
847 | } | ||
848 | |||
849 | if ((message->size == ntohs (sizeof (struct PONG))) && (message->type == ntohs (4321))) | ||
850 | { | ||
851 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s %s from peer `%s'\n", | ||
852 | "CORE", | ||
853 | "PONG", | ||
854 | GNUNET_i2s (peer)); | ||
855 | |||
856 | } | ||
857 | |||
858 | return GNUNET_OK; | ||
859 | } | ||
590 | 860 | ||
591 | static void | 861 | static void |
592 | core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | 862 | core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, |
@@ -728,7 +998,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
728 | stats = GNUNET_STATISTICS_create ("watchdog", cfg); | 998 | stats = GNUNET_STATISTICS_create ("watchdog", cfg); |
729 | peers = GNUNET_CONTAINER_multihashmap_create (20); | 999 | peers = GNUNET_CONTAINER_multihashmap_create (20); |
730 | 1000 | ||
731 | th = GNUNET_TRANSPORT_connect(cfg, NULL, NULL, NULL, | 1001 | th = GNUNET_TRANSPORT_connect(cfg, NULL, NULL, |
1002 | &transport_notify_receive_cb, | ||
732 | &transport_notify_connect_cb, | 1003 | &transport_notify_connect_cb, |
733 | &transport_notify_disconnect_cb); | 1004 | &transport_notify_disconnect_cb); |
734 | GNUNET_assert (th != NULL); | 1005 | GNUNET_assert (th != NULL); |
@@ -737,7 +1008,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
737 | &core_init_cb, | 1008 | &core_init_cb, |
738 | &core_connect_cb, | 1009 | &core_connect_cb, |
739 | &core_disconnect_cb, | 1010 | &core_disconnect_cb, |
740 | NULL, GNUNET_NO, | 1011 | &core_notify_receive_cb, GNUNET_NO, |
741 | NULL, GNUNET_NO, | 1012 | NULL, GNUNET_NO, |
742 | NULL); | 1013 | NULL); |
743 | GNUNET_assert (ch != NULL); | 1014 | GNUNET_assert (ch != NULL); |