aboutsummaryrefslogtreecommitdiff
path: root/src/ats/plugin_ats_mlp.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-05 21:41:58 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-05 21:41:58 +0000
commitb8d5c4c9220576e85b4eec4c7ffa0390ba887fb5 (patch)
treef93ff7c7d94c81f5182e1c4bc7fd829f4fc9a609 /src/ats/plugin_ats_mlp.c
parentd4cb0035c1248e050d906e9018d36a9f5d19eb73 (diff)
downloadgnunet-b8d5c4c9220576e85b4eec4c7ffa0390ba887fb5.tar.gz
gnunet-b8d5c4c9220576e85b4eec4c7ffa0390ba887fb5.zip
first pass at cleaning up ATS plugin API
Diffstat (limited to 'src/ats/plugin_ats_mlp.c')
-rw-r--r--src/ats/plugin_ats_mlp.c149
1 files changed, 63 insertions, 86 deletions
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c
index eeffb3454..11f74a37f 100644
--- a/src/ats/plugin_ats_mlp.c
+++ b/src/ats/plugin_ats_mlp.c
@@ -219,46 +219,11 @@ struct GAS_MLP_Handle
219 struct GNUNET_ATS_PluginEnvironment *env; 219 struct GNUNET_ATS_PluginEnvironment *env;
220 220
221 /** 221 /**
222 * Statistics handle
223 */
224 struct GNUNET_STATISTICS_Handle *stats;
225
226 /**
227 * Address hashmap for lookups 222 * Address hashmap for lookups
228 */ 223 */
229 const struct GNUNET_CONTAINER_MultiPeerMap *addresses; 224 const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
230 225
231 /** 226 /**
232 * Addresses' bandwidth changed callback
233 */
234 GAS_bandwidth_changed_cb bw_changed_cb;
235
236 /**
237 * Addresses' bandwidth changed callback closure
238 */
239 void *bw_changed_cb_cls;
240
241 /**
242 * ATS function to get preferences
243 */
244 GAS_get_preferences get_preferences;
245
246 /**
247 * Closure for ATS function to get preferences
248 */
249 void *get_preferences_cls;
250
251 /**
252 * ATS function to get properties
253 */
254 GAS_get_properties get_properties;
255
256 /**
257 * Closure for ATS function to get properties
258 */
259 void *get_properties_cls;
260
261 /**
262 * Exclude peer from next result propagation 227 * Exclude peer from next result propagation
263 */ 228 */
264 const struct GNUNET_PeerIdentity *exclude_peer; 229 const struct GNUNET_PeerIdentity *exclude_peer;
@@ -281,7 +246,6 @@ struct GAS_MLP_Handle
281 /** 246 /**
282 * Bulk lock 247 * Bulk lock
283 */ 248 */
284
285 int stat_bulk_lock; 249 int stat_bulk_lock;
286 250
287 /** 251 /**
@@ -394,27 +358,41 @@ struct GAS_MLP_Handle
394struct MLP_information 358struct MLP_information
395{ 359{
396 360
397 /* Bandwidth assigned outbound */ 361 /**
362 * Bandwidth assigned outbound
363 */
398 uint32_t b_out; 364 uint32_t b_out;
399 365
400 /* Bandwidth assigned inbound */ 366 /**
367 * Bandwidth assigned inbound
368 */
401 uint32_t b_in; 369 uint32_t b_in;
402 370
403 /* Address selected */ 371 /**
372 * Address selected
373 */
404 int n; 374 int n;
405 375
406 /* bandwidth column index */ 376 /**
377 * bandwidth column index
378 */
407 signed int c_b; 379 signed int c_b;
408 380
409 /* address usage column */ 381 /**
382 * address usage column
383 */
410 signed int c_n; 384 signed int c_n;
411 385
412 /* row indexes */ 386 /* row indexes */
413 387
414 /* constraint 1: bandwidth capping */ 388 /**
389 * constraint 1: bandwidth capping
390 */
415 unsigned int r_c1; 391 unsigned int r_c1;
416 392
417 /* constraint 3: minimum bandwidth */ 393 /**
394 * constraint 3: minimum bandwidth
395 */
418 unsigned int r_c3; 396 unsigned int r_c3;
419}; 397};
420 398
@@ -553,7 +531,7 @@ mlp_term_hook (void *info, const char *s)
553 * @param cls not used 531 * @param cls not used
554 * @param key the key 532 * @param key the key
555 * @param value ATS_Peer 533 * @param value ATS_Peer
556 * @return GNUNET_OK 534 * @return #GNUNET_OK
557 */ 535 */
558static int 536static int
559reset_peers (void *cls, 537reset_peers (void *cls,
@@ -1177,7 +1155,7 @@ mlp_create_problem_add_address_information (void *cls,
1177 /* For all quality metrics, set quality of this address */ 1155 /* For all quality metrics, set quality of this address */
1178 if (GNUNET_YES == mlp->opt_dbg_optimize_quality) 1156 if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
1179 { 1157 {
1180 props = mlp->get_properties (mlp->get_properties_cls, address); 1158 props = mlp->env->get_property (mlp->env->cls, address);
1181 for (c = 0; c < mlp->pv.m_q; c++) 1159 for (c = 0; c < mlp->pv.m_q; c++)
1182 { 1160 {
1183 if ((props[c] < 1.0) && (props[c] > 2.0)) 1161 if ((props[c] < 1.0) && (props[c] > 2.0))
@@ -1473,7 +1451,7 @@ mlp_propagate_results (void *cls,
1473 address->assigned_bw_out = mlp_bw_out; 1451 address->assigned_bw_out = mlp_bw_out;
1474 mlpi->b_out = mlp_bw_out; 1452 mlpi->b_out = mlp_bw_out;
1475 if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer)))) 1453 if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer))))
1476 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); 1454 mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
1477 return GNUNET_OK; 1455 return GNUNET_OK;
1478 } 1456 }
1479 else if (GNUNET_YES == address->active) 1457 else if (GNUNET_YES == address->active)
@@ -1489,7 +1467,7 @@ mlp_propagate_results (void *cls,
1489 address->assigned_bw_out = mlp_bw_out; 1467 address->assigned_bw_out = mlp_bw_out;
1490 mlpi->b_out = mlp_bw_out; 1468 mlpi->b_out = mlp_bw_out;
1491 if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer)))) 1469 if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer))))
1492 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); 1470 mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
1493 return GNUNET_OK; 1471 return GNUNET_OK;
1494 } 1472 }
1495 } 1473 }
@@ -1537,7 +1515,7 @@ notify (struct GAS_MLP_Handle *mlp,
1537 enum GAS_Solver_Additional_Information add) 1515 enum GAS_Solver_Additional_Information add)
1538{ 1516{
1539 if (NULL != mlp->env->info_cb) 1517 if (NULL != mlp->env->info_cb)
1540 mlp->env->info_cb (mlp->env->info_cb_cls, op, stat, add); 1518 mlp->env->info_cb (mlp->env->cls, op, stat, add);
1541} 1519}
1542 1520
1543 1521
@@ -2091,8 +2069,8 @@ get_peer_pref_value (struct GAS_MLP_Handle *mlp,
2091 double res; 2069 double res;
2092 const double *preferences = NULL; 2070 const double *preferences = NULL;
2093 int c; 2071 int c;
2094 preferences = mlp->get_preferences (mlp->get_preferences_cls, peer);
2095 2072
2073 preferences = mlp->env->get_preferences (mlp->env->cls, peer);
2096 res = 0.0; 2074 res = 0.0;
2097 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) 2075 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
2098 { 2076 {
@@ -2230,7 +2208,7 @@ GAS_mlp_address_delete (void *solver,
2230 if (NULL == GAS_mlp_get_preferred_address (solver, &address->peer)) 2208 if (NULL == GAS_mlp_get_preferred_address (solver, &address->peer))
2231 { 2209 {
2232 /* No alternative address, disconnecting peer */ 2210 /* No alternative address, disconnecting peer */
2233 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); 2211 mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
2234 } 2212 }
2235 } 2213 }
2236 2214
@@ -2327,10 +2305,13 @@ GAS_mlp_address_change_preference (void *solver,
2327 struct GAS_MLP_Handle *mlp = solver; 2305 struct GAS_MLP_Handle *mlp = solver;
2328 struct ATS_Peer *p; 2306 struct ATS_Peer *p;
2329 2307
2330 LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing preference for address for peer `%s' to %.2f\n", 2308 LOG (GNUNET_ERROR_TYPE_DEBUG,
2331 GNUNET_i2s(peer), pref_rel); 2309 "Changing preference for address for peer `%s' to %.2f\n",
2310 GNUNET_i2s(peer),
2311 pref_rel);
2332 2312
2333 GNUNET_STATISTICS_update (mlp->stats,"# LP address preference changes", 1, GNUNET_NO); 2313 GNUNET_STATISTICS_update (mlp->env->stats,
2314 "# LP address preference changes", 1, GNUNET_NO);
2334 /* Update the constraints with changed preferences */ 2315 /* Update the constraints with changed preferences */
2335 2316
2336 2317
@@ -2338,14 +2319,20 @@ GAS_mlp_address_change_preference (void *solver,
2338 /* Update relativity constraint c9 */ 2319 /* Update relativity constraint c9 */
2339 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, peer))) 2320 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, peer)))
2340 { 2321 {
2341 LOG (GNUNET_ERROR_TYPE_INFO, "Updating preference for unknown peer `%s'\n", GNUNET_i2s(peer)); 2322 LOG (GNUNET_ERROR_TYPE_INFO,
2323 "Updating preference for unknown peer `%s'\n",
2324 GNUNET_i2s(peer));
2342 return; 2325 return;
2343 } 2326 }
2344 2327
2345 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 2328 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
2346 { 2329 {
2347 p->f = get_peer_pref_value (mlp, peer); 2330 p->f = get_peer_pref_value (mlp, peer);
2348 mlp_create_problem_update_value (&mlp->p, p->r_c9, mlp->p.c_r, -p->f, __LINE__); 2331 mlp_create_problem_update_value (&mlp->p,
2332 p->r_c9,
2333 mlp->p.c_r,
2334 - p->f,
2335 __LINE__);
2349 2336
2350 /* Problem size changed: new address for peer with pending request */ 2337 /* Problem size changed: new address for peer with pending request */
2351 mlp->stat_mlp_prob_updated = GNUNET_YES; 2338 mlp->stat_mlp_prob_updated = GNUNET_YES;
@@ -2367,16 +2354,16 @@ GAS_mlp_address_change_preference (void *solver,
2367 */ 2354 */
2368static void 2355static void
2369GAS_mlp_address_preference_feedback (void *solver, 2356GAS_mlp_address_preference_feedback (void *solver,
2370 void *application, 2357 struct GNUNET_SERVER_Client *application,
2371 const struct GNUNET_PeerIdentity *peer, 2358 const struct GNUNET_PeerIdentity *peer,
2372 const struct GNUNET_TIME_Relative scope, 2359 const struct GNUNET_TIME_Relative scope,
2373 enum GNUNET_ATS_PreferenceKind kind, 2360 enum GNUNET_ATS_PreferenceKind kind,
2374 double score) 2361 double score)
2375{ 2362{
2376 struct GAS_PROPORTIONAL_Handle *s = solver; 2363 struct GAS_PROPORTIONAL_Handle *s = solver;
2364
2377 GNUNET_assert (NULL != solver); 2365 GNUNET_assert (NULL != solver);
2378 GNUNET_assert (NULL != peer); 2366 GNUNET_assert (NULL != peer);
2379
2380 GNUNET_assert (NULL != s); 2367 GNUNET_assert (NULL != s);
2381} 2368}
2382 2369
@@ -2405,13 +2392,12 @@ mlp_free_peers (void *cls,
2405void * 2392void *
2406libgnunet_plugin_ats_mlp_done (void *cls) 2393libgnunet_plugin_ats_mlp_done (void *cls)
2407{ 2394{
2408 struct GAS_MLP_Handle *mlp = cls; 2395 struct GNUNET_ATS_SolverFunctions *sf = cls;
2409 GNUNET_assert (mlp != NULL); 2396 struct GAS_MLP_Handle *mlp = sf->cls;
2410 2397
2411 LOG (GNUNET_ERROR_TYPE_DEBUG, 2398 LOG (GNUNET_ERROR_TYPE_DEBUG,
2412 "Shutting down mlp solver\n"); 2399 "Shutting down mlp solver\n");
2413 mlp_delete_problem (mlp); 2400 mlp_delete_problem (mlp);
2414
2415 GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers, 2401 GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers,
2416 &mlp_free_peers, 2402 &mlp_free_peers,
2417 mlp->requested_peers); 2403 mlp->requested_peers);
@@ -2431,6 +2417,7 @@ libgnunet_plugin_ats_mlp_done (void *cls)
2431void * 2417void *
2432libgnunet_plugin_ats_mlp_init (void *cls) 2418libgnunet_plugin_ats_mlp_init (void *cls)
2433{ 2419{
2420 static struct GNUNET_ATS_SolverFunctions sf;
2434 struct GNUNET_ATS_PluginEnvironment *env = cls; 2421 struct GNUNET_ATS_PluginEnvironment *env = cls;
2435 struct GAS_MLP_Handle * mlp = GNUNET_new (struct GAS_MLP_Handle); 2422 struct GAS_MLP_Handle * mlp = GNUNET_new (struct GAS_MLP_Handle);
2436 2423
@@ -2826,28 +2813,18 @@ libgnunet_plugin_ats_mlp_init (void *cls)
2826 } 2813 }
2827 } 2814 }
2828 mlp->env = env; 2815 mlp->env = env;
2829 env->sf.s_add = &GAS_mlp_address_add; 2816 sf.cls = mlp;
2830 env->sf.s_address_update_property = &GAS_mlp_address_property_changed; 2817 sf.s_add = &GAS_mlp_address_add;
2831 env->sf.s_get = &GAS_mlp_get_preferred_address; 2818 sf.s_address_update_property = &GAS_mlp_address_property_changed;
2832 env->sf.s_get_stop = &GAS_mlp_stop_get_preferred_address; 2819 sf.s_get = &GAS_mlp_get_preferred_address;
2833 env->sf.s_pref = &GAS_mlp_address_change_preference; 2820 sf.s_get_stop = &GAS_mlp_stop_get_preferred_address;
2834 env->sf.s_feedback = &GAS_mlp_address_preference_feedback; 2821 sf.s_pref = &GAS_mlp_address_change_preference;
2835 env->sf.s_del = &GAS_mlp_address_delete; 2822 sf.s_feedback = &GAS_mlp_address_preference_feedback;
2836 env->sf.s_bulk_start = &GAS_mlp_bulk_start; 2823 sf.s_del = &GAS_mlp_address_delete;
2837 env->sf.s_bulk_stop = &GAS_mlp_bulk_stop; 2824 sf.s_bulk_start = &GAS_mlp_bulk_start;
2838 2825 sf.s_bulk_stop = &GAS_mlp_bulk_stop;
2839
2840 /* Assign options to handle */
2841 mlp->stats = (struct GNUNET_STATISTICS_Handle *) env->stats;
2842 mlp->addresses = env->addresses;
2843 mlp->bw_changed_cb = env->bandwidth_changed_cb;
2844 mlp->bw_changed_cb_cls = env->bw_changed_cb_cls;
2845 mlp->get_preferences = env->get_preferences;
2846 mlp->get_preferences_cls = env->get_preference_cls;
2847 mlp->get_properties = env->get_property;
2848 mlp->get_properties_cls = env->get_property_cls;
2849 /* Setting MLP Input variables */
2850 2826
2827 /* Setting MLP Input variables */
2851 mlp->pv.b_min = b_min; 2828 mlp->pv.b_min = b_min;
2852 mlp->pv.n_min = n_min; 2829 mlp->pv.n_min = n_min;
2853 mlp->pv.m_q = GNUNET_ATS_QualityPropertiesCount; 2830 mlp->pv.m_q = GNUNET_ATS_QualityPropertiesCount;
@@ -2884,7 +2861,7 @@ libgnunet_plugin_ats_mlp_init (void *cls)
2884 2861
2885 LOG (GNUNET_ERROR_TYPE_DEBUG, "solver ready\n"); 2862 LOG (GNUNET_ERROR_TYPE_DEBUG, "solver ready\n");
2886 2863
2887 return mlp; 2864 return &sf;
2888} 2865}
2889 2866
2890/* end of plugin_ats_mlp.c */ 2867/* end of plugin_ats_mlp.c */