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