aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_normalization.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats_normalization.c')
-rw-r--r--src/ats/gnunet-service-ats_normalization.c77
1 files changed, 44 insertions, 33 deletions
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c
index fabef09e4..bd9dcb706 100644
--- a/src/ats/gnunet-service-ats_normalization.c
+++ b/src/ats/gnunet-service-ats_normalization.c
@@ -149,12 +149,13 @@ void *prop_ch_cb_cls;
149/** 149/**
150 * Hashmap to store peer information for preference normalization 150 * Hashmap to store peer information for preference normalization
151 */ 151 */
152static struct GNUNET_CONTAINER_MultiHashMap *preference_peers; 152static struct GNUNET_CONTAINER_MultiPeerMap *preference_peers;
153 153
154/** 154/**
155 * Hashmap to store peer information for property normalization 155 * Hashmap to store peer information for property normalization
156 * FIXME: this map is not used!
156 */ 157 */
157static struct GNUNET_CONTAINER_MultiHashMap *property_peers; 158static struct GNUNET_CONTAINER_MultiPeerMap *property_peers;
158 159
159/** 160/**
160 * Clients in DLL: head 161 * Clients in DLL: head
@@ -220,8 +221,8 @@ update_peers (struct GNUNET_PeerIdentity *id,
220 count, GNUNET_i2s (id), GNUNET_ATS_print_preference_type (kind), 221 count, GNUNET_i2s (id), GNUNET_ATS_print_preference_type (kind),
221 f_rel_total); 222 f_rel_total);
222 if (NULL 223 if (NULL
223 != (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers, 224 != (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers,
224 &id->hashPubKey))) 225 id)))
225 { 226 {
226 backup = rp->f_rel[kind]; 227 backup = rp->f_rel[kind];
227 if (0 < count) 228 if (0 < count)
@@ -302,7 +303,7 @@ recalculate_rel_preferences (struct PreferenceClient *c,
302 { 303 {
303 /* Value did not chang, return old value*/ 304 /* Value did not chang, return old value*/
304 GNUNET_assert( 305 GNUNET_assert(
305 NULL != (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers, &p->id.hashPubKey))); 306 NULL != (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, &p->id)));
306 ret = rp->f_rel[kind]; 307 ret = rp->f_rel[kind];
307 } 308 }
308 } 309 }
@@ -474,14 +475,14 @@ GAS_normalization_normalize_preference (void *src,
474 GNUNET_CONTAINER_DLL_insert(c_cur->p_head, c_cur->p_tail, p_cur); 475 GNUNET_CONTAINER_DLL_insert(c_cur->p_head, c_cur->p_tail, p_cur);
475 } 476 }
476 477
477 if (NULL == GNUNET_CONTAINER_multihashmap_get (preference_peers, 478 if (NULL == GNUNET_CONTAINER_multipeermap_get (preference_peers,
478 &peer->hashPubKey)) 479 peer))
479 { 480 {
480 r_cur = GNUNET_malloc (sizeof (struct PeerRelative)); 481 r_cur = GNUNET_malloc (sizeof (struct PeerRelative));
481 r_cur->id = (*peer); 482 r_cur->id = (*peer);
482 for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) 483 for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
483 r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; 484 r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
484 GNUNET_CONTAINER_multihashmap_put (preference_peers, &r_cur->id.hashPubKey, 485 GNUNET_CONTAINER_multipeermap_put (preference_peers, &r_cur->id,
485 r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 486 r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
486 } 487 }
487 488
@@ -508,8 +509,8 @@ GAS_normalization_get_preferences (const struct GNUNET_PeerIdentity *id)
508 509
509 struct PeerRelative *rp; 510 struct PeerRelative *rp;
510 if (NULL 511 if (NULL
511 == (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers, 512 == (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers,
512 &id->hashPubKey))) 513 id)))
513 { 514 {
514 return defvalues.f_rel; 515 return defvalues.f_rel;
515 } 516 }
@@ -625,6 +626,7 @@ property_average (struct ATS_Address *address,
625 return res; 626 return res;
626} 627}
627 628
629
628struct FindMinMaxCtx 630struct FindMinMaxCtx
629{ 631{
630 struct Property *p; 632 struct Property *p;
@@ -632,11 +634,14 @@ struct FindMinMaxCtx
632 uint32_t max; 634 uint32_t max;
633}; 635};
634 636
637
635static int 638static int
636find_min_max_it (void *cls, const struct GNUNET_HashCode *h, void *k) 639find_min_max_it (void *cls,
640 const struct GNUNET_PeerIdentity *h,
641 void *k)
637{ 642{
638 struct ATS_Address *a = (struct ATS_Address *) k;
639 struct FindMinMaxCtx *find_res = cls; 643 struct FindMinMaxCtx *find_res = cls;
644 struct ATS_Address *a = k;
640 645
641 if (a->atsin[find_res->p->prop_type].avg > find_res->max) 646 if (a->atsin[find_res->p->prop_type].avg > find_res->max)
642 find_res->max = a->atsin[find_res->p->prop_type].avg; 647 find_res->max = a->atsin[find_res->p->prop_type].avg;
@@ -647,11 +652,14 @@ find_min_max_it (void *cls, const struct GNUNET_HashCode *h, void *k)
647 return GNUNET_OK; 652 return GNUNET_OK;
648} 653}
649 654
655
650static int 656static int
651normalize_address (void *cls, const struct GNUNET_HashCode *h, void *k) 657normalize_address (void *cls,
658 const struct GNUNET_PeerIdentity *h,
659 void *k)
652{ 660{
653 struct Property *p = cls; 661 struct Property *p = cls;
654 struct ATS_Address *address = (struct ATS_Address *) k; 662 struct ATS_Address *address = k;
655 663
656 double delta; 664 double delta;
657 uint32_t avg_value = address->atsin[p->prop_type].avg; 665 uint32_t avg_value = address->atsin[p->prop_type].avg;
@@ -673,6 +681,7 @@ normalize_address (void *cls, const struct GNUNET_HashCode *h, void *k)
673 return GNUNET_OK; 681 return GNUNET_OK;
674} 682}
675 683
684
676/** 685/**
677 * Normalize avg_value to a range of values between [1.0, 2.0] 686 * Normalize avg_value to a range of values between [1.0, 2.0]
678 * based on min max values currently known. 687 * based on min max values currently known.
@@ -682,10 +691,11 @@ normalize_address (void *cls, const struct GNUNET_HashCode *h, void *k)
682 * @param address the address 691 * @param address the address
683 * @param avg_value the value to normalize 692 * @param avg_value the value to normalize
684 */ 693 */
685
686static void 694static void
687property_normalize (struct GNUNET_CONTAINER_MultiHashMap *addresses, 695property_normalize (struct GNUNET_CONTAINER_MultiPeerMap *addresses,
688 struct Property *p, struct ATS_Address *address, uint32_t avg_value) 696 struct Property *p,
697 struct ATS_Address *address,
698 uint32_t avg_value)
689{ 699{
690 struct FindMinMaxCtx find_ctx; 700 struct FindMinMaxCtx find_ctx;
691 int addr_count; 701 int addr_count;
@@ -694,8 +704,8 @@ property_normalize (struct GNUNET_CONTAINER_MultiHashMap *addresses,
694 find_ctx.p = p; 704 find_ctx.p = p;
695 find_ctx.max = 0; 705 find_ctx.max = 0;
696 find_ctx.min = UINT32_MAX; 706 find_ctx.min = UINT32_MAX;
697 addr_count = GNUNET_CONTAINER_multihashmap_iterate (addresses, 707 addr_count = GNUNET_CONTAINER_multipeermap_iterate (addresses,
698 &find_min_max_it, &find_ctx); 708 &find_min_max_it, &find_ctx);
699 if (0 == addr_count) 709 if (0 == addr_count)
700 { 710 {
701 GNUNET_break(0); 711 GNUNET_break(0);
@@ -731,13 +741,13 @@ property_normalize (struct GNUNET_CONTAINER_MultiHashMap *addresses,
731 if (GNUNET_NO == limits_changed) 741 if (GNUNET_NO == limits_changed)
732 { 742 {
733 /* normalize just this address */ 743 /* normalize just this address */
734 normalize_address (p, &address->peer.hashPubKey, address); 744 normalize_address (p, &address->peer, address);
735 return; 745 return;
736 } 746 }
737 else 747 else
738 { 748 {
739 /* limits changed, normalize all addresses */ 749 /* limits changed, normalize all addresses */
740 GNUNET_CONTAINER_multihashmap_iterate (addresses, &normalize_address, p); 750 GNUNET_CONTAINER_multipeermap_iterate (addresses, &normalize_address, p);
741 return; 751 return;
742 } 752 }
743} 753}
@@ -751,10 +761,10 @@ property_normalize (struct GNUNET_CONTAINER_MultiHashMap *addresses,
751 * @param atsi_count the number of atsi information in the array 761 * @param atsi_count the number of atsi information in the array
752 */ 762 */
753void 763void
754GAS_normalization_normalize_property ( 764GAS_normalization_normalize_property (struct GNUNET_CONTAINER_MultiPeerMap *addresses,
755 struct GNUNET_CONTAINER_MultiHashMap *addresses, 765 struct ATS_Address *address,
756 struct ATS_Address *address, const struct GNUNET_ATS_Information *atsi, 766 const struct GNUNET_ATS_Information *atsi,
757 uint32_t atsi_count) 767 uint32_t atsi_count)
758{ 768{
759 struct Property *cur_prop; 769 struct Property *cur_prop;
760 int c1; 770 int c1;
@@ -814,8 +824,8 @@ GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb,
814{ 824{
815 int c1; 825 int c1;
816 int i; 826 int i;
817 preference_peers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); 827 preference_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
818 property_peers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); 828 property_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
819 unsigned int existing_properties[] = GNUNET_ATS_QualityProperties; 829 unsigned int existing_properties[] = GNUNET_ATS_QualityProperties;
820 830
821 for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) 831 for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
@@ -840,20 +850,21 @@ GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb,
840 return; 850 return;
841} 851}
842 852
853
843/** 854/**
844 * Free a peer 855 * Free a peer
845 * 856 *
846 * @param cls unused 857 * @param cls unused
847 * @param key the key 858 * @param key the key
848 * @param value RelativePeer 859 * @param value RelativePeer
849 * @return GNUNET_OK to continue 860 * @return #GNUNET_OK to continue
850 */ 861 */
851static int 862static int
852free_peer (void *cls, const struct GNUNET_HashCode * key, void *value) 863free_peer (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
853{ 864{
854 struct PeerRelative *rp = value; 865 struct PeerRelative *rp = value;
855 if (GNUNET_YES 866 if (GNUNET_YES
856 == GNUNET_CONTAINER_multihashmap_remove (preference_peers, key, value)) 867 == GNUNET_CONTAINER_multipeermap_remove (preference_peers, key, value))
857 GNUNET_free(rp); 868 GNUNET_free(rp);
858 else 869 else
859 GNUNET_break(0); 870 GNUNET_break(0);
@@ -892,9 +903,9 @@ GAS_normalization_stop ()
892 GNUNET_free(pc); 903 GNUNET_free(pc);
893 } 904 }
894 905
895 GNUNET_CONTAINER_multihashmap_iterate (preference_peers, &free_peer, NULL ); 906 GNUNET_CONTAINER_multipeermap_iterate (preference_peers, &free_peer, NULL );
896 GNUNET_CONTAINER_multihashmap_destroy (preference_peers); 907 GNUNET_CONTAINER_multipeermap_destroy (preference_peers);
897 GNUNET_CONTAINER_multihashmap_destroy (property_peers); 908 GNUNET_CONTAINER_multipeermap_destroy (property_peers);
898 return; 909 return;
899} 910}
900 911