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.
17 * @file dht/gnunet-service-dht_nse.c
18 * @brief GNUnet DHT integration with NSE
19 * @author Christian Grothoff
22 #include "gnunet_nse_service.h"
23 #include "gnunet-service-dht.h"
24 #include "gnunet-service-dht_nse.h"
27 * log of the current network size estimate, used as the point where
28 * we switch between random and deterministic routing. Default
29 * value of 4.0 is used if NSE module is not available (i.e. not
32 static double log_of_network_size_estimate = 4.0;
35 * Network size estimation handle.
37 static struct GNUNET_NSE_Handle *nse;
41 * Callback that is called when network size estimate is updated.
44 * @param timestamp time when the estimate was received from the server (or created by the server)
45 * @param logestimate the log(Base 2) value of the current network size estimate
46 * @param std_dev standard deviation for the estimate
50 update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
51 double logestimate, double std_dev)
53 GNUNET_STATISTICS_update (GDS_stats,
54 gettext_noop ("# Network size estimates received"),
56 /* do not allow estimates < 0.5 */
57 log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate);
62 * Return the log of the current network size estimate.
69 return log_of_network_size_estimate;
74 * Initialize NSE subsystem.
79 unsigned long long hops;
82 GNUNET_CONFIGURATION_have_value (GDS_cfg,
86 GNUNET_CONFIGURATION_get_value_number (GDS_cfg,
91 log_of_network_size_estimate = (double) hops;
94 nse = GNUNET_NSE_connect (GDS_cfg, &update_network_size_estimate, NULL);
99 * Shutdown NSE subsystem.
106 GNUNET_NSE_disconnect (nse);
111 /* end of gnunet-service-dht_nse.c */