diff options
Diffstat (limited to 'src/statistics/statistics_api.c')
-rw-r--r-- | src/statistics/statistics_api.c | 1146 |
1 files changed, 570 insertions, 576 deletions
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index da307c887..487f2569c 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file statistics/statistics_api.c | 22 | * @file statistics/statistics_api.c |
@@ -35,15 +35,14 @@ | |||
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(GNUNET_TIME_UNIT_SECONDS, 2) |
39 | 39 | ||
40 | #define LOG(kind,...) GNUNET_log_from (kind, "statistics-api",__VA_ARGS__) | 40 | #define LOG(kind, ...) GNUNET_log_from(kind, "statistics-api", __VA_ARGS__) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Types of actions. | 43 | * Types of actions. |
44 | */ | 44 | */ |
45 | enum ActionType | 45 | enum ActionType { |
46 | { | ||
47 | /** | 46 | /** |
48 | * Get a value. | 47 | * Get a value. |
49 | */ | 48 | */ |
@@ -69,9 +68,7 @@ enum ActionType | |||
69 | /** | 68 | /** |
70 | * Entry kept for each value we are watching. | 69 | * Entry kept for each value we are watching. |
71 | */ | 70 | */ |
72 | struct GNUNET_STATISTICS_WatchEntry | 71 | struct GNUNET_STATISTICS_WatchEntry { |
73 | { | ||
74 | |||
75 | /** | 72 | /** |
76 | * What subsystem is this action about? (never NULL) | 73 | * What subsystem is this action about? (never NULL) |
77 | */ | 74 | */ |
@@ -91,16 +88,13 @@ struct GNUNET_STATISTICS_WatchEntry | |||
91 | * Closure for @e proc | 88 | * Closure for @e proc |
92 | */ | 89 | */ |
93 | void *proc_cls; | 90 | void *proc_cls; |
94 | |||
95 | }; | 91 | }; |
96 | 92 | ||
97 | 93 | ||
98 | /** | 94 | /** |
99 | * Linked list of things we still need to do. | 95 | * Linked list of things we still need to do. |
100 | */ | 96 | */ |
101 | struct GNUNET_STATISTICS_GetHandle | 97 | struct GNUNET_STATISTICS_GetHandle { |
102 | { | ||
103 | |||
104 | /** | 98 | /** |
105 | * This is a doubly linked list. | 99 | * This is a doubly linked list. |
106 | */ | 100 | */ |
@@ -170,15 +164,13 @@ struct GNUNET_STATISTICS_GetHandle | |||
170 | * Size of the message that we will be transmitting. | 164 | * Size of the message that we will be transmitting. |
171 | */ | 165 | */ |
172 | uint16_t msize; | 166 | uint16_t msize; |
173 | |||
174 | }; | 167 | }; |
175 | 168 | ||
176 | 169 | ||
177 | /** | 170 | /** |
178 | * Handle for the service. | 171 | * Handle for the service. |
179 | */ | 172 | */ |
180 | struct GNUNET_STATISTICS_Handle | 173 | struct GNUNET_STATISTICS_Handle { |
181 | { | ||
182 | /** | 174 | /** |
183 | * Name of our subsystem. | 175 | * Name of our subsystem. |
184 | */ | 176 | */ |
@@ -257,7 +249,6 @@ struct GNUNET_STATISTICS_Handle | |||
257 | * Are we currently receiving from the service? | 249 | * Are we currently receiving from the service? |
258 | */ | 250 | */ |
259 | int receiving; | 251 | int receiving; |
260 | |||
261 | }; | 252 | }; |
262 | 253 | ||
263 | 254 | ||
@@ -266,7 +257,7 @@ struct GNUNET_STATISTICS_Handle | |||
266 | * report those as well (if they changed). | 257 | * report those as well (if they changed). |
267 | */ | 258 | */ |
268 | static void | 259 | static void |
269 | update_memory_statistics (struct GNUNET_STATISTICS_Handle *h) | 260 | update_memory_statistics(struct GNUNET_STATISTICS_Handle *h) |
270 | { | 261 | { |
271 | #if ENABLE_HEAP_STATISTICS | 262 | #if ENABLE_HEAP_STATISTICS |
272 | uint64_t current_heap_size = 0; | 263 | uint64_t current_heap_size = 0; |
@@ -286,28 +277,28 @@ update_memory_statistics (struct GNUNET_STATISTICS_Handle *h) | |||
286 | { | 277 | { |
287 | struct rusage ru; | 278 | struct rusage ru; |
288 | 279 | ||
289 | if (0 == getrusage (RUSAGE_SELF, &ru)) | 280 | if (0 == getrusage(RUSAGE_SELF, &ru)) |
290 | { | 281 | { |
291 | current_rss = 1024LL * ru.ru_maxrss; | 282 | current_rss = 1024LL * ru.ru_maxrss; |
292 | } | 283 | } |
293 | } | 284 | } |
294 | #endif | 285 | #endif |
295 | if (current_heap_size > h->peak_heap_size) | 286 | if (current_heap_size > h->peak_heap_size) |
296 | { | 287 | { |
297 | h->peak_heap_size = current_heap_size; | 288 | h->peak_heap_size = current_heap_size; |
298 | GNUNET_STATISTICS_set (h, | 289 | GNUNET_STATISTICS_set(h, |
299 | "# peak heap size", | 290 | "# peak heap size", |
300 | current_heap_size, | 291 | current_heap_size, |
301 | GNUNET_NO); | 292 | GNUNET_NO); |
302 | } | 293 | } |
303 | if (current_rss > h->peak_rss) | 294 | if (current_rss > h->peak_rss) |
304 | { | 295 | { |
305 | h->peak_rss = current_rss; | 296 | h->peak_rss = current_rss; |
306 | GNUNET_STATISTICS_set (h, | 297 | GNUNET_STATISTICS_set(h, |
307 | "# peak resident set size", | 298 | "# peak resident set size", |
308 | current_rss, | 299 | current_rss, |
309 | GNUNET_NO); | 300 | GNUNET_NO); |
310 | } | 301 | } |
311 | #endif | 302 | #endif |
312 | } | 303 | } |
313 | 304 | ||
@@ -318,7 +309,7 @@ update_memory_statistics (struct GNUNET_STATISTICS_Handle *h) | |||
318 | * @param h statistics handle | 309 | * @param h statistics handle |
319 | */ | 310 | */ |
320 | static void | 311 | static void |
321 | reconnect_later (struct GNUNET_STATISTICS_Handle *h); | 312 | reconnect_later(struct GNUNET_STATISTICS_Handle *h); |
322 | 313 | ||
323 | 314 | ||
324 | /** | 315 | /** |
@@ -327,7 +318,7 @@ reconnect_later (struct GNUNET_STATISTICS_Handle *h); | |||
327 | * @param cls statistics handle to reconnect | 318 | * @param cls statistics handle to reconnect |
328 | */ | 319 | */ |
329 | static void | 320 | static void |
330 | schedule_action (void *cls); | 321 | schedule_action(void *cls); |
331 | 322 | ||
332 | 323 | ||
333 | /** | 324 | /** |
@@ -338,35 +329,35 @@ schedule_action (void *cls); | |||
338 | * @param watch watch entry of the value to watch | 329 | * @param watch watch entry of the value to watch |
339 | */ | 330 | */ |
340 | static void | 331 | static void |
341 | schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, | 332 | schedule_watch_request(struct GNUNET_STATISTICS_Handle *h, |
342 | struct GNUNET_STATISTICS_WatchEntry *watch) | 333 | struct GNUNET_STATISTICS_WatchEntry *watch) |
343 | { | 334 | { |
344 | struct GNUNET_STATISTICS_GetHandle *ai; | 335 | struct GNUNET_STATISTICS_GetHandle *ai; |
345 | size_t slen; | 336 | size_t slen; |
346 | size_t nlen; | 337 | size_t nlen; |
347 | size_t nsize; | 338 | size_t nsize; |
348 | 339 | ||
349 | slen = strlen (watch->subsystem) + 1; | 340 | slen = strlen(watch->subsystem) + 1; |
350 | nlen = strlen (watch->name) + 1; | 341 | nlen = strlen(watch->name) + 1; |
351 | nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen; | 342 | nsize = sizeof(struct GNUNET_MessageHeader) + slen + nlen; |
352 | if (nsize >= GNUNET_MAX_MESSAGE_SIZE) | 343 | if (nsize >= GNUNET_MAX_MESSAGE_SIZE) |
353 | { | 344 | { |
354 | GNUNET_break (0); | 345 | GNUNET_break(0); |
355 | return; | 346 | return; |
356 | } | 347 | } |
357 | ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle); | 348 | ai = GNUNET_new(struct GNUNET_STATISTICS_GetHandle); |
358 | ai->sh = h; | 349 | ai->sh = h; |
359 | ai->subsystem = GNUNET_strdup (watch->subsystem); | 350 | ai->subsystem = GNUNET_strdup(watch->subsystem); |
360 | ai->name = GNUNET_strdup (watch->name); | 351 | ai->name = GNUNET_strdup(watch->name); |
361 | ai->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 352 | ai->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
362 | ai->msize = nsize; | 353 | ai->msize = nsize; |
363 | ai->type = ACTION_WATCH; | 354 | ai->type = ACTION_WATCH; |
364 | ai->proc = watch->proc; | 355 | ai->proc = watch->proc; |
365 | ai->cls = watch->proc_cls; | 356 | ai->cls = watch->proc_cls; |
366 | GNUNET_CONTAINER_DLL_insert_tail (h->action_head, | 357 | GNUNET_CONTAINER_DLL_insert_tail(h->action_head, |
367 | h->action_tail, | 358 | h->action_tail, |
368 | ai); | 359 | ai); |
369 | schedule_action (h); | 360 | schedule_action(h); |
370 | } | 361 | } |
371 | 362 | ||
372 | 363 | ||
@@ -376,11 +367,11 @@ schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, | |||
376 | * @param gh action item to free | 367 | * @param gh action item to free |
377 | */ | 368 | */ |
378 | static void | 369 | static void |
379 | free_action_item (struct GNUNET_STATISTICS_GetHandle *gh) | 370 | free_action_item(struct GNUNET_STATISTICS_GetHandle *gh) |
380 | { | 371 | { |
381 | GNUNET_free_non_null (gh->subsystem); | 372 | GNUNET_free_non_null(gh->subsystem); |
382 | GNUNET_free_non_null (gh->name); | 373 | GNUNET_free_non_null(gh->name); |
383 | GNUNET_free (gh); | 374 | GNUNET_free(gh); |
384 | } | 375 | } |
385 | 376 | ||
386 | 377 | ||
@@ -390,28 +381,28 @@ free_action_item (struct GNUNET_STATISTICS_GetHandle *gh) | |||
390 | * @param h statistics handle to disconnect from | 381 | * @param h statistics handle to disconnect from |
391 | */ | 382 | */ |
392 | static void | 383 | static void |
393 | do_disconnect (struct GNUNET_STATISTICS_Handle *h) | 384 | do_disconnect(struct GNUNET_STATISTICS_Handle *h) |
394 | { | 385 | { |
395 | struct GNUNET_STATISTICS_GetHandle *c; | 386 | struct GNUNET_STATISTICS_GetHandle *c; |
396 | 387 | ||
397 | h->receiving = GNUNET_NO; | 388 | h->receiving = GNUNET_NO; |
398 | if (NULL != (c = h->current)) | 389 | if (NULL != (c = h->current)) |
399 | { | ||
400 | h->current = NULL; | ||
401 | if ( (NULL != c->cont) && | ||
402 | (GNUNET_YES != c->aborted) ) | ||
403 | { | 390 | { |
404 | c->cont (c->cls, | 391 | h->current = NULL; |
405 | GNUNET_SYSERR); | 392 | if ((NULL != c->cont) && |
406 | c->cont = NULL; | 393 | (GNUNET_YES != c->aborted)) |
394 | { | ||
395 | c->cont(c->cls, | ||
396 | GNUNET_SYSERR); | ||
397 | c->cont = NULL; | ||
398 | } | ||
399 | free_action_item(c); | ||
407 | } | 400 | } |
408 | free_action_item (c); | ||
409 | } | ||
410 | if (NULL != h->mq) | 401 | if (NULL != h->mq) |
411 | { | 402 | { |
412 | GNUNET_MQ_destroy (h->mq); | 403 | GNUNET_MQ_destroy(h->mq); |
413 | h->mq = NULL; | 404 | h->mq = NULL; |
414 | } | 405 | } |
415 | } | 406 | } |
416 | 407 | ||
417 | 408 | ||
@@ -423,25 +414,25 @@ do_disconnect (struct GNUNET_STATISTICS_Handle *h) | |||
423 | * @return #GNUNET_OK if the message was well-formed | 414 | * @return #GNUNET_OK if the message was well-formed |
424 | */ | 415 | */ |
425 | static int | 416 | static int |
426 | check_statistics_value (void *cls, | 417 | check_statistics_value(void *cls, |
427 | const struct GNUNET_STATISTICS_ReplyMessage *smsg) | 418 | const struct GNUNET_STATISTICS_ReplyMessage *smsg) |
428 | { | 419 | { |
429 | const char *service; | 420 | const char *service; |
430 | const char *name; | 421 | const char *name; |
431 | uint16_t size; | 422 | uint16_t size; |
432 | 423 | ||
433 | size = ntohs (smsg->header.size); | 424 | size = ntohs(smsg->header.size); |
434 | size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); | 425 | size -= sizeof(struct GNUNET_STATISTICS_ReplyMessage); |
435 | if (size != | 426 | if (size != |
436 | GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], | 427 | GNUNET_STRINGS_buffer_tokenize((const char *)&smsg[1], |
437 | size, | 428 | size, |
438 | 2, | 429 | 2, |
439 | &service, | 430 | &service, |
440 | &name)) | 431 | &name)) |
441 | { | 432 | { |
442 | GNUNET_break (0); | 433 | GNUNET_break(0); |
443 | return GNUNET_SYSERR; | 434 | return GNUNET_SYSERR; |
444 | } | 435 | } |
445 | return GNUNET_OK; | 436 | return GNUNET_OK; |
446 | } | 437 | } |
447 | 438 | ||
@@ -454,8 +445,8 @@ check_statistics_value (void *cls, | |||
454 | * @return #GNUNET_OK if the message was well-formed | 445 | * @return #GNUNET_OK if the message was well-formed |
455 | */ | 446 | */ |
456 | static void | 447 | static void |
457 | handle_statistics_value (void *cls, | 448 | handle_statistics_value(void *cls, |
458 | const struct GNUNET_STATISTICS_ReplyMessage *smsg) | 449 | const struct GNUNET_STATISTICS_ReplyMessage *smsg) |
459 | { | 450 | { |
460 | struct GNUNET_STATISTICS_Handle *h = cls; | 451 | struct GNUNET_STATISTICS_Handle *h = cls; |
461 | const char *service; | 452 | const char *service; |
@@ -465,30 +456,30 @@ handle_statistics_value (void *cls, | |||
465 | if (h->current->aborted) | 456 | if (h->current->aborted) |
466 | return; /* iteration aborted, don't bother */ | 457 | return; /* iteration aborted, don't bother */ |
467 | 458 | ||
468 | size = ntohs (smsg->header.size); | 459 | size = ntohs(smsg->header.size); |
469 | size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); | 460 | size -= sizeof(struct GNUNET_STATISTICS_ReplyMessage); |
470 | GNUNET_assert (size == | 461 | GNUNET_assert(size == |
471 | GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], | 462 | GNUNET_STRINGS_buffer_tokenize((const char *)&smsg[1], |
472 | size, | 463 | size, |
473 | 2, | 464 | 2, |
474 | &service, | 465 | &service, |
475 | &name)); | 466 | &name)); |
476 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 467 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
477 | "Received valid statistic on `%s:%s': %llu\n", | 468 | "Received valid statistic on `%s:%s': %llu\n", |
478 | service, name, | 469 | service, name, |
479 | GNUNET_ntohll (smsg->value)); | 470 | GNUNET_ntohll(smsg->value)); |
480 | if (GNUNET_OK != | 471 | if (GNUNET_OK != |
481 | h->current->proc (h->current->cls, | 472 | h->current->proc(h->current->cls, |
482 | service, | 473 | service, |
483 | name, | 474 | name, |
484 | GNUNET_ntohll (smsg->value), | 475 | GNUNET_ntohll(smsg->value), |
485 | 0 != | 476 | 0 != |
486 | (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) | 477 | (ntohl(smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) |
487 | { | 478 | { |
488 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 479 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
489 | "Processing of remaining statistics aborted by client.\n"); | 480 | "Processing of remaining statistics aborted by client.\n"); |
490 | h->current->aborted = GNUNET_YES; | 481 | h->current->aborted = GNUNET_YES; |
491 | } | 482 | } |
492 | } | 483 | } |
493 | 484 | ||
494 | 485 | ||
@@ -499,29 +490,29 @@ handle_statistics_value (void *cls, | |||
499 | * @param msg the watch value message | 490 | * @param msg the watch value message |
500 | */ | 491 | */ |
501 | static void | 492 | static void |
502 | handle_statistics_watch_value (void *cls, | 493 | handle_statistics_watch_value(void *cls, |
503 | const struct GNUNET_STATISTICS_WatchValueMessage *wvm) | 494 | const struct GNUNET_STATISTICS_WatchValueMessage *wvm) |
504 | { | 495 | { |
505 | struct GNUNET_STATISTICS_Handle *h = cls; | 496 | struct GNUNET_STATISTICS_Handle *h = cls; |
506 | struct GNUNET_STATISTICS_WatchEntry *w; | 497 | struct GNUNET_STATISTICS_WatchEntry *w; |
507 | uint32_t wid; | 498 | uint32_t wid; |
508 | 499 | ||
509 | GNUNET_break (0 == ntohl (wvm->reserved)); | 500 | GNUNET_break(0 == ntohl(wvm->reserved)); |
510 | wid = ntohl (wvm->wid); | 501 | wid = ntohl(wvm->wid); |
511 | if (wid >= h->watches_size) | 502 | if (wid >= h->watches_size) |
512 | { | 503 | { |
513 | do_disconnect (h); | 504 | do_disconnect(h); |
514 | reconnect_later (h); | 505 | reconnect_later(h); |
515 | return; | 506 | return; |
516 | } | 507 | } |
517 | w = h->watches[wid]; | 508 | w = h->watches[wid]; |
518 | if (NULL == w) | 509 | if (NULL == w) |
519 | return; | 510 | return; |
520 | (void) w->proc (w->proc_cls, | 511 | (void)w->proc(w->proc_cls, |
521 | w->subsystem, | 512 | w->subsystem, |
522 | w->name, | 513 | w->name, |
523 | GNUNET_ntohll (wvm->value), | 514 | GNUNET_ntohll(wvm->value), |
524 | 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); | 515 | 0 != (ntohl(wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); |
525 | } | 516 | } |
526 | 517 | ||
527 | 518 | ||
@@ -534,25 +525,25 @@ handle_statistics_watch_value (void *cls, | |||
534 | * @param error error code | 525 | * @param error error code |
535 | */ | 526 | */ |
536 | static void | 527 | static void |
537 | mq_error_handler (void *cls, | 528 | mq_error_handler(void *cls, |
538 | enum GNUNET_MQ_Error error) | 529 | enum GNUNET_MQ_Error error) |
539 | { | 530 | { |
540 | struct GNUNET_STATISTICS_Handle *h = cls; | 531 | struct GNUNET_STATISTICS_Handle *h = cls; |
541 | 532 | ||
542 | if (GNUNET_NO != h->do_destroy) | 533 | if (GNUNET_NO != h->do_destroy) |
543 | { | ||
544 | h->do_destroy = GNUNET_NO; | ||
545 | if (NULL != h->destroy_task) | ||
546 | { | 534 | { |
547 | GNUNET_SCHEDULER_cancel (h->destroy_task); | 535 | h->do_destroy = GNUNET_NO; |
548 | h->destroy_task = NULL; | 536 | if (NULL != h->destroy_task) |
537 | { | ||
538 | GNUNET_SCHEDULER_cancel(h->destroy_task); | ||
539 | h->destroy_task = NULL; | ||
540 | } | ||
541 | GNUNET_STATISTICS_destroy(h, | ||
542 | GNUNET_NO); | ||
543 | return; | ||
549 | } | 544 | } |
550 | GNUNET_STATISTICS_destroy (h, | 545 | do_disconnect(h); |
551 | GNUNET_NO); | 546 | reconnect_later(h); |
552 | return; | ||
553 | } | ||
554 | do_disconnect (h); | ||
555 | reconnect_later (h); | ||
556 | } | 547 | } |
557 | 548 | ||
558 | 549 | ||
@@ -562,16 +553,16 @@ mq_error_handler (void *cls, | |||
562 | * @param cls the `struct GNUNET_STATISTICS_Handle` | 553 | * @param cls the `struct GNUNET_STATISTICS_Handle` |
563 | */ | 554 | */ |
564 | static void | 555 | static void |
565 | do_destroy (void *cls) | 556 | do_destroy(void *cls) |
566 | { | 557 | { |
567 | struct GNUNET_STATISTICS_Handle *h = cls; | 558 | struct GNUNET_STATISTICS_Handle *h = cls; |
568 | 559 | ||
569 | h->destroy_task = NULL; | 560 | h->destroy_task = NULL; |
570 | h->do_destroy = GNUNET_NO; | 561 | h->do_destroy = GNUNET_NO; |
571 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 562 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
572 | "Running final destruction\n"); | 563 | "Running final destruction\n"); |
573 | GNUNET_STATISTICS_destroy (h, | 564 | GNUNET_STATISTICS_destroy(h, |
574 | GNUNET_NO); | 565 | GNUNET_NO); |
575 | } | 566 | } |
576 | 567 | ||
577 | 568 | ||
@@ -584,25 +575,25 @@ do_destroy (void *cls) | |||
584 | * @param msg the message | 575 | * @param msg the message |
585 | */ | 576 | */ |
586 | static void | 577 | static void |
587 | handle_disconnect_confirm (void *cls, | 578 | handle_disconnect_confirm(void *cls, |
588 | const struct GNUNET_MessageHeader *msg) | 579 | const struct GNUNET_MessageHeader *msg) |
589 | { | 580 | { |
590 | struct GNUNET_STATISTICS_Handle *h = cls; | 581 | struct GNUNET_STATISTICS_Handle *h = cls; |
591 | 582 | ||
592 | if (GNUNET_SYSERR != h->do_destroy) | 583 | if (GNUNET_SYSERR != h->do_destroy) |
593 | { | 584 | { |
594 | /* not in shutdown, why do we get 'TEST'? */ | 585 | /* not in shutdown, why do we get 'TEST'? */ |
595 | GNUNET_break (0); | 586 | GNUNET_break(0); |
596 | do_disconnect (h); | 587 | do_disconnect(h); |
597 | reconnect_later (h); | 588 | reconnect_later(h); |
598 | return; | 589 | return; |
599 | } | 590 | } |
600 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 591 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
601 | "Received DISCONNNECT_CONFIRM message from statistics, can complete disconnect\n"); | 592 | "Received DISCONNNECT_CONFIRM message from statistics, can complete disconnect\n"); |
602 | if (NULL != h->destroy_task) | 593 | if (NULL != h->destroy_task) |
603 | GNUNET_SCHEDULER_cancel (h->destroy_task); | 594 | GNUNET_SCHEDULER_cancel(h->destroy_task); |
604 | h->destroy_task = GNUNET_SCHEDULER_add_now (&do_destroy, | 595 | h->destroy_task = GNUNET_SCHEDULER_add_now(&do_destroy, |
605 | h); | 596 | h); |
606 | } | 597 | } |
607 | 598 | ||
608 | 599 | ||
@@ -615,31 +606,31 @@ handle_disconnect_confirm (void *cls, | |||
615 | * @param msg the message | 606 | * @param msg the message |
616 | */ | 607 | */ |
617 | static void | 608 | static void |
618 | handle_statistics_end (void *cls, | 609 | handle_statistics_end(void *cls, |
619 | const struct GNUNET_MessageHeader *msg) | 610 | const struct GNUNET_MessageHeader *msg) |
620 | { | 611 | { |
621 | struct GNUNET_STATISTICS_Handle *h = cls; | 612 | struct GNUNET_STATISTICS_Handle *h = cls; |
622 | struct GNUNET_STATISTICS_GetHandle *c; | 613 | struct GNUNET_STATISTICS_GetHandle *c; |
623 | 614 | ||
624 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 615 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
625 | "Received end of statistics marker\n"); | 616 | "Received end of statistics marker\n"); |
626 | if (NULL == (c = h->current)) | 617 | if (NULL == (c = h->current)) |
627 | { | 618 | { |
628 | GNUNET_break (0); | 619 | GNUNET_break(0); |
629 | do_disconnect (h); | 620 | do_disconnect(h); |
630 | reconnect_later (h); | 621 | reconnect_later(h); |
631 | return; | 622 | return; |
632 | } | 623 | } |
633 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 624 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
634 | h->current = NULL; | 625 | h->current = NULL; |
635 | schedule_action (h); | 626 | schedule_action(h); |
636 | if (NULL != c->cont) | 627 | if (NULL != c->cont) |
637 | { | 628 | { |
638 | c->cont (c->cls, | 629 | c->cont(c->cls, |
639 | GNUNET_OK); | 630 | GNUNET_OK); |
640 | c->cont = NULL; | 631 | c->cont = NULL; |
641 | } | 632 | } |
642 | free_action_item (c); | 633 | free_action_item(c); |
643 | } | 634 | } |
644 | 635 | ||
645 | 636 | ||
@@ -650,26 +641,26 @@ handle_statistics_end (void *cls, | |||
650 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. | 641 | * @return #GNUNET_YES on success, #GNUNET_NO on failure. |
651 | */ | 642 | */ |
652 | static int | 643 | static int |
653 | try_connect (struct GNUNET_STATISTICS_Handle *h) | 644 | try_connect(struct GNUNET_STATISTICS_Handle *h) |
654 | { | 645 | { |
655 | struct GNUNET_MQ_MessageHandler handlers[] = { | 646 | struct GNUNET_MQ_MessageHandler handlers[] = { |
656 | GNUNET_MQ_hd_fixed_size (disconnect_confirm, | 647 | GNUNET_MQ_hd_fixed_size(disconnect_confirm, |
657 | GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM, | 648 | GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM, |
658 | struct GNUNET_MessageHeader, | 649 | struct GNUNET_MessageHeader, |
659 | h), | 650 | h), |
660 | GNUNET_MQ_hd_fixed_size (statistics_end, | 651 | GNUNET_MQ_hd_fixed_size(statistics_end, |
661 | GNUNET_MESSAGE_TYPE_STATISTICS_END, | 652 | GNUNET_MESSAGE_TYPE_STATISTICS_END, |
662 | struct GNUNET_MessageHeader, | 653 | struct GNUNET_MessageHeader, |
663 | h), | 654 | h), |
664 | GNUNET_MQ_hd_var_size (statistics_value, | 655 | GNUNET_MQ_hd_var_size(statistics_value, |
665 | GNUNET_MESSAGE_TYPE_STATISTICS_VALUE, | 656 | GNUNET_MESSAGE_TYPE_STATISTICS_VALUE, |
666 | struct GNUNET_STATISTICS_ReplyMessage, | 657 | struct GNUNET_STATISTICS_ReplyMessage, |
667 | h), | 658 | h), |
668 | GNUNET_MQ_hd_fixed_size (statistics_watch_value, | 659 | GNUNET_MQ_hd_fixed_size(statistics_watch_value, |
669 | GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE, | 660 | GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE, |
670 | struct GNUNET_STATISTICS_WatchValueMessage, | 661 | struct GNUNET_STATISTICS_WatchValueMessage, |
671 | h), | 662 | h), |
672 | GNUNET_MQ_handler_end () | 663 | GNUNET_MQ_handler_end() |
673 | }; | 664 | }; |
674 | struct GNUNET_STATISTICS_GetHandle *gh; | 665 | struct GNUNET_STATISTICS_GetHandle *gh; |
675 | struct GNUNET_STATISTICS_GetHandle *gn; | 666 | struct GNUNET_STATISTICS_GetHandle *gn; |
@@ -678,33 +669,33 @@ try_connect (struct GNUNET_STATISTICS_Handle *h) | |||
678 | return GNUNET_NO; | 669 | return GNUNET_NO; |
679 | if (NULL != h->mq) | 670 | if (NULL != h->mq) |
680 | return GNUNET_YES; | 671 | return GNUNET_YES; |
681 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 672 | h->mq = GNUNET_CLIENT_connect(h->cfg, |
682 | "statistics", | 673 | "statistics", |
683 | handlers, | 674 | handlers, |
684 | &mq_error_handler, | 675 | &mq_error_handler, |
685 | h); | 676 | h); |
686 | if (NULL == h->mq) | 677 | if (NULL == h->mq) |
687 | { | 678 | { |
688 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 679 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
689 | "Failed to connect to statistics service!\n"); | 680 | "Failed to connect to statistics service!\n"); |
690 | return GNUNET_NO; | 681 | return GNUNET_NO; |
691 | } | 682 | } |
692 | gn = h->action_head; | 683 | gn = h->action_head; |
693 | while (NULL != (gh = gn)) | 684 | while (NULL != (gh = gn)) |
694 | { | ||
695 | gn = gh->next; | ||
696 | if (gh->type == ACTION_WATCH) | ||
697 | { | 685 | { |
698 | GNUNET_CONTAINER_DLL_remove (h->action_head, | 686 | gn = gh->next; |
699 | h->action_tail, | 687 | if (gh->type == ACTION_WATCH) |
700 | gh); | 688 | { |
701 | free_action_item (gh); | 689 | GNUNET_CONTAINER_DLL_remove(h->action_head, |
690 | h->action_tail, | ||
691 | gh); | ||
692 | free_action_item(gh); | ||
693 | } | ||
702 | } | 694 | } |
703 | } | ||
704 | for (unsigned int i = 0; i < h->watches_size; i++) | 695 | for (unsigned int i = 0; i < h->watches_size; i++) |
705 | if (NULL != h->watches[i]) | 696 | if (NULL != h->watches[i]) |
706 | schedule_watch_request (h, | 697 | schedule_watch_request(h, |
707 | h->watches[i]); | 698 | h->watches[i]); |
708 | return GNUNET_YES; | 699 | return GNUNET_YES; |
709 | } | 700 | } |
710 | 701 | ||
@@ -715,12 +706,12 @@ try_connect (struct GNUNET_STATISTICS_Handle *h) | |||
715 | * @param cls the `struct GNUNET_STATISTICS_Handle` to reconnect | 706 | * @param cls the `struct GNUNET_STATISTICS_Handle` to reconnect |
716 | */ | 707 | */ |
717 | static void | 708 | static void |
718 | reconnect_task (void *cls) | 709 | reconnect_task(void *cls) |
719 | { | 710 | { |
720 | struct GNUNET_STATISTICS_Handle *h = cls; | 711 | struct GNUNET_STATISTICS_Handle *h = cls; |
721 | 712 | ||
722 | h->backoff_task = NULL; | 713 | h->backoff_task = NULL; |
723 | schedule_action (h); | 714 | schedule_action(h); |
724 | } | 715 | } |
725 | 716 | ||
726 | 717 | ||
@@ -730,38 +721,38 @@ reconnect_task (void *cls) | |||
730 | * @param h statistics handle | 721 | * @param h statistics handle |
731 | */ | 722 | */ |
732 | static void | 723 | static void |
733 | reconnect_later (struct GNUNET_STATISTICS_Handle *h) | 724 | reconnect_later(struct GNUNET_STATISTICS_Handle *h) |
734 | { | 725 | { |
735 | int loss; | 726 | int loss; |
736 | struct GNUNET_STATISTICS_GetHandle *gh; | 727 | struct GNUNET_STATISTICS_GetHandle *gh; |
737 | 728 | ||
738 | GNUNET_assert (NULL == h->backoff_task); | 729 | GNUNET_assert(NULL == h->backoff_task); |
739 | if (GNUNET_YES == h->do_destroy) | 730 | if (GNUNET_YES == h->do_destroy) |
740 | { | 731 | { |
741 | /* So we are shutting down and the service is not reachable. | 732 | /* So we are shutting down and the service is not reachable. |
742 | * Chances are that it's down for good and we are not going to connect to | 733 | * Chances are that it's down for good and we are not going to connect to |
743 | * it anymore. | 734 | * it anymore. |
744 | * Give up and don't sync the rest of the data. | 735 | * Give up and don't sync the rest of the data. |
745 | */ | 736 | */ |
746 | loss = GNUNET_NO; | 737 | loss = GNUNET_NO; |
747 | for (gh = h->action_head; NULL != gh; gh = gh->next) | 738 | for (gh = h->action_head; NULL != gh; gh = gh->next) |
748 | if ( (gh->make_persistent) && | 739 | if ((gh->make_persistent) && |
749 | (ACTION_SET == gh->type) ) | 740 | (ACTION_SET == gh->type)) |
750 | loss = GNUNET_YES; | 741 | loss = GNUNET_YES; |
751 | if (GNUNET_YES == loss) | 742 | if (GNUNET_YES == loss) |
752 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 743 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
753 | _("Could not save some persistent statistics\n")); | 744 | _("Could not save some persistent statistics\n")); |
754 | if (NULL != h->destroy_task) | 745 | if (NULL != h->destroy_task) |
755 | GNUNET_SCHEDULER_cancel (h->destroy_task); | 746 | GNUNET_SCHEDULER_cancel(h->destroy_task); |
756 | h->destroy_task = GNUNET_SCHEDULER_add_now (&do_destroy, | 747 | h->destroy_task = GNUNET_SCHEDULER_add_now(&do_destroy, |
757 | h); | 748 | h); |
758 | return; | 749 | return; |
759 | } | 750 | } |
760 | h->backoff_task | 751 | h->backoff_task |
761 | = GNUNET_SCHEDULER_add_delayed (h->backoff, | 752 | = GNUNET_SCHEDULER_add_delayed(h->backoff, |
762 | &reconnect_task, | 753 | &reconnect_task, |
763 | h); | 754 | h); |
764 | h->backoff = GNUNET_TIME_STD_BACKOFF (h->backoff); | 755 | h->backoff = GNUNET_TIME_STD_BACKOFF(h->backoff); |
765 | } | 756 | } |
766 | 757 | ||
767 | 758 | ||
@@ -773,7 +764,7 @@ reconnect_later (struct GNUNET_STATISTICS_Handle *h) | |||
773 | * @param handle statistics handle | 764 | * @param handle statistics handle |
774 | */ | 765 | */ |
775 | static void | 766 | static void |
776 | transmit_get (struct GNUNET_STATISTICS_Handle *handle) | 767 | transmit_get(struct GNUNET_STATISTICS_Handle *handle) |
777 | { | 768 | { |
778 | struct GNUNET_STATISTICS_GetHandle *c; | 769 | struct GNUNET_STATISTICS_GetHandle *c; |
779 | struct GNUNET_MessageHeader *hdr; | 770 | struct GNUNET_MessageHeader *hdr; |
@@ -781,23 +772,23 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle) | |||
781 | size_t slen1; | 772 | size_t slen1; |
782 | size_t slen2; | 773 | size_t slen2; |
783 | 774 | ||
784 | GNUNET_assert (NULL != (c = handle->current)); | 775 | GNUNET_assert(NULL != (c = handle->current)); |
785 | slen1 = strlen (c->subsystem) + 1; | 776 | slen1 = strlen(c->subsystem) + 1; |
786 | slen2 = strlen (c->name) + 1; | 777 | slen2 = strlen(c->name) + 1; |
787 | env = GNUNET_MQ_msg_extra (hdr, | 778 | env = GNUNET_MQ_msg_extra(hdr, |
788 | slen1 + slen2, | 779 | slen1 + slen2, |
789 | GNUNET_MESSAGE_TYPE_STATISTICS_GET); | 780 | GNUNET_MESSAGE_TYPE_STATISTICS_GET); |
790 | GNUNET_assert (slen1 + slen2 == | 781 | GNUNET_assert(slen1 + slen2 == |
791 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], | 782 | GNUNET_STRINGS_buffer_fill((char *)&hdr[1], |
792 | slen1 + slen2, | 783 | slen1 + slen2, |
793 | 2, | 784 | 2, |
794 | c->subsystem, | 785 | c->subsystem, |
795 | c->name)); | 786 | c->name)); |
796 | GNUNET_MQ_notify_sent (env, | 787 | GNUNET_MQ_notify_sent(env, |
797 | &schedule_action, | 788 | &schedule_action, |
798 | handle); | 789 | handle); |
799 | GNUNET_MQ_send (handle->mq, | 790 | GNUNET_MQ_send(handle->mq, |
800 | env); | 791 | env); |
801 | } | 792 | } |
802 | 793 | ||
803 | 794 | ||
@@ -808,36 +799,36 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle) | |||
808 | * @param handle statistics handle | 799 | * @param handle statistics handle |
809 | */ | 800 | */ |
810 | static void | 801 | static void |
811 | transmit_watch (struct GNUNET_STATISTICS_Handle *handle) | 802 | transmit_watch(struct GNUNET_STATISTICS_Handle *handle) |
812 | { | 803 | { |
813 | struct GNUNET_MessageHeader *hdr; | 804 | struct GNUNET_MessageHeader *hdr; |
814 | struct GNUNET_MQ_Envelope *env; | 805 | struct GNUNET_MQ_Envelope *env; |
815 | size_t slen1; | 806 | size_t slen1; |
816 | size_t slen2; | 807 | size_t slen2; |
817 | 808 | ||
818 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 809 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
819 | "Transmitting watch request for `%s'\n", | 810 | "Transmitting watch request for `%s'\n", |
820 | handle->current->name); | 811 | handle->current->name); |
821 | slen1 = strlen (handle->current->subsystem) + 1; | 812 | slen1 = strlen(handle->current->subsystem) + 1; |
822 | slen2 = strlen (handle->current->name) + 1; | 813 | slen2 = strlen(handle->current->name) + 1; |
823 | env = GNUNET_MQ_msg_extra (hdr, | 814 | env = GNUNET_MQ_msg_extra(hdr, |
824 | slen1 + slen2, | 815 | slen1 + slen2, |
825 | GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); | 816 | GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); |
826 | GNUNET_assert (slen1 + slen2 == | 817 | GNUNET_assert(slen1 + slen2 == |
827 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], | 818 | GNUNET_STRINGS_buffer_fill((char *)&hdr[1], |
828 | slen1 + slen2, | 819 | slen1 + slen2, |
829 | 2, | 820 | 2, |
830 | handle->current->subsystem, | 821 | handle->current->subsystem, |
831 | handle->current->name)); | 822 | handle->current->name)); |
832 | GNUNET_MQ_notify_sent (env, | 823 | GNUNET_MQ_notify_sent(env, |
833 | &schedule_action, | 824 | &schedule_action, |
834 | handle); | 825 | handle); |
835 | GNUNET_MQ_send (handle->mq, | 826 | GNUNET_MQ_send(handle->mq, |
836 | env); | 827 | env); |
837 | GNUNET_assert (NULL == handle->current->cont); | 828 | GNUNET_assert(NULL == handle->current->cont); |
838 | free_action_item (handle->current); | 829 | free_action_item(handle->current); |
839 | handle->current = NULL; | 830 | handle->current = NULL; |
840 | schedule_action (handle); | 831 | schedule_action(handle); |
841 | } | 832 | } |
842 | 833 | ||
843 | 834 | ||
@@ -847,39 +838,39 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle) | |||
847 | * @param handle statistics handle | 838 | * @param handle statistics handle |
848 | */ | 839 | */ |
849 | static void | 840 | static void |
850 | transmit_set (struct GNUNET_STATISTICS_Handle *handle) | 841 | transmit_set(struct GNUNET_STATISTICS_Handle *handle) |
851 | { | 842 | { |
852 | struct GNUNET_STATISTICS_SetMessage *r; | 843 | struct GNUNET_STATISTICS_SetMessage *r; |
853 | struct GNUNET_MQ_Envelope *env; | 844 | struct GNUNET_MQ_Envelope *env; |
854 | size_t slen; | 845 | size_t slen; |
855 | size_t nlen; | 846 | size_t nlen; |
856 | 847 | ||
857 | slen = strlen (handle->current->subsystem) + 1; | 848 | slen = strlen(handle->current->subsystem) + 1; |
858 | nlen = strlen (handle->current->name) + 1; | 849 | nlen = strlen(handle->current->name) + 1; |
859 | env = GNUNET_MQ_msg_extra (r, | 850 | env = GNUNET_MQ_msg_extra(r, |
860 | slen + nlen, | 851 | slen + nlen, |
861 | GNUNET_MESSAGE_TYPE_STATISTICS_SET); | 852 | GNUNET_MESSAGE_TYPE_STATISTICS_SET); |
862 | r->flags = 0; | 853 | r->flags = 0; |
863 | r->value = GNUNET_htonll (handle->current->value); | 854 | r->value = GNUNET_htonll(handle->current->value); |
864 | if (handle->current->make_persistent) | 855 | if (handle->current->make_persistent) |
865 | r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_PERSISTENT); | 856 | r->flags |= htonl(GNUNET_STATISTICS_SETFLAG_PERSISTENT); |
866 | if (handle->current->type == ACTION_UPDATE) | 857 | if (handle->current->type == ACTION_UPDATE) |
867 | r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE); | 858 | r->flags |= htonl(GNUNET_STATISTICS_SETFLAG_RELATIVE); |
868 | GNUNET_assert (slen + nlen == | 859 | GNUNET_assert(slen + nlen == |
869 | GNUNET_STRINGS_buffer_fill ((char *) &r[1], | 860 | GNUNET_STRINGS_buffer_fill((char *)&r[1], |
870 | slen + nlen, | 861 | slen + nlen, |
871 | 2, | 862 | 2, |
872 | handle->current->subsystem, | 863 | handle->current->subsystem, |
873 | handle->current->name)); | 864 | handle->current->name)); |
874 | GNUNET_assert (NULL == handle->current->cont); | 865 | GNUNET_assert(NULL == handle->current->cont); |
875 | free_action_item (handle->current); | 866 | free_action_item(handle->current); |
876 | handle->current = NULL; | 867 | handle->current = NULL; |
877 | update_memory_statistics (handle); | 868 | update_memory_statistics(handle); |
878 | GNUNET_MQ_notify_sent (env, | 869 | GNUNET_MQ_notify_sent(env, |
879 | &schedule_action, | 870 | &schedule_action, |
880 | handle); | 871 | handle); |
881 | GNUNET_MQ_send (handle->mq, | 872 | GNUNET_MQ_send(handle->mq, |
882 | env); | 873 | env); |
883 | } | 874 | } |
884 | 875 | ||
885 | 876 | ||
@@ -891,19 +882,19 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle) | |||
891 | * @return handle to use | 882 | * @return handle to use |
892 | */ | 883 | */ |
893 | struct GNUNET_STATISTICS_Handle * | 884 | struct GNUNET_STATISTICS_Handle * |
894 | GNUNET_STATISTICS_create (const char *subsystem, | 885 | GNUNET_STATISTICS_create(const char *subsystem, |
895 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 886 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
896 | { | 887 | { |
897 | struct GNUNET_STATISTICS_Handle *h; | 888 | struct GNUNET_STATISTICS_Handle *h; |
898 | 889 | ||
899 | if (GNUNET_YES == | 890 | if (GNUNET_YES == |
900 | GNUNET_CONFIGURATION_get_value_yesno (cfg, | 891 | GNUNET_CONFIGURATION_get_value_yesno(cfg, |
901 | "statistics", | 892 | "statistics", |
902 | "DISABLE")) | 893 | "DISABLE")) |
903 | return NULL; | 894 | return NULL; |
904 | h = GNUNET_new (struct GNUNET_STATISTICS_Handle); | 895 | h = GNUNET_new(struct GNUNET_STATISTICS_Handle); |
905 | h->cfg = cfg; | 896 | h->cfg = cfg; |
906 | h->subsystem = GNUNET_strdup (subsystem); | 897 | h->subsystem = GNUNET_strdup(subsystem); |
907 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 898 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
908 | return h; | 899 | return h; |
909 | } | 900 | } |
@@ -918,82 +909,82 @@ GNUNET_STATISTICS_create (const char *subsystem, | |||
918 | * be completed | 909 | * be completed |
919 | */ | 910 | */ |
920 | void | 911 | void |
921 | GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | 912 | GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, |
922 | int sync_first) | 913 | int sync_first) |
923 | { | 914 | { |
924 | struct GNUNET_STATISTICS_GetHandle *pos; | 915 | struct GNUNET_STATISTICS_GetHandle *pos; |
925 | struct GNUNET_STATISTICS_GetHandle *next; | 916 | struct GNUNET_STATISTICS_GetHandle *next; |
926 | 917 | ||
927 | if (NULL == h) | 918 | if (NULL == h) |
928 | return; | 919 | return; |
929 | GNUNET_assert (GNUNET_NO == h->do_destroy); /* Don't call twice. */ | 920 | GNUNET_assert(GNUNET_NO == h->do_destroy); /* Don't call twice. */ |
930 | if ( (sync_first) && | 921 | if ((sync_first) && |
931 | (NULL != h->mq) && | 922 | (NULL != h->mq) && |
932 | (0 != GNUNET_MQ_get_length (h->mq)) ) | 923 | (0 != GNUNET_MQ_get_length(h->mq))) |
933 | { | ||
934 | if ( (NULL != h->current) && | ||
935 | (ACTION_GET == h->current->type) ) | ||
936 | h->current->aborted = GNUNET_YES; | ||
937 | next = h->action_head; | ||
938 | while (NULL != (pos = next)) | ||
939 | { | 924 | { |
940 | next = pos->next; | 925 | if ((NULL != h->current) && |
941 | if ( (ACTION_GET == pos->type) || | 926 | (ACTION_GET == h->current->type)) |
942 | (ACTION_WATCH == pos->type) ) | 927 | h->current->aborted = GNUNET_YES; |
943 | { | 928 | next = h->action_head; |
944 | GNUNET_CONTAINER_DLL_remove (h->action_head, | 929 | while (NULL != (pos = next)) |
945 | h->action_tail, | 930 | { |
946 | pos); | 931 | next = pos->next; |
947 | free_action_item (pos); | 932 | if ((ACTION_GET == pos->type) || |
948 | } | 933 | (ACTION_WATCH == pos->type)) |
949 | } | 934 | { |
950 | h->do_destroy = GNUNET_YES; | 935 | GNUNET_CONTAINER_DLL_remove(h->action_head, |
951 | schedule_action (h); | 936 | h->action_tail, |
952 | GNUNET_assert (NULL == h->destroy_task); | 937 | pos); |
953 | h->destroy_task | 938 | free_action_item(pos); |
954 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (h->backoff, | 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, | ||
955 | 5), | 946 | 5), |
956 | &do_destroy, | 947 | &do_destroy, |
957 | h); | 948 | h); |
958 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 949 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
959 | "Deferring destruction\n"); | 950 | "Deferring destruction\n"); |
960 | return; /* do not finish destruction just yet */ | 951 | return; /* do not finish destruction just yet */ |
961 | } | 952 | } |
962 | /* do clean up all */ | 953 | /* do clean up all */ |
963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 954 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
964 | "Cleaning all up\n"); | 955 | "Cleaning all up\n"); |
965 | while (NULL != (pos = h->action_head)) | 956 | while (NULL != (pos = h->action_head)) |
966 | { | 957 | { |
967 | GNUNET_CONTAINER_DLL_remove (h->action_head, | 958 | GNUNET_CONTAINER_DLL_remove(h->action_head, |
968 | h->action_tail, | 959 | h->action_tail, |
969 | pos); | 960 | pos); |
970 | free_action_item (pos); | 961 | free_action_item(pos); |
971 | } | 962 | } |
972 | do_disconnect (h); | 963 | do_disconnect(h); |
973 | if (NULL != h->backoff_task) | 964 | if (NULL != h->backoff_task) |
974 | { | 965 | { |
975 | GNUNET_SCHEDULER_cancel (h->backoff_task); | 966 | GNUNET_SCHEDULER_cancel(h->backoff_task); |
976 | h->backoff_task = NULL; | 967 | h->backoff_task = NULL; |
977 | } | 968 | } |
978 | if (NULL != h->destroy_task) | 969 | if (NULL != h->destroy_task) |
979 | { | 970 | { |
980 | GNUNET_break (0); | 971 | GNUNET_break(0); |
981 | GNUNET_SCHEDULER_cancel (h->destroy_task); | 972 | GNUNET_SCHEDULER_cancel(h->destroy_task); |
982 | h->destroy_task = NULL; | 973 | h->destroy_task = NULL; |
983 | } | 974 | } |
984 | for (unsigned int i = 0; i < h->watches_size; i++) | 975 | for (unsigned int i = 0; i < h->watches_size; i++) |
985 | { | 976 | { |
986 | if (NULL == h->watches[i]) | 977 | if (NULL == h->watches[i]) |
987 | continue; | 978 | continue; |
988 | GNUNET_free (h->watches[i]->subsystem); | 979 | GNUNET_free(h->watches[i]->subsystem); |
989 | GNUNET_free (h->watches[i]->name); | 980 | GNUNET_free(h->watches[i]->name); |
990 | GNUNET_free (h->watches[i]); | 981 | GNUNET_free(h->watches[i]); |
991 | } | 982 | } |
992 | GNUNET_array_grow (h->watches, | 983 | GNUNET_array_grow(h->watches, |
993 | h->watches_size, | 984 | h->watches_size, |
994 | 0); | 985 | 0); |
995 | GNUNET_free (h->subsystem); | 986 | GNUNET_free(h->subsystem); |
996 | GNUNET_free (h); | 987 | GNUNET_free(h); |
997 | } | 988 | } |
998 | 989 | ||
999 | 990 | ||
@@ -1003,63 +994,66 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, | |||
1003 | * @param cls statistics handle | 994 | * @param cls statistics handle |
1004 | */ | 995 | */ |
1005 | static void | 996 | static void |
1006 | schedule_action (void *cls) | 997 | schedule_action(void *cls) |
1007 | { | 998 | { |
1008 | struct GNUNET_STATISTICS_Handle *h = cls; | 999 | struct GNUNET_STATISTICS_Handle *h = cls; |
1009 | 1000 | ||
1010 | if (NULL != h->backoff_task) | 1001 | if (NULL != h->backoff_task) |
1011 | return; /* action already pending */ | 1002 | return; /* action already pending */ |
1012 | if (GNUNET_YES != try_connect (h)) | 1003 | if (GNUNET_YES != try_connect(h)) |
1013 | { | ||
1014 | reconnect_later (h); | ||
1015 | return; | ||
1016 | } | ||
1017 | if (0 < GNUNET_MQ_get_length (h->mq)) | ||
1018 | return; /* Wait for queue to be reduced more */ | ||
1019 | /* schedule next action */ | ||
1020 | while (NULL == h->current) | ||
1021 | { | ||
1022 | h->current = h->action_head; | ||
1023 | if (NULL == h->current) | ||
1024 | { | 1004 | { |
1025 | struct GNUNET_MessageHeader *hdr; | 1005 | reconnect_later(h); |
1026 | struct GNUNET_MQ_Envelope *env; | ||
1027 | |||
1028 | if (GNUNET_YES != h->do_destroy) | ||
1029 | return; /* nothing to do */ | ||
1030 | /* let service know that we're done */ | ||
1031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1032 | "Notifying service that we are done\n"); | ||
1033 | h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */ | ||
1034 | env = GNUNET_MQ_msg (hdr, | ||
1035 | GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT); | ||
1036 | GNUNET_MQ_notify_sent (env, | ||
1037 | &schedule_action, | ||
1038 | h); | ||
1039 | GNUNET_MQ_send (h->mq, | ||
1040 | env); | ||
1041 | return; | 1006 | return; |
1042 | } | 1007 | } |
1043 | GNUNET_CONTAINER_DLL_remove (h->action_head, | 1008 | if (0 < GNUNET_MQ_get_length(h->mq)) |
1044 | h->action_tail, | 1009 | return; /* Wait for queue to be reduced more */ |
1045 | h->current); | 1010 | /* schedule next action */ |
1046 | switch (h->current->type) | 1011 | while (NULL == h->current) |
1047 | { | 1012 | { |
1048 | case ACTION_GET: | 1013 | h->current = h->action_head; |
1049 | transmit_get (h); | 1014 | if (NULL == h->current) |
1050 | break; | 1015 | { |
1051 | case ACTION_SET: | 1016 | struct GNUNET_MessageHeader *hdr; |
1052 | case ACTION_UPDATE: | 1017 | struct GNUNET_MQ_Envelope *env; |
1053 | transmit_set (h); | 1018 | |
1054 | break; | 1019 | if (GNUNET_YES != h->do_destroy) |
1055 | case ACTION_WATCH: | 1020 | return; /* nothing to do */ |
1056 | transmit_watch (h); | 1021 | /* let service know that we're done */ |
1057 | break; | 1022 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1058 | default: | 1023 | "Notifying service that we are done\n"); |
1059 | GNUNET_assert (0); | 1024 | h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */ |
1060 | break; | 1025 | env = GNUNET_MQ_msg(hdr, |
1026 | GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT); | ||
1027 | GNUNET_MQ_notify_sent(env, | ||
1028 | &schedule_action, | ||
1029 | h); | ||
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 | } | ||
1061 | } | 1056 | } |
1062 | } | ||
1063 | } | 1057 | } |
1064 | 1058 | ||
1065 | 1059 | ||
@@ -1076,12 +1070,12 @@ schedule_action (void *cls) | |||
1076 | * @return NULL on error | 1070 | * @return NULL on error |
1077 | */ | 1071 | */ |
1078 | struct GNUNET_STATISTICS_GetHandle * | 1072 | struct GNUNET_STATISTICS_GetHandle * |
1079 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | 1073 | GNUNET_STATISTICS_get(struct GNUNET_STATISTICS_Handle *handle, |
1080 | const char *subsystem, | 1074 | const char *subsystem, |
1081 | const char *name, | 1075 | const char *name, |
1082 | GNUNET_STATISTICS_Callback cont, | 1076 | GNUNET_STATISTICS_Callback cont, |
1083 | GNUNET_STATISTICS_Iterator proc, | 1077 | GNUNET_STATISTICS_Iterator proc, |
1084 | void *cls) | 1078 | void *cls) |
1085 | { | 1079 | { |
1086 | size_t slen1; | 1080 | size_t slen1; |
1087 | size_t slen2; | 1081 | size_t slen2; |
@@ -1089,29 +1083,29 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | |||
1089 | 1083 | ||
1090 | if (NULL == handle) | 1084 | if (NULL == handle) |
1091 | return NULL; | 1085 | return NULL; |
1092 | GNUNET_assert (NULL != proc); | 1086 | GNUNET_assert(NULL != proc); |
1093 | GNUNET_assert (GNUNET_NO == handle->do_destroy); | 1087 | GNUNET_assert(GNUNET_NO == handle->do_destroy); |
1094 | if (NULL == subsystem) | 1088 | if (NULL == subsystem) |
1095 | subsystem = ""; | 1089 | subsystem = ""; |
1096 | if (NULL == name) | 1090 | if (NULL == name) |
1097 | name = ""; | 1091 | name = ""; |
1098 | slen1 = strlen (subsystem) + 1; | 1092 | slen1 = strlen(subsystem) + 1; |
1099 | slen2 = strlen (name) + 1; | 1093 | slen2 = strlen(name) + 1; |
1100 | GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) < | 1094 | GNUNET_assert(slen1 + slen2 + sizeof(struct GNUNET_MessageHeader) < |
1101 | GNUNET_MAX_MESSAGE_SIZE); | 1095 | GNUNET_MAX_MESSAGE_SIZE); |
1102 | ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle); | 1096 | ai = GNUNET_new(struct GNUNET_STATISTICS_GetHandle); |
1103 | ai->sh = handle; | 1097 | ai->sh = handle; |
1104 | ai->subsystem = GNUNET_strdup (subsystem); | 1098 | ai->subsystem = GNUNET_strdup(subsystem); |
1105 | ai->name = GNUNET_strdup (name); | 1099 | ai->name = GNUNET_strdup(name); |
1106 | ai->cont = cont; | 1100 | ai->cont = cont; |
1107 | ai->proc = proc; | 1101 | ai->proc = proc; |
1108 | ai->cls = cls; | 1102 | ai->cls = cls; |
1109 | ai->type = ACTION_GET; | 1103 | ai->type = ACTION_GET; |
1110 | ai->msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); | 1104 | ai->msize = slen1 + slen2 + sizeof(struct GNUNET_MessageHeader); |
1111 | GNUNET_CONTAINER_DLL_insert_tail (handle->action_head, | 1105 | GNUNET_CONTAINER_DLL_insert_tail(handle->action_head, |
1112 | handle->action_tail, | 1106 | handle->action_tail, |
1113 | ai); | 1107 | ai); |
1114 | schedule_action (handle); | 1108 | schedule_action(handle); |
1115 | return ai; | 1109 | return ai; |
1116 | } | 1110 | } |
1117 | 1111 | ||
@@ -1123,22 +1117,22 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | |||
1123 | * @param gh handle of the request to cancel | 1117 | * @param gh handle of the request to cancel |
1124 | */ | 1118 | */ |
1125 | void | 1119 | void |
1126 | GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) | 1120 | GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh) |
1127 | { | 1121 | { |
1128 | if (NULL == gh) | 1122 | if (NULL == gh) |
1129 | return; | 1123 | return; |
1130 | gh->cont = NULL; | 1124 | gh->cont = NULL; |
1131 | if (gh->sh->current == gh) | 1125 | if (gh->sh->current == gh) |
1132 | { | 1126 | { |
1133 | gh->aborted = GNUNET_YES; | 1127 | gh->aborted = GNUNET_YES; |
1134 | return; | 1128 | return; |
1135 | } | 1129 | } |
1136 | GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, | 1130 | GNUNET_CONTAINER_DLL_remove(gh->sh->action_head, |
1137 | gh->sh->action_tail, | 1131 | gh->sh->action_tail, |
1138 | gh); | 1132 | gh); |
1139 | GNUNET_free (gh->name); | 1133 | GNUNET_free(gh->name); |
1140 | GNUNET_free (gh->subsystem); | 1134 | GNUNET_free(gh->subsystem); |
1141 | GNUNET_free (gh); | 1135 | GNUNET_free(gh); |
1142 | } | 1136 | } |
1143 | 1137 | ||
1144 | 1138 | ||
@@ -1153,26 +1147,26 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) | |||
1153 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1147 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1154 | */ | 1148 | */ |
1155 | int | 1149 | int |
1156 | GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, | 1150 | GNUNET_STATISTICS_watch(struct GNUNET_STATISTICS_Handle *handle, |
1157 | const char *subsystem, | 1151 | const char *subsystem, |
1158 | const char *name, | 1152 | const char *name, |
1159 | GNUNET_STATISTICS_Iterator proc, | 1153 | GNUNET_STATISTICS_Iterator proc, |
1160 | void *proc_cls) | 1154 | void *proc_cls) |
1161 | { | 1155 | { |
1162 | struct GNUNET_STATISTICS_WatchEntry *w; | 1156 | struct GNUNET_STATISTICS_WatchEntry *w; |
1163 | 1157 | ||
1164 | if (NULL == handle) | 1158 | if (NULL == handle) |
1165 | return GNUNET_SYSERR; | 1159 | return GNUNET_SYSERR; |
1166 | w = GNUNET_new (struct GNUNET_STATISTICS_WatchEntry); | 1160 | w = GNUNET_new(struct GNUNET_STATISTICS_WatchEntry); |
1167 | w->subsystem = GNUNET_strdup (subsystem); | 1161 | w->subsystem = GNUNET_strdup(subsystem); |
1168 | w->name = GNUNET_strdup (name); | 1162 | w->name = GNUNET_strdup(name); |
1169 | w->proc = proc; | 1163 | w->proc = proc; |
1170 | w->proc_cls = proc_cls; | 1164 | w->proc_cls = proc_cls; |
1171 | GNUNET_array_append (handle->watches, | 1165 | GNUNET_array_append(handle->watches, |
1172 | handle->watches_size, | 1166 | handle->watches_size, |
1173 | w); | 1167 | w); |
1174 | schedule_watch_request (handle, | 1168 | schedule_watch_request(handle, |
1175 | w); | 1169 | w); |
1176 | return GNUNET_OK; | 1170 | return GNUNET_OK; |
1177 | } | 1171 | } |
1178 | 1172 | ||
@@ -1188,35 +1182,35 @@ GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, | |||
1188 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (no such watch) | 1182 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (no such watch) |
1189 | */ | 1183 | */ |
1190 | int | 1184 | int |
1191 | GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle, | 1185 | GNUNET_STATISTICS_watch_cancel(struct GNUNET_STATISTICS_Handle *handle, |
1192 | const char *subsystem, | 1186 | const char *subsystem, |
1193 | const char *name, | 1187 | const char *name, |
1194 | GNUNET_STATISTICS_Iterator proc, | 1188 | GNUNET_STATISTICS_Iterator proc, |
1195 | void *proc_cls) | 1189 | void *proc_cls) |
1196 | { | 1190 | { |
1197 | struct GNUNET_STATISTICS_WatchEntry *w; | 1191 | struct GNUNET_STATISTICS_WatchEntry *w; |
1198 | 1192 | ||
1199 | if (NULL == handle) | 1193 | if (NULL == handle) |
1200 | return GNUNET_SYSERR; | 1194 | return GNUNET_SYSERR; |
1201 | for (unsigned int i=0;i<handle->watches_size;i++) | 1195 | 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)) ) | ||
1212 | { | 1196 | { |
1213 | GNUNET_free (w->name); | 1197 | w = handle->watches[i]; |
1214 | GNUNET_free (w->subsystem); | 1198 | if (NULL == w) |
1215 | GNUNET_free (w); | 1199 | continue; |
1216 | handle->watches[i] = NULL; | 1200 | if ((w->proc == proc) && |
1217 | return GNUNET_OK; | 1201 | (w->proc_cls == proc_cls) && |
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 | } | ||
1218 | } | 1213 | } |
1219 | } | ||
1220 | return GNUNET_SYSERR; | 1214 | return GNUNET_SYSERR; |
1221 | } | 1215 | } |
1222 | 1216 | ||
@@ -1231,11 +1225,11 @@ GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle, | |||
1231 | * @param type type of the action (#ACTION_SET or #ACTION_UPDATE) | 1225 | * @param type type of the action (#ACTION_SET or #ACTION_UPDATE) |
1232 | */ | 1226 | */ |
1233 | static void | 1227 | static void |
1234 | add_setter_action (struct GNUNET_STATISTICS_Handle *h, | 1228 | add_setter_action(struct GNUNET_STATISTICS_Handle *h, |
1235 | const char *name, | 1229 | const char *name, |
1236 | int make_persistent, | 1230 | int make_persistent, |
1237 | uint64_t value, | 1231 | uint64_t value, |
1238 | enum ActionType type) | 1232 | enum ActionType type) |
1239 | { | 1233 | { |
1240 | struct GNUNET_STATISTICS_GetHandle *ai; | 1234 | struct GNUNET_STATISTICS_GetHandle *ai; |
1241 | size_t slen; | 1235 | size_t slen; |
@@ -1243,83 +1237,83 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, | |||
1243 | size_t nsize; | 1237 | size_t nsize; |
1244 | int64_t delta; | 1238 | int64_t delta; |
1245 | 1239 | ||
1246 | slen = strlen (h->subsystem) + 1; | 1240 | slen = strlen(h->subsystem) + 1; |
1247 | nlen = strlen (name) + 1; | 1241 | nlen = strlen(name) + 1; |
1248 | nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen; | 1242 | nsize = sizeof(struct GNUNET_STATISTICS_SetMessage) + slen + nlen; |
1249 | if (nsize >= GNUNET_MAX_MESSAGE_SIZE) | 1243 | if (nsize >= GNUNET_MAX_MESSAGE_SIZE) |
1250 | { | ||
1251 | GNUNET_break (0); | ||
1252 | return; | ||
1253 | } | ||
1254 | for (ai = h->action_head; NULL != ai; ai = ai->next) | ||
1255 | { | ||
1256 | if (! ( (0 == strcmp (ai->subsystem, | ||
1257 | h->subsystem)) && | ||
1258 | (0 == strcmp (ai->name, | ||
1259 | name)) && | ||
1260 | ( (ACTION_UPDATE == ai->type) || | ||
1261 | (ACTION_SET == ai->type) ) ) ) | ||
1262 | continue; | ||
1263 | if (ACTION_SET == ai->type) | ||
1264 | { | 1244 | { |
1265 | if (ACTION_UPDATE == type) | 1245 | GNUNET_break(0); |
1266 | { | 1246 | return; |
1267 | delta = (int64_t) value; | ||
1268 | if (delta > 0) | ||
1269 | { | ||
1270 | /* update old set by new delta */ | ||
1271 | ai->value += delta; | ||
1272 | } | ||
1273 | else | ||
1274 | { | ||
1275 | /* update old set by new delta, but never go negative */ | ||
1276 | if (ai->value < -delta) | ||
1277 | ai->value = 0; | ||
1278 | else | ||
1279 | ai->value += delta; | ||
1280 | } | ||
1281 | } | ||
1282 | else | ||
1283 | { | ||
1284 | /* new set overrides old set */ | ||
1285 | ai->value = value; | ||
1286 | } | ||
1287 | } | 1247 | } |
1288 | else | 1248 | for (ai = h->action_head; NULL != ai; ai = ai->next) |
1289 | { | 1249 | { |
1290 | if (ACTION_UPDATE == type) | 1250 | if (!((0 == strcmp(ai->subsystem, |
1291 | { | 1251 | h->subsystem)) && |
1292 | /* make delta cummulative */ | 1252 | (0 == strcmp(ai->name, |
1293 | delta = (int64_t) value; | 1253 | name)) && |
1294 | ai->value += delta; | 1254 | ((ACTION_UPDATE == ai->type) || |
1295 | } | 1255 | (ACTION_SET == ai->type)))) |
1256 | continue; | ||
1257 | if (ACTION_SET == ai->type) | ||
1258 | { | ||
1259 | if (ACTION_UPDATE == type) | ||
1260 | { | ||
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 | } | ||
1296 | else | 1282 | else |
1297 | { | 1283 | { |
1298 | /* drop old 'update', use new 'set' instead */ | 1284 | if (ACTION_UPDATE == type) |
1299 | ai->value = value; | 1285 | { |
1300 | ai->type = type; | 1286 | /* make delta cummulative */ |
1301 | } | 1287 | delta = (int64_t)value; |
1288 | ai->value += delta; | ||
1289 | } | ||
1290 | else | ||
1291 | { | ||
1292 | /* drop old 'update', use new 'set' instead */ | ||
1293 | ai->value = value; | ||
1294 | ai->type = type; | ||
1295 | } | ||
1296 | } | ||
1297 | ai->timeout | ||
1298 | = GNUNET_TIME_relative_to_absolute(SET_TRANSMIT_TIMEOUT); | ||
1299 | ai->make_persistent | ||
1300 | = make_persistent; | ||
1301 | return; | ||
1302 | } | 1302 | } |
1303 | ai->timeout | ||
1304 | = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT); | ||
1305 | ai->make_persistent | ||
1306 | = make_persistent; | ||
1307 | return; | ||
1308 | } | ||
1309 | /* no existing entry matches, create a fresh one */ | 1303 | /* no existing entry matches, create a fresh one */ |
1310 | ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle); | 1304 | ai = GNUNET_new(struct GNUNET_STATISTICS_GetHandle); |
1311 | ai->sh = h; | 1305 | ai->sh = h; |
1312 | ai->subsystem = GNUNET_strdup (h->subsystem); | 1306 | ai->subsystem = GNUNET_strdup(h->subsystem); |
1313 | ai->name = GNUNET_strdup (name); | 1307 | ai->name = GNUNET_strdup(name); |
1314 | ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT); | 1308 | ai->timeout = GNUNET_TIME_relative_to_absolute(SET_TRANSMIT_TIMEOUT); |
1315 | ai->make_persistent = make_persistent; | 1309 | ai->make_persistent = make_persistent; |
1316 | ai->msize = nsize; | 1310 | ai->msize = nsize; |
1317 | ai->value = value; | 1311 | ai->value = value; |
1318 | ai->type = type; | 1312 | ai->type = type; |
1319 | GNUNET_CONTAINER_DLL_insert_tail (h->action_head, | 1313 | GNUNET_CONTAINER_DLL_insert_tail(h->action_head, |
1320 | h->action_tail, | 1314 | h->action_tail, |
1321 | ai); | 1315 | ai); |
1322 | schedule_action (h); | 1316 | schedule_action(h); |
1323 | } | 1317 | } |
1324 | 1318 | ||
1325 | 1319 | ||
@@ -1333,19 +1327,19 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, | |||
1333 | * @param make_persistent should the value be kept across restarts? | 1327 | * @param make_persistent should the value be kept across restarts? |
1334 | */ | 1328 | */ |
1335 | void | 1329 | void |
1336 | GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, | 1330 | GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, |
1337 | const char *name, | 1331 | const char *name, |
1338 | uint64_t value, | 1332 | uint64_t value, |
1339 | int make_persistent) | 1333 | int make_persistent) |
1340 | { | 1334 | { |
1341 | if (NULL == handle) | 1335 | if (NULL == handle) |
1342 | return; | 1336 | return; |
1343 | GNUNET_assert (GNUNET_NO == handle->do_destroy); | 1337 | GNUNET_assert(GNUNET_NO == handle->do_destroy); |
1344 | add_setter_action (handle, | 1338 | add_setter_action(handle, |
1345 | name, | 1339 | name, |
1346 | make_persistent, | 1340 | make_persistent, |
1347 | value, | 1341 | value, |
1348 | ACTION_SET); | 1342 | ACTION_SET); |
1349 | } | 1343 | } |
1350 | 1344 | ||
1351 | 1345 | ||
@@ -1359,21 +1353,21 @@ GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, | |||
1359 | * @param make_persistent should the value be kept across restarts? | 1353 | * @param make_persistent should the value be kept across restarts? |
1360 | */ | 1354 | */ |
1361 | void | 1355 | void |
1362 | GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, | 1356 | GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, |
1363 | const char *name, | 1357 | const char *name, |
1364 | int64_t delta, | 1358 | int64_t delta, |
1365 | int make_persistent) | 1359 | int make_persistent) |
1366 | { | 1360 | { |
1367 | if (NULL == handle) | 1361 | if (NULL == handle) |
1368 | return; | 1362 | return; |
1369 | if (0 == delta) | 1363 | if (0 == delta) |
1370 | return; | 1364 | return; |
1371 | GNUNET_assert (GNUNET_NO == handle->do_destroy); | 1365 | GNUNET_assert(GNUNET_NO == handle->do_destroy); |
1372 | add_setter_action (handle, | 1366 | add_setter_action(handle, |
1373 | name, | 1367 | name, |
1374 | make_persistent, | 1368 | make_persistent, |
1375 | (uint64_t) delta, | 1369 | (uint64_t)delta, |
1376 | ACTION_UPDATE); | 1370 | ACTION_UPDATE); |
1377 | } | 1371 | } |
1378 | 1372 | ||
1379 | 1373 | ||