GNUnet  0.11.x
Macros | Functions
gnunet-service-ats_preferences.h File Reference

manage preferences expressed by clients More...

#include "gnunet_util_lib.h"
#include "gnunet_ats_service.h"
#include "gnunet-service-ats.h"
#include "gnunet_statistics_service.h"
#include "ats.h"
Include dependency graph for gnunet-service-ats_preferences.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DEFAULT_ABS_PREFERENCE   0.0
 Default preference value we assume if we know nothing. More...
 
#define DEFAULT_REL_PREFERENCE   0.0
 Default relative preference value we assume if we know nothing. More...
 

Functions

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 (void)
 Initialize preferences subsystem. More...
 
void GAS_preference_done (void)
 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. More...
 
void GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client)
 A performance client disconnected. More...
 

Detailed Description

manage preferences expressed by clients

Author
Matthias Wachs
Christian Grothoff

Definition in file gnunet-service-ats_preferences.h.

Macro Definition Documentation

◆ DEFAULT_ABS_PREFERENCE

#define DEFAULT_ABS_PREFERENCE   0.0

Default preference value we assume if we know nothing.

Definition at line 38 of file gnunet-service-ats_preferences.h.

Referenced by age_values(), enforce_add_address(), and update_preference().

◆ DEFAULT_REL_PREFERENCE

#define DEFAULT_REL_PREFERENCE   0.0

Default relative preference value we assume if we know nothing.

Definition at line 43 of file gnunet-service-ats_preferences.h.

Referenced by age_values(), enforce_add_address(), GAS_preference_init(), run(), and update_preference().

Function Documentation

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

Parameters
clsignored
idthe peer
Returns
pointer to the values, can be indexed with enum GNUNET_ATS_PreferenceKind, never NULL

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 disconnecting client
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: