aboutsummaryrefslogtreecommitdiff
path: root/src/statistics
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/statistics
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/statistics')
-rw-r--r--src/statistics/gnunet-service-statistics.c842
-rw-r--r--src/statistics/gnunet-statistics.c786
-rw-r--r--src/statistics/statistics.h11
-rw-r--r--src/statistics/statistics_api.c1120
-rw-r--r--src/statistics/test_statistics_api.c284
-rw-r--r--src/statistics/test_statistics_api_loop.c90
-rw-r--r--src/statistics/test_statistics_api_watch.c128
-rw-r--r--src/statistics/test_statistics_api_watch_zero_value.c176
8 files changed, 1726 insertions, 1711 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
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c
index 470bb2ed8..aba80ab36 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -93,7 +93,8 @@ static int set_value;
93/** 93/**
94 * @brief Representation of all (testbed) nodes. 94 * @brief Representation of all (testbed) nodes.
95 */ 95 */
96static struct Node { 96static struct Node
97{
97 /** 98 /**
98 * @brief Index of the node in this array. 99 * @brief Index of the node in this array.
99 */ 100 */
@@ -117,7 +118,7 @@ static struct Node {
117 * @brief Identifier for shutdown task for this node. 118 * @brief Identifier for shutdown task for this node.
118 */ 119 */
119 struct GNUNET_SCHEDULER_Task *shutdown_task; 120 struct GNUNET_SCHEDULER_Task *shutdown_task;
120} * nodes; 121} *nodes;
121 122
122/** 123/**
123 * @brief Number of configurations of all (testbed) nodes. 124 * @brief Number of configurations of all (testbed) nodes.
@@ -127,7 +128,8 @@ static unsigned num_nodes;
127/** 128/**
128 * @brief Set of values for a combination of subsystem and name. 129 * @brief Set of values for a combination of subsystem and name.
129 */ 130 */
130struct ValueSet { 131struct ValueSet
132{
131 /** 133 /**
132 * @brief Subsystem of the valueset. 134 * @brief Subsystem of the valueset.
133 */ 135 */
@@ -175,17 +177,17 @@ static int num_nodes_ready_shutdown;
175 * @return Newly allocated #ValueSet. 177 * @return Newly allocated #ValueSet.
176 */ 178 */
177static struct ValueSet * 179static struct ValueSet *
178new_value_set(const char *subsystem, 180new_value_set (const char *subsystem,
179 const char *name, 181 const char *name,
180 unsigned num_values, 182 unsigned num_values,
181 int is_persistent) 183 int is_persistent)
182{ 184{
183 struct ValueSet *value_set; 185 struct ValueSet *value_set;
184 186
185 value_set = GNUNET_new(struct ValueSet); 187 value_set = GNUNET_new (struct ValueSet);
186 value_set->subsystem = GNUNET_strdup(subsystem); 188 value_set->subsystem = GNUNET_strdup (subsystem);
187 value_set->name = GNUNET_strdup(name); 189 value_set->name = GNUNET_strdup (name);
188 value_set->values = GNUNET_new_array(num_values, uint64_t); 190 value_set->values = GNUNET_new_array (num_values, uint64_t);
189 value_set->is_persistent = persistent; 191 value_set->is_persistent = persistent;
190 return value_set; 192 return value_set;
191} 193}
@@ -203,56 +205,56 @@ new_value_set(const char *subsystem,
203 * @return GNUNET_YES - continue iteration. 205 * @return GNUNET_YES - continue iteration.
204 */ 206 */
205static int 207static int
206printer(void *cls, const struct GNUNET_HashCode *key, void *value) 208printer (void *cls, const struct GNUNET_HashCode *key, void *value)
207{ 209{
208 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 210 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
209 const char *now_str; 211 const char *now_str;
210 struct ValueSet *value_set = value; 212 struct ValueSet *value_set = value;
211 213
212 if (quiet == GNUNET_NO) 214 if (quiet == GNUNET_NO)
215 {
216 if (GNUNET_YES == watch)
213 { 217 {
214 if (GNUNET_YES == watch) 218 now_str = GNUNET_STRINGS_absolute_time_to_string (now);
215 { 219 fprintf (stdout,
216 now_str = GNUNET_STRINGS_absolute_time_to_string(now); 220 "%24s%s %s%s%12s%s %s%50s%s%s ",
217 fprintf(stdout, 221 now_str,
218 "%24s%s %s%s%12s%s %s%50s%s%s ", 222 csv_separator,
219 now_str, 223 value_set->is_persistent ? "!" : " ",
220 csv_separator, 224 csv_separator,
221 value_set->is_persistent ? "!" : " ", 225 value_set->subsystem,
222 csv_separator, 226 csv_separator,
223 value_set->subsystem, 227 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
224 csv_separator, 228 _ (value_set->name),
225 (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */ 229 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
226 _(value_set->name), 230 (0 == strlen (csv_separator) ? ":" : csv_separator));
227 (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */
228 (0 == strlen(csv_separator) ? ":" : csv_separator));
229 }
230 else
231 {
232 fprintf(stdout,
233 "%s%s%12s%s %s%50s%s%s ",
234 value_set->is_persistent ? "!" : " ",
235 csv_separator,
236 value_set->subsystem,
237 csv_separator,
238 (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */
239 _(value_set->name),
240 (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */
241 (0 == strlen(csv_separator) ? ":" : csv_separator));
242 }
243 } 231 }
244 for (unsigned i = 0; i < num_nodes; i++) 232 else
245 { 233 {
246 fprintf(stdout, 234 fprintf (stdout,
247 "%16llu%s", 235 "%s%s%12s%s %s%50s%s%s ",
248 (unsigned long long)value_set->values[i], 236 value_set->is_persistent ? "!" : " ",
249 csv_separator); 237 csv_separator,
238 value_set->subsystem,
239 csv_separator,
240 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
241 _ (value_set->name),
242 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
243 (0 == strlen (csv_separator) ? ":" : csv_separator));
250 } 244 }
251 fprintf(stdout, "\n"); 245 }
252 GNUNET_free(value_set->subsystem); 246 for (unsigned i = 0; i < num_nodes; i++)
253 GNUNET_free(value_set->name); 247 {
254 GNUNET_free(value_set->values); 248 fprintf (stdout,
255 GNUNET_free(value_set); 249 "%16llu%s",
250 (unsigned long long) value_set->values[i],
251 csv_separator);
252 }
253 fprintf (stdout, "\n");
254 GNUNET_free (value_set->subsystem);
255 GNUNET_free (value_set->name);
256 GNUNET_free (value_set->values);
257 GNUNET_free (value_set);
256 return GNUNET_YES; 258 return GNUNET_YES;
257} 259}
258 260
@@ -267,51 +269,51 @@ printer(void *cls, const struct GNUNET_HashCode *key, void *value)
267 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 269 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
268 */ 270 */
269static int 271static int
270printer_watch(void *cls, 272printer_watch (void *cls,
271 const char *subsystem, 273 const char *subsystem,
272 const char *name, 274 const char *name,
273 uint64_t value, 275 uint64_t value,
274 int is_persistent) 276 int is_persistent)
275{ 277{
276 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 278 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
277 const char *now_str; 279 const char *now_str;
278 280
279 if (quiet == GNUNET_NO) 281 if (quiet == GNUNET_NO)
282 {
283 if (GNUNET_YES == watch)
280 { 284 {
281 if (GNUNET_YES == watch) 285 now_str = GNUNET_STRINGS_absolute_time_to_string (now);
282 { 286 fprintf (stdout,
283 now_str = GNUNET_STRINGS_absolute_time_to_string(now); 287 "%24s%s %s%s%12s%s %s%50s%s%s %16llu\n",
284 fprintf(stdout, 288 now_str,
285 "%24s%s %s%s%12s%s %s%50s%s%s %16llu\n", 289 csv_separator,
286 now_str, 290 is_persistent ? "!" : " ",
287 csv_separator, 291 csv_separator,
288 is_persistent ? "!" : " ", 292 subsystem,
289 csv_separator, 293 csv_separator,
290 subsystem, 294 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
291 csv_separator, 295 _ (name),
292 (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */ 296 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
293 _(name), 297 (0 == strlen (csv_separator) ? ":" : csv_separator),
294 (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */ 298 (unsigned long long) value);
295 (0 == strlen(csv_separator) ? ":" : csv_separator),
296 (unsigned long long)value);
297 }
298 else
299 {
300 fprintf(stdout,
301 "%s%s%12s%s %s%50s%s%s %16llu\n",
302 is_persistent ? "!" : " ",
303 csv_separator,
304 subsystem,
305 csv_separator,
306 (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */
307 _(name),
308 (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */
309 (0 == strlen(csv_separator) ? ":" : csv_separator),
310 (unsigned long long)value);
311 }
312 } 299 }
300 else
301 {
302 fprintf (stdout,
303 "%s%s%12s%s %s%50s%s%s %16llu\n",
304 is_persistent ? "!" : " ",
305 csv_separator,
306 subsystem,
307 csv_separator,
308 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
309 _ (name),
310 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
311 (0 == strlen (csv_separator) ? ":" : csv_separator),
312 (unsigned long long) value);
313 }
314 }
313 else 315 else
314 fprintf(stdout, "%llu\n", (unsigned long long)value); 316 fprintf (stdout, "%llu\n", (unsigned long long) value);
315 317
316 return GNUNET_OK; 318 return GNUNET_OK;
317} 319}
@@ -324,50 +326,50 @@ printer_watch(void *cls,
324 * @param cls the index of the node 326 * @param cls the index of the node
325 */ 327 */
326static void 328static void
327clean_node(void *cls) 329clean_node (void *cls)
328{ 330{
329 const unsigned index_node = *(unsigned *)cls; 331 const unsigned index_node = *(unsigned *) cls;
330 struct GNUNET_STATISTICS_Handle *h; 332 struct GNUNET_STATISTICS_Handle *h;
331 struct GNUNET_STATISTICS_GetHandle *gh; 333 struct GNUNET_STATISTICS_GetHandle *gh;
332 334
333 if ((NULL != path_testbed) && /* were issued with -t <testbed-path> option */ 335 if ((NULL != path_testbed) && /* were issued with -t <testbed-path> option */
334 (NULL != nodes[index_node].conf)) 336 (NULL != nodes[index_node].conf))
335 { 337 {
336 GNUNET_CONFIGURATION_destroy(nodes[index_node].conf); 338 GNUNET_CONFIGURATION_destroy (nodes[index_node].conf);
337 nodes[index_node].conf = NULL; 339 nodes[index_node].conf = NULL;
338 } 340 }
339 341
340 h = nodes[index_node].handle; 342 h = nodes[index_node].handle;
341 gh = nodes[index_node].gh; 343 gh = nodes[index_node].gh;
342 344
343 if (NULL != gh) 345 if (NULL != gh)
344 { 346 {
345 GNUNET_STATISTICS_get_cancel(gh); 347 GNUNET_STATISTICS_get_cancel (gh);
346 gh = NULL; 348 gh = NULL;
347 } 349 }
348 if (GNUNET_YES == watch) 350 if (GNUNET_YES == watch)
349 { 351 {
350 GNUNET_assert( 352 GNUNET_assert (
351 GNUNET_OK == 353 GNUNET_OK ==
352 GNUNET_STATISTICS_watch_cancel(h, 354 GNUNET_STATISTICS_watch_cancel (h,
353 subsystem, 355 subsystem,
354 name, 356 name,
355 &printer_watch, 357 &printer_watch,
356 &nodes[index_node].index_node)); 358 &nodes[index_node].index_node));
357 } 359 }
358 360
359 if (NULL != h) 361 if (NULL != h)
360 { 362 {
361 GNUNET_STATISTICS_destroy(h, GNUNET_NO); 363 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
362 h = NULL; 364 h = NULL;
363 } 365 }
364 366
365 num_nodes_ready_shutdown++; 367 num_nodes_ready_shutdown++;
366 if (num_nodes == num_nodes_ready_shutdown) 368 if (num_nodes == num_nodes_ready_shutdown)
367 { 369 {
368 GNUNET_array_grow(nodes, num_nodes, 0); 370 GNUNET_array_grow (nodes, num_nodes, 0);
369 GNUNET_CONTAINER_multihashmap_destroy(values); 371 GNUNET_CONTAINER_multihashmap_destroy (values);
370 } 372 }
371} 373}
372 374
373/** 375/**
@@ -376,10 +378,10 @@ clean_node(void *cls)
376 * @param cls unused 378 * @param cls unused
377 */ 379 */
378static void 380static void
379print_finish(void *cls) 381print_finish (void *cls)
380{ 382{
381 GNUNET_CONTAINER_multihashmap_iterate(values, printer, NULL); 383 GNUNET_CONTAINER_multihashmap_iterate (values, printer, NULL);
382 GNUNET_SCHEDULER_shutdown(); 384 GNUNET_SCHEDULER_shutdown ();
383} 385}
384 386
385/** 387/**
@@ -391,33 +393,33 @@ print_finish(void *cls)
391 * @param succes Whether statistics were obtained successfully. 393 * @param succes Whether statistics were obtained successfully.
392 */ 394 */
393static void 395static void
394continuation_print(void *cls, int success) 396continuation_print (void *cls, int success)
395{ 397{
396 const unsigned index_node = *(unsigned *)cls; 398 const unsigned index_node = *(unsigned *) cls;
397 399
398 nodes[index_node].gh = NULL; 400 nodes[index_node].gh = NULL;
399 if (GNUNET_OK != success) 401 if (GNUNET_OK != success)
400 { 402 {
401 if (NULL == remote_host) 403 if (NULL == remote_host)
402 fprintf(stderr, "%s", _("Failed to obtain statistics.\n")); 404 fprintf (stderr, "%s", _ ("Failed to obtain statistics.\n"));
403 else 405 else
404 fprintf(stderr, 406 fprintf (stderr,
405 _("Failed to obtain statistics from host `%s:%llu'\n"), 407 _ ("Failed to obtain statistics from host `%s:%llu'\n"),
406 remote_host, 408 remote_host,
407 remote_port); 409 remote_port);
408 ret = 1; 410 ret = 1;
409 } 411 }
410 if (NULL != nodes[index_node].shutdown_task) 412 if (NULL != nodes[index_node].shutdown_task)
411 { 413 {
412 GNUNET_SCHEDULER_cancel(nodes[index_node].shutdown_task); 414 GNUNET_SCHEDULER_cancel (nodes[index_node].shutdown_task);
413 nodes[index_node].shutdown_task = NULL; 415 nodes[index_node].shutdown_task = NULL;
414 } 416 }
415 GNUNET_SCHEDULER_add_now(clean_node, &nodes[index_node].index_node); 417 GNUNET_SCHEDULER_add_now (clean_node, &nodes[index_node].index_node);
416 num_nodes_ready++; 418 num_nodes_ready++;
417 if (num_nodes_ready == num_nodes) 419 if (num_nodes_ready == num_nodes)
418 { 420 {
419 GNUNET_SCHEDULER_add_now(print_finish, NULL); 421 GNUNET_SCHEDULER_add_now (print_finish, NULL);
420 } 422 }
421} 423}
422 424
423/** 425/**
@@ -428,24 +430,24 @@ continuation_print(void *cls, int success)
428 * successfully obtained, #GNUNET_SYSERR if not. 430 * successfully obtained, #GNUNET_SYSERR if not.
429 */ 431 */
430static void 432static void
431cleanup(void *cls, int success) 433cleanup (void *cls, int success)
432{ 434{
433 for (unsigned i = 0; i < num_nodes; i++) 435 for (unsigned i = 0; i < num_nodes; i++)
434 { 436 {
435 nodes[i].gh = NULL; 437 nodes[i].gh = NULL;
436 } 438 }
437 if (GNUNET_OK != success) 439 if (GNUNET_OK != success)
438 { 440 {
439 if (NULL == remote_host) 441 if (NULL == remote_host)
440 fprintf(stderr, "%s", _("Failed to obtain statistics.\n")); 442 fprintf (stderr, "%s", _ ("Failed to obtain statistics.\n"));
441 else 443 else
442 fprintf(stderr, 444 fprintf (stderr,
443 _("Failed to obtain statistics from host `%s:%llu'\n"), 445 _ ("Failed to obtain statistics from host `%s:%llu'\n"),
444 remote_host, 446 remote_host,
445 remote_port); 447 remote_port);
446 ret = 1; 448 ret = 1;
447 } 449 }
448 GNUNET_SCHEDULER_shutdown(); 450 GNUNET_SCHEDULER_shutdown ();
449} 451}
450 452
451/** 453/**
@@ -461,40 +463,40 @@ cleanup(void *cls, int success)
461 * @return GNUNET_OK - continue. 463 * @return GNUNET_OK - continue.
462 */ 464 */
463static int 465static int
464collector(void *cls, 466collector (void *cls,
465 const char *subsystem, 467 const char *subsystem,
466 const char *name, 468 const char *name,
467 uint64_t value, 469 uint64_t value,
468 int is_persistent) 470 int is_persistent)
469{ 471{
470 const unsigned index_node = *(unsigned *)cls; 472 const unsigned index_node = *(unsigned *) cls;
471 struct GNUNET_HashCode *key; 473 struct GNUNET_HashCode *key;
472 struct GNUNET_HashCode hc; 474 struct GNUNET_HashCode hc;
473 char *subsys_name; 475 char *subsys_name;
474 unsigned len_subsys_name; 476 unsigned len_subsys_name;
475 struct ValueSet *value_set; 477 struct ValueSet *value_set;
476 478
477 len_subsys_name = strlen(subsystem) + 3 + strlen(name) + 1; 479 len_subsys_name = strlen (subsystem) + 3 + strlen (name) + 1;
478 subsys_name = GNUNET_malloc(len_subsys_name); 480 subsys_name = GNUNET_malloc (len_subsys_name);
479 sprintf(subsys_name, "%s---%s", subsystem, name); 481 sprintf (subsys_name, "%s---%s", subsystem, name);
480 key = &hc; 482 key = &hc;
481 GNUNET_CRYPTO_hash(subsys_name, len_subsys_name, key); 483 GNUNET_CRYPTO_hash (subsys_name, len_subsys_name, key);
482 GNUNET_free(subsys_name); 484 GNUNET_free (subsys_name);
483 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(values, key)) 485 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (values, key))
484 { 486 {
485 value_set = GNUNET_CONTAINER_multihashmap_get(values, key); 487 value_set = GNUNET_CONTAINER_multihashmap_get (values, key);
486 } 488 }
487 else 489 else
488 { 490 {
489 value_set = new_value_set(subsystem, name, num_nodes, is_persistent); 491 value_set = new_value_set (subsystem, name, num_nodes, is_persistent);
490 } 492 }
491 value_set->values[index_node] = value; 493 value_set->values[index_node] = value;
492 GNUNET_assert(GNUNET_YES == 494 GNUNET_assert (GNUNET_YES ==
493 GNUNET_CONTAINER_multihashmap_put( 495 GNUNET_CONTAINER_multihashmap_put (
494 values, 496 values,
495 key, 497 key,
496 value_set, 498 value_set,
497 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 499 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
498 return GNUNET_OK; 500 return GNUNET_OK;
499} 501}
500 502
@@ -504,80 +506,80 @@ collector(void *cls,
504 * @param cls closure with our configuration 506 * @param cls closure with our configuration
505 */ 507 */
506static void 508static void
507main_task(void *cls) 509main_task (void *cls)
508{ 510{
509 unsigned index_node = *(unsigned *)cls; 511 unsigned index_node = *(unsigned *) cls;
510 const struct GNUNET_CONFIGURATION_Handle *cfg = nodes[index_node].conf; 512 const struct GNUNET_CONFIGURATION_Handle *cfg = nodes[index_node].conf;
511 513
512 if (set_value) 514 if (set_value)
515 {
516 if (NULL == subsystem)
513 { 517 {
514 if (NULL == subsystem) 518 fprintf (stderr, "%s", _ ("Missing argument: subsystem \n"));
515 { 519 ret = 1;
516 fprintf(stderr, "%s", _("Missing argument: subsystem \n"));
517 ret = 1;
518 return;
519 }
520 if (NULL == name)
521 {
522 fprintf(stderr, "%s", _("Missing argument: name\n"));
523 ret = 1;
524 return;
525 }
526 nodes[index_node].handle = GNUNET_STATISTICS_create(subsystem, cfg);
527 if (NULL == nodes[index_node].handle)
528 {
529 ret = 1;
530 return;
531 }
532 GNUNET_STATISTICS_set(nodes[index_node].handle,
533 name,
534 (uint64_t)set_val,
535 persistent);
536 GNUNET_STATISTICS_destroy(nodes[index_node].handle, GNUNET_YES);
537 nodes[index_node].handle = NULL;
538 return; 520 return;
539 } 521 }
540 if (NULL == (nodes[index_node].handle = 522 if (NULL == name)
541 GNUNET_STATISTICS_create("gnunet-statistics", cfg)))
542 { 523 {
524 fprintf (stderr, "%s", _ ("Missing argument: name\n"));
543 ret = 1; 525 ret = 1;
544 return; 526 return;
545 } 527 }
546 if (GNUNET_NO == watch) 528 nodes[index_node].handle = GNUNET_STATISTICS_create (subsystem, cfg);
529 if (NULL == nodes[index_node].handle)
547 { 530 {
548 if (NULL == (nodes[index_node].gh = 531 ret = 1;
549 GNUNET_STATISTICS_get(nodes[index_node].handle, 532 return;
550 subsystem,
551 name,
552 &continuation_print,
553 &collector,
554 &nodes[index_node].index_node)))
555 cleanup(nodes[index_node].handle, GNUNET_SYSERR);
556 } 533 }
534 GNUNET_STATISTICS_set (nodes[index_node].handle,
535 name,
536 (uint64_t) set_val,
537 persistent);
538 GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_YES);
539 nodes[index_node].handle = NULL;
540 return;
541 }
542 if (NULL == (nodes[index_node].handle =
543 GNUNET_STATISTICS_create ("gnunet-statistics", cfg)))
544 {
545 ret = 1;
546 return;
547 }
548 if (GNUNET_NO == watch)
549 {
550 if (NULL == (nodes[index_node].gh =
551 GNUNET_STATISTICS_get (nodes[index_node].handle,
552 subsystem,
553 name,
554 &continuation_print,
555 &collector,
556 &nodes[index_node].index_node)))
557 cleanup (nodes[index_node].handle, GNUNET_SYSERR);
558 }
557 else 559 else
560 {
561 if ((NULL == subsystem) || (NULL == name))
558 { 562 {
559 if ((NULL == subsystem) || (NULL == name)) 563 printf (_ ("No subsystem or name given\n"));
560 { 564 GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_NO);
561 printf(_("No subsystem or name given\n")); 565 nodes[index_node].handle = NULL;
562 GNUNET_STATISTICS_destroy(nodes[index_node].handle, GNUNET_NO); 566 ret = 1;
563 nodes[index_node].handle = NULL; 567 return;
564 ret = 1; 568 }
565 return; 569 if (GNUNET_OK != GNUNET_STATISTICS_watch (nodes[index_node].handle,
566 } 570 subsystem,
567 if (GNUNET_OK != GNUNET_STATISTICS_watch(nodes[index_node].handle, 571 name,
568 subsystem, 572 &printer_watch,
569 name, 573 &nodes[index_node].index_node))
570 &printer_watch, 574 {
571 &nodes[index_node].index_node)) 575 fprintf (stderr, _ ("Failed to initialize watch routine\n"));
572 { 576 nodes[index_node].shutdown_task =
573 fprintf(stderr, _("Failed to initialize watch routine\n")); 577 GNUNET_SCHEDULER_add_now (&clean_node, &nodes[index_node].index_node);
574 nodes[index_node].shutdown_task = 578 return;
575 GNUNET_SCHEDULER_add_now(&clean_node, &nodes[index_node].index_node);
576 return;
577 }
578 } 579 }
580 }
579 nodes[index_node].shutdown_task = 581 nodes[index_node].shutdown_task =
580 GNUNET_SCHEDULER_add_shutdown(&clean_node, &nodes[index_node].index_node); 582 GNUNET_SCHEDULER_add_shutdown (&clean_node, &nodes[index_node].index_node);
581} 583}
582 584
583/** 585/**
@@ -592,27 +594,27 @@ main_task(void *cls)
592 * @return to continue iteration or not to 594 * @return to continue iteration or not to
593 */ 595 */
594static int 596static int
595iter_check_config(void *cls, const char *filename) 597iter_check_config (void *cls, const char *filename)
596{ 598{
597 if (0 == strncmp(GNUNET_STRINGS_get_short_name(filename), "config", 6)) 599 if (0 == strncmp (GNUNET_STRINGS_get_short_name (filename), "config", 6))
600 {
601 /* Found the config - stop iteration successfully */
602 GNUNET_array_grow (nodes, num_nodes, num_nodes + 1);
603 nodes[num_nodes - 1].conf = GNUNET_CONFIGURATION_create ();
604 nodes[num_nodes - 1].index_node = num_nodes - 1;
605 if (GNUNET_OK !=
606 GNUNET_CONFIGURATION_load (nodes[num_nodes - 1].conf, filename))
598 { 607 {
599 /* Found the config - stop iteration successfully */ 608 fprintf (stderr, "Failed loading config `%s'\n", filename);
600 GNUNET_array_grow(nodes, num_nodes, num_nodes + 1); 609 return GNUNET_SYSERR;
601 nodes[num_nodes - 1].conf = GNUNET_CONFIGURATION_create();
602 nodes[num_nodes - 1].index_node = num_nodes - 1;
603 if (GNUNET_OK !=
604 GNUNET_CONFIGURATION_load(nodes[num_nodes - 1].conf, filename))
605 {
606 fprintf(stderr, "Failed loading config `%s'\n", filename);
607 return GNUNET_SYSERR;
608 }
609 return GNUNET_NO;
610 } 610 }
611 return GNUNET_NO;
612 }
611 else 613 else
612 { 614 {
613 /* Continue iteration */ 615 /* Continue iteration */
614 return GNUNET_OK; 616 return GNUNET_OK;
615 } 617 }
616} 618}
617 619
618/** 620/**
@@ -629,21 +631,21 @@ iter_check_config(void *cls, const char *filename)
629 * @return status whether to continue iteration 631 * @return status whether to continue iteration
630 */ 632 */
631static int 633static int
632iter_testbed_path(void *cls, const char *filename) 634iter_testbed_path (void *cls, const char *filename)
633{ 635{
634 unsigned index_node; 636 unsigned index_node;
635 637
636 GNUNET_assert(NULL != filename); 638 GNUNET_assert (NULL != filename);
637 if (1 == sscanf(GNUNET_STRINGS_get_short_name(filename), "%u", &index_node)) 639 if (1 == sscanf (GNUNET_STRINGS_get_short_name (filename), "%u", &index_node))
640 {
641 if (-1 == GNUNET_DISK_directory_scan (filename, iter_check_config, NULL))
638 { 642 {
639 if (-1 == GNUNET_DISK_directory_scan(filename, iter_check_config, NULL)) 643 /* This is probably no directory for a testbed node
640 { 644 * Go on with iteration */
641 /* This is probably no directory for a testbed node
642 * Go on with iteration */
643 return GNUNET_OK;
644 }
645 return GNUNET_OK; 645 return GNUNET_OK;
646 } 646 }
647 return GNUNET_OK;
648 }
647 return GNUNET_OK; 649 return GNUNET_OK;
648} 650}
649 651
@@ -655,17 +657,17 @@ iter_testbed_path(void *cls, const char *filename)
655 * @return number of running nodes 657 * @return number of running nodes
656 */ 658 */
657static int 659static int
658discover_testbed_nodes(const char *path_testbed) 660discover_testbed_nodes (const char *path_testbed)
659{ 661{
660 int num_dir_entries; 662 int num_dir_entries;
661 663
662 num_dir_entries = 664 num_dir_entries =
663 GNUNET_DISK_directory_scan(path_testbed, iter_testbed_path, NULL); 665 GNUNET_DISK_directory_scan (path_testbed, iter_testbed_path, NULL);
664 if (-1 == num_dir_entries) 666 if (-1 == num_dir_entries)
665 { 667 {
666 fprintf(stderr, "Failure during scanning directory `%s'\n", path_testbed); 668 fprintf (stderr, "Failure during scanning directory `%s'\n", path_testbed);
667 return -1; 669 return -1;
668 } 670 }
669 return 0; 671 return 0;
670} 672}
671 673
@@ -678,90 +680,90 @@ discover_testbed_nodes(const char *path_testbed)
678 * @param cfg configuration 680 * @param cfg configuration
679 */ 681 */
680static void 682static void
681run(void *cls, 683run (void *cls,
682 char *const *args, 684 char *const *args,
683 const char *cfgfile, 685 const char *cfgfile,
684 const struct GNUNET_CONFIGURATION_Handle *cfg) 686 const struct GNUNET_CONFIGURATION_Handle *cfg)
685{ 687{
686 struct GNUNET_CONFIGURATION_Handle *c; 688 struct GNUNET_CONFIGURATION_Handle *c;
687 689
688 c = (struct GNUNET_CONFIGURATION_Handle *)cfg; 690 c = (struct GNUNET_CONFIGURATION_Handle *) cfg;
689 set_value = GNUNET_NO; 691 set_value = GNUNET_NO;
690 if (NULL == csv_separator) 692 if (NULL == csv_separator)
691 csv_separator = ""; 693 csv_separator = "";
692 if (NULL != args[0]) 694 if (NULL != args[0])
695 {
696 if (1 != sscanf (args[0], "%llu", &set_val))
693 { 697 {
694 if (1 != sscanf(args[0], "%llu", &set_val)) 698 fprintf (stderr, _ ("Invalid argument `%s'\n"), args[0]);
695 { 699 ret = 1;
696 fprintf(stderr, _("Invalid argument `%s'\n"), args[0]); 700 return;
697 ret = 1;
698 return;
699 }
700 set_value = GNUNET_YES;
701 } 701 }
702 set_value = GNUNET_YES;
703 }
702 if (NULL != remote_host) 704 if (NULL != remote_host)
705 {
706 if (0 == remote_port)
703 { 707 {
704 if (0 == remote_port) 708 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
705 { 709 "statistics",
706 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 710 "PORT",
707 "statistics", 711 &remote_port))
708 "PORT", 712 {
709 &remote_port)) 713 fprintf (stderr,
710 { 714 _ ("A port is required to connect to host `%s'\n"),
711 fprintf(stderr, 715 remote_host);
712 _("A port is required to connect to host `%s'\n"), 716 return;
713 remote_host); 717 }
714 return;
715 }
716 }
717 else if (65535 <= remote_port)
718 {
719 fprintf(stderr,
720 _(
721 "A port has to be between 1 and 65535 to connect to host `%s'\n"),
722 remote_host);
723 return;
724 }
725
726 /* Manipulate configuration */
727 GNUNET_CONFIGURATION_set_value_string(c, "statistics", "UNIXPATH", "");
728 GNUNET_CONFIGURATION_set_value_string(c,
729 "statistics",
730 "HOSTNAME",
731 remote_host);
732 GNUNET_CONFIGURATION_set_value_number(c,
733 "statistics",
734 "PORT",
735 remote_port);
736 } 718 }
737 if (NULL == path_testbed) 719 else if (65535 <= remote_port)
738 { 720 {
739 values = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO); 721 fprintf (stderr,
740 GNUNET_array_grow(nodes, num_nodes, 1); 722 _ (
741 nodes[0].index_node = 0; 723 "A port has to be between 1 and 65535 to connect to host `%s'\n"),
742 nodes[0].conf = c; 724 remote_host);
743 GNUNET_SCHEDULER_add_now(&main_task, &nodes[0].index_node); 725 return;
744 } 726 }
727
728 /* Manipulate configuration */
729 GNUNET_CONFIGURATION_set_value_string (c, "statistics", "UNIXPATH", "");
730 GNUNET_CONFIGURATION_set_value_string (c,
731 "statistics",
732 "HOSTNAME",
733 remote_host);
734 GNUNET_CONFIGURATION_set_value_number (c,
735 "statistics",
736 "PORT",
737 remote_port);
738 }
739 if (NULL == path_testbed)
740 {
741 values = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
742 GNUNET_array_grow (nodes, num_nodes, 1);
743 nodes[0].index_node = 0;
744 nodes[0].conf = c;
745 GNUNET_SCHEDULER_add_now (&main_task, &nodes[0].index_node);
746 }
745 else 747 else
748 {
749 if (GNUNET_YES == watch)
750 {
751 printf (
752 _ ("Not able to watch testbed nodes (yet - feel free to implement)\n"));
753 ret = 1;
754 return;
755 }
756 values = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
757 if (-1 == discover_testbed_nodes (path_testbed))
758 {
759 return;
760 }
761 /* For each config/node collect statistics */
762 for (unsigned i = 0; i < num_nodes; i++)
746 { 763 {
747 if (GNUNET_YES == watch) 764 GNUNET_SCHEDULER_add_now (&main_task, &nodes[i].index_node);
748 {
749 printf(
750 _("Not able to watch testbed nodes (yet - feel free to implement)\n"));
751 ret = 1;
752 return;
753 }
754 values = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO);
755 if (-1 == discover_testbed_nodes(path_testbed))
756 {
757 return;
758 }
759 /* For each config/node collect statistics */
760 for (unsigned i = 0; i < num_nodes; i++)
761 {
762 GNUNET_SCHEDULER_add_now(&main_task, &nodes[i].index_node);
763 }
764 } 765 }
766 }
765} 767}
766 768
767 769
@@ -773,85 +775,85 @@ run(void *cls,
773 * @return 0 ok, 1 on error 775 * @return 0 ok, 1 on error
774 */ 776 */
775int 777int
776main(int argc, char *const *argv) 778main (int argc, char *const *argv)
777{ 779{
778 struct GNUNET_GETOPT_CommandLineOption options[] = 780 struct GNUNET_GETOPT_CommandLineOption options[] =
779 { GNUNET_GETOPT_option_string( 781 { GNUNET_GETOPT_option_string (
780 'n', 782 'n',
781 "name", 783 "name",
782 "NAME", 784 "NAME",
783 gettext_noop("limit output to statistics for the given NAME"), 785 gettext_noop ("limit output to statistics for the given NAME"),
784 &name), 786 &name),
785 787
786 GNUNET_GETOPT_option_flag('p', 788 GNUNET_GETOPT_option_flag ('p',
787 "persistent", 789 "persistent",
788 gettext_noop( 790 gettext_noop (
789 "make the value being set persistent"), 791 "make the value being set persistent"),
790 &persistent), 792 &persistent),
791 793
792 GNUNET_GETOPT_option_string('s', 794 GNUNET_GETOPT_option_string ('s',
793 "subsystem", 795 "subsystem",
794 "SUBSYSTEM", 796 "SUBSYSTEM",
795 gettext_noop( 797 gettext_noop (
796 "limit output to the given SUBSYSTEM"), 798 "limit output to the given SUBSYSTEM"),
797 &subsystem), 799 &subsystem),
798 800
799 GNUNET_GETOPT_option_string('S', 801 GNUNET_GETOPT_option_string ('S',
800 "csv-separator", 802 "csv-separator",
801 "CSV_SEPARATOR", 803 "CSV_SEPARATOR",
802 gettext_noop("use as csv separator"), 804 gettext_noop ("use as csv separator"),
803 &csv_separator), 805 &csv_separator),
804 806
805 GNUNET_GETOPT_option_filename( 807 GNUNET_GETOPT_option_filename (
806 't', 808 't',
807 "testbed", 809 "testbed",
808 "TESTBED", 810 "TESTBED",
809 gettext_noop("path to the folder containing the testbed data"), 811 gettext_noop ("path to the folder containing the testbed data"),
810 &path_testbed), 812 &path_testbed),
811 813
812 GNUNET_GETOPT_option_flag('q', 814 GNUNET_GETOPT_option_flag ('q',
813 "quiet", 815 "quiet",
814 gettext_noop( 816 gettext_noop (
815 "just print the statistics value"), 817 "just print the statistics value"),
816 &quiet), 818 &quiet),
817 819
818 GNUNET_GETOPT_option_flag('w', 820 GNUNET_GETOPT_option_flag ('w',
819 "watch", 821 "watch",
820 gettext_noop("watch value continuously"), 822 gettext_noop ("watch value continuously"),
821 &watch), 823 &watch),
822 824
823 GNUNET_GETOPT_option_string('r', 825 GNUNET_GETOPT_option_string ('r',
824 "remote", 826 "remote",
825 "REMOTE", 827 "REMOTE",
826 gettext_noop("connect to remote host"), 828 gettext_noop ("connect to remote host"),
827 &remote_host), 829 &remote_host),
828 830
829 GNUNET_GETOPT_option_ulong('o', 831 GNUNET_GETOPT_option_ulong ('o',
830 "port", 832 "port",
831 "PORT", 833 "PORT",
832 gettext_noop("port for remote host"), 834 gettext_noop ("port for remote host"),
833 &remote_port), 835 &remote_port),
834 836
835 GNUNET_GETOPT_OPTION_END }; 837 GNUNET_GETOPT_OPTION_END };
836 838
837 remote_port = 0; 839 remote_port = 0;
838 remote_host = NULL; 840 remote_host = NULL;
839 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 841 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
840 return 2; 842 return 2;
841 843
842 ret = (GNUNET_OK == 844 ret = (GNUNET_OK ==
843 GNUNET_PROGRAM_run(argc, 845 GNUNET_PROGRAM_run (argc,
844 argv, 846 argv,
845 "gnunet-statistics [options [value]]", 847 "gnunet-statistics [options [value]]",
846 gettext_noop( 848 gettext_noop (
847 "Print statistics about GNUnet operations."), 849 "Print statistics about GNUnet operations."),
848 options, 850 options,
849 &run, 851 &run,
850 NULL)) 852 NULL))
851 ? ret 853 ? ret
852 : 1; 854 : 1;
853 GNUNET_free_non_null(remote_host); 855 GNUNET_free_non_null (remote_host);
854 GNUNET_free((void *)argv); 856 GNUNET_free ((void *) argv);
855 return ret; 857 return ret;
856} 858}
857 859
diff --git a/src/statistics/statistics.h b/src/statistics/statistics.h
index c01dca15a..6eb75cc99 100644
--- a/src/statistics/statistics.h
+++ b/src/statistics/statistics.h
@@ -37,7 +37,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
37 * The struct is be followed by the service name and 37 * The struct is be followed by the service name and
38 * name of the statistic, both 0-terminated. 38 * name of the statistic, both 0-terminated.
39 */ 39 */
40struct GNUNET_STATISTICS_ReplyMessage { 40struct GNUNET_STATISTICS_ReplyMessage
41{
41 /** 42 /**
42 * Type: GNUNET_MESSAGE_TYPE_STATISTICS_VALUE 43 * Type: GNUNET_MESSAGE_TYPE_STATISTICS_VALUE
43 */ 44 */
@@ -61,7 +62,7 @@ struct GNUNET_STATISTICS_ReplyMessage {
61 * Flag for the `struct GNUNET_STATISTICS_ReplyMessage` UID only. 62 * Flag for the `struct GNUNET_STATISTICS_ReplyMessage` UID only.
62 * Note that other messages use #GNUNET_STATISTICS_SETFLAG_PERSISTENT. 63 * Note that other messages use #GNUNET_STATISTICS_SETFLAG_PERSISTENT.
63 */ 64 */
64#define GNUNET_STATISTICS_PERSIST_BIT ((uint32_t)(1LLU << 31)) 65#define GNUNET_STATISTICS_PERSIST_BIT ((uint32_t) (1LLU << 31))
65 66
66/** 67/**
67 * The value being set is an absolute change. 68 * The value being set is an absolute change.
@@ -87,7 +88,8 @@ struct GNUNET_STATISTICS_ReplyMessage {
87 * by the subsystem name and the name of 88 * by the subsystem name and the name of
88 * the statistic (each 0-terminated). 89 * the statistic (each 0-terminated).
89 */ 90 */
90struct GNUNET_STATISTICS_SetMessage { 91struct GNUNET_STATISTICS_SetMessage
92{
91 /** 93 /**
92 * Type: #GNUNET_MESSAGE_TYPE_STATISTICS_SET 94 * Type: #GNUNET_MESSAGE_TYPE_STATISTICS_SET
93 */ 95 */
@@ -110,7 +112,8 @@ struct GNUNET_STATISTICS_SetMessage {
110/** 112/**
111 * Message transmitted if a watched value changes. 113 * Message transmitted if a watched value changes.
112 */ 114 */
113struct GNUNET_STATISTICS_WatchValueMessage { 115struct GNUNET_STATISTICS_WatchValueMessage
116{
114 /** 117 /**
115 * Type: #GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE 118 * Type: #GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE
116 */ 119 */
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c
index 487f2569c..1f3dfcfa6 100644
--- a/src/statistics/statistics_api.c
+++ b/src/statistics/statistics_api.c
@@ -35,14 +35,16 @@
35 * a value times out? (The update will be lost if the 35 * a value times out? (The update will be lost if the
36 * service does not react within this timeframe). 36 * service does not react within this timeframe).
37 */ 37 */
38#define SET_TRANSMIT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2) 38#define SET_TRANSMIT_TIMEOUT GNUNET_TIME_relative_multiply ( \
39 GNUNET_TIME_UNIT_SECONDS, 2)
39 40
40#define LOG(kind, ...) GNUNET_log_from(kind, "statistics-api", __VA_ARGS__) 41#define LOG(kind, ...) GNUNET_log_from (kind, "statistics-api", __VA_ARGS__)
41 42
42/** 43/**
43 * Types of actions. 44 * Types of actions.
44 */ 45 */
45enum ActionType { 46enum ActionType
47{
46 /** 48 /**
47 * Get a value. 49 * Get a value.
48 */ 50 */
@@ -68,7 +70,8 @@ enum ActionType {
68/** 70/**
69 * Entry kept for each value we are watching. 71 * Entry kept for each value we are watching.
70 */ 72 */
71struct GNUNET_STATISTICS_WatchEntry { 73struct GNUNET_STATISTICS_WatchEntry
74{
72 /** 75 /**
73 * What subsystem is this action about? (never NULL) 76 * What subsystem is this action about? (never NULL)
74 */ 77 */
@@ -94,7 +97,8 @@ struct GNUNET_STATISTICS_WatchEntry {
94/** 97/**
95 * Linked list of things we still need to do. 98 * Linked list of things we still need to do.
96 */ 99 */
97struct GNUNET_STATISTICS_GetHandle { 100struct GNUNET_STATISTICS_GetHandle
101{
98 /** 102 /**
99 * This is a doubly linked list. 103 * This is a doubly linked list.
100 */ 104 */
@@ -170,7 +174,8 @@ struct GNUNET_STATISTICS_GetHandle {
170/** 174/**
171 * Handle for the service. 175 * Handle for the service.
172 */ 176 */
173struct GNUNET_STATISTICS_Handle { 177struct GNUNET_STATISTICS_Handle
178{
174 /** 179 /**
175 * Name of our subsystem. 180 * Name of our subsystem.
176 */ 181 */
@@ -257,7 +262,7 @@ struct GNUNET_STATISTICS_Handle {
257 * report those as well (if they changed). 262 * report those as well (if they changed).
258 */ 263 */
259static void 264static void
260update_memory_statistics(struct GNUNET_STATISTICS_Handle *h) 265update_memory_statistics (struct GNUNET_STATISTICS_Handle *h)
261{ 266{
262#if ENABLE_HEAP_STATISTICS 267#if ENABLE_HEAP_STATISTICS
263 uint64_t current_heap_size = 0; 268 uint64_t current_heap_size = 0;
@@ -269,7 +274,7 @@ update_memory_statistics(struct GNUNET_STATISTICS_Handle *h)
269 { 274 {
270 struct mallinfo mi; 275 struct mallinfo mi;
271 276
272 mi = mallinfo(); 277 mi = mallinfo ();
273 current_heap_size = mi.uordblks + mi.fordblks; 278 current_heap_size = mi.uordblks + mi.fordblks;
274 } 279 }
275#endif 280#endif
@@ -277,28 +282,28 @@ update_memory_statistics(struct GNUNET_STATISTICS_Handle *h)
277 { 282 {
278 struct rusage ru; 283 struct rusage ru;
279 284
280 if (0 == getrusage(RUSAGE_SELF, &ru)) 285 if (0 == getrusage (RUSAGE_SELF, &ru))
281 { 286 {
282 current_rss = 1024LL * ru.ru_maxrss; 287 current_rss = 1024LL * ru.ru_maxrss;
283 } 288 }
284 } 289 }
285#endif 290#endif
286 if (current_heap_size > h->peak_heap_size) 291 if (current_heap_size > h->peak_heap_size)
287 { 292 {
288 h->peak_heap_size = current_heap_size; 293 h->peak_heap_size = current_heap_size;
289 GNUNET_STATISTICS_set(h, 294 GNUNET_STATISTICS_set (h,
290 "# peak heap size", 295 "# peak heap size",
291 current_heap_size, 296 current_heap_size,
292 GNUNET_NO); 297 GNUNET_NO);
293 } 298 }
294 if (current_rss > h->peak_rss) 299 if (current_rss > h->peak_rss)
295 { 300 {
296 h->peak_rss = current_rss; 301 h->peak_rss = current_rss;
297 GNUNET_STATISTICS_set(h, 302 GNUNET_STATISTICS_set (h,
298 "# peak resident set size", 303 "# peak resident set size",
299 current_rss, 304 current_rss,
300 GNUNET_NO); 305 GNUNET_NO);
301 } 306 }
302#endif 307#endif
303} 308}
304 309
@@ -309,7 +314,7 @@ update_memory_statistics(struct GNUNET_STATISTICS_Handle *h)
309 * @param h statistics handle 314 * @param h statistics handle
310 */ 315 */
311static void 316static void
312reconnect_later(struct GNUNET_STATISTICS_Handle *h); 317reconnect_later (struct GNUNET_STATISTICS_Handle *h);
313 318
314 319
315/** 320/**
@@ -318,7 +323,7 @@ reconnect_later(struct GNUNET_STATISTICS_Handle *h);
318 * @param cls statistics handle to reconnect 323 * @param cls statistics handle to reconnect
319 */ 324 */
320static void 325static void
321schedule_action(void *cls); 326schedule_action (void *cls);
322 327
323 328
324/** 329/**
@@ -329,35 +334,35 @@ schedule_action(void *cls);
329 * @param watch watch entry of the value to watch 334 * @param watch watch entry of the value to watch
330 */ 335 */
331static void 336static void
332schedule_watch_request(struct GNUNET_STATISTICS_Handle *h, 337schedule_watch_request (struct GNUNET_STATISTICS_Handle *h,
333 struct GNUNET_STATISTICS_WatchEntry *watch) 338 struct GNUNET_STATISTICS_WatchEntry *watch)
334{ 339{
335 struct GNUNET_STATISTICS_GetHandle *ai; 340 struct GNUNET_STATISTICS_GetHandle *ai;
336 size_t slen; 341 size_t slen;
337 size_t nlen; 342 size_t nlen;
338 size_t nsize; 343 size_t nsize;
339 344
340 slen = strlen(watch->subsystem) + 1; 345 slen = strlen (watch->subsystem) + 1;
341 nlen = strlen(watch->name) + 1; 346 nlen = strlen (watch->name) + 1;
342 nsize = sizeof(struct GNUNET_MessageHeader) + slen + nlen; 347 nsize = sizeof(struct GNUNET_MessageHeader) + slen + nlen;
343 if (nsize >= GNUNET_MAX_MESSAGE_SIZE) 348 if (nsize >= GNUNET_MAX_MESSAGE_SIZE)
344 { 349 {
345 GNUNET_break(0); 350 GNUNET_break (0);
346 return; 351 return;
347 } 352 }
348 ai = GNUNET_new(struct GNUNET_STATISTICS_GetHandle); 353 ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle);
349 ai->sh = h; 354 ai->sh = h;
350 ai->subsystem = GNUNET_strdup(watch->subsystem); 355 ai->subsystem = GNUNET_strdup (watch->subsystem);
351 ai->name = GNUNET_strdup(watch->name); 356 ai->name = GNUNET_strdup (watch->name);
352 ai->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 357 ai->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
353 ai->msize = nsize; 358 ai->msize = nsize;
354 ai->type = ACTION_WATCH; 359 ai->type = ACTION_WATCH;
355 ai->proc = watch->proc; 360 ai->proc = watch->proc;
356 ai->cls = watch->proc_cls; 361 ai->cls = watch->proc_cls;
357 GNUNET_CONTAINER_DLL_insert_tail(h->action_head, 362 GNUNET_CONTAINER_DLL_insert_tail (h->action_head,
358 h->action_tail, 363 h->action_tail,
359 ai); 364 ai);
360 schedule_action(h); 365 schedule_action (h);
361} 366}
362 367
363 368
@@ -367,11 +372,11 @@ schedule_watch_request(struct GNUNET_STATISTICS_Handle *h,
367 * @param gh action item to free 372 * @param gh action item to free
368 */ 373 */
369static void 374static void
370free_action_item(struct GNUNET_STATISTICS_GetHandle *gh) 375free_action_item (struct GNUNET_STATISTICS_GetHandle *gh)
371{ 376{
372 GNUNET_free_non_null(gh->subsystem); 377 GNUNET_free_non_null (gh->subsystem);
373 GNUNET_free_non_null(gh->name); 378 GNUNET_free_non_null (gh->name);
374 GNUNET_free(gh); 379 GNUNET_free (gh);
375} 380}
376 381
377 382
@@ -381,28 +386,28 @@ free_action_item(struct GNUNET_STATISTICS_GetHandle *gh)
381 * @param h statistics handle to disconnect from 386 * @param h statistics handle to disconnect from
382 */ 387 */
383static void 388static void
384do_disconnect(struct GNUNET_STATISTICS_Handle *h) 389do_disconnect (struct GNUNET_STATISTICS_Handle *h)
385{ 390{
386 struct GNUNET_STATISTICS_GetHandle *c; 391 struct GNUNET_STATISTICS_GetHandle *c;
387 392
388 h->receiving = GNUNET_NO; 393 h->receiving = GNUNET_NO;
389 if (NULL != (c = h->current)) 394 if (NULL != (c = h->current))
395 {
396 h->current = NULL;
397 if ((NULL != c->cont) &&
398 (GNUNET_YES != c->aborted))
390 { 399 {
391 h->current = NULL; 400 c->cont (c->cls,
392 if ((NULL != c->cont) && 401 GNUNET_SYSERR);
393 (GNUNET_YES != c->aborted)) 402 c->cont = NULL;
394 {
395 c->cont(c->cls,
396 GNUNET_SYSERR);
397 c->cont = NULL;
398 }
399 free_action_item(c);
400 } 403 }
404 free_action_item (c);
405 }
401 if (NULL != h->mq) 406 if (NULL != h->mq)
402 { 407 {
403 GNUNET_MQ_destroy(h->mq); 408 GNUNET_MQ_destroy (h->mq);
404 h->mq = NULL; 409 h->mq = NULL;
405 } 410 }
406} 411}
407 412
408 413
@@ -414,25 +419,25 @@ do_disconnect(struct GNUNET_STATISTICS_Handle *h)
414 * @return #GNUNET_OK if the message was well-formed 419 * @return #GNUNET_OK if the message was well-formed
415 */ 420 */
416static int 421static int
417check_statistics_value(void *cls, 422check_statistics_value (void *cls,
418 const struct GNUNET_STATISTICS_ReplyMessage *smsg) 423 const struct GNUNET_STATISTICS_ReplyMessage *smsg)
419{ 424{
420 const char *service; 425 const char *service;
421 const char *name; 426 const char *name;
422 uint16_t size; 427 uint16_t size;
423 428
424 size = ntohs(smsg->header.size); 429 size = ntohs (smsg->header.size);
425 size -= sizeof(struct GNUNET_STATISTICS_ReplyMessage); 430 size -= sizeof(struct GNUNET_STATISTICS_ReplyMessage);
426 if (size != 431 if (size !=
427 GNUNET_STRINGS_buffer_tokenize((const char *)&smsg[1], 432 GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1],
428 size, 433 size,
429 2, 434 2,
430 &service, 435 &service,
431 &name)) 436 &name))
432 { 437 {
433 GNUNET_break(0); 438 GNUNET_break (0);
434 return GNUNET_SYSERR; 439 return GNUNET_SYSERR;
435 } 440 }
436 return GNUNET_OK; 441 return GNUNET_OK;
437} 442}
438 443
@@ -445,8 +450,8 @@ check_statistics_value(void *cls,
445 * @return #GNUNET_OK if the message was well-formed 450 * @return #GNUNET_OK if the message was well-formed
446 */ 451 */
447static void 452static void
448handle_statistics_value(void *cls, 453handle_statistics_value (void *cls,
449 const struct GNUNET_STATISTICS_ReplyMessage *smsg) 454 const struct GNUNET_STATISTICS_ReplyMessage *smsg)
450{ 455{
451 struct GNUNET_STATISTICS_Handle *h = cls; 456 struct GNUNET_STATISTICS_Handle *h = cls;
452 const char *service; 457 const char *service;
@@ -456,30 +461,30 @@ handle_statistics_value(void *cls,
456 if (h->current->aborted) 461 if (h->current->aborted)
457 return; /* iteration aborted, don't bother */ 462 return; /* iteration aborted, don't bother */
458 463
459 size = ntohs(smsg->header.size); 464 size = ntohs (smsg->header.size);
460 size -= sizeof(struct GNUNET_STATISTICS_ReplyMessage); 465 size -= sizeof(struct GNUNET_STATISTICS_ReplyMessage);
461 GNUNET_assert(size == 466 GNUNET_assert (size ==
462 GNUNET_STRINGS_buffer_tokenize((const char *)&smsg[1], 467 GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1],
463 size, 468 size,
464 2, 469 2,
465 &service, 470 &service,
466 &name)); 471 &name));
467 LOG(GNUNET_ERROR_TYPE_DEBUG, 472 LOG (GNUNET_ERROR_TYPE_DEBUG,
468 "Received valid statistic on `%s:%s': %llu\n", 473 "Received valid statistic on `%s:%s': %llu\n",
469 service, name, 474 service, name,
470 GNUNET_ntohll(smsg->value)); 475 GNUNET_ntohll (smsg->value));
471 if (GNUNET_OK != 476 if (GNUNET_OK !=
472 h->current->proc(h->current->cls, 477 h->current->proc (h->current->cls,
473 service, 478 service,
474 name, 479 name,
475 GNUNET_ntohll(smsg->value), 480 GNUNET_ntohll (smsg->value),
476 0 != 481 (0 !=
477 (ntohl(smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) 482 (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT)) ))
478 { 483 {
479 LOG(GNUNET_ERROR_TYPE_DEBUG, 484 LOG (GNUNET_ERROR_TYPE_DEBUG,
480 "Processing of remaining statistics aborted by client.\n"); 485 "Processing of remaining statistics aborted by client.\n");
481 h->current->aborted = GNUNET_YES; 486 h->current->aborted = GNUNET_YES;
482 } 487 }
483} 488}
484 489
485 490
@@ -490,29 +495,30 @@ handle_statistics_value(void *cls,
490 * @param msg the watch value message 495 * @param msg the watch value message
491 */ 496 */
492static void 497static void
493handle_statistics_watch_value(void *cls, 498handle_statistics_watch_value (void *cls,
494 const struct GNUNET_STATISTICS_WatchValueMessage *wvm) 499 const struct
500 GNUNET_STATISTICS_WatchValueMessage *wvm)
495{ 501{
496 struct GNUNET_STATISTICS_Handle *h = cls; 502 struct GNUNET_STATISTICS_Handle *h = cls;
497 struct GNUNET_STATISTICS_WatchEntry *w; 503 struct GNUNET_STATISTICS_WatchEntry *w;
498 uint32_t wid; 504 uint32_t wid;
499 505
500 GNUNET_break(0 == ntohl(wvm->reserved)); 506 GNUNET_break (0 == ntohl (wvm->reserved));
501 wid = ntohl(wvm->wid); 507 wid = ntohl (wvm->wid);
502 if (wid >= h->watches_size) 508 if (wid >= h->watches_size)
503 { 509 {
504 do_disconnect(h); 510 do_disconnect (h);
505 reconnect_later(h); 511 reconnect_later (h);
506 return; 512 return;
507 } 513 }
508 w = h->watches[wid]; 514 w = h->watches[wid];
509 if (NULL == w) 515 if (NULL == w)
510 return; 516 return;
511 (void)w->proc(w->proc_cls, 517 (void) w->proc (w->proc_cls,
512 w->subsystem, 518 w->subsystem,
513 w->name, 519 w->name,
514 GNUNET_ntohll(wvm->value), 520 GNUNET_ntohll (wvm->value),
515 0 != (ntohl(wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); 521 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
516} 522}
517 523
518 524
@@ -525,25 +531,25 @@ handle_statistics_watch_value(void *cls,
525 * @param error error code 531 * @param error error code
526 */ 532 */
527static void 533static void
528mq_error_handler(void *cls, 534mq_error_handler (void *cls,
529 enum GNUNET_MQ_Error error) 535 enum GNUNET_MQ_Error error)
530{ 536{
531 struct GNUNET_STATISTICS_Handle *h = cls; 537 struct GNUNET_STATISTICS_Handle *h = cls;
532 538
533 if (GNUNET_NO != h->do_destroy) 539 if (GNUNET_NO != h->do_destroy)
540 {
541 h->do_destroy = GNUNET_NO;
542 if (NULL != h->destroy_task)
534 { 543 {
535 h->do_destroy = GNUNET_NO; 544 GNUNET_SCHEDULER_cancel (h->destroy_task);
536 if (NULL != h->destroy_task) 545 h->destroy_task = NULL;
537 {
538 GNUNET_SCHEDULER_cancel(h->destroy_task);
539 h->destroy_task = NULL;
540 }
541 GNUNET_STATISTICS_destroy(h,
542 GNUNET_NO);
543 return;
544 } 546 }
545 do_disconnect(h); 547 GNUNET_STATISTICS_destroy (h,
546 reconnect_later(h); 548 GNUNET_NO);
549 return;
550 }
551 do_disconnect (h);
552 reconnect_later (h);
547} 553}
548 554
549 555
@@ -553,16 +559,16 @@ mq_error_handler(void *cls,
553 * @param cls the `struct GNUNET_STATISTICS_Handle` 559 * @param cls the `struct GNUNET_STATISTICS_Handle`
554 */ 560 */
555static void 561static void
556do_destroy(void *cls) 562do_destroy (void *cls)
557{ 563{
558 struct GNUNET_STATISTICS_Handle *h = cls; 564 struct GNUNET_STATISTICS_Handle *h = cls;
559 565
560 h->destroy_task = NULL; 566 h->destroy_task = NULL;
561 h->do_destroy = GNUNET_NO; 567 h->do_destroy = GNUNET_NO;
562 LOG(GNUNET_ERROR_TYPE_DEBUG, 568 LOG (GNUNET_ERROR_TYPE_DEBUG,
563 "Running final destruction\n"); 569 "Running final destruction\n");
564 GNUNET_STATISTICS_destroy(h, 570 GNUNET_STATISTICS_destroy (h,
565 GNUNET_NO); 571 GNUNET_NO);
566} 572}
567 573
568 574
@@ -575,25 +581,25 @@ do_destroy(void *cls)
575 * @param msg the message 581 * @param msg the message
576 */ 582 */
577static void 583static void
578handle_disconnect_confirm(void *cls, 584handle_disconnect_confirm (void *cls,
579 const struct GNUNET_MessageHeader *msg) 585 const struct GNUNET_MessageHeader *msg)
580{ 586{
581 struct GNUNET_STATISTICS_Handle *h = cls; 587 struct GNUNET_STATISTICS_Handle *h = cls;
582 588
583 if (GNUNET_SYSERR != h->do_destroy) 589 if (GNUNET_SYSERR != h->do_destroy)
584 { 590 {
585 /* not in shutdown, why do we get 'TEST'? */ 591 /* not in shutdown, why do we get 'TEST'? */
586 GNUNET_break(0); 592 GNUNET_break (0);
587 do_disconnect(h); 593 do_disconnect (h);
588 reconnect_later(h); 594 reconnect_later (h);
589 return; 595 return;
590 } 596 }
591 LOG(GNUNET_ERROR_TYPE_DEBUG, 597 LOG (GNUNET_ERROR_TYPE_DEBUG,
592 "Received DISCONNNECT_CONFIRM message from statistics, can complete disconnect\n"); 598 "Received DISCONNNECT_CONFIRM message from statistics, can complete disconnect\n");
593 if (NULL != h->destroy_task) 599 if (NULL != h->destroy_task)
594 GNUNET_SCHEDULER_cancel(h->destroy_task); 600 GNUNET_SCHEDULER_cancel (h->destroy_task);
595 h->destroy_task = GNUNET_SCHEDULER_add_now(&do_destroy, 601 h->destroy_task = GNUNET_SCHEDULER_add_now (&do_destroy,
596 h); 602 h);
597} 603}
598 604
599 605
@@ -606,31 +612,31 @@ handle_disconnect_confirm(void *cls,
606 * @param msg the message 612 * @param msg the message
607 */ 613 */
608static void 614static void
609handle_statistics_end(void *cls, 615handle_statistics_end (void *cls,
610 const struct GNUNET_MessageHeader *msg) 616 const struct GNUNET_MessageHeader *msg)
611{ 617{
612 struct GNUNET_STATISTICS_Handle *h = cls; 618 struct GNUNET_STATISTICS_Handle *h = cls;
613 struct GNUNET_STATISTICS_GetHandle *c; 619 struct GNUNET_STATISTICS_GetHandle *c;
614 620
615 LOG(GNUNET_ERROR_TYPE_DEBUG, 621 LOG (GNUNET_ERROR_TYPE_DEBUG,
616 "Received end of statistics marker\n"); 622 "Received end of statistics marker\n");
617 if (NULL == (c = h->current)) 623 if (NULL == (c = h->current))
618 { 624 {
619 GNUNET_break(0); 625 GNUNET_break (0);
620 do_disconnect(h); 626 do_disconnect (h);
621 reconnect_later(h); 627 reconnect_later (h);
622 return; 628 return;
623 } 629 }
624 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; 630 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
625 h->current = NULL; 631 h->current = NULL;
626 schedule_action(h); 632 schedule_action (h);
627 if (NULL != c->cont) 633 if (NULL != c->cont)
628 { 634 {
629 c->cont(c->cls, 635 c->cont (c->cls,
630 GNUNET_OK); 636 GNUNET_OK);
631 c->cont = NULL; 637 c->cont = NULL;
632 } 638 }
633 free_action_item(c); 639 free_action_item (c);
634} 640}
635 641
636 642
@@ -641,26 +647,26 @@ handle_statistics_end(void *cls,
641 * @return #GNUNET_YES on success, #GNUNET_NO on failure. 647 * @return #GNUNET_YES on success, #GNUNET_NO on failure.
642 */ 648 */
643static int 649static int
644try_connect(struct GNUNET_STATISTICS_Handle *h) 650try_connect (struct GNUNET_STATISTICS_Handle *h)
645{ 651{
646 struct GNUNET_MQ_MessageHandler handlers[] = { 652 struct GNUNET_MQ_MessageHandler handlers[] = {
647 GNUNET_MQ_hd_fixed_size(disconnect_confirm, 653 GNUNET_MQ_hd_fixed_size (disconnect_confirm,
648 GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM, 654 GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM,
649 struct GNUNET_MessageHeader, 655 struct GNUNET_MessageHeader,
650 h), 656 h),
651 GNUNET_MQ_hd_fixed_size(statistics_end, 657 GNUNET_MQ_hd_fixed_size (statistics_end,
652 GNUNET_MESSAGE_TYPE_STATISTICS_END, 658 GNUNET_MESSAGE_TYPE_STATISTICS_END,
653 struct GNUNET_MessageHeader, 659 struct GNUNET_MessageHeader,
654 h), 660 h),
655 GNUNET_MQ_hd_var_size(statistics_value, 661 GNUNET_MQ_hd_var_size (statistics_value,
656 GNUNET_MESSAGE_TYPE_STATISTICS_VALUE, 662 GNUNET_MESSAGE_TYPE_STATISTICS_VALUE,
657 struct GNUNET_STATISTICS_ReplyMessage, 663 struct GNUNET_STATISTICS_ReplyMessage,
658 h), 664 h),
659 GNUNET_MQ_hd_fixed_size(statistics_watch_value, 665 GNUNET_MQ_hd_fixed_size (statistics_watch_value,
660 GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE, 666 GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE,
661 struct GNUNET_STATISTICS_WatchValueMessage, 667 struct GNUNET_STATISTICS_WatchValueMessage,
662 h), 668 h),
663 GNUNET_MQ_handler_end() 669 GNUNET_MQ_handler_end ()
664 }; 670 };
665 struct GNUNET_STATISTICS_GetHandle *gh; 671 struct GNUNET_STATISTICS_GetHandle *gh;
666 struct GNUNET_STATISTICS_GetHandle *gn; 672 struct GNUNET_STATISTICS_GetHandle *gn;
@@ -669,33 +675,33 @@ try_connect(struct GNUNET_STATISTICS_Handle *h)
669 return GNUNET_NO; 675 return GNUNET_NO;
670 if (NULL != h->mq) 676 if (NULL != h->mq)
671 return GNUNET_YES; 677 return GNUNET_YES;
672 h->mq = GNUNET_CLIENT_connect(h->cfg, 678 h->mq = GNUNET_CLIENT_connect (h->cfg,
673 "statistics", 679 "statistics",
674 handlers, 680 handlers,
675 &mq_error_handler, 681 &mq_error_handler,
676 h); 682 h);
677 if (NULL == h->mq) 683 if (NULL == h->mq)
678 { 684 {
679 LOG(GNUNET_ERROR_TYPE_DEBUG, 685 LOG (GNUNET_ERROR_TYPE_DEBUG,
680 "Failed to connect to statistics service!\n"); 686 "Failed to connect to statistics service!\n");
681 return GNUNET_NO; 687 return GNUNET_NO;
682 } 688 }
683 gn = h->action_head; 689 gn = h->action_head;
684 while (NULL != (gh = gn)) 690 while (NULL != (gh = gn))
691 {
692 gn = gh->next;
693 if (gh->type == ACTION_WATCH)
685 { 694 {
686 gn = gh->next; 695 GNUNET_CONTAINER_DLL_remove (h->action_head,
687 if (gh->type == ACTION_WATCH) 696 h->action_tail,
688 { 697 gh);
689 GNUNET_CONTAINER_DLL_remove(h->action_head, 698 free_action_item (gh);
690 h->action_tail,
691 gh);
692 free_action_item(gh);
693 }
694 } 699 }
700 }
695 for (unsigned int i = 0; i < h->watches_size; i++) 701 for (unsigned int i = 0; i < h->watches_size; i++)
696 if (NULL != h->watches[i]) 702 if (NULL != h->watches[i])
697 schedule_watch_request(h, 703 schedule_watch_request (h,
698 h->watches[i]); 704 h->watches[i]);
699 return GNUNET_YES; 705 return GNUNET_YES;
700} 706}
701 707
@@ -706,12 +712,12 @@ try_connect(struct GNUNET_STATISTICS_Handle *h)
706 * @param cls the `struct GNUNET_STATISTICS_Handle` to reconnect 712 * @param cls the `struct GNUNET_STATISTICS_Handle` to reconnect
707 */ 713 */
708static void 714static void
709reconnect_task(void *cls) 715reconnect_task (void *cls)
710{ 716{
711 struct GNUNET_STATISTICS_Handle *h = cls; 717 struct GNUNET_STATISTICS_Handle *h = cls;
712 718
713 h->backoff_task = NULL; 719 h->backoff_task = NULL;
714 schedule_action(h); 720 schedule_action (h);
715} 721}
716 722
717 723
@@ -721,38 +727,38 @@ reconnect_task(void *cls)
721 * @param h statistics handle 727 * @param h statistics handle
722 */ 728 */
723static void 729static void
724reconnect_later(struct GNUNET_STATISTICS_Handle *h) 730reconnect_later (struct GNUNET_STATISTICS_Handle *h)
725{ 731{
726 int loss; 732 int loss;
727 struct GNUNET_STATISTICS_GetHandle *gh; 733 struct GNUNET_STATISTICS_GetHandle *gh;
728 734
729 GNUNET_assert(NULL == h->backoff_task); 735 GNUNET_assert (NULL == h->backoff_task);
730 if (GNUNET_YES == h->do_destroy) 736 if (GNUNET_YES == h->do_destroy)
731 { 737 {
732 /* So we are shutting down and the service is not reachable. 738 /* So we are shutting down and the service is not reachable.
733 * Chances are that it's down for good and we are not going to connect to 739 * Chances are that it's down for good and we are not going to connect to
734 * it anymore. 740 * it anymore.
735 * Give up and don't sync the rest of the data. 741 * Give up and don't sync the rest of the data.
736 */ 742 */
737 loss = GNUNET_NO; 743 loss = GNUNET_NO;
738 for (gh = h->action_head; NULL != gh; gh = gh->next) 744 for (gh = h->action_head; NULL != gh; gh = gh->next)
739 if ((gh->make_persistent) && 745 if ((gh->make_persistent) &&
740 (ACTION_SET == gh->type)) 746 (ACTION_SET == gh->type))
741 loss = GNUNET_YES; 747 loss = GNUNET_YES;
742 if (GNUNET_YES == loss) 748 if (GNUNET_YES == loss)
743 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 749 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
744 _("Could not save some persistent statistics\n")); 750 _ ("Could not save some persistent statistics\n"));
745 if (NULL != h->destroy_task) 751 if (NULL != h->destroy_task)
746 GNUNET_SCHEDULER_cancel(h->destroy_task); 752 GNUNET_SCHEDULER_cancel (h->destroy_task);
747 h->destroy_task = GNUNET_SCHEDULER_add_now(&do_destroy, 753 h->destroy_task = GNUNET_SCHEDULER_add_now (&do_destroy,
748 h); 754 h);
749 return; 755 return;
750 } 756 }
751 h->backoff_task 757 h->backoff_task
752 = GNUNET_SCHEDULER_add_delayed(h->backoff, 758 = GNUNET_SCHEDULER_add_delayed (h->backoff,
753 &reconnect_task, 759 &reconnect_task,
754 h); 760 h);
755 h->backoff = GNUNET_TIME_STD_BACKOFF(h->backoff); 761 h->backoff = GNUNET_TIME_STD_BACKOFF (h->backoff);
756} 762}
757 763
758 764
@@ -764,7 +770,7 @@ reconnect_later(struct GNUNET_STATISTICS_Handle *h)
764 * @param handle statistics handle 770 * @param handle statistics handle
765 */ 771 */
766static void 772static void
767transmit_get(struct GNUNET_STATISTICS_Handle *handle) 773transmit_get (struct GNUNET_STATISTICS_Handle *handle)
768{ 774{
769 struct GNUNET_STATISTICS_GetHandle *c; 775 struct GNUNET_STATISTICS_GetHandle *c;
770 struct GNUNET_MessageHeader *hdr; 776 struct GNUNET_MessageHeader *hdr;
@@ -772,23 +778,23 @@ transmit_get(struct GNUNET_STATISTICS_Handle *handle)
772 size_t slen1; 778 size_t slen1;
773 size_t slen2; 779 size_t slen2;
774 780
775 GNUNET_assert(NULL != (c = handle->current)); 781 GNUNET_assert (NULL != (c = handle->current));
776 slen1 = strlen(c->subsystem) + 1; 782 slen1 = strlen (c->subsystem) + 1;
777 slen2 = strlen(c->name) + 1; 783 slen2 = strlen (c->name) + 1;
778 env = GNUNET_MQ_msg_extra(hdr, 784 env = GNUNET_MQ_msg_extra (hdr,
779 slen1 + slen2, 785 slen1 + slen2,
780 GNUNET_MESSAGE_TYPE_STATISTICS_GET); 786 GNUNET_MESSAGE_TYPE_STATISTICS_GET);
781 GNUNET_assert(slen1 + slen2 == 787 GNUNET_assert (slen1 + slen2 ==
782 GNUNET_STRINGS_buffer_fill((char *)&hdr[1], 788 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1],
783 slen1 + slen2, 789 slen1 + slen2,
784 2, 790 2,
785 c->subsystem, 791 c->subsystem,
786 c->name)); 792 c->name));
787 GNUNET_MQ_notify_sent(env, 793 GNUNET_MQ_notify_sent (env,
788 &schedule_action, 794 &schedule_action,
789 handle); 795 handle);
790 GNUNET_MQ_send(handle->mq, 796 GNUNET_MQ_send (handle->mq,
791 env); 797 env);
792} 798}
793 799
794 800
@@ -799,36 +805,36 @@ transmit_get(struct GNUNET_STATISTICS_Handle *handle)
799 * @param handle statistics handle 805 * @param handle statistics handle
800 */ 806 */
801static void 807static void
802transmit_watch(struct GNUNET_STATISTICS_Handle *handle) 808transmit_watch (struct GNUNET_STATISTICS_Handle *handle)
803{ 809{
804 struct GNUNET_MessageHeader *hdr; 810 struct GNUNET_MessageHeader *hdr;
805 struct GNUNET_MQ_Envelope *env; 811 struct GNUNET_MQ_Envelope *env;
806 size_t slen1; 812 size_t slen1;
807 size_t slen2; 813 size_t slen2;
808 814
809 LOG(GNUNET_ERROR_TYPE_DEBUG, 815 LOG (GNUNET_ERROR_TYPE_DEBUG,
810 "Transmitting watch request for `%s'\n", 816 "Transmitting watch request for `%s'\n",
811 handle->current->name); 817 handle->current->name);
812 slen1 = strlen(handle->current->subsystem) + 1; 818 slen1 = strlen (handle->current->subsystem) + 1;
813 slen2 = strlen(handle->current->name) + 1; 819 slen2 = strlen (handle->current->name) + 1;
814 env = GNUNET_MQ_msg_extra(hdr, 820 env = GNUNET_MQ_msg_extra (hdr,
815 slen1 + slen2, 821 slen1 + slen2,
816 GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); 822 GNUNET_MESSAGE_TYPE_STATISTICS_WATCH);
817 GNUNET_assert(slen1 + slen2 == 823 GNUNET_assert (slen1 + slen2 ==
818 GNUNET_STRINGS_buffer_fill((char *)&hdr[1], 824 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1],
819 slen1 + slen2, 825 slen1 + slen2,
820 2, 826 2,
821 handle->current->subsystem, 827 handle->current->subsystem,
822 handle->current->name)); 828 handle->current->name));
823 GNUNET_MQ_notify_sent(env, 829 GNUNET_MQ_notify_sent (env,
824 &schedule_action, 830 &schedule_action,
825 handle); 831 handle);
826 GNUNET_MQ_send(handle->mq, 832 GNUNET_MQ_send (handle->mq,
827 env); 833 env);
828 GNUNET_assert(NULL == handle->current->cont); 834 GNUNET_assert (NULL == handle->current->cont);
829 free_action_item(handle->current); 835 free_action_item (handle->current);
830 handle->current = NULL; 836 handle->current = NULL;
831 schedule_action(handle); 837 schedule_action (handle);
832} 838}
833 839
834 840
@@ -838,39 +844,39 @@ transmit_watch(struct GNUNET_STATISTICS_Handle *handle)
838 * @param handle statistics handle 844 * @param handle statistics handle
839 */ 845 */
840static void 846static void
841transmit_set(struct GNUNET_STATISTICS_Handle *handle) 847transmit_set (struct GNUNET_STATISTICS_Handle *handle)
842{ 848{
843 struct GNUNET_STATISTICS_SetMessage *r; 849 struct GNUNET_STATISTICS_SetMessage *r;
844 struct GNUNET_MQ_Envelope *env; 850 struct GNUNET_MQ_Envelope *env;
845 size_t slen; 851 size_t slen;
846 size_t nlen; 852 size_t nlen;
847 853
848 slen = strlen(handle->current->subsystem) + 1; 854 slen = strlen (handle->current->subsystem) + 1;
849 nlen = strlen(handle->current->name) + 1; 855 nlen = strlen (handle->current->name) + 1;
850 env = GNUNET_MQ_msg_extra(r, 856 env = GNUNET_MQ_msg_extra (r,
851 slen + nlen, 857 slen + nlen,
852 GNUNET_MESSAGE_TYPE_STATISTICS_SET); 858 GNUNET_MESSAGE_TYPE_STATISTICS_SET);
853 r->flags = 0; 859 r->flags = 0;
854 r->value = GNUNET_htonll(handle->current->value); 860 r->value = GNUNET_htonll (handle->current->value);
855 if (handle->current->make_persistent) 861 if (handle->current->make_persistent)
856 r->flags |= htonl(GNUNET_STATISTICS_SETFLAG_PERSISTENT); 862 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_PERSISTENT);
857 if (handle->current->type == ACTION_UPDATE) 863 if (handle->current->type == ACTION_UPDATE)
858 r->flags |= htonl(GNUNET_STATISTICS_SETFLAG_RELATIVE); 864 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE);
859 GNUNET_assert(slen + nlen == 865 GNUNET_assert (slen + nlen ==
860 GNUNET_STRINGS_buffer_fill((char *)&r[1], 866 GNUNET_STRINGS_buffer_fill ((char *) &r[1],
861 slen + nlen, 867 slen + nlen,
862 2, 868 2,
863 handle->current->subsystem, 869 handle->current->subsystem,
864 handle->current->name)); 870 handle->current->name));
865 GNUNET_assert(NULL == handle->current->cont); 871 GNUNET_assert (NULL == handle->current->cont);
866 free_action_item(handle->current); 872 free_action_item (handle->current);
867 handle->current = NULL; 873 handle->current = NULL;
868 update_memory_statistics(handle); 874 update_memory_statistics (handle);
869 GNUNET_MQ_notify_sent(env, 875 GNUNET_MQ_notify_sent (env,
870 &schedule_action, 876 &schedule_action,
871 handle); 877 handle);
872 GNUNET_MQ_send(handle->mq, 878 GNUNET_MQ_send (handle->mq,
873 env); 879 env);
874} 880}
875 881
876 882
@@ -882,19 +888,19 @@ transmit_set(struct GNUNET_STATISTICS_Handle *handle)
882 * @return handle to use 888 * @return handle to use
883 */ 889 */
884struct GNUNET_STATISTICS_Handle * 890struct GNUNET_STATISTICS_Handle *
885GNUNET_STATISTICS_create(const char *subsystem, 891GNUNET_STATISTICS_create (const char *subsystem,
886 const struct GNUNET_CONFIGURATION_Handle *cfg) 892 const struct GNUNET_CONFIGURATION_Handle *cfg)
887{ 893{
888 struct GNUNET_STATISTICS_Handle *h; 894 struct GNUNET_STATISTICS_Handle *h;
889 895
890 if (GNUNET_YES == 896 if (GNUNET_YES ==
891 GNUNET_CONFIGURATION_get_value_yesno(cfg, 897 GNUNET_CONFIGURATION_get_value_yesno (cfg,
892 "statistics", 898 "statistics",
893 "DISABLE")) 899 "DISABLE"))
894 return NULL; 900 return NULL;
895 h = GNUNET_new(struct GNUNET_STATISTICS_Handle); 901 h = GNUNET_new (struct GNUNET_STATISTICS_Handle);
896 h->cfg = cfg; 902 h->cfg = cfg;
897 h->subsystem = GNUNET_strdup(subsystem); 903 h->subsystem = GNUNET_strdup (subsystem);
898 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; 904 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
899 return h; 905 return h;
900} 906}
@@ -909,82 +915,82 @@ GNUNET_STATISTICS_create(const char *subsystem,
909 * be completed 915 * be completed
910 */ 916 */
911void 917void
912GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, 918GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
913 int sync_first) 919 int sync_first)
914{ 920{
915 struct GNUNET_STATISTICS_GetHandle *pos; 921 struct GNUNET_STATISTICS_GetHandle *pos;
916 struct GNUNET_STATISTICS_GetHandle *next; 922 struct GNUNET_STATISTICS_GetHandle *next;
917 923
918 if (NULL == h) 924 if (NULL == h)
919 return; 925 return;
920 GNUNET_assert(GNUNET_NO == h->do_destroy); /* Don't call twice. */ 926 GNUNET_assert (GNUNET_NO == h->do_destroy); /* Don't call twice. */
921 if ((sync_first) && 927 if ((sync_first) &&
922 (NULL != h->mq) && 928 (NULL != h->mq) &&
923 (0 != GNUNET_MQ_get_length(h->mq))) 929 (0 != GNUNET_MQ_get_length (h->mq)))
930 {
931 if ((NULL != h->current) &&
932 (ACTION_GET == h->current->type))
933 h->current->aborted = GNUNET_YES;
934 next = h->action_head;
935 while (NULL != (pos = next))
924 { 936 {
925 if ((NULL != h->current) && 937 next = pos->next;
926 (ACTION_GET == h->current->type)) 938 if ((ACTION_GET == pos->type) ||
927 h->current->aborted = GNUNET_YES; 939 (ACTION_WATCH == pos->type))
928 next = h->action_head; 940 {
929 while (NULL != (pos = next)) 941 GNUNET_CONTAINER_DLL_remove (h->action_head,
930 { 942 h->action_tail,
931 next = pos->next; 943 pos);
932 if ((ACTION_GET == pos->type) || 944 free_action_item (pos);
933 (ACTION_WATCH == pos->type)) 945 }
934 {
935 GNUNET_CONTAINER_DLL_remove(h->action_head,
936 h->action_tail,
937 pos);
938 free_action_item(pos);
939 }
940 }
941 h->do_destroy = GNUNET_YES;
942 schedule_action(h);
943 GNUNET_assert(NULL == h->destroy_task);
944 h->destroy_task
945 = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(h->backoff,
946 5),
947 &do_destroy,
948 h);
949 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
950 "Deferring destruction\n");
951 return; /* do not finish destruction just yet */
952 } 946 }
947 h->do_destroy = GNUNET_YES;
948 schedule_action (h);
949 GNUNET_assert (NULL == h->destroy_task);
950 h->destroy_task
951 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (h->backoff,
952 5),
953 &do_destroy,
954 h);
955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
956 "Deferring destruction\n");
957 return; /* do not finish destruction just yet */
958 }
953 /* do clean up all */ 959 /* do clean up all */
954 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
955 "Cleaning all up\n"); 961 "Cleaning all up\n");
956 while (NULL != (pos = h->action_head)) 962 while (NULL != (pos = h->action_head))
957 { 963 {
958 GNUNET_CONTAINER_DLL_remove(h->action_head, 964 GNUNET_CONTAINER_DLL_remove (h->action_head,
959 h->action_tail, 965 h->action_tail,
960 pos); 966 pos);
961 free_action_item(pos); 967 free_action_item (pos);
962 } 968 }
963 do_disconnect(h); 969 do_disconnect (h);
964 if (NULL != h->backoff_task) 970 if (NULL != h->backoff_task)
965 { 971 {
966 GNUNET_SCHEDULER_cancel(h->backoff_task); 972 GNUNET_SCHEDULER_cancel (h->backoff_task);
967 h->backoff_task = NULL; 973 h->backoff_task = NULL;
968 } 974 }
969 if (NULL != h->destroy_task) 975 if (NULL != h->destroy_task)
970 { 976 {
971 GNUNET_break(0); 977 GNUNET_break (0);
972 GNUNET_SCHEDULER_cancel(h->destroy_task); 978 GNUNET_SCHEDULER_cancel (h->destroy_task);
973 h->destroy_task = NULL; 979 h->destroy_task = NULL;
974 } 980 }
975 for (unsigned int i = 0; i < h->watches_size; i++) 981 for (unsigned int i = 0; i < h->watches_size; i++)
976 { 982 {
977 if (NULL == h->watches[i]) 983 if (NULL == h->watches[i])
978 continue; 984 continue;
979 GNUNET_free(h->watches[i]->subsystem); 985 GNUNET_free (h->watches[i]->subsystem);
980 GNUNET_free(h->watches[i]->name); 986 GNUNET_free (h->watches[i]->name);
981 GNUNET_free(h->watches[i]); 987 GNUNET_free (h->watches[i]);
982 } 988 }
983 GNUNET_array_grow(h->watches, 989 GNUNET_array_grow (h->watches,
984 h->watches_size, 990 h->watches_size,
985 0); 991 0);
986 GNUNET_free(h->subsystem); 992 GNUNET_free (h->subsystem);
987 GNUNET_free(h); 993 GNUNET_free (h);
988} 994}
989 995
990 996
@@ -994,66 +1000,66 @@ GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h,
994 * @param cls statistics handle 1000 * @param cls statistics handle
995 */ 1001 */
996static void 1002static void
997schedule_action(void *cls) 1003schedule_action (void *cls)
998{ 1004{
999 struct GNUNET_STATISTICS_Handle *h = cls; 1005 struct GNUNET_STATISTICS_Handle *h = cls;
1000 1006
1001 if (NULL != h->backoff_task) 1007 if (NULL != h->backoff_task)
1002 return; /* action already pending */ 1008 return; /* action already pending */
1003 if (GNUNET_YES != try_connect(h)) 1009 if (GNUNET_YES != try_connect (h))
1004 { 1010 {
1005 reconnect_later(h); 1011 reconnect_later (h);
1006 return; 1012 return;
1007 } 1013 }
1008 if (0 < GNUNET_MQ_get_length(h->mq)) 1014 if (0 < GNUNET_MQ_get_length (h->mq))
1009 return; /* Wait for queue to be reduced more */ 1015 return; /* Wait for queue to be reduced more */
1010 /* schedule next action */ 1016 /* schedule next action */
1011 while (NULL == h->current) 1017 while (NULL == h->current)
1018 {
1019 h->current = h->action_head;
1020 if (NULL == h->current)
1012 { 1021 {
1013 h->current = h->action_head; 1022 struct GNUNET_MessageHeader *hdr;
1014 if (NULL == h->current) 1023 struct GNUNET_MQ_Envelope *env;
1015 { 1024
1016 struct GNUNET_MessageHeader *hdr; 1025 if (GNUNET_YES != h->do_destroy)
1017 struct GNUNET_MQ_Envelope *env; 1026 return; /* nothing to do */
1018 1027 /* let service know that we're done */
1019 if (GNUNET_YES != h->do_destroy) 1028 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1020 return; /* nothing to do */ 1029 "Notifying service that we are done\n");
1021 /* let service know that we're done */ 1030 h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */
1022 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1031 env = GNUNET_MQ_msg (hdr,
1023 "Notifying service that we are done\n"); 1032 GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT);
1024 h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */ 1033 GNUNET_MQ_notify_sent (env,
1025 env = GNUNET_MQ_msg(hdr, 1034 &schedule_action,
1026 GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT); 1035 h);
1027 GNUNET_MQ_notify_sent(env, 1036 GNUNET_MQ_send (h->mq,
1028 &schedule_action, 1037 env);
1029 h); 1038 return;
1030 GNUNET_MQ_send(h->mq,
1031 env);
1032 return;
1033 }
1034 GNUNET_CONTAINER_DLL_remove(h->action_head,
1035 h->action_tail,
1036 h->current);
1037 switch (h->current->type)
1038 {
1039 case ACTION_GET:
1040 transmit_get(h);
1041 break;
1042
1043 case ACTION_SET:
1044 case ACTION_UPDATE:
1045 transmit_set(h);
1046 break;
1047
1048 case ACTION_WATCH:
1049 transmit_watch(h);
1050 break;
1051
1052 default:
1053 GNUNET_assert(0);
1054 break;
1055 }
1056 } 1039 }
1040 GNUNET_CONTAINER_DLL_remove (h->action_head,
1041 h->action_tail,
1042 h->current);
1043 switch (h->current->type)
1044 {
1045 case ACTION_GET:
1046 transmit_get (h);
1047 break;
1048
1049 case ACTION_SET:
1050 case ACTION_UPDATE:
1051 transmit_set (h);
1052 break;
1053
1054 case ACTION_WATCH:
1055 transmit_watch (h);
1056 break;
1057
1058 default:
1059 GNUNET_assert (0);
1060 break;
1061 }
1062 }
1057} 1063}
1058 1064
1059 1065
@@ -1070,12 +1076,12 @@ schedule_action(void *cls)
1070 * @return NULL on error 1076 * @return NULL on error
1071 */ 1077 */
1072struct GNUNET_STATISTICS_GetHandle * 1078struct GNUNET_STATISTICS_GetHandle *
1073GNUNET_STATISTICS_get(struct GNUNET_STATISTICS_Handle *handle, 1079GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
1074 const char *subsystem, 1080 const char *subsystem,
1075 const char *name, 1081 const char *name,
1076 GNUNET_STATISTICS_Callback cont, 1082 GNUNET_STATISTICS_Callback cont,
1077 GNUNET_STATISTICS_Iterator proc, 1083 GNUNET_STATISTICS_Iterator proc,
1078 void *cls) 1084 void *cls)
1079{ 1085{
1080 size_t slen1; 1086 size_t slen1;
1081 size_t slen2; 1087 size_t slen2;
@@ -1083,29 +1089,29 @@ GNUNET_STATISTICS_get(struct GNUNET_STATISTICS_Handle *handle,
1083 1089
1084 if (NULL == handle) 1090 if (NULL == handle)
1085 return NULL; 1091 return NULL;
1086 GNUNET_assert(NULL != proc); 1092 GNUNET_assert (NULL != proc);
1087 GNUNET_assert(GNUNET_NO == handle->do_destroy); 1093 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1088 if (NULL == subsystem) 1094 if (NULL == subsystem)
1089 subsystem = ""; 1095 subsystem = "";
1090 if (NULL == name) 1096 if (NULL == name)
1091 name = ""; 1097 name = "";
1092 slen1 = strlen(subsystem) + 1; 1098 slen1 = strlen (subsystem) + 1;
1093 slen2 = strlen(name) + 1; 1099 slen2 = strlen (name) + 1;
1094 GNUNET_assert(slen1 + slen2 + sizeof(struct GNUNET_MessageHeader) < 1100 GNUNET_assert (slen1 + slen2 + sizeof(struct GNUNET_MessageHeader) <
1095 GNUNET_MAX_MESSAGE_SIZE); 1101 GNUNET_MAX_MESSAGE_SIZE);
1096 ai = GNUNET_new(struct GNUNET_STATISTICS_GetHandle); 1102 ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle);
1097 ai->sh = handle; 1103 ai->sh = handle;
1098 ai->subsystem = GNUNET_strdup(subsystem); 1104 ai->subsystem = GNUNET_strdup (subsystem);
1099 ai->name = GNUNET_strdup(name); 1105 ai->name = GNUNET_strdup (name);
1100 ai->cont = cont; 1106 ai->cont = cont;
1101 ai->proc = proc; 1107 ai->proc = proc;
1102 ai->cls = cls; 1108 ai->cls = cls;
1103 ai->type = ACTION_GET; 1109 ai->type = ACTION_GET;
1104 ai->msize = slen1 + slen2 + sizeof(struct GNUNET_MessageHeader); 1110 ai->msize = slen1 + slen2 + sizeof(struct GNUNET_MessageHeader);
1105 GNUNET_CONTAINER_DLL_insert_tail(handle->action_head, 1111 GNUNET_CONTAINER_DLL_insert_tail (handle->action_head,
1106 handle->action_tail, 1112 handle->action_tail,
1107 ai); 1113 ai);
1108 schedule_action(handle); 1114 schedule_action (handle);
1109 return ai; 1115 return ai;
1110} 1116}
1111 1117
@@ -1117,22 +1123,22 @@ GNUNET_STATISTICS_get(struct GNUNET_STATISTICS_Handle *handle,
1117 * @param gh handle of the request to cancel 1123 * @param gh handle of the request to cancel
1118 */ 1124 */
1119void 1125void
1120GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh) 1126GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
1121{ 1127{
1122 if (NULL == gh) 1128 if (NULL == gh)
1123 return; 1129 return;
1124 gh->cont = NULL; 1130 gh->cont = NULL;
1125 if (gh->sh->current == gh) 1131 if (gh->sh->current == gh)
1126 { 1132 {
1127 gh->aborted = GNUNET_YES; 1133 gh->aborted = GNUNET_YES;
1128 return; 1134 return;
1129 } 1135 }
1130 GNUNET_CONTAINER_DLL_remove(gh->sh->action_head, 1136 GNUNET_CONTAINER_DLL_remove (gh->sh->action_head,
1131 gh->sh->action_tail, 1137 gh->sh->action_tail,
1132 gh); 1138 gh);
1133 GNUNET_free(gh->name); 1139 GNUNET_free (gh->name);
1134 GNUNET_free(gh->subsystem); 1140 GNUNET_free (gh->subsystem);
1135 GNUNET_free(gh); 1141 GNUNET_free (gh);
1136} 1142}
1137 1143
1138 1144
@@ -1147,26 +1153,26 @@ GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh)
1147 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1153 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1148 */ 1154 */
1149int 1155int
1150GNUNET_STATISTICS_watch(struct GNUNET_STATISTICS_Handle *handle, 1156GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
1151 const char *subsystem, 1157 const char *subsystem,
1152 const char *name, 1158 const char *name,
1153 GNUNET_STATISTICS_Iterator proc, 1159 GNUNET_STATISTICS_Iterator proc,
1154 void *proc_cls) 1160 void *proc_cls)
1155{ 1161{
1156 struct GNUNET_STATISTICS_WatchEntry *w; 1162 struct GNUNET_STATISTICS_WatchEntry *w;
1157 1163
1158 if (NULL == handle) 1164 if (NULL == handle)
1159 return GNUNET_SYSERR; 1165 return GNUNET_SYSERR;
1160 w = GNUNET_new(struct GNUNET_STATISTICS_WatchEntry); 1166 w = GNUNET_new (struct GNUNET_STATISTICS_WatchEntry);
1161 w->subsystem = GNUNET_strdup(subsystem); 1167 w->subsystem = GNUNET_strdup (subsystem);
1162 w->name = GNUNET_strdup(name); 1168 w->name = GNUNET_strdup (name);
1163 w->proc = proc; 1169 w->proc = proc;
1164 w->proc_cls = proc_cls; 1170 w->proc_cls = proc_cls;
1165 GNUNET_array_append(handle->watches, 1171 GNUNET_array_append (handle->watches,
1166 handle->watches_size, 1172 handle->watches_size,
1167 w); 1173 w);
1168 schedule_watch_request(handle, 1174 schedule_watch_request (handle,
1169 w); 1175 w);
1170 return GNUNET_OK; 1176 return GNUNET_OK;
1171} 1177}
1172 1178
@@ -1182,35 +1188,35 @@ GNUNET_STATISTICS_watch(struct GNUNET_STATISTICS_Handle *handle,
1182 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (no such watch) 1188 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (no such watch)
1183 */ 1189 */
1184int 1190int
1185GNUNET_STATISTICS_watch_cancel(struct GNUNET_STATISTICS_Handle *handle, 1191GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle,
1186 const char *subsystem, 1192 const char *subsystem,
1187 const char *name, 1193 const char *name,
1188 GNUNET_STATISTICS_Iterator proc, 1194 GNUNET_STATISTICS_Iterator proc,
1189 void *proc_cls) 1195 void *proc_cls)
1190{ 1196{
1191 struct GNUNET_STATISTICS_WatchEntry *w; 1197 struct GNUNET_STATISTICS_WatchEntry *w;
1192 1198
1193 if (NULL == handle) 1199 if (NULL == handle)
1194 return GNUNET_SYSERR; 1200 return GNUNET_SYSERR;
1195 for (unsigned int i = 0; i < handle->watches_size; i++) 1201 for (unsigned int i = 0; i < handle->watches_size; i++)
1202 {
1203 w = handle->watches[i];
1204 if (NULL == w)
1205 continue;
1206 if ((w->proc == proc) &&
1207 (w->proc_cls == proc_cls) &&
1208 (0 == strcmp (w->name,
1209 name)) &&
1210 (0 == strcmp (w->subsystem,
1211 subsystem)))
1196 { 1212 {
1197 w = handle->watches[i]; 1213 GNUNET_free (w->name);
1198 if (NULL == w) 1214 GNUNET_free (w->subsystem);
1199 continue; 1215 GNUNET_free (w);
1200 if ((w->proc == proc) && 1216 handle->watches[i] = NULL;
1201 (w->proc_cls == proc_cls) && 1217 return GNUNET_OK;
1202 (0 == strcmp(w->name,
1203 name)) &&
1204 (0 == strcmp(w->subsystem,
1205 subsystem)))
1206 {
1207 GNUNET_free(w->name);
1208 GNUNET_free(w->subsystem);
1209 GNUNET_free(w);
1210 handle->watches[i] = NULL;
1211 return GNUNET_OK;
1212 }
1213 } 1218 }
1219 }
1214 return GNUNET_SYSERR; 1220 return GNUNET_SYSERR;
1215} 1221}
1216 1222
@@ -1225,11 +1231,11 @@ GNUNET_STATISTICS_watch_cancel(struct GNUNET_STATISTICS_Handle *handle,
1225 * @param type type of the action (#ACTION_SET or #ACTION_UPDATE) 1231 * @param type type of the action (#ACTION_SET or #ACTION_UPDATE)
1226 */ 1232 */
1227static void 1233static void
1228add_setter_action(struct GNUNET_STATISTICS_Handle *h, 1234add_setter_action (struct GNUNET_STATISTICS_Handle *h,
1229 const char *name, 1235 const char *name,
1230 int make_persistent, 1236 int make_persistent,
1231 uint64_t value, 1237 uint64_t value,
1232 enum ActionType type) 1238 enum ActionType type)
1233{ 1239{
1234 struct GNUNET_STATISTICS_GetHandle *ai; 1240 struct GNUNET_STATISTICS_GetHandle *ai;
1235 size_t slen; 1241 size_t slen;
@@ -1237,83 +1243,83 @@ add_setter_action(struct GNUNET_STATISTICS_Handle *h,
1237 size_t nsize; 1243 size_t nsize;
1238 int64_t delta; 1244 int64_t delta;
1239 1245
1240 slen = strlen(h->subsystem) + 1; 1246 slen = strlen (h->subsystem) + 1;
1241 nlen = strlen(name) + 1; 1247 nlen = strlen (name) + 1;
1242 nsize = sizeof(struct GNUNET_STATISTICS_SetMessage) + slen + nlen; 1248 nsize = sizeof(struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
1243 if (nsize >= GNUNET_MAX_MESSAGE_SIZE) 1249 if (nsize >= GNUNET_MAX_MESSAGE_SIZE)
1244 { 1250 {
1245 GNUNET_break(0); 1251 GNUNET_break (0);
1246 return; 1252 return;
1247 } 1253 }
1248 for (ai = h->action_head; NULL != ai; ai = ai->next) 1254 for (ai = h->action_head; NULL != ai; ai = ai->next)
1249 { 1255 {
1250 if (!((0 == strcmp(ai->subsystem, 1256 if (! ((0 == strcmp (ai->subsystem,
1251 h->subsystem)) && 1257 h->subsystem)) &&
1252 (0 == strcmp(ai->name, 1258 (0 == strcmp (ai->name,
1253 name)) && 1259 name)) &&
1254 ((ACTION_UPDATE == ai->type) || 1260 ((ACTION_UPDATE == ai->type) ||
1255 (ACTION_SET == ai->type)))) 1261 (ACTION_SET == ai->type))))
1256 continue; 1262 continue;
1257 if (ACTION_SET == ai->type) 1263 if (ACTION_SET == ai->type)
1264 {
1265 if (ACTION_UPDATE == type)
1266 {
1267 delta = (int64_t) value;
1268 if (delta > 0)
1258 { 1269 {
1259 if (ACTION_UPDATE == type) 1270 /* update old set by new delta */
1260 { 1271 ai->value += delta;
1261 delta = (int64_t)value;
1262 if (delta > 0)
1263 {
1264 /* update old set by new delta */
1265 ai->value += delta;
1266 }
1267 else
1268 {
1269 /* update old set by new delta, but never go negative */
1270 if (ai->value < -delta)
1271 ai->value = 0;
1272 else
1273 ai->value += delta;
1274 }
1275 }
1276 else
1277 {
1278 /* new set overrides old set */
1279 ai->value = value;
1280 }
1281 } 1272 }
1282 else 1273 else
1283 { 1274 {
1284 if (ACTION_UPDATE == type) 1275 /* update old set by new delta, but never go negative */
1285 { 1276 if (ai->value < -delta)
1286 /* make delta cummulative */ 1277 ai->value = 0;
1287 delta = (int64_t)value;
1288 ai->value += delta;
1289 }
1290 else 1278 else
1291 { 1279 ai->value += delta;
1292 /* drop old 'update', use new 'set' instead */
1293 ai->value = value;
1294 ai->type = type;
1295 }
1296 } 1280 }
1297 ai->timeout 1281 }
1298 = GNUNET_TIME_relative_to_absolute(SET_TRANSMIT_TIMEOUT); 1282 else
1299 ai->make_persistent 1283 {
1300 = make_persistent; 1284 /* new set overrides old set */
1301 return; 1285 ai->value = value;
1286 }
1302 } 1287 }
1288 else
1289 {
1290 if (ACTION_UPDATE == type)
1291 {
1292 /* make delta cummulative */
1293 delta = (int64_t) value;
1294 ai->value += delta;
1295 }
1296 else
1297 {
1298 /* drop old 'update', use new 'set' instead */
1299 ai->value = value;
1300 ai->type = type;
1301 }
1302 }
1303 ai->timeout
1304 = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1305 ai->make_persistent
1306 = make_persistent;
1307 return;
1308 }
1303 /* no existing entry matches, create a fresh one */ 1309 /* no existing entry matches, create a fresh one */
1304 ai = GNUNET_new(struct GNUNET_STATISTICS_GetHandle); 1310 ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle);
1305 ai->sh = h; 1311 ai->sh = h;
1306 ai->subsystem = GNUNET_strdup(h->subsystem); 1312 ai->subsystem = GNUNET_strdup (h->subsystem);
1307 ai->name = GNUNET_strdup(name); 1313 ai->name = GNUNET_strdup (name);
1308 ai->timeout = GNUNET_TIME_relative_to_absolute(SET_TRANSMIT_TIMEOUT); 1314 ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1309 ai->make_persistent = make_persistent; 1315 ai->make_persistent = make_persistent;
1310 ai->msize = nsize; 1316 ai->msize = nsize;
1311 ai->value = value; 1317 ai->value = value;
1312 ai->type = type; 1318 ai->type = type;
1313 GNUNET_CONTAINER_DLL_insert_tail(h->action_head, 1319 GNUNET_CONTAINER_DLL_insert_tail (h->action_head,
1314 h->action_tail, 1320 h->action_tail,
1315 ai); 1321 ai);
1316 schedule_action(h); 1322 schedule_action (h);
1317} 1323}
1318 1324
1319 1325
@@ -1327,19 +1333,19 @@ add_setter_action(struct GNUNET_STATISTICS_Handle *h,
1327 * @param make_persistent should the value be kept across restarts? 1333 * @param make_persistent should the value be kept across restarts?
1328 */ 1334 */
1329void 1335void
1330GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, 1336GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
1331 const char *name, 1337 const char *name,
1332 uint64_t value, 1338 uint64_t value,
1333 int make_persistent) 1339 int make_persistent)
1334{ 1340{
1335 if (NULL == handle) 1341 if (NULL == handle)
1336 return; 1342 return;
1337 GNUNET_assert(GNUNET_NO == handle->do_destroy); 1343 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1338 add_setter_action(handle, 1344 add_setter_action (handle,
1339 name, 1345 name,
1340 make_persistent, 1346 make_persistent,
1341 value, 1347 value,
1342 ACTION_SET); 1348 ACTION_SET);
1343} 1349}
1344 1350
1345 1351
@@ -1353,21 +1359,21 @@ GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle,
1353 * @param make_persistent should the value be kept across restarts? 1359 * @param make_persistent should the value be kept across restarts?
1354 */ 1360 */
1355void 1361void
1356GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, 1362GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
1357 const char *name, 1363 const char *name,
1358 int64_t delta, 1364 int64_t delta,
1359 int make_persistent) 1365 int make_persistent)
1360{ 1366{
1361 if (NULL == handle) 1367 if (NULL == handle)
1362 return; 1368 return;
1363 if (0 == delta) 1369 if (0 == delta)
1364 return; 1370 return;
1365 GNUNET_assert(GNUNET_NO == handle->do_destroy); 1371 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1366 add_setter_action(handle, 1372 add_setter_action (handle,
1367 name, 1373 name,
1368 make_persistent, 1374 make_persistent,
1369 (uint64_t)delta, 1375 (uint64_t) delta,
1370 ACTION_UPDATE); 1376 ACTION_UPDATE);
1371} 1377}
1372 1378
1373 1379
diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c
index b21fa5ef1..9ff02d510 100644
--- a/src/statistics/test_statistics_api.c
+++ b/src/statistics/test_statistics_api.c
@@ -33,152 +33,152 @@ static struct GNUNET_STATISTICS_GetHandle *g;
33 33
34 34
35static void 35static void
36do_shutdown() 36do_shutdown ()
37{ 37{
38 if (NULL != g) 38 if (NULL != g)
39 { 39 {
40 GNUNET_STATISTICS_get_cancel(g); 40 GNUNET_STATISTICS_get_cancel (g);
41 g = NULL; 41 g = NULL;
42 } 42 }
43 GNUNET_STATISTICS_destroy(h, GNUNET_NO); 43 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
44 h = NULL; 44 h = NULL;
45} 45}
46 46
47 47
48static int 48static int
49check_1(void *cls, 49check_1 (void *cls,
50 const char *subsystem, 50 const char *subsystem,
51 const char *name, 51 const char *name,
52 uint64_t value, 52 uint64_t value,
53 int is_persistent) 53 int is_persistent)
54{ 54{
55 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 55 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
56 "Received value %llu for `%s:%s\n", 56 "Received value %llu for `%s:%s\n",
57 (unsigned long long)value, 57 (unsigned long long) value,
58 subsystem, 58 subsystem,
59 name); 59 name);
60 GNUNET_assert(0 == strcmp(name, "test-1")); 60 GNUNET_assert (0 == strcmp (name, "test-1"));
61 GNUNET_assert(0 == strcmp(subsystem, "test-statistics-api")); 61 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
62 GNUNET_assert(value == 1); 62 GNUNET_assert (value == 1);
63 GNUNET_assert(is_persistent == GNUNET_NO); 63 GNUNET_assert (is_persistent == GNUNET_NO);
64 return GNUNET_OK; 64 return GNUNET_OK;
65} 65}
66 66
67 67
68static int 68static int
69check_2(void *cls, 69check_2 (void *cls,
70 const char *subsystem, 70 const char *subsystem,
71 const char *name, 71 const char *name,
72 uint64_t value, 72 uint64_t value,
73 int is_persistent) 73 int is_persistent)
74{ 74{
75 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
76 "Received value %llu for `%s:%s\n", 76 "Received value %llu for `%s:%s\n",
77 (unsigned long long)value, 77 (unsigned long long) value,
78 subsystem, 78 subsystem,
79 name); 79 name);
80 GNUNET_assert(0 == strcmp(name, "test-2")); 80 GNUNET_assert (0 == strcmp (name, "test-2"));
81 GNUNET_assert(0 == strcmp(subsystem, "test-statistics-api")); 81 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
82 GNUNET_assert(value == 2); 82 GNUNET_assert (value == 2);
83 GNUNET_assert(is_persistent == GNUNET_NO); 83 GNUNET_assert (is_persistent == GNUNET_NO);
84 return GNUNET_OK; 84 return GNUNET_OK;
85} 85}
86 86
87 87
88static int 88static int
89check_3(void *cls, 89check_3 (void *cls,
90 const char *subsystem, 90 const char *subsystem,
91 const char *name, 91 const char *name,
92 uint64_t value, 92 uint64_t value,
93 int is_persistent) 93 int is_persistent)
94{ 94{
95 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
96 "Received value %llu for `%s:%s\n", 96 "Received value %llu for `%s:%s\n",
97 (unsigned long long)value, 97 (unsigned long long) value,
98 subsystem, 98 subsystem,
99 name); 99 name);
100 GNUNET_assert(0 == strcmp(name, "test-3")); 100 GNUNET_assert (0 == strcmp (name, "test-3"));
101 GNUNET_assert(0 == strcmp(subsystem, "test-statistics-api")); 101 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api"));
102 GNUNET_assert(value == 3); 102 GNUNET_assert (value == 3);
103 GNUNET_assert(is_persistent == GNUNET_YES); 103 GNUNET_assert (is_persistent == GNUNET_YES);
104 return GNUNET_OK; 104 return GNUNET_OK;
105} 105}
106 106
107 107
108static void 108static void
109next_fin(void *cls, 109next_fin (void *cls,
110 int success) 110 int success)
111{ 111{
112 int *ok = cls; 112 int *ok = cls;
113 113
114 g = NULL; 114 g = NULL;
115 GNUNET_SCHEDULER_shutdown(); 115 GNUNET_SCHEDULER_shutdown ();
116 GNUNET_assert(success == GNUNET_OK); 116 GNUNET_assert (success == GNUNET_OK);
117 *ok = 0; 117 *ok = 0;
118} 118}
119 119
120 120
121static void 121static void
122next(void *cls, int success) 122next (void *cls, int success)
123{ 123{
124 g = NULL; 124 g = NULL;
125 GNUNET_assert(success == GNUNET_OK); 125 GNUNET_assert (success == GNUNET_OK);
126 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127 "Issuing GET request\n"); 127 "Issuing GET request\n");
128 GNUNET_break(NULL != 128 GNUNET_break (NULL !=
129 GNUNET_STATISTICS_get(h, NULL, "test-2", 129 GNUNET_STATISTICS_get (h, NULL, "test-2",
130 &next_fin, 130 &next_fin,
131 &check_2, cls)); 131 &check_2, cls));
132} 132}
133 133
134 134
135static void 135static void
136run(void *cls, 136run (void *cls,
137 char *const *args, 137 char *const *args,
138 const char *cfgfile, 138 const char *cfgfile,
139 const struct GNUNET_CONFIGURATION_Handle *cfg) 139 const struct GNUNET_CONFIGURATION_Handle *cfg)
140{ 140{
141 h = GNUNET_STATISTICS_create("test-statistics-api", cfg); 141 h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
142 if (NULL == h) 142 if (NULL == h)
143 { 143 {
144 GNUNET_break(0); 144 GNUNET_break (0);
145 return; 145 return;
146 } 146 }
147 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 147 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
148 NULL); 148 NULL);
149 GNUNET_STATISTICS_set(h, "test-1", 1, GNUNET_NO); 149 GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
150 GNUNET_STATISTICS_set(h, "test-2", 2, GNUNET_NO); 150 GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO);
151 GNUNET_STATISTICS_set(h, "test-3", 2, GNUNET_NO); 151 GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO);
152 GNUNET_STATISTICS_update(h, "test-3", 1, GNUNET_YES); 152 GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES);
153 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
154 "Issuing GET request\n"); 154 "Issuing GET request\n");
155 GNUNET_break(NULL != 155 GNUNET_break (NULL !=
156 (g = GNUNET_STATISTICS_get(h, NULL, "test-1", 156 (g = GNUNET_STATISTICS_get (h, NULL, "test-1",
157 &next, 157 &next,
158 &check_1, cls))); 158 &check_1, cls)));
159} 159}
160 160
161 161
162static void 162static void
163run_more(void *cls, 163run_more (void *cls,
164 char *const *args, 164 char *const *args,
165 const char *cfgfile, 165 const char *cfgfile,
166 const struct GNUNET_CONFIGURATION_Handle *cfg) 166 const struct GNUNET_CONFIGURATION_Handle *cfg)
167{ 167{
168 h = GNUNET_STATISTICS_create("test-statistics-api", 168 h = GNUNET_STATISTICS_create ("test-statistics-api",
169 cfg); 169 cfg);
170 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 170 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
171 NULL); 171 NULL);
172 GNUNET_break(NULL != 172 GNUNET_break (NULL !=
173 (g = GNUNET_STATISTICS_get(h, NULL, 173 (g = GNUNET_STATISTICS_get (h, NULL,
174 "test-3", 174 "test-3",
175 &next_fin, 175 &next_fin,
176 &check_3, cls))); 176 &check_3, cls)));
177} 177}
178 178
179 179
180int 180int
181main(int argc, char *argv_ign[]) 181main (int argc, char *argv_ign[])
182{ 182{
183 int ok = 1; 183 int ok = 1;
184 char *const argv[] = { "test-statistics-api", 184 char *const argv[] = { "test-statistics-api",
@@ -192,60 +192,60 @@ main(int argc, char *argv_ign[])
192 struct GNUNET_OS_Process *proc; 192 struct GNUNET_OS_Process *proc;
193 char *binary; 193 char *binary;
194 194
195 GNUNET_log_setup("test_statistics_api", 195 GNUNET_log_setup ("test_statistics_api",
196 "WARNING", 196 "WARNING",
197 NULL); 197 NULL);
198 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-statistics"); 198 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
199 proc = 199 proc =
200 GNUNET_OS_start_process(GNUNET_YES, 200 GNUNET_OS_start_process (GNUNET_YES,
201 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 201 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
202 NULL, NULL, NULL, 202 NULL, NULL, NULL,
203 binary, 203 binary,
204 "gnunet-service-statistics", 204 "gnunet-service-statistics",
205 "-c", "test_statistics_api_data.conf", NULL); 205 "-c", "test_statistics_api_data.conf", NULL);
206 GNUNET_assert(NULL != proc); 206 GNUNET_assert (NULL != proc);
207 GNUNET_PROGRAM_run(5, argv, 207 GNUNET_PROGRAM_run (5, argv,
208 "test-statistics-api", "nohelp", 208 "test-statistics-api", "nohelp",
209 options, &run, 209 options, &run,
210 &ok); 210 &ok);
211 if (0 != GNUNET_OS_process_kill(proc, 211 if (0 != GNUNET_OS_process_kill (proc,
212 GNUNET_TERM_SIG)) 212 GNUNET_TERM_SIG))
213 { 213 {
214 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); 214 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
215 ok = 1; 215 ok = 1;
216 } 216 }
217 GNUNET_OS_process_wait(proc); 217 GNUNET_OS_process_wait (proc);
218 GNUNET_OS_process_destroy(proc); 218 GNUNET_OS_process_destroy (proc);
219 proc = NULL; 219 proc = NULL;
220 if (ok != 0) 220 if (ok != 0)
221 { 221 {
222 GNUNET_free(binary); 222 GNUNET_free (binary);
223 return ok; 223 return ok;
224 } 224 }
225 ok = 1; 225 ok = 1;
226 /* restart to check persistence! */ 226 /* restart to check persistence! */
227 proc = 227 proc =
228 GNUNET_OS_start_process(GNUNET_YES, 228 GNUNET_OS_start_process (GNUNET_YES,
229 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 229 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
230 NULL, NULL, NULL, 230 NULL, NULL, NULL,
231 binary, 231 binary,
232 "gnunet-service-statistics", 232 "gnunet-service-statistics",
233 "-c", "test_statistics_api_data.conf", 233 "-c", "test_statistics_api_data.conf",
234 NULL); 234 NULL);
235 GNUNET_PROGRAM_run(5, argv, 235 GNUNET_PROGRAM_run (5, argv,
236 "test-statistics-api", "nohelp", 236 "test-statistics-api", "nohelp",
237 options, 237 options,
238 &run_more, &ok); 238 &run_more, &ok);
239 if (0 != GNUNET_OS_process_kill(proc, 239 if (0 != GNUNET_OS_process_kill (proc,
240 GNUNET_TERM_SIG)) 240 GNUNET_TERM_SIG))
241 { 241 {
242 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); 242 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
243 ok = 1; 243 ok = 1;
244 } 244 }
245 GNUNET_OS_process_wait(proc); 245 GNUNET_OS_process_wait (proc);
246 GNUNET_OS_process_destroy(proc); 246 GNUNET_OS_process_destroy (proc);
247 proc = NULL; 247 proc = NULL;
248 GNUNET_free(binary); 248 GNUNET_free (binary);
249 return ok; 249 return ok;
250} 250}
251 251
diff --git a/src/statistics/test_statistics_api_loop.c b/src/statistics/test_statistics_api_loop.c
index 61cf1130a..54de96107 100644
--- a/src/statistics/test_statistics_api_loop.c
+++ b/src/statistics/test_statistics_api_loop.c
@@ -31,58 +31,58 @@ static struct GNUNET_STATISTICS_Handle *h;
31 31
32 32
33static int 33static int
34check_1(void *cls, 34check_1 (void *cls,
35 const char *subsystem, 35 const char *subsystem,
36 const char *name, 36 const char *name,
37 uint64_t value, 37 uint64_t value,
38 int is_persistent) 38 int is_persistent)
39{ 39{
40 GNUNET_assert(0 == strcmp(name, "test-0")); 40 GNUNET_assert (0 == strcmp (name, "test-0"));
41 GNUNET_assert(0 == strcmp(subsystem, "test-statistics-api-loop")); 41 GNUNET_assert (0 == strcmp (subsystem, "test-statistics-api-loop"));
42 GNUNET_assert(is_persistent == GNUNET_NO); 42 GNUNET_assert (is_persistent == GNUNET_NO);
43 return GNUNET_OK; 43 return GNUNET_OK;
44} 44}
45 45
46 46
47static void 47static void
48next(void *cls, 48next (void *cls,
49 int success) 49 int success)
50{ 50{
51 int *ok = cls; 51 int *ok = cls;
52 52
53 GNUNET_STATISTICS_destroy(h, GNUNET_NO); 53 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
54 GNUNET_assert(success == GNUNET_OK); 54 GNUNET_assert (success == GNUNET_OK);
55 *ok = 0; 55 *ok = 0;
56} 56}
57 57
58 58
59static void 59static void
60run(void *cls, 60run (void *cls,
61 char *const *args, 61 char *const *args,
62 const char *cfgfile, 62 const char *cfgfile,
63 const struct GNUNET_CONFIGURATION_Handle *cfg) 63 const struct GNUNET_CONFIGURATION_Handle *cfg)
64{ 64{
65 unsigned int i; 65 unsigned int i;
66 char name[128]; 66 char name[128];
67 67
68 h = GNUNET_STATISTICS_create("test-statistics-api-loop", cfg); 68 h = GNUNET_STATISTICS_create ("test-statistics-api-loop", cfg);
69 for (i = 0; i < ROUNDS; i++) 69 for (i = 0; i < ROUNDS; i++)
70 { 70 {
71 GNUNET_snprintf(name, sizeof(name), "test-%d", i % 32); 71 GNUNET_snprintf (name, sizeof(name), "test-%d", i % 32);
72 GNUNET_STATISTICS_set(h, name, i, GNUNET_NO); 72 GNUNET_STATISTICS_set (h, name, i, GNUNET_NO);
73 GNUNET_snprintf(name, sizeof(name), "test-%d", i % 16); 73 GNUNET_snprintf (name, sizeof(name), "test-%d", i % 16);
74 GNUNET_STATISTICS_update(h, name, 1, GNUNET_NO); 74 GNUNET_STATISTICS_update (h, name, 1, GNUNET_NO);
75 } 75 }
76 i = 0; 76 i = 0;
77 GNUNET_break(NULL != 77 GNUNET_break (NULL !=
78 GNUNET_STATISTICS_get(h, NULL, "test-0", 78 GNUNET_STATISTICS_get (h, NULL, "test-0",
79 &next, 79 &next,
80 &check_1, cls)); 80 &check_1, cls));
81} 81}
82 82
83 83
84int 84int
85main(int argc, char *argv_ign[]) 85main (int argc, char *argv_ign[])
86{ 86{
87 int ok = 1; 87 int ok = 1;
88 88
@@ -96,25 +96,25 @@ main(int argc, char *argv_ign[])
96 struct GNUNET_OS_Process *proc; 96 struct GNUNET_OS_Process *proc;
97 char *binary; 97 char *binary;
98 98
99 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-statistics"); 99 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
100 proc = 100 proc =
101 GNUNET_OS_start_process(GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 101 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
102 NULL, NULL, NULL, 102 NULL, NULL, NULL,
103 binary, 103 binary,
104 "gnunet-service-statistics", 104 "gnunet-service-statistics",
105 "-c", "test_statistics_api_data.conf", NULL); 105 "-c", "test_statistics_api_data.conf", NULL);
106 GNUNET_assert(NULL != proc); 106 GNUNET_assert (NULL != proc);
107 GNUNET_PROGRAM_run(3, argv, "test-statistics-api", "nohelp", options, &run, 107 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run,
108 &ok); 108 &ok);
109 if (0 != GNUNET_OS_process_kill(proc, GNUNET_TERM_SIG)) 109 if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
110 { 110 {
111 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); 111 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
112 ok = 1; 112 ok = 1;
113 } 113 }
114 GNUNET_OS_process_wait(proc); 114 GNUNET_OS_process_wait (proc);
115 GNUNET_OS_process_destroy(proc); 115 GNUNET_OS_process_destroy (proc);
116 proc = NULL; 116 proc = NULL;
117 GNUNET_free(binary); 117 GNUNET_free (binary);
118 return ok; 118 return ok;
119} 119}
120 120
diff --git a/src/statistics/test_statistics_api_watch.c b/src/statistics/test_statistics_api_watch.c
index e8cd15047..06e639599 100644
--- a/src/statistics/test_statistics_api_watch.c
+++ b/src/statistics/test_statistics_api_watch.c
@@ -37,86 +37,86 @@ static struct GNUNET_SCHEDULER_Task *shutdown_task;
37 37
38 38
39static void 39static void
40force_shutdown(void *cls) 40force_shutdown (void *cls)
41{ 41{
42 fprintf(stderr, "Timeout, failed to receive notifications: %d\n", ok); 42 fprintf (stderr, "Timeout, failed to receive notifications: %d\n", ok);
43 GNUNET_STATISTICS_destroy(h, GNUNET_NO); 43 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
44 GNUNET_STATISTICS_destroy(h2, GNUNET_NO); 44 GNUNET_STATISTICS_destroy (h2, GNUNET_NO);
45 ok = 7; 45 ok = 7;
46} 46}
47 47
48 48
49static void 49static void
50normal_shutdown(void *cls) 50normal_shutdown (void *cls)
51{ 51{
52 GNUNET_STATISTICS_destroy(h, GNUNET_NO); 52 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
53 GNUNET_STATISTICS_destroy(h2, GNUNET_NO); 53 GNUNET_STATISTICS_destroy (h2, GNUNET_NO);
54} 54}
55 55
56 56
57static int 57static int
58watch_1(void *cls, 58watch_1 (void *cls,
59 const char *subsystem, 59 const char *subsystem,
60 const char *name, 60 const char *name,
61 uint64_t value, 61 uint64_t value,
62 int is_persistent) 62 int is_persistent)
63{ 63{
64 GNUNET_assert(value == 42); 64 GNUNET_assert (value == 42);
65 GNUNET_assert(0 == strcmp(name, "test-1")); 65 GNUNET_assert (0 == strcmp (name, "test-1"));
66 ok &= ~1; 66 ok &= ~1;
67 if (0 == ok) 67 if (0 == ok)
68 { 68 {
69 GNUNET_SCHEDULER_cancel(shutdown_task); 69 GNUNET_SCHEDULER_cancel (shutdown_task);
70 GNUNET_SCHEDULER_add_now(&normal_shutdown, NULL); 70 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
71 } 71 }
72 return GNUNET_OK; 72 return GNUNET_OK;
73} 73}
74 74
75 75
76static int 76static int
77watch_2(void *cls, 77watch_2 (void *cls,
78 const char *subsystem, 78 const char *subsystem,
79 const char *name, 79 const char *name,
80 uint64_t value, 80 uint64_t value,
81 int is_persistent) 81 int is_persistent)
82{ 82{
83 GNUNET_assert(value == 43); 83 GNUNET_assert (value == 43);
84 GNUNET_assert(0 == strcmp(name, "test-2")); 84 GNUNET_assert (0 == strcmp (name, "test-2"));
85 ok &= ~2; 85 ok &= ~2;
86 if (0 == ok) 86 if (0 == ok)
87 { 87 {
88 GNUNET_SCHEDULER_cancel(shutdown_task); 88 GNUNET_SCHEDULER_cancel (shutdown_task);
89 GNUNET_SCHEDULER_add_now(&normal_shutdown, NULL); 89 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
90 } 90 }
91 return GNUNET_OK; 91 return GNUNET_OK;
92} 92}
93 93
94 94
95static void 95static void
96run(void *cls, 96run (void *cls,
97 char *const *args, 97 char *const *args,
98 const char *cfgfile, 98 const char *cfgfile,
99 const struct GNUNET_CONFIGURATION_Handle *cfg) 99 const struct GNUNET_CONFIGURATION_Handle *cfg)
100{ 100{
101 h = GNUNET_STATISTICS_create("dummy", cfg); 101 h = GNUNET_STATISTICS_create ("dummy", cfg);
102 GNUNET_assert(GNUNET_OK == 102 GNUNET_assert (GNUNET_OK ==
103 GNUNET_STATISTICS_watch(h, "test-statistics-api-watch", 103 GNUNET_STATISTICS_watch (h, "test-statistics-api-watch",
104 "test-1", &watch_1, NULL)); 104 "test-1", &watch_1, NULL));
105 GNUNET_assert(GNUNET_OK == 105 GNUNET_assert (GNUNET_OK ==
106 GNUNET_STATISTICS_watch(h, "test-statistics-api-watch", 106 GNUNET_STATISTICS_watch (h, "test-statistics-api-watch",
107 "test-2", &watch_2, NULL)); 107 "test-2", &watch_2, NULL));
108 h2 = GNUNET_STATISTICS_create("test-statistics-api-watch", cfg); 108 h2 = GNUNET_STATISTICS_create ("test-statistics-api-watch", cfg);
109 GNUNET_STATISTICS_set(h2, "test-1", 42, GNUNET_NO); 109 GNUNET_STATISTICS_set (h2, "test-1", 42, GNUNET_NO);
110 GNUNET_STATISTICS_set(h2, "test-2", 43, GNUNET_NO); 110 GNUNET_STATISTICS_set (h2, "test-2", 43, GNUNET_NO);
111 shutdown_task = 111 shutdown_task =
112 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, 112 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
113 &force_shutdown, 113 &force_shutdown,
114 NULL); 114 NULL);
115} 115}
116 116
117 117
118int 118int
119main(int argc, char *argv_ign[]) 119main (int argc, char *argv_ign[])
120{ 120{
121 char *const argv[] = { "test-statistics-api", 121 char *const argv[] = { "test-statistics-api",
122 "-c", 122 "-c",
@@ -128,26 +128,26 @@ main(int argc, char *argv_ign[])
128 struct GNUNET_OS_Process *proc; 128 struct GNUNET_OS_Process *proc;
129 char *binary; 129 char *binary;
130 130
131 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-statistics"); 131 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
132 proc = 132 proc =
133 GNUNET_OS_start_process(GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 133 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
134 NULL, NULL, NULL, 134 NULL, NULL, NULL,
135 binary, 135 binary,
136 "gnunet-service-statistics", 136 "gnunet-service-statistics",
137 "-c", "test_statistics_api_data.conf", NULL); 137 "-c", "test_statistics_api_data.conf", NULL);
138 GNUNET_assert(NULL != proc); 138 GNUNET_assert (NULL != proc);
139 ok = 3; 139 ok = 3;
140 GNUNET_PROGRAM_run(3, argv, "test-statistics-api", "nohelp", options, &run, 140 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run,
141 NULL); 141 NULL);
142 if (0 != GNUNET_OS_process_kill(proc, GNUNET_TERM_SIG)) 142 if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
143 { 143 {
144 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); 144 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
145 ok = 1; 145 ok = 1;
146 } 146 }
147 GNUNET_OS_process_wait(proc); 147 GNUNET_OS_process_wait (proc);
148 GNUNET_OS_process_destroy(proc); 148 GNUNET_OS_process_destroy (proc);
149 proc = NULL; 149 proc = NULL;
150 GNUNET_free(binary); 150 GNUNET_free (binary);
151 return ok; 151 return ok;
152} 152}
153 153
diff --git a/src/statistics/test_statistics_api_watch_zero_value.c b/src/statistics/test_statistics_api_watch_zero_value.c
index 1dc093658..67cfb4c46 100644
--- a/src/statistics/test_statistics_api_watch_zero_value.c
+++ b/src/statistics/test_statistics_api_watch_zero_value.c
@@ -37,124 +37,124 @@ static struct GNUNET_SCHEDULER_Task *shutdown_task;
37 37
38 38
39static void 39static void
40force_shutdown(void *cls) 40force_shutdown (void *cls)
41{ 41{
42 fprintf(stderr, "Timeout, failed to receive notifications: %d\n", ok); 42 fprintf (stderr, "Timeout, failed to receive notifications: %d\n", ok);
43 GNUNET_STATISTICS_destroy(h, GNUNET_NO); 43 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
44 GNUNET_STATISTICS_destroy(h2, GNUNET_NO); 44 GNUNET_STATISTICS_destroy (h2, GNUNET_NO);
45 ok = 7; 45 ok = 7;
46} 46}
47 47
48 48
49static void 49static void
50normal_shutdown(void *cls) 50normal_shutdown (void *cls)
51{ 51{
52 GNUNET_STATISTICS_destroy(h, GNUNET_NO); 52 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
53 GNUNET_STATISTICS_destroy(h2, GNUNET_NO); 53 GNUNET_STATISTICS_destroy (h2, GNUNET_NO);
54} 54}
55 55
56 56
57static int 57static int
58watch_1(void *cls, const char *subsystem, const char *name, uint64_t value, 58watch_1 (void *cls, const char *subsystem, const char *name, uint64_t value,
59 int is_persistent) 59 int is_persistent)
60{ 60{
61 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
62 "Received value `%s' `%s' %llu\n", 62 "Received value `%s' `%s' %llu\n",
63 subsystem, 63 subsystem,
64 name, 64 name,
65 (unsigned long long)value); 65 (unsigned long long) value);
66 GNUNET_assert(0 == strcmp(name, "test-1")); 66 GNUNET_assert (0 == strcmp (name, "test-1"));
67 if ((0 == value) && (3 == ok)) 67 if ((0 == value) && (3 == ok))
68 { 68 {
69 ok--; 69 ok--;
70 GNUNET_STATISTICS_set(h, "test-1", 42, GNUNET_NO); 70 GNUNET_STATISTICS_set (h, "test-1", 42, GNUNET_NO);
71 } 71 }
72 72
73 if ((42 == value) && (2 == ok)) 73 if ((42 == value) && (2 == ok))
74 { 74 {
75 ok--; 75 ok--;
76 GNUNET_STATISTICS_set(h, "test-1", 0, GNUNET_NO); 76 GNUNET_STATISTICS_set (h, "test-1", 0, GNUNET_NO);
77 } 77 }
78 78
79 if ((0 == value) && (1 == ok)) 79 if ((0 == value) && (1 == ok))
80 { 80 {
81 ok--; 81 ok--;
82 } 82 }
83 if ((0 == ok) && (0 == ok2)) 83 if ((0 == ok) && (0 == ok2))
84 { 84 {
85 GNUNET_SCHEDULER_cancel(shutdown_task); 85 GNUNET_SCHEDULER_cancel (shutdown_task);
86 GNUNET_SCHEDULER_add_now(&normal_shutdown, NULL); 86 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
87 } 87 }
88 88
89 return GNUNET_OK; 89 return GNUNET_OK;
90} 90}
91 91
92 92
93static int 93static int
94watch_2(void *cls, 94watch_2 (void *cls,
95 const char *subsystem, 95 const char *subsystem,
96 const char *name, 96 const char *name,
97 uint64_t value, 97 uint64_t value,
98 int is_persistent) 98 int is_persistent)
99{ 99{
100 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
101 "Received value `%s' `%s' %llu\n", 101 "Received value `%s' `%s' %llu\n",
102 subsystem, 102 subsystem,
103 name, 103 name,
104 (unsigned long long)value); 104 (unsigned long long) value);
105 105
106 GNUNET_assert(0 == strcmp(name, "test-2")); 106 GNUNET_assert (0 == strcmp (name, "test-2"));
107 if ((42 == value) && (1 == ok2)) 107 if ((42 == value) && (1 == ok2))
108 {
109 ok2 = 0;
110 if (0 == ok)
108 { 111 {
109 ok2 = 0; 112 GNUNET_SCHEDULER_cancel (shutdown_task);
110 if (0 == ok) 113 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
111 {
112 GNUNET_SCHEDULER_cancel(shutdown_task);
113 GNUNET_SCHEDULER_add_now(&normal_shutdown, NULL);
114 }
115 } 114 }
115 }
116 else 116 else
117 { 117 {
118 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
119 "Received unexpected value %llu\n", 119 "Received unexpected value %llu\n",
120 (unsigned long long)value); 120 (unsigned long long) value);
121 121
122 GNUNET_break(0); 122 GNUNET_break (0);
123 GNUNET_SCHEDULER_cancel(shutdown_task); 123 GNUNET_SCHEDULER_cancel (shutdown_task);
124 GNUNET_SCHEDULER_add_now(&normal_shutdown, NULL); 124 GNUNET_SCHEDULER_add_now (&normal_shutdown, NULL);
125 } 125 }
126 126
127 return GNUNET_OK; 127 return GNUNET_OK;
128} 128}
129 129
130 130
131static void 131static void
132run(void *cls, char *const *args, const char *cfgfile, 132run (void *cls, char *const *args, const char *cfgfile,
133 const struct GNUNET_CONFIGURATION_Handle *cfg) 133 const struct GNUNET_CONFIGURATION_Handle *cfg)
134{ 134{
135 h = GNUNET_STATISTICS_create("dummy", cfg); 135 h = GNUNET_STATISTICS_create ("dummy", cfg);
136 h2 = GNUNET_STATISTICS_create("dummy-2", cfg); 136 h2 = GNUNET_STATISTICS_create ("dummy-2", cfg);
137 GNUNET_assert(GNUNET_OK == 137 GNUNET_assert (GNUNET_OK ==
138 GNUNET_STATISTICS_watch(h, "dummy", 138 GNUNET_STATISTICS_watch (h, "dummy",
139 "test-1", &watch_1, NULL)); 139 "test-1", &watch_1, NULL));
140 140
141 GNUNET_assert(GNUNET_OK == 141 GNUNET_assert (GNUNET_OK ==
142 GNUNET_STATISTICS_watch(h2, "dummy-2", 142 GNUNET_STATISTICS_watch (h2, "dummy-2",
143 "test-2", &watch_2, NULL)); 143 "test-2", &watch_2, NULL));
144 144
145 /* Set initial value to 0 */ 145 /* Set initial value to 0 */
146 GNUNET_STATISTICS_set(h, "test-1", 0, GNUNET_NO); 146 GNUNET_STATISTICS_set (h, "test-1", 0, GNUNET_NO);
147 GNUNET_STATISTICS_set(h2, "test-2", 42, GNUNET_NO); 147 GNUNET_STATISTICS_set (h2, "test-2", 42, GNUNET_NO);
148 148
149 shutdown_task = 149 shutdown_task =
150 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, 150 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
151 &force_shutdown, 151 &force_shutdown,
152 NULL); 152 NULL);
153} 153}
154 154
155 155
156int 156int
157main(int argc, char *argv_ign[]) 157main (int argc, char *argv_ign[])
158{ 158{
159 char *const argv[] = { "test-statistics-api", 159 char *const argv[] = { "test-statistics-api",
160 "-c", 160 "-c",
@@ -166,27 +166,27 @@ main(int argc, char *argv_ign[])
166 struct GNUNET_OS_Process *proc; 166 struct GNUNET_OS_Process *proc;
167 char *binary; 167 char *binary;
168 168
169 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-statistics"); 169 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics");
170 proc = 170 proc =
171 GNUNET_OS_start_process(GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 171 GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
172 NULL, NULL, NULL, 172 NULL, NULL, NULL,
173 binary, 173 binary,
174 "gnunet-service-statistics", 174 "gnunet-service-statistics",
175 "-c", "test_statistics_api_data.conf", NULL); 175 "-c", "test_statistics_api_data.conf", NULL);
176 GNUNET_assert(NULL != proc); 176 GNUNET_assert (NULL != proc);
177 ok = 3; 177 ok = 3;
178 ok2 = 1; 178 ok2 = 1;
179 GNUNET_PROGRAM_run(3, argv, "test-statistics-api", "nohelp", options, &run, 179 GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run,
180 NULL); 180 NULL);
181 if (0 != GNUNET_OS_process_kill(proc, GNUNET_TERM_SIG)) 181 if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
182 { 182 {
183 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); 183 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
184 ok = 1; 184 ok = 1;
185 } 185 }
186 GNUNET_OS_process_wait(proc); 186 GNUNET_OS_process_wait (proc);
187 GNUNET_OS_process_destroy(proc); 187 GNUNET_OS_process_destroy (proc);
188 proc = NULL; 188 proc = NULL;
189 GNUNET_free(binary); 189 GNUNET_free (binary);
190 if ((0 == ok) && (0 == ok2)) 190 if ((0 == ok) && (0 == ok2))
191 return 0; 191 return 0;
192 return 1; 192 return 1;