diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-05 19:48:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-05 19:48:15 +0000 |
commit | 21264a59434a5b18b4f5e85e735a2d3ec5c3c6c6 (patch) | |
tree | db7c1187ddbba17641e0c0fcd631331803d19983 /src | |
parent | 88031e0e8188e96d7ae4ce3659e6ed0d90a64f26 (diff) | |
download | gnunet-21264a59434a5b18b4f5e85e735a2d3ec5c3c6c6.tar.gz gnunet-21264a59434a5b18b4f5e85e735a2d3ec5c3c6c6.zip |
cleaning up gnunet-service-ats_normalization.c
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 29 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 8 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_feedback.h | 2 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 143 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.h | 50 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_plugins.c | 13 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_preferences.h | 51 |
7 files changed, 169 insertions, 127 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index e87bf487b..bbd2fda2d 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -501,10 +501,10 @@ find_exact_address (const struct GNUNET_PeerIdentity *peer, | |||
501 | * @return the value in HBO or #GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist | 501 | * @return the value in HBO or #GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist |
502 | */ | 502 | */ |
503 | static int | 503 | static int |
504 | get_performance_info (struct ATS_Address *address, uint32_t type) | 504 | get_performance_info (struct ATS_Address *address, |
505 | uint32_t type) | ||
505 | { | 506 | { |
506 | int c1; | 507 | uint32_t c1; |
507 | GNUNET_assert(NULL != address); | ||
508 | 508 | ||
509 | if ((NULL == address->atsi) || (0 == address->atsi_count)) | 509 | if ((NULL == address->atsi) || (0 == address->atsi_count)) |
510 | return GNUNET_ATS_VALUE_UNDEFINED; | 510 | return GNUNET_ATS_VALUE_UNDEFINED; |
@@ -550,11 +550,6 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
550 | GNUNET_break (0); | 550 | GNUNET_break (0); |
551 | return; | 551 | return; |
552 | } | 552 | } |
553 | |||
554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
555 | "Received `%s' for peer `%s'\n", | ||
556 | "ADDRESS ADD", | ||
557 | GNUNET_i2s (peer)); | ||
558 | new_address = create_address (peer, | 553 | new_address = create_address (peer, |
559 | plugin_name, | 554 | plugin_name, |
560 | plugin_addr, | 555 | plugin_addr, |
@@ -581,13 +576,9 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
581 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 576 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
582 | update_addresses_stat (); | 577 | update_addresses_stat (); |
583 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 578 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
584 | "Adding new address %p for peer `%s', length %u, session id %u, %s\n", | 579 | "Adding new address for peer `%s' slot %u\n", |
585 | new_address, | ||
586 | GNUNET_i2s (peer), | 580 | GNUNET_i2s (peer), |
587 | plugin_addr_len, | 581 | session_id); |
588 | session_id, | ||
589 | GNUNET_ATS_print_network_type (addr_net)); | ||
590 | |||
591 | /* Tell solver about new address */ | 582 | /* Tell solver about new address */ |
592 | GAS_plugin_new_address (new_address, | 583 | GAS_plugin_new_address (new_address, |
593 | addr_net, | 584 | addr_net, |
@@ -638,10 +629,9 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
638 | return; | 629 | return; |
639 | } | 630 | } |
640 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 631 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
641 | "Received `%s' for peer `%s' address \n", | 632 | "Received ADDRESS_UPDATE for peer `%s' slot %u\n", |
642 | "ADDRESS UPDATE", | ||
643 | GNUNET_i2s (peer), | 633 | GNUNET_i2s (peer), |
644 | aa); | 634 | (unsigned int) session_id); |
645 | 635 | ||
646 | /* Update address */ | 636 | /* Update address */ |
647 | aa->t_last_activity = GNUNET_TIME_absolute_get(); | 637 | aa->t_last_activity = GNUNET_TIME_absolute_get(); |
@@ -673,7 +663,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
673 | 663 | ||
674 | 664 | ||
675 | /** | 665 | /** |
676 | * Remove an address or just a session for a peer. | 666 | * Remove an address for a peer. |
677 | * | 667 | * |
678 | * @param peer peer | 668 | * @param peer peer |
679 | * @param session_id session id, can never be 0 | 669 | * @param session_id session id, can never be 0 |
@@ -693,9 +683,8 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, | |||
693 | return; | 683 | return; |
694 | } | 684 | } |
695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 685 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
696 | "Received ADDRESS_DESTROYED for peer `%s' address %p session %u\n", | 686 | "Received ADDRESS_DESTROYED for peer `%s' session %u\n", |
697 | GNUNET_i2s (peer), | 687 | GNUNET_i2s (peer), |
698 | ea, | ||
699 | session_id); | 688 | session_id); |
700 | free_address (ea); | 689 | free_address (ea); |
701 | } | 690 | } |
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 31d3ac8ac..864cdec19 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -379,7 +379,7 @@ GAS_addresses_done (void); | |||
379 | * @param peer peer | 379 | * @param peer peer |
380 | * @param plugin_name transport plugin name | 380 | * @param plugin_name transport plugin name |
381 | * @param plugin_addr plugin address | 381 | * @param plugin_addr plugin address |
382 | * @param plugin_addr_len length of the plugin address | 382 | * @param plugin_addr_len length of the @a plugin_addr |
383 | * @param local_address_info the local address for the address | 383 | * @param local_address_info the local address for the address |
384 | * @param session_id session id, can never be 0. | 384 | * @param session_id session id, can never be 0. |
385 | * @param atsi performance information for this address | 385 | * @param atsi performance information for this address |
@@ -412,7 +412,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
412 | 412 | ||
413 | 413 | ||
414 | /** | 414 | /** |
415 | * Remove an address or just a session for a peer. | 415 | * Remove an address for a peer. |
416 | * | 416 | * |
417 | * @param peer peer | 417 | * @param peer peer |
418 | * @param session_id session id, can never be 0 | 418 | * @param session_id session id, can never be 0 |
@@ -432,7 +432,7 @@ GAS_addresses_destroy_all (void); | |||
432 | /** | 432 | /** |
433 | * Iterator for #GAS_addresses_get_peer_info() | 433 | * Iterator for #GAS_addresses_get_peer_info() |
434 | * | 434 | * |
435 | * @param p_it_cls closure closure | 435 | * @param cls closure |
436 | * @param id the peer id | 436 | * @param id the peer id |
437 | * @param plugin_name plugin name | 437 | * @param plugin_name plugin name |
438 | * @param plugin_addr address | 438 | * @param plugin_addr address |
@@ -444,7 +444,7 @@ GAS_addresses_destroy_all (void); | |||
444 | * @param bandwidth_in current inbound bandwidth assigned to address | 444 | * @param bandwidth_in current inbound bandwidth assigned to address |
445 | */ | 445 | */ |
446 | typedef void | 446 | typedef void |
447 | (*GNUNET_ATS_PeerInfo_Iterator) (void *p_it_cls, | 447 | (*GNUNET_ATS_PeerInfo_Iterator) (void *cls, |
448 | const struct GNUNET_PeerIdentity *id, | 448 | const struct GNUNET_PeerIdentity *id, |
449 | const char *plugin_name, | 449 | const char *plugin_name, |
450 | const void *plugin_addr, | 450 | const void *plugin_addr, |
diff --git a/src/ats/gnunet-service-ats_feedback.h b/src/ats/gnunet-service-ats_feedback.h index dab37d06e..2e37065a1 100644 --- a/src/ats/gnunet-service-ats_feedback.h +++ b/src/ats/gnunet-service-ats_feedback.h | |||
@@ -26,6 +26,8 @@ | |||
26 | #ifndef GNUNET_SERVICE_ATS_FEEDBACK_H | 26 | #ifndef GNUNET_SERVICE_ATS_FEEDBACK_H |
27 | #define GNUNET_SERVICE_ATS_FEEDBACK_H | 27 | #define GNUNET_SERVICE_ATS_FEEDBACK_H |
28 | 28 | ||
29 | #include "gnunet_util_lib.h" | ||
30 | |||
29 | /** | 31 | /** |
30 | * Handle 'preference feedback' messages from clients. | 32 | * Handle 'preference feedback' messages from clients. |
31 | * | 33 | * |
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index 7003f69e4..244813108 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2011-2015 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -24,7 +24,7 @@ | |||
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | * | 26 | * |
27 | * FIXME: rename to 'properties'! | 27 | * FIXME: rename to 'properties'!? |
28 | */ | 28 | */ |
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #include "gnunet_ats_service.h" | 30 | #include "gnunet_ats_service.h" |
@@ -35,32 +35,42 @@ | |||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-normalization",__VA_ARGS__) | 35 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-normalization",__VA_ARGS__) |
36 | 36 | ||
37 | 37 | ||
38 | |||
39 | /** | 38 | /** |
40 | * Quality Normalization | 39 | * Quality Normalization |
41 | */ | 40 | */ |
42 | struct Property | 41 | struct Property |
43 | { | 42 | { |
43 | /** | ||
44 | * Index into the properties array. | ||
45 | */ | ||
44 | uint32_t prop_type; | 46 | uint32_t prop_type; |
47 | |||
48 | /** | ||
49 | * Corresponding enum value. FIXME: type? | ||
50 | */ | ||
45 | uint32_t atsi_type; | 51 | uint32_t atsi_type; |
52 | |||
53 | /** | ||
54 | * Minimum value we see for this property across all addresses. | ||
55 | */ | ||
46 | uint32_t min; | 56 | uint32_t min; |
57 | |||
58 | /** | ||
59 | * Maximum value we see for this property across all addresses. | ||
60 | */ | ||
47 | uint32_t max; | 61 | uint32_t max; |
48 | }; | 62 | }; |
49 | 63 | ||
50 | static struct Property properties[GNUNET_ATS_QualityPropertiesCount]; | ||
51 | 64 | ||
52 | /** | 65 | /** |
53 | * Hashmap to store peer information for property normalization | 66 | * Range information for all properties we see. |
54 | * FIXME: this map is not used! | ||
55 | */ | 67 | */ |
56 | static struct GNUNET_CONTAINER_MultiPeerMap *property_peers; | 68 | static struct Property properties[GNUNET_ATS_QualityPropertiesCount]; |
57 | |||
58 | |||
59 | 69 | ||
60 | 70 | ||
61 | /** | 71 | /** |
62 | * Get the normalized properties values for a specific peer or | 72 | * Get the normalized properties values for a specific peer or |
63 | * the default values if | 73 | * the default values if no normalized values are available. |
64 | * | 74 | * |
65 | * @param cls ignored | 75 | * @param cls ignored |
66 | * @param address the address | 76 | * @param address the address |
@@ -72,9 +82,7 @@ GAS_normalization_get_properties (void *cls, | |||
72 | const struct ATS_Address *address) | 82 | const struct ATS_Address *address) |
73 | { | 83 | { |
74 | static double norm_values[GNUNET_ATS_QualityPropertiesCount]; | 84 | static double norm_values[GNUNET_ATS_QualityPropertiesCount]; |
75 | int i; | 85 | unsigned int i; |
76 | |||
77 | GNUNET_assert(NULL != address); | ||
78 | 86 | ||
79 | for (i = 0; i < GNUNET_ATS_QualityPropertiesCount; i++) | 87 | for (i = 0; i < GNUNET_ATS_QualityPropertiesCount; i++) |
80 | { | 88 | { |
@@ -88,7 +96,8 @@ GAS_normalization_get_properties (void *cls, | |||
88 | 96 | ||
89 | 97 | ||
90 | /** | 98 | /** |
91 | * Normalize a specific ATS type with the values in queue | 99 | * Normalize a specific ATS type with the values in queue. |
100 | * | ||
92 | * @param address the address | 101 | * @param address the address |
93 | * @param atsi the ats information | 102 | * @param atsi the ats information |
94 | * @return the new average or GNUNET_ATS_VALUE_UNDEFINED | 103 | * @return the new average or GNUNET_ATS_VALUE_UNDEFINED |
@@ -149,40 +158,78 @@ property_average (struct ATS_Address *address, | |||
149 | res = sum / count; | 158 | res = sum / count; |
150 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 159 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
151 | "New average of `%s' created by adding %u from %u elements: %u\n", | 160 | "New average of `%s' created by adding %u from %u elements: %u\n", |
152 | GNUNET_ATS_print_property_type (current_type), current_val, count, res, | 161 | GNUNET_ATS_print_property_type (current_type), |
162 | current_val, | ||
163 | count, | ||
164 | res, | ||
153 | sum); | 165 | sum); |
154 | ni->avg = res; | 166 | ni->avg = res; |
155 | return res; | 167 | return res; |
156 | } | 168 | } |
157 | 169 | ||
158 | 170 | ||
171 | /** | ||
172 | * Closure for #find_min_max_it(). | ||
173 | */ | ||
159 | struct FindMinMaxCtx | 174 | struct FindMinMaxCtx |
160 | { | 175 | { |
176 | /** | ||
177 | * Property we are looking for. | ||
178 | */ | ||
161 | struct Property *p; | 179 | struct Property *p; |
180 | |||
181 | /** | ||
182 | * Set to mimimum value observed. | ||
183 | */ | ||
162 | uint32_t min; | 184 | uint32_t min; |
185 | |||
186 | /** | ||
187 | * Set to maximum value observed. | ||
188 | */ | ||
163 | uint32_t max; | 189 | uint32_t max; |
164 | }; | 190 | }; |
165 | 191 | ||
166 | 192 | ||
193 | /** | ||
194 | * Function called on X to find the minimum and maximum | ||
195 | * values for a given property. | ||
196 | * | ||
197 | * @param cls the `struct FindMinMaxCtx` | ||
198 | * @param h which peer are we looking at (ignored) | ||
199 | * @param k the address for that peer | ||
200 | * @return #GNUNET_OK (continue to iterate) | ||
201 | */ | ||
167 | static int | 202 | static int |
168 | find_min_max_it (void *cls, const struct GNUNET_PeerIdentity *h, void *k) | 203 | find_min_max_it (void *cls, |
204 | const struct GNUNET_PeerIdentity *h, | ||
205 | void *k) | ||
169 | { | 206 | { |
170 | struct FindMinMaxCtx *find_res = cls; | 207 | struct FindMinMaxCtx *find_res = cls; |
171 | struct ATS_Address *a = k; | 208 | const struct ATS_Address *a = k; |
172 | |||
173 | if (a->atsin[find_res->p->prop_type].avg > find_res->max) | ||
174 | find_res->max = a->atsin[find_res->p->prop_type].avg; | ||
175 | |||
176 | if (a->atsin[find_res->p->prop_type].avg < find_res->min) | ||
177 | find_res->min = a->atsin[find_res->p->prop_type].avg; | ||
178 | 209 | ||
210 | find_res->max = GNUNET_MAX (find_res->max, | ||
211 | a->atsin[find_res->p->prop_type].avg); | ||
212 | find_res->min = GNUNET_MIN (find_res->min, | ||
213 | a->atsin[find_res->p->prop_type].avg); | ||
179 | return GNUNET_OK; | 214 | return GNUNET_OK; |
180 | } | 215 | } |
181 | 216 | ||
182 | 217 | ||
218 | /** | ||
219 | * Normalize the property value for a given address based | ||
220 | * on the range we know that property value has globally. | ||
221 | * | ||
222 | * @param cls the `struct Property` with details on the | ||
223 | * property and its global range | ||
224 | * @param h which peer are we looking at (ignored) | ||
225 | * @param k the address for that peer, from where we get | ||
226 | * the original value and where we write the | ||
227 | * normalized value | ||
228 | * @return #GNUNET_OK (continue to iterate) | ||
229 | */ | ||
183 | static int | 230 | static int |
184 | normalize_address (void *cls, | 231 | normalize_address (void *cls, |
185 | const struct GNUNET_PeerIdentity *h, | 232 | const struct GNUNET_PeerIdentity *h, |
186 | void *k) | 233 | void *k) |
187 | { | 234 | { |
188 | struct Property *p = cls; | 235 | struct Property *p = cls; |
@@ -203,32 +250,30 @@ normalize_address (void *cls, | |||
203 | if (backup == address->atsin[p->prop_type].norm) | 250 | if (backup == address->atsin[p->prop_type].norm) |
204 | return GNUNET_OK; | 251 | return GNUNET_OK; |
205 | 252 | ||
206 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 253 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
207 | "Normalize `%s' address %p's '%s' with value %u to range [%u..%u] = %.3f\n", | 254 | "Normalize `%s' address %p's '%s' with value %u to range [%u..%u] = %.3f\n", |
208 | GNUNET_i2s (&address->peer), address, | 255 | GNUNET_i2s (&address->peer), address, |
209 | GNUNET_ATS_print_property_type (p->atsi_type), | 256 | GNUNET_ATS_print_property_type (p->atsi_type), |
210 | address->atsin[p->prop_type].avg, p->min, p->max, | 257 | address->atsin[p->prop_type].avg, p->min, p->max, |
211 | address->atsin[p->prop_type].norm); | 258 | address->atsin[p->prop_type].norm); |
212 | 259 | GAS_normalized_property_changed (address, | |
213 | GAS_normalized_property_changed (address, | ||
214 | p->atsi_type, | 260 | p->atsi_type, |
215 | address->atsin[p->prop_type].norm); | 261 | address->atsin[p->prop_type].norm); |
216 | |||
217 | return GNUNET_OK; | 262 | return GNUNET_OK; |
218 | } | 263 | } |
219 | 264 | ||
220 | 265 | ||
221 | /** | 266 | /** |
222 | * Normalize avg_value to a range of values between [1.0, 2.0] | 267 | * Normalize @a avg_value to a range of values between [1.0, 2.0] |
223 | * based on min max values currently known. | 268 | * based on min/max values currently known. |
224 | * | 269 | * |
225 | * @param p the property | 270 | * @param p the property |
226 | * @param address the address | 271 | * @param address the address |
227 | * @param avg_value the value to normalize | 272 | * @param avg_value the value to normalize |
228 | */ | 273 | */ |
229 | static void | 274 | static void |
230 | property_normalize (struct Property *p, | 275 | property_normalize (struct Property *p, |
231 | struct ATS_Address *address, | 276 | struct ATS_Address *address, |
232 | uint32_t avg_value) | 277 | uint32_t avg_value) |
233 | { | 278 | { |
234 | struct FindMinMaxCtx find_ctx; | 279 | struct FindMinMaxCtx find_ctx; |
@@ -239,7 +284,7 @@ property_normalize (struct Property *p, | |||
239 | find_ctx.max = 0; | 284 | find_ctx.max = 0; |
240 | find_ctx.min = UINT32_MAX; | 285 | find_ctx.min = UINT32_MAX; |
241 | addr_count = GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | 286 | addr_count = GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, |
242 | &find_min_max_it, | 287 | &find_min_max_it, |
243 | &find_ctx); | 288 | &find_ctx); |
244 | if (0 == addr_count) | 289 | if (0 == addr_count) |
245 | { | 290 | { |
@@ -252,7 +297,7 @@ property_normalize (struct Property *p, | |||
252 | { | 297 | { |
253 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 298 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
254 | "Normalizing %s: new maximum %u -> recalculate all values\n", | 299 | "Normalizing %s: new maximum %u -> recalculate all values\n", |
255 | GNUNET_ATS_print_property_type (p->atsi_type), | 300 | GNUNET_ATS_print_property_type (p->atsi_type), |
256 | find_ctx.max); | 301 | find_ctx.max); |
257 | p->max = find_ctx.max; | 302 | p->max = find_ctx.max; |
258 | limits_changed = GNUNET_YES; | 303 | limits_changed = GNUNET_YES; |
@@ -278,13 +323,15 @@ property_normalize (struct Property *p, | |||
278 | if (GNUNET_NO == limits_changed) | 323 | if (GNUNET_NO == limits_changed) |
279 | { | 324 | { |
280 | /* normalize just this address */ | 325 | /* normalize just this address */ |
281 | normalize_address (p, &address->peer, address); | 326 | normalize_address (p, |
327 | &address->peer, | ||
328 | address); | ||
282 | } | 329 | } |
283 | else | 330 | else |
284 | { | 331 | { |
285 | /* limits changed, normalize all addresses */ | 332 | /* limits changed, normalize all addresses */ |
286 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | 333 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, |
287 | &normalize_address, | 334 | &normalize_address, |
288 | p); | 335 | p); |
289 | } | 336 | } |
290 | } | 337 | } |
@@ -340,40 +387,40 @@ GAS_normalization_normalize_property (struct ATS_Address *address, | |||
340 | /* Normalizing */ | 387 | /* Normalizing */ |
341 | /* Check min, max */ | 388 | /* Check min, max */ |
342 | cur_prop = &properties[c2]; | 389 | cur_prop = &properties[c2]; |
343 | property_normalize (cur_prop, address, current_val); | 390 | property_normalize (cur_prop, |
391 | address, | ||
392 | current_val); | ||
344 | } | 393 | } |
345 | } | 394 | } |
346 | 395 | ||
347 | 396 | ||
348 | |||
349 | /** | 397 | /** |
350 | * Start the normalization component | 398 | * Start the normalization component |
351 | */ | 399 | */ |
352 | void | 400 | void |
353 | GAS_normalization_start () | 401 | GAS_normalization_start () |
354 | { | 402 | { |
355 | int c1; | 403 | unsigned int c1; |
356 | unsigned int existing_properties[] = GNUNET_ATS_QualityProperties; | 404 | unsigned int existing_properties[] = GNUNET_ATS_QualityProperties; |
357 | 405 | ||
358 | property_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | ||
359 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) | 406 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) |
360 | { | 407 | { |
361 | properties[c1].prop_type = c1; | 408 | properties[c1].prop_type = c1; |
362 | properties[c1].atsi_type = existing_properties[c1]; | 409 | properties[c1].atsi_type = existing_properties[c1]; |
363 | properties[c1].min = 0; | 410 | properties[c1].min = UINT32_MAX; |
364 | properties[c1].max = 0; | 411 | properties[c1].max = 0; |
365 | } | 412 | } |
366 | } | 413 | } |
367 | 414 | ||
368 | 415 | ||
369 | |||
370 | /** | 416 | /** |
371 | * Stop the normalization component and free all items | 417 | * Stop the normalization component and free all items |
372 | */ | 418 | */ |
373 | void | 419 | void |
374 | GAS_normalization_stop () | 420 | GAS_normalization_stop () |
375 | { | 421 | { |
376 | GNUNET_CONTAINER_multipeermap_destroy (property_peers); | 422 | /* nothing to do */ |
377 | } | 423 | } |
378 | 424 | ||
425 | |||
379 | /* end of gnunet-service-ats_normalization.c */ | 426 | /* end of gnunet-service-ats_normalization.c */ |
diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h index e542097c9..0e65d0ed8 100644 --- a/src/ats/gnunet-service-ats_normalization.h +++ b/src/ats/gnunet-service-ats_normalization.h | |||
@@ -32,20 +32,8 @@ | |||
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Get the normalized preference values for a specific peer | ||
36 | * | ||
37 | * @param cls ignored | ||
38 | * @param id the peer @return pointer to the values, can be indexed | ||
39 | * with GNUNET_ATS_PreferenceKind, NULL if peer does not exist | ||
40 | */ | ||
41 | const double * | ||
42 | GAS_normalization_get_preferences_by_peer (void *cls, | ||
43 | const struct GNUNET_PeerIdentity *id); | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Get the normalized properties values for a specific peer or | 35 | * Get the normalized properties values for a specific peer or |
48 | * the default values if | 36 | * the default values if no normalized values are available. |
49 | * | 37 | * |
50 | * @param cls ignored | 38 | * @param cls ignored |
51 | * @param address the address | 39 | * @param address the address |
@@ -58,33 +46,6 @@ GAS_normalization_get_properties (void *cls, | |||
58 | 46 | ||
59 | 47 | ||
60 | /** | 48 | /** |
61 | * Get the normalized preference values for a specific client and peer | ||
62 | * | ||
63 | * @param client client | ||
64 | * @param peer the peer | ||
65 | * @param pref the preference type | ||
66 | * @return the value | ||
67 | */ | ||
68 | double | ||
69 | GAS_normalization_get_preferences_by_client (const void *client, | ||
70 | const struct GNUNET_PeerIdentity *peer, | ||
71 | enum GNUNET_ATS_PreferenceKind pref); | ||
72 | |||
73 | /** | ||
74 | * Normalize an updated preference value | ||
75 | * | ||
76 | * @param client the client with this preference | ||
77 | * @param peer the peer to change the preference for | ||
78 | * @param kind the kind to change the preference | ||
79 | * @param score_abs the normalized score | ||
80 | */ | ||
81 | void | ||
82 | GAS_normalization_normalize_preference (void *client, | ||
83 | const struct GNUNET_PeerIdentity *peer, | ||
84 | enum GNUNET_ATS_PreferenceKind kind, | ||
85 | float score_abs); | ||
86 | |||
87 | /** | ||
88 | * Update and normalize a atsi performance information | 49 | * Update and normalize a atsi performance information |
89 | * | 50 | * |
90 | * @param address the address to update | 51 | * @param address the address to update |
@@ -98,15 +59,6 @@ GAS_normalization_normalize_property (struct ATS_Address *address, | |||
98 | 59 | ||
99 | 60 | ||
100 | /** | 61 | /** |
101 | * A performance client disconnected | ||
102 | * | ||
103 | * @param client the disconnecting client | ||
104 | */ | ||
105 | void | ||
106 | GAS_normalization_preference_client_disconnect (void *client); | ||
107 | |||
108 | |||
109 | /** | ||
110 | * Start the normalization component | 62 | * Start the normalization component |
111 | */ | 63 | */ |
112 | void | 64 | void |
diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c index 1e234b56d..fed3c8496 100644 --- a/src/ats/gnunet-service-ats_plugins.c +++ b/src/ats/gnunet-service-ats_plugins.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "gnunet_ats_plugin.h" | 32 | #include "gnunet_ats_plugin.h" |
33 | #include "gnunet-service-ats_addresses.h" | 33 | #include "gnunet-service-ats_addresses.h" |
34 | #include "gnunet-service-ats_performance.h" | 34 | #include "gnunet-service-ats_performance.h" |
35 | #include "gnunet-service-ats_preferences.h" | ||
35 | #include "gnunet-service-ats_plugins.h" | 36 | #include "gnunet-service-ats_plugins.h" |
36 | #include "gnunet-service-ats_scheduling.h" | 37 | #include "gnunet-service-ats_scheduling.h" |
37 | #include "gnunet-service-ats_normalization.h" | 38 | #include "gnunet-service-ats_normalization.h" |
@@ -207,7 +208,7 @@ solver_info_cb (void *cls, | |||
207 | * @param address the address with changes | 208 | * @param address the address with changes |
208 | */ | 209 | */ |
209 | static void | 210 | static void |
210 | bandwidth_changed_cb (void *cls, | 211 | bandwidth_changed_cb (void *cls, |
211 | struct ATS_Address *address) | 212 | struct ATS_Address *address) |
212 | { | 213 | { |
213 | uint32_t diff_out; | 214 | uint32_t diff_out; |
@@ -222,7 +223,7 @@ bandwidth_changed_cb (void *cls, | |||
222 | address->plugin, | 223 | address->plugin, |
223 | address->addr, | 224 | address->addr, |
224 | address->addr_len, | 225 | address->addr_len, |
225 | address->active, | 226 | address->active, |
226 | address->atsi, | 227 | address->atsi, |
227 | address->atsi_count, | 228 | address->atsi_count, |
228 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_out), | 229 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_out), |
@@ -601,8 +602,8 @@ GAS_plugin_preference_feedback (void *application, | |||
601 | { | 602 | { |
602 | env.sf.s_feedback (solver, | 603 | env.sf.s_feedback (solver, |
603 | application, | 604 | application, |
604 | peer, | 605 | peer, |
605 | scope, | 606 | scope, |
606 | kind, | 607 | kind, |
607 | score_abs); | 608 | score_abs); |
608 | } | 609 | } |
@@ -635,9 +636,9 @@ GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid) | |||
635 | GNUNET_i2s (pid)); | 636 | GNUNET_i2s (pid)); |
636 | return; | 637 | return; |
637 | } | 638 | } |
638 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 639 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
639 | "Suggesting address %p for peer `%s'\n", | 640 | "Suggesting address %p for peer `%s'\n", |
640 | aa, | 641 | aa, |
641 | GNUNET_i2s (pid)); | 642 | GNUNET_i2s (pid)); |
642 | 643 | ||
643 | GAS_scheduling_transmit_address_suggestion (pid, | 644 | GAS_scheduling_transmit_address_suggestion (pid, |
diff --git a/src/ats/gnunet-service-ats_preferences.h b/src/ats/gnunet-service-ats_preferences.h index cecc9d5f6..66610d470 100644 --- a/src/ats/gnunet-service-ats_preferences.h +++ b/src/ats/gnunet-service-ats_preferences.h | |||
@@ -49,6 +49,57 @@ GAS_preference_client_disconnect (struct GNUNET_SERVER_Client *client); | |||
49 | 49 | ||
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Get the normalized preference values for a specific peer. | ||
53 | * | ||
54 | * @param cls ignored | ||
55 | * @param id the peer | ||
56 | * @return pointer to the values, can be indexed | ||
57 | * with GNUNET_ATS_PreferenceKind, NULL if peer does not exist | ||
58 | */ | ||
59 | const double * | ||
60 | GAS_normalization_get_preferences_by_peer (void *cls, | ||
61 | const struct GNUNET_PeerIdentity *id); | ||
62 | |||
63 | |||
64 | /** | ||
65 | * Get the normalized preference values for a specific client and peer | ||
66 | * | ||
67 | * @param client client | ||
68 | * @param peer the peer | ||
69 | * @param pref the preference type | ||
70 | * @return the value | ||
71 | */ | ||
72 | double | ||
73 | GAS_normalization_get_preferences_by_client (const void *client, | ||
74 | const struct GNUNET_PeerIdentity *peer, | ||
75 | enum GNUNET_ATS_PreferenceKind pref); | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Normalize an updated preference value | ||
80 | * | ||
81 | * @param client the client with this preference | ||
82 | * @param peer the peer to change the preference for | ||
83 | * @param kind the kind to change the preference | ||
84 | * @param score_abs the normalized score | ||
85 | */ | ||
86 | void | ||
87 | GAS_normalization_normalize_preference (void *client, | ||
88 | const struct GNUNET_PeerIdentity *peer, | ||
89 | enum GNUNET_ATS_PreferenceKind kind, | ||
90 | float score_abs); | ||
91 | |||
92 | |||
93 | /** | ||
94 | * A performance client disconnected | ||
95 | * | ||
96 | * @param client the disconnecting client | ||
97 | */ | ||
98 | void | ||
99 | GAS_normalization_preference_client_disconnect (void *client); | ||
100 | |||
101 | |||
102 | /** | ||
52 | * Handle 'preference change' messages from clients. | 103 | * Handle 'preference change' messages from clients. |
53 | * | 104 | * |
54 | * @param cls unused, NULL | 105 | * @param cls unused, NULL |