GNUnet  0.11.x
gnunet-service-dht_nse.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009, 2010, 2011 GNUnet e.V.
4 
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.
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  Affero General Public License for more details.
14 
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/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
26 #include "platform.h"
27 #include "gnunet_nse_service.h"
28 #include "gnunet-service-dht.h"
29 #include "gnunet-service-dht_nse.h"
30 
37 static double log_of_network_size_estimate = 4.0;
38 
42 static struct GNUNET_NSE_Handle *nse;
43 
44 
54 static void
56  double logestimate, double std_dev)
57 {
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 
71 double
73 {
75 }
76 
77 
81 void
83 {
84  unsigned long long hops;
85 
86  if ((GNUNET_YES ==
88  "dht",
89  "FORCE_NSE")) &&
90  (GNUNET_OK ==
92  "dht",
93  "FORCE_NSE",
94  &hops)))
95  {
96  log_of_network_size_estimate = (double) hops;
97  return;
98  }
100 }
101 
102 
106 void
108 {
109  if (NULL != nse)
110  {
111  GNUNET_NSE_disconnect (nse);
112  nse = NULL;
113  }
114 }
115 
116 
117 /* end of gnunet-service-dht_nse.c */
GNUnet DHT globals.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
struct GNUNET_NSE_Handle * GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NSE_Callback func, void *func_cls)
Connect to the network size estimation service.
Definition: nse_api.c:165
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GDS_NSE_init()
Initialize NSE subsystem.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GDS_NSE_done()
Shutdown NSE subsystem.
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:82
int GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
static void update_network_size_estimate(void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)
Callback that is called when network size estimate is updated.
void GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h)
Disconnect from network size estimation service.
Definition: nse_api.c:193
static struct GNUNET_NSE_Handle * nse
Network size estimation handle.
Handle for talking with the NSE service.
Definition: nse_api.c:40
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:77
double GDS_NSE_get()
Return the log of the current network size estimate.
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
GNUnet DHT integration with NSE.
static double log_of_network_size_estimate
log of the current network size estimate, used as the point where we switch between random and determ...
#define gettext_noop(String)
Definition: gettext.h:69