GNUnet  0.10.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 642 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().

644 {
645  const struct PreferenceInformation *pi;
646  uint32_t nump;
647 
648  nump = ntohl(msg->num_preferences);
650  "Received PREFERENCE_CHANGE message for peer `%s'\n",
651  GNUNET_i2s(&msg->peer));
653  "# preference change requests processed",
654  1,
655  GNUNET_NO);
656  pi = (const struct PreferenceInformation *)&msg[1];
658  for (uint32_t i = 0; i < nump; i++)
659  update_preference(client,
660  &msg->peer,
661  (enum GNUNET_ATS_PreferenceKind)ntohl(pi[i].preference_kind),
662  pi[i].preference_value);
664 }
struct GNUNET_PeerIdentity peer
Which peer is the preference being expressed for?
Definition: ats.h:440
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:412
#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:435
#define GNUNET_log(kind,...)
Variable-size entry in a struct ChangePreferenceMessage or struct FeedbackPreferenceMessage.
Definition: ats.h:408
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:418
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 671 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().

672 {
673  unsigned int i;
674 
676  GNUNET_NO);
677  for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
679 }
#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 686 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().

687 {
688  struct PreferenceClient *pc;
689  struct PreferenceClient *next_pc;
690 
691  if (NULL != aging_task)
692  {
694  aging_task = NULL;
695  }
696  next_pc = pc_head;
697  while (NULL != (pc = next_pc))
698  {
699  next_pc = pc->next;
701  pc_tail,
702  pc);
705  pc);
707  GNUNET_free(pc);
708  }
710  &free_peer,
711  NULL);
713 }
#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:956
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 726 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().

728 {
729  struct PeerRelative *rp;
730 
731  if (NULL ==
733  id)))
734  {
735  return defvalues.f_rel;
736  }
737  return rp->f_rel;
738 }
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 747 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().

748 {
749  struct PreferenceClient *c_cur;
750 
751  for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
752  if (client == c_cur->client)
753  break;
754  if (NULL == c_cur)
755  return;
757  pc_tail,
758  c_cur);
761  c_cur);
763  GNUNET_free(c_cur);
764 }
#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: