diff options
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 94 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 6 |
2 files changed, 67 insertions, 33 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index ab4602b6e..0a1bf7002 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -671,6 +671,13 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC | |||
671 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key)) | 671 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key)) |
672 | return GNUNET_OK; | 672 | return GNUNET_OK; |
673 | 673 | ||
674 | mlpi = address->solver_information; | ||
675 | if (NULL == mlpi) | ||
676 | { | ||
677 | GNUNET_break (0); | ||
678 | return GNUNET_OK; | ||
679 | } | ||
680 | |||
674 | /* Get peer */ | 681 | /* Get peer */ |
675 | peer = GNUNET_CONTAINER_multihashmap_get (mlp->peers, key); | 682 | peer = GNUNET_CONTAINER_multihashmap_get (mlp->peers, key); |
676 | if (peer->processed == GNUNET_NO) | 683 | if (peer->processed == GNUNET_NO) |
@@ -690,15 +697,14 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC | |||
690 | peer->processed = GNUNET_YES; | 697 | peer->processed = GNUNET_YES; |
691 | } | 698 | } |
692 | 699 | ||
693 | 700 | /* Reset addresses' solver information */ | |
694 | /* Prepare solver information */ | 701 | mlpi->c_b = 0; |
695 | if (NULL != address->solver_information) | 702 | mlpi->c_n = 0; |
696 | { | 703 | mlpi->n = 0; |
697 | GNUNET_free (address->solver_information); | 704 | mlpi->r_c1 = 0; |
698 | address->solver_information = NULL; | 705 | mlpi->r_c3 = 0; |
699 | } | 706 | for (c = 0; c < mlp->pv.m_q; c++) |
700 | mlpi = GNUNET_malloc (sizeof (struct MLP_information)); | 707 | mlpi->r_q[0] = 0; |
701 | address->solver_information = mlpi; | ||
702 | 708 | ||
703 | /* Add bandwidth column */ | 709 | /* Add bandwidth column */ |
704 | GNUNET_asprintf (&name, "b_%s_%s", GNUNET_i2s (&address->peer), address->plugin); | 710 | GNUNET_asprintf (&name, "b_%s_%s", GNUNET_i2s (&address->peer), address->plugin); |
@@ -1003,7 +1009,8 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value | |||
1003 | struct GAS_MLP_Handle *mlp = cls; | 1009 | struct GAS_MLP_Handle *mlp = cls; |
1004 | struct ATS_Address *address; | 1010 | struct ATS_Address *address; |
1005 | struct MLP_information *mlpi; | 1011 | struct MLP_information *mlpi; |
1006 | double mlp_bw = NaN; | 1012 | double mlp_bw_in = NaN; |
1013 | double mlp_bw_out = NaN; | ||
1007 | double mlp_use = NaN; | 1014 | double mlp_use = NaN; |
1008 | 1015 | ||
1009 | /* Check if we have to add this peer due to a pending request */ | 1016 | /* Check if we have to add this peer due to a pending request */ |
@@ -1013,40 +1020,62 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value | |||
1013 | GNUNET_assert (address->solver_information != NULL); | 1020 | GNUNET_assert (address->solver_information != NULL); |
1014 | mlpi = address->solver_information; | 1021 | mlpi = address->solver_information; |
1015 | 1022 | ||
1016 | mlp_bw = glp_mip_col_val(mlp->p.prob, mlpi->c_b); | 1023 | mlp_bw_in = glp_mip_col_val(mlp->p.prob, mlpi->c_b);/* FIXME */ |
1024 | if (mlp_bw_in > (double) UINT32_MAX) | ||
1025 | { | ||
1026 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n" ); | ||
1027 | mlp_bw_in = (double) UINT32_MAX; | ||
1028 | } | ||
1029 | mlp_bw_out = glp_mip_col_val(mlp->p.prob, mlpi->c_b); | ||
1030 | if (mlp_bw_out > (double) UINT32_MAX) | ||
1031 | { | ||
1032 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n" ); | ||
1033 | mlp_bw_out = (double) UINT32_MAX; | ||
1034 | } | ||
1017 | mlp_use = glp_mip_col_val(mlp->p.prob, mlpi->c_n); | 1035 | mlp_use = glp_mip_col_val(mlp->p.prob, mlpi->c_n); |
1018 | 1036 | ||
1037 | |||
1038 | |||
1019 | if ((GLP_YES == mlp_use) && (GNUNET_NO == address->active)) | 1039 | if ((GLP_YES == mlp_use) && (GNUNET_NO == address->active)) |
1020 | { | 1040 | { |
1021 | /* Address switch: Activate address*/ | 1041 | /* Address switch: Activate address*/ |
1022 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); | 1042 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out); |
1023 | address->active = GNUNET_YES; | 1043 | address->active = GNUNET_YES; |
1024 | address->assigned_bw_in.value__ = htonl (mlp_bw); | 1044 | address->assigned_bw_in.value__ = htonl (mlp_bw_in); |
1025 | address->assigned_bw_out.value__ = htonl (mlp_bw); | 1045 | mlpi->b_in.value__ = htonl(mlp_bw_in); |
1046 | address->assigned_bw_out.value__ = htonl (mlp_bw_out); | ||
1047 | mlpi->b_out.value__ = htonl(mlp_bw_out); | ||
1048 | mlpi->n = mlp_use; | ||
1026 | mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); | 1049 | mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); |
1027 | } | 1050 | } |
1028 | else if ((GLP_NO == mlp_use) && (GNUNET_YES == address->active)) | 1051 | else if ((GLP_NO == mlp_use) && (GNUNET_YES == address->active)) |
1029 | { | 1052 | { |
1030 | /* Address switch: Disable address*/ | 1053 | /* Address switch: Disable address*/ |
1031 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); | 1054 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out); |
1032 | address->active = GNUNET_NO; | 1055 | address->active = GNUNET_NO; |
1033 | /* Set bandwidth to 0 */ | 1056 | /* Set bandwidth to 0 */ |
1034 | address->assigned_bw_in.value__ = htonl (0); | 1057 | address->assigned_bw_in.value__ = htonl (0); |
1058 | mlpi->b_in.value__ = htonl(mlp_bw_in); | ||
1035 | address->assigned_bw_out.value__ = htonl (0); | 1059 | address->assigned_bw_out.value__ = htonl (0); |
1060 | mlpi->b_out.value__ = htonl(mlp_bw_out); | ||
1061 | mlpi->n = mlp_use; | ||
1036 | mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); | 1062 | mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); |
1037 | } | 1063 | } |
1038 | else if ((mlp_bw != ntohl(address->assigned_bw_out.value__)) || | 1064 | else if ((mlp_bw_out != ntohl(address->assigned_bw_out.value__)) || |
1039 | (mlp_bw != ntohl(address->assigned_bw_in.value__))) | 1065 | (mlp_bw_in != ntohl(address->assigned_bw_in.value__))) |
1040 | { | 1066 | { |
1041 | /* Bandwidth changed */ | 1067 | /* Bandwidth changed */ |
1042 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : bandwidth changed\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); | 1068 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : bandwidth changed\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out); |
1043 | address->assigned_bw_in.value__ = htonl (mlp_bw); | 1069 | address->assigned_bw_in.value__ = htonl (mlp_bw_in); |
1044 | address->assigned_bw_out.value__ = htonl (mlp_bw); | 1070 | mlpi->b_in.value__ = htonl(mlp_bw_in); |
1071 | address->assigned_bw_out.value__ = htonl (mlp_bw_out); | ||
1072 | mlpi->b_out.value__ = htonl(mlp_bw_out); | ||
1073 | mlpi->n = mlp_use; | ||
1045 | mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); | 1074 | mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); |
1046 | } | 1075 | } |
1047 | else | 1076 | else |
1048 | { | 1077 | { |
1049 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); | 1078 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out); |
1050 | } | 1079 | } |
1051 | 1080 | ||
1052 | return GNUNET_OK; | 1081 | return GNUNET_OK; |
@@ -1172,16 +1201,17 @@ GAS_mlp_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addres | |||
1172 | GNUNET_assert (NULL != addresses); | 1201 | GNUNET_assert (NULL != addresses); |
1173 | GNUNET_assert (NULL != address); | 1202 | GNUNET_assert (NULL != address); |
1174 | 1203 | ||
1204 | if (NULL == address->solver_information) | ||
1205 | address->solver_information = GNUNET_malloc (sizeof (struct MLP_information)); | ||
1206 | else | ||
1207 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding address for peer `%s' multiple times\n"), GNUNET_i2s(&address->peer)); | ||
1208 | |||
1175 | /* Is this peer included in the problem? */ | 1209 | /* Is this peer included in the problem? */ |
1176 | if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->peers, &address->peer.hashPubKey))) | 1210 | if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->peers, &address->peer.hashPubKey))) |
1177 | { | 1211 | { |
1178 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer `%s' without address request \n", GNUNET_i2s(&address->peer)); | 1212 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer `%s' without address request \n", GNUNET_i2s(&address->peer)); |
1179 | return; | 1213 | return; |
1180 | } | 1214 | } |
1181 | if (NULL != address->solver_information) | ||
1182 | { | ||
1183 | GNUNET_break (0); | ||
1184 | } | ||
1185 | 1215 | ||
1186 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer `%s' with address request \n", GNUNET_i2s(&address->peer)); | 1216 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer `%s' with address request \n", GNUNET_i2s(&address->peer)); |
1187 | /* Problem size changed: new address for peer with pending request */ | 1217 | /* Problem size changed: new address for peer with pending request */ |
@@ -1347,14 +1377,17 @@ GAS_mlp_address_delete (void *solver, | |||
1347 | { | 1377 | { |
1348 | struct ATS_Peer *p; | 1378 | struct ATS_Peer *p; |
1349 | struct GAS_MLP_Handle *mlp = solver; | 1379 | struct GAS_MLP_Handle *mlp = solver; |
1380 | struct MLP_information *mlpi; | ||
1350 | 1381 | ||
1351 | GNUNET_assert (NULL != solver); | 1382 | GNUNET_assert (NULL != solver); |
1352 | GNUNET_assert (NULL != addresses); | 1383 | GNUNET_assert (NULL != addresses); |
1353 | GNUNET_assert (NULL != address); | 1384 | GNUNET_assert (NULL != address); |
1354 | 1385 | ||
1355 | if (NULL != address->solver_information) | 1386 | mlpi = address->solver_information; |
1387 | |||
1388 | if (NULL != mlpi) | ||
1356 | { | 1389 | { |
1357 | GNUNET_free (address->solver_information); | 1390 | GNUNET_free (mlpi); |
1358 | address->solver_information = NULL; | 1391 | address->solver_information = NULL; |
1359 | } | 1392 | } |
1360 | 1393 | ||
@@ -1393,11 +1426,8 @@ mlp_get_preferred_address_it (void *cls, const struct GNUNET_HashCode * key, voi | |||
1393 | if (mlpi->n == GNUNET_YES) | 1426 | if (mlpi->n == GNUNET_YES) |
1394 | { | 1427 | { |
1395 | aa = addr; | 1428 | aa = addr; |
1396 | if (mlpi->b > (double) UINT32_MAX) | 1429 | aa->assigned_bw_in = mlpi->b_in; |
1397 | aa->assigned_bw_out.value__ = htonl (UINT32_MAX); | 1430 | aa->assigned_bw_out = mlpi->b_out; |
1398 | else | ||
1399 | aa->assigned_bw_out.value__ = htonl((uint32_t) mlpi->b); | ||
1400 | aa->assigned_bw_in.value__ = htonl(0); | ||
1401 | return GNUNET_NO; | 1431 | return GNUNET_NO; |
1402 | } | 1432 | } |
1403 | return GNUNET_YES; | 1433 | return GNUNET_YES; |
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index 235b7d14d..9bd18f31f 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h | |||
@@ -284,8 +284,12 @@ struct GAS_MLP_Handle | |||
284 | */ | 284 | */ |
285 | struct MLP_information | 285 | struct MLP_information |
286 | { | 286 | { |
287 | double b; | ||
288 | 287 | ||
288 | /* Bandwidth assigned */ | ||
289 | struct GNUNET_BANDWIDTH_Value32NBO b_out; | ||
290 | struct GNUNET_BANDWIDTH_Value32NBO b_in; | ||
291 | |||
292 | /* Address selected */ | ||
289 | int n; | 293 | int n; |
290 | 294 | ||
291 | /* bandwidth column index */ | 295 | /* bandwidth column index */ |