GNUnet  0.19.5
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.

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

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.

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_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_STATISTICS_Handle * GSA_stats
Handle for statistics.
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
void GAS_plugin_solver_unlock()
Resume instant solving, we are done with the bulk state updates.
void GAS_plugin_solver_lock()
Stop instant solving, there are many state updates happening in bulk right now.
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.
GNUNET_ATS_PreferenceKind
Enum defining all known preference categories.
#define GNUNET_log(kind,...)
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
Variable-size entry in a struct ChangePreferenceMessage or struct FeedbackPreferenceMessage.
Definition: ats.h:420
uint32_t preference_kind
An enum GNUNET_ATS_PreferenceKind in NBO.
Definition: ats.h:424
float preference_value
Degree of preference (or appreciation) for this preference_kind being expressed.
Definition: ats.h:430

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

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.

681 {
682  unsigned int i;
683 
685  GNUNET_NO);
686  for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
688 }
static struct PeerRelative defvalues
Default values, returned as our preferences if we do not have any preferences expressed for a peer.
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.
@ GNUNET_ATS_PREFERENCE_END
End of preference list.
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).
double f_rel[GNUNET_ATS_PREFERENCE_END]
Array of relative preference values, to be indexed by an enum GNUNET_ATS_PreferenceKind.

References DEFAULT_REL_PREFERENCE, defvalues, PeerRelative::f_rel, GNUNET_ATS_PREFERENCE_END, GNUNET_CONTAINER_multipeermap_create(), GNUNET_NO, and preference_peers.

Referenced by run().

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.

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 }
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
static int free_peer(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Free a peer's struct PeerRelative.
static struct GNUNET_SCHEDULER_Task * aging_task
Handle for task we run periodically to age preferences over time.
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.
static struct PreferenceClient * pc_tail
Clients in DLL: tail.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash 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.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
Preference client, as in a client that expressed preferences for peers.

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

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.

737 {
738  struct PeerRelative *rp;
739 
740  if (NULL ==
742  id)))
743  {
744  return defvalues.f_rel;
745  }
746  return rp->f_rel;
747 }
static char * rp
Relying party.
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.
Relative preferences for a peer.

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

Referenced by GAS_plugin_init(), and get_preferences_cb().

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

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

752 {
753  struct PreferenceClient *c_cur;
754 
755  for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
756  if (client == c_cur->client)
757  break;
758  if (NULL == c_cur)
759  return;
761  pc_tail,
762  c_cur);
765  c_cur);
767  GNUNET_free (c_cur);
768 }
struct GNUNET_SERVICE_Client * client
Client handle.
struct PreferenceClient * next
Next in client list.
struct GNUNET_CONTAINER_MultiPeerMap * peer2pref
Mapping peer identities to struct PreferencePeer entry for the respective peer.

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

Here is the call graph for this function:
Here is the caller graph for this function: