GNUnet  0.10.x
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 
40 struct PropertyRange {
45 
50 };
51 
52 
57 
58 
66 static void
67 update_avg(uint64_t current_val,
68  struct GAS_NormalizationInfo *ni)
69 {
70  double sum;
71  uint32_t count;
72  unsigned int c1;
73 
74  ni->atsi_abs[ni->avg_queue_index++] = current_val;
76  ni->avg_queue_index = 0;
77  count = 0;
78  sum = 0.0;
79  for (c1 = 0; c1 < GAS_normalization_queue_length; c1++)
80  {
81  if (UINT64_MAX != ni->atsi_abs[c1])
82  {
83  count++;
84  sum += (double)ni->atsi_abs[c1];
85  }
86  }
87  if (0 == count)
88  ni->avg = current_val; /* must be UINT64_MAX */
89  else
90  ni->avg = sum / count;
91 }
92 
93 
104 static int
105 find_min_max_it(void *cls,
106  const struct GNUNET_PeerIdentity *h,
107  void *k)
108 {
109  struct PropertyRange *pr = cls;
110  const struct ATS_Address *a = k;
111 
116  pr->max.distance = GNUNET_MAX(pr->max.distance,
117  a->properties.distance);
119  a->properties.delay);
124  pr->min.distance = GNUNET_MIN(pr->min.distance,
125  a->properties.distance);
127  a->properties.delay);
128  return GNUNET_OK;
129 }
130 
131 
140 static void
141 update_norm(uint64_t min,
142  uint64_t max,
143  struct GAS_NormalizationInfo *ni)
144 {
145  /* max - 2 * min + avg_value / (max - min) */
146  if (min < max)
147  ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double)(max - min);
148  else
150 }
151 
152 
164 static int
166  const struct GNUNET_PeerIdentity *key,
167  void *value)
168 {
169  struct ATS_Address *address = value;
170 
173  &address->norm_delay);
176  &address->norm_distance);
179  &address->norm_utilization_in);
182  &address->norm_utilization_out);
183  return GNUNET_OK;
184 }
185 
186 
195 static int
196 notify_change(void *cls,
197  const struct GNUNET_PeerIdentity *key,
198  void *value)
199 {
200  struct ATS_Address *address = value;
201 
203  return GNUNET_OK;
204 }
205 
206 
213 static void
215 {
216  memset(pr, 0, sizeof(struct PropertyRange));
217  pr->min.utilization_out = UINT32_MAX;
218  pr->min.utilization_in = UINT32_MAX;
219  pr->min.distance = UINT32_MAX;
221 }
222 
223 
229 void
231 {
232  const struct GNUNET_ATS_Properties *prop = &address->properties;
233  struct PropertyRange range;
234 
236  "Updating properties for peer `%s'\n",
237  GNUNET_i2s(&address->peer));
240  &address->norm_delay);
241  update_avg(prop->distance,
242  &address->norm_distance);
244  &address->norm_utilization_in);
246  &address->norm_utilization_out);
247 
248  init_range(&range);
251  &range);
252  if (0 != GNUNET_memcmp(&range,
253  &property_range))
254  {
255  /* limits changed, (re)normalize all addresses */
256  property_range = range;
259  NULL);
261  &notify_change,
262  NULL);
263  }
264  else
265  {
266  /* renormalize just this one address */
267  normalize_address(NULL,
268  &address->peer,
269  address);
270  notify_change(NULL,
271  &address->peer,
272  address);
273  }
275 }
276 
277 
281 void
283 {
285 }
286 
287 
291 void
293 {
294  /* nothing to do */
295 }
296 
297 
298 /* end of gnunet-service-ats_normalization.c */
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.
unsigned int avg_queue_index
Next index to use in averaging queue.
void GAS_normalization_stop()
Stop the normalization component and free all items.
uint64_t rel_value_us
The actual value.
#define GAS_normalization_queue_length
struct GNUNET_ATS_Properties properties
ATS performance information for this address.
struct GNUNET_ATS_Properties min
Minimum value we see for this property across all addresses.
uint32_t utilization_in
Actual traffic on this connection from the other peer to this peer.
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:287
struct GNUNET_PeerIdentity peer
Peer ID this address is for.
void GAS_plugin_solver_lock()
Stop instant solving, there are many state updates happening in bulk right now.
uint64_t atsi_abs[3]
Averaging queue.
#define DEFAULT_REL_QUALITY
Value we return for a normalized quality score if we have no data.
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...
Range information for normalization of quality properties.
ats service address: management of ATS properties and preferences normalization
ats service plugin management
static struct PropertyRange property_range
Range information for all quality properties we see.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
ATS performance characteristics for an address.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
void GAS_plugin_solver_unlock()
Resume instant solving, we are done with the bulk state updates.
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.
void GAS_plugin_notify_property_changed(struct ATS_Address *address)
The relative value for a property changed.
static char * value
Value of the record to add/remove.
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:82
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:80
struct GNUNET_TIME_Relative delay
Delay.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GAS_NormalizationInfo norm_utilization_out
Normalized utilization outbound for this address.
Information provided by ATS normalization.
uint64_t avg
Averaged ATSI values from queue.
Address with additional information.
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:272
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_CONTAINER_MultiPeerMap * GSA_addresses
A multihashmap to store all addresses.
ats service address management
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
The identity of the host (wraps the signing key of the peer).
struct GAS_NormalizationInfo norm_utilization_in
Normalized utilization inbound for this address.
static void init_range(struct PropertyRange *pr)
Initialize property range to the values corresponding to an empty set.
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...
Automatic transport selection and outbound bandwidth determination.
#define LOG(kind,...)
struct GAS_NormalizationInfo norm_delay
Normalized delay information for this address.
struct GNUNET_ATS_Properties max
Maximum value we see for this property across all addresses.
unsigned int distance
Distance on network layer (required for distance-vector routing) in hops.
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
double norm
Normalized values from queue to a range of values [1.0...2.0].
struct GAS_NormalizationInfo norm_distance
Normalized distance information for this address.
uint32_t utilization_out
Actual traffic on this connection from this peer to the other peer.