summaryrefslogtreecommitdiff
path: root/src/rps/test_rps.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r--src/rps/test_rps.c2658
1 files changed, 1354 insertions, 1304 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index 7fc91743b..6bbb4c6ac 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file rps/test_rps.c 21 * @file rps/test_rps.c
22 * @brief Testcase for the random peer sampling service. Starts 22 * @brief Testcase for the random peer sampling service. Starts
@@ -85,8 +85,7 @@ enum PEER_ONLINE_DELTA {
85/** 85/**
86 * Operation map entry 86 * Operation map entry
87 */ 87 */
88struct OpListEntry 88struct OpListEntry {
89{
90 /** 89 /**
91 * DLL next ptr 90 * DLL next ptr
92 */ 91 */
@@ -128,8 +127,7 @@ static struct OpListEntry *oplist_tail;
128/** 127/**
129 * A pending reply: A request was sent and the reply is pending. 128 * A pending reply: A request was sent and the reply is pending.
130 */ 129 */
131struct PendingReply 130struct PendingReply {
132{
133 /** 131 /**
134 * DLL next,prev ptr 132 * DLL next,prev ptr
135 */ 133 */
@@ -151,8 +149,7 @@ struct PendingReply
151/** 149/**
152 * A pending request: A request was not made yet but is scheduled for later. 150 * A pending request: A request was not made yet but is scheduled for later.
153 */ 151 */
154struct PendingRequest 152struct PendingRequest {
155{
156 /** 153 /**
157 * DLL next,prev ptr 154 * DLL next,prev ptr
158 */ 155 */
@@ -174,8 +171,7 @@ struct PendingRequest
174/** 171/**
175 * Information we track for each peer. 172 * Information we track for each peer.
176 */ 173 */
177struct RPSPeer 174struct RPSPeer {
178{
179 /** 175 /**
180 * Index of the peer. 176 * Index of the peer.
181 */ 177 */
@@ -311,8 +307,7 @@ struct RPSPeer
311 uint64_t num_recv_pull_rep; 307 uint64_t num_recv_pull_rep;
312}; 308};
313 309
314enum STAT_TYPE 310enum STAT_TYPE {
315{
316 STAT_TYPE_ROUNDS = 0x1, /* 1 */ 311 STAT_TYPE_ROUNDS = 0x1, /* 1 */
317 STAT_TYPE_BLOCKS = 0x2, /* 2 */ 312 STAT_TYPE_BLOCKS = 0x2, /* 2 */
318 STAT_TYPE_BLOCKS_MANY_PUSH = 0x4, /* 3 */ 313 STAT_TYPE_BLOCKS_MANY_PUSH = 0x4, /* 3 */
@@ -332,8 +327,7 @@ enum STAT_TYPE
332 STAT_TYPE_MAX = 0x80000000, /* 32 */ 327 STAT_TYPE_MAX = 0x80000000, /* 32 */
333}; 328};
334 329
335struct STATcls 330struct STATcls {
336{
337 struct RPSPeer *rps_peer; 331 struct RPSPeer *rps_peer;
338 enum STAT_TYPE stat_type; 332 enum STAT_TYPE stat_type;
339}; 333};
@@ -497,8 +491,7 @@ enum OPTION_COLLECT_VIEW {
497/** 491/**
498 * Structure to define a single test 492 * Structure to define a single test
499 */ 493 */
500struct SingleTestRun 494struct SingleTestRun {
501{
502 /** 495 /**
503 * Name of the test 496 * Name of the test
504 */ 497 */
@@ -585,7 +578,7 @@ static int in_shutdown;
585 * Append arguments to file 578 * Append arguments to file
586 */ 579 */
587static void 580static void
588tofile_ (const char *file_name, const char *line) 581tofile_(const char *file_name, const char *line)
589{ 582{
590 struct GNUNET_DISK_FileHandle *f; 583 struct GNUNET_DISK_FileHandle *f;
591 /* char output_buffer[512]; */ 584 /* char output_buffer[512]; */
@@ -593,69 +586,69 @@ tofile_ (const char *file_name, const char *line)
593 /* int size; */ 586 /* int size; */
594 size_t size2; 587 size_t size2;
595 588
596 if (NULL == (f = GNUNET_DISK_file_open (file_name, 589 if (NULL == (f = GNUNET_DISK_file_open(file_name,
597 GNUNET_DISK_OPEN_APPEND | 590 GNUNET_DISK_OPEN_APPEND |
598 GNUNET_DISK_OPEN_WRITE | 591 GNUNET_DISK_OPEN_WRITE |
599 GNUNET_DISK_OPEN_CREATE, 592 GNUNET_DISK_OPEN_CREATE,
600 GNUNET_DISK_PERM_USER_READ | 593 GNUNET_DISK_PERM_USER_READ |
601 GNUNET_DISK_PERM_USER_WRITE | 594 GNUNET_DISK_PERM_USER_WRITE |
602 GNUNET_DISK_PERM_GROUP_READ | 595 GNUNET_DISK_PERM_GROUP_READ |
603 GNUNET_DISK_PERM_OTHER_READ))) 596 GNUNET_DISK_PERM_OTHER_READ)))
604 { 597 {
605 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 598 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
606 "Not able to open file %s\n", 599 "Not able to open file %s\n",
607 file_name); 600 file_name);
608 return; 601 return;
609 } 602 }
610 /* size = GNUNET_snprintf (output_buffer, 603 /* size = GNUNET_snprintf (output_buffer,
611 sizeof (output_buffer), 604 sizeof (output_buffer),
612 "%llu %s\n", 605 "%llu %s\n",
613 GNUNET_TIME_absolute_get ().abs_value_us, 606 GNUNET_TIME_absolute_get ().abs_value_us,
614 line); 607 line);
615 if (0 > size) 608 if (0 > size)
616 { 609 {
617 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 610 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
618 "Failed to write string to buffer (size: %i)\n", 611 "Failed to write string to buffer (size: %i)\n",
619 size); 612 size);
620 return; 613 return;
621 } */ 614 } */
622 615
623 size = strlen (line) * sizeof (char); 616 size = strlen(line) * sizeof(char);
624 617
625 size2 = GNUNET_DISK_file_write (f, line, size); 618 size2 = GNUNET_DISK_file_write(f, line, size);
626 if (size != size2) 619 if (size != size2)
627 {
628 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
629 "Unable to write to file! (Size: %lu, size2: %lu)\n",
630 size,
631 size2);
632 if (GNUNET_YES != GNUNET_DISK_file_close (f))
633 { 620 {
634 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 621 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
635 "Unable to close file\n"); 622 "Unable to write to file! (Size: %lu, size2: %lu)\n",
623 size,
624 size2);
625 if (GNUNET_YES != GNUNET_DISK_file_close(f))
626 {
627 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
628 "Unable to close file\n");
629 }
630 return;
636 } 631 }
637 return;
638 }
639 632
640 if (GNUNET_YES != GNUNET_DISK_file_close (f)) 633 if (GNUNET_YES != GNUNET_DISK_file_close(f))
641 { 634 {
642 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 635 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
643 "Unable to close file\n"); 636 "Unable to close file\n");
644 } 637 }
645} 638}
646 639
647/** 640/**
648 * This function is used to facilitate writing important information to disk 641 * This function is used to facilitate writing important information to disk
649 */ 642 */
650#define tofile(file_name, ...) do {\ 643#define tofile(file_name, ...) do { \
651 char tmp_buf[512];\ 644 char tmp_buf[512]; \
652 int size;\ 645 int size; \
653 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ 646 size = GNUNET_snprintf(tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \
654 if (0 > size)\ 647 if (0 > size) \
655 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ 648 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
656 "Failed to create tmp_buf\n");\ 649 "Failed to create tmp_buf\n"); \
657 else\ 650 else \
658 tofile_(file_name,tmp_buf);\ 651 tofile_ (file_name, tmp_buf); \
659 } while (0); 652 } while (0);
660 653
661 654
@@ -664,33 +657,33 @@ tofile_ (const char *file_name, const char *line)
664 * Unused 657 * Unused
665 */ 658 */
666/* static void 659/* static void
667ids_to_file (char *file_name, 660 ids_to_file (char *file_name,
668 struct GNUNET_PeerIdentity *peer_ids, 661 struct GNUNET_PeerIdentity *peer_ids,
669 unsigned int num_peer_ids) 662 unsigned int num_peer_ids)
670{ 663 {
671 unsigned int i; 664 unsigned int i;
672 665
673 for (i=0 ; i < num_peer_ids ; i++) 666 for (i=0 ; i < num_peer_ids ; i++)
674 { 667 {
675 to_file (file_name, 668 to_file (file_name,
676 "%u\t%s", 669 "%u\t%s",
677 i, 670 i,
678 GNUNET_i2s_full (&peer_ids[i])); 671 GNUNET_i2s_full (&peer_ids[i]));
679 } 672 }
680} */ 673 } */
681 674
682/** 675/**
683 * Task run on timeout to collect statistics and potentially shut down. 676 * Task run on timeout to collect statistics and potentially shut down.
684 */ 677 */
685static void 678static void
686post_test_op (void *cls); 679post_test_op(void *cls);
687 680
688 681
689/** 682/**
690 * Test the success of a single test 683 * Test the success of a single test
691 */ 684 */
692static int 685static int
693evaluate (void) 686evaluate(void)
694{ 687{
695 unsigned int i; 688 unsigned int i;
696 int tmp_ok; 689 int tmp_ok;
@@ -698,17 +691,17 @@ evaluate (void)
698 tmp_ok = 1; 691 tmp_ok = 1;
699 692
700 for (i = 0; i < num_peers; i++) 693 for (i = 0; i < num_peers; i++)
701 { 694 {
702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 695 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
703 "%u. peer [%s] received %u of %u expected peer_ids: %i\n", 696 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
704 i, 697 i,
705 GNUNET_i2s (rps_peers[i].peer_id), 698 GNUNET_i2s(rps_peers[i].peer_id),
706 rps_peers[i].num_recv_ids, 699 rps_peers[i].num_recv_ids,
707 rps_peers[i].num_ids_to_request, 700 rps_peers[i].num_ids_to_request,
708 (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); 701 (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids));
709 tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); 702 tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids);
710 } 703 }
711 return tmp_ok? 0 : 1; 704 return tmp_ok ? 0 : 1;
712} 705}
713 706
714 707
@@ -716,12 +709,12 @@ evaluate (void)
716 * Creates an oplist entry and adds it to the oplist DLL 709 * Creates an oplist entry and adds it to the oplist DLL
717 */ 710 */
718static struct OpListEntry * 711static struct OpListEntry *
719make_oplist_entry () 712make_oplist_entry()
720{ 713{
721 struct OpListEntry *entry; 714 struct OpListEntry *entry;
722 715
723 entry = GNUNET_new (struct OpListEntry); 716 entry = GNUNET_new(struct OpListEntry);
724 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); 717 GNUNET_CONTAINER_DLL_insert_tail(oplist_head, oplist_tail, entry);
725 return entry; 718 return entry;
726} 719}
727 720
@@ -735,15 +728,15 @@ make_oplist_entry ()
735 * @return #GNUNET_YES if so 728 * @return #GNUNET_YES if so
736 * #GNUNET_NO otherwise 729 * #GNUNET_NO otherwise
737 */ 730 */
738static int check_statistics_collect_completed_single_peer ( 731static int check_statistics_collect_completed_single_peer(
739 const struct RPSPeer *rps_peer) 732 const struct RPSPeer *rps_peer)
740{ 733{
741 if (cur_test_run.stat_collect_flags != 734 if (cur_test_run.stat_collect_flags !=
742 (cur_test_run.stat_collect_flags & 735 (cur_test_run.stat_collect_flags &
743 rps_peer->stat_collected_flags)) 736 rps_peer->stat_collected_flags))
744 { 737 {
745 return GNUNET_NO; 738 return GNUNET_NO;
746 } 739 }
747 return GNUNET_YES; 740 return GNUNET_YES;
748} 741}
749 742
@@ -755,22 +748,22 @@ static int check_statistics_collect_completed_single_peer (
755 * @return #GNUNET_YES if so 748 * @return #GNUNET_YES if so
756 * #GNUNET_NO otherwise 749 * #GNUNET_NO otherwise
757 */ 750 */
758static int check_statistics_collect_completed () 751static int check_statistics_collect_completed()
759{ 752{
760 uint32_t i; 753 uint32_t i;
761 754
762 for (i = 0; i < num_peers; i++) 755 for (i = 0; i < num_peers; i++)
763 {
764 if (GNUNET_NO == check_statistics_collect_completed_single_peer (&rps_peers[i]))
765 { 756 {
766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 757 if (GNUNET_NO == check_statistics_collect_completed_single_peer(&rps_peers[i]))
767 "At least Peer %" PRIu32 " did not yet receive all statistics values\n", 758 {
768 i); 759 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
769 return GNUNET_NO; 760 "At least Peer %" PRIu32 " did not yet receive all statistics values\n",
761 i);
762 return GNUNET_NO;
763 }
770 } 764 }
771 } 765 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 766 "All peers received their statistics values\n");
773 "All peers received their statistics values\n");
774 return GNUNET_YES; 767 return GNUNET_YES;
775} 768}
776 769
@@ -779,35 +772,36 @@ static int check_statistics_collect_completed ()
779 * Task run on timeout to shut everything down. 772 * Task run on timeout to shut everything down.
780 */ 773 */
781static void 774static void
782shutdown_op (void *cls) 775shutdown_op(void *cls)
783{ 776{
784 unsigned int i; 777 unsigned int i;
785 (void) cls;
786 778
787 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 779 (void)cls;
788 "Shutdown task scheduled, going down.\n"); 780
781 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
782 "Shutdown task scheduled, going down.\n");
789 in_shutdown = GNUNET_YES; 783 in_shutdown = GNUNET_YES;
790 if (NULL != post_test_task) 784 if (NULL != post_test_task)
791 { 785 {
792 GNUNET_SCHEDULER_cancel (post_test_task); 786 GNUNET_SCHEDULER_cancel(post_test_task);
793 post_test_op (NULL); 787 post_test_op(NULL);
794 } 788 }
795 if (NULL != churn_task) 789 if (NULL != churn_task)
796 {
797 GNUNET_SCHEDULER_cancel (churn_task);
798 churn_task = NULL;
799 }
800 for (i = 0; i < num_peers; i++)
801 {
802 if (NULL != rps_peers[i].rps_handle)
803 { 790 {
804 GNUNET_RPS_disconnect (rps_peers[i].rps_handle); 791 GNUNET_SCHEDULER_cancel(churn_task);
792 churn_task = NULL;
805 } 793 }
806 if (NULL != rps_peers[i].op) 794 for (i = 0; i < num_peers; i++)
807 { 795 {
808 GNUNET_TESTBED_operation_done (rps_peers[i].op); 796 if (NULL != rps_peers[i].rps_handle)
797 {
798 GNUNET_RPS_disconnect(rps_peers[i].rps_handle);
799 }
800 if (NULL != rps_peers[i].op)
801 {
802 GNUNET_TESTBED_operation_done(rps_peers[i].op);
803 }
809 } 804 }
810 }
811} 805}
812 806
813 807
@@ -815,39 +809,40 @@ shutdown_op (void *cls)
815 * Task run on timeout to collect statistics and potentially shut down. 809 * Task run on timeout to collect statistics and potentially shut down.
816 */ 810 */
817static void 811static void
818post_test_op (void *cls) 812post_test_op(void *cls)
819{ 813{
820 unsigned int i; 814 unsigned int i;
821 (void) cls; 815
816 (void)cls;
822 817
823 post_test_task = NULL; 818 post_test_task = NULL;
824 post_test = GNUNET_YES; 819 post_test = GNUNET_YES;
825 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 820 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
826 "Post test task scheduled, going down.\n"); 821 "Post test task scheduled, going down.\n");
827 if (NULL != churn_task) 822 if (NULL != churn_task)
828 {
829 GNUNET_SCHEDULER_cancel (churn_task);
830 churn_task = NULL;
831 }
832 for (i = 0; i < num_peers; i++)
833 {
834 if (NULL != cur_test_run.post_test)
835 { 823 {
836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); 824 GNUNET_SCHEDULER_cancel(churn_task);
837 cur_test_run.post_test (&rps_peers[i]); 825 churn_task = NULL;
838 } 826 }
839 if (NULL != rps_peers[i].op) 827 for (i = 0; i < num_peers; i++)
840 { 828 {
841 GNUNET_TESTBED_operation_done (rps_peers[i].op); 829 if (NULL != cur_test_run.post_test)
842 rps_peers[i].op = NULL; 830 {
831 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i);
832 cur_test_run.post_test(&rps_peers[i]);
833 }
834 if (NULL != rps_peers[i].op)
835 {
836 GNUNET_TESTBED_operation_done(rps_peers[i].op);
837 rps_peers[i].op = NULL;
838 }
843 } 839 }
844 }
845 /* If we do not collect statistics, shut down directly */ 840 /* If we do not collect statistics, shut down directly */
846 if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics || 841 if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics ||
847 GNUNET_YES == check_statistics_collect_completed()) 842 GNUNET_YES == check_statistics_collect_completed())
848 { 843 {
849 GNUNET_SCHEDULER_shutdown (); 844 GNUNET_SCHEDULER_shutdown();
850 } 845 }
851} 846}
852 847
853 848
@@ -855,29 +850,29 @@ post_test_op (void *cls)
855 * Seed peers. 850 * Seed peers.
856 */ 851 */
857static void 852static void
858seed_peers (void *cls) 853seed_peers(void *cls)
859{ 854{
860 struct RPSPeer *peer = cls; 855 struct RPSPeer *peer = cls;
861 unsigned int amount; 856 unsigned int amount;
862 unsigned int i; 857 unsigned int i;
863 858
864 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 859 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
865 { 860 {
866 return; 861 return;
867 } 862 }
868 863
869 GNUNET_assert (NULL != peer->rps_handle); 864 GNUNET_assert(NULL != peer->rps_handle);
870 865
871 // TODO if malicious don't seed mal peers 866 // TODO if malicious don't seed mal peers
872 amount = round (.5 * num_peers); 867 amount = round(.5 * num_peers);
873 868
874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); 869 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
875 for (i = 0 ; i < amount ; i++) 870 for (i = 0; i < amount; i++)
876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", 871 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
877 i, 872 i,
878 GNUNET_i2s (&rps_peer_ids[i])); 873 GNUNET_i2s(&rps_peer_ids[i]));
879 874
880 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids); 875 GNUNET_RPS_seed_ids(peer->rps_handle, amount, rps_peer_ids);
881} 876}
882 877
883 878
@@ -885,7 +880,7 @@ seed_peers (void *cls)
885 * Seed peers. 880 * Seed peers.
886 */ 881 */
887static void 882static void
888seed_peers_big (void *cls) 883seed_peers_big(void *cls)
889{ 884{
890 struct RPSPeer *peer = cls; 885 struct RPSPeer *peer = cls;
891 unsigned int seed_msg_size; 886 unsigned int seed_msg_size;
@@ -895,71 +890,72 @@ seed_peers_big (void *cls)
895 890
896 seed_msg_size = 8; /* sizeof (struct GNUNET_RPS_CS_SeedMessage) */ 891 seed_msg_size = 8; /* sizeof (struct GNUNET_RPS_CS_SeedMessage) */
897 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - seed_msg_size) / 892 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - seed_msg_size) /
898 sizeof (struct GNUNET_PeerIdentity); 893 sizeof(struct GNUNET_PeerIdentity);
899 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 894 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
900 "Peers that fit in one seed msg; %u\n", 895 "Peers that fit in one seed msg; %u\n",
901 num_peers_max); 896 num_peers_max);
902 amount = num_peers_max + (0.5 * num_peers_max); 897 amount = num_peers_max + (0.5 * num_peers_max);
903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 898 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
904 "Seeding many (%u) peers:\n", 899 "Seeding many (%u) peers:\n",
905 amount); 900 amount);
906 struct GNUNET_PeerIdentity ids_to_seed[amount]; 901 struct GNUNET_PeerIdentity ids_to_seed[amount];
907 for (i = 0; i < amount; i++) 902 for (i = 0; i < amount; i++)
908 { 903 {
909 ids_to_seed[i] = *peer->peer_id; 904 ids_to_seed[i] = *peer->peer_id;
910 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", 905 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
911 i, 906 i,
912 GNUNET_i2s (&ids_to_seed[i])); 907 GNUNET_i2s(&ids_to_seed[i]));
913 } 908 }
914 909
915 GNUNET_RPS_seed_ids (peer->rps_handle, amount, ids_to_seed); 910 GNUNET_RPS_seed_ids(peer->rps_handle, amount, ids_to_seed);
916} 911}
917 912
918/** 913/**
919 * Get the id of peer i. 914 * Get the id of peer i.
920 */ 915 */
921 void 916void
922info_cb (void *cb_cls, 917info_cb(void *cb_cls,
923 struct GNUNET_TESTBED_Operation *op, 918 struct GNUNET_TESTBED_Operation *op,
924 const struct GNUNET_TESTBED_PeerInformation *pinfo, 919 const struct GNUNET_TESTBED_PeerInformation *pinfo,
925 const char *emsg) 920 const char *emsg)
926{ 921{
927 struct OpListEntry *entry = (struct OpListEntry *) cb_cls; 922 struct OpListEntry *entry = (struct OpListEntry *)cb_cls;
928 (void) op; 923
924 (void)op;
929 925
930 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 926 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
931 { 927 {
932 return; 928 return;
933 } 929 }
934 930
935 if (NULL == pinfo || NULL != emsg) 931 if (NULL == pinfo || NULL != emsg)
936 { 932 {
937 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); 933 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
938 GNUNET_TESTBED_operation_done (entry->op); 934 GNUNET_TESTBED_operation_done(entry->op);
939 return; 935 return;
940 } 936 }
941 937
942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 938 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
943 "Peer %u is %s\n", 939 "Peer %u is %s\n",
944 entry->index, 940 entry->index,
945 GNUNET_i2s (pinfo->result.id)); 941 GNUNET_i2s(pinfo->result.id));
946 942
947 rps_peer_ids[entry->index] = *(pinfo->result.id); 943 rps_peer_ids[entry->index] = *(pinfo->result.id);
948 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; 944 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
949 945
950 GNUNET_assert (GNUNET_OK == 946 GNUNET_assert(GNUNET_OK ==
951 GNUNET_CONTAINER_multipeermap_put (peer_map, 947 GNUNET_CONTAINER_multipeermap_put(peer_map,
952 &rps_peer_ids[entry->index], 948 &rps_peer_ids[entry->index],
953 &rps_peers[entry->index], 949 &rps_peers[entry->index],
954 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 950 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
955 tofile ("/tmp/rps/peer_ids", 951 tofile("/tmp/rps/peer_ids",
956 "%u\t%s\n", 952 "%u\t%s\n",
957 entry->index, 953 entry->index,
958 GNUNET_i2s_full (&rps_peer_ids[entry->index])); 954 GNUNET_i2s_full(&rps_peer_ids[entry->index]));
959 955
960 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); 956 GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry);
961 GNUNET_TESTBED_operation_done (entry->op); 957 GNUNET_TESTBED_operation_done(entry->op);
962 GNUNET_free (entry); 958 GNUNET_free(entry);
963} 959}
964 960
965 961
@@ -973,39 +969,39 @@ info_cb (void *cb_cls,
973 * operation has executed successfully. 969 * operation has executed successfully.
974 */ 970 */
975static void 971static void
976rps_connect_complete_cb (void *cls, 972rps_connect_complete_cb(void *cls,
977 struct GNUNET_TESTBED_Operation *op, 973 struct GNUNET_TESTBED_Operation *op,
978 void *ca_result, 974 void *ca_result,
979 const char *emsg) 975 const char *emsg)
980{ 976{
981 struct RPSPeer *rps_peer = cls; 977 struct RPSPeer *rps_peer = cls;
982 struct GNUNET_RPS_Handle *rps = ca_result; 978 struct GNUNET_RPS_Handle *rps = ca_result;
983 979
984 GNUNET_assert (NULL != ca_result); 980 GNUNET_assert(NULL != ca_result);
985 981
986 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 982 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
987 { 983 {
988 return; 984 return;
989 } 985 }
990 986
991 rps_peer->rps_handle = rps; 987 rps_peer->rps_handle = rps;
992 rps_peer->online = GNUNET_YES; 988 rps_peer->online = GNUNET_YES;
993 num_peers_online++; 989 num_peers_online++;
994 990
995 GNUNET_assert (op == rps_peer->op); 991 GNUNET_assert(op == rps_peer->op);
996 if (NULL != emsg) 992 if (NULL != emsg)
997 { 993 {
998 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 994 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
999 "Failed to connect to RPS service: %s\n", 995 "Failed to connect to RPS service: %s\n",
1000 emsg); 996 emsg);
1001 ok = 1; 997 ok = 1;
1002 GNUNET_SCHEDULER_shutdown (); 998 GNUNET_SCHEDULER_shutdown();
1003 return; 999 return;
1004 } 1000 }
1005 1001
1006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); 1002 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
1007 1003
1008 cur_test_run.main_test (rps_peer); 1004 cur_test_run.main_test(rps_peer);
1009} 1005}
1010 1006
1011 1007
@@ -1020,17 +1016,17 @@ rps_connect_complete_cb (void *cls,
1020 * @return service handle to return in 'op_result', NULL on error 1016 * @return service handle to return in 'op_result', NULL on error
1021 */ 1017 */
1022static void * 1018static void *
1023rps_connect_adapter (void *cls, 1019rps_connect_adapter(void *cls,
1024 const struct GNUNET_CONFIGURATION_Handle *cfg) 1020 const struct GNUNET_CONFIGURATION_Handle *cfg)
1025{ 1021{
1026 struct GNUNET_RPS_Handle *h; 1022 struct GNUNET_RPS_Handle *h;
1027 1023
1028 h = GNUNET_RPS_connect (cfg); 1024 h = GNUNET_RPS_connect(cfg);
1029 GNUNET_assert (NULL != h); 1025 GNUNET_assert(NULL != h);
1030 1026
1031 if (NULL != cur_test_run.pre_test) 1027 if (NULL != cur_test_run.pre_test)
1032 cur_test_run.pre_test (cls, h); 1028 cur_test_run.pre_test(cls, h);
1033 GNUNET_assert (NULL != h); 1029 GNUNET_assert(NULL != h);
1034 1030
1035 return h; 1031 return h;
1036} 1032}
@@ -1045,12 +1041,12 @@ rps_connect_adapter (void *cls,
1045 * @return service handle to return in 'op_result', NULL on error 1041 * @return service handle to return in 'op_result', NULL on error
1046 */ 1042 */
1047static void * 1043static void *
1048stat_connect_adapter (void *cls, 1044stat_connect_adapter(void *cls,
1049 const struct GNUNET_CONFIGURATION_Handle *cfg) 1045 const struct GNUNET_CONFIGURATION_Handle *cfg)
1050{ 1046{
1051 struct RPSPeer *peer = cls; 1047 struct RPSPeer *peer = cls;
1052 1048
1053 peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg); 1049 peer->stats_h = GNUNET_STATISTICS_create("rps-profiler", cfg);
1054 return peer->stats_h; 1050 return peer->stats_h;
1055} 1051}
1056 1052
@@ -1061,7 +1057,7 @@ stat_connect_adapter (void *cls,
1061 * @param op_result service handle returned from the connect adapter 1057 * @param op_result service handle returned from the connect adapter
1062 */ 1058 */
1063static void 1059static void
1064stat_disconnect_adapter (void *cls, void *op_result) 1060stat_disconnect_adapter(void *cls, void *op_result)
1065{ 1061{
1066 struct RPSPeer *peer = cls; 1062 struct RPSPeer *peer = cls;
1067 1063
@@ -1071,7 +1067,7 @@ stat_disconnect_adapter (void *cls, void *op_result)
1071 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel 1067 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
1072 // (peer->stats_h, "nse", "# peers connected", 1068 // (peer->stats_h, "nse", "# peers connected",
1073 // stat_iterator, peer)); 1069 // stat_iterator, peer));
1074 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); 1070 GNUNET_STATISTICS_destroy(op_result, GNUNET_NO);
1075 peer->stats_h = NULL; 1071 peer->stats_h = NULL;
1076} 1072}
1077 1073
@@ -1086,20 +1082,20 @@ stat_disconnect_adapter (void *cls, void *op_result)
1086 * operation has executed successfully. 1082 * operation has executed successfully.
1087 */ 1083 */
1088static void 1084static void
1089stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op, 1085stat_complete_cb(void *cls, struct GNUNET_TESTBED_Operation *op,
1090 void *ca_result, const char *emsg ) 1086 void *ca_result, const char *emsg)
1091{ 1087{
1092 //struct GNUNET_STATISTICS_Handle *sh = ca_result; 1088 //struct GNUNET_STATISTICS_Handle *sh = ca_result;
1093 //struct RPSPeer *peer = (struct RPSPeer *) cls; 1089 //struct RPSPeer *peer = (struct RPSPeer *) cls;
1094 (void) cls; 1090 (void)cls;
1095 (void) op; 1091 (void)op;
1096 (void) ca_result; 1092 (void)ca_result;
1097 1093
1098 if (NULL != emsg) 1094 if (NULL != emsg)
1099 { 1095 {
1100 GNUNET_break (0); 1096 GNUNET_break(0);
1101 return; 1097 return;
1102 } 1098 }
1103 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch 1099 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1104 // (sh, "core", "# peers connected", 1100 // (sh, "core", "# peers connected",
1105 // stat_iterator, peer)); 1101 // stat_iterator, peer));
@@ -1117,36 +1113,36 @@ stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
1117 * @param op_result service handle returned from the connect adapter 1113 * @param op_result service handle returned from the connect adapter
1118 */ 1114 */
1119static void 1115static void
1120rps_disconnect_adapter (void *cls, 1116rps_disconnect_adapter(void *cls,
1121 void *op_result) 1117 void *op_result)
1122{ 1118{
1123 struct RPSPeer *peer = cls; 1119 struct RPSPeer *peer = cls;
1124 struct GNUNET_RPS_Handle *h = op_result; 1120 struct GNUNET_RPS_Handle *h = op_result;
1125 1121
1126 if (NULL != peer->rps_srh) 1122 if (NULL != peer->rps_srh)
1127 { 1123 {
1128 GNUNET_RPS_stream_cancel (peer->rps_srh); 1124 GNUNET_RPS_stream_cancel(peer->rps_srh);
1129 peer->rps_srh = NULL; 1125 peer->rps_srh = NULL;
1130 } 1126 }
1131 GNUNET_assert (NULL != peer); 1127 GNUNET_assert(NULL != peer);
1132 GNUNET_RPS_disconnect (h); 1128 GNUNET_RPS_disconnect(h);
1133 peer->rps_handle = NULL; 1129 peer->rps_handle = NULL;
1134} 1130}
1135 1131
1136 1132
1137/*********************************************************************** 1133/***********************************************************************
1138 * Definition of tests 1134* Definition of tests
1139***********************************************************************/ 1135***********************************************************************/
1140 1136
1141// TODO check whether tests can be stopped earlier 1137// TODO check whether tests can be stopped earlier
1142static int 1138static int
1143default_eval_cb (void) 1139default_eval_cb(void)
1144{ 1140{
1145 return evaluate (); 1141 return evaluate();
1146} 1142}
1147 1143
1148static int 1144static int
1149no_eval (void) 1145no_eval(void)
1150{ 1146{
1151 return 0; 1147 return 0;
1152} 1148}
@@ -1154,7 +1150,7 @@ no_eval (void)
1154/** 1150/**
1155 * Initialise given RPSPeer 1151 * Initialise given RPSPeer
1156 */ 1152 */
1157static void default_init_peer (struct RPSPeer *rps_peer) 1153static void default_init_peer(struct RPSPeer *rps_peer)
1158{ 1154{
1159 rps_peer->num_ids_to_request = 1; 1155 rps_peer->num_ids_to_request = 1;
1160} 1156}
@@ -1167,49 +1163,49 @@ static void default_init_peer (struct RPSPeer *rps_peer)
1167 * @param recv_peers the received peers 1163 * @param recv_peers the received peers
1168 */ 1164 */
1169static void 1165static void
1170default_reply_handle (void *cls, 1166default_reply_handle(void *cls,
1171 uint64_t n, 1167 uint64_t n,
1172 const struct GNUNET_PeerIdentity *recv_peers) 1168 const struct GNUNET_PeerIdentity *recv_peers)
1173{ 1169{
1174 struct RPSPeer *rps_peer; 1170 struct RPSPeer *rps_peer;
1175 struct PendingReply *pending_rep = (struct PendingReply *) cls; 1171 struct PendingReply *pending_rep = (struct PendingReply *)cls;
1176 unsigned int i; 1172 unsigned int i;
1177 1173
1178 rps_peer = pending_rep->rps_peer; 1174 rps_peer = pending_rep->rps_peer;
1179 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, 1175 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head,
1180 rps_peer->pending_rep_tail, 1176 rps_peer->pending_rep_tail,
1181 pending_rep); 1177 pending_rep);
1182 rps_peer->num_pending_reps--; 1178 rps_peer->num_pending_reps--;
1183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1179 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1184 "[%s] got %" PRIu64 " peers:\n", 1180 "[%s] got %" PRIu64 " peers:\n",
1185 GNUNET_i2s (rps_peer->peer_id), 1181 GNUNET_i2s(rps_peer->peer_id),
1186 n); 1182 n);
1187 1183
1188 for (i = 0; i < n; i++) 1184 for (i = 0; i < n; i++)
1189 { 1185 {
1190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1186 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1191 "%u: %s\n", 1187 "%u: %s\n",
1192 i, 1188 i,
1193 GNUNET_i2s (&recv_peers[i])); 1189 GNUNET_i2s(&recv_peers[i]));
1194 1190
1195 rps_peer->num_recv_ids++; 1191 rps_peer->num_recv_ids++;
1196 } 1192 }
1197 1193
1198 if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) 1194 if (0 == evaluate() && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit)
1199 { 1195 {
1200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); 1196 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n");
1201 GNUNET_assert (NULL != post_test_task); 1197 GNUNET_assert(NULL != post_test_task);
1202 GNUNET_SCHEDULER_cancel (post_test_task); 1198 GNUNET_SCHEDULER_cancel(post_test_task);
1203 post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); 1199 post_test_task = GNUNET_SCHEDULER_add_now(&post_test_op, NULL);
1204 GNUNET_assert (NULL!= post_test_task); 1200 GNUNET_assert(NULL != post_test_task);
1205 } 1201 }
1206} 1202}
1207 1203
1208/** 1204/**
1209 * Request random peers. 1205 * Request random peers.
1210 */ 1206 */
1211static void 1207static void
1212request_peers (void *cls) 1208request_peers(void *cls)
1213{ 1209{
1214 struct PendingRequest *pending_req = cls; 1210 struct PendingRequest *pending_req = cls;
1215 struct RPSPeer *rps_peer; 1211 struct RPSPeer *rps_peer;
@@ -1218,62 +1214,62 @@ request_peers (void *cls)
1218 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1214 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1219 return; 1215 return;
1220 rps_peer = pending_req->rps_peer; 1216 rps_peer = pending_req->rps_peer;
1221 GNUNET_assert (1 <= rps_peer->num_pending_reqs); 1217 GNUNET_assert(1 <= rps_peer->num_pending_reqs);
1222 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, 1218 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head,
1223 rps_peer->pending_req_tail, 1219 rps_peer->pending_req_tail,
1224 pending_req); 1220 pending_req);
1225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1226 "Requesting one peer\n"); 1222 "Requesting one peer\n");
1227 pending_rep = GNUNET_new (struct PendingReply); 1223 pending_rep = GNUNET_new(struct PendingReply);
1228 pending_rep->rps_peer = rps_peer; 1224 pending_rep->rps_peer = rps_peer;
1229 pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, 1225 pending_rep->req_handle = GNUNET_RPS_request_peers(rps_peer->rps_handle,
1230 1, 1226 1,
1231 cur_test_run.reply_handle, 1227 cur_test_run.reply_handle,
1232 pending_rep); 1228 pending_rep);
1233 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head, 1229 GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_rep_head,
1234 rps_peer->pending_rep_tail, 1230 rps_peer->pending_rep_tail,
1235 pending_rep); 1231 pending_rep);
1236 rps_peer->num_pending_reps++; 1232 rps_peer->num_pending_reps++;
1237 rps_peer->num_pending_reqs--; 1233 rps_peer->num_pending_reqs--;
1238} 1234}
1239 1235
1240static void 1236static void
1241cancel_pending_req (struct PendingRequest *pending_req) 1237cancel_pending_req(struct PendingRequest *pending_req)
1242{ 1238{
1243 struct RPSPeer *rps_peer; 1239 struct RPSPeer *rps_peer;
1244 1240
1245 rps_peer = pending_req->rps_peer; 1241 rps_peer = pending_req->rps_peer;
1246 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, 1242 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head,
1247 rps_peer->pending_req_tail, 1243 rps_peer->pending_req_tail,
1248 pending_req); 1244 pending_req);
1249 rps_peer->num_pending_reqs--; 1245 rps_peer->num_pending_reqs--;
1250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1251 "Cancelling pending request\n"); 1247 "Cancelling pending request\n");
1252 GNUNET_SCHEDULER_cancel (pending_req->request_task); 1248 GNUNET_SCHEDULER_cancel(pending_req->request_task);
1253 GNUNET_free (pending_req); 1249 GNUNET_free(pending_req);
1254} 1250}
1255 1251
1256static void 1252static void
1257cancel_request (struct PendingReply *pending_rep) 1253cancel_request(struct PendingReply *pending_rep)
1258{ 1254{
1259 struct RPSPeer *rps_peer; 1255 struct RPSPeer *rps_peer;
1260 1256
1261 rps_peer = pending_rep->rps_peer; 1257 rps_peer = pending_rep->rps_peer;
1262 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, 1258 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head,
1263 rps_peer->pending_rep_tail, 1259 rps_peer->pending_rep_tail,
1264 pending_rep); 1260 pending_rep);
1265 rps_peer->num_pending_reps--; 1261 rps_peer->num_pending_reps--;
1266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1262 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1267 "Cancelling request\n"); 1263 "Cancelling request\n");
1268 GNUNET_RPS_request_cancel (pending_rep->req_handle); 1264 GNUNET_RPS_request_cancel(pending_rep->req_handle);
1269 GNUNET_free (pending_rep); 1265 GNUNET_free(pending_rep);
1270} 1266}
1271 1267
1272/** 1268/**
1273 * Cancel a request. 1269 * Cancel a request.
1274 */ 1270 */
1275static void 1271static void
1276cancel_request_cb (void *cls) 1272cancel_request_cb(void *cls)
1277{ 1273{
1278 struct RPSPeer *rps_peer = cls; 1274 struct RPSPeer *rps_peer = cls;
1279 struct PendingReply *pending_rep; 1275 struct PendingReply *pending_rep;
@@ -1281,8 +1277,8 @@ cancel_request_cb (void *cls)
1281 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1277 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1282 return; 1278 return;
1283 pending_rep = rps_peer->pending_rep_head; 1279 pending_rep = rps_peer->pending_rep_head;
1284 GNUNET_assert (1 <= rps_peer->num_pending_reps); 1280 GNUNET_assert(1 <= rps_peer->num_pending_reps);
1285 cancel_request (pending_rep); 1281 cancel_request(pending_rep);
1286} 1282}
1287 1283
1288 1284
@@ -1291,57 +1287,57 @@ cancel_request_cb (void *cls)
1291 * issued, nor replied 1287 * issued, nor replied
1292 */ 1288 */
1293void 1289void
1294schedule_missing_requests (struct RPSPeer *rps_peer) 1290schedule_missing_requests(struct RPSPeer *rps_peer)
1295{ 1291{
1296 unsigned int i; 1292 unsigned int i;
1297 struct PendingRequest *pending_req; 1293 struct PendingRequest *pending_req;
1298 1294
1299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1295 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1300 "Scheduling %u - %u missing requests\n", 1296 "Scheduling %u - %u missing requests\n",
1301 rps_peer->num_ids_to_request, 1297 rps_peer->num_ids_to_request,
1302 rps_peer->num_pending_reqs + rps_peer->num_pending_reps); 1298 rps_peer->num_pending_reqs + rps_peer->num_pending_reps);
1303 GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= 1299 GNUNET_assert(rps_peer->num_pending_reqs + rps_peer->num_pending_reps <=
1304 rps_peer->num_ids_to_request); 1300 rps_peer->num_ids_to_request);
1305 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; 1301 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps;
1306 i < rps_peer->num_ids_to_request; i++) 1302 i < rps_peer->num_ids_to_request; i++)
1307 { 1303 {
1308 pending_req = GNUNET_new (struct PendingRequest); 1304 pending_req = GNUNET_new(struct PendingRequest);
1309 pending_req->rps_peer = rps_peer; 1305 pending_req->rps_peer = rps_peer;
1310 pending_req->request_task = GNUNET_SCHEDULER_add_delayed ( 1306 pending_req->request_task = GNUNET_SCHEDULER_add_delayed(
1311 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1307 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
1312 cur_test_run.request_interval * i), 1308 cur_test_run.request_interval * i),
1313 request_peers, 1309 request_peers,
1314 pending_req); 1310 pending_req);
1315 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head, 1311 GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_req_head,
1316 rps_peer->pending_req_tail, 1312 rps_peer->pending_req_tail,
1317 pending_req); 1313 pending_req);
1318 rps_peer->num_pending_reqs++; 1314 rps_peer->num_pending_reqs++;
1319 } 1315 }
1320} 1316}
1321 1317
1322void 1318void
1323cancel_pending_req_rep (struct RPSPeer *rps_peer) 1319cancel_pending_req_rep(struct RPSPeer *rps_peer)
1324{ 1320{
1325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1321 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1326 "Cancelling all (pending) requests.\n"); 1322 "Cancelling all (pending) requests.\n");
1327 while (NULL != rps_peer->pending_req_head) 1323 while (NULL != rps_peer->pending_req_head)
1328 cancel_pending_req (rps_peer->pending_req_head); 1324 cancel_pending_req(rps_peer->pending_req_head);
1329 GNUNET_assert (0 == rps_peer->num_pending_reqs); 1325 GNUNET_assert(0 == rps_peer->num_pending_reqs);
1330 while (NULL != rps_peer->pending_rep_head) 1326 while (NULL != rps_peer->pending_rep_head)
1331 cancel_request (rps_peer->pending_rep_head); 1327 cancel_request(rps_peer->pending_rep_head);
1332 GNUNET_assert (0 == rps_peer->num_pending_reps); 1328 GNUNET_assert(0 == rps_peer->num_pending_reps);
1333} 1329}
1334 1330
1335/*********************************** 1331/***********************************
1336 * MALICIOUS 1332* MALICIOUS
1337***********************************/ 1333***********************************/
1338 1334
1339/** 1335/**
1340 * Initialise only non-mal RPSPeers 1336 * Initialise only non-mal RPSPeers
1341 */ 1337 */
1342static void mal_init_peer (struct RPSPeer *rps_peer) 1338static void mal_init_peer(struct RPSPeer *rps_peer)
1343{ 1339{
1344 if (rps_peer->index >= round (portion * num_peers)) 1340 if (rps_peer->index >= round(portion * num_peers))
1345 rps_peer->num_ids_to_request = 1; 1341 rps_peer->num_ids_to_request = 1;
1346} 1342}
1347 1343
@@ -1355,169 +1351,169 @@ static void mal_init_peer (struct RPSPeer *rps_peer)
1355 * @param h the handle to the service 1351 * @param h the handle to the service
1356 */ 1352 */
1357static void 1353static void
1358mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 1354mal_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1359{ 1355{
1360 #if ENABLE_MALICIOUS 1356 #if ENABLE_MALICIOUS
1361 uint32_t num_mal_peers; 1357 uint32_t num_mal_peers;
1362 1358
1363 GNUNET_assert ( (1 >= portion) && 1359 GNUNET_assert((1 >= portion) &&
1364 (0 < portion) ); 1360 (0 < portion));
1365 num_mal_peers = round (portion * num_peers); 1361 num_mal_peers = round(portion * num_peers);
1366 1362
1367 if (rps_peer->index < num_mal_peers) 1363 if (rps_peer->index < num_mal_peers)
1368 { 1364 {
1369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1365 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1370 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", 1366 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
1371 rps_peer->index, 1367 rps_peer->index,
1372 GNUNET_i2s (rps_peer->peer_id), 1368 GNUNET_i2s(rps_peer->peer_id),
1373 num_mal_peers); 1369 num_mal_peers);
1374 1370
1375 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, 1371 GNUNET_RPS_act_malicious(h, mal_type, num_mal_peers,
1376 rps_peer_ids, target_peer); 1372 rps_peer_ids, target_peer);
1377 } 1373 }
1378 #endif /* ENABLE_MALICIOUS */ 1374 #endif /* ENABLE_MALICIOUS */
1379} 1375}
1380 1376
1381static void 1377static void
1382mal_cb (struct RPSPeer *rps_peer) 1378mal_cb(struct RPSPeer *rps_peer)
1383{ 1379{
1384 uint32_t num_mal_peers; 1380 uint32_t num_mal_peers;
1385 1381
1386 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1382 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1387 { 1383 {
1388 return; 1384 return;
1389 } 1385 }
1390 1386
1391 #if ENABLE_MALICIOUS 1387 #if ENABLE_MALICIOUS
1392 GNUNET_assert ( (1 >= portion) && 1388 GNUNET_assert((1 >= portion) &&
1393 (0 < portion) ); 1389 (0 < portion));
1394 num_mal_peers = round (portion * num_peers); 1390 num_mal_peers = round(portion * num_peers);
1395 1391
1396 if (rps_peer->index >= num_mal_peers) 1392 if (rps_peer->index >= num_mal_peers)
1397 { /* It's useless to ask a malicious peer about a random sample - 1393 { /* It's useless to ask a malicious peer about a random sample -
1398 it's not sampling */ 1394 it's not sampling */
1399 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), 1395 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
1400 seed_peers, rps_peer); 1396 seed_peers, rps_peer);
1401 schedule_missing_requests (rps_peer); 1397 schedule_missing_requests(rps_peer);
1402 } 1398 }
1403 #endif /* ENABLE_MALICIOUS */ 1399 #endif /* ENABLE_MALICIOUS */
1404} 1400}
1405 1401
1406 1402
1407/*********************************** 1403/***********************************
1408 * SINGLE_REQUEST 1404* SINGLE_REQUEST
1409***********************************/ 1405***********************************/
1410static void 1406static void
1411single_req_cb (struct RPSPeer *rps_peer) 1407single_req_cb(struct RPSPeer *rps_peer)
1412{ 1408{
1413 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1409 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1414 { 1410 {
1415 return; 1411 return;
1416 } 1412 }
1417 1413
1418 schedule_missing_requests (rps_peer); 1414 schedule_missing_requests(rps_peer);
1419} 1415}
1420 1416
1421/*********************************** 1417/***********************************
1422 * DELAYED_REQUESTS 1418* DELAYED_REQUESTS
1423***********************************/ 1419***********************************/
1424static void 1420static void
1425delay_req_cb (struct RPSPeer *rps_peer) 1421delay_req_cb(struct RPSPeer *rps_peer)
1426{ 1422{
1427 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1423 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1428 { 1424 {
1429 return; 1425 return;
1430 } 1426 }
1431 1427
1432 schedule_missing_requests (rps_peer); 1428 schedule_missing_requests(rps_peer);
1433} 1429}
1434 1430
1435/*********************************** 1431/***********************************
1436 * SEED 1432* SEED
1437***********************************/ 1433***********************************/
1438static void 1434static void
1439seed_cb (struct RPSPeer *rps_peer) 1435seed_cb(struct RPSPeer *rps_peer)
1440{ 1436{
1441 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1437 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1442 { 1438 {
1443 return; 1439 return;
1444 } 1440 }
1445 1441
1446 GNUNET_SCHEDULER_add_delayed ( 1442 GNUNET_SCHEDULER_add_delayed(
1447 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 1443 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
1448 seed_peers, rps_peer); 1444 seed_peers, rps_peer);
1449} 1445}
1450 1446
1451/*********************************** 1447/***********************************
1452 * SEED_BIG 1448* SEED_BIG
1453***********************************/ 1449***********************************/
1454static void 1450static void
1455seed_big_cb (struct RPSPeer *rps_peer) 1451seed_big_cb(struct RPSPeer *rps_peer)
1456{ 1452{
1457 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1453 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1458 { 1454 {
1459 return; 1455 return;
1460 } 1456 }
1461 1457
1462 // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers 1458 // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers
1463 GNUNET_SCHEDULER_add_delayed ( 1459 GNUNET_SCHEDULER_add_delayed(
1464 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), 1460 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
1465 seed_peers_big, rps_peer); 1461 seed_peers_big, rps_peer);
1466} 1462}
1467 1463
1468/*********************************** 1464/***********************************
1469 * SINGLE_PEER_SEED 1465* SINGLE_PEER_SEED
1470***********************************/ 1466***********************************/
1471static void 1467static void
1472single_peer_seed_cb (struct RPSPeer *rps_peer) 1468single_peer_seed_cb(struct RPSPeer *rps_peer)
1473{ 1469{
1474 (void) rps_peer; 1470 (void)rps_peer;
1475 // TODO 1471 // TODO
1476} 1472}
1477 1473
1478/*********************************** 1474/***********************************
1479 * SEED_REQUEST 1475* SEED_REQUEST
1480***********************************/ 1476***********************************/
1481static void 1477static void
1482seed_req_cb (struct RPSPeer *rps_peer) 1478seed_req_cb(struct RPSPeer *rps_peer)
1483{ 1479{
1484 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1480 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1485 { 1481 {
1486 return; 1482 return;
1487 } 1483 }
1488 1484
1489 GNUNET_SCHEDULER_add_delayed ( 1485 GNUNET_SCHEDULER_add_delayed(
1490 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), 1486 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
1491 seed_peers, rps_peer); 1487 seed_peers, rps_peer);
1492 schedule_missing_requests (rps_peer); 1488 schedule_missing_requests(rps_peer);
1493} 1489}
1494 1490
1495//TODO start big mal 1491//TODO start big mal
1496 1492
1497/*********************************** 1493/***********************************
1498 * REQUEST_CANCEL 1494* REQUEST_CANCEL
1499***********************************/ 1495***********************************/
1500static void 1496static void
1501req_cancel_cb (struct RPSPeer *rps_peer) 1497req_cancel_cb(struct RPSPeer *rps_peer)
1502{ 1498{
1503 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1499 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1504 { 1500 {
1505 return; 1501 return;
1506 } 1502 }
1507 1503
1508 schedule_missing_requests (rps_peer); 1504 schedule_missing_requests(rps_peer);
1509 GNUNET_SCHEDULER_add_delayed ( 1505 GNUNET_SCHEDULER_add_delayed(
1510 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1506 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
1511 (cur_test_run.request_interval + 1)), 1507 (cur_test_run.request_interval + 1)),
1512 cancel_request_cb, rps_peer); 1508 cancel_request_cb, rps_peer);
1513} 1509}
1514 1510
1515/*********************************** 1511/***********************************
1516 * CHURN 1512* CHURN
1517***********************************/ 1513***********************************/
1518 1514
1519static void 1515static void
1520churn (void *cls); 1516churn(void *cls);
1521 1517
1522/** 1518/**
1523 * @brief Starts churn 1519 * @brief Starts churn
@@ -1531,89 +1527,95 @@ churn (void *cls);
1531 * @param rps_peer The peer it's called for 1527 * @param rps_peer The peer it's called for
1532 */ 1528 */
1533static void 1529static void
1534churn_test_cb (struct RPSPeer *rps_peer) 1530churn_test_cb(struct RPSPeer *rps_peer)
1535{ 1531{
1536 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1532 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1537 { 1533 {
1538 return; 1534 return;
1539 } 1535 }
1540 1536
1541 /* Start churn */ 1537 /* Start churn */
1542 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) 1538 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task)
1543 { 1539 {
1544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1540 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1545 "Starting churn task\n"); 1541 "Starting churn task\n");
1546 churn_task = GNUNET_SCHEDULER_add_delayed ( 1542 churn_task = GNUNET_SCHEDULER_add_delayed(
1547 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), 1543 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
1548 churn, 1544 churn,
1549 NULL); 1545 NULL);
1550 } else { 1546 }
1551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1547 else
1552 "Not starting churn task\n"); 1548 {
1553 } 1549 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1550 "Not starting churn task\n");
1551 }
1554 1552
1555 schedule_missing_requests (rps_peer); 1553 schedule_missing_requests(rps_peer);
1556} 1554}
1557 1555
1558/*********************************** 1556/***********************************
1559 * SUB 1557* SUB
1560***********************************/ 1558***********************************/
1561 1559
1562static void 1560static void
1563got_stream_peer_cb (void *cls, 1561got_stream_peer_cb(void *cls,
1564 uint64_t num_peers, 1562 uint64_t num_peers,
1565 const struct GNUNET_PeerIdentity *peers) 1563 const struct GNUNET_PeerIdentity *peers)
1566{ 1564{
1567 const struct RPSPeer *rps_peer = cls; 1565 const struct RPSPeer *rps_peer = cls;
1568 1566
1569 for (uint64_t i = 0; i < num_peers; i++) 1567 for (uint64_t i = 0; i < num_peers; i++)
1570 {
1571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1572 "Peer %" PRIu32 " received [%s] from stream.\n",
1573 rps_peer->index,
1574 GNUNET_i2s (&peers[i]));
1575 if (0 != rps_peer->index &&
1576 0 == memcmp (&peers[i],
1577 &rps_peers[0].peer_id,
1578 sizeof (struct GNUNET_PeerIdentity)))
1579 {
1580 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub\n");
1581 ok = 1;
1582 }
1583 else if (0 == rps_peer->index &&
1584 0 != memcmp (&peers[i],
1585 &rps_peers[0].peer_id,
1586 sizeof (struct GNUNET_PeerIdentity)))
1587 { 1568 {
1588 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub (lonely)\n"); 1569 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1589 ok = 1; 1570 "Peer %" PRIu32 " received [%s] from stream.\n",
1571 rps_peer->index,
1572 GNUNET_i2s(&peers[i]));
1573 if (0 != rps_peer->index &&
1574 0 == memcmp(&peers[i],
1575 &rps_peers[0].peer_id,
1576 sizeof(struct GNUNET_PeerIdentity)))
1577 {
1578 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub\n");
1579 ok = 1;
1580 }
1581 else if (0 == rps_peer->index &&
1582 0 != memcmp(&peers[i],
1583 &rps_peers[0].peer_id,
1584 sizeof(struct GNUNET_PeerIdentity)))
1585 {
1586 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub (lonely)\n");
1587 ok = 1;
1588 }
1590 } 1589 }
1591 }
1592} 1590}
1593 1591
1594 1592
1595static void 1593static void
1596sub_post (struct RPSPeer *rps_peer) 1594sub_post(struct RPSPeer *rps_peer)
1597{ 1595{
1598 if (0 != rps_peer->index) GNUNET_RPS_sub_stop (rps_peer->rps_handle, "test"); 1596 if (0 != rps_peer->index)
1599 else GNUNET_RPS_sub_stop (rps_peer->rps_handle, "lonely"); 1597 GNUNET_RPS_sub_stop(rps_peer->rps_handle, "test");
1598 else
1599 GNUNET_RPS_sub_stop(rps_peer->rps_handle, "lonely");
1600} 1600}
1601 1601
1602 1602
1603static void 1603static void
1604sub_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 1604sub_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1605{ 1605{
1606 (void) rps_peer; 1606 (void)rps_peer;
1607 1607
1608 if (0 != rps_peer->index) GNUNET_RPS_sub_start (h, "test"); 1608 if (0 != rps_peer->index)
1609 else GNUNET_RPS_sub_start (h, "lonely"); /* have a group of one */ 1609 GNUNET_RPS_sub_start(h, "test");
1610 rps_peer->rps_srh = GNUNET_RPS_stream_request (h, 1610 else
1611 &got_stream_peer_cb, 1611 GNUNET_RPS_sub_start(h, "lonely"); /* have a group of one */
1612 rps_peer); 1612 rps_peer->rps_srh = GNUNET_RPS_stream_request(h,
1613 &got_stream_peer_cb,
1614 rps_peer);
1613} 1615}
1614 1616
1615/*********************************** 1617/***********************************
1616 * PROFILER 1618* PROFILER
1617***********************************/ 1619***********************************/
1618 1620
1619/** 1621/**
@@ -1624,81 +1626,81 @@ sub_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1624 * @param emsg NULL on success; otherwise an error description 1626 * @param emsg NULL on success; otherwise an error description
1625 */ 1627 */
1626static void 1628static void
1627churn_cb (void *cls, 1629churn_cb(void *cls,
1628 struct GNUNET_TESTBED_Operation *op, 1630 struct GNUNET_TESTBED_Operation *op,
1629 const char *emsg) 1631 const char *emsg)
1630{ 1632{
1631 (void) op; 1633 (void)op;
1632 // FIXME 1634 // FIXME
1633 struct OpListEntry *entry = cls; 1635 struct OpListEntry *entry = cls;
1634 1636
1635 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1637 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1636 { 1638 {
1637 return; 1639 return;
1638 } 1640 }
1639 1641
1640 GNUNET_TESTBED_operation_done (entry->op); 1642 GNUNET_TESTBED_operation_done(entry->op);
1641 if (NULL != emsg) 1643 if (NULL != emsg)
1642 { 1644 {
1643 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); 1645 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n");
1644 GNUNET_SCHEDULER_shutdown (); 1646 GNUNET_SCHEDULER_shutdown();
1645 return; 1647 return;
1646 } 1648 }
1647 GNUNET_assert (0 != entry->delta); 1649 GNUNET_assert(0 != entry->delta);
1648 1650
1649 num_peers_online += entry->delta; 1651 num_peers_online += entry->delta;
1650 1652
1651 if (PEER_GO_OFFLINE == entry->delta) 1653 if (PEER_GO_OFFLINE == entry->delta)
1652 { /* Peer hopefully just went offline */ 1654 { /* Peer hopefully just went offline */
1653 if (GNUNET_YES != rps_peers[entry->index].online) 1655 if (GNUNET_YES != rps_peers[entry->index].online)
1654 { 1656 {
1655 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1657 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1656 "peer %s was expected to go offline but is still marked as online\n", 1658 "peer %s was expected to go offline but is still marked as online\n",
1657 GNUNET_i2s (rps_peers[entry->index].peer_id)); 1659 GNUNET_i2s(rps_peers[entry->index].peer_id));
1658 GNUNET_break (0); 1660 GNUNET_break(0);
1659 } 1661 }
1660 else 1662 else
1661 { 1663 {
1662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1664 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1663 "peer %s probably went offline as expected\n", 1665 "peer %s probably went offline as expected\n",
1664 GNUNET_i2s (rps_peers[entry->index].peer_id)); 1666 GNUNET_i2s(rps_peers[entry->index].peer_id));
1667 }
1668 rps_peers[entry->index].online = GNUNET_NO;
1665 } 1669 }
1666 rps_peers[entry->index].online = GNUNET_NO;
1667 }
1668 1670
1669 else if (PEER_GO_ONLINE < entry->delta) 1671 else if (PEER_GO_ONLINE < entry->delta)
1670 { /* Peer hopefully just went online */ 1672 { /* Peer hopefully just went online */
1671 if (GNUNET_NO != rps_peers[entry->index].online) 1673 if (GNUNET_NO != rps_peers[entry->index].online)
1672 { 1674 {
1673 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1675 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1674 "peer %s was expected to go online but is still marked as offline\n", 1676 "peer %s was expected to go online but is still marked as offline\n",
1675 GNUNET_i2s (rps_peers[entry->index].peer_id)); 1677 GNUNET_i2s(rps_peers[entry->index].peer_id));
1676 GNUNET_break (0); 1678 GNUNET_break(0);
1677 } 1679 }
1678 else 1680 else
1679 { 1681 {
1680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1682 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1681 "peer %s probably went online as expected\n", 1683 "peer %s probably went online as expected\n",
1682 GNUNET_i2s (rps_peers[entry->index].peer_id)); 1684 GNUNET_i2s(rps_peers[entry->index].peer_id));
1683 if (NULL != cur_test_run.pre_test) 1685 if (NULL != cur_test_run.pre_test)
1684 { 1686 {
1685 cur_test_run.pre_test (&rps_peers[entry->index], 1687 cur_test_run.pre_test(&rps_peers[entry->index],
1686 rps_peers[entry->index].rps_handle); 1688 rps_peers[entry->index].rps_handle);
1687 schedule_missing_requests (&rps_peers[entry->index]); 1689 schedule_missing_requests(&rps_peers[entry->index]);
1688 } 1690 }
1689 } 1691 }
1690 rps_peers[entry->index].online = GNUNET_YES; 1692 rps_peers[entry->index].online = GNUNET_YES;
1691 } 1693 }
1692 else 1694 else
1693 { 1695 {
1694 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1696 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1695 "Invalid value for delta: %i\n", entry->delta); 1697 "Invalid value for delta: %i\n", entry->delta);
1696 GNUNET_break (0); 1698 GNUNET_break(0);
1697 } 1699 }
1698 1700
1699 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); 1701 GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry);
1700 rps_peers[entry->index].entry_op_manage = NULL; 1702 rps_peers[entry->index].entry_op_manage = NULL;
1701 GNUNET_free (entry); 1703 GNUNET_free(entry);
1702 //if (num_peers_in_round[current_round] == peers_running) 1704 //if (num_peers_in_round[current_round] == peers_running)
1703 // run_round (); 1705 // run_round ();
1704} 1706}
@@ -1712,54 +1714,54 @@ churn_cb (void *cls,
1712 * @param prob_go_on_off the probability of the action 1714 * @param prob_go_on_off the probability of the action
1713 */ 1715 */
1714static void 1716static void
1715manage_service_wrapper (unsigned int i, unsigned int j, 1717manage_service_wrapper(unsigned int i, unsigned int j,
1716 enum PEER_ONLINE_DELTA delta, 1718 enum PEER_ONLINE_DELTA delta,
1717 double prob_go_on_off) 1719 double prob_go_on_off)
1718{ 1720{
1719 struct OpListEntry *entry = NULL; 1721 struct OpListEntry *entry = NULL;
1720 uint32_t prob; 1722 uint32_t prob;
1721 1723
1722 /* make sure that management operation is not already scheduled */ 1724 /* make sure that management operation is not already scheduled */
1723 if (NULL != rps_peers[j].entry_op_manage) 1725 if (NULL != rps_peers[j].entry_op_manage)
1724 { 1726 {
1725 return; 1727 return;
1726 } 1728 }
1727 1729
1728 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1730 prob = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
1729 UINT32_MAX); 1731 UINT32_MAX);
1730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1732 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1731 "%u. selected peer (%u: %s) is %s.\n", 1733 "%u. selected peer (%u: %s) is %s.\n",
1732 i, 1734 i,
1733 j, 1735 j,
1734 GNUNET_i2s (rps_peers[j].peer_id), 1736 GNUNET_i2s(rps_peers[j].peer_id),
1735 (PEER_GO_ONLINE == delta) ? "online" : "offline"); 1737 (PEER_GO_ONLINE == delta) ? "online" : "offline");
1736 if (prob < prob_go_on_off * UINT32_MAX) 1738 if (prob < prob_go_on_off * UINT32_MAX)
1737 { 1739 {
1738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1740 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1739 "%s goes %s\n", 1741 "%s goes %s\n",
1740 GNUNET_i2s (rps_peers[j].peer_id), 1742 GNUNET_i2s(rps_peers[j].peer_id),
1741 (PEER_GO_OFFLINE == delta) ? "offline" : "online"); 1743 (PEER_GO_OFFLINE == delta) ? "offline" : "online");
1742 1744
1743 if (PEER_GO_OFFLINE == delta) 1745 if (PEER_GO_OFFLINE == delta)
1744 cancel_pending_req_rep (&rps_peers[j]); 1746 cancel_pending_req_rep(&rps_peers[j]);
1745 entry = make_oplist_entry (); 1747 entry = make_oplist_entry();
1746 entry->delta = delta; 1748 entry->delta = delta;
1747 entry->index = j; 1749 entry->index = j;
1748 entry->op = GNUNET_TESTBED_peer_manage_service (NULL, 1750 entry->op = GNUNET_TESTBED_peer_manage_service(NULL,
1749 testbed_peers[j], 1751 testbed_peers[j],
1750 "rps", 1752 "rps",
1751 &churn_cb, 1753 &churn_cb,
1752 entry, 1754 entry,
1753 (PEER_GO_OFFLINE == delta) ? 0 : 1); 1755 (PEER_GO_OFFLINE == delta) ? 0 : 1);
1754 rps_peers[j].entry_op_manage = entry; 1756 rps_peers[j].entry_op_manage = entry;
1755 } 1757 }
1756} 1758}
1757 1759
1758 1760
1759static void 1761static void
1760churn (void *cls) 1762churn(void *cls)
1761{ 1763{
1762 (void) cls; 1764 (void)cls;
1763 unsigned int i; 1765 unsigned int i;
1764 unsigned int j; 1766 unsigned int j;
1765 double portion_online; 1767 double portion_online;
@@ -1769,67 +1771,67 @@ churn (void *cls)
1769 double portion_go_offline; 1771 double portion_go_offline;
1770 1772
1771 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1773 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1772 { 1774 {
1773 return; 1775 return;
1774 } 1776 }
1775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1777 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1776 "Churn function executing\n"); 1778 "Churn function executing\n");
1777 1779
1778 churn_task = NULL; /* Should be invalid by now */ 1780 churn_task = NULL; /* Should be invalid by now */
1779 1781
1780 /* Compute the probability for an online peer to go offline 1782 /* Compute the probability for an online peer to go offline
1781 * this round */ 1783 * this round */
1782 portion_online = num_peers_online * 1.0 / num_peers; 1784 portion_online = num_peers_online * 1.0 / num_peers;
1783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1785 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1784 "Portion online: %f\n", 1786 "Portion online: %f\n",
1785 portion_online); 1787 portion_online);
1786 portion_go_online = ((1 - portion_online) * .5 * .66); 1788 portion_go_online = ((1 - portion_online) * .5 * .66);
1787 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1789 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1788 "Portion that should go online: %f\n", 1790 "Portion that should go online: %f\n",
1789 portion_go_online); 1791 portion_go_online);
1790 portion_go_offline = (portion_online + portion_go_online) - .75; 1792 portion_go_offline = (portion_online + portion_go_online) - .75;
1791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1793 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1792 "Portion that probably goes offline: %f\n", 1794 "Portion that probably goes offline: %f\n",
1793 portion_go_offline); 1795 portion_go_offline);
1794 prob_go_offline = portion_go_offline / (portion_online * .5); 1796 prob_go_offline = portion_go_offline / (portion_online * .5);
1795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1797 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1796 "Probability of a selected online peer to go offline: %f\n", 1798 "Probability of a selected online peer to go offline: %f\n",
1797 prob_go_offline); 1799 prob_go_offline);
1798 1800
1799 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, 1801 permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK,
1800 (unsigned int) num_peers); 1802 (unsigned int)num_peers);
1801 1803
1802 /* Go over 50% randomly chosen peers */ 1804 /* Go over 50% randomly chosen peers */
1803 for (i = 0; i < .5 * num_peers; i++) 1805 for (i = 0; i < .5 * num_peers; i++)
1804 {
1805 j = permut[i];
1806
1807 /* If online, shut down with certain probability */
1808 if (GNUNET_YES == rps_peers[j].online)
1809 {
1810 manage_service_wrapper (i, j, -1, prob_go_offline);
1811 }
1812
1813 /* If offline, restart with certain probability */
1814 else if (GNUNET_NO == rps_peers[j].online)
1815 { 1806 {
1816 manage_service_wrapper (i, j, 1, 0.66); 1807 j = permut[i];
1808
1809 /* If online, shut down with certain probability */
1810 if (GNUNET_YES == rps_peers[j].online)
1811 {
1812 manage_service_wrapper(i, j, -1, prob_go_offline);
1813 }
1814
1815 /* If offline, restart with certain probability */
1816 else if (GNUNET_NO == rps_peers[j].online)
1817 {
1818 manage_service_wrapper(i, j, 1, 0.66);
1819 }
1817 } 1820 }
1818 }
1819 1821
1820 GNUNET_free (permut); 1822 GNUNET_free(permut);
1821 1823
1822 churn_task = GNUNET_SCHEDULER_add_delayed ( 1824 churn_task = GNUNET_SCHEDULER_add_delayed(
1823 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), 1825 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
1824 churn, 1826 churn,
1825 NULL); 1827 NULL);
1826} 1828}
1827 1829
1828 1830
1829/** 1831/**
1830 * Initialise given RPSPeer 1832 * Initialise given RPSPeer
1831 */ 1833 */
1832static void profiler_init_peer (struct RPSPeer *rps_peer) 1834static void profiler_init_peer(struct RPSPeer *rps_peer)
1833{ 1835{
1834 if (num_peers - 1 == rps_peer->index) 1836 if (num_peers - 1 == rps_peer->index)
1835 rps_peer->num_ids_to_request = cur_test_run.num_requests; 1837 rps_peer->num_ids_to_request = cur_test_run.num_requests;
@@ -1844,7 +1846,7 @@ static void profiler_init_peer (struct RPSPeer *rps_peer)
1844 * @param recv_peers the received peers 1846 * @param recv_peers the received peers
1845 */ 1847 */
1846static void 1848static void
1847profiler_reply_handle (void *cls, 1849profiler_reply_handle(void *cls,
1848 uint64_t n, 1850 uint64_t n,
1849 const struct GNUNET_PeerIdentity *recv_peers) 1851 const struct GNUNET_PeerIdentity *recv_peers)
1850{ 1852{
@@ -1853,61 +1855,63 @@ profiler_reply_handle (void *cls,
1853 char *file_name; 1855 char *file_name;
1854 char *file_name_dh; 1856 char *file_name_dh;
1855 unsigned int i; 1857 unsigned int i;
1856 struct PendingReply *pending_rep = (struct PendingReply *) cls; 1858 struct PendingReply *pending_rep = (struct PendingReply *)cls;
1857 1859
1858 rps_peer = pending_rep->rps_peer; 1860 rps_peer = pending_rep->rps_peer;
1859 file_name = "/tmp/rps/received_ids"; 1861 file_name = "/tmp/rps/received_ids";
1860 file_name_dh = "/tmp/rps/diehard_input"; 1862 file_name_dh = "/tmp/rps/diehard_input";
1861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1863 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1862 "[%s] got %" PRIu64 " peers:\n", 1864 "[%s] got %" PRIu64 " peers:\n",
1863 GNUNET_i2s (rps_peer->peer_id), 1865 GNUNET_i2s(rps_peer->peer_id),
1864 n); 1866 n);
1865 for (i = 0; i < n; i++) 1867 for (i = 0; i < n; i++)
1866 { 1868 {
1867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1869 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1868 "%u: %s\n", 1870 "%u: %s\n",
1869 i, 1871 i,
1870 GNUNET_i2s (&recv_peers[i])); 1872 GNUNET_i2s(&recv_peers[i]));
1871 tofile (file_name, 1873 tofile(file_name,
1872 "%s\n", 1874 "%s\n",
1873 GNUNET_i2s_full (&recv_peers[i])); 1875 GNUNET_i2s_full(&recv_peers[i]));
1874 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]); 1876 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, &recv_peers[i]);
1875 GNUNET_assert (NULL != rcv_rps_peer); 1877 GNUNET_assert(NULL != rcv_rps_peer);
1876 tofile (file_name_dh, 1878 tofile(file_name_dh,
1877 "%" PRIu32 "\n", 1879 "%" PRIu32 "\n",
1878 (uint32_t) rcv_rps_peer->index); 1880 (uint32_t)rcv_rps_peer->index);
1879 } 1881 }
1880 default_reply_handle (cls, n, recv_peers); 1882 default_reply_handle(cls, n, recv_peers);
1881} 1883}
1882 1884
1883 1885
1884static void 1886static void
1885profiler_cb (struct RPSPeer *rps_peer) 1887profiler_cb(struct RPSPeer *rps_peer)
1886{ 1888{
1887 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1889 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1888 { 1890 {
1889 return; 1891 return;
1890 } 1892 }
1891 1893
1892 /* Start churn */ 1894 /* Start churn */
1893 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) 1895 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task)
1894 { 1896 {
1895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1897 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1896 "Starting churn task\n"); 1898 "Starting churn task\n");
1897 churn_task = GNUNET_SCHEDULER_add_delayed ( 1899 churn_task = GNUNET_SCHEDULER_add_delayed(
1898 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), 1900 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
1899 churn, 1901 churn,
1900 NULL); 1902 NULL);
1901 } else { 1903 }
1902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1904 else
1903 "Not starting churn task\n"); 1905 {
1904 } 1906 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1907 "Not starting churn task\n");
1908 }
1905 1909
1906 /* Only request peer ids at one peer. 1910 /* Only request peer ids at one peer.
1907 * (It's the before-last because last one is target of the focussed attack.) 1911 * (It's the before-last because last one is target of the focussed attack.)
1908 */ 1912 */
1909 if (eval_peer == rps_peer) 1913 if (eval_peer == rps_peer)
1910 schedule_missing_requests (rps_peer); 1914 schedule_missing_requests(rps_peer);
1911} 1915}
1912 1916
1913/** 1917/**
@@ -1920,30 +1924,30 @@ profiler_cb (struct RPSPeer *rps_peer)
1920 * #GNUNET_SYSERR to abort iteration with error! 1924 * #GNUNET_SYSERR to abort iteration with error!
1921 */ 1925 */
1922int 1926int
1923file_name_cb (void *cls, const char *filename) 1927file_name_cb(void *cls, const char *filename)
1924{ 1928{
1925 (void) cls; 1929 (void)cls;
1926 1930
1927 if (NULL != strstr (filename, "sampler_el")) 1931 if (NULL != strstr(filename, "sampler_el"))
1928 {
1929 struct RPS_SamplerElement *s_elem;
1930 struct GNUNET_CRYPTO_AuthKey auth_key;
1931 const char *key_char;
1932 uint32_t i;
1933
1934 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
1935 tofile (filename, "--------------------------\n");
1936
1937 auth_key = string_to_auth_key (key_char);
1938 s_elem = RPS_sampler_elem_create ();
1939 RPS_sampler_elem_set (s_elem, auth_key);
1940
1941 for (i = 0; i < num_peers; i++)
1942 { 1932 {
1943 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); 1933 struct RPS_SamplerElement *s_elem;
1934 struct GNUNET_CRYPTO_AuthKey auth_key;
1935 const char *key_char;
1936 uint32_t i;
1937
1938 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
1939 tofile(filename, "--------------------------\n");
1940
1941 auth_key = string_to_auth_key(key_char);
1942 s_elem = RPS_sampler_elem_create();
1943 RPS_sampler_elem_set(s_elem, auth_key);
1944
1945 for (i = 0; i < num_peers; i++)
1946 {
1947 RPS_sampler_elem_next(s_elem, &rps_peer_ids[i]);
1948 }
1949 RPS_sampler_elem_destroy(s_elem);
1944 } 1950 }
1945 RPS_sampler_elem_destroy (s_elem);
1946 }
1947 return GNUNET_OK; 1951 return GNUNET_OK;
1948} 1952}
1949 1953
@@ -1953,15 +1957,15 @@ file_name_cb (void *cls, const char *filename)
1953 * Compute all perfect samples. 1957 * Compute all perfect samples.
1954 */ 1958 */
1955int 1959int
1956profiler_eval (void) 1960profiler_eval(void)
1957{ 1961{
1958 /* Compute perfect sample for each sampler element */ 1962 /* Compute perfect sample for each sampler element */
1959 if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL)) 1963 if (-1 == GNUNET_DISK_directory_scan("/tmp/rps/", file_name_cb, NULL))
1960 { 1964 {
1961 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); 1965 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
1962 } 1966 }
1963 1967
1964 return evaluate (); 1968 return evaluate();
1965} 1969}
1966 1970
1967 1971
@@ -1973,39 +1977,40 @@ profiler_eval (void)
1973 * 1977 *
1974 * @return 1978 * @return
1975 */ 1979 */
1976static int is_in_view (uint32_t a, uint32_t b) 1980static int is_in_view(uint32_t a, uint32_t b)
1977{ 1981{
1978 uint32_t i; 1982 uint32_t i;
1983
1979 for (i = 0; i < rps_peers[a].cur_view_count; i++) 1984 for (i = 0; i < rps_peers[a].cur_view_count; i++)
1980 {
1981 if (0 == memcmp (rps_peers[b].peer_id,
1982 &rps_peers[a].cur_view[i],
1983 sizeof (struct GNUNET_PeerIdentity)))
1984 { 1985 {
1985 return GNUNET_YES; 1986 if (0 == memcmp(rps_peers[b].peer_id,
1987 &rps_peers[a].cur_view[i],
1988 sizeof(struct GNUNET_PeerIdentity)))
1989 {
1990 return GNUNET_YES;
1991 }
1986 } 1992 }
1987 }
1988 return GNUNET_NO; 1993 return GNUNET_NO;
1989} 1994}
1990 1995
1991static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid) 1996static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid)
1992{ 1997{
1993 uint32_t i; 1998 uint32_t i;
1994 1999
1995 for (i = 0; i < num_peers; i++) 2000 for (i = 0; i < num_peers; i++)
1996 {
1997 if (0 == memcmp (pid,
1998 rps_peers[i].peer_id,
1999 sizeof (struct GNUNET_PeerIdentity)))
2000 { 2001 {
2001 return i; 2002 if (0 == memcmp(pid,
2003 rps_peers[i].peer_id,
2004 sizeof(struct GNUNET_PeerIdentity)))
2005 {
2006 return i;
2007 }
2002 } 2008 }
2003 }
2004 //return 0; /* Should not happen - make compiler happy */ 2009 //return 0; /* Should not happen - make compiler happy */
2005 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2010 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2006 "No known _PeerIdentity %s!\n", 2011 "No known _PeerIdentity %s!\n",
2007 GNUNET_i2s_full (pid)); 2012 GNUNET_i2s_full(pid));
2008 GNUNET_assert (0); 2013 GNUNET_assert(0);
2009} 2014}
2010 2015
2011/** 2016/**
@@ -2016,20 +2021,20 @@ static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid)
2016 * 2021 *
2017 * @return 2022 * @return
2018 */ 2023 */
2019static uint32_t count_containing_views (uint32_t a, uint32_t b) 2024static uint32_t count_containing_views(uint32_t a, uint32_t b)
2020{ 2025{
2021 uint32_t i; 2026 uint32_t i;
2022 uint32_t peer_idx; 2027 uint32_t peer_idx;
2023 uint32_t count = 0; 2028 uint32_t count = 0;
2024 2029
2025 for (i = 0; i < rps_peers[a].cur_view_count; i++) 2030 for (i = 0; i < rps_peers[a].cur_view_count; i++)
2026 {
2027 peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]);
2028 if (GNUNET_YES == is_in_view (peer_idx, b))
2029 { 2031 {
2030 count++; 2032 peer_idx = get_idx_of_pid(&rps_peers[a].cur_view[i]);
2033 if (GNUNET_YES == is_in_view(peer_idx, b))
2034 {
2035 count++;
2036 }
2031 } 2037 }
2032 }
2033 return count; 2038 return count;
2034} 2039}
2035 2040
@@ -2039,12 +2044,12 @@ static uint32_t count_containing_views (uint32_t a, uint32_t b)
2039 * 2044 *
2040 * @param peer_idx index of the peer that is about to sample 2045 * @param peer_idx index of the peer that is about to sample
2041 */ 2046 */
2042static void compute_probabilities (uint32_t peer_idx) 2047static void compute_probabilities(uint32_t peer_idx)
2043{ 2048{
2044 //double probs[num_peers] = { 0 }; 2049 //double probs[num_peers] = { 0 };
2045 double probs[num_peers]; 2050 double probs[num_peers];
2046 size_t probs_as_str_size = (num_peers * 10 + 1) * sizeof (char); 2051 size_t probs_as_str_size = (num_peers * 10 + 1) * sizeof(char);
2047 char *probs_as_str = GNUNET_malloc (probs_as_str_size); 2052 char *probs_as_str = GNUNET_malloc(probs_as_str_size);
2048 char *probs_as_str_cpy; 2053 char *probs_as_str_cpy;
2049 uint32_t i; 2054 uint32_t i;
2050 double prob_push; 2055 double prob_push;
@@ -2055,113 +2060,119 @@ static void compute_probabilities (uint32_t peer_idx)
2055 int tmp; 2060 int tmp;
2056 uint32_t count_non_zero_prob = 0; 2061 uint32_t count_non_zero_prob = 0;
2057 2062
2058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2063 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2059 "Computing probabilities for peer %" PRIu32 "\n", peer_idx); 2064 "Computing probabilities for peer %" PRIu32 "\n", peer_idx);
2060 /* Firstly without knowledge of old views */ 2065 /* Firstly without knowledge of old views */
2061 for (i = 0; i < num_peers; i++) 2066 for (i = 0; i < num_peers; i++)
2062 { 2067 {
2063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2068 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2064 "\tfor peer %" PRIu32 ":\n", i); 2069 "\tfor peer %" PRIu32 ":\n", i);
2065 view_size = rps_peers[i].cur_view_count; 2070 view_size = rps_peers[i].cur_view_count;
2066 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2071 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2067 "\t\tview_size: %" PRIu32 "\n", view_size); 2072 "\t\tview_size: %" PRIu32 "\n", view_size);
2068 /* For peer i the probability of being sampled is 2073 /* For peer i the probability of being sampled is
2069 * evenly distributed among all possibly observed peers. */ 2074 * evenly distributed among all possibly observed peers. */
2070 /* We could have observed a peer in three cases: 2075 /* We could have observed a peer in three cases:
2071 * 1. peer sent a push 2076 * 1. peer sent a push
2072 * 2. peer was contained in a pull reply 2077 * 2. peer was contained in a pull reply
2073 * 3. peer was in history (sampler) - ignored for now */ 2078 * 3. peer was in history (sampler) - ignored for now */
2074 /* 1. Probability of having received a push from peer i */ 2079 /* 1. Probability of having received a push from peer i */
2075 if ((GNUNET_YES == is_in_view (i, peer_idx)) && 2080 if ((GNUNET_YES == is_in_view(i, peer_idx)) &&
2076 (1 <= (0.45 * view_size))) 2081 (1 <= (0.45 * view_size)))
2077 { 2082 {
2078 prob_push = 1.0 * binom (0.45 * view_size, 1) 2083 prob_push = 1.0 * binom(0.45 * view_size, 1)
2079 / 2084 /
2080 binom (view_size, 0.45 * view_size); 2085 binom(view_size, 0.45 * view_size);
2081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2086 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2082 "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", 2087 "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n",
2088 peer_idx,
2089 i,
2090 prob_push);
2091 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2092 "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n",
2093 binom(view_size, 0.45 * view_size),
2094 binom(0.45 * view_size, 1));
2095 }
2096 else
2097 {
2098 prob_push = 0;
2099 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2100 "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n",
2101 peer_idx,
2102 i);
2103 }
2104 /* 2. Probability of peer i being contained in pulls */
2105 view_size = rps_peers[peer_idx].cur_view_count;
2106 cont_views = count_containing_views(peer_idx, i);
2107 number_of_being_in_pull_events =
2108 (binom(view_size, 0.45 * view_size) -
2109 binom(view_size - cont_views, 0.45 * view_size));
2110 if (0 != number_of_being_in_pull_events)
2111 {
2112 prob_pull = number_of_being_in_pull_events
2113 /
2114 (1.0 * binom(view_size, 0.45 * view_size));
2115 }
2116 else
2117 {
2118 prob_pull = 0;
2119 }
2120 probs[i] = prob_push + prob_pull - (prob_push * prob_pull);
2121 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2122 "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32
2123 " peers in its view who know %" PRIu32 " prob: %f\n",
2083 peer_idx, 2124 peer_idx,
2125 cont_views,
2126 view_size,
2084 i, 2127 i,
2085 prob_push); 2128 prob_pull);
2086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2129 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2087 "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", 2130 "\t\tnumber of possible pull combinations: %" PRIu32 "\n",
2088 binom (view_size, 0.45 * view_size), 2131 binom(view_size, 0.45 * view_size));
2089 binom (0.45 * view_size, 1)); 2132 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2090 } else { 2133 "\t\tnumber of possible pull combinations without %" PRIu32
2091 prob_push = 0; 2134 ": %" PRIu32 "\n",
2092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2135 i,
2093 "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", 2136 binom(view_size - cont_views, 0.45 * view_size));
2094 peer_idx, 2137 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2095 i); 2138 "\t\tnumber of possible pull combinations with %" PRIu32
2096 } 2139 ": %" PRIu32 "\n",
2097 /* 2. Probability of peer i being contained in pulls */ 2140 i,
2098 view_size = rps_peers[peer_idx].cur_view_count; 2141 number_of_being_in_pull_events);
2099 cont_views = count_containing_views (peer_idx, i);
2100 number_of_being_in_pull_events =
2101 (binom (view_size, 0.45 * view_size) -
2102 binom (view_size - cont_views, 0.45 * view_size));
2103 if (0 != number_of_being_in_pull_events)
2104 {
2105 prob_pull = number_of_being_in_pull_events
2106 /
2107 (1.0 * binom (view_size, 0.45 * view_size));
2108 } else
2109 {
2110 prob_pull = 0;
2111 }
2112 probs[i] = prob_push + prob_pull - (prob_push * prob_pull);
2113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2114 "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32
2115 " peers in its view who know %" PRIu32 " prob: %f\n",
2116 peer_idx,
2117 cont_views,
2118 view_size,
2119 i,
2120 prob_pull);
2121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2122 "\t\tnumber of possible pull combinations: %" PRIu32 "\n",
2123 binom (view_size, 0.45 * view_size));
2124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2125 "\t\tnumber of possible pull combinations without %" PRIu32
2126 ": %" PRIu32 "\n",
2127 i,
2128 binom (view_size - cont_views, 0.45 * view_size));
2129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2130 "\t\tnumber of possible pull combinations with %" PRIu32
2131 ": %" PRIu32 "\n",
2132 i,
2133 number_of_being_in_pull_events);
2134 2142
2135 if (0 != probs[i]) count_non_zero_prob++; 2143 if (0 != probs[i])
2136 } 2144 count_non_zero_prob++;
2145 }
2137 /* normalize */ 2146 /* normalize */
2138 if (0 != count_non_zero_prob) 2147 if (0 != count_non_zero_prob)
2139 {
2140 for (i = 0; i < num_peers; i++)
2141 { 2148 {
2142 probs[i] = probs[i] * (1.0 / count_non_zero_prob); 2149 for (i = 0; i < num_peers; i++)
2150 {
2151 probs[i] = probs[i] * (1.0 / count_non_zero_prob);
2152 }
2143 } 2153 }
2144 } else { 2154 else
2145 for (i = 0; i < num_peers; i++)
2146 { 2155 {
2147 probs[i] = 0; 2156 for (i = 0; i < num_peers; i++)
2157 {
2158 probs[i] = 0;
2159 }
2148 } 2160 }
2149 }
2150 /* str repr */ 2161 /* str repr */
2151 for (i = 0; i < num_peers; i++) 2162 for (i = 0; i < num_peers; i++)
2152 { 2163 {
2153 probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); 2164 probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size);
2154 tmp = GNUNET_snprintf (probs_as_str, 2165 tmp = GNUNET_snprintf(probs_as_str,
2155 probs_as_str_size, 2166 probs_as_str_size,
2156 "%s %7.6f", probs_as_str_cpy, probs[i]); 2167 "%s %7.6f", probs_as_str_cpy, probs[i]);
2157 GNUNET_free (probs_as_str_cpy); 2168 GNUNET_free(probs_as_str_cpy);
2158 GNUNET_assert (0 <= tmp); 2169 GNUNET_assert(0 <= tmp);
2159 } 2170 }
2160 2171
2161 to_file_w_len (rps_peers[peer_idx].file_name_probs, 2172 to_file_w_len(rps_peers[peer_idx].file_name_probs,
2162 probs_as_str_size, 2173 probs_as_str_size,
2163 probs_as_str); 2174 probs_as_str);
2164 GNUNET_free (probs_as_str); 2175 GNUNET_free(probs_as_str);
2165} 2176}
2166 2177
2167/** 2178/**
@@ -2173,98 +2184,98 @@ static void compute_probabilities (uint32_t peer_idx)
2173 * 2184 *
2174 * @return the number of occurrences 2185 * @return the number of occurrences
2175 */ 2186 */
2176static uint32_t count_peer_in_views_2 (uint32_t peer_idx) 2187static uint32_t count_peer_in_views_2(uint32_t peer_idx)
2177{ 2188{
2178 uint32_t i, j; 2189 uint32_t i, j;
2179 uint32_t count = 0; 2190 uint32_t count = 0;
2180 2191
2181 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ 2192 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2182 { 2193 {
2183 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ 2194 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2184 { 2195 {
2185 if (0 == memcmp (rps_peers[peer_idx].peer_id, 2196 if (0 == memcmp(rps_peers[peer_idx].peer_id,
2186 &rps_peers[i].cur_view[j], 2197 &rps_peers[i].cur_view[j],
2187 sizeof (struct GNUNET_PeerIdentity))) 2198 sizeof(struct GNUNET_PeerIdentity)))
2188 { 2199 {
2189 count++; 2200 count++;
2190 break; 2201 break;
2191 } 2202 }
2192 } 2203 }
2193 } 2204 }
2194 rps_peers[peer_idx].count_in_views = count; 2205 rps_peers[peer_idx].count_in_views = count;
2195 return count; 2206 return count;
2196} 2207}
2197 2208
2198static uint32_t cumulated_view_sizes () 2209static uint32_t cumulated_view_sizes()
2199{ 2210{
2200 uint32_t i; 2211 uint32_t i;
2201 2212
2202 view_sizes = 0; 2213 view_sizes = 0;
2203 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ 2214 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2204 { 2215 {
2205 view_sizes += rps_peers[i].cur_view_count; 2216 view_sizes += rps_peers[i].cur_view_count;
2206 } 2217 }
2207 return view_sizes; 2218 return view_sizes;
2208} 2219}
2209 2220
2210static void count_peer_in_views (uint32_t *count_peers) 2221static void count_peer_in_views(uint32_t *count_peers)
2211{ 2222{
2212 uint32_t i, j; 2223 uint32_t i, j;
2213 2224
2214 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ 2225 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2215 {
2216 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2217 { 2226 {
2218 if (0 == memcmp (rps_peers[i].peer_id, 2227 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2219 &rps_peers[i].cur_view[j], 2228 {
2220 sizeof (struct GNUNET_PeerIdentity))) 2229 if (0 == memcmp(rps_peers[i].peer_id,
2221 { 2230 &rps_peers[i].cur_view[j],
2222 count_peers[i]++; 2231 sizeof(struct GNUNET_PeerIdentity)))
2223 } 2232 {
2233 count_peers[i]++;
2234 }
2235 }
2224 } 2236 }
2225 }
2226} 2237}
2227 2238
2228void compute_diversity () 2239void compute_diversity()
2229{ 2240{
2230 uint32_t i; 2241 uint32_t i;
2231 /* ith entry represents the numer of occurrences in other peer's views */ 2242 /* ith entry represents the numer of occurrences in other peer's views */
2232 uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t); 2243 uint32_t *count_peers = GNUNET_new_array(num_peers, uint32_t);
2233 uint32_t views_total_size; 2244 uint32_t views_total_size;
2234 double expected; 2245 double expected;
2235 /* deviation from expected number of peers */ 2246 /* deviation from expected number of peers */
2236 double *deviation = GNUNET_new_array (num_peers, double); 2247 double *deviation = GNUNET_new_array(num_peers, double);
2237 2248
2238 views_total_size = 0; 2249 views_total_size = 0;
2239 expected = 0; 2250 expected = 0;
2240 2251
2241 /* For each peer count its representation in other peer's views*/ 2252 /* For each peer count its representation in other peer's views*/
2242 for (i = 0; i < num_peers; i++) /* Peer to count */ 2253 for (i = 0; i < num_peers; i++) /* Peer to count */
2243 { 2254 {
2244 views_total_size += rps_peers[i].cur_view_count; 2255 views_total_size += rps_peers[i].cur_view_count;
2245 count_peer_in_views (count_peers); 2256 count_peer_in_views(count_peers);
2246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2257 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2247 "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32"\n", 2258 "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32 "\n",
2248 i, 2259 i,
2249 GNUNET_i2s (rps_peers[i].peer_id), 2260 GNUNET_i2s(rps_peers[i].peer_id),
2250 count_peers[i]); 2261 count_peers[i]);
2251 } 2262 }
2252 2263
2253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2264 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2254 "size of all views combined: %" PRIu32 "\n", 2265 "size of all views combined: %" PRIu32 "\n",
2255 views_total_size); 2266 views_total_size);
2256 expected = ((double) 1/num_peers) * views_total_size; 2267 expected = ((double)1 / num_peers) * views_total_size;
2257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2268 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2258 "Expected number of occurrences of each peer in all views: %f\n", 2269 "Expected number of occurrences of each peer in all views: %f\n",
2259 expected); 2270 expected);
2260 for (i = 0; i < num_peers; i++) /* Peer to count */ 2271 for (i = 0; i < num_peers; i++) /* Peer to count */
2261 { 2272 {
2262 deviation[i] = expected - count_peers[i]; 2273 deviation[i] = expected - count_peers[i];
2263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2274 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2264 "Deviation from expectation: %f\n", deviation[i]); 2275 "Deviation from expectation: %f\n", deviation[i]);
2265 } 2276 }
2266 GNUNET_free (count_peers); 2277 GNUNET_free(count_peers);
2267 GNUNET_free (deviation); 2278 GNUNET_free(deviation);
2268} 2279}
2269 2280
2270void print_view_sizes() 2281void print_view_sizes()
@@ -2272,13 +2283,13 @@ void print_view_sizes()
2272 uint32_t i; 2283 uint32_t i;
2273 2284
2274 for (i = 0; i < num_peers; i++) /* Peer to count */ 2285 for (i = 0; i < num_peers; i++) /* Peer to count */
2275 { 2286 {
2276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2287 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2277 "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", 2288 "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n",
2278 i, 2289 i,
2279 GNUNET_i2s (rps_peers[i].peer_id), 2290 GNUNET_i2s(rps_peers[i].peer_id),
2280 rps_peers[i].cur_view_count); 2291 rps_peers[i].cur_view_count);
2281 } 2292 }
2282} 2293}
2283 2294
2284void all_views_updated_cb() 2295void all_views_updated_cb()
@@ -2287,97 +2298,98 @@ void all_views_updated_cb()
2287 print_view_sizes(); 2298 print_view_sizes();
2288} 2299}
2289 2300
2290void view_update_cb (void *cls, 2301void view_update_cb(void *cls,
2291 uint64_t view_size, 2302 uint64_t view_size,
2292 const struct GNUNET_PeerIdentity *peers) 2303 const struct GNUNET_PeerIdentity *peers)
2293{ 2304{
2294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2305 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2295 "View was updated (%" PRIu64 ")\n", view_size); 2306 "View was updated (%" PRIu64 ")\n", view_size);
2296 struct RPSPeer *rps_peer = (struct RPSPeer *) cls; 2307 struct RPSPeer *rps_peer = (struct RPSPeer *)cls;
2297 to_file ("/tmp/rps/view_sizes.txt", 2308 to_file("/tmp/rps/view_sizes.txt",
2298 "%" PRIu64 " %" PRIu32 "", 2309 "%" PRIu64 " %" PRIu32 "",
2299 rps_peer->index, 2310 rps_peer->index,
2300 view_size); 2311 view_size);
2301 for (int i = 0; i < view_size; i++) 2312 for (int i = 0; i < view_size; i++)
2302 { 2313 {
2303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2314 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2304 "\t%s\n", GNUNET_i2s (&peers[i])); 2315 "\t%s\n", GNUNET_i2s(&peers[i]));
2305 } 2316 }
2306 GNUNET_array_grow (rps_peer->cur_view, 2317 GNUNET_array_grow(rps_peer->cur_view,
2307 rps_peer->cur_view_count, 2318 rps_peer->cur_view_count,
2308 view_size); 2319 view_size);
2309 //*rps_peer->cur_view = *peers; 2320 //*rps_peer->cur_view = *peers;
2310 GNUNET_memcpy (rps_peer->cur_view, 2321 GNUNET_memcpy(rps_peer->cur_view,
2311 peers, 2322 peers,
2312 view_size * sizeof (struct GNUNET_PeerIdentity)); 2323 view_size * sizeof(struct GNUNET_PeerIdentity));
2313 to_file ("/tmp/rps/count_in_views.txt", 2324 to_file("/tmp/rps/count_in_views.txt",
2314 "%" PRIu64 " %" PRIu32 "", 2325 "%" PRIu64 " %" PRIu32 "",
2315 rps_peer->index, 2326 rps_peer->index,
2316 count_peer_in_views_2 (rps_peer->index)); 2327 count_peer_in_views_2(rps_peer->index));
2317 cumulated_view_sizes(); 2328 cumulated_view_sizes();
2318 if (0 != view_size) 2329 if (0 != view_size)
2319 { 2330 {
2320 to_file ("/tmp/rps/repr.txt", 2331 to_file("/tmp/rps/repr.txt",
2321 "%" PRIu64 /* index */ 2332 "%" PRIu64 /* index */
2322 " %" PRIu32 /* occurrence in views */ 2333 " %" PRIu32 /* occurrence in views */
2323 " %" PRIu32 /* view sizes */ 2334 " %" PRIu32 /* view sizes */
2324 " %f" /* fraction of repr in views */ 2335 " %f" /* fraction of repr in views */
2325 " %f" /* average view size */ 2336 " %f" /* average view size */
2326 " %f" /* prob of occurrence in view slot */ 2337 " %f" /* prob of occurrence in view slot */
2327 " %f" "", /* exp frac of repr in views */ 2338 " %f" "", /* exp frac of repr in views */
2328 rps_peer->index, 2339 rps_peer->index,
2329 count_peer_in_views_2 (rps_peer->index), 2340 count_peer_in_views_2(rps_peer->index),
2330 view_sizes, 2341 view_sizes,
2331 count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ 2342 count_peer_in_views_2(rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */
2332 view_sizes / (view_size * 1.0), /* average view size */ 2343 view_sizes / (view_size * 1.0), /* average view size */
2333 1.0 /view_size, /* prob of occurrence in view slot */ 2344 1.0 / view_size, /* prob of occurrence in view slot */
2334 (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ 2345 (1.0 / view_size) * (view_sizes / view_size) /* expected fraction of repr in views */
2335 ); 2346 );
2336 } 2347 }
2337 compute_probabilities (rps_peer->index); 2348 compute_probabilities(rps_peer->index);
2338 all_views_updated_cb(); 2349 all_views_updated_cb();
2339} 2350}
2340 2351
2341static void 2352static void
2342pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 2353pre_profiler(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
2343{ 2354{
2344 rps_peer->file_name_probs = 2355 rps_peer->file_name_probs =
2345 store_prefix_file_name (rps_peer->peer_id, "probs"); 2356 store_prefix_file_name(rps_peer->peer_id, "probs");
2346 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); 2357 GNUNET_RPS_view_request(h, 0, view_update_cb, rps_peer);
2347} 2358}
2348 2359
2349void write_final_stats (void){ 2360void write_final_stats(void)
2361{
2350 uint32_t i; 2362 uint32_t i;
2351 2363
2352 for (i = 0; i < num_peers; i++) 2364 for (i = 0; i < num_peers; i++)
2353 { 2365 {
2354 to_file ("/tmp/rps/final_stats.dat", 2366 to_file("/tmp/rps/final_stats.dat",
2355 "%" PRIu32 " " /* index */ 2367 "%" PRIu32 " " /* index */
2356 "%s %" /* id */ 2368 "%s %" /* id */
2357 PRIu64 " %" /* rounds */ 2369 PRIu64 " %" /* rounds */
2358 PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ 2370 PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */
2359 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */ 2371 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */
2360 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */ 2372 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */
2361 PRIu64 " %" PRIu64 " %" PRIu64 /* recv */, 2373 PRIu64 " %" PRIu64 " %" PRIu64 /* recv */,
2362 i, 2374 i,
2363 GNUNET_i2s (rps_peers[i].peer_id), 2375 GNUNET_i2s(rps_peers[i].peer_id),
2364 rps_peers[i].num_rounds, 2376 rps_peers[i].num_rounds,
2365 rps_peers[i].num_blocks, 2377 rps_peers[i].num_blocks,
2366 rps_peers[i].num_blocks_many_push, 2378 rps_peers[i].num_blocks_many_push,
2367 rps_peers[i].num_blocks_no_push, 2379 rps_peers[i].num_blocks_no_push,
2368 rps_peers[i].num_blocks_no_pull, 2380 rps_peers[i].num_blocks_no_pull,
2369 rps_peers[i].num_blocks_many_push_no_pull, 2381 rps_peers[i].num_blocks_many_push_no_pull,
2370 rps_peers[i].num_blocks_no_push_no_pull, 2382 rps_peers[i].num_blocks_no_push_no_pull,
2371 rps_peers[i].num_issued_push, 2383 rps_peers[i].num_issued_push,
2372 rps_peers[i].num_issued_pull_req, 2384 rps_peers[i].num_issued_pull_req,
2373 rps_peers[i].num_issued_pull_rep, 2385 rps_peers[i].num_issued_pull_rep,
2374 rps_peers[i].num_sent_push, 2386 rps_peers[i].num_sent_push,
2375 rps_peers[i].num_sent_pull_req, 2387 rps_peers[i].num_sent_pull_req,
2376 rps_peers[i].num_sent_pull_rep, 2388 rps_peers[i].num_sent_pull_rep,
2377 rps_peers[i].num_recv_push, 2389 rps_peers[i].num_recv_push,
2378 rps_peers[i].num_recv_pull_req, 2390 rps_peers[i].num_recv_pull_req,
2379 rps_peers[i].num_recv_pull_rep); 2391 rps_peers[i].num_recv_pull_rep);
2380 } 2392 }
2381} 2393}
2382 2394
2383/** 2395/**
@@ -2392,40 +2404,45 @@ void write_final_stats (void){
2392 * successfully obtained, #GNUNET_SYSERR if not. 2404 * successfully obtained, #GNUNET_SYSERR if not.
2393 */ 2405 */
2394void 2406void
2395post_test_shutdown_ready_cb (void *cls, 2407post_test_shutdown_ready_cb(void *cls,
2396 int success) 2408 int success)
2397{ 2409{
2398 struct STATcls *stat_cls = (struct STATcls *) cls; 2410 struct STATcls *stat_cls = (struct STATcls *)cls;
2399 struct RPSPeer *rps_peer = stat_cls->rps_peer; 2411 struct RPSPeer *rps_peer = stat_cls->rps_peer;
2412
2400 if (GNUNET_OK == success) 2413 if (GNUNET_OK == success)
2401 { 2414 {
2402 /* set flag that we we got the value */ 2415 /* set flag that we we got the value */
2403 rps_peer->stat_collected_flags |= stat_cls->stat_type; 2416 rps_peer->stat_collected_flags |= stat_cls->stat_type;
2404 } else { 2417 }
2405 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2418 else
2406 "Peer %u did not receive statistics value\n", 2419 {
2407 rps_peer->index); 2420 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2408 GNUNET_free (stat_cls); 2421 "Peer %u did not receive statistics value\n",
2409 GNUNET_break (0); 2422 rps_peer->index);
2410 } 2423 GNUNET_free(stat_cls);
2424 GNUNET_break(0);
2425 }
2411 2426
2412 if (NULL != rps_peer->stat_op && 2427 if (NULL != rps_peer->stat_op &&
2413 GNUNET_YES == check_statistics_collect_completed_single_peer (rps_peer)) 2428 GNUNET_YES == check_statistics_collect_completed_single_peer(rps_peer))
2414 { 2429 {
2415 GNUNET_TESTBED_operation_done (rps_peer->stat_op); 2430 GNUNET_TESTBED_operation_done(rps_peer->stat_op);
2416 } 2431 }
2417 2432
2418 write_final_stats (); 2433 write_final_stats();
2419 if (GNUNET_YES == check_statistics_collect_completed()) 2434 if (GNUNET_YES == check_statistics_collect_completed())
2420 { 2435 {
2421 //write_final_stats (); 2436 //write_final_stats ();
2422 GNUNET_free (stat_cls); 2437 GNUNET_free(stat_cls);
2423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2438 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2424 "Shutting down\n"); 2439 "Shutting down\n");
2425 GNUNET_SCHEDULER_shutdown (); 2440 GNUNET_SCHEDULER_shutdown();
2426 } else { 2441 }
2427 GNUNET_free (stat_cls); 2442 else
2428 } 2443 {
2444 GNUNET_free(stat_cls);
2445 }
2429} 2446}
2430 2447
2431/** 2448/**
@@ -2435,72 +2452,72 @@ post_test_shutdown_ready_cb (void *cls,
2435 * 2452 *
2436 * @return corresponding enum 2453 * @return corresponding enum
2437 */ 2454 */
2438enum STAT_TYPE stat_str_2_type (const char *stat_str) 2455enum STAT_TYPE stat_str_2_type(const char *stat_str)
2439{ 2456{
2440 if (0 == strncmp ("# rounds blocked - no pull replies", stat_str, strlen ("# rounds blocked - no pull replies"))) 2457 if (0 == strncmp("# rounds blocked - no pull replies", stat_str, strlen("# rounds blocked - no pull replies")))
2441 { 2458 {
2442 return STAT_TYPE_BLOCKS_NO_PULL; 2459 return STAT_TYPE_BLOCKS_NO_PULL;
2443 } 2460 }
2444 else if (0 == strncmp ("# rounds blocked - too many pushes, no pull replies", stat_str, strlen ("# rounds blocked - too many pushes, no pull replies"))) 2461 else if (0 == strncmp("# rounds blocked - too many pushes, no pull replies", stat_str, strlen("# rounds blocked - too many pushes, no pull replies")))
2445 { 2462 {
2446 return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; 2463 return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL;
2447 } 2464 }
2448 else if (0 == strncmp ("# rounds blocked - too many pushes", stat_str, strlen ("# rounds blocked - too many pushes"))) 2465 else if (0 == strncmp("# rounds blocked - too many pushes", stat_str, strlen("# rounds blocked - too many pushes")))
2449 { 2466 {
2450 return STAT_TYPE_BLOCKS_MANY_PUSH; 2467 return STAT_TYPE_BLOCKS_MANY_PUSH;
2451 } 2468 }
2452 else if (0 == strncmp ("# rounds blocked - no pushes, no pull replies", stat_str, strlen ("# rounds blocked - no pushes, no pull replies"))) 2469 else if (0 == strncmp("# rounds blocked - no pushes, no pull replies", stat_str, strlen("# rounds blocked - no pushes, no pull replies")))
2453 { 2470 {
2454 return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; 2471 return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL;
2455 } 2472 }
2456 else if (0 == strncmp ("# rounds blocked - no pushes", stat_str, strlen ("# rounds blocked - no pushes"))) 2473 else if (0 == strncmp("# rounds blocked - no pushes", stat_str, strlen("# rounds blocked - no pushes")))
2457 { 2474 {
2458 return STAT_TYPE_BLOCKS_NO_PUSH; 2475 return STAT_TYPE_BLOCKS_NO_PUSH;
2459 } 2476 }
2460 else if (0 == strncmp ("# rounds blocked", stat_str, strlen ("# rounds blocked"))) 2477 else if (0 == strncmp("# rounds blocked", stat_str, strlen("# rounds blocked")))
2461 { 2478 {
2462 return STAT_TYPE_BLOCKS; 2479 return STAT_TYPE_BLOCKS;
2463 } 2480 }
2464 else if (0 == strncmp ("# rounds", stat_str, strlen ("# rounds"))) 2481 else if (0 == strncmp("# rounds", stat_str, strlen("# rounds")))
2465 { 2482 {
2466 return STAT_TYPE_ROUNDS; 2483 return STAT_TYPE_ROUNDS;
2467 } 2484 }
2468 else if (0 == strncmp ("# push send issued", stat_str, strlen ("# push send issued"))) 2485 else if (0 == strncmp("# push send issued", stat_str, strlen("# push send issued")))
2469 { 2486 {
2470 return STAT_TYPE_ISSUED_PUSH_SEND; 2487 return STAT_TYPE_ISSUED_PUSH_SEND;
2471 } 2488 }
2472 else if (0 == strncmp ("# pull request send issued", stat_str, strlen ("# pull request send issued"))) 2489 else if (0 == strncmp("# pull request send issued", stat_str, strlen("# pull request send issued")))
2473 { 2490 {
2474 return STAT_TYPE_ISSUED_PULL_REQ; 2491 return STAT_TYPE_ISSUED_PULL_REQ;
2475 } 2492 }
2476 else if (0 == strncmp ("# pull reply send issued", stat_str, strlen ("# pull reply send issued"))) 2493 else if (0 == strncmp("# pull reply send issued", stat_str, strlen("# pull reply send issued")))
2477 { 2494 {
2478 return STAT_TYPE_ISSUED_PULL_REP; 2495 return STAT_TYPE_ISSUED_PULL_REP;
2479 } 2496 }
2480 else if (0 == strncmp ("# pushes sent", stat_str, strlen ("# pushes sent"))) 2497 else if (0 == strncmp("# pushes sent", stat_str, strlen("# pushes sent")))
2481 { 2498 {
2482 return STAT_TYPE_SENT_PUSH_SEND; 2499 return STAT_TYPE_SENT_PUSH_SEND;
2483 } 2500 }
2484 else if (0 == strncmp ("# pull requests sent", stat_str, strlen ("# pull requests sent"))) 2501 else if (0 == strncmp("# pull requests sent", stat_str, strlen("# pull requests sent")))
2485 { 2502 {
2486 return STAT_TYPE_SENT_PULL_REQ; 2503 return STAT_TYPE_SENT_PULL_REQ;
2487 } 2504 }
2488 else if (0 == strncmp ("# pull replys sent", stat_str, strlen ("# pull replys sent"))) 2505 else if (0 == strncmp("# pull replys sent", stat_str, strlen("# pull replys sent")))
2489 { 2506 {
2490 return STAT_TYPE_SENT_PULL_REP; 2507 return STAT_TYPE_SENT_PULL_REP;
2491 } 2508 }
2492 else if (0 == strncmp ("# push message received", stat_str, strlen ("# push message received"))) 2509 else if (0 == strncmp("# push message received", stat_str, strlen("# push message received")))
2493 { 2510 {
2494 return STAT_TYPE_RECV_PUSH_SEND; 2511 return STAT_TYPE_RECV_PUSH_SEND;
2495 } 2512 }
2496 else if (0 == strncmp ("# pull request message received", stat_str, strlen ("# pull request message received"))) 2513 else if (0 == strncmp("# pull request message received", stat_str, strlen("# pull request message received")))
2497 { 2514 {
2498 return STAT_TYPE_RECV_PULL_REQ; 2515 return STAT_TYPE_RECV_PULL_REQ;
2499 } 2516 }
2500 else if (0 == strncmp ("# pull reply messages received", stat_str, strlen ("# pull reply messages received"))) 2517 else if (0 == strncmp("# pull reply messages received", stat_str, strlen("# pull reply messages received")))
2501 { 2518 {
2502 return STAT_TYPE_RECV_PULL_REP; 2519 return STAT_TYPE_RECV_PULL_REP;
2503 } 2520 }
2504 return STAT_TYPE_MAX; 2521 return STAT_TYPE_MAX;
2505} 2522}
2506 2523
@@ -2513,47 +2530,63 @@ enum STAT_TYPE stat_str_2_type (const char *stat_str)
2513 * 2530 *
2514 * @return string representation that matches statistics value 2531 * @return string representation that matches statistics value
2515 */ 2532 */
2516char* stat_type_2_str (enum STAT_TYPE stat_type) 2533char* stat_type_2_str(enum STAT_TYPE stat_type)
2517{ 2534{
2518 switch (stat_type) 2535 switch (stat_type)
2519 { 2536 {
2520 case STAT_TYPE_ROUNDS: 2537 case STAT_TYPE_ROUNDS:
2521 return "# rounds"; 2538 return "# rounds";
2539
2522 case STAT_TYPE_BLOCKS: 2540 case STAT_TYPE_BLOCKS:
2523 return "# rounds blocked"; 2541 return "# rounds blocked";
2542
2524 case STAT_TYPE_BLOCKS_MANY_PUSH: 2543 case STAT_TYPE_BLOCKS_MANY_PUSH:
2525 return "# rounds blocked - too many pushes"; 2544 return "# rounds blocked - too many pushes";
2545
2526 case STAT_TYPE_BLOCKS_NO_PUSH: 2546 case STAT_TYPE_BLOCKS_NO_PUSH:
2527 return "# rounds blocked - no pushes"; 2547 return "# rounds blocked - no pushes";
2548
2528 case STAT_TYPE_BLOCKS_NO_PULL: 2549 case STAT_TYPE_BLOCKS_NO_PULL:
2529 return "# rounds blocked - no pull replies"; 2550 return "# rounds blocked - no pull replies";
2551
2530 case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: 2552 case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL:
2531 return "# rounds blocked - too many pushes, no pull replies"; 2553 return "# rounds blocked - too many pushes, no pull replies";
2554
2532 case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: 2555 case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL:
2533 return "# rounds blocked - no pushes, no pull replies"; 2556 return "# rounds blocked - no pushes, no pull replies";
2557
2534 case STAT_TYPE_ISSUED_PUSH_SEND: 2558 case STAT_TYPE_ISSUED_PUSH_SEND:
2535 return "# push send issued"; 2559 return "# push send issued";
2560
2536 case STAT_TYPE_ISSUED_PULL_REQ: 2561 case STAT_TYPE_ISSUED_PULL_REQ:
2537 return "# pull request send issued"; 2562 return "# pull request send issued";
2563
2538 case STAT_TYPE_ISSUED_PULL_REP: 2564 case STAT_TYPE_ISSUED_PULL_REP:
2539 return "# pull reply send issued"; 2565 return "# pull reply send issued";
2566
2540 case STAT_TYPE_SENT_PUSH_SEND: 2567 case STAT_TYPE_SENT_PUSH_SEND:
2541 return "# pushes sent"; 2568 return "# pushes sent";
2569
2542 case STAT_TYPE_SENT_PULL_REQ: 2570 case STAT_TYPE_SENT_PULL_REQ:
2543 return "# pull requests sent"; 2571 return "# pull requests sent";
2572
2544 case STAT_TYPE_SENT_PULL_REP: 2573 case STAT_TYPE_SENT_PULL_REP:
2545 return "# pull replys sent"; 2574 return "# pull replys sent";
2575
2546 case STAT_TYPE_RECV_PUSH_SEND: 2576 case STAT_TYPE_RECV_PUSH_SEND:
2547 return "# push message received"; 2577 return "# push message received";
2578
2548 case STAT_TYPE_RECV_PULL_REQ: 2579 case STAT_TYPE_RECV_PULL_REQ:
2549 return "# pull request message received"; 2580 return "# pull request message received";
2581
2550 case STAT_TYPE_RECV_PULL_REP: 2582 case STAT_TYPE_RECV_PULL_REP:
2551 return "# pull reply messages received"; 2583 return "# pull reply messages received";
2584
2552 case STAT_TYPE_MAX: 2585 case STAT_TYPE_MAX:
2553 default: 2586 default:
2554 return "ERROR"; 2587 return "ERROR";
2555 ; 2588 ;
2556 } 2589 }
2557} 2590}
2558 2591
2559/** 2592/**
@@ -2567,125 +2600,141 @@ char* stat_type_2_str (enum STAT_TYPE stat_type)
2567 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 2600 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
2568 */ 2601 */
2569int 2602int
2570stat_iterator (void *cls, 2603stat_iterator(void *cls,
2571 const char *subsystem, 2604 const char *subsystem,
2572 const char *name, 2605 const char *name,
2573 uint64_t value, 2606 uint64_t value,
2574 int is_persistent) 2607 int is_persistent)
2575{ 2608{
2576 (void) subsystem; 2609 (void)subsystem;
2577 (void) is_persistent; 2610 (void)is_persistent;
2578 const struct STATcls *stat_cls = (const struct STATcls *) cls; 2611 const struct STATcls *stat_cls = (const struct STATcls *)cls;
2579 struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer; 2612 struct RPSPeer *rps_peer = (struct RPSPeer *)stat_cls->rps_peer;
2580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", 2613 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n",
2581 //stat_type_2_str (stat_cls->stat_type), 2614 //stat_type_2_str (stat_cls->stat_type),
2582 name, 2615 name,
2583 value); 2616 value);
2584 to_file (rps_peer->file_name_stats, 2617 to_file(rps_peer->file_name_stats,
2585 "%s: %" PRIu64 "\n", 2618 "%s: %" PRIu64 "\n",
2586 name, 2619 name,
2587 value); 2620 value);
2588 switch (stat_str_2_type (name)) 2621 switch (stat_str_2_type(name))
2589 { 2622 {
2590 case STAT_TYPE_ROUNDS: 2623 case STAT_TYPE_ROUNDS:
2591 rps_peer->num_rounds = value; 2624 rps_peer->num_rounds = value;
2592 break; 2625 break;
2626
2593 case STAT_TYPE_BLOCKS: 2627 case STAT_TYPE_BLOCKS:
2594 rps_peer->num_blocks = value; 2628 rps_peer->num_blocks = value;
2595 break; 2629 break;
2630
2596 case STAT_TYPE_BLOCKS_MANY_PUSH: 2631 case STAT_TYPE_BLOCKS_MANY_PUSH:
2597 rps_peer->num_blocks_many_push = value; 2632 rps_peer->num_blocks_many_push = value;
2598 break; 2633 break;
2634
2599 case STAT_TYPE_BLOCKS_NO_PUSH: 2635 case STAT_TYPE_BLOCKS_NO_PUSH:
2600 rps_peer->num_blocks_no_push = value; 2636 rps_peer->num_blocks_no_push = value;
2601 break; 2637 break;
2638
2602 case STAT_TYPE_BLOCKS_NO_PULL: 2639 case STAT_TYPE_BLOCKS_NO_PULL:
2603 rps_peer->num_blocks_no_pull = value; 2640 rps_peer->num_blocks_no_pull = value;
2604 break; 2641 break;
2642
2605 case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: 2643 case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL:
2606 rps_peer->num_blocks_many_push_no_pull = value; 2644 rps_peer->num_blocks_many_push_no_pull = value;
2607 break; 2645 break;
2646
2608 case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: 2647 case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL:
2609 rps_peer->num_blocks_no_push_no_pull = value; 2648 rps_peer->num_blocks_no_push_no_pull = value;
2610 break; 2649 break;
2650
2611 case STAT_TYPE_ISSUED_PUSH_SEND: 2651 case STAT_TYPE_ISSUED_PUSH_SEND:
2612 rps_peer->num_issued_push = value; 2652 rps_peer->num_issued_push = value;
2613 break; 2653 break;
2654
2614 case STAT_TYPE_ISSUED_PULL_REQ: 2655 case STAT_TYPE_ISSUED_PULL_REQ:
2615 rps_peer->num_issued_pull_req = value; 2656 rps_peer->num_issued_pull_req = value;
2616 break; 2657 break;
2658
2617 case STAT_TYPE_ISSUED_PULL_REP: 2659 case STAT_TYPE_ISSUED_PULL_REP:
2618 rps_peer->num_issued_pull_rep = value; 2660 rps_peer->num_issued_pull_rep = value;
2619 break; 2661 break;
2662
2620 case STAT_TYPE_SENT_PUSH_SEND: 2663 case STAT_TYPE_SENT_PUSH_SEND:
2621 rps_peer->num_sent_push = value; 2664 rps_peer->num_sent_push = value;
2622 break; 2665 break;
2666
2623 case STAT_TYPE_SENT_PULL_REQ: 2667 case STAT_TYPE_SENT_PULL_REQ:
2624 rps_peer->num_sent_pull_req = value; 2668 rps_peer->num_sent_pull_req = value;
2625 break; 2669 break;
2670
2626 case STAT_TYPE_SENT_PULL_REP: 2671 case STAT_TYPE_SENT_PULL_REP:
2627 rps_peer->num_sent_pull_rep = value; 2672 rps_peer->num_sent_pull_rep = value;
2628 break; 2673 break;
2674
2629 case STAT_TYPE_RECV_PUSH_SEND: 2675 case STAT_TYPE_RECV_PUSH_SEND:
2630 rps_peer->num_recv_push = value; 2676 rps_peer->num_recv_push = value;
2631 break; 2677 break;
2678
2632 case STAT_TYPE_RECV_PULL_REQ: 2679 case STAT_TYPE_RECV_PULL_REQ:
2633 rps_peer->num_recv_pull_req = value; 2680 rps_peer->num_recv_pull_req = value;
2634 break; 2681 break;
2682
2635 case STAT_TYPE_RECV_PULL_REP: 2683 case STAT_TYPE_RECV_PULL_REP:
2636 rps_peer->num_recv_pull_rep = value; 2684 rps_peer->num_recv_pull_rep = value;
2637 break; 2685 break;
2686
2638 case STAT_TYPE_MAX: 2687 case STAT_TYPE_MAX:
2639 default: 2688 default:
2640 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2689 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
2641 "Unknown statistics string: %s\n", 2690 "Unknown statistics string: %s\n",
2642 name); 2691 name);
2643 break; 2692 break;
2644 } 2693 }
2645 return GNUNET_OK; 2694 return GNUNET_OK;
2646} 2695}
2647 2696
2648void post_profiler (struct RPSPeer *rps_peer) 2697void post_profiler(struct RPSPeer *rps_peer)
2649{ 2698{
2650 if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics) 2699 if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics)
2651 { 2700 {
2652 return; 2701 return;
2653 } 2702 }
2654 2703
2655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2704 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2656 "Going to request statistic values with mask 0x%" PRIx32 "\n", 2705 "Going to request statistic values with mask 0x%" PRIx32 "\n",
2657 cur_test_run.stat_collect_flags); 2706 cur_test_run.stat_collect_flags);
2658 2707
2659 struct STATcls *stat_cls; 2708 struct STATcls *stat_cls;
2660 uint32_t stat_type; 2709 uint32_t stat_type;
2661 for (stat_type = STAT_TYPE_ROUNDS; 2710 for (stat_type = STAT_TYPE_ROUNDS;
2662 stat_type < STAT_TYPE_MAX; 2711 stat_type < STAT_TYPE_MAX;
2663 stat_type = stat_type <<1) 2712 stat_type = stat_type << 1)
2664 { 2713 {
2665 if (stat_type & cur_test_run.stat_collect_flags) 2714 if (stat_type & cur_test_run.stat_collect_flags)
2666 { 2715 {
2667 stat_cls = GNUNET_malloc (sizeof (struct STATcls)); 2716 stat_cls = GNUNET_malloc(sizeof(struct STATcls));
2668 stat_cls->rps_peer = rps_peer; 2717 stat_cls->rps_peer = rps_peer;
2669 stat_cls->stat_type = stat_type; 2718 stat_cls->stat_type = stat_type;
2670 rps_peer->file_name_stats = 2719 rps_peer->file_name_stats =
2671 store_prefix_file_name (rps_peer->peer_id, "stats"); 2720 store_prefix_file_name(rps_peer->peer_id, "stats");
2672 GNUNET_STATISTICS_get (rps_peer->stats_h, 2721 GNUNET_STATISTICS_get(rps_peer->stats_h,
2673 "rps", 2722 "rps",
2674 stat_type_2_str (stat_type), 2723 stat_type_2_str(stat_type),
2675 post_test_shutdown_ready_cb, 2724 post_test_shutdown_ready_cb,
2676 stat_iterator, 2725 stat_iterator,
2677 (struct STATcls *) stat_cls); 2726 (struct STATcls *)stat_cls);
2678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2727 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2679 "Requested statistics for %s (peer %" PRIu32 ")\n", 2728 "Requested statistics for %s (peer %" PRIu32 ")\n",
2680 stat_type_2_str (stat_type), 2729 stat_type_2_str(stat_type),
2681 rps_peer->index); 2730 rps_peer->index);
2682 } 2731 }
2683 } 2732 }
2684} 2733}
2685 2734
2686 2735
2687/*********************************************************************** 2736/***********************************************************************
2688 * /Definition of tests 2737* /Definition of tests
2689***********************************************************************/ 2738***********************************************************************/
2690 2739
2691 2740
@@ -2702,92 +2751,92 @@ void post_profiler (struct RPSPeer *rps_peer)
2702 * failed 2751 * failed
2703 */ 2752 */
2704static void 2753static void
2705run (void *cls, 2754run(void *cls,
2706 struct GNUNET_TESTBED_RunHandle *h, 2755 struct GNUNET_TESTBED_RunHandle *h,
2707 unsigned int n_peers, 2756 unsigned int n_peers,
2708 struct GNUNET_TESTBED_Peer **peers, 2757 struct GNUNET_TESTBED_Peer **peers,
2709 unsigned int links_succeeded, 2758 unsigned int links_succeeded,
2710 unsigned int links_failed) 2759 unsigned int links_failed)
2711{ 2760{
2712 (void) cls; 2761 (void)cls;
2713 (void) h; 2762 (void)h;
2714 (void) links_failed; 2763 (void)links_failed;
2715 unsigned int i; 2764 unsigned int i;
2716 struct OpListEntry *entry; 2765 struct OpListEntry *entry;
2717 2766
2718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); 2767 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n");
2719 2768
2720 /* Check whether we timed out */ 2769 /* Check whether we timed out */
2721 if (n_peers != num_peers || 2770 if (n_peers != num_peers ||
2722 NULL == peers || 2771 NULL == peers ||
2723 0 == links_succeeded) 2772 0 == links_succeeded)
2724 { 2773 {
2725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n"); 2774 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n");
2726 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); 2775 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers);
2727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers); 2776 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers);
2728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); 2777 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers);
2729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded); 2778 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded);
2730 GNUNET_SCHEDULER_shutdown (); 2779 GNUNET_SCHEDULER_shutdown();
2731 return; 2780 return;
2732 } 2781 }
2733 2782
2734 2783
2735 /* Initialize peers */ 2784 /* Initialize peers */
2736 testbed_peers = peers; 2785 testbed_peers = peers;
2737 num_peers_online = 0; 2786 num_peers_online = 0;
2738 for (i = 0; i < num_peers; i++) 2787 for (i = 0; i < num_peers; i++)
2739 { 2788 {
2740 entry = make_oplist_entry (); 2789 entry = make_oplist_entry();
2741 entry->index = i; 2790 entry->index = i;
2742 rps_peers[i].index = i; 2791 rps_peers[i].index = i;
2743 if (NULL != cur_test_run.init_peer) 2792 if (NULL != cur_test_run.init_peer)
2744 cur_test_run.init_peer (&rps_peers[i]); 2793 cur_test_run.init_peer(&rps_peers[i]);
2745 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) 2794 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
2746 { 2795 {
2747 rps_peers->cur_view_count = 0; 2796 rps_peers->cur_view_count = 0;
2748 rps_peers->cur_view = NULL; 2797 rps_peers->cur_view = NULL;
2749 } 2798 }
2750 entry->op = GNUNET_TESTBED_peer_get_information (peers[i], 2799 entry->op = GNUNET_TESTBED_peer_get_information(peers[i],
2751 GNUNET_TESTBED_PIT_IDENTITY, 2800 GNUNET_TESTBED_PIT_IDENTITY,
2752 &info_cb, 2801 &info_cb,
2753 entry); 2802 entry);
2754 } 2803 }
2755 2804
2756 /* Bring peers up */ 2805 /* Bring peers up */
2757 GNUNET_assert (num_peers == n_peers); 2806 GNUNET_assert(num_peers == n_peers);
2758 for (i = 0; i < n_peers; i++) 2807 for (i = 0; i < n_peers; i++)
2759 { 2808 {
2760 rps_peers[i].index = i; 2809 rps_peers[i].index = i;
2761 rps_peers[i].op = 2810 rps_peers[i].op =
2762 GNUNET_TESTBED_service_connect (&rps_peers[i], 2811 GNUNET_TESTBED_service_connect(&rps_peers[i],
2763 peers[i], 2812 peers[i],
2764 "rps", 2813 "rps",
2765 &rps_connect_complete_cb, 2814 &rps_connect_complete_cb,
2766 &rps_peers[i], 2815 &rps_peers[i],
2767 &rps_connect_adapter, 2816 &rps_connect_adapter,
2768 &rps_disconnect_adapter, 2817 &rps_disconnect_adapter,
2769 &rps_peers[i]); 2818 &rps_peers[i]);
2770 /* Connect all peers to statistics service */ 2819 /* Connect all peers to statistics service */
2771 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) 2820 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
2772 { 2821 {
2773 rps_peers[i].stat_op = 2822 rps_peers[i].stat_op =
2774 GNUNET_TESTBED_service_connect (NULL, 2823 GNUNET_TESTBED_service_connect(NULL,
2775 peers[i], 2824 peers[i],
2776 "statistics", 2825 "statistics",
2777 stat_complete_cb, 2826 stat_complete_cb,
2778 &rps_peers[i], 2827 &rps_peers[i],
2779 &stat_connect_adapter, 2828 &stat_connect_adapter,
2780 &stat_disconnect_adapter, 2829 &stat_disconnect_adapter,
2781 &rps_peers[i]); 2830 &rps_peers[i]);
2782 } 2831 }
2783 } 2832 }
2784 2833
2785 if (NULL != churn_task) 2834 if (NULL != churn_task)
2786 GNUNET_SCHEDULER_cancel (churn_task); 2835 GNUNET_SCHEDULER_cancel(churn_task);
2787 post_test_task = GNUNET_SCHEDULER_add_delayed (timeout, &post_test_op, NULL); 2836 post_test_task = GNUNET_SCHEDULER_add_delayed(timeout, &post_test_op, NULL);
2788 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2837 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
2789 (timeout_s * 1.2) + 0.1 * num_peers); 2838 (timeout_s * 1.2) + 0.1 * num_peers);
2790 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); 2839 shutdown_task = GNUNET_SCHEDULER_add_delayed(timeout, &shutdown_op, NULL);
2791} 2840}
2792 2841
2793 2842
@@ -2799,10 +2848,11 @@ run (void *cls,
2799 * @return 0 on success 2848 * @return 0 on success
2800 */ 2849 */
2801int 2850int
2802main (int argc, char *argv[]) 2851main(int argc, char *argv[])
2803{ 2852{
2804 int ret_value; 2853 int ret_value;
2805 (void) argc; 2854
2855 (void)argc;
2806 2856
2807 /* Defaults for tests */ 2857 /* Defaults for tests */
2808 num_peers = 5; 2858 num_peers = 5;
@@ -2819,174 +2869,174 @@ main (int argc, char *argv[])
2819 churn_task = NULL; 2869 churn_task = NULL;
2820 timeout_s = 30; 2870 timeout_s = 30;
2821 2871
2822 if (strstr (argv[0], "malicious") != NULL) 2872 if (strstr(argv[0], "malicious") != NULL)
2823 { 2873 {
2824 cur_test_run.pre_test = mal_pre; 2874 cur_test_run.pre_test = mal_pre;
2825 cur_test_run.main_test = mal_cb; 2875 cur_test_run.main_test = mal_cb;
2826 cur_test_run.init_peer = mal_init_peer; 2876 cur_test_run.init_peer = mal_init_peer;
2827 timeout_s = 40; 2877 timeout_s = 40;
2878
2879 if (strstr(argv[0], "_1") != NULL)
2880 {
2881 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
2882 cur_test_run.name = "test-rps-malicious_1";
2883 mal_type = 1;
2884 }
2885 else if (strstr(argv[0], "_2") != NULL)
2886 {
2887 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
2888 cur_test_run.name = "test-rps-malicious_2";
2889 mal_type = 2;
2890 }
2891 else if (strstr(argv[0], "_3") != NULL)
2892 {
2893 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n");
2894 cur_test_run.name = "test-rps-malicious_3";
2895 mal_type = 3;
2896 }
2897 }
2898
2899 else if (strstr(argv[0], "_single_req") != NULL)
2900 {
2901 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
2902 cur_test_run.name = "test-rps-single-req";
2903 cur_test_run.main_test = single_req_cb;
2904 cur_test_run.have_churn = HAVE_NO_CHURN;
2905 }
2906
2907 else if (strstr(argv[0], "_delayed_reqs") != NULL)
2908 {
2909 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
2910 cur_test_run.name = "test-rps-delayed-reqs";
2911 cur_test_run.main_test = delay_req_cb;
2912 cur_test_run.have_churn = HAVE_NO_CHURN;
2913 }
2914
2915 else if (strstr(argv[0], "_seed_big") != NULL)
2916 {
2917 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_MAX_MESSAGE_SIZE)\n");
2918 num_peers = 1;
2919 cur_test_run.name = "test-rps-seed-big";
2920 cur_test_run.main_test = seed_big_cb;
2921 cur_test_run.eval_cb = no_eval;
2922 cur_test_run.have_churn = HAVE_NO_CHURN;
2923 timeout_s = 10;
2924 }
2925
2926 else if (strstr(argv[0], "_single_peer_seed") != NULL)
2927 {
2928 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
2929 cur_test_run.name = "test-rps-single-peer-seed";
2930 cur_test_run.main_test = single_peer_seed_cb;
2931 cur_test_run.have_churn = HAVE_NO_CHURN;
2932 }
2933
2934 else if (strstr(argv[0], "_seed_request") != NULL)
2935 {
2936 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
2937 cur_test_run.name = "test-rps-seed-request";
2938 cur_test_run.main_test = seed_req_cb;
2939 cur_test_run.have_churn = HAVE_NO_CHURN;
2940 }
2941
2942 else if (strstr(argv[0], "_seed") != NULL)
2943 {
2944 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
2945 cur_test_run.name = "test-rps-seed";
2946 cur_test_run.main_test = seed_cb;
2947 cur_test_run.eval_cb = no_eval;
2948 cur_test_run.have_churn = HAVE_NO_CHURN;
2949 }
2950
2951 else if (strstr(argv[0], "_req_cancel") != NULL)
2952 {
2953 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
2954 cur_test_run.name = "test-rps-req-cancel";
2955 num_peers = 1;
2956 cur_test_run.main_test = req_cancel_cb;
2957 cur_test_run.eval_cb = no_eval;
2958 cur_test_run.have_churn = HAVE_NO_CHURN;
2959 timeout_s = 10;
2960 }
2828 2961
2829 if (strstr (argv[0], "_1") != NULL) 2962 else if (strstr(argv[0], "_churn") != NULL)
2830 { 2963 {
2831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n"); 2964 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test churn\n");
2832 cur_test_run.name = "test-rps-malicious_1"; 2965 cur_test_run.name = "test-rps-churn";
2833 mal_type = 1; 2966 num_peers = 5;
2967 cur_test_run.init_peer = default_init_peer;
2968 cur_test_run.main_test = churn_test_cb;
2969 cur_test_run.reply_handle = default_reply_handle;
2970 cur_test_run.eval_cb = default_eval_cb;
2971 cur_test_run.have_churn = HAVE_NO_CHURN;
2972 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
2973 timeout_s = 40;
2834 } 2974 }
2835 else if (strstr (argv[0], "_2") != NULL) 2975
2976 else if (strstr(argv[0], "_sub") != NULL)
2836 { 2977 {
2837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n"); 2978 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test subs\n");
2838 cur_test_run.name = "test-rps-malicious_2"; 2979 cur_test_run.name = "test-rps-sub";
2839 mal_type = 2; 2980 num_peers = 5;
2981 //cur_test_run.init_peer = &default_init_peer;
2982 cur_test_run.pre_test = &sub_pre;
2983 cur_test_run.main_test = &single_req_cb;
2984 //cur_test_run.reply_handle = default_reply_handle;
2985 cur_test_run.post_test = &sub_post;
2986 //cur_test_run.eval_cb = default_eval_cb;
2987 cur_test_run.have_churn = HAVE_NO_CHURN;
2988 cur_test_run.have_quick_quit = HAVE_QUICK_QUIT;
2840 } 2989 }
2841 else if (strstr (argv[0], "_3") != NULL) 2990
2991 else if (strstr(argv[0], "profiler") != NULL)
2842 { 2992 {
2843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n"); 2993 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
2844 cur_test_run.name = "test-rps-malicious_3"; 2994 cur_test_run.name = "test-rps-profiler";
2995 num_peers = 16;
2845 mal_type = 3; 2996 mal_type = 3;
2997 cur_test_run.init_peer = profiler_init_peer;
2998 //cur_test_run.pre_test = mal_pre;
2999 cur_test_run.pre_test = pre_profiler;
3000 cur_test_run.main_test = profiler_cb;
3001 cur_test_run.reply_handle = profiler_reply_handle;
3002 cur_test_run.eval_cb = profiler_eval;
3003 cur_test_run.post_test = post_profiler;
3004 cur_test_run.request_interval = 2;
3005 cur_test_run.num_requests = 5;
3006 //cur_test_run.have_churn = HAVE_CHURN;
3007 cur_test_run.have_churn = HAVE_NO_CHURN;
3008 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
3009 cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
3010 cur_test_run.stat_collect_flags = STAT_TYPE_ROUNDS |
3011 STAT_TYPE_BLOCKS |
3012 STAT_TYPE_BLOCKS_MANY_PUSH |
3013 STAT_TYPE_BLOCKS_NO_PUSH |
3014 STAT_TYPE_BLOCKS_NO_PULL |
3015 STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL |
3016 STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL |
3017 STAT_TYPE_ISSUED_PUSH_SEND |
3018 STAT_TYPE_ISSUED_PULL_REQ |
3019 STAT_TYPE_ISSUED_PULL_REP |
3020 STAT_TYPE_SENT_PUSH_SEND |
3021 STAT_TYPE_SENT_PULL_REQ |
3022 STAT_TYPE_SENT_PULL_REP |
3023 STAT_TYPE_RECV_PUSH_SEND |
3024 STAT_TYPE_RECV_PULL_REQ |
3025 STAT_TYPE_RECV_PULL_REP;
3026 cur_test_run.have_collect_view = COLLECT_VIEW;
3027 timeout_s = 150;
3028
3029 /* 'Clean' directory */
3030 (void)GNUNET_DISK_directory_remove("/tmp/rps/");
3031 GNUNET_DISK_directory_create("/tmp/rps/");
2846 } 3032 }
2847 } 3033 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, timeout_s);
2848 3034
2849 else if (strstr (argv[0], "_single_req") != NULL) 3035 rps_peers = GNUNET_new_array(num_peers, struct RPSPeer);
2850 { 3036 peer_map = GNUNET_CONTAINER_multipeermap_create(num_peers, GNUNET_NO);
2851 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n"); 3037 rps_peer_ids = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity);
2852 cur_test_run.name = "test-rps-single-req"; 3038 if ((2 == mal_type) ||
2853 cur_test_run.main_test = single_req_cb; 3039 (3 == mal_type))
2854 cur_test_run.have_churn = HAVE_NO_CHURN;
2855 }
2856
2857 else if (strstr (argv[0], "_delayed_reqs") != NULL)
2858 {
2859 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
2860 cur_test_run.name = "test-rps-delayed-reqs";
2861 cur_test_run.main_test = delay_req_cb;
2862 cur_test_run.have_churn = HAVE_NO_CHURN;
2863 }
2864
2865 else if (strstr (argv[0], "_seed_big") != NULL)
2866 {
2867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_MAX_MESSAGE_SIZE)\n");
2868 num_peers = 1;
2869 cur_test_run.name = "test-rps-seed-big";
2870 cur_test_run.main_test = seed_big_cb;
2871 cur_test_run.eval_cb = no_eval;
2872 cur_test_run.have_churn = HAVE_NO_CHURN;
2873 timeout_s = 10;
2874 }
2875
2876 else if (strstr (argv[0], "_single_peer_seed") != NULL)
2877 {
2878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
2879 cur_test_run.name = "test-rps-single-peer-seed";
2880 cur_test_run.main_test = single_peer_seed_cb;
2881 cur_test_run.have_churn = HAVE_NO_CHURN;
2882 }
2883
2884 else if (strstr (argv[0], "_seed_request") != NULL)
2885 {
2886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
2887 cur_test_run.name = "test-rps-seed-request";
2888 cur_test_run.main_test = seed_req_cb;
2889 cur_test_run.have_churn = HAVE_NO_CHURN;
2890 }
2891
2892 else if (strstr (argv[0], "_seed") != NULL)
2893 {
2894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
2895 cur_test_run.name = "test-rps-seed";
2896 cur_test_run.main_test = seed_cb;
2897 cur_test_run.eval_cb = no_eval;
2898 cur_test_run.have_churn = HAVE_NO_CHURN;
2899 }
2900
2901 else if (strstr (argv[0], "_req_cancel") != NULL)
2902 {
2903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
2904 cur_test_run.name = "test-rps-req-cancel";
2905 num_peers = 1;
2906 cur_test_run.main_test = req_cancel_cb;
2907 cur_test_run.eval_cb = no_eval;
2908 cur_test_run.have_churn = HAVE_NO_CHURN;
2909 timeout_s = 10;
2910 }
2911
2912 else if (strstr (argv[0], "_churn") != NULL)
2913 {
2914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test churn\n");
2915 cur_test_run.name = "test-rps-churn";
2916 num_peers = 5;
2917 cur_test_run.init_peer = default_init_peer;
2918 cur_test_run.main_test = churn_test_cb;
2919 cur_test_run.reply_handle = default_reply_handle;
2920 cur_test_run.eval_cb = default_eval_cb;
2921 cur_test_run.have_churn = HAVE_NO_CHURN;
2922 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
2923 timeout_s = 40;
2924 }
2925
2926 else if (strstr (argv[0], "_sub") != NULL)
2927 {
2928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test subs\n");
2929 cur_test_run.name = "test-rps-sub";
2930 num_peers = 5;
2931 //cur_test_run.init_peer = &default_init_peer;
2932 cur_test_run.pre_test = &sub_pre;
2933 cur_test_run.main_test = &single_req_cb;
2934 //cur_test_run.reply_handle = default_reply_handle;
2935 cur_test_run.post_test = &sub_post;
2936 //cur_test_run.eval_cb = default_eval_cb;
2937 cur_test_run.have_churn = HAVE_NO_CHURN;
2938 cur_test_run.have_quick_quit = HAVE_QUICK_QUIT;
2939 }
2940
2941 else if (strstr (argv[0], "profiler") != NULL)
2942 {
2943 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
2944 cur_test_run.name = "test-rps-profiler";
2945 num_peers = 16;
2946 mal_type = 3;
2947 cur_test_run.init_peer = profiler_init_peer;
2948 //cur_test_run.pre_test = mal_pre;
2949 cur_test_run.pre_test = pre_profiler;
2950 cur_test_run.main_test = profiler_cb;
2951 cur_test_run.reply_handle = profiler_reply_handle;
2952 cur_test_run.eval_cb = profiler_eval;
2953 cur_test_run.post_test = post_profiler;
2954 cur_test_run.request_interval = 2;
2955 cur_test_run.num_requests = 5;
2956 //cur_test_run.have_churn = HAVE_CHURN;
2957 cur_test_run.have_churn = HAVE_NO_CHURN;
2958 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
2959 cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
2960 cur_test_run.stat_collect_flags = STAT_TYPE_ROUNDS |
2961 STAT_TYPE_BLOCKS |
2962 STAT_TYPE_BLOCKS_MANY_PUSH |
2963 STAT_TYPE_BLOCKS_NO_PUSH |
2964 STAT_TYPE_BLOCKS_NO_PULL |
2965 STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL |
2966 STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL |
2967 STAT_TYPE_ISSUED_PUSH_SEND |
2968 STAT_TYPE_ISSUED_PULL_REQ |
2969 STAT_TYPE_ISSUED_PULL_REP |
2970 STAT_TYPE_SENT_PUSH_SEND |
2971 STAT_TYPE_SENT_PULL_REQ |
2972 STAT_TYPE_SENT_PULL_REP |
2973 STAT_TYPE_RECV_PUSH_SEND |
2974 STAT_TYPE_RECV_PULL_REQ |
2975 STAT_TYPE_RECV_PULL_REP;
2976 cur_test_run.have_collect_view = COLLECT_VIEW;
2977 timeout_s = 150;
2978
2979 /* 'Clean' directory */
2980 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
2981 GNUNET_DISK_directory_create ("/tmp/rps/");
2982 }
2983 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s);
2984
2985 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
2986 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
2987 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
2988 if ( (2 == mal_type) ||
2989 (3 == mal_type))
2990 target_peer = &rps_peer_ids[num_peers - 2]; 3040 target_peer = &rps_peer_ids[num_peers - 2];
2991 if (profiler_eval == cur_test_run.eval_cb) 3041 if (profiler_eval == cur_test_run.eval_cb)
2992 eval_peer = &rps_peers[num_peers - 1]; /* FIXME: eval_peer could be a 3042 eval_peer = &rps_peers[num_peers - 1]; /* FIXME: eval_peer could be a
@@ -2994,30 +3044,30 @@ main (int argc, char *argv[])
2994 with the malicious portion */ 3044 with the malicious portion */
2995 3045
2996 ok = 1; 3046 ok = 1;
2997 ret_value = GNUNET_TESTBED_test_run (cur_test_run.name, 3047 ret_value = GNUNET_TESTBED_test_run(cur_test_run.name,
2998 "test_rps.conf", 3048 "test_rps.conf",
2999 num_peers, 3049 num_peers,
3000 0, NULL, NULL, 3050 0, NULL, NULL,
3001 &run, NULL); 3051 &run, NULL);
3002 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3052 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
3003 "_test_run returned.\n"); 3053 "_test_run returned.\n");
3004 if (GNUNET_OK != ret_value) 3054 if (GNUNET_OK != ret_value)
3005 { 3055 {
3006 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3056 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
3007 "Test did not run successfully!\n"); 3057 "Test did not run successfully!\n");
3008 } 3058 }
3009 3059
3010 ret_value = cur_test_run.eval_cb(); 3060 ret_value = cur_test_run.eval_cb();
3011 3061
3012 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) 3062 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
3013 { 3063 {
3014 GNUNET_array_grow (rps_peers->cur_view, 3064 GNUNET_array_grow(rps_peers->cur_view,
3015 rps_peers->cur_view_count, 3065 rps_peers->cur_view_count,
3016 0); 3066 0);
3017 } 3067 }
3018 GNUNET_free (rps_peers); 3068 GNUNET_free(rps_peers);
3019 GNUNET_free (rps_peer_ids); 3069 GNUNET_free(rps_peer_ids);
3020 GNUNET_CONTAINER_multipeermap_destroy (peer_map); 3070 GNUNET_CONTAINER_multipeermap_destroy(peer_map);
3021 return ret_value; 3071 return ret_value;
3022} 3072}
3023 3073