REST: nothing triggers rest
[oweals/gnunet.git] / src / ats / plugin_ats_proportional.c
index 69afa8a524396e14231e584a2e8e8462b5b265b0..3fab09fb3ec3cb7f6c3132b6354a0e4ce54bab60 100644 (file)
@@ -1,21 +1,21 @@
 /*
  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
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ 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.
Affero 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.
+ You should have received a copy of the GNU Affero General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
  */
 /**
  * @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__)
@@ -141,7 +141,7 @@ struct Network
   /**
    * ATS network type
    */
-  enum GNUNET_ATS_Network_Type type;
+  enum GNUNET_NetworkType type;
 
   /**
    * Number of active addresses for this network
@@ -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)
@@ -430,7 +431,7 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Redistributing bandwidth in network %s with %u active and %u total addresses\n",
-         GNUNET_ATS_print_network_type(n->type),
+         GNUNET_NT_to_string(n->type),
          n->active_addresses,
          n->total_addresses);
     s->env->info_cb (s->env->cls,
@@ -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;
@@ -1035,7 +1007,7 @@ GAS_proportional_address_property_changed (void *solver,
 static void
 GAS_proportional_address_add (void *solver,
                               struct ATS_Address *address,
-                              enum GNUNET_ATS_Network_Type network)
+                              uint32_t network)
 {
   struct GAS_PROPORTIONAL_Handle *s = solver;
   struct Network *net;
@@ -1211,7 +1183,7 @@ libgnunet_plugin_ats_proportional_init (void *cls)
     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);
+    cur->desc = GNUNET_NT_to_string (c);
     GNUNET_asprintf (&cur->stat_total,
                      "# ATS addresses %s total",
                      cur->desc);