aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentd4cb0035c1248e050d906e9018d36a9f5d19eb73 (diff)
downloadgnunet-b8d5c4c9220576e85b4eec4c7ffa0390ba887fb5.tar.gz
gnunet-b8d5c4c9220576e85b4eec4c7ffa0390ba887fb5.zip
first pass at cleaning up ATS plugin API
Diffstat (limited to 'src')
-rw-r--r--src/ats/gnunet-ats-solver-eval.c65
-rw-r--r--src/ats/gnunet-ats-solver-eval.h2
-rw-r--r--src/ats/gnunet-service-ats_plugins.c73
-rw-r--r--src/ats/perf_ats_solver.c135
-rw-r--r--src/ats/plugin_ats_mlp.c149
-rw-r--r--src/ats/plugin_ats_proportional.c139
-rw-r--r--src/ats/plugin_ats_ril.c65
-rw-r--r--src/include/gnunet_ats_plugin.h134
8 files changed, 356 insertions, 406 deletions
diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c
index 6bf640f21..bfb1c84ab 100644
--- a/src/ats/gnunet-ats-solver-eval.c
+++ b/src/ats/gnunet-ats-solver-eval.c
@@ -108,29 +108,6 @@ print_generator_type (enum GeneratorType g)
108 } 108 }
109} 109}
110 110
111struct AddressLookupCtx
112{
113 struct ATS_Address *res;
114 char *plugin;
115 char *addr;
116};
117
118
119int find_address_it (void *cls,
120 const struct GNUNET_PeerIdentity *key,
121 void *value)
122{
123 struct AddressLookupCtx *ctx = cls;
124 struct ATS_Address *addr = value;
125
126 if ( (0 == strcmp (ctx->plugin, addr->plugin)) &&
127 (0 == strcmp (ctx->addr, addr->addr)) )
128 {
129 ctx->res = addr;
130 return GNUNET_NO;
131 }
132 return GNUNET_YES;
133}
134 111
135static struct TestPeer * 112static struct TestPeer *
136find_peer_by_id (int id) 113find_peer_by_id (int id)
@@ -670,17 +647,17 @@ set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
670 atsi.value = htonl ((uint32_t) prop_value); 647 atsi.value = htonl ((uint32_t) prop_value);
671 648
672 /* set performance here! */ 649 /* set performance here! */
673 sh->env.sf.s_bulk_start (sh->solver); 650 sh->sf->s_bulk_start (sh->sf->cls);
674 if (GNUNET_YES == opt_disable_normalization) 651 if (GNUNET_YES == opt_disable_normalization)
675 { 652 {
676 a->prop_abs[pg->ats_property] = prop_value; 653 a->prop_abs[pg->ats_property] = prop_value;
677 a->prop_norm[pg->ats_property] = prop_value; 654 a->prop_norm[pg->ats_property] = prop_value;
678 sh->env.sf.s_address_update_property (sh->solver, a->ats_addr, 655 sh->sf->s_address_update_property (sh->sf->cls, a->ats_addr,
679 pg->ats_property, prop_value, prop_value); 656 pg->ats_property, prop_value, prop_value);
680 } 657 }
681 else 658 else
682 GAS_normalization_normalize_property (pg->test_address->ats_addr, &atsi, 1); 659 GAS_normalization_normalize_property (pg->test_address->ats_addr, &atsi, 1);
683 sh->env.sf.s_bulk_stop (sh->solver); 660 sh->sf->s_bulk_stop (sh->sf->cls);
684 661
685 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency, 662 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
686 &set_prop_task, pg); 663 &set_prop_task, pg);
@@ -949,7 +926,7 @@ set_feedback_task (void *cls,
949 GNUNET_ATS_print_preference_type (pg->kind), 926 GNUNET_ATS_print_preference_type (pg->kind),
950 feedback); 927 feedback);
951 928
952 sh->env.sf.s_feedback (sh->solver, NULL + (pg->client_id), &p->peer_id, 929 sh->sf->s_feedback (sh->sf->cls, NULL + (pg->client_id), &p->peer_id,
953 pg->feedback_frequency, pg->kind, feedback); 930 pg->feedback_frequency, pg->kind, feedback);
954 pg->feedback_last = GNUNET_TIME_absolute_get(); 931 pg->feedback_last = GNUNET_TIME_absolute_get();
955 932
@@ -1003,17 +980,17 @@ set_pref_task (void *cls,
1003 pg->peer, NULL + (pg->client_id), 980 pg->peer, NULL + (pg->client_id),
1004 GNUNET_ATS_print_preference_type (pg->kind), pref_value); 981 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
1005 982
1006 sh->env.sf.s_bulk_start (sh->solver); 983 sh->sf->s_bulk_start (sh->sf->cls);
1007 if (GNUNET_YES == opt_disable_normalization) 984 if (GNUNET_YES == opt_disable_normalization)
1008 { 985 {
1009 p->pref_abs[pg->kind] = pref_value; 986 p->pref_abs[pg->kind] = pref_value;
1010 p->pref_norm[pg->kind] = pref_value; 987 p->pref_norm[pg->kind] = pref_value;
1011 sh->env.sf.s_pref (sh->solver, &p->peer_id, pg->kind, pref_value); 988 sh->sf->s_pref (sh->sf->cls, &p->peer_id, pg->kind, pref_value);
1012 } 989 }
1013 else 990 else
1014 GAS_normalization_normalize_preference (NULL + (pg->client_id), 991 GAS_normalization_normalize_preference (NULL + (pg->client_id),
1015 &p->peer_id, pg->kind, pref_value); 992 &p->peer_id, pg->kind, pref_value);
1016 sh->env.sf.s_bulk_stop (sh->solver); 993 sh->sf->s_bulk_stop (sh->sf->cls);
1017 994
1018 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency, 995 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
1019 set_pref_task, pg); 996 set_pref_task, pg);
@@ -2250,7 +2227,7 @@ enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
2250 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n", 2227 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
2251 op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network)); 2228 op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
2252 2229
2253 sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network); 2230 sh->sf->s_add (sh->sf->cls, a->ats_addr, op->address_network);
2254 2231
2255} 2232}
2256 2233
@@ -2292,7 +2269,7 @@ enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
2292 op->address_id, 2269 op->address_id,
2293 op->peer_id); 2270 op->peer_id);
2294 2271
2295 sh->env.sf.s_del (sh->solver, a->ats_addr, GNUNET_NO); 2272 sh->sf->s_del (sh->sf->cls, a->ats_addr, GNUNET_NO);
2296 2273
2297 if (NULL != l) 2274 if (NULL != l)
2298 { 2275 {
@@ -2437,7 +2414,7 @@ enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
2437 op->peer_id); 2414 op->peer_id);
2438 p->is_requested = GNUNET_YES; 2415 p->is_requested = GNUNET_YES;
2439 2416
2440 res = sh->env.sf.s_get (sh->solver, &p->peer_id); 2417 res = sh->sf->s_get (sh->sf->cls, &p->peer_id);
2441 if (NULL != res) 2418 if (NULL != res)
2442 { 2419 {
2443 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n", 2420 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
@@ -2469,7 +2446,7 @@ enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
2469 p->is_requested = GNUNET_NO; 2446 p->is_requested = GNUNET_NO;
2470 p->assigned_bw_in = 0; 2447 p->assigned_bw_in = 0;
2471 p->assigned_bw_out = 0; 2448 p->assigned_bw_out = 0;
2472 sh->env.sf.s_get_stop (sh->solver, &p->peer_id); 2449 sh->sf->s_get_stop (sh->sf->cls, &p->peer_id);
2473 2450
2474 if (NULL != l) 2451 if (NULL != l)
2475 { 2452 {
@@ -2755,16 +2732,19 @@ GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2755{ 2732{
2756 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats, 2733 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2757 GNUNET_NO); 2734 GNUNET_NO);
2758 GNUNET_PLUGIN_unload (sh->plugin, sh->solver); 2735 GNUNET_PLUGIN_unload (sh->plugin, sh->sf);
2759 2736 sh->sf = NULL;
2760 GAS_normalization_stop(); 2737 GAS_normalization_stop();
2761 2738
2762 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL); 2739 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses,
2740 &free_all_it,
2741 NULL);
2763 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses); 2742 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2764 GNUNET_free (sh->plugin); 2743 GNUNET_free (sh->plugin);
2765 GNUNET_free (sh); 2744 GNUNET_free (sh);
2766} 2745}
2767 2746
2747
2768/** 2748/**
2769 * Load quotas for networks from configuration 2749 * Load quotas for networks from configuration
2770 * 2750 *
@@ -3096,8 +3076,9 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3096 } 3076 }
3097 3077
3098 sh = GNUNET_new (struct SolverHandle); 3078 sh = GNUNET_new (struct SolverHandle);
3099 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str); 3079 GNUNET_asprintf (&sh->plugin,
3100 3080 "libgnunet_plugin_ats_%s",
3081 solver_str);
3101 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); 3082 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
3102 3083
3103 /* setup environment */ 3084 /* setup environment */
@@ -3109,7 +3090,6 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3109 sh->env.get_property = &get_property_cb; 3090 sh->env.get_property = &get_property_cb;
3110 sh->env.network_count = GNUNET_ATS_NetworkTypeCount; 3091 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3111 sh->env.info_cb = &solver_info_cb; 3092 sh->env.info_cb = &solver_info_cb;
3112 sh->env.info_cb_cls = NULL;
3113 sh->env.network_count = GNUNET_ATS_NetworkTypeCount; 3093 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3114 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; 3094 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
3115 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) 3095 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
@@ -3130,8 +3110,8 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3130 return NULL; 3110 return NULL;
3131 } 3111 }
3132 3112
3133 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env); 3113 sh->sf = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
3134 if (NULL == sh->solver) 3114 if (NULL == sh->sf)
3135 { 3115 {
3136 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin); 3116 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
3137 GNUNET_break(0); 3117 GNUNET_break(0);
@@ -3143,6 +3123,7 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3143 return sh; 3123 return sh;
3144} 3124}
3145 3125
3126
3146static void 3127static void
3147done () 3128done ()
3148{ 3129{
diff --git a/src/ats/gnunet-ats-solver-eval.h b/src/ats/gnunet-ats-solver-eval.h
index 808f524da..17dde6e67 100644
--- a/src/ats/gnunet-ats-solver-eval.h
+++ b/src/ats/gnunet-ats-solver-eval.h
@@ -70,7 +70,7 @@ struct SolverHandle
70 /** 70 /**
71 * Solver handle 71 * Solver handle
72 */ 72 */
73 void *solver; 73 struct GNUNET_ATS_SolverFunctions *sf;
74 74
75 /** 75 /**
76 * Address hashmap 76 * Address hashmap
diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c
index 47761fc14..7e03a1a7e 100644
--- a/src/ats/gnunet-service-ats_plugins.c
+++ b/src/ats/gnunet-service-ats_plugins.c
@@ -39,12 +39,12 @@
39static int ats_mode; 39static int ats_mode;
40 40
41/** 41/**
42 * Solver handle. FIXME: TYPE!? 42 * Solver handle.
43 */ 43 */
44static void *solver; 44static struct GNUNET_ATS_SolverFunctions *sf;
45 45
46/** 46/**
47 * Solver functions. FIXME. 47 * Solver environment.
48 */ 48 */
49static struct GNUNET_ATS_PluginEnvironment env; 49static struct GNUNET_ATS_PluginEnvironment env;
50 50
@@ -67,7 +67,7 @@ GAS_normalized_preference_changed (const struct GNUNET_PeerIdentity *peer,
67 double pref_rel) 67 double pref_rel)
68{ 68{
69 /* Tell solver about update */ 69 /* Tell solver about update */
70 env.sf.s_pref (solver, peer, kind, pref_rel); 70 sf->s_pref (sf->cls, peer, kind, pref_rel);
71} 71}
72 72
73 73
@@ -88,11 +88,11 @@ GAS_normalized_property_changed (struct ATS_Address *address,
88 GNUNET_ATS_print_property_type (type), 88 GNUNET_ATS_print_property_type (type),
89 GNUNET_i2s (&address->peer), 89 GNUNET_i2s (&address->peer),
90 prop_rel); 90 prop_rel);
91 env.sf.s_address_update_property (solver, 91 sf->s_address_update_property (sf->cls,
92 address, 92 address,
93 type, 93 type,
94 0, 94 0,
95 prop_rel); 95 prop_rel);
96} 96}
97 97
98 98
@@ -453,14 +453,11 @@ GAS_plugins_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
453 } 453 }
454 454
455 load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount); 455 load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount);
456 env.cls = NULL;
456 env.info_cb = &solver_info_cb; 457 env.info_cb = &solver_info_cb;
457 env.info_cb_cls = NULL;
458 env.bandwidth_changed_cb = &bandwidth_changed_cb; 458 env.bandwidth_changed_cb = &bandwidth_changed_cb;
459 env.bw_changed_cb_cls = NULL;
460 env.get_preferences = &GAS_normalization_get_preferences_by_peer; 459 env.get_preferences = &GAS_normalization_get_preferences_by_peer;
461 env.get_preference_cls = NULL;
462 env.get_property = &GAS_normalization_get_properties; 460 env.get_property = &GAS_normalization_get_properties;
463 env.get_property_cls = NULL;
464 env.cfg = cfg; 461 env.cfg = cfg;
465 env.stats = GSA_stats; 462 env.stats = GSA_stats;
466 env.addresses = GSA_addresses; 463 env.addresses = GSA_addresses;
@@ -495,31 +492,13 @@ GAS_plugins_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
495 "Initializing solver `%s '`%s'\n", 492 "Initializing solver `%s '`%s'\n",
496 plugin_short, 493 plugin_short,
497 plugin); 494 plugin);
498 if (NULL == (solver = GNUNET_PLUGIN_load (plugin, &env))) 495 if (NULL == (sf = GNUNET_PLUGIN_load (plugin, &env)))
499 { 496 {
500 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 497 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
501 _("Failed to initialize solver `%s'!\n"), 498 _("Failed to initialize solver `%s'!\n"),
502 plugin); 499 plugin);
503 return GNUNET_SYSERR; 500 return GNUNET_SYSERR;
504 } 501 }
505
506
507 GNUNET_assert (NULL != env.sf.s_add);
508 GNUNET_assert (NULL != env.sf.s_address_update_property);
509 GNUNET_assert (NULL != env.sf.s_get);
510 GNUNET_assert (NULL != env.sf.s_get_stop);
511 GNUNET_assert (NULL != env.sf.s_pref);
512 GNUNET_assert (NULL != env.sf.s_feedback);
513 GNUNET_assert (NULL != env.sf.s_del);
514 GNUNET_assert (NULL != env.sf.s_bulk_start);
515 GNUNET_assert (NULL != env.sf.s_bulk_stop);
516
517 if (NULL == solver)
518 {
519 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
520 _("Failed to initialize solver!\n"));
521 return GNUNET_SYSERR;
522 }
523 return GNUNET_OK; 502 return GNUNET_OK;
524} 503}
525 504
@@ -531,8 +510,8 @@ void
531GAS_plugins_done () 510GAS_plugins_done ()
532{ 511{
533 GNUNET_PLUGIN_unload (plugin, 512 GNUNET_PLUGIN_unload (plugin,
534 solver); 513 sf);
535 solver = NULL; 514 sf = NULL;
536 GNUNET_free (plugin); 515 GNUNET_free (plugin);
537 plugin = NULL; 516 plugin = NULL;
538} 517}
@@ -544,12 +523,12 @@ GAS_plugin_new_address (struct ATS_Address *new_address,
544 const struct GNUNET_ATS_Information *atsi, 523 const struct GNUNET_ATS_Information *atsi,
545 uint32_t atsi_count) 524 uint32_t atsi_count)
546{ 525{
547 env.sf.s_add (solver, new_address, addr_net); 526 sf->s_add (sf->cls, new_address, addr_net);
548 env.sf.s_bulk_start (solver); 527 sf->s_bulk_start (sf->cls);
549 GAS_normalization_normalize_property (new_address, 528 GAS_normalization_normalize_property (new_address,
550 atsi, 529 atsi,
551 atsi_count); 530 atsi_count);
552 env.sf.s_bulk_stop (solver); 531 sf->s_bulk_stop (sf->cls);
553} 532}
554 533
555 534
@@ -558,18 +537,18 @@ GAS_plugin_update_address (struct ATS_Address *address,
558 const struct GNUNET_ATS_Information *atsi, 537 const struct GNUNET_ATS_Information *atsi,
559 uint32_t atsi_count) 538 uint32_t atsi_count)
560{ 539{
561 env.sf.s_bulk_start (solver); 540 sf->s_bulk_start (sf->cls);
562 GAS_normalization_normalize_property (address, 541 GAS_normalization_normalize_property (address,
563 atsi, 542 atsi,
564 atsi_count); 543 atsi_count);
565 env.sf.s_bulk_stop (solver); 544 sf->s_bulk_stop (sf->cls);
566} 545}
567 546
568 547
569void 548void
570GAS_plugin_delete_address (struct ATS_Address *address) 549GAS_plugin_delete_address (struct ATS_Address *address)
571{ 550{
572 env.sf.s_del (solver, address, GNUNET_NO); 551 sf->s_del (sf->cls, address, GNUNET_NO);
573} 552}
574 553
575 554
@@ -579,10 +558,10 @@ GAS_plugin_update_preferences (void *client,
579 enum GNUNET_ATS_PreferenceKind kind, 558 enum GNUNET_ATS_PreferenceKind kind,
580 float score_abs) 559 float score_abs)
581{ 560{
582 env.sf.s_bulk_start (solver); 561 sf->s_bulk_start (sf->cls);
583 /* Tell normalization about change, normalization will call callback if preference changed */ 562 /* Tell normalization about change, normalization will call callback if preference changed */
584 GAS_normalization_normalize_preference (client, peer, kind, score_abs); 563 GAS_normalization_normalize_preference (client, peer, kind, score_abs);
585 env.sf.s_bulk_stop (solver); 564 sf->s_bulk_stop (sf->cls);
586} 565}
587 566
588 567
@@ -593,7 +572,7 @@ GAS_plugin_preference_feedback (void *application,
593 enum GNUNET_ATS_PreferenceKind kind, 572 enum GNUNET_ATS_PreferenceKind kind,
594 float score_abs) 573 float score_abs)
595{ 574{
596 env.sf.s_feedback (solver, 575 sf->s_feedback (sf->cls,
597 application, 576 application,
598 peer, 577 peer,
599 scope, 578 scope,
@@ -605,14 +584,14 @@ GAS_plugin_preference_feedback (void *application,
605void 584void
606GAS_plugin_solver_lock () 585GAS_plugin_solver_lock ()
607{ 586{
608 env.sf.s_bulk_start (solver); 587 sf->s_bulk_start (sf->cls);
609} 588}
610 589
611 590
612void 591void
613GAS_plugin_solver_unlock () 592GAS_plugin_solver_unlock ()
614{ 593{
615 env.sf.s_bulk_start (solver); 594 sf->s_bulk_start (sf->cls);
616} 595}
617 596
618 597
@@ -621,7 +600,7 @@ GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid)
621{ 600{
622 const struct ATS_Address *aa; 601 const struct ATS_Address *aa;
623 602
624 aa = env.sf.s_get (solver, pid); 603 aa = sf->s_get (sf->cls, pid);
625 if (NULL == aa) 604 if (NULL == aa)
626 { 605 {
627 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 606 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -648,7 +627,7 @@ GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid)
648void 627void
649GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid) 628GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid)
650{ 629{
651 env.sf.s_get_stop (solver, pid); 630 sf->s_get_stop (sf->cls, pid);
652} 631}
653 632
654 633
diff --git a/src/ats/perf_ats_solver.c b/src/ats/perf_ats_solver.c
index 769acea99..d81b5779b 100644
--- a/src/ats/perf_ats_solver.c
+++ b/src/ats/perf_ats_solver.c
@@ -29,6 +29,7 @@
29#include "gnunet-service-ats_addresses.h" 29#include "gnunet-service-ats_addresses.h"
30#include "gnunet-service-ats_plugins.h" 30#include "gnunet-service-ats_plugins.h"
31#include "gnunet-service-ats_normalization.h" 31#include "gnunet-service-ats_normalization.h"
32#include "gnunet-service-ats_preferences.h"
32#include "gnunet_ats_service.h" 33#include "gnunet_ats_service.h"
33#include "gnunet_ats_plugin.h" 34#include "gnunet_ats_plugin.h"
34#include "test_ats_api_common.h" 35#include "test_ats_api_common.h"
@@ -58,7 +59,7 @@ struct PerfHandle
58 /** 59 /**
59 * Solver handle 60 * Solver handle
60 */ 61 */
61 void *solver; 62 struct GNUNET_ATS_SolverFunctions *sf;
62 63
63 /** 64 /**
64 * Statistics stat; 65 * Statistics stat;
@@ -372,7 +373,7 @@ perf_update_address (struct ATS_Address *cur)
372 GNUNET_i2s (&cur->peer), cur, 373 GNUNET_i2s (&cur->peer), cur,
373 "GNUNET_ATS_QUALITY_NET_DELAY", 374 "GNUNET_ATS_QUALITY_NET_DELAY",
374 abs_val, rel_val); 375 abs_val, rel_val);
375 ph.env.sf.s_address_update_property (ph.solver, cur, 376 ph.sf->s_address_update_property (ph.sf->cls, cur,
376 GNUNET_ATS_QUALITY_NET_DELAY, 377 GNUNET_ATS_QUALITY_NET_DELAY,
377 abs_val, rel_val); 378 abs_val, rel_val);
378 break; 379 break;
@@ -384,7 +385,7 @@ perf_update_address (struct ATS_Address *cur)
384 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", 385 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
385 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", 386 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE",
386 abs_val, rel_val); 387 abs_val, rel_val);
387 ph.env.sf.s_address_update_property (ph.solver, cur, 388 ph.sf->s_address_update_property (ph.sf->cls, cur,
388 GNUNET_ATS_QUALITY_NET_DISTANCE, 389 GNUNET_ATS_QUALITY_NET_DISTANCE,
389 abs_val, rel_val); 390 abs_val, rel_val);
390 break; 391 break;
@@ -423,13 +424,13 @@ get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
423const double * 424const double *
424get_property_cb (void *cls, const struct ATS_Address *address) 425get_property_cb (void *cls, const struct ATS_Address *address)
425{ 426{
426 return GAS_normalization_get_properties (NULL, 427 return GAS_normalization_get_properties (NULL,
427 address); 428 address);
428} 429}
429 430
430 431
431static void 432static void
432perf_address_initial_update (void *solver, 433perf_address_initial_update (void *dead,
433 struct GNUNET_CONTAINER_MultiPeerMap * addresses, 434 struct GNUNET_CONTAINER_MultiPeerMap * addresses,
434 struct ATS_Address *address) 435 struct ATS_Address *address)
435{ 436{
@@ -437,19 +438,45 @@ perf_address_initial_update (void *solver,
437 double distance; 438 double distance;
438 uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); 439 uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
439 delay = (100 + (double) random) / 100; 440 delay = (100 + (double) random) / 100;
440 ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY, 441 ph.sf->s_address_update_property (ph.sf->cls,
442 address, GNUNET_ATS_QUALITY_NET_DELAY,
441 100, delay); 443 100, delay);
442 444
443 random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); 445 random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
444 distance = (100 + (double) random) / 100; 446 distance = (100 + (double) random) / 100;
445 447
446 ph.env.sf.s_address_update_property (solver, address, 448 ph.sf->s_address_update_property (ph.sf->cls, address,
447 GNUNET_ATS_QUALITY_NET_DISTANCE, 10, distance); 449 GNUNET_ATS_QUALITY_NET_DISTANCE,
450 10, distance);
448 451
449 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 452 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
450 "Initial update address %p : %.2f %.2f\n", address, delay, distance); 453 "Initial update address %p : %.2f %.2f\n",
454 address, delay, distance);
451} 455}
452 456
457
458struct DUA_Ctx
459{
460 int r;
461 int c_cur_a;
462};
463
464
465static int
466do_update_address (void *cls,
467 const struct GNUNET_PeerIdentity *pid,
468 void *value)
469{
470 struct DUA_Ctx *ctx = cls;
471 struct ATS_Address *addr = value;
472
473 if (ctx->c_cur_a == ctx->r)
474 perf_update_address (addr);
475 ctx->c_cur_a++;
476 return GNUNET_OK;
477}
478
479
453/** 480/**
454 * Update a certain percentage of peers 481 * Update a certain percentage of peers
455 * 482 *
@@ -457,18 +484,16 @@ perf_address_initial_update (void *solver,
457 * @param ca the current number of addresses 484 * @param ca the current number of addresses
458 * @param percentage_peers the percentage of peers to update 485 * @param percentage_peers the percentage of peers to update
459 */ 486 */
460
461static void 487static void
462perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers) 488perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers)
463{ 489{
464 struct ATS_Address *cur_address;
465 int c_peer; 490 int c_peer;
466 int c_select; 491 int c_select;
467 int c_cur_p; 492 int c_cur_p;
468 int c_cur_a;
469 int r; 493 int r;
470 int count; 494 int count;
471 unsigned int m[cp]; 495 unsigned int m[cp];
496 struct DUA_Ctx dua_ctx;
472 497
473 count = cp * ((double) percentage_peers / 100); 498 count = cp * ((double) percentage_peers / 100);
474 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 499 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
@@ -496,15 +521,14 @@ perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percen
496 { 521 {
497 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca); 522 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
498 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 523 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
499 "Updating peer [%u] address [%u]\n", c_cur_p, r); 524 "Updating peer [%u] address [%u]\n", c_cur_p, r);
500 525
501 c_cur_a = 0; 526 dua_ctx.c_cur_a = 0;
502 for (cur_address = ph.peers[c_cur_p].head; NULL != cur_address; cur_address = cur_address->next) 527 dua_ctx.r = r;
503 { 528 GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
504 if (c_cur_a == r) 529 &ph.peers[c_cur_p].id,
505 perf_update_address (cur_address); 530 &do_update_address,
506 c_cur_a ++; 531 &dua_ctx);
507 }
508 } 532 }
509 } 533 }
510} 534}
@@ -520,9 +544,9 @@ static struct ATS_Address *
520perf_create_address (int cp, int ca) 544perf_create_address (int cp, int ca)
521{ 545{
522 struct ATS_Address *a; 546 struct ATS_Address *a;
547
523 a = create_address (&ph.peers[cp].id, 548 a = create_address (&ph.peers[cp].id,
524 "Test 1", "test 1", strlen ("test 1") + 1, 0); 549 "Test 1", "test 1", strlen ("test 1") + 1, 0);
525 GNUNET_CONTAINER_DLL_insert (ph.peers[cp].head, ph.peers[cp].tail, a);
526 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a, 550 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
527 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 551 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
528 return a; 552 return a;
@@ -1028,15 +1052,34 @@ write_all_iterations (void)
1028 GNUNET_free_non_null (data_fn_update); 1052 GNUNET_free_non_null (data_fn_update);
1029} 1053}
1030 1054
1055
1056static int
1057do_delete_address (void *cls,
1058 const struct GNUNET_PeerIdentity *pid,
1059 void *value)
1060{
1061 struct ATS_Address *cur = value;
1062
1063 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1064 "Deleting addresses for peer %u\n",
1065 pid);
1066 GNUNET_assert (GNUNET_OK ==
1067 GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
1068 pid,
1069 cur));
1070 ph.sf->s_del (ph.sf->cls, cur, GNUNET_NO);
1071 GNUNET_free_non_null (cur->atsi);
1072 GNUNET_free (cur);
1073 return GNUNET_OK;
1074}
1075
1076
1031/** 1077/**
1032 * Run a performance iteration 1078 * Run a performance iteration
1033 */ 1079 */
1034
1035static void 1080static void
1036perf_run_iteration (void) 1081perf_run_iteration (void)
1037{ 1082{
1038 struct ATS_Address *cur;
1039 struct ATS_Address *next;
1040 int cp; 1083 int cp;
1041 int ca; 1084 int ca;
1042 int count_p = ph.N_peers_end; 1085 int count_p = ph.N_peers_end;
@@ -1059,7 +1102,7 @@ perf_run_iteration (void)
1059 if (GNUNET_NO == ph.bulk_running) 1102 if (GNUNET_NO == ph.bulk_running)
1060 { 1103 {
1061 ph.bulk_running = GNUNET_YES; 1104 ph.bulk_running = GNUNET_YES;
1062 ph.env.sf.s_bulk_start (ph.solver); 1105 ph.sf->s_bulk_start (ph.sf->cls);
1063 } 1106 }
1064 ph.current_p = cp + 1; 1107 ph.current_p = cp + 1;
1065 for (ca = 0; ca < count_a; ca++) 1108 for (ca = 0; ca < count_a; ca++)
@@ -1078,16 +1121,16 @@ perf_run_iteration (void)
1078 cur_addr->atsi_count = 1; 1121 cur_addr->atsi_count = 1;
1079 cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); 1122 cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1080 cur_addr->atsi[0].value = htonl (net); 1123 cur_addr->atsi[0].value = htonl (net);
1081 ph.env.sf.s_add (ph.solver, cur_addr, net); 1124 ph.sf->s_add (ph.sf->cls, cur_addr, net);
1082 1125
1083 ph.current_a = ca + 1; 1126 ph.current_a = ca + 1;
1084 perf_address_initial_update (ph.solver, ph.addresses, cur_addr); 1127 perf_address_initial_update (NULL, ph.addresses, cur_addr);
1085 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1128 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1086 "Adding address for peer %u address %u in network %s\n", cp, ca, 1129 "Adding address for peer %u address %u in network %s\n", cp, ca,
1087 GNUNET_ATS_print_network_type(net)); 1130 GNUNET_ATS_print_network_type(net));
1088 } 1131 }
1089 /* Notify solver about request */ 1132 /* Notify solver about request */
1090 ph.env.sf.s_get (ph.solver, &ph.peers[cp].id); 1133 ph.sf->s_get (ph.sf->cls, &ph.peers[cp].id);
1091 1134
1092 if (cp + 1 >= ph.N_peers_start) 1135 if (cp + 1 >= ph.N_peers_start)
1093 { 1136 {
@@ -1096,7 +1139,7 @@ perf_run_iteration (void)
1096 { 1139 {
1097 ph.expecting_solution = GNUNET_YES; 1140 ph.expecting_solution = GNUNET_YES;
1098 ph.bulk_running = GNUNET_NO; 1141 ph.bulk_running = GNUNET_NO;
1099 ph.env.sf.s_bulk_stop (ph.solver); 1142 ph.sf->s_bulk_stop (ph.sf->cls);
1100 } 1143 }
1101 else 1144 else
1102 GNUNET_break (0); 1145 GNUNET_break (0);
@@ -1116,11 +1159,11 @@ perf_run_iteration (void)
1116 if (GNUNET_NO == ph.bulk_running) 1159 if (GNUNET_NO == ph.bulk_running)
1117 { 1160 {
1118 ph.bulk_running = GNUNET_YES; 1161 ph.bulk_running = GNUNET_YES;
1119 ph.env.sf.s_bulk_start (ph.solver); 1162 ph.sf->s_bulk_start (ph.sf->cls);
1120 } 1163 }
1121 perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent); 1164 perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
1122 ph.bulk_running = GNUNET_NO; 1165 ph.bulk_running = GNUNET_NO;
1123 ph.env.sf.s_bulk_stop (ph.solver); 1166 ph.sf->s_bulk_stop (ph.sf->cls);
1124 /* Problem is solved by the solver here due to unlocking */ 1167 /* Problem is solved by the solver here due to unlocking */
1125 ph.performed_update = GNUNET_NO; 1168 ph.performed_update = GNUNET_NO;
1126 ph.expecting_solution = GNUNET_NO; 1169 ph.expecting_solution = GNUNET_NO;
@@ -1133,24 +1176,16 @@ perf_run_iteration (void)
1133 "Done, cleaning up addresses\n"); 1176 "Done, cleaning up addresses\n");
1134 if (GNUNET_NO == ph.bulk_running) 1177 if (GNUNET_NO == ph.bulk_running)
1135 { 1178 {
1136 ph.env.sf.s_bulk_start (ph.solver); 1179 ph.sf->s_bulk_start (ph.sf->cls);
1137 ph.bulk_running = GNUNET_YES; 1180 ph.bulk_running = GNUNET_YES;
1138 } 1181 }
1139 1182
1140 for (cp = 0; cp < count_p; cp++) 1183 for (cp = 0; cp < count_p; cp++)
1141 { 1184 {
1142 for (cur = ph.peers[cp].head; cur != NULL ; cur = next) 1185 GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
1143 { 1186 &ph.peers[cp].id,
1144 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1187 &do_delete_address,
1145 "Deleting addresses for peer %u\n", cp); 1188 NULL);
1146 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
1147 &ph.peers[cp].id, cur));
1148 ph.env.sf.s_del (ph.solver, cur, GNUNET_NO);
1149 next = cur->next;
1150 GNUNET_CONTAINER_DLL_remove(ph.peers[cp].head, ph.peers[cp].tail, cur);
1151 GNUNET_free_non_null (cur->atsi);
1152 GNUNET_free (cur);
1153 }
1154 } 1189 }
1155 1190
1156 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1191 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
@@ -1271,7 +1306,6 @@ run (void *cls, char * const *args, const char *cfgfile,
1271 ph.env.get_property = &get_property_cb; 1306 ph.env.get_property = &get_property_cb;
1272 ph.env.network_count = GNUNET_ATS_NetworkTypeCount; 1307 ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
1273 ph.env.info_cb = &solver_info_cb; 1308 ph.env.info_cb = &solver_info_cb;
1274 ph.env.info_cb_cls = NULL;
1275 1309
1276 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; 1310 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
1277 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) 1311 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
@@ -1288,9 +1322,10 @@ run (void *cls, char * const *args, const char *cfgfile,
1288 1322
1289 GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string); 1323 GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string);
1290 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);
1291 if (NULL == (ph.solver = GNUNET_PLUGIN_load (plugin, &ph.env))) 1325 if (NULL == (ph.sf = GNUNET_PLUGIN_load (plugin, &ph.env)))
1292 { 1326 {
1293 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), plugin); 1327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1328 _("Failed to initialize solver `%s'!\n"), plugin);
1294 ret = 1; 1329 ret = 1;
1295 return; 1330 return;
1296 } 1331 }
@@ -1308,7 +1343,8 @@ run (void *cls, char * const *args, const char *cfgfile,
1308 1343
1309 /* Unload solver*/ 1344 /* Unload solver*/
1310 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string); 1345 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string);
1311 GNUNET_PLUGIN_unload (plugin, ph.solver); 1346 GNUNET_PLUGIN_unload (plugin, ph.sf);
1347 ph.sf = NULL;
1312 GNUNET_free (plugin); 1348 GNUNET_free (plugin);
1313 for (c = 0; c < ph.total_iterations; c++ ) 1349 for (c = 0; c < ph.total_iterations; c++ )
1314 { 1350 {
@@ -1328,7 +1364,6 @@ run (void *cls, char * const *args, const char *cfgfile,
1328 1364
1329 GNUNET_CONFIGURATION_destroy (solver_cfg); 1365 GNUNET_CONFIGURATION_destroy (solver_cfg);
1330 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO); 1366 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
1331 ph.solver = NULL;
1332} 1367}
1333 1368
1334/** 1369/**
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 */
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c
index cc5a55ebb..a154ceff3 100644
--- a/src/ats/plugin_ats_proportional.c
+++ b/src/ats/plugin_ats_proportional.c
@@ -217,12 +217,11 @@
217 */ 217 */
218struct GAS_PROPORTIONAL_Handle 218struct GAS_PROPORTIONAL_Handle
219{ 219{
220 struct GNUNET_ATS_PluginEnvironment *env;
221 220
222 /** 221 /**
223 * Statistics handle 222 * Our execution environment.
224 */ 223 */
225 struct GNUNET_STATISTICS_Handle *stats; 224 struct GNUNET_ATS_PluginEnvironment *env;
226 225
227 /** 226 /**
228 * Hashmap containing all valid addresses 227 * Hashmap containing all valid addresses
@@ -235,36 +234,6 @@ struct GAS_PROPORTIONAL_Handle
235 struct GNUNET_CONTAINER_MultiPeerMap *requests; 234 struct GNUNET_CONTAINER_MultiPeerMap *requests;
236 235
237 /** 236 /**
238 * Bandwidth changed callback
239 */
240 GAS_bandwidth_changed_cb bw_changed;
241
242 /**
243 * Bandwidth changed callback cls
244 */
245 void *bw_changed_cls;
246
247 /**
248 * ATS function to get preferences
249 */
250 GAS_get_preferences get_preferences;
251
252 /**
253 * Closure for ATS function to get preferences
254 */
255 void *get_preferences_cls;
256
257 /**
258 * ATS function to get properties
259 */
260 GAS_get_properties get_properties;
261
262 /**
263 * Closure for ATS function to get properties
264 */
265 void *get_properties_cls;
266
267 /**
268 * Bulk lock 237 * Bulk lock
269 */ 238 */
270 int bulk_lock; 239 int bulk_lock;
@@ -418,7 +387,8 @@ struct AddressWrapper
418void * 387void *
419libgnunet_plugin_ats_proportional_done (void *cls) 388libgnunet_plugin_ats_proportional_done (void *cls)
420{ 389{
421 struct GAS_PROPORTIONAL_Handle *s = cls; 390 struct GNUNET_ATS_SolverFunctions *sf = cls;
391 struct GAS_PROPORTIONAL_Handle *s = sf->cls;
422 struct AddressWrapper *cur; 392 struct AddressWrapper *cur;
423 struct AddressWrapper *next; 393 struct AddressWrapper *next;
424 int c; 394 int c;
@@ -572,8 +542,8 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
572 if (GNUNET_YES != cur_address->addr->active) 542 if (GNUNET_YES != cur_address->addr->active)
573 continue; 543 continue;
574 544
575 GNUNET_assert( NULL != (peer_relative_prefs = s->get_preferences (s->get_preferences_cls, 545 GNUNET_assert( NULL != (peer_relative_prefs = s->env->get_preferences (s->env->cls,
576 &cur_address->addr->peer))); 546 &cur_address->addr->peer)));
577 relative_peer_prefence = 0.0; 547 relative_peer_prefence = 0.0;
578 relative_peer_prefence += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; 548 relative_peer_prefence += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
579 sum_relative_peer_prefences += relative_peer_prefence; 549 sum_relative_peer_prefences += relative_peer_prefence;
@@ -608,7 +578,8 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
608 if (GNUNET_YES == cur_address->addr->active) 578 if (GNUNET_YES == cur_address->addr->active)
609 { 579 {
610 GNUNET_assert( NULL != (peer_relative_prefs = 580 GNUNET_assert( NULL != (peer_relative_prefs =
611 s->get_preferences (s->get_preferences_cls, &cur_address->addr->peer))); 581 s->env->get_preferences (s->env->cls,
582 &cur_address->addr->peer)));
612 583
613 cur_pref = peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; 584 cur_pref = peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
614 total_weight = net->active_addresses + 585 total_weight = net->active_addresses +
@@ -767,15 +738,15 @@ find_best_address_it (void *cls,
767 } 738 }
768 739
769 /* Now compare ATS information */ 740 /* Now compare ATS information */
770 norm_prop_cur = ctx->s->get_properties (ctx->s->get_properties_cls, 741 norm_prop_cur = ctx->s->env->get_property (ctx->s->env->cls,
771 (const struct ATS_Address *) current); 742 current);
772 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE); 743 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
773 cur_distance = norm_prop_cur[index]; 744 cur_distance = norm_prop_cur[index];
774 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY); 745 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
775 cur_delay = norm_prop_cur[index]; 746 cur_delay = norm_prop_cur[index];
776 747
777 norm_prop_best = ctx->s->get_properties (ctx->s->get_properties_cls, 748 norm_prop_best = ctx->s->env->get_property (ctx->s->env->cls,
778 (const struct ATS_Address *) ctx->best); 749 ctx->best);
779 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE); 750 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
780 best_distance = norm_prop_best[index]; 751 best_distance = norm_prop_best[index];
781 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY); 752 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
@@ -951,16 +922,20 @@ address_increment (struct GAS_PROPORTIONAL_Handle *s,
951 { 922 {
952 s->total_addresses++; 923 s->total_addresses++;
953 net->total_addresses++; 924 net->total_addresses++;
954 GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", 1, GNUNET_NO); 925 GNUNET_STATISTICS_update (s->env->stats,
955 GNUNET_STATISTICS_update (s->stats, net->stat_total, 1, GNUNET_NO); 926 "# ATS addresses total", 1, GNUNET_NO);
927 GNUNET_STATISTICS_update (s->env->stats,
928 net->stat_total, 1, GNUNET_NO);
956 } 929 }
957 if (GNUNET_YES == active) 930 if (GNUNET_YES == active)
958 { 931 {
959 net->active_addresses++; 932 net->active_addresses++;
960 s->active_addresses++; 933 s->active_addresses++;
961 GNUNET_STATISTICS_update (s->stats, "# ATS active addresses total", 1, 934 GNUNET_STATISTICS_update (s->env->stats,
935 "# ATS active addresses total", 1,
962 GNUNET_NO); 936 GNUNET_NO);
963 GNUNET_STATISTICS_update (s->stats, net->stat_active, 1, GNUNET_NO); 937 GNUNET_STATISTICS_update (s->env->stats,
938 net->stat_active, 1, GNUNET_NO);
964 } 939 }
965 940
966} 941}
@@ -992,7 +967,8 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
992 else 967 else
993 { 968 {
994 s->total_addresses--; 969 s->total_addresses--;
995 GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", -1, 970 GNUNET_STATISTICS_update (s->env->stats,
971 "# ATS addresses total", -1,
996 GNUNET_NO); 972 GNUNET_NO);
997 } 973 }
998 if (net->total_addresses < 1) 974 if (net->total_addresses < 1)
@@ -1003,7 +979,8 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
1003 else 979 else
1004 { 980 {
1005 net->total_addresses--; 981 net->total_addresses--;
1006 GNUNET_STATISTICS_update (s->stats, net->stat_total, -1, GNUNET_NO); 982 GNUNET_STATISTICS_update (s->env->stats,
983 net->stat_total, -1, GNUNET_NO);
1007 } 984 }
1008 } 985 }
1009 986
@@ -1017,7 +994,8 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
1017 else 994 else
1018 { 995 {
1019 net->active_addresses--; 996 net->active_addresses--;
1020 GNUNET_STATISTICS_update (s->stats, net->stat_active, -1, GNUNET_NO); 997 GNUNET_STATISTICS_update (s->env->stats,
998 net->stat_active, -1, GNUNET_NO);
1021 } 999 }
1022 if (s->active_addresses < 1) 1000 if (s->active_addresses < 1)
1023 { 1001 {
@@ -1027,7 +1005,8 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
1027 else 1005 else
1028 { 1006 {
1029 s->active_addresses--; 1007 s->active_addresses--;
1030 GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", -1, 1008 GNUNET_STATISTICS_update (s->env->stats,
1009 "# ATS addresses total", -1,
1031 GNUNET_NO); 1010 GNUNET_NO);
1032 } 1011 }
1033 } 1012 }
@@ -1071,6 +1050,7 @@ propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
1071{ 1050{
1072 struct AddressWrapper *cur; 1051 struct AddressWrapper *cur;
1073 struct AddressSolverInformation *asi; 1052 struct AddressSolverInformation *asi;
1053
1074 for (cur = net->head; NULL != cur; cur = cur->next) 1054 for (cur = net->head; NULL != cur; cur = cur->next)
1075 { 1055 {
1076 asi = cur->addr->solver_information; 1056 asi = cur->addr->solver_information;
@@ -1094,7 +1074,8 @@ propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
1094 /* Notify on change */ 1074 /* Notify on change */
1095 if ((GNUNET_YES == cur->addr->active)) 1075 if ((GNUNET_YES == cur->addr->active))
1096 { 1076 {
1097 s->bw_changed (s->bw_changed_cls, cur->addr); 1077 s->env->bandwidth_changed_cb (s->env->cls,
1078 cur->addr);
1098 } 1079 }
1099 } 1080 }
1100 } 1081 }
@@ -1125,31 +1106,31 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
1125 n->active_addresses, n->total_addresses); 1106 n->active_addresses, n->total_addresses);
1126 1107
1127 if (NULL != s->env->info_cb) 1108 if (NULL != s->env->info_cb)
1128 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START, 1109 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_START,
1129 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); 1110 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
1130 1111
1131 /* Distribute */ 1112 /* Distribute */
1132 distribute_bandwidth(s, n); 1113 distribute_bandwidth(s, n);
1133 1114
1134 if (NULL != s->env->info_cb) 1115 if (NULL != s->env->info_cb)
1135 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP, 1116 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_STOP,
1136 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); 1117 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
1137 if (NULL != s->env->info_cb) 1118 if (NULL != s->env->info_cb)
1138 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, 1119 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
1139 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); 1120 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
1140 1121
1141 /* Do propagation */ 1122 /* Do propagation */
1142 propagate_bandwidth (s, n); 1123 propagate_bandwidth (s, n);
1143 1124
1144 if (NULL != s->env->info_cb) 1125 if (NULL != s->env->info_cb)
1145 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, 1126 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
1146 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE); 1127 GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
1147 } 1128 }
1148 else 1129 else
1149 { 1130 {
1150 int i; 1131 int i;
1151 if (NULL != s->env->info_cb) 1132 if (NULL != s->env->info_cb)
1152 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START, 1133 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_START,
1153 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); 1134 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
1154 for (i = 0; i < s->network_count; i++) 1135 for (i = 0; i < s->network_count; i++)
1155 { 1136 {
@@ -1158,10 +1139,10 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
1158 } 1139 }
1159 1140
1160 if (NULL != s->env->info_cb) 1141 if (NULL != s->env->info_cb)
1161 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP, 1142 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_STOP,
1162 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); 1143 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
1163 if (NULL != s->env->info_cb) 1144 if (NULL != s->env->info_cb)
1164 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, 1145 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
1165 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); 1146 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
1166 for (i = 0; i < s->network_count; i++) 1147 for (i = 0; i < s->network_count; i++)
1167 { 1148 {
@@ -1169,7 +1150,7 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
1169 propagate_bandwidth(s, &s->network_entries[i]); 1150 propagate_bandwidth(s, &s->network_entries[i]);
1170 } 1151 }
1171 if (NULL != s->env->info_cb) 1152 if (NULL != s->env->info_cb)
1172 s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, 1153 s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
1173 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); 1154 GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
1174 } 1155 }
1175} 1156}
@@ -1254,8 +1235,8 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
1254 "Disconnecting peer `%s' with previous address %p\n", 1235 "Disconnecting peer `%s' with previous address %p\n",
1255 GNUNET_i2s (peer), 1236 GNUNET_i2s (peer),
1256 current_address); 1237 current_address);
1257 s->bw_changed (s->bw_changed_cls, 1238 s->env->bandwidth_changed_cb (s->env->cls,
1258 current_address); 1239 current_address);
1259 } 1240 }
1260 } 1241 }
1261 if (NULL == best_address) 1242 if (NULL == best_address)
@@ -1347,7 +1328,7 @@ GAS_proportional_address_change_preference (void *solver,
1347 */ 1328 */
1348static void 1329static void
1349GAS_proportional_address_preference_feedback (void *solver, 1330GAS_proportional_address_preference_feedback (void *solver,
1350 void *application, 1331 struct GNUNET_SERVER_Client *application,
1351 const struct GNUNET_PeerIdentity *peer, 1332 const struct GNUNET_PeerIdentity *peer,
1352 const struct GNUNET_TIME_Relative scope, 1333 const struct GNUNET_TIME_Relative scope,
1353 enum GNUNET_ATS_PreferenceKind kind, 1334 enum GNUNET_ATS_PreferenceKind kind,
@@ -1547,8 +1528,8 @@ GAS_proportional_address_delete (void *solver,
1547 "Disconnecting peer `%s' after deleting previous address %p\n", 1528 "Disconnecting peer `%s' after deleting previous address %p\n",
1548 GNUNET_i2s (&address->peer), 1529 GNUNET_i2s (&address->peer),
1549 address); 1530 address);
1550 s->bw_changed (s->bw_changed_cls, 1531 s->env->bandwidth_changed_cb (s->env->cls,
1551 address); 1532 address);
1552 } 1533 }
1553 } 1534 }
1554 if (GNUNET_NO == session_only) 1535 if (GNUNET_NO == session_only)
@@ -1746,6 +1727,7 @@ GAS_proportional_address_add (void *solver,
1746void * 1727void *
1747libgnunet_plugin_ats_proportional_init (void *cls) 1728libgnunet_plugin_ats_proportional_init (void *cls)
1748{ 1729{
1730 static struct GNUNET_ATS_SolverFunctions sf;
1749 struct GNUNET_ATS_PluginEnvironment *env = cls; 1731 struct GNUNET_ATS_PluginEnvironment *env = cls;
1750 struct GAS_PROPORTIONAL_Handle *s; 1732 struct GAS_PROPORTIONAL_Handle *s;
1751 struct Network * cur; 1733 struct Network * cur;
@@ -1760,24 +1742,17 @@ libgnunet_plugin_ats_proportional_init (void *cls)
1760 1742
1761 s = GNUNET_new (struct GAS_PROPORTIONAL_Handle); 1743 s = GNUNET_new (struct GAS_PROPORTIONAL_Handle);
1762 s->env = env; 1744 s->env = env;
1763 env->sf.s_add = &GAS_proportional_address_add; 1745 sf.cls = s;
1764 env->sf.s_address_update_property = &GAS_proportional_address_property_changed; 1746 sf.s_add = &GAS_proportional_address_add;
1765 env->sf.s_get = &GAS_proportional_get_preferred_address; 1747 sf.s_address_update_property = &GAS_proportional_address_property_changed;
1766 env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address; 1748 sf.s_get = &GAS_proportional_get_preferred_address;
1767 env->sf.s_pref = &GAS_proportional_address_change_preference; 1749 sf.s_get_stop = &GAS_proportional_stop_get_preferred_address;
1768 env->sf.s_feedback = &GAS_proportional_address_preference_feedback; 1750 sf.s_pref = &GAS_proportional_address_change_preference;
1769 env->sf.s_del = &GAS_proportional_address_delete; 1751 sf.s_feedback = &GAS_proportional_address_preference_feedback;
1770 env->sf.s_bulk_start = &GAS_proportional_bulk_start; 1752 sf.s_del = &GAS_proportional_address_delete;
1771 env->sf.s_bulk_stop = &GAS_proportional_bulk_stop; 1753 sf.s_bulk_start = &GAS_proportional_bulk_start;
1772 1754 sf.s_bulk_stop = &GAS_proportional_bulk_stop;
1773 s->stats = (struct GNUNET_STATISTICS_Handle *) env->stats; 1755
1774 s->bw_changed = env->bandwidth_changed_cb;
1775 s->bw_changed_cls = env->bw_changed_cb_cls;
1776 s->get_preferences = env->get_preferences;
1777 s->get_preferences_cls = env->get_preference_cls;
1778 s->get_properties = env->get_property;
1779 s->get_properties_cls = env->get_property_cls;
1780 s->network_count = env->network_count;
1781 s->network_entries = GNUNET_malloc (env->network_count * sizeof (struct Network)); 1756 s->network_entries = GNUNET_malloc (env->network_count * sizeof (struct Network));
1782 1757
1783 /* Init */ 1758 /* Init */
@@ -1849,7 +1824,7 @@ libgnunet_plugin_ats_proportional_init (void *cls)
1849 cur->total_quota_in, 1824 cur->total_quota_in,
1850 cur->total_quota_out); 1825 cur->total_quota_out);
1851 } 1826 }
1852 return s; 1827 return &sf;
1853} 1828}
1854 1829
1855 1830
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c
index 31bed2a27..662935583 100644
--- a/src/ats/plugin_ats_ril.c
+++ b/src/ats/plugin_ats_ril.c
@@ -392,12 +392,7 @@ struct GAS_RIL_Handle
392 /** 392 /**
393 * The solver-plugin environment of the solver-plugin API 393 * The solver-plugin environment of the solver-plugin API
394 */ 394 */
395 struct GNUNET_ATS_PluginEnvironment *plugin_envi; 395 struct GNUNET_ATS_PluginEnvironment *env;
396
397 /**
398 * Statistics handle
399 */
400 struct GNUNET_STATISTICS_Handle *stats;
401 396
402 /** 397 /**
403 * Number of performed steps 398 * Number of performed steps
@@ -786,8 +781,8 @@ ril_inform (struct GAS_RIL_Handle *solver,
786 enum GAS_Solver_Operation op, 781 enum GAS_Solver_Operation op,
787 enum GAS_Solver_Status stat) 782 enum GAS_Solver_Status stat)
788{ 783{
789 if (NULL != solver->plugin_envi->info_cb) 784 if (NULL != solver->env->info_cb)
790 solver->plugin_envi->info_cb (solver->plugin_envi->info_cb_cls, op, stat, GAS_INFO_NONE); 785 solver->env->info_cb (solver->env->cls, op, stat, GAS_INFO_NONE);
791} 786}
792 787
793/** 788/**
@@ -974,8 +969,8 @@ agent_get_utility (struct RIL_Peer_Agent *agent)
974 double delay_norm; 969 double delay_norm;
975 double pref_match; 970 double pref_match;
976 971
977 preferences = agent->envi->plugin_envi->get_preferences (agent->envi->plugin_envi->get_preference_cls, 972 preferences = agent->envi->env->get_preferences (agent->envi->env->cls,
978 &agent->peer); 973 &agent->peer);
979 974
980 delay_atsi = (double) ril_get_atsi (agent->address_inuse, GNUNET_ATS_QUALITY_NET_DELAY); 975 delay_atsi = (double) ril_get_atsi (agent->address_inuse, GNUNET_ATS_QUALITY_NET_DELAY);
981 delay_norm = RIL_UTILITY_DELAY_MAX*exp(-delay_atsi*0.00001); 976 delay_norm = RIL_UTILITY_DELAY_MAX*exp(-delay_atsi*0.00001);
@@ -1937,7 +1932,7 @@ ril_step (struct GAS_RIL_Handle *solver)
1937 for (cur = solver->agents_head; NULL != cur; cur = cur->next) 1932 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
1938 { 1933 {
1939 if (cur->suggestion_issue) { 1934 if (cur->suggestion_issue) {
1940 solver->plugin_envi->bandwidth_changed_cb(solver->plugin_envi->bw_changed_cb_cls, cur->suggestion_address); 1935 solver->env->bandwidth_changed_cb(solver->env->cls, cur->suggestion_address);
1941 cur->suggestion_issue = GNUNET_NO; 1936 cur->suggestion_issue = GNUNET_NO;
1942 } 1937 }
1943 } 1938 }
@@ -2397,16 +2392,19 @@ GAS_ril_address_property_changed (void *solver,
2397 */ 2392 */
2398static void 2393static void
2399GAS_ril_address_preference_feedback (void *solver, 2394GAS_ril_address_preference_feedback (void *solver,
2400 void *application, 2395 struct GNUNET_SERVER_Client *application,
2401 const struct GNUNET_PeerIdentity *peer, 2396 const struct GNUNET_PeerIdentity *peer,
2402 const struct GNUNET_TIME_Relative scope, 2397 const struct GNUNET_TIME_Relative scope,
2403 enum GNUNET_ATS_PreferenceKind kind, 2398 enum GNUNET_ATS_PreferenceKind kind,
2404 double score) 2399 double score)
2405{ 2400{
2406 LOG(GNUNET_ERROR_TYPE_DEBUG, 2401 LOG (GNUNET_ERROR_TYPE_DEBUG,
2407 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for " 2402 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
2408 "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN", 2403 "preference %s for %d seconds\n",
2409 GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000); 2404 GNUNET_i2s (peer),
2405 "UNKNOWN",
2406 GNUNET_ATS_print_preference_type (kind),
2407 scope.rel_value_us / 1000000);
2410} 2408}
2411 2409
2412 2410
@@ -2555,6 +2553,7 @@ GAS_ril_stop_get_preferred_address (void *solver,
2555void * 2553void *
2556libgnunet_plugin_ats_ril_init (void *cls) 2554libgnunet_plugin_ats_ril_init (void *cls)
2557{ 2555{
2556 static struct GNUNET_ATS_SolverFunctions sf;
2558 struct GNUNET_ATS_PluginEnvironment *env = cls; 2557 struct GNUNET_ATS_PluginEnvironment *env = cls;
2559 struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle); 2558 struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
2560 struct RIL_Scope * cur; 2559 struct RIL_Scope * cur;
@@ -2780,17 +2779,18 @@ libgnunet_plugin_ats_ril_init (void *cls)
2780 solver->parameters.social_welfare = RIL_DEFAULT_WELFARE; 2779 solver->parameters.social_welfare = RIL_DEFAULT_WELFARE;
2781 } 2780 }
2782 2781
2783 env->sf.s_add = &GAS_ril_address_add; 2782 solver->env = env;
2784 env->sf.s_address_update_property = &GAS_ril_address_property_changed; 2783 sf.cls = solver;
2785 env->sf.s_get = &GAS_ril_get_preferred_address; 2784 sf.s_add = &GAS_ril_address_add;
2786 env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address; 2785 sf.s_address_update_property = &GAS_ril_address_property_changed;
2787 env->sf.s_pref = &GAS_ril_address_change_preference; 2786 sf.s_get = &GAS_ril_get_preferred_address;
2788 env->sf.s_feedback = &GAS_ril_address_preference_feedback; 2787 sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
2789 env->sf.s_del = &GAS_ril_address_delete; 2788 sf.s_pref = &GAS_ril_address_change_preference;
2790 env->sf.s_bulk_start = &GAS_ril_bulk_start; 2789 sf.s_feedback = &GAS_ril_address_preference_feedback;
2791 env->sf.s_bulk_stop = &GAS_ril_bulk_stop; 2790 sf.s_del = &GAS_ril_address_delete;
2791 sf.s_bulk_start = &GAS_ril_bulk_start;
2792 sf.s_bulk_stop = &GAS_ril_bulk_stop;
2792 2793
2793 solver->plugin_envi = env;
2794 solver->networks_count = env->network_count; 2794 solver->networks_count = env->network_count;
2795 solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope)); 2795 solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope));
2796 solver->step_count = 0; 2796 solver->step_count = 0;
@@ -2818,7 +2818,7 @@ libgnunet_plugin_ats_ril_init (void *cls)
2818 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n", 2818 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n",
2819 solver->parameters.rbf_divisor); 2819 solver->parameters.rbf_divisor);
2820 2820
2821 return solver; 2821 return &sf;
2822} 2822}
2823 2823
2824 2824
@@ -2830,7 +2830,8 @@ libgnunet_plugin_ats_ril_init (void *cls)
2830void * 2830void *
2831libgnunet_plugin_ats_ril_done (void *cls) 2831libgnunet_plugin_ats_ril_done (void *cls)
2832{ 2832{
2833 struct GAS_RIL_Handle *s = cls; 2833 struct GNUNET_ATS_SolverFunctions *sf = cls;
2834 struct GAS_RIL_Handle *s = sf->cls;
2834 struct RIL_Peer_Agent *cur_agent; 2835 struct RIL_Peer_Agent *cur_agent;
2835 struct RIL_Peer_Agent *next_agent; 2836 struct RIL_Peer_Agent *next_agent;
2836 2837
diff --git a/src/include/gnunet_ats_plugin.h b/src/include/gnunet_ats_plugin.h
index e2272fdc8..36a49d252 100644
--- a/src/include/gnunet_ats_plugin.h
+++ b/src/include/gnunet_ats_plugin.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors) 3 (C) 2009-2015 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
@@ -53,8 +53,10 @@ struct ATS_Address;
53 */ 53 */
54typedef void 54typedef void
55(*GAS_solver_address_change_preference) (void *solver, 55(*GAS_solver_address_change_preference) (void *solver,
56 const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, 56 const struct GNUNET_PeerIdentity *peer,
57 double pref_rel); 57 enum GNUNET_ATS_PreferenceKind kind,
58 double pref_rel);
59
58 60
59/** 61/**
60 * Give feedback about the current assignment 62 * Give feedback about the current assignment
@@ -67,10 +69,12 @@ typedef void
67 * @param score the feedback score 69 * @param score the feedback score
68 */ 70 */
69typedef void 71typedef void
70(*GAS_solver_address_feedback_preference) (void *solver, void *application, 72(*GAS_solver_address_feedback_preference) (void *solver,
71 const struct GNUNET_PeerIdentity *peer, 73 struct GNUNET_SERVER_Client *application,
72 const struct GNUNET_TIME_Relative scope, 74 const struct GNUNET_PeerIdentity *peer,
73 enum GNUNET_ATS_PreferenceKind kind, double score); 75 const struct GNUNET_TIME_Relative scope,
76 enum GNUNET_ATS_PreferenceKind kind,
77 double score);
74 78
75/** 79/**
76 * Notify the solver about a bulk operation changing possibly a lot of values 80 * Notify the solver about a bulk operation changing possibly a lot of values
@@ -81,6 +85,7 @@ typedef void
81typedef void 85typedef void
82(*GAS_solver_bulk_start) (void *solver); 86(*GAS_solver_bulk_start) (void *solver);
83 87
88
84/** 89/**
85 * Mark a bulk operation as done 90 * Mark a bulk operation as done
86 * Solver will resolve if values have changed 91 * Solver will resolve if values have changed
@@ -90,29 +95,32 @@ typedef void
90typedef void 95typedef void
91(*GAS_solver_bulk_stop) (void *solver); 96(*GAS_solver_bulk_stop) (void *solver);
92 97
98
93/** 99/**
94 * Add a single address within a network to the solver 100 * Add a single address within a network to the solver
95 * 101 *
96 * @param solver the solver Handle 102 * @param solver the solver Handle
97 * @param addresses the address hashmap containing all addresses
98 * @param address the address to add 103 * @param address the address to add
99 * @param network network type of this address 104 * @param network network type of this address
100 */ 105 */
101typedef void 106typedef void
102(*GAS_solver_address_add) (void *solver, struct ATS_Address *address, 107(*GAS_solver_address_add) (void *solver,
103 uint32_t network); 108 struct ATS_Address *address,
109 uint32_t network);
110
104 111
105/** 112/**
106 * Delete an address or just the session from the solver 113 * Delete an address or just the session from the solver
107 * 114 *
108 * @param solver the solver Handle 115 * @param solver the solver Handle
109 * @param addresses the address hashmap containing all addresses
110 * @param address the address to delete 116 * @param address the address to delete
111 * @param session_only remove address or just session 117 * @param session_only remove address or just session
112 */ 118 */
113typedef void 119typedef void
114(*GAS_solver_address_delete) (void *solver, struct ATS_Address *address, 120(*GAS_solver_address_delete) (void *solver,
115 int session_only); 121 struct ATS_Address *address,
122 int session_only);
123
116 124
117/** 125/**
118 * Transport properties for this address have changed 126 * Transport properties for this address have changed
@@ -125,42 +133,49 @@ typedef void
125 */ 133 */
126typedef void 134typedef void
127(*GAS_solver_address_property_changed) (void *solver, 135(*GAS_solver_address_property_changed) (void *solver,
128 struct ATS_Address *address, uint32_t type, uint32_t abs_value, 136 struct ATS_Address *address,
129 double rel_value); 137 uint32_t type,
138 uint32_t abs_value,
139 double rel_value);
130 140
131 141
132/** 142/**
133 * Get the prefered address for a peer from solver 143 * Get the prefered address for a peer from solver
134 * 144 *
135 * @param solver the solver to use 145 * @param solver the solver to use
136 * @param addresses the address hashmap containing all addresses
137 * @param peer the peer 146 * @param peer the peer
138 */ 147 */
139typedef const struct ATS_Address * 148typedef const struct ATS_Address *
140(*GAS_solver_get_preferred_address) (void *solver, 149(*GAS_solver_get_preferred_address) (void *solver,
141 const struct GNUNET_PeerIdentity *peer); 150 const struct GNUNET_PeerIdentity *peer);
151
142 152
143/** 153/**
144 * Stop getting the prefered address for a peer from solver 154 * Stop getting the prefered address for a peer from solver
145 * 155 *
146 * @param solver the solver to use 156 * @param solver the solver to use
147 * @param addresses the address hashmap containing all addresses
148 * @param peer the peer 157 * @param peer the peer
149 */ 158 */
150typedef void 159typedef void
151(*GAS_solver_stop_get_preferred_address) (void *solver, 160(*GAS_solver_stop_get_preferred_address) (void *solver,
152 const struct GNUNET_PeerIdentity *peer); 161 const struct GNUNET_PeerIdentity *peer);
162
153 163
154/** 164/**
155 * Solver functions 165 * Solver functions.
156 * 166 *
157 * Each solver is required to set up this struct contained in the plugin 167 * Each solver is required to set up and return an instance
158 * environment struct in during startup 168 * of this struct during initialization.
159 */ 169 */
160struct GNUNET_ATS_SolverFunctions 170struct GNUNET_ATS_SolverFunctions
161{ 171{
162 172
163 /** 173 /**
174 * Closure to pass to all solver functions in this struct.
175 */
176 void *cls;
177
178 /**
164 * Add a new address for a peer to the solver 179 * Add a new address for a peer to the solver
165 * 180 *
166 * The address is already contained in the addresses hashmap! 181 * The address is already contained in the addresses hashmap!
@@ -226,15 +241,15 @@ struct GNUNET_ATS_SolverFunctions
226 GAS_solver_bulk_stop s_bulk_stop; 241 GAS_solver_bulk_stop s_bulk_stop;
227}; 242};
228 243
244
229/** 245/**
230 * Operation codes for solver information callback 246 * Operation codes for solver information callback
231 * 247 *
232 * Order of calls is expected to be: 248 * Order of calls is expected to be:
233 * GAS_OP_SOLVE_START 249 * #GAS_OP_SOLVE_START
234 * 250 * #GAS_OP_SOLVE_STOP
235 * GAS_OP_SOLVE_STOP 251 * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
236 * GAS_OP_SOLVE_UPDATE_NOTIFICATION_START 252 * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
237 * GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
238 * 253 *
239 */ 254 */
240enum GAS_Solver_Operation 255enum GAS_Solver_Operation
@@ -296,6 +311,7 @@ enum GAS_Solver_Operation
296 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP 311 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
297}; 312};
298 313
314
299/** 315/**
300 * Status of a GAS_Solver_Operation operation 316 * Status of a GAS_Solver_Operation operation
301 */ 317 */
@@ -312,6 +328,7 @@ enum GAS_Solver_Status
312 GAS_STAT_FAIL 328 GAS_STAT_FAIL
313}; 329};
314 330
331
315/** 332/**
316 * Status of the operation 333 * Status of the operation
317 */ 334 */
@@ -345,20 +362,20 @@ enum GAS_Solver_Additional_Information
345 GAS_INFO_PROP_ALL 362 GAS_INFO_PROP_ALL
346}; 363};
347 364
365
348/** 366/**
349 * Callback to call with additional information 367 * Callback to call with additional information
350 * Used for measurement 368 * Used for measurement
351 * 369 *
352 * @param cls the closure 370 * @param cls the closure
353 * @param op the operation 371 * @param op the operation
354 * @param peer the peer id
355 * @param kind the preference kind to change
356 * @param score the new preference score
357 * @param pref_rel the normalized preference value for this kind over all clients
358 */ 372 */
359typedef void 373typedef void
360(*GAS_solver_information_callback) (void *cls, enum GAS_Solver_Operation op, 374(*GAS_solver_information_callback) (void *cls,
361 enum GAS_Solver_Status stat, enum GAS_Solver_Additional_Information); 375 enum GAS_Solver_Operation op,
376 enum GAS_Solver_Status stat,
377 enum GAS_Solver_Additional_Information);
378
362 379
363/** 380/**
364 * Callback to call from solver when bandwidth for address has changed 381 * Callback to call from solver when bandwidth for address has changed
@@ -366,7 +383,9 @@ typedef void
366 * @param address the with changed bandwidth assigned 383 * @param address the with changed bandwidth assigned
367 */ 384 */
368typedef void 385typedef void
369(*GAS_bandwidth_changed_cb) (void *cls, struct ATS_Address *address); 386(*GAS_bandwidth_changed_cb) (void *cls,
387 struct ATS_Address *address);
388
370 389
371/** 390/**
372 * Callback to call from solver to obtain application preference values for a 391 * Callback to call from solver to obtain application preference values for a
@@ -378,7 +397,9 @@ typedef void
378 * GNUNET_ATS_PreferenceCount elements 397 * GNUNET_ATS_PreferenceCount elements
379 */ 398 */
380typedef const double * 399typedef const double *
381(*GAS_get_preferences) (void *cls, const struct GNUNET_PeerIdentity *id); 400(*GAS_get_preferences) (void *cls,
401 const struct GNUNET_PeerIdentity *id);
402
382 403
383/** 404/**
384 * Callback to call from solver to obtain transport properties for an 405 * Callback to call from solver to obtain transport properties for an
@@ -390,12 +411,14 @@ typedef const double *
390 * GNUNET_ATS_PreferenceCount elements 411 * GNUNET_ATS_PreferenceCount elements
391 */ 412 */
392typedef const double * 413typedef const double *
393(*GAS_get_properties) (void *cls, const struct ATS_Address *address); 414(*GAS_get_properties) (void *cls,
415 const struct ATS_Address *address);
416
394 417
395/** 418/**
396 * The ATS service will pass a pointer to a struct 419 * The ATS plugin will pass a pointer to a struct
397 * of this type as the first and only argument to the 420 * of this type as to the initialization function
398 * entry point of each ATS solver. 421 * of the ATS plugins.
399 */ 422 */
400struct GNUNET_ATS_PluginEnvironment 423struct GNUNET_ATS_PluginEnvironment
401{ 424{
@@ -407,7 +430,12 @@ struct GNUNET_ATS_PluginEnvironment
407 /** 430 /**
408 * Statistics handle to be used by the solver 431 * Statistics handle to be used by the solver
409 */ 432 */
410 const struct GNUNET_STATISTICS_Handle *stats; 433 struct GNUNET_STATISTICS_Handle *stats;
434
435 /**
436 * Closure to pass to all callbacks in this struct.
437 */
438 void *cls;
411 439
412 /** 440 /**
413 * Hashmap containing all addresses available 441 * Hashmap containing all addresses available
@@ -420,48 +448,22 @@ struct GNUNET_ATS_PluginEnvironment
420 GAS_bandwidth_changed_cb bandwidth_changed_cb; 448 GAS_bandwidth_changed_cb bandwidth_changed_cb;
421 449
422 /** 450 /**
423 * ATS addresses closure to be notified about bandwidth assignment changes
424 */
425 void *bw_changed_cb_cls;
426
427 /**
428 * ATS addresses function to obtain preference values 451 * ATS addresses function to obtain preference values
429 */ 452 */
430 GAS_get_preferences get_preferences; 453 GAS_get_preferences get_preferences;
431 454
432 /** 455 /**
433 * ATS addresses function closure to obtain preference values
434 */
435 void *get_preference_cls;
436
437 /**
438 * ATS addresses function to obtain property values 456 * ATS addresses function to obtain property values
439 */ 457 */
440 GAS_get_properties get_property; 458 GAS_get_properties get_property;
441 459
442 /** 460 /**
443 * ATS addresses function closure to obtain property values
444 */
445 void *get_property_cls;
446
447 /**
448 * Callback for solver to call with status information, 461 * Callback for solver to call with status information,
449 * can be NULL 462 * can be NULL
450 */ 463 */
451 GAS_solver_information_callback info_cb; 464 GAS_solver_information_callback info_cb;
452 465
453 /** 466 /**
454 * Closure for information callback,
455 * can be NULL
456 */
457 void *info_cb_cls;
458
459 /**
460 * The ATS solver plugin functions to call
461 */
462 struct GNUNET_ATS_SolverFunctions sf;
463
464 /**
465 * Available networks 467 * Available networks
466 */ 468 */
467 int networks[GNUNET_ATS_NetworkTypeCount]; 469 int networks[GNUNET_ATS_NetworkTypeCount];