diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-08 17:02:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-08 17:02:40 +0000 |
commit | 6a2eb1566c41498f16410c4101f669e1ced59abf (patch) | |
tree | ebdc8fdf4c74c980cd88104dffc9c6401a4c00c4 /src/ats/plugin_ats_proportional.c | |
parent | ef5b7049c8ac74924c4ee24e566802e1fc05addd (diff) | |
download | gnunet-6a2eb1566c41498f16410c4101f669e1ced59abf.tar.gz gnunet-6a2eb1566c41498f16410c4101f669e1ced59abf.zip |
eliminate super-lazy functions
Diffstat (limited to 'src/ats/plugin_ats_proportional.c')
-rw-r--r-- | src/ats/plugin_ats_proportional.c | 238 |
1 files changed, 81 insertions, 157 deletions
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index f233ca4df..312199e95 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c | |||
@@ -372,66 +372,6 @@ struct GAS_PROPORTIONAL_Handle | |||
372 | 372 | ||
373 | 373 | ||
374 | /** | 374 | /** |
375 | * Function used to unload the plugin. | ||
376 | * | ||
377 | * @param cls return value from #libgnunet_plugin_ats_proportional_init() | ||
378 | */ | ||
379 | void * | ||
380 | libgnunet_plugin_ats_proportional_done (void *cls) | ||
381 | { | ||
382 | struct GNUNET_ATS_SolverFunctions *sf = cls; | ||
383 | struct GAS_PROPORTIONAL_Handle *s = sf->cls; | ||
384 | struct AddressWrapper *cur; | ||
385 | struct AddressWrapper *next; | ||
386 | unsigned int c; | ||
387 | |||
388 | for (c = 0; c < s->network_count; c++) | ||
389 | { | ||
390 | if (s->network_entries[c].total_addresses > 0) | ||
391 | { | ||
392 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
393 | "Had %u addresses for network `%s' not deleted during shutdown\n", | ||
394 | s->network_entries[c].total_addresses, | ||
395 | s->network_entries[c].desc); | ||
396 | //GNUNET_break(0); | ||
397 | } | ||
398 | |||
399 | if (s->network_entries[c].active_addresses > 0) | ||
400 | { | ||
401 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
402 | "Had %u active addresses for network `%s' not deleted during shutdown\n", | ||
403 | s->network_entries[c].active_addresses, | ||
404 | s->network_entries[c].desc); | ||
405 | //GNUNET_break(0); | ||
406 | } | ||
407 | |||
408 | next = s->network_entries[c].head; | ||
409 | while (NULL != (cur = next)) | ||
410 | { | ||
411 | next = cur->next; | ||
412 | GNUNET_CONTAINER_DLL_remove (s->network_entries[c].head, | ||
413 | s->network_entries[c].tail, | ||
414 | cur); | ||
415 | GNUNET_free_non_null (cur->addr->solver_information); | ||
416 | GNUNET_free(cur); | ||
417 | } | ||
418 | GNUNET_free (s->network_entries[c].stat_total); | ||
419 | GNUNET_free (s->network_entries[c].stat_active); | ||
420 | } | ||
421 | if (s->active_addresses > 0) | ||
422 | { | ||
423 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
424 | "Had %u active addresses not deleted during shutdown\n", | ||
425 | s->active_addresses); | ||
426 | // GNUNET_break (0); | ||
427 | } | ||
428 | GNUNET_free (s->network_entries); | ||
429 | GNUNET_free (s); | ||
430 | return NULL; | ||
431 | } | ||
432 | |||
433 | |||
434 | /** | ||
435 | * 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 |
436 | * | 376 | * |
437 | * @param net the network type to update | 377 | * @param net the network type to update |
@@ -443,8 +383,8 @@ is_bandwidth_available_in_network (struct Network *net) | |||
443 | unsigned int na = net->active_addresses + 1; | 383 | unsigned int na = net->active_addresses + 1; |
444 | uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); | 384 | uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); |
445 | 385 | ||
446 | if (((net->total_quota_in / na) > min_bw) | 386 | if ( ((net->total_quota_in / na) > min_bw) && |
447 | && ((net->total_quota_out / na) > min_bw)) | 387 | ((net->total_quota_out / na) > min_bw) ) |
448 | { | 388 | { |
449 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 389 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
450 | "Enough bandwidth available for %u active addresses in network `%s'\n", | 390 | "Enough bandwidth available for %u active addresses in network `%s'\n", |
@@ -854,26 +794,6 @@ get_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
854 | 794 | ||
855 | 795 | ||
856 | /** | 796 | /** |
857 | * Lookup network struct by type | ||
858 | * | ||
859 | * @param s the solver handle | ||
860 | * @param type the network type | ||
861 | * @return the network struct | ||
862 | */ | ||
863 | static struct Network * | ||
864 | get_network (struct GAS_PROPORTIONAL_Handle *s, | ||
865 | enum GNUNET_ATS_Network_Type type) | ||
866 | { | ||
867 | if (type >= s->env->network_count) | ||
868 | { | ||
869 | GNUNET_break (0); | ||
870 | return NULL; | ||
871 | } | ||
872 | return &s->network_entries[type]; | ||
873 | } | ||
874 | |||
875 | |||
876 | /** | ||
877 | * Decrease address count in network | 797 | * Decrease address count in network |
878 | * | 798 | * |
879 | * @param s the solver handle | 799 | * @param s the solver handle |
@@ -909,30 +829,6 @@ address_decrement_active (struct GAS_PROPORTIONAL_Handle *s, | |||
909 | 829 | ||
910 | 830 | ||
911 | /** | 831 | /** |
912 | * Compares addresses | ||
913 | * | ||
914 | * @param a address a | ||
915 | * @param b address b | ||
916 | * @return GNUNET_YES if equal, GNUNET_NO else | ||
917 | */ | ||
918 | static int | ||
919 | address_eq (struct ATS_Address *a, struct ATS_Address *b) | ||
920 | { | ||
921 | GNUNET_assert (NULL != a); | ||
922 | GNUNET_assert (NULL != b); | ||
923 | if (0 != strcmp(a->plugin, b->plugin)) | ||
924 | return GNUNET_NO; | ||
925 | if (a->addr_len != b->addr_len) | ||
926 | return GNUNET_NO; | ||
927 | if (0 != memcmp (a->addr, b->addr, b->addr_len)) | ||
928 | return GNUNET_NO; | ||
929 | if (a->session_id != b->session_id) | ||
930 | return GNUNET_NO; | ||
931 | return GNUNET_YES; | ||
932 | } | ||
933 | |||
934 | |||
935 | /** | ||
936 | * Notify bandwidth changes to addresses | 832 | * Notify bandwidth changes to addresses |
937 | * | 833 | * |
938 | * @param s solver handle | 834 | * @param s solver handle |
@@ -946,30 +842,27 @@ propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | |||
946 | 842 | ||
947 | for (cur = net->head; NULL != cur; cur = cur->next) | 843 | for (cur = net->head; NULL != cur; cur = cur->next) |
948 | { | 844 | { |
949 | if ( (cur->addr->assigned_bw_in != cur->calculated_quota_in) || | 845 | if ( (cur->addr->assigned_bw_in == cur->calculated_quota_in) && |
950 | (cur->addr->assigned_bw_out != cur->calculated_quota_out) ) | 846 | (cur->addr->assigned_bw_out == cur->calculated_quota_out) ) |
951 | { | 847 | continue; |
952 | cur->addr->assigned_bw_in = cur->calculated_quota_in; | 848 | cur->addr->assigned_bw_in = cur->calculated_quota_in; |
953 | cur->addr->assigned_bw_out = cur->calculated_quota_out; | 849 | cur->addr->assigned_bw_out = cur->calculated_quota_out; |
954 | 850 | ||
955 | /* Reset for next iteration */ | 851 | /* Reset for next iteration */ |
956 | cur->calculated_quota_in = 0; | 852 | cur->calculated_quota_in = 0; |
957 | cur->calculated_quota_out = 0; | 853 | cur->calculated_quota_out = 0; |
958 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 854 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
959 | "Bandwidth for %s address %p for peer `%s' changed to %u/%u\n", | 855 | "Bandwidth for %s address %p for peer `%s' changed to %u/%u\n", |
960 | (GNUNET_NO == cur->addr->active) ? "inactive" : "active", | 856 | (GNUNET_NO == cur->addr->active) ? "inactive" : "active", |
961 | cur->addr, | 857 | cur->addr, |
962 | GNUNET_i2s (&cur->addr->peer), | 858 | GNUNET_i2s (&cur->addr->peer), |
963 | cur->addr->assigned_bw_in, | 859 | cur->addr->assigned_bw_in, |
964 | cur->addr->assigned_bw_out); | 860 | cur->addr->assigned_bw_out); |
965 | 861 | ||
966 | /* Notify on change */ | 862 | /* Notify on change */ |
967 | if ((GNUNET_YES == cur->addr->active)) | 863 | if (GNUNET_YES == cur->addr->active) |
968 | { | 864 | s->env->bandwidth_changed_cb (s->env->cls, |
969 | s->env->bandwidth_changed_cb (s->env->cls, | 865 | cur->addr); |
970 | cur->addr); | ||
971 | } | ||
972 | } | ||
973 | } | 866 | } |
974 | } | 867 | } |
975 | 868 | ||
@@ -1102,8 +995,7 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
1102 | GNUNET_assert (GNUNET_YES == current_address->active); | 995 | GNUNET_assert (GNUNET_YES == current_address->active); |
1103 | if ( (NULL == best_address) || | 996 | if ( (NULL == best_address) || |
1104 | ( (NULL != best_address) && | 997 | ( (NULL != best_address) && |
1105 | (GNUNET_NO == address_eq (current_address, | 998 | (current_address != best_address) ) ) |
1106 | best_address)) ) ) | ||
1107 | { | 999 | { |
1108 | /* We switch to a new address (or to none), | 1000 | /* We switch to a new address (or to none), |
1109 | mark old address as inactive */ | 1001 | mark old address as inactive */ |
@@ -1148,7 +1040,7 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
1148 | GNUNET_i2s (peer)); | 1040 | GNUNET_i2s (peer)); |
1149 | 1041 | ||
1150 | if ( (NULL != current_address) && | 1042 | if ( (NULL != current_address) && |
1151 | (GNUNET_YES == address_eq (best_address, current_address)) ) | 1043 | (best_address == current_address) ) |
1152 | { | 1044 | { |
1153 | GNUNET_break (GNUNET_NO != current_address->active); | 1045 | GNUNET_break (GNUNET_NO != current_address->active); |
1154 | return best_address; /* Same same */ | 1046 | return best_address; /* Same same */ |
@@ -1211,8 +1103,8 @@ GAS_proportional_address_change_preference (void *solver, | |||
1211 | peer); | 1103 | peer); |
1212 | best_address = update_active_address (s, peer); | 1104 | best_address = update_active_address (s, peer); |
1213 | 1105 | ||
1214 | if ((NULL != best_address) && ((NULL != active_address) && | 1106 | if ( (NULL != best_address) && |
1215 | (GNUNET_YES == address_eq (active_address, best_address)))) | 1107 | (active_address == best_address) ) |
1216 | { | 1108 | { |
1217 | asi = best_address->solver_information; | 1109 | asi = best_address->solver_information; |
1218 | GNUNET_assert (NULL != asi); | 1110 | GNUNET_assert (NULL != asi); |
@@ -1327,7 +1219,9 @@ GAS_proportional_bulk_start (void *solver) | |||
1327 | 1219 | ||
1328 | 1220 | ||
1329 | /** | 1221 | /** |
1330 | * Bulk operation done | 1222 | * Bulk operation done. |
1223 | * | ||
1224 | * @param solver our `struct GAS_PROPORTIONAL_Handle *` | ||
1331 | */ | 1225 | */ |
1332 | static void | 1226 | static void |
1333 | GAS_proportional_bulk_stop (void *solver) | 1227 | GAS_proportional_bulk_stop (void *solver) |
@@ -1387,18 +1281,15 @@ GAS_proportional_address_property_changed (void *solver, | |||
1387 | return; /* Peer is not requested */ | 1281 | return; /* Peer is not requested */ |
1388 | 1282 | ||
1389 | /* This peer is requested, find active and best address */ | 1283 | /* This peer is requested, find active and best address */ |
1390 | active_address = get_active_address(s, | 1284 | active_address = get_active_address (s, |
1391 | &address->peer); | 1285 | &address->peer); |
1392 | best_address = update_active_address (s, | 1286 | best_address = update_active_address (s, |
1393 | &address->peer); | 1287 | &address->peer); |
1394 | 1288 | if (active_address == best_address) | |
1395 | if ((NULL != best_address) && ((NULL != active_address) && | ||
1396 | (GNUNET_YES == address_eq (active_address, best_address)))) | ||
1397 | { | 1289 | { |
1398 | asi = best_address->solver_information; | 1290 | /* We stuck to the same address, therefore redistribute |
1399 | GNUNET_assert (NULL != asi); | 1291 | (NOTE: because otherwise update_active_address() already |
1400 | 1292 | calls distribute_bandwidth_in_network() )*/ | |
1401 | /* We sticked to the same address, therefore redistribute */ | ||
1402 | distribute_bandwidth_in_network (s, asi->network); | 1293 | distribute_bandwidth_in_network (s, asi->network); |
1403 | } | 1294 | } |
1404 | } | 1295 | } |
@@ -1420,20 +1311,17 @@ GAS_proportional_address_add (void *solver, | |||
1420 | struct Network *net; | 1311 | struct Network *net; |
1421 | struct AddressWrapper *aw; | 1312 | struct AddressWrapper *aw; |
1422 | 1313 | ||
1423 | net = get_network (s, | 1314 | GNUNET_assert (network < s->env->network_count); |
1424 | network); | 1315 | net = &s->network_entries[network]; |
1425 | if (NULL == net) | 1316 | net->total_addresses++; |
1426 | { | ||
1427 | GNUNET_break (0); | ||
1428 | return; | ||
1429 | } | ||
1430 | 1317 | ||
1431 | aw = GNUNET_new (struct AddressWrapper); | 1318 | aw = GNUNET_new (struct AddressWrapper); |
1432 | aw->addr = address; | 1319 | aw->addr = address; |
1320 | aw->network = net; | ||
1321 | address->solver_information = aw; | ||
1433 | GNUNET_CONTAINER_DLL_insert (net->head, | 1322 | GNUNET_CONTAINER_DLL_insert (net->head, |
1434 | net->tail, | 1323 | net->tail, |
1435 | aw); | 1324 | aw); |
1436 | net->total_addresses++; | ||
1437 | GNUNET_STATISTICS_update (s->env->stats, | 1325 | GNUNET_STATISTICS_update (s->env->stats, |
1438 | "# ATS addresses total", | 1326 | "# ATS addresses total", |
1439 | 1, | 1327 | 1, |
@@ -1442,8 +1330,6 @@ GAS_proportional_address_add (void *solver, | |||
1442 | net->stat_total, | 1330 | net->stat_total, |
1443 | 1, | 1331 | 1, |
1444 | GNUNET_NO); | 1332 | GNUNET_NO); |
1445 | aw->network = net; | ||
1446 | address->solver_information = aw; | ||
1447 | 1333 | ||
1448 | LOG (GNUNET_ERROR_TYPE_INFO, | 1334 | LOG (GNUNET_ERROR_TYPE_INFO, |
1449 | "Adding new address %p for peer `%s', now total %u and active %u addresses in network `%s'\n", | 1335 | "Adding new address %p for peer `%s', now total %u and active %u addresses in network `%s'\n", |
@@ -1605,8 +1491,8 @@ libgnunet_plugin_ats_proportional_init (void *cls) | |||
1605 | s->prop_factor = f_tmp; | 1491 | s->prop_factor = f_tmp; |
1606 | LOG (GNUNET_ERROR_TYPE_INFO, | 1492 | LOG (GNUNET_ERROR_TYPE_INFO, |
1607 | "Using %s of %.3f\n", | 1493 | "Using %s of %.3f\n", |
1608 | "PROP_PROPORTIONALITY_FACTOR" | 1494 | "PROP_PROPORTIONALITY_FACTOR", |
1609 | , f_tmp); | 1495 | f_tmp); |
1610 | } | 1496 | } |
1611 | } | 1497 | } |
1612 | 1498 | ||
@@ -1636,4 +1522,42 @@ libgnunet_plugin_ats_proportional_init (void *cls) | |||
1636 | } | 1522 | } |
1637 | 1523 | ||
1638 | 1524 | ||
1525 | /** | ||
1526 | * Function used to unload the plugin. | ||
1527 | * | ||
1528 | * @param cls return value from #libgnunet_plugin_ats_proportional_init() | ||
1529 | */ | ||
1530 | void * | ||
1531 | libgnunet_plugin_ats_proportional_done (void *cls) | ||
1532 | { | ||
1533 | struct GNUNET_ATS_SolverFunctions *sf = cls; | ||
1534 | struct GAS_PROPORTIONAL_Handle *s = sf->cls; | ||
1535 | struct AddressWrapper *cur; | ||
1536 | struct AddressWrapper *next; | ||
1537 | unsigned int c; | ||
1538 | |||
1539 | for (c = 0; c < s->network_count; c++) | ||
1540 | { | ||
1541 | GNUNET_break (0 == s->network_entries[c].total_addresses); | ||
1542 | GNUNET_break (0 == s->network_entries[c].active_addresses); | ||
1543 | next = s->network_entries[c].head; | ||
1544 | while (NULL != (cur = next)) | ||
1545 | { | ||
1546 | next = cur->next; | ||
1547 | GNUNET_CONTAINER_DLL_remove (s->network_entries[c].head, | ||
1548 | s->network_entries[c].tail, | ||
1549 | cur); | ||
1550 | GNUNET_free_non_null (cur->addr->solver_information); | ||
1551 | GNUNET_free(cur); | ||
1552 | } | ||
1553 | GNUNET_free (s->network_entries[c].stat_total); | ||
1554 | GNUNET_free (s->network_entries[c].stat_active); | ||
1555 | } | ||
1556 | GNUNET_break (0 == s->active_addresses); | ||
1557 | GNUNET_free (s->network_entries); | ||
1558 | GNUNET_free (s); | ||
1559 | return NULL; | ||
1560 | } | ||
1561 | |||
1562 | |||
1639 | /* end of plugin_ats_proportional.c */ | 1563 | /* end of plugin_ats_proportional.c */ |