2 This file is part of GNUnet.
3 Copyright (C) 2009, 2012 Christian Grothoff (and other contributing authors)
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_multipeer.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?
44 * How long do we run the test?
46 //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
47 static struct GNUNET_TIME_Relative timeout;
51 * Portion of malicious peers
53 static double portion = .1;
56 * Type of malicious peer to test
58 static unsigned int mal_type = 0;
61 * Handles to all of the running peers
63 static struct GNUNET_TESTBED_Peer **testbed_peers;
74 struct OpListEntry *next;
79 struct OpListEntry *prev;
82 * The testbed operation
84 struct GNUNET_TESTBED_Operation *op;
87 * Depending on whether we start or stop NSE service at the peer set this to 1
93 * Index of the regarding peer
101 static struct OpListEntry *oplist_head;
106 static struct OpListEntry *oplist_tail;
110 * Information we track for each peer.
120 * Handle for RPS connect operation.
122 struct GNUNET_TESTBED_Operation *op;
125 * Handle to RPS service.
127 struct GNUNET_RPS_Handle *rps_handle;
132 struct GNUNET_PeerIdentity *peer_id;
135 * A request handle to check for an request
137 //struct GNUNET_RPS_Request_Handle *req_handle;
140 * Peer on- or offline?
147 struct GNUNET_PeerIdentity *rec_ids;
150 * Number of received PeerIDs
152 unsigned int num_rec_ids;
157 * Information for all the peers.
159 static struct RPSPeer *rps_peers;
164 static struct GNUNET_PeerIdentity *rps_peer_ids;
167 * Number of online peers.
169 static unsigned int num_peers_online;
172 * Return value from 'main'.
178 * Identifier for the churn task that runs periodically
180 static struct GNUNET_SCHEDULER_Task *churn_task;
184 * Called directly after connecting to the service
186 typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h);
189 * Called from within #rps_connect_complete_cb ()
190 * Executes functions to test the api/service
192 typedef void (*MainTest) (struct RPSPeer *rps_peer);
195 * Callback called once the requested random peers are available
197 typedef void (*ReplyHandle) (void *cls,
199 const struct GNUNET_PeerIdentity *recv_peers);
202 * Called directly before disconnecting from the service
204 typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h);
207 * Function called after disconnect to evaluate test success
209 typedef int (*EvaluationCallback) (void);
213 * Structure to define a single test
223 * Called directly after connecting to the service
228 * Function to execute the functions to be tested
233 * Callback called once the requested peers are available
235 ReplyHandle reply_handle;
238 * Called directly before disconnecting from the service
243 * Function to evaluate the test results
245 EvaluationCallback eval_cb;
250 uint32_t request_interval;
253 * Number of Requests to make.
255 uint32_t num_requests;
260 * Append arguments to file
263 tofile_ (const char *file_name, char *line)
265 struct GNUNET_DISK_FileHandle *f;
266 /* char output_buffer[512]; */
271 if (NULL == (f = GNUNET_DISK_file_open (file_name,
272 GNUNET_DISK_OPEN_APPEND |
273 GNUNET_DISK_OPEN_WRITE |
274 GNUNET_DISK_OPEN_CREATE,
275 GNUNET_DISK_PERM_USER_READ |
276 GNUNET_DISK_PERM_USER_WRITE |
277 GNUNET_DISK_PERM_GROUP_READ |
278 GNUNET_DISK_PERM_OTHER_READ)))
280 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
281 "Not able to open file %s\n",
285 /* size = GNUNET_snprintf (output_buffer,
286 sizeof (output_buffer),
288 GNUNET_TIME_absolute_get ().abs_value_us,
292 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
293 "Failed to write string to buffer (size: %i)\n",
298 size = strlen (line) * sizeof (char);
300 size2 = GNUNET_DISK_file_write (f, line, size);
303 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
304 "Unable to write to file! (Size: %u, size2: %u)\n",
310 if (GNUNET_YES != GNUNET_DISK_file_close (f))
311 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
312 "Unable to close file\n");
316 * This function is used to facilitate writing important information to disk
318 #define tofile(file_name, ...) do {\
321 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
323 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
324 "Failed to create tmp_buf\n");\
326 tofile_(file_name,tmp_buf);\
330 * Write the ids and their according index in the given array to a file
334 ids_to_file (char *file_name,
335 struct GNUNET_PeerIdentity *peer_ids,
336 unsigned int num_peer_ids)
340 for (i=0 ; i < num_peer_ids ; i++)
345 GNUNET_i2s_full (&peer_ids[i]));
350 * Test the success of a single test
353 evaluate (struct RPSPeer *loc_rps_peers,
354 unsigned int num_loc_rps_peers,
355 unsigned int expected_recv)
360 tmp_ok = (1 == loc_rps_peers[0].num_rec_ids);
362 for (i = 0 ; i < num_loc_rps_peers ; i++)
364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
365 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
367 GNUNET_i2s (loc_rps_peers[i].peer_id),
368 loc_rps_peers[i].num_rec_ids,
370 (1 == loc_rps_peers[i].num_rec_ids));
371 tmp_ok &= (1 == loc_rps_peers[i].num_rec_ids);
373 return tmp_ok? 0 : 1;
378 * Creates an oplist entry and adds it to the oplist DLL
380 static struct OpListEntry *
383 struct OpListEntry *entry;
385 entry = GNUNET_new (struct OpListEntry);
386 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
392 * Callback to be called when RPS service is started or stopped at peers
395 * @param op the operation handle
396 * @param emsg NULL on success; otherwise an error description
400 struct GNUNET_TESTBED_Operation *op,
404 struct OpListEntry *entry = cls;
406 GNUNET_TESTBED_operation_done (entry->op);
409 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n");
410 GNUNET_SCHEDULER_shutdown ();
413 GNUNET_assert (0 != entry->delta);
415 num_peers_online += entry->delta;
417 if (0 > entry->delta)
418 { /* Peer hopefully just went offline */
419 if (GNUNET_YES != rps_peers[entry->index].online)
421 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
422 "peer %s was expected to go offline but is still marked as online\n",
423 GNUNET_i2s (rps_peers[entry->index].peer_id));
428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
429 "peer %s probably went offline as expected\n",
430 GNUNET_i2s (rps_peers[entry->index].peer_id));
432 rps_peers[entry->index].online = GNUNET_NO;
435 else if (0 < entry->delta)
436 { /* Peer hopefully just went online */
437 if (GNUNET_NO != rps_peers[entry->index].online)
439 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
440 "peer %s was expected to go online but is still marked as offline\n",
441 GNUNET_i2s (rps_peers[entry->index].peer_id));
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
447 "peer %s probably went online as expected\n",
448 GNUNET_i2s (rps_peers[entry->index].peer_id));
449 if (NULL != cur_test_run.pre_test)
451 cur_test_run.pre_test (&rps_peers[entry->index],
452 rps_peers[entry->index].rps_handle);
455 rps_peers[entry->index].online = GNUNET_YES;
458 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
460 //if (num_peers_in_round[current_round] == peers_running)
466 * Task run on timeout to shut everything down.
469 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
473 if (NULL != churn_task)
474 GNUNET_SCHEDULER_cancel (churn_task);
476 for (i = 0 ; i < num_peers ; i++)
477 GNUNET_TESTBED_operation_done (rps_peers[i].op);
478 GNUNET_SCHEDULER_shutdown ();
486 seed_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
489 struct RPSPeer *peer = (struct RPSPeer *) cls;
492 // TODO if malicious don't seed mal peers
493 amount = round (.5 * num_peers);
495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
496 for (i = 0 ; i < amount ; i++)
497 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
499 GNUNET_i2s (&rps_peer_ids[i]));
501 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
506 * Get the id of peer i.
509 info_cb (void *cb_cls,
510 struct GNUNET_TESTBED_Operation *op,
511 const struct GNUNET_TESTBED_PeerInformation *pinfo,
514 struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
516 if (NULL == pinfo || NULL != emsg)
518 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
525 GNUNET_i2s (pinfo->result.id));
527 rps_peer_ids[entry->index] = *(pinfo->result.id);
528 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
529 rps_peers[entry->index].rec_ids = NULL;
530 rps_peers[entry->index].num_rec_ids = 0;
532 tofile ("/tmp/rps/peer_ids",
535 GNUNET_i2s_full (&rps_peer_ids[entry->index]));
537 GNUNET_TESTBED_operation_done (entry->op);
539 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
545 * Callback to be called when RPS service connect operation is completed
547 * @param cls the callback closure from functions generating an operation
548 * @param op the operation that has been finished
549 * @param ca_result the RPS service handle returned from rps_connect_adapter
550 * @param emsg error message in case the operation has failed; will be NULL if
551 * operation has executed successfully.
554 rps_connect_complete_cb (void *cls,
555 struct GNUNET_TESTBED_Operation *op,
559 struct RPSPeer *rps_peer = cls;
560 struct GNUNET_RPS_Handle *rps = ca_result;
562 rps_peer->rps_handle = rps;
563 rps_peer->online = GNUNET_YES;
566 GNUNET_assert (op == rps_peer->op);
569 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
570 "Failed to connect to RPS service: %s\n",
573 GNUNET_SCHEDULER_shutdown ();
577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
579 cur_test_run.main_test (rps_peer);
584 * Adapter function called to establish a connection to
588 * @param cfg configuration of the peer to connect to; will be available until
589 * GNUNET_TESTBED_operation_done() is called on the operation returned
590 * from GNUNET_TESTBED_service_connect()
591 * @return service handle to return in 'op_result', NULL on error
594 rps_connect_adapter (void *cls,
595 const struct GNUNET_CONFIGURATION_Handle *cfg)
597 struct GNUNET_RPS_Handle *h;
599 h = GNUNET_RPS_connect (cfg);
601 if (NULL != cur_test_run.pre_test)
602 cur_test_run.pre_test (cls, h);
609 * Adapter function called to destroy connection to
613 * @param op_result service handle returned from the connect adapter
616 rps_disconnect_adapter (void *cls,
619 struct GNUNET_RPS_Handle *h = op_result;
620 GNUNET_RPS_disconnect (h);
624 /***********************************************************************
625 * Definition of tests
626 ***********************************************************************/
628 // TODO check whether tests can be stopped earlier
630 default_eval_cb (void)
632 return evaluate (rps_peers, num_peers, 1);
642 * Callback to call on receipt of a reply
645 * @param n number of peers
646 * @param recv_peers the received peers
649 default_reply_handle (void *cls,
651 const struct GNUNET_PeerIdentity *recv_peers)
653 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "[%s] got %" PRIu64 " peers:\n",
658 GNUNET_i2s (rps_peer->peer_id),
661 for (i = 0 ; i < n ; i++)
663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
666 GNUNET_i2s (&recv_peers[i]));
668 GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]);
673 * Request random peers.
676 request_peers (void *cls,
677 const struct GNUNET_SCHEDULER_TaskContext *tc)
679 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
682 "Requesting one peer\n");
684 GNUNET_free (GNUNET_RPS_request_peers (rps_peer->rps_handle,
686 cur_test_run.reply_handle,
688 //rps_peer->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, 1, handle_reply, rps_peer);
692 /***********************************
694 ***********************************/
696 mal_pre (void *cls, struct GNUNET_RPS_Handle *h)
698 #ifdef ENABLE_MALICIOUS
699 uint32_t num_mal_peers;
700 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
702 GNUNET_assert (1 >= portion
704 num_mal_peers = round (portion * num_peers);
706 if (rps_peer->index < num_mal_peers)
708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
709 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
711 GNUNET_i2s (rps_peer->peer_id),
714 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, rps_peer_ids);
716 #endif /* ENABLE_MALICIOUS */
720 mal_cb (struct RPSPeer *rps_peer)
722 uint32_t num_mal_peers;
724 #ifdef ENABLE_MALICIOUS
725 GNUNET_assert (1 >= portion
727 num_mal_peers = round (portion * num_peers);
729 if (rps_peer->index >= num_mal_peers)
730 { /* It's useless to ask a malicious peer about a random sample -
732 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
733 seed_peers, rps_peer);
734 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
735 request_peers, rps_peer);
737 #endif /* ENABLE_MALICIOUS */
743 unsigned int num_mal_peers;
745 num_mal_peers = round (num_peers * portion);
746 return evaluate (&rps_peers[num_mal_peers],
747 num_peers - (num_mal_peers),
752 /***********************************
754 ***********************************/
756 single_req_cb (struct RPSPeer *rps_peer)
758 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
759 request_peers, rps_peer);
762 /***********************************
764 ***********************************/
766 delay_req_cb (struct RPSPeer *rps_peer)
768 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
769 request_peers, rps_peer);
770 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
771 request_peers, rps_peer);
774 /***********************************
776 ***********************************/
778 seed_cb (struct RPSPeer *rps_peer)
780 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
781 seed_peers, rps_peer);
784 /***********************************
786 ***********************************/
788 seed_big_cb (struct RPSPeer *rps_peer)
790 // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers
793 /***********************************
795 ***********************************/
797 single_peer_seed_cb (struct RPSPeer *rps_peer)
802 /***********************************
804 ***********************************/
806 seed_req_cb (struct RPSPeer *rps_peer)
808 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
809 seed_peers, rps_peer);
810 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15),
811 request_peers, rps_peer);
816 /***********************************
818 ***********************************/
820 req_cancel_cb (struct RPSPeer *rps_peer)
825 /***********************************
827 ***********************************/
829 churn (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
831 struct OpListEntry *entry;
834 double portion_online;
835 unsigned int *permut;
836 double prob_go_offline;
837 double portion_go_online;
838 double portion_go_offline;
841 /* Compute the probability for an online peer to go offline
843 portion_online = num_peers_online * 1.0 / num_peers;
844 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
845 "Portion online: %f\n",
847 portion_go_online = ((1 - portion_online) * .5 * .66);
848 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
849 "Portion that should go online: %f\n",
851 portion_go_offline = (portion_online + portion_go_online) - .75;
852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
853 "Portion that probably goes offline: %f\n",
855 prob_go_offline = portion_go_offline / (portion_online * .5);
856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
857 "Probability of a selected online peer to go offline: %f\n",
860 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
861 (unsigned int) num_peers);
863 /* Go over 50% randomly chosen peers */
864 for (i = 0 ; i < .5 * num_peers ; i++)
868 /* If online, shut down with certain probability */
869 if (GNUNET_YES == rps_peers[j].online)
871 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
874 "%u. selected peer (%u: %s) is online.\n",
877 GNUNET_i2s (rps_peers[j].peer_id));
878 if (prob < prob_go_offline * UINT32_MAX)
880 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
882 GNUNET_i2s (rps_peers[j].peer_id));
884 entry = make_oplist_entry ();
887 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
896 /* If offline, restart with certain probability */
897 else if (GNUNET_NO == rps_peers[j].online)
899 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
902 "%u. selected peer (%u: %s) is offline.\n",
905 GNUNET_i2s (rps_peers[j].peer_id));
906 if (prob < .66 * UINT32_MAX)
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
910 GNUNET_i2s (rps_peers[j].peer_id));
912 entry = make_oplist_entry ();
915 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
925 GNUNET_free (permut);
927 churn_task = GNUNET_SCHEDULER_add_delayed (
928 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
935 profiler_pre (void *cls, struct GNUNET_RPS_Handle *h)
937 //churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
942 /* if (NULL == churn_task)
944 churn_task = GNUNET_SCHEDULER_add_delayed (
945 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
953 * Callback to call on receipt of a reply
956 * @param n number of peers
957 * @param recv_peers the received peers
960 profiler_reply_handle (void *cls,
962 const struct GNUNET_PeerIdentity *recv_peers)
964 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
968 file_name = "/tmp/rps/received_ids";
970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
971 "[%s] got %" PRIu64 " peers:\n",
972 GNUNET_i2s (rps_peer->peer_id),
975 for (i = 0 ; i < n ; i++)
977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
980 GNUNET_i2s (&recv_peers[i]));
982 /* GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); */
985 GNUNET_i2s_full (&recv_peers[i]));
991 profiler_cb (struct RPSPeer *rps_peer)
995 /* Churn only at peers that do not request peers for evaluation */
996 if (NULL == churn_task &&
997 rps_peer->index != num_peers - 2)
999 churn_task = GNUNET_SCHEDULER_add_delayed (
1000 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
1005 /* Only request peer ids at one peer.
1006 * (It's the before-last because last one is target of the focussed attack.)
1008 if (rps_peer->index == num_peers - 2)
1010 for (i = 0 ; i < cur_test_run.num_requests ; i++)
1012 GNUNET_SCHEDULER_add_delayed (
1013 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1014 cur_test_run.request_interval * i),
1022 * Function called from #profiler_eval with a filename.
1024 * @param cls closure
1025 * @param filename complete filename (absolute path)
1026 * @return #GNUNET_OK to continue to iterate,
1027 * #GNUNET_NO to stop iteration with no error,
1028 * #GNUNET_SYSERR to abort iteration with error!
1031 file_name_cb (void *cls, const char *filename)
1033 if (NULL != strstr (filename, "sampler_el"))
1035 struct RPS_SamplerElement *s_elem;
1036 struct GNUNET_CRYPTO_AuthKey auth_key;
1037 const char *key_char;
1040 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
1041 tofile (filename, "--------------------------\n");
1043 auth_key = string_to_auth_key (key_char);
1044 s_elem = RPS_sampler_elem_create ();
1045 RPS_sampler_elem_set (s_elem, auth_key);
1047 for (i = 0; i < num_peers; i++)
1049 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
1056 * This is run after the test finished.
1058 * Compute all perfect samples.
1061 profiler_eval (void)
1063 /* Compute perfect sample for each sampler element */
1064 if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL))
1066 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
1073 /***********************************************************************
1074 * /Definition of tests
1075 ***********************************************************************/
1079 * Actual "main" function for the testcase.
1081 * @param cls closure
1082 * @param h the run handle
1083 * @param n_peers number of peers in 'peers'
1084 * @param peers handle to peers run in the testbed
1085 * @param links_succeeded the number of overlay link connection attempts that
1087 * @param links_failed the number of overlay link connection attempts that
1092 struct GNUNET_TESTBED_RunHandle *h,
1093 unsigned int n_peers,
1094 struct GNUNET_TESTBED_Peer **peers,
1095 unsigned int links_succeeded,
1096 unsigned int links_failed)
1099 struct OpListEntry *entry;
1101 testbed_peers = peers;
1102 num_peers_online = 0;
1104 for (i = 0 ; i < num_peers ; i++)
1106 entry = make_oplist_entry ();
1108 entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
1109 GNUNET_TESTBED_PIT_IDENTITY,
1115 // This seems not to work
1116 //if (NULL != strstr (cur_test_run.name, "profiler"))
1118 // churn_task = GNUNET_SCHEDULER_add_delayed (
1119 // GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1124 GNUNET_assert (num_peers == n_peers);
1125 for (i = 0 ; i < n_peers ; i++)
1127 rps_peers[i].index = i;
1129 GNUNET_TESTBED_service_connect (&rps_peers[i],
1132 &rps_connect_complete_cb,
1134 &rps_connect_adapter,
1135 &rps_disconnect_adapter,
1139 if (NULL != churn_task)
1140 GNUNET_SCHEDULER_cancel (churn_task);
1142 GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL);
1147 * Entry point for the testcase, sets up the testbed.
1149 * @param argc unused
1150 * @param argv unused
1151 * @return 0 on success
1154 main (int argc, char *argv[])
1156 cur_test_run.name = "test-rps-default";
1157 cur_test_run.pre_test = NULL;
1158 cur_test_run.reply_handle = default_reply_handle;
1159 cur_test_run.eval_cb = default_eval_cb;
1163 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
1165 if (strstr (argv[0], "malicious") != NULL)
1167 cur_test_run.pre_test = mal_pre;
1168 cur_test_run.main_test = mal_cb;
1169 cur_test_run.eval_cb = mal_eval;
1171 if (strstr (argv[0], "_1") != NULL)
1173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
1174 cur_test_run.name = "test-rps-malicious_1";
1177 else if (strstr (argv[0], "_2") != NULL)
1179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
1180 cur_test_run.name = "test-rps-malicious_2";
1183 else if (strstr (argv[0], "_3") != NULL)
1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n");
1186 cur_test_run.name = "test-rps-malicious_3";
1191 else if (strstr (argv[0], "_single_req") != NULL)
1193 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
1194 cur_test_run.name = "test-rps-single-req";
1195 cur_test_run.main_test = single_req_cb;
1198 else if (strstr (argv[0], "_delayed_reqs") != NULL)
1200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
1201 cur_test_run.name = "test-rps-delayed-reqs";
1202 cur_test_run.main_test = delay_req_cb;
1205 else if (strstr (argv[0], "_seed_big") != NULL)
1207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_SERVER_MAX_MESSAGE_SIZE)\n");
1208 cur_test_run.name = "test-rps-seed-big";
1209 cur_test_run.main_test = seed_big_cb;
1212 else if (strstr (argv[0], "_single_peer_seed") != NULL)
1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
1215 cur_test_run.name = "test-rps-single-peer-seed";
1216 cur_test_run.main_test = single_peer_seed_cb;
1219 else if (strstr (argv[0], "_seed_request") != NULL)
1221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
1222 cur_test_run.name = "test-rps-seed-request";
1223 cur_test_run.main_test = seed_req_cb;
1226 else if (strstr (argv[0], "_seed") != NULL)
1228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
1229 cur_test_run.name = "test-rps-seed";
1230 cur_test_run.main_test = seed_cb;
1231 cur_test_run.eval_cb = no_eval;
1234 else if (strstr (argv[0], "_req_cancel") != NULL)
1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
1237 cur_test_run.name = "test-rps-req-cancel";
1238 cur_test_run.main_test = req_cancel_cb;
1241 else if (strstr (argv[0], "profiler") != NULL)
1243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
1244 cur_test_run.name = "test-rps-profiler";
1246 cur_test_run.pre_test = profiler_pre;
1247 cur_test_run.main_test = profiler_cb;
1248 cur_test_run.reply_handle = profiler_reply_handle;
1249 cur_test_run.eval_cb = profiler_eval;
1250 cur_test_run.request_interval = 2;
1251 cur_test_run.num_requests = 50;
1255 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
1256 GNUNET_DISK_directory_create ("/tmp/rps/");
1257 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90);
1260 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
1261 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
1264 (void) GNUNET_TESTBED_test_run (cur_test_run.name,
1270 return cur_test_run.eval_cb();
1273 /* end of test_rps_multipeer.c */