244 unsigned long long total;
265 slen = strlen (se->
service) + 1;
271 nlen = strlen (pos->
name) + 1;
313 _ (
"Wrote %llu bytes of statistics to `%s'\n"),
337 m->uid = htonl (e->
uid);
347 "Transmitting value for `%s:%s' (%d): %llu\n",
351 (
unsigned long long) e->
value);
436 nlen = strlen (
name);
438 "Received request for statistics on `%s:%s'\n",
447 if (! ((0 == nlen) || (0 == strcmp (
name, pos->
name))))
470 for (pos = se->
we_head; NULL != pos; pos = pos->
next)
484 wvm->
wid = htonl (pos->
wid);
522 "Allocating new subsystem entry `%s'\n",
527 se->
service = (
const char *) &se[1];
568 msize = ntohs (
msg->header.
size) -
sizeof(*msg);
605 msize = ntohs (
msg->header.
size);
616 "Received request to update statistic on `%s:%s' (%u) to/by %llu\n",
619 (
unsigned int)
flags,
620 (
unsigned long long)
value);
635 changed = (0 != pos->
value);
640 changed = (0 !=
delta);
658 "Statistic `%s:%s' updated to value %llu (%d).\n",
661 (
unsigned long long) pos->
value,
663 if ((changed) || (1 == initial_set))
669 nlen = strlen (
name) + 1;
672 pos->
name = (
const char *) &pos[1];
688 "New statistic on `%s:%s' with value %llu created.\n",
691 (
unsigned long long) pos->
value);
750 msize = ntohs (message->
size);
759 "Received request to watch statistic on `%s:%s'\n",
766 nlen = strlen (
name) + 1;
769 pos->
name = (
const char *) &pos[1];
775 "New statistic on `%s:%s' with value %llu created.\n",
778 (
unsigned long long) pos->
value);
834 while (NULL != (we = pos->
we_head))
886 while (NULL != (we = wen))
916 uint16_t msize = ntohs (message->
size);
978 _ (
"Loading %llu bytes of statistics from `%s'\n"),
979 (
unsigned long long) fsize,
1041#if defined(__linux__) && defined(__GLIBC__)
1045GNUNET_STATISTICS_memory_init(
void);
1051GNUNET_STATISTICS_memory_init (
void)
1053 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1054 mallopt (M_TOP_PAD, 1 * 1024);
struct GNUNET_MQ_Handle * mq
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static int end
Set if we are to shutdown all services (including ARM).
static int get
Get DID Documement for DID Flag.
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static void transmit(struct ClientEntry *ce, const struct StatsEntry *e)
Transmit the given stats value.
static void handle_set(void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
Handle SET-message.
static int check_watch(void *cls, const struct GNUNET_MessageHeader *message)
Check integrity of WATCH-message.
static void handle_watch(void *cls, const struct GNUNET_MessageHeader *message)
Handle WATCH-message.
static struct SubsystemEntry * find_subsystem_entry(struct ClientEntry *ce, const char *service)
Find the subsystem entry of the given name for the specified client.
static void handle_disconnect(void *cls, const struct GNUNET_MessageHeader *message)
Handle DISCONNECT-message.
static int inject_message(void *cls, const struct GNUNET_MessageHeader *message)
We've read a struct GNUNET_STATISTICS_SetMessage * from disk.
GNUNET_SERVICE_MAIN(GNUNET_OS_project_data_gnunet(), "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.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static unsigned int client_count
Number of connected clients.
static struct GNUNET_NotificationContext * nc
Our notification context.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_cls)
A client disconnected.
static int in_shutdown
Set to GNUNET_YES if we are shutting down as soon as possible.
static void shutdown_task(void *cls)
Task run during shutdown.
static void handle_get(void *cls, const struct GNUNET_MessageHeader *message)
Handle GET-message.
static void save()
Write persistent statistics to disk.
static void notify_change(struct StatsEntry *se)
Notify all clients listening about a change to a value.
static void load()
Load persistent values from disk.
static struct SubsystemEntry * sub_tail
Tail of linked list of subsystems with active statistics.
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Process statistics requests.
static void do_shutdown()
Actually perform the shutdown.
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.
static struct SubsystemEntry * sub_head
Head of linked list of subsystems with active statistics.
static struct StatsEntry * find_stat_entry(struct SubsystemEntry *se, const char *name)
Find the statistics entry of the given subsystem.
static int check_set(void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
Check format of SET-message.
static uint32_t uidgen
Counter used to generate unique values.
static int check_get(void *cls, const struct GNUNET_MessageHeader *message)
Check integrity of GET-message.
static int watch
Watch value continuously.
struct GNUNET_PQ_ResultSpec __attribute__
Constants for network protocols.
Functions related to time.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
enum GNUNET_GenericReturnValue GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read some contents into a buffer.
enum GNUNET_GenericReturnValue GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
enum GNUNET_GenericReturnValue GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
enum GNUNET_GenericReturnValue GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
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.
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 GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#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...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#define GNUNET_MESSAGE_TYPE_STATISTICS_END
Response to a STATISTICS_GET message (end of value stream).
#define GNUNET_MESSAGE_TYPE_STATISTICS_GET
Get a statistical value(s).
#define GNUNET_MESSAGE_TYPE_STATISTICS_VALUE
Response to a STATISTICS_GET message (with value).
#define GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE
Changes to a watched value.
#define GNUNET_MESSAGE_TYPE_STATISTICS_SET
Set a statistical value.
#define GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM
Service confirms disconnect and that it is done processing all requests from the client.
#define GNUNET_MESSAGE_TYPE_STATISTICS_WATCH
Watch changes to a statistical value.
#define GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT
Client is done sending service requests and will now disconnect.
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,...
enum GNUNET_GenericReturnValue 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.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the 'monitor' flag on this client.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
@ GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN
Trigger a SOFT server shutdown on signals, allowing active non-monitor clients to complete their tran...
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 ...
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).
static unsigned int size
Size of the "table".
static void disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the peerstore service.
static struct GNUNET_TIME_Relative delta
#define GNUNET_STATISTICS_PERSIST_BIT
Flag for the struct GNUNET_STATISTICS_ReplyMessage UID only.
#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_STATISTICS_SETFLAG_RELATIVE
The value being set is a relative change.
Information about one of our clients.
struct GNUNET_SERVICE_Client * client
Handle identifying the client.
struct SubsystemEntry * subsystem
Which subsystem is this client writing to (SET/UPDATE)?
uint32_t max_wid
Maximum watch ID used by this client so far.
struct GNUNET_MQ_Handle * mq
Queue for transmissions to client.
Handle for buffered reading.
Handle for buffered writing.
Handle to a message queue.
Handle to a message stream tokenizer.
The notification context is the key datastructure for a convenience API used for transmission of noti...
Handle to a client that is connected to a service.
Message to set a statistic.
uint32_t flags
0 for absolute value, 1 for relative value; 2 to make persistent (see GNUNET_STATISTICS_SETFLAG_*).
Message transmitted if a watched value changes.
uint32_t reserved
Reserved (always 0).
uint32_t flags
0 for absolute value, 1 for relative value; 2 to make persistent (see GNUNET_STATISTICS_SETFLAG_*).
uint32_t wid
Unique watch identification number (watch requests are enumerated in the order they are received,...
Entry in the statistics list.
struct StatsEntry * prev
This is a linked list.
struct StatsEntry * next
This is a linked list.
struct SubsystemEntry * subsystem
Subsystem this entry belongs to.
struct WatchEntry * we_tail
Watch context for changes to this value, or NULL for none.
struct WatchEntry * we_head
Watch context for changes to this value, or NULL for none.
int persistent
Is this value persistent?
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.
We keep the statistics organized by subsystem for faster lookup during SET operations.
struct SubsystemEntry * prev
Subsystems are kept in a DLL.
struct SubsystemEntry * next
Subsystems are kept in a DLL.
struct StatsEntry * stat_head
Head of list of values kept for this subsystem.
struct StatsEntry * stat_tail
Tail of list of values kept for this subsystem.
const char * service
Name of the subsystem this entry is for, allocated at the end of this struct, do not free().
struct WatchEntry * next
Watch entries are kept in a linked list.
uint64_t last_value
Last value we communicated to the client for this watch entry.
struct WatchEntry * prev
Watch entries are kept in a linked list.
int last_value_set
Is last_value valid GNUNET_NO : last_value is n/a, GNUNET_YES: last_value is valid.
uint32_t wid
Unique watch number for this client and this watched value.
struct ClientEntry * ce
For which client is this watch entry?