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