diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-18 06:29:10 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-18 06:29:10 +0000 |
commit | 34410c93193c7175aba1f46bee08587c7d926b90 (patch) | |
tree | 0d6765ca84954395797a78f948af984a32534ac3 /src/ats/gnunet-service-ats_normalization.c | |
parent | a1a3e38bf8d6f8e67c5e9f1109706bece9bef10c (diff) | |
download | gnunet-34410c93193c7175aba1f46bee08587c7d926b90.tar.gz gnunet-34410c93193c7175aba1f46bee08587c7d926b90.zip |
Diffstat (limited to 'src/ats/gnunet-service-ats_normalization.c')
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index 2d5c07520..ccc67f5f6 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c | |||
@@ -129,7 +129,7 @@ struct PeerRelative | |||
129 | struct GNUNET_PeerIdentity id; | 129 | struct GNUNET_PeerIdentity id; |
130 | }; | 130 | }; |
131 | 131 | ||
132 | 132 | GAS_Normalization_preference_changed_cb pref_changed_cb; | |
133 | struct GNUNET_CONTAINER_MultiHashMap *peers; | 133 | struct GNUNET_CONTAINER_MultiHashMap *peers; |
134 | struct PreferenceClient *pc_head; | 134 | struct PreferenceClient *pc_head; |
135 | struct PreferenceClient *pc_tail; | 135 | struct PreferenceClient *pc_tail; |
@@ -144,6 +144,7 @@ update_peers (struct GNUNET_PeerIdentity *id, | |||
144 | struct PreferencePeer *p_cur; | 144 | struct PreferencePeer *p_cur; |
145 | struct PeerRelative *rp; | 145 | struct PeerRelative *rp; |
146 | double f_rel_total; | 146 | double f_rel_total; |
147 | double backup; | ||
147 | unsigned int count; | 148 | unsigned int count; |
148 | 149 | ||
149 | f_rel_total = 0.0; | 150 | f_rel_total = 0.0; |
@@ -166,33 +167,35 @@ update_peers (struct GNUNET_PeerIdentity *id, | |||
166 | } | 167 | } |
167 | } | 168 | } |
168 | 169 | ||
169 | if (0 < count) | 170 | /* Find a client */ |
171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u clients have a total relative preference for peer `%s''s `%s' of %.3f\n", | ||
172 | count, | ||
173 | GNUNET_i2s (id), | ||
174 | GNUNET_ATS_print_preference_type (kind), | ||
175 | f_rel_total); | ||
176 | if (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (peers, &id->hashPubKey))) | ||
170 | { | 177 | { |
171 | /* Find a client */ | 178 | backup = rp->f_rel[kind]; |
172 | f_rel_total /= count; | 179 | if (0 < count) |
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u clients have a total relative preference for peer `%s''s%s is %.3f\n", | ||
174 | count, | ||
175 | GNUNET_i2s (id), | ||
176 | GNUNET_ATS_print_preference_type (kind), | ||
177 | f_rel_total); | ||
178 | if (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (peers, &id->hashPubKey))) | ||
179 | { | 180 | { |
180 | rp->f_rel[kind] = f_rel_total; | 181 | rp->f_rel[kind] = f_rel_total / count; |
181 | } | 182 | } |
182 | return f_rel_total; | 183 | else |
183 | } | ||
184 | else | ||
185 | { | ||
186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No clients have a total relative preference for peer `%s''s%s\n", | ||
187 | count, | ||
188 | GNUNET_i2s (id), | ||
189 | GNUNET_ATS_print_preference_type (kind)); | ||
190 | if (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (peers, &id->hashPubKey))) | ||
191 | { | 184 | { |
192 | rp->f_rel[kind] = DEFAULT_REL_PREFERENCE; | 185 | rp->f_rel[kind] = DEFAULT_REL_PREFERENCE; |
193 | } | 186 | } |
187 | } | ||
188 | else | ||
189 | { | ||
194 | return DEFAULT_REL_PREFERENCE; | 190 | return DEFAULT_REL_PREFERENCE; |
195 | } | 191 | } |
192 | |||
193 | if ((backup != rp->f_rel[kind]) && (NULL != pref_changed_cb)) | ||
194 | { | ||
195 | pref_changed_cb (&rp->id, kind, rp->f_rel[kind]); | ||
196 | } | ||
197 | |||
198 | return rp->f_rel[kind]; | ||
196 | } | 199 | } |
197 | 200 | ||
198 | /** | 201 | /** |
@@ -426,12 +429,13 @@ GAS_normalization_get_preferences (struct GNUNET_PeerIdentity *id) | |||
426 | return rp->f_rel; | 429 | return rp->f_rel; |
427 | } | 430 | } |
428 | 431 | ||
432 | |||
429 | void | 433 | void |
430 | GAS_normalization_start () | 434 | GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb) |
431 | { | 435 | { |
432 | int i; | 436 | int i; |
433 | peers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); | 437 | peers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); |
434 | 438 | pref_changed_cb = pref_ch_cb; | |
435 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 439 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) |
436 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; | 440 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; |
437 | return; | 441 | return; |