-merge branch 'master' into identity_oidc
[oweals/gnunet.git] / src / include / gnunet_nse_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2011 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18       Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef GNUNET_NSE_SERVICE_H_
22 #define GNUNET_NSE_SERVICE_H_
23
24 /**
25  * @author Nathan Evans
26  *
27  * @file
28  * API to retrieve the current network size estimate
29  *
30  * @defgroup nse  NSE service
31  * Network Size Estimation
32  *
33  * Provides an API to retrieve the current network size estimate,
34  * also to register for notifications whenever a new
35  * network size estimate is calculated.
36  *
37  * @see [Documentation](https://gnunet.org/gnunet-nse-subsystem)
38  *
39  * @{
40  */
41
42 #ifdef __cplusplus
43 extern "C"
44 {
45 #if 0                           /* keep Emacsens' auto-indent happy */
46 }
47 #endif
48 #endif
49
50 #include "gnunet_util_lib.h"
51
52 /**
53  * Version of the network size estimation API.
54  */
55 #define GNUNET_NSE_VERSION 0x00000000
56
57 /**
58  * Handle for the network size estimation service.
59  */
60 struct GNUNET_NSE_Handle;
61
62 /**
63  * Callback to call when network size estimate is updated.
64  *
65  * @param cls closure
66  * @param timestamp time when the estimate was received from the server (or created by the server)
67  * @param logestimate the log(Base 2) value of the current network size estimate
68  * @param std_dev standard deviation for the estimate
69  *
70  */
71 typedef void (*GNUNET_NSE_Callback) (void *cls,
72                                      struct GNUNET_TIME_Absolute timestamp,
73                                      double logestimate, double std_dev);
74
75
76 /**
77  * Convert the logarithmic estimated returned to the 'GNUNET_NSE_Callback'
78  * into an absolute estimate in terms of the number of peers in the network.
79  *
80  * @param loge logarithmic estimate
81  * @return absolute number of peers in the network (estimated)
82  */
83 #define GNUNET_NSE_log_estimate_to_n(loge) pow(2.0, (loge))
84
85
86 /**
87  * Connect to the network size estimation service.
88  *
89  * @param cfg the configuration to use
90  * @param func funtion to call with network size estimate
91  * @param func_cls closure to pass to @a func
92  * @return handle to use in #GNUNET_NSE_disconnect to stop NSE from invoking the callbacks
93  */
94 struct GNUNET_NSE_Handle *
95 GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
96                     GNUNET_NSE_Callback func, void *func_cls);
97
98
99 /**
100  * Disconnect from network size estimation service
101  *
102  * @param h handle to destroy
103  */
104 void
105 GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h);
106
107
108 #if 0                           /* keep Emacsens' auto-indent happy */
109 {
110 #endif
111 #ifdef __cplusplus
112 }
113 #endif
114
115 /** @} */ /* end of group nse */
116
117 #endif /* GNUNET_NSE_SERVICE_H_ */