From: Matthias Wachs Date: Fri, 17 Feb 2012 15:32:23 +0000 (+0000) Subject: - changes to ats X-Git-Tag: initial-import-from-subversion-38251~14822 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=847f1b045f087dac3ed2b8989a0512610b58b00d;hp=dde12b107415d22cf0dbe44e2a0b88a974b59ae0;p=oweals%2Fgnunet.git - changes to ats --- diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 04cc07c8b..12eaef113 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -77,17 +77,19 @@ static int ats_mode; * @return GNUNET_OK (continue to iterate) */ static int -update_bw_it (void *cls, const GNUNET_HashCode * key, void *value) +update_bw_simple_it (void *cls, const GNUNET_HashCode * key, void *value) { struct ATS_Address *aa = value; - - /* Simple method */ if (GNUNET_YES != aa->active) return GNUNET_OK; GNUNET_assert (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); + 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__)); @@ -117,7 +119,8 @@ recalculate_assigned_bw () 1, GNUNET_NO); GNUNET_STATISTICS_set (GSA_stats, "# active addresses", active_addr_count, GNUNET_NO); - GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_it, NULL); + + GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_simple_it, NULL); } /** @@ -591,14 +594,24 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) struct ATS_Address *aa; aa = NULL; - GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, - &find_address_it, &aa); - if (aa == NULL) + + if (ats_mode == SIMPLE) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer)); - return; + /* 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, + "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer)); + return; + } } + if (ats_mode == MLP) + { + /* Get preferred address from MLP */ + } + if (aa->active == GNUNET_NO) { aa->active = GNUNET_YES; diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 50d1e42a2..0c9e0b328 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c @@ -1026,17 +1026,20 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) mlpi = a->mlp_information; b = glp_mip_col_val(mlp->prob, mlpi->c_b); - n = glp_mip_col_val(mlp->prob, mlpi->c_n); + mlpi->b = b; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tAddress %f %f\n", n, b); + n = glp_mip_col_val(mlp->prob, mlpi->c_n); + if (n == 1.0) + mlpi->n = GNUNET_YES; + else + mlpi->n = GNUNET_NO; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tAddress %s %f\n", + (n == 1.0) ? "[x]" : "[ ]", b); } } - - - if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel(mlp->mlp_task); @@ -1416,6 +1419,41 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult } } +static int +mlp_get_preferred_address_it (void *cls, const GNUNET_HashCode * key, void *value) +{ + + struct ATS_Address **aa = (struct ATS_Address **)cls; + struct ATS_Address *addr = value; + struct MLP_information *mlpi = addr->mlp_information; + if (mlpi->n == GNUNET_YES) + { + *aa = addr; + return GNUNET_NO; + } + return GNUNET_YES; +} + + +/** + * Get the preferred address for a specific peer + * + * @param mlp the MLP Handle + * @param peer the peer + * @return suggested address + */ +struct ATS_Address * +GAS_mlp_get_preferred_address (struct GAS_MLP_Handle *mlp, + struct GNUNET_CONTAINER_MultiHashMap * addresses, + const struct GNUNET_PeerIdentity *peer) +{ + struct ATS_Address * aa = NULL; + 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); + return aa; +} + + /** * Changes the preferences for a peer in the MLP problem * diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index 52631eb3c..a2e665f4b 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h @@ -251,6 +251,10 @@ struct GAS_MLP_Handle */ struct MLP_information { + double b; + + int n; + /* bandwidth column index */ signed int c_b; @@ -348,6 +352,18 @@ GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, float score); +/** + * Get the preferred address for a specific peer + * + * @param mlp the MLP Handle + * @param peer the peer + * @return suggested address + */ +struct ATS_Address * +GAS_mlp_get_preferred_address (struct GAS_MLP_Handle *mlp, + struct GNUNET_CONTAINER_MultiHashMap * addresses, + const struct GNUNET_PeerIdentity *peer); + /** * Shutdown the MLP problem solving component */ diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index 23ab71f7a..ddcd41237 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_mlp.c @@ -45,6 +45,7 @@ struct GNUNET_CONTAINER_MultiHashMap * addresses; struct GAS_MLP_Handle *mlp; + static void create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct GNUNET_ATS_Information *ats) { @@ -73,6 +74,7 @@ check (void *cls, char *const *args, const char *cfgfile, return; #endif struct ATS_Address addr[10]; + struct ATS_Address *res[10]; stats = GNUNET_STATISTICS_create("ats", cfg); @@ -138,6 +140,11 @@ check (void *cls, char *const *args, const char *cfgfile, GNUNET_assert (GNUNET_OK == GAS_mlp_solve_problem(mlp)); + res[0] = GAS_mlp_get_preferred_address(mlp, addresses, &p[0]); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preferred address `%s' \n",res[0]->plugin); + res[1] = GAS_mlp_get_preferred_address(mlp, addresses, &p[1]); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preferred address `%s' \n",res[1]->plugin); + /* Delete an address */ GNUNET_CONTAINER_multihashmap_remove (addresses, &addr[0].peer.hashPubKey, &addr[0]); GAS_mlp_address_delete (mlp, addresses, &addr[0]);