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"
30 #include "gnunet_rps_service.h"
36 * How many peers do we start?
41 * How long do we run the test?
43 //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
44 static struct GNUNET_TIME_Relative timeout;
48 * Portion of malicious peers
50 static double portion = .1;
53 * Type of malicious peer to test
55 static unsigned int mal_type = 0;
58 * Handles to all of the running peers
60 static struct GNUNET_TESTBED_Peer **testbed_peers;
71 struct OpListEntry *next;
76 struct OpListEntry *prev;
79 * The testbed operation
81 struct GNUNET_TESTBED_Operation *op;
84 * Depending on whether we start or stop NSE service at the peer set this to 1
90 * Index of the regarding peer
98 static struct OpListEntry *oplist_head;
103 static struct OpListEntry *oplist_tail;
107 * Information we track for each peer.
117 * Handle for RPS connect operation.
119 struct GNUNET_TESTBED_Operation *op;
122 * Handle to RPS service.
124 struct GNUNET_RPS_Handle *rps_handle;
129 struct GNUNET_PeerIdentity *peer_id;
132 * A request handle to check for an request
134 //struct GNUNET_RPS_Request_Handle *req_handle;
137 * Peer on- or offline?
144 struct GNUNET_PeerIdentity *rec_ids;
147 * Number of received PeerIDs
149 unsigned int num_rec_ids;
154 * Information for all the peers.
156 static struct RPSPeer *rps_peers;
161 static struct GNUNET_PeerIdentity *rps_peer_ids;
164 * Number of online peers.
166 static unsigned int num_peers_online;
169 * Return value from 'main'.
175 * Identifier for the churn task that runs periodically
177 static struct GNUNET_SCHEDULER_Task *churn_task;
181 * Called directly after connecting to the service
183 typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h);
186 * Called from within #rps_connect_complete_cb ()
187 * Executes functions to test the api/service
189 typedef void (*MainTest) (struct RPSPeer *rps_peer);
192 * Callback called once the requested random peers are available
194 typedef void (*ReplyHandle) (void *cls,
196 const struct GNUNET_PeerIdentity *recv_peers);
199 * Called directly before disconnecting from the service
201 typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h);
204 * Function called after disconnect to evaluate test success
206 typedef int (*EvaluationCallback) (void);
210 * Structure to define a single test
220 * Called directly after connecting to the service
225 * Function to execute the functions to be tested
230 * Callback called once the requested peers are available
232 ReplyHandle reply_handle;
235 * Called directly before disconnecting from the service
240 * Function to evaluate the test results
242 EvaluationCallback eval_cb;
247 uint32_t request_interval;
250 * Number of Requests to make.
252 uint32_t num_requests;
257 * Append arguments to file
260 to_file_ (char *file_name, char *line)
262 struct GNUNET_DISK_FileHandle *f;
263 /* char output_buffer[512]; */
268 if (NULL == (f = GNUNET_DISK_file_open (file_name,
269 GNUNET_DISK_OPEN_APPEND |
270 GNUNET_DISK_OPEN_WRITE |
271 GNUNET_DISK_OPEN_CREATE,
272 GNUNET_DISK_PERM_USER_READ |
273 GNUNET_DISK_PERM_USER_WRITE |
274 GNUNET_DISK_PERM_GROUP_READ |
275 GNUNET_DISK_PERM_OTHER_READ)))
277 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
278 "Not able to open file %s\n",
282 /* size = GNUNET_snprintf (output_buffer,
283 sizeof (output_buffer),
285 GNUNET_TIME_absolute_get ().abs_value_us,
289 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
290 "Failed to write string to buffer (size: %i)\n",
295 size = strlen (line) * sizeof (char);
297 size2 = GNUNET_DISK_file_write (f, line, size);
300 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
301 "Unable to write to file! (Size: %u, size2: %u)\n",
307 if (GNUNET_YES != GNUNET_DISK_file_close (f))
308 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
309 "Unable to close file\n");
313 * This function is used to facilitate writing important information to disk
315 #define to_file(file_name, ...) do {\
318 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
320 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
321 "Failed to create tmp_buf\n");\
323 to_file_(file_name,tmp_buf);\
327 * Write the ids and their according index in the given array to a file
331 ids_to_file (char *file_name,
332 struct GNUNET_PeerIdentity *peer_ids,
333 unsigned int num_peer_ids)
337 for (i=0 ; i < num_peer_ids ; i++)
342 GNUNET_i2s_full (&peer_ids[i]));
347 * Test the success of a single test
350 evaluate (struct RPSPeer *loc_rps_peers,
351 unsigned int num_loc_rps_peers,
352 unsigned int expected_recv)
357 tmp_ok = (1 == loc_rps_peers[0].num_rec_ids);
359 for (i = 0 ; i < num_loc_rps_peers ; i++)
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
362 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
364 GNUNET_i2s (loc_rps_peers[i].peer_id),
365 loc_rps_peers[i].num_rec_ids,
367 (1 == loc_rps_peers[i].num_rec_ids));
368 tmp_ok &= (1 == loc_rps_peers[i].num_rec_ids);
370 return tmp_ok? 0 : 1;
375 * Creates an oplist entry and adds it to the oplist DLL
377 static struct OpListEntry *
380 struct OpListEntry *entry;
382 entry = GNUNET_new (struct OpListEntry);
383 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
389 * Callback to be called when NSE service is started or stopped at peers
392 * @param op the operation handle
393 * @param emsg NULL on success; otherwise an error description
397 struct GNUNET_TESTBED_Operation *op,
401 struct OpListEntry *entry = cls;
403 GNUNET_TESTBED_operation_done (entry->op);
406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n");
407 GNUNET_SCHEDULER_shutdown ();
410 GNUNET_assert (0 != entry->delta);
412 num_peers_online += entry->delta;
414 if (0 > entry->delta)
415 { /* Peer hopefully just went offline */
416 if (GNUNET_YES != rps_peers[entry->index].online)
418 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
419 "peer %s was expected to go offline but is still marked as online\n",
420 GNUNET_i2s (rps_peers[entry->index].peer_id));
425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
426 "peer %s probably went offline as expected\n",
427 GNUNET_i2s (rps_peers[entry->index].peer_id));
429 rps_peers[entry->index].online = GNUNET_NO;
432 else if (0 < entry->delta)
433 { /* Peer hopefully just went online */
434 if (GNUNET_NO != rps_peers[entry->index].online)
436 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
437 "peer %s was expected to go online but is still marked as offline\n",
438 GNUNET_i2s (rps_peers[entry->index].peer_id));
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
444 "peer %s probably went online as expected\n",
445 GNUNET_i2s (rps_peers[entry->index].peer_id));
447 rps_peers[entry->index].online = GNUNET_YES;
450 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
452 //if (num_peers_in_round[current_round] == peers_running)
458 * Task run on timeout to shut everything down.
461 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
465 if (NULL != churn_task)
466 GNUNET_SCHEDULER_cancel (churn_task);
468 for (i = 0 ; i < num_peers ; i++)
469 GNUNET_TESTBED_operation_done (rps_peers[i].op);
470 GNUNET_SCHEDULER_shutdown ();
478 seed_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
481 struct RPSPeer *peer = (struct RPSPeer *) cls;
484 // TODO if malicious don't seed mal peers
485 amount = round (.5 * num_peers);
487 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
488 for (i = 0 ; i < amount ; i++)
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
491 GNUNET_i2s (&rps_peer_ids[i]));
493 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
498 * Get the id of peer i.
501 info_cb (void *cb_cls,
502 struct GNUNET_TESTBED_Operation *op,
503 const struct GNUNET_TESTBED_PeerInformation *pinfo,
506 struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
508 if (NULL == pinfo || NULL != emsg)
510 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
517 GNUNET_i2s (pinfo->result.id));
519 rps_peer_ids[entry->index] = *(pinfo->result.id);
520 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
521 rps_peers[entry->index].rec_ids = NULL;
522 rps_peers[entry->index].num_rec_ids = 0;
524 to_file ("/tmp/rps/peer_ids",
527 GNUNET_i2s_full (&rps_peer_ids[entry->index]));
529 GNUNET_TESTBED_operation_done (entry->op);
531 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
537 * Callback to be called when RPS service connect operation is completed
539 * @param cls the callback closure from functions generating an operation
540 * @param op the operation that has been finished
541 * @param ca_result the RPS service handle returned from rps_connect_adapter
542 * @param emsg error message in case the operation has failed; will be NULL if
543 * operation has executed successfully.
546 rps_connect_complete_cb (void *cls,
547 struct GNUNET_TESTBED_Operation *op,
551 struct RPSPeer *rps_peer = cls;
552 struct GNUNET_RPS_Handle *rps = ca_result;
554 rps_peer->rps_handle = rps;
555 rps_peer->online = GNUNET_YES;
558 GNUNET_assert (op == rps_peer->op);
561 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
562 "Failed to connect to RPS service: %s\n",
565 GNUNET_SCHEDULER_shutdown ();
569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
571 cur_test_run.main_test (rps_peer);
576 * Adapter function called to establish a connection to
580 * @param cfg configuration of the peer to connect to; will be available until
581 * GNUNET_TESTBED_operation_done() is called on the operation returned
582 * from GNUNET_TESTBED_service_connect()
583 * @return service handle to return in 'op_result', NULL on error
586 rps_connect_adapter (void *cls,
587 const struct GNUNET_CONFIGURATION_Handle *cfg)
589 struct GNUNET_RPS_Handle *h;
591 h = GNUNET_RPS_connect (cfg);
593 if (NULL != cur_test_run.pre_test)
594 cur_test_run.pre_test (cls, h);
601 * Adapter function called to destroy connection to
605 * @param op_result service handle returned from the connect adapter
608 rps_disconnect_adapter (void *cls,
611 struct GNUNET_RPS_Handle *h = op_result;
612 GNUNET_RPS_disconnect (h);
616 /***********************************************************************
617 * Definition of tests
618 ***********************************************************************/
620 // TODO check whether tests can be stopped earlier
622 default_eval_cb (void)
624 return evaluate (rps_peers, num_peers, 1);
634 * Callback to call on receipt of a reply
637 * @param n number of peers
638 * @param recv_peers the received peers
641 default_reply_handle (void *cls,
643 const struct GNUNET_PeerIdentity *recv_peers)
645 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
649 "[%s] got %" PRIu64 " peers:\n",
650 GNUNET_i2s (rps_peer->peer_id),
653 for (i = 0 ; i < n ; i++)
655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
658 GNUNET_i2s (&recv_peers[i]));
660 GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]);
665 * Request random peers.
668 request_peers (void *cls,
669 const struct GNUNET_SCHEDULER_TaskContext *tc)
671 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
674 "Requesting one peer\n");
676 GNUNET_free (GNUNET_RPS_request_peers (rps_peer->rps_handle,
678 cur_test_run.reply_handle,
680 //rps_peer->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, 1, handle_reply, rps_peer);
684 /***********************************
686 ***********************************/
688 mal_pre (void *cls, struct GNUNET_RPS_Handle *h)
690 #ifdef ENABLE_MALICIOUS
691 uint32_t num_mal_peers;
692 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
694 GNUNET_assert (1 >= portion
696 num_mal_peers = round (portion * num_peers);
698 if (rps_peer->index < num_mal_peers)
700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
701 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
703 GNUNET_i2s (rps_peer->peer_id),
706 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, rps_peer_ids);
708 #endif /* ENABLE_MALICIOUS */
712 mal_cb (struct RPSPeer *rps_peer)
714 uint32_t num_mal_peers;
716 #ifdef ENABLE_MALICIOUS
717 GNUNET_assert (1 >= portion
719 num_mal_peers = round (portion * num_peers);
721 if (rps_peer->index >= num_mal_peers)
722 { /* It's useless to ask a malicious peer about a random sample -
724 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
725 seed_peers, rps_peer);
726 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
727 request_peers, rps_peer);
729 #endif /* ENABLE_MALICIOUS */
735 unsigned int num_mal_peers;
737 num_mal_peers = round (num_peers * portion);
738 return evaluate (&rps_peers[num_mal_peers],
739 num_peers - (num_mal_peers),
744 /***********************************
746 ***********************************/
748 single_req_cb (struct RPSPeer *rps_peer)
750 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
751 request_peers, rps_peer);
754 /***********************************
756 ***********************************/
758 delay_req_cb (struct RPSPeer *rps_peer)
760 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
761 request_peers, rps_peer);
762 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
763 request_peers, rps_peer);
766 /***********************************
768 ***********************************/
770 seed_cb (struct RPSPeer *rps_peer)
772 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
773 seed_peers, rps_peer);
776 /***********************************
778 ***********************************/
780 seed_big_cb (struct RPSPeer *rps_peer)
782 // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers
785 /***********************************
787 ***********************************/
789 single_peer_seed_cb (struct RPSPeer *rps_peer)
794 /***********************************
796 ***********************************/
798 seed_req_cb (struct RPSPeer *rps_peer)
800 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
801 seed_peers, rps_peer);
802 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15),
803 request_peers, rps_peer);
808 /***********************************
810 ***********************************/
812 req_cancel_cb (struct RPSPeer *rps_peer)
817 /***********************************
819 ***********************************/
821 churn (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
823 struct OpListEntry *entry;
826 double portion_online;
827 unsigned int *permut;
828 double prob_go_offline;
829 double portion_go_online;
830 double portion_go_offline;
833 /* Compute the probability for an online peer to go offline
835 portion_online = num_peers_online * 1.0 / num_peers;
836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
837 "Portion online: %f\n",
839 portion_go_online = ((1 - portion_online) * .5 * .66);
840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
841 "Portion that should go online: %f\n",
843 portion_go_offline = (portion_online + portion_go_online) - .75;
844 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
845 "Portion that probably goes offline: %f\n",
847 prob_go_offline = portion_go_offline / (portion_online * .5);
848 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
849 "Probability of a selected online peer to go offline: %f\n",
852 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
853 (unsigned int) num_peers);
855 /* Go over 50% randomly chosen peers */
856 for (i = 0 ; i < .5 * num_peers ; i++)
860 /* If online, shut down with certain probability */
861 if (GNUNET_YES == rps_peers[j].online)
863 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
866 "%u. selected peer (%u: %s) is online.\n",
869 GNUNET_i2s (rps_peers[j].peer_id));
870 if (prob < prob_go_offline * UINT32_MAX)
872 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
874 GNUNET_i2s (rps_peers[j].peer_id));
876 entry = make_oplist_entry ();
879 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
888 /* If offline, restart with certain probability */
889 else if (GNUNET_NO == rps_peers[j].online)
891 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
893 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
894 "%u. selected peer (%u: %s) is offline.\n",
897 GNUNET_i2s (rps_peers[j].peer_id));
898 if (prob < .66 * UINT32_MAX)
900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
902 GNUNET_i2s (rps_peers[j].peer_id));
904 entry = make_oplist_entry ();
907 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
917 GNUNET_free (permut);
919 churn_task = GNUNET_SCHEDULER_add_delayed (
920 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
927 profiler_pre (void *cls, struct GNUNET_RPS_Handle *h)
929 //churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
934 /* if (NULL == churn_task)
936 churn_task = GNUNET_SCHEDULER_add_delayed (
937 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
945 * Callback to call on receipt of a reply
948 * @param n number of peers
949 * @param recv_peers the received peers
952 profiler_reply_handle (void *cls,
954 const struct GNUNET_PeerIdentity *recv_peers)
956 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
960 file_name = "/tmp/rps/received_ids";
962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
963 "[%s] got %" PRIu64 " peers:\n",
964 GNUNET_i2s (rps_peer->peer_id),
967 for (i = 0 ; i < n ; i++)
969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
972 GNUNET_i2s (&recv_peers[i]));
974 /* GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); */
977 GNUNET_i2s_full (&recv_peers[i]));
983 profiler_cb (struct RPSPeer *rps_peer)
987 /* Churn only at peers that do not request peers for evaluation */
988 if (NULL == churn_task &&
989 rps_peer->index != num_peers - 2)
991 churn_task = GNUNET_SCHEDULER_add_delayed (
992 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
997 /* Only request peer ids at one peer.
998 * (It's the before-last because last one is target of the focussed attack.)
1000 if (rps_peer->index == num_peers - 2)
1002 for (i = 0 ; i < cur_test_run.num_requests ; i++)
1004 GNUNET_SCHEDULER_add_delayed (
1005 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1006 cur_test_run.request_interval * i),
1014 /***********************************************************************
1015 * /Definition of tests
1016 ***********************************************************************/
1020 * Actual "main" function for the testcase.
1022 * @param cls closure
1023 * @param h the run handle
1024 * @param n_peers number of peers in 'peers'
1025 * @param peers handle to peers run in the testbed
1026 * @param links_succeeded the number of overlay link connection attempts that
1028 * @param links_failed the number of overlay link connection attempts that
1033 struct GNUNET_TESTBED_RunHandle *h,
1034 unsigned int n_peers,
1035 struct GNUNET_TESTBED_Peer **peers,
1036 unsigned int links_succeeded,
1037 unsigned int links_failed)
1040 struct OpListEntry *entry;
1042 testbed_peers = peers;
1043 num_peers_online = 0;
1045 for (i = 0 ; i < num_peers ; i++)
1047 entry = make_oplist_entry ();
1049 entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
1050 GNUNET_TESTBED_PIT_IDENTITY,
1056 // This seems not to work
1057 //if (NULL != strstr (cur_test_run.name, "profiler"))
1059 // churn_task = GNUNET_SCHEDULER_add_delayed (
1060 // GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1065 GNUNET_assert (num_peers == n_peers);
1066 for (i = 0 ; i < n_peers ; i++)
1068 rps_peers[i].index = i;
1070 GNUNET_TESTBED_service_connect (&rps_peers[i],
1073 &rps_connect_complete_cb,
1075 &rps_connect_adapter,
1076 &rps_disconnect_adapter,
1080 if (NULL != churn_task)
1081 GNUNET_SCHEDULER_cancel (churn_task);
1083 GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL);
1088 * Entry point for the testcase, sets up the testbed.
1090 * @param argc unused
1091 * @param argv unused
1092 * @return 0 on success
1095 main (int argc, char *argv[])
1097 cur_test_run.name = "test-rps-default";
1098 cur_test_run.pre_test = NULL;
1099 cur_test_run.reply_handle = default_reply_handle;
1100 cur_test_run.eval_cb = default_eval_cb;
1104 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
1106 if (strstr (argv[0], "malicious") != NULL)
1108 cur_test_run.pre_test = mal_pre;
1109 cur_test_run.main_test = mal_cb;
1110 cur_test_run.eval_cb = mal_eval;
1112 if (strstr (argv[0], "_1") != NULL)
1114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
1115 cur_test_run.name = "test-rps-malicious_1";
1118 else if (strstr (argv[0], "_2") != NULL)
1120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
1121 cur_test_run.name = "test-rps-malicious_2";
1124 else if (strstr (argv[0], "_3") != NULL)
1126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n");
1127 cur_test_run.name = "test-rps-malicious_3";
1132 else if (strstr (argv[0], "_single_req") != NULL)
1134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
1135 cur_test_run.name = "test-rps-single-req";
1136 cur_test_run.main_test = single_req_cb;
1139 else if (strstr (argv[0], "_delayed_reqs") != NULL)
1141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
1142 cur_test_run.name = "test-rps-delayed-reqs";
1143 cur_test_run.main_test = delay_req_cb;
1146 else if (strstr (argv[0], "_seed_big") != NULL)
1148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_SERVER_MAX_MESSAGE_SIZE)\n");
1149 cur_test_run.name = "test-rps-seed-big";
1150 cur_test_run.main_test = seed_big_cb;
1153 else if (strstr (argv[0], "_single_peer_seed") != NULL)
1155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
1156 cur_test_run.name = "test-rps-single-peer-seed";
1157 cur_test_run.main_test = single_peer_seed_cb;
1160 else if (strstr (argv[0], "_seed_request") != NULL)
1162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
1163 cur_test_run.name = "test-rps-seed-request";
1164 cur_test_run.main_test = seed_req_cb;
1167 else if (strstr (argv[0], "_seed") != NULL)
1169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
1170 cur_test_run.name = "test-rps-seed";
1171 cur_test_run.main_test = seed_cb;
1172 cur_test_run.eval_cb = no_eval;
1175 else if (strstr (argv[0], "_req_cancel") != NULL)
1177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
1178 cur_test_run.name = "test-rps-req-cancel";
1179 cur_test_run.main_test = req_cancel_cb;
1182 else if (strstr (argv[0], "profiler") != NULL)
1184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
1185 cur_test_run.name = "test-rps-profiler";
1187 cur_test_run.pre_test = profiler_pre;
1188 cur_test_run.main_test = profiler_cb;
1189 cur_test_run.reply_handle = profiler_reply_handle;
1190 cur_test_run.eval_cb = no_eval;
1191 cur_test_run.request_interval = 2;
1192 cur_test_run.num_requests = 50;
1196 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
1197 GNUNET_DISK_directory_create ("/tmp/rps/");
1198 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90);
1201 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
1202 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
1205 (void) GNUNET_TESTBED_test_run (cur_test_run.name,
1211 return cur_test_run.eval_cb();
1214 /* end of test_rps_multipeer.c */