aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ats/gnunet-service-ats.h2
-rw-r--r--src/ats/gnunet-service-ats_addresses.c10
-rw-r--r--src/ats/gnunet-service-ats_addresses.h14
-rw-r--r--src/ats/gnunet-service-ats_normalization.c72
-rw-r--r--src/ats/gnunet-service-ats_normalization.h1
-rw-r--r--src/ats/test_ats_api_common.c4
6 files changed, 95 insertions, 8 deletions
diff --git a/src/ats/gnunet-service-ats.h b/src/ats/gnunet-service-ats.h
index b60332d209..4335c52260 100644
--- a/src/ats/gnunet-service-ats.h
+++ b/src/ats/gnunet-service-ats.h
@@ -29,6 +29,8 @@
#include "gnunet_statistics_service.h"
+#define GAS_normalization_queue_length 3
+
/**
* Handle for statistics.
*/
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 8083ba9142..d7c4100ea0 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -512,6 +512,8 @@ create_address (const struct GNUNET_PeerIdentity *peer,
uint32_t session_id)
{
struct ATS_Address *aa = NULL;
+ int c1;
+ int c2;
aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len);
aa->peer = *peer;
@@ -527,6 +529,14 @@ create_address (const struct GNUNET_PeerIdentity *peer,
aa->atsi_count = 0;
aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
+
+ for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1 ++)
+ {
+ aa->atsin[c1].index = 0;
+ for (c2 = 0; c2 < GAS_normalization_queue_length; c2++)
+ aa->atsin[c1].atsi_abs[c2] = GNUNET_ATS_VALUE_UNDEFINED;
+ }
+
return aa;
}
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h
index 0da559d20a..cfc54b2eaa 100644
--- a/src/ats/gnunet-service-ats_addresses.h
+++ b/src/ats/gnunet-service-ats_addresses.h
@@ -29,6 +29,7 @@
#include "gnunet_util_lib.h"
#include "gnunet_ats_service.h"
+#include "gnunet-service-ats.h"
#include "gnunet_statistics_service.h"
#include "ats.h"
@@ -232,6 +233,13 @@
struct GAS_Addresses_Handle;
+
+struct GAS_NormalizationInfo
+{
+ unsigned int index;
+ uint32_t atsi_abs[GAS_normalization_queue_length];
+};
+
/**
* Address with additional information
*/
@@ -342,6 +350,12 @@ struct ATS_Address
* Is this the address for this peer in use?
*/
int used;
+
+ /**
+ * Normalized ATS performance information for this address
+ * Each entry can be accessed using the GNUNET_ATS_QualityProperties index
+ */
+ struct GAS_NormalizationInfo atsin[GNUNET_ATS_QualityPropertiesCount];
};
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c
index 2b0efa912a..c290b697c0 100644
--- a/src/ats/gnunet-service-ats_normalization.c
+++ b/src/ats/gnunet-service-ats_normalization.c
@@ -514,11 +514,66 @@ struct Property
struct Property properties[GNUNET_ATS_QualityPropertiesCount];
+/**
+ * Normalize a specific ATS type with the values in queue
+ * @param address the address
+ * @param atsi the ats information
+ * @return the new average or GNUNET_ATS_VALUE_UNDEFINED
+ */
+
uint32_t property_average (struct ATS_Address *address,
const struct GNUNET_ATS_Information *atsi)
{
+ struct GAS_NormalizationInfo *ni;
+ uint32_t current_type;
+ uint32_t current_val;
+
+ uint32_t sum;
+ uint32_t count;
+ unsigned int c1;
+ unsigned int index;
+ unsigned int props[] = GNUNET_ATS_QualityProperties;
+
/* Average the values of this property */
- return ntohl(atsi->value);
+ current_type = ntohl (atsi->type);
+ current_val = ntohl (atsi->value);
+
+ for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
+ {
+ if (current_type == props[c1])
+ break;
+ }
+ if (c1 == GNUNET_ATS_QualityPropertiesCount)
+ {
+ GNUNET_break (0);
+ return GNUNET_ATS_VALUE_UNDEFINED;
+ }
+ index = c1;
+
+ ni = &address->atsin[index];
+ ni->atsi_abs[ni->index] = current_val;
+ ni->index ++;
+ if (GAS_normalization_queue_length == ni->index)
+ ni->index = 0;
+
+ count = 0;
+ for (c1 = 0; c1 < GAS_normalization_queue_length; c1++)
+ {
+ if (GNUNET_ATS_VALUE_UNDEFINED != ni->atsi_abs[c1])
+ {
+ count++;
+ if (GNUNET_ATS_VALUE_UNDEFINED > (sum + ni->atsi_abs[c1]))
+ sum += ni->atsi_abs[c1];
+ else
+ {
+ sum = GNUNET_ATS_VALUE_UNDEFINED - 1;
+ GNUNET_break (0);
+ }
+ }
+ }
+ GNUNET_assert (0 != count);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New average from %u elements: %u\n", count, sum / count);
+ return 0;
}
void property_normalize (struct ATS_Address *address,
@@ -540,8 +595,10 @@ GAS_normalization_normalize_property (struct ATS_Address *address,
int c2;
uint32_t current_type;
uint32_t current_val;
+ unsigned int existing_properties[] = GNUNET_ATS_QualityProperties;
- int existing_properties[] = GNUNET_ATS_QualityProperties;
+ GNUNET_assert (NULL != address);
+ GNUNET_assert (NULL != atsi);
for (c1 = 0; c1 < atsi_count; c1++)
{
@@ -549,17 +606,23 @@ GAS_normalization_normalize_property (struct ATS_Address *address,
current_val = ntohl (atsi[c1].value);
for (c2 = 0; c2 < GNUNET_ATS_QualityPropertiesCount; c2++)
{
+ /* Check if type is valid */
if (current_type == existing_properties[c2])
break;
}
if (GNUNET_ATS_QualityPropertiesCount == c2)
{
- /* Invalid property */
+ /* Invalid property, continue with next element */
continue;
}
/* Averaging */
current_val = property_average (address, &atsi[c1]);
+ if (GNUNET_ATS_VALUE_UNDEFINED == current_val)
+ {
+ GNUNET_break (0);
+ continue;
+ }
/* Normalizing */
/* Check min, max */
@@ -579,8 +642,7 @@ GAS_normalization_normalize_property (struct ATS_Address *address,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New minimum of %u for property %u\n", cur_prop->min, current_type);
}
-
- property_normalize (address, ntohl(atsi[c1].type));
+ //property_normalize (address, ntohl(atsi[c1].type));
}
}
diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h
index c90d4d8c6e..967702baec 100644
--- a/src/ats/gnunet-service-ats_normalization.h
+++ b/src/ats/gnunet-service-ats_normalization.h
@@ -33,7 +33,6 @@
#define DEFAULT_REL_PREFERENCE 1.0
#define DEFAULT_ABS_PREFERENCE 0.0
-
typedef void
(*GAS_Normalization_preference_changed_cb) (void *cls,
const struct GNUNET_PeerIdentity *peer,
diff --git a/src/ats/test_ats_api_common.c b/src/ats/test_ats_api_common.c
index 79005d8d3e..44d6274243 100644
--- a/src/ats/test_ats_api_common.c
+++ b/src/ats/test_ats_api_common.c
@@ -69,13 +69,13 @@ compare_addresses (const struct GNUNET_HELLO_Address *address1, void *session1,
}
if (address1->address_length != address2->address_length)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address length'\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address length\n");
return GNUNET_SYSERR;
}
else if (0 != memcmp (address1->address, address2->address, address2->address_length))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address'\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address\n");
return GNUNET_SYSERR;
}
if (session1 != session2)