146be4c2c2403466b6e93318bf332de616d5c206
[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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, 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
31 #include "gnunet_rps_service.h"
32 #include "rps-test_util.h"
33 #include "gnunet-service-rps_sampler_elem.h"
34
35 #include <inttypes.h>
36
37
38 /**
39  * How many peers do we start?
40  */
41 uint32_t num_peers;
42
43 /**
44  * How long do we run the test?
45  */
46 //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
47 static struct GNUNET_TIME_Relative timeout;
48
49
50 /**
51  * Portion of malicious peers
52  */
53 static double portion = .1;
54
55 /**
56  * Type of malicious peer to test
57  */
58 static unsigned int mal_type = 0;
59
60 /**
61  * Handles to all of the running peers
62  */
63 static struct GNUNET_TESTBED_Peer **testbed_peers;
64
65
66 /**
67  * Operation map entry
68  */
69 struct OpListEntry
70 {
71   /**
72    * DLL next ptr
73    */
74   struct OpListEntry *next;
75
76   /**
77    * DLL prev ptr
78    */
79   struct OpListEntry *prev;
80
81   /**
82    * The testbed operation
83    */
84   struct GNUNET_TESTBED_Operation *op;
85
86   /**
87    * Depending on whether we start or stop NSE service at the peer set this to 1
88    * or -1
89    */
90   int delta;
91
92   /**
93    * Index of the regarding peer
94    */
95   unsigned int index;
96 };
97
98 /**
99  * OpList DLL head
100  */
101 static struct OpListEntry *oplist_head;
102
103 /**
104  * OpList DLL tail
105  */
106 static struct OpListEntry *oplist_tail;
107
108
109 /**
110  * A pending reply: A request was sent and the reply is pending.
111  */
112 struct PendingReply
113 {
114   /**
115    * DLL next,prev ptr
116    */
117   struct PendingReply *next;
118   struct PendingReply *prev;
119
120   /**
121    * Handle to the request we are waiting for
122    */
123   struct GNUNET_RPS_Request_Handle *req_handle;
124
125   /**
126    * The peer that requested
127    */
128   struct RPSPeer *rps_peer;
129 };
130
131
132 /**
133  * A pending request: A request was not made yet but is scheduled for later.
134  */
135 struct PendingRequest
136 {
137   /**
138    * DLL next,prev ptr
139    */
140   struct PendingRequest *next;
141   struct PendingRequest *prev;
142
143   /**
144    * Handle to the request we are waiting for
145    */
146   struct GNUNET_SCHEDULER_Task *request_task;
147
148   /**
149    * The peer that requested
150    */
151   struct RPSPeer *rps_peer;
152 };
153
154
155 /**
156  * Information we track for each peer.
157  */
158 struct RPSPeer
159 {
160   /**
161    * Index of the peer.
162    */
163   unsigned int index;
164
165   /**
166    * Handle for RPS connect operation.
167    */
168   struct GNUNET_TESTBED_Operation *op;
169
170   /**
171    * Handle to RPS service.
172    */
173   struct GNUNET_RPS_Handle *rps_handle;
174
175   /**
176    * ID of the peer.
177    */
178   struct GNUNET_PeerIdentity *peer_id;
179
180   /**
181    * A request handle to check for an request
182    */
183   //struct GNUNET_RPS_Request_Handle *req_handle;
184
185   /**
186    * Peer on- or offline?
187    */
188   int online;
189
190   /**
191    * Number of Peer IDs to request
192    */
193   unsigned int num_ids_to_request;
194
195   /**
196    * Pending requests DLL
197    */
198   struct PendingRequest *pending_req_head;
199   struct PendingRequest *pending_req_tail;
200
201   /**
202    * Number of pending requests
203    */
204   unsigned int num_pending_reqs;
205
206   /**
207    * Pending replies DLL
208    */
209   struct PendingReply *pending_rep_head;
210   struct PendingReply *pending_rep_tail;
211
212   /**
213    * Number of pending replies
214    */
215   unsigned int num_pending_reps;
216
217   /**
218    * Number of received PeerIDs
219    */
220   unsigned int num_recv_ids;
221 };
222
223
224 /**
225  * Information for all the peers.
226  */
227 static struct RPSPeer *rps_peers;
228
229 /**
230  * Peermap to get the index of a given peer ID quick.
231  */
232 static struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
233
234 /**
235  * IDs of the peers.
236  */
237 static struct GNUNET_PeerIdentity *rps_peer_ids;
238
239 /**
240  * ID of the targeted peer.
241  */
242 static struct GNUNET_PeerIdentity *target_peer;
243
244 /**
245  * ID of the peer that requests for the evaluation.
246  */
247 static struct RPSPeer *eval_peer;
248
249 /**
250  * Number of online peers.
251  */
252 static unsigned int num_peers_online;
253
254 /**
255  * Return value from 'main'.
256  */
257 static int ok;
258
259
260 /**
261  * Identifier for the churn task that runs periodically
262  */
263 static struct GNUNET_SCHEDULER_Task *churn_task;
264
265 /**
266  * Identifier for the churn task that runs periodically
267  */
268 static struct GNUNET_SCHEDULER_Task *shutdown_task;
269
270
271 /**
272  * Called to initialise the given RPSPeer
273  */
274 typedef void (*InitPeer) (struct RPSPeer *rps_peer);
275
276 /**
277  * Called directly after connecting to the service
278  */
279 typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h);
280
281 /**
282  * Called from within #rps_connect_complete_cb ()
283  * Executes functions to test the api/service
284  */
285 typedef void (*MainTest) (struct RPSPeer *rps_peer);
286
287 /**
288  * Callback called once the requested random peers are available
289  */
290 typedef void (*ReplyHandle) (void *cls,
291                              uint64_t n,
292                              const struct GNUNET_PeerIdentity *recv_peers);
293
294 /**
295  * Called directly before disconnecting from the service
296  */
297 typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h);
298
299 /**
300  * Function called after disconnect to evaluate test success
301  */
302 typedef int (*EvaluationCallback) (void);
303
304
305 /**
306  * Structure to define a single test
307  */
308 struct SingleTestRun
309 {
310   /**
311    * Name of the test
312    */
313   char *name;
314
315   /**
316    * Called to initialise peer
317    */
318   InitPeer init_peer;
319
320   /**
321    * Called directly after connecting to the service
322    */
323   PreTest pre_test;
324
325   /**
326    * Function to execute the functions to be tested
327    */
328   MainTest main_test;
329
330   /**
331    * Callback called once the requested peers are available
332    */
333   ReplyHandle reply_handle;
334
335   /**
336    * Called directly before disconnecting from the service
337    */
338   PostTest post_test;
339
340   /**
341    * Function to evaluate the test results
342    */
343   EvaluationCallback eval_cb;
344
345   /**
346    * Request interval
347    */
348   uint32_t request_interval;
349
350   /**
351    * Number of Requests to make.
352    */
353   uint32_t num_requests;
354 } cur_test_run;
355
356 /**
357  * Are we shutting down?
358  */
359 static int in_shutdown;
360
361 /**
362  * Append arguments to file
363  */
364 static void
365 tofile_ (const char *file_name, char *line)
366 {
367   struct GNUNET_DISK_FileHandle *f;
368   /* char output_buffer[512]; */
369   size_t size;
370   /* int size; */
371   size_t size2;
372
373   if (NULL == (f = GNUNET_DISK_file_open (file_name,
374                                           GNUNET_DISK_OPEN_APPEND |
375                                           GNUNET_DISK_OPEN_WRITE |
376                                           GNUNET_DISK_OPEN_CREATE,
377                                           GNUNET_DISK_PERM_USER_READ |
378                                           GNUNET_DISK_PERM_USER_WRITE |
379                                           GNUNET_DISK_PERM_GROUP_READ |
380                                           GNUNET_DISK_PERM_OTHER_READ)))
381   {
382     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
383                 "Not able to open file %s\n",
384                 file_name);
385     return;
386   }
387   /* size = GNUNET_snprintf (output_buffer,
388                           sizeof (output_buffer),
389                           "%llu %s\n",
390                           GNUNET_TIME_absolute_get ().abs_value_us,
391                           line);
392   if (0 > size)
393   {
394     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
395                 "Failed to write string to buffer (size: %i)\n",
396                 size);
397     return;
398   } */
399
400   size = strlen (line) * sizeof (char);
401
402   size2 = GNUNET_DISK_file_write (f, line, size);
403   if (size != size2)
404   {
405     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
406                 "Unable to write to file! (Size: %u, size2: %u)\n",
407                 size,
408                 size2);
409     return;
410   }
411
412   if (GNUNET_YES != GNUNET_DISK_file_close (f))
413     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
414                 "Unable to close file\n");
415 }
416
417 /**
418  * This function is used to facilitate writing important information to disk
419  */
420 #define tofile(file_name, ...) do {\
421   char tmp_buf[512];\
422     int size;\
423     size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
424     if (0 > size)\
425       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
426                      "Failed to create tmp_buf\n");\
427     else\
428       tofile_(file_name,tmp_buf);\
429   } while (0);
430
431
432 /**
433  * Write the ids and their according index in the given array to a file 
434  * Unused
435  */
436 /* static void
437 ids_to_file (char *file_name,
438              struct GNUNET_PeerIdentity *peer_ids,
439              unsigned int num_peer_ids)
440 {
441   unsigned int i;
442
443   for (i=0 ; i < num_peer_ids ; i++)
444   {
445     to_file (file_name,
446              "%u\t%s",
447              i,
448              GNUNET_i2s_full (&peer_ids[i]));
449   }
450 } */
451
452 /**
453  * Test the success of a single test
454  */
455 static int
456 evaluate (void)
457 {
458   unsigned int i;
459   int tmp_ok;
460
461   tmp_ok = 1;
462
463   for (i = 0; i < num_peers; i++)
464   {
465     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
466         "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
467         i,
468         GNUNET_i2s (rps_peers[i].peer_id),
469         rps_peers[i].num_recv_ids,
470         rps_peers[i].num_ids_to_request,
471         (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids));
472     tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids);
473   }
474   return tmp_ok? 0 : 1;
475 }
476
477
478 /**
479  * Creates an oplist entry and adds it to the oplist DLL
480  */
481 static struct OpListEntry *
482 make_oplist_entry ()
483 {
484   struct OpListEntry *entry;
485
486   entry = GNUNET_new (struct OpListEntry);
487   GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
488   return entry;
489 }
490
491
492 /**
493  * Task run on timeout to shut everything down.
494  */
495 static void
496 shutdown_op (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
497 {
498   unsigned int i;
499
500   in_shutdown = GNUNET_YES;
501   if (NULL != churn_task)
502     GNUNET_SCHEDULER_cancel (churn_task);
503
504   for (i = 0 ; i < num_peers ; i++)
505     GNUNET_TESTBED_operation_done (rps_peers[i].op);
506   GNUNET_SCHEDULER_shutdown ();
507 }
508
509
510 /**
511  * Seed peers.
512  */
513   void
514 seed_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
515 {
516   unsigned int amount;
517   struct RPSPeer *peer = (struct RPSPeer *) cls;
518   unsigned int i;
519
520   // TODO if malicious don't seed mal peers
521   amount = round (.5 * num_peers);
522
523   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
524   for (i = 0 ; i < amount ; i++)
525     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
526                 i,
527                 GNUNET_i2s (&rps_peer_ids[i]));
528
529   GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
530 }
531
532
533 /**
534  * Get the id of peer i.
535  */
536   void
537 info_cb (void *cb_cls,
538          struct GNUNET_TESTBED_Operation *op,
539          const struct GNUNET_TESTBED_PeerInformation *pinfo,
540          const char *emsg)
541 {
542   struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
543
544   if (NULL == pinfo || NULL != emsg)
545   {
546     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
547     return;
548   }
549
550   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
551               "Peer %u is %s\n",
552               entry->index,
553               GNUNET_i2s (pinfo->result.id));
554
555   rps_peer_ids[entry->index] = *(pinfo->result.id);
556   rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
557   rps_peers[entry->index].rec_ids = NULL;
558   rps_peers[entry->index].num_rec_ids = 0;
559
560   GNUNET_CONTAINER_multipeermap_put (peer_map,
561       &rps_peer_ids[entry->index],
562       &rps_peers[entry->index],
563       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
564   tofile ("/tmp/rps/peer_ids",
565            "%u\t%s\n",
566            entry->index,
567            GNUNET_i2s_full (&rps_peer_ids[entry->index]));
568
569   if (NULL != cur_test_run.init_peer)
570     cur_test_run.init_peer (&rps_peers[entry->index]);
571
572   GNUNET_TESTBED_operation_done (entry->op);
573   GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
574   GNUNET_free (entry);
575 }
576
577
578 /**
579  * Callback to be called when RPS service connect operation is completed
580  *
581  * @param cls the callback closure from functions generating an operation
582  * @param op the operation that has been finished
583  * @param ca_result the RPS service handle returned from rps_connect_adapter
584  * @param emsg error message in case the operation has failed; will be NULL if
585  *          operation has executed successfully.
586  */
587 static void
588 rps_connect_complete_cb (void *cls,
589                          struct GNUNET_TESTBED_Operation *op,
590                          void *ca_result,
591                          const char *emsg)
592 {
593   struct RPSPeer *rps_peer = cls;
594   struct GNUNET_RPS_Handle *rps = ca_result;
595
596   rps_peer->rps_handle = rps;
597   rps_peer->online = GNUNET_YES;
598   num_peers_online++;
599
600   GNUNET_assert (op == rps_peer->op);
601   if (NULL != emsg)
602   {
603     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
604                 "Failed to connect to RPS service: %s\n",
605                 emsg);
606     ok = 1;
607     GNUNET_SCHEDULER_shutdown ();
608     return;
609   }
610
611   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
612
613   cur_test_run.main_test (rps_peer);
614 }
615
616
617 /**
618  * Adapter function called to establish a connection to
619  * the RPS service.
620  *
621  * @param cls closure
622  * @param cfg configuration of the peer to connect to; will be available until
623  *          GNUNET_TESTBED_operation_done() is called on the operation returned
624  *          from GNUNET_TESTBED_service_connect()
625  * @return service handle to return in 'op_result', NULL on error
626  */
627 static void *
628 rps_connect_adapter (void *cls,
629                                  const struct GNUNET_CONFIGURATION_Handle *cfg)
630 {
631   struct GNUNET_RPS_Handle *h;
632
633   h = GNUNET_RPS_connect (cfg);
634
635   if (NULL != cur_test_run.pre_test)
636     cur_test_run.pre_test (cls, h);
637
638   return h;
639 }
640
641
642 /**
643  * Adapter function called to destroy connection to
644  * RPS service.
645  *
646  * @param cls closure
647  * @param op_result service handle returned from the connect adapter
648  */
649 static void
650 rps_disconnect_adapter (void *cls,
651                                           void *op_result)
652 {
653   struct RPSPeer *peer = cls;
654   struct GNUNET_RPS_Handle *h = op_result;
655   GNUNET_assert (NULL != peer);
656   GNUNET_RPS_disconnect (h);
657   peer->rps_handle = NULL;
658 }
659
660
661 /***********************************************************************
662  * Definition of tests
663 ***********************************************************************/
664
665 // TODO check whether tests can be stopped earlier
666 static int
667 default_eval_cb (void)
668 {
669   return evaluate ();
670 }
671
672 static int
673 no_eval (void)
674 {
675   return 0;
676 }
677
678 /**
679  * Initialise given RPSPeer
680  */
681 static void default_init_peer (struct RPSPeer *rps_peer)
682 {
683   rps_peer->num_ids_to_request = 1;
684 }
685
686 /**
687  * Callback to call on receipt of a reply
688  *
689  * @param cls closure
690  * @param n number of peers
691  * @param recv_peers the received peers
692  */
693 static void
694 default_reply_handle (void *cls,
695                       uint64_t n,
696                       const struct GNUNET_PeerIdentity *recv_peers)
697 {
698   struct RPSPeer *rps_peer;
699   struct PendingReply *pending_rep = (struct PendingReply *) cls;
700   unsigned int i;
701
702   rps_peer = pending_rep->rps_peer;
703   GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
704                                rps_peer->pending_rep_tail,
705                                pending_rep);
706   rps_peer->num_pending_reps--;
707   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
708               "[%s] got %" PRIu64 " peers:\n",
709               GNUNET_i2s (rps_peer->peer_id),
710               n);
711   
712   for (i = 0; i < n; i++)
713   {
714     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
715                 "%u: %s\n",
716                 i,
717                 GNUNET_i2s (&recv_peers[i]));
718
719     rps_peer->num_recv_ids++;
720   }
721
722   if (0 == evaluate ())
723   {
724     GNUNET_SCHEDULER_cancel (shutdown_task);
725     shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL);
726   }
727 }
728
729 /**
730  * Request random peers.
731  */
732 static void
733 request_peers (void *cls,
734                const struct GNUNET_SCHEDULER_TaskContext *tc)
735 {
736   struct RPSPeer *rps_peer;
737   struct PendingRequest *pending_req = (struct PendingRequest *) cls;
738   struct PendingReply *pending_rep;
739
740   if (GNUNET_YES == in_shutdown)
741     return;
742   rps_peer = pending_req->rps_peer;
743   GNUNET_assert (1 <= rps_peer->num_pending_reqs);
744   GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
745                                rps_peer->pending_req_tail,
746                                pending_req);
747   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
748               "Requesting one peer\n");
749   pending_rep = GNUNET_new (struct PendingReply);
750   pending_rep->rps_peer = rps_peer;
751   pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle,
752       1,
753       cur_test_run.reply_handle,
754       pending_rep);
755   GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head,
756                                     rps_peer->pending_rep_tail,
757                                     pending_rep);
758   rps_peer->num_pending_reps++;
759   rps_peer->num_pending_reqs--;
760 }
761
762 static void
763 cancel_pending_req (struct PendingRequest *pending_req)
764 {
765   struct RPSPeer *rps_peer;
766
767   rps_peer = pending_req->rps_peer;
768   GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
769                                rps_peer->pending_req_tail,
770                                pending_req);
771   rps_peer->num_pending_reqs--;
772   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
773               "Cancelling pending request\n");
774   GNUNET_SCHEDULER_cancel (pending_req->request_task);
775   GNUNET_free (pending_req);
776 }
777
778 static void
779 cancel_request (struct PendingReply *pending_rep)
780 {
781   struct RPSPeer *rps_peer;
782
783   rps_peer = pending_rep->rps_peer;
784   GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
785                                rps_peer->pending_rep_tail,
786                                pending_rep);
787   rps_peer->num_pending_reps--;
788   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
789               "Cancelling request\n");
790   GNUNET_RPS_request_cancel (pending_rep->req_handle);
791   GNUNET_free (pending_rep);
792 }
793
794 /**
795  * Cancel a request.
796  */
797 static void
798 cancel_request_cb (void *cls,
799                 const struct GNUNET_SCHEDULER_TaskContext *tc)
800 {
801   struct PendingReply *pending_rep;
802   struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
803
804   if (GNUNET_YES == in_shutdown)
805     return;
806   pending_rep = rps_peer->pending_rep_head;
807   GNUNET_assert (1 <= rps_peer->num_pending_reps);
808   cancel_request (pending_rep);
809 }
810
811
812 /**
813  * Schedule requests for peer @a rps_peer that have neither been scheduled, nor
814  * issued, nor replied
815  */
816 void
817 schedule_missing_requests (struct RPSPeer *rps_peer)
818 {
819   unsigned int i;
820   struct PendingRequest *pending_req;
821
822   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
823       "Scheduling %u - %u missing requests\n",
824       rps_peer->num_ids_to_request,
825       rps_peer->num_pending_reqs + rps_peer->num_pending_reps);
826   GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <=
827       rps_peer->num_ids_to_request);
828   for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps;
829        i < rps_peer->num_ids_to_request; i++)
830   {
831     pending_req = GNUNET_new (struct PendingRequest);
832     pending_req->rps_peer = rps_peer;
833     pending_req->request_task = GNUNET_SCHEDULER_add_delayed (
834         GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
835           cur_test_run.request_interval * i),
836         request_peers,
837         pending_req);
838     GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head,
839                                       rps_peer->pending_req_tail,
840                                       pending_req);
841     rps_peer->num_pending_reqs++;
842   }
843 }
844
845 void
846 cancel_pending_req_rep (struct RPSPeer *rps_peer)
847 {
848   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
849       "Cancelling all (pending) requests.\n");
850   while (NULL != rps_peer->pending_req_head)
851     cancel_pending_req (rps_peer->pending_req_head);
852   GNUNET_assert (0 == rps_peer->num_pending_reqs);
853   while (NULL != rps_peer->pending_rep_head)
854     cancel_request (rps_peer->pending_rep_head);
855   GNUNET_assert (0 == rps_peer->num_pending_reps);
856 }
857
858 /***********************************
859  * MALICIOUS
860 ***********************************/
861
862 /**
863  * Initialise only non-mal RPSPeers
864  */
865 static void mal_init_peer (struct RPSPeer *rps_peer)
866 {
867   if (rps_peer->index >= round (portion * num_peers))
868     rps_peer->num_ids_to_request = 1;
869 }
870
871 static void
872 mal_pre (void *cls, struct GNUNET_RPS_Handle *h)
873 {
874   #ifdef ENABLE_MALICIOUS
875   uint32_t num_mal_peers;
876   struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
877
878   GNUNET_assert ( (1 >= portion) &&
879                   (0 <  portion) );
880   num_mal_peers = round (portion * num_peers);
881
882   if (rps_peer->index < num_mal_peers)
883   {
884     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
885                 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
886                 rps_peer->index,
887                 GNUNET_i2s (rps_peer->peer_id),
888                 num_mal_peers);
889
890     GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers,
891                               rps_peer_ids, target_peer);
892   }
893   #endif /* ENABLE_MALICIOUS */
894 }
895
896 static void
897 mal_cb (struct RPSPeer *rps_peer)
898 {
899   uint32_t num_mal_peers;
900
901   #ifdef ENABLE_MALICIOUS
902   GNUNET_assert ( (1 >= portion) &&
903                   (0 <  portion) );
904   num_mal_peers = round (portion * num_peers);
905
906   if (rps_peer->index >= num_mal_peers)
907   { /* It's useless to ask a malicious peer about a random sample -
908        it's not sampling */
909     GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
910                                   seed_peers, rps_peer);
911     schedule_missing_requests (rps_peer);
912   }
913   #endif /* ENABLE_MALICIOUS */
914 }
915
916
917 /***********************************
918  * SINGLE_REQUEST
919 ***********************************/
920 static void
921 single_req_cb (struct RPSPeer *rps_peer)
922 {
923   schedule_missing_requests (rps_peer);
924 }
925
926 /***********************************
927  * DELAYED_REQUESTS
928 ***********************************/
929 static void
930 delay_req_cb (struct RPSPeer *rps_peer)
931 {
932   schedule_missing_requests (rps_peer);
933 }
934
935 /***********************************
936  * SEED
937 ***********************************/
938 static void
939 seed_cb (struct RPSPeer *rps_peer)
940 {
941   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
942                                 seed_peers, rps_peer);
943 }
944
945 /***********************************
946  * SEED_BIG
947 ***********************************/
948 static void
949 seed_big_cb (struct RPSPeer *rps_peer)
950 {
951   // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers
952 }
953
954 /***********************************
955  * SINGLE_PEER_SEED
956 ***********************************/
957 static void
958 single_peer_seed_cb (struct RPSPeer *rps_peer)
959 {
960   // TODO
961 }
962
963 /***********************************
964  * SEED_REQUEST
965 ***********************************/
966 static void
967 seed_req_cb (struct RPSPeer *rps_peer)
968 {
969   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
970                                 seed_peers, rps_peer);
971   schedule_missing_requests (rps_peer);
972 }
973
974 //TODO start big mal
975
976 /***********************************
977  * REQUEST_CANCEL
978 ***********************************/
979 static void
980 req_cancel_cb (struct RPSPeer *rps_peer)
981 {
982   schedule_missing_requests (rps_peer);
983   GNUNET_SCHEDULER_add_delayed (
984       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
985                                      (cur_test_run.request_interval + 1)),
986       cancel_request_cb, rps_peer);
987 }
988
989 /***********************************
990  * PROFILER
991 ***********************************/
992
993 /**
994  * Callback to be called when RPS service is started or stopped at peers
995  *
996  * @param cls NULL
997  * @param op the operation handle
998  * @param emsg NULL on success; otherwise an error description
999  */
1000 static void
1001 churn_cb (void *cls,
1002           struct GNUNET_TESTBED_Operation *op,
1003           const char *emsg)
1004 {
1005   // FIXME
1006   struct OpListEntry *entry = cls;
1007
1008   GNUNET_TESTBED_operation_done (entry->op);
1009   if (NULL != emsg)
1010   {
1011     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n");
1012     GNUNET_SCHEDULER_shutdown ();
1013     return;
1014   }
1015   GNUNET_assert (0 != entry->delta);
1016
1017   num_peers_online += entry->delta;
1018
1019   if (0 > entry->delta)
1020   { /* Peer hopefully just went offline */
1021     if (GNUNET_YES != rps_peers[entry->index].online)
1022     {
1023       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1024                   "peer %s was expected to go offline but is still marked as online\n",
1025                   GNUNET_i2s (rps_peers[entry->index].peer_id));
1026       GNUNET_break (0);
1027     }
1028     else
1029     {
1030       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1031                   "peer %s probably went offline as expected\n",
1032                   GNUNET_i2s (rps_peers[entry->index].peer_id));
1033     }
1034     rps_peers[entry->index].online = GNUNET_NO;
1035   }
1036
1037   else if (0 < entry->delta)
1038   { /* Peer hopefully just went online */
1039     if (GNUNET_NO != rps_peers[entry->index].online)
1040     {
1041       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1042                   "peer %s was expected to go online but is still marked as offline\n",
1043                   GNUNET_i2s (rps_peers[entry->index].peer_id));
1044       GNUNET_break (0);
1045     }
1046     else
1047     {
1048       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1049                   "peer %s probably went online as expected\n",
1050                   GNUNET_i2s (rps_peers[entry->index].peer_id));
1051       if (NULL != cur_test_run.pre_test)
1052       {
1053         cur_test_run.pre_test (&rps_peers[entry->index],
1054             rps_peers[entry->index].rps_handle);
1055         schedule_missing_requests (&rps_peers[entry->index]);
1056       }
1057     }
1058     rps_peers[entry->index].online = GNUNET_YES;
1059   }
1060
1061   GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1062   GNUNET_free (entry);
1063   //if (num_peers_in_round[current_round] == peers_running)
1064   //  run_round ();
1065 }
1066
1067 static void
1068 manage_service_wrapper (unsigned int i, unsigned int j, int delta,
1069     double prob_go_on_off)
1070 {
1071   struct OpListEntry *entry;
1072   uint32_t prob;
1073
1074   prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1075                                    UINT32_MAX);
1076   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1077               "%u. selected peer (%u: %s) is %s.\n",
1078               i,
1079               j,
1080               GNUNET_i2s (rps_peers[j].peer_id),
1081               (0 > delta) ? "online" : "offline");
1082   if (prob < prob_go_on_off * UINT32_MAX)
1083   {
1084     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1085                 "%s goes %s\n",
1086                 GNUNET_i2s (rps_peers[j].peer_id),
1087                 (0 > delta) ? "offline" : "online");
1088
1089     if (0 > delta)
1090       cancel_pending_req_rep (&rps_peers[j]);
1091     entry = make_oplist_entry ();
1092     entry->delta = delta;
1093     entry->index = j;
1094     entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
1095                                                     testbed_peers[j],
1096                                                     "rps",
1097                                                     &churn_cb,
1098                                                     entry,
1099                                                     (0 > delta) ? 0 : 1);
1100   }
1101 }
1102
1103 static void
1104 churn (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1105 {
1106   unsigned int i;
1107   unsigned int j;
1108   double portion_online;
1109   unsigned int *permut;
1110   double prob_go_offline;
1111   double portion_go_online;
1112   double portion_go_offline;
1113
1114   /* Compute the probability for an online peer to go offline
1115    * this round */
1116   portion_online = num_peers_online * 1.0 / num_peers;
1117   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1118               "Portion online: %f\n",
1119               portion_online);
1120   portion_go_online = ((1 - portion_online) * .5 * .66);
1121   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1122               "Portion that should go online: %f\n",
1123               portion_go_online);
1124   portion_go_offline = (portion_online + portion_go_online) - .75;
1125   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1126               "Portion that probably goes offline: %f\n",
1127               portion_go_offline);
1128   prob_go_offline = portion_go_offline / (portion_online * .5);
1129   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1130               "Probability of a selected online peer to go offline: %f\n",
1131               prob_go_offline);
1132
1133   permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
1134                                          (unsigned int) num_peers);
1135
1136   /* Go over 50% randomly chosen peers */
1137   for (i = 0; i < .5 * num_peers; i++)
1138   {
1139     j = permut[i];
1140
1141     /* If online, shut down with certain probability */
1142     if (GNUNET_YES == rps_peers[j].online)
1143     {
1144       manage_service_wrapper (i, j, -1, prob_go_offline);
1145     }
1146
1147     /* If offline, restart with certain probability */
1148     else if (GNUNET_NO == rps_peers[j].online)
1149     {
1150       manage_service_wrapper (i, j, 1, 0.66);
1151     }
1152   }
1153
1154   GNUNET_free (permut);
1155
1156   churn_task = GNUNET_SCHEDULER_add_delayed (
1157         GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1158         churn,
1159         NULL);
1160 }
1161
1162
1163 /**
1164  * Initialise given RPSPeer
1165  */
1166 static void profiler_init_peer (struct RPSPeer *rps_peer)
1167 {
1168   if (num_peers - 1 == rps_peer->index)
1169     rps_peer->num_ids_to_request = cur_test_run.num_requests;
1170 }
1171
1172
1173 /**
1174  * Callback to call on receipt of a reply
1175  *
1176  * @param cls closure
1177  * @param n number of peers
1178  * @param recv_peers the received peers
1179  */
1180 static void
1181 profiler_reply_handle (void *cls,
1182                       uint64_t n,
1183                       const struct GNUNET_PeerIdentity *recv_peers)
1184 {
1185   struct RPSPeer *rps_peer;
1186   struct RPSPeer *rcv_rps_peer;
1187   char *file_name;
1188   char *file_name_dh;
1189   unsigned int i;
1190   struct PendingReply *pending_rep = (struct PendingReply *) cls;
1191
1192   rps_peer = pending_rep->rps_peer;
1193   file_name = "/tmp/rps/received_ids";
1194   file_name_dh = "/tmp/rps/diehard_input";
1195   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1196               "[%s] got %" PRIu64 " peers:\n",
1197               GNUNET_i2s (rps_peer->peer_id),
1198               n);
1199   for (i = 0; i < n; i++)
1200   {
1201     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1202                 "%u: %s\n",
1203                 i,
1204                 GNUNET_i2s (&recv_peers[i]));
1205     tofile (file_name,
1206              "%s\n",
1207              GNUNET_i2s_full (&recv_peers[i]));
1208     rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]);
1209     tofile (file_name_dh,
1210              "%" PRIu32 "\n",
1211              (uint32_t) rcv_rps_peer->index);
1212   }
1213   default_reply_handle (cls, n, recv_peers);
1214 }
1215
1216
1217 static void
1218 profiler_cb (struct RPSPeer *rps_peer)
1219 {
1220   /* Start churn */
1221   if (NULL == churn_task)
1222   {
1223     churn_task = GNUNET_SCHEDULER_add_delayed (
1224           GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1225           churn,
1226           NULL);
1227   }
1228
1229   /* Only request peer ids at one peer.
1230    * (It's the before-last because last one is target of the focussed attack.)
1231    */
1232   if (eval_peer == rps_peer)
1233     schedule_missing_requests (rps_peer);
1234 }
1235
1236 /**
1237  * Function called from #profiler_eval with a filename.
1238  *
1239  * @param cls closure
1240  * @param filename complete filename (absolute path)
1241  * @return #GNUNET_OK to continue to iterate,
1242  *  #GNUNET_NO to stop iteration with no error,
1243  *  #GNUNET_SYSERR to abort iteration with error!
1244  */
1245 int
1246 file_name_cb (void *cls, const char *filename)
1247 {
1248   if (NULL != strstr (filename, "sampler_el"))
1249   {
1250     struct RPS_SamplerElement *s_elem;
1251     struct GNUNET_CRYPTO_AuthKey auth_key;
1252     const char *key_char;
1253     uint32_t i;
1254
1255     key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
1256     tofile (filename, "--------------------------\n");
1257
1258     auth_key = string_to_auth_key (key_char);
1259     s_elem = RPS_sampler_elem_create ();
1260     RPS_sampler_elem_set (s_elem, auth_key);
1261
1262     for (i = 0; i < num_peers; i++)
1263     {
1264       RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
1265     }
1266   }
1267   return GNUNET_OK;
1268 }
1269
1270 /**
1271  * This is run after the test finished.
1272  *
1273  * Compute all perfect samples.
1274  */
1275 int
1276 profiler_eval (void)
1277 {
1278   /* Compute perfect sample for each sampler element */
1279   if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL))
1280   {
1281     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
1282   }
1283
1284   return evaluate ();
1285 }
1286
1287
1288 /***********************************************************************
1289  * /Definition of tests
1290 ***********************************************************************/
1291
1292
1293 /**
1294  * Actual "main" function for the testcase.
1295  *
1296  * @param cls closure
1297  * @param h the run handle
1298  * @param n_peers number of peers in 'peers'
1299  * @param peers handle to peers run in the testbed
1300  * @param links_succeeded the number of overlay link connection attempts that
1301  *          succeeded
1302  * @param links_failed the number of overlay link connection attempts that
1303  *          failed
1304  */
1305 static void
1306 run (void *cls,
1307      struct GNUNET_TESTBED_RunHandle *h,
1308      unsigned int n_peers,
1309      struct GNUNET_TESTBED_Peer **peers,
1310      unsigned int links_succeeded,
1311      unsigned int links_failed)
1312 {
1313   unsigned int i;
1314   struct OpListEntry *entry;
1315
1316   testbed_peers = peers;
1317   num_peers_online = 0;
1318   for (i = 0 ; i < num_peers ; i++)
1319   {
1320     entry = make_oplist_entry ();
1321     entry->index = i;
1322     entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
1323                                                      GNUNET_TESTBED_PIT_IDENTITY,
1324                                                      &info_cb,
1325                                                      entry);
1326   }
1327
1328   GNUNET_assert (num_peers == n_peers);
1329   for (i = 0 ; i < n_peers ; i++)
1330   {
1331     rps_peers[i].index = i;
1332     rps_peers[i].op =
1333       GNUNET_TESTBED_service_connect (&rps_peers[i],
1334                                       peers[i],
1335                                       "rps",
1336                                       &rps_connect_complete_cb,
1337                                       &rps_peers[i],
1338                                       &rps_connect_adapter,
1339                                       &rps_disconnect_adapter,
1340                                       &rps_peers[i]);
1341   }
1342
1343   if (NULL != churn_task)
1344     GNUNET_SCHEDULER_cancel (churn_task);
1345   shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
1346 }
1347
1348
1349 /**
1350  * Entry point for the testcase, sets up the testbed.
1351  *
1352  * @param argc unused
1353  * @param argv unused
1354  * @return 0 on success
1355  */
1356 int
1357 main (int argc, char *argv[])
1358 {
1359   int ret_value;
1360
1361   num_peers = 5;
1362   cur_test_run.name = "test-rps-default";
1363   cur_test_run.init_peer = default_init_peer;
1364   cur_test_run.pre_test = NULL;
1365   cur_test_run.reply_handle = default_reply_handle;
1366   cur_test_run.eval_cb = default_eval_cb;
1367   churn_task = NULL;
1368   timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
1369
1370   if (strstr (argv[0], "malicious") != NULL)
1371   {
1372     cur_test_run.pre_test = mal_pre;
1373     cur_test_run.main_test = mal_cb;
1374     cur_test_run.init_peer = mal_init_peer;
1375
1376     if (strstr (argv[0], "_1") != NULL)
1377     {
1378       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
1379       cur_test_run.name = "test-rps-malicious_1";
1380       mal_type = 1;
1381     }
1382     else if (strstr (argv[0], "_2") != NULL)
1383     {
1384       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
1385       cur_test_run.name = "test-rps-malicious_2";
1386       mal_type = 2;
1387     }
1388     else if (strstr (argv[0], "_3") != NULL)
1389     {
1390       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n");
1391       cur_test_run.name = "test-rps-malicious_3";
1392       mal_type = 3;
1393     }
1394   }
1395
1396   else if (strstr (argv[0], "_single_req") != NULL)
1397   {
1398     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
1399     cur_test_run.name = "test-rps-single-req";
1400     cur_test_run.main_test = single_req_cb;
1401   }
1402
1403   else if (strstr (argv[0], "_delayed_reqs") != NULL)
1404   {
1405     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
1406     cur_test_run.name = "test-rps-delayed-reqs";
1407     cur_test_run.main_test = delay_req_cb;
1408   }
1409
1410   else if (strstr (argv[0], "_seed_big") != NULL)
1411   {
1412     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_SERVER_MAX_MESSAGE_SIZE)\n");
1413     cur_test_run.name = "test-rps-seed-big";
1414     cur_test_run.main_test = seed_big_cb;
1415   }
1416
1417   else if (strstr (argv[0], "_single_peer_seed") != NULL)
1418   {
1419     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
1420     cur_test_run.name = "test-rps-single-peer-seed";
1421     cur_test_run.main_test = single_peer_seed_cb;
1422   }
1423
1424   else if (strstr (argv[0], "_seed_request") != NULL)
1425   {
1426     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
1427     cur_test_run.name = "test-rps-seed-request";
1428     cur_test_run.main_test = seed_req_cb;
1429   }
1430
1431   else if (strstr (argv[0], "_seed") != NULL)
1432   {
1433     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
1434     cur_test_run.name = "test-rps-seed";
1435     cur_test_run.main_test = seed_cb;
1436     cur_test_run.eval_cb = no_eval;
1437   }
1438
1439   else if (strstr (argv[0], "_req_cancel") != NULL)
1440   {
1441     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
1442     cur_test_run.name = "test-rps-req-cancel";
1443     num_peers = 1;
1444     cur_test_run.main_test = req_cancel_cb;
1445     cur_test_run.eval_cb = no_eval;
1446     timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10);
1447   }
1448
1449   else if (strstr (argv[0], "profiler") != NULL)
1450   {
1451     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
1452     cur_test_run.name = "test-rps-profiler";
1453     num_peers = 10;
1454     mal_type = 3;
1455     cur_test_run.init_peer = profiler_init_peer;
1456     cur_test_run.pre_test = mal_pre;
1457     cur_test_run.main_test = profiler_cb;
1458     cur_test_run.reply_handle = profiler_reply_handle;
1459     cur_test_run.eval_cb = profiler_eval;
1460     cur_test_run.request_interval = 2;
1461     cur_test_run.num_requests = 5;
1462     timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90);
1463
1464     /* 'Clean' directory */
1465     (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
1466     GNUNET_DISK_directory_create ("/tmp/rps/");
1467   }
1468
1469   rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
1470   peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
1471   rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
1472   if ( (2 == mal_type) ||
1473        (3 == mal_type))
1474     target_peer = &rps_peer_ids[num_peers - 2];
1475   if (profiler_eval == cur_test_run.eval_cb)
1476     eval_peer = &rps_peers[num_peers - 1];
1477
1478   ok = 1;
1479   (void) GNUNET_TESTBED_test_run (cur_test_run.name,
1480                                   "test_rps.conf",
1481                                   num_peers,
1482                                   0, NULL, NULL,
1483                                   &run, NULL);
1484
1485   ret_value = cur_test_run.eval_cb();
1486   GNUNET_free (rps_peers );
1487   GNUNET_free (rps_peer_ids);
1488   GNUNET_CONTAINER_multipeermap_destroy (peer_map);
1489   return ret_value;
1490 }
1491
1492 /* end of test_rps_multipeer.c */