GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
gnunet-service-ats_preferences.c File Reference

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"
Include dependency graph for gnunet-service-ats_preferences.c:
This graph shows which files directly or indirectly include this file:

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 prefernce 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 releative 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_MultiPeerMappreference_peers
 Hashmap to store peer information for preference normalization. More...
 
static struct PreferenceClientpc_head
 Clients in DLL: head. More...
 
static struct PreferenceClientpc_tail
 Clients in DLL: tail. More...
 
static struct GNUNET_SCHEDULER_Taskaging_task
 Handle for task we run periodically to age preferences over time. More...
 

Detailed Description

manage preferences expressed by clients

Author
Matthias Wachs
Christian Grothoff

Definition in file gnunet-service-ats_preferences.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "ats-preferences", __VA_ARGS__)

◆ PREF_AGING_INTERVAL

#define PREF_AGING_INTERVAL
Value:
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:442

How frequently do we age preference values?

Definition at line 40 of file gnunet-service-ats_preferences.c.

Referenced by preference_aging(), and update_preference().

◆ PREF_AGING_FACTOR

#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.

Referenced by age_values().

◆ PREF_EPSILON

#define PREF_EPSILON   0.01

What is the lowest threshold up to which prefernce 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.

Referenced by age_values().

Function Documentation

◆ sum_relative_preferences()

static int sum_relative_preferences ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Add the relative preference for the kind given to the closure.

Parameters
clsthe struct SumContext with the kind and place to store the result
peerignored
valuethe struct PreferencePeer for getting the rel pref.
Returns
GNUNET_OK

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().

204 {
205  struct SumContext *sum_ctx = cls;
206  struct PreferencePeer *p_cur = value;
207 
208  sum_ctx->f_rel_total += p_cur->f_rel[sum_ctx->kind];
209  return GNUNET_OK;
210 }
enum GNUNET_ATS_PreferenceKind kind
Which kind of preference value are we adding up?
double f_rel_total
Where to accumulate the result.
Closure for sum_relative_preferences().
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
double f_rel[GNUNET_ATS_PREFERENCE_END]
Relative preference values for all preference types, normalized in [0..1] based on how the respective...
static char * value
Value of the record to add/remove.
Preference information per peer and client.
Here is the caller graph for this function:

◆ update_relative_values_for_peer()

static void update_relative_values_for_peer ( const struct GNUNET_PeerIdentity id,
enum GNUNET_ATS_PreferenceKind  kind 
)
static

Update the total releative preference for a peer by summing up the relative preferences all clients have for this peer.

Parameters
idpeer id of the peer for which we should do the update
kindthe kind of preference value to update
Returns
the new relative preference

Definition at line 222 of file gnunet-service-ats_preferences.c.

References PeerRelative::f_rel, 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, PreferenceClient::peer2pref, rp, and sum_relative_preferences().

Referenced by age_values(), and update_iterator().

224 {
225  struct PreferenceClient *c_cur;
226  struct SumContext sum_ctx;
227  struct PeerRelative *rp;
228 
229  sum_ctx.f_rel_total = 0.0;
230  sum_ctx.kind = kind;
231  for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
233  id,
235  &sum_ctx);
237  "Total relative preference for peer `%s' for `%s' is %.3f\n",
238  GNUNET_i2s (id),
240  sum_ctx.f_rel_total);
242  id);
243  GNUNET_assert (NULL != rp);
244  if (rp->f_rel[kind] != sum_ctx.f_rel_total)
245  {
246  rp->f_rel[kind] = sum_ctx.f_rel_total;
248  kind,
249  rp->f_rel[kind]);
250  }
251 }
struct PreferenceClient * next
Next in client list.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Closure for sum_relative_preferences().
void GAS_plugin_notify_preference_changed(const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, double pref_rel)
The preference changed for a peer, update solver.
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.
double f_rel[GNUNET_ATS_PREFERENCE_END]
Array of relative preference values, to be indexed by an enum GNUNET_ATS_PreferenceKind.
Preference client, as in a client that expressed preferences for peers.
const char * GNUNET_ATS_print_preference_type(enum GNUNET_ATS_PreferenceKind type)
Convert a enum GNUNET_ATS_PreferenceType to a string.
static struct GNUNET_CONTAINER_MultiPeerMap * preference_peers
Hashmap to store peer information for preference normalization.
Relative preferences for a peer.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
static char * rp
Relying party.
static struct PreferenceClient * pc_head
Clients in DLL: head.
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
struct GNUNET_CONTAINER_MultiPeerMap * peer2pref
Mapping peer identities to struct PreferencePeer entry for the respective peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_peer()

static int free_peer ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Free a peer's struct PeerRelative.

Parameters
clsunused
keythe key
valuethe struct PeerRelative to free.
Returns
GNUNET_OK to continue

Definition at line 263 of file gnunet-service-ats_preferences.c.

References GNUNET_assert, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_OK, GNUNET_YES, rp, and value.

Referenced by free_preference(), and GAS_preference_done().

266 {
267  struct PeerRelative *rp = value;
268 
271  key,
272  value));
273  GNUNET_free (rp);
274  return GNUNET_OK;
275 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static char * value
Value of the record to add/remove.
static struct GNUNET_CONTAINER_MultiPeerMap * preference_peers
Hashmap to store peer information for preference normalization.
Relative preferences for a peer.
static char * rp
Relying party.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_preference()

static int free_preference ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Free struct PreferencePeer entry in map.

Parameters
clsthe struct PreferenceClient with the map
keythe peer the entry is for
valuethe struct PreferencePeer entry to free
Returns
GNUNET_OK (continue to iterate)

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, PeerRelative::num_clients, p, pc, PreferenceClient::peer2pref, and value.

Referenced by age_values(), GAS_preference_client_disconnect(), and GAS_preference_done().

290 {
291  struct PreferenceClient *pc = cls;
292  struct PreferencePeer *p = value;
293  struct PeerRelative *pr;
294 
297  key,
298  p));
299  GNUNET_free (p);
301  key);
302  GNUNET_assert (NULL != pr);
303  GNUNET_assert (pr->num_clients > 0);
304  pr->num_clients--;
305  if (0 == pr->num_clients)
306  {
307  free_peer (NULL,
308  key,
309  pr);
310  }
311  return GNUNET_OK;
312 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static int free_peer(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Free a peer's struct PeerRelative.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static char * value
Value of the record to add/remove.
Preference client, as in a client that expressed preferences for peers.
static struct GNUNET_CONTAINER_MultiPeerMap * preference_peers
Hashmap to store peer information for preference normalization.
Preference information per peer and client.
Relative preferences for a peer.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
unsigned int num_clients
Number of clients that are expressing a preference for this peer.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CONTAINER_MultiPeerMap * peer2pref
Mapping peer identities to struct PreferencePeer entry for the respective peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ age_values()

static int age_values ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Age preference values of the given peer.

Parameters
clsa `
peerpeer being aged
valuethe struct PreferencePeer for the peer
Returns
GNUNET_OK (continue to iterate)

Definition at line 342 of file gnunet-service-ats_preferences.c.

References ac, AgeContext::cur_client, DEFAULT_ABS_PREFERENCE, DEFAULT_REL_PREFERENCE, PreferencePeer::f_abs, PreferencePeer::f_rel, free_preference(), GNUNET_ATS_PREFERENCE_END, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_YES, p, PREF_AGING_FACTOR, PREF_EPSILON, update_relative_values_for_peer(), value, and AgeContext::values_to_update.

Referenced by preference_aging().

345 {
346  struct AgeContext *ac = cls;
347  struct PreferencePeer *p = value;
348  unsigned int i;
349  int dead;
350 
351  dead = GNUNET_YES;
352  for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
353  {
355  "Aging preference for peer `%s'\n",
356  GNUNET_i2s (peer));
357  if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE)
358  p->f_abs[i] *= PREF_AGING_FACTOR;
360  {
364  i);
365  }
366  else
367  {
368  ac->values_to_update++;
369  dead = GNUNET_NO;
370  }
371  }
372  if (GNUNET_YES == dead)
373  {
374  /* all preferences are zero, remove this entry */
376  peer,
377  p);
378  }
379  return GNUNET_OK;
380 }
struct PreferenceClient * cur_client
Client we are currently aging values for.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
End of preference list.
double f_rel[GNUNET_ATS_PREFERENCE_END]
Relative preference values for all preference types, normalized in [0..1] based on how the respective...
Closure for age_values().
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static char * value
Value of the record to add/remove.
#define PREF_AGING_FACTOR
By which factor do we age preferences expressed during each PREF_AGING_INTERVAL?
unsigned int values_to_update
Counter of values remaining to update, incremented for each value changed (to a new non-zero value)...
Preference information per peer and client.
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
#define DEFAULT_REL_PREFERENCE
Default relative preference value we assume if we know nothing.
#define PREF_EPSILON
What is the lowest threshold up to which prefernce values are aged, and below which we consider them ...
#define GNUNET_log(kind,...)
static int free_preference(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Free struct PreferencePeer entry in map.
static void update_relative_values_for_peer(const struct GNUNET_PeerIdentity *id, enum GNUNET_ATS_PreferenceKind kind)
Update the total releative preference for a peer by summing up the relative preferences all clients h...
#define GNUNET_YES
Definition: gnunet_common.h:77
#define DEFAULT_ABS_PREFERENCE
Default preference value we assume if we know nothing.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
double f_abs[GNUNET_ATS_PREFERENCE_END]
Absolute preference values for all preference types as expressed by this client for this peer...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ preference_aging()

static void preference_aging ( void *  cls)
static

Reduce absolute preferences since they got old.

Parameters
clsunused

Definition at line 389 of file gnunet-service-ats_preferences.c.

References age_values(), AgeContext::cur_client, GAS_plugin_solver_lock(), GAS_plugin_solver_unlock(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), PreferenceClient::next, PreferenceClient::peer2pref, PREF_AGING_INTERVAL, and AgeContext::values_to_update.

Referenced by update_preference().

390 {
391  struct AgeContext ac;
392 
393  aging_task = NULL;
395  ac.values_to_update = 0;
396  for (ac.cur_client = pc_head; NULL != ac.cur_client; ac.cur_client =
397  ac.cur_client->next)
398  GNUNET_CONTAINER_multipeermap_iterate (ac.cur_client->peer2pref,
399  &age_values,
400  &ac);
402  if (ac.values_to_update > 0)
403  {
405  "Rescheduling aging task due to %u elements remaining to age\n",
406  ac.values_to_update);
407  if (NULL == aging_task)
410  NULL);
411  }
412  else
413  {
415  "No values to age left, not rescheduling aging task\n");
416  }
417 }
void GAS_plugin_solver_lock()
Stop instant solving, there are many state updates happening in bulk right now.
void GAS_plugin_solver_unlock()
Resume instant solving, we are done with the bulk state updates.
Closure for age_values().
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static int age_values(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Age preference values of the given peer.
struct GNUNET_MQ_Envelope * next
Messages are stored in a linked list.
Definition: mq.c:38
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_SCHEDULER_Task * aging_task
Handle for task we run periodically to age preferences over time.
#define PREF_AGING_INTERVAL
How frequently do we age preference values?
static void preference_aging(void *cls)
Reduce absolute preferences since they got old.
#define GNUNET_log(kind,...)
static struct PreferenceClient * pc_head
Clients in DLL: head.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_abs_sum()

static int update_abs_sum ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Compute updated absolute score for the client based on the current absolute scores for each peer.

Parameters
clsa struct UpdateContext
peerpeer being updated
valuethe struct PreferencePeer for the peer
Returns
GNUNET_OK (continue to iterate)

Definition at line 447 of file gnunet-service-ats_preferences.c.

References PreferencePeer::f_abs, PreferenceClient::f_abs_sum, GNUNET_OK, UpdateContext::kind, UpdateContext::pc, uc, and value.

Referenced by recalculate_relative_preferences().

450 {
451  struct UpdateContext *uc = cls;
452  struct PreferencePeer *p_cur = value;
453 
454  uc->pc->f_abs_sum[uc->kind] += p_cur->f_abs[uc->kind];
455  return GNUNET_OK;
456 }
Closure for update_rel_sum() and update_abs_sum().
static struct GNUNET_FS_UnindexContext * uc
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static char * value
Value of the record to add/remove.
enum GNUNET_ATS_PreferenceKind kind
Which kind are we updating?
Preference information per peer and client.
double f_abs_sum[GNUNET_ATS_PREFERENCE_END]
Array of sums of absolute preferences for all peers as expressed by this client.
struct PreferenceClient * pc
Preference client with the sum of all absolute scores.
double f_abs[GNUNET_ATS_PREFERENCE_END]
Absolute preference values for all preference types as expressed by this client for this peer...
Here is the caller graph for this function:

◆ update_rel_sum()

static int update_rel_sum ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Compute updated relative score for each peer based on the current absolute score given by this client.

Parameters
clsa struct UpdateContext
peerpeer being updated
valuethe struct PreferencePeer for the peer (updated)
Returns
GNUNET_OK (continue to iterate)

Definition at line 469 of file gnunet-service-ats_preferences.c.

References PreferencePeer::f_abs, PreferenceClient::f_abs_sum, PreferencePeer::f_rel, GNUNET_ATS_print_preference_type(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_OK, UpdateContext::kind, LOG, UpdateContext::pc, uc, and value.

Referenced by recalculate_relative_preferences().

472 {
473  struct UpdateContext *uc = cls;
474  struct PreferencePeer *p_cur = value;
475 
476  p_cur->f_rel[uc->kind] = p_cur->f_abs[uc->kind] / uc->pc->f_abs_sum[uc->kind];
478  "Client has relative preference for %s for peer `%s' of %.3f\n",
480  GNUNET_i2s (peer),
481  p_cur->f_rel[uc->kind]);
482  return GNUNET_OK;
483 }
Closure for update_rel_sum() and update_abs_sum().
static struct GNUNET_FS_UnindexContext * uc
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
double f_rel[GNUNET_ATS_PREFERENCE_END]
Relative preference values for all preference types, normalized in [0..1] based on how the respective...
static char * value
Value of the record to add/remove.
enum GNUNET_ATS_PreferenceKind kind
Which kind are we updating?
const char * GNUNET_ATS_print_preference_type(enum GNUNET_ATS_PreferenceKind type)
Convert a enum GNUNET_ATS_PreferenceType to a string.
Preference information per peer and client.
double f_abs_sum[GNUNET_ATS_PREFERENCE_END]
Array of sums of absolute preferences for all peers as expressed by this client.
struct PreferenceClient * pc
Preference client with the sum of all absolute scores.
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
double f_abs[GNUNET_ATS_PREFERENCE_END]
Absolute preference values for all preference types as expressed by this client for this peer...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ recalculate_relative_preferences()

static void recalculate_relative_preferences ( struct PreferenceClient c,
enum GNUNET_ATS_PreferenceKind  kind 
)
static

Recalculate preference for a specific ATS property.

Parameters
cthe preference client
kindthe preference kind
Returns
the result

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, UpdateContext::pc, PreferenceClient::peer2pref, update_abs_sum(), and update_rel_sum().

Referenced by update_preference().

496 {
497  struct UpdateContext uc;
498 
499  /* For this client: sum of absolute preference values for this preference */
500  uc.kind = kind;
501  uc.pc = c;
502  c->f_abs_sum[kind] = 0.0;
503 
504  /* For all peers: calculate sum of absolute preferences */
507  &uc);
509  "Client has sum of total preferences for %s of %.3f\n",
511  c->f_abs_sum[kind]);
512 
513  /* For all peers: calculate relative preference */
516  &uc);
517 }
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...
Closure for update_rel_sum() and update_abs_sum().
static struct GNUNET_FS_UnindexContext * uc
enum GNUNET_ATS_PreferenceKind kind
Which kind are we updating?
const char * GNUNET_ATS_print_preference_type(enum GNUNET_ATS_PreferenceKind type)
Convert a enum GNUNET_ATS_PreferenceType to a string.
double f_abs_sum[GNUNET_ATS_PREFERENCE_END]
Array of sums of absolute preferences for all peers as expressed by this client.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
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...
#define LOG(kind,...)
struct GNUNET_CONTAINER_MultiPeerMap * peer2pref
Mapping peer identities to struct PreferencePeer entry for the respective peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_iterator()

static int update_iterator ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

The relative preferences of one of the clients have changed, update the global preferences for the given peer and notify the plugin.

Parameters
clsthe kind of preference to calculate the new global relative preference values for
keythe peer to update relative preference values for
valuea struct PeerRelative, unused

Definition at line 531 of file gnunet-service-ats_preferences.c.

References GNUNET_OK, UpdateContext::kind, and update_relative_values_for_peer().

Referenced by update_preference().

534 {
535  enum GNUNET_ATS_PreferenceKind *kind = cls;
536 
538  *kind);
539  return GNUNET_OK;
540 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
enum GNUNET_ATS_PreferenceKind kind
Which kind are we updating?
static void update_relative_values_for_peer(const struct GNUNET_PeerIdentity *id, enum GNUNET_ATS_PreferenceKind kind)
Update the total releative preference for a peer by summing up the relative preferences all clients h...
GNUNET_ATS_PreferenceKind
Enum defining all known preference categories.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_preference()

static void update_preference ( struct GNUNET_SERVICE_Client client,
const struct GNUNET_PeerIdentity peer,
enum GNUNET_ATS_PreferenceKind  kind,
float  score_abs 
)
static

Update the absolute preference and calculate the new relative preference value.

Parameters
clientthe client with this preference
peerthe peer to change the preference for
kindthe kind to change the preference
score_absthe normalized score

Definition at line 553 of file gnunet-service-ats_preferences.c.

References 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, PreferenceClient::peer2pref, PREF_AGING_INTERVAL, preference_aging(), recalculate_relative_preferences(), and update_iterator().

Referenced by GAS_handle_preference_change(), and set_pref_task().

557 {
558  struct PreferenceClient *c_cur;
559  struct PreferencePeer *p_cur;
560  struct PeerRelative *r_cur;
561  unsigned int i;
562 
563  if (kind >= GNUNET_ATS_PREFERENCE_END)
564  {
565  GNUNET_break (0);
566  return;
567  }
569  "Client changes preference for peer `%s' for `%s' to %.2f\n",
570  GNUNET_i2s (peer),
572  score_abs);
573 
574  /* Find preference client */
575  for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
576  if (client == c_cur->client)
577  break;
578  /* Not found: create new preference client */
579  if (NULL == c_cur)
580  {
581  c_cur = GNUNET_new (struct PreferenceClient);
582  c_cur->client = client;
584  GNUNET_NO);
585  for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
586  c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE;
588  pc_tail,
589  c_cur);
590  }
591 
592  /* check global peer entry exists */
593  if (NULL ==
595  peer)))
596  {
597  /* Create struct for peer */
598  r_cur = GNUNET_new (struct PeerRelative);
599  for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
600  r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
603  peer,
604  r_cur,
606  }
607 
608  /* Find entry for peer */
610  peer);
611  if (NULL == p_cur)
612  {
613  /* Not found: create new peer entry */
614  p_cur = GNUNET_new (struct PreferencePeer);
615  for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
616  {
617  /* Default value per peer absolute preference for a preference*/
618  p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE;
619  /* Default value per peer relative preference for a quality */
620  p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
621  }
624  peer,
625  p_cur,
627  r_cur->num_clients++;
628  }
629 
630  p_cur->f_abs[kind] += score_abs;
631  recalculate_relative_preferences (c_cur, kind);
634  &kind);
635 
636  if (NULL == aging_task)
639  NULL);
640 }
struct GNUNET_SERVICE_Client * client
Client handle.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct PreferenceClient * next
Next in client list.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
End of preference list.
double f_rel[GNUNET_ATS_PREFERENCE_END]
Relative preference values for all preference types, normalized in [0..1] based on how the respective...
static void recalculate_relative_preferences(struct PreferenceClient *c, enum GNUNET_ATS_PreferenceKind kind)
Recalculate preference for a specific ATS property.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
double f_rel[GNUNET_ATS_PREFERENCE_END]
Array of relative preference values, to be indexed by an enum GNUNET_ATS_PreferenceKind.
Preference client, as in a client that expressed preferences for peers.
const char * GNUNET_ATS_print_preference_type(enum GNUNET_ATS_PreferenceKind type)
Convert a enum GNUNET_ATS_PreferenceType to a string.
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 gi...
There must only be one value per key; storing a value should fail if a value under the same key alrea...
static struct GNUNET_CONTAINER_MultiPeerMap * preference_peers
Hashmap to store peer information for preference normalization.
Preference information per peer and client.
#define DEFAULT_REL_PREFERENCE
Default relative preference value we assume if we know nothing.
Relative preferences for a peer.
double f_abs_sum[GNUNET_ATS_PREFERENCE_END]
Array of sums of absolute preferences for all peers as expressed by this client.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_SCHEDULER_Task * aging_task
Handle for task we run periodically to age preferences over time.
#define PREF_AGING_INTERVAL
How frequently do we age preference values?
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
static void preference_aging(void *cls)
Reduce absolute preferences since they got old.
unsigned int num_clients
Number of clients that are expressing a preference for this peer.
static struct PreferenceClient * pc_tail
Clients in DLL: tail.
static struct PreferenceClient * pc_head
Clients in DLL: head.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define DEFAULT_ABS_PREFERENCE
Default preference value we assume if we know nothing.
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
double f_abs[GNUNET_ATS_PREFERENCE_END]
Absolute preference values for all preference types as expressed by this client for this peer...
struct GNUNET_CONTAINER_MultiPeerMap * peer2pref
Mapping peer identities to struct PreferencePeer entry for the respective peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_handle_preference_change()

void GAS_handle_preference_change ( struct GNUNET_SERVICE_Client client,
const struct ChangePreferenceMessage msg 
)

Handle 'preference change' messages from clients.

Parameters
clientthe client that sent the request
msgthe 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, ChangePreferenceMessage::num_preferences, ChangePreferenceMessage::peer, pi, PreferenceInformation::preference_kind, PreferenceInformation::preference_value, and update_preference().

Referenced by handle_preference_change().

652 {
653  const struct PreferenceInformation *pi;
654  uint32_t nump;
655 
656  nump = ntohl (msg->num_preferences);
658  "Received PREFERENCE_CHANGE message for peer `%s'\n",
659  GNUNET_i2s (&msg->peer));
661  "# preference change requests processed",
662  1,
663  GNUNET_NO);
664  pi = (const struct PreferenceInformation *) &msg[1];
666  for (uint32_t i = 0; i < nump; i++)
667  update_preference (client,
668  &msg->peer,
669  (enum GNUNET_ATS_PreferenceKind) ntohl (
670  pi[i].preference_kind),
671  pi[i].preference_value);
673 }
struct GNUNET_PeerIdentity peer
Which peer is the preference being expressed for?
Definition: ats.h:453
void GAS_plugin_solver_lock()
Stop instant solving, there are many state updates happening in bulk right now.
uint32_t preference_kind
An enum GNUNET_ATS_PreferenceKind in NBO.
Definition: ats.h:424
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
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.
struct GNUNET_STATISTICS_Handle * GSA_stats
Handle for statistics.
void GAS_plugin_solver_unlock()
Resume instant solving, we are done with the bulk state updates.
uint32_t num_preferences
How many struct PreferenceInformation entries follow this struct?
Definition: ats.h:448
#define GNUNET_log(kind,...)
Variable-size entry in a struct ChangePreferenceMessage or struct FeedbackPreferenceMessage.
Definition: ats.h:419
GNUNET_ATS_PreferenceKind
Enum defining all known preference categories.
float preference_value
Degree of preference (or appreciation) for this preference_kind being expressed.
Definition: ats.h:430
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_preference_init()

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(), and GNUNET_NO.

Referenced by run().

681 {
682  unsigned int i;
683 
685  GNUNET_NO);
686  for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
688 }
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
End of preference list.
double f_rel[GNUNET_ATS_PREFERENCE_END]
Array of relative preference values, to be indexed by an enum GNUNET_ATS_PreferenceKind.
static struct GNUNET_CONTAINER_MultiPeerMap * preference_peers
Hashmap to store peer information for preference normalization.
#define DEFAULT_REL_PREFERENCE
Default relative preference value we assume if we know nothing.
static struct PeerRelative defvalues
Default values, returned as our preferences if we do not have any preferences expressed for a peer...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_preference_done()

void GAS_preference_done ( void  )

Shutdown preferences subsystem.

Definition at line 695 of file gnunet-service-ats_preferences.c.

References free_peer(), free_preference(), GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_free, GNUNET_SCHEDULER_cancel(), PreferenceClient::next, pc, pc_head, and PreferenceClient::peer2pref.

Referenced by cleanup_task(), and run().

696 {
697  struct PreferenceClient *pc;
698  struct PreferenceClient *next_pc;
699 
700  if (NULL != aging_task)
701  {
703  aging_task = NULL;
704  }
705  next_pc = pc_head;
706  while (NULL != (pc = next_pc))
707  {
708  next_pc = pc->next;
710  pc_tail,
711  pc);
714  pc);
716  GNUNET_free (pc);
717  }
719  &free_peer,
720  NULL);
722 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct PreferenceClient * next
Next in client list.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
static int free_peer(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Free a peer&#39;s struct PeerRelative.
Preference client, as in a client that expressed preferences for peers.
static struct GNUNET_CONTAINER_MultiPeerMap * preference_peers
Hashmap to store peer information for preference normalization.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
static struct GNUNET_SCHEDULER_Task * aging_task
Handle for task we run periodically to age preferences over time.
static struct PreferenceClient * pc_tail
Clients in DLL: tail.
static int free_preference(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Free struct PreferencePeer entry in map.
static struct PreferenceClient * pc_head
Clients in DLL: head.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CONTAINER_MultiPeerMap * peer2pref
Mapping peer identities to struct PreferencePeer entry for the respective peer.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_preference_get_by_peer()

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.

Parameters
clsignored
idthe peer
Returns
pointer to the values, can be indexed with GNUNET_ATS_PreferenceKind, default preferences if peer does not exist

Definition at line 735 of file gnunet-service-ats_preferences.c.

References defvalues, PeerRelative::f_rel, GNUNET_CONTAINER_multipeermap_get(), and rp.

Referenced by GAS_plugin_init(), and get_preferences_cb().

737 {
738  struct PeerRelative *rp;
739 
740  if (NULL ==
742  id)))
743  {
744  return defvalues.f_rel;
745  }
746  return rp->f_rel;
747 }
double f_rel[GNUNET_ATS_PREFERENCE_END]
Array of relative preference values, to be indexed by an enum GNUNET_ATS_PreferenceKind.
static struct GNUNET_CONTAINER_MultiPeerMap * preference_peers
Hashmap to store peer information for preference normalization.
Relative preferences for a peer.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
static char * rp
Relying party.
static struct PeerRelative defvalues
Default values, returned as our preferences if we do not have any preferences expressed for a peer...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_preference_client_disconnect()

void GAS_preference_client_disconnect ( struct GNUNET_SERVICE_Client client)

A performance client disconnected.

Parameters
clientthe client

Definition at line 756 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, and PreferenceClient::peer2pref.

Referenced by client_disconnect_cb().

757 {
758  struct PreferenceClient *c_cur;
759 
760  for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
761  if (client == c_cur->client)
762  break;
763  if (NULL == c_cur)
764  return;
766  pc_tail,
767  c_cur);
770  c_cur);
772  GNUNET_free (c_cur);
773 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_SERVICE_Client * client
Client handle.
struct PreferenceClient * next
Next in client list.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
Preference client, as in a client that expressed preferences for peers.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct PreferenceClient * pc_tail
Clients in DLL: tail.
static int free_preference(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Free struct PreferencePeer entry in map.
static struct PreferenceClient * pc_head
Clients in DLL: head.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CONTAINER_MultiPeerMap * peer2pref
Mapping peer identities to struct PreferencePeer entry for the respective peer.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ defvalues

struct PeerRelative defvalues
static

Default values, returned as our preferences if we do not have any preferences expressed for a peer.

Definition at line 81 of file gnunet-service-ats_preferences.c.

Referenced by GAS_preference_get_by_peer(), and GAS_preference_init().

◆ preference_peers

struct GNUNET_CONTAINER_MultiPeerMap* preference_peers
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.

◆ pc_head

struct PreferenceClient* pc_head
static

Clients in DLL: head.

Definition at line 160 of file gnunet-service-ats_preferences.c.

Referenced by GAS_preference_done().

◆ pc_tail

struct PreferenceClient* pc_tail
static

Clients in DLL: tail.

Definition at line 165 of file gnunet-service-ats_preferences.c.

◆ aging_task

struct GNUNET_SCHEDULER_Task* aging_task
static

Handle for task we run periodically to age preferences over time.

Definition at line 170 of file gnunet-service-ats_preferences.c.