2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file ats/gnunet-service-ats_normalization.c
23 * @brief ats service address: management of ATS properties and preferences normalization
24 * @author Matthias Wachs
25 * @author Christian Grothoff
28 #include "gnunet_ats_service.h"
29 #include "gnunet-service-ats_addresses.h"
30 #include "gnunet-service-ats_normalization.h"
32 #define LOG(kind,...) GNUNET_log_from (kind, "ats-normalization",__VA_ARGS__)
37 struct PreferenceClient
42 struct PreferenceClient *prev;
48 struct PreferenceClient *next;
56 * Array of sum of absolute preferences for this client
58 double f_abs_sum[GNUNET_ATS_PreferenceCount];
61 * Array of sum of relative preferences for this client
63 double f_rel_sum[GNUNET_ATS_PreferenceCount];
66 * List of peer preferences for this client
72 struct PreferencePeer *p_head;
77 struct PreferencePeer *p_tail;
88 struct PreferencePeer *next;
93 struct PreferencePeer *prev;
98 struct PreferenceClient *client;
103 struct GNUNET_PeerIdentity id;
106 * Absolute preference values for all preference types
108 double f_abs[GNUNET_ATS_PreferenceCount];
111 * Relative preference values for all preference types
113 double f_rel[GNUNET_ATS_PreferenceCount];
116 * Absolute point of time of next aging process
118 struct GNUNET_TIME_Absolute next_aging[GNUNET_ATS_PreferenceCount];
122 * Relative preferences for a peer
127 * Relative preference values
129 double f_rel[GNUNET_ATS_PreferenceCount];
134 struct GNUNET_PeerIdentity id;
138 * Quality Normalization
148 struct Property properties[GNUNET_ATS_QualityPropertiesCount];
152 * Callback to call on changing preference values
154 static GAS_Normalization_preference_changed_cb pref_changed_cb;
157 * Closure for callback to call on changing preference values
159 static void *pref_changed_cb_cls;
162 * Callback to call on changing property values
164 GAS_Normalization_property_changed_cb prop_ch_cb;
167 * Closure for callback to call on changing property values
169 void *prop_ch_cb_cls;
172 * Hashmap to store peer information for preference normalization
174 static struct GNUNET_CONTAINER_MultiPeerMap *preference_peers;
177 * Hashmap to store peer information for property normalization
178 * FIXME: this map is not used!
180 static struct GNUNET_CONTAINER_MultiPeerMap *property_peers;
183 * Clients in DLL: head
185 static struct PreferenceClient *pc_head;
188 * Clients in DLL: tail
190 static struct PreferenceClient *pc_tail;
195 static struct PeerRelative defvalues;
197 static GNUNET_SCHEDULER_TaskIdentifier aging_task;
200 * Application Preference Normalization
206 * @param kind the kind
207 * @return the new relative preference
210 update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id,
211 enum GNUNET_ATS_PreferenceKind kind, struct PeerRelative *rp)
213 struct PreferenceClient *c_cur;
214 struct PreferencePeer *p_cur;
218 unsigned int peer_count;
224 /* For all clients */
225 for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
227 /* For peer entries with this id */
228 for (p_cur = c_cur->p_head; NULL != p_cur; p_cur = p_cur->next)
230 f_rel_sum += p_cur->f_rel[kind];
231 if (0 == memcmp (id, &p_cur->id, sizeof(struct GNUNET_PeerIdentity)))
234 f_rel_total += p_cur->f_rel[kind];
240 LOG (GNUNET_ERROR_TYPE_DEBUG,
241 "%u clients have a total relative preference for peer `%s' `%s' of %.3f and for %s in total %.3f\n",
242 peer_count, GNUNET_i2s (id),
243 GNUNET_ATS_print_preference_type (kind),
245 GNUNET_ATS_print_preference_type (kind),
248 /* Find entry for the peer containing relative values in the hashmap */
251 backup = rp->f_rel[kind];
253 rp->f_rel[kind] = f_rel_total / f_rel_sum;
256 /* No client had any preferences for this type and any peer */
257 rp->f_rel[kind] = DEFAULT_REL_PREFERENCE;
261 if ((backup != rp->f_rel[kind]) && (NULL != pref_changed_cb))
263 pref_changed_cb (pref_changed_cb_cls, &rp->id, kind, rp->f_rel[kind]);
268 * Recalculate preference for a specific ATS property
270 * @param c the preference client
271 * @param kind the preference kind
275 recalculate_relative_preferences (struct PreferenceClient *c, enum GNUNET_ATS_PreferenceKind kind)
277 struct PreferencePeer *p_cur;
279 /* For this client: sum of absolute preference values for this preference */
280 c->f_abs_sum[kind] = 0.0;
281 /* For this client: sum of relative preference values for this preference
283 * Note: this value should also be 1.0, but:
284 * if no preferences exist due to aging, this value can be 0.0
285 * and the client can be removed */
286 c->f_rel_sum[kind] = 0.0;
288 for (p_cur = c->p_head; NULL != p_cur; p_cur = p_cur->next)
289 c->f_abs_sum[kind] += p_cur->f_abs[kind];
290 LOG (GNUNET_ERROR_TYPE_DEBUG,
291 "Client %p has sum of total preferences for %s of %.3f\n",
292 c->client, GNUNET_ATS_print_preference_type (kind), c->f_abs_sum[kind]);
294 /* For all peers: calculate relative preference */
295 for (p_cur = c->p_head; NULL != p_cur; p_cur = p_cur->next)
297 /* Calculate relative preference for specific kind */
299 /* Every application has a preference for each peer between
300 * [0 .. 1] in relative values
301 * and [0 .. inf] in absolute values */
302 p_cur->f_rel[kind] = p_cur->f_abs[kind] / c->f_abs_sum[kind];
303 c->f_rel_sum[kind] += p_cur->f_rel[kind];
305 LOG (GNUNET_ERROR_TYPE_DEBUG,
306 "Client %p has relative preference for %s for peer `%s' of %.3f\n",
308 GNUNET_ATS_print_preference_type (kind),
309 GNUNET_i2s (&p_cur->id),
316 * Update the absolute preference value for a peer
317 * @param c the client
319 * @param kind the preference kind
320 * @param score_abs the absolute value
321 * @return the new relative preference value
324 update_abs_preference (struct PreferenceClient *c, struct PreferencePeer *p,
325 enum GNUNET_ATS_PreferenceKind kind, float score_abs)
327 double score = score_abs;
329 /* Update preference value according to type */
332 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
333 case GNUNET_ATS_PREFERENCE_LATENCY:
334 p->f_abs[kind] = score;
335 /* p->f_abs[kind] = (p->f_abs[kind] + score) / 2; */
336 p->next_aging[kind] = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
337 PREF_AGING_INTERVAL);
339 case GNUNET_ATS_PREFERENCE_END:
346 static int update_iterator (void *cls,
347 const struct GNUNET_PeerIdentity *key,
350 enum GNUNET_ATS_PreferenceKind *kind = cls;
351 update_relative_values_for_peer (key, (*kind), (struct PeerRelative *) value);
356 run_preference_update (struct PreferenceClient *c_cur,
357 struct PreferencePeer *p_cur,enum GNUNET_ATS_PreferenceKind kind,
362 /* Update relative value */
363 old_value = p_cur->f_rel[kind];
364 recalculate_relative_preferences (c_cur, kind);
365 if (p_cur->f_rel[kind] == old_value)
368 /* Relative preference value changed, recalculate for all peers */
369 GNUNET_CONTAINER_multipeermap_iterate (preference_peers, &update_iterator, &kind);
373 * Reduce absolute preferences since they got old
375 * @param cls the PreferencePeer
379 preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
381 struct PreferencePeer *p;
382 struct PreferenceClient *cur_client;
384 int values_to_update;
387 aging_task = GNUNET_SCHEDULER_NO_TASK;
388 values_to_update = 0;
391 for (cur_client = pc_head; NULL != cur_client; cur_client = cur_client->next)
393 for (p = cur_client->p_head; NULL != p; p = p->next)
395 /* Aging absolute values: */
396 for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
399 == GNUNET_TIME_absolute_get_remaining (p->next_aging[i]).rel_value_us)
401 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
402 "Aging preference for peer `%s'\n", GNUNET_i2s (&p->id));
403 backup = p->f_abs[i];
404 if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE)
405 p->f_abs[i] *= PREF_AGING_FACTOR;
407 if (p->f_abs[i] <= DEFAULT_ABS_PREFERENCE + PREF_EPSILON)
408 p->f_abs[i] = DEFAULT_ABS_PREFERENCE;
410 if ( (p->f_abs[i] != DEFAULT_ABS_PREFERENCE) &&
411 (backup != p->f_abs[i]) )
413 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
414 "Aged preference for peer `%s' from %.3f to %.3f\n",
415 GNUNET_i2s (&p->id), backup, p->f_abs[i]);
417 run_preference_update(cur_client, p, i, p->f_abs[i]);
419 p->next_aging[i] = GNUNET_TIME_absolute_add (
420 GNUNET_TIME_absolute_get (), PREF_AGING_INTERVAL);
428 if (values_to_update > 0)
430 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
431 "Rescheduling aging task due to %u elements to age\n",
433 aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
434 &preference_aging, NULL );
437 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
438 "No values to age left, not rescheduling aging task\n");
443 * Normalize an updated preference value
445 * @param client the client with this preference
446 * @param peer the peer to change the preference for
447 * @param kind the kind to change the preference
448 * @param score_abs the normalized score
451 GAS_normalization_normalize_preference (void *client,
452 const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind,
455 struct PreferenceClient *c_cur;
456 struct PreferencePeer *p_cur;
457 struct PeerRelative *r_cur;
461 GNUNET_assert(NULL != client);
462 GNUNET_assert(NULL != peer);
464 LOG (GNUNET_ERROR_TYPE_DEBUG,
465 "Client %p changes preference for peer `%s' for `%s' to %.2f\n",
468 GNUNET_ATS_print_preference_type (kind),
471 if (kind >= GNUNET_ATS_PreferenceCount)
477 /* Find preference client */
478 for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
480 if (client == c_cur->client)
483 /* Not found: create new preference client */
486 c_cur = GNUNET_new (struct PreferenceClient);
487 c_cur->client = client;
488 for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
490 c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE;
491 c_cur->f_rel_sum[i] = DEFAULT_REL_PREFERENCE;
494 GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, c_cur);
495 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding new client %p \n", c_cur);
498 /* Find entry for peer */
499 for (p_cur = c_cur->p_head; NULL != p_cur; p_cur = p_cur->next)
500 if (0 == memcmp (&p_cur->id, peer, sizeof(p_cur->id)))
503 /* Not found: create new peer entry */
506 p_cur = GNUNET_new (struct PreferencePeer);
507 p_cur->client = c_cur;
509 for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
511 /* Default value per peer absolute preference for a preference: 0 */
512 p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE;
513 /* Default value per peer relative preference for a quality: 1.0 */
514 p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
515 p_cur->next_aging[i] = GNUNET_TIME_UNIT_FOREVER_ABS;
517 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding new peer %p for client %p \n",
519 GNUNET_CONTAINER_DLL_insert(c_cur->p_head, c_cur->p_tail, p_cur);
522 /* Create struct for peer */
523 if (NULL == GNUNET_CONTAINER_multipeermap_get (preference_peers, peer))
525 r_cur = GNUNET_new (struct PeerRelative);
527 for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
528 r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
530 GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (preference_peers,
531 &r_cur->id, r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
534 /* Update absolute value */
535 old_value = p_cur->f_abs[kind];
536 update_abs_preference (c_cur, p_cur, kind, score_abs);
537 if (p_cur->f_abs[kind] == old_value)
540 run_preference_update (c_cur, p_cur, kind, score_abs);
542 /* Start aging task */
543 if (GNUNET_SCHEDULER_NO_TASK == aging_task)
544 aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
545 &preference_aging, NULL );
550 * Get the normalized preference values for a specific peer or
551 * the default values if
554 * @return pointer to the values, can be indexed with GNUNET_ATS_PreferenceKind,
555 * default preferences if peer does not exist
558 GAS_normalization_get_preferences_by_peer (const struct GNUNET_PeerIdentity *id)
560 GNUNET_assert(NULL != preference_peers);
561 GNUNET_assert(NULL != id);
563 struct PeerRelative *rp;
564 if (NULL == (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, id)))
566 return defvalues.f_rel;
572 * Get the normalized preference values for a specific client and peer
574 * @param client client
575 * @param peer the peer
576 * @param pref the preference type
580 GAS_normalization_get_preferences_by_client (const void *client,
581 const struct GNUNET_PeerIdentity *peer,
582 enum GNUNET_ATS_PreferenceKind pref)
584 struct PreferenceClient *c_cur;
585 struct PreferencePeer *p_cur;
587 /* Find preference client */
588 for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
590 if (client == c_cur->client)
596 for (p_cur = c_cur->p_head; NULL != p_cur; p_cur = p_cur->next)
598 if (0 == memcmp (peer, &p_cur->id, sizeof (struct GNUNET_PeerIdentity)))
602 return DEFAULT_REL_PREFERENCE; /* Not found, return default */
604 return p_cur->f_rel[pref];
608 * Get the normalized properties values for a specific peer or
609 * the default values if
611 * @param address the address
612 * @return pointer to the values, can be indexed with GNUNET_ATS_PreferenceKind,
613 * default preferences if peer does not exist
616 GAS_normalization_get_properties (struct ATS_Address *address)
618 static double norm_values[GNUNET_ATS_QualityPropertiesCount];
621 GNUNET_assert(NULL != address);
623 for (i = 0; i < GNUNET_ATS_QualityPropertiesCount; i++)
625 if ((address->atsin[i].norm >= 1.0) && (address->atsin[i].norm <= 2.0))
626 norm_values[i] = address->atsin[i].norm;
628 norm_values[i] = DEFAULT_REL_QUALITY;
634 * Normalize a specific ATS type with the values in queue
635 * @param address the address
636 * @param atsi the ats information
637 * @return the new average or GNUNET_ATS_VALUE_UNDEFINED
641 property_average (struct ATS_Address *address,
642 const struct GNUNET_ATS_Information *atsi)
644 struct GAS_NormalizationInfo *ni;
645 uint32_t current_type;
646 uint32_t current_val;
652 unsigned int props[] = GNUNET_ATS_QualityProperties;
654 /* Average the values of this property */
655 current_type = ntohl (atsi->type);
656 current_val = ntohl (atsi->value);
658 for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
660 if (current_type == props[c1])
663 if (c1 == GNUNET_ATS_QualityPropertiesCount)
666 return GNUNET_ATS_VALUE_UNDEFINED;
670 ni = &address->atsin[index];
671 ni->atsi_abs[ni->avg_queue_index] = current_val;
672 ni->avg_queue_index++;
673 if (GAS_normalization_queue_length == ni->avg_queue_index)
674 ni->avg_queue_index = 0;
678 for (c1 = 0; c1 < GAS_normalization_queue_length; c1++)
680 if (GNUNET_ATS_VALUE_UNDEFINED != ni->atsi_abs[c1])
683 if (GNUNET_ATS_VALUE_UNDEFINED > (sum + ni->atsi_abs[c1]))
684 sum += ni->atsi_abs[c1];
687 sum = GNUNET_ATS_VALUE_UNDEFINED - 1;
692 GNUNET_assert(0 != count);
694 LOG(GNUNET_ERROR_TYPE_DEBUG,
695 "New average of `%s' created by adding %u from %u elements: %u\n",
696 GNUNET_ATS_print_property_type (current_type), current_val, count, res,
710 find_min_max_it (void *cls, const struct GNUNET_PeerIdentity *h, void *k)
712 struct FindMinMaxCtx *find_res = cls;
713 struct ATS_Address *a = k;
715 if (a->atsin[find_res->p->prop_type].avg > find_res->max)
716 find_res->max = a->atsin[find_res->p->prop_type].avg;
718 if (a->atsin[find_res->p->prop_type].avg < find_res->min)
719 find_res->min = a->atsin[find_res->p->prop_type].avg;
725 normalize_address (void *cls, const struct GNUNET_PeerIdentity *h, void *k)
727 struct Property *p = cls;
728 struct ATS_Address *address = k;
733 backup = address->atsin[p->prop_type].norm;
734 avg_value = address->atsin[p->prop_type].avg;
735 delta = p->max - p->min;
736 address->atsin[p->prop_type].norm = (delta + (avg_value - p->min)) / (delta);
738 if (backup == address->atsin[p->prop_type].norm)
741 LOG(GNUNET_ERROR_TYPE_DEBUG,
742 "Normalize `%s' address %p's '%s' with value %u to range [%u..%u] = %.3f\n",
743 GNUNET_i2s (&address->peer), address,
744 GNUNET_ATS_print_property_type (p->atsi_type),
745 address->atsin[p->prop_type].avg, p->min, p->max,
746 address->atsin[p->prop_type].norm);
748 if (NULL != prop_ch_cb)
749 prop_ch_cb (prop_ch_cb_cls, address, p->atsi_type,
750 address->atsin[p->prop_type].norm);
756 * Normalize avg_value to a range of values between [1.0, 2.0]
757 * based on min max values currently known.
759 * @param addresses the address hashmap
760 * @param p the property
761 * @param address the address
762 * @param avg_value the value to normalize
765 property_normalize (struct GNUNET_CONTAINER_MultiPeerMap *addresses,
766 struct Property *p, struct ATS_Address *address, uint32_t avg_value)
768 struct FindMinMaxCtx find_ctx;
774 find_ctx.min = UINT32_MAX;
775 addr_count = GNUNET_CONTAINER_multipeermap_iterate (addresses,
776 &find_min_max_it, &find_ctx);
783 limits_changed = GNUNET_NO;
784 if (find_ctx.max != p->max)
786 LOG(GNUNET_ERROR_TYPE_DEBUG,
787 "Normalizing %s: new maximum %u -> recalculate all values\n",
788 GNUNET_ATS_print_property_type (p->atsi_type), find_ctx.max);
789 p->max = find_ctx.max;
790 limits_changed = GNUNET_YES;
793 if ((find_ctx.min != p->min) && (find_ctx.min < p->max))
795 LOG(GNUNET_ERROR_TYPE_DEBUG,
796 "Normalizing %s: new minimum %u -> recalculate all values\n",
797 GNUNET_ATS_print_property_type (p->atsi_type), find_ctx.min,
799 p->min = find_ctx.min;
800 limits_changed = GNUNET_YES;
802 else if (find_ctx.min == p->max)
804 /* Only one value, so minimum has to be 0 */
808 /* Normalize the values of this property */
809 if (GNUNET_NO == limits_changed)
811 /* normalize just this address */
812 normalize_address (p, &address->peer, address);
817 /* limits changed, normalize all addresses */
818 GNUNET_CONTAINER_multipeermap_iterate (addresses, &normalize_address, p);
824 * Update and normalize atsi performance information
826 * @param addresses hashmap containing all addresses
827 * @param address the address to update
828 * @param atsi the array of performance information
829 * @param atsi_count the number of atsi information in the array
832 GAS_normalization_normalize_property (
833 struct GNUNET_CONTAINER_MultiPeerMap *addresses,
834 struct ATS_Address *address, const struct GNUNET_ATS_Information *atsi,
837 struct Property *cur_prop;
840 uint32_t current_type;
841 uint32_t current_val;
842 unsigned int existing_properties[] = GNUNET_ATS_QualityProperties;
844 GNUNET_assert(NULL != address);
845 GNUNET_assert(NULL != atsi);
847 LOG(GNUNET_ERROR_TYPE_DEBUG, "Updating %u elements for peer `%s'\n",
848 atsi_count, GNUNET_i2s (&address->peer));
850 for (c1 = 0; c1 < atsi_count; c1++)
852 current_type = ntohl (atsi[c1].type);
854 for (c2 = 0; c2 < GNUNET_ATS_QualityPropertiesCount; c2++)
856 /* Check if type is valid */
857 if (current_type == existing_properties[c2])
860 if (GNUNET_ATS_QualityPropertiesCount == c2)
862 /* Invalid property, continue with next element */
866 current_val = property_average (address, &atsi[c1]);
867 if (GNUNET_ATS_VALUE_UNDEFINED == current_val)
875 cur_prop = &properties[c2];
876 property_normalize (addresses, cur_prop, address, current_val);
881 free_client (struct PreferenceClient *pc)
883 struct PreferencePeer *next_p;
884 struct PreferencePeer *p;
886 while (NULL != (p = next_p))
889 GNUNET_CONTAINER_DLL_remove(pc->p_head, pc->p_tail, p);
896 * A performance client disconnected
898 * @param client the client
902 GAS_normalization_preference_client_disconnect (void *client)
904 struct PreferenceClient *c_cur;
905 /* Find preference client */
907 for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
909 if (client == c_cur->client)
915 GNUNET_CONTAINER_DLL_remove(pc_head, pc_tail, c_cur);
920 * Start the normalization component
922 * @param pref_ch_cb callback to call on relative preference changing
923 * @param pref_ch_cb_cls cls for the preference callback
924 * @param property_ch_cb callback to call on relative property changing
925 * @param property_ch_cb_cls cls for the property callback
928 GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb,
929 void *pref_ch_cb_cls, GAS_Normalization_property_changed_cb property_ch_cb,
930 void *property_ch_cb_cls)
934 preference_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
935 property_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
936 unsigned int existing_properties[] = GNUNET_ATS_QualityProperties;
938 for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
940 properties[c1].prop_type = c1;
941 properties[c1].atsi_type = existing_properties[c1];
942 properties[c1].min = 0;
943 properties[c1].max = 0;
946 pref_changed_cb = pref_ch_cb;
947 pref_changed_cb_cls = pref_ch_cb_cls;
948 prop_ch_cb = property_ch_cb;
949 prop_ch_cb_cls = pref_ch_cb_cls;
954 for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
955 defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE;
956 aging_task = GNUNET_SCHEDULER_NO_TASK;
965 * @param value RelativePeer
966 * @return #GNUNET_OK to continue
969 free_peer (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
971 struct PeerRelative *rp = value;
973 == GNUNET_CONTAINER_multipeermap_remove (preference_peers, key, value))
981 * Stop the normalization component and free all items
984 GAS_normalization_stop ()
986 struct PreferenceClient *pc;
987 struct PreferenceClient *next_pc;
989 if (GNUNET_SCHEDULER_NO_TASK != aging_task)
991 GNUNET_SCHEDULER_cancel (aging_task);
992 aging_task = GNUNET_SCHEDULER_NO_TASK;
996 while (NULL != (pc = next_pc))
999 GNUNET_CONTAINER_DLL_remove(pc_head, pc_tail, pc);
1003 GNUNET_CONTAINER_multipeermap_iterate (preference_peers, &free_peer, NULL );
1004 GNUNET_CONTAINER_multipeermap_destroy (preference_peers);
1005 GNUNET_CONTAINER_multipeermap_destroy (property_peers);
1009 /* end of gnunet-service-ats_normalization.c */