aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2014-04-07 09:41:26 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2014-04-07 09:41:26 +0000
commit906f67b113fa2a9b27ab7a333d1e25cb0b500140 (patch)
tree651597190f6e30d97ce46cd4c1d692004015c6a3
parentdf0a5da00aeb71ec3e6eb5937e800f2e6fd269ee (diff)
downloadgnunet-906f67b113fa2a9b27ab7a333d1e25cb0b500140.tar.gz
gnunet-906f67b113fa2a9b27ab7a333d1e25cb0b500140.zip
Add gnunet-nse program to show network size estimates.
-rw-r--r--src/nse/Makefile.am9
-rw-r--r--src/nse/gnunet-nse.c172
2 files changed, 181 insertions, 0 deletions
diff --git a/src/nse/Makefile.am b/src/nse/Makefile.am
index 6c6a9d8e0..a9d8bc15c 100644
--- a/src/nse/Makefile.am
+++ b/src/nse/Makefile.am
@@ -16,6 +16,15 @@ libexecdir= $(pkglibdir)/libexec/
16pkgcfg_DATA = \ 16pkgcfg_DATA = \
17 nse.conf 17 nse.conf
18 18
19bin_PROGRAMS = gnunet-nse
20
21gnunet_nse_SOURCES = gnunet-nse.c
22gnunet_nse_LDFLAGS = \
23 libgnunetnse.la \
24 $(top_builddir)/src/util/libgnunetutil.la \
25 $(XLIB) $(GN_LIBINTL)
26gnunet_nse_DEPENDENCIES = \
27 $(top_builddir)/src/util/libgnunetutil.la
19 28
20lib_LTLIBRARIES = libgnunetnse.la 29lib_LTLIBRARIES = libgnunetnse.la
21 30
diff --git a/src/nse/gnunet-nse.c b/src/nse/gnunet-nse.c
new file mode 100644
index 000000000..ec2ad26d3
--- /dev/null
+++ b/src/nse/gnunet-nse.c
@@ -0,0 +1,172 @@
1/*
2 This file is part of GNUnet
3 (C) 2008--2014 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/**
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>
25 */
26
27#include "platform.h"
28#include "gnunet_nse_service.h"
29
30/**
31 * Handle to our configuration
32 */
33static struct GNUNET_CONFIGURATION_Handle *cfg;
34
35/**
36 * The handle to the NSE service
37 */
38static struct GNUNET_NSE_Handle *nse;
39
40/**
41 * The handle to test if NSE service is running or not
42 */
43static struct GNUNET_CLIENT_TestHandle *test;
44
45/**
46 * Shutdown task
47 */
48static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
49
50/**
51 * The program status; 0 for success.
52 */
53static int status;
54
55
56/**
57 * Task to shutdown and clean up all state
58 *
59 * @param cls NULL
60 * @param tc the scheduler task context
61 */
62static void
63do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
64{
65 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
66 if (NULL != test)
67 GNUNET_CLIENT_service_test_cancel (test);
68 if (NULL != nse)
69 GNUNET_NSE_disconnect (nse);
70 if (NULL != cfg)
71 GNUNET_CONFIGURATION_destroy (cfg);
72}
73
74
75/**
76 * Callback to call when network size estimate is updated.
77 *
78 * @param cls NULL
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
83 */
84static void
85handle_estimate (void *cls,
86 struct GNUNET_TIME_Absolute timestamp,
87 double estimate, double std_dev)
88{
89 FPRINTF (stdout, "%llu %f %f %f\n",
90 (unsigned long long) timestamp.abs_value_us,
91 GNUNET_NSE_log_estimate_to_n (estimate),
92 estimate,
93 std_dev);
94}
95
96
97/**
98 * Function called with the result on the service test for the NSE service
99 *
100 * @param cls NULL
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
104 */
105static void
106nse_test_result (void *cls, int result)
107{
108 test = NULL;
109 switch (result)
110 {
111 case GNUNET_YES:
112 nse = GNUNET_NSE_connect (cfg, &handle_estimate, NULL);
113 status = 0;
114 break;
115 case GNUNET_NO:
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
117 _("NSE service is not running\n"));
118 GNUNET_SCHEDULER_shutdown ();
119 return;
120 default:
121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
122 _("Error while checking if NSE service is running or not\n"));
123 GNUNET_SCHEDULER_shutdown ();
124 return;
125 }
126}
127
128
129/**
130 * Actual main function that runs the emulation.
131 *
132 * @param cls unused
133 * @param args remaining args, unused
134 * @param cfgfile name of the configuration
135 * @param cfg configuration handle
136 */
137static void
138run (void *cls, char *const *args, const char *cfgfile,
139 const struct GNUNET_CONFIGURATION_Handle *_cfg)
140{
141 cfg = GNUNET_CONFIGURATION_dup (_cfg);
142 test = GNUNET_CLIENT_service_test ("nse",
143 cfg,
144 GNUNET_TIME_UNIT_SECONDS,
145 nse_test_result,
146 NULL);
147 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
148 &do_shutdown, NULL);
149}
150
151
152/**
153 * Main function.
154 *
155 * @return 0 on success
156 */
157int
158main (int argc, char *const *argv)
159{
160 static struct GNUNET_GETOPT_CommandLineOption options[] = {
161 GNUNET_GETOPT_OPTION_END
162 };
163
164 status = 1;
165 if (GNUNET_OK !=
166 GNUNET_PROGRAM_run (argc, argv, "gnunet-nse",
167 gettext_noop
168 ("Show network size estimates from NSE service."),
169 options, &run, NULL))
170 return 2;
171 return status;
172}