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 many peers are ready to shutdown?
46 static uint32_t num_shutdown_ready;
49 * How long do we run the test?
51 //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
52 static struct GNUNET_TIME_Relative timeout;
56 * Portion of malicious peers
58 static double portion = .1;
61 * Type of malicious peer to test
63 static unsigned int mal_type = 0;
66 * Handles to all of the running peers
68 static struct GNUNET_TESTBED_Peer **testbed_peers;
71 * @brief Indicates whether peer should go off- or online
73 enum PEER_ONLINE_DELTA {
75 * @brief Indicates peer going online
79 * @brief Indicates peer going offline
92 struct OpListEntry *next;
97 struct OpListEntry *prev;
100 * The testbed operation
102 struct GNUNET_TESTBED_Operation *op;
105 * Depending on whether we start or stop RPS service at the peer, set this to
106 * #PEER_GO_ONLINE (1) or #PEER_GO_OFFLINE (-1)
108 enum PEER_ONLINE_DELTA delta;
111 * Index of the regarding peer
119 static struct OpListEntry *oplist_head;
124 static struct OpListEntry *oplist_tail;
128 * A pending reply: A request was sent and the reply is pending.
135 struct PendingReply *next;
136 struct PendingReply *prev;
139 * Handle to the request we are waiting for
141 struct GNUNET_RPS_Request_Handle *req_handle;
144 * The peer that requested
146 struct RPSPeer *rps_peer;
151 * A pending request: A request was not made yet but is scheduled for later.
153 struct PendingRequest
158 struct PendingRequest *next;
159 struct PendingRequest *prev;
162 * Handle to the request we are waiting for
164 struct GNUNET_SCHEDULER_Task *request_task;
167 * The peer that requested
169 struct RPSPeer *rps_peer;
174 * Information we track for each peer.
184 * Handle for RPS connect operation.
186 struct GNUNET_TESTBED_Operation *op;
189 * Handle to RPS service.
191 struct GNUNET_RPS_Handle *rps_handle;
196 struct GNUNET_PeerIdentity *peer_id;
199 * A request handle to check for an request
201 //struct GNUNET_RPS_Request_Handle *req_handle;
204 * Peer on- or offline?
209 * Number of Peer IDs to request during the whole test
211 unsigned int num_ids_to_request;
214 * Pending requests DLL
216 struct PendingRequest *pending_req_head;
217 struct PendingRequest *pending_req_tail;
220 * Number of pending requests
222 unsigned int num_pending_reqs;
225 * Pending replies DLL
227 struct PendingReply *pending_rep_head;
228 struct PendingReply *pending_rep_tail;
231 * Number of pending replies
233 unsigned int num_pending_reps;
236 * Number of received PeerIDs
238 unsigned int num_recv_ids;
241 * Pending operation on that peer
243 const struct OpListEntry *entry_op_manage;
246 * Testbed operation to connect to statistics service
248 struct GNUNET_TESTBED_Operation *stat_op;
251 * Handle to the statistics service
253 struct GNUNET_STATISTICS_Handle *stats_h;
258 * Information for all the peers.
260 static struct RPSPeer *rps_peers;
263 * Peermap to get the index of a given peer ID quick.
265 static struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
270 static struct GNUNET_PeerIdentity *rps_peer_ids;
273 * ID of the targeted peer.
275 static struct GNUNET_PeerIdentity *target_peer;
278 * ID of the peer that requests for the evaluation.
280 static struct RPSPeer *eval_peer;
283 * Number of online peers.
285 static unsigned int num_peers_online;
288 * Return value from 'main'.
293 * Identifier for the churn task that runs periodically
295 static struct GNUNET_SCHEDULER_Task *shutdown_task;
298 * Identifier for the churn task that runs periodically
300 static struct GNUNET_SCHEDULER_Task *churn_task;
303 * Called to initialise the given RPSPeer
305 typedef void (*InitPeer) (struct RPSPeer *rps_peer);
308 * @brief Called directly after connecting to the service
310 * @param rps_peer Specific peer the function is called on
311 * @param h the handle to the rps service
313 typedef void (*PreTest) (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h);
316 * @brief Executes functions to test the api/service for a given peer
318 * Called from within #rps_connect_complete_cb ()
319 * Implemented by #churn_test_cb, #profiler_cb, #mal_cb, #single_req_cb,
320 * #delay_req_cb, #seed_big_cb, #single_peer_seed_cb, #seed_cb, #req_cancel_cb
322 * @param rps_peer the peer the task runs on
324 typedef void (*MainTest) (struct RPSPeer *rps_peer);
327 * Callback called once the requested random peers are available
329 typedef void (*ReplyHandle) (void *cls,
331 const struct GNUNET_PeerIdentity *recv_peers);
334 * Called directly before disconnecting from the service
336 typedef void (*PostTest) (const struct RPSPeer *peer);
339 * Function called after disconnect to evaluate test success
341 typedef int (*EvaluationCallback) (void);
344 * @brief Do we have Churn?
348 * @brief If we have churn this is set
352 * @brief If we have no churn this is set
358 * @brief Is it ok to quit the test before the timeout?
360 enum OPTION_QUICK_QUIT {
362 * @brief It is ok for the test to quit before the timeout triggers
367 * @brief It is NOT ok for the test to quit before the timeout triggers
373 * @brief Do we collect statistics at the end?
375 enum OPTION_COLLECT_STATISTICS {
377 * @brief We collect statistics at the end
382 * @brief We do not collect statistics at the end
384 NO_COLLECT_STATISTICS,
388 * Structure to define a single test
398 * Called with a single peer in order to initialise that peer
403 * Called directly after connecting to the service
408 * Main function for each peer
413 * Callback called once the requested peers are available
415 ReplyHandle reply_handle;
418 * Called directly before disconnecting from the service
423 * Function to evaluate the test results
425 EvaluationCallback eval_cb;
430 uint32_t request_interval;
433 * Number of Requests to make.
435 uint32_t num_requests;
438 * Run with (-out) churn
440 enum OPTION_CHURN have_churn;
443 * Quit test before timeout?
445 enum OPTION_QUICK_QUIT have_quick_quit;
448 * Collect statistics at the end?
450 enum OPTION_COLLECT_STATISTICS have_collect_statistics;
454 * Are we shutting down?
456 static int in_shutdown;
459 * Append arguments to file
462 tofile_ (const char *file_name, const char *line)
464 struct GNUNET_DISK_FileHandle *f;
465 /* char output_buffer[512]; */
470 if (NULL == (f = GNUNET_DISK_file_open (file_name,
471 GNUNET_DISK_OPEN_APPEND |
472 GNUNET_DISK_OPEN_WRITE |
473 GNUNET_DISK_OPEN_CREATE,
474 GNUNET_DISK_PERM_USER_READ |
475 GNUNET_DISK_PERM_USER_WRITE |
476 GNUNET_DISK_PERM_GROUP_READ |
477 GNUNET_DISK_PERM_OTHER_READ)))
479 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
480 "Not able to open file %s\n",
484 /* size = GNUNET_snprintf (output_buffer,
485 sizeof (output_buffer),
487 GNUNET_TIME_absolute_get ().abs_value_us,
491 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
492 "Failed to write string to buffer (size: %i)\n",
497 size = strlen (line) * sizeof (char);
499 size2 = GNUNET_DISK_file_write (f, line, size);
502 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
503 "Unable to write to file! (Size: %lu, size2: %lu)\n",
506 if (GNUNET_YES != GNUNET_DISK_file_close (f))
508 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
509 "Unable to close file\n");
514 if (GNUNET_YES != GNUNET_DISK_file_close (f))
516 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
517 "Unable to close file\n");
522 * This function is used to facilitate writing important information to disk
524 #define tofile(file_name, ...) do {\
527 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
529 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
530 "Failed to create tmp_buf\n");\
532 tofile_(file_name,tmp_buf);\
537 * Write the ids and their according index in the given array to a file
541 ids_to_file (char *file_name,
542 struct GNUNET_PeerIdentity *peer_ids,
543 unsigned int num_peer_ids)
547 for (i=0 ; i < num_peer_ids ; i++)
552 GNUNET_i2s_full (&peer_ids[i]));
557 * Test the success of a single test
567 for (i = 0; i < num_peers; i++)
569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
570 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
572 GNUNET_i2s (rps_peers[i].peer_id),
573 rps_peers[i].num_recv_ids,
574 rps_peers[i].num_ids_to_request,
575 (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids));
576 tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids);
578 return tmp_ok? 0 : 1;
583 * Creates an oplist entry and adds it to the oplist DLL
585 static struct OpListEntry *
588 struct OpListEntry *entry;
590 entry = GNUNET_new (struct OpListEntry);
591 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
597 * Task run on timeout to shut everything down.
600 shutdown_op (void *cls)
604 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
605 "Shutdown task scheduled, going down.\n");
606 in_shutdown = GNUNET_YES;
607 if (NULL != churn_task)
609 GNUNET_SCHEDULER_cancel (churn_task);
612 for (i = 0; i < num_peers; i++)
614 if (NULL != rps_peers[i].op)
615 GNUNET_TESTBED_operation_done (rps_peers[i].op);
616 if (NULL != cur_test_run.post_test)
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i);
619 cur_test_run.post_test (&rps_peers[i]);
622 /* If we do not collect statistics, shut down directly */
623 if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics ||
624 num_peers <= num_shutdown_ready)
626 GNUNET_SCHEDULER_shutdown ();
635 seed_peers (void *cls)
637 struct RPSPeer *peer = cls;
641 // TODO if malicious don't seed mal peers
642 amount = round (.5 * num_peers);
644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
645 for (i = 0 ; i < amount ; i++)
646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
648 GNUNET_i2s (&rps_peer_ids[i]));
650 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
658 seed_peers_big (void *cls)
660 struct RPSPeer *peer = cls;
661 unsigned int seed_msg_size;
662 uint32_t num_peers_max;
666 seed_msg_size = 8; /* sizeof (struct GNUNET_RPS_CS_SeedMessage) */
667 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - seed_msg_size) /
668 sizeof (struct GNUNET_PeerIdentity);
669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
670 "Peers that fit in one seed msg; %u\n",
672 amount = num_peers_max + (0.5 * num_peers_max);
673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
674 "Seeding many (%u) peers:\n",
676 struct GNUNET_PeerIdentity ids_to_seed[amount];
677 for (i = 0; i < amount; i++)
679 ids_to_seed[i] = *peer->peer_id;
680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
682 GNUNET_i2s (&ids_to_seed[i]));
685 GNUNET_RPS_seed_ids (peer->rps_handle, amount, ids_to_seed);
689 * Get the id of peer i.
692 info_cb (void *cb_cls,
693 struct GNUNET_TESTBED_Operation *op,
694 const struct GNUNET_TESTBED_PeerInformation *pinfo,
697 struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
699 if (GNUNET_YES == in_shutdown)
704 if (NULL == pinfo || NULL != emsg)
706 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
707 GNUNET_TESTBED_operation_done (entry->op);
711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
714 GNUNET_i2s (pinfo->result.id));
716 rps_peer_ids[entry->index] = *(pinfo->result.id);
717 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
719 GNUNET_assert (GNUNET_OK ==
720 GNUNET_CONTAINER_multipeermap_put (peer_map,
721 &rps_peer_ids[entry->index],
722 &rps_peers[entry->index],
723 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
724 tofile ("/tmp/rps/peer_ids",
727 GNUNET_i2s_full (&rps_peer_ids[entry->index]));
729 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
730 GNUNET_TESTBED_operation_done (entry->op);
736 * Callback to be called when RPS service connect operation is completed
738 * @param cls the callback closure from functions generating an operation
739 * @param op the operation that has been finished
740 * @param ca_result the RPS service handle returned from rps_connect_adapter
741 * @param emsg error message in case the operation has failed; will be NULL if
742 * operation has executed successfully.
745 rps_connect_complete_cb (void *cls,
746 struct GNUNET_TESTBED_Operation *op,
750 struct RPSPeer *rps_peer = cls;
751 struct GNUNET_RPS_Handle *rps = ca_result;
753 if (GNUNET_YES == in_shutdown)
758 rps_peer->rps_handle = rps;
759 rps_peer->online = GNUNET_YES;
762 GNUNET_assert (op == rps_peer->op);
765 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
766 "Failed to connect to RPS service: %s\n",
769 GNUNET_SCHEDULER_shutdown ();
773 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
775 cur_test_run.main_test (rps_peer);
780 * Adapter function called to establish a connection to
784 * @param cfg configuration of the peer to connect to; will be available until
785 * GNUNET_TESTBED_operation_done() is called on the operation returned
786 * from GNUNET_TESTBED_service_connect()
787 * @return service handle to return in 'op_result', NULL on error
790 rps_connect_adapter (void *cls,
791 const struct GNUNET_CONFIGURATION_Handle *cfg)
793 struct GNUNET_RPS_Handle *h;
795 h = GNUNET_RPS_connect (cfg);
797 if (NULL != cur_test_run.pre_test)
798 cur_test_run.pre_test (cls, h);
804 * Called to open a connection to the peer's statistics
806 * @param cls peer context
807 * @param cfg configuration of the peer to connect to; will be available until
808 * GNUNET_TESTBED_operation_done() is called on the operation returned
809 * from GNUNET_TESTBED_service_connect()
810 * @return service handle to return in 'op_result', NULL on error
813 stat_connect_adapter (void *cls,
814 const struct GNUNET_CONFIGURATION_Handle *cfg)
816 struct RPSPeer *peer = cls;
818 peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg);
819 return peer->stats_h;
823 * Called to disconnect from peer's statistics service
825 * @param cls peer context
826 * @param op_result service handle returned from the connect adapter
829 stat_disconnect_adapter (void *cls, void *op_result)
831 struct RPSPeer *peer = cls;
833 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
834 // (peer->stats_h, "core", "# peers connected",
835 // stat_iterator, peer));
836 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
837 // (peer->stats_h, "nse", "# peers connected",
838 // stat_iterator, peer));
839 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
840 peer->stats_h = NULL;
844 * Called after successfully opening a connection to a peer's statistics
845 * service; we register statistics monitoring for CORE and NSE here.
847 * @param cls the callback closure from functions generating an operation
848 * @param op the operation that has been finished
849 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
850 * @param emsg error message in case the operation has failed; will be NULL if
851 * operation has executed successfully.
854 stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
855 void *ca_result, const char *emsg )
857 //struct GNUNET_STATISTICS_Handle *sh = ca_result;
858 //struct RPSPeer *peer = (struct RPSPeer *) cls;
865 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
866 // (sh, "core", "# peers connected",
867 // stat_iterator, peer));
868 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
869 // (sh, "nse", "# peers connected",
870 // stat_iterator, peer));
875 * Adapter function called to destroy connection to
879 * @param op_result service handle returned from the connect adapter
882 rps_disconnect_adapter (void *cls,
885 struct RPSPeer *peer = cls;
886 struct GNUNET_RPS_Handle *h = op_result;
887 GNUNET_assert (NULL != peer);
888 GNUNET_RPS_disconnect (h);
889 peer->rps_handle = NULL;
893 /***********************************************************************
894 * Definition of tests
895 ***********************************************************************/
897 // TODO check whether tests can be stopped earlier
899 default_eval_cb (void)
911 * Initialise given RPSPeer
913 static void default_init_peer (struct RPSPeer *rps_peer)
915 rps_peer->num_ids_to_request = 1;
919 * Callback to call on receipt of a reply
922 * @param n number of peers
923 * @param recv_peers the received peers
926 default_reply_handle (void *cls,
928 const struct GNUNET_PeerIdentity *recv_peers)
930 struct RPSPeer *rps_peer;
931 struct PendingReply *pending_rep = (struct PendingReply *) cls;
934 rps_peer = pending_rep->rps_peer;
935 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
936 rps_peer->pending_rep_tail,
938 rps_peer->num_pending_reps--;
939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
940 "[%s] got %" PRIu64 " peers:\n",
941 GNUNET_i2s (rps_peer->peer_id),
944 for (i = 0; i < n; i++)
946 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
949 GNUNET_i2s (&recv_peers[i]));
951 rps_peer->num_recv_ids++;
954 if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit)
956 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n");
957 GNUNET_assert (NULL != shutdown_task);
958 GNUNET_SCHEDULER_cancel (shutdown_task);
959 shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL);
960 GNUNET_assert (NULL!= shutdown_task);
965 * Request random peers.
968 request_peers (void *cls)
970 struct PendingRequest *pending_req = cls;
971 struct RPSPeer *rps_peer;
972 struct PendingReply *pending_rep;
974 if (GNUNET_YES == in_shutdown)
976 rps_peer = pending_req->rps_peer;
977 GNUNET_assert (1 <= rps_peer->num_pending_reqs);
978 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
979 rps_peer->pending_req_tail,
981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
982 "Requesting one peer\n");
983 pending_rep = GNUNET_new (struct PendingReply);
984 pending_rep->rps_peer = rps_peer;
985 pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle,
987 cur_test_run.reply_handle,
989 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head,
990 rps_peer->pending_rep_tail,
992 rps_peer->num_pending_reps++;
993 rps_peer->num_pending_reqs--;
997 cancel_pending_req (struct PendingRequest *pending_req)
999 struct RPSPeer *rps_peer;
1001 rps_peer = pending_req->rps_peer;
1002 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1003 rps_peer->pending_req_tail,
1005 rps_peer->num_pending_reqs--;
1006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1007 "Cancelling pending request\n");
1008 GNUNET_SCHEDULER_cancel (pending_req->request_task);
1009 GNUNET_free (pending_req);
1013 cancel_request (struct PendingReply *pending_rep)
1015 struct RPSPeer *rps_peer;
1017 rps_peer = pending_rep->rps_peer;
1018 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1019 rps_peer->pending_rep_tail,
1021 rps_peer->num_pending_reps--;
1022 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1023 "Cancelling request\n");
1024 GNUNET_RPS_request_cancel (pending_rep->req_handle);
1025 GNUNET_free (pending_rep);
1032 cancel_request_cb (void *cls)
1034 struct RPSPeer *rps_peer = cls;
1035 struct PendingReply *pending_rep;
1037 if (GNUNET_YES == in_shutdown)
1039 pending_rep = rps_peer->pending_rep_head;
1040 GNUNET_assert (1 <= rps_peer->num_pending_reps);
1041 cancel_request (pending_rep);
1046 * Schedule requests for peer @a rps_peer that have neither been scheduled, nor
1047 * issued, nor replied
1050 schedule_missing_requests (struct RPSPeer *rps_peer)
1053 struct PendingRequest *pending_req;
1055 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1056 "Scheduling %u - %u missing requests\n",
1057 rps_peer->num_ids_to_request,
1058 rps_peer->num_pending_reqs + rps_peer->num_pending_reps);
1059 GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <=
1060 rps_peer->num_ids_to_request);
1061 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps;
1062 i < rps_peer->num_ids_to_request; i++)
1064 pending_req = GNUNET_new (struct PendingRequest);
1065 pending_req->rps_peer = rps_peer;
1066 pending_req->request_task = GNUNET_SCHEDULER_add_delayed (
1067 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1068 cur_test_run.request_interval * i),
1071 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head,
1072 rps_peer->pending_req_tail,
1074 rps_peer->num_pending_reqs++;
1079 cancel_pending_req_rep (struct RPSPeer *rps_peer)
1081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1082 "Cancelling all (pending) requests.\n");
1083 while (NULL != rps_peer->pending_req_head)
1084 cancel_pending_req (rps_peer->pending_req_head);
1085 GNUNET_assert (0 == rps_peer->num_pending_reqs);
1086 while (NULL != rps_peer->pending_rep_head)
1087 cancel_request (rps_peer->pending_rep_head);
1088 GNUNET_assert (0 == rps_peer->num_pending_reps);
1091 /***********************************
1093 ***********************************/
1096 * Initialise only non-mal RPSPeers
1098 static void mal_init_peer (struct RPSPeer *rps_peer)
1100 if (rps_peer->index >= round (portion * num_peers))
1101 rps_peer->num_ids_to_request = 1;
1106 * @brief Set peers to (non-)malicious before execution
1108 * Of signature #PreTest
1110 * @param rps_peer the peer to set (non-) malicious
1111 * @param h the handle to the service
1114 mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1116 #ifdef ENABLE_MALICIOUS
1117 uint32_t num_mal_peers;
1119 GNUNET_assert ( (1 >= portion) &&
1121 num_mal_peers = round (portion * num_peers);
1123 if (rps_peer->index < num_mal_peers)
1125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1126 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
1128 GNUNET_i2s (rps_peer->peer_id),
1131 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers,
1132 rps_peer_ids, target_peer);
1134 #endif /* ENABLE_MALICIOUS */
1138 mal_cb (struct RPSPeer *rps_peer)
1140 uint32_t num_mal_peers;
1142 if (GNUNET_YES == in_shutdown)
1147 #ifdef ENABLE_MALICIOUS
1148 GNUNET_assert ( (1 >= portion) &&
1150 num_mal_peers = round (portion * num_peers);
1152 if (rps_peer->index >= num_mal_peers)
1153 { /* It's useless to ask a malicious peer about a random sample -
1154 it's not sampling */
1155 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1156 seed_peers, rps_peer);
1157 schedule_missing_requests (rps_peer);
1159 #endif /* ENABLE_MALICIOUS */
1163 /***********************************
1165 ***********************************/
1167 single_req_cb (struct RPSPeer *rps_peer)
1169 if (GNUNET_YES == in_shutdown)
1174 schedule_missing_requests (rps_peer);
1177 /***********************************
1179 ***********************************/
1181 delay_req_cb (struct RPSPeer *rps_peer)
1183 if (GNUNET_YES == in_shutdown)
1188 schedule_missing_requests (rps_peer);
1191 /***********************************
1193 ***********************************/
1195 seed_cb (struct RPSPeer *rps_peer)
1197 if (GNUNET_YES == in_shutdown)
1202 GNUNET_SCHEDULER_add_delayed (
1203 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
1204 seed_peers, rps_peer);
1207 /***********************************
1209 ***********************************/
1211 seed_big_cb (struct RPSPeer *rps_peer)
1213 if (GNUNET_YES == in_shutdown)
1218 // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers
1219 GNUNET_SCHEDULER_add_delayed (
1220 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1221 seed_peers_big, rps_peer);
1224 /***********************************
1226 ***********************************/
1228 single_peer_seed_cb (struct RPSPeer *rps_peer)
1233 /***********************************
1235 ***********************************/
1237 seed_req_cb (struct RPSPeer *rps_peer)
1239 if (GNUNET_YES == in_shutdown)
1244 GNUNET_SCHEDULER_add_delayed (
1245 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1246 seed_peers, rps_peer);
1247 schedule_missing_requests (rps_peer);
1250 //TODO start big mal
1252 /***********************************
1254 ***********************************/
1256 req_cancel_cb (struct RPSPeer *rps_peer)
1258 if (GNUNET_YES == in_shutdown)
1263 schedule_missing_requests (rps_peer);
1264 GNUNET_SCHEDULER_add_delayed (
1265 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1266 (cur_test_run.request_interval + 1)),
1267 cancel_request_cb, rps_peer);
1270 /***********************************
1272 ***********************************/
1278 * @brief Starts churn
1280 * Has signature of #MainTest
1282 * This is not implemented too nicely as this is called for each peer, but we
1283 * only need to call it once. (Yes we check that we only schedule the task
1286 * @param rps_peer The peer it's called for
1289 churn_test_cb (struct RPSPeer *rps_peer)
1291 if (GNUNET_YES == in_shutdown)
1297 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task)
1299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1300 "Starting churn task\n");
1301 churn_task = GNUNET_SCHEDULER_add_delayed (
1302 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1307 "Not starting churn task\n");
1310 schedule_missing_requests (rps_peer);
1313 /***********************************
1315 ***********************************/
1318 * Callback to be called when RPS service is started or stopped at peers
1321 * @param op the operation handle
1322 * @param emsg NULL on success; otherwise an error description
1325 churn_cb (void *cls,
1326 struct GNUNET_TESTBED_Operation *op,
1330 struct OpListEntry *entry = cls;
1332 if (GNUNET_YES == in_shutdown)
1337 GNUNET_TESTBED_operation_done (entry->op);
1340 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n");
1341 GNUNET_SCHEDULER_shutdown ();
1344 GNUNET_assert (0 != entry->delta);
1346 num_peers_online += entry->delta;
1348 if (PEER_GO_OFFLINE == entry->delta)
1349 { /* Peer hopefully just went offline */
1350 if (GNUNET_YES != rps_peers[entry->index].online)
1352 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1353 "peer %s was expected to go offline but is still marked as online\n",
1354 GNUNET_i2s (rps_peers[entry->index].peer_id));
1359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1360 "peer %s probably went offline as expected\n",
1361 GNUNET_i2s (rps_peers[entry->index].peer_id));
1363 rps_peers[entry->index].online = GNUNET_NO;
1366 else if (PEER_GO_ONLINE < entry->delta)
1367 { /* Peer hopefully just went online */
1368 if (GNUNET_NO != rps_peers[entry->index].online)
1370 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1371 "peer %s was expected to go online but is still marked as offline\n",
1372 GNUNET_i2s (rps_peers[entry->index].peer_id));
1377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1378 "peer %s probably went online as expected\n",
1379 GNUNET_i2s (rps_peers[entry->index].peer_id));
1380 if (NULL != cur_test_run.pre_test)
1382 cur_test_run.pre_test (&rps_peers[entry->index],
1383 rps_peers[entry->index].rps_handle);
1384 schedule_missing_requests (&rps_peers[entry->index]);
1387 rps_peers[entry->index].online = GNUNET_YES;
1391 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1392 "Invalid value for delta: %i\n", entry->delta);
1396 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1397 rps_peers[entry->index].entry_op_manage = NULL;
1398 GNUNET_free (entry);
1399 //if (num_peers_in_round[current_round] == peers_running)
1404 * @brief Set the rps-service up or down for a specific peer
1406 * @param i index of action
1407 * @param j index of peer
1408 * @param delta (#PEER_ONLINE_DELTA) down (-1) or up (1)
1409 * @param prob_go_on_off the probability of the action
1412 manage_service_wrapper (unsigned int i, unsigned int j,
1413 enum PEER_ONLINE_DELTA delta,
1414 double prob_go_on_off)
1416 struct OpListEntry *entry = NULL;
1419 /* make sure that management operation is not already scheduled */
1420 if (NULL != rps_peers[j].entry_op_manage)
1425 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1428 "%u. selected peer (%u: %s) is %s.\n",
1431 GNUNET_i2s (rps_peers[j].peer_id),
1432 (PEER_GO_ONLINE == delta) ? "online" : "offline");
1433 if (prob < prob_go_on_off * UINT32_MAX)
1435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1437 GNUNET_i2s (rps_peers[j].peer_id),
1438 (PEER_GO_OFFLINE == delta) ? "offline" : "online");
1440 if (PEER_GO_OFFLINE == delta)
1441 cancel_pending_req_rep (&rps_peers[j]);
1442 entry = make_oplist_entry ();
1443 entry->delta = delta;
1445 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
1450 (PEER_GO_OFFLINE == delta) ? 0 : 1);
1452 rps_peers[j].entry_op_manage = entry;
1461 double portion_online;
1462 unsigned int *permut;
1463 double prob_go_offline;
1464 double portion_go_online;
1465 double portion_go_offline;
1467 if (GNUNET_YES == in_shutdown)
1471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1472 "Churn function executing\n");
1474 churn_task = NULL; /* Should be invalid by now */
1476 /* Compute the probability for an online peer to go offline
1478 portion_online = num_peers_online * 1.0 / num_peers;
1479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1480 "Portion online: %f\n",
1482 portion_go_online = ((1 - portion_online) * .5 * .66);
1483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1484 "Portion that should go online: %f\n",
1486 portion_go_offline = (portion_online + portion_go_online) - .75;
1487 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1488 "Portion that probably goes offline: %f\n",
1489 portion_go_offline);
1490 prob_go_offline = portion_go_offline / (portion_online * .5);
1491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1492 "Probability of a selected online peer to go offline: %f\n",
1495 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
1496 (unsigned int) num_peers);
1498 /* Go over 50% randomly chosen peers */
1499 for (i = 0; i < .5 * num_peers; i++)
1503 /* If online, shut down with certain probability */
1504 if (GNUNET_YES == rps_peers[j].online)
1506 manage_service_wrapper (i, j, -1, prob_go_offline);
1509 /* If offline, restart with certain probability */
1510 else if (GNUNET_NO == rps_peers[j].online)
1512 manage_service_wrapper (i, j, 1, 0.66);
1516 GNUNET_free (permut);
1518 churn_task = GNUNET_SCHEDULER_add_delayed (
1519 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1526 * Initialise given RPSPeer
1528 static void profiler_init_peer (struct RPSPeer *rps_peer)
1530 if (num_peers - 1 == rps_peer->index)
1531 rps_peer->num_ids_to_request = cur_test_run.num_requests;
1536 * Callback to call on receipt of a reply
1538 * @param cls closure
1539 * @param n number of peers
1540 * @param recv_peers the received peers
1543 profiler_reply_handle (void *cls,
1545 const struct GNUNET_PeerIdentity *recv_peers)
1547 struct RPSPeer *rps_peer;
1548 struct RPSPeer *rcv_rps_peer;
1552 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1554 rps_peer = pending_rep->rps_peer;
1555 file_name = "/tmp/rps/received_ids";
1556 file_name_dh = "/tmp/rps/diehard_input";
1557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1558 "[%s] got %" PRIu64 " peers:\n",
1559 GNUNET_i2s (rps_peer->peer_id),
1561 for (i = 0; i < n; i++)
1563 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1566 GNUNET_i2s (&recv_peers[i]));
1569 GNUNET_i2s_full (&recv_peers[i]));
1570 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]);
1571 GNUNET_assert (NULL != rcv_rps_peer);
1572 tofile (file_name_dh,
1574 (uint32_t) rcv_rps_peer->index);
1576 default_reply_handle (cls, n, recv_peers);
1581 profiler_cb (struct RPSPeer *rps_peer)
1583 if (GNUNET_YES == in_shutdown)
1589 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task)
1591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1592 "Starting churn task\n");
1593 churn_task = GNUNET_SCHEDULER_add_delayed (
1594 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1599 "Not starting churn task\n");
1602 /* Only request peer ids at one peer.
1603 * (It's the before-last because last one is target of the focussed attack.)
1605 if (eval_peer == rps_peer)
1606 schedule_missing_requests (rps_peer);
1610 * Function called from #profiler_eval with a filename.
1612 * @param cls closure
1613 * @param filename complete filename (absolute path)
1614 * @return #GNUNET_OK to continue to iterate,
1615 * #GNUNET_NO to stop iteration with no error,
1616 * #GNUNET_SYSERR to abort iteration with error!
1619 file_name_cb (void *cls, const char *filename)
1621 if (NULL != strstr (filename, "sampler_el"))
1623 struct RPS_SamplerElement *s_elem;
1624 struct GNUNET_CRYPTO_AuthKey auth_key;
1625 const char *key_char;
1628 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
1629 tofile (filename, "--------------------------\n");
1631 auth_key = string_to_auth_key (key_char);
1632 s_elem = RPS_sampler_elem_create ();
1633 RPS_sampler_elem_set (s_elem, auth_key);
1635 for (i = 0; i < num_peers; i++)
1637 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
1639 RPS_sampler_elem_destroy (s_elem);
1645 * This is run after the test finished.
1647 * Compute all perfect samples.
1650 profiler_eval (void)
1652 /* Compute perfect sample for each sampler element */
1653 if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL))
1655 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
1662 * Continuation called by #GNUNET_STATISTICS_get() functions.
1664 * Checks whether all peers received their statistics yet.
1665 * Issues the shutdown.
1667 * @param cls closure
1668 * @param success #GNUNET_OK if statistics were
1669 * successfully obtained, #GNUNET_SYSERR if not.
1672 post_test_shutdown_ready_cb (void *cls,
1675 const struct RPSPeer *rps_peer = (const struct RPSPeer *) cls;
1676 if (NULL != rps_peer->stat_op)
1678 GNUNET_TESTBED_operation_done (rps_peer->stat_op);
1680 num_shutdown_ready++;
1681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1682 "%" PRIu32 " of %" PRIu32 " Peers are ready to shut down\n",
1685 if (num_peers <= num_shutdown_ready)
1687 GNUNET_SCHEDULER_shutdown ();
1692 * Callback function to process statistic values.
1694 * @param cls closure
1695 * @param subsystem name of subsystem that created the statistic
1696 * @param name the name of the datum
1697 * @param value the current value
1698 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
1699 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
1702 stat_iterator (void *cls,
1703 const char *subsystem,
1708 //const struct RPSPeer *rps_peer = (const struct RPSPeer *) cls;
1709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %" PRIu64 "\n", value);
1713 void post_profiler (const struct RPSPeer *rps_peer)
1715 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
1717 GNUNET_STATISTICS_get (rps_peer->stats_h,
1720 post_test_shutdown_ready_cb,
1722 (struct RPSPeer *) rps_peer);
1727 /***********************************************************************
1728 * /Definition of tests
1729 ***********************************************************************/
1733 * Actual "main" function for the testcase.
1735 * @param cls closure
1736 * @param h the run handle
1737 * @param n_peers number of peers in 'peers'
1738 * @param peers handle to peers run in the testbed
1739 * @param links_succeeded the number of overlay link connection attempts that
1741 * @param links_failed the number of overlay link connection attempts that
1746 struct GNUNET_TESTBED_RunHandle *h,
1747 unsigned int n_peers,
1748 struct GNUNET_TESTBED_Peer **peers,
1749 unsigned int links_succeeded,
1750 unsigned int links_failed)
1753 struct OpListEntry *entry;
1754 uint32_t num_mal_peers;
1756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n");
1758 /* Check whether we timed out */
1759 if (n_peers != num_peers ||
1761 0 == links_succeeded)
1763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n");
1764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers);
1765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers);
1766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers);
1767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded);
1768 GNUNET_SCHEDULER_shutdown ();
1773 /* Initialize peers */
1774 testbed_peers = peers;
1775 num_peers_online = 0;
1776 for (i = 0; i < num_peers; i++)
1778 entry = make_oplist_entry ();
1780 rps_peers[i].index = i;
1781 if (NULL != cur_test_run.init_peer)
1782 cur_test_run.init_peer (&rps_peers[i]);
1783 entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
1784 GNUNET_TESTBED_PIT_IDENTITY,
1789 /* Bring peers up */
1790 num_mal_peers = round (portion * num_peers);
1791 GNUNET_assert (num_peers == n_peers);
1792 for (i = 0; i < n_peers; i++)
1794 rps_peers[i].index = i;
1795 if ( (rps_peers[i].num_recv_ids < rps_peers[i].num_ids_to_request) ||
1796 (i < num_mal_peers) )
1799 GNUNET_TESTBED_service_connect (&rps_peers[i],
1802 &rps_connect_complete_cb,
1804 &rps_connect_adapter,
1805 &rps_disconnect_adapter,
1808 /* Connect all peers to statistics service */
1809 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
1811 rps_peers[i].stat_op =
1812 GNUNET_TESTBED_service_connect (NULL,
1817 &stat_connect_adapter,
1818 &stat_disconnect_adapter,
1823 if (NULL != churn_task)
1824 GNUNET_SCHEDULER_cancel (churn_task);
1825 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
1830 * Entry point for the testcase, sets up the testbed.
1832 * @param argc unused
1833 * @param argv unused
1834 * @return 0 on success
1837 main (int argc, char *argv[])
1842 num_shutdown_ready = 0;
1843 cur_test_run.name = "test-rps-default";
1844 cur_test_run.init_peer = default_init_peer;
1845 cur_test_run.pre_test = NULL;
1846 cur_test_run.reply_handle = default_reply_handle;
1847 cur_test_run.eval_cb = default_eval_cb;
1848 cur_test_run.post_test = NULL;
1849 cur_test_run.have_churn = HAVE_CHURN;
1850 cur_test_run.have_collect_statistics = NO_COLLECT_STATISTICS;
1852 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
1854 if (strstr (argv[0], "malicious") != NULL)
1856 cur_test_run.pre_test = mal_pre;
1857 cur_test_run.main_test = mal_cb;
1858 cur_test_run.init_peer = mal_init_peer;
1860 if (strstr (argv[0], "_1") != NULL)
1862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
1863 cur_test_run.name = "test-rps-malicious_1";
1866 else if (strstr (argv[0], "_2") != NULL)
1868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
1869 cur_test_run.name = "test-rps-malicious_2";
1872 else if (strstr (argv[0], "_3") != NULL)
1874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n");
1875 cur_test_run.name = "test-rps-malicious_3";
1880 else if (strstr (argv[0], "_single_req") != NULL)
1882 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
1883 cur_test_run.name = "test-rps-single-req";
1884 cur_test_run.main_test = single_req_cb;
1885 cur_test_run.have_churn = HAVE_NO_CHURN;
1888 else if (strstr (argv[0], "_delayed_reqs") != NULL)
1890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
1891 cur_test_run.name = "test-rps-delayed-reqs";
1892 cur_test_run.main_test = delay_req_cb;
1893 cur_test_run.have_churn = HAVE_NO_CHURN;
1896 else if (strstr (argv[0], "_seed_big") != NULL)
1898 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_MAX_MESSAGE_SIZE)\n");
1900 cur_test_run.name = "test-rps-seed-big";
1901 cur_test_run.main_test = seed_big_cb;
1902 cur_test_run.eval_cb = no_eval;
1903 cur_test_run.have_churn = HAVE_NO_CHURN;
1904 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1907 else if (strstr (argv[0], "_single_peer_seed") != NULL)
1909 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
1910 cur_test_run.name = "test-rps-single-peer-seed";
1911 cur_test_run.main_test = single_peer_seed_cb;
1912 cur_test_run.have_churn = HAVE_NO_CHURN;
1915 else if (strstr (argv[0], "_seed_request") != NULL)
1917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
1918 cur_test_run.name = "test-rps-seed-request";
1919 cur_test_run.main_test = seed_req_cb;
1920 cur_test_run.have_churn = HAVE_NO_CHURN;
1923 else if (strstr (argv[0], "_seed") != NULL)
1925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
1926 cur_test_run.name = "test-rps-seed";
1927 cur_test_run.main_test = seed_cb;
1928 cur_test_run.eval_cb = no_eval;
1929 cur_test_run.have_churn = HAVE_NO_CHURN;
1932 else if (strstr (argv[0], "_req_cancel") != NULL)
1934 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
1935 cur_test_run.name = "test-rps-req-cancel";
1937 cur_test_run.main_test = req_cancel_cb;
1938 cur_test_run.eval_cb = no_eval;
1939 cur_test_run.have_churn = HAVE_NO_CHURN;
1940 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1943 else if (strstr (argv[0], "_churn") != NULL)
1945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test churn\n");
1946 cur_test_run.name = "test-rps-churn";
1948 cur_test_run.init_peer = default_init_peer;
1949 cur_test_run.main_test = churn_test_cb;
1950 cur_test_run.reply_handle = default_reply_handle;
1951 cur_test_run.eval_cb = default_eval_cb;
1952 cur_test_run.have_churn = HAVE_CHURN;
1953 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
1954 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1957 else if (strstr (argv[0], "profiler") != NULL)
1959 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
1960 cur_test_run.name = "test-rps-profiler";
1963 cur_test_run.init_peer = profiler_init_peer;
1964 cur_test_run.pre_test = mal_pre;
1965 cur_test_run.main_test = profiler_cb;
1966 cur_test_run.reply_handle = profiler_reply_handle;
1967 cur_test_run.eval_cb = profiler_eval;
1968 cur_test_run.post_test = post_profiler;
1969 cur_test_run.request_interval = 2;
1970 cur_test_run.num_requests = 5;
1971 cur_test_run.have_churn = HAVE_CHURN;
1972 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
1973 cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
1974 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300);
1976 /* 'Clean' directory */
1977 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
1978 GNUNET_DISK_directory_create ("/tmp/rps/");
1981 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
1982 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
1983 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
1984 if ( (2 == mal_type) ||
1986 target_peer = &rps_peer_ids[num_peers - 2];
1987 if (profiler_eval == cur_test_run.eval_cb)
1988 eval_peer = &rps_peers[num_peers - 1]; /* FIXME: eval_peer could be a
1989 malicious peer if not careful
1990 with the malicious portion */
1993 ret_value = GNUNET_TESTBED_test_run (cur_test_run.name,
1998 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1999 "_test_run returned.\n");
2000 if (GNUNET_OK != ret_value)
2002 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2003 "Test did not run successfully!\n");
2006 ret_value = cur_test_run.eval_cb();
2007 GNUNET_free (rps_peers);
2008 GNUNET_free (rps_peer_ids);
2009 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
2013 /* end of test_rps.c */