From bfa3b153493bc4d15f0be2d3dfa0b77e45065a61 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 3 Jul 2013 11:55:28 +0000 Subject: [PATCH] function to get normalized properties in solver --- src/ats/gnunet-service-ats_addresses.c | 22 ++++++++++++++++ src/ats/gnunet-service-ats_normalization.c | 29 ++++++++++++++++++++++ src/ats/gnunet-service-ats_normalization.h | 11 ++++++++ 3 files changed, 62 insertions(+) diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 4574383ab..317cfa07c 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -1379,12 +1379,34 @@ normalized_property_changed_cb (void *cls, prop_rel); } + +/** + * Function allowing the solver to obtain normalized preference + * values from solver + * + * @param cls unused + * @param id the peer to return the normalized properties for + * @return array of double values with |GNUNET_ATS_PreferenceCount| elements + */ const double * get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) { return GAS_normalization_get_preferences (id); } +/** + * Function allowing the solver to obtain normalized property + * values for an address from solver + * + * @param cls unused + * @param id the peer to return the normalized properties for + * @return array of double values with |GNUNET_ATS_QualityPropertiesCount| elements + */ +const double * +get_property_cb (void *cls, struct ATS_Address *address) +{ + return GAS_normalization_get_properties (address); +} /** * Change the preference for a peer diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index 86e6f1700..6ced1b49e 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c @@ -509,6 +509,35 @@ GAS_normalization_get_preferences (const struct GNUNET_PeerIdentity *id) return rp->f_rel; } + +/** + * Get the normalized properties values for a specific peer or + * the default values if + * + * @param address the address + * @return pointer to the values, can be indexed with GNUNET_ATS_PreferenceKind, + * default preferences if peer does not exist + */ +const double * +GAS_normalization_get_properties (struct ATS_Address *address) +{ + static double norm_values[GNUNET_ATS_QualityPropertiesCount]; + int i; + + GNUNET_assert (NULL != address); + + for (i = 0; i < GNUNET_ATS_QualityPropertiesCount; i++) + { + if ((address->atsin[i].norm >= 1.0) && + (address->atsin[i].norm <= 2.0)) + norm_values[i] = address->atsin[i].norm; + else + norm_values[i] = DEFAULT_REL_QUALITY; + } + return norm_values; +} + + /** * Quality Normalization */ diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h index 3637766f5..551c47cd3 100644 --- a/src/ats/gnunet-service-ats_normalization.h +++ b/src/ats/gnunet-service-ats_normalization.h @@ -57,6 +57,17 @@ const double * GAS_normalization_get_preferences (const struct GNUNET_PeerIdentity *id); +/** + * Get the normalized properties values for a specific peer or + * the default values if + * + * @param address the address + * @return pointer to the values, can be indexed with GNUNET_ATS_PreferenceKind, + * default preferences if peer does not exist + */ +const double * +GAS_normalization_get_properties (struct ATS_Address *address); + /** * Normalize an updated preference value * -- 2.25.1