- use ping-pong to avoid collisions
[oweals/gnunet.git] / src / mesh / gnunet-mesh-profiler.c
1 /*
2      This file is part of GNUnet.
3      (C) 2011 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 mesh/gnunet-mesh-profiler.c
22  *
23  * @brief Profiler for mesh experiments.
24  */
25 #include <stdio.h>
26 #include "platform.h"
27 #include "mesh_test_lib.h"
28 #include "gnunet_mesh_service.h"
29 #include "gnunet_statistics_service.h"
30
31
32 #define PING 1
33 #define PONG 2
34
35 /**
36  * How namy peers to run
37  */
38 #define TOTAL_PEERS 10
39
40 /**
41  * How long until we give up on connecting the peers?
42  */
43 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
44
45 /**
46  * Time to wait for stuff that should be rather fast
47  */
48 #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
49
50
51 struct MeshPeer
52 {
53   /**
54    * Testbed Operation (to get peer id, etc).
55    */
56   struct GNUNET_TESTBED_Operation *op;
57
58   /**
59    * Peer ID.
60    */
61   struct GNUNET_PeerIdentity id;
62
63   /**
64    * Mesh handle for the root peer
65    */
66   struct GNUNET_MESH_Handle *mesh;
67
68   /**
69    * Channel handle for the root peer
70    */
71   struct GNUNET_MESH_Channel *ch;
72
73   /**
74    * Channel handle for the dest peer
75    */
76   struct GNUNET_MESH_Channel *incoming_ch;
77
78   /**
79    * Number of payload packes sent
80    */
81   int data_sent;
82
83   /**
84    * Number of payload packets received
85    */
86   int data_received;
87
88   struct MeshPeer *dest;
89   struct MeshPeer *incoming;
90   GNUNET_SCHEDULER_TaskIdentifier ping_task;
91   struct GNUNET_TIME_Absolute timestamp;
92 };
93
94 /**
95  * GNUNET_PeerIdentity -> MeshPeer
96  */
97 static struct GNUNET_CONTAINER_MultiPeerMap *ids;
98
99 /**
100  * Testbed peer handles.
101  */
102 static struct GNUNET_TESTBED_Peer **testbed_handles;
103
104 /**
105  * Testbed Operation (to get stats).
106  */
107 static struct GNUNET_TESTBED_Operation *stats_op;
108
109 /**
110  * How many events have happened
111  */
112 static int ok;
113
114 /**
115  * Number of events expected to conclude the test successfully.
116  */
117 static int ok_goal;
118
119 /**
120  * Size of each test packet
121  */
122 size_t size_payload = sizeof (struct GNUNET_MessageHeader) + sizeof (uint32_t);
123
124 /**
125  * Operation to get peer ids.
126  */
127 struct MeshPeer peers[TOTAL_PEERS];
128
129 /**
130  * Peer ids counter.
131  */
132 static unsigned int p_ids;
133
134 /**
135  * Total number of currently running peers.
136  */
137 static unsigned long long peers_running;
138
139 /**
140  * Test context (to shut down).
141  */
142 static struct GNUNET_MESH_TEST_Context *test_ctx;
143
144 /**
145  * Task called to shutdown test.
146  */
147 static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
148
149 /**
150  * Task called to disconnect peers, before shutdown.
151  */
152 static GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
153
154 /**
155  * Task to perform tests
156  */
157 static GNUNET_SCHEDULER_TaskIdentifier test_task;
158
159
160 /**
161  * Flag to notify callbacks not to generate any new traffic anymore.
162  */
163 static int test_finished;
164
165 /**
166  * Calculate a random delay.
167  *
168  * @param max Exclusive maximum, in ms.
169  *
170  * @return A time between 0 a max-1 ms.
171  */
172 static struct GNUNET_TIME_Relative
173 delay_ms_rnd (unsigned int max)
174 {
175   unsigned int rnd;
176
177   rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max);
178   return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rnd);
179 }
180
181
182 /**
183  * Get the index of a peer in the peers array.
184  *
185  * @param peer Peer whose index to get.
186  *
187  * @return Index of peer in peers.
188  */
189 static unsigned int
190 get_index (struct MeshPeer *peer)
191 {
192   return peer - peers;
193 }
194
195
196 /**
197  * Show the results of the test (banwidth acheived) and log them to GAUGER
198  */
199 static void
200 show_end_data (void)
201 {
202 }
203
204
205 /**
206  * Shut down peergroup, clean up.
207  *
208  * @param cls Closure (unused).
209  * @param tc Task Context.
210  */
211 static void
212 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
213 {
214   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Ending test.\n");
215   shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
216 }
217
218
219 /**
220  * Disconnect from mesh services af all peers, call shutdown.
221  *
222  * @param cls Closure (unused).
223  * @param tc Task Context.
224  */
225 static void
226 disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
227 {
228   long line = (long) cls;
229   unsigned int i;
230
231   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
232               "disconnecting mesh service of peers, called from line %ld\n",
233               line);
234   disconnect_task = GNUNET_SCHEDULER_NO_TASK;
235   for (i = 0; i < TOTAL_PEERS; i++)
236   {
237     GNUNET_TESTBED_operation_done (peers[i].op);
238     GNUNET_MESH_channel_destroy (peers[i].ch);
239     GNUNET_MESH_channel_destroy (peers[i].incoming_ch);
240   }
241   GNUNET_MESH_TEST_cleanup (test_ctx);
242   if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
243   {
244     GNUNET_SCHEDULER_cancel (shutdown_handle);
245   }
246   shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
247 }
248
249
250 /**
251  * Finish test normally: schedule disconnect and shutdown
252  *
253  * @param line Line in the code the abort is requested from (__LINE__).
254  */
255 static void
256 abort_test (long line)
257 {
258   if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
259   {
260     GNUNET_SCHEDULER_cancel (disconnect_task);
261     disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers,
262                                                 (void *) line);
263   }
264 }
265
266 /**
267  * Stats callback. Finish the stats testbed operation and when all stats have
268  * been iterated, shutdown the test.
269  *
270  * @param cls closure
271  * @param op the operation that has been finished
272  * @param emsg error message in case the operation has failed; will be NULL if
273  *          operation has executed successfully.
274  */
275 static void
276 stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
277 {
278   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "... collecting statistics done.\n");
279   GNUNET_TESTBED_operation_done (stats_op);
280
281   if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
282     GNUNET_SCHEDULER_cancel (disconnect_task);
283   disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers,
284                                               (void *) __LINE__);
285
286 }
287
288
289 /**
290  * Process statistic values.
291  *
292  * @param cls closure
293  * @param peer the peer the statistic belong to
294  * @param subsystem name of subsystem that created the statistic
295  * @param name the name of the datum
296  * @param value the current value
297  * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
298  * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
299  */
300 static int
301 stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
302                 const char *subsystem, const char *name,
303                 uint64_t value, int is_persistent)
304 {
305   uint32_t i;
306
307   i = GNUNET_TESTBED_get_index (peer);
308   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " STATS %u - %s [%s]: %llu\n",
309               i, subsystem, name, value);
310
311   return GNUNET_OK;
312 }
313
314
315 /**
316  * Task check that keepalives were sent and received.
317  *
318  * @param cls Closure (NULL).
319  * @param tc Task Context.
320  */
321 static void
322 collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
323 {
324   if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
325     return;
326
327   disconnect_task = GNUNET_SCHEDULER_NO_TASK;
328   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
329   stats_op = GNUNET_TESTBED_get_statistics (TOTAL_PEERS, testbed_handles,
330                                             NULL, NULL,
331                                             stats_iterator, stats_cont, NULL);
332 }
333
334
335 /**
336  * @brief Finish profiler normally.
337  *
338  * @param cls Closure (unused).
339  * @param tc Task context.
340  */
341 static void
342 finish_profiler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
343 {
344   if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
345     return;
346
347   test_finished = GNUNET_YES;
348   show_end_data();
349   GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
350 }
351
352
353
354 /**
355  * Transmit ready callback.
356  *
357  * @param cls Closure (unused).
358  * @param size Size of the tranmist buffer.
359  * @param buf Pointer to the beginning of the buffer.
360  *
361  * @return Number of bytes written to buf.
362  */
363 static size_t
364 tmt_ping_rdy (void *cls, size_t size, void *buf);
365
366 /**
367  * Transmit ready callback.
368  *
369  * @param cls Closure (unused).
370  * @param size Size of the tranmist buffer.
371  * @param buf Pointer to the beginning of the buffer.
372  *
373  * @return Number of bytes written to buf.
374  */
375 static size_t
376 tmt_pong_rdy (void *cls, size_t size, void *buf);
377
378
379 /**
380  * @brief Send a ping to destination
381  *
382  * @param cls Closure (peer).
383  * @param tc Task context.
384  */
385 static void
386 ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
387 {
388   struct MeshPeer *peer = (struct MeshPeer *) cls;
389
390   peer->ping_task = GNUNET_SCHEDULER_NO_TASK;
391   if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
392     return;
393
394   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u -> %u\n",
395               get_index (peer), get_index (peer->dest));
396
397   GNUNET_MESH_notify_transmit_ready (peer->ch, GNUNET_NO,
398                                      GNUNET_TIME_UNIT_FOREVER_REL,
399                                      size_payload, &tmt_ping_rdy, peer);
400 }
401
402 /**
403  * @brief Reply with a pong to origin.
404  *
405  * @param cls Closure (peer).
406  * @param tc Task context.
407  */
408 static void
409 pong (struct GNUNET_MESH_Channel *channel)
410 {
411   GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO,
412                                      GNUNET_TIME_UNIT_FOREVER_REL,
413                                      size_payload, &tmt_pong_rdy, NULL);
414 }
415
416
417 /**
418  * Transmit ready callback
419  *
420  * @param cls Closure (unused).
421  * @param size Size of the buffer we have.
422  * @param buf Buffer to copy data to.
423  */
424 size_t
425 tmt_ping_rdy (void *cls, size_t size, void *buf)
426 {
427   struct MeshPeer *peer = (struct MeshPeer *) cls;
428   struct GNUNET_MessageHeader *msg = buf;
429   uint32_t *data;
430   unsigned int s;
431
432   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n");
433   if (size < size_payload || NULL == buf)
434   {
435     GNUNET_break (ok >= ok_goal - 2);
436     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
437                 "size %u, buf %p, data_sent %u, data_received %u\n",
438                 size, buf, peer->data_sent, peer->data_received);
439     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok %u, ok goal %u\n", ok, ok_goal);
440
441     return 0;
442   }
443   msg->size = htons (size);
444   msg->type = htons (PING);
445   data = (uint32_t *) &msg[1];
446   *data = htonl (peer->data_sent);
447   if (0 == peer->data_sent)
448   {
449     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent: initializer\n");
450     s = 5;
451   }
452   else
453   {
454     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent: msg %d\n", peer->data_sent);
455     s = 60;
456   }
457   peer->data_sent++;
458   peer->timestamp = GNUNET_TIME_absolute_get ();
459   peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (s * 1000),
460                                                   &ping, peer);
461
462   return size_payload;
463 }
464
465
466 /**
467  * Transmit ready callback
468  *
469  * @param cls Closure (unused).
470  * @param size Size of the buffer we have.
471  * @param buf Buffer to copy data to.
472  */
473 size_t
474 tmt_pong_rdy (void *cls, size_t size, void *buf)
475 {
476   struct GNUNET_MessageHeader *msg = buf;
477   size_t size_payload = sizeof (struct GNUNET_MessageHeader);
478
479   if (size < size_payload || NULL == buf)
480   {
481     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot send PONG\n");
482     return 0;
483   }
484   msg->size = htons (size_payload);
485   msg->type = htons (PONG);
486
487   return size_payload;
488 }
489
490
491 /**
492  * Function is called whenever a PING message is received.
493  *
494  * @param cls closure (peer #, set from GNUNET_MESH_connect)
495  * @param channel connection to the other end
496  * @param channel_ctx place to store local state associated with the channel
497  * @param message the actual message
498  * @return GNUNET_OK to keep the connection open,
499  *         GNUNET_SYSERR to close it (signal serious error)
500  */
501 int
502 ping_handler (void *cls, struct GNUNET_MESH_Channel *channel,
503               void **channel_ctx,
504               const struct GNUNET_MessageHeader *message)
505 {
506   long n = (long) cls;
507
508   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u got PING\n", n);
509   GNUNET_MESH_receive_done (channel);
510   if (GNUNET_NO == test_finished)
511     pong (channel);
512
513   return GNUNET_OK;
514 }
515
516
517 /**
518  * Function is called whenever a PONG message is received.
519  *
520  * @param cls closure (peer #, set from GNUNET_MESH_connect)
521  * @param channel connection to the other end
522  * @param channel_ctx place to store local state associated with the channel
523  * @param message the actual message
524  * @return GNUNET_OK to keep the connection open,
525  *         GNUNET_SYSERR to close it (signal serious error)
526  */
527 int
528 pong_handler (void *cls, struct GNUNET_MESH_Channel *channel,
529               void **channel_ctx,
530               const struct GNUNET_MessageHeader *message)
531 {
532   long n = (long) cls;
533   struct MeshPeer *peer;
534   struct GNUNET_TIME_Relative latency;
535
536   GNUNET_MESH_receive_done (channel);
537   peer = &peers[n];
538
539   GNUNET_assert (0 != peer->timestamp.abs_value_us);
540   latency = GNUNET_TIME_absolute_get_duration (peer->incoming->timestamp);
541   FPRINTF (stderr, "%u -> %ld latency: %s\n",
542            get_index (peer->incoming), n,
543            GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
544   peer->timestamp.abs_value_us = 0;
545
546   return GNUNET_OK;
547 }
548
549
550 /**
551  * Handlers, for diverse services
552  */
553 static struct GNUNET_MESH_MessageHandler handlers[] = {
554   {&ping_handler, PING, sizeof (struct GNUNET_MessageHeader)},
555   {&pong_handler, PONG, sizeof (struct GNUNET_MessageHeader)},
556   {NULL, 0, 0}
557 };
558
559
560 /**
561  * Method called whenever another peer has added us to a channel
562  * the other peer initiated.
563  *
564  * @param cls Closure.
565  * @param channel New handle to the channel.
566  * @param initiator Peer that started the channel.
567  * @param port Port this channel is connected to.
568  * @param options channel option flags
569  * @return Initial channel context for the channel
570  *         (can be NULL -- that's not an error).
571  */
572 static void *
573 incoming_channel (void *cls, struct GNUNET_MESH_Channel *channel,
574                  const struct GNUNET_PeerIdentity *initiator,
575                  uint32_t port, enum GNUNET_MESH_ChannelOption options)
576 {
577   long n = (long) cls;
578   struct MeshPeer *peer;
579
580   peer = GNUNET_CONTAINER_multipeermap_get (ids, initiator);
581   GNUNET_assert (NULL != peer);
582   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <= %u\n", n, get_index (peer));
583   peers[n].incoming_ch = channel;
584
585   if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
586   {
587     GNUNET_SCHEDULER_cancel (disconnect_task);
588     disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
589                                                     &disconnect_mesh_peers,
590                                                     (void *) __LINE__);
591   }
592
593   return NULL;
594 }
595
596 /**
597  * Function called whenever an inbound channel is destroyed.  Should clean up
598  * any associated state.
599  *
600  * @param cls closure (set from GNUNET_MESH_connect)
601  * @param channel connection to the other end (henceforth invalid)
602  * @param channel_ctx place where local state associated
603  *                   with the channel is stored
604  */
605 static void
606 channel_cleaner (void *cls, const struct GNUNET_MESH_Channel *channel,
607                  void *channel_ctx)
608 {
609   long n = (long) cls;
610
611   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
612               "Incoming channel disconnected at peer %ld\n", n);
613   GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
614
615   if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
616   {
617     GNUNET_SCHEDULER_cancel (disconnect_task);
618     disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers,
619                                                 (void *) __LINE__);
620   }
621 }
622
623
624 static struct MeshPeer *
625 select_random_peer (struct MeshPeer *peer)
626 {
627   unsigned int r;
628
629   do
630   {
631     r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, TOTAL_PEERS);
632   } while (NULL != peers[r].incoming);
633   peers[r].incoming = peer;
634
635   return &peers[r];
636 }
637
638 /**
639  * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES.
640  *
641  * Testcase continues when the root receives confirmation of connected peers,
642  * on callback funtion ch.
643  *
644  * @param cls Closure (unsued).
645  * @param tc Task Context.
646  */
647 static void
648 do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
649 {
650   enum GNUNET_MESH_ChannelOption flags;
651   unsigned long i;
652
653   if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
654     return;
655
656   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
657
658   if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
659     GNUNET_SCHEDULER_cancel (disconnect_task);
660   disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
661                                                   &disconnect_mesh_peers,
662                                                   (void *) __LINE__);
663
664   flags = GNUNET_MESH_OPTION_DEFAULT;
665   for (i = 0; i < TOTAL_PEERS; i++)
666   {
667
668     peers[i].dest = select_random_peer (&peers[i]);
669     peers[i].ch = GNUNET_MESH_channel_create (peers[i].mesh, NULL,
670                                               &peers[i].dest->id,
671                                               1, flags);
672     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u => %u\n",
673                 i, get_index (peers[i].dest));
674     peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
675                                                        &ping, &peers[i]);
676   }
677 }
678
679
680 /**
681  * Callback to be called when the requested peer information is available
682  *
683  * @param cls the closure from GNUNET_TESTBED_peer_get_information()
684  * @param op the operation this callback corresponds to
685  * @param pinfo the result; will be NULL if the operation has failed
686  * @param emsg error message if the operation has failed;
687  *             NULL if the operation is successfull
688  */
689 static void
690 peer_id_cb (void *cls,
691        struct GNUNET_TESTBED_Operation *op,
692        const struct GNUNET_TESTBED_PeerInformation *pinfo,
693        const char *emsg)
694 {
695   long n = (long) cls;
696
697   if (NULL == pinfo || NULL != emsg)
698   {
699     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg);
700     abort_test (__LINE__);
701     return;
702   }
703   peers[n].id = *(pinfo->result.id);
704   GNUNET_log (GNUNET_ERROR_TYPE_INFO, " %u  id: %s\n",
705               n, GNUNET_i2s (&peers[n].id));
706   GNUNET_break (GNUNET_OK ==
707                 GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n],
708                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
709   p_ids++;
710   if (p_ids < TOTAL_PEERS)
711     return;
712   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n");
713   test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
714                                             &do_test, NULL);
715 }
716
717 /**
718  * test main: start test when all peers are connected
719  *
720  * @param cls Closure.
721  * @param ctx Argument to give to GNUNET_MESH_TEST_cleanup on test end.
722  * @param num_peers Number of peers that are running.
723  * @param testbed_peers Array of peers.
724  * @param meshes Handle to each of the MESHs of the peers.
725  */
726 static void
727 tmain (void *cls,
728        struct GNUNET_MESH_TEST_Context *ctx,
729        unsigned int num_peers,
730        struct GNUNET_TESTBED_Peer **testbed_peers,
731        struct GNUNET_MESH_Handle **meshes)
732 {
733   unsigned long i;
734
735   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n");
736   ok = 0;
737   test_ctx = ctx;
738   GNUNET_assert (TOTAL_PEERS == num_peers);
739   peers_running = num_peers;
740   testbed_handles = testbed_peers;
741   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
742                                 &finish_profiler, NULL);
743   disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
744                                                   &disconnect_mesh_peers,
745                                                   (void *) __LINE__);
746   shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
747                                                   &shutdown_task, NULL);
748   for (i = 0; i < TOTAL_PEERS; i++)
749   {
750     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i);
751     peers[i].mesh = meshes[i];
752     peers[i].op =
753       GNUNET_TESTBED_peer_get_information (testbed_handles[i],
754                                            GNUNET_TESTBED_PIT_IDENTITY,
755                                            &peer_id_cb, (void *) i);
756   }
757   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n");
758   /* Continues from pi_cb -> do_test */
759 }
760
761
762 /**
763  * Main: start profiler.
764  */
765 int
766 main (int argc, char *argv[])
767 {
768   static uint32_t ports[2];
769   const char *config_file;
770
771   config_file = "test_mesh.conf";
772
773   ids = GNUNET_CONTAINER_multipeermap_create (2 * TOTAL_PEERS, GNUNET_YES);
774   GNUNET_assert (NULL != ids);
775   p_ids = 0;
776   test_finished = GNUNET_NO;
777   ports[0] = 1;
778   ports[1] = 0;
779   GNUNET_MESH_TEST_run ("mesh-profiler", config_file, TOTAL_PEERS,
780                         &tmain, NULL, /* tmain cls */
781                         &incoming_channel, &channel_cleaner,
782                         handlers, ports);
783
784   if (ok_goal > ok)
785   {
786     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
787                 "FAILED! (%d/%d)\n", ok, ok_goal);
788     return 1;
789   }
790   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
791   return 0;
792 }
793
794 /* end of gnunet-mesh-profiler.c */
795