diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-12 09:59:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-12 09:59:00 +0000 |
commit | 47f8e95b1b10961d37e7fd3ae26c697130ce9e91 (patch) | |
tree | c786f63a8355131a92af74800b46858ab9694536 /src/ats/plugin_ats_ril.c | |
parent | e2e4a05a592edb53c7ba182564b2c9b4c11388ca (diff) | |
download | gnunet-47f8e95b1b10961d37e7fd3ae26c697130ce9e91.tar.gz gnunet-47f8e95b1b10961d37e7fd3ae26c697130ce9e91.zip |
code cleanup
Diffstat (limited to 'src/ats/plugin_ats_ril.c')
-rw-r--r-- | src/ats/plugin_ats_ril.c | 727 |
1 files changed, 382 insertions, 345 deletions
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c index fef969a89..03bddad50 100644 --- a/src/ats/plugin_ats_ril.c +++ b/src/ats/plugin_ats_ril.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2011-2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -24,7 +24,13 @@ | |||
24 | * @author Fabian Oehlmann | 24 | * @author Fabian Oehlmann |
25 | * @author Matthias Wachs | 25 | * @author Matthias Wachs |
26 | */ | 26 | */ |
27 | #include "plugin_ats_ril.h" | 27 | #include "platform.h" |
28 | #include <float.h> | ||
29 | #include <math.h> | ||
30 | #include "gnunet_ats_plugin.h" | ||
31 | #include "gnunet-service-ats_addresses.h" | ||
32 | |||
33 | |||
28 | 34 | ||
29 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__) | 35 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__) |
30 | 36 | ||
@@ -2130,11 +2136,11 @@ ril_cut_from_vector (void **old, | |||
2130 | * @param kind the kind to change the preference | 2136 | * @param kind the kind to change the preference |
2131 | * @param pref_rel the normalized preference value for this kind over all clients | 2137 | * @param pref_rel the normalized preference value for this kind over all clients |
2132 | */ | 2138 | */ |
2133 | void | 2139 | static void |
2134 | GAS_ril_address_change_preference (void *solver, | 2140 | GAS_ril_address_change_preference (void *solver, |
2135 | const struct GNUNET_PeerIdentity *peer, | 2141 | const struct GNUNET_PeerIdentity *peer, |
2136 | enum GNUNET_ATS_PreferenceKind kind, | 2142 | enum GNUNET_ATS_PreferenceKind kind, |
2137 | double pref_rel) | 2143 | double pref_rel) |
2138 | { | 2144 | { |
2139 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2145 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2140 | "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n", | 2146 | "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n", |
@@ -2147,308 +2153,6 @@ GAS_ril_address_change_preference (void *solver, | |||
2147 | ril_step (s); | 2153 | ril_step (s); |
2148 | } | 2154 | } |
2149 | 2155 | ||
2150 | /** | ||
2151 | * Entry point for the plugin | ||
2152 | * | ||
2153 | * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment' | ||
2154 | */ | ||
2155 | void * | ||
2156 | libgnunet_plugin_ats_ril_init (void *cls) | ||
2157 | { | ||
2158 | struct GNUNET_ATS_PluginEnvironment *env = cls; | ||
2159 | struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle); | ||
2160 | struct RIL_Scope * cur; | ||
2161 | int c; | ||
2162 | char *string; | ||
2163 | float f_tmp; | ||
2164 | |||
2165 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n"); | ||
2166 | |||
2167 | GNUNET_assert(NULL != env); | ||
2168 | GNUNET_assert(NULL != env->cfg); | ||
2169 | GNUNET_assert(NULL != env->stats); | ||
2170 | GNUNET_assert(NULL != env->bandwidth_changed_cb); | ||
2171 | GNUNET_assert(NULL != env->get_preferences); | ||
2172 | GNUNET_assert(NULL != env->get_property); | ||
2173 | |||
2174 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor)) | ||
2175 | { | ||
2176 | solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR; | ||
2177 | } | ||
2178 | |||
2179 | if (GNUNET_OK | ||
2180 | != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MIN", | ||
2181 | &solver->parameters.step_time_min)) | ||
2182 | { | ||
2183 | solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN; | ||
2184 | } | ||
2185 | |||
2186 | if (GNUNET_OK | ||
2187 | != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MAX", | ||
2188 | &solver->parameters.step_time_max)) | ||
2189 | { | ||
2190 | solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX; | ||
2191 | } | ||
2192 | |||
2193 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_ALGORITHM", &string)) | ||
2194 | { | ||
2195 | solver->parameters.algorithm = !strcmp (string, "SARSA") ? RIL_ALGO_SARSA : RIL_ALGO_Q; | ||
2196 | GNUNET_free (string); | ||
2197 | } | ||
2198 | else | ||
2199 | { | ||
2200 | solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM; | ||
2201 | } | ||
2202 | |||
2203 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SELECT", &string)) | ||
2204 | { | ||
2205 | solver->parameters.select = !strcmp (string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX; | ||
2206 | GNUNET_free (string); | ||
2207 | } | ||
2208 | else | ||
2209 | { | ||
2210 | solver->parameters.select = RIL_DEFAULT_SELECT; | ||
2211 | } | ||
2212 | |||
2213 | |||
2214 | solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA; | ||
2215 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2216 | "RIL_DISCOUNT_BETA", &f_tmp)) | ||
2217 | { | ||
2218 | if (f_tmp < 0.0) | ||
2219 | { | ||
2220 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2221 | "RIL_DISCOUNT_BETA", f_tmp); | ||
2222 | } | ||
2223 | else | ||
2224 | { | ||
2225 | solver->parameters.beta = f_tmp; | ||
2226 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2227 | "RIL_DISCOUNT_BETA", f_tmp); | ||
2228 | } | ||
2229 | } | ||
2230 | |||
2231 | solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA; | ||
2232 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2233 | "RIL_DISCOUNT_GAMMA", &f_tmp)) | ||
2234 | { | ||
2235 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2236 | { | ||
2237 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2238 | "RIL_DISCOUNT_GAMMA", f_tmp); | ||
2239 | } | ||
2240 | else | ||
2241 | { | ||
2242 | solver->parameters.gamma = f_tmp; | ||
2243 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2244 | "RIL_DISCOUNT_GAMMA", f_tmp); | ||
2245 | } | ||
2246 | } | ||
2247 | |||
2248 | solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE; | ||
2249 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2250 | "RIL_GRADIENT_STEP_SIZE", &f_tmp)) | ||
2251 | { | ||
2252 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2253 | { | ||
2254 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2255 | "RIL_GRADIENT_STEP_SIZE", f_tmp); | ||
2256 | } | ||
2257 | else | ||
2258 | { | ||
2259 | solver->parameters.alpha = f_tmp; | ||
2260 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2261 | "RIL_GRADIENT_STEP_SIZE", f_tmp); | ||
2262 | } | ||
2263 | } | ||
2264 | |||
2265 | solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY; | ||
2266 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2267 | "RIL_TRACE_DECAY", &f_tmp)) | ||
2268 | { | ||
2269 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2270 | { | ||
2271 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2272 | "RIL_TRACE_DECAY", f_tmp); | ||
2273 | } | ||
2274 | else | ||
2275 | { | ||
2276 | solver->parameters.lambda = f_tmp; | ||
2277 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2278 | "RIL_TRACE_DECAY", f_tmp); | ||
2279 | } | ||
2280 | } | ||
2281 | |||
2282 | solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO; | ||
2283 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2284 | "RIL_EXPLORE_RATIO", &f_tmp)) | ||
2285 | { | ||
2286 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2287 | { | ||
2288 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2289 | "RIL_EXPLORE_RATIO", f_tmp); | ||
2290 | } | ||
2291 | else | ||
2292 | { | ||
2293 | solver->parameters.epsilon_init = f_tmp; | ||
2294 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2295 | "RIL_EXPLORE_RATIO", f_tmp); | ||
2296 | } | ||
2297 | } | ||
2298 | |||
2299 | solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY; | ||
2300 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2301 | "RIL_EXPLORE_DECAY", &f_tmp)) | ||
2302 | { | ||
2303 | if ((f_tmp < 0.0) || (f_tmp > 0.0)) | ||
2304 | { | ||
2305 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2306 | "RIL_EXPLORE_DECAY", f_tmp); | ||
2307 | } | ||
2308 | else | ||
2309 | { | ||
2310 | solver->parameters.epsilon_decay = f_tmp; | ||
2311 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2312 | "RIL_EXPLORE_DECAY", f_tmp); | ||
2313 | } | ||
2314 | } | ||
2315 | |||
2316 | solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE; | ||
2317 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2318 | "RIL_TEMPERATURE", &f_tmp)) | ||
2319 | { | ||
2320 | if (f_tmp <= 0.0) | ||
2321 | { | ||
2322 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2323 | "RIL_TEMPERATURE", f_tmp); | ||
2324 | } | ||
2325 | else | ||
2326 | { | ||
2327 | solver->parameters.temperature_init = f_tmp; | ||
2328 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2329 | "RIL_TEMPERATURE", f_tmp); | ||
2330 | } | ||
2331 | } | ||
2332 | |||
2333 | solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY; | ||
2334 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2335 | "RIL_TEMPERATURE_DECAY", &f_tmp)) | ||
2336 | { | ||
2337 | if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1) | ||
2338 | { | ||
2339 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2340 | "RIL_TEMPERATURE_DECAY", f_tmp); | ||
2341 | } | ||
2342 | else | ||
2343 | { | ||
2344 | solver->parameters.temperature_decay = f_tmp; | ||
2345 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2346 | "RIL_TEMPERATURE_DECAY", f_tmp); | ||
2347 | } | ||
2348 | } | ||
2349 | |||
2350 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats", "RIL_SIMULATE", &solver->simulate)) | ||
2351 | { | ||
2352 | solver->simulate = GNUNET_NO; | ||
2353 | } | ||
2354 | |||
2355 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES")) | ||
2356 | { | ||
2357 | solver->parameters.eligibility_trace_mode = RIL_E_REPLACE; | ||
2358 | } | ||
2359 | else | ||
2360 | { | ||
2361 | solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE; | ||
2362 | } | ||
2363 | |||
2364 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string)) | ||
2365 | { | ||
2366 | solver->parameters.social_welfare = !strcmp (string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN; | ||
2367 | GNUNET_free (string); | ||
2368 | } | ||
2369 | else | ||
2370 | { | ||
2371 | solver->parameters.social_welfare = RIL_DEFAULT_WELFARE; | ||
2372 | } | ||
2373 | |||
2374 | env->sf.s_add = &GAS_ril_address_add; | ||
2375 | env->sf.s_address_update_property = &GAS_ril_address_property_changed; | ||
2376 | env->sf.s_address_update_session = &GAS_ril_address_session_changed; | ||
2377 | env->sf.s_address_update_inuse = &GAS_ril_address_inuse_changed; | ||
2378 | env->sf.s_address_update_network = &GAS_ril_address_change_network; | ||
2379 | env->sf.s_get = &GAS_ril_get_preferred_address; | ||
2380 | env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address; | ||
2381 | env->sf.s_pref = &GAS_ril_address_change_preference; | ||
2382 | env->sf.s_feedback = &GAS_ril_address_preference_feedback; | ||
2383 | env->sf.s_del = &GAS_ril_address_delete; | ||
2384 | env->sf.s_bulk_start = &GAS_ril_bulk_start; | ||
2385 | env->sf.s_bulk_stop = &GAS_ril_bulk_stop; | ||
2386 | |||
2387 | solver->plugin_envi = env; | ||
2388 | solver->networks_count = env->network_count; | ||
2389 | solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope)); | ||
2390 | solver->step_count = 0; | ||
2391 | solver->done = GNUNET_NO; | ||
2392 | |||
2393 | for (c = 0; c < env->network_count; c++) | ||
2394 | { | ||
2395 | cur = &solver->network_entries[c]; | ||
2396 | cur->type = env->networks[c]; | ||
2397 | cur->bw_in_available = env->in_quota[c]; | ||
2398 | cur->bw_out_available = env->out_quota[c]; | ||
2399 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Quotas for %s network: IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024); | ||
2400 | } | ||
2401 | |||
2402 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n"); | ||
2403 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n", | ||
2404 | solver->parameters.algorithm ? "Q" : "SARSA", | ||
2405 | solver->parameters.alpha, | ||
2406 | solver->parameters.beta, | ||
2407 | solver->parameters.lambda); | ||
2408 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() exploration_ratio = %f, temperature = %f, ActionSelection = %s\n", | ||
2409 | solver->parameters.epsilon, | ||
2410 | solver->parameters.temperature, | ||
2411 | solver->parameters.select ? "EGREEDY" : "SOFTMAX"); | ||
2412 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n", | ||
2413 | solver->parameters.rbf_divisor); | ||
2414 | |||
2415 | return solver; | ||
2416 | } | ||
2417 | |||
2418 | /** | ||
2419 | * Exit point for the plugin | ||
2420 | * | ||
2421 | * @param cls the solver handle | ||
2422 | */ | ||
2423 | void * | ||
2424 | libgnunet_plugin_ats_ril_done (void *cls) | ||
2425 | { | ||
2426 | struct GAS_RIL_Handle *s = cls; | ||
2427 | struct RIL_Peer_Agent *cur_agent; | ||
2428 | struct RIL_Peer_Agent *next_agent; | ||
2429 | |||
2430 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n"); | ||
2431 | |||
2432 | s->done = GNUNET_YES; | ||
2433 | |||
2434 | cur_agent = s->agents_head; | ||
2435 | while (NULL != cur_agent) | ||
2436 | { | ||
2437 | next_agent = cur_agent->next; | ||
2438 | GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent); | ||
2439 | agent_die (s, cur_agent); | ||
2440 | cur_agent = next_agent; | ||
2441 | } | ||
2442 | |||
2443 | if (GNUNET_SCHEDULER_NO_TASK != s->step_next_task_id) | ||
2444 | { | ||
2445 | GNUNET_SCHEDULER_cancel (s->step_next_task_id); | ||
2446 | } | ||
2447 | GNUNET_free(s->network_entries); | ||
2448 | GNUNET_free(s); | ||
2449 | |||
2450 | return NULL; | ||
2451 | } | ||
2452 | 2156 | ||
2453 | /** | 2157 | /** |
2454 | * Add a new address for a peer to the solver | 2158 | * Add a new address for a peer to the solver |
@@ -2459,8 +2163,10 @@ libgnunet_plugin_ats_ril_done (void *cls) | |||
2459 | * @param address the address to add | 2163 | * @param address the address to add |
2460 | * @param network network type of this address | 2164 | * @param network network type of this address |
2461 | */ | 2165 | */ |
2462 | void | 2166 | static void |
2463 | GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network) | 2167 | GAS_ril_address_add (void *solver, |
2168 | struct ATS_Address *address, | ||
2169 | uint32_t network) | ||
2464 | { | 2170 | { |
2465 | struct GAS_RIL_Handle *s = solver; | 2171 | struct GAS_RIL_Handle *s = solver; |
2466 | struct RIL_Peer_Agent *agent; | 2172 | struct RIL_Peer_Agent *agent; |
@@ -2473,7 +2179,8 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network | |||
2473 | int i; | 2179 | int i; |
2474 | unsigned int zero; | 2180 | unsigned int zero; |
2475 | 2181 | ||
2476 | LOG (GNUNET_ERROR_TYPE_DEBUG, "API_address_add()\n"); | 2182 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2183 | "API_address_add()\n"); | ||
2477 | 2184 | ||
2478 | net = ril_get_network (s, network); | 2185 | net = ril_get_network (s, network); |
2479 | address->solver_information = net; | 2186 | address->solver_information = net; |
@@ -2545,8 +2252,10 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network | |||
2545 | * @param address the address to remove | 2252 | * @param address the address to remove |
2546 | * @param session_only delete only session not whole address | 2253 | * @param session_only delete only session not whole address |
2547 | */ | 2254 | */ |
2548 | void | 2255 | static void |
2549 | GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only) | 2256 | GAS_ril_address_delete (void *solver, |
2257 | struct ATS_Address *address, | ||
2258 | int session_only) | ||
2550 | { | 2259 | { |
2551 | struct GAS_RIL_Handle *s = solver; | 2260 | struct GAS_RIL_Handle *s = solver; |
2552 | struct RIL_Peer_Agent *agent; | 2261 | struct RIL_Peer_Agent *agent; |
@@ -2558,9 +2267,11 @@ GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_o | |||
2558 | int i; | 2267 | int i; |
2559 | struct RIL_Scope *net; | 2268 | struct RIL_Scope *net; |
2560 | 2269 | ||
2561 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() Delete %s%s %s address %s for peer '%s'\n", | 2270 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2562 | session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin, | 2271 | "API_address_delete() Delete %s%s %s address %s for peer '%s'\n", |
2563 | address->addr, GNUNET_i2s (&address->peer)); | 2272 | session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin, |
2273 | address->addr, | ||
2274 | GNUNET_i2s (&address->peer)); | ||
2564 | 2275 | ||
2565 | agent = ril_get_agent (s, &address->peer, GNUNET_NO); | 2276 | agent = ril_get_agent (s, &address->peer, GNUNET_NO); |
2566 | if (NULL == agent) | 2277 | if (NULL == agent) |
@@ -2649,25 +2360,29 @@ GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_o | |||
2649 | * @param abs_value the absolute value of the property | 2360 | * @param abs_value the absolute value of the property |
2650 | * @param rel_value the normalized value | 2361 | * @param rel_value the normalized value |
2651 | */ | 2362 | */ |
2652 | void | 2363 | static void |
2653 | GAS_ril_address_property_changed (void *solver, | 2364 | GAS_ril_address_property_changed (void *solver, |
2654 | struct ATS_Address *address, | 2365 | struct ATS_Address *address, |
2655 | uint32_t type, | 2366 | uint32_t type, |
2656 | uint32_t abs_value, | 2367 | uint32_t abs_value, |
2657 | double rel_value) | 2368 | double rel_value) |
2658 | { | 2369 | { |
2370 | struct GAS_RIL_Handle *s = solver; | ||
2371 | |||
2659 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2372 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2660 | "API_address_property_changed() Property '%s' for peer '%s' address %s changed " | 2373 | "API_address_property_changed() Property '%s' for peer '%s' address %s changed " |
2661 | "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer), | 2374 | "to %.2f \n", |
2375 | GNUNET_ATS_print_property_type (type), | ||
2376 | GNUNET_i2s (&address->peer), | ||
2662 | address->addr, rel_value); | 2377 | address->addr, rel_value); |
2663 | 2378 | ||
2664 | struct GAS_RIL_Handle *s = solver; | ||
2665 | 2379 | ||
2666 | s->parameters.temperature = s->parameters.temperature_init; | 2380 | s->parameters.temperature = s->parameters.temperature_init; |
2667 | s->parameters.epsilon = s->parameters.epsilon_init; | 2381 | s->parameters.epsilon = s->parameters.epsilon_init; |
2668 | ril_step (s); | 2382 | ril_step (s); |
2669 | } | 2383 | } |
2670 | 2384 | ||
2385 | |||
2671 | /** | 2386 | /** |
2672 | * Update the session of an address in the solver | 2387 | * Update the session of an address in the solver |
2673 | * | 2388 | * |
@@ -2678,15 +2393,17 @@ GAS_ril_address_property_changed (void *solver, | |||
2678 | * @param cur_session the current session | 2393 | * @param cur_session the current session |
2679 | * @param new_session the new session | 2394 | * @param new_session the new session |
2680 | */ | 2395 | */ |
2681 | void | 2396 | static void |
2682 | GAS_ril_address_session_changed (void *solver, | 2397 | GAS_ril_address_session_changed (void *solver, |
2683 | struct ATS_Address *address, | 2398 | struct ATS_Address *address, |
2684 | uint32_t cur_session, | 2399 | uint32_t cur_session, |
2685 | uint32_t new_session) | 2400 | uint32_t new_session) |
2686 | { | 2401 | { |
2687 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n"); | 2402 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2403 | "API_address_session_changed()\n"); | ||
2688 | } | 2404 | } |
2689 | 2405 | ||
2406 | |||
2690 | /** | 2407 | /** |
2691 | * Notify the solver that an address is (not) actively used by transport | 2408 | * Notify the solver that an address is (not) actively used by transport |
2692 | * to communicate with a remote peer | 2409 | * to communicate with a remote peer |
@@ -2697,14 +2414,17 @@ GAS_ril_address_session_changed (void *solver, | |||
2697 | * @param address the address | 2414 | * @param address the address |
2698 | * @param in_use usage state | 2415 | * @param in_use usage state |
2699 | */ | 2416 | */ |
2700 | void | 2417 | static void |
2701 | GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use) | 2418 | GAS_ril_address_inuse_changed (void *solver, |
2419 | struct ATS_Address *address, | ||
2420 | int in_use) | ||
2702 | { | 2421 | { |
2703 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2422 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2704 | "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n", | 2423 | "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n", |
2705 | address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED"); | 2424 | address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED"); |
2706 | } | 2425 | } |
2707 | 2426 | ||
2427 | |||
2708 | /** | 2428 | /** |
2709 | * Notify solver that the network an address is located in has changed | 2429 | * Notify solver that the network an address is located in has changed |
2710 | * | 2430 | * |
@@ -2715,16 +2435,17 @@ GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in | |||
2715 | * @param current_network the current network | 2435 | * @param current_network the current network |
2716 | * @param new_network the new network | 2436 | * @param new_network the new network |
2717 | */ | 2437 | */ |
2718 | void | 2438 | static void |
2719 | GAS_ril_address_change_network (void *solver, | 2439 | GAS_ril_address_change_network (void *solver, |
2720 | struct ATS_Address *address, | 2440 | struct ATS_Address *address, |
2721 | uint32_t current_network, | 2441 | uint32_t current_network, |
2722 | uint32_t new_network) | 2442 | uint32_t new_network) |
2723 | { | 2443 | { |
2724 | struct GAS_RIL_Handle *s = solver; | 2444 | struct GAS_RIL_Handle *s = solver; |
2725 | struct RIL_Peer_Agent *agent; | 2445 | struct RIL_Peer_Agent *agent; |
2726 | 2446 | ||
2727 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_change_network() Network type changed, moving " | 2447 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2448 | "API_address_change_network() Network type changed, moving " | ||
2728 | "%s address of peer %s from '%s' to '%s'\n", | 2449 | "%s address of peer %s from '%s' to '%s'\n", |
2729 | (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer), | 2450 | (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer), |
2730 | GNUNET_ATS_print_network_type (current_network), GNUNET_ATS_print_network_type (new_network)); | 2451 | GNUNET_ATS_print_network_type (current_network), GNUNET_ATS_print_network_type (new_network)); |
@@ -2750,6 +2471,7 @@ GAS_ril_address_change_network (void *solver, | |||
2750 | address->solver_information = ril_get_network(solver, new_network); | 2471 | address->solver_information = ril_get_network(solver, new_network); |
2751 | } | 2472 | } |
2752 | 2473 | ||
2474 | |||
2753 | /** | 2475 | /** |
2754 | * Give feedback about the current assignment | 2476 | * Give feedback about the current assignment |
2755 | * | 2477 | * |
@@ -2760,7 +2482,7 @@ GAS_ril_address_change_network (void *solver, | |||
2760 | * @param kind the kind to change the preference | 2482 | * @param kind the kind to change the preference |
2761 | * @param score the score | 2483 | * @param score the score |
2762 | */ | 2484 | */ |
2763 | void | 2485 | static void |
2764 | GAS_ril_address_preference_feedback (void *solver, | 2486 | GAS_ril_address_preference_feedback (void *solver, |
2765 | void *application, | 2487 | void *application, |
2766 | const struct GNUNET_PeerIdentity *peer, | 2488 | const struct GNUNET_PeerIdentity *peer, |
@@ -2774,32 +2496,37 @@ GAS_ril_address_preference_feedback (void *solver, | |||
2774 | GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000); | 2496 | GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000); |
2775 | } | 2497 | } |
2776 | 2498 | ||
2499 | |||
2777 | /** | 2500 | /** |
2778 | * Start a bulk operation | 2501 | * Start a bulk operation |
2779 | * | 2502 | * |
2780 | * @param solver the solver | 2503 | * @param solver the solver |
2781 | */ | 2504 | */ |
2782 | void | 2505 | static void |
2783 | GAS_ril_bulk_start (void *solver) | 2506 | GAS_ril_bulk_start (void *solver) |
2784 | { | 2507 | { |
2785 | struct GAS_RIL_Handle *s = solver; | 2508 | struct GAS_RIL_Handle *s = solver; |
2786 | 2509 | ||
2787 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start() lock: %d\n", s->bulk_lock+1); | 2510 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2511 | "API_bulk_start() lock: %d\n", s->bulk_lock+1); | ||
2788 | 2512 | ||
2789 | s->bulk_lock++; | 2513 | s->bulk_lock++; |
2790 | } | 2514 | } |
2791 | 2515 | ||
2516 | |||
2792 | /** | 2517 | /** |
2793 | * Bulk operation done | 2518 | * Bulk operation done |
2794 | * | 2519 | * |
2795 | * @param solver the solver handle | 2520 | * @param solver the solver handle |
2796 | */ | 2521 | */ |
2797 | void | 2522 | static void |
2798 | GAS_ril_bulk_stop (void *solver) | 2523 | GAS_ril_bulk_stop (void *solver) |
2799 | { | 2524 | { |
2800 | struct GAS_RIL_Handle *s = solver; | 2525 | struct GAS_RIL_Handle *s = solver; |
2801 | 2526 | ||
2802 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop() lock: %d\n", s->bulk_lock-1); | 2527 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2528 | "API_bulk_stop() lock: %d\n", | ||
2529 | s->bulk_lock - 1); | ||
2803 | 2530 | ||
2804 | if (s->bulk_lock < 1) | 2531 | if (s->bulk_lock < 1) |
2805 | { | 2532 | { |
@@ -2815,6 +2542,7 @@ GAS_ril_bulk_stop (void *solver) | |||
2815 | } | 2542 | } |
2816 | } | 2543 | } |
2817 | 2544 | ||
2545 | |||
2818 | /** | 2546 | /** |
2819 | * Tell solver to notify ATS if the address to use changes for a specific | 2547 | * Tell solver to notify ATS if the address to use changes for a specific |
2820 | * peer using the bandwidth changed callback | 2548 | * peer using the bandwidth changed callback |
@@ -2825,8 +2553,9 @@ GAS_ril_bulk_stop (void *solver) | |||
2825 | * @param solver the solver handle | 2553 | * @param solver the solver handle |
2826 | * @param peer the identity of the peer | 2554 | * @param peer the identity of the peer |
2827 | */ | 2555 | */ |
2828 | const struct ATS_Address * | 2556 | static const struct ATS_Address * |
2829 | GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer) | 2557 | GAS_ril_get_preferred_address (void *solver, |
2558 | const struct GNUNET_PeerIdentity *peer) | ||
2830 | { | 2559 | { |
2831 | struct GAS_RIL_Handle *s = solver; | 2560 | struct GAS_RIL_Handle *s = solver; |
2832 | struct RIL_Peer_Agent *agent; | 2561 | struct RIL_Peer_Agent *agent; |
@@ -2866,13 +2595,15 @@ GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *p | |||
2866 | * @param solver the solver handle | 2595 | * @param solver the solver handle |
2867 | * @param peer the peer | 2596 | * @param peer the peer |
2868 | */ | 2597 | */ |
2869 | void | 2598 | static void |
2870 | GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer) | 2599 | GAS_ril_stop_get_preferred_address (void *solver, |
2600 | const struct GNUNET_PeerIdentity *peer) | ||
2871 | { | 2601 | { |
2872 | struct GAS_RIL_Handle *s = solver; | 2602 | struct GAS_RIL_Handle *s = solver; |
2873 | struct RIL_Peer_Agent *agent; | 2603 | struct RIL_Peer_Agent *agent; |
2874 | 2604 | ||
2875 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_stop_get_preferred_address()"); | 2605 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2606 | "API_stop_get_preferred_address()"); | ||
2876 | 2607 | ||
2877 | agent = ril_get_agent (s, peer, GNUNET_NO); | 2608 | agent = ril_get_agent (s, peer, GNUNET_NO); |
2878 | 2609 | ||
@@ -2902,4 +2633,310 @@ GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdenti | |||
2902 | GNUNET_i2s (peer), agent->address_inuse->plugin); | 2633 | GNUNET_i2s (peer), agent->address_inuse->plugin); |
2903 | } | 2634 | } |
2904 | 2635 | ||
2636 | |||
2637 | /** | ||
2638 | * Entry point for the plugin | ||
2639 | * | ||
2640 | * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment' | ||
2641 | */ | ||
2642 | void * | ||
2643 | libgnunet_plugin_ats_ril_init (void *cls) | ||
2644 | { | ||
2645 | struct GNUNET_ATS_PluginEnvironment *env = cls; | ||
2646 | struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle); | ||
2647 | struct RIL_Scope * cur; | ||
2648 | int c; | ||
2649 | char *string; | ||
2650 | float f_tmp; | ||
2651 | |||
2652 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n"); | ||
2653 | |||
2654 | GNUNET_assert(NULL != env); | ||
2655 | GNUNET_assert(NULL != env->cfg); | ||
2656 | GNUNET_assert(NULL != env->stats); | ||
2657 | GNUNET_assert(NULL != env->bandwidth_changed_cb); | ||
2658 | GNUNET_assert(NULL != env->get_preferences); | ||
2659 | GNUNET_assert(NULL != env->get_property); | ||
2660 | |||
2661 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor)) | ||
2662 | { | ||
2663 | solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR; | ||
2664 | } | ||
2665 | |||
2666 | if (GNUNET_OK | ||
2667 | != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MIN", | ||
2668 | &solver->parameters.step_time_min)) | ||
2669 | { | ||
2670 | solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN; | ||
2671 | } | ||
2672 | |||
2673 | if (GNUNET_OK | ||
2674 | != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MAX", | ||
2675 | &solver->parameters.step_time_max)) | ||
2676 | { | ||
2677 | solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX; | ||
2678 | } | ||
2679 | |||
2680 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_ALGORITHM", &string)) | ||
2681 | { | ||
2682 | solver->parameters.algorithm = !strcmp (string, "SARSA") ? RIL_ALGO_SARSA : RIL_ALGO_Q; | ||
2683 | GNUNET_free (string); | ||
2684 | } | ||
2685 | else | ||
2686 | { | ||
2687 | solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM; | ||
2688 | } | ||
2689 | |||
2690 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SELECT", &string)) | ||
2691 | { | ||
2692 | solver->parameters.select = !strcmp (string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX; | ||
2693 | GNUNET_free (string); | ||
2694 | } | ||
2695 | else | ||
2696 | { | ||
2697 | solver->parameters.select = RIL_DEFAULT_SELECT; | ||
2698 | } | ||
2699 | |||
2700 | |||
2701 | solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA; | ||
2702 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2703 | "RIL_DISCOUNT_BETA", &f_tmp)) | ||
2704 | { | ||
2705 | if (f_tmp < 0.0) | ||
2706 | { | ||
2707 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2708 | "RIL_DISCOUNT_BETA", f_tmp); | ||
2709 | } | ||
2710 | else | ||
2711 | { | ||
2712 | solver->parameters.beta = f_tmp; | ||
2713 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2714 | "RIL_DISCOUNT_BETA", f_tmp); | ||
2715 | } | ||
2716 | } | ||
2717 | |||
2718 | solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA; | ||
2719 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2720 | "RIL_DISCOUNT_GAMMA", &f_tmp)) | ||
2721 | { | ||
2722 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2723 | { | ||
2724 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2725 | "RIL_DISCOUNT_GAMMA", f_tmp); | ||
2726 | } | ||
2727 | else | ||
2728 | { | ||
2729 | solver->parameters.gamma = f_tmp; | ||
2730 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2731 | "RIL_DISCOUNT_GAMMA", f_tmp); | ||
2732 | } | ||
2733 | } | ||
2734 | |||
2735 | solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE; | ||
2736 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2737 | "RIL_GRADIENT_STEP_SIZE", &f_tmp)) | ||
2738 | { | ||
2739 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2740 | { | ||
2741 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2742 | "RIL_GRADIENT_STEP_SIZE", f_tmp); | ||
2743 | } | ||
2744 | else | ||
2745 | { | ||
2746 | solver->parameters.alpha = f_tmp; | ||
2747 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2748 | "RIL_GRADIENT_STEP_SIZE", f_tmp); | ||
2749 | } | ||
2750 | } | ||
2751 | |||
2752 | solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY; | ||
2753 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2754 | "RIL_TRACE_DECAY", &f_tmp)) | ||
2755 | { | ||
2756 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2757 | { | ||
2758 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2759 | "RIL_TRACE_DECAY", f_tmp); | ||
2760 | } | ||
2761 | else | ||
2762 | { | ||
2763 | solver->parameters.lambda = f_tmp; | ||
2764 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2765 | "RIL_TRACE_DECAY", f_tmp); | ||
2766 | } | ||
2767 | } | ||
2768 | |||
2769 | solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO; | ||
2770 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2771 | "RIL_EXPLORE_RATIO", &f_tmp)) | ||
2772 | { | ||
2773 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2774 | { | ||
2775 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2776 | "RIL_EXPLORE_RATIO", f_tmp); | ||
2777 | } | ||
2778 | else | ||
2779 | { | ||
2780 | solver->parameters.epsilon_init = f_tmp; | ||
2781 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2782 | "RIL_EXPLORE_RATIO", f_tmp); | ||
2783 | } | ||
2784 | } | ||
2785 | |||
2786 | solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY; | ||
2787 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2788 | "RIL_EXPLORE_DECAY", &f_tmp)) | ||
2789 | { | ||
2790 | if ((f_tmp < 0.0) || (f_tmp > 0.0)) | ||
2791 | { | ||
2792 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2793 | "RIL_EXPLORE_DECAY", f_tmp); | ||
2794 | } | ||
2795 | else | ||
2796 | { | ||
2797 | solver->parameters.epsilon_decay = f_tmp; | ||
2798 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2799 | "RIL_EXPLORE_DECAY", f_tmp); | ||
2800 | } | ||
2801 | } | ||
2802 | |||
2803 | solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE; | ||
2804 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2805 | "RIL_TEMPERATURE", &f_tmp)) | ||
2806 | { | ||
2807 | if (f_tmp <= 0.0) | ||
2808 | { | ||
2809 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2810 | "RIL_TEMPERATURE", f_tmp); | ||
2811 | } | ||
2812 | else | ||
2813 | { | ||
2814 | solver->parameters.temperature_init = f_tmp; | ||
2815 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2816 | "RIL_TEMPERATURE", f_tmp); | ||
2817 | } | ||
2818 | } | ||
2819 | |||
2820 | solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY; | ||
2821 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | ||
2822 | "RIL_TEMPERATURE_DECAY", &f_tmp)) | ||
2823 | { | ||
2824 | if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1) | ||
2825 | { | ||
2826 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2827 | "RIL_TEMPERATURE_DECAY", f_tmp); | ||
2828 | } | ||
2829 | else | ||
2830 | { | ||
2831 | solver->parameters.temperature_decay = f_tmp; | ||
2832 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2833 | "RIL_TEMPERATURE_DECAY", f_tmp); | ||
2834 | } | ||
2835 | } | ||
2836 | |||
2837 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats", "RIL_SIMULATE", &solver->simulate)) | ||
2838 | { | ||
2839 | solver->simulate = GNUNET_NO; | ||
2840 | } | ||
2841 | |||
2842 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES")) | ||
2843 | { | ||
2844 | solver->parameters.eligibility_trace_mode = RIL_E_REPLACE; | ||
2845 | } | ||
2846 | else | ||
2847 | { | ||
2848 | solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE; | ||
2849 | } | ||
2850 | |||
2851 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string)) | ||
2852 | { | ||
2853 | solver->parameters.social_welfare = !strcmp (string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN; | ||
2854 | GNUNET_free (string); | ||
2855 | } | ||
2856 | else | ||
2857 | { | ||
2858 | solver->parameters.social_welfare = RIL_DEFAULT_WELFARE; | ||
2859 | } | ||
2860 | |||
2861 | env->sf.s_add = &GAS_ril_address_add; | ||
2862 | env->sf.s_address_update_property = &GAS_ril_address_property_changed; | ||
2863 | env->sf.s_address_update_session = &GAS_ril_address_session_changed; | ||
2864 | env->sf.s_address_update_inuse = &GAS_ril_address_inuse_changed; | ||
2865 | env->sf.s_address_update_network = &GAS_ril_address_change_network; | ||
2866 | env->sf.s_get = &GAS_ril_get_preferred_address; | ||
2867 | env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address; | ||
2868 | env->sf.s_pref = &GAS_ril_address_change_preference; | ||
2869 | env->sf.s_feedback = &GAS_ril_address_preference_feedback; | ||
2870 | env->sf.s_del = &GAS_ril_address_delete; | ||
2871 | env->sf.s_bulk_start = &GAS_ril_bulk_start; | ||
2872 | env->sf.s_bulk_stop = &GAS_ril_bulk_stop; | ||
2873 | |||
2874 | solver->plugin_envi = env; | ||
2875 | solver->networks_count = env->network_count; | ||
2876 | solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope)); | ||
2877 | solver->step_count = 0; | ||
2878 | solver->done = GNUNET_NO; | ||
2879 | |||
2880 | for (c = 0; c < env->network_count; c++) | ||
2881 | { | ||
2882 | cur = &solver->network_entries[c]; | ||
2883 | cur->type = env->networks[c]; | ||
2884 | cur->bw_in_available = env->in_quota[c]; | ||
2885 | cur->bw_out_available = env->out_quota[c]; | ||
2886 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Quotas for %s network: IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024); | ||
2887 | } | ||
2888 | |||
2889 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n"); | ||
2890 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n", | ||
2891 | solver->parameters.algorithm ? "Q" : "SARSA", | ||
2892 | solver->parameters.alpha, | ||
2893 | solver->parameters.beta, | ||
2894 | solver->parameters.lambda); | ||
2895 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() exploration_ratio = %f, temperature = %f, ActionSelection = %s\n", | ||
2896 | solver->parameters.epsilon, | ||
2897 | solver->parameters.temperature, | ||
2898 | solver->parameters.select ? "EGREEDY" : "SOFTMAX"); | ||
2899 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n", | ||
2900 | solver->parameters.rbf_divisor); | ||
2901 | |||
2902 | return solver; | ||
2903 | } | ||
2904 | |||
2905 | |||
2906 | /** | ||
2907 | * Exit point for the plugin | ||
2908 | * | ||
2909 | * @param cls the solver handle | ||
2910 | */ | ||
2911 | void * | ||
2912 | libgnunet_plugin_ats_ril_done (void *cls) | ||
2913 | { | ||
2914 | struct GAS_RIL_Handle *s = cls; | ||
2915 | struct RIL_Peer_Agent *cur_agent; | ||
2916 | struct RIL_Peer_Agent *next_agent; | ||
2917 | |||
2918 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n"); | ||
2919 | |||
2920 | s->done = GNUNET_YES; | ||
2921 | |||
2922 | cur_agent = s->agents_head; | ||
2923 | while (NULL != cur_agent) | ||
2924 | { | ||
2925 | next_agent = cur_agent->next; | ||
2926 | GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent); | ||
2927 | agent_die (s, cur_agent); | ||
2928 | cur_agent = next_agent; | ||
2929 | } | ||
2930 | |||
2931 | if (GNUNET_SCHEDULER_NO_TASK != s->step_next_task_id) | ||
2932 | { | ||
2933 | GNUNET_SCHEDULER_cancel (s->step_next_task_id); | ||
2934 | } | ||
2935 | GNUNET_free(s->network_entries); | ||
2936 | GNUNET_free(s); | ||
2937 | |||
2938 | return NULL; | ||
2939 | } | ||
2940 | |||
2941 | |||
2905 | /* end of plugin_ats_ril.c */ | 2942 | /* end of plugin_ats_ril.c */ |