37e5ecfbd7950c5a77b4dcc44b7e3cb5405db5f5
[oweals/gnunet.git] / src / nse / gnunet-nse-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 nse/gnunet-nse-profiler.c
22  *
23  * @brief Profiling driver for the network size estimation service.
24  *        Generally, the profiler starts a given number of peers,
25  *        then churns some off, waits a certain amount of time, then
26  *        churns again, and repeats.
27  */
28 #include "platform.h"
29 #include "gnunet_testing_lib.h"
30 #include "gnunet_nse_service.h"
31
32 #define VERBOSE 3
33
34 struct NSEPeer
35 {
36   struct NSEPeer *prev;
37
38   struct NSEPeer *next;
39
40   struct GNUNET_TESTING_Daemon *daemon;
41
42   struct GNUNET_NSE_Handle *nse_handle;
43
44   struct GNUNET_STATISTICS_Handle *stats;
45 };
46
47
48 struct StatsContext
49 {
50   unsigned long long total_nse_bytes;
51 };
52
53
54 static struct NSEPeer *peer_head;
55
56 static struct NSEPeer *peer_tail;
57
58 /**
59  * How long until we give up on connecting the peers?
60  */
61 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500)
62
63 static int ok;
64
65 /**
66  * Be verbose
67  */
68 static int verbose;
69
70 /**
71  * Total number of peers in the test.
72  */
73 static unsigned long long num_peers;
74
75 /**
76  * Global configuration file
77  */
78 static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
79
80 /**
81  * Total number of currently running peers.
82  */
83 static unsigned long long peers_running;
84
85 /**
86  * Current round we are in.
87  */
88 static unsigned long long current_round;
89
90 /**
91  * Peers desired in the next round.
92  */
93 static unsigned long long peers_next_round;
94
95 /**
96  * Maximum number of connections to NSE services.
97  */
98 static unsigned long long connection_limit;
99
100 /**
101  * Total number of connections in the whole network.
102  */
103 static unsigned int total_connections;
104
105 /**
106  * The currently running peer group.
107  */
108 static struct GNUNET_TESTING_PeerGroup *pg;
109
110 /**
111  * File to report results to.
112  */
113 static struct GNUNET_DISK_FileHandle *output_file;
114
115 /**
116  * File to log connection info, statistics to.
117  */
118 static struct GNUNET_DISK_FileHandle *data_file;
119
120 /**
121  * How many data points to capture before triggering next round?
122  */
123 static struct GNUNET_TIME_Relative wait_time;
124
125 /**
126  * Task called to disconnect peers.
127  */
128 static GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
129
130 /**
131  * Task called to shutdown test.
132  */
133 static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
134
135 /**
136  * Task used to churn the network.
137  */
138 static GNUNET_SCHEDULER_TaskIdentifier churn_task;
139
140 static char *topology_file;
141
142 /**
143  * Check whether peers successfully shut down.
144  */
145 static void
146 shutdown_callback (void *cls, const char *emsg)
147 {
148   if (emsg != NULL)
149   {
150 #if VERBOSE
151     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
152 #endif
153     if (ok == 0)
154       ok = 666;
155   }
156   else
157   {
158 #if VERBOSE
159     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n");
160 #endif
161     ok = 0;
162   }
163 }
164
165
166 static void
167 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
168 {
169   struct NSEPeer *pos;
170
171 #if VERBOSE
172   fprintf (stderr, "Ending test.\n");
173 #endif
174
175   if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
176   {
177     GNUNET_SCHEDULER_cancel (disconnect_task);
178     disconnect_task = GNUNET_SCHEDULER_NO_TASK;
179   }
180   while (NULL != (pos = peer_head))
181   {
182     if (pos->nse_handle != NULL)
183       GNUNET_NSE_disconnect (pos->nse_handle);
184     GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
185     GNUNET_free (pos);
186   }
187
188   if (data_file != NULL)
189     GNUNET_DISK_file_close (data_file);
190   GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
191 }
192
193
194 /**
195  * Callback to call when network size estimate is updated.
196  *
197  * @param cls closure
198  * @param timestamp server timestamp
199  * @param estimate the value of the current network size estimate
200  * @param std_dev standard deviation (rounded down to nearest integer)
201  *                of the size estimation values seen
202  *
203  */
204 static void
205 handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
206                  double estimate, double std_dev)
207 {
208   struct NSEPeer *peer = cls;
209   char *output_buffer;
210   size_t size;
211
212   if (output_file != NULL)
213   {
214     size =
215         GNUNET_asprintf (&output_buffer, "%s %llu %llu %f %f %f\n",
216                          GNUNET_i2s (&peer->daemon->id), peers_running,
217                          timestamp.abs_value,
218                          GNUNET_NSE_log_estimate_to_n (estimate), estimate,
219                          std_dev);
220     if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
221       GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
222     GNUNET_free (output_buffer);
223   }
224   else
225     fprintf (stderr,
226              "Received network size estimate from peer %s. Size: %f std.dev. %f\n",
227              GNUNET_i2s (&peer->daemon->id), estimate, std_dev);
228
229 }
230
231 /**
232  * Process core statistic values.
233  *
234  * @param cls closure
235  * @param subsystem name of subsystem that created the statistic
236  * @param name the name of the datum
237  * @param value the current value
238  * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
239  * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
240  */
241 static int
242 core_stats_iterator (void *cls, const char *subsystem, const char *name,
243                      uint64_t value, int is_persistent)
244 {
245   struct NSEPeer *peer = cls;
246   char *output_buffer;
247   size_t size;
248
249   if (output_file != NULL)
250   {
251     size =
252         GNUNET_asprintf (&output_buffer, "%s -> %s [%s]: %llu\n",
253                           GNUNET_i2s (&peer->daemon->id),
254                          subsystem, name, value);
255     if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
256       GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
257     GNUNET_free (output_buffer);
258   }
259   else
260     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
261                 "%s -> %s [%s]: %llu\n",
262                 GNUNET_i2s (&peer->daemon->id), subsystem, name, value);
263
264   return GNUNET_OK;
265 }
266
267 /**
268  * Continuation called by "get_stats" function.
269  *
270  * @param cls closure
271  * @param success GNUNET_OK if statistics were
272  *        successfully obtained, GNUNET_SYSERR if not.
273  */
274 static void
275 core_stats_cont (void *cls, int success);
276
277 static void
278 core_get_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
279 {
280   struct NSEPeer *peer = cls;
281   if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
282   {
283     GNUNET_STATISTICS_destroy(peer->stats, GNUNET_YES);
284   }
285   else
286   {
287     GNUNET_STATISTICS_get(peer->stats, "core", NULL,
288                           GNUNET_TIME_UNIT_FOREVER_REL,
289                           &core_stats_cont, &core_stats_iterator, peer);
290   }
291 }
292
293 /**
294  * Continuation called by "get_stats" function.
295  *
296  * @param cls closure
297  * @param success GNUNET_OK if statistics were
298  *        successfully obtained, GNUNET_SYSERR if not.
299  */
300 static void
301 core_stats_cont (void *cls, int success)
302 {
303   struct NSEPeer *peer = cls;
304   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
305                                 &core_get_stats, peer);
306 }
307
308
309 /**
310  *
311  */
312 static void
313 connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
314 {
315   struct NSEPeer *current_peer;
316   unsigned int i;
317
318 #if VERBOSE
319   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to nse service of peers\n");
320 #endif
321   for (i = 0; i < num_peers; i++)
322   {
323     if ((connection_limit > 0) && (i % (num_peers / connection_limit) != 0))
324       continue;
325 #if VERBOSE
326     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
327                 "nse-profiler: connecting to nse service of peer %d\n", i);
328 #endif
329     current_peer = GNUNET_malloc (sizeof (struct NSEPeer));
330     current_peer->daemon = GNUNET_TESTING_daemon_get (pg, i);
331     if (GNUNET_YES ==
332         GNUNET_TESTING_test_daemon_running (GNUNET_TESTING_daemon_get (pg, i)))
333     {
334       current_peer->nse_handle =
335           GNUNET_NSE_connect (current_peer->daemon->cfg, &handle_estimate,
336                               current_peer);
337       GNUNET_assert (current_peer->nse_handle != NULL);
338     }
339     current_peer->stats = GNUNET_STATISTICS_create("profiler", current_peer->daemon->cfg);
340     GNUNET_STATISTICS_get(current_peer->stats, "core", NULL, GNUNET_TIME_UNIT_FOREVER_REL,
341                           &core_stats_cont, &core_stats_iterator, current_peer);
342     GNUNET_STATISTICS_get(current_peer->stats, "transport", NULL, GNUNET_TIME_UNIT_FOREVER_REL,
343                           NULL, &core_stats_iterator, current_peer);
344     GNUNET_STATISTICS_get(current_peer->stats, "nse", NULL, GNUNET_TIME_UNIT_FOREVER_REL,
345                           NULL, &core_stats_iterator, current_peer);
346     GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
347   }
348 }
349
350
351 static void
352 churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
353
354
355 /**
356  * Continuation called by the "get_all" and "get" functions.
357  *
358  * @param cls struct StatsContext
359  * @param success GNUNET_OK if statistics were
360  *        successfully obtained, GNUNET_SYSERR if not.
361  */
362 static void
363 stats_finished_callback (void *cls, int success)
364 {
365   struct StatsContext *stats_context = cls;
366   char *buf;
367   int buf_len;
368
369   if ((GNUNET_OK == success) && (data_file != NULL))
370   {
371     /* Stats lookup successful, write out data */
372     buf = NULL;
373     buf_len =
374         GNUNET_asprintf (&buf, "TOTAL_NSE_BYTES: %u\n",
375                          stats_context->total_nse_bytes);
376     if (buf_len > 0)
377     {
378       GNUNET_DISK_file_write (data_file, buf, buf_len);
379     }
380     GNUNET_free_non_null (buf);
381   }
382
383   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == shutdown_handle);
384   shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
385   GNUNET_free (stats_context);
386 }
387
388
389 /**
390  * Callback function to process statistic values.
391  *
392  * @param cls struct StatsContext
393  * @param peer the peer the statistics belong to
394  * @param subsystem name of subsystem that created the statistic
395  * @param name the name of the datum
396  * @param value the current value
397  * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
398  * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
399  */
400 static int
401 statistics_iterator (void *cls, const struct GNUNET_PeerIdentity *peer,
402                      const char *subsystem, const char *name, uint64_t value,
403                      int is_persistent)
404 {
405   struct StatsContext *stats_context = cls;
406
407   if ((0 == strstr (subsystem, "nse")) &&
408       (0 == strstr (name, "# flood messages received")))
409     stats_context->total_nse_bytes += value;
410   return GNUNET_OK;
411 }
412
413
414 static void
415 disconnect_nse_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
416 {
417   struct NSEPeer *pos;
418   char *buf;
419   struct StatsContext *stats_context;
420
421   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting nse service of peers\n");
422   disconnect_task = GNUNET_SCHEDULER_NO_TASK;
423   pos = peer_head;
424   while (NULL != (pos = peer_head))
425   {
426     if (pos->nse_handle != NULL)
427     {
428       GNUNET_NSE_disconnect (pos->nse_handle);
429       pos->nse_handle = NULL;
430     }
431     GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
432     GNUNET_free (pos);
433   }
434
435   GNUNET_asprintf (&buf, "round%llu", current_round);
436   if (GNUNET_OK ==
437       GNUNET_CONFIGURATION_get_value_number (testing_cfg, "nse-profiler", buf,
438                                              &peers_next_round))
439   {
440     current_round++;
441     GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK);
442     churn_task = GNUNET_SCHEDULER_add_now (&churn_peers, NULL);
443   }
444   else                          /* No more rounds, let's shut it down! */
445   {
446     stats_context = GNUNET_malloc (sizeof (struct StatsContext));
447     GNUNET_SCHEDULER_cancel (shutdown_handle);
448     shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
449     GNUNET_TESTING_get_statistics (pg, &stats_finished_callback,
450                                    &statistics_iterator, stats_context);
451   }
452   GNUNET_free (buf);
453 }
454
455
456 /**
457  * FIXME.
458  *
459  * @param cls unused
460  * @param emsg NULL on success
461  */
462 static void
463 topology_output_callback (void *cls, const char *emsg)
464 {
465   disconnect_task =
466       GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_nse_peers, NULL);
467   GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
468 }
469
470
471 /**
472  * FIXME.
473  *
474  * @param cls closure
475  * @param emsg NULL on success
476  */
477 static void
478 churn_callback (void *cls, const char *emsg)
479 {
480   char *temp_output_file;
481
482   if (emsg == NULL)             /* Everything is okay! */
483   {
484     peers_running = peers_next_round;
485     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
486                 "Round %llu, churn finished successfully.\n", current_round);
487     GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
488     GNUNET_asprintf (&temp_output_file, "%s_%llu.dot", topology_file,
489                      current_round);
490     GNUNET_TESTING_peergroup_topology_to_file (pg, temp_output_file,
491                                                &topology_output_callback, NULL);
492     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Writing topology to file %s\n",
493                 temp_output_file);
494     GNUNET_free (temp_output_file);
495   }
496   else
497   {
498     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %llu, churn FAILED!!\n",
499                 current_round);
500     GNUNET_SCHEDULER_cancel (shutdown_handle);
501     shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
502   }
503 }
504
505
506 static void
507 churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
508 {
509   /* peers_running = GNUNET_TESTING_daemons_running(pg); */
510   churn_task = GNUNET_SCHEDULER_NO_TASK;
511   if (peers_next_round == peers_running)
512   {
513     /* Nothing to do... */
514     GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
515     GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
516     disconnect_task =
517         GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_nse_peers, NULL);
518     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n",
519                 current_round);
520   }
521   else
522   {
523     if (peers_next_round > num_peers)
524     {
525       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
526                   "Asked to turn on more peers than we have!!\n");
527       GNUNET_SCHEDULER_cancel (shutdown_handle);
528       GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
529     }
530     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
531                 "Round %llu, turning off %llu peers, turning on %llu peers!\n",
532                 current_round,
533                 (peers_running >
534                  peers_next_round) ? peers_running - peers_next_round : 0,
535                 (peers_next_round >
536                  peers_running) ? peers_next_round - peers_running : 0);
537     GNUNET_TESTING_daemons_churn (pg, "nse",
538                                   (peers_running >
539                                    peers_next_round) ? peers_running -
540                                   peers_next_round : 0,
541                                   (peers_next_round >
542                                    peers_running) ? peers_next_round -
543                                   peers_running : 0, wait_time, &churn_callback,
544                                   NULL);
545   }
546 }
547
548
549 static void
550 nse_started_cb (void *cls, const char *emsg)
551 {
552   GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
553   disconnect_task =
554       GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_nse_peers, NULL);
555 }
556
557
558 static void
559 my_cb (void *cls, const char *emsg)
560 {
561   char *buf;
562   int buf_len;
563
564   if (emsg != NULL)
565   {
566     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
567                 "Peergroup callback called with error, aborting test!\n");
568     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
569     ok = 1;
570     GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
571     return;
572   }
573 #if VERBOSE
574   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
575               "Peer Group started successfully, connecting to NSE service for each peer!\n");
576 #endif
577   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n",
578               total_connections);
579   if (data_file != NULL)
580   {
581     buf = NULL;
582     buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
583     if (buf_len > 0)
584       GNUNET_DISK_file_write (data_file, buf, buf_len);
585     GNUNET_free (buf);
586   }
587   peers_running = GNUNET_TESTING_daemons_running (pg);
588   GNUNET_TESTING_daemons_start_service (pg, "nse", wait_time, &nse_started_cb,
589                                         NULL);
590
591 }
592
593
594 /**
595  * Function that will be called whenever two daemons are connected by
596  * the testing library.
597  *
598  * @param cls closure
599  * @param first peer id for first daemon
600  * @param second peer id for the second daemon
601  * @param distance distance between the connected peers
602  * @param first_cfg config for the first daemon
603  * @param second_cfg config for the second daemon
604  * @param first_daemon handle for the first daemon
605  * @param second_daemon handle for the second daemon
606  * @param emsg error message (NULL on success)
607  */
608 static void
609 connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
610             const struct GNUNET_PeerIdentity *second, uint32_t distance,
611             const struct GNUNET_CONFIGURATION_Handle *first_cfg,
612             const struct GNUNET_CONFIGURATION_Handle *second_cfg,
613             struct GNUNET_TESTING_Daemon *first_daemon,
614             struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
615 {
616   if (emsg == NULL)
617     total_connections++;
618 }
619
620
621 static void
622 run (void *cls, char *const *args, const char *cfgfile,
623      const struct GNUNET_CONFIGURATION_Handle *cfg)
624 {
625   char *temp_str;
626   struct GNUNET_TESTING_Host *hosts;
627   char *data_filename;
628
629   ok = 1;
630   //testing_cfg = GNUNET_CONFIGURATION_create ();
631   testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
632 #if VERBOSE
633   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
634   GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
635                                          "use_progressbars", "YES");
636 #endif
637   if (GNUNET_OK !=
638       GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
639                                              "num_peers", &num_peers))
640   {
641     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
642                 "Option TESTING:NUM_PEERS is required!\n");
643     return;
644   }
645
646   if (GNUNET_OK !=
647       GNUNET_CONFIGURATION_get_value_time (testing_cfg, "nse-profiler",
648                                            "WAIT_TIME", &wait_time))
649   {
650     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
651                 "Option nse-profiler:wait_time is required!\n");
652     return;
653   }
654
655   if (GNUNET_OK !=
656       GNUNET_CONFIGURATION_get_value_number (testing_cfg, "nse-profiler",
657                                              "connection_limit",
658                                              &connection_limit))
659   {
660     connection_limit = 0;
661   }
662
663   if (GNUNET_OK !=
664       GNUNET_CONFIGURATION_get_value_string (testing_cfg, "nse-profiler",
665                                              "topology_output_file",
666                                              &topology_file))
667   {
668     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
669                 "Option nse-profiler:topology_output_file is required!\n");
670     return;
671   }
672
673   if (GNUNET_OK ==
674       GNUNET_CONFIGURATION_get_value_string (testing_cfg, "nse-profiler",
675                                              "data_output_file",
676                                              &data_filename))
677   {
678     data_file =
679         GNUNET_DISK_file_open (data_filename,
680                                GNUNET_DISK_OPEN_READWRITE |
681                                GNUNET_DISK_OPEN_CREATE,
682                                GNUNET_DISK_PERM_USER_READ |
683                                GNUNET_DISK_PERM_USER_WRITE);
684     if (data_file == NULL)
685       GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
686                   data_filename);
687     GNUNET_free (data_filename);
688   }
689
690   if (GNUNET_YES ==
691       GNUNET_CONFIGURATION_get_value_string (cfg, "nse-profiler", "output_file",
692                                              &temp_str))
693   {
694     output_file =
695         GNUNET_DISK_file_open (temp_str,
696                                GNUNET_DISK_OPEN_READWRITE |
697                                GNUNET_DISK_OPEN_CREATE,
698                                GNUNET_DISK_PERM_USER_READ |
699                                GNUNET_DISK_PERM_USER_WRITE);
700     if (output_file == NULL)
701       GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
702                   temp_str);
703   }
704   GNUNET_free_non_null (temp_str);
705
706   hosts = GNUNET_TESTING_hosts_load (testing_cfg);
707
708   pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
709                                        &connect_cb, &my_cb, NULL, hosts);
710   GNUNET_assert (pg != NULL);
711   shutdown_handle =
712       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
713                                     &shutdown_task, NULL);
714 }
715
716
717
718 /**
719  * nse-profiler command line options
720  */
721 static struct GNUNET_GETOPT_CommandLineOption options[] = {
722   {'V', "verbose", NULL,
723    gettext_noop ("be verbose (print progress information)"),
724    0, &GNUNET_GETOPT_set_one, &verbose},
725   GNUNET_GETOPT_OPTION_END
726 };
727
728
729 int
730 main (int argc, char *argv[])
731 {
732   GNUNET_log_setup ("nse-profiler",
733 #if VERBOSE
734                     "DEBUG",
735 #else
736                     "WARNING",
737 #endif
738                     NULL);
739   GNUNET_PROGRAM_run (argc, argv, "nse-profiler",
740                       gettext_noop
741                       ("Measure quality and performance of the NSE service."),
742                       options, &run, NULL);
743 #if REMOVE_DIR
744   GNUNET_DISK_directory_remove ("/tmp/nse-profiler");
745 #endif
746   return ok;
747 }
748
749 /* end of nse-profiler.c */