X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fats%2Fplugin_ats_proportional.c;h=9309bc2ea799df575b99b5884aea081cd2ab8552;hb=7c8c596991f6397ec3ca1911638acb2de721c7a7;hp=d65cbb289859017a44958ebb7831936439af48e7;hpb=03a39827ef721653ad9509ce12173bd674592caf;p=oweals%2Fgnunet.git diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index d65cbb289..9309bc2ea 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c @@ -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__) @@ -198,10 +198,6 @@ struct GAS_PROPORTIONAL_Handle */ unsigned int active_addresses; - /** - * Number of networks in @a network_entries - */ - unsigned int network_count; }; @@ -219,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; @@ -312,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) @@ -425,7 +422,7 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, { unsigned int i; - if (GNUNET_YES == s->bulk_lock) + if (0 != s->bulk_lock) { s->bulk_requests++; return; @@ -461,11 +458,14 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, } else { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Redistributing bandwidth in all %u networks\n", + s->env->network_count); 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++) + for (i = 0; i < s->env->network_count; i++) distribute_bandwidth (s, &s->network_entries[i]); s->env->info_cb (s->env->cls, @@ -476,7 +476,7 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, GAS_STAT_SUCCESS, GAS_INFO_PROP_ALL); - for (i = 0; i < s->network_count; i++) + for (i = 0; i < s->env->network_count; i++) propagate_bandwidth (s, &s->network_entries[i]); s->env->info_cb (s->env->cls, @@ -504,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, @@ -549,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; @@ -602,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) @@ -816,7 +792,7 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, } /* We do have a new address, activate it */ LOG (GNUNET_ERROR_TYPE_DEBUG, - "Suggesting new address %p for peer `%s'\n", + "Selecting new address %p for peer `%s'\n", best_address, GNUNET_i2s (peer)); /* Mark address as active */ @@ -837,7 +813,6 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, best_address, GNUNET_i2s (peer)); - if (GNUNET_NO == is_bandwidth_available_in_network (asi_best->network, 0)) @@ -849,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; @@ -861,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); @@ -903,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, @@ -1008,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; @@ -1062,16 +1032,10 @@ GAS_proportional_address_add (void *solver, net->stat_total, 1, GNUNET_NO); - if (0 != - s->env->get_connectivity (s->env->cls, - &address->peer)) - { - /* This peer is requested, find best address */ - update_active_address (s, - get_active_address (s, - &address->peer), - &address->peer); - } + update_active_address (s, + get_active_address (s, + &address->peer), + &address->peer); LOG (GNUNET_ERROR_TYPE_INFO, "Added new address for `%s', now total %u and active %u addresses in network `%s'\n", GNUNET_i2s (&address->peer), @@ -1251,7 +1215,7 @@ libgnunet_plugin_ats_proportional_done (void *cls) struct AddressWrapper *next; unsigned int c; - for (c = 0; c < s->network_count; c++) + for (c = 0; c < s->env->network_count; c++) { GNUNET_break (0 == s->network_entries[c].total_addresses); GNUNET_break (0 == s->network_entries[c].active_addresses);