diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-08 13:41:07 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-08 13:41:07 +0000 |
commit | 1d971bac50ceddcd6ea2ff20525013becc1d6170 (patch) | |
tree | 3a3e1903c061741c67a07b5281407d438321b455 /src/ats/gnunet-service-ats_preferences.c | |
parent | 02a693623a817c991630c45691907b618470a0bb (diff) | |
download | gnunet-1d971bac50ceddcd6ea2ff20525013becc1d6170.tar.gz gnunet-1d971bac50ceddcd6ea2ff20525013becc1d6170.zip |
-adding comments, minor cleanup start
Diffstat (limited to 'src/ats/gnunet-service-ats_preferences.c')
-rw-r--r-- | src/ats/gnunet-service-ats_preferences.c | 107 |
1 files changed, 58 insertions, 49 deletions
diff --git a/src/ats/gnunet-service-ats_preferences.c b/src/ats/gnunet-service-ats_preferences.c index c26a71b5d..e22a583ee 100644 --- a/src/ats/gnunet-service-ats_preferences.c +++ b/src/ats/gnunet-service-ats_preferences.c | |||
@@ -32,20 +32,23 @@ | |||
32 | #include "gnunet-service-ats_reservations.h" | 32 | #include "gnunet-service-ats_reservations.h" |
33 | #include "ats.h" | 33 | #include "ats.h" |
34 | 34 | ||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-preferencesx",__VA_ARGS__) | 35 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-preferences",__VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * | 38 | * How frequently do we age preference values? |
39 | */ | 39 | */ |
40 | #define PREF_AGING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 40 | #define PREF_AGING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * | 43 | * By which factor do we age preferences expressed during |
44 | * each #PREF_AGING_INTERVAL? | ||
44 | */ | 45 | */ |
45 | #define PREF_AGING_FACTOR 0.95 | 46 | #define PREF_AGING_FACTOR 0.95 |
46 | 47 | ||
47 | /** | 48 | /** |
48 | * | 49 | * What is the lowest threshold up to which prefernce values |
50 | * are aged, and below which we consider them zero and thus | ||
51 | * no longer subject to aging? | ||
49 | */ | 52 | */ |
50 | #define PREF_EPSILON 0.01 | 53 | #define PREF_EPSILON 0.01 |
51 | 54 | ||
@@ -158,7 +161,9 @@ struct PreferencePeer | |||
158 | 161 | ||
159 | 162 | ||
160 | /** | 163 | /** |
161 | * Hashmap to store peer information for preference normalization | 164 | * Hashmap to store peer information for preference normalization. |
165 | * Maps the identity of a peer to a `struct PeerRelative` containing | ||
166 | * the current relative preference values for that peer. | ||
162 | */ | 167 | */ |
163 | static struct GNUNET_CONTAINER_MultiPeerMap *preference_peers; | 168 | static struct GNUNET_CONTAINER_MultiPeerMap *preference_peers; |
164 | 169 | ||
@@ -245,24 +250,6 @@ update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id, | |||
245 | 250 | ||
246 | 251 | ||
247 | /** | 252 | /** |
248 | * FIXME | ||
249 | */ | ||
250 | static int | ||
251 | update_iterator (void *cls, | ||
252 | const struct GNUNET_PeerIdentity *key, | ||
253 | void *value) | ||
254 | { | ||
255 | enum GNUNET_ATS_PreferenceKind *kind = cls; | ||
256 | struct PeerRelative *pr = value; | ||
257 | |||
258 | update_relative_values_for_peer (key, | ||
259 | *kind, | ||
260 | pr); | ||
261 | return GNUNET_OK; | ||
262 | } | ||
263 | |||
264 | |||
265 | /** | ||
266 | * Recalculate preference for a specific ATS property | 253 | * Recalculate preference for a specific ATS property |
267 | * | 254 | * |
268 | * @param c the preference client | 255 | * @param c the preference client |
@@ -287,8 +274,10 @@ recalculate_relative_preferences (struct PreferenceClient *c, | |||
287 | for (p_cur = c->p_head; NULL != p_cur; p_cur = p_cur->next) | 274 | for (p_cur = c->p_head; NULL != p_cur; p_cur = p_cur->next) |
288 | c->f_abs_sum[kind] += p_cur->f_abs[kind]; | 275 | c->f_abs_sum[kind] += p_cur->f_abs[kind]; |
289 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 276 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
290 | "Client %p has sum of total preferences for %s of %.3f\n", | 277 | "Client %p has sum of total preferences for %s of %.3f\n", |
291 | c->client, GNUNET_ATS_print_preference_type (kind), c->f_abs_sum[kind]); | 278 | c->client, |
279 | GNUNET_ATS_print_preference_type (kind), | ||
280 | c->f_abs_sum[kind]); | ||
292 | 281 | ||
293 | /* For all peers: calculate relative preference */ | 282 | /* For all peers: calculate relative preference */ |
294 | for (p_cur = c->p_head; NULL != p_cur; p_cur = p_cur->next) | 283 | for (p_cur = c->p_head; NULL != p_cur; p_cur = p_cur->next) |
@@ -308,7 +297,24 @@ recalculate_relative_preferences (struct PreferenceClient *c, | |||
308 | GNUNET_i2s (&p_cur->id), | 297 | GNUNET_i2s (&p_cur->id), |
309 | p_cur->f_rel[kind]); | 298 | p_cur->f_rel[kind]); |
310 | } | 299 | } |
300 | } | ||
311 | 301 | ||
302 | |||
303 | /** | ||
304 | * FIXME | ||
305 | */ | ||
306 | static int | ||
307 | update_iterator (void *cls, | ||
308 | const struct GNUNET_PeerIdentity *key, | ||
309 | void *value) | ||
310 | { | ||
311 | enum GNUNET_ATS_PreferenceKind *kind = cls; | ||
312 | struct PeerRelative *pr = value; | ||
313 | |||
314 | update_relative_values_for_peer (key, | ||
315 | *kind, | ||
316 | pr); | ||
317 | return GNUNET_OK; | ||
312 | } | 318 | } |
313 | 319 | ||
314 | 320 | ||
@@ -538,11 +544,11 @@ normalize_preference (struct GNUNET_SERVER_Client *client, | |||
538 | r_cur->id = *peer; | 544 | r_cur->id = *peer; |
539 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 545 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) |
540 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; | 546 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; |
541 | GNUNET_assert(GNUNET_OK == | 547 | GNUNET_assert (GNUNET_OK == |
542 | GNUNET_CONTAINER_multipeermap_put (preference_peers, | 548 | GNUNET_CONTAINER_multipeermap_put (preference_peers, |
543 | &r_cur->id, | 549 | &r_cur->id, |
544 | r_cur, | 550 | r_cur, |
545 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 551 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
546 | } | 552 | } |
547 | 553 | ||
548 | /* Update absolute value */ | 554 | /* Update absolute value */ |
@@ -583,8 +589,6 @@ GAS_handle_preference_change (void *cls, | |||
583 | uint32_t nump; | 589 | uint32_t nump; |
584 | uint32_t i; | 590 | uint32_t i; |
585 | 591 | ||
586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
587 | "Received PREFERENCE_CHANGE message\n"); | ||
588 | msize = ntohs (message->size); | 592 | msize = ntohs (message->size); |
589 | if (msize < sizeof (struct ChangePreferenceMessage)) | 593 | if (msize < sizeof (struct ChangePreferenceMessage)) |
590 | { | 594 | { |
@@ -594,14 +598,18 @@ GAS_handle_preference_change (void *cls, | |||
594 | } | 598 | } |
595 | msg = (const struct ChangePreferenceMessage *) message; | 599 | msg = (const struct ChangePreferenceMessage *) message; |
596 | nump = ntohl (msg->num_preferences); | 600 | nump = ntohl (msg->num_preferences); |
597 | if (msize != | 601 | if ( (msize != |
598 | sizeof (struct ChangePreferenceMessage) + | 602 | sizeof (struct ChangePreferenceMessage) + |
599 | nump * sizeof (struct PreferenceInformation)) | 603 | nump * sizeof (struct PreferenceInformation)) || |
604 | (UINT16_MAX / sizeof (struct PreferenceInformation) < nump) ) | ||
600 | { | 605 | { |
601 | GNUNET_break (0); | 606 | GNUNET_break (0); |
602 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 607 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
603 | return; | 608 | return; |
604 | } | 609 | } |
610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
611 | "Received PREFERENCE_CHANGE message for peer `%s'\n", | ||
612 | GNUNET_i2s (&msg->peer)); | ||
605 | GNUNET_STATISTICS_update (GSA_stats, | 613 | GNUNET_STATISTICS_update (GSA_stats, |
606 | "# preference change requests processed", | 614 | "# preference change requests processed", |
607 | 1, GNUNET_NO); | 615 | 1, GNUNET_NO); |
@@ -622,20 +630,21 @@ GAS_handle_preference_change (void *cls, | |||
622 | void | 630 | void |
623 | GAS_preference_init () | 631 | GAS_preference_init () |
624 | { | 632 | { |
625 | int i; | 633 | unsigned int i; |
626 | 634 | ||
627 | preference_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 635 | preference_peers = GNUNET_CONTAINER_multipeermap_create (16, |
636 | GNUNET_NO); | ||
628 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 637 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) |
629 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; | 638 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; |
630 | } | 639 | } |
631 | 640 | ||
632 | 641 | ||
633 | /** | 642 | /** |
634 | * Free a peer | 643 | * Free a peer's `struct PeerRelative`. |
635 | * | 644 | * |
636 | * @param cls unused | 645 | * @param cls unused |
637 | * @param key the key | 646 | * @param key the key |
638 | * @param value RelativePeer | 647 | * @param value the `struct PeerRelative` to free. |
639 | * @return #GNUNET_OK to continue | 648 | * @return #GNUNET_OK to continue |
640 | */ | 649 | */ |
641 | static int | 650 | static int |
@@ -645,13 +654,11 @@ free_peer (void *cls, | |||
645 | { | 654 | { |
646 | struct PeerRelative *rp = value; | 655 | struct PeerRelative *rp = value; |
647 | 656 | ||
648 | if (GNUNET_YES == | 657 | GNUNET_assert (GNUNET_YES == |
649 | GNUNET_CONTAINER_multipeermap_remove (preference_peers, | 658 | GNUNET_CONTAINER_multipeermap_remove (preference_peers, |
650 | key, | 659 | key, |
651 | value)) | 660 | value)); |
652 | GNUNET_free (rp); | 661 | GNUNET_free (rp); |
653 | else | ||
654 | GNUNET_break (0); | ||
655 | return GNUNET_OK; | 662 | return GNUNET_OK; |
656 | } | 663 | } |
657 | 664 | ||
@@ -666,10 +673,12 @@ free_client (struct PreferenceClient *pc) | |||
666 | while (NULL != (p = next_p)) | 673 | while (NULL != (p = next_p)) |
667 | { | 674 | { |
668 | next_p = p->next; | 675 | next_p = p->next; |
669 | GNUNET_CONTAINER_DLL_remove(pc->p_head, pc->p_tail, p); | 676 | GNUNET_CONTAINER_DLL_remove (pc->p_head, |
670 | GNUNET_free(p); | 677 | pc->p_tail, |
678 | p); | ||
679 | GNUNET_free (p); | ||
671 | } | 680 | } |
672 | GNUNET_free(pc); | 681 | GNUNET_free (pc); |
673 | } | 682 | } |
674 | 683 | ||
675 | 684 | ||