diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-08 21:48:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-08 21:48:01 +0000 |
commit | 8913155539cdac83e11f126498f589db7b51bda7 (patch) | |
tree | 0b0ab5be26a6bdeb68e8572d2d33756f261015ee /src | |
parent | 9a306b5be81c1595dab61579897fe83dfc584ebf (diff) | |
download | gnunet-8913155539cdac83e11f126498f589db7b51bda7.tar.gz gnunet-8913155539cdac83e11f126498f589db7b51bda7.zip |
-further simplify
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/plugin_ats_proportional.c | 181 |
1 files changed, 70 insertions, 111 deletions
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index 3496b8eed..dd6acabfb 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c | |||
@@ -372,9 +372,9 @@ struct GAS_PROPORTIONAL_Handle | |||
372 | 372 | ||
373 | 373 | ||
374 | /** | 374 | /** |
375 | * Test if bandwidth is available in this network to add an additional address | 375 | * Test if bandwidth is available in this network to add an additional address. |
376 | * | 376 | * |
377 | * @param net the network type to update | 377 | * @param net the network type to check |
378 | * @return #GNUNET_YES or #GNUNET_NO | 378 | * @return #GNUNET_YES or #GNUNET_NO |
379 | */ | 379 | */ |
380 | static int | 380 | static int |
@@ -385,18 +385,7 @@ is_bandwidth_available_in_network (struct Network *net) | |||
385 | 385 | ||
386 | if ( ((net->total_quota_in / na) > min_bw) && | 386 | if ( ((net->total_quota_in / na) > min_bw) && |
387 | ((net->total_quota_out / na) > min_bw) ) | 387 | ((net->total_quota_out / na) > min_bw) ) |
388 | { | ||
389 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
390 | "Enough bandwidth available for %u active addresses in network `%s'\n", | ||
391 | na, | ||
392 | net->desc); | ||
393 | |||
394 | return GNUNET_YES; | 388 | return GNUNET_YES; |
395 | } | ||
396 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
397 | "Not enough bandwidth available for %u active addresses in network `%s'\n", | ||
398 | na, | ||
399 | net->desc); | ||
400 | return GNUNET_NO; | 389 | return GNUNET_NO; |
401 | } | 390 | } |
402 | 391 | ||
@@ -591,16 +580,6 @@ propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | |||
591 | continue; | 580 | continue; |
592 | cur->addr->assigned_bw_in = cur->calculated_quota_in; | 581 | cur->addr->assigned_bw_in = cur->calculated_quota_in; |
593 | cur->addr->assigned_bw_out = cur->calculated_quota_out; | 582 | cur->addr->assigned_bw_out = cur->calculated_quota_out; |
594 | |||
595 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
596 | "Bandwidth for %s address %p for peer `%s' changed to %u/%u\n", | ||
597 | (GNUNET_NO == cur->addr->active) ? "inactive" : "active", | ||
598 | cur->addr, | ||
599 | GNUNET_i2s (&cur->addr->peer), | ||
600 | cur->addr->assigned_bw_in, | ||
601 | cur->addr->assigned_bw_out); | ||
602 | |||
603 | /* Notify on change */ | ||
604 | if (GNUNET_YES == cur->addr->active) | 583 | if (GNUNET_YES == cur->addr->active) |
605 | s->env->bandwidth_changed_cb (s->env->cls, | 584 | s->env->bandwidth_changed_cb (s->env->cls, |
606 | cur->addr); | 585 | cur->addr); |
@@ -912,107 +891,99 @@ get_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
912 | 891 | ||
913 | 892 | ||
914 | /** | 893 | /** |
915 | * Update active address for a peer: | 894 | * Update active address for a peer. Check if active address exists |
916 | * Check if active address exists and what the best address is, if addresses | 895 | * and what the best address is, if addresses are different switch. |
917 | * are different switch | 896 | * Then reallocate bandwidth within the affected network scopes. |
918 | * | 897 | * |
919 | * @param s solver handle | 898 | * @param s solver handle |
920 | * @param current_address the address currently active for the peer, | 899 | * @param current_address the address currently active for the peer, |
921 | * NULL for none | 900 | * NULL for none |
922 | * @param peer the peer to check | 901 | * @param peer the peer to check |
923 | * return the new address or NULL if no update was performed | 902 | */ |
924 | */ | 903 | static void |
925 | static struct ATS_Address * | ||
926 | update_active_address (struct GAS_PROPORTIONAL_Handle *s, | 904 | update_active_address (struct GAS_PROPORTIONAL_Handle *s, |
927 | struct ATS_Address *current_address, | 905 | struct ATS_Address *current_address, |
928 | const struct GNUNET_PeerIdentity *peer) | 906 | const struct GNUNET_PeerIdentity *peer) |
929 | { | 907 | { |
930 | struct ATS_Address *best_address; | 908 | struct ATS_Address *best_address; |
931 | struct AddressWrapper *asi; | 909 | struct AddressWrapper *asi_cur; |
932 | struct Network *net; | 910 | struct AddressWrapper *asi_best; |
933 | 911 | ||
934 | best_address = get_best_address (s, | 912 | best_address = get_best_address (s, |
935 | s->env->addresses, | 913 | s->env->addresses, |
936 | peer); | 914 | peer); |
915 | if (NULL != best_address) | ||
916 | asi_best = best_address->solver_information; | ||
917 | else | ||
918 | asi_best = NULL; | ||
919 | if (current_address == best_address) | ||
920 | return; /* no changes */ | ||
937 | if (NULL != current_address) | 921 | if (NULL != current_address) |
938 | { | 922 | { |
923 | /* We switch to a new address (or to none); | ||
924 | mark old address as inactive. */ | ||
925 | asi_cur = current_address->solver_information; | ||
939 | GNUNET_assert (GNUNET_YES == current_address->active); | 926 | GNUNET_assert (GNUNET_YES == current_address->active); |
927 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
928 | "Disabling previous active address for peer `%s'\n", | ||
929 | GNUNET_i2s (peer)); | ||
930 | asi_cur->activated = GNUNET_TIME_UNIT_ZERO_ABS; | ||
931 | current_address->active = GNUNET_NO; | ||
932 | current_address->assigned_bw_in = 0; | ||
933 | current_address->assigned_bw_out = 0; | ||
934 | address_decrement_active (s, | ||
935 | asi_cur->network); | ||
940 | if ( (NULL == best_address) || | 936 | if ( (NULL == best_address) || |
941 | ( (NULL != best_address) && | 937 | (asi_best->network != asi_cur->network) ) |
942 | (current_address != best_address) ) ) | 938 | distribute_bandwidth_in_network (s, |
943 | { | 939 | asi_cur->network); |
944 | /* We switch to a new address (or to none), | ||
945 | mark old address as inactive */ | ||
946 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
947 | "Disabling previous active address for peer `%s'\n", | ||
948 | GNUNET_i2s (peer)); | ||
949 | |||
950 | asi = current_address->solver_information; | ||
951 | net = asi->network; | ||
952 | asi->activated = GNUNET_TIME_UNIT_ZERO_ABS; | ||
953 | current_address->active = GNUNET_NO; /* No active any longer */ | ||
954 | current_address->assigned_bw_in = 0; /* no bandwidth assigned */ | ||
955 | current_address->assigned_bw_out = 0; /* no bandwidth assigned */ | ||
956 | address_decrement_active (s, net); | ||
957 | distribute_bandwidth_in_network (s, net); | ||
958 | } | ||
959 | if (NULL == best_address) | 940 | if (NULL == best_address) |
960 | { | 941 | { |
961 | /* We previously had an active address, but now we cannot suggest one | 942 | /* We previously had an active address, but now we cannot |
962 | * Therefore we have to disconnect the peer */ | 943 | * suggest one. Therefore we have to disconnect the peer. |
963 | LOG (GNUNET_ERROR_TYPE_INFO, | 944 | * The above call to "distribute_bandwidth_in_network() |
964 | "Disconnecting peer `%s' with previous address %p\n", | 945 | * does not see 'current_address' so we need to trigger |
965 | GNUNET_i2s (peer), | 946 | * the update here. */ |
966 | current_address); | 947 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
948 | "Disconnecting peer `%s'.\n", | ||
949 | GNUNET_i2s (peer)); | ||
967 | s->env->bandwidth_changed_cb (s->env->cls, | 950 | s->env->bandwidth_changed_cb (s->env->cls, |
968 | current_address); | 951 | current_address); |
952 | return; | ||
969 | } | 953 | } |
970 | } | 954 | } |
971 | if (NULL == best_address) | 955 | if (NULL == best_address) |
972 | { | 956 | { |
973 | LOG (GNUNET_ERROR_TYPE_INFO, | 957 | /* We do not have a new address, so we are done. */ |
958 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
974 | "Cannot suggest address for peer `%s'\n", | 959 | "Cannot suggest address for peer `%s'\n", |
975 | GNUNET_i2s (peer)); | 960 | GNUNET_i2s (peer)); |
976 | return NULL; | 961 | return; |
977 | } | 962 | } |
978 | 963 | /* We do have a new address, activate it */ | |
979 | LOG (GNUNET_ERROR_TYPE_INFO, | 964 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
980 | "Suggesting new address %p for peer `%s'\n", | 965 | "Suggesting new address %p for peer `%s'\n", |
981 | best_address, | 966 | best_address, |
982 | GNUNET_i2s (peer)); | 967 | GNUNET_i2s (peer)); |
983 | |||
984 | if ( (NULL != current_address) && | ||
985 | (best_address == current_address) ) | ||
986 | { | ||
987 | GNUNET_break (GNUNET_NO != current_address->active); | ||
988 | return best_address; /* Same same */ | ||
989 | } | ||
990 | |||
991 | asi = best_address->solver_information; | ||
992 | net = asi->network; | ||
993 | |||
994 | /* Mark address as active */ | 968 | /* Mark address as active */ |
995 | asi->activated = GNUNET_TIME_absolute_get (); | ||
996 | best_address->active = GNUNET_YES; | 969 | best_address->active = GNUNET_YES; |
997 | 970 | asi_best->activated = GNUNET_TIME_absolute_get (); | |
998 | net->active_addresses++; | 971 | asi_best->network->active_addresses++; |
999 | s->active_addresses++; | 972 | s->active_addresses++; |
1000 | GNUNET_STATISTICS_update (s->env->stats, | 973 | GNUNET_STATISTICS_update (s->env->stats, |
1001 | "# ATS active addresses total", | 974 | "# ATS active addresses total", |
1002 | 1, | 975 | 1, |
1003 | GNUNET_NO); | 976 | GNUNET_NO); |
1004 | GNUNET_STATISTICS_update (s->env->stats, | 977 | GNUNET_STATISTICS_update (s->env->stats, |
1005 | net->stat_active, | 978 | asi_best->network->stat_active, |
1006 | 1, | 979 | 1, |
1007 | GNUNET_NO); | 980 | GNUNET_NO); |
1008 | LOG (GNUNET_ERROR_TYPE_INFO, | 981 | LOG (GNUNET_ERROR_TYPE_INFO, |
1009 | "Address %p for peer `%s' is now active\n", | 982 | "Address %p for peer `%s' is now active\n", |
1010 | best_address, | 983 | best_address, |
1011 | GNUNET_i2s (peer)); | 984 | GNUNET_i2s (peer)); |
1012 | /* Distribute bandwidth */ | ||
1013 | distribute_bandwidth_in_network (s, | 985 | distribute_bandwidth_in_network (s, |
1014 | net); | 986 | asi_best->network); |
1015 | return best_address; | ||
1016 | } | 987 | } |
1017 | 988 | ||
1018 | 989 | ||
@@ -1025,10 +996,10 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
1025 | * @param pref_rel the normalized preference value for this kind over all clients | 996 | * @param pref_rel the normalized preference value for this kind over all clients |
1026 | */ | 997 | */ |
1027 | static void | 998 | static void |
1028 | GAS_proportional_address_change_preference (void *solver, | 999 | GAS_proportional_change_preference (void *solver, |
1029 | const struct GNUNET_PeerIdentity *peer, | 1000 | const struct GNUNET_PeerIdentity *peer, |
1030 | enum GNUNET_ATS_PreferenceKind kind, | 1001 | enum GNUNET_ATS_PreferenceKind kind, |
1031 | double pref_rel) | 1002 | double pref_rel) |
1032 | { | 1003 | { |
1033 | struct GAS_PROPORTIONAL_Handle *s = solver; | 1004 | struct GAS_PROPORTIONAL_Handle *s = solver; |
1034 | 1005 | ||
@@ -1048,12 +1019,12 @@ GAS_proportional_address_change_preference (void *solver, | |||
1048 | * @param score the score | 1019 | * @param score the score |
1049 | */ | 1020 | */ |
1050 | static void | 1021 | static void |
1051 | GAS_proportional_address_preference_feedback (void *solver, | 1022 | GAS_proportional_feedback (void *solver, |
1052 | struct GNUNET_SERVER_Client *application, | 1023 | struct GNUNET_SERVER_Client *application, |
1053 | const struct GNUNET_PeerIdentity *peer, | 1024 | const struct GNUNET_PeerIdentity *peer, |
1054 | const struct GNUNET_TIME_Relative scope, | 1025 | const struct GNUNET_TIME_Relative scope, |
1055 | enum GNUNET_ATS_PreferenceKind kind, | 1026 | enum GNUNET_ATS_PreferenceKind kind, |
1056 | double score) | 1027 | double score) |
1057 | { | 1028 | { |
1058 | /* Proportional does not care about feedback */ | 1029 | /* Proportional does not care about feedback */ |
1059 | } | 1030 | } |
@@ -1066,24 +1037,15 @@ GAS_proportional_address_preference_feedback (void *solver, | |||
1066 | * @param peer the identity of the peer | 1037 | * @param peer the identity of the peer |
1067 | */ | 1038 | */ |
1068 | static void | 1039 | static void |
1069 | GAS_proportional_get_preferred_address (void *solver, | 1040 | GAS_proportional_start_get_address (void *solver, |
1070 | const struct GNUNET_PeerIdentity *peer) | 1041 | const struct GNUNET_PeerIdentity *peer) |
1071 | { | 1042 | { |
1072 | struct GAS_PROPORTIONAL_Handle *s = solver; | 1043 | struct GAS_PROPORTIONAL_Handle *s = solver; |
1073 | struct ATS_Address *best_address; | ||
1074 | struct AddressWrapper *asi; | ||
1075 | 1044 | ||
1076 | best_address = update_active_address (s, | 1045 | update_active_address (s, |
1077 | get_active_address (s, | 1046 | get_active_address (s, |
1078 | peer), | 1047 | peer), |
1079 | peer); | 1048 | peer); |
1080 | if (NULL == best_address) | ||
1081 | return; | ||
1082 | if (s->bulk_lock > 0) | ||
1083 | return; | ||
1084 | asi = best_address->solver_information; | ||
1085 | distribute_bandwidth_in_network (s, | ||
1086 | asi->network); | ||
1087 | } | 1049 | } |
1088 | 1050 | ||
1089 | 1051 | ||
@@ -1094,8 +1056,8 @@ GAS_proportional_get_preferred_address (void *solver, | |||
1094 | * @param peer the peer | 1056 | * @param peer the peer |
1095 | */ | 1057 | */ |
1096 | static void | 1058 | static void |
1097 | GAS_proportional_stop_get_preferred_address (void *solver, | 1059 | GAS_proportional_stop_get_address (void *solver, |
1098 | const struct GNUNET_PeerIdentity *peer) | 1060 | const struct GNUNET_PeerIdentity *peer) |
1099 | { | 1061 | { |
1100 | struct GAS_PROPORTIONAL_Handle *s = solver; | 1062 | struct GAS_PROPORTIONAL_Handle *s = solver; |
1101 | struct ATS_Address *cur; | 1063 | struct ATS_Address *cur; |
@@ -1217,7 +1179,6 @@ GAS_proportional_address_add (void *solver, | |||
1217 | net->stat_total, | 1179 | net->stat_total, |
1218 | 1, | 1180 | 1, |
1219 | GNUNET_NO); | 1181 | GNUNET_NO); |
1220 | |||
1221 | if (0 != | 1182 | if (0 != |
1222 | s->env->get_connectivity (s->env->cls, | 1183 | s->env->get_connectivity (s->env->cls, |
1223 | &address->peer)) | 1184 | &address->peer)) |
@@ -1234,8 +1195,6 @@ GAS_proportional_address_add (void *solver, | |||
1234 | net->total_addresses, | 1195 | net->total_addresses, |
1235 | net->active_addresses, | 1196 | net->active_addresses, |
1236 | net->desc); | 1197 | net->desc); |
1237 | |||
1238 | |||
1239 | } | 1198 | } |
1240 | 1199 | ||
1241 | 1200 | ||
@@ -1315,10 +1274,10 @@ libgnunet_plugin_ats_proportional_init (void *cls) | |||
1315 | sf.cls = s; | 1274 | sf.cls = s; |
1316 | sf.s_add = &GAS_proportional_address_add; | 1275 | sf.s_add = &GAS_proportional_address_add; |
1317 | sf.s_address_update_property = &GAS_proportional_address_property_changed; | 1276 | sf.s_address_update_property = &GAS_proportional_address_property_changed; |
1318 | sf.s_get = &GAS_proportional_get_preferred_address; | 1277 | sf.s_get = &GAS_proportional_start_get_address; |
1319 | sf.s_get_stop = &GAS_proportional_stop_get_preferred_address; | 1278 | sf.s_get_stop = &GAS_proportional_stop_get_address; |
1320 | sf.s_pref = &GAS_proportional_address_change_preference; | 1279 | sf.s_pref = &GAS_proportional_change_preference; |
1321 | sf.s_feedback = &GAS_proportional_address_preference_feedback; | 1280 | sf.s_feedback = &GAS_proportional_feedback; |
1322 | sf.s_del = &GAS_proportional_address_delete; | 1281 | sf.s_del = &GAS_proportional_address_delete; |
1323 | sf.s_bulk_start = &GAS_proportional_bulk_start; | 1282 | sf.s_bulk_start = &GAS_proportional_bulk_start; |
1324 | sf.s_bulk_stop = &GAS_proportional_bulk_stop; | 1283 | sf.s_bulk_stop = &GAS_proportional_bulk_stop; |