aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-05 20:09:20 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-05 20:09:20 +0000
commit04c43865242385b22cb8a399843680542009031a (patch)
treeb47a63f5ea1e09095f5d08f3767efe66cbd468cf /src
parentae8902cf73b5f8a6121fada4c9796b4750b5ce19 (diff)
downloadgnunet-04c43865242385b22cb8a399843680542009031a.tar.gz
gnunet-04c43865242385b22cb8a399843680542009031a.zip
starting with cleaning up gnunet-service-ats_preferences.c
Diffstat (limited to 'src')
-rw-r--r--src/ats/gnunet-service-ats_preferences.c97
1 files changed, 52 insertions, 45 deletions
diff --git a/src/ats/gnunet-service-ats_preferences.c b/src/ats/gnunet-service-ats_preferences.c
index 41fb78140..762caf8ea 100644
--- a/src/ats/gnunet-service-ats_preferences.c
+++ b/src/ats/gnunet-service-ats_preferences.c
@@ -64,14 +64,13 @@ struct PeerRelative
64static struct PeerRelative defvalues; 64static struct PeerRelative defvalues;
65 65
66 66
67
68/** 67/**
69 * Preference client 68 * Preference client, information we keep track of per client.
70 */ 69 */
71struct PreferenceClient 70struct PreferenceClient
72{ 71{
73 /** 72 /**
74 * Next in DLL 73 * Previous in DLL
75 */ 74 */
76 struct PreferenceClient *prev; 75 struct PreferenceClient *prev;
77 76
@@ -81,54 +80,54 @@ struct PreferenceClient
81 struct PreferenceClient *next; 80 struct PreferenceClient *next;
82 81
83 /** 82 /**
84 * Client handle 83 * Head of peer list
85 */ 84 */
86 void *client; 85 struct PreferencePeer *p_head;
87 86
88 /** 87 /**
89 * Array of sum of absolute preferences for this client 88 * Tail of peer list
90 */ 89 */
91 double f_abs_sum[GNUNET_ATS_PreferenceCount]; 90 struct PreferencePeer *p_tail;
92 91
93 /** 92 /**
94 * Array of sum of relative preferences for this client 93 * Client handle
95 */ 94 */
96 double f_rel_sum[GNUNET_ATS_PreferenceCount]; 95 struct GNUNET_SERVER_Client *client;
97 96
98 /** 97 /**
99 * Head of peer list 98 * Array of sum of absolute preferences for this client
100 */ 99 */
101 struct PreferencePeer *p_head; 100 double f_abs_sum[GNUNET_ATS_PreferenceCount];
102 101
103 /** 102 /**
104 * Tail of peer list 103 * Array of sum of relative preferences for this client
105 */ 104 */
106 struct PreferencePeer *p_tail; 105 double f_rel_sum[GNUNET_ATS_PreferenceCount];
107}; 106};
108 107
109 108
110/** 109/**
111 * Preference peer 110 * Preference information per peer and client.
112 */ 111 */
113struct PreferencePeer 112struct PreferencePeer
114{ 113{
115 /** 114 /**
116 * Next in DLL 115 * Next in DLL of preference entries for the same client.
117 */ 116 */
118 struct PreferencePeer *next; 117 struct PreferencePeer *next;
119 118
120 /** 119 /**
121 * Previous in DLL 120 * Previous in DLL of preference entries for the same client.
122 */ 121 */
123 struct PreferencePeer *prev; 122 struct PreferencePeer *prev;
124 123
125 /** 124 /**
126 * Client 125 * Client that expressed this preferences.
127 */ 126 */
128 struct PreferenceClient *client; 127 struct PreferenceClient *client;
129 128
130 /** 129 /**
131 * Peer id 130 * Peer identity for which the preference was expressed.
132 */ 131 */
133 struct GNUNET_PeerIdentity id; 132 struct GNUNET_PeerIdentity id;
134 133
@@ -164,9 +163,10 @@ static struct PreferenceClient *pc_head;
164 */ 163 */
165static struct PreferenceClient *pc_tail; 164static struct PreferenceClient *pc_tail;
166 165
167 166/**
168 167 * Handle for task we run periodically to age preferences over time.
169static struct GNUNET_SCHEDULER_Task * aging_task; 168 */
169static struct GNUNET_SCHEDULER_Task *aging_task;
170 170
171 171
172/** 172/**
@@ -210,12 +210,13 @@ update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id,
210 } 210 }
211 211
212 LOG (GNUNET_ERROR_TYPE_DEBUG, 212 LOG (GNUNET_ERROR_TYPE_DEBUG,
213 "%u clients have a total relative preference for peer `%s' `%s' of %.3f and for %s in total %.3f\n", 213 "%u clients have a total relative preference for peer `%s' `%s' of %.3f and for %s in total %.3f\n",
214 peer_count, GNUNET_i2s (id), 214 peer_count,
215 GNUNET_ATS_print_preference_type (kind), 215 GNUNET_i2s (id),
216 f_rel_total, 216 GNUNET_ATS_print_preference_type (kind),
217 GNUNET_ATS_print_preference_type (kind), 217 f_rel_total,
218 f_rel_sum); 218 GNUNET_ATS_print_preference_type (kind),
219 f_rel_sum);
219 220
220 /* Find entry for the peer containing relative values in the hashmap */ 221 /* Find entry for the peer containing relative values in the hashmap */
221 if (NULL != rp) 222 if (NULL != rp)
@@ -234,6 +235,9 @@ update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id,
234} 235}
235 236
236 237
238/**
239 * FIXME
240 */
237static int 241static int
238update_iterator (void *cls, 242update_iterator (void *cls,
239 const struct GNUNET_PeerIdentity *key, 243 const struct GNUNET_PeerIdentity *key,
@@ -249,7 +253,6 @@ update_iterator (void *cls,
249} 253}
250 254
251 255
252
253/** 256/**
254 * Recalculate preference for a specific ATS property 257 * Recalculate preference for a specific ATS property
255 * 258 *
@@ -300,7 +303,10 @@ recalculate_relative_preferences (struct PreferenceClient *c,
300} 303}
301 304
302 305
303 306/**
307 * FIXME.
308 *
309 */
304static void 310static void
305run_preference_update (struct PreferenceClient *c_cur, 311run_preference_update (struct PreferenceClient *c_cur,
306 struct PreferencePeer *p_cur, 312 struct PreferencePeer *p_cur,
@@ -322,8 +328,6 @@ run_preference_update (struct PreferenceClient *c_cur,
322} 328}
323 329
324 330
325
326
327/** 331/**
328 * Reduce absolute preferences since they got old 332 * Reduce absolute preferences since they got old
329 * 333 *
@@ -331,12 +335,13 @@ run_preference_update (struct PreferenceClient *c_cur,
331 * @param tc context 335 * @param tc context
332 */ 336 */
333static void 337static void
334preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 338preference_aging (void *cls,
339 const struct GNUNET_SCHEDULER_TaskContext *tc)
335{ 340{
336 struct PreferencePeer *p; 341 struct PreferencePeer *p;
337 struct PreferenceClient *cur_client; 342 struct PreferenceClient *cur_client;
338 int i; 343 unsigned int i;
339 int values_to_update; 344 unsigned int values_to_update;
340 double backup; 345 double backup;
341 346
342 aging_task = NULL; 347 aging_task = NULL;
@@ -382,16 +387,18 @@ preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
382 387
383 if (values_to_update > 0) 388 if (values_to_update > 0)
384 { 389 {
385 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
386 "Rescheduling aging task due to %u elements to age\n", 391 "Rescheduling aging task due to %u elements to age\n",
387 values_to_update); 392 values_to_update);
388 aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, 393 aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
389 &preference_aging, NULL ); 394 &preference_aging,
395 NULL);
390 } 396 }
391 else 397 else
392 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 398 {
393 "No values to age left, not rescheduling aging task\n"); 399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 400 "No values to age left, not rescheduling aging task\n");
401 }
395} 402}
396 403
397 404
@@ -720,11 +727,11 @@ const double *
720GAS_normalization_get_preferences_by_peer (void *cls, 727GAS_normalization_get_preferences_by_peer (void *cls,
721 const struct GNUNET_PeerIdentity *id) 728 const struct GNUNET_PeerIdentity *id)
722{ 729{
723 GNUNET_assert(NULL != preference_peers);
724 GNUNET_assert(NULL != id);
725
726 struct PeerRelative *rp; 730 struct PeerRelative *rp;
727 if (NULL == (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, id))) 731
732 if (NULL ==
733 (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers,
734 id)))
728 { 735 {
729 return defvalues.f_rel; 736 return defvalues.f_rel;
730 } 737 }