diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-06 12:18:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-06 12:18:53 +0000 |
commit | 0dcfafed3117b1759f1d4ab3cb5db11952e65061 (patch) | |
tree | 91ca5e6e6c86d8fe94d2e48d91de7d81ba6349ea /src | |
parent | ca0050772a26fc9251d83146ef9b05b0b56069a9 (diff) | |
download | gnunet-0dcfafed3117b1759f1d4ab3cb5db11952e65061.tar.gz gnunet-0dcfafed3117b1759f1d4ab3cb5db11952e65061.zip |
-fix misc minor crashes
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/perf_ats_solver.c | 2 | ||||
-rw-r--r-- | src/ats/plugin_ats_mlp.c | 26 | ||||
-rw-r--r-- | src/ats/plugin_ats_ril.c | 70 |
3 files changed, 58 insertions, 40 deletions
diff --git a/src/ats/perf_ats_solver.c b/src/ats/perf_ats_solver.c index 0d75561bc..e07883471 100644 --- a/src/ats/perf_ats_solver.c +++ b/src/ats/perf_ats_solver.c | |||
@@ -329,6 +329,7 @@ end_now (int res) | |||
329 | GNUNET_free_non_null (ph.iterations_results); | 329 | GNUNET_free_non_null (ph.iterations_results); |
330 | 330 | ||
331 | GAS_normalization_stop (); | 331 | GAS_normalization_stop (); |
332 | GAS_preference_done (); | ||
332 | ret = res; | 333 | ret = res; |
333 | } | 334 | } |
334 | 335 | ||
@@ -1317,6 +1318,7 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
1317 | ph.env.in_quota[c]); | 1318 | ph.env.in_quota[c]); |
1318 | } | 1319 | } |
1319 | GAS_normalization_start (); | 1320 | GAS_normalization_start (); |
1321 | GAS_preference_init (); | ||
1320 | 1322 | ||
1321 | GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string); | 1323 | GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string); |
1322 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string); | 1324 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string); |
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c index 23fbf5063..533aae506 100644 --- a/src/ats/plugin_ats_mlp.c +++ b/src/ats/plugin_ats_mlp.c | |||
@@ -219,11 +219,6 @@ struct GAS_MLP_Handle | |||
219 | struct GNUNET_ATS_PluginEnvironment *env; | 219 | struct GNUNET_ATS_PluginEnvironment *env; |
220 | 220 | ||
221 | /** | 221 | /** |
222 | * Address hashmap for lookups | ||
223 | */ | ||
224 | const struct GNUNET_CONTAINER_MultiPeerMap *addresses; | ||
225 | |||
226 | /** | ||
227 | * Exclude peer from next result propagation | 222 | * Exclude peer from next result propagation |
228 | */ | 223 | */ |
229 | const struct GNUNET_PeerIdentity *exclude_peer; | 224 | const struct GNUNET_PeerIdentity *exclude_peer; |
@@ -1290,8 +1285,9 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp) | |||
1290 | /* create the glpk problem */ | 1285 | /* create the glpk problem */ |
1291 | p->prob = glp_create_prob (); | 1286 | p->prob = glp_create_prob (); |
1292 | GNUNET_assert (NULL != p->prob); | 1287 | GNUNET_assert (NULL != p->prob); |
1293 | p->num_peers = mlp_create_problem_count_peers (mlp->requested_peers, mlp->addresses); | 1288 | p->num_peers = mlp_create_problem_count_peers (mlp->requested_peers, mlp->env->addresses); |
1294 | p->num_addresses = mlp_create_problem_count_addresses (mlp->requested_peers, mlp->addresses); | 1289 | p->num_addresses = mlp_create_problem_count_addresses (mlp->requested_peers, |
1290 | mlp->env->addresses); | ||
1295 | 1291 | ||
1296 | /* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */ | 1292 | /* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */ |
1297 | p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses + | 1293 | p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses + |
@@ -1331,7 +1327,7 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp) | |||
1331 | mlp_create_problem_add_invariant_rows (mlp, p); | 1327 | mlp_create_problem_add_invariant_rows (mlp, p); |
1332 | 1328 | ||
1333 | /* Adding address dependent columns constraint rows */ | 1329 | /* Adding address dependent columns constraint rows */ |
1334 | GNUNET_CONTAINER_multipeermap_iterate (mlp->addresses, | 1330 | GNUNET_CONTAINER_multipeermap_iterate (mlp->env->addresses, |
1335 | &mlp_create_problem_add_address_information, | 1331 | &mlp_create_problem_add_address_information, |
1336 | mlp); | 1332 | mlp); |
1337 | 1333 | ||
@@ -1618,7 +1614,7 @@ GAS_mlp_solve_problem (void *solver) | |||
1618 | notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE); | 1614 | notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE); |
1619 | return GNUNET_OK; /* No pending requests */ | 1615 | return GNUNET_OK; /* No pending requests */ |
1620 | } | 1616 | } |
1621 | if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->addresses)) | 1617 | if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->env->addresses)) |
1622 | { | 1618 | { |
1623 | notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE); | 1619 | notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE); |
1624 | return GNUNET_OK; /* No addresses available */ | 1620 | return GNUNET_OK; /* No addresses available */ |
@@ -1831,7 +1827,7 @@ GAS_mlp_solve_problem (void *solver) | |||
1831 | GAS_INFO_NONE); | 1827 | GAS_INFO_NONE); |
1832 | if ((GNUNET_OK == res_lp) && (GNUNET_OK == mip_res)) | 1828 | if ((GNUNET_OK == res_lp) && (GNUNET_OK == mip_res)) |
1833 | { | 1829 | { |
1834 | GNUNET_CONTAINER_multipeermap_iterate(mlp->addresses, | 1830 | GNUNET_CONTAINER_multipeermap_iterate(mlp->env->addresses, |
1835 | &mlp_propagate_results, mlp); | 1831 | &mlp_propagate_results, mlp); |
1836 | } | 1832 | } |
1837 | notify (mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, | 1833 | notify (mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, |
@@ -2133,7 +2129,7 @@ GAS_mlp_get_preferred_address (void *solver, | |||
2133 | mlp->stat_mlp_prob_changed = GNUNET_YES; | 2129 | mlp->stat_mlp_prob_changed = GNUNET_YES; |
2134 | 2130 | ||
2135 | if ((GNUNET_YES == mlp->opt_mlp_auto_solve)&& | 2131 | if ((GNUNET_YES == mlp->opt_mlp_auto_solve)&& |
2136 | (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->addresses, | 2132 | (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->env->addresses, |
2137 | peer))) | 2133 | peer))) |
2138 | { | 2134 | { |
2139 | mlp->exclude_peer = peer; | 2135 | mlp->exclude_peer = peer; |
@@ -2143,7 +2139,7 @@ GAS_mlp_get_preferred_address (void *solver, | |||
2143 | } | 2139 | } |
2144 | /* Get prefered address */ | 2140 | /* Get prefered address */ |
2145 | res = NULL; | 2141 | res = NULL; |
2146 | GNUNET_CONTAINER_multipeermap_get_multiple (mlp->addresses, peer, | 2142 | GNUNET_CONTAINER_multipeermap_get_multiple (mlp->env->addresses, peer, |
2147 | &mlp_get_preferred_address_it, &res); | 2143 | &mlp_get_preferred_address_it, &res); |
2148 | return res; | 2144 | return res; |
2149 | } | 2145 | } |
@@ -2430,12 +2426,6 @@ libgnunet_plugin_ats_mlp_init (void *cls) | |||
2430 | struct GNUNET_TIME_Relative max_duration; | 2426 | struct GNUNET_TIME_Relative max_duration; |
2431 | long long unsigned int max_iterations; | 2427 | long long unsigned int max_iterations; |
2432 | 2428 | ||
2433 | GNUNET_assert (NULL != env->cfg); | ||
2434 | GNUNET_assert (NULL != env->addresses); | ||
2435 | GNUNET_assert (NULL != env->bandwidth_changed_cb); | ||
2436 | GNUNET_assert (NULL != env->get_preferences); | ||
2437 | GNUNET_assert (NULL != env->get_property); | ||
2438 | |||
2439 | /* Init GLPK environment */ | 2429 | /* Init GLPK environment */ |
2440 | int res = glp_init_env(); | 2430 | int res = glp_init_env(); |
2441 | switch (res) { | 2431 | switch (res) { |
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c index 6718cae22..73bb8d27d 100644 --- a/src/ats/plugin_ats_ril.c +++ b/src/ats/plugin_ats_ril.c | |||
@@ -223,6 +223,7 @@ struct RIL_Address_Wrapped | |||
223 | struct ATS_Address *address_naked; | 223 | struct ATS_Address *address_naked; |
224 | }; | 224 | }; |
225 | 225 | ||
226 | |||
226 | struct RIL_Peer_Agent | 227 | struct RIL_Peer_Agent |
227 | { | 228 | { |
228 | /** | 229 | /** |
@@ -273,7 +274,7 @@ struct RIL_Peer_Agent | |||
273 | /** | 274 | /** |
274 | * Last perceived state feature vector | 275 | * Last perceived state feature vector |
275 | */ | 276 | */ |
276 | double * s_old; | 277 | double *s_old; |
277 | 278 | ||
278 | /** | 279 | /** |
279 | * Last chosen action | 280 | * Last chosen action |
@@ -293,17 +294,17 @@ struct RIL_Peer_Agent | |||
293 | /** | 294 | /** |
294 | * Address in use | 295 | * Address in use |
295 | */ | 296 | */ |
296 | struct ATS_Address * address_inuse; | 297 | struct ATS_Address *address_inuse; |
297 | 298 | ||
298 | /** | 299 | /** |
299 | * Head of addresses DLL | 300 | * Head of addresses DLL |
300 | */ | 301 | */ |
301 | struct RIL_Address_Wrapped * addresses_head; | 302 | struct RIL_Address_Wrapped *addresses_head; |
302 | 303 | ||
303 | /** | 304 | /** |
304 | * Tail of addresses DLL | 305 | * Tail of addresses DLL |
305 | */ | 306 | */ |
306 | struct RIL_Address_Wrapped * addresses_tail; | 307 | struct RIL_Address_Wrapped *addresses_tail; |
307 | 308 | ||
308 | /** | 309 | /** |
309 | * Inbound bandwidth assigned by the agent | 310 | * Inbound bandwidth assigned by the agent |
@@ -323,7 +324,7 @@ struct RIL_Peer_Agent | |||
323 | /** | 324 | /** |
324 | * The address which has to be issued | 325 | * The address which has to be issued |
325 | */ | 326 | */ |
326 | struct ATS_Address * suggestion_address; | 327 | struct ATS_Address *suggestion_address; |
327 | 328 | ||
328 | /** | 329 | /** |
329 | * The agent's last objective value | 330 | * The agent's last objective value |
@@ -475,7 +476,8 @@ struct GAS_RIL_Handle | |||
475 | * @return estimation value | 476 | * @return estimation value |
476 | */ | 477 | */ |
477 | static double | 478 | static double |
478 | agent_q (struct RIL_Peer_Agent *agent, double *state, int action) | 479 | agent_q (struct RIL_Peer_Agent *agent, |
480 | const double *state, int action) | ||
479 | { | 481 | { |
480 | int i; | 482 | int i; |
481 | double result = 0; | 483 | double result = 0; |
@@ -1388,6 +1390,8 @@ agent_select_softmax (struct RIL_Peer_Agent *agent, double *state) | |||
1388 | if (agent_action_is_possible(agent, i)) | 1390 | if (agent_action_is_possible(agent, i)) |
1389 | { | 1391 | { |
1390 | eqt[i] = exp(agent_q(agent,state,i) / agent->envi->parameters.temperature); | 1392 | eqt[i] = exp(agent_q(agent,state,i) / agent->envi->parameters.temperature); |
1393 | if (isinf (eqt[i])) | ||
1394 | eqt[i] = isinf(eqt[i]) * UINT32_MAX; | ||
1391 | sum += eqt[i]; | 1395 | sum += eqt[i]; |
1392 | } | 1396 | } |
1393 | } | 1397 | } |
@@ -1529,6 +1533,7 @@ agent_step (struct RIL_Peer_Agent *agent) | |||
1529 | static void | 1533 | static void |
1530 | ril_step (struct GAS_RIL_Handle *solver); | 1534 | ril_step (struct GAS_RIL_Handle *solver); |
1531 | 1535 | ||
1536 | |||
1532 | /** | 1537 | /** |
1533 | * Task for the scheduler, which performs one step and lets the solver know that | 1538 | * Task for the scheduler, which performs one step and lets the solver know that |
1534 | * no further step is scheduled. | 1539 | * no further step is scheduled. |
@@ -1932,7 +1937,8 @@ ril_step (struct GAS_RIL_Handle *solver) | |||
1932 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 1937 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
1933 | { | 1938 | { |
1934 | if (cur->suggestion_issue) { | 1939 | if (cur->suggestion_issue) { |
1935 | solver->env->bandwidth_changed_cb(solver->env->cls, cur->suggestion_address); | 1940 | solver->env->bandwidth_changed_cb (solver->env->cls, |
1941 | cur->suggestion_address); | ||
1936 | cur->suggestion_issue = GNUNET_NO; | 1942 | cur->suggestion_issue = GNUNET_NO; |
1937 | } | 1943 | } |
1938 | } | 1944 | } |
@@ -2257,7 +2263,7 @@ GAS_ril_address_delete (void *solver, | |||
2257 | struct GAS_RIL_Handle *s = solver; | 2263 | struct GAS_RIL_Handle *s = solver; |
2258 | struct RIL_Peer_Agent *agent; | 2264 | struct RIL_Peer_Agent *agent; |
2259 | struct RIL_Address_Wrapped *address_wrapped; | 2265 | struct RIL_Address_Wrapped *address_wrapped; |
2260 | int address_was_used = address->active; | 2266 | int address_was_used; |
2261 | int address_index; | 2267 | int address_index; |
2262 | unsigned int m_new; | 2268 | unsigned int m_new; |
2263 | unsigned int n_new; | 2269 | unsigned int n_new; |
@@ -2274,9 +2280,9 @@ GAS_ril_address_delete (void *solver, | |||
2274 | if (NULL == agent) | 2280 | if (NULL == agent) |
2275 | { | 2281 | { |
2276 | net = address->solver_information; | 2282 | net = address->solver_information; |
2277 | GNUNET_assert(!ril_network_is_active (s, net->type)); | 2283 | GNUNET_assert(! ril_network_is_active (s, net->type)); |
2278 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2284 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2279 | "No agent allocated for peer yet, since address was in inactive network\n"); | 2285 | "No agent allocated for peer yet, since address was in inactive network\n"); |
2280 | return; | 2286 | return; |
2281 | } | 2287 | } |
2282 | 2288 | ||
@@ -2289,13 +2295,29 @@ GAS_ril_address_delete (void *solver, | |||
2289 | if (NULL == address_wrapped) | 2295 | if (NULL == address_wrapped) |
2290 | { | 2296 | { |
2291 | net = address->solver_information; | 2297 | net = address->solver_information; |
2292 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2298 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2293 | "Address not considered by agent, address was in inactive network\n"); | 2299 | "Address not considered by agent, address was in inactive network\n"); |
2294 | return; | 2300 | return; |
2295 | } | 2301 | } |
2296 | 2302 | GNUNET_CONTAINER_DLL_remove (agent->addresses_head, | |
2297 | GNUNET_CONTAINER_DLL_remove(agent->addresses_head, agent->addresses_tail, address_wrapped); | 2303 | agent->addresses_tail, |
2298 | GNUNET_free(address_wrapped); | 2304 | address_wrapped); |
2305 | GNUNET_free (address_wrapped); | ||
2306 | if (agent->suggestion_address == address) | ||
2307 | { | ||
2308 | agent->suggestion_address = NULL; | ||
2309 | agent->suggestion_issue = GNUNET_NO; | ||
2310 | address_was_used = GNUNET_YES; | ||
2311 | } | ||
2312 | else if (agent->address_inuse == address) | ||
2313 | { | ||
2314 | agent->address_inuse = NULL; | ||
2315 | address_was_used = GNUNET_YES; | ||
2316 | } | ||
2317 | else | ||
2318 | { | ||
2319 | address_was_used = GNUNET_NO; | ||
2320 | } | ||
2299 | 2321 | ||
2300 | //decrease W | 2322 | //decrease W |
2301 | m_new = agent->m - ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)); | 2323 | m_new = agent->m - ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)); |
@@ -2327,8 +2349,8 @@ GAS_ril_address_delete (void *solver, | |||
2327 | } | 2349 | } |
2328 | //decrease old state vector | 2350 | //decrease old state vector |
2329 | ril_cut_from_vector ((void **) &agent->s_old, sizeof(double), | 2351 | ril_cut_from_vector ((void **) &agent->s_old, sizeof(double), |
2330 | address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), | 2352 | address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), |
2331 | ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m); | 2353 | ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m); |
2332 | agent->m = m_new; | 2354 | agent->m = m_new; |
2333 | agent->n = n_new; | 2355 | agent->n = n_new; |
2334 | 2356 | ||
@@ -2336,8 +2358,12 @@ GAS_ril_address_delete (void *solver, | |||
2336 | { | 2358 | { |
2337 | if (NULL != agent->addresses_head) //if peer has an address left, use it | 2359 | if (NULL != agent->addresses_head) //if peer has an address left, use it |
2338 | { | 2360 | { |
2339 | envi_set_active_suggestion (s, agent, agent->addresses_head->address_naked, agent->bw_in, agent->bw_out, | 2361 | envi_set_active_suggestion (s, |
2340 | GNUNET_YES); | 2362 | agent, |
2363 | agent->addresses_head->address_naked, | ||
2364 | agent->bw_in, | ||
2365 | agent->bw_out, | ||
2366 | GNUNET_YES); | ||
2341 | } | 2367 | } |
2342 | else | 2368 | else |
2343 | { | 2369 | { |
@@ -2540,8 +2566,8 @@ GAS_ril_stop_get_preferred_address (void *solver, | |||
2540 | ril_step (s); | 2566 | ril_step (s); |
2541 | 2567 | ||
2542 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2568 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2543 | "API_stop_get_preferred_address() Paused agent for peer '%s' with %s address\n", | 2569 | "API_stop_get_preferred_address() Paused agent for peer '%s'\n", |
2544 | GNUNET_i2s (peer), agent->address_inuse->plugin); | 2570 | GNUNET_i2s (peer)); |
2545 | } | 2571 | } |
2546 | 2572 | ||
2547 | 2573 | ||