manage preferences expressed by clients More...
#include "platform.h"
#include "gnunet-service-ats.h"
#include "gnunet-service-ats_addresses.h"
#include "gnunet-service-ats_performance.h"
#include "gnunet-service-ats_plugins.h"
#include "gnunet-service-ats_preferences.h"
#include "gnunet-service-ats_reservations.h"
#include "ats.h"
Go to the source code of this file.
Data Structures | |
struct | PeerRelative |
Relative preferences for a peer. More... | |
struct | PreferencePeer |
Preference information per peer and client. More... | |
struct | PreferenceClient |
Preference client, as in a client that expressed preferences for peers. More... | |
struct | SumContext |
Closure for sum_relative_preferences(). More... | |
struct | AgeContext |
Closure for age_values(). More... | |
struct | UpdateContext |
Closure for update_rel_sum() and update_abs_sum(). More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "ats-preferences", __VA_ARGS__) |
#define | PREF_AGING_INTERVAL |
How frequently do we age preference values? More... | |
#define | PREF_AGING_FACTOR 0.95 |
By which factor do we age preferences expressed during each PREF_AGING_INTERVAL? More... | |
#define | PREF_EPSILON 0.01 |
What is the lowest threshold up to which preference values are aged, and below which we consider them zero and thus no longer subject to aging? More... | |
Functions | |
static int | sum_relative_preferences (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) |
Add the relative preference for the kind given to the closure. More... | |
static void | update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id, enum GNUNET_ATS_PreferenceKind kind) |
Update the total relative preference for a peer by summing up the relative preferences all clients have for this peer. More... | |
static int | free_peer (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
Free a peer's struct PeerRelative . More... | |
static int | free_preference (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
Free struct PreferencePeer entry in map. More... | |
static int | age_values (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) |
Age preference values of the given peer. More... | |
static void | preference_aging (void *cls) |
Reduce absolute preferences since they got old. More... | |
static int | update_abs_sum (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) |
Compute updated absolute score for the client based on the current absolute scores for each peer. More... | |
static int | update_rel_sum (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) |
Compute updated relative score for each peer based on the current absolute score given by this client. More... | |
static void | recalculate_relative_preferences (struct PreferenceClient *c, enum GNUNET_ATS_PreferenceKind kind) |
Recalculate preference for a specific ATS property. More... | |
static int | update_iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
The relative preferences of one of the clients have changed, update the global preferences for the given peer and notify the plugin. More... | |
static void | update_preference (struct GNUNET_SERVICE_Client *client, const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, float score_abs) |
Update the absolute preference and calculate the new relative preference value. More... | |
void | GAS_handle_preference_change (struct GNUNET_SERVICE_Client *client, const struct ChangePreferenceMessage *msg) |
Handle 'preference change' messages from clients. More... | |
void | GAS_preference_init () |
Initialize preferences subsystem. More... | |
void | GAS_preference_done () |
Shutdown preferences subsystem. More... | |
const double * | GAS_preference_get_by_peer (void *cls, const struct GNUNET_PeerIdentity *id) |
Get the normalized preference values for a specific peer or the default values if. More... | |
void | GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client) |
A performance client disconnected. More... | |
Variables | |
static struct PeerRelative | defvalues |
Default values, returned as our preferences if we do not have any preferences expressed for a peer. More... | |
static struct GNUNET_CONTAINER_MultiPeerMap * | preference_peers |
Hashmap to store peer information for preference normalization. More... | |
static struct PreferenceClient * | pc_head |
Clients in DLL: head. More... | |
static struct PreferenceClient * | pc_tail |
Clients in DLL: tail. More... | |
static struct GNUNET_SCHEDULER_Task * | aging_task |
Handle for task we run periodically to age preferences over time. More... | |
manage preferences expressed by clients
Definition in file gnunet-service-ats_preferences.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "ats-preferences", __VA_ARGS__) |
Definition at line 35 of file gnunet-service-ats_preferences.c.
#define PREF_AGING_INTERVAL |
How frequently do we age preference values?
Definition at line 40 of file gnunet-service-ats_preferences.c.
#define PREF_AGING_FACTOR 0.95 |
By which factor do we age preferences expressed during each PREF_AGING_INTERVAL?
Definition at line 47 of file gnunet-service-ats_preferences.c.
#define PREF_EPSILON 0.01 |
What is the lowest threshold up to which preference values are aged, and below which we consider them zero and thus no longer subject to aging?
Definition at line 54 of file gnunet-service-ats_preferences.c.
|
static |
Add the relative preference for the kind given to the closure.
cls | the struct SumContext with the kind and place to store the result |
peer | ignored |
value | the struct PreferencePeer for getting the rel pref. |
Definition at line 201 of file gnunet-service-ats_preferences.c.
References PreferencePeer::f_rel, SumContext::f_rel_total, GNUNET_OK, SumContext::kind, and value.
Referenced by update_relative_values_for_peer().
|
static |
Update the total relative preference for a peer by summing up the relative preferences all clients have for this peer.
id | peer id of the peer for which we should do the update |
kind | the kind of preference value to update |
Definition at line 222 of file gnunet-service-ats_preferences.c.
References SumContext::f_rel_total, GAS_plugin_notify_preference_changed(), GNUNET_assert, GNUNET_ATS_print_preference_type(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), SumContext::kind, LOG, PreferenceClient::next, pc_head, PreferenceClient::peer2pref, preference_peers, rp, and sum_relative_preferences().
Referenced by age_values(), and update_iterator().
|
static |
Free a peer's struct PeerRelative
.
cls | unused |
key | the key |
value | the struct PeerRelative to free. |
Definition at line 263 of file gnunet-service-ats_preferences.c.
References GNUNET_assert, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_OK, GNUNET_YES, key, preference_peers, rp, and value.
Referenced by free_preference(), and GAS_preference_done().
|
static |
Free struct PreferencePeer
entry in map.
cls | the struct PreferenceClient with the map |
key | the peer the entry is for |
value | the struct PreferencePeer entry to free |
Definition at line 287 of file gnunet-service-ats_preferences.c.
References free_peer(), GNUNET_assert, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_OK, key, PeerRelative::num_clients, p, pc, preference_peers, and value.
Referenced by age_values(), GAS_preference_client_disconnect(), and GAS_preference_done().
|
static |
Age preference values of the given peer.
cls | a ` |
peer | peer being aged |
value | the struct PreferencePeer for the peer |
Definition at line 342 of file gnunet-service-ats_preferences.c.
References ac, DEFAULT_ABS_PREFERENCE, DEFAULT_REL_PREFERENCE, free_preference(), GNUNET_ATS_PREFERENCE_END, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_YES, p, peer, PREF_AGING_FACTOR, PREF_EPSILON, update_relative_values_for_peer(), and value.
Referenced by preference_aging().
|
static |
Reduce absolute preferences since they got old.
cls | unused |
Definition at line 389 of file gnunet-service-ats_preferences.c.
References ac, age_values(), aging_task, GAS_plugin_solver_lock(), GAS_plugin_solver_unlock(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_MQ_Envelope::next, pc_head, and PREF_AGING_INTERVAL.
Referenced by update_preference().
|
static |
Compute updated absolute score for the client based on the current absolute scores for each peer.
cls | a struct UpdateContext |
peer | peer being updated |
value | the struct PreferencePeer for the peer |
Definition at line 447 of file gnunet-service-ats_preferences.c.
References PreferencePeer::f_abs, GNUNET_OK, uc, and value.
Referenced by recalculate_relative_preferences().
|
static |
Compute updated relative score for each peer based on the current absolute score given by this client.
cls | a struct UpdateContext |
peer | peer being updated |
value | the struct PreferencePeer for the peer (updated) |
Definition at line 469 of file gnunet-service-ats_preferences.c.
References PreferencePeer::f_abs, PreferencePeer::f_rel, GNUNET_ATS_print_preference_type(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_OK, LOG, peer, uc, and value.
Referenced by recalculate_relative_preferences().
|
static |
Recalculate preference for a specific ATS property.
c | the preference client |
kind | the preference kind |
Definition at line 494 of file gnunet-service-ats_preferences.c.
References PreferenceClient::f_abs_sum, GNUNET_ATS_print_preference_type(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, UpdateContext::kind, LOG, PreferenceClient::peer2pref, uc, update_abs_sum(), and update_rel_sum().
Referenced by update_preference().
|
static |
The relative preferences of one of the clients have changed, update the global preferences for the given peer and notify the plugin.
cls | the kind of preference to calculate the new global relative preference values for |
key | the peer to update relative preference values for |
value | a struct PeerRelative , unused |
Definition at line 531 of file gnunet-service-ats_preferences.c.
References GNUNET_OK, key, UpdateContext::kind, and update_relative_values_for_peer().
Referenced by update_preference().
|
static |
Update the absolute preference and calculate the new relative preference value.
client | the client with this preference |
peer | the peer to change the preference for |
kind | the kind to change the preference |
score_abs | the normalized score |
Definition at line 553 of file gnunet-service-ats_preferences.c.
References aging_task, PreferenceClient::client, DEFAULT_ABS_PREFERENCE, DEFAULT_REL_PREFERENCE, PreferencePeer::f_abs, PreferenceClient::f_abs_sum, PeerRelative::f_rel, PreferencePeer::f_rel, GNUNET_assert, GNUNET_ATS_PREFERENCE_END, GNUNET_ATS_print_preference_type(), GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_create(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_YES, LOG, PreferenceClient::next, PeerRelative::num_clients, pc_head, pc_tail, peer, PreferenceClient::peer2pref, PREF_AGING_INTERVAL, preference_aging(), preference_peers, recalculate_relative_preferences(), and update_iterator().
Referenced by GAS_handle_preference_change(), and set_pref_task().
void GAS_handle_preference_change | ( | struct GNUNET_SERVICE_Client * | client, |
const struct ChangePreferenceMessage * | msg | ||
) |
Handle 'preference change' messages from clients.
client | the client that sent the request |
msg | the request message |
Definition at line 650 of file gnunet-service-ats_preferences.c.
References GAS_plugin_solver_lock(), GAS_plugin_solver_unlock(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GSA_stats, msg, pi, PreferenceInformation::preference_kind, PreferenceInformation::preference_value, and update_preference().
Referenced by handle_preference_change().
void GAS_preference_init | ( | void | ) |
Initialize preferences subsystem.
Definition at line 680 of file gnunet-service-ats_preferences.c.
References DEFAULT_REL_PREFERENCE, defvalues, PeerRelative::f_rel, GNUNET_ATS_PREFERENCE_END, GNUNET_CONTAINER_multipeermap_create(), GNUNET_NO, and preference_peers.
Referenced by run().
void GAS_preference_done | ( | void | ) |
Shutdown preferences subsystem.
Definition at line 695 of file gnunet-service-ats_preferences.c.
References aging_task, free_peer(), free_preference(), GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_free, GNUNET_SCHEDULER_cancel(), pc, pc_head, pc_tail, and preference_peers.
Referenced by cleanup_task(), and run().
const double* GAS_preference_get_by_peer | ( | void * | cls, |
const struct GNUNET_PeerIdentity * | id | ||
) |
Get the normalized preference values for a specific peer or the default values if.
Get the normalized preference values for a specific peer.
cls | ignored |
id | the peer |
Definition at line 735 of file gnunet-service-ats_preferences.c.
References defvalues, PeerRelative::f_rel, GNUNET_CONTAINER_multipeermap_get(), preference_peers, and rp.
Referenced by GAS_plugin_init(), and get_preferences_cb().
void GAS_preference_client_disconnect | ( | struct GNUNET_SERVICE_Client * | client | ) |
A performance client disconnected.
client | the disconnecting client |
Definition at line 751 of file gnunet-service-ats_preferences.c.
References PreferenceClient::client, free_preference(), GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_free, PreferenceClient::next, pc_head, pc_tail, and PreferenceClient::peer2pref.
Referenced by client_disconnect_cb().
|
static |
Default values, returned as our preferences if we do not have any preferences expressed for a peer.
Definition at line 1 of file gnunet-service-ats_preferences.c.
Referenced by GAS_preference_get_by_peer(), and GAS_preference_init().
|
static |
Hashmap to store peer information for preference normalization.
Maps the identity of a peer to a struct PeerRelative
containing the current relative preference values for that peer.
Definition at line 155 of file gnunet-service-ats_preferences.c.
Referenced by free_peer(), free_preference(), GAS_preference_done(), GAS_preference_get_by_peer(), GAS_preference_init(), update_preference(), and update_relative_values_for_peer().
|
static |
Clients in DLL: head.
Definition at line 160 of file gnunet-service-ats_preferences.c.
Referenced by GAS_preference_client_disconnect(), GAS_preference_done(), preference_aging(), update_preference(), and update_relative_values_for_peer().
|
static |
Clients in DLL: tail.
Definition at line 165 of file gnunet-service-ats_preferences.c.
Referenced by GAS_preference_client_disconnect(), GAS_preference_done(), and update_preference().
|
static |
Handle for task we run periodically to age preferences over time.
Definition at line 170 of file gnunet-service-ats_preferences.c.
Referenced by GAS_preference_done(), preference_aging(), and update_preference().