aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-22 23:11:25 +0000
committerChristian Grothoff <christian@grothoff.org>2015-01-22 23:11:25 +0000
commit05cff1f88139935278c7954d6c09645ee54d6adb (patch)
tree0646284d56c5cffa0c1fcfba2bf7a88e8511f907 /src
parentbffe57690709d934d5b7b0013607d561628e3a25 (diff)
downloadgnunet-05cff1f88139935278c7954d6c09645ee54d6adb.tar.gz
gnunet-05cff1f88139935278c7954d6c09645ee54d6adb.zip
-use static where allowed
Diffstat (limited to 'src')
-rw-r--r--src/ats/gnunet-service-ats_normalization.c86
1 files changed, 56 insertions, 30 deletions
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c
index e93b878e7..b4051c9fa 100644
--- a/src/ats/gnunet-service-ats_normalization.c
+++ b/src/ats/gnunet-service-ats_normalization.c
@@ -145,7 +145,7 @@ struct Property
145 uint32_t max; 145 uint32_t max;
146}; 146};
147 147
148struct Property properties[GNUNET_ATS_QualityPropertiesCount]; 148static struct Property properties[GNUNET_ATS_QualityPropertiesCount];
149 149
150 150
151/** 151/**
@@ -161,12 +161,12 @@ static void *pref_changed_cb_cls;
161/** 161/**
162 * Callback to call on changing property values 162 * Callback to call on changing property values
163 */ 163 */
164GAS_Normalization_property_changed_cb prop_ch_cb; 164static GAS_Normalization_property_changed_cb prop_ch_cb;
165 165
166/** 166/**
167 * Closure for callback to call on changing property values 167 * Closure for callback to call on changing property values
168 */ 168 */
169void *prop_ch_cb_cls; 169static void *prop_ch_cb_cls;
170 170
171/** 171/**
172 * Hashmap to store peer information for preference normalization 172 * Hashmap to store peer information for preference normalization
@@ -196,9 +196,6 @@ static struct PeerRelative defvalues;
196 196
197static struct GNUNET_SCHEDULER_Task * aging_task; 197static struct GNUNET_SCHEDULER_Task * aging_task;
198 198
199/**
200 * Application Preference Normalization
201 */
202 199
203/** 200/**
204 * Update a peer 201 * Update a peer
@@ -265,6 +262,7 @@ update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id,
265 } 262 }
266} 263}
267 264
265
268/** 266/**
269 * Recalculate preference for a specific ATS property 267 * Recalculate preference for a specific ATS property
270 * 268 *
@@ -273,7 +271,8 @@ update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id,
273 * @return the result 271 * @return the result
274 */ 272 */
275static void 273static void
276recalculate_relative_preferences (struct PreferenceClient *c, enum GNUNET_ATS_PreferenceKind kind) 274recalculate_relative_preferences (struct PreferenceClient *c,
275 enum GNUNET_ATS_PreferenceKind kind)
277{ 276{
278 struct PreferencePeer *p_cur; 277 struct PreferencePeer *p_cur;
279 278
@@ -313,6 +312,7 @@ recalculate_relative_preferences (struct PreferenceClient *c, enum GNUNET_ATS_Pr
313 312
314} 313}
315 314
315
316/** 316/**
317 * Update the absolute preference value for a peer 317 * Update the absolute preference value for a peer
318 * @param c the client 318 * @param c the client
@@ -322,8 +322,10 @@ recalculate_relative_preferences (struct PreferenceClient *c, enum GNUNET_ATS_Pr
322 * @return the new relative preference value 322 * @return the new relative preference value
323 */ 323 */
324static void 324static void
325update_abs_preference (struct PreferenceClient *c, struct PreferencePeer *p, 325update_abs_preference (struct PreferenceClient *c,
326 enum GNUNET_ATS_PreferenceKind kind, float score_abs) 326 struct PreferencePeer *p,
327 enum GNUNET_ATS_PreferenceKind kind,
328 float score_abs)
327{ 329{
328 double score = score_abs; 330 double score = score_abs;
329 331
@@ -344,19 +346,27 @@ update_abs_preference (struct PreferenceClient *c, struct PreferencePeer *p,
344 } 346 }
345} 347}
346 348
347static int update_iterator (void *cls, 349
348 const struct GNUNET_PeerIdentity *key, 350static int
349 void *value) 351update_iterator (void *cls,
352 const struct GNUNET_PeerIdentity *key,
353 void *value)
350{ 354{
351 enum GNUNET_ATS_PreferenceKind *kind = cls; 355 enum GNUNET_ATS_PreferenceKind *kind = cls;
352 update_relative_values_for_peer (key, (*kind), (struct PeerRelative *) value); 356 struct PeerRelative *pr = value;
357
358 update_relative_values_for_peer (key,
359 (*kind),
360 pr);
353 return GNUNET_OK; 361 return GNUNET_OK;
354} 362}
355 363
364
356static void 365static void
357run_preference_update (struct PreferenceClient *c_cur, 366run_preference_update (struct PreferenceClient *c_cur,
358 struct PreferencePeer *p_cur,enum GNUNET_ATS_PreferenceKind kind, 367 struct PreferencePeer *p_cur,
359 float score_abs) 368 enum GNUNET_ATS_PreferenceKind kind,
369 float score_abs)
360{ 370{
361 double old_value; 371 double old_value;
362 372
@@ -370,6 +380,7 @@ run_preference_update (struct PreferenceClient *c_cur,
370 GNUNET_CONTAINER_multipeermap_iterate (preference_peers, &update_iterator, &kind); 380 GNUNET_CONTAINER_multipeermap_iterate (preference_peers, &update_iterator, &kind);
371} 381}
372 382
383
373/** 384/**
374 * Reduce absolute preferences since they got old 385 * Reduce absolute preferences since they got old
375 * 386 *
@@ -440,6 +451,7 @@ preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
440 451
441} 452}
442 453
454
443/** 455/**
444 * Normalize an updated preference value 456 * Normalize an updated preference value
445 * 457 *
@@ -450,9 +462,9 @@ preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
450 */ 462 */
451void 463void
452GAS_normalization_normalize_preference (void *client, 464GAS_normalization_normalize_preference (void *client,
453 const struct GNUNET_PeerIdentity *peer, 465 const struct GNUNET_PeerIdentity *peer,
454 enum GNUNET_ATS_PreferenceKind kind, 466 enum GNUNET_ATS_PreferenceKind kind,
455 float score_abs) 467 float score_abs)
456{ 468{
457 struct PreferenceClient *c_cur; 469 struct PreferenceClient *c_cur;
458 struct PreferencePeer *p_cur; 470 struct PreferencePeer *p_cur;
@@ -548,6 +560,7 @@ GAS_normalization_normalize_preference (void *client,
548 560
549} 561}
550 562
563
551/** 564/**
552 * Get the normalized preference values for a specific peer or 565 * Get the normalized preference values for a specific peer or
553 * the default values if 566 * the default values if
@@ -570,6 +583,7 @@ GAS_normalization_get_preferences_by_peer (const struct GNUNET_PeerIdentity *id)
570 return rp->f_rel; 583 return rp->f_rel;
571} 584}
572 585
586
573/** 587/**
574 * Get the normalized preference values for a specific client and peer 588 * Get the normalized preference values for a specific client and peer
575 * 589 *
@@ -606,6 +620,7 @@ GAS_normalization_get_preferences_by_client (const void *client,
606 return p_cur->f_rel[pref]; 620 return p_cur->f_rel[pref];
607} 621}
608 622
623
609/** 624/**
610 * Get the normalized properties values for a specific peer or 625 * Get the normalized properties values for a specific peer or
611 * the default values if 626 * the default values if
@@ -632,16 +647,16 @@ GAS_normalization_get_properties (const struct ATS_Address *address)
632 return norm_values; 647 return norm_values;
633} 648}
634 649
650
635/** 651/**
636 * Normalize a specific ATS type with the values in queue 652 * Normalize a specific ATS type with the values in queue
637 * @param address the address 653 * @param address the address
638 * @param atsi the ats information 654 * @param atsi the ats information
639 * @return the new average or GNUNET_ATS_VALUE_UNDEFINED 655 * @return the new average or GNUNET_ATS_VALUE_UNDEFINED
640 */ 656 */
641 657static uint32_t
642uint32_t
643property_average (struct ATS_Address *address, 658property_average (struct ATS_Address *address,
644 const struct GNUNET_ATS_Information *atsi) 659 const struct GNUNET_ATS_Information *atsi)
645{ 660{
646 struct GAS_NormalizationInfo *ni; 661 struct GAS_NormalizationInfo *ni;
647 uint32_t current_type; 662 uint32_t current_type;
@@ -701,6 +716,7 @@ property_average (struct ATS_Address *address,
701 return res; 716 return res;
702} 717}
703 718
719
704struct FindMinMaxCtx 720struct FindMinMaxCtx
705{ 721{
706 struct Property *p; 722 struct Property *p;
@@ -708,6 +724,7 @@ struct FindMinMaxCtx
708 uint32_t max; 724 uint32_t max;
709}; 725};
710 726
727
711static int 728static int
712find_min_max_it (void *cls, const struct GNUNET_PeerIdentity *h, void *k) 729find_min_max_it (void *cls, const struct GNUNET_PeerIdentity *h, void *k)
713{ 730{
@@ -723,6 +740,7 @@ find_min_max_it (void *cls, const struct GNUNET_PeerIdentity *h, void *k)
723 return GNUNET_OK; 740 return GNUNET_OK;
724} 741}
725 742
743
726static int 744static int
727normalize_address (void *cls, const struct GNUNET_PeerIdentity *h, void *k) 745normalize_address (void *cls, const struct GNUNET_PeerIdentity *h, void *k)
728{ 746{
@@ -758,6 +776,7 @@ normalize_address (void *cls, const struct GNUNET_PeerIdentity *h, void *k)
758 return GNUNET_OK; 776 return GNUNET_OK;
759} 777}
760 778
779
761/** 780/**
762 * Normalize avg_value to a range of values between [1.0, 2.0] 781 * Normalize avg_value to a range of values between [1.0, 2.0]
763 * based on min max values currently known. 782 * based on min max values currently known.
@@ -826,6 +845,7 @@ property_normalize (struct GNUNET_CONTAINER_MultiPeerMap *addresses,
826 } 845 }
827} 846}
828 847
848
829/** 849/**
830 * Update and normalize atsi performance information 850 * Update and normalize atsi performance information
831 * 851 *
@@ -835,10 +855,10 @@ property_normalize (struct GNUNET_CONTAINER_MultiPeerMap *addresses,
835 * @param atsi_count the number of atsi information in the array 855 * @param atsi_count the number of atsi information in the array
836 */ 856 */
837void 857void
838GAS_normalization_normalize_property ( 858GAS_normalization_normalize_property (struct GNUNET_CONTAINER_MultiPeerMap *addresses,
839 struct GNUNET_CONTAINER_MultiPeerMap *addresses, 859 struct ATS_Address *address,
840 struct ATS_Address *address, const struct GNUNET_ATS_Information *atsi, 860 const struct GNUNET_ATS_Information *atsi,
841 uint32_t atsi_count) 861 uint32_t atsi_count)
842{ 862{
843 struct Property *cur_prop; 863 struct Property *cur_prop;
844 int c1; 864 int c1;
@@ -847,11 +867,13 @@ GAS_normalization_normalize_property (
847 uint32_t current_val; 867 uint32_t current_val;
848 unsigned int existing_properties[] = GNUNET_ATS_QualityProperties; 868 unsigned int existing_properties[] = GNUNET_ATS_QualityProperties;
849 869
850 GNUNET_assert(NULL != address); 870 GNUNET_assert (NULL != address);
851 GNUNET_assert(NULL != atsi); 871 GNUNET_assert (NULL != atsi);
852 872
853 LOG(GNUNET_ERROR_TYPE_DEBUG, "Updating %u elements for peer `%s'\n", 873 LOG (GNUNET_ERROR_TYPE_DEBUG,
854 atsi_count, GNUNET_i2s (&address->peer)); 874 "Updating %u elements for peer `%s'\n",
875 atsi_count,
876 GNUNET_i2s (&address->peer));
855 877
856 for (c1 = 0; c1 < atsi_count; c1++) 878 for (c1 = 0; c1 < atsi_count; c1++)
857 { 879 {
@@ -883,6 +905,7 @@ GAS_normalization_normalize_property (
883 } 905 }
884} 906}
885 907
908
886static void 909static void
887free_client (struct PreferenceClient *pc) 910free_client (struct PreferenceClient *pc)
888{ 911{
@@ -898,12 +921,12 @@ free_client (struct PreferenceClient *pc)
898 GNUNET_free(pc); 921 GNUNET_free(pc);
899} 922}
900 923
924
901/** 925/**
902 * A performance client disconnected 926 * A performance client disconnected
903 * 927 *
904 * @param client the client 928 * @param client the client
905 */ 929 */
906
907void 930void
908GAS_normalization_preference_client_disconnect (void *client) 931GAS_normalization_preference_client_disconnect (void *client)
909{ 932{
@@ -922,6 +945,7 @@ GAS_normalization_preference_client_disconnect (void *client)
922 free_client (c_cur); 945 free_client (c_cur);
923} 946}
924 947
948
925/** 949/**
926 * Start the normalization component 950 * Start the normalization component
927 * 951 *
@@ -963,6 +987,7 @@ GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb,
963 return; 987 return;
964} 988}
965 989
990
966/** 991/**
967 * Free a peer 992 * Free a peer
968 * 993 *
@@ -983,6 +1008,7 @@ free_peer (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
983 return GNUNET_OK; 1008 return GNUNET_OK;
984} 1009}
985 1010
1011
986/** 1012/**
987 * Stop the normalization component and free all items 1013 * Stop the normalization component and free all items
988 */ 1014 */