diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-08 16:36:30 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-08 16:36:30 +0000 |
commit | 0e29d84d844a3613f5ecf9e033b8c20f88affe30 (patch) | |
tree | 83452350ee2aa5ee9eb29a0e58d2141d0578779f /src/ats/plugin_ats_proportional.c | |
parent | acbb6a5bebd11b6c741b0b9ce1b6eb75f4cee61f (diff) | |
download | gnunet-0e29d84d844a3613f5ecf9e033b8c20f88affe30.tar.gz gnunet-0e29d84d844a3613f5ecf9e033b8c20f88affe30.zip |
cleaning up address_decrement
Diffstat (limited to 'src/ats/plugin_ats_proportional.c')
-rw-r--r-- | src/ats/plugin_ats_proportional.c | 99 |
1 files changed, 39 insertions, 60 deletions
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index c387e8045..329f2ad5d 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c | |||
@@ -889,53 +889,32 @@ get_network (struct GAS_PROPORTIONAL_Handle *s, | |||
889 | * | 889 | * |
890 | * @param s the solver handle | 890 | * @param s the solver handle |
891 | * @param net the network type | 891 | * @param net the network type |
892 | * @param total decrease total addresses | ||
893 | * @param active decrease active addresses | ||
894 | */ | 892 | */ |
895 | static void | 893 | static void |
896 | address_decrement (struct GAS_PROPORTIONAL_Handle *s, | 894 | address_decrement_active (struct GAS_PROPORTIONAL_Handle *s, |
897 | struct Network *net, | 895 | struct Network *net) |
898 | int total, | ||
899 | int active) | ||
900 | { | 896 | { |
901 | if (GNUNET_YES == total) | 897 | if (net->active_addresses < 1) |
902 | { | 898 | { |
903 | if (net->total_addresses < 1) | 899 | GNUNET_break (0); |
904 | { | ||
905 | GNUNET_break(0); | ||
906 | } | ||
907 | else | ||
908 | { | ||
909 | net->total_addresses--; | ||
910 | GNUNET_STATISTICS_update (s->env->stats, | ||
911 | net->stat_total, -1, GNUNET_NO); | ||
912 | } | ||
913 | } | 900 | } |
914 | 901 | else | |
915 | if (GNUNET_YES == active) | ||
916 | { | 902 | { |
917 | if (net->active_addresses < 1) | 903 | net->active_addresses--; |
918 | { | 904 | GNUNET_STATISTICS_update (s->env->stats, |
919 | GNUNET_break (0); | 905 | net->stat_active, -1, GNUNET_NO); |
920 | } | 906 | } |
921 | else | 907 | if (s->active_addresses < 1) |
922 | { | 908 | { |
923 | net->active_addresses--; | 909 | GNUNET_break (0); |
924 | GNUNET_STATISTICS_update (s->env->stats, | 910 | } |
925 | net->stat_active, -1, GNUNET_NO); | 911 | else |
926 | } | 912 | { |
927 | if (s->active_addresses < 1) | 913 | s->active_addresses--; |
928 | { | 914 | GNUNET_STATISTICS_update (s->env->stats, |
929 | GNUNET_break (0); | 915 | "# ATS addresses total", |
930 | } | 916 | -1, |
931 | else | 917 | GNUNET_NO); |
932 | { | ||
933 | s->active_addresses--; | ||
934 | GNUNET_STATISTICS_update (s->env->stats, | ||
935 | "# ATS addresses total", | ||
936 | -1, | ||
937 | GNUNET_NO); | ||
938 | } | ||
939 | } | 918 | } |
940 | } | 919 | } |
941 | 920 | ||
@@ -1132,6 +1111,7 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
1132 | 1111 | ||
1133 | if (NULL != current_address) | 1112 | if (NULL != current_address) |
1134 | { | 1113 | { |
1114 | GNUNET_assert (GNUNET_YES == current_address->active); | ||
1135 | if ( (NULL == best_address) || | 1115 | if ( (NULL == best_address) || |
1136 | ( (NULL != best_address) && | 1116 | ( (NULL != best_address) && |
1137 | (GNUNET_NO == address_eq (current_address, | 1117 | (GNUNET_NO == address_eq (current_address, |
@@ -1146,17 +1126,12 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
1146 | GNUNET_i2s (peer)); | 1126 | GNUNET_i2s (peer)); |
1147 | 1127 | ||
1148 | asi = current_address->solver_information; | 1128 | asi = current_address->solver_information; |
1149 | GNUNET_assert (NULL != asi); | ||
1150 | |||
1151 | net = asi->network; | 1129 | net = asi->network; |
1152 | asi->activated = GNUNET_TIME_UNIT_ZERO_ABS; | 1130 | asi->activated = GNUNET_TIME_UNIT_ZERO_ABS; |
1153 | current_address->active = GNUNET_NO; /* No active any longer */ | 1131 | current_address->active = GNUNET_NO; /* No active any longer */ |
1154 | current_address->assigned_bw_in = 0; /* no bandwidth assigned */ | 1132 | current_address->assigned_bw_in = 0; /* no bandwidth assigned */ |
1155 | current_address->assigned_bw_out = 0; /* no bandwidth assigned */ | 1133 | current_address->assigned_bw_out = 0; /* no bandwidth assigned */ |
1156 | 1134 | address_decrement_active (s, net); | |
1157 | address_decrement (s, net, GNUNET_NO, GNUNET_YES); | ||
1158 | |||
1159 | /* Update network of previous address */ | ||
1160 | distribute_bandwidth_in_network (s, net); | 1135 | distribute_bandwidth_in_network (s, net); |
1161 | } | 1136 | } |
1162 | if (NULL == best_address) | 1137 | if (NULL == best_address) |
@@ -1341,7 +1316,7 @@ GAS_proportional_stop_get_preferred_address (void *solver, | |||
1341 | cur->assigned_bw_in = 0; /* no bandwidth assigned */ | 1316 | cur->assigned_bw_in = 0; /* no bandwidth assigned */ |
1342 | cur->assigned_bw_out = 0; /* no bandwidth assigned */ | 1317 | cur->assigned_bw_out = 0; /* no bandwidth assigned */ |
1343 | 1318 | ||
1344 | address_decrement (s, cur_net, GNUNET_NO, GNUNET_YES); | 1319 | address_decrement_active (s, cur_net); |
1345 | 1320 | ||
1346 | distribute_bandwidth_in_network (s, cur_net); | 1321 | distribute_bandwidth_in_network (s, cur_net); |
1347 | } | 1322 | } |
@@ -1537,7 +1512,7 @@ GAS_proportional_address_delete (void *solver, | |||
1537 | struct AddressWrapper *aw = address->solver_information; | 1512 | struct AddressWrapper *aw = address->solver_information; |
1538 | struct Network *net = aw->network; | 1513 | struct Network *net = aw->network; |
1539 | 1514 | ||
1540 | LOG (GNUNET_ERROR_TYPE_INFO, | 1515 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1541 | "Deleting %s address for peer `%s' from network `%s' (total: %u/active: %u)\n", | 1516 | "Deleting %s address for peer `%s' from network `%s' (total: %u/active: %u)\n", |
1542 | (GNUNET_NO == address->active) ? "inactive" : "active", | 1517 | (GNUNET_NO == address->active) ? "inactive" : "active", |
1543 | GNUNET_i2s (&address->peer), | 1518 | GNUNET_i2s (&address->peer), |
@@ -1546,21 +1521,29 @@ GAS_proportional_address_delete (void *solver, | |||
1546 | net->active_addresses); | 1521 | net->active_addresses); |
1547 | 1522 | ||
1548 | /* Remove address */ | 1523 | /* Remove address */ |
1549 | address_decrement (s, net, GNUNET_YES, GNUNET_NO); | 1524 | GNUNET_CONTAINER_DLL_remove (net->head, |
1525 | net->tail, | ||
1526 | aw); | ||
1527 | GNUNET_assert (net->total_addresses > 0); | ||
1528 | net->total_addresses--; | ||
1529 | GNUNET_STATISTICS_update (s->env->stats, | ||
1530 | net->stat_total, | ||
1531 | -1, | ||
1532 | GNUNET_NO); | ||
1550 | if (GNUNET_YES == address->active) | 1533 | if (GNUNET_YES == address->active) |
1551 | { | 1534 | { |
1552 | /* Address was active, remove from network and update quotas*/ | 1535 | /* Address was active, remove from network and update quotas*/ |
1553 | address->active = GNUNET_NO; | 1536 | address->active = GNUNET_NO; |
1554 | address->assigned_bw_in = 0; | 1537 | address->assigned_bw_in = 0; |
1555 | address->assigned_bw_out = 0; | 1538 | address->assigned_bw_out = 0; |
1556 | aw->calculated_quota_in = 0; | 1539 | address_decrement_active (s, net); |
1557 | aw->calculated_quota_out = 0; | 1540 | /* FIXME: this may trigger the solver unnecessarily, |
1558 | 1541 | especially if update_active_address() succeeds! */ | |
1559 | address_decrement (s, net, GNUNET_NO, GNUNET_YES); | ||
1560 | distribute_bandwidth_in_network (s, net); | 1542 | distribute_bandwidth_in_network (s, net); |
1561 | 1543 | ||
1562 | if (NULL == | 1544 | if (NULL == |
1563 | update_active_address (s, &address->peer)) | 1545 | update_active_address (s, |
1546 | &address->peer)) | ||
1564 | { | 1547 | { |
1565 | /* No alternative address found, disconnect peer */ | 1548 | /* No alternative address found, disconnect peer */ |
1566 | LOG (GNUNET_ERROR_TYPE_INFO, | 1549 | LOG (GNUNET_ERROR_TYPE_INFO, |
@@ -1571,13 +1554,9 @@ GAS_proportional_address_delete (void *solver, | |||
1571 | address); | 1554 | address); |
1572 | } | 1555 | } |
1573 | } | 1556 | } |
1574 | GNUNET_CONTAINER_DLL_remove (net->head, | ||
1575 | net->tail, | ||
1576 | aw); | ||
1577 | GNUNET_free (aw); | 1557 | GNUNET_free (aw); |
1578 | address->solver_information = NULL; | 1558 | address->solver_information = NULL; |
1579 | 1559 | LOG (GNUNET_ERROR_TYPE_DEBUG, | |
1580 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1581 | "After deleting address now total %u and active %u addresses in network `%s'\n", | 1560 | "After deleting address now total %u and active %u addresses in network `%s'\n", |
1582 | net->total_addresses, | 1561 | net->total_addresses, |
1583 | net->active_addresses, | 1562 | net->active_addresses, |