gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r33650 - gnunet/src/ats


From: gnunet
Subject: [GNUnet-SVN] r33650 - gnunet/src/ats
Date: Wed, 11 Jun 2014 13:31:32 +0200

Author: grothoff
Date: 2014-06-11 13:31:32 +0200 (Wed, 11 Jun 2014)
New Revision: 33650

Removed:
   gnunet/src/ats/plugin_ats_proportional.h
Modified:
   gnunet/src/ats/Makefile.am
   gnunet/src/ats/plugin_ats_proportional.c
Log:
-simplify plugin, remove unnecessary header, make internal plugin functions 
static, doxygen, indentation, code simplification

Modified: gnunet/src/ats/Makefile.am
===================================================================
--- gnunet/src/ats/Makefile.am  2014-06-11 10:53:46 UTC (rev 33649)
+++ gnunet/src/ats/Makefile.am  2014-06-11 11:31:32 UTC (rev 33650)
@@ -518,7 +518,6 @@
 
 EXTRA_DIST = \
   ats.h \
-  plugin_ats_proportional.h \
   plugin_ats_mlp.h \
   plugin_ats_ril.h \
   test_ats_api.conf \

Modified: gnunet/src/ats/plugin_ats_proportional.c
===================================================================
--- gnunet/src/ats/plugin_ats_proportional.c    2014-06-11 10:53:46 UTC (rev 
33649)
+++ gnunet/src/ats/plugin_ats_proportional.c    2014-06-11 11:31:32 UTC (rev 
33650)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet.
- (C) 2011 Christian Grothoff (and other contributing authors)
+ (C) 2011-2014 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
@@ -24,8 +24,14 @@
  * @author Matthias Wachs
  * @author Christian Grothoff
  */
-#include "plugin_ats_proportional.h"
+#include "platform.h"
+#include "gnunet_statistics_service.h"
+#include "gnunet_ats_plugin.h"
+#include "gnunet-service-ats_addresses.h"
 
+#define PROP_STABILITY_FACTOR 1.25
+
+
 #define LOG(kind,...) GNUNET_log_from (kind, "ats-proportional",__VA_ARGS__)
 
 
@@ -102,12 +108,12 @@
  *    return of payload data transport switches to the real network
  *    the address is located in.  When an address changes networks it
  *    is first of all removed from the old network using the solver
- *    API function GAS_proportional_address_delete and the network in
+ *    API function #GAS_proportional_address_delete() and the network in
  *    the address struct is updated. A lookup for the respective new
  *    proportional network is done and stored in the addresse's
  *    solver_information field. Next the address is re-added to the
  *    solver using the solver API function
- *    GAS_proportional_address_add. If the address was marked as in
+ *    #GAS_proportional_address_add(). If the address was marked as in
  *    active, the solver checks if bandwidth is available in the
  *    network and if yes sets the address to active and updates the
  *    bandwidth distribution in this network. If no bandwidth is
@@ -345,7 +351,14 @@
    */
   char *stat_active;
 
+  /**
+   * FIXME.
+   */
   struct AddressWrapper *head;
+
+  /**
+   * FIXME.
+   */
   struct AddressWrapper *tail;
 };
 
@@ -396,119 +409,20 @@
   struct ATS_Address *addr;
 };
 
+
 /**
- *  Important solver functions
- *  ---------------------------
+ * Function used to unload the plugin.
+ *
+ * @param cls return value from #libgnunet_plugin_ats_proportional_init()
  */
-
 void *
-libgnunet_plugin_ats_proportional_init (void *cls)
-{
-  struct GNUNET_ATS_PluginEnvironment *env = cls;
-  struct GAS_PROPORTIONAL_Handle *s;
-  struct Network * cur;
-  char * net_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
-  float f_tmp;
-  int c;
-
-  GNUNET_assert (NULL != env);
-  GNUNET_assert(NULL != env->cfg);
-  GNUNET_assert(NULL != env->bandwidth_changed_cb);
-  GNUNET_assert(NULL != env->get_preferences);
-  GNUNET_assert(NULL != env->get_property);
-
-  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_address_update_session = &GAS_proportional_address_session_changed;
-  env->sf.s_address_update_inuse = &GAS_proportional_address_inuse_changed;
-  env->sf.s_address_update_network = &GAS_proportional_address_change_network;
-  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;
-
-  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 */
-  s->active_addresses = 0;
-  s->total_addresses = 0;
-  s->bulk_lock = GNUNET_NO;
-  s->addresses = env->addresses;
-  s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
-
-  s->stability_factor = PROP_STABILITY_FACTOR;
-  if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
-      "PROP_STABILITY_FACTOR", &f_tmp))
-  {
-    if ((f_tmp < 1.0) || (f_tmp > 2.0))
-    {
-      LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
-          "PROP_STABILITY_FACTOR", f_tmp);
-    }
-    else
-    {
-      s->stability_factor = f_tmp;
-      LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
-          "PROP_STABILITY_FACTOR", f_tmp);
-    }
-  }
-
-  s->prop_factor = PROPORTIONALITY_FACTOR;
-  if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
-      "PROP_STABILITY_FACTOR", &f_tmp))
-  {
-    if (f_tmp < 1.0)
-    {
-      LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
-          "PROP_PROPORTIONALITY_FACTOR", f_tmp);
-    }
-    else
-    {
-      s->prop_factor = f_tmp;
-      LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
-          "PROP_PROPORTIONALITY_FACTOR", f_tmp);
-    }
-  }
-
-  for (c = 0; c < env->network_count; c++)
-  {
-    cur = &s->network_entries[c];
-    cur->total_addresses = 0;
-    cur->active_addresses = 0;
-    cur->type = env->networks[c];
-    cur->total_quota_in = env->in_quota[c];
-    cur->total_quota_out = env->out_quota[c];
-    cur->desc = net_str[c];
-    GNUNET_asprintf (&cur->stat_total,
-        "# ATS addresses %s total", cur->desc);
-    GNUNET_asprintf (&cur->stat_active,
-        "# ATS active addresses %s total", cur->desc);
-    LOG (GNUNET_ERROR_TYPE_INFO, "Added network %u `%s' (%llu/%llu)\n",
-        c, cur->desc, cur->total_quota_in, cur->total_quota_out);
-  }
-  return s;
-}
-
-void *
 libgnunet_plugin_ats_proportional_done (void *cls)
 {
   struct GAS_PROPORTIONAL_Handle *s = cls;
   struct AddressWrapper *cur;
   struct AddressWrapper *next;
   int c;
+
   GNUNET_assert(s != NULL);
   for (c = 0; c < s->network_count; c++)
   {
@@ -564,7 +478,7 @@
  * Test if bandwidth is available in this network to add an additional address
  *
  * @param net the network type to update
- * @return GNUNET_YES or GNUNET_NO
+ * @return #GNUNET_YES or #GNUNET_NO
  */
 static int
 is_bandwidth_available_in_network (struct Network *net)
@@ -587,6 +501,7 @@
   return GNUNET_NO;
 }
 
+
 /**
  * Update bandwidth assigned to peers in this network
  *
@@ -749,6 +664,10 @@
   }
 }
 
+
+/**
+ * FIXME.
+ */
 struct FindBestAddressCtx
 {
   struct GAS_PROPORTIONAL_Handle *s;
@@ -756,6 +675,9 @@
 };
 
 
+/**
+ * FIXME.
+ */
 static int
 find_property_index (uint32_t type)
 {
@@ -915,21 +837,26 @@
   return GNUNET_OK;
 }
 
+
+/**
+ * FIXME.
+ */
 struct ATS_Address *
 get_best_address (struct GAS_PROPORTIONAL_Handle *s,
-    struct GNUNET_CONTAINER_MultiPeerMap *addresses,
-    const struct GNUNET_PeerIdentity *id)
+                  struct GNUNET_CONTAINER_MultiPeerMap *addresses,
+                  const struct GNUNET_PeerIdentity *id)
 {
   struct FindBestAddressCtx fba_ctx;
+
   fba_ctx.best = NULL;
   fba_ctx.s = s;
-
   GNUNET_CONTAINER_multipeermap_get_multiple (addresses, id,
-      &find_best_address_it, &fba_ctx);
+                                              &find_best_address_it, &fba_ctx);
 
   return fba_ctx.best;
 }
 
+
 /**
  * Hashmap Iterator to find current active address for peer
  *
@@ -952,8 +879,9 @@
     if (NULL != (*dest))
     {
       /* should never happen */
-      LOG(GNUNET_ERROR_TYPE_ERROR, "Multiple active addresses for peer `%s'\n",
-          GNUNET_i2s (&aa->peer));
+      LOG (GNUNET_ERROR_TYPE_ERROR,
+           "Multiple active addresses for peer `%s'\n",
+           GNUNET_i2s (&aa->peer));
       GNUNET_break(0);
       return GNUNET_NO;
     }
@@ -962,6 +890,7 @@
   return GNUNET_OK;
 }
 
+
 /**
  * Find current active address for peer
  *
@@ -1003,9 +932,14 @@
 }
 
 
+/**
+ * FIXME.  Degermanize.
+ */
 static void
-addresse_increment (struct GAS_PROPORTIONAL_Handle *s, struct Network *net,
-    int total, int active)
+addresse_increment (struct GAS_PROPORTIONAL_Handle *s,
+                    struct Network *net,
+                    int total,
+                    int active)
 {
   if (GNUNET_YES == total)
   {
@@ -1026,11 +960,17 @@
 }
 
 
+/**
+ * FIXME.  Degermanize.
+ */
 static int
-addresse_decrement (struct GAS_PROPORTIONAL_Handle *s, struct Network *net,
-    int total, int active)
+addresse_decrement (struct GAS_PROPORTIONAL_Handle *s,
+                    struct Network *net,
+                    int total,
+                    int active)
 {
   int res = GNUNET_OK;
+
   if (GNUNET_YES == total)
   {
     if (s->total_addresses < 1)
@@ -1083,6 +1023,10 @@
   return res;
 }
 
+
+/**
+ * FIXME.
+ */
 static int
 address_eq (struct ATS_Address *a, struct ATS_Address *b)
 {
@@ -1099,13 +1043,13 @@
   return GNUNET_YES;
 }
 
+
 /**
- *  Helper functions
- *  ---------------------------
+ * FIXME.
  */
 static void
 propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
-    struct Network *net)
+                     struct Network *net)
 {
   struct AddressWrapper *cur;
   struct AddressSolverInformation *asi;
@@ -1139,6 +1083,7 @@
   }
 }
 
+
 /**
  * Distribibute bandwidth
  *
@@ -1148,7 +1093,7 @@
  */
 static void
 distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
-    struct Network *n)
+                                 struct Network *n)
 {
   if (GNUNET_YES == s->bulk_lock)
   {
@@ -1213,17 +1158,22 @@
   }
 }
 
+
+/**
+ * FIXME
+ */
 static const struct ATS_Address *
 update_active_address (struct GAS_PROPORTIONAL_Handle *s,
-    const struct GNUNET_PeerIdentity *peer)
+                       const struct GNUNET_PeerIdentity *peer)
 {
   struct ATS_Address *best_address;
   struct ATS_Address *current_address;
   struct AddressSolverInformation *asi;
   struct Network *net;
 
-  LOG (GNUNET_ERROR_TYPE_INFO, "Updating active address for peer `%s'\n",
-      GNUNET_i2s (peer));
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "Updating active address for peer `%s'\n",
+       GNUNET_i2s (peer));
 
   /* Find active address */
   current_address = get_active_address (s, s->addresses, peer);
@@ -1304,10 +1254,6 @@
   return best_address;
 }
 
-/**
- *  Solver API functions
- *  ---------------------------
- */
 
 /**
  * Changes the preferences for a peer in the problem
@@ -1317,7 +1263,7 @@
  * @param kind the kind to change the preference
  * @param pref_rel the normalized preference value for this kind over all 
clients
  */
-void
+static void
 GAS_proportional_address_change_preference (void *solver,
                                            const struct GNUNET_PeerIdentity 
*peer,
                                            enum GNUNET_ATS_PreferenceKind kind,
@@ -1328,7 +1274,7 @@
   struct ATS_Address *active_address;
   struct AddressSolverInformation *asi;
 
-  GNUNET_assert(NULL != solver);
+  GNUNET_assert(NULL != s);
   GNUNET_assert(NULL != peer);
 
   if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, peer))
@@ -1360,16 +1306,17 @@
  * @param kind the kind to change the preference
  * @param score the score
  */
-void
-GAS_proportional_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)
+static void
+GAS_proportional_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 GAS_PROPORTIONAL_Handle *s = solver;
-  GNUNET_assert(NULL != solver);
+
   GNUNET_assert(NULL != peer);
-
   GNUNET_assert(NULL != s);
 }
 
@@ -1377,14 +1324,13 @@
 /**
  * Get the preferred address for a specific peer
  *
- *
- *
  * @param solver the solver handle
  * @param peer the identity of the peer
+ * @return FIXME
  */
-const struct ATS_Address *
+static const struct ATS_Address *
 GAS_proportional_get_preferred_address (void *solver,
-    const struct GNUNET_PeerIdentity *peer)
+                                        const struct GNUNET_PeerIdentity *peer)
 {
   struct GAS_PROPORTIONAL_Handle *s = solver;
   const struct ATS_Address *best_address;
@@ -1410,15 +1356,16 @@
   return best_address;
 }
 
+
 /**
  * Stop notifying about address and bandwidth changes for this peer
  *
  * @param solver the solver handle
  * @param peer the peer
  */
-void
+static void
 GAS_proportional_stop_get_preferred_address (void *solver,
-    const struct GNUNET_PeerIdentity *peer)
+                                             const struct GNUNET_PeerIdentity 
*peer)
 {
   struct GAS_PROPORTIONAL_Handle *s = solver;
   struct ATS_Address *cur;
@@ -1453,6 +1400,7 @@
   return;
 }
 
+
 /**
  * Remove an address from the solver
  *
@@ -1460,9 +1408,10 @@
  * @param address the address to remove
  * @param session_only delete only session not whole address
  */
-void
-GAS_proportional_address_delete (void *solver, struct ATS_Address *address,
-    int session_only)
+static void
+GAS_proportional_address_delete (void *solver,
+                                 struct ATS_Address *address,
+                                 int session_only)
 {
   struct GAS_PROPORTIONAL_Handle *s = solver;
   struct Network *net;
@@ -1554,17 +1503,19 @@
 
 }
 
+
 /**
  * Start a bulk operation
  *
  * @param solver the solver
  */
-void
+static void
 GAS_proportional_bulk_start (void *solver)
 {
-  LOG(GNUNET_ERROR_TYPE_DEBUG, "Locking solver for bulk operation ...\n");
-  struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) 
solver;
+  struct GAS_PROPORTIONAL_Handle *s = solver;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Locking solver for bulk operation ...\n");
   GNUNET_assert(NULL != solver);
   s->bulk_lock++;
 }
@@ -1573,12 +1524,13 @@
 /**
  * Bulk operation done
  */
-void
+static void
 GAS_proportional_bulk_stop (void *solver)
 {
-  LOG(GNUNET_ERROR_TYPE_DEBUG, "Unlocking solver from bulk operation ...\n");
+  struct GAS_PROPORTIONAL_Handle *s = solver;
 
-  struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) 
solver;
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Unlocking solver from bulk operation ...\n");
   GNUNET_assert(NULL != solver);
 
   if (s->bulk_lock < 1)
@@ -1603,10 +1555,12 @@
  * @param address the address to add
  * @param network network type of this address
  */
-void
-GAS_proportional_address_add (void *solver, struct ATS_Address *address,
-    uint32_t network);
+static void
+GAS_proportional_address_add (void *solver,
+                              struct ATS_Address *address,
+                              uint32_t network);
 
+
 /**
  * Transport properties for this address have changed
  *
@@ -1616,21 +1570,21 @@
  * @param abs_value the absolute value of the property
  * @param rel_value the normalized value
  */
-void
+static void
 GAS_proportional_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)
 {
-  struct GAS_PROPORTIONAL_Handle *s;
+  struct GAS_PROPORTIONAL_Handle *s = solver;
   struct Network *n;
   struct AddressSolverInformation *asi;
   struct ATS_Address *best_address;
   struct ATS_Address *active_address;
 
-  GNUNET_assert(NULL != solver);
+  GNUNET_assert(NULL != s);
   GNUNET_assert(NULL != address);
-
-  s = (struct GAS_PROPORTIONAL_Handle *) solver;
   asi = address->solver_information;
   if (NULL == asi)
   {
@@ -1678,20 +1632,23 @@
  * @param cur_session the current session
  * @param new_session the new session
  */
-void
+static void
 GAS_proportional_address_session_changed (void *solver,
-    struct ATS_Address *address, uint32_t cur_session, uint32_t new_session)
+                                          struct ATS_Address *address,
+                                          uint32_t cur_session,
+                                          uint32_t new_session)
 {
   struct GAS_PROPORTIONAL_Handle *s = solver;
   struct ATS_Address *best_address;
   struct ATS_Address *active_address;
   struct AddressSolverInformation *asi;
 
-  s = (struct GAS_PROPORTIONAL_Handle *) solver;
   if (cur_session != new_session)
   {
-    LOG(GNUNET_ERROR_TYPE_DEBUG, "Session changed from %u to %u\n", 
cur_session,
-        new_session);
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Session changed from %u to %u\n",
+         cur_session,
+         new_session);
   }
 
   if (NULL == address->solver_information)
@@ -1718,6 +1675,7 @@
   }
 }
 
+
 /**
  * Usage for this address has changed
  *
@@ -1727,20 +1685,19 @@
  * @param address the address
  * @param in_use usage state
  */
-void
+static void
 GAS_proportional_address_inuse_changed (void *solver,
-    struct ATS_Address *address, int in_use)
+                                        struct ATS_Address *address,
+                                        int in_use)
 {
-  struct GAS_PROPORTIONAL_Handle *s;
+  struct GAS_PROPORTIONAL_Handle *s = solver;
   struct Network *n;
   struct AddressSolverInformation *asi;
   struct ATS_Address *best_address;
   struct ATS_Address *active_address;
 
-  GNUNET_assert(NULL != solver);
+  GNUNET_assert(NULL != s);
   GNUNET_assert(NULL != address);
-
-  s = (struct GAS_PROPORTIONAL_Handle *) solver;
   asi = address->solver_information;
   if (NULL == asi)
   {
@@ -1788,11 +1745,13 @@
  * @param current_network the current network
  * @param new_network the new network
  */
-void
+static void
 GAS_proportional_address_change_network (void *solver,
-    struct ATS_Address *address, uint32_t current_network, uint32_t 
new_network)
+                                         struct ATS_Address *address,
+                                         uint32_t current_network,
+                                         uint32_t new_network)
 {
-  struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) 
solver;
+  struct GAS_PROPORTIONAL_Handle *s = solver;
   struct AddressSolverInformation *asi;
   int save_active = GNUNET_NO;
 
@@ -1866,9 +1825,10 @@
  * @param address the address to add
  * @param network network type of this address
  */
-void
-GAS_proportional_address_add (void *solver, struct ATS_Address *address,
-    uint32_t network)
+static void
+GAS_proportional_address_add (void *solver,
+                              struct ATS_Address *address,
+                              uint32_t network)
 {
   struct GAS_PROPORTIONAL_Handle *s = solver;
   struct Network *net = NULL;
@@ -1912,4 +1872,122 @@
 }
 
 
+
+/**
+ * Function invoked when the plugin is loaded.
+ *
+ * @param cls[in,out] the `struct GNUNET_ATS_PluginEnvironment *` to use;
+ *            modified to return the API functions (ugh).
+ * @return the `struct GAS_PROPORTIONAL_Handle` to pass as a closure
+ */
+void *
+libgnunet_plugin_ats_proportional_init (void *cls)
+{
+  struct GNUNET_ATS_PluginEnvironment *env = cls;
+  struct GAS_PROPORTIONAL_Handle *s;
+  struct Network * cur;
+  char * net_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
+  float f_tmp;
+  int c;
+
+  GNUNET_assert (NULL != env);
+  GNUNET_assert (NULL != env->cfg);
+  GNUNET_assert (NULL != env->bandwidth_changed_cb);
+  GNUNET_assert (NULL != env->get_preferences);
+  GNUNET_assert (NULL != env->get_property);
+
+  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_address_update_session = &GAS_proportional_address_session_changed;
+  env->sf.s_address_update_inuse = &GAS_proportional_address_inuse_changed;
+  env->sf.s_address_update_network = &GAS_proportional_address_change_network;
+  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;
+
+  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 */
+  s->active_addresses = 0;
+  s->total_addresses = 0;
+  s->bulk_lock = GNUNET_NO;
+  s->addresses = env->addresses;
+  s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
+
+  s->stability_factor = PROP_STABILITY_FACTOR;
+  if (GNUNET_SYSERR !=
+      GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+                                            "PROP_STABILITY_FACTOR", &f_tmp))
+  {
+    if ((f_tmp < 1.0) || (f_tmp > 2.0))
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR,
+           _("Invalid %s configuration %f \n"),
+           "PROP_STABILITY_FACTOR",
+           f_tmp);
+    }
+    else
+    {
+      s->stability_factor = f_tmp;
+      LOG (GNUNET_ERROR_TYPE_INFO,
+           "Using %s of %.3f\n",
+           "PROP_STABILITY_FACTOR", f_tmp);
+    }
+  }
+
+  s->prop_factor = PROPORTIONALITY_FACTOR;
+  if (GNUNET_SYSERR !=
+      GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+                                            "PROP_STABILITY_FACTOR", &f_tmp))
+  {
+    if (f_tmp < 1.0)
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR,
+           _("Invalid %s configuration %f \n"),
+           "PROP_PROPORTIONALITY_FACTOR", f_tmp);
+    }
+    else
+    {
+      s->prop_factor = f_tmp;
+      LOG (GNUNET_ERROR_TYPE_INFO,
+           "Using %s of %.3f\n",
+           "PROP_PROPORTIONALITY_FACTOR", f_tmp);
+    }
+  }
+
+  for (c = 0; c < env->network_count; c++)
+  {
+    cur = &s->network_entries[c];
+    cur->total_addresses = 0;
+    cur->active_addresses = 0;
+    cur->type = env->networks[c];
+    cur->total_quota_in = env->in_quota[c];
+    cur->total_quota_out = env->out_quota[c];
+    cur->desc = net_str[c];
+    GNUNET_asprintf (&cur->stat_total,
+        "# ATS addresses %s total", cur->desc);
+    GNUNET_asprintf (&cur->stat_active,
+        "# ATS active addresses %s total", cur->desc);
+    LOG (GNUNET_ERROR_TYPE_INFO,
+         "Added network %u `%s' (%llu/%llu)\n",
+        c, cur->desc, cur->total_quota_in, cur->total_quota_out);
+  }
+  return s;
+}
+
+
 /* end of plugin_ats_proportional.c */

Deleted: gnunet/src/ats/plugin_ats_proportional.h
===================================================================
--- gnunet/src/ats/plugin_ats_proportional.h    2014-06-11 10:53:46 UTC (rev 
33649)
+++ gnunet/src/ats/plugin_ats_proportional.h    2014-06-11 11:31:32 UTC (rev 
33650)
@@ -1,188 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2011 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
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING.  If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file ats/plugin_ats_proportional.h
- * @brief ATS proportional solver
- * @author Matthias Wachs
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "gnunet_statistics_service.h"
-#include "gnunet_ats_plugin.h"
-#include "gnunet-service-ats_addresses.h"
-
-#define PROP_STABILITY_FACTOR 1.25
-
-/**
- * ATS proportional solver
- *
- * General description
- */
-
-/**
- * Changes the preferences for a peer in the problem
- *
- * @param solver the solver handle
- * @param peer the peer to change the preference for
- * @param kind the kind to change the preference
- * @param pref_rel the normalized preference value for this kind over all 
clients
- */
-void
-GAS_proportional_address_change_preference (void *solver,
-    const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind 
kind,
-    double pref_rel);
-
-/**
- * Get application feedback for a peer
- *
- * @param solver the solver handle
- * @param application the application
- * @param peer the peer to change the preference for
- * @param scope the time interval for this feedback: [now - scope .. now]
- * @param kind the kind to change the preference
- * @param score the score
- */
-void
-GAS_proportional_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);
-
-/**
- * Shutdown the proportional problem solver
- *
- * @param solver the respective handle to shutdown
- */
-void
-GAS_proportional_done (void * solver);
-
-/**
- * Add a single address within a network to the solver
- *
- * @param solver the solver Handle
- * @param address the address to add
- * @param network network type of this address
- */
-void
-GAS_proportional_address_add (void *solver, struct ATS_Address *address,
-    uint32_t network);
-
-/**
- * Transport properties for this address have changed
- *
- * @param solver solver handle
- * @param address the address
- * @param type the ATSI type in HBO
- * @param abs_value the absolute value of the property
- * @param rel_value the normalized value
- */
-void
-GAS_proportional_address_property_changed (void *solver,
-    struct ATS_Address *address, uint32_t type, uint32_t abs_value,
-    double rel_value);
-
-/**
- * Transport session for this address has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param cur_session the current session
- * @param new_session the new session
- */
-void
-GAS_proportional_address_session_changed (void *solver,
-    struct ATS_Address *address, uint32_t cur_session, uint32_t new_session);
-
-/**
- * Usage for this address has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param in_use usage state
- */
-void
-GAS_proportional_address_inuse_changed (void *solver,
-    struct ATS_Address *address, int in_use);
-
-/**
- * Network scope for this address has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param current_network the current network
- * @param new_network the new network
- */
-void
-GAS_proportional_address_change_network (void *solver,
-    struct ATS_Address *address, uint32_t current_network, uint32_t 
new_network);
-
-/**
- * Remove an address from the solver
- *
- * @param solver the solver handle
- * @param address the address to remove
- * @param session_only delete only session not whole address
- */
-void
-GAS_proportional_address_delete (void *solver, struct ATS_Address *address,
-    int session_only);
-
-/**
- * Start a bulk operation
- *
- * @param solver the solver
- */
-void
-GAS_proportional_bulk_start (void *solver);
-
-/**
- * Bulk operation done
- */
-void
-GAS_proportional_bulk_stop (void *solver);
-
-/**
- * Stop notifying about address and bandwidth changes for this peer
- *
- * @param solver the proportional handle
- * @param peer the peer
- */
-void
-GAS_proportional_stop_get_preferred_address (void *solver,
-    const struct GNUNET_PeerIdentity *peer);
-
-/**
- * Get the prefered address for a specific peer
- *
- * @param solver the solver handle
- * @param peer the identity of the peer
- */
-const struct ATS_Address *
-GAS_proportional_get_preferred_address (void *solver,
-    const struct GNUNET_PeerIdentity *peer);
-
-/* end of plugin_ats_proportional.h */




reply via email to

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