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