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

API of the statistics service. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_statistics_service.h"
#include "statistics.h"
Include dependency graph for statistics_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_STATISTICS_WatchEntry
 Entry kept for each value we are watching. More...
 
struct  GNUNET_STATISTICS_GetHandle
 Linked list of things we still need to do. More...
 
struct  GNUNET_STATISTICS_Handle
 Handle for the service. More...
 

Macros

#define SET_TRANSMIT_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
 How long do we wait until a statistics request for setting a value times out? (The update will be lost if the service does not react within this timeframe). More...
 
#define LOG(kind, ...)   GNUNET_log_from (kind, "statistics-api",__VA_ARGS__)
 

Enumerations

enum  ActionType { ACTION_GET, ACTION_SET, ACTION_UPDATE, ACTION_WATCH }
 Types of actions. More...
 

Functions

static void update_memory_statistics (struct GNUNET_STATISTICS_Handle *h)
 Obtain statistics about this process's memory consumption and report those as well (if they changed). More...
 
static void reconnect_later (struct GNUNET_STATISTICS_Handle *h)
 Reconnect at a later time, respecting back-off. More...
 
static void schedule_action (void *cls)
 Schedule the next action to be performed. More...
 
static void schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, struct GNUNET_STATISTICS_WatchEntry *watch)
 Transmit request to service that we want to watch the development of a particular value. More...
 
static void free_action_item (struct GNUNET_STATISTICS_GetHandle *gh)
 Free memory associated with the given action item. More...
 
static void do_disconnect (struct GNUNET_STATISTICS_Handle *h)
 Disconnect from the statistics service. More...
 
static int check_statistics_value (void *cls, const struct GNUNET_STATISTICS_ReplyMessage *smsg)
 Process a GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message. More...
 
static void handle_statistics_value (void *cls, const struct GNUNET_STATISTICS_ReplyMessage *smsg)
 Process a GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message. More...
 
static void handle_statistics_watch_value (void *cls, const struct GNUNET_STATISTICS_WatchValueMessage *wvm)
 We have received a watch value from the service. 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...
 
static void do_destroy (void *cls)
 Task used to destroy the statistics handle. More...
 
static void handle_disconnect_confirm (void *cls, const struct GNUNET_MessageHeader *msg)
 Handle a GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM message. More...
 
static void handle_statistics_end (void *cls, const struct GNUNET_MessageHeader *msg)
 Handle a GNUNET_MESSAGE_TYPE_STATISTICS_END message. More...
 
static int try_connect (struct GNUNET_STATISTICS_Handle *h)
 Try to (re)connect to the statistics service. More...
 
static void reconnect_task (void *cls)
 We've waited long enough, reconnect now. More...
 
static void transmit_get (struct GNUNET_STATISTICS_Handle *handle)
 Transmit a GET request (and if successful, start to receive the response). More...
 
static void transmit_watch (struct GNUNET_STATISTICS_Handle *handle)
 Transmit a WATCH request (and if successful, start to receive the response). More...
 
static void transmit_set (struct GNUNET_STATISTICS_Handle *handle)
 Transmit a SET/UPDATE request. More...
 
struct GNUNET_STATISTICS_HandleGNUNET_STATISTICS_create (const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Get handle for the statistics service. More...
 
void GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first)
 Destroy a handle (free all state associated with it). More...
 
struct GNUNET_STATISTICS_GetHandleGNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, const char *subsystem, const char *name, GNUNET_STATISTICS_Callback cont, GNUNET_STATISTICS_Iterator proc, void *cls)
 Get statistic from the peer. More...
 
void GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
 Cancel a 'get' request. More...
 
int GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, const char *subsystem, const char *name, GNUNET_STATISTICS_Iterator proc, void *proc_cls)
 Watch statistics from the peer (be notified whenever they change). More...
 
int GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle, const char *subsystem, const char *name, GNUNET_STATISTICS_Iterator proc, void *proc_cls)
 Stop watching statistics from the peer. More...
 
static void add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, int make_persistent, uint64_t value, enum ActionType type)
 Queue a request to change a statistic. More...
 
void GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
 Set statistic value for the peer. More...
 
void GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
 Set statistic value for the peer. More...
 

Detailed Description

API of the statistics service.

Author
Christian Grothoff

Definition in file statistics_api.c.

Macro Definition Documentation

◆ SET_TRANSMIT_TIMEOUT

#define SET_TRANSMIT_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)

How long do we wait until a statistics request for setting a value times out? (The update will be lost if the service does not react within this timeframe).

Definition at line 38 of file statistics_api.c.

Referenced by add_setter_action().

◆ LOG

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

Enumeration Type Documentation

◆ ActionType

enum ActionType

Types of actions.

Enumerator
ACTION_GET 

Get a value.

ACTION_SET 

Set a value.

ACTION_UPDATE 

Update a value.

ACTION_WATCH 

Watch a value.

Definition at line 45 of file statistics_api.c.

46 {
50  ACTION_GET,
51 
55  ACTION_SET,
56 
61 
66 };
Watch a value.
Update a value.
Get a value.
Set a value.

Function Documentation

◆ update_memory_statistics()

static void update_memory_statistics ( struct GNUNET_STATISTICS_Handle h)
static

Obtain statistics about this process's memory consumption and report those as well (if they changed).

Definition at line 269 of file statistics_api.c.

References GNUNET_STATISTICS_Handle::do_destroy, GNUNET_NO, GNUNET_STATISTICS_set(), h, GNUNET_STATISTICS_Handle::peak_heap_size, GNUNET_STATISTICS_Handle::peak_rss, reconnect_later(), and schedule_action().

Referenced by transmit_set().

270 {
271 #if ENABLE_HEAP_STATISTICS
272  uint64_t current_heap_size = 0;
273  uint64_t current_rss = 0;
274 
275  if (GNUNET_NO != h->do_destroy)
276  return;
277 #if HAVE_MALLINFO
278  {
279  struct mallinfo mi;
280 
281  mi = mallinfo();
282  current_heap_size = mi.uordblks + mi.fordblks;
283  }
284 #endif
285 #if HAVE_GETRUSAGE
286  {
287  struct rusage ru;
288 
289  if (0 == getrusage (RUSAGE_SELF, &ru))
290  {
291  current_rss = 1024LL * ru.ru_maxrss;
292  }
293  }
294 #endif
295  if (current_heap_size > h->peak_heap_size)
296  {
297  h->peak_heap_size = current_heap_size;
299  "# peak heap size",
300  current_heap_size,
301  GNUNET_NO);
302  }
303  if (current_rss > h->peak_rss)
304  {
305  h->peak_rss = current_rss;
307  "# peak resident set size",
308  current_rss,
309  GNUNET_NO);
310  }
311 #endif
312 }
int do_destroy
Should this handle auto-destruct once all actions have been processed?
#define GNUNET_NO
Definition: gnunet_common.h:81
uint64_t peak_rss
Maximum resident set side observed so far (if available).
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
uint64_t peak_heap_size
Maximum heap size observed so far (if available).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconnect_later()

static void reconnect_later ( struct GNUNET_STATISTICS_Handle h)
static

Reconnect at a later time, respecting back-off.

Parameters
hstatistics handle

Definition at line 733 of file statistics_api.c.

References _, GNUNET_STATISTICS_Handle::action_head, ACTION_SET, GNUNET_STATISTICS_Handle::backoff, GNUNET_STATISTICS_Handle::backoff_task, GNUNET_STATISTICS_Handle::destroy_task, GNUNET_STATISTICS_Handle::do_destroy, do_destroy(), gh, GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, GNUNET_STATISTICS_GetHandle::make_persistent, GNUNET_STATISTICS_GetHandle::next, reconnect_task(), and GNUNET_STATISTICS_GetHandle::type.

Referenced by handle_disconnect_confirm(), handle_statistics_end(), handle_statistics_watch_value(), mq_error_handler(), schedule_action(), and update_memory_statistics().

734 {
735  int loss;
737 
738  GNUNET_assert (NULL == h->backoff_task);
739  if (GNUNET_YES == h->do_destroy)
740  {
741  /* So we are shutting down and the service is not reachable.
742  * Chances are that it's down for good and we are not going to connect to
743  * it anymore.
744  * Give up and don't sync the rest of the data.
745  */
746  loss = GNUNET_NO;
747  for (gh = h->action_head; NULL != gh; gh = gh->next)
748  if ( (gh->make_persistent) &&
749  (ACTION_SET == gh->type) )
750  loss = GNUNET_YES;
751  if (GNUNET_YES == loss)
753  _("Could not save some persistent statistics\n"));
754  if (NULL != h->destroy_task)
757  h);
758  return;
759  }
760  h->backoff_task
763  h);
765 }
int do_destroy
Should this handle auto-destruct once all actions have been processed?
int make_persistent
Flag for SET/UPDATE actions.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum ActionType type
Is this a ACTION_GET, ACTION_SET, ACTION_UPDATE or ACTION_WATCH?
Linked list of things we still need to do.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_TIME_Relative backoff
Time for next connect retry.
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:1246
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
struct GNUNET_SCHEDULER_Task * backoff_task
Task doing exponential back-off trying to reconnect.
static void reconnect_task(void *cls)
We've waited long enough, reconnect now.
static void do_destroy(void *cls)
Task used to destroy the statistics handle.
struct GNUNET_SCHEDULER_Task * destroy_task
Task for running do_destroy().
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Set a value.
static struct GNUNET_TRANSPORT_HelloGetHandle * gh
Pending GNUNET_TRANSPORT_hello_get() operation.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_STATISTICS_GetHandle * next
This is a doubly linked list.
struct GNUNET_STATISTICS_GetHandle * action_head
Head of the linked list of pending actions (first action to be performed).
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedule_action()

static void schedule_action ( void *  cls)
static

Schedule the next action to be performed.

Parameters
clsstatistics handle to reconnect
clsstatistics handle

Definition at line 1006 of file statistics_api.c.

References ACTION_GET, GNUNET_STATISTICS_Handle::action_head, ACTION_SET, GNUNET_STATISTICS_Handle::action_tail, ACTION_UPDATE, ACTION_WATCH, GNUNET_STATISTICS_Handle::backoff_task, GNUNET_STATISTICS_Handle::current, GNUNET_STATISTICS_Handle::do_destroy, env, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT, GNUNET_MQ_get_length(), GNUNET_MQ_msg, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_SYSERR, GNUNET_YES, GNUNET_STATISTICS_Handle::mq, reconnect_later(), transmit_get(), transmit_set(), transmit_watch(), try_connect(), and GNUNET_STATISTICS_GetHandle::type.

Referenced by add_setter_action(), GNUNET_STATISTICS_destroy(), GNUNET_STATISTICS_get(), handle_statistics_end(), reconnect_task(), schedule_watch_request(), transmit_get(), transmit_set(), transmit_watch(), and update_memory_statistics().

1007 {
1008  struct GNUNET_STATISTICS_Handle *h = cls;
1009 
1010  if (NULL != h->backoff_task)
1011  return; /* action already pending */
1012  if (GNUNET_YES != try_connect (h))
1013  {
1014  reconnect_later (h);
1015  return;
1016  }
1017  if (0 < GNUNET_MQ_get_length (h->mq))
1018  return; /* Wait for queue to be reduced more */
1019  /* schedule next action */
1020  while (NULL == h->current)
1021  {
1022  h->current = h->action_head;
1023  if (NULL == h->current)
1024  {
1025  struct GNUNET_MessageHeader *hdr;
1026  struct GNUNET_MQ_Envelope *env;
1027 
1028  if (GNUNET_YES != h->do_destroy)
1029  return; /* nothing to do */
1030  /* let service know that we're done */
1032  "Notifying service that we are done\n");
1033  h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */
1034  env = GNUNET_MQ_msg (hdr,
1036  GNUNET_MQ_notify_sent (env,
1037  &schedule_action,
1038  h);
1039  GNUNET_MQ_send (h->mq,
1040  env);
1041  return;
1042  }
1044  h->action_tail,
1045  h->current);
1046  switch (h->current->type)
1047  {
1048  case ACTION_GET:
1049  transmit_get (h);
1050  break;
1051  case ACTION_SET:
1052  case ACTION_UPDATE:
1053  transmit_set (h);
1054  break;
1055  case ACTION_WATCH:
1056  transmit_watch (h);
1057  break;
1058  default:
1059  GNUNET_assert (0);
1060  break;
1061  }
1062  }
1063 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int do_destroy
Should this handle auto-destruct once all actions have been processed?
static void reconnect_later(struct GNUNET_STATISTICS_Handle *h)
Reconnect at a later time, respecting back-off.
static void transmit_set(struct GNUNET_STATISTICS_Handle *handle)
Transmit a SET/UPDATE request.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum ActionType type
Is this a ACTION_GET, ACTION_SET, ACTION_UPDATE or ACTION_WATCH?
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
Handle for the service.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
Watch a value.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:335
struct GNUNET_SCHEDULER_Task * backoff_task
Task doing exponential back-off trying to reconnect.
static int try_connect(struct GNUNET_STATISTICS_Handle *h)
Try to (re)connect to the statistics service.
#define GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT
Client is done sending service requests and will now disconnect.
struct GNUNET_STATISTICS_GetHandle * action_tail
Tail of the linked list of actions (for fast append).
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_MQ_Handle * mq
Message queue to the service.
Update a value.
Get a value.
static void transmit_get(struct GNUNET_STATISTICS_Handle *handle)
Transmit a GET request (and if successful, start to receive the response).
Set a value.
static void schedule_action(void *cls)
Schedule the next action to be performed.
#define GNUNET_log(kind,...)
struct GNUNET_STATISTICS_GetHandle * current
Action we are currently busy with (action request has been transmitted, we&#39;re now receiving the respo...
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:80
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:353
static void transmit_watch(struct GNUNET_STATISTICS_Handle *handle)
Transmit a WATCH request (and if successful, start to receive the response).
struct GNUNET_STATISTICS_GetHandle * action_head
Head of the linked list of pending actions (first action to be performed).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedule_watch_request()

static void schedule_watch_request ( struct GNUNET_STATISTICS_Handle h,
struct GNUNET_STATISTICS_WatchEntry watch 
)
static

Transmit request to service that we want to watch the development of a particular value.

Parameters
hstatistics handle
watchwatch entry of the value to watch

Definition at line 341 of file statistics_api.c.

References GNUNET_STATISTICS_Handle::action_head, GNUNET_STATISTICS_Handle::action_tail, ACTION_WATCH, ai, GNUNET_STATISTICS_GetHandle::cls, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_MAX_MESSAGE_SIZE, GNUNET_new, GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_ABS, h, GNUNET_STATISTICS_GetHandle::msize, GNUNET_STATISTICS_WatchEntry::name, GNUNET_STATISTICS_GetHandle::name, GNUNET_STATISTICS_WatchEntry::proc, GNUNET_STATISTICS_GetHandle::proc, GNUNET_STATISTICS_WatchEntry::proc_cls, schedule_action(), GNUNET_STATISTICS_GetHandle::sh, GNUNET_STATISTICS_WatchEntry::subsystem, GNUNET_STATISTICS_GetHandle::subsystem, GNUNET_STATISTICS_GetHandle::timeout, and GNUNET_STATISTICS_GetHandle::type.

Referenced by GNUNET_STATISTICS_watch(), and try_connect().

343 {
345  size_t slen;
346  size_t nlen;
347  size_t nsize;
348 
349  slen = strlen (watch->subsystem) + 1;
350  nlen = strlen (watch->name) + 1;
351  nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen;
352  if (nsize >= GNUNET_MAX_MESSAGE_SIZE)
353  {
354  GNUNET_break (0);
355  return;
356  }
358  ai->sh = h;
359  ai->subsystem = GNUNET_strdup (watch->subsystem);
360  ai->name = GNUNET_strdup (watch->name);
362  ai->msize = nsize;
363  ai->type = ACTION_WATCH;
364  ai->proc = watch->proc;
365  ai->cls = watch->proc_cls;
367  h->action_tail,
368  ai);
369  schedule_action (h);
370 }
char * name
What value is this action about? (can be NULL)
void * proc_cls
Closure for proc.
GNUNET_STATISTICS_Iterator proc
Function to call (for GET actions only).
char * subsystem
What subsystem is this action about? (can be NULL)
enum ActionType type
Is this a ACTION_GET, ACTION_SET, ACTION_UPDATE or ACTION_WATCH?
char * name
What value is this action about? (never NULL)
Linked list of things we still need to do.
uint16_t msize
Size of the message that we will be transmitting.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Absolute timeout
Timeout for this action.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
Watch a value.
GNUNET_STATISTICS_Iterator proc
Function to call.
struct GNUNET_STATISTICS_GetHandle * action_tail
Tail of the linked list of actions (for fast append).
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct GNUNET_STATISTICS_Handle * sh
Main statistics handle.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
static void schedule_action(void *cls)
Schedule the next action to be performed.
void * cls
Closure for proc and cont.
Header for all communications.
char * subsystem
What subsystem is this action about? (never NULL)
struct GNUNET_STATISTICS_GetHandle * action_head
Head of the linked list of pending actions (first action to be performed).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_action_item()

static void free_action_item ( struct GNUNET_STATISTICS_GetHandle gh)
static

Free memory associated with the given action item.

Parameters
ghaction item to free

Definition at line 379 of file statistics_api.c.

References GNUNET_free, GNUNET_free_non_null, GNUNET_STATISTICS_GetHandle::name, and GNUNET_STATISTICS_GetHandle::subsystem.

Referenced by do_disconnect(), GNUNET_STATISTICS_destroy(), handle_statistics_end(), transmit_set(), transmit_watch(), and try_connect().

380 {
383  GNUNET_free (gh);
384 }
char * name
What value is this action about? (can be NULL)
char * subsystem
What subsystem is this action about? (can be NULL)
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ do_disconnect()

static void do_disconnect ( struct GNUNET_STATISTICS_Handle h)
static

Disconnect from the statistics service.

Parameters
hstatistics handle to disconnect from

Definition at line 393 of file statistics_api.c.

References GNUNET_STATISTICS_GetHandle::aborted, GNUNET_STATISTICS_GetHandle::cls, GNUNET_STATISTICS_GetHandle::cont, GNUNET_STATISTICS_Handle::current, free_action_item(), GNUNET_MQ_destroy(), GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, GNUNET_STATISTICS_Handle::mq, and GNUNET_STATISTICS_Handle::receiving.

Referenced by GNUNET_STATISTICS_destroy(), handle_disconnect_confirm(), handle_statistics_end(), handle_statistics_watch_value(), and mq_error_handler().

394 {
395  struct GNUNET_STATISTICS_GetHandle *c;
396 
397  h->receiving = GNUNET_NO;
398  if (NULL != (c = h->current))
399  {
400  h->current = NULL;
401  if ( (NULL != c->cont) &&
402  (GNUNET_YES != c->aborted) )
403  {
404  c->cont (c->cls,
405  GNUNET_SYSERR);
406  c->cont = NULL;
407  }
408  free_action_item (c);
409  }
410  if (NULL != h->mq)
411  {
412  GNUNET_MQ_destroy (h->mq);
413  h->mq = NULL;
414  }
415 }
int receiving
Are we currently receiving from the service?
Linked list of things we still need to do.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
GNUNET_STATISTICS_Callback cont
Continuation to call once action is complete.
struct GNUNET_MQ_Handle * mq
Message queue to the service.
void * cls
Closure for proc and cont.
struct GNUNET_STATISTICS_GetHandle * current
Action we are currently busy with (action request has been transmitted, we&#39;re now receiving the respo...
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_YES
Definition: gnunet_common.h:80
static void free_action_item(struct GNUNET_STATISTICS_GetHandle *gh)
Free memory associated with the given action item.
int aborted
Has the current iteration been aborted; for GET actions.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_statistics_value()

static int check_statistics_value ( void *  cls,
const struct GNUNET_STATISTICS_ReplyMessage smsg 
)
static

Process a GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message.

Parameters
clsstatistics handle
smsgmessage received from the service, never NULL
Returns
GNUNET_OK if the message was well-formed

Definition at line 426 of file statistics_api.c.

References GNUNET_break, GNUNET_OK, GNUNET_STRINGS_buffer_tokenize(), GNUNET_SYSERR, GNUNET_STATISTICS_ReplyMessage::header, GNUNET_STATISTICS_WatchEntry::name, service, size, and GNUNET_MessageHeader::size.

428 {
429  const char *service;
430  const char *name;
431  uint16_t size;
432 
433  size = ntohs (smsg->header.size);
434  size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage);
435  if (size !=
436  GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1],
437  size,
438  2,
439  &service,
440  &name))
441  {
442  GNUNET_break (0);
443  return GNUNET_SYSERR;
444  }
445  return GNUNET_OK;
446 }
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_STATISTICS_VALUE.
Definition: statistics.h:45
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
Statistics message.
Definition: statistics.h:40
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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...
unsigned int GNUNET_STRINGS_buffer_tokenize(const char *buffer, size_t size, unsigned int count,...)
Given a buffer of a given size, find "count" 0-terminated strings in the buffer and assign the count ...
Definition: strings.c:136
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static unsigned int size
Size of the "table".
Definition: peer.c:67
const char * name
Here is the call graph for this function:

◆ handle_statistics_value()

static void handle_statistics_value ( void *  cls,
const struct GNUNET_STATISTICS_ReplyMessage smsg 
)
static

Process a GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message.

Parameters
clsstatistics handle
msgmessage received from the service, never NULL
Returns
GNUNET_OK if the message was well-formed

Definition at line 457 of file statistics_api.c.

References GNUNET_STATISTICS_GetHandle::aborted, GNUNET_STATISTICS_GetHandle::cls, GNUNET_STATISTICS_Handle::current, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ntohll(), GNUNET_OK, GNUNET_STATISTICS_PERSIST_BIT, GNUNET_STRINGS_buffer_tokenize(), GNUNET_YES, GNUNET_STATISTICS_ReplyMessage::header, LOG, GNUNET_STATISTICS_WatchEntry::name, GNUNET_STATISTICS_GetHandle::proc, service, size, and GNUNET_MessageHeader::size.

459 {
460  struct GNUNET_STATISTICS_Handle *h = cls;
461  const char *service;
462  const char *name;
463  uint16_t size;
464 
465  if (h->current->aborted)
466  return; /* iteration aborted, don't bother */
467 
468  size = ntohs (smsg->header.size);
469  size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage);
470  GNUNET_assert (size ==
471  GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1],
472  size,
473  2,
474  &service,
475  &name));
477  "Received valid statistic on `%s:%s': %llu\n",
478  service, name,
479  GNUNET_ntohll (smsg->value));
480  if (GNUNET_OK !=
481  h->current->proc (h->current->cls,
482  service,
483  name,
484  GNUNET_ntohll (smsg->value),
485  0 !=
486  (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT)))
487  {
489  "Processing of remaining statistics aborted by client.\n");
490  h->current->aborted = GNUNET_YES;
491  }
492 }
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_STATISTICS_VALUE.
Definition: statistics.h:45
#define LOG(kind,...)
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
GNUNET_STATISTICS_Iterator proc
Function to call (for GET actions only).
Statistics message.
Definition: statistics.h:40
uint32_t uid
Unique numerical identifier for the value (will not change during the same client-session).
Definition: statistics.h:53
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
Handle for the service.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
unsigned int GNUNET_STRINGS_buffer_tokenize(const char *buffer, size_t size, unsigned int count,...)
Given a buffer of a given size, find "count" 0-terminated strings in the buffer and assign the count ...
Definition: strings.c:136
static unsigned int size
Size of the "table".
Definition: peer.c:67
const char * name
#define GNUNET_STATISTICS_PERSIST_BIT
Flag for the struct GNUNET_STATISTICS_ReplyMessage UID only.
Definition: statistics.h:66
void * cls
Closure for proc and cont.
struct GNUNET_STATISTICS_GetHandle * current
Action we are currently busy with (action request has been transmitted, we&#39;re now receiving the respo...
#define GNUNET_YES
Definition: gnunet_common.h:80
uint64_t value
The value.
Definition: statistics.h:58
int aborted
Has the current iteration been aborted; for GET actions.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
Here is the call graph for this function:

◆ handle_statistics_watch_value()

static void handle_statistics_watch_value ( void *  cls,
const struct GNUNET_STATISTICS_WatchValueMessage wvm 
)
static

We have received a watch value from the service.

Process it.

Parameters
clsstatistics handle
msgthe watch value message

Definition at line 502 of file statistics_api.c.

References do_disconnect(), GNUNET_STATISTICS_WatchValueMessage::flags, GNUNET_break, GNUNET_ntohll(), GNUNET_STATISTICS_PERSIST_BIT, GNUNET_STATISTICS_WatchEntry::name, GNUNET_STATISTICS_WatchEntry::proc, GNUNET_STATISTICS_WatchEntry::proc_cls, reconnect_later(), GNUNET_STATISTICS_WatchValueMessage::reserved, GNUNET_STATISTICS_WatchEntry::subsystem, GNUNET_STATISTICS_WatchValueMessage::value, GNUNET_STATISTICS_Handle::watches, GNUNET_STATISTICS_Handle::watches_size, and GNUNET_STATISTICS_WatchValueMessage::wid.

504 {
505  struct GNUNET_STATISTICS_Handle *h = cls;
507  uint32_t wid;
508 
509  GNUNET_break (0 == ntohl (wvm->reserved));
510  wid = ntohl (wvm->wid);
511  if (wid >= h->watches_size)
512  {
513  do_disconnect (h);
514  reconnect_later (h);
515  return;
516  }
517  w = h->watches[wid];
518  if (NULL == w)
519  return;
520  (void) w->proc (w->proc_cls,
521  w->subsystem,
522  w->name,
523  GNUNET_ntohll (wvm->value),
524  0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
525 }
static void reconnect_later(struct GNUNET_STATISTICS_Handle *h)
Reconnect at a later time, respecting back-off.
struct GNUNET_STATISTICS_WatchEntry ** watches
Array of watch entries.
void * proc_cls
Closure for proc.
static void do_disconnect(struct GNUNET_STATISTICS_Handle *h)
Disconnect from the statistics service.
char * name
What value is this action about? (never NULL)
uint32_t flags
0 for absolute value, 1 for relative value; 2 to make persistent (see GNUNET_STATISTICS_SETFLAG_*).
Definition: statistics.h:128
uint32_t reserved
Reserved (always 0).
Definition: statistics.h:141
Handle for the service.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
GNUNET_STATISTICS_Iterator proc
Function to call.
uint32_t wid
Unique watch identification number (watch requests are enumerated in the order they are received...
Definition: statistics.h:136
#define GNUNET_STATISTICS_PERSIST_BIT
Flag for the struct GNUNET_STATISTICS_ReplyMessage UID only.
Definition: statistics.h:66
unsigned int watches_size
Size of the watches array.
Entry kept for each value we are watching.
char * subsystem
What subsystem is this action about? (never NULL)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
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_STATISTICS_Handle *
errorerror code

Definition at line 537 of file statistics_api.c.

References GNUNET_STATISTICS_Handle::destroy_task, GNUNET_STATISTICS_Handle::do_destroy, do_disconnect(), GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), and reconnect_later().

Referenced by try_connect().

539 {
540  struct GNUNET_STATISTICS_Handle *h = cls;
541 
542  if (GNUNET_NO != h->do_destroy)
543  {
544  h->do_destroy = GNUNET_NO;
545  if (NULL != h->destroy_task)
546  {
548  h->destroy_task = NULL;
549  }
551  GNUNET_NO);
552  return;
553  }
554  do_disconnect (h);
555  reconnect_later (h);
556 }
int do_destroy
Should this handle auto-destruct once all actions have been processed?
static void reconnect_later(struct GNUNET_STATISTICS_Handle *h)
Reconnect at a later time, respecting back-off.
static void do_disconnect(struct GNUNET_STATISTICS_Handle *h)
Disconnect from the statistics service.
#define GNUNET_NO
Definition: gnunet_common.h:81
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
Handle for the service.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
struct GNUNET_SCHEDULER_Task * destroy_task
Task for running do_destroy().
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_destroy()

static void do_destroy ( void *  cls)
static

Task used to destroy the statistics handle.

Parameters
clsthe struct GNUNET_STATISTICS_Handle

Definition at line 565 of file statistics_api.c.

References GNUNET_STATISTICS_Handle::destroy_task, GNUNET_STATISTICS_Handle::do_destroy, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_STATISTICS_destroy(), and LOG.

Referenced by GNUNET_STATISTICS_destroy(), handle_disconnect_confirm(), and reconnect_later().

566 {
567  struct GNUNET_STATISTICS_Handle *h = cls;
568 
569  h->destroy_task = NULL;
570  h->do_destroy = GNUNET_NO;
572  "Running final destruction\n");
574  GNUNET_NO);
575 }
int do_destroy
Should this handle auto-destruct once all actions have been processed?
#define LOG(kind,...)
#define GNUNET_NO
Definition: gnunet_common.h:81
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
Handle for the service.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
struct GNUNET_SCHEDULER_Task * destroy_task
Task for running do_destroy().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_disconnect_confirm()

static void handle_disconnect_confirm ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Handle a GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM message.

We receive this message at the end of the shutdown when the service confirms that all data has been written to disk.

Parameters
clsour struct GNUNET_STATISTICS_Handle *
msgthe message

Definition at line 587 of file statistics_api.c.

References GNUNET_STATISTICS_Handle::destroy_task, GNUNET_STATISTICS_Handle::do_destroy, do_destroy(), do_disconnect(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, LOG, and reconnect_later().

589 {
590  struct GNUNET_STATISTICS_Handle *h = cls;
591 
592  if (GNUNET_SYSERR != h->do_destroy)
593  {
594  /* not in shutdown, why do we get 'TEST'? */
595  GNUNET_break (0);
596  do_disconnect (h);
597  reconnect_later (h);
598  return;
599  }
601  "Received DISCONNNECT_CONFIRM message from statistics, can complete disconnect\n");
602  if (NULL != h->destroy_task)
605  h);
606 }
int do_destroy
Should this handle auto-destruct once all actions have been processed?
#define LOG(kind,...)
static void reconnect_later(struct GNUNET_STATISTICS_Handle *h)
Reconnect at a later time, respecting back-off.
static void do_disconnect(struct GNUNET_STATISTICS_Handle *h)
Disconnect from the statistics service.
Handle for the service.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static void do_destroy(void *cls)
Task used to destroy the statistics handle.
struct GNUNET_SCHEDULER_Task * destroy_task
Task for running do_destroy().
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:

◆ handle_statistics_end()

static void handle_statistics_end ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Handle a GNUNET_MESSAGE_TYPE_STATISTICS_END message.

We receive this message in response to a query to indicate that there are no further matching results.

Parameters
clsour struct GNUNET_STATISTICS_Handle *
msgthe message

Definition at line 618 of file statistics_api.c.

References GNUNET_STATISTICS_Handle::backoff, GNUNET_STATISTICS_GetHandle::cls, GNUNET_STATISTICS_GetHandle::cont, GNUNET_STATISTICS_Handle::current, do_disconnect(), free_action_item(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, GNUNET_TIME_UNIT_MILLISECONDS, LOG, reconnect_later(), and schedule_action().

620 {
621  struct GNUNET_STATISTICS_Handle *h = cls;
622  struct GNUNET_STATISTICS_GetHandle *c;
623 
625  "Received end of statistics marker\n");
626  if (NULL == (c = h->current))
627  {
628  GNUNET_break (0);
629  do_disconnect (h);
630  reconnect_later (h);
631  return;
632  }
634  h->current = NULL;
635  schedule_action (h);
636  if (NULL != c->cont)
637  {
638  c->cont (c->cls,
639  GNUNET_OK);
640  c->cont = NULL;
641  }
642  free_action_item (c);
643 }
#define LOG(kind,...)
static void reconnect_later(struct GNUNET_STATISTICS_Handle *h)
Reconnect at a later time, respecting back-off.
static void do_disconnect(struct GNUNET_STATISTICS_Handle *h)
Disconnect from the statistics service.
Linked list of things we still need to do.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Handle for the service.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
struct GNUNET_TIME_Relative backoff
Time for next connect retry.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
GNUNET_STATISTICS_Callback cont
Continuation to call once action is complete.
static void schedule_action(void *cls)
Schedule the next action to be performed.
void * cls
Closure for proc and cont.
struct GNUNET_STATISTICS_GetHandle * current
Action we are currently busy with (action request has been transmitted, we&#39;re now receiving the respo...
static void free_action_item(struct GNUNET_STATISTICS_GetHandle *gh)
Free memory associated with the given action item.
Here is the call graph for this function:

◆ try_connect()

static int try_connect ( struct GNUNET_STATISTICS_Handle h)
static

Try to (re)connect to the statistics service.

Parameters
hstatistics handle to reconnect
Returns
GNUNET_YES on success, GNUNET_NO on failure.

Definition at line 653 of file statistics_api.c.

References GNUNET_STATISTICS_Handle::action_head, GNUNET_STATISTICS_Handle::action_tail, ACTION_WATCH, GNUNET_STATISTICS_Handle::backoff_task, GNUNET_STATISTICS_Handle::cfg, free_action_item(), gh, GNUNET_CLIENT_connect(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM, GNUNET_MESSAGE_TYPE_STATISTICS_END, GNUNET_MESSAGE_TYPE_STATISTICS_VALUE, GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_YES, LOG, GNUNET_STATISTICS_Handle::mq, mq_error_handler(), GNUNET_STATISTICS_GetHandle::next, schedule_watch_request(), GNUNET_STATISTICS_GetHandle::type, GNUNET_STATISTICS_Handle::watches, and GNUNET_STATISTICS_Handle::watches_size.

Referenced by schedule_action().

654 {
656  GNUNET_MQ_hd_fixed_size (disconnect_confirm,
658  struct GNUNET_MessageHeader,
659  h),
660  GNUNET_MQ_hd_fixed_size (statistics_end,
662  struct GNUNET_MessageHeader,
663  h),
664  GNUNET_MQ_hd_var_size (statistics_value,
667  h),
668  GNUNET_MQ_hd_fixed_size (statistics_watch_value,
671  h),
673  };
675  struct GNUNET_STATISTICS_GetHandle *gn;
676 
677  if (NULL != h->backoff_task)
678  return GNUNET_NO;
679  if (NULL != h->mq)
680  return GNUNET_YES;
681  h->mq = GNUNET_CLIENT_connect (h->cfg,
682  "statistics",
683  handlers,
685  h);
686  if (NULL == h->mq)
687  {
689  "Failed to connect to statistics service!\n");
690  return GNUNET_NO;
691  }
692  gn = h->action_head;
693  while (NULL != (gh = gn))
694  {
695  gn = gh->next;
696  if (gh->type == ACTION_WATCH)
697  {
699  h->action_tail,
700  gh);
701  free_action_item (gh);
702  }
703  }
704  for (unsigned int i = 0; i < h->watches_size; i++)
705  if (NULL != h->watches[i])
707  h->watches[i]);
708  return GNUNET_YES;
709 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
#define LOG(kind,...)
struct GNUNET_STATISTICS_WatchEntry ** watches
Array of watch entries.
#define GNUNET_MESSAGE_TYPE_STATISTICS_END
Response to a STATISTICS_GET message (end of value stream).
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:901
Statistics message.
Definition: statistics.h:40
enum ActionType type
Is this a ACTION_GET, ACTION_SET, ACTION_UPDATE or ACTION_WATCH?
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
Linked list of things we still need to do.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_MESSAGE_TYPE_STATISTICS_VALUE
Response to a STATISTICS_GET message (with value).
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...
Message transmitted if a watched value changes.
Definition: statistics.h:117
Watch a value.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM
Service confirms disconnect and that it is done processing all requests from the client.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE
Changes to a watched value.
struct GNUNET_SCHEDULER_Task * backoff_task
Task doing exponential back-off trying to reconnect.
Message handler for a specific message type.
struct GNUNET_STATISTICS_GetHandle * action_tail
Tail of the linked list of actions (for fast append).
struct GNUNET_MQ_Handle * mq
Message queue to the service.
static struct GNUNET_TRANSPORT_HelloGetHandle * gh
Pending GNUNET_TRANSPORT_hello_get() operation.
static void schedule_watch_request(struct GNUNET_STATISTICS_Handle *h, struct GNUNET_STATISTICS_WatchEntry *watch)
Transmit request to service that we want to watch the development of a particular value...
Header for all communications.
unsigned int watches_size
Size of the watches array.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_STATISTICS_GetHandle * next
This is a doubly linked list.
static void free_action_item(struct GNUNET_STATISTICS_GetHandle *gh)
Free memory associated with the given action item.
struct GNUNET_STATISTICS_GetHandle * action_head
Head of the linked list of pending actions (first action to be performed).
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
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

We've waited long enough, reconnect now.

Parameters
clsthe struct GNUNET_STATISTICS_Handle to reconnect

Definition at line 718 of file statistics_api.c.

References GNUNET_STATISTICS_Handle::backoff_task, and schedule_action().

Referenced by reconnect_later().

719 {
720  struct GNUNET_STATISTICS_Handle *h = cls;
721 
722  h->backoff_task = NULL;
723  schedule_action (h);
724 }
Handle for the service.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
struct GNUNET_SCHEDULER_Task * backoff_task
Task doing exponential back-off trying to reconnect.
static void schedule_action(void *cls)
Schedule the next action to be performed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_get()

static void transmit_get ( struct GNUNET_STATISTICS_Handle handle)
static

Transmit a GET request (and if successful, start to receive the response).

Parameters
handlestatistics handle

Definition at line 776 of file statistics_api.c.

References GNUNET_STATISTICS_Handle::current, env, GNUNET_assert, GNUNET_MESSAGE_TYPE_STATISTICS_GET, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_STRINGS_buffer_fill(), GNUNET_STATISTICS_Handle::mq, GNUNET_STATISTICS_GetHandle::name, schedule_action(), and GNUNET_STATISTICS_GetHandle::subsystem.

Referenced by schedule_action().

777 {
778  struct GNUNET_STATISTICS_GetHandle *c;
779  struct GNUNET_MessageHeader *hdr;
780  struct GNUNET_MQ_Envelope *env;
781  size_t slen1;
782  size_t slen2;
783 
784  GNUNET_assert (NULL != (c = handle->current));
785  slen1 = strlen (c->subsystem) + 1;
786  slen2 = strlen (c->name) + 1;
787  env = GNUNET_MQ_msg_extra (hdr,
788  slen1 + slen2,
790  GNUNET_assert (slen1 + slen2 ==
791  GNUNET_STRINGS_buffer_fill ((char *) &hdr[1],
792  slen1 + slen2,
793  2,
794  c->subsystem,
795  c->name));
798  handle);
799  GNUNET_MQ_send (handle->mq,
800  env);
801 }
char * name
What value is this action about? (can be NULL)
char * subsystem
What subsystem is this action about? (can be NULL)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Linked list of things we still need to do.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
#define GNUNET_MESSAGE_TYPE_STATISTICS_GET
Get a statistical value(s).
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
size_t GNUNET_STRINGS_buffer_fill(char *buffer, size_t size, unsigned int count,...)
Fill a buffer of the given size with count 0-terminated strings (given as varargs).
Definition: strings.c:64
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_MQ_Handle * mq
Message queue to the service.
static void schedule_action(void *cls)
Schedule the next action to be performed.
struct GNUNET_STATISTICS_GetHandle * current
Action we are currently busy with (action request has been transmitted, we&#39;re now receiving the respo...
Header for all communications.
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:353
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_watch()

static void transmit_watch ( struct GNUNET_STATISTICS_Handle handle)
static

Transmit a WATCH request (and if successful, start to receive the response).

Parameters
handlestatistics handle

Definition at line 811 of file statistics_api.c.

References GNUNET_STATISTICS_GetHandle::cont, GNUNET_STATISTICS_Handle::current, env, free_action_item(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_STATISTICS_WATCH, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_STRINGS_buffer_fill(), LOG, GNUNET_STATISTICS_Handle::mq, GNUNET_STATISTICS_GetHandle::name, schedule_action(), and GNUNET_STATISTICS_GetHandle::subsystem.

Referenced by schedule_action().

812 {
813  struct GNUNET_MessageHeader *hdr;
814  struct GNUNET_MQ_Envelope *env;
815  size_t slen1;
816  size_t slen2;
817 
819  "Transmitting watch request for `%s'\n",
820  handle->current->name);
821  slen1 = strlen (handle->current->subsystem) + 1;
822  slen2 = strlen (handle->current->name) + 1;
823  env = GNUNET_MQ_msg_extra (hdr,
824  slen1 + slen2,
826  GNUNET_assert (slen1 + slen2 ==
827  GNUNET_STRINGS_buffer_fill ((char *) &hdr[1],
828  slen1 + slen2,
829  2,
830  handle->current->subsystem,
831  handle->current->name));
834  handle);
835  GNUNET_MQ_send (handle->mq,
836  env);
837  GNUNET_assert (NULL == handle->current->cont);
838  free_action_item (handle->current);
839  handle->current = NULL;
840  schedule_action (handle);
841 }
char * name
What value is this action about? (can be NULL)
#define LOG(kind,...)
#define GNUNET_MESSAGE_TYPE_STATISTICS_WATCH
Watch changes to a statistical value.
char * subsystem
What subsystem is this action about? (can be NULL)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
size_t GNUNET_STRINGS_buffer_fill(char *buffer, size_t size, unsigned int count,...)
Fill a buffer of the given size with count 0-terminated strings (given as varargs).
Definition: strings.c:64
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
GNUNET_STATISTICS_Callback cont
Continuation to call once action is complete.
struct GNUNET_MQ_Handle * mq
Message queue to the service.
static void schedule_action(void *cls)
Schedule the next action to be performed.
struct GNUNET_STATISTICS_GetHandle * current
Action we are currently busy with (action request has been transmitted, we&#39;re now receiving the respo...
Header for all communications.
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:353
static void free_action_item(struct GNUNET_STATISTICS_GetHandle *gh)
Free memory associated with the given action item.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_set()

static void transmit_set ( struct GNUNET_STATISTICS_Handle handle)
static

Transmit a SET/UPDATE request.

Parameters
handlestatistics handle

Definition at line 850 of file statistics_api.c.

References ACTION_UPDATE, GNUNET_STATISTICS_GetHandle::cont, GNUNET_STATISTICS_Handle::current, env, GNUNET_STATISTICS_SetMessage::flags, free_action_item(), GNUNET_assert, GNUNET_htonll(), GNUNET_MESSAGE_TYPE_STATISTICS_SET, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_STATISTICS_SETFLAG_PERSISTENT, GNUNET_STATISTICS_SETFLAG_RELATIVE, GNUNET_STRINGS_buffer_fill(), GNUNET_STATISTICS_GetHandle::make_persistent, GNUNET_STATISTICS_Handle::mq, GNUNET_STATISTICS_GetHandle::name, schedule_action(), GNUNET_STATISTICS_GetHandle::subsystem, GNUNET_STATISTICS_GetHandle::type, update_memory_statistics(), GNUNET_STATISTICS_SetMessage::value, and GNUNET_STATISTICS_GetHandle::value.

Referenced by schedule_action().

851 {
853  struct GNUNET_MQ_Envelope *env;
854  size_t slen;
855  size_t nlen;
856 
857  slen = strlen (handle->current->subsystem) + 1;
858  nlen = strlen (handle->current->name) + 1;
859  env = GNUNET_MQ_msg_extra (r,
860  slen + nlen,
862  r->flags = 0;
863  r->value = GNUNET_htonll (handle->current->value);
864  if (handle->current->make_persistent)
866  if (handle->current->type == ACTION_UPDATE)
868  GNUNET_assert (slen + nlen ==
869  GNUNET_STRINGS_buffer_fill ((char *) &r[1],
870  slen + nlen,
871  2,
872  handle->current->subsystem,
873  handle->current->name));
874  GNUNET_assert (NULL == handle->current->cont);
875  free_action_item (handle->current);
876  handle->current = NULL;
877  update_memory_statistics (handle);
880  handle);
881  GNUNET_MQ_send (handle->mq,
882  env);
883 }
int make_persistent
Flag for SET/UPDATE actions.
char * name
What value is this action about? (can be NULL)
#define GNUNET_MESSAGE_TYPE_STATISTICS_SET
Set a statistical value.
static void update_memory_statistics(struct GNUNET_STATISTICS_Handle *h)
Obtain statistics about this process&#39;s memory consumption and report those as well (if they changed)...
char * subsystem
What subsystem is this action about? (can be NULL)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum ActionType type
Is this a ACTION_GET, ACTION_SET, ACTION_UPDATE or ACTION_WATCH?
Message to set a statistic.
Definition: statistics.h:92
#define GNUNET_STATISTICS_SETFLAG_RELATIVE
The value being set is a relative change.
Definition: statistics.h:76
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
uint64_t value
Associated value.
size_t GNUNET_STRINGS_buffer_fill(char *buffer, size_t size, unsigned int count,...)
Fill a buffer of the given size with count 0-terminated strings (given as varargs).
Definition: strings.c:64
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
GNUNET_STATISTICS_Callback cont
Continuation to call once action is complete.
struct GNUNET_MQ_Handle * mq
Message queue to the service.
Update a value.
uint32_t flags
0 for absolute value, 1 for relative value; 2 to make persistent (see GNUNET_STATISTICS_SETFLAG_*).
Definition: statistics.h:103
static void schedule_action(void *cls)
Schedule the next action to be performed.
struct GNUNET_STATISTICS_GetHandle * current
Action we are currently busy with (action request has been transmitted, we&#39;re now receiving the respo...
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:353
static void free_action_item(struct GNUNET_STATISTICS_GetHandle *gh)
Free memory associated with the given action item.
#define GNUNET_STATISTICS_SETFLAG_PERSISTENT
The value being set is to be persistent (note that this bit can be combined with GNUNET_STATISTICS_SE...
Definition: statistics.h:84
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_setter_action()

static void add_setter_action ( struct GNUNET_STATISTICS_Handle h,
const char *  name,
int  make_persistent,
uint64_t  value,
enum ActionType  type 
)
static

Queue a request to change a statistic.

Parameters
hstatistics handle
namename of the value
make_persistentshould the value be kept across restarts?
valuenew value or change
typetype of the action (ACTION_SET or ACTION_UPDATE)

Definition at line 1234 of file statistics_api.c.

References GNUNET_STATISTICS_Handle::action_head, ACTION_SET, GNUNET_STATISTICS_Handle::action_tail, ACTION_UPDATE, ai, delta, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_MAX_MESSAGE_SIZE, GNUNET_new, GNUNET_strdup, GNUNET_TIME_relative_to_absolute(), h, GNUNET_STATISTICS_GetHandle::make_persistent, GNUNET_STATISTICS_GetHandle::msize, GNUNET_STATISTICS_GetHandle::name, GNUNET_STATISTICS_GetHandle::next, schedule_action(), SET_TRANSMIT_TIMEOUT, GNUNET_STATISTICS_GetHandle::sh, GNUNET_STATISTICS_GetHandle::subsystem, GNUNET_STATISTICS_Handle::subsystem, GNUNET_STATISTICS_GetHandle::timeout, type, GNUNET_STATISTICS_GetHandle::type, value, and GNUNET_STATISTICS_GetHandle::value.

Referenced by GNUNET_STATISTICS_set(), and GNUNET_STATISTICS_update().

1239 {
1241  size_t slen;
1242  size_t nlen;
1243  size_t nsize;
1244  int64_t delta;
1245 
1246  slen = strlen (h->subsystem) + 1;
1247  nlen = strlen (name) + 1;
1248  nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
1249  if (nsize >= GNUNET_MAX_MESSAGE_SIZE)
1250  {
1251  GNUNET_break (0);
1252  return;
1253  }
1254  for (ai = h->action_head; NULL != ai; ai = ai->next)
1255  {
1256  if (! ( (0 == strcmp (ai->subsystem,
1257  h->subsystem)) &&
1258  (0 == strcmp (ai->name,
1259  name)) &&
1260  ( (ACTION_UPDATE == ai->type) ||
1261  (ACTION_SET == ai->type) ) ) )
1262  continue;
1263  if (ACTION_SET == ai->type)
1264  {
1265  if (ACTION_UPDATE == type)
1266  {
1267  delta = (int64_t) value;
1268  if (delta > 0)
1269  {
1270  /* update old set by new delta */
1271  ai->value += delta;
1272  }
1273  else
1274  {
1275  /* update old set by new delta, but never go negative */
1276  if (ai->value < -delta)
1277  ai->value = 0;
1278  else
1279  ai->value += delta;
1280  }
1281  }
1282  else
1283  {
1284  /* new set overrides old set */
1285  ai->value = value;
1286  }
1287  }
1288  else
1289  {
1290  if (ACTION_UPDATE == type)
1291  {
1292  /* make delta cummulative */
1293  delta = (int64_t) value;
1294  ai->value += delta;
1295  }
1296  else
1297  {
1298  /* drop old 'update', use new 'set' instead */
1299  ai->value = value;
1300  ai->type = type;
1301  }
1302  }
1303  ai->timeout
1305  ai->make_persistent
1306  = make_persistent;
1307  return;
1308  }
1309  /* no existing entry matches, create a fresh one */
1311  ai->sh = h;
1312  ai->subsystem = GNUNET_strdup (h->subsystem);
1313  ai->name = GNUNET_strdup (name);
1315  ai->make_persistent = make_persistent;
1316  ai->msize = nsize;
1317  ai->value = value;
1318  ai->type = type;
1320  h->action_tail,
1321  ai);
1322  schedule_action (h);
1323 }
int make_persistent
Flag for SET/UPDATE actions.
char * name
What value is this action about? (can be NULL)
char * subsystem
Name of our subsystem.
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
char * subsystem
What subsystem is this action about? (can be NULL)
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
enum ActionType type
Is this a ACTION_GET, ACTION_SET, ACTION_UPDATE or ACTION_WATCH?
Linked list of things we still need to do.
Message to set a statistic.
Definition: statistics.h:92
uint16_t msize
Size of the message that we will be transmitting.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Absolute timeout
Timeout for this action.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
static char * value
Value of the record to add/remove.
uint64_t value
Associated value.
struct GNUNET_STATISTICS_GetHandle * action_tail
Tail of the linked list of actions (for fast append).
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
const char * name
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct GNUNET_STATISTICS_Handle * sh
Main statistics handle.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
Update a value.
#define SET_TRANSMIT_TIMEOUT
How long do we wait until a statistics request for setting a value times out? (The update will be los...
Set a value.
static void schedule_action(void *cls)
Schedule the next action to be performed.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
struct GNUNET_STATISTICS_GetHandle * next
This is a doubly linked list.
struct GNUNET_STATISTICS_GetHandle * action_head
Head of the linked list of pending actions (first action to be performed).
Here is the call graph for this function:
Here is the caller graph for this function: