MODE_MLP
};
-static struct GNUNET_CONTAINER_MultiHashMap *addresses;
-static unsigned long long wan_quota_in;
-static unsigned long long wan_quota_out;
-static unsigned int active_addr_count;
-static int ats_mode;
-
-static int running;
-
-void *solver;
struct GAS_Addresses_Handle
{
+ struct GNUNET_CONTAINER_MultiHashMap *addresses;
+
+ unsigned long long wan_quota_in;
+
+ unsigned long long wan_quota_out;
+
+ unsigned int active_addr_count;
+
+ int running;
+
+
int ats_mode;
/* Solver handle */
void *solver;
GAS_solver_address_change_preference s_pref;
};
+struct GAS_Addresses_Handle *handle;
static unsigned int
assemble_ats_information (struct ATS_Address *aa, struct GNUNET_ATS_Information **dest)
if (GNUNET_YES != aa->active)
return GNUNET_OK;
- GNUNET_assert (active_addr_count > 0);
+ GNUNET_assert (handle->active_addr_count > 0);
/* Simple method */
- aa->assigned_bw_in.value__ = htonl (wan_quota_in / active_addr_count);
- aa->assigned_bw_out.value__ = htonl (wan_quota_out / active_addr_count);
+ aa->assigned_bw_in.value__ = htonl (handle->wan_quota_in / handle->active_addr_count);
+ aa->assigned_bw_out.value__ = htonl (handle->wan_quota_out / handle->active_addr_count);
send_bw_notification (aa);
"Recalculating bandwidth for all active connections\n");
GNUNET_STATISTICS_update (GSA_stats, "# bandwidth recalculations performed",
1, GNUNET_NO);
- GNUNET_STATISTICS_set (GSA_stats, "# active addresses", active_addr_count,
+ GNUNET_STATISTICS_set (GSA_stats, "# active addresses", handle->active_addr_count,
GNUNET_NO);
- GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_simple_it, NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &update_bw_simple_it, NULL);
}
/**
ret = GNUNET_NO;
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (addresses,
+ GNUNET_CONTAINER_multihashmap_remove (handle->addresses,
&addr->peer.hashPubKey,
addr));
#if HAVE_LIBGLPK
- if (ats_mode == MODE_MLP)
- GAS_mlp_address_delete (solver, addresses, addr);
+ if (handle->ats_mode == MODE_MLP)
+ GAS_mlp_address_delete (handle->solver, handle->addresses, addr);
#endif
if (GNUNET_YES == addr->active)
{
- active_addr_count--;
+ handle->active_addr_count--;
addr->active = GNUNET_NO;
ret = GNUNET_YES;
}
cac.exact_address = NULL;
cac.base_address = NULL;
cac.search = addr;
- GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
+ GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey,
&compare_address_it, &cac);
#if 0
}
-#if DEADCODE
static int
compare_address_session_it (void *cls, const struct GNUNET_HashCode * key, void *value)
{
{
if ((0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) && (aa->session_id == cac->search->session_id))
{
- cac->exact_address = aa;
+ cac->exact_address = aa;
return GNUNET_NO;
}
}
cac.exact_address = NULL;
cac.search = addr;
- GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
+ GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey,
&compare_address_session_it, &cac);
return cac.exact_address;
}
-#endif
void
struct ATS_Address *aa;
struct ATS_Address *old;
- if (GNUNET_NO == running)
+ if (GNUNET_NO == handle->running)
return;
- GNUNET_assert (NULL != addresses);
+ GNUNET_assert (NULL != handle->addresses);
aa = create_address (peer,
plugin_name,
{
/* We have a new address */
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (addresses,
+ GNUNET_CONTAINER_multihashmap_put (handle->addresses,
&peer->hashPubKey, aa,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' session id %u, %p\n",
struct ATS_Address *old;
uint32_t i;
- if (GNUNET_NO == running)
+ if (GNUNET_NO == handle->running)
return;
- GNUNET_assert (NULL != addresses);
+ GNUNET_assert (NULL != handle->addresses);
/* Get existing address */
old = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len,
}
/* Tell solver about update */
- switch (ats_mode)
+ switch (handle->ats_mode)
{
case MODE_MLP:
- GAS_mlp_address_update (solver, addresses, old);
+ GAS_mlp_address_update (handle->solver, handle->addresses, old);
break;
case MODE_SIMPLISTIC:
- GAS_simplistic_address_update (solver, addresses, old);
+ GAS_simplistic_address_update (handle->solver, handle->addresses, old);
break;
default:
GNUNET_break (0);
if (GNUNET_YES == aa->active)
{
aa->active = GNUNET_NO;
- active_addr_count--;
+ handle->active_addr_count--;
recalculate_assigned_bw ();
}
{
/* session was set to 0, update address */
#if HAVE_LIBGLPK
- if (ats_mode == MODE_MLP)
- GAS_mlp_address_update (solver, addresses, aa);
+ if (handle->ats_mode == MODE_MLP)
+ GAS_mlp_address_update (handle->solver, handle->addresses, aa);
#endif
}
struct ATS_Address *aa;
struct ATS_Address *old;
- if (GNUNET_NO == running)
+ if (GNUNET_NO == handle->running)
return;
/* Get existing address */
GNUNET_break (0 < strlen (plugin_name));
aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id);
- GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
+ GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey,
&destroy_by_session_id, aa);
free_address (aa);
struct ATS_Address *old;
- if (GNUNET_NO == running)
+ if (GNUNET_NO == handle->running)
return GNUNET_SYSERR;
old = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id, NULL, 0);
old->used = in_use;
/* Tell solver about update */
- switch (ats_mode)
+ switch (handle->ats_mode)
{
case MODE_MLP:
- GAS_mlp_address_update (solver, addresses, old);
+ GAS_mlp_address_update (handle->solver, handle->addresses, old);
break;
case MODE_SIMPLISTIC:
- GAS_simplistic_address_update (solver, addresses, old);
+ GAS_simplistic_address_update (handle->solver, handle->addresses, old);
break;
default:
GNUNET_break (0);
if (aa->active == GNUNET_NO)
{
aa->active = GNUNET_YES;
- active_addr_count++;
-
+ handle->active_addr_count++;
send_bw_notification (aa);
}
else
aa = NULL;
/* Get address with: stick to current address, lower distance, lower latency */
- GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
+ GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey,
&find_address_it, &aa);
if (aa == NULL)
{
if (aa->active == GNUNET_NO)
{
aa->active = GNUNET_YES;
- active_addr_count++;
- if (ats_mode == MODE_SIMPLISTIC)
+ handle->active_addr_count++;
+ if (handle->ats_mode == MODE_SIMPLISTIC)
{
recalculate_assigned_bw ();
}
void
GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
{
- if (GNUNET_NO == running)
+ if (GNUNET_NO == handle->running)
return;
- if (ats_mode == MODE_SIMPLISTIC)
+ if (handle->ats_mode == MODE_SIMPLISTIC)
{
request_address_simple (peer);
}
- if (ats_mode == MODE_MLP)
+ if (handle->ats_mode == MODE_MLP)
{
request_address_mlp(peer);
}
void
GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer)
{
- GNUNET_break (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple (addresses,
+ GNUNET_break (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses,
&peer->hashPubKey,
&reset_address_it,
NULL));
enum GNUNET_ATS_PreferenceKind kind,
float score)
{
- if (GNUNET_NO == running)
+ if (GNUNET_NO == handle->running)
return;
/* Tell solver about update */
- switch (ats_mode)
+ switch (handle->ats_mode)
{
case MODE_MLP:
- GAS_mlp_address_change_preference (solver, peer, kind, score);
+ GAS_mlp_address_change_preference (handle->solver, peer, kind, score);
break;
case MODE_SIMPLISTIC:
- GAS_simplistic_address_change_preference (solver, peer, kind, score);
+ GAS_simplistic_address_change_preference (handle->solver, peer, kind, score);
break;
default:
GNUNET_break (0);
const struct GNUNET_STATISTICS_Handle *stats)
{
struct GAS_Addresses_Handle *ah;
- int c;
char *quota_wan_in_str;
char *quota_wan_out_str;
char *mode_str;
- running = GNUNET_NO;
+ int c;
+
+ ah = GNUNET_malloc (sizeof (struct GAS_Addresses_Handle));
+ handle = ah;
+ handle->running = GNUNET_NO;
/* Initialize the system with configuration values */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", "WAN_QUOTA_IN", "a_wan_in_str))
{
if (0 == strcmp(quota_wan_in_str, "unlimited") ||
- (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_wan_in_str, &wan_quota_in)))
- wan_quota_in = (UINT32_MAX) /10;
+ (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_wan_in_str, &ah->wan_quota_in)))
+ ah->wan_quota_in = (UINT32_MAX) /10;
GNUNET_free (quota_wan_in_str);
quota_wan_in_str = NULL;
}
else
- {
- wan_quota_in = (UINT32_MAX) /10;
- }
+ ah->wan_quota_in = (UINT32_MAX) /10;
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", "WAN_QUOTA_OUT", "a_wan_out_str))
{
if (0 == strcmp(quota_wan_out_str, "unlimited") ||
- (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_wan_out_str, &wan_quota_out)))
- wan_quota_out = (UINT32_MAX) /10;
+ (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_wan_out_str, &ah->wan_quota_out)))
+ ah->wan_quota_out = (UINT32_MAX) /10;
GNUNET_free (quota_wan_out_str);
quota_wan_out_str = NULL;
}
else
- {
- wan_quota_out = (UINT32_MAX) /10;
- }
+ ah->wan_quota_out = (UINT32_MAX) /10;
/* Initialize the addresses database */
- addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO);
- GNUNET_assert (NULL != addresses);
+ ah->addresses = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO);
+ GNUNET_assert (NULL != ah->addresses);
/* Figure out configured solution method */
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "No ressource assignment method configured, using simplistic approch\n");
- ats_mode = MODE_SIMPLISTIC;
+ ah->ats_mode = MODE_SIMPLISTIC;
}
else
{
mode_str[c] = toupper (mode_str[c]);
if (0 == strcmp (mode_str, "SIMPLISTIC"))
{
- ats_mode = MODE_SIMPLISTIC;
+ ah->ats_mode = MODE_SIMPLISTIC;
}
else if (0 == strcmp (mode_str, "MLP"))
{
- ats_mode = MODE_MLP;
+ ah->ats_mode = MODE_MLP;
#if !HAVE_LIBGLPK
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Assignment method `%s' configured, but GLPK is not availabe, please install \n", mode_str);
- ats_mode = MODE_SIMPLISTIC;
+ ah->ats_mode = MODE_SIMPLISTIC;
#endif
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid ressource assignment method `%s' configured, using simplistic approch\n", mode_str);
- ats_mode = MODE_SIMPLISTIC;
+ ah->ats_mode = MODE_SIMPLISTIC;
}
}
-
-
- ah = GNUNET_malloc (sizeof (struct GAS_Addresses_Handle));
-
/* Start configured solution method */
- switch (ats_mode)
+ switch (ah->ats_mode)
{
case MODE_MLP:
/* Init the MLP solver with default values */
ah->s_del = &GAS_mlp_address_delete;
ah->s_done = &GAS_mlp_done;
#else
- GNUNET_freee (ah);
+ GNUNET_free (ah);
return NULL;
#endif
break;
GNUNET_assert (NULL != ah->s_done);
ah->solver = ah->s_init (cfg, stats);
- /* REMOVE */ solver = ah->solver;
if (NULL == ah->solver)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize MLP solver!\n");
}
/* up and running */
- running = GNUNET_YES;
+ ah->running = GNUNET_YES;
return ah;
}
void
GAS_addresses_destroy_all ()
{
- if (GNUNET_NO == running)
+ if (GNUNET_NO == handle->running)
return;
- if (addresses != NULL)
- GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL);
- GNUNET_assert (active_addr_count == 0);
+ if (handle->addresses != NULL)
+ GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &free_address_it, NULL);
+ GNUNET_assert (handle->active_addr_count == 0);
}
* Shutdown address subsystem.
*/
void
-GAS_addresses_done ()
+GAS_addresses_done (struct GAS_Addresses_Handle *handle)
{
- GAS_addresses_destroy_all ();
- running = GNUNET_NO;
- GNUNET_CONTAINER_multihashmap_destroy (addresses);
- addresses = NULL;
+ GNUNET_assert (NULL != handle);
+ GAS_addresses_destroy_all ();
+ handle->running = GNUNET_NO;
+ GNUNET_CONTAINER_multihashmap_destroy (handle->addresses);
+ handle->addresses = NULL;
+ GNUNET_free (handle);
/* Stop configured solution method */
- switch (ats_mode)
- {
- case MODE_MLP:
- /* Init the MLP solver with default values */
- GAS_mlp_done (solver);
- break;
- case MODE_SIMPLISTIC:
- /* Init the simplistic solver with default values */
- GAS_simplistic_done (solver);
- break;
- default:
- break;
- }
+
}
struct PeerIteratorContext
if (NULL == p_it)
return;
- GNUNET_assert (NULL != addresses);
+ GNUNET_assert (NULL != handle->addresses);
- size = GNUNET_CONTAINER_multihashmap_size(addresses);
+ size = GNUNET_CONTAINER_multihashmap_size(handle->addresses);
if (0 != size)
{
ip_ctx.it = p_it;
ip_ctx.it_cls = p_it_cls;
ip_ctx.peers_returned = GNUNET_CONTAINER_multihashmap_create (size, GNUNET_NO);
- GNUNET_CONTAINER_multihashmap_iterate (addresses, &peer_it, &ip_ctx);
+ GNUNET_CONTAINER_multihashmap_iterate (handle->addresses, &peer_it, &ip_ctx);
GNUNET_CONTAINER_multihashmap_destroy (ip_ctx.peers_returned);
}
p_it (p_it_cls, NULL);
struct PeerInfoIteratorContext pi_ctx;
struct GNUNET_BANDWIDTH_Value32NBO zero_bw;
GNUNET_assert (NULL != peer);
- GNUNET_assert (NULL != addresses);
+ GNUNET_assert (NULL != handle->addresses);
if (NULL == pi_it)
return; /* does not make sense without callback */
pi_ctx.it = pi_it;
pi_ctx.it_cls = pi_it_cls;
- GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, &peerinfo_it, &pi_ctx);
+ GNUNET_CONTAINER_multihashmap_get_multiple (handle->addresses, &peer->hashPubKey, &peerinfo_it, &pi_ctx);
if (NULL != pi_it)
pi_it (pi_it_cls, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, zero_bw, zero_bw);