diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-07 12:46:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-07 12:46:37 +0000 |
commit | 6e54571bd00f7ea045dabcd5fc9fc3080665f5fc (patch) | |
tree | e8e204155e5fd9fc8bf6e7620331a9fc484ce78a /src | |
parent | 577ad3b798f0cd62c2e9ab92fdc58cfe75a3fcdc (diff) |
simplify logic
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/Makefile.am | 1 | ||||
-rw-r--r-- | src/ats/gnunet-ats-solver-eval.c | 15 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 7 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 5 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_plugins.c | 21 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_plugins.h | 14 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_preferences.c | 264 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_preferences.h | 14 |
8 files changed, 130 insertions, 211 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index fcd71d37df..501fec4d76 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -48,7 +48,6 @@ gnunet_ats_solver_eval_SOURCES = \ 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 diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c index c39bb30f70..99771d0e8e 100644 --- a/src/ats/gnunet-ats-solver-eval.c +++ b/src/ats/gnunet-ats-solver-eval.c @@ -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 @@ set_pref_task (void *cls, 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 @@ set_pref_task (void *cls, 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) { diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 0c896e4890..78bde6ec26 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -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 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, 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); } diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index 2448131082..8eaedc92db 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c @@ -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 @@ GAS_normalization_normalize_property (struct ATS_Address *address, "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 @@ GAS_normalization_normalize_property (struct ATS_Address *address, address, current_val); } + GAS_plugin_solver_unlock (); } diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c index c388e7f67d..8cc6af46f3 100644 --- a/src/ats/gnunet-service-ats_plugins.c +++ b/src/ats/gnunet-service-ats_plugins.c @@ -545,27 +545,6 @@ GAS_plugin_new_address (struct ATS_Address *new_address, /** - * 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. * diff --git a/src/ats/gnunet-service-ats_plugins.h b/src/ats/gnunet-service-ats_plugins.h index 7e093d9402..46a1d29fb9 100644 --- a/src/ats/gnunet-service-ats_plugins.h +++ b/src/ats/gnunet-service-ats_plugins.h @@ -125,20 +125,6 @@ GAS_plugin_new_address (struct ATS_Address *new_address, /** - * 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. * diff --git a/src/ats/gnunet-service-ats_preferences.c b/src/ats/gnunet-service-ats_preferences.c index c9559ba89d..297db7d7ed 100644 --- a/src/ats/gnunet-service-ats_preferences.c +++ b/src/ats/gnunet-service-ats_preferences.c @@ -446,35 +446,122 @@ update_abs_preference (struct PreferenceClient *c, /** - * 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 @@ GAS_handle_preference_change (void *cls, 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 @@ GAS_handle_preference_change (void *cls, 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 @@ GAS_preference_done () /** - * 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 * diff --git a/src/ats/gnunet-service-ats_preferences.h b/src/ats/gnunet-service-ats_preferences.h index 1715288d73..fb52ecb62b 100644 --- a/src/ats/gnunet-service-ats_preferences.h +++ b/src/ats/gnunet-service-ats_preferences.h @@ -66,20 +66,6 @@ GAS_preference_done (void); /** - * 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 |