[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r35126 - gnunet/src/ats
From: |
gnunet |
Subject: |
[GNUnet-SVN] r35126 - gnunet/src/ats |
Date: |
Sat, 7 Feb 2015 13:46:37 +0100 |
Author: grothoff
Date: 2015-02-07 13:46:37 +0100 (Sat, 07 Feb 2015)
New Revision: 35126
Modified:
gnunet/src/ats/Makefile.am
gnunet/src/ats/gnunet-ats-solver-eval.c
gnunet/src/ats/gnunet-service-ats_addresses.c
gnunet/src/ats/gnunet-service-ats_normalization.c
gnunet/src/ats/gnunet-service-ats_plugins.c
gnunet/src/ats/gnunet-service-ats_plugins.h
gnunet/src/ats/gnunet-service-ats_preferences.c
gnunet/src/ats/gnunet-service-ats_preferences.h
Log:
simplify logic
Modified: gnunet/src/ats/Makefile.am
===================================================================
--- gnunet/src/ats/Makefile.am 2015-02-07 12:33:51 UTC (rev 35125)
+++ gnunet/src/ats/Makefile.am 2015-02-07 12:46:37 UTC (rev 35126)
@@ -48,7 +48,6 @@
gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \
gnunet-service-ats_feedback.c gnunet-service-ats_feedback.h \
gnunet-service-ats_performance.c gnunet-service-ats_performance.h \
- gnunet-service-ats_preferences.c gnunet-service-ats_preferences.h \
gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h \
gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \
gnunet-service-ats_normalization.c
Modified: gnunet/src/ats/gnunet-ats-solver-eval.c
===================================================================
--- gnunet/src/ats/gnunet-ats-solver-eval.c 2015-02-07 12:33:51 UTC (rev
35125)
+++ gnunet/src/ats/gnunet-ats-solver-eval.c 2015-02-07 12:46:37 UTC (rev
35126)
@@ -27,7 +27,7 @@
#include "gnunet_util_lib.h"
#include "gnunet-ats-solver-eval.h"
#include "gnunet-service-ats_normalization.h"
-#include "gnunet-service-ats_preferences.h"
+#include "gnunet-service-ats_preferences.c"
#define BIG_M_STRING "unlimited"
@@ -980,7 +980,6 @@
pg->peer, NULL + (pg->client_id),
GNUNET_ATS_print_preference_type (pg->kind), pref_value);
- sh->sf->s_bulk_start (sh->sf->cls);
if (GNUNET_YES == opt_disable_normalization)
{
p->pref_abs[pg->kind] = pref_value;
@@ -988,15 +987,17 @@
sh->sf->s_pref (sh->sf->cls, &p->peer_id, pg->kind, pref_value);
}
else
- GAS_normalization_normalize_preference (NULL + (pg->client_id),
- &p->peer_id, pg->kind, pref_value);
- sh->sf->s_bulk_stop (sh->sf->cls);
+ normalize_preference (NULL + (pg->client_id),
+ &p->peer_id,
+ pg->kind,
+ pref_value);
pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
- set_pref_task, pg);
-
+ &set_pref_task,
+ pg);
}
+
static struct PreferenceGenerator *
find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
{
Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c 2015-02-07 12:33:51 UTC
(rev 35125)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c 2015-02-07 12:46:37 UTC
(rev 35126)
@@ -27,6 +27,7 @@
#include "platform.h"
#include "gnunet-service-ats_addresses.h"
#include "gnunet-service-ats_performance.h"
+#include "gnunet-service-ats_normalization.h"
#include "gnunet-service-ats_plugins.h"
@@ -644,9 +645,9 @@
GNUNET_BANDWIDTH_value_init
(aa->assigned_bw_out),
GNUNET_BANDWIDTH_value_init
(aa->assigned_bw_in));
- GAS_plugin_update_address (aa,
- atsi,
- atsi_count);
+ GAS_normalization_normalize_property (aa,
+ atsi,
+ atsi_count);
}
GNUNET_free_non_null (atsi_delta);
}
Modified: gnunet/src/ats/gnunet-service-ats_normalization.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_normalization.c 2015-02-07 12:33:51 UTC
(rev 35125)
+++ gnunet/src/ats/gnunet-service-ats_normalization.c 2015-02-07 12:46:37 UTC
(rev 35126)
@@ -24,7 +24,7 @@
* @author Matthias Wachs
* @author Christian Grothoff
*
- * FIXME: rename to 'properties'!?
+ * FIXME: rename to 'properties'!? merge with addresses!?
*/
#include "platform.h"
#include "gnunet_ats_service.h"
@@ -360,7 +360,7 @@
"Updating %u elements for peer `%s'\n",
atsi_count,
GNUNET_i2s (&address->peer));
-
+ GAS_plugin_solver_lock ();
for (c1 = 0; c1 < atsi_count; c1++)
{
current_type = ntohl (atsi[c1].type);
@@ -391,6 +391,7 @@
address,
current_val);
}
+ GAS_plugin_solver_unlock ();
}
Modified: gnunet/src/ats/gnunet-service-ats_plugins.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_plugins.c 2015-02-07 12:33:51 UTC (rev
35125)
+++ gnunet/src/ats/gnunet-service-ats_plugins.c 2015-02-07 12:46:37 UTC (rev
35126)
@@ -545,27 +545,6 @@
/**
- * Tell the solver that updated performance data was
- * observed for the given address.
- *
- * @param new_address the new address
- * @param atsi updated performance data for the address
- * @param atsi_count size of the @a atsi array
- */
-void
-GAS_plugin_update_address (struct ATS_Address *address,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count)
-{
- sf->s_bulk_start (sf->cls);
- GAS_normalization_normalize_property (address,
- atsi,
- atsi_count);
- sf->s_bulk_stop (sf->cls);
-}
-
-
-/**
* Tell the solver that the given address is no longer valid
* can cannot be used any longer.
*
Modified: gnunet/src/ats/gnunet-service-ats_plugins.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_plugins.h 2015-02-07 12:33:51 UTC (rev
35125)
+++ gnunet/src/ats/gnunet-service-ats_plugins.h 2015-02-07 12:46:37 UTC (rev
35126)
@@ -125,20 +125,6 @@
/**
- * Tell the solver that updated performance data was
- * observed for the given address.
- *
- * @param new_address the new address
- * @param atsi updated performance data for the address
- * @param atsi_count size of the @a atsi array
- */
-void
-GAS_plugin_update_address (struct ATS_Address *address,
- const struct GNUNET_ATS_Information *atsi,
- uint32_t atsi_count);
-
-
-/**
* Tell the solver that the given address is no longer valid
* can cannot be used any longer.
*
Modified: gnunet/src/ats/gnunet-service-ats_preferences.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_preferences.c 2015-02-07 12:33:51 UTC
(rev 35125)
+++ gnunet/src/ats/gnunet-service-ats_preferences.c 2015-02-07 12:46:37 UTC
(rev 35126)
@@ -446,35 +446,122 @@
/**
- * Change the preference for a peer
+ * Normalize an updated preference value
*
- * @param client the client sending this request
- * @param peer the peer id
- * @param kind the preference kind to change
- * @param score_abs the new preference score
+ * @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
*/
static void
-preference_change (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- float score_abs)
+normalize_preference (struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_PeerIdentity *peer,
+ enum GNUNET_ATS_PreferenceKind kind,
+ float score_abs)
{
- if (GNUNET_NO ==
- GNUNET_CONTAINER_multipeermap_contains (GSA_addresses,
- peer))
+ struct PreferenceClient *c_cur;
+ struct PreferencePeer *p_cur;
+ struct PeerRelative *r_cur;
+ double old_value;
+ int i;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Client changes preference for peer `%s' for `%s' to %.2f\n",
+ GNUNET_i2s (peer),
+ GNUNET_ATS_print_preference_type (kind),
+ score_abs);
+
+ if (kind >= GNUNET_ATS_PreferenceCount)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received CHANGE_PREFERENCE for unknown peer `%s'\n",
- GNUNET_i2s (peer));
+ GNUNET_break(0);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received CHANGE_PREFERENCE for peer `%s'\n",
- GNUNET_i2s (peer));
- GAS_normalization_normalize_preference (client,
- peer,
- kind,
- score_abs);
+
+ /* Find preference client */
+ for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
+ if (client == c_cur->client)
+ break;
+ /* Not found: create new preference client */
+ if (NULL == c_cur)
+ {
+ c_cur = GNUNET_new (struct PreferenceClient);
+ c_cur->client = client;
+ for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
+ {
+ c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE;
+ c_cur->f_rel_sum[i] = DEFAULT_REL_PREFERENCE;
+ }
+ GNUNET_CONTAINER_DLL_insert (pc_head,
+ pc_tail,
+ c_cur);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding new client %p\n",
+ 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_new (struct PreferencePeer);
+ p_cur->client = c_cur;
+ p_cur->id = *peer;
+ for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
+ {
+ /* Default value per peer absolute preference for a 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->next_aging[i] = GNUNET_TIME_UNIT_FOREVER_ABS;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding new peer %p for client %p\n",
+ p_cur,
+ c_cur);
+ GNUNET_CONTAINER_DLL_insert (c_cur->p_head,
+ c_cur->p_tail,
+ p_cur);
+ }
+
+ /* Create struct for peer */
+ if (NULL ==
+ GNUNET_CONTAINER_multipeermap_get (preference_peers,
+ peer))
+ {
+ r_cur = GNUNET_new (struct PeerRelative);
+ r_cur->id = *peer;
+ for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
+ r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
+ GNUNET_assert(GNUNET_OK ==
+ GNUNET_CONTAINER_multipeermap_put (preference_peers,
+ &r_cur->id,
+ r_cur,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ }
+
+ /* Update absolute value */
+ old_value = p_cur->f_abs[kind];
+ update_abs_preference (c_cur, p_cur, kind, score_abs);
+ if (p_cur->f_abs[kind] == old_value)
+ return;
+
+ GAS_plugin_solver_lock ();
+ run_preference_update (c_cur,
+ p_cur,
+ kind,
+ score_abs);
+ GAS_plugin_solver_unlock ();
+
+ if (NULL == aging_task)
+ aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
+ &preference_aging,
+ NULL);
}
@@ -497,8 +584,7 @@
uint32_t i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message\n",
- "PREFERENCE_CHANGE");
+ "Received PREFERENCE_CHANGE message\n");
msize = ntohs (message->size);
if (msize < sizeof (struct ChangePreferenceMessage))
{
@@ -521,11 +607,11 @@
1, GNUNET_NO);
pi = (const struct PreferenceInformation *) &msg[1];
for (i = 0; i < nump; i++)
- preference_change (client,
- &msg->peer,
- (enum GNUNET_ATS_PreferenceKind)
- ntohl (pi[i].preference_kind),
- pi[i].preference_value);
+ normalize_preference (client,
+ &msg->peer,
+ (enum GNUNET_ATS_PreferenceKind)
+ ntohl (pi[i].preference_kind),
+ pi[i].preference_value);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -619,126 +705,6 @@
/**
- * 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 (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- float score_abs)
-{
- struct PreferenceClient *c_cur;
- struct PreferencePeer *p_cur;
- struct PeerRelative *r_cur;
- double old_value;
- int i;
-
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Client changes preference for peer `%s' for `%s' to %.2f\n",
- GNUNET_i2s (peer),
- GNUNET_ATS_print_preference_type (kind),
- score_abs);
-
- if (kind >= GNUNET_ATS_PreferenceCount)
- {
- GNUNET_break(0);
- return;
- }
-
- /* Find preference client */
- for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
- if (client == c_cur->client)
- break;
- /* Not found: create new preference client */
- if (NULL == c_cur)
- {
- c_cur = GNUNET_new (struct PreferenceClient);
- c_cur->client = client;
- for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
- {
- c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE;
- c_cur->f_rel_sum[i] = DEFAULT_REL_PREFERENCE;
- }
- GNUNET_CONTAINER_DLL_insert (pc_head,
- pc_tail,
- c_cur);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding new client %p\n",
- 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_new (struct PreferencePeer);
- p_cur->client = c_cur;
- p_cur->id = *peer;
- for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
- {
- /* Default value per peer absolute preference for a 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->next_aging[i] = GNUNET_TIME_UNIT_FOREVER_ABS;
- }
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding new peer %p for client %p\n",
- p_cur,
- c_cur);
- GNUNET_CONTAINER_DLL_insert (c_cur->p_head,
- c_cur->p_tail,
- p_cur);
- }
-
- /* Create struct for peer */
- if (NULL ==
- GNUNET_CONTAINER_multipeermap_get (preference_peers,
- peer))
- {
- r_cur = GNUNET_new (struct PeerRelative);
- r_cur->id = *peer;
- for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
- r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
- GNUNET_assert(GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put (preference_peers,
- &r_cur->id,
- r_cur,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- }
-
- /* Update absolute value */
- old_value = p_cur->f_abs[kind];
- update_abs_preference (c_cur, p_cur, kind, score_abs);
- if (p_cur->f_abs[kind] == old_value)
- return;
-
- GAS_plugin_solver_lock ();
- run_preference_update (c_cur,
- p_cur,
- kind,
- score_abs);
- GAS_plugin_solver_unlock ();
-
- if (NULL == aging_task)
- aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
- &preference_aging,
- NULL);
-}
-
-
-/**
* Get the normalized preference values for a specific peer or
* the default values if
*
Modified: gnunet/src/ats/gnunet-service-ats_preferences.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_preferences.h 2015-02-07 12:33:51 UTC
(rev 35125)
+++ gnunet/src/ats/gnunet-service-ats_preferences.h 2015-02-07 12:46:37 UTC
(rev 35126)
@@ -66,20 +66,6 @@
/**
- * 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 (struct GNUNET_SERVER_Client *client,
- const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- float score_abs);
-
-/**
* Get the normalized preference values for a specific peer.
*
* @param cls ignored
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r35126 - gnunet/src/ats,
gnunet <=