"Address %p ready for suggestion, block interval now %llu \n",
aa, aa->block_interval);
-
GNUNET_free (ats);
}
}
+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.
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");
};
+/**
+ * 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
*
* @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 *
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
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));
*
* @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);
/**
struct Network *network_entries;
unsigned int networks;
+ GAS_bandwidth_changed_cb bw_changed;
};
struct Network
* 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;
};
/**
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));
{
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;
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;
+ }
+
}
/**
{
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)
{
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);
* @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 *
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