aboutsummaryrefslogtreecommitdiff
path: root/src/ats/plugin_ats_proportional.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-08 20:55:25 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-08 20:55:25 +0000
commite14164d8be56720436ec4bc736c29443d8513af4 (patch)
treee22e1759edbd5f4bff2c68a624fb9b8fb908e8a2 /src/ats/plugin_ats_proportional.c
parent02addaea83c38c80670fe94ab4b021eeb3105de7 (diff)
downloadgnunet-e14164d8be56720436ec4bc736c29443d8513af4.tar.gz
gnunet-e14164d8be56720436ec4bc736c29443d8513af4.zip
-getting there...
Diffstat (limited to 'src/ats/plugin_ats_proportional.c')
-rw-r--r--src/ats/plugin_ats_proportional.c55
1 files changed, 25 insertions, 30 deletions
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c
index be50c4393..4833fe764 100644
--- a/src/ats/plugin_ats_proportional.c
+++ b/src/ats/plugin_ats_proportional.c
@@ -917,29 +917,23 @@ get_active_address (struct GAS_PROPORTIONAL_Handle *s,
917 * are different switch 917 * are different switch
918 * 918 *
919 * @param s solver handle 919 * @param s solver handle
920 * @param current_address the address currently active for the peer,
921 * NULL for none
920 * @param peer the peer to check 922 * @param peer the peer to check
921 * return the new address or NULL if no update was performed 923 * return the new address or NULL if no update was performed
922 */ 924 */
923static struct ATS_Address * 925static struct ATS_Address *
924update_active_address (struct GAS_PROPORTIONAL_Handle *s, 926update_active_address (struct GAS_PROPORTIONAL_Handle *s,
927 struct ATS_Address *current_address,
925 const struct GNUNET_PeerIdentity *peer) 928 const struct GNUNET_PeerIdentity *peer)
926{ 929{
927 struct ATS_Address *best_address; 930 struct ATS_Address *best_address;
928 struct ATS_Address *current_address;
929 struct AddressWrapper *asi; 931 struct AddressWrapper *asi;
930 struct Network *net; 932 struct Network *net;
931 933
932 current_address = get_active_address (s,
933 peer);
934 best_address = get_best_address (s, 934 best_address = get_best_address (s,
935 s->env->addresses, 935 s->env->addresses,
936 peer); 936 peer);
937 LOG (GNUNET_ERROR_TYPE_INFO,
938 "Peer `%s' has active address %p and best address %p\n",
939 GNUNET_i2s (peer),
940 current_address,
941 best_address);
942
943 if (NULL != current_address) 937 if (NULL != current_address)
944 { 938 {
945 GNUNET_assert (GNUNET_YES == current_address->active); 939 GNUNET_assert (GNUNET_YES == current_address->active);
@@ -950,9 +944,7 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
950 /* We switch to a new address (or to none), 944 /* We switch to a new address (or to none),
951 mark old address as inactive */ 945 mark old address as inactive */
952 LOG (GNUNET_ERROR_TYPE_INFO, 946 LOG (GNUNET_ERROR_TYPE_INFO,
953 "Disabling previous %s address %p for peer `%s'\n", 947 "Disabling previous active address for peer `%s'\n",
954 (GNUNET_NO == current_address->active) ? "inactive" : "active",
955 current_address,
956 GNUNET_i2s (peer)); 948 GNUNET_i2s (peer));
957 949
958 asi = current_address->solver_information; 950 asi = current_address->solver_information;
@@ -997,7 +989,6 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
997 } 989 }
998 990
999 asi = best_address->solver_information; 991 asi = best_address->solver_information;
1000 GNUNET_assert (NULL != asi);
1001 net = asi->network; 992 net = asi->network;
1002 993
1003 /* Mark address as active */ 994 /* Mark address as active */
@@ -1019,7 +1010,8 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
1019 best_address, 1010 best_address,
1020 GNUNET_i2s (peer)); 1011 GNUNET_i2s (peer));
1021 /* Distribute bandwidth */ 1012 /* Distribute bandwidth */
1022 distribute_bandwidth_in_network (s, net); 1013 distribute_bandwidth_in_network (s,
1014 net);
1023 return best_address; 1015 return best_address;
1024} 1016}
1025 1017
@@ -1082,6 +1074,8 @@ GAS_proportional_get_preferred_address (void *solver,
1082 struct AddressWrapper *asi; 1074 struct AddressWrapper *asi;
1083 1075
1084 best_address = update_active_address (s, 1076 best_address = update_active_address (s,
1077 get_active_address (s,
1078 peer),
1085 peer); 1079 peer);
1086 if (NULL == best_address) 1080 if (NULL == best_address)
1087 return; 1081 return;
@@ -1152,11 +1146,13 @@ GAS_proportional_bulk_stop (void *solver)
1152 return; 1146 return;
1153 } 1147 }
1154 s->bulk_lock--; 1148 s->bulk_lock--;
1155 if ((0 == s->bulk_lock) && (0 < s->bulk_requests)) 1149 if ( (0 == s->bulk_lock) &&
1150 (0 < s->bulk_requests) )
1156 { 1151 {
1157 LOG (GNUNET_ERROR_TYPE_INFO, 1152 LOG (GNUNET_ERROR_TYPE_INFO,
1158 "No lock pending, recalculating\n"); 1153 "No lock pending, recalculating\n");
1159 distribute_bandwidth_in_network (s, NULL); 1154 distribute_bandwidth_in_network (s,
1155 NULL);
1160 s->bulk_requests = 0; 1156 s->bulk_requests = 0;
1161 } 1157 }
1162} 1158}
@@ -1222,21 +1218,24 @@ GAS_proportional_address_add (void *solver,
1222 1, 1218 1,
1223 GNUNET_NO); 1219 GNUNET_NO);
1224 1220
1221 if (0 !=
1222 s->env->get_connectivity (s->env->cls,
1223 &address->peer))
1224 {
1225 /* This peer is requested, find best address */
1226 update_active_address (s,
1227 get_active_address (s,
1228 &address->peer),
1229 &address->peer);
1230 }
1225 LOG (GNUNET_ERROR_TYPE_INFO, 1231 LOG (GNUNET_ERROR_TYPE_INFO,
1226 "Added new address for `%s', now total %u and active %u addresses in network `%s'\n", 1232 "Added new address for `%s', now total %u and active %u addresses in network `%s'\n",
1227 GNUNET_i2s (&address->peer), 1233 GNUNET_i2s (&address->peer),
1228 net->total_addresses, 1234 net->total_addresses,
1229 net->active_addresses, 1235 net->active_addresses,
1230 net->desc); 1236 net->desc);
1231 1237
1232 if (0 ==
1233 s->env->get_connectivity (s->env->cls,
1234 &address->peer))
1235 return; /* Peer is not requested */
1236 1238
1237 /* This peer is requested, find best address */
1238 update_active_address (s,
1239 &address->peer);
1240} 1239}
1241 1240
1242 1241
@@ -1279,16 +1278,11 @@ GAS_proportional_address_delete (void *solver,
1279 if (GNUNET_YES == address->active) 1278 if (GNUNET_YES == address->active)
1280 { 1279 {
1281 /* Address was active, remove from network and update quotas*/ 1280 /* Address was active, remove from network and update quotas*/
1282 address->active = GNUNET_NO;
1283 address->assigned_bw_in = 0; 1281 address->assigned_bw_in = 0;
1284 address->assigned_bw_out = 0; 1282 address->assigned_bw_out = 0;
1285 address_decrement_active (s, net);
1286 /* FIXME: this may trigger the solver unnecessarily,
1287 especially if update_active_address() succeeds! */
1288 distribute_bandwidth_in_network (s, net);
1289
1290 if (NULL == 1283 if (NULL ==
1291 update_active_address (s, 1284 update_active_address (s,
1285 address,
1292 &address->peer)) 1286 &address->peer))
1293 { 1287 {
1294 /* No alternative address found, disconnect peer */ 1288 /* No alternative address found, disconnect peer */
@@ -1299,6 +1293,7 @@ GAS_proportional_address_delete (void *solver,
1299 s->env->bandwidth_changed_cb (s->env->cls, 1293 s->env->bandwidth_changed_cb (s->env->cls,
1300 address); 1294 address);
1301 } 1295 }
1296 distribute_bandwidth_in_network (s, net);
1302 } 1297 }
1303 GNUNET_free (aw); 1298 GNUNET_free (aw);
1304 address->solver_information = NULL; 1299 address->solver_information = NULL;