diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-05 00:53:22 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-05 00:53:22 +0000 |
commit | 15dd8e6cc1199d611d804853e134882bf13b234a (patch) | |
tree | 7cc90886eabe8d0ffa397a319e12a87042d0ba28 /src/ats/plugin_ats_proportional.c | |
parent | bf6a2c9deeff7a3b384eb029d8267d6099066df3 (diff) | |
download | gnunet-15dd8e6cc1199d611d804853e134882bf13b234a.tar.gz gnunet-15dd8e6cc1199d611d804853e134882bf13b234a.zip |
Various changes:
- removed "in_use" from being passed to ATS, no
longer needed as we tell ATS when we cannot
follow a suggestion by removing the address;
simplifies the code a lot
- better handling of state machine, fallback to
primary session if address switch to new
session timed out
- nicer logging
- more comments
- new testcase failures, because of
#3652, #3651 and #3650 (or more that i missed).
Diffstat (limited to 'src/ats/plugin_ats_proportional.c')
-rw-r--r-- | src/ats/plugin_ats_proportional.c | 301 |
1 files changed, 130 insertions, 171 deletions
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index 64dca90c5..7bcc948b7 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c | |||
@@ -50,7 +50,7 @@ | |||
50 | * outbound quota is configured and the bandwidth available in | 50 | * outbound quota is configured and the bandwidth available in |
51 | * these networks is distributed over the addresses. The solver | 51 | * these networks is distributed over the addresses. The solver |
52 | * first assigns every addresses the minimum amount of bandwidth | 52 | * first assigns every addresses the minimum amount of bandwidth |
53 | * GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT and then distributes the | 53 | * #GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT and then distributes the |
54 | * remaining bandwidth available according to the preference | 54 | * remaining bandwidth available according to the preference |
55 | * values. For each peer only a single address gets bandwidth | 55 | * values. For each peer only a single address gets bandwidth |
56 | * assigned and only one address marked as active. The most | 56 | * assigned and only one address marked as active. The most |
@@ -104,7 +104,7 @@ | |||
104 | * solver is when an address switches network it is located | 104 | * solver is when an address switches network it is located |
105 | * in. This is common because addresses added by transport's | 105 | * in. This is common because addresses added by transport's |
106 | * validation mechanism are commonly located in | 106 | * validation mechanism are commonly located in |
107 | * GNUNET_ATS_NET_UNSPECIFIED. Addresses in validation are located | 107 | * #GNUNET_ATS_NET_UNSPECIFIED. Addresses in validation are located |
108 | * in this network type and only if a connection is successful on | 108 | * in this network type and only if a connection is successful on |
109 | * return of payload data transport switches to the real network | 109 | * return of payload data transport switches to the real network |
110 | * the address is located in. When an address changes networks it | 110 | * the address is located in. When an address changes networks it |
@@ -155,9 +155,9 @@ | |||
155 | * the best available address. Several checks are done when an | 155 | * the best available address. Several checks are done when an |
156 | * address is selected. First if this address is currently blocked | 156 | * address is selected. First if this address is currently blocked |
157 | * by addresses from being suggested. An address is blocked for the | 157 | * by addresses from being suggested. An address is blocked for the |
158 | * duration of ATS_BLOCKING_DELTA when it is suggested to | 158 | * duration of #ATS_BLOCKING_DELTA when it is suggested to |
159 | * transport. Next it is checked if at least | 159 | * transport. Next it is checked if at least |
160 | * GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT bytes bandwidth is available | 160 | * #GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT bytes bandwidth is available |
161 | * in the addresse's network, because suggesting an address without | 161 | * in the addresse's network, because suggesting an address without |
162 | * bandwidth does not make sense. This also ensures that all active | 162 | * bandwidth does not make sense. This also ensures that all active |
163 | * addresses in this network get at least the minimum amount of | 163 | * addresses in this network get at least the minimum amount of |
@@ -322,13 +322,11 @@ struct Network | |||
322 | 322 | ||
323 | /** | 323 | /** |
324 | * Total inbound quota | 324 | * Total inbound quota |
325 | * | ||
326 | */ | 325 | */ |
327 | unsigned long long total_quota_in; | 326 | unsigned long long total_quota_in; |
328 | 327 | ||
329 | /** | 328 | /** |
330 | * Total outbound quota | 329 | * Total outbound quota |
331 | * | ||
332 | */ | 330 | */ |
333 | unsigned long long total_quota_out; | 331 | unsigned long long total_quota_out; |
334 | 332 | ||
@@ -375,13 +373,11 @@ struct AddressSolverInformation | |||
375 | 373 | ||
376 | /** | 374 | /** |
377 | * Inbound quota | 375 | * Inbound quota |
378 | * | ||
379 | */ | 376 | */ |
380 | uint32_t calculated_quota_in; | 377 | uint32_t calculated_quota_in; |
381 | 378 | ||
382 | /** | 379 | /** |
383 | * Outbound quota | 380 | * Outbound quota |
384 | * | ||
385 | */ | 381 | */ |
386 | uint32_t calculated_quota_out; | 382 | uint32_t calculated_quota_out; |
387 | 383 | ||
@@ -427,7 +423,6 @@ libgnunet_plugin_ats_proportional_done (void *cls) | |||
427 | struct AddressWrapper *next; | 423 | struct AddressWrapper *next; |
428 | int c; | 424 | int c; |
429 | 425 | ||
430 | GNUNET_assert(s != NULL); | ||
431 | for (c = 0; c < s->network_count; c++) | 426 | for (c = 0; c < s->network_count; c++) |
432 | { | 427 | { |
433 | if (s->network_entries[c].total_addresses > 0) | 428 | if (s->network_entries[c].total_addresses > 0) |
@@ -515,11 +510,10 @@ is_bandwidth_available_in_network (struct Network *net) | |||
515 | */ | 510 | */ |
516 | static void | 511 | static void |
517 | distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | 512 | distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, |
518 | struct Network *net) | 513 | struct Network *net) |
519 | { | 514 | { |
520 | struct AddressSolverInformation *asi; | 515 | struct AddressSolverInformation *asi; |
521 | struct AddressWrapper *cur_address; | 516 | struct AddressWrapper *cur_address; |
522 | |||
523 | unsigned long long remaining_quota_in = 0; | 517 | unsigned long long remaining_quota_in = 0; |
524 | unsigned long long quota_out_used = 0; | 518 | unsigned long long quota_out_used = 0; |
525 | unsigned long long remaining_quota_out = 0; | 519 | unsigned long long remaining_quota_out = 0; |
@@ -537,10 +531,12 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | |||
537 | uint32_t assigned_quota_out = 0; | 531 | uint32_t assigned_quota_out = 0; |
538 | 532 | ||
539 | 533 | ||
540 | LOG(GNUNET_ERROR_TYPE_INFO, | 534 | LOG (GNUNET_ERROR_TYPE_INFO, |
541 | "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n", | 535 | "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n", |
542 | net->desc, net->active_addresses, net->total_quota_in, | 536 | net->desc, |
543 | net->total_quota_in); | 537 | net->active_addresses, |
538 | net->total_quota_in, | ||
539 | net->total_quota_in); | ||
544 | 540 | ||
545 | if (net->active_addresses == 0) | 541 | if (net->active_addresses == 0) |
546 | { | 542 | { |
@@ -803,7 +799,6 @@ find_best_address_it (void *cls, | |||
803 | /* user shorter distance */ | 799 | /* user shorter distance */ |
804 | if (cur_distance < best_distance) | 800 | if (cur_distance < best_distance) |
805 | { | 801 | { |
806 | |||
807 | if (GNUNET_NO == ctx->best->active) | 802 | if (GNUNET_NO == ctx->best->active) |
808 | { | 803 | { |
809 | current_best = current; /* Use current */ | 804 | current_best = current; /* Use current */ |
@@ -864,9 +859,10 @@ get_best_address (struct GAS_PROPORTIONAL_Handle *s, | |||
864 | 859 | ||
865 | fba_ctx.best = NULL; | 860 | fba_ctx.best = NULL; |
866 | fba_ctx.s = s; | 861 | fba_ctx.s = s; |
867 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, id, | 862 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, |
868 | &find_best_address_it, &fba_ctx); | 863 | id, |
869 | 864 | &find_best_address_it, | |
865 | &fba_ctx); | ||
870 | return fba_ctx.best; | 866 | return fba_ctx.best; |
871 | } | 867 | } |
872 | 868 | ||
@@ -1203,7 +1199,7 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, | |||
1203 | * @param peer the peer to check | 1199 | * @param peer the peer to check |
1204 | * return the new address or NULL if no update was performed | 1200 | * return the new address or NULL if no update was performed |
1205 | */ | 1201 | */ |
1206 | static const struct ATS_Address * | 1202 | static struct ATS_Address * |
1207 | update_active_address (struct GAS_PROPORTIONAL_Handle *s, | 1203 | update_active_address (struct GAS_PROPORTIONAL_Handle *s, |
1208 | const struct GNUNET_PeerIdentity *peer) | 1204 | const struct GNUNET_PeerIdentity *peer) |
1209 | { | 1205 | { |
@@ -1217,27 +1213,38 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
1217 | GNUNET_i2s (peer)); | 1213 | GNUNET_i2s (peer)); |
1218 | 1214 | ||
1219 | /* Find active address */ | 1215 | /* Find active address */ |
1220 | current_address = get_active_address (s, s->addresses, peer); | 1216 | current_address = get_active_address (s, |
1217 | s->addresses, | ||
1218 | peer); | ||
1221 | 1219 | ||
1222 | LOG (GNUNET_ERROR_TYPE_INFO, "Peer `%s' has active address %p\n", | 1220 | LOG (GNUNET_ERROR_TYPE_INFO, |
1223 | GNUNET_i2s (peer), current_address); | 1221 | "Peer `%s' has active address %p\n", |
1222 | GNUNET_i2s (peer), | ||
1223 | current_address); | ||
1224 | 1224 | ||
1225 | /* Find best address */ | 1225 | /* Find best address */ |
1226 | best_address = get_best_address (s,s->addresses, peer); | 1226 | best_address = get_best_address (s, |
1227 | LOG (GNUNET_ERROR_TYPE_INFO, "Peer `%s' has best address %p\n", | 1227 | s->addresses, |
1228 | GNUNET_i2s (peer), best_address); | 1228 | peer); |
1229 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1230 | "Peer `%s' has best address %p\n", | ||
1231 | GNUNET_i2s (peer), | ||
1232 | best_address); | ||
1229 | 1233 | ||
1230 | if (NULL != current_address) | 1234 | if (NULL != current_address) |
1231 | { | 1235 | { |
1232 | if ((NULL == best_address) || ((NULL != best_address) && | 1236 | if ( (NULL == best_address) || |
1233 | (GNUNET_NO == address_eq (current_address, best_address)))) | 1237 | ( (NULL != best_address) && |
1238 | (GNUNET_NO == address_eq (current_address, | ||
1239 | best_address)) ) ) | ||
1234 | { | 1240 | { |
1235 | /* We switch to a new address, mark old address as inactive */ | 1241 | /* We switch to a new address (or to none), |
1242 | mark old address as inactive */ | ||
1236 | LOG (GNUNET_ERROR_TYPE_INFO, | 1243 | LOG (GNUNET_ERROR_TYPE_INFO, |
1237 | "Disabling previous %s address %p for peer `%s'\n", | 1244 | "Disabling previous %s address %p for peer `%s'\n", |
1238 | (GNUNET_NO == current_address->active) ? "inactive" : "active", | 1245 | (GNUNET_NO == current_address->active) ? "inactive" : "active", |
1239 | current_address, | 1246 | current_address, |
1240 | GNUNET_i2s (peer)); | 1247 | GNUNET_i2s (peer)); |
1241 | 1248 | ||
1242 | asi = current_address->solver_information; | 1249 | asi = current_address->solver_information; |
1243 | GNUNET_assert (NULL != asi); | 1250 | GNUNET_assert (NULL != asi); |
@@ -1258,32 +1265,31 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
1258 | { | 1265 | { |
1259 | /* We previously had an active address, but now we cannot suggest one | 1266 | /* We previously had an active address, but now we cannot suggest one |
1260 | * Therefore we have to disconnect the peer */ | 1267 | * Therefore we have to disconnect the peer */ |
1261 | |||
1262 | LOG (GNUNET_ERROR_TYPE_INFO, | 1268 | LOG (GNUNET_ERROR_TYPE_INFO, |
1263 | "Disconnecting peer `%s' with previous %s address %p\n", | 1269 | "Disconnecting peer `%s' with previous address %p\n", |
1264 | GNUNET_i2s (peer), | 1270 | GNUNET_i2s (peer), |
1265 | (GNUNET_NO == current_address->active) ? "inactive" : "active", | 1271 | current_address); |
1266 | current_address); | 1272 | s->bw_changed (s->bw_changed_cls, |
1267 | s->bw_changed (s->bw_changed_cls, current_address); | 1273 | current_address); |
1268 | } | 1274 | } |
1269 | } | 1275 | } |
1270 | |||
1271 | if (NULL == best_address) | 1276 | if (NULL == best_address) |
1272 | { | 1277 | { |
1273 | LOG (GNUNET_ERROR_TYPE_INFO, "Cannot suggest address for peer `%s'\n", | 1278 | LOG (GNUNET_ERROR_TYPE_INFO, |
1274 | GNUNET_i2s (peer)); | 1279 | "Cannot suggest address for peer `%s'\n", |
1275 | return NULL ; | 1280 | GNUNET_i2s (peer)); |
1281 | return NULL; | ||
1276 | } | 1282 | } |
1277 | 1283 | ||
1278 | LOG (GNUNET_ERROR_TYPE_INFO, "Suggesting %s address %p for peer `%s'\n", | 1284 | LOG (GNUNET_ERROR_TYPE_INFO, |
1279 | (GNUNET_NO == best_address->active) ? "inactive" : "active", best_address, | 1285 | "Suggesting new address %p for peer `%s'\n", |
1280 | GNUNET_i2s (peer)); | 1286 | best_address, |
1287 | GNUNET_i2s (peer)); | ||
1281 | 1288 | ||
1282 | if ((NULL != current_address) && | 1289 | if ( (NULL != current_address) && |
1283 | (GNUNET_YES == address_eq (best_address, current_address))) | 1290 | (GNUNET_YES == address_eq (best_address, current_address)) ) |
1284 | { | 1291 | { |
1285 | if (current_address->active == GNUNET_NO) | 1292 | GNUNET_break (GNUNET_NO != current_address->active); |
1286 | GNUNET_break (0); /* Should never happen */ | ||
1287 | return best_address; /* Same same */ | 1293 | return best_address; /* Same same */ |
1288 | } | 1294 | } |
1289 | 1295 | ||
@@ -1292,11 +1298,13 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
1292 | net = asi->network; | 1298 | net = asi->network; |
1293 | 1299 | ||
1294 | /* Mark address as active */ | 1300 | /* Mark address as active */ |
1295 | asi->activated = GNUNET_TIME_absolute_get(); | 1301 | asi->activated = GNUNET_TIME_absolute_get (); |
1296 | best_address->active = GNUNET_YES; | 1302 | best_address->active = GNUNET_YES; |
1297 | address_increment (s, net, GNUNET_NO, GNUNET_YES); | 1303 | address_increment (s, net, GNUNET_NO, GNUNET_YES); |
1298 | LOG (GNUNET_ERROR_TYPE_INFO, "Address %p for peer `%s' is now active\n", | 1304 | LOG (GNUNET_ERROR_TYPE_INFO, |
1299 | best_address, GNUNET_i2s (peer)); | 1305 | "Address %p for peer `%s' is now active\n", |
1306 | best_address, | ||
1307 | GNUNET_i2s (peer)); | ||
1300 | /* Distribute bandwidth */ | 1308 | /* Distribute bandwidth */ |
1301 | distribute_bandwidth_in_network (s, net); | 1309 | distribute_bandwidth_in_network (s, net); |
1302 | return best_address; | 1310 | return best_address; |
@@ -1322,15 +1330,13 @@ GAS_proportional_address_change_preference (void *solver, | |||
1322 | struct ATS_Address *active_address; | 1330 | struct ATS_Address *active_address; |
1323 | struct AddressSolverInformation *asi; | 1331 | struct AddressSolverInformation *asi; |
1324 | 1332 | ||
1325 | GNUNET_assert(NULL != s); | 1333 | if (GNUNET_NO == |
1326 | GNUNET_assert(NULL != peer); | 1334 | GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) |
1327 | |||
1328 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) | ||
1329 | return; /* Peer is not requested */ | 1335 | return; /* Peer is not requested */ |
1330 | 1336 | ||
1331 | /* This peer is requested, find best address */ | 1337 | /* This peer is requested, find best address */ |
1332 | active_address = get_active_address(s, s->addresses, peer); | 1338 | active_address = get_active_address (s, s->addresses, peer); |
1333 | best_address = (struct ATS_Address *) update_active_address (s, peer); | 1339 | best_address = update_active_address (s, peer); |
1334 | 1340 | ||
1335 | if ((NULL != best_address) && ((NULL != active_address) && | 1341 | if ((NULL != best_address) && ((NULL != active_address) && |
1336 | (GNUNET_YES == address_eq (active_address, best_address)))) | 1342 | (GNUNET_YES == address_eq (active_address, best_address)))) |
@@ -1383,18 +1389,18 @@ GAS_proportional_get_preferred_address (void *solver, | |||
1383 | struct GAS_PROPORTIONAL_Handle *s = solver; | 1389 | struct GAS_PROPORTIONAL_Handle *s = solver; |
1384 | const struct ATS_Address *best_address; | 1390 | const struct ATS_Address *best_address; |
1385 | 1391 | ||
1386 | |||
1387 | GNUNET_assert(s != NULL); | ||
1388 | GNUNET_assert(peer != NULL); | ||
1389 | |||
1390 | /* Add to list of pending requests */ | 1392 | /* Add to list of pending requests */ |
1391 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) | 1393 | if (GNUNET_NO == |
1394 | GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) | ||
1392 | { | 1395 | { |
1393 | GNUNET_assert( | 1396 | GNUNET_assert (GNUNET_OK == |
1394 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (s->requests, peer, NULL, | 1397 | GNUNET_CONTAINER_multipeermap_put (s->requests, |
1398 | peer, | ||
1399 | NULL, | ||
1395 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1400 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1396 | LOG (GNUNET_ERROR_TYPE_INFO, "Start suggesting addresses for peer `%s'\n", | 1401 | LOG (GNUNET_ERROR_TYPE_INFO, |
1397 | GNUNET_i2s (peer)); | 1402 | "Start suggesting addresses for peer `%s'\n", |
1403 | GNUNET_i2s (peer)); | ||
1398 | } | 1404 | } |
1399 | 1405 | ||
1400 | best_address = update_active_address (s, peer); | 1406 | best_address = update_active_address (s, peer); |
@@ -1420,23 +1426,28 @@ GAS_proportional_stop_get_preferred_address (void *solver, | |||
1420 | struct AddressSolverInformation *asi; | 1426 | struct AddressSolverInformation *asi; |
1421 | struct Network *cur_net; | 1427 | struct Network *cur_net; |
1422 | 1428 | ||
1423 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) | 1429 | if (GNUNET_YES == |
1430 | GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) | ||
1424 | { | 1431 | { |
1425 | GNUNET_assert (GNUNET_OK == | 1432 | GNUNET_assert (GNUNET_OK == |
1426 | GNUNET_CONTAINER_multipeermap_remove (s->requests, | 1433 | GNUNET_CONTAINER_multipeermap_remove (s->requests, |
1427 | peer, NULL)); | 1434 | peer, |
1435 | NULL)); | ||
1428 | LOG (GNUNET_ERROR_TYPE_INFO, | 1436 | LOG (GNUNET_ERROR_TYPE_INFO, |
1429 | "Stop suggesting addresses for peer `%s'\n", | 1437 | "Stop suggesting addresses for peer `%s'\n", |
1430 | GNUNET_i2s (peer)); | 1438 | GNUNET_i2s (peer)); |
1431 | } | 1439 | } |
1432 | 1440 | ||
1433 | cur = get_active_address (s, s->addresses, peer); | 1441 | cur = get_active_address (s, |
1442 | s->addresses, | ||
1443 | peer); | ||
1434 | if (NULL != cur) | 1444 | if (NULL != cur) |
1435 | { | 1445 | { |
1436 | LOG(GNUNET_ERROR_TYPE_INFO, | 1446 | LOG (GNUNET_ERROR_TYPE_INFO, |
1437 | "Disabling %s address %p for peer `%s'\n", | 1447 | "Disabling %s address %p for peer `%s'\n", |
1438 | (GNUNET_NO == cur->active) ? "inactive" : "active", cur, | 1448 | (GNUNET_NO == cur->active) ? "inactive" : "active", |
1439 | GNUNET_i2s (&cur->peer)); | 1449 | cur, |
1450 | GNUNET_i2s (&cur->peer)); | ||
1440 | 1451 | ||
1441 | /* Disabling current address */ | 1452 | /* Disabling current address */ |
1442 | asi = cur->solver_information; | 1453 | asi = cur->solver_information; |
@@ -1446,12 +1457,12 @@ GAS_proportional_stop_get_preferred_address (void *solver, | |||
1446 | cur->assigned_bw_in = 0; /* no bandwidth assigned */ | 1457 | cur->assigned_bw_in = 0; /* no bandwidth assigned */ |
1447 | cur->assigned_bw_out = 0; /* no bandwidth assigned */ | 1458 | cur->assigned_bw_out = 0; /* no bandwidth assigned */ |
1448 | 1459 | ||
1449 | if (GNUNET_SYSERR == addresse_decrement (s, cur_net, GNUNET_NO, GNUNET_YES)) | 1460 | if (GNUNET_SYSERR == |
1461 | addresse_decrement (s, cur_net, GNUNET_NO, GNUNET_YES)) | ||
1450 | GNUNET_break(0); | 1462 | GNUNET_break(0); |
1451 | 1463 | ||
1452 | distribute_bandwidth_in_network (s, cur_net ); | 1464 | distribute_bandwidth_in_network (s, cur_net); |
1453 | } | 1465 | } |
1454 | return; | ||
1455 | } | 1466 | } |
1456 | 1467 | ||
1457 | 1468 | ||
@@ -1490,11 +1501,14 @@ GAS_proportional_address_delete (void *solver, | |||
1490 | 1501 | ||
1491 | if (GNUNET_NO == session_only) | 1502 | if (GNUNET_NO == session_only) |
1492 | { | 1503 | { |
1493 | LOG(GNUNET_ERROR_TYPE_INFO, | 1504 | LOG (GNUNET_ERROR_TYPE_INFO, |
1494 | "Deleting %s address %p for peer `%s' from network `%s' (total: %u/ active: %u)\n", | 1505 | "Deleting %s address %p for peer `%s' from network `%s' (total: %u/ active: %u)\n", |
1495 | (GNUNET_NO == address->active) ? "inactive" : "active", address, | 1506 | (GNUNET_NO == address->active) ? "inactive" : "active", |
1496 | GNUNET_i2s (&address->peer), net->desc, net->total_addresses, | 1507 | address, |
1497 | net->active_addresses); | 1508 | GNUNET_i2s (&address->peer), |
1509 | net->desc, | ||
1510 | net->total_addresses, | ||
1511 | net->active_addresses); | ||
1498 | 1512 | ||
1499 | /* Remove address */ | 1513 | /* Remove address */ |
1500 | addresse_decrement (s, net, GNUNET_YES, GNUNET_NO); | 1514 | addresse_decrement (s, net, GNUNET_YES, GNUNET_NO); |
@@ -1508,42 +1522,48 @@ GAS_proportional_address_delete (void *solver, | |||
1508 | GNUNET_break(0); | 1522 | GNUNET_break(0); |
1509 | return; | 1523 | return; |
1510 | } | 1524 | } |
1511 | GNUNET_CONTAINER_DLL_remove(net->head, net->tail, aw); | 1525 | GNUNET_CONTAINER_DLL_remove (net->head, |
1512 | GNUNET_free(aw); | 1526 | net->tail, |
1527 | aw); | ||
1528 | GNUNET_free (aw); | ||
1513 | } | 1529 | } |
1514 | else | 1530 | else |
1515 | { | 1531 | { |
1516 | /* Remove session only: remove if active and update */ | 1532 | /* Remove session only: remove if active and update */ |
1517 | LOG(GNUNET_ERROR_TYPE_INFO, | 1533 | LOG (GNUNET_ERROR_TYPE_INFO, |
1518 | "Deleting %s session %p for peer `%s' from network `%s' (total: %u/ active: %u)\n", | 1534 | "Deleting %s session %p for peer `%s' from network `%s' (total: %u/ active: %u)\n", |
1519 | (GNUNET_NO == address->active) ? "inactive" : "active", address, | 1535 | (GNUNET_NO == address->active) ? "inactive" : "active", |
1520 | GNUNET_i2s (&address->peer), net->desc, net->total_addresses, | 1536 | address, |
1521 | net->active_addresses); | 1537 | GNUNET_i2s (&address->peer), |
1538 | net->desc, | ||
1539 | net->total_addresses, | ||
1540 | net->active_addresses); | ||
1522 | } | 1541 | } |
1523 | 1542 | ||
1524 | if (GNUNET_YES == address->active) | 1543 | if (GNUNET_YES == address->active) |
1525 | { | 1544 | { |
1526 | /* Address was active, remove from network and update quotas*/ | 1545 | /* Address was active, remove from network and update quotas*/ |
1527 | address->active = GNUNET_NO; | 1546 | address->active = GNUNET_NO; |
1528 | |||
1529 | address->assigned_bw_in = 0; | 1547 | address->assigned_bw_in = 0; |
1530 | address->assigned_bw_out = 0; | 1548 | address->assigned_bw_out = 0; |
1531 | asi->calculated_quota_in = 0; | 1549 | asi->calculated_quota_in = 0; |
1532 | asi->calculated_quota_out = 0; | 1550 | asi->calculated_quota_out = 0; |
1533 | 1551 | ||
1534 | if (GNUNET_SYSERR == addresse_decrement (s, net, GNUNET_NO, GNUNET_YES)) | 1552 | if (GNUNET_SYSERR == |
1553 | addresse_decrement (s, net, GNUNET_NO, GNUNET_YES)) | ||
1535 | GNUNET_break(0); | 1554 | GNUNET_break(0); |
1536 | distribute_bandwidth_in_network (s, net); | 1555 | distribute_bandwidth_in_network (s, net); |
1537 | 1556 | ||
1538 | if (NULL == update_active_address (s, &address->peer)) | 1557 | if (NULL == |
1558 | update_active_address (s, &address->peer)) | ||
1539 | { | 1559 | { |
1540 | /* No alternative address found, disconnect peer */ | 1560 | /* No alternative address found, disconnect peer */ |
1541 | LOG (GNUNET_ERROR_TYPE_INFO, | 1561 | LOG (GNUNET_ERROR_TYPE_INFO, |
1542 | "Disconnecting peer `%s' after deleting previous %s address %p\n", | 1562 | "Disconnecting peer `%s' after deleting previous address %p\n", |
1543 | GNUNET_i2s (&address->peer), | 1563 | GNUNET_i2s (&address->peer), |
1544 | (GNUNET_NO == address->active) ? "inactive" : "active", | 1564 | address); |
1545 | address); | 1565 | s->bw_changed (s->bw_changed_cls, |
1546 | s->bw_changed (s->bw_changed_cls, address); | 1566 | address); |
1547 | } | 1567 | } |
1548 | } | 1568 | } |
1549 | if (GNUNET_NO == session_only) | 1569 | if (GNUNET_NO == session_only) |
@@ -1552,10 +1572,11 @@ GAS_proportional_address_delete (void *solver, | |||
1552 | address->solver_information = NULL; | 1572 | address->solver_information = NULL; |
1553 | } | 1573 | } |
1554 | 1574 | ||
1555 | LOG(GNUNET_ERROR_TYPE_INFO, | 1575 | LOG (GNUNET_ERROR_TYPE_INFO, |
1556 | "After deleting address now total %u and active %u addresses in network `%s'\n", | 1576 | "After deleting address now total %u and active %u addresses in network `%s'\n", |
1557 | net->total_addresses, net->active_addresses, net->desc); | 1577 | net->total_addresses, |
1558 | 1578 | net->active_addresses, | |
1579 | net->desc); | ||
1559 | } | 1580 | } |
1560 | 1581 | ||
1561 | 1582 | ||
@@ -1571,7 +1592,7 @@ GAS_proportional_bulk_start (void *solver) | |||
1571 | 1592 | ||
1572 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1593 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1573 | "Locking solver for bulk operation ...\n"); | 1594 | "Locking solver for bulk operation ...\n"); |
1574 | GNUNET_assert(NULL != solver); | 1595 | GNUNET_assert (NULL != solver); |
1575 | s->bulk_lock++; | 1596 | s->bulk_lock++; |
1576 | } | 1597 | } |
1577 | 1598 | ||
@@ -1586,8 +1607,6 @@ GAS_proportional_bulk_stop (void *solver) | |||
1586 | 1607 | ||
1587 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1608 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1588 | "Unlocking solver from bulk operation ...\n"); | 1609 | "Unlocking solver from bulk operation ...\n"); |
1589 | GNUNET_assert(NULL != solver); | ||
1590 | |||
1591 | if (s->bulk_lock < 1) | 1610 | if (s->bulk_lock < 1) |
1592 | { | 1611 | { |
1593 | GNUNET_break(0); | 1612 | GNUNET_break(0); |
@@ -1638,8 +1657,6 @@ GAS_proportional_address_property_changed (void *solver, | |||
1638 | struct ATS_Address *best_address; | 1657 | struct ATS_Address *best_address; |
1639 | struct ATS_Address *active_address; | 1658 | struct ATS_Address *active_address; |
1640 | 1659 | ||
1641 | GNUNET_assert(NULL != s); | ||
1642 | GNUNET_assert(NULL != address); | ||
1643 | asi = address->solver_information; | 1660 | asi = address->solver_information; |
1644 | if (NULL == asi) | 1661 | if (NULL == asi) |
1645 | { | 1662 | { |
@@ -1664,7 +1681,8 @@ GAS_proportional_address_property_changed (void *solver, | |||
1664 | 1681 | ||
1665 | /* This peer is requested, find active and best address */ | 1682 | /* This peer is requested, find active and best address */ |
1666 | active_address = get_active_address(s, s->addresses, &address->peer); | 1683 | active_address = get_active_address(s, s->addresses, &address->peer); |
1667 | best_address = (struct ATS_Address *) update_active_address (s, &address->peer); | 1684 | best_address = update_active_address (s, |
1685 | &address->peer); | ||
1668 | 1686 | ||
1669 | if ((NULL != best_address) && ((NULL != active_address) && | 1687 | if ((NULL != best_address) && ((NULL != active_address) && |
1670 | (GNUNET_YES == address_eq (active_address, best_address)))) | 1688 | (GNUNET_YES == address_eq (active_address, best_address)))) |
@@ -1712,12 +1730,13 @@ GAS_proportional_address_session_changed (void *solver, | |||
1712 | return; | 1730 | return; |
1713 | } | 1731 | } |
1714 | 1732 | ||
1715 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, &address->peer)) | 1733 | if (GNUNET_NO == |
1734 | GNUNET_CONTAINER_multipeermap_contains (s->requests, &address->peer)) | ||
1716 | return; /* Peer is not requested */ | 1735 | return; /* Peer is not requested */ |
1717 | 1736 | ||
1718 | /* This peer is requested, find active and best address */ | 1737 | /* This peer is requested, find active and best address */ |
1719 | active_address = get_active_address(s, s->addresses, &address->peer); | 1738 | active_address = get_active_address (s, s->addresses, &address->peer); |
1720 | best_address = (struct ATS_Address *) update_active_address (s, &address->peer); | 1739 | best_address = update_active_address (s, &address->peer); |
1721 | 1740 | ||
1722 | if ((NULL != best_address) && ((NULL != active_address) && | 1741 | if ((NULL != best_address) && ((NULL != active_address) && |
1723 | (GNUNET_YES == address_eq (active_address, best_address)))) | 1742 | (GNUNET_YES == address_eq (active_address, best_address)))) |
@@ -1732,65 +1751,6 @@ GAS_proportional_address_session_changed (void *solver, | |||
1732 | 1751 | ||
1733 | 1752 | ||
1734 | /** | 1753 | /** |
1735 | * Usage for this address has changed | ||
1736 | * | ||
1737 | * NOTE: values in addresses are already updated | ||
1738 | * | ||
1739 | * @param solver solver handle | ||
1740 | * @param address the address | ||
1741 | * @param in_use usage state | ||
1742 | */ | ||
1743 | static void | ||
1744 | GAS_proportional_address_inuse_changed (void *solver, | ||
1745 | struct ATS_Address *address, | ||
1746 | int in_use) | ||
1747 | { | ||
1748 | struct GAS_PROPORTIONAL_Handle *s = solver; | ||
1749 | struct Network *n; | ||
1750 | struct AddressSolverInformation *asi; | ||
1751 | struct ATS_Address *best_address; | ||
1752 | struct ATS_Address *active_address; | ||
1753 | |||
1754 | GNUNET_assert(NULL != s); | ||
1755 | GNUNET_assert(NULL != address); | ||
1756 | asi = address->solver_information; | ||
1757 | if (NULL == asi) | ||
1758 | { | ||
1759 | GNUNET_break(0); | ||
1760 | return; | ||
1761 | } | ||
1762 | |||
1763 | n = asi->network; | ||
1764 | if (NULL == n) | ||
1765 | { | ||
1766 | GNUNET_break(0); | ||
1767 | return; | ||
1768 | } | ||
1769 | |||
1770 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
1771 | "Usage of peer `%s' address %p changed to %s \n", | ||
1772 | GNUNET_i2s (&address->peer), address, | ||
1773 | (GNUNET_YES == in_use) ? "YES" : "NO"); | ||
1774 | |||
1775 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, &address->peer)) | ||
1776 | return; /* Peer is not requested */ | ||
1777 | |||
1778 | /* This peer is requested, find active and best address */ | ||
1779 | active_address = get_active_address(s, s->addresses, &address->peer); | ||
1780 | best_address = (struct ATS_Address *) update_active_address (s, &address->peer); | ||
1781 | |||
1782 | if ((NULL != best_address) && ((NULL != active_address) && | ||
1783 | (GNUNET_YES == address_eq (active_address, best_address)))) | ||
1784 | { | ||
1785 | asi = best_address->solver_information; | ||
1786 | GNUNET_assert (NULL != asi); | ||
1787 | |||
1788 | /* We sticked to the same address, therefore redistribute */ | ||
1789 | distribute_bandwidth_in_network (s, asi->network); | ||
1790 | } | ||
1791 | } | ||
1792 | |||
1793 | /** | ||
1794 | * Network scope for this address has changed | 1754 | * Network scope for this address has changed |
1795 | * | 1755 | * |
1796 | * NOTE: values in addresses are already updated | 1756 | * NOTE: values in addresses are already updated |
@@ -1955,7 +1915,6 @@ libgnunet_plugin_ats_proportional_init (void *cls) | |||
1955 | env->sf.s_add = &GAS_proportional_address_add; | 1915 | env->sf.s_add = &GAS_proportional_address_add; |
1956 | env->sf.s_address_update_property = &GAS_proportional_address_property_changed; | 1916 | env->sf.s_address_update_property = &GAS_proportional_address_property_changed; |
1957 | env->sf.s_address_update_session = &GAS_proportional_address_session_changed; | 1917 | env->sf.s_address_update_session = &GAS_proportional_address_session_changed; |
1958 | env->sf.s_address_update_inuse = &GAS_proportional_address_inuse_changed; | ||
1959 | env->sf.s_address_update_network = &GAS_proportional_address_change_network; | 1918 | env->sf.s_address_update_network = &GAS_proportional_address_change_network; |
1960 | env->sf.s_get = &GAS_proportional_get_preferred_address; | 1919 | env->sf.s_get = &GAS_proportional_get_preferred_address; |
1961 | env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address; | 1920 | env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address; |