GNUnet  0.19.5
gnunet-service-ats_normalization.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011-2015 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 
27 #include "platform.h"
28 #include <float.h>
29 #include "gnunet_ats_service.h"
33 
34 #define LOG(kind, ...) GNUNET_log_from (kind, "ats-normalization", __VA_ARGS__)
35 
36 
41 {
46 
51 };
52 
53 
57 static struct PropertyRange property_range;
58 
59 
67 static void
68 update_avg (uint64_t current_val,
69  struct GAS_NormalizationInfo *ni)
70 {
71  double sum;
72  uint32_t count;
73  unsigned int c1;
74 
75  ni->atsi_abs[ni->avg_queue_index++] = current_val;
77  ni->avg_queue_index = 0;
78  count = 0;
79  sum = 0.0;
80  for (c1 = 0; c1 < GAS_normalization_queue_length; c1++)
81  {
82  if (UINT64_MAX != ni->atsi_abs[c1])
83  {
84  count++;
85  sum += (double) ni->atsi_abs[c1];
86  }
87  }
88  if (0 == count)
89  ni->avg = current_val; /* must be UINT64_MAX */
90  else
91  ni->avg = sum / count;
92 }
93 
94 
105 static int
106 find_min_max_it (void *cls,
107  const struct GNUNET_PeerIdentity *h,
108  void *k)
109 {
110  struct PropertyRange *pr = cls;
111  const struct ATS_Address *a = k;
112 
117  pr->max.distance = GNUNET_MAX (pr->max.distance,
118  a->properties.distance);
120  a->properties.delay);
125  pr->min.distance = GNUNET_MIN (pr->min.distance,
126  a->properties.distance);
128  a->properties.delay);
129  return GNUNET_OK;
130 }
131 
132 
141 static void
142 update_norm (uint64_t min,
143  uint64_t max,
144  struct GAS_NormalizationInfo *ni)
145 {
146  /* max - 2 * min + avg_value / (max - min) */
147  if (min < max)
148  ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double) (max - min);
149  else
151 }
152 
153 
165 static int
166 normalize_address (void *cls,
167  const struct GNUNET_PeerIdentity *key,
168  void *value)
169 {
170  struct ATS_Address *address = value;
171 
174  &address->norm_delay);
177  &address->norm_distance);
180  &address->norm_utilization_in);
183  &address->norm_utilization_out);
184  return GNUNET_OK;
185 }
186 
187 
196 static int
197 notify_change (void *cls,
198  const struct GNUNET_PeerIdentity *key,
199  void *value)
200 {
201  struct ATS_Address *address = value;
202 
204  return GNUNET_OK;
205 }
206 
207 
214 static void
216 {
217  memset (pr, 0, sizeof(struct PropertyRange));
218  pr->min.utilization_out = UINT32_MAX;
219  pr->min.utilization_in = UINT32_MAX;
220  pr->min.distance = UINT32_MAX;
222 }
223 
224 
230 void
232 {
233  const struct GNUNET_ATS_Properties *prop = &address->properties;
234  struct PropertyRange range;
235 
237  "Updating properties for peer `%s'\n",
238  GNUNET_i2s (&address->peer));
241  &address->norm_delay);
242  update_avg (prop->distance,
243  &address->norm_distance);
244  update_avg (prop->utilization_in,
245  &address->norm_utilization_in);
246  update_avg (prop->utilization_in,
247  &address->norm_utilization_out);
248 
249  init_range (&range);
252  &range);
253  if (0 != GNUNET_memcmp (&range,
254  &property_range))
255  {
256  /* limits changed, (re)normalize all addresses */
257  property_range = range;
260  NULL);
262  &notify_change,
263  NULL);
264  }
265  else
266  {
267  /* renormalize just this one address */
268  normalize_address (NULL,
269  &address->peer,
270  address);
271  notify_change (NULL,
272  &address->peer,
273  address);
274  }
276 }
277 
278 
282 void
284 {
286 }
287 
288 
292 void
294 {
295  /* nothing to do */
296 }
297 
298 
299 /* end of gnunet-service-ats_normalization.c */
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static char * address
GNS address for this phone.
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
#define GAS_normalization_queue_length
struct GNUNET_CONTAINER_MultiPeerMap * GSA_addresses
A multihashmap to store all addresses.
ats service address management
static struct PropertyRange property_range
Range information for all quality properties we see.
static void update_norm(uint64_t min, uint64_t max, struct GAS_NormalizationInfo *ni)
Compute the normalized value from the given ni range data and the average value.
void GAS_normalization_stop()
Stop the normalization component and free all items.
static int find_min_max_it(void *cls, const struct GNUNET_PeerIdentity *h, void *k)
Function called for all addresses and peers to find the minimum and maximum (averaged) values for a g...
void GAS_normalization_start()
Start the normalization component.
static int normalize_address(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Normalize the property value for a given address based on the range we know that property values have...
static void init_range(struct PropertyRange *pr)
Initialize property range to the values corresponding to an empty set.
static void update_avg(uint64_t current_val, struct GAS_NormalizationInfo *ni)
Add the value from atsi to the running average of the given ni quality property.
#define LOG(kind,...)
static int notify_change(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Notify about change in normalized property.
void GAS_normalization_update_property(struct ATS_Address *address)
Update and normalize atsi performance information.
ats service address: management of ATS properties and preferences normalization
#define DEFAULT_REL_QUALITY
Value we return for a normalized quality score if we have no data.
void GAS_plugin_solver_unlock()
Resume instant solving, we are done with the bulk state updates.
void GAS_plugin_notify_property_changed(struct ATS_Address *address)
The relative value for a property changed.
void GAS_plugin_solver_lock()
Stop instant solving, there are many state updates happening in bulk right now.
ats service plugin management
Automatic transport selection and outbound bandwidth determination.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_MAX(a, b)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_MIN(a, b)
@ GNUNET_OK
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:343
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_relative_max(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the maximum of two relative time values.
Definition: time.c:351
#define min(x, y)
#define max(x, y)
Address with additional information.
struct GNUNET_ATS_Properties properties
ATS performance information for this address.
Information provided by ATS normalization.
uint64_t atsi_abs[3]
Averaging queue.
double norm
Normalized values from queue to a range of values [1.0...2.0].
unsigned int avg_queue_index
Next index to use in averaging queue.
uint64_t avg
Averaged ATSI values from queue.
ATS performance characteristics for an address.
uint32_t utilization_in
Actual traffic on this connection from the other peer to this peer.
unsigned int distance
Distance on network layer (required for distance-vector routing) in hops.
struct GNUNET_TIME_Relative delay
Delay.
uint32_t utilization_out
Actual traffic on this connection from this peer to the other peer.
The identity of the host (wraps the signing key of the peer).
uint64_t rel_value_us
The actual value.
Range information for normalization of quality properties.
struct GNUNET_ATS_Properties min
Minimum value we see for this property across all addresses.
struct GNUNET_ATS_Properties max
Maximum value we see for this property across all addresses.