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