aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-wdht_nse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-service-wdht_nse.c')
-rw-r--r--src/dht/gnunet-service-wdht_nse.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/dht/gnunet-service-wdht_nse.c b/src/dht/gnunet-service-wdht_nse.c
new file mode 100644
index 000000000..4cce88f6e
--- /dev/null
+++ b/src/dht/gnunet-service-wdht_nse.c
@@ -0,0 +1,116 @@
1/*
2 This file is part of GNUnet.
3 Copyright (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-xdht_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-wdht.h"
29#include "gnunet-service-wdht_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 */
37static double log_of_network_size_estimate = 4.0;
38
39/**
40 * Network size estimation handle.
41 */
42static 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 */
54static void
55update_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"),
60 1, GNUNET_NO);
61 /* do not allow estimates < 0.5 */
62 log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate);
63}
64
65
66/**
67 * Return the log of the current network size estimate.
68 *
69 * @return log of NSE
70 */
71double
72GDS_NSE_get ()
73{
74 return log_of_network_size_estimate;
75}
76
77
78/**
79 * Initialize NSE subsystem.
80 */
81void
82GDS_NSE_init ()
83{
84 unsigned long long hops;
85
86 if ( (GNUNET_YES ==
87 GNUNET_CONFIGURATION_have_value (GDS_cfg,
88 "dht",
89 "FORCE_NSE")) &&
90 (GNUNET_OK ==
91 GNUNET_CONFIGURATION_get_value_number (GDS_cfg,
92 "dht",
93 "FORCE_NSE",
94 &hops)) )
95 {
96 log_of_network_size_estimate = (double) hops;
97 return;
98 }
99 nse = GNUNET_NSE_connect (GDS_cfg, &update_network_size_estimate, NULL);
100}
101
102
103/**
104 * Shutdown NSE subsystem.
105 */
106void
107GDS_NSE_done ()
108{
109 if (NULL != nse)
110 {
111 GNUNET_NSE_disconnect (nse);
112 nse = NULL;
113 }
114}
115
116/* end of gnunet-service-dht_nse.c */