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 it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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 "rps_test_lib.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testbed_service.h"
32 #include "gnunet_rps_service.h"
33 #include "rps-test_util.h"
34 #include "gnunet-service-rps_sampler_elem.h"
39 #define BIT(n) (1 << (n))
42 * How many peers do we start?
44 static uint32_t num_peers;
47 * @brief numer of bits required to represent the largest peer id
49 static unsigned bits_needed;
52 * How long do we run the test?
54 static struct GNUNET_TIME_Relative duration;
57 * When do we do a hard shutdown?
59 static struct GNUNET_TIME_Relative timeout;
63 * Portion of malicious peers
65 static double portion = .1;
68 * Type of malicious peer to test
70 static unsigned int mal_type = 0;
73 * Handles to all of the running peers
75 static struct GNUNET_TESTBED_Peer **testbed_peers;
79 STAT_TYPE_ROUNDS, /* 0 */
80 STAT_TYPE_BLOCKS, /* 1 */
81 STAT_TYPE_BLOCKS_MANY_PUSH, /* 2 */
82 STAT_TYPE_BLOCKS_NO_PUSH, /* 3 */
83 STAT_TYPE_BLOCKS_NO_PULL, /* 4 */
84 STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL, /* 5 */
85 STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL, /* 6 */
86 STAT_TYPE_ISSUED_PUSH_SEND, /* 7 */
87 STAT_TYPE_ISSUED_PUSH_SEND_MH, /* 8 */
88 STAT_TYPE_ISSUED_PULL_REQ, /* 9 */
89 STAT_TYPE_ISSUED_PULL_REQ_MH, /* 10 */
90 STAT_TYPE_ISSUED_PULL_REP, /* 11 */
91 STAT_TYPE_SENT_PUSH_SEND, /* 12 */
92 STAT_TYPE_SENT_PULL_REQ, /* 13 */
93 STAT_TYPE_SENT_PULL_REQ_MH, /* 14 */
94 STAT_TYPE_SENT_PULL_REP, /* 15 */
95 STAT_TYPE_RECV_PUSH_SEND, /* 16 */
96 STAT_TYPE_RECV_PUSH_SEND_MH, /* 17 */
97 STAT_TYPE_RECV_PULL_REQ, /* 18 */
98 STAT_TYPE_RECV_PULL_REQ_MH, /* 19 */
99 STAT_TYPE_RECV_PULL_REP, /* 20 */
100 STAT_TYPE_RECV_PULL_REP_MH, /* 21 */
101 STAT_TYPE_VIEW_SIZE, /* 22 */
102 STAT_TYPE_KNOWN_PEERS, /* 23 */
103 STAT_TYPE_VALID_PEERS, /* 24 */
104 STAT_TYPE_LEARND_PEERS, /* 25 */
105 STAT_TYPE_PENDING_ONLINE_CHECKS, /* 26 */
106 STAT_TYPE_UNREQUESTED_PULL_REPLIES, /* 27 */
107 STAT_TYPE_PEERS_IN_PUSH_MAP, /* 28 */
108 STAT_TYPE_PEERS_IN_PULL_MAP, /* 29 */
109 STAT_TYPE_PEERS_IN_VIEW, /* 30 */
110 STAT_TYPE_VIEW_SIZE_AIM, /* 31 */
111 STAT_TYPE_MAX, /* 32 */
114 static char*stat_type_strings[] = {
117 "# rounds blocked - too many pushes",
118 "# rounds blocked - no pushes",
119 "# rounds blocked - no pull replies",
120 "# rounds blocked - too many pushes, no pull replies",
121 "# rounds blocked - no pushes, no pull replies",
122 "# push send issued",
123 "# push send issued (multi-hop peer)",
124 "# pull request send issued",
125 "# pull request send issued (multi-hop peer)",
126 "# pull reply send issued",
128 "# pull requests sent",
129 "# pull requests sent (multi-hop peer)",
130 "# pull replys sent",
131 "# push message received",
132 "# push message received (multi-hop peer)",
133 "# pull request message received",
134 "# pull request message received (multi-hop peer)",
135 "# pull reply messages received",
136 "# pull reply messages received (multi-hop peer)",
141 "# pending online checks",
142 "# unrequested pull replies",
143 "# peers in push map at end of round",
144 "# peers in pull map at end of round",
145 "# peers in view at end of round",
151 struct RPSPeer *rps_peer;
152 enum STAT_TYPE stat_type;
157 * @brief Converts string representation to the corresponding #STAT_TYPE enum.
159 * @param stat_str string representation of statistics specifier
161 * @return corresponding enum
164 stat_str_2_type (const char *stat_str)
166 if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL],
168 strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL])))
170 return STAT_TYPE_BLOCKS_NO_PULL;
172 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
175 stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL])))
177 return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL;
179 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH],
182 stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH])))
184 return STAT_TYPE_BLOCKS_MANY_PUSH;
186 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
189 stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL])))
191 return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL;
193 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH],
195 strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH])))
197 return STAT_TYPE_BLOCKS_NO_PUSH;
199 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS],
201 strlen (stat_type_strings[STAT_TYPE_BLOCKS])))
203 return STAT_TYPE_BLOCKS;
205 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ROUNDS],
207 strlen (stat_type_strings[STAT_TYPE_ROUNDS])))
209 return STAT_TYPE_ROUNDS;
211 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND],
214 stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND])))
216 return STAT_TYPE_ISSUED_PUSH_SEND;
218 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH],
221 stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH])))
223 return STAT_TYPE_ISSUED_PUSH_SEND_MH;
225 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ],
227 strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ])))
229 return STAT_TYPE_ISSUED_PULL_REQ;
231 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH],
234 stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH])))
236 return STAT_TYPE_ISSUED_PULL_REQ_MH;
238 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP],
240 strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP])))
242 return STAT_TYPE_ISSUED_PULL_REP;
244 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND],
246 strlen (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND])))
248 return STAT_TYPE_SENT_PUSH_SEND;
250 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REQ],
252 strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REQ])))
254 return STAT_TYPE_SENT_PULL_REQ;
256 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH],
259 stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH])))
261 return STAT_TYPE_SENT_PULL_REQ_MH;
263 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REP],
265 strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REP])))
267 return STAT_TYPE_SENT_PULL_REP;
269 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND],
271 strlen (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND])))
273 return STAT_TYPE_RECV_PUSH_SEND;
275 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH],
278 stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH])))
280 return STAT_TYPE_RECV_PUSH_SEND_MH;
282 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REQ],
284 strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REQ])))
286 return STAT_TYPE_RECV_PULL_REQ;
288 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH],
291 stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH])))
293 return STAT_TYPE_RECV_PULL_REQ_MH;
295 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REP],
297 strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REP])))
299 return STAT_TYPE_RECV_PULL_REP;
301 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH],
304 stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH])))
306 return STAT_TYPE_RECV_PULL_REP_MH;
308 else if (0 == strncmp (stat_type_strings[STAT_TYPE_VIEW_SIZE],
310 strlen (stat_type_strings[STAT_TYPE_VIEW_SIZE])))
312 return STAT_TYPE_VIEW_SIZE;
314 else if (0 == strncmp (stat_type_strings[STAT_TYPE_KNOWN_PEERS],
316 strlen (stat_type_strings[STAT_TYPE_KNOWN_PEERS])))
318 return STAT_TYPE_KNOWN_PEERS;
320 else if (0 == strncmp (stat_type_strings[STAT_TYPE_VALID_PEERS],
322 strlen (stat_type_strings[STAT_TYPE_VALID_PEERS])))
324 return STAT_TYPE_VALID_PEERS;
326 else if (0 == strncmp (stat_type_strings[STAT_TYPE_LEARND_PEERS],
328 strlen (stat_type_strings[STAT_TYPE_LEARND_PEERS])))
330 return STAT_TYPE_LEARND_PEERS;
332 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS],
335 stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS])))
337 return STAT_TYPE_PENDING_ONLINE_CHECKS;
339 else if (0 == strncmp (stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES],
342 stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES])))
344 return STAT_TYPE_UNREQUESTED_PULL_REPLIES;
346 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP],
349 stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP])))
351 return STAT_TYPE_PEERS_IN_PUSH_MAP;
353 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP],
356 stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP])))
358 return STAT_TYPE_PEERS_IN_PULL_MAP;
360 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_VIEW],
362 strlen (stat_type_strings[STAT_TYPE_PEERS_IN_VIEW])))
364 return STAT_TYPE_PEERS_IN_VIEW;
366 else if (0 == strncmp (stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM],
368 strlen (stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM])))
370 return STAT_TYPE_VIEW_SIZE_AIM;
372 return STAT_TYPE_MAX;
377 * @brief Indicates whether peer should go off- or online
379 enum PEER_ONLINE_DELTA
382 * @brief Indicates peer going online
386 * @brief Indicates peer going offline
388 PEER_GO_OFFLINE = -1,
392 * Operation map entry
399 struct OpListEntry *next;
404 struct OpListEntry *prev;
407 * The testbed operation
409 struct GNUNET_TESTBED_Operation *op;
412 * Depending on whether we start or stop RPS service at the peer, set this to
413 * #PEER_GO_ONLINE (1) or #PEER_GO_OFFLINE (-1)
415 enum PEER_ONLINE_DELTA delta;
418 * Index of the regarding peer
426 static struct OpListEntry *oplist_head;
431 static struct OpListEntry *oplist_tail;
435 * A pending reply: A request was sent and the reply is pending.
442 struct PendingReply *next;
443 struct PendingReply *prev;
446 * Handle to the request we are waiting for
448 struct GNUNET_RPS_Request_Handle_Single_Info *req_handle;
451 * The peer that requested
453 struct RPSPeer *rps_peer;
458 * A pending request: A request was not made yet but is scheduled for later.
460 struct PendingRequest
465 struct PendingRequest *next;
466 struct PendingRequest *prev;
469 * Handle to the request we are waiting for
471 struct GNUNET_SCHEDULER_Task *request_task;
474 * The peer that requested
476 struct RPSPeer *rps_peer;
481 * Information we track for each peer.
491 * Handle for RPS connect operation.
493 struct GNUNET_TESTBED_Operation *op;
496 * Handle to RPS service.
498 struct GNUNET_RPS_Handle *rps_handle;
503 struct GNUNET_PeerIdentity *peer_id;
506 * A request handle to check for an request
508 // struct GNUNET_RPS_Request_Handle *req_handle;
511 * Peer on- or offline?
516 * Number of Peer IDs to request during the whole test
518 unsigned int num_ids_to_request;
521 * Pending requests DLL
523 struct PendingRequest *pending_req_head;
524 struct PendingRequest *pending_req_tail;
527 * Number of pending requests
529 unsigned int num_pending_reqs;
532 * Pending replies DLL
534 struct PendingReply *pending_rep_head;
535 struct PendingReply *pending_rep_tail;
538 * Number of pending replies
540 unsigned int num_pending_reps;
543 * Number of received PeerIDs
545 unsigned int num_recv_ids;
548 * Pending operation on that peer
550 const struct OpListEntry *entry_op_manage;
553 * Testbed operation to connect to statistics service
555 struct GNUNET_TESTBED_Operation *stat_op;
558 * Handle to the statistics service
560 struct GNUNET_STATISTICS_Handle *stats_h;
563 * @brief flags to indicate which statistics values have been already
564 * collected from the statistics service.
565 * Used to check whether we are able to shutdown.
567 uint32_t stat_collected_flags;
570 * @brief File name of the file the stats are finally written to
572 const char *file_name_stats;
575 * @brief File name of the file the stats are finally written to
577 const char *file_name_probs;
580 * @brief File name of the file the stats are finally written to
582 const char *file_name_probs_hist;
585 * @brief The current view
587 struct GNUNET_PeerIdentity *cur_view;
590 * @brief Number of peers in the #cur_view.
592 uint32_t cur_view_count;
595 * @brief Number of occurrences in other peer's view
597 uint32_t count_in_views;
600 * @brief statistics values
602 uint64_t stats[STAT_TYPE_MAX];
604 * @brief Handle for the statistics get request
606 struct GNUNET_STATISTICS_GetHandle *h_stat_get[STAT_TYPE_MAX];
609 * @brief Keep the probabilities in cache for computing the probabilities
610 * with respect to history.
612 double *eval_probs_cache;
616 * Information for all the peers.
618 static struct RPSPeer *rps_peers;
621 * Peermap to get the index of a given peer ID quick.
623 static struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
628 static struct GNUNET_PeerIdentity *rps_peer_ids;
631 * ID of the targeted peer.
633 static struct GNUNET_PeerIdentity *target_peer;
636 * Number of online peers.
638 static unsigned int num_peers_online;
641 * @brief The added sizes of the peer's views
643 static unsigned int view_sizes;
646 * Return value from 'main'.
651 * Identifier for the task that runs after the test to collect results
653 static struct GNUNET_SCHEDULER_Task *post_test_task;
656 * Identifier for the shutdown task
658 static struct GNUNET_SCHEDULER_Task *shutdown_task;
662 * Identifier for the churn task that runs periodically
664 static struct GNUNET_SCHEDULER_Task *churn_task;
667 * Called to initialise the given RPSPeer
669 typedef void (*InitPeer) (struct RPSPeer *rps_peer);
672 * @brief Called directly after connecting to the service
674 * @param rps_peer Specific peer the function is called on
675 * @param h the handle to the rps service
677 typedef void (*PreTest) (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h);
680 * @brief Executes functions to test the api/service for a given peer
682 * Called from within #rps_connect_complete_cb ()
683 * Implemented by #churn_test_cb, #profiler_cb, #mal_cb, #single_req_cb,
684 * #delay_req_cb, #seed_big_cb, #single_peer_seed_cb, #seed_cb, #req_cancel_cb
686 * @param rps_peer the peer the task runs on
688 typedef void (*MainTest) (struct RPSPeer *rps_peer);
691 * Callback called once the requested random peers are available
693 typedef void (*ReplyHandle) (void *cls,
695 const struct GNUNET_PeerIdentity *recv_peers);
698 * Called directly before disconnecting from the service
700 typedef void (*PostTest) (struct RPSPeer *peer);
703 * Function called after disconnect to evaluate test success
705 typedef int (*EvaluationCallback) (void);
708 * @brief Do we have Churn?
713 * @brief If we have churn this is set
717 * @brief If we have no churn this is set
723 * @brief Is it ok to quit the test before the timeout?
725 enum OPTION_QUICK_QUIT
728 * @brief It is ok for the test to quit before the timeout triggers
733 * @brief It is NOT ok for the test to quit before the timeout triggers
739 * @brief Do we collect statistics at the end?
741 enum OPTION_COLLECT_STATISTICS
744 * @brief We collect statistics at the end
749 * @brief We do not collect statistics at the end
751 NO_COLLECT_STATISTICS,
755 * @brief Do we collect views during run?
757 enum OPTION_COLLECT_VIEW
760 * @brief We collect view during run
765 * @brief We do not collect the view during run
771 * Structure to define a single test
781 * Called with a single peer in order to initialise that peer
786 * Called directly after connecting to the service
791 * Main function for each peer
796 * Callback called once the requested peers are available
798 ReplyHandle reply_handle;
801 * Called directly before disconnecting from the service
806 * Function to evaluate the test results
808 EvaluationCallback eval_cb;
813 uint32_t request_interval;
816 * Number of Requests to make.
818 uint32_t num_requests;
821 * Run with (-out) churn
823 enum OPTION_CHURN have_churn;
826 * Quit test before timeout?
828 enum OPTION_QUICK_QUIT have_quick_quit;
831 * Collect statistics at the end?
833 enum OPTION_COLLECT_STATISTICS have_collect_statistics;
836 * Collect view during run?
838 enum OPTION_COLLECT_VIEW have_collect_view;
841 * @brief Mark which values from the statistics service to collect at the end
844 uint32_t stat_collect_flags;
848 * Did we finish the test?
850 static int post_test;
853 * Are we shutting down?
855 static int in_shutdown;
858 * Append arguments to file
861 tofile_ (const char *file_name, const char *line)
863 struct GNUNET_DISK_FileHandle *f;
864 /* char output_buffer[512]; */
869 if (NULL == (f = GNUNET_DISK_file_open (file_name,
870 GNUNET_DISK_OPEN_APPEND
871 | GNUNET_DISK_OPEN_WRITE
872 | GNUNET_DISK_OPEN_CREATE,
873 GNUNET_DISK_PERM_USER_READ
874 | GNUNET_DISK_PERM_USER_WRITE
875 | GNUNET_DISK_PERM_GROUP_READ
876 | GNUNET_DISK_PERM_OTHER_READ)))
878 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
879 "Not able to open file %s\n",
883 /* size = GNUNET_snprintf (output_buffer,
884 sizeof (output_buffer),
886 GNUNET_TIME_absolute_get ().abs_value_us,
890 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
891 "Failed to write string to buffer (size: %i)\n",
894 } */size = strlen (line) * sizeof(char);
896 size2 = GNUNET_DISK_file_write (f, line, size);
899 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
900 "Unable to write to file! (Size: %lu, size2: %lu)\n",
903 if (GNUNET_YES != GNUNET_DISK_file_close (f))
905 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
906 "Unable to close file\n");
911 if (GNUNET_YES != GNUNET_DISK_file_close (f))
913 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
914 "Unable to close file\n");
920 * This function is used to facilitate writing important information to disk
922 #define tofile(file_name, ...) do { \
925 size = GNUNET_snprintf (tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \
927 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
928 "Failed to create tmp_buf\n"); \
930 tofile_ (file_name, tmp_buf); \
935 * Write the ids and their according index in the given array to a file
939 ids_to_file (char *file_name,
940 struct GNUNET_PeerIdentity *peer_ids,
941 unsigned int num_peer_ids)
945 for (i=0 ; i < num_peer_ids ; i++)
950 GNUNET_i2s_full (&peer_ids[i]));
955 * Test the success of a single test
965 for (i = 0; i < num_peers; i++)
967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
968 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
970 GNUNET_i2s (rps_peers[i].peer_id),
971 rps_peers[i].num_recv_ids,
972 rps_peers[i].num_ids_to_request,
973 (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids));
974 tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids);
976 return tmp_ok ? 0 : 1;
981 * Creates an oplist entry and adds it to the oplist DLL
983 static struct OpListEntry *
986 struct OpListEntry *entry;
988 entry = GNUNET_new (struct OpListEntry);
989 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
995 * @brief Checks if given peer already received its statistics value from the
996 * statistics service.
998 * @param rps_peer the peer to check for
1000 * @return #GNUNET_YES if so
1001 * #GNUNET_NO otherwise
1004 check_statistics_collect_completed_single_peer (
1005 const struct RPSPeer *rps_peer)
1007 if (cur_test_run.stat_collect_flags !=
1008 (cur_test_run.stat_collect_flags
1009 & rps_peer->stat_collected_flags))
1018 * @brief Checks if all peers already received their statistics value from the
1019 * statistics service.
1021 * @return #GNUNET_YES if so
1022 * #GNUNET_NO otherwise
1025 check_statistics_collect_completed ()
1029 for (i = 0; i < num_peers; i++)
1031 if (GNUNET_NO == check_statistics_collect_completed_single_peer (
1034 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1035 "At least Peer %" PRIu32
1036 " did not yet receive all statistics values\n",
1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1042 "All peers received their statistics values\n");
1048 rps_disconnect_adapter (void *cls,
1052 cancel_pending_req (struct PendingRequest *pending_req)
1054 struct RPSPeer *rps_peer;
1056 rps_peer = pending_req->rps_peer;
1057 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1058 rps_peer->pending_req_tail,
1060 rps_peer->num_pending_reqs--;
1061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1062 "Cancelling pending rps get request\n");
1063 GNUNET_SCHEDULER_cancel (pending_req->request_task);
1064 GNUNET_free (pending_req);
1069 cancel_request (struct PendingReply *pending_rep)
1071 struct RPSPeer *rps_peer;
1073 rps_peer = pending_rep->rps_peer;
1074 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1075 rps_peer->pending_rep_tail,
1077 rps_peer->num_pending_reps--;
1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1079 "Cancelling rps get reply\n");
1080 GNUNET_assert (NULL != pending_rep->req_handle);
1081 GNUNET_RPS_request_single_info_cancel (pending_rep->req_handle);
1082 pending_rep->req_handle = NULL;
1083 GNUNET_free (pending_rep);
1089 clean_peer (unsigned peer_index)
1091 struct PendingRequest *pending_req;
1093 while (NULL != (pending_req = rps_peers[peer_index].pending_req_head))
1095 cancel_pending_req (pending_req);
1097 pending_req = rps_peers[peer_index].pending_req_head;
1098 rps_disconnect_adapter (&rps_peers[peer_index],
1099 &rps_peers[peer_index].rps_handle);
1100 for (unsigned stat_type = STAT_TYPE_ROUNDS;
1101 stat_type < STAT_TYPE_MAX;
1104 if (NULL != rps_peers[peer_index].h_stat_get[stat_type])
1106 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1107 "(%u) did not yet receive stat value for `%s'\n",
1108 rps_peers[peer_index].index,
1109 stat_type_strings[stat_type]);
1110 GNUNET_STATISTICS_get_cancel (
1111 rps_peers[peer_index].h_stat_get[stat_type]);
1114 if (NULL != rps_peers[peer_index].op)
1116 GNUNET_TESTBED_operation_done (rps_peers[peer_index].op);
1117 rps_peers[peer_index].op = NULL;
1123 * Task run on timeout to shut everything down.
1126 shutdown_op (void *cls)
1129 struct OpListEntry *entry;
1133 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1134 "Shutdown task scheduled, going down.\n");
1135 in_shutdown = GNUNET_YES;
1137 if (NULL != shutdown_task)
1139 GNUNET_SCHEDULER_cancel (shutdown_task);
1140 shutdown_task = NULL;
1142 if (NULL != post_test_task)
1144 GNUNET_SCHEDULER_cancel (post_test_task);
1145 post_test_task = NULL;
1147 if (NULL != churn_task)
1149 GNUNET_SCHEDULER_cancel (churn_task);
1152 entry = oplist_head;
1153 while (NULL != (entry = oplist_head))
1155 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1156 "Operation still pending on shutdown (%u)\n",
1158 GNUNET_TESTBED_operation_done (entry->op);
1159 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1160 GNUNET_free (entry);
1162 for (i = 0; i < num_peers; i++)
1171 trigger_shutdown (void *cls)
1175 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1176 "Shutdown was triggerd by timeout, going down.\n");
1177 shutdown_task = NULL;
1178 GNUNET_SCHEDULER_shutdown ();
1183 * Task run after #duration to collect statistics and potentially shut down.
1186 post_test_op (void *cls)
1192 post_test_task = NULL;
1193 post_test = GNUNET_YES;
1194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1195 "Executing post test op.\n");
1196 if (NULL != churn_task)
1198 GNUNET_SCHEDULER_cancel (churn_task);
1201 for (i = 0; i < num_peers; i++)
1203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1204 "Executing post test op. (peer %" PRIu32 ")\n",
1205 rps_peers[i].index);
1206 if (NULL != rps_peers[i].op)
1208 GNUNET_TESTBED_operation_done (rps_peers[i].op);
1209 rps_peers[i].op = NULL;
1210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1211 "Cancelled testbed operation\n");
1213 if (NULL != cur_test_run.post_test)
1215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n",
1217 cur_test_run.post_test (&rps_peers[i]);
1220 /* If we do not collect statistics, shut down directly */
1221 if ((NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics) ||
1222 (GNUNET_YES == check_statistics_collect_completed ()) )
1224 GNUNET_SCHEDULER_cancel (shutdown_task);
1225 shutdown_task = NULL;
1226 GNUNET_SCHEDULER_shutdown ();
1235 seed_peers (void *cls)
1237 struct RPSPeer *peer = cls;
1238 unsigned int amount;
1241 // TODO if malicious don't seed mal peers
1242 amount = round (.5 * num_peers);
1244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
1245 for (i = 0; i < amount; i++)
1246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
1248 GNUNET_i2s (&rps_peer_ids[i]));
1250 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
1255 * Get the id of peer i.
1258 info_cb (void *cb_cls,
1259 struct GNUNET_TESTBED_Operation *op,
1260 const struct GNUNET_TESTBED_PeerInformation *pinfo,
1263 struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
1267 if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test))
1272 if ((NULL == pinfo) || (NULL != emsg))
1274 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
1275 GNUNET_TESTBED_operation_done (entry->op);
1279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1282 GNUNET_i2s (pinfo->result.id));
1284 rps_peer_ids[entry->index] = *(pinfo->result.id);
1285 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
1287 GNUNET_assert (GNUNET_OK ==
1288 GNUNET_CONTAINER_multipeermap_put (peer_map,
1289 &rps_peer_ids[entry->index],
1290 &rps_peers[entry->index],
1291 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1292 tofile ("/tmp/rps/peer_ids",
1295 GNUNET_i2s_full (&rps_peer_ids[entry->index]));
1297 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1298 GNUNET_TESTBED_operation_done (entry->op);
1299 GNUNET_free (entry);
1304 * Callback to be called when RPS service connect operation is completed
1306 * @param cls the callback closure from functions generating an operation
1307 * @param op the operation that has been finished
1308 * @param ca_result the RPS service handle returned from rps_connect_adapter
1309 * @param emsg error message in case the operation has failed; will be NULL if
1310 * operation has executed successfully.
1313 rps_connect_complete_cb (void *cls,
1314 struct GNUNET_TESTBED_Operation *op,
1318 struct RPSPeer *rps_peer = cls;
1319 struct GNUNET_RPS_Handle *rps = ca_result;
1321 if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test))
1326 rps_peer->rps_handle = rps;
1327 rps_peer->online = GNUNET_YES;
1330 GNUNET_assert (op == rps_peer->op);
1333 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1334 "Failed to connect to RPS service: %s\n",
1337 GNUNET_SCHEDULER_shutdown ();
1341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1342 "Started client successfully (%u)\n",
1345 cur_test_run.main_test (rps_peer);
1350 * Adapter function called to establish a connection to
1353 * @param cls closure
1354 * @param cfg configuration of the peer to connect to; will be available until
1355 * GNUNET_TESTBED_operation_done() is called on the operation returned
1356 * from GNUNET_TESTBED_service_connect()
1357 * @return service handle to return in 'op_result', NULL on error
1360 rps_connect_adapter (void *cls,
1361 const struct GNUNET_CONFIGURATION_Handle *cfg)
1363 struct GNUNET_RPS_Handle *h;
1365 h = GNUNET_RPS_connect (cfg);
1367 if (NULL != cur_test_run.pre_test)
1368 cur_test_run.pre_test (cls, h);
1375 * Called to open a connection to the peer's statistics
1377 * @param cls peer context
1378 * @param cfg configuration of the peer to connect to; will be available until
1379 * GNUNET_TESTBED_operation_done() is called on the operation returned
1380 * from GNUNET_TESTBED_service_connect()
1381 * @return service handle to return in 'op_result', NULL on error
1384 stat_connect_adapter (void *cls,
1385 const struct GNUNET_CONFIGURATION_Handle *cfg)
1387 struct RPSPeer *peer = cls;
1389 peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg);
1390 return peer->stats_h;
1395 * Called to disconnect from peer's statistics service
1397 * @param cls peer context
1398 * @param op_result service handle returned from the connect adapter
1401 stat_disconnect_adapter (void *cls, void *op_result)
1403 struct RPSPeer *peer = cls;
1405 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
1406 // (peer->stats_h, "core", "# peers connected",
1407 // stat_iterator, peer));
1408 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
1409 // (peer->stats_h, "nse", "# peers connected",
1410 // stat_iterator, peer));
1411 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
1412 peer->stats_h = NULL;
1417 * Called after successfully opening a connection to a peer's statistics
1418 * service; we register statistics monitoring for CORE and NSE here.
1420 * @param cls the callback closure from functions generating an operation
1421 * @param op the operation that has been finished
1422 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1423 * @param emsg error message in case the operation has failed; will be NULL if
1424 * operation has executed successfully.
1427 stat_complete_cb (void *cls,
1428 struct GNUNET_TESTBED_Operation *op,
1432 // struct GNUNET_STATISTICS_Handle *sh = ca_result;
1433 // struct RPSPeer *peer = (struct RPSPeer *) cls;
1443 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1444 // (sh, "core", "# peers connected",
1445 // stat_iterator, peer));
1446 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1447 // (sh, "nse", "# peers connected",
1448 // stat_iterator, peer));
1453 * Adapter function called to destroy connection to
1456 * @param cls closure
1457 * @param op_result service handle returned from the connect adapter
1460 rps_disconnect_adapter (void *cls,
1463 struct RPSPeer *peer = cls;
1464 struct GNUNET_RPS_Handle *h = op_result;
1465 struct PendingReply *pending_rep;
1467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1468 "disconnect_adapter (%u)\n",
1470 GNUNET_assert (NULL != peer);
1471 if (NULL != peer->rps_handle)
1473 while (NULL != (pending_rep = peer->pending_rep_head))
1475 cancel_request (pending_rep);
1477 GNUNET_assert (h == peer->rps_handle);
1480 GNUNET_RPS_disconnect (h);
1483 peer->rps_handle = NULL;
1488 /***********************************************************************
1489 * Definition of tests
1490 ***********************************************************************/
1493 * Callback to call on receipt of a reply
1495 * @param cls closure
1496 * @param n number of peers
1497 * @param recv_peers the received peers
1500 default_reply_handle (void *cls,
1502 const struct GNUNET_PeerIdentity *recv_peers)
1504 struct RPSPeer *rps_peer;
1505 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1508 rps_peer = pending_rep->rps_peer;
1509 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1510 rps_peer->pending_rep_tail,
1512 rps_peer->num_pending_reps--;
1513 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1514 "[%s] got %" PRIu64 " peers:\n",
1515 GNUNET_i2s (rps_peer->peer_id),
1518 for (i = 0; i < n; i++)
1520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1523 GNUNET_i2s (&recv_peers[i]));
1525 rps_peer->num_recv_ids++;
1528 if (GNUNET_YES != post_test)
1530 if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit)
1532 if (0 == evaluate ())
1534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1535 "Test succeeded before end of duration\n");
1536 if (NULL != post_test_task)
1537 GNUNET_SCHEDULER_cancel (post_test_task);
1538 post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL);
1539 GNUNET_assert (NULL != post_test_task);
1545 profiler_reply_handle_info (void *cls,
1546 const struct GNUNET_PeerIdentity *recv_peer,
1548 uint32_t num_observed);
1551 * Request random peers.
1554 request_peers (void *cls)
1556 struct PendingRequest *pending_req = cls;
1557 struct RPSPeer *rps_peer;
1558 struct PendingReply *pending_rep;
1560 rps_peer = pending_req->rps_peer;
1561 GNUNET_assert (1 <= rps_peer->num_pending_reqs);
1562 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1563 rps_peer->pending_req_tail,
1565 rps_peer->num_pending_reqs--;
1566 if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test))
1568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1569 "Requesting one peer\n");
1570 pending_rep = GNUNET_new (struct PendingReply);
1571 pending_rep->rps_peer = rps_peer;
1572 // pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle,
1574 // cur_test_run.reply_handle,
1576 pending_rep->req_handle = GNUNET_RPS_request_peer_info (rps_peer->rps_handle,
1577 profiler_reply_handle_info,
1579 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head,
1580 rps_peer->pending_rep_tail,
1582 rps_peer->num_pending_reps++;
1587 * Schedule requests for peer @a rps_peer that have neither been scheduled, nor
1588 * issued, nor replied
1591 schedule_missing_requests (struct RPSPeer *rps_peer)
1594 struct PendingRequest *pending_req;
1596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1597 "Scheduling %u - %u missing requests\n",
1598 rps_peer->num_ids_to_request,
1599 rps_peer->num_pending_reqs + rps_peer->num_pending_reps);
1600 GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <=
1601 rps_peer->num_ids_to_request);
1602 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps;
1603 i < rps_peer->num_ids_to_request; i++)
1605 pending_req = GNUNET_new (struct PendingRequest);
1606 pending_req->rps_peer = rps_peer;
1607 pending_req->request_task = GNUNET_SCHEDULER_add_delayed (
1608 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1609 cur_test_run.request_interval * i),
1612 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head,
1613 rps_peer->pending_req_tail,
1615 rps_peer->num_pending_reqs++;
1621 cancel_pending_req_rep (struct RPSPeer *rps_peer)
1623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1624 "Cancelling all (pending) requests.\n");
1625 while (NULL != rps_peer->pending_req_head)
1626 cancel_pending_req (rps_peer->pending_req_head);
1627 GNUNET_assert (0 == rps_peer->num_pending_reqs);
1628 while (NULL != rps_peer->pending_rep_head)
1629 cancel_request (rps_peer->pending_rep_head);
1630 GNUNET_assert (0 == rps_peer->num_pending_reps);
1634 /***********************************
1636 ***********************************/
1639 * Initialise only non-mal RPSPeers
1642 mal_init_peer (struct RPSPeer *rps_peer)
1644 if (rps_peer->index >= round (portion * num_peers))
1645 rps_peer->num_ids_to_request = 1;
1650 * @brief Set peers to (non-)malicious before execution
1652 * Of signature #PreTest
1654 * @param rps_peer the peer to set (non-) malicious
1655 * @param h the handle to the service
1658 mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1660 #if ENABLE_MALICIOUS
1661 uint32_t num_mal_peers;
1663 GNUNET_assert ((1 >= portion) &&
1665 num_mal_peers = round (portion * num_peers);
1667 if (rps_peer->index < num_mal_peers)
1669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1670 "%u. peer [%s] of %" PRIu32
1671 " malicious peers turning malicious\n",
1673 GNUNET_i2s (rps_peer->peer_id),
1676 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers,
1677 rps_peer_ids, target_peer);
1679 #endif /* ENABLE_MALICIOUS */
1684 mal_cb (struct RPSPeer *rps_peer)
1686 uint32_t num_mal_peers;
1688 if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test))
1693 #if ENABLE_MALICIOUS
1694 GNUNET_assert ((1 >= portion) &&
1696 num_mal_peers = round (portion * num_peers);
1698 if (rps_peer->index >= num_mal_peers)
1699 { /* It's useless to ask a malicious peer about a random sample -
1700 it's not sampling */
1701 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
1702 GNUNET_TIME_UNIT_SECONDS, 2),
1703 seed_peers, rps_peer);
1704 schedule_missing_requests (rps_peer);
1706 #endif /* ENABLE_MALICIOUS */
1710 /***********************************
1712 ***********************************/
1718 * @brief Starts churn
1720 * Has signature of #MainTest
1722 * This is not implemented too nicely as this is called for each peer, but we
1723 * only need to call it once. (Yes we check that we only schedule the task
1726 * @param rps_peer The peer it's called for
1729 churn_test_cb (struct RPSPeer *rps_peer)
1731 if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test))
1737 if ((HAVE_CHURN == cur_test_run.have_churn) && (NULL == churn_task))
1739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1740 "Starting churn task\n");
1741 churn_task = GNUNET_SCHEDULER_add_delayed (
1742 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1748 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1749 "Not starting churn task\n");
1752 schedule_missing_requests (rps_peer);
1756 /***********************************
1758 ***********************************/
1761 * Callback to be called when RPS service is started or stopped at peers
1764 * @param op the operation handle
1765 * @param emsg NULL on success; otherwise an error description
1768 churn_cb (void *cls,
1769 struct GNUNET_TESTBED_Operation *op,
1773 struct OpListEntry *entry = cls;
1777 if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test))
1782 GNUNET_TESTBED_operation_done (entry->op);
1785 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1786 "Failed to start/stop RPS at a peer\n");
1787 GNUNET_SCHEDULER_shutdown ();
1790 GNUNET_assert (0 != entry->delta);
1792 num_peers_online += entry->delta;
1794 if (PEER_GO_OFFLINE == entry->delta)
1795 { /* Peer hopefully just went offline */
1796 if (GNUNET_YES != rps_peers[entry->index].online)
1798 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1799 "peer %s was expected to go offline but is still marked as online\n",
1800 GNUNET_i2s (rps_peers[entry->index].peer_id));
1805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1806 "peer %s probably went offline as expected\n",
1807 GNUNET_i2s (rps_peers[entry->index].peer_id));
1809 rps_peers[entry->index].online = GNUNET_NO;
1812 else if (PEER_GO_ONLINE < entry->delta)
1813 { /* Peer hopefully just went online */
1814 if (GNUNET_NO != rps_peers[entry->index].online)
1816 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1817 "peer %s was expected to go online but is still marked as offline\n",
1818 GNUNET_i2s (rps_peers[entry->index].peer_id));
1823 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1824 "peer %s probably went online as expected\n",
1825 GNUNET_i2s (rps_peers[entry->index].peer_id));
1826 if (NULL != cur_test_run.pre_test)
1828 cur_test_run.pre_test (&rps_peers[entry->index],
1829 rps_peers[entry->index].rps_handle);
1830 schedule_missing_requests (&rps_peers[entry->index]);
1833 rps_peers[entry->index].online = GNUNET_YES;
1837 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1838 "Invalid value for delta: %i\n", entry->delta);
1842 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1843 rps_peers[entry->index].entry_op_manage = NULL;
1844 GNUNET_free (entry);
1845 // if (num_peers_in_round[current_round] == peers_running)
1851 * @brief Set the rps-service up or down for a specific peer
1853 * @param i index of action
1854 * @param j index of peer
1855 * @param delta (#PEER_ONLINE_DELTA) down (-1) or up (1)
1856 * @param prob_go_on_off the probability of the action
1859 manage_service_wrapper (unsigned int i, unsigned int j,
1860 enum PEER_ONLINE_DELTA delta,
1861 double prob_go_on_off)
1863 struct OpListEntry *entry = NULL;
1866 /* make sure that management operation is not already scheduled */
1867 if (NULL != rps_peers[j].entry_op_manage)
1872 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1875 "%u. selected peer (%u: %s) is %s.\n",
1878 GNUNET_i2s (rps_peers[j].peer_id),
1879 (PEER_GO_ONLINE == delta) ? "online" : "offline");
1880 if (prob < prob_go_on_off * UINT32_MAX)
1882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1884 GNUNET_i2s (rps_peers[j].peer_id),
1885 (PEER_GO_OFFLINE == delta) ? "offline" : "online");
1887 if (PEER_GO_OFFLINE == delta)
1888 cancel_pending_req_rep (&rps_peers[j]);
1889 entry = make_oplist_entry ();
1890 entry->delta = delta;
1892 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
1897 (PEER_GO_OFFLINE == delta) ?
1899 rps_peers[j].entry_op_manage = entry;
1909 double portion_online;
1910 unsigned int *permut;
1911 double prob_go_offline;
1912 double portion_go_online;
1913 double portion_go_offline;
1917 if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test))
1921 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1922 "Churn function executing\n");
1924 churn_task = NULL; /* Should be invalid by now */
1926 /* Compute the probability for an online peer to go offline
1928 portion_online = num_peers_online * 1.0 / num_peers;
1929 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1930 "Portion online: %f\n",
1932 portion_go_online = ((1 - portion_online) * .5 * .66);
1933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1934 "Portion that should go online: %f\n",
1936 portion_go_offline = (portion_online + portion_go_online) - .75;
1937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1938 "Portion that probably goes offline: %f\n",
1939 portion_go_offline);
1940 prob_go_offline = portion_go_offline / (portion_online * .5);
1941 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1942 "Probability of a selected online peer to go offline: %f\n",
1945 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
1946 (unsigned int) num_peers);
1948 /* Go over 50% randomly chosen peers */
1949 for (i = 0; i < .5 * num_peers; i++)
1953 /* If online, shut down with certain probability */
1954 if (GNUNET_YES == rps_peers[j].online)
1956 manage_service_wrapper (i, j, -1, prob_go_offline);
1959 /* If offline, restart with certain probability */
1960 else if (GNUNET_NO == rps_peers[j].online)
1962 manage_service_wrapper (i, j, 1, 0.66);
1966 GNUNET_free (permut);
1968 churn_task = GNUNET_SCHEDULER_add_delayed (
1969 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1976 * Initialise given RPSPeer
1979 profiler_init_peer (struct RPSPeer *rps_peer)
1981 rps_peer->num_ids_to_request = cur_test_run.num_requests;
1982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n",
1983 rps_peer->num_ids_to_request);
1988 * Callback to call on receipt of a reply
1990 * @param cls closure
1991 * @param n number of peers
1992 * @param recv_peers the received peers
1995 profiler_reply_handle (void *cls,
1997 const struct GNUNET_PeerIdentity *recv_peers)
1999 struct RPSPeer *rps_peer;
2000 struct RPSPeer *rcv_rps_peer;
2001 char file_name_buf[128];
2002 char file_name_dh_buf[128];
2003 char file_name_dhr_buf[128];
2004 char file_name_dhru_buf[128];
2005 char *file_name = file_name_buf;
2006 char *file_name_dh = file_name_dh_buf;
2007 char *file_name_dhr = file_name_dhr_buf;
2008 char *file_name_dhru = file_name_dhru_buf;
2010 struct PendingReply *pending_rep = (struct PendingReply *) cls;
2012 pending_rep->req_handle = NULL;
2013 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n");
2014 rps_peer = pending_rep->rps_peer;
2015 (void) GNUNET_asprintf (&file_name,
2016 "/tmp/rps/received_ids-%u",
2019 (void) GNUNET_asprintf (&file_name_dh,
2020 "/tmp/rps/diehard_input-%u",
2022 (void) GNUNET_asprintf (&file_name_dhr,
2023 "/tmp/rps/diehard_input_raw-%u",
2025 (void) GNUNET_asprintf (&file_name_dhru,
2026 "/tmp/rps/diehard_input_raw_aligned-%u",
2028 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2029 "[%s] got %" PRIu64 " peers:\n",
2030 GNUNET_i2s (rps_peer->peer_id),
2032 for (i = 0; i < n; i++)
2034 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2037 GNUNET_i2s (&recv_peers[i]));
2040 GNUNET_i2s_full (&recv_peers[i]));
2041 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]);
2042 GNUNET_assert (NULL != rcv_rps_peer);
2043 tofile (file_name_dh,
2045 (uint32_t) rcv_rps_peer->index);
2047 to_file_raw (file_name_dhr,
2048 (char *) &rcv_rps_peer->index,
2050 to_file_raw_unaligned (file_name_dhru,
2051 (char *) &rcv_rps_peer->index,
2054 #endif /* TO_FILE */
2056 default_reply_handle (cls, n, recv_peers);
2061 * Callback to call on receipt of a reply
2063 * @param cls closure
2064 * @param n number of peers
2065 * @param recv_peers the received peers
2068 profiler_reply_handle_info (void *cls,
2069 const struct GNUNET_PeerIdentity *recv_peer,
2071 uint32_t num_observed)
2073 struct RPSPeer *rps_peer;
2074 struct RPSPeer *rcv_rps_peer;
2075 char file_name_buf[128];
2076 char file_name_dh_buf[128];
2077 char file_name_dhr_buf[128];
2078 char file_name_dhru_buf[128];
2079 char *file_name = file_name_buf;
2080 char *file_name_dh = file_name_dh_buf;
2081 char *file_name_dhr = file_name_dhr_buf;
2082 char *file_name_dhru = file_name_dhru_buf;
2084 struct PendingReply *pending_rep = (struct PendingReply *) cls;
2086 pending_rep->req_handle = NULL;
2087 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n");
2088 rps_peer = pending_rep->rps_peer;
2089 (void) GNUNET_asprintf (&file_name,
2090 "/tmp/rps/received_ids-%u",
2093 (void) GNUNET_asprintf (&file_name_dh,
2094 "/tmp/rps/diehard_input-%u",
2096 (void) GNUNET_asprintf (&file_name_dhr,
2097 "/tmp/rps/diehard_input_raw-%u",
2099 (void) GNUNET_asprintf (&file_name_dhru,
2100 "/tmp/rps/diehard_input_raw_aligned-%u",
2102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2103 "[%s] got peer with info:\n",
2104 GNUNET_i2s (rps_peer->peer_id));
2105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2107 GNUNET_i2s (recv_peer));
2109 "%s %d %" PRIu32 " \n",
2110 GNUNET_i2s_full (recv_peer),
2113 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, recv_peer);
2114 GNUNET_assert (NULL != rcv_rps_peer);
2115 tofile (file_name_dh,
2117 (uint32_t) rcv_rps_peer->index);
2119 to_file_raw (file_name_dhr,
2120 (char *) &rcv_rps_peer->index,
2122 to_file_raw_unaligned (file_name_dhru,
2123 (char *) &rcv_rps_peer->index,
2126 #endif /* TO_FILE */
2127 default_reply_handle (cls, 1, recv_peer);
2132 profiler_cb (struct RPSPeer *rps_peer)
2134 if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test))
2140 if ((HAVE_CHURN == cur_test_run.have_churn) && (NULL == churn_task))
2142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2143 "Starting churn task\n");
2144 churn_task = GNUNET_SCHEDULER_add_delayed (
2145 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
2151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2152 "Not starting churn task\n");
2155 /* Only request peer ids at one peer.
2156 * (It's the before-last because last one is target of the focussed attack.)
2158 if (0 < rps_peer->num_ids_to_request)
2159 schedule_missing_requests (rps_peer);
2164 * Function called from #profiler_eval with a filename.
2166 * @param cls closure
2167 * @param filename complete filename (absolute path)
2168 * @return #GNUNET_OK to continue to iterate,
2169 * #GNUNET_NO to stop iteration with no error,
2170 * #GNUNET_SYSERR to abort iteration with error!
2173 file_name_cb (void *cls, const char *filename)
2175 if (NULL != strstr (filename, "sampler_el"))
2177 struct RPS_SamplerElement *s_elem;
2178 struct GNUNET_CRYPTO_AuthKey auth_key;
2179 const char *key_char;
2183 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
2184 tofile (filename, "--------------------------\n");
2186 auth_key = string_to_auth_key (key_char);
2187 s_elem = RPS_sampler_elem_create ();
2188 RPS_sampler_elem_set (s_elem, auth_key);
2190 for (i = 0; i < num_peers; i++)
2192 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
2194 RPS_sampler_elem_destroy (s_elem);
2201 * This is run after the test finished.
2203 * Compute all perfect samples.
2206 profiler_eval (void)
2209 /* Compute perfect sample for each sampler element */
2210 if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL))
2212 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
2214 #endif /* TO_FILE */
2220 /** @brief is b in view of a?
2228 is_in_view (uint32_t a, uint32_t b)
2232 for (i = 0; i < rps_peers[a].cur_view_count; i++)
2234 if (0 == memcmp (rps_peers[b].peer_id,
2235 &rps_peers[a].cur_view[i],
2236 sizeof(struct GNUNET_PeerIdentity)))
2246 get_idx_of_pid (const struct GNUNET_PeerIdentity *pid)
2250 for (i = 0; i < num_peers; i++)
2252 if (0 == memcmp (pid,
2253 rps_peers[i].peer_id,
2254 sizeof(struct GNUNET_PeerIdentity)))
2259 // return 0; /* Should not happen - make compiler happy */
2260 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2261 "No known _PeerIdentity %s!\n",
2262 GNUNET_i2s_full (pid));
2268 * @brief Counts number of peers in view of a that have b in their view
2276 count_containing_views (uint32_t a, uint32_t b)
2282 for (i = 0; i < rps_peers[a].cur_view_count; i++)
2284 peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]);
2285 if (GNUNET_YES == is_in_view (peer_idx, b))
2295 * @brief Computes the probability for each other peer to be selected by the
2296 * sampling process based on the views of all peers
2298 * @param peer_idx index of the peer that is about to sample
2301 compute_probabilities (uint32_t peer_idx)
2303 // double probs[num_peers] = { 0 };
2304 double probs[num_peers];
2305 double probs_hist[num_peers]; /* Probability respecting the history */
2306 size_t probs_as_str_size = (num_peers * 10 + 2) * sizeof(char);
2307 char *probs_as_str = GNUNET_malloc (probs_as_str_size);
2308 char *probs_as_str_cpy;
2313 uint32_t cont_views;
2314 uint32_t number_of_being_in_pull_events;
2316 double sum_non_zero_prob = 0;
2317 double sum_non_zero_prob_hist = 0;
2319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2320 "Computing probabilities for peer %" PRIu32 "\n", peer_idx);
2321 /* Firstly without knowledge of old views */
2322 for (i = 0; i < num_peers; i++)
2324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2325 "\tfor peer %" PRIu32 ":\n", i);
2326 view_size = rps_peers[i].cur_view_count;
2327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2328 "\t\tview_size: %" PRIu32 "\n", view_size);
2329 /* For peer i the probability of being sampled is
2330 * evenly distributed among all possibly observed peers. */
2331 /* We could have observed a peer in three cases:
2332 * 1. peer sent a push
2333 * 2. peer was contained in a pull reply
2334 * 3. peer was in history (sampler) - ignored for now */
2335 /* 1. Probability of having received a push from peer i */
2336 if ((GNUNET_YES == is_in_view (i, peer_idx)) &&
2337 (1 <= (0.45 * view_size)))
2339 if (0 == binom (view_size, 0.45 * view_size))
2343 prob_push = 1.0 * binom (0.45 * view_size, 1)
2345 binom (view_size, 0.45 * view_size);
2347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2348 "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n",
2352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2353 "\t\tposs choices from view: %" PRIu32 ", containing i: %"
2355 binom (view_size, 0.45 * view_size),
2356 binom (0.45 * view_size, 1));
2361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2362 "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n",
2366 /* 2. Probability of peer i being contained in pulls */
2367 view_size = rps_peers[peer_idx].cur_view_count;
2368 cont_views = count_containing_views (peer_idx, i);
2369 number_of_being_in_pull_events =
2370 (binom (view_size, 0.45 * view_size)
2371 - binom (view_size - cont_views, 0.45 * view_size));
2372 if (0 != number_of_being_in_pull_events)
2374 prob_pull = number_of_being_in_pull_events
2376 (1.0 * binom (view_size, 0.45 * view_size));
2382 probs[i] = prob_push + prob_pull - (prob_push * prob_pull);
2383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2384 "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32
2385 " peers in its view who know %" PRIu32 " prob: %f\n",
2391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2392 "\t\tnumber of possible pull combinations: %" PRIu32 "\n",
2393 binom (view_size, 0.45 * view_size));
2394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2395 "\t\tnumber of possible pull combinations without %" PRIu32
2398 binom (view_size - cont_views, 0.45 * view_size));
2399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2400 "\t\tnumber of possible pull combinations with %" PRIu32
2403 number_of_being_in_pull_events);
2405 probs_hist[i] = 0.9 * rps_peers[peer_idx].eval_probs_cache[i] + probs[i];
2406 rps_peers[peer_idx].eval_probs_cache[i] = probs_hist[i];
2408 sum_non_zero_prob += probs[i];
2409 sum_non_zero_prob_hist += probs_hist[i];
2412 if (0 != sum_non_zero_prob)
2414 for (i = 0; i < num_peers; i++)
2416 probs[i] = probs[i] * (1.0 / sum_non_zero_prob);
2419 if (0 != sum_non_zero_prob_hist)
2421 for (i = 0; i < num_peers; i++)
2423 probs_hist[i] = probs_hist[i] * (1.0 / sum_non_zero_prob_hist);
2428 for (i = 0; i < num_peers; i++)
2430 probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size);
2431 tmp = GNUNET_snprintf (probs_as_str,
2433 "%s %7.6f", probs_as_str_cpy, probs[i]);
2434 GNUNET_free (probs_as_str_cpy);
2435 GNUNET_assert (0 <= tmp);
2438 to_file_w_len (rps_peers[peer_idx].file_name_probs,
2442 probs_as_str[0] = '\0';
2443 for (i = 0; i < num_peers; i++)
2445 probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size);
2446 tmp = GNUNET_snprintf (probs_as_str,
2448 "%s %7.6f", probs_as_str_cpy, probs_hist[i]);
2449 GNUNET_free (probs_as_str_cpy);
2450 GNUNET_assert (0 <= tmp);
2453 to_file_w_len (rps_peers[peer_idx].file_name_probs_hist,
2456 GNUNET_free (probs_as_str);
2461 * @brief This counts the number of peers in which views a given peer occurs.
2463 * It also stores this value in the rps peer.
2465 * @param peer_idx the index of the peer to count the representation
2467 * @return the number of occurrences
2470 count_peer_in_views_2 (uint32_t peer_idx)
2475 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2477 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2479 if (0 == memcmp (rps_peers[peer_idx].peer_id,
2480 &rps_peers[i].cur_view[j],
2481 sizeof(struct GNUNET_PeerIdentity)))
2488 rps_peers[peer_idx].count_in_views = count;
2494 cumulated_view_sizes ()
2499 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2501 view_sizes += rps_peers[i].cur_view_count;
2508 count_peer_in_views (uint32_t *count_peers)
2512 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2514 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2516 if (0 == memcmp (rps_peers[i].peer_id,
2517 &rps_peers[i].cur_view[j],
2518 sizeof(struct GNUNET_PeerIdentity)))
2528 compute_diversity ()
2531 /* ith entry represents the numer of occurrences in other peer's views */
2532 uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t);
2533 uint32_t views_total_size;
2535 /* deviation from expected number of peers */
2536 double *deviation = GNUNET_new_array (num_peers, double);
2538 views_total_size = 0;
2541 /* For each peer count its representation in other peer's views*/
2542 for (i = 0; i < num_peers; i++) /* Peer to count */
2544 views_total_size += rps_peers[i].cur_view_count;
2545 count_peer_in_views (count_peers);
2546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2547 "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32
2550 GNUNET_i2s (rps_peers[i].peer_id),
2554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2555 "size of all views combined: %" PRIu32 "\n",
2557 expected = ((double) 1 / num_peers) * views_total_size;
2558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2559 "Expected number of occurrences of each peer in all views: %f\n",
2561 for (i = 0; i < num_peers; i++) /* Peer to count */
2563 deviation[i] = expected - count_peers[i];
2564 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2565 "Deviation from expectation: %f\n", deviation[i]);
2567 GNUNET_free (count_peers);
2568 GNUNET_free (deviation);
2577 for (i = 0; i < num_peers; i++) /* Peer to count */
2579 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2580 "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n",
2582 GNUNET_i2s (rps_peers[i].peer_id),
2583 rps_peers[i].cur_view_count);
2589 all_views_updated_cb ()
2591 compute_diversity ();
2592 print_view_sizes ();
2597 view_update_cb (void *cls,
2599 const struct GNUNET_PeerIdentity *peers)
2601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2602 "View was updated (%" PRIu64 ")\n", view_size);
2603 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
2604 to_file ("/tmp/rps/view_sizes.txt",
2605 "%" PRIu64 " %" PRIu32 "",
2608 for (uint64_t i = 0; i < view_size; i++)
2610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2611 "\t%s\n", GNUNET_i2s (&peers[i]));
2613 GNUNET_array_grow (rps_peer->cur_view,
2614 rps_peer->cur_view_count,
2616 // *rps_peer->cur_view = *peers;
2617 GNUNET_memcpy (rps_peer->cur_view,
2619 view_size * sizeof(struct GNUNET_PeerIdentity));
2620 to_file ("/tmp/rps/count_in_views.txt",
2621 "%" PRIu64 " %" PRIu32 "",
2623 count_peer_in_views_2 (rps_peer->index));
2624 cumulated_view_sizes ();
2627 to_file ("/tmp/rps/repr.txt",
2628 "%" PRIu64 /* index */
2629 " %" PRIu32 /* occurrence in views */
2630 " %" PRIu32 /* view sizes */
2631 " %f" /* fraction of repr in views */
2632 " %f" /* average view size */
2633 " %f" /* prob of occurrence in view slot */
2634 " %f" "", /* exp frac of repr in views */
2636 count_peer_in_views_2 (rps_peer->index),
2638 count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */
2639 view_sizes / (view_size * 1.0), /* average view size */
2640 1.0 / view_size, /* prob of occurrence in view slot */
2641 (1.0 / view_size) * (view_sizes / view_size) /* expected fraction of repr in views */
2644 compute_probabilities (rps_peer->index);
2645 all_views_updated_cb ();
2650 pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
2652 rps_peer->file_name_probs =
2653 store_prefix_file_name (rps_peer->index, "probs");
2654 rps_peer->file_name_probs_hist =
2655 store_prefix_file_name (rps_peer->index, "probs_hist");
2656 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer);
2661 write_final_stats (void)
2663 uint64_t sums[STAT_TYPE_MAX] = { 0 };
2665 for (uint32_t i = 0; i < num_peers; i++)
2667 to_file ("/tmp/rps/final_stats.csv",
2668 "%" PRIu32 ", " /* index */
2670 PRIu64 ", %" /* rounds */
2671 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %"
2672 PRIu64 ", %" /* blocking */
2673 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */
2674 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */
2675 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %"
2676 PRIu64 ", %" /* recv */
2677 PRIu64 ", %" /* view size */
2678 PRIu64 ", %" /* known peers */
2679 PRIu64 ", %" /* valid peers */
2680 PRIu64 ", %" /* learned peers */
2681 PRIu64 ", %" /* pending online checks */
2682 PRIu64 ", %" /* unrequested pull replies */
2683 PRIu64 ", %" /* peers in push map */
2684 PRIu64 ", %" /* peers in pull map */
2685 PRIu64 ", %" /* peers in view */
2686 PRIu64 "\n" /* view size aim */,
2688 GNUNET_i2s (rps_peers[i].peer_id),
2689 rps_peers[i].stats[STAT_TYPE_ROUNDS],
2690 rps_peers[i].stats[STAT_TYPE_BLOCKS],
2691 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH],
2692 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH],
2693 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL],
2694 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
2695 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
2696 rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND],
2697 rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND_MH],
2698 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ],
2699 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ_MH],
2700 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP],
2701 rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND],
2702 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ],
2703 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ_MH],
2704 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP],
2705 rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND],
2706 rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND_MH],
2707 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ],
2708 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ_MH],
2709 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP_MH],
2710 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP],
2711 rps_peers[i].stats[STAT_TYPE_VIEW_SIZE],
2712 rps_peers[i].stats[STAT_TYPE_KNOWN_PEERS],
2713 rps_peers[i].stats[STAT_TYPE_VALID_PEERS],
2714 rps_peers[i].stats[STAT_TYPE_LEARND_PEERS],
2715 rps_peers[i].stats[STAT_TYPE_PENDING_ONLINE_CHECKS],
2716 rps_peers[i].stats[STAT_TYPE_UNREQUESTED_PULL_REPLIES],
2717 rps_peers[i].stats[STAT_TYPE_PEERS_IN_PUSH_MAP],
2718 rps_peers[i].stats[STAT_TYPE_PEERS_IN_PULL_MAP],
2719 rps_peers[i].stats[STAT_TYPE_PEERS_IN_VIEW],
2720 rps_peers[i].stats[STAT_TYPE_VIEW_SIZE_AIM]);
2721 for (enum STAT_TYPE stat_type = STAT_TYPE_ROUNDS;
2722 stat_type < STAT_TYPE_MAX;
2725 sums[stat_type] += rps_peers[i].stats[stat_type];
2728 to_file ("/tmp/rps/final_stats.dat",
2730 PRIu64 " %" /* rounds */
2731 PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64
2733 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */
2734 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */
2735 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %"
2736 PRIu64 ", %" /* recv */
2737 PRIu64 ", %" /* view size */
2738 PRIu64 ", %" /* known peers */
2739 PRIu64 ", %" /* valid peers */
2740 PRIu64 ", %" /* learned peers */
2741 PRIu64 ", %" /* pending online checks */
2742 PRIu64 ", %" /* unrequested pull replies */
2743 PRIu64 ", %" /* peers in push map */
2744 PRIu64 ", %" /* peers in pull map */
2745 PRIu64 ", %" /* peers in view */
2746 PRIu64 "\n" /* view size aim */,
2747 sums[STAT_TYPE_ROUNDS],
2748 sums[STAT_TYPE_BLOCKS],
2749 sums[STAT_TYPE_BLOCKS_MANY_PUSH],
2750 sums[STAT_TYPE_BLOCKS_NO_PUSH],
2751 sums[STAT_TYPE_BLOCKS_NO_PULL],
2752 sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
2753 sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
2754 sums[STAT_TYPE_ISSUED_PUSH_SEND],
2755 sums[STAT_TYPE_ISSUED_PUSH_SEND_MH],
2756 sums[STAT_TYPE_ISSUED_PULL_REQ],
2757 sums[STAT_TYPE_ISSUED_PULL_REQ_MH],
2758 sums[STAT_TYPE_ISSUED_PULL_REP],
2759 sums[STAT_TYPE_SENT_PUSH_SEND],
2760 sums[STAT_TYPE_SENT_PULL_REQ],
2761 sums[STAT_TYPE_SENT_PULL_REQ_MH],
2762 sums[STAT_TYPE_SENT_PULL_REP],
2763 sums[STAT_TYPE_RECV_PUSH_SEND],
2764 sums[STAT_TYPE_RECV_PUSH_SEND_MH],
2765 sums[STAT_TYPE_RECV_PULL_REQ],
2766 sums[STAT_TYPE_RECV_PULL_REQ_MH],
2767 sums[STAT_TYPE_RECV_PULL_REP],
2768 sums[STAT_TYPE_RECV_PULL_REP_MH],
2769 sums[STAT_TYPE_VIEW_SIZE],
2770 sums[STAT_TYPE_KNOWN_PEERS],
2771 sums[STAT_TYPE_VALID_PEERS],
2772 sums[STAT_TYPE_LEARND_PEERS],
2773 sums[STAT_TYPE_PENDING_ONLINE_CHECKS],
2774 sums[STAT_TYPE_UNREQUESTED_PULL_REPLIES],
2775 sums[STAT_TYPE_PEERS_IN_PUSH_MAP],
2776 sums[STAT_TYPE_PEERS_IN_PULL_MAP],
2777 sums[STAT_TYPE_PEERS_IN_VIEW],
2778 sums[STAT_TYPE_VIEW_SIZE_AIM]);
2783 * Continuation called by #GNUNET_STATISTICS_get() functions.
2785 * Remembers that this specific statistics value was received for this peer.
2786 * Checks whether all peers received their statistics yet.
2787 * Issues the shutdown.
2789 * @param cls closure
2790 * @param success #GNUNET_OK if statistics were
2791 * successfully obtained, #GNUNET_SYSERR if not.
2794 post_test_shutdown_ready_cb (void *cls,
2797 struct STATcls *stat_cls = (struct STATcls *) cls;
2798 struct RPSPeer *rps_peer = stat_cls->rps_peer;
2800 rps_peer->h_stat_get[stat_cls->stat_type] = NULL;
2801 if (GNUNET_OK == success)
2803 /* set flag that we we got the value */
2804 rps_peer->stat_collected_flags |= BIT (stat_cls->stat_type);
2808 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2809 "Peer %u did not receive statistics value\n",
2811 GNUNET_free (stat_cls);
2816 if ((NULL != rps_peer->stat_op) &&
2817 (GNUNET_YES == check_statistics_collect_completed_single_peer (
2820 GNUNET_TESTBED_operation_done (rps_peer->stat_op);
2823 write_final_stats ();
2824 if (GNUNET_YES == check_statistics_collect_completed ())
2826 // write_final_stats ();
2827 GNUNET_free (stat_cls);
2828 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2830 GNUNET_SCHEDULER_shutdown ();
2834 GNUNET_free (stat_cls);
2840 * Callback function to process statistic values.
2842 * @param cls closure
2843 * @param subsystem name of subsystem that created the statistic
2844 * @param name the name of the datum
2845 * @param value the current value
2846 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
2847 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
2850 stat_iterator (void *cls,
2851 const char *subsystem,
2856 const struct STATcls *stat_cls = (const struct STATcls *) cls;
2857 struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer;
2858 enum STAT_TYPE stat_type;
2861 (void) is_persistent;
2863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2864 "Got stat value: %s - %" PRIu64 " (%u)\n",
2868 to_file (rps_peer->file_name_stats,
2869 "%s: %" PRIu64 "\n",
2872 stat_type = stat_str_2_type (name);
2873 GNUNET_assert (STAT_TYPE_ROUNDS <= stat_type &&
2874 STAT_TYPE_MAX > stat_type);
2875 rps_peer->stats[stat_type] = value;
2881 post_profiler (struct RPSPeer *rps_peer)
2883 if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics)
2888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2889 "Going to request statistic values with mask 0x%" PRIx32 "\n",
2890 cur_test_run.stat_collect_flags);
2892 struct STATcls *stat_cls;
2894 for (stat_type = STAT_TYPE_ROUNDS;
2895 stat_type < STAT_TYPE_MAX;
2898 if (BIT (stat_type) & cur_test_run.stat_collect_flags)
2900 stat_cls = GNUNET_malloc (sizeof(struct STATcls));
2901 stat_cls->rps_peer = rps_peer;
2902 stat_cls->stat_type = stat_type;
2903 rps_peer->file_name_stats =
2904 store_prefix_file_name (rps_peer->peer_id, "stats");
2905 rps_peer->h_stat_get[stat_type] =
2906 GNUNET_STATISTICS_get (rps_peer->stats_h,
2908 stat_type_strings [stat_type],
2909 post_test_shutdown_ready_cb,
2911 (struct STATcls *) stat_cls);
2912 GNUNET_assert (NULL != rps_peer->h_stat_get);
2913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2914 "Requested statistics for %s (peer %" PRIu32 ")\n",
2915 stat_type_strings [stat_type],
2919 GNUNET_free (rps_peer->eval_probs_cache);
2923 /***********************************************************************
2924 * /Definition of tests
2925 ***********************************************************************/
2929 * Actual "main" function for the testcase.
2931 * @param cls closure
2932 * @param h the run handle
2933 * @param n_peers number of peers in 'peers'
2934 * @param peers handle to peers run in the testbed
2935 * @param links_succeeded the number of overlay link connection attempts that
2937 * @param links_failed the number of overlay link connection attempts that
2941 test_run (void *cls,
2942 struct GNUNET_TESTBED_RunHandle *h,
2943 unsigned int n_peers,
2944 struct GNUNET_TESTBED_Peer **peers,
2945 unsigned int links_succeeded,
2946 unsigned int links_failed)
2949 struct OpListEntry *entry;
2953 (void) links_failed;
2955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n");
2957 /* Check whether we timed out */
2958 if ((n_peers != num_peers) ||
2960 (0 == links_succeeded) )
2962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2963 "Going down due to args (eg. timeout)\n");
2964 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers);
2965 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n",
2967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers);
2968 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n",
2971 GNUNET_SCHEDULER_shutdown ();
2976 /* Initialize peers */
2977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n");
2978 testbed_peers = peers;
2979 num_peers_online = 0;
2980 for (i = 0; i < num_peers; i++)
2982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i);
2983 entry = make_oplist_entry ();
2985 rps_peers[i].index = i;
2986 if (NULL != cur_test_run.init_peer)
2987 cur_test_run.init_peer (&rps_peers[i]);
2988 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
2990 rps_peers->cur_view_count = 0;
2991 rps_peers->cur_view = NULL;
2993 entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
2994 GNUNET_TESTBED_PIT_IDENTITY,
2999 /* Bring peers up */
3000 GNUNET_assert (num_peers == n_peers);
3001 for (i = 0; i < n_peers; i++)
3003 rps_peers[i].index = i;
3005 GNUNET_TESTBED_service_connect (&rps_peers[i],
3008 &rps_connect_complete_cb,
3010 &rps_connect_adapter,
3011 &rps_disconnect_adapter,
3013 /* Connect all peers to statistics service */
3014 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
3016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3017 "Connecting to statistics service\n");
3018 rps_peers[i].stat_op =
3019 GNUNET_TESTBED_service_connect (NULL,
3024 &stat_connect_adapter,
3025 &stat_disconnect_adapter,
3030 if (NULL != churn_task)
3031 GNUNET_SCHEDULER_cancel (churn_task);
3032 post_test_task = GNUNET_SCHEDULER_add_delayed (duration, &post_test_op, NULL);
3033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n",
3034 timeout.rel_value_us / 1000000);
3035 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout,
3038 GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL);
3043 * Entry point for the testcase, sets up the testbed.
3045 * @param argc unused
3046 * @param argv unused
3051 const char *cfgfile,
3052 const struct GNUNET_CONFIGURATION_Handle *cfg)
3059 /* Defaults for tests */
3062 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
3063 cur_test_run.name = "test-rps-profiler";
3067 cur_test_run.init_peer = profiler_init_peer;
3068 // cur_test_run.pre_test = mal_pre;
3069 cur_test_run.pre_test = pre_profiler;
3070 cur_test_run.main_test = profiler_cb;
3071 cur_test_run.reply_handle = profiler_reply_handle;
3072 cur_test_run.eval_cb = profiler_eval;
3073 cur_test_run.post_test = post_profiler;
3074 cur_test_run.request_interval = 2;
3075 if (0 == cur_test_run.num_requests)
3076 cur_test_run.num_requests = 5;
3077 // cur_test_run.have_churn = HAVE_CHURN;
3078 cur_test_run.have_churn = HAVE_NO_CHURN;
3079 cur_test_run.have_quick_quit = HAVE_QUICK_QUIT;
3080 cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
3081 cur_test_run.stat_collect_flags = BIT (STAT_TYPE_ROUNDS)
3082 | BIT (STAT_TYPE_BLOCKS)
3083 | BIT (STAT_TYPE_BLOCKS_MANY_PUSH)
3084 | BIT (STAT_TYPE_BLOCKS_NO_PUSH)
3085 | BIT (STAT_TYPE_BLOCKS_NO_PULL)
3086 | BIT (STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL)
3087 | BIT (STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL)
3088 | BIT (STAT_TYPE_ISSUED_PUSH_SEND)
3089 | BIT (STAT_TYPE_ISSUED_PUSH_SEND_MH)
3090 | BIT (STAT_TYPE_ISSUED_PULL_REQ)
3091 | BIT (STAT_TYPE_ISSUED_PULL_REQ_MH)
3092 | BIT (STAT_TYPE_ISSUED_PULL_REP)
3093 | BIT (STAT_TYPE_SENT_PUSH_SEND)
3094 | BIT (STAT_TYPE_SENT_PULL_REQ)
3095 | BIT (STAT_TYPE_SENT_PULL_REQ_MH)
3096 | BIT (STAT_TYPE_SENT_PULL_REP)
3097 | BIT (STAT_TYPE_RECV_PUSH_SEND)
3098 | BIT (STAT_TYPE_RECV_PUSH_SEND_MH)
3099 | BIT (STAT_TYPE_RECV_PULL_REQ)
3100 | BIT (STAT_TYPE_RECV_PULL_REQ_MH)
3101 | BIT (STAT_TYPE_RECV_PULL_REP)
3102 | BIT (STAT_TYPE_RECV_PULL_REP_MH)
3103 | BIT (STAT_TYPE_VIEW_SIZE)
3104 | BIT (STAT_TYPE_KNOWN_PEERS)
3105 | BIT (STAT_TYPE_VALID_PEERS)
3106 | BIT (STAT_TYPE_LEARND_PEERS)
3107 | BIT (STAT_TYPE_PENDING_ONLINE_CHECKS)
3108 | BIT (STAT_TYPE_UNREQUESTED_PULL_REPLIES)
3109 | BIT (STAT_TYPE_PEERS_IN_PUSH_MAP)
3110 | BIT (STAT_TYPE_PEERS_IN_PULL_MAP)
3111 | BIT (STAT_TYPE_PEERS_IN_VIEW)
3112 | BIT (STAT_TYPE_VIEW_SIZE_AIM);
3113 cur_test_run.have_collect_view = COLLECT_VIEW;
3115 /* 'Clean' directory */
3116 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
3117 GNUNET_DISK_directory_create ("/tmp/rps/");
3118 if (0 == duration.rel_value_us)
3120 if (0 == timeout.rel_value_us)
3122 duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90);
3123 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3125 + (0.01 * num_peers));
3129 duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3130 (timeout.rel_value_us / 1000000)
3136 if (0 == timeout.rel_value_us)
3138 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3139 ((duration.rel_value_us
3141 * 1.2) + (0.01 * num_peers));
3144 GNUNET_assert (duration.rel_value_us < timeout.rel_value_us);
3145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3146 "duration is %lus\n",
3147 duration.rel_value_us / 1000000);
3148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3149 "timeout is %lus\n",
3150 timeout.rel_value_us / 1000000);
3152 /* Compute number of bits for representing largest peer id */
3153 for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++)
3155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3156 "Need %u bits to represent %" PRIu32 " peers\n",
3160 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
3161 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
3162 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
3163 if ((2 == mal_type) ||
3165 target_peer = &rps_peer_ids[num_peers - 2];
3168 GNUNET_TESTBED_run (NULL,
3180 * Entry point for the testcase, sets up the testbed.
3182 * @param argc unused
3183 * @param argv unused
3184 * @return 0 on success
3187 main (int argc, char *argv[])
3190 struct GNUNET_GETOPT_CommandLineOption options[] = {
3191 GNUNET_GETOPT_option_uint ('n',
3194 gettext_noop ("number of peers to start"),
3196 GNUNET_GETOPT_option_relative_time ('d',
3200 "duration of the profiling"),
3202 GNUNET_GETOPT_option_relative_time ('t',
3206 "timeout for the profiling"),
3208 GNUNET_GETOPT_option_uint ('r',
3211 gettext_noop ("number of PeerIDs to request"),
3212 &cur_test_run.num_requests),
3213 GNUNET_GETOPT_OPTION_END
3216 unsetenv ("XDG_DATA_HOME");
3217 unsetenv ("XDG_CONFIG_HOME");
3219 // GNUNET_STRINGS_get_utf8_args (argc, argv,
3224 GNUNET_PROGRAM_run (argc,
3226 "gnunet-rps-profiler",
3228 "Measure quality and performance of the RPS service."),
3237 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3238 "Test did not run successfully!\n");
3242 ret_value = cur_test_run.eval_cb ();
3243 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
3245 GNUNET_array_grow (rps_peers->cur_view,
3246 rps_peers->cur_view_count,
3249 GNUNET_free (rps_peers);
3250 GNUNET_free (rps_peer_ids);
3251 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
3257 /* end of test_rps.c */