2 This file is part of GNUnet
3 (C) 2008--2014 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file nse/gnunet-nse.c
23 * @brief Program to display network size estimates from the NSE service
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
28 #include "gnunet_nse_service.h"
31 * Handle to our configuration
33 static struct GNUNET_CONFIGURATION_Handle *cfg;
36 * The handle to the NSE service
38 static struct GNUNET_NSE_Handle *nse;
41 * The handle to test if NSE service is running or not
43 static struct GNUNET_CLIENT_TestHandle *test;
48 static struct GNUNET_SCHEDULER_Task * shutdown_task;
51 * The program status; 0 for success.
57 * Task to shutdown and clean up all state
60 * @param tc the scheduler task context
63 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
67 GNUNET_CLIENT_service_test_cancel (test);
69 GNUNET_NSE_disconnect (nse);
71 GNUNET_CONFIGURATION_destroy (cfg);
76 * Callback to call when network size estimate is updated.
79 * @param timestamp server timestamp
80 * @param estimate the value of the current network size estimate
81 * @param std_dev standard deviation (rounded down to nearest integer)
82 * of the size estimation values seen
85 handle_estimate (void *cls,
86 struct GNUNET_TIME_Absolute timestamp,
87 double estimate, double std_dev)
89 FPRINTF (stdout, "%llu %f %f %f\n",
90 (unsigned long long) timestamp.abs_value_us,
91 GNUNET_NSE_log_estimate_to_n (estimate),
98 * Function called with the result on the service test for the NSE service
101 * @param result #GNUNET_YES if the service is running,
102 * #GNUNET_NO if the service is not running
103 * #GNUNET_SYSERR if the configuration is invalid
106 nse_test_result (void *cls, int result)
112 nse = GNUNET_NSE_connect (cfg, &handle_estimate, NULL);
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
117 _("NSE service is not running\n"));
118 GNUNET_SCHEDULER_shutdown ();
121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
122 _("Error while checking if NSE service is running or not\n"));
123 GNUNET_SCHEDULER_shutdown ();
130 * Actual main function that runs the emulation.
133 * @param args remaining args, unused
134 * @param cfgfile name of the configuration
135 * @param cfg configuration handle
138 run (void *cls, char *const *args, const char *cfgfile,
139 const struct GNUNET_CONFIGURATION_Handle *_cfg)
141 cfg = GNUNET_CONFIGURATION_dup (_cfg);
142 test = GNUNET_CLIENT_service_test ("nse",
144 GNUNET_TIME_UNIT_SECONDS,
147 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
155 * @return 0 on success
158 main (int argc, char *const *argv)
160 static struct GNUNET_GETOPT_CommandLineOption options[] = {
161 GNUNET_GETOPT_OPTION_END
166 GNUNET_PROGRAM_run (argc, argv, "gnunet-nse",
168 ("Show network size estimates from NSE service."),
169 options, &run, NULL))