diff options
Diffstat (limited to 'src/cli/nse')
-rw-r--r-- | src/cli/nse/.gitignore | 1 | ||||
-rw-r--r-- | src/cli/nse/Makefile.am | 19 | ||||
-rw-r--r-- | src/cli/nse/gnunet-nse.c | 143 | ||||
-rw-r--r-- | src/cli/nse/meson.build | 7 |
4 files changed, 170 insertions, 0 deletions
diff --git a/src/cli/nse/.gitignore b/src/cli/nse/.gitignore new file mode 100644 index 000000000..ec3c6a9cf --- /dev/null +++ b/src/cli/nse/.gitignore | |||
@@ -0,0 +1 @@ | |||
gnunet-nse | |||
diff --git a/src/cli/nse/Makefile.am b/src/cli/nse/Makefile.am new file mode 100644 index 000000000..e724a22d3 --- /dev/null +++ b/src/cli/nse/Makefile.am | |||
@@ -0,0 +1,19 @@ | |||
1 | # This Makefile.am is in the public domain | ||
2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include | ||
3 | |||
4 | if USE_COVERAGE | ||
5 | AM_CFLAGS = --coverage -O0 | ||
6 | XLIB = -lgcov | ||
7 | endif | ||
8 | |||
9 | pkgcfgdir= $(pkgdatadir)/config.d/ | ||
10 | |||
11 | libexecdir= $(pkglibdir)/libexec/ | ||
12 | |||
13 | bin_PROGRAMS = gnunet-nse | ||
14 | |||
15 | gnunet_nse_SOURCES = gnunet-nse.c | ||
16 | gnunet_nse_LDADD = \ | ||
17 | $(top_builddir)/src/service/nse/libgnunetnse.la \ | ||
18 | $(top_builddir)/src/lib/util/libgnunetutil.la \ | ||
19 | $(XLIB) $(GN_LIBINTL) | ||
diff --git a/src/cli/nse/gnunet-nse.c b/src/cli/nse/gnunet-nse.c new file mode 100644 index 000000000..b88697695 --- /dev/null +++ b/src/cli/nse/gnunet-nse.c | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2008--2014, 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
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 | #include <gnunet_util_lib.h> | ||
30 | |||
31 | /** | ||
32 | * The handle to the NSE service | ||
33 | */ | ||
34 | static struct GNUNET_NSE_Handle *nse; | ||
35 | |||
36 | /** | ||
37 | * The program status; 0 for success. | ||
38 | */ | ||
39 | static int status; | ||
40 | |||
41 | /** | ||
42 | * Monitor flag. | ||
43 | */ | ||
44 | static int monitor; | ||
45 | |||
46 | |||
47 | /** | ||
48 | * Task to shutdown and clean up all state | ||
49 | * | ||
50 | * @param cls NULL | ||
51 | */ | ||
52 | static void | ||
53 | do_shutdown (void *cls) | ||
54 | { | ||
55 | (void) cls; | ||
56 | if (NULL != nse) | ||
57 | { | ||
58 | GNUNET_NSE_disconnect (nse); | ||
59 | nse = NULL; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | |||
64 | /** | ||
65 | * Callback to call when network size estimate is updated. | ||
66 | * | ||
67 | * @param cls NULL | ||
68 | * @param timestamp server timestamp | ||
69 | * @param estimate the value of the current network size estimate | ||
70 | * @param std_dev standard deviation (rounded down to nearest integer) | ||
71 | * of the size estimation values seen | ||
72 | */ | ||
73 | static void | ||
74 | handle_estimate (void *cls, | ||
75 | struct GNUNET_TIME_Absolute timestamp, | ||
76 | double estimate, | ||
77 | double std_dev) | ||
78 | { | ||
79 | (void) cls; | ||
80 | status = 0; | ||
81 | fprintf (stdout, | ||
82 | "%s: #peers=%f (ld(#peers)=%f, stddev=%f)\n", | ||
83 | GNUNET_STRINGS_absolute_time_to_string (timestamp), | ||
84 | GNUNET_NSE_log_estimate_to_n (estimate), | ||
85 | estimate, | ||
86 | std_dev); | ||
87 | if (! monitor) | ||
88 | GNUNET_SCHEDULER_shutdown (); | ||
89 | } | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Actual main function that runs the emulation. | ||
94 | * | ||
95 | * @param cls unused | ||
96 | * @param args remaining args, unused | ||
97 | * @param cfgfile name of the configuration | ||
98 | * @param cfg configuration handle | ||
99 | */ | ||
100 | static void | ||
101 | run (void *cls, | ||
102 | char *const *args, | ||
103 | const char *cfgfile, | ||
104 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
105 | { | ||
106 | (void) cls; | ||
107 | (void) args; | ||
108 | (void) cfgfile; | ||
109 | nse = GNUNET_NSE_connect (cfg, &handle_estimate, NULL); | ||
110 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
111 | } | ||
112 | |||
113 | |||
114 | /** | ||
115 | * Main function. | ||
116 | * | ||
117 | * @return 0 on success | ||
118 | */ | ||
119 | int | ||
120 | main (int argc, char *const *argv) | ||
121 | { | ||
122 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
123 | GNUNET_GETOPT_option_flag ('m', | ||
124 | "monitor", | ||
125 | gettext_noop ( | ||
126 | "Monitor and output current estimates"), | ||
127 | &monitor), | ||
128 | GNUNET_GETOPT_OPTION_END | ||
129 | }; | ||
130 | |||
131 | status = 1; | ||
132 | if (GNUNET_OK != | ||
133 | GNUNET_PROGRAM_run (argc, | ||
134 | argv, | ||
135 | "gnunet-nse", | ||
136 | gettext_noop ( | ||
137 | "Show network size estimates from NSE service."), | ||
138 | options, | ||
139 | &run, | ||
140 | NULL)) | ||
141 | return 2; | ||
142 | return status; | ||
143 | } | ||
diff --git a/src/cli/nse/meson.build b/src/cli/nse/meson.build new file mode 100644 index 000000000..584c7eb71 --- /dev/null +++ b/src/cli/nse/meson.build | |||
@@ -0,0 +1,7 @@ | |||
1 | executable ('gnunet-nse', | ||
2 | ['gnunet-nse.c'], | ||
3 | dependencies: [libgnunetnse_dep, m_dep, libgnunetutil_dep], | ||
4 | include_directories: [incdir, configuration_inc], | ||
5 | install: true, | ||
6 | install_dir: get_option('bindir')) | ||
7 | |||