diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
commit | 5746309cb4be2073d550ad7a6885e918631dbc38 (patch) | |
tree | 89455bc4aadf977816b38df13f990372cd81d71a /src/statistics/statistics_api.c | |
parent | 6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff) | |
download | gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip |
indentation
Diffstat (limited to 'src/statistics/statistics_api.c')
-rw-r--r-- | src/statistics/statistics_api.c | 109 |
1 files changed, 45 insertions, 64 deletions
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index a76f83db1..f4a71cc21 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -256,8 +256,8 @@ static void | |||
256 | insert_ai (struct GNUNET_STATISTICS_Handle *h, | 256 | insert_ai (struct GNUNET_STATISTICS_Handle *h, |
257 | struct GNUNET_STATISTICS_GetHandle *ai) | 257 | struct GNUNET_STATISTICS_GetHandle *ai) |
258 | { | 258 | { |
259 | GNUNET_CONTAINER_DLL_insert_after (h->action_head, | 259 | GNUNET_CONTAINER_DLL_insert_after (h->action_head, h->action_tail, |
260 | h->action_tail, h->action_tail, ai); | 260 | h->action_tail, ai); |
261 | if (h->action_head == ai) | 261 | if (h->action_head == ai) |
262 | schedule_action (h); | 262 | schedule_action (h); |
263 | } | 263 | } |
@@ -388,21 +388,20 @@ process_message (struct GNUNET_STATISTICS_Handle *h, | |||
388 | } | 388 | } |
389 | smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg; | 389 | smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg; |
390 | size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); | 390 | size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage); |
391 | if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], | 391 | if (size != |
392 | size, 2, &service, &name)) | 392 | GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], size, 2, |
393 | &service, &name)) | ||
393 | { | 394 | { |
394 | GNUNET_break (0); | 395 | GNUNET_break (0); |
395 | return GNUNET_SYSERR; | 396 | return GNUNET_SYSERR; |
396 | } | 397 | } |
397 | #if DEBUG_STATISTICS | 398 | #if DEBUG_STATISTICS |
398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
399 | "Received valid statistic on `%s:%s': %llu\n", | 400 | "Received valid statistic on `%s:%s': %llu\n", service, name, |
400 | service, name, GNUNET_ntohll (smsg->value)); | 401 | GNUNET_ntohll (smsg->value)); |
401 | #endif | 402 | #endif |
402 | if (GNUNET_OK != | 403 | if (GNUNET_OK != |
403 | h->current->proc (h->current->cls, | 404 | h->current->proc (h->current->cls, service, name, |
404 | service, | ||
405 | name, | ||
406 | GNUNET_ntohll (smsg->value), | 405 | GNUNET_ntohll (smsg->value), |
407 | 0 != | 406 | 0 != |
408 | (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) | 407 | (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT))) |
@@ -442,9 +441,7 @@ process_watch_value (struct GNUNET_STATISTICS_Handle *h, | |||
442 | return GNUNET_SYSERR; | 441 | return GNUNET_SYSERR; |
443 | } | 442 | } |
444 | w = h->watches[wid]; | 443 | w = h->watches[wid]; |
445 | (void) w->proc (w->proc_cls, | 444 | (void) w->proc (w->proc_cls, w->subsystem, w->name, |
446 | w->subsystem, | ||
447 | w->name, | ||
448 | GNUNET_ntohll (wvm->value), | 445 | GNUNET_ntohll (wvm->value), |
449 | 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); | 446 | 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); |
450 | return GNUNET_OK; | 447 | return GNUNET_OK; |
@@ -485,8 +482,8 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) | |||
485 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 482 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
486 | if (h->watches_size > 0) | 483 | if (h->watches_size > 0) |
487 | { | 484 | { |
488 | GNUNET_CLIENT_receive (h->client, | 485 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, |
489 | &receive_stats, h, GNUNET_TIME_UNIT_FOREVER_REL); | 486 | GNUNET_TIME_UNIT_FOREVER_REL); |
490 | } | 487 | } |
491 | else | 488 | else |
492 | { | 489 | { |
@@ -502,11 +499,9 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) | |||
502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
503 | "Processing VALUE done, now reading more\n"); | 500 | "Processing VALUE done, now reading more\n"); |
504 | #endif | 501 | #endif |
505 | GNUNET_CLIENT_receive (h->client, | 502 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, |
506 | &receive_stats, | 503 | GNUNET_TIME_absolute_get_remaining (h->current-> |
507 | h, | 504 | timeout)); |
508 | GNUNET_TIME_absolute_get_remaining | ||
509 | (h->current->timeout)); | ||
510 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 505 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
511 | return; | 506 | return; |
512 | } | 507 | } |
@@ -517,8 +512,8 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) | |||
517 | { | 512 | { |
518 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 513 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
519 | GNUNET_assert (h->watches_size > 0); | 514 | GNUNET_assert (h->watches_size > 0); |
520 | GNUNET_CLIENT_receive (h->client, | 515 | GNUNET_CLIENT_receive (h->client, &receive_stats, h, |
521 | &receive_stats, h, GNUNET_TIME_UNIT_FOREVER_REL); | 516 | GNUNET_TIME_UNIT_FOREVER_REL); |
522 | return; | 517 | return; |
523 | } | 518 | } |
524 | GNUNET_break (0); | 519 | GNUNET_break (0); |
@@ -566,9 +561,7 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
566 | hdr->size = htons (msize); | 561 | hdr->size = htons (msize); |
567 | hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET); | 562 | hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET); |
568 | GNUNET_assert (slen1 + slen2 == | 563 | GNUNET_assert (slen1 + slen2 == |
569 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], | 564 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2, |
570 | slen1 + slen2, | ||
571 | 2, | ||
572 | handle->current->subsystem, | 565 | handle->current->subsystem, |
573 | handle->current->name)); | 566 | handle->current->name)); |
574 | if (!handle->receiving) | 567 | if (!handle->receiving) |
@@ -578,11 +571,9 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
578 | "Transmission of GET done, now reading response\n"); | 571 | "Transmission of GET done, now reading response\n"); |
579 | #endif | 572 | #endif |
580 | handle->receiving = GNUNET_YES; | 573 | handle->receiving = GNUNET_YES; |
581 | GNUNET_CLIENT_receive (handle->client, | 574 | GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, |
582 | &receive_stats, | 575 | GNUNET_TIME_absolute_get_remaining (handle->current-> |
583 | handle, | 576 | timeout)); |
584 | GNUNET_TIME_absolute_get_remaining (handle-> | ||
585 | current->timeout)); | ||
586 | } | 577 | } |
587 | return msize; | 578 | return msize; |
588 | } | 579 | } |
@@ -611,8 +602,8 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
611 | return 0; | 602 | return 0; |
612 | } | 603 | } |
613 | #if DEBUG_STATISTICS | 604 | #if DEBUG_STATISTICS |
614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting watch request for `%s'\n", |
615 | "Transmitting watch request for `%s'\n", handle->current->name); | 606 | handle->current->name); |
616 | #endif | 607 | #endif |
617 | slen1 = strlen (handle->current->subsystem) + 1; | 608 | slen1 = strlen (handle->current->subsystem) + 1; |
618 | slen2 = strlen (handle->current->name) + 1; | 609 | slen2 = strlen (handle->current->name) + 1; |
@@ -622,17 +613,14 @@ transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
622 | hdr->size = htons (msize); | 613 | hdr->size = htons (msize); |
623 | hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); | 614 | hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH); |
624 | GNUNET_assert (slen1 + slen2 == | 615 | GNUNET_assert (slen1 + slen2 == |
625 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], | 616 | GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2, |
626 | slen1 + slen2, | ||
627 | 2, | ||
628 | handle->current->subsystem, | 617 | handle->current->subsystem, |
629 | handle->current->name)); | 618 | handle->current->name)); |
630 | if (GNUNET_YES != handle->receiving) | 619 | if (GNUNET_YES != handle->receiving) |
631 | { | 620 | { |
632 | handle->receiving = GNUNET_YES; | 621 | handle->receiving = GNUNET_YES; |
633 | GNUNET_CLIENT_receive (handle->client, | 622 | GNUNET_CLIENT_receive (handle->client, &receive_stats, handle, |
634 | &receive_stats, | 623 | GNUNET_TIME_UNIT_FOREVER_REL); |
635 | handle, GNUNET_TIME_UNIT_FOREVER_REL); | ||
636 | } | 624 | } |
637 | finish (handle, GNUNET_OK); | 625 | finish (handle, GNUNET_OK); |
638 | return msize; | 626 | return msize; |
@@ -675,9 +663,7 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
675 | if (handle->current->type == ACTION_UPDATE) | 663 | if (handle->current->type == ACTION_UPDATE) |
676 | r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE); | 664 | r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE); |
677 | GNUNET_assert (slen + nlen == | 665 | GNUNET_assert (slen + nlen == |
678 | GNUNET_STRINGS_buffer_fill ((char *) &r[1], | 666 | GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2, |
679 | slen + nlen, | ||
680 | 2, | ||
681 | handle->current->subsystem, | 667 | handle->current->subsystem, |
682 | handle->current->name)); | 668 | handle->current->name)); |
683 | finish (handle, GNUNET_OK); | 669 | finish (handle, GNUNET_OK); |
@@ -809,11 +795,10 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first) | |||
809 | if ((h->current != NULL) && (h->th == NULL)) | 795 | if ((h->current != NULL) && (h->th == NULL)) |
810 | { | 796 | { |
811 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); | 797 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); |
812 | h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, | 798 | h->th = |
813 | h->current->msize, | 799 | GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, |
814 | timeout, | 800 | timeout, GNUNET_YES, |
815 | GNUNET_YES, | 801 | &transmit_action, h); |
816 | &transmit_action, h); | ||
817 | GNUNET_assert (NULL != h->th); | 802 | GNUNET_assert (NULL != h->th); |
818 | } | 803 | } |
819 | if (h->th != NULL) | 804 | if (h->th != NULL) |
@@ -870,11 +855,11 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) | |||
870 | return; /* action already pending */ | 855 | return; /* action already pending */ |
871 | if (GNUNET_YES != try_connect (h)) | 856 | if (GNUNET_YES != try_connect (h)) |
872 | { | 857 | { |
873 | h->backoff_task = GNUNET_SCHEDULER_add_delayed (h->backoff, | 858 | h->backoff_task = |
874 | &finish_task, h); | 859 | GNUNET_SCHEDULER_add_delayed (h->backoff, &finish_task, h); |
875 | h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2); | 860 | h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2); |
876 | h->backoff = GNUNET_TIME_relative_min (h->backoff, | 861 | h->backoff = |
877 | GNUNET_CONSTANTS_SERVICE_TIMEOUT); | 862 | GNUNET_TIME_relative_min (h->backoff, GNUNET_CONSTANTS_SERVICE_TIMEOUT); |
878 | return; | 863 | return; |
879 | } | 864 | } |
880 | 865 | ||
@@ -892,11 +877,10 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) | |||
892 | GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current); | 877 | GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current); |
893 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); | 878 | timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout); |
894 | if (NULL == | 879 | if (NULL == |
895 | (h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, | 880 | (h->th = |
896 | h->current->msize, | 881 | GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize, |
897 | timeout, | 882 | timeout, GNUNET_YES, |
898 | GNUNET_YES, | 883 | &transmit_action, h))) |
899 | &transmit_action, h))) | ||
900 | { | 884 | { |
901 | #if DEBUG_STATISTICS | 885 | #if DEBUG_STATISTICS |
902 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 886 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -922,8 +906,7 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h) | |||
922 | */ | 906 | */ |
923 | struct GNUNET_STATISTICS_GetHandle * | 907 | struct GNUNET_STATISTICS_GetHandle * |
924 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, | 908 | GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, |
925 | const char *subsystem, | 909 | const char *subsystem, const char *name, |
926 | const char *name, | ||
927 | struct GNUNET_TIME_Relative timeout, | 910 | struct GNUNET_TIME_Relative timeout, |
928 | GNUNET_STATISTICS_Callback cont, | 911 | GNUNET_STATISTICS_Callback cont, |
929 | GNUNET_STATISTICS_Iterator proc, void *cls) | 912 | GNUNET_STATISTICS_Iterator proc, void *cls) |
@@ -1005,8 +988,7 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) | |||
1005 | */ | 988 | */ |
1006 | int | 989 | int |
1007 | GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, | 990 | GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, |
1008 | const char *subsystem, | 991 | const char *subsystem, const char *name, |
1009 | const char *name, | ||
1010 | GNUNET_STATISTICS_Iterator proc, void *proc_cls) | 992 | GNUNET_STATISTICS_Iterator proc, void *proc_cls) |
1011 | { | 993 | { |
1012 | struct GNUNET_STATISTICS_WatchEntry *w; | 994 | struct GNUNET_STATISTICS_WatchEntry *w; |
@@ -1025,8 +1007,7 @@ GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, | |||
1025 | 1007 | ||
1026 | 1008 | ||
1027 | static void | 1009 | static void |
1028 | add_setter_action (struct GNUNET_STATISTICS_Handle *h, | 1010 | add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, |
1029 | const char *name, | ||
1030 | int make_persistent, uint64_t value, enum ActionType type) | 1011 | int make_persistent, uint64_t value, enum ActionType type) |
1031 | { | 1012 | { |
1032 | struct GNUNET_STATISTICS_GetHandle *ai; | 1013 | struct GNUNET_STATISTICS_GetHandle *ai; |
@@ -1051,8 +1032,8 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, | |||
1051 | while (ai != NULL) | 1032 | while (ai != NULL) |
1052 | { | 1033 | { |
1053 | if ((0 == strcmp (ai->subsystem, h->subsystem)) && | 1034 | if ((0 == strcmp (ai->subsystem, h->subsystem)) && |
1054 | (0 == strcmp (ai->name, name)) && | 1035 | (0 == strcmp (ai->name, name)) && ((ai->type == ACTION_UPDATE) || |
1055 | ((ai->type == ACTION_UPDATE) || (ai->type == ACTION_SET))) | 1036 | (ai->type == ACTION_SET))) |
1056 | { | 1037 | { |
1057 | if (ai->type == ACTION_SET) | 1038 | if (ai->type == ACTION_SET) |
1058 | { | 1039 | { |
@@ -1146,8 +1127,8 @@ GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, | |||
1146 | if (delta == 0) | 1127 | if (delta == 0) |
1147 | return; | 1128 | return; |
1148 | GNUNET_assert (GNUNET_NO == handle->do_destroy); | 1129 | GNUNET_assert (GNUNET_NO == handle->do_destroy); |
1149 | add_setter_action (handle, name, make_persistent, | 1130 | add_setter_action (handle, name, make_persistent, (uint64_t) delta, |
1150 | (uint64_t) delta, ACTION_UPDATE); | 1131 | ACTION_UPDATE); |
1151 | } | 1132 | } |
1152 | 1133 | ||
1153 | 1134 | ||