-fix config, shutdown issue
[oweals/gnunet.git] / src / ats / plugin_ats_proportional.c
index a154ceff3e296e47dcf53ed3e3c47381f60d9fff..b4cabb0676afe60074d05693ea704468fe7cb4fa 100644 (file)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet.
- (C) 2011-2014 Christian Grothoff (and other contributing authors)
Copyright (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
@@ -282,7 +282,7 @@ struct Network
   /**
    * ATS network type
    */
-  unsigned int type;
+  enum GNUNET_ATS_Network_Type type;
 
   /**
    * Network description
@@ -687,8 +687,6 @@ find_best_address_it (void *cls,
   struct AddressSolverInformation *asi;
   struct GNUNET_TIME_Relative active_time;
   struct GNUNET_TIME_Relative min_active_time;
-  const double *norm_prop_cur;
-  const double *norm_prop_best;
   double best_delay;
   double best_distance;
   double cur_delay;
@@ -738,19 +736,12 @@ find_best_address_it (void *cls,
   }
 
   /* Now compare ATS information */
-  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];
+  cur_distance = current->atsin[index].norm;
+  best_distance = ctx->best->atsin[index].norm;
   index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
-  cur_delay = norm_prop_cur[index];
-
-  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);
-  best_delay = norm_prop_best[index];
+  cur_delay = current->atsin[index].norm;
+  best_delay = ctx->best->atsin[index].norm;
 
   /* user shorter distance */
   if (cur_distance < best_distance)
@@ -875,11 +866,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 +884,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];
 }
 
 
@@ -1105,53 +1097,61 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
         GNUNET_ATS_print_network_type(n->type),
         n->active_addresses, n->total_addresses);
 
-    if (NULL != s->env->info_cb)
-      s->env->info_cb(s->env->cls, GAS_OP_SOLVE_START,
-          GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
+    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->cls, GAS_OP_SOLVE_STOP,
-          GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
-    if (NULL != s->env->info_cb)
-      s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
-          GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
+    s->env->info_cb (s->env->cls,
+                     GAS_OP_SOLVE_STOP,
+                     GAS_STAT_SUCCESS,
+                     GAS_INFO_PROP_SINGLE);
+    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->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
-          GAS_STAT_SUCCESS, GAS_INFO_PROP_SINGLE);
+    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->cls, GAS_OP_SOLVE_START,
-          GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
+    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++)
     {
       /* Distribute */
       distribute_bandwidth(s, &s->network_entries[i]);
     }
 
-    if (NULL != s->env->info_cb)
-      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->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
-          GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
+    s->env->info_cb (s->env->cls,
+                     GAS_OP_SOLVE_STOP,
+                     GAS_STAT_SUCCESS,
+                     GAS_INFO_PROP_ALL);
+    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++)
     {
       /* Do propagation */
       propagate_bandwidth(s, &s->network_entries[i]);
     }
-    if (NULL != s->env->info_cb)
-      s->env->info_cb(s->env->cls, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
-          GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL);
+    s->env->info_cb (s->env->cls,
+                     GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
+                     GAS_STAT_SUCCESS,
+                     GAS_INFO_PROP_ALL);
   }
 }
 
@@ -1613,7 +1613,7 @@ GAS_proportional_address_add (void *solver,
 static void
 GAS_proportional_address_property_changed (void *solver,
                                            struct ATS_Address *address,
-                                           uint32_t type,
+                                           enum GNUNET_ATS_Property type,
                                            uint32_t abs_value,
                                            double rel_value)
 {
@@ -1672,24 +1672,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;
   }
 
@@ -1738,7 +1737,6 @@ libgnunet_plugin_ats_proportional_init (void *cls)
   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;
@@ -1807,7 +1805,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);