250 unsigned long long total;
268 while (NULL != (se = sub_head))
271 slen = strlen (se->
service) + 1;
277 nlen = strlen (pos->
name) + 1;
319 _ (
"Wrote %llu bytes of statistics to `%s'\n"),
353 "Transmitting value for `%s:%s' (%d): %llu\n",
357 (
unsigned long long) e->
value);
441 slen = strlen (service);
442 nlen = strlen (name);
444 "Received request for statistics on `%s:%s'\n",
445 slen ? service :
"*",
447 for (se = sub_head; NULL != se; se = se->
next)
449 if (! ((0 == slen) || (0 == strcmp (service, se->
service))))
453 if (! ((0 == nlen) || (0 == strcmp (name, pos->
name))))
476 for (pos = se->
we_head; NULL != pos; pos = pos->
next)
490 wvm->
wid = htonl (pos->
wid);
517 if ((NULL == se) || (0 != strcmp (service, se->
service)))
519 for (se = sub_head; NULL != se; se = se->
next)
520 if (0 == strcmp (service, se->
service))
528 "Allocating new subsystem entry `%s'\n",
530 slen = strlen (service) + 1;
533 se->
service = (
const char *) &se[1];
554 if (0 == strcmp (name, pos->
name))
574 msize = ntohs (msg->
header.
size) -
sizeof(*msg);
619 flags = ntohl (msg->flags);
622 "Received request to update statistic on `%s:%s' (%u) to/by %llu\n",
625 (
unsigned int) flags,
626 (
unsigned long long) value);
638 delta = (int64_t) value;
641 changed = (0 != pos->
value);
646 changed = (0 !=
delta);
664 "Statistic `%s:%s' updated to value %llu (%d).\n",
667 (
unsigned long long) pos->
value,
669 if ((changed) || (1 == initial_set))
675 nlen = strlen (name) + 1;
678 pos->
name = (
const char *) &pos[1];
694 "New statistic on `%s:%s' with value %llu created.\n",
697 (
unsigned long long) pos->
value);
756 msize = ntohs (message->
size);
765 "Received request to watch statistic on `%s:%s'\n",
772 nlen = strlen (name) + 1;
775 pos->
name = (
const char *) &pos[1];
781 "New statistic on `%s:%s' with value %llu created.\n",
784 (
unsigned long long) pos->
value);
834 while (NULL != (se = sub_head))
840 while (NULL != (we = pos->
we_head))
887 for (se = sub_head; NULL != se; se = se->
next)
892 while (NULL != (we = wen))
922 uint16_t msize = ntohs (message->
size);
984 _ (
"Loading %llu bytes of statistics from `%s'\n"),
985 (
unsigned long long) fsize,
1046 #if defined(__linux__) && defined(__GLIBC__) 1053 GNUNET_STATISTICS_memory_init ()
1055 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1056 mallopt (M_TOP_PAD, 1 * 1024);
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static void handle_get(void *cls, const struct GNUNET_MessageHeader *message)
Handle GET-message.
struct StatsEntry * stat_head
Head of list of values kept for this subsystem.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
The notification context is the key datastructure for a convenience API used for transmission of noti...
#define GNUNET_MESSAGE_TYPE_STATISTICS_SET
Set a statistical value.
struct GNUNET_MessageHeader * msg
const char * service
Name of the subsystem this entry is for, allocated at the end of this struct, do not free()...
static struct GNUNET_TIME_Relative delta
#define GNUNET_MESSAGE_TYPE_STATISTICS_END
Response to a STATISTICS_GET message (end of value stream).
static int end
Set if we are to shutdown all services (including ARM).
static void load()
Load persistent values from disk.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct SubsystemEntry * subsystem
Which subsystem is this client writing to (SET/UPDATE)?
struct StatsEntry * prev
This is a linked list.
#define GNUNET_MESSAGE_TYPE_STATISTICS_WATCH
Watch changes to a statistical value.
static unsigned int client_count
Number of connected clients.
static int check_get(void *cls, const struct GNUNET_MessageHeader *message)
Check integrity of GET-message.
uint32_t uid
Unique numerical identifier for the value (will not change during the same client-session).
struct StatsEntry * next
This is a linked list.
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_cls)
A client disconnected.
static void notify_change(struct StatsEntry *se)
Notify all clients listening about a change to a value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct WatchEntry * we_head
Watch context for changes to this value, or NULL for none.
static void shutdown_task(void *cls)
Task run during shutdown.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
Callback called when a client connects to the service.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
static struct Experiment * e
Message to set a statistic.
#define GNUNET_MESSAGE_TYPE_STATISTICS_VALUE
Response to a STATISTICS_GET message (with value).
uint32_t flags
0 for absolute value, 1 for relative value; 2 to make persistent (see GNUNET_STATISTICS_SETFLAG_*).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
uint32_t reserved
Reserved (always 0).
static void save()
Write persistent statistics to disk.
#define GNUNET_STATISTICS_SETFLAG_RELATIVE
The value being set is a relative change.
struct WatchEntry * prev
Watch entries are kept in a linked list.
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
struct GNUNET_SERVICE_Client * client
Handle identifying the client.
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Handle to a client that is connected to a service.
static int in_shutdown
Set to GNUNET_YES if we are shutting down as soon as possible.
struct SubsystemEntry * next
Subsystems are kept in a DLL.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read some contents into a buffer.
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 ...
Message transmitted if a watched value changes.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
struct WatchEntry * we_tail
Watch context for changes to this value, or NULL for none.
static int inject_message(void *cls, const struct GNUNET_MessageHeader *message)
We've read a struct GNUNET_STATISTICS_SetMessage * from disk.
We keep the statistics organized by subsystem for faster lookup during SET operations.
#define GNUNET_MESSAGE_TYPE_STATISTICS_GET
Get a statistical value(s).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
uint32_t wid
Unique watch number for this client and this watched value.
static char * value
Value of the record to add/remove.
#define GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM
Service confirms disconnect and that it is done processing all requests from the client.
Information about one of our clients.
int last_value_set
Is last_value valid GNUNET_NO : last_value is n/a, GNUNET_YES: last_value is valid.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
static struct SubsystemEntry * sub_tail
Tail of linked list of subsystems with active statistics.
static char * fn
Filename of the unique file.
Trigger a SOFT server shutdown on signals, allowing active non-monitor clients to complete their tran...
#define GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE
Changes to a watched value.
Handle to a message stream tokenizer.
static void disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the peerstore service.
static int check_set(void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
Check format of SET-message.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
static void do_shutdown()
Actually perform the shutdown.
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).
int persistent
Is this value persistent?
int GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the 'monitor' flag on this client.
Handle for buffered writing.
GNUNET_SERVICE_MAIN("statistics", GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(set, GNUNET_MESSAGE_TYPE_STATISTICS_SET, struct GNUNET_STATISTICS_SetMessage, NULL), GNUNET_MQ_hd_var_size(get, GNUNET_MESSAGE_TYPE_STATISTICS_GET, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_var_size(watch, GNUNET_MESSAGE_TYPE_STATISTICS_WATCH, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_fixed_size(disconnect, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
static void transmit(struct ClientEntry *ce, const struct StatsEntry *e)
Transmit the given stats value.
static void handle_disconnect(void *cls, const struct GNUNET_MessageHeader *message)
Handle DISCONNECT-message.
uint32_t wid
Unique watch identification number (watch requests are enumerated in the order they are received...
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
uint64_t last_value
Last value we communicated to the client for this watch entry.
#define GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT
Client is done sending service requests and will now disconnect.
static int watch
Watch value continuously.
static unsigned int size
Size of the "table".
struct GNUNET_MQ_Handle * mq
Queue for transmissions to client.
static void handle_set(void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
Handle SET-message.
static uint32_t uidgen
Counter used to generate unique values.
Entry in the statistics list.
#define GNUNET_STATISTICS_PERSIST_BIT
Flag for the struct GNUNET_STATISTICS_ReplyMessage UID only.
struct GNUNET_MQ_Envelope * env
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
struct ClientEntry * ce
For which client is this watch entry?
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
static struct SubsystemEntry * sub_head
Head of linked list of subsystems with active statistics.
const char * name
Name for the value stored by this entry, allocated at the end of this struct.
int set
Is this value set? GNUNET_NO: value is n/a, GNUNET_YES: value is valid.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
static struct GNUNET_NotificationContext * nc
Our notification context.
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
Handle to a message queue.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
enum RadiotapType __attribute__
struct StatsEntry * stat_tail
Tail of list of values kept for this subsystem.
static int check_watch(void *cls, const struct GNUNET_MessageHeader *message)
Check integrity of WATCH-message.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_STATISTICS_SET.
struct GNUNET_MQ_Handle * mq
#define GNUNET_log(kind,...)
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Process statistics requests.
static struct StatsEntry * find_stat_entry(struct SubsystemEntry *se, const char *name)
Find the statistics entry of the given subsystem.
struct SubsystemEntry * prev
Subsystems are kept in a DLL.
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
struct SubsystemEntry * subsystem
Subsystem this entry belongs to.
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct WatchEntry * next
Watch entries are kept in a linked list.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
uint32_t max_wid
Maximum watch ID used by this client so far.
static void handle_watch(void *cls, const struct GNUNET_MessageHeader *message)
Handle WATCH-message.
#define GNUNET_malloc(size)
Wrapper around malloc.
Handle for buffered reading.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
#define GNUNET_STATISTICS_SETFLAG_PERSISTENT
The value being set is to be persistent (note that this bit can be combined with GNUNET_STATISTICS_SE...
#define GNUNET_free(ptr)
Wrapper around free.
static struct SubsystemEntry * find_subsystem_entry(struct ClientEntry *ce, const char *service)
Find the subsystem entry of the given name for the specified client.