diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-10 13:34:24 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-10 13:34:24 +0000 |
commit | d9482088d0e83c9a8784a1042012fa71c0b7a65e (patch) | |
tree | a71bbf30642950e5f8c130ac4b27adde824f76d1 /src | |
parent | b71f3dfcdc72ab1d1e707e90a594a27666b2333a (diff) | |
download | gnunet-d9482088d0e83c9a8784a1042012fa71c0b7a65e.tar.gz gnunet-d9482088d0e83c9a8784a1042012fa71c0b7a65e.zip |
use LOG macro in statistics_api.c
Diffstat (limited to 'src')
-rw-r--r-- | src/statistics/statistics_api.c | 716 |
1 files changed, 360 insertions, 356 deletions
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 10659f11a..5d419f637 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -40,6 +40,7 @@ | |||
40 | */ | 40 | */ |
41 | #define SET_TRANSMIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) | 41 | #define SET_TRANSMIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) |
42 | 42 | ||
43 | #define LOG(kind,...) GNUNET_log_from (kind, "statistics-api",__VA_ARGS__) | ||
43 | 44 | ||
44 | /** | 45 | /** |
45 | * Types of actions. | 46 | * Types of actions. |
@@ -242,24 +243,22 @@ struct GNUNET_STATISTICS_Handle | |||
242 | /** | 243 | /** |
243 | * Schedule the next action to be performed. | 244 | * Schedule the next action to be performed. |
244 | */ | 245 | */ |
245 | static void | 246 | static void schedule_action (struct GNUNET_STATISTICS_Handle *h); |
246 | schedule_action (struct GNUNET_STATISTICS_Handle *h); | ||
247 | 247 | ||
248 | /** | 248 | /** |
249 | * Try to (re)connect to the statistics service. | 249 | * Try to (re)connect to the statistics service. |
250 | * | 250 | * |
251 | * @return GNUNET_YES on success, GNUNET_NO on failure. | 251 | * @return GNUNET_YES on success, GNUNET_NO on failure. |
252 | */ | 252 | */ |
253 | static int | 253 | static int try_connect (struct GNUNET_STATISTICS_Handle *ret); |
254 | try_connect (struct GNUNET_STATISTICS_Handle *ret); | ||
255 | 254 | ||
256 | 255 | ||
257 | static void | 256 | static void |
258 | insert_ai (struct GNUNET_STATISTICS_Handle *h, | 257 | insert_ai (struct GNUNET_STATISTICS_Handle *h, |
259 | struct GNUNET_STATISTICS_GetHandle *ai) | 258 | struct GNUNET_STATISTICS_GetHandle *ai) |
260 | { | 259 | { |
261 | GNUNET_CONTAINER_DLL_insert_after (h->action_head, h->action_tail, | 260 | GNUNET_CONTAINER_DLL_insert_after (h->action_head, h->action_tail, |
262 | h->action_tail, ai); | 261 | h->action_tail, ai); |
263 | if (h->action_head == ai) | 262 | if (h->action_head == ai) |
264 | schedule_action (h); | 263 | schedule_action (h); |
265 | } | 264 | } |
@@ -267,7 +266,7 @@ insert_ai (struct GNUNET_STATISTICS_Handle *h, | |||
267 | 266 | ||
268 | static void | 267 | static void |
269 | schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, | 268 | schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, |
270 | struct GNUNET_STATISTICS_WatchEntry *watch) | 269 | struct GNUNET_STATISTICS_WatchEntry *watch) |
271 | { | 270 | { |
272 | 271 | ||
273 | struct GNUNET_STATISTICS_GetHandle *ai; | 272 | struct GNUNET_STATISTICS_GetHandle *ai; |
@@ -277,18 +276,18 @@ schedule_watch_request (struct GNUNET_STATISTICS_Handle *h, | |||
277 | 276 | ||
278 | GNUNET_assert (h != NULL); | 277 | GNUNET_assert (h != NULL); |
279 | if (GNUNET_YES != try_connect (h)) | 278 | if (GNUNET_YES != try_connect (h)) |
280 | { | 279 | { |
281 | schedule_action (h); | 280 | schedule_action (h); |
282 | return; | 281 | return; |
283 | } | 282 | } |
284 | slen = strlen (watch->subsystem) + 1; | 283 | slen = strlen (watch->subsystem) + 1; |
285 | nlen = strlen (watch->name) + 1; | 284 | nlen = strlen (watch->name) + 1; |
286 | nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen; | 285 | nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen; |
287 | if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 286 | if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
288 | { | 287 | { |
289 | GNUNET_break (0); | 288 | GNUNET_break (0); |
290 | return; | 289 | return; |
291 | } | 290 | } |
292 | ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); | 291 | ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); |
293 | ai->sh = h; | 292 | ai->sh = h; |
294 | ai->subsystem = GNUNET_strdup (watch->subsystem); | 293 | ai->subsystem = GNUNET_strdup (watch->subsystem); |
@@ -316,14 +315,14 @@ try_connect (struct GNUNET_STATISTICS_Handle *ret) | |||
316 | return GNUNET_YES; | 315 | return GNUNET_YES; |
317 | ret->client = GNUNET_CLIENT_connect ("statistics", ret->cfg); | 316 | ret->client = GNUNET_CLIENT_connect ("statistics", ret->cfg); |
318 | if (ret->client != NULL) | 317 | if (ret->client != NULL) |
319 | { | 318 | { |
320 | for (i = 0; i < ret->watches_size; i++) | 319 | for (i = 0; i < ret->watches_size; i++) |
321 | schedule_watch_request (ret, ret->watches[i]); | 320 | schedule_watch_request (ret, ret->watches[i]); |
322 | return GNUNET_YES; | 321 | return GNUNET_YES; |
323 | } | 322 | } |
324 | #if DEBUG_STATISTICS | 323 | #if DEBUG_STATISTICS |
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 324 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
326 | _("Failed to connect to statistics service!\n")); | 325 | _("Failed to connect to statistics service!\n")); |
327 | #endif | 326 | #endif |
328 | return GNUNET_NO; | 327 | return GNUNET_NO; |
329 | } | 328 | } |
@@ -352,11 +351,11 @@ finish (struct GNUNET_STATISTICS_Handle *h, int code) | |||
352 | h->current = NULL; | 351 | h->current = NULL; |
353 | schedule_action (h); | 352 | schedule_action (h); |
354 | if (pos != NULL) | 353 | if (pos != NULL) |
355 | { | 354 | { |
356 | if (pos->cont != NULL) | 355 | if (pos->cont != NULL) |
357 | pos->cont (pos->cls, code); | 356 | pos->cont (pos->cls, code); |
358 | free_action_item (pos); | 357 | free_action_item (pos); |
359 | } | 358 | } |
360 | } | 359 | } |
361 | 360 | ||
362 | 361 | ||
@@ -367,7 +366,7 @@ finish (struct GNUNET_STATISTICS_Handle *h, int code) | |||
367 | */ | 366 | */ |
368 | static int | 367 | static int |
369 | process_message (struct GNUNET_STATISTICS_Handle *h, | 368 | process_message (struct GNUNET_STATISTICS_Handle *h, |
370 | const struct GNUNET_MessageHeader *msg) | 369 | const struct GNUNET_MessageHeader *msg) |
371 | { | 370 | { |
372 | char *service; | 371 | char *service; |
373 | char *name; | 372 | char *name; |
@@ -375,47 +374,47 @@ process_message (struct GNUNET_STATISTICS_Handle *h, | |||
375 | uint16_t size; | 374 | uint16_t size; |
376 | 375 | ||
377 | if (h->current->aborted) | 376 | if (h->current->aborted) |
378 | { | 377 | { |
379 | #if DEBUG_STATISTICS | 378 | #if DEBUG_STATISTICS |
380 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 379 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
381 | "Iteration was aborted, ignoring VALUE\n"); | 380 | "Iteration was aborted, ignoring VALUE\n"); |
382 | #endif | 381 | #endif |
383 | return GNUNET_OK; /* don't bother */ | 382 | return GNUNET_OK; /* don't bother */ |
384 | } | 383 | } |
385 | size = ntohs (msg->size); | 384 | size = ntohs (msg->size); |
386 | if (size < sizeof (struct GNUNET_STATISTICS_ReplyMessage)) | 385 | if (size < sizeof (struct GNUNET_STATISTICS_ReplyMessage)) |
387 | { | 386 | { |
388 | GNUNET_break (0); | 387 | GNUNET_break (0); |
389 | return GNUNET_SYSERR; | 388 | return GNUNET_SYSERR; |
390 | } | 389 | } |
391 | smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg; | 390 | smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg; |
392 | size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); | 391 | size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); |
393 | if (size != | 392 | if (size != |
394 | GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], size, 2, | 393 | GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], size, 2, |
395 | &service, &name)) | 394 | &service, &name)) |
396 | { | 395 | { |
397 | GNUNET_break (0); | 396 | GNUNET_break (0); |
398 | return GNUNET_SYSERR; | 397 | return GNUNET_SYSERR; |
399 | } | 398 | } |
400 | #if DEBUG_STATISTICS | 399 | #if DEBUG_STATISTICS |
401 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 400 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
402 | "Received valid statistic on `%s:%s': %llu\n", service, name, | 401 | "Received valid statistic on `%s:%s': %llu\n", service, name, |
403 | GNUNET_ntohll (smsg->value)); | 402 | GNUNET_ntohll (smsg->value)); |
404 | #endif | 403 | #endif |
405 | if (GNUNET_OK != | 404 | if (GNUNET_OK != |
406 | h->current->proc (h->current->cls, service, name, | 405 | h->current->proc (h->current->cls, service, name, |
407 | GNUNET_ntohll (smsg->value), | 406 | GNUNET_ntohll (smsg->value), |
408 | 0 != | 407 | 0 != |
409 | (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) | 408 | (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) |
410 | { | 409 | { |
411 | #if DEBUG_STATISTICS | 410 | #if DEBUG_STATISTICS |
412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 411 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
413 | "Processing of remaining statistics aborted by client.\n"); | 412 | "Processing of remaining statistics aborted by client.\n"); |
414 | #endif | 413 | #endif |
415 | h->current->aborted = GNUNET_YES; | 414 | h->current->aborted = GNUNET_YES; |
416 | } | 415 | } |
417 | #if DEBUG_STATISTICS | 416 | #if DEBUG_STATISTICS |
418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "VALUE processed successfully\n"); | 417 | LOG (GNUNET_ERROR_TYPE_DEBUG, "VALUE processed successfully\n"); |
419 | #endif | 418 | #endif |
420 | return GNUNET_OK; | 419 | return GNUNET_OK; |
421 | } | 420 | } |
@@ -423,29 +422,30 @@ process_message (struct GNUNET_STATISTICS_Handle *h, | |||
423 | 422 | ||
424 | static int | 423 | static int |
425 | process_watch_value (struct GNUNET_STATISTICS_Handle *h, | 424 | process_watch_value (struct GNUNET_STATISTICS_Handle *h, |
426 | const struct GNUNET_MessageHeader *msg) | 425 | const struct GNUNET_MessageHeader *msg) |
427 | { | 426 | { |
428 | const struct GNUNET_STATISTICS_WatchValueMessage *wvm; | 427 | const struct GNUNET_STATISTICS_WatchValueMessage *wvm; |
429 | struct GNUNET_STATISTICS_WatchEntry *w; | 428 | struct GNUNET_STATISTICS_WatchEntry *w; |
430 | uint32_t wid; | 429 | uint32_t wid; |
431 | 430 | ||
432 | if (sizeof (struct GNUNET_STATISTICS_WatchValueMessage) != ntohs (msg->size)) | 431 | if (sizeof (struct GNUNET_STATISTICS_WatchValueMessage) != |
433 | { | 432 | ntohs (msg->size)) |
434 | GNUNET_break (0); | 433 | { |
435 | return GNUNET_SYSERR; | 434 | GNUNET_break (0); |
436 | } | 435 | return GNUNET_SYSERR; |
436 | } | ||
437 | wvm = (const struct GNUNET_STATISTICS_WatchValueMessage *) msg; | 437 | wvm = (const struct GNUNET_STATISTICS_WatchValueMessage *) msg; |
438 | GNUNET_break (0 == ntohl (wvm->reserved)); | 438 | GNUNET_break (0 == ntohl (wvm->reserved)); |
439 | wid = ntohl (wvm->wid); | 439 | wid = ntohl (wvm->wid); |
440 | if (wid >= h->watches_size) | 440 | if (wid >= h->watches_size) |
441 | { | 441 | { |
442 | GNUNET_break (0); | 442 | GNUNET_break (0); |
443 | return GNUNET_SYSERR; | 443 | return GNUNET_SYSERR; |
444 | } | 444 | } |
445 | w = h->watches[wid]; | 445 | w = h->watches[wid]; |
446 | (void) w->proc (w->proc_cls, w->subsystem, w->name, | 446 | (void) w->proc (w->proc_cls, w->subsystem, w->name, |
447 | GNUNET_ntohll (wvm->value), | 447 | GNUNET_ntohll (wvm->value), |
448 | 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); | 448 | 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); |
449 | return GNUNET_OK; | 449 | return GNUNET_OK; |
450 | } | 450 | } |
451 | 451 | ||
@@ -462,73 +462,73 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) | |||
462 | struct GNUNET_STATISTICS_Handle *h = cls; | 462 | struct GNUNET_STATISTICS_Handle *h = cls; |
463 | 463 | ||
464 | if (msg == NULL) | 464 | if (msg == NULL) |
465 | { | ||
466 | if (NULL != h->client) | ||
467 | { | 465 | { |
468 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); | 466 | if (NULL != h->client) |
469 | h->client = NULL; | 467 | { |
470 | } | 468 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); |
471 | #if DEBUG_STATISTICS | 469 | h->client = NULL; |
472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 470 | } |
473 | "Error receiving statistics from service, is the service running?\n"); | ||
474 | #endif | ||
475 | finish (h, GNUNET_SYSERR); | ||
476 | return; | ||
477 | } | ||
478 | switch (ntohs (msg->type)) | ||
479 | { | ||
480 | case GNUNET_MESSAGE_TYPE_STATISTICS_END: | ||
481 | #if DEBUG_STATISTICS | 471 | #if DEBUG_STATISTICS |
482 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received end of statistics marker\n"); | 472 | LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
473 | "Error receiving statistics from service, is the service running?\n"); | ||
483 | #endif | 474 | #endif |
484 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 475 | finish (h, GNUNET_SYSERR); |
485 | if (h->watches_size > 0) | 476 | return; |
486 | { | ||
487 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, | ||
488 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
489 | } | ||
490 | else | ||
491 | { | ||
492 | h->receiving = GNUNET_NO; | ||
493 | } | 477 | } |
494 | finish (h, GNUNET_OK); | 478 | switch (ntohs (msg->type)) |
495 | return; | ||
496 | case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE: | ||
497 | if (GNUNET_OK == process_message (h, msg)) | ||
498 | { | 479 | { |
499 | /* finally, look for more! */ | 480 | case GNUNET_MESSAGE_TYPE_STATISTICS_END: |
500 | #if DEBUG_STATISTICS | 481 | #if DEBUG_STATISTICS |
501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 482 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received end of statistics marker\n"); |
502 | "Processing VALUE done, now reading more\n"); | ||
503 | #endif | 483 | #endif |
504 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, | ||
505 | GNUNET_TIME_absolute_get_remaining (h-> | ||
506 | current->timeout)); | ||
507 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 484 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
485 | if (h->watches_size > 0) | ||
486 | { | ||
487 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, | ||
488 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
489 | } | ||
490 | else | ||
491 | { | ||
492 | h->receiving = GNUNET_NO; | ||
493 | } | ||
494 | finish (h, GNUNET_OK); | ||
508 | return; | 495 | return; |
496 | case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE: | ||
497 | if (GNUNET_OK == process_message (h, msg)) | ||
498 | { | ||
499 | /* finally, look for more! */ | ||
500 | #if DEBUG_STATISTICS | ||
501 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
502 | "Processing VALUE done, now reading more\n"); | ||
503 | #endif | ||
504 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, | ||
505 | GNUNET_TIME_absolute_get_remaining | ||
506 | (h->current->timeout)); | ||
507 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | ||
508 | return; | ||
509 | } | ||
510 | GNUNET_break (0); | ||
511 | break; | ||
512 | case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE: | ||
513 | if (GNUNET_OK == process_watch_value (h, msg)) | ||
514 | { | ||
515 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | ||
516 | GNUNET_assert (h->watches_size > 0); | ||
517 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, | ||
518 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
519 | return; | ||
520 | } | ||
521 | GNUNET_break (0); | ||
522 | break; | ||
523 | default: | ||
524 | GNUNET_break (0); | ||
525 | break; | ||
509 | } | 526 | } |
510 | GNUNET_break (0); | 527 | if (NULL != h->client) |
511 | break; | ||
512 | case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE: | ||
513 | if (GNUNET_OK == process_watch_value (h, msg)) | ||
514 | { | 528 | { |
515 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 529 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); |
516 | GNUNET_assert (h->watches_size > 0); | 530 | h->client = NULL; |
517 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, | ||
518 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
519 | return; | ||
520 | } | 531 | } |
521 | GNUNET_break (0); | ||
522 | break; | ||
523 | default: | ||
524 | GNUNET_break (0); | ||
525 | break; | ||
526 | } | ||
527 | if (NULL != h->client) | ||
528 | { | ||
529 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); | ||
530 | h->client = NULL; | ||
531 | } | ||
532 | finish (h, GNUNET_SYSERR); | 532 | finish (h, GNUNET_SYSERR); |
533 | } | 533 | } |
534 | 534 | ||
@@ -546,15 +546,15 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
546 | uint16_t msize; | 546 | uint16_t msize; |
547 | 547 | ||
548 | if (buf == NULL) | 548 | if (buf == NULL) |
549 | { | 549 | { |
550 | /* timeout / error */ | 550 | /* timeout / error */ |
551 | #if DEBUG_STATISTICS | 551 | #if DEBUG_STATISTICS |
552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 552 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
553 | "Transmission of request for statistics failed!\n"); | 553 | "Transmission of request for statistics failed!\n"); |
554 | #endif | 554 | #endif |
555 | finish (handle, GNUNET_SYSERR); | 555 | finish (handle, GNUNET_SYSERR); |
556 | return 0; | 556 | return 0; |
557 | } | 557 | } |
558 | slen1 = strlen (handle->current->subsystem) + 1; | 558 | slen1 = strlen (handle->current->subsystem) + 1; |
559 | slen2 = strlen (handle->current->name) + 1; | 559 | slen2 = strlen (handle->current->name) + 1; |
560 | msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); | 560 | msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader); |
@@ -563,20 +563,20 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
563 | hdr->size = htons (msize); | 563 | hdr->size = htons (msize); |
564 | hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET); | 564 | hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET); |
565 | GNUNET_assert (slen1 + slen2 == | 565 | GNUNET_assert (slen1 + slen2 == |
566 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2, | 566 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, |
567 | handle->current->subsystem, | 567 | 2, handle->current->subsystem, |
568 | handle->current->name)); | 568 | handle->current->name)); |
569 | if (!handle->receiving) | 569 | if (!handle->receiving) |
570 | { | 570 | { |
571 | #if DEBUG_STATISTICS | 571 | #if DEBUG_STATISTICS |
572 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 572 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
573 | "Transmission of GET done, now reading response\n"); | 573 | "Transmission of GET done, now reading response\n"); |
574 | #endif | 574 | #endif |
575 | handle->receiving = GNUNET_YES; | 575 | handle->receiving = GNUNET_YES; |
576 | GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, | 576 | GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, |
577 | GNUNET_TIME_absolute_get_remaining (handle-> | 577 | GNUNET_TIME_absolute_get_remaining |
578 | current->timeout)); | 578 | (handle->current->timeout)); |
579 | } | 579 | } |
580 | return msize; | 580 | return msize; |
581 | } | 581 | } |
582 | 582 | ||
@@ -586,7 +586,8 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
586 | * the response). | 586 | * the response). |
587 | */ | 587 | */ |
588 | static size_t | 588 | static size_t |
589 | transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | 589 | transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, |
590 | void *buf) | ||
590 | { | 591 | { |
591 | struct GNUNET_MessageHeader *hdr; | 592 | struct GNUNET_MessageHeader *hdr; |
592 | size_t slen1; | 593 | size_t slen1; |
@@ -594,18 +595,18 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
594 | uint16_t msize; | 595 | uint16_t msize; |
595 | 596 | ||
596 | if (buf == NULL) | 597 | if (buf == NULL) |
597 | { | 598 | { |
598 | /* timeout / error */ | 599 | /* timeout / error */ |
599 | #if DEBUG_STATISTICS | 600 | #if DEBUG_STATISTICS |
600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 601 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
601 | "Transmission of request for statistics failed!\n"); | 602 | "Transmission of request for statistics failed!\n"); |
602 | #endif | 603 | #endif |
603 | finish (handle, GNUNET_SYSERR); | 604 | finish (handle, GNUNET_SYSERR); |
604 | return 0; | 605 | return 0; |
605 | } | 606 | } |
606 | #if DEBUG_STATISTICS | 607 | #if DEBUG_STATISTICS |
607 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting watch request for `%s'\n", | 608 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting watch request for `%s'\n", |
608 | handle->current->name); | 609 | handle->current->name); |
609 | #endif | 610 | #endif |
610 | slen1 = strlen (handle->current->subsystem) + 1; | 611 | slen1 = strlen (handle->current->subsystem) + 1; |
611 | slen2 = strlen (handle->current->name) + 1; | 612 | slen2 = strlen (handle->current->name) + 1; |
@@ -615,15 +616,15 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
615 | hdr->size = htons (msize); | 616 | hdr->size = htons (msize); |
616 | hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); | 617 | hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); |
617 | GNUNET_assert (slen1 + slen2 == | 618 | GNUNET_assert (slen1 + slen2 == |
618 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2, | 619 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, |
619 | handle->current->subsystem, | 620 | 2, handle->current->subsystem, |
620 | handle->current->name)); | 621 | handle->current->name)); |
621 | if (GNUNET_YES != handle->receiving) | 622 | if (GNUNET_YES != handle->receiving) |
622 | { | 623 | { |
623 | handle->receiving = GNUNET_YES; | 624 | handle->receiving = GNUNET_YES; |
624 | GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, | 625 | GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, |
625 | GNUNET_TIME_UNIT_FOREVER_REL); | 626 | GNUNET_TIME_UNIT_FOREVER_REL); |
626 | } | 627 | } |
627 | finish (handle, GNUNET_OK); | 628 | finish (handle, GNUNET_OK); |
628 | return msize; | 629 | return msize; |
629 | } | 630 | } |
@@ -641,20 +642,20 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
641 | size_t nsize; | 642 | size_t nsize; |
642 | 643 | ||
643 | if (NULL == buf) | 644 | if (NULL == buf) |
644 | { | 645 | { |
645 | finish (handle, GNUNET_SYSERR); | 646 | finish (handle, GNUNET_SYSERR); |
646 | return 0; | 647 | return 0; |
647 | } | 648 | } |
648 | 649 | ||
649 | slen = strlen (handle->current->subsystem) + 1; | 650 | slen = strlen (handle->current->subsystem) + 1; |
650 | nlen = strlen (handle->current->name) + 1; | 651 | nlen = strlen (handle->current->name) + 1; |
651 | nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen; | 652 | nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen; |
652 | if (size < nsize) | 653 | if (size < nsize) |
653 | { | 654 | { |
654 | GNUNET_break (0); | 655 | GNUNET_break (0); |
655 | finish (handle, GNUNET_SYSERR); | 656 | finish (handle, GNUNET_SYSERR); |
656 | return 0; | 657 | return 0; |
657 | } | 658 | } |
658 | r = buf; | 659 | r = buf; |
659 | r->header.size = htons (nsize); | 660 | r->header.size = htons (nsize); |
660 | r->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET); | 661 | r->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET); |
@@ -665,9 +666,9 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
665 | if (handle->current->type == ACTION_UPDATE) | 666 | if (handle->current->type == ACTION_UPDATE) |
666 | r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE); | 667 | r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE); |
667 | GNUNET_assert (slen + nlen == | 668 | GNUNET_assert (slen + nlen == |
668 | GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2, | 669 | GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2, |
669 | handle->current->subsystem, | 670 | handle->current->subsystem, |
670 | handle->current->name)); | 671 | handle->current->name)); |
671 | finish (handle, GNUNET_OK); | 672 | finish (handle, GNUNET_OK); |
672 | return nsize; | 673 | return nsize; |
673 | } | 674 | } |
@@ -681,22 +682,22 @@ transmit_action (void *cls, size_t size, void *buf) | |||
681 | 682 | ||
682 | handle->th = NULL; | 683 | handle->th = NULL; |
683 | switch (handle->current->type) | 684 | switch (handle->current->type) |
684 | { | 685 | { |
685 | case ACTION_GET: | 686 | case ACTION_GET: |
686 | ret = transmit_get (handle, size, buf); | 687 | ret = transmit_get (handle, size, buf); |
687 | break; | 688 | break; |
688 | case ACTION_SET: | 689 | case ACTION_SET: |
689 | case ACTION_UPDATE: | 690 | case ACTION_UPDATE: |
690 | ret = transmit_set (handle, size, buf); | 691 | ret = transmit_set (handle, size, buf); |
691 | break; | 692 | break; |
692 | case ACTION_WATCH: | 693 | case ACTION_WATCH: |
693 | ret = transmit_watch (handle, size, buf); | 694 | ret = transmit_watch (handle, size, buf); |
694 | break; | 695 | break; |
695 | default: | 696 | default: |
696 | ret = 0; | 697 | ret = 0; |
697 | GNUNET_break (0); | 698 | GNUNET_break (0); |
698 | break; | 699 | break; |
699 | } | 700 | } |
700 | return ret; | 701 | return ret; |
701 | } | 702 | } |
702 | 703 | ||
@@ -710,7 +711,7 @@ transmit_action (void *cls, size_t size, void *buf) | |||
710 | */ | 711 | */ |
711 | struct GNUNET_STATISTICS_Handle * | 712 | struct GNUNET_STATISTICS_Handle * |
712 | GNUNET_STATISTICS_create (const char *subsystem, | 713 | GNUNET_STATISTICS_create (const char *subsystem, |
713 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 714 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
714 | { | 715 | { |
715 | struct GNUNET_STATISTICS_Handle *ret; | 716 | struct GNUNET_STATISTICS_Handle *ret; |
716 | 717 | ||
@@ -721,11 +722,11 @@ GNUNET_STATISTICS_create (const char *subsystem, | |||
721 | ret->subsystem = GNUNET_strdup (subsystem); | 722 | ret->subsystem = GNUNET_strdup (subsystem); |
722 | ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 723 | ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
723 | if (GNUNET_YES != try_connect (ret)) | 724 | if (GNUNET_YES != try_connect (ret)) |
724 | { | 725 | { |
725 | GNUNET_free (ret->subsystem); | 726 | GNUNET_free (ret->subsystem); |
726 | GNUNET_free (ret); | 727 | GNUNET_free (ret); |
727 | return NULL; | 728 | return NULL; |
728 | } | 729 | } |
729 | return ret; | 730 | return ret; |
730 | } | 731 | } |
731 | 732 | ||
@@ -752,83 +753,83 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first) | |||
752 | if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task) | 753 | if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task) |
753 | GNUNET_SCHEDULER_cancel (h->backoff_task); | 754 | GNUNET_SCHEDULER_cancel (h->backoff_task); |
754 | if (sync_first) | 755 | if (sync_first) |
755 | { | ||
756 | if (h->current != NULL) | ||
757 | { | 756 | { |
758 | if (h->current->type == ACTION_GET) | 757 | if (h->current != NULL) |
759 | { | 758 | { |
760 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | 759 | if (h->current->type == ACTION_GET) |
761 | h->th = NULL; | 760 | { |
762 | free_action_item (h->current); | 761 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); |
763 | h->current = NULL; | 762 | h->th = NULL; |
764 | } | 763 | free_action_item (h->current); |
765 | } | 764 | h->current = NULL; |
766 | pos = h->action_head; | 765 | } |
767 | prev = NULL; | 766 | } |
768 | while (pos != NULL) | 767 | pos = h->action_head; |
769 | { | 768 | prev = NULL; |
770 | next = pos->next; | 769 | while (pos != NULL) |
771 | if (pos->type == ACTION_GET) | 770 | { |
772 | { | 771 | next = pos->next; |
773 | if (prev == NULL) | 772 | if (pos->type == ACTION_GET) |
774 | h->action_head = next; | 773 | { |
775 | else | 774 | if (prev == NULL) |
776 | prev->next = next; | 775 | h->action_head = next; |
777 | free_action_item (pos); | 776 | else |
778 | } | 777 | prev->next = next; |
779 | else | 778 | free_action_item (pos); |
780 | { | 779 | } |
781 | prev = pos; | 780 | else |
782 | } | 781 | { |
783 | pos = next; | 782 | prev = pos; |
783 | } | ||
784 | pos = next; | ||
785 | } | ||
786 | h->action_tail = prev; | ||
787 | if (h->current == NULL) | ||
788 | { | ||
789 | h->current = h->action_head; | ||
790 | if (h->action_head != NULL) | ||
791 | { | ||
792 | h->action_head = h->action_head->next; | ||
793 | if (h->action_head == NULL) | ||
794 | h->action_tail = NULL; | ||
795 | } | ||
796 | } | ||
797 | h->do_destroy = GNUNET_YES; | ||
798 | if ((h->current != NULL) && (h->th == NULL)) | ||
799 | { | ||
800 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); | ||
801 | h->th = | ||
802 | GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, | ||
803 | timeout, GNUNET_YES, | ||
804 | &transmit_action, h); | ||
805 | GNUNET_assert (NULL != h->th); | ||
806 | } | ||
807 | if (h->th != NULL) | ||
808 | return; | ||
784 | } | 809 | } |
785 | h->action_tail = prev; | 810 | if (NULL != h->th) |
786 | if (h->current == NULL) | ||
787 | { | ||
788 | h->current = h->action_head; | ||
789 | if (h->action_head != NULL) | ||
790 | { | ||
791 | h->action_head = h->action_head->next; | ||
792 | if (h->action_head == NULL) | ||
793 | h->action_tail = NULL; | ||
794 | } | ||
795 | } | ||
796 | h->do_destroy = GNUNET_YES; | ||
797 | if ((h->current != NULL) && (h->th == NULL)) | ||
798 | { | 811 | { |
799 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); | 812 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); |
800 | h->th = | 813 | h->th = NULL; |
801 | GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, | ||
802 | timeout, GNUNET_YES, | ||
803 | &transmit_action, h); | ||
804 | GNUNET_assert (NULL != h->th); | ||
805 | } | 814 | } |
806 | if (h->th != NULL) | ||
807 | return; | ||
808 | } | ||
809 | if (NULL != h->th) | ||
810 | { | ||
811 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | ||
812 | h->th = NULL; | ||
813 | } | ||
814 | if (h->current != NULL) | 815 | if (h->current != NULL) |
815 | free_action_item (h->current); | 816 | free_action_item (h->current); |
816 | while (NULL != (pos = h->action_head)) | 817 | while (NULL != (pos = h->action_head)) |
817 | { | 818 | { |
818 | h->action_head = pos->next; | 819 | h->action_head = pos->next; |
819 | free_action_item (pos); | 820 | free_action_item (pos); |
820 | } | 821 | } |
821 | if (h->client != NULL) | 822 | if (h->client != NULL) |
822 | { | 823 | { |
823 | GNUNET_CLIENT_disconnect (h->client, GNUNET_YES); | 824 | GNUNET_CLIENT_disconnect (h->client, GNUNET_YES); |
824 | h->client = NULL; | 825 | h->client = NULL; |
825 | } | 826 | } |
826 | for (i = 0; i < h->watches_size; i++) | 827 | for (i = 0; i < h->watches_size; i++) |
827 | { | 828 | { |
828 | GNUNET_free (h->watches[i]->subsystem); | 829 | GNUNET_free (h->watches[i]->subsystem); |
829 | GNUNET_free (h->watches[i]->name); | 830 | GNUNET_free (h->watches[i]->name); |
830 | GNUNET_free (h->watches[i]); | 831 | GNUNET_free (h->watches[i]); |
831 | } | 832 | } |
832 | GNUNET_array_grow (h->watches, h->watches_size, 0); | 833 | GNUNET_array_grow (h->watches, h->watches_size, 0); |
833 | GNUNET_free (h->subsystem); | 834 | GNUNET_free (h->subsystem); |
834 | GNUNET_free (h); | 835 | GNUNET_free (h); |
@@ -854,42 +855,43 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) | |||
854 | struct GNUNET_TIME_Relative timeout; | 855 | struct GNUNET_TIME_Relative timeout; |
855 | 856 | ||
856 | if (h->current != NULL) | 857 | if (h->current != NULL) |
857 | return; /* action already pending */ | 858 | return; /* action already pending */ |
858 | if (GNUNET_YES != try_connect (h)) | 859 | if (GNUNET_YES != try_connect (h)) |
859 | { | 860 | { |
860 | h->backoff_task = | 861 | h->backoff_task = |
861 | GNUNET_SCHEDULER_add_delayed (h->backoff, &finish_task, h); | 862 | GNUNET_SCHEDULER_add_delayed (h->backoff, &finish_task, h); |
862 | h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2); | 863 | h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2); |
863 | h->backoff = | 864 | h->backoff = |
864 | GNUNET_TIME_relative_min (h->backoff, GNUNET_CONSTANTS_SERVICE_TIMEOUT); | 865 | GNUNET_TIME_relative_min (h->backoff, |
865 | return; | 866 | GNUNET_CONSTANTS_SERVICE_TIMEOUT); |
866 | } | 867 | return; |
868 | } | ||
867 | 869 | ||
868 | /* schedule next action */ | 870 | /* schedule next action */ |
869 | h->current = h->action_head; | 871 | h->current = h->action_head; |
870 | if (NULL == h->current) | 872 | if (NULL == h->current) |
871 | { | ||
872 | if (h->do_destroy) | ||
873 | { | 873 | { |
874 | h->do_destroy = GNUNET_NO; | 874 | if (h->do_destroy) |
875 | GNUNET_STATISTICS_destroy (h, GNUNET_YES); | 875 | { |
876 | h->do_destroy = GNUNET_NO; | ||
877 | GNUNET_STATISTICS_destroy (h, GNUNET_YES); | ||
878 | } | ||
879 | return; | ||
876 | } | 880 | } |
877 | return; | ||
878 | } | ||
879 | GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current); | 881 | GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current); |
880 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); | 882 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); |
881 | if (NULL == | 883 | if (NULL == |
882 | (h->th = | 884 | (h->th = |
883 | GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, | 885 | GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, |
884 | timeout, GNUNET_YES, | 886 | timeout, GNUNET_YES, |
885 | &transmit_action, h))) | 887 | &transmit_action, h))) |
886 | { | 888 | { |
887 | #if DEBUG_STATISTICS | 889 | #if DEBUG_STATISTICS |
888 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 890 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
889 | "Failed to transmit request to statistics service.\n"); | 891 | "Failed to transmit request to statistics service.\n"); |
890 | #endif | 892 | #endif |
891 | finish (h, GNUNET_SYSERR); | 893 | finish (h, GNUNET_SYSERR); |
892 | } | 894 | } |
893 | } | 895 | } |
894 | 896 | ||
895 | 897 | ||
@@ -908,10 +910,10 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) | |||
908 | */ | 910 | */ |
909 | struct GNUNET_STATISTICS_GetHandle * | 911 | struct GNUNET_STATISTICS_GetHandle * |
910 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | 912 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, |
911 | const char *subsystem, const char *name, | 913 | const char *subsystem, const char *name, |
912 | struct GNUNET_TIME_Relative timeout, | 914 | struct GNUNET_TIME_Relative timeout, |
913 | GNUNET_STATISTICS_Callback cont, | 915 | GNUNET_STATISTICS_Callback cont, |
914 | GNUNET_STATISTICS_Iterator proc, void *cls) | 916 | GNUNET_STATISTICS_Iterator proc, void *cls) |
915 | { | 917 | { |
916 | size_t slen1; | 918 | size_t slen1; |
917 | size_t slen2; | 919 | size_t slen2; |
@@ -921,15 +923,14 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | |||
921 | GNUNET_assert (proc != NULL); | 923 | GNUNET_assert (proc != NULL); |
922 | GNUNET_assert (GNUNET_NO == handle->do_destroy); | 924 | GNUNET_assert (GNUNET_NO == handle->do_destroy); |
923 | if (GNUNET_YES != try_connect (handle)) | 925 | if (GNUNET_YES != try_connect (handle)) |
924 | { | 926 | { |
925 | #if DEBUG_STATISTICS | 927 | #if DEBUG_STATISTICS |
926 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 928 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
927 | "Failed to connect to statistics service, can not get value `%s:%s'.\n", | 929 | "Failed to connect to statistics service, can not get value `%s:%s'.\n", |
928 | strlen (subsystem) ? subsystem : "*", | 930 | strlen (subsystem) ? subsystem : "*", strlen (name) ? name : "*"); |
929 | strlen (name) ? name : "*"); | ||
930 | #endif | 931 | #endif |
931 | return NULL; | 932 | return NULL; |
932 | } | 933 | } |
933 | if (subsystem == NULL) | 934 | if (subsystem == NULL) |
934 | subsystem = ""; | 935 | subsystem = ""; |
935 | if (name == NULL) | 936 | if (name == NULL) |
@@ -937,7 +938,7 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | |||
937 | slen1 = strlen (subsystem) + 1; | 938 | slen1 = strlen (subsystem) + 1; |
938 | slen2 = strlen (name) + 1; | 939 | slen2 = strlen (name) + 1; |
939 | GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) < | 940 | GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) < |
940 | GNUNET_SERVER_MAX_MESSAGE_SIZE); | 941 | GNUNET_SERVER_MAX_MESSAGE_SIZE); |
941 | ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); | 942 | ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); |
942 | ai->sh = handle; | 943 | ai->sh = handle; |
943 | ai->subsystem = GNUNET_strdup (subsystem); | 944 | ai->subsystem = GNUNET_strdup (subsystem); |
@@ -963,16 +964,17 @@ void | |||
963 | GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) | 964 | GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) |
964 | { | 965 | { |
965 | if (gh->sh->current == gh) | 966 | if (gh->sh->current == gh) |
966 | { | 967 | { |
967 | gh->aborted = GNUNET_YES; | 968 | gh->aborted = GNUNET_YES; |
968 | } | 969 | } |
969 | else | 970 | else |
970 | { | 971 | { |
971 | GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, gh->sh->action_tail, gh); | 972 | GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, gh->sh->action_tail, |
972 | GNUNET_free (gh->name); | 973 | gh); |
973 | GNUNET_free (gh->subsystem); | 974 | GNUNET_free (gh->name); |
974 | GNUNET_free (gh); | 975 | GNUNET_free (gh->subsystem); |
975 | } | 976 | GNUNET_free (gh); |
977 | } | ||
976 | } | 978 | } |
977 | 979 | ||
978 | 980 | ||
@@ -990,8 +992,8 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) | |||
990 | */ | 992 | */ |
991 | int | 993 | int |
992 | GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, | 994 | GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, |
993 | const char *subsystem, const char *name, | 995 | const char *subsystem, const char *name, |
994 | GNUNET_STATISTICS_Iterator proc, void *proc_cls) | 996 | GNUNET_STATISTICS_Iterator proc, void *proc_cls) |
995 | { | 997 | { |
996 | struct GNUNET_STATISTICS_WatchEntry *w; | 998 | struct GNUNET_STATISTICS_WatchEntry *w; |
997 | 999 | ||
@@ -1010,7 +1012,7 @@ GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, | |||
1010 | 1012 | ||
1011 | static void | 1013 | static void |
1012 | add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, | 1014 | add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, |
1013 | int make_persistent, uint64_t value, enum ActionType type) | 1015 | int make_persistent, uint64_t value, enum ActionType type) |
1014 | { | 1016 | { |
1015 | struct GNUNET_STATISTICS_GetHandle *ai; | 1017 | struct GNUNET_STATISTICS_GetHandle *ai; |
1016 | size_t slen; | 1018 | size_t slen; |
@@ -1026,58 +1028,59 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, | |||
1026 | nlen = strlen (name) + 1; | 1028 | nlen = strlen (name) + 1; |
1027 | nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen; | 1029 | nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen; |
1028 | if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1030 | if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1029 | { | 1031 | { |
1030 | GNUNET_break (0); | 1032 | GNUNET_break (0); |
1031 | return; | 1033 | return; |
1032 | } | 1034 | } |
1033 | ai = h->action_head; | 1035 | ai = h->action_head; |
1034 | while (ai != NULL) | 1036 | while (ai != NULL) |
1035 | { | ||
1036 | if ((0 == strcmp (ai->subsystem, h->subsystem)) && | ||
1037 | (0 == strcmp (ai->name, name)) && ((ai->type == ACTION_UPDATE) || | ||
1038 | (ai->type == ACTION_SET))) | ||
1039 | { | 1037 | { |
1040 | if (ai->type == ACTION_SET) | 1038 | if ((0 == strcmp (ai->subsystem, h->subsystem)) && |
1041 | { | 1039 | (0 == strcmp (ai->name, name)) && ((ai->type == ACTION_UPDATE) || |
1042 | if (type == ACTION_UPDATE) | 1040 | (ai->type == ACTION_SET))) |
1043 | { | 1041 | { |
1044 | delta = (int64_t) value; | 1042 | if (ai->type == ACTION_SET) |
1045 | if (delta > 0) | 1043 | { |
1046 | { | 1044 | if (type == ACTION_UPDATE) |
1047 | ai->value += delta; | 1045 | { |
1048 | } | 1046 | delta = (int64_t) value; |
1049 | else | 1047 | if (delta > 0) |
1050 | { | 1048 | { |
1051 | if (ai->value < -delta) | 1049 | ai->value += delta; |
1052 | ai->value = 0; | 1050 | } |
1053 | else | 1051 | else |
1054 | ai->value += delta; | 1052 | { |
1055 | } | 1053 | if (ai->value < -delta) |
1056 | } | 1054 | ai->value = 0; |
1057 | else | 1055 | else |
1058 | { | 1056 | ai->value += delta; |
1059 | ai->value = value; | 1057 | } |
1060 | } | 1058 | } |
1061 | } | 1059 | else |
1062 | else | 1060 | { |
1063 | { | 1061 | ai->value = value; |
1064 | if (type == ACTION_UPDATE) | 1062 | } |
1065 | { | 1063 | } |
1066 | delta = (int64_t) value; | 1064 | else |
1067 | ai->value += delta; | 1065 | { |
1068 | } | 1066 | if (type == ACTION_UPDATE) |
1069 | else | 1067 | { |
1070 | { | 1068 | delta = (int64_t) value; |
1071 | ai->value = value; | 1069 | ai->value += delta; |
1072 | ai->type = type; | 1070 | } |
1073 | } | 1071 | else |
1074 | } | 1072 | { |
1075 | ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT); | 1073 | ai->value = value; |
1076 | ai->make_persistent = make_persistent; | 1074 | ai->type = type; |
1077 | return; | 1075 | } |
1076 | } | ||
1077 | ai->timeout = | ||
1078 | GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT); | ||
1079 | ai->make_persistent = make_persistent; | ||
1080 | return; | ||
1081 | } | ||
1082 | ai = ai->next; | ||
1078 | } | 1083 | } |
1079 | ai = ai->next; | ||
1080 | } | ||
1081 | ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); | 1084 | ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); |
1082 | ai->sh = h; | 1085 | ai->sh = h; |
1083 | ai->subsystem = GNUNET_strdup (h->subsystem); | 1086 | ai->subsystem = GNUNET_strdup (h->subsystem); |
@@ -1102,7 +1105,7 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, | |||
1102 | */ | 1105 | */ |
1103 | void | 1106 | void |
1104 | GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, | 1107 | GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, |
1105 | const char *name, uint64_t value, int make_persistent) | 1108 | const char *name, uint64_t value, int make_persistent) |
1106 | { | 1109 | { |
1107 | if (handle == NULL) | 1110 | if (handle == NULL) |
1108 | return; | 1111 | return; |
@@ -1122,7 +1125,8 @@ GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, | |||
1122 | */ | 1125 | */ |
1123 | void | 1126 | void |
1124 | GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, | 1127 | GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, |
1125 | const char *name, int64_t delta, int make_persistent) | 1128 | const char *name, int64_t delta, |
1129 | int make_persistent) | ||
1126 | { | 1130 | { |
1127 | if (handle == NULL) | 1131 | if (handle == NULL) |
1128 | return; | 1132 | return; |
@@ -1130,7 +1134,7 @@ GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, | |||
1130 | return; | 1134 | return; |
1131 | GNUNET_assert (GNUNET_NO == handle->do_destroy); | 1135 | GNUNET_assert (GNUNET_NO == handle->do_destroy); |
1132 | add_setter_action (handle, name, make_persistent, (uint64_t) delta, | 1136 | add_setter_action (handle, name, make_persistent, (uint64_t) delta, |
1133 | ACTION_UPDATE); | 1137 | ACTION_UPDATE); |
1134 | } | 1138 | } |
1135 | 1139 | ||
1136 | 1140 | ||