2 This file is part of GNUnet.
3 Copyright (C) 2009, 2012 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file rps/test_rps.c
22 * @brief Testcase for the random peer sampling service. Starts
23 * a peergroup with a given number of peers, then waits to
24 * receive size pushes/pulls from each peer. Expects to wait
25 * for one message from each peer.
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
31 #include "gnunet_rps_service.h"
32 #include "rps-test_util.h"
33 #include "gnunet-service-rps_sampler_elem.h"
39 * How many peers do we start?
41 static uint32_t num_peers;
44 * How long do we run the test?
46 //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
47 static struct GNUNET_TIME_Relative timeout;
51 * Portion of malicious peers
53 static double portion = .1;
56 * Type of malicious peer to test
58 static unsigned int mal_type = 0;
61 * Handles to all of the running peers
63 static struct GNUNET_TESTBED_Peer **testbed_peers;
66 * @brief Indicates whether peer should go off- or online
68 enum PEER_ONLINE_DELTA {
70 * @brief Indicates peer going online
74 * @brief Indicates peer going offline
87 struct OpListEntry *next;
92 struct OpListEntry *prev;
95 * The testbed operation
97 struct GNUNET_TESTBED_Operation *op;
100 * Depending on whether we start or stop RPS service at the peer, set this to
101 * #PEER_GO_ONLINE (1) or #PEER_GO_OFFLINE (-1)
103 enum PEER_ONLINE_DELTA delta;
106 * Index of the regarding peer
114 static struct OpListEntry *oplist_head;
119 static struct OpListEntry *oplist_tail;
123 * A pending reply: A request was sent and the reply is pending.
130 struct PendingReply *next;
131 struct PendingReply *prev;
134 * Handle to the request we are waiting for
136 struct GNUNET_RPS_Request_Handle *req_handle;
139 * The peer that requested
141 struct RPSPeer *rps_peer;
146 * A pending request: A request was not made yet but is scheduled for later.
148 struct PendingRequest
153 struct PendingRequest *next;
154 struct PendingRequest *prev;
157 * Handle to the request we are waiting for
159 struct GNUNET_SCHEDULER_Task *request_task;
162 * The peer that requested
164 struct RPSPeer *rps_peer;
169 * Information we track for each peer.
179 * Handle for RPS connect operation.
181 struct GNUNET_TESTBED_Operation *op;
184 * Handle to RPS service.
186 struct GNUNET_RPS_Handle *rps_handle;
191 struct GNUNET_PeerIdentity *peer_id;
194 * A request handle to check for an request
196 //struct GNUNET_RPS_Request_Handle *req_handle;
199 * Peer on- or offline?
204 * Number of Peer IDs to request during the whole test
206 unsigned int num_ids_to_request;
209 * Pending requests DLL
211 struct PendingRequest *pending_req_head;
212 struct PendingRequest *pending_req_tail;
215 * Number of pending requests
217 unsigned int num_pending_reqs;
220 * Pending replies DLL
222 struct PendingReply *pending_rep_head;
223 struct PendingReply *pending_rep_tail;
226 * Number of pending replies
228 unsigned int num_pending_reps;
231 * Number of received PeerIDs
233 unsigned int num_recv_ids;
236 * Pending operation on that peer
238 const struct OpListEntry *entry_op_manage;
241 * Testbed operation to connect to statistics service
243 struct GNUNET_TESTBED_Operation *stat_op;
246 * Handle to the statistics service
248 struct GNUNET_STATISTICS_Handle *stats_h;
251 * @brief flags to indicate which statistics values have been already
252 * collected from the statistics service.
253 * Used to check whether we are able to shutdown.
255 uint32_t stat_collected_flags;
258 * @brief File name of the file the stats are finally written to
260 const char *file_name_stats;
263 * @brief File name of the file the stats are finally written to
265 const char *file_name_probs;
268 * @brief The current view
270 struct GNUNET_PeerIdentity *cur_view;
273 * @brief Number of peers in the #cur_view.
275 uint32_t cur_view_count;
278 * @brief Number of occurrences in other peer's view
280 uint32_t count_in_views;
283 * @brief statistics values
287 uint64_t num_blocks_many_push;
288 uint64_t num_blocks_no_push;
289 uint64_t num_blocks_no_pull;
290 uint64_t num_blocks_many_push_no_pull;
291 uint64_t num_blocks_no_push_no_pull;
292 uint64_t num_issued_push;
293 uint64_t num_issued_pull_req;
294 uint64_t num_issued_pull_rep;
295 uint64_t num_sent_push;
296 uint64_t num_sent_pull_req;
297 uint64_t num_sent_pull_rep;
298 uint64_t num_recv_push;
299 uint64_t num_recv_pull_req;
300 uint64_t num_recv_pull_rep;
305 STAT_TYPE_ROUNDS = 0x1, /* 1 */
306 STAT_TYPE_BLOCKS = 0x2, /* 2 */
307 STAT_TYPE_BLOCKS_MANY_PUSH = 0x4, /* 3 */
308 STAT_TYPE_BLOCKS_NO_PUSH = 0x8, /* 4 */
309 STAT_TYPE_BLOCKS_NO_PULL = 0x10, /* 5 */
310 STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL = 0x20, /* 6 */
311 STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL = 0x40, /* 7 */
312 STAT_TYPE_ISSUED_PUSH_SEND = 0x80, /* 8 */
313 STAT_TYPE_ISSUED_PULL_REQ = 0x100, /* 9 */
314 STAT_TYPE_ISSUED_PULL_REP = 0x200, /* 10 */
315 STAT_TYPE_SENT_PUSH_SEND = 0x400, /* 11 */
316 STAT_TYPE_SENT_PULL_REQ = 0x800, /* 12 */
317 STAT_TYPE_SENT_PULL_REP = 0x1000, /* 13 */
318 STAT_TYPE_RECV_PUSH_SEND = 0x2000, /* 14 */
319 STAT_TYPE_RECV_PULL_REQ = 0x4000, /* 15 */
320 STAT_TYPE_RECV_PULL_REP = 0x8000, /* 16 */
321 STAT_TYPE_MAX = 0x80000000, /* 32 */
326 struct RPSPeer *rps_peer;
327 enum STAT_TYPE stat_type;
332 * Information for all the peers.
334 static struct RPSPeer *rps_peers;
337 * Peermap to get the index of a given peer ID quick.
339 static struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
344 static struct GNUNET_PeerIdentity *rps_peer_ids;
347 * ID of the targeted peer.
349 static struct GNUNET_PeerIdentity *target_peer;
352 * ID of the peer that requests for the evaluation.
354 static struct RPSPeer *eval_peer;
357 * Number of online peers.
359 static unsigned int num_peers_online;
362 * @brief The added sizes of the peer's views
364 static unsigned int view_sizes;
367 * Return value from 'main'.
372 * Identifier for the churn task that runs periodically
374 static struct GNUNET_SCHEDULER_Task *shutdown_task;
377 * Identifier for the churn task that runs periodically
379 static struct GNUNET_SCHEDULER_Task *churn_task;
382 * Called to initialise the given RPSPeer
384 typedef void (*InitPeer) (struct RPSPeer *rps_peer);
387 * @brief Called directly after connecting to the service
389 * @param rps_peer Specific peer the function is called on
390 * @param h the handle to the rps service
392 typedef void (*PreTest) (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h);
395 * @brief Executes functions to test the api/service for a given peer
397 * Called from within #rps_connect_complete_cb ()
398 * Implemented by #churn_test_cb, #profiler_cb, #mal_cb, #single_req_cb,
399 * #delay_req_cb, #seed_big_cb, #single_peer_seed_cb, #seed_cb, #req_cancel_cb
401 * @param rps_peer the peer the task runs on
403 typedef void (*MainTest) (struct RPSPeer *rps_peer);
406 * Callback called once the requested random peers are available
408 typedef void (*ReplyHandle) (void *cls,
410 const struct GNUNET_PeerIdentity *recv_peers);
413 * Called directly before disconnecting from the service
415 typedef void (*PostTest) (struct RPSPeer *peer);
418 * Function called after disconnect to evaluate test success
420 typedef int (*EvaluationCallback) (void);
423 * @brief Do we have Churn?
427 * @brief If we have churn this is set
431 * @brief If we have no churn this is set
437 * @brief Is it ok to quit the test before the timeout?
439 enum OPTION_QUICK_QUIT {
441 * @brief It is ok for the test to quit before the timeout triggers
446 * @brief It is NOT ok for the test to quit before the timeout triggers
452 * @brief Do we collect statistics at the end?
454 enum OPTION_COLLECT_STATISTICS {
456 * @brief We collect statistics at the end
461 * @brief We do not collect statistics at the end
463 NO_COLLECT_STATISTICS,
467 * @brief Do we collect views during run?
469 enum OPTION_COLLECT_VIEW {
471 * @brief We collect view during run
476 * @brief We do not collect the view during run
482 * Structure to define a single test
492 * Called with a single peer in order to initialise that peer
497 * Called directly after connecting to the service
502 * Main function for each peer
507 * Callback called once the requested peers are available
509 ReplyHandle reply_handle;
512 * Called directly before disconnecting from the service
517 * Function to evaluate the test results
519 EvaluationCallback eval_cb;
524 uint32_t request_interval;
527 * Number of Requests to make.
529 uint32_t num_requests;
532 * Run with (-out) churn
534 enum OPTION_CHURN have_churn;
537 * Quit test before timeout?
539 enum OPTION_QUICK_QUIT have_quick_quit;
542 * Collect statistics at the end?
544 enum OPTION_COLLECT_STATISTICS have_collect_statistics;
547 * Collect view during run?
549 enum OPTION_COLLECT_VIEW have_collect_view;
552 * @brief Mark which values from the statistics service to collect at the end
555 uint32_t stat_collect_flags;
559 * Are we shutting down?
561 static int in_shutdown;
564 * Append arguments to file
567 tofile_ (const char *file_name, const char *line)
569 struct GNUNET_DISK_FileHandle *f;
570 /* char output_buffer[512]; */
575 if (NULL == (f = GNUNET_DISK_file_open (file_name,
576 GNUNET_DISK_OPEN_APPEND |
577 GNUNET_DISK_OPEN_WRITE |
578 GNUNET_DISK_OPEN_CREATE,
579 GNUNET_DISK_PERM_USER_READ |
580 GNUNET_DISK_PERM_USER_WRITE |
581 GNUNET_DISK_PERM_GROUP_READ |
582 GNUNET_DISK_PERM_OTHER_READ)))
584 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
585 "Not able to open file %s\n",
589 /* size = GNUNET_snprintf (output_buffer,
590 sizeof (output_buffer),
592 GNUNET_TIME_absolute_get ().abs_value_us,
596 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
597 "Failed to write string to buffer (size: %i)\n",
602 size = strlen (line) * sizeof (char);
604 size2 = GNUNET_DISK_file_write (f, line, size);
607 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
608 "Unable to write to file! (Size: %lu, size2: %lu)\n",
611 if (GNUNET_YES != GNUNET_DISK_file_close (f))
613 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
614 "Unable to close file\n");
619 if (GNUNET_YES != GNUNET_DISK_file_close (f))
621 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
622 "Unable to close file\n");
627 * This function is used to facilitate writing important information to disk
629 #define tofile(file_name, ...) do {\
632 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
634 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
635 "Failed to create tmp_buf\n");\
637 tofile_(file_name,tmp_buf);\
642 * Write the ids and their according index in the given array to a file
646 ids_to_file (char *file_name,
647 struct GNUNET_PeerIdentity *peer_ids,
648 unsigned int num_peer_ids)
652 for (i=0 ; i < num_peer_ids ; i++)
657 GNUNET_i2s_full (&peer_ids[i]));
662 * Test the success of a single test
672 for (i = 0; i < num_peers; i++)
674 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
675 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
677 GNUNET_i2s (rps_peers[i].peer_id),
678 rps_peers[i].num_recv_ids,
679 rps_peers[i].num_ids_to_request,
680 (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids));
681 tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids);
683 return tmp_ok? 0 : 1;
688 * Creates an oplist entry and adds it to the oplist DLL
690 static struct OpListEntry *
693 struct OpListEntry *entry;
695 entry = GNUNET_new (struct OpListEntry);
696 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
702 * @brief Checks if given peer already received its statistics value from the
703 * statistics service.
705 * @param rps_peer the peer to check for
707 * @return #GNUNET_YES if so
708 * #GNUNET_NO otherwise
710 static int check_statistics_collect_completed_single_peer (
711 const struct RPSPeer *rps_peer)
713 if (cur_test_run.stat_collect_flags !=
714 (cur_test_run.stat_collect_flags &
715 rps_peer->stat_collected_flags))
722 * @brief Checks if all peers already received their statistics value from the
723 * statistics service.
725 * @return #GNUNET_YES if so
726 * #GNUNET_NO otherwise
728 static int check_statistics_collect_completed ()
732 for (i = 0; i < num_peers; i++)
734 if (GNUNET_NO == check_statistics_collect_completed_single_peer (&rps_peers[i]))
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "At least Peer %" PRIu32 " did not yet receive all statistics values\n",
742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
743 "All peers received their statistics values\n");
748 * Task run on timeout to shut everything down.
751 shutdown_op (void *cls)
755 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
756 "Shutdown task scheduled, going down.\n");
757 in_shutdown = GNUNET_YES;
758 if (NULL != churn_task)
760 GNUNET_SCHEDULER_cancel (churn_task);
763 for (i = 0; i < num_peers; i++)
765 if (NULL != rps_peers[i].op)
766 GNUNET_TESTBED_operation_done (rps_peers[i].op);
767 if (NULL != cur_test_run.post_test)
769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i);
770 cur_test_run.post_test (&rps_peers[i]);
773 /* If we do not collect statistics, shut down directly */
774 if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics ||
775 GNUNET_YES == check_statistics_collect_completed())
777 GNUNET_SCHEDULER_shutdown ();
786 seed_peers (void *cls)
788 struct RPSPeer *peer = cls;
792 // TODO if malicious don't seed mal peers
793 amount = round (.5 * num_peers);
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
796 for (i = 0 ; i < amount ; i++)
797 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
799 GNUNET_i2s (&rps_peer_ids[i]));
801 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
809 seed_peers_big (void *cls)
811 struct RPSPeer *peer = cls;
812 unsigned int seed_msg_size;
813 uint32_t num_peers_max;
817 seed_msg_size = 8; /* sizeof (struct GNUNET_RPS_CS_SeedMessage) */
818 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - seed_msg_size) /
819 sizeof (struct GNUNET_PeerIdentity);
820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
821 "Peers that fit in one seed msg; %u\n",
823 amount = num_peers_max + (0.5 * num_peers_max);
824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
825 "Seeding many (%u) peers:\n",
827 struct GNUNET_PeerIdentity ids_to_seed[amount];
828 for (i = 0; i < amount; i++)
830 ids_to_seed[i] = *peer->peer_id;
831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
833 GNUNET_i2s (&ids_to_seed[i]));
836 GNUNET_RPS_seed_ids (peer->rps_handle, amount, ids_to_seed);
840 * Get the id of peer i.
843 info_cb (void *cb_cls,
844 struct GNUNET_TESTBED_Operation *op,
845 const struct GNUNET_TESTBED_PeerInformation *pinfo,
848 struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
850 if (GNUNET_YES == in_shutdown)
855 if (NULL == pinfo || NULL != emsg)
857 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
858 GNUNET_TESTBED_operation_done (entry->op);
862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
865 GNUNET_i2s (pinfo->result.id));
867 rps_peer_ids[entry->index] = *(pinfo->result.id);
868 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
870 GNUNET_assert (GNUNET_OK ==
871 GNUNET_CONTAINER_multipeermap_put (peer_map,
872 &rps_peer_ids[entry->index],
873 &rps_peers[entry->index],
874 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
875 tofile ("/tmp/rps/peer_ids",
878 GNUNET_i2s_full (&rps_peer_ids[entry->index]));
880 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
881 GNUNET_TESTBED_operation_done (entry->op);
887 * Callback to be called when RPS service connect operation is completed
889 * @param cls the callback closure from functions generating an operation
890 * @param op the operation that has been finished
891 * @param ca_result the RPS service handle returned from rps_connect_adapter
892 * @param emsg error message in case the operation has failed; will be NULL if
893 * operation has executed successfully.
896 rps_connect_complete_cb (void *cls,
897 struct GNUNET_TESTBED_Operation *op,
901 struct RPSPeer *rps_peer = cls;
902 struct GNUNET_RPS_Handle *rps = ca_result;
904 if (GNUNET_YES == in_shutdown)
909 rps_peer->rps_handle = rps;
910 rps_peer->online = GNUNET_YES;
913 GNUNET_assert (op == rps_peer->op);
916 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
917 "Failed to connect to RPS service: %s\n",
920 GNUNET_SCHEDULER_shutdown ();
924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
926 cur_test_run.main_test (rps_peer);
931 * Adapter function called to establish a connection to
935 * @param cfg configuration of the peer to connect to; will be available until
936 * GNUNET_TESTBED_operation_done() is called on the operation returned
937 * from GNUNET_TESTBED_service_connect()
938 * @return service handle to return in 'op_result', NULL on error
941 rps_connect_adapter (void *cls,
942 const struct GNUNET_CONFIGURATION_Handle *cfg)
944 struct GNUNET_RPS_Handle *h;
946 h = GNUNET_RPS_connect (cfg);
948 if (NULL != cur_test_run.pre_test)
949 cur_test_run.pre_test (cls, h);
955 * Called to open a connection to the peer's statistics
957 * @param cls peer context
958 * @param cfg configuration of the peer to connect to; will be available until
959 * GNUNET_TESTBED_operation_done() is called on the operation returned
960 * from GNUNET_TESTBED_service_connect()
961 * @return service handle to return in 'op_result', NULL on error
964 stat_connect_adapter (void *cls,
965 const struct GNUNET_CONFIGURATION_Handle *cfg)
967 struct RPSPeer *peer = cls;
969 peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg);
970 return peer->stats_h;
974 * Called to disconnect from peer's statistics service
976 * @param cls peer context
977 * @param op_result service handle returned from the connect adapter
980 stat_disconnect_adapter (void *cls, void *op_result)
982 struct RPSPeer *peer = cls;
984 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
985 // (peer->stats_h, "core", "# peers connected",
986 // stat_iterator, peer));
987 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
988 // (peer->stats_h, "nse", "# peers connected",
989 // stat_iterator, peer));
990 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
991 peer->stats_h = NULL;
995 * Called after successfully opening a connection to a peer's statistics
996 * service; we register statistics monitoring for CORE and NSE here.
998 * @param cls the callback closure from functions generating an operation
999 * @param op the operation that has been finished
1000 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1001 * @param emsg error message in case the operation has failed; will be NULL if
1002 * operation has executed successfully.
1005 stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
1006 void *ca_result, const char *emsg )
1008 //struct GNUNET_STATISTICS_Handle *sh = ca_result;
1009 //struct RPSPeer *peer = (struct RPSPeer *) cls;
1016 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1017 // (sh, "core", "# peers connected",
1018 // stat_iterator, peer));
1019 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1020 // (sh, "nse", "# peers connected",
1021 // stat_iterator, peer));
1026 * Adapter function called to destroy connection to
1029 * @param cls closure
1030 * @param op_result service handle returned from the connect adapter
1033 rps_disconnect_adapter (void *cls,
1036 struct RPSPeer *peer = cls;
1037 struct GNUNET_RPS_Handle *h = op_result;
1038 GNUNET_assert (NULL != peer);
1039 GNUNET_RPS_disconnect (h);
1040 peer->rps_handle = NULL;
1044 /***********************************************************************
1045 * Definition of tests
1046 ***********************************************************************/
1048 // TODO check whether tests can be stopped earlier
1050 default_eval_cb (void)
1062 * Initialise given RPSPeer
1064 static void default_init_peer (struct RPSPeer *rps_peer)
1066 rps_peer->num_ids_to_request = 1;
1070 * Callback to call on receipt of a reply
1072 * @param cls closure
1073 * @param n number of peers
1074 * @param recv_peers the received peers
1077 default_reply_handle (void *cls,
1079 const struct GNUNET_PeerIdentity *recv_peers)
1081 struct RPSPeer *rps_peer;
1082 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1085 rps_peer = pending_rep->rps_peer;
1086 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1087 rps_peer->pending_rep_tail,
1089 rps_peer->num_pending_reps--;
1090 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1091 "[%s] got %" PRIu64 " peers:\n",
1092 GNUNET_i2s (rps_peer->peer_id),
1095 for (i = 0; i < n; i++)
1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1100 GNUNET_i2s (&recv_peers[i]));
1102 rps_peer->num_recv_ids++;
1105 if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit)
1107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n");
1108 GNUNET_assert (NULL != shutdown_task);
1109 GNUNET_SCHEDULER_cancel (shutdown_task);
1110 shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL);
1111 GNUNET_assert (NULL!= shutdown_task);
1116 * Request random peers.
1119 request_peers (void *cls)
1121 struct PendingRequest *pending_req = cls;
1122 struct RPSPeer *rps_peer;
1123 struct PendingReply *pending_rep;
1125 if (GNUNET_YES == in_shutdown)
1127 rps_peer = pending_req->rps_peer;
1128 GNUNET_assert (1 <= rps_peer->num_pending_reqs);
1129 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1130 rps_peer->pending_req_tail,
1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1133 "Requesting one peer\n");
1134 pending_rep = GNUNET_new (struct PendingReply);
1135 pending_rep->rps_peer = rps_peer;
1136 pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle,
1138 cur_test_run.reply_handle,
1140 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head,
1141 rps_peer->pending_rep_tail,
1143 rps_peer->num_pending_reps++;
1144 rps_peer->num_pending_reqs--;
1148 cancel_pending_req (struct PendingRequest *pending_req)
1150 struct RPSPeer *rps_peer;
1152 rps_peer = pending_req->rps_peer;
1153 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1154 rps_peer->pending_req_tail,
1156 rps_peer->num_pending_reqs--;
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1158 "Cancelling pending request\n");
1159 GNUNET_SCHEDULER_cancel (pending_req->request_task);
1160 GNUNET_free (pending_req);
1164 cancel_request (struct PendingReply *pending_rep)
1166 struct RPSPeer *rps_peer;
1168 rps_peer = pending_rep->rps_peer;
1169 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1170 rps_peer->pending_rep_tail,
1172 rps_peer->num_pending_reps--;
1173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1174 "Cancelling request\n");
1175 GNUNET_RPS_request_cancel (pending_rep->req_handle);
1176 GNUNET_free (pending_rep);
1183 cancel_request_cb (void *cls)
1185 struct RPSPeer *rps_peer = cls;
1186 struct PendingReply *pending_rep;
1188 if (GNUNET_YES == in_shutdown)
1190 pending_rep = rps_peer->pending_rep_head;
1191 GNUNET_assert (1 <= rps_peer->num_pending_reps);
1192 cancel_request (pending_rep);
1197 * Schedule requests for peer @a rps_peer that have neither been scheduled, nor
1198 * issued, nor replied
1201 schedule_missing_requests (struct RPSPeer *rps_peer)
1204 struct PendingRequest *pending_req;
1206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1207 "Scheduling %u - %u missing requests\n",
1208 rps_peer->num_ids_to_request,
1209 rps_peer->num_pending_reqs + rps_peer->num_pending_reps);
1210 GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <=
1211 rps_peer->num_ids_to_request);
1212 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps;
1213 i < rps_peer->num_ids_to_request; i++)
1215 pending_req = GNUNET_new (struct PendingRequest);
1216 pending_req->rps_peer = rps_peer;
1217 pending_req->request_task = GNUNET_SCHEDULER_add_delayed (
1218 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1219 cur_test_run.request_interval * i),
1222 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head,
1223 rps_peer->pending_req_tail,
1225 rps_peer->num_pending_reqs++;
1230 cancel_pending_req_rep (struct RPSPeer *rps_peer)
1232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1233 "Cancelling all (pending) requests.\n");
1234 while (NULL != rps_peer->pending_req_head)
1235 cancel_pending_req (rps_peer->pending_req_head);
1236 GNUNET_assert (0 == rps_peer->num_pending_reqs);
1237 while (NULL != rps_peer->pending_rep_head)
1238 cancel_request (rps_peer->pending_rep_head);
1239 GNUNET_assert (0 == rps_peer->num_pending_reps);
1242 /***********************************
1244 ***********************************/
1247 * Initialise only non-mal RPSPeers
1249 static void mal_init_peer (struct RPSPeer *rps_peer)
1251 if (rps_peer->index >= round (portion * num_peers))
1252 rps_peer->num_ids_to_request = 1;
1257 * @brief Set peers to (non-)malicious before execution
1259 * Of signature #PreTest
1261 * @param rps_peer the peer to set (non-) malicious
1262 * @param h the handle to the service
1265 mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1267 #ifdef ENABLE_MALICIOUS
1268 uint32_t num_mal_peers;
1270 GNUNET_assert ( (1 >= portion) &&
1272 num_mal_peers = round (portion * num_peers);
1274 if (rps_peer->index < num_mal_peers)
1276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1277 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
1279 GNUNET_i2s (rps_peer->peer_id),
1282 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers,
1283 rps_peer_ids, target_peer);
1285 #endif /* ENABLE_MALICIOUS */
1289 mal_cb (struct RPSPeer *rps_peer)
1291 uint32_t num_mal_peers;
1293 if (GNUNET_YES == in_shutdown)
1298 #ifdef ENABLE_MALICIOUS
1299 GNUNET_assert ( (1 >= portion) &&
1301 num_mal_peers = round (portion * num_peers);
1303 if (rps_peer->index >= num_mal_peers)
1304 { /* It's useless to ask a malicious peer about a random sample -
1305 it's not sampling */
1306 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1307 seed_peers, rps_peer);
1308 schedule_missing_requests (rps_peer);
1310 #endif /* ENABLE_MALICIOUS */
1314 /***********************************
1316 ***********************************/
1318 single_req_cb (struct RPSPeer *rps_peer)
1320 if (GNUNET_YES == in_shutdown)
1325 schedule_missing_requests (rps_peer);
1328 /***********************************
1330 ***********************************/
1332 delay_req_cb (struct RPSPeer *rps_peer)
1334 if (GNUNET_YES == in_shutdown)
1339 schedule_missing_requests (rps_peer);
1342 /***********************************
1344 ***********************************/
1346 seed_cb (struct RPSPeer *rps_peer)
1348 if (GNUNET_YES == in_shutdown)
1353 GNUNET_SCHEDULER_add_delayed (
1354 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
1355 seed_peers, rps_peer);
1358 /***********************************
1360 ***********************************/
1362 seed_big_cb (struct RPSPeer *rps_peer)
1364 if (GNUNET_YES == in_shutdown)
1369 // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers
1370 GNUNET_SCHEDULER_add_delayed (
1371 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1372 seed_peers_big, rps_peer);
1375 /***********************************
1377 ***********************************/
1379 single_peer_seed_cb (struct RPSPeer *rps_peer)
1384 /***********************************
1386 ***********************************/
1388 seed_req_cb (struct RPSPeer *rps_peer)
1390 if (GNUNET_YES == in_shutdown)
1395 GNUNET_SCHEDULER_add_delayed (
1396 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1397 seed_peers, rps_peer);
1398 schedule_missing_requests (rps_peer);
1401 //TODO start big mal
1403 /***********************************
1405 ***********************************/
1407 req_cancel_cb (struct RPSPeer *rps_peer)
1409 if (GNUNET_YES == in_shutdown)
1414 schedule_missing_requests (rps_peer);
1415 GNUNET_SCHEDULER_add_delayed (
1416 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1417 (cur_test_run.request_interval + 1)),
1418 cancel_request_cb, rps_peer);
1421 /***********************************
1423 ***********************************/
1429 * @brief Starts churn
1431 * Has signature of #MainTest
1433 * This is not implemented too nicely as this is called for each peer, but we
1434 * only need to call it once. (Yes we check that we only schedule the task
1437 * @param rps_peer The peer it's called for
1440 churn_test_cb (struct RPSPeer *rps_peer)
1442 if (GNUNET_YES == in_shutdown)
1448 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task)
1450 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1451 "Starting churn task\n");
1452 churn_task = GNUNET_SCHEDULER_add_delayed (
1453 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1458 "Not starting churn task\n");
1461 schedule_missing_requests (rps_peer);
1464 /***********************************
1466 ***********************************/
1469 * Callback to be called when RPS service is started or stopped at peers
1472 * @param op the operation handle
1473 * @param emsg NULL on success; otherwise an error description
1476 churn_cb (void *cls,
1477 struct GNUNET_TESTBED_Operation *op,
1481 struct OpListEntry *entry = cls;
1483 if (GNUNET_YES == in_shutdown)
1488 GNUNET_TESTBED_operation_done (entry->op);
1491 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n");
1492 GNUNET_SCHEDULER_shutdown ();
1495 GNUNET_assert (0 != entry->delta);
1497 num_peers_online += entry->delta;
1499 if (PEER_GO_OFFLINE == entry->delta)
1500 { /* Peer hopefully just went offline */
1501 if (GNUNET_YES != rps_peers[entry->index].online)
1503 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1504 "peer %s was expected to go offline but is still marked as online\n",
1505 GNUNET_i2s (rps_peers[entry->index].peer_id));
1510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1511 "peer %s probably went offline as expected\n",
1512 GNUNET_i2s (rps_peers[entry->index].peer_id));
1514 rps_peers[entry->index].online = GNUNET_NO;
1517 else if (PEER_GO_ONLINE < entry->delta)
1518 { /* Peer hopefully just went online */
1519 if (GNUNET_NO != rps_peers[entry->index].online)
1521 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1522 "peer %s was expected to go online but is still marked as offline\n",
1523 GNUNET_i2s (rps_peers[entry->index].peer_id));
1528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1529 "peer %s probably went online as expected\n",
1530 GNUNET_i2s (rps_peers[entry->index].peer_id));
1531 if (NULL != cur_test_run.pre_test)
1533 cur_test_run.pre_test (&rps_peers[entry->index],
1534 rps_peers[entry->index].rps_handle);
1535 schedule_missing_requests (&rps_peers[entry->index]);
1538 rps_peers[entry->index].online = GNUNET_YES;
1542 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1543 "Invalid value for delta: %i\n", entry->delta);
1547 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1548 rps_peers[entry->index].entry_op_manage = NULL;
1549 GNUNET_free (entry);
1550 //if (num_peers_in_round[current_round] == peers_running)
1555 * @brief Set the rps-service up or down for a specific peer
1557 * @param i index of action
1558 * @param j index of peer
1559 * @param delta (#PEER_ONLINE_DELTA) down (-1) or up (1)
1560 * @param prob_go_on_off the probability of the action
1563 manage_service_wrapper (unsigned int i, unsigned int j,
1564 enum PEER_ONLINE_DELTA delta,
1565 double prob_go_on_off)
1567 struct OpListEntry *entry = NULL;
1570 /* make sure that management operation is not already scheduled */
1571 if (NULL != rps_peers[j].entry_op_manage)
1576 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1579 "%u. selected peer (%u: %s) is %s.\n",
1582 GNUNET_i2s (rps_peers[j].peer_id),
1583 (PEER_GO_ONLINE == delta) ? "online" : "offline");
1584 if (prob < prob_go_on_off * UINT32_MAX)
1586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1588 GNUNET_i2s (rps_peers[j].peer_id),
1589 (PEER_GO_OFFLINE == delta) ? "offline" : "online");
1591 if (PEER_GO_OFFLINE == delta)
1592 cancel_pending_req_rep (&rps_peers[j]);
1593 entry = make_oplist_entry ();
1594 entry->delta = delta;
1596 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
1601 (PEER_GO_OFFLINE == delta) ? 0 : 1);
1602 rps_peers[j].entry_op_manage = entry;
1612 double portion_online;
1613 unsigned int *permut;
1614 double prob_go_offline;
1615 double portion_go_online;
1616 double portion_go_offline;
1618 if (GNUNET_YES == in_shutdown)
1622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1623 "Churn function executing\n");
1625 churn_task = NULL; /* Should be invalid by now */
1627 /* Compute the probability for an online peer to go offline
1629 portion_online = num_peers_online * 1.0 / num_peers;
1630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1631 "Portion online: %f\n",
1633 portion_go_online = ((1 - portion_online) * .5 * .66);
1634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1635 "Portion that should go online: %f\n",
1637 portion_go_offline = (portion_online + portion_go_online) - .75;
1638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1639 "Portion that probably goes offline: %f\n",
1640 portion_go_offline);
1641 prob_go_offline = portion_go_offline / (portion_online * .5);
1642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1643 "Probability of a selected online peer to go offline: %f\n",
1646 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
1647 (unsigned int) num_peers);
1649 /* Go over 50% randomly chosen peers */
1650 for (i = 0; i < .5 * num_peers; i++)
1654 /* If online, shut down with certain probability */
1655 if (GNUNET_YES == rps_peers[j].online)
1657 manage_service_wrapper (i, j, -1, prob_go_offline);
1660 /* If offline, restart with certain probability */
1661 else if (GNUNET_NO == rps_peers[j].online)
1663 manage_service_wrapper (i, j, 1, 0.66);
1667 GNUNET_free (permut);
1669 churn_task = GNUNET_SCHEDULER_add_delayed (
1670 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1677 * Initialise given RPSPeer
1679 static void profiler_init_peer (struct RPSPeer *rps_peer)
1681 if (num_peers - 1 == rps_peer->index)
1682 rps_peer->num_ids_to_request = cur_test_run.num_requests;
1687 * Callback to call on receipt of a reply
1689 * @param cls closure
1690 * @param n number of peers
1691 * @param recv_peers the received peers
1694 profiler_reply_handle (void *cls,
1696 const struct GNUNET_PeerIdentity *recv_peers)
1698 struct RPSPeer *rps_peer;
1699 struct RPSPeer *rcv_rps_peer;
1703 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1705 rps_peer = pending_rep->rps_peer;
1706 file_name = "/tmp/rps/received_ids";
1707 file_name_dh = "/tmp/rps/diehard_input";
1708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1709 "[%s] got %" PRIu64 " peers:\n",
1710 GNUNET_i2s (rps_peer->peer_id),
1712 for (i = 0; i < n; i++)
1714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1717 GNUNET_i2s (&recv_peers[i]));
1720 GNUNET_i2s_full (&recv_peers[i]));
1721 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]);
1722 GNUNET_assert (NULL != rcv_rps_peer);
1723 tofile (file_name_dh,
1725 (uint32_t) rcv_rps_peer->index);
1727 default_reply_handle (cls, n, recv_peers);
1732 profiler_cb (struct RPSPeer *rps_peer)
1734 if (GNUNET_YES == in_shutdown)
1740 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task)
1742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1743 "Starting churn task\n");
1744 churn_task = GNUNET_SCHEDULER_add_delayed (
1745 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1750 "Not starting churn task\n");
1753 /* Only request peer ids at one peer.
1754 * (It's the before-last because last one is target of the focussed attack.)
1756 if (eval_peer == rps_peer)
1757 schedule_missing_requests (rps_peer);
1761 * Function called from #profiler_eval with a filename.
1763 * @param cls closure
1764 * @param filename complete filename (absolute path)
1765 * @return #GNUNET_OK to continue to iterate,
1766 * #GNUNET_NO to stop iteration with no error,
1767 * #GNUNET_SYSERR to abort iteration with error!
1770 file_name_cb (void *cls, const char *filename)
1772 if (NULL != strstr (filename, "sampler_el"))
1774 struct RPS_SamplerElement *s_elem;
1775 struct GNUNET_CRYPTO_AuthKey auth_key;
1776 const char *key_char;
1779 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
1780 tofile (filename, "--------------------------\n");
1782 auth_key = string_to_auth_key (key_char);
1783 s_elem = RPS_sampler_elem_create ();
1784 RPS_sampler_elem_set (s_elem, auth_key);
1786 for (i = 0; i < num_peers; i++)
1788 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
1790 RPS_sampler_elem_destroy (s_elem);
1796 * This is run after the test finished.
1798 * Compute all perfect samples.
1801 profiler_eval (void)
1803 /* Compute perfect sample for each sampler element */
1804 if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL))
1806 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
1813 * @brief Try to ensure that `/tmp/rps` exists.
1815 * @return #GNUNET_YES on success
1816 * #GNUNET_SYSERR on failure
1818 static int ensure_folder_exist (void)
1820 if (GNUNET_NO == GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
1822 GNUNET_DISK_directory_create ("/tmp/rps");
1824 if (GNUNET_YES != GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
1826 return GNUNET_SYSERR;
1832 store_prefix_file_name (struct RPSPeer *rps_peer, const char *prefix)
1834 unsigned int len_file_name;
1835 unsigned int out_size;
1837 const char *pid_long;
1839 if (GNUNET_SYSERR == ensure_folder_exist()) return NULL;
1840 pid_long = GNUNET_i2s_full (rps_peer->peer_id);
1841 len_file_name = (strlen (prefix) +
1845 file_name = GNUNET_malloc (len_file_name);
1846 out_size = GNUNET_snprintf (file_name,
1851 if (len_file_name < out_size ||
1854 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1855 "Failed to write string to buffer (size: %i, out_size: %i)\n",
1862 static uint32_t fac (uint32_t x)
1868 return x * fac (x - 1);
1871 static uint32_t binom (uint32_t n, uint32_t k)
1873 //GNUNET_assert (n >= k);
1874 if (k > n) return 0;
1875 if (0 > n) return 0;
1876 if (0 > k) return 0;
1877 if (0 == k) return 1;
1880 fac(k) * fac(n - k);
1884 * @brief is b in view of a?
1891 static int is_in_view (uint32_t a, uint32_t b)
1894 for (i = 0; i < rps_peers[a].cur_view_count; i++)
1896 if (0 == memcmp (rps_peers[b].peer_id,
1897 &rps_peers[a].cur_view[i],
1898 sizeof (struct GNUNET_PeerIdentity)))
1906 static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid)
1910 for (i = 0; i < num_peers; i++)
1912 if (0 == memcmp (pid,
1913 rps_peers[i].peer_id,
1914 sizeof (struct GNUNET_PeerIdentity)))
1919 //return 0; /* Should not happen - make compiler happy */
1920 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1921 "No known _PeerIdentity %s!\n",
1922 GNUNET_i2s_full (pid));
1927 * @brief Counts number of peers in view of a that have b in their view
1934 static uint32_t count_containing_views (uint32_t a, uint32_t b)
1940 for (i = 0; i < rps_peers[a].cur_view_count; i++)
1942 peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]);
1943 if (GNUNET_YES == is_in_view (peer_idx, b))
1952 * @brief Computes the probability for each other peer to be selected by the
1953 * sampling process based on the views of all peers
1955 * @param peer_idx index of the peer that is about to sample
1957 static void compute_probabilities (uint32_t peer_idx)
1959 //double probs[num_peers] = { 0 };
1960 double probs[num_peers];
1961 size_t probs_as_str_size = (num_peers * 6 + 1) * sizeof (char);
1962 char *probs_as_str = GNUNET_malloc (probs_as_str_size);
1963 char *probs_as_str_cpy;
1968 uint32_t cont_views;
1969 uint32_t number_of_being_in_pull_events;
1971 uint32_t count_non_zero_prob = 0;
1973 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1974 "Computing probabilities for peer %" PRIu32 "\n", peer_idx);
1975 /* Firstly without knowledge of old views */
1976 for (i = 0; i < num_peers; i++)
1978 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1979 "\tfor peer %" PRIu32 ":\n", i);
1980 view_size = rps_peers[i].cur_view_count;
1981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1982 "\t\tview_size: %" PRIu32 "\n", view_size);
1983 /* For peer i the probability of being sampled is
1984 * evenly distributed among all possibly observed peers. */
1985 /* We could have observed a peer in three cases:
1986 * 1. peer sent a push
1987 * 2. peer was contained in a pull reply
1988 * 3. peer was in history (sampler) - ignored for now */
1989 /* 1. Probability of having received a push from peer i */
1990 if ((GNUNET_YES == is_in_view (i, peer_idx)) &&
1991 (1 <= (0.45 * view_size)))
1993 prob_push = 1.0 * binom (0.45 * view_size, 1)
1995 binom (view_size, 0.45 * view_size);
1996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1997 "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n",
2003 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2004 "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n",
2008 /* 2. Probability of peer i being contained in pulls */
2009 view_size = rps_peers[peer_idx].cur_view_count;
2010 cont_views = count_containing_views (peer_idx, i);
2011 number_of_being_in_pull_events =
2012 (binom (view_size, 0.45 * view_size) -
2013 binom (view_size - cont_views, 0.45 * view_size));
2014 if (0 != number_of_being_in_pull_events)
2016 prob_pull = 1.0 / number_of_being_in_pull_events;
2021 probs[i] = prob_push + prob_pull - (prob_push * prob_pull);
2022 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2023 "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32
2024 " peers in its view who know %" PRIu32 " prob: %f\n",
2030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2031 "\t\tnumber of possible pull combinations: %" PRIu32 "\n",
2032 binom (view_size, 0.45 * view_size));
2033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2034 "\t\tnumber of possible pull combinations without %" PRIu32
2037 binom (view_size - cont_views, 0.45 * view_size));
2038 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2039 "\t\tnumber of possible pull combinations with %" PRIu32
2042 number_of_being_in_pull_events);
2044 if (0 != probs[i]) count_non_zero_prob++;
2047 if (0 != count_non_zero_prob)
2049 for (i = 0; i < num_peers; i++)
2051 probs[i] = probs[i] * (1.0 / count_non_zero_prob);
2054 for (i = 0; i < num_peers; i++)
2060 for (i = 0; i < num_peers; i++)
2062 probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size);
2063 tmp = GNUNET_snprintf (probs_as_str,
2065 "%s %3.2f", probs_as_str_cpy, probs[i]);
2066 GNUNET_free (probs_as_str_cpy);
2067 GNUNET_assert (0 <= tmp);
2070 to_file_w_len (rps_peers[peer_idx].file_name_probs,
2073 GNUNET_free (probs_as_str);
2077 * @brief This counts the number of peers in which views a given peer occurs.
2079 * It also stores this value in the rps peer.
2081 * @param peer_idx the index of the peer to count the representation
2083 * @return the number of occurrences
2085 static uint32_t count_peer_in_views_2 (uint32_t peer_idx)
2090 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2092 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2094 if (0 == memcmp (rps_peers[peer_idx].peer_id,
2095 &rps_peers[i].cur_view[j],
2096 sizeof (struct GNUNET_PeerIdentity)))
2103 rps_peers[peer_idx].count_in_views = count;
2107 static uint32_t cumulated_view_sizes ()
2112 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2114 view_sizes += rps_peers[i].cur_view_count;
2119 static void count_peer_in_views (uint32_t *count_peers)
2123 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2125 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2127 if (0 == memcmp (rps_peers[i].peer_id,
2128 &rps_peers[i].cur_view[j],
2129 sizeof (struct GNUNET_PeerIdentity)))
2137 void compute_diversity ()
2140 /* ith entry represents the numer of occurrences in other peer's views */
2141 uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t);
2142 uint32_t views_total_size;
2144 /* deviation from expected number of peers */
2145 double *deviation = GNUNET_new_array (num_peers, double);
2147 views_total_size = 0;
2150 /* For each peer count its representation in other peer's views*/
2151 for (i = 0; i < num_peers; i++) /* Peer to count */
2153 views_total_size += rps_peers[i].cur_view_count;
2154 count_peer_in_views (count_peers);
2155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2156 "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32"\n",
2158 GNUNET_i2s (rps_peers[i].peer_id),
2162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2163 "size of all views combined: %" PRIu32 "\n",
2165 expected = ((double) 1/num_peers) * views_total_size;
2166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2167 "Expected number of occurrences of each peer in all views: %f\n",
2169 for (i = 0; i < num_peers; i++) /* Peer to count */
2171 deviation[i] = expected - count_peers[i];
2172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2173 "Deviation from expectation: %f\n", deviation[i]);
2175 GNUNET_free (count_peers);
2176 GNUNET_free (deviation);
2179 void print_view_sizes()
2183 for (i = 0; i < num_peers; i++) /* Peer to count */
2185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2186 "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n",
2188 GNUNET_i2s (rps_peers[i].peer_id),
2189 rps_peers[i].cur_view_count);
2193 void all_views_updated_cb()
2195 compute_diversity();
2199 void view_update_cb (void *cls,
2201 const struct GNUNET_PeerIdentity *peers)
2203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2204 "View was updated (%" PRIu64 ")\n", view_size);
2205 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
2206 to_file ("/tmp/rps/view_sizes.txt",
2207 "%" PRIu64 " %" PRIu32 "",
2210 for (int i = 0; i < view_size; i++)
2212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2213 "\t%s\n", GNUNET_i2s (&peers[i]));
2215 GNUNET_array_grow (rps_peer->cur_view,
2216 rps_peer->cur_view_count,
2218 //*rps_peer->cur_view = *peers;
2219 memcpy (rps_peer->cur_view,
2221 view_size * sizeof (struct GNUNET_PeerIdentity));
2222 to_file ("/tmp/rps/count_in_views.txt",
2223 "%" PRIu64 " %" PRIu32 "",
2225 count_peer_in_views_2 (rps_peer->index));
2226 cumulated_view_sizes();
2227 to_file ("/tmp/rps/repr.txt",
2228 "%" PRIu64 /* index */
2229 " %" PRIu32 /* occurrence in views */
2230 " %" PRIu32 /* view sizes */
2231 " %f" /* fraction of repr in views */
2232 " %f" /* average view size */
2233 " %f" /* prob of occurrence in view slot */
2234 " %f" "", /* exp frac of repr in views */
2236 count_peer_in_views_2 (rps_peer->index),
2238 count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */
2239 view_sizes / (view_size * 1.0), /* average view size */
2240 1.0 /view_size, /* prob of occurrence in view slot */
2241 (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */
2243 compute_probabilities (rps_peer->index);
2244 all_views_updated_cb();
2248 pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
2250 rps_peer->file_name_probs = store_prefix_file_name (rps_peer, "probs");
2251 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer);
2254 void write_final_stats (void){
2257 for (i = 0; i < num_peers; i++)
2259 to_file ("/tmp/rps/final_stats.dat",
2260 "%" PRIu32 " " /* index */
2262 PRIu64 " %" /* rounds */
2263 PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */
2264 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */
2265 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */
2266 PRIu64 " %" PRIu64 " %" PRIu64 /* recv */,
2268 GNUNET_i2s (rps_peers[i].peer_id),
2269 rps_peers[i].num_rounds,
2270 rps_peers[i].num_blocks,
2271 rps_peers[i].num_blocks_many_push,
2272 rps_peers[i].num_blocks_no_push,
2273 rps_peers[i].num_blocks_no_pull,
2274 rps_peers[i].num_blocks_many_push_no_pull,
2275 rps_peers[i].num_blocks_no_push_no_pull,
2276 rps_peers[i].num_issued_push,
2277 rps_peers[i].num_issued_pull_req,
2278 rps_peers[i].num_issued_pull_rep,
2279 rps_peers[i].num_sent_push,
2280 rps_peers[i].num_sent_pull_req,
2281 rps_peers[i].num_sent_pull_rep,
2282 rps_peers[i].num_recv_push,
2283 rps_peers[i].num_recv_pull_req,
2284 rps_peers[i].num_recv_pull_rep);
2289 * Continuation called by #GNUNET_STATISTICS_get() functions.
2291 * Remembers that this specific statistics value was received for this peer.
2292 * Checks whether all peers received their statistics yet.
2293 * Issues the shutdown.
2295 * @param cls closure
2296 * @param success #GNUNET_OK if statistics were
2297 * successfully obtained, #GNUNET_SYSERR if not.
2300 post_test_shutdown_ready_cb (void *cls,
2303 struct STATcls *stat_cls = (struct STATcls *) cls;
2304 struct RPSPeer *rps_peer = stat_cls->rps_peer;
2305 if (GNUNET_OK == success)
2307 /* set flag that we we got the value */
2308 rps_peer->stat_collected_flags |= stat_cls->stat_type;
2310 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2311 "Peer %u did not receive statistics value\n",
2313 GNUNET_free (stat_cls);
2317 if (NULL != rps_peer->stat_op &&
2318 GNUNET_YES == check_statistics_collect_completed_single_peer (rps_peer))
2320 GNUNET_TESTBED_operation_done (rps_peer->stat_op);
2323 write_final_stats ();
2324 if (GNUNET_YES == check_statistics_collect_completed())
2326 //write_final_stats ();
2327 GNUNET_free (stat_cls);
2328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2330 GNUNET_SCHEDULER_shutdown ();
2332 GNUNET_free (stat_cls);
2337 * @brief Converts string representation to the corresponding #STAT_TYPE enum.
2339 * @param stat_str string representation of statistics specifier
2341 * @return corresponding enum
2343 enum STAT_TYPE stat_str_2_type (const char *stat_str)
2345 if (0 == strncmp ("# rounds blocked - no pull replies", stat_str, strlen ("# rounds blocked - no pull replies")))
2347 return STAT_TYPE_BLOCKS_NO_PULL;
2349 else if (0 == strncmp ("# rounds blocked - too many pushes, no pull replies", stat_str, strlen ("# rounds blocked - too many pushes, no pull replies")))
2351 return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL;
2353 else if (0 == strncmp ("# rounds blocked - too many pushes", stat_str, strlen ("# rounds blocked - too many pushes")))
2355 return STAT_TYPE_BLOCKS_MANY_PUSH;
2357 else if (0 == strncmp ("# rounds blocked - no pushes, no pull replies", stat_str, strlen ("# rounds blocked - no pushes, no pull replies")))
2359 return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL;
2361 else if (0 == strncmp ("# rounds blocked - no pushes", stat_str, strlen ("# rounds blocked - no pushes")))
2363 return STAT_TYPE_BLOCKS_NO_PUSH;
2365 else if (0 == strncmp ("# rounds blocked", stat_str, strlen ("# rounds blocked")))
2367 return STAT_TYPE_BLOCKS;
2369 else if (0 == strncmp ("# rounds", stat_str, strlen ("# rounds")))
2371 return STAT_TYPE_ROUNDS;
2373 else if (0 == strncmp ("# push send issued", stat_str, strlen ("# push send issued")))
2375 return STAT_TYPE_ISSUED_PUSH_SEND;
2377 else if (0 == strncmp ("# pull request send issued", stat_str, strlen ("# pull request send issued")))
2379 return STAT_TYPE_ISSUED_PULL_REQ;
2381 else if (0 == strncmp ("# pull reply send issued", stat_str, strlen ("# pull reply send issued")))
2383 return STAT_TYPE_ISSUED_PULL_REP;
2385 else if (0 == strncmp ("# pushes sent", stat_str, strlen ("# pushes sent")))
2387 return STAT_TYPE_SENT_PUSH_SEND;
2389 else if (0 == strncmp ("# pull requests sent", stat_str, strlen ("# pull requests sent")))
2391 return STAT_TYPE_SENT_PULL_REQ;
2393 else if (0 == strncmp ("# pull replys sent", stat_str, strlen ("# pull replys sent")))
2395 return STAT_TYPE_SENT_PULL_REP;
2397 else if (0 == strncmp ("# push message received", stat_str, strlen ("# push message received")))
2399 return STAT_TYPE_RECV_PUSH_SEND;
2401 else if (0 == strncmp ("# pull request message received", stat_str, strlen ("# pull request message received")))
2403 return STAT_TYPE_RECV_PULL_REQ;
2405 else if (0 == strncmp ("# pull reply messages received", stat_str, strlen ("# pull reply messages received")))
2407 return STAT_TYPE_RECV_PULL_REP;
2409 return STAT_TYPE_MAX;
2414 * @brief Converts #STAT_TYPE enum to the equivalent string representation that
2415 * is stored with the statistics service.
2417 * @param stat_type #STAT_TYPE enum
2419 * @return string representation that matches statistics value
2421 char* stat_type_2_str (enum STAT_TYPE stat_type)
2425 case STAT_TYPE_ROUNDS:
2427 case STAT_TYPE_BLOCKS:
2428 return "# rounds blocked";
2429 case STAT_TYPE_BLOCKS_MANY_PUSH:
2430 return "# rounds blocked - too many pushes";
2431 case STAT_TYPE_BLOCKS_NO_PUSH:
2432 return "# rounds blocked - no pushes";
2433 case STAT_TYPE_BLOCKS_NO_PULL:
2434 return "# rounds blocked - no pull replies";
2435 case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL:
2436 return "# rounds blocked - too many pushes, no pull replies";
2437 case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL:
2438 return "# rounds blocked - no pushes, no pull replies";
2439 case STAT_TYPE_ISSUED_PUSH_SEND:
2440 return "# push send issued";
2441 case STAT_TYPE_ISSUED_PULL_REQ:
2442 return "# pull request send issued";
2443 case STAT_TYPE_ISSUED_PULL_REP:
2444 return "# pull reply send issued";
2445 case STAT_TYPE_SENT_PUSH_SEND:
2446 return "# pushes sent";
2447 case STAT_TYPE_SENT_PULL_REQ:
2448 return "# pull requests sent";
2449 case STAT_TYPE_SENT_PULL_REP:
2450 return "# pull replys sent";
2451 case STAT_TYPE_RECV_PUSH_SEND:
2452 return "# push message received";
2453 case STAT_TYPE_RECV_PULL_REQ:
2454 return "# pull request message received";
2455 case STAT_TYPE_RECV_PULL_REP:
2456 return "# pull reply messages received";
2465 * Callback function to process statistic values.
2467 * @param cls closure
2468 * @param subsystem name of subsystem that created the statistic
2469 * @param name the name of the datum
2470 * @param value the current value
2471 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
2472 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
2475 stat_iterator (void *cls,
2476 const char *subsystem,
2481 const struct STATcls *stat_cls = (const struct STATcls *) cls;
2482 struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer;
2483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n",
2484 //stat_type_2_str (stat_cls->stat_type),
2487 to_file (rps_peer->file_name_stats,
2488 "%s: %" PRIu64 "\n",
2491 switch (stat_str_2_type (name))
2493 case STAT_TYPE_ROUNDS:
2494 rps_peer->num_rounds = value;
2496 case STAT_TYPE_BLOCKS:
2497 rps_peer->num_blocks = value;
2499 case STAT_TYPE_BLOCKS_MANY_PUSH:
2500 rps_peer->num_blocks_many_push = value;
2502 case STAT_TYPE_BLOCKS_NO_PUSH:
2503 rps_peer->num_blocks_no_push = value;
2505 case STAT_TYPE_BLOCKS_NO_PULL:
2506 rps_peer->num_blocks_no_pull = value;
2508 case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL:
2509 rps_peer->num_blocks_many_push_no_pull = value;
2511 case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL:
2512 rps_peer->num_blocks_no_push_no_pull = value;
2514 case STAT_TYPE_ISSUED_PUSH_SEND:
2515 rps_peer->num_issued_push = value;
2517 case STAT_TYPE_ISSUED_PULL_REQ:
2518 rps_peer->num_issued_pull_req = value;
2520 case STAT_TYPE_ISSUED_PULL_REP:
2521 rps_peer->num_issued_pull_rep = value;
2523 case STAT_TYPE_SENT_PUSH_SEND:
2524 rps_peer->num_sent_push = value;
2526 case STAT_TYPE_SENT_PULL_REQ:
2527 rps_peer->num_sent_pull_req = value;
2529 case STAT_TYPE_SENT_PULL_REP:
2530 rps_peer->num_sent_pull_rep = value;
2532 case STAT_TYPE_RECV_PUSH_SEND:
2533 rps_peer->num_recv_push = value;
2535 case STAT_TYPE_RECV_PULL_REQ:
2536 rps_peer->num_recv_pull_req = value;
2538 case STAT_TYPE_RECV_PULL_REP:
2539 rps_peer->num_recv_pull_rep = value;
2543 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2544 "Unknown statistics string: %s\n",
2551 void post_profiler (struct RPSPeer *rps_peer)
2553 if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics)
2558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2559 "Going to request statistic values with mask 0x%" PRIx32 "\n",
2560 cur_test_run.stat_collect_flags);
2562 struct STATcls *stat_cls;
2564 for (stat_type = STAT_TYPE_ROUNDS;
2565 stat_type < STAT_TYPE_MAX;
2566 stat_type = stat_type <<1)
2568 if (stat_type & cur_test_run.stat_collect_flags)
2570 stat_cls = GNUNET_malloc (sizeof (struct STATcls));
2571 stat_cls->rps_peer = rps_peer;
2572 stat_cls->stat_type = stat_type;
2573 rps_peer->file_name_stats = store_prefix_file_name (rps_peer, "stats");
2574 GNUNET_STATISTICS_get (rps_peer->stats_h,
2576 stat_type_2_str (stat_type),
2577 post_test_shutdown_ready_cb,
2579 (struct STATcls *) stat_cls);
2580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2581 "Requested statistics for %s (peer %" PRIu32 ")\n",
2582 stat_type_2_str (stat_type),
2589 /***********************************************************************
2590 * /Definition of tests
2591 ***********************************************************************/
2595 * Actual "main" function for the testcase.
2597 * @param cls closure
2598 * @param h the run handle
2599 * @param n_peers number of peers in 'peers'
2600 * @param peers handle to peers run in the testbed
2601 * @param links_succeeded the number of overlay link connection attempts that
2603 * @param links_failed the number of overlay link connection attempts that
2608 struct GNUNET_TESTBED_RunHandle *h,
2609 unsigned int n_peers,
2610 struct GNUNET_TESTBED_Peer **peers,
2611 unsigned int links_succeeded,
2612 unsigned int links_failed)
2615 struct OpListEntry *entry;
2617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n");
2619 /* Check whether we timed out */
2620 if (n_peers != num_peers ||
2622 0 == links_succeeded)
2624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n");
2625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers);
2626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers);
2627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers);
2628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded);
2629 GNUNET_SCHEDULER_shutdown ();
2634 /* Initialize peers */
2635 testbed_peers = peers;
2636 num_peers_online = 0;
2637 for (i = 0; i < num_peers; i++)
2639 entry = make_oplist_entry ();
2641 rps_peers[i].index = i;
2642 if (NULL != cur_test_run.init_peer)
2643 cur_test_run.init_peer (&rps_peers[i]);
2644 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
2646 rps_peers->cur_view_count = 0;
2647 rps_peers->cur_view = NULL;
2649 entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
2650 GNUNET_TESTBED_PIT_IDENTITY,
2655 /* Bring peers up */
2656 GNUNET_assert (num_peers == n_peers);
2657 for (i = 0; i < n_peers; i++)
2659 rps_peers[i].index = i;
2661 GNUNET_TESTBED_service_connect (&rps_peers[i],
2664 &rps_connect_complete_cb,
2666 &rps_connect_adapter,
2667 &rps_disconnect_adapter,
2669 /* Connect all peers to statistics service */
2670 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
2672 rps_peers[i].stat_op =
2673 GNUNET_TESTBED_service_connect (NULL,
2678 &stat_connect_adapter,
2679 &stat_disconnect_adapter,
2684 if (NULL != churn_task)
2685 GNUNET_SCHEDULER_cancel (churn_task);
2686 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
2691 * Entry point for the testcase, sets up the testbed.
2693 * @param argc unused
2694 * @param argv unused
2695 * @return 0 on success
2698 main (int argc, char *argv[])
2702 /* Defaults for tests */
2704 cur_test_run.name = "test-rps-default";
2705 cur_test_run.init_peer = default_init_peer;
2706 cur_test_run.pre_test = NULL;
2707 cur_test_run.reply_handle = default_reply_handle;
2708 cur_test_run.eval_cb = default_eval_cb;
2709 cur_test_run.post_test = NULL;
2710 cur_test_run.have_churn = HAVE_CHURN;
2711 cur_test_run.have_collect_statistics = NO_COLLECT_STATISTICS;
2712 cur_test_run.stat_collect_flags = 0;
2713 cur_test_run.have_collect_view = NO_COLLECT_VIEW;
2715 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
2717 if (strstr (argv[0], "malicious") != NULL)
2719 cur_test_run.pre_test = mal_pre;
2720 cur_test_run.main_test = mal_cb;
2721 cur_test_run.init_peer = mal_init_peer;
2723 if (strstr (argv[0], "_1") != NULL)
2725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
2726 cur_test_run.name = "test-rps-malicious_1";
2729 else if (strstr (argv[0], "_2") != NULL)
2731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
2732 cur_test_run.name = "test-rps-malicious_2";
2735 else if (strstr (argv[0], "_3") != NULL)
2737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n");
2738 cur_test_run.name = "test-rps-malicious_3";
2743 else if (strstr (argv[0], "_single_req") != NULL)
2745 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
2746 cur_test_run.name = "test-rps-single-req";
2747 cur_test_run.main_test = single_req_cb;
2748 cur_test_run.have_churn = HAVE_NO_CHURN;
2751 else if (strstr (argv[0], "_delayed_reqs") != NULL)
2753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
2754 cur_test_run.name = "test-rps-delayed-reqs";
2755 cur_test_run.main_test = delay_req_cb;
2756 cur_test_run.have_churn = HAVE_NO_CHURN;
2759 else if (strstr (argv[0], "_seed_big") != NULL)
2761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_MAX_MESSAGE_SIZE)\n");
2763 cur_test_run.name = "test-rps-seed-big";
2764 cur_test_run.main_test = seed_big_cb;
2765 cur_test_run.eval_cb = no_eval;
2766 cur_test_run.have_churn = HAVE_NO_CHURN;
2767 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
2770 else if (strstr (argv[0], "_single_peer_seed") != NULL)
2772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
2773 cur_test_run.name = "test-rps-single-peer-seed";
2774 cur_test_run.main_test = single_peer_seed_cb;
2775 cur_test_run.have_churn = HAVE_NO_CHURN;
2778 else if (strstr (argv[0], "_seed_request") != NULL)
2780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
2781 cur_test_run.name = "test-rps-seed-request";
2782 cur_test_run.main_test = seed_req_cb;
2783 cur_test_run.have_churn = HAVE_NO_CHURN;
2786 else if (strstr (argv[0], "_seed") != NULL)
2788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
2789 cur_test_run.name = "test-rps-seed";
2790 cur_test_run.main_test = seed_cb;
2791 cur_test_run.eval_cb = no_eval;
2792 cur_test_run.have_churn = HAVE_NO_CHURN;
2795 else if (strstr (argv[0], "_req_cancel") != NULL)
2797 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
2798 cur_test_run.name = "test-rps-req-cancel";
2800 cur_test_run.main_test = req_cancel_cb;
2801 cur_test_run.eval_cb = no_eval;
2802 cur_test_run.have_churn = HAVE_NO_CHURN;
2803 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
2806 else if (strstr (argv[0], "_churn") != NULL)
2808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test churn\n");
2809 cur_test_run.name = "test-rps-churn";
2811 cur_test_run.init_peer = default_init_peer;
2812 cur_test_run.main_test = churn_test_cb;
2813 cur_test_run.reply_handle = default_reply_handle;
2814 cur_test_run.eval_cb = default_eval_cb;
2815 cur_test_run.have_churn = HAVE_CHURN;
2816 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
2817 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
2820 else if (strstr (argv[0], "profiler") != NULL)
2822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
2823 cur_test_run.name = "test-rps-profiler";
2826 cur_test_run.init_peer = profiler_init_peer;
2827 //cur_test_run.pre_test = mal_pre;
2828 cur_test_run.pre_test = pre_profiler;
2829 cur_test_run.main_test = profiler_cb;
2830 cur_test_run.reply_handle = profiler_reply_handle;
2831 cur_test_run.eval_cb = profiler_eval;
2832 cur_test_run.post_test = post_profiler;
2833 cur_test_run.request_interval = 2;
2834 cur_test_run.num_requests = 5;
2835 cur_test_run.have_churn = HAVE_CHURN;
2836 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
2837 cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
2838 cur_test_run.stat_collect_flags = STAT_TYPE_ROUNDS |
2840 STAT_TYPE_BLOCKS_MANY_PUSH |
2841 STAT_TYPE_BLOCKS_NO_PUSH |
2842 STAT_TYPE_BLOCKS_NO_PULL |
2843 STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL |
2844 STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL |
2845 STAT_TYPE_ISSUED_PUSH_SEND |
2846 STAT_TYPE_ISSUED_PULL_REQ |
2847 STAT_TYPE_ISSUED_PULL_REP |
2848 STAT_TYPE_SENT_PUSH_SEND |
2849 STAT_TYPE_SENT_PULL_REQ |
2850 STAT_TYPE_SENT_PULL_REP |
2851 STAT_TYPE_RECV_PUSH_SEND |
2852 STAT_TYPE_RECV_PULL_REQ |
2853 STAT_TYPE_RECV_PULL_REP;
2854 cur_test_run.have_collect_view = COLLECT_VIEW;
2855 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300);
2857 /* 'Clean' directory */
2858 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
2859 GNUNET_DISK_directory_create ("/tmp/rps/");
2862 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
2863 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
2864 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
2865 if ( (2 == mal_type) ||
2867 target_peer = &rps_peer_ids[num_peers - 2];
2868 if (profiler_eval == cur_test_run.eval_cb)
2869 eval_peer = &rps_peers[num_peers - 1]; /* FIXME: eval_peer could be a
2870 malicious peer if not careful
2871 with the malicious portion */
2874 ret_value = GNUNET_TESTBED_test_run (cur_test_run.name,
2879 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2880 "_test_run returned.\n");
2881 if (GNUNET_OK != ret_value)
2883 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2884 "Test did not run successfully!\n");
2887 ret_value = cur_test_run.eval_cb();
2888 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
2890 GNUNET_array_grow (rps_peers->cur_view,
2891 rps_peers->cur_view_count,
2894 GNUNET_free (rps_peers);
2895 GNUNET_free (rps_peer_ids);
2896 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
2900 /* end of test_rps.c */