struct GNUNET_CONTAINER_MultiHashMap *peers;
};
+
+/**
+ * Get the prefered address for a specific peer
+ *
+ * @param solver the solver handle
+ * @param addresses the address hashmap containing all addresses
+ * @param peer the identity of the peer
+ */
+const struct ATS_Address *
+GAS_simplistic_get_preferred_address (void *solver,
+ struct GNUNET_CONTAINER_MultiHashMap * addresses,
+ const struct GNUNET_PeerIdentity *peer);
+
/**
* Init the simplistic problem solving component
*
GNUNET_free (s);
}
+static unsigned long long int
+calculate_new_quota (unsigned long long int total,
+ unsigned int addresses)
+{
+ return (total / addresses);
+}
+
+/**
+ * Test if bandwidth is available in this network
+ *
+ * @param s the solver handle
+ * @param net the network type to update
+ * @return GNUNET_YES or GNUNET_NO
+ */
+
+static int
+bw_available_in_network (struct Network *net)
+{
+ unsigned int na = net->active_addresses + 1;
+ uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
+ if ((calculate_new_quota (net->total_quota_in, na) > min_bw) &&
+ (calculate_new_quota (net->total_quota_out, na) > min_bw))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Enough bandwidth available for %u active addresses in network `%s'\n",
+ na,
+ net->desc);
+
+ return GNUNET_YES;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Not enough bandwidth available for %u active addresses in network `%s'\n",
+ na,
+ net->desc);
+ return GNUNET_NO;
+}
+
/**
* Update the quotas for a network type
*
* @param address_except address excluded from notifcation, since we suggest
* this address
*/
-
static void
update_quota_per_network (struct GAS_SIMPLISTIC_Handle *s,
struct Network *net,
if (net->active_addresses == 0)
return; /* no addresses to update */
- quota_in = net->total_quota_in / net->active_addresses;
- quota_out = net->total_quota_out / net->active_addresses;
+ quota_in = calculate_new_quota (net->total_quota_in, net->active_addresses);
+ quota_out = calculate_new_quota (net->total_quota_out, net->active_addresses);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"New per address quota for network type `%s' for %u addresses (in/out): %llu/%llu \n",
net->desc, net->total_addresses, net->active_addresses);
}
-
if (GNUNET_YES == address->active)
{
/* Address was active, remove from network and update quotas*/
const struct GNUNET_ATS_Information *atsi,
uint32_t atsi_count)
{
+ struct ATS_Address *new;
struct GAS_SIMPLISTIC_Handle *s = (struct GAS_SIMPLISTIC_Handle *) solver;
int i;
uint32_t value;
GAS_simplistic_address_add (solver, addresses, address);
if (GNUNET_YES == save_active)
{
+ /* check if bandwidth available*/
+ if (GNUNET_NO == (bw_available_in_network (new_net)))
+ {
+ /* Find new address to suggest since no bandwidth in network*/
+ new = (struct ATS_Address *) GAS_simplistic_get_preferred_address (s, addresses, &address->peer);
+ if (NULL != new)
+ {
+ /* Have an alternative address to suggest */
+ s->bw_changed (s->bw_changed_cls, address);
+ }
+ else
+ continue;
+ }
addresse_increment (s, new_net, GNUNET_NO, GNUNET_YES);
update_quota_per_network (solver, new_net, NULL);
}
struct ATS_Address *current = (struct ATS_Address *) value;
struct ATS_Address *previous = *previous_p;
struct GNUNET_TIME_Absolute now;
+ struct Network *net = (struct Network *) current->solver_information;
now = GNUNET_TIME_absolute_get();
return GNUNET_OK;
}
+ if (GNUNET_NO == bw_available_in_network (net))
+ return GNUNET_OK; /* There's no bandwidth available in this network */
+
if (NULL != previous)
{
if ((0 == strcmp (previous->plugin, "tcp")) &&
update_quota_per_network (s, net_prev, NULL);
}
+ if (GNUNET_NO == (bw_available_in_network (cur->solver_information)))
+ {
+ GNUNET_break (0); /* This should never happen*/
+ return NULL;
+ }
+
cur->active = GNUNET_YES;
addresse_increment(s, net_cur, GNUNET_NO, GNUNET_YES);
update_quota_per_network (s, net_cur, cur);