aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/gnunet-service-statistics.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/statistics/gnunet-service-statistics.c')
-rw-r--r--src/statistics/gnunet-service-statistics.c842
1 files changed, 423 insertions, 419 deletions
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c
index 7d84f421e..3de481e77 100644
--- a/src/statistics/gnunet-service-statistics.c
+++ b/src/statistics/gnunet-service-statistics.c
@@ -38,7 +38,8 @@
38/** 38/**
39 * Watch entry. 39 * Watch entry.
40 */ 40 */
41struct WatchEntry { 41struct WatchEntry
42{
42 /** 43 /**
43 * Watch entries are kept in a linked list. 44 * Watch entries are kept in a linked list.
44 */ 45 */
@@ -82,7 +83,8 @@ struct SubsystemEntry;
82/** 83/**
83 * Entry in the statistics list. 84 * Entry in the statistics list.
84 */ 85 */
85struct StatsEntry { 86struct StatsEntry
87{
86 /** 88 /**
87 * This is a linked list. 89 * This is a linked list.
88 */ 90 */
@@ -141,7 +143,8 @@ struct StatsEntry {
141 * We keep the statistics organized by subsystem for faster 143 * We keep the statistics organized by subsystem for faster
142 * lookup during SET operations. 144 * lookup during SET operations.
143 */ 145 */
144struct SubsystemEntry { 146struct SubsystemEntry
147{
145 /** 148 /**
146 * Subsystems are kept in a DLL. 149 * Subsystems are kept in a DLL.
147 */ 150 */
@@ -173,7 +176,8 @@ struct SubsystemEntry {
173/** 176/**
174 * Client entry. 177 * Client entry.
175 */ 178 */
176struct ClientEntry { 179struct ClientEntry
180{
177 /** 181 /**
178 * Corresponding server handle. 182 * Corresponding server handle.
179 */ 183 */
@@ -236,7 +240,7 @@ static int in_shutdown;
236 * Write persistent statistics to disk. 240 * Write persistent statistics to disk.
237 */ 241 */
238static void 242static void
239save() 243save ()
240{ 244{
241 struct SubsystemEntry *se; 245 struct SubsystemEntry *se;
242 struct StatsEntry *pos; 246 struct StatsEntry *pos;
@@ -248,74 +252,74 @@ save()
248 size_t slen; 252 size_t slen;
249 struct GNUNET_STATISTICS_SetMessage *msg; 253 struct GNUNET_STATISTICS_SetMessage *msg;
250 254
251 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, 255 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
252 "STATISTICS", 256 "STATISTICS",
253 "DATABASE", 257 "DATABASE",
254 &fn)) 258 &fn))
255 { 259 {
256 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 260 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
257 "STATISTICS", 261 "STATISTICS",
258 "DATABASE"); 262 "DATABASE");
259 return; 263 return;
260 } 264 }
261 (void)GNUNET_DISK_directory_create_for_file(fn); 265 (void) GNUNET_DISK_directory_create_for_file (fn);
262 wh = GNUNET_BIO_write_open(fn); 266 wh = GNUNET_BIO_write_open (fn);
263 total = 0; 267 total = 0;
264 while (NULL != (se = sub_head)) 268 while (NULL != (se = sub_head))
269 {
270 GNUNET_CONTAINER_DLL_remove (sub_head, sub_tail, se);
271 slen = strlen (se->service) + 1;
272 while (NULL != (pos = se->stat_head))
265 { 273 {
266 GNUNET_CONTAINER_DLL_remove(sub_head, sub_tail, se); 274 GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos);
267 slen = strlen(se->service) + 1; 275 if ((pos->persistent) && (NULL != wh))
268 while (NULL != (pos = se->stat_head)) 276 {
277 nlen = strlen (pos->name) + 1;
278 size = sizeof(struct GNUNET_STATISTICS_SetMessage) + nlen + slen;
279 GNUNET_assert (size < UINT16_MAX);
280 msg = GNUNET_malloc (size);
281
282 msg->header.size = htons ((uint16_t) size);
283 msg->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET);
284 GNUNET_assert (nlen + slen ==
285 GNUNET_STRINGS_buffer_fill ((char *) &msg[1],
286 nlen + slen,
287 2,
288 se->service,
289 pos->name));
290 msg->flags =
291 htonl (pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0);
292 msg->value = GNUNET_htonll (pos->value);
293 if (GNUNET_OK != GNUNET_BIO_write (wh, msg, size))
294 {
295 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
296 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
297 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn);
298 wh = NULL;
299 }
300 else
269 { 301 {
270 GNUNET_CONTAINER_DLL_remove(se->stat_head, se->stat_tail, pos); 302 total += size;
271 if ((pos->persistent) && (NULL != wh))
272 {
273 nlen = strlen(pos->name) + 1;
274 size = sizeof(struct GNUNET_STATISTICS_SetMessage) + nlen + slen;
275 GNUNET_assert(size < UINT16_MAX);
276 msg = GNUNET_malloc(size);
277
278 msg->header.size = htons((uint16_t)size);
279 msg->header.type = htons(GNUNET_MESSAGE_TYPE_STATISTICS_SET);
280 GNUNET_assert(nlen + slen ==
281 GNUNET_STRINGS_buffer_fill((char *)&msg[1],
282 nlen + slen,
283 2,
284 se->service,
285 pos->name));
286 msg->flags =
287 htonl(pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0);
288 msg->value = GNUNET_htonll(pos->value);
289 if (GNUNET_OK != GNUNET_BIO_write(wh, msg, size))
290 {
291 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "write", fn);
292 if (GNUNET_OK != GNUNET_BIO_write_close(wh))
293 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "close", fn);
294 wh = NULL;
295 }
296 else
297 {
298 total += size;
299 }
300 GNUNET_free(msg);
301 }
302 GNUNET_free(pos);
303 } 303 }
304 GNUNET_free(se); 304 GNUNET_free (msg);
305 }
306 GNUNET_free (pos);
305 } 307 }
308 GNUNET_free (se);
309 }
306 if (NULL != wh) 310 if (NULL != wh)
307 { 311 {
308 if (GNUNET_OK != GNUNET_BIO_write_close(wh)) 312 if (GNUNET_OK != GNUNET_BIO_write_close (wh))
309 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "close", fn); 313 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn);
310 if (0 == total) 314 if (0 == total)
311 GNUNET_break(0 == unlink(fn)); 315 GNUNET_break (0 == unlink (fn));
312 else 316 else
313 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 317 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
314 _("Wrote %llu bytes of statistics to `%s'\n"), 318 _ ("Wrote %llu bytes of statistics to `%s'\n"),
315 total, 319 total,
316 fn); 320 fn);
317 } 321 }
318 GNUNET_free_non_null(fn); 322 GNUNET_free_non_null (fn);
319} 323}
320 324
321 325
@@ -326,31 +330,31 @@ save()
326 * @param e value to transmit 330 * @param e value to transmit
327 */ 331 */
328static void 332static void
329transmit(struct ClientEntry *ce, const struct StatsEntry *e) 333transmit (struct ClientEntry *ce, const struct StatsEntry *e)
330{ 334{
331 struct GNUNET_MQ_Envelope *env; 335 struct GNUNET_MQ_Envelope *env;
332 struct GNUNET_STATISTICS_ReplyMessage *m; 336 struct GNUNET_STATISTICS_ReplyMessage *m;
333 size_t size; 337 size_t size;
334 338
335 size = strlen(e->subsystem->service) + 1 + strlen(e->name) + 1; 339 size = strlen (e->subsystem->service) + 1 + strlen (e->name) + 1;
336 GNUNET_assert(size < GNUNET_MAX_MESSAGE_SIZE); 340 GNUNET_assert (size < GNUNET_MAX_MESSAGE_SIZE);
337 env = GNUNET_MQ_msg_extra(m, size, GNUNET_MESSAGE_TYPE_STATISTICS_VALUE); 341 env = GNUNET_MQ_msg_extra (m, size, GNUNET_MESSAGE_TYPE_STATISTICS_VALUE);
338 m->uid = htonl(e->uid); 342 m->uid = htonl (e->uid);
339 if (e->persistent) 343 if (e->persistent)
340 m->uid |= htonl(GNUNET_STATISTICS_PERSIST_BIT); 344 m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT);
341 m->value = GNUNET_htonll(e->value); 345 m->value = GNUNET_htonll (e->value);
342 GNUNET_assert(size == GNUNET_STRINGS_buffer_fill((char *)&m[1], 346 GNUNET_assert (size == GNUNET_STRINGS_buffer_fill ((char *) &m[1],
343 size, 347 size,
344 2, 348 2,
345 e->subsystem->service, 349 e->subsystem->service,
346 e->name)); 350 e->name));
347 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
348 "Transmitting value for `%s:%s' (%d): %llu\n", 352 "Transmitting value for `%s:%s' (%d): %llu\n",
349 e->subsystem->service, 353 e->subsystem->service,
350 e->name, 354 e->name,
351 e->persistent, 355 e->persistent,
352 (unsigned long long)e->value); 356 (unsigned long long) e->value);
353 GNUNET_MQ_send(ce->mq, env); 357 GNUNET_MQ_send (ce->mq, env);
354} 358}
355 359
356 360
@@ -363,17 +367,17 @@ transmit(struct ClientEntry *ce, const struct StatsEntry *e)
363 * @return @a c 367 * @return @a c
364 */ 368 */
365static void * 369static void *
366client_connect_cb(void *cls, 370client_connect_cb (void *cls,
367 struct GNUNET_SERVICE_Client *c, 371 struct GNUNET_SERVICE_Client *c,
368 struct GNUNET_MQ_Handle *mq) 372 struct GNUNET_MQ_Handle *mq)
369{ 373{
370 struct ClientEntry *ce; 374 struct ClientEntry *ce;
371 375
372 ce = GNUNET_new(struct ClientEntry); 376 ce = GNUNET_new (struct ClientEntry);
373 ce->client = c; 377 ce->client = c;
374 ce->mq = mq; 378 ce->mq = mq;
375 client_count++; 379 client_count++;
376 GNUNET_notification_context_add(nc, mq); 380 GNUNET_notification_context_add (nc, mq);
377 return ce; 381 return ce;
378} 382}
379 383
@@ -386,22 +390,22 @@ client_connect_cb(void *cls,
386 * @return #GNUNET_OK if @a message is well-formed 390 * @return #GNUNET_OK if @a message is well-formed
387 */ 391 */
388static int 392static int
389check_get(void *cls, const struct GNUNET_MessageHeader *message) 393check_get (void *cls, const struct GNUNET_MessageHeader *message)
390{ 394{
391 const char *service; 395 const char *service;
392 const char *name; 396 const char *name;
393 size_t size; 397 size_t size;
394 398
395 size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader); 399 size = ntohs (message->size) - sizeof(struct GNUNET_MessageHeader);
396 if (size != GNUNET_STRINGS_buffer_tokenize((const char *)&message[1], 400 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
397 size, 401 size,
398 2, 402 2,
399 &service, 403 &service,
400 &name)) 404 &name))
401 { 405 {
402 GNUNET_break(0); 406 GNUNET_break (0);
403 return GNUNET_SYSERR; 407 return GNUNET_SYSERR;
404 } 408 }
405 return GNUNET_OK; 409 return GNUNET_OK;
406} 410}
407 411
@@ -413,7 +417,7 @@ check_get(void *cls, const struct GNUNET_MessageHeader *message)
413 * @param message the actual message 417 * @param message the actual message
414 */ 418 */
415static void 419static void
416handle_get(void *cls, const struct GNUNET_MessageHeader *message) 420handle_get (void *cls, const struct GNUNET_MessageHeader *message)
417{ 421{
418 struct ClientEntry *ce = cls; 422 struct ClientEntry *ce = cls;
419 struct GNUNET_MQ_Envelope *env; 423 struct GNUNET_MQ_Envelope *env;
@@ -426,33 +430,33 @@ handle_get(void *cls, const struct GNUNET_MessageHeader *message)
426 struct StatsEntry *pos; 430 struct StatsEntry *pos;
427 size_t size; 431 size_t size;
428 432
429 size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader); 433 size = ntohs (message->size) - sizeof(struct GNUNET_MessageHeader);
430 GNUNET_assert(size == 434 GNUNET_assert (size ==
431 GNUNET_STRINGS_buffer_tokenize((const char *)&message[1], 435 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
432 size, 436 size,
433 2, 437 2,
434 &service, 438 &service,
435 &name)); 439 &name));
436 slen = strlen(service); 440 slen = strlen (service);
437 nlen = strlen(name); 441 nlen = strlen (name);
438 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
439 "Received request for statistics on `%s:%s'\n", 443 "Received request for statistics on `%s:%s'\n",
440 slen ? service : "*", 444 slen ? service : "*",
441 nlen ? name : "*"); 445 nlen ? name : "*");
442 for (se = sub_head; NULL != se; se = se->next) 446 for (se = sub_head; NULL != se; se = se->next)
447 {
448 if (! ((0 == slen) || (0 == strcmp (service, se->service))))
449 continue;
450 for (pos = se->stat_head; NULL != pos; pos = pos->next)
443 { 451 {
444 if (!((0 == slen) || (0 == strcmp(service, se->service)))) 452 if (! ((0 == nlen) || (0 == strcmp (name, pos->name))))
445 continue; 453 continue;
446 for (pos = se->stat_head; NULL != pos; pos = pos->next) 454 transmit (ce, pos);
447 {
448 if (!((0 == nlen) || (0 == strcmp(name, pos->name))))
449 continue;
450 transmit(ce, pos);
451 }
452 } 455 }
453 env = GNUNET_MQ_msg(end, GNUNET_MESSAGE_TYPE_STATISTICS_END); 456 }
454 GNUNET_MQ_send(ce->mq, env); 457 env = GNUNET_MQ_msg (end, GNUNET_MESSAGE_TYPE_STATISTICS_END);
455 GNUNET_SERVICE_client_continue(ce->client); 458 GNUNET_MQ_send (ce->mq, env);
459 GNUNET_SERVICE_client_continue (ce->client);
456} 460}
457 461
458 462
@@ -462,32 +466,32 @@ handle_get(void *cls, const struct GNUNET_MessageHeader *message)
462 * @param se value that changed 466 * @param se value that changed
463 */ 467 */
464static void 468static void
465notify_change(struct StatsEntry *se) 469notify_change (struct StatsEntry *se)
466{ 470{
467 struct GNUNET_MQ_Envelope *env; 471 struct GNUNET_MQ_Envelope *env;
468 struct GNUNET_STATISTICS_WatchValueMessage *wvm; 472 struct GNUNET_STATISTICS_WatchValueMessage *wvm;
469 struct WatchEntry *pos; 473 struct WatchEntry *pos;
470 474
471 for (pos = se->we_head; NULL != pos; pos = pos->next) 475 for (pos = se->we_head; NULL != pos; pos = pos->next)
476 {
477 if (GNUNET_YES == pos->last_value_set)
472 { 478 {
473 if (GNUNET_YES == pos->last_value_set) 479 if (pos->last_value == se->value)
474 { 480 continue;
475 if (pos->last_value == se->value)
476 continue;
477 }
478 else
479 {
480 pos->last_value_set = GNUNET_YES;
481 }
482 env = GNUNET_MQ_msg(wvm, GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE);
483 wvm->flags =
484 htonl(se->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0);
485 wvm->wid = htonl(pos->wid);
486 wvm->reserved = htonl(0);
487 wvm->value = GNUNET_htonll(se->value);
488 GNUNET_MQ_send(pos->ce->mq, env);
489 pos->last_value = se->value;
490 } 481 }
482 else
483 {
484 pos->last_value_set = GNUNET_YES;
485 }
486 env = GNUNET_MQ_msg (wvm, GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE);
487 wvm->flags =
488 htonl (se->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0);
489 wvm->wid = htonl (pos->wid);
490 wvm->reserved = htonl (0);
491 wvm->value = GNUNET_htonll (se->value);
492 GNUNET_MQ_send (pos->ce->mq, env);
493 pos->last_value = se->value;
494 }
491} 495}
492 496
493 497
@@ -500,7 +504,7 @@ notify_change(struct StatsEntry *se)
500 * @return subsystem entry, never NULL (subsystem entry is created if necessary) 504 * @return subsystem entry, never NULL (subsystem entry is created if necessary)
501 */ 505 */
502static struct SubsystemEntry * 506static struct SubsystemEntry *
503find_subsystem_entry(struct ClientEntry *ce, const char *service) 507find_subsystem_entry (struct ClientEntry *ce, const char *service)
504{ 508{
505 size_t slen; 509 size_t slen;
506 struct SubsystemEntry *se; 510 struct SubsystemEntry *se;
@@ -509,24 +513,24 @@ find_subsystem_entry(struct ClientEntry *ce, const char *service)
509 se = ce->subsystem; 513 se = ce->subsystem;
510 else 514 else
511 se = NULL; 515 se = NULL;
512 if ((NULL == se) || (0 != strcmp(service, se->service))) 516 if ((NULL == se) || (0 != strcmp (service, se->service)))
513 { 517 {
514 for (se = sub_head; NULL != se; se = se->next) 518 for (se = sub_head; NULL != se; se = se->next)
515 if (0 == strcmp(service, se->service)) 519 if (0 == strcmp (service, se->service))
516 break; 520 break;
517 if (NULL != ce) 521 if (NULL != ce)
518 ce->subsystem = se; 522 ce->subsystem = se;
519 } 523 }
520 if (NULL != se) 524 if (NULL != se)
521 return se; 525 return se;
522 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
523 "Allocating new subsystem entry `%s'\n", 527 "Allocating new subsystem entry `%s'\n",
524 service); 528 service);
525 slen = strlen(service) + 1; 529 slen = strlen (service) + 1;
526 se = GNUNET_malloc(sizeof(struct SubsystemEntry) + slen); 530 se = GNUNET_malloc (sizeof(struct SubsystemEntry) + slen);
527 GNUNET_memcpy(&se[1], service, slen); 531 GNUNET_memcpy (&se[1], service, slen);
528 se->service = (const char *)&se[1]; 532 se->service = (const char *) &se[1];
529 GNUNET_CONTAINER_DLL_insert(sub_head, sub_tail, se); 533 GNUNET_CONTAINER_DLL_insert (sub_head, sub_tail, se);
530 if (NULL != ce) 534 if (NULL != ce)
531 ce->subsystem = se; 535 ce->subsystem = se;
532 return se; 536 return se;
@@ -541,12 +545,12 @@ find_subsystem_entry(struct ClientEntry *ce, const char *service)
541 * @return statistis entry, or NULL if not found 545 * @return statistis entry, or NULL if not found
542 */ 546 */
543static struct StatsEntry * 547static struct StatsEntry *
544find_stat_entry(struct SubsystemEntry *se, const char *name) 548find_stat_entry (struct SubsystemEntry *se, const char *name)
545{ 549{
546 struct StatsEntry *pos; 550 struct StatsEntry *pos;
547 551
548 for (pos = se->stat_head; NULL != pos; pos = pos->next) 552 for (pos = se->stat_head; NULL != pos; pos = pos->next)
549 if (0 == strcmp(name, pos->name)) 553 if (0 == strcmp (name, pos->name))
550 return pos; 554 return pos;
551 return NULL; 555 return NULL;
552} 556}
@@ -560,22 +564,22 @@ find_stat_entry(struct SubsystemEntry *se, const char *name)
560 * @return #GNUNET_OK if message is well-formed 564 * @return #GNUNET_OK if message is well-formed
561 */ 565 */
562static int 566static int
563check_set(void *cls, const struct GNUNET_STATISTICS_SetMessage *msg) 567check_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
564{ 568{
565 const char *service; 569 const char *service;
566 const char *name; 570 const char *name;
567 size_t msize; 571 size_t msize;
568 572
569 msize = ntohs(msg->header.size) - sizeof(*msg); 573 msize = ntohs (msg->header.size) - sizeof(*msg);
570 if (msize != GNUNET_STRINGS_buffer_tokenize((const char *)&msg[1], 574 if (msize != GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1],
571 msize, 575 msize,
572 2, 576 2,
573 &service, 577 &service,
574 &name)) 578 &name))
575 { 579 {
576 GNUNET_break(0); 580 GNUNET_break (0);
577 return GNUNET_SYSERR; 581 return GNUNET_SYSERR;
578 } 582 }
579 return GNUNET_OK; 583 return GNUNET_OK;
580} 584}
581 585
@@ -587,7 +591,7 @@ check_set(void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
587 * @param message the actual message 591 * @param message the actual message
588 */ 592 */
589static void 593static void
590handle_set(void *cls, const struct GNUNET_STATISTICS_SetMessage *msg) 594handle_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
591{ 595{
592 struct ClientEntry *ce = cls; 596 struct ClientEntry *ce = cls;
593 const char *service; 597 const char *service;
@@ -603,95 +607,95 @@ handle_set(void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
603 int changed; 607 int changed;
604 int initial_set; 608 int initial_set;
605 609
606 msize = ntohs(msg->header.size); 610 msize = ntohs (msg->header.size);
607 size = msize - sizeof(struct GNUNET_STATISTICS_SetMessage); 611 size = msize - sizeof(struct GNUNET_STATISTICS_SetMessage);
608 GNUNET_assert(size == GNUNET_STRINGS_buffer_tokenize((const char *)&msg[1], 612 GNUNET_assert (size == GNUNET_STRINGS_buffer_tokenize ((const char *) &msg[1],
609 size, 613 size,
610 2, 614 2,
611 &service, 615 &service,
612 &name)); 616 &name));
613 se = find_subsystem_entry(ce, service); 617 se = find_subsystem_entry (ce, service);
614 flags = ntohl(msg->flags); 618 flags = ntohl (msg->flags);
615 value = GNUNET_ntohll(msg->value); 619 value = GNUNET_ntohll (msg->value);
616 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
617 "Received request to update statistic on `%s:%s' (%u) to/by %llu\n", 621 "Received request to update statistic on `%s:%s' (%u) to/by %llu\n",
618 service, 622 service,
619 name, 623 name,
620 (unsigned int)flags, 624 (unsigned int) flags,
621 (unsigned long long)value); 625 (unsigned long long) value);
622 pos = find_stat_entry(se, name); 626 pos = find_stat_entry (se, name);
623 if (NULL != pos) 627 if (NULL != pos)
628 {
629 initial_set = 0;
630 if (0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE))
624 { 631 {
625 initial_set = 0; 632 changed = (pos->value != value);
626 if (0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE)) 633 pos->value = value;
627 { 634 }
628 changed = (pos->value != value); 635 else
629 pos->value = value; 636 {
630 } 637 delta = (int64_t) value;
638 if ((delta < 0) && (pos->value < -delta))
639 {
640 changed = (0 != pos->value);
641 pos->value = 0;
642 }
631 else 643 else
632 { 644 {
633 delta = (int64_t)value; 645 changed = (0 != delta);
634 if ((delta < 0) && (pos->value < -delta)) 646 GNUNET_break ((delta <= 0) || (pos->value + delta > pos->value));
635 { 647 pos->value += delta;
636 changed = (0 != pos->value); 648 }
637 pos->value = 0;
638 }
639 else
640 {
641 changed = (0 != delta);
642 GNUNET_break((delta <= 0) || (pos->value + delta > pos->value));
643 pos->value += delta;
644 }
645 }
646 if (GNUNET_NO == pos->set)
647 {
648 pos->set = GNUNET_YES;
649 initial_set = 1;
650 }
651 pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT));
652 if (pos != se->stat_head)
653 {
654 /* move to front for faster setting next time! */
655 GNUNET_CONTAINER_DLL_remove(se->stat_head, se->stat_tail, pos);
656 GNUNET_CONTAINER_DLL_insert(se->stat_head, se->stat_tail, pos);
657 }
658 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
659 "Statistic `%s:%s' updated to value %llu (%d).\n",
660 service,
661 name,
662 (unsigned long long)pos->value,
663 pos->persistent);
664 if ((changed) || (1 == initial_set))
665 notify_change(pos);
666 GNUNET_SERVICE_client_continue(ce->client);
667 return;
668 } 649 }
669 /* not found, create a new entry */ 650 if (GNUNET_NO == pos->set)
670 nlen = strlen(name) + 1;
671 pos = GNUNET_malloc(sizeof(struct StatsEntry) + nlen);
672 GNUNET_memcpy(&pos[1], name, nlen);
673 pos->name = (const char *)&pos[1];
674 pos->subsystem = se;
675 if ((0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE)) ||
676 (0 < (int64_t)GNUNET_ntohll(msg->value)))
677 { 651 {
678 pos->value = GNUNET_ntohll(msg->value);
679 pos->set = GNUNET_YES; 652 pos->set = GNUNET_YES;
653 initial_set = 1;
680 } 654 }
681 else 655 pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT));
656 if (pos != se->stat_head)
682 { 657 {
683 pos->set = GNUNET_NO; 658 /* move to front for faster setting next time! */
659 GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos);
660 GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos);
684 } 661 }
662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
663 "Statistic `%s:%s' updated to value %llu (%d).\n",
664 service,
665 name,
666 (unsigned long long) pos->value,
667 pos->persistent);
668 if ((changed) || (1 == initial_set))
669 notify_change (pos);
670 GNUNET_SERVICE_client_continue (ce->client);
671 return;
672 }
673 /* not found, create a new entry */
674 nlen = strlen (name) + 1;
675 pos = GNUNET_malloc (sizeof(struct StatsEntry) + nlen);
676 GNUNET_memcpy (&pos[1], name, nlen);
677 pos->name = (const char *) &pos[1];
678 pos->subsystem = se;
679 if ((0 == (flags & GNUNET_STATISTICS_SETFLAG_RELATIVE)) ||
680 (0 < (int64_t) GNUNET_ntohll (msg->value)))
681 {
682 pos->value = GNUNET_ntohll (msg->value);
683 pos->set = GNUNET_YES;
684 }
685 else
686 {
687 pos->set = GNUNET_NO;
688 }
685 pos->uid = uidgen++; 689 pos->uid = uidgen++;
686 pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT)); 690 pos->persistent = (0 != (flags & GNUNET_STATISTICS_SETFLAG_PERSISTENT));
687 GNUNET_CONTAINER_DLL_insert(se->stat_head, se->stat_tail, pos); 691 GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos);
688 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
689 "New statistic on `%s:%s' with value %llu created.\n", 693 "New statistic on `%s:%s' with value %llu created.\n",
690 service, 694 service,
691 name, 695 name,
692 (unsigned long long)pos->value); 696 (unsigned long long) pos->value);
693 if (NULL != ce) 697 if (NULL != ce)
694 GNUNET_SERVICE_client_continue(ce->client); 698 GNUNET_SERVICE_client_continue (ce->client);
695} 699}
696 700
697 701
@@ -703,22 +707,22 @@ handle_set(void *cls, const struct GNUNET_STATISTICS_SetMessage *msg)
703 * @return #GNUNET_OK if message is well-formed 707 * @return #GNUNET_OK if message is well-formed
704 */ 708 */
705static int 709static int
706check_watch(void *cls, const struct GNUNET_MessageHeader *message) 710check_watch (void *cls, const struct GNUNET_MessageHeader *message)
707{ 711{
708 size_t size; 712 size_t size;
709 const char *service; 713 const char *service;
710 const char *name; 714 const char *name;
711 715
712 size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader); 716 size = ntohs (message->size) - sizeof(struct GNUNET_MessageHeader);
713 if (size != GNUNET_STRINGS_buffer_tokenize((const char *)&message[1], 717 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
714 size, 718 size,
715 2, 719 2,
716 &service, 720 &service,
717 &name)) 721 &name))
718 { 722 {
719 GNUNET_break(0); 723 GNUNET_break (0);
720 return GNUNET_SYSERR; 724 return GNUNET_SYSERR;
721 } 725 }
722 return GNUNET_OK; 726 return GNUNET_OK;
723} 727}
724 728
@@ -730,7 +734,7 @@ check_watch(void *cls, const struct GNUNET_MessageHeader *message)
730 * @param message the actual message 734 * @param message the actual message
731 */ 735 */
732static void 736static void
733handle_watch(void *cls, const struct GNUNET_MessageHeader *message) 737handle_watch (void *cls, const struct GNUNET_MessageHeader *message)
734{ 738{
735 struct ClientEntry *ce = cls; 739 struct ClientEntry *ce = cls;
736 const char *service; 740 const char *service;
@@ -743,49 +747,49 @@ handle_watch(void *cls, const struct GNUNET_MessageHeader *message)
743 size_t nlen; 747 size_t nlen;
744 748
745 if (NULL == nc) 749 if (NULL == nc)
746 { 750 {
747 GNUNET_SERVICE_client_drop(ce->client); 751 GNUNET_SERVICE_client_drop (ce->client);
748 return; 752 return;
749 } 753 }
750 GNUNET_SERVICE_client_mark_monitor(ce->client); 754 GNUNET_SERVICE_client_mark_monitor (ce->client);
751 msize = ntohs(message->size); 755 msize = ntohs (message->size);
752 size = msize - sizeof(struct GNUNET_MessageHeader); 756 size = msize - sizeof(struct GNUNET_MessageHeader);
753 GNUNET_assert(size == 757 GNUNET_assert (size ==
754 GNUNET_STRINGS_buffer_tokenize((const char *)&message[1], 758 GNUNET_STRINGS_buffer_tokenize ((const char *) &message[1],
755 size, 759 size,
756 2, 760 2,
757 &service, 761 &service,
758 &name)); 762 &name));
759 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
760 "Received request to watch statistic on `%s:%s'\n", 764 "Received request to watch statistic on `%s:%s'\n",
761 service, 765 service,
762 name); 766 name);
763 se = find_subsystem_entry(ce, service); 767 se = find_subsystem_entry (ce, service);
764 pos = find_stat_entry(se, name); 768 pos = find_stat_entry (se, name);
765 if (NULL == pos) 769 if (NULL == pos)
766 { 770 {
767 nlen = strlen(name) + 1; 771 nlen = strlen (name) + 1;
768 pos = GNUNET_malloc(sizeof(struct StatsEntry) + nlen); 772 pos = GNUNET_malloc (sizeof(struct StatsEntry) + nlen);
769 GNUNET_memcpy(&pos[1], name, nlen); 773 GNUNET_memcpy (&pos[1], name, nlen);
770 pos->name = (const char *)&pos[1]; 774 pos->name = (const char *) &pos[1];
771 pos->subsystem = se; 775 pos->subsystem = se;
772 GNUNET_CONTAINER_DLL_insert(se->stat_head, se->stat_tail, pos); 776 GNUNET_CONTAINER_DLL_insert (se->stat_head, se->stat_tail, pos);
773 pos->uid = uidgen++; 777 pos->uid = uidgen++;
774 pos->set = GNUNET_NO; 778 pos->set = GNUNET_NO;
775 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
776 "New statistic on `%s:%s' with value %llu created.\n", 780 "New statistic on `%s:%s' with value %llu created.\n",
777 service, 781 service,
778 name, 782 name,
779 (unsigned long long)pos->value); 783 (unsigned long long) pos->value);
780 } 784 }
781 we = GNUNET_new(struct WatchEntry); 785 we = GNUNET_new (struct WatchEntry);
782 we->ce = ce; 786 we->ce = ce;
783 we->last_value_set = GNUNET_NO; 787 we->last_value_set = GNUNET_NO;
784 we->wid = ce->max_wid++; 788 we->wid = ce->max_wid++;
785 GNUNET_CONTAINER_DLL_insert(pos->we_head, pos->we_tail, we); 789 GNUNET_CONTAINER_DLL_insert (pos->we_head, pos->we_tail, we);
786 if (0 != pos->value) 790 if (0 != pos->value)
787 notify_change(pos); 791 notify_change (pos);
788 GNUNET_SERVICE_client_continue(ce->client); 792 GNUNET_SERVICE_client_continue (ce->client);
789} 793}
790 794
791 795
@@ -798,15 +802,15 @@ handle_watch(void *cls, const struct GNUNET_MessageHeader *message)
798 * @param message the actual message 802 * @param message the actual message
799 */ 803 */
800static void 804static void
801handle_disconnect(void *cls, const struct GNUNET_MessageHeader *message) 805handle_disconnect (void *cls, const struct GNUNET_MessageHeader *message)
802{ 806{
803 struct ClientEntry *ce = cls; 807 struct ClientEntry *ce = cls;
804 struct GNUNET_MQ_Envelope *env; 808 struct GNUNET_MQ_Envelope *env;
805 struct GNUNET_MessageHeader *msg; 809 struct GNUNET_MessageHeader *msg;
806 810
807 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM); 811 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM);
808 GNUNET_MQ_send(ce->mq, env); 812 GNUNET_MQ_send (ce->mq, env);
809 GNUNET_SERVICE_client_continue(ce->client); 813 GNUNET_SERVICE_client_continue (ce->client);
810} 814}
811 815
812 816
@@ -814,7 +818,7 @@ handle_disconnect(void *cls, const struct GNUNET_MessageHeader *message)
814 * Actually perform the shutdown. 818 * Actually perform the shutdown.
815 */ 819 */
816static void 820static void
817do_shutdown() 821do_shutdown ()
818{ 822{
819 struct WatchEntry *we; 823 struct WatchEntry *we;
820 struct StatsEntry *pos; 824 struct StatsEntry *pos;
@@ -822,26 +826,26 @@ do_shutdown()
822 826
823 if (NULL == nc) 827 if (NULL == nc)
824 return; 828 return;
825 save(); 829 save ();
826 GNUNET_notification_context_destroy(nc); 830 GNUNET_notification_context_destroy (nc);
827 nc = NULL; 831 nc = NULL;
828 GNUNET_assert(0 == client_count); 832 GNUNET_assert (0 == client_count);
829 while (NULL != (se = sub_head)) 833 while (NULL != (se = sub_head))
834 {
835 GNUNET_CONTAINER_DLL_remove (sub_head, sub_tail, se);
836 while (NULL != (pos = se->stat_head))
830 { 837 {
831 GNUNET_CONTAINER_DLL_remove(sub_head, sub_tail, se); 838 GNUNET_CONTAINER_DLL_remove (se->stat_head, se->stat_tail, pos);
832 while (NULL != (pos = se->stat_head)) 839 while (NULL != (we = pos->we_head))
833 { 840 {
834 GNUNET_CONTAINER_DLL_remove(se->stat_head, se->stat_tail, pos); 841 GNUNET_break (0);
835 while (NULL != (we = pos->we_head)) 842 GNUNET_CONTAINER_DLL_remove (pos->we_head, pos->we_tail, we);
836 { 843 GNUNET_free (we);
837 GNUNET_break(0); 844 }
838 GNUNET_CONTAINER_DLL_remove(pos->we_head, pos->we_tail, we); 845 GNUNET_free (pos);
839 GNUNET_free(we);
840 }
841 GNUNET_free(pos);
842 }
843 GNUNET_free(se);
844 } 846 }
847 GNUNET_free (se);
848 }
845} 849}
846 850
847 851
@@ -851,12 +855,12 @@ do_shutdown()
851 * @param cls unused 855 * @param cls unused
852 */ 856 */
853static void 857static void
854shutdown_task(void *cls) 858shutdown_task (void *cls)
855{ 859{
856 in_shutdown = GNUNET_YES; 860 in_shutdown = GNUNET_YES;
857 if (0 != client_count) 861 if (0 != client_count)
858 return; 862 return;
859 do_shutdown(); 863 do_shutdown ();
860} 864}
861 865
862 866
@@ -868,9 +872,9 @@ shutdown_task(void *cls)
868 * @param app_cls the `struct ClientEntry *` 872 * @param app_cls the `struct ClientEntry *`
869 */ 873 */
870static void 874static void
871client_disconnect_cb(void *cls, 875client_disconnect_cb (void *cls,
872 struct GNUNET_SERVICE_Client *client, 876 struct GNUNET_SERVICE_Client *client,
873 void *app_cls) 877 void *app_cls)
874{ 878{
875 struct ClientEntry *ce = app_cls; 879 struct ClientEntry *ce = app_cls;
876 struct WatchEntry *we; 880 struct WatchEntry *we;
@@ -880,23 +884,23 @@ client_disconnect_cb(void *cls,
880 884
881 client_count--; 885 client_count--;
882 for (se = sub_head; NULL != se; se = se->next) 886 for (se = sub_head; NULL != se; se = se->next)
887 {
888 for (pos = se->stat_head; NULL != pos; pos = pos->next)
883 { 889 {
884 for (pos = se->stat_head; NULL != pos; pos = pos->next) 890 wen = pos->we_head;
885 { 891 while (NULL != (we = wen))
886 wen = pos->we_head; 892 {
887 while (NULL != (we = wen)) 893 wen = we->next;
888 { 894 if (we->ce != ce)
889 wen = we->next; 895 continue;
890 if (we->ce != ce) 896 GNUNET_CONTAINER_DLL_remove (pos->we_head, pos->we_tail, we);
891 continue; 897 GNUNET_free (we);
892 GNUNET_CONTAINER_DLL_remove(pos->we_head, pos->we_tail, we); 898 }
893 GNUNET_free(we);
894 }
895 }
896 } 899 }
897 GNUNET_free(ce); 900 }
901 GNUNET_free (ce);
898 if ((0 == client_count) && (GNUNET_YES == in_shutdown)) 902 if ((0 == client_count) && (GNUNET_YES == in_shutdown))
899 do_shutdown(); 903 do_shutdown ();
900} 904}
901 905
902 906
@@ -912,19 +916,19 @@ client_disconnect_cb(void *cls,
912 * #GNUNET_SYSERR to stop further processing with error 916 * #GNUNET_SYSERR to stop further processing with error
913 */ 917 */
914static int 918static int
915inject_message(void *cls, const struct GNUNET_MessageHeader *message) 919inject_message (void *cls, const struct GNUNET_MessageHeader *message)
916{ 920{
917 uint16_t msize = ntohs(message->size); 921 uint16_t msize = ntohs (message->size);
918 const struct GNUNET_STATISTICS_SetMessage *sm; 922 const struct GNUNET_STATISTICS_SetMessage *sm;
919 923
920 sm = (const struct GNUNET_STATISTICS_SetMessage *)message; 924 sm = (const struct GNUNET_STATISTICS_SetMessage *) message;
921 if ((sizeof(struct GNUNET_STATISTICS_SetMessage) > msize) || 925 if ((sizeof(struct GNUNET_STATISTICS_SetMessage) > msize) ||
922 (GNUNET_OK != check_set(NULL, sm))) 926 (GNUNET_OK != check_set (NULL, sm)))
923 { 927 {
924 GNUNET_break(0); 928 GNUNET_break (0);
925 return GNUNET_SYSERR; 929 return GNUNET_SYSERR;
926 } 930 }
927 handle_set(NULL, sm); 931 handle_set (NULL, sm);
928 return GNUNET_OK; 932 return GNUNET_OK;
929} 933}
930 934
@@ -934,7 +938,7 @@ inject_message(void *cls, const struct GNUNET_MessageHeader *message)
934 * format that we also use for setting the values over the network. 938 * format that we also use for setting the values over the network.
935 */ 939 */
936static void 940static void
937load() 941load ()
938{ 942{
939 char *fn; 943 char *fn;
940 struct GNUNET_BIO_ReadHandle *rh; 944 struct GNUNET_BIO_ReadHandle *rh;
@@ -942,51 +946,51 @@ load()
942 char *buf; 946 char *buf;
943 struct GNUNET_MessageStreamTokenizer *mst; 947 struct GNUNET_MessageStreamTokenizer *mst;
944 948
945 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, 949 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
946 "STATISTICS", 950 "STATISTICS",
947 "DATABASE", 951 "DATABASE",
948 &fn)) 952 &fn))
949 { 953 {
950 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 954 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
951 "STATISTICS", 955 "STATISTICS",
952 "DATABASE"); 956 "DATABASE");
953 return; 957 return;
954 } 958 }
955 if ((GNUNET_OK != 959 if ((GNUNET_OK !=
956 GNUNET_DISK_file_size(fn, &fsize, GNUNET_NO, GNUNET_YES)) || 960 GNUNET_DISK_file_size (fn, &fsize, GNUNET_NO, GNUNET_YES)) ||
957 (0 == fsize)) 961 (0 == fsize))
958 { 962 {
959 GNUNET_free(fn); 963 GNUNET_free (fn);
960 return; 964 return;
961 } 965 }
962 buf = GNUNET_malloc(fsize); 966 buf = GNUNET_malloc (fsize);
963 rh = GNUNET_BIO_read_open(fn); 967 rh = GNUNET_BIO_read_open (fn);
964 if (!rh) 968 if (! rh)
965 { 969 {
966 GNUNET_free(buf); 970 GNUNET_free (buf);
967 GNUNET_free(fn); 971 GNUNET_free (fn);
968 return; 972 return;
969 } 973 }
970 if (GNUNET_OK != GNUNET_BIO_read(rh, fn, buf, fsize)) 974 if (GNUNET_OK != GNUNET_BIO_read (rh, fn, buf, fsize))
971 { 975 {
972 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "read", fn); 976 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "read", fn);
973 GNUNET_break(GNUNET_OK == GNUNET_BIO_read_close(rh, NULL)); 977 GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
974 GNUNET_free(buf); 978 GNUNET_free (buf);
975 GNUNET_free(fn); 979 GNUNET_free (fn);
976 return; 980 return;
977 } 981 }
978 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 982 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
979 _("Loading %llu bytes of statistics from `%s'\n"), 983 _ ("Loading %llu bytes of statistics from `%s'\n"),
980 (unsigned long long)fsize, 984 (unsigned long long) fsize,
981 fn); 985 fn);
982 mst = GNUNET_MST_create(&inject_message, NULL); 986 mst = GNUNET_MST_create (&inject_message, NULL);
983 GNUNET_break( 987 GNUNET_break (
984 GNUNET_OK == 988 GNUNET_OK ==
985 GNUNET_MST_from_buffer(mst, buf, (size_t)fsize, GNUNET_YES, GNUNET_NO)); 989 GNUNET_MST_from_buffer (mst, buf, (size_t) fsize, GNUNET_YES, GNUNET_NO));
986 GNUNET_MST_destroy(mst); 990 GNUNET_MST_destroy (mst);
987 GNUNET_free(buf); 991 GNUNET_free (buf);
988 GNUNET_break(GNUNET_OK == GNUNET_BIO_read_close(rh, NULL)); 992 GNUNET_break (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL));
989 GNUNET_free(fn); 993 GNUNET_free (fn);
990} 994}
991 995
992 996
@@ -998,44 +1002,44 @@ load()
998 * @param service the initialized service 1002 * @param service the initialized service
999 */ 1003 */
1000static void 1004static void
1001run(void *cls, 1005run (void *cls,
1002 const struct GNUNET_CONFIGURATION_Handle *c, 1006 const struct GNUNET_CONFIGURATION_Handle *c,
1003 struct GNUNET_SERVICE_Handle *service) 1007 struct GNUNET_SERVICE_Handle *service)
1004{ 1008{
1005 cfg = c; 1009 cfg = c;
1006 nc = GNUNET_notification_context_create(16); 1010 nc = GNUNET_notification_context_create (16);
1007 load(); 1011 load ();
1008 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 1012 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1009} 1013}
1010 1014
1011 1015
1012/** 1016/**
1013 * Define "main" method using service macro. 1017 * Define "main" method using service macro.
1014 */ 1018 */
1015GNUNET_SERVICE_MAIN( 1019GNUNET_SERVICE_MAIN (
1016 "statistics", 1020 "statistics",
1017 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, 1021 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN,
1018 &run, 1022 &run,
1019 &client_connect_cb, 1023 &client_connect_cb,
1020 &client_disconnect_cb, 1024 &client_disconnect_cb,
1021 NULL, 1025 NULL,
1022 GNUNET_MQ_hd_var_size(set, 1026 GNUNET_MQ_hd_var_size (set,
1023 GNUNET_MESSAGE_TYPE_STATISTICS_SET, 1027 GNUNET_MESSAGE_TYPE_STATISTICS_SET,
1024 struct GNUNET_STATISTICS_SetMessage, 1028 struct GNUNET_STATISTICS_SetMessage,
1025 NULL), 1029 NULL),
1026 GNUNET_MQ_hd_var_size(get, 1030 GNUNET_MQ_hd_var_size (get,
1027 GNUNET_MESSAGE_TYPE_STATISTICS_GET, 1031 GNUNET_MESSAGE_TYPE_STATISTICS_GET,
1028 struct GNUNET_MessageHeader, 1032 struct GNUNET_MessageHeader,
1029 NULL), 1033 NULL),
1030 GNUNET_MQ_hd_var_size(watch, 1034 GNUNET_MQ_hd_var_size (watch,
1031 GNUNET_MESSAGE_TYPE_STATISTICS_WATCH, 1035 GNUNET_MESSAGE_TYPE_STATISTICS_WATCH,
1032 struct GNUNET_MessageHeader, 1036 struct GNUNET_MessageHeader,
1033 NULL), 1037 NULL),
1034 GNUNET_MQ_hd_fixed_size(disconnect, 1038 GNUNET_MQ_hd_fixed_size (disconnect,
1035 GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT, 1039 GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT,
1036 struct GNUNET_MessageHeader, 1040 struct GNUNET_MessageHeader,
1037 NULL), 1041 NULL),
1038 GNUNET_MQ_handler_end()); 1042 GNUNET_MQ_handler_end ());
1039 1043
1040 1044
1041#if defined(LINUX) && defined(__GLIBC__) 1045#if defined(LINUX) && defined(__GLIBC__)
@@ -1044,11 +1048,11 @@ GNUNET_SERVICE_MAIN(
1044/** 1048/**
1045 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 1049 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1046 */ 1050 */
1047void __attribute__ ((constructor)) GNUNET_STATISTICS_memory_init() 1051void __attribute__ ((constructor)) GNUNET_STATISTICS_memory_init ()
1048{ 1052{
1049 mallopt(M_TRIM_THRESHOLD, 4 * 1024); 1053 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1050 mallopt(M_TOP_PAD, 1 * 1024); 1054 mallopt (M_TOP_PAD, 1 * 1024);
1051 malloc_trim(0); 1055 malloc_trim (0);
1052} 1056}
1053#endif 1057#endif
1054 1058