[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25360 - gnunet/src/ats
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25360 - gnunet/src/ats |
Date: |
Mon, 10 Dec 2012 15:25:53 +0100 |
Author: wachs
Date: 2012-12-10 15:25:53 +0100 (Mon, 10 Dec 2012)
New Revision: 25360
Modified:
gnunet/src/ats/gnunet-service-ats_addresses.c
gnunet/src/ats/gnunet-service-ats_addresses.h
gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
gnunet/src/ats/gnunet-service-ats_addresses_mlp.h
gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c
gnunet/src/ats/gnunet-service-ats_addresses_simplistic.h
Log:
more changes
Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c 2012-12-10 14:16:04 UTC
(rev 25359)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c 2012-12-10 14:25:53 UTC
(rev 25360)
@@ -806,7 +806,6 @@
"Address %p ready for suggestion, block interval now %llu \n",
aa, aa->block_interval);
-
GNUNET_free (ats);
}
@@ -940,7 +939,42 @@
}
+static void
+bandwidth_changed_cb (struct ATS_Address *address)
+{
+ struct GAS_Addresses_Suggestion_Requests *cur;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bandwidth assignment changed for peer
%s \n", GNUNET_i2s(&address->peer));
+ struct GNUNET_ATS_Information *ats;
+ unsigned int ats_count;
+ cur = handle->r_head;
+ while (NULL != cur)
+ {
+ if (0 == memcmp (&address->peer, &cur->id, sizeof (cur->id)))
+ break; /* we have an address request pending*/
+ cur = cur->next;
+ }
+ if (NULL == cur)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Nobody is interested in peer `%s' :(\n",GNUNET_i2s
(&address->peer));
+ return;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending bandwidth update for peer `%s'\n",GNUNET_i2s
(&address->peer));
+
+ ats_count = assemble_ats_information (address, &ats);
+ GAS_scheduling_transmit_address_suggestion (&address->peer,
+ address->plugin,
+ address->addr, address->addr_len,
+ address->session_id,
+ ats, ats_count,
+ address->assigned_bw_out,
+ address->assigned_bw_in);
+}
+
+
/**
* Initialize address subsystem.
*
@@ -1042,7 +1076,7 @@
quota_count = load_quotas(cfg, quotas_in, quotas_out,
GNUNET_ATS_NetworkTypeCount);
- ah->solver = ah->s_init (cfg, stats, quotas, quotas_in, quotas_out,
quota_count);
+ ah->solver = ah->s_init (cfg, stats, quotas, quotas_in, quotas_out,
quota_count, &bandwidth_changed_cb);
if (NULL == ah->solver)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize solver!\n");
Modified: gnunet/src/ats/gnunet-service-ats_addresses.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.h 2012-12-10 14:16:04 UTC
(rev 25359)
+++ gnunet/src/ats/gnunet-service-ats_addresses.h 2012-12-10 14:25:53 UTC
(rev 25360)
@@ -148,6 +148,15 @@
/**
+ * Callback to call from solver when bandwidth for address has changed
+ *
+ * @param address the with changed bandwidth assigned
+ */
+
+typedef void
+ (*GAS_bandwidth_changed_cb) (struct ATS_Address *address);
+
+/**
* Init the simplistic problem solving component
*
* Quotas:
@@ -165,7 +174,8 @@
* @param stats the GNUNET_STATISTICS handle
* @param network array of GNUNET_ATS_NetworkType with length dest_length
* @param out_quota array of outbound quotas
- * param in_quota array of outbound quota
+ * @param in_quota array of outbound quota
+ * @param bw_changed_cb callback to call when assigned changes
* @return handle for the solver on success, NULL on fail
*/
typedef void *
@@ -174,7 +184,8 @@
int *network,
unsigned long long *out_quota,
unsigned long long *in_quota,
- int dest_length);
+ int dest_length,
+ GAS_bandwidth_changed_cb bw_changed_cb);
typedef void
Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.c 2012-12-10 14:16:04 UTC
(rev 25359)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.c 2012-12-10 14:25:53 UTC
(rev 25360)
@@ -1079,7 +1079,10 @@
GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
const struct GNUNET_STATISTICS_Handle *stats,
int *network,
- unsigned long long *out_dest, unsigned long long *in_dest, int
dest_length)
+ unsigned long long *out_dest,
+ unsigned long long *in_dest,
+ int dest_length,
+ GAS_bandwidth_changed_cb bw_changed_cb)
{
struct GAS_MLP_Handle * mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle));
Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.h 2012-12-10 14:16:04 UTC
(rev 25359)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.h 2012-12-10 14:25:53 UTC
(rev 25360)
@@ -316,13 +316,17 @@
*
* @param cfg configuration handle
* @param stats the GNUNET_STATISTICS handle
+ * @param bw_changed_cb callback to call when assigned changes
* @return struct GAS_MLP_Handle on success, NULL on fail
*/
void *
GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
const struct GNUNET_STATISTICS_Handle *stats,
int *network,
- unsigned long long *out_dest, unsigned long long *in_dest, int
dest_length);
+ unsigned long long *out_dest,
+ unsigned long long *in_dest,
+ int dest_length,
+ GAS_bandwidth_changed_cb bw_changed_cb);
/**
Modified: gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c 2012-12-10
14:16:04 UTC (rev 25359)
+++ gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c 2012-12-10
14:25:53 UTC (rev 25360)
@@ -41,6 +41,7 @@
struct Network *network_entries;
unsigned int networks;
+ GAS_bandwidth_changed_cb bw_changed;
};
struct Network
@@ -71,8 +72,19 @@
* Number of active addresses for this network
*/
unsigned int active_addresses;
+
+ struct AddressWrapper *head;
+ struct AddressWrapper *tail;
};
+struct AddressWrapper
+{
+ struct AddressWrapper *next;
+ struct AddressWrapper *prev;
+
+ struct ATS_Address *addr;
+};
+
/**
* Init the simplistic problem solving component
*
@@ -100,13 +112,15 @@
int *network,
unsigned long long *out_quota,
unsigned long long *in_quota,
- int dest_length)
+ int dest_length,
+ GAS_bandwidth_changed_cb bw_changed_cb)
{
int c;
struct GAS_SIMPLISTIC_Handle *s = GNUNET_malloc (sizeof (struct
GAS_SIMPLISTIC_Handle));
struct Network * cur;
char * net_str[GNUNET_ATS_NetworkTypeCount] = {"UNSPECIFIED", "LOOPBACK",
"LAN", "WAN", "WLAN"};
+ s->bw_changed = bw_changed_cb;
s->networks = dest_length;
s->network_entries = GNUNET_malloc (dest_length * sizeof (struct Network));
@@ -141,6 +155,7 @@
{
unsigned long long quota_in;
unsigned long long quota_out;
+ struct AddressWrapper *cur;
quota_in = net->total_quota_in / net->active_addresses;
quota_out = net->total_quota_out / net->active_addresses;
@@ -148,6 +163,22 @@
LOG (GNUNET_ERROR_TYPE_DEBUG,
"New quota for network type `%s' (in/out): %llu/%llu \n",
net->desc, quota_in, quota_out);
+
+ cur = net->head;
+ while (NULL != cur)
+ {
+ /* Compare to current bandwidth assigned */
+ if ((quota_in != ntohl(cur->addr->assigned_bw_in.value__)) ||
+ (quota_out != ntohl(cur->addr->assigned_bw_out.value__)))
+ {
+ cur->addr->assigned_bw_in.value__ = htonl (quota_in);
+ cur->addr->assigned_bw_out.value__ = htonl (quota_out);
+ /* Notify on change */
+ s->bw_changed (cur->addr);
+ }
+ cur = cur->next;
+ }
+
}
/**
@@ -162,20 +193,14 @@
{
struct GAS_SIMPLISTIC_Handle *s = solver;
struct Network *cur = NULL;
+ struct AddressWrapper *aw = NULL;
GNUNET_assert (NULL != s);
int c;
for (c = 0; c < s->networks; c++)
{
cur = &s->network_entries[c];
if (address->atsp_network_type == cur->type)
- {
- cur->active_addresses ++;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding new address for network type `%s' (now %u
total)\n",
- cur->desc,
- cur->active_addresses);
break;
- }
}
if (NULL == cur)
{
@@ -183,6 +208,16 @@
return;
}
+ aw = GNUNET_malloc (sizeof (struct AddressWrapper));
+ aw->addr = address;
+ GNUNET_CONTAINER_DLL_insert (cur->head, cur->tail, aw);
+ cur->active_addresses ++;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding new address for network type `%s' (now %u total)\n",
+ cur->desc,
+ cur->active_addresses);
+
/* Update quota for this network type */
update_quota (s, cur);
Modified: gnunet/src/ats/gnunet-service-ats_addresses_simplistic.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_simplistic.h 2012-12-10
14:16:04 UTC (rev 25359)
+++ gnunet/src/ats/gnunet-service-ats_addresses_simplistic.h 2012-12-10
14:25:53 UTC (rev 25360)
@@ -49,6 +49,7 @@
* @param network array of GNUNET_ATS_NetworkType with length dest_length
* @param out_quota array of outbound quotas
* param in_quota array of outbound quota
+ * @param bw_changed_cb callback to call when assigned changes
* @return handle for the solver on success, NULL on fail
*/
void *
@@ -57,7 +58,8 @@
int *network,
unsigned long long *out_quota,
unsigned long long *in_quota,
- int dest_length);
+ int dest_length,
+ GAS_bandwidth_changed_cb bw_changed_cb);
/**
* Shutdown the simplistic problem solving component
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25360 - gnunet/src/ats,
gnunet <=