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;
50 * Portion of malicious peers
52 static double portion = .1;
55 * Type of malicious peer to test
57 static unsigned int mal_type = 0;
60 * Handles to all of the running peers
62 static struct GNUNET_TESTBED_Peer **testbed_peers;
73 struct OpListEntry *next;
78 struct OpListEntry *prev;
81 * The testbed operation
83 struct GNUNET_TESTBED_Operation *op;
86 * Depending on whether we start or stop NSE service at the peer set this to 1
92 * Index of the regarding peer
100 static struct OpListEntry *oplist_head;
105 static struct OpListEntry *oplist_tail;
109 * Information we track for each peer.
119 * Handle for RPS connect operation.
121 struct GNUNET_TESTBED_Operation *op;
124 * Handle to RPS service.
126 struct GNUNET_RPS_Handle *rps_handle;
131 struct GNUNET_PeerIdentity *peer_id;
134 * A request handle to check for an request
136 //struct GNUNET_RPS_Request_Handle *req_handle;
139 * Peer on- or offline?
146 struct GNUNET_PeerIdentity *rec_ids;
149 * Number of received PeerIDs
151 unsigned int num_rec_ids;
156 * Information for all the peers.
158 static struct RPSPeer *rps_peers;
161 * Peermap to get the index of a given peer ID quick.
163 static struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
168 static struct GNUNET_PeerIdentity *rps_peer_ids;
171 * Number of online peers.
173 static unsigned int num_peers_online;
176 * Return value from 'main'.
182 * Identifier for the churn task that runs periodically
184 static struct GNUNET_SCHEDULER_Task *churn_task;
188 * Called directly after connecting to the service
190 typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h);
193 * Called from within #rps_connect_complete_cb ()
194 * Executes functions to test the api/service
196 typedef void (*MainTest) (struct RPSPeer *rps_peer);
199 * Callback called once the requested random peers are available
201 typedef void (*ReplyHandle) (void *cls,
203 const struct GNUNET_PeerIdentity *recv_peers);
206 * Called directly before disconnecting from the service
208 typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h);
211 * Function called after disconnect to evaluate test success
213 typedef int (*EvaluationCallback) (void);
217 * Structure to define a single test
227 * Called directly after connecting to the service
232 * Function to execute the functions to be tested
237 * Callback called once the requested peers are available
239 ReplyHandle reply_handle;
242 * Called directly before disconnecting from the service
247 * Function to evaluate the test results
249 EvaluationCallback eval_cb;
254 uint32_t request_interval;
257 * Number of Requests to make.
259 uint32_t num_requests;
263 * Are we shutting down?
265 static int in_shutdown;
268 * Append arguments to file
271 tofile_ (const char *file_name, char *line)
273 struct GNUNET_DISK_FileHandle *f;
274 /* char output_buffer[512]; */
279 if (NULL == (f = GNUNET_DISK_file_open (file_name,
280 GNUNET_DISK_OPEN_APPEND |
281 GNUNET_DISK_OPEN_WRITE |
282 GNUNET_DISK_OPEN_CREATE,
283 GNUNET_DISK_PERM_USER_READ |
284 GNUNET_DISK_PERM_USER_WRITE |
285 GNUNET_DISK_PERM_GROUP_READ |
286 GNUNET_DISK_PERM_OTHER_READ)))
288 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
289 "Not able to open file %s\n",
293 /* size = GNUNET_snprintf (output_buffer,
294 sizeof (output_buffer),
296 GNUNET_TIME_absolute_get ().abs_value_us,
300 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
301 "Failed to write string to buffer (size: %i)\n",
306 size = strlen (line) * sizeof (char);
308 size2 = GNUNET_DISK_file_write (f, line, size);
311 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
312 "Unable to write to file! (Size: %u, size2: %u)\n",
318 if (GNUNET_YES != GNUNET_DISK_file_close (f))
319 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
320 "Unable to close file\n");
324 * This function is used to facilitate writing important information to disk
326 #define tofile(file_name, ...) do {\
329 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
331 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
332 "Failed to create tmp_buf\n");\
334 tofile_(file_name,tmp_buf);\
339 * Write the ids and their according index in the given array to a file
343 ids_to_file (char *file_name,
344 struct GNUNET_PeerIdentity *peer_ids,
345 unsigned int num_peer_ids)
349 for (i=0 ; i < num_peer_ids ; i++)
354 GNUNET_i2s_full (&peer_ids[i]));
359 * Test the success of a single test
362 evaluate (struct RPSPeer *loc_rps_peers,
363 unsigned int num_loc_rps_peers,
364 unsigned int expected_recv)
369 tmp_ok = (1 == loc_rps_peers[0].num_rec_ids);
371 for (i = 0 ; i < num_loc_rps_peers ; i++)
373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
374 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
376 GNUNET_i2s (loc_rps_peers[i].peer_id),
377 loc_rps_peers[i].num_rec_ids,
379 (1 == loc_rps_peers[i].num_rec_ids));
380 tmp_ok &= (1 == loc_rps_peers[i].num_rec_ids);
382 return tmp_ok? 0 : 1;
387 * Creates an oplist entry and adds it to the oplist DLL
389 static struct OpListEntry *
392 struct OpListEntry *entry;
394 entry = GNUNET_new (struct OpListEntry);
395 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
401 * Callback to be called when RPS service is started or stopped at peers
404 * @param op the operation handle
405 * @param emsg NULL on success; otherwise an error description
409 struct GNUNET_TESTBED_Operation *op,
413 struct OpListEntry *entry = cls;
415 GNUNET_TESTBED_operation_done (entry->op);
418 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n");
419 GNUNET_SCHEDULER_shutdown ();
422 GNUNET_assert (0 != entry->delta);
424 num_peers_online += entry->delta;
426 if (0 > entry->delta)
427 { /* Peer hopefully just went offline */
428 if (GNUNET_YES != rps_peers[entry->index].online)
430 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
431 "peer %s was expected to go offline but is still marked as online\n",
432 GNUNET_i2s (rps_peers[entry->index].peer_id));
437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
438 "peer %s probably went offline as expected\n",
439 GNUNET_i2s (rps_peers[entry->index].peer_id));
441 rps_peers[entry->index].online = GNUNET_NO;
444 else if (0 < entry->delta)
445 { /* Peer hopefully just went online */
446 if (GNUNET_NO != rps_peers[entry->index].online)
448 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
449 "peer %s was expected to go online but is still marked as offline\n",
450 GNUNET_i2s (rps_peers[entry->index].peer_id));
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
456 "peer %s probably went online as expected\n",
457 GNUNET_i2s (rps_peers[entry->index].peer_id));
458 if (NULL != cur_test_run.pre_test)
460 cur_test_run.pre_test (&rps_peers[entry->index],
461 rps_peers[entry->index].rps_handle);
464 rps_peers[entry->index].online = GNUNET_YES;
467 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
469 //if (num_peers_in_round[current_round] == peers_running)
475 * Task run on timeout to shut everything down.
478 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
482 in_shutdown = GNUNET_YES;
483 if (NULL != churn_task)
484 GNUNET_SCHEDULER_cancel (churn_task);
486 for (i = 0 ; i < num_peers ; i++)
487 GNUNET_TESTBED_operation_done (rps_peers[i].op);
488 GNUNET_SCHEDULER_shutdown ();
496 seed_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
499 struct RPSPeer *peer = (struct RPSPeer *) cls;
502 // TODO if malicious don't seed mal peers
503 amount = round (.5 * num_peers);
505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
506 for (i = 0 ; i < amount ; i++)
507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
509 GNUNET_i2s (&rps_peer_ids[i]));
511 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
516 * Get the id of peer i.
519 info_cb (void *cb_cls,
520 struct GNUNET_TESTBED_Operation *op,
521 const struct GNUNET_TESTBED_PeerInformation *pinfo,
524 struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
526 if (NULL == pinfo || NULL != emsg)
528 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
535 GNUNET_i2s (pinfo->result.id));
537 rps_peer_ids[entry->index] = *(pinfo->result.id);
538 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
539 rps_peers[entry->index].rec_ids = NULL;
540 rps_peers[entry->index].num_rec_ids = 0;
542 GNUNET_CONTAINER_multipeermap_put (peer_map,
543 &rps_peer_ids[entry->index],
544 &rps_peers[entry->index],
545 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
547 tofile ("/tmp/rps/peer_ids",
550 GNUNET_i2s_full (&rps_peer_ids[entry->index]));
552 GNUNET_TESTBED_operation_done (entry->op);
554 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
560 * Callback to be called when RPS service connect operation is completed
562 * @param cls the callback closure from functions generating an operation
563 * @param op the operation that has been finished
564 * @param ca_result the RPS service handle returned from rps_connect_adapter
565 * @param emsg error message in case the operation has failed; will be NULL if
566 * operation has executed successfully.
569 rps_connect_complete_cb (void *cls,
570 struct GNUNET_TESTBED_Operation *op,
574 struct RPSPeer *rps_peer = cls;
575 struct GNUNET_RPS_Handle *rps = ca_result;
577 rps_peer->rps_handle = rps;
578 rps_peer->online = GNUNET_YES;
581 GNUNET_assert (op == rps_peer->op);
584 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
585 "Failed to connect to RPS service: %s\n",
588 GNUNET_SCHEDULER_shutdown ();
592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
594 cur_test_run.main_test (rps_peer);
599 * Adapter function called to establish a connection to
603 * @param cfg configuration of the peer to connect to; will be available until
604 * GNUNET_TESTBED_operation_done() is called on the operation returned
605 * from GNUNET_TESTBED_service_connect()
606 * @return service handle to return in 'op_result', NULL on error
609 rps_connect_adapter (void *cls,
610 const struct GNUNET_CONFIGURATION_Handle *cfg)
612 struct GNUNET_RPS_Handle *h;
614 h = GNUNET_RPS_connect (cfg);
616 if (NULL != cur_test_run.pre_test)
617 cur_test_run.pre_test (cls, h);
624 * Adapter function called to destroy connection to
628 * @param op_result service handle returned from the connect adapter
631 rps_disconnect_adapter (void *cls,
634 struct GNUNET_RPS_Handle *h = op_result;
635 GNUNET_RPS_disconnect (h);
639 /***********************************************************************
640 * Definition of tests
641 ***********************************************************************/
643 // TODO check whether tests can be stopped earlier
645 default_eval_cb (void)
647 return evaluate (rps_peers, num_peers, 1);
657 * Callback to call on receipt of a reply
660 * @param n number of peers
661 * @param recv_peers the received peers
664 default_reply_handle (void *cls,
666 const struct GNUNET_PeerIdentity *recv_peers)
668 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
672 "[%s] got %" PRIu64 " peers:\n",
673 GNUNET_i2s (rps_peer->peer_id),
676 for (i = 0 ; i < n ; i++)
678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
681 GNUNET_i2s (&recv_peers[i]));
683 GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]);
688 * Request random peers.
691 request_peers (void *cls,
692 const struct GNUNET_SCHEDULER_TaskContext *tc)
694 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
696 if (GNUNET_YES == in_shutdown)
698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
699 "Requesting one peer\n");
701 GNUNET_free (GNUNET_RPS_request_peers (rps_peer->rps_handle,
703 cur_test_run.reply_handle,
705 //rps_peer->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, 1, handle_reply, rps_peer);
709 /***********************************
711 ***********************************/
713 mal_pre (void *cls, struct GNUNET_RPS_Handle *h)
715 #ifdef ENABLE_MALICIOUS
716 uint32_t num_mal_peers;
717 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
719 GNUNET_assert (1 >= portion
721 num_mal_peers = round (portion * num_peers);
723 if (rps_peer->index < num_mal_peers)
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
726 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
728 GNUNET_i2s (rps_peer->peer_id),
731 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, rps_peer_ids);
733 #endif /* ENABLE_MALICIOUS */
737 mal_cb (struct RPSPeer *rps_peer)
739 uint32_t num_mal_peers;
741 #ifdef ENABLE_MALICIOUS
742 GNUNET_assert (1 >= portion
744 num_mal_peers = round (portion * num_peers);
746 if (rps_peer->index >= num_mal_peers)
747 { /* It's useless to ask a malicious peer about a random sample -
749 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
750 seed_peers, rps_peer);
751 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
752 request_peers, rps_peer);
754 #endif /* ENABLE_MALICIOUS */
760 unsigned int num_mal_peers;
762 num_mal_peers = round (num_peers * portion);
763 return evaluate (&rps_peers[num_mal_peers],
764 num_peers - (num_mal_peers),
769 /***********************************
771 ***********************************/
773 single_req_cb (struct RPSPeer *rps_peer)
775 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
776 request_peers, rps_peer);
779 /***********************************
781 ***********************************/
783 delay_req_cb (struct RPSPeer *rps_peer)
785 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
786 request_peers, rps_peer);
787 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
788 request_peers, rps_peer);
791 /***********************************
793 ***********************************/
795 seed_cb (struct RPSPeer *rps_peer)
797 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
798 seed_peers, rps_peer);
801 /***********************************
803 ***********************************/
805 seed_big_cb (struct RPSPeer *rps_peer)
807 // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers
810 /***********************************
812 ***********************************/
814 single_peer_seed_cb (struct RPSPeer *rps_peer)
819 /***********************************
821 ***********************************/
823 seed_req_cb (struct RPSPeer *rps_peer)
825 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
826 seed_peers, rps_peer);
827 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15),
828 request_peers, rps_peer);
833 /***********************************
835 ***********************************/
837 req_cancel_cb (struct RPSPeer *rps_peer)
842 /***********************************
844 ***********************************/
846 churn (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
848 struct OpListEntry *entry;
851 double portion_online;
852 unsigned int *permut;
853 double prob_go_offline;
854 double portion_go_online;
855 double portion_go_offline;
858 /* Compute the probability for an online peer to go offline
860 portion_online = num_peers_online * 1.0 / num_peers;
861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
862 "Portion online: %f\n",
864 portion_go_online = ((1 - portion_online) * .5 * .66);
865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
866 "Portion that should go online: %f\n",
868 portion_go_offline = (portion_online + portion_go_online) - .75;
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
870 "Portion that probably goes offline: %f\n",
872 prob_go_offline = portion_go_offline / (portion_online * .5);
873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
874 "Probability of a selected online peer to go offline: %f\n",
877 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
878 (unsigned int) num_peers);
880 /* Go over 50% randomly chosen peers */
881 for (i = 0 ; i < .5 * num_peers ; i++)
885 /* If online, shut down with certain probability */
886 if (GNUNET_YES == rps_peers[j].online)
888 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
891 "%u. selected peer (%u: %s) is online.\n",
894 GNUNET_i2s (rps_peers[j].peer_id));
895 if (prob < prob_go_offline * UINT32_MAX)
897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
899 GNUNET_i2s (rps_peers[j].peer_id));
901 entry = make_oplist_entry ();
904 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
913 /* If offline, restart with certain probability */
914 else if (GNUNET_NO == rps_peers[j].online)
916 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
919 "%u. selected peer (%u: %s) is offline.\n",
922 GNUNET_i2s (rps_peers[j].peer_id));
923 if (prob < .66 * UINT32_MAX)
925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
927 GNUNET_i2s (rps_peers[j].peer_id));
929 entry = make_oplist_entry ();
932 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
942 GNUNET_free (permut);
944 churn_task = GNUNET_SCHEDULER_add_delayed (
945 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
952 profiler_pre (void *cls, struct GNUNET_RPS_Handle *h)
954 //churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
959 /* if (NULL == churn_task)
961 churn_task = GNUNET_SCHEDULER_add_delayed (
962 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
970 * Callback to call on receipt of a reply
973 * @param n number of peers
974 * @param recv_peers the received peers
977 profiler_reply_handle (void *cls,
979 const struct GNUNET_PeerIdentity *recv_peers)
981 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
982 struct RPSPeer *rcv_rps_peer;
987 file_name = "/tmp/rps/received_ids";
988 file_name_dh = "/tmp/rps/diehard_input";
990 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
991 "[%s] got %" PRIu64 " peers:\n",
992 GNUNET_i2s (rps_peer->peer_id),
995 for (i = 0 ; i < n ; i++)
997 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1000 GNUNET_i2s (&recv_peers[i]));
1002 /* GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); */
1005 GNUNET_i2s_full (&recv_peers[i]));
1007 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]);
1009 tofile (file_name_dh,
1011 (uint32_t) rcv_rps_peer->index);
1017 profiler_cb (struct RPSPeer *rps_peer)
1021 /* Churn only at peers that do not request peers for evaluation */
1022 if (NULL == churn_task &&
1023 rps_peer->index != num_peers - 2)
1025 churn_task = GNUNET_SCHEDULER_add_delayed (
1026 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
1031 /* Only request peer ids at one peer.
1032 * (It's the before-last because last one is target of the focussed attack.)
1034 if (rps_peer->index == num_peers - 2)
1036 for (i = 0 ; i < cur_test_run.num_requests ; i++)
1038 GNUNET_SCHEDULER_add_delayed (
1039 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1040 cur_test_run.request_interval * i),
1048 * Function called from #profiler_eval with a filename.
1050 * @param cls closure
1051 * @param filename complete filename (absolute path)
1052 * @return #GNUNET_OK to continue to iterate,
1053 * #GNUNET_NO to stop iteration with no error,
1054 * #GNUNET_SYSERR to abort iteration with error!
1057 file_name_cb (void *cls, const char *filename)
1059 if (NULL != strstr (filename, "sampler_el"))
1061 struct RPS_SamplerElement *s_elem;
1062 struct GNUNET_CRYPTO_AuthKey auth_key;
1063 const char *key_char;
1066 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
1067 tofile (filename, "--------------------------\n");
1069 auth_key = string_to_auth_key (key_char);
1070 s_elem = RPS_sampler_elem_create ();
1071 RPS_sampler_elem_set (s_elem, auth_key);
1073 for (i = 0; i < num_peers; i++)
1075 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
1082 * This is run after the test finished.
1084 * Compute all perfect samples.
1087 profiler_eval (void)
1089 /* Compute perfect sample for each sampler element */
1090 if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL))
1092 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
1099 /***********************************************************************
1100 * /Definition of tests
1101 ***********************************************************************/
1105 * Actual "main" function for the testcase.
1107 * @param cls closure
1108 * @param h the run handle
1109 * @param n_peers number of peers in 'peers'
1110 * @param peers handle to peers run in the testbed
1111 * @param links_succeeded the number of overlay link connection attempts that
1113 * @param links_failed the number of overlay link connection attempts that
1118 struct GNUNET_TESTBED_RunHandle *h,
1119 unsigned int n_peers,
1120 struct GNUNET_TESTBED_Peer **peers,
1121 unsigned int links_succeeded,
1122 unsigned int links_failed)
1125 struct OpListEntry *entry;
1127 testbed_peers = peers;
1128 num_peers_online = 0;
1130 for (i = 0 ; i < num_peers ; i++)
1132 entry = make_oplist_entry ();
1134 entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
1135 GNUNET_TESTBED_PIT_IDENTITY,
1141 // This seems not to work
1142 //if (NULL != strstr (cur_test_run.name, "profiler"))
1144 // churn_task = GNUNET_SCHEDULER_add_delayed (
1145 // GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1150 GNUNET_assert (num_peers == n_peers);
1151 for (i = 0 ; i < n_peers ; i++)
1153 rps_peers[i].index = i;
1155 GNUNET_TESTBED_service_connect (&rps_peers[i],
1158 &rps_connect_complete_cb,
1160 &rps_connect_adapter,
1161 &rps_disconnect_adapter,
1164 GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL);
1169 * Entry point for the testcase, sets up the testbed.
1171 * @param argc unused
1172 * @param argv unused
1173 * @return 0 on success
1176 main (int argc, char *argv[])
1180 cur_test_run.name = "test-rps-default";
1181 cur_test_run.pre_test = NULL;
1182 cur_test_run.reply_handle = default_reply_handle;
1183 cur_test_run.eval_cb = default_eval_cb;
1187 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
1189 if (strstr (argv[0], "malicious") != NULL)
1191 cur_test_run.pre_test = mal_pre;
1192 cur_test_run.main_test = mal_cb;
1193 cur_test_run.eval_cb = mal_eval;
1195 if (strstr (argv[0], "_1") != NULL)
1197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
1198 cur_test_run.name = "test-rps-malicious_1";
1201 else if (strstr (argv[0], "_2") != NULL)
1203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
1204 cur_test_run.name = "test-rps-malicious_2";
1207 else if (strstr (argv[0], "_3") != NULL)
1209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n");
1210 cur_test_run.name = "test-rps-malicious_3";
1215 else if (strstr (argv[0], "_single_req") != NULL)
1217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
1218 cur_test_run.name = "test-rps-single-req";
1219 cur_test_run.main_test = single_req_cb;
1222 else if (strstr (argv[0], "_delayed_reqs") != NULL)
1224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
1225 cur_test_run.name = "test-rps-delayed-reqs";
1226 cur_test_run.main_test = delay_req_cb;
1229 else if (strstr (argv[0], "_seed_big") != NULL)
1231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_SERVER_MAX_MESSAGE_SIZE)\n");
1232 cur_test_run.name = "test-rps-seed-big";
1233 cur_test_run.main_test = seed_big_cb;
1236 else if (strstr (argv[0], "_single_peer_seed") != NULL)
1238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
1239 cur_test_run.name = "test-rps-single-peer-seed";
1240 cur_test_run.main_test = single_peer_seed_cb;
1243 else if (strstr (argv[0], "_seed_request") != NULL)
1245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
1246 cur_test_run.name = "test-rps-seed-request";
1247 cur_test_run.main_test = seed_req_cb;
1250 else if (strstr (argv[0], "_seed") != NULL)
1252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
1253 cur_test_run.name = "test-rps-seed";
1254 cur_test_run.main_test = seed_cb;
1255 cur_test_run.eval_cb = no_eval;
1258 else if (strstr (argv[0], "_req_cancel") != NULL)
1260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
1261 cur_test_run.name = "test-rps-req-cancel";
1262 cur_test_run.main_test = req_cancel_cb;
1265 else if (strstr (argv[0], "profiler") != NULL)
1267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
1268 cur_test_run.name = "test-rps-profiler";
1270 cur_test_run.pre_test = profiler_pre;
1271 cur_test_run.main_test = profiler_cb;
1272 cur_test_run.reply_handle = profiler_reply_handle;
1273 cur_test_run.eval_cb = profiler_eval;
1274 cur_test_run.request_interval = 2;
1275 cur_test_run.num_requests = 50;
1279 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
1280 GNUNET_DISK_directory_create ("/tmp/rps/");
1281 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90);
1284 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
1285 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
1286 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
1289 (void) GNUNET_TESTBED_test_run (cur_test_run.name,
1295 ret_value = cur_test_run.eval_cb();
1297 GNUNET_free (rps_peers );
1298 GNUNET_free (rps_peer_ids);
1299 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
1304 /* end of test_rps_multipeer.c */