/*
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
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
*/
#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__)
*/
unsigned int active_addresses;
- /**
- * Number of networks in @a network_entries
- */
- unsigned int network_count;
};
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;
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)
{
unsigned int i;
- if (GNUNET_YES == s->bulk_lock)
+ if (0 != s->bulk_lock)
{
s->bulk_requests++;
return;
}
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,
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,
};
-/**
- * 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,
double best_distance;
double cur_delay;
double cur_distance;
- int index;
unsigned int con;
int bw_available;
int need;
}
/* 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)
}
/* 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 */
best_address,
GNUNET_i2s (peer));
-
if (GNUNET_NO ==
is_bandwidth_available_in_network (asi_best->network,
0))
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;
}
update_active_address (s,
aw_min->addr,
- &aw->addr->peer);
+ &aw_min->addr->peer);
}
distribute_bandwidth_in_network (s,
asi_best->network);
*
* @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;
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),
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);