From c4745ca5df31efd2917ebd134ac82a0d1e1281f6 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Mon, 20 Feb 2012 22:02:28 +0000 Subject: [PATCH] - latest changes --- src/ats/gnunet-service-ats_addresses.c | 91 ++++++++++++++++------ src/ats/gnunet-service-ats_addresses_mlp.c | 8 +- 2 files changed, 73 insertions(+), 26 deletions(-) diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 843394a0f..8900abcb6 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -588,34 +588,68 @@ GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer, #endif } -void -GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) + +void request_address_mlp (const struct GNUNET_PeerIdentity *peer) { struct ATS_Address *aa; - aa = NULL; - if (ats_mode == SIMPLE) +#if HAVE_GLPK + /* Get preferred address from MLP */ + struct ATS_PreferedAddress * paddr = NULL; + paddr = GAS_mlp_get_preferred_address (mlp, addresses, peer); + aa = paddr->address; + aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(paddr->bandwidth_out); + /* FIXME use bw in value */ + paddr->bandwidth_in = paddr->bandwidth_out; + aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init (paddr->bandwidth_in); + GNUNET_free (paddr); +#endif + + if (aa == NULL) { - /* Get address with: stick to current address, lower distance, lower latency */ - GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, - &find_address_it, &aa); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer)); + return; } - if (ats_mode == MLP) + if (aa->active == GNUNET_NO) { -#if HAVE_GLPK -#endif - /* Get preferred address from MLP */ - struct ATS_PreferedAddress * paddr = NULL; - paddr = GAS_mlp_get_preferred_address (mlp, addresses, peer); - aa = paddr->address; - aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(paddr->bandwidth_out); - /* FIXME use bw in value */ - paddr->bandwidth_in = paddr->bandwidth_out; - aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init (paddr->bandwidth_in); - GNUNET_free (paddr); + aa->active = GNUNET_YES; + active_addr_count++; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n", + GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__), + ntohl (aa->assigned_bw_out.value__)); + GAS_scheduling_transmit_address_suggestion (&aa->peer, aa->plugin, aa->addr, + aa->addr_len, aa->session_id, + aa->ats, aa->ats_count, + aa->assigned_bw_out, + aa->assigned_bw_in); + GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in); + GAS_performance_notify_clients (&aa->peer, aa->plugin, aa->addr, aa->addr_len, + aa->ats, aa->ats_count, aa->assigned_bw_out, + aa->assigned_bw_in); + } + else + { + /* just to be sure... */ + GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr, + aa->addr_len, aa->session_id, + aa->ats, aa->ats_count, + aa->assigned_bw_out, + aa->assigned_bw_in); } +} + +void request_address_simple (const struct GNUNET_PeerIdentity *peer) +{ + struct ATS_Address *aa; + aa = NULL; + + /* Get address with: stick to current address, lower distance, lower latency */ + GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, + &find_address_it, &aa); if (aa == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -631,10 +665,6 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) { recalculate_assigned_bw (); } - if (ats_mode == SIMPLE) - { - recalculate_assigned_bw (); - } } else { @@ -648,6 +678,20 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) } +void +GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) +{ + if (ats_mode == SIMPLE) + { + request_address_simple (peer); + } + if (ats_mode == MLP) + { + request_address_mlp(peer); + } +} + + // FIXME: this function should likely end up in the LP-subsystem and // not with 'addresses' in the future... void @@ -692,7 +736,6 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); break; #else - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode"); ats_mode = SIMPLE; break; diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 1e10370d9..17e3f2f2a 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c @@ -1092,7 +1092,6 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tAddress %s %f\n", (n == 1.0) ? "[x]" : "[ ]", b); } - } if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK) @@ -1556,6 +1555,8 @@ mlp_get_preferred_address_it (void *cls, const GNUNET_HashCode * key, void *valu struct ATS_PreferedAddress *aa = (struct ATS_PreferedAddress *) cls; struct ATS_Address *addr = value; struct MLP_information *mlpi = addr->mlp_information; + if (mlpi == NULL) + return GNUNET_YES; if (mlpi->n == GNUNET_YES) { aa->address = addr; @@ -1583,8 +1584,11 @@ GAS_mlp_get_preferred_address (struct GAS_MLP_Handle *mlp, const struct GNUNET_PeerIdentity *peer) { struct ATS_PreferedAddress * aa = GNUNET_malloc (sizeof (struct ATS_PreferedAddress)); + aa->address = NULL; + aa->bandwidth_in = 0; + aa->bandwidth_out = 0; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting preferred address for `%s'\n", GNUNET_i2s (peer)); - GNUNET_CONTAINER_multihashmap_get_multiple(addresses, &peer->hashPubKey, mlp_get_preferred_address_it, aa); + GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, mlp_get_preferred_address_it, aa); return aa; } -- 2.25.1