From ddf5b926ada060c2e34500899dc3c4c0942f3c5c Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Fri, 20 Jan 2012 09:57:39 +0000 Subject: [PATCH] - more code --- src/ats/gnunet-service-ats_addresses_mlp.c | 89 ++++++++++++++++++++++ src/ats/test_ats_mlp.c | 38 +++++++-- 2 files changed, 119 insertions(+), 8 deletions(-) diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index fa4d3a106..0de6ec3b3 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c @@ -147,6 +147,52 @@ mlp_status_to_string (int retcode) return "unknown error"; } +/** + * Translate ATS properties to text + * Just intended for debugging + * + * @param retcode return code + * @return string with result + */ +const char * +mlp_ats_to_string (int ats_index) +{ + switch (ats_index) { + case GNUNET_ATS_ARRAY_TERMINATOR: + return "GNUNET_ATS_ARRAY_TERMINATOR"; + break; + case GNUNET_ATS_UTILIZATION_UP: + return "GNUNET_ATS_UTILIZATION_UP"; + break; + case GNUNET_ATS_UTILIZATION_DOWN: + return "GNUNET_ATS_UTILIZATION_DOWN"; + break; + case GNUNET_ATS_COST_LAN: + return "GNUNET_ATS_COST_LAN"; + break; + case GNUNET_ATS_COST_WAN: + return "GNUNET_ATS_COST_LAN"; + break; + case GNUNET_ATS_COST_WLAN: + return "GNUNET_ATS_COST_WLAN"; + break; + case GNUNET_ATS_NETWORK_TYPE: + return "GNUNET_ATS_NETWORK_TYPE"; + break; + case GNUNET_ATS_QUALITY_NET_DELAY: + return "GNUNET_ATS_QUALITY_NET_DELAY"; + break; + case GNUNET_ATS_QUALITY_NET_DISTANCE: + return "GNUNET_ATS_QUALITY_NET_DISTANCE"; + break; + default: + return "unknown"; + break; + } + GNUNET_break (0); + return "unknown error"; +} + /** * Find a peer in the DLL * @param the peer to find @@ -302,6 +348,34 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value) return GNUNET_OK; } +/** + * Find the required ATS information for an address + * + * @param addr the address + * @param ats_index the desired ATS index + * + * @return the index on success, otherwise GNUNET_SYSERR + */ + +static int +mlp_lookup_ats (struct ATS_Address *addr, int ats_index) +{ + struct GNUNET_ATS_Information * ats = addr->ats; + int c; + int found = GNUNET_NO; + for (c = 0; c < addr->ats_count; c++) + { + if (ats[c].type == ats_index) + { + found = GNUNET_YES; + break; + } + } + if (found == GNUNET_YES) + return c; + else + return GNUNET_SYSERR; +} /** * Adds the problem constraints for all addresses @@ -519,6 +593,21 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON while (addr != NULL) { + /* lookup ATS information */ + int index = mlp_lookup_ats(addr, mlp->q[c]); + + if (index != GNUNET_SYSERR) + { + value = (double) addr->ats[index].value; +#if DEBUG_ATS + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Quality %i with ATS property `%s' has index %i in addresses ats information has value %f\n", c, mlp_ats_to_string(mlp->q[c]), index, (double) addr->ats[index].value); +#endif + } +#if DEBUG_ATS + else + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Quality %i with ATS property `%s' not existing\n", c, mlp_ats_to_string(mlp->q[c]), index); +#endif + mlpi = addr->mlp_information; ia[mlp->ci] = mlp->r_q[c]; ja[mlp->ci] = mlpi->c_b; diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index bf0c6a10a..0ff5bed4b 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_mlp.c @@ -27,6 +27,7 @@ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_statistics_service.h" +#include "gnunet_ats_service.h" #include "gnunet-service-ats_addresses_mlp.h" #define VERBOSE GNUNET_YES @@ -44,6 +45,24 @@ 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) +{ + addr->mlp_information = NULL; + addr->next = NULL; + addr->prev = NULL; + addr->plugin = strdup (plugin); + addr->ats_count = ats_count; + addr->ats = ats; +} + +static void +set_ats (struct GNUNET_ATS_Information *ats, uint32_t type, uint32_t value) +{ + ats->type = type; + ats->value = value; +} + static void check (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) @@ -59,17 +78,20 @@ check (void *cls, char *const *args, const char *cfgfile, addresses = GNUNET_CONTAINER_multihashmap_create (10); + /* Creating address 1 */ GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[0].peer.hashPubKey); - addr[0].mlp_information = NULL; - addr[0].next = NULL; - addr[0].prev = NULL; - addr[0].plugin = strdup ("dummy"); + struct GNUNET_ATS_Information a1_ats[3]; + set_ats (&a1_ats[0], GNUNET_ATS_QUALITY_NET_DISTANCE, 1); + set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32); + set_ats (&a1_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0); + create_address (&addr[0], "dummy", 3, &a1_ats[0]); GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[1].peer.hashPubKey); - addr[1].mlp_information = NULL; - addr[1].next = NULL; - addr[1].prev = NULL; - addr[1].plugin = strdup ("dummy2"); + struct GNUNET_ATS_Information a2_ats[3]; + set_ats (&a2_ats[0], GNUNET_ATS_QUALITY_NET_DELAY, 32); + set_ats (&a2_ats[1], GNUNET_ATS_QUALITY_NET_DISTANCE, 1); + set_ats (&a2_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0); + create_address (&addr[1], "dummy2", 3, &a2_ats[0]); GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); -- 2.25.1