X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fats%2Fgnunet-service-ats_normalization.c;h=e70be018e03057f22d2e807f4195224d1dc1d1c3;hb=e871f8368c8a1f0867f68f656875e4c37c26f298;hp=2b0efa912ace9018a8dd6613e105692afdf0f741;hpb=a73229d780f855971649aa5afb66813ff759453b;p=oweals%2Fgnunet.git
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c
index 2b0efa912..e70be018e 100644
--- a/src/ats/gnunet-service-ats_normalization.c
+++ b/src/ats/gnunet-service-ats_normalization.c
@@ -1,22 +1,20 @@
/*
- This file is part of GNUnet.
- (C) 2011 Christian Grothoff (and other contributing authors)
+ This file is part of GNUnet.
+ Copyright (C) 2011-2015 GNUnet e.V.
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
/**
* @file ats/gnunet-service-ats_normalization.c
@@ -25,617 +23,265 @@
* @author Christian Grothoff
*/
#include "platform.h"
+#include
#include "gnunet_ats_service.h"
#include "gnunet-service-ats_addresses.h"
#include "gnunet-service-ats_normalization.h"
+#include "gnunet-service-ats_plugins.h"
+#define LOG(kind,...) GNUNET_log_from (kind, "ats-normalization",__VA_ARGS__)
/**
- * Preference client
- */
-struct PreferenceClient
-{
- /**
- * Next in DLL
- */
- struct PreferenceClient *prev;
-
- /**
- * Next in DLL
- */
-
- struct PreferenceClient *next;
-
- /**
- * Client handle
- */
- void *client;
-
- /**
- * Total preference for this peer
- */
- double f_abs_sum[GNUNET_ATS_PreferenceCount];
-
- /**
- * List of peer preferences for this client
- */
-
- /**
- * Head of peer list
- */
- struct PreferencePeer *p_head;
-
- /**
- * Tail of peer list
- */
- struct PreferencePeer *p_tail;
-};
-
-
-/**
- * Preference peer
- */
-struct PreferencePeer
-{
- /**
- * Next in DLL
- */
- struct PreferencePeer *next;
-
- /**
- * Previous in DLL
- */
- struct PreferencePeer *prev;
-
- /**
- * Client
- */
- struct PreferenceClient *client;
-
- /**
- * Peer id
- */
- struct GNUNET_PeerIdentity id;
-
- /**
- * Absolute preference values
- */
- double f_abs[GNUNET_ATS_PreferenceCount];
-
- /**
- * Relative preference values
- */
- double f_rel[GNUNET_ATS_PreferenceCount];
-
- /**
- * Aging Task
- */
- GNUNET_SCHEDULER_TaskIdentifier aging_task;
-};
-
-/**
- * Relative preferences for a peer
+ * Range information for normalization of quality properties.
*/
-struct PeerRelative
+struct PropertyRange
{
/**
- * Relative preference values
+ * Minimum value we see for this property across all addresses.
*/
- double f_rel[GNUNET_ATS_PreferenceCount];
+ struct GNUNET_ATS_Properties min;
/**
- * Peer id
+ * Maximum value we see for this property across all addresses.
*/
- struct GNUNET_PeerIdentity id;
+ struct GNUNET_ATS_Properties max;
};
/**
- * Callback to call on changing preference values
- */
-static GAS_Normalization_preference_changed_cb pref_changed_cb;
-
-
-/**
- * Closure for callback to call on changing preference values
- */
-static void *pref_changed_cb_cls;
-
-
-/**
- * Hashmap to store peer information for preference normalization
- */
-static struct GNUNET_CONTAINER_MultiHashMap *preference_peers;
-
-
-
-/**
- * Hashmap to store peer information for property normalization
- */
-static struct GNUNET_CONTAINER_MultiHashMap *property_peers;
-
-
-
-/**
- * Clients in DLL: head
- */
-static struct PreferenceClient *pc_head;
-
-
-/**
- * Clients in DLL: tail
- */
-static struct PreferenceClient *pc_tail;
-
-
-/**
- * Default values
- */
-static struct PeerRelative defvalues;
-
-/**
- * Application Preference Normalization
+ * Range information for all quality properties we see.
*/
+static struct PropertyRange property_range;
/**
- * Update a peer
- * @param id peer id
- * @param kind the kind
- * @return the new relative preference
+ * Add the value from @a atsi to the running average of the
+ * given @a ni quality property.
+ *
+ * @param current_val the updated value
+ * @param ni normalization information to update
*/
-static double
-update_peers (struct GNUNET_PeerIdentity *id,
- enum GNUNET_ATS_PreferenceKind kind)
+static void
+update_avg (uint64_t current_val,
+ struct GAS_NormalizationInfo *ni)
{
- struct PreferenceClient *c_cur;
- struct PreferencePeer *p_cur;
- struct PeerRelative *rp;
- double f_rel_total;
- double backup;
- unsigned int count;
-
- f_rel_total = 0.0;
- count = 0;
-
- /* For all clients */
- for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
- {
- /* Find peer with id */
- for (p_cur = c_cur->p_head; NULL != p_cur; p_cur = p_cur->next)
- {
- if (0 == memcmp (id, &p_cur->id, sizeof (struct GNUNET_PeerIdentity)))
- break;
- }
- if (NULL != p_cur)
- {
- /* Found peer with id */
- f_rel_total += p_cur->f_rel[kind];
- count ++;
- }
- }
-
- /* Find a client */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%u clients have a total relative preference for peer `%s''s `%s' of %.3f\n",
- count,
- GNUNET_i2s (id),
- GNUNET_ATS_print_preference_type (kind),
- f_rel_total);
- if (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers, &id->hashPubKey)))
- {
- backup = rp->f_rel[kind];
- if (0 < count)
- {
- rp->f_rel[kind] = f_rel_total / count;
- }
- else
- {
- rp->f_rel[kind] = DEFAULT_REL_PREFERENCE;
- }
- }
- else
- {
- return DEFAULT_REL_PREFERENCE;
- }
-
- if ((backup != rp->f_rel[kind]) && (NULL != pref_changed_cb))
- {
- pref_changed_cb (pref_changed_cb_cls, &rp->id, kind, rp->f_rel[kind]);
- }
-
- return rp->f_rel[kind];
+ double sum;
+ uint32_t count;
+ unsigned int c1;
+
+ ni->atsi_abs[ni->avg_queue_index++] = current_val;
+ if (GAS_normalization_queue_length == ni->avg_queue_index)
+ ni->avg_queue_index = 0;
+ count = 0;
+ sum = 0.0;
+ for (c1 = 0; c1 < GAS_normalization_queue_length; c1++)
+ {
+ if (UINT64_MAX != ni->atsi_abs[c1])
+ {
+ count++;
+ sum += (double) ni->atsi_abs[c1];
+ }
+ }
+ if (0 == count)
+ ni->avg = current_val; /* must be UINT64_MAX */
+ else
+ ni->avg = sum / count;
}
/**
- * Recalculate preference for a specific ATS property
+ * Function called for all addresses and peers to find the minimum and
+ * maximum (averaged) values for a given quality property. Given
+ * those, we can then calculate the normalized score.
*
- * @param c the preference client
- * @param p the peer
- * @param kind the preference kind
- * @return the result
+ * @param cls the `struct PropertyRange`
+ * @param h which peer are we looking at (ignored)
+ * @param k the address for that peer
+ * @return #GNUNET_OK (continue to iterate)
*/
-static double
-recalculate_rel_preferences (struct PreferenceClient *c,
- struct PreferencePeer *p,
- enum GNUNET_ATS_PreferenceKind kind)
+static int
+find_min_max_it (void *cls,
+ const struct GNUNET_PeerIdentity *h,
+ void *k)
{
- struct PreferencePeer *p_cur;
- struct PeerRelative *rp;
- double backup;
- double res;
- double ret;
-
- /* For this client: sum preferences to total preference */
- c->f_abs_sum[kind] = 0;
- for (p_cur = c->p_head; NULL != p_cur; p_cur = p_cur->next)
- c->f_abs_sum[kind] += p_cur->f_abs[kind];
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p has total preference for %s of %.3f\n",
- c->client,
- GNUNET_ATS_print_preference_type (kind),
- c->f_abs_sum[kind]);
-
- ret = DEFAULT_REL_PREFERENCE;
- /* For all peers: calculate relative preference */
- for (p_cur = c->p_head; NULL != p_cur; p_cur = p_cur->next)
- {
- /* Calculate relative preference for specific kind */
- backup = p_cur->f_rel[kind];
- if (DEFAULT_ABS_PREFERENCE == c->f_abs_sum[kind])
- /* No peer has a preference for this property,
- * so set default preference */
- p_cur->f_rel[kind] = DEFAULT_REL_PREFERENCE;
- else
- p_cur->f_rel[kind] = (c->f_abs_sum[kind] + p_cur->f_abs[kind]) /
- c->f_abs_sum[kind];
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p: peer `%s' has relative preference for %s of %.3f\n",
- c->client,
- GNUNET_i2s (&p_cur->id),
- GNUNET_ATS_print_preference_type (kind),
- p_cur->f_rel[kind]);
-
- res = 0.0;
- if (p_cur->f_rel[kind] != backup)
- {
- /* Value changed, recalculate */
- res = update_peers (&p_cur->id,kind);
- if (0 == memcmp (&p->id, &p_cur->id, sizeof (struct GNUNET_PeerIdentity)))
- ret = res;
- }
- else
- {
- /* Value did not chang, return old value*/
- GNUNET_assert (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers,
- &p->id.hashPubKey)));
- ret = rp->f_rel[kind];
- }
- }
- return ret;
+ struct PropertyRange *pr = cls;
+ const struct ATS_Address *a = k;
+
+ pr->max.utilization_out = GNUNET_MAX (pr->max.utilization_out,
+ a->properties.utilization_out);
+ pr->max.utilization_in = GNUNET_MAX (pr->max.utilization_in,
+ a->properties.utilization_in);
+ pr->max.distance = GNUNET_MAX (pr->max.distance,
+ a->properties.distance);
+ pr->max.delay = GNUNET_TIME_relative_max (pr->max.delay,
+ a->properties.delay);
+ pr->min.utilization_out = GNUNET_MIN (pr->min.utilization_out,
+ a->properties.utilization_out);
+ pr->min.utilization_in = GNUNET_MIN (pr->min.utilization_in,
+ a->properties.utilization_in);
+ pr->min.distance = GNUNET_MIN (pr->min.distance,
+ a->properties.distance);
+ pr->min.delay = GNUNET_TIME_relative_min (pr->min.delay,
+ a->properties.delay);
+ return GNUNET_OK;
}
/**
- * Update the absolute preference value for a peer
- * @param c the client
- * @param p the peer
- * @param kind the preference kind
- * @param score_abs the absolute value
- * @return the new relative preference value
+ * Compute the normalized value from the given @a ni range
+ * data and the average value.
+ *
+ * @param min minimum value
+ * @param max maximum value
+ * @param ni normalization information to update
*/
-static double
-update_preference (struct PreferenceClient *c,
- struct PreferencePeer *p,
- enum GNUNET_ATS_PreferenceKind kind,
- float score_abs)
+static void
+update_norm (uint64_t min,
+ uint64_t max,
+ struct GAS_NormalizationInfo *ni)
{
- double score = score_abs;
-
- /* Update preference value according to type */
- switch (kind) {
- case GNUNET_ATS_PREFERENCE_BANDWIDTH:
- case GNUNET_ATS_PREFERENCE_LATENCY:
- p->f_abs[kind] = (p->f_abs[kind] + score) / 2;
- break;
- case GNUNET_ATS_PREFERENCE_END:
- break;
- default:
- break;
- }
- return recalculate_rel_preferences (c, p, kind);
+ /* max - 2 * min + avg_value / (max - min) */
+ if (min < max)
+ ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double) (max - min);
+ else
+ ni->norm = DEFAULT_REL_QUALITY;
}
/**
- * Reduce absolute preferences since they got old
+ * Normalize the property value for a given address based
+ * on the range we know that property values have globally.
*
- * @param cls the PreferencePeer
- * @param tc context
+ * @param cls NULL
+ * @param key which peer are we looking at (ignored)
+ * @param value the address for that peer, from where we get
+ * the original value and where we write the
+ * normalized value
+ * @return #GNUNET_OK (continue to iterate)
*/
-static void
-preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+static int
+normalize_address (void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
{
- int i;
- double backup;
- struct PreferencePeer *p = cls;
- GNUNET_assert (NULL != p);
-
- p->aging_task = GNUNET_SCHEDULER_NO_TASK;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Aging preferences for peer `%s'\n",
- GNUNET_i2s (&p->id));
-
- /* Aging absolute values: */
- for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
- {
- backup = p->f_abs[i];
- if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE)
- p->f_abs[i] *= PREF_AGING_FACTOR;
- if (backup != p->f_abs[i])
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Aged preference for peer `%s' from %.3f to %.3f\n",
- GNUNET_i2s (&p->id), backup, p->f_abs[i]);
- recalculate_rel_preferences (p->client, p, i);
- }
- }
- p->aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
- &preference_aging, p);
+ struct ATS_Address *address = value;
+
+ update_norm (property_range.min.delay.rel_value_us,
+ property_range.max.delay.rel_value_us,
+ &address->norm_delay);
+ update_norm (property_range.min.distance,
+ property_range.max.distance,
+ &address->norm_distance);
+ update_norm (property_range.min.utilization_in,
+ property_range.max.utilization_in,
+ &address->norm_utilization_in);
+ update_norm (property_range.min.utilization_out,
+ property_range.max.utilization_out,
+ &address->norm_utilization_out);
+ return GNUNET_OK;
}
/**
- * Normalize an updated preference value
+ * Notify about change in normalized property.
*
- * @param src the client with this preference
- * @param peer the peer to change the preference for
- * @param kind the kind to change the preference
- * @param score_abs the normalized score
+ * @param cls NULL
+ * @param key which peer are we looking at (ignored)
+ * @param value the address for that peer
+ * @return #GNUNET_OK (continue to iterate)
*/
-float
-GAS_normalization_normalize_preference (void *src,
- const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- float score_abs)
+static int
+notify_change (void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
{
- float score_rel;
- struct PreferenceClient *c_cur;
- struct PreferencePeer *p_cur;
- struct PeerRelative *r_cur;
- int i;
-
-
- GNUNET_assert (NULL != src);
- GNUNET_assert (NULL != peer);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p changes preference for peer `%s' for `%s' to %.2f\n",
- src,
- GNUNET_i2s (peer),
- GNUNET_ATS_print_preference_type (kind),
- score_abs);
-
- if (kind >= GNUNET_ATS_PreferenceCount)
- {
- GNUNET_break (0);
- return 0.0;
- }
-
- /* Find preference client */
- for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
- {
- if (src == c_cur->client)
- break;
- }
- /* Not found: create new preference client */
- if (NULL == c_cur)
- {
- c_cur = GNUNET_malloc (sizeof (struct PreferenceClient));
- c_cur->client = src;
- GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, c_cur);
- }
-
- /* Find entry for peer */
- for (p_cur = c_cur->p_head; NULL != p_cur; p_cur = p_cur->next)
- if (0 == memcmp (&p_cur->id, peer, sizeof (p_cur->id)))
- break;
-
- /* Not found: create new peer entry */
- if (NULL == p_cur)
- {
- p_cur = GNUNET_malloc (sizeof (struct PreferencePeer));
- p_cur->client = c_cur;
- p_cur->id = (*peer);
- for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
- {
- /* Default value per peer absolut preference for a quality:
- * No value set, so absolute preference 0 */
- p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE;
- /* Default value per peer relative preference for a quality: 1.0 */
- p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
- }
- p_cur->aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
- &preference_aging, p_cur);
- GNUNET_CONTAINER_DLL_insert (c_cur->p_head, c_cur->p_tail, p_cur);
- }
-
- if (NULL == (r_cur = GNUNET_CONTAINER_multihashmap_get (preference_peers,
- &peer->hashPubKey)))
- {
- r_cur = GNUNET_malloc (sizeof (struct PeerRelative));
- r_cur->id = (*peer);
- for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
- r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
- GNUNET_CONTAINER_multihashmap_put (preference_peers, &r_cur->id.hashPubKey,
- r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
- }
+ struct ATS_Address *address = value;
- score_rel = update_preference (c_cur, p_cur, kind, score_abs);
- return score_rel;
+ GAS_plugin_notify_property_changed (address);
+ return GNUNET_OK;
}
/**
- * Get the normalized preference values for a specific peer or
- * the default values if
+ * Initialize property range to the values corresponding
+ * to an empty set.
*
- * @param id the peer
- * @return pointer to the values, can be indexed with GNUNET_ATS_PreferenceKind,
- * default preferences if peer does not exist
- */
-const double *
-GAS_normalization_get_preferences (const struct GNUNET_PeerIdentity *id)
-{
- GNUNET_assert (NULL != preference_peers);
- GNUNET_assert (NULL != id);
-
- struct PeerRelative *rp;
- if (NULL == (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers, &id->hashPubKey)))
- {
- return defvalues.f_rel;
- }
- return rp->f_rel;
-}
-
-/**
- * Quality Normalization
+ * @param pr range to initialize
*/
-
-struct Property
-{
- int have_min; /* Do we have min and max */
- int have_max;
- uint32_t min;
- uint32_t max;
-};
-
-struct Property properties[GNUNET_ATS_QualityPropertiesCount];
-
-uint32_t property_average (struct ATS_Address *address,
- const struct GNUNET_ATS_Information *atsi)
-{
- /* Average the values of this property */
- return ntohl(atsi->value);
-}
-
-void property_normalize (struct ATS_Address *address,
- uint32_t type)
-{
- /* Normalize the values of this property */
- //GNUNET_break (0);
-}
-
-
-
-void
-GAS_normalization_normalize_property (struct ATS_Address *address,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count)
+static void
+init_range (struct PropertyRange *pr)
{
- struct Property *cur_prop;
- int c1;
- int c2;
- uint32_t current_type;
- uint32_t current_val;
-
- int existing_properties[] = GNUNET_ATS_QualityProperties;
-
- for (c1 = 0; c1 < atsi_count; c1++)
- {
- current_type = ntohl (atsi[c1].type);
- current_val = ntohl (atsi[c1].value);
- for (c2 = 0; c2 < GNUNET_ATS_QualityPropertiesCount; c2++)
- {
- if (current_type == existing_properties[c2])
- break;
- }
- if (GNUNET_ATS_QualityPropertiesCount == c2)
- {
- /* Invalid property */
- continue;
- }
-
- /* Averaging */
- current_val = property_average (address, &atsi[c1]);
-
- /* Normalizing */
- /* Check min, max */
- cur_prop = &properties[c2];
- if (cur_prop->max < current_val)
- {
- cur_prop->max = current_val;
- if (GNUNET_NO == cur_prop->have_max)
- cur_prop->have_max = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New maximum of %u for property %u\n", cur_prop->max, current_type);
- }
- if (cur_prop->min > current_val)
- {
- cur_prop->min = current_val;
- if (GNUNET_NO == cur_prop->have_min)
- cur_prop->have_min = GNUNET_YES;
- 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));
- }
-
+ memset (pr, 0, sizeof (struct PropertyRange));
+ pr->min.utilization_out = UINT32_MAX;
+ pr->min.utilization_in = UINT32_MAX;
+ pr->min.distance = UINT32_MAX;
+ pr->min.delay = GNUNET_TIME_UNIT_FOREVER_REL;
}
-
-
/**
- * Start the normalization component
+ * Update and normalize atsi performance information
*
- * @param pref_ch_cb callback to call on relative preference changing
- * @param pref_ch_cb_cls cls for the callback
+ * @param address the address to update
*/
void
-GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb,
- void *pref_ch_cb_cls)
+GAS_normalization_update_property (struct ATS_Address *address)
{
- int c1;
- int i;
- preference_peers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO);
- property_peers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO);
-
- for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
- {
- properties[c1].min = 0;
- properties[c1].max = 0;
- properties[c1].have_max = GNUNET_NO;
- properties[c1].have_min = GNUNET_NO;
- }
-
- pref_changed_cb = pref_ch_cb;
- pref_changed_cb_cls = pref_ch_cb_cls;
- for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
- defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE;
- return;
+ const struct GNUNET_ATS_Properties *prop = &address->properties;
+ struct PropertyRange range;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Updating properties for peer `%s'\n",
+ GNUNET_i2s (&address->peer));
+ GAS_plugin_solver_lock ();
+ update_avg (prop->delay.rel_value_us,
+ &address->norm_delay);
+ update_avg (prop->distance,
+ &address->norm_distance);
+ update_avg (prop->utilization_in,
+ &address->norm_utilization_in);
+ update_avg (prop->utilization_in,
+ &address->norm_utilization_out);
+
+ init_range (&range);
+ GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
+ &find_min_max_it,
+ &range);
+ if (0 != memcmp (&range,
+ &property_range,
+ sizeof (struct PropertyRange)))
+ {
+ /* limits changed, (re)normalize all addresses */
+ property_range = range;
+ GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
+ &normalize_address,
+ NULL);
+ GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
+ ¬ify_change,
+ NULL);
+ }
+ else
+ {
+ /* renormalize just this one address */
+ normalize_address (NULL,
+ &address->peer,
+ address);
+ notify_change (NULL,
+ &address->peer,
+ address);
+ }
+ GAS_plugin_solver_unlock ();
}
/**
- * Free a peer
- *
- * @param cls unused
- * @param key the key
- * @param value RelativePeer
- * @return GNUNET_OK to continue
+ * Start the normalization component
*/
-static int
-free_peer (void *cls,
- const struct GNUNET_HashCode * key,
- void *value)
+void
+GAS_normalization_start ()
{
- struct PeerRelative *rp = value;
- GNUNET_CONTAINER_multihashmap_remove (preference_peers, key, value);
- GNUNET_free (rp);
- return GNUNET_OK;
+ init_range (&property_range);
}
@@ -645,34 +291,8 @@ free_peer (void *cls,
void
GAS_normalization_stop ()
{
- struct PreferenceClient *pc;
- struct PreferenceClient *next_pc;
- struct PreferencePeer *p;
- struct PreferencePeer *next_p;
-
- next_pc = pc_head;
- while (NULL != (pc = next_pc))
- {
- next_pc = pc->next;
- GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
- next_p = pc->p_head;
- while (NULL != (p = next_p))
- {
- next_p = p->next;
- if (GNUNET_SCHEDULER_NO_TASK != p->aging_task)
- {
- GNUNET_SCHEDULER_cancel(p->aging_task);
- p->aging_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_CONTAINER_DLL_remove (pc->p_head, pc->p_tail, p);
- GNUNET_free (p);
- }
- GNUNET_free (pc);
- }
- GNUNET_CONTAINER_multihashmap_iterate (preference_peers, &free_peer, NULL);
- GNUNET_CONTAINER_multihashmap_destroy (preference_peers);
- GNUNET_CONTAINER_multihashmap_destroy (property_peers);
- return;
+ /* nothing to do */
}
+
/* end of gnunet-service-ats_normalization.c */