static uint32_t uidgen;
+static void
+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));
+}
+
+
/**
* Load persistent values from disk. Disk format is
* exactly the same format that we also use for
struct GNUNET_DISK_MapHandle *mh;
struct stat sb;
char *buf;
- size_t off;
- const struct GNUNET_MessageHeader *msg;
+ struct GNUNET_SERVER_MessageStreamTokenizer *mst;
fn = GNUNET_DISK_get_home_filename (cfg,
"statistics", "statistics.data", NULL);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Loading %llu bytes of statistics from `%s'\n"),
(unsigned long long) sb.st_size, fn);
- off = 0;
- while (off + sizeof (struct GNUNET_MessageHeader) < sb.st_size)
- {
- msg = (const struct GNUNET_MessageHeader *) &buf[off];
- if ((ntohs (msg->size) + off > sb.st_size) ||
- (GNUNET_OK != GNUNET_SERVER_inject (server, NULL, msg)))
- {
- GNUNET_break (0);
- break;
- }
- off += ntohs (msg->size);
- }
+ mst = GNUNET_SERVER_mst_create (&inject_message,
+ server);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_SERVER_mst_receive (mst,
+ NULL,
+ buf,
+ sb.st_size,
+ GNUNET_YES,
+ GNUNET_NO));
+ GNUNET_SERVER_mst_destroy (mst);
GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (mh));
GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh));
GNUNET_free (fn);
{
struct ClientEntry *ce;
- if (client == NULL)
- return NULL;
+ GNUNET_assert (client != NULL);
ce = client_head;
while (ce != NULL)
{
struct StatsEntry *pos;
size_t size;
- make_client_entry (client);
+ if (client != NULL)
+ make_client_entry (client);
size = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader);
if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
size, 2, &service, &name))
int64_t delta;
int changed;
- make_client_entry (client);
+ if (client != NULL)
+ make_client_entry (client);
msize = ntohs (message->size);
if (msize < sizeof (struct GNUNET_STATISTICS_SetMessage))
{
struct StatsEntry *pos;
struct ClientEntry *ce;
struct WatchEntry *we;
+ size_t slen;
ce = make_client_entry (client);
msize = ntohs (message->size);
pos->msg->header.size = htons (sizeof (struct GNUNET_STATISTICS_SetMessage) +
size);
pos->msg->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET);
- memcpy (pos->msg, message, ntohs (message->size));
pos->service = (const char *) &pos->msg[1];
- memcpy (&pos->msg[1], service, strlen (service)+1);
- pos->name = &pos->service[strlen (pos->service) + 1];
+ slen = strlen (service) + 1;
+ memcpy ((void*) pos->service, service, slen);
+ pos->name = &pos->service[slen];
memcpy ((void*) pos->name, name, strlen (name)+1);
start = pos;
}
* Process statistics requests.
*
* @param cls closure
- * @param sched scheduler to use
* @param server the initialized server
* @param c configuration to use
*/
static void
run (void *cls,
- struct GNUNET_SCHEDULER_Handle *sched,
struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
&handle_client_disconnect,
NULL);
load (server);
- GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&shutdown_task,
NULL);
}