get rid of stupid network[i]=i array
authorChristian Grothoff <christian@grothoff.org>
Fri, 6 Feb 2015 09:28:57 +0000 (09:28 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 6 Feb 2015 09:28:57 +0000 (09:28 +0000)
src/ats/ats_api_scanner.c
src/ats/gnunet-ats-solver-eval.c
src/ats/gnunet-service-ats.c
src/ats/gnunet-service-ats_plugins.c
src/ats/perf_ats_solver.c
src/ats/plugin_ats_mlp.c
src/ats/plugin_ats_proportional.c
src/ats/plugin_ats_ril.c
src/include/gnunet_ats_plugin.h
src/include/gnunet_ats_service.h

index 43e79b3cf3f04ffa69b2dfdc94350ae884a09121..c213983f2043feda5a4819d98cfece2473513807 100644 (file)
@@ -331,7 +331,7 @@ GNUNET_ATS_scanner_address_get_type (struct GNUNET_ATS_InterfaceScanner *is,
                                      socklen_t addrlen)
 {
   struct ATS_Network *cur = is->net_head;
-  enum GNUNET_ATS_NetworkType type = GNUNET_ATS_NET_UNSPECIFIED;
+  enum GNUNET_ATS_Network_Type type = GNUNET_ATS_NET_UNSPECIFIED;
 
   switch (addr->sa_family)
     {
index bfb1c84ab56f1b3d66d8666b9c4ca14a7ba7dad4..c39bb30f700b57b6f09a87b3511e64c7f8cf4b84 100644 (file)
@@ -3057,7 +3057,6 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
 {
   struct SolverHandle *sh;
   char * solver_str;
-  int c;
 
   switch (type) {
     case GNUNET_ATS_SOLVER_PROPORTIONAL:
@@ -3091,10 +3090,6 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
   sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
   sh->env.info_cb = &solver_info_cb;
   sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
-  int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
-  for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
-    sh->env.networks[c] = networks[c];
-
 
   /* start normalization */
   GAS_normalization_start ();
index 9c809f913006f291ffa0906f449ad7917dbeed6f..830deb04bb6242eb248684b9264d74eca6b8ce0c 100644 (file)
@@ -126,10 +126,10 @@ cleanup_task (void *cls,
               const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GAS_addresses_done ();
+  GAS_connectivity_done ();
   GAS_plugins_done ();
   GAS_normalization_stop ();
   GAS_scheduling_done ();
-  GAS_connectivity_done ();
   GAS_performance_done ();
   GAS_preference_done ();
   GAS_reservations_done ();
index 7e03a1a7e8ce9634d5ee0b015d47eb61d672fc58..6c15bc27c0375c290c7e1fdd4a3f65236d4b6f8c 100644 (file)
@@ -452,7 +452,10 @@ GAS_plugins_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
     GNUNET_free(mode_str);
   }
 
-  load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount);
+  load_quotas (cfg,
+               quotas_out,
+               quotas_in,
+               GNUNET_ATS_NetworkTypeCount);
   env.cls = NULL;
   env.info_cb = &solver_info_cb;
   env.bandwidth_changed_cb = &bandwidth_changed_cb;
@@ -461,12 +464,9 @@ GAS_plugins_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
   env.cfg = cfg;
   env.stats = GSA_stats;
   env.addresses = GSA_addresses;
-
   env.network_count = GNUNET_ATS_NetworkTypeCount;
-  int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
   for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
   {
-    env.networks[c] = networks[c];
     env.out_quota[c] = quotas_out[c];
     env.in_quota[c] = quotas_in[c];
   }
index d81b5779b6623c680327b1d9eb088886817750cf..0d75561bc9313444377f9a0d4908615a6c1fce1d 100644 (file)
@@ -1307,16 +1307,14 @@ run (void *cls, char * const *args, const char *cfgfile,
   ph.env.network_count = GNUNET_ATS_NetworkTypeCount;
   ph.env.info_cb = &solver_info_cb;
 
-  int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
   for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
   {
-    ph.env.networks[c] = networks[c];
     ph.env.out_quota[c] = quotas_out[c];
     ph.env.in_quota[c] = quotas_in[c];
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading network quotas: `%s' %llu %llu \n",
-        GNUNET_ATS_print_network_type(ph.env.networks[c]),
-        ph.env.out_quota[c],
-        ph.env.in_quota[c]);
+                GNUNET_ATS_print_network_type (c),
+                ph.env.out_quota[c],
+                ph.env.in_quota[c]);
   }
   GAS_normalization_start ();
 
index 11f74a37f1e6e521d0d75ee8a7c06bcf6d5af97e..23fbf5063c98808c73d841399ed7f0ffef1f961a 100644 (file)
@@ -2420,14 +2420,11 @@ 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);
-
   float f_tmp;
   unsigned long long tmp;
   unsigned int b_min;
   unsigned int n_min;
   int c;
-  int c2;
-  int found;
   char *outputformat;
 
   struct GNUNET_TIME_Relative max_duration;
@@ -2740,77 +2737,55 @@ libgnunet_plugin_ats_mlp_init (void *cls)
     n_min = MLP_DEFAULT_MIN_CONNECTIONS;
 
   /* Init network quotas */
-  int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
   for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
   {
-      found = GNUNET_NO;
-      for (c2 = 0; c2 < env->network_count; c2++)
-      {
-          if (quotas[c] == env->networks[c2])
-          {
-              mlp->pv.quota_index[c] = env->networks[c2];
-              mlp->pv.quota_out[c] = env->out_quota[c2];
-              mlp->pv.quota_in[c] = env->in_quota[c2];
-
-              found = GNUNET_YES;
-              LOG (GNUNET_ERROR_TYPE_INFO,
-                  "Quota for network `%s' (in/out) %llu/%llu\n",
-                  GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
-                  mlp->pv.quota_out[c],
-                  mlp->pv.quota_in[c]);
-              break;
-
-          }
-      }
-
-      /* Check if defined quota could make problem unsolvable */
-      if ((n_min * b_min) > mlp->pv.quota_out[c])
-      {
-        LOG (GNUNET_ERROR_TYPE_INFO,
-            _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"),
-            GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
-            mlp->pv.quota_out[c],
-            (n_min * b_min));
-        mlp->pv.quota_out[c] = (n_min * b_min);
-      }
-      if ((n_min * b_min) > mlp->pv.quota_in[c])
-      {
-        LOG (GNUNET_ERROR_TYPE_INFO,
-            _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"),
-            GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
-            mlp->pv.quota_in[c],
-            (n_min * b_min));
-        mlp->pv.quota_in[c] = (n_min * b_min);
-      }
-
-      /* Check if bandwidth is too big to make problem solvable */
-      if (mlp->pv.BIG_M < mlp->pv.quota_out[c])
-      {
-        LOG (GNUNET_ERROR_TYPE_INFO,
-            _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"),
-            GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
-            mlp->pv.quota_out[c],
-            mlp->pv.BIG_M);
-        mlp->pv.quota_out[c] = mlp->pv.BIG_M ;
-      }
-      if (mlp->pv.BIG_M < mlp->pv.quota_in[c])
-      {
-        LOG (GNUNET_ERROR_TYPE_INFO, _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"),
-            GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
-            mlp->pv.quota_in[c],
-            mlp->pv.BIG_M);
-        mlp->pv.quota_in[c] = mlp->pv.BIG_M ;
-      }
+    mlp->pv.quota_index[c] = c;
+    mlp->pv.quota_out[c] = env->out_quota[c];
+    mlp->pv.quota_in[c] = env->in_quota[c];
 
-      if (GNUNET_NO == found)
-      {
-        mlp->pv.quota_in[c] = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
-        mlp->pv.quota_out[c] = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
-        LOG (GNUNET_ERROR_TYPE_INFO, _("Using default quota configuration for network `%s' (in/out) %llu/%llu\n"),
-            GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
-            mlp->pv.quota_in[c],
-            mlp->pv.quota_out[c]);
-      }
+    LOG (GNUNET_ERROR_TYPE_INFO,
+         "Quota for network `%s' (in/out) %llu/%llu\n",
+         GNUNET_ATS_print_network_type (c),
+         mlp->pv.quota_out[c],
+         mlp->pv.quota_in[c]);
+    /* Check if defined quota could make problem unsolvable */
+    if ((n_min * b_min) > mlp->pv.quota_out[c])
+    {
+      LOG (GNUNET_ERROR_TYPE_INFO,
+           _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"),
+           GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+           mlp->pv.quota_out[c],
+           (n_min * b_min));
+      mlp->pv.quota_out[c] = (n_min * b_min);
+    }
+    if ((n_min * b_min) > mlp->pv.quota_in[c])
+    {
+      LOG (GNUNET_ERROR_TYPE_INFO,
+           _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"),
+           GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+           mlp->pv.quota_in[c],
+           (n_min * b_min));
+      mlp->pv.quota_in[c] = (n_min * b_min);
+    }
+    /* Check if bandwidth is too big to make problem solvable */
+    if (mlp->pv.BIG_M < mlp->pv.quota_out[c])
+    {
+      LOG (GNUNET_ERROR_TYPE_INFO,
+           _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"),
+           GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+           mlp->pv.quota_out[c],
+           mlp->pv.BIG_M);
+      mlp->pv.quota_out[c] = mlp->pv.BIG_M ;
+    }
+    if (mlp->pv.BIG_M < mlp->pv.quota_in[c])
+    {
+      LOG (GNUNET_ERROR_TYPE_INFO,
+           _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"),
+           GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+           mlp->pv.quota_in[c],
+           mlp->pv.BIG_M);
+      mlp->pv.quota_in[c] = mlp->pv.BIG_M ;
+    }
   }
   mlp->env = env;
   sf.cls = mlp;
index a154ceff3e296e47dcf53ed3e3c47381f60d9fff..32ee9f4e432c9f4370d3cf72611208b52732d6d8 100644 (file)
@@ -282,7 +282,7 @@ struct Network
   /**
    * ATS network type
    */
-  unsigned int type;
+  enum GNUNET_ATS_Network_Type type;
 
   /**
    * Network description
@@ -875,11 +875,12 @@ get_active_address (void *solver,
                     const struct GNUNET_CONTAINER_MultiPeerMap * addresses,
                     const struct GNUNET_PeerIdentity *peer)
 {
-  static struct ATS_Address * dest = NULL;
+  static struct ATS_Address *dest;
 
   dest = NULL;
   GNUNET_CONTAINER_multipeermap_get_multiple (addresses, peer,
-                                              &get_active_address_it, &dest);
+                                              &get_active_address_it,
+                                              &dest);
   return dest;
 }
 
@@ -892,15 +893,15 @@ get_active_address (void *solver,
  * @return the network struct
  */
 static struct Network *
-get_network (struct GAS_PROPORTIONAL_Handle *s, uint32_t type)
+get_network (struct GAS_PROPORTIONAL_Handle *s,
+             enum GNUNET_ATS_Network_Type type)
 {
-  int c;
-  for (c = 0; c < s->network_count; c++)
+  if (type >= s->env->network_count)
   {
-    if (s->network_entries[c].type == type)
-      return &s->network_entries[c];
+    GNUNET_break (0);
+    return NULL;
   }
-  return NULL ;
+  return &s->network_entries[type];
 }
 
 
@@ -1672,24 +1673,23 @@ GAS_proportional_address_property_changed (void *solver,
 static void
 GAS_proportional_address_add (void *solver,
                               struct ATS_Address *address,
-                              uint32_t network)
+                              enum GNUNET_ATS_Network_Type network)
 {
   struct GAS_PROPORTIONAL_Handle *s = solver;
-  struct Network *net = NULL;
-  struct AddressWrapper *aw = NULL;
+  struct Network *net;
+  struct AddressWrapper *aw;
   struct AddressSolverInformation *asi;
 
-  GNUNET_assert(NULL != s);
   net = get_network (s, network);
   if (NULL == net)
   {
-    GNUNET_break(0);
-
-    LOG(GNUNET_ERROR_TYPE_ERROR,
-        "Unknown network %u `%s' for new address %p for peer `%s'\n",
-        network, GNUNET_ATS_print_network_type(network),
-        address, GNUNET_i2s(&address->peer));
-
+    GNUNET_break (0);
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         "Unknown network %u `%s' for new address %p for peer `%s'\n",
+         network,
+         GNUNET_ATS_print_network_type (network),
+         address,
+         GNUNET_i2s (&address->peer));
     return;
   }
 
@@ -1807,7 +1807,7 @@ libgnunet_plugin_ats_proportional_init (void *cls)
   for (c = 0; c < env->network_count; c++)
   {
     cur = &s->network_entries[c];
-    cur->type = env->networks[c];
+    cur->type = c;
     cur->total_quota_in = env->in_quota[c];
     cur->total_quota_out = env->out_quota[c];
     cur->desc = GNUNET_ATS_print_network_type (c);
index 6629355830fe62325c3912da18ee0b802abeb968..6718cae22fb907e9f19b12f4cde23bdb0fa07c4f 100644 (file)
@@ -2799,7 +2799,7 @@ libgnunet_plugin_ats_ril_init (void *cls)
   for (c = 0; c < env->network_count; c++)
   {
     cur = &solver->network_entries[c];
-    cur->type = env->networks[c];
+    cur->type = c;
     cur->bw_in_available = env->in_quota[c];
     cur->bw_out_available = env->out_quota[c];
     LOG(GNUNET_ERROR_TYPE_DEBUG, "init()  Quotas for %s network:  IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024);
index 36a49d25251fff5082c357afd2e97f532014f807..bec94b31bce9548101fbbaf330a199bde3a7b70b 100644 (file)
@@ -464,14 +464,10 @@ struct GNUNET_ATS_PluginEnvironment
   GAS_solver_information_callback info_cb;
 
   /**
-   *  Available networks
+   * Number of networks available, size of the @e out_quota
+   * and @e in_quota arrays.
    */
-  int networks[GNUNET_ATS_NetworkTypeCount];
-
-  /**
-   * Number of networks available
-   */
-  int network_count;
+  unsigned int network_count;
 
   /**
    * Array of configured outbound quotas
index 63c56048759e20f85ec9cea0ccf9bafab5ac7b3e..e4070c40fe8e5fb9118b62293d5dcbd9e335e44c 100644 (file)
 #include "gnunet_util_lib.h"
 #include "gnunet_hello_lib.h"
 
-/**
- * Number of network types supported by ATS
- */
-#define GNUNET_ATS_NetworkTypeCount 6
-
-
 /**
  * Types of networks (with separate quotas) we support.
  */
@@ -70,14 +64,13 @@ enum GNUNET_ATS_Network_Type
    * Bluetooth LAN
    */
   GNUNET_ATS_NET_BT = 5
-};
-
 
 /**
- * ATS network types as array initializer
+ * Number of network types supported by ATS
  */
-#define GNUNET_ATS_NetworkType { GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN, GNUNET_ATS_NET_BT }
+#define GNUNET_ATS_NetworkTypeCount 6
 
+};
 
 
 /**