GNUnet  0.10.x
Data Structures | Macros | Functions
ats_api_performance.c File Reference

automatic transport selection and outbound bandwidth determination More...

#include "platform.h"
#include "gnunet_ats_service.h"
#include "ats.h"
Include dependency graph for ats_api_performance.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_ATS_ReservationContext
 Linked list of pending reservations. More...
 
struct  GNUNET_ATS_AddressListHandle
 Linked list of pending reservations. More...
 
struct  GNUNET_ATS_PerformanceHandle
 ATS Handle to obtain and/or modify performance information. More...
 

Macros

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

Functions

static void reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
 Re-establish the connection to the ATS service. More...
 
static void reconnect_task (void *cls)
 Re-establish the connection to the ATS service. More...
 
static void do_reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
 Reconnect to the ATS service, something went wrong. More...
 
static int check_peer_information (void *cls, const struct PeerInformationMessage *pi)
 We received a peer information message. More...
 
static void handle_peer_information (void *cls, const struct PeerInformationMessage *pi)
 We received a peer information message. More...
 
static void handle_reservation_result (void *cls, const struct ReservationResultMessage *rr)
 We received a reservation result message. More...
 
static int check_address_list (void *cls, const struct PeerInformationMessage *pi)
 We received a PeerInformationMessage. More...
 
static void handle_address_list (void *cls, const struct PeerInformationMessage *pi)
 We received a GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
struct GNUNET_ATS_PerformanceHandleGNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ATS_AddressInformationCallback addr_info_cb, void *addr_info_cb_cls)
 Get handle to access performance API of the ATS subsystem. More...
 
void GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
 Client is done using the ATS performance subsystem, release resources. More...
 
struct GNUNET_ATS_ReservationContextGNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer, int32_t amount, GNUNET_ATS_ReservationCallback rcb, void *rcb_cls)
 Reserve inbound bandwidth from the given peer. More...
 
void GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc)
 Cancel request for reserving bandwidth. More...
 
struct GNUNET_ATS_AddressListHandleGNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer, int all, GNUNET_ATS_AddressInformationCallback infocb, void *infocb_cls)
 Get information about addresses known to the ATS subsystem. More...
 
void GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *alh)
 Cancel a pending address listing operation. More...
 
const char * GNUNET_ATS_print_preference_type (enum GNUNET_ATS_PreferenceKind type)
 Convert a enum GNUNET_ATS_PreferenceType to a string. More...
 
void GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer,...)
 Change preferences for the given peer. More...
 
void GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TIME_Relative scope,...)
 Send feedback to ATS on how good a the requirements for a peer and a preference is satisfied by ATS. More...
 

Detailed Description

automatic transport selection and outbound bandwidth determination

Author
Christian Grothoff
Matthias Wachs

Definition in file ats_api_performance.c.

Macro Definition Documentation

◆ LOG

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

Definition at line 31 of file ats_api_performance.c.

Referenced by handle_address_list().

Function Documentation

◆ reconnect()

static void reconnect ( struct GNUNET_ATS_PerformanceHandle ph)
static

Re-establish the connection to the ATS service.

Parameters
phhandle to use to re-connect.

Definition at line 560 of file ats_api_performance.c.

References GNUNET_ATS_PerformanceHandle::addr_info_cb, GNUNET_ATS_PerformanceHandle::cfg, env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE, GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION, GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT, GNUNET_MESSAGE_TYPE_ATS_START, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), init, GNUNET_ATS_PerformanceHandle::mq, mq_error_handler(), ClientStartMessage::start_flag, START_FLAG_PERFORMANCE_NO_PIC, and START_FLAG_PERFORMANCE_WITH_PIC.

Referenced by GNUNET_ATS_performance_init(), handle_reservation_result(), and reconnect_task().

561 {
563  GNUNET_MQ_hd_var_size(peer_information,
565  struct PeerInformationMessage,
566  ph),
567  GNUNET_MQ_hd_fixed_size(reservation_result,
570  ph),
571  GNUNET_MQ_hd_var_size(address_list,
573  struct PeerInformationMessage,
574  ph),
576  };
577  struct GNUNET_MQ_Envelope *env;
578  struct ClientStartMessage *init;
579 
580  GNUNET_assert(NULL == ph->mq);
581  ph->mq = GNUNET_CLIENT_connect(ph->cfg,
582  "ats",
583  handlers,
585  ph);
586  if (NULL == ph->mq)
587  return;
588  env = GNUNET_MQ_msg(init,
590  init->start_flag = htonl((NULL == ph->addr_info_cb)
593  GNUNET_MQ_send(ph->mq,
594  env);
595 }
#define GNUNET_MESSAGE_TYPE_ATS_START
Type of the 'struct ClientStartMessage' sent by clients to ATS to identify the type of the client...
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:900
uint32_t start_flag
NBO value of an enum StartFlag.
Definition: ats.h:77
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MQ_Handle * mq
Connection to ATS service.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
Performance monitoring client that does NOT want to learn about changes in performance characteristic...
Definition: ats.h:53
#define GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION
Type of the 'struct PeerInformationMessage' sent by ATS to clients to inform about QoS for a particul...
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
GNUNET_ATS_AddressInformationCallback addr_info_cb
Callback to invoke when an address has performance changes.
Message handler for a specific message type.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static char * init
Set to the name of a service to start.
Definition: gnunet-arm.c:69
#define GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE
Type of the 'struct AddressListResponseMessage' sent by ATS to client with information about addresse...
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:351
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
#define GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT
Type of the 'struct ReservationResultMessage' sent by ATS to clients in response to a reservation req...
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
First message any client sends to ATS, used to self-identify (what type of client this is)...
Definition: ats.h:68
Performance monitoring client that wants to learn about changes in performance characteristics.
Definition: ats.h:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconnect_task()

static void reconnect_task ( void *  cls)
static

Re-establish the connection to the ATS service.

Parameters
clshandle to use to re-connect.

Definition at line 221 of file ats_api_performance.c.

References ph, reconnect(), and GNUNET_ATS_PerformanceHandle::task.

Referenced by do_reconnect().

222 {
223  struct GNUNET_ATS_PerformanceHandle *ph = cls;
224 
225  ph->task = NULL;
226  reconnect(ph);
227 }
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
struct GNUNET_SCHEDULER_Task * task
Task to trigger reconnect.
ATS Handle to obtain and/or modify performance information.
static void reconnect(struct GNUNET_ATS_PerformanceHandle *ph)
Re-establish the connection to the ATS service.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_reconnect()

static void do_reconnect ( struct GNUNET_ATS_PerformanceHandle ph)
static

Reconnect to the ATS service, something went wrong.

Parameters
phhandle to reconnect

Definition at line 236 of file ats_api_performance.c.

References GNUNET_ATS_PerformanceHandle::addr_info_cb, GNUNET_ATS_PerformanceHandle::addr_info_cb_cls, GNUNET_ATS_PerformanceHandle::addresslist_head, GNUNET_ATS_PerformanceHandle::addresslist_tail, alh, GNUNET_ATS_PerformanceHandle::backoff, GNUNET_ATS_AddressListHandle::cb, GNUNET_ATS_AddressListHandle::cb_cls, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_ATS_PerformanceHandle::mq, GNUNET_ATS_ReservationContext::rcb, GNUNET_ATS_ReservationContext::rcb_cls, reconnect_task(), GNUNET_ATS_PerformanceHandle::reservation_head, GNUNET_ATS_PerformanceHandle::reservation_tail, GNUNET_ATS_PerformanceHandle::task, and GNUNET_BANDWIDTH_Value32NBO::value__.

Referenced by mq_error_handler().

237 {
240  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero;
241 
242  if (NULL != ph->mq)
243  {
244  GNUNET_MQ_destroy(ph->mq);
245  ph->mq = NULL;
246  }
247  while (NULL != (rc = ph->reservation_head))
248  {
250  ph->reservation_tail,
251  rc);
252  if (NULL != rc->rcb)
253  rc->rcb(rc->rcb_cls,
254  NULL,
255  0,
257  GNUNET_free(rc);
258  }
259  bandwidth_zero.value__ = htonl(0);
260  while (NULL != (alh = ph->addresslist_head))
261  {
263  ph->addresslist_tail,
264  alh);
265  if (NULL != alh->cb)
266  alh->cb(alh->cb_cls,
267  NULL,
268  GNUNET_NO,
269  bandwidth_zero,
270  bandwidth_zero,
271  NULL);
272  GNUNET_free(alh);
273  }
274  if (NULL != ph->addr_info_cb)
275  {
276  /* Indicate reconnect */
278  NULL,
279  GNUNET_NO,
280  bandwidth_zero,
281  bandwidth_zero,
282  NULL);
283  }
287  ph);
288 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_ATS_AddressListHandle * addresslist_tail
Tail of linked list of pending address list requests.
struct GNUNET_ATS_ReservationContext * reservation_tail
Tail of linked list of pending reservation requests.
struct GNUNET_ATS_AddressListHandle * addresslist_head
Head of linked list of pending address list requests.
GNUNET_ATS_ReservationCallback rcb
Function to call on result.
struct GNUNET_ATS_ReservationContext * reservation_head
Head of linked list of pending reservation requests.
struct GNUNET_MQ_Handle * mq
Connection to ATS service.
void * rcb_cls
Closure for rcb.
#define GNUNET_NO
Definition: gnunet_common.h:78
Linked list of pending reservations.
GNUNET_ATS_AddressInformationCallback cb
Callback.
static struct GNUNET_ATS_AddressListHandle * alh
ATS address list handle used.
Definition: gnunet-ats.c:131
struct GNUNET_SCHEDULER_Task * task
Task to trigger reconnect.
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:1237
GNUNET_ATS_AddressInformationCallback addr_info_cb
Callback to invoke when an address has performance changes.
void * cb_cls
Callback closure for cb.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
static void reconnect_task(void *cls)
Re-establish the connection to the ATS service.
struct GNUNET_TIME_Relative backoff
Reconnect backoff delay.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
void * addr_info_cb_cls
Closure for addr_info_cb.
#define GNUNET_free(ptr)
Wrapper around free.
Linked list of pending reservations.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_peer_information()

static int check_peer_information ( void *  cls,
const struct PeerInformationMessage pi 
)
static

We received a peer information message.

Validate and process it.

Parameters
clsour context with the callback
pithe message
Returns
GNUNET_OK if the message was well-formed

Definition at line 299 of file ats_api_performance.c.

References PeerInformationMessage::address_length, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, PeerInformationMessage::header, plugin_name, PeerInformationMessage::plugin_name_length, and GNUNET_MessageHeader::size.

301 {
302  const char *plugin_address;
303  const char *plugin_name;
304  uint16_t plugin_address_length;
305  uint16_t plugin_name_length;
306 
307  plugin_address_length = ntohs(pi->address_length);
308  plugin_name_length = ntohs(pi->plugin_name_length);
309  plugin_address = (const char *)&pi[1];
310  plugin_name = &plugin_address[plugin_address_length];
311  if ((plugin_address_length + plugin_name_length
312  + sizeof(struct PeerInformationMessage) != ntohs(pi->header.size)) ||
313  (plugin_name[plugin_name_length - 1] != '\0'))
314  {
315  GNUNET_break(0);
316  return GNUNET_SYSERR;
317  }
318  return GNUNET_OK;
319 }
uint16_t address_length
Definition: ats.h:280
uint16_t plugin_name_length
Definition: ats.h:285
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION.
Definition: ats.h:275
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char * plugin_name
Solver plugin name as string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76

◆ handle_peer_information()

static void handle_peer_information ( void *  cls,
const struct PeerInformationMessage pi 
)
static

We received a peer information message.

Validate and process it.

Parameters
clsour context with the callback
pithe message
Returns
GNUNET_OK if the message was well-formed

Definition at line 330 of file ats_api_performance.c.

References GNUNET_ATS_PerformanceHandle::addr_info_cb, GNUNET_ATS_PerformanceHandle::addr_info_cb_cls, GNUNET_HELLO_Address::address, PeerInformationMessage::address_active, GNUNET_HELLO_Address::address_length, PeerInformationMessage::address_length, PeerInformationMessage::address_local_info, PeerInformationMessage::bandwidth_in, PeerInformationMessage::bandwidth_out, GNUNET_ATS_properties_ntoh(), GNUNET_HELLO_Address::local_info, PeerInformationMessage::peer, GNUNET_HELLO_Address::peer, ph, plugin_name, PeerInformationMessage::properties, and GNUNET_HELLO_Address::transport_name.

332 {
333  struct GNUNET_ATS_PerformanceHandle *ph = cls;
334  const char *plugin_address;
335  const char *plugin_name;
337  uint16_t plugin_address_length;
338  int addr_active;
339  struct GNUNET_ATS_Properties prop;
340 
341  if (NULL == ph->addr_info_cb)
342  return;
343  plugin_address_length = ntohs(pi->address_length);
344  addr_active = (int)ntohl(pi->address_active);
345  plugin_address = (const char *)&pi[1];
346  plugin_name = &plugin_address[plugin_address_length];
347 
349  &pi->properties);
350  address.peer = pi->peer;
351  address.local_info = (enum GNUNET_HELLO_AddressInfo)ntohl(pi->address_local_info);
352  address.address = plugin_address;
353  address.address_length = plugin_address_length;
354  address.transport_name = plugin_name;
356  &address,
357  addr_active,
358  pi->bandwidth_out,
359  pi->bandwidth_in,
360  &prop);
361 }
uint16_t address_length
Definition: ats.h:280
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Definition: ats.h:310
uint32_t address_local_info
Local-only information of the address, see enum GNUNET_HELLO_AddressInfo.
Definition: ats.h:321
ATS performance characteristics for an address.
struct GNUNET_ATS_PropertiesNBO properties
Performance properties of the address.
Definition: ats.h:315
struct GNUNET_PeerIdentity peer
Definition: ats.h:290
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Definition: ats.h:305
GNUNET_ATS_AddressInformationCallback addr_info_cb
Callback to invoke when an address has performance changes.
static char * plugin_name
Solver plugin name as string.
ATS Handle to obtain and/or modify performance information.
void GNUNET_ATS_properties_ntoh(struct GNUNET_ATS_Properties *hbo, const struct GNUNET_ATS_PropertiesNBO *nbo)
Convert ATS properties from network to host byte order.
An address for communicating with a peer.
uint32_t address_active
Definition: ats.h:295
GNUNET_HELLO_AddressInfo
Additional local information about an address.
static char * address
GNS address for this phone.
void * addr_info_cb_cls
Closure for addr_info_cb.
Here is the call graph for this function:

◆ handle_reservation_result()

static void handle_reservation_result ( void *  cls,
const struct ReservationResultMessage rr 
)
static

We received a reservation result message.

Validate and process it.

Parameters
clsour context with the callback
rrthe message

Definition at line 371 of file ats_api_performance.c.

References ReservationResultMessage::amount, GNUNET_ATS_reserve_bandwidth(), GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_memcmp, GNUNET_TIME_relative_ntoh(), GNUNET_YES, GNUNET_ATS_ReservationContext::peer, ReservationResultMessage::peer, ph, GNUNET_ATS_ReservationContext::rcb, GNUNET_ATS_ReservationContext::rcb_cls, reconnect(), ReservationResultMessage::res_delay, GNUNET_ATS_PerformanceHandle::reservation_head, GNUNET_ATS_PerformanceHandle::reservation_tail, and GNUNET_ATS_ReservationContext::undo.

373 {
374  struct GNUNET_ATS_PerformanceHandle *ph = cls;
376  int32_t amount;
377 
378  amount = ntohl(rr->amount);
379  rc = ph->reservation_head;
380  if (0 != GNUNET_memcmp(&rr->peer,
381  &rc->peer))
382  {
383  GNUNET_break(0);
384  reconnect(ph);
385  return;
386  }
388  ph->reservation_tail,
389  rc);
390  if ((0 == amount) ||
391  (NULL != rc->rcb))
392  {
393  /* tell client if not cancelled */
394  if (NULL != rc->rcb)
395  rc->rcb(rc->rcb_cls,
396  &rr->peer,
397  amount,
399  GNUNET_free(rc);
400  return;
401  }
402  /* amount non-zero, but client cancelled, consider undo! */
403  if (GNUNET_YES != rc->undo)
404  {
405  GNUNET_free(rc);
406  return; /* do not try to undo failed undos or negative amounts */
407  }
408  GNUNET_free(rc);
410  &rr->peer,
411  -amount,
412  NULL, NULL);
413 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_ATS_ReservationContext * reservation_tail
Tail of linked list of pending reservation requests.
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
GNUNET_ATS_ReservationCallback rcb
Function to call on result.
struct GNUNET_ATS_ReservationContext * reservation_head
Head of linked list of pending reservation requests.
void * rcb_cls
Closure for rcb.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_PeerIdentity peer
Definition: ats.h:395
int undo
Do we need to undo this reservation if it succeeded? Set to GNUNET_YES if a reservation is cancelled...
struct GNUNET_ATS_ReservationContext * GNUNET_ATS_reserve_bandwidth(struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer, int32_t amount, GNUNET_ATS_ReservationCallback rcb, void *rcb_cls)
Reserve inbound bandwidth from the given peer.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:639
struct GNUNET_PeerIdentity peer
Target peer.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
ATS Handle to obtain and/or modify performance information.
static void reconnect(struct GNUNET_ATS_PerformanceHandle *ph)
Re-establish the connection to the ATS service.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TIME_RelativeNBO res_delay
Definition: ats.h:400
#define GNUNET_free(ptr)
Wrapper around free.
Linked list of pending reservations.
Here is the call graph for this function:

◆ check_address_list()

static int check_address_list ( void *  cls,
const struct PeerInformationMessage pi 
)
static

We received a PeerInformationMessage.

Validate it.

Parameters
clsour context with the callback
pithe message
Returns
GNUNET_OK if the message was well-formed

Definition at line 424 of file ats_api_performance.c.

References PeerInformationMessage::address_length, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, PeerInformationMessage::header, plugin_name, PeerInformationMessage::plugin_name_length, and GNUNET_MessageHeader::size.

426 {
427  const char *plugin_address;
428  const char *plugin_name;
429  uint16_t plugin_address_length;
430  uint16_t plugin_name_length;
431 
432  plugin_address_length = ntohs(pi->address_length);
433  plugin_name_length = ntohs(pi->plugin_name_length);
434  plugin_address = (const char *)&pi[1];
435  plugin_name = &plugin_address[plugin_address_length];
436  if ((plugin_address_length + plugin_name_length
437  + sizeof(struct PeerInformationMessage) != ntohs(pi->header.size)) ||
438  (plugin_name[plugin_name_length - 1] != '\0'))
439  {
440  GNUNET_break(0);
441  return GNUNET_SYSERR;
442  }
443  return GNUNET_OK;
444 }
uint16_t address_length
Definition: ats.h:280
uint16_t plugin_name_length
Definition: ats.h:285
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION.
Definition: ats.h:275
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char * plugin_name
Solver plugin name as string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76

◆ handle_address_list()

static void handle_address_list ( void *  cls,
const struct PeerInformationMessage pi 
)
static

We received a GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE.

Process it.

Parameters
clsour context with the callback
pithe message

Definition at line 455 of file ats_api_performance.c.

References GNUNET_HELLO_Address::address, PeerInformationMessage::address_active, GNUNET_HELLO_Address::address_length, PeerInformationMessage::address_length, GNUNET_ATS_PerformanceHandle::addresslist_head, GNUNET_ATS_PerformanceHandle::addresslist_tail, alh, GNUNET_ATS_AddressListHandle::all_addresses, PeerInformationMessage::bandwidth_in, PeerInformationMessage::bandwidth_out, GNUNET_ATS_AddressListHandle::cb, GNUNET_ATS_AddressListHandle::cb_cls, GNUNET_ATS_properties_ntoh(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_is_zero, GNUNET_NO, GNUNET_YES, GNUNET_ATS_AddressListHandle::id, id, PeerInformationMessage::id, LOG, GNUNET_ATS_ReservationContext::next, GNUNET_ATS_AddressListHandle::next, PeerInformationMessage::peer, GNUNET_HELLO_Address::peer, ph, plugin_name, PeerInformationMessage::plugin_name_length, PeerInformationMessage::properties, GNUNET_HELLO_Address::transport_name, and GNUNET_BANDWIDTH_Value32NBO::value__.

457 {
458  struct GNUNET_ATS_PerformanceHandle *ph = cls;
461  const char *plugin_address;
462  const char *plugin_name;
464  struct GNUNET_PeerIdentity allzeros;
465  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero;
466  struct GNUNET_ATS_Properties prop;
467  uint16_t plugin_address_length;
468  uint16_t plugin_name_length;
469  uint32_t active;
470  uint32_t id;
471 
472  id = ntohl(pi->id);
473  active = ntohl(pi->address_active);
474  plugin_address_length = ntohs(pi->address_length);
475  plugin_name_length = ntohs(pi->plugin_name_length);
476  plugin_address = (const char *)&pi[1];
477  plugin_name = &plugin_address[plugin_address_length];
479  "Received ATS_ADDRESSLIST_RESPONSE message for peer %s and plugin %s\n",
480  GNUNET_i2s(&pi->peer),
481  plugin_name);
482 
483  next = ph->addresslist_head;
484  while (NULL != (alh = next))
485  {
486  next = alh->next;
487  if (alh->id == id)
488  break;
489  }
490  if (NULL == alh)
491  return; /* was canceled */
492 
493  memset(&allzeros, '\0', sizeof(allzeros));
494  if ((0 == GNUNET_is_zero(&pi->peer)) &&
495  (0 == plugin_name_length) &&
496  (0 == plugin_address_length))
497  {
498  /* Done */
500  "Received last message for ATS_ADDRESSLIST_RESPONSE\n");
501  bandwidth_zero.value__ = htonl(0);
503  ph->addresslist_tail,
504  alh);
505  if (NULL != alh->cb)
506  alh->cb(alh->cb_cls,
507  NULL,
508  GNUNET_NO,
509  bandwidth_zero,
510  bandwidth_zero,
511  NULL);
512  GNUNET_free(alh);
513  return;
514  }
515 
516  address.peer = pi->peer;
517  address.address = plugin_address;
518  address.address_length = plugin_address_length;
519  address.transport_name = plugin_name;
520  if (((GNUNET_YES == alh->all_addresses) ||
521  (GNUNET_YES == active)) &&
522  (NULL != alh->cb))
523  {
525  &pi->properties);
526  alh->cb(alh->cb_cls,
527  &address,
528  active,
529  pi->bandwidth_out,
530  pi->bandwidth_in,
531  &prop);
532  }
533 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_ATS_AddressListHandle * addresslist_tail
Tail of linked list of pending address list requests.
uint16_t address_length
Definition: ats.h:280
int all_addresses
Return all or used address only.
struct GNUNET_ATS_AddressListHandle * addresslist_head
Head of linked list of pending address list requests.
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Definition: ats.h:310
uint16_t plugin_name_length
Definition: ats.h:285
#define GNUNET_NO
Definition: gnunet_common.h:78
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
struct GNUNET_ATS_AddressListHandle * next
Kept in a DLL.
ATS performance characteristics for an address.
struct GNUNET_ATS_PropertiesNBO properties
Performance properties of the address.
Definition: ats.h:315
struct GNUNET_PeerIdentity peer
Definition: ats.h:290
Linked list of pending reservations.
GNUNET_ATS_AddressInformationCallback cb
Callback.
static struct GNUNET_ATS_AddressListHandle * alh
ATS address list handle used.
Definition: gnunet-ats.c:131
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Definition: ats.h:305
void * cb_cls
Callback closure for cb.
#define LOG(kind,...)
static char * plugin_name
Solver plugin name as string.
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
#define GNUNET_is_zero(a)
Check that memory in a is all zeros.
ATS Handle to obtain and/or modify performance information.
uint32_t id
Request multiplexing.
The identity of the host (wraps the signing key of the peer).
void GNUNET_ATS_properties_ntoh(struct GNUNET_ATS_Properties *hbo, const struct GNUNET_ATS_PropertiesNBO *nbo)
Convert ATS properties from network to host byte order.
An address for communicating with a peer.
#define GNUNET_YES
Definition: gnunet_common.h:77
uint32_t address_active
Definition: ats.h:295
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_ATS_PerformanceHandle *
errorerror code

Definition at line 545 of file ats_api_performance.c.

References do_reconnect(), and ph.

Referenced by reconnect().

547 {
548  struct GNUNET_ATS_PerformanceHandle *ph = cls;
549 
550  do_reconnect(ph);
551 }
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
static void do_reconnect(struct GNUNET_ATS_PerformanceHandle *ph)
Reconnect to the ATS service, something went wrong.
ATS Handle to obtain and/or modify performance information.
Here is the call graph for this function:
Here is the caller graph for this function: