print stat
[oweals/gnunet.git] / src / dht / gnunet-service-dht_nse.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010, 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 /**
22  * @file dht/gnunet-service-dht_nse.c
23  * @brief GNUnet DHT integration with NSE
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_nse_service.h"
28 #include "gnunet-service-dht.h"
29 #include "gnunet-service-dht_nse.h"
30
31 /**
32  * log of the current network size estimate, used as the point where
33  * we switch between random and deterministic routing.  Default
34  * value of 4.0 is used if NSE module is not available (i.e. not
35  * configured).
36  */
37 static double log_of_network_size_estimate = 4.0;
38
39 /**
40  * Network size estimation handle.
41  */
42 static struct GNUNET_NSE_Handle *nse;
43
44
45 /**
46  * Callback that is called when network size estimate is updated.
47  *
48  * @param cls closure
49  * @param timestamp time when the estimate was received from the server (or created by the server)
50  * @param logestimate the log(Base 2) value of the current network size estimate
51  * @param std_dev standard deviation for the estimate
52  *
53  */
54 static void
55 update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
56                               double logestimate, double std_dev)
57 {
58   GNUNET_STATISTICS_update (GDS_stats,
59                             gettext_noop ("# Network size estimates received"), 1,
60                             GNUNET_NO);
61   log_of_network_size_estimate = logestimate;
62 }
63
64
65 /**
66  * Return the log of the current network size estimate.
67  *
68  * @return log of NSE
69  */
70 double
71 GDS_NSE_get ()
72 {
73   return log_of_network_size_estimate;
74 }
75
76
77 /**
78  * Initialize NSE subsystem.
79  */
80 void
81 GDS_NSE_init ()
82 {
83   nse = GNUNET_NSE_connect (GDS_cfg, &update_network_size_estimate, NULL);
84 }
85
86
87 /**
88  * Shutdown NSE subsystem.
89  */
90 void
91 GDS_NSE_done ()
92 {  
93   if (NULL != nse)
94     {
95     GNUNET_NSE_disconnect (nse);
96     nse = NULL;
97   }
98 }
99
100 /* end of gnunet-service-dht_nse.c */