diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/statistics/statistics_api.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/statistics/statistics_api.c')
-rw-r--r-- | src/statistics/statistics_api.c | 1120 |
1 files changed, 563 insertions, 557 deletions
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 | */ |
45 | enum ActionType { | 46 | enum 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 | */ |
71 | struct GNUNET_STATISTICS_WatchEntry { | 73 | struct 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 | */ |
97 | struct GNUNET_STATISTICS_GetHandle { | 100 | struct 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 | */ |
173 | struct GNUNET_STATISTICS_Handle { | 177 | struct 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 | */ |
259 | static void | 264 | static void |
260 | update_memory_statistics(struct GNUNET_STATISTICS_Handle *h) | 265 | update_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 | */ |
311 | static void | 316 | static void |
312 | reconnect_later(struct GNUNET_STATISTICS_Handle *h); | 317 | reconnect_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 | */ |
320 | static void | 325 | static void |
321 | schedule_action(void *cls); | 326 | schedule_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 | */ |
331 | static void | 336 | static void |
332 | schedule_watch_request(struct GNUNET_STATISTICS_Handle *h, | 337 | schedule_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 | */ |
369 | static void | 374 | static void |
370 | free_action_item(struct GNUNET_STATISTICS_GetHandle *gh) | 375 | free_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 | */ |
383 | static void | 388 | static void |
384 | do_disconnect(struct GNUNET_STATISTICS_Handle *h) | 389 | do_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 | */ |
416 | static int | 421 | static int |
417 | check_statistics_value(void *cls, | 422 | check_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 | */ |
447 | static void | 452 | static void |
448 | handle_statistics_value(void *cls, | 453 | handle_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 | */ |
492 | static void | 497 | static void |
493 | handle_statistics_watch_value(void *cls, | 498 | handle_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 | */ |
527 | static void | 533 | static void |
528 | mq_error_handler(void *cls, | 534 | mq_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 | */ |
555 | static void | 561 | static void |
556 | do_destroy(void *cls) | 562 | do_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 | */ |
577 | static void | 583 | static void |
578 | handle_disconnect_confirm(void *cls, | 584 | handle_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 | */ |
608 | static void | 614 | static void |
609 | handle_statistics_end(void *cls, | 615 | handle_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 | */ |
643 | static int | 649 | static int |
644 | try_connect(struct GNUNET_STATISTICS_Handle *h) | 650 | try_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 | */ |
708 | static void | 714 | static void |
709 | reconnect_task(void *cls) | 715 | reconnect_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 | */ |
723 | static void | 729 | static void |
724 | reconnect_later(struct GNUNET_STATISTICS_Handle *h) | 730 | reconnect_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 | */ |
766 | static void | 772 | static void |
767 | transmit_get(struct GNUNET_STATISTICS_Handle *handle) | 773 | transmit_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 | */ |
801 | static void | 807 | static void |
802 | transmit_watch(struct GNUNET_STATISTICS_Handle *handle) | 808 | transmit_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 | */ |
840 | static void | 846 | static void |
841 | transmit_set(struct GNUNET_STATISTICS_Handle *handle) | 847 | transmit_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 | */ |
884 | struct GNUNET_STATISTICS_Handle * | 890 | struct GNUNET_STATISTICS_Handle * |
885 | GNUNET_STATISTICS_create(const char *subsystem, | 891 | GNUNET_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 | */ |
911 | void | 917 | void |
912 | GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, | 918 | GNUNET_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 | */ |
996 | static void | 1002 | static void |
997 | schedule_action(void *cls) | 1003 | schedule_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 | */ |
1072 | struct GNUNET_STATISTICS_GetHandle * | 1078 | struct GNUNET_STATISTICS_GetHandle * |
1073 | GNUNET_STATISTICS_get(struct GNUNET_STATISTICS_Handle *handle, | 1079 | GNUNET_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 | */ |
1119 | void | 1125 | void |
1120 | GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh) | 1126 | GNUNET_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 | */ |
1149 | int | 1155 | int |
1150 | GNUNET_STATISTICS_watch(struct GNUNET_STATISTICS_Handle *handle, | 1156 | GNUNET_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 | */ |
1184 | int | 1190 | int |
1185 | GNUNET_STATISTICS_watch_cancel(struct GNUNET_STATISTICS_Handle *handle, | 1191 | GNUNET_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 | */ |
1227 | static void | 1233 | static void |
1228 | add_setter_action(struct GNUNET_STATISTICS_Handle *h, | 1234 | add_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 | */ |
1329 | void | 1335 | void |
1330 | GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, | 1336 | GNUNET_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 | */ |
1355 | void | 1361 | void |
1356 | GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, | 1362 | GNUNET_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 | ||