aboutsummaryrefslogtreecommitdiff
path: root/src/ats/plugin_ats_proportional.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-05 21:41:58 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-05 21:41:58 +0000
commitb8d5c4c9220576e85b4eec4c7ffa0390ba887fb5 (patch)
treef93ff7c7d94c81f5182e1c4bc7fd829f4fc9a609 /src/ats/plugin_ats_proportional.c
parentd4cb0035c1248e050d906e9018d36a9f5d19eb73 (diff)
downloadgnunet-b8d5c4c9220576e85b4eec4c7ffa0390ba887fb5.tar.gz
gnunet-b8d5c4c9220576e85b4eec4c7ffa0390ba887fb5.zip
first pass at cleaning up ATS plugin API
Diffstat (limited to 'src/ats/plugin_ats_proportional.c')
-rw-r--r--src/ats/plugin_ats_proportional.c139
1 files changed, 57 insertions, 82 deletions
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c
index cc5a55ebb..a154ceff3 100644
--- a/src/ats/plugin_ats_proportional.c
+++ b/src/ats/plugin_ats_proportional.c
@@ -217,12 +217,11 @@
217 */ 217 */
218struct GAS_PROPORTIONAL_Handle 218struct GAS_PROPORTIONAL_Handle
219{ 219{
220 struct GNUNET_ATS_PluginEnvironment *env;
221 220
222 /** 221 /**
223 * Statistics handle 222 * Our execution environment.
224 */ 223 */
225 struct GNUNET_STATISTICS_Handle *stats; 224 struct GNUNET_ATS_PluginEnvironment *env;
226 225
227 /** 226 /**
228 * Hashmap containing all valid addresses 227 * Hashmap containing all valid addresses
@@ -235,36 +234,6 @@ struct GAS_PROPORTIONAL_Handle
235 struct GNUNET_CONTAINER_MultiPeerMap *requests; 234 struct GNUNET_CONTAINER_MultiPeerMap *requests;
236 235
237 /** 236 /**
238 * Bandwidth changed callback
239 */
240 GAS_bandwidth_changed_cb bw_changed;
241
242 /**
243 * Bandwidth changed callback cls
244 */
245 void *bw_changed_cls;
246
247 /**
248 * ATS function to get preferences
249 */
250 GAS_get_preferences get_preferences;
251
252 /**
253 * Closure for ATS function to get preferences
254 */
255 void *get_preferences_cls;
256
257 /**
258 * ATS function to get properties
259 */
260 GAS_get_properties get_properties;
261
262 /**
263 * Closure for ATS function to get properties
264 */
265 void *get_properties_cls;
266
267 /**
268 * Bulk lock 237 * Bulk lock
269 */ 238 */
270 int bulk_lock; 239 int bulk_lock;
@@ -418,7 +387,8 @@ struct AddressWrapper
418void * 387void *
419libgnunet_plugin_ats_proportional_done (void *cls) 388libgnunet_plugin_ats_proportional_done (void *cls)
420{ 389{
421 struct GAS_PROPORTIONAL_Handle *s = cls; 390 struct GNUNET_ATS_SolverFunctions *sf = cls;
391 struct GAS_PROPORTIONAL_Handle *s = sf->cls;
422 struct AddressWrapper *cur; 392 struct AddressWrapper *cur;
423 struct AddressWrapper *next; 393 struct AddressWrapper *next;
424 int c; 394 int c;
@@ -572,8 +542,8 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
572 if (GNUNET_YES != cur_address->addr->active) 542 if (GNUNET_YES != cur_address->addr->active)
573 continue; 543 continue;
574 544
575 GNUNET_assert( NULL != (peer_relative_prefs = s->get_preferences (s->get_preferences_cls, 545 GNUNET_assert( NULL != (peer_relative_prefs = s->env->get_preferences (s->env->cls,
576 &cur_address->addr->peer))); 546 &cur_address->addr->peer)));
577 relative_peer_prefence = 0.0; 547 relative_peer_prefence = 0.0;
578 relative_peer_prefence += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; 548 relative_peer_prefence += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
579 sum_relative_peer_prefences += relative_peer_prefence; 549 sum_relative_peer_prefences += relative_peer_prefence;
@@ -608,7 +578,8 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
608 if (GNUNET_YES == cur_address->addr->active) 578 if (GNUNET_YES == cur_address->addr->active)
609 { 579 {
610 GNUNET_assert( NULL != (peer_relative_prefs = 580 GNUNET_assert( NULL != (peer_relative_prefs =
611 s->get_preferences (s->get_preferences_cls, &cur_address->addr->peer))); 581 s->env->get_preferences (s->env->cls,
582 &cur_address->addr->peer)));
612 583
613 cur_pref = peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; 584 cur_pref = peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
614 total_weight = net->active_addresses + 585 total_weight = net->active_addresses +
@@ -767,15 +738,15 @@ find_best_address_it (void *cls,
767 } 738 }
768 739
769 /* Now compare ATS information */ 740 /* Now compare ATS information */
770 norm_prop_cur = ctx->s->get_properties (ctx->s->get_properties_cls, 741 norm_prop_cur = ctx->s->env->get_property (ctx->s->env->cls,
771 (const struct ATS_Address *) current); 742 current);
772 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE); 743 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
773 cur_distance = norm_prop_cur[index]; 744 cur_distance = norm_prop_cur[index];
774 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY); 745 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
775 cur_delay = norm_prop_cur[index]; 746 cur_delay = norm_prop_cur[index];
776 747
777 norm_prop_best = ctx->s->get_properties (ctx->s->get_properties_cls, 748 norm_prop_best = ctx->s->env->get_property (ctx->s->env->cls,
778 (const struct ATS_Address *) ctx->best); 749 ctx->best);
779 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE); 750 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
780 best_distance = norm_prop_best[index]; 751 best_distance = norm_prop_best[index];
781 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY); 752 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
@@ -951,16 +922,20 @@ address_increment (struct GAS_PROPORTIONAL_Handle *s,
951 { 922 {
952 s->total_addresses++; 923 s->total_addresses++;
953 net->total_addresses++; 924 net->total_addresses++;
954 GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", 1, GNUNET_NO); 925 GNUNET_STATISTICS_update (s->env->stats,
955 GNUNET_STATISTICS_update (s->stats, net->stat_total, 1, GNUNET_NO); 926 "# ATS addresses total", 1, GNUNET_NO);
927 GNUNET_STATISTICS_update (s->env->stats,
928 net->stat_total, 1, GNUNET_NO);
956 } 929 }
957 if (GNUNET_YES == active) 930 if (GNUNET_YES == active)
958 { 931 {
959 net->active_addresses++; 932 net->active_addresses++;
960 s->active_addresses++; 933 s->active_addresses++;
961 GNUNET_STATISTICS_update (s->stats, "# ATS active addresses total", 1, 934 GNUNET_STATISTICS_update (s->env->stats,
935 "# ATS active addresses total", 1,
962 GNUNET_NO); 936 GNUNET_NO);
963 GNUNET_STATISTICS_update (s->stats, net->stat_active, 1, GNUNET_NO); 937 GNUNET_STATISTICS_update (s->env->stats,
938 net->stat_active, 1, GNUNET_NO);
964 } 939 }
965 940
966} 941}
@@ -992,7 +967,8 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
992 else 967 else
993 { 968 {
994 s->total_addresses--; 969 s->total_addresses--;
995 GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", -1, 970 GNUNET_STATISTICS_update (s->env->stats,
971 "# ATS addresses total", -1,
996 GNUNET_NO); 972 GNUNET_NO);
997 } 973 }
998 if (net->total_addresses < 1) 974 if (net->total_addresses < 1)
@@ -1003,7 +979,8 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
1003 else 979 else
1004 { 980 {
1005 net->total_addresses--; 981 net->total_addresses--;
1006 GNUNET_STATISTICS_update (s->stats, net->stat_total, -1, GNUNET_NO); 982 GNUNET_STATISTICS_update (s->env->stats,
983 net->stat_total, -1, GNUNET_NO);
1007 } 984 }
1008 } 985 }
1009 986
@@ -1017,7 +994,8 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
1017 else 994 else
1018 { 995 {
1019 net->active_addresses--; 996 net->active_addresses--;
1020 GNUNET_STATISTICS_update (s->stats, net->stat_active, -1, GNUNET_NO); 997 GNUNET_STATISTICS_update (s->env->stats,
998 net->stat_active, -1, GNUNET_NO);
1021 } 999 }
1022 if (s->active_addresses < 1) 1000 if (s->active_addresses < 1)
1023 { 1001 {
@@ -1027,7 +1005,8 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
1027 else 1005 else
1028 { 1006 {
1029 s->active_addresses--; 1007 s->active_addresses--;
1030 GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", -1, 1008 GNUNET_STATISTICS_update (s->env->stats,
1009 "# ATS addresses total", -1,
1031 GNUNET_NO); 1010 GNUNET_NO);
1032 } 1011 }
1033 } 1012 }
@@ -1071,6 +1050,7 @@ propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
1071{ 1050{
1072 struct AddressWrapper *cur; 1051 struct AddressWrapper *cur;
1073 struct AddressSolverInformation *asi; 1052 struct AddressSolverInformation *asi;
1053
1074 for (cur = net->head; NULL != cur; cur = cur->next) 1054 for (cur = net->head; NULL != cur; cur = cur->next)
1075 { 1055 {
1076 asi = cur->addr->solver_information; 1056 asi = cur->addr->solver_information;
@@ -1094,7 +1074,8 @@ propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
1094 /* Notify on change */ 1074 /* Notify on change */
1095 if ((GNUNET_YES == cur->addr->active)) 1075 if ((GNUNET_YES == cur->addr->active))
1096 { 1076 {
1097 s->bw_changed (s->bw_changed_cls, cur->addr); 1077 s->env->bandwidth_changed_cb (s->env->cls,
1078 cur->addr);
1098 } 1079 }
1099 } 1080 }
1100 } 1081 }
@@ -1125,31 +1106,31 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
1125 n->active_addresses, n->total_addresses); 1106 n->active_addresses, n->total_addresses);
1126 1107
1127 if (NULL != s->env->info_cb) 1108 if (NULL != s->env->info_cb)
1128 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START, 1109 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_START,
1129 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); 1110 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
1130 1111
1131 /* Distribute */ 1112 /* Distribute */
1132 distribute_bandwidth(s, n); 1113 distribute_bandwidth(s, n);
1133 1114
1134 if (NULL != s->env->info_cb) 1115 if (NULL != s->env->info_cb)
1135 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP, 1116 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_STOP,
1136 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); 1117 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
1137 if (NULL != s->env->info_cb) 1118 if (NULL != s->env->info_cb)
1138 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, 1119 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
1139 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); 1120 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
1140 1121
1141 /* Do propagation */ 1122 /* Do propagation */
1142 propagate_bandwidth (s, n); 1123 propagate_bandwidth (s, n);
1143 1124
1144 if (NULL != s->env->info_cb) 1125 if (NULL != s->env->info_cb)
1145 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, 1126 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
1146 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); 1127 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
1147 } 1128 }
1148 else 1129 else
1149 { 1130 {
1150 int i; 1131 int i;
1151 if (NULL != s->env->info_cb) 1132 if (NULL != s->env->info_cb)
1152 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START, 1133 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_START,
1153 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); 1134 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
1154 for (i = 0; i < s->network_count; i++) 1135 for (i = 0; i < s->network_count; i++)
1155 { 1136 {
@@ -1158,10 +1139,10 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
1158 } 1139 }
1159 1140
1160 if (NULL != s->env->info_cb) 1141 if (NULL != s->env->info_cb)
1161 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP, 1142 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_STOP,
1162 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); 1143 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
1163 if (NULL != s->env->info_cb) 1144 if (NULL != s->env->info_cb)
1164 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, 1145 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
1165 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); 1146 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
1166 for (i = 0; i < s->network_count; i++) 1147 for (i = 0; i < s->network_count; i++)
1167 { 1148 {
@@ -1169,7 +1150,7 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
1169 propagate_bandwidth(s, &s->network_entries[i]); 1150 propagate_bandwidth(s, &s->network_entries[i]);
1170 } 1151 }
1171 if (NULL != s->env->info_cb) 1152 if (NULL != s->env->info_cb)
1172 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, 1153 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
1173 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); 1154 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
1174 } 1155 }
1175} 1156}
@@ -1254,8 +1235,8 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
1254 "Disconnecting peer `%s' with previous address %p\n", 1235 "Disconnecting peer `%s' with previous address %p\n",
1255 GNUNET_i2s (peer), 1236 GNUNET_i2s (peer),
1256 current_address); 1237 current_address);
1257 s->bw_changed (s->bw_changed_cls, 1238 s->env->bandwidth_changed_cb (s->env->cls,
1258 current_address); 1239 current_address);
1259 } 1240 }
1260 } 1241 }
1261 if (NULL == best_address) 1242 if (NULL == best_address)
@@ -1347,7 +1328,7 @@ GAS_proportional_address_change_preference (void *solver,
1347 */ 1328 */
1348static void 1329static void
1349GAS_proportional_address_preference_feedback (void *solver, 1330GAS_proportional_address_preference_feedback (void *solver,
1350 void *application, 1331 struct GNUNET_SERVER_Client *application,
1351 const struct GNUNET_PeerIdentity *peer, 1332 const struct GNUNET_PeerIdentity *peer,
1352 const struct GNUNET_TIME_Relative scope, 1333 const struct GNUNET_TIME_Relative scope,
1353 enum GNUNET_ATS_PreferenceKind kind, 1334 enum GNUNET_ATS_PreferenceKind kind,
@@ -1547,8 +1528,8 @@ GAS_proportional_address_delete (void *solver,
1547 "Disconnecting peer `%s' after deleting previous address %p\n", 1528 "Disconnecting peer `%s' after deleting previous address %p\n",
1548 GNUNET_i2s (&address->peer), 1529 GNUNET_i2s (&address->peer),
1549 address); 1530 address);
1550 s->bw_changed (s->bw_changed_cls, 1531 s->env->bandwidth_changed_cb (s->env->cls,
1551 address); 1532 address);
1552 } 1533 }
1553 } 1534 }
1554 if (GNUNET_NO == session_only) 1535 if (GNUNET_NO == session_only)
@@ -1746,6 +1727,7 @@ GAS_proportional_address_add (void *solver,
1746void * 1727void *
1747libgnunet_plugin_ats_proportional_init (void *cls) 1728libgnunet_plugin_ats_proportional_init (void *cls)
1748{ 1729{
1730 static struct GNUNET_ATS_SolverFunctions sf;
1749 struct GNUNET_ATS_PluginEnvironment *env = cls; 1731 struct GNUNET_ATS_PluginEnvironment *env = cls;
1750 struct GAS_PROPORTIONAL_Handle *s; 1732 struct GAS_PROPORTIONAL_Handle *s;
1751 struct Network * cur; 1733 struct Network * cur;
@@ -1760,24 +1742,17 @@ libgnunet_plugin_ats_proportional_init (void *cls)
1760 1742
1761 s = GNUNET_new (struct GAS_PROPORTIONAL_Handle); 1743 s = GNUNET_new (struct GAS_PROPORTIONAL_Handle);
1762 s->env = env; 1744 s->env = env;
1763 env->sf.s_add = &GAS_proportional_address_add; 1745 sf.cls = s;
1764 env->sf.s_address_update_property = &GAS_proportional_address_property_changed; 1746 sf.s_add = &GAS_proportional_address_add;
1765 env->sf.s_get = &GAS_proportional_get_preferred_address; 1747 sf.s_address_update_property = &GAS_proportional_address_property_changed;
1766 env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address; 1748 sf.s_get = &GAS_proportional_get_preferred_address;
1767 env->sf.s_pref = &GAS_proportional_address_change_preference; 1749 sf.s_get_stop = &GAS_proportional_stop_get_preferred_address;
1768 env->sf.s_feedback = &GAS_proportional_address_preference_feedback; 1750 sf.s_pref = &GAS_proportional_address_change_preference;
1769 env->sf.s_del = &GAS_proportional_address_delete; 1751 sf.s_feedback = &GAS_proportional_address_preference_feedback;
1770 env->sf.s_bulk_start = &GAS_proportional_bulk_start; 1752 sf.s_del = &GAS_proportional_address_delete;
1771 env->sf.s_bulk_stop = &GAS_proportional_bulk_stop; 1753 sf.s_bulk_start = &GAS_proportional_bulk_start;
1772 1754 sf.s_bulk_stop = &GAS_proportional_bulk_stop;
1773 s->stats = (struct GNUNET_STATISTICS_Handle *) env->stats; 1755
1774 s->bw_changed = env->bandwidth_changed_cb;
1775 s->bw_changed_cls = env->bw_changed_cb_cls;
1776 s->get_preferences = env->get_preferences;
1777 s->get_preferences_cls = env->get_preference_cls;
1778 s->get_properties = env->get_property;
1779 s->get_properties_cls = env->get_property_cls;
1780 s->network_count = env->network_count;
1781 s->network_entries = GNUNET_malloc (env->network_count * sizeof (struct Network)); 1756 s->network_entries = GNUNET_malloc (env->network_count * sizeof (struct Network));
1782 1757
1783 /* Init */ 1758 /* Init */
@@ -1849,7 +1824,7 @@ libgnunet_plugin_ats_proportional_init (void *cls)
1849 cur->total_quota_in, 1824 cur->total_quota_in,
1850 cur->total_quota_out); 1825 cur->total_quota_out);
1851 } 1826 }
1852 return s; 1827 return &sf;
1853} 1828}
1854 1829
1855 1830