* @param client unused
* @param msg message to inject
*/
-static void
+static int
inject_message (void *cls, void *client, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_SERVER_Handle *server = cls;
GNUNET_break (GNUNET_OK == GNUNET_SERVER_inject (server, NULL, msg));
+ return GNUNET_OK;
}
struct GNUNET_SERVER_MessageStreamTokenizer *mst;
char *emsg;
- fn = GNUNET_DISK_get_home_filename (cfg, "statistics", "statistics.data",
- NULL);
- if (fn == NULL)
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "STATISTICS",
+ "DATABASE",
+ &fn))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "STATISTICS",
+ "DATABASE");
return;
- if ((GNUNET_OK != GNUNET_DISK_file_size (fn, &fsize, GNUNET_NO, GNUNET_YES)) || (fsize == 0))
+ }
+ if ( (GNUNET_OK !=
+ GNUNET_DISK_file_size (fn, &fsize, GNUNET_NO, GNUNET_YES)) ||
+ (0 == fsize) )
{
GNUNET_free (fn);
return;
struct StatsEntry *pos;
char *fn;
struct GNUNET_BIO_WriteHandle *wh;
-
uint16_t size;
unsigned long long total;
- wh = NULL;
- fn = GNUNET_DISK_get_home_filename (cfg, "statistics", "statistics.data",
- NULL);
- if (fn != NULL)
- wh = GNUNET_BIO_write_open (fn);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "STATISTICS",
+ "DATABASE",
+ &fn))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "STATISTICS",
+ "DATABASE");
+ return;
+ }
+ (void) GNUNET_DISK_directory_create_for_file (fn);
+ wh = GNUNET_BIO_write_open (fn);
total = 0;
while (NULL != (pos = start))
{
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return NULL;
}
- ce = GNUNET_malloc (sizeof (struct ClientEntry));
+ ce = GNUNET_new (struct ClientEntry);
ce->client = client;
- GNUNET_SERVER_client_keep (client);
GNUNET_CONTAINER_DLL_insert (client_head, client_tail, ce);
GNUNET_SERVER_notification_context_add (nc, client);
return ce;
}
}
+
/**
* Handle SET-message.
*
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
+ GNUNET_SERVER_client_mark_monitor (client);
ce = make_client_entry (client);
msize = ntohs (message->size);
if (msize < sizeof (struct GNUNET_MessageHeader))
"New statistic on `%s:%s' with value %llu created.\n", service,
name, pos->value);
}
- we = GNUNET_malloc (sizeof (struct WatchEntry));
+ we = GNUNET_new (struct WatchEntry);
we->client = client;
we->last_value_set = GNUNET_NO;
- GNUNET_SERVER_client_keep (client);
we->wid = ce->max_wid++;
GNUNET_CONTAINER_DLL_insert (pos->we_head, pos->we_tail, we);
if (pos->value != 0)
/**
* Actually perform the shutdown.
*/
-static void
+static void
do_shutdown ()
{
struct WatchEntry *we;
return;
save ();
GNUNET_SERVER_notification_context_destroy (nc);
- nc = NULL;
+ nc = NULL;
GNUNET_assert (NULL == client_head);
while (NULL != (se = start))
{
start = se->next;
while (NULL != (we = se->we_head))
{
- GNUNET_SERVER_client_drop (we->client);
GNUNET_CONTAINER_DLL_remove (se->we_head, se->we_tail, we);
GNUNET_free (we);
}
{
if (ce->client == client)
{
- GNUNET_SERVER_client_drop (ce->client);
GNUNET_CONTAINER_DLL_remove (client_head, client_tail, ce);
GNUNET_free (ce);
break;
wen = we->next;
if (we->client != client)
continue;
- GNUNET_SERVER_client_drop (we->client);
GNUNET_CONTAINER_DLL_remove (se->we_head, se->we_tail, we);
GNUNET_free (we);
}
{
return (GNUNET_OK ==
GNUNET_SERVICE_run (argc, argv, "statistics",
- GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
+ GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, NULL)) ? 0 : 1;
+}
+
+#ifdef LINUX
+#include <malloc.h>
+
+/**
+ * MINIMIZE heap size (way below 128k) since this process doesn't need much.
+ */
+void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
+{
+ mallopt (M_TRIM_THRESHOLD, 4 * 1024);
+ mallopt (M_TOP_PAD, 1 * 1024);
+ malloc_trim (0);
}
+#endif
+
/* end of gnunet-service-statistics.c */