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;
162 * Peermap to get the index of a given peer ID quick.
164 static struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
169 static struct GNUNET_PeerIdentity *rps_peer_ids;
172 * Number of online peers.
174 static unsigned int num_peers_online;
177 * Return value from 'main'.
183 * Identifier for the churn task that runs periodically
185 static struct GNUNET_SCHEDULER_Task *churn_task;
189 * Called directly after connecting to the service
191 typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h);
194 * Called from within #rps_connect_complete_cb ()
195 * Executes functions to test the api/service
197 typedef void (*MainTest) (struct RPSPeer *rps_peer);
200 * Callback called once the requested random peers are available
202 typedef void (*ReplyHandle) (void *cls,
204 const struct GNUNET_PeerIdentity *recv_peers);
207 * Called directly before disconnecting from the service
209 typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h);
212 * Function called after disconnect to evaluate test success
214 typedef int (*EvaluationCallback) (void);
218 * Structure to define a single test
228 * Called directly after connecting to the service
233 * Function to execute the functions to be tested
238 * Callback called once the requested peers are available
240 ReplyHandle reply_handle;
243 * Called directly before disconnecting from the service
248 * Function to evaluate the test results
250 EvaluationCallback eval_cb;
255 uint32_t request_interval;
258 * Number of Requests to make.
260 uint32_t num_requests;
265 * Append arguments to file
268 tofile_ (const char *file_name, char *line)
270 struct GNUNET_DISK_FileHandle *f;
271 /* char output_buffer[512]; */
276 if (NULL == (f = GNUNET_DISK_file_open (file_name,
277 GNUNET_DISK_OPEN_APPEND |
278 GNUNET_DISK_OPEN_WRITE |
279 GNUNET_DISK_OPEN_CREATE,
280 GNUNET_DISK_PERM_USER_READ |
281 GNUNET_DISK_PERM_USER_WRITE |
282 GNUNET_DISK_PERM_GROUP_READ |
283 GNUNET_DISK_PERM_OTHER_READ)))
285 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
286 "Not able to open file %s\n",
290 /* size = GNUNET_snprintf (output_buffer,
291 sizeof (output_buffer),
293 GNUNET_TIME_absolute_get ().abs_value_us,
297 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
298 "Failed to write string to buffer (size: %i)\n",
303 size = strlen (line) * sizeof (char);
305 size2 = GNUNET_DISK_file_write (f, line, size);
308 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
309 "Unable to write to file! (Size: %u, size2: %u)\n",
315 if (GNUNET_YES != GNUNET_DISK_file_close (f))
316 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
317 "Unable to close file\n");
321 * This function is used to facilitate writing important information to disk
323 #define tofile(file_name, ...) do {\
326 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
328 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
329 "Failed to create tmp_buf\n");\
331 tofile_(file_name,tmp_buf);\
336 * Write the ids and their according index in the given array to a file
340 ids_to_file (char *file_name,
341 struct GNUNET_PeerIdentity *peer_ids,
342 unsigned int num_peer_ids)
346 for (i=0 ; i < num_peer_ids ; i++)
351 GNUNET_i2s_full (&peer_ids[i]));
356 * Test the success of a single test
359 evaluate (struct RPSPeer *loc_rps_peers,
360 unsigned int num_loc_rps_peers,
361 unsigned int expected_recv)
366 tmp_ok = (1 == loc_rps_peers[0].num_rec_ids);
368 for (i = 0 ; i < num_loc_rps_peers ; i++)
370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
371 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
373 GNUNET_i2s (loc_rps_peers[i].peer_id),
374 loc_rps_peers[i].num_rec_ids,
376 (1 == loc_rps_peers[i].num_rec_ids));
377 tmp_ok &= (1 == loc_rps_peers[i].num_rec_ids);
379 return tmp_ok? 0 : 1;
384 * Creates an oplist entry and adds it to the oplist DLL
386 static struct OpListEntry *
389 struct OpListEntry *entry;
391 entry = GNUNET_new (struct OpListEntry);
392 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
398 * Callback to be called when RPS service is started or stopped at peers
401 * @param op the operation handle
402 * @param emsg NULL on success; otherwise an error description
406 struct GNUNET_TESTBED_Operation *op,
410 struct OpListEntry *entry = cls;
412 GNUNET_TESTBED_operation_done (entry->op);
415 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n");
416 GNUNET_SCHEDULER_shutdown ();
419 GNUNET_assert (0 != entry->delta);
421 num_peers_online += entry->delta;
423 if (0 > entry->delta)
424 { /* Peer hopefully just went offline */
425 if (GNUNET_YES != rps_peers[entry->index].online)
427 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
428 "peer %s was expected to go offline but is still marked as online\n",
429 GNUNET_i2s (rps_peers[entry->index].peer_id));
434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
435 "peer %s probably went offline as expected\n",
436 GNUNET_i2s (rps_peers[entry->index].peer_id));
438 rps_peers[entry->index].online = GNUNET_NO;
441 else if (0 < entry->delta)
442 { /* Peer hopefully just went online */
443 if (GNUNET_NO != rps_peers[entry->index].online)
445 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
446 "peer %s was expected to go online but is still marked as offline\n",
447 GNUNET_i2s (rps_peers[entry->index].peer_id));
452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
453 "peer %s probably went online as expected\n",
454 GNUNET_i2s (rps_peers[entry->index].peer_id));
455 if (NULL != cur_test_run.pre_test)
457 cur_test_run.pre_test (&rps_peers[entry->index],
458 rps_peers[entry->index].rps_handle);
461 rps_peers[entry->index].online = GNUNET_YES;
464 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
466 //if (num_peers_in_round[current_round] == peers_running)
472 * Task run on timeout to shut everything down.
475 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
479 if (NULL != churn_task)
480 GNUNET_SCHEDULER_cancel (churn_task);
482 for (i = 0 ; i < num_peers ; i++)
483 GNUNET_TESTBED_operation_done (rps_peers[i].op);
484 GNUNET_SCHEDULER_shutdown ();
492 seed_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
495 struct RPSPeer *peer = (struct RPSPeer *) cls;
498 // TODO if malicious don't seed mal peers
499 amount = round (.5 * num_peers);
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
502 for (i = 0 ; i < amount ; i++)
503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
505 GNUNET_i2s (&rps_peer_ids[i]));
507 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
512 * Get the id of peer i.
515 info_cb (void *cb_cls,
516 struct GNUNET_TESTBED_Operation *op,
517 const struct GNUNET_TESTBED_PeerInformation *pinfo,
520 struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
522 if (NULL == pinfo || NULL != emsg)
524 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
531 GNUNET_i2s (pinfo->result.id));
533 rps_peer_ids[entry->index] = *(pinfo->result.id);
534 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
535 rps_peers[entry->index].rec_ids = NULL;
536 rps_peers[entry->index].num_rec_ids = 0;
538 GNUNET_CONTAINER_multipeermap_put (peer_map,
539 &rps_peer_ids[entry->index],
540 &rps_peers[entry->index],
541 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
543 tofile ("/tmp/rps/peer_ids",
546 GNUNET_i2s_full (&rps_peer_ids[entry->index]));
548 GNUNET_TESTBED_operation_done (entry->op);
550 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
556 * Callback to be called when RPS service connect operation is completed
558 * @param cls the callback closure from functions generating an operation
559 * @param op the operation that has been finished
560 * @param ca_result the RPS service handle returned from rps_connect_adapter
561 * @param emsg error message in case the operation has failed; will be NULL if
562 * operation has executed successfully.
565 rps_connect_complete_cb (void *cls,
566 struct GNUNET_TESTBED_Operation *op,
570 struct RPSPeer *rps_peer = cls;
571 struct GNUNET_RPS_Handle *rps = ca_result;
573 rps_peer->rps_handle = rps;
574 rps_peer->online = GNUNET_YES;
577 GNUNET_assert (op == rps_peer->op);
580 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
581 "Failed to connect to RPS service: %s\n",
584 GNUNET_SCHEDULER_shutdown ();
588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
590 cur_test_run.main_test (rps_peer);
595 * Adapter function called to establish a connection to
599 * @param cfg configuration of the peer to connect to; will be available until
600 * GNUNET_TESTBED_operation_done() is called on the operation returned
601 * from GNUNET_TESTBED_service_connect()
602 * @return service handle to return in 'op_result', NULL on error
605 rps_connect_adapter (void *cls,
606 const struct GNUNET_CONFIGURATION_Handle *cfg)
608 struct GNUNET_RPS_Handle *h;
610 h = GNUNET_RPS_connect (cfg);
612 if (NULL != cur_test_run.pre_test)
613 cur_test_run.pre_test (cls, h);
620 * Adapter function called to destroy connection to
624 * @param op_result service handle returned from the connect adapter
627 rps_disconnect_adapter (void *cls,
630 struct GNUNET_RPS_Handle *h = op_result;
631 GNUNET_RPS_disconnect (h);
635 /***********************************************************************
636 * Definition of tests
637 ***********************************************************************/
639 // TODO check whether tests can be stopped earlier
641 default_eval_cb (void)
643 return evaluate (rps_peers, num_peers, 1);
653 * Callback to call on receipt of a reply
656 * @param n number of peers
657 * @param recv_peers the received peers
660 default_reply_handle (void *cls,
662 const struct GNUNET_PeerIdentity *recv_peers)
664 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
667 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
668 "[%s] got %" PRIu64 " peers:\n",
669 GNUNET_i2s (rps_peer->peer_id),
672 for (i = 0 ; i < n ; i++)
674 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
677 GNUNET_i2s (&recv_peers[i]));
679 GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]);
684 * Request random peers.
687 request_peers (void *cls,
688 const struct GNUNET_SCHEDULER_TaskContext *tc)
690 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
693 "Requesting one peer\n");
695 GNUNET_free (GNUNET_RPS_request_peers (rps_peer->rps_handle,
697 cur_test_run.reply_handle,
699 //rps_peer->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, 1, handle_reply, rps_peer);
703 /***********************************
705 ***********************************/
707 mal_pre (void *cls, struct GNUNET_RPS_Handle *h)
709 #ifdef ENABLE_MALICIOUS
710 uint32_t num_mal_peers;
711 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
713 GNUNET_assert (1 >= portion
715 num_mal_peers = round (portion * num_peers);
717 if (rps_peer->index < num_mal_peers)
719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
720 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
722 GNUNET_i2s (rps_peer->peer_id),
725 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, rps_peer_ids);
727 #endif /* ENABLE_MALICIOUS */
731 mal_cb (struct RPSPeer *rps_peer)
733 uint32_t num_mal_peers;
735 #ifdef ENABLE_MALICIOUS
736 GNUNET_assert (1 >= portion
738 num_mal_peers = round (portion * num_peers);
740 if (rps_peer->index >= num_mal_peers)
741 { /* It's useless to ask a malicious peer about a random sample -
743 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
744 seed_peers, rps_peer);
745 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
746 request_peers, rps_peer);
748 #endif /* ENABLE_MALICIOUS */
754 unsigned int num_mal_peers;
756 num_mal_peers = round (num_peers * portion);
757 return evaluate (&rps_peers[num_mal_peers],
758 num_peers - (num_mal_peers),
763 /***********************************
765 ***********************************/
767 single_req_cb (struct RPSPeer *rps_peer)
769 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
770 request_peers, rps_peer);
773 /***********************************
775 ***********************************/
777 delay_req_cb (struct RPSPeer *rps_peer)
779 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
780 request_peers, rps_peer);
781 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
782 request_peers, rps_peer);
785 /***********************************
787 ***********************************/
789 seed_cb (struct RPSPeer *rps_peer)
791 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
792 seed_peers, rps_peer);
795 /***********************************
797 ***********************************/
799 seed_big_cb (struct RPSPeer *rps_peer)
801 // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers
804 /***********************************
806 ***********************************/
808 single_peer_seed_cb (struct RPSPeer *rps_peer)
813 /***********************************
815 ***********************************/
817 seed_req_cb (struct RPSPeer *rps_peer)
819 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
820 seed_peers, rps_peer);
821 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15),
822 request_peers, rps_peer);
827 /***********************************
829 ***********************************/
831 req_cancel_cb (struct RPSPeer *rps_peer)
836 /***********************************
838 ***********************************/
840 churn (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
842 struct OpListEntry *entry;
845 double portion_online;
846 unsigned int *permut;
847 double prob_go_offline;
848 double portion_go_online;
849 double portion_go_offline;
852 /* Compute the probability for an online peer to go offline
854 portion_online = num_peers_online * 1.0 / num_peers;
855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
856 "Portion online: %f\n",
858 portion_go_online = ((1 - portion_online) * .5 * .66);
859 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
860 "Portion that should go online: %f\n",
862 portion_go_offline = (portion_online + portion_go_online) - .75;
863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
864 "Portion that probably goes offline: %f\n",
866 prob_go_offline = portion_go_offline / (portion_online * .5);
867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
868 "Probability of a selected online peer to go offline: %f\n",
871 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
872 (unsigned int) num_peers);
874 /* Go over 50% randomly chosen peers */
875 for (i = 0 ; i < .5 * num_peers ; i++)
879 /* If online, shut down with certain probability */
880 if (GNUNET_YES == rps_peers[j].online)
882 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
885 "%u. selected peer (%u: %s) is online.\n",
888 GNUNET_i2s (rps_peers[j].peer_id));
889 if (prob < prob_go_offline * UINT32_MAX)
891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
893 GNUNET_i2s (rps_peers[j].peer_id));
895 entry = make_oplist_entry ();
898 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
907 /* If offline, restart with certain probability */
908 else if (GNUNET_NO == rps_peers[j].online)
910 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
913 "%u. selected peer (%u: %s) is offline.\n",
916 GNUNET_i2s (rps_peers[j].peer_id));
917 if (prob < .66 * UINT32_MAX)
919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
921 GNUNET_i2s (rps_peers[j].peer_id));
923 entry = make_oplist_entry ();
926 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
936 GNUNET_free (permut);
938 churn_task = GNUNET_SCHEDULER_add_delayed (
939 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
946 profiler_pre (void *cls, struct GNUNET_RPS_Handle *h)
948 //churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
953 /* if (NULL == churn_task)
955 churn_task = GNUNET_SCHEDULER_add_delayed (
956 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
964 * Callback to call on receipt of a reply
967 * @param n number of peers
968 * @param recv_peers the received peers
971 profiler_reply_handle (void *cls,
973 const struct GNUNET_PeerIdentity *recv_peers)
975 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
976 struct RPSPeer *rcv_rps_peer;
981 file_name = "/tmp/rps/received_ids";
982 file_name_dh = "/tmp/rps/diehard_input";
984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
985 "[%s] got %" PRIu64 " peers:\n",
986 GNUNET_i2s (rps_peer->peer_id),
989 for (i = 0 ; i < n ; i++)
991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
994 GNUNET_i2s (&recv_peers[i]));
996 /* GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); */
999 GNUNET_i2s_full (&recv_peers[i]));
1001 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]);
1003 tofile (file_name_dh,
1005 (uint32_t) rcv_rps_peer->index);
1011 profiler_cb (struct RPSPeer *rps_peer)
1015 /* Churn only at peers that do not request peers for evaluation */
1016 if (NULL == churn_task &&
1017 rps_peer->index != num_peers - 2)
1019 churn_task = GNUNET_SCHEDULER_add_delayed (
1020 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
1025 /* Only request peer ids at one peer.
1026 * (It's the before-last because last one is target of the focussed attack.)
1028 if (rps_peer->index == num_peers - 2)
1030 for (i = 0 ; i < cur_test_run.num_requests ; i++)
1032 GNUNET_SCHEDULER_add_delayed (
1033 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1034 cur_test_run.request_interval * i),
1042 * Function called from #profiler_eval with a filename.
1044 * @param cls closure
1045 * @param filename complete filename (absolute path)
1046 * @return #GNUNET_OK to continue to iterate,
1047 * #GNUNET_NO to stop iteration with no error,
1048 * #GNUNET_SYSERR to abort iteration with error!
1051 file_name_cb (void *cls, const char *filename)
1053 if (NULL != strstr (filename, "sampler_el"))
1055 struct RPS_SamplerElement *s_elem;
1056 struct GNUNET_CRYPTO_AuthKey auth_key;
1057 const char *key_char;
1060 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
1061 tofile (filename, "--------------------------\n");
1063 auth_key = string_to_auth_key (key_char);
1064 s_elem = RPS_sampler_elem_create ();
1065 RPS_sampler_elem_set (s_elem, auth_key);
1067 for (i = 0; i < num_peers; i++)
1069 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
1076 * This is run after the test finished.
1078 * Compute all perfect samples.
1081 profiler_eval (void)
1083 /* Compute perfect sample for each sampler element */
1084 if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL))
1086 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
1093 /***********************************************************************
1094 * /Definition of tests
1095 ***********************************************************************/
1099 * Actual "main" function for the testcase.
1101 * @param cls closure
1102 * @param h the run handle
1103 * @param n_peers number of peers in 'peers'
1104 * @param peers handle to peers run in the testbed
1105 * @param links_succeeded the number of overlay link connection attempts that
1107 * @param links_failed the number of overlay link connection attempts that
1112 struct GNUNET_TESTBED_RunHandle *h,
1113 unsigned int n_peers,
1114 struct GNUNET_TESTBED_Peer **peers,
1115 unsigned int links_succeeded,
1116 unsigned int links_failed)
1119 struct OpListEntry *entry;
1121 testbed_peers = peers;
1122 num_peers_online = 0;
1124 for (i = 0 ; i < num_peers ; i++)
1126 entry = make_oplist_entry ();
1128 entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
1129 GNUNET_TESTBED_PIT_IDENTITY,
1135 // This seems not to work
1136 //if (NULL != strstr (cur_test_run.name, "profiler"))
1138 // churn_task = GNUNET_SCHEDULER_add_delayed (
1139 // GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1144 GNUNET_assert (num_peers == n_peers);
1145 for (i = 0 ; i < n_peers ; i++)
1147 rps_peers[i].index = i;
1149 GNUNET_TESTBED_service_connect (&rps_peers[i],
1152 &rps_connect_complete_cb,
1154 &rps_connect_adapter,
1155 &rps_disconnect_adapter,
1159 if (NULL != churn_task)
1160 GNUNET_SCHEDULER_cancel (churn_task);
1162 GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL);
1167 * Entry point for the testcase, sets up the testbed.
1169 * @param argc unused
1170 * @param argv unused
1171 * @return 0 on success
1174 main (int argc, char *argv[])
1178 cur_test_run.name = "test-rps-default";
1179 cur_test_run.pre_test = NULL;
1180 cur_test_run.reply_handle = default_reply_handle;
1181 cur_test_run.eval_cb = default_eval_cb;
1185 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
1187 if (strstr (argv[0], "malicious") != NULL)
1189 cur_test_run.pre_test = mal_pre;
1190 cur_test_run.main_test = mal_cb;
1191 cur_test_run.eval_cb = mal_eval;
1193 if (strstr (argv[0], "_1") != NULL)
1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
1196 cur_test_run.name = "test-rps-malicious_1";
1199 else if (strstr (argv[0], "_2") != NULL)
1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
1202 cur_test_run.name = "test-rps-malicious_2";
1205 else if (strstr (argv[0], "_3") != NULL)
1207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n");
1208 cur_test_run.name = "test-rps-malicious_3";
1213 else if (strstr (argv[0], "_single_req") != NULL)
1215 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
1216 cur_test_run.name = "test-rps-single-req";
1217 cur_test_run.main_test = single_req_cb;
1220 else if (strstr (argv[0], "_delayed_reqs") != NULL)
1222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
1223 cur_test_run.name = "test-rps-delayed-reqs";
1224 cur_test_run.main_test = delay_req_cb;
1227 else if (strstr (argv[0], "_seed_big") != NULL)
1229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_SERVER_MAX_MESSAGE_SIZE)\n");
1230 cur_test_run.name = "test-rps-seed-big";
1231 cur_test_run.main_test = seed_big_cb;
1234 else if (strstr (argv[0], "_single_peer_seed") != NULL)
1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
1237 cur_test_run.name = "test-rps-single-peer-seed";
1238 cur_test_run.main_test = single_peer_seed_cb;
1241 else if (strstr (argv[0], "_seed_request") != NULL)
1243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
1244 cur_test_run.name = "test-rps-seed-request";
1245 cur_test_run.main_test = seed_req_cb;
1248 else if (strstr (argv[0], "_seed") != NULL)
1250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
1251 cur_test_run.name = "test-rps-seed";
1252 cur_test_run.main_test = seed_cb;
1253 cur_test_run.eval_cb = no_eval;
1256 else if (strstr (argv[0], "_req_cancel") != NULL)
1258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
1259 cur_test_run.name = "test-rps-req-cancel";
1260 cur_test_run.main_test = req_cancel_cb;
1263 else if (strstr (argv[0], "profiler") != NULL)
1265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
1266 cur_test_run.name = "test-rps-profiler";
1268 cur_test_run.pre_test = profiler_pre;
1269 cur_test_run.main_test = profiler_cb;
1270 cur_test_run.reply_handle = profiler_reply_handle;
1271 cur_test_run.eval_cb = profiler_eval;
1272 cur_test_run.request_interval = 2;
1273 cur_test_run.num_requests = 50;
1277 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
1278 GNUNET_DISK_directory_create ("/tmp/rps/");
1279 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90);
1282 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
1283 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
1284 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
1287 (void) GNUNET_TESTBED_test_run (cur_test_run.name,
1293 ret_value = cur_test_run.eval_cb();
1295 GNUNET_free (rps_peers );
1296 GNUNET_free (rps_peer_ids);
1297 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
1302 /* end of test_rps_multipeer.c */