compile test to profiler
[oweals/gnunet.git] / src / rps / test_rps.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009, 2012 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20 /**
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.
26  */
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
30 #include "gnunet_rps_service.h"
31
32 #include <inttypes.h>
33
34
35 /**
36  * How many peers do we start?
37  */
38 #define NUM_PEERS 5
39
40 /**
41  * How long do we run the test?
42  */
43 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
44
45
46 /**
47  * Portion of malicious peers
48  */
49 static double portion = .1;
50
51 /**
52  * Type of malicious peer to test
53  */
54 static unsigned int mal_type = 0;
55
56 /**
57  * Handles to all of the running peers
58  */
59 static struct GNUNET_TESTBED_Peer **testbed_peers;
60
61
62 /**
63  * Operation map entry
64  */
65 struct OpListEntry
66 {
67   /**
68    * DLL next ptr
69    */
70   struct OpListEntry *next;
71
72   /**
73    * DLL prev ptr
74    */
75   struct OpListEntry *prev;
76
77   /**
78    * The testbed operation
79    */
80   struct GNUNET_TESTBED_Operation *op;
81
82   /**
83    * Depending on whether we start or stop NSE service at the peer set this to 1
84    * or -1
85    */
86   int delta;
87
88   /**
89    * Index of the regarding peer
90    */
91   unsigned int index;
92 };
93
94 /**
95  * OpList DLL head
96  */
97 static struct OpListEntry *oplist_head;
98
99 /**
100  * OpList DLL tail
101  */
102 static struct OpListEntry *oplist_tail;
103
104
105 /**
106  * Information we track for each peer.
107  */
108 struct RPSPeer
109 {
110   /**
111    * Index of the peer.
112    */
113   unsigned int index;
114
115   /**
116    * Handle for RPS connect operation.
117    */
118   struct GNUNET_TESTBED_Operation *op;
119
120   /**
121    * Handle to RPS service.
122    */
123   struct GNUNET_RPS_Handle *rps_handle;
124
125   /**
126    * ID of the peer.
127    */
128   struct GNUNET_PeerIdentity *peer_id;
129
130   /**
131    * A request handle to check for an request
132    */
133   //struct GNUNET_RPS_Request_Handle *req_handle;
134
135   /**
136    * Peer on- or offline?
137    */
138   int online;
139
140   /**
141    * Received PeerIDs
142    */
143   struct GNUNET_PeerIdentity *rec_ids;
144
145   /**
146    * Number of received PeerIDs
147    */
148   unsigned int num_rec_ids;
149 };
150
151
152 /**
153  * Information for all the peers.
154  */
155 static struct RPSPeer rps_peers[NUM_PEERS];
156
157 /**
158  * IDs of the peers.
159  */
160 static struct GNUNET_PeerIdentity rps_peer_ids[NUM_PEERS];
161
162 /**
163  * Number of online peers.
164  */
165 static unsigned int num_peers_online;
166
167 /**
168  * Return value from 'main'.
169  */
170 static int ok;
171
172
173 /**
174  * Identifier for the churn task that runs periodically
175  */
176 static struct GNUNET_SCHEDULER_Task *churn_task;
177
178
179 /**
180  * Called directly after connecting to the service
181  */
182 typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h);
183
184 /**
185  * Called from within #rps_connect_complete_cb ()
186  * Executes functions to test the api/service
187  */
188 typedef void (*MainTest) (struct RPSPeer *rps_peer);
189
190 /**
191  * Called directly before disconnecting from the service
192  */
193 typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h);
194
195 /**
196  * Function called after disconnect to evaluate test success
197  */
198 typedef int (*EvaluationCallback) (void);
199
200
201 /**
202  * Structure to define a single test
203  */
204 struct SingleTestRun
205 {
206   /**
207    * Called directly after connecting to the service
208    */
209   PreTest pre_test;
210
211   /**
212    * Function to execute the functions to be tested
213    */
214   MainTest main_test;
215
216   /**
217    * Called directly before disconnecting from the service
218    */
219   PostTest post_test;
220
221   /**
222    * Function to evaluate the test results
223    */
224   EvaluationCallback eval_cb;
225 } cur_test_run;
226
227
228 /**
229  * Test the success of a single test
230  */
231 static int
232 evaluate (struct RPSPeer *loc_rps_peers,
233           unsigned int num_loc_rps_peers,
234           unsigned int expected_recv)
235 {
236   unsigned int i;
237   int tmp_ok;
238
239   tmp_ok = (1 == loc_rps_peers[0].num_rec_ids);
240
241   for (i = 0 ; i < num_loc_rps_peers ; i++)
242   {
243     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
244                 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
245                 i,
246                 GNUNET_i2s (loc_rps_peers[i].peer_id),
247                 loc_rps_peers[i].num_rec_ids,
248                 expected_recv,
249                 (1 == loc_rps_peers[i].num_rec_ids));
250     tmp_ok &= (1 == loc_rps_peers[i].num_rec_ids);
251   }
252   return tmp_ok? 0 : 1;
253 }
254
255
256 /**
257  * Creates an oplist entry and adds it to the oplist DLL
258  */
259 static struct OpListEntry *
260 make_oplist_entry ()
261 {
262   struct OpListEntry *entry;
263
264   entry = GNUNET_new (struct OpListEntry);
265   GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
266   return entry;
267 }
268
269
270 /**
271  * Callback to be called when NSE service is started or stopped at peers
272  *
273  * @param cls NULL
274  * @param op the operation handle
275  * @param emsg NULL on success; otherwise an error description
276  */
277 static void
278 churn_cb (void *cls,
279                    struct GNUNET_TESTBED_Operation *op,
280                    const char *emsg)
281 {
282   struct OpListEntry *entry = cls;
283
284   GNUNET_TESTBED_operation_done (entry->op);
285   if (NULL != emsg)
286   {
287     //LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop NSE at a peer\n");
288     GNUNET_SCHEDULER_shutdown ();
289     return;
290   }
291   GNUNET_assert (0 != entry->delta);
292
293   num_peers_online += entry->delta;
294
295   if (0 < entry->delta)
296   { /* Peer hopefully just went online */
297     GNUNET_break (GNUNET_NO == rps_peers[entry->index].online);
298     rps_peers[entry->index].online = GNUNET_YES;
299   }
300   else if (0 > entry->delta)
301   { /* Peer hopefully just went offline */
302     GNUNET_break (GNUNET_YES == rps_peers[entry->index].online);
303     rps_peers[entry->index].online = GNUNET_NO;
304   }
305
306   GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
307   GNUNET_free (entry);
308   //if (num_peers_in_round[current_round] == peers_running)
309   //  run_round ();
310 }
311
312
313 /**
314  * Task run on timeout to shut everything down.
315  */
316 static void
317 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
318 {
319   unsigned int i;
320
321   for (i=0;i<NUM_PEERS;i++)
322     GNUNET_TESTBED_operation_done (rps_peers[i].op);
323   GNUNET_SCHEDULER_shutdown ();
324 }
325
326
327 /**
328  * Callback to call on receipt of a reply
329  *
330  * @param cls closure
331  * @param n number of peers
332  * @param recv_peers the received peers
333  */
334 static void
335 handle_reply (void *cls, uint64_t n, const struct GNUNET_PeerIdentity *recv_peers)
336 {
337   struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
338   unsigned int i;
339
340   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341               "[%s] got %" PRIu64 " peers:\n",
342               GNUNET_i2s (rps_peer->peer_id),
343               n);
344   
345   for (i = 0 ; i < n ; i++)
346   {
347     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
348                 "%u: %s\n",
349                 i,
350                 GNUNET_i2s (&recv_peers[i]));
351
352     GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]);
353   }
354 }
355
356
357 /**
358  * Request random peers.
359  */
360   void
361 request_peers (void *cls,
362                const struct GNUNET_SCHEDULER_TaskContext *tc)
363 {
364   struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
365
366   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
367               "Requesting one peer\n");
368
369   (void) GNUNET_RPS_request_peers (rps_peer->rps_handle, 1, handle_reply, rps_peer);
370   //rps_peer->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, 1, handle_reply, rps_peer);
371 }
372
373
374 /**
375  * Seed peers.
376  */
377   void
378 seed_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
379 {
380   unsigned int amount;
381   struct RPSPeer *peer = (struct RPSPeer *) cls;
382   unsigned int i;
383
384   // TODO if malicious don't seed mal peers
385   amount = round (.5 * NUM_PEERS);
386
387   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
388   for (i = 0 ; i < amount ; i++)
389     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
390                 i,
391                 GNUNET_i2s (&rps_peer_ids[i]));
392
393   GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
394 }
395
396
397 /**
398  * Get the id of peer i.
399  */
400   void
401 info_cb (void *cb_cls,
402          struct GNUNET_TESTBED_Operation *op,
403          const struct GNUNET_TESTBED_PeerInformation *pinfo,
404          const char *emsg)
405 {
406   unsigned int i = *((unsigned int *) cb_cls);
407
408   if (NULL == pinfo || NULL != emsg)
409   {
410     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
411     return;
412   }
413
414   GNUNET_free (cb_cls);
415
416   rps_peer_ids[i] = *(pinfo->result.id);
417   rps_peers[i].peer_id = &rps_peer_ids[i];
418   rps_peers[i].rec_ids = NULL;
419   rps_peers[i].num_rec_ids = 0;
420
421 }
422
423
424 /**
425  * Callback to be called when RPS service connect operation is completed
426  *
427  * @param cls the callback closure from functions generating an operation
428  * @param op the operation that has been finished
429  * @param ca_result the RPS service handle returned from rps_connect_adapter
430  * @param emsg error message in case the operation has failed; will be NULL if
431  *          operation has executed successfully.
432  */
433 static void
434 rps_connect_complete_cb (void *cls,
435                          struct GNUNET_TESTBED_Operation *op,
436                          void *ca_result,
437                          const char *emsg)
438 {
439   struct RPSPeer *rps_peer = cls;
440   struct GNUNET_RPS_Handle *rps = ca_result;
441
442   rps_peer->rps_handle = rps;
443   rps_peer->online = GNUNET_YES;
444   num_peers_online++;
445
446   GNUNET_assert (op == rps_peer->op);
447   if (NULL != emsg)
448   {
449     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
450                 "Failed to connect to RPS service: %s\n",
451                 emsg);
452     ok = 1;
453     GNUNET_SCHEDULER_shutdown ();
454     return;
455   }
456
457   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
458
459   cur_test_run.main_test (rps_peer);
460 }
461
462
463 /**
464  * Adapter function called to establish a connection to
465  * the RPS service.
466  *
467  * @param cls closure
468  * @param cfg configuration of the peer to connect to; will be available until
469  *          GNUNET_TESTBED_operation_done() is called on the operation returned
470  *          from GNUNET_TESTBED_service_connect()
471  * @return service handle to return in 'op_result', NULL on error
472  */
473 static void *
474 rps_connect_adapter (void *cls,
475                                  const struct GNUNET_CONFIGURATION_Handle *cfg)
476 {
477   struct GNUNET_RPS_Handle *h;
478
479   h = GNUNET_RPS_connect (cfg);
480
481   if (NULL != cur_test_run.pre_test)
482     cur_test_run.pre_test (cls, h);
483
484   return h;
485 }
486
487
488 /**
489  * Adapter function called to destroy connection to
490  * RPS service.
491  *
492  * @param cls closure
493  * @param op_result service handle returned from the connect adapter
494  */
495 static void
496 rps_disconnect_adapter (void *cls,
497                                           void *op_result)
498 {
499   struct GNUNET_RPS_Handle *h = op_result;
500   GNUNET_RPS_disconnect (h);
501 }
502
503
504 /***********************************************************************
505  * Definition of tests
506 ***********************************************************************/
507
508 static int
509 default_eval_cb (void)
510 {
511   return evaluate (rps_peers, NUM_PEERS, 1);
512 }
513 /***********************************
514  * MALICIOUS
515 ***********************************/
516 static void
517 mal_pre (void *cls, struct GNUNET_RPS_Handle *h)
518 {
519   #ifdef ENABLE_MALICIOUS
520   uint32_t num_mal_peers;
521   struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
522
523   GNUNET_assert (1 >= portion
524                  && 0 <  portion);
525   num_mal_peers = round (portion * NUM_PEERS);
526
527   if (rps_peer->index < num_mal_peers)
528   {
529     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
530                 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
531                 rps_peer->index,
532                 GNUNET_i2s (rps_peer->peer_id),
533                 num_mal_peers);
534
535     GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, rps_peer_ids);
536   }
537   #endif /* ENABLE_MALICIOUS */
538 }
539
540 static void
541 mal_cb (struct RPSPeer *rps_peer)
542 {
543   uint32_t num_mal_peers;
544
545   #ifdef ENABLE_MALICIOUS
546   GNUNET_assert (1 >= portion
547                  && 0 <  portion);
548   num_mal_peers = round (portion * NUM_PEERS);
549
550   if (rps_peer->index >= num_mal_peers)
551   { /* It's useless to ask a malicious peer about a random sample -
552        it's not sampling */
553     GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
554                                   seed_peers, rps_peer);
555     GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
556                                   request_peers, rps_peer);
557   }
558   #endif /* ENABLE_MALICIOUS */
559 }
560
561 static int
562 mal_eval (void)
563 {
564   unsigned int num_mal_peers;
565
566   num_mal_peers = round (NUM_PEERS * portion);
567   return evaluate (&rps_peers[num_mal_peers],
568                    NUM_PEERS - (num_mal_peers),
569                    1);
570 }
571
572
573 /***********************************
574  * SINGLE_REQUEST
575 ***********************************/
576 static void
577 single_req_cb (struct RPSPeer *rps_peer)
578 {
579   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
580                                 request_peers, rps_peer);
581 }
582
583 /***********************************
584  * DELAYED_REQUESTS
585 ***********************************/
586 static void
587 delay_req_cb (struct RPSPeer *rps_peer)
588 {
589   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
590                                 request_peers, rps_peer);
591   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
592                                 request_peers, rps_peer);
593 }
594
595 /***********************************
596  * SEED
597 ***********************************/
598 static void
599 seed_cb (struct RPSPeer *rps_peer)
600 {
601   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
602                                 seed_peers, rps_peer);
603 }
604
605 static int
606 seed_eval (void)
607 {
608   return 1;
609 }
610
611 /***********************************
612  * SEED_BIG
613 ***********************************/
614 static void
615 seed_big_cb (struct RPSPeer *rps_peer)
616 {
617   // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers
618 }
619
620 /***********************************
621  * SINGLE_PEER_SEED
622 ***********************************/
623 static void
624 single_peer_seed_cb (struct RPSPeer *rps_peer)
625 {
626   // TODO
627 }
628
629 /***********************************
630  * SEED_REQUEST
631 ***********************************/
632 static void
633 seed_req_cb (struct RPSPeer *rps_peer)
634 {
635   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
636                                 seed_peers, rps_peer);
637   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15),
638                                 request_peers, rps_peer);
639 }
640
641 //TODO start big mal
642
643 /***********************************
644  * REQUEST_CANCEL
645 ***********************************/
646 static void
647 req_cancel_cb (struct RPSPeer *rps_peer)
648 {
649   // TODO
650 }
651
652 /***********************************
653  * PROFILER
654 ***********************************/
655 static void
656 churn (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
657 {
658   struct OpListEntry *entry;
659   unsigned int i;
660   unsigned int j;
661   double portion_online;
662   unsigned int *permut;
663   double prob_go_offline;
664   double portion_go_online;
665   double portion_go_offline;
666   uint32_t prob;
667
668   portion_online = num_peers_online / NUM_PEERS;
669   portion_go_online = ((1 - portion_online) * .5 * .66);
670   portion_go_offline = (portion_online + portion_go_online) - .75;
671   prob_go_offline = portion_go_offline / (portion_online * .5);
672
673   permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
674                                          (unsigned int) NUM_PEERS);
675
676   for (i = 0 ; i < .5 * NUM_PEERS ; i++)
677   {
678     j = permut[i];
679
680     if (GNUNET_YES == rps_peers[j].online)
681     {
682        prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
683                                         UINT32_MAX);
684       if (prob < prob_go_offline * UINT32_MAX)
685       {
686         entry = make_oplist_entry ();
687         entry->delta = 1;
688         entry->index = j;
689         entry->op =  GNUNET_TESTBED_peer_manage_service (NULL,
690                                                          testbed_peers[j],
691                                                          "rps",
692                                                          &churn_cb,
693                                                          entry,
694                                                          1);
695       }
696    }
697
698     else if (GNUNET_NO == rps_peers[j].online)
699     {
700       prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
701                                        UINT32_MAX);
702       if (prob < .66 * UINT32_MAX)
703       {
704         entry = make_oplist_entry ();
705         entry->delta = -1;
706         entry->index = j;
707         entry->op =  GNUNET_TESTBED_peer_manage_service (NULL,
708                                                          testbed_peers[j],
709                                                          "rps",
710                                                          &churn_cb,
711                                                          entry,
712                                                          0);
713       }
714     }
715   }
716
717   churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
718                                                                             10),
719                                              churn, NULL);
720 }
721
722 static void
723 profiler_pre (void *cls, struct GNUNET_RPS_Handle *h)
724 {
725   churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
726                                                                             10),
727                                              churn, NULL);
728   mal_pre (cls, h);
729 }
730
731 static void
732 profiler_cb (struct RPSPeer *rps_peer)
733 {
734   // We're not requesting peers
735   // TODO maybe seed
736 }
737
738
739 /***********************************************************************
740  * /Definition of tests
741 ***********************************************************************/
742
743
744 /**
745  * Actual "main" function for the testcase.
746  *
747  * @param cls closure
748  * @param h the run handle
749  * @param num_peers number of peers in 'peers'
750  * @param peers handle to peers run in the testbed
751  * @param links_succeeded the number of overlay link connection attempts that
752  *          succeeded
753  * @param links_failed the number of overlay link connection attempts that
754  *          failed
755  */
756 static void
757 run (void *cls,
758      struct GNUNET_TESTBED_RunHandle *h,
759      unsigned int num_peers,
760      struct GNUNET_TESTBED_Peer **peers,
761      unsigned int links_succeeded,
762      unsigned int links_failed)
763 {
764   unsigned int i;
765   unsigned int *tmp_i;
766
767   testbed_peers = peers;
768   num_peers_online = 0;
769
770   for (i = 0 ; i < NUM_PEERS ; i++)
771   {
772     tmp_i = GNUNET_new (unsigned int);
773     *tmp_i = i;
774
775     (void) GNUNET_TESTBED_peer_get_information (peers[i],
776                                                 GNUNET_TESTBED_PIT_IDENTITY,
777                                                 &info_cb,
778                                                 tmp_i);
779   }
780
781   GNUNET_assert (NUM_PEERS == num_peers);
782   for (i = 0 ; i < num_peers ; i++)
783   {
784     rps_peers[i].index = i;
785     rps_peers[i].op =
786       GNUNET_TESTBED_service_connect (&rps_peers[i],
787                                                                           peers[i],
788                                                                           "rps",
789                                                                           &rps_connect_complete_cb,
790                                                                           &rps_peers[i],
791                                                                           &rps_connect_adapter,
792                                                                           &rps_disconnect_adapter,
793                                                                           &rps_peers[i]);
794   }
795   GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
796 }
797
798
799 /**
800  * Entry point for the testcase, sets up the testbed.
801  *
802  * @param argc unused
803  * @param argv unused
804  * @return 0 on success
805  */
806 int
807 main (int argc, char *argv[])
808 {
809   cur_test_run.pre_test = NULL;
810   cur_test_run.eval_cb = default_eval_cb;
811   churn_task = NULL;
812
813   if (strstr (argv[0], "malicious") != NULL)
814   {
815     cur_test_run.pre_test = mal_pre;
816     cur_test_run.main_test = mal_cb;
817     cur_test_run.eval_cb = mal_eval;
818
819     if (strstr (argv[0], "_1") != NULL)
820     {
821       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
822       mal_type = 1;
823     }
824     else if (strstr (argv[0], "_2") != NULL)
825     {
826       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
827       mal_type = 2;
828     }
829     else if (strstr (argv[0], "_3") != NULL)
830     {
831       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n");
832       mal_type = 3;
833     }
834   }
835
836   else if (strstr (argv[0], "_single_req") != NULL)
837   {
838     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
839     cur_test_run.main_test = single_req_cb;
840   }
841   else if (strstr (argv[0], "_delayed_reqs") != NULL)
842   {
843     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
844     cur_test_run.main_test = delay_req_cb;
845   }
846   else if (strstr (argv[0], "_seed_big") != NULL)
847   {
848     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_SERVER_MAX_MESSAGE_SIZE)\n");
849     cur_test_run.main_test = seed_big_cb;
850   }
851   else if (strstr (argv[0], "_single_peer_seed") != NULL)
852   {
853     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
854     cur_test_run.main_test = single_peer_seed_cb;
855   }
856   else if (strstr (argv[0], "_seed_request") != NULL)
857   {
858     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
859     cur_test_run.main_test = seed_req_cb;
860   }
861   else if (strstr (argv[0], "_seed") != NULL)
862   {
863     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
864     cur_test_run.main_test = seed_cb;
865     cur_test_run.eval_cb = seed_eval;
866   }
867   else if (strstr (argv[0], "_req_cancel") != NULL)
868   {
869     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
870     cur_test_run.main_test = req_cancel_cb;
871   }
872   else if (strstr (argv[0], "profiler") != NULL)
873   {
874     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
875     mal_type = 3;
876     cur_test_run.pre_test = profiler_pre;
877     cur_test_run.main_test = profiler_cb;
878     churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
879                                                                               10),
880                                                churn, NULL);
881   }
882
883   ok = 1;
884   (void) GNUNET_TESTBED_test_run ("test-rps-multipeer",
885                                   "test_rps.conf",
886                                   NUM_PEERS,
887                                   0, NULL, NULL,
888                                   &run, NULL);
889
890   if (NULL != churn_task)
891     GNUNET_SCHEDULER_cancel (churn_task);
892
893   return cur_test_run.eval_cb();
894 }
895
896 /* end of test_rps_multipeer.c */