#endif
#include "gnunet-service-ats_addresses_simplistic.h"
+/**
+ * ATS address management
+ *
+ * Adding addresses:
+ *
+ * - If you add a new address without a session, a new address will be added
+ * - If you add this address again now with a session a, the existing address
+ * will be updated with this session
+ * - If you add this address again now with a session b, a new address object
+ * with this session will be added
+
+ * Destroying addresses:
+ *
+ * - If you destroy an address without a session, the address itself and all
+ * address instances with an session will be removed
+ * - If you destroy an address with a session, the session for this address
+ * will be removed
+ *
+ * Conclusion
+ * Addresses without a session will be updated with a new session and if the
+ * the session is destroyed the session is removed and address itself still
+ * exists for suggestion
+ *
+ */
+
/**
* Available ressource assignment modes
};
/**
- * Handle for ATS address component
+ * Pending Address suggestion requests
*/
struct GAS_Addresses_Suggestion_Requests
{
+ /**
+ * Next in DLL
+ */
struct GAS_Addresses_Suggestion_Requests *next;
+
+ /**
+ * Previous in DLL
+ */
struct GAS_Addresses_Suggestion_Requests *prev;
+ /**
+ * Peer ID
+ */
struct GNUNET_PeerIdentity id;
};
*/
struct GAS_Addresses_Handle
{
+ /**
+ *
+ */
+ struct GNUNET_STATISTICS_Handle *stat;
+
/**
* A multihashmap to store all addresses
*/
};
-/**
- * Temporary handle
- */
-struct GAS_Addresses_Handle *handle;
-
-
static unsigned int
assemble_ats_information (const struct ATS_Address *aa, struct GNUNET_ATS_Information **dest)
{
res ++;
break;
case GNUNET_ATS_QUALITY_NET_DISTANCE:
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Old ATS type %u %u\n", dest->atsp_distance, ntohl (src[i].type));
dest->atsp_distance = ntohl (src[i].value);
res ++;
break;
aa->plugin = GNUNET_strdup (plugin_name);
aa->session_id = session_id;
aa->active = GNUNET_NO;
+ aa->used = GNUNET_NO;
aa->solver_information = NULL;
aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
/**
* Destroy the given address.
*
+ * @param handle the address handle
* @param addr address to destroy
* @return GNUNET_YES if bandwidth allocations should be recalcualted
*/
static int
-destroy_address (struct ATS_Address *addr)
+destroy_address (struct GAS_Addresses_Handle *handle, struct ATS_Address *addr)
{
int ret;
GNUNET_CONTAINER_multihashmap_remove (handle->addresses,
&addr->peer.hashPubKey,
addr));
-
- handle->s_del (handle->solver, handle->addresses, addr);
free_address (addr);
return ret;
}
* Compares by peer identity and network address OR by session ID
* (one of the two must match).
*
+ * @param handle the address handle
* @param peer peer to lookup addresses for
* @param addr existing address record
* @return existing address record, NULL for none
*/
struct ATS_Address *
-find_address (const struct GNUNET_PeerIdentity *peer,
- const struct ATS_Address *addr)
+find_equivalent_address (struct GAS_Addresses_Handle *handle,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct ATS_Address *addr)
{
struct CompareAddressContext cac;
static struct ATS_Address *
-lookup_address (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name, const void *plugin_addr,
- size_t plugin_addr_len, uint32_t session_id,
+lookup_address (struct GAS_Addresses_Handle *handle,
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name,
+ const void *plugin_addr,
+ size_t plugin_addr_len,
+ uint32_t session_id,
const struct GNUNET_ATS_Information *atsi,
uint32_t atsi_count)
{
struct ATS_Address *aa;
- struct ATS_Address *old;
+ struct ATS_Address *ea;
aa = create_address (peer,
plugin_name,
session_id);
/* Get existing address or address with session == 0 */
- old = find_address (peer, aa);
+ ea = find_equivalent_address (handle, peer, aa);
free_address (aa);
- if (old == NULL)
+ if (ea == NULL)
{
return NULL;
}
- else if (old->session_id != session_id)
+ else if (ea->session_id != session_id)
{
return NULL;
}
- return old;
+ return ea;
}
void
-GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name, const void *plugin_addr,
- size_t plugin_addr_len, uint32_t session_id,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count)
+GAS_addresses_add (struct GAS_Addresses_Handle *handle,
+ const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name, const void *plugin_addr,
+ size_t plugin_addr_len, uint32_t session_id,
+ const struct GNUNET_ATS_Information *atsi,
+ uint32_t atsi_count)
{
struct ATS_Address *aa;
- struct ATS_Address *old;
+ struct ATS_Address *ea;
unsigned int ats_res;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_assert (NULL != handle->addresses);
- aa = create_address (peer,
- plugin_name,
- plugin_addr, plugin_addr_len,
+ aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len,
session_id);
if (atsi_count != (ats_res = disassemble_ats_information(atsi, atsi_count, aa)))
{
}
/* Get existing address or address with session == 0 */
- old = find_address (peer, aa);
- if (old == NULL)
+ ea = find_equivalent_address (handle, peer, aa);
+ if (ea == NULL)
{
/* We have a new address */
GNUNET_assert (GNUNET_OK ==
GNUNET_free (aa->plugin);
GNUNET_free (aa);
- if (old->session_id != 0)
+ if (ea->session_id != 0)
{
- /* This address and session is already existing */
+ /* This address with the same session is already existing
+ * Should not happen */
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Added already existing address for peer `%s' `%s' %p with new session %u\n",
GNUNET_i2s (peer), plugin_name, session_id);
}
/* We have an address without an session, update this address */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Updated existing address for peer `%s' %p with new session %u\n",
- GNUNET_i2s (peer), old, session_id);
- old->session_id = session_id;
- if (atsi_count != (ats_res = disassemble_ats_information(atsi, atsi_count, old)))
+
+ /* Notify solver about update with atsi information and session */
+ handle->s_update (handle->solver, handle->addresses, ea, session_id, ea->used, atsi, atsi_count);
+
+ /* Do the update */
+ ea->session_id = session_id;
+ if (atsi_count != (ats_res = disassemble_ats_information(atsi, atsi_count, ea)))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "While updating address: had %u ATS elements to add, could only add %u\n",
- atsi_count, ats_res);
+ "While updating address: had %u ATS elements to add, could only add %u\n",
+ atsi_count, ats_res);
}
-
- handle->s_update (handle->solver, handle->addresses, old);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Updated existing address for peer `%s' %p with new session %u\n",
+ GNUNET_i2s (peer), ea, session_id);
}
void
-GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
+GAS_addresses_update (struct GAS_Addresses_Handle *handle,
+ const struct GNUNET_PeerIdentity *peer,
const char *plugin_name, const void *plugin_addr,
size_t plugin_addr_len, uint32_t session_id,
const struct GNUNET_ATS_Information *atsi,
GNUNET_assert (NULL != handle->addresses);
/* Get existing address */
- aa = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len,
+ aa = lookup_address (handle, peer, plugin_name, plugin_addr, plugin_addr_len,
session_id, atsi, atsi_count);
if (aa == NULL)
{
"ADDRESS UPDATE",
GNUNET_i2s (peer), aa);
+ /* Tell solver about update */
+ handle->s_update (handle->solver, handle->addresses, aa, session_id, aa->used, atsi, atsi_count);
+
+ /* Update address */
if (atsi_count != (ats_res = disassemble_ats_information (atsi, atsi_count, aa)))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Updated %u ATS elements for address %p\n",
ats_res, aa);
-
- /* Tell solver about update */
- handle->s_update (handle->solver, handle->addresses, aa);
}
+struct DestroyContext
+{
+ struct ATS_Address *aa;
+
+ struct GAS_Addresses_Handle *handle;
+
+ /**
+ * GNUNET_NO : full address
+ * GNUNET_YES : just session
+ */
+ int result;
+};
+
+
/**
* Delete an address
*
static int
destroy_by_session_id (void *cls, const struct GNUNET_HashCode * key, void *value)
{
- const struct ATS_Address *info = cls;
+ struct DestroyContext *dc = cls;
+ struct GAS_Addresses_Handle *handle = dc->handle;
+ const struct ATS_Address *des = dc->aa;
struct ATS_Address *aa = value;
- GNUNET_assert (0 ==
- memcmp (&aa->peer, &info->peer,
- sizeof (struct GNUNET_PeerIdentity)));
- /* session == 0, remove full address */
- if ((info->session_id == 0) && (0 == strcmp (info->plugin, aa->plugin)) &&
- (aa->addr_len == info->addr_len) &&
- (0 == memcmp (info->addr, aa->addr, aa->addr_len)))
- {
+ GNUNET_assert (0 == memcmp (&aa->peer, &des->peer,
+ sizeof (struct GNUNET_PeerIdentity)));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting address for peer `%s': `%s' %u\n",
- GNUNET_i2s (&aa->peer), aa->plugin, aa->session_id);
- destroy_address (aa);
- // FIXME if (GNUNET_YES == destroy_address (aa))recalculate_assigned_bw ();
- return GNUNET_OK;
- }
- /* session != 0, just remove session */
- if (aa->session_id != info->session_id)
- return GNUNET_OK; /* irrelevant */
- if (aa->session_id != 0)
- GNUNET_break (0 == strcmp (info->plugin, aa->plugin));
- /* session died */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting session for peer `%s': `%s' %u\n",
- GNUNET_i2s (&aa->peer), aa->plugin, aa->session_id);
- aa->session_id = 0;
-
- if (GNUNET_YES == aa->active)
+ if (des->session_id == 0)
{
- aa->active = GNUNET_NO;
- //FIXME recalculate_assigned_bw ();
- }
+ /* Session == 0, remove full address */
+ if ((0 == strcmp (des->plugin, aa->plugin)) &&
+ (aa->addr_len == des->addr_len) &&
+ (0 == memcmp (des->addr, aa->addr, aa->addr_len)))
+ {
- /* session == 0 and addrlen == 0 : destroy address */
- if (aa->addr_len == 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting session and address for peer `%s': `%s' %u\n",
- GNUNET_i2s (&aa->peer), aa->plugin, aa->session_id);
- (void) destroy_address (aa);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Deleting full address for peer `%s' session %u %p\n",
+ GNUNET_i2s (&aa->peer), aa->session_id, aa);
+
+ /* Notify solver about deletion */
+ handle->s_del (handle->solver, handle->addresses, aa, GNUNET_NO);
+ destroy_address (handle, aa);
+ dc->result = GNUNET_NO;
+ return GNUNET_OK; /* Continue iteration */
+ }
}
else
{
- /* session was set to 0, update address */
-#if HAVE_LIBGLPK
- if (handle->ats_mode == MODE_MLP)
- GAS_mlp_address_update (handle->solver, handle->addresses, aa);
-#endif
- }
+ /* Session != 0, just remove session */
+ if (aa->session_id != des->session_id)
+ return GNUNET_OK; /* irrelevant */
+
+ if ((aa->session_id != 0) &&
+ (0 != strcmp (des->plugin, aa->plugin)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Different plugins during removal: `%s' vs `%s' \n",
+ des->plugin, aa->plugin);
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
+ if (aa->addr_len == 0)
+ {
+ /* Inbound connection died, delete full address */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Deleting inbound address for peer `%s': `%s' session %u\n",
+ GNUNET_i2s (&aa->peer), aa->plugin, aa->session_id);
+
+ /* Notify solver about deletion */
+ handle->s_del (handle->solver, handle->addresses, aa, GNUNET_NO);
+ destroy_address (handle, aa);
+ dc->result = GNUNET_NO;
+ return GNUNET_OK; /* Continue iteration */
+ }
+ else
+ {
+ /* Session died */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Deleting session for peer `%s': `%s' %u\n",
+ GNUNET_i2s (&aa->peer), aa->plugin, aa->session_id);
+ /* Notify solver to delete session */
+ handle->s_del (handle->solver, handle->addresses, aa, GNUNET_YES);
+ aa->session_id = 0;
+ return GNUNET_OK;
+ }
+ }
return GNUNET_OK;
}
-
void
-GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
+GAS_addresses_destroy (struct GAS_Addresses_Handle *handle,
+ const struct GNUNET_PeerIdentity *peer,
const char *plugin_name, const void *plugin_addr,
size_t plugin_addr_len, uint32_t session_id)
{
- struct ATS_Address *aa;
- struct ATS_Address *old;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' for peer `%s'\n",
- "ADDRESS DESTROY",
- GNUNET_i2s (peer));
+ struct ATS_Address *ea;
+ struct DestroyContext dc;
if (GNUNET_NO == handle->running)
return;
/* Get existing address */
- old = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len,
+ ea = lookup_address (handle, peer, plugin_name, plugin_addr, plugin_addr_len,
session_id, NULL, 0);
- if (old == NULL)
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received `%s' for peer `%s' address %p session %u\n",
+ "ADDRESS DESTROY",
+ GNUNET_i2s (peer), ea, session_id);
+
+ if (ea == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Tried to destroy unknown address for peer `%s' `%s' session id %u\n",
GNUNET_i2s (peer), plugin_name, session_id);
}
GNUNET_break (0 < strlen (plugin_name));
- aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id);
+ dc.handle = handle;
+ dc.aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id);
+
GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey,
- &destroy_by_session_id, aa);
- free_address (aa);
+ &destroy_by_session_id, &dc);
+ free_address (dc.aa);
}
int
-GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer,
+GAS_addresses_in_use (struct GAS_Addresses_Handle *handle,
+ const struct GNUNET_PeerIdentity *peer,
const char *plugin_name, const void *plugin_addr,
size_t plugin_addr_len, uint32_t session_id, int in_use)
{
- struct ATS_Address *old;
+ struct ATS_Address *ea;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' for peer `%s'\n",
if (GNUNET_NO == handle->running)
return GNUNET_SYSERR;
- old = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id, NULL, 0);
- if (NULL == old)
+ ea = lookup_address (handle, peer, plugin_name,
+ plugin_addr, plugin_addr_len,
+ session_id, NULL, 0);
+ if (NULL == ea)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Trying to set unknown address `%s', %s %u %s \n",
GNUNET_break (0);
return GNUNET_SYSERR;
}
- if (old->used == in_use)
+ if (ea->used == in_use)
{
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Address in use called multiple times for peer `%s': %s -> %s \n",
GNUNET_i2s (peer),
- (GNUNET_NO == old->used) ? "NO" : "YES",
+ (GNUNET_NO == ea->used) ? "NO" : "YES",
(GNUNET_NO == in_use) ? "NO" : "YES");
return GNUNET_SYSERR;
}
- old->used = in_use;
/* Tell solver about update */
- handle->s_update (handle->solver, handle->addresses, old);
+ handle->s_update (handle->solver, handle->addresses, ea, session_id, in_use, NULL, 0);
+ ea->used = in_use;
return GNUNET_OK;
}
/**
* Cancel address suggestions for a peer
*
+ * @param handle the address handle
* @param peer the respective peer
*/
void
-GAS_addresses_request_address_cancel (const struct GNUNET_PeerIdentity *peer)
+GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle,
+ const struct GNUNET_PeerIdentity *peer)
{
struct GAS_Addresses_Suggestion_Requests *cur = handle->r_head;
"No address requests pending for peer `%s', cannot remove!\n", GNUNET_i2s (peer));
return;
}
- GAS_addresses_handle_backoff_reset (peer);
+ GAS_addresses_handle_backoff_reset (handle, peer);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Removed request pending for peer `%s\n", GNUNET_i2s (peer));
GNUNET_CONTAINER_DLL_remove (handle->r_head, handle->r_tail, cur);
/**
* Add an address suggestions for a peer
*
+ * @param handle the address handle
* @param peer the respective peer
*/
void
-GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
+GAS_addresses_request_address (struct GAS_Addresses_Handle *handle,
+ const struct GNUNET_PeerIdentity *peer)
{
struct GAS_Addresses_Suggestion_Requests *cur = handle->r_head;
struct ATS_Address *aa;
void
-GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer)
+GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle,
+ const struct GNUNET_PeerIdentity *peer)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' for peer `%s'\n",
void
-GAS_addresses_change_preference (const struct GNUNET_PeerIdentity *peer,
+GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle,
+ const struct GNUNET_PeerIdentity *peer,
enum GNUNET_ATS_PreferenceKind kind,
float score)
{
static unsigned int
load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *out_dest, unsigned long long *in_dest, int dest_length)
{
- int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+ char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
char * entry_in = NULL;
char * entry_out = NULL;
char * quota_out_str;
{
in_dest[c] = 0;
out_dest[c] = 0;
- switch (quotas[c]) {
- case GNUNET_ATS_NET_UNSPECIFIED:
- entry_out = "UNSPECIFIED_QUOTA_OUT";
- entry_in = "UNSPECIFIED_QUOTA_IN";
- break;
- case GNUNET_ATS_NET_LOOPBACK:
- entry_out = "LOOPBACK_QUOTA_OUT";
- entry_in = "LOOPBACK_QUOTA_IN";
- break;
- case GNUNET_ATS_NET_LAN:
- entry_out = "LAN_QUOTA_OUT";
- entry_in = "LAN_QUOTA_IN";
- break;
- case GNUNET_ATS_NET_WAN:
- entry_out = "WAN_QUOTA_OUT";
- entry_in = "WAN_QUOTA_IN";
- break;
- case GNUNET_ATS_NET_WLAN:
- entry_out = "WLAN_QUOTA_OUT";
- entry_in = "WLAN_QUOTA_IN";
- break;
- default:
- break;
- }
- if ((entry_in == NULL) || (entry_out == NULL))
- continue;
+ GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
+ GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
+
/* quota out */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
{
- if (0 == strcmp(quota_out_str, BIG_M_STRING) ||
- (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
- out_dest[c] = UINT32_MAX;
-
+ if (0 == strcmp(quota_out_str, BIG_M_STRING))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Outbound quota configure for network `%s' is unlimited (%llu)\n"),
+ network_str[c], GNUNET_ATS_MaxBandwidth);
+ out_dest[c] = GNUNET_ATS_MaxBandwidth;
+ }
+ else if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c]))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not convert quota configure for network `%s': `%s', assigning default bandwidth %llu\n"),
+ network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
+ out_dest[c] = GNUNET_ATS_DefaultBandwidth;
+ }
GNUNET_free (quota_out_str);
- quota_out_str = NULL;
}
- else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
- out_dest[c] = UINT32_MAX;
else
- out_dest[c] = UINT32_MAX;
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
+ network_str[c], GNUNET_ATS_DefaultBandwidth);
+ out_dest[c] = GNUNET_ATS_DefaultBandwidth;
+ }
/* quota in */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
{
- if (0 == strcmp(quota_in_str, BIG_M_STRING) ||
- (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
- in_dest[c] = UINT32_MAX;
+ if (0 == strcmp(quota_in_str, BIG_M_STRING))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Inbound quota configure for network `%s' is unlimited (%llu)\n"),
+ network_str[c], GNUNET_ATS_MaxBandwidth);
+ in_dest[c] = GNUNET_ATS_MaxBandwidth;
+ }
+ else if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c]))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not convert quota configure for network `%s': `%s', assigning default bandwidth %llu\n"),
+ network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
+ in_dest[c] = GNUNET_ATS_DefaultBandwidth;
+ }
GNUNET_free (quota_in_str);
- quota_in_str = NULL;
- }
- else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
- {
- in_dest[c] = UINT32_MAX;
}
else
{
- in_dest[c] = UINT32_MAX;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No inbound quota configure for network `%s', assigning default bandwidth %llu\n"),
+ network_str[c], GNUNET_ATS_DefaultBandwidth);
+ in_dest[c] = GNUNET_ATS_DefaultBandwidth;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota: %s %u, %s %u\n", entry_in, in_dest[c], entry_out, out_dest[c]);
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota for network `%s' (in/out): %llu %llu\n", network_str[c], in_dest[c], out_dest[c]);
+ GNUNET_free (entry_out);
+ GNUNET_free (entry_in);
}
return GNUNET_ATS_NetworkTypeCount;
}
static void
-bandwidth_changed_cb (struct ATS_Address *address)
+bandwidth_changed_cb (void *cls, struct ATS_Address *address)
{
+ struct GAS_Addresses_Handle *handle = cls;
struct GAS_Addresses_Suggestion_Requests *cur;
+
+ GNUNET_assert (handle != NULL);
+ GNUNET_assert (address != NULL);
+
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;
int c;
ah = GNUNET_malloc (sizeof (struct GAS_Addresses_Handle));
- handle = ah;
- handle->running = GNUNET_NO;
+ ah->running = GNUNET_NO;
+ ah->stat = (struct GNUNET_STATISTICS_Handle *) stats;
/* Initialize the addresses database */
ah->addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO);
GNUNET_assert (NULL != ah->addresses);
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, &bandwidth_changed_cb);
+ ah->solver = ah->s_init (cfg, stats, quotas, quotas_in, quotas_out, quota_count, &bandwidth_changed_cb, ah);
if (NULL == ah->solver)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize solver!\n");
static int
free_address_it (void *cls, const struct GNUNET_HashCode * key, void *value)
{
+ struct GAS_Addresses_Handle *handle = cls;
struct ATS_Address *aa = value;
-
- destroy_address (aa);
+ handle->s_del (handle->solver, handle->addresses, aa, GNUNET_NO);
+ destroy_address (handle, aa);
return GNUNET_OK;
}
void
-GAS_addresses_destroy_all ()
+GAS_addresses_destroy_all (struct GAS_Addresses_Handle *handle)
{
if (GNUNET_NO == handle->running)
return;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received `%s'\n",
+ "DESTROY ALL");
+
if (handle->addresses != NULL)
- GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &free_address_it, NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &free_address_it, handle);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Shutting down addresses\n");
GNUNET_assert (NULL != handle);
- GAS_addresses_destroy_all ();
+ GAS_addresses_destroy_all (handle);
handle->running = GNUNET_NO;
GNUNET_CONTAINER_multihashmap_destroy (handle->addresses);
handle->addresses = NULL;
/**
* Return all peers currently known to ATS
*
+ * @param handle the address handle
* @param p_it the iterator to call for every peer, callbach with id == NULL
* when done
* @param p_it_cls the closure for the iterator
*/
void
-GAS_addresses_iterate_peers (GNUNET_ATS_Peer_Iterator p_it, void *p_it_cls)
+GAS_addresses_iterate_peers (struct GAS_Addresses_Handle *handle, GNUNET_ATS_Peer_Iterator p_it, void *p_it_cls)
{
struct PeerIteratorContext ip_ctx;
unsigned int size;
/**
* Return all peers currently known to ATS
*
+ * @param handle the address handle
* @param peer the respective peer
* @param pi_it the iterator to call for every peer
* @param pi_it_cls the closure for the iterator
*/
void
-GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it, void *pi_it_cls)
+GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle,
+ const struct GNUNET_PeerIdentity *peer,
+ GNUNET_ATS_PeerInfo_Iterator pi_it,
+ void *pi_it_cls)
{
struct PeerInfoIteratorContext pi_ctx;
struct GNUNET_BANDWIDTH_Value32NBO zero_bw;