use NULL as flag for evaluation of query, ensure we pass non-NULL for reply_block...
[oweals/gnunet.git] / src / ats / plugin_ats_proportional.c
index 69afa8a524396e14231e584a2e8e8462b5b265b0..9309bc2ea799df575b99b5884aea081cd2ab8552 100644 (file)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet.
- Copyright (C) 2011-2015 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2011-2015 GNUnet e.V.
 
  GNUnet is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
  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.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
  */
 /**
  * @file ats/plugin_ats_proportional.c
@@ -25,8 +25,8 @@
  */
 #include "platform.h"
 #include "gnunet_statistics_service.h"
-#include "gnunet_ats_plugin.h"
 #include "gnunet_ats_service.h"
+#include "gnunet_ats_plugin.h"
 #include "gnunet-service-ats_addresses.h"
 
 #define LOG(kind,...) GNUNET_log_from (kind, "ats-proportional",__VA_ARGS__)
@@ -215,7 +215,7 @@ is_bandwidth_available_in_network (struct Network *net,
   unsigned int na;
   uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
 
-  GNUNET_assert (net->active_addresses + extra >= 0);
+  GNUNET_assert (((int)net->active_addresses) + extra >= 0);
   na = net->active_addresses + extra;
   if (0 == na)
     return GNUNET_YES;
@@ -308,7 +308,8 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
       continue;
     peer_relative_prefs = s->env->get_preferences (s->env->cls,
                                                    &aw->addr->peer);
-    sum_relative_peer_prefences += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
+    sum_relative_peer_prefences
+      += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
     count_addresses++;
   }
   if (count_addresses != net->active_addresses)
@@ -503,27 +504,6 @@ struct FindBestAddressCtx
 };
 
 
-/**
- * Find index of a ATS property type in the quality properties array.
- *
- * @param type ATS property type
- * @return index in the quality array, #GNUNET_SYSERR if the type
- *         was not a quality property
- */
-static int
-find_quality_property_index (enum GNUNET_ATS_Property type)
-{
-  enum GNUNET_ATS_Property existing_types[] = GNUNET_ATS_QualityProperties;
-  unsigned int c;
-
-  for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
-    if (existing_types[c] == type)
-      return c;
-  GNUNET_break (0);
-  return GNUNET_SYSERR;
-}
-
-
 /**
  * Find a "good" address to use for a peer by iterating over the
  * addresses for this peer.  If we already have an existing address,
@@ -548,7 +528,6 @@ find_best_address_it (void *cls,
   double best_distance;
   double cur_delay;
   double cur_distance;
-  int index;
   unsigned int con;
   int bw_available;
   int need;
@@ -601,12 +580,10 @@ find_best_address_it (void *cls,
   }
 
   /* Now compare ATS information */
-  index = find_quality_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
-  cur_distance = current->atsin[index].norm;
-  best_distance = ctx->best->atsin[index].norm;
-  index = find_quality_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
-  cur_delay = current->atsin[index].norm;
-  best_delay = ctx->best->atsin[index].norm;
+  cur_distance = current->norm_distance.norm;
+  best_distance = ctx->best->norm_distance.norm;
+  cur_delay = current->norm_delay.norm;
+  best_delay = ctx->best->norm_delay.norm;
 
   /* user shorter distance */
   if (cur_distance < best_distance)
@@ -847,9 +824,10 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
     aw_min = NULL;
     for (aw = asi_best->network->head; NULL != aw; aw = aw->next)
     {
-      if (con_min >
-          (a_con = s->env->get_connectivity (s->env->cls,
-                                             &aw->addr->peer)))
+      if ( (con_min >
+            (a_con = s->env->get_connectivity (s->env->cls,
+                                               &aw->addr->peer))) &&
+           (GNUNET_YES == aw->addr->active) )
       {
         aw_min = aw;
         con_min = a_con;
@@ -859,7 +837,7 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s,
     }
     update_active_address (s,
                            aw_min->addr,
-                           &aw->addr->peer);
+                           &aw_min->addr->peer);
   }
   distribute_bandwidth_in_network (s,
                                    asi_best->network);
@@ -901,7 +879,7 @@ GAS_proportional_change_preference (void *solver,
  */
 static void
 GAS_proportional_feedback (void *solver,
-                           struct GNUNET_SERVER_Client *application,
+                           struct GNUNET_SERVICE_Client *application,
                            const struct GNUNET_PeerIdentity *peer,
                            const struct GNUNET_TIME_Relative scope,
                            enum GNUNET_ATS_PreferenceKind kind,
@@ -1006,16 +984,10 @@ GAS_proportional_bulk_stop (void *solver)
  *
  * @param solver solver handle
  * @param address the address
- * @param type the ATSI type
- * @param abs_value the absolute value of the property
- * @param rel_value the normalized value
  */
 static void
 GAS_proportional_address_property_changed (void *solver,
-                                           struct ATS_Address *address,
-                                           enum GNUNET_ATS_Property type,
-                                           uint32_t abs_value,
-                                           double rel_value)
+                                           struct ATS_Address *address)
 {
   struct GAS_PROPORTIONAL_Handle *s = solver;
   struct AddressWrapper *asi = address->solver_information;