diff options
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 2 | ||||
-rw-r--r-- | src/ats/plugin_ats_proportional.c | 709 | ||||
-rw-r--r-- | src/ats/test_ats_solver_alternative_after_delete_address.c | 26 |
3 files changed, 374 insertions, 363 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 406acf614..8b5413b92 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -1459,6 +1459,7 @@ find_active_address (void *cls, const struct GNUNET_PeerIdentity *id, void *obj) | |||
1459 | void | 1459 | void |
1460 | GAS_addresses_evaluate_assignment (struct GAS_Addresses_Handle *ah) | 1460 | GAS_addresses_evaluate_assignment (struct GAS_Addresses_Handle *ah) |
1461 | { | 1461 | { |
1462 | #if 0 | ||
1462 | struct GAS_Addresses_Suggestion_Requests *cur; | 1463 | struct GAS_Addresses_Suggestion_Requests *cur; |
1463 | struct GAS_Addresses_Preference_Clients *pcur; | 1464 | struct GAS_Addresses_Preference_Clients *pcur; |
1464 | int c; | 1465 | int c; |
@@ -1657,6 +1658,7 @@ GAS_addresses_evaluate_assignment (struct GAS_Addresses_Handle *ah) | |||
1657 | quality_bandwidth_utilization_total, | 1658 | quality_bandwidth_utilization_total, |
1658 | quality_application_requirements, | 1659 | quality_application_requirements, |
1659 | guq); | 1660 | guq); |
1661 | #endif | ||
1660 | } | 1662 | } |
1661 | 1663 | ||
1662 | /** | 1664 | /** |
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index 0c593ad96..6def592e2 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c | |||
@@ -368,6 +368,10 @@ struct AddressSolverInformation | |||
368 | */ | 368 | */ |
369 | unsigned long long calculated_quota_out_NBO; | 369 | unsigned long long calculated_quota_out_NBO; |
370 | 370 | ||
371 | /** | ||
372 | * When was this address activated | ||
373 | */ | ||
374 | struct GNUNET_TIME_Absolute activated; | ||
371 | 375 | ||
372 | }; | 376 | }; |
373 | 377 | ||
@@ -588,29 +592,16 @@ is_bandwidth_available_in_network (struct Network *net) | |||
588 | return GNUNET_NO; | 592 | return GNUNET_NO; |
589 | } | 593 | } |
590 | 594 | ||
591 | static void | ||
592 | bandwidth_changed (struct GAS_PROPORTIONAL_Handle *s) | ||
593 | { | ||
594 | if (GNUNET_YES == s->bulk_lock) | ||
595 | { | ||
596 | s->bulk_requests++; | ||
597 | return; | ||
598 | } | ||
599 | |||
600 | |||
601 | } | ||
602 | |||
603 | /** | 595 | /** |
604 | * Update bandwidth assigned to peers in this network | 596 | * Update bandwidth assigned to peers in this network |
605 | * | 597 | * |
606 | * @param s the solver handle | 598 | * @param s the solver handle |
607 | * @param net the network type to update | 599 | * @param net the network type to update |
608 | * @param address_except address excluded from notification, since we suggest | ||
609 | * this address | 600 | * this address |
610 | */ | 601 | */ |
611 | static void | 602 | static void |
612 | distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | 603 | distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, |
613 | struct Network *net, struct ATS_Address *address_except) | 604 | struct Network *net) |
614 | { | 605 | { |
615 | struct AddressSolverInformation *asi; | 606 | struct AddressSolverInformation *asi; |
616 | struct AddressWrapper *cur_address; | 607 | struct AddressWrapper *cur_address; |
@@ -780,6 +771,8 @@ find_best_address_it (void *cls, | |||
780 | struct ATS_Address *current_best = (struct ATS_Address *) value; | 771 | struct ATS_Address *current_best = (struct ATS_Address *) value; |
781 | struct GNUNET_TIME_Absolute now; | 772 | struct GNUNET_TIME_Absolute now; |
782 | struct AddressSolverInformation *asi; | 773 | struct AddressSolverInformation *asi; |
774 | struct GNUNET_TIME_Relative active_time; | ||
775 | struct GNUNET_TIME_Relative min_active_time; | ||
783 | const double *norm_prop_cur; | 776 | const double *norm_prop_cur; |
784 | const double *norm_prop_best; | 777 | const double *norm_prop_best; |
785 | double best_delay; | 778 | double best_delay; |
@@ -792,8 +785,9 @@ find_best_address_it (void *cls, | |||
792 | asi = current->solver_information; | 785 | asi = current->solver_information; |
793 | now = GNUNET_TIME_absolute_get (); | 786 | now = GNUNET_TIME_absolute_get (); |
794 | 787 | ||
795 | if (current->blocked_until.abs_value_us | 788 | if ((current->active == GNUNET_NO) |
796 | == GNUNET_TIME_absolute_max (now, current->blocked_until).abs_value_us) | 789 | && (current->blocked_until.abs_value_us |
790 | == GNUNET_TIME_absolute_max (now, current->blocked_until).abs_value_us)) | ||
797 | { | 791 | { |
798 | /* This address is blocked for suggestion */ | 792 | /* This address is blocked for suggestion */ |
799 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Address %p blocked for suggestion for %s \n", | 793 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Address %p blocked for suggestion for %s \n", |
@@ -808,30 +802,14 @@ find_best_address_it (void *cls, | |||
808 | } | 802 | } |
809 | 803 | ||
810 | if (GNUNET_NO == is_bandwidth_available_in_network (asi->network)) | 804 | if (GNUNET_NO == is_bandwidth_available_in_network (asi->network)) |
805 | { | ||
811 | return GNUNET_OK; /* There's no bandwidth available in this network */ | 806 | return GNUNET_OK; /* There's no bandwidth available in this network */ |
807 | } | ||
812 | 808 | ||
813 | if (NULL != ctx->best) | 809 | if (NULL != ctx->best) |
814 | { | 810 | { |
815 | /* Compare current addresses with denominated 'best' address */ | 811 | /* Compare current addresses with denominated 'best' address */ |
816 | |||
817 | current_best = ctx->best; | 812 | current_best = ctx->best; |
818 | if ((0 != ctx->best->addr_len) && (0 == current->addr_len)) | ||
819 | { | ||
820 | /* saved address was an outbound address, but we have an inbound address */ | ||
821 | current_best = current; | ||
822 | goto end; | ||
823 | } | ||
824 | if (ctx->best->t_last_activity.abs_value_us < current->t_last_activity.abs_value_us) | ||
825 | { | ||
826 | /* Current address is newer */ | ||
827 | current_best = current; | ||
828 | } | ||
829 | if (ctx->best->t_added.abs_value_us < current->t_added.abs_value_us) | ||
830 | { | ||
831 | /* Current address is newer */ | ||
832 | current_best = current; | ||
833 | goto end; | ||
834 | } | ||
835 | } | 813 | } |
836 | else | 814 | else |
837 | { | 815 | { |
@@ -841,6 +819,20 @@ find_best_address_it (void *cls, | |||
841 | goto end; | 819 | goto end; |
842 | } | 820 | } |
843 | 821 | ||
822 | if (GNUNET_YES == current->active) | ||
823 | { | ||
824 | GNUNET_assert (asi->activated.abs_value_us != GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us); | ||
825 | active_time = GNUNET_TIME_absolute_get_duration (asi->activated); | ||
826 | min_active_time.rel_value_us = ((double) GNUNET_TIME_UNIT_SECONDS.rel_value_us) * | ||
827 | PROP_STABILITY_FACTOR; | ||
828 | if (active_time.rel_value_us <= min_active_time.rel_value_us) | ||
829 | { | ||
830 | /* Keep active address for stability reasons */ | ||
831 | ctx->best = current; | ||
832 | return GNUNET_NO; | ||
833 | } | ||
834 | } | ||
835 | |||
844 | /* Now compare ATS information */ | 836 | /* Now compare ATS information */ |
845 | norm_prop_cur = ctx->s->get_properties (ctx->s->get_properties_cls, | 837 | norm_prop_cur = ctx->s->get_properties (ctx->s->get_properties_cls, |
846 | (const struct ATS_Address *) current); | 838 | (const struct ATS_Address *) current); |
@@ -857,8 +849,6 @@ find_best_address_it (void *cls, | |||
857 | best_delay = norm_prop_best[index]; | 849 | best_delay = norm_prop_best[index]; |
858 | 850 | ||
859 | /* user shorter distance */ | 851 | /* user shorter distance */ |
860 | |||
861 | |||
862 | if (cur_distance < best_distance) | 852 | if (cur_distance < best_distance) |
863 | { | 853 | { |
864 | 854 | ||
@@ -891,10 +881,6 @@ find_best_address_it (void *cls, | |||
891 | /* Best and active address performs worse */ | 881 | /* Best and active address performs worse */ |
892 | current_best = current; | 882 | current_best = current; |
893 | } | 883 | } |
894 | else | ||
895 | { | ||
896 | //GNUNET_break (0); | ||
897 | } | ||
898 | } | 884 | } |
899 | else | 885 | else |
900 | { | 886 | { |
@@ -923,137 +909,6 @@ get_best_address (struct GAS_PROPORTIONAL_Handle *s, | |||
923 | } | 909 | } |
924 | 910 | ||
925 | /** | 911 | /** |
926 | * Helper functions | ||
927 | * --------------------------- | ||
928 | */ | ||
929 | static void | ||
930 | propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | ||
931 | struct Network *net, struct ATS_Address *address_except) | ||
932 | { | ||
933 | struct AddressWrapper *cur; | ||
934 | struct AddressSolverInformation *asi; | ||
935 | for (cur = net->head; NULL != cur; cur = cur->next) | ||
936 | { | ||
937 | asi = cur->addr->solver_information; | ||
938 | if ( (cur->addr->assigned_bw_in.value__ != asi->calculated_quota_in_NBO) || | ||
939 | (cur->addr->assigned_bw_out.value__ != asi->calculated_quota_out_NBO) ) | ||
940 | { | ||
941 | cur->addr->assigned_bw_in.value__ = asi->calculated_quota_in_NBO; | ||
942 | cur->addr->assigned_bw_out.value__ = asi->calculated_quota_out_NBO; | ||
943 | |||
944 | /* Reset for next iteration */ | ||
945 | asi->calculated_quota_in_NBO = htonl (0); | ||
946 | asi->calculated_quota_out_NBO = htonl (0); | ||
947 | |||
948 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
949 | "Bandwidth for %s address %p for peer `%s' changed to %u/%u\n", | ||
950 | (GNUNET_NO == cur->addr->active) ? "inactive" : "active", | ||
951 | cur->addr, | ||
952 | GNUNET_i2s (&cur->addr->peer), | ||
953 | ntohl (cur->addr->assigned_bw_in.value__), | ||
954 | ntohl (cur->addr->assigned_bw_out.value__ )); | ||
955 | |||
956 | /* Notify on change */ | ||
957 | if ((GNUNET_YES == cur->addr->active) && (cur->addr != address_except)) | ||
958 | s->bw_changed (s->bw_changed_cls, cur->addr); | ||
959 | } | ||
960 | } | ||
961 | } | ||
962 | |||
963 | /** | ||
964 | * Distribibute bandwidth | ||
965 | * | ||
966 | * @param s the solver handle | ||
967 | * @param n the network, can be NULL for all network | ||
968 | * @param address_except do not notify for this address | ||
969 | */ | ||
970 | static void | ||
971 | distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, | ||
972 | struct Network *n, struct ATS_Address *address_except) | ||
973 | { | ||
974 | if (GNUNET_YES == s->bulk_lock) | ||
975 | { | ||
976 | s->bulk_requests++; | ||
977 | return; | ||
978 | } | ||
979 | |||
980 | if (NULL != n) | ||
981 | { | ||
982 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
983 | "Redistributing bandwidth in network %s with %u active and %u total addresses\n", | ||
984 | GNUNET_ATS_print_network_type(n->type), | ||
985 | n->active_addresses, n->total_addresses); | ||
986 | |||
987 | if (NULL != s->env->info_cb) | ||
988 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START, | ||
989 | GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); | ||
990 | |||
991 | /* Distribute */ | ||
992 | distribute_bandwidth(s, n, address_except); | ||
993 | |||
994 | if (NULL != s->env->info_cb) | ||
995 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP, | ||
996 | GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); | ||
997 | if (NULL != s->env->info_cb) | ||
998 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, | ||
999 | GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); | ||
1000 | |||
1001 | /* Do propagation */ | ||
1002 | propagate_bandwidth (s, n, address_except); | ||
1003 | |||
1004 | if (NULL != s->env->info_cb) | ||
1005 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, | ||
1006 | GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); | ||
1007 | } | ||
1008 | else | ||
1009 | { | ||
1010 | int i; | ||
1011 | if (NULL != s->env->info_cb) | ||
1012 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START, | ||
1013 | GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); | ||
1014 | for (i = 0; i < s->network_count; i++) | ||
1015 | { | ||
1016 | /* Distribute */ | ||
1017 | distribute_bandwidth(s, &s->network_entries[i], NULL); | ||
1018 | } | ||
1019 | |||
1020 | if (NULL != s->env->info_cb) | ||
1021 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP, | ||
1022 | GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); | ||
1023 | if (NULL != s->env->info_cb) | ||
1024 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, | ||
1025 | GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); | ||
1026 | for (i = 0; i < s->network_count; i++) | ||
1027 | { | ||
1028 | /* Do propagation */ | ||
1029 | propagate_bandwidth(s, &s->network_entries[i], address_except); | ||
1030 | } | ||
1031 | if (NULL != s->env->info_cb) | ||
1032 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, | ||
1033 | GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); | ||
1034 | } | ||
1035 | } | ||
1036 | |||
1037 | /** | ||
1038 | * Lookup network struct by type | ||
1039 | * | ||
1040 | * @param s the solver handle | ||
1041 | * @param type the network type | ||
1042 | * @return the network struct | ||
1043 | */ | ||
1044 | static struct Network * | ||
1045 | get_network (struct GAS_PROPORTIONAL_Handle *s, uint32_t type) | ||
1046 | { | ||
1047 | int c; | ||
1048 | for (c = 0; c < s->network_count; c++) | ||
1049 | { | ||
1050 | if (s->network_entries[c].type == type) | ||
1051 | return &s->network_entries[c]; | ||
1052 | } | ||
1053 | return NULL ; | ||
1054 | } | ||
1055 | |||
1056 | /** | ||
1057 | * Hashmap Iterator to find current active address for peer | 912 | * Hashmap Iterator to find current active address for peer |
1058 | * | 913 | * |
1059 | * @param cls last active address | 914 | * @param cls last active address |
@@ -1063,8 +918,8 @@ get_network (struct GAS_PROPORTIONAL_Handle *s, uint32_t type) | |||
1063 | */ | 918 | */ |
1064 | static int | 919 | static int |
1065 | get_active_address_it (void *cls, | 920 | get_active_address_it (void *cls, |
1066 | const struct GNUNET_PeerIdentity *key, | 921 | const struct GNUNET_PeerIdentity *key, |
1067 | void *value) | 922 | void *value) |
1068 | { | 923 | { |
1069 | struct ATS_Address **dest = cls; | 924 | struct ATS_Address **dest = cls; |
1070 | struct ATS_Address *aa = (struct ATS_Address *) value; | 925 | struct ATS_Address *aa = (struct ATS_Address *) value; |
@@ -1095,17 +950,37 @@ get_active_address_it (void *cls, | |||
1095 | */ | 950 | */ |
1096 | static struct ATS_Address * | 951 | static struct ATS_Address * |
1097 | get_active_address (void *solver, | 952 | get_active_address (void *solver, |
1098 | const struct GNUNET_CONTAINER_MultiPeerMap * addresses, | 953 | const struct GNUNET_CONTAINER_MultiPeerMap * addresses, |
1099 | const struct GNUNET_PeerIdentity *peer) | 954 | const struct GNUNET_PeerIdentity *peer) |
1100 | { | 955 | { |
1101 | struct ATS_Address * dest = NULL; | 956 | struct ATS_Address * dest = NULL; |
1102 | 957 | ||
1103 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, peer, | 958 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, peer, |
1104 | &get_active_address_it, &dest); | 959 | &get_active_address_it, &dest); |
1105 | return dest; | 960 | return dest; |
1106 | } | 961 | } |
1107 | 962 | ||
1108 | 963 | ||
964 | /** | ||
965 | * Lookup network struct by type | ||
966 | * | ||
967 | * @param s the solver handle | ||
968 | * @param type the network type | ||
969 | * @return the network struct | ||
970 | */ | ||
971 | static struct Network * | ||
972 | get_network (struct GAS_PROPORTIONAL_Handle *s, uint32_t type) | ||
973 | { | ||
974 | int c; | ||
975 | for (c = 0; c < s->network_count; c++) | ||
976 | { | ||
977 | if (s->network_entries[c].type == type) | ||
978 | return &s->network_entries[c]; | ||
979 | } | ||
980 | return NULL ; | ||
981 | } | ||
982 | |||
983 | |||
1109 | static void | 984 | static void |
1110 | addresse_increment (struct GAS_PROPORTIONAL_Handle *s, struct Network *net, | 985 | addresse_increment (struct GAS_PROPORTIONAL_Handle *s, struct Network *net, |
1111 | int total, int active) | 986 | int total, int active) |
@@ -1203,6 +1078,210 @@ address_eq (struct ATS_Address *a, struct ATS_Address *b) | |||
1203 | } | 1078 | } |
1204 | 1079 | ||
1205 | /** | 1080 | /** |
1081 | * Helper functions | ||
1082 | * --------------------------- | ||
1083 | */ | ||
1084 | static void | ||
1085 | propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | ||
1086 | struct Network *net) | ||
1087 | { | ||
1088 | struct AddressWrapper *cur; | ||
1089 | struct AddressSolverInformation *asi; | ||
1090 | for (cur = net->head; NULL != cur; cur = cur->next) | ||
1091 | { | ||
1092 | asi = cur->addr->solver_information; | ||
1093 | if ( (cur->addr->assigned_bw_in.value__ != asi->calculated_quota_in_NBO) || | ||
1094 | (cur->addr->assigned_bw_out.value__ != asi->calculated_quota_out_NBO) ) | ||
1095 | { | ||
1096 | cur->addr->assigned_bw_in.value__ = asi->calculated_quota_in_NBO; | ||
1097 | cur->addr->assigned_bw_out.value__ = asi->calculated_quota_out_NBO; | ||
1098 | |||
1099 | /* Reset for next iteration */ | ||
1100 | asi->calculated_quota_in_NBO = htonl (0); | ||
1101 | asi->calculated_quota_out_NBO = htonl (0); | ||
1102 | |||
1103 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1104 | "Bandwidth for %s address %p for peer `%s' changed to %u/%u\n", | ||
1105 | (GNUNET_NO == cur->addr->active) ? "inactive" : "active", | ||
1106 | cur->addr, | ||
1107 | GNUNET_i2s (&cur->addr->peer), | ||
1108 | ntohl (cur->addr->assigned_bw_in.value__), | ||
1109 | ntohl (cur->addr->assigned_bw_out.value__ )); | ||
1110 | |||
1111 | /* Notify on change */ | ||
1112 | if ((GNUNET_YES == cur->addr->active)) | ||
1113 | { | ||
1114 | s->bw_changed (s->bw_changed_cls, cur->addr); | ||
1115 | } | ||
1116 | } | ||
1117 | } | ||
1118 | } | ||
1119 | |||
1120 | /** | ||
1121 | * Distribibute bandwidth | ||
1122 | * | ||
1123 | * @param s the solver handle | ||
1124 | * @param n the network, can be NULL for all network | ||
1125 | * @param address_except do not notify for this address | ||
1126 | */ | ||
1127 | static void | ||
1128 | distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, | ||
1129 | struct Network *n) | ||
1130 | { | ||
1131 | if (GNUNET_YES == s->bulk_lock) | ||
1132 | { | ||
1133 | s->bulk_requests++; | ||
1134 | return; | ||
1135 | } | ||
1136 | |||
1137 | if (NULL != n) | ||
1138 | { | ||
1139 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1140 | "Redistributing bandwidth in network %s with %u active and %u total addresses\n", | ||
1141 | GNUNET_ATS_print_network_type(n->type), | ||
1142 | n->active_addresses, n->total_addresses); | ||
1143 | |||
1144 | if (NULL != s->env->info_cb) | ||
1145 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START, | ||
1146 | GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); | ||
1147 | |||
1148 | /* Distribute */ | ||
1149 | distribute_bandwidth(s, n); | ||
1150 | |||
1151 | if (NULL != s->env->info_cb) | ||
1152 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP, | ||
1153 | GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); | ||
1154 | if (NULL != s->env->info_cb) | ||
1155 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, | ||
1156 | GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); | ||
1157 | |||
1158 | /* Do propagation */ | ||
1159 | propagate_bandwidth (s, n); | ||
1160 | |||
1161 | if (NULL != s->env->info_cb) | ||
1162 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, | ||
1163 | GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); | ||
1164 | } | ||
1165 | else | ||
1166 | { | ||
1167 | int i; | ||
1168 | if (NULL != s->env->info_cb) | ||
1169 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START, | ||
1170 | GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); | ||
1171 | for (i = 0; i < s->network_count; i++) | ||
1172 | { | ||
1173 | /* Distribute */ | ||
1174 | distribute_bandwidth(s, &s->network_entries[i]); | ||
1175 | } | ||
1176 | |||
1177 | if (NULL != s->env->info_cb) | ||
1178 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP, | ||
1179 | GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); | ||
1180 | if (NULL != s->env->info_cb) | ||
1181 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, | ||
1182 | GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); | ||
1183 | for (i = 0; i < s->network_count; i++) | ||
1184 | { | ||
1185 | /* Do propagation */ | ||
1186 | propagate_bandwidth(s, &s->network_entries[i]); | ||
1187 | } | ||
1188 | if (NULL != s->env->info_cb) | ||
1189 | s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, | ||
1190 | GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); | ||
1191 | } | ||
1192 | } | ||
1193 | |||
1194 | static const struct ATS_Address * | ||
1195 | update_active_address (struct GAS_PROPORTIONAL_Handle *s, | ||
1196 | const struct GNUNET_PeerIdentity *peer) | ||
1197 | { | ||
1198 | struct ATS_Address *best_address; | ||
1199 | struct ATS_Address *current_address; | ||
1200 | struct AddressSolverInformation *asi; | ||
1201 | struct Network *net; | ||
1202 | |||
1203 | LOG (GNUNET_ERROR_TYPE_INFO, "Updating active address for peer `%s'\n", | ||
1204 | GNUNET_i2s (peer)); | ||
1205 | |||
1206 | /* Find active address */ | ||
1207 | current_address = get_active_address (s, s->addresses, peer); | ||
1208 | /* Find best address */ | ||
1209 | best_address = get_best_address (s,s->addresses, peer); | ||
1210 | |||
1211 | if (NULL != current_address) | ||
1212 | { | ||
1213 | if ((NULL == best_address) || ((NULL != best_address) && (GNUNET_NO == address_eq (current_address, best_address)))) | ||
1214 | { | ||
1215 | /* We switch to a new address, mark old address as inactive */ | ||
1216 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1217 | "Disabling previous %s address %p for peer `%s'\n", | ||
1218 | (GNUNET_NO == current_address->active) ? "inactive" : "active", | ||
1219 | current_address, | ||
1220 | GNUNET_i2s (peer)); | ||
1221 | |||
1222 | asi = current_address->solver_information; | ||
1223 | GNUNET_assert (NULL != asi); | ||
1224 | |||
1225 | net = asi->network; | ||
1226 | asi->activated = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1227 | current_address->active = GNUNET_NO; /* No active any longer */ | ||
1228 | current_address->assigned_bw_in = BANDWIDTH_ZERO; /* no bandwidth assigned */ | ||
1229 | current_address->assigned_bw_out = BANDWIDTH_ZERO; /* no bandwidth assigned */ | ||
1230 | |||
1231 | if (GNUNET_SYSERR == addresse_decrement (s, net, GNUNET_NO, GNUNET_YES)) | ||
1232 | GNUNET_break(0); | ||
1233 | |||
1234 | /* Update network of previous address */ | ||
1235 | distribute_bandwidth_in_network (s, net); | ||
1236 | } | ||
1237 | if (NULL == best_address) | ||
1238 | { | ||
1239 | /* We previously had an active address, but now we cannot suggest one | ||
1240 | * Therefore we have to disconnect the peer */ | ||
1241 | |||
1242 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1243 | "Disconnecting peer `%s' with previous %s address %p\n", | ||
1244 | GNUNET_i2s (peer), | ||
1245 | (GNUNET_NO == current_address->active) ? "inactive" : "active", | ||
1246 | current_address); | ||
1247 | s->bw_changed (s->bw_changed_cls, current_address); | ||
1248 | } | ||
1249 | } | ||
1250 | |||
1251 | if (NULL == best_address) | ||
1252 | { | ||
1253 | LOG (GNUNET_ERROR_TYPE_INFO, "Cannot suggest address for peer `%s'\n", | ||
1254 | GNUNET_i2s (peer)); | ||
1255 | return NULL ; | ||
1256 | } | ||
1257 | |||
1258 | LOG (GNUNET_ERROR_TYPE_INFO, "Suggesting %s address %p for peer `%s'\n", | ||
1259 | (GNUNET_NO == best_address->active) ? "inactive" : "active", best_address, | ||
1260 | GNUNET_i2s (peer)); | ||
1261 | |||
1262 | if ((NULL != current_address) && | ||
1263 | (GNUNET_YES == address_eq (best_address, current_address))) | ||
1264 | { | ||
1265 | if (current_address->active == GNUNET_NO) | ||
1266 | GNUNET_break (0); /* Should never happen */ | ||
1267 | return best_address; /* Same same */ | ||
1268 | } | ||
1269 | |||
1270 | asi = best_address->solver_information; | ||
1271 | GNUNET_assert (NULL != asi); | ||
1272 | net = asi->network; | ||
1273 | |||
1274 | /* Mark address as active */ | ||
1275 | asi->activated = GNUNET_TIME_absolute_get(); | ||
1276 | best_address->active = GNUNET_YES; | ||
1277 | addresse_increment (s, net, GNUNET_NO, GNUNET_YES); | ||
1278 | |||
1279 | /* Distribute bandwidth */ | ||
1280 | distribute_bandwidth_in_network (s, net); | ||
1281 | return best_address; | ||
1282 | } | ||
1283 | |||
1284 | /** | ||
1206 | * Solver API functions | 1285 | * Solver API functions |
1207 | * --------------------------- | 1286 | * --------------------------- |
1208 | */ | 1287 | */ |
@@ -1224,6 +1303,7 @@ GAS_proportional_address_change_preference (void *solver, | |||
1224 | struct GAS_PROPORTIONAL_Handle *s = solver; | 1303 | struct GAS_PROPORTIONAL_Handle *s = solver; |
1225 | struct ATS_Address *best_address; | 1304 | struct ATS_Address *best_address; |
1226 | struct ATS_Address *active_address; | 1305 | struct ATS_Address *active_address; |
1306 | struct AddressSolverInformation *asi; | ||
1227 | 1307 | ||
1228 | GNUNET_assert(NULL != solver); | 1308 | GNUNET_assert(NULL != solver); |
1229 | GNUNET_assert(NULL != peer); | 1309 | GNUNET_assert(NULL != peer); |
@@ -1233,21 +1313,17 @@ GAS_proportional_address_change_preference (void *solver, | |||
1233 | 1313 | ||
1234 | /* This peer is requested, find best address */ | 1314 | /* This peer is requested, find best address */ |
1235 | active_address = get_active_address(s, s->addresses, peer); | 1315 | active_address = get_active_address(s, s->addresses, peer); |
1236 | best_address = (struct ATS_Address *) GAS_proportional_get_preferred_address (s, peer); | 1316 | best_address = (struct ATS_Address *) update_active_address (s, peer); |
1237 | 1317 | ||
1238 | if (NULL == best_address) | 1318 | if ((NULL != best_address) && ((NULL != active_address) && |
1239 | return; /* No address to suggest */ | 1319 | (GNUNET_YES == address_eq (active_address, best_address)))) |
1240 | |||
1241 | if ((NULL == active_address) || ((NULL != active_address) && | ||
1242 | (GNUNET_NO == address_eq (active_address, best_address)))) | ||
1243 | { | 1320 | { |
1244 | /* We now have an active address */ | 1321 | asi = best_address->solver_information; |
1245 | s->bw_changed (s->bw_changed_cls, best_address); | 1322 | GNUNET_assert (NULL != asi); |
1246 | return; | ||
1247 | } | ||
1248 | 1323 | ||
1249 | /* Preferences changed, we have to recalculate bandwidth distribution */ | 1324 | /* We sticked to the same address, therefore redistribute */ |
1250 | distribute_bandwidth_in_network (s, NULL, NULL); | 1325 | distribute_bandwidth_in_network (s, asi->network); |
1326 | } | ||
1251 | } | 1327 | } |
1252 | 1328 | ||
1253 | 1329 | ||
@@ -1272,9 +1348,9 @@ GAS_proportional_address_preference_feedback (void *solver, void *application, | |||
1272 | GNUNET_assert(NULL != peer); | 1348 | GNUNET_assert(NULL != peer); |
1273 | 1349 | ||
1274 | GNUNET_assert(NULL != s); | 1350 | GNUNET_assert(NULL != s); |
1275 | GNUNET_break(0); | ||
1276 | } | 1351 | } |
1277 | 1352 | ||
1353 | |||
1278 | /** | 1354 | /** |
1279 | * Get the preferred address for a specific peer | 1355 | * Get the preferred address for a specific peer |
1280 | * | 1356 | * |
@@ -1288,12 +1364,8 @@ GAS_proportional_get_preferred_address (void *solver, | |||
1288 | const struct GNUNET_PeerIdentity *peer) | 1364 | const struct GNUNET_PeerIdentity *peer) |
1289 | { | 1365 | { |
1290 | struct GAS_PROPORTIONAL_Handle *s = solver; | 1366 | struct GAS_PROPORTIONAL_Handle *s = solver; |
1291 | struct Network *net_prev; | 1367 | const struct ATS_Address *best_address; |
1292 | struct Network *net_cur; | 1368 | |
1293 | struct ATS_Address *prev; | ||
1294 | struct ATS_Address *best_address; | ||
1295 | struct AddressSolverInformation *asi; | ||
1296 | struct AddressSolverInformation *asi_prev; | ||
1297 | 1369 | ||
1298 | GNUNET_assert(s != NULL); | 1370 | GNUNET_assert(s != NULL); |
1299 | GNUNET_assert(peer != NULL); | 1371 | GNUNET_assert(peer != NULL); |
@@ -1304,64 +1376,14 @@ GAS_proportional_get_preferred_address (void *solver, | |||
1304 | GNUNET_assert( | 1376 | GNUNET_assert( |
1305 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (s->requests, peer, NULL, | 1377 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (s->requests, peer, NULL, |
1306 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1378 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1379 | LOG (GNUNET_ERROR_TYPE_INFO, "Start suggesting addresses for peer `%s'\n", | ||
1380 | GNUNET_i2s (peer)); | ||
1307 | } | 1381 | } |
1308 | 1382 | ||
1309 | /* Find best address */ | 1383 | best_address = update_active_address (s, peer); |
1310 | best_address = get_best_address (s,s->addresses, peer); | 1384 | if (s->bulk_lock > 0) |
1311 | if (NULL == best_address) | 1385 | return NULL; /* Do not suggest since bulk lock is pending */ |
1312 | { | ||
1313 | LOG (GNUNET_ERROR_TYPE_INFO, "Cannot suggest address for peer `%s'\n", | ||
1314 | GNUNET_i2s (peer)); | ||
1315 | return NULL ; | ||
1316 | } | ||
1317 | |||
1318 | LOG (GNUNET_ERROR_TYPE_INFO, "Suggesting %s address %p for peer `%s'\n", | ||
1319 | (GNUNET_NO == best_address->active) ? "inactive" : "active", best_address, | ||
1320 | GNUNET_i2s (peer)); | ||
1321 | 1386 | ||
1322 | asi = best_address->solver_information; | ||
1323 | net_cur = asi->network ; | ||
1324 | if (GNUNET_YES == best_address->active) | ||
1325 | { | ||
1326 | /* This address was selected previously, so no need to update quotas */ | ||
1327 | return best_address; | ||
1328 | } | ||
1329 | |||
1330 | /* This address was not active, so we have to: | ||
1331 | * | ||
1332 | * - mark previous active address as not active | ||
1333 | * - update quota for previous address network | ||
1334 | * - update quota for this address network | ||
1335 | */ | ||
1336 | prev = get_active_address (s, s->addresses, peer); | ||
1337 | if (NULL != prev) | ||
1338 | { | ||
1339 | asi_prev = prev->solver_information; | ||
1340 | net_prev = asi_prev->network; | ||
1341 | prev->active = GNUNET_NO; /* No active any longer */ | ||
1342 | prev->assigned_bw_in = BANDWIDTH_ZERO; /* no bandwidth assigned */ | ||
1343 | prev->assigned_bw_out = BANDWIDTH_ZERO; /* no bandwidth assigned */ | ||
1344 | |||
1345 | if (GNUNET_SYSERR == addresse_decrement (s, net_prev, GNUNET_NO, GNUNET_YES)) | ||
1346 | GNUNET_break(0); | ||
1347 | |||
1348 | /* Update network of previous address */ | ||
1349 | distribute_bandwidth_in_network (s, net_prev, NULL); | ||
1350 | } | ||
1351 | |||
1352 | if (GNUNET_NO == (is_bandwidth_available_in_network (net_cur))) | ||
1353 | { | ||
1354 | /* This should never happen, because we checked when finding best address */ | ||
1355 | GNUNET_break(0); | ||
1356 | return NULL ; | ||
1357 | } | ||
1358 | |||
1359 | /* Mark address as active */ | ||
1360 | best_address->active = GNUNET_YES; | ||
1361 | addresse_increment (s, net_cur, GNUNET_NO, GNUNET_YES); | ||
1362 | |||
1363 | /* Distribute bandwidth */ | ||
1364 | distribute_bandwidth_in_network (s, net_cur, best_address); | ||
1365 | return best_address; | 1387 | return best_address; |
1366 | } | 1388 | } |
1367 | 1389 | ||
@@ -1395,6 +1417,7 @@ GAS_proportional_stop_get_preferred_address (void *solver, | |||
1395 | /* Disabling current address */ | 1417 | /* Disabling current address */ |
1396 | asi = cur->solver_information; | 1418 | asi = cur->solver_information; |
1397 | cur_net = asi->network ; | 1419 | cur_net = asi->network ; |
1420 | asi->activated = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1398 | cur->active = GNUNET_NO; /* No active any longer */ | 1421 | cur->active = GNUNET_NO; /* No active any longer */ |
1399 | cur->assigned_bw_in = BANDWIDTH_ZERO; /* no bandwidth assigned */ | 1422 | cur->assigned_bw_in = BANDWIDTH_ZERO; /* no bandwidth assigned */ |
1400 | cur->assigned_bw_out = BANDWIDTH_ZERO; /* no bandwidth assigned */ | 1423 | cur->assigned_bw_out = BANDWIDTH_ZERO; /* no bandwidth assigned */ |
@@ -1402,7 +1425,7 @@ GAS_proportional_stop_get_preferred_address (void *solver, | |||
1402 | if (GNUNET_SYSERR == addresse_decrement (s, cur_net, GNUNET_NO, GNUNET_YES)) | 1425 | if (GNUNET_SYSERR == addresse_decrement (s, cur_net, GNUNET_NO, GNUNET_YES)) |
1403 | GNUNET_break(0); | 1426 | GNUNET_break(0); |
1404 | 1427 | ||
1405 | distribute_bandwidth_in_network (s, cur_net, NULL ); | 1428 | distribute_bandwidth_in_network (s, cur_net ); |
1406 | } | 1429 | } |
1407 | return; | 1430 | return; |
1408 | } | 1431 | } |
@@ -1422,8 +1445,6 @@ GAS_proportional_address_delete (void *solver, struct ATS_Address *address, | |||
1422 | struct Network *net; | 1445 | struct Network *net; |
1423 | struct AddressWrapper *aw; | 1446 | struct AddressWrapper *aw; |
1424 | struct AddressSolverInformation *asi; | 1447 | struct AddressSolverInformation *asi; |
1425 | const struct ATS_Address *new_address; | ||
1426 | |||
1427 | 1448 | ||
1428 | /* Remove an adress completely, we have to: | 1449 | /* Remove an adress completely, we have to: |
1429 | * - Remove from specific network | 1450 | * - Remove from specific network |
@@ -1485,18 +1506,18 @@ GAS_proportional_address_delete (void *solver, struct ATS_Address *address, | |||
1485 | 1506 | ||
1486 | if (GNUNET_SYSERR == addresse_decrement (s, net, GNUNET_NO, GNUNET_YES)) | 1507 | if (GNUNET_SYSERR == addresse_decrement (s, net, GNUNET_NO, GNUNET_YES)) |
1487 | GNUNET_break(0); | 1508 | GNUNET_break(0); |
1488 | distribute_bandwidth_in_network (s, net, NULL); | 1509 | distribute_bandwidth_in_network (s, net); |
1489 | 1510 | ||
1490 | if (NULL == (new_address = GAS_proportional_get_preferred_address (s, &address->peer))) | 1511 | if (NULL == update_active_address (s, &address->peer)) |
1491 | { | 1512 | { |
1492 | /* No alternative address found, disconnect peer */ | 1513 | /* No alternative address found, disconnect peer */ |
1514 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1515 | "Disconnecting peer `%s' after deleting previous %s address %p\n", | ||
1516 | GNUNET_i2s (&address->peer), | ||
1517 | (GNUNET_NO == address->active) ? "inactive" : "active", | ||
1518 | address); | ||
1493 | s->bw_changed (s->bw_changed_cls, address); | 1519 | s->bw_changed (s->bw_changed_cls, address); |
1494 | } | 1520 | } |
1495 | else | ||
1496 | { | ||
1497 | /* We found an alternative, notify about it */ | ||
1498 | s->bw_changed (s->bw_changed_cls, (struct ATS_Address *) new_address); | ||
1499 | } | ||
1500 | } | 1521 | } |
1501 | if (GNUNET_NO == session_only) | 1522 | if (GNUNET_NO == session_only) |
1502 | { | 1523 | { |
@@ -1545,8 +1566,8 @@ GAS_proportional_bulk_stop (void *solver) | |||
1545 | s->bulk_lock--; | 1566 | s->bulk_lock--; |
1546 | if ((0 == s->bulk_lock) && (0 < s->bulk_requests)) | 1567 | if ((0 == s->bulk_lock) && (0 < s->bulk_requests)) |
1547 | { | 1568 | { |
1548 | LOG(GNUNET_ERROR_TYPE_DEBUG, "No lock pending, recalculating\n"); | 1569 | LOG(GNUNET_ERROR_TYPE_INFO, "No lock pending, recalculating\n"); |
1549 | distribute_bandwidth_in_network (s, NULL, NULL); | 1570 | distribute_bandwidth_in_network (s, NULL); |
1550 | s->bulk_requests = 0; | 1571 | s->bulk_requests = 0; |
1551 | } | 1572 | } |
1552 | } | 1573 | } |
@@ -1611,23 +1632,16 @@ GAS_proportional_address_property_changed (void *solver, | |||
1611 | 1632 | ||
1612 | /* This peer is requested, find active and best address */ | 1633 | /* This peer is requested, find active and best address */ |
1613 | active_address = get_active_address(s, s->addresses, &address->peer); | 1634 | active_address = get_active_address(s, s->addresses, &address->peer); |
1614 | best_address = (struct ATS_Address *) GAS_proportional_get_preferred_address (s, &address->peer); | 1635 | best_address = (struct ATS_Address *) update_active_address (s, &address->peer); |
1615 | |||
1616 | if (NULL == best_address) | ||
1617 | return; /* No address to suggest */ | ||
1618 | 1636 | ||
1619 | if ((NULL != active_address) && GNUNET_YES == address_eq (active_address, best_address)) | 1637 | if ((NULL != best_address) && ((NULL != active_address) && |
1638 | (GNUNET_YES == address_eq (active_address, best_address)))) | ||
1620 | { | 1639 | { |
1621 | /* We kept the active address, just redistribute */ | 1640 | asi = best_address->solver_information; |
1622 | distribute_bandwidth_in_network (s, n, NULL); | 1641 | GNUNET_assert (NULL != asi); |
1623 | return; | ||
1624 | } | ||
1625 | 1642 | ||
1626 | if ((NULL == active_address) || ((NULL != active_address) && | 1643 | /* We sticked to the same address, therefore redistribute */ |
1627 | (GNUNET_NO == address_eq (active_address, best_address)))) | 1644 | distribute_bandwidth_in_network (s, asi->network); |
1628 | { | ||
1629 | /* We switched active addresses */ | ||
1630 | s->bw_changed (s->bw_changed_cls, (struct ATS_Address *) best_address); | ||
1631 | } | 1645 | } |
1632 | } | 1646 | } |
1633 | 1647 | ||
@@ -1649,7 +1663,6 @@ GAS_proportional_address_session_changed (void *solver, | |||
1649 | struct ATS_Address *best_address; | 1663 | struct ATS_Address *best_address; |
1650 | struct ATS_Address *active_address; | 1664 | struct ATS_Address *active_address; |
1651 | struct AddressSolverInformation *asi; | 1665 | struct AddressSolverInformation *asi; |
1652 | struct Network *net_cur; | ||
1653 | 1666 | ||
1654 | s = (struct GAS_PROPORTIONAL_Handle *) solver; | 1667 | s = (struct GAS_PROPORTIONAL_Handle *) solver; |
1655 | if (cur_session != new_session) | 1668 | if (cur_session != new_session) |
@@ -1669,32 +1682,16 @@ GAS_proportional_address_session_changed (void *solver, | |||
1669 | 1682 | ||
1670 | /* This peer is requested, find active and best address */ | 1683 | /* This peer is requested, find active and best address */ |
1671 | active_address = get_active_address(s, s->addresses, &address->peer); | 1684 | active_address = get_active_address(s, s->addresses, &address->peer); |
1672 | best_address = (struct ATS_Address *) GAS_proportional_get_preferred_address (s, &address->peer); | 1685 | best_address = (struct ATS_Address *) update_active_address (s, &address->peer); |
1673 | 1686 | ||
1674 | asi = active_address->solver_information; | 1687 | if ((NULL != best_address) && ((NULL != active_address) && |
1675 | if (NULL == asi) | 1688 | (GNUNET_YES == address_eq (active_address, best_address)))) |
1676 | { | 1689 | { |
1677 | GNUNET_break (0); | 1690 | asi = best_address->solver_information; |
1678 | return; | 1691 | GNUNET_assert (NULL != asi); |
1679 | } | ||
1680 | |||
1681 | net_cur = asi->network ; | ||
1682 | |||
1683 | if (NULL == best_address) | ||
1684 | return; /* No address to suggest */ | ||
1685 | 1692 | ||
1686 | if ((NULL != active_address) && GNUNET_YES == address_eq (active_address, best_address)) | 1693 | /* We sticked to the same address, therefore redistribute */ |
1687 | { | 1694 | distribute_bandwidth_in_network (s, asi->network); |
1688 | /* We kept the active address, just redistribute */ | ||
1689 | distribute_bandwidth_in_network (s, net_cur, NULL); | ||
1690 | return; | ||
1691 | } | ||
1692 | |||
1693 | if ((NULL == active_address) || ((NULL != active_address) && | ||
1694 | (GNUNET_NO == address_eq (active_address, best_address)))) | ||
1695 | { | ||
1696 | /* We switched active addresses */ | ||
1697 | s->bw_changed (s->bw_changed_cls, (struct ATS_Address *) best_address); | ||
1698 | } | 1695 | } |
1699 | } | 1696 | } |
1700 | 1697 | ||
@@ -1711,8 +1708,51 @@ void | |||
1711 | GAS_proportional_address_inuse_changed (void *solver, | 1708 | GAS_proportional_address_inuse_changed (void *solver, |
1712 | struct ATS_Address *address, int in_use) | 1709 | struct ATS_Address *address, int in_use) |
1713 | { | 1710 | { |
1714 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Usage changed to %s\n", | 1711 | struct GAS_PROPORTIONAL_Handle *s; |
1715 | (GNUNET_YES == in_use) ? "USED" : "UNUSED"); | 1712 | struct Network *n; |
1713 | struct AddressSolverInformation *asi; | ||
1714 | struct ATS_Address *best_address; | ||
1715 | struct ATS_Address *active_address; | ||
1716 | |||
1717 | GNUNET_assert(NULL != solver); | ||
1718 | GNUNET_assert(NULL != address); | ||
1719 | |||
1720 | s = (struct GAS_PROPORTIONAL_Handle *) solver; | ||
1721 | asi = address->solver_information; | ||
1722 | if (NULL == asi) | ||
1723 | { | ||
1724 | GNUNET_break(0); | ||
1725 | return; | ||
1726 | } | ||
1727 | |||
1728 | n = asi->network; | ||
1729 | if (NULL == n) | ||
1730 | { | ||
1731 | GNUNET_break(0); | ||
1732 | return; | ||
1733 | } | ||
1734 | |||
1735 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
1736 | "Usage of peer `%s' address %p changed to %s \n", | ||
1737 | GNUNET_i2s (&address->peer), address, | ||
1738 | (GNUNET_YES == in_use) ? "YES" : "NO"); | ||
1739 | |||
1740 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, &address->peer)) | ||
1741 | return; /* Peer is not requested */ | ||
1742 | |||
1743 | /* This peer is requested, find active and best address */ | ||
1744 | active_address = get_active_address(s, s->addresses, &address->peer); | ||
1745 | best_address = (struct ATS_Address *) update_active_address (s, &address->peer); | ||
1746 | |||
1747 | if ((NULL != best_address) && ((NULL != active_address) && | ||
1748 | (GNUNET_YES == address_eq (active_address, best_address)))) | ||
1749 | { | ||
1750 | asi = best_address->solver_information; | ||
1751 | GNUNET_assert (NULL != asi); | ||
1752 | |||
1753 | /* We sticked to the same address, therefore redistribute */ | ||
1754 | distribute_bandwidth_in_network (s, asi->network); | ||
1755 | } | ||
1716 | } | 1756 | } |
1717 | 1757 | ||
1718 | /** | 1758 | /** |
@@ -1755,6 +1795,10 @@ GAS_proportional_address_change_network (void *solver, | |||
1755 | GNUNET_ATS_print_network_type (current_network), | 1795 | GNUNET_ATS_print_network_type (current_network), |
1756 | GNUNET_ATS_print_network_type (new_network)); | 1796 | GNUNET_ATS_print_network_type (new_network)); |
1757 | 1797 | ||
1798 | |||
1799 | /* Start bulk to prevent disconnect */ | ||
1800 | GAS_proportional_bulk_start(s); | ||
1801 | |||
1758 | save_active = address->active; | 1802 | save_active = address->active; |
1759 | 1803 | ||
1760 | /* Disable and assign no bandwidth */ | 1804 | /* Disable and assign no bandwidth */ |
@@ -1772,41 +1816,26 @@ GAS_proportional_address_change_network (void *solver, | |||
1772 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1816 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1773 | _("Invalid network type `%u' `%s': Disconnect!\n"), new_network, | 1817 | _("Invalid network type `%u' `%s': Disconnect!\n"), new_network, |
1774 | GNUNET_ATS_print_network_type (new_network)); | 1818 | GNUNET_ATS_print_network_type (new_network)); |
1775 | 1819 | s->bw_changed (s->bw_changed_cls, address); | |
1776 | /* Find new address to suggest since no bandwidth in network*/ | 1820 | } |
1777 | if (NULL == GAS_proportional_get_preferred_address (s, &address->peer)) | 1821 | else |
1778 | { | 1822 | { |
1779 | /* No alternative address found, disconnect peer */ | 1823 | /* Add to new network and update*/ |
1780 | s->bw_changed (s->bw_changed_cls, address); | 1824 | GAS_proportional_address_add (solver, address, new_network); |
1781 | } | ||
1782 | return; | ||
1783 | } | 1825 | } |
1826 | GAS_proportional_bulk_stop (s); | ||
1784 | 1827 | ||
1785 | /* Add to new network and update*/ | 1828 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, &address->peer)) |
1786 | asi->network = new_net; | 1829 | return; /* Peer is not requested */ |
1787 | GAS_proportional_address_add (solver, address, new_network); | 1830 | |
1831 | /* Find new address to suggest */ | ||
1788 | if (GNUNET_YES == save_active) | 1832 | if (GNUNET_YES == save_active) |
1789 | { | 1833 | { |
1790 | /* check if bandwidth available in new network */ | 1834 | /* No address available, therefore disconnect */ |
1791 | if (GNUNET_YES == (is_bandwidth_available_in_network (new_net))) | 1835 | if (NULL == update_active_address (s, &address->peer)) |
1792 | { | 1836 | s->bw_changed (s->bw_changed_cls, address); |
1793 | /* Assign bandwidth to updated address */ | ||
1794 | address->active = GNUNET_YES; | ||
1795 | addresse_increment (s, new_net, GNUNET_NO, GNUNET_YES); | ||
1796 | distribute_bandwidth_in_network (solver, new_net, NULL); | ||
1797 | } | ||
1798 | else | ||
1799 | { | ||
1800 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1801 | "Not enough bandwidth in new network, suggesting alternative address ..\n"); | ||
1802 | /* Find new address to suggest since no bandwidth in network*/ | ||
1803 | if (NULL == GAS_proportional_get_preferred_address (s, &address->peer)) | ||
1804 | { | ||
1805 | /* No alternative address found, disconnect peer */ | ||
1806 | s->bw_changed (s->bw_changed_cls, address); | ||
1807 | } | ||
1808 | } | ||
1809 | } | 1837 | } |
1838 | |||
1810 | } | 1839 | } |
1811 | 1840 | ||
1812 | /** | 1841 | /** |
@@ -1824,8 +1853,6 @@ GAS_proportional_address_add (void *solver, struct ATS_Address *address, | |||
1824 | struct Network *net = NULL; | 1853 | struct Network *net = NULL; |
1825 | struct AddressWrapper *aw = NULL; | 1854 | struct AddressWrapper *aw = NULL; |
1826 | struct AddressSolverInformation *asi; | 1855 | struct AddressSolverInformation *asi; |
1827 | struct ATS_Address *best_address; | ||
1828 | struct ATS_Address *active_address; | ||
1829 | 1856 | ||
1830 | GNUNET_assert(NULL != s); | 1857 | GNUNET_assert(NULL != s); |
1831 | net = get_network (s, network); | 1858 | net = get_network (s, network); |
@@ -1860,19 +1887,7 @@ GAS_proportional_address_add (void *solver, struct ATS_Address *address, | |||
1860 | return; /* Peer is not requested */ | 1887 | return; /* Peer is not requested */ |
1861 | 1888 | ||
1862 | /* This peer is requested, find best address */ | 1889 | /* This peer is requested, find best address */ |
1863 | active_address = get_active_address(s, s->addresses, &address->peer); | 1890 | update_active_address (s, &address->peer); |
1864 | best_address = (struct ATS_Address *) GAS_proportional_get_preferred_address (s, &address->peer); | ||
1865 | |||
1866 | if (NULL == best_address) | ||
1867 | return; /* No address to suggest */ | ||
1868 | |||
1869 | if ((NULL == active_address) | ||
1870 | || ((NULL != active_address) | ||
1871 | && (GNUNET_NO == address_eq (active_address, best_address)))) | ||
1872 | { | ||
1873 | /* We now have an active address or the active address changed */ | ||
1874 | s->bw_changed (s->bw_changed_cls, (struct ATS_Address *) best_address); | ||
1875 | } | ||
1876 | } | 1891 | } |
1877 | 1892 | ||
1878 | 1893 | ||
diff --git a/src/ats/test_ats_solver_alternative_after_delete_address.c b/src/ats/test_ats_solver_alternative_after_delete_address.c index a1bb840da..8653d7db7 100644 --- a/src/ats/test_ats_solver_alternative_after_delete_address.c +++ b/src/ats/test_ats_solver_alternative_after_delete_address.c | |||
@@ -223,26 +223,20 @@ address_suggest_cb (void *cls, | |||
223 | return; | 223 | return; |
224 | } | 224 | } |
225 | 225 | ||
226 | if (0 == memcmp (address->address, first_suggestion->address, | 226 | if (0 != memcmp (address->address, first_suggestion->address, |
227 | (first_suggestion->address_length < address->address_length) ? first_suggestion->address_length : address->address_length)) | 227 | (first_suggestion->address_length < address->address_length) ? first_suggestion->address_length : address->address_length)) |
228 | { | 228 | { |
229 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleted 1st address for peer `%s' was suggested after deletion: `%s' `%s'\n", | 229 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received 2nd sugggestion for peer `%s' : `%s'\n", |
230 | GNUNET_i2s (&address->peer), (char *) address->address, first_suggestion->address); | 230 | GNUNET_i2s (&address->peer), (char *) address->address); |
231 | GNUNET_break (0); | 231 | second_suggestion = GNUNET_HELLO_address_copy (address); |
232 | end_badly_now (); | 232 | second_address_suggested = GNUNET_YES; |
233 | |||
234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 2nd address for peer `%s' : `%s'\n", | ||
235 | GNUNET_i2s (&address->peer), (char *) address->address); | ||
236 | GNUNET_ATS_address_destroyed (sched_ats, address, session); | ||
237 | second_address_deleted = GNUNET_YES; | ||
233 | return; | 238 | return; |
234 | } | 239 | } |
235 | |||
236 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received 2nd sugggestion for peer `%s' : `%s'\n", | ||
237 | GNUNET_i2s (&address->peer), (char *) address->address); | ||
238 | second_suggestion = GNUNET_HELLO_address_copy (address); | ||
239 | second_address_suggested = GNUNET_YES; | ||
240 | |||
241 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 2nd address for peer `%s' : `%s'\n", | ||
242 | GNUNET_i2s (&address->peer), (char *) address->address); | ||
243 | GNUNET_ATS_address_destroyed (sched_ats, address, session); | ||
244 | second_address_deleted = GNUNET_YES; | ||
245 | return; | ||
246 | } | 240 | } |
247 | 241 | ||
248 | } | 242 | } |