aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-08 16:24:42 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-08 16:24:42 +0000
commit4f4a572297261f4bddce6e39879340d91a492ab9 (patch)
tree0aea7620b69659cebbe4b5311263f04fd12a70a6
parent386b7d1a0a8b86248e503602b30614b8a3984061 (diff)
downloadgnunet-4f4a572297261f4bddce6e39879340d91a492ab9.tar.gz
gnunet-4f4a572297261f4bddce6e39879340d91a492ab9.zip
avoid several linear scans and allocations by combining AddressWrapper and asi structs
-rw-r--r--src/ats/gnunet-ats-solver-eval.c2
-rw-r--r--src/ats/gnunet-service-ats_plugins.c3
-rw-r--r--src/ats/perf_ats_solver.c12
-rw-r--r--src/ats/plugin_ats_mlp.c20
-rw-r--r--src/ats/plugin_ats_proportional.c468
-rw-r--r--src/ats/plugin_ats_ril.c9
6 files changed, 196 insertions, 318 deletions
diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c
index 1c3d473d4..a10d745fd 100644
--- a/src/ats/gnunet-ats-solver-eval.c
+++ b/src/ats/gnunet-ats-solver-eval.c
@@ -2251,7 +2251,7 @@ enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
2251 op->address_id, 2251 op->address_id,
2252 op->peer_id); 2252 op->peer_id);
2253 2253
2254 sh->sf->s_del (sh->sf->cls, a->ats_addr, GNUNET_NO); 2254 sh->sf->s_del (sh->sf->cls, a->ats_addr);
2255 2255
2256 if (NULL != l) 2256 if (NULL != l)
2257 { 2257 {
diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c
index 64ef53e55..712f927b5 100644
--- a/src/ats/gnunet-service-ats_plugins.c
+++ b/src/ats/gnunet-service-ats_plugins.c
@@ -495,8 +495,7 @@ void
495GAS_plugin_delete_address (struct ATS_Address *address) 495GAS_plugin_delete_address (struct ATS_Address *address)
496{ 496{
497 sf->s_del (sf->cls, 497 sf->s_del (sf->cls,
498 address, 498 address);
499 GNUNET_NO);
500} 499}
501 500
502 501
diff --git a/src/ats/perf_ats_solver.c b/src/ats/perf_ats_solver.c
index b7ddec503..3f9c12f20 100644
--- a/src/ats/perf_ats_solver.c
+++ b/src/ats/perf_ats_solver.c
@@ -866,6 +866,15 @@ evaluate (int iteration)
866} 866}
867 867
868 868
869static unsigned int
870get_connectivity_cb (void *cls,
871 const struct GNUNET_PeerIdentity *peer)
872{
873 return GNUNET_CONTAINER_multipeermap_contains (ph.addresses,
874 peer);
875}
876
877
869/** 878/**
870 * Evaluate average results for all iterations 879 * Evaluate average results for all iterations
871 */ 880 */
@@ -1060,7 +1069,7 @@ do_delete_address (void *cls,
1060 GNUNET_CONTAINER_multipeermap_remove (ph.addresses, 1069 GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
1061 pid, 1070 pid,
1062 cur)); 1071 cur));
1063 ph.sf->s_del (ph.sf->cls, cur, GNUNET_NO); 1072 ph.sf->s_del (ph.sf->cls, cur);
1064 GNUNET_free_non_null (cur->atsi); 1073 GNUNET_free_non_null (cur->atsi);
1065 GNUNET_free (cur); 1074 GNUNET_free (cur);
1066 return GNUNET_OK; 1075 return GNUNET_OK;
@@ -1292,6 +1301,7 @@ run (void *cls, char * const *args, const char *cfgfile,
1292 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); 1301 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1293 ph.env.addresses = ph.addresses; 1302 ph.env.addresses = ph.addresses;
1294 ph.env.bandwidth_changed_cb = bandwidth_changed_cb; 1303 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
1304 ph.env.get_connectivity = &get_connectivity_cb;
1295 ph.env.get_preferences = &get_preferences_cb; 1305 ph.env.get_preferences = &get_preferences_cb;
1296 ph.env.network_count = GNUNET_ATS_NetworkTypeCount; 1306 ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
1297 ph.env.info_cb = &solver_info_cb; 1307 ph.env.info_cb = &solver_info_cb;
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c
index f2f961f7e..900a07fa5 100644
--- a/src/ats/plugin_ats_mlp.c
+++ b/src/ats/plugin_ats_mlp.c
@@ -2121,22 +2121,17 @@ GAS_mlp_get_preferred_address (void *solver,
2121 * 2121 *
2122 * @param solver the MLP Handle 2122 * @param solver the MLP Handle
2123 * @param address the address to delete 2123 * @param address the address to delete
2124 * @param session_only delete only session not whole address
2125 */ 2124 */
2126static void 2125static void
2127GAS_mlp_address_delete (void *solver, 2126GAS_mlp_address_delete (void *solver,
2128 struct ATS_Address *address, 2127 struct ATS_Address *address)
2129 int session_only)
2130{ 2128{
2131 struct GAS_MLP_Handle *mlp = solver; 2129 struct GAS_MLP_Handle *mlp = solver;
2132 struct MLP_information *mlpi; 2130 struct MLP_information *mlpi;
2133 int was_active; 2131 int was_active;
2134 2132
2135 GNUNET_assert (NULL != solver);
2136 GNUNET_assert (NULL != address);
2137
2138 mlpi = address->solver_information; 2133 mlpi = address->solver_information;
2139 if ((GNUNET_NO == session_only) && (NULL != mlpi)) 2134 if (NULL != mlpi)
2140 { 2135 {
2141 /* Remove full address */ 2136 /* Remove full address */
2142 GNUNET_free (mlpi); 2137 GNUNET_free (mlpi);
@@ -2153,14 +2148,13 @@ GAS_mlp_address_delete (void *solver,
2153 &address->peer)) 2148 &address->peer))
2154 { 2149 {
2155 LOG (GNUNET_ERROR_TYPE_INFO, 2150 LOG (GNUNET_ERROR_TYPE_INFO,
2156 "Deleting %s for peer `%s' without address request \n", 2151 "Deleting address for peer `%s' without address request \n",
2157 (session_only == GNUNET_YES) ? "session" : "address",
2158 GNUNET_i2s(&address->peer)); 2152 GNUNET_i2s(&address->peer));
2159 return; 2153 return;
2160 } 2154 }
2161 LOG (GNUNET_ERROR_TYPE_INFO, "Deleting %s for peer `%s' with address request \n", 2155 LOG (GNUNET_ERROR_TYPE_INFO,
2162 (session_only == GNUNET_YES) ? "session" : "address", 2156 "Deleting address for peer `%s' with address request \n",
2163 GNUNET_i2s(&address->peer)); 2157 GNUNET_i2s (&address->peer));
2164 2158
2165 /* Problem size changed: new address for peer with pending request */ 2159 /* Problem size changed: new address for peer with pending request */
2166 mlp->stat_mlp_prob_changed = GNUNET_YES; 2160 mlp->stat_mlp_prob_changed = GNUNET_YES;
@@ -2176,8 +2170,6 @@ GAS_mlp_address_delete (void *solver,
2176 mlp->env->bandwidth_changed_cb (mlp->env->cls, address); 2170 mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
2177 } 2171 }
2178 } 2172 }
2179
2180 return;
2181} 2173}
2182 2174
2183 2175
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c
index 72508a628..c387e8045 100644
--- a/src/ats/plugin_ats_proportional.c
+++ b/src/ats/plugin_ats_proportional.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011-2014 Christian Grothoff (and other contributing authors) 3 Copyright (C) 2011-2015 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -211,14 +211,18 @@
211 */ 211 */
212 212
213/** 213/**
214 * FIXME. 214 * Default value to assume for the proportionality factor,
215 * if none is given in the configuration.
215 */ 216 */
216#define PROPORTIONALITY_FACTOR 2.0 217#define PROPORTIONALITY_FACTOR 2.0
217 218
218 219
219/** 220/**
220 * Wrapper for addresses to store them in a 221 * Address information stored for the proportional solver in the
221 * `struct Network`'s linked list 222 * `solver_information` member of `struct GNUNET_ATS_Address`.
223 *
224 * They are also stored in the respective `struct Network`'s linked
225 * list.
222 */ 226 */
223struct AddressWrapper 227struct AddressWrapper
224{ 228{
@@ -236,6 +240,27 @@ struct AddressWrapper
236 * The address 240 * The address
237 */ 241 */
238 struct ATS_Address *addr; 242 struct ATS_Address *addr;
243
244 /**
245 * Network scope this address is in
246 */
247 struct Network *network;
248
249 /**
250 * Inbound quota
251 */
252 uint32_t calculated_quota_in;
253
254 /**
255 * Outbound quota
256 */
257 uint32_t calculated_quota_out;
258
259 /**
260 * When was this address activated
261 */
262 struct GNUNET_TIME_Absolute activated;
263
239}; 264};
240 265
241 266
@@ -314,31 +339,6 @@ struct GAS_PROPORTIONAL_Handle
314 struct Network *network_entries; 339 struct Network *network_entries;
315 340
316 /** 341 /**
317 * Bulk lock
318 */
319 int bulk_lock;
320
321 /**
322 * Number of changes while solver was locked
323 */
324 int bulk_requests;
325
326 /**
327 * Total number of addresses for solver
328 */
329 unsigned int total_addresses;
330
331 /**
332 * Number of active addresses for solver
333 */
334 unsigned int active_addresses;
335
336 /**
337 * Number of networks in @a network_entries
338 */
339 unsigned int network_count;
340
341 /**
342 * Proportionality factor 342 * Proportionality factor
343 */ 343 */
344 double prop_factor; 344 double prop_factor;
@@ -347,33 +347,27 @@ struct GAS_PROPORTIONAL_Handle
347 * Stability factor 347 * Stability factor
348 */ 348 */
349 double stability_factor; 349 double stability_factor;
350};
351 350
352/**
353 * Address information stored in the solver
354 */
355struct AddressSolverInformation
356{
357 /** 351 /**
358 * Network scope this address is in 352 * Bulk lock counter. If zero, we are not locked.
359 */ 353 */
360 struct Network *network; 354 unsigned int bulk_lock;
361 355
362 /** 356 /**
363 * Inbound quota 357 * Number of changes made while solver was locked. We really only
358 * use 0/non-zero to check on unlock if we have to run the update.
364 */ 359 */
365 uint32_t calculated_quota_in; 360 unsigned int bulk_requests;
366 361
367 /** 362 /**
368 * Outbound quota 363 * Number of active addresses for solver
369 */ 364 */
370 uint32_t calculated_quota_out; 365 unsigned int active_addresses;
371 366
372 /** 367 /**
373 * When was this address activated 368 * Number of networks in @a network_entries
374 */ 369 */
375 struct GNUNET_TIME_Absolute activated; 370 unsigned int network_count;
376
377}; 371};
378 372
379 373
@@ -424,13 +418,6 @@ libgnunet_plugin_ats_proportional_done (void *cls)
424 GNUNET_free (s->network_entries[c].stat_total); 418 GNUNET_free (s->network_entries[c].stat_total);
425 GNUNET_free (s->network_entries[c].stat_active); 419 GNUNET_free (s->network_entries[c].stat_active);
426 } 420 }
427 if (s->total_addresses > 0)
428 {
429 LOG (GNUNET_ERROR_TYPE_DEBUG,
430 "Had %u addresses not deleted during shutdown\n",
431 s->total_addresses);
432 // GNUNET_break(0);
433 }
434 if (s->active_addresses > 0) 421 if (s->active_addresses > 0)
435 { 422 {
436 LOG (GNUNET_ERROR_TYPE_DEBUG, 423 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -485,8 +472,7 @@ static void
485distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, 472distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
486 struct Network *net) 473 struct Network *net)
487{ 474{
488 struct AddressSolverInformation *asi; 475 struct AddressWrapper *aw;
489 struct AddressWrapper *cur_address;
490 unsigned long long remaining_quota_in = 0; 476 unsigned long long remaining_quota_in = 0;
491 unsigned long long quota_out_used = 0; 477 unsigned long long quota_out_used = 0;
492 unsigned long long remaining_quota_out = 0; 478 unsigned long long remaining_quota_out = 0;
@@ -540,13 +526,13 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
540 526
541 /* Calculate sum of relative preference for active addresses in this network */ 527 /* Calculate sum of relative preference for active addresses in this network */
542 count_addresses = 0; 528 count_addresses = 0;
543 for (cur_address = net->head; NULL != cur_address; cur_address = cur_address->next) 529 for (aw = net->head; NULL != aw; aw = aw->next)
544 { 530 {
545 if (GNUNET_YES != cur_address->addr->active) 531 if (GNUNET_YES != aw->addr->active)
546 continue; 532 continue;
547 533
548 peer_relative_prefs = s->env->get_preferences (s->env->cls, 534 peer_relative_prefs = s->env->get_preferences (s->env->cls,
549 &cur_address->addr->peer); 535 &aw->addr->peer);
550 relative_peer_prefence = 0.0; 536 relative_peer_prefence = 0.0;
551 relative_peer_prefence += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; 537 relative_peer_prefence += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
552 sum_relative_peer_prefences += relative_peer_prefence; 538 sum_relative_peer_prefences += relative_peer_prefence;
@@ -559,16 +545,16 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
559 LOG (GNUNET_ERROR_TYPE_WARNING, 545 LOG (GNUNET_ERROR_TYPE_WARNING,
560 "%s: Counted %u active addresses, but network says to have %u active addresses\n", 546 "%s: Counted %u active addresses, but network says to have %u active addresses\n",
561 net->desc, count_addresses, net->active_addresses); 547 net->desc, count_addresses, net->active_addresses);
562 for (cur_address = net->head; NULL != cur_address; cur_address = cur_address->next) 548 for (aw = net->head; NULL != aw; aw = aw->next)
563 { 549 {
564 if (GNUNET_YES != cur_address->addr->active) 550 if (GNUNET_YES != aw->addr->active)
565 continue; 551 continue;
566 552
567 LOG (GNUNET_ERROR_TYPE_WARNING, 553 LOG (GNUNET_ERROR_TYPE_WARNING,
568 "Active: `%s' `%s' length %u\n", 554 "Active: `%s' `%s' length %u\n",
569 GNUNET_i2s (&cur_address->addr->peer), 555 GNUNET_i2s (&aw->addr->peer),
570 cur_address->addr->plugin, 556 aw->addr->plugin,
571 cur_address->addr->addr_len); 557 aw->addr->addr_len);
572 } 558 }
573 } 559 }
574 560
@@ -576,12 +562,12 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
576 "Total relative preference %.3f for %u addresses in network %s\n", 562 "Total relative preference %.3f for %u addresses in network %s\n",
577 sum_relative_peer_prefences, net->active_addresses, net->desc); 563 sum_relative_peer_prefences, net->active_addresses, net->desc);
578 564
579 for (cur_address = net->head; NULL != cur_address; cur_address = cur_address->next) 565 for (aw = net->head; NULL != aw; aw = aw->next)
580 { 566 {
581 if (GNUNET_YES == cur_address->addr->active) 567 if (GNUNET_YES == aw->addr->active)
582 { 568 {
583 peer_relative_prefs = s->env->get_preferences (s->env->cls, 569 peer_relative_prefs = s->env->get_preferences (s->env->cls,
584 &cur_address->addr->peer); 570 &aw->addr->peer);
585 571
586 cur_pref = peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; 572 cur_pref = peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
587 total_weight = net->active_addresses + 573 total_weight = net->active_addresses +
@@ -595,7 +581,7 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
595 581
596 LOG (GNUNET_ERROR_TYPE_INFO, 582 LOG (GNUNET_ERROR_TYPE_INFO,
597 "New quota for peer `%s' with weight (cur/total) %.3f/%.3f (in/out): %llu / %llu\n", 583 "New quota for peer `%s' with weight (cur/total) %.3f/%.3f (in/out): %llu / %llu\n",
598 GNUNET_i2s (&cur_address->addr->peer), peer_weight, total_weight, 584 GNUNET_i2s (&aw->addr->peer), peer_weight, total_weight,
599 assigned_quota_in, assigned_quota_out); 585 assigned_quota_in, assigned_quota_out);
600 } 586 }
601 else 587 else
@@ -613,9 +599,8 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
613 assigned_quota_out = UINT32_MAX; 599 assigned_quota_out = UINT32_MAX;
614 600
615 /* Compare to current bandwidth assigned */ 601 /* Compare to current bandwidth assigned */
616 asi = cur_address->addr->solver_information; 602 aw->calculated_quota_in = assigned_quota_in;
617 asi->calculated_quota_in = assigned_quota_in; 603 aw->calculated_quota_out = assigned_quota_out;
618 asi->calculated_quota_out = assigned_quota_out;
619 } 604 }
620 LOG(GNUNET_ERROR_TYPE_DEBUG, 605 LOG(GNUNET_ERROR_TYPE_DEBUG,
621 "Total bandwidth assigned is (in/out): %llu /%llu\n", quota_in_used, 606 "Total bandwidth assigned is (in/out): %llu /%llu\n", quota_in_used,
@@ -686,7 +671,7 @@ find_best_address_it (void *cls,
686 struct FindBestAddressCtx *ctx = cls; 671 struct FindBestAddressCtx *ctx = cls;
687 struct ATS_Address *current = value; 672 struct ATS_Address *current = value;
688 struct ATS_Address *current_best = current; 673 struct ATS_Address *current_best = current;
689 struct AddressSolverInformation *asi; 674 struct AddressWrapper *asi;
690 struct GNUNET_TIME_Relative active_time; 675 struct GNUNET_TIME_Relative active_time;
691 struct GNUNET_TIME_Relative min_active_time; 676 struct GNUNET_TIME_Relative min_active_time;
692 double best_delay; 677 double best_delay;
@@ -900,43 +885,6 @@ get_network (struct GAS_PROPORTIONAL_Handle *s,
900 885
901 886
902/** 887/**
903 * Increase address count in network
904 *
905 * @param s the solver handle
906 * @param net the network type
907 * @param total increase total addresses
908 * @param active increase active addresses
909 */
910static void
911address_increment (struct GAS_PROPORTIONAL_Handle *s,
912 struct Network *net,
913 int total,
914 int active)
915{
916 if (GNUNET_YES == total)
917 {
918 s->total_addresses++;
919 net->total_addresses++;
920 GNUNET_STATISTICS_update (s->env->stats,
921 "# ATS addresses total", 1, GNUNET_NO);
922 GNUNET_STATISTICS_update (s->env->stats,
923 net->stat_total, 1, GNUNET_NO);
924 }
925 if (GNUNET_YES == active)
926 {
927 net->active_addresses++;
928 s->active_addresses++;
929 GNUNET_STATISTICS_update (s->env->stats,
930 "# ATS active addresses total", 1,
931 GNUNET_NO);
932 GNUNET_STATISTICS_update (s->env->stats,
933 net->stat_active, 1, GNUNET_NO);
934 }
935
936}
937
938
939/**
940 * Decrease address count in network 888 * Decrease address count in network
941 * 889 *
942 * @param s the solver handle 890 * @param s the solver handle
@@ -944,32 +892,17 @@ address_increment (struct GAS_PROPORTIONAL_Handle *s,
944 * @param total decrease total addresses 892 * @param total decrease total addresses
945 * @param active decrease active addresses 893 * @param active decrease active addresses
946 */ 894 */
947static int 895static void
948addresse_decrement (struct GAS_PROPORTIONAL_Handle *s, 896address_decrement (struct GAS_PROPORTIONAL_Handle *s,
949 struct Network *net, 897 struct Network *net,
950 int total, 898 int total,
951 int active) 899 int active)
952{ 900{
953 int res = GNUNET_OK;
954
955 if (GNUNET_YES == total) 901 if (GNUNET_YES == total)
956 { 902 {
957 if (s->total_addresses < 1)
958 {
959 GNUNET_break(0);
960 res = GNUNET_SYSERR;
961 }
962 else
963 {
964 s->total_addresses--;
965 GNUNET_STATISTICS_update (s->env->stats,
966 "# ATS addresses total", -1,
967 GNUNET_NO);
968 }
969 if (net->total_addresses < 1) 903 if (net->total_addresses < 1)
970 { 904 {
971 GNUNET_break(0); 905 GNUNET_break(0);
972 res = GNUNET_SYSERR;
973 } 906 }
974 else 907 else
975 { 908 {
@@ -983,8 +916,7 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
983 { 916 {
984 if (net->active_addresses < 1) 917 if (net->active_addresses < 1)
985 { 918 {
986 GNUNET_break(0); 919 GNUNET_break (0);
987 res = GNUNET_SYSERR;
988 } 920 }
989 else 921 else
990 { 922 {
@@ -994,18 +926,17 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
994 } 926 }
995 if (s->active_addresses < 1) 927 if (s->active_addresses < 1)
996 { 928 {
997 GNUNET_break(0); 929 GNUNET_break (0);
998 res = GNUNET_SYSERR;
999 } 930 }
1000 else 931 else
1001 { 932 {
1002 s->active_addresses--; 933 s->active_addresses--;
1003 GNUNET_STATISTICS_update (s->env->stats, 934 GNUNET_STATISTICS_update (s->env->stats,
1004 "# ATS addresses total", -1, 935 "# ATS addresses total",
1005 GNUNET_NO); 936 -1,
937 GNUNET_NO);
1006 } 938 }
1007 } 939 }
1008 return res;
1009} 940}
1010 941
1011 942
@@ -1044,20 +975,18 @@ propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
1044 struct Network *net) 975 struct Network *net)
1045{ 976{
1046 struct AddressWrapper *cur; 977 struct AddressWrapper *cur;
1047 struct AddressSolverInformation *asi;
1048 978
1049 for (cur = net->head; NULL != cur; cur = cur->next) 979 for (cur = net->head; NULL != cur; cur = cur->next)
1050 { 980 {
1051 asi = cur->addr->solver_information; 981 if ( (cur->addr->assigned_bw_in != cur->calculated_quota_in) ||
1052 if ( (cur->addr->assigned_bw_in != asi->calculated_quota_in) || 982 (cur->addr->assigned_bw_out != cur->calculated_quota_out) )
1053 (cur->addr->assigned_bw_out != asi->calculated_quota_out) )
1054 { 983 {
1055 cur->addr->assigned_bw_in = asi->calculated_quota_in; 984 cur->addr->assigned_bw_in = cur->calculated_quota_in;
1056 cur->addr->assigned_bw_out = asi->calculated_quota_out; 985 cur->addr->assigned_bw_out = cur->calculated_quota_out;
1057 986
1058 /* Reset for next iteration */ 987 /* Reset for next iteration */
1059 asi->calculated_quota_in = 0; 988 cur->calculated_quota_in = 0;
1060 asi->calculated_quota_out = 0; 989 cur->calculated_quota_out = 0;
1061 LOG (GNUNET_ERROR_TYPE_DEBUG, 990 LOG (GNUNET_ERROR_TYPE_DEBUG,
1062 "Bandwidth for %s address %p for peer `%s' changed to %u/%u\n", 991 "Bandwidth for %s address %p for peer `%s' changed to %u/%u\n",
1063 (GNUNET_NO == cur->addr->active) ? "inactive" : "active", 992 (GNUNET_NO == cur->addr->active) ? "inactive" : "active",
@@ -1097,8 +1026,9 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
1097 { 1026 {
1098 LOG (GNUNET_ERROR_TYPE_INFO, 1027 LOG (GNUNET_ERROR_TYPE_INFO,
1099 "Redistributing bandwidth in network %s with %u active and %u total addresses\n", 1028 "Redistributing bandwidth in network %s with %u active and %u total addresses\n",
1100 GNUNET_ATS_print_network_type(n->type), 1029 GNUNET_ATS_print_network_type(n->type),
1101 n->active_addresses, n->total_addresses); 1030 n->active_addresses,
1031 n->total_addresses);
1102 1032
1103 s->env->info_cb (s->env->cls, 1033 s->env->info_cb (s->env->cls,
1104 GAS_OP_SOLVE_START, 1034 GAS_OP_SOLVE_START,
@@ -1174,7 +1104,7 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
1174{ 1104{
1175 struct ATS_Address *best_address; 1105 struct ATS_Address *best_address;
1176 struct ATS_Address *current_address; 1106 struct ATS_Address *current_address;
1177 struct AddressSolverInformation *asi; 1107 struct AddressWrapper *asi;
1178 struct Network *net; 1108 struct Network *net;
1179 1109
1180 LOG (GNUNET_ERROR_TYPE_INFO, 1110 LOG (GNUNET_ERROR_TYPE_INFO,
@@ -1224,8 +1154,7 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
1224 current_address->assigned_bw_in = 0; /* no bandwidth assigned */ 1154 current_address->assigned_bw_in = 0; /* no bandwidth assigned */
1225 current_address->assigned_bw_out = 0; /* no bandwidth assigned */ 1155 current_address->assigned_bw_out = 0; /* no bandwidth assigned */
1226 1156
1227 if (GNUNET_SYSERR == addresse_decrement (s, net, GNUNET_NO, GNUNET_YES)) 1157 address_decrement (s, net, GNUNET_NO, GNUNET_YES);
1228 GNUNET_break(0);
1229 1158
1230 /* Update network of previous address */ 1159 /* Update network of previous address */
1231 distribute_bandwidth_in_network (s, net); 1160 distribute_bandwidth_in_network (s, net);
@@ -1269,7 +1198,17 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
1269 /* Mark address as active */ 1198 /* Mark address as active */
1270 asi->activated = GNUNET_TIME_absolute_get (); 1199 asi->activated = GNUNET_TIME_absolute_get ();
1271 best_address->active = GNUNET_YES; 1200 best_address->active = GNUNET_YES;
1272 address_increment (s, net, GNUNET_NO, GNUNET_YES); 1201
1202 net->active_addresses++;
1203 s->active_addresses++;
1204 GNUNET_STATISTICS_update (s->env->stats,
1205 "# ATS active addresses total",
1206 1,
1207 GNUNET_NO);
1208 GNUNET_STATISTICS_update (s->env->stats,
1209 net->stat_active,
1210 1,
1211 GNUNET_NO);
1273 LOG (GNUNET_ERROR_TYPE_INFO, 1212 LOG (GNUNET_ERROR_TYPE_INFO,
1274 "Address %p for peer `%s' is now active\n", 1213 "Address %p for peer `%s' is now active\n",
1275 best_address, 1214 best_address,
@@ -1297,7 +1236,7 @@ GAS_proportional_address_change_preference (void *solver,
1297 struct GAS_PROPORTIONAL_Handle *s = solver; 1236 struct GAS_PROPORTIONAL_Handle *s = solver;
1298 struct ATS_Address *best_address; 1237 struct ATS_Address *best_address;
1299 struct ATS_Address *active_address; 1238 struct ATS_Address *active_address;
1300 struct AddressSolverInformation *asi; 1239 struct AddressWrapper *asi;
1301 1240
1302 if (0 == 1241 if (0 ==
1303 s->env->get_connectivity (s->env->cls, 1242 s->env->get_connectivity (s->env->cls,
@@ -1380,7 +1319,7 @@ GAS_proportional_stop_get_preferred_address (void *solver,
1380{ 1319{
1381 struct GAS_PROPORTIONAL_Handle *s = solver; 1320 struct GAS_PROPORTIONAL_Handle *s = solver;
1382 struct ATS_Address *cur; 1321 struct ATS_Address *cur;
1383 struct AddressSolverInformation *asi; 1322 struct AddressWrapper *asi;
1384 struct Network *cur_net; 1323 struct Network *cur_net;
1385 1324
1386 cur = get_active_address (s, 1325 cur = get_active_address (s,
@@ -1396,15 +1335,13 @@ GAS_proportional_stop_get_preferred_address (void *solver,
1396 1335
1397 /* Disabling current address */ 1336 /* Disabling current address */
1398 asi = cur->solver_information; 1337 asi = cur->solver_information;
1399 cur_net = asi->network ; 1338 cur_net = asi->network;
1400 asi->activated = GNUNET_TIME_UNIT_ZERO_ABS; 1339 asi->activated = GNUNET_TIME_UNIT_ZERO_ABS;
1401 cur->active = GNUNET_NO; /* No active any longer */ 1340 cur->active = GNUNET_NO; /* No active any longer */
1402 cur->assigned_bw_in = 0; /* no bandwidth assigned */ 1341 cur->assigned_bw_in = 0; /* no bandwidth assigned */
1403 cur->assigned_bw_out = 0; /* no bandwidth assigned */ 1342 cur->assigned_bw_out = 0; /* no bandwidth assigned */
1404 1343
1405 if (GNUNET_SYSERR == 1344 address_decrement (s, cur_net, GNUNET_NO, GNUNET_YES);
1406 addresse_decrement (s, cur_net, GNUNET_NO, GNUNET_YES))
1407 GNUNET_break(0);
1408 1345
1409 distribute_bandwidth_in_network (s, cur_net); 1346 distribute_bandwidth_in_network (s, cur_net);
1410 } 1347 }
@@ -1412,120 +1349,6 @@ GAS_proportional_stop_get_preferred_address (void *solver,
1412 1349
1413 1350
1414/** 1351/**
1415 * Remove an address from the solver
1416 *
1417 * @param solver the solver handle
1418 * @param address the address to remove
1419 * @param session_only delete only session not whole address
1420 */
1421static void
1422GAS_proportional_address_delete (void *solver,
1423 struct ATS_Address *address,
1424 int session_only)
1425{
1426 struct GAS_PROPORTIONAL_Handle *s = solver;
1427 struct Network *net;
1428 struct AddressWrapper *aw;
1429 struct AddressSolverInformation *asi;
1430
1431 /* Remove an adress completely, we have to:
1432 * - Remove from specific network
1433 * - Decrease number of total addresses
1434 * - If active:
1435 * - decrease number of active addreses
1436 * - update quotas
1437 */
1438 asi = address->solver_information;
1439
1440 if (NULL == asi)
1441 {
1442 GNUNET_break (0);
1443 return;
1444 }
1445 net = asi->network;
1446
1447 if (GNUNET_NO == session_only)
1448 {
1449 LOG (GNUNET_ERROR_TYPE_INFO,
1450 "Deleting %s address %p for peer `%s' from network `%s' (total: %u/ active: %u)\n",
1451 (GNUNET_NO == address->active) ? "inactive" : "active",
1452 address,
1453 GNUNET_i2s (&address->peer),
1454 net->desc,
1455 net->total_addresses,
1456 net->active_addresses);
1457
1458 /* Remove address */
1459 addresse_decrement (s, net, GNUNET_YES, GNUNET_NO);
1460 for (aw = net->head; NULL != aw; aw = aw->next)
1461 {
1462 if (aw->addr == address)
1463 break;
1464 }
1465 if (NULL == aw)
1466 {
1467 GNUNET_break(0);
1468 return;
1469 }
1470 GNUNET_CONTAINER_DLL_remove (net->head,
1471 net->tail,
1472 aw);
1473 GNUNET_free (aw);
1474 }
1475 else
1476 {
1477 /* Remove session only: remove if active and update */
1478 LOG (GNUNET_ERROR_TYPE_INFO,
1479 "Deleting %s session %p for peer `%s' from network `%s' (total: %u/ active: %u)\n",
1480 (GNUNET_NO == address->active) ? "inactive" : "active",
1481 address,
1482 GNUNET_i2s (&address->peer),
1483 net->desc,
1484 net->total_addresses,
1485 net->active_addresses);
1486 }
1487
1488 if (GNUNET_YES == address->active)
1489 {
1490 /* Address was active, remove from network and update quotas*/
1491 address->active = GNUNET_NO;
1492 address->assigned_bw_in = 0;
1493 address->assigned_bw_out = 0;
1494 asi->calculated_quota_in = 0;
1495 asi->calculated_quota_out = 0;
1496
1497 if (GNUNET_SYSERR ==
1498 addresse_decrement (s, net, GNUNET_NO, GNUNET_YES))
1499 GNUNET_break(0);
1500 distribute_bandwidth_in_network (s, net);
1501
1502 if (NULL ==
1503 update_active_address (s, &address->peer))
1504 {
1505 /* No alternative address found, disconnect peer */
1506 LOG (GNUNET_ERROR_TYPE_INFO,
1507 "Disconnecting peer `%s' after deleting previous address %p\n",
1508 GNUNET_i2s (&address->peer),
1509 address);
1510 s->env->bandwidth_changed_cb (s->env->cls,
1511 address);
1512 }
1513 }
1514 if (GNUNET_NO == session_only)
1515 {
1516 GNUNET_free_non_null (address->solver_information);
1517 address->solver_information = NULL;
1518 }
1519
1520 LOG (GNUNET_ERROR_TYPE_INFO,
1521 "After deleting address now total %u and active %u addresses in network `%s'\n",
1522 net->total_addresses,
1523 net->active_addresses,
1524 net->desc);
1525}
1526
1527
1528/**
1529 * Start a bulk operation 1352 * Start a bulk operation
1530 * 1353 *
1531 * @param solver the solver 1354 * @param solver the solver
@@ -1560,7 +1383,8 @@ GAS_proportional_bulk_stop (void *solver)
1560 s->bulk_lock--; 1383 s->bulk_lock--;
1561 if ((0 == s->bulk_lock) && (0 < s->bulk_requests)) 1384 if ((0 == s->bulk_lock) && (0 < s->bulk_requests))
1562 { 1385 {
1563 LOG(GNUNET_ERROR_TYPE_INFO, "No lock pending, recalculating\n"); 1386 LOG (GNUNET_ERROR_TYPE_INFO,
1387 "No lock pending, recalculating\n");
1564 distribute_bandwidth_in_network (s, NULL); 1388 distribute_bandwidth_in_network (s, NULL);
1565 s->bulk_requests = 0; 1389 s->bulk_requests = 0;
1566 } 1390 }
@@ -1568,19 +1392,6 @@ GAS_proportional_bulk_stop (void *solver)
1568 1392
1569 1393
1570/** 1394/**
1571 * Add a new single address to a network
1572 *
1573 * @param solver the solver Handle
1574 * @param address the address to add
1575 * @param network network type of this address
1576 */
1577static void
1578GAS_proportional_address_add (void *solver,
1579 struct ATS_Address *address,
1580 uint32_t network);
1581
1582
1583/**
1584 * Transport properties for this address have changed 1395 * Transport properties for this address have changed
1585 * 1396 *
1586 * @param solver solver handle 1397 * @param solver solver handle
@@ -1598,7 +1409,7 @@ GAS_proportional_address_property_changed (void *solver,
1598{ 1409{
1599 struct GAS_PROPORTIONAL_Handle *s = solver; 1410 struct GAS_PROPORTIONAL_Handle *s = solver;
1600 struct Network *n; 1411 struct Network *n;
1601 struct AddressSolverInformation *asi; 1412 struct AddressWrapper *asi;
1602 struct ATS_Address *best_address; 1413 struct ATS_Address *best_address;
1603 struct ATS_Address *active_address; 1414 struct ATS_Address *active_address;
1604 1415
@@ -1662,31 +1473,31 @@ GAS_proportional_address_add (void *solver,
1662 struct GAS_PROPORTIONAL_Handle *s = solver; 1473 struct GAS_PROPORTIONAL_Handle *s = solver;
1663 struct Network *net; 1474 struct Network *net;
1664 struct AddressWrapper *aw; 1475 struct AddressWrapper *aw;
1665 struct AddressSolverInformation *asi;
1666 1476
1667 net = get_network (s, network); 1477 net = get_network (s,
1478 network);
1668 if (NULL == net) 1479 if (NULL == net)
1669 { 1480 {
1670 GNUNET_break (0); 1481 GNUNET_break (0);
1671 LOG (GNUNET_ERROR_TYPE_ERROR,
1672 "Unknown network %u `%s' for new address %p for peer `%s'\n",
1673 network,
1674 GNUNET_ATS_print_network_type (network),
1675 address,
1676 GNUNET_i2s (&address->peer));
1677 return; 1482 return;
1678 } 1483 }
1679 1484
1680 aw = GNUNET_new (struct AddressWrapper); 1485 aw = GNUNET_new (struct AddressWrapper);
1681 aw->addr = address; 1486 aw->addr = address;
1682 GNUNET_CONTAINER_DLL_insert (net->head, net->tail, aw); 1487 GNUNET_CONTAINER_DLL_insert (net->head,
1683 address_increment (s, net, GNUNET_YES, GNUNET_NO); 1488 net->tail,
1684 1489 aw);
1685 asi = GNUNET_new (struct AddressSolverInformation); 1490 net->total_addresses++;
1686 asi->network = net; 1491 GNUNET_STATISTICS_update (s->env->stats,
1687 asi->calculated_quota_in = 0; 1492 "# ATS addresses total",
1688 asi->calculated_quota_out = 0; 1493 1,
1689 aw->addr->solver_information = asi; 1494 GNUNET_NO);
1495 GNUNET_STATISTICS_update (s->env->stats,
1496 net->stat_total,
1497 1,
1498 GNUNET_NO);
1499 aw->network = net;
1500 address->solver_information = aw;
1690 1501
1691 LOG (GNUNET_ERROR_TYPE_INFO, 1502 LOG (GNUNET_ERROR_TYPE_INFO,
1692 "Adding new address %p for peer `%s', now total %u and active %u addresses in network `%s'\n", 1503 "Adding new address %p for peer `%s', now total %u and active %u addresses in network `%s'\n",
@@ -1708,6 +1519,73 @@ GAS_proportional_address_add (void *solver,
1708 1519
1709 1520
1710/** 1521/**
1522 * Remove an address from the solver. To do so, we:
1523 * - Removed it from specific network
1524 * - Decrease the number of total addresses
1525 * - If active:
1526 * - decrease number of active addreses
1527 * - update quotas
1528 *
1529 * @param solver the solver handle
1530 * @param address the address to remove
1531 */
1532static void
1533GAS_proportional_address_delete (void *solver,
1534 struct ATS_Address *address)
1535{
1536 struct GAS_PROPORTIONAL_Handle *s = solver;
1537 struct AddressWrapper *aw = address->solver_information;
1538 struct Network *net = aw->network;
1539
1540 LOG (GNUNET_ERROR_TYPE_INFO,
1541 "Deleting %s address for peer `%s' from network `%s' (total: %u/active: %u)\n",
1542 (GNUNET_NO == address->active) ? "inactive" : "active",
1543 GNUNET_i2s (&address->peer),
1544 net->desc,
1545 net->total_addresses,
1546 net->active_addresses);
1547
1548 /* Remove address */
1549 address_decrement (s, net, GNUNET_YES, GNUNET_NO);
1550 if (GNUNET_YES == address->active)
1551 {
1552 /* Address was active, remove from network and update quotas*/
1553 address->active = GNUNET_NO;
1554 address->assigned_bw_in = 0;
1555 address->assigned_bw_out = 0;
1556 aw->calculated_quota_in = 0;
1557 aw->calculated_quota_out = 0;
1558
1559 address_decrement (s, net, GNUNET_NO, GNUNET_YES);
1560 distribute_bandwidth_in_network (s, net);
1561
1562 if (NULL ==
1563 update_active_address (s, &address->peer))
1564 {
1565 /* No alternative address found, disconnect peer */
1566 LOG (GNUNET_ERROR_TYPE_INFO,
1567 "Disconnecting peer `%s' after deleting previous address %p\n",
1568 GNUNET_i2s (&address->peer),
1569 address);
1570 s->env->bandwidth_changed_cb (s->env->cls,
1571 address);
1572 }
1573 }
1574 GNUNET_CONTAINER_DLL_remove (net->head,
1575 net->tail,
1576 aw);
1577 GNUNET_free (aw);
1578 address->solver_information = NULL;
1579
1580 LOG (GNUNET_ERROR_TYPE_INFO,
1581 "After deleting address now total %u and active %u addresses in network `%s'\n",
1582 net->total_addresses,
1583 net->active_addresses,
1584 net->desc);
1585}
1586
1587
1588/**
1711 * Function invoked when the plugin is loaded. 1589 * Function invoked when the plugin is loaded.
1712 * 1590 *
1713 * @param[in,out] cls the `struct GNUNET_ATS_PluginEnvironment *` to use; 1591 * @param[in,out] cls the `struct GNUNET_ATS_PluginEnvironment *` to use;
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c
index 76212e835..047be865c 100644
--- a/src/ats/plugin_ats_ril.c
+++ b/src/ats/plugin_ats_ril.c
@@ -2257,12 +2257,10 @@ GAS_ril_address_add (void *solver,
2257 * 2257 *
2258 * @param solver the solver handle 2258 * @param solver the solver handle
2259 * @param address the address to remove 2259 * @param address the address to remove
2260 * @param session_only delete only session not whole address
2261 */ 2260 */
2262static void 2261static void
2263GAS_ril_address_delete (void *solver, 2262GAS_ril_address_delete (void *solver,
2264 struct ATS_Address *address, 2263 struct ATS_Address *address)
2265 int session_only)
2266{ 2264{
2267 struct GAS_RIL_Handle *s = solver; 2265 struct GAS_RIL_Handle *s = solver;
2268 struct RIL_Peer_Agent *agent; 2266 struct RIL_Peer_Agent *agent;
@@ -2274,8 +2272,9 @@ GAS_ril_address_delete (void *solver,
2274 struct RIL_Scope *net; 2272 struct RIL_Scope *net;
2275 2273
2276 LOG (GNUNET_ERROR_TYPE_DEBUG, 2274 LOG (GNUNET_ERROR_TYPE_DEBUG,
2277 "API_address_delete() Delete %s%s %s address %s for peer '%s'\n", 2275 "API_address_delete() Delete %s %s address %s for peer '%s'\n",
2278 session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin, 2276 address->active ? "active" : "inactive",
2277 address->plugin,
2279 address->addr, 2278 address->addr,
2280 GNUNET_i2s (&address->peer)); 2279 GNUNET_i2s (&address->peer));
2281 2280