-/**
- * Normalize an updated preference value
- *
- * @param client the client with this preference
- * @param peer the peer to change the preference for
- * @param kind the kind to change the preference
- * @param score_abs the normalized score
- */
-void
-GAS_normalization_normalize_preference (void *client,
- const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- float score_abs)
-{
- struct PreferenceClient *c_cur;
- struct PreferencePeer *p_cur;
- struct PeerRelative *r_cur;
- double old_value;
- int i;
-
- GNUNET_assert(NULL != client);
- GNUNET_assert(NULL != peer);
-
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p changes preference for peer `%s' for `%s' to %.2f\n",
- client,
- GNUNET_i2s (peer),
- GNUNET_ATS_print_preference_type (kind),
- score_abs);
-
- if (kind >= GNUNET_ATS_PreferenceCount)
- {
- GNUNET_break(0);
- return;
- }
-
- /* Find preference client */
- for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
- {
- if (client == c_cur->client)
- break;
- }
- /* Not found: create new preference client */
- if (NULL == c_cur)
- {
- c_cur = GNUNET_new (struct PreferenceClient);
- c_cur->client = client;
- for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
- {
- c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE;
- c_cur->f_rel_sum[i] = DEFAULT_REL_PREFERENCE;
- }
-
- GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, c_cur);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding new client %p \n", c_cur);
- }
-
- /* Find entry for peer */
- for (p_cur = c_cur->p_head; NULL != p_cur; p_cur = p_cur->next)
- if (0 == memcmp (&p_cur->id, peer, sizeof(p_cur->id)))
- break;
-
- /* Not found: create new peer entry */
- if (NULL == p_cur)
- {
- p_cur = GNUNET_new (struct PreferencePeer);
- p_cur->client = c_cur;
- p_cur->id = (*peer);
- for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
- {
- /* Default value per peer absolute preference for a preference: 0 */
- p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE;
- /* Default value per peer relative preference for a quality: 1.0 */
- p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
- p_cur->next_aging[i] = GNUNET_TIME_UNIT_FOREVER_ABS;
- }
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding new peer %p for client %p \n",
- p_cur, c_cur);
- GNUNET_CONTAINER_DLL_insert(c_cur->p_head, c_cur->p_tail, p_cur);
- }
-
- /* Create struct for peer */
- if (NULL == GNUNET_CONTAINER_multipeermap_get (preference_peers, peer))
- {
- r_cur = GNUNET_new (struct PeerRelative);
- r_cur->id = (*peer);
- for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
- r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
- GNUNET_assert(
- GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (preference_peers,
- &r_cur->id, r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- }
-
- /* Update absolute value */
- old_value = p_cur->f_abs[kind];
- update_abs_preference (c_cur, p_cur, kind, score_abs);
- if (p_cur->f_abs[kind] == old_value)
- return;
-
- run_preference_update (c_cur, p_cur, kind, score_abs);
-
- /* Start aging task */
- if (GNUNET_SCHEDULER_NO_TASK == aging_task)
- aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
- &preference_aging, NULL );
-
-}