2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2011 GNUnet e.V.
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.
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.
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/>.
20 * @file dht/gnunet-service-dht_nse.c
21 * @brief GNUnet DHT integration with NSE
22 * @author Christian Grothoff
25 #include "gnunet_nse_service.h"
26 #include "gnunet-service-dht.h"
27 #include "gnunet-service-dht_nse.h"
30 * log of the current network size estimate, used as the point where
31 * we switch between random and deterministic routing. Default
32 * value of 4.0 is used if NSE module is not available (i.e. not
35 static double log_of_network_size_estimate = 4.0;
38 * Network size estimation handle.
40 static struct GNUNET_NSE_Handle *nse;
44 * Callback that is called when network size estimate is updated.
47 * @param timestamp time when the estimate was received from the server (or created by the server)
48 * @param logestimate the log(Base 2) value of the current network size estimate
49 * @param std_dev standard deviation for the estimate
53 update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
54 double logestimate, double std_dev)
56 GNUNET_STATISTICS_update (GDS_stats,
57 gettext_noop ("# Network size estimates received"),
59 /* do not allow estimates < 0.5 */
60 log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate);
65 * Return the log of the current network size estimate.
72 return log_of_network_size_estimate;
77 * Initialize NSE subsystem.
82 unsigned long long hops;
85 GNUNET_CONFIGURATION_have_value (GDS_cfg,
89 GNUNET_CONFIGURATION_get_value_number (GDS_cfg,
94 log_of_network_size_estimate = (double) hops;
97 nse = GNUNET_NSE_connect (GDS_cfg, &update_network_size_estimate, NULL);
102 * Shutdown NSE subsystem.
109 GNUNET_NSE_disconnect (nse);
114 /* end of gnunet-service-dht_nse.c */