aboutsummaryrefslogtreecommitdiff
path: root/src/ats/plugin_ats_ril.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-06 12:18:53 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-06 12:18:53 +0000
commit0dcfafed3117b1759f1d4ab3cb5db11952e65061 (patch)
tree91ca5e6e6c86d8fe94d2e48d91de7d81ba6349ea /src/ats/plugin_ats_ril.c
parentca0050772a26fc9251d83146ef9b05b0b56069a9 (diff)
downloadgnunet-0dcfafed3117b1759f1d4ab3cb5db11952e65061.tar.gz
gnunet-0dcfafed3117b1759f1d4ab3cb5db11952e65061.zip
-fix misc minor crashes
Diffstat (limited to 'src/ats/plugin_ats_ril.c')
-rw-r--r--src/ats/plugin_ats_ril.c70
1 files changed, 48 insertions, 22 deletions
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
226struct RIL_Peer_Agent 227struct 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 */
477static double 478static double
478agent_q (struct RIL_Peer_Agent *agent, double *state, int action) 479agent_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)
1529static void 1533static void
1530ril_step (struct GAS_RIL_Handle *solver); 1534ril_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