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_normalization.h"
36 struct PreferenceClient
41 struct PreferenceClient *prev;
47 struct PreferenceClient *next;
55 * Total preference for this peer
57 double f_total[GNUNET_ATS_PreferenceCount];
60 * List of peer preferences for this client
66 struct PreferencePeer *p_head;
71 struct PreferencePeer *p_tail;
83 struct PreferencePeer *next;
88 struct PreferencePeer *prev;
93 struct PreferenceClient *client;
98 struct GNUNET_PeerIdentity id;
103 double f[GNUNET_ATS_PreferenceCount];
106 * Relative Preference Values
108 double f_rel[GNUNET_ATS_PreferenceCount];
111 * Relative Total Preference Value
115 GNUNET_SCHEDULER_TaskIdentifier aging_task;
120 struct PreferenceClient *pc_head;
121 struct PreferenceClient *pc_tail;
124 preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
130 * Changes the preferences for a peer in the problem
132 * @param solver the solver handle
133 * @param client the client with this preference
134 * @param peer the peer to change the preference for
135 * @param kind the kind to change the preference
136 * @param score the normalized score
139 GAS_normalization_change_preference (void *src,
140 const struct GNUNET_PeerIdentity *peer,
141 enum GNUNET_ATS_PreferenceKind kind,
144 float score_rel = 1.0;
145 struct PreferenceClient *c_cur;
146 struct PreferencePeer *p_cur;
150 GNUNET_assert (NULL != src);
151 GNUNET_assert (NULL != peer);
153 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p changes preference for peer `%s' %s %f\n",
156 GNUNET_ATS_print_preference_type (kind),
159 if (kind >= GNUNET_ATS_PreferenceCount)
165 /* Find preference client */
166 for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
168 if (src == c_cur->client)
171 /* Not found: create new preference client */
174 c_cur = GNUNET_malloc (sizeof (struct PreferenceClient));
176 GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, c_cur);
179 /* Find entry for peer */
180 for (p_cur = c_cur->p_head; NULL != p_cur; p_cur = p_cur->next)
181 if (0 == memcmp (&p_cur->id, peer, sizeof (p_cur->id)))
184 /* Not found: create new peer entry */
187 p_cur = GNUNET_malloc (sizeof (struct PreferencePeer));
188 p_cur->client = c_cur;
190 for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
192 /* Default value per peer absolut preference for a quality:
193 * No value set, so absolute preference 0 */
194 p_cur->f[i] = DEFAULT_ABS_PREFERENCE;
195 /* Default value per peer relative preference for a quality: 1.0 */
196 p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
198 p_cur->aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, &preference_aging, p_cur);
199 GNUNET_CONTAINER_DLL_insert (c_cur->p_head, c_cur->p_tail, p_cur);
201 // update_preference (p_cur, kind, score);
206 GAS_normalization_start ()
212 GAS_normalization_stop ()
214 struct PreferenceClient *pc;
215 struct PreferenceClient *next_pc;
216 struct PreferencePeer *p;
217 struct PreferencePeer *next_p;
220 while (NULL != (pc = next_pc))
223 GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
225 while (NULL != (p = next_p))
228 if (GNUNET_SCHEDULER_NO_TASK != p->aging_task)
230 GNUNET_SCHEDULER_cancel(p->aging_task);
231 p->aging_task = GNUNET_SCHEDULER_NO_TASK;
233 GNUNET_CONTAINER_DLL_remove (pc->p_head, pc->p_tail, p);
241 /* end of gnunet-service-ats_normalization.c */