[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r35161 - gnunet/src/ats
From: |
gnunet |
Subject: |
[GNUnet-SVN] r35161 - gnunet/src/ats |
Date: |
Sun, 8 Feb 2015 16:50:13 +0100 |
Author: grothoff
Date: 2015-02-08 16:50:13 +0100 (Sun, 08 Feb 2015)
New Revision: 35161
Modified:
gnunet/src/ats/plugin_ats_proportional.c
Log:
use new 'get_connectivity' API which is also RC-counting, instead of another map
Modified: gnunet/src/ats/plugin_ats_proportional.c
===================================================================
--- gnunet/src/ats/plugin_ats_proportional.c 2015-02-08 15:34:37 UTC (rev
35160)
+++ gnunet/src/ats/plugin_ats_proportional.c 2015-02-08 15:50:13 UTC (rev
35161)
@@ -210,124 +210,143 @@
*
*/
+/**
+ * FIXME.
+ */
#define PROPORTIONALITY_FACTOR 2.0
+
/**
- * A handle for the proportional solver
+ * Wrapper for addresses to store them in a
+ * `struct Network`'s linked list
*/
-struct GAS_PROPORTIONAL_Handle
+struct AddressWrapper
{
+ /**
+ * Next in DLL
+ */
+ struct AddressWrapper *next;
/**
- * Our execution environment.
+ * Previous in DLL
*/
- struct GNUNET_ATS_PluginEnvironment *env;
+ struct AddressWrapper *prev;
/**
- * Hashmap containing all valid addresses
+ * The address
*/
- struct GNUNET_CONTAINER_MultiPeerMap *addresses;
+ struct ATS_Address *addr;
+};
+
+/**
+ * Representation of a network
+ */
+struct Network
+{
/**
- * Pending address requests
+ * Network description
*/
- struct GNUNET_CONTAINER_MultiPeerMap *requests;
+ const char *desc;
/**
- * Bulk lock
+ * String for statistics total addresses
*/
- int bulk_lock;
+ char *stat_total;
/**
- * Number of changes while solver was locked
+ * String for statistics active addresses
*/
- int bulk_requests;
+ char *stat_active;
/**
- * Total number of addresses for solver
+ * Linked list of addresses in this network: head
*/
- unsigned int total_addresses;
+ struct AddressWrapper *head;
/**
- * Number of active addresses for solver
+ * Linked list of addresses in this network: tail
*/
- unsigned int active_addresses;
+ struct AddressWrapper *tail;
/**
- * Networks array
+ * Total inbound quota
*/
- struct Network *network_entries;
+ unsigned long long total_quota_in;
/**
- * Number of networks
+ * Total outbound quota
*/
- unsigned int network_count;
+ unsigned long long total_quota_out;
/**
- * Proportionality factor
+ * ATS network type
*/
- double prop_factor;
+ enum GNUNET_ATS_Network_Type type;
/**
- * Stability factor
+ * Number of active addresses for this network
*/
- double stability_factor;
+ unsigned int active_addresses;
+
+ /**
+ * Number of total addresses for this network
+ */
+ unsigned int total_addresses;
+
};
+
/**
- * Representation of a network
+ * A handle for the proportional solver
*/
-struct Network
+struct GAS_PROPORTIONAL_Handle
{
- /**
- * ATS network type
- */
- enum GNUNET_ATS_Network_Type type;
/**
- * Network description
+ * Our execution environment.
*/
- const char *desc;
+ struct GNUNET_ATS_PluginEnvironment *env;
/**
- * Total inbound quota
+ * Networks array
*/
- unsigned long long total_quota_in;
+ struct Network *network_entries;
/**
- * Total outbound quota
+ * Bulk lock
*/
- unsigned long long total_quota_out;
+ int bulk_lock;
/**
- * Number of active addresses for this network
+ * Number of changes while solver was locked
*/
- unsigned int active_addresses;
+ int bulk_requests;
/**
- * Number of total addresses for this network
+ * Total number of addresses for solver
*/
unsigned int total_addresses;
/**
- * String for statistics total addresses
+ * Number of active addresses for solver
*/
- char *stat_total;
+ unsigned int active_addresses;
/**
- * String for statistics active addresses
+ * Number of networks in @a network_entries
*/
- char *stat_active;
+ unsigned int network_count;
/**
- * Linked list of addresses in this network: head
+ * Proportionality factor
*/
- struct AddressWrapper *head;
+ double prop_factor;
/**
- * Linked list of addresses in this network: tail
+ * Stability factor
*/
- struct AddressWrapper *tail;
+ double stability_factor;
};
/**
@@ -357,28 +376,7 @@
};
-/**
- * Wrapper for addresses to store them in network's linked list
- */
-struct AddressWrapper
-{
- /**
- * Next in DLL
- */
- struct AddressWrapper *next;
- /**
- * Previous in DLL
- */
- struct AddressWrapper *prev;
-
- /**
- * The address
- */
- struct ATS_Address *addr;
-};
-
-
/**
* Function used to unload the plugin.
*
@@ -391,23 +389,25 @@
struct GAS_PROPORTIONAL_Handle *s = sf->cls;
struct AddressWrapper *cur;
struct AddressWrapper *next;
- int c;
+ unsigned int c;
for (c = 0; c < s->network_count; c++)
{
if (s->network_entries[c].total_addresses > 0)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Had %u addresses for network `%s' not deleted during shutdown\n",
- s->network_entries[c].total_addresses, s->network_entries[c].desc);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Had %u addresses for network `%s' not deleted during shutdown\n",
+ s->network_entries[c].total_addresses,
+ s->network_entries[c].desc);
//GNUNET_break(0);
}
if (s->network_entries[c].active_addresses > 0)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Had %u active addresses for network `%s' not deleted during
shutdown\n",
- s->network_entries[c].active_addresses, s->network_entries[c].desc);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Had %u active addresses for network `%s' not deleted during
shutdown\n",
+ s->network_entries[c].active_addresses,
+ s->network_entries[c].desc);
//GNUNET_break(0);
}
@@ -415,29 +415,30 @@
while (NULL != (cur = next))
{
next = cur->next;
- GNUNET_CONTAINER_DLL_remove(s->network_entries[c].head,
- s->network_entries[c].tail, cur);
+ GNUNET_CONTAINER_DLL_remove (s->network_entries[c].head,
+ s->network_entries[c].tail,
+ cur);
GNUNET_free_non_null (cur->addr->solver_information);
GNUNET_free(cur);
}
- GNUNET_free(s->network_entries[c].stat_total);
- GNUNET_free(s->network_entries[c].stat_active);
+ GNUNET_free (s->network_entries[c].stat_total);
+ GNUNET_free (s->network_entries[c].stat_active);
}
if (s->total_addresses > 0)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Had %u addresses not deleted during shutdown\n", s->total_addresses);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Had %u addresses not deleted during shutdown\n",
+ s->total_addresses);
// GNUNET_break(0);
}
if (s->active_addresses > 0)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Had %u active addresses not deleted during shutdown\n",
- s->active_addresses);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Had %u active addresses not deleted during shutdown\n",
+ s->active_addresses);
// GNUNET_break (0);
}
GNUNET_free (s->network_entries);
- GNUNET_CONTAINER_multipeermap_destroy (s->requests);
GNUNET_free (s);
return NULL;
}
@@ -452,21 +453,23 @@
static int
is_bandwidth_available_in_network (struct Network *net)
{
- GNUNET_assert(NULL != net);
unsigned int na = net->active_addresses + 1;
uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
+
if (((net->total_quota_in / na) > min_bw)
&& ((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);
+ 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);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Not enough bandwidth available for %u active addresses in network
`%s'\n",
+ na,
+ net->desc);
return GNUNET_NO;
}
@@ -868,7 +871,8 @@
static struct ATS_Address *dest;
dest = NULL;
- GNUNET_CONTAINER_multipeermap_get_multiple (addresses, peer,
+ GNUNET_CONTAINER_multipeermap_get_multiple (addresses,
+ peer,
&get_active_address_it,
&dest);
return dest;
@@ -1179,7 +1183,7 @@
/* Find active address */
current_address = get_active_address (s,
- s->addresses,
+ s->env->addresses,
peer);
LOG (GNUNET_ERROR_TYPE_INFO,
@@ -1189,7 +1193,7 @@
/* Find best address */
best_address = get_best_address (s,
- s->addresses,
+ s->env->addresses,
peer);
LOG (GNUNET_ERROR_TYPE_INFO,
"Peer `%s' has best address %p\n",
@@ -1295,12 +1299,15 @@
struct ATS_Address *active_address;
struct AddressSolverInformation *asi;
- if (GNUNET_NO ==
- GNUNET_CONTAINER_multipeermap_contains (s->requests, peer))
+ if (0 ==
+ s->env->get_connectivity (s->env->cls,
+ peer))
return; /* Peer is not requested */
/* This peer is requested, find best address */
- active_address = get_active_address (s, s->addresses, peer);
+ active_address = get_active_address (s,
+ s->env->addresses,
+ peer);
best_address = update_active_address (s, peer);
if ((NULL != best_address) && ((NULL != active_address) &&
@@ -1354,24 +1361,9 @@
struct GAS_PROPORTIONAL_Handle *s = solver;
const struct ATS_Address *best_address;
- /* Add to list of pending requests */
- if (GNUNET_NO ==
- GNUNET_CONTAINER_multipeermap_contains (s->requests, peer))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put (s->requests,
- peer,
- NULL,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- LOG (GNUNET_ERROR_TYPE_INFO,
- "Start suggesting addresses for peer `%s'\n",
- GNUNET_i2s (peer));
- }
-
best_address = update_active_address (s, peer);
if (s->bulk_lock > 0)
- return NULL; /* Do not suggest since bulk lock is pending */
-
+ return NULL;
return best_address;
}
@@ -1391,20 +1383,8 @@
struct AddressSolverInformation *asi;
struct Network *cur_net;
- if (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_contains (s->requests, peer))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_remove (s->requests,
- peer,
- NULL));
- LOG (GNUNET_ERROR_TYPE_INFO,
- "Stop suggesting addresses for peer `%s'\n",
- GNUNET_i2s (peer));
- }
-
cur = get_active_address (s,
- s->addresses,
+ s->env->addresses,
peer);
if (NULL != cur)
{
@@ -1636,16 +1616,22 @@
return;
}
- LOG(GNUNET_ERROR_TYPE_INFO,
- "Property `%s' for peer `%s' address %p changed to %.2f \n",
- GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
- address, rel_value);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Property `%s' for peer `%s' address %p changed to %.2f \n",
+ GNUNET_ATS_print_property_type (type),
+ GNUNET_i2s (&address->peer),
+ address,
+ rel_value);
- if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests,
&address->peer))
+ if (0 ==
+ s->env->get_connectivity (s->env->cls,
+ &address->peer))
return; /* Peer is not requested */
/* This peer is requested, find active and best address */
- active_address = get_active_address(s, s->addresses, &address->peer);
+ active_address = get_active_address(s,
+ s->env->addresses,
+ &address->peer);
best_address = update_active_address (s,
&address->peer);
@@ -1693,7 +1679,7 @@
aw = GNUNET_new (struct AddressWrapper);
aw->addr = address;
- GNUNET_CONTAINER_DLL_insert(net->head, net->tail, aw);
+ GNUNET_CONTAINER_DLL_insert (net->head, net->tail, aw);
address_increment (s, net, GNUNET_YES, GNUNET_NO);
asi = GNUNET_new (struct AddressSolverInformation);
@@ -1702,19 +1688,25 @@
asi->calculated_quota_out = 0;
aw->addr->solver_information = asi;
- LOG(GNUNET_ERROR_TYPE_INFO,
- "Adding new address %p for peer `%s', now total %u and active %u
addresses in network `%s'\n",
- address, GNUNET_i2s(&address->peer), net->total_addresses,
net->active_addresses, net->desc);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Adding new address %p for peer `%s', now total %u and active %u
addresses in network `%s'\n",
+ address,
+ GNUNET_i2s (&address->peer),
+ net->total_addresses,
+ net->active_addresses,
+ net->desc);
- if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests,
&address->peer))
+ if (0 ==
+ s->env->get_connectivity (s->env->cls,
+ &address->peer))
return; /* Peer is not requested */
/* This peer is requested, find best address */
- update_active_address (s, &address->peer);
+ update_active_address (s,
+ &address->peer);
}
-
/**
* Function invoked when the plugin is loaded.
*
@@ -1730,13 +1722,8 @@
struct GAS_PROPORTIONAL_Handle *s;
struct Network * cur;
float f_tmp;
- int c;
+ unsigned int c;
- GNUNET_assert (NULL != env);
- GNUNET_assert (NULL != env->cfg);
- GNUNET_assert (NULL != env->bandwidth_changed_cb);
- GNUNET_assert (NULL != env->get_preferences);
-
s = GNUNET_new (struct GAS_PROPORTIONAL_Handle);
s->env = env;
sf.cls = s;
@@ -1749,20 +1736,12 @@
sf.s_del = &GAS_proportional_address_delete;
sf.s_bulk_start = &GAS_proportional_bulk_start;
sf.s_bulk_stop = &GAS_proportional_bulk_stop;
-
- s->network_entries = GNUNET_malloc (env->network_count * sizeof (struct
Network));
-
- /* Init */
- s->active_addresses = 0;
- s->total_addresses = 0;
- s->bulk_lock = GNUNET_NO;
- s->addresses = env->addresses;
- s->requests = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
-
s->stability_factor = PROP_STABILITY_FACTOR;
if (GNUNET_SYSERR !=
- GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
- "PROP_STABILITY_FACTOR", &f_tmp))
+ GNUNET_CONFIGURATION_get_value_float (env->cfg,
+ "ats",
+ "PROP_STABILITY_FACTOR",
+ &f_tmp))
{
if ((f_tmp < 1.0) || (f_tmp > 2.0))
{
@@ -1776,31 +1755,36 @@
s->stability_factor = f_tmp;
LOG (GNUNET_ERROR_TYPE_INFO,
"Using %s of %.3f\n",
- "PROP_STABILITY_FACTOR", f_tmp);
+ "PROP_STABILITY_FACTOR",
+ f_tmp);
}
}
-
s->prop_factor = PROPORTIONALITY_FACTOR;
if (GNUNET_SYSERR !=
- GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ GNUNET_CONFIGURATION_get_value_float (env->cfg,
+ "ats",
"PROP_PROPORTIONALITY_FACTOR",
&f_tmp))
{
if (f_tmp < 1.0)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid %s configuration %f \n"),
- "PROP_PROPORTIONALITY_FACTOR", f_tmp);
+ _("Invalid %s configuration %f\n"),
+ "PROP_PROPORTIONALITY_FACTOR",
+ f_tmp);
}
else
{
s->prop_factor = f_tmp;
LOG (GNUNET_ERROR_TYPE_INFO,
"Using %s of %.3f\n",
- "PROP_PROPORTIONALITY_FACTOR", f_tmp);
+ "PROP_PROPORTIONALITY_FACTOR"
+ , f_tmp);
}
}
+ s->network_entries = GNUNET_malloc (env->network_count *
+ sizeof (struct Network));
for (c = 0; c < env->network_count; c++)
{
cur = &s->network_entries[c];
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r35161 - gnunet/src/ats,
gnunet <=