[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r35109 - gnunet/src/ats
From: |
gnunet |
Subject: |
[GNUnet-SVN] r35109 - gnunet/src/ats |
Date: |
Thu, 5 Feb 2015 20:48:15 +0100 |
Author: grothoff
Date: 2015-02-05 20:48:15 +0100 (Thu, 05 Feb 2015)
New Revision: 35109
Modified:
gnunet/src/ats/gnunet-service-ats_addresses.c
gnunet/src/ats/gnunet-service-ats_addresses.h
gnunet/src/ats/gnunet-service-ats_feedback.h
gnunet/src/ats/gnunet-service-ats_normalization.c
gnunet/src/ats/gnunet-service-ats_normalization.h
gnunet/src/ats/gnunet-service-ats_plugins.c
gnunet/src/ats/gnunet-service-ats_preferences.h
Log:
cleaning up gnunet-service-ats_normalization.c
Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c 2015-02-05 18:35:39 UTC
(rev 35108)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c 2015-02-05 19:48:15 UTC
(rev 35109)
@@ -501,10 +501,10 @@
* @return the value in HBO or #GNUNET_ATS_VALUE_UNDEFINED in HBO if value
does not exist
*/
static int
-get_performance_info (struct ATS_Address *address, uint32_t type)
+get_performance_info (struct ATS_Address *address,
+ uint32_t type)
{
- int c1;
- GNUNET_assert(NULL != address);
+ uint32_t c1;
if ((NULL == address->atsi) || (0 == address->atsi_count))
return GNUNET_ATS_VALUE_UNDEFINED;
@@ -550,11 +550,6 @@
GNUNET_break (0);
return;
}
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' for peer `%s'\n",
- "ADDRESS ADD",
- GNUNET_i2s (peer));
new_address = create_address (peer,
plugin_name,
plugin_addr,
@@ -581,13 +576,9 @@
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
update_addresses_stat ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Adding new address %p for peer `%s', length %u, session id %u,
%s\n",
- new_address,
+ "Adding new address for peer `%s' slot %u\n",
GNUNET_i2s (peer),
- plugin_addr_len,
- session_id,
- GNUNET_ATS_print_network_type (addr_net));
-
+ session_id);
/* Tell solver about new address */
GAS_plugin_new_address (new_address,
addr_net,
@@ -638,10 +629,9 @@
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' for peer `%s' address \n",
- "ADDRESS UPDATE",
+ "Received ADDRESS_UPDATE for peer `%s' slot %u\n",
GNUNET_i2s (peer),
- aa);
+ (unsigned int) session_id);
/* Update address */
aa->t_last_activity = GNUNET_TIME_absolute_get();
@@ -673,7 +663,7 @@
/**
- * Remove an address or just a session for a peer.
+ * Remove an address for a peer.
*
* @param peer peer
* @param session_id session id, can never be 0
@@ -693,9 +683,8 @@
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received ADDRESS_DESTROYED for peer `%s' address %p session
%u\n",
+ "Received ADDRESS_DESTROYED for peer `%s' session %u\n",
GNUNET_i2s (peer),
- ea,
session_id);
free_address (ea);
}
Modified: gnunet/src/ats/gnunet-service-ats_addresses.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.h 2015-02-05 18:35:39 UTC
(rev 35108)
+++ gnunet/src/ats/gnunet-service-ats_addresses.h 2015-02-05 19:48:15 UTC
(rev 35109)
@@ -379,7 +379,7 @@
* @param peer peer
* @param plugin_name transport plugin name
* @param plugin_addr plugin address
- * @param plugin_addr_len length of the plugin address
+ * @param plugin_addr_len length of the @a plugin_addr
* @param local_address_info the local address for the address
* @param session_id session id, can never be 0.
* @param atsi performance information for this address
@@ -412,7 +412,7 @@
/**
- * Remove an address or just a session for a peer.
+ * Remove an address for a peer.
*
* @param peer peer
* @param session_id session id, can never be 0
@@ -432,7 +432,7 @@
/**
* Iterator for #GAS_addresses_get_peer_info()
*
- * @param p_it_cls closure closure
+ * @param cls closure
* @param id the peer id
* @param plugin_name plugin name
* @param plugin_addr address
@@ -444,7 +444,7 @@
* @param bandwidth_in current inbound bandwidth assigned to address
*/
typedef void
-(*GNUNET_ATS_PeerInfo_Iterator) (void *p_it_cls,
+(*GNUNET_ATS_PeerInfo_Iterator) (void *cls,
const struct GNUNET_PeerIdentity *id,
const char *plugin_name,
const void *plugin_addr,
Modified: gnunet/src/ats/gnunet-service-ats_feedback.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_feedback.h 2015-02-05 18:35:39 UTC
(rev 35108)
+++ gnunet/src/ats/gnunet-service-ats_feedback.h 2015-02-05 19:48:15 UTC
(rev 35109)
@@ -26,6 +26,8 @@
#ifndef GNUNET_SERVICE_ATS_FEEDBACK_H
#define GNUNET_SERVICE_ATS_FEEDBACK_H
+#include "gnunet_util_lib.h"
+
/**
* Handle 'preference feedback' messages from clients.
*
Modified: gnunet/src/ats/gnunet-service-ats_normalization.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_normalization.c 2015-02-05 18:35:39 UTC
(rev 35108)
+++ gnunet/src/ats/gnunet-service-ats_normalization.c 2015-02-05 19:48:15 UTC
(rev 35109)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2011 Christian Grothoff (and other contributing authors)
+ (C) 2011-2015 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -24,7 +24,7 @@
* @author Matthias Wachs
* @author Christian Grothoff
*
- * FIXME: rename to 'properties'!
+ * FIXME: rename to 'properties'!?
*/
#include "platform.h"
#include "gnunet_ats_service.h"
@@ -35,32 +35,42 @@
#define LOG(kind,...) GNUNET_log_from (kind, "ats-normalization",__VA_ARGS__)
-
/**
* Quality Normalization
*/
struct Property
{
+ /**
+ * Index into the properties array.
+ */
uint32_t prop_type;
+
+ /**
+ * Corresponding enum value. FIXME: type?
+ */
uint32_t atsi_type;
+
+ /**
+ * Minimum value we see for this property across all addresses.
+ */
uint32_t min;
+
+ /**
+ * Maximum value we see for this property across all addresses.
+ */
uint32_t max;
};
-static struct Property properties[GNUNET_ATS_QualityPropertiesCount];
/**
- * Hashmap to store peer information for property normalization
- * FIXME: this map is not used!
+ * Range information for all properties we see.
*/
-static struct GNUNET_CONTAINER_MultiPeerMap *property_peers;
+static struct Property properties[GNUNET_ATS_QualityPropertiesCount];
-
-
/**
* Get the normalized properties values for a specific peer or
- * the default values if
+ * the default values if no normalized values are available.
*
* @param cls ignored
* @param address the address
@@ -72,10 +82,8 @@
const struct ATS_Address *address)
{
static double norm_values[GNUNET_ATS_QualityPropertiesCount];
- int i;
+ unsigned 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))
@@ -88,7 +96,8 @@
/**
- * Normalize a specific ATS type with the values in queue
+ * 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
@@ -149,40 +158,78 @@
res = sum / count;
LOG(GNUNET_ERROR_TYPE_DEBUG,
"New average of `%s' created by adding %u from %u elements: %u\n",
- GNUNET_ATS_print_property_type (current_type), current_val, count, res,
+ GNUNET_ATS_print_property_type (current_type),
+ current_val,
+ count,
+ res,
sum);
ni->avg = res;
return res;
}
+/**
+ * Closure for #find_min_max_it().
+ */
struct FindMinMaxCtx
{
+ /**
+ * Property we are looking for.
+ */
struct Property *p;
+
+ /**
+ * Set to mimimum value observed.
+ */
uint32_t min;
+
+ /**
+ * Set to maximum value observed.
+ */
uint32_t max;
};
+/**
+ * Function called on X to find the minimum and maximum
+ * values for a given property.
+ *
+ * @param cls the `struct FindMinMaxCtx`
+ * @param h which peer are we looking at (ignored)
+ * @param k the address for that peer
+ * @return #GNUNET_OK (continue to iterate)
+ */
static int
-find_min_max_it (void *cls, const struct GNUNET_PeerIdentity *h, void *k)
+find_min_max_it (void *cls,
+ const struct GNUNET_PeerIdentity *h,
+ void *k)
{
struct FindMinMaxCtx *find_res = cls;
- struct ATS_Address *a = k;
+ const struct ATS_Address *a = k;
- if (a->atsin[find_res->p->prop_type].avg > find_res->max)
- find_res->max = a->atsin[find_res->p->prop_type].avg;
-
- if (a->atsin[find_res->p->prop_type].avg < find_res->min)
- find_res->min = a->atsin[find_res->p->prop_type].avg;
-
+ find_res->max = GNUNET_MAX (find_res->max,
+ a->atsin[find_res->p->prop_type].avg);
+ find_res->min = GNUNET_MIN (find_res->min,
+ a->atsin[find_res->p->prop_type].avg);
return GNUNET_OK;
}
+/**
+ * Normalize the property value for a given address based
+ * on the range we know that property value has globally.
+ *
+ * @param cls the `struct Property` with details on the
+ * property and its global range
+ * @param h which peer are we looking at (ignored)
+ * @param k 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 int
normalize_address (void *cls,
- const struct GNUNET_PeerIdentity *h,
+ const struct GNUNET_PeerIdentity *h,
void *k)
{
struct Property *p = cls;
@@ -203,32 +250,30 @@
if (backup == address->atsin[p->prop_type].norm)
return GNUNET_OK;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Normalize `%s' address %p's '%s' with value %u to range [%u..%u] =
%.3f\n",
- GNUNET_i2s (&address->peer), address,
- GNUNET_ATS_print_property_type (p->atsi_type),
- address->atsin[p->prop_type].avg, p->min, p->max,
- address->atsin[p->prop_type].norm);
-
- GAS_normalized_property_changed (address,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Normalize `%s' address %p's '%s' with value %u to range [%u..%u] =
%.3f\n",
+ GNUNET_i2s (&address->peer), address,
+ GNUNET_ATS_print_property_type (p->atsi_type),
+ address->atsin[p->prop_type].avg, p->min, p->max,
+ address->atsin[p->prop_type].norm);
+ GAS_normalized_property_changed (address,
p->atsi_type,
address->atsin[p->prop_type].norm);
-
return GNUNET_OK;
}
/**
- * Normalize avg_value to a range of values between [1.0, 2.0]
- * based on min max values currently known.
+ * Normalize @a avg_value to a range of values between [1.0, 2.0]
+ * based on min/max values currently known.
*
* @param p the property
* @param address the address
* @param avg_value the value to normalize
*/
static void
-property_normalize (struct Property *p,
- struct ATS_Address *address,
+property_normalize (struct Property *p,
+ struct ATS_Address *address,
uint32_t avg_value)
{
struct FindMinMaxCtx find_ctx;
@@ -239,7 +284,7 @@
find_ctx.max = 0;
find_ctx.min = UINT32_MAX;
addr_count = GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
- &find_min_max_it,
+ &find_min_max_it,
&find_ctx);
if (0 == addr_count)
{
@@ -252,7 +297,7 @@
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Normalizing %s: new maximum %u -> recalculate all values\n",
- GNUNET_ATS_print_property_type (p->atsi_type),
+ GNUNET_ATS_print_property_type (p->atsi_type),
find_ctx.max);
p->max = find_ctx.max;
limits_changed = GNUNET_YES;
@@ -278,13 +323,15 @@
if (GNUNET_NO == limits_changed)
{
/* normalize just this address */
- normalize_address (p, &address->peer, address);
+ normalize_address (p,
+ &address->peer,
+ address);
}
else
{
/* limits changed, normalize all addresses */
GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
- &normalize_address,
+ &normalize_address,
p);
}
}
@@ -340,40 +387,40 @@
/* Normalizing */
/* Check min, max */
cur_prop = &properties[c2];
- property_normalize (cur_prop, address, current_val);
+ property_normalize (cur_prop,
+ address,
+ current_val);
}
}
-
/**
* Start the normalization component
*/
void
GAS_normalization_start ()
{
- int c1;
+ unsigned int c1;
unsigned int existing_properties[] = GNUNET_ATS_QualityProperties;
- property_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
{
properties[c1].prop_type = c1;
properties[c1].atsi_type = existing_properties[c1];
- properties[c1].min = 0;
+ properties[c1].min = UINT32_MAX;
properties[c1].max = 0;
}
}
-
/**
* Stop the normalization component and free all items
*/
void
GAS_normalization_stop ()
{
- GNUNET_CONTAINER_multipeermap_destroy (property_peers);
+ /* nothing to do */
}
+
/* end of gnunet-service-ats_normalization.c */
Modified: gnunet/src/ats/gnunet-service-ats_normalization.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_normalization.h 2015-02-05 18:35:39 UTC
(rev 35108)
+++ gnunet/src/ats/gnunet-service-ats_normalization.h 2015-02-05 19:48:15 UTC
(rev 35109)
@@ -32,20 +32,8 @@
/**
- * Get the normalized preference values for a specific peer
- *
- * @param cls ignored
- * @param id the peer @return pointer to the values, can be indexed
- * with GNUNET_ATS_PreferenceKind, NULL if peer does not exist
- */
-const double *
-GAS_normalization_get_preferences_by_peer (void *cls,
- const struct GNUNET_PeerIdentity
*id);
-
-
-/**
* Get the normalized properties values for a specific peer or
- * the default values if
+ * the default values if no normalized values are available.
*
* @param cls ignored
* @param address the address
@@ -58,33 +46,6 @@
/**
- * Get the normalized preference values for a specific client and peer
- *
- * @param client client
- * @param peer the peer
- * @param pref the preference type
- * @return the value
- */
-double
-GAS_normalization_get_preferences_by_client (const void *client,
- const struct GNUNET_PeerIdentity
*peer,
- enum GNUNET_ATS_PreferenceKind
pref);
-
-/**
- * Normalize an updated preference value
- *
- * @param client 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
- */
-void
-GAS_normalization_normalize_preference (void *client,
- const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- float score_abs);
-
-/**
* Update and normalize a atsi performance information
*
* @param address the address to update
@@ -98,15 +59,6 @@
/**
- * A performance client disconnected
- *
- * @param client the disconnecting client
- */
-void
-GAS_normalization_preference_client_disconnect (void *client);
-
-
-/**
* Start the normalization component
*/
void
Modified: gnunet/src/ats/gnunet-service-ats_plugins.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_plugins.c 2015-02-05 18:35:39 UTC (rev
35108)
+++ gnunet/src/ats/gnunet-service-ats_plugins.c 2015-02-05 19:48:15 UTC (rev
35109)
@@ -32,6 +32,7 @@
#include "gnunet_ats_plugin.h"
#include "gnunet-service-ats_addresses.h"
#include "gnunet-service-ats_performance.h"
+#include "gnunet-service-ats_preferences.h"
#include "gnunet-service-ats_plugins.h"
#include "gnunet-service-ats_scheduling.h"
#include "gnunet-service-ats_normalization.h"
@@ -207,7 +208,7 @@
* @param address the address with changes
*/
static void
-bandwidth_changed_cb (void *cls,
+bandwidth_changed_cb (void *cls,
struct ATS_Address *address)
{
uint32_t diff_out;
@@ -222,7 +223,7 @@
address->plugin,
address->addr,
address->addr_len,
- address->active,
+ address->active,
address->atsi,
address->atsi_count,
GNUNET_BANDWIDTH_value_init
(address->assigned_bw_out),
@@ -601,8 +602,8 @@
{
env.sf.s_feedback (solver,
application,
- peer,
- scope,
+ peer,
+ scope,
kind,
score_abs);
}
@@ -635,9 +636,9 @@
GNUNET_i2s (pid));
return;
}
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Suggesting address %p for peer `%s'\n",
- aa,
+ aa,
GNUNET_i2s (pid));
GAS_scheduling_transmit_address_suggestion (pid,
Modified: gnunet/src/ats/gnunet-service-ats_preferences.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_preferences.h 2015-02-05 18:35:39 UTC
(rev 35108)
+++ gnunet/src/ats/gnunet-service-ats_preferences.h 2015-02-05 19:48:15 UTC
(rev 35109)
@@ -49,6 +49,57 @@
/**
+ * Get the normalized preference values for a specific peer.
+ *
+ * @param cls ignored
+ * @param id the peer
+ * @return pointer to the values, can be indexed
+ * with GNUNET_ATS_PreferenceKind, NULL if peer does not exist
+ */
+const double *
+GAS_normalization_get_preferences_by_peer (void *cls,
+ const struct GNUNET_PeerIdentity
*id);
+
+
+/**
+ * Get the normalized preference values for a specific client and peer
+ *
+ * @param client client
+ * @param peer the peer
+ * @param pref the preference type
+ * @return the value
+ */
+double
+GAS_normalization_get_preferences_by_client (const void *client,
+ const struct GNUNET_PeerIdentity
*peer,
+ enum GNUNET_ATS_PreferenceKind
pref);
+
+
+/**
+ * Normalize an updated preference value
+ *
+ * @param client 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
+ */
+void
+GAS_normalization_normalize_preference (void *client,
+ const struct GNUNET_PeerIdentity *peer,
+ enum GNUNET_ATS_PreferenceKind kind,
+ float score_abs);
+
+
+/**
+ * A performance client disconnected
+ *
+ * @param client the disconnecting client
+ */
+void
+GAS_normalization_preference_client_disconnect (void *client);
+
+
+/**
* Handle 'preference change' messages from clients.
*
* @param cls unused, NULL
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r35109 - gnunet/src/ats,
gnunet <=