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"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 |
| 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 | 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). | |
| static void | reconnect_later (struct GNUNET_STATISTICS_Handle *h) |
| Reconnect at a later time, respecting back-off. | |
| static void | schedule_action (void *cls) |
| Schedule the next action to be performed. | |
| 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. | |
| static void | free_action_item (struct GNUNET_STATISTICS_GetHandle *gh) |
| Free memory associated with the given action item. | |
| static void | do_disconnect (struct GNUNET_STATISTICS_Handle *h) |
| Disconnect from the statistics service. | |
| static int | check_statistics_value (void *cls, const struct GNUNET_STATISTICS_ReplyMessage *smsg) |
| Process a GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message. | |
| static void | handle_statistics_value (void *cls, const struct GNUNET_STATISTICS_ReplyMessage *smsg) |
| Process a GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message. | |
| static void | handle_statistics_watch_value (void *cls, const struct GNUNET_STATISTICS_WatchValueMessage *wvm) |
| We have received a watch value from the service. | |
| 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. | |
| static void | do_destroy (void *cls) |
| Task used to destroy the statistics handle. | |
| static void | handle_disconnect_confirm (void *cls, const struct GNUNET_MessageHeader *msg) |
| Handle a GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM message. | |
| static void | handle_statistics_end (void *cls, const struct GNUNET_MessageHeader *msg) |
| Handle a GNUNET_MESSAGE_TYPE_STATISTICS_END message. | |
| static int | try_connect (struct GNUNET_STATISTICS_Handle *h) |
| Try to (re)connect to the statistics service. | |
| static void | reconnect_task (void *cls) |
| We've waited long enough, reconnect now. | |
| static void | transmit_get (struct GNUNET_STATISTICS_Handle *handle) |
| Transmit a GET request (and if successful, start to receive the response). | |
| static void | transmit_watch (struct GNUNET_STATISTICS_Handle *handle) |
| Transmit a WATCH request (and if successful, start to receive the response). | |
| static void | transmit_set (struct GNUNET_STATISTICS_Handle *handle) |
| Transmit a SET/UPDATE request. | |
| struct GNUNET_STATISTICS_Handle * | GNUNET_STATISTICS_create (const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg) |
| Get handle for the statistics service. | |
| void | GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first) |
| Destroy a handle (free all state associated with it). | |
| struct GNUNET_STATISTICS_GetHandle * | GNUNET_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. | |
| void | GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) |
| Cancel a GNUNET_STATISTICS_get request. | |
| 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). | |
| 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. | |
| 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. | |
| void | GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent) |
| Set statistic value for the peer. | |
| void | GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent) |
| Set statistic value for the peer. | |
API of the statistics service.
Definition in file statistics_api.c.
| #define SET_TRANSMIT_TIMEOUT |
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.
| #define LOG | ( | kind, | |
| ... | |||
| ) | GNUNET_log_from (kind, "statistics-api", __VA_ARGS__) |
Definition at line 41 of file statistics_api.c.
| 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 46 of file statistics_api.c.
|
static |
Obtain statistics about this process's memory consumption and report those as well (if they changed).
Definition at line 265 of file statistics_api.c.
References GNUNET_NO, GNUNET_STATISTICS_set(), and h.
Referenced by transmit_set().
|
static |
Reconnect at a later time, respecting back-off.
| h | statistics handle |
Definition at line 730 of file statistics_api.c.
References _, ACTION_SET, do_destroy(), 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, h, 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(), and schedule_action().
|
static |
Schedule the next action to be performed.
| cls | statistics handle to reconnect |
| cls | statistics handle |
Definition at line 1001 of file statistics_api.c.
References ACTION_GET, ACTION_SET, ACTION_UPDATE, ACTION_WATCH, 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, h, GNUNET_ARM_Handle::mq, reconnect_later(), schedule_action(), transmit_get(), transmit_set(), transmit_watch(), and try_connect().
Referenced by add_setter_action(), GNUNET_STATISTICS_destroy(), GNUNET_STATISTICS_get(), handle_statistics_end(), reconnect_task(), schedule_action(), schedule_watch_request(), transmit_get(), transmit_set(), and transmit_watch().
|
static |
Transmit request to service that we want to watch the development of a particular value.
| h | statistics handle |
| watch | watch entry of the value to watch |
Definition at line 337 of file statistics_api.c.
References ACTION_WATCH, ai, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_MAX_MESSAGE_SIZE, GNUNET_new, GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_ABS, h, schedule_action(), and watch.
Referenced by GNUNET_STATISTICS_watch(), and try_connect().
|
static |
Free memory associated with the given action item.
| gh | action item to free |
Definition at line 375 of file statistics_api.c.
References GNUNET_free, 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().
|
static |
Disconnect from the statistics service.
| h | statistics handle to disconnect from |
Definition at line 389 of file statistics_api.c.
References GNUNET_STATISTICS_GetHandle::aborted, GNUNET_STATISTICS_GetHandle::cls, GNUNET_STATISTICS_GetHandle::cont, free_action_item(), GNUNET_MQ_destroy(), GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, h, and GNUNET_ARM_Handle::mq.
|
static |
Process a GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message.
| cls | statistics handle |
| smsg | message received from the service, never NULL |
Definition at line 422 of file statistics_api.c.
References GNUNET_break, GNUNET_OK, GNUNET_STRINGS_buffer_tokenize(), GNUNET_SYSERR, GNUNET_STATISTICS_ReplyMessage::header, name, service, GNUNET_MessageHeader::size, and size.
|
static |
Process a GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message.
| cls | statistics handle |
| smsg | message received from the service, never NULL |
Definition at line 453 of file statistics_api.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ntohll(), GNUNET_OK, GNUNET_STATISTICS_PERSIST_BIT, GNUNET_STRINGS_buffer_tokenize(), GNUNET_YES, h, GNUNET_STATISTICS_ReplyMessage::header, LOG, name, service, GNUNET_MessageHeader::size, size, GNUNET_STATISTICS_ReplyMessage::uid, and GNUNET_STATISTICS_ReplyMessage::value.
|
static |
We have received a watch value from the service.
Process it.
| cls | statistics handle |
| wvm | the watch value message |
Definition at line 498 of file statistics_api.c.
References do_disconnect, GNUNET_STATISTICS_WatchValueMessage::flags, GNUNET_break, GNUNET_ntohll(), GNUNET_STATISTICS_PERSIST_BIT, h, 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, and GNUNET_STATISTICS_WatchValueMessage::wid.
|
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.
| cls | closure with the struct GNUNET_STATISTICS_Handle * |
| error | error code |
Definition at line 534 of file statistics_api.c.
References do_disconnect, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), h, and reconnect_later().
Referenced by try_connect().
|
static |
Task used to destroy the statistics handle.
| cls | the struct GNUNET_STATISTICS_Handle |
Definition at line 562 of file statistics_api.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_STATISTICS_destroy(), h, and LOG.
Referenced by GNUNET_STATISTICS_destroy(), handle_disconnect_confirm(), and reconnect_later().
|
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.
| cls | our struct GNUNET_STATISTICS_Handle * |
| msg | the message |
Definition at line 584 of file statistics_api.c.
References do_destroy(), do_disconnect, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, h, LOG, and reconnect_later().
|
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.
| cls | our struct GNUNET_STATISTICS_Handle * |
| msg | the message |
Definition at line 615 of file statistics_api.c.
References GNUNET_STATISTICS_GetHandle::cls, GNUNET_STATISTICS_GetHandle::cont, do_disconnect, free_action_item(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, GNUNET_TIME_UNIT_MILLISECONDS, h, LOG, reconnect_later(), and schedule_action().
|
static |
Try to (re)connect to the statistics service.
| h | statistics handle to reconnect |
Definition at line 650 of file statistics_api.c.
References ACTION_WATCH, GNUNET_ARM_Handle::cfg, free_action_item(), 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, h, handlers, LOG, GNUNET_ARM_Handle::mq, mq_error_handler(), GNUNET_STATISTICS_GetHandle::next, schedule_watch_request(), and GNUNET_STATISTICS_GetHandle::type.
Referenced by schedule_action().
|
static |
We've waited long enough, reconnect now.
| cls | the struct GNUNET_STATISTICS_Handle to reconnect |
Definition at line 715 of file statistics_api.c.
References h, and schedule_action().
Referenced by reconnect_later().
|
static |
Transmit a GET request (and if successful, start to receive the response).
| handle | statistics handle |
Definition at line 771 of file statistics_api.c.
References env, GNUNET_assert, GNUNET_MESSAGE_TYPE_STATISTICS_GET, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_STRINGS_buffer_fill(), handle, GNUNET_VPN_Handle::mq, GNUNET_STATISTICS_GetHandle::name, schedule_action(), and GNUNET_STATISTICS_GetHandle::subsystem.
Referenced by schedule_action().
|
static |
Transmit a WATCH request (and if successful, start to receive the response).
| handle | statistics handle |
Definition at line 806 of file statistics_api.c.
References 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(), handle, LOG, GNUNET_VPN_Handle::mq, and schedule_action().
Referenced by schedule_action().
|
static |
Transmit a SET/UPDATE request.
| handle | statistics handle |
Definition at line 845 of file statistics_api.c.
References ACTION_UPDATE, 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(), handle, GNUNET_VPN_Handle::mq, schedule_action(), update_memory_statistics(), and GNUNET_STATISTICS_SetMessage::value.
Referenced by schedule_action().
|
static |
Queue a request to change a statistic.
| h | statistics handle |
| name | name of the value |
| make_persistent | should the value be kept across restarts? |
| value | new value or change |
| type | type of the action (ACTION_SET or ACTION_UPDATE) |
Definition at line 1214 of file statistics_api.c.
References ACTION_SET, 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, name, GNUNET_TRANSPORT_AddressIdentifier::next, schedule_action(), SET_TRANSMIT_TIMEOUT, type, and value.
Referenced by GNUNET_STATISTICS_set(), and GNUNET_STATISTICS_update().