From: Matthias Wachs Date: Thu, 6 Dec 2012 14:00:56 +0000 (+0000) Subject: changes X-Git-Tag: initial-import-from-subversion-38251~10583 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4d695831e94d8146b5f23ad26d852fdd3dc03948;p=oweals%2Fgnunet.git changes --- diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index d92f600bb..fd81226f2 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -182,6 +182,59 @@ assemble_ats_information (const struct ATS_Address *aa, struct GNUNET_ATS_Infor return ats_count; } +static unsigned int +disassemble_ats_information (const struct GNUNET_ATS_Information *src, + uint32_t ats_count, + struct ATS_Address *dest) +{ + int i; + int res = 0; + for (i = 0; i < ats_count; i++) + switch (ntohl (src[i].type)) + { + case GNUNET_ATS_UTILIZATION_UP: + dest->atsp_utilization_out.value__ = src[i].value; + res ++; + break; + case GNUNET_ATS_UTILIZATION_DOWN: + dest->atsp_utilization_in.value__ = src[i].value; + res ++; + break; + case GNUNET_ATS_QUALITY_NET_DELAY: + dest->atsp_latency.rel_value = ntohl (src[i].value); + res ++; + break; + case GNUNET_ATS_QUALITY_NET_DISTANCE: + dest->atsp_distance = ntohl (src[i].value); + res ++; + break; + case GNUNET_ATS_COST_WAN: + dest->atsp_cost_wan = ntohl (src[i].value); + res ++; + break; + case GNUNET_ATS_COST_LAN: + dest->atsp_cost_lan = ntohl (src[i].value); + res ++; + break; + case GNUNET_ATS_COST_WLAN: + dest->atsp_cost_wlan = ntohl (src[i].value); + res ++; + break; + case GNUNET_ATS_NETWORK_TYPE: + dest->atsp_network_type = ntohl (src[i].value); + res ++; + break; + case GNUNET_ATS_ARRAY_TERMINATOR: + break; + default: + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Received unsupported ATS type %u\n", ntohl (src[i].type)); + GNUNET_break (0); + break; + } + return res; +} + /** * Free the given address * @param addr address to destroy @@ -189,7 +242,6 @@ assemble_ats_information (const struct ATS_Address *aa, struct GNUNET_ATS_Infor static void free_address (struct ATS_Address *addr) { - GNUNET_free_non_null (addr->ats); GNUNET_free (addr->plugin); GNUNET_free (addr); } @@ -376,9 +428,6 @@ lookup_address (const struct GNUNET_PeerIdentity *peer, session_id); aa->mlp_information = NULL; - aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information)); - aa->ats_count = atsi_count; - memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_ATS_Information)); /* Get existing address or address with session == 0 */ old = find_address (peer, aa); @@ -446,6 +495,7 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, { struct ATS_Address *aa; struct ATS_Address *old; + unsigned int ats_res; if (GNUNET_NO == handle->running) return; @@ -457,9 +507,12 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, plugin_addr, plugin_addr_len, session_id); aa->mlp_information = NULL; - aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information)); - aa->ats_count = atsi_count; - memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_ATS_Information)); + if (atsi_count != (ats_res = disassemble_ats_information(atsi, atsi_count, aa))) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "While adding address: had %u ATS elements to add, could only add %u\n", + atsi_count, ats_res); + } /* Get existing address or address with session == 0 */ old = find_address (peer, aa); @@ -491,12 +544,13 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updated existing address for peer `%s' %p with new session %u\n", GNUNET_i2s (peer), old, session_id); - GNUNET_free_non_null (old->ats); old->session_id = session_id; - old->ats = NULL; - old->ats_count = 0; - old->ats = aa->ats; - old->ats_count = aa->ats_count; + if (atsi_count != (ats_res = disassemble_ats_information(atsi, atsi_count, old))) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "While updating address: had %u ATS elements to add, could only add %u\n", + atsi_count, ats_res); + } GNUNET_free (aa->plugin); GNUNET_free (aa); handle->s_update (handle->solver, handle->addresses, old); diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index b430824cb..80c89afba 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h @@ -83,12 +83,12 @@ struct ATS_Address /** * ATS information */ - struct GNUNET_ATS_Information *ats; + //struct GNUNET_ATS_Information *ats; /** * Number of ATS information */ - uint32_t ats_count; + //uint32_t ats_count; /* CHECK USAGE */ struct GNUNET_TIME_Relative atsp_latency; diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 825dfeb6d..7f20ab68e 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c @@ -347,7 +347,7 @@ create_constraint_it (void *cls, const struct GNUNET_HashCode * key, void *value * * @return the index on success, otherwise GNUNET_SYSERR */ - +#if 0 static int mlp_lookup_ats (struct ATS_Address *addr, int ats_index) { @@ -367,6 +367,7 @@ mlp_lookup_ats (struct ATS_Address *addr, int ats_index) else return GNUNET_SYSERR; } +#endif /** * Adds the problem constraints for all addresses @@ -1363,28 +1364,32 @@ update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address) GNUNET_assert (NULL != address); GNUNET_assert (NULL != address->mlp_information); - GNUNET_assert (NULL != address->ats); +// GNUNET_assert (NULL != address->ats); struct MLP_information *mlpi = address->mlp_information; - struct GNUNET_ATS_Information *ats = address->ats; + //struct GNUNET_ATS_Information *ats = address->ats; GNUNET_assert (mlpi != NULL); int c; for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) { - int index = mlp_lookup_ats(address, mlp->q[c]); + + /* FIXME int index = mlp_lookup_ats(address, mlp->q[c]); */ + int index = GNUNET_SYSERR; if (index == GNUNET_SYSERR) continue; - + /* FIXME GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s' value `%s': %f\n", GNUNET_i2s (&address->peer), mlp_ats_to_string(mlp->q[c]), (double) ats[index].value); - int i = mlpi->q_avg_i[c]; + int i = mlpi->q_avg_i[c];*/ double * qp = mlpi->q[c]; + /* FIXME qp[i] = (double) ats[index].value; + */ int t; for (t = 0; t < MLP_AVERAGING_QUEUE_LENGTH; t++) diff --git a/src/ats/test_ats_api_scheduling_update_address.c b/src/ats/test_ats_api_scheduling_update_address.c index ace4cc86e..bf7f8f388 100644 --- a/src/ats/test_ats_api_scheduling_update_address.c +++ b/src/ats/test_ats_api_scheduling_update_address.c @@ -234,6 +234,14 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, } /* Update address */ + /* Prepare ATS Information */ + test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); + test_ats_info[0].value = htonl(GNUNET_ATS_NET_LAN); + test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); + test_ats_info[1].value = htonl(3); + test_ats_count = 2; + + GNUNET_ATS_address_update (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); /* Request address */ GNUNET_ATS_suggest_address (sched_ats, &p.id); @@ -255,6 +263,14 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, ret = 1; } + if (GNUNET_OK != compare_ats(atsi, ats_count, test_ats_info, test_ats_count)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 1: Callback with incorrect ats info \n"); + ret = 1; + GNUNET_SCHEDULER_add_now (&end, NULL); + return; + } + GNUNET_SCHEDULER_add_now (&end, NULL); } }