gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r35116 - in gnunet/src: ats include


From: gnunet
Subject: [GNUnet-SVN] r35116 - in gnunet/src: ats include
Date: Thu, 5 Feb 2015 22:41:58 +0100

Author: grothoff
Date: 2015-02-05 22:41:58 +0100 (Thu, 05 Feb 2015)
New Revision: 35116

Modified:
   gnunet/src/ats/gnunet-ats-solver-eval.c
   gnunet/src/ats/gnunet-ats-solver-eval.h
   gnunet/src/ats/gnunet-service-ats_plugins.c
   gnunet/src/ats/perf_ats_solver.c
   gnunet/src/ats/plugin_ats_mlp.c
   gnunet/src/ats/plugin_ats_proportional.c
   gnunet/src/ats/plugin_ats_ril.c
   gnunet/src/include/gnunet_ats_plugin.h
Log:
first pass at cleaning up ATS plugin API

Modified: gnunet/src/ats/gnunet-ats-solver-eval.c
===================================================================
--- gnunet/src/ats/gnunet-ats-solver-eval.c     2015-02-05 20:15:02 UTC (rev 
35115)
+++ gnunet/src/ats/gnunet-ats-solver-eval.c     2015-02-05 21:41:58 UTC (rev 
35116)
@@ -108,30 +108,7 @@
   }
 }
 
-struct AddressLookupCtx
-{
-  struct ATS_Address *res;
-  char *plugin;
-  char *addr;
-};
 
-
-int find_address_it (void *cls,
-                     const struct GNUNET_PeerIdentity *key,
-                     void *value)
-{
-  struct AddressLookupCtx *ctx = cls;
-  struct ATS_Address *addr = value;
-
-  if ( (0 == strcmp (ctx->plugin, addr->plugin)) &&
-       (0 == strcmp (ctx->addr, addr->addr)) )
-  {
-       ctx->res = addr;
-       return GNUNET_NO;
-  }
-  return GNUNET_YES;
-}
-
 static struct TestPeer *
 find_peer_by_id (int id)
 {
@@ -670,17 +647,17 @@
   atsi.value = htonl ((uint32_t) prop_value);
 
   /* set performance here! */
-  sh->env.sf.s_bulk_start (sh->solver);
+  sh->sf->s_bulk_start (sh->sf->cls);
   if (GNUNET_YES == opt_disable_normalization)
   {
     a->prop_abs[pg->ats_property] = prop_value;
     a->prop_norm[pg->ats_property] = prop_value;
-    sh->env.sf.s_address_update_property (sh->solver, a->ats_addr,
+    sh->sf->s_address_update_property (sh->sf->cls, a->ats_addr,
         pg->ats_property, prop_value, prop_value);
   }
   else
     GAS_normalization_normalize_property (pg->test_address->ats_addr, &atsi, 
1);
-  sh->env.sf.s_bulk_stop (sh->solver);
+  sh->sf->s_bulk_stop (sh->sf->cls);
 
   pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
       &set_prop_task, pg);
@@ -949,7 +926,7 @@
       GNUNET_ATS_print_preference_type (pg->kind),
       feedback);
 
-  sh->env.sf.s_feedback (sh->solver, NULL + (pg->client_id), &p->peer_id,
+  sh->sf->s_feedback (sh->sf->cls, NULL + (pg->client_id), &p->peer_id,
       pg->feedback_frequency, pg->kind, feedback);
   pg->feedback_last = GNUNET_TIME_absolute_get();
 
@@ -1003,17 +980,17 @@
       pg->peer, NULL + (pg->client_id),
       GNUNET_ATS_print_preference_type (pg->kind), pref_value);
 
-  sh->env.sf.s_bulk_start (sh->solver);
+  sh->sf->s_bulk_start (sh->sf->cls);
   if (GNUNET_YES == opt_disable_normalization)
   {
     p->pref_abs[pg->kind] = pref_value;
     p->pref_norm[pg->kind] = pref_value;
-    sh->env.sf.s_pref (sh->solver, &p->peer_id, pg->kind, pref_value);
+    sh->sf->s_pref (sh->sf->cls, &p->peer_id, pg->kind, pref_value);
   }
   else
     GAS_normalization_normalize_preference (NULL + (pg->client_id),
         &p->peer_id, pg->kind, pref_value);
-  sh->env.sf.s_bulk_stop (sh->solver);
+  sh->sf->s_bulk_stop (sh->sf->cls);
 
   pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
       set_pref_task, pg);
@@ -2250,7 +2227,7 @@
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in 
network `%s'\n",
     op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
 
-  sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
+  sh->sf->s_add (sh->sf->cls, a->ats_addr, op->address_network);
 
 }
 
@@ -2292,7 +2269,7 @@
               op->address_id,
               op->peer_id);
 
-  sh->env.sf.s_del (sh->solver, a->ats_addr, GNUNET_NO);
+  sh->sf->s_del (sh->sf->cls, a->ats_addr, GNUNET_NO);
 
   if (NULL != l)
   {
@@ -2437,7 +2414,7 @@
       op->peer_id);
   p->is_requested = GNUNET_YES;
 
-  res = sh->env.sf.s_get (sh->solver, &p->peer_id);
+  res = sh->sf->s_get (sh->sf->cls, &p->peer_id);
   if (NULL != res)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu 
%llu\n",
@@ -2469,7 +2446,7 @@
   p->is_requested = GNUNET_NO;
   p->assigned_bw_in = 0;
   p->assigned_bw_out = 0;
-  sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
+  sh->sf->s_get_stop (sh->sf->cls, &p->peer_id);
 
   if (NULL != l)
   {
@@ -2755,16 +2732,19 @@
 {
  GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
      GNUNET_NO);
- GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
-
+ GNUNET_PLUGIN_unload (sh->plugin, sh->sf);
+ sh->sf = NULL;
  GAS_normalization_stop();
 
- GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
+ GNUNET_CONTAINER_multipeermap_iterate (sh->addresses,
+                                        &free_all_it,
+                                        NULL);
  GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
  GNUNET_free (sh->plugin);
  GNUNET_free (sh);
 }
 
+
 /**
  * Load quotas for networks from configuration
  *
@@ -3096,8 +3076,9 @@
   }
 
   sh = GNUNET_new (struct SolverHandle);
-  GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
-
+  GNUNET_asprintf (&sh->plugin,
+                   "libgnunet_plugin_ats_%s",
+                   solver_str);
   sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
 
   /* setup environment */
@@ -3109,7 +3090,6 @@
   sh->env.get_property = &get_property_cb;
   sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
   sh->env.info_cb = &solver_info_cb;
-  sh->env.info_cb_cls = NULL;
   sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
   int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
   for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
@@ -3130,8 +3110,8 @@
     return NULL;
   }
 
-  sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
-  if (NULL == sh->solver)
+  sh->sf = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
+  if (NULL == sh->sf)
   {
     fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
     GNUNET_break(0);
@@ -3143,6 +3123,7 @@
   return sh;
 }
 
+
 static void
 done ()
 {

Modified: gnunet/src/ats/gnunet-ats-solver-eval.h
===================================================================
--- gnunet/src/ats/gnunet-ats-solver-eval.h     2015-02-05 20:15:02 UTC (rev 
35115)
+++ gnunet/src/ats/gnunet-ats-solver-eval.h     2015-02-05 21:41:58 UTC (rev 
35116)
@@ -70,7 +70,7 @@
   /**
    * Solver handle
    */
-  void *solver;
+  struct GNUNET_ATS_SolverFunctions *sf;
 
   /**
    * Address hashmap

Modified: gnunet/src/ats/gnunet-service-ats_plugins.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_plugins.c 2015-02-05 20:15:02 UTC (rev 
35115)
+++ gnunet/src/ats/gnunet-service-ats_plugins.c 2015-02-05 21:41:58 UTC (rev 
35116)
@@ -39,12 +39,12 @@
 static int ats_mode;
 
 /**
- * Solver handle. FIXME: TYPE!?
+ * Solver handle.
  */
-static void *solver;
+static struct GNUNET_ATS_SolverFunctions *sf;
 
 /**
- * Solver functions. FIXME.
+ * Solver environment.
  */
 static struct GNUNET_ATS_PluginEnvironment env;
 
@@ -67,7 +67,7 @@
                                   double pref_rel)
 {
   /* Tell solver about update */
-  env.sf.s_pref (solver, peer, kind, pref_rel);
+  sf->s_pref (sf->cls, peer, kind, pref_rel);
 }
 
 
@@ -88,11 +88,11 @@
              GNUNET_ATS_print_property_type (type),
              GNUNET_i2s (&address->peer),
              prop_rel);
-  env.sf.s_address_update_property (solver,
-                                    address,
-                                    type,
-                                    0,
-                                    prop_rel);
+  sf->s_address_update_property (sf->cls,
+                                 address,
+                                 type,
+                                 0,
+                                 prop_rel);
 }
 
 
@@ -453,14 +453,11 @@
   }
 
   load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount);
+  env.cls = NULL;
   env.info_cb = &solver_info_cb;
-  env.info_cb_cls = NULL;
   env.bandwidth_changed_cb = &bandwidth_changed_cb;
-  env.bw_changed_cb_cls = NULL;
   env.get_preferences = &GAS_normalization_get_preferences_by_peer;
-  env.get_preference_cls = NULL;
   env.get_property = &GAS_normalization_get_properties;
-  env.get_property_cls = NULL;
   env.cfg = cfg;
   env.stats = GSA_stats;
   env.addresses = GSA_addresses;
@@ -495,31 +492,13 @@
               "Initializing solver `%s '`%s'\n",
               plugin_short,
               plugin);
-  if (NULL == (solver = GNUNET_PLUGIN_load (plugin, &env)))
+  if (NULL == (sf = GNUNET_PLUGIN_load (plugin, &env)))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 _("Failed to initialize solver `%s'!\n"),
                 plugin);
     return GNUNET_SYSERR;
   }
-
-
-  GNUNET_assert (NULL != env.sf.s_add);
-  GNUNET_assert (NULL != env.sf.s_address_update_property);
-  GNUNET_assert (NULL != env.sf.s_get);
-  GNUNET_assert (NULL != env.sf.s_get_stop);
-  GNUNET_assert (NULL != env.sf.s_pref);
-  GNUNET_assert (NULL != env.sf.s_feedback);
-  GNUNET_assert (NULL != env.sf.s_del);
-  GNUNET_assert (NULL != env.sf.s_bulk_start);
-  GNUNET_assert (NULL != env.sf.s_bulk_stop);
-
-  if (NULL == solver)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Failed to initialize solver!\n"));
-    return GNUNET_SYSERR;
-  }
   return GNUNET_OK;
 }
 
@@ -531,8 +510,8 @@
 GAS_plugins_done ()
 {
   GNUNET_PLUGIN_unload (plugin,
-                        solver);
-  solver = NULL;
+                        sf);
+  sf = NULL;
   GNUNET_free (plugin);
   plugin = NULL;
 }
@@ -544,12 +523,12 @@
                        const struct GNUNET_ATS_Information *atsi,
                        uint32_t atsi_count)
 {
-  env.sf.s_add (solver, new_address, addr_net);
-  env.sf.s_bulk_start (solver);
+  sf->s_add (sf->cls, new_address, addr_net);
+  sf->s_bulk_start (sf->cls);
   GAS_normalization_normalize_property (new_address,
                                        atsi,
                                        atsi_count);
-  env.sf.s_bulk_stop (solver);
+  sf->s_bulk_stop (sf->cls);
 }
 
 
@@ -558,18 +537,18 @@
                           const struct GNUNET_ATS_Information *atsi,
                           uint32_t atsi_count)
 {
-  env.sf.s_bulk_start (solver);
+  sf->s_bulk_start (sf->cls);
   GAS_normalization_normalize_property (address,
                                        atsi,
                                        atsi_count);
-  env.sf.s_bulk_stop (solver);
+  sf->s_bulk_stop (sf->cls);
 }
 
 
 void
 GAS_plugin_delete_address (struct ATS_Address *address)
 {
-  env.sf.s_del (solver, address, GNUNET_NO);
+  sf->s_del (sf->cls, address, GNUNET_NO);
 }
 
 
@@ -579,10 +558,10 @@
                               enum GNUNET_ATS_PreferenceKind kind,
                               float score_abs)
 {
-  env.sf.s_bulk_start (solver);
+  sf->s_bulk_start (sf->cls);
   /* Tell normalization about change, normalization will call callback if 
preference changed */
   GAS_normalization_normalize_preference (client, peer, kind, score_abs);
-  env.sf.s_bulk_stop (solver);
+  sf->s_bulk_stop (sf->cls);
 }
 
 
@@ -593,7 +572,7 @@
                                enum GNUNET_ATS_PreferenceKind kind,
                                float score_abs)
 {
-  env.sf.s_feedback (solver,
+  sf->s_feedback (sf->cls,
                     application,
                     peer,
                     scope,
@@ -605,14 +584,14 @@
 void
 GAS_plugin_solver_lock ()
 {
-  env.sf.s_bulk_start (solver);
+  sf->s_bulk_start (sf->cls);
 }
 
 
 void
 GAS_plugin_solver_unlock ()
 {
-  env.sf.s_bulk_start (solver);
+  sf->s_bulk_start (sf->cls);
 }
 
 
@@ -621,7 +600,7 @@
 {
   const struct ATS_Address *aa;
 
-  aa = env.sf.s_get (solver, pid);
+  aa = sf->s_get (sf->cls, pid);
   if (NULL == aa)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -648,7 +627,7 @@
 void
 GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid)
 {
-  env.sf.s_get_stop (solver, pid);
+  sf->s_get_stop (sf->cls, pid);
 }
 
 

Modified: gnunet/src/ats/perf_ats_solver.c
===================================================================
--- gnunet/src/ats/perf_ats_solver.c    2015-02-05 20:15:02 UTC (rev 35115)
+++ gnunet/src/ats/perf_ats_solver.c    2015-02-05 21:41:58 UTC (rev 35116)
@@ -29,6 +29,7 @@
 #include "gnunet-service-ats_addresses.h"
 #include "gnunet-service-ats_plugins.h"
 #include "gnunet-service-ats_normalization.h"
+#include "gnunet-service-ats_preferences.h"
 #include "gnunet_ats_service.h"
 #include "gnunet_ats_plugin.h"
 #include "test_ats_api_common.h"
@@ -58,7 +59,7 @@
   /**
    *  Solver handle
    */
-  void *solver;
+  struct GNUNET_ATS_SolverFunctions *sf;
 
   /**
    * Statistics stat;
@@ -372,7 +373,7 @@
         GNUNET_i2s (&cur->peer), cur,
         "GNUNET_ATS_QUALITY_NET_DELAY",
         abs_val, rel_val);
-    ph.env.sf.s_address_update_property (ph.solver, cur,
+    ph.sf->s_address_update_property (ph.sf->cls, cur,
         GNUNET_ATS_QUALITY_NET_DELAY,
         abs_val, rel_val);
     break;
@@ -384,7 +385,7 @@
         "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
         GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE",
         abs_val, rel_val);
-    ph.env.sf.s_address_update_property (ph.solver, cur,
+    ph.sf->s_address_update_property (ph.sf->cls, cur,
         GNUNET_ATS_QUALITY_NET_DISTANCE,
         abs_val, rel_val);
     break;
@@ -423,13 +424,13 @@
 const double *
 get_property_cb (void *cls, const struct ATS_Address *address)
 {
-  return GAS_normalization_get_properties (NULL, 
+  return GAS_normalization_get_properties (NULL,
                                           address);
 }
 
 
 static void
-perf_address_initial_update (void *solver,
+perf_address_initial_update (void *dead,
     struct GNUNET_CONTAINER_MultiPeerMap * addresses,
     struct ATS_Address *address)
 {
@@ -437,19 +438,45 @@
   double distance;
   uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
   delay = (100 + (double) random) / 100;
-  ph.env.sf.s_address_update_property (solver, address, 
GNUNET_ATS_QUALITY_NET_DELAY,
+  ph.sf->s_address_update_property (ph.sf->cls,
+                                    address, GNUNET_ATS_QUALITY_NET_DELAY,
       100,  delay);
 
   random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
   distance = (100 + (double) random) / 100;
 
-  ph.env.sf.s_address_update_property (solver, address,
-      GNUNET_ATS_QUALITY_NET_DISTANCE, 10, distance);
+  ph.sf->s_address_update_property (ph.sf->cls, address,
+                                    GNUNET_ATS_QUALITY_NET_DISTANCE,
+                                    10, distance);
 
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-      "Initial update address %p : %.2f  %.2f\n", address, delay, distance);
+             "Initial update address %p : %.2f  %.2f\n",
+             address, delay, distance);
 }
 
+
+struct DUA_Ctx
+{
+  int r;
+  int c_cur_a;
+};
+
+
+static int
+do_update_address (void *cls,
+                   const struct GNUNET_PeerIdentity *pid,
+                   void *value)
+{
+  struct DUA_Ctx *ctx = cls;
+  struct ATS_Address *addr = value;
+
+  if (ctx->c_cur_a == ctx->r)
+    perf_update_address (addr);
+  ctx->c_cur_a++;
+  return GNUNET_OK;
+}
+
+
 /**
  * Update a certain percentage of peers
  *
@@ -457,18 +484,16 @@
  * @param ca the current number of addresses
  * @param percentage_peers the percentage of peers to update
  */
-
 static void
 perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int 
percentage_peers)
 {
-  struct ATS_Address *cur_address;
   int c_peer;
   int c_select;
   int c_cur_p;
-  int c_cur_a;
   int r;
   int count;
   unsigned int m[cp];
+  struct DUA_Ctx dua_ctx;
 
   count = cp * ((double) percentage_peers / 100);
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
@@ -496,15 +521,14 @@
     {
       r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
       GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-          "Updating peer [%u] address [%u]\n", c_cur_p, r);
+                 "Updating peer [%u] address [%u]\n", c_cur_p, r);
 
-      c_cur_a = 0;
-      for (cur_address = ph.peers[c_cur_p].head; NULL != cur_address; 
cur_address = cur_address->next)
-      {
-        if (c_cur_a == r)
-          perf_update_address (cur_address);
-        c_cur_a ++;
-      }
+      dua_ctx.c_cur_a = 0;
+      dua_ctx.r = r;
+      GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
+                                                  &ph.peers[c_cur_p].id,
+                                                  &do_update_address,
+                                                  &dua_ctx);
     }
   }
 }
@@ -520,9 +544,9 @@
 perf_create_address (int cp, int ca)
 {
   struct ATS_Address *a;
+
   a = create_address (&ph.peers[cp].id,
       "Test 1", "test 1", strlen ("test 1") + 1, 0);
-  GNUNET_CONTAINER_DLL_insert (ph.peers[cp].head, ph.peers[cp].tail, a);
   GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
       GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
   return a;
@@ -1028,15 +1052,34 @@
   GNUNET_free_non_null (data_fn_update);
 }
 
+
+static int
+do_delete_address (void *cls,
+                   const struct GNUNET_PeerIdentity *pid,
+                   void *value)
+{
+  struct ATS_Address *cur = value;
+
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Deleting addresses for peer %u\n",
+             pid);
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
+                                                       pid,
+                                                       cur));
+  ph.sf->s_del (ph.sf->cls, cur, GNUNET_NO);
+  GNUNET_free_non_null (cur->atsi);
+  GNUNET_free (cur);
+  return GNUNET_OK;
+}
+
+
 /**
  * Run a performance iteration
  */
-
 static void
 perf_run_iteration (void)
 {
-  struct ATS_Address *cur;
-  struct ATS_Address *next;
   int cp;
   int ca;
   int count_p = ph.N_peers_end;
@@ -1059,7 +1102,7 @@
     if (GNUNET_NO == ph.bulk_running)
     {
       ph.bulk_running = GNUNET_YES;
-      ph.env.sf.s_bulk_start (ph.solver);
+      ph.sf->s_bulk_start (ph.sf->cls);
     }
     ph.current_p = cp + 1;
     for (ca = 0; ca < count_a; ca++)
@@ -1078,16 +1121,16 @@
       cur_addr->atsi_count = 1;
       cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
       cur_addr->atsi[0].value = htonl (net);
-      ph.env.sf.s_add (ph.solver, cur_addr, net);
+      ph.sf->s_add (ph.sf->cls, cur_addr, net);
 
       ph.current_a = ca + 1;
-      perf_address_initial_update (ph.solver, ph.addresses, cur_addr);
+      perf_address_initial_update (NULL, ph.addresses, cur_addr);
       GNUNET_log(GNUNET_ERROR_TYPE_INFO,
           "Adding address for peer %u address %u in network %s\n", cp, ca,
           GNUNET_ATS_print_network_type(net));
     }
     /* Notify solver about request */
-    ph.env.sf.s_get (ph.solver, &ph.peers[cp].id);
+    ph.sf->s_get (ph.sf->cls, &ph.peers[cp].id);
 
     if (cp + 1 >= ph.N_peers_start)
     {
@@ -1096,7 +1139,7 @@
       {
         ph.expecting_solution = GNUNET_YES;
         ph.bulk_running = GNUNET_NO;
-        ph.env.sf.s_bulk_stop (ph.solver);
+        ph.sf->s_bulk_stop (ph.sf->cls);
       }
       else
         GNUNET_break (0);
@@ -1116,11 +1159,11 @@
         if (GNUNET_NO == ph.bulk_running)
         {
           ph.bulk_running = GNUNET_YES;
-          ph.env.sf.s_bulk_start (ph.solver);
+          ph.sf->s_bulk_start (ph.sf->cls);
         }
         perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
         ph.bulk_running = GNUNET_NO;
-        ph.env.sf.s_bulk_stop (ph.solver);
+        ph.sf->s_bulk_stop (ph.sf->cls);
         /* Problem is solved by the solver here due to unlocking */
         ph.performed_update = GNUNET_NO;
         ph.expecting_solution = GNUNET_NO;
@@ -1133,24 +1176,16 @@
       "Done, cleaning up addresses\n");
   if (GNUNET_NO == ph.bulk_running)
   {
-    ph.env.sf.s_bulk_start (ph.solver);
+    ph.sf->s_bulk_start (ph.sf->cls);
     ph.bulk_running = GNUNET_YES;
   }
 
   for (cp = 0; cp < count_p; cp++)
   {
-    for (cur = ph.peers[cp].head; cur != NULL ; cur = next)
-    {
-      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-          "Deleting addresses for peer %u\n", cp);
-      GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove 
(ph.addresses,
-          &ph.peers[cp].id, cur));
-      ph.env.sf.s_del (ph.solver, cur, GNUNET_NO);
-      next = cur->next;
-      GNUNET_CONTAINER_DLL_remove(ph.peers[cp].head, ph.peers[cp].tail, cur);
-      GNUNET_free_non_null (cur->atsi);
-      GNUNET_free (cur);
-    }
+    GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
+                                                &ph.peers[cp].id,
+                                                &do_delete_address,
+                                                NULL);
   }
 
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
@@ -1271,7 +1306,6 @@
   ph.env.get_property = &get_property_cb;
   ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
   ph.env.info_cb = &solver_info_cb;
-  ph.env.info_cb_cls = NULL;
 
   int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
   for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
@@ -1288,9 +1322,10 @@
 
   GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string);
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), 
ph.ats_string);
-  if  (NULL == (ph.solver = GNUNET_PLUGIN_load (plugin, &ph.env)))
+  if  (NULL == (ph.sf = GNUNET_PLUGIN_load (plugin, &ph.env)))
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver 
`%s'!\n"), plugin);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Failed to initialize solver `%s'!\n"), plugin);
     ret = 1;
     return;
   }
@@ -1308,7 +1343,8 @@
 
   /* Unload solver*/
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), 
ph.ats_string);
-  GNUNET_PLUGIN_unload (plugin, ph.solver);
+  GNUNET_PLUGIN_unload (plugin, ph.sf);
+  ph.sf = NULL;
   GNUNET_free (plugin);
   for (c = 0; c < ph.total_iterations; c++ )
   {
@@ -1328,7 +1364,6 @@
 
   GNUNET_CONFIGURATION_destroy (solver_cfg);
   GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
-  ph.solver = NULL;
 }
 
 /**

Modified: gnunet/src/ats/plugin_ats_mlp.c
===================================================================
--- gnunet/src/ats/plugin_ats_mlp.c     2015-02-05 20:15:02 UTC (rev 35115)
+++ gnunet/src/ats/plugin_ats_mlp.c     2015-02-05 21:41:58 UTC (rev 35116)
@@ -219,46 +219,11 @@
   struct GNUNET_ATS_PluginEnvironment *env;
 
   /**
-   * Statistics handle
-   */
-  struct GNUNET_STATISTICS_Handle *stats;
-
-  /**
    * Address hashmap for lookups
    */
   const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
 
   /**
-   * Addresses' bandwidth changed callback
-   */
-  GAS_bandwidth_changed_cb bw_changed_cb;
-
-  /**
-   * Addresses' bandwidth changed callback closure
-   */
-  void *bw_changed_cb_cls;
-
-  /**
-   * ATS function to get preferences
-   */
-  GAS_get_preferences get_preferences;
-
-  /**
-   * Closure for ATS function to get preferences
-   */
-  void *get_preferences_cls;
-
-  /**
-   * ATS function to get properties
-   */
-  GAS_get_properties get_properties;
-
-  /**
-   * Closure for ATS function to get properties
-   */
-  void *get_properties_cls;
-
-  /**
    * Exclude peer from next result propagation
    */
   const struct GNUNET_PeerIdentity *exclude_peer;
@@ -281,7 +246,6 @@
   /**
    * Bulk lock
    */
-
   int stat_bulk_lock;
 
   /**
@@ -394,27 +358,41 @@
 struct MLP_information
 {
 
-  /* Bandwidth assigned outbound */
+  /**
+   * Bandwidth assigned outbound
+   */
   uint32_t b_out;
 
-  /* Bandwidth assigned inbound */
+  /**
+   * Bandwidth assigned inbound
+   */
   uint32_t b_in;
 
-  /* Address selected */
+  /**
+   * Address selected
+   */
   int n;
 
-  /* bandwidth column index */
+  /**
+   * bandwidth column index
+   */
   signed int c_b;
 
-  /* address usage column */
+  /**
+   * address usage column
+   */
   signed int c_n;
 
   /* row indexes */
 
-  /* constraint 1: bandwidth capping */
+  /**
+   * constraint 1: bandwidth capping
+   */
   unsigned int r_c1;
 
-  /* constraint 3: minimum bandwidth */
+  /**
+   * constraint 3: minimum bandwidth
+   */
   unsigned int r_c3;
 };
 
@@ -553,7 +531,7 @@
  * @param cls not used
  * @param key the key
  * @param value ATS_Peer
- * @return GNUNET_OK
+ * @return #GNUNET_OK
  */
 static int
 reset_peers (void *cls,
@@ -1177,7 +1155,7 @@
     /* For all quality metrics, set quality of this address */
     if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
     {
-      props = mlp->get_properties (mlp->get_properties_cls, address);
+      props = mlp->env->get_property (mlp->env->cls, address);
       for (c = 0; c < mlp->pv.m_q; c++)
       {
         if ((props[c] < 1.0) && (props[c] > 2.0))
@@ -1473,7 +1451,7 @@
       address->assigned_bw_out = mlp_bw_out;
       mlpi->b_out = mlp_bw_out;
       if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, 
mlp->exclude_peer, sizeof (address->peer))))
-        mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+        mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
       return GNUNET_OK;
     }
     else if (GNUNET_YES == address->active)
@@ -1489,7 +1467,7 @@
           address->assigned_bw_out = mlp_bw_out;
           mlpi->b_out = mlp_bw_out;
           if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, 
mlp->exclude_peer, sizeof (address->peer))))
-            mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+            mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
           return GNUNET_OK;
       }
     }
@@ -1537,7 +1515,7 @@
        enum GAS_Solver_Additional_Information add)
 {
   if (NULL != mlp->env->info_cb)
-    mlp->env->info_cb (mlp->env->info_cb_cls, op, stat, add);
+    mlp->env->info_cb (mlp->env->cls, op, stat, add);
 }
 
 
@@ -2091,8 +2069,8 @@
   double res;
   const double *preferences = NULL;
   int c;
-  preferences = mlp->get_preferences (mlp->get_preferences_cls, peer);
 
+  preferences = mlp->env->get_preferences (mlp->env->cls, peer);
   res = 0.0;
   for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
   {
@@ -2230,7 +2208,7 @@
     if (NULL == GAS_mlp_get_preferred_address (solver, &address->peer))
     {
       /* No alternative address, disconnecting peer */
-      mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
+      mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
     }
   }
 
@@ -2327,10 +2305,13 @@
   struct GAS_MLP_Handle *mlp = solver;
   struct ATS_Peer *p;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing preference for address for peer `%s' 
to %.2f\n",
-      GNUNET_i2s(peer), pref_rel);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Changing preference for address for peer `%s' to %.2f\n",
+       GNUNET_i2s(peer),
+       pref_rel);
 
-  GNUNET_STATISTICS_update (mlp->stats,"# LP address preference changes", 1, 
GNUNET_NO);
+  GNUNET_STATISTICS_update (mlp->env->stats,
+                            "# LP address preference changes", 1, GNUNET_NO);
   /* Update the constraints with changed preferences */
 
 
@@ -2338,14 +2319,20 @@
   /* Update relativity constraint c9 */
   if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, 
peer)))
   {
-    LOG (GNUNET_ERROR_TYPE_INFO, "Updating preference for unknown peer 
`%s'\n", GNUNET_i2s(peer));
+    LOG (GNUNET_ERROR_TYPE_INFO,
+         "Updating preference for unknown peer `%s'\n",
+         GNUNET_i2s(peer));
     return;
   }
 
   if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
   {
     p->f = get_peer_pref_value (mlp, peer);
-    mlp_create_problem_update_value (&mlp->p, p->r_c9, mlp->p.c_r, -p->f, 
__LINE__);
+    mlp_create_problem_update_value (&mlp->p,
+                                     p->r_c9,
+                                     mlp->p.c_r,
+                                     - p->f,
+                                     __LINE__);
 
     /* Problem size changed: new address for peer with pending request */
     mlp->stat_mlp_prob_updated = GNUNET_YES;
@@ -2367,16 +2354,16 @@
  */
 static void
 GAS_mlp_address_preference_feedback (void *solver,
-                                    void *application,
-                                    const struct GNUNET_PeerIdentity *peer,
-                                    const struct GNUNET_TIME_Relative scope,
-                                    enum GNUNET_ATS_PreferenceKind kind,
-                                    double score)
+                                     struct GNUNET_SERVER_Client *application,
+                                     const struct GNUNET_PeerIdentity *peer,
+                                     const struct GNUNET_TIME_Relative scope,
+                                     enum GNUNET_ATS_PreferenceKind kind,
+                                     double score)
 {
   struct GAS_PROPORTIONAL_Handle *s = solver;
+
   GNUNET_assert (NULL != solver);
   GNUNET_assert (NULL != peer);
-
   GNUNET_assert (NULL != s);
 }
 
@@ -2405,13 +2392,12 @@
 void *
 libgnunet_plugin_ats_mlp_done (void *cls)
 {
-  struct GAS_MLP_Handle *mlp = cls;
-  GNUNET_assert (mlp != NULL);
+  struct GNUNET_ATS_SolverFunctions *sf = cls;
+  struct GAS_MLP_Handle *mlp = sf->cls;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Shutting down mlp solver\n");
   mlp_delete_problem (mlp);
-
   GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers,
                                         &mlp_free_peers,
                                         mlp->requested_peers);
@@ -2431,6 +2417,7 @@
 void *
 libgnunet_plugin_ats_mlp_init (void *cls)
 {
+  static struct GNUNET_ATS_SolverFunctions sf;
   struct GNUNET_ATS_PluginEnvironment *env = cls;
   struct GAS_MLP_Handle * mlp = GNUNET_new (struct GAS_MLP_Handle);
 
@@ -2826,28 +2813,18 @@
       }
   }
   mlp->env = env;
-  env->sf.s_add = &GAS_mlp_address_add;
-  env->sf.s_address_update_property = &GAS_mlp_address_property_changed;
-  env->sf.s_get = &GAS_mlp_get_preferred_address;
-  env->sf.s_get_stop = &GAS_mlp_stop_get_preferred_address;
-  env->sf.s_pref = &GAS_mlp_address_change_preference;
-  env->sf.s_feedback = &GAS_mlp_address_preference_feedback;
-  env->sf.s_del = &GAS_mlp_address_delete;
-  env->sf.s_bulk_start = &GAS_mlp_bulk_start;
-  env->sf.s_bulk_stop = &GAS_mlp_bulk_stop;
+  sf.cls = mlp;
+  sf.s_add = &GAS_mlp_address_add;
+  sf.s_address_update_property = &GAS_mlp_address_property_changed;
+  sf.s_get = &GAS_mlp_get_preferred_address;
+  sf.s_get_stop = &GAS_mlp_stop_get_preferred_address;
+  sf.s_pref = &GAS_mlp_address_change_preference;
+  sf.s_feedback = &GAS_mlp_address_preference_feedback;
+  sf.s_del = &GAS_mlp_address_delete;
+  sf.s_bulk_start = &GAS_mlp_bulk_start;
+  sf.s_bulk_stop = &GAS_mlp_bulk_stop;
 
-
-  /* Assign options to handle */
-  mlp->stats = (struct GNUNET_STATISTICS_Handle *) env->stats;
-  mlp->addresses = env->addresses;
-  mlp->bw_changed_cb = env->bandwidth_changed_cb;
-  mlp->bw_changed_cb_cls = env->bw_changed_cb_cls;
-  mlp->get_preferences =  env->get_preferences;
-  mlp->get_preferences_cls = env->get_preference_cls;
-  mlp->get_properties = env->get_property;
-  mlp->get_properties_cls = env->get_property_cls;
   /* Setting MLP Input variables */
-
   mlp->pv.b_min = b_min;
   mlp->pv.n_min = n_min;
   mlp->pv.m_q = GNUNET_ATS_QualityPropertiesCount;
@@ -2884,7 +2861,7 @@
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "solver ready\n");
 
-  return mlp;
+  return &sf;
 }
 
 /* end of plugin_ats_mlp.c */

Modified: gnunet/src/ats/plugin_ats_proportional.c
===================================================================
--- gnunet/src/ats/plugin_ats_proportional.c    2015-02-05 20:15:02 UTC (rev 
35115)
+++ gnunet/src/ats/plugin_ats_proportional.c    2015-02-05 21:41:58 UTC (rev 
35116)
@@ -217,12 +217,11 @@
  */
 struct GAS_PROPORTIONAL_Handle
 {
-   struct GNUNET_ATS_PluginEnvironment *env;
 
   /**
-   * Statistics handle
+   * Our execution environment.
    */
-  struct GNUNET_STATISTICS_Handle *stats;
+  struct GNUNET_ATS_PluginEnvironment *env;
 
   /**
    * Hashmap containing all valid addresses
@@ -235,36 +234,6 @@
   struct GNUNET_CONTAINER_MultiPeerMap *requests;
 
   /**
-   * Bandwidth changed callback
-   */
-  GAS_bandwidth_changed_cb bw_changed;
-
-  /**
-   * Bandwidth changed callback cls
-   */
-  void *bw_changed_cls;
-
-  /**
-   * ATS function to get preferences
-   */
-  GAS_get_preferences get_preferences;
-
-  /**
-   * Closure for ATS function to get preferences
-   */
-  void *get_preferences_cls;
-
-  /**
-   * ATS function to get properties
-   */
-  GAS_get_properties get_properties;
-
-  /**
-   * Closure for ATS function to get properties
-   */
-  void *get_properties_cls;
-
-  /**
    * Bulk lock
    */
   int bulk_lock;
@@ -418,7 +387,8 @@
 void *
 libgnunet_plugin_ats_proportional_done (void *cls)
 {
-  struct GAS_PROPORTIONAL_Handle *s = cls;
+  struct GNUNET_ATS_SolverFunctions *sf = cls;
+  struct GAS_PROPORTIONAL_Handle *s = sf->cls;
   struct AddressWrapper *cur;
   struct AddressWrapper *next;
   int c;
@@ -572,8 +542,8 @@
     if (GNUNET_YES != cur_address->addr->active)
       continue;
 
-    GNUNET_assert( NULL != (peer_relative_prefs = s->get_preferences 
(s->get_preferences_cls,
-        &cur_address->addr->peer)));
+    GNUNET_assert( NULL != (peer_relative_prefs = s->env->get_preferences 
(s->env->cls,
+                                                                           
&cur_address->addr->peer)));
     relative_peer_prefence = 0.0;
     relative_peer_prefence += 
peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
     sum_relative_peer_prefences += relative_peer_prefence;
@@ -608,7 +578,8 @@
     if (GNUNET_YES == cur_address->addr->active)
     {
       GNUNET_assert( NULL != (peer_relative_prefs =
-          s->get_preferences (s->get_preferences_cls, 
&cur_address->addr->peer)));
+                              s->env->get_preferences (s->env->cls,
+                                                       
&cur_address->addr->peer)));
 
       cur_pref = peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
       total_weight = net->active_addresses +
@@ -767,15 +738,15 @@
   }
 
   /* Now compare ATS information */
-  norm_prop_cur = ctx->s->get_properties (ctx->s->get_properties_cls,
-      (const struct ATS_Address *) current);
+  norm_prop_cur = ctx->s->env->get_property (ctx->s->env->cls,
+                                             current);
   index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
   cur_distance = norm_prop_cur[index];
   index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
   cur_delay = norm_prop_cur[index];
 
-  norm_prop_best = ctx->s->get_properties (ctx->s->get_properties_cls,
-      (const struct ATS_Address *) ctx->best);
+  norm_prop_best = ctx->s->env->get_property (ctx->s->env->cls,
+                                              ctx->best);
   index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
   best_distance = norm_prop_best[index];
   index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
@@ -951,16 +922,20 @@
   {
     s->total_addresses++;
     net->total_addresses++;
-    GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", 1, GNUNET_NO);
-    GNUNET_STATISTICS_update (s->stats, net->stat_total, 1, GNUNET_NO);
+    GNUNET_STATISTICS_update (s->env->stats,
+                              "# ATS addresses total", 1, GNUNET_NO);
+    GNUNET_STATISTICS_update (s->env->stats,
+                              net->stat_total, 1, GNUNET_NO);
   }
   if (GNUNET_YES == active)
   {
     net->active_addresses++;
     s->active_addresses++;
-    GNUNET_STATISTICS_update (s->stats, "# ATS active addresses total", 1,
+    GNUNET_STATISTICS_update (s->env->stats,
+                              "# ATS active addresses total", 1,
         GNUNET_NO);
-    GNUNET_STATISTICS_update (s->stats, net->stat_active, 1, GNUNET_NO);
+    GNUNET_STATISTICS_update (s->env->stats,
+                              net->stat_active, 1, GNUNET_NO);
   }
 
 }
@@ -992,7 +967,8 @@
     else
     {
       s->total_addresses--;
-      GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", -1,
+      GNUNET_STATISTICS_update (s->env->stats,
+                                "# ATS addresses total", -1,
           GNUNET_NO);
     }
     if (net->total_addresses < 1)
@@ -1003,7 +979,8 @@
     else
     {
       net->total_addresses--;
-      GNUNET_STATISTICS_update (s->stats, net->stat_total, -1, GNUNET_NO);
+      GNUNET_STATISTICS_update (s->env->stats,
+                                net->stat_total, -1, GNUNET_NO);
     }
   }
 
@@ -1017,7 +994,8 @@
     else
     {
       net->active_addresses--;
-      GNUNET_STATISTICS_update (s->stats, net->stat_active, -1, GNUNET_NO);
+      GNUNET_STATISTICS_update (s->env->stats,
+                                net->stat_active, -1, GNUNET_NO);
     }
     if (s->active_addresses < 1)
     {
@@ -1027,7 +1005,8 @@
     else
     {
       s->active_addresses--;
-      GNUNET_STATISTICS_update (s->stats, "# ATS addresses total", -1,
+      GNUNET_STATISTICS_update (s->env->stats,
+                                "# ATS addresses total", -1,
           GNUNET_NO);
     }
   }
@@ -1071,6 +1050,7 @@
 {
   struct AddressWrapper *cur;
   struct AddressSolverInformation *asi;
+
   for (cur = net->head; NULL != cur; cur = cur->next)
   {
       asi = cur->addr->solver_information;
@@ -1094,7 +1074,8 @@
         /* Notify on change */
         if ((GNUNET_YES == cur->addr->active))
         {
-          s->bw_changed (s->bw_changed_cls, cur->addr);
+          s->env->bandwidth_changed_cb (s->env->cls,
+                                        cur->addr);
         }
       }
   }
@@ -1125,31 +1106,31 @@
         n->active_addresses, n->total_addresses);
 
     if (NULL != s->env->info_cb)
-      s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START,
+      s->env->info_cb(s->env->cls, GAS_OP_SOLVE_START,
           GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
 
     /* Distribute  */
     distribute_bandwidth(s, n);
 
     if (NULL != s->env->info_cb)
-      s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP,
+      s->env->info_cb(s->env->cls, GAS_OP_SOLVE_STOP,
           GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
     if (NULL != s->env->info_cb)
-      s->env->info_cb(s->env->info_cb_cls, 
GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
+      s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
           GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
 
     /* Do propagation */
     propagate_bandwidth (s, n);
 
     if (NULL != s->env->info_cb)
-      s->env->info_cb(s->env->info_cb_cls, 
GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
+      s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
           GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
   }
   else
   {
     int i;
     if (NULL != s->env->info_cb)
-      s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_START,
+      s->env->info_cb(s->env->cls, GAS_OP_SOLVE_START,
           GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
     for (i = 0; i < s->network_count; i++)
     {
@@ -1158,10 +1139,10 @@
     }
 
     if (NULL != s->env->info_cb)
-      s->env->info_cb(s->env->info_cb_cls, GAS_OP_SOLVE_STOP,
+      s->env->info_cb(s->env->cls, GAS_OP_SOLVE_STOP,
           GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
     if (NULL != s->env->info_cb)
-      s->env->info_cb(s->env->info_cb_cls, 
GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
+      s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
           GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
     for (i = 0; i < s->network_count; i++)
     {
@@ -1169,7 +1150,7 @@
       propagate_bandwidth(s, &s->network_entries[i]);
     }
     if (NULL != s->env->info_cb)
-      s->env->info_cb(s->env->info_cb_cls, 
GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
+      s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
           GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
   }
 }
@@ -1254,8 +1235,8 @@
            "Disconnecting peer `%s' with previous address %p\n",
            GNUNET_i2s (peer),
            current_address);
-      s->bw_changed (s->bw_changed_cls,
-                     current_address);
+      s->env->bandwidth_changed_cb (s->env->cls,
+                                    current_address);
     }
   }
   if (NULL == best_address)
@@ -1347,7 +1328,7 @@
  */
 static void
 GAS_proportional_address_preference_feedback (void *solver,
-                                              void *application,
+                                              struct GNUNET_SERVER_Client 
*application,
                                               const struct GNUNET_PeerIdentity 
*peer,
                                               const struct 
GNUNET_TIME_Relative scope,
                                               enum GNUNET_ATS_PreferenceKind 
kind,
@@ -1547,8 +1528,8 @@
            "Disconnecting peer `%s' after deleting previous address %p\n",
            GNUNET_i2s (&address->peer),
            address);
-      s->bw_changed (s->bw_changed_cls,
-                     address);
+      s->env->bandwidth_changed_cb (s->env->cls,
+                                    address);
     }
   }
   if (GNUNET_NO == session_only)
@@ -1746,6 +1727,7 @@
 void *
 libgnunet_plugin_ats_proportional_init (void *cls)
 {
+  static struct GNUNET_ATS_SolverFunctions sf;
   struct GNUNET_ATS_PluginEnvironment *env = cls;
   struct GAS_PROPORTIONAL_Handle *s;
   struct Network * cur;
@@ -1760,24 +1742,17 @@
 
   s = GNUNET_new (struct GAS_PROPORTIONAL_Handle);
   s->env = env;
-  env->sf.s_add = &GAS_proportional_address_add;
-  env->sf.s_address_update_property = 
&GAS_proportional_address_property_changed;
-  env->sf.s_get = &GAS_proportional_get_preferred_address;
-  env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address;
-  env->sf.s_pref = &GAS_proportional_address_change_preference;
-  env->sf.s_feedback = &GAS_proportional_address_preference_feedback;
-  env->sf.s_del = &GAS_proportional_address_delete;
-  env->sf.s_bulk_start = &GAS_proportional_bulk_start;
-  env->sf.s_bulk_stop = &GAS_proportional_bulk_stop;
+  sf.cls = s;
+  sf.s_add = &GAS_proportional_address_add;
+  sf.s_address_update_property = &GAS_proportional_address_property_changed;
+  sf.s_get = &GAS_proportional_get_preferred_address;
+  sf.s_get_stop = &GAS_proportional_stop_get_preferred_address;
+  sf.s_pref = &GAS_proportional_address_change_preference;
+  sf.s_feedback = &GAS_proportional_address_preference_feedback;
+  sf.s_del = &GAS_proportional_address_delete;
+  sf.s_bulk_start = &GAS_proportional_bulk_start;
+  sf.s_bulk_stop = &GAS_proportional_bulk_stop;
 
-  s->stats = (struct GNUNET_STATISTICS_Handle *) env->stats;
-  s->bw_changed = env->bandwidth_changed_cb;
-  s->bw_changed_cls = env->bw_changed_cb_cls;
-  s->get_preferences = env->get_preferences;
-  s->get_preferences_cls = env->get_preference_cls;
-  s->get_properties = env->get_property;
-  s->get_properties_cls = env->get_property_cls;
-  s->network_count = env->network_count;
   s->network_entries = GNUNET_malloc (env->network_count * sizeof (struct 
Network));
 
   /* Init */
@@ -1849,7 +1824,7 @@
          cur->total_quota_in,
          cur->total_quota_out);
   }
-  return s;
+  return &sf;
 }
 
 

Modified: gnunet/src/ats/plugin_ats_ril.c
===================================================================
--- gnunet/src/ats/plugin_ats_ril.c     2015-02-05 20:15:02 UTC (rev 35115)
+++ gnunet/src/ats/plugin_ats_ril.c     2015-02-05 21:41:58 UTC (rev 35116)
@@ -392,14 +392,9 @@
   /**
    * The solver-plugin environment of the solver-plugin API
    */
-  struct GNUNET_ATS_PluginEnvironment *plugin_envi;
+  struct GNUNET_ATS_PluginEnvironment *env;
 
   /**
-   * Statistics handle
-   */
-  struct GNUNET_STATISTICS_Handle *stats;
-
-  /**
    * Number of performed steps
    */
   unsigned long long step_count;
@@ -786,8 +781,8 @@
             enum GAS_Solver_Operation op,
             enum GAS_Solver_Status stat)
 {
-  if (NULL != solver->plugin_envi->info_cb)
-    solver->plugin_envi->info_cb (solver->plugin_envi->info_cb_cls, op, stat, 
GAS_INFO_NONE);
+  if (NULL != solver->env->info_cb)
+    solver->env->info_cb (solver->env->cls, op, stat, GAS_INFO_NONE);
 }
 
 /**
@@ -974,8 +969,8 @@
   double delay_norm;
   double pref_match;
 
-  preferences = agent->envi->plugin_envi->get_preferences 
(agent->envi->plugin_envi->get_preference_cls,
-      &agent->peer);
+  preferences = agent->envi->env->get_preferences (agent->envi->env->cls,
+                                                   &agent->peer);
 
   delay_atsi = (double) ril_get_atsi (agent->address_inuse, 
GNUNET_ATS_QUALITY_NET_DELAY);
   delay_norm = RIL_UTILITY_DELAY_MAX*exp(-delay_atsi*0.00001);
@@ -1937,7 +1932,7 @@
   for (cur = solver->agents_head; NULL != cur; cur = cur->next)
   {
     if (cur->suggestion_issue) {
-      
solver->plugin_envi->bandwidth_changed_cb(solver->plugin_envi->bw_changed_cb_cls,
 cur->suggestion_address);
+      solver->env->bandwidth_changed_cb(solver->env->cls, 
cur->suggestion_address);
       cur->suggestion_issue = GNUNET_NO;
     }
   }
@@ -2397,16 +2392,19 @@
  */
 static void
 GAS_ril_address_preference_feedback (void *solver,
-    void *application,
-    const struct GNUNET_PeerIdentity *peer,
-    const struct GNUNET_TIME_Relative scope,
-    enum GNUNET_ATS_PreferenceKind kind,
-    double score)
+                                     struct GNUNET_SERVER_Client *application,
+                                     const struct GNUNET_PeerIdentity *peer,
+                                     const struct GNUNET_TIME_Relative scope,
+                                     enum GNUNET_ATS_PreferenceKind kind,
+                                     double score)
 {
-  LOG(GNUNET_ERROR_TYPE_DEBUG,
-      "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f 
from application %s for "
-          "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN",
-      GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f 
from application %s for "
+       "preference %s for %d seconds\n",
+       GNUNET_i2s (peer),
+       "UNKNOWN",
+       GNUNET_ATS_print_preference_type (kind),
+       scope.rel_value_us / 1000000);
 }
 
 
@@ -2555,6 +2553,7 @@
 void *
 libgnunet_plugin_ats_ril_init (void *cls)
 {
+  static struct GNUNET_ATS_SolverFunctions sf;
   struct GNUNET_ATS_PluginEnvironment *env = cls;
   struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
   struct RIL_Scope * cur;
@@ -2780,17 +2779,18 @@
     solver->parameters.social_welfare = RIL_DEFAULT_WELFARE;
   }
 
-  env->sf.s_add = &GAS_ril_address_add;
-  env->sf.s_address_update_property = &GAS_ril_address_property_changed;
-  env->sf.s_get = &GAS_ril_get_preferred_address;
-  env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
-  env->sf.s_pref = &GAS_ril_address_change_preference;
-  env->sf.s_feedback = &GAS_ril_address_preference_feedback;
-  env->sf.s_del = &GAS_ril_address_delete;
-  env->sf.s_bulk_start = &GAS_ril_bulk_start;
-  env->sf.s_bulk_stop = &GAS_ril_bulk_stop;
+  solver->env = env;
+  sf.cls = solver;
+  sf.s_add = &GAS_ril_address_add;
+  sf.s_address_update_property = &GAS_ril_address_property_changed;
+  sf.s_get = &GAS_ril_get_preferred_address;
+  sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
+  sf.s_pref = &GAS_ril_address_change_preference;
+  sf.s_feedback = &GAS_ril_address_preference_feedback;
+  sf.s_del = &GAS_ril_address_delete;
+  sf.s_bulk_start = &GAS_ril_bulk_start;
+  sf.s_bulk_stop = &GAS_ril_bulk_stop;
 
-  solver->plugin_envi = env;
   solver->networks_count = env->network_count;
   solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct 
RIL_Scope));
   solver->step_count = 0;
@@ -2818,7 +2818,7 @@
   LOG(GNUNET_ERROR_TYPE_DEBUG, "init()  RBF_DIVISOR = %llu\n",
       solver->parameters.rbf_divisor);
 
-  return solver;
+  return &sf;
 }
 
 
@@ -2830,7 +2830,8 @@
 void *
 libgnunet_plugin_ats_ril_done (void *cls)
 {
-  struct GAS_RIL_Handle *s = cls;
+  struct GNUNET_ATS_SolverFunctions *sf = cls;
+  struct GAS_RIL_Handle *s = sf->cls;
   struct RIL_Peer_Agent *cur_agent;
   struct RIL_Peer_Agent *next_agent;
 

Modified: gnunet/src/include/gnunet_ats_plugin.h
===================================================================
--- gnunet/src/include/gnunet_ats_plugin.h      2015-02-05 20:15:02 UTC (rev 
35115)
+++ gnunet/src/include/gnunet_ats_plugin.h      2015-02-05 21:41:58 UTC (rev 
35116)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet
- (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+ (C) 2009-2015 Christian Grothoff (and other contributing authors)
 
  GNUnet is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
@@ -53,9 +53,11 @@
  */
 typedef void
 (*GAS_solver_address_change_preference) (void *solver,
-    const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind 
kind,
-    double pref_rel);
+                                         const struct GNUNET_PeerIdentity 
*peer,
+                                         enum GNUNET_ATS_PreferenceKind kind,
+                                         double pref_rel);
 
+
 /**
  * Give feedback about the current assignment
  *
@@ -67,10 +69,12 @@
  * @param score the feedback score
  */
 typedef void
-(*GAS_solver_address_feedback_preference) (void *solver, void *application,
-    const struct GNUNET_PeerIdentity *peer,
-    const struct GNUNET_TIME_Relative scope,
-    enum GNUNET_ATS_PreferenceKind kind, double score);
+(*GAS_solver_address_feedback_preference) (void *solver,
+                                           struct GNUNET_SERVER_Client 
*application,
+                                           const struct GNUNET_PeerIdentity 
*peer,
+                                           const struct GNUNET_TIME_Relative 
scope,
+                                           enum GNUNET_ATS_PreferenceKind kind,
+                                           double score);
 
 /**
  * Notify the solver about a bulk operation changing possibly a lot of values
@@ -81,6 +85,7 @@
 typedef void
 (*GAS_solver_bulk_start) (void *solver);
 
+
 /**
  * Mark a bulk operation as done
  * Solver will resolve if values have changed
@@ -90,30 +95,33 @@
 typedef void
 (*GAS_solver_bulk_stop) (void *solver);
 
+
 /**
  * Add a single address within a network to the solver
  *
  * @param solver the solver Handle
- * @param addresses the address hashmap containing all addresses
  * @param address the address to add
  * @param network network type of this address
  */
 typedef void
-(*GAS_solver_address_add) (void *solver, struct ATS_Address *address,
-    uint32_t network);
+(*GAS_solver_address_add) (void *solver,
+                           struct ATS_Address *address,
+                           uint32_t network);
 
+
 /**
  * Delete an address or just the session from the solver
  *
  * @param solver the solver Handle
- * @param addresses the address hashmap containing all addresses
  * @param address the address to delete
  * @param session_only remove address or just session
  */
 typedef void
-(*GAS_solver_address_delete) (void *solver, struct ATS_Address *address,
-    int session_only);
+(*GAS_solver_address_delete) (void *solver,
+                              struct ATS_Address *address,
+                              int session_only);
 
+
 /**
  * Transport properties for this address have changed
  *
@@ -125,42 +133,49 @@
  */
 typedef void
 (*GAS_solver_address_property_changed) (void *solver,
-    struct ATS_Address *address, uint32_t type, uint32_t abs_value,
-    double rel_value);
+                                        struct ATS_Address *address,
+                                        uint32_t type,
+                                        uint32_t abs_value,
+                                        double rel_value);
 
 
 /**
  * Get the prefered address for a peer from solver
  *
  * @param solver the solver to use
- * @param addresses the address hashmap containing all addresses
  * @param peer the peer
  */
 typedef const struct ATS_Address *
 (*GAS_solver_get_preferred_address) (void *solver,
-    const struct GNUNET_PeerIdentity *peer);
+                                     const struct GNUNET_PeerIdentity *peer);
 
+
 /**
  * Stop getting the prefered address for a peer from solver
  *
  * @param solver the solver to use
- * @param addresses the address hashmap containing all addresses
  * @param peer the peer
  */
 typedef void
 (*GAS_solver_stop_get_preferred_address) (void *solver,
-    const struct GNUNET_PeerIdentity *peer);
+                                          const struct GNUNET_PeerIdentity 
*peer);
 
+
 /**
- * Solver functions
+ * Solver functions.
  *
- * Each solver is required to set up this struct contained in the plugin
- * environment struct in during startup
+ * Each solver is required to set up and return an instance
+ * of this struct during initialization.
  */
 struct GNUNET_ATS_SolverFunctions
 {
 
   /**
+   * Closure to pass to all solver functions in this struct.
+   */
+  void *cls;
+
+  /**
    * Add a new address for a peer to the solver
    *
    * The address is already contained in the addresses hashmap!
@@ -226,16 +241,16 @@
   GAS_solver_bulk_stop s_bulk_stop;
 };
 
+
 /**
  * Operation codes for solver information callback
  *
  * Order of calls is expected to be:
- * GAS_OP_SOLVE_START
+ * #GAS_OP_SOLVE_START
+ * #GAS_OP_SOLVE_STOP
+ * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
+ * #GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
  *
- * GAS_OP_SOLVE_STOP
- * GAS_OP_SOLVE_UPDATE_NOTIFICATION_START
- * GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
- *
  */
 enum GAS_Solver_Operation
 {
@@ -296,6 +311,7 @@
   GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP
 };
 
+
 /**
  * Status of a GAS_Solver_Operation operation
  */
@@ -312,6 +328,7 @@
   GAS_STAT_FAIL
 };
 
+
 /**
  * Status of the operation
  */
@@ -345,29 +362,31 @@
   GAS_INFO_PROP_ALL
 };
 
+
 /**
  * Callback to call with additional information
  * Used for measurement
  *
  * @param cls the closure
  * @param op the operation
- * @param peer the peer id
- * @param kind the preference kind to change
- * @param score the new preference score
- * @param pref_rel the normalized preference value for this kind over all 
clients
  */
 typedef void
-(*GAS_solver_information_callback) (void *cls, enum GAS_Solver_Operation op,
-    enum GAS_Solver_Status stat, enum GAS_Solver_Additional_Information);
+(*GAS_solver_information_callback) (void *cls,
+                                    enum GAS_Solver_Operation op,
+                                    enum GAS_Solver_Status stat,
+                                    enum GAS_Solver_Additional_Information);
 
+
 /**
  * Callback to call from solver when bandwidth for address has changed
  *
  * @param address the with changed bandwidth assigned
  */
 typedef void
-(*GAS_bandwidth_changed_cb) (void *cls, struct ATS_Address *address);
+(*GAS_bandwidth_changed_cb) (void *cls,
+                             struct ATS_Address *address);
 
+
 /**
  * Callback to call from solver to obtain application preference values for a
  * peer
@@ -378,8 +397,10 @@
  *      GNUNET_ATS_PreferenceCount elements
  */
 typedef const double *
-(*GAS_get_preferences) (void *cls, const struct GNUNET_PeerIdentity *id);
+(*GAS_get_preferences) (void *cls,
+                        const struct GNUNET_PeerIdentity *id);
 
+
 /**
  * Callback to call from solver to obtain transport properties for an
  * address
@@ -390,12 +411,14 @@
  *      GNUNET_ATS_PreferenceCount elements
  */
 typedef const double *
-(*GAS_get_properties) (void *cls, const struct ATS_Address *address);
+(*GAS_get_properties) (void *cls,
+                       const struct ATS_Address *address);
 
+
 /**
- * The ATS service will pass a pointer to a struct
- * of this type as the first and only argument to the
- * entry point of each ATS solver.
+ * The ATS plugin will pass a pointer to a struct
+ * of this type as to the initialization function
+ * of the ATS plugins.
  */
 struct GNUNET_ATS_PluginEnvironment
 {
@@ -407,9 +430,14 @@
   /**
    * Statistics handle to be used by the solver
    */
-  const struct GNUNET_STATISTICS_Handle *stats;
+  struct GNUNET_STATISTICS_Handle *stats;
 
   /**
+   * Closure to pass to all callbacks in this struct.
+   */
+  void *cls;
+
+  /**
    * Hashmap containing all addresses available
    */
   struct GNUNET_CONTAINER_MultiPeerMap *addresses;
@@ -420,48 +448,22 @@
   GAS_bandwidth_changed_cb bandwidth_changed_cb;
 
   /**
-   * ATS addresses closure to be notified about bandwidth assignment changes
-   */
-  void *bw_changed_cb_cls;
-
-  /**
    * ATS addresses function to obtain preference values
    */
   GAS_get_preferences get_preferences;
 
   /**
-   * ATS addresses function closure to obtain preference values
-   */
-  void *get_preference_cls;
-
-  /**
    * ATS addresses function to obtain property values
    */
   GAS_get_properties get_property;
 
   /**
-   * ATS addresses function closure to obtain property values
-   */
-  void *get_property_cls;
-
-  /**
    * Callback for solver to call with status information,
    * can be NULL
    */
   GAS_solver_information_callback info_cb;
 
   /**
-   * Closure for information callback,
-   * can be NULL
-   */
-  void *info_cb_cls;
-
-  /**
-   * The ATS solver plugin functions to call
-   */
-  struct GNUNET_ATS_SolverFunctions sf;
-
-  /**
    *  Available networks
    */
   int networks[GNUNET_ATS_NetworkTypeCount];




reply via email to

[Prev in Thread] Current Thread [Next in Thread]