/*
This file is part of GNUnet.
Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file statistics/statistics_api.c
* @brief API of the statistics service
* @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_statistics_service.h"
#include "statistics.h"
/**
* 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).
*/
#define SET_TRANSMIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
#define LOG(kind,...) GNUNET_log_from (kind, "statistics-api",__VA_ARGS__)
/**
* Types of actions.
*/
enum ActionType
{
/**
* Get a value.
*/
ACTION_GET,
/**
* Set a value.
*/
ACTION_SET,
/**
* Update a value.
*/
ACTION_UPDATE,
/**
* Watch a value.
*/
ACTION_WATCH
};
/**
* Entry kept for each value we are watching.
*/
struct GNUNET_STATISTICS_WatchEntry
{
/**
* What subsystem is this action about? (never NULL)
*/
char *subsystem;
/**
* What value is this action about? (never NULL)
*/
char *name;
/**
* Function to call
*/
GNUNET_STATISTICS_Iterator proc;
/**
* Closure for @e proc
*/
void *proc_cls;
};
/**
* Linked list of things we still need to do.
*/
struct GNUNET_STATISTICS_GetHandle
{
/**
* This is a doubly linked list.
*/
struct GNUNET_STATISTICS_GetHandle *next;
/**
* This is a doubly linked list.
*/
struct GNUNET_STATISTICS_GetHandle *prev;
/**
* Main statistics handle.
*/
struct GNUNET_STATISTICS_Handle *sh;
/**
* What subsystem is this action about? (can be NULL)
*/
char *subsystem;
/**
* What value is this action about? (can be NULL)
*/
char *name;
/**
* Continuation to call once action is complete.
*/
GNUNET_STATISTICS_Callback cont;
/**
* Function to call (for GET actions only).
*/
GNUNET_STATISTICS_Iterator proc;
/**
* Closure for @e proc and @e cont.
*/
void *cls;
/**
* Timeout for this action.
*/
struct GNUNET_TIME_Absolute timeout;
/**
* Associated value.
*/
uint64_t value;
/**
* Flag for SET/UPDATE actions.
*/
int make_persistent;
/**
* Has the current iteration been aborted; for GET actions.
*/
int aborted;
/**
* Is this a #ACTION_GET, #ACTION_SET, #ACTION_UPDATE or #ACTION_WATCH?
*/
enum ActionType type;
/**
* Size of the message that we will be transmitting.
*/
uint16_t