GNUnet  0.19.4
gnunet-service-ats_performance.c File Reference

ats service, interaction with 'performance' API More...

Include dependency graph for gnunet-service-ats_performance.c:

Go to the source code of this file.

Functions

static void notify_client (struct GNUNET_SERVICE_Client *client, const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, int active, const struct GNUNET_ATS_Properties *prop, enum GNUNET_HELLO_AddressInfo local_address_info, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 Transmit the given performance information to all performance clients. More...
 
void GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, int active, const struct GNUNET_ATS_Properties *prop, enum GNUNET_HELLO_AddressInfo local_address_info, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 Transmit the given performance information to all performance clients. More...
 
static void peerinfo_it (void *cls, const struct GNUNET_PeerIdentity *id, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, int active, const struct GNUNET_ATS_Properties *prop, enum GNUNET_HELLO_AddressInfo local_address_info, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
 Iterator for called from GAS_addresses_get_peer_info() More...
 
void GAS_performance_add_client (struct GNUNET_SERVICE_Client *client, enum StartFlag flag)
 Register a new performance client. More...
 
void GAS_performance_init ()
 Initialize performance subsystem. More...
 
void GAS_performance_done ()
 Shutdown performance subsystem. More...
 

Variables

static struct GNUNET_NotificationContextnc_no_pic
 Context for sending messages to performance clients without PIC. More...
 
static struct GNUNET_NotificationContextnc_pic
 Context for sending messages to performance clients with PIC. More...
 

Detailed Description

ats service, interaction with 'performance' API

Author
Matthias Wachs
Christian Grothoff

TODO:

Definition in file gnunet-service-ats_performance.c.

Function Documentation

◆ notify_client()

static void notify_client ( struct GNUNET_SERVICE_Client client,
const struct GNUNET_PeerIdentity peer,
const char *  plugin_name,
const void *  plugin_addr,
size_t  plugin_addr_len,
int  active,
const struct GNUNET_ATS_Properties prop,
enum GNUNET_HELLO_AddressInfo  local_address_info,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_out,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_in 
)
static

Transmit the given performance information to all performance clients.

Parameters
clientclient to send to, NULL for all
peerpeer for which this is an address suggestion
plugin_name0-termintated string specifying the transport plugin
plugin_addrbinary address for the plugin to use
plugin_addr_lennumber of bytes in plugin_addr
activeGNUNET_YES if this address is actively used to maintain a connection to a peer; GNUNET_NO if the address is not actively used; GNUNET_SYSERR if this address is no longer available for ATS
propperformance data for the address
local_address_infoinformation about the local flags for the address
bandwidth_outassigned outbound bandwidth
bandwidth_inassigned inbound bandwidth

Definition at line 66 of file gnunet-service-ats_performance.c.

76 {
78  size_t plugin_name_length = strlen (plugin_name) + 1;
79  size_t msize =
80  sizeof(struct PeerInformationMessage)
81  + plugin_addr_len
83  char buf[msize] GNUNET_ALIGN;
84  char *addrp;
85 
86  if (NULL != prop)
89  msg = (struct PeerInformationMessage *) buf;
90  msg->header.size = htons (msize);
92  msg->id = htonl (0);
93  msg->peer = *peer;
94  msg->address_length = htons (plugin_addr_len);
95  msg->address_active = ntohl ((uint32_t) active);
96  msg->plugin_name_length = htons (plugin_name_length);
97  msg->bandwidth_out = bandwidth_out;
98  msg->bandwidth_in = bandwidth_in;
99  if (NULL != prop)
100  GNUNET_ATS_properties_hton (&msg->properties,
101  prop);
102  else
103  memset (&msg->properties,
104  0,
105  sizeof(struct GNUNET_ATS_Properties));
106  msg->address_local_info = htonl (local_address_info);
107  addrp = (char *) &msg[1];
108  GNUNET_memcpy (addrp, plugin_addr, plugin_addr_len);
109  strcpy (&addrp[plugin_addr_len], plugin_name);
110  if (NULL == client)
111  {
113  &msg->header,
114  GNUNET_YES);
115  }
116  else
117  {
118  struct GNUNET_MQ_Envelope *env;
119 
120  env = GNUNET_MQ_msg_copy (&msg->header);
122  env);
123  }
124 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_NotificationContext * nc_pic
Context for sending messages to performance clients with PIC.
static char * plugin_name
Name of our plugin.
static char buf[2048]
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
void GNUNET_ATS_properties_hton(struct GNUNET_ATS_PropertiesNBO *nbo, const struct GNUNET_ATS_Properties *hbo)
Convert ATS properties from host to network byte order.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
void GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, const struct GNUNET_MessageHeader *msg, int can_drop)
Send a message to all subscribers of this context.
Definition: nc.c:190
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:533
@ GNUNET_NT_UNSPECIFIED
Category of last resort.
Definition: gnunet_nt_lib.h:43
#define GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION
Type of the 'struct PeerInformationMessage' sent by ATS to clients to inform about QoS for a particul...
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2443
ATS performance characteristics for an address.
enum GNUNET_NetworkType scope
Which network scope does the respective address belong to? This property does not change.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Definition: ats.h:318
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Definition: ats.h:313
uint16_t plugin_name_length
Definition: ats.h:293
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.

References PeerInformationMessage::bandwidth_in, PeerInformationMessage::bandwidth_out, buf, env, GNUNET_ALIGN, GNUNET_assert, GNUNET_ATS_properties_hton(), GNUNET_break, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION, GNUNET_MQ_msg_copy(), GNUNET_MQ_send(), GNUNET_notification_context_broadcast(), GNUNET_NT_UNSPECIFIED, GNUNET_SERVICE_client_get_mq(), GNUNET_YES, msg, nc_pic, peer, plugin_name, PeerInformationMessage::plugin_name_length, GNUNET_ATS_Properties::scope, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by GAS_performance_notify_all_clients(), and peerinfo_it().

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

◆ GAS_performance_notify_all_clients()

void GAS_performance_notify_all_clients ( const struct GNUNET_PeerIdentity peer,
const char *  plugin_name,
const void *  plugin_addr,
size_t  plugin_addr_len,
int  active,
const struct GNUNET_ATS_Properties prop,
enum GNUNET_HELLO_AddressInfo  local_address_info,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_out,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_in 
)

Transmit the given performance information to all performance clients.

Parameters
peerpeer for which this is an address suggestion
plugin_name0-termintated string specifying the transport plugin
plugin_addrbinary address for the plugin to use
plugin_addr_lennumber of bytes in plugin_addr
activeGNUNET_YES if this address is actively used to maintain a connection to a peer; GNUNET_NO if the address is not actively used; GNUNET_SYSERR if this address is no longer available for ATS
propperformance data for the address
local_address_infoinformation about the local flags for the address
bandwidth_outassigned outbound bandwidth
bandwidth_inassigned inbound bandwidth

Definition at line 145 of file gnunet-service-ats_performance.c.

157 {
158  GNUNET_break ((NULL == prop) ||
159  (GNUNET_NT_UNSPECIFIED != prop->scope));
160  notify_client (NULL,
161  peer,
162  plugin_name,
163  plugin_addr,
164  plugin_addr_len,
165  active,
166  prop,
167  local_address_info,
168  bandwidth_out,
169  bandwidth_in);
171  "# performance updates given to clients",
172  1,
173  GNUNET_NO);
174 }
struct GNUNET_STATISTICS_Handle * GSA_stats
Handle for statistics.
static void notify_client(struct GNUNET_SERVICE_Client *client, const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, int active, const struct GNUNET_ATS_Properties *prop, enum GNUNET_HELLO_AddressInfo local_address_info, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
Transmit the given performance information to all performance clients.
@ GNUNET_NO
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.

References GNUNET_break, GNUNET_NO, GNUNET_NT_UNSPECIFIED, GNUNET_STATISTICS_update(), GSA_stats, notify_client(), peer, plugin_name, and GNUNET_ATS_Properties::scope.

Referenced by bandwidth_changed_cb(), free_address(), GAS_addresses_add(), and GAS_addresses_update().

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

◆ peerinfo_it()

static void peerinfo_it ( void *  cls,
const struct GNUNET_PeerIdentity id,
const char *  plugin_name,
const void *  plugin_addr,
size_t  plugin_addr_len,
int  active,
const struct GNUNET_ATS_Properties prop,
enum GNUNET_HELLO_AddressInfo  local_address_info,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_out,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_in 
)
static

Iterator for called from GAS_addresses_get_peer_info()

Parameters
clsclosure with the struct GNUNET_SERVICE_Client * to inform.
idthe peer id
plugin_nameplugin name
plugin_addraddress
plugin_addr_lenlength of plugin_addr
activeis address actively used
propperformance information
local_address_infoinformation about the local flags for the address
bandwidth_outcurrent outbound bandwidth assigned to address
bandwidth_incurrent inbound bandwidth assigned to address

Definition at line 192 of file gnunet-service-ats_performance.c.

202 {
203  struct GNUNET_SERVICE_Client *client = cls;
204 
205  if (NULL == id)
206  return;
208  "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n",
209  GNUNET_i2s (id),
210  plugin_name,
211  (unsigned int) ntohl (bandwidth_out.value__),
212  (unsigned int) ntohl (bandwidth_in.value__));
214  notify_client (client,
215  id,
216  plugin_name,
217  plugin_addr,
218  plugin_addr_len,
219  active,
220  prop,
221  local_address_info,
222  bandwidth_out,
223  bandwidth_in);
224 }
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
uint32_t value__
The actual value (bytes per second).
Handle to a client that is connected to a service.
Definition: service.c:252

References GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NT_UNSPECIFIED, notify_client(), plugin_name, GNUNET_ATS_Properties::scope, and GNUNET_BANDWIDTH_Value32NBO::value__.

Referenced by GAS_performance_add_client().

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

◆ GAS_performance_add_client()

void GAS_performance_add_client ( struct GNUNET_SERVICE_Client client,
enum StartFlag  flag 
)

Register a new performance client.

Parameters
clienthandle of the new client
flagflag specifying the type of the client

Definition at line 234 of file gnunet-service-ats_performance.c.

236 {
237  struct GNUNET_MQ_Handle *mq;
238 
239  mq = GNUNET_SERVICE_client_get_mq (client);
241  {
243  mq);
245  &peerinfo_it,
246  client);
247  }
248  else
249  {
251  mq);
252  }
253 }
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
@ START_FLAG_PERFORMANCE_WITH_PIC
Performance monitoring client that wants to learn about changes in performance characteristics.
Definition: ats.h:48
void GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it, void *pi_it_cls)
Return information all peers currently known to ATS.
static void peerinfo_it(void *cls, const struct GNUNET_PeerIdentity *id, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, int active, const struct GNUNET_ATS_Properties *prop, enum GNUNET_HELLO_AddressInfo local_address_info, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
Iterator for called from GAS_addresses_get_peer_info()
static struct GNUNET_NotificationContext * nc_no_pic
Context for sending messages to performance clients without PIC.
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
Definition: nc.c:161
Handle to a message queue.
Definition: mq.c:87

References GAS_addresses_get_peer_info(), GNUNET_notification_context_add(), GNUNET_SERVICE_client_get_mq(), mq, nc_no_pic, nc_pic, peerinfo_it(), and START_FLAG_PERFORMANCE_WITH_PIC.

Referenced by handle_ats_start().

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

◆ GAS_performance_init()

void GAS_performance_init ( void  )

Initialize performance subsystem.

Parameters
serverhandle to our server

Definition at line 262 of file gnunet-service-ats_performance.c.

263 {
266 }
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
Definition: nc.c:122

References GNUNET_notification_context_create(), nc_no_pic, and nc_pic.

Referenced by run().

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

◆ GAS_performance_done()

void GAS_performance_done ( void  )

Shutdown performance subsystem.

Definition at line 273 of file gnunet-service-ats_performance.c.

274 {
276  nc_no_pic = NULL;
278  nc_pic = NULL;
279 }
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
Definition: nc.c:138

References GNUNET_notification_context_destroy(), nc_no_pic, and nc_pic.

Referenced by cleanup_task().

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

Variable Documentation

◆ nc_no_pic

struct GNUNET_NotificationContext* nc_no_pic
static

Context for sending messages to performance clients without PIC.

Definition at line 39 of file gnunet-service-ats_performance.c.

Referenced by GAS_performance_add_client(), GAS_performance_done(), and GAS_performance_init().

◆ nc_pic

struct GNUNET_NotificationContext* nc_pic
static

Context for sending messages to performance clients with PIC.

Definition at line 44 of file gnunet-service-ats_performance.c.

Referenced by GAS_performance_add_client(), GAS_performance_done(), GAS_performance_init(), and notify_client().