diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-05 20:15:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-05 20:15:02 +0000 |
commit | d4cb0035c1248e050d906e9018d36a9f5d19eb73 (patch) | |
tree | 61992da6bc1c7b769f4db7dde10feace04486a89 /src/ats/gnunet-service-ats_preferences.c | |
parent | 04c43865242385b22cb8a399843680542009031a (diff) | |
download | gnunet-d4cb0035c1248e050d906e9018d36a9f5d19eb73.tar.gz gnunet-d4cb0035c1248e050d906e9018d36a9f5d19eb73.zip |
starting with cleaning up gnunet-service-ats_preferences.c
Diffstat (limited to 'src/ats/gnunet-service-ats_preferences.c')
-rw-r--r-- | src/ats/gnunet-service-ats_preferences.c | 80 |
1 files changed, 52 insertions, 28 deletions
diff --git a/src/ats/gnunet-service-ats_preferences.c b/src/ats/gnunet-service-ats_preferences.c index 762caf8ea..cbb1eba08 100644 --- a/src/ats/gnunet-service-ats_preferences.c +++ b/src/ats/gnunet-service-ats_preferences.c | |||
@@ -34,10 +34,19 @@ | |||
34 | 34 | ||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-preferencesx",__VA_ARGS__) | 35 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-preferencesx",__VA_ARGS__) |
36 | 36 | ||
37 | /** | ||
38 | * | ||
39 | */ | ||
37 | #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) |
38 | 41 | ||
42 | /** | ||
43 | * | ||
44 | */ | ||
39 | #define PREF_AGING_FACTOR 0.95 | 45 | #define PREF_AGING_FACTOR 0.95 |
40 | 46 | ||
47 | /** | ||
48 | * | ||
49 | */ | ||
41 | #define PREF_EPSILON 0.01 | 50 | #define PREF_EPSILON 0.01 |
42 | 51 | ||
43 | 52 | ||
@@ -205,7 +214,6 @@ update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id, | |||
205 | peer_count ++; | 214 | peer_count ++; |
206 | f_rel_total += p_cur->f_rel[kind]; | 215 | f_rel_total += p_cur->f_rel[kind]; |
207 | } | 216 | } |
208 | |||
209 | } | 217 | } |
210 | } | 218 | } |
211 | 219 | ||
@@ -230,7 +238,8 @@ update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id, | |||
230 | rp->f_rel[kind] = DEFAULT_REL_PREFERENCE; | 238 | rp->f_rel[kind] = DEFAULT_REL_PREFERENCE; |
231 | } | 239 | } |
232 | if (backup != rp->f_rel[kind]) | 240 | if (backup != rp->f_rel[kind]) |
233 | GAS_normalized_preference_changed (&rp->id, kind, rp->f_rel[kind]); | 241 | GAS_normalized_preference_changed (&rp->id, kind, |
242 | rp->f_rel[kind]); | ||
234 | } | 243 | } |
235 | } | 244 | } |
236 | 245 | ||
@@ -436,7 +445,6 @@ update_abs_preference (struct PreferenceClient *c, | |||
436 | } | 445 | } |
437 | 446 | ||
438 | 447 | ||
439 | |||
440 | /** | 448 | /** |
441 | * Change the preference for a peer | 449 | * Change the preference for a peer |
442 | * | 450 | * |
@@ -447,9 +455,9 @@ update_abs_preference (struct PreferenceClient *c, | |||
447 | */ | 455 | */ |
448 | static void | 456 | static void |
449 | preference_change (struct GNUNET_SERVER_Client *client, | 457 | preference_change (struct GNUNET_SERVER_Client *client, |
450 | const struct GNUNET_PeerIdentity *peer, | 458 | const struct GNUNET_PeerIdentity *peer, |
451 | enum GNUNET_ATS_PreferenceKind kind, | 459 | enum GNUNET_ATS_PreferenceKind kind, |
452 | float score_abs) | 460 | float score_abs) |
453 | { | 461 | { |
454 | if (GNUNET_NO == | 462 | if (GNUNET_NO == |
455 | GNUNET_CONTAINER_multipeermap_contains (GSA_addresses, | 463 | GNUNET_CONTAINER_multipeermap_contains (GSA_addresses, |
@@ -597,7 +605,9 @@ GAS_preference_done () | |||
597 | while (NULL != (pc = next_pc)) | 605 | while (NULL != (pc = next_pc)) |
598 | { | 606 | { |
599 | next_pc = pc->next; | 607 | next_pc = pc->next; |
600 | GNUNET_CONTAINER_DLL_remove(pc_head, pc_tail, pc); | 608 | GNUNET_CONTAINER_DLL_remove (pc_head, |
609 | pc_tail, | ||
610 | pc); | ||
601 | free_client (pc); | 611 | free_client (pc); |
602 | } | 612 | } |
603 | GNUNET_CONTAINER_multipeermap_iterate (preference_peers, | 613 | GNUNET_CONTAINER_multipeermap_iterate (preference_peers, |
@@ -642,10 +652,8 @@ GAS_normalization_normalize_preference (struct GNUNET_SERVER_Client *client, | |||
642 | 652 | ||
643 | /* Find preference client */ | 653 | /* Find preference client */ |
644 | for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) | 654 | for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) |
645 | { | ||
646 | if (client == c_cur->client) | 655 | if (client == c_cur->client) |
647 | break; | 656 | break; |
648 | } | ||
649 | /* Not found: create new preference client */ | 657 | /* Not found: create new preference client */ |
650 | if (NULL == c_cur) | 658 | if (NULL == c_cur) |
651 | { | 659 | { |
@@ -657,13 +665,19 @@ GAS_normalization_normalize_preference (struct GNUNET_SERVER_Client *client, | |||
657 | c_cur->f_rel_sum[i] = DEFAULT_REL_PREFERENCE; | 665 | c_cur->f_rel_sum[i] = DEFAULT_REL_PREFERENCE; |
658 | } | 666 | } |
659 | 667 | ||
660 | GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, c_cur); | 668 | GNUNET_CONTAINER_DLL_insert (pc_head, |
661 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding new client %p \n", c_cur); | 669 | pc_tail, |
670 | c_cur); | ||
671 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
672 | "Adding new client %p\n", | ||
673 | c_cur); | ||
662 | } | 674 | } |
663 | 675 | ||
664 | /* Find entry for peer */ | 676 | /* Find entry for peer */ |
665 | for (p_cur = c_cur->p_head; NULL != p_cur; p_cur = p_cur->next) | 677 | for (p_cur = c_cur->p_head; NULL != p_cur; p_cur = p_cur->next) |
666 | if (0 == memcmp (&p_cur->id, peer, sizeof(p_cur->id))) | 678 | if (0 == memcmp (&p_cur->id, |
679 | peer, | ||
680 | sizeof (p_cur->id))) | ||
667 | break; | 681 | break; |
668 | 682 | ||
669 | /* Not found: create new peer entry */ | 683 | /* Not found: create new peer entry */ |
@@ -680,21 +694,29 @@ GAS_normalization_normalize_preference (struct GNUNET_SERVER_Client *client, | |||
680 | p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; | 694 | p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; |
681 | p_cur->next_aging[i] = GNUNET_TIME_UNIT_FOREVER_ABS; | 695 | p_cur->next_aging[i] = GNUNET_TIME_UNIT_FOREVER_ABS; |
682 | } | 696 | } |
683 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding new peer %p for client %p \n", | 697 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
684 | p_cur, c_cur); | 698 | "Adding new peer %p for client %p\n", |
685 | GNUNET_CONTAINER_DLL_insert(c_cur->p_head, c_cur->p_tail, p_cur); | 699 | p_cur, |
700 | c_cur); | ||
701 | GNUNET_CONTAINER_DLL_insert (c_cur->p_head, | ||
702 | c_cur->p_tail, | ||
703 | p_cur); | ||
686 | } | 704 | } |
687 | 705 | ||
688 | /* Create struct for peer */ | 706 | /* Create struct for peer */ |
689 | if (NULL == GNUNET_CONTAINER_multipeermap_get (preference_peers, peer)) | 707 | if (NULL == |
708 | GNUNET_CONTAINER_multipeermap_get (preference_peers, | ||
709 | peer)) | ||
690 | { | 710 | { |
691 | r_cur = GNUNET_new (struct PeerRelative); | 711 | r_cur = GNUNET_new (struct PeerRelative); |
692 | r_cur->id = (*peer); | 712 | r_cur->id = *peer; |
693 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 713 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) |
694 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; | 714 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; |
695 | GNUNET_assert( | 715 | GNUNET_assert(GNUNET_OK == |
696 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (preference_peers, | 716 | GNUNET_CONTAINER_multipeermap_put (preference_peers, |
697 | &r_cur->id, r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 717 | &r_cur->id, |
718 | r_cur, | ||
719 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
698 | } | 720 | } |
699 | 721 | ||
700 | /* Update absolute value */ | 722 | /* Update absolute value */ |
@@ -703,14 +725,15 @@ GAS_normalization_normalize_preference (struct GNUNET_SERVER_Client *client, | |||
703 | if (p_cur->f_abs[kind] == old_value) | 725 | if (p_cur->f_abs[kind] == old_value) |
704 | return; | 726 | return; |
705 | 727 | ||
706 | run_preference_update (c_cur, p_cur, kind, score_abs); | 728 | run_preference_update (c_cur, |
729 | p_cur, | ||
730 | kind, | ||
731 | score_abs); | ||
707 | 732 | ||
708 | /* Start aging task */ | ||
709 | if (NULL == aging_task) | 733 | if (NULL == aging_task) |
710 | aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, | 734 | aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, |
711 | &preference_aging, | 735 | &preference_aging, |
712 | NULL); | 736 | NULL); |
713 | |||
714 | } | 737 | } |
715 | 738 | ||
716 | 739 | ||
@@ -748,16 +771,17 @@ void | |||
748 | GAS_normalization_preference_client_disconnect (struct GNUNET_SERVER_Client *client) | 771 | GAS_normalization_preference_client_disconnect (struct GNUNET_SERVER_Client *client) |
749 | { | 772 | { |
750 | struct PreferenceClient *c_cur; | 773 | struct PreferenceClient *c_cur; |
751 | /* Find preference client */ | ||
752 | 774 | ||
753 | for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) | 775 | for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) |
754 | { | ||
755 | if (client == c_cur->client) | 776 | if (client == c_cur->client) |
756 | break; | 777 | break; |
757 | } | ||
758 | if (NULL == c_cur) | 778 | if (NULL == c_cur) |
759 | return; | 779 | return; |
760 | 780 | GNUNET_CONTAINER_DLL_remove (pc_head, | |
761 | GNUNET_CONTAINER_DLL_remove(pc_head, pc_tail, c_cur); | 781 | pc_tail, |
782 | c_cur); | ||
762 | free_client (c_cur); | 783 | free_client (c_cur); |
763 | } | 784 | } |
785 | |||
786 | |||
787 | /* end of gnunet-service-ats_preferences.c */ | ||