diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_normalization.c')
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 193 |
1 files changed, 97 insertions, 96 deletions
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index fa2b37425..36584e944 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c | |||
@@ -31,13 +31,14 @@ | |||
31 | #include "gnunet-service-ats_normalization.h" | 31 | #include "gnunet-service-ats_normalization.h" |
32 | #include "gnunet-service-ats_plugins.h" | 32 | #include "gnunet-service-ats_plugins.h" |
33 | 33 | ||
34 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-normalization", __VA_ARGS__) | 34 | #define LOG(kind, ...) GNUNET_log_from (kind, "ats-normalization", __VA_ARGS__) |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Range information for normalization of quality properties. | 38 | * Range information for normalization of quality properties. |
39 | */ | 39 | */ |
40 | struct PropertyRange { | 40 | struct PropertyRange |
41 | { | ||
41 | /** | 42 | /** |
42 | * Minimum value we see for this property across all addresses. | 43 | * Minimum value we see for this property across all addresses. |
43 | */ | 44 | */ |
@@ -64,8 +65,8 @@ static struct PropertyRange property_range; | |||
64 | * @param ni normalization information to update | 65 | * @param ni normalization information to update |
65 | */ | 66 | */ |
66 | static void | 67 | static void |
67 | update_avg(uint64_t current_val, | 68 | update_avg (uint64_t current_val, |
68 | struct GAS_NormalizationInfo *ni) | 69 | struct GAS_NormalizationInfo *ni) |
69 | { | 70 | { |
70 | double sum; | 71 | double sum; |
71 | uint32_t count; | 72 | uint32_t count; |
@@ -77,13 +78,13 @@ update_avg(uint64_t current_val, | |||
77 | count = 0; | 78 | count = 0; |
78 | sum = 0.0; | 79 | sum = 0.0; |
79 | for (c1 = 0; c1 < GAS_normalization_queue_length; c1++) | 80 | for (c1 = 0; c1 < GAS_normalization_queue_length; c1++) |
81 | { | ||
82 | if (UINT64_MAX != ni->atsi_abs[c1]) | ||
80 | { | 83 | { |
81 | if (UINT64_MAX != ni->atsi_abs[c1]) | 84 | count++; |
82 | { | 85 | sum += (double) ni->atsi_abs[c1]; |
83 | count++; | ||
84 | sum += (double)ni->atsi_abs[c1]; | ||
85 | } | ||
86 | } | 86 | } |
87 | } | ||
87 | if (0 == count) | 88 | if (0 == count) |
88 | ni->avg = current_val; /* must be UINT64_MAX */ | 89 | ni->avg = current_val; /* must be UINT64_MAX */ |
89 | else | 90 | else |
@@ -102,29 +103,29 @@ update_avg(uint64_t current_val, | |||
102 | * @return #GNUNET_OK (continue to iterate) | 103 | * @return #GNUNET_OK (continue to iterate) |
103 | */ | 104 | */ |
104 | static int | 105 | static int |
105 | find_min_max_it(void *cls, | 106 | find_min_max_it (void *cls, |
106 | const struct GNUNET_PeerIdentity *h, | 107 | const struct GNUNET_PeerIdentity *h, |
107 | void *k) | 108 | void *k) |
108 | { | 109 | { |
109 | struct PropertyRange *pr = cls; | 110 | struct PropertyRange *pr = cls; |
110 | const struct ATS_Address *a = k; | 111 | const struct ATS_Address *a = k; |
111 | 112 | ||
112 | pr->max.utilization_out = GNUNET_MAX(pr->max.utilization_out, | 113 | pr->max.utilization_out = GNUNET_MAX (pr->max.utilization_out, |
113 | a->properties.utilization_out); | 114 | a->properties.utilization_out); |
114 | pr->max.utilization_in = GNUNET_MAX(pr->max.utilization_in, | 115 | pr->max.utilization_in = GNUNET_MAX (pr->max.utilization_in, |
115 | a->properties.utilization_in); | 116 | a->properties.utilization_in); |
116 | pr->max.distance = GNUNET_MAX(pr->max.distance, | 117 | pr->max.distance = GNUNET_MAX (pr->max.distance, |
117 | a->properties.distance); | 118 | a->properties.distance); |
118 | pr->max.delay = GNUNET_TIME_relative_max(pr->max.delay, | 119 | pr->max.delay = GNUNET_TIME_relative_max (pr->max.delay, |
119 | a->properties.delay); | 120 | a->properties.delay); |
120 | pr->min.utilization_out = GNUNET_MIN(pr->min.utilization_out, | 121 | pr->min.utilization_out = GNUNET_MIN (pr->min.utilization_out, |
121 | a->properties.utilization_out); | 122 | a->properties.utilization_out); |
122 | pr->min.utilization_in = GNUNET_MIN(pr->min.utilization_in, | 123 | pr->min.utilization_in = GNUNET_MIN (pr->min.utilization_in, |
123 | a->properties.utilization_in); | 124 | a->properties.utilization_in); |
124 | pr->min.distance = GNUNET_MIN(pr->min.distance, | 125 | pr->min.distance = GNUNET_MIN (pr->min.distance, |
125 | a->properties.distance); | 126 | a->properties.distance); |
126 | pr->min.delay = GNUNET_TIME_relative_min(pr->min.delay, | 127 | pr->min.delay = GNUNET_TIME_relative_min (pr->min.delay, |
127 | a->properties.delay); | 128 | a->properties.delay); |
128 | return GNUNET_OK; | 129 | return GNUNET_OK; |
129 | } | 130 | } |
130 | 131 | ||
@@ -138,13 +139,13 @@ find_min_max_it(void *cls, | |||
138 | * @param ni normalization information to update | 139 | * @param ni normalization information to update |
139 | */ | 140 | */ |
140 | static void | 141 | static void |
141 | update_norm(uint64_t min, | 142 | update_norm (uint64_t min, |
142 | uint64_t max, | 143 | uint64_t max, |
143 | struct GAS_NormalizationInfo *ni) | 144 | struct GAS_NormalizationInfo *ni) |
144 | { | 145 | { |
145 | /* max - 2 * min + avg_value / (max - min) */ | 146 | /* max - 2 * min + avg_value / (max - min) */ |
146 | if (min < max) | 147 | if (min < max) |
147 | ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double)(max - min); | 148 | ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double) (max - min); |
148 | else | 149 | else |
149 | ni->norm = DEFAULT_REL_QUALITY; | 150 | ni->norm = DEFAULT_REL_QUALITY; |
150 | } | 151 | } |
@@ -162,24 +163,24 @@ update_norm(uint64_t min, | |||
162 | * @return #GNUNET_OK (continue to iterate) | 163 | * @return #GNUNET_OK (continue to iterate) |
163 | */ | 164 | */ |
164 | static int | 165 | static int |
165 | normalize_address(void *cls, | 166 | normalize_address (void *cls, |
166 | const struct GNUNET_PeerIdentity *key, | 167 | const struct GNUNET_PeerIdentity *key, |
167 | void *value) | 168 | void *value) |
168 | { | 169 | { |
169 | struct ATS_Address *address = value; | 170 | struct ATS_Address *address = value; |
170 | 171 | ||
171 | update_norm(property_range.min.delay.rel_value_us, | 172 | update_norm (property_range.min.delay.rel_value_us, |
172 | property_range.max.delay.rel_value_us, | 173 | property_range.max.delay.rel_value_us, |
173 | &address->norm_delay); | 174 | &address->norm_delay); |
174 | update_norm(property_range.min.distance, | 175 | update_norm (property_range.min.distance, |
175 | property_range.max.distance, | 176 | property_range.max.distance, |
176 | &address->norm_distance); | 177 | &address->norm_distance); |
177 | update_norm(property_range.min.utilization_in, | 178 | update_norm (property_range.min.utilization_in, |
178 | property_range.max.utilization_in, | 179 | property_range.max.utilization_in, |
179 | &address->norm_utilization_in); | 180 | &address->norm_utilization_in); |
180 | update_norm(property_range.min.utilization_out, | 181 | update_norm (property_range.min.utilization_out, |
181 | property_range.max.utilization_out, | 182 | property_range.max.utilization_out, |
182 | &address->norm_utilization_out); | 183 | &address->norm_utilization_out); |
183 | return GNUNET_OK; | 184 | return GNUNET_OK; |
184 | } | 185 | } |
185 | 186 | ||
@@ -193,13 +194,13 @@ normalize_address(void *cls, | |||
193 | * @return #GNUNET_OK (continue to iterate) | 194 | * @return #GNUNET_OK (continue to iterate) |
194 | */ | 195 | */ |
195 | static int | 196 | static int |
196 | notify_change(void *cls, | 197 | notify_change (void *cls, |
197 | const struct GNUNET_PeerIdentity *key, | 198 | const struct GNUNET_PeerIdentity *key, |
198 | void *value) | 199 | void *value) |
199 | { | 200 | { |
200 | struct ATS_Address *address = value; | 201 | struct ATS_Address *address = value; |
201 | 202 | ||
202 | GAS_plugin_notify_property_changed(address); | 203 | GAS_plugin_notify_property_changed (address); |
203 | return GNUNET_OK; | 204 | return GNUNET_OK; |
204 | } | 205 | } |
205 | 206 | ||
@@ -211,9 +212,9 @@ notify_change(void *cls, | |||
211 | * @param pr range to initialize | 212 | * @param pr range to initialize |
212 | */ | 213 | */ |
213 | static void | 214 | static void |
214 | init_range(struct PropertyRange *pr) | 215 | init_range (struct PropertyRange *pr) |
215 | { | 216 | { |
216 | memset(pr, 0, sizeof(struct PropertyRange)); | 217 | memset (pr, 0, sizeof(struct PropertyRange)); |
217 | pr->min.utilization_out = UINT32_MAX; | 218 | pr->min.utilization_out = UINT32_MAX; |
218 | pr->min.utilization_in = UINT32_MAX; | 219 | pr->min.utilization_in = UINT32_MAX; |
219 | pr->min.distance = UINT32_MAX; | 220 | pr->min.distance = UINT32_MAX; |
@@ -227,51 +228,51 @@ init_range(struct PropertyRange *pr) | |||
227 | * @param address the address to update | 228 | * @param address the address to update |
228 | */ | 229 | */ |
229 | void | 230 | void |
230 | GAS_normalization_update_property(struct ATS_Address *address) | 231 | GAS_normalization_update_property (struct ATS_Address *address) |
231 | { | 232 | { |
232 | const struct GNUNET_ATS_Properties *prop = &address->properties; | 233 | const struct GNUNET_ATS_Properties *prop = &address->properties; |
233 | struct PropertyRange range; | 234 | struct PropertyRange range; |
234 | 235 | ||
235 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 236 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
236 | "Updating properties for peer `%s'\n", | 237 | "Updating properties for peer `%s'\n", |
237 | GNUNET_i2s(&address->peer)); | 238 | GNUNET_i2s (&address->peer)); |
238 | GAS_plugin_solver_lock(); | 239 | GAS_plugin_solver_lock (); |
239 | update_avg(prop->delay.rel_value_us, | 240 | update_avg (prop->delay.rel_value_us, |
240 | &address->norm_delay); | 241 | &address->norm_delay); |
241 | update_avg(prop->distance, | 242 | update_avg (prop->distance, |
242 | &address->norm_distance); | 243 | &address->norm_distance); |
243 | update_avg(prop->utilization_in, | 244 | update_avg (prop->utilization_in, |
244 | &address->norm_utilization_in); | 245 | &address->norm_utilization_in); |
245 | update_avg(prop->utilization_in, | 246 | update_avg (prop->utilization_in, |
246 | &address->norm_utilization_out); | 247 | &address->norm_utilization_out); |
247 | 248 | ||
248 | init_range(&range); | 249 | init_range (&range); |
249 | GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, | 250 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, |
250 | &find_min_max_it, | 251 | &find_min_max_it, |
251 | &range); | 252 | &range); |
252 | if (0 != GNUNET_memcmp(&range, | 253 | if (0 != GNUNET_memcmp (&range, |
253 | &property_range)) | 254 | &property_range)) |
254 | { | 255 | { |
255 | /* limits changed, (re)normalize all addresses */ | 256 | /* limits changed, (re)normalize all addresses */ |
256 | property_range = range; | 257 | property_range = range; |
257 | GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, | 258 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, |
258 | &normalize_address, | 259 | &normalize_address, |
259 | NULL); | 260 | NULL); |
260 | GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, | 261 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, |
261 | ¬ify_change, | 262 | ¬ify_change, |
262 | NULL); | 263 | NULL); |
263 | } | 264 | } |
264 | else | 265 | else |
265 | { | 266 | { |
266 | /* renormalize just this one address */ | 267 | /* renormalize just this one address */ |
267 | normalize_address(NULL, | 268 | normalize_address (NULL, |
268 | &address->peer, | 269 | &address->peer, |
269 | address); | 270 | address); |
270 | notify_change(NULL, | 271 | notify_change (NULL, |
271 | &address->peer, | 272 | &address->peer, |
272 | address); | 273 | address); |
273 | } | 274 | } |
274 | GAS_plugin_solver_unlock(); | 275 | GAS_plugin_solver_unlock (); |
275 | } | 276 | } |
276 | 277 | ||
277 | 278 | ||
@@ -279,9 +280,9 @@ GAS_normalization_update_property(struct ATS_Address *address) | |||
279 | * Start the normalization component | 280 | * Start the normalization component |
280 | */ | 281 | */ |
281 | void | 282 | void |
282 | GAS_normalization_start() | 283 | GAS_normalization_start () |
283 | { | 284 | { |
284 | init_range(&property_range); | 285 | init_range (&property_range); |
285 | } | 286 | } |
286 | 287 | ||
287 | 288 | ||
@@ -289,7 +290,7 @@ GAS_normalization_start() | |||
289 | * Stop the normalization component and free all items | 290 | * Stop the normalization component and free all items |
290 | */ | 291 | */ |
291 | void | 292 | void |
292 | GAS_normalization_stop() | 293 | GAS_normalization_stop () |
293 | { | 294 | { |
294 | /* nothing to do */ | 295 | /* nothing to do */ |
295 | } | 296 | } |