aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-08 20:55:25 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-08 20:55:25 +0000
commite14164d8be56720436ec4bc736c29443d8513af4 (patch)
treee22e1759edbd5f4bff2c68a624fb9b8fb908e8a2 /src
parent02addaea83c38c80670fe94ab4b021eeb3105de7 (diff)
downloadgnunet-e14164d8be56720436ec4bc736c29443d8513af4.tar.gz
gnunet-e14164d8be56720436ec4bc736c29443d8513af4.zip
-getting there...
Diffstat (limited to 'src')
-rw-r--r--src/ats/plugin_ats_proportional.c55
-rw-r--r--src/ats/test_ats_api_common.c44
-rw-r--r--src/ats/test_ats_solver_alternative_after_delete_address.c16
3 files changed, 63 insertions, 52 deletions
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c
index be50c4393..4833fe764 100644
--- a/src/ats/plugin_ats_proportional.c
+++ b/src/ats/plugin_ats_proportional.c
@@ -917,29 +917,23 @@ get_active_address (struct GAS_PROPORTIONAL_Handle *s,
917 * are different switch 917 * are different switch
918 * 918 *
919 * @param s solver handle 919 * @param s solver handle
920 * @param current_address the address currently active for the peer,
921 * NULL for none
920 * @param peer the peer to check 922 * @param peer the peer to check
921 * return the new address or NULL if no update was performed 923 * return the new address or NULL if no update was performed
922 */ 924 */
923static struct ATS_Address * 925static struct ATS_Address *
924update_active_address (struct GAS_PROPORTIONAL_Handle *s, 926update_active_address (struct GAS_PROPORTIONAL_Handle *s,
927 struct ATS_Address *current_address,
925 const struct GNUNET_PeerIdentity *peer) 928 const struct GNUNET_PeerIdentity *peer)
926{ 929{
927 struct ATS_Address *best_address; 930 struct ATS_Address *best_address;
928 struct ATS_Address *current_address;
929 struct AddressWrapper *asi; 931 struct AddressWrapper *asi;
930 struct Network *net; 932 struct Network *net;
931 933
932 current_address = get_active_address (s,
933 peer);
934 best_address = get_best_address (s, 934 best_address = get_best_address (s,
935 s->env->addresses, 935 s->env->addresses,
936 peer); 936 peer);
937 LOG (GNUNET_ERROR_TYPE_INFO,
938 "Peer `%s' has active address %p and best address %p\n",
939 GNUNET_i2s (peer),
940 current_address,
941 best_address);
942
943 if (NULL != current_address) 937 if (NULL != current_address)
944 { 938 {
945 GNUNET_assert (GNUNET_YES == current_address->active); 939 GNUNET_assert (GNUNET_YES == current_address->active);
@@ -950,9 +944,7 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
950 /* We switch to a new address (or to none), 944 /* We switch to a new address (or to none),
951 mark old address as inactive */ 945 mark old address as inactive */
952 LOG (GNUNET_ERROR_TYPE_INFO, 946 LOG (GNUNET_ERROR_TYPE_INFO,
953 "Disabling previous %s address %p for peer `%s'\n", 947 "Disabling previous active address for peer `%s'\n",
954 (GNUNET_NO == current_address->active) ? "inactive" : "active",
955 current_address,
956 GNUNET_i2s (peer)); 948 GNUNET_i2s (peer));
957 949
958 asi = current_address->solver_information; 950 asi = current_address->solver_information;
@@ -997,7 +989,6 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
997 } 989 }
998 990
999 asi = best_address->solver_information; 991 asi = best_address->solver_information;
1000 GNUNET_assert (NULL != asi);
1001 net = asi->network; 992 net = asi->network;
1002 993
1003 /* Mark address as active */ 994 /* Mark address as active */
@@ -1019,7 +1010,8 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
1019 best_address, 1010 best_address,
1020 GNUNET_i2s (peer)); 1011 GNUNET_i2s (peer));
1021 /* Distribute bandwidth */ 1012 /* Distribute bandwidth */
1022 distribute_bandwidth_in_network (s, net); 1013 distribute_bandwidth_in_network (s,
1014 net);
1023 return best_address; 1015 return best_address;
1024} 1016}
1025 1017
@@ -1082,6 +1074,8 @@ GAS_proportional_get_preferred_address (void *solver,
1082 struct AddressWrapper *asi; 1074 struct AddressWrapper *asi;
1083 1075
1084 best_address = update_active_address (s, 1076 best_address = update_active_address (s,
1077 get_active_address (s,
1078 peer),
1085 peer); 1079 peer);
1086 if (NULL == best_address) 1080 if (NULL == best_address)
1087 return; 1081 return;
@@ -1152,11 +1146,13 @@ GAS_proportional_bulk_stop (void *solver)
1152 return; 1146 return;
1153 } 1147 }
1154 s->bulk_lock--; 1148 s->bulk_lock--;
1155 if ((0 == s->bulk_lock) && (0 < s->bulk_requests)) 1149 if ( (0 == s->bulk_lock) &&
1150 (0 < s->bulk_requests) )
1156 { 1151 {
1157 LOG (GNUNET_ERROR_TYPE_INFO, 1152 LOG (GNUNET_ERROR_TYPE_INFO,
1158 "No lock pending, recalculating\n"); 1153 "No lock pending, recalculating\n");
1159 distribute_bandwidth_in_network (s, NULL); 1154 distribute_bandwidth_in_network (s,
1155 NULL);
1160 s->bulk_requests = 0; 1156 s->bulk_requests = 0;
1161 } 1157 }
1162} 1158}
@@ -1222,21 +1218,24 @@ GAS_proportional_address_add (void *solver,
1222 1, 1218 1,
1223 GNUNET_NO); 1219 GNUNET_NO);
1224 1220
1221 if (0 !=
1222 s->env->get_connectivity (s->env->cls,
1223 &address->peer))
1224 {
1225 /* This peer is requested, find best address */
1226 update_active_address (s,
1227 get_active_address (s,
1228 &address->peer),
1229 &address->peer);
1230 }
1225 LOG (GNUNET_ERROR_TYPE_INFO, 1231 LOG (GNUNET_ERROR_TYPE_INFO,
1226 "Added new address for `%s', now total %u and active %u addresses in network `%s'\n", 1232 "Added new address for `%s', now total %u and active %u addresses in network `%s'\n",
1227 GNUNET_i2s (&address->peer), 1233 GNUNET_i2s (&address->peer),
1228 net->total_addresses, 1234 net->total_addresses,
1229 net->active_addresses, 1235 net->active_addresses,
1230 net->desc); 1236 net->desc);
1231 1237
1232 if (0 ==
1233 s->env->get_connectivity (s->env->cls,
1234 &address->peer))
1235 return; /* Peer is not requested */
1236 1238
1237 /* This peer is requested, find best address */
1238 update_active_address (s,
1239 &address->peer);
1240} 1239}
1241 1240
1242 1241
@@ -1279,16 +1278,11 @@ GAS_proportional_address_delete (void *solver,
1279 if (GNUNET_YES == address->active) 1278 if (GNUNET_YES == address->active)
1280 { 1279 {
1281 /* Address was active, remove from network and update quotas*/ 1280 /* Address was active, remove from network and update quotas*/
1282 address->active = GNUNET_NO;
1283 address->assigned_bw_in = 0; 1281 address->assigned_bw_in = 0;
1284 address->assigned_bw_out = 0; 1282 address->assigned_bw_out = 0;
1285 address_decrement_active (s, net);
1286 /* FIXME: this may trigger the solver unnecessarily,
1287 especially if update_active_address() succeeds! */
1288 distribute_bandwidth_in_network (s, net);
1289
1290 if (NULL == 1283 if (NULL ==
1291 update_active_address (s, 1284 update_active_address (s,
1285 address,
1292 &address->peer)) 1286 &address->peer))
1293 { 1287 {
1294 /* No alternative address found, disconnect peer */ 1288 /* No alternative address found, disconnect peer */
@@ -1299,6 +1293,7 @@ GAS_proportional_address_delete (void *solver,
1299 s->env->bandwidth_changed_cb (s->env->cls, 1293 s->env->bandwidth_changed_cb (s->env->cls,
1300 address); 1294 address);
1301 } 1295 }
1296 distribute_bandwidth_in_network (s, net);
1302 } 1297 }
1303 GNUNET_free (aw); 1298 GNUNET_free (aw);
1304 address->solver_information = NULL; 1299 address->solver_information = NULL;
diff --git a/src/ats/test_ats_api_common.c b/src/ats/test_ats_api_common.c
index 5b3af3b9a..2bfebaa6d 100644
--- a/src/ats/test_ats_api_common.c
+++ b/src/ats/test_ats_api_common.c
@@ -44,6 +44,7 @@ create_test_address (struct Test_Address *dest, char * plugin, void *session, vo
44 dest->addr_len = addrlen; 44 dest->addr_len = addrlen;
45} 45}
46 46
47
47void 48void
48free_test_address (struct Test_Address *dest) 49free_test_address (struct Test_Address *dest)
49{ 50{
@@ -53,37 +54,46 @@ free_test_address (struct Test_Address *dest)
53 dest->addr = NULL; 54 dest->addr = NULL;
54} 55}
55 56
57
56int 58int
57compare_addresses (const struct GNUNET_HELLO_Address *address1, void *session1, 59compare_addresses (const struct GNUNET_HELLO_Address *address1,
58 const struct GNUNET_HELLO_Address *address2, void *session2) 60 void *session1,
61 const struct GNUNET_HELLO_Address *address2,
62 void *session2)
59{ 63{
60 if (0 != memcmp (&address1->peer, &address2->peer, sizeof (struct GNUNET_PeerIdentity))) 64 if (0 !=
65 memcmp (&address1->peer,
66 &address2->peer,
67 sizeof (struct GNUNET_PeerIdentity)))
61 { 68 {
62 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid peer id'\n"); 69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
63 return GNUNET_SYSERR; 70 "Suggestion with invalid peer id'\n");
71 return GNUNET_SYSERR;
64 } 72 }
65 if (0 != strcmp (address1->transport_name, address2->transport_name)) 73 if (0 != strcmp (address1->transport_name, address2->transport_name))
66 { 74 {
67 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid plugin'\n"); 75 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
68 return GNUNET_SYSERR; 76 "Suggestion with invalid plugin'\n");
77 return GNUNET_SYSERR;
69 } 78 }
70 if (address1->address_length != address2->address_length) 79 if (address1->address_length != address2->address_length)
71 { 80 {
72 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address length\n"); 81 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
73 return GNUNET_SYSERR; 82 "Suggestion with invalid address length\n");
74 83 return GNUNET_SYSERR;
75 } 84 }
76 else if (0 != memcmp (address1->address, address2->address, address2->address_length)) 85 if (0 != memcmp (address1->address, address2->address, address2->address_length))
77 { 86 {
78 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address\n"); 87 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
79 return GNUNET_SYSERR; 88 "Suggestion with invalid address\n");
89 return GNUNET_SYSERR;
80 } 90 }
81 if (session1 != session2) 91 if (session1 != session2)
82 { 92 {
83 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid session1 %p vs session2 %p'\n", 93 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
84 session1, session2); 94 "Suggestion with invalid session1 %p vs session2 %p'\n",
85 return GNUNET_SYSERR; 95 session1, session2);
86 96 return GNUNET_SYSERR;
87 } 97 }
88 return GNUNET_OK; 98 return GNUNET_OK;
89} 99}
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 fcaf0db70..77c903f1c 100644
--- a/src/ats/test_ats_solver_alternative_after_delete_address.c
+++ b/src/ats/test_ats_solver_alternative_after_delete_address.c
@@ -145,17 +145,20 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
145 GNUNET_ATS_scheduling_done (sched_ats); 145 GNUNET_ATS_scheduling_done (sched_ats);
146 sched_ats = NULL; 146 sched_ats = NULL;
147 } 147 }
148 148 GNUNET_STATISTICS_watch_cancel (stats,
149 GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); 149 "ats",
150 "# addresses",
151 &stat_cb, NULL);
150 if (NULL != stats) 152 if (NULL != stats)
151 { 153 {
152 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 154 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
153 stats = NULL; 155 stats = NULL;
154 } 156 }
155
156 free_test_address (&test_addr); 157 free_test_address (&test_addr);
157 GNUNET_free_non_null (first_suggestion); 158 GNUNET_free_non_null (first_suggestion);
159 first_suggestion = NULL;
158 GNUNET_free_non_null (second_suggestion); 160 GNUNET_free_non_null (second_suggestion);
161 second_suggestion = NULL;
159 ret = 0; 162 ret = 0;
160} 163}
161 164
@@ -253,8 +256,11 @@ address_suggest_cb (void *cls,
253 return; 256 return;
254 } 257 }
255 258
256 if (0 != memcmp (address->address, first_suggestion->address, 259 if (0 !=
257 (first_suggestion->address_length < address->address_length) ? first_suggestion->address_length : address->address_length)) 260 memcmp (address->address,
261 first_suggestion->address,
262 (first_suggestion->address_length < address->address_length)
263 ? first_suggestion->address_length : address->address_length))
258 { 264 {
259 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 265 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
260 "Received 2nd sugggestion for peer `%s' : `%s'\n", 266 "Received 2nd sugggestion for peer `%s' : `%s'\n",