aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-02-27 16:39:19 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-02-27 16:39:19 +0000
commitc2317d734f36c120155550898a6dcda711910fcb (patch)
tree2d4faec810204812dda4f7f0748bb47c0cb3939d /src
parentbe03b31aa11333f56ba62009709fc955ecdf46fd (diff)
downloadgnunet-c2317d734f36c120155550898a6dcda711910fcb.tar.gz
gnunet-c2317d734f36c120155550898a6dcda711910fcb.zip
switching networks
Diffstat (limited to 'src')
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c80
1 files changed, 74 insertions, 6 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index ecc6f95f0..af30ecd1b 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -1042,7 +1042,9 @@ GAS_mlp_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addres
1042 1042
1043 1043
1044static void 1044static void
1045mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address, 1045mlp_update_quality (struct GAS_MLP_Handle *mlp,
1046 struct GNUNET_CONTAINER_MultiHashMap *addresses,
1047 struct ATS_Address * address,
1046 const struct GNUNET_ATS_Information *ats, uint32_t ats_count) 1048 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
1047{ 1049{
1048 struct MLP_information *mlpi = address->solver_information; 1050 struct MLP_information *mlpi = address->solver_information;
@@ -1052,6 +1054,7 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1052 unsigned int c_queue_it; 1054 unsigned int c_queue_it;
1053 unsigned int c_row; 1055 unsigned int c_row;
1054 unsigned int c_qual; 1056 unsigned int c_qual;
1057 unsigned int c_net;
1055 int qual_changed; 1058 int qual_changed;
1056 int type_index; 1059 int type_index;
1057 int avg_index; 1060 int avg_index;
@@ -1077,6 +1080,67 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1077 type_index = -1; 1080 type_index = -1;
1078 avg_index = -1; 1081 avg_index = -1;
1079 1082
1083 /* Check for network update */
1084 if (type == GNUNET_ATS_NETWORK_TYPE)
1085 {
1086 if (address->atsp_network_type != value)
1087 {
1088 LOG (GNUNET_ERROR_TYPE_ERROR, "Updating network for peer `%s' from `%s' to `%s'\n",
1089 GNUNET_i2s (&address->peer),
1090 GNUNET_ATS_print_network_type(address->atsp_network_type),
1091 GNUNET_ATS_print_network_type(value));
1092
1093 }
1094
1095 rows = glp_get_num_rows(mlp->p.prob);
1096 ind = GNUNET_malloc (rows * sizeof (int) + 1);
1097 val = GNUNET_malloc (rows * sizeof (double) + 1);
1098 int length = glp_get_mat_col (mlp->p.prob, mlpi->c_b, ind, val);
1099
1100 for (c_net = 0; c_net <= length + 1; c_net ++)
1101 {
1102 if (ind[c_net] == mlp->p.r_quota[value])
1103 LOG (GNUNET_ERROR_TYPE_ERROR, "New [%u] == [%f]\n",ind[c_net],val[c_net]);
1104 if (ind[c_net] == mlp->p.r_quota[address->atsp_network_type])
1105 {
1106 LOG (GNUNET_ERROR_TYPE_ERROR, "Old [%u] == [%f]\n",ind[c_net],val[c_net]);
1107 break;
1108 }
1109 }
1110 val[c_net] = 0.0;
1111 glp_set_mat_col (mlp->p.prob, mlpi->c_b, length, ind, val);
1112 /* Set updated column */
1113 ind[c_net] = mlp->p.r_quota[value];
1114 val[c_net] = 1.0;
1115 glp_set_mat_col (mlp->p.prob, mlpi->c_b, length, ind, val);
1116 GNUNET_free (ind);
1117 GNUNET_free (val);
1118
1119 rows = glp_get_num_rows(mlp->p.prob);
1120 ind = GNUNET_malloc (rows * sizeof (int) + 1);
1121 val = GNUNET_malloc (rows * sizeof (double) + 1);
1122 length = glp_get_mat_col (mlp->p.prob, mlpi->c_b, ind, val);
1123
1124 for (c_net = 0; c_net <= length + 1; c_net ++)
1125 {
1126 if (ind[c_net] == mlp->p.r_quota[value])
1127 LOG (GNUNET_ERROR_TYPE_ERROR, "New [%u] == [%f]\n",ind[c_net],val[c_net]);
1128 if (ind[c_net] == mlp->p.r_quota[address->atsp_network_type])
1129 {
1130 LOG (GNUNET_ERROR_TYPE_ERROR, "Old [%u] == [%f]\n",ind[c_net],val[c_net]);
1131 break;
1132 }
1133 }
1134
1135 GNUNET_free (ind);
1136 GNUNET_free (val);
1137 address->atsp_network_type = value;
1138 mlp->mlp_prob_changed = GNUNET_YES;
1139
1140 continue;
1141 }
1142
1143
1080 /* Find index for this ATS type */ 1144 /* Find index for this ATS type */
1081 for (c_cmp = 0; c_cmp < mlp->pv.m_q; c_cmp++) 1145 for (c_cmp = 0; c_cmp < mlp->pv.m_q; c_cmp++)
1082 { 1146 {
@@ -1139,14 +1203,18 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1139 } 1203 }
1140 } 1204 }
1141 1205
1206 /* Changed, but quality will be automatically set during rebuild */
1207 if ((GNUNET_YES == mlp->mlp_prob_changed) &&
1208 (GNUNET_YES == mlp->mlp_auto_solve))
1209 {
1210 GAS_mlp_solve_problem (mlp, addresses);
1211 return;
1212 }
1213
1142 /* Update problem matrix if required */ 1214 /* Update problem matrix if required */
1143 if (GNUNET_NO == qual_changed) 1215 if (GNUNET_NO == qual_changed)
1144 return; 1216 return;
1145 1217
1146 /* Changed, but quality will be automatically set during rebuild */
1147 if (GNUNET_YES == mlp->mlp_prob_changed)
1148 return;
1149
1150 /* Address not yet included in matrix */ 1218 /* Address not yet included in matrix */
1151 if (0 == mlpi->c_b) 1219 if (0 == mlpi->c_b)
1152 return; 1220 return;
@@ -1213,7 +1281,7 @@ GAS_mlp_address_update (void *solver,
1213 LOG (GNUNET_ERROR_TYPE_ERROR, _("Updating address for peer `%s' not added before\n"), GNUNET_i2s(&address->peer)); 1281 LOG (GNUNET_ERROR_TYPE_ERROR, _("Updating address for peer `%s' not added before\n"), GNUNET_i2s(&address->peer));
1214 return; 1282 return;
1215 } 1283 }
1216 mlp_update_quality (mlp, address, atsi, atsi_count); 1284 mlp_update_quality (mlp, addresses, address, atsi, atsi_count);
1217 1285
1218 /* Is this peer included in the problem? */ 1286 /* Is this peer included in the problem? */
1219 if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->peers, &address->peer.hashPubKey))) 1287 if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->peers, &address->peer.hashPubKey)))