GNUnet  0.10.x
gnunet-nse.c
Go to the documentation of this file.
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 
27 #include "platform.h"
28 #include "gnunet_nse_service.h"
29 
33 static struct GNUNET_NSE_Handle *nse;
34 
38 static int status;
39 
40 
46 static void
47 do_shutdown(void *cls)
48 {
49  (void)cls;
50  if (NULL != nse)
51  {
53  nse = NULL;
54  }
55 }
56 
57 
67 static void
68 handle_estimate(void *cls,
69  struct GNUNET_TIME_Absolute timestamp,
70  double estimate,
71  double std_dev)
72 {
73  (void)cls;
74  status = 0;
75  fprintf(stdout,
76  "%llu %f %f %f\n",
77  (unsigned long long)timestamp.abs_value_us,
79  estimate,
80  std_dev);
81 }
82 
83 
92 static void
93 run(void *cls,
94  char *const *args,
95  const char *cfgfile,
96  const struct GNUNET_CONFIGURATION_Handle *cfg)
97 {
98  (void)cls;
99  (void)args;
100  (void)cfgfile;
101  nse = GNUNET_NSE_connect(cfg, &handle_estimate, NULL);
103 }
104 
105 
111 int
112 main(int argc, char *const *argv)
113 {
114  static struct GNUNET_GETOPT_CommandLineOption options[] = {
116  };
117 
118  status = 1;
119  if (GNUNET_OK !=
120  GNUNET_PROGRAM_run(argc,
121  argv,
122  "gnunet-nse",
123  gettext_noop(
124  "Show network size estimates from NSE service."),
125  options,
126  &run,
127  NULL))
128  return 2;
129  return status;
130 }
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
struct GNUNET_NSE_Handle * GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NSE_Callback func, void *func_cls)
Connect to the network size estimation service.
Definition: nse_api.c:164
int main(int argc, char *const *argv)
Main function.
Definition: gnunet-nse.c:112
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Actual main function that runs the emulation.
Definition: gnunet-nse.c:93
Definition of a command line option.
static struct GNUNET_NSE_Handle * nse
The handle to the NSE service.
Definition: gnunet-nse.c:33
uint64_t abs_value_us
The actual value.
static int status
The program status; 0 for success.
Definition: gnunet-nse.c:38
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static void do_shutdown(void *cls)
Task to shutdown and clean up all state.
Definition: gnunet-nse.c:47
void GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h)
Disconnect from network size estimation service.
Definition: nse_api.c:192
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
Handle for talking with the NSE service.
Definition: nse_api.c:40
configuration data
Definition: configuration.c:83
int GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:367
Time for absolute times used by GNUnet, in microseconds.
static void handle_estimate(void *cls, struct GNUNET_TIME_Absolute timestamp, double estimate, double std_dev)
Callback to call when network size estimate is updated.
Definition: gnunet-nse.c:68
#define GNUNET_NSE_log_estimate_to_n(loge)
Convert the logarithmic estimated returned to the &#39;GNUNET_NSE_Callback&#39; into an absolute estimate in ...
#define gettext_noop(String)
Definition: gettext.h:69