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